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; } }
int main (int argc, char **argv) { FILE *routes_file; osip_route_t *route; char *a_route; char *dest; char *res; routes_file = fopen (argv[1], "r"); if (routes_file == NULL) { fprintf (stdout, "Failed to open %s file.\nUsage: troute routes.txt\n", argv[1]); exit (0); } a_route = (char *) osip_malloc (200); res = fgets (a_route, 200, routes_file); /* lines are under 200 */ while (res != NULL) { int errcode; /* remove the last '\n' before parsing */ strncpy (a_route + strlen (a_route) - 1, "\0", 1); if (0 != strncmp (a_route, "#", 1)) { /* allocate & init route */ osip_route_init (&route); printf ("=================================================\n"); printf ("ROUTE TO PARSE: |%s|\n", a_route); errcode = osip_route_parse (route, a_route); if (errcode != -1) { if (osip_route_to_str (route, &dest) != -1) { printf ("result: |%s|\n", dest); osip_free (dest); } } else printf ("Bad route format: %s\n", a_route); osip_route_free (route); printf ("=================================================\n"); } res = fgets (a_route, 200, routes_file); /* lines are under 200 */ } osip_free (a_route); return 0; }
/* 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; }