Module: kamailio
Branch: master
Commit: 0efa0994519428c415c0cf16266b6bfc8345b67c
URL:
https://github.com/kamailio/kamailio/commit/0efa0994519428c415c0cf16266b6bf…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-04-13T09:27:13+02:00
speeddial: exported functions to kemi framework
---
Modified: src/modules/speeddial/sdlookup.c
Modified: src/modules/speeddial/sdlookup.h
Modified: src/modules/speeddial/speeddial.c
---
Diff:
https://github.com/kamailio/kamailio/commit/0efa0994519428c415c0cf16266b6bf…
Patch:
https://github.com/kamailio/kamailio/commit/0efa0994519428c415c0cf16266b6bf…
---
diff --git a/src/modules/speeddial/sdlookup.c b/src/modules/speeddial/sdlookup.c
index 79d52a8..13c7095 100644
--- a/src/modules/speeddial/sdlookup.c
+++ b/src/modules/speeddial/sdlookup.c
@@ -61,7 +61,7 @@ static inline int rewrite_ruri(struct sip_msg* _m, char* _s)
/**
*
*/
-int sd_lookup(struct sip_msg* _msg, char* _table, char* _owner)
+int sd_lookup_owner(sip_msg_t* _msg, str* stable, str* sowner)
{
str user_s, table_s, uri_s;
int nr_keys;
@@ -72,24 +72,21 @@ int sd_lookup(struct sip_msg* _msg, char* _table, char* _owner)
db_key_t db_cols[1];
db1_res_t* db_res = NULL;
- if(_table==NULL || fixup_get_svalue(_msg, (gparam_p)_table, &table_s)!=0)
+ if(stable==NULL || stable->s==NULL || stable->len<=0)
{
LM_ERR("invalid table parameter");
return -1;
}
+ table_s = *stable;
/* init */
nr_keys = 0;
db_cols[0]=&new_uri_column;
- if(_owner)
+ if(sowner!=NULL && sowner->s!=NULL && sowner->len>0)
{
+ uri_s = *sowner;
memset(&turi, 0, sizeof(struct sip_uri));
- if(fixup_get_svalue(_msg, (gparam_p)_owner, &uri_s)!=0)
- {
- LM_ERR("invalid owner uri parameter");
- return -1;
- }
if(parse_uri(uri_s.s, uri_s.len, &turi)!=0)
{
LM_ERR("bad owner SIP address!\n");
@@ -236,3 +233,28 @@ int sd_lookup(struct sip_msg* _msg, char* _table, char* _owner)
return -1;
}
+/**
+ *
+ */
+int w_sd_lookup(struct sip_msg* _msg, char* _table, char* _owner)
+{
+ str table_s, uri_s;
+
+ if(_table==NULL || fixup_get_svalue(_msg, (gparam_p)_table, &table_s)!=0)
+ {
+ LM_ERR("invalid table parameter");
+ return -1;
+ }
+
+ if(_owner)
+ {
+ if(fixup_get_svalue(_msg, (gparam_p)_owner, &uri_s)!=0)
+ {
+ LM_ERR("invalid owner uri parameter");
+ return -1;
+ }
+ return sd_lookup_owner(_msg, &table_s, &uri_s);
+ }
+
+ return sd_lookup_owner(_msg, &table_s, NULL);
+}
diff --git a/src/modules/speeddial/sdlookup.h b/src/modules/speeddial/sdlookup.h
index ea846b7..582afd4 100644
--- a/src/modules/speeddial/sdlookup.h
+++ b/src/modules/speeddial/sdlookup.h
@@ -26,6 +26,7 @@
#include "../../core/parser/msg_parser.h"
-int sd_lookup(struct sip_msg* _msg, char* _table, char* _str2);
+int w_sd_lookup(struct sip_msg* _msg, char* _table, char* _owner);
+int sd_lookup_owner(struct sip_msg* _msg, str* _stable, str* _sowner);
#endif /* _SDLOOKUP_H_ */
diff --git a/src/modules/speeddial/speeddial.c b/src/modules/speeddial/speeddial.c
index 6c4e2a5..d5baa65 100644
--- a/src/modules/speeddial/speeddial.c
+++ b/src/modules/speeddial/speeddial.c
@@ -29,6 +29,7 @@
#include "../../core/error.h"
#include "../../core/mem/mem.h"
#include "../../core/mod_fix.h"
+#include "../../core/kemi.h"
#include "sdlookup.h"
@@ -65,9 +66,9 @@ db1_con_t* db_handle=0; /* Database connection handle */
/* Exported functions */
static cmd_export_t cmds[] = {
- {"sd_lookup", (cmd_function)sd_lookup, 1, fixup_spve_null, 0,
+ {"sd_lookup", (cmd_function)w_sd_lookup, 1, fixup_spve_null, 0,
REQUEST_ROUTE},
- {"sd_lookup", (cmd_function)sd_lookup, 2, fixup_spve_spve, 0,
+ {"sd_lookup", (cmd_function)w_sd_lookup, 2, fixup_spve_spve, 0,
REQUEST_ROUTE},
{0, 0, 0, 0, 0, 0}
};
@@ -158,3 +159,39 @@ static void destroy(void)
db_funcs.close(db_handle);
}
+/**
+ *
+ */
+static int ki_sd_lookup(sip_msg_t *msg, str *stable)
+{
+ return sd_lookup_owner(msg, stable, NULL);
+}
+
+/**
+ *
+ */
+/* clang-format off */
+static sr_kemi_t sr_kemi_speeddial_exports[] = {
+ { str_init("speeddial"), str_init("lookup"),
+ SR_KEMIP_INT, ki_sd_lookup,
+ { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("speeddial"), str_init("lookup_owner"),
+ SR_KEMIP_INT, sd_lookup_owner,
+ { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+
+ { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
+};
+/* clang-format on */
+
+/**
+ *
+ */
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
+{
+ sr_kemi_modules_add(sr_kemi_speeddial_exports);
+ return 0;
+}