[Olsr-cvs] olsrd-current/lib/httpinfo/src olsrd_httpinfo.c, 1.68, 1.69 olsrd_httpinfo.h, 1.29, 1.30 olsrd_plugin.h, 1.22, 1.23 olsrd_plugin.c, 1.16, 1.17
Bernd Petrovitsch
(spam-protected)
Sun Jul 15 21:29:40 CEST 2007
Update of /cvsroot/olsrd/olsrd-current/lib/httpinfo/src
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv5004/lib/httpinfo/src
Modified Files:
olsrd_httpinfo.c olsrd_httpinfo.h olsrd_plugin.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_httpinfo.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/httpinfo/src/olsrd_httpinfo.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -C2 -d -r1.68 -r1.69
*** olsrd_httpinfo.c 2 Jul 2007 10:20:24 -0000 1.68
--- olsrd_httpinfo.c 15 Jul 2007 19:29:38 -0000 1.69
***************
*** 131,192 ****
};
! static int
! get_http_socket(int);
!
! static int
! build_tabs(char *, olsr_u32_t, int);
!
! static void
! parse_http_request(int);
! int
! build_http_header(http_header_type, olsr_bool, olsr_u32_t, char *, olsr_u32_t);
! static int
! build_frame(char *, char *, int, char *, olsr_u32_t, int(*frame_body_cb)(char *, olsr_u32_t));
! int
! build_routes_body(char *, olsr_u32_t);
! int
! build_config_body(char *, olsr_u32_t);
! int
! build_neigh_body(char *, olsr_u32_t);
! int
! build_topo_body(char *, olsr_u32_t);
! int
! build_hna_body(char *, olsr_u32_t);
! int
! build_mid_body(char *, olsr_u32_t);
! int
! build_nodes_body(char *, olsr_u32_t);
! int
! build_all_body(char *, olsr_u32_t);
! int
! build_about_body(char *, olsr_u32_t);
! int
! build_cfgfile_body(char *, olsr_u32_t);
! char *
! sockaddr_to_string(struct sockaddr *);
! olsr_bool
! check_allowed_ip(union olsr_ip_addr *);
! static int
! build_ip_txt(char *buf, const olsr_u32_t bufsize, const olsr_bool want_link, const char * const ipstr, const char * const maskstr);
! static int
! build_ipaddr_link(char *buf, const olsr_u32_t bufsize, const olsr_bool want_link, union olsr_ip_addr * const ipaddr, const union hna_netmask * const mask);
static ssize_t writen(int fd, const void *buf, size_t count);
--- 131,171 ----
};
+ static int get_http_socket(int);
! static int build_tabs(char *, olsr_u32_t, int);
! static void parse_http_request(int);
! static int build_http_header(http_header_type, olsr_bool, olsr_u32_t, char *, olsr_u32_t);
! static int build_frame(char *, char *, int, char *, olsr_u32_t, int(*frame_body_cb)(char *, olsr_u32_t));
! static int build_routes_body(char *, olsr_u32_t);
! static int build_config_body(char *, olsr_u32_t);
! static int build_neigh_body(char *, olsr_u32_t);
! static int build_topo_body(char *, olsr_u32_t);
! static int build_hna_body(char *, olsr_u32_t);
! static int build_mid_body(char *, olsr_u32_t);
! static int build_nodes_body(char *, olsr_u32_t);
! static int build_all_body(char *, olsr_u32_t);
! static int build_about_body(char *, olsr_u32_t);
+ static int build_cfgfile_body(char *, olsr_u32_t);
! static int check_allowed_ip(const struct allowed_net * const allowed_nets, const union olsr_ip_addr * const addr);
! static int build_ip_txt(char *buf, const olsr_u32_t bufsize, const olsr_bool want_link, const char * const ipstr, const char * const maskstr);
+ static int build_ipaddr_link(char *buf, const olsr_u32_t bufsize, const olsr_bool want_link, union olsr_ip_addr * const ipaddr, const union hna_netmask * const mask);
! static char *olsr_netmask_to_string(union hna_netmask *);
static ssize_t writen(int fd, const void *buf, size_t count);
***************
*** 337,342 ****
int c = 0, r = 1, size = 0;
- addrlen = sizeof(struct sockaddr_in);
-
if(curr_clients >= MAX_CLIENTS)
return;
--- 316,319 ----
***************
*** 344,347 ****
--- 321,325 ----
curr_clients++;
+ addrlen = sizeof(struct sockaddr_in);
if ((client_sockets[curr_clients] = accept(fd, (struct sockaddr *) &pin, &addrlen)) == -1)
{
***************
*** 350,354 ****
}
! if(!check_allowed_ip((union olsr_ip_addr *)&pin.sin_addr.s_addr))
{
olsr_printf(1, "HTTP request from non-allowed host %s!\n",
--- 328,332 ----
}
! if(!check_allowed_ip(allowed_nets, (union olsr_ip_addr *)&pin.sin_addr.s_addr))
{
olsr_printf(1, "HTTP request from non-allowed host %s!\n",
***************
*** 625,630 ****
! int
! build_tabs(char *buf, const olsr_u32_t bufsize, int active)
{
int size = 0, i = 0, tabs = 0;
--- 603,607 ----
! static int build_tabs(char *buf, const olsr_u32_t bufsize, int active)
{
int size = 0, i = 0, tabs = 0;
***************
*** 679,689 ****
! static int
! build_frame(char *title __attribute__((unused)),
! char *link __attribute__((unused)),
! int width __attribute__((unused)),
! char *buf,
! olsr_u32_t bufsize,
! int(*frame_body_cb)(char *, olsr_u32_t))
{
int i = 0, size = 0;
--- 656,665 ----
! static int build_frame(char *title __attribute__((unused)),
! char *link __attribute__((unused)),
! int width __attribute__((unused)),
! char *buf,
! olsr_u32_t bufsize,
! int(*frame_body_cb)(char *, olsr_u32_t))
{
int i = 0, size = 0;
***************
*** 702,707 ****
}
! static int
! build_ip_txt(char *buf, const olsr_u32_t bufsize, const olsr_bool want_link, const char * const ipstr, const char * const maskstr)
{
int size = 0;
--- 678,682 ----
}
! static int build_ip_txt(char *buf, const olsr_u32_t bufsize, const olsr_bool want_link, const char * const ipstr, const char * const maskstr)
{
int size = 0;
***************
*** 723,728 ****
}
! static int
! build_ipaddr_link(char *buf, const olsr_u32_t bufsize, const olsr_bool want_link, union olsr_ip_addr * const ipaddr, const union hna_netmask * const mask)
{
int size = 0;
--- 698,702 ----
}
! static int build_ipaddr_link(char *buf, const olsr_u32_t bufsize, const olsr_bool want_link, union olsr_ip_addr * const ipaddr, const union hna_netmask * const mask)
{
int size = 0;
***************
*** 764,769 ****
#define build_ipaddr_no_link(buf, bufsize, ipaddr, mask) build_ipaddr_link((buf), (bufsize), OLSR_FALSE, (ipaddr), (mask))
! int
! build_routes_body(char *buf, olsr_u32_t bufsize)
{
int size = 0, index;
--- 738,742 ----
#define build_ipaddr_no_link(buf, bufsize, ipaddr, mask) build_ipaddr_link((buf), (bufsize), OLSR_FALSE, (ipaddr), (mask))
! static int build_routes_body(char *buf, olsr_u32_t bufsize)
{
int size = 0, index;
***************
*** 826,831 ****
}
! int
! build_config_body(char *buf, olsr_u32_t bufsize)
{
char systime[100];
--- 799,803 ----
}
! static int build_config_body(char *buf, olsr_u32_t bufsize)
{
char systime[100];
***************
*** 1022,1027 ****
! int
! build_neigh_body(char *buf, olsr_u32_t bufsize)
{
struct neighbor_entry *neigh;
--- 994,998 ----
! static int build_neigh_body(char *buf, olsr_u32_t bufsize)
{
struct neighbor_entry *neigh;
***************
*** 1110,1117 ****
}
!
!
! int
! build_topo_body(char *buf, olsr_u32_t bufsize)
{
int size = 0;
--- 1081,1085 ----
}
! static int build_topo_body(char *buf, olsr_u32_t bufsize)
{
int size = 0;
***************
*** 1165,1172 ****
}
!
!
! int
! build_hna_body(char *buf, olsr_u32_t bufsize)
{
int size;
--- 1133,1137 ----
}
! static int build_hna_body(char *buf, olsr_u32_t bufsize)
{
int size;
***************
*** 1209,1214 ****
! int
! build_mid_body(char *buf, olsr_u32_t bufsize)
{
int size = 0;
--- 1174,1178 ----
! static int build_mid_body(char *buf, olsr_u32_t bufsize)
{
int size = 0;
***************
*** 1247,1252 ****
! int
! build_nodes_body(char *buf, olsr_u32_t bufsize)
{
int size = 0;
--- 1211,1215 ----
! static int build_nodes_body(char *buf, olsr_u32_t bufsize)
{
int size = 0;
***************
*** 1260,1265 ****
}
! int
! build_all_body(char *buf, olsr_u32_t bufsize)
{
int size = 0;
--- 1223,1227 ----
}
! static int build_all_body(char *buf, olsr_u32_t bufsize)
{
int size = 0;
***************
*** 1276,1281 ****
! int
! build_about_body(char *buf, olsr_u32_t bufsize)
{
int size = 0, i = 0;
--- 1238,1242 ----
! static int build_about_body(char *buf, olsr_u32_t bufsize)
{
int size = 0, i = 0;
***************
*** 1288,1293 ****
}
! int
! build_cfgfile_body(char *buf, olsr_u32_t bufsize)
{
int size = 0, i = 0;
--- 1249,1253 ----
}
! static int build_cfgfile_body(char *buf, olsr_u32_t bufsize)
{
int size = 0, i = 0;
***************
*** 1324,1362 ****
}
!
! olsr_bool
! check_allowed_ip(union olsr_ip_addr *addr)
{
! struct allowed_host *allh = allowed_hosts;
! struct allowed_net *alln = allowed_nets;
!
! if(addr->v4 == ntohl(INADDR_LOOPBACK))
! return OLSR_TRUE;
!
! /* check hosts */
! while(allh)
! {
! if(addr->v4 == allh->host.v4)
! return OLSR_TRUE;
! allh = allh->next;
! }
!
! /* check nets */
! while(alln)
! {
! if((addr->v4 & alln->mask.v4) == (alln->net.v4 & alln->mask.v4))
! return OLSR_TRUE;
! alln = alln->next;
}
!
! return OLSR_FALSE;
}
/**
*This function is just as bad as the previous one :-(
*/
! char *
! olsr_netmask_to_string(union hna_netmask *mask)
{
char *ret;
--- 1284,1304 ----
}
! static int check_allowed_ip(const struct allowed_net * const allowed_nets, const union olsr_ip_addr * const addr)
{
! const struct allowed_net *alln;
! for (alln = allowed_nets; alln != NULL; alln = alln->next) {
! if((addr->v4 & alln->mask.v4) == (alln->net.v4 & alln->mask.v4)) {
! return 1;
! }
}
! return 0;
}
+
/**
*This function is just as bad as the previous one :-(
*/
! static char *olsr_netmask_to_string(union hna_netmask *mask)
{
char *ret;
Index: olsrd_httpinfo.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/httpinfo/src/olsrd_httpinfo.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** olsrd_httpinfo.h 20 Apr 2007 14:06:18 -0000 1.29
--- olsrd_httpinfo.h 15 Jul 2007 19:29:38 -0000 1.30
***************
*** 48,51 ****
--- 48,52 ----
#include "olsrd_plugin.h"
+ #include "plugin_util.h"
***************
*** 62,91 ****
! typedef enum
! {
HTTP_BAD_REQ,
HTTP_BAD_FILE,
HTTP_OK
! }http_header_type;
! struct http_stats
! {
! olsr_u32_t ok_hits;
! olsr_u32_t dyn_hits;
! olsr_u32_t err_hits;
! olsr_u32_t ill_hits;
};
-
extern struct olsrd_config *olsr_cfg;
-
- char *
- olsr_netmask_to_string(union hna_netmask *);
-
/* Destructor function */
! void
! olsr_plugin_exit(void);
#endif
--- 63,96 ----
! typedef enum {
HTTP_BAD_REQ,
HTTP_BAD_FILE,
HTTP_OK
! } http_header_type;
! struct http_stats {
! olsr_u32_t ok_hits;
! olsr_u32_t dyn_hits;
! olsr_u32_t err_hits;
! olsr_u32_t ill_hits;
};
extern struct olsrd_config *olsr_cfg;
/* Destructor function */
! void olsr_plugin_exit(void);
! void olsr_plugin_exit(void);
! void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size);
!
#endif
+
+ /*
+ * Local Variables:
+ * mode: c
+ * style: linux
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Index: olsrd_plugin.h
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/httpinfo/src/olsrd_plugin.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** olsrd_plugin.h 2 Apr 2007 22:22:26 -0000 1.22
--- olsrd_plugin.h 15 Jul 2007 19:29:38 -0000 1.23
***************
*** 58,61 ****
--- 58,62 ----
#include "olsr_types.h"
+ #include "../../../src/olsrd_plugin.h"
#include "neighbor_table.h"
#include "two_hop_neighbor_table.h"
***************
*** 70,74 ****
#define PLUGIN_AUTHOR "Andreas Tønnesen"
#define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION " by " PLUGIN_AUTHOR
! #define PLUGIN_INTERFACE_VERSION 4
extern int http_port;
--- 71,75 ----
#define PLUGIN_AUTHOR "Andreas Tønnesen"
#define MOD_DESC PLUGIN_NAME " " PLUGIN_VERSION " by " PLUGIN_AUTHOR
! #define PLUGIN_INTERFACE_VERSION 5
extern int http_port;
***************
*** 77,95 ****
/* Allowed hosts stuff */
! struct allowed_host
! {
! union olsr_ip_addr host;
! struct allowed_host *next;
! };
!
! struct allowed_net
! {
! union olsr_ip_addr net;
! union olsr_ip_addr mask;
! struct allowed_net *next;
};
! struct allowed_host *allowed_hosts;
! struct allowed_net *allowed_nets;
--- 78,88 ----
/* Allowed hosts stuff */
! struct allowed_net {
! union olsr_ip_addr net;
! union olsr_ip_addr mask;
! struct allowed_net *next;
};
! extern struct allowed_net *allowed_nets;
***************
*** 98,111 ****
****************************************************************************/
-
/* Initialization function */
! int
! olsrd_plugin_init(void);
! int
! olsrd_plugin_register_param(char *, char *);
! int
! olsrd_plugin_interface_version(void);
#endif
--- 91,109 ----
****************************************************************************/
/* Initialization function */
! int olsrd_plugin_init(void);
! void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size);
! int olsrd_plugin_interface_version(void);
#endif
+
+ /*
+ * Local Variables:
+ * mode: c
+ * style: linux
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
Index: olsrd_plugin.c
===================================================================
RCS file: /cvsroot/olsrd/olsrd-current/lib/httpinfo/src/olsrd_plugin.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** olsrd_plugin.c 9 May 2007 00:22:47 -0000 1.16
--- olsrd_plugin.c 15 Jul 2007 19:29:38 -0000 1.17
***************
*** 60,69 ****
int http_port = 0;
int resolve_ip_addresses = 0;
! static void __attribute__ ((constructor))
! my_init(void);
! static void __attribute__ ((destructor))
! my_fini(void);
/*
--- 60,72 ----
int http_port = 0;
int resolve_ip_addresses = 0;
+ struct allowed_net *allowed_nets = NULL;
! static void my_init(void) __attribute__ ((constructor));
! static void my_fini(void) __attribute__ ((destructor));
! static int add_plugin_ipnet(const char *value, void *data);
! static int add_plugin_ipaddr(const char *value, void *data);
!
! static int insert_plugin_ipnet(const char *sz_net, const char *sz_mask, struct allowed_net **allowed_nets);
/*
***************
*** 72,93 ****
* Do not alter unless you know what you are doing!
*/
! int
! olsrd_plugin_interface_version(void)
{
! return PLUGIN_INTERFACE_VERSION;
}
-
-
/**
*Constructor
*/
! static void
! my_init(void)
{
! /* Print plugin info to stdout */
! printf("%s\n", MOD_DESC);
!
! return;
}
--- 75,90 ----
* Do not alter unless you know what you are doing!
*/
! int olsrd_plugin_interface_version(void)
{
! return PLUGIN_INTERFACE_VERSION;
}
/**
*Constructor
*/
! static void my_init(void)
{
! /* Print plugin info to stdout */
! printf("%s\n", MOD_DESC);
}
***************
*** 95,186 ****
*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();
!
! return;
}
! int
! olsrd_plugin_register_param(char *key, char *value)
{
! if(!strcmp(key, "port") || !strcmp(key, "Port"))
! {
! http_port = atoi(value);
! printf("(HTTPINFO) listening on port: %d\n", http_port);
! }
! if(!strcmp(key, "host") || !strcmp(key, "Host"))
! {
! struct in_addr in;
! struct allowed_host *ah;
!
! if(inet_aton(value, &in) == 0)
! return 0;
! ah = malloc(sizeof(struct allowed_host));
! if(!ah)
! {
! fprintf(stderr, "(HTTPINFO) register param host out of memory!\n");
! exit(0);
! }
! ah->host.v4 = in.s_addr;
! ah->next = allowed_hosts;
! allowed_hosts = ah;
! return 1;
}
! if(!strcmp(key, "net") || !strcmp(key, "Net"))
! {
! struct in_addr net, mask;
! struct allowed_net *an;
! char sz_net[100], sz_mask[100]; /* IPv6 in the future */
!
! if(sscanf(value, "%99s %99s", sz_net, sz_mask) != 2)
! {
! olsr_printf(1, "(HTTPINFO) Error parsing net param \"%s\"!\n", value);
! return 0;
! }
!
! if(inet_aton(sz_net, &net) == 0)
! return 0;
!
! if(inet_aton(sz_mask, &mask) == 0)
! return 0;
! an = malloc(sizeof(struct allowed_net));
! if(!an)
! {
! fprintf(stderr, "(HTTPINFO) register param net out of memory!\n");
! exit(0);
! }
! an->net.v4 = net.s_addr;
! an->mask.v4 = mask.s_addr;
! an->next = allowed_nets;
! allowed_nets = an;
! return 1;
!
! }
! if(!strcasecmp(key, "resolve"))
! {
! if (!strcasecmp (value, "yes")) {
! resolve_ip_addresses = 1;
! } else if (!strcasecmp (value, "no")) {
! resolve_ip_addresses = 0;
! } else {
! return 0;
! }
}
! return 1;
}
--- 92,166 ----
*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();
}
+ static const struct olsrd_plugin_parameters plugin_parameters[] = {
+ { .name = "port", .set_plugin_parameter = &set_plugin_port, .data = &http_port },
+ { .name = "host", .set_plugin_parameter = &add_plugin_ipaddr, .data = &allowed_nets },
+ { .name = "net", .set_plugin_parameter = &add_plugin_ipnet, .data = &allowed_nets },
+ { .name = "resolve",.set_plugin_parameter = &set_boolean, .data = &resolve_ip_addresses },
+ };
! void olsrd_get_plugin_parameters(const struct olsrd_plugin_parameters **params, int *size)
{
! *params = plugin_parameters;
! *size = sizeof(plugin_parameters)/sizeof(*plugin_parameters);
! }
! static int insert_plugin_ipnet(const char *sz_net, const char *sz_mask, struct allowed_net **allowed_nets)
! {
! struct in_addr net, mask;
! struct allowed_net *an;
! if(inet_aton(sz_net, &net) == 0) {
! return 1;
! }
! if(inet_aton(sz_mask, &mask) == 0) {
! return 1;
}
! an = olsr_malloc(sizeof(*an), __func__);
! if (an == NULL) {
! fprintf(stderr, "(HTTPINFO) register param net out of memory!\n");
! exit(0);
! }
! an->net.v4 = net.s_addr;
! an->mask.v4 = mask.s_addr;
! an->next = *allowed_nets;
! *allowed_nets = an;
! return 0;
! }
! static int add_plugin_ipnet(const char *value, void *data)
! {
! char sz_net[100], sz_mask[100]; /* IPv6 in the future */
! if(sscanf(value, "%99s %99s", sz_net, sz_mask) != 2) {
! olsr_printf(1, "(HTTPINFO) Error parsing net param \"%s\"!\n", value);
! return 0;
}
! return insert_plugin_ipnet(sz_net, sz_mask, data);
! }
!
! static int add_plugin_ipaddr(const char *value, void *data)
! {
! return insert_plugin_ipnet(value, "255.255.255.255", data);
}
+
+ /*
+ * Local Variables:
+ * mode: c
+ * style: linux
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
More information about the Olsr-cvs
mailing list