[Olsr-cvs] olsrd-current/lib/nameservice/src mapwrite.h, NONE, 1.1 mapwrite.c, NONE, 1.1 nameservice.h, 1.16, 1.17 nameservice.c, 1.38, 1.39

Bernd Petrovitsch (spam-protected)
Thu Nov 29 01:26:19 CET 2007


Update of /cvsroot/olsrd/olsrd-current/lib/nameservice/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv7957/lib/nameservice/src

Modified Files:
	nameservice.h nameservice.c 
Added Files:
	mapwrite.h mapwrite.c 
Log Message:
Patch from Sven-Ola Tücke <(spam-protected)> from
http://download-master.berlin.freifunk.net/sven-ola/nylon/packages/olsrd/files/135-georss-map-for-nameservice.patch: fixes and extensions for the namesaervice plugin


--- NEW FILE: mapwrite.c ---
/*
 * Copyright (c) 2007, Sven-Ola <sven-ola-aet-gmx.de>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met:
 *
 * * Redistributions of source code must retain the above copyright notice, 
 *   this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above copyright notice, 
 *   this list of conditions and the following disclaimer in the documentation 
 *   and/or other materials provided with the distribution.
 * * Neither the name of the UniK olsr daemon nor the names of its contributors 
 *   may be used to endorse or promote products derived from this software 
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

/* $Id: mapwrite.c,v 1.1 2007/11/29 00:26:16 bernd67 Exp $ */
 
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "defs.h"
#include "scheduler.h"
#include "nameservice.h"
#include "mid_set.h"
#include "tc_set.h"
#include "net_olsr.h"
#include "mapwrite.h"

static char my_latlon_str[48];

/**
 * lookup a nodes position
 */
static char* lookup_position_latlon(union olsr_ip_addr *ip)
{
  int hash;
  struct db_entry *entry;
  if (ipequal(ip, &olsr_cnf->main_addr))
  {
    return my_latlon_str;
  }
  for (hash = 0; hash < HASHSIZE; hash++) 
  {
    for(entry = latlon_list[hash]; entry != NULL; entry = entry->next)
    {
      if (NULL != entry->names && ipequal(&entry->originator, ip))
      {
        return entry->names->name;
      }
    }
  }
  return NULL;
}

/**
 * write latlon positions to a file
 */
