| 248 | |
| 249 | |
| 250 | static inline int set_sl_branch(struct sip_msg* msg) |
| 251 | { |
| 252 | struct hdr_field *h_via; |
| 253 | struct via_body *b_via; |
| 254 | str *branch; |
| 255 | int via_parsed; |
| 256 | char b_md5[MD5_LEN]; |
| 257 | |
| 258 | via_parsed = 0; |
| 259 | branch = 0; |
| 260 | |
| 261 | /* first VIA header must be parsed */ |
| 262 | for( h_via=msg->h_via1 ; h_via ; h_via=h_via->sibling ) { |
| 263 | |
| 264 | b_via = (struct via_body*)h_via->parsed; |
| 265 | for( ; b_via ; b_via=b_via->next ) { |
| 266 | /* check if there is any valid branch param */ |
| 267 | if (b_via->branch==0 || b_via->branch->value.s==0 |
| 268 | || b_via->branch->value.len==0 ) |
| 269 | continue; |
| 270 | branch = &b_via->branch->value; |
| 271 | /* check if the branch param has the magic cookie */ |
| 272 | if (branch->len <= (int)MCOOKIE_LEN |
| 273 | || memcmp( branch->s, MCOOKIE, MCOOKIE_LEN)!=0 ) |
| 274 | continue; |
| 275 | /* found a statefull branch -> use it */ |
| 276 | goto found; |
| 277 | } |
| 278 | |
| 279 | if (!via_parsed) { |
| 280 | if ( parse_headers(msg,HDR_EOH_F,0)<0 ) { |
| 281 | LM_ERR("failed to parse all hdrs\n"); |
| 282 | return -1; |
| 283 | } |
| 284 | via_parsed = 1; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | /* no statefull branch :(.. -> use the branch from the last via */ |
| 289 | found: |
| 290 | if (branch==NULL) { |
| 291 | /* no branch found :(.. -> try to use the From TAG param as |
| 292 | * a value to seed the MD5 - the From TAG is per call, so it gives |
| 293 | * a bit of uniqueness; if this is empty, as a last resort, use the |
| 294 | * FROM URI (it cannot mis) */ |
| 295 | if ( parse_from_header(msg)!=0 ) |
| 296 | { |
| 297 | LM_ERR("failed to extract FROM header\n"); |
| 298 | return -1; |
| 299 | } |
| 300 | if ( get_from(msg)->tag_value.len ) |
| 301 | branch = &get_from(msg)->tag_value; |
| 302 | else |
| 303 | branch = &get_from(msg)->uri; |
| 304 | } |
| 305 | |
| 306 | /* make an MD5 over the found branch, to ensure a controlable |
| 307 | * length of the resulting branch */ |
no test coverage detected