Commit 8cdc0840 authored by Simon Morlat's avatar Simon Morlat
Browse files

Merge branch 'master' of belledonne-communications.com:belle-sip

parents 64eaad9b f80fb643
......@@ -72,6 +72,7 @@
<option id="gnu.c.compiler.option.include.paths.1874152018" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="/Users/jehanmonnier/opt/include"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/belle-sip/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/belle-sip/src}&quot;"/>
<listOptionValue builtIn="false" value="/opt/local/include"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1419900147" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
......@@ -99,7 +100,7 @@
</fileInfo>
<fileInfo id="cdt.managedbuild.config.gnu.macosx.exe.debug.341835025.569616755" name="belle_sip_message_tester.c" rcbsApplicability="disable" resourcePath="tester/belle_sip_message_tester.c" toolsToInvoke="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.156963690">
<tool id="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201.156963690" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.macosx.exe.debug.315151201">
<option id="gnu.c.compiler.option.include.paths.1281017285" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<option id="gnu.c.compiler.option.include.paths.1281017285" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="/Users/jehanmonnier/opt/include"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/belle-sip/include}&quot;"/>
<listOptionValue builtIn="false" value="/opt/local/include"/>
......
This diff is collapsed.
......@@ -64,6 +64,27 @@ typedef enum belle_sip_type_id{
BELLE_SIP_TYPE_ID(belle_sip_header_record_route_t),
BELLE_SIP_TYPE_ID(belle_sip_header_content_length_t),
BELLE_SIP_TYPE_ID(belle_sip_header_t),
BELLE_SIP_TYPE_ID(belle_sip_header_extension_t),
BELLE_SIP_TYPE_ID(belle_sip_header_authorization_t),
BELLE_SIP_TYPE_ID(belle_sip_header_www_authenticate_t),
BELLE_SIP_TYPE_ID(belle_sip_header_proxy_authorization_t),
BELLE_SIP_TYPE_ID(belle_sdp_attribute_t),
BELLE_SIP_TYPE_ID(belle_sdp_bandwidth_t),
BELLE_SIP_TYPE_ID(belle_sdp_connection_t),
BELLE_SIP_TYPE_ID(belle_sdp_email_t),
BELLE_SIP_TYPE_ID(belle_sdp_info_t),
BELLE_SIP_TYPE_ID(belle_sdp_key_t),
BELLE_SIP_TYPE_ID(belle_sdp_media_t),
BELLE_SIP_TYPE_ID(belle_sdp_media_description_t),
BELLE_SIP_TYPE_ID(belle_sdp_origin_t),
BELLE_SIP_TYPE_ID(belle_sdp_phone_t),
BELLE_SIP_TYPE_ID(belle_sdp_repeate_time_t),
BELLE_SIP_TYPE_ID(belle_sdp_session_description_t),
BELLE_SIP_TYPE_ID(belle_sdp_session_name_t),
BELLE_SIP_TYPE_ID(belle_sdp_time_t),
BELLE_SIP_TYPE_ID(belle_sdp_time_description_t),
BELLE_SIP_TYPE_ID(belle_sdp_uri_t),
BELLE_SIP_TYPE_ID(belle_sdp_version_t),
belle_sip_type_id_end
}belle_sip_type_id_t;
......@@ -110,11 +131,14 @@ void belle_sip_object_delete(void *obj);
void *belle_sip_object_cast(belle_sip_object_t *obj, belle_sip_type_id_t id, const char *castname, const char *file, int fileno);
char* belle_sip_object_to_string(belle_sip_object_t* obj);
unsigned int belle_sip_object_is_instance_of(belle_sip_object_t * obj,belle_sip_type_id_t id);
BELLE_SIP_END_DECLS
#define BELLE_SIP_CAST(obj,_type) ((_type*)belle_sip_object_cast((belle_sip_object_t *)(obj), _type##_id, #_type, __FILE__, __LINE__))
#define BELLE_SIP_OBJECT(obj) BELLE_SIP_CAST(obj,belle_sip_object_t)
#define BELLE_SIP_IS_INSTANCE_OF(obj,_type) belle_sip_object_is_instance_of(obj,_type##_id)
typedef struct belle_sip_listening_point belle_sip_listening_point_t;
......
......@@ -64,7 +64,7 @@ void belle_sip_header_address_set_displayname(belle_sip_header_address_t* addres
typedef struct _belle_sip_header belle_sip_header_t;
const char* belle_sip_header_get_name (const belle_sip_header_t* obj);
void belle_sip_header_set_name (belle_sip_header_t* obj,const char* value);
int belle_sip_header_marshal(belle_sip_header_t* header, char* buff, unsigned int offset,unsigned int buff_size);
#define BELLE_SIP_HEADER(t) BELLE_SIP_CAST(t,belle_sip_header_t)
/***********************
......@@ -250,4 +250,86 @@ unsigned int belle_sip_header_content_length_get_content_length(const belle_sip_
void belle_sip_header_content_length_set_content_length(belle_sip_header_content_length_t* content_length,unsigned int length);
#define BELLE_SIP_HEADER_CONTENT_LENGTH(t) BELLE_SIP_CAST(t,belle_sip_header_content_length_t)
/******************************
* authorization header inherit from parameters
*
******************************/
typedef struct _belle_sip_header_authorization belle_sip_header_authorization_t;
belle_sip_header_authorization_t* belle_sip_header_authorization_new();
belle_sip_header_authorization_t* belle_sip_header_authorization_parse(const char* authorization);
const char* belle_sip_header_authorization_get_algorithm(const belle_sip_header_authorization_t* authorization );
const char* belle_sip_header_authorization_get_cnonce(const belle_sip_header_authorization_t* authorization );
const char* belle_sip_header_authorization_get_nonce(const belle_sip_header_authorization_t* authorization);
int belle_sip_header_authorization_get_nonce_count(const belle_sip_header_authorization_t* authorization);
const char* belle_sip_header_authorization_get_opaque(const belle_sip_header_authorization_t* authorization);
const char* belle_sip_header_authorization_get_qop(const belle_sip_header_authorization_t* authorization);
const char* belle_sip_header_authorization_get_realm(const belle_sip_header_authorization_t* authorization);
const char* belle_sip_header_authorization_get_response(const belle_sip_header_authorization_t* authorization);
const char* belle_sip_header_authorization_get_scheme(const belle_sip_header_authorization_t* authorization);
belle_sip_uri_t* belle_sip_header_authorization_get_uri(const belle_sip_header_authorization_t* authorization);
const char* belle_sip_header_authorization_get_username(const belle_sip_header_authorization_t* authorization);
void belle_sip_header_authorization_set_algorithm(belle_sip_header_authorization_t* authorization, const char* algorithm);
void belle_sip_header_authorization_set_cnonce(belle_sip_header_authorization_t* authorization, const char* cNonce);
void belle_sip_header_authorization_set_nonce(belle_sip_header_authorization_t* authorization, const char* nonce);
void belle_sip_header_authorization_set_nonce_count(belle_sip_header_authorization_t* authorization, int nonceCount);
void belle_sip_header_authorization_set_opaque(belle_sip_header_authorization_t* authorization, const char* opaque);
void belle_sip_header_authorization_set_qop(belle_sip_header_authorization_t* authorization, const char* qop);
void belle_sip_header_authorization_set_realm(belle_sip_header_authorization_t* authorization, const char* realm);
void belle_sip_header_authorization_set_response(belle_sip_header_authorization_t* authorization, const char* response);
void belle_sip_header_authorization_set_scheme(belle_sip_header_authorization_t* authorization, const char* scheme);
void belle_sip_header_authorization_set_uri(belle_sip_header_authorization_t* authorization, belle_sip_uri_t* uri);
void belle_sip_header_authorization_set_username(belle_sip_header_authorization_t* authorization, const char* username);
#define BELLE_SIP_HEADER_AUTHORIZATION(t) BELLE_SIP_CAST(t,belle_sip_header_authorization_t)
/*******************************
* proxy_authorization inherit from Authorization
*/
typedef struct _belle_sip_header_proxy_authorization belle_sip_header_proxy_authorization_t;
belle_sip_header_proxy_authorization_t* belle_sip_header_proxy_authorization_new();
belle_sip_header_proxy_authorization_t* belle_sip_header_proxy_authorization_parse(const char* proxy_authorization);
#define BELLE_SIP_HEADER_PROXY_AUTHORIZATION(t) BELLE_SIP_CAST(t,belle_sip_header_proxy_authorization_t)
/*******************************
* www_authenticate inherit from parameters
*/
typedef struct _belle_sip_header_www_authenticate belle_sip_header_www_authenticate_t;
belle_sip_header_www_authenticate_t* belle_sip_header_www_authenticate_new();
belle_sip_header_www_authenticate_t* belle_sip_header_www_authenticate_parse(const char* www_authenticate);
const char* belle_sip_header_www_authenticate_get_algorithm(const belle_sip_header_www_authenticate_t* www_authenticate );
const char* belle_sip_header_www_authenticate_get_nonce(const belle_sip_header_www_authenticate_t* www_authenticate);
const char* belle_sip_header_www_authenticate_get_opaque(const belle_sip_header_www_authenticate_t* www_authenticate);
const char* belle_sip_header_www_authenticate_get_qop(const belle_sip_header_www_authenticate_t* www_authetication);
const char* belle_sip_header_www_authenticate_get_realm(const belle_sip_header_www_authenticate_t* www_authenticate);
const char* belle_sip_header_www_authenticate_get_scheme(const belle_sip_header_www_authenticate_t* www_authenticate);
const char* belle_sip_header_www_authenticate_get_domain(const belle_sip_header_www_authenticate_t* www_authenticate);
unsigned int belle_sip_header_www_authenticate_is_stale(const belle_sip_header_www_authenticate_t* www_authenticate);
void belle_sip_header_www_authenticate_set_algorithm(belle_sip_header_www_authenticate_t* www_authenticate, const char* algorithm);
void belle_sip_header_www_authenticate_set_nonce(belle_sip_header_www_authenticate_t* www_authenticate, const char* nonce);
void belle_sip_header_www_authenticate_set_opaque(belle_sip_header_www_authenticate_t* www_authenticate, const char* opaque);
void belle_sip_header_www_authenticate_set_qop(belle_sip_header_www_authenticate_t* www_authentication, const char* qop);
void belle_sip_header_www_authenticate_set_realm(belle_sip_header_www_authenticate_t* www_authenticate, const char* realm);
void belle_sip_header_www_authenticate_set_scheme(belle_sip_header_www_authenticate_t* www_authenticate, const char* scheme);
void belle_sip_header_www_authenticate_set_domain(belle_sip_header_www_authenticate_t* www_authenticate,const char* domain);
void belle_sip_header_www_authenticate_set_stale(belle_sip_header_www_authenticate_t* www_authenticate, unsigned int enable);
#define BELLE_SIP_HEADER_WWW_AUTHENTICATE(t) BELLE_SIP_CAST(t,belle_sip_header_www_authenticate_t)
/******************************
*
* Extension header inherit from header
*
******************************/
typedef struct _belle_sip_header_extension belle_sip_header_extension_t;
belle_sip_header_extension_t* belle_sip_header_extension_new();
belle_sip_header_extension_t* belle_sip_header_extension_parse (const char* extension) ;
const char* belle_sip_header_extension_get_value(const belle_sip_header_extension_t* extension);
void belle_sip_header_extension_set_value(belle_sip_header_extension_t* extension,const char* value);
#define BELLE_SIP_HEADER_EXTENSION(t) BELLE_SIP_CAST(t,belle_sip_header_extension_t)
#endif /* HEADERS_H_ */
......@@ -29,7 +29,14 @@ typedef struct _belle_sip_response belle_sip_response_t;
BELLE_SIP_BEGIN_DECLS
belle_sip_message_t* belle_sip_message_parse(const char* raw);
/**
* Parse sip message from a raw buffer
* @param [in] buff buffer to be parsed
* @param [in] buff_length size of the buffer to be parsed
* @param [out] message_length number of bytes read
* @return parsed message
*/
belle_sip_message_t* belle_sip_message_parse_raw (const char* buff, size_t buff_length,size_t* message_length );
int belle_sip_message_is_request(belle_sip_message_t *msg);
belle_sip_request_t* belle_sip_request_new();
......@@ -61,8 +68,15 @@ void belle_sip_message_add_header(belle_sip_message_t *msg, belle_sip_header_t*
void belle_sip_message_add_headers(belle_sip_message_t *message, const belle_sip_list_t *header_list);
char *belle_sip_message_to_string(belle_sip_message_t *msg);
const char* belle_sip_message_get_body(belle_sip_message_t *msg);
void belle_sip_message_set_body(belle_sip_message_t *msg,char* body,unsigned int size);
int belle_sip_response_get_status_code(const belle_sip_response_t *response);
void belle_sip_response_set_status_code(belle_sip_response_t *response,int status);
const char* belle_sip_response_get_reason_phrase(const belle_sip_response_t *response);
void belle_sip_response_set_reason_phrase(belle_sip_response_t *response,const char* reason_phrase);
belle_sip_response_t *belle_sip_response_new(void);
......
......@@ -39,8 +39,12 @@ void belle_sip_parameters_set_parameter(belle_sip_parameters_t* obj,const char*
const belle_sip_list_t * belle_sip_parameters_get_parameter_names(belle_sip_parameters_t* obj);
const belle_sip_list_t * belle_sip_parameters_get_parameters(belle_sip_parameters_t* obj);
void belle_sip_parameters_remove_parameter(belle_sip_parameters_t* obj,const char* name);
int belle_sip_parameters_marshal(belle_sip_parameters_t* obj, char* buff,unsigned int offset,unsigned int buff_size);
#define BELLE_SIP_PARAMETERS(obj) BELLE_SIP_CAST(obj,belle_sip_parameters_t)
#endif /*PARAMETERS_H_*/
......@@ -174,6 +174,8 @@ typedef struct _belle_sip_uri belle_sip_uri_t;
*/
char* belle_sip_uri_to_string(belle_sip_uri_t* uri) ;
int belle_sip_uri_marshal(belle_sip_uri_t* uri, char* buff,unsigned int offset,unsigned int buff_size);
#define BELLE_SIP_URI(obj) BELLE_SIP_CAST(obj,belle_sip_uri_t)
#endif /*BELLE_SIP_URI_H_*/
......
/*
belle-sdp - SDP (RFC) library.
Copyright (C) 2010 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
grammar belle_sdp;
options {
language = C;
}
@header {
#include "belle-sip/belle-sdp.h"
#include "belle_sip_internal.h"
}
titi: TOTO;
TOTO: .;
This diff is collapsed.
......@@ -31,6 +31,7 @@
typedef void (*belle_sip_object_destroy_t)(belle_sip_object_t*);
typedef void (*belle_sip_object_clone_t)(belle_sip_object_t* obj, const belle_sip_object_t *orig);
typedef int (*belle_sip_object_marshal_t)(belle_sip_object_t* obj, char* buff,unsigned int offset,size_t buff_size);
struct _belle_sip_object_vptr{
belle_sip_type_id_t id;
......@@ -38,6 +39,8 @@ struct _belle_sip_object_vptr{
void *interfaces; /*unused for the moment*/
belle_sip_object_destroy_t destroy;
belle_sip_object_clone_t clone;
belle_sip_object_marshal_t marshal;
};
typedef struct _belle_sip_object_vptr belle_sip_object_vptr_t;
......@@ -59,13 +62,14 @@ extern belle_sip_object_vptr_t belle_sip_object_t_vptr;
#define BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_END };
#define BELLE_SIP_INSTANCIATE_VPTR(object_type,parent_type,destroy,clone) \
#define BELLE_SIP_INSTANCIATE_VPTR(object_type,parent_type,destroy,clone,marshal) \
belle_sip_object_vptr_t object_type##_vptr={ \
BELLE_SIP_TYPE_ID(object_type), \
(belle_sip_object_vptr_t*)&BELLE_SIP_OBJECT_VPTR_NAME(parent_type), \
NULL, \
(belle_sip_object_destroy_t)destroy, \
(belle_sip_object_clone_t)clone \
(belle_sip_object_clone_t)clone, \
(belle_sip_object_marshal_t)marshal\
}
......@@ -79,7 +83,7 @@ struct _belle_sip_object{
};
belle_sip_object_t * _belle_sip_object_new(size_t objsize, belle_sip_object_vptr_t *vptr, int initially_unowed);
int belle_sip_object_marshal(belle_sip_object_t* obj, char* buff,unsigned int offset,size_t buff_size);
#define belle_sip_object_new(_type) (_type*)_belle_sip_object_new(sizeof(_type),(belle_sip_object_vptr_t*)&BELLE_SIP_OBJECT_VPTR_NAME(_type),0)
#define belle_sip_object_new_unowed(_type,destroy)(_type*)_belle_sip_object_new(sizeof(_type),(belle_sip_object_vptr_t*)&BELLE_SIP_OBJECT_VPTR_NAME(_type),1)
......@@ -357,17 +361,23 @@ belle_sip_##object_type##_t* belle_sip_##object_type##_parse (const char* value)
tokens ->free(tokens);\
lex ->free(lex);\
input ->close(input);\
if (l_parsed_object == NULL) belle_sip_error(#object_type" parser error for [%s]",value);\
return l_parsed_object;\
}
#define BELLE_SIP_NEW(object_type,super_type) BELLE_SIP_NEW_WITH_NAME(object_type,super_type,NULL)
#define BELLE_SIP_NEW_WITH_NAME(object_type,super_type,name) \
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_##object_type##_t,belle_sip_##super_type##_t , belle_sip_##object_type##_destroy, belle_sip_##object_type##_clone); \
#define BELLE_SIP_NEW(object_type,super_type) BELLE_SIP_NEW_HEADER(object_type,super_type,NULL)
#define BELLE_SIP_NEW_HEADER(object_type,super_type,name) BELLE_SIP_NEW_HEADER_INIT(object_type,super_type,name,header)
#define BELLE_SIP_NEW_HEADER_INIT(object_type,super_type,name,init_type) \
BELLE_SIP_INSTANCIATE_VPTR( belle_sip_##object_type##_t\
, belle_sip_##super_type##_t\
, belle_sip_##object_type##_destroy\
, belle_sip_##object_type##_clone\
, belle_sip_##object_type##_marshal); \
belle_sip_##object_type##_t* belle_sip_##object_type##_new () { \
belle_sip_##object_type##_t* l_object = belle_sip_object_new(belle_sip_##object_type##_t);\
belle_sip_##super_type##_init((belle_sip_##super_type##_t*)l_object); \
belle_sip_object_set_name(BELLE_SIP_OBJECT(l_object),name);\
belle_sip_##init_type##_init((belle_sip_##init_type##_t*) l_object); \
if (name) belle_sip_header_set_name(BELLE_SIP_HEADER(l_object),name);\
return l_object;\
}
typedef struct belle_sip_param_pair_t {
......@@ -393,9 +403,13 @@ void belle_sip_header_address_set_quoted_displayname(belle_sip_header_address_t*
/*calss header*/
struct _belle_sip_header {
belle_sip_object_t base;
belle_sip_header_t* next;
const char* name;
};
void belle_sip_header_set_next(belle_sip_header_t* header,belle_sip_header_t* next);
belle_sip_header_t* belle_sip_header_get_next(const belle_sip_header_t* headers);
void belle_sip_header_init(belle_sip_header_t* obj);
/*class parameters*/
struct _belle_sip_parameters {
......@@ -503,6 +517,11 @@ void belle_sip_client_transaction_add_response(belle_sip_client_transaction_t *t
*/
void belle_sip_response_get_return_hop(belle_sip_response_t *msg, belle_sip_hop_t *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)
char* _belle_sip_str_dup_and_unquote_string(char* quoted_string);
#ifdef __cplusplus
}
#endif
......
......@@ -42,7 +42,7 @@ void belle_sip_fd_source_init(belle_sip_source_t *s, belle_sip_source_func_t fun
s->notify=func;
}
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_source_t,belle_sip_object_t,belle_sip_source_destroy,NULL);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_source_t,belle_sip_object_t,belle_sip_source_destroy,NULL,NULL);
belle_sip_source_t * belle_sip_fd_source_new(belle_sip_source_func_t func, void *data, int fd, unsigned int events, unsigned int timeout_value_ms){
belle_sip_source_t *s=belle_sip_object_new(belle_sip_source_t);
......@@ -89,7 +89,7 @@ static int main_loop_done(void *data, unsigned int events){
return TRUE;
}
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_main_loop_t,belle_sip_object_t,belle_sip_main_loop_destroy,NULL);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_main_loop_t,belle_sip_object_t,belle_sip_main_loop_destroy,NULL,NULL);
belle_sip_main_loop_t *belle_sip_main_loop_new(void){
belle_sip_main_loop_t*m=belle_sip_object_new(belle_sip_main_loop_t);
......
This diff is collapsed.
......@@ -27,7 +27,9 @@ static int has_type(belle_sip_object_t *obj, belle_sip_type_id_t id){
}
return FALSE;
}
unsigned int belle_sip_object_is_instance_of(belle_sip_object_t * obj,belle_sip_type_id_t id) {
return has_type(obj,id);
}
belle_sip_object_t * _belle_sip_object_new(size_t objsize, belle_sip_object_vptr_t *vptr, int initially_unowed){
belle_sip_object_t *obj=(belle_sip_object_t *)belle_sip_malloc0(objsize);
obj->ref=initially_unowed ? 0 : 1;
......@@ -72,7 +74,8 @@ belle_sip_object_vptr_t belle_sip_object_t_vptr={
NULL, /*no parent, it's god*/
NULL,
_belle_sip_object_uninit,
_belle_sip_object_clone
_belle_sip_object_clone,
NULL
};
void belle_sip_object_delete(void *ptr){
......@@ -103,6 +106,7 @@ belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj){
belle_sip_fatal("Object of type %i cannot be cloned, it does not provide a clone() implementation.",vptr->id);
return NULL;
}else vptr->clone(newobj,obj);
vptr=vptr->parent;
}
return newobj;
}
......@@ -128,3 +132,22 @@ void belle_sip_object_set_name(belle_sip_object_t* object,const char* name) {
const char* belle_sip_object_get_name(belle_sip_object_t* object) {
return object->name;
}
int belle_sip_object_marshal(belle_sip_object_t* obj, char* buff,unsigned int offset,size_t buff_size) {
belle_sip_object_vptr_t *vptr=obj->vptr;
while (vptr != NULL) {
if (vptr->marshal != NULL) {
return vptr->marshal(obj,buff,offset,buff_size);
} else {
vptr=vptr->parent;
}
}
return -1; /*no implementation found*/
}
char* belle_sip_object_to_string(belle_sip_object_t* obj) {
char buff[2048]; /*to be optimized*/
int size = belle_sip_object_marshal(obj,buff,0,sizeof(buff));
buff[size]='\0';
return strdup(buff);
}
......@@ -31,9 +31,23 @@ static void belle_sip_parameters_destroy(belle_sip_parameters_t* params) {
static void belle_sip_parameters_clone(belle_sip_parameters_t *params, const belle_sip_parameters_t *orig){
belle_sip_fatal("not implemented");
}
int belle_sip_parameters_marshal(belle_sip_parameters_t* params, char* buff,unsigned int offset,unsigned int buff_size) {
belle_sip_list_t* list=params->param_list;
unsigned int curent_offset=offset;
for(;list!=NULL;list=list->next){
belle_sip_param_pair_t* container = (belle_sip_param_pair_t* )(list->data);
if (container->value) {
curent_offset+=snprintf(buff+curent_offset,buff_size-curent_offset,";%s=%s",container->name,container->value);
} else {
curent_offset+=snprintf(buff+curent_offset,buff_size-curent_offset,";%s",container->name);
}
}
return curent_offset-offset;
}
BELLE_SIP_NEW(parameters,header)
const belle_sip_list_t * belle_sip_parameters_get_parameters(belle_sip_parameters_t* obj) {
return obj->param_list;
}
const char* belle_sip_parameters_get_parameter(belle_sip_parameters_t* params,const char* name) {
belle_sip_list_t * lResult = belle_sip_list_find_custom(params->param_list, (belle_sip_compare_func)belle_sip_param_pair_comp_func, name);
if (lResult) {
......
grammar belle_sip_uri;
options {
language = C;
}
@header { #include "belle-sip/uri.h"}
to_header : 'TO' ':' an_sip_uri;
an_sip_uri returns [belle_sip_uri_t* ret]
scope { belle_sip_uri_t* current; }
@init { $an_sip_uri::current = belle_sip_uri_new(); }
: sip_schema ((userinfo hostport) | hostport ) uri_parameters? headers? {$ret = $an_sip_uri::current;};
sip_schema : ('sip' | is_sips='sips') ':' {if ($is_sips) belle_sip_uri_set_secure($an_sip_uri::current,1);};
userinfo : user ( ':' password )? '@' ;
user : ( unreserved | escaped | user_unreserved )+ {belle_sip_uri_set_user($an_sip_uri::current,(const char *)$text->chars);};
user_unreserved : '&' | '=' | '+' | '$' | ',' | ';' | '?' | '/';
password : ( unreserved |'&' | '=' | '+' | '$' | ',' )*;
hostport : host ( ':' port )? {belle_sip_uri_set_host($an_sip_uri::current,(const char *)$host.text->chars);};
host : (hostname | ipv4address | ipv6reference) ;
hostname : ( domainlabel '.' )* toplabel '.'? ;
domainlabel : alphanum | (alphanum ( alphanum | '-' )* alphanum) ;
toplabel : alpha | (alpha ( alphanum | '-' )* alphanum) ;
ipv4address : three_digit '.' three_digit '.' three_digit '.' three_digit;
ipv6reference : '[' ipv6address ']';
ipv6address : hexpart ( ':' ipv4address )?;
hexpart : hexseq | hexseq '::' ( hexseq )? | '::' ( hexseq )?;
hexseq : hex4 ( ':' hex4)*;
hex4 : hexdigit hexdigit hexdigit hexdigit ;
port : DIGIT+ {belle_sip_uri_set_port($an_sip_uri::current,atoi((const char *)$text->chars));};
uri_parameters
: ( ';' uri_parameter )+;
uri_parameter //all parameters are considered as other
: other_param ;
other_param : pname ( '=' pvalue )?
{
if (strcmp("lr",(const char *)$pname.text->chars) == 0) {
belle_sip_uri_set_lr_param($an_sip_uri::current,1);
} else if (strcmp("transport",(const char*)$pname.text->chars)==0) {
belle_sip_uri_set_transport_param($an_sip_uri::current,(const char *)$pvalue.text->chars);
} else if (strcmp("user",(const char *)$pname.text->chars)==0) {
belle_sip_uri_set_user_param($an_sip_uri::current,(const char *)$pvalue.text->chars);
} else if (strcmp("maddr",(const char *)$pname.text->chars)==0) {
belle_sip_uri_set_maddr_param($an_sip_uri::current,(const char *)$pvalue.text->chars);
} else if (strcmp("ttl",(const char *)$pname.text->chars)==0) {
belle_sip_uri_set_ttl_param($an_sip_uri::current,atoi((const char *)$pvalue.text->chars));
}
};
pname
: paramchar+;
pvalue
: paramchar+;
paramchar
: param_unreserved | unreserved | escaped;
param_unreserved
: '[' | ']' | '/' | ':' | '&' | '+' | '$' | '.';
headers : '?' header ( '&' header )* ;
header : hname '=' hvalue? {belle_sip_uri_set_header($an_sip_uri::current,(const char *)$hname.text->chars,(const char *)$hvalue.text->chars);};
hname : ( hnv_unreserved | unreserved | escaped )+;
hvalue : ( hnv_unreserved | unreserved | escaped )+;
hnv_unreserved : '[' | ']' | '|' | '?' | ':' | '+' | '$' ;
escaped : '%' hexdigit hexdigit;
ttl : three_digit;
three_digit: DIGIT | (DIGIT DIGIT) | (DIGIT DIGIT DIGIT) ;
token
: (alphanum | MARK_LEX | '%' | '+' | '`' )+;
unreserved : alphanum |MARK_LEX;
alphanum : alpha | DIGIT ;
hexdigit
: HEX_CHAR|DIGIT;
alpha : HEX_CHAR | COMMON_CHAR;
COMMON_CHAR
: 'g'..'z' | 'G'..'Z' ;
MARK_LEX : '-' | '_' | '.' | '!' | '~' | '*' | '\'' ;
HEX_CHAR: 'a'..'f' |'A'..'F';
DIGIT : '0'..'9' ;
......@@ -56,10 +56,39 @@ void belle_sip_uri_destroy(belle_sip_uri_t* uri) {
belle_sip_object_unref(BELLE_SIP_OBJECT(uri->header_list));
}
int belle_sip_uri_marshal(belle_sip_uri_t* uri, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
const belle_sip_list_t* list=belle_sip_parameters_get_parameters(uri->header_list);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s:",uri->secure?"sips":"sip");
if (uri->user) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s@",uri->user);
}
if (uri->host) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",uri->host);
} else {
belle_sip_warning("no host found in this uri");
}
if (uri->port>0) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,":%i",uri->port);
}
current_offset+=belle_sip_parameters_marshal(&uri->params,buff,current_offset,buff_size);
for(;list!=NULL;list=list->next){
belle_sip_param_pair_t* container = list->data;
if (list == belle_sip_parameters_get_parameters(uri->header_list)) {
//first case
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"?%s=%s",container->name,container->value);
} else {
//subsequent headers
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"&%s=%s",container->name,container->value);
}
}
return current_offset-offset;
}
BELLE_SIP_PARSE(uri);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_uri_t,belle_sip_object_t,belle_sip_uri_destroy,NULL);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_uri_t,belle_sip_parameters_t,belle_sip_uri_destroy,NULL,belle_sip_uri_marshal);
belle_sip_uri_t* belle_sip_uri_new () {
......
......@@ -470,5 +470,11 @@ int belle_sip_param_pair_comp_func(const belle_sip_param_pair_t *a, const char*b
return strcmp(a->name,b);
}
char* _belle_sip_str_dup_and_unquote_string(char* quoted_string) {
size_t value_size = strlen(quoted_string);
char* unquoted_string = belle_sip_malloc0(value_size-2+1);
strncpy(unquoted_string,quoted_string+1,value_size-2);
return unquoted_string;
}
......@@ -28,7 +28,7 @@ typedef struct _headers_container {
static headers_container_t* belle_sip_message_headers_container_new(const char* name) {
headers_container_t* headers_container = belle_sip_new0(headers_container_t);
headers_container->name= belle_sip_strdup(name);
return NULL; /*FIXME*/
return headers_container;
}
static void belle_sip_headers_container_delete(headers_container_t *obj){
......@@ -39,6 +39,8 @@ static void belle_sip_headers_container_delete(headers_container_t *obj){
struct _belle_sip_message {
belle_sip_object_t base;
belle_sip_list_t* header_list;
char* body;
unsigned int body_length;
};
static void belle_sip_message_destroy(belle_sip_message_t *msg){
......@@ -46,9 +48,39 @@ static void belle_sip_message_destroy(belle_sip_message_t *msg){
belle_sip_list_free(msg->header_list);