static void testInviteMessage(void) { const char* raw_message = "INVITE sip:[email protected] SIP/2.0\r\n"\ "Via: SIP/2.0/UDP 10.23.17.117:22600;branch=z9hG4bK-d8754z-4d7620d2feccbfac-1---d8754z-;rport=4820;received=202.165.193.129\r\n"\ "Max-Forwards: 70\r\n"\ "Contact: <sip:[email protected]:4820>\r\n"\ "To: \"becheong\" <sip:[email protected]>\r\n"\ "From: \"Benjamin Cheong\" <sip:[email protected]>;tag=7326e5f6\r\n"\ "Call-ID: Y2NlNzg0ODc0ZGIxODU1MWI5MzhkNDVkNDZhOTQ4YWU.\r\n"\ "CSeq: 1 INVITE\r\n"\ "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO\r\n"\ "c: application/sdp\r\n"\ "Supported: replaces\r\n"\ "Authorization: Digest username=\"003332176\", realm=\"sip.ovh.net\", nonce=\"24212965507cde726e8bc37e04686459\", uri=\"sip:sip.ovh.net\", response=\"896e786e9c0525ca3085322c7f1bce7b\", algorithm=MD5, opaque=\"241b9fb347752f2\"\r\n"\ "User-Agent: X-Lite 4 release 4.0 stamp 58832\r\n"\ "Content-Length: 230\r\n\r\n"; belle_sip_request_t* request; belle_sip_message_t* message = belle_sip_message_parse(raw_message); char* encoded_message = belle_sip_object_to_string(BELLE_SIP_OBJECT(message)); belle_sip_object_unref(BELLE_SIP_OBJECT(message)); message = belle_sip_message_parse(encoded_message); request = BELLE_SIP_REQUEST(message); CU_ASSERT_STRING_EQUAL(belle_sip_request_get_method(request),"INVITE"); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Contact")); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Authorization")); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Content-Type")); check_uri_and_headers(message); belle_sip_object_unref(message); belle_sip_free(encoded_message); }
static void testRegisterMessage(void) { const char* raw_message = "REGISTER sip:192.168.0.20 SIP/2.0\r\n"\ "v: SIP/2.0/UDP 192.168.1.8:5062;rport;branch=z9hG4bK1439638806\r\n"\ "f: <sip:[email protected]>;tag=465687829\r\n"\ "t: <sip:[email protected]>\r\n"\ "i: 1053183492\r\n"\ "CSeq: 1 REGISTER\r\n"\ "m: <sip:[email protected]:5062>\r\n"\ "Max-Forwards: 70\r\n"\ "User-Agent: Linphone/3.3.99.10 (eXosip2/3.3.0)\r\n"\ "Expires: 3600\r\n"\ "Proxy-Authorization: Digest username=\"8117396\", realm=\"Realm\", nonce=\"MTMwNDAwMjIxMjA4NzVkODY4ZmZhODMzMzU4ZDJkOTA1NzM2NTQ2NDZlNmIz"\ ", uri=\"sip:linphone.net\", response=\"eed376ff7c963441255ec66594e470e7\", algorithm=MD5, cnonce=\"0a4f113b\", qop=auth, nc=00000001\r\n"\ "l: 0\r\n\r\n"; belle_sip_request_t* request; belle_sip_message_t* message = belle_sip_message_parse(raw_message); char* encoded_message = belle_sip_object_to_string(BELLE_SIP_OBJECT(message)); belle_sip_object_unref(BELLE_SIP_OBJECT(message)); message = belle_sip_message_parse(encoded_message); request = BELLE_SIP_REQUEST(message); CU_ASSERT_STRING_EQUAL(belle_sip_request_get_method(request),"REGISTER"); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Expires")); CU_ASSERT_PTR_NOT_NULL(BELLE_SIP_HEADER_EXPIRES(belle_sip_message_get_header(message,"Expires"))); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Proxy-Authorization")); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Contact")); check_uri_and_headers(message); belle_sip_free(encoded_message); belle_sip_object_unref(message); }
static void testGenericMessage(void) { const char* raw_message = "SIP/2.0 180 Ringing\r\n" "Via: SIP/2.0/UDP 192.168.1.73:5060;branch=z9hG4bK.hhdJx4~kD;rport\r\n" "Record-Route: <sip:91.121.209.194;lr>\r\n" "Record-Route: <sip:[email protected]:5060;lr>\r\n" "From: <sip:[email protected]>;tag=5DuaoDRru\r\n" "To: <sip:[email protected]>;tag=PelIhu0\r\n" "Call-ID: e-2Q~fxwNs\r\n" "CSeq: 21 INVITE\r\n" "user-agent: Linphone/3.6.99 (belle-sip/1.2.4)\r\n" "supported: replaces\r\n" "supported: outbound\r\n" "Content-Length: 0\r\n" "\r\n"; belle_sip_response_t* response; belle_sip_message_t* message = belle_sip_message_parse(raw_message); char* encoded_message = belle_sip_object_to_string(BELLE_SIP_OBJECT(message)); belle_sip_object_unref(BELLE_SIP_OBJECT(message)); message = belle_sip_message_parse(encoded_message); response = BELLE_SIP_RESPONSE(message); CU_ASSERT_EQUAL(belle_sip_response_get_status_code(response),180); /* CU_ASSERT_STRING_EQUAL(belle_sip_response_get_reason_phrase(response),"Unauthorized"); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"WWW-Authenticate")); check_uri_and_headers(message);*/ belle_sip_object_unref(message); belle_sip_free(encoded_message); }
static void test_extract_source(void) { const char * invite_1="INVITE sip:[email protected]:50343;transport=tcp;line=f18e0009dd6cc43 SIP/2.0\r\n" "Via: SIP/2.0/TCP 37.59.129.73;branch=z9hG4bK.SKvK9U327e8mU68XUv5rt144pg\r\n" "Via: SIP/2.0/UDP 192.168.1.12:15060;rport=15060;branch=z9hG4bK1596944937;received=81.56.113.2\r\n" "Record-Route: <sip:37.59.129.73;lr;transport=tcp>\r\n" "Record-Route: <sip:37.59.129.73;lr>\r\n" "Max-Forwards: 70\r\n" "From: <sip:[email protected]>;tag=711138653\r\n" "To: <sip:[email protected]>\r\n" "Call-ID: 977107319\r\n" "CSeq: 21 INVITE\r\n" "Contact: <sip:[email protected]:15060>\r\n" "Subject: Phone call\r\n" "User-Agent: Linphone/3.5.2 (eXosip2/3.6.0)\r\n" "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO\r\n" "Content-Type: application/sdp\r\n"\ "Content-Length: 230\r\n\r\n"; const char * invite_2="INVITE sip:[email protected]:50343;transport=tcp;line=f18e0009dd6cc43 SIP/2.0\r\n" "Via: SIP/2.0/UDP 192.168.1.12:15060;rport=15060;branch=z9hG4bK1596944937;received=81.56.113.2\r\n" "Via: SIP/2.0/TCP 37.59.129.73;branch=z9hG4bK.SKvK9U327e8mU68XUv5rt144pg\r\n" "Record-Route: <sip:37.59.129.73;lr;transport=tcp>\r\n" "Record-Route: <sip:37.59.129.73;lr>\r\n" "Max-Forwards: 70\r\n" "From: <sip:[email protected]>;tag=711138653\r\n" "To: <sip:[email protected]>\r\n" "Call-ID: 977107319\r\n" "CSeq: 21 INVITE\r\n" "Contact: <sip:[email protected]:15060>\r\n" "Subject: Phone call\r\n" "User-Agent: Linphone/3.5.2 (eXosip2/3.6.0)\r\n" "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO\r\n" "Content-Length: 0\r\n\r\n"; belle_sip_message_t* message = belle_sip_message_parse(invite_1); belle_sip_request_t* request = BELLE_SIP_REQUEST(message); belle_sip_uri_t* source =belle_sip_request_extract_origin(request); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Content-type")); CU_ASSERT_PTR_NOT_NULL(source); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(source),"37.59.129.73"); CU_ASSERT_EQUAL(belle_sip_uri_get_port(source),0); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_transport_param(source),"tcp"); belle_sip_object_unref(message); message = belle_sip_message_parse(invite_2); request = BELLE_SIP_REQUEST(message); source =belle_sip_request_extract_origin(request); CU_ASSERT_PTR_NOT_NULL(source); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(source),"81.56.113.2"); CU_ASSERT_EQUAL(belle_sip_uri_get_port(source),15060); CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_transport_param(source),"udp"); belle_sip_object_unref(message); }
static void testHttp200Ok(void) { const char* raw_message = "HTTP/1.1 200 OK\r\n" "Date: Tue, 07 Jan 2014 09:28:43 GMT\r\n" "Server: Apache\r\n" "Last-Modified: Tue, 18 Aug 1998 20:19:11 GMT\r\n" "ETag: \"8982a60-14a17-335b3dcdcadc0\"\r\n" "Accept-Ranges: bytes\r\n" "Vary: Accept-Encoding\r\n" "Content-Encoding: gzip\r\n" "Content-Length: 6\r\n" "Keep-Alive: timeout=15, max=100\r\n" "Connection: Keep-Alive\r\n" "Content-Type: text/plain\r\n" "\r\n" "blabla"; char* marshaled_msg; belle_sip_message_t* msg = belle_sip_message_parse(raw_message); belle_http_response_t* http_response; belle_sip_header_extension_t* host_header; belle_sip_object_t* tmp; CU_ASSERT_PTR_NOT_NULL_FATAL(msg); marshaled_msg=belle_sip_object_to_string(BELLE_SIP_OBJECT(msg)); belle_sip_object_unref(msg); msg = belle_sip_message_parse(marshaled_msg); belle_sip_free(marshaled_msg); tmp=belle_sip_object_clone(BELLE_SIP_OBJECT(msg)); belle_sip_object_unref(msg); msg=BELLE_SIP_MESSAGE(tmp); CU_ASSERT_TRUE(BELLE_SIP_IS_INSTANCE_OF(msg,belle_http_response_t)); http_response=BELLE_HTTP_RESPONSE(msg); CU_ASSERT_EQUAL(belle_http_response_get_status_code(http_response),200); CU_ASSERT_STRING_EQUAL(belle_http_response_get_reason_phrase(http_response),"OK"); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"Date")); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"ETag")); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"Connection")); CU_ASSERT_PTR_NOT_NULL(host_header=BELLE_SIP_HEADER_EXTENSION(belle_sip_message_get_header(msg,"Server"))); CU_ASSERT_STRING_EQUAL(belle_sip_header_extension_get_value(host_header),"Apache"); belle_sip_object_unref(msg); }
static void test_sipfrag(void) { const char* raw_message = "SIP/2.0 100 Trying\r\n"; belle_sip_response_t* response; belle_sip_message_t* message = belle_sip_message_parse(raw_message); response = BELLE_SIP_RESPONSE(message); CU_ASSERT_EQUAL(belle_sip_response_get_status_code(response),100); CU_ASSERT_STRING_EQUAL(belle_sip_response_get_reason_phrase(response),"Trying"); belle_sip_object_unref(message); }
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 void test401ResponseWithoutResponsePhrase(void) { const char* raw_message = "SIP/2.0 401 \r\n" "Call-ID: 577586163\r\n" "CSeq: 21 REGISTER\r\n" "From: <sip:[email protected]>;tag=1790643209\r\n" "Server: Cirpack/v4.42x (gw_sip)\r\n" "To: <sip:[email protected]>;tag=00-08075-24212984-22e348d97\r\n" "Via: SIP/2.0/UDP 192.168.0.18:5062;received=81.56.113.2;rport=5062;branch=z9hG4bK1939354046\r\n" "WWW-Authenticate: Digest realm=\"sip.ovh.net\",\r\n nonce=\"24212965507cde726e8bc37e04686459\",opaque=\"241b9fb347752f2\",stale=false,algorithm=MD5\r\n" "Content-Length: 0\r\n\r\n"; belle_sip_response_t* response; belle_sip_message_t* message = belle_sip_message_parse(raw_message); char* encoded_message = belle_sip_object_to_string(BELLE_SIP_OBJECT(message)); belle_sip_object_unref(BELLE_SIP_OBJECT(message)); message = belle_sip_message_parse(encoded_message); response = BELLE_SIP_RESPONSE(message); CU_ASSERT_EQUAL(belle_sip_response_get_status_code(response),401); CU_ASSERT_PTR_NULL(belle_sip_response_get_reason_phrase(response)); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"WWW-Authenticate")); check_uri_and_headers(message); belle_sip_object_unref(message); belle_sip_free(encoded_message); }
static void testHttpGet(void) { const char* raw_message = "GET /index.php HTTP/1.1\r\n" "User-Agent: Wget/1.14 (darwin11.4.2)\r\n" "Accept: */*\r\n" "Host: www.linphone.org\r\n" "Connection: Keep-Alive\r\n" "\r\n"; char* marshaled_msg; belle_sip_message_t* msg = belle_sip_message_parse(raw_message); belle_http_request_t* http_request; belle_generic_uri_t* uri; belle_sip_header_extension_t* host_header; belle_sip_object_t* tmp; CU_ASSERT_PTR_NOT_NULL_FATAL(msg); marshaled_msg=belle_sip_object_to_string(BELLE_SIP_OBJECT(msg)); belle_sip_object_unref(msg); msg = belle_sip_message_parse(marshaled_msg); belle_sip_free(marshaled_msg); tmp=belle_sip_object_clone(BELLE_SIP_OBJECT(msg)); belle_sip_object_unref(msg); msg=BELLE_SIP_MESSAGE(tmp); CU_ASSERT_TRUE(BELLE_SIP_IS_INSTANCE_OF(msg,belle_http_request_t)); http_request=BELLE_HTTP_REQUEST(msg); CU_ASSERT_PTR_NOT_NULL_FATAL(uri=belle_http_request_get_uri(http_request)); CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(uri),"/index.php"); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"User-Agent")); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"Accept")); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"Connection")); CU_ASSERT_PTR_NOT_NULL(host_header=BELLE_SIP_HEADER_EXTENSION(belle_sip_message_get_header(msg,"Host"))); CU_ASSERT_STRING_EQUAL(belle_sip_header_extension_get_value(host_header),"www.linphone.org"); belle_sip_object_unref(msg); }
static void testOptionMessage(void) { const char* raw_message = "REGISTER sip:192.168.0.20 SIP/2.0\r\n"\ "Via: SIP/2.0/UDP 192.168.1.8:5062;rport;branch=z9hG4bK1439638806\r\n"\ "From: <sip:[email protected]>;tag=465687829\r\n"\ "To: <sip:[email protected]>\r\n"\ "Call-ID: 1053183492\r\n"\ "CSeq: 1 REGISTER\r\n"\ "Contact: <sip:[email protected]:5062>\r\n"\ "Max-Forwards: 70\r\n"\ "User-Agent: Linphone/3.3.99.10 (eXosip2/3.3.0)\r\n"\ "Expires: 3600\r\n"\ "Content-Length: 0\r\n\r\n"; belle_sip_message_t* message = belle_sip_message_parse(raw_message); belle_sip_request_t* request = BELLE_SIP_REQUEST(message); CU_ASSERT_STRING_EQUAL(belle_sip_request_get_method(request),"REGISTER"); CU_ASSERT_PTR_NOT_NULL(belle_sip_request_get_uri(request)); belle_sip_object_unref(message); }
static void testMalformedMessage(void) { const char * raw_message= "INVITE sip:[email protected]:50343;transport=tcp;line=f18e0009dd6cc43 SIP/2.0\r\n" "Via: SIP/2.0/UDP 192.168.1.12:15060;rport=15060;branch=z9hG4bK1596944937;received=81.56.113.2\r\n" "Via: SIP/2.0/TCP 37.59.129.73;branch=z9hG4bK.SKvK9U327e8mU68XUv5rt144pg\r\n" "Record-Route: <sip:37.59.129.73;lr;transport=tcp>\r\n" "Record-Route: <sip:37.59.129.73;lr>\r\n" "Max-Forwards: 70\r\n" "From: <sip:[email protected]>;tag=711138653\r\n" "To: <sip:[email protected]>\r\n" "Call-ID: 977107319\r\n" "CSeq: 21 INVITE\r\n" "Contact: <sip:[email protected]:5062>;pn-tok=/throttledthirdparty\r\n" /*Slash is not allowed for contact params*/\ "Subject: Phone call\r\n" "User-Agent: Linphone/3.5.2 (eXosip2/3.6.0)\r\n" "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO\r\n" "Content-Length: 0\r\n\r\n"; belle_sip_message_t* message = belle_sip_message_parse(raw_message); CU_ASSERT_FALSE(belle_sip_message_check_headers(message)); }
static void testRFC2543_base(char* branch) { belle_sip_server_transaction_t *tr; const char* raw_message_base = "INVITE sip:[email protected] SIP/2.0\r\n" "Via: SIP/2.0/UDP 192.168.1.12:15060;%srport=15060;received=81.56.113.2\r\n" "Record-Route: <sip:37.59.129.73;lr;transport=tcp>\r\n" "Record-Route: <sip:37.59.129.73;lr>\r\n" "Max-Forwards: 70\r\n" "From: <sip:[email protected]>;tag=711138653\r\n" "To: <sip:[email protected]>\r\n" "Call-ID: 977107319\r\n" "CSeq: 21 INVITE\r\n" "Contact: <sip:[email protected]:5062>\r\n" "Subject: Phone call\r\n" "User-Agent: Linphone/3.5.2 (eXosip2/3.6.0)\r\n" "Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO\r\n" "Content-Length: 0\r\n" "Extended: \r\n" /*fixme lexer*/ "\r\n"; char raw_message[2048]; belle_sip_request_t* request; belle_sip_stack_t *stack=belle_sip_stack_new(NULL); belle_sip_provider_t *prov=belle_sip_provider_new(stack,NULL); belle_sip_message_t* message; snprintf(raw_message,sizeof(raw_message),raw_message_base,branch); message = belle_sip_message_parse(raw_message); belle_sip_object_ref(message); belle_sip_object_ref(message); /*yes double ref: originally the message is created with 0 refcount, and dispatch_message will unref() it.*/ belle_sip_provider_dispatch_message(prov,message); request = BELLE_SIP_REQUEST(message); CU_ASSERT_PTR_NOT_NULL(request); tr=belle_sip_provider_create_server_transaction(prov,request); CU_ASSERT_PTR_NOT_NULL(belle_sip_provider_find_matching_server_transaction(prov,request)); /*make sure branch id is properly set*/ CU_ASSERT_PTR_NOT_NULL(tr); belle_sip_object_unref(prov); belle_sip_object_unref(stack); belle_sip_object_unref(message); }
void sal_op_call_process_notify(SalOp *op, const belle_sip_request_event_t *event, belle_sip_server_transaction_t* server_transaction){ belle_sip_request_t* req = belle_sip_request_event_get_request(event); const char* body = belle_sip_message_get_body(BELLE_SIP_MESSAGE(req)); belle_sip_header_t* header_event=belle_sip_message_get_header(BELLE_SIP_MESSAGE(req),"Event"); belle_sip_header_content_type_t* content_type = belle_sip_message_get_header_by_type(req,belle_sip_header_content_type_t); belle_sip_response_t* resp; ms_message("Receiving NOTIFY request on op [%p]",op); if (header_event && strncasecmp(belle_sip_header_get_unparsed_value(header_event),"refer",strlen("refer"))==0 && content_type && strcmp(belle_sip_header_content_type_get_type(content_type),"message")==0 && strcmp(belle_sip_header_content_type_get_subtype(content_type),"sipfrag")==0 && body){ belle_sip_response_t* sipfrag=BELLE_SIP_RESPONSE(belle_sip_message_parse(body)); if (sipfrag){ int code=belle_sip_response_get_status_code(sipfrag); SalReferStatus status=SalReferFailed; if (code<200){ status=SalReferTrying; }else if (code<300){ status=SalReferSuccess; }else if (code>=400){ status=SalReferFailed; } belle_sip_object_unref(sipfrag); resp = sal_op_create_response_from_request(op,req,200); belle_sip_server_transaction_send_response(server_transaction,resp); op->base.root->callbacks.notify_refer(op,status); } }else{ ms_error("Notify without sipfrag, trashing"); resp = sal_op_create_response_from_request(op,req,501); belle_sip_server_transaction_send_response(server_transaction,resp); } }
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); }