[Olsr-cvs] olsrd-current/lib/dot_draw/src olsrd_dot_draw.c, 1.24, 1.25 olsrd_dot_draw.h, 1.8, 1.9 olsrd_plugin.c, 1.15, 1.16

Bernd Petrovitsch (spam-protected)
Sun Jul 15 21:29:39 CEST 2007


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

Modified Files:
	olsrd_dot_draw.c olsrd_dot_draw.h olsrd_plugin.c 
Log Message:

I started to clean up the plugin parameter handling:
* Up to now some used case-insensitive, some used case-sensitive (with
  differing cases BTW) parameter names.
* Most plugins silently ignored unknown parameters.
This makes it hard to find errors in the olsrd.conf file.
Instead of simply fixing all the various plugins (and the mostly - more
or less - copied code), I reduced the plugin special code to a minimum
and (more or less automatically) all plugins behave the same (with
respect to the parameter handling).

How does it look now?
Every plugins exports a table of { parameter-name, parse-function,
addr-of-storage } to allow to share more code, e.g. the parsing and
checking of a port number or IP addresses.
Every plugin will export a function
----  snip  ----
void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size);
----  snip  ----
which delivers the address of the table and it's size. So in theory the
plugin could generate the table at load time though ATM all current
ones export statically defined tables.

What else is different?
- I introduced SUPPORT_OLD_PLUGIN_VERSIONS to simplifiy the compile-time
  removal of legacy support. It is not that much but more of a start.
- Plugin interface version 4 is supported until all plugins are
  migrated.
- The plugin loader produces now much more output - on good and error
  cases. I had too often to look into the source to find that I mistyped
  some parameter .....

ToDo:
- Several plugins cannot handle IPv6 at all - only IPv4 is implemented.
  Some of these functions are locally now but fixed versions can (and
  should IMHO) be shared by all plugins.



Index: olsrd_dot_draw.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/dot_draw/src/olsrd_dot_draw.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** olsrd_dot_draw.h	20 Apr 2007 14:20:11 -0000	1.8
--- olsrd_dot_draw.h	15 Jul 2007 19:29:37 -0000	1.9
***************
*** 48,66 ****
  #define _OLSRD_DOT_DRAW
  
  
  extern struct in_addr ipc_accept_ip;
  extern int ipc_port;
  
! int 
! olsrd_plugin_interface_version(void);
! 
! int
! olsrd_plugin_init(void);
! 
! int
! olsrd_plugin_register_param(char *key, char *value);
! 
! void
! olsr_plugin_exit(void);
  
  #endif
--- 48,61 ----
  #define _OLSRD_DOT_DRAW
  
+ #include "olsrd_plugin.h"
+ #include "plugin_util.h"
  
  extern struct in_addr ipc_accept_ip;
  extern int ipc_port;
  
! int olsrd_plugin_interface_version(void);
! int olsrd_plugin_init(void);
! void olsr_plugin_exit(void);
! void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size);
  
  #endif

Index: olsrd_dot_draw.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/dot_draw/src/olsrd_dot_draw.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** olsrd_dot_draw.c	1 Jul 2007 01:17:38 -0000	1.24
--- olsrd_dot_draw.c	15 Jul 2007 19:29:37 -0000	1.25
***************
*** 237,243 ****
  	}
  
- 
        /* Register with olsrd */
!       printf("Adding socket with olsrd\n");
        add_olsr_socket(ipc_socket, &ipc_action);
        ipc_socket_up = 1;
--- 237,242 ----
  	}
  
        /* Register with olsrd */
!       //printf("Adding socket with olsrd\n");
        add_olsr_socket(ipc_socket, &ipc_action);
        ipc_socket_up = 1;

Index: olsrd_plugin.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/dot_draw/src/olsrd_plugin.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** olsrd_plugin.c	1 Jul 2007 01:17:38 -0000	1.15
--- olsrd_plugin.c	15 Jul 2007 19:29:37 -0000	1.16
***************
*** 43,48 ****
   * Dynamic linked library for the olsr.org olsr daemon
   */
- 
- 
  #include <stdio.h>
  #include <string.h>
--- 43,46 ----
***************
*** 61,76 ****
  #define PLUGIN_AUTHOR   "Andreas Tønnesen"
  #define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION " by " PLUGIN_AUTHOR
! #define PLUGIN_INTERFACE_VERSION 4
! 
  
  struct in_addr ipc_accept_ip;
  int ipc_port;
  
! 
! static void __attribute__ ((constructor)) 
! my_init(void);
! 
! static void __attribute__ ((destructor)) 
! my_fini(void);
  
  
--- 59,69 ----
  #define PLUGIN_AUTHOR   "Andreas Tønnesen"
  #define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION " by " PLUGIN_AUTHOR
! #define PLUGIN_INTERFACE_VERSION 5
  
  struct in_addr ipc_accept_ip;
  int ipc_port;
  
! static void my_init(void) __attribute__ ((constructor)) ;
! static void my_fini(void) __attribute__ ((destructor));
  
  
***************
*** 78,90 ****
   *Constructor
   */
! static void
! my_init(void)
  {
!   /* Print plugin info to stdout */
!   printf("%s\n", MOD_DESC);
  
!   /* defaults for parameters */
!   ipc_port = 2004;
!   ipc_accept_ip.s_addr = htonl(INADDR_LOOPBACK);
  }
  
--- 71,82 ----
   *Constructor
   */
! static void my_init(void)
  {
!     /* Print plugin info to stdout */
!     printf("%s\n", MOD_DESC);
  
!     /* defaults for parameters */
!     ipc_port = 2004;
!     ipc_accept_ip.s_addr = htonl(INADDR_LOOPBACK);
  }
  
***************
*** 93,133 ****
   *Destructor
   */
! static void
! my_fini(void)
  {
!   /* Calls the destruction function
!    * olsr_plugin_exit()
!    * This function should be present in your
!    * sourcefile and all data destruction
!    * should happen there - NOT HERE!
!    */
!   olsr_plugin_exit();
  }
  
  
! int 
! olsrd_plugin_interface_version(void)
  {
!   return PLUGIN_INTERFACE_VERSION;
  }
  
  
! int
! olsrd_plugin_register_param(char *key, char *value)
! {
!   if(!strcmp(key, "Port"))
!     {
!       ipc_port = atoi(value);
!       olsr_printf(0, "(DOT DRAW) listening on port: %d\n", ipc_port);
!       return 1;
!     }
  
!   if(!strcmp(key, "Accept"))
!     {
!       inet_aton(value, &ipc_accept_ip);
!       olsr_printf(0, "(DOT DRAW) accept only: %s\n", inet_ntoa(ipc_accept_ip));
!       return 1;
!     }
!   olsr_printf(0, "(DOT DRAW) ignored: %s=\"%s\"\n", key, value);
!   return 1;
  }
--- 85,123 ----
   *Destructor
   */
! static void my_fini(void)
  {
!     /* Calls the destruction function
!      * olsr_plugin_exit()
!      * This function should be present in your
!      * sourcefile and all data destruction
!      * should happen there - NOT HERE!
!      */
!     olsr_plugin_exit();
  }
  
  
! int  olsrd_plugin_interface_version(void)
  {
!     return PLUGIN_INTERFACE_VERSION;
  }
  
  
! static const struct olsrd_plugin_parameters plugin_parameters[] = {
!     { .name = "port",   .set_plugin_parameter = &set_plugin_port,      .data = &ipc_port },
!     { .name = "accept", .set_plugin_parameter = &set_plugin_ipaddress, .data = &ipc_accept_ip },
! };
  
! void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
! {
!     *params = plugin_parameters;
!     *size = sizeof(plugin_parameters)/sizeof(*plugin_parameters);
  }
+ 
+ /*
+  * Local Variables:
+  * mode: c
+  * style: linux
+  * c-basic-offset: 4
+  * indent-tabs-mode: nil
+  * End:
+  */





More information about the Olsr-cvs mailing list