* Get user part from P-Charge-Info header * param msg SIP message * param user User part of P-Charge-Info header * param bufsize Size of fromuser buffer * return 0 success, 1 without P-Charge-Info, -1 failure */
| 665 | * return 0 success, 1 without P-Charge-Info, -1 failure |
| 666 | */ |
| 667 | int ospGetPciUser( |
| 668 | struct sip_msg* msg, |
| 669 | char* pciuser, |
| 670 | int bufsize) |
| 671 | { |
| 672 | struct to_body body; |
| 673 | struct to_body* pci = NULL; |
| 674 | struct hdr_field* hf; |
| 675 | struct sip_uri uri; |
| 676 | int result = -1; |
| 677 | |
| 678 | if ((pciuser != NULL) && (bufsize > 0)) { |
| 679 | pciuser[0] = '\0'; |
| 680 | if (parse_headers(msg, HDR_EOH_F, 0) == 0) { |
| 681 | hf = get_header_by_name(msg, PCHARGEINFO, strlen(PCHARGEINFO)); |
| 682 | if (hf) { |
| 683 | if (!(pci = hf->parsed)) { |
| 684 | pci = &body; |
| 685 | parse_to(hf->body.s, hf->body.s + hf->body.len + 1, pci); |
| 686 | } |
| 687 | if (pci->error != PARSE_ERROR) { |
| 688 | if (parse_uri(pci->uri.s, pci->uri.len, &uri) == 0) { |
| 689 | ospCopyStrToBuffer(&uri.user, pciuser, bufsize); |
| 690 | ospSkipUserParam(pciuser); |
| 691 | result = 0; |
| 692 | } else { |
| 693 | LM_ERR("failed to parse P-Charge-Info uri\n"); |
| 694 | } |
| 695 | if (pci == &body) { |
| 696 | free_to_params(pci); |
| 697 | } |
| 698 | } else { |
| 699 | LM_ERR("bad P-Charge-Info header\n"); |
| 700 | } |
| 701 | } else { |
| 702 | LM_DBG("without P-Charge-Info header\n"); |
| 703 | result = 1; |
| 704 | } |
| 705 | } else { |
| 706 | LM_ERR("failed to parse message\n"); |
| 707 | } |
| 708 | } else { |
| 709 | LM_ERR("bad parameters to parse user part from PAI\n"); |
| 710 | } |
| 711 | |
| 712 | return result; |
| 713 | } |
| 714 | |
| 715 | /* |
| 716 | * Get host part from P-Charge-Info header |
no test coverage detected