* Get host info from To header * param msg SIP message * param tohost Host part of To header * param bufsize Size of tohost buffer * return 0 success, -1 failure */
| 396 | * return 0 success, -1 failure |
| 397 | */ |
| 398 | int ospGetToHost( |
| 399 | struct sip_msg* msg, |
| 400 | char* tohost, |
| 401 | int bufsize) |
| 402 | { |
| 403 | struct to_body* to; |
| 404 | struct sip_uri uri; |
| 405 | int result = -1; |
| 406 | |
| 407 | if ((tohost != NULL) && (bufsize > 0)) { |
| 408 | tohost[0] = '\0'; |
| 409 | if (msg->to != NULL) { |
| 410 | if (parse_headers(msg, HDR_TO_F, 0) == 0) { |
| 411 | to = get_to(msg); |
| 412 | if (parse_uri(to->uri.s, to->uri.len, &uri) == 0) { |
| 413 | if (uri.port_no != 0) { |
| 414 | snprintf(tohost, bufsize, "%.*s:%d", uri.host.len, uri.host.s, uri.port_no); |
| 415 | } else { |
| 416 | ospCopyStrToBuffer(&uri.host, tohost, bufsize); |
| 417 | } |
| 418 | result = 0; |
| 419 | } else { |
| 420 | LM_ERR("failed to parse To uri\n"); |
| 421 | } |
| 422 | } else { |
| 423 | LM_ERR("failed to parse To header\n"); |
| 424 | } |
| 425 | } else { |
| 426 | LM_ERR("failed to find To header\n"); |
| 427 | } |
| 428 | } else { |
| 429 | LM_ERR("bad parameters to parse hsto info from To header\n"); |
| 430 | } |
| 431 | |
| 432 | return result; |
| 433 | } |
| 434 | |
| 435 | /* |
| 436 | * Get To header |
no test coverage detected