... | ... |
@@ -88,6 +88,7 @@ CHECK_VIA check_via |
88 | 88 |
LOOP_CHECKS loop_checks |
89 | 89 |
|
90 | 90 |
LOADMODULE loadmodule |
91 |
+MODPARAM modparam |
|
91 | 92 |
|
92 | 93 |
/* values */ |
93 | 94 |
YES "yes"|"true"|"on"|"enable" |
... | ... |
@@ -162,6 +163,7 @@ EAT_ABLE [\ \t\b\r] |
162 | 163 |
<INITIAL>{CHECK_VIA} { count(); yylval.strval=yytext; return CHECK_VIA; } |
163 | 164 |
<INITIAL>{LOOP_CHECKS} { count(); yylval.strval=yytext; return LOOP_CHECKS; } |
164 | 165 |
<INITIAL>{LOADMODULE} { count(); yylval.strval=yytext; return LOADMODULE; } |
166 |
+<INITIAL>{MODPARAM} { count(); yylval.strval=yytext; return MODPARAM; } |
|
165 | 167 |
|
166 | 168 |
<INITIAL>{EQUAL} { count(); return EQUAL; } |
167 | 169 |
<INITIAL>{EQUAL_T} { count(); return EQUAL_T; } |
... | ... |
@@ -18,6 +18,7 @@ |
18 | 18 |
#include "route.h" |
19 | 19 |
#include "dprint.h" |
20 | 20 |
#include "sr_module.h" |
21 |
+#include "modparam.h" |
|
21 | 22 |
|
22 | 23 |
|
23 | 24 |
#ifdef DEBUG_DMALLOC |
... | ... |
@@ -80,6 +81,7 @@ void* f_tmp; |
80 | 81 |
%token CHECK_VIA |
81 | 82 |
%token LOOP_CHECKS |
82 | 83 |
%token LOADMODULE |
84 |
+%token MODPARAM |
|
83 | 85 |
%token MAXBUFFER |
84 | 86 |
|
85 | 87 |
|
... | ... |
@@ -230,7 +232,18 @@ module_stm: LOADMODULE STRING { DBG("loading module %s\n", $2); |
230 | 232 |
yyerror("failed to load module"); |
231 | 233 |
} |
232 | 234 |
} |
233 |
- | LOADMODULE error { yyerror("string expected"); } |
|
235 |
+ | LOADMODULE error { yyerror("string expected"); } |
|
236 |
+ | MODPARAM LPAREN STRING COMMA STRING COMMA STRING RPAREN { |
|
237 |
+ if (set_mod_param($3, $5, STR_PARAM, $7) != 0) { |
|
238 |
+ yyerror("Can't set module parameter"); |
|
239 |
+ } |
|
240 |
+ } |
|
241 |
+ | MODPARAM LPAREN STRING COMMA STRING COMMA NUMBER RPAREN { |
|
242 |
+ if (set_mod_param($3, $5, INT_PARAM, (void*)$7) != 0) { |
|
243 |
+ yyerror("Can't set module parameter"); |
|
244 |
+ } |
|
245 |
+ } |
|
246 |
+ | MODPARAM error { yyerror("Invalid arguments"); } |
|
234 | 247 |
; |
235 | 248 |
|
236 | 249 |
|
... | ... |
@@ -31,32 +31,32 @@ struct sr_module* modules=0; |
31 | 31 |
|
32 | 32 |
|
33 | 33 |
/* initializes statically built (compiled in) modules*/ |
34 |
-int init_builtin_modules() |
|
34 |
+int register_builtin_modules() |
|
35 | 35 |
{ |
36 | 36 |
int ret; |
37 | 37 |
|
38 | 38 |
ret=0; |
39 | 39 |
#ifdef STATIC_TM |
40 |
- ret=register_module(tm_mod_register,"built-in", 0); |
|
40 |
+ ret=register_module(tm_exports,"built-in", 0); |
|
41 | 41 |
if (ret<0) return ret; |
42 | 42 |
#endif |
43 | 43 |
#ifdef STATIC_MAXFWD |
44 |
- ret=register_module(maxfwd_mod_register, "built-in", 0); |
|
44 |
+ ret=register_module(maxfwd_exports, "built-in", 0); |
|
45 | 45 |
if (ret<0) return ret; |
46 | 46 |
#endif |
47 | 47 |
|
48 | 48 |
#ifdef STATIC_AUTH |
49 |
- ret=register_module(tm_mod_register, "built-in", 0); |
|
49 |
+ ret=register_module(tm_exports, "built-in", 0); |
|
50 | 50 |
if (ret<0) return ret; |
51 | 51 |
#endif |
52 | 52 |
|
53 | 53 |
#ifdef STATIC_RR |
54 |
- ret=register_module(rr_mod_register, "built-in", 0); |
|
54 |
+ ret=register_module(rr_exports, "built-in", 0); |
|
55 | 55 |
if (ret<0) return ret; |
56 | 56 |
#endif |
57 | 57 |
|
58 | 58 |
#ifdef STATIC_USRLOC |
59 |
- ret=register_module(usrloc_mod_register, "built-in", 0); |
|
59 |
+ ret=register_module(usrloc_exports, "built-in", 0); |
|
60 | 60 |
if (ret<0) return ret; |
61 | 61 |
#endif |
62 | 62 |
|
... | ... |
@@ -67,18 +67,13 @@ int init_builtin_modules() |
67 | 67 |
|
68 | 68 |
/* registers a module, register_f= module register functions |
69 | 69 |
* returns <0 on error, 0 on success */ |
70 |
-int register_module(module_register register_f, char* path, void* handle) |
|
70 |
+int register_module(struct module_exports* e, char* path, void* handle) |
|
71 | 71 |
{ |
72 | 72 |
int ret; |
73 |
- struct module_exports* e; |
|
74 | 73 |
struct sr_module* mod; |
75 | 74 |
|
76 | 75 |
ret=-1; |
77 |
- e=(*register_f)(); |
|
78 |
- if (e==0){ |
|
79 |
- LOG(L_ERR, "ERROR: mod_register returned null\n"); |
|
80 |
- goto error; |
|
81 |
- } |
|
76 |
+ |
|
82 | 77 |
/* add module to the list */ |
83 | 78 |
if ((mod=malloc(sizeof(struct sr_module)))==0){ |
84 | 79 |
LOG(L_ERR, "load_module: memory allocation failure\n"); |
... | ... |
@@ -122,7 +117,7 @@ int load_module(char* path) |
122 | 117 |
{ |
123 | 118 |
void* handle; |
124 | 119 |
char* error; |
125 |
- module_register mod_register; |
|
120 |
+ struct module_exports* exp; |
|
126 | 121 |
struct sr_module* t; |
127 | 122 |
|
128 | 123 |
handle=dlopen(path, RTLD_NOW); /* resolve all symbols now */ |
... | ... |
@@ -140,12 +135,12 @@ int load_module(char* path) |
140 | 135 |
} |
141 | 136 |
} |
142 | 137 |
/* launch register */ |
143 |
- mod_register = (module_register)dlsym(handle, "mod_register"); |
|
138 |
+ exp = (struct module_exports*)dlsym(handle, "exports"); |
|
144 | 139 |
if ( (error =dlerror())!=0 ){ |
145 | 140 |
LOG(L_ERR, "ERROR: load_module: %s\n", error); |
146 | 141 |
goto error1; |
147 | 142 |
} |
148 |
- if (register_module(mod_register, path, handle)<0) goto error1; |
|
143 |
+ if (register_module(exp, path, handle)<0) goto error1; |
|
149 | 144 |
return 0; |
150 | 145 |
|
151 | 146 |
error1: |
... | ... |
@@ -179,6 +174,28 @@ cmd_function find_export(char* name, int param_no) |
179 | 174 |
} |
180 | 175 |
|
181 | 176 |
|
177 |
+void* find_param_export(char* mod, char* name, modparam_t type) |
|
178 |
+{ |
|
179 |
+ struct sr_module* t; |
|
180 |
+ int r; |
|
181 |
+ |
|
182 |
+ for(t = modules; t; t = t->next) { |
|
183 |
+ if (strcmp(mod, t->exports->name) == 0) { |
|
184 |
+ for(r = 0; r < t->exports->par_no; r++) { |
|
185 |
+ if ((strcmp(name, t->exports->param_names[r]) == 0) && |
|
186 |
+ (t->exports->param_types[r] == type)) { |
|
187 |
+ DBG("find_param_export: found <%s> in module %s [%s]\n", |
|
188 |
+ name, t->exports->name, t->path); |
|
189 |
+ return t->exports->param_pointers[r]; |
|
190 |
+ } |
|
191 |
+ } |
|
192 |
+ } |
|
193 |
+ } |
|
194 |
+ DBG("find_param_export: parameter <%s> or module <%s> not found\n", name, mod); |
|
195 |
+ return 0; |
|
196 |
+} |
|
197 |
+ |
|
198 |
+ |
|
182 | 199 |
|
183 | 200 |
/* finds a module, given a pointer to a module function * |
184 | 201 |
* returns pointer to module, & if i i!=0, *i=the function index */ |
... | ... |
@@ -205,3 +222,22 @@ void destroy_modules() |
205 | 222 |
for(t=modules;t;t=t->next) |
206 | 223 |
if ((t->exports)&&(t->exports->destroy_f)) t->exports->destroy_f(); |
207 | 224 |
} |
225 |
+ |
|
226 |
+ |
|
227 |
+/* |
|
228 |
+ * Initialize all loaded modules, the initialization |
|
229 |
+ * is done *AFTER* the configuration file is parsed |
|
230 |
+ */ |
|
231 |
+int init_modules(void) |
|
232 |
+{ |
|
233 |
+ struct sr_module* t; |
|
234 |
+ |
|
235 |
+ for(t = modules; t; t = t->next) { |
|
236 |
+ if ((t->exports) && (t->exports->init_f)) |
|
237 |
+ if (t->exports->init_f() != 0) { |
|
238 |
+ LOG(L_ERR, "init_modules(): Error while initializing module %s\n", t->exports->name); |
|
239 |
+ return -1; |
|
240 |
+ } |
|
241 |
+ } |
|
242 |
+ return 0; |
|
243 |
+} |
... | ... |
@@ -15,25 +15,47 @@ typedef int (*fixup_function)(void** param, int param_no); |
15 | 15 |
typedef int (*response_function)(struct sip_msg*); |
16 | 16 |
typedef void (*onbreak_function)(struct sip_msg*); |
17 | 17 |
typedef void (*destroy_function)(); |
18 |
+typedef int (*init_function)(void); |
|
18 | 19 |
typedef int (*child_init_function)(int rank); |
19 | 20 |
|
21 |
+ |
|
22 |
+typedef enum { |
|
23 |
+ STR_PARAM, /* String parameter type */ |
|
24 |
+ INT_PARAM, /* Integer parameter type */ |
|
25 |
+} modparam_t; /* Allowed types of parameters */ |
|
26 |
+ |
|
27 |
+ |
|
20 | 28 |
struct module_exports{ |
21 |
- char* name; /* null terminated module name */ |
|
22 |
- char** cmd_names; /* cmd names registered by this modules */ |
|
23 |
- cmd_function* cmd_pointers; /* pointers to the corresponding functions */ |
|
24 |
- int* param_no; /* number of parameters used by the function */ |
|
29 |
+ char* name; /* null terminated module name */ |
|
30 |
+ char** cmd_names; /* cmd names registered by this modules */ |
|
31 |
+ cmd_function* cmd_pointers; /* pointers to the corresponding functions */ |
|
32 |
+ int* param_no; /* number of parameters used by the function */ |
|
25 | 33 |
fixup_function* fixup_pointers; /* pointers to functions called to "fix" |
26 |
- the params, e.g: precompile a re */ |
|
27 |
- int cmd_no; /* number of registered commands |
|
28 |
- (size of cmd_{names,pointers}*/ |
|
34 |
+ * the params, e.g: precompile a re |
|
35 |
+ */ |
|
36 |
+ int cmd_no; /* number of registered commands |
|
37 |
+ * (size of cmd_{names,pointers} |
|
38 |
+ */ |
|
39 |
+ |
|
40 |
+ char** param_names; /* parameter names registered by this modules */ |
|
41 |
+ modparam_t* param_types; /* Type of parameters */ |
|
42 |
+ void** param_pointers; /* Pointers to the corresponding memory locations */ |
|
43 |
+ int par_no; /* Number of registered parameters */ |
|
44 |
+ |
|
45 |
+ |
|
46 |
+ init_function init_f; /* Initilization function */ |
|
29 | 47 |
response_function response_f; /* function used for responses, |
30 |
- returns yes or no; |
|
31 |
- can be null */ |
|
32 |
- destroy_function destroy_f; /*function called when the module should |
|
33 |
- be "destroyed", e.g: on ser exit; |
|
34 |
- can be null */ |
|
48 |
+ * returns yes or no; |
|
49 |
+ * can be null |
|
50 |
+ */ |
|
51 |
+ destroy_function destroy_f; /* function called when the module should |
|
52 |
+ * be "destroyed", e.g: on ser exit; |
|
53 |
+ * can be null |
|
54 |
+ */ |
|
35 | 55 |
onbreak_function onbreak_f; |
36 |
- child_init_function init_child_f; /* Function will be called by all processes after the fork */ |
|
56 |
+ child_init_function init_child_f; /* Function will be called by all |
|
57 |
+ * processes after the fork |
|
58 |
+ */ |
|
37 | 59 |
}; |
38 | 60 |
|
39 | 61 |
struct sr_module{ |
... | ... |
@@ -45,14 +67,21 @@ struct sr_module{ |
45 | 67 |
|
46 | 68 |
struct sr_module* modules; /* global module list*/ |
47 | 69 |
|
48 |
-int init_builtin_modules(); |
|
49 |
-int register_module(module_register, char*, void*); |
|
70 |
+int register_builtin_modules(); |
|
71 |
+int register_module(struct module_exports*, char*, void*); |
|
50 | 72 |
int load_module(char* path); |
51 | 73 |
cmd_function find_export(char* name, int param_no); |
52 | 74 |
struct sr_module* find_module(void *f, int* r); |
53 | 75 |
void destroy_modules(); |
54 | 76 |
int init_child(int rank); |
77 |
+int init_modules(void); |
|
55 | 78 |
|
79 |
+/* |
|
80 |
+ * Find a parameter with given type and return it's |
|
81 |
+ * address in memory |
|
82 |
+ * If there is no such parameter, NULL is returned |
|
83 |
+ */ |
|
84 |
+void* find_param_export(char* mod, char* name, modparam_t type); |
|
56 | 85 |
|
57 | 86 |
/* modules function prototypes: |
58 | 87 |
* struct module_exports* mod_register(); (type module_register) |