Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.673 diff -u -r1.673 chan_sip.c --- channels/chan_sip.c 15 Mar 2005 05:50:58 -0000 1.673 +++ channels/chan_sip.c 17 Mar 2005 13:18:06 -0000 @@ -3242,7 +3242,8 @@ /*--- respprep: Prepare SIP response packet ---*/ static int respprep(struct sip_request *resp, struct sip_pvt *p, char *msg, struct sip_request *req) { - char newto[256] = "", *ot; + char newto[256] = ""; + char *ot; memset(resp, 0, sizeof(*resp)); init_resp(resp, msg, req); @@ -3298,6 +3299,7 @@ char newto[256]; char *c, *n; char *ot, *of; + int is_strict = 0; /* Strict routing flag */ memset(req, 0, sizeof(struct sip_request)); @@ -3312,17 +3314,23 @@ p->branch ^= rand(); build_via(p, p->via, sizeof(p->via)); } + + /* Check if next hop is a strict route */ + if (p->route && !ast_strlen_zero(p->route->hop) && strstr(p->route->hop,";lr") == NULL) { + is_strict = 1; /* Strict route indeed, sir */ + } + if (!strcasecmp(msg, "CANCEL")) { c = p->initreq.rlPart2; /* Use original URI */ } else if (!strcasecmp(msg, "ACK")) { /* Use URI from Contact: in 200 OK (if INVITE) (we only have the contacturi on INVITEs) */ if (!ast_strlen_zero(p->okcontacturi)) - c = p->okcontacturi; + c = is_strict ? p->route->hop : p->okcontacturi; else c = p->initreq.rlPart2; } else if (!ast_strlen_zero(p->okcontacturi)) { - c = p->okcontacturi; /* Use for BYE or REINVITE */ + c = is_strict ? p->route->hop : p->okcontacturi; /* Use for BYE or REINVITE */ } else if (!ast_strlen_zero(p->uri)) { c = p->uri; } else { @@ -3351,6 +3359,10 @@ add_header(req, "Via", p->via); if (p->route) { set_destination(p, p->route->hop); + if (is_strict) /* First route is already at URI */ + add_route(req, p->route->next); + else /* All routes must be present */ + add_route(req, p->route); add_route(req, p->route->next); }