* Get next hop using the first Route not generated by this proxy or URI from the Request-Line * param msg SIP message * param nexthop Next hop IP * param bufsize Size of nexthop * return 0 success, -1 failure */
| 1549 | * return 0 success, -1 failure |
| 1550 | */ |
| 1551 | int ospGetNextHop( |
| 1552 | struct sip_msg* msg, |
| 1553 | char* nexthop, |
| 1554 | int bufsize) |
| 1555 | { |
| 1556 | struct hdr_field* hf; |
| 1557 | struct sip_uri uri; |
| 1558 | rr_t* rt; |
| 1559 | int found = 0; |
| 1560 | int result = -1; |
| 1561 | |
| 1562 | if ((nexthop != NULL) && (bufsize > 0)) { |
| 1563 | result = 0; |
| 1564 | |
| 1565 | for (hf = msg->headers; hf; hf = hf->next) { |
| 1566 | if (hf->type == HDR_ROUTE_T) { |
| 1567 | for (rt = (rr_t*)hf->parsed; rt; rt = rt->next) { |
| 1568 | if (parse_uri(rt->nameaddr.uri.s, rt->nameaddr.uri.len, &uri) == 0) { |
| 1569 | LM_DBG("host '%.*s' port '%d'\n", uri.host.len, uri.host.s, uri.port_no); |
| 1570 | |
| 1571 | if (check_self(&uri.host, uri.port_no ? uri.port_no : SIP_PORT, PROTO_NONE) != 1) { |
| 1572 | LM_DBG("it is NOT me, FOUND!\n"); |
| 1573 | |
| 1574 | if (uri.port_no != 0) { |
| 1575 | snprintf(nexthop, bufsize, "%.*s:%d", uri.host.len, uri.host.s, uri.port_no); |
| 1576 | } else { |
| 1577 | ospCopyStrToBuffer(&uri.host, nexthop, bufsize); |
| 1578 | } |
| 1579 | found = 1; |
| 1580 | break; |
| 1581 | } else { |
| 1582 | LM_DBG("it IS me, keep looking\n"); |
| 1583 | } |
| 1584 | } else { |
| 1585 | LM_ERR("failed to parse route uri '%.*s'\n", |
| 1586 | rt->nameaddr.uri.len, |
| 1587 | rt->nameaddr.uri.s); |
| 1588 | } |
| 1589 | } |
| 1590 | if (found == 1) { |
| 1591 | break; |
| 1592 | } |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | if (!found) { |
| 1597 | LM_DBG("using the Request-Line instead host '%.*s' port '%d'\n", |
| 1598 | msg->parsed_uri.host.len, |
| 1599 | msg->parsed_uri.host.s, |
| 1600 | msg->parsed_uri.port_no); |
| 1601 | |
| 1602 | if (msg->parsed_uri.port_no != 0) { |
| 1603 | snprintf(nexthop, bufsize, "%.*s:%d", msg->parsed_uri.host.len, msg->parsed_uri.host.s, msg->parsed_uri.port_no); |
| 1604 | } else { |
| 1605 | ospCopyStrToBuffer(&msg->parsed_uri.host, nexthop, bufsize); |
| 1606 | } |
| 1607 | found = 1; |
| 1608 | } |
no test coverage detected