Commit 4d89f8d0 authored by jehan's avatar jehan

initial 100rel commit

parent 0f999ecc
......@@ -34,7 +34,6 @@ BELLESIP_EXPORT const char* belle_sip_dialog_state_to_string(const belle_sip_dia
BELLESIP_EXPORT belle_sip_request_t *belle_sip_dialog_create_ack(belle_sip_dialog_t *dialog, unsigned int cseq);
Please register or sign in to reply
/**
* Create a request part of this dialog.
**/
......@@ -103,6 +102,8 @@ 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);
Please register or sign in to reply
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
......
......@@ -450,6 +450,84 @@ static void belle_sip_dialog_update_remote_target(belle_sip_dialog_t *obj, belle
}
}
static void belle_sip_dialog_update_local_cseq(belle_sip_dialog_t *obj, const char *method){
if (obj->local_cseq==0) obj->local_cseq=110;
if (strcmp(method,"ACK")!=0) obj->local_cseq++;
}
static belle_sip_request_t *belle_sip_dialog_create_prack(belle_sip_dialog_t *dialog, unsigned int rseq, unsigned int cseq, const char* method){
  • Why not using belle_sip_dialog_create_request and just add RAck ?

    Edited by jehan
Please register or sign in to reply
belle_sip_request_t *prack;
belle_sip_request_t *invite = dialog->last_out_invite;
if (!invite){
belle_sip_error("No INVITE to PACK.");
return NULL;
}
belle_sip_dialog_update_local_cseq(dialog, "PRACK");
prack = create_request(dialog, "PRACK", TRUE);
if (prack){
//RAck
char header[50];
snprintf(header,sizeof(header),"%d %d %s", rseq, cseq, method);
belle_sip_header_t *rack = belle_sip_header_create("RAck", header);
belle_sip_message_add_header(BELLE_SIP_MESSAGE(prack), rack);
//Contact
belle_sip_header_from_t* from_header = belle_sip_message_get_header_by_type(prack, belle_sip_header_from_t);
belle_sip_uri_t* req_uri = belle_sip_header_address_get_uri((belle_sip_header_address_t*)from_header);
belle_sip_header_contact_t* contact_header = belle_sip_header_contact_new();
belle_sip_header_address_set_uri((belle_sip_header_address_t*)contact_header, belle_sip_uri_new());
belle_sip_uri_set_user(belle_sip_header_address_get_uri((belle_sip_header_address_t*)contact_header),belle_sip_uri_get_user(req_uri));
belle_sip_message_add_header(BELLE_SIP_MESSAGE(prack),BELLE_SIP_HEADER(contact_header));
const belle_sip_list_t *aut = belle_sip_message_get_headers((belle_sip_message_t*)invite, "Authorization");
const belle_sip_list_t *prx_aut = belle_sip_message_get_headers((belle_sip_message_t*)invite, "Proxy-Authorization");
if (aut)
belle_sip_message_add_headers((belle_sip_message_t*)prack, aut);
if (prx_aut)
belle_sip_message_add_headers((belle_sip_message_t*)prack, prx_aut);
}
return prack;
}
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);
if (header_cseq_resp == NULL){
belle_sip_message("Message [%p] does not contain CSeq header!", msg);
}
belle_sip_header_t *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].", msg);
belle_sip_header_t *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);
unsigned int cseq_resp = belle_sip_header_cseq_get_seq_number(header_cseq_resp);
const char* method_resp = belle_sip_header_cseq_get_method(header_cseq_resp);
/*send PRACK from callee */
belle_sip_request_t *prack = belle_sip_dialog_create_prack(obj, rseq, cseq_resp, method_resp);
if (prack){
belle_sip_dialog_send_prack(obj, 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)", msg);
}
}
}
}
/*
* return 0 if message should be delivered to the next listener, otherwise, its a retransmision, just keep it
* */
......@@ -496,6 +574,9 @@ 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);
break;
......@@ -532,6 +613,9 @@ 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) {
belle_sip_dialog_process_response_100rel(obj, resp);
}
break;
case BELLE_SIP_DIALOG_CONFIRMED:
if (code==481 && (is_invite || is_subscribe)) {
......@@ -710,7 +794,6 @@ 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_header_cseq_t *cseqh;
belle_sip_request_t *invite=obj->last_out_invite;
belle_sip_request_t *ack;
......@@ -718,12 +801,9 @@ belle_sip_request_t *belle_sip_dialog_create_ack(belle_sip_dialog_t *obj, unsign
belle_sip_error("No INVITE to ACK.");
return NULL;
}
cseqh=belle_sip_message_get_header_by_type(invite,belle_sip_header_cseq_t);
Please register or sign in to reply
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")));
/*
22 Usage of HTTP Authentication
22.1 Framework
......@@ -819,11 +899,6 @@ belle_sip_request_t * belle_sip_dialog_create_queued_request(belle_sip_dialog_t
return req;
}
static void belle_sip_dialog_update_local_cseq(belle_sip_dialog_t *obj, const char *method){
if (obj->local_cseq==0) obj->local_cseq=110;
if (strcmp(method,"ACK")!=0) obj->local_cseq++;
}
belle_sip_request_t *belle_sip_dialog_create_request(belle_sip_dialog_t *obj, const char *method){
belle_sip_request_t *req;
......@@ -993,6 +1068,10 @@ 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){
Please register or sign in to reply
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;
}
......
......@@ -47,6 +47,7 @@ static belle_sip_dialog_t* caller_dialog;
static belle_sip_dialog_t* callee_dialog;
static belle_sip_response_t* ok_response;
static belle_sip_server_transaction_t* inserv_transaction;
static belle_sip_client_transaction_t* pauline_reg_transaction;
belle_sip_request_t* build_request(belle_sip_stack_t * stack
......@@ -68,7 +69,9 @@ belle_sip_request_t* build_request(belle_sip_stack_t * stack
contact_header= belle_sip_header_contact_new();
belle_sip_header_address_set_uri((belle_sip_header_address_t*)contact_header,belle_sip_uri_new());
belle_sip_uri_set_user(belle_sip_header_address_get_uri((belle_sip_header_address_t*)contact_header),belle_sip_uri_get_user(req_uri));
belle_sip_uri_set_user(belle_sip_header_address_get_uri((belle_sip_header_address_t*)contact_header),
belle_sip_uri_get_user(belle_sip_header_address_get_uri((belle_sip_header_address_t*)from_header)));
req=belle_sip_request_create(
req_uri,
method,
......@@ -78,6 +81,7 @@ belle_sip_request_t* build_request(belle_sip_stack_t * stack
to_header,
belle_sip_header_via_new(),
70);
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(contact_header));
if (route) {
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(belle_sip_header_route_create(route)));
......@@ -123,6 +127,8 @@ 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;
......@@ -131,6 +137,14 @@ static void callee_process_request_event(void *user_ctx, const belle_sip_request
return; /*not for the callee*/
}
method = belle_sip_request_get_method(belle_sip_request_event_get_request(event));
if (strcmp(method,"PRACK") == 0){
belle_sip_server_transaction_t* server_trans = belle_sip_provider_create_server_transaction(prov,belle_sip_request_event_get_request(event));
belle_sip_response_t* prack_resp_ok = belle_sip_response_create_from_request(belle_sip_request_event_get_request(event), 200);
belle_sip_server_transaction_send_response(server_trans, prack_resp_ok);
return;
}
if (!server_transaction && strcmp(method,"ACK")!=0) {
server_transaction= belle_sip_provider_create_server_transaction(prov,belle_sip_request_event_get_request(event));
}
......@@ -143,8 +157,22 @@ static void callee_process_request_event(void *user_ctx, const belle_sip_request
callee_dialog=dialog;
inserv_transaction=server_transaction;
}
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));
/*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));
......@@ -153,6 +181,7 @@ static void callee_process_request_event(void *user_ctx, const belle_sip_request
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) {
......@@ -167,11 +196,16 @@ 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
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*/
......@@ -188,6 +222,34 @@ 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;
......@@ -264,6 +326,7 @@ 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;
......@@ -285,32 +348,35 @@ static void do_simple_call(void) {
callee_listener_callbacks.process_transaction_terminated=process_transaction_terminated;
callee_listener_callbacks.listener_destroyed=listener_destroyed;
pauline_register_req=register_user(stack, prov, "TCP" ,1 ,CALLER,NULL);
pauline_reg_transaction = register_user_with_transaction(stack, prov, "TCP", CALLEE, NULL);
pauline_register_req = belle_sip_transaction_get_request((belle_sip_transaction_t*)pauline_reg_transaction);
if (belle_sip_provider_get_listening_point(prov, "tls")) {
marie_register_req=register_user(stack, prov, "TLS" ,1 ,CALLEE,NULL);
marie_register_req = register_user(stack, prov, "TLS", 1, CALLER, NULL);
} else {
marie_register_req=register_user(stack, prov, "TCP" ,1 ,CALLEE,NULL);
marie_register_req = register_user(stack, prov, "TCP", 1, CALLER, NULL);
}
from=belle_sip_header_address_create(NULL,belle_sip_uri_create(CALLER,test_domain));
from = belle_sip_header_address_create(NULL,belle_sip_uri_create(CALLER,test_domain));
/*to make sure unexpected messages are ignored*/
belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(from),"cookie",belle_sip_random_token(cookie,sizeof(cookie)));
/*to make sure unexpected messages are ignored*/
to=belle_sip_header_address_create(NULL,belle_sip_uri_create(CALLEE,test_domain));
to = belle_sip_header_address_create(NULL,belle_sip_uri_create(CALLEE,test_domain));
belle_sip_parameters_set_parameter(BELLE_SIP_PARAMETERS(to),"cookie",belle_sip_random_token(cookie,sizeof(cookie)));
belle_sip_provider_add_sip_listener(prov,caller_listener=belle_sip_listener_create_from_callbacks(&caller_listener_callbacks,belle_sip_object_ref(belle_sip_header_address_get_uri((belle_sip_header_address_t*)from))));
belle_sip_provider_add_sip_listener(prov,callee_listener=belle_sip_listener_create_from_callbacks(&callee_listener_callbacks,belle_sip_object_ref(belle_sip_header_address_get_uri((belle_sip_header_address_t*)to))));
belle_sip_provider_add_sip_listener(prov, caller_listener = belle_sip_listener_create_from_callbacks(&caller_listener_callbacks, belle_sip_object_ref(belle_sip_header_address_get_uri((belle_sip_header_address_t*)from))));
belle_sip_provider_add_sip_listener(prov, callee_listener = belle_sip_listener_create_from_callbacks(&callee_listener_callbacks, belle_sip_object_ref(belle_sip_header_address_get_uri((belle_sip_header_address_t*)to))));
route = belle_sip_header_address_create(NULL,belle_sip_uri_create(NULL,test_domain));
belle_sip_uri_set_transport_param(belle_sip_header_address_get_uri(route),"tcp");
req=build_request(stack,prov,from,to,route,"INVITE");
header_allow = belle_sip_header_allow_create("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
req = build_request(stack,prov,from,to,route,"INVITE");
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));
content_length= belle_sip_header_content_length_create(strlen(sdp));
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(req),BELLE_SIP_HEADER(content_type));
belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(content_length));
......@@ -318,10 +384,10 @@ static void do_simple_call(void) {
client_transaction = belle_sip_provider_create_client_transaction(prov,req);
caller_dialog=belle_sip_provider_create_dialog(prov,BELLE_SIP_TRANSACTION(client_transaction));
caller_dialog = belle_sip_provider_create_dialog(prov,BELLE_SIP_TRANSACTION(client_transaction));
BC_ASSERT_PTR_NOT_NULL(belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(client_transaction)));
//belle_sip_transaction_set_application_data(BELLE_SIP_TRANSACTION(client_transaction),op);
call_endeed=0;
call_endeed = 0;
belle_sip_client_transaction_send_request(client_transaction);
//int i=0;
//for(i=0;i<10 &&!call_endeed;i++)
......
......@@ -452,6 +452,24 @@ static void test_route_header(void) {
}
static void test_rseq_header()
{
belle_sip_header_t* L_tmp;
belle_sip_header_t* L_rseq;
char* l_raw_header = NULL;
L_rseq = belle_sip_header_parse("RSeq: 3344");
l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_rseq));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_rseq));
L_tmp = belle_sip_header_parse(l_raw_header);
L_rseq = BELLE_SIP_HEADER(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
belle_sip_free(l_raw_header);
BC_ASSERT_STRING_EQUAL(belle_sip_header_get_unparsed_value(L_rseq), "3344");
belle_sip_object_unref(L_rseq);
}
static void test_service_route_header(void) {
belle_sip_header_service_route_t* L_service_route = belle_sip_header_service_route_parse("Service-Route: <sip:orig@scscf.ims.linphone.com:6060;lr>");
belle_sip_uri_t* L_uri;
......@@ -560,6 +578,23 @@ static void test_proxy_authorization_header(void) {
BC_ASSERT_PTR_NULL(belle_sip_header_proxy_authorization_parse("nimportequoi"));
}
static void test_rack_header(void ) {
belle_sip_header_t* L_tmp;
belle_sip_header_t* L_rseq;
char* l_raw_header = NULL;
L_rseq = belle_sip_header_parse("RAck: 3344 101 INVITE");
l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_rseq));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_rseq));
L_tmp = belle_sip_header_parse(l_raw_header);
L_rseq = BELLE_SIP_HEADER(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
belle_sip_free(l_raw_header);
BC_ASSERT_STRING_EQUAL(belle_sip_header_get_unparsed_value(L_rseq), "3344 101 INVITE");
belle_sip_object_unref(L_rseq);
}
static void check_header_authenticate(belle_sip_header_www_authenticate_t* authenticate) {
belle_sip_list_t* qop;
BC_ASSERT_PTR_NOT_NULL(authenticate);
......@@ -718,7 +753,7 @@ static void test_expires_header(void) {
static void test_allow_header(void) {
belle_sip_header_allow_t* L_tmp;
belle_sip_header_allow_t* L_allow = belle_sip_header_allow_parse("Allow:INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
belle_sip_header_allow_t* L_allow = belle_sip_header_allow_parse("Allow:INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO, PRACK");
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_allow));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_allow));
L_tmp = belle_sip_header_allow_parse(l_raw_header);
......@@ -726,7 +761,7 @@ static void test_allow_header(void) {
belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
belle_sip_free(l_raw_header);
BC_ASSERT_STRING_EQUAL(belle_sip_header_allow_get_method(L_allow), "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
BC_ASSERT_STRING_EQUAL(belle_sip_header_allow_get_method(L_allow), "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO, PRACK");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_allow));
BC_ASSERT_PTR_NULL(belle_sip_header_allow_parse("nimportequoi"));
}
......@@ -983,6 +1018,28 @@ static void test_replaces_escaped_header(void) {
}
static void test_require(const char* header_name, const char * header_value) {
belle_sip_header_t* L_tmp;
belle_sip_header_t* L_require;
char header[256];
char* l_raw_header = NULL;
snprintf(header, sizeof(header), "%s:%s", header_name, header_value);
L_require = belle_sip_header_parse(header);
l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_require));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_require));
L_tmp = belle_sip_header_parse(l_raw_header);
L_require = BELLE_SIP_HEADER(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
belle_sip_free(l_raw_header);
BC_ASSERT_STRING_EQUAL(belle_sip_header_get_unparsed_value(L_require), header_value);
belle_sip_object_unref(L_require);
}
static void test_header_require(void) {
test_require("Require", "100rel");
}
#ifndef _WIN32
static void _test_date_header(void){
belle_sip_header_date_t *date,*date2;
......@@ -1122,11 +1179,14 @@ static void test_supported(const char* header_name, const char * header_value, c
belle_sip_object_unref(BELLE_SIP_OBJECT(L_supported));
BC_ASSERT_PTR_NULL(belle_sip_header_supported_parse("nimportequoi"));
}
static void test_supported_header(void) {
const char* value1[] ={"user","critical"};
const char* value2[] ={"id"};
const char* value3[] ={"100rel"};
test_supported("Supported","user, critical",value1,2);
test_supported("Supported", "id",value2,1);
test_supported("Supported", "100rel", value3, 1);
}
static void test_content_disposition_header(void) {
......@@ -1276,12 +1336,15 @@ test_t headers_tests[] = {
TEST_NO_TAG("P-Preferred-Identity", test_p_preferred_identity_header),
TEST_NO_TAG("Proxy-Authenticate", test_proxy_authenticate_header),
TEST_NO_TAG("Proxy-Authorization", test_proxy_authorization_header),
TEST_NO_TAG("RAck", test_rack_header),
TEST_NO_TAG("Record-Route", test_record_route_header),
TEST_NO_TAG("Refer-To", test_refer_to_header),
TEST_NO_TAG("Referred-By", test_referred_by_header),
TEST_NO_TAG("Replaces", test_replaces_header),
TEST_NO_TAG("Replaces (Escaped)", test_replaces_escaped_header),
TEST_NO_TAG("Require", test_header_require),
TEST_NO_TAG("Route", test_route_header),
TEST_NO_TAG("RSeq", test_rseq_header),
TEST_NO_TAG("Service-Route", test_service_route_header),
TEST_NO_TAG("Subscription-State", test_subscription_state_header),
TEST_NO_TAG("To", test_to_header),
......
......@@ -18,6 +18,7 @@
#include "belle-sip/belle-sip.h"
#include "belle_sip_tester.h"
#include "belle_sip_internal.h"
static void check_uri_and_headers(belle_sip_message_t* message) {
......@@ -97,9 +98,10 @@ static void testInviteMessage(void) {
"From: \"Benjamin Cheong\" <sip:bcheong@sip.linphone.org>;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"\
"Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO, PRACK\r\n"\
"c: application/sdp\r\n"\
"Supported: replaces\r\n"\
"Supported: 100rel\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";
......@@ -113,6 +115,23 @@ static void testInviteMessage(void) {
BC_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Contact"));
BC_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Authorization"));
BC_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Content-Type"));
belle_sip_header_supported_t* header_support;
BC_ASSERT_PTR_NOT_NULL(header_support=BELLE_SIP_HEADER_SUPPORTED(belle_sip_message_get_header(message,"Supported")));
if (header_support) {
belle_sip_list_t* list;
list = belle_sip_header_supported_get_supported(header_support);
BC_ASSERT_PTR_NOT_NULL(list);
const char* value[] = {"replaces", "100rel"};
int num_supported = 2;
for(int i = 0; i < num_supported; i++){
if (list) {
BC_ASSERT_STRING_EQUAL((const char *)(list->data), value[i]);
list=list->next;
}
}
}
check_uri_and_headers(message);
belle_sip_object_unref(message);
belle_sip_free(encoded_message);
......@@ -388,7 +407,6 @@ static void testMalformedMessageWithWrongStart(void) {
belle_sip_message_t* message = belle_sip_message_parse(raw_message);
BC_ASSERT_PTR_NULL(message);
}
#include "belle_sip_internal.h"
void channel_parser_tester_recovery_from_error_base (const char* prelude,const char* raw_message) {
......
......@@ -445,6 +445,80 @@ belle_sip_request_t* register_user(belle_sip_stack_t * stack
return register_user_at_domain(stack,prov,transport,use_transaction,username,test_domain,outbound);
}
belle_sip_client_transaction_t* register_user_with_transaction(belle_sip_stack_t * stack
  • Should be possible to share more code with register_user_at_domain

Please register or sign in to reply
,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);
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*/
}
}
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;
}
static void register_with_outbound(const char *transport, int use_transaction,const char* outbound ) {
belle_sip_request_t *req;
......
......@@ -28,8 +28,11 @@ extern belle_sip_request_t* register_user(belle_sip_stack_t * stack
,const char *transport
,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);
extern void unregister_user(belle_sip_stack_t * stack
,belle_sip_provider_t *prov
,belle_sip_request_t* initial_request
,int use_transaction);
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