/**@ingroup sip_route * * Fix and duplicate a route header (@Route, @RecordRoute, @Path, @ServiceRoute). * */ sip_route_t *sip_route_fixdup_as(su_home_t *home, msg_hclass_t *hc, sip_route_t const *route) { sip_route_t *copy = NULL; sip_route_t r[1], **rr; sip_route_init(r); /* Copy the record route as route */ for (rr = © route; route = route->r_next) { *r->r_url = *route->r_url; /* Fix broken (Record-)Routes without <> */ if (r->r_url->url_params == NULL && r->r_params && r->r_params[0] && (r->r_params[0][0] == 'l' || r->r_params[0][0] == 'L') && (r->r_params[0][1] == 'r' || r->r_params[0][1] == 'R') && (r->r_params[0][2] == '=' || r->r_params[0][2] == 0)) r->r_url->url_params = route->r_params[0], r->r_params = route->r_params + 1; else r->r_params = route->r_params; *rr = (sip_route_t *)msg_header_dup_as(home, hc, (msg_header_t *)r); if (!*rr) goto error; rr = &(*rr)->r_next; } return copy; error: msg_header_free_all(home, (msg_header_t *)copy); return NULL; }
/**@ingroup sip_route * * Reverse a route header (@Route, @RecordRoute, @Path, @ServiceRoute). */ sip_route_t *sip_route_reverse_as(su_home_t *home, msg_hclass_t *hc, sip_route_t const *route) { sip_route_t *reverse = NULL; sip_route_t r[1], *tmp; sip_route_init(r); r->r_common->h_class = hc; for (reverse = NULL; route; route = route->r_next) { *r->r_url = *route->r_url; /* Fix broken (Record-)Routes without <> */ if (r->r_url->url_params == NULL && r->r_params && r->r_params[0] && (r->r_params[0][0] == 'l' || r->r_params[0][0] == 'L') && (r->r_params[0][1] == 'r' || r->r_params[0][1] == 'R') && (r->r_params[0][2] == '=' || r->r_params[0][2] == 0)) r->r_url->url_params = route->r_params[0], r->r_params = route->r_params + 1; else r->r_params = route->r_params; tmp = (sip_route_t *)msg_header_dup_as(home, hc, (msg_header_t *)r); if (!tmp) goto error; tmp->r_next = reverse; reverse = tmp; } return reverse; error: msg_header_free_all(home, (msg_header_t *)reverse); return NULL; }
int nua_base_client_check_restart(nua_client_request_t *cr, int status, char const *phrase, sip_t const *sip) { nua_handle_t *nh = cr->cr_owner; nta_outgoing_t *orq; #if 0 if (status == 302 || status == 305) { sip_route_t r[1]; if (!can_redirect(sip->sip_contact, cr->cr_method)) return 0; switch (status) { case 302: if (nua_dialog_zap(nh, nh->nh_ds) == 0 && nua_client_set_target(cr, sip->sip_contact->m_url) >= 0) return nua_client_restart(cr, 100, "Redirected"); break; case 305: sip_route_init(r); *r->r_url = *sip->sip_contact->m_url; if (nua_dialog_zap(nh, nh->nh_ds) == 0 && sip_add_dup(cr->cr_msg, cr->cr_sip, (sip_header_t *)r) >= 0) return nua_client_restart(cr, 100, "Redirected via a proxy"); break; default: break; } } #endif if (status == 423) { unsigned my_expires = 0; if (cr->cr_sip->sip_expires) my_expires = cr->cr_sip->sip_expires->ex_delta; if (sip->sip_min_expires && sip->sip_min_expires->me_delta > my_expires) { sip_expires_t ex[1]; sip_expires_init(ex); ex->ex_delta = sip->sip_min_expires->me_delta; if (sip_add_dup(cr->cr_msg, NULL, (sip_header_t *)ex) < 0) return 0; return nua_client_restart(cr, 100, "Re-Negotiating Expiration"); } } if ((status == 401 && sip->sip_www_authenticate) || (status == 407 && sip->sip_proxy_authenticate)) { int server = 0, proxy = 0; if (sip->sip_www_authenticate) server = auc_challenge(&nh->nh_auth, nh->nh_home, sip->sip_www_authenticate, sip_authorization_class); if (sip->sip_proxy_authenticate) proxy = auc_challenge(&nh->nh_auth, nh->nh_home, sip->sip_proxy_authenticate, sip_proxy_authorization_class); if (server >= 0 && proxy >= 0) { int invalid = cr->cr_challenged && server + proxy == 0; cr->cr_challenged = 1; if (invalid) { /* Bad username/password */ SU_DEBUG_7(("nua(%p): bad credentials, clearing them\n", (void *)nh)); auc_clear_credentials(&nh->nh_auth, NULL, NULL); } else if (auc_has_authorization(&nh->nh_auth)) return nua_client_restart(cr, 100, "Request Authorized by Cache"); orq = cr->cr_orq, cr->cr_orq = NULL; cr->cr_waiting = cr->cr_wait_for_cred = 1; nua_client_report(cr, status, phrase, NULL, orq, NULL); nta_outgoing_destroy(orq); cr->cr_status = 0, cr->cr_phrase = NULL; nua_client_request_unref(cr); return 1; } } if (0 && 500 <= status && status < 600 && sip->sip_retry_after && sip->sip_retry_after->af_delta < 32) { su_timer_t *timer; char phrase[18]; /* Retry After XXXX\0 */ timer = su_timer_create(su_root_task(nh->nh_nua->nua_root), 0); if (su_timer_set_interval(timer, nua_client_restart_after, cr, sip->sip_retry_after->af_delta * 1000) < 0) { su_timer_destroy(timer); return 0; /* Too bad */ } cr->cr_timer = timer; /* This takes over cr reference from orq */ snprintf(phrase, sizeof phrase, "Retry After %u", (unsigned)sip->sip_retry_after->af_delta); orq = cr->cr_orq, cr->cr_orq = NULL; cr->cr_waiting = 1; nua_client_report(cr, 100, phrase, NULL, orq, NULL); nta_outgoing_destroy(orq); cr->cr_status = 0, cr->cr_phrase = NULL; return 1; } return 0; /* This was a final response that cannot be restarted. */ }