[Olsr-cvs] olsrd-current/lib/nameservice/src nameservice.c, 1.25, 1.26 olsrd_plugin.c, 1.14, 1.15

Bernd Petrovitsch (spam-protected)
Sat Aug 25 21:48:44 CEST 2007


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

Modified Files:
	nameservice.c olsrd_plugin.c 
Log Message:
* Patch from Sven-Ola Tuecke to convert more plugins to the new interface.


Index: nameservice.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/nameservice/src/nameservice.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** nameservice.c	23 Aug 2007 21:01:56 -0000	1.25
--- nameservice.c	25 Aug 2007 19:48:42 -0000	1.26
***************
*** 3,6 ****
--- 3,7 ----
   * Copyright (c) 2005, Bruno Randolf <(spam-protected)>
   * Copyright (c) 2004, Andreas Tønnesen(andreto-at-olsr.org)
+  * Copyright (c) 2007, Sven-Ola <(spam-protected)>
   * All rights reserved.
   *
***************
*** 57,60 ****
--- 58,62 ----
  #include "link_set.h"
  
+ #include "plugin_util.h"
  #include "nameservice.h"
  #include "olsrd_copy.h"
***************
*** 167,259 ****
  
  
! /**
!  * called for all plugin parameters
!  */
! int
! olsrd_plugin_register_param(char *key, char *value)
  {
! 	if(!strcmp(key, "interval")) {
! 		my_interval = atoi(value);
! 		OLSR_PRINTF(1, "\nNAME PLUGIN: parameter interval: %d\n", my_interval);
! 	}
! 	else if(!strcmp(key, "timeout")) {
! 		my_timeout = atof(value);
! 		OLSR_PRINTF(1, "\nNAME PLUGIN: parameter timeout: %f\n", my_timeout);
! 	} 
! 	else if(!strcmp(key, "hosts-file")) {
! 		strncpy( my_hosts_file, value, MAX_FILE );
! 		OLSR_PRINTF(1, "\nNAME PLUGIN: parameter filename: %s\n", my_hosts_file);
! 	}
! 	else if(!strcmp(key, "resolv-file")) {
! 		strncpy(my_resolv_file, value, MAX_FILE);
! 		OLSR_PRINTF(1, "\nNAME PLUGIN: parameter resolv file: %s\n", my_resolv_file);
! 	}
! 	else if(!strcmp(key, "suffix")) {
! 		strncpy(my_suffix, value, MAX_SUFFIX);
! 		OLSR_PRINTF(1, "\nNAME PLUGIN: parameter suffix: %s\n", my_suffix);
! 	}
! 	else if(!strcmp(key, "add-hosts")) {
! 		strncpy(my_add_hosts, value, MAX_FILE);
! 		OLSR_PRINTF(1, "\nNAME PLUGIN: parameter additional host: %s\n", my_add_hosts);
! 	}
! 	else if(!strcmp(key, "services-file")) {
! 		strncpy(my_services_file, value, MAX_FILE);
! 		OLSR_PRINTF(1,"\nNAME PLUGIN: parameter services-file: %s", my_services_file);
! 	}
! 	else if(!strcmp(key, "lat")) {
! 		my_lat = atof(value);
! 		OLSR_PRINTF(1,"\nNAME PLUGIN: parameter lat: %f\n", my_lat);
! 	}
! 	else if(!strcmp(key, "lon")) {
! 		my_lon = atof(value);
! 		OLSR_PRINTF(1,"\nNAME PLUGIN: parameter lon: %f\n", my_lon);
  	}
! 	else if(!strcmp(key, "latlon-file")) {
! 		strncpy( my_latlon_file, value, MAX_FILE );
! 		OLSR_PRINTF(1, "\nNAME PLUGIN: parameter latlon-file: %s\n", my_latlon_file);
  	}
! 	else if(!strcmp(key, "latlon-infile")) {
! 		strncpy( latlon_in_file, value, MAX_FILE );
! 		OLSR_PRINTF(1, "\nNAME PLUGIN: parameter latlon-infile: %s\n", latlon_in_file);
  	}
! 	else if(!strcmp(key, "dns-server")) {
! 		union olsr_ip_addr ip;
! 		if (strlen(value) == 0) {
! 			my_forwarders = add_name_to_list(my_forwarders, "", NAME_FORWARDER, NULL);
! 			OLSR_PRINTF(1,"\nNAME PLUGIN: parameter dns-server: (main address)");
! 		} else if (inet_pton(olsr_cnf->ip_version, value, &ip) > 0) {
! 			my_forwarders = add_name_to_list(my_forwarders, "", NAME_FORWARDER, &ip);
! 			OLSR_PRINTF(1,"\nNAME PLUGIN: parameter dns-server: (%s)", value);
! 		} else {
! 			OLSR_PRINTF(1,"\nNAME PLUGIN: invalid parameter dns-server: %s ", value);
! 		}
  	}
! 	else if(!strcmp(key, "name")) {
! 		// name for main address
! 		my_names = add_name_to_list(my_names, value, NAME_HOST, NULL);
! 		OLSR_PRINTF(1,"\nNAME PLUGIN: parameter name: %s (main address)", value);
  	}
! 	else if(!strcmp(key, "service")) {
! 		// name for main address
! 		my_services = add_name_to_list(my_services, value, NAME_SERVICE, NULL);
! 		OLSR_PRINTF(1,"\nNAME PLUGIN: parameter service: %s (main address)", value);
  	}
! 	else {
! 		// assume this is an IP address and hostname
! 		union olsr_ip_addr ip;
! 		
! 		if (inet_pton(olsr_cnf->ip_version, key, &ip) > 0) {
! 			// the IP is validated later
! 			my_names = add_name_to_list(my_names, value, NAME_HOST, &ip);
! 			OLSR_PRINTF(1,"\nNAME PLUGIN: parameter name %s (%s)", value, key);
! 		} 
! 		else {
! 			OLSR_PRINTF(1, "\nNAME PLUGIN: invalid IP %s for name %s!\n", key, value);
! 		}
  	}
- 
  	return 1;
  }
  
  
  /**
--- 169,270 ----
  
  
! static int set_nameservice_server(const char *value, void *data, unsigned int addon)
  {
! 	union olsr_ip_addr ip;
! 	struct name_entry **v = data;
! 	if (0 == strlen(value))
! 	{
! 		*v = add_name_to_list(*v, "", addon, NULL);
!                 OLSR_PRINTF(1, "%s got %s (main address)\n", "Got", value);
! 		return 0;
  	}
! 	else if (0 < inet_pton(olsr_cnf->ip_version, value, &ip))
! 	{
! 		*v = add_name_to_list(*v, "", addon, &ip);
!                 OLSR_PRINTF(1, "%s got %s\n", "Got", value);
! 		return 0;
  	}
! 	else
! 	{
!                 OLSR_PRINTF(0, "Illegal IP address \"%s\"", value);
  	}
! 	return 1;
! }
! 
! static int set_nameservice_name(const char *value, void *data, unsigned int addon)
! {
! 	struct name_entry **v = data;
! 	if (0 < strlen(value))
! 	{
! 		*v = add_name_to_list(*v, (char*)value, addon, NULL);
!                 OLSR_PRINTF(1, "%s got %s (main address)\n", "Got", value);
! 		return 0;
  	}
! 	else
! 	{
!                 OLSR_PRINTF(0, "Illegal name \"%s\"", value);
  	}
! 	return 1;
! }
! 
! static int set_nameservice_host(const char *value, void *data, unsigned int addon)
! {
! 	union olsr_ip_addr ip;
! 	struct name_entry **v = data;
! 	if (0 < inet_pton(olsr_cnf->ip_version, (char*)addon, &ip))
! 	{
! 		// the IP is validated later
! 		*v = add_name_to_list(*v, (char*)value, addon, &ip);
!                 OLSR_PRINTF(1, "%s: %s got %s\n", "Got", (char*) addon, value);
! 		return 0;
  	}
! 	else
! 	{
!                 OLSR_PRINTF(0, "%s: Illegal IP address \"%s\"", (char*) addon, value);
  	}
  	return 1;
  }
  
+ static int set_nameservice_float(const char *value, void *data, unsigned int addon)
+ {
+     const float thefloat = atof(value);
+     if (addon) {}
+     if (data != NULL)
+     {
+         float *v = data;
+         *v = thefloat;
+         OLSR_PRINTF(1, "%s float %f\n", "Got", thefloat);
+     }
+     else
+     {
+         OLSR_PRINTF(0, "%s float %f\n", "Ignored", thefloat);
+     }
+     return 0;
+ }
+ 
+ static const struct olsrd_plugin_parameters plugin_parameters[] = {
+     { .name = "interval",      .set_plugin_parameter = &set_plugin_int,         .data = &my_interval },
+     { .name = "timeout",       .set_plugin_parameter = &set_nameservice_float,  .data = &my_timeout },
+     { .name = "hosts-file",    .set_plugin_parameter = &set_plugin_string,      .data = &my_hosts_file,    .addon = sizeof(my_hosts_file) },
+     { .name = "resolv-file",   .set_plugin_parameter = &set_plugin_string,      .data = &my_resolv_file,   .addon = sizeof(my_resolv_file) },
+     { .name = "suffix",        .set_plugin_parameter = &set_plugin_string,      .data = &my_suffix,        .addon = sizeof(my_suffix) },
+     { .name = "add-hosts",     .set_plugin_parameter = &set_plugin_string,      .data = &my_add_hosts,     .addon = sizeof(my_add_hosts) },
+     { .name = "services-file", .set_plugin_parameter = &set_plugin_string,      .data = &my_services_file, .addon = sizeof(my_services_file) },
+     { .name = "lat",           .set_plugin_parameter = &set_nameservice_float,  .data = &my_lat },
+     { .name = "lon",           .set_plugin_parameter = &set_nameservice_float,  .data = &my_lon },
+     { .name = "latlon-file",   .set_plugin_parameter = &set_plugin_string,      .data = &my_latlon_file,   .addon = sizeof(my_latlon_file) },
+     { .name = "latlon-infile", .set_plugin_parameter = &set_plugin_string,      .data = &latlon_in_file,   .addon = sizeof(latlon_in_file) },
+     { .name = "dns-server",    .set_plugin_parameter = &set_nameservice_server, .data = &my_forwarders,    .addon = NAME_FORWARDER },
+     { .name = "name",          .set_plugin_parameter = &set_nameservice_name,   .data = &my_names,         .addon = NAME_HOST },
+     { .name = "service",       .set_plugin_parameter = &set_nameservice_name,   .data = &my_services,      .addon = NAME_SERVICE },
+     { .name = "",              .set_plugin_parameter = &set_nameservice_host,   .data = &my_names,         .addon = NAME_HOST },
+ };
+ 
+ void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
+ {
+     *params = plugin_parameters;
+     *size = sizeof(plugin_parameters)/sizeof(*plugin_parameters);
+ }
+ 
  
  /**

Index: olsrd_plugin.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/nameservice/src/olsrd_plugin.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** olsrd_plugin.c	15 Jul 2007 17:41:33 -0000	1.14
--- olsrd_plugin.c	25 Aug 2007 19:48:42 -0000	1.15
***************
*** 46,50 ****
  #define PLUGIN_AUTHOR   "Bruno Randolf, Jens Nachtigall, Sven-Ola"
  #define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION
! #define PLUGIN_INTERFACE_VERSION 4
  
  
--- 46,50 ----
  #define PLUGIN_AUTHOR   "Bruno Randolf, Jens Nachtigall, Sven-Ola"
  #define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION
! #define PLUGIN_INTERFACE_VERSION 5
  
  





More information about the Olsr-cvs mailing list