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,156 +0,0 @@
1
-/*
2
- * Copyright (C) 2001-2003 FhG Fokus
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
-
22
-/*!
23
- * \file
24
- * \brief Kamailio core :: Configuration parameters for modules (modparams)
25
- * \ingroup core
26
- * Module: \ref core
27
- */
28
-
29
-
30
-#include "modparam.h"
31
-#include "dprint.h"
32
-#include "mem/mem.h"
33
-#include <sys/types.h>
34
-#include <regex.h>
35
-#include <string.h>
36
-
37
-int set_mod_param(char* _mod, char* _name, modparam_t _type, void* _val)
38
-{
39
-	return set_mod_param_regex(_mod, _name, _type, _val);
40
-}
41
-
42
-int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
43
-{
44
-	struct sr_module* t;
45
-	regex_t preg;
46
-	int mod_found, len;
47
-	char* reg;
48
-	void *ptr, *val2;
49
-	modparam_t param_type;
50
-	str s;
51
-
52
-	if (!regex) {
53
-		LM_ERR("Invalid mod parameter value\n");
54
-		return -5;
55
-	}
56
-	if (!name) {
57
-		LM_ERR("Invalid name parameter value\n");
58
-		return -6;
59
-	}
60
-
61
-	len = strlen(regex);
62
-	reg = pkg_malloc(len + 4 + 1);
63
-	if (reg == 0) {
64
-		LM_ERR("No memory left\n");
65
-		return -1;
66
-	}
67
-	reg[0] = '^';
68
-	reg[1] = '(';
69
-	memcpy(reg + 2, regex, len);
70
-	reg[len + 2] = ')';
71
-	reg[len + 3] = '$';
72
-	reg[len + 4] = '\0';
73
-
74
-	if (regcomp(&preg, reg, REG_EXTENDED | REG_NOSUB | REG_ICASE)) {
75
-		LM_ERR("Error while compiling regular expression\n");
76
-		pkg_free(reg);
77
-		return -2;
78
-	}
79
-
80
-	mod_found = 0;
81
-	for(t = modules; t; t = t->next) {
82
-		if (regexec(&preg, t->exports.name, 0, 0, 0) == 0) {
83
-			LM_DBG("'%s' matches module '%s'\n", regex, t->exports.name);
84
-			mod_found = 1;
85
-			/* PARAM_STR (PARAM_STRING) may be assigned also to PARAM_STRING(PARAM_STR) so let get both module param */
86
-			ptr = find_param_export(t, name, type | ((type & (PARAM_STR|PARAM_STRING))?PARAM_STR|PARAM_STRING:0), &param_type);
87
-			if (ptr) {
88
-				     /* type casting */
89
-				if (type == PARAM_STRING && PARAM_TYPE_MASK(param_type) == PARAM_STR) {
90
-					s.s = (char*)val;
91
-					s.len = s.s ? strlen(s.s) : 0;
92
-					val2 = &s;
93
-				} else if (type == PARAM_STR && PARAM_TYPE_MASK(param_type) == PARAM_STRING) {
94
-					s = *(str*)val;
95
-					val2 = s.s;	/* zero terminator expected */
96
-				} else {
97
-					val2 = val;
98
-				}
99
-				LM_DBG("found <%s> in module %s [%s]\n", name, t->exports.name, t->path);
100
-				if (param_type & PARAM_USE_FUNC) {
101
-					if ( ((param_func_t)(ptr))(param_type, val2) < 0) {
102
-						regfree(&preg);
103
-						pkg_free(reg);
104
-						return -4;
105
-					}
106
-				}
107
-				else {
108
-					switch(PARAM_TYPE_MASK(param_type)) {
109
-						case PARAM_STRING:
110
-							*((char**)ptr) = pkg_malloc(strlen((char*)val2)+1);
111
-							if (!*((char**)ptr)) {
112
-								LM_ERR("No memory left\n");
113
-								regfree(&preg);
114
-								pkg_free(reg);
115
-								return -1;
116
-							}
117
-							strcpy(*((char**)ptr), (char*)val2);
118
-							break;
119
-
120
-						case PARAM_STR:
121
-							((str*)ptr)->s = pkg_malloc(((str*)val2)->len+1);
122
-							if (!((str*)ptr)->s) {
123
-								LM_ERR("No memory left\n");
124
-								regfree(&preg);
125
-								pkg_free(reg);
126
-								return -1;
127
-							}
128
-							memcpy(((str*)ptr)->s, ((str*)val2)->s, ((str*)val2)->len);
129
-							((str*)ptr)->len = ((str*)val2)->len;
130
-							((str*)ptr)->s[((str*)ptr)->len] = 0;
131
-							break;
132
-
133
-						case PARAM_INT:
134
-							*((int*)ptr) = (int)(long)val2;
135
-							break;
136
-					}
137
-				}
138
-			}
139
-			else {
140
-				LM_ERR("parameter <%s> of type <%d> not found in module <%s>\n",
141
-						name, type, t->exports.name);
142
-				regfree(&preg);
143
-				pkg_free(reg);
144
-				return -3;
145
-			}
146
-		}
147
-	}
148
-
149
-	regfree(&preg);
150
-	pkg_free(reg);
151
-	if (!mod_found) {
152
-		LM_ERR("No module matching <%s> found\n", regex);
153
-		return -4;
154
-	}
155
-	return 0;
156
-}
Browse code

core: fix regex error for modules parameters

Ambiguous was possible in params for multiple modules in one config line.