void mapwrite_work(FILE* fmap)
{
  int hash;
  struct olsr_if *ifs;
  union olsr_ip_addr ip;
  struct ipaddr_str strbuf1, strbuf2;
  struct tc_entry *tc;
  struct tc_edge_entry *tc_edge;

  if (!my_names || !fmap) return;

  for (ifs = olsr_cnf->interfaces; ifs; ifs = ifs->next)
  {
    if (0 != ifs->interf)
    {
      if (olsr_cnf->ip_version == AF_INET)
      {
        if (!(ip4equal((struct in_addr *)&olsr_cnf->main_addr, &ifs->interf->int_addr.sin_addr)))
        {
          if (0 > fprintf(fmap, "Mid('%s','%s');\n",
            olsr_ip_to_string(&strbuf1, &olsr_cnf->main_addr),
            olsr_ip_to_string(&strbuf2, (union olsr_ip_addr *)&ifs->interf->int_addr.sin_addr)))
          {
            return;
          }
        }
      }
      else if (!(ip6equal((struct in6_addr *)&olsr_cnf->main_addr, &ifs->interf->int6_addr.sin6_addr)))
      {
        if (0 > fprintf(fmap, "Mid('%s','%s');\n",
          olsr_ip_to_string(&strbuf1, &olsr_cnf->main_addr),
          olsr_ip_to_string(&strbuf2, (union olsr_ip_addr *)&ifs->interf->int6_addr.sin6_addr)))
        {
          return;
        }
      }
    }
  }

  for (hash = 0; hash < HASHSIZE; hash++) 
  {
    struct mid_entry *entry = mid_set[hash].next;
    while(entry != &mid_set[hash])
    {
      struct mid_address *alias = entry->aliases;
      while(alias)
      {
        if (0 > fprintf(fmap, "Mid('%s','%s');\n",
          olsr_ip_to_string(&strbuf1, &entry->main_addr),
          olsr_ip_to_string(&strbuf2, &alias->alias)))
        {
          return;
        }
        alias = alias->next_alias;
      }
      entry = entry->next;
    }
  }
  lookup_defhna_latlon(&ip);
  sprintf(my_latlon_str, "%f,%f,%d", my_lat, my_lon, get_isdefhna_latlon());
  if (0 > fprintf(fmap, "Self('%s',%s,'%s','%s');\n",
    olsr_ip_to_string(&strbuf1, &olsr_cnf->main_addr), my_latlon_str, 
    olsr_ip_to_string(&strbuf2, &ip), my_names->name))
  {
    return;
  }
  for (hash = 0; hash < HASHSIZE; hash++) 
  {
    struct db_entry *entry;
    for(entry = latlon_list[hash]; entry != NULL; entry = entry->next)
    {
      if (NULL != entry->names)
      {
        if (0 > fprintf(fmap, "Node('%s',%s,'%s','%s');\n",
          olsr_ip_to_string(&strbuf1, &entry->originator),
          entry->names->name, olsr_ip_to_string(&strbuf2, &entry->names->ip),
          lookup_name_latlon(&entry->originator)))
        {
          return;
        }
      }
    }
  }

  OLSR_FOR_ALL_TC_ENTRIES(tc) {
  OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
    char* lla = lookup_position_latlon(&tc->addr);
    char* llb = lookup_position_latlon(&tc_edge->T_dest_addr);
    if (NULL != lla && NULL != llb)
    {
      /*
       * To speed up processing, Links with both positions are named PLink()
       */
      if (0 > fprintf(fmap, "PLink('%s','%s',%f,%f,%f,%s,%s);\n", 
            olsr_ip_to_string(&strbuf1, &tc_edge->T_dest_addr),
            olsr_ip_to_string(&strbuf2, &tc->addr), 
            tc_edge->link_quality,
            tc_edge->inverse_link_quality,
            (tc_edge->link_quality * tc_edge->inverse_link_quality) ?
              1.0 / (tc_edge->link_quality * tc_edge->inverse_link_quality) : 0.0,
            lla, llb))
      {
        return;
      }
    }
    else
    {
      /*
       * If one link end pos is unkown, only send Link()
       */
      if (0 > fprintf(fmap, "Link('%s','%s',%f,%f,%f);\n", 
            olsr_ip_to_string(&strbuf1, &tc_edge->T_dest_addr),
            olsr_ip_to_string(&strbuf2, &tc->addr), 
            tc_edge->link_quality,
            tc_edge->inverse_link_quality,
            (tc_edge->link_quality * tc_edge->inverse_link_quality) ?
              1.0 / (tc_edge->link_quality * tc_edge->inverse_link_quality) : 0.0))
      {
        return;
      }
    }
  } OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
  } OLSR_FOR_ALL_TC_ENTRIES_END(tc);
}

#ifndef WIN32

/*
 * Windows doesn't know fifo's AFAIK. We better write
 * to a file (done in nameservice.c, see #ifdef WIN32)
 */
 
static const char* the_fifoname = 0;
static int fifopolltime = 0;

static void mapwrite_poll(void)
{
  fifopolltime++;
  if (0 == (fifopolltime & 7) && 0 != the_fifoname)
  {
    FILE * fout;
    /* Non-blocking means: fail open if no pipe reader */
    int fd = open(the_fifoname, O_WRONLY | O_NONBLOCK);
    if (0 <= fd)
    {
      /* 
       * Change to blocking, otherwhise expect fprintf errors
       */
      fcntl(fd, F_SETFL, O_WRONLY);
      fout = fdopen(fd, "w");
      if (0 != fout)
      {
        mapwrite_work(fout);
        fclose(fout);
        /* Give pipe reader cpu slot to detect EOF */
        usleep(1);
      }
      else
      {
        close(fd);
      }
    }
  }
}

