int eXosip_subscribe_set_route(struct eXosip_t *excontext, int did, const char* new_route_str) { eXosip_dialog_t *jd = NULL; eXosip_subscribe_t *js = NULL; int i; osip_route_t* new_route = NULL; osip_uri_t* new_route_uri = NULL; osip_route_t *old_route_uri = NULL; osip_route_t *route = NULL; int n = 0; char* tmp = NULL; if (did <= 0) return OSIP_BADPARAMETER; /* find dialog by did */ if (did > 0) { _eXosip_subscribe_dialog_find (excontext, did, &js, &jd); } if (jd == NULL) { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: No subscribe here?\n")); return OSIP_NOTFOUND; } /* parse the given new route-URI */ osip_route_init (&new_route); i = osip_route_parse (new_route, new_route_str); if (i != 0) { return OSIP_BADPARAMETER; } new_route_uri = new_route->url; /* compare with the old entry (first list-item) */ old_route_uri = osip_list_get (&jd->d_dialog->route_set, 0); /* replace entries */ n = osip_list_size (&jd->d_dialog->route_set); /* start with the last list-item */ if (n == 0) { // no Record-Route has been used if ((jd->d_dialog->remote_contact_uri != NULL) && (jd->d_dialog->remote_contact_uri->url != NULL)) { /* replace hostname */ if (jd->d_dialog->remote_contact_uri->url->host != NULL) { osip_free (jd->d_dialog->remote_contact_uri->url->host); jd->d_dialog->remote_contact_uri->url->host = NULL; } if (new_route_uri->host != NULL) { jd->d_dialog->remote_contact_uri->url->host = osip_strdup (new_route_uri->host); } /* replace port */ if (jd->d_dialog->remote_contact_uri->url->port != NULL) { osip_free (jd->d_dialog->remote_contact_uri->url->port); jd->d_dialog->remote_contact_uri->url->port = NULL; } if (new_route_uri->port != NULL) { jd->d_dialog->remote_contact_uri->url->port = osip_strdup (new_route_uri->port); } /* replace username */ if (jd->d_dialog->remote_contact_uri->url->username != NULL) { osip_free (jd->d_dialog->remote_contact_uri->url->username); jd->d_dialog->remote_contact_uri->url->username = NULL; } if (new_route_uri->username != NULL) { jd->d_dialog->remote_contact_uri->url->username = osip_strdup (new_route_uri->username); } } } else { // Record-Route has been used while (n > 0) { route = (osip_route_t *) osip_list_get (&jd->d_dialog->route_set, n-1); if ((route != NULL) && (route->url != NULL) && (route->url->host != NULL) && (old_route_uri->url->host != NULL)) { if ((n == 1) || /* always replace the first list-item */ ((n > 1) && (osip_strcasecmp (route->url->host, old_route_uri->url->host) == 0) && /* matching hostname */ (((route->url->port == NULL) && (old_route_uri->url->port == NULL)) || (osip_strcasecmp (route->url->port, old_route_uri->url->port) == 0)))) /* matching port */ { /* replace hostname */ if (route->url->host != NULL) { osip_free (route->url->host); route->url->host = NULL; } if (new_route_uri->host != NULL) { route->url->host = osip_strdup (new_route_uri->host); } /* replace port */ if (route->url->port != NULL) { osip_free (route->url->port); route->url->port = NULL; } if (new_route_uri->port != NULL) { route->url->port = osip_strdup (new_route_uri->port); } /* replace username */ if (route->url->username != NULL) { osip_free (route->url->username); route->url->username = NULL; } if (new_route_uri->username != NULL) { route->url->username = osip_strdup (new_route_uri->username); } } } n--; } } osip_uri_free (new_route_uri); return OSIP_SUCCESS; }