瀏覽代碼

- 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 24 年之前
父節點
當前提交
bf08223a61
共有 5 個文件被更改,包括 33 次插入10 次删除
  1. 6 4
      main.c
  2. 2 2
      modules/tm/t_funcs.c
  3. 8 3
      modules/tm/tm.c
  4. 10 0
      sr_module.c
  5. 7 1
      sr_module.h

+ 6 - 4
main.c

@@ -27,6 +27,7 @@
 #ifdef SHM_MEM
 #include "shm_mem.h"
 #endif
+#include "sr_module.h"
 
 
 #include <signal.h>
@@ -296,19 +297,20 @@ static void sig_usr(int signo)
 			else
 				printf("statistics dump to %s failed\n", stat_file );
 #endif
+		DPrint("INT received, program terminates\n");
+		DPrint("Thank you for flying ser\n");
+		/* WARNING: very dangerous, might be unsafe*/
+		destroy_modules();
 #ifdef PKG_MALLOC
 		pkg_status();
 #endif
 #ifdef SHM_MEM
 		shm_status();
 #endif
-		DPrint("INT received, program terminates\n");
-		DPrint("Thank you for flying ser\n");
-		/* WARNING: very dangerous, might be unsafe*/
 #ifdef SHM_MEM
 		shm_mem_destroy();
-		exit(0);
 #endif
+		exit(0);
 	} else if (signo==SIGUSR1) { /* statistic */
 #ifdef STATS
 		dump_all_statistic();

+ 2 - 2
modules/tm/t_funcs.c

@@ -480,7 +480,7 @@ int t_on_reply_received( struct sip_msg  *p_msg )
 
 /*   returns 1 if everything was OK or -1 for error
   */
-int t_put_on_wait(  struct sip_msg  *p_msg  )
+int t_put_on_wait(  struct sip_msg  *p_msg)
 {
    struct timer_link *tl;
    unsigned int i;
@@ -1221,7 +1221,7 @@ int t_build_and_send_ACK( struct cell *Trans, unsigned int branch, struct sip_ms
 
    /* sends the ACK message to the same destination as the INVITE */
    udp_send( ack_buf, p-ack_buf, (struct sockaddr*)&(T->outbound_request[branch]->to) , sizeof(struct sockaddr_in) );
-   DBG("DEBUG: t_build_and_send_ACK: ACK sent\n",);
+   DBG("DEBUG: t_build_and_send_ACK: ACK sent\n");
 
    /* free mem*/
    if (ack_buf) free( ack_buf );

+ 8 - 3
modules/tm/tm.c

@@ -28,6 +28,7 @@ static int w_t_put_on_wait(struct sip_msg* msg, char* str, char* str2);
 static int fixup_t_forward(void** param, int param_no);
 static int fixup_t_forward_def(void** param, int param_no);
 static int fixup_t_send_reply(void** param, int param_no);
+static void tm_destroy_module();
 
 static struct module_exports nm_exports= {
 	"tm_module",
@@ -71,7 +72,8 @@ static struct module_exports nm_exports= {
 				0
 		},
 	8,
-	(response_function) t_on_reply_received
+	(response_function) t_on_reply_received,
+	(destroy_function) tm_destroy_module
 };
 
 
@@ -214,12 +216,15 @@ static int w_t_send_reply(struct sip_msg* msg, char* str, char* str2)
 	return t_send_reply(msg, (unsigned int) str, str2);
 }
 
+
 static int w_t_put_on_wait(struct sip_msg* msg, char* str, char* str2)
 {
 	return t_put_on_wait(msg);
 }
 
 
-
-
+static void tm_destroy_module()
+{
+	LOG(L_CRIT, "BUG: tm_destroy_module not implemented yet -FIX FIX FIX\n");
+}
 

+ 10 - 0
sr_module.c

@@ -108,3 +108,13 @@ struct sr_module* find_module(void* f, int *i)
 	}
 	return 0;
 }
+
+
+
+void destroy_modules()
+{
+	struct sr_module* t;
+
+	for(t=modules;t;t=t->next)
+		if  ((t->exports)&&(t->exports->destroy_f)) t->exports->destroy_f();
+}

+ 7 - 1
sr_module.h

@@ -11,6 +11,7 @@
 typedef  int (*cmd_function)(struct sip_msg*, char*, char*);
 typedef  int (*fixup_function)(void** param, int param_no);
 typedef  int (*response_function)(struct sip_msg*);
+typedef void (*destroy_function)();
 
 struct module_exports{
 	char* name; /* null terminated module name */
@@ -22,7 +23,11 @@ struct module_exports{
 	int cmd_no; /* number of registered commands 
 				   (size of cmd_{names,pointers}*/
 	response_function response_f; /* function used for responses,
-											   returns yes or no */
+											   returns yes or no;
+									can be null */
+	destroy_function destroy_f; /*function called when the module should
+								  be "destroyed", e.g: on ser exit;
+								  can be null */
 };
 
 struct sr_module{
@@ -37,6 +42,7 @@ struct sr_module* modules; /* global module list*/
 int load_module(char* path);
 cmd_function find_export(char* name, int param_no);
 struct sr_module* find_module(void *f, int* r);
+void destroy_modules();
 
 
 /* modules function prototypes: