| 351 | |
| 352 | |
| 353 | int parse_authenticate_header(struct hdr_field *authenticate, |
| 354 | const struct match_auth_hf_desc *md, struct authenticate_body **picked_auth) |
| 355 | { |
| 356 | void **parsed; |
| 357 | struct authenticate_body *auth_body, *ret_auth; |
| 358 | int rc, prev_parsed; |
| 359 | |
| 360 | parsed = &(authenticate->parsed); |
| 361 | prev_parsed = (*parsed != NULL); |
| 362 | ret_auth = NULL; |
| 363 | |
| 364 | while(*parsed == NULL) |
| 365 | { |
| 366 | auth_body = pkg_malloc(sizeof(struct authenticate_body)); |
| 367 | if (auth_body == NULL) |
| 368 | { |
| 369 | LM_ERR("oom\n"); |
| 370 | *picked_auth = ret_auth; |
| 371 | return -1; |
| 372 | } |
| 373 | |
| 374 | rc = parse_authenticate_body(authenticate->body, auth_body); |
| 375 | if (rc < 0) { |
| 376 | pkg_free(auth_body); |
| 377 | *picked_auth = ret_auth; |
| 378 | return -1; |
| 379 | } |
| 380 | |
| 381 | if (rc == 0 && !ret_auth && |
| 382 | (md == NULL || md->matchf(auth_body, md))) |
| 383 | ret_auth = auth_body; |
| 384 | |
| 385 | *parsed = auth_body; |
| 386 | |
| 387 | authenticate = authenticate->sibling; |
| 388 | if (authenticate) |
| 389 | parsed = &(authenticate->parsed); |
| 390 | else |
| 391 | break; |
| 392 | } |
| 393 | if (prev_parsed) { |
| 394 | while (!ret_auth && authenticate) { |
| 395 | if (authenticate->parsed && |
| 396 | (md == NULL || md->matchf(authenticate->parsed, md))) |
| 397 | ret_auth = authenticate->parsed; |
| 398 | authenticate = authenticate->sibling; |
| 399 | } |
| 400 | } |
| 401 | *picked_auth = ret_auth; |
| 402 | |
| 403 | return ret_auth ? 0 : -1; |
| 404 | } |
| 405 | |
| 406 | /* |
| 407 | * This method is used to parse WWW-Authenticate header. |
no test coverage detected