int mapwrite_init(const char* fifoname)
{
  the_fifoname = fifoname;
  if (0 != fifoname && 0 != *fifoname)
  {
    unlink(fifoname);
    if (0 > mkfifo(fifoname, S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH))
    {
      OLSR_PRINTF(1, "mkfifo(%s): %s", fifoname, strerror(errno));
      return OLSR_FALSE;
    }
    else
    {
      the_fifoname = fifoname;
      olsr_register_timeout_function(&mapwrite_poll, OLSR_FALSE);
    }
  }
  return OLSR_TRUE;
}

void mapwrite_exit(void)
{
  if (0 != the_fifoname)
  {
    unlink(the_fifoname);
    /* Ignore any Error */
    the_fifoname = 0;
  }
}
#endif

/*
 * Local Variables:
 * mode: c
 * c-indent-tabs-mode: t
 * c-basic-offset: 4
 * tab-width: 4
 * End:
 */

Index: nameservice.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/nameservice/src/nameservice.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** nameservice.h	16 Nov 2007 19:12:55 -0000	1.16
--- nameservice.h	29 Nov 2007 00:26:16 -0000	1.17
***************
*** 48,51 ****
--- 48,53 ----
  #include "olsrd_plugin.h"
  #include "nameservice_msg.h"
+ #include "hashing.h"
+ #include "mapwrite.h"
  
  #define PLUGIN_NAME	"OLSRD nameservice plugin"
***************
*** 104,107 ****
--- 106,112 ----
  };
  
+ extern struct name_entry *my_names;
+ extern struct db_entry* latlon_list[HASHSIZE];
+ extern float my_lat, my_lon;
  
  /* Timeout function to register with the sceduler */

Index: nameservice.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/nameservice/src/nameservice.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** nameservice.c	29 Nov 2007 00:10:17 -0000	1.38
--- nameservice.c	29 Nov 2007 00:26:16 -0000	1.39
***************
*** 60,63 ****
--- 60,64 ----
  #include "plugin_util.h"
  #include "nameservice.h"
+ #include "mapwrite.h"
  #include "olsrd_copy.h"
  #include "compat.h"
***************
*** 74,78 ****
  static char latlon_in_file[MAX_FILE + 1];
  static char my_latlon_file[MAX_FILE + 1];
! static float my_lat = 0.0, my_lon = 0.0;
  
  /* the databases (using hashing)
--- 75,79 ----
  static char latlon_in_file[MAX_FILE + 1];
  static char my_latlon_file[MAX_FILE + 1];
! float my_lat = 0.0, my_lon = 0.0;
  
  /* the databases (using hashing)
***************
*** 83,87 ****
   * */
  static struct db_entry* list[HASHSIZE];
! static struct name_entry *my_names = NULL;
  static olsr_bool name_table_changed = OLSR_TRUE;
  
--- 84,88 ----
   * */
  static struct db_entry* list[HASHSIZE];
! struct name_entry *my_names = NULL;
  static olsr_bool name_table_changed = OLSR_TRUE;
  
***************
*** 94,98 ****
  static olsr_bool forwarder_table_changed = OLSR_TRUE;
  
! static struct db_entry* latlon_list[HASHSIZE];
  static olsr_bool latlon_table_changed = OLSR_TRUE;
  
--- 95,99 ----
  static olsr_bool forwarder_table_changed = OLSR_TRUE;
  
! struct db_entry* latlon_list[HASHSIZE];
  static olsr_bool latlon_table_changed = OLSR_TRUE;
  
***************
*** 119,123 ****
  	GetWindowsDirectory(my_hosts_file, MAX_FILE - 12);
  	GetWindowsDirectory(my_services_file, MAX_FILE - 12);
! 	GetWindowsDirectory(my_latlon_file, MAX_FILE - 12);
  
  	len = strlen(my_hosts_file);
--- 120,124 ----
  	GetWindowsDirectory(my_hosts_file, MAX_FILE - 12);
  	GetWindowsDirectory(my_services_file, MAX_FILE - 12);
! 	GetWindowsDirectory(my_resolv_file, MAX_FILE - 12);
  
  	len = strlen(my_hosts_file);
***************
*** 135,152 ****
  		my_resolv_file[len++] = '\\';
  	strcpy(my_resolv_file + len, "resolvconf_olsr");
