Browse code

core: kemi - index embedded api functions by module

Daniel-Constantin Mierla authored on 12/04/2016 06:17:34
Showing 2 changed files
... ...
@@ -27,3 +27,121 @@
27 27
 
28 28
 #include "kemi.h"
29 29
 
30
+#define SR_KEMI_MODULES_MAX_SIZE	1024
31
+static int _sr_kemi_modules_size = 1;
32
+static sr_kemi_module_t _sr_kemi_modules[SR_KEMI_MODULES_MAX_SIZE];
33
+
34
+/**
35
+ *
36
+ */
37
+int sr_kemi_modules_add(sr_kemi_t *klist)
38
+{
39
+	if(_sr_kemi_modules_size>=SR_KEMI_MODULES_MAX_SIZE) {
40
+		return -1;
41
+	}
42
+	LM_DBG("adding module: %.*s\n", klist[0].mname.len, klist[0].mname.s);
43
+	_sr_kemi_modules[_sr_kemi_modules_size].mname = klist[0].mname;
44
+	_sr_kemi_modules[_sr_kemi_modules_size].kexp = klist;
45
+	_sr_kemi_modules_size++;
46
+	return 0;
47
+}
48
+
49
+/**
50
+ *
51
+ */
52
+int sr_kemi_modules_size_get(void)
53
+{
54
+	return _sr_kemi_modules_size;
55
+}
56
+
57
+/**
58
+ *
59
+ */
60
+sr_kemi_module_t* sr_kemi_modules_get(void)
61
+{
62
+	return _sr_kemi_modules;
63
+}
64
+
65
+/**
66
+ *
67
+ */
68
+static int lua_sr_kemi_dbg(sip_msg_t *msg, str *txt)
69
+{
70
+	if(txt!=NULL && txt->s!=NULL)
71
+		LM_DBG("%.*s", txt->len, txt->s);
72
+	return 0;
73
+}
74
+
75
+/**
76
+ *
77
+ */
78
+static int lua_sr_kemi_err(sip_msg_t *msg, str *txt)
79
+{
80
+	if(txt!=NULL && txt->s!=NULL)
81
+		LM_ERR("%.*s", txt->len, txt->s);
82
+	return 0;
83
+}
84
+
85
+/**
86
+ *
87
+ */
88
+static int lua_sr_kemi_info(sip_msg_t *msg, str *txt)
89
+{
90
+	if(txt!=NULL && txt->s!=NULL)
91
+		LM_INFO("%.*s", txt->len, txt->s);
92
+	return 0;
93
+}
94
+
95
+
96
+/**
97
+ *
98
+ */
99
+static sr_kemi_t _sr_kemi_core[] = {
100
+	{ str_init(""), str_init("dbg"),
101
+		SR_KEMIP_NONE, lua_sr_kemi_dbg,
102
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
103
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
104
+	},
105
+	{ str_init(""), str_init("err"),
106
+		SR_KEMIP_NONE, lua_sr_kemi_err,
107
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
108
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
109
+	},
110
+	{ str_init(""), str_init("info"),
111
+		SR_KEMIP_NONE, lua_sr_kemi_info,
112
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
113
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
114
+	},
115
+
116
+	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
117
+};
118
+
119
+/**
120
+ *
121
+ */
122
+sr_kemi_t* sr_kemi_lookup(str *mname, int midx, str *fname)
123
+{
124
+	int i;
125
+	sr_kemi_t *ket;
126
+
127
+	if(mname==NULL || mname->len<=0) {
128
+		for(i=0; ; i++) {
129
+			ket = &_sr_kemi_core[i];
130
+			if(ket->fname.len==fname->len
131
+					&& strncasecmp(ket->fname.s, fname->s, fname->len)==0) {
132
+				return ket;
133
+			}
134
+		}
135
+	} else {
136
+		if(midx>0 && midx<SR_KEMI_MODULES_MAX_SIZE) {
137
+			for(i=0; ; i++) {
138
+				ket = &_sr_kemi_modules[midx].kexp[i];
139
+				if(ket->fname.len==fname->len
140
+						&& strncasecmp(ket->fname.s, fname->s, fname->len)==0) {
141
+					return ket;
142
+				}
143
+			}
144
+		}
145
+	}
146
+	return NULL;
147
+}
... ...
@@ -46,6 +46,11 @@ typedef struct sr_kemi_item {
46 46
 	struct sr_kemi_item *next;
47 47
 } sr_kemi_item_t;
48 48
 
49
+typedef struct sr_kemi_module {
50
+	str mname;
51
+	sr_kemi_t *kexp;
52
+} sr_kemi_module_t;
53
+
49 54
 typedef union {
50 55
 	int n;
51 56
 	str s;
... ...
@@ -74,4 +79,14 @@ typedef int (*sr_kemi_fmsns_f)(sip_msg_t*, str*, int, str*);
74 74
 typedef int (*sr_kemi_fmssn_f)(sip_msg_t*, str*, str*, int);
75 75
 typedef int (*sr_kemi_fmsss_f)(sip_msg_t*, str*, str*, str*);
76 76
 
77
+typedef int (*sr_kemi_fmssss_f)(sip_msg_t*, str*, str*, str*, str*);
78
+typedef int (*sr_kemi_fmsssss_f)(sip_msg_t*, str*, str*, str*, str*, str*);
79
+typedef int (*sr_kemi_fmssssss_f)(sip_msg_t*, str*, str*, str*, str*, str*, str*);
80
+
81
+sr_kemi_t* sr_kemi_lookup(str *mname, int midx, str *fname);
82
+
83
+int sr_kemi_modules_add(sr_kemi_t *klist);
84
+int sr_kemi_modules_size_get(void);
85
+sr_kemi_module_t* sr_kemi_modules_get(void);
86
+
77 87
 #endif