Module: sip-router Branch: master Commit: 6b2081df15344300ccdeda67c5447a512920fe98 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6b2081df...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Fri Nov 26 22:42:46 2010 +0100
htable: exported inter-module API
---
modules_k/htable/api.c | 128 +++++++++++++++++++++++++++++++++++++++++++++ modules_k/htable/api.h | 73 +++++++++++++++++++++++++ modules_k/htable/htable.c | 18 +++--- 3 files changed, 210 insertions(+), 9 deletions(-)
diff --git a/modules_k/htable/api.c b/modules_k/htable/api.c new file mode 100644 index 0000000..4a2d0df --- /dev/null +++ b/modules_k/htable/api.c @@ -0,0 +1,128 @@ +/** + * $Id$ + * + * Copyright (C) 2008 Elena-Ramona Modroiu (asipto.com) + * + * This file is part of kamailio, a free SIP server. + * + * openser is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version + * + * openser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#include "../../dprint.h" + +#include "ht_api.h" +#include "api.h" + +/** + * + */ +int ht_api_set_cell(str *hname, str *name, int type, + int_str *val, int mode) +{ + ht_t* ht; + ht = ht_get_table(hname); + if(ht==NULL) + return -1; + return ht_set_cell(ht, name, type, val, mode); +} + +/** + * + */ +int ht_api_del_cell(str *hname, str *name) +{ + ht_t* ht; + ht = ht_get_table(hname); + if(ht==NULL) + return -1; + return ht_del_cell(ht, name); +} + +/** + * + */ +int ht_api_set_cell_expire(str *hname, str *name, + int type, int_str *val) +{ + ht_t* ht; + ht = ht_get_table(hname); + if(ht==NULL) + return -1; + return ht_set_cell_expire(ht, name, type, val); +} + +/** + * + */ +int ht_api_get_cell_expire(str *hname, str *name, + unsigned int *val) +{ + ht_t* ht; + ht = ht_get_table(hname); + if(ht==NULL) + return -1; + return ht_get_cell_expire(ht, name, val); +} + +/** + * + */ +int ht_api_rm_cell_re(str *hname, str *sre, int mode) +{ + ht_t* ht; + ht = ht_get_table(hname); + if(ht==NULL) + return -1; + if(ht_rm_cell_re(sre, ht, mode /* 0 - name; 1 - value */)<0) + return -1; + return 0; +} + +/** + * + */ +int ht_api_count_cells_re(str *hname, str *sre, int mode) +{ + ht_t* ht; + ht = ht_get_table(hname); + if(ht==NULL) + return -1; + if(ht_count_cells_re(sre, ht, mode /* 0 - name; 1 - value */)<0) + return -1; + return 0; +} + +/** + * + */ +int bind_htable(htable_api_t* api) +{ + if (!api) { + ERR("Invalid parameter value\n"); + return -1; + } + api->set = ht_api_set_cell; + api->rm = ht_api_del_cell; + api->set_expire = ht_api_set_cell_expire; + api->get_expire = ht_api_get_cell_expire; + api->rm_re = ht_api_rm_cell_re; + api->count_re = ht_api_count_cells_re; + return 0; +} + diff --git a/modules_k/htable/api.h b/modules_k/htable/api.h new file mode 100644 index 0000000..868abf2 --- /dev/null +++ b/modules_k/htable/api.h @@ -0,0 +1,73 @@ +/** + * $Id$ + * + * Copyright (C) 2008 Elena-Ramona Modroiu (asipto.com) + * + * This file is part of kamailio, a free SIP server. + * + * openser is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version + * + * openser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _HT_MOD_API_H_ +#define _HT_MOD_API_H_ + +#include "../../sr_module.h" +#include "../../usr_avp.h" + +typedef int (*ht_api_set_cell_f)(str *hname, str *name, int type, + int_str *val, int mode); +typedef int (*ht_api_del_cell_f)(str *hname, str *name); + +typedef int (*ht_api_set_cell_expire_f)(str *hname, str *name, + int type, int_str *val); +typedef int (*ht_api_get_cell_expire_f)(str *hname, str *name, + unsigned int *val); + +typedef int (*ht_api_rm_cell_re_f)(str *hname, str *sre, int mode); +typedef int (*ht_api_count_cells_re_f)(str *hname, str *sre, int mode); + +typedef struct htable_api { + ht_api_set_cell_f set; + ht_api_del_cell_f rm; + ht_api_set_cell_expire_f set_expire; + ht_api_get_cell_expire_f get_expire; + ht_api_rm_cell_re_f rm_re; + ht_api_count_cells_re_f count_re; +} htable_api_t; + +typedef int (*bind_htable_f)(htable_api_t* api); +int bind_htable(htable_api_t* api); + +/** + * @brief Load the Sanity API + */ +static inline int htable_load_api(htable_api_t *api) +{ + bind_htable_f bindhtable; + + bindhtable = (bind_htable_f)find_export("bind_htable", 0, 0); + if(bindhtable == 0) { + LM_ERR("cannot find bind_htable\n"); + return -1; + } + if(bindhtable(api)<0) + { + LM_ERR("cannot bind htable api\n"); + return -1; + } + return 0; +} + +#endif diff --git a/modules_k/htable/htable.c b/modules_k/htable/htable.c index 85d238b..ac01e32 100644 --- a/modules_k/htable/htable.c +++ b/modules_k/htable/htable.c @@ -42,6 +42,7 @@ #include "ht_api.h" #include "ht_db.h" #include "ht_var.h" +#include "api.h"
MODULE_VERSION @@ -86,15 +87,14 @@ static mi_export_t mi_cmds[] = {
static cmd_export_t cmds[]={ - {"sht_print", (cmd_function)ht_print, 0, 0, 0, - REQUEST_ROUTE | FAILURE_ROUTE | - ONREPLY_ROUTE | BRANCH_ROUTE | ERROR_ROUTE | LOCAL_ROUTE}, - {"sht_rm_name_re", (cmd_function)ht_rm_name_re, 1, fixup_ht_rm, 0, - REQUEST_ROUTE | FAILURE_ROUTE | - ONREPLY_ROUTE | BRANCH_ROUTE | ERROR_ROUTE | LOCAL_ROUTE}, - {"sht_rm_value_re", (cmd_function)ht_rm_value_re, 1, fixup_ht_rm, 0, - REQUEST_ROUTE | FAILURE_ROUTE | - ONREPLY_ROUTE | BRANCH_ROUTE | ERROR_ROUTE | LOCAL_ROUTE}, + {"sht_print", (cmd_function)ht_print, 0, 0, 0, + ANY_ROUTE}, + {"sht_rm_name_re", (cmd_function)ht_rm_name_re, 1, fixup_ht_rm, 0, + ANY_ROUTE}, + {"sht_rm_value_re", (cmd_function)ht_rm_value_re, 1, fixup_ht_rm, 0, + ANY_ROUTE}, + {"bind_htable", (cmd_function)bind_htable, 0, 0, 0, + ANY_ROUTE}, {0,0,0,0,0,0} };