- 
- 	len = strlen(my_latlon_file);
- 	if (my_latlon_file[len - 1] != '\\')
- 		my_latlon_file[len++] = '\\';
- 	strcpy(my_latlon_file + len, "latlon.js");
  #else
  	strcpy(my_hosts_file, "/var/run/hosts_olsr");
  	strcpy(my_services_file, "/var/run/services_olsr");
  	strcpy(my_resolv_file, "/var/run/resolvconf_olsr");
- 	strcpy(my_latlon_file, "/var/run/latlon.js");
  #endif
  
  	my_suffix[0] = '\0';
  	my_add_hosts[0] = '\0';
  	latlon_in_file[0] = '\0';
  	
--- 136,148 ----
  		my_resolv_file[len++] = '\\';
  	strcpy(my_resolv_file + len, "resolvconf_olsr");
  #else
  	strcpy(my_hosts_file, "/var/run/hosts_olsr");
  	strcpy(my_services_file, "/var/run/services_olsr");
  	strcpy(my_resolv_file, "/var/run/resolvconf_olsr");
  #endif
  
  	my_suffix[0] = '\0';
  	my_add_hosts[0] = '\0';
+ 	my_latlon_file[0] = '\0';
  	latlon_in_file[0] = '\0';
  	
***************
*** 357,363 ****
  
  	for (name = my_names; name != NULL; name = name->next) {
! 		if (memcmp(&name->ip, &ipz, olsr_cnf->ipsize) == 0) {
  			OLSR_PRINTF(2, "NAME PLUGIN: insert main addr for name %s \n", name->name);
! 			memcpy(&name->ip, &olsr_cnf->main_addr, olsr_cnf->ipsize);
  		}
  	}
--- 353,359 ----
  
  	for (name = my_names; name != NULL; name = name->next) {
! 		if (ipequal(&name->ip, &ipz)) {
  			OLSR_PRINTF(2, "NAME PLUGIN: insert main addr for name %s \n", name->name);
! 			name->ip = olsr_cnf->main_addr;
  		}
  	}
***************
*** 365,369 ****
  		if (name->ip.v4.s_addr == 0) {
  			OLSR_PRINTF(2, "NAME PLUGIN: insert main addr for name %s \n", name->name);
! 			memcpy(&name->ip, &olsr_cnf->main_addr, olsr_cnf->ipsize);
  		}
  	}
--- 361,365 ----
  		if (name->ip.v4.s_addr == 0) {
  			OLSR_PRINTF(2, "NAME PLUGIN: insert main addr for name %s \n", name->name);
! 			name->ip = olsr_cnf->main_addr;
  		}
  	}
***************
*** 379,382 ****
--- 375,379 ----
  	olsr_register_timeout_function(&olsr_timeout, OLSR_TRUE);
  	olsr_register_scheduler_event(&olsr_event, NULL, my_interval, 0, NULL);
+ 	mapwrite_init(my_latlon_file);
  
  	return 1;
***************
*** 452,456 ****
  	regfree(&regex_t_name);
  	regfree(&regex_t_service);
! 	
  }
  
--- 449,453 ----
  	regfree(&regex_t_name);
  	regfree(&regex_t_service);
! 	mapwrite_exit();
  }
  
***************
*** 508,514 ****
--- 505,513 ----
  			write_services_file(); // if service_table_changed
  			break;
+ #ifdef WIN32
  		case 4:
  			write_latlon_file(); // latlon_table_changed
  			break;
+ #endif
  		default:
  			timeout_roundrobin = 0;
***************
*** 647,651 ****
  	/* Check if message originated from this node. 
  	If so - back off */
! 	if(memcmp(&originator, &olsr_cnf->main_addr, olsr_cnf->ipsize) == 0)
  		return;
  
--- 646,650 ----
  	/* Check if message originated from this node. 
  	If so - back off */
! 	if(ipequal(&originator, &olsr_cnf->main_addr))
  		return;
  
***************
*** 762,766 ****
  	to->type = htons(from->type);
  	to->len = htons(from->len);
! 	memcpy(&to->ip, &from->ip, olsr_cnf->ipsize);
  	pos += sizeof(struct name);
  	strncpy(pos, from->name, from->len);
