Module: kamailio
Branch: master
Commit: 16a41dba5c7baef489f735d15e6c912e59d8857f
URL:
https://github.com/kamailio/kamailio/commit/16a41dba5c7baef489f735d15e6c912…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2016-04-12T08:22:37+02:00
core: kemi - index embedded api functions by module
---
Modified: kemi.c
Modified: kemi.h
---
Diff:
https://github.com/kamailio/kamailio/commit/16a41dba5c7baef489f735d15e6c912…
Patch:
https://github.com/kamailio/kamailio/commit/16a41dba5c7baef489f735d15e6c912…
---
diff --git a/kemi.c b/kemi.c
index fa3ad8f..305d066 100644
--- a/kemi.c
+++ b/kemi.c
@@ -27,3 +27,121 @@
#include "kemi.h"
+#define SR_KEMI_MODULES_MAX_SIZE 1024
+static int _sr_kemi_modules_size = 1;
+static sr_kemi_module_t _sr_kemi_modules[SR_KEMI_MODULES_MAX_SIZE];
+
+/**
+ *
+ */
+int sr_kemi_modules_add(sr_kemi_t *klist)
+{
+ if(_sr_kemi_modules_size>=SR_KEMI_MODULES_MAX_SIZE) {
+ return -1;
+ }
+ LM_DBG("adding module: %.*s\n", klist[0].mname.len, klist[0].mname.s);
+ _sr_kemi_modules[_sr_kemi_modules_size].mname = klist[0].mname;
+ _sr_kemi_modules[_sr_kemi_modules_size].kexp = klist;
+ _sr_kemi_modules_size++;
+ return 0;
+}
+
+/**
+ *
+ */
+int sr_kemi_modules_size_get(void)
+{
+ return _sr_kemi_modules_size;
+}
+
+/**
+ *
+ */
+sr_kemi_module_t* sr_kemi_modules_get(void)
+{
+ return _sr_kemi_modules;
+}
+
+/**
+ *
+ */
+static int lua_sr_kemi_dbg(sip_msg_t *msg, str *txt)
+{
+ if(txt!=NULL && txt->s!=NULL)
+ LM_DBG("%.*s", txt->len, txt->s);
+ return 0;
+}
+
+/**
+ *
+ */
+static int lua_sr_kemi_err(sip_msg_t *msg, str *txt)
+{
+ if(txt!=NULL && txt->s!=NULL)
+ LM_ERR("%.*s", txt->len, txt->s);
+ return 0;
+}
+
+/**
+ *
+ */
+static int lua_sr_kemi_info(sip_msg_t *msg, str *txt)
+{
+ if(txt!=NULL && txt->s!=NULL)
+ LM_INFO("%.*s", txt->len, txt->s);
+ return 0;
+}
+
+
+/**
+ *
+ */
+static sr_kemi_t _sr_kemi_core[] = {
+ { str_init(""), str_init("dbg"),
+ SR_KEMIP_NONE, lua_sr_kemi_dbg,
+ { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init(""), str_init("err"),
+ SR_KEMIP_NONE, lua_sr_kemi_err,
+ { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init(""), str_init("info"),
+ SR_KEMIP_NONE, lua_sr_kemi_info,
+ { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+
+ { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
+};
+
+/**
+ *
+ */
+sr_kemi_t* sr_kemi_lookup(str *mname, int midx, str *fname)
+{
+ int i;
+ sr_kemi_t *ket;
+
+ if(mname==NULL || mname->len<=0) {
+ for(i=0; ; i++) {
+ ket = &_sr_kemi_core[i];
+ if(ket->fname.len==fname->len
+ && strncasecmp(ket->fname.s, fname->s, fname->len)==0) {
+ return ket;
+ }
+ }
+ } else {
+ if(midx>0 && midx<SR_KEMI_MODULES_MAX_SIZE) {
+ for(i=0; ; i++) {
+ ket = &_sr_kemi_modules[midx].kexp[i];
+ if(ket->fname.len==fname->len
+ && strncasecmp(ket->fname.s, fname->s, fname->len)==0) {
+ return ket;
+ }
+ }
+ }
+ }
+ return NULL;
+}
diff --git a/kemi.h b/kemi.h
index cc49212..45b98a2 100644
--- a/kemi.h
+++ b/kemi.h
@@ -46,6 +46,11 @@ typedef struct sr_kemi_item {
struct sr_kemi_item *next;
} sr_kemi_item_t;
+typedef struct sr_kemi_module {
+ str mname;
+ sr_kemi_t *kexp;
+} sr_kemi_module_t;
+
typedef union {
int n;
str s;
@@ -74,4 +79,14 @@ typedef int (*sr_kemi_fmsns_f)(sip_msg_t*, str*, int, str*);
typedef int (*sr_kemi_fmssn_f)(sip_msg_t*, str*, str*, int);
typedef int (*sr_kemi_fmsss_f)(sip_msg_t*, str*, str*, str*);
+typedef int (*sr_kemi_fmssss_f)(sip_msg_t*, str*, str*, str*, str*);
+typedef int (*sr_kemi_fmsssss_f)(sip_msg_t*, str*, str*, str*, str*, str*);
+typedef int (*sr_kemi_fmssssss_f)(sip_msg_t*, str*, str*, str*, str*, str*, str*);
+
+sr_kemi_t* sr_kemi_lookup(str *mname, int midx, str *fname);
+
+int sr_kemi_modules_add(sr_kemi_t *klist);
+int sr_kemi_modules_size_get(void);
+sr_kemi_module_t* sr_kemi_modules_get(void);
+
#endif