Commit 5b3a6d54 authored by jehan's avatar jehan

implement escaped form of username: ref 0000577: username in both URI/SDP must...

implement escaped form of username: ref 0000577: username in both URI/SDP must be automatically escaped
parent f3651773
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
<folderInfo id="cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290." name="/" resourcePath=""> <folderInfo id="cdt.managedbuild.toolchain.gnu.macosx.base.557244179.959032290." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.macosx.base.1209613831" name="cdt.managedbuild.toolchain.gnu.macosx.base" superClass="cdt.managedbuild.toolchain.gnu.macosx.base"> <toolChain id="cdt.managedbuild.toolchain.gnu.macosx.base.1209613831" name="cdt.managedbuild.toolchain.gnu.macosx.base" superClass="cdt.managedbuild.toolchain.gnu.macosx.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.MachO64" id="cdt.managedbuild.target.gnu.platform.macosx.base.973927327" name="Debug Platform" osList="macosx" superClass="cdt.managedbuild.target.gnu.platform.macosx.base"/> <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.MachO64" id="cdt.managedbuild.target.gnu.platform.macosx.base.973927327" name="Debug Platform" osList="macosx" superClass="cdt.managedbuild.target.gnu.platform.macosx.base"/>
<builder arguments="-j2 CFLAGS=&quot;-g -Wall &quot;" command="make" id="cdt.managedbuild.target.gnu.builder.macosx.base.190701400" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.macosx.base"/> <builder arguments="CFLAGS=&quot;-g -Wall &quot;" command="make" id="cdt.managedbuild.target.gnu.builder.macosx.base.190701400" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="cdt.managedbuild.target.gnu.builder.macosx.base"/>
<tool id="cdt.managedbuild.tool.macosx.c.linker.macosx.base.419159753" name="MacOS X C Linker" superClass="cdt.managedbuild.tool.macosx.c.linker.macosx.base"> <tool id="cdt.managedbuild.tool.macosx.c.linker.macosx.base.419159753" name="MacOS X C Linker" superClass="cdt.managedbuild.tool.macosx.c.linker.macosx.base">
<inputType id="cdt.managedbuild.tool.macosx.c.linker.input.1079464415" superClass="cdt.managedbuild.tool.macosx.c.linker.input"> <inputType id="cdt.managedbuild.tool.macosx.c.linker.input.1079464415" superClass="cdt.managedbuild.tool.macosx.c.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/> <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
...@@ -74,6 +74,10 @@ ...@@ -74,6 +74,10 @@
<tool id="cdt.managedbuild.tool.gnu.archiver.macosx.base.84823320" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.macosx.base"/> <tool id="cdt.managedbuild.tool.gnu.archiver.macosx.base.84823320" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.macosx.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base.1713349409" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base"/> <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base.1713349409" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.macosx.base"/>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.macosx.base.3940526" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.macosx.base"> <tool id="cdt.managedbuild.tool.gnu.c.compiler.macosx.base.3940526" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.macosx.base">
<option id="gnu.c.compiler.option.preprocessor.def.symbols.1609070473" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols"/>
<option id="gnu.c.compiler.option.preprocessor.undef.symbol.1484649451" name="Undefined symbols (-U)" superClass="gnu.c.compiler.option.preprocessor.undef.symbol" valueType="undefDefinedSymbols">
<listOptionValue builtIn="false" value="__cplusplus"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.2089521215" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.2089521215" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool> </tool>
</toolChain> </toolChain>
...@@ -292,4 +296,5 @@ ...@@ -292,4 +296,5 @@
</profile> </profile>
</scannerConfigBuildInfo> </scannerConfigBuildInfo>
</storageModule> </storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
</cproject> </cproject>
...@@ -30,7 +30,7 @@ config.h ...@@ -30,7 +30,7 @@ config.h
*Parser.h *Parser.h
*Parser.c *Parser.c
*.tokens *.tokens
src/specs.cpp src/specs.c
...@@ -79,6 +79,6 @@ EXTRA_DIST=$(grammar_files) ...@@ -79,6 +79,6 @@ EXTRA_DIST=$(grammar_files)
CLEANFILES=$(generated_src) *.tokens generated_src_stamp CLEANFILES=$(generated_src) *.tokens generated_src_stamp
discovery: discovery:
touch specs.cpp touch specs.c
$(CC) $(CFLAGS) -include $(top_builddir)/config.h $(ANTLR_CFLAGS) $(CUNIT_CFLAGS) $(TLS_CFLAGS) -E -P -v -dD specs.cpp $(CC) $(CFLAGS) -include $(top_builddir)/config.h $(ANTLR_CFLAGS) $(CUNIT_CFLAGS) $(TLS_CFLAGS) -E -P -v -dD specs.c
...@@ -1273,58 +1273,13 @@ belle_sip_header_replaces_t* belle_sip_header_replaces_create2(const char* escap ...@@ -1273,58 +1273,13 @@ belle_sip_header_replaces_t* belle_sip_header_replaces_create2(const char* escap
} }
char* belle_sip_header_replaces_value_to_escaped_string(const belle_sip_header_replaces_t* replaces) { char* belle_sip_header_replaces_value_to_escaped_string(const belle_sip_header_replaces_t* replaces) {
char buff[BELLE_SIP_MAX_TO_STRING_SIZE]; char buff[BELLE_SIP_MAX_TO_STRING_SIZE];
char output_buff[BELLE_SIP_MAX_TO_STRING_SIZE];
unsigned int i;
unsigned int out_buff_index=0;
size_t buff_size=sizeof(buff); size_t buff_size=sizeof(buff);
unsigned int current_offset=0; unsigned int current_offset=0;
output_buff[BELLE_SIP_MAX_TO_STRING_SIZE-1]='\0';
/*first, marshall callid/from/to tags*/ /*first, marshall callid/from/to tags*/
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",replaces->call_id); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",replaces->call_id);
current_offset+=belle_sip_parameters_marshal(BELLE_SIP_PARAMETERS(replaces), buff,current_offset, buff_size); current_offset+=belle_sip_parameters_marshal(BELLE_SIP_PARAMETERS(replaces), buff,current_offset, buff_size);
for(i=0;i<current_offset&&i<BELLE_SIP_MAX_TO_STRING_SIZE-4 /*to make sure last param can be stored in escaped form*/;i++) { buff[current_offset]='\0';
return belle_sip_to_escaped_string(buff);
/*hvalue = *( hnv-unreserved / unreserved / escaped )
hnv-unreserved = "[" / "]" / "/" / "?" / ":" / "+" / "$"
unreserved = alphanum / mark
mark = "-" / "_" / "." / "!" / "~" / "*" / "'"
/ "(" / ")"*/
switch(buff[i]) {
case '[' :
case ']' :
case '/' :
case '?' :
case ':' :
case '+' :
case '$' :
case '-' :
case '_' :
case '.' :
case '!' :
case '~' :
case '*' :
case '\'' :
case '(' :
case ')' :
output_buff[out_buff_index++]=buff[i];
break;
default:
/*serach for alfanum*/
if ((buff[i]>='0' && buff[i]<='9')
|| (buff[i]>='A' && buff[i]<='Z')
|| (buff[i]>='a' && buff[i]<='z')
|| (buff[i]=='\0')) {
output_buff[out_buff_index++]=buff[i];
} else {
out_buff_index+=sprintf(output_buff+out_buff_index,"%%%02x",buff[i]);
}
break;
}
}
output_buff[out_buff_index]='\0';
return belle_sip_strdup(output_buff);
} }
belle_sip_header_replaces_t* belle_sip_header_replaces_create(const char* call_id,const char* from_tag,const char* to_tag) { belle_sip_header_replaces_t* belle_sip_header_replaces_create(const char* call_id,const char* from_tag,const char* to_tag) {
belle_sip_header_replaces_t* replaces=belle_sip_header_replaces_new(); belle_sip_header_replaces_t* replaces=belle_sip_header_replaces_new();
......
...@@ -220,10 +220,6 @@ void belle_sip_source_uninit(belle_sip_source_t *s); ...@@ -220,10 +220,6 @@ void belle_sip_source_uninit(belle_sip_source_t *s);
#include "channel.h" #include "channel.h"
#ifdef __cplusplus
extern "C" {
#endif
#define belle_sip_new(type) (type*)belle_sip_malloc(sizeof(type)) #define belle_sip_new(type) (type*)belle_sip_malloc(sizeof(type))
...@@ -831,14 +827,15 @@ belle_sip_auth_event_t* belle_sip_auth_event_create(const char* realm,const char ...@@ -831,14 +827,15 @@ belle_sip_auth_event_t* belle_sip_auth_event_create(const char* realm,const char
* refresher * refresher
* */ * */
belle_sip_refresher_t* belle_sip_refresher_new(belle_sip_client_transaction_t* transaction); belle_sip_refresher_t* belle_sip_refresher_new(belle_sip_client_transaction_t* transaction);
#ifdef __cplusplus
}
#endif
/* /*
* returns a char, even if entry is escaped*/ * returns a char, even if entry is escaped*/
int belle_sip_get_char (const char*a,int n,char*out); int belle_sip_get_char (const char*a,int n,char*out);
/*return an escaped string*/
char* belle_sip_to_escaped_string(const char* buff) ;
char* belle_sip_to_unescaped_string(const char* buff) ;
/*include private headers */ /*include private headers */
#include "belle_sip_resolver.h" #include "belle_sip_resolver.h"
......
...@@ -1244,7 +1244,12 @@ userinfo[belle_sip_uri_t* uri] ...@@ -1244,7 +1244,12 @@ userinfo[belle_sip_uri_t* uri]
scope { belle_sip_uri_t* current; } scope { belle_sip_uri_t* current; }
@init {$userinfo::current=uri;} @init {$userinfo::current=uri;}
: user ( COLON password )? '@' ; : user ( COLON password )? '@' ;
user : ( unreserved | escaped | user_unreserved )+ {belle_sip_uri_set_user($userinfo::current,(const char *)$text->chars);}; user : ( unreserved | escaped | user_unreserved )+ {
char* unescaped_username;
unescaped_username=belle_sip_to_unescaped_string((const char *)$text->chars);
belle_sip_uri_set_user($userinfo::current,unescaped_username);
belle_sip_free(unescaped_username);
};
user_unreserved : '&' | EQUAL | '+' | '$' | COMMA | SEMI | '?' | SLASH; user_unreserved : '&' | EQUAL | '+' | '$' | COMMA | SEMI | '?' | SLASH;
password : ( unreserved |'&' | EQUAL | '+' | '$' | COMMA )*; password : ( unreserved |'&' | EQUAL | '+' | '$' | COMMA )*;
hostport[belle_sip_uri_t* uri] hostport[belle_sip_uri_t* uri]
......
...@@ -75,7 +75,9 @@ int belle_sip_uri_marshal(const belle_sip_uri_t* uri, char* buff,unsigned int of ...@@ -75,7 +75,9 @@ int belle_sip_uri_marshal(const belle_sip_uri_t* uri, char* buff,unsigned int of
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s:",uri->secure?"sips":"sip"); current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s:",uri->secure?"sips":"sip");
if (uri->user) { if (uri->user) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s@",uri->user); char* escaped_username=belle_sip_to_escaped_string(uri->user);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s@",escaped_username);
belle_sip_free(escaped_username);
} }
if (uri->host) { if (uri->host) {
if (strchr(uri->host,':')) { /*ipv6*/ if (strchr(uri->host,':')) { /*ipv6*/
......
...@@ -665,3 +665,62 @@ int belle_sip_get_char (const char*a,int n,char*out) { ...@@ -665,3 +665,62 @@ int belle_sip_get_char (const char*a,int n,char*out) {
} }
return result; return result;
} }
char* belle_sip_to_unescaped_string(const char* buff) {
char output_buff[BELLE_SIP_MAX_TO_STRING_SIZE];
unsigned int i;
unsigned int out_buff_index=0;
output_buff[BELLE_SIP_MAX_TO_STRING_SIZE-1]='\0';
for(i=0;buff[i]!='\0' &&i<BELLE_SIP_MAX_TO_STRING_SIZE /*to make sure last param can be stored in escaped form*/;) {
i+=belle_sip_get_char(buff+i,3,output_buff+out_buff_index++);
}
output_buff[out_buff_index]='\0';
return belle_sip_strdup(output_buff);
}
char* belle_sip_to_escaped_string(const char* buff) {
char output_buff[BELLE_SIP_MAX_TO_STRING_SIZE];
unsigned int i;
unsigned int out_buff_index=0;
output_buff[BELLE_SIP_MAX_TO_STRING_SIZE-1]='\0';
for(i=0;buff[i]!='\0' &&i<BELLE_SIP_MAX_TO_STRING_SIZE-4 /*to make sure last param can be stored in escaped form*/;i++) {
/*hvalue = *( hnv-unreserved / unreserved / escaped )
hnv-unreserved = "[" / "]" / "/" / "?" / ":" / "+" / "$"
unreserved = alphanum / mark
mark = "-" / "_" / "." / "!" / "~" / "*" / "'"
/ "(" / ")"*/
switch(buff[i]) {
case '[' :
case ']' :
case '/' :
case '?' :
case ':' :
case '+' :
case '$' :
case '-' :
case '_' :
case '.' :
case '!' :
case '~' :
case '*' :
case '\'' :
case '(' :
case ')' :
output_buff[out_buff_index++]=buff[i];
break;
default:
/*serach for alfanum*/
if ((buff[i]>='0' && buff[i]<='9')
|| (buff[i]>='A' && buff[i]<='Z')
|| (buff[i]>='a' && buff[i]<='z')
|| (buff[i]=='\0')) {
output_buff[out_buff_index++]=buff[i];
} else {
out_buff_index+=sprintf(output_buff+out_buff_index,"%%%02x",buff[i]);
}
break;
}
}
output_buff[out_buff_index]='\0';
return belle_sip_strdup(output_buff);
}
...@@ -180,6 +180,20 @@ static void testSIMPLEURI_error(void) { ...@@ -180,6 +180,20 @@ static void testSIMPLEURI_error(void) {
} }
static void test_escaped_username(void) {
belle_sip_uri_t* L_tmp;
belle_sip_uri_t * L_uri = belle_sip_uri_parse("sip:toto%40linphone.org@titi.com");
char* l_raw_uri = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_uri));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri));
L_tmp = belle_sip_uri_parse(l_raw_uri);
L_uri = BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
belle_sip_free(l_raw_uri);
CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_user(L_uri), "toto@linphone.org");
CU_ASSERT_STRING_EQUAL(belle_sip_uri_get_host(L_uri), "titi.com");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_uri));
}
static void test_uri_equals(void) { static void test_uri_equals(void) {
belle_sip_uri_t* a; belle_sip_uri_t* a;
belle_sip_uri_t* b; belle_sip_uri_t* b;
...@@ -298,6 +312,7 @@ static void test_uri_equals(void) { ...@@ -298,6 +312,7 @@ static void test_uri_equals(void) {
test_t uri_tests[] = { test_t uri_tests[] = {
{ "Simple URI", testSIMPLEURI }, { "Simple URI", testSIMPLEURI },
{ "Complex URI", testCOMPLEXURI }, { "Complex URI", testCOMPLEXURI },
{ "Escaped username", test_escaped_username },
{ "IP host", test_ip_host }, { "IP host", test_ip_host },
{ "lr", test_lr }, { "lr", test_lr },
{ "maddr", test_maddr }, { "maddr", test_maddr },
......
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