Browse code

- added a new member to the ser_module struct: destroy_f, called when a module must be destroyed (e.g. ser exit) - updated ser_module structs init. in tm, textops & print - added bogus tm_destroy module functions in tm.c

Andrei Pelinescu-Onciul authored on 04/12/2001 19:00:49
Showing 5 changed files
... ...
@@ -27,6 +27,7 @@
27 27
 #ifdef SHM_MEM
28 28
 #include "shm_mem.h"
29 29
 #endif
30
+#include "sr_module.h"
30 31
 
31 32
 
32 33
 #include <signal.h>
... ...
@@ -296,19 +297,20 @@ static void sig_usr(int signo)
296 296
 			else
297 297
 				printf("statistics dump to %s failed\n", stat_file );
298 298
 #endif
299
+		DPrint("INT received, program terminates\n");
300
+		DPrint("Thank you for flying ser\n");
301
+		/* WARNING: very dangerous, might be unsafe*/
302
+		destroy_modules();
299 303
 #ifdef PKG_MALLOC
300 304
 		pkg_status();
301 305
 #endif
302 306
 #ifdef SHM_MEM
303 307
 		shm_status();
304 308
 #endif
305
-		DPrint("INT received, program terminates\n");
306
-		DPrint("Thank you for flying ser\n");
307
-		/* WARNING: very dangerous, might be unsafe*/
308 309
 #ifdef SHM_MEM
309 310
 		shm_mem_destroy();
310
-		exit(0);
311 311
 #endif
312
+		exit(0);
312 313
 	} else if (signo==SIGUSR1) { /* statistic */
313 314
 #ifdef STATS
314 315
 		dump_all_statistic();
... ...
@@ -480,7 +480,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
480 480
 
481 481
 /*   returns 1 if everything was OK or -1 for error
482 482
   */
483
-int t_put_on_wait(  struct sip_msg  *p_msg  )
483
+int t_put_on_wait(  struct sip_msg  *p_msg)
484 484
 {
485 485
    struct timer_link *tl;
486 486
    unsigned int i;
... ...
@@ -1221,7 +1221,7 @@ int t_build_and_send_ACK( struct cell *Trans, unsigned int branch, struct sip_ms
1221 1221
 
1222 1222
    /* sends the ACK message to the same destination as the INVITE */
1223 1223
    udp_send( ack_buf, p-ack_buf, (struct sockaddr*)&(T->outbound_request[branch]->to) , sizeof(struct sockaddr_in) );
1224
-   DBG("DEBUG: t_build_and_send_ACK: ACK sent\n",);
1224
+   DBG("DEBUG: t_build_and_send_ACK: ACK sent\n");
1225 1225
 
1226 1226
    /* free mem*/
1227 1227
    if (ack_buf) free( ack_buf );
... ...
@@ -28,6 +28,7 @@ static int w_t_put_on_wait(struct sip_msg* msg, char* str, char* str2);
28 28
 static int fixup_t_forward(void** param, int param_no);
29 29
 static int fixup_t_forward_def(void** param, int param_no);
30 30
 static int fixup_t_send_reply(void** param, int param_no);
31
+static void tm_destroy_module();
31 32
 
32 33
 static struct module_exports nm_exports= {
33 34
 	"tm_module",
... ...
@@ -71,7 +72,8 @@ static struct module_exports nm_exports= {
71 71
 				0
72 72
 		},
73 73
 	8,
74
-	(response_function) t_on_reply_received
74
+	(response_function) t_on_reply_received,
75
+	(destroy_function) tm_destroy_module
75 76
 };
76 77
 
77 78
 
... ...
@@ -214,12 +216,15 @@ static int w_t_send_reply(struct sip_msg* msg, char* str, char* str2)
214 214
 	return t_send_reply(msg, (unsigned int) str, str2);
215 215
 }
216 216
 
217
+
217 218
 static int w_t_put_on_wait(struct sip_msg* msg, char* str, char* str2)
218 219
 {
219 220
 	return t_put_on_wait(msg);
220 221
 }
221 222
 
222 223
 
223
-
224
-
224
+static void tm_destroy_module()
225
+{
226
+	LOG(L_CRIT, "BUG: tm_destroy_module not implemented yet -FIX FIX FIX\n");
227
+}
225 228
 
... ...
@@ -108,3 +108,13 @@ struct sr_module* find_module(void* f, int *i)
108 108
 	}
109 109
 	return 0;
110 110
 }
111
+
112
+
113
+
114
+void destroy_modules()
115
+{
116
+	struct sr_module* t;
117
+
118
+	for(t=modules;t;t=t->next)
119
+		if  ((t->exports)&&(t->exports->destroy_f)) t->exports->destroy_f();
120
+}
... ...
@@ -11,6 +11,7 @@
11 11
 typedef  int (*cmd_function)(struct sip_msg*, char*, char*);
12 12
 typedef  int (*fixup_function)(void** param, int param_no);
13 13
 typedef  int (*response_function)(struct sip_msg*);
14
+typedef void (*destroy_function)();
14 15
 
15 16
 struct module_exports{
16 17
 	char* name; /* null terminated module name */
... ...
@@ -22,7 +23,11 @@ struct module_exports{
22 22
 	int cmd_no; /* number of registered commands 
23 23
 				   (size of cmd_{names,pointers}*/
24 24
 	response_function response_f; /* function used for responses,
25
-											   returns yes or no */
25
+											   returns yes or no;
26
+									can be null */
27
+	destroy_function destroy_f; /*function called when the module should
28
+								  be "destroyed", e.g: on ser exit;
29
+								  can be null */
26 30
 };
27 31
 
28 32
 struct sr_module{
... ...
@@ -37,6 +42,7 @@ struct sr_module* modules; /* global module list*/
37 37
 int load_module(char* path);
38 38
 cmd_function find_export(char* name, int param_no);
39 39
 struct sr_module* find_module(void *f, int* r);
40
+void destroy_modules();
40 41
 
41 42
 
42 43
 /* modules function prototypes: