Browse code

core: foundation for config interpreter engine via kemi

- to allow execution of a config file written in an embedded language

Daniel-Constantin Mierla authored on 12/04/2016 10:21:56
Showing 2 changed files
... ...
@@ -145,3 +145,71 @@ sr_kemi_t* sr_kemi_lookup(str *mname, int midx, str *fname)
145 145
 	}
146 146
 	return NULL;
147 147
 }
148
+
149
+/**
150
+ *
151
+ */
152
+
153
+#define SR_KEMI_ENG_LIST_MAX_SIZE	8
154
+static sr_kemi_eng_t _sr_kemi_eng_list[SR_KEMI_ENG_LIST_MAX_SIZE];
155
+sr_kemi_eng_t *_sr_kemi_eng = NULL;
156
+static int _sr_kemi_eng_list_size=0;
157
+
158
+/**
159
+ *
160
+ */
161
+int sr_kemi_eng_register(str *ename, sr_kemi_eng_route_f froute)
162
+{
163
+	int i;
164
+
165
+	for(i=0; i<_sr_kemi_eng_list_size; i++) {
166
+		if(_sr_kemi_eng_list[i].ename.len==ename->len
167
+				&& strncasecmp(_sr_kemi_eng_list[i].ename.s, ename->s,
168
+					ename->len)==0) {
169
+			/* found */
170
+			return 1;
171
+		}
172
+	}
173
+	if(_sr_kemi_eng_list_size>=SR_KEMI_ENG_LIST_MAX_SIZE) {
174
+		LM_ERR("too many config routing engines registered\n");
175
+		return -1;
176
+	}
177
+	if(ename->len>=SR_KEMI_BNAME_SIZE) {
178
+		LM_ERR("config routing engine name too long\n");
179
+		return -1;
180
+	}
181
+	strncpy(_sr_kemi_eng_list[_sr_kemi_eng_list_size].bname,
182
+			ename->s, ename->len);
183
+	_sr_kemi_eng_list[_sr_kemi_eng_list_size].ename.s
184
+			= _sr_kemi_eng_list[_sr_kemi_eng_list_size].bname;
185
+	_sr_kemi_eng_list[_sr_kemi_eng_list_size].ename.len = ename->len;
186
+	_sr_kemi_eng_list[_sr_kemi_eng_list_size].ename.s[ename->len] = 0;
187
+	_sr_kemi_eng_list[_sr_kemi_eng_list_size].froute = froute;
188
+	_sr_kemi_eng_list_size++;
189
+
190
+	return 0;
191
+}
192
+
193
+/**
194
+ *
195
+ */
196
+int sr_kemi_eng_set(str *ename, str *cpath)
197
+{
198
+	int i;
199
+
200
+	for(i=0; i<_sr_kemi_eng_list_size; i++) {
201
+		if(_sr_kemi_eng_list[i].ename.len==ename->len
202
+				&& strncasecmp(_sr_kemi_eng_list[i].ename.s, ename->s,
203
+					ename->len)==0) {
204
+			/* found */
205
+			_sr_kemi_eng = &_sr_kemi_eng_list[i];
206
+			return 0;
207
+		}
208
+	}
209
+	return -1;
210
+}
211
+
212
+sr_kemi_eng_t* sr_kemi_eng_get(void)
213
+{
214
+	return _sr_kemi_eng;
215
+}
... ...
@@ -89,4 +89,17 @@ int sr_kemi_modules_add(sr_kemi_t *klist);
89 89
 int sr_kemi_modules_size_get(void);
90 90
 sr_kemi_module_t* sr_kemi_modules_get(void);
91 91
 
92
+typedef int (*sr_kemi_eng_route_f)(sip_msg_t*, int, str *);
93
+
94
+#define SR_KEMI_BNAME_SIZE	256
95
+typedef struct sr_kemi_eng {
96
+	char bname[SR_KEMI_BNAME_SIZE];
97
+	str  ename;
98
+	sr_kemi_eng_route_f froute;
99
+} sr_kemi_eng_t;
100
+
101
+int sr_kemi_eng_register(str *ename, sr_kemi_eng_route_f froute);
102
+int sr_kemi_eng_set(str *ename, str *cpath);
103
+sr_kemi_eng_t* sr_kemi_eng_get(void);
104
+
92 105
 #endif