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
deleted file mode 100644
... ...
@@ -1,436 +0,0 @@
1
-/*
2
- * Copyright (C) 2008 iptelorg GmbH
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
-#include <stdio.h>
22
-
23
-#include "../select.h"
24
-#include "../ut.h"
25
-#include "cfg_struct.h"
26
-#include "cfg_ctx.h"
27
-#include "cfg_select.h"
28
-
29
-/* It may happen that the select calls cannot be fixed up before shmizing
30
- * the config, because for example the mapping structures have not been
31
- * allocated for the dynamic groups yet. So we have to keep track of all the
32
- * selects that we failed to fix-up, and retry the fixup once more just
33
- * before forking */
34
-typedef struct _cfg_selects {
35
-	str	gname;
36
-	str	vname;
37
-	void	**group_p;
38
-	void	**var_p;
39
-	struct _cfg_selects	*next;
40
-} cfg_selects_t;
41
-
42
-/* linked list of non-fixed selects */
43
-static cfg_selects_t	*cfg_non_fixed_selects = NULL;
44
-
45
-/* add a new select item to the linked list */
46
-static int cfg_new_select(str *gname, str *vname, void **group_p, void **var_p)
47
-{
48
-	cfg_selects_t	*sel;
49
-
50
-	sel = (cfg_selects_t *)pkg_malloc(sizeof(cfg_selects_t));
51
-	if (!sel) goto error;
52
-	memset(sel, 0, sizeof(cfg_selects_t));
53
-
54
-	sel->gname.s = (char *)pkg_malloc(sizeof(char)*gname->len);
55
-	if (!sel->gname.s) goto error;
56
-	memcpy(sel->gname.s, gname->s, gname->len);
57
-	sel->gname.len = gname->len;
58
-	sel->group_p = group_p;
59
-
60
-	if (vname) {
61
-		sel->vname.s = (char *)pkg_malloc(sizeof(char)*vname->len);
62
-		if (!sel->vname.s) goto error;
63
-		memcpy(sel->vname.s, vname->s, vname->len);
64
-		sel->vname.len = vname->len;
65
-
66
-		sel->var_p = var_p;
67
-	}
68
-
69
-
70
-	sel->next = cfg_non_fixed_selects;
71
-	cfg_non_fixed_selects = sel;
72
-
73
-	return 0;
74
-
75
-error:
76
-	LOG(L_ERR, "ERROR: cfg_new_select(): not enough memory\n");
77
-	if (sel) {
78
-		if (sel->gname.s) pkg_free(sel->gname.s);
79
-		if (sel->vname.s) pkg_free(sel->vname.s);
80
-		pkg_free(sel);
81
-	}
82
-	return -1;
83
-}
84
-
85
-/* free the list of not yet fixed selects */
86
-void cfg_free_selects()
87
-{
88
-	cfg_selects_t	*sel, *next_sel;
89
-
90
-	sel = cfg_non_fixed_selects;
91
-	while (sel) {
92
-		next_sel = sel->next;
93
-
94
-		if (sel->gname.s) pkg_free(sel->gname.s);
95
-		if (sel->vname.s) pkg_free(sel->vname.s);
96
-		pkg_free(sel);
97
-
98
-		sel = next_sel;
99
-	}
100
-	cfg_non_fixed_selects = NULL;
101
-}
102
-
103
-/* fix-up the select calls */
104
-int cfg_fixup_selects()
105
-{
106
-	cfg_selects_t	*sel;
107
-	cfg_group_t	*group;
108
-	cfg_mapping_t	*var;
109
-
110
-	for (sel=cfg_non_fixed_selects; sel; sel=sel->next) {
111
-
112
-		if (sel->var_p) {
113
-			if (cfg_lookup_var(&sel->gname, &sel->vname, &group, &var)) {
114
-				LOG(L_ERR, "ERROR: cfg_parse_selects(): unknown variable: %.*s.%.*s\n",
115
-					sel->gname.len, sel->gname.s,
116
-					sel->vname.len, sel->vname.s);
117
-				return -1;
118
-			}
119
-			*(sel->group_p) = (void *)group;
120
-			*(sel->var_p) = (void *)var;
121
-		} else {
122
-			if (!(group = cfg_lookup_group(sel->gname.s, sel->gname.len))) {
123
-				LOG(L_ERR, "ERROR: cfg_parse_selects(): unknown configuration group: %.*s\n",
124
-					sel->gname.len, sel->gname.s);
125
-				return -1;
126
-			}
127
-			*(sel->group_p) = (void *)group;
128
-		}
129
-	}
130
-	/* the select list is not needed anymore */
131
-	cfg_free_selects();
132
-	return 0;
133
-}
134
-
135
-int select_cfg_var(str *res, select_t *s, struct sip_msg *msg)
136
-{
137
-	cfg_group_t	*group;
138
-	cfg_mapping_t	*var;
139
-	void		*p;
140
-	int		i;
141
-	static char	buf[INT2STR_MAX_LEN];
142
-
143
-	if (msg == NULL) {
144
-		/* fixup call */
145
-
146
-		/* two parameters are mandatory, group name and variable name */
147
-		if (s->n < 3) {
148
-			LOG(L_ERR, "ERROR: select_cfg_var(): At least two parameters are expected\n");
149
-			return -1;
150
-		}
151
-
152
-		if ((s->params[1].type != SEL_PARAM_STR)
153
-		|| (s->params[2].type != SEL_PARAM_STR)) {
154
-			LOG(L_ERR, "ERROR: select_cfg_var(): string parameters are expected\n");
155
-			return -1;
156
-		}
157
-
158
-		/* look-up the group and the variable */
159
-		if (cfg_lookup_var(&s->params[1].v.s, &s->params[2].v.s, &group, &var)) {
160
-			if (cfg_shmized) {
161
-				LOG(L_ERR, "ERROR: select_cfg_var(): unknown variable: %.*s.%.*s\n",
162
-					s->params[1].v.s.len, s->params[1].v.s.s,
163
-					s->params[2].v.s.len, s->params[2].v.s.s);
164
-				return -1;
165
-			}
166
-			/* The variable was not found, add it to the non-fixed select list.
167
-			 * So we act as if the fixup was successful, and we retry it later */
168
-			if (cfg_new_select(&s->params[1].v.s, &s->params[2].v.s,
169
-						&s->params[1].v.p, &s->params[2].v.p))
170
-				return -1;
171
-
172
-			LOG(L_DBG, "DEBUG: select_cfg_var(): select fixup is postponed: %.*s.%.*s\n",
173
-				s->params[1].v.s.len, s->params[1].v.s.s,
174
-				s->params[2].v.s.len, s->params[2].v.s.s);
175
-
176
-			s->params[1].type = SEL_PARAM_PTR;
177
-			s->params[1].v.p = NULL;
178
-
179
-			s->params[2].type = SEL_PARAM_PTR;
180
-			s->params[2].v.p = NULL;
181
-
182
-			return 0;
183
-		}
184
-
185
-		if (var->def->on_change_cb) {
186
-			/* fixup function is defined -- safer to return an error
187
-			than an incorrect value */
188
-			LOG(L_ERR, "ERROR: select_cfg_var(): variable cannot be retrieved\n");
189
-			return -1;
190
-		}
191
-
192
-		s->params[1].type = SEL_PARAM_PTR;
193
-		s->params[1].v.p = (void *)group;
194
-
195
-		s->params[2].type = SEL_PARAM_PTR;
196
-		s->params[2].v.p = (void *)var;
197
-		return 1;
198
-	}
199
-
200
-	group = (cfg_group_t *)s->params[1].v.p;
201
-	var = (cfg_mapping_t *)s->params[2].v.p;
202
-
203
-	if (!group || !var) return -1;
204
-
205
-	/* use the module's handle to access the variable, so the variables
206
-	are read from the local config */
207
-	p = *(group->handle) + var->offset;
208
-	if (p == NULL)
209
-		return -1;	/* The group is not yet ready.
210
-				 * (Trying to read the value from the
211
-				 * main process that has no local configuration) */
212
-
213
-	switch (CFG_VAR_TYPE(var)) {
214
-	case CFG_VAR_INT:
215
-		i = *(int *)p;
216
-		res->len = snprintf(buf, sizeof(buf)-1, "%d", i);
217
-		buf[res->len] = '\0';
218
-		res->s = buf;
219
-		break;
220
-
221
-	case CFG_VAR_STRING:
222
-		res->s = *(char **)p;
223
-		res->len = (res->s) ? strlen(res->s) : 0;
224
-		break;
225
-
226
-	case CFG_VAR_STR:
227
-		memcpy(res, p, sizeof(str));
228
-		break;
229
-
230
-	default:
231
-		LOG(L_DBG, "DEBUG: select_cfg_var(): unsupported variable type: %d\n",
232
-			CFG_VAR_TYPE(var));
233
-		return -1;
234
-	}
235
-	return 0;
236
-}
237
-
238
-/* fake function to eat the first parameter of @cfg_get */
239
-ABSTRACT_F(select_cfg_var1)
240
-
241
-/* fix-up function for read_cfg_var()
242
- *
243
- * return value:
244
- * >0 - success
245
- *  0 - the variable has not been declared yet, but it will be automatically
246
- *	fixed-up later.
247
- * <0 - error
248
- */
249
-int read_cfg_var_fixup(char *gname, char *vname, struct cfg_read_handle *read_handle)
250
-{
251
-	cfg_group_t	*group;
252
-	cfg_mapping_t	*var;
253
-	str		group_name, var_name;
254
-
255
-	if (!gname || !vname || !read_handle)
256
-		return -1;
257
-
258
-	group_name.s = gname;
259
-	group_name.len = strlen(gname);
260
-	var_name.s = vname;
261
-	var_name.len = strlen(vname);
262
-
263
-	/* look-up the group and the variable */
264
-	if (cfg_lookup_var(&group_name, &var_name, &group, &var)) {
265
-		if (cfg_shmized) {
266
-			LOG(L_ERR, "ERROR: read_cfg_var_fixup(): unknown variable: %.*s.%.*s\n",
267
-				group_name.len, group_name.s,
268
-				var_name.len, var_name.s);
269
-			return -1;
270
-		}
271
-		/* The variable was not found, add it to the non-fixed select list.
272
-		 * So we act as if the fixup was successful, and we retry it later */
273
-		if (cfg_new_select(&group_name, &var_name,
274
-					&read_handle->group, &read_handle->var))
275
-			return -1;
276
-
277
-		LOG(L_DBG, "DEBUG: read_cfg_var_fixup(): cfg read fixup is postponed: %.*s.%.*s\n",
278
-			group_name.len, group_name.s,
279
-			var_name.len, var_name.s);
280
-
281
-		read_handle->group = NULL;
282
-		read_handle->var = NULL;
283
-		return 0;
284
-	}
285
-
286
-	read_handle->group = (void *)group;
287
-	read_handle->var = (void *)var;
288
-	return 1;
289
-}
290
-
291
-/* read the value of a variable via a group and variable name previously fixed up
292
- * Returns the type of the variable
293
- */
294
-unsigned int read_cfg_var(struct cfg_read_handle *read_handle, void **val)
295
-{
296
-	cfg_group_t	*group;
297
-	cfg_mapping_t	*var;
298
-	void		*p;
299
-	static str	s;
300
-
301
-	if (!val || !read_handle || !read_handle->group || !read_handle->var)
302
-		return 0;
303
-
304
-	group = (cfg_group_t *)(read_handle->group);
305
-	var = (cfg_mapping_t *)(read_handle->var);
306
-
307
-
308
-	/* use the module's handle to access the variable, so the variables
309
-	are read from the local config */
310
-	p = *(group->handle) + var->offset;
311
-	if (p == NULL)
312
-		return 0;	/* The group is not yet ready.
313
-				 * (Trying to read the value from the
314
-				 * main process that has no local configuration) */
315
-
316
-	switch (CFG_VAR_TYPE(var)) {
317
-	case CFG_VAR_INT:
318
-		*val = (void *)(long)*(int *)p;
319
-		break;
320
-
321
-	case CFG_VAR_STRING:
322
-		*val = (void *)*(char **)p;
323
-		break;
324
-
325
-	case CFG_VAR_STR:
326
-		memcpy(&s, p, sizeof(str));
327
-		*val = (void *)&s;
328
-		break;
329
-
330
-	case CFG_VAR_POINTER:
331
-		*val = *(void **)p;
332
-		break;
333
-
334
-	}
335
-	return CFG_VAR_TYPE(var);
336
-}
337
-
338
-/* wrapper function for read_cfg_var() -- convert the value to integer
339
- * returns -1 on error, 0 on success
340
- */
341
-int read_cfg_var_int(struct cfg_read_handle *read_handle, int *val)
342
-{
343
-	unsigned int	type;
344
-	void		*v1=NULL, *v2=NULL;
345
-
346
-	if ((type = read_cfg_var(read_handle, &v1)) == 0)
347
-		return -1;
348
-
349
-	if (convert_val(type, v1, CFG_INPUT_INT, &v2))
350
-		return -1;
351
-
352
-	*val = (int)(long)(v2);
353
-	return 0;
354
-}
355
-
356
-/* wrapper function for read_cfg_var() -- convert the value to str
357
- * returns -1 on error, 0 on success
358
- */
359
-int read_cfg_var_str(struct cfg_read_handle *read_handle, str *val)
360
-{
361
-	unsigned int	type;
362
-	void		*v1=NULL, *v2=NULL;
363
-
364
-	if ((type = read_cfg_var(read_handle, &v1)) == 0)
365
-		return -1;
366
-
367
-	if (convert_val(type, v1, CFG_INPUT_STR, &v2))
368
-		return -1;
369
-
370
-	*val = *(str *)(v2);
371
-	return 0;
372
-}
373
-
374
-/* return the selected group instance */
375
-int cfg_selected_inst(str *res, select_t *s, struct sip_msg *msg)
376
-{
377
-	cfg_group_t	*group;
378
-	cfg_group_inst_t	*inst;
379
-
380
-	if (msg == NULL) {
381
-		/* fixup call */
382
-
383
-		/* one parameter is mandatory: group name */
384
-		if (s->n != 2) {
385
-			LOG(L_ERR, "ERROR: selected_inst(): One parameter is expected\n");
386
-			return -1;
387
-		}
388
-
389
-		if (s->params[1].type != SEL_PARAM_STR) {
390
-			LOG(L_ERR, "ERROR: selected_inst(): string parameter is expected\n");
391
-			return -1;
392
-		}
393
-
394
-		/* look-up the group and the variable */
395
-		if (!(group = cfg_lookup_group(s->params[1].v.s.s, s->params[1].v.s.len))) {
396
-			if (cfg_shmized) {
397
-				LOG(L_ERR, "ERROR: selected_inst(): unknown configuration group: %.*s\n",
398
-					s->params[1].v.s.len, s->params[1].v.s.s);
399
-				return -1;
400
-			}
401
-			/* The group was not found, add it to the non-fixed select list.
402
-			 * So we act as if the fixup was successful, and we retry it later */
403
-			if (cfg_new_select(&s->params[1].v.s, NULL,
404
-						&s->params[1].v.p, NULL))
405
-				return -1;
406
-
407
-			LOG(L_DBG, "DEBUG: selected_inst(): select fixup is postponed: %.*s\n",
408
-				s->params[1].v.s.len, s->params[1].v.s.s);
409
-
410
-			s->params[1].type = SEL_PARAM_PTR;
411
-			s->params[1].v.p = NULL;
412
-
413
-			return 0;
414
-		}
415
-
416
-		s->params[1].type = SEL_PARAM_PTR;
417
-		s->params[1].v.p = (void *)group;
418
-
419
-		return 1;
420
-	}
421
-
422
-	group = (cfg_group_t *)s->params[1].v.p;
423
-	if (!group) return -1;
424
-
425
-	/* Get the current group instance from the group handle. */
426
-	inst = CFG_HANDLE_TO_GINST(*(group->handle));
427
-
428
-	if (inst) {
429
-		res->s = int2str(inst->id, &res->len);
430
-	} else {
431
-		res->s = "";
432
-		res->len = 0;
433
-	}
434
-	return 0;
435
-}
436
-
Browse code

