Browse code

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 authored on 08/10/2009 10:14:29
Showing 4 changed files
... ...
@@ -172,6 +172,7 @@
172 172
 #include "cfg_core.h"
173 173
 #include "endianness.h" /* init */
174 174
 #include "basex.h" /* init */
175
+#include "pvapi_init.h" /* init */
175 176
 #include "pv_core.h" /* register core pvars */
176 177
 
177 178
 #ifdef DEBUG_DMALLOC
... ...
@@ -532,6 +533,7 @@ void cleanup(show_status)
532 532
 	destroy_sctp();
533 533
 #endif
534 534
 	destroy_timer();
535
+	destroy_pv_api();
535 536
 	destroy_script_cb();
536 537
 	destroy_nonsip_hooks();
537 538
 	destroy_routes();
... ...
@@ -1764,9 +1766,10 @@ int main(int argc, char** argv)
1764 1764
 	if (init_routes()<0) goto error;
1765 1765
 	if (init_nonsip_hooks()<0) goto error;
1766 1766
 	if (init_script_cb()<0) goto error;
1767
+	if (init_pv_api()<0) goto error;
1768
+	if (pv_register_core_vars()!=0) goto error;
1767 1769
 	if (init_rpcs()<0) goto error;
1768 1770
 	if (register_core_rpcs()!=0) goto error;
1769
-	if (pv_register_core_vars()!=0) goto error;
1770 1771
 
1771 1772
 	/* Fix the value of cfg_file variable.*/
1772 1773
 	if (fix_cfg_file() < 0) goto error;
... ...
@@ -36,6 +36,7 @@
36 36
 #include "dprint.h"
37 37
 #include "hashes.h"
38 38
 #include "route.h"
39
+#include "pvapi_init.h"
39 40
 #include "pvar.h"
40 41
 
41 42
 #define is_in_str(p, in) (p<in->s+in->len && *p)
... ...
@@ -196,9 +197,9 @@ int pv_table_free(void)
196 196
 			xe = xe->next;
197 197
 			pkg_free(xe1);
198 198
 		}
199
-		memset(_pv_table, 0, sizeof(pv_item_t*)*PV_TABLE_SIZE);
200
-		_pv_table_set = 0;
201 199
 	}
200
+	memset(_pv_table, 0, sizeof(pv_item_t*)*PV_TABLE_SIZE);
201
+	_pv_table_set = 0;
202 202
 	
203 203
 	return 0;
204 204
 }
... ...
@@ -1445,9 +1446,9 @@ int tr_table_free(void)
1445 1445
 			te = te->next;
1446 1446
 			pkg_free(te1);
1447 1447
 		}
1448
-		memset(_tr_table, 0, sizeof(tr_item_t*)*TR_TABLE_SIZE);
1449
-		_tr_table_set = 0;
1450 1448
 	}
1449
+	memset(_tr_table, 0, sizeof(tr_item_t*)*TR_TABLE_SIZE);
1450
+	_tr_table_set = 0;
1451 1451
 	
1452 1452
 	return 0;
1453 1453
 }
... ...
@@ -1478,8 +1479,23 @@ tr_export_t* tr_lookup_class(str *tclass)
1478 1478
 	return NULL;
1479 1479
 }
1480 1480
 
1481
-void pv_api_destroy(void)
1481
+
1482
+/** init pv api (optional).
1483
+ * @return 0 on success, -1 on error
1484
+ */
1485
+int init_pv_api(void)
1486
+{
1487
+	pv_init_table();
1488
+	tr_init_table();
1489
+	return 0;
1490
+}
1491
+
1492
+
1493
+/** destroy pv api. */
1494
+void destroy_pv_api(void)
1482 1495
 {
1483 1496
 	/* free PV and TR hash tables */
1497
+	pv_table_free();
1498
+	tr_table_free();
1484 1499
 	return;
1485 1500
 }
1486 1501
new file mode 100644
... ...
@@ -0,0 +1,31 @@
0
+/* 
1
+ * $Id$
2
+ * 
3
+ * Copyright (C) 2009 iptelorg GmbH
4
+ *
5
+ * Permission to use, copy, modify, and distribute this software for any
6
+ * purpose with or without fee is hereby granted, provided that the above
7
+ * copyright notice and this permission notice appear in all copies.
8
+ *
9
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
+ */
17
+/*
18
+ * pvapi_init.h - pvapi init and destroy functions.
19
+ */
20
+
21
+#ifndef __pvapi_init_h
22
+#define __pvapi_init_h
23
+
24
+int init_pv_api(void);
25
+void destroy_pv_api(void);
26
+
27
+
28
+#endif /*__pvapi_init_h*/
29
+
30
+/* vi: set ts=4 sw=4 tw=79:ai:cindent: */
... ...
@@ -184,7 +184,6 @@ int pv_parse_format(str *in, pv_elem_p *el);
184 184
 int pv_parse_index(pv_spec_p sp, str *in);
185 185
 int pv_init_iname(pv_spec_p sp, int param);
186 186
 int pv_printf_s(struct sip_msg* msg, pv_elem_p list, str *s);
187
-void pv_api_destroy(void);
188 187
 
189 188
 typedef struct _pvname_list {
190 189
 	pv_spec_t sname;