Browse code

core: unified module exports interface

- have a single module interface by merging the ser and kamailio ones

Daniel-Constantin Mierla authored on 27/09/2018 14:19:39 • Victor Seva committed on 28/09/2018 11:03:26
Showing 5 changed files
... ...
@@ -299,7 +299,7 @@ int do_action(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
299 299
 	struct dest_info dst;
300 300
 	char* tmp;
301 301
 	char *new_uri, *end, *crt;
302
-	sr31_cmd_export_t* cmd;
302
+	ksr_cmd_export_t* cmd;
303 303
 	int len;
304 304
 	int user;
305 305
 	struct sip_uri uri, next_hop;
... ...
@@ -1574,7 +1574,7 @@ int run_actions(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
1574 1574
 						"alert - action [%s (%d)]"
1575 1575
 						" cfg [%s:%d] took too long [%u ms]\n",
1576 1576
 						is_mod_func(t) ?
1577
-							((cmd_export_common_t*)(t->val[0].u.data))->name
1577
+							((cmd_export_t*)(t->val[0].u.data))->name
1578 1578
 							: "corefunc",
1579 1579
 						t->type, (t->cfile)?t->cfile:"", t->cline, ms);
1580 1580
 			}
... ...
@@ -1596,13 +1596,6 @@ int run_actions(struct run_act_ctx* h, struct action* a, struct sip_msg* msg)
1596 1596
 
1597 1597
 	h->rec_lev--;
1598 1598
 end:
1599
-	/* process module onbreak handlers if present */
1600
-	if (unlikely(h->rec_lev==0 && ret==0 &&
1601
-					!(h->run_flags & IGNORE_ON_BREAK_R_F)))
1602
-		for (mod=modules;mod;mod=mod->next)
1603
-			if (unlikely(mod->exports.onbreak_f)) {
1604
-				mod->exports.onbreak_f( msg );
1605
-			}
1606 1599
 	return ret;
1607 1600
 
1608 1601
 
