* */
| 5290 | * |
| 5291 | */ |
| 5292 | int pv_parse_format(const str *in, pv_elem_p *el) |
| 5293 | { |
| 5294 | char *p, *p0; |
| 5295 | /*int n = 0;*/ |
| 5296 | pv_elem_p e, e0; |
| 5297 | str s; |
| 5298 | |
| 5299 | if(in==NULL || in->s==NULL || el==NULL) |
| 5300 | return -1; |
| 5301 | |
| 5302 | /*LM_DBG("parsing [%.*s]\n", in->len, in->s);*/ |
| 5303 | |
| 5304 | if(in->len == 0) |
| 5305 | { |
| 5306 | *el = pkg_malloc(sizeof(pv_elem_t)); |
| 5307 | if(*el == NULL) { |
| 5308 | LM_ERR("not enough pkg memory for PV element (1)\n"); |
| 5309 | goto error; |
| 5310 | } |
| 5311 | memset(*el, 0, sizeof(pv_elem_t)); |
| 5312 | (*el)->text = *in; |
| 5313 | return 0; |
| 5314 | } |
| 5315 | |
| 5316 | p = in->s; |
| 5317 | *el = NULL; |
| 5318 | e = e0 = NULL; |
| 5319 | |
| 5320 | while(is_in_str(p,in)) |
| 5321 | { |
| 5322 | e0 = e; |
| 5323 | e = pkg_malloc(sizeof(pv_elem_t)); |
| 5324 | if(!e) { |
| 5325 | LM_ERR("not enough pkg memory for PV element (2)\n"); |
| 5326 | goto error; |
| 5327 | } |
| 5328 | memset(e, 0, sizeof(pv_elem_t)); |
| 5329 | /*n++;*/ |
| 5330 | if(*el == NULL) |
| 5331 | *el = e; |
| 5332 | if(e0) |
| 5333 | e0->next = e; |
| 5334 | |
| 5335 | e->text.s = p; |
| 5336 | while(is_in_str(p,in) && *p!=PV_MARKER) |
| 5337 | p++; |
| 5338 | e->text.len = p - e->text.s; |
| 5339 | |
| 5340 | if(!is_in_str(p,in)) |
| 5341 | break; |
| 5342 | s.s = p; |
| 5343 | s.len = in->s+in->len-p; |
| 5344 | p0 = pv_parse_spec(&s, &e->spec); |
| 5345 | |
| 5346 | if(p0==NULL) { |
| 5347 | LM_ERR("parsing PV spec failed\n"); |
| 5348 | goto error; |
| 5349 | } |
no test coverage detected