Dmitri Savolainen authored on 09/07/2016 14:05:09
Showing 1 changed files
... ...
@@ -59,15 +59,17 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
59 59
 	}
60 60
 
61 61
 	len = strlen(regex);
62
-	reg = pkg_malloc(len + 2 + 1);
62
+	reg = pkg_malloc(len + 4 + 1);
63 63
 	if (reg == 0) {
64 64
 		LM_ERR("No memory left\n");
65 65
 		return -1;
66 66
 	}
67 67
 	reg[0] = '^';
68
-	memcpy(reg + 1, regex, len);
69
-	reg[len + 1] = '$';
70
-	reg[len + 2] = '\0';
68
+	reg[1] = '(';
69
+	memcpy(reg + 2, regex, len);
70
+	reg[len + 2] = ')';
71
+	reg[len + 3] = '$';
72
+	reg[len + 4] = '\0';
71 73
 
72 74
 	if (regcomp(&preg, reg, REG_EXTENDED | REG_NOSUB | REG_ICASE)) {
73 75
 		LM_ERR("Error while compiling regular expression\n");
Browse code

modparam.c: logging: DBG -> LM_DBG

Ovidiu Sas authored on 13/01/2015 16:47:19
Showing 1 changed files
... ...
@@ -78,8 +78,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
78 78
 	mod_found = 0;
79 79
 	for(t = modules; t; t = t->next) {
80 80
 		if (regexec(&preg, t->exports.name, 0, 0, 0) == 0) {
81
-			DBG("set_mod_param_regex: '%s' matches module '%s'\n",
82
-					regex, t->exports.name);
81
+			LM_DBG("'%s' matches module '%s'\n", regex, t->exports.name);
83 82
 			mod_found = 1;
84 83
 			/* PARAM_STR (PARAM_STRING) may be assigned also to PARAM_STRING(PARAM_STR) so let get both module param */
85 84
 			ptr = find_param_export(t, name, type | ((type & (PARAM_STR|PARAM_STRING))?PARAM_STR|PARAM_STRING:0), &param_type);
... ...
@@ -95,8 +94,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
95 94
 				} else {
96 95
 					val2 = val;
97 96
 				}
98
-				DBG("set_mod_param_regex: found <%s> in module %s [%s]\n",
99
-						name, t->exports.name, t->path);
97
+				LM_DBG("found <%s> in module %s [%s]\n", name, t->exports.name, t->path);
100 98
 				if (param_type & PARAM_USE_FUNC) {
101 99
 					if ( ((param_func_t)(ptr))(param_type, val2) < 0) {
102 100
 						regfree(&preg);
Browse code

core Update headers, change "SIP-router" to "Kamailio", update doxygen file headers

Olle E. Johansson authored on 03/01/2015 14:15:58
Showing 1 changed files
... ...
@@ -8,11 +8,6 @@
8 8
  * the Free Software Foundation; either version 2 of the License, or
9 9
  * (at your option) any later version
10 10
  *
11
- * For a license to use the ser software under conditions
12
- * other than those described here, or to purchase support for this
13
- * software, please contact iptel.org by e-mail at the following addresses:
14
- *    info@iptel.org
15
- *
16 11
  * Kamailio is distributed in the hope that it will be useful,
17 12
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Browse code

Core Removed history, svn $id$ and doxygen udpates on the .c files

Olle E. Johansson authored on 03/01/2015 09:53:17
Showing 1 changed files
... ...
@@ -1,12 +1,9 @@
1 1
 /*
2
- * $Id$
3
- *
4
- *
5 2
  * Copyright (C) 2001-2003 FhG Fokus
6 3
  *
7
- * This file is part of ser, a free SIP server.
4
+ * This file is part of Kamailio, a free SIP server.
8 5
  *
9
- * ser is free software; you can redistribute it and/or modify
6
+ * Kamailio is free software; you can redistribute it and/or modify
10 7
  * it under the terms of the GNU General Public License as published by
11 8
  * the Free Software Foundation; either version 2 of the License, or
12 9
  * (at your option) any later version
... ...
@@ -16,7 +13,7 @@
16 13
  * software, please contact iptel.org by e-mail at the following addresses:
17 14
  *    info@iptel.org
18 15
  *
19
- * ser is distributed in the hope that it will be useful,
16
+ * Kamailio is distributed in the hope that it will be useful,
20 17
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 18
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 19
  * GNU General Public License for more details.
... ...
@@ -25,17 +22,11 @@
25 22
  * along with this program; if not, write to the Free Software
26 23
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
27 24
  *
28
- * History:
29
- * -------
30
- * 2003-03-20  regex support in modparam (janakj)
31
- * 2004-03-12  extra flag USE_FUNC_PARAM added to modparam type -
32
- *             instead of copying the param value, a func is called (bogdan)
33
- * 2005-07-01  PARAM_STRING & PARAM_STR support
34 25
  */
35 26
 
36 27
 /*!
37 28
  * \file
38
- * \brief SIP-router core :: 
29
+ * \brief Kamailio core :: Configuration parameters for modules (modparams)
39 30
  * \ingroup core
40 31
  * Module: \ref core
41 32
  */
Browse code

modparam.c: logging: convert LOG to LM_*

Ovidiu Sas authored on 03/10/2014 20:48:57
Showing 1 changed files
... ...
@@ -64,18 +64,18 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
64 64
 	str s;
65 65
 
66 66
 	if (!regex) {
67
-		LOG(L_ERR, "set_mod_param_regex(): Invalid mod parameter value\n");
67
+		LM_ERR("Invalid mod parameter value\n");
68 68
 		return -5;
69 69
 	}
70 70
 	if (!name) {
71
-		LOG(L_ERR, "set_mod_param_regex(): Invalid name parameter value\n");
71
+		LM_ERR("Invalid name parameter value\n");
72 72
 		return -6;
73 73
 	}
74 74
 
75 75
 	len = strlen(regex);
76 76
 	reg = pkg_malloc(len + 2 + 1);
77 77
 	if (reg == 0) {
78
-		LOG(L_ERR, "set_mod_param_regex(): No memory left\n");
78
+		LM_ERR("No memory left\n");
79 79
 		return -1;
80 80
 	}
81 81
 	reg[0] = '^';
... ...
@@ -84,7 +84,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
84 84
 	reg[len + 2] = '\0';
85 85
 
86 86
 	if (regcomp(&preg, reg, REG_EXTENDED | REG_NOSUB | REG_ICASE)) {
87
-		LOG(L_ERR, "set_mod_param_regex(): Error while compiling regular expression\n");
87
+		LM_ERR("Error while compiling regular expression\n");
88 88
 		pkg_free(reg);
89 89
 		return -2;
90 90
 	}
... ...
@@ -123,7 +123,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
123 123
 						case PARAM_STRING:
124 124
 							*((char**)ptr) = pkg_malloc(strlen((char*)val2)+1);
125 125
 							if (!*((char**)ptr)) {
126
-								LOG(L_ERR, "set_mod_param_regex(): No memory left\n");
126
+								LM_ERR("No memory left\n");
127 127
 								regfree(&preg);
128 128
 								pkg_free(reg);
129 129
 								return -1;
... ...
@@ -134,7 +134,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
134 134
 						case PARAM_STR:
135 135
 							((str*)ptr)->s = pkg_malloc(((str*)val2)->len+1);
136 136
 							if (!((str*)ptr)->s) {
137
-								LOG(L_ERR, "set_mod_param_regex(): No memory left\n");
137
+								LM_ERR("No memory left\n");
138 138
 								regfree(&preg);
139 139
 								pkg_free(reg);
140 140
 								return -1;
... ...
@@ -151,9 +151,8 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
151 151
 				}
152 152
 			}
153 153
 			else {
154
-				LOG(L_ERR, "set_mod_param_regex: parameter <%s>"
155
-							" of type <%d> not found in"
156
-							" module <%s>\n", name, type, t->exports.name);
154
+				LM_ERR("parameter <%s> of type <%d> not found in module <%s>\n",
155
+						name, type, t->exports.name);
157 156
 				regfree(&preg);
158 157
 				pkg_free(reg);
159 158
 				return -3;
... ...
@@ -164,7 +163,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
164 163
 	regfree(&preg);
165 164
 	pkg_free(reg);
166 165
 	if (!mod_found) {
167
-		LOG(L_ERR, "set_mod_param_regex: No module matching <%s> found\n", regex);
166
+		LM_ERR("No module matching <%s> found\n", regex);
168 167
 		return -4;
169 168
 	}
170 169
 	return 0;
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
... ...
@@ -23,7 +23,7 @@
23 23
  *
24 24
  * You should have received a copy of the GNU General Public License
25 25
  * along with this program; if not, write to the Free Software
26
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
27 27
  *
28 28
  * History:
29 29
  * -------
Browse code

core: free allocated memory in case of failing to get more for modparams

- keep shutdown at startup error clean

Daniel-Constantin Mierla authored on 21/04/2014 15:50:53
Showing 1 changed files
... ...
@@ -124,6 +124,8 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
124 124
 							*((char**)ptr) = pkg_malloc(strlen((char*)val2)+1);
125 125
 							if (!*((char**)ptr)) {
126 126
 								LOG(L_ERR, "set_mod_param_regex(): No memory left\n");
127
+								regfree(&preg);
128
+								pkg_free(reg);
127 129
 								return -1;
128 130
 							}
129 131
 							strcpy(*((char**)ptr), (char*)val2);
... ...
@@ -133,6 +135,8 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
133 135
 							((str*)ptr)->s = pkg_malloc(((str*)val2)->len+1);
134 136
 							if (!((str*)ptr)->s) {
135 137
 								LOG(L_ERR, "set_mod_param_regex(): No memory left\n");
138
+								regfree(&preg);
139
+								pkg_free(reg);
136 140
 								return -1;
137 141
 							}
138 142
 							memcpy(((str*)ptr)->s, ((str*)val2)->s, ((str*)val2)->len);
Browse code

core: print modparam type id in log when parameter not found

Daniel-Constantin Mierla authored on 23/10/2012 14:17:24
Showing 1 changed files
... ...
@@ -147,8 +147,9 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
147 147
 				}
148 148
 			}
149 149
 			else {
150
-				LOG(L_ERR, "set_mod_param_regex: parameter <%s> not found in"
151
-							" module <%s>\n", name, t->exports.name);
150
+				LOG(L_ERR, "set_mod_param_regex: parameter <%s>"
151
+							" of type <%d> not found in"
152
+							" module <%s>\n", name, type, t->exports.name);
152 153
 				regfree(&preg);
153 154
 				pkg_free(reg);
154 155
 				return -3;
Browse code

core:modparam.c In case of a STRING type to STR type convertion, garbage was written

The local "s" var was never written, a line was missing.

Marius Zbihlei authored on 14/01/2011 15:52:52
Showing 1 changed files
... ...
@@ -104,6 +104,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
104 104
 					s.len = s.s ? strlen(s.s) : 0;
105 105
 					val2 = &s;
106 106
 				} else if (type == PARAM_STR && PARAM_TYPE_MASK(param_type) == PARAM_STRING) {
107
+					s = *(str*)val;
107 108
 					val2 = s.s;	/* zero terminator expected */
108 109
 				} else {
109 110
 					val2 = val;
Browse code

core: internal module interface changes

Use a new internal representation for the module interface, that
combines the ser & kamailio module interfaces plus some extra
internal stuff.
This allows using extra flags (e.g. the new internal fixup_flags)
and also simplifies all the functions dealing with the module
interface or cmd_exports (since now there is a single internal
interface there's no need to check its version and access it
differently depending on it).
The ser or kamailio module interfaces are converted to the new
sr31 mod interface when the modules are loaded
(register_module()).

Andrei Pelinescu-Onciul authored on 04/08/2010 13:38:58
Showing 1 changed files
... ...
@@ -91,9 +91,9 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
91 91
 
92 92
 	mod_found = 0;
93 93
 	for(t = modules; t; t = t->next) {
94
-		if (regexec(&preg, t->exports->c.name, 0, 0, 0) == 0) {
94
+		if (regexec(&preg, t->exports.name, 0, 0, 0) == 0) {
95 95
 			DBG("set_mod_param_regex: '%s' matches module '%s'\n",
96
-					regex, t->exports->c.name);
96
+					regex, t->exports.name);
97 97
 			mod_found = 1;
98 98
 			/* PARAM_STR (PARAM_STRING) may be assigned also to PARAM_STRING(PARAM_STR) so let get both module param */
99 99
 			ptr = find_param_export(t, name, type | ((type & (PARAM_STR|PARAM_STRING))?PARAM_STR|PARAM_STRING:0), &param_type);
... ...
@@ -109,7 +109,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
109 109
 					val2 = val;
110 110
 				}
111 111
 				DBG("set_mod_param_regex: found <%s> in module %s [%s]\n",
112
-						name, t->exports->c.name, t->path);
112
+						name, t->exports.name, t->path);
113 113
 				if (param_type & PARAM_USE_FUNC) {
114 114
 					if ( ((param_func_t)(ptr))(param_type, val2) < 0) {
115 115
 						regfree(&preg);
... ...
@@ -147,7 +147,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
147 147
 			}
148 148
 			else {
149 149
 				LOG(L_ERR, "set_mod_param_regex: parameter <%s> not found in"
150
-							" module <%s>\n", name, t->exports->c.name);
150
+							" module <%s>\n", name, t->exports.name);
151 151
 				regfree(&preg);
152 152
 				pkg_free(reg);
153 153
 				return -3;
Browse code

Adding doxygen template to all core .c files

Please fill in after the :: to explain the function of this file.

oej authored on 10/10/2009 13:54:13
Showing 1 changed files
... ...
@@ -33,6 +33,13 @@
33 33
  * 2005-07-01  PARAM_STRING & PARAM_STR support
34 34
  */
35 35
 
36
+/*!
37
+ * \file
38
+ * \brief SIP-router core :: 
39
+ * \ingroup core
40
+ * Module: \ref core
41
+ */
42
+
36 43
 
37 44
 #include "modparam.h"
38 45
 #include "dprint.h"
Browse code

dual module interface support: ser and kamailio

Added support for both ser and kamailio module interfaces: a module
just needs to define its module interface prior to including sr_module.h
(e.g. by adding EXTRA_DEFS+=-DSER_MOD_INTERFACE for a ser module or
EXTRA_DEFS+=-DKAMAILIO_MOD_INTERFACE to the module Makefile).
This way ser and kamailio modules can be mixed at will with only one
Makefile change.
Under the hood, now each module declares its interface version (by
exporting a global symbol named module_interface_ver) and the internal
module loader and module export finder were updated to take the interface
version into account.
Internally the core works now with a generic module_export_u union.

Andrei Pelinescu-Onciul authored on 17/11/2008 23:48:59
Showing 1 changed files
... ...
@@ -84,8 +84,9 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
84 84
 
85 85
 	mod_found = 0;
86 86
 	for(t = modules; t; t = t->next) {
87
-		if (regexec(&preg, t->exports->name, 0, 0, 0) == 0) {
88
-			DBG("set_mod_param_regex: '%s' matches module '%s'\n", regex, t->exports->name);
87
+		if (regexec(&preg, t->exports->c.name, 0, 0, 0) == 0) {
88
+			DBG("set_mod_param_regex: '%s' matches module '%s'\n",
89
+					regex, t->exports->c.name);
89 90
 			mod_found = 1;
90 91
 			/* PARAM_STR (PARAM_STRING) may be assigned also to PARAM_STRING(PARAM_STR) so let get both module param */
91 92
 			ptr = find_param_export(t, name, type | ((type & (PARAM_STR|PARAM_STRING))?PARAM_STR|PARAM_STRING:0), &param_type);
... ...
@@ -100,7 +101,8 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
100 101
 				} else {
101 102
 					val2 = val;
102 103
 				}
103
-				DBG("set_mod_param_regex: found <%s> in module %s [%s]\n", name, t->exports->name, t->path);
104
+				DBG("set_mod_param_regex: found <%s> in module %s [%s]\n",
105
+						name, t->exports->c.name, t->path);
104 106
 				if (param_type & PARAM_USE_FUNC) {
105 107
 					if ( ((param_func_t)(ptr))(param_type, val2) < 0) {
106 108
 						regfree(&preg);
... ...
@@ -137,8 +139,8 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
137 139
 				}
138 140
 			}
139 141
 			else {
140
-				LOG(L_ERR, "set_mod_param_regex: parameter <%s> not found in module <%s>\n",
141
-				    name, t->exports->name);
142
+				LOG(L_ERR, "set_mod_param_regex: parameter <%s> not found in"
143
+							" module <%s>\n", name, t->exports->c.name);
142 144
 				regfree(&preg);
143 145
 				pkg_free(reg);
144 146
 				return -3;
Browse code

-changed strdup to pkg_malloc, valgrind disliked strlen(strdup'ed memory)

Tomas Mandys authored on 08/02/2006 21:11:51
Showing 1 changed files
... ...
@@ -100,7 +100,6 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
100 100
 				} else {
101 101
 					val2 = val;
102 102
 				}
103
-
104 103
 				DBG("set_mod_param_regex: found <%s> in module %s [%s]\n", name, t->exports->name, t->path);
105 104
 				if (param_type & PARAM_USE_FUNC) {
106 105
 					if ( ((param_func_t)(ptr))(param_type, val2) < 0) {
... ...
@@ -112,12 +111,23 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
112 111
 				else {
113 112
 					switch(PARAM_TYPE_MASK(param_type)) {
114 113
 						case PARAM_STRING:
115
-							*((char**)ptr) = strdup((char*)val2);
114
+							*((char**)ptr) = pkg_malloc(strlen((char*)val2)+1);
115
+							if (!*((char**)ptr)) {
116
+								LOG(L_ERR, "set_mod_param_regex(): No memory left\n");
117
+								return -1;
118
+							}
119
+							strcpy(*((char**)ptr), (char*)val2);
116 120
 							break;
117 121
 
118 122
 						case PARAM_STR:
119
-							((str*)ptr)->s = strdup(((str*)val2)->s);
120
-							((str*)ptr)->len = ((str*)ptr)->s?strlen(((str*)ptr)->s):0;
123
+							((str*)ptr)->s = pkg_malloc(((str*)val2)->len+1);
124
+							if (!((str*)ptr)->s) {
125
+								LOG(L_ERR, "set_mod_param_regex(): No memory left\n");
126
+								return -1;
127
+							}
128
+							memcpy(((str*)ptr)->s, ((str*)val2)->s, ((str*)val2)->len);
129
+							((str*)ptr)->len = ((str*)val2)->len;
130
+							((str*)ptr)->s[((str*)ptr)->len] = 0;
121 131
 							break;
122 132
 
123 133
 						case PARAM_INT:
Browse code

- rewritten module function parsing and call processing (mk_action, struct action, action_u_t) - API to get other fixup params from fixup - full function overloading - optional NUMBER/STRING param in config for module functions - added oveloaded functions to print_stdout (demostrates overloading)

Tomas Mandys authored on 09/01/2006 19:42:35
Showing 1 changed files
... ...
@@ -87,6 +87,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
87 87
 		if (regexec(&preg, t->exports->name, 0, 0, 0) == 0) {
88 88
 			DBG("set_mod_param_regex: '%s' matches module '%s'\n", regex, t->exports->name);
89 89
 			mod_found = 1;
90
+			/* PARAM_STR (PARAM_STRING) may be assigned also to PARAM_STRING(PARAM_STR) so let get both module param */
90 91
 			ptr = find_param_export(t, name, type | ((type & (PARAM_STR|PARAM_STRING))?PARAM_STR|PARAM_STRING:0), &param_type);
91 92
 			if (ptr) {
92 93
 				     /* type casting */
Browse code

- removed // comments, minor estetical changes

Jan Janak authored on 09/01/2006 09:56:14
Showing 1 changed files
... ...
@@ -89,17 +89,16 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
89 89
 			mod_found = 1;
90 90
 			ptr = find_param_export(t, name, type | ((type & (PARAM_STR|PARAM_STRING))?PARAM_STR|PARAM_STRING:0), &param_type);
91 91
 			if (ptr) {
92
-				// type casting
92
+				     /* type casting */
93 93
 				if (type == PARAM_STRING && PARAM_TYPE_MASK(param_type) == PARAM_STR) {
94 94
 					s.s = (char*)val;
95
-					s.len = s.s?strlen(s.s):0;
95
+					s.len = s.s ? strlen(s.s) : 0;
96 96
 					val2 = &s;
97 97
 				} else if (type == PARAM_STR && PARAM_TYPE_MASK(param_type) == PARAM_STRING) {
98
-					val2 = s.s;	// zero terminator expected
99
-				}
100
-				else
98
+					val2 = s.s;	/* zero terminator expected */
99
+				} else {
101 100
 					val2 = val;
102
-
101
+				}
103 102
 
104 103
 				DBG("set_mod_param_regex: found <%s> in module %s [%s]\n", name, t->exports->name, t->path);
105 104
 				if (param_type & PARAM_USE_FUNC) {
Browse code

fixed parameter type expression in the call to find_param_export. it fixes the use of integer parameters.

Raphael Coeffic authored on 09/01/2006 09:25:38
Showing 1 changed files
... ...
@@ -87,7 +87,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
87 87
 		if (regexec(&preg, t->exports->name, 0, 0, 0) == 0) {
88 88
 			DBG("set_mod_param_regex: '%s' matches module '%s'\n", regex, t->exports->name);
89 89
 			mod_found = 1;
90
-			ptr = find_param_export(t, name, type | (type & (PARAM_STR|PARAM_STRING))?PARAM_STR|PARAM_STRING:0, &param_type);
90
+			ptr = find_param_export(t, name, type | ((type & (PARAM_STR|PARAM_STRING))?PARAM_STR|PARAM_STRING:0), &param_type);
91 91
 			if (ptr) {
92 92
 				// type casting
93 93
 				if (type == PARAM_STRING && PARAM_TYPE_MASK(param_type) == PARAM_STR) {
Browse code

- set_mod_param uses set_mod_param_regex - set_mod_param_regex str/string type casting - rr_mod ignore_user removed, i_user as str param

Tomas Mandys authored on 08/01/2006 23:51:12
Showing 1 changed files
... ...
@@ -41,62 +41,29 @@
41 41
 #include <regex.h>
42 42
 #include <string.h>
43 43
 
44
-
45 44
 int set_mod_param(char* _mod, char* _name, modparam_t _type, void* _val)
46 45
 {
47
-	void* ptr;
48
-	modparam_t param_type;
49
-
50
-	if (!_mod) {
51
-		LOG(L_ERR, "set_mod_param(): Invalid _mod parameter value\n");
52
-		return -1;
53
-	}
54
-
55
-	if (!_name) {
56
-		LOG(L_ERR, "set_mod_param(): Invalid _name parameter value\n");
57
-		return -2;
58
-	}
59
-
60
-
61
-	ptr = find_param_export(find_module_by_name(_mod), _name, _type, &param_type);
62
-	if (!ptr) {
63
-		LOG(L_ERR, "set_mod_param(): Parameter not found\n");
64
-		return -3;
65
-	}
66
-
67
-	if (param_type & PARAM_USE_FUNC) {
68
-		if ( ((param_func_t)(ptr))(param_type, _val) < 0) {
69
-			return -4;
70
-		}
71
-	}
72
-	else {
73
-		switch(PARAM_TYPE_MASK(param_type)) {
74
-			case PARAM_STRING:
75
-				*((char**)ptr) = strdup((char*)_val);
76
-				break;
77
-
78
-			case PARAM_STR:
79
-				((str*)ptr)->s = strdup((char*)_val);
80
-				((str*)ptr)->len = strlen(((str*)ptr)->s);
81
-				break;
82
-
83
-			case PARAM_INT:
84
-				*((int*)ptr) = (int)(long)_val;
85
-				break;
86
-		}
87
-	}
88
-	return 0;
46
+	return set_mod_param_regex(_mod, _name, _type, _val);
89 47
 }
90 48
 
91
-
92 49
 int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
93 50
 {
94 51
 	struct sr_module* t;
95 52
 	regex_t preg;
96 53
 	int mod_found, len;
97 54
 	char* reg;
98
-	void *ptr;
55
+	void *ptr, *val2;
99 56
 	modparam_t param_type;
57
+	str s;
58
+
59
+	if (!regex) {
60
+		LOG(L_ERR, "set_mod_param_regex(): Invalid mod parameter value\n");
61
+		return -5;
62
+	}
63
+	if (!name) {
64
+		LOG(L_ERR, "set_mod_param_regex(): Invalid name parameter value\n");
65
+		return -6;
66
+	}
100 67
 
101 68
 	len = strlen(regex);
102 69
 	reg = pkg_malloc(len + 2 + 1);
... ...
@@ -120,11 +87,23 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
120 87
 		if (regexec(&preg, t->exports->name, 0, 0, 0) == 0) {
121 88
 			DBG("set_mod_param_regex: '%s' matches module '%s'\n", regex, t->exports->name);
122 89
 			mod_found = 1;
123
-			ptr = find_param_export(t, name, type, &param_type);
90
+			ptr = find_param_export(t, name, type | (type & (PARAM_STR|PARAM_STRING))?PARAM_STR|PARAM_STRING:0, &param_type);
124 91
 			if (ptr) {
92
+				// type casting
93
+				if (type == PARAM_STRING && PARAM_TYPE_MASK(param_type) == PARAM_STR) {
94
+					s.s = (char*)val;
95
+					s.len = s.s?strlen(s.s):0;
96
+					val2 = &s;
97
+				} else if (type == PARAM_STR && PARAM_TYPE_MASK(param_type) == PARAM_STRING) {
98
+					val2 = s.s;	// zero terminator expected
99
+				}
100
+				else
101
+					val2 = val;
102
+
103
+
125 104
 				DBG("set_mod_param_regex: found <%s> in module %s [%s]\n", name, t->exports->name, t->path);
126 105
 				if (param_type & PARAM_USE_FUNC) {
127
-					if ( ((param_func_t)(ptr))(param_type, val) < 0) {
106
+					if ( ((param_func_t)(ptr))(param_type, val2) < 0) {
128 107
 						regfree(&preg);
129 108
 						pkg_free(reg);
130 109
 						return -4;
... ...
@@ -133,16 +112,16 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
133 112
 				else {
134 113
 					switch(PARAM_TYPE_MASK(param_type)) {
135 114
 						case PARAM_STRING:
136
-							*((char**)ptr) = strdup((char*)val);
115
+							*((char**)ptr) = strdup((char*)val2);
137 116
 							break;
138 117
 
139 118
 						case PARAM_STR:
140
-							((str*)ptr)->s = strdup((char*)val);
141
-							((str*)ptr)->len = strlen(((str*)ptr)->s);
119
+							((str*)ptr)->s = strdup(((str*)val2)->s);
120
+							((str*)ptr)->len = ((str*)ptr)->s?strlen(((str*)ptr)->s):0;
142 121
 							break;
143 122
 
144 123
 						case PARAM_INT:
145
-							*((int*)ptr) = (int)(long)val;
124
+							*((int*)ptr) = (int)(long)val2;
146 125
 							break;
147 126
 					}
148 127
 				}
Browse code

- support for str param type (xxx_PARAM->PARAM_xxx, PARAM_STRING)

Tomas Mandys authored on 07/01/2006 23:24:58
Showing 1 changed files
... ...
@@ -21,8 +21,8 @@
21 21
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 22
  * GNU General Public License for more details.
23 23
  *
24
- * You should have received a copy of the GNU General Public License 
25
- * along with this program; if not, write to the Free Software 
24
+ * You should have received a copy of the GNU General Public License
25
+ * along with this program; if not, write to the Free Software
26 26
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27 27
  *
28 28
  * History:
... ...
@@ -30,6 +30,7 @@
30 30
  * 2003-03-20  regex support in modparam (janakj)
31 31
  * 2004-03-12  extra flag USE_FUNC_PARAM added to modparam type -
32 32
  *             instead of copying the param value, a func is called (bogdan)
33
+ * 2005-07-01  PARAM_STRING & PARAM_STR support
33 34
  */
34 35
 
35 36
 
... ...
@@ -44,7 +45,8 @@
44 45
 int set_mod_param(char* _mod, char* _name, modparam_t _type, void* _val)
45 46
 {
46 47
 	void* ptr;
47
-	
48
+	modparam_t param_type;
49
+
48 50
 	if (!_mod) {
49 51
 		LOG(L_ERR, "set_mod_param(): Invalid _mod parameter value\n");
50 52
 		return -1;
... ...
@@ -55,22 +57,34 @@ int set_mod_param(char* _mod, char* _name, modparam_t _type, void* _val)
55 57
 		return -2;
56 58
 	}
57 59
 
58
-	ptr = find_param_export(_mod, _name, _type);
60
+
61
+	ptr = find_param_export(find_module_by_name(_mod), _name, _type, &param_type);
59 62
 	if (!ptr) {
60 63
 		LOG(L_ERR, "set_mod_param(): Parameter not found\n");
61 64
 		return -3;
62 65
 	}
63 66
 
64
-	switch(_type) {
65
-	case STR_PARAM:
66
-		*((char**)ptr) = strdup((char*)_val);
67
-		break;
68
-
69
-	case INT_PARAM:
70
-		*((int*)ptr) = (int)(long)_val;
71
-		break;
67
+	if (param_type & PARAM_USE_FUNC) {
68
+		if ( ((param_func_t)(ptr))(param_type, _val) < 0) {
69
+			return -4;
70
+		}
71
+	}
72
+	else {
73
+		switch(PARAM_TYPE_MASK(param_type)) {
74
+			case PARAM_STRING:
75
+				*((char**)ptr) = strdup((char*)_val);
76
+				break;
77
+
78
+			case PARAM_STR:
79
+				((str*)ptr)->s = strdup((char*)_val);
80
+				((str*)ptr)->len = strlen(((str*)ptr)->s);
81
+				break;
82
+
83
+			case PARAM_INT:
84
+				*((int*)ptr) = (int)(long)_val;
85
+				break;
86
+		}
72 87
 	}
73
-
74 88
 	return 0;
75 89
 }
76 90
 
... ...
@@ -78,11 +92,11 @@ int set_mod_param(char* _mod, char* _name, modparam_t _type, void* _val)
78 92
 int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
79 93
 {
80 94
 	struct sr_module* t;
81
-	param_export_t* param;
82 95
 	regex_t preg;
83 96
 	int mod_found, len;
84 97
 	char* reg;
85
-	int n;
98
+	void *ptr;
99
+	modparam_t param_type;
86 100
 
87 101
 	len = strlen(regex);
88 102
 	reg = pkg_malloc(len + 2 + 1);
... ...
@@ -94,47 +108,46 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
94 108
 	memcpy(reg + 1, regex, len);
95 109
 	reg[len + 1] = '$';
96 110
 	reg[len + 2] = '\0';
97
-	
111
+
98 112
 	if (regcomp(&preg, reg, REG_EXTENDED | REG_NOSUB | REG_ICASE)) {
99 113
 		LOG(L_ERR, "set_mod_param_regex(): Error while compiling regular expression\n");
100 114
 		pkg_free(reg);
101 115
 		return -2;
102 116
 	}
103
-	
104
-	mod_found = 0;
105 117
 
118
+	mod_found = 0;
106 119
 	for(t = modules; t; t = t->next) {
107 120
 		if (regexec(&preg, t->exports->name, 0, 0, 0) == 0) {
108
-			DBG("set_mod_param_regex: %s matches module %s\n",
109
-					regex, t->exports->name);
121
+			DBG("set_mod_param_regex: '%s' matches module '%s'\n", regex, t->exports->name);
110 122
 			mod_found = 1;
111
-			for(param=t->exports->params;param && param->name ; param++) {
112
-				if ((strcmp(name, param->name) == 0) &&
113
-				( PARAM_TYPE_MASK(param->type) == type)) {
114
-					DBG("set_mod_param_regex: found <%s> in module %s [%s]\n",
115
-						name, t->exports->name, t->path);
116
-
117
-					if (param->type&USE_FUNC_PARAM) {
118
-						n = ((param_func_t)(param->param_pointer))(type, val );
119
-						if (n<0)
120
-							return -4;
121
-					} else {
122
-						switch(type) {
123
-							case STR_PARAM:
124
-								*((char**)(param->param_pointer)) =
125
-									strdup((char*)val);
126
-								break;
127
-							case INT_PARAM:
128
-								*((int*)(param->param_pointer)) =
129
-									(int)(long)val;
130
-								break;
131
-						}
123
+			ptr = find_param_export(t, name, type, &param_type);
124
+			if (ptr) {
125
+				DBG("set_mod_param_regex: found <%s> in module %s [%s]\n", name, t->exports->name, t->path);
126
+				if (param_type & PARAM_USE_FUNC) {
127
+					if ( ((param_func_t)(ptr))(param_type, val) < 0) {
128
+						regfree(&preg);
129
+						pkg_free(reg);
130
+						return -4;
131
+					}
132
+				}
133
+				else {
134
+					switch(PARAM_TYPE_MASK(param_type)) {
135
+						case PARAM_STRING:
136
+							*((char**)ptr) = strdup((char*)val);
137
+							break;
138
+
139
+						case PARAM_STR:
140
+							((str*)ptr)->s = strdup((char*)val);
141
+							((str*)ptr)->len = strlen(((str*)ptr)->s);
142
+							break;
143
+
144
+						case PARAM_INT:
145
+							*((int*)ptr) = (int)(long)val;
146
+							break;
132 147
 					}
133
-
134
-					break;
135 148
 				}
136 149
 			}
137
-			if (!param || !param->name) {
150
+			else {
138 151
 				LOG(L_ERR, "set_mod_param_regex: parameter <%s> not found in module <%s>\n",
139 152
 				    name, t->exports->name);
140 153
 				regfree(&preg);
... ...
@@ -145,12 +158,10 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
145 158
 	}
146 159
 
147 160
 	regfree(&preg);
161
+	pkg_free(reg);
148 162
 	if (!mod_found) {
149
-		LOG(L_ERR, "set_mod_param_regex: No module matching %s found\n|", regex);
150
-		pkg_free(reg);
163
+		LOG(L_ERR, "set_mod_param_regex: No module matching <%s> found\n", regex);
151 164
 		return -4;
152 165
 	}
153
-
154
-	pkg_free(reg);
155 166
 	return 0;
156 167
 }
Browse code

- lots of fixes (alignments, casts, warnings) - it compiles cleanly now wit sun cc and intel icc. - slight api change for param_func_t (it takes a void* now instead of a param_func_param_t)

Andrei Pelinescu-Onciul authored on 03/12/2004 19:09:31
Showing 1 changed files
... ...
@@ -115,8 +115,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
115 115
 						name, t->exports->name, t->path);
116 116
 
117 117
 					if (param->type&USE_FUNC_PARAM) {
118
-						n = ((param_func_t)(param->param_pointer))
119
-							(type, (param_func_param_t)(char*)val );
118
+						n = ((param_func_t)(param->param_pointer))(type, val );
120 119
 						if (n<0)
121 120
 							return -4;
122 121
 					} else {
Browse code

- Spelling checked - READMEs updated

Jan Janak authored on 24/08/2004 08:45:09
Showing 1 changed files
... ...
@@ -2,7 +2,7 @@
2 2
  * $Id$
3 3
  *
4 4
  *
5
- * Copyright (C) 2001-2003 Fhg Fokus
5
+ * Copyright (C) 2001-2003 FhG Fokus
6 6
  *
7 7
  * This file is part of ser, a free SIP server.
8 8
  *
Browse code

- modparam types switched to flags; USE_FUNC_PARAM flag added for param type - instead of copying the param value, a func is called to process it

Bogdan-Andrei Iancu authored on 12/03/2004 14:15:22
Showing 1 changed files
... ...
@@ -28,6 +28,8 @@
28 28
  * History:
29 29
  * -------
30 30
  * 2003-03-20  regex support in modparam (janakj)
31
+ * 2004-03-12  extra flag USE_FUNC_PARAM added to modparam type -
32
+ *             instead of copying the param value, a func is called (bogdan)
31 33
  */
32 34
 
33 35
 
... ...
@@ -80,6 +82,7 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
80 82
 	regex_t preg;
81 83
 	int mod_found, len;
82 84
 	char* reg;
85
+	int n;
83 86
 
84 87
 	len = strlen(regex);
85 88
 	reg = pkg_malloc(len + 2 + 1);
... ...
@@ -102,22 +105,31 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
102 105
 
103 106
 	for(t = modules; t; t = t->next) {
104 107
 		if (regexec(&preg, t->exports->name, 0, 0, 0) == 0) {
105
-			DBG("set_mod_param_regex: %s matches module %s\n", regex, t->exports->name);
108
+			DBG("set_mod_param_regex: %s matches module %s\n",
109
+					regex, t->exports->name);
106 110
 			mod_found = 1;
107 111
 			for(param=t->exports->params;param && param->name ; param++) {
108 112
 				if ((strcmp(name, param->name) == 0) &&
109
-				    (param->type == type)) {
113
+				( PARAM_TYPE_MASK(param->type) == type)) {
110 114
 					DBG("set_mod_param_regex: found <%s> in module %s [%s]\n",
111
-					    name, t->exports->name, t->path);
112
-
113
-					switch(type) {
114
-					case STR_PARAM:
115
-						*((char**)(param->param_pointer)) = strdup((char*)val);
116
-						break;
117
-						
118
-					case INT_PARAM:
119
-						*((int*)(param->param_pointer)) = (int)(long)val;
120
-						break;
115
+						name, t->exports->name, t->path);
116
+
117
+					if (param->type&USE_FUNC_PARAM) {
118
+						n = ((param_func_t)(param->param_pointer))
119
+							(type, (param_func_param_t)(char*)val );
120
+						if (n<0)
121
+							return -4;