... ...
@@ -1624,7 +1617,7 @@ int run_actions_safe(struct run_act_ctx* h, struct action* a,
1624 1617
 	struct run_act_ctx ctx;
1625 1618
 	int ret;
1626 1619
 	int ign_on_break;
1627
-	
1620
+
1628 1621
 	/* start with a fresh action context */
1629 1622
 	init_run_actions_ctx(&ctx);
1630 1623
 	ctx.last_retcode = h->last_retcode;
... ...
@@ -3340,11 +3340,9 @@ cmd:
3340 3340
 	| ID {mod_func_action = mk_action(MODULE0_T, 2, MODEXP_ST, NULL, NUMBER_ST,
3341 3341
 			0); } LPAREN func_params RPAREN	{
3342 3342
 		mod_func_action->val[0].u.data =
3343
-			find_export_record($1, mod_func_action->val[1].u.number, rt,
3344
-								&u_tmp);
3343
+			find_export_record($1, mod_func_action->val[1].u.number, rt);
3345 3344
 		if (mod_func_action->val[0].u.data == 0) {
3346
-			if (find_export_record($1, mod_func_action->val[1].u.number, 0,
3347
-									&u_tmp) ) {
3345
+			if (find_export_record($1, mod_func_action->val[1].u.number, 0) ) {
3348 3346
 					LM_ERR("misused command %s\n", $1);
3349 3347
 					yyerror("Command cannot be used in the block\n");
3350 3348
 			} else {
... ...
@@ -3841,7 +3839,7 @@ static int case_check_default(struct case_stms* stms)
3841 3839
  */
3842 3840
 static int mod_f_params_pre_fixup(struct action* a)
3843 3841
 {
3844
-	sr31_cmd_export_t* cmd_exp;
3842
+	ksr_cmd_export_t* cmd_exp;
3845 3843
 	action_u_t* params;
3846 3844
 	int param_no;
3847 3845
 	struct rval_expr* rve;
... ...
@@ -603,7 +603,7 @@ int fix_actions(struct action* a)
603 603
 	void *tmp_p;
604 604
 	int ret;
605 605
 	int i;
606
-	sr31_cmd_export_t* cmd;
606
+	ksr_cmd_export_t* cmd;
607 607
 	str s;
608 608
 	struct hostent* he;
609 609
 	struct ip_addr ip;
... ...
@@ -201,78 +201,14 @@ int register_builtin_modules()
201 201
 }
202 202
 
203 203
 
204
-
205
-/** convert cmd exports to current format.
206
- * @param ver - module interface versions (0 == ser, 1 == kam).
207
- * @param src - null terminated array of cmd exports
208
- *              (either ser_cmd_export_t or kam_cmd_export_t, depending
209
- *               on ver).
210
- * @param mod - pointer to module exports structure.
211
- * @return - pkg_malloc'ed null terminated sr_cmd_export_v31_t array with
212
- *           the converted cmd exports  or 0 on error.
213
- */
214
-static sr31_cmd_export_t* sr_cmd_exports_convert(unsigned ver,
215
-													void* src, void* mod)
216
-{
217
-	int i, n;
218
-	ser_cmd_export_t* ser_cmd;
219
-	kam_cmd_export_t* kam_cmd;
220
-	sr31_cmd_export_t* ret;
221
-
222
-	ser_cmd = 0;
223
-	kam_cmd = 0;
224
-	ret = 0;
225
-	n = 0;
226
-	/* count the number of elements */
227
-	if (ver == 0) {
228
-		ser_cmd = src;
229
-		for (; ser_cmd[n].name; n++);
230
-	} else if (ver == 1) {
231
-		kam_cmd = src;
232
-		for (; kam_cmd[n].name; n++);
233
-	} else goto error; /* unknown interface version */
234
-	/* alloc & init new array */
235
-	ret = pkg_malloc(sizeof(*ret)*(n+1));
236
-	memset(ret, 0, sizeof(*ret)*(n+1));
237
-	/* convert/copy */
238
-	for (i=0; i < n; i++) {
239
-		if (ver == 0) {
240
-			ret[i].name = ser_cmd[i].name;
241
-			ret[i].function = ser_cmd[i].function;
242
-			ret[i].param_no = ser_cmd[i].param_no;
243
-			ret[i].fixup = ser_cmd[i].fixup;
244
-			ret[i].free_fixup = 0; /* no present in ser  <= 2.1 */
245
-			ret[i].flags = ser_cmd[i].flags;
246
-		} else {
247
-			ret[i].name = kam_cmd[i].name;
248
-			ret[i].function = kam_cmd[i].function;
249
-			ret[i].param_no = kam_cmd[i].param_no;
250
-			ret[i].fixup = kam_cmd[i].fixup;
251
-			ret[i].free_fixup = kam_cmd[i].free_fixup;
252
-			ret[i].flags = kam_cmd[i].flags;
253
-		}
254
-		/* 3.1+ specific stuff */
255
-		ret[i].fixup_flags = 0;
256
-		ret[i].module_exports = mod;
257
-		/* fill known free fixups */
258
-		if (ret[i].fixup && ret[i].free_fixup == 0)
259
-			ret[i].free_fixup = get_fixup_free(ret[i].fixup);
260
-	}
261
-	return ret;
262
-error:
263
-	return 0;
264
-}
265
-
266
-
267
-
268 204
 /* registers a module,  register_f= module register  functions
269 205
  * returns <0 on error, 0 on success */
270
-static int register_module(unsigned ver, union module_exports_u* e,
271
-					char* path, void* handle)
206
+static int register_module(module_exports_t* e, char* path, void* handle)
272 207
 {
273 208
 	int ret, i;
274 209
 	struct sr_module* mod;
275 210
 	char defmod[64];
211
+	int n;
276 212
 
277 213
 	ret=-1;
278 214
 
... ...
@@ -282,68 +218,47 @@ static int register_module(unsigned ver, union module_exports_u* e,
282 218
 		ret=E_OUT_OF_MEM;
283 219
 		goto error;
284 220
 	}
285
-	memset(mod,0, sizeof(struct sr_module));
221
+	memset(mod, 0, sizeof(struct sr_module));
286 222
 	mod->path=path;
287 223
 	mod->handle=handle;
288
-	mod->orig_mod_interface_ver=ver;
289
-	/* convert exports to sr31 format */
290
-	if (ver == 0) {
291
-		/* ser <= 3.0 */
292
-		mod->exports.name = e->v0.name;
293
-		if (e->v0.cmds) {
294
-			mod->exports.cmds = sr_cmd_exports_convert(ver, e->v0.cmds, mod);
295
-			if (mod->exports.cmds == 0) {
296
-				LM_ERR("failed to convert module command exports to 3.1 format"
297
-						" for module \"%s\" (%s), interface version %d\n",
298
-						mod->exports.name, mod->path, ver);
299
-				ret = E_UNSPEC;
300
-				goto error;
301
-			}
302
-		}
303
-		mod->exports.params = e->v0.params;
304
-		mod->exports.init_f = e->v0.init_f;
305
-		mod->exports.response_f = e->v0.response_f;
306
-		mod->exports.destroy_f = e->v0.destroy_f;
307
-		mod->exports.onbreak_f = e->v0.onbreak_f;
308
-		mod->exports.init_child_f = e->v0.init_child_f;
309
-		mod->exports.dlflags = 0; /* not used in ser <= 3.0 */
310
-		mod->exports.rpc_methods = e->v0.rpc_methods;
311
-		/* the rest are 0, not used in ser */
312
-	} else if (ver == 1) {
313
-		/* kamailio <= 3.0 */
314
-		mod->exports.name = e->v1.name;
315
-		if (e->v1.cmds) {
316
-			mod->exports.cmds = sr_cmd_exports_convert(ver, e->v1.cmds, mod);
317
-			if (mod->exports.cmds == 0) {
318
-				LM_ERR("failed to convert module command exports to 3.1 format"
319
-						" for module \"%s\" (%s), interface version %d\n",
320
-						mod->exports.name, mod->path, ver);
321
-				ret = E_UNSPEC;
322
-				goto error;
323
-			}
224
+
225
+	/* copy and convert fields */
226
+	mod->exports.name = e->name;
227
+
228
+	mod->exports.dlflags = e->dlflags;
229
+
230
+	for (n=0; e->cmds[n].name; n++);
231
+	mod->exports.cmds = pkg_malloc(sizeof(ksr_cmd_export_t)*(n+1));
232
+	memset(mod->exports.cmds, 0, sizeof(ksr_cmd_export_t)*(n+1));
233
+	for (i=0; i < n; i++) {
234
+		mod->exports.cmds[i].name = e->cmds[i].name;
235
+		mod->exports.cmds[i].function = e->cmds[i].function;
236
+		mod->exports.cmds[i].param_no = e->cmds[i].param_no;
237
+		mod->exports.cmds[i].fixup = e->cmds[i].fixup;
238
+		mod->exports.cmds[i].free_fixup = e->cmds[i].free_fixup;
239
+		mod->exports.cmds[i].flags = e->cmds[i].flags;
240
+
241
+		mod->exports.cmds[i].fixup_flags = 0;
242
+		mod->exports.cmds[i].module_exports = mod;
243
+		/* fill known free fixups */
244
+		if (mod->exports.cmds[i].fixup && mod->exports.cmds[i].free_fixup == 0) {
245
+			mod->exports.cmds[i].free_fixup
246
+					= get_fixup_free(mod->exports.cmds[i].fixup);
324 247
 		}
325
-		mod->exports.params = e->v1.params;
326
-		mod->exports.init_f = e->v1.init_f;
327
-		mod->exports.response_f = e->v1.response_f;
328
-		mod->exports.destroy_f = e->v1.destroy_f;
329
-		mod->exports.onbreak_f = 0; /* not used in k <= 3.0 */
330
-		mod->exports.init_child_f = e->v1.init_child_f;
331
-		mod->exports.dlflags = e->v1.dlflags;
332
-		mod->exports.rpc_methods = 0; /* not used in k <= 3.0 */
333
-		mod->exports.stats = e->v1.stats;
334
-		mod->exports.nn_cmds = e->v1.nn_cmds;
335
-		mod->exports.items = e->v1.items;
336
-		mod->exports.procs = e->v1.procs;
337
-	} else {
338
-		LM_ERR("unsupported module interface version %d\n", ver);
339
-		ret = E_UNSPEC;
340
-		goto error;
341 248
 	}
342 249
 
343
-	if (mod->exports.items) {
250
+	mod->exports.params = e->params;
251
+	mod->exports.rpc_methods = e->rpc_methods;
252
+	mod->exports.pv_items = e->pv_items;
253
+	mod->exports.response_f = e->response_f;
254
+	mod->exports.init_mod_f = e->init_mod_f;
255
+	mod->exports.init_child_f = e->init_child_f;
256
+	mod->exports.destroy_mod_f = e->destroy_mod_f;
257
+
258
+	if (mod->exports.pv_items) {
344 259
 		/* register module pseudo-variables for kamailio modules */
345 260
 		LM_DBG("register PV from: %s\n", mod->exports.name);
346
-		if (register_pvars_mod(mod->exports.name, mod->exports.items)!=0) {
261
+		if (register_pvars_mod(mod->exports.name, mod->exports.pv_items)!=0) {
347 262
 			LM_ERR("failed to register pseudo-variables for module %s (%s)\n",
348 263
 				mod->exports.name, path);
349 264
 			ret = E_UNSPEC;
... ...
@@ -451,8 +366,7 @@ int load_module(char* mod_path)
451 366
 	void* handle;
452 367
 	char* error;
453 368
 	mod_register_function mr;
454
-	union module_exports_u* exp;
455
-	unsigned* mod_if_ver;
369
+	module_exports_t* exp;
456 370
 	struct sr_module* t;
457 371
 	struct stat stat_buf;
458 372
 	str modname;
... ...
@@ -593,11 +507,6 @@ reload:
593 507
 	if (!version_control(handle, path)) {
594 508
 		exit(-1);
595 509
 	}
596
-	mod_if_ver = (unsigned *)dlsym(handle, "module_interface_ver");
597
-	if (mod_if_ver==NULL || (error =(char*)dlerror())!=0 ){
598
-		LM_ERR("no module interface version in module <%s>\n", path );
599
-		goto error1;
600
-	}
601 510
 	/* launch register */
602 511
 	mr = (mod_register_function)dlsym(handle, "mod_register");
603 512
 	if (((error =(char*)dlerror())==0) && mr) {
... ...
@@ -617,7 +526,7 @@ reload:
617 526
 			goto error;
618 527
 		}
619 528
 	}
620
-	exp = (union module_exports_u*)dlsym(handle, "exports");
529
+	exp = (module_exports_t*)dlsym(handle, "exports");
621 530
 	if(exp==NULL) {
622 531
 		error =(char*)dlerror();
623 532
 		LM_DBG("attempt to lookup exports structure failed - dlerror: %s\n",
... ...
@@ -634,7 +543,7 @@ reload:
634 543
 			expref.len -= 3;
635 544
 		snprintf(exbuf, 62, "_%.*s_exports", expref.len, expref.s);
636 545
 		LM_DBG("looking up exports with name: %s\n", exbuf);
637
-		exp = (union module_exports_u*)dlsym(handle, exbuf);
546
+		exp = (module_exports_t*)dlsym(handle, exbuf);
638 547
 		if(exp==NULL || (error =(char*)dlerror())!=0 ){
639 548
 			LM_ERR("failure for exports symbol: %s - dlerror: %s\n",
640 549
 					exbuf, (error)?error:"none");
... ...
@@ -642,22 +551,20 @@ reload:
642 551
 		}
643 552
 	}
644 553
 	/* hack to allow for kamailio style dlflags inside exports */
645
-	if (*mod_if_ver == 1) {
646
-		new_dlflags = exp->v1.dlflags;
647
-		if (new_dlflags!=dlflags && new_dlflags!=DEFAULT_DLFLAGS) {
648
-			/* we have to reload the module */
649
-			dlclose(handle);
650
-			DEBUG("%s: exports dlflags interface is deprecated and it will not"
651
-					" be supported in newer versions; consider using"
652
-					" mod_register() instead\n", path);
653
-			dlflags=new_dlflags;
654
-			retries--;
655
-			if (retries>0) goto reload;
656
-			LM_ERR("%s: cannot agree on the dlflags\n", path);
657
-			goto error;
658
-		}
554
+	new_dlflags = exp->dlflags;
555
+	if (new_dlflags!=dlflags && new_dlflags!=DEFAULT_DLFLAGS) {
556
+		/* we have to reload the module */
557
+		dlclose(handle);
558
+		DEBUG("%s: exports dlflags interface is deprecated and it will not"
559
+				" be supported in newer versions; consider using"
560
+				" mod_register() instead\n", path);
561
+		dlflags=new_dlflags;
562
+		retries--;
563
+		if (retries>0) goto reload;
564
+		LM_ERR("%s: cannot agree on the dlflags\n", path);
565
+		goto error;
659 566
 	}
660
-	if (register_module(*mod_if_ver, exp, path, handle)<0) goto error1;
567
+	if (register_module(exp, path, handle)<0) goto error1;
661 568
 	return 0;
662 569
 
663 570
 error1:
... ...
@@ -687,16 +594,14 @@ static inline int sr_cmd_flags_match(int cflags, int rflags)
687 594
 
688 595
 /* searches the module list for function name in module mod and returns
689 596
  *  a pointer to the "name" function record union or 0 if not found
690
- * sets also *mod_if_ver to the original module interface version.
691 597
  * mod==0 is a wildcard matching all modules
692 598
  * flags parameter is OR value of all flags that must match
693 599
  */
694
-sr31_cmd_export_t* find_mod_export_record(char* mod, char* name,
695
-											int param_no, int flags,
696
-											unsigned* mod_if_ver)
600
+ksr_cmd_export_t* find_mod_export_record(char* mod, char* name,
601
+											int param_no, int flags)
697 602
 {
698 603
 	struct sr_module* t;
699
-	sr31_cmd_export_t* cmd;
604
+	ksr_cmd_export_t* cmd;
700 605
 
701 606
 	for(t=modules;t;t=t->next){
702 607
 		if (mod!=0 && (strcmp(t->exports.name, mod) !=0))
... ...
@@ -710,7 +615,6 @@ sr31_cmd_export_t* find_mod_export_record(char* mod, char* name,
710 615
 				){
711 616
 					LM_DBG("found export of <%s> in module %s [%s]\n",
712 617
 						name, t->exports.name, t->path);
713
-					*mod_if_ver=t->orig_mod_interface_ver;
714 618
 					return cmd;
715 619
 				}
716 620
 			}
... ...
@@ -723,26 +627,21 @@ sr31_cmd_export_t* find_mod_export_record(char* mod, char* name,
723 627
 
724 628
 /* searches the module list for function name and returns
725 629
  *  a pointer to the "name" function record union or 0 if not found
726
- * sets also *mod_if_ver to the module interface version (needed to know
727
- * which member of the union should be accessed v0 or v1)
728 630
  * mod==0 is a wildcard matching all modules
729 631
  * flags parameter is OR value of all flags that must match
730 632
  */
731
-sr31_cmd_export_t* find_export_record(char* name,
732
-											int param_no, int flags,
733
-											unsigned* mod_if_ver)
633
+ksr_cmd_export_t* find_export_record(char* name, int param_no, int flags)
734 634
 {
735
-	return find_mod_export_record(0, name, param_no, flags, mod_if_ver);
635
+	return find_mod_export_record(0, name, param_no, flags);
736 636
 }
737 637
 
738 638
 
739 639
 
740 640
 cmd_function find_export(char* name, int param_no, int flags)
741 641
 {
742
-	sr31_cmd_export_t* cmd;
743
-	unsigned mver;
642
+	ksr_cmd_export_t* cmd;
744 643
 
745
-	cmd = find_export_record(name, param_no, flags, &mver);
644
+	cmd = find_export_record(name, param_no, flags);
746 645
 	return cmd?cmd->function:0;
747 646
 }
748 647
 
... ...
@@ -761,10 +660,9 @@ rpc_export_t* find_rpc_export(char* name, int flags)
761 660
  */
762 661
 cmd_function find_mod_export(char* mod, char* name, int param_no, int flags)
763 662
 {
764
-	sr31_cmd_export_t* cmd;
765
-	unsigned mver;
663
+	ksr_cmd_export_t* cmd;
766 664
 
767
-	cmd=find_mod_export_record(mod, name, param_no, flags, &mver);
665
+	cmd=find_mod_export_record(mod, name, param_no, flags);
768 666
 	if (cmd)
769 667
 		return cmd->function;
770 668
 
... ...
@@ -828,8 +726,8 @@ void destroy_modules()
828 726
 	t=modules;
829 727
 	while(t) {
830 728
 		foo=t->next;
831
-		if (t->exports.destroy_f){
832
-			t->exports.destroy_f();
729
+		if (t->exports.destroy_mod_f){
730
+			t->exports.destroy_mod_f();
833 731
 		}
834 732
 		t=foo;
835 733
 	}
... ...
@@ -984,9 +882,9 @@ static int init_mod( struct sr_module* m )
984 882
 		 * propagate it up the stack
985 883
 		 */
986 884
 		if (init_mod(m->next)!=0) return -1;
987
-			if (m->exports.init_f) {
885
+			if (m->exports.init_mod_f) {
988 886
 				LM_DBG("%s\n", m->exports.name);
989
-				if (m->exports.init_f()!=0) {
887
+				if (m->exports.init_mod_f()!=0) {
990 888
 					LM_ERR("Error while initializing module %s (%s)\n",
991 889
 								m->exports.name, m->path);
992 890
 					return -1;
... ...
@@ -42,30 +42,11 @@
42 42
 #include "counters.h"
43 43
 #include "pvar.h"
44 44
 
45
-
46
-
47
-#if defined KAMAILIO_MOD_INTERFACE || defined OPENSER_MOD_INTERFACE || \
48
-	defined MOD_INTERFACE_V1
49
-
50
-#define MODULE_INTERFACE_VER 1
51
-#define cmd_export_t kam_cmd_export_t
52
-#define module_exports kam_module_exports
53
-
54
-#elif defined SER_MOD_INTERFACE || defined MOD_INTERFACE_V0
55
-
56
-#define MODULE_INTERFACE_VER 0
57
-#define cmd_export_t ser_cmd_export_t
58
-#define module_exports ser_module_exports
59
-
60
-#else
61
-
62
-/* do nothing for core */
63
-
64
-#endif
45
+#define MODULE_INTERFACE_VER 4
65 46
 
66 47
 /**
67 48
  * @brief type used for the mod_register function export
68
- * 
49
+ *
69 50
  * mod_register is a function called when loading a module
70 51
  * (if present), prior to registering the module exports.
71 52
  * @param path path to the module, including file name
... ...
@@ -77,13 +58,14 @@
77 58
  * @return 0 on success, -1 on error, all the other values are reserved
78 59
  *                      for future use (<0 meaning error and >0 success)
79 60
  */
80
-typedef  int (*mod_register_function)(char* path, int* dlflags, void* reserved1, void* reserved2);
61
+typedef  int (*mod_register_function)(char* path, int* dlflags, void* reserved1,
62
+		void* reserved2);
81 63
 
82 64
 typedef  struct module_exports* (*module_register)(void);
83 65
 
84 66
 /**
85 67
  * @brief main two parameter module function
86
- * 
68
+ *
87 69
  * Main two parameter module function, default and oldest version.
88 70
  * @param sip_msg SIP message
89 71
  * @param param1 first parameter
... ...
@@ -99,7 +81,7 @@ typedef  int (*cmd_function6)(struct sip_msg*,  char*, char*, char*,
99 81
 												char*, char*, char*);
100 82
 /**
101 83
  * @brief variable number of parameter module function
102
- * 
84
+ *
103 85
  * Variable number of parameter module function, takes as param the sip_msg,
104 86
  * extra parameters number and a pointer to an array of parameters
105 87
  * @param sip_msg SIP message
... ...
@@ -207,19 +189,9 @@ typedef int (*param_func_t)( modparam_t type, void* val);
207 189
 	char *module_flags=SER_COMPILE_FLAGS; \
208 190
 	unsigned int module_interface_ver=MODULE_INTERFACE_VER;
209 191
 
210
-/** ser version */
211
-struct ser_cmd_export_ {
212
-	char* name;             /**< null terminated command name */
213
-	cmd_function function;  /**< pointer to the corresponding function */
214
-	int param_no;           /**< number of parameters used by the function */
215
-	fixup_function fixup;   /**< pointer to the function called to "fix" the
216
-							   parameters */
217
-	unsigned int flags;     /**< Function flags */
218
-};
219
-
220 192
 
221 193
 /** kamailio/openser version */
222
-struct kam_cmd_export_ {
194
+typedef struct cmd_export {
223 195
 	char* name;             /**< null terminated command name */
224 196
 	cmd_function function;  /**< pointer to the corresponding function */
225 197
 	int param_no;           /**< number of parameters used by the function */
... ...
@@ -228,10 +200,10 @@ struct kam_cmd_export_ {
228 200
 	free_fixup_function free_fixup; /**< function called to free the "fixed"
229 201
 									   parameters */
230 202
 	unsigned int flags;     /**< Function flags */
231
-};
203
+} cmd_export_t;
232 204
 
233 205
 /** sip-router version */
234
-struct sr31_cmd_export_ {
206
+typedef struct ksr_cmd_export {
235 207
 	char* name;             /**< null terminated command name */
236 208
 	cmd_function function;  /**< pointer to the corresponding function */
237 209
 	int param_no;           /**< number of parameters used by the function */
... ...
@@ -242,24 +214,14 @@ struct sr31_cmd_export_ {
242 214
 	unsigned int flags;     /**< Function flags */
243 215
 	unsigned int fixup_flags;
244 216
 	void* module_exports; /**< pointer to module structure */
245
-};
246
-
247
-
248
-/** members situated at the same place in memory in both ser & kamailio
249
-   cmd_export */
250
-struct cmd_export_common_ {
251
-	char* name;
252
-	cmd_function function;
253
-	int param_no;
254
-	fixup_function fixup;
255
-};
217
+} ksr_cmd_export_t;
256 218
 
257 219
 
258
-struct param_export_ {
220
+typedef struct param_export {
259 221
 	char* name;             /**< null terminated param. name */
260 222
 	modparam_t type;        /**< param. type */
261 223
 	void* param_pointer;    /**< pointer to the param. memory location */
262
-};
224
+} param_export_t;
263 225
 
264 226
 
265 227
 /*
... ...
@@ -304,142 +266,59 @@ typedef struct fparam {
304 266
 	void *fixed;
305 267
 } fparam_t;
306 268
 
307
-
308
-typedef struct param_export_ param_export_t;
309
-typedef struct ser_cmd_export_ ser_cmd_export_t;
310
-typedef struct kam_cmd_export_ kam_cmd_export_t;
311
-typedef struct cmd_export_common_ cmd_export_common_t;
312
-typedef struct sr31_cmd_export_ sr31_cmd_export_t;
313
-
314
-
315
-/** ser module exports version */
316
-struct ser_module_exports {
317
-	char* name;			/**< null terminated module name */
318
-	ser_cmd_export_t* cmds;         /**< null terminated array of the exported
319
-									   commands */
320
-	rpc_export_t* rpc_methods;      /**< null terminated array of exported rpc methods */
321
-	param_export_t* params;         /**< null terminated array of the exported
322
-									   module parameters */
323
-	init_function init_f;           /**< Initialization function */
324
-	response_function response_f;   /**< function used for responses,
325
-									   returns yes or no; can be null */
326
-	destroy_function destroy_f;     /**< function called when the module should
327
-									   be "destroyed", e.g: on ser exit;
328
-									   can be null */
329
-	onbreak_function onbreak_f;
330
-	child_init_function init_child_f;  /**< function called by all processes
331
-										  after the fork */
332
-};
333
-
334
-
335
-/** kamailio/openser proc_export (missing from ser) */
336
-typedef void (*mod_proc)(int no);
337
-
338
-typedef int (*mod_proc_wrapper)(void);
339
-
340
-struct proc_export_ {
341
-	char *name;
342
-	mod_proc_wrapper pre_fork_function;
343
-	mod_proc_wrapper post_fork_function;
344
-	mod_proc function;
345
-	unsigned int no;
346
-};
347
-
348
-typedef struct proc_export_ proc_export_t;
349
-
350
-typedef void nn_export_t;
351
-
352
-/** kamailio/openser module exports version */
353
-struct kam_module_exports {
354
-	char* name;				/**< null terminated module name */
355
-	unsigned int dlflags;			/**< flags for dlopen  */
356
-	kam_cmd_export_t* cmds;			/**< null terminated array of the exported
357
-									   commands */
358
-	param_export_t* params;			/**< null terminated array of the exported
359
-									   module parameters */
360
-	stat_export_t* stats;			/**< null terminated array of the exported
361
-									  module statistics */
362
-	nn_export_t* nn_cmds;			/**< null terminated array of the exported
363
-									  NN functions */
364
-	pv_export_t* items;				/*!< null terminated array of the exported
365
-									   module items (pseudo-variables) */
366
-	proc_export_t* procs;			/**< null terminated array of the
367
-									  additional processes required by the
368
-									  module */
369
-	init_function init_f;			/**< Initialization function */
370
-	response_function response_f;		/**< function used for responses,
371
-									   returns yes or no; can be null */
372
-	destroy_function destroy_f;			/**< function called when the module should
373
-									   be "destroyed", e.g: on ser exit;
374
-									   can be null */
375
-	child_init_function init_child_f;	/**< function called by all processes
376
-										  after the fork */
377
-};
378
-
379
-
380
-
381
-/**
382
- * @brief sr/ser 3.1+ module exports version
383
- *
384
- * sr/ser 3.1+ module exports version, Includes ser and kamailio versions,
385
- * re-arraranged + some extras.
386
- * @note Some of the members will be obsoleted and are kept only for
387
- * backward compatibility (avoid re-writing all the modules exports
388
- * declarations).
389
- */
390
-struct sr31_module_exports {
391
-	char* name;			/**< null terminated module name */
392
-	sr31_cmd_export_t* cmds;	/**< null terminated array of the exported
393
-									   commands */
394
-	param_export_t* params;         /**< null terminated array of the exported
395
-									   module parameters */
396
-	init_function init_f;           /**< Initialization function */
397
-	response_function response_f;   /**< function used for responses,
398
-									   returns yes or no; can be null */
399
-	destroy_function destroy_f;     /**< function called when the module should
400
-									   be "destroyed", e.g: on ser exit;
401
-									   can be null */
402
-	onbreak_function onbreak_f;
403
-	child_init_function init_child_f;/**< function called by all processes
404
-										  after the fork */
405
-	unsigned int dlflags;		/**< flags for dlopen */
406
-	/* ser specific exports
407
-	   (to be obsoleted and replaced by register_...) */
408
-	rpc_export_t* rpc_methods;	/**< null terminated array of exported
409
-							rpc methods */
410
-	/* kamailio specific exports
411
-	   (to be obsoleted and replaced by register_...) */
412
-	stat_export_t* stats;			/**< null terminated array of the exported
413
-									  module statistics */
414
-	nn_export_t* nn_cmds;			/**< null terminated array of the exported
415
-									  NN functions */
416
-	pv_export_t* items;			/**< null terminated array of the exported
417
-									   module items (pseudo-variables) */
418
-	proc_export_t* procs;			/**< null terminated array of the
419
-									  additional processes required by the
420
-									  module */
421
-};
422
-
423
-
424
-
425
-/** module exports in the same place in memory in both ser & kamailio */
426
-struct module_exports_common {
269
+/** kamailio module exports version */
270
+typedef struct module_exports {
271
+	/**< null terminated module name */
427 272
 	char* name;
428
-};
429
-
430
-
431
-union module_exports_u {
432
-		struct module_exports_common c; /**< common members for all the versions */
433
-		struct ser_module_exports v0;
434
-		struct kam_module_exports v1;
435
-};
436
-
273
+	/**< flags for dlopen  */
274
+	unsigned int dlflags;
275
+	/**< null terminated array of the exported commands (config functions)*/
276
+	cmd_export_t* cmds;
277
+	/**< null terminated array of the exported module parameters */
278
+	param_export_t* params;
279
+	/**< null terminated array of exported rpc methods */
280
+	rpc_export_t* rpc_methods;
281
+	/*!< null terminated array of the exported module items (pseudo-variables) */
282
+	pv_export_t* pv_items;
283
+	/**< function used for responses, returns yes or no; can be null */
284
+	response_function response_f;
285
+	/**< Initialization function */
286
+	init_function init_mod_f;
287
+	/**< function called by all processes after the fork */
288
+	child_init_function init_child_f;
289
+	/**< function called when the module is "destroyed" (on server shut down) */
290
+	destroy_function destroy_mod_f;
291
+} module_exports_t;
292
+
293
+
294
+/** kamailio module exports version coverted for core operations */
295
+typedef struct ksr_module_exports {
296
+	/**< null terminated module name */
297
+	char* name;
298
+	/**< flags for dlopen  */
299
+	unsigned int dlflags;
300
+	/**< null terminated array of the exported commands (config functions)*/
301
+	ksr_cmd_export_t* cmds;
302
+	/**< null terminated array of the exported module parameters */
303
+	param_export_t* params;
304
+	/**< null terminated array of exported rpc methods */
305
+	rpc_export_t* rpc_methods;
306
+	/*!< null terminated array of the exported module items (pseudo-variables) */
307
+	pv_export_t* pv_items;
308
+	/**< function used for responses, returns yes or no; can be null */
309
+	response_function response_f;
310
+	/**< Initialization function */
311
+	init_function init_mod_f;
312
+	/**< function called by all processes after the fork */
313
+	child_init_function init_child_f;
314
+	/**< function called when the module is "destroyed" (on server shut down) */
315
+	destroy_function destroy_mod_f;
316
+} ksr_module_exports_t;
437 317
 
438 318
 typedef struct sr_module {
439 319
 	char* path;
440 320
 	void* handle;
441
-	unsigned int orig_mod_interface_ver;
442
-	struct sr31_module_exports exports;
321
+	ksr_module_exports_t exports;
443 322
 	struct sr_module* next;
444 323
 } sr_module_t;
445 324
 
... ...
@@ -450,8 +329,7 @@ extern int mod_response_cbk_no; /**< size of reponse callbacks array */
450 329
 
451 330
 int register_builtin_modules(void);
452 331
 int load_module(char* path);
453
-sr31_cmd_export_t* find_export_record(char* name, int param_no, int flags,
454
-										unsigned *ver);
332
+ksr_cmd_export_t* find_export_record(char* name, int param_no, int flags);
455 333
 cmd_function find_export(char* name, int param_no, int flags);
456 334
 cmd_function find_mod_export(char* mod, char* name, int param_no, int flags);
457 335
 rpc_export_t* find_rpc_export(char* name, int flags);
... ...
@@ -473,11 +351,13 @@ sr_module_t* get_loaded_modules(void);
473 351
  * @param param_type parameter type
474 352
  * @return parameter address in memory, if there is no such parameter, NULL is returned
475 353
  */
476
-void* find_param_export(struct sr_module* mod, char* name, modparam_t type_mask, modparam_t *param_type);
354
+void* find_param_export(struct sr_module* mod, char* name, modparam_t type_mask,
355
+		modparam_t *param_type);
477 356
 
478 357
 
479 358
 /** API function to get other parameters from fixup */
480
-action_u_t *fixup_get_param(void **cur_param, int cur_param_no, int required_param_no);
359
+action_u_t *fixup_get_param(void **cur_param, int cur_param_no,
360
+		int required_param_no);
481 361
 int fixup_get_param_count(void **cur_param, int cur_param_no);
482 362
 
483 363
 int fix_flag( modparam_t type, void* val,
... ...
@@ -618,7 +498,8 @@ int get_int_fparam(int* dst, struct sip_msg* msg, fparam_t* param);
618 498
  * @param flags flags to indicate destinations
619 499
  * @return 0 on success, 1 on error, e.g. cannot get value
620 500
  */
621
-int get_is_fparam(int* i_dst, str* s_dst, struct sip_msg* msg, fparam_t* param, unsigned int *flags);
501
+int get_is_fparam(int* i_dst, str* s_dst, struct sip_msg* msg, fparam_t* param,
502
+		unsigned int *flags);
622 503
 
623 504
 /**
624 505
  * @brief Get the function parameter value as compiled regular expression