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,410 +0,0 @@
1
-/*
2
- * Copyright (c) 2004 Juha Heinanen
3
- *
4
- * This file is part of Kamailio, a free SIP server.
5
- *
6
- * Kamailio is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version
10
- *
11
- * Kamailio is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License 
17
- * along with this program; if not, write to the Free Software 
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
- */
20
-
21
-/*! \file
22
- * \brief Parser :: Parse Methods
23
- *
24
- * \ingroup parser
25
- */
26
-
27
-#include <strings.h>
28
-#include "../dprint.h"
29
-#include "../trim.h"
30
-#include "parse_methods.h"
31
-
32
-
33
-/*! \brief
34
- * Check if argument is valid RFC3261 token character.
35
- */
36
-static int token_char(char _c)
37
-{
38
- 	return 	(_c >= 65 && _c <= 90) ||        /* upper alpha */
39
- 		(_c >= 97 && _c <= 122) ||       /* lower aplha */
40
- 		(_c >= 48 && _c <= 57) ||        /* digits */
41
- 		(_c == '-') || (_c == '.') || (_c == '!') || (_c == '%') ||
42
- 		(_c == '*') || (_c == '_') || (_c == '+') || (_c == '`') ||
43
- 		(_c == '\'') || (_c == '~');
44
- }
45
-
46
-
47
-
48
-/*! \brief Parse a string containing a method.
49
- *
50
- * Parse a method pointed by s & assign its enum bit to method. The string
51
- * _must_ contain _only_ the method (without trailing or heading whitespace).
52
- * \return 0 on success, -1 on error
53
- */
54
-int parse_method_name(const str* const s, enum request_method* const method)
55
- {
56
-	if (unlikely(!s || !method)) {
57
-		LOG(L_ERR, "Invalid parameter value\n");
58
-		return -1;
59
-	}
60
-	
61
-	if (unlikely(!s->len || (s->s==0))) {
62
-		DBG("No input\n");
63
-		*method = METHOD_OTHER;
64
-		return 0;
65
-	}
66
-	
67
-	switch ((s->s)[0]) {
68
-		/* ordered after probability of aparition on a normal proxy */
69
-		case 'R':
70
-		case 'r':
71
-			if (likely((s->len == 8) &&
72
-					!strncasecmp(s->s + 1, "egister", 7))) {
73
-				*method = METHOD_REGISTER;
74
-				return 0;
75
-			}
76
-			if (likely((s->len==5) && !strncasecmp(s->s + 1, "efer", 4))) {
77
-				*method = METHOD_REFER;
78
-				return 0;
79
-			}
80
-			break;
81
-		case 'A':
82
-		case 'a':
83
-			if (likely((s->len==3) && !strncasecmp(s->s + 1, "ck", 2))) {
84
-				*method = METHOD_ACK;
85
-				return 0;
86
-			}
87
-			break;
88
-		case 'I':
89
-		case 'i':
90
-			if (likely((s->len==6) && !strncasecmp(s->s + 1, "nvite", 5))){
91
-				*method = METHOD_INVITE;
92
-				return 0;
93
-			}
94
-			if (likely((s->len==4) && !strncasecmp(s->s + 1, "nfo", 3))) {
95
-				*method = METHOD_INFO;
96
-				return 0;
97
-			}
98
-			break;
99
-		case 'P':
100
-		case 'p':
101
-			if (likely((s->len==5) && !strncasecmp(s->s + 1, "rack", 4))) {
102
-				*method = METHOD_PRACK;
103
-				return 0;
104
-			}
105
-			if (likely((s->len==7) && !strncasecmp(s->s + 1, "ublish", 6))) {
106
-				*method = METHOD_PUBLISH;
107
-				return 0;
108
-			}
109
-			break;
110
-		case 'C':
111
-		case 'c':
112
-			if (likely((s->len==6) && !strncasecmp(s->s + 1, "ancel", 5))) {
113
-				*method = METHOD_CANCEL;
114
-				return 0;
115
-			}
116
-			break;
117
-		case 'B':
118
-		case 'b':
119
-			if (likely((s->len==3) && !strncasecmp(s->s + 1, "ye", 2))) {
120
-				*method = METHOD_BYE;
121
-				return 0;
122
-			}
123
-			break;
124
-		case 'M':
125
-		case 'm':
126
-			if (likely((s->len==7) && !strncasecmp(s->s + 1, "essage", 6))) {
127
-				*method = METHOD_MESSAGE;
128
-				return 0;
129
-			}
130
-			break;
131
-		case 'O':
132
-		case 'o':
133
-			if (likely((s->len==7) && !strncasecmp(s->s + 1, "ptions", 6))) {
134
-				*method = METHOD_OPTIONS;
135
-				return 0;
136
-			}
137
-			break;
138
-		case 'S':
139
-		case 's':
140
-			if (likely((s->len==9) && !strncasecmp(s->s + 1, "ubscribe", 8))) {
141
-				*method = METHOD_SUBSCRIBE;
142
-				return 0;
143
-			}
144
-			break;
145
-		case 'N':
146
-		case 'n':
147
-			if (likely((s->len==6) && !strncasecmp(s->s + 1, "otify", 5))){
148
-				*method = METHOD_NOTIFY;
149
-				return 0;
150
-			}
151
-			break;
152
-		case 'U':
153
-		case 'u':
154
-			if (likely((s->len==6) && !strncasecmp(s->s + 1, "pdate", 5))){
155
-				*method = METHOD_UPDATE;
156
-				return 0;
157
-			}
158
-			break;
159
-		default:
160
-			break;
161
-	}
162
-	/* unknown method */
163
-	*method = METHOD_OTHER;
164
-	return 0;
165
-}
166
-
167
-
168
-
169
- /*! \brief
170
-  * Parse a method pointed by _next, assign its enum bit to _method, and update
171
-  * _next past the method. Returns 1 if parse succeeded and 0 otherwise.
172
-  */
173
-static int parse_method_advance(str* const _next, enum request_method* const _method)
174
- {
175
-	char* end;
176
-	
177
-	 if (unlikely(!_next || !_method)) {
178
-		 LOG(L_ERR, "Invalid parameter value\n");
179
-		 return 0;
180
-	 }
181
-	 
182
-	 if (unlikely(!_next->len || !_next->s)) {
183
-		 DBG("No input\n");
184
- 		*_method = METHOD_OTHER;
185
-		 return 1;
186
-	 }
187
-	end=_next->s+_next->len;
188
-	
189
-	 switch ((_next->s)[0]) {
190
-	 case 'A':
191
-	 case 'a':
192
-		 if ((_next->len > 2) && !strncasecmp(_next->s + 1, "ck", 2)) {
193
- 			*_method = METHOD_ACK;
194
- 			_next->len -= 3;
195
- 			_next->s += 3;
196
-			goto found;
197
- 		} else {
198
- 			goto unknown;
199
- 		}
200
-
201
- 	case 'B':
202
- 	case 'b':
203
- 		if ((_next->len > 2) && !strncasecmp(_next->s + 1, "ye", 2)) {
204
- 			*_method = METHOD_BYE;
205
- 			_next->len -= 3;
206
- 			_next->s += 3;
207
-			goto found;
208
- 		} else {
209
- 			goto unknown;
210
- 		}
211
-
212
- 	case 'C':
213
- 	case 'c':
214
- 		if ((_next->len > 5) && !strncasecmp(_next->s + 1, "ancel", 5)) {
215
- 			*_method = METHOD_CANCEL;
216
- 			_next->len -= 6;
217
- 			_next->s += 6;
218
-			goto found;
219
- 		} else {
220
- 			goto unknown;
221
- 		}
222
-
223
- 	case 'I':
224
- 	case 'i':
225
- 		if ((_next->len > 3) &&
226
- 		    ((*(_next->s + 1) == 'N') || (*(_next->s + 1) == 'n'))) {
227
- 			if (!strncasecmp(_next->s + 2, "fo", 2)) {
228
- 				*_method = METHOD_INFO;
229
- 				_next->len -= 4;
230
- 				_next->s += 4;
231
-				goto found;
232
- 			}
233
-
234
- 			if ((_next->len > 5) && !strncasecmp(_next->s + 2, "vite", 4)) {
235
- 				*_method = METHOD_INVITE;
236
- 				_next->len -= 6;
237
- 				_next->s += 6;
238
-				goto found;
239
- 			}
240
- 		}
241
- 		goto unknown;
242
-
243
- 	case 'M':
244
- 	case 'm':
245
- 		if ((_next->len > 6) && !strncasecmp(_next->s + 1, "essage", 6)) {
246
- 			*_method = METHOD_MESSAGE;
247
- 			_next->len -= 7;
248
- 			_next->s += 7;
249
-			goto found;
250
- 		} else {
251
- 			goto unknown;
252
- 		}
253
-
254
- 	case 'N':
255
- 	case 'n':
256
- 		if ((_next->len > 5) && !strncasecmp(_next->s + 1, "otify", 5)) {
257
- 			*_method = METHOD_NOTIFY;
258
- 			_next->len -= 6;
259
- 			_next->s += 6;
260
-			goto found;
261
- 		} else {
262
- 			goto unknown;
263
- 		}
264
-
265
- 	case 'O':
266
- 	case 'o':
267
- 		if ((_next->len > 6) && !strncasecmp(_next->s + 1, "ptions", 6)) {
268
- 			*_method = METHOD_OPTIONS;
269
- 			_next->len -= 7;
270
- 			_next->s += 7;
271
-			goto found;
272
- 		} else {
273
- 			goto unknown;
274
- 		}
275
-
276
- 	case 'P':
277
- 	case 'p':
278
- 		if ((_next->len > 4) && !strncasecmp(_next->s + 1, "rack", 4)) {
279
- 			*_method = METHOD_PRACK;
280
- 			_next->len -= 5;
281
- 			_next->s += 5;
282
-			goto found;
283
- 		}
284
- 		if ((_next->len > 6) && !strncasecmp(_next->s + 1, "ublish", 6)) {
285
- 			*_method = METHOD_PUBLISH;
286
- 			_next->len -= 7;
287
- 			_next->s += 7;
288
-			goto found;
289
- 		}
290
- 		goto unknown;
291
-
292
- 	case 'R':
293
- 	case 'r':
294
- 		if ((_next->len > 4) &&
295
- 		    ((*(_next->s + 1) == 'E') || (*(_next->s + 1) == 'e'))) {
296
- 			if (!strncasecmp(_next->s + 2, "fer", 3)) {
297
- 				*_method = METHOD_REFER;
298
- 				_next->len -= 5;
299
- 				_next->s += 5;
300
-				goto found;
301
- 			}
302
-
303
- 			if ((_next->len > 7) && !strncasecmp(_next->s + 2, "gister", 6)) {
304
- 				*_method = METHOD_REGISTER;
305
- 				_next->len -= 8;
306
- 				_next->s += 8;
307
-				goto found;
308
- 			}
309
- 		}
310
- 		goto unknown;
311
-
312
- 	case 'S':
313
- 	case 's':
314
- 		if ((_next->len > 8) && !strncasecmp(_next->s + 1, "ubscribe", 8)) {
315
- 			*_method = METHOD_SUBSCRIBE;
316
- 			_next->len -= 9;
317
- 			_next->s += 9;
318
-			goto found;
319
- 		} else {
320
- 			goto unknown;
321
- 		}
322
-
323
- 	case 'U':
324
- 	case 'u':
325
- 		if ((_next->len > 5) && !strncasecmp(_next->s + 1, "pdate", 5)) {
326
- 			*_method = METHOD_UPDATE;
327
- 			_next->len -= 6;
328
- 			_next->s += 6;
329
-			goto found;
330
- 		} else {
331
- 			goto unknown;
332
- 		}
333
-
334
- 	default:
335
- 		goto unknown;
336
- 	}
337
-
338
- unknown:
339
- 	if (token_char(*(_next->s))) {
340
- 		do { 
341
- 			_next->s++;
342
- 			_next->len--;
343
- 		} while (_next->len && token_char(*(_next->s)));
344
- 		*_method = METHOD_OTHER;
345
- 		return 1;
346
- 	} else {
347
- 		return 0;
348
- 	}
349
-found:
350
-	/* check if the method really ends here (if not return 0) */
351
-	return (_next->s>=end) || (!token_char(*(_next->s)));
352
- }
353
- 
354
- 
355
- /*! \brief
356
-  * Parse comma separated list of methods pointed by _body and assign their
357
-  * enum bits to _methods.  Returns 0 on success and -1 on failure.
358
-  */
359
-int parse_methods(const str* const _body, unsigned int* const _methods)
360
- {
361
- 	str next;
362
- 	unsigned int method;
363
-	
364
-	method=0; /* fixes silly gcc 4.x warning */
365
- 
366
-	if (!_body || !_methods) {
367
-		LOG(L_ERR, "parse_methods: Invalid parameter value\n");
368
-		return -1;
369
-	}
370
-
371
-	next.len = _body->len;
372
-	next.s = _body->s;
373
- 
374
- 	trim_leading(&next);
375
- 
376
-  	*_methods = 0;
377
- 
378
- 	if (next.len == 0) {
379
- 		return 0;
380
- 	}
381
-
382
- 	while (1) {
383
- 		if (parse_method_advance(&next, &method)) {
384
- 			*_methods |= method;
385
- 		} else {
386
- 			LOG(L_ERR, "ERROR: parse_methods: Invalid method\n");
387
- 			return -1;
388
- 		}
389
-		
390
- 		trim_leading(&next);
391
- 		if (next.len) {
392
- 			if (next.s[0] == ',') {
393
- 				next.len--;
394
- 				next.s++;
395
- 				trim_leading(&next);
396
- 				if (next.len == 0) {
397
- 					LOG(L_ERR, "ERROR: parse_methods: Method expected\n");
398
- 					return 0;
399
- 				}
400
- 			} else {
401
- 				LOG(L_ERR, "ERROR: parse_methods: Comma expected\n");
402
- 				return -1;
403
- 			}
404
- 		} else {
405
- 			break;
406
- 		}
407
- 	}
408
-
409
- 	return 0;
410
- }
Browse code

core parser - remove svn ID, remove history, change "ser" => "Kamailio"

Olle E. Johansson authored on 18/01/2015 19:36:18
Showing 1 changed files
... ...
@@ -1,14 +1,14 @@
1 1
 /*
2 2
  * Copyright (c) 2004 Juha Heinanen
3 3
  *
4
- * This file is part of ser, a free SIP server.
4
+ * This file is part of Kamailio, a free SIP server.
5 5
  *
6
- * ser is free software; you can redistribute it and/or modify
6
+ * Kamailio is free software; you can redistribute it and/or modify
7 7
  * it under the terms of the GNU General Public License as published by
8 8
  * the Free Software Foundation; either version 2 of the License, or
9 9
  * (at your option) any later version
10 10
  *
11
- * ser is distributed in the hope that it will be useful,
11
+ * Kamailio is distributed in the hope that it will be useful,
12 12
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
  * GNU General Public License for more details.
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
... ...
@@ -15,7 +15,7 @@
15 15
  *
16 16
  * You should have received a copy of the GNU General Public License 
17 17
  * along with this program; if not, write to the Free Software 
18
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 19
  */
20 20
 
21 21
 /*! \file
Browse code

core/parse_methods: removed duplicate check for same characters

- on a report generated by cppcheck sent by David Binderman

Daniel-Constantin Mierla authored on 28/01/2014 17:47:42
Showing 1 changed files
... ...
@@ -40,7 +40,7 @@ static int token_char(char _c)
40 40
  		(_c >= 48 && _c <= 57) ||        /* digits */
