| 3111 | } |
| 3112 | |
| 3113 | static int pv_get_hdr_name(struct sip_msg *msg, pv_param_t *param, pv_value_t *res) |
| 3114 | { |
| 3115 | int idx, idx_f; |
| 3116 | struct hdr_field *hf; |
| 3117 | char *p; |
| 3118 | int n; |
| 3119 | |
| 3120 | if(msg==NULL || res==NULL || param==NULL) |
| 3121 | return -1; |
| 3122 | |
| 3123 | /* get the index */ |
| 3124 | if (pv_get_spec_index(msg, param, &idx, &idx_f) != 0) { |
| 3125 | LM_ERR("invalid index\n"); |
| 3126 | return -1; |
| 3127 | } |
| 3128 | |
| 3129 | /* make sure we have parsed all the headers */ |
| 3130 | if (parse_headers(msg, HDR_EOH_F, 0) <0 ) { |
| 3131 | LM_ERR("error parsing headers\n"); |
| 3132 | return pv_get_null(msg, param, res); |
| 3133 | } |
| 3134 | |
| 3135 | res->flags = PV_VAL_STR; |
| 3136 | |
| 3137 | if (idx_f == PV_IDX_ALL) { |
| 3138 | /* return all header names, separated by ',' */ |
| 3139 | |
| 3140 | p = pv_local_buf; |
| 3141 | hf = msg->headers; |
| 3142 | do { |
| 3143 | if (p != pv_local_buf) { |
| 3144 | if (p - pv_local_buf + PV_FIELD_DELIM_LEN + 1 > PV_LOCAL_BUF_SIZE) { |
| 3145 | LM_ERR("local buffer length exceeded\n"); |
| 3146 | return pv_get_null(msg, param, res); |
| 3147 | } |
| 3148 | memcpy(p, PV_FIELD_DELIM, PV_FIELD_DELIM_LEN); |
| 3149 | p += PV_FIELD_DELIM_LEN; |
| 3150 | } |
| 3151 | |
| 3152 | if (p - pv_local_buf + hf->name.len + 1 > PV_LOCAL_BUF_SIZE) { |
| 3153 | LM_ERR("local buffer length exceeded!\n"); |
| 3154 | return pv_get_null(msg, param, res); |
| 3155 | } |
| 3156 | memcpy(p, hf->name.s, hf->name.len); |
| 3157 | p += hf->name.len; |
| 3158 | |
| 3159 | hf = hf->next; |
| 3160 | } while (hf); |
| 3161 | |
| 3162 | *p = 0; |
| 3163 | res->rs.s = pv_local_buf; |
| 3164 | res->rs.len = p - pv_local_buf; |
| 3165 | return 0; |
| 3166 | } |
| 3167 | |
| 3168 | if (idx < 0) { |
| 3169 | /* negative index, translate it to a positive one */ |
| 3170 |
nothing calls this directly
no test coverage detected