static void test_file_path(void) { belle_generic_uri_t* source_uri = belle_generic_uri_parse("/index.html"); char* source_uri_raw = belle_sip_object_to_string(source_uri); belle_generic_uri_t* first_uri = belle_generic_uri_parse(source_uri_raw); belle_generic_uri_t* uri=BELLE_GENERIC_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(first_uri))); belle_sip_free(source_uri_raw); belle_sip_object_unref(source_uri); belle_sip_object_unref(first_uri); BC_ASSERT_PTR_NULL(belle_generic_uri_get_scheme(uri)); BC_ASSERT_PTR_NULL(belle_generic_uri_get_host(uri)); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(uri),"/index.html"); belle_sip_object_unref(uri); source_uri = belle_generic_uri_parse("file:///tmp/absolute-file"); BC_ASSERT_PTR_NOT_NULL(source_uri); if (source_uri!=NULL){ BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(source_uri),"file"); BC_ASSERT_PTR_NULL(belle_generic_uri_get_host(source_uri)); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(source_uri),"/tmp/absolute-file"); belle_sip_object_unref(source_uri); } /*this is INVALID*/ source_uri = belle_generic_uri_parse("file://./relative-file"); BC_ASSERT_PTR_NOT_NULL(source_uri); /* PATH segment always start by / */ source_uri = belle_generic_uri_parse("./relative-file"); BC_ASSERT_PTR_NULL(source_uri); if (source_uri!=NULL){ belle_sip_object_unref(source_uri); } }
static void test_basic_uri(void) { belle_generic_uri_t* source_uri = belle_generic_uri_parse("http://www.linphone.org/index.html"); char* source_uri_raw = belle_sip_object_to_string(source_uri); belle_generic_uri_t* first_uri = belle_generic_uri_parse(source_uri_raw); belle_generic_uri_t* uri=BELLE_GENERIC_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(first_uri))); belle_sip_free(source_uri_raw); belle_sip_object_unref(source_uri); belle_sip_object_unref(first_uri); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(uri),"http"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_host(uri),"www.linphone.org"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(uri),"/index.html"); belle_sip_object_unref(uri); source_uri = belle_generic_uri_parse("http://www.linphone.org/"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(source_uri),"/"); belle_sip_object_unref(source_uri); source_uri = belle_generic_uri_parse("http://www.linphone.org/a/b/c"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(source_uri),"/a/b/c"); BC_ASSERT_STRING_EQUAL("http://www.linphone.org/a/b/c",source_uri_raw = belle_sip_object_to_string(source_uri)); belle_sip_free(source_uri_raw); belle_sip_object_unref(source_uri); }
static void test_complex_uri(void) { belle_generic_uri_t* source_uri = belle_generic_uri_parse("ftp://*****:*****@ftp.linphone.fr:1234/url?sa=t&rct=j&url=http%3A%2F%2Ftranslate.google.fr"); char* source_uri_raw = belle_generic_uri_to_string(source_uri); belle_generic_uri_t* first_uri = belle_generic_uri_parse(source_uri_raw); belle_generic_uri_t* uri=BELLE_GENERIC_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(first_uri))); belle_sip_free(source_uri_raw); belle_sip_object_unref(source_uri); belle_sip_object_unref(first_uri); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(uri),"ftp"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_host(uri),"ftp.linphone.fr"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_user(uri),"toto"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_user_password(uri),"secret"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_host(uri),"ftp.linphone.fr"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(uri),"/url"); BC_ASSERT_EQUAL(belle_generic_uri_get_port(uri),1234,int,"%d"); BC_ASSERT_STRING_EQUAL(belle_generic_uri_get_query(uri),"sa=t&rct=j&url=http://translate.google.fr"); belle_sip_object_unref(uri); }
static void split_request_url(belle_http_request_t *req){ belle_generic_uri_t *uri=belle_http_request_get_uri(req); belle_generic_uri_t *new_uri; char *host_value; const char *path; if (belle_generic_uri_get_host(uri)==NULL && req->orig_uri!=NULL) return;/*already processed request uri*/ path=belle_generic_uri_get_path(uri); if (path==NULL) path="/"; new_uri=belle_generic_uri_new(); belle_generic_uri_set_path(new_uri,path); belle_generic_uri_set_query(new_uri, belle_generic_uri_get_query(uri)); if (belle_generic_uri_get_port(uri)>0) host_value=belle_sip_strdup_printf("%s:%i",belle_generic_uri_get_host(uri),belle_generic_uri_get_port(uri)); else host_value=belle_sip_strdup(belle_generic_uri_get_host(uri)); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),belle_sip_header_create("Host",host_value)); belle_sip_free(host_value); SET_OBJECT_PROPERTY(req,orig_uri,uri); belle_http_request_set_uri(req,new_uri); }
belle_http_request_t *belle_http_request_create(const char *method, belle_generic_uri_t *url, ...){ va_list vl; belle_http_request_t *obj; belle_sip_header_t *header; if (belle_generic_uri_get_host(url) == NULL) { belle_sip_error("%s: NULL host in url", __FUNCTION__); return NULL; } obj=belle_http_request_new(); obj->method=belle_sip_strdup(method); obj->req_uri=(belle_generic_uri_t*)belle_sip_object_ref(url); va_start(vl,url); while((header=va_arg(vl,belle_sip_header_t*))!=NULL){ belle_sip_message_add_header(BELLE_SIP_MESSAGE(obj),header); } va_end(vl); return obj; }
belle_sip_hop_t* belle_sip_hop_new_from_generic_uri(const belle_generic_uri_t *uri){ const char *host; const char * transport="TCP"; const char *scheme=belle_generic_uri_get_scheme(uri); int port=belle_generic_uri_get_port(uri); int well_known_port=0; host=belle_generic_uri_get_host(uri); if (strcasecmp(scheme,"http")==0) { transport="TCP"; well_known_port=80; }else if (strcasecmp(scheme,"https")==0) { transport="TLS"; well_known_port=443; } return belle_sip_hop_new(transport, host, host, port > 0 ? port : well_known_port); }