Commit 01c0c39d authored by Simon Morlat's avatar Simon Morlat
Browse files

Merge branch 'dev_sipuri_rework'

parents b27fe32e 80c9250e
......@@ -1594,7 +1594,7 @@ static void escaped_to_ascii(const char*a,char*b,size_t n) {
size_t index_a=0,index_b=0;
while (a[index_a]!='\0'&& index_a<n)
index_a+=belle_sip_get_char(a+index_a,n-index_a,b+index_b++);
index_a+=belle_sip_get_char(a+index_a,b+index_b++);
}
#define REPLACES_PREF_OFFSET (strlen(BELLE_SIP_REPLACES)+2)
......
......@@ -959,7 +959,7 @@ belle_sip_refresher_t* belle_sip_refresher_new(belle_sip_client_transaction_t* t
/*
* returns a char, even if entry is escaped*/
size_t belle_sip_get_char (const char*a,size_t n,char*out);
size_t belle_sip_get_char (const char*a,char*out);
/*return an escaped string*/
BELLESIP_INTERNAL_EXPORT char* belle_sip_uri_to_escaped_username(const char* buff) ;
BELLESIP_INTERNAL_EXPORT char* belle_sip_uri_to_escaped_userpasswd(const char* buff) ;
......
......@@ -240,37 +240,39 @@ void belle_sip_uri_headers_clean(belle_sip_uri_t* uri) {
}
static int uri_strncmp_common(const char*a,const char*b,size_t n,int case_sensitive) {
int result=0;
static int uri_strcmp(const char*a,const char*b,int case_sensitive) {
int result = 0;
size_t index_a=0,index_b=0;
char char_a,char_b;
if (a == NULL && b == NULL) {
goto end;
}
if ((a != NULL && b == NULL) || (a == NULL && b != NULL)){
result = 1;
goto end;
}
while (a[index_a]!='\0'&&b[index_b]!='\0'&&index_a<n&&index_b<n) {
index_a+=belle_sip_get_char(a+index_a,n-index_a,&char_a);
index_b+=belle_sip_get_char(b+index_b,n-index_b,&char_b);
do {
index_a+=belle_sip_get_char(a+index_a,&char_a);
index_b+=belle_sip_get_char(b+index_b,&char_b);
if (!case_sensitive && char_a<0x7B && char_a>0x60) char_a-=0x20;
if (!case_sensitive && char_b<0x7B && char_b>0x60) char_b-=0x20;
result+=(char_a!=char_b);
}
result=(char_a!=char_b);
if (result) break;
if (char_a == '\0' || char_b == '\0') break;
}while(1);
end:
return result;
}
static int uri_strncmp(const char*a,const char*b,size_t n) {
return uri_strncmp_common(a,b,n,1);
}
static int uri_strncasecmp(const char*a,const char*b,size_t n) {
return uri_strncmp_common(a,b,n,0);
}
#define IS_EQUAL(a,b) uri_strncmp(a,b,MIN(strlen(a),strlen(b)))!=0
#define IS_EQUAL_CASE(a,b) uri_strncasecmp(a,b,MIN(strlen(a),strlen(b)))!=0
#define IS_EQUAL(a,b) (uri_strcmp(a,b,TRUE)==0)
#define IS_EQUAL_CASE(a,b) (uri_strcmp(a,b,FALSE)==0)
#define PARAM_CASE_CMP(uri_a,uri_b,param) \
a_param=belle_sip_parameters_get_case_parameter((belle_sip_parameters_t*) uri_a,param); \
b_param=belle_sip_parameters_get_case_parameter((belle_sip_parameters_t*) uri_b,param);\
if (a_param && b_param) { \
if (IS_EQUAL_CASE(a_param,b_param)) return 0; \
} else if (a_param != b_param) {\
return 0;\
}
if (!IS_EQUAL_CASE(a_param,b_param)) return 0;
/*
* RFC 3261 SIP: Session Initiation Protocol June 2002
......@@ -299,11 +301,8 @@ int belle_sip_uri_equals(const belle_sip_uri_t* uri_a,const belle_sip_uri_t* uri
components of the URI is case-insensitive unless explicitly
defined otherwise.
*/
if (uri_a->user && uri_b->user) {
if (IS_EQUAL(uri_a->user,uri_b->user)) return 0;
} else if (uri_a->user != uri_b->user) {
return 0;
}
if (!IS_EQUAL(uri_a->user,uri_b->user)) return 0;
/*
o The ordering of parameters and header fields is not significant
in comparing SIP and SIPS URIs.
......@@ -317,12 +316,10 @@ int belle_sip_uri_equals(const belle_sip_uri_t* uri_a,const belle_sip_uri_t* uri
o For two URIs to be equal, the user, password, host, and port
components must match.
*/
if (!uri_a->host || !uri_b->host) {
return 0;
} else if (IS_EQUAL_CASE(uri_a->host,uri_b->host)) {
return 0;
}
if (uri_a->port !=uri_b->port) return 0;
if (!IS_EQUAL_CASE(uri_a->host,uri_b->host)) {
return 0;
}
if (uri_a->port != uri_b->port) return 0;
/*
A URI omitting the user component will not match a URI that
includes one. A URI omitting the password component will not
......@@ -352,19 +349,18 @@ int belle_sip_uri_equals(const belle_sip_uri_t* uri_a,const belle_sip_uri_t* uri
- A URI that includes an maddr parameter will not match a URI
that contains no maddr parameter.
* */
PARAM_CASE_CMP(uri_a,uri_b,"transport")
PARAM_CASE_CMP(uri_a,uri_b,"user")
PARAM_CASE_CMP(uri_a,uri_b,"ttl")
PARAM_CASE_CMP(uri_a,uri_b,"method")
PARAM_CASE_CMP(uri_a,uri_b,"maddr")
PARAM_CASE_CMP(uri_a,uri_b,"transport")
PARAM_CASE_CMP(uri_a,uri_b,"user")
PARAM_CASE_CMP(uri_a,uri_b,"ttl")
PARAM_CASE_CMP(uri_a,uri_b,"method")
PARAM_CASE_CMP(uri_a,uri_b,"maddr")
for(params=belle_sip_parameters_get_parameters((belle_sip_parameters_t*) uri_a);params!=NULL;params=params->next) {
if ((b_param=belle_sip_parameters_get_parameter((belle_sip_parameters_t*) uri_b,(const char*)params->data)) !=NULL) {
if (IS_EQUAL_CASE(b_param,(const char*)params->data)) return 0;
}
for(params=belle_sip_parameters_get_parameters((belle_sip_parameters_t*) uri_a);params!=NULL;params=params->next) {
if ((b_param=belle_sip_parameters_get_parameter((belle_sip_parameters_t*) uri_b,(const char*)params->data)) != NULL) {
if (!IS_EQUAL_CASE(b_param,(const char*)params->data)) return 0;
}
}
/*
......
......@@ -355,8 +355,12 @@ void belle_sip_util_copy_headers(belle_sip_message_t *orig, belle_sip_message_t
}
}
size_t belle_sip_get_char (const char*a,size_t n,char*out) {
if (*a=='%' && n>2) {
static int is_escaped_char(const char *a){
return a[0] == '%' && a[1] != '\0' && a[2] != '\0';
}
size_t belle_sip_get_char (const char*a, char*out) {
if (is_escaped_char(a)) {
unsigned int tmp;
sscanf(a+1,"%02x",&tmp);
*out=(char)tmp;
......@@ -373,7 +377,7 @@ char* belle_sip_to_unescaped_string(const char* buff) {
size_t out_buff_index=0;
for(i=0; buff[i]!='\0'; out_buff_index++) {
i+=belle_sip_get_char(buff+i,3,output_buff+out_buff_index);
i+=belle_sip_get_char(buff+i,output_buff+out_buff_index);
}
output_buff[out_buff_index]='\0';
return output_buff;
......
......@@ -351,6 +351,14 @@ static void test_uri_equals(void) {
BC_ASSERT_FALSE(belle_sip_uri_equals(a,b));
belle_sip_object_unref(a);
belle_sip_object_unref(b);
a = belle_sip_uri_parse("sip:bob@biloxi.com");
if (!BC_ASSERT_PTR_NOT_NULL(a)) return;
b = belle_sip_uri_parse("sip:boba@biloxi.com");
if (!BC_ASSERT_PTR_NOT_NULL(b)) return;
BC_ASSERT_FALSE(belle_sip_uri_equals(a,b));
belle_sip_object_unref(a);
belle_sip_object_unref(b);
/* sip:carol@chicago.com (different header component)
sip:carol@chicago.com?Subject=next%20meeting
......
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