Quellcode durchsuchen

pv: added init and working destroy functions

- added init and destroy functions (declared in pvapi_init.h)
- fixed pv_table_free() and tr_table_free() bug
Andrei Pelinescu-Onciul vor 16 Jahren
Ursprung
Commit
8c3a715892
4 geänderte Dateien mit 56 neuen und 7 gelöschten Zeilen
  1. 4 1
      main.c
  2. 21 5
      pvapi.c
  3. 31 0
      pvapi_init.h
  4. 0 1
      pvar.h

+ 4 - 1
main.c

@@ -172,6 +172,7 @@
 #include "cfg_core.h"
 #include "endianness.h" /* init */
 #include "basex.h" /* init */
+#include "pvapi_init.h" /* init */
 #include "pv_core.h" /* register core pvars */
 
 #ifdef DEBUG_DMALLOC
@@ -532,6 +533,7 @@ void cleanup(show_status)
 	destroy_sctp();
 #endif
 	destroy_timer();
+	destroy_pv_api();
 	destroy_script_cb();
 	destroy_nonsip_hooks();
 	destroy_routes();
@@ -1764,9 +1766,10 @@ int main(int argc, char** argv)
 	if (init_routes()<0) goto error;
 	if (init_nonsip_hooks()<0) goto error;
 	if (init_script_cb()<0) goto error;
+	if (init_pv_api()<0) goto error;
+	if (pv_register_core_vars()!=0) goto error;
 	if (init_rpcs()<0) goto error;
 	if (register_core_rpcs()!=0) goto error;
-	if (pv_register_core_vars()!=0) goto error;
 
 	/* Fix the value of cfg_file variable.*/
 	if (fix_cfg_file() < 0) goto error;

+ 21 - 5
pvapi.c

@@ -36,6 +36,7 @@
 #include "dprint.h"
 #include "hashes.h"
 #include "route.h"
+#include "pvapi_init.h"
 #include "pvar.h"
 
 #define is_in_str(p, in) (p<in->s+in->len && *p)
@@ -196,9 +197,9 @@ int pv_table_free(void)
 			xe = xe->next;
 			pkg_free(xe1);
 		}
-		memset(_pv_table, 0, sizeof(pv_item_t*)*PV_TABLE_SIZE);
-		_pv_table_set = 0;
 	}
+	memset(_pv_table, 0, sizeof(pv_item_t*)*PV_TABLE_SIZE);
+	_pv_table_set = 0;
 	
 	return 0;
 }
@@ -1445,9 +1446,9 @@ int tr_table_free(void)
 			te = te->next;
 			pkg_free(te1);
 		}
-		memset(_tr_table, 0, sizeof(tr_item_t*)*TR_TABLE_SIZE);
-		_tr_table_set = 0;
 	}
+	memset(_tr_table, 0, sizeof(tr_item_t*)*TR_TABLE_SIZE);
+	_tr_table_set = 0;
 	
 	return 0;
 }
@@ -1478,8 +1479,23 @@ tr_export_t* tr_lookup_class(str *tclass)
 	return NULL;
 }
 
-void pv_api_destroy(void)
+
+/** init pv api (optional).
+ * @return 0 on success, -1 on error
+ */
+int init_pv_api(void)
+{
+	pv_init_table();
+	tr_init_table();
+	return 0;
+}
+
+
+/** destroy pv api. */
+void destroy_pv_api(void)
 {
 	/* free PV and TR hash tables */
+	pv_table_free();
+	tr_table_free();
 	return;
 }

+ 31 - 0
pvapi_init.h

@@ -0,0 +1,31 @@
+/* 
+ * $Id$
+ * 
+ * Copyright (C) 2009 iptelorg GmbH
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/*
+ * pvapi_init.h - pvapi init and destroy functions.
+ */
+
+#ifndef __pvapi_init_h
+#define __pvapi_init_h
+
+int init_pv_api(void);
+void destroy_pv_api(void);
+
+
+#endif /*__pvapi_init_h*/
+
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */

+ 0 - 1
pvar.h

@@ -184,7 +184,6 @@ int pv_parse_format(str *in, pv_elem_p *el);
 int pv_parse_index(pv_spec_p sp, str *in);
 int pv_init_iname(pv_spec_p sp, int param);
 int pv_printf_s(struct sip_msg* msg, pv_elem_p list, str *s);
-void pv_api_destroy(void);
 
 typedef struct _pvname_list {
 	pv_spec_t sname;