Sal * sal_init(){ belle_sip_listener_callbacks_t listener_callbacks; Sal * sal=ms_new0(Sal,1); sal->nat_helper_enabled=TRUE; sal->user_agent=belle_sip_header_user_agent_new(); #if defined(PACKAGE_NAME) && defined(LINPHONE_VERSION) belle_sip_header_user_agent_add_product(sal->user_agent, PACKAGE_NAME "/" LINPHONE_VERSION); #endif sal_append_stack_string_to_user_agent(sal); belle_sip_object_ref(sal->user_agent); belle_sip_set_log_handler(_belle_sip_log); sal->stack = belle_sip_stack_new(NULL); sal->prov = belle_sip_stack_create_provider(sal->stack,NULL); memset(&listener_callbacks,0,sizeof(listener_callbacks)); listener_callbacks.process_dialog_terminated=process_dialog_terminated; listener_callbacks.process_io_error=process_io_error; listener_callbacks.process_request_event=process_request_event; listener_callbacks.process_response_event=process_response_event; listener_callbacks.process_timeout=process_timeout; listener_callbacks.process_transaction_terminated=process_transaction_terminated; listener_callbacks.process_auth_requested=process_auth_requested; sal->listener=belle_sip_listener_create_from_callbacks(&listener_callbacks,sal); belle_sip_provider_add_sip_listener(sal->prov,sal->listener); sal->tls_verify=TRUE; sal->tls_verify_cn=TRUE; sal->refresher_retry_after=60000; /*default value in ms*/ return sal; }
int register_init(void) { belle_sip_listening_point_t *lp; stack=belle_sip_stack_new(NULL); lp=belle_sip_stack_create_listening_point(stack,"0.0.0.0",7060,"UDP"); prov=belle_sip_stack_create_provider(stack,lp); lp=belle_sip_stack_create_listening_point(stack,"0.0.0.0",7060,"TCP"); belle_sip_provider_add_listening_point(prov,lp); lp=belle_sip_stack_create_listening_point(stack,"0.0.0.0",7061,"TLS"); if (lp) { /* since test.linphone.org does not have proper certificates, don't verify anything*/ belle_sip_tls_listening_point_set_verify_exceptions(BELLE_SIP_TLS_LISTENING_POINT(lp),BELLE_SIP_TLS_LISTENING_POINT_BADCERT_ANY_REASON); if (belle_sip_tester_get_root_ca_path() != NULL) { belle_sip_tls_listening_point_set_root_ca(BELLE_SIP_TLS_LISTENING_POINT(lp), belle_sip_tester_get_root_ca_path()); } belle_sip_provider_add_listening_point(prov,lp); } listener_callbacks.process_dialog_terminated=process_dialog_terminated; listener_callbacks.process_io_error=process_io_error; listener_callbacks.process_request_event=process_request_event; listener_callbacks.process_response_event=process_response_event; listener_callbacks.process_timeout=process_timeout; listener_callbacks.process_transaction_terminated=process_transaction_terminated; listener_callbacks.process_auth_requested=process_auth_requested; listener_callbacks.listener_destroyed=NULL; listener=belle_sip_listener_create_from_callbacks(&listener_callbacks,NULL); return 0; }
static void testMalformedMandatoryField(void){ belle_sip_stack_t* stack = belle_sip_stack_new(NULL); belle_sip_listening_point_t* lp = belle_sip_stack_create_listening_point(stack, "127.0.0.1", LISTENING_POINT_PORT, "tcp"); belle_sip_provider_t* provider = belle_sip_provider_new(stack,lp); belle_sip_listener_callbacks_t listener_cbs = {0}; /* the MESSAGE message has no definition on which fields are required, which means we'll go into * * * */ const char* raw_message = "MESSAGE sip:[email protected]:5861;transport=tcp SIP/2.0\r\n" "Via: SIP/2.0/TCP " LISTENING_POINT_HOSTPORT ";branch=z9hG4bK5eca096a;rport\r\n" "Max-Forwards: 70\r\n" "From: \"MS TFT\" <sip:[email protected]>;tag=as2413a381\r\n" "To: <sip:[email protected]:5861;app-id=fr.lollol.phone.prod;pn-type=apple;pn-tok=azertyuiopqsdfghhjjkmlqoijfubieuzhqiluehcpoqidufqsdkjlcnuoishcvs;pn-msg-str=IM_MSG;pn-call-str=IC_MSG;pn-call-snd=ring.caf;pn-msg-snd=msg.caf;transport=tcp>;tag=\r\n" "Call-ID: [email protected]:5060\r\n" "CSeq: 103 MESSAGE\r\n" "User-Agent: Sip Server On Host (20130523_12h10)\r\n" "Content-Type: text/plain;charset=UTF-8\r\n" "Content-Length: 276\r\n" "\r\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" "<VDUCMediaConfig GId=\"1234567\" IdPosteType=\"123\"><Label>Salut Bilout TFT MS2</Label><MediaConfig GId=\"456\"><CommandCode Code=\"MediaCommand*\"><Label>Porte ouverte</Label></CommandCode><withVideo FPS=\"0.0\"/></MediaConfig></VDUCMediaConfig>\r\n" "\r\n"; belle_sip_message_t* message = belle_sip_message_parse(raw_message); belle_sip_listener_t* listener = NULL; int called_times = 0; listener_cbs.process_response_event = testMalformedFrom_process_response_cb; listener = belle_sip_listener_create_from_callbacks(&listener_cbs, &called_times); belle_sip_provider_add_sip_listener(provider, listener); belle_sip_object_ref(message); belle_sip_object_ref(message); /* double ref: originally the message is created with 0 refcount, and dispatch_message will unref() it.*/ belle_sip_provider_dispatch_message(provider, message); // we expect the stack to send a 400 error belle_sip_stack_sleep(stack,1000); CU_ASSERT_EQUAL(called_times,1); belle_sip_provider_remove_sip_listener(provider,listener); belle_sip_object_unref(listener); belle_sip_object_unref(provider); belle_sip_object_unref(stack); belle_sip_object_unref(message); }
static endpoint_t* create_endpoint(const char *ip, int port,const char* transport,belle_sip_listener_callbacks_t* listener_callbacks) { endpoint_t* endpoint = belle_sip_new0(endpoint_t); endpoint->stack=belle_sip_stack_new(NULL); endpoint->listener_callbacks=listener_callbacks; endpoint->lp=belle_sip_stack_create_listening_point(endpoint->stack,ip,port,transport); endpoint->connection_family=AF_INET; if (endpoint->lp) belle_sip_object_ref(endpoint->lp); endpoint->provider=belle_sip_stack_create_provider(endpoint->stack,endpoint->lp); belle_sip_provider_add_sip_listener(endpoint->provider,(endpoint->listener=belle_sip_listener_create_from_callbacks(endpoint->listener_callbacks,endpoint))); sprintf(endpoint->nonce,"%p",endpoint); /*initial nonce*/ endpoint->nonce_count=1; endpoint->register_count=3; return endpoint; }
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); }
Sal * sal_init(MSFactory *factory){ belle_sip_listener_callbacks_t listener_callbacks; Sal * sal=ms_new0(Sal,1); /*belle_sip_object_enable_marshal_check(TRUE);*/ sal->auto_contacts=TRUE; sal->factory = factory; /*first create the stack, which initializes the belle-sip object's pool for this thread*/ belle_sip_set_log_handler(_belle_sip_log); sal->stack = belle_sip_stack_new(NULL); sal->user_agent=belle_sip_header_user_agent_new(); #if defined(PACKAGE_NAME) && defined(LIBLINPHONE_VERSION) belle_sip_header_user_agent_add_product(sal->user_agent, PACKAGE_NAME "/" LIBLINPHONE_VERSION); #else belle_sip_header_user_agent_add_product(sal->user_agent, "Unknown"); #endif sal_append_stack_string_to_user_agent(sal); belle_sip_object_ref(sal->user_agent); sal->prov = belle_sip_stack_create_provider(sal->stack,NULL); sal_nat_helper_enable(sal,TRUE); memset(&listener_callbacks,0,sizeof(listener_callbacks)); listener_callbacks.process_dialog_terminated=process_dialog_terminated; listener_callbacks.process_io_error=process_io_error; listener_callbacks.process_request_event=process_request_event; listener_callbacks.process_response_event=process_response_event; listener_callbacks.process_timeout=process_timeout; listener_callbacks.process_transaction_terminated=process_transaction_terminated; listener_callbacks.process_auth_requested=process_auth_requested; sal->listener=belle_sip_listener_create_from_callbacks(&listener_callbacks,sal); belle_sip_provider_add_sip_listener(sal->prov,sal->listener); sal->tls_verify=TRUE; sal->tls_verify_cn=TRUE; sal->refresher_retry_after=60000; /*default value in ms*/ sal->enable_sip_update=TRUE; sal->pending_trans_checking=TRUE; sal->ssl_config = NULL; return sal; }
static void testMalformedFrom(void){ belle_sip_stack_t* stack = belle_sip_stack_new(NULL); belle_sip_listening_point_t* lp = belle_sip_stack_create_listening_point(stack, "127.0.0.1", LISTENING_POINT_PORT, "tcp"); belle_sip_provider_t* provider = belle_sip_provider_new(stack,lp); belle_sip_listener_callbacks_t listener_cbs = {0}; const char* raw_message = "INVITE sip:[email protected] SIP/2.0\r\n" "Via: SIP/2.0/TCP " LISTENING_POINT_HOSTPORT ";branch=z9hG4bK-edx-U_1zoIkaq72GJPqpSmDpJQ-ouBelFuLODzf9oS5J9MeFUA;rport\r\n" "From: c\x8e test <sip:00_12_34_56_78_90@us2>;tag=klsk+kwDc\r\n" /** 'cŽ test' should be enclosed in double quotes */ "To: <sip:[email protected];transport=tcp>\r\n" "Contact: <sip:[email protected]>\r\n" "Call-ID: [email protected]\r\n" "Content-Type: application/sdp\r\n" "Content-Length: 389\r\n" "CSeq: 1 INVITE\r\n" "Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, INFO, UPDATE, REGISTER, MESSAGE, REFER, SUBSCRIBE, PRACK\r\n" "Accept: application/sdp, application/dtmf-relay\r\n" "Max-Forwards: 69\r\n" "\r\n" "v=0\r\n" "o=- 1826 1826 IN IP4 172.16.42.1\r\n" "s=VeriCall Edge\r\n" "c=IN IP4 172.16.42.1\r\n" "t=0 0\r\n" "m=audio 20506 RTP/AVP 0 8 13 101\r\n" "a=rtpmap:0 PCMU/8000\r\n" "a=rtpmap:8 PCMA/8000\r\n" "a=rtpmap:13 CN/8000\r\n" "a=rtpmap:101 telephone-event/8000\r\n" "a=fmtp:101 0-15\r\n" "m=video 24194 RTP/AVP 105 104\r\n" "a=sendonly\r\n" "a=rtpmap:105 H264/90000\r\n" "a=fmtp:105 packetization-mode=0\r\n" "a=rtpmap:104 H263-1998/90000\r\n" "a=fmtp:104 CIF=1;J=1\r\n"; belle_sip_message_t* message = belle_sip_message_parse(raw_message); belle_sip_listener_t* listener = NULL; int called_times = 0; listener_cbs.process_response_event = testMalformedFrom_process_response_cb; listener = belle_sip_listener_create_from_callbacks(&listener_cbs, &called_times); belle_sip_provider_add_sip_listener(provider, listener); belle_sip_object_ref(message); belle_sip_object_ref(message); /* double ref: originally the message is created with 0 refcount, and dispatch_message will unref() it.*/ belle_sip_provider_dispatch_message(provider, message); // we expect the stack to send a 400 error belle_sip_stack_sleep(stack,1000); CU_ASSERT_EQUAL(called_times,1); belle_sip_provider_remove_sip_listener(provider,listener); belle_sip_object_unref(listener); belle_sip_object_unref(provider); belle_sip_object_unref(stack); belle_sip_object_unref(message); }
static void reuse_nonce(void) { belle_sip_request_t *register_request; int initial_auth_context_count=belle_sip_list_size(prov->auth_contexts); register_request=register_user_at_domain(stack, prov, "tcp",1,"marie","sip.linphone.org",NULL); if (register_request) { char * first_nonce_used; belle_sip_header_authorization_t * h = NULL; belle_sip_request_t *message_request; listener_callbacks.process_dialog_terminated=process_dialog_terminated; listener_callbacks.process_io_error=process_io_error; listener_callbacks.process_request_event=process_request_event; listener_callbacks.process_response_event=process_message_response_event; listener_callbacks.process_timeout=process_timeout; listener_callbacks.process_transaction_terminated=process_transaction_terminated; listener_callbacks.process_auth_requested=process_auth_requested; listener_callbacks.listener_destroyed=NULL; listener=belle_sip_listener_create_from_callbacks(&listener_callbacks,NULL); belle_sip_provider_add_sip_listener(prov,BELLE_SIP_LISTENER(listener)); /*currently only one nonce should have been used (the one for the REGISTER)*/ CU_ASSERT_EQUAL(belle_sip_list_size(prov->auth_contexts), initial_auth_context_count+1); /*this should reuse previous nonce*/ message_request=send_message(register_request, auth_domain); CU_ASSERT_EQUAL(is_register_ok, 404); h = BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_message_get_header_by_type( BELLE_SIP_MESSAGE(message_request), belle_sip_header_proxy_authorization_t )); CU_ASSERT_PTR_NOT_NULL_FATAL(h); CU_ASSERT_EQUAL(2, belle_sip_header_authorization_get_nonce_count(h)); first_nonce_used = belle_sip_strdup(belle_sip_header_authorization_get_nonce(h)); belle_sip_object_unref(message_request); /*new nonce should be created when not using outbound proxy realm*/ message_request=send_message(register_request, NULL); CU_ASSERT_EQUAL(is_register_ok, 407); h = BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_message_get_header_by_type( BELLE_SIP_MESSAGE(message_request), belle_sip_header_proxy_authorization_t )); CU_ASSERT_PTR_NULL_FATAL(h); belle_sip_object_unref(message_request); /*new nonce should be created here too*/ message_request=send_message(register_request, "wrongrealm"); CU_ASSERT_EQUAL(is_register_ok, 407); h = BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_message_get_header_by_type( BELLE_SIP_MESSAGE(message_request), belle_sip_header_proxy_authorization_t )); CU_ASSERT_PTR_NULL_FATAL(h); belle_sip_object_unref(message_request); /*first nonce created should be reused*/ message_request=send_message(register_request, auth_domain); CU_ASSERT_EQUAL(is_register_ok, 404); h = BELLE_SIP_HEADER_AUTHORIZATION(belle_sip_message_get_header_by_type( BELLE_SIP_MESSAGE(message_request), belle_sip_header_proxy_authorization_t )); CU_ASSERT_PTR_NOT_NULL_FATAL(h); CU_ASSERT_EQUAL(3, belle_sip_header_authorization_get_nonce_count(h)); belle_sip_object_unref(message_request); belle_sip_provider_remove_sip_listener(prov,BELLE_SIP_LISTENER(listener)); unregister_user(stack,prov,register_request,1); belle_sip_object_unref(register_request); belle_sip_free(first_nonce_used); } }