--- chan_sip.c 2005-05-19 23:14:41.000000000 -0400 +++ channels/chan_sip.c 2005-05-20 16:26:56.275571733 -0400 @@ -3516,7 +3516,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); @@ -3573,6 +3574,7 @@ char newto[256]; char *c, *n; char *ot, *of; + int is_strict = 0; /* Strict routing flag */ memset(req, 0, sizeof(struct sip_request)); @@ -3587,17 +3589,27 @@ 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 (sipmethod == SIP_CANCEL) { c = p->initreq.rlPart2; /* Use original URI */ } else if (sipmethod == SIP_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 = p->route->hop; + +/* if (!ast_strlen_zero(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, REFER 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 { @@ -3626,6 +3638,11 @@ add_header(req, "Via", p->via); if (p->route) { set_destination(p, p->route->hop); + + if (is_strict) + add_route(req, p->route->next); + else + add_route(req, p->route); add_route(req, p->route->next); }