Commit 644c537c authored by Simon Morlat's avatar Simon Morlat

Merge remote-tracking branch 'origin/master' into dev_http

Conflicts:
	include/belle-sip/Makefile.am
	include/belle-sip/belle-sip.h
	src/Makefile.am
	src/belle_sip_internal.h
parents 957298c1 46e5106e
......@@ -44,6 +44,7 @@ LOCAL_SRC_FILES := \
belle_sdpLexer.c \
belle_sdpParser.c \
belle_sip_object.c \
belle_sip_dict.c \
belle_sip_parameters.c \
belle_sip_resolver.c \
belle_sip_uri_impl.c \
......
......@@ -29,9 +29,11 @@ LT_INIT(win32-dll disable-static)
dnl Workaround for mingw, whose compiler doesn't check in /usr/include ...
case "$target_os" in
*mingw*)
if test "$prefix" = "/usr" ; then
CPPFLAGS="$CPPFLAGS -I/usr/include"
LDFLAGS="$LDFLAGS -L/usr/lib"
if test "$cross_compiling" != "yes"; then
if test "$prefix" = "/usr" ; then
CPPFLAGS="$CPPFLAGS -I/usr/include"
LDFLAGS="$LDFLAGS -L/usr/lib"
fi
fi
;;
esac
......@@ -85,7 +87,7 @@ ANTLR_LIBS="$ANTLR_LIBS -lantlr3c"
dnl check antlr headers
CPPFLAGS_save=$CPPFLAGS
CPPFLAGS="$CPPFLAGS $ANTLR_CFLAGS"
CPPFLAGS="$ANTLR_CFLAGS $CPPFLAGS"
AC_CHECK_HEADERS([antlr3.h], [found_antlr3=yes])
AC_CHECK_DECL( [antlr3StringStreamNew]
,[AC_DEFINE(HAVE_ANTLR_STRING_STREAM_NEW,1,[Defined when antlr 3.4 api is detected])]
......@@ -255,6 +257,10 @@ AM_CONDITIONAL(ENABLE_TESTS, test x$tests_enabled = xyes && test x$found_cunit =
# Checks for typedefs, structures, and compiler characteristics.
# Eliminate -lstdc++ addition to postdeps for cross compiles.
postdeps_CXX=`echo " $postdeps_CXX " | sed 's, -lstdc++ ,,g'`
# Checks for library functions.
AC_CHECK_LIB(rt, clock_gettime)
AC_CHECK_LIB(dl, dlopen)
......
......@@ -21,6 +21,7 @@ bellesip_HEADERS=\
refresher.h \
defs.h \
resolver.h \
dict.h \
http-provider.h \
http-message.h \
http-listener.h
......
......@@ -22,6 +22,7 @@
#include "belle-sip/defs.h"
#include "belle-sip/object.h"
#include "belle-sip/dict.h"
/**
* This enum declares all object types used in belle-sip (see belle_sip_object_t)
......@@ -114,6 +115,7 @@ BELLE_SIP_DECLARE_TYPES_BEGIN(belle_sip,1)
BELLE_SIP_TYPE_ID(belle_sip_dns_srv_t),
BELLE_SIP_TYPE_ID(belle_sip_simple_resolver_context_t),
BELLE_SIP_TYPE_ID(belle_sip_combined_resolver_context_t),
BELLE_SIP_TYPE_ID(belle_sip_dict_t),
BELLE_SIP_TYPE_ID(belle_http_provider_t),
BELLE_SIP_TYPE_ID(belle_http_request_t),
BELLE_SIP_TYPE_ID(belle_http_response_t),
......
/*
belle-sip - SIP (RFC3261) 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/>.
*/
#ifndef DICT_H
#define DICT_H
#ifndef WIN32
#include <sys/types.h>
#endif
#include <inttypes.h>
#include "object.h"
BELLE_SIP_BEGIN_DECLS
typedef struct belle_sip_dict belle_sip_dict_t;
#define BELLE_SIP_DICT(obj) BELLE_SIP_CAST(obj,belle_sip_dict_t)
/**
* @brief belle_sip_dict_create
* @return an instance of a belle_sip_dict_t object.
* @note The object is not owned by default.
* @note all belle_sip_dict_set_* functions will overwrite existing values.
*/
BELLESIP_EXPORT belle_sip_dict_t* belle_sip_dict_create();
/**
* @brief belle_sip_dict_set_int stores an integer into the dictionary
* @param obj the dictionary instance
* @param key the name of the integer to store
* @param value value to store
*/
BELLESIP_EXPORT void belle_sip_dict_set_int(belle_sip_dict_t* obj, const char* key, int value);
/**
* @brief belle_sip_dict_get_int retrieves an integer from the dictionary
* @param obj the dictionary instance
* @param key name of the integer to retrieve
* @param default_value value to return if the key is not found
* @return the searched integer if the key exists, default_value if not found
*/
BELLESIP_EXPORT int belle_sip_dict_get_int(belle_sip_dict_t* obj, const char* key, int default_value);
/**
* @brief belle_sip_dict_set_string stores a string into the dictionary
* @param obj the dictionary instance
* @param key the name of the string to store
* @param value value to store
*/
BELLESIP_EXPORT void belle_sip_dict_set_string(belle_sip_dict_t* obj, const char* key, const char*value);
/**
* @brief belle_sip_dict_get_string retrieves a string from the dictionary
* @param obj the dictionary instance
* @param key the name of the string to retrieve
* @param default_value
* @return the searched string if the key exists, default_value if not found
*/
BELLESIP_EXPORT const char* belle_sip_dict_get_string(belle_sip_dict_t* obj, const char* key, const char* default_value);
/**
* @brief belle_sip_dict_set_int64 stores an int64 in the dictionary
* @param obj the dictionary instance
* @param key the name of the integer to store
* @param value value to store
*/
BELLESIP_EXPORT void belle_sip_dict_set_int64(belle_sip_dict_t* obj, const char* key, int64_t value);
/**
* @brief belle_sip_dict_get_int64 retrieves an int64 from the dictionary
* @param obj the dictionary instance
* @param key the name of the integer to retrieve
* @param default_value value to return if the key is not found
* @return the searched int64 if the key exists, default_value if not found
*/
BELLESIP_EXPORT int64_t belle_sip_dict_get_int64(belle_sip_dict_t* obj, const char* key, int64_t default_value);
/**
* @brief belle_sip_dict_remove will erase the value for a key
* @param obj the dictionary instance
* @param key the name of the integer to remove
* @return 0 if the key was found, 1 otherwise
*/
BELLESIP_EXPORT int belle_sip_dict_remove(belle_sip_dict_t* obj, const char* key);
/**
* @brief belle_sip_dict_clear will clear the object's dictionary.
* @param obj the dictionary instance
*/
BELLESIP_EXPORT void belle_sip_dict_clear(belle_sip_dict_t* obj);
/**
* Clones the source dictionary into the dst dictionary. The dst dictionary is cleared before the cloning
* is done.
* @param src source dictionary
* @param dst destination dictionary
*/
BELLESIP_EXPORT void belle_sip_dict_clone( const belle_sip_dict_t* src, belle_sip_dict_t* dst);
/**
* Merge the source dictionary into the destination dictionary.
*
* Same function as #belle_sip_dict_clone, except the destination dictionary is not cleared before inserting the source data.
* This overwrites common keys, and keeps existing keys.
*/
BELLESIP_EXPORT void belle_sip_dict_merge( const belle_sip_dict_t* src, belle_sip_dict_t* dst);
/**
* @brief belle_sip_dict_haskey tells if a key exists in the dictionary.
* @param obj the dictionary instance
* @param key the key to look for
* @return 1 if the key exists, 0 otherwise
* @todo create unit test
*/
BELLESIP_EXPORT int belle_sip_dict_haskey(belle_sip_dict_t* obj, const char* key);
/**
* Apply a function for all keys stored in the dictionary
*/
BELLESIP_EXPORT void belle_sip_dict_foreach(const belle_sip_dict_t* obj, void (*apply_func)(const char*, void*, void*), void* userdata);
BELLE_SIP_END_DECLS
#endif // DICT_H
This diff is collapsed.
......@@ -54,6 +54,10 @@ BELLESIP_EXPORT int belle_sip_stack_get_dns_timeout(const belle_sip_stack_t *sta
BELLESIP_EXPORT void belle_sip_stack_set_dns_timeout(belle_sip_stack_t *stack, int timeout);
BELLESIP_EXPORT unsigned char belle_sip_stack_dns_srv_enabled(const belle_sip_stack_t *stack);
BELLESIP_EXPORT void belle_sip_stack_enable_dns_srv(belle_sip_stack_t *stack, unsigned char enable);
/**
* Can be used to simulate network transmission delays, for tests.
**/
......
......@@ -63,6 +63,7 @@ libbellesip_la_SOURCES= \
transports/stream_listeningpoint.c \
refresher.c \
dns.c dns.h \
belle_sip_dict.c \
http-provider.c \
http-message.c
......
/*
belle-sip - SIP (RFC3261) 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/>.
*/
#include "belle-sip/dict.h"
#include "belle-sip/object.h"
#include "belle-sip/belle-sip.h"
#include "belle_sip_internal.h"
#define BELLE_SIP_DICT(obj) BELLE_SIP_CAST(obj,belle_sip_dict_t)
static void belle_sip_dict_string_destroy( void* data )
{
belle_sip_free(data);
}
static void* belle_sip_dict_string_clone( const char* str, void* data )
{
(void)str;
return belle_sip_strdup((const char*)data);
}
belle_sip_dict_t* belle_sip_dict_create()
{
return belle_sip_object_new(belle_sip_dict_t);
}
static void belle_sip_dict_destroy( belle_sip_dict_t* obj)
{
}
void belle_sip_dict_set_int(belle_sip_dict_t* obj, const char* key, int value)
{
char tmp[30];
snprintf(tmp,sizeof(tmp),"%i",value);
belle_sip_dict_set_string(obj, key, tmp);
}
int belle_sip_dict_get_int(belle_sip_dict_t* obj, const char* key, int default_value)
{
const char *str=belle_sip_object_data_get(BELLE_SIP_OBJECT(obj),key);
if (str!=NULL) {
int ret=0;
if (strstr(str,"0x")==str){
sscanf(str,"%x",&ret);
}else ret=atoi(str);
return ret;
}
else return default_value;
}
void belle_sip_dict_set_string(belle_sip_dict_t* obj, const char*key, const char*value)
{
belle_sip_object_data_set( BELLE_SIP_OBJECT(obj), key, (void*)belle_sip_strdup(value), belle_sip_dict_string_destroy );
}
const char* belle_sip_dict_get_string(belle_sip_dict_t* obj, const char* key, const char* default_value)
{
void* data = belle_sip_object_data_get( BELLE_SIP_OBJECT(obj), key );
if( data ) return (const char *)data;
else return default_value;
}
void belle_sip_dict_set_int64(belle_sip_dict_t* obj, const char* key, int64_t value)
{
char tmp[30];
snprintf(tmp,sizeof(tmp),"%"PRId64"",value);
belle_sip_dict_set_string(obj,key,tmp);
}
int64_t belle_sip_dict_get_int64(belle_sip_dict_t* obj, const char* key, int64_t default_value)
{
const char *str= belle_sip_object_data_get( BELLE_SIP_OBJECT(obj), key );
if (str!=NULL) {
#ifdef WIN32
return (int64_t)_atoi64(str);
#else
return atoll(str);
#endif
}
else return default_value;
}
int belle_sip_dict_remove(belle_sip_dict_t* obj, const char*key)
{
return belle_sip_object_data_remove(BELLE_SIP_OBJECT(obj), key);
}
void belle_sip_dict_clone( const belle_sip_dict_t* src, belle_sip_dict_t* dst)
{
belle_sip_dict_clear(dst);
belle_sip_dict_merge(src, dst);
}
void belle_sip_dict_merge( const belle_sip_dict_t* src, belle_sip_dict_t* dst)
{
belle_sip_object_data_merge(BELLE_SIP_OBJECT(src), BELLE_SIP_OBJECT(dst), belle_sip_dict_string_clone);
}
int belle_sip_dict_haskey(belle_sip_dict_t* obj, const char* key)
{
return belle_sip_object_data_exists(BELLE_SIP_OBJECT(obj), key);
}
void belle_sip_dict_foreach(const belle_sip_dict_t* obj, void (*apply_func)(const char*, void*, void*), void* userdata)
{
belle_sip_object_data_foreach(BELLE_SIP_OBJECT(obj),apply_func, userdata);
}
void belle_sip_dict_clear(belle_sip_dict_t* obj)
{
return belle_sip_object_data_clear(BELLE_SIP_OBJECT(obj));
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_dict_t);
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_dict_t, belle_sip_object_t,
belle_sip_dict_destroy,
NULL,
NULL,
TRUE);
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
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 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.
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/>.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef belle_utils_h
#define belle_utils_h
......@@ -124,7 +124,6 @@ void belle_sip_object_pool_remove(belle_sip_object_pool_t *pool, belle_sip_objec
/*list of all vptrs (classes) used in belle-sip*/
BELLE_SIP_DECLARE_VPTR(belle_sip_object_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_stack_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_datagram_listening_point_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_provider_t);
......@@ -190,6 +189,7 @@ BELLE_SIP_DECLARE_VPTR(belle_sip_header_privacy_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_certificates_chain_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_signing_key_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_dns_srv_t);
BELLE_SIP_DECLARE_VPTR(belle_sip_dict_t)
BELLE_SIP_DECLARE_VPTR(belle_http_provider_t);
BELLE_SIP_DECLARE_VPTR(belle_http_channel_context_t);
......@@ -241,7 +241,7 @@ void belle_sip_source_uninit(belle_sip_source_t *s);
#define belle_sip_new(type) (type*)belle_sip_malloc(sizeof(type))
#define belle_sip_new0(type) (type*)belle_sip_malloc0(sizeof(type))
belle_sip_list_t *belle_sip_list_new(void *data);
belle_sip_list_t* belle_sip_list_append_link(belle_sip_list_t* elem,belle_sip_list_t *new_elem);
belle_sip_list_t *belle_sip_list_delete_custom(belle_sip_list_t *list, belle_sip_compare_func compare_func, const void *user_data);
......@@ -249,7 +249,10 @@ belle_sip_list_t *belle_sip_list_delete_custom(belle_sip_list_t *list, belle_sip
#define belle_sip_list_next(elem) ((elem)->next)
/* dictionary */
struct belle_sip_dict {
belle_sip_object_t base;
};
#undef MIN
......@@ -408,7 +411,7 @@ belle_sip_##object_type##_t* belle_sip_##object_type##_parse (const char* value)
return l_object;\
}
#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_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_##object_type##_t); \
......@@ -500,6 +503,7 @@ struct belle_sip_stack{
int resolver_send_error; /* used to simulate network error*/
int dscp;
char *dns_user_hosts_file; /* used to load additional hosts file for tests */
unsigned char dns_srv_enabled;
};
belle_sip_hop_t* belle_sip_hop_new(const char* transport, const char *cname, const char* host,int port);
......@@ -532,8 +536,8 @@ void belle_sip_provider_add_client_transaction(belle_sip_provider_t *prov, belle
belle_sip_client_transaction_t *belle_sip_provider_find_matching_client_transaction(belle_sip_provider_t *prov, belle_sip_response_t *resp);
void belle_sip_provider_remove_client_transaction(belle_sip_provider_t *prov, belle_sip_client_transaction_t *t);
void belle_sip_provider_add_server_transaction(belle_sip_provider_t *prov, belle_sip_server_transaction_t *t);
belle_sip_server_transaction_t * belle_sip_provider_find_matching_server_transaction(belle_sip_provider_t *prov,
belle_sip_request_t *req);
belle_sip_server_transaction_t * belle_sip_provider_find_matching_server_transaction(belle_sip_provider_t *prov,
belle_sip_request_t *req);
void belle_sip_provider_remove_server_transaction(belle_sip_provider_t *prov, belle_sip_server_transaction_t *t);
void belle_sip_provider_set_transaction_terminated(belle_sip_provider_t *p, belle_sip_transaction_t *t);
belle_sip_channel_t * belle_sip_provider_get_channel(belle_sip_provider_t *p, const belle_sip_hop_t *hop);
......@@ -575,7 +579,7 @@ struct _belle_sip_message {
char* body;
unsigned int body_length;
};
struct _belle_sip_request {
belle_sip_message_t message;
char* method;
......@@ -602,7 +606,7 @@ struct belle_sip_transaction{
belle_sip_transaction_state_t state;
void *appdata;
unsigned char is_internal;
unsigned char timed_out;
unsigned char timed_out;
};
......@@ -735,7 +739,7 @@ belle_sip_nist_t * belle_sip_nist_new(belle_sip_provider_t *prov, belle_sip_requ
/*
* Dialogs
*/
*/
struct belle_sip_dialog{
belle_sip_object_t base;
void *appdata;
......
/*
belle-sip - SIP (RFC3261) library.
Copyright (C) 2010 Belledonne Communications SARL
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 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.
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/>.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "belle_sip_internal.h"
......@@ -24,7 +24,7 @@ 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;
while(vptr!=NULL){
if (vptr->id==id) return TRUE;
vptr=vptr->parent;
......@@ -158,13 +158,14 @@ belle_sip_object_vptr_t belle_sip_object_t_vptr={
void belle_sip_object_delete(void *ptr){
belle_sip_object_t *obj=BELLE_SIP_OBJECT(ptr);
belle_sip_object_vptr_t *vptr;
belle_sip_object_loose_weak_refs(obj);
vptr=obj->vptr;
while(vptr!=NULL){
if (vptr->destroy) vptr->destroy(obj);
vptr=vptr->parent;
}
belle_sip_object_data_clear(obj);
belle_sip_free(obj);
}
......@@ -199,7 +200,7 @@ void _belle_sip_object_copy(belle_sip_object_t *newobj, const belle_sip_object_t
belle_sip_object_t *belle_sip_object_clone(const belle_sip_object_t *obj){
belle_sip_object_t *newobj;
newobj=belle_sip_malloc0(obj->size);
newobj->ref=obj->vptr->initially_unowned ? 0 : 1;
newobj->vptr=obj->vptr;
......@@ -216,6 +217,146 @@ belle_sip_object_t *belle_sip_object_clone_and_ref(const belle_sip_object_t *obj
return belle_sip_object_ref(belle_sip_object_clone(obj));
}
struct belle_sip_object_data{
char* name;
void* data;
belle_sip_data_destroy destroy_func;
};
static int belle_sip_object_data_find(const void* a, const void* b)
{
struct belle_sip_object_data* da = (struct belle_sip_object_data*)a;
return strcmp(da->name, (const char*)b);
}
static void belle_sip_object_data_destroy(void* data)
{
struct belle_sip_object_data* da = (struct belle_sip_object_data*)data;
if(da->destroy_func ) da->destroy_func(da->data);
belle_sip_free(da->name);
}
int belle_sip_object_data_set( belle_sip_object_t *obj, const char* name, void* data, belle_sip_data_destroy destroy_func )
{
int ret = 0;
struct _belle_sip_list* list_entry = belle_sip_list_find_custom(obj->data_store, belle_sip_object_data_find, name);
struct belle_sip_object_data* entry = (list_entry)? list_entry->data : NULL;
if( entry == NULL){
entry = belle_sip_malloc0(sizeof( struct belle_sip_object_data));
obj->data_store = belle_sip_list_append(obj->data_store, entry);
}
else {
// clean previous data
if( entry->destroy_func ) entry->destroy_func(entry->data);
belle_sip_free(entry->name);
ret = 1;
}
if( entry ){
entry->data = data;
entry->name = belle_sip_strdup(name);
entry->destroy_func = destroy_func;
} else {
ret = -1;
}
return ret;
}
void* belle_sip_object_data_get( belle_sip_object_t *obj, const char* name )
{
struct _belle_sip_list* list_entry = belle_sip_list_find_custom(obj->data_store, belle_sip_object_data_find, name);
struct belle_sip_object_data* entry = (list_entry)? list_entry->data : NULL;
return entry? entry->data : NULL;
}
int belle_sip_object_data_remove( belle_sip_object_t *obj, const char* name)
{
struct _belle_sip_list* list_entry = belle_sip_list_find_custom(obj->data_store, belle_sip_object_data_find, name);
struct belle_sip_object_data* entry = (list_entry)? list_entry->data : NULL;
if( entry ){
belle_sip_free(entry->name);
if( entry->destroy_func ) entry->destroy_func(entry->data);
belle_sip_free(entry);
}
if( list_entry ) obj->data_store = belle_sip_list_remove_link(obj->data_store, list_entry);
return !(list_entry!= NULL);
}
int belle_sip_object_data_exists( belle_sip_object_t *obj, const char* name )
{
return (belle_sip_list_find_custom(obj->data_store, belle_sip_object_data_find, name) != NULL);
}
void* belle_sip_object_data_grab( belle_sip_object_t* obj, const char* name)
{
struct _belle_sip_list* list_entry = belle_sip_list_find_custom(obj->data_store, belle_sip_object_data_find, name);
struct belle_sip_object_data* entry = (list_entry)? list_entry->data : NULL;
void* data =NULL;
if( entry ){
belle_sip_free(entry->name);
data = entry->data;
}
obj->data_store = belle_sip_list_remove_link(obj->data_store, list_entry);
belle_sip_free(entry);
return data;
}
void belle_sip_object_data_clear( belle_sip_object_t* obj )
{
belle_sip_list_for_each(obj->data_store, belle_sip_object_data_destroy);
obj->data_store = belle_sip_list_free(obj->data_store);
}
void belle_sip_object_data_clone( const belle_sip_object_t* src, belle_sip_object_t* dst, belle_sip_data_clone clone_func)
{
belle_sip_object_data_clear(dst);
belle_sip_object_data_merge(src, dst, clone_func);
}
void belle_sip_object_data_merge( const belle_sip_object_t* src, belle_sip_object_t* dst, belle_sip_data_clone clone_func)
{
struct _belle_sip_list* list = src->data_store;
struct belle_sip_object_data* it = NULL;
void* cloned_data = NULL;
while( list ){
it = list->data;
if( it ){
cloned_data = (clone_func)? clone_func( it->name, it->data ) : it->data;
belle_sip_object_data_set(dst, it->name, cloned_data, it->destroy_func);
}
list = list->next;
}
}
struct belle_sip_object_foreach_data {
void (*apply_func)(const char*, void*, void*);
void* userdata;
};
static void belle_sip_object_for_each_cb(void* data, void* userdata)
{
struct belle_sip_object_foreach_data* fd = (struct belle_sip_object_foreach_data*)userdata;
struct belle_sip_object_data* it = (struct belle_sip_object_data*)data;
if( it && fd->apply_func )
fd->apply_func(it->name, it->data, userdata);
}
void belle_sip_object_data_foreach( const belle_sip_object_t* obj, void (*apply_func)(const char* key, void* data, void* userdata), void* userdata)
{
struct belle_sip_object_foreach_data fd = { apply_func, userdata };
belle_sip_list_for_each2(obj->data_store, belle_sip_object_for_each_cb, &fd);
}
void *belle_sip_object_cast(belle_sip_object_t *obj, belle_sip_type_id_t id, const char *castname, const char *file, int fileno){
if (obj!=NULL){
if (has_type(obj,id)==0){
......@@ -313,7 +454,7 @@ belle_sip_error_code belle_sip_object_marshal(belle_sip_object_t* obj, char* buf
return BELLE_SIP_NOT_IMPLEMENTED; /*no implementation found*/
}
static char * belle_sip_object_to_alloc_string(belle_sip_object_t *obj, int size_hint){
char *buf=belle_sip_malloc(size_hint);
size_t offset=0;
......@@ -361,7 +502,7 @@ char * _belle_sip_object_describe_type(belle_sip_object_vptr_t *vptr){
belle_sip_list_t *l=NULL,*elem;
belle_sip_snprintf(ret,maxbufsize,&pos,"Ownership:\n");
belle_sip_snprintf(ret,maxbufsize,&pos,"\t%s is created initially %s\n",vptr->type_name,
vptr->initially_unowned ? "unowned" : "owned");
vptr->initially_unowned ? "unowned" : "owned");
belle_sip_snprintf(ret,maxbufsize,&pos,"\nInheritance diagram:\n");
for(it=vptr;it!=NULL;it=it->parent){
l=belle_sip_list_prepend(l,it);
......@@ -398,7 +539,7 @@ char *belle_sip_object_describe_type_from_name(const char *name){
char *vptr_name;
void *handle;
void *symbol;
handle=dlopen(NULL,RTLD_LAZY);
if (handle==NULL){
belle_sip_error("belle_sip_object_describe_type_from_name: dlopen() failed: %s",dlerror());
......@@ -473,13 +614,13 @@ int belle_sip_object_pool_cleanable(belle_sip_object_pool_t *pool){
void belle_sip_object_pool_clean(belle_sip_object_pool_t *pool){
belle_sip_list_t *elem,*next;
if (!belle_sip_object_pool_cleanable(pool)){
belle_sip_warning("Thread pool [%p] cannot be cleaned from thread [%lu] because it was created for thread [%lu]",
pool,belle_sip_thread_self_id(),(unsigned long)pool->thread_id);
return;
}
for(elem=pool->objects;elem!=NULL;elem=next){
belle_sip_object_t *obj=(belle_sip_object_t*)elem->data;
if (obj->ref==0){
......@@ -523,9 +664,9 @@ static belle_sip_list_t** get_current_pool_stack(int *first_time){
static belle_sip_thread_key_t pools_key;
static int pools_key_created=0;
belle_sip_list_t **pool_stack;