Commit f931682f authored by Ghislain MARY's avatar Ghislain MARY

Some more improvements on object marshalling.

 - Use size_t instead of unsigned int for offset.
 - Add function to enable marshal check at runtime.
 - Enable marshal check in unit tests.
parent 12152171
......@@ -76,7 +76,7 @@ typedef struct _belle_sip_header belle_sip_header_t;
BELLESIP_EXPORT belle_sip_header_t* belle_sip_header_create (const char* name,const char* value);
BELLESIP_EXPORT const char* belle_sip_header_get_name (const belle_sip_header_t* obj);
BELLESIP_EXPORT void belle_sip_header_set_name (belle_sip_header_t* obj,const char* value);
BELLESIP_EXPORT belle_sip_error_code belle_sip_header_marshal(belle_sip_header_t* header, char* buff, size_t buff_size, unsigned int *offset);
BELLESIP_EXPORT belle_sip_error_code belle_sip_header_marshal(belle_sip_header_t* header, char* buff, size_t buff_size, size_t *offset);
BELLESIP_EXPORT const char *belle_sip_header_get_unparsed_value(belle_sip_header_t* obj);
#define BELLE_SIP_HEADER(t) BELLE_SIP_CAST(t,belle_sip_header_t)
......
......@@ -114,7 +114,7 @@ typedef struct _belle_sip_object belle_sip_object_t;
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, size_t buff_size, unsigned int *offset);
typedef int (*belle_sip_object_marshal_t)(belle_sip_object_t* obj, char* buff, size_t buff_size, size_t *offset);
struct _belle_sip_object_vptr{
belle_sip_type_id_t id;
......@@ -151,6 +151,13 @@ BELLESIP_EXPORT belle_sip_object_t * _belle_sip_object_new(size_t objsize, belle
#define belle_sip_object_new(_type) (_type*)_belle_sip_object_new(sizeof(_type),(belle_sip_object_vptr_t*)&BELLE_SIP_OBJECT_VPTR_NAME(_type))
/**
* Activates checks on object marshalling.
* Useful for debug purposes.
* @param enable TRUE to enable, FALSE to disable.
**/
BELLESIP_EXPORT void belle_sip_object_enable_marshal_check(int enable);
int belle_sip_object_is_unowed(const belle_sip_object_t *obj);
/**
......@@ -231,7 +238,7 @@ BELLESIP_EXPORT char* belle_sip_object_to_string(void* obj);
* Writes a string representation of the object into the supplied buffer.
* Same as belle_sip_object_to_string(), but without allocating space for the output string.
**/
BELLESIP_EXPORT belle_sip_error_code belle_sip_object_marshal(belle_sip_object_t* obj, char* buff, size_t buff_size, unsigned int *offset);
BELLESIP_EXPORT belle_sip_error_code belle_sip_object_marshal(belle_sip_object_t* obj, char* buff, size_t buff_size, size_t *offset);
BELLESIP_EXPORT int belle_sip_object_is_instance_of(belle_sip_object_t * obj,belle_sip_type_id_t id);
......
......@@ -52,7 +52,7 @@ BELLESIP_EXPORT const belle_sip_list_t * belle_sip_parameters_get_parameters(con
BELLESIP_EXPORT void belle_sip_parameters_remove_parameter(belle_sip_parameters_t* obj,const char* name);
BELLESIP_EXPORT belle_sip_error_code belle_sip_parameters_marshal(const belle_sip_parameters_t* obj, char* buff, size_t buff_size, unsigned int *offset);
BELLESIP_EXPORT belle_sip_error_code belle_sip_parameters_marshal(const belle_sip_parameters_t* obj, char* buff, size_t buff_size, size_t *offset);
#define BELLE_SIP_PARAMETERS(obj) BELLE_SIP_CAST(obj,belle_sip_parameters_t)
......
......@@ -185,7 +185,7 @@ BELLESIP_EXPORT void belle_sip_uri_fix(belle_sip_uri_t *uri);
*/
BELLESIP_EXPORT char* belle_sip_uri_to_string(belle_sip_uri_t* uri) ;
belle_sip_error_code belle_sip_uri_marshal(const belle_sip_uri_t* uri, char* buff, size_t buff_size, unsigned int *offset);
belle_sip_error_code belle_sip_uri_marshal(const belle_sip_uri_t* uri, char* buff, size_t buff_size, size_t *offset);
#define BELLE_SIP_URI(obj) BELLE_SIP_CAST(obj,belle_sip_uri_t)
......
......@@ -145,7 +145,7 @@ BELLESIP_EXPORT void belle_sip_set_log_handler(belle_sip_log_function_t func);
BELLESIP_EXPORT char * BELLE_SIP_CHECK_FORMAT_ARGS(1,2) belle_sip_strdup_printf(const char *fmt,...);
BELLESIP_EXPORT belle_sip_error_code belle_sip_snprintf(char *buff, unsigned int buff_size, unsigned int *offset, const char *fmt, ...);
BELLESIP_EXPORT belle_sip_error_code belle_sip_snprintf(char *buff, size_t buff_size, size_t *offset, const char *fmt, ...);
BELLESIP_EXPORT void belle_sip_set_log_level(int level);
......
......@@ -38,7 +38,7 @@ void belle_sdp_attribute_clone(belle_sdp_attribute_t *attribute, const belle_sdp
CLONE_STRING(belle_sdp_attribute,value,attribute,orig)
}
belle_sip_error_code belle_sdp_attribute_marshal(belle_sdp_attribute_t* attribute, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sdp_attribute_marshal(belle_sdp_attribute_t* attribute, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_snprintf(buff,buff_size,offset,"a=%s",attribute->name);
if (error!=BELLE_SIP_OK) return error;
if (attribute->value) {
......@@ -79,7 +79,7 @@ void belle_sdp_bandwidth_clone(belle_sdp_bandwidth_t *bandwidth, const belle_sdp
bandwidth->value=orig->value;
}
belle_sip_error_code belle_sdp_bandwidth_marshal(belle_sdp_bandwidth_t* bandwidth, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sdp_bandwidth_marshal(belle_sdp_bandwidth_t* bandwidth, char* buff, size_t buff_size, size_t *offset) {
return belle_sip_snprintf(buff,buff_size,offset,"b=%s:%i",bandwidth->type,bandwidth->value);
}
......@@ -111,7 +111,7 @@ void belle_sdp_connection_clone(belle_sdp_connection_t *connection, const belle_
}
belle_sip_error_code belle_sdp_connection_marshal(belle_sdp_connection_t* connection, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sdp_connection_marshal(belle_sdp_connection_t* connection, char* buff, size_t buff_size, size_t *offset) {
return belle_sip_snprintf(buff,buff_size,offset,"c=%s %s %s",connection->network_type,connection->address_type,connection->address);
}
......@@ -143,7 +143,7 @@ void belle_sdp_email_clone(belle_sdp_email_t *email, const belle_sdp_email_t *or
CLONE_STRING(belle_sdp_email,value,email,orig)
}
belle_sip_error_code belle_sdp_email_marshal(belle_sdp_email_t* email, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sdp_email_marshal(belle_sdp_email_t* email, char* buff, size_t buff_size, size_t *offset) {
return belle_sip_snprintf(buff,buff_size,offset,"e=%s",email->value);
}
......@@ -166,7 +166,7 @@ void belle_sdp_info_clone(belle_sdp_info_t *info, const belle_sdp_info_t *orig){
CLONE_STRING(belle_sdp_info,value,info,orig)
}
belle_sip_error_code belle_sdp_info_marshal(belle_sdp_info_t* info, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sdp_info_marshal(belle_sdp_info_t* info, char* buff, size_t buff_size, size_t *offset) {
return belle_sip_snprintf(buff,buff_size,offset,"i=%s",info->value);
}
......@@ -208,7 +208,7 @@ void belle_sdp_media_clone(belle_sdp_media_t *media, const belle_sdp_media_t *or
CLONE_STRING(belle_sdp_media,protocol,media,orig)
}
belle_sip_error_code belle_sdp_media_marshal(belle_sdp_media_t* media, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sdp_media_marshal(belle_sdp_media_t* media, char* buff, size_t buff_size, size_t *offset) {
belle_sip_list_t* list=media->media_formats;
belle_sip_error_code error=belle_sip_snprintf(buff,buff_size,offset,"m=%s %i",media->media_type,media->media_port);
if (error!=BELLE_SIP_OK) return error;
......@@ -279,7 +279,7 @@ static void belle_sdp_base_description_clone(belle_sdp_base_description_t *base_
}
belle_sip_error_code belle_sdp_base_description_marshal(belle_sdp_base_description_t* base_description, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sdp_base_description_marshal(belle_sdp_base_description_t* base_description, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=BELLE_SIP_OK;
belle_sip_list_t* bandwidths;
// belle_sip_list_t* attributes;
......@@ -302,8 +302,8 @@ belle_sip_error_code belle_sdp_base_description_marshal(belle_sdp_base_descripti
if (error!=BELLE_SIP_OK) return error;
}
// for(attributes=base_description->attributes;attributes!=NULL;attributes=attributes->next){
// current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(attributes->data),buff,current_offset,buff_size);
// current_offset+=snprintf(buff+current_offset, buff_size-current_offset, "\r\n");
// error=belle_sip_object_marshal(BELLE_SIP_OBJECT(attributes->data),buff,buff_size,offset);
// error=belle_sip_snprintf(buff, buff_size, offset, "\r\n");
// }
return error;
}
......@@ -424,7 +424,7 @@ void belle_sdp_media_description_clone(belle_sdp_media_description_t *media_desc
if (orig->media) media_description->media = BELLE_SDP_MEDIA(belle_sip_object_clone_and_ref(BELLE_SIP_OBJECT((orig->media))));
}
belle_sip_error_code belle_sdp_media_description_marshal(belle_sdp_media_description_t* media_description, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sdp_media_description_marshal(belle_sdp_media_description_t* media_description, char* buff, size_t buff_size, size_t *offset) {
belle_sip_list_t* attributes;
belle_sip_error_code error=belle_sip_object_marshal(BELLE_SIP_OBJECT(media_description->media),buff,buff_size,offset);
if (error!=BELLE_SIP_OK) return error;
......@@ -819,7 +819,7 @@ void belle_sdp_origin_clone(belle_sdp_origin_t *origin, const belle_sdp_origin_t
origin->session_version = orig->session_version;
}
belle_sip_error_code belle_sdp_origin_marshal(belle_sdp_origin_t* origin, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sdp_origin_marshal(belle_sdp_origin_t* origin, char* buff, size_t buff_size, size_t *offset) {
return belle_sip_snprintf( buff
,buff_size
,offset
......@@ -871,7 +871,7 @@ void belle_sdp_session_name_clone(belle_sdp_session_name_t *session_name, const
CLONE_STRING(belle_sdp_session_name,value,session_name,orig);
}
belle_sip_error_code belle_sdp_session_name_marshal(belle_sdp_session_name_t* session_name, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sdp_session_name_marshal(belle_sdp_session_name_t* session_name, char* buff, size_t buff_size, size_t *offset) {
return belle_sip_snprintf(buff,buff_size,offset,"s=%s",session_name->value);
}
......@@ -925,7 +925,7 @@ void belle_sdp_session_description_clone(belle_sdp_session_description_t *sessio
session_description->media_descriptions = belle_sip_list_copy_with_data(orig->media_descriptions,belle_sip_object_copyfunc);
}
belle_sip_error_code belle_sdp_session_description_marshal(belle_sdp_session_description_t* session_description, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sdp_session_description_marshal(belle_sdp_session_description_t* session_description, char* buff, size_t buff_size, size_t *offset) {
/*session_description: proto_version CR LF
origin_field
session_name_field
......@@ -1130,7 +1130,7 @@ void belle_sdp_time_clone(belle_sdp_time_t *time, const belle_sdp_time_t *orig){
time->stop=orig->stop;
}
belle_sip_error_code belle_sdp_time_marshal(belle_sdp_time_t* time, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sdp_time_marshal(belle_sdp_time_t* time, char* buff, size_t buff_size, size_t *offset) {
return belle_sip_snprintf(buff,buff_size,offset,"%i %i",time->start,time->stop);
}
......@@ -1156,7 +1156,7 @@ void belle_sdp_time_description_clone(belle_sdp_time_description_t *time_descrip
if (orig->time) time_description->time = BELLE_SDP_TIME(belle_sip_object_clone_and_ref(BELLE_SIP_OBJECT(orig->time)));
}
belle_sip_error_code belle_sdp_time_description_marshal(belle_sdp_time_description_t* time_description, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sdp_time_description_marshal(belle_sdp_time_description_t* time_description, char* buff, size_t buff_size, size_t *offset) {
return belle_sip_object_marshal(BELLE_SIP_OBJECT(time_description->time),buff,buff_size,offset);
}
......@@ -1200,7 +1200,7 @@ void belle_sdp_version_clone(belle_sdp_version_t *version, const belle_sdp_versi
version->version = orig->version;
}
belle_sip_error_code belle_sdp_version_marshal(belle_sdp_version_t* version, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sdp_version_marshal(belle_sdp_version_t* version, char* buff, size_t buff_size, size_t *offset) {
return belle_sip_snprintf(buff,buff_size,offset,"v=%i",version->version);
}
......
......@@ -82,7 +82,7 @@ const char *belle_sip_header_get_unparsed_value(belle_sip_header_t* obj){
return ret;
}
belle_sip_error_code belle_sip_header_marshal(belle_sip_header_t* header, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_marshal(belle_sip_header_t* header, char* buff, size_t buff_size, size_t *offset) {
if (header->name) {
return belle_sip_snprintf(buff,buff_size,offset,"%s: ",header->name);
} else {
......@@ -121,7 +121,7 @@ static void belle_sip_header_address_clone(belle_sip_header_address_t *addr, con
}
}
belle_sip_error_code belle_sip_header_address_marshal(belle_sip_header_address_t* header, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_address_marshal(belle_sip_header_address_t* header, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=BELLE_SIP_OK;
/*1 display name*/
if (header->displayname) {
......@@ -199,7 +199,7 @@ static void belle_sip_header_allow_destroy(belle_sip_header_allow_t* allow) {
}
belle_sip_error_code belle_sip_header_allow_marshal(belle_sip_header_allow_t* allow, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_allow_marshal(belle_sip_header_allow_t* allow, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(allow), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%s",allow->method);
......@@ -233,7 +233,7 @@ void belle_sip_header_contact_clone(belle_sip_header_contact_t *contact, const b
contact->wildcard=orig->wildcard;
}
belle_sip_error_code belle_sip_header_contact_marshal(belle_sip_header_contact_t* contact, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_contact_marshal(belle_sip_header_contact_t* contact, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(contact), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
if (contact->wildcard) {
......@@ -305,7 +305,7 @@ 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) {
}
belle_sip_error_code belle_sip_header_from_marshal(belle_sip_header_from_t* from, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_from_marshal(belle_sip_header_from_t* from, char* buff, size_t buff_size, size_t *offset) {
BELLE_SIP_FROM_LIKE_MARSHAL(from);
}
......@@ -357,7 +357,7 @@ 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){
}
belle_sip_error_code belle_sip_header_to_marshal(belle_sip_header_to_t* to, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_to_marshal(belle_sip_header_to_t* to, char* buff, size_t buff_size, size_t *offset) {
BELLE_SIP_FROM_LIKE_MARSHAL(to)
}
......@@ -417,7 +417,7 @@ static void belle_sip_header_user_agent_clone(belle_sip_header_user_agent_t* use
}
}
belle_sip_error_code belle_sip_header_user_agent_marshal(belle_sip_header_user_agent_t* user_agent, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_user_agent_marshal(belle_sip_header_user_agent_t* user_agent, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=BELLE_SIP_OK;
belle_sip_list_t* list = user_agent->products;
error=belle_sip_header_marshal(BELLE_SIP_HEADER(user_agent), buff, buff_size, offset);
......@@ -487,7 +487,7 @@ static void belle_sip_header_via_clone(belle_sip_header_via_t* via, const belle_
via->port=orig->port;
}
belle_sip_error_code belle_sip_header_via_marshal(belle_sip_header_via_t* via, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_via_marshal(belle_sip_header_via_t* via, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(via), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%s/%s",via->protocol,via->transport);
......@@ -610,7 +610,7 @@ static void belle_sip_header_call_id_clone(belle_sip_header_call_id_t* call_id,c
CLONE_STRING(belle_sip_header_call_id,call_id,call_id,orig);
}
belle_sip_error_code belle_sip_header_call_id_marshal(belle_sip_header_call_id_t* call_id, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_call_id_marshal(belle_sip_header_call_id_t* call_id, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(call_id), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%s",call_id->call_id);
......@@ -643,7 +643,7 @@ static void belle_sip_header_cseq_clone(belle_sip_header_cseq_t* cseq, const bel
cseq->seq_number=orig->seq_number;
}
belle_sip_error_code belle_sip_header_cseq_marshal(belle_sip_header_cseq_t* cseq, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_cseq_marshal(belle_sip_header_cseq_t* cseq, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(cseq), buff,buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%i %s",cseq->seq_number,cseq->method);
......@@ -681,7 +681,7 @@ static void belle_sip_header_content_type_clone(belle_sip_header_content_type_t*
CLONE_STRING(belle_sip_header_content_type,subtype,content_type,orig);
}
belle_sip_error_code belle_sip_header_content_type_marshal(belle_sip_header_content_type_t* content_type, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_content_type_marshal(belle_sip_header_content_type_t* content_type, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(content_type), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%s/%s",content_type->type, content_type->subtype);
......@@ -715,7 +715,7 @@ 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) {
}
belle_sip_error_code belle_sip_header_route_marshal(belle_sip_header_route_t* route, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_route_marshal(belle_sip_header_route_t* route, char* buff, size_t buff_size, size_t *offset) {
BELLE_SIP_FROM_LIKE_MARSHAL(route)
}
......@@ -742,7 +742,7 @@ static void belle_sip_header_record_route_clone(belle_sip_header_record_route_t*
const belle_sip_header_record_route_t* orig ) {
}
belle_sip_error_code belle_sip_header_record_route_marshal(belle_sip_header_record_route_t* record_route, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_record_route_marshal(belle_sip_header_record_route_t* record_route, char* buff, size_t buff_size, size_t *offset) {
BELLE_SIP_FROM_LIKE_MARSHAL(record_route)
}
......@@ -763,7 +763,7 @@ static void belle_sip_header_service_route_clone(belle_sip_header_service_route_
const belle_sip_header_service_route_t* orig ) {
}
belle_sip_error_code belle_sip_header_service_route_marshal(belle_sip_header_service_route_t* service_route, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_service_route_marshal(belle_sip_header_service_route_t* service_route, char* buff, size_t buff_size, size_t *offset) {
BELLE_SIP_FROM_LIKE_MARSHAL(service_route)
}
......@@ -786,7 +786,7 @@ static void belle_sip_header_content_length_clone(belle_sip_header_content_lengt
content_length->content_length=orig->content_length;
}
belle_sip_error_code belle_sip_header_content_length_marshal(belle_sip_header_content_length_t* content_length, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_content_length_marshal(belle_sip_header_content_length_t* content_length, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(content_length), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%i",content_length->content_length);
......@@ -820,7 +820,7 @@ static void belle_sip_header_expires_clone(belle_sip_header_expires_t* expires,
expires->expires=orig->expires;
}
belle_sip_error_code belle_sip_header_expires_marshal(belle_sip_header_expires_t* expires, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_expires_marshal(belle_sip_header_expires_t* expires, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(expires), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%i",expires->expires);
......@@ -853,7 +853,7 @@ static void belle_sip_header_extension_clone(belle_sip_header_extension_t* exten
CLONE_STRING(belle_sip_header_extension,value,extension,orig)
}
belle_sip_error_code belle_sip_header_extension_marshal(belle_sip_header_extension_t* extension, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_extension_marshal(belle_sip_header_extension_t* extension, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(extension), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%s",extension->value);
......@@ -1016,7 +1016,7 @@ void belle_sip_header_authorization_set_uri(belle_sip_header_authorization_t* au
authorization->uri=uri;
}
belle_sip_error_code belle_sip_header_authorization_marshal(belle_sip_header_authorization_t* authorization, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_authorization_marshal(belle_sip_header_authorization_t* authorization, char* buff, size_t buff_size, size_t *offset) {
char nonce_count[10];
AUTH_BASE_MARSHAL(authorization)
if (authorization->username) {
......@@ -1100,7 +1100,7 @@ static void belle_sip_header_proxy_authorization_clone(belle_sip_header_proxy_au
const belle_sip_header_proxy_authorization_t *orig ) {
}
belle_sip_error_code belle_sip_header_proxy_authorization_marshal(belle_sip_header_proxy_authorization_t* proxy_authorization, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_proxy_authorization_marshal(belle_sip_header_proxy_authorization_t* proxy_authorization, char* buff, size_t buff_size, size_t *offset) {
return belle_sip_header_authorization_marshal(&proxy_authorization->authorization,buff,buff_size,offset);
}
......@@ -1134,7 +1134,7 @@ static void belle_sip_header_www_authenticate_clone(belle_sip_header_www_authent
www_authenticate->qop=belle_sip_list_copy_with_data(orig->qop,(void* (*)(void*))belle_sip_strdup);
}
belle_sip_error_code belle_sip_header_www_authenticate_marshal(belle_sip_header_www_authenticate_t* www_authenticate, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_www_authenticate_marshal(belle_sip_header_www_authenticate_t* www_authenticate, char* buff, size_t buff_size, size_t *offset) {
belle_sip_list_t* qops=www_authenticate->qop;
AUTH_BASE_MARSHAL(www_authenticate)
if (www_authenticate->domain) {
......@@ -1207,7 +1207,7 @@ static void belle_sip_header_proxy_authenticate_clone(belle_sip_header_proxy_aut
const belle_sip_header_proxy_authenticate_t *orig ) {
}
belle_sip_error_code belle_sip_header_proxy_authenticate_marshal(belle_sip_header_proxy_authenticate_t* proxy_authenticate, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_proxy_authenticate_marshal(belle_sip_header_proxy_authenticate_t* proxy_authenticate, char* buff, size_t buff_size, size_t *offset) {
return belle_sip_header_www_authenticate_marshal(&proxy_authenticate->www_authenticate,buff,buff_size,offset);
}
......@@ -1231,7 +1231,7 @@ static void belle_sip_header_max_forwards_clone(belle_sip_header_max_forwards_t*
max_forwards->max_forwards=orig->max_forwards;
}
belle_sip_error_code belle_sip_header_max_forwards_marshal(belle_sip_header_max_forwards_t* max_forwards, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_max_forwards_marshal(belle_sip_header_max_forwards_t* max_forwards, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(max_forwards), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%i",max_forwards->max_forwards);
......@@ -1263,7 +1263,7 @@ static void belle_sip_header_subscription_state_clone(belle_sip_header_subscript
CLONE_STRING(belle_sip_header_subscription_state,state,subscription_state,orig)
}
belle_sip_error_code belle_sip_header_subscription_state_marshal(belle_sip_header_subscription_state_t* subscription_state, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_subscription_state_marshal(belle_sip_header_subscription_state_t* subscription_state, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(subscription_state), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%s",subscription_state->state);
......@@ -1295,7 +1295,7 @@ struct _belle_sip_header_##name { \
static void belle_sip_header_##name##_destroy(belle_sip_header_##name##_t * obj) { \
} \
void belle_sip_header_##name##_clone(belle_sip_header_##name##_t *contact, const belle_sip_header_##name##_t *orig){ }\
belle_sip_error_code belle_sip_header_##name##_marshal(belle_sip_header_##name##_t* name, char* buff, size_t buff_size, unsigned int *offset) {\
belle_sip_error_code belle_sip_header_##name##_marshal(belle_sip_header_##name##_t* name, char* buff, size_t buff_size, size_t *offset) {\
BELLE_SIP_FROM_LIKE_MARSHAL(name)\
}\
BELLE_SIP_NEW_HEADER(header_##name,header_address,header_name)\
......@@ -1337,7 +1337,7 @@ static void belle_sip_header_replaces_clone(belle_sip_header_replaces_t* replace
CLONE_STRING(belle_sip_header_replaces,call_id,replaces,orig)
}
belle_sip_error_code belle_sip_header_replaces_marshal(belle_sip_header_replaces_t* replaces, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_replaces_marshal(belle_sip_header_replaces_t* replaces, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(replaces), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%s",replaces->call_id);
......@@ -1377,14 +1377,14 @@ 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 buff[BELLE_SIP_MAX_TO_STRING_SIZE];
size_t buff_size=sizeof(buff);
unsigned int current_offset=0;
size_t offset=0;
belle_sip_error_code error=BELLE_SIP_OK;
/*first, marshall callid/from/to tags*/
error=belle_sip_snprintf(buff,buff_size,&current_offset,"%s",replaces->call_id);
error=belle_sip_snprintf(buff,buff_size,&offset,"%s",replaces->call_id);
if (error!=BELLE_SIP_OK) return NULL;
error=belle_sip_parameters_marshal(BELLE_SIP_PARAMETERS(replaces), buff, buff_size, &current_offset);
error=belle_sip_parameters_marshal(BELLE_SIP_PARAMETERS(replaces), buff, buff_size, &offset);
if (error!=BELLE_SIP_OK) return NULL;
buff[current_offset]='\0';
buff[offset]='\0';
return belle_sip_to_escaped_string(buff);
}
......@@ -1410,7 +1410,7 @@ static void belle_sip_header_date_clone(belle_sip_header_date_t* obj,
CLONE_STRING(belle_sip_header_date,date,obj,orig);
}
belle_sip_error_code belle_sip_header_date_marshal(belle_sip_header_date_t* obj, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_date_marshal(belle_sip_header_date_t* obj, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(obj), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_snprintf(buff,buff_size,offset,"%s",obj->date);
......@@ -1496,7 +1496,7 @@ void belle_sip_header_p_preferred_identity_destroy(belle_sip_header_p_preferred_
void belle_sip_header_p_preferred_identity_clone(belle_sip_header_p_preferred_identity_t *p_preferred_identity, const belle_sip_header_p_preferred_identity_t *orig){
}
belle_sip_error_code belle_sip_header_p_preferred_identity_marshal(belle_sip_header_p_preferred_identity_t* p_preferred_identity, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_header_p_preferred_identity_marshal(belle_sip_header_p_preferred_identity_t* p_preferred_identity, char* buff, size_t buff_size, size_t *offset) {
belle_sip_error_code error=belle_sip_header_marshal(BELLE_SIP_HEADER(p_preferred_identity), buff, buff_size, offset);
if (error!=BELLE_SIP_OK) return error;
error=belle_sip_header_address_marshal(&p_preferred_identity->address, buff, buff_size, offset);
......
......@@ -20,6 +20,8 @@
static void _belle_sip_object_pool_remove_from_stack(belle_sip_object_pool_t *pool);
static int _belle_sip_object_marshal_check_enabled = FALSE;
static int has_type(belle_sip_object_t *obj, belle_sip_type_id_t id){
belle_sip_object_vptr_t *vptr=obj->vptr;
......@@ -34,6 +36,10 @@ int belle_sip_object_is_instance_of(belle_sip_object_t * obj,belle_sip_type_id_t
return has_type(obj,id);
}
void belle_sip_object_enable_marshal_check(int enable) {
_belle_sip_object_marshal_check_enabled = (enable) ? TRUE : FALSE;
}
belle_sip_object_t * _belle_sip_object_new(size_t objsize, belle_sip_object_vptr_t *vptr){
belle_sip_object_t *obj=(belle_sip_object_t *)belle_sip_malloc0(objsize);
obj->ref=vptr->initially_unowned ? 0 : 1;
......@@ -129,7 +135,7 @@ static void _belle_sip_object_clone(belle_sip_object_t *obj, const belle_sip_obj
if (orig->name!=NULL) obj->name=belle_sip_strdup(obj->name);
}
static belle_sip_error_code _belle_object_marshal(belle_sip_object_t* obj, char* buff, size_t buff_size, unsigned int *offset) {
static belle_sip_error_code _belle_object_marshal(belle_sip_object_t* obj, char* buff, size_t buff_size, size_t *offset) {
return belle_sip_snprintf(buff,buff_size,offset,"{%s::%s %p}",obj->vptr->type_name,obj->name ? obj->name : "(no name)",obj);
}
......@@ -259,42 +265,42 @@ const char* belle_sip_object_get_name(belle_sip_object_t* object) {
return object->name;
}
/*turn this to 1 if you feel a marshal method is buggy.*/
#define CHECKED_MARSHAL 0
#if CHECKED_MARSHAL
static belle_sip_error_code checked_marshal(belle_sip_object_vptr_t *vptr, belle_sip_object_t* obj, char* buff, size_t buff_size, unsigned int *offset){
int tmp_buf_size=buff_size*2;
static belle_sip_error_code checked_marshal(belle_sip_object_vptr_t *vptr, belle_sip_object_t* obj, char* buff, size_t buff_size, size_t *offset){
size_t tmp_buf_size=buff_size*2;
char *p=(char*)belle_sip_malloc0(tmp_buf_size);
int i;
unsigned int initial_offset=*offset;
size_t i;
size_t initial_offset=*offset;
belle_sip_error_code error=vptr->marshal(obj,p,buff_size,offset);
int written;
size_t written;
for (i=initial_offset;i<buff_size;++i){
if (p[i]=='\0') break;
}
written=i-initial_offset;
if (error==BELLE_SIP_BUFFER_OVERFLOW){
belle_sip_fatal("Object of type %s commited a buffer overflow by marshalling %i bytes",
belle_sip_error("Object of type %s commited a buffer overflow by marshalling %i bytes",
vptr->type_name,*offset-initial_offset);
} else if (error!=BELLE_SIP_OK){
belle_sip_fatal("Object of type %s produced an error during marshalling: %i",
belle_sip_error("Object of type %s produced an error during marshalling: %i",
vptr->type_name,error);
}
memcpy(buff+initial_offset,p,*offset-initial_offset);
if (written!=(*offset-initial_offset) && written!=(buff_size-initial_offset-1)){ /*this is because snprintf won't allow you to write a non null character at the end of the buffer*/
belle_sip_fatal("Object of type %s marshalled %i bytes but said it marshalled %i bytes !",
vptr->type_name,written,*offset-initial_offset);
}
memcpy(buff+initial_offset,p+initial_offset,*offset-initial_offset);
belle_sip_free(p);
return ret;
return error;
}
#endif
belle_sip_error_code belle_sip_object_marshal(belle_sip_object_t* obj, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_object_marshal(belle_sip_object_t* obj, char* buff, size_t buff_size, size_t *offset) {
belle_sip_object_vptr_t *vptr=obj->vptr;
while (vptr != NULL) {
if (vptr->marshal != NULL) {
#if CHECKED_MARSHAL
return checked_marshal(vptr,obj,buff,buff_size,offset);
#else
return vptr->marshal(obj,buff,buff_size,offset);
#endif
if (_belle_sip_object_marshal_check_enabled == TRUE)
return checked_marshal(vptr,obj,buff,buff_size,offset);
else
return vptr->marshal(obj,buff,buff_size,offset);
} else {
vptr=vptr->parent;
}
......@@ -305,7 +311,7 @@ belle_sip_error_code belle_sip_object_marshal(belle_sip_object_t* obj, char* buf
static char * belle_sip_object_to_alloc_string(belle_sip_object_t *obj, int size_hint){
char *buf=belle_sip_malloc(size_hint);
unsigned int offset=0;
size_t offset=0;
belle_sip_error_code error = belle_sip_object_marshal(obj,buf,size_hint-1,&offset);
obj->vptr->tostring_bufsize_hint=size_hint;
if (error==BELLE_SIP_BUFFER_OVERFLOW){
......@@ -330,7 +336,7 @@ char* belle_sip_object_to_string(void* _obj) {
return belle_sip_object_to_alloc_string(obj,obj->vptr->tostring_bufsize_hint);
}else{
char buff[BELLE_SIP_MAX_TO_STRING_SIZE];
unsigned int offset=0;
size_t offset=0;
belle_sip_error_code error = belle_sip_object_marshal(obj,buff,sizeof(buff),&offset);
if (error==BELLE_SIP_BUFFER_OVERFLOW){
belle_sip_message("belle_sip_object_to_string(): temporary buffer is too short while doing to_string() for %s, retrying", obj->vptr->type_name);
......
......@@ -41,7 +41,7 @@ static void belle_sip_parameters_clone(belle_sip_parameters_t *params, const bel
}
}
belle_sip_error_code belle_sip_parameters_marshal(const belle_sip_parameters_t* params, char* buff,size_t buff_size,unsigned int *offset) {
belle_sip_error_code belle_sip_parameters_marshal(const belle_sip_parameters_t* params, char* buff, size_t buff_size, size_t *offset) {
belle_sip_list_t* list=params->param_list;
belle_sip_error_code error=BELLE_SIP_OK;
for(;list!=NULL;list=list->next){
......
......@@ -69,7 +69,7 @@ static void belle_sip_uri_clone(belle_sip_uri_t* uri, const belle_sip_uri_t *ori
}
belle_sip_error_code belle_sip_uri_marshal(const belle_sip_uri_t* uri, char* buff, size_t buff_size, unsigned int *offset) {
belle_sip_error_code belle_sip_uri_marshal(const belle_sip_uri_t* uri, char* buff, size_t buff_size, size_t *offset) {
const belle_sip_list_t* list=belle_sip_parameters_get_parameters(uri->header_list);
belle_sip_error_code error=BELLE_SIP_OK;
......
......@@ -106,7 +106,7 @@ char *belle_sip_strdup_printf(const char *fmt,...){
return ret;
}