Commit 72e23ced authored by Viacheslav Demydiuk's avatar Viacheslav Demydiuk Committed by Vyacheslav Demidyuk

final 100rel commit. belle_sip_dialog_tester work with test 'Simple call with...

final 100rel commit. belle_sip_dialog_tester work with test 'Simple call with prack' for testing PRACK message.
parent 4d89f8d0
......@@ -102,8 +102,6 @@ BELLESIP_EXPORT int belle_sip_dialog_is_secure(const belle_sip_dialog_t *dialog)
BELLESIP_EXPORT void belle_sip_dialog_send_ack(belle_sip_dialog_t *dialog, belle_sip_request_t *request);
BELLESIP_EXPORT void belle_sip_dialog_send_prack(belle_sip_dialog_t *dialog, belle_sip_request_t *request);
BELLESIP_EXPORT void belle_sip_dialog_terminate_on_bye(belle_sip_dialog_t *dialog, int val);
/**
* Give access to the last transaction processed by a dialog. Can be useful to get reason code for dialog terminated before reaching established state
......
......@@ -463,9 +463,8 @@ static belle_sip_request_t *belle_sip_dialog_create_prack(belle_sip_dialog_t *di
belle_sip_error("No INVITE to PACK.");
return NULL;
}
belle_sip_dialog_update_local_cseq(dialog, "PRACK");
prack = create_request(dialog, "PRACK", TRUE);
prack = belle_sip_dialog_create_request(dialog, "PRACK");
if (prack){
//RAck
......@@ -493,6 +492,10 @@ static belle_sip_request_t *belle_sip_dialog_create_prack(belle_sip_dialog_t *di
return prack;
}
static void belle_sip_dialog_send_prack(belle_sip_dialog_t *dialog, belle_sip_request_t *request){
belle_sip_provider_send_request(dialog->provider, request);
}
static void belle_sip_dialog_process_response_100rel(belle_sip_dialog_t *obj, belle_sip_response_t *resp){
belle_sip_message_t* msg = (belle_sip_message_t*)resp;
belle_sip_header_cseq_t *header_cseq_resp = belle_sip_message_get_header_by_type(msg, belle_sip_header_cseq_t);
......@@ -574,11 +577,11 @@ int belle_sip_dialog_update(belle_sip_dialog_t *obj, belle_sip_transaction_t* tr
/*always establish a dialog*/
if (code>100 && code<300 && (is_invite || is_subscribe)) {
belle_sip_dialog_establish(obj,req,resp);
if (code == 180 && !as_uas) {
belle_sip_dialog_process_response_100rel(obj, resp);
}
if (code<200){
set_state(obj,BELLE_SIP_DIALOG_EARLY);
if ((code == 180 || code == 183) && !as_uas) {
belle_sip_dialog_process_response_100rel(obj, resp);
}
break;
}/* no break for code >200 because need to call belle_sip_dialog_establish_full*/
}
......@@ -613,7 +616,7 @@ int belle_sip_dialog_update(belle_sip_dialog_t *obj, belle_sip_transaction_t* tr
/*no response establishing the dialog, and transaction terminated (transport errors)*/
delete_dialog=TRUE;
}
if (code == 183 && !as_uas) {
if ((code == 180 || code == 183) && !as_uas) {
belle_sip_dialog_process_response_100rel(obj, resp);
}
break;
......@@ -796,12 +799,19 @@ belle_sip_dialog_t *belle_sip_dialog_new(belle_sip_transaction_t *t){
belle_sip_request_t *belle_sip_dialog_create_ack(belle_sip_dialog_t *obj, unsigned int cseq){
belle_sip_request_t *invite=obj->last_out_invite;
belle_sip_request_t *ack;
belle_sip_header_cseq_t* cseqh;
if (!invite){
belle_sip_error("No INVITE to ACK.");
return NULL;
}
cseqh=belle_sip_message_get_header_by_type(invite,belle_sip_header_cseq_t);
if (belle_sip_header_cseq_get_seq_number(cseqh)!=cseq){
belle_sip_error("No INVITE with cseq %i to create ack for.",cseq);
return NULL;
}
ack=create_request(obj,"ACK",TRUE);
belle_sip_message_set_header(BELLE_SIP_MESSAGE(ack), BELLE_SIP_HEADER(belle_sip_header_cseq_create(cseq, "ACK")));
/*
......@@ -1068,10 +1078,6 @@ void belle_sip_dialog_send_ack(belle_sip_dialog_t *obj, belle_sip_request_t *req
}
}
void belle_sip_dialog_send_prack(belle_sip_dialog_t *dialog, belle_sip_request_t *request){
belle_sip_provider_send_request(dialog->provider, request);
}
void belle_sip_dialog_terminate_on_bye(belle_sip_dialog_t *obj, int val){
obj->terminate_on_bye=val;
}
......
......@@ -127,8 +127,6 @@ static void callee_process_request_event(void *user_ctx, const belle_sip_request
belle_sip_response_t* ringing_response;
belle_sip_header_content_type_t* content_type ;
belle_sip_header_content_length_t* content_length;
belle_sip_header_t* header_require;
belle_sip_header_t* header_rseq;
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;
......@@ -161,18 +159,33 @@ static void callee_process_request_event(void *user_ctx, const belle_sip_request
if (belle_sip_dialog_get_state(dialog) == BELLE_SIP_DIALOG_NULL) {
/*prepare 180*/
ringing_response = belle_sip_response_create_from_request(belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(server_transaction)),180);
header_require = belle_sip_header_create("Require", "100rel");
header_rseq = belle_sip_header_create("RSeq", "1");
belle_sip_message_add_header(BELLE_SIP_MESSAGE(ringing_response), BELLE_SIP_HEADER(header_require));
belle_sip_message_add_header(BELLE_SIP_MESSAGE(ringing_response), BELLE_SIP_HEADER(header_rseq));
//workaround for PRACK message. Server will correct Contact header that will be used during create PRACK massege (dialog->remote_target)
belle_sip_response_t* marie_reg_response = belle_sip_transaction_get_response((belle_sip_transaction_t*)pauline_reg_transaction);
BC_ASSERT_PTR_NOT_NULL(marie_reg_response);
belle_sip_header_contact_t* L_tmp = belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(marie_reg_response), belle_sip_header_contact_t);
belle_sip_header_contact_t* contact_header = BELLE_SIP_HEADER_CONTACT(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
belle_sip_message_add_header(BELLE_SIP_MESSAGE(ringing_response),BELLE_SIP_HEADER(contact_header));
belle_sip_header_supported_t* header_supported = belle_sip_message_get_header_by_type(belle_sip_request_event_get_request(event),belle_sip_header_supported_t);
if (header_supported){
belle_sip_list_t* list = belle_sip_header_supported_get_supported(header_supported);
int supported_100rel = 0;
while (list){
if (strcmp(list->data, "100rel") == 0){
supported_100rel = 1;
break;
}
list=list->next;
}
if (supported_100rel){
belle_sip_message("Found supported 100rel in message [%p]. PRACK will be required in response 180.", belle_sip_request_event_get_request(event));
belle_sip_header_t* header_require = belle_sip_header_create("Require", "100rel");
belle_sip_header_t* header_rseq = belle_sip_header_create("RSeq", "1");
belle_sip_message_add_header(BELLE_SIP_MESSAGE(ringing_response), BELLE_SIP_HEADER(header_require));
belle_sip_message_add_header(BELLE_SIP_MESSAGE(ringing_response), BELLE_SIP_HEADER(header_rseq));
//workaround for PRACK message. Server will correct Contact header that will be used during create PRACK massege (dialog->remote_target)
belle_sip_response_t* marie_reg_response = belle_sip_transaction_get_response((belle_sip_transaction_t*)pauline_reg_transaction);
BC_ASSERT_PTR_NOT_NULL(marie_reg_response);
belle_sip_header_contact_t* L_tmp = belle_sip_message_get_header_by_type(BELLE_SIP_MESSAGE(marie_reg_response), belle_sip_header_contact_t);
belle_sip_header_contact_t* contact_header = BELLE_SIP_HEADER_CONTACT(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
belle_sip_message_add_header(BELLE_SIP_MESSAGE(ringing_response),BELLE_SIP_HEADER(contact_header));
}
}
/*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));
......@@ -197,15 +210,13 @@ static void callee_process_request_event(void *user_ctx, const belle_sip_request
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);
if (client_transaction == NULL)
return; //temporary fix for received 200 of PRACK
return; //fix for received 200 of PRACK
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;
// belle_sip_header_t *header_require;
// belle_sip_header_t *header_rseq;
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*/
......@@ -222,34 +233,6 @@ static void caller_process_response_event(void *user_ctx, const belle_sip_respon
} 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_message_t* msg = BELLE_SIP_MESSAGE(belle_sip_response_event_get_response(event));
// header_require = belle_sip_message_get_header(msg,"Require");
// if (header_require){
// const char* header_require_value = belle_sip_header_get_unparsed_value(header_require);
// if (strcmp(header_require_value, "100rel") == 0){
// belle_sip_message("Found header Require with value 100rel in message [%p].", belle_sip_response_event_get_response(event));
// header_rseq = belle_sip_message_get_header(msg, "RSeq");
// if (header_rseq){
// const char* header_rseq_value = belle_sip_header_get_unparsed_value(header_rseq);
// long rseq = strtol(header_rseq_value, NULL, 10);
//
// /*send PRACK from callee */
// belle_sip_request_t *prack = belle_sip_dialog_create_prack(dialog, 21, rseq, "INVITE");
// if (prack){
// belle_sip_dialog_send_prack(dialog, prack);
// }
// else {
// belle_sip_message("Failed to create PRACK message!");
// }
// }
// else {
// belle_sip_message("Message [%p] does not contain RSeq header! (required be with 100rel)", belle_sip_response_event_get_response(event));
// }
// }
// }
belle_sip_server_transaction_send_response(inserv_transaction,ok_response);
belle_sip_object_unref(ok_response);
ok_response=NULL;
......@@ -312,7 +295,7 @@ static void listener_destroyed(void *user_ctx){
belle_sip_object_unref(user_ctx);
}
static void do_simple_call(void) {
static void do_simple_call(int enable_100rel) {
#define CALLER "marie"
#define CALLEE "pauline"
belle_sip_request_t *pauline_register_req;
......@@ -326,7 +309,6 @@ static void do_simple_call(void) {
belle_sip_header_address_t* to;
belle_sip_header_address_t* route;
belle_sip_header_allow_t* header_allow;
belle_sip_header_supported_t* header_supported;
belle_sip_header_content_type_t* content_type ;
belle_sip_header_content_length_t* content_length;
belle_sip_client_transaction_t* client_transaction;
......@@ -373,8 +355,10 @@ static void do_simple_call(void) {
header_allow = belle_sip_header_allow_create("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO, PRACK");
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(header_allow));
header_supported = belle_sip_header_supported_create("100rel");
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req), BELLE_SIP_HEADER(header_supported));
if (enable_100rel){
belle_sip_header_supported_t* header_supported = belle_sip_header_supported_create("100rel");
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req), BELLE_SIP_HEADER(header_supported));
}
content_length = belle_sip_header_content_length_create(strlen(sdp));
content_type = belle_sip_header_content_type_create("application","sdp");
......@@ -408,14 +392,20 @@ static void do_simple_call(void) {
static void simple_call(void){
belle_sip_stack_set_tx_delay(stack,0);
do_simple_call();
do_simple_call(0);
}
static void simple_call_with_delay(void){
belle_sip_stack_set_tx_delay(stack,2000);
do_simple_call();
do_simple_call(0);
belle_sip_stack_set_tx_delay(stack,0);
}
static void simple_call_with_prack(void){
belle_sip_stack_set_tx_delay(stack,0);
do_simple_call(1);
}
/*static void simple_call_udp_tcp_with_delay(void){
belle_sip_listening_point_t* lp=belle_sip_provider_get_listening_point(prov,"tls");
belle_sip_object_ref(lp);
......@@ -431,6 +421,7 @@ static void simple_call_with_delay(void){
test_t dialog_tests[] = {
TEST_ONE_TAG("Simple call", simple_call, "LeaksMemory"),
TEST_ONE_TAG("Simple call with delay", simple_call_with_delay, "LeaksMemory"),
TEST_ONE_TAG("Simple call with prack", simple_call_with_prack, "LeaksMemory"),
};
test_suite_t dialog_test_suite = {"Dialog", register_before_all, register_after_all, belle_sip_tester_before_each,
......
......@@ -353,58 +353,67 @@ void unregister_user(belle_sip_stack_t * stack
belle_sip_provider_remove_sip_listener(prov,l);
}
belle_sip_request_t* try_register_user_at_domain(belle_sip_stack_t * stack
static belle_sip_request_t* create_registration_request(belle_sip_stack_t * stack
,belle_sip_provider_t *prov
,const char *transport
,int use_transaction
,const char* username
,const char* domain
,const char* outbound_proxy
,int success_expected) {
belle_sip_request_t *req,*copy;
,const char* outbound_proxy) {
belle_sip_request_t *req;
char identity[256];
char uri[256];
int i;
char *outbound=NULL;
int do_manual_retransmissions = FALSE;
number_of_challenge=0;
if (transport)
snprintf(uri,sizeof(uri),"sip:%s;transport=%s",domain,transport);
else snprintf(uri,sizeof(uri),"sip:%s",domain);
if (transport && strcasecmp("tls",transport)==0 && belle_sip_provider_get_listening_point(prov,"tls")==NULL){
belle_sip_error("No TLS support, test skipped.");
return NULL;
}
else snprintf(uri,sizeof(uri),"sip:%s",domain);
if (transport && strcasecmp("tls",transport)==0 && belle_sip_provider_get_listening_point(prov,"tls")==NULL){
belle_sip_error("No TLS support, test skipped.");
return NULL;
}
if (outbound_proxy){
if (strstr(outbound_proxy,"sip:")==NULL && strstr(outbound_proxy,"sips:")==NULL){
outbound=belle_sip_strdup_printf("sip:%s",outbound_proxy);
}else outbound=belle_sip_strdup(outbound_proxy);
}
snprintf(identity,sizeof(identity),"Tester <sip:%s@%s>",username,domain);
req=belle_sip_request_create(
belle_sip_uri_parse(uri),
"REGISTER",
belle_sip_provider_create_call_id(prov),
belle_sip_header_cseq_create(20,"REGISTER"),
belle_sip_header_from_create2(identity,BELLE_SIP_RANDOM_TAG),
belle_sip_header_to_create2(identity,NULL),
belle_sip_header_via_new(),
70);
belle_sip_uri_parse(uri),
"REGISTER",
belle_sip_provider_create_call_id(prov),
belle_sip_header_cseq_create(20,"REGISTER"),
belle_sip_header_from_create2(identity,BELLE_SIP_RANDOM_TAG),
belle_sip_header_to_create2(identity,NULL),
belle_sip_header_via_new(),
70);
belle_sip_object_ref(req);
is_register_ok=0;
io_error_count=0;
using_transaction=0;
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(belle_sip_header_contact_new()));
copy=(belle_sip_request_t*)belle_sip_object_ref(belle_sip_object_clone((belle_sip_object_t*)req));
return req;
}
static void execute_registration(belle_sip_stack_t * stack,
belle_sip_provider_t *prov,
belle_sip_client_transaction_t *trans,
belle_sip_request_t *req,
const char *transport,
int success_expected){
int do_manual_retransmissions = FALSE;
int use_transaction = trans ? 1 : 0;
int i;
char *outbound=NULL;
belle_sip_provider_add_sip_listener(prov,l=BELLE_SIP_LISTENER(listener));
if (use_transaction){
belle_sip_client_transaction_t *t=belle_sip_provider_create_client_transaction(prov,req);
belle_sip_client_transaction_send_request_to(t,outbound?belle_sip_uri_parse(outbound):NULL);
if (trans){
belle_sip_client_transaction_send_request_to(trans,outbound?belle_sip_uri_parse(outbound):NULL);
}else{
belle_sip_provider_send_request(prov,req);
do_manual_retransmissions = (transport == NULL) || (strcasecmp(transport,"udp") == 0);
......@@ -418,10 +427,31 @@ belle_sip_request_t* try_register_user_at_domain(belle_sip_stack_t * stack
}
BC_ASSERT_EQUAL(is_register_ok,success_expected,int,"%d");
if (success_expected) BC_ASSERT_EQUAL(using_transaction,use_transaction,int,"%d");
belle_sip_object_unref(req);
belle_sip_provider_remove_sip_listener(prov,l);
if (outbound) belle_sip_free(outbound);
}
belle_sip_request_t* try_register_user_at_domain(belle_sip_stack_t * stack
,belle_sip_provider_t *prov
,const char *transport
,int use_transaction
,const char* username
,const char* domain
,const char* outbound_proxy
,int success_expected) {
belle_sip_request_t *req,*copy = NULL;
req = create_registration_request(stack, prov, transport, username, domain, outbound_proxy);
if (req)
{
copy = (belle_sip_request_t*)belle_sip_object_ref(belle_sip_object_clone((belle_sip_object_t*)req));
belle_sip_client_transaction_t *t = use_transaction ? belle_sip_provider_create_client_transaction(prov,req) : NULL;
execute_registration(stack, prov, t, req, transport, success_expected);
belle_sip_object_unref(req);
}
return copy;
}
......@@ -446,76 +476,21 @@ belle_sip_request_t* register_user(belle_sip_stack_t * stack
}
belle_sip_client_transaction_t* register_user_with_transaction(belle_sip_stack_t * stack
,belle_sip_provider_t *prov
,const char *transport
,const char* username
,const char* outbound_proxy) {
,belle_sip_provider_t *prov
,const char *transport
,const char* username
,const char* outbound_proxy) {
belle_sip_request_t *req;
belle_sip_client_transaction_t *t;
char identity[256];
char uri[256];
int i;
char *outbound = NULL;
int do_manual_retransmissions = FALSE;
number_of_challenge = 0;
if (transport)
snprintf(uri, sizeof(uri), "sip:%s;transport=%s", test_domain, transport);
else
snprintf(uri, sizeof(uri), "sip:%s", test_domain);
if (transport && strcasecmp("tls",transport) == 0 && belle_sip_provider_get_listening_point(prov,"tls") == NULL){
belle_sip_error("No TLS support, test skipped.");
return NULL;
}
if (outbound_proxy){
if (strstr(outbound_proxy,"sip:") == NULL && strstr(outbound_proxy,"sips:") == NULL){
outbound = belle_sip_strdup_printf("sip:%s",outbound_proxy);
}
else
outbound=belle_sip_strdup(outbound_proxy);
}
snprintf(identity,sizeof(identity), "Tester <sip:%s@%s>", username, test_domain);
belle_sip_client_transaction_t *t = NULL;
req = belle_sip_request_create(
belle_sip_uri_parse(uri),
"REGISTER",
belle_sip_provider_create_call_id(prov),
belle_sip_header_cseq_create(20,"REGISTER"),
belle_sip_header_from_create2(identity,BELLE_SIP_RANDOM_TAG),
belle_sip_header_to_create2(identity,NULL),
belle_sip_header_via_new(),
70);
belle_sip_object_ref(req);
is_register_ok = 0;
io_error_count = 0;
using_transaction = 0;
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(belle_sip_header_contact_new()));
belle_sip_provider_add_sip_listener(prov,l = BELLE_SIP_LISTENER(listener));
t = belle_sip_provider_create_client_transaction(prov, req);
belle_sip_object_ref(t);
belle_sip_client_transaction_send_request_to(t, outbound ? belle_sip_uri_parse(outbound) : NULL);
for(i = 0; !is_register_ok && i < 20 && io_error_count == 0; i++) {
belle_sip_stack_sleep(stack,500);
if (do_manual_retransmissions && !is_register_ok) {
belle_sip_object_ref(req);
belle_sip_provider_send_request(prov, req); /*manage retransmitions*/
}
req = create_registration_request(stack, prov, transport, username, test_domain, outbound_proxy);
if (req)
{
t = belle_sip_provider_create_client_transaction(prov, req);
belle_sip_object_ref(t);
execute_registration(stack, prov, t, req, transport, 1);
}
BC_ASSERT_EQUAL(is_register_ok, 1, int, "%d");
belle_sip_object_unref(req);
belle_sip_provider_remove_sip_listener(prov,l);
if (outbound) belle_sip_free(outbound);
return t;
}
......
......@@ -29,9 +29,10 @@ extern belle_sip_request_t* register_user(belle_sip_stack_t * stack
,int use_transaction
,const char* username,const char* outbound) ;
extern belle_sip_client_transaction_t* register_user_with_transaction(belle_sip_stack_t * stack
,belle_sip_provider_t *prov
,const char *transport
,const char* username,const char* outbound);
,belle_sip_provider_t *prov
,const char *transport
,const char* username
,const char* outbound_proxy);
extern void unregister_user(belle_sip_stack_t * stack
,belle_sip_provider_t *prov
,belle_sip_request_t* initial_request
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment