Browse code

core: parser - print ascii code and position of invalid char for identity info

Daniel-Constantin Mierla authored on 12/01/2022 13:12:42
Showing 1 changed files
... ...
@@ -311,8 +311,8 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
311 311
 
312 312
 parseerror:
313 313
 	if(p < end) {
314
-		LM_ERR("unexpected char [%c] in status %d: [%.*s]\n", *p, status,
315
-				(int)(p - buffer), buffer);
314
+		LM_ERR("unexpected char [%c/%d] in status %d - pos %d: [%.*s]\n", *p, *p,
315
+				status, (int)(p - buffer), (int)(p - buffer), buffer);
316 316
 	} else {
317 317
 		LM_ERR("unexpected end of buffer - status %d\n", status);
318 318
 	}
Browse code

core: parser - clang format for parse_identityinfo.c

Daniel-Constantin Mierla authored on 15/12/2021 08:00:45
Showing 1 changed files
... ...
@@ -31,7 +31,7 @@
31 31
 #include "../mem/mem.h"
32 32
 #include "parse_def.h"
33 33
 #include "parse_identityinfo.h"
34
-#include "parser_f.h"  /* eat_space_end and so on */
34
+#include "parser_f.h" /* eat_space_end and so on */
35 35
 
36 36
 
37 37
 /*! \brief Parse Identity-info header field */
... ...
@@ -42,7 +42,8 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
42 42
 	char *p;
43 43
 
44 44
 
45
-	if (!buffer || !end || !ii_b) return ;
45
+	if(!buffer || !end || !ii_b)
46
+		return;
46 47
 
47 48
 
48 49
 	ii_b->error = PARSE_ERROR;
... ...
@@ -50,8 +51,8 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
50 51
 	for(p = buffer; p < end; p++) {
51 52
 		switch(*p) {
52 53
 			case '<':
53
-				if (status == II_START) {
54
-					status=II_URI_BEGIN;
54
+				if(status == II_START) {
55
+					status = II_URI_BEGIN;
55 56
 					mainstatus = II_M_URI_BEGIN;
56 57
 					ii_b->uri.s = p + 1;
57 58
 				} else {
... ...
@@ -60,15 +61,16 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
60 61
 				break;
61 62
 			case 'h':
62 63
 			case 'H': /* "http://" or "https://" part  */
63
-				switch (status) {
64
+				switch(status) {
64 65
 					case II_URI_BEGIN:
65
-						if (end - p <= 8 || strncasecmp(p, "http", 4))
66
+						if(end - p <= 8 || strncasecmp(p, "http", 4))
66 67
 							goto parseerror;
67
-						p+=4;
68
-						if (*p == 's' || *p == 'S') p++;
69
-						if (memcmp(p,"://",strlen("://")))
68
+						p += 4;
69
+						if(*p == 's' || *p == 'S')
70
+							p++;
71
+						if(memcmp(p, "://", strlen("://")))
70 72
 							goto parseerror;
71
-						p+=2;
73
+						p += 2;
72 74
 						status = II_URI_DOMAIN;
73 75
 						break;
74 76
 					case II_URI_DOMAIN:
... ...
@@ -85,14 +87,14 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
85 87
 						ii_b->alg.s = p;
86 88
 						break;
87 89
 					case II_LWSCRLF:
88
-						ii_b->error=PARSE_OK;
89
-						return ;
90
+						ii_b->error = PARSE_OK;
91
+						return;
90 92
 					default:
91 93
 						goto parseerror;
92 94
 				}
93 95
 				break;
94 96
 			case '/':
95
-				switch(status){
97
+				switch(status) {
96 98
 					case II_URI_IPV4:
97 99
 						ii_b->domain.len = p - ii_b->domain.s;
98 100
 						status = II_URI_PATH;
... ...
@@ -105,7 +107,7 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
105 107
 				}
106 108
 				break;
107 109
 			case '>':
108
-				if (status == II_URI_PATH) {
110
+				if(status == II_URI_PATH) {
109 111
 					ii_b->uri.len = p - ii_b->uri.s;
110 112
 					status = II_URI_END;
111 113
 					mainstatus = II_M_URI_END;
... ...
@@ -114,7 +116,7 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
114 116
 				break;
115 117
 			case ' ':
116 118
 			case '\t':
117
-				switch (status) {
119
+				switch(status) {
118 120
 					case II_EQUAL:
119 121
 					case II_TAG:
120 122
 					case II_SEMIC:
... ...
@@ -132,7 +134,7 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
132 134
 				}
133 135
 				break;
134 136
 			case '\r':
135
-				switch (status) {
137
+				switch(status) {
136 138
 					case II_TOKEN:
137 139
 						ii_b->alg.len = p - ii_b->alg.s;
138 140
 						status = II_ENDHEADER;
... ...
@@ -145,17 +147,17 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
145 147
 						status = II_LWSCR;
146 148
 						break;
147 149
 					case II_LWSCRLF:
148
-						ii_b->error=PARSE_OK;
149
-						return ;
150
+						ii_b->error = PARSE_OK;
151
+						return;
150 152
 					default:
151 153
 						goto parseerror;
152 154
 				}
153 155
 				break;
154 156
 			case '\n':
155
-				switch (status) {
157
+				switch(status) {
156 158
 					case II_LWSCRLF:
157
-						ii_b->error=PARSE_OK;
158
-						return ;
159
+						ii_b->error = PARSE_OK;
160
+						return;
159 161
 					case II_EQUAL:
160 162
 					case II_TAG:
161 163
 					case II_SEMIC:
... ...
@@ -167,24 +169,24 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
167 169
 					case II_TOKEN: /* if there was not '\r' */
168 170
 						ii_b->alg.len = p - ii_b->alg.s;
169 171
 					case II_ENDHEADER:
170
-						p=eat_lws_end(p, end);
172
+						p = eat_lws_end(p, end);
171 173
 						/*check if the header ends here*/
172
-						if (p>=end) {
174
+						if(p >= end) {
173 175
 							LM_ERR("strange EoHF\n");
174 176
 							goto parseerror;
175 177
 						}
176
-						ii_b->error=PARSE_OK;
177
-						return ;
178
+						ii_b->error = PARSE_OK;
179
+						return;
178 180
 					default:
179 181
 						goto parseerror;
180 182
 				}
181 183
 				break;
182 184
 			case ';':
183
-				switch (status) {
185
+				switch(status) {
184 186
 					case II_URI_END:
185 187
 					case II_LWS:
186 188
 					case II_LWSCRLFSP:
187
-						if (mainstatus == II_M_URI_END) {
189
+						if(mainstatus == II_M_URI_END) {
188 190
 							status = II_SEMIC;
189 191
 							mainstatus = II_M_SEMIC;
190 192
 						} else
... ...
@@ -196,17 +198,17 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
196 198
 				break;
197 199
 			case 'a': /* tag part of 'alg' parameter */
198 200
 			case 'A':
199
-				switch (status) {
201
+				switch(status) {
200 202
 					case II_LWS:
201 203
 					case II_LWSCRLFSP:
202 204
 					case II_SEMIC:
203
-						if (mainstatus == II_M_SEMIC) {
205
+						if(mainstatus == II_M_SEMIC) {
204 206
 							mainstatus = II_M_TAG;
205 207
 							status = II_TAG;
206
-							if (end - p <= 3
207
-									|| strncasecmp(p,"alg",strlen("alg")))
208
+							if(end - p <= 3
209
+									|| strncasecmp(p, "alg", strlen("alg")))
208 210
 								goto parseerror;
209
-							p+=2;
211
+							p += 2;
210 212
 						} else
211 213
 							goto parseerror;
212 214
 						break;
... ...
@@ -223,18 +225,18 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
223 225
 						ii_b->alg.s = p;
224 226
 						break;
225 227
 					case II_LWSCRLF:
226
-						ii_b->error=PARSE_OK;
227
-						return ;
228
+						ii_b->error = PARSE_OK;
229
+						return;
228 230
 					default:
229 231
 						goto parseerror;
230 232
 				}
231 233
 				break;
232 234
 			case '=':
233
-				switch (status) {
235
+				switch(status) {
234 236
 					case II_TAG:
235 237
 					case II_LWS:
236 238
 					case II_LWSCRLFSP:
237
-						if (mainstatus == II_M_TAG) {
239
+						if(mainstatus == II_M_TAG) {
238 240
 							status = II_EQUAL;
239 241
 							mainstatus = II_M_EQUAL;
240 242
 						} else
... ...
@@ -247,7 +249,7 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
247 249
 				}
248 250
 				break;
249 251
 			case '[':
250
-				switch (status) {
252
+				switch(status) {
251 253
 					case II_URI_DOMAIN:
252 254
 						status = II_URI_IPV6;
253 255
 						ii_b->domain.s = p + 1;
... ...
@@ -257,7 +259,7 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
257 259
 				}
258 260
 				break;
259 261
 			case ']':
260
-				switch (status) {
262
+				switch(status) {
261 263
 					case II_URI_IPV6:
262 264
 						ii_b->domain.len = p - ii_b->domain.s;
263 265
 						status = II_URI_PATH;
... ...
@@ -268,17 +270,17 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
268 270
 				}
269 271
 				break;
270 272
 			case ':':
271
-				if (status == II_URI_IPV4) {
273
+				if(status == II_URI_IPV4) {
272 274
 					ii_b->domain.len = p - ii_b->domain.s;
273 275
 					status = II_URI_PATH;
274 276
 				}
275 277
 				break;
276 278
 			default:
277
-				switch (status) {
279
+				switch(status) {
278 280
 					case II_EQUAL:
279 281
 					case II_LWS:
280 282
 					case II_LWSCRLFSP:
281
-						if (mainstatus == II_M_EQUAL) {
283
+						if(mainstatus == II_M_EQUAL) {
282 284
 							status = II_TOKEN;
283 285
 							mainstatus = II_M_TOKEN;
284 286
 							ii_b->alg.s = p;
... ...
@@ -288,18 +290,15 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
288 290
 					case II_TOKEN:
289 291
 						break;
290 292
 					case II_LWSCRLF:
291
-						ii_b->error=PARSE_OK;
292
-						return ;
293
+						ii_b->error = PARSE_OK;
294
+						return;
293 295
 					case II_URI_DOMAIN:
294 296
 						ii_b->domain.s = p;
295 297
 						status = II_URI_IPV4;
296 298
 					case II_URI_IPV4:
297 299
 					case II_URI_IPV6:
298
-						if (isalnum(*p)
299
-								|| *p == '-'
300
-								|| *p == '.'
301
-								|| *p == ':' )
302
-						break;
300
+						if(isalnum(*p) || *p == '-' || *p == '.' || *p == ':')
301
+							break;
303 302
 					case II_START:
304 303
 						goto parseerror;
305 304
 				}
... ...
@@ -307,50 +306,50 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
307 306
 		}
308 307
 	}
309 308
 	/* we successfully parse the header */
310
-	ii_b->error=PARSE_OK;
311
-	return ;
309
+	ii_b->error = PARSE_OK;
310
+	return;
312 311
 
313 312
 parseerror:
314
-	if(p<end) {
315
-		LM_ERR("unexpected char [%c] in status %d: <<%.*s>> .\n",
316
-				*p, status, (int)(p-buffer), buffer);
313
+	if(p < end) {
314
+		LM_ERR("unexpected char [%c] in status %d: [%.*s]\n", *p, status,
315
+				(int)(p - buffer), buffer);
317 316
 	} else {
318 317
 		LM_ERR("unexpected end of buffer - status %d\n", status);
319 318
 	}
320
-	return ;
319
+	return;
321 320
 }
322 321
 
323 322
 int parse_identityinfo_header(struct sip_msg *msg)
324 323
 {
325
-	struct identityinfo_body* identityinfo_b;
324
+	struct identityinfo_body *identityinfo_b;
326 325
 
327 326
 
328
-	if ( !msg->identity_info
329
-			&& (parse_headers(msg,HDR_IDENTITY_INFO_F,0)==-1
330
-				|| !msg->identity_info) ) {
327
+	if(!msg->identity_info
328
+			&& (parse_headers(msg, HDR_IDENTITY_INFO_F, 0) == -1
329
+					|| !msg->identity_info)) {
331 330
 		LM_ERR("bad msg or missing IDENTITY-INFO header\n");
332 331
 		goto error;
333 332
 	}
334 333
 
335 334
 	/* maybe the header is already parsed! */
336
-	if (msg->identity_info->parsed)
335
+	if(msg->identity_info->parsed)
337 336
 		return 0;
338 337
 
339
-	identityinfo_b=pkg_malloc(sizeof(*identityinfo_b));
340
-	if (identityinfo_b==0){
338
+	identityinfo_b = pkg_malloc(sizeof(*identityinfo_b));
339
+	if(identityinfo_b == 0) {
341 340
 		PKG_MEM_ERROR;
342 341
 		goto error;
343 342
 	}
344 343
 	memset(identityinfo_b, 0, sizeof(*identityinfo_b));
345 344
 
346 345
 	parse_identityinfo(msg->identity_info->body.s,
347
-			msg->identity_info->body.s + msg->identity_info->body.len+1,
346
+			msg->identity_info->body.s + msg->identity_info->body.len + 1,
348 347
 			identityinfo_b);
349
-	if (identityinfo_b->error==PARSE_ERROR){
348
+	if(identityinfo_b->error == PARSE_ERROR) {
350 349
 		free_identityinfo(identityinfo_b);
351 350
 		goto error;
352 351
 	}
353
-	msg->identity_info->parsed=(void*)identityinfo_b;
352
+	msg->identity_info->parsed = (void *)identityinfo_b;
354 353
 
355 354
 	return 0;
356 355
 error:
Browse code

core: parser - print start of buffer on error for identity info

Daniel-Constantin Mierla authored on 11/12/2021 17:40:51
Showing 1 changed files
... ...
@@ -313,7 +313,7 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
313 313
 parseerror:
314 314
 	if(p<end) {
315 315
 		LM_ERR("unexpected char [%c] in status %d: <<%.*s>> .\n",
316
-				*p, status, (int)(p-buffer), ZSW(p));
316
+				*p, status, (int)(p-buffer), buffer);
317 317
 	} else {
318 318
 		LM_ERR("unexpected end of buffer - status %d\n", status);
319 319
 	}
Browse code

core: parse identityinfo - log message on end of buffer

Daniel-Constantin Mierla authored on 20/09/2021 05:22:57
Showing 1 changed files
... ...
@@ -311,8 +311,12 @@ void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
311 311
 	return ;
312 312
 
313 313
 parseerror:
314
-	LM_ERR("unexpected char [%c] in status %d: <<%.*s>> .\n",
315
-			*p,status, (int)(p-buffer), ZSW(p));
314
+	if(p<end) {
315
+		LM_ERR("unexpected char [%c] in status %d: <<%.*s>> .\n",
316
+				*p, status, (int)(p-buffer), ZSW(p));
317
+	} else {
318
+		LM_ERR("unexpected end of buffer - status %d\n", status);
319
+	}
316 320
 	return ;
317 321
 }
318 322
 
Browse code

core: parse iidentityinfo - use ZSW() define from core

Daniel-Constantin Mierla authored on 12/10/2020 06:31:28
Showing 1 changed files
... ...
@@ -27,6 +27,7 @@
27 27
 #include <stdlib.h>
28 28
 #include <string.h>
29 29
 #include <ctype.h>
30
+#include "../ut.h"
30 31
 #include "../mem/mem.h"
31 32
 #include "parse_def.h"
32 33
 #include "parse_identityinfo.h"
Browse code

core: use generic PKG_MEM_ERROR, SHM_ERROR and _CRITICAL helper defines in core

- refactoring of the core to use generic PKG_MEM_ERROR, SHM_ERROR,
PKG_MEM_CRITICAL, SHM_MEM_CRITICAL and SYS_MEM_ERROR helper defines
- unify many different error messages in different spellings
- add a few missing error handler for allocation errors after (found
with a complete review of all memory allocation functions in core)
- no other functional changes, change has been reviewed two times

Henning Westerholt authored on 23/12/2018 21:31:03
Showing 1 changed files
... ...
@@ -333,7 +333,7 @@ int parse_identityinfo_header(struct sip_msg *msg)
333 333
 
334 334
 	identityinfo_b=pkg_malloc(sizeof(*identityinfo_b));
335 335
 	if (identityinfo_b==0){
336
-		LM_ERR("out of pkg memory\n");
336
+		PKG_MEM_ERROR;
337 337
 		goto error;
338 338
 	}
339 339
 	memset(identityinfo_b, 0, sizeof(*identityinfo_b));
Browse code

core: parser - converted old log macros

- indentation adjustments

Daniel-Constantin Mierla authored on 07/08/2017 07:16:15
Showing 1 changed files
... ...
@@ -333,7 +333,7 @@ int parse_identityinfo_header(struct sip_msg *msg)
333 333
 
334 334
 	identityinfo_b=pkg_malloc(sizeof(*identityinfo_b));
335 335
 	if (identityinfo_b==0){
336
-		LOG(L_ERR, "ERROR:parse_identityinfo_header: out of memory\n");
336
+		LM_ERR("out of pkg memory\n");
337 337
 		goto error;
338 338
 	}
339 339
 	memset(identityinfo_b, 0, sizeof(*identityinfo_b));
Browse code

core, lib, modules: restructured source code tree

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

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,358 @@
1
+/*
2
+ * Copyright (c) 2007 iptelorg GmbH
3
+ *
4
+ * This file is part of Kamailio, a free SIP server.
5
+ *
6
+ * Kamailio is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version
10
+ *
11
+ * Kamailio is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
+ */
20
+
21
+/*! \file
22
+ * \brief Parser :: Parse Identity-info header field
23
+ *
24
+ * \ingroup parser
25
+ */
26
+
27
+#include <stdlib.h>
28
+#include <string.h>
29
+#include <ctype.h>
30
+#include "../mem/mem.h"
31
+#include "parse_def.h"
32
+#include "parse_identityinfo.h"
33
+#include "parser_f.h"  /* eat_space_end and so on */
34
+
35
+
36
+/*! \brief Parse Identity-info header field */
37
+void parse_identityinfo(char *buffer, char *end, struct identityinfo_body *ii_b)
38
+{
39
+	int status = II_START;
40
+	int mainstatus = II_M_START;
41
+	char *p;
42
+
43
+
44
+	if (!buffer || !end || !ii_b) return ;
45
+
46
+
47
+	ii_b->error = PARSE_ERROR;
48
+
49
+	for(p = buffer; p < end; p++) {
50
+		switch(*p) {
51
+			case '<':
52
+				if (status == II_START) {
53
+					status=II_URI_BEGIN;
54
+					mainstatus = II_M_URI_BEGIN;
55
+					ii_b->uri.s = p + 1;
56
+				} else {
57
+					goto parseerror;
58
+				}
59
+				break;
60
+			case 'h':
61
+			case 'H': /* "http://" or "https://" part  */
62
+				switch (status) {
63
+					case II_URI_BEGIN:
64
+						if (end - p <= 8 || strncasecmp(p, "http", 4))
65
+							goto parseerror;
66
+						p+=4;
67
+						if (*p == 's' || *p == 'S') p++;
68
+						if (memcmp(p,"://",strlen("://")))
69
+							goto parseerror;
70
+						p+=2;
71
+						status = II_URI_DOMAIN;
72
+						break;
73
+					case II_URI_DOMAIN:
74
+						status = II_URI_IPV4;
75
+					case II_URI_IPV4:
76
+					case II_URI_IPV6:
77
+					case II_URI_PATH:
78
+					case II_TOKEN:
79
+					case II_TAG:
80
+						break;
81
+					case II_EQUAL:
82
+						status = II_TOKEN;
83
+						mainstatus = II_M_TOKEN;
84
+						ii_b->alg.s = p;
85
+						break;
86
+					case II_LWSCRLF:
87
+						ii_b->error=PARSE_OK;
88
+						return ;
89
+					default:
90
+						goto parseerror;
91
+				}
92
+				break;
93
+			case '/':
94
+				switch(status){
95
+					case II_URI_IPV4:
96
+						ii_b->domain.len = p - ii_b->domain.s;
97
+						status = II_URI_PATH;
98
+						break;
99
+					case II_URI_PATH:
100
+						break;
101
+					case II_URI_IPV6:
102
+					default:
103
+						goto parseerror;
104
+				}
105
+				break;
106
+			case '>':
107
+				if (status == II_URI_PATH) {
108
+					ii_b->uri.len = p - ii_b->uri.s;
109
+					status = II_URI_END;
110
+					mainstatus = II_M_URI_END;
111
+				} else
112
+					goto parseerror;
113
+				break;
114
+			case ' ':
115
+			case '\t':
116
+				switch (status) {
117
+					case II_EQUAL:
118
+					case II_TAG:
119
+					case II_SEMIC:
120
+					case II_URI_END:
121
+						status = II_LWS;
122
+						break;
123
+					case II_LWS:
124
+					case II_LWSCRLFSP:
125
+						break;
126
+					case II_LWSCRLF:
127
+						status = II_LWSCRLFSP;
128
+						break;
129
+					default:
130
+						goto parseerror;
131
+				}
132
+				break;
133
+			case '\r':
134
+				switch (status) {
135
+					case II_TOKEN:
136
+						ii_b->alg.len = p - ii_b->alg.s;
137
+						status = II_ENDHEADER;
138
+						break;
139
+					case II_EQUAL:
140
+					case II_TAG:
141
+					case II_SEMIC:
142
+					case II_URI_END:
143
+					case II_LWS:
144
+						status = II_LWSCR;
145
+						break;
146
+					case II_LWSCRLF:
147
+						ii_b->error=PARSE_OK;
148
+						return ;
149
+					default:
150
+						goto parseerror;
151
+				}
152
+				break;
153
+			case '\n':
154
+				switch (status) {
155
+					case II_LWSCRLF:
156
+						ii_b->error=PARSE_OK;
157
+						return ;
158
+					case II_EQUAL:
159
+					case II_TAG:
160
+					case II_SEMIC:
161
+					case II_URI_END:
162
+					case II_LWS:
163
+					case II_LWSCR:
164
+						status = II_LWSCRLF;
165
+						break;
166
+					case II_TOKEN: /* if there was not '\r' */
167
+						ii_b->alg.len = p - ii_b->alg.s;
168
+					case II_ENDHEADER:
169
+						p=eat_lws_end(p, end);
170
+						/*check if the header ends here*/
171
+						if (p>=end) {
172
+							LM_ERR("strange EoHF\n");
173
+							goto parseerror;
174
+						}
175
+						ii_b->error=PARSE_OK;
176
+						return ;
177
+					default:
178
+						goto parseerror;
179
+				}
180
+				break;
181
+			case ';':
182
+				switch (status) {
183
+					case II_URI_END:
184
+					case II_LWS:
185
+					case II_LWSCRLFSP:
186
+						if (mainstatus == II_M_URI_END) {
187
+							status = II_SEMIC;
188
+							mainstatus = II_M_SEMIC;
189
+						} else
190
+							goto parseerror;
191
+						break;
192
+					default:
193
+						goto parseerror;
194
+				}
195
+				break;
196
+			case 'a': /* tag part of 'alg' parameter */
197
+			case 'A':
198
+				switch (status) {
199
+					case II_LWS:
200
+					case II_LWSCRLFSP:
201
+					case II_SEMIC:
202
+						if (mainstatus == II_M_SEMIC) {
203
+							mainstatus = II_M_TAG;
204
+							status = II_TAG;
205
+							if (end - p <= 3
206
+									|| strncasecmp(p,"alg",strlen("alg")))
207
+								goto parseerror;
208
+							p+=2;
209
+						} else
210
+							goto parseerror;
211
+						break;
212
+					case II_URI_DOMAIN:
213
+						status = II_URI_IPV4;
214
+					case II_URI_IPV4:
215
+					case II_URI_IPV6:
216
+					case II_URI_PATH:
217
+					case II_TOKEN:
218
+						break;
219
+					case II_EQUAL:
220
+						status = II_TOKEN;
221
+						mainstatus = II_M_TOKEN;
222
+						ii_b->alg.s = p;
223
+						break;
224
+					case II_LWSCRLF:
225
+						ii_b->error=PARSE_OK;
226
+						return ;
227
+					default:
228
+						goto parseerror;
229
+				}
230
+				break;
231
+			case '=':
232
+				switch (status) {
233
+					case II_TAG:
234
+					case II_LWS:
235
+					case II_LWSCRLFSP:
236
+						if (mainstatus == II_M_TAG) {
237
+							status = II_EQUAL;
238
+							mainstatus = II_M_EQUAL;
239
+						} else
240
+							goto parseerror;
241
+						break;
242
+					case II_URI_PATH:
243
+						break;
244
+					default:
245
+						goto parseerror;
246
+				}
247
+				break;
248
+			case '[':
249
+				switch (status) {
250
+					case II_URI_DOMAIN:
251
+						status = II_URI_IPV6;
252
+						ii_b->domain.s = p + 1;
253
+						break;
254
+					default:
255
+						goto parseerror;
256
+				}
257
+				break;
258
+			case ']':
259
+				switch (status) {
260
+					case II_URI_IPV6:
261
+						ii_b->domain.len = p - ii_b->domain.s;
262
+						status = II_URI_PATH;
263
+						break;
264
+					case II_URI_IPV4:
265
+					case II_URI_PATH:
266
+						goto parseerror;
267
+				}
268
+				break;
269
+			case ':':
270
+				if (status == II_URI_IPV4) {
271
+					ii_b->domain.len = p - ii_b->domain.s;
272
+					status = II_URI_PATH;
273
+				}
274
+				break;
275
+			default:
276
+				switch (status) {
277
+					case II_EQUAL:
278
+					case II_LWS:
279
+					case II_LWSCRLFSP:
280
+						if (mainstatus == II_M_EQUAL) {
281
+							status = II_TOKEN;
282
+							mainstatus = II_M_TOKEN;
283
+							ii_b->alg.s = p;
284
+						} else
285
+							goto parseerror;
286
+						break;
287
+					case II_TOKEN:
288
+						break;
289
+					case II_LWSCRLF:
290
+						ii_b->error=PARSE_OK;
291
+						return ;
292
+					case II_URI_DOMAIN:
293
+						ii_b->domain.s = p;
294
+						status = II_URI_IPV4;
295
+					case II_URI_IPV4:
296
+					case II_URI_IPV6:
297
+						if (isalnum(*p)
298
+								|| *p == '-'
299
+								|| *p == '.'
300
+								|| *p == ':' )
301
+						break;
302
+					case II_START:
303
+						goto parseerror;
304
+				}
305
+				break;
306
+		}
307
+	}
308
+	/* we successfully parse the header */
309
+	ii_b->error=PARSE_OK;
310
+	return ;
311
+
312
+parseerror:
313
+	LM_ERR("unexpected char [%c] in status %d: <<%.*s>> .\n",
314
+			*p,status, (int)(p-buffer), ZSW(p));
315
+	return ;
316
+}
317
+
318
+int parse_identityinfo_header(struct sip_msg *msg)
319
+{
320
+	struct identityinfo_body* identityinfo_b;
321
+
322
+
323
+	if ( !msg->identity_info
324
+			&& (parse_headers(msg,HDR_IDENTITY_INFO_F,0)==-1
325
+				|| !msg->identity_info) ) {
326
+		LM_ERR("bad msg or missing IDENTITY-INFO header\n");
327
+		goto error;
328
+	}
329
+
330
+	/* maybe the header is already parsed! */
331
+	if (msg->identity_info->parsed)
332
+		return 0;
333
+
334
+	identityinfo_b=pkg_malloc(sizeof(*identityinfo_b));
335
+	if (identityinfo_b==0){
336
+		LOG(L_ERR, "ERROR:parse_identityinfo_header: out of memory\n");
337
+		goto error;
338
+	}
339
+	memset(identityinfo_b, 0, sizeof(*identityinfo_b));
340
+
341
+	parse_identityinfo(msg->identity_info->body.s,
342
+			msg->identity_info->body.s + msg->identity_info->body.len+1,
343
+			identityinfo_b);
344
+	if (identityinfo_b->error==PARSE_ERROR){
345
+		free_identityinfo(identityinfo_b);
346
+		goto error;
347
+	}
348
+	msg->identity_info->parsed=(void*)identityinfo_b;
349
+
350
+	return 0;
351
+error:
352
+	return -1;
353
+}
354
+
355
+void free_identityinfo(struct identityinfo_body *ii_b)
356
+{
357
+	pkg_free(ii_b);
358
+}