Commit 549173ff authored by jehan's avatar jehan

add basic support for absolute uri in reg uri, from, to header (including tel uri)

parent 380e0d2d
......@@ -137,6 +137,19 @@ BELLESIP_EXPORT char* belle_generic_uri_to_string(belle_generic_uri_t* uri) ;
BELLESIP_EXPORT belle_sip_error_code belle_generic_uri_marshal(const belle_generic_uri_t* uri, char* buff, size_t buff_size, size_t *offset);
/**
* gets opaque part of this uri if hierarchies part not detected.
*
*/
BELLESIP_EXPORT const char* belle_generic_uri_get_opaque_part(const belle_generic_uri_t* uri) ;
/**
* sets opaque part of this uri. Means hierarchies part is ignored if present.
*
*/
BELLESIP_EXPORT void belle_generic_uri_set_opaque_part(belle_generic_uri_t* uri,const char * opaque_part) ;
#define BELLE_GENERIC_URI(obj) BELLE_SIP_CAST(obj,belle_generic_uri_t)
......
......@@ -21,6 +21,7 @@
#include "belle-sip/defs.h"
#include "belle-sip/sip-uri.h"
#include "belle-sip/generic-uri.h"
#include "belle-sip/utils.h"
#include "belle-sip/parameters.h"
......@@ -46,17 +47,36 @@ BELLESIP_EXPORT belle_sip_header_address_t* belle_sip_header_address_new();
* */
BELLESIP_EXPORT belle_sip_header_address_t* belle_sip_header_address_create(const char* display, belle_sip_uri_t* uri);
/*
* creates an address from a display name and an absolute uri
* Note the uri not copied but only its ref count is incremented
* @param display display name. May be null.
* @param uri uri set to the newly created header_address
* @return
* */
BELLESIP_EXPORT belle_sip_header_address_t* belle_sip_header_address_create2(const char* display, belle_generic_uri_t* uri);
BELLESIP_EXPORT belle_sip_header_address_t* belle_sip_header_address_parse (const char* address) ;
/**
*
* returns a sip uri. A header address cannot have both a sip uri and an absolute uri.
*/
BELLESIP_EXPORT belle_sip_uri_t* belle_sip_header_address_get_uri(const belle_sip_header_address_t* address);
/**
*
* set an absolute uri. A header address cannot have both a sip uri and an absolute uri. This function also to absolute uri to NULL
*/
BELLESIP_EXPORT void belle_sip_header_address_set_uri(belle_sip_header_address_t* address, belle_sip_uri_t* uri);
/**
* returns an absolute uri. A header address cannot have both a sip uri and an absolute uri.
*/
BELLESIP_EXPORT belle_generic_uri_t* belle_sip_header_address_get_absolute_uri(const belle_sip_header_address_t* address);
/**
* set an absolute uri. A header address cannot have both a sip uri and an absolute uri. This function also to uri to NULL
*/
BELLESIP_EXPORT void belle_sip_header_address_set_absolute_uri(belle_sip_header_address_t* address, belle_generic_uri_t* uri);
/**
*
*/
......
......@@ -71,6 +71,19 @@ BELLESIP_EXPORT belle_sip_uri_t* belle_sip_request_extract_origin(const belle_si
*/
BELLESIP_EXPORT belle_sip_request_t * belle_sip_request_clone_with_body(const belle_sip_request_t *initial_req);
/**
* returns an absolute uri. A header address cannot have both a sip uri and an absolute uri.
*/
BELLESIP_EXPORT belle_generic_uri_t* belle_sip_request_get_absolute_uri(const belle_sip_request_t* req);
/**
* set an absolute uri. A header address cannot have both a sip uri and an absolute uri. This function also to uri to NULL
*/
BELLESIP_EXPORT void belle_sip_request_set_absolute_uri(belle_sip_request_t* req, belle_generic_uri_t* uri);
BELLESIP_EXPORT int belle_sip_message_is_response(const belle_sip_message_t *msg);
BELLESIP_EXPORT belle_sip_header_t *belle_sip_message_get_header(const belle_sip_message_t *msg, const char *header_name);
......
......@@ -178,6 +178,7 @@ struct _belle_sip_header_address {
belle_sip_parameters_t base;
char* displayname;
belle_sip_uri_t* uri;
belle_generic_uri_t* absolute_uri;
};
static void belle_sip_header_address_init(belle_sip_header_address_t* object){
......@@ -194,6 +195,9 @@ static void belle_sip_header_address_clone(belle_sip_header_address_t *addr, con
if (belle_sip_header_address_get_uri(orig)) {
belle_sip_header_address_set_uri(addr,BELLE_SIP_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_address_get_uri(orig)))));
}
if (belle_sip_header_address_get_absolute_uri(orig)) {
belle_sip_header_address_set_absolute_uri(addr,BELLE_GENERIC_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(belle_sip_header_address_get_absolute_uri(orig)))));
}
}
static belle_sip_error_code _belle_sip_header_address_marshal(belle_sip_header_address_t* header, char* buff, size_t buff_size, size_t *offset, int force_angle_quote) {
......@@ -205,18 +209,26 @@ static belle_sip_error_code _belle_sip_header_address_marshal(belle_sip_header_a
belle_sip_free(escaped_display_name);
if (error!=BELLE_SIP_OK) return error;
}
if (header->uri) {
if (header->uri || header->absolute_uri) {
/*cases where < is required*/
if (force_angle_quote || header->displayname
if (force_angle_quote
|| header->displayname
|| header->absolute_uri
|| belle_sip_parameters_get_parameter_names((belle_sip_parameters_t*)header->uri)
|| belle_sip_uri_get_header_names(header->uri)
|| belle_sip_parameters_get_parameter_names(&header->base)) {
error=belle_sip_snprintf(buff,buff_size,offset,"%s","<");
if (error!=BELLE_SIP_OK) return error;
}
error=belle_sip_uri_marshal(header->uri,buff,buff_size,offset);
if (header->uri) {
error=belle_sip_uri_marshal(header->uri,buff,buff_size,offset);
} else {
error=belle_generic_uri_marshal(header->absolute_uri,buff,buff_size,offset);
}
if (error!=BELLE_SIP_OK) return error;
if (force_angle_quote || header->displayname
if (force_angle_quote
|| header->displayname
|| header->absolute_uri
|| belle_sip_parameters_get_parameter_names((belle_sip_parameters_t*)header->uri)
|| belle_sip_uri_get_header_names(header->uri)
|| belle_sip_parameters_get_parameter_names(&header->base)) {
......@@ -250,11 +262,31 @@ belle_sip_uri_t* belle_sip_header_address_get_uri(const belle_sip_header_address
}
void belle_sip_header_address_set_uri(belle_sip_header_address_t* address, belle_sip_uri_t* uri) {
belle_sip_object_ref(uri);
if (uri) belle_sip_object_ref(uri);
if (address->uri){
belle_sip_object_unref(address->uri);
}
address->uri=uri;
if (address->absolute_uri && uri) {
belle_sip_warning("sip absolute uri [%p] already set for header_address [%p], cleaning it",address->absolute_uri, address);
belle_sip_header_address_set_absolute_uri(address,NULL);
}
}
belle_generic_uri_t* belle_sip_header_address_get_absolute_uri(const belle_sip_header_address_t* address) {
return address->absolute_uri;
}
void belle_sip_header_address_set_absolute_uri(belle_sip_header_address_t* address, belle_generic_uri_t* absolute_uri) {
belle_sip_object_ref(absolute_uri);
if (address->absolute_uri){
belle_sip_object_unref(address->absolute_uri);
}
address->absolute_uri=absolute_uri;
if (address->uri && absolute_uri) {
belle_sip_warning("sip uri [%p] already set for header_address [%p], cleaning it",address->uri, address);
belle_sip_header_address_set_uri(address,NULL);
}
}
belle_sip_header_address_t* belle_sip_header_address_create(const char* display, belle_sip_uri_t* uri) {
......@@ -264,6 +296,13 @@ belle_sip_header_address_t* belle_sip_header_address_create(const char* display,
return address;
}
belle_sip_header_address_t* belle_sip_header_address_create2(const char* display, belle_generic_uri_t* uri) {
belle_sip_header_address_t* address = belle_sip_header_address_new();
belle_sip_header_address_set_displayname(address,display);
belle_sip_header_address_set_absolute_uri(address,uri);
return address;
}
/******************************
* Extension header inherits from header
*
......
......@@ -603,6 +603,7 @@ struct _belle_sip_request {
belle_sip_message_t base;
char* method;
belle_sip_uri_t* uri;
belle_generic_uri_t *absolute_uri;
belle_sip_dialog_t *dialog;/*set if request was created by a dialog to avoid to search in dialog list*/
char *rfc2543_branch; /*computed 'branch' id in case we receive this request from an old RFC2543 stack*/
unsigned char dialog_queued;
......
......@@ -34,6 +34,7 @@ struct _belle_generic_uri {
int port;
char* path;
char* query;
char* opaque_part;
};
void belle_generic_uri_init(belle_generic_uri_t *uri) {
......@@ -47,6 +48,7 @@ static void belle_generic_uri_destroy(belle_generic_uri_t* uri) {
DESTROY_STRING(uri,host)
DESTROY_STRING(uri,path)
DESTROY_STRING(uri,query)
DESTROY_STRING(uri,opaque_part)
}
static void belle_generic_uri_clone(belle_generic_uri_t* uri, const belle_generic_uri_t *orig){
CLONE_STRING(belle_generic_uri,scheme,uri,orig)
......@@ -56,6 +58,7 @@ static void belle_generic_uri_clone(belle_generic_uri_t* uri, const belle_generi
uri->port=orig->port;
CLONE_STRING(belle_generic_uri,path,uri,orig)
CLONE_STRING(belle_generic_uri,query,uri,orig)
CLONE_STRING(belle_generic_uri,opaque_part,uri,orig)
}
belle_sip_error_code belle_generic_uri_marshal(const belle_generic_uri_t* uri, char* buff, size_t buff_size, size_t *offset) {
......@@ -65,55 +68,59 @@ belle_sip_error_code belle_generic_uri_marshal(const belle_generic_uri_t* uri, c
error=belle_sip_snprintf(buff,buff_size,offset,"%s:",uri->scheme);
if (error!=BELLE_SIP_OK) return error;
}
if (uri->host) {
error=belle_sip_snprintf(buff,buff_size,offset,"//");
if (uri->opaque_part) {
error=belle_sip_snprintf(buff,buff_size,offset,"%s",uri->opaque_part);
if (error!=BELLE_SIP_OK) return error;
}
} else {
if (uri->host) {
error=belle_sip_snprintf(buff,buff_size,offset,"//");
if (error!=BELLE_SIP_OK) return error;
}
if (uri->user) {
char* escaped_username=belle_sip_uri_to_escaped_username(uri->user);
error=belle_sip_snprintf(buff,buff_size,offset,"%s",escaped_username);
belle_sip_free(escaped_username);
if (error!=BELLE_SIP_OK) return error;
if (uri->user) {
char* escaped_username=belle_sip_uri_to_escaped_username(uri->user);
error=belle_sip_snprintf(buff,buff_size,offset,"%s",escaped_username);
belle_sip_free(escaped_username);
if (error!=BELLE_SIP_OK) return error;
if (uri->user_password) {
char* escaped_password=belle_sip_uri_to_escaped_userpasswd(uri->user_password);
error=belle_sip_snprintf(buff,buff_size,offset,":%s",escaped_password);
belle_sip_free(escaped_password);
if (uri->user_password) {
char* escaped_password=belle_sip_uri_to_escaped_userpasswd(uri->user_password);
error=belle_sip_snprintf(buff,buff_size,offset,":%s",escaped_password);
belle_sip_free(escaped_password);
if (error!=BELLE_SIP_OK) return error;
}
error=belle_sip_snprintf(buff,buff_size,offset,"@");
if (error!=BELLE_SIP_OK) return error;
}
error=belle_sip_snprintf(buff,buff_size,offset,"@");
if (error!=BELLE_SIP_OK) return error;
}
}
if (uri->host) {
if (strchr(uri->host,':')) { /*ipv6*/
error=belle_sip_snprintf(buff,buff_size,offset,"[%s]",uri->host);
} else {
error=belle_sip_snprintf(buff,buff_size,offset,"%s",uri->host);
if (uri->host) {
if (strchr(uri->host,':')) { /*ipv6*/
error=belle_sip_snprintf(buff,buff_size,offset,"[%s]",uri->host);
} else {
error=belle_sip_snprintf(buff,buff_size,offset,"%s",uri->host);
}
if (error!=BELLE_SIP_OK) return error;
}
if (error!=BELLE_SIP_OK) return error;
}
if (uri->port>0) {
error=belle_sip_snprintf(buff,buff_size,offset,":%i",uri->port);
if (error!=BELLE_SIP_OK) return error;
}
if (uri->port>0) {
error=belle_sip_snprintf(buff,buff_size,offset,":%i",uri->port);
if (error!=BELLE_SIP_OK) return error;
}
if (uri->path) {
char* escaped_path=belle_generic_uri_to_escaped_path(uri->path);
error=belle_sip_snprintf(buff,buff_size,offset,"%s",escaped_path);
belle_sip_free(escaped_path);
if (error!=BELLE_SIP_OK) return error;
}
if (uri->path) {
char* escaped_path=belle_generic_uri_to_escaped_path(uri->path);
error=belle_sip_snprintf(buff,buff_size,offset,"%s",escaped_path);
belle_sip_free(escaped_path);
if (error!=BELLE_SIP_OK) return error;
}
if (uri->query) {
char* escaped_query=belle_generic_uri_to_escaped_query(uri->query);
error=belle_sip_snprintf(buff,buff_size,offset,"?%s",escaped_query);
belle_sip_free(escaped_query);
if (error!=BELLE_SIP_OK) return error;
if (uri->query) {
char* escaped_query=belle_generic_uri_to_escaped_query(uri->query);
error=belle_sip_snprintf(buff,buff_size,offset,"?%s",escaped_query);
belle_sip_free(escaped_query);
if (error!=BELLE_SIP_OK) return error;
}
}
return BELLE_SIP_OK;
......@@ -125,6 +132,7 @@ GET_SET_STRING(belle_generic_uri,user_password);
GET_SET_STRING(belle_generic_uri,host);
GET_SET_STRING(belle_generic_uri,path);
GET_SET_STRING(belle_generic_uri,query);
GET_SET_STRING(belle_generic_uri,opaque_part);
GET_SET_INT(belle_generic_uri,port,int)
BELLE_NEW(belle_generic_uri,belle_sip_object)
BELLE_PARSE(belle_sip_messageParser,belle_,generic_uri)
......
......@@ -123,7 +123,10 @@ scope { belle_sip_request_t* current; }
@init {$request_line::current = belle_sip_request_new(); $ret=$request_line::current; }
: method {belle_sip_request_set_method($request_line::current,(const char*)($method.text->chars));}
SP
uri {belle_sip_request_set_uri($request_line::current,$uri.ret);}
( uri {belle_sip_request_set_uri($request_line::current,$uri.ret);}
|
generic_uri {belle_sip_request_set_absolute_uri($request_line::current,$generic_uri.ret);}
)
SP
sip_version
CRLF ;
......@@ -291,13 +294,44 @@ catch [ANTLR3_RECOGNITION_EXCEPTION]
abs_path = "/" path_segments
*/
/*comma, semicolon, or question
mark*/
opaque_part_for_from_to_contact_addr_spec
: uric_no_slash_for_from_to_contact_addr_spec uric_for_from_to_contact_addr_spec*;
opaque_part
: uric_no_slash uric*;
uric_no_slash_for_from_to_contact_addr_spec
: unreserved | escaped | COLON | AT| AND | EQUAL | PLUS | DOLLARD;
uric_no_slash
:COMMA | SEMI | QMARK | uric_no_slash_for_from_to_contact_addr_spec ;
scheme: alpha ( alphanum | PLUS | DASH | DOT )*;
/*remove hiearachy part because complex to handle the :comma, semicolon, or question
markexception see rfc3261 section 20.10 Contact*/
generic_uri_for_from_to_contact_addr_spec returns [belle_generic_uri_t* ret=NULL]
scope { belle_generic_uri_t* current; }
@init { $generic_uri_for_from_to_contact_addr_spec::current = $ret = belle_generic_uri_new(); }
: scheme {belle_generic_uri_set_scheme($generic_uri_for_from_to_contact_addr_spec::current,(const char*)$scheme.text->chars);}
COLON opaque_part_for_from_to_contact_addr_spec {belle_generic_uri_set_opaque_part($generic_uri_for_from_to_contact_addr_spec::current,(const char*)$opaque_part_for_from_to_contact_addr_spec.text->chars) ;} ;
catch [ANTLR3_RECOGNITION_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
belle_sip_object_unref($generic_uri::current);
$ret=NULL;
}
generic_uri returns [belle_generic_uri_t* ret=NULL]
scope { belle_generic_uri_t* current; }
@init { $generic_uri::current = $ret = belle_generic_uri_new(); }
: (scheme {belle_generic_uri_set_scheme($generic_uri::current,(const char*)$scheme.text->chars);} COLON)? hier_part[$generic_uri::current] ;
: hier_part[$generic_uri::current]
| (scheme {belle_generic_uri_set_scheme($generic_uri::current,(const char*)$scheme.text->chars);}
COLON (opaque_part {belle_generic_uri_set_opaque_part($generic_uri::current,(const char*)$opaque_part.text->chars) ;}
| hier_part[$generic_uri::current]) ) ;
catch [ANTLR3_RECOGNITION_EXCEPTION]
{
belle_sip_message("[\%s] reason [\%s]",(const char*)EXCEPTION->name,(const char*)EXCEPTION->message);
......@@ -335,6 +369,8 @@ pchar: unreserved | escaped | COLON | AT | AND | EQUAL | PLUS | DOLLARD | COMMA
query: uric+;
uric: reserved | unreserved | escaped;
uric_for_from_to_contact_addr_spec: reserved_for_from_to_contact_addr_spec | unreserved | escaped;
authority[belle_generic_uri_t* uri]
:
......@@ -626,8 +662,8 @@ header_address returns [belle_sip_header_address_t* ret]
header_address_base[belle_sip_header_address_t* obj] returns [belle_sip_header_address_t* ret]
@init { $ret=obj; }
: name_addr[BELLE_SIP_HEADER_ADDRESS($ret)]
| addr_spec[BELLE_SIP_HEADER_ADDRESS($ret)];
: name_addr_with_generic_uri[BELLE_SIP_HEADER_ADDRESS($ret)]
| addr_spec_with_generic_uri[BELLE_SIP_HEADER_ADDRESS($ret)];
catch [ANTLR3_RECOGNITION_EXCEPTION]
{
belle_sip_object_unref($ret);
......@@ -636,12 +672,28 @@ catch [ANTLR3_RECOGNITION_EXCEPTION]
name_addr[belle_sip_header_address_t* object]
: (lws? display_name[object])? sp_laquot addr_spec[object] raquot_sp;
name_addr_with_generic_uri[belle_sip_header_address_t* object]
: (lws? display_name[object])? sp_laquot addr_spec_with_generic_uri[object] raquot_sp;
addr_spec[belle_sip_header_address_t* object]
: lws? uri {belle_sip_header_address_set_uri(object,$uri.ret);} lws?;//| absoluteURI;
addr_spec_with_generic_uri[belle_sip_header_address_t* object]
: lws? ( uri {belle_sip_header_address_set_uri(object,$uri.ret);}
|
generic_uri{belle_sip_header_address_set_absolute_uri(object,$generic_uri.ret);}
) lws?;
paramless_addr_spec[belle_sip_header_address_t* object]
: lws? paramless_uri {belle_sip_header_address_set_uri(object,$paramless_uri.ret);} lws? ;//| absoluteURI;
paramless_addr_spec_with_generic_uri[belle_sip_header_address_t* object]
: lws? ( paramless_uri {belle_sip_header_address_set_uri(object,$paramless_uri.ret);}
|
generic_uri_for_from_to_contact_addr_spec{belle_sip_header_address_set_absolute_uri(object,$generic_uri_for_from_to_contact_addr_spec.ret);}
) lws? ;
display_name_tokens
:token (lws token)* ;
display_name[belle_sip_header_address_t* object]
......@@ -843,7 +895,7 @@ catch [ANTLR3_RECOGNITION_EXCEPTION]
}
from_spec
: ( name_addr[BELLE_SIP_HEADER_ADDRESS($header_from::current)] | paramless_addr_spec[BELLE_SIP_HEADER_ADDRESS($header_from::current)] )
: ( name_addr_with_generic_uri[BELLE_SIP_HEADER_ADDRESS($header_from::current)] | paramless_addr_spec_with_generic_uri[BELLE_SIP_HEADER_ADDRESS($header_from::current)] )
( SEMI lws? from_param lws?)*;
from_param
: /*tag_param |*/ generic_param [BELLE_SIP_PARAMETERS($header_from::current)];
......@@ -1133,7 +1185,7 @@ catch [ANTLR3_RECOGNITION_EXCEPTION]
$ret=NULL;
}
to_spec
: ( name_addr[BELLE_SIP_HEADER_ADDRESS($header_to::current)] | paramless_addr_spec[BELLE_SIP_HEADER_ADDRESS($header_to::current)] )
: ( name_addr_with_generic_uri[BELLE_SIP_HEADER_ADDRESS($header_to::current)] | paramless_addr_spec_with_generic_uri[BELLE_SIP_HEADER_ADDRESS($header_to::current)] )
( SEMI lws? to_param lws?)*;
to_param
: /*tag_param |*/ generic_param [BELLE_SIP_PARAMETERS($header_to::current)];
......@@ -1530,9 +1582,11 @@ three_digit: (DIGIT) => DIGIT
token
: (alphanum | mark | PERCENT | PLUS | BQUOTE )+;
reserved_for_from_to_contact_addr_spec:
COLON | AT | AND | EQUAL | PLUS | DOLLARD | SLASH;
reserved
: SEMI | SLASH | QMARK | COLON | AT | AND | EQUAL | PLUS
| DOLLARD | COMMA;
: SEMI | COMMA | QMARK | reserved_for_from_to_contact_addr_spec ;
unreserved : alphanum |mark;
alphanum : alpha | DIGIT ;
......
......@@ -343,6 +343,7 @@ belle_sip_error_code belle_sip_headers_marshal(belle_sip_message_t *message, cha
static void belle_sip_request_destroy(belle_sip_request_t* request) {
if (request->method) belle_sip_free(request->method);
if (request->uri) belle_sip_object_unref(request->uri);
if (request->absolute_uri) belle_sip_object_unref(request->absolute_uri);
if (request->dialog) belle_sip_object_unref(request->dialog);
if (request->rfc2543_branch) belle_sip_free(request->rfc2543_branch);
}
......@@ -353,6 +354,7 @@ static void belle_sip_request_init(belle_sip_request_t *message){
static void belle_sip_request_clone(belle_sip_request_t *request, const belle_sip_request_t *orig){
if (orig->method) request->method=belle_sip_strdup(orig->method);
if (orig->uri) request->uri=(belle_sip_uri_t*)belle_sip_object_ref(belle_sip_object_clone((belle_sip_object_t*)orig->uri));
if (orig->absolute_uri) request->absolute_uri=(belle_generic_uri_t*)belle_sip_object_ref(belle_sip_object_clone((belle_sip_object_t*)orig->absolute_uri));
if (orig->rfc2543_branch) request->rfc2543_branch=belle_sip_strdup(orig->rfc2543_branch);
}
......@@ -360,7 +362,16 @@ belle_sip_error_code belle_sip_request_marshal(belle_sip_request_t* request, cha
belle_sip_error_code error=belle_sip_snprintf(buff,buff_size,offset,"%s ",belle_sip_request_get_method(request));
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_uri_marshal(belle_sip_request_get_uri(request),buff,buff_size,offset);
if (request->uri)
error=belle_sip_uri_marshal(belle_sip_request_get_uri(request),buff,buff_size,offset);
else if (request->absolute_uri)
error=belle_generic_uri_marshal(belle_sip_request_get_absolute_uri(request),buff,buff_size,offset);
else {
belle_sip_error("Missing uri for marshaling request [%p]",request);
/*fixme better to have an error code*/
error=BELLE_SIP_OK;
}
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset," %s","SIP/2.0\r\n");
if (error!=BELLE_SIP_OK) return error;
......@@ -382,12 +393,29 @@ void belle_sip_request_set_dialog(belle_sip_request_t *req, belle_sip_dialog_t *
void belle_sip_request_set_uri(belle_sip_request_t* request,belle_sip_uri_t* uri) {
SET_OBJECT_PROPERTY(request,uri,uri);
if (request->absolute_uri && uri) {
belle_sip_warning("absolute uri [%p] already set for request [%p], cleaning it",request->absolute_uri, request);
belle_sip_request_set_absolute_uri(request,NULL);
}
}
belle_sip_uri_t * belle_sip_request_get_uri(const belle_sip_request_t *request){
return request->uri;
}
void belle_sip_request_set_absolute_uri(belle_sip_request_t* request,belle_generic_uri_t* absolute_uri) {
SET_OBJECT_PROPERTY(request,absolute_uri,absolute_uri);
if (request->uri && absolute_uri) {
belle_sip_warning("sip uri [%p] already set for request [%p], cleaning it",request->uri, request);
belle_sip_request_set_uri(request,NULL);
}
}
belle_generic_uri_t * belle_sip_request_get_absolute_uri(const belle_sip_request_t *request){
return request->absolute_uri;
}
belle_sip_uri_t* belle_sip_request_extract_origin(const belle_sip_request_t* req) {
belle_sip_header_via_t* via_header = belle_sip_message_get_header_by_type(req,belle_sip_header_via_t);
belle_sip_uri_t* uri=NULL;
......
......@@ -105,12 +105,39 @@ static void test_file_path() {
belle_sip_object_unref(source_uri);
}
}
static void test_absolute_uri() {
belle_generic_uri_t* source_uri = belle_generic_uri_parse("tel:+33123457");
char* source_uri_raw = belle_generic_uri_to_string(source_uri);
belle_generic_uri_t* first_uri = belle_generic_uri_parse(source_uri_raw);
belle_generic_uri_t* uri=BELLE_GENERIC_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(first_uri)));
belle_sip_free(source_uri_raw);
belle_sip_object_unref(source_uri);
belle_sip_object_unref(first_uri);
CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(uri),"tel");
CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(uri),"+33123457");
belle_sip_object_unref(uri);
source_uri = belle_generic_uri_parse("tel:11234567888;phone-context=vzims.com");
source_uri_raw = belle_generic_uri_to_string(source_uri);
first_uri = belle_generic_uri_parse(source_uri_raw);
uri=BELLE_GENERIC_URI(belle_sip_object_clone(BELLE_SIP_OBJECT(first_uri)));
belle_sip_free(source_uri_raw);
belle_sip_object_unref(source_uri);
belle_sip_object_unref(first_uri);
CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(uri),"tel");
CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(uri),"11234567888;phone-context=vzims.com");
belle_sip_object_unref(uri);
}
static test_t tests[] = {
{ "Simple uri", test_basic_uri },
{ "Complex uri", test_complex_uri },
{ "File path", test_file_path }
{ "File path", test_file_path },
{ "Absolute uri", test_absolute_uri }
};
test_suite_t generic_uri_test_suite = {
......
......@@ -90,6 +90,7 @@ static void test_complex_contact_header(void) {
static void test_from_header(void) {
belle_sip_header_from_t* L_tmp;
belle_sip_uri_t* L_uri;
belle_generic_uri_t* L_absoluteUri;
belle_sip_header_from_t* L_from = belle_sip_header_from_parse("f:<sip:titi.com;transport=tcp>;tag=dlfjklcn6545614XX");
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_from));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_from));
......@@ -105,6 +106,22 @@ static void test_from_header(void) {
CU_ASSERT_STRING_EQUAL(belle_sip_header_from_get_tag(L_from),"dlfjklcn6545614XX");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_from));
L_from = belle_sip_header_from_parse("From: <tel:+33124585454;toto=titi>;tag=dlfjklcn6545614XX");
l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_from));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_from));
L_tmp = belle_sip_header_from_parse(l_raw_header);
L_from = BELLE_SIP_HEADER_FROM(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
belle_sip_free(l_raw_header);
L_absoluteUri = belle_sip_header_address_get_absolute_uri(BELLE_SIP_HEADER_ADDRESS(L_from));
CU_ASSERT_PTR_NULL(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_from)));
CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(L_absoluteUri), "+33124585454;toto=titi");
CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(L_absoluteUri), "tel");
CU_ASSERT_STRING_EQUAL(belle_sip_header_from_get_tag(L_from),"dlfjklcn6545614XX");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_from));
/*test factory*/
L_from = belle_sip_header_from_create2("super <sip:titi.com:5060;lr;ttl=1;method=INVITE;maddr=192.168.0.1;transport=tcp?header=123>","12345-abc");
CU_ASSERT_PTR_NOT_NULL_FATAL(L_from);
......@@ -126,17 +143,38 @@ static void test_from_header(void) {
}
static void test_from_header_with_paramless_address_spec(void) {
belle_generic_uri_t *L_absoluteUri;
belle_sip_header_from_t* L_from = belle_sip_header_from_parse("From: sip:bob@titi.com;tag=dlfjklcn6545614XX");
CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_header_from_get_tag(L_from));
CU_ASSERT_STRING_EQUAL(belle_sip_header_from_get_tag(L_from),"dlfjklcn6545614XX");
belle_sip_object_unref(L_from);
L_from = belle_sip_header_from_parse("From: tel:1234567;tag=dlfjklcn6545614XX");
CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_header_from_get_tag(L_from));
L_absoluteUri = belle_sip_header_address_get_absolute_uri(BELLE_SIP_HEADER_ADDRESS(L_from));
CU_ASSERT_PTR_NULL(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_from)));
CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(L_absoluteUri), "1234567");
CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(L_absoluteUri), "tel");
CU_ASSERT_STRING_EQUAL(belle_sip_header_from_get_tag(L_from),"dlfjklcn6545614XX");
belle_sip_object_unref(L_from);
}
static void test_to_header_with_paramless_address_spec(void) {
belle_generic_uri_t *L_absoluteUri;
belle_sip_header_to_t* L_to = belle_sip_header_to_parse("To: sip:bob@titi.com;tag=dlfjklcn6545614XX");
CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_header_to_get_tag(L_to));
CU_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"dlfjklcn6545614XX");
belle_sip_object_unref(L_to);
L_to = belle_sip_header_to_parse("To: tel:1234567;tag=dlfjklcn6545614XX");
CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_header_to_get_tag(L_to));
L_absoluteUri = belle_sip_header_address_get_absolute_uri(BELLE_SIP_HEADER_ADDRESS(L_to));
CU_ASSERT_PTR_NULL(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_to)));
CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(L_absoluteUri), "1234567");
CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(L_absoluteUri), "tel");
CU_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"dlfjklcn6545614XX");
belle_sip_object_unref(L_to);
CU_ASSERT_PTR_NULL(belle_sip_header_to_parse("nimportequoi"));
}
......@@ -148,7 +186,8 @@ static void test_contact_header_with_paramless_address_spec(void) {
static void test_to_header(void) {
belle_sip_uri_t* L_uri;
belle_sip_header_to_t* L_to = belle_sip_header_to_parse("t : < sip:titi.com;transport=tcp> ; tag = dlfjklcn6545614XX");
belle_generic_uri_t* L_absoluteUri;
belle_sip_header_to_t *L_tmp, *L_to = belle_sip_header_to_parse("t : < sip:titi.com;transport=tcp> ; tag = dlfjklcn6545614XX");
char* l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_to));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_to));
L_to = belle_sip_header_to_parse(l_raw_header);
......@@ -177,6 +216,22 @@ static void test_to_header(void) {
CU_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"12345-abc");
belle_sip_object_unref(L_to);
L_to = belle_sip_header_to_parse("To: <tel:+33124585454;toto=titi>;tag=dlfjklcn6545614XX");
l_raw_header = belle_sip_object_to_string(BELLE_SIP_OBJECT(L_to));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_to));
L_tmp = belle_sip_header_to_parse(l_raw_header);
L_to = BELLE_SIP_HEADER_TO(belle_sip_object_clone(BELLE_SIP_OBJECT(L_tmp)));
belle_sip_object_unref(BELLE_SIP_OBJECT(L_tmp));
belle_sip_free(l_raw_header);
L_absoluteUri = belle_sip_header_address_get_absolute_uri(BELLE_SIP_HEADER_ADDRESS(L_to));
CU_ASSERT_PTR_NULL(belle_sip_header_address_get_uri(BELLE_SIP_HEADER_ADDRESS(L_to)));
CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(L_absoluteUri), "+33124585454;toto=titi");
CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_scheme(L_absoluteUri), "tel");
CU_ASSERT_STRING_EQUAL(belle_sip_header_to_get_tag(L_to),"dlfjklcn6545614XX");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_to));
}
static void test_via_header(void) {
......@@ -661,6 +716,25 @@ static void test_address_header(void) {
}
static void test_address_header_with_tel_uri(void) {
belle_generic_uri_t* L_uri;
char* L_raw;
belle_sip_header_address_t* laddress = belle_sip_header_address_parse("\"toto\" <tel:123456>");
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_absolute_uri(laddress);
CU_ASSERT_PTR_NOT_NULL(belle_generic_uri_get_opaque_part(L_uri));
CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_opaque_part(L_uri), "123456");
belle_sip_object_unref(BELLE_SIP_OBJECT(laddress));
}
static void test_very_long_address_header(void) {
belle_sip_uri_t* L_uri;
const char* raw = "<sip:jehan@sip.linphone.org"
......@@ -892,6 +966,7 @@ static void test_event_header(void) {
test_t headers_tests[] = {
{ "Address", test_address_header },
{ "Address tel uri", test_address_header_with_tel_uri },
{ "Header address (very long)", test_very_long_address_header },
{ "Address with error", test_address_with_error_header },
{ "Allow", test_allow_header },
......
......@@ -24,7 +24,7 @@
static void check_uri_and_headers(belle_sip_message_t* message) {
if (belle_sip_message_is_request(message)) {
CU_ASSERT_PTR_NOT_NULL(belle_sip_request_get_uri(BELLE_SIP_REQUEST(message)));
CU_ASSERT_TRUE(belle_sip_request_get_uri(BELLE_SIP_REQUEST(message))|| belle_sip_request_get_absolute_uri(BELLE_SIP_REQUEST(message)) );
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Max-Forwards"));
CU_ASSERT_PTR_NOT_NULL(BELLE_SIP_HEADER_MAX_FORWARDS(belle_sip_message_get_header(message,"Max-Forwards")));
......@@ -120,6 +120,39 @@ static void testInviteMessage(void) {
belle_sip_free(encoded_message);
}
static void testInviteMessageWithTelUri(void) {
const char* raw_message = "INVITE tel:11234567888;phone-context=vzims.fr SIP/2.0\r\n"\
"Via: SIP/2.0/UDP 10.23.17.117:22600;branch=z9hG4bK-d8754z-4d7620d2feccbfac-1---d8754z-;rport=4820;received=202.165.193.129\r\n"\
"Max-Forwards: 70\r\n"\
"Contact: <sip:bcheong@202.165.193.129:4820>\r\n"\
"To: <tel:+3311234567888;tot=titi>\r\n"\
"From: tel:11234567888;tag=werwrw\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"\
"c: application/sdp\r\n"\
"Supported: replaces\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";
belle_sip_request_t* request;
belle_sip_message_t* message = belle_sip_message_parse(raw_message);
char* encoded_message = belle_sip_object_to_string(BELLE_SIP_OBJECT(message));
belle_sip_object_unref(BELLE_SIP_OBJECT(message));