--- 761,765 ----
  	to->type = htons(from->type);
  	to->len = htons(from->len);
! 	to->ip = from->ip;
  	pos += sizeof(struct name);
  	strncpy(pos, from->name, from->len);
***************
*** 788,792 ****
  		type_of_from_packet, len_of_name, name);
  
! 	//XXX: should I check the from_packet->ip here? If so, why not also check the ip fro HOST and SERVICE?
  	if( (type_of_from_packet==NAME_HOST && !is_name_wellformed(name)) ||
  		(type_of_from_packet==NAME_SERVICE && !is_service_wellformed(name)) ||
--- 787,791 ----
  		type_of_from_packet, len_of_name, name);
  
! 	//XXX: should I check the from_packet->ip here? If so, why not also check the ip from HOST and SERVICE?
  	if( (type_of_from_packet==NAME_HOST && !is_name_wellformed(name)) ||
  		(type_of_from_packet==NAME_SERVICE && !is_service_wellformed(name)) ||
***************
*** 799,803 ****
  	//ignore all packets with a too long name
  	//or a spoofed len of its included name string
! 	if (len_of_name > MAX_NAME || strlen(name) != len_of_name) {
  		OLSR_PRINTF(4, "NAME PLUGIN: from_packet->len %d > MAX_NAME %d or from_packet->len %d !0 strlen(name [%s] in packet)\n",
  			len_of_name, MAX_NAME, len_of_name, name );
--- 798,802 ----
  	//ignore all packets with a too long name
  	//or a spoofed len of its included name string
! 	if (len_of_name > MAX_NAME || strlen(name) != len_of_name || NULL != strchr(name, '\\') || NULL != strchr(name, '\'')) {
  		OLSR_PRINTF(4, "NAME PLUGIN: from_packet->len %d > MAX_NAME %d or from_packet->len %d !0 strlen(name [%s] in packet)\n",
  			len_of_name, MAX_NAME, len_of_name, name );
***************
*** 837,841 ****
  					olsr_ip_to_string(&strbuf2, &from_packet->ip),
  					olsr_ip_to_string(&strbuf3, &already_saved_name_entries->ip));
! 				memcpy(&already_saved_name_entries->ip, &from_packet->ip, olsr_cnf->ipsize);
  				*this_table_changed = OLSR_TRUE;
  			}
--- 836,840 ----
  					olsr_ip_to_string(&strbuf2, &from_packet->ip),
  					olsr_ip_to_string(&strbuf3, &already_saved_name_entries->ip));
! 				already_saved_name_entries->ip = from_packet->ip;
  				*this_table_changed = OLSR_TRUE;
  			}
***************
*** 854,858 ****
  	tmp->len = len_of_name > MAX_NAME ? MAX_NAME : ntohs(from_packet->len);
  	tmp->name = olsr_malloc(tmp->len+1, "new name_entry name");
! 	memcpy(&tmp->ip, &from_packet->ip, olsr_cnf->ipsize);
  	strncpy(tmp->name, name, tmp->len);
  	tmp->name[tmp->len] = '\0';
--- 853,857 ----
  	tmp->len = len_of_name > MAX_NAME ? MAX_NAME : ntohs(from_packet->len);
  	tmp->name = olsr_malloc(tmp->len+1, "new name_entry name");
! 	tmp->ip = from_packet->ip;
  	strncpy(tmp->name, name, tmp->len);
  	tmp->name[tmp->len] = '\0';
***************
*** 942,946 ****
  	for (entry = this_list[hash]; entry != NULL; entry = entry->next)
  	{
! 		if (memcmp(originator, &entry->originator, olsr_cnf->ipsize) == 0) {
  #ifndef NODEBUG
  			struct ipaddr_str strbuf;
--- 941,945 ----
  	for (entry = this_list[hash]; entry != NULL; entry = entry->next)
  	{
! 		if (ipequal(originator, &entry->originator)) {
  #ifndef NODEBUG
  			struct ipaddr_str strbuf;
***************
*** 967,971 ****
  		entry = olsr_malloc(sizeof(struct db_entry), "new db_entry");
  
! 		memcpy(&entry->originator, originator, olsr_cnf->ipsize);
  		olsr_get_timestamp(vtime * 1000, &entry->timer);
  		entry->names = NULL;
--- 966,970 ----
  		entry = olsr_malloc(sizeof(struct db_entry), "new db_entry");
  
! 		entry->originator = *originator;
  		olsr_get_timestamp(vtime * 1000, &entry->timer);
  		entry->names = NULL;
***************
*** 1446,1457 ****
  void lookup_defhna_latlon(union olsr_ip_addr *ip)
  {
! 	union olsr_ip_addr dest;
! 	struct rt_entry* rt_hna;
! 	memset(ip, 0, sizeof(ip));
! 	memset(&dest, 0, sizeof(dest));
! 	if (NULL != (rt_hna = olsr_lookup_routing_table(&dest))) {
! 		//COPY_IP(ip, &rt_hna->rt_best->rtp_nexthop.gateway);
! 		*ip = rt_hna->rt_best->rtp_nexthop.gateway;
! 	}
  }
  
--- 1445,1458 ----
  void lookup_defhna_latlon(union olsr_ip_addr *ip)
  {
!   struct avl_node *rt_tree_node;
!   struct olsr_ip_prefix prefix;
! 
!   memset(ip, 0, sizeof(ip));
!   memset(&prefix, 0, sizeof(prefix));
! 
!   if (NULL != (rt_tree_node = avl_find(&routingtree, &prefix)))
!   {
!     *ip = ((struct rt_entry *)rt_tree_node->data)->rt_best->rtp_nexthop.gateway;
!   }
  }
  
***************
*** 1478,1481 ****
--- 1479,1483 ----
  }
  
+ #ifdef WIN32
  /**
   * write latlon positions to a javascript file
***************
*** 1484,1582 ****
  write_latlon_file(void)
  {
! 	int hash;
! 	FILE* js;
! 	struct olsr_if *ifs;
! 	union olsr_ip_addr ip;
! 	struct ipaddr_str strbuf1, strbuf2;
! 	struct tc_entry *tc;
! 	struct tc_edge_entry *tc_edge;
! 
! 	if (!my_names || !latlon_table_changed) {
! 		return;
! 	}
! 	OLSR_PRINTF(2, "NAME PLUGIN: writing latlon file\n");
! 
! 	js = fopen( my_latlon_file, "w" );
! 	if (js == NULL) {
! 		OLSR_PRINTF(0, "NAME PLUGIN: cant write latlon file\n");
! 		return;
! 	}
! 	fprintf(js, "/* This file is overwritten regularly by olsrd */\n");
! 
! 	for (ifs = olsr_cnf->interfaces; ifs; ifs = ifs->next)
! 	{
! 		if (0 != ifs->interf)
! 		{
! 			if (olsr_cnf->ip_version == AF_INET)
! 			{
! 				/*
! 				 * Didn't find a good sample to grab a simple
! 				 * olsr_ip_addr from a given interface. Sven-Ola
! 				 */
! 				const char* p = olsr_ip_to_string(&strbuf1, &olsr_cnf->main_addr);
! 				const char* q = ip4_to_string(&strbuf1, ifs->interf->int_addr.sin_addr);
! 				if (0 != strcmp(p, q))
! 				{
! 					fprintf(js, "Mid('%s','%s');\n", p, q);
! 				}
! 			}
! 			else if (!(ipequal(&olsr_cnf->main_addr, (union olsr_ip_addr *)&ifs->interf->int6_addr.sin6_addr)))
! 			{
! 				fprintf(js, "Mid('%s','%s');\n",
! 					olsr_ip_to_string(&strbuf1, &olsr_cnf->main_addr),
! 					olsr_ip_to_string(&strbuf2, (union olsr_ip_addr *)&ifs->interf->int6_addr.sin6_addr));
! 			}
! 		}
! 	}
! 
! 	for (hash = 0; hash < HASHSIZE; hash++) 
! 	{
! 		struct mid_entry *entry = mid_set[hash].next;
! 		while(entry != &mid_set[hash])
! 		{
! 			struct mid_address *alias = entry->aliases;
! 			while(alias)
! 			{
! 				fprintf(js, "Mid('%s','%s');\n",
! 						olsr_ip_to_string(&strbuf1, &entry->main_addr),
! 						olsr_ip_to_string(&strbuf2, &alias->alias));
! 				alias = alias->next_alias;
! 			}
! 			entry = entry->next;
! 		}
! 	}
! 	lookup_defhna_latlon(&ip);
! 	fprintf(js, "Self('%s',%f,%f,%d,'%s','%s');\n", olsr_ip_to_string(&strbuf1, &olsr_cnf->main_addr),
! 			my_lat, my_lon, get_isdefhna_latlon(), olsr_ip_to_string(&strbuf2, &ip), my_names->name);
! 	for (hash = 0; hash < HASHSIZE; hash++) 
! 	{
! 		struct db_entry *entry;
! 		for(entry = latlon_list[hash]; entry != NULL; entry = entry->next)
! 		{
! 			struct name_entry *name;
! 			for (name = entry->names; name != NULL; name = name->next) 
! 			{
! 				fprintf(js, "Node('%s',%s,'%s','%s');\n",
! 					olsr_ip_to_string(&strbuf1, &entry->originator),
! 					name->name, olsr_ip_to_string(&strbuf2, &name->ip),
! 					lookup_name_latlon(&entry->originator));
! 			}
! 		}
! 	}
! 
! 	OLSR_FOR_ALL_TC_ENTRIES(tc) {
! 		OLSR_FOR_ALL_TC_EDGE_ENTRIES(tc, tc_edge) {
! 			fprintf(js, "Link('%s','%s',%f,%f,%f);\n", 
! 					olsr_ip_to_string(&strbuf1, &tc_edge->T_dest_addr),
! 					olsr_ip_to_string(&strbuf2, &tc->addr), 
! 					tc_edge->link_quality,
! 					tc_edge->inverse_link_quality,
! 					olsr_calc_tc_etx(tc_edge));
! 		} OLSR_FOR_ALL_TC_EDGE_ENTRIES_END(tc, tc_edge);
! 	} OLSR_FOR_ALL_TC_ENTRIES_END(tc);
  
! 	fclose(js);
! 	latlon_table_changed = OLSR_FALSE;
  }
  
  /*
--- 1486,1505 ----
  write_latlon_file(void)
  {
!   FILE* fmap;
!   
!   if (!my_names || !latlon_table_changed) return;
!   
!   OLSR_PRINTF(2, "NAME PLUGIN: writing latlon file\n");
  
!   if (NULL == (fmap = fopen(my_latlon_file, "w"))) {
!     OLSR_PRINTF(0, "NAME PLUGIN: cant write latlon file\n");
!     return;
!   }
!   fprintf(fmap, "/* This file is overwritten regularly by olsrd */\n");
!   mapwrite_work(fmap);  
!   fclose(fmap);
!   latlon_table_changed = OLSR_FALSE;
  }
+ #endif
  
  /*

--- NEW FILE: mapwrite.h ---
/*
 * Copyright (c) 2007, Sven-Ola <sven-ola-aet-gmx.de>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met:
 *
 * * Redistributions of source code must retain the above copyright notice, 
 *   this list of conditions and the following disclaimer.
 * * Redistributions in binary form must reproduce the above copyright notice, 
 *   this list of conditions and the following disclaimer in the documentation 
 *   and/or other materials provided with the distribution.
 * * Neither the name of the UniK olsr daemon nor the names of its contributors 
 *   may be used to endorse or promote products derived from this software 
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

/* $Id: mapwrite.h,v 1.1 2007/11/29 00:26:16 bernd67 Exp $ */
 
#ifndef _MAPWRITE_H
#define _MAPWRITE_H

int mapwrite_init(const char* fifoname);
void mapwrite_work(FILE* fmap);
void mapwrite_exit(void);

#endif /* _MAPWRITE_H */

/*
 * Local Variables:
 * mode: c
 * c-indent-tabs-mode: t
 * c-basic-offset: 4
 * tab-width: 4
 * End:
 */





More information about the Olsr-cvs mailing list