Commit 0d432ae3 authored by jehan's avatar jehan

many bug fixes.

Header name parsing is nno longuer case sensitive
parent 6b9d281b
......@@ -28,6 +28,10 @@
typedef struct _belle_sip_parameters belle_sip_parameters_t;
belle_sip_parameters_t* belle_sip_parameters_new();
/*
* remove all parameters */
void belle_sip_parameters_clean(belle_sip_parameters_t* params);
const char* belle_sip_parameters_get_parameter(const belle_sip_parameters_t* obj,const char* name);
/**
......
......@@ -711,7 +711,7 @@ void belle_sip_response_get_return_hop(belle_sip_response_t *msg, belle_sip_hop_
#define IS_TOKEN(token) \
(INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token)))->chars ?\
strcmp(#token,(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token)))->chars)) == 0:0)
strcasecmp(#token,(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token)))->chars)) == 0:0)
char* _belle_sip_str_dup_and_unquote_string(const char* quoted_string);
/*********************************************************
......
......@@ -1044,41 +1044,41 @@ catch [ANTLR3_MISMATCHED_TOKEN_EXCEPTION]
header_extension[ANTLR3_BOOLEAN check_for_known_header] returns [belle_sip_header_t* ret]
: header_name
hcolon
header_value {if (check_for_known_header && strcmp("Contact",(const char*)$header_name.text->chars) == 0) {
header_value {if (check_for_known_header && strcasecmp("Contact",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_contact_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("From",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("From",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_from_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("To",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("To",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_to_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Call-ID",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("Call-ID",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_call_id_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Content-Length",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("Content-Length",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_content_length_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Content-Type",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("Content-Type",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_content_type_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("CSeq",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("CSeq",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_cseq_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Route",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("Route",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_route_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Record-Route",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("Record-Route",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_record_route_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Via",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("Via",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_via_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Authorization",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("Authorization",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_authorization_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Proxy-Authorization",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("Proxy-Authorization",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_proxy_authorization_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("WWW-Authenticate",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("WWW-Authenticate",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_www_authenticate_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Proxy-Authenticate",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("Proxy-Authenticate",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_proxy_authenticate_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Max-Forwards",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("Max-Forwards",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_max_forwards_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("User-Agent",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("User-Agent",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_user_agent_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Expires",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("Expires",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_expires_parse((const char*)$header_extension.text->chars));
} else if (check_for_known_header && strcmp("Allow",(const char*)$header_name.text->chars) == 0) {
} else if (check_for_known_header && strcasecmp("Allow",(const char*)$header_name.text->chars) == 0) {
$ret = BELLE_SIP_HEADER(belle_sip_header_allow_parse((const char*)$header_extension.text->chars));
}else {
$ret = BELLE_SIP_HEADER(belle_sip_header_extension_new());
......
......@@ -51,7 +51,7 @@ belle_sip_object_t * belle_sip_object_ref(void *obj){
void belle_sip_object_unref(void *ptr){
belle_sip_object_t *obj=BELLE_SIP_OBJECT(ptr);
if (obj->ref==-1) belle_sip_fatal("Object freed twice !");
if (obj->ref==-1) belle_sip_fatal("Object of type [%s] freed twice !",obj->name);
if (obj->ref==0){
obj->ref=-1;
belle_sip_object_delete(obj);
......
......@@ -23,9 +23,14 @@
void belle_sip_parameters_init(belle_sip_parameters_t *obj){
}
static void belle_sip_parameters_destroy(belle_sip_parameters_t* params) {
void belle_sip_parameters_clean(belle_sip_parameters_t* params) {
if (params->param_list) belle_sip_list_free_with_data (params->param_list, (void (*)(void*))belle_sip_param_pair_destroy);
if (params->paramnames_list) belle_sip_list_free(params->paramnames_list);
params->paramnames_list=NULL;
params->param_list=NULL;
}
static void belle_sip_parameters_destroy(belle_sip_parameters_t* params) {
belle_sip_parameters_clean(params);
}
static void belle_sip_parameters_clone(belle_sip_parameters_t *params, const belle_sip_parameters_t *orig){
......
......@@ -288,6 +288,11 @@ belle_sip_dialog_t *belle_sip_dialog_new(belle_sip_transaction_t *t){
obj->route_set=belle_sip_list_append(obj->route_set,belle_sip_object_ref(predefined_routes->data));
}
}
belle_sip_message("New %s dialog [%x] , local tag [%s], remote tag [%s]"
,obj->is_server?"server":"client"
,obj
,obj->local_tag
,obj->remote_tag);
obj->state=BELLE_SIP_DIALOG_NULL;
return obj;
}
......@@ -327,15 +332,18 @@ belle_sip_request_t *belle_sip_dialog_create_request(belle_sip_dialog_t *obj, co
belle_sip_header_to_create(obj->remote_party,NULL),
belle_sip_header_via_new(),
0);
if (obj->route_set) belle_sip_message_add_headers((belle_sip_message_t*)req,obj->route_set);
if (obj->route_set) {
belle_sip_list_for_each(obj->route_set,(void (*)(void *) )belle_sip_object_ref);/*don't forget to inc ref count*/
belle_sip_message_add_headers((belle_sip_message_t*)req,obj->route_set);
}
if (strcmp(method,"ACK")!=0) obj->local_cseq++;
return req;
}
void belle_sip_dialog_delete(belle_sip_dialog_t *obj){
belle_sip_dialog_state_t prevstate=obj->state;
/*belle_sip_dialog_state_t prevstate=obj->state;*/
obj->state=BELLE_SIP_DIALOG_TERMINATED;
if (prevstate!=BELLE_SIP_DIALOG_NULL)
/*if (prevstate!=BELLE_SIP_DIALOG_NULL) why only removing non NULL dialog*/
belle_sip_provider_remove_dialog(obj->provider,obj);
}
......@@ -435,8 +443,9 @@ int belle_sip_dialog_match(belle_sip_dialog_t *obj, belle_sip_message_t *msg, in
}
int _belle_sip_dialog_match(belle_sip_dialog_t *obj, const char *call_id, const char *local_tag, const char *remote_tag){
const char *dcid=belle_sip_header_call_id_get_call_id(obj->call_id);
const char *dcid;
if (obj->state==BELLE_SIP_DIALOG_NULL) belle_sip_fatal("_belle_sip_dialog_match() must not be used for dialog in null state.");
dcid=belle_sip_header_call_id_get_call_id(obj->call_id);
return strcmp(dcid,call_id)==0 && strcmp(obj->local_tag,local_tag)==0 && strcmp(obj->remote_tag,remote_tag)==0;
}
......
......@@ -86,7 +86,7 @@ static void belle_sip_provider_dispatch_request(belle_sip_provider_t* prov, bell
ev.dialog=NULL;
/* Should we limit to ACK ? if (strcmp("ACK",belle_sip_request_get_method(req))==0) */
/*Search for a dialog if exist */
ev.dialog=belle_sip_provider_find_dialog(prov,req,0);
ev.dialog=belle_sip_provider_find_dialog(prov,req,1/*request=uas*/);
ev.source=prov;
ev.server_transaction=NULL;
......@@ -289,6 +289,7 @@ belle_sip_dialog_t * belle_sip_provider_create_dialog(belle_sip_provider_t *prov
belle_sip_dialog_t *belle_sip_provider_find_dialog(belle_sip_provider_t *prov, belle_sip_request_t *msg, int as_uas){
belle_sip_list_t *elem;
belle_sip_dialog_t *dialog;
belle_sip_dialog_t *returned_dialog=NULL;
belle_sip_header_call_id_t *call_id;
belle_sip_header_from_t *from;
belle_sip_header_to_t *to=belle_sip_message_get_header_by_type(msg,belle_sip_header_to_t);
......@@ -315,10 +316,15 @@ belle_sip_dialog_t *belle_sip_provider_find_dialog(belle_sip_provider_t *prov, b
for (elem=prov->dialogs;elem!=NULL;elem=elem->next){
dialog=(belle_sip_dialog_t*)elem->data;
if (_belle_sip_dialog_match(dialog,call_id_value,local_tag,remote_tag))
return dialog;
/*ignore dialog in state BELLE_SIP_DIALOG_NULL, is it really the correct things to do*/
if (belle_sip_dialog_get_state(dialog) != BELLE_SIP_DIALOG_NULL && _belle_sip_dialog_match(dialog,call_id_value,local_tag,remote_tag)) {
if (!returned_dialog)
returned_dialog=dialog;
else
belle_sip_fatal("More than 1 dialog is matching, check your app");
}
}
return NULL;
return returned_dialog;
}
void belle_sip_provider_add_dialog(belle_sip_provider_t *prov, belle_sip_dialog_t *dialog){
......
......@@ -475,6 +475,19 @@ static void test_header_address_with_error() {
belle_sip_header_address_t* laddress = belle_sip_header_address_parse("sip:liblinphone_tester@=auth1.example.org");
CU_ASSERT_PTR_NULL(laddress);
}
static void test_header_address() {
belle_sip_header_address_t* laddress = belle_sip_header_address_parse("\"toto\" <sip:liblinphone_tester@81.56.11.2:5060>");
CU_ASSERT_PTR_NOT_NULL_FATAL(laddress);
CU_ASSERT_STRING_EQUAL("toto",belle_sip_header_address_get_displayname(laddress))
belle_sip_uri_t* L_uri = belle_sip_header_address_get_uri(laddress);
CU_ASSERT_PTR_NOT_NULL(belle_sip_uri_get_user(L_uri));
CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "81.56.11.2");
CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri), "liblinphone_tester");
CU_ASSERT_EQUAL(belle_sip_uri_get_port(L_uri), 5060);
belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
}
int belle_sip_headers_test_suite() {
CU_pSuite pSuite = NULL;
......@@ -546,5 +559,8 @@ int belle_sip_headers_test_suite() {
if (NULL == CU_add_test(pSuite, "test header address with error",test_header_address_with_error )) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "test-header-address",test_header_address )) {
return CU_get_error();
}
return 0;
}
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