Module: sip-router
Branch: master
Commit: 8c3a715892421cdbc309ab37b16dcf349078f487
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8c3a715…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Thu Oct 8 12:14:29 2009 +0200
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
---
main.c | 5 ++++-
pvapi.c | 26 +++++++++++++++++++++-----
pvapi_init.h | 31 +++++++++++++++++++++++++++++++
pvar.h | 1 -
4 files changed, 56 insertions(+), 7 deletions(-)
diff --git a/main.c b/main.c
index 01a6fde..e5e0833 100644
--- a/main.c
+++ b/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;
diff --git a/pvapi.c b/pvapi.c
index 34ef819..99226da 100644
--- a/pvapi.c
+++ b/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;
}
diff --git a/pvapi_init.h b/pvapi_init.h
new file mode 100644
index 0000000..1d4ccd6
--- /dev/null
+++ b/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: */
diff --git a/pvar.h b/pvar.h
index bb98ef0..19b9310 100644
--- a/pvar.h
+++ b/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;