| 2210 | } |
| 2211 | |
| 2212 | static int pv_get_msg_branch_fields(struct sip_msg *msg, pv_param_t *param, |
| 2213 | pv_value_t *res, int field) |
| 2214 | { |
| 2215 | int size; |
| 2216 | int idx; |
| 2217 | int idxf; |
| 2218 | char *p; |
| 2219 | |
| 2220 | if(msg==NULL || res==NULL) |
| 2221 | return -1; |
| 2222 | |
| 2223 | size = get_dset_size() + 1; |
| 2224 | |
| 2225 | /* get the index */ |
| 2226 | if(pv_get_spec_index(msg, param, &idx, &idxf)!=0) { |
| 2227 | LM_ERR("invalid index\n"); |
| 2228 | return -1; |
| 2229 | } |
| 2230 | |
| 2231 | if (idxf==0 && idx==0) { |
| 2232 | /* no index specified -> operate with the last branch */ |
| 2233 | return get_msg_branch_field( msg, size-1 , field, res); |
| 2234 | } |
| 2235 | |
| 2236 | if(idxf==PV_IDX_ALL) { |
| 2237 | /* return all branches */ |
| 2238 | p = pv_local_buf; |
| 2239 | idx = 0; |
| 2240 | |
| 2241 | while ( idx<size ) { |
| 2242 | |
| 2243 | get_msg_branch_field( msg, idx, field, res); |
| 2244 | |
| 2245 | if ( pv_local_buf + PV_LOCAL_BUF_SIZE <= |
| 2246 | p + res->rs.len + PV_FIELD_DELIM_LEN ) { |
| 2247 | LM_ERR("local buffer length exceeded\n"); |
| 2248 | return pv_get_null(msg, param, res); |
| 2249 | } |
| 2250 | |
| 2251 | if (idx) { |
| 2252 | memcpy(p, PV_FIELD_DELIM, PV_FIELD_DELIM_LEN); |
| 2253 | p += PV_FIELD_DELIM_LEN; |
| 2254 | } |
| 2255 | |
| 2256 | memcpy(p, res->rs.s, res->rs.len); |
| 2257 | p += res->rs.len; |
| 2258 | idx++; |
| 2259 | } |
| 2260 | |
| 2261 | res->rs.s = pv_local_buf; |
| 2262 | res->rs.len = p - pv_local_buf; |
| 2263 | res->flags = PV_VAL_STR; |
| 2264 | return 0; |
| 2265 | } |
| 2266 | |
| 2267 | /* numerical index */ |
| 2268 | if (idx<0) { |
| 2269 | /* index from the end */ |
no test coverage detected