Cfg Remove SVN ID, history

Olle E. Johansson authored on 18/01/2015 19:17:38
Showing 1 changed files
... ...
@@ -1,16 +1,14 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (C) 2008 iptelorg GmbH
5 3
  *
6
- * This file is part of SIP-router, a free SIP server.
4
+ * This file is part of Kamailio, a free SIP server.
7 5
  *
8
- * SIP-router is free software; you can redistribute it and/or modify
6
+ * Kamailio is free software; you can redistribute it and/or modify
9 7
  * it under the terms of the GNU General Public License as published by
10 8
  * the Free Software Foundation; either version 2 of the License, or
11 9
  * (at your option) any later version
12 10
  *
13
- * SIP-router is distributed in the hope that it will be useful,
11
+ * Kamailio is distributed in the hope that it will be useful,
14 12
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 14
  * GNU General Public License for more details.
... ...
@@ -19,9 +17,6 @@
19 17
  * along with this program; if not, write to the Free Software
20 18
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 19
  *
22
- * History
23
- * -------
24
- *  2008-01-10	Initial version (Miklos)
25 20
  */
26 21
 #include <stdio.h>
27 22
 
Browse code

all: updated FSF address in GPL text

Anthony Messina authored on 04/07/2014 09:36:37 • Daniel-Constantin Mierla committed on 04/07/2014 09:37:36
Showing 1 changed files
... ...
@@ -17,7 +17,7 @@
17 17
  *
18 18
  * You should have received a copy of the GNU General Public License
19 19
  * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 21
  *
22 22
  * History
23 23
  * -------
Browse code

fixed compile time warnings

- init vars and remove unused ones

Daniel-Constantin Mierla authored on 16/04/2012 11:46:40
Showing 1 changed files
... ...
@@ -346,7 +346,7 @@ unsigned int read_cfg_var(struct cfg_read_handle *read_handle, void **val)
346 346
 int read_cfg_var_int(struct cfg_read_handle *read_handle, int *val)
347 347
 {
348 348
 	unsigned int	type;
349
-	void		*v1, *v2;
349
+	void		*v1=NULL, *v2=NULL;
350 350
 
351 351
 	if ((type = read_cfg_var(read_handle, &v1)) == 0)
352 352
 		return -1;
... ...
@@ -364,7 +364,7 @@ int read_cfg_var_int(struct cfg_read_handle *read_handle, int *val)
364 364
 int read_cfg_var_str(struct cfg_read_handle *read_handle, str *val)
365 365
 {
366 366
 	unsigned int	type;
367
-	void		*v1, *v2;
367
+	void		*v1=NULL, *v2=NULL;
368 368
 
369 369
 	if ((type = read_cfg_var(read_handle, &v1)) == 0)
370 370
 		return -1;
Browse code

cfg framework: @cfg_get supports nested calls

@cfg_get.<group>.<variable> makes use of the already implemented
nested select functions to parse the returned value. The following
nested calls are supported:

- @cfg.get.<group>.<variable>.nameaddr...
- @cfg.get.<group>.<variable>.uri...
- @cfg.get.<group>.<variable>.params...

Credits go to Tomas Mandys

Miklos Tirpak authored on 31/01/2011 16:36:59
Showing 1 changed files
... ...
@@ -149,8 +149,8 @@ int select_cfg_var(str *res, select_t *s, struct sip_msg *msg)
149 149
 		/* fixup call */
150 150
 
151 151
 		/* two parameters are mandatory, group name and variable name */
152
-		if (s->n != 3) {
153
-			LOG(L_ERR, "ERROR: select_cfg_var(): two parameters are expected\n");
152
+		if (s->n < 3) {
153
+			LOG(L_ERR, "ERROR: select_cfg_var(): At least two parameters are expected\n");
154 154
 			return -1;
155 155
 		}
156 156
 
... ...
@@ -240,6 +240,9 @@ int select_cfg_var(str *res, select_t *s, struct sip_msg *msg)
240 240
 	return 0;
241 241
 }
242 242
 
243
+/* fake function to eat the first parameter of @cfg_get */
244
+ABSTRACT_F(select_cfg_var1)
245
+
243 246
 /* fix-up function for read_cfg_var()
244 247
  *
245 248
  * return value:
Browse code

cfg framework: @cfg_selected.group added

@cfg_selected.<group_name> returns the selected instance id of the
specified group. If no group instance is selected, i.e. the default
is used, then empty string is returned.

Miklos Tirpak authored on 31/01/2011 11:45:57
Showing 1 changed files
... ...
@@ -60,14 +60,17 @@ static int cfg_new_select(str *gname, str *vname, void **group_p, void **var_p)
60 60
 	if (!sel->gname.s) goto error;
61 61
 	memcpy(sel->gname.s, gname->s, gname->len);
62 62
 	sel->gname.len = gname->len;
63
+	sel->group_p = group_p;
63 64
 
64
-	sel->vname.s = (char *)pkg_malloc(sizeof(char)*vname->len);
65
-	if (!sel->vname.s) goto error;
66
-	memcpy(sel->vname.s, vname->s, vname->len);
67
-	sel->vname.len = vname->len;
65
+	if (vname) {
66
+		sel->vname.s = (char *)pkg_malloc(sizeof(char)*vname->len);
67
+		if (!sel->vname.s) goto error;
68
+		memcpy(sel->vname.s, vname->s, vname->len);
69
+		sel->vname.len = vname->len;
70
+
71
+		sel->var_p = var_p;
72
+	}
68 73
 
69
-	sel->group_p = group_p;
70
-	sel->var_p = var_p;
71 74
 
72 75
 	sel->next = cfg_non_fixed_selects;
73 76
 	cfg_non_fixed_selects = sel;
... ...
@@ -111,14 +114,23 @@ int cfg_fixup_selects()
111 114
 
112 115
 	for (sel=cfg_non_fixed_selects; sel; sel=sel->next) {
113 116
 
114
-		if (cfg_lookup_var(&sel->gname, &sel->vname, &group, &var)) {
115
-			LOG(L_ERR, "ERROR: cfg_parse_selects(): unknown variable: %.*s.%.*s\n",
116
-				sel->gname.len, sel->gname.s,
117
-				sel->vname.len, sel->vname.s);
118
-			return -1;
117
+		if (sel->var_p) {
118
+			if (cfg_lookup_var(&sel->gname, &sel->vname, &group, &var)) {
119
+				LOG(L_ERR, "ERROR: cfg_parse_selects(): unknown variable: %.*s.%.*s\n",
120
+					sel->gname.len, sel->gname.s,
121
+					sel->vname.len, sel->vname.s);
122
+				return -1;
123
+			}
124
+			*(sel->group_p) = (void *)group;
125
+			*(sel->var_p) = (void *)var;
126
+		} else {
127
+			if (!(group = cfg_lookup_group(sel->gname.s, sel->gname.len))) {
128
+				LOG(L_ERR, "ERROR: cfg_parse_selects(): unknown configuration group: %.*s\n",
129
+					sel->gname.len, sel->gname.s);
130
+				return -1;
131
+			}
132
+			*(sel->group_p) = (void *)group;
119 133
 		}
120
-		*(sel->group_p) = (void *)group;
121
-		*(sel->var_p) = (void *)var;
122 134
 	}
123 135
 	/* the select list is not needed anymore */
124 136
 	cfg_free_selects();
... ...
@@ -360,3 +372,67 @@ int read_cfg_var_str(struct cfg_read_handle *read_handle, str *val)
360 372
 	*val = *(str *)(v2);
361 373
 	return 0;
362 374
 }
375
+
376
+/* return the selected group instance */
377
+int cfg_selected_inst(str *res, select_t *s, struct sip_msg *msg)
378
+{
379
+	cfg_group_t	*group;
380
+	cfg_group_inst_t	*inst;
381
+
382
+	if (msg == NULL) {
383
+		/* fixup call */
384
+
385
+		/* one parameter is mandatory: group name */
386
+		if (s->n != 2) {
387
+			LOG(L_ERR, "ERROR: selected_inst(): One parameter is expected\n");
388
+			return -1;
389
+		}
390
+
391
+		if (s->params[1].type != SEL_PARAM_STR) {
392
+			LOG(L_ERR, "ERROR: selected_inst(): string parameter is expected\n");
393
+			return -1;
394
+		}
395
+
396
+		/* look-up the group and the variable */
397
+		if (!(group = cfg_lookup_group(s->params[1].v.s.s, s->params[1].v.s.len))) {
398
+			if (cfg_shmized) {
399
+				LOG(L_ERR, "ERROR: selected_inst(): unknown configuration group: %.*s\n",
400
+					s->params[1].v.s.len, s->params[1].v.s.s);
401
+				return -1;
402
+			}
403
+			/* The group was not found, add it to the non-fixed select list.
404
+			 * So we act as if the fixup was successful, and we retry it later */
405
+			if (cfg_new_select(&s->params[1].v.s, NULL,
406
+						&s->params[1].v.p, NULL))
407
+				return -1;
408
+
409
+			LOG(L_DBG, "DEBUG: selected_inst(): select fixup is postponed: %.*s\n",
410
+				s->params[1].v.s.len, s->params[1].v.s.s);
411
+
412
+			s->params[1].type = SEL_PARAM_PTR;
413
+			s->params[1].v.p = NULL;
414
+
415
+			return 0;
416
+		}
417
+
418
+		s->params[1].type = SEL_PARAM_PTR;
419
+		s->params[1].v.p = (void *)group;
420
+
421
+		return 1;
422
+	}
423
+
424
+	group = (cfg_group_t *)s->params[1].v.p;
425
+	if (!group) return -1;
426
+
427
+	/* Get the current group instance from the group handle. */
428
+	inst = CFG_HANDLE_TO_GINST(*(group->handle));
429
+
430
+	if (inst) {
431
+		res->s = int2str(inst->id, &res->len);
432
+	} else {
433
+		res->s = "";
434
+		res->len = 0;
435
+	}
436
+	return 0;
437
+}
438
+
Browse code

Doxygen updates (not done with this directory)

oej authored on 20/10/2009 20:20:22
Showing 1 changed files
... ...
@@ -3,19 +3,14 @@
3 3
  *
4 4
  * Copyright (C) 2008 iptelorg GmbH
5 5
  *
6
- * This file is part of ser, a free SIP server.
6
+ * This file is part of SIP-router, a free SIP server.
7 7
  *
8
- * ser is free software; you can redistribute it and/or modify
8
+ * SIP-router is free software; you can redistribute it and/or modify
9 9
  * it under the terms of the GNU General Public License as published by
10 10
  * the Free Software Foundation; either version 2 of the License, or
11 11
  * (at your option) any later version
12 12
  *
13
- * For a license to use the ser software under conditions
14
- * other than those described here, or to purchase support for this
15
- * software, please contact iptel.org by e-mail at the following addresses:
16
- *    info@iptel.org
17
- *
18
- * ser is distributed in the hope that it will be useful,
13
+ * SIP-router is distributed in the hope that it will be useful,
19 14
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 16
  * GNU General Public License for more details.
Browse code

cfg framework: fix the group handles in the main process

The main process does not have a local configuration,
it has access only to the config values that were set before
forking. As a result, the group handles cannot ponint to
the shared memory address because the shared memory block
may be freed later by one of the child processes. This problem
resulted sometimes in a core dump after the processes were killed
when the main process tried to access a variable from shared mem
which was no longer available.

Miklos Tirpak authored on 13/07/2009 14:36:36
Showing 1 changed files
... ...
@@ -203,6 +203,10 @@ int select_cfg_var(str *res, select_t *s, struct sip_msg *msg)
203 203
 	/* use the module's handle to access the variable, so the variables
204 204
 	are read from the local config */
205 205
 	p = *(group->handle) + var->offset;
206
+	if (p == NULL)
207
+		return -1;	/* The group is not yet ready.
208
+				 * (Trying to read the value from the
209
+				 * main process that has no local configuration) */
206 210
 
207 211
 	switch (CFG_VAR_TYPE(var)) {
208 212
 	case CFG_VAR_INT:
... ...
@@ -295,9 +299,14 @@ unsigned int read_cfg_var(struct cfg_read_handle *read_handle, void **val)
295 299
 	group = (cfg_group_t *)(read_handle->group);
296 300
 	var = (cfg_mapping_t *)(read_handle->var);
297 301
 
302
+
298 303
 	/* use the module's handle to access the variable, so the variables
299 304
 	are read from the local config */
300 305
 	p = *(group->handle) + var->offset;
306
+	if (p == NULL)
307
+		return 0;	/* The group is not yet ready.
308
+				 * (Trying to read the value from the
309
+				 * main process that has no local configuration) */
301 310
 
302 311
 	switch (CFG_VAR_TYPE(var)) {
303 312
 	case CFG_VAR_INT:
Browse code

cfg framework: documentation for cfg_read_var*

- How to read the variables of another module, core, or
the script is documented.
- cfg_read_var() fixed -- it did not allow reading the variables
that had a fixup function.

Miklos Tirpak authored on 01/07/2009 12:23:09
Showing 1 changed files
... ...
@@ -274,13 +274,6 @@ int read_cfg_var_fixup(char *gname, char *vname, struct cfg_read_handle *read_ha
274 274
 		return 0;
275 275
 	}
276 276
 
277
-	if (var->def->on_change_cb) {
278
-		/* fixup function is defined -- safer to return an error
279
-		than an incorrect value */
280
-		LOG(L_ERR, "ERROR: read_cfg_var_fixup(): variable cannot be retrieved\n");
281
-		return -1;
282
-	}
283
-
284 277
 	read_handle->group = (void *)group;
285 278
 	read_handle->var = (void *)var;
286 279
 	return 1;
Browse code

cfg framework: read variables by name with a handle

- read_cfg_var() is introduced which allows reading
even the custom declared variables from the modules.
It requires a handle returned by read_cfg_var_fixup()
- read_cfg_var_int() and read_cfg_var_str() are wrapper functions

Miklos Tirpak authored on 30/06/2009 15:33:52
Showing 1 changed files
... ...
@@ -33,6 +33,7 @@
33 33
 #include "../select.h"
34 34
 #include "../ut.h"
35 35
 #include "cfg_struct.h"
36
+#include "cfg_ctx.h"
36 37
 #include "cfg_select.h"
37 38
 
38 39
 /* It may happen that the select calls cannot be fixed up before shmizing
... ...
@@ -200,7 +201,7 @@ int select_cfg_var(str *res, select_t *s, struct sip_msg *msg)
200 201
 	if (!group || !var) return -1;
201 202
 
202 203
 	/* use the module's handle to access the variable, so the variables
203
-	are read from private memory */
204
+	are read from the local config */
204 205
 	p = *(group->handle) + var->offset;
205 206
 
206 207
 	switch (CFG_VAR_TYPE(var)) {
... ...
@@ -220,6 +221,145 @@ int select_cfg_var(str *res, select_t *s, struct sip_msg *msg)
220 221
 		memcpy(res, p, sizeof(str));
221 222
 		break;
222 223
 
224
+	default:
225
+		LOG(L_DBG, "DEBUG: select_cfg_var(): unsupported variable type: %d\n",
226
+			CFG_VAR_TYPE(var));
227
+		return -1;
223 228
 	}
224 229
 	return 0;
225 230
 }
231
+
232
+/* fix-up function for read_cfg_var()
233
+ *
234
+ * return value:
235
+ * >0 - success
236
+ *  0 - the variable has not been declared yet, but it will be automatically
237
+ *	fixed-up later.
238
+ * <0 - error
239
+ */
240
+int read_cfg_var_fixup(char *gname, char *vname, struct cfg_read_handle *read_handle)
241
+{
242
+	cfg_group_t	*group;
243
+	cfg_mapping_t	*var;
244
+	str		group_name, var_name;
245
+
246
+	if (!gname || !vname || !read_handle)
247
+		return -1;
248
+
249
+	group_name.s = gname;
250
+	group_name.len = strlen(gname);
251
+	var_name.s = vname;
252
+	var_name.len = strlen(vname);
253
+
254
+	/* look-up the group and the variable */
255
+	if (cfg_lookup_var(&group_name, &var_name, &group, &var)) {
256
+		if (cfg_shmized) {
257
+			LOG(L_ERR, "ERROR: read_cfg_var_fixup(): unknown variable: %.*s.%.*s\n",
258
+				group_name.len, group_name.s,
259
+				var_name.len, var_name.s);
260
+			return -1;
261
+		}
262
+		/* The variable was not found, add it to the non-fixed select list.
263
+		 * So we act as if the fixup was successful, and we retry it later */
264
+		if (cfg_new_select(&group_name, &var_name,
265
+					&read_handle->group, &read_handle->var))
266
+			return -1;
267
+
268
+		LOG(L_DBG, "DEBUG: read_cfg_var_fixup(): cfg read fixup is postponed: %.*s.%.*s\n",
269
+			group_name.len, group_name.s,
270
+			var_name.len, var_name.s);
271
+
272
+		read_handle->group = NULL;
273
+		read_handle->var = NULL;
274
+		return 0;
275
+	}
276
+
277
+	if (var->def->on_change_cb) {
278
+		/* fixup function is defined -- safer to return an error
279
+		than an incorrect value */
280
+		LOG(L_ERR, "ERROR: read_cfg_var_fixup(): variable cannot be retrieved\n");
281
+		return -1;
282
+	}
283
+
284
+	read_handle->group = (void *)group;
285
+	read_handle->var = (void *)var;
286
+	return 1;
287
+}
288
+
289
+/* read the value of a variable via a group and variable name previously fixed up
290
+ * Returns the type of the variable
291
+ */
292
+unsigned int read_cfg_var(struct cfg_read_handle *read_handle, void **val)
293
+{
294
+	cfg_group_t	*group;
295
+	cfg_mapping_t	*var;
296
+	void		*p;
297
+	static str	s;
298
+
299
+	if (!val || !read_handle || !read_handle->group || !read_handle->var)
300
+		return 0;
301
+
302
+	group = (cfg_group_t *)(read_handle->group);
303
+	var = (cfg_mapping_t *)(read_handle->var);
304
+
305
+	/* use the module's handle to access the variable, so the variables
306
+	are read from the local config */
307
+	p = *(group->handle) + var->offset;
308
+
309
+	switch (CFG_VAR_TYPE(var)) {
310
+	case CFG_VAR_INT:
311
+		*val = (void *)(long)*(int *)p;
312
+		break;
313
+
314
+	case CFG_VAR_STRING:
315
+		*val = (void *)*(char **)p;
316
+		break;
317
+
318
+	case CFG_VAR_STR:
319
+		memcpy(&s, p, sizeof(str));
320
+		*val = (void *)&s;
321
+		break;
322
+
323
+	case CFG_VAR_POINTER:
324
+		*val = *(void **)p;
325
+		break;
326
+
327
+	}
328
+	return CFG_VAR_TYPE(var);
329
+}
330
+
331
+/* wrapper function for read_cfg_var() -- convert the value to integer
332
+ * returns -1 on error, 0 on success
333
+ */
334
+int read_cfg_var_int(struct cfg_read_handle *read_handle, int *val)
335
+{
336
+	unsigned int	type;
337
+	void		*v1, *v2;
338
+
339
+	if ((type = read_cfg_var(read_handle, &v1)) == 0)
340
+		return -1;
341
+
342
+	if (convert_val(type, v1, CFG_INPUT_INT, &v2))
343
+		return -1;
344
+
345
+	*val = (int)(long)(v2);
346
+	return 0;
347
+}
348
+
349
+/* wrapper function for read_cfg_var() -- convert the value to str
350
+ * returns -1 on error, 0 on success
351
+ */
352
+int read_cfg_var_str(struct cfg_read_handle *read_handle, str *val)
353
+{
354
+	unsigned int	type;
355
+	void		*v1, *v2;
356
+
357
+	if ((type = read_cfg_var(read_handle, &v1)) == 0)
358
+		return -1;
359
+
360
+	if (convert_val(type, v1, CFG_INPUT_STR, &v2))
361
+		return -1;
362
+
363
+	*val = *(str *)(v2);
364
+	return 0;
365
+}
Browse code

Select fixup is postponed until the config is shmized, if the fixup fails at parsing time. It can happen that the config group is not ready at parsing time (dynamic group), but a module tries to parse a @cfg_get select call in mod_init, or when the modparams are parsed.

Miklos Tirpak authored on 26/02/2008 17:07:35
Showing 1 changed files
... ...
@@ -35,6 +35,100 @@
35 35
 #include "cfg_struct.h"
36 36
 #include "cfg_select.h"
37 37
 
38
+/* It may happen that the select calls cannot be fixed up before shmizing
39
+ * the config, because for example the mapping structures have not been
40
+ * allocated for the dynamic groups yet. So we have to keep track of all the
41
+ * selects that we failed to fix-up, and retry the fixup once more just
42
+ * before forking */
43
+typedef struct _cfg_selects {
44
+	str	gname;
45
+	str	vname;
46
+	void	**group_p;
47
+	void	**var_p;
48
+	struct _cfg_selects	*next;
49
+} cfg_selects_t;
50
+
51
+/* linked list of non-fixed selects */
52
+static cfg_selects_t	*cfg_non_fixed_selects = NULL;
53
+
54
+/* add a new select item to the linked list */
55
+static int cfg_new_select(str *gname, str *vname, void **group_p, void **var_p)
56
+{
57
+	cfg_selects_t	*sel;
58
+
59
+	sel = (cfg_selects_t *)pkg_malloc(sizeof(cfg_selects_t));
60
+	if (!sel) goto error;
61
+	memset(sel, 0, sizeof(cfg_selects_t));
62
+
63
+	sel->gname.s = (char *)pkg_malloc(sizeof(char)*gname->len);
64
+	if (!sel->gname.s) goto error;
65
+	memcpy(sel->gname.s, gname->s, gname->len);
66
+	sel->gname.len = gname->len;