void linphone_proxy_config_set_route(LinphoneProxyConfig *obj, const char *route) { int err; osip_uri_param_t *lr_param=NULL; osip_route_t *rt=NULL; char *tmproute=NULL; if (route!=NULL && strlen(route)>0){ osip_route_init(&rt); err=osip_route_parse(rt,route); if (err<0){ ms_warning("Could not parse %s",route); osip_route_free(rt); return ; } if (obj->reg_route!=NULL) { ms_free(obj->reg_route); obj->reg_route=NULL; } /* check if the lr parameter is set , if not add it */ osip_uri_uparam_get_byname(rt->url, "lr", &lr_param); if (lr_param==NULL){ osip_uri_uparam_add(rt->url,osip_strdup("lr"),NULL); osip_route_to_str(rt,&tmproute); obj->reg_route=ms_strdup(tmproute); osip_free(tmproute); }else obj->reg_route=ms_strdup(route); }else{ if (obj->reg_route!=NULL) ms_free(obj->reg_route); obj->reg_route=NULL; } }
/* Set loose route if not set in route url */ char* uas_check_route(const char *url) { int err; osip_uri_param_t *lr_param=NULL; osip_route_t *rt=NULL; char *route=NULL; if (url!=NULL && strlen(url)>0) { osip_route_init(&rt); err=osip_route_parse(rt,url); if (err<0) { osip_route_free(rt); return NULL; } /* check if the lr parameter is set , if not add it */ osip_uri_uparam_get_byname(rt->url, "lr", &lr_param); if (lr_param==NULL) { osip_uri_uparam_add(rt->url,osip_strdup("lr"),NULL); osip_route_to_str(rt,&route); return route; } return xstr_clone(url); } return NULL; }
int generating_register (eXosip_reg_t * jreg, osip_message_t ** reg, char *transport, char *from, char *proxy, char *contact, int expires) { int i; char locip[65]; char firewall_ip[65]; char firewall_port[10]; if (eXosip.eXtl == NULL) return OSIP_NO_NETWORK; if (eXosip.eXtl->tl_get_masquerade_contact != NULL) { eXosip.eXtl->tl_get_masquerade_contact (firewall_ip, sizeof (firewall_ip), firewall_port, sizeof (firewall_port)); } i = generating_request_out_of_dialog (reg, "REGISTER", NULL, transport, from, proxy); if (i != 0) return i; memset (locip, '\0', sizeof (locip)); eXosip_guess_ip_for_via (eXosip.eXtl->proto_family, locip, 49); if (locip[0] == '\0') { OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_ERROR, NULL, "eXosip: no default interface defined\n")); osip_message_free (*reg); *reg = NULL; return OSIP_NO_NETWORK; } if (contact == NULL) { osip_contact_t *new_contact = NULL; osip_uri_t *new_contact_url = NULL; i = osip_contact_init (&new_contact); if (i == 0) i = osip_uri_init (&new_contact_url); new_contact->url = new_contact_url; if (i == 0 && (*reg)->from != NULL && (*reg)->from->url != NULL && (*reg)->from->url->username != NULL) { new_contact_url->username = osip_strdup ((*reg)->from->url->username); } if (i == 0 && (*reg)->from != NULL && (*reg)->from->url != NULL) { /* serach for correct ip */ if (firewall_ip[0] != '\0') { char *c_address = (*reg)->req_uri->host; struct addrinfo *addrinfo; struct __eXosip_sockaddr addr; i = eXosip_get_addrinfo (&addrinfo, (*reg)->req_uri->host, 5060, IPPROTO_UDP); if (i == 0) { memcpy (&addr, addrinfo->ai_addr, addrinfo->ai_addrlen); eXosip_freeaddrinfo (addrinfo); c_address = inet_ntoa (((struct sockaddr_in *) &addr)->sin_addr); OSIP_TRACE (osip_trace (__FILE__, __LINE__, OSIP_INFO1, NULL, "eXosip: here is the resolved destination host=%s\n", c_address)); } if (eXosip_is_public_address (c_address)) { new_contact_url->host = osip_strdup (firewall_ip); new_contact_url->port = osip_strdup (firewall_port); } else { new_contact_url->host = osip_strdup (locip); new_contact_url->port = osip_strdup (firewall_port); } } else { new_contact_url->host = osip_strdup (locip); new_contact_url->port = osip_strdup (firewall_port); } if (transport != NULL && osip_strcasecmp (transport, "UDP") != 0) { osip_uri_uparam_add (new_contact_url, osip_strdup ("transport"), osip_strdup (transport)); } if (jreg->r_line[0] != '\0') { osip_uri_uparam_add (new_contact_url, osip_strdup ("line"), osip_strdup (jreg->r_line)); } osip_list_add (&(*reg)->contacts, new_contact, -1); } } else { osip_message_set_contact (*reg, contact); } { char exp[10]; /* MUST never be ouside 1 and 3600 */ snprintf (exp, 9, "%i", expires); osip_message_set_expires (*reg, exp); } osip_message_set_content_length (*reg, "0"); return OSIP_SUCCESS; }
int osip_uri_parse_params (osip_uri_t * url, const char *params) { char *pname; char *pvalue; const char *comma; const char *equal; /* find '=' wich is the separator for one param */ /* find ';' wich is the separator for multiple params */ equal = next_separator (params + 1, '=', ';'); comma = strchr (params + 1, ';'); while (comma != NULL) { if (equal == NULL) { equal = comma; pvalue = NULL; } else { if (comma - equal < 2) return -1; pvalue = (char *) osip_malloc (comma - equal); if (pvalue == NULL) return -1; osip_strncpy (pvalue, equal + 1, comma - equal - 1); __osip_uri_unescape (pvalue); } if (equal - params < 2) { osip_free (pvalue); return -1; } pname = (char *) osip_malloc (equal - params); if (pname == NULL) { osip_free (pvalue); return -1; } osip_strncpy (pname, params + 1, equal - params - 1); __osip_uri_unescape (pname); osip_uri_uparam_add (url, pname, pvalue); params = comma; equal = next_separator (params + 1, '=', ';'); comma = strchr (params + 1, ';'); } /* this is the last header (comma==NULL) */ comma = params + strlen (params); if (equal == NULL) { equal = comma; /* at the end */ pvalue = NULL; } else { if (comma - equal < 2) return -1; pvalue = (char *) osip_malloc (comma - equal); if (pvalue == NULL) return -1; osip_strncpy (pvalue, equal + 1, comma - equal - 1); } if (equal - params < 2) { osip_free (pvalue); return -1; } pname = (char *) osip_malloc (equal - params); if (pname == NULL) { osip_free (pvalue); return -1; } osip_strncpy (pname, params + 1, equal - params - 1); osip_uri_uparam_add (url, pname, pvalue); return 0; }