| 882 | |
| 883 | |
| 884 | static int pv_get_contact_body(struct sip_msg *msg, pv_param_t *param, |
| 885 | pv_value_t *res) |
| 886 | { |
| 887 | struct hdr_field *ct_h; |
| 888 | contact_body_t *ct_b; |
| 889 | contact_t *ct; |
| 890 | int idx; |
| 891 | int idxf; |
| 892 | char *p; |
| 893 | |
| 894 | if(msg==NULL) |
| 895 | return -1; |
| 896 | |
| 897 | /* get all CONTACT headers */ |
| 898 | if(parse_headers(msg, HDR_EOH_F, 0)==-1 || msg->contact==NULL || |
| 899 | !msg->contact->body.s || msg->contact->body.len<=0) |
| 900 | { |
| 901 | LM_DBG("no contact header!\n"); |
| 902 | return pv_get_null(msg, param, res); |
| 903 | } |
| 904 | |
| 905 | ct_h = msg->contact; |
| 906 | if (parse_contact( ct_h )!=0) { |
| 907 | LM_ERR("failed to parse contact hdr\n"); |
| 908 | return -1; |
| 909 | } |
| 910 | ct_b = (contact_body_t*)ct_h->parsed; |
| 911 | if (ct_b==NULL) |
| 912 | return pv_get_null(msg, param, res); |
| 913 | ct = ct_b->contacts; |
| 914 | |
| 915 | /* get the index */ |
| 916 | if(pv_get_spec_index(msg, param, &idx, &idxf)!=0) { |
| 917 | LM_ERR("invalid index\n"); |
| 918 | return -1; |
| 919 | } |
| 920 | |
| 921 | if( idxf!=PV_IDX_ALL && idx==0) { |
| 922 | /* no index specified -> return the first contact body */ |
| 923 | return get_contact_body_field( res , ct_h, ct, ¶m->pvn); |
| 924 | } |
| 925 | |
| 926 | if(idxf==PV_IDX_ALL) { |
| 927 | /* return all contact bodies */ |
| 928 | p = pv_local_buf; |
| 929 | do { |
| 930 | if(p!=pv_local_buf) { |
| 931 | if (p-pv_local_buf+PV_FIELD_DELIM_LEN+1>PV_LOCAL_BUF_SIZE){ |
| 932 | LM_ERR("local buffer length exceeded\n"); |
| 933 | return pv_get_null(msg, param, res); |
| 934 | } |
| 935 | memcpy(p, PV_FIELD_DELIM, PV_FIELD_DELIM_LEN); |
| 936 | p += PV_FIELD_DELIM_LEN; |
| 937 | } |
| 938 | |
| 939 | get_contact_body_field( res , ct_h, ct, ¶m->pvn); |
| 940 | if (p-pv_local_buf+res->rs.len+1>PV_LOCAL_BUF_SIZE) { |
| 941 | LM_ERR("local buffer length exceeded!\n"); |
nothing calls this directly
no test coverage detected