41 41
  		(_c == '-') || (_c == '.') || (_c == '!') || (_c == '%') ||
42 42
  		(_c == '*') || (_c == '_') || (_c == '+') || (_c == '`') ||
43
- 		(_c == '\'') || (_c == '~') || (_c == '+') || (_c == '`');
43
+ 		(_c == '\'') || (_c == '~');
44 44
  }
45 45
 
46 46
 
Browse code

parser: remove old $Id$ docs header from subversion times, not usable anymore

Henning Westerholt authored on 05/07/2012 21:39:51
Showing 1 changed files
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (c) 2004 Juha Heinanen
5 3
  *
6 4
  * This file is part of ser, a free SIP server.
Browse code

parser: make get_hdr_field(..) and necessary called functions const-correct

Henning Westerholt authored on 05/07/2012 20:35:22
Showing 1 changed files
... ...
@@ -53,7 +53,7 @@ static int token_char(char _c)
53 53
  * _must_ contain _only_ the method (without trailing or heading whitespace).
54 54
  * \return 0 on success, -1 on error
55 55
  */
56
-int parse_method_name(str* s, enum request_method* method)
56
+int parse_method_name(const str* const s, enum request_method* const method)
57 57
  {
58 58
 	if (unlikely(!s || !method)) {
59 59
 		LOG(L_ERR, "Invalid parameter value\n");
... ...
@@ -172,7 +172,7 @@ int parse_method_name(str* s, enum request_method* method)
172 172
   * Parse a method pointed by _next, assign its enum bit to _method, and update
173 173
   * _next past the method. Returns 1 if parse succeeded and 0 otherwise.
174 174
   */
175
-static int parse_method_advance(str* _next, enum request_method* _method)
175
+static int parse_method_advance(str* const _next, enum request_method* const _method)
176 176
  {
177 177
 	char* end;
178 178
 	
... ...
@@ -358,7 +358,7 @@ found:
358 358
   * Parse comma separated list of methods pointed by _body and assign their
359 359
   * enum bits to _methods.  Returns 0 on success and -1 on failure.
360 360
   */
361
- int parse_methods(str* _body, unsigned int* _methods)
361
+int parse_methods(const str* const _body, unsigned int* const _methods)
362 362
  {
363 363
  	str next;
364 364
  	unsigned int method;
Browse code

Doxygen changes

oej authored on 25/10/2009 18:30:31
Showing 1 changed files
... ...
@@ -10,11 +10,6 @@
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 13
  * ser 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
... ...
@@ -25,13 +20,19 @@
25 20
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 21
  */
27 22
 
23
+/*! \file
24
+ * \brief Parser :: Parse Methods
25
+ *
26
+ * \ingroup parser
27
+ */
28
+
28 29
 #include <strings.h>
29 30
 #include "../dprint.h"
30 31
 #include "../trim.h"
31 32
 #include "parse_methods.h"
32 33
 
33 34
 
34
-/*
35
+/*! \brief
35 36
  * Check if argument is valid RFC3261 token character.
36 37
  */
37 38
 static int token_char(char _c)
... ...
@@ -46,10 +47,11 @@ static int token_char(char _c)
46 47
 
47 48
 
48 49
 
49
-/** Parse a string containing a method.
50
+/*! \brief Parse a string containing a method.
51
+ *
50 52
  * Parse a method pointed by s & assign its enum bit to method. The string
51 53
  * _must_ contain _only_ the method (without trailing or heading whitespace).
52
- * @return 0 on success, -1 on error
54
+ * \return 0 on success, -1 on error
53 55
  */
54 56
 int parse_method_name(str* s, enum request_method* method)
55 57
  {
... ...
@@ -159,14 +161,14 @@ int parse_method_name(str* s, enum request_method* method)
159 161
 		default:
160 162
 			break;
161 163
 	}
162
-/* unknown method */
164
+	/* unknown method */
163 165
 	*method = METHOD_OTHER;
164 166
 	return 0;
165 167
 }
166 168
 
167 169
 
168 170
 
169
- /*
171
+ /*! \brief
170 172
   * Parse a method pointed by _next, assign its enum bit to _method, and update
171 173
   * _next past the method. Returns 1 if parse succeeded and 0 otherwise.
172 174
   */
... ...
@@ -352,7 +354,7 @@ found:
352 354
  }
353 355
  
354 356
  
355
- /* 
357
+ /*! \brief
356 358
   * Parse comma separated list of methods pointed by _body and assign their
357 359
   * enum bits to _methods.  Returns 0 on success and -1 on failure.
358 360
   */
Browse code

core: parse_cseq wrong use of parse_method fix

- parse_method renamed to parse_method_advance(), made static and
changed to check if the method name ends with a non-token char.
- added parse_method_name() for parsing a single method name with
known length (no leading or trailing whitespace).
- changed parse_cseq() to use parse_method_name()
(it's previous use of parse_method() had the side effect of
setting the method name to "").

Reported-by: Henning Westerholt <henning.westerholt@1und1.de>

Andrei Pelinescu-Onciul authored on 20/05/2009 17:06:43
Showing 1 changed files
... ...
@@ -43,24 +43,149 @@ static int token_char(char _c)
43 43
  		(_c == '*') || (_c == '_') || (_c == '+') || (_c == '`') ||
44 44
  		(_c == '\'') || (_c == '~') || (_c == '+') || (_c == '`');
45 45
  }
46
- 
47
- 
46
+
47
+
48
+
49
+/** Parse a string containing a method.
50
+ * Parse a method pointed by s & assign its enum bit to method. The string
51
+ * _must_ contain _only_ the method (without trailing or heading whitespace).
52
+ * @return 0 on success, -1 on error
53
+ */
54
+int parse_method_name(str* s, enum request_method* method)
55
+ {
56
+	if (unlikely(!s || !method)) {
57
+		LOG(L_ERR, "Invalid parameter value\n");
58
+		return -1;
59
+	}
60
+	
61
+	if (unlikely(!s->len || (s->s==0))) {
62
+		DBG("No input\n");
63
+		*method = METHOD_OTHER;
64
+		return 0;
65
+	}
66
+	
67
+	switch ((s->s)[0]) {
68
+		/* ordered after probability of aparition on a normal proxy */
69
+		case 'R':
70
+		case 'r':
71
+			if (likely((s->len == 8) &&
72
+					!strncasecmp(s->s + 1, "egister", 7))) {
73
+				*method = METHOD_REGISTER;
74
+				return 0;
75
+			}
76
+			if (likely((s->len==5) && !strncasecmp(s->s + 1, "efer", 4))) {
77
+				*method = METHOD_REFER;
78
+				return 0;
79
+			}
80
+			break;
81
+		case 'A':
82
+		case 'a':
83
+			if (likely((s->len==3) && !strncasecmp(s->s + 1, "ck", 2))) {
84
+				*method = METHOD_ACK;
85
+				return 0;
86
+			}
87
+			break;
88
+		case 'I':
89
+		case 'i':
90
+			if (likely((s->len==6) && !strncasecmp(s->s + 1, "nvite", 5))){
91
+				*method = METHOD_INVITE;
92
+				return 0;
93
+			}
94
+			if (likely((s->len==4) && !strncasecmp(s->s + 1, "nfo", 3))) {
95
+				*method = METHOD_INFO;
96
+				return 0;
97
+			}
98
+			break;
99
+		case 'P':
100
+		case 'p':
101
+			if (likely((s->len==5) && !strncasecmp(s->s + 1, "rack", 4))) {
102
+				*method = METHOD_PRACK;
103
+				return 0;
104
+			}
105
+			if (likely((s->len==7) && !strncasecmp(s->s + 1, "ublish", 6))) {
106
+				*method = METHOD_PUBLISH;
107
+				return 0;
108
+			}
109
+			break;
110
+		case 'C':
111
+		case 'c':
112
+			if (likely((s->len==6) && !strncasecmp(s->s + 1, "ancel", 5))) {
113
+				*method = METHOD_CANCEL;
114
+				return 0;
115
+			}
116
+			break;
117
+		case 'B':
118
+		case 'b':
119
+			if (likely((s->len==3) && !strncasecmp(s->s + 1, "ye", 2))) {
120
+				*method = METHOD_BYE;
121
+				return 0;
122
+			}
123
+			break;
124
+		case 'M':
125
+		case 'm':
126
+			if (likely((s->len==7) && !strncasecmp(s->s + 1, "essage", 6))) {
127
+				*method = METHOD_MESSAGE;
128
+				return 0;
129
+			}
130
+			break;
131
+		case 'O':
132
+		case 'o':
133
+			if (likely((s->len==7) && !strncasecmp(s->s + 1, "ptions", 6))) {
134
+				*method = METHOD_OPTIONS;
135
+				return 0;
136
+			}
137
+			break;
138
+		case 'S':
139
+		case 's':
140
+			if (likely((s->len==9) && !strncasecmp(s->s + 1, "ubscribe", 8))) {
141
+				*method = METHOD_SUBSCRIBE;
142
+				return 0;
143
+			}
144
+			break;
145
+		case 'N':
146
+		case 'n':
147
+			if (likely((s->len==6) && !strncasecmp(s->s + 1, "otify", 5))){
148
+				*method = METHOD_NOTIFY;
149
+				return 0;
150
+			}
151
+			break;
152
+		case 'U':
153
+		case 'u':
154
+			if (likely((s->len==6) && !strncasecmp(s->s + 1, "pdate", 5))){
155
+				*method = METHOD_UPDATE;
156
+				return 0;
157
+			}
158
+			break;
159
+		default:
160
+			break;
161
+	}
162
+/* unknown method */
163
+	*method = METHOD_OTHER;
164
+	return 0;
165
+}
166
+
167
+
168
+
48 169
  /*
49 170
   * Parse a method pointed by _next, assign its enum bit to _method, and update
50 171
   * _next past the method. Returns 1 if parse succeeded and 0 otherwise.
51 172
   */
52
-int parse_method(str* _next, enum request_method* _method) 
173
+static int parse_method_advance(str* _next, enum request_method* _method)
53 174
  {
54
-	 if (!_next || !_method) {
55
-		 LOG(L_ERR, "parse_method: Invalid parameter value\n");
175
+	char* end;
176
+	
177
+	 if (unlikely(!_next || !_method)) {
178
+		 LOG(L_ERR, "Invalid parameter value\n");
56 179
 		 return 0;
57 180
 	 }
58 181
 	 
59
-	 if (!_next->len || !_next->s) {
60
-		 DBG("parse_method: No input\n");
182
+	 if (unlikely(!_next->len || !_next->s)) {
183
+		 DBG("No input\n");
184
+ 		*_method = METHOD_OTHER;
61 185
 		 return 1;
62 186
 	 }
63
-
187
+	end=_next->s+_next->len;
188
+	
64 189
 	 switch ((_next->s)[0]) {
65 190
 	 case 'A':
66 191
 	 case 'a':
... ...
@@ -68,7 +193,7 @@ int parse_method(str* _next, enum request_method* _method)
68 193
  			*_method = METHOD_ACK;
69 194
  			_next->len -= 3;
70 195
  			_next->s += 3;
71
- 			return 1;
196
+			goto found;
72 197
  		} else {
73 198
  			goto unknown;
74 199
  		}
... ...
@@ -79,7 +204,7 @@ int parse_method(str* _next, enum request_method* _method)
79 204
  			*_method = METHOD_BYE;
80 205
  			_next->len -= 3;
81 206
  			_next->s += 3;
82
- 			return 1;
207
+			goto found;
83 208
  		} else {
84 209
  			goto unknown;
85 210
  		}
... ...
@@ -90,7 +215,7 @@ int parse_method(str* _next, enum request_method* _method)
90 215
  			*_method = METHOD_CANCEL;
91 216
  			_next->len -= 6;
92 217
  			_next->s += 6;
93
- 			return 1;
218
+			goto found;
94 219
  		} else {
95 220
  			goto unknown;
96 221
  		}
... ...
@@ -103,14 +228,14 @@ int parse_method(str* _next, enum request_method* _method)
103 228
  				*_method = METHOD_INFO;
104 229
  				_next->len -= 4;
105 230
  				_next->s += 4;
106
- 				return 1;
231
+				goto found;
107 232
  			}
108 233
 
109 234
  			if ((_next->len > 5) && !strncasecmp(_next->s + 2, "vite", 4)) {
110 235
  				*_method = METHOD_INVITE;
111 236
  				_next->len -= 6;
112 237
  				_next->s += 6;
113
- 				return 1;
238
+				goto found;
114 239
  			}
115 240
  		}
116 241
  		goto unknown;
... ...
@@ -121,7 +246,7 @@ int parse_method(str* _next, enum request_method* _method)
121 246
  			*_method = METHOD_MESSAGE;
122 247
  			_next->len -= 7;
123 248
  			_next->s += 7;
124
- 			return 1;
249
+			goto found;
125 250
  		} else {
126 251
  			goto unknown;
127 252
  		}
... ...
@@ -132,7 +257,7 @@ int parse_method(str* _next, enum request_method* _method)
132 257
  			*_method = METHOD_NOTIFY;
133 258
  			_next->len -= 6;
134 259
  			_next->s += 6;
135
- 			return 1;
260
+			goto found;
136 261
  		} else {
137 262
  			goto unknown;
138 263
  		}
... ...
@@ -143,7 +268,7 @@ int parse_method(str* _next, enum request_method* _method)
143 268
  			*_method = METHOD_OPTIONS;
144 269
  			_next->len -= 7;
145 270
  			_next->s += 7;
146
- 			return 1;
271
+			goto found;
147 272
  		} else {
148 273
  			goto unknown;
149 274
  		}
... ...
@@ -154,13 +279,13 @@ int parse_method(str* _next, enum request_method* _method)
154 279
  			*_method = METHOD_PRACK;
155 280
  			_next->len -= 5;
156 281
  			_next->s += 5;
157
- 			return 1;
282
+			goto found;
158 283
  		}
159 284
  		if ((_next->len > 6) && !strncasecmp(_next->s + 1, "ublish", 6)) {
160 285
  			*_method = METHOD_PUBLISH;
161 286
  			_next->len -= 7;
162 287
  			_next->s += 7;
163
- 			return 1;
288
+			goto found;
164 289
  		}
165 290
  		goto unknown;
166 291
 
... ...
@@ -172,14 +297,14 @@ int parse_method(str* _next, enum request_method* _method)
172 297
  				*_method = METHOD_REFER;
173 298
  				_next->len -= 5;
174 299
  				_next->s += 5;
175
- 				return 1;
300
+				goto found;
176 301
  			}
177 302
 
178 303
  			if ((_next->len > 7) && !strncasecmp(_next->s + 2, "gister", 6)) {
179 304
  				*_method = METHOD_REGISTER;
180 305
  				_next->len -= 8;
181 306
  				_next->s += 8;
182
- 				return 1;
307
+				goto found;
183 308
  			}
184 309
  		}
185 310
  		goto unknown;
... ...
@@ -190,7 +315,7 @@ int parse_method(str* _next, enum request_method* _method)
190 315
  			*_method = METHOD_SUBSCRIBE;
191 316
  			_next->len -= 9;
192 317
  			_next->s += 9;
193
- 			return 1;
318
+			goto found;
194 319
  		} else {
195 320
  			goto unknown;
196 321
  		}
... ...
@@ -201,7 +326,7 @@ int parse_method(str* _next, enum request_method* _method)
201 326
  			*_method = METHOD_UPDATE;
202 327
  			_next->len -= 6;
203 328
  			_next->s += 6;
204
- 			return 1;
329
+			goto found;
205 330
  		} else {
206 331
  			goto unknown;
207 332
  		}
... ...
@@ -209,7 +334,7 @@ int parse_method(str* _next, enum request_method* _method)
209 334
  	default:
210 335
  		goto unknown;
211 336
  	}
212
- 
337
+
213 338
  unknown:
214 339
  	if (token_char(*(_next->s))) {
215 340
  		do { 
... ...
@@ -221,6 +346,9 @@ int parse_method(str* _next, enum request_method* _method)
221 346
  	} else {
222 347
  		return 0;
223 348
  	}
349
+found:
350
+	/* check if the method really ends here (if not return 0) */
351
+	return (_next->s>=end) || (!token_char(*(_next->s)));
224 352
  }
225 353
  
226 354
  
... ...
@@ -252,7 +380,7 @@ int parse_method(str* _next, enum request_method* _method)
252 380
  	}
253 381
 
254 382
  	while (1) {
255
- 		if (parse_method(&next, &method)) {
383
+ 		if (parse_method_advance(&next, &method)) {
256 384
  			*_methods |= method;
257 385
  		} else {
258 386
  			LOG(L_ERR, "ERROR: parse_methods: Invalid method\n");
Browse code

parser: added METHOD_PUBLISH

- new bit flag allocated for PUBLISH
- parse_method() supports now METHOD_PUBLISH
- parse_methods() returns 0 on success and -1 on error as it is expected
by all use cases

Daniel-Constantin Mierla authored on 16/04/2009 22:33:43
Showing 1 changed files
... ...
@@ -155,9 +155,14 @@ int parse_method(str* _next, enum request_method* _method)
155 155
  			_next->len -= 5;
156 156
  			_next->s += 5;
157 157
  			return 1;
158
- 		} else {
159
- 			goto unknown;
160 158
  		}
159
+ 		if ((_next->len > 6) && !strncasecmp(_next->s + 1, "ublish", 6)) {
160
+ 			*_method = METHOD_PUBLISH;
161
+ 			_next->len -= 7;
162
+ 			_next->s += 7;
163
+ 			return 1;
164
+ 		}
165
+ 		goto unknown;
161 166
 
162 167
  	case 'R':
163 168
  	case 'r':
... ...
@@ -221,7 +226,7 @@ int parse_method(str* _next, enum request_method* _method)
221 226
  
222 227
  /* 
223 228
   * Parse comma separated list of methods pointed by _body and assign their
224
-  * enum bits to _methods.  Returns 1 on success and 0 on failure.
229
+  * enum bits to _methods.  Returns 0 on success and -1 on failure.
225 230
   */
226 231
  int parse_methods(str* _body, unsigned int* _methods)
227 232
  {
... ...
@@ -232,7 +237,7 @@ int parse_method(str* _next, enum request_method* _method)
232 237
  
233 238
 	if (!_body || !_methods) {
234 239
 		LOG(L_ERR, "parse_methods: Invalid parameter value\n");
235
-		return 0;
240
+		return -1;
236 241
 	}
237 242
 
238 243
 	next.len = _body->len;
... ...
@@ -240,19 +245,18 @@ int parse_method(str* _next, enum request_method* _method)
240 245
  
241 246
  	trim_leading(&next);
242 247
  
248
+  	*_methods = 0;
249
+ 
243 250
  	if (next.len == 0) {
244
- 		LOG(L_ERR, "ERROR: parse_methods: Empty body\n");
245 251
  		return 0;
246 252
  	}
247