Commit a3b1d2e1 authored by jehan's avatar jehan

big bunch of code for marshalling

parent 43ab5a03
......@@ -114,6 +114,8 @@ 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
......
......@@ -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)
/***********************
......
......@@ -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_*/
......
......@@ -50,7 +50,15 @@ belle_sip_header_t* belle_sip_header_get_next(const belle_sip_header_t* header)
return header->next;
}
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_header_t,belle_sip_object_t,belle_sip_header_destroy,NULL);
int belle_sip_header_marshal(belle_sip_header_t* header, char* buff,unsigned int offset,unsigned int buff_size) {
if (header->name) {
return snprintf(buff+offset,buff_size-offset,"%s:",header->name);
} else {
belle_sip_warning("no header name found");
return 0;
}
}
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_header_t,belle_sip_object_t,belle_sip_header_destroy,NULL,belle_sip_header_marshal);
/************************
......@@ -73,6 +81,24 @@ static void belle_sip_header_address_destroy(belle_sip_header_address_t* contact
static void belle_sip_header_address_clone(belle_sip_header_address_t *addr){
}
int belle_sip_header_address_marshal(belle_sip_header_address_t* header, char* buff,unsigned int offset,unsigned int buff_size) {
/*1 display name*/
unsigned int current_offset=offset;
if (header->displayname) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"\"%s\" ",header->displayname);;
}
if (header->uri) {
if (header->displayname || belle_sip_parameters_get_parameter_names(&header->base) !=NULL) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s","<");
}
current_offset+=belle_sip_uri_marshal(header->uri,buff,current_offset,buff_size);
if (header->displayname || belle_sip_parameters_get_parameter_names(&header->base) !=NULL) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",">");
}
}
current_offset+=belle_sip_parameters_marshal(&header->base,buff,current_offset,buff_size);
return current_offset-offset;
}
BELLE_SIP_NEW(header_address,parameters)
GET_SET_STRING(belle_sip_header_address,displayname);
......@@ -104,7 +130,16 @@ void belle_sip_header_contact_destroy(belle_sip_header_contact_t* contact) {
void belle_sip_header_contact_clone(belle_sip_header_contact_t *contact, const belle_sip_header_contact_t *orig){
}
int belle_sip_header_contact_marshal(belle_sip_header_contact_t* contact, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(contact), buff,offset, buff_size);
if (contact->wildcard) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s","*");
} else {
current_offset+=belle_sip_header_address_marshal(&contact->address, buff,current_offset, buff_size);
}
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_contact,header_address,"Contact")
BELLE_SIP_PARSE(header_contact)
......@@ -136,6 +171,11 @@ float belle_sip_header_contact_get_qvalue(const belle_sip_header_contact_t* cont
* From header object inherent from header_address
****************************
*/
#define BELLE_SIP_FROM_LIKE_MARSHAL(header) \
unsigned int current_offset=offset; \
current_offset+=belle_sip_##header_marshal(BELLE_SIP_HEADER(header), buff,current_offset, buff_size);\
current_offset+=belle_sip_header_address_marshal(&header->address, buff,current_offset, buff_size); \
return current_offset-offset;
struct _belle_sip_header_from {
belle_sip_header_address_t address;
};
......@@ -145,7 +185,9 @@ static void belle_sip_header_from_destroy(belle_sip_header_from_t* from) {
static void belle_sip_header_from_clone(belle_sip_header_from_t* from, const belle_sip_header_from_t* cloned) {
}
int belle_sip_header_from_marshal(belle_sip_header_from_t* from, char* buff,unsigned int offset,unsigned int buff_size) {
BELLE_SIP_FROM_LIKE_MARSHAL(from);
}
BELLE_SIP_NEW_HEADER(header_from,header_address,"From")
BELLE_SIP_PARSE(header_from)
......@@ -164,6 +206,9 @@ static void belle_sip_header_to_destroy(belle_sip_header_to_t* to) {
void belle_sip_header_to_clone(belle_sip_header_to_t *contact, const belle_sip_header_to_t *orig){
}
int belle_sip_header_to_marshal(belle_sip_header_to_t* to, char* buff,unsigned int offset,unsigned int buff_size) {
BELLE_SIP_FROM_LIKE_MARSHAL(to)
}
BELLE_SIP_NEW_HEADER(header_to,header_address,"To")
BELLE_SIP_PARSE(header_to)
......@@ -188,6 +233,17 @@ static void belle_sip_header_via_destroy(belle_sip_header_via_t* via) {
static void belle_sip_header_via_clone(belle_sip_header_via_t* via, const belle_sip_header_via_t*orig){
}
int belle_sip_header_via_marshal(belle_sip_header_via_t* via, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(via), buff,current_offset, buff_size);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s/%s",via->protocol,via->transport);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset," %s",via->host);
if (via->port > 0) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,":%i",via->port);
}
current_offset+=belle_sip_parameters_marshal(&via->params_list, buff,current_offset, buff_size);
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_via,header_address,"Via")
BELLE_SIP_PARSE(header_via)
......@@ -253,6 +309,12 @@ static void belle_sip_header_call_id_destroy(belle_sip_header_call_id_t* call_id
static void belle_sip_header_call_id_clone(belle_sip_header_call_id_t* call_id,const belle_sip_header_call_id_t *orig){
}
int belle_sip_header_call_id_marshal(belle_sip_header_call_id_t* call_id, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(call_id), buff,current_offset, buff_size);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",call_id->call_id);
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_call_id,header,"Call-ID")
BELLE_SIP_PARSE(header_call_id)
......@@ -274,7 +336,12 @@ static void belle_sip_header_cseq_destroy(belle_sip_header_cseq_t* cseq) {
static void belle_sip_header_cseq_clone(belle_sip_header_cseq_t* cseq, const belle_sip_header_cseq_t *orig) {
if (cseq->method) belle_sip_free((void*)cseq->method);
}
int belle_sip_header_cseq_marshal(belle_sip_header_cseq_t* cseq, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(cseq), buff,current_offset, buff_size);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i %s",cseq->seq_number,cseq->method);
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_cseq,header,"CSeq")
BELLE_SIP_PARSE(header_cseq)
GET_SET_STRING(belle_sip_header_cseq,method);
......@@ -296,7 +363,13 @@ static void belle_sip_header_content_type_destroy(belle_sip_header_content_type_
static void belle_sip_header_content_type_clone(belle_sip_header_content_type_t* content_type, const belle_sip_header_content_type_t* orig){
}
int belle_sip_header_content_type_marshal(belle_sip_header_content_type_t* content_type, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(content_type), buff,current_offset, buff_size);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s/%s",content_type->type, content_type->subtype);
current_offset+=belle_sip_parameters_marshal(&content_type->params_list, buff,current_offset, buff_size);
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_content_type,parameters,"Content-Type")
BELLE_SIP_PARSE(header_content_type)
GET_SET_STRING(belle_sip_header_content_type,type);
......@@ -314,7 +387,9 @@ static void belle_sip_header_route_destroy(belle_sip_header_route_t* route) {
static void belle_sip_header_route_clone(belle_sip_header_route_t* route, const belle_sip_header_route_t* orig) {
}
int belle_sip_header_route_marshal(belle_sip_header_route_t* route, char* buff,unsigned int offset,unsigned int buff_size) {
BELLE_SIP_FROM_LIKE_MARSHAL(route)
}
BELLE_SIP_NEW_HEADER(header_route,header_address,"Route")
BELLE_SIP_PARSE(header_route)
/**************************
......@@ -331,7 +406,9 @@ static void belle_sip_header_record_route_destroy(belle_sip_header_record_route_
static void belle_sip_header_record_route_clone(belle_sip_header_record_route_t* record_route,
const belle_sip_header_record_route_t* orig ) {
}
int belle_sip_header_record_route_marshal(belle_sip_header_record_route_t* record_route, char* buff,unsigned int offset,unsigned int buff_size) {
BELLE_SIP_FROM_LIKE_MARSHAL(record_route)
}
BELLE_SIP_NEW_HEADER(header_record_route,header_address,"Record-Route")
BELLE_SIP_PARSE(header_record_route)
/**************************
......@@ -350,7 +427,12 @@ static void belle_sip_header_content_length_clone(belle_sip_header_content_lengt
const belle_sip_header_content_length_t *orig ) {
}
int belle_sip_header_content_length_marshal(belle_sip_header_content_length_t* content_length, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(content_length), buff,current_offset, buff_size);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%i",content_length->content_length);
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_content_length,header,"Content-Length")
BELLE_SIP_PARSE(header_content_length)
GET_SET_INT(belle_sip_header_content_length,content_length,unsigned int)
......@@ -369,7 +451,13 @@ static void belle_sip_header_extension_destroy(belle_sip_header_extension_t* ext
static void belle_sip_header_extension_clone(belle_sip_header_extension_t* extension, const belle_sip_header_extension_t* orig){
}
int belle_sip_header_extension_marshal(belle_sip_header_extension_t* extension, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(extension), buff,current_offset, buff_size);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s",extension->value);
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_extension,header,NULL)
/**
......@@ -416,10 +504,48 @@ GET_SET_STRING(belle_sip_header_extension,value);
if (obj->algorithm) belle_sip_free((void*)obj->algorithm);\
if (obj->opaque) belle_sip_free((void*)obj->opaque);\
if (obj->qop) belle_sip_free((void*)obj->qop);\
struct _belle_sip_header_authorization {
/*if (obj->params_list) FIXME free list*/
#define AUTH_BASE_MARSHAL(header) \
unsigned int current_offset=offset;\
char* border=" ";\
current_offset+=belle_sip_header_marshal(BELLE_SIP_HEADER(header), buff,current_offset, buff_size);\
const belle_sip_list_t* list=belle_sip_parameters_get_parameters(&header->params_list);\
if (header->scheme) { \
current_offset+=snprintf(buff+current_offset,buff_size-current_offset," %s",header->scheme);\
} else { \
belle_sip_error("missing mandatory scheme"); \
} \
for(;list!=NULL;list=list->next){\
belle_sip_param_pair_t* container = list->data;\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s%s=%s",border, container->name,container->value);\
border=", ";\
}\
if (header->realm) {\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%srealm=\"%s\"",border,header->realm);\
border=", ";\
}\
if (header->nonce) {\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%snonce=\"%s\"",border,header->nonce);\
border=", ";\
}\
if (header->algorithm) {\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%salgorithm=%s",border,header->algorithm);\
border=", ";\
}\
if (header->opaque) {\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sopaque=\"%s\"",border,header->opaque);\
border=", ";\
}\
if (header->qop) {\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sqop=%s",border,header->qop);\
border=", ";\
}
struct _belle_sip_header_authorization {
AUTH_BASE
const char* username;
belle_sip_uri_t* uri;
......@@ -456,6 +582,35 @@ void belle_sip_header_authorization_set_uri(belle_sip_header_authorization_t* au
authorization->uri=uri;
if (authorization->uri) belle_sip_object_ref(authorization->uri);
}
int belle_sip_header_authorization_marshal(belle_sip_header_authorization_t* authorization, char* buff,unsigned int offset,unsigned int buff_size) {
AUTH_BASE_MARSHAL(authorization)
if (authorization->username) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%susername=\"%s\"",border,authorization->username);\
border=", ";
}
if (authorization->uri) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s uri=\"",border);
border=", ";
current_offset+=belle_sip_uri_marshal(authorization->uri,buff,current_offset,buff_size);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s","\"");
}
if (authorization->algorithm) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%salgorithm=%s",border,authorization->algorithm);
border=", ";
}
if (authorization->response) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sresponse=\"%s\"",border,authorization->response);
border=", ";
}
if (authorization->cnonce) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%scnonce=\"%s\"",border,authorization->cnonce);
border=", ";
}
if (authorization->nonce_count>0) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%snc=\"%08i\"",border,authorization->nonce_count);
}
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_authorization,parameters,"Authorization")
BELLE_SIP_PARSE(header_authorization)
GET_SET_STRING(belle_sip_header_authorization,scheme);
......@@ -484,6 +639,9 @@ static void belle_sip_header_proxy_authorization_destroy(belle_sip_header_proxy_
static void belle_sip_header_proxy_authorization_clone(belle_sip_header_proxy_authorization_t* proxy_authorization,
const belle_sip_header_proxy_authorization_t *orig ) {
}
int belle_sip_header_proxy_authorization_marshal(belle_sip_header_proxy_authorization_t* proxy_authorization, char* buff,unsigned int offset,unsigned int buff_size) {
return belle_sip_header_authorization_marshal(&proxy_authorization->authorization,buff,offset,buff_size);
}
BELLE_SIP_NEW_HEADER(header_proxy_authorization,header_authorization,"Proxy-Authorization")
BELLE_SIP_PARSE(header_proxy_authorization)
/**************************
......@@ -498,12 +656,26 @@ struct _belle_sip_header_www_authenticate {
static void belle_sip_header_www_authenticate_destroy(belle_sip_header_www_authenticate_t* www_authenticate) {
if (www_authenticate->domain) belle_sip_free((void*)www_authenticate->domain);
}
void belle_sip_header_www_authenticate_init(belle_sip_header_www_authenticate_t* www_authenticate) {
www_authenticate->stale=-1;
}
static void belle_sip_header_www_authenticate_clone(belle_sip_header_www_authenticate_t* www_authenticate,
const belle_sip_header_www_authenticate_t *orig ) {
}
BELLE_SIP_NEW_HEADER(header_www_authenticate,parameters,"WWW-Authenticate")
int belle_sip_header_www_authenticate_marshal(belle_sip_header_www_authenticate_t* www_authenticate, char* buff,unsigned int offset,unsigned int buff_size) {
AUTH_BASE_MARSHAL(www_authenticate)
if (www_authenticate->domain) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sdomain=\"%s\"",border,www_authenticate->domain);\
border=", ";
}
if (www_authenticate->stale>=0) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sstale=\"%s",border,www_authenticate->stale?"true":"false");
}
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER_INIT(header_www_authenticate,parameters,"WWW-Authenticate",header_www_authenticate)
BELLE_SIP_PARSE(header_www_authenticate)
GET_SET_STRING(belle_sip_header_www_authenticate,scheme);
GET_SET_STRING(belle_sip_header_www_authenticate,realm);
......
......@@ -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\
}
......@@ -362,12 +366,17 @@ belle_sip_##object_type##_t* belle_sip_##object_type##_parse (const char* value)
}
#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_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_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_##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;\
}
......
......@@ -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);
......
......@@ -74,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){
......@@ -105,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;
}
......@@ -130,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) {
......
......@@ -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_parameters_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 () {
......
......@@ -46,7 +46,7 @@ static void belle_sip_message_destroy(belle_sip_message_t *msg){
belle_sip_list_free(msg->header_list);
}
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_message_t,belle_sip_object_t,belle_sip_message_destroy,NULL);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_message_t,belle_sip_object_t,belle_sip_message_destroy,NULL,NULL);
BELLE_SIP_PARSE(message)
......@@ -131,7 +131,9 @@ static void belle_sip_request_destroy(belle_sip_request_t* request) {
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);
}
int belle_sip_request_marshal(belle_sip_request_t* request, char* buff,unsigned int offset,unsigned int buff_size) {
}
BELLE_SIP_NEW(request,message)
BELLE_SIP_PARSE(request)
GET_SET_STRING(belle_sip_request,method);
......@@ -253,7 +255,9 @@ static void belle_sip_response_clone(belle_sip_response_t *resp, const belle_sip
if (orig->sip_version) resp->sip_version=belle_sip_strdup(orig->sip_version);
if (orig->reason_phrase) resp->reason_phrase=belle_sip_strdup(orig->reason_phrase);
}
int belle_sip_response_marshal(belle_sip_response_t *resp, char* buff,unsigned int offset,unsigned int buff_size) {
return 0;
}
BELLE_SIP_NEW(response,message);
BELLE_SIP_PARSE(response)
GET_SET_STRING(belle_sip_response,reason_phrase);
......
......@@ -33,7 +33,7 @@ static void belle_sip_provider_uninit(belle_sip_provider_t *p){
belle_sip_list_free(p->lps);
}
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_provider_t,belle_sip_object_t,belle_sip_provider_uninit,NULL);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_provider_t,belle_sip_object_t,belle_sip_provider_uninit,NULL,NULL);
belle_sip_provider_t *belle_sip_provider_new(belle_sip_stack_t *s, belle_sip_listening_point_t *lp){
belle_sip_provider_t *p=belle_sip_object_new(belle_sip_provider_t);
......
......@@ -29,7 +29,7 @@ static void belle_sip_sender_task_uninit(belle_sip_sender_task_t *t){
if (t->resolver_id>0) belle_sip_main_loop_cancel_source (stack->ml,t->resolver_id);
}
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_sender_task_t,belle_sip_object_t,belle_sip_sender_task_uninit,NULL);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_sender_task_t,belle_sip_object_t,belle_sip_sender_task_uninit,NULL,NULL);
belle_sip_sender_task_t * belle_sip_sender_task_new(belle_sip_provider_t *provider, belle_sip_sender_task_callback_t cb, void *data){
belle_sip_sender_task_t *t=belle_sip_object_new(belle_sip_sender_task_t);
......
......@@ -25,7 +25,7 @@ static void belle_sip_stack_destroy(belle_sip_stack_t *stack){
belle_sip_list_free(stack->lp);
}
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_stack_t,belle_sip_object_t,belle_sip_stack_destroy,NULL);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_stack_t,belle_sip_object_t,belle_sip_stack_destroy,NULL,NULL);