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,321 +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
- * \file
23
- * \brief Kamailio core :: Flags
24
- * \ingroup core
25
- * Module: \ref core
26
- */
27
-
28
-
29
-#include <limits.h>
30
-#include "sr_module.h"
31
-#include "dprint.h"
32
-#include "parser/msg_parser.h"
33
-#include "flags.h"
34
-#include "error.h"
35
-#include "stdlib.h"
36
-#include "hashes.h"
37
-#include "clist.h"
38
-#include "mem/mem.h"
39
-
40
-/* Script flags */
41
-static flag_t sflags = 0;
42
-
43
-
44
-int setflag( struct sip_msg* msg, flag_t flag ) {
45
-	msg->flags |= 1 << flag;
46
-	return 1;
47
-}
48
-
49
-int resetflag( struct sip_msg* msg, flag_t flag ) {
50
-	msg->flags &= ~ (1 << flag);
51
-	return 1;
52
-}
53
-
54
-int isflagset( struct sip_msg* msg, flag_t flag ) {
55
-	return (msg->flags & (1<<flag)) ? 1 : -1;
56
-}
57
-
58
-int flag_in_range( flag_t flag ) {
59
-	if (flag > MAX_FLAG ) {
60
-		LM_ERR("message flag %d too high; MAX=%d\n", flag, MAX_FLAG );
61
-		return 0;
62
-	}
63
-	if ((int)flag<0) {
64
-		LM_ERR("message flag (%d) must be in range 0..%d\n", flag, MAX_FLAG );
65
-		return 0;
66
-	}
67
-	return 1;
68
-}
69
-
70
-
71
-int setsflagsval(flag_t val)
72
-{
73
-	sflags = val;
74
-	return 1;
75
-}
76
-
77
-
78
-int setsflag(flag_t flag)
79
-{
80
-	sflags |= 1 << flag;
81
-	return 1;
82
-}
83
-
84
-
85
-int resetsflag(flag_t flag)
86
-{
87
-	sflags &= ~ (1 << flag);
88
-	return 1;
89
-}
90
-
91
-
92
-int issflagset(flag_t flag)
93
-{
94
-	return (sflags & (1<<flag)) ? 1 : -1;
95
-}
96
-
97
-
98
-flag_t getsflags(void)
99
-{
100
-	return sflags;
101
-}
102
-
103
-
104
-/* use 2^k */
105
-#define FLAGS_NAME_HASH_ENTRIES		32
106
-
107
-struct flag_entry{
108
-	struct flag_entry* next;
109
-	struct flag_entry* prev;
110
-	str name;
111
-	int no;
112
-};
113
-
114
-
115
-struct flag_hash_head{
116
-	struct flag_entry* next;
117
-	struct flag_entry* prev;
118
-};
119
-
120
-static struct flag_hash_head  name2flags[FLAGS_NAME_HASH_ENTRIES];
121
-static unsigned char registered_flags[MAX_FLAG+1];
122
-
123
-
124
-void init_named_flags()
125
-{
126
-	int r;
127
-	
128
-	for (r=0; r<FLAGS_NAME_HASH_ENTRIES; r++)
129
-		clist_init(&name2flags[r], next, prev);
130
-}
131
-
132
-
133
-
134
-/* returns 0 on success, -1 on error */
135
-int check_flag(int n)
136
-{
137
-	if (!flag_in_range(n))
138
-		return -1;
139
-	if (registered_flags[n]){
140
-		LM_WARN("flag %d is already used by a named flag\n", n);
141
-	}
142
-	return 0;
143
-}
144
-
145
-
146
-inline static struct flag_entry* flag_search(struct flag_hash_head* lst,
147
-												char* name, int len)
148
-{
149
-	struct flag_entry* fe;
150
-	
151
-	clist_foreach(lst, fe, next){
152
-		if ((fe->name.len==len) && (memcmp(fe->name.s, name, len)==0)){
153
-			/* found */
154
-			return fe;
155
-		}
156
-	}
157
-	return 0;
158
-}
159
-
160
-
161
-
162
-/* returns flag entry or 0 on not found */
163
-inline static struct flag_entry* get_flag_entry(char* name, int len)
164
-{
165
-	int h;
166
-	/* get hash */
167
-	h=get_hash1_raw(name, len) & (FLAGS_NAME_HASH_ENTRIES-1);
168
-	return flag_search(&name2flags[h], name, len);
169
-}
170
-
171
-
172
-
173
-/* returns flag number, or -1 on error */
174
-int get_flag_no(char* name, int len)
175
-{
176
-	struct flag_entry* fe;
177
-	
178
-	fe=get_flag_entry(name, len);
179
-	return (fe)?fe->no:-1;
180
-}
181
-
182
-
183
-
184
-/* resgiter a new flag name and associates it with pos
185
- * pos== -1 => any position will do 
186
- * returns flag pos on success (>=0)
187
- *         -1  flag is an alias for an already existing flag
188
- *         -2  flag already registered
189
- *         -3  mem. alloc. failure
190
- *         -4  invalid pos
191
- *         -5 no free flags */
192
-int register_flag(char* name, int pos)
193
-{
194
-	struct flag_entry* e;
195
-	int len;
196
-	unsigned int r;
197
-	static unsigned int crt_flag=0;
198
-	unsigned int last_flag;
199
-	unsigned int h;
200
-	
201
-	len=strlen(name);
202
-	h=get_hash1_raw(name, len) & (FLAGS_NAME_HASH_ENTRIES-1);
203
-	/* check if the name already exists */
204
-	e=flag_search(&name2flags[h], name, len);
205
-	if (e){
206
-		LM_ERR("flag %.*s already registered\n", len, name);
207
-		return -2;
208
-	}
209
-	/* check if there is already another flag registered at pos */
210
-	if (pos!=-1){
211
-		if ((pos<0) || (pos>MAX_FLAG)){
212
-			LM_ERR("invalid flag %.*s position(%d)\n", len, name, pos);
213
-			return -4;
214
-		}
215
-		if (registered_flags[pos]!=0){
216
-			LM_WARN("%.*s:  flag %d already in use under another name\n",
217
-					len, name, pos);
218
-			/* continue */
219
-		}
220
-	}else{
221
-		/* alloc an empty flag */
222
-		last_flag=crt_flag+(MAX_FLAG+1);
223
-		for (; crt_flag!=last_flag; crt_flag++){
224
-			r=crt_flag%(MAX_FLAG+1);
225
-			if (registered_flags[r]==0){
226
-				pos=r;
227
-				break;
228
-			}
229
-		}
230
-		if (pos==-1){
231
-			LM_ERR("could not register %.*s - too many flags\n", len, name);
232
-			return -5;
233
-		}
234
-	}
235
-	registered_flags[pos]++;
236
-	
237
-	e=pkg_malloc(sizeof(struct flag_entry));
238
-	if (e==0){
239
-		LM_ERR("memory allocation failure\n");
240
-		return -3;
241
-	}
242
-	e->name.s=name;
243
-	e->name.len=len;
244
-	e->no=pos;
245
-	clist_insert(&name2flags[h], e, next, prev);
246
-	return pos;
247
-}
248
-
249
-
250
-
251
-#ifdef _GET_AWAY
252
-
253
-/* wrapping functions for flag processing  */
254
-static int fixup_t_flag(void** param, int param_no)
255
-{
256
-    unsigned int *code;
257
-	char *c;
258
-	int token;
259
-
260
-	LM_DBG("fixing flag: %s\n", (char *) (*param));
261
-
262
-	if (param_no!=1) {
263
-		LM_ERR("TM module: only parameter #1 for flags can be fixed\n");
264
-		return E_BUG;
265
-	};
266
-
267
-	if ( !(code =pkg_malloc( sizeof( unsigned int) )) ) return E_OUT_OF_MEM;
268
-
269
-	*code = 0;
270
-	c = *param;
271
-	while ( *c && (*c==' ' || *c=='\t')) c++; /* initial whitespaces */
272
-
273
-	token=1;
274
-	if (strcasecmp(c, "white")==0) *code=FL_WHITE;
275
-	else if (strcasecmp(c, "yellow")==0) *code=FL_YELLOW;
276
-	else if (strcasecmp(c, "green")==0) *code=FL_GREEN;
277
-	else if (strcasecmp(c, "red")==0) *code=FL_RED;
278
-	else if (strcasecmp(c, "blue")==0) *code=FL_BLUE;
279
-	else if (strcasecmp(c, "magenta")==0) *code=FL_MAGENTA;
280
-	else if (strcasecmp(c, "brown")==0) *code=FL_BROWN;
281
-	else if (strcasecmp(c, "black")==0) *code=FL_BLACK;
282
-	else if (strcasecmp(c, "acc")==0) *code=FL_ACC;
283
-	else {
284
-		token=0;
285
-		while ( *c && *c>='0' && *c<='9' ) {
286
-			*code = *code*10+ *c-'0';
287
-			if (*code > (sizeof( flag_t ) * CHAR_BIT - 1 )) {
288
-				LM_ERR("TM module: too big flag number: %s; MAX=%d\n",
289
-					(char *) (*param), sizeof( flag_t ) * CHAR_BIT - 1 );
290
-				goto error;
291
-			}
292
-			c++;
293
-		}
294
-	}
295
-	while ( *c && (*c==' ' || *c=='\t')) c++; /* terminating whitespaces */
296
-
297
-	if ( *code == 0 ) {
298
-		LM_ERR("TM module: bad flag number: %s\n", (char *) (*param));
299
-		goto error;
300
-	}
301
-
302
-	if (*code < FL_MAX && token==0) {
303
-		LM_ERR("TM module: too high flag number: %s (%d)\n; lower number"
304
-			" bellow %d reserved\n", (char *) (*param), *code, FL_MAX );
305
-		goto error;
306
-	}
307
-
308
-	/* free string */
309
-	pkg_free( *param );
310
-	/* fix now */
311
-	*param = code;
312
-	
313
-	return 0;
314
-
315
-error:
316
-	pkg_free( code );
317
-	return E_CFG;
318
-}
319
-
320
-
321
-#endif
Browse code

flags.c: logging: DBG -> LM_DBG

Ovidiu Sas authored on 13/01/2015 17:06:51
Showing 1 changed files
... ...
@@ -257,7 +257,7 @@ static int fixup_t_flag(void** param, int param_no)
257 257
 	char *c;
258 258
 	int token;
259 259
 
260
-	DBG("DEBUG: fixing flag: %s\n", (char *) (*param));
260
+	LM_DBG("fixing flag: %s\n", (char *) (*param));
261 261
 
262 262
 	if (param_no!=1) {
263 263
 		LM_ERR("TM module: only parameter #1 for flags can be fixed\n");
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,11 +1,9 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (C) 2001-2003 FhG Fokus
5 3
  *
6
- * This file is part of ser, a free SIP server.
4
+ * This file is part of Kamailio, a free SIP server.
7 5
  *
8
- * ser 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
... ...
@@ -15,7 +13,7 @@
15 13
  * software, please contact iptel.org by e-mail at the following addresses:
16 14
  *    info@iptel.org
17 15
  *
18
- * ser is distributed in the hope that it will be useful,
16
+ * Kamailio is distributed in the hope that it will be useful,
19 17
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 18
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 19
  * GNU General Public License for more details.
... ...
@@ -24,16 +22,10 @@
24 22
  * along with this program; if not, write to the Free Software 
25 23
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26 24
  */
27
-/*
28
- * History:
29
- * --------
30
- *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
31
- *  2006-02-02  named flags support (andrei)
32
- */
33 25
 
34 26
 /*!
35 27
  * \file
36
- * \brief SIP-router core :: 
28
+ * \brief Kamailio core :: Flags
37 29
  * \ingroup core
38 30
  * Module: \ref core
39 31
  */
Browse code

flags.c: logging: convert LOG to LM_*

Ovidiu Sas authored on 04/10/2014 00:20:49
Showing 1 changed files
... ...
@@ -70,13 +70,11 @@ int isflagset( struct sip_msg* msg, flag_t flag ) {
70 70
 
71 71
 int flag_in_range( flag_t flag ) {
72 72
 	if (flag > MAX_FLAG ) {
73
-		LOG(L_ERR, "ERROR: message flag %d too high; MAX=%d\n",
74
-			flag, MAX_FLAG );
73
+		LM_ERR("message flag %d too high; MAX=%d\n", flag, MAX_FLAG );
75 74
 		return 0;
76 75
 	}
77 76
 	if ((int)flag<0) {
78
-		LOG(L_ERR, "ERROR: message flag (%d) must be in range %d..%d\n",
79
-			flag, 0, MAX_FLAG );
77
+		LM_ERR("message flag (%d) must be in range 0..%d\n", flag, MAX_FLAG );
80 78
 		return 0;
81 79
 	}
82 80
 	return 1;
... ...
@@ -152,8 +150,7 @@ int check_flag(int n)
152 150
 	if (!flag_in_range(n))
153 151
 		return -1;
154 152
 	if (registered_flags[n]){
155
-		LOG(L_WARN, "WARNING: check_flag: flag %d is already used by "
156
-					" a named flag\n", n);
153
+		LM_WARN("flag %d is already used by a named flag\n", n);
157 154
 	}
158 155
 	return 0;
159 156
 }
... ...
@@ -219,20 +216,18 @@ int register_flag(char* name, int pos)
219 216
 	/* check if the name already exists */
220 217
 	e=flag_search(&name2flags[h], name, len);
221 218
 	if (e){
222
-		LOG(L_ERR, "ERROR: register_flag: flag %.*s already registered\n",
223
-					len, name);
219
+		LM_ERR("flag %.*s already registered\n", len, name);
224 220
 		return -2;
225 221
 	}
226 222
 	/* check if there is already another flag registered at pos */
227 223
 	if (pos!=-1){
228 224
 		if ((pos<0) || (pos>MAX_FLAG)){
229
-			LOG(L_ERR, "ERROR: register_flag: invalid flag %.*s "
230
-					"position(%d)\n", len, name, pos);
225
+			LM_ERR("invalid flag %.*s position(%d)\n", len, name, pos);
231 226
 			return -4;
232 227
 		}
233 228
 		if (registered_flags[pos]!=0){
234
-			LOG(L_WARN, "WARNING: register_flag:  %.*s:  flag %d already in "
235
-					"use under another name\n", len, name, pos);
229
+			LM_WARN("%.*s:  flag %d already in use under another name\n",
230
+					len, name, pos);
236 231
 			/* continue */
237 232
 		}
238 233
 	}else{
... ...
@@ -246,8 +241,7 @@ int register_flag(char* name, int pos)
246 241
 			}
247 242
 		}
248 243
 		if (pos==-1){
249
-			LOG(L_ERR, "ERROR: register_flag: could not register %.*s"
250
-					" - too many flags\n", len, name);
244
+			LM_ERR("could not register %.*s - too many flags\n", len, name);
251 245
 			return -5;
252 246
 		}
253 247
 	}
... ...
@@ -255,7 +249,7 @@ int register_flag(char* name, int pos)
255 249
 	
256 250
 	e=pkg_malloc(sizeof(struct flag_entry));
257 251
 	if (e==0){
258
-		LOG(L_ERR, "ERROR: register_flag: memory allocation failure\n");
252
+		LM_ERR("memory allocation failure\n");
259 253
 		return -3;
260 254
 	}
261 255
 	e->name.s=name;
... ...
@@ -279,8 +273,7 @@ static int fixup_t_flag(void** param, int param_no)
279 273
 	DBG("DEBUG: fixing flag: %s\n", (char *) (*param));
280 274
 
281 275
 	if (param_no!=1) {
282
-		LOG(L_ERR, "ERROR: TM module: only parameter #1 for flags can be"
283
-					" fixed\n");
276
+		LM_ERR("TM module: only parameter #1 for flags can be fixed\n");
284 277
 		return E_BUG;
285 278
 	};
286 279
 
... ...
@@ -305,7 +298,7 @@ static int fixup_t_flag(void** param, int param_no)
305 298
 		while ( *c && *c>='0' && *c<='9' ) {
306 299
 			*code = *code*10+ *c-'0';
307 300
 			if (*code > (sizeof( flag_t ) * CHAR_BIT - 1 )) {
308
-				LOG(L_ERR, "ERROR: TM module: too big flag number: %s; MAX=%d\n",
301
+				LM_ERR("TM module: too big flag number: %s; MAX=%d\n",
309 302
 					(char *) (*param), sizeof( flag_t ) * CHAR_BIT - 1 );
310 303
 				goto error;
311 304
 			}
... ...
@@ -315,12 +308,12 @@ static int fixup_t_flag(void** param, int param_no)
315 308
 	while ( *c && (*c==' ' || *c=='\t')) c++; /* terminating whitespaces */
316 309
 
317 310
 	if ( *code == 0 ) {
318
-		LOG(L_ERR, "ERROR: TM module: bad flag number: %s\n", (char *) (*param));
311
+		LM_ERR("TM module: bad flag number: %s\n", (char *) (*param));
319 312
 		goto error;
320 313
 	}
321 314
 
322 315
 	if (*code < FL_MAX && token==0) {
323
-		LOG(L_ERR, "ERROR: TM module: too high flag number: %s (%d)\n; lower number"
316
+		LM_ERR("TM module: too high flag number: %s (%d)\n; lower number"
324 317
 			" bellow %d reserved\n", (char *) (*param), *code, FL_MAX );
325 318
 		goto error;
326 319
 	}
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
... ...
@@ -22,7 +22,7 @@
22 22
  *
23 23
  * You should have received a copy of the GNU General Public License 
24 24
  * along with this program; if not, write to the Free Software 
25
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
26 26
  */
27 27
 /*
28 28
  * History:
Browse code

core: fixed several clang compiler warnings

Daniel-Constantin Mierla authored on 06/12/2013 16:16:25
Showing 1 changed files
... ...
@@ -74,7 +74,7 @@ int flag_in_range( flag_t flag ) {
74 74
 			flag, MAX_FLAG );
75 75
 		return 0;
76 76
 	}
77
-	if (flag<0) {
77
+	if ((int)flag<0) {
78 78
 		LOG(L_ERR, "ERROR: message flag (%d) must be in range %d..%d\n",
79 79
 			flag, 0, MAX_FLAG );
80 80
 		return 0;
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
... ...
@@ -31,6 +31,13 @@
31 31
  *  2006-02-02  named flags support (andrei)
32 32
  */
33 33
 
34
+/*!
35
+ * \file
36
+ * \brief SIP-router core :: 
37
+ * \ingroup core
38
+ * Module: \ref core
39
+ */
40
+
34 41
 
35 42
 #include <limits.h>
36 43
 #include "sr_module.h"
Browse code

Kamailio compatibility: script flags

This patch adds support for script flags identical to those present in
the kamailio core. Script flags is a global set of flags which preserve
their value for the duration of script processing. Script flags are kept
in a global variable in the sip-router core.

There are several functions that can be used to manipulate the value
of script flags:
* setflagsval - This function sets the value of _all_ script flags
at once. The new value of all the flags must be combined in the
single function parameter.

* setsflag - This function sets one particular script flag to 1. The
function gets the index of the flag (counting from 0) as a
parameter.

* resetsflag - This function sets one particular script flag to 0. The
function gets the index of the flag (counting from 0) as a parameter.

* issflagset - Test the value of a script flag. Returns 1 if the flag
is set and -1 otherwise.

* getsflags - Returns the value of all script flags combined into a
single variable of type flag_t. This function can be used to make a
backup copy of script flags.

Jan Janak authored on 15/03/2009 19:45:53
Showing 1 changed files
... ...
@@ -43,6 +43,10 @@
43 43
 #include "clist.h"
44 44
 #include "mem/mem.h"
45 45
 
46
+/* Script flags */
47
+static flag_t sflags = 0;
48
+
49
+
46 50
 int setflag( struct sip_msg* msg, flag_t flag ) {
47 51
 	msg->flags |= 1 << flag;
48 52
 	return 1;
... ...
@@ -72,6 +76,39 @@ int flag_in_range( flag_t flag ) {
72 76
 }
73 77
 
74 78
 
79
+int setsflagsval(flag_t val)
80
+{
81
+	sflags = val;
82
+	return 1;
83
+}
84
+
85
+
86
+int setsflag(flag_t flag)
87
+{
88
+	sflags |= 1 << flag;
89
+	return 1;
90
+}
91
+
92
+
93
+int resetsflag(flag_t flag)
94
+{
95
+	sflags &= ~ (1 << flag);
96
+	return 1;
97
+}
98
+
99
+
100
+int issflagset(flag_t flag)
101
+{
102
+	return (sflags & (1<<flag)) ? 1 : -1;
103
+}
104
+
105
+
106
+flag_t getsflags(void)
107
+{
108
+	return sflags;
109
+}
110
+
111
+
75 112
 /* use 2^k */
76 113
 #define FLAGS_NAME_HASH_ENTRIES		32
77 114
 
Browse code

- hash cleanup/cosmetics: - use the "raw" hash functions from hashes.h as base for the other hashes (e.g. tm hash). This doesn't change the hash functions, just removes some extra copies. - split old hashes.h into hashes.h (more generic stuff) and str_hash.h - new_hash() is safer now (nobody uses it, but just in case...)

Andrei Pelinescu-Onciul authored on 13/12/2006 22:50:46
Showing 1 changed files
... ...
@@ -40,6 +40,8 @@
40 40
 #include "error.h"
41 41
 #include "stdlib.h"
42 42
 #include "hashes.h"
43
+#include "clist.h"
44
+#include "mem/mem.h"
43 45
 
44 46
 int setflag( struct sip_msg* msg, flag_t flag ) {
45 47
 	msg->flags |= 1 << flag;
Browse code

- fixed flag hash bug, reported by Tomas Mandys - fixed MAX_FLAG usage (flags no = MAX_FLAG+1 and not MAX_FLAG)

Andrei Pelinescu-Onciul authored on 08/02/2006 16:44:37
Showing 1 changed files
... ...
@@ -74,10 +74,10 @@ int flag_in_range( flag_t flag ) {
74 74
 #define FLAGS_NAME_HASH_ENTRIES		32
75 75
 
76 76
 struct flag_entry{
77
-	str name;
78
-	int no;
79 77
 	struct flag_entry* next;
80 78
 	struct flag_entry* prev;
79
+	str name;
80
+	int no;
81 81
 };
82 82
 
83 83
 
... ...
@@ -87,7 +87,7 @@ struct flag_hash_head{
87 87
 };
88 88
 
89 89
 static struct flag_hash_head  name2flags[FLAGS_NAME_HASH_ENTRIES];
90
-static unsigned char registered_flags[MAX_FLAG];
90
+static unsigned char registered_flags[MAX_FLAG+1];
91 91
 
92 92
 
93 93
 void init_named_flags()
... ...
@@ -191,9 +191,9 @@ int register_flag(char* name, int pos)
191 191
 		}
192 192
 	}else{
193 193
 		/* alloc an empty flag */
194
-		last_flag=crt_flag+MAX_FLAG;
194
+		last_flag=crt_flag+(MAX_FLAG+1);
195 195
 		for (; crt_flag!=last_flag; crt_flag++){
196
-			r=crt_flag%MAX_FLAG;
196
+			r=crt_flag%(MAX_FLAG+1);
197 197
 			if (registered_flags[r]==0){
198 198
 				pos=r;
199 199
 				break;
Browse code

- modules named flag support in modparams (registrar, acc_*) E.g.:

flags foo, bar, nat;
modparam("registrar", "nat_flag", "nat")

or modparam("registrar", "nat_flag", "f:9") # uses flag 9 and "names" it f

Andrei Pelinescu-Onciul authored on 07/02/2006 19:17:38
Showing 1 changed files
... ...
@@ -173,7 +173,7 @@ int register_flag(char* name, int pos)
173 173
 	/* check if the name already exists */
174 174
 	e=flag_search(&name2flags[h], name, len);
175 175
 	if (e){
176
-		LOG(L_WARN, "WARNING: register_flag: flag %.*s already registered\n",
176
+		LOG(L_ERR, "ERROR: register_flag: flag %.*s already registered\n",
177 177
 					len, name);
178 178
 		return -2;
179 179
 	}
Browse code

- more generic hash functions - named flags support: the flags can now have names Example: flags a, b:6, test_flag; # b is set to the 6 flag, the rest are # allocated automatically route{ setflag(test_flag); ... }

Andrei Pelinescu-Onciul authored on 02/02/2006 19:29:21
Showing 1 changed files
... ...
@@ -28,6 +28,7 @@
28 28
  * History:
29 29
  * --------
30 30
  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
31
+ *  2006-02-02  named flags support (andrei)
31 32
  */
32 33
 
33 34
 
... ...
@@ -38,6 +39,7 @@
38 39
 #include "flags.h"
39 40
 #include "error.h"
40 41
 #include "stdlib.h"
42
+#include "hashes.h"
41 43
 
42 44
 int setflag( struct sip_msg* msg, flag_t flag ) {
43 45
 	msg->flags |= 1 << flag;
... ...
@@ -59,15 +61,166 @@ int flag_in_range( flag_t flag ) {
59 61
 			flag, MAX_FLAG );
60 62
 		return 0;
61 63
 	}
62
-	if (flag<=0) {
64
+	if (flag<0) {
63 65
 		LOG(L_ERR, "ERROR: message flag (%d) must be in range %d..%d\n",
64
-			flag, 1, MAX_FLAG );
66
+			flag, 0, MAX_FLAG );
65 67
 		return 0;
66 68
 	}
67 69
 	return 1;
68 70
 }
69 71
 
70 72
 
73
+/* use 2^k */
74
+#define FLAGS_NAME_HASH_ENTRIES		32
75
+
76
+struct flag_entry{
77
+	str name;
78
+	int no;
79
+	struct flag_entry* next;
80
+	struct flag_entry* prev;
81
+};
82
+
83
+
84
+struct flag_hash_head{
85
+	struct flag_entry* next;
86
+	struct flag_entry* prev;
87
+};
88
+
89
+static struct flag_hash_head  name2flags[FLAGS_NAME_HASH_ENTRIES];
90
+static unsigned char registered_flags[MAX_FLAG];
91
+
92
+
93
+void init_named_flags()
94
+{
95
+	int r;
96
+	
97
+	for (r=0; r<FLAGS_NAME_HASH_ENTRIES; r++)
98
+		clist_init(&name2flags[r], next, prev);
99
+}
100
+
101
+
102
+
103
+/* returns 0 on success, -1 on error */
104
+int check_flag(int n)
105
+{
106
+	if (!flag_in_range(n))
107
+		return -1;
108
+	if (registered_flags[n]){
109
+		LOG(L_WARN, "WARNING: check_flag: flag %d is already used by "
110
+					" a named flag\n", n);
111
+	}
112
+	return 0;
113
+}
114
+
115
+
116
+inline static struct flag_entry* flag_search(struct flag_hash_head* lst,
117
+												char* name, int len)
118
+{
119
+	struct flag_entry* fe;
120
+	
121
+	clist_foreach(lst, fe, next){
122
+		if ((fe->name.len==len) && (memcmp(fe->name.s, name, len)==0)){
123
+			/* found */
124
+			return fe;
125
+		}
126
+	}
127
+	return 0;
128
+}
129
+
130
+
131
+
132
+/* returns flag entry or 0 on not found */
133
+inline static struct flag_entry* get_flag_entry(char* name, int len)
134
+{
135
+	int h;
136
+	/* get hash */
137
+	h=get_hash1_raw(name, len) & (FLAGS_NAME_HASH_ENTRIES-1);
138
+	return flag_search(&name2flags[h], name, len);
139
+}
140
+
141
+
142
+
143
+/* returns flag number, or -1 on error */
144
+int get_flag_no(char* name, int len)
145
+{
146
+	struct flag_entry* fe;
147
+	
148
+	fe=get_flag_entry(name, len);
149
+	return (fe)?fe->no:-1;
150
+}
151
+
152
+
153
+
154
+/* resgiter a new flag name and associates it with pos
155
+ * pos== -1 => any position will do 
156
+ * returns flag pos on success (>=0)
157
+ *         -1  flag is an alias for an already existing flag
158
+ *         -2  flag already registered
159
+ *         -3  mem. alloc. failure
160
+ *         -4  invalid pos
161
+ *         -5 no free flags */
162
+int register_flag(char* name, int pos)
163
+{
164
+	struct flag_entry* e;
165
+	int len;
166
+	unsigned int r;
167
+	static unsigned int crt_flag=0;
168
+	unsigned int last_flag;
169
+	unsigned int h;
170
+	
171
+	len=strlen(name);
172
+	h=get_hash1_raw(name, len) & (FLAGS_NAME_HASH_ENTRIES-1);
173
+	/* check if the name already exists */
174
+	e=flag_search(&name2flags[h], name, len);
175
+	if (e){
176
+		LOG(L_WARN, "WARNING: register_flag: flag %.*s already registered\n",
177
+					len, name);
178
+		return -2;
179
+	}
180
+	/* check if there is already another flag registered at pos */
181
+	if (pos!=-1){
182
+		if ((pos<0) || (pos>MAX_FLAG)){
183
+			LOG(L_ERR, "ERROR: register_flag: invalid flag %.*s "
184
+					"position(%d)\n", len, name, pos);
185
+			return -4;
186
+		}
187
+		if (registered_flags[pos]!=0){
188
+			LOG(L_WARN, "WARNING: register_flag:  %.*s:  flag %d already in "
189
+					"use under another name\n", len, name, pos);
190
+			/* continue */
191
+		}
192
+	}else{
193
+		/* alloc an empty flag */
194
+		last_flag=crt_flag+MAX_FLAG;
195
+		for (; crt_flag!=last_flag; crt_flag++){
196
+			r=crt_flag%MAX_FLAG;
197
+			if (registered_flags[r]==0){
198
+				pos=r;
199
+				break;
200
+			}
201
+		}
202
+		if (pos==-1){
203
+			LOG(L_ERR, "ERROR: register_flag: could not register %.*s"
204
+					" - too many flags\n", len, name);
205
+			return -5;
206
+		}
207
+	}
208
+	registered_flags[pos]++;
209
+	
210
+	e=pkg_malloc(sizeof(struct flag_entry));
211
+	if (e==0){
212
+		LOG(L_ERR, "ERROR: register_flag: memory allocation failure\n");
213
+		return -3;
214
+	}
215
+	e->name.s=name;
216
+	e->name.len=len;
217
+	e->no=pos;
218
+	clist_insert(&name2flags[h], e, next, prev);
219
+	return pos;
220
+}
221
+
222
+
223
+
71 224
 #ifdef _GET_AWAY
72 225
 
73 226
 /* wrapping functions for flag processing  */
Browse code

- Spelling checked - READMEs updated

Jan Janak authored on 24/08/2004 08:45:09
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  * $Id$
3 3
  *
4
- * Copyright (C) 2001-2003 Fhg Fokus
4
+ * Copyright (C) 2001-2003 FhG Fokus
5 5
  *
6 6
  * This file is part of ser, a free SIP server.
7 7
  *
... ...
@@ -89,7 +89,7 @@ static int fixup_t_flag(void** param, int param_no)
89 89
 
90 90
 	*code = 0;
91 91
 	c = *param;
92
-	while ( *c && (*c==' ' || *c=='\t')) c++; /* intial whitespaces */
92
+	while ( *c && (*c==' ' || *c=='\t')) c++; /* initial whitespaces */
93 93
 
94 94
 	token=1;
95 95
 	if (strcasecmp(c, "white")==0) *code=FL_WHITE;
Browse code

- replaced all mallocs/frees w/ pkg_malloc/pkg_free - minor lock_dealloc warning fixes

Andrei Pelinescu-Onciul authored on 19/03/2003 18:41:58
Showing 1 changed files
... ...
@@ -24,6 +24,11 @@
24 24
  * along with this program; if not, write to the Free Software 
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27
+/*
28
+ * History:
29
+ * --------
30
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
31
+ */
27 32
 
28 33
 
29 34
 #include <limits.h>
... ...
@@ -75,11 +80,12 @@ static int fixup_t_flag(void** param, int param_no)
75 80
 	DBG("DEBUG: fixing flag: %s\n", (char *) (*param));
76 81
 
77 82
 	if (param_no!=1) {
78
-		LOG(L_ERR, "ERROR: TM module: only parameter #1 for flags can be fixed\n");
83
+		LOG(L_ERR, "ERROR: TM module: only parameter #1 for flags can be"
84
+					" fixed\n");
79 85
 		return E_BUG;
80 86
 	};
81 87
 
82
-	if ( !(code = malloc( sizeof( unsigned int) )) ) return E_OUT_OF_MEM;
88
+	if ( !(code =pkg_malloc( sizeof( unsigned int) )) ) return E_OUT_OF_MEM;
83 89
 
84 90
 	*code = 0;
85 91
 	c = *param;
... ...
@@ -121,14 +127,14 @@ static int fixup_t_flag(void** param, int param_no)
121 127
 	}
122 128
 
123 129
 	/* free string */
124
-	free( *param );
130
+	pkg_free( *param );
125 131
 	/* fix now */
126 132
 	*param = code;
127 133
 	
128 134
 	return 0;
129 135
 
130 136
 error:
131
-	free( code );
137
+	pkg_free( code );
132 138
 	return E_CFG;
133 139
 }
134 140
 
Browse code

GPLization banner introduced to *.[hc] files

Jiri Kuthan authored on 19/09/2002 12:23:52
Showing 1 changed files
... ...
@@ -1,7 +1,31 @@
1 1
 /*
2 2
  * $Id$
3
+ *
4
+ * Copyright (C) 2001-2003 Fhg Fokus
5
+ *
6
+ * This file is part of ser, a free SIP server.
7
+ *
8
+ * ser is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
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,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License 
24
+ * along with this program; if not, write to the Free Software 
25
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
3 26
  */
4 27
 
28
+
5 29
 #include <limits.h>