Browse code

- wrong parameter length fixed, fix provided by Bogdan Pintea closes SER-135

Jan Janak authored on 22/11/2006 17:56:15
Showing 2 changed files
... ...
@@ -350,6 +350,78 @@ static inline int parse_param_body(str* _s, param_t* _c)
350 350
 }
351 351
 
352 352
 
353
+/**
354
+ * Only parse one parameter
355
+ * Returns:
356
+ * 	t: out parameter
357
+ * 	-1: on error
358
+ * 	0: success, but expect a next paramter
359
+ * 	1: success and exepect no more parameters
360
+ */
361
+inline int parse_param(str *_s, pclass_t _c, param_hooks_t *_h, param_t *t)
362
+{
363
+	memset(t, 0, sizeof(param_t));
364
+
365
+	parse_param_name(_s, _c, _h, t);
366
+	trim_leading(_s);
367
+	
368
+	if (_s->len == 0) { /* The last parameter without body */
369
+		t->len = t->name.len;
370
+		goto ok;
371
+	}
372
+	
373
+	if (_s->s[0] == '=') {
374
+		_s->s++;
375
+		_s->len--;
376
+		trim_leading(_s);
377
+
378
+		if (_s->len == 0) {
379
+			LOG(L_ERR, "parse_params(): Body missing\n");
380
+			goto error;
381
+		}
382
+
383
+		if (parse_param_body(_s, t) < 0) {
384
+			LOG(L_ERR, "parse_params(): Error while parsing param body\n");
385
+			goto error;
386
+		}
387
+
388
+		t->len = _s->s - t->name.s;
389
+
390
+		trim_leading(_s);
391
+		if (_s->len == 0) {
392
+			goto ok;
393
+		}
394
+	} else {
395
+		t->len = t->name.len;
396
+	}
397
+
398
+	if (_s->s[0] == ',') goto ok; /* To be able to parse header parameters */
399
+	if (_s->s[0] == '>') goto ok; /* To be able to parse URI parameters */
400
+
401
+	if (_s->s[0] != ';') {
402
+		LOG(L_ERR, "parse_params(): Invalid character, ; expected\n");
403
+		goto error;
404
+	}
405
+
406
+	_s->s++;
407
+	_s->len--;
408
+	trim_leading(_s);
409
+	
410
+	if (_s->len == 0) {
411
+		LOG(L_ERR, "parse_params(): Param name missing after ;\n");
412
+		goto error;
413
+	}
414
+
415
+	return 0; /* expect more params */
416
+
417
+ok:
418
+	return 1; /* done with parsing for params */
419
+error:
420
+	return -1;
421
+}
422
+
423
+
424
+
353 425
 /*
354 426
  * Parse parameters
355 427
  * _s is string containing parameters, it will be updated to point behind the parameters
... ...
@@ -383,55 +455,11 @@ int parse_params(str* _s, pclass_t _c, param_hooks_t* _h, param_t** _p)
383 455
 			LOG(L_ERR, "parse_params(): No memory left\n");
384 456
 			goto error;
385 457
 		}
386
-		memset(t, 0, sizeof(param_t));
387
-
388
-		parse_param_name(_s, _c, _h, t);
389
-		trim_leading(_s);
390
-		
391
-		if (_s->len == 0) { /* The last parameter without body */
392
-			goto ok;
393
-		}
394
-		
395
-		if (_s->s[0] == '=') {
396
-			_s->s++;
397
-			_s->len--;
398
-			trim_leading(_s);
399
-
400
-			if (_s->len == 0) {
401
-				LOG(L_ERR, "parse_params(): Body missing\n");
402
-				goto error;
403
-			}
404
-
405
-			if (parse_param_body(_s, t) < 0) {
406
-				LOG(L_ERR, "parse_params(): Error while parsing param body\n");
407
-				goto error;
408
-			}
409 458
 
410
-			t->len = _s->s - t->name.s;
411
-
412
-			trim_leading(_s);
413
-			if (_s->len == 0) {
414
-				goto ok;
415
-			}
416
-		} else {
417
-			t->len = t->name.len;
418
-		}
419
-
420
-		if (_s->s[0] == ',') goto ok; /* To be able to parse header parameters */
421
-		if (_s->s[0] == '>') goto ok; /* To be able to parse URI parameters */
422
-
423
-		if (_s->s[0] != ';') {
424
-			LOG(L_ERR, "parse_params(): Invalid character, ; expected\n");
425
-			goto error;
426
-		}
427
-
428
-		_s->s++;
429
-		_s->len--;
430
-		trim_leading(_s);
431
-		
432
-		if (_s->len == 0) {
433
-			LOG(L_ERR, "parse_params(): Param name missing after ;\n");
434
-			goto error;
459
+		switch(parse_param(_s, _c, _h, t)) {
460
+		case 0: break;
461
+		case 1: goto ok;
462
+		default: goto error;
435 463
 		}
436 464
 
437 465
 		t->next = *_p;
... ...
@@ -117,6 +117,16 @@ typedef union param_hooks {
117 117
 	struct uri_hooks uri;         /* URI hooks */
118 118
 } param_hooks_t;
119 119
 
120
+/**
121
+ * Only parse one parameter
122
+ * @Return:
123
+ * 	t: out parameter
124
+ * 	-1: on error
125
+ * 	0: success, but expect a next paramter
126
+ * 	1: success and exepect no more parameters
127
+ */
128
+inline int parse_param(str *_s, pclass_t _c, param_hooks_t *_h, param_t *t);
129
+
120 130
 
121 131
 /*
122 132
  * Parse parameters