static void caller_process_response_event(void *user_ctx, const belle_sip_response_event_t *event){ belle_sip_client_transaction_t* client_transaction = belle_sip_response_event_get_client_transaction(event); belle_sip_header_from_t* from=belle_sip_message_get_header_by_type(belle_sip_response_event_get_response(event),belle_sip_header_from_t); belle_sip_header_cseq_t* invite_cseq=belle_sip_message_get_header_by_type(belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(client_transaction)),belle_sip_header_cseq_t); belle_sip_request_t* ack; belle_sip_dialog_t* dialog; int status; if (!belle_sip_uri_equals(BELLE_SIP_URI(user_ctx),belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(from)))) { belle_sip_message("Message [%p] not for caller, skipping",belle_sip_response_event_get_response(event)); return; /*not for the caller*/ } status = belle_sip_response_get_status_code(belle_sip_response_event_get_response(event)); belle_sip_message("caller_process_response_event [%i]",status); if (BC_ASSERT_PTR_NOT_NULL(client_transaction)) { dialog = belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(client_transaction)); if (BC_ASSERT_PTR_NOT_NULL(dialog)) { BC_ASSERT_PTR_EQUAL(caller_dialog,dialog); if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_NULL) { BC_ASSERT_EQUAL(status,100, int, "%d"); } else if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_EARLY){ BC_ASSERT_EQUAL(status,180, int, "%d"); /*send 200ok from callee*/ belle_sip_server_transaction_send_response(inserv_transaction,ok_response); belle_sip_object_unref(ok_response); ok_response=NULL; } else if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_CONFIRMED) {
static void test_escaped_username(void) { belle_sip_uri_t* L_tmp; belle_sip_uri_t * L_uri = belle_sip_uri_parse("sip:toto%[email protected]"); char* l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_tmp = belle_sip_uri_parse(l_raw_uri); L_uri = BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp)); belle_sip_free(l_raw_uri); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri), "*****@*****.**"); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com"); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); }
static void test_escaped_parameter(void) { belle_sip_uri_t* L_tmp; belle_sip_uri_t * L_uri = belle_sip_uri_parse("sip:[email protected];pa%3Dram=aa%40bb:5060[];o%40"); char* l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_tmp = belle_sip_uri_parse(l_raw_uri); L_uri = BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp)); belle_sip_free(l_raw_uri); CU_ASSERT_STRING_EQUAL(belle_sip_parameters_get_parameter(BELLE_SIP_PARAMETERS(L_uri), "pa=ram"), "aa@bb:5060[]"); CU_ASSERT_TRUE(belle_sip_parameters_has_parameter(BELLE_SIP_PARAMETERS(L_uri), "o@")); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com"); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); }
static void testCOMPLEXURI(void) { belle_sip_uri_t* L_tmp; belle_sip_uri_t * L_uri = belle_sip_uri_parse("sip:[email protected]:5060;transport=tcp"); char* l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_tmp = belle_sip_uri_parse(l_raw_uri); L_uri = BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp)); belle_sip_free(l_raw_uri); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri), "toto"); CU_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 5060); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com"); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_transport_param(L_uri), "tcp"); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); }
static void testSIMPLEURI(void) { belle_sip_uri_t* L_tmp; belle_sip_uri_t* L_uri = belle_sip_uri_parse("sip:sip.titi.com"); char* l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_tmp = belle_sip_uri_parse(l_raw_uri); L_uri = BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp)); belle_sip_free(l_raw_uri); CU_ASSERT_PTR_NULL(belle_sip_uri_get_user(L_uri)); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "sip.titi.com"); CU_ASSERT_PTR_NULL(belle_sip_uri_get_transport_param(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); }
static void test_escaped_passwd(void) { belle_sip_uri_t* L_tmp; belle_sip_uri_t * L_uri = belle_sip_uri_parse("sips:%22jehan%22%20%3cjehan%40sip2.linphone.org:544%[email protected]"); char* l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_tmp = belle_sip_uri_parse(l_raw_uri); L_uri = BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp)); belle_sip_free(l_raw_uri); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri), "\"jehan\" <*****@*****.**"); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "sip.linphone.org"); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user_password(L_uri), "544>"); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); }
static void callee_process_request_event(void *user_ctx, const belle_sip_request_event_t *event) { belle_sip_dialog_t* dialog; belle_sip_response_t* ringing_response; belle_sip_header_content_type_t* content_type ; belle_sip_header_content_length_t* content_length; belle_sip_server_transaction_t* server_transaction = belle_sip_request_event_get_server_transaction(event); belle_sip_header_to_t* to=belle_sip_message_get_header_by_type(belle_sip_request_event_get_request(event),belle_sip_header_to_t); const char* method; if (!belle_sip_uri_equals(BELLE_SIP_URI(user_ctx),belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(to)))) { belle_sip_message("Message [%p] not for callee, skipping",belle_sip_request_event_get_request(event)); return; /*not for the callee*/ } method = belle_sip_request_get_method(belle_sip_request_event_get_request(event)); if (!server_transaction && strcmp(method,"ACK")!=0) { server_transaction= belle_sip_provider_create_server_transaction(prov,belle_sip_request_event_get_request(event)); } belle_sip_message("callee_process_request_event received [%s] message",method); dialog = belle_sip_request_event_get_dialog(event); if (!dialog ) { BC_ASSERT_STRING_EQUAL_FATAL("INVITE",method); dialog=belle_sip_provider_create_dialog(prov,BELLE_SIP_TRANSACTION(server_transaction)); callee_dialog=dialog; inserv_transaction=server_transaction; } if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_NULL) { ringing_response = belle_sip_response_create_from_request(belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(server_transaction)),180); /*prepare 200ok*/ ok_response = belle_sip_response_create_from_request(belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(server_transaction)),200); content_length= belle_sip_header_content_length_create(strlen(sdp)); content_type = belle_sip_header_content_type_create("application","sdp"); belle_sip_message_add_header(BELLE_SIP_MESSAGE(ok_response),BELLE_SIP_HEADER(content_type)); belle_sip_message_add_header(BELLE_SIP_MESSAGE(ok_response),BELLE_SIP_HEADER(content_length)); belle_sip_message_set_body(BELLE_SIP_MESSAGE(ok_response),sdp,strlen(sdp)); belle_sip_object_ref(ok_response); /*only send ringing*/ belle_sip_server_transaction_send_response(server_transaction,ringing_response); } else if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_CONFIRMED) { /*time to send bye*/ belle_sip_client_transaction_t* client_transaction = belle_sip_provider_create_client_transaction(prov,belle_sip_dialog_create_request(dialog,"BYE")); belle_sip_client_transaction_send_request(client_transaction); } else { belle_sip_warning("Unexpected state [%s] for dialog [%p]",belle_sip_dialog_state_to_string(belle_sip_dialog_get_state(dialog)),dialog ); } }
static void test_bad_request(void) { belle_sip_request_t *req; belle_sip_listener_t *bad_req_listener; belle_sip_client_transaction_t *t; belle_sip_header_address_t* route_address=belle_sip_header_address_create(NULL,belle_sip_uri_create(NULL,test_domain)); belle_sip_header_route_t* route; belle_sip_header_to_t* to = belle_sip_header_to_create2("sip:[email protected]",NULL); belle_sip_listener_callbacks_t cbs; belle_sip_listening_point_t *lp=belle_sip_provider_get_listening_point(prov,"TCP"); int bad_request_response_received=0; memset(&cbs,0,sizeof(cbs)); cbs.process_io_error=bad_req_process_io_error; cbs.process_response_event=bad_req_process_response_event; bad_req_listener = belle_sip_listener_create_from_callbacks(&cbs,&bad_request_response_received); req=belle_sip_request_create( BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_address_get_uri(route_address)))), "REGISTER", belle_sip_provider_create_call_id(prov), belle_sip_header_cseq_create(20,"REGISTER"), belle_sip_header_from_create2("sip:[email protected]",BELLE_SIP_RANDOM_TAG), to, belle_sip_header_via_new(), 70); belle_sip_uri_set_transport_param(belle_sip_header_address_get_uri(route_address),"tcp"); route = belle_sip_header_route_create(route_address); belle_sip_header_set_name(BELLE_SIP_HEADER(to),"BrokenHeader"); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_expires_create(600))); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(route)); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_contact_new())); belle_sip_provider_add_sip_listener(prov,bad_req_listener); t=belle_sip_provider_create_client_transaction(prov,req); belle_sip_client_transaction_send_request(t); belle_sip_stack_sleep(stack,3000); CU_ASSERT_TRUE(bad_request_response_received==1); belle_sip_provider_remove_sip_listener(prov,bad_req_listener); belle_sip_object_unref(bad_req_listener); belle_sip_listening_point_clean_channels(lp); }
static void caller_process_request_event(void *user_ctx, const belle_sip_request_event_t *event) { belle_sip_server_transaction_t* server_transaction; belle_sip_response_t* resp; belle_sip_dialog_t* dialog; belle_sip_header_to_t* to=belle_sip_message_get_header_by_type(belle_sip_request_event_get_request(event),belle_sip_header_to_t); if (!belle_sip_uri_equals(BELLE_SIP_URI(user_ctx),belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(to)))) { belle_sip_message("Message [%p] not for caller, skipping",belle_sip_request_event_get_request(event)); return; /*not for the caller*/ } belle_sip_message("caller_process_request_event received [%s] message",belle_sip_request_get_method(belle_sip_request_event_get_request(event))); server_transaction=belle_sip_provider_create_server_transaction(prov,belle_sip_request_event_get_request(event)); BC_ASSERT_STRING_EQUAL_FATAL("BYE",belle_sip_request_get_method(belle_sip_request_event_get_request(event))); dialog = belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(server_transaction)); BC_ASSERT_PTR_NOT_NULL_FATAL(dialog); BC_ASSERT_EQUAL(belle_sip_dialog_get_state(dialog) , BELLE_SIP_DIALOG_CONFIRMED, int, "%d"); resp=belle_sip_response_create_from_request(belle_sip_request_event_get_request(event),200); belle_sip_server_transaction_send_response(server_transaction,resp); }
static void testIPV6URI_base(const char* ip6) { belle_sip_uri_t* L_tmp; belle_sip_uri_t * L_uri; char* l_raw_uri; char uri[256]; snprintf(uri,sizeof(uri),"sip:toto@[%s]:5060;transport=tcp",ip6); L_uri = belle_sip_uri_parse(uri); l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_tmp = belle_sip_uri_parse(l_raw_uri); L_uri = BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp)); belle_sip_free(l_raw_uri); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri), "toto"); CU_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 5060); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri),ip6); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_transport_param(L_uri), "tcp"); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); }
static void test_uri_parameters (void) { char* l_raw_uri; belle_sip_uri_t* L_tmp; belle_sip_uri_t * L_uri = belle_sip_uri_parse("sip:192.168.0.1;ttl=12"); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_uri = belle_sip_uri_parse("sip:[email protected];lr;maddr=192.168.0.1;user=ip;ttl=140;transport=sctp;method=INVITE;rport=5060"); l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri)); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); L_tmp = belle_sip_uri_parse(l_raw_uri); L_uri = BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp))); belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp)); belle_sip_free(l_raw_uri); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_maddr_param(L_uri), "192.168.0.1"); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user_param(L_uri), "ip"); CU_ASSERT_EQUAL(belle_sip_uri_get_ttl_param(L_uri),140); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_transport_param(L_uri), "sctp"); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_method_param(L_uri), "INVITE"); belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri)); }