diff -ruN asterisk-1.4.19.orig/channels/chan_sip.c asterisk-1.4.19/channels/chan_sip.c --- asterisk-1.4.19.orig/channels/chan_sip.c 2008-03-26 20:04:35.000000000 +0100 +++ asterisk-1.4.19/channels/chan_sip.c 2008-04-16 14:15:26.000000000 +0200 @@ -727,7 +727,7 @@ #define SIP_REALTIME (1 << 11) /*!< Flag for realtime users */ #define SIP_USECLIENTCODE (1 << 12) /*!< Trust X-ClientCode info message */ #define SIP_OUTGOING (1 << 13) /*!< Direction of the last transaction in this dialog */ -#define SIP_FREE_BIT (1 << 14) /*!< ---- */ +#define SIP_STRICTROUTING (1 << 14) /*!< Does this session use Strict SIP routing? */ #define SIP_DEFER_BYE_ON_TRANSFER (1 << 15) /*!< Do not hangup at first ast_hangup */ #define SIP_DTMF (3 << 16) /*!< DTMF Support: four settings, uses two bits */ #define SIP_DTMF_RFC2833 (0 << 16) /*!< DTMF Support: RTP DTMF - "rfc2833" */ @@ -5928,10 +5928,12 @@ } /* Check for strict or loose router */ - if (p->route && !ast_strlen_zero(p->route->hop) && strstr(p->route->hop,";lr") == NULL) { - is_strict = TRUE; - if (sipdebug) + if (ast_test_flag(&p->flags[0], SIP_STRICTROUTING)) { + if (option_debug) { ast_log(LOG_DEBUG, "Strict routing enforced for session %s\n", p->callid); + add_header(req, "X-Asterisk-routing", "Strict routing enforced on this session"); + } + is_strict = TRUE; } if (sipmethod == SIP_CANCEL) @@ -5962,7 +5964,10 @@ add_header(req, "Via", p->via); if (p->route) { set_destination(p, p->route->hop); - add_route(req, is_strict ? p->route->next : p->route); + if (ast_test_flag(&p->flags[0], SIP_STRICTROUTING)) + add_route(req, p->route->next); /* Start with second hop */ + else + add_route(req, p->route); /* Start with first hop */ } ot = get_header(orig, "To"); @@ -8304,16 +8309,8 @@ if (option_debug > 1) ast_log(LOG_DEBUG, "build_route: Contact hop: %s\n", contact); /* Look for <: delimited address */ - c = strchr(contact, '<'); - if (c) { - /* Take to > */ - ++c; - len = strcspn(c, ">") + 1; - } else { - /* No <> - just take the lot */ - c = contact; - len = strlen(contact) + 1; - } + c = get_in_brackets(contact); + len = strlen(contact) + 1; if ((thishop = ast_malloc(sizeof(*thishop) + len))) { /* ast_calloc is not needed because all fields are initialized in this block */ ast_copy_string(thishop->hop, c, len);