Browse code

core, lib, modules: updated include paths for header files

Daniel-Constantin Mierla authored on 07/12/2016 11:07:22
Showing 1 changed files
... ...
@@ -26,9 +26,9 @@
26 26
  */
27 27
 
28 28
 
29
-#include "../../mem/mem.h"
30
-#include "../../dprint.h"
31
-#include "../../mod_fix.h"
29
+#include "../../core/mem/mem.h"
30
+#include "../../core/dprint.h"
31
+#include "../../core/mod_fix.h"
32 32
 
33 33
 #include "sql_api.h"
34 34
 #include "sql_var.h"
Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,280 @@
1
+/**
2
+ * Copyright (C) 2008 Elena-Ramona Modroiu (asipto.com)
3
+ *
4
+ * This file is part of kamailio, a free SIP server.
5
+ *
6
+ * Kamailio is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version
10
+ *
11
+ * Kamailio is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
+ */
20
+
21
+/*! \file
22
+ * \ingroup sqlops
23
+ * \brief Kamailio SQL-operations :: Variables
24
+ *
25
+ * - Module: \ref sqlops
26
+ */
27
+
28
+
29
+#include "../../mem/mem.h"
30
+#include "../../dprint.h"
31
+#include "../../mod_fix.h"
32
+
33
+#include "sql_api.h"
34
+#include "sql_var.h"
35
+
36
+typedef struct _sql_pv {
37
+	str resname;
38
+	sql_result_t *res;
39
+	int type;
40
+	gparam_t row;
41
+	gparam_t col;
42
+} sql_pv_t;
43
+
44
+int pv_get_dbr(struct sip_msg *msg,  pv_param_t *param,
45
+		pv_value_t *res)
46
+{
47
+	sql_pv_t *spv;
48
+	int row;
49
+	int col;
50
+
51
+	spv = (sql_pv_t*)param->pvn.u.dname;
52
+
53
+	if(spv->res==NULL)
54
+	{
55
+		spv->res = sql_get_result(&spv->resname);
56
+		if(spv->res==NULL)
57
+			return pv_get_null(msg, param, res);
58
+	}
59
+
60
+	switch(spv->type)
61
+	{
62
+		case 1:
63
+			return pv_get_sintval(msg, param, res, spv->res->nrows);
64
+		break;
65
+		case 2:
66
+			return pv_get_sintval(msg, param, res, spv->res->ncols);
67
+		break;
68
+		case 3:
69
+			if(fixup_get_ivalue(msg, &spv->row, &row)!=0)
70
+				return pv_get_null(msg, param, res);
71
+			if(fixup_get_ivalue(msg, &spv->col, &col)!=0)
72
+				return pv_get_null(msg, param, res);
73
+			if(row>=spv->res->nrows)
74
+				return pv_get_null(msg, param, res);
75
+			if(col>=spv->res->ncols)
76
+				return pv_get_null(msg, param, res);
77
+			if(spv->res->vals[row][col].flags&PV_VAL_NULL)
78
+				return pv_get_null(msg, param, res);
79
+			if(spv->res->vals[row][col].flags&PV_VAL_INT)
80
+				return pv_get_sintval(msg, param, res, 
81
+						spv->res->vals[row][col].value.n);
82
+			return pv_get_strval(msg, param, res, 
83
+						&spv->res->vals[row][col].value.s);
84
+		break;
85
+		case 4:
86
+			if(fixup_get_ivalue(msg, &spv->col, &col)!=0)
87
+				return pv_get_null(msg, param, res);
88
+			if(col>=spv->res->ncols)
89
+				return pv_get_null(msg, param, res);
90
+			return pv_get_strval(msg, param, res, 
91
+						&spv->res->cols[col].name);
92
+		break;
93
+	}
94
+	return 0;
95
+}
96
+
97
+
98
+int sql_parse_index(str *in, gparam_t *gp)
99
+{
100
+	if(in->s[0]==PV_MARKER)
101
+	{
102
+		gp->type = GPARAM_TYPE_PVS;
103
+		gp->v.pvs = (pv_spec_t*)pkg_malloc(sizeof(pv_spec_t));
104
+		if (gp->v.pvs == NULL)
105
+		{
106
+			LM_ERR("no pkg memory left for pv_spec_t\n");
107
+		    return -1;
108
+		}
109
+
110
+		if(pv_parse_spec(in, gp->v.pvs)==NULL)
111
+		{
112
+			LM_ERR("invalid PV identifier\n");
113
+		    pkg_free(gp->v.pvs);
114
+			return -1;
115
+		}
116
+	} else {
117
+		gp->type = GPARAM_TYPE_INT;
118
+		if(str2sint(in, &gp->v.i) != 0)
119
+		{
120
+			LM_ERR("bad number <%.*s>\n", in->len, in->s);
121
+			return -1;
122
+		}
123
+	}
124
+	return 0;
125
+}
126
+
127
+int pv_parse_dbr_name(pv_spec_p sp, str *in)
128
+{
129
+	sql_pv_t *spv=NULL;
130
+	char *p;
131
+	str pvs;
132
+	str tok;
133
+
134
+	spv = (sql_pv_t*)pkg_malloc(sizeof(sql_pv_t));
135
+	if(spv==NULL)
136
+		return -1;
137
+
138
+	memset(spv, 0, sizeof(sql_pv_t));
139
+
140
+	p = in->s;
141
+
142
+	while(p<in->s+in->len && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
143
+		p++;
144
+	if(p>in->s+in->len || *p=='\0')
145
+		goto error;
146
+	spv->resname.s = p;
147
+	while(p < in->s + in->len)
148
+	{
149
+		if(*p=='=' || *p==' ' || *p=='\t' || *p=='\n' || *p=='\r')
150
+			break;
151
+		p++;
152
+	}
153
+	if(p>in->s+in->len || *p=='\0')
154
+		goto error;
155
+	spv->resname.len = p - spv->resname.s;
156
+	spv->res = sql_get_result(&spv->resname);
157
+
158
+	if(*p!='=')
159
+	{
160
+		while(p<in->s+in->len && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
161
+			p++;
162
+		if(p>in->s+in->len || *p=='\0' || *p!='=')
163
+			goto error;
164
+	}
165
+	p++;
166
+	if(*p!='>')
167
+		goto error;
168
+	p++;
169
+
170
+	pvs.len = in->len - (int)(p - in->s);
171
+	pvs.s = p;
172
+	p = pvs.s+pvs.len-1;
173
+	while(p>pvs.s && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
174
+			p--;
175
+	if(p==pvs.s)
176
+	{
177
+		LM_ERR("invalid key in [%.*s]\n", in->len, in->s);
178
+		goto error;
179
+	}
180
+	pvs.len = p - pvs.s + 1;
181
+
182
+	LM_DBG("res [%.*s] - key [%.*s]\n", spv->resname.len, spv->resname.s,
183
+			pvs.len, pvs.s);
184
+	if(pvs.len==4 && strncmp(pvs.s, "rows", 4)==0)
185
+	{
186
+		spv->type = 1;
187
+	} else if(pvs.len==4 && strncmp(pvs.s, "cols", 4)==0) {
188
+		spv->type = 2;
189
+	} else if(pvs.s[0]=='[') {
190
+		spv->type = 3;
191
+		p = pvs.s+1;
192
+		while(p<in->s+in->len && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
193
+			p++;
194
+		if(p>in->s+in->len || *p=='\0')
195
+			goto error_index;
196
+		tok.s = p;
197
+		while(p < in->s + in->len)
198
+		{
199
+			if(*p==',' || *p==' ' || *p=='\t' || *p=='\n' || *p=='\r')
200
+				break;
201
+			p++;
202
+		}
203
+		if(p>in->s+in->len || *p=='\0')
204
+			goto error_index;
205
+		tok.len = p - tok.s;
206
+		if(sql_parse_index(&tok, &spv->row)!=0)
207
+			goto error_index;
208
+		while(p<in->s+in->len && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
209
+			p++;
210
+		if(p>in->s+in->len || *p=='\0' || *p!=',')
211
+			goto error_index;
212
+		p++;
213
+		while(p<in->s+in->len && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
214
+			p++;
215
+		if(p>in->s+in->len || *p=='\0')
216
+			goto error_index;
217
+		tok.s = p;
218
+		while(p < in->s + in->len)
219
+		{
220
+			if(*p==']' || *p==' ' || *p=='\t' || *p=='\n' || *p=='\r')
221
+				break;
222
+			p++;
223
+		}
224
+		if(p>in->s+in->len || *p=='\0')
225
+			goto error_index;
226
+		tok.len = p - tok.s;
227
+		if(sql_parse_index(&tok, &spv->col)!=0)
228
+			goto error_index;
229
+		while(p<in->s+in->len && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
230
+			p++;
231
+		if(p>in->s+in->len || *p=='\0' || *p!=']')
232
+			goto error_index;
233
+	} else if(pvs.len>9 && strncmp(pvs.s, "colname", 7)==0) {
234
+		spv->type = 4;
235
+		p = pvs.s+7;
236
+		while(p<in->s+in->len && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
237
+			p++;
238
+		if(p>in->s+in->len || *p=='\0' || *p!='[')
239
+			goto error_index;
240
+		p++;
241
+		tok.s = p;
242
+		while(p < in->s + in->len)
243
+		{
244
+			if(*p==']' || *p==' ' || *p=='\t' || *p=='\n' || *p=='\r')
245
+				break;
246
+			p++;
247
+		}
248
+		if(p>in->s+in->len || *p=='\0')
249
+			goto error_index;
250
+		tok.len = p - tok.s;
251
+		if(sql_parse_index(&tok, &spv->col)!=0)
252
+			goto error_index;
253
+		while(p<in->s+in->len && (*p==' ' || *p=='\t' || *p=='\n' || *p=='\r'))
254
+			p++;
255
+		if(p>in->s+in->len || *p=='\0' || *p!=']')
256
+			goto error_index;
257
+	} else {
258
+		LM_ERR("unknown key [%.*s]\n", pvs.len, pvs.s);
259
+		if(spv!=NULL)
260
+			pkg_free(spv);
261
+		return -1;
262
+	}
263
+	sp->pvp.pvn.u.dname = (void*)spv;
264
+	sp->pvp.pvn.type = PV_NAME_PVAR;
265
+
266
+	return 0;
267
+
268
+error:
269
+	LM_ERR("invalid pv name [%.*s]\n", in->len, in->s);
270
+	if(spv!=NULL)
271
+		pkg_free(spv);
272
+	return -1;
273
+
274
+error_index:
275
+	LM_ERR("invalid index in [%.*s]\n", pvs.len, pvs.s);
276
+	if(spv!=NULL)
277
+		pkg_free(spv);
278
+	return -1;
279
+}
280
+