Commit 0cbcd848 authored by jehan's avatar jehan

add support of backslashed escaped display name

parent 6dd817ae
......@@ -199,7 +199,9 @@ static belle_sip_error_code _belle_sip_header_address_marshal(belle_sip_header_a
belle_sip_error_code error=BELLE_SIP_OK;
/*1 display name*/
if (header->displayname) {
error=belle_sip_snprintf(buff,buff_size,offset,"\"%s\" ",header->displayname);
char* escaped_display_name = belle_sip_display_name_to_backslashed_escaped_string(header->displayname);
error=belle_sip_snprintf(buff,buff_size,offset,"\"%s\" ",escaped_display_name);
belle_sip_free(escaped_display_name);
if (error!=BELLE_SIP_OK) return error;
}
if (header->uri) {
......
......@@ -1045,3 +1045,33 @@ char* belle_generic_uri_to_escaped_path(const char* buff) {
return belle_sip_escape(buff, get_generic_uri_path_noescapes());
}
char* belle_sip_string_to_backslash_less_unescaped_string(const char* buff) {
char *output_buff=belle_sip_malloc(strlen(buff)+1);
unsigned int i;
unsigned int out_buff_index=0;
for(i=0; buff[i] != '\0'; i++) {
if (buff[i] == '\\') {
i++;/*skip \*/
}
/*make sure to only remove one \ in case of \\*/
output_buff[out_buff_index++]=buff[i];
}
output_buff[out_buff_index]='\0';
return output_buff;
}
char* belle_sip_display_name_to_backslashed_escaped_string(const char* buff) {
char output_buff[BELLE_SIP_MAX_TO_STRING_SIZE];
unsigned int i;
unsigned int out_buff_index=0;
for(i=0; buff[i] != '\0' && out_buff_index < sizeof(output_buff)-2; i++) {
/*-3 to make sure last param can be stored in escaped form*/
const char c = buff[i];
if (c == '\"' || c == '\\') {
output_buff[out_buff_index++]='\\'; /*insert escape character*/
}
output_buff[out_buff_index++]=c;
}
output_buff[out_buff_index]='\0';
return belle_sip_strdup(output_buff);
}
......@@ -391,7 +391,7 @@ gen_value
quoted_string
options { greedy = false; }
: DQUOTE unquoted_value=(.*) DQUOTE ;
: DQUOTE (~(DQUOTE | BSLASH) | (BSLASH .))* DQUOTE ;
/*
accept_encoding
......@@ -645,7 +645,12 @@ paramless_addr_spec[belle_sip_header_address_t* object]
display_name[belle_sip_header_address_t* object]
: token {belle_sip_header_address_set_displayname(object,(const char*)($token.text->chars));}
| quoted_string {belle_sip_header_address_set_quoted_displayname(object,(const char*)($quoted_string.text->chars));}
| quoted_string
{
char* unescaped_char = belle_sip_string_to_backslash_less_unescaped_string((const char*)($quoted_string.text->chars));
belle_sip_header_address_set_quoted_displayname(object,(const char*)unescaped_char);
belle_sip_free(unescaped_char);
}
;
contact_params
......
......@@ -37,4 +37,17 @@ BELLESIP_INTERNAL_EXPORT void belle_sip_header_set_next(belle_sip_header_t* head
BELLESIP_INTERNAL_EXPORT char* belle_sip_to_unescaped_string(const char* buff);
belle_sip_param_pair_t* belle_sip_param_pair_new(const char* name,const char* value);
char* _belle_sip_str_dup_and_unquote_string(const char* quoted_string);
/**
* quoted-string = SWS DQUOTE *(qdtext / quoted-pair ) DQUOTE
qdtext = LWS / %x21 / %x23-5B / %x5D-7E
/ UTF8-NONASCII
quoted-pair = "\" (%x00-09 / %x0B-0C
/ %x0E-7F)
remove any \
* */
BELLESIP_INTERNAL_EXPORT char* belle_sip_string_to_backslash_less_unescaped_string(const char* buff);
BELLESIP_INTERNAL_EXPORT char* belle_sip_display_name_to_backslashed_escaped_string(const char* buff);
#endif
......@@ -616,8 +616,15 @@ static void test_address_with_error_header(void) {
static void test_address_header(void) {
belle_sip_uri_t* L_uri;
char* L_raw;
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_PTR_NOT_NULL(laddress);
L_raw = belle_sip_object_to_string(BELLE_SIP_OBJECT(laddress));
CU_ASSERT_PTR_NOT_NULL(L_raw);
belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
laddress = belle_sip_header_address_parse(L_raw);
belle_sip_free(L_raw);
CU_ASSERT_STRING_EQUAL("toto",belle_sip_header_address_get_displayname(laddress))
L_uri = belle_sip_header_address_get_uri(laddress);
......@@ -626,6 +633,19 @@ static void test_address_header(void) {
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));
laddress = belle_sip_header_address_parse("\"\\\"to\\\\to\\\"\" <sip:liblinphone_tester@81.56.11.2:5060>");
CU_ASSERT_PTR_NOT_NULL(laddress);
L_raw = belle_sip_object_to_string(BELLE_SIP_OBJECT(laddress));
CU_ASSERT_PTR_NOT_NULL(L_raw);
belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
laddress = belle_sip_header_address_parse(L_raw);
belle_sip_free(L_raw);
CU_ASSERT_STRING_EQUAL("\"to\\to\"",belle_sip_header_address_get_displayname(laddress))
belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
}
static void test_very_long_address_header(void) {
......
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