* Parse parameters * _s is string containing parameters, it will be updated to point behind the parameters * _c is class of parameters * _h is pointer to structure that will be filled with pointer to well known parameters * linked list of parsed parameters will be stored in * the variable _p is pointing to * The function returns 0 on success and negative number * on an error */
| 346 | * on an error |
| 347 | */ |
| 348 | int parse_params(str* _s, pclass_t _c, param_hooks_t* _h, param_t** _p) |
| 349 | { |
| 350 | param_t* t; |
| 351 | param_t* last; |
| 352 | |
| 353 | if (!_s || !_h || !_p) { |
| 354 | LM_ERR("invalid parameter value\n"); |
| 355 | return -1; |
| 356 | } |
| 357 | |
| 358 | memset(_h, 0, sizeof(param_hooks_t)); |
| 359 | last = NULL; |
| 360 | *_p = 0; |
| 361 | |
| 362 | if (!_s->s) { /* no parameters at all -- we're done */ |
| 363 | LM_DBG("empty uri params, skipping\n"); |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | LM_DBG("Parsing params for:[%.*s]\n",_s->len,_s->s); |
| 368 | |
| 369 | while(1) { |
| 370 | t = (param_t*)pkg_malloc(sizeof(param_t)); |
| 371 | if (t == 0) { |
| 372 | LM_ERR("no pkg memory left\n"); |
| 373 | goto error; |
| 374 | } |
| 375 | memset(t, 0, sizeof(param_t)); |
| 376 | |
| 377 | parse_param_name(_s, _c, _h, t); |
| 378 | trim_leading(_s); |
| 379 | |
| 380 | if (_s->len == 0) { /* The last parameter without body */ |
| 381 | t->len = t->name.len; |
| 382 | goto ok; |
| 383 | } |
| 384 | |
| 385 | if (_s->s[0] == '=') { |
| 386 | _s->s++; |
| 387 | _s->len--; |
| 388 | trim_leading(_s); |
| 389 | |
| 390 | if (_s->len == 0) { |
| 391 | LM_ERR("body missing\n"); |
| 392 | goto error; |
| 393 | } |
| 394 | |
| 395 | if (parse_param_body(_s, t) < 0) { |
| 396 | LM_ERR("failed to parse param body\n"); |
| 397 | goto error; |
| 398 | } |
| 399 | |
| 400 | t->len = _s->s - t->name.s; |
| 401 | |
| 402 | trim_leading(_s); |
| 403 | if (_s->len == 0) { |
| 404 | goto ok; |
| 405 | } |
no test coverage detected