Commit c195cbf9 authored by Danmei Chen's avatar Danmei Chen

Merge branch 'master' into dev_sha256

parents 3129623a 51906fb4
......@@ -84,19 +84,23 @@ typedef unsigned int belle_sip_type_id_t;
(belle_sip_object_get_vptr_t)BELLE_SIP_OBJECT_GET_VPTR_FUNC(parent_type), \
(belle_sip_interface_desc_t**)object_type##interfaces_table
#define BELLE_SIP_INSTANCIATE_VPTR(object_type,parent_type,destroy,clone,marshal,unowned) \
static BELLE_SIP_OBJECT_VPTR_TYPE(object_type) BELLE_SIP_OBJECT_VPTR_NAME(object_type)={ \
#define BELLE_SIP_INSTANCIATE_VPTR2(object_type,parent_type,destroy,clone,marshal,on_first_ref,on_last_ref,unowned) \
static BELLE_SIP_OBJECT_VPTR_TYPE(object_type) BELLE_SIP_OBJECT_VPTR_NAME(object_type)={ \
BELLE_SIP_VPTR_INIT(object_type,parent_type,unowned), \
(belle_sip_object_destroy_t)destroy, \
(belle_sip_object_clone_t)clone, \
(belle_sip_object_marshal_t)marshal,\
(belle_sip_object_on_first_ref_t)on_first_ref,\
(belle_sip_object_on_last_ref_t)on_last_ref,\
BELLE_SIP_DEFAULT_BUFSIZE_HINT\
}; \
BELLE_SIP_OBJECT_VPTR_TYPE(object_type) * BELLE_SIP_OBJECT_GET_VPTR_FUNC(object_type)(void){\
return &BELLE_SIP_OBJECT_VPTR_NAME(object_type); \
}
#define BELLE_SIP_INSTANCIATE_VPTR(object_type,parent_type,destroy,clone,marshal,unowned) \
BELLE_SIP_INSTANCIATE_VPTR2(object_type, parent_type, destroy, clone, marshal, NULL, NULL, unowned)
/**
* belle_sip_object_t is the base object.
* It is the base class for all belle sip non trivial objects.
......@@ -143,6 +147,8 @@ 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 belle_sip_error_code (*belle_sip_object_marshal_t)(belle_sip_object_t* obj, char* buff, size_t buff_size, size_t *offset);
typedef struct _belle_sip_object_vptr *(*belle_sip_object_get_vptr_t)(void);
typedef void (*belle_sip_object_on_first_ref_t)(belle_sip_object_t*);
typedef void (*belle_sip_object_on_last_ref_t)(belle_sip_object_t*);
struct _belle_sip_object_vptr{
belle_sip_type_id_t id;
......@@ -154,6 +160,8 @@ struct _belle_sip_object_vptr{
belle_sip_object_destroy_t destroy;
belle_sip_object_clone_t clone;
belle_sip_object_marshal_t marshal;
belle_sip_object_on_first_ref_t on_first_ref; /*called when object is ref'd for the first time*/
belle_sip_object_on_last_ref_t on_last_ref; /*called in unref() when the last reference of the object remains*/
int tostring_bufsize_hint; /*optimization: you can suggest here the typical size for a to_string() result.*/
};
......@@ -175,8 +183,11 @@ BELLE_SIP_BEGIN_DECLS
BELLESIP_EXPORT belle_sip_object_t * _belle_sip_object_new(size_t objsize, belle_sip_object_vptr_t *vptr);
#ifdef __cplusplus
#define belle_sip_object_new(_type) reinterpret_cast<_type*>(_belle_sip_object_new(sizeof(_type),(belle_sip_object_vptr_t*)BELLE_SIP_OBJECT_GET_VPTR_FUNC(_type)()))
#else
#define belle_sip_object_new(_type) (_type*)_belle_sip_object_new(sizeof(_type),(belle_sip_object_vptr_t*)BELLE_SIP_OBJECT_GET_VPTR_FUNC(_type)())
#endif
/**
* Activates checks on object marshalling.
......
......@@ -94,12 +94,14 @@ void belle_sip_object_dump_active_objects(void){
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(vptr->size);
obj->ref=vptr->initially_unowned ? 0 : 1;
obj->vptr=vptr;
if (obj->ref==0){
obj->vptr = vptr;
obj->ref = vptr->initially_unowned ? 0 : 1;
if (obj->ref == 0) {
belle_sip_object_pool_t *pool=belle_sip_object_pool_get_current();
if (pool) belle_sip_object_pool_add(pool,obj);
}
add_new_object(obj);
return obj;
}
......@@ -110,10 +112,14 @@ int belle_sip_object_is_initially_unowned(const belle_sip_object_t *obj){
belle_sip_object_t * belle_sip_object_ref(void *obj){
belle_sip_object_t *o=BELLE_SIP_OBJECT(obj);
if (o->ref==0 && o->pool){
if (o->ref == 0 && o->pool) {
belle_sip_object_pool_remove(o->pool,obj);
}
if (o->vptr->on_first_ref && (o->ref == 0 || (!o->vptr->initially_unowned && o->ref == 1)))
o->vptr->on_first_ref(o);
o->ref++;
return obj;
}
......@@ -126,6 +132,7 @@ void belle_sip_object_unref(void *ptr){
belle_sip_fatal("Fatal object error encountered, aborting.");
return;
}
if (obj->vptr->initially_unowned && obj->ref==0){
if (obj->pool)
belle_sip_object_pool_remove(obj->pool,obj);
......@@ -133,7 +140,15 @@ void belle_sip_object_unref(void *ptr){
belle_sip_object_delete(obj);
return;
}
obj->ref--;
if (obj->vptr->on_last_ref){
if ((obj->vptr->initially_unowned && obj->ref==0)
|| (!obj->vptr->initially_unowned && obj->ref == 1)){
obj->vptr->on_last_ref(obj);
}
}
if (obj->ref == 0){
obj->ref = -1;
belle_sip_object_delete(obj);
......@@ -807,5 +822,3 @@ belle_sip_object_pool_t *belle_sip_object_pool_get_current(void){
}
return (belle_sip_object_pool_t*)(*pools)->data;
}
......@@ -442,11 +442,11 @@ typedef struct uri_components {
} uri_components_t;
/*belle sip allows contact header without host because stack will auutomatically put host if missing*/
/*belle sip allows contact header without host because stack will automatically put host if missing*/
static uri_components_t uri_component_use_for_request = {"Req.-URI" ,o ,o ,m ,o ,o ,na ,o ,o ,o ,o ,o ,na};
static uri_components_t uri_component_use_for_header_to = {"Header To" ,o ,o ,m ,na ,o ,na ,na ,na ,na ,na ,o ,na};
static uri_components_t uri_component_use_for_header_from = {"Header From" ,o ,o ,m ,na ,o ,na ,na ,na ,na ,na ,o ,na};
static uri_components_t uri_component_use_for_header_refer_to = {"Header Refer-To" ,o ,o ,/*m*/o ,na ,o ,na ,na ,na ,na ,na ,o ,na};
static uri_components_t uri_component_use_for_header_refer_to = {"Header Refer-To" ,o ,o ,o ,o ,o ,o ,o ,o ,o ,o ,o ,o};
static uri_components_t uri_component_use_for_contact_in_reg = {"Contact in REG" ,o ,o ,/*m*/o ,o ,o ,na ,o ,o ,o ,na ,o ,o};
static uri_components_t uri_component_use_for_dialog_ct_rr_ro = {"Dialog Contact/R-R/Route" ,o ,o ,/*m*/o ,o ,o ,na ,o ,na ,o ,o ,o ,na};
static uri_components_t uri_component_use_for_external = {"External" ,o ,o ,m ,o ,o ,o ,o ,o ,o ,o ,o ,o};
......
......@@ -75,6 +75,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_body_handler_t)
(belle_sip_object_destroy_t) belle_sip_body_handler_destroy,
(belle_sip_object_clone_t) belle_sip_body_handler_clone,
(belle_sip_object_marshal_t) belle_sip_body_handler_marshal,
(belle_sip_object_on_first_ref_t) NULL,
(belle_sip_object_on_last_ref_t) NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
NULL, /* begin_recv_transfer */
......
......@@ -152,6 +152,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_channel_t)
(belle_sip_object_destroy_t)belle_sip_channel_destroy,
NULL, /*clone*/
NULL, /*marshal*/
NULL, /*on_first_ref*/
NULL, /*on_last_ref*/
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
NULL, /* transport */
......
......@@ -55,13 +55,9 @@ static void belle_sip_dialog_uninit(belle_sip_dialog_t *obj){
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(belle_sip_dialog_t);
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_dialog_t)
BELLE_SIP_VPTR_INIT(belle_sip_dialog_t, belle_sip_object_t,TRUE),
(belle_sip_object_destroy_t)belle_sip_dialog_uninit,
NULL,
NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_END
BELLE_SIP_INSTANCIATE_VPTR(belle_sip_dialog_t, belle_sip_object_t, belle_sip_dialog_uninit, NULL, NULL, TRUE);
const char* belle_sip_dialog_state_to_string(const belle_sip_dialog_state_t state) {
switch(state) {
......
......@@ -210,6 +210,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_ict_t)
(belle_sip_object_destroy_t)ict_destroy,
NULL,
NULL,
(belle_sip_object_on_first_ref_t) NULL,
(belle_sip_object_on_last_ref_t) NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
(void (*)(belle_sip_transaction_t*))on_ict_terminate
......
......@@ -174,6 +174,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_ist_t)
(belle_sip_object_destroy_t)ist_destroy,
NULL,
NULL,
(belle_sip_object_on_first_ref_t) NULL,
(belle_sip_object_on_last_ref_t) NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
(void (*)(belle_sip_transaction_t *))ist_on_terminate
......
......@@ -106,6 +106,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_listening_point_t)
(belle_sip_object_destroy_t)belle_sip_listening_point_uninit,
NULL,
NULL,
(belle_sip_object_on_first_ref_t) NULL,
(belle_sip_object_on_last_ref_t) NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
NULL,
......
......@@ -321,6 +321,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_server_transaction_t)
(belle_sip_object_destroy_t) server_transaction_destroy,
NULL,
NULL,
(belle_sip_object_on_first_ref_t) NULL,
(belle_sip_object_on_last_ref_t) NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
NULL
......@@ -633,6 +635,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_client_transaction_t)
(belle_sip_object_destroy_t)client_transaction_destroy,
NULL,
NULL,
(belle_sip_object_on_first_ref_t) NULL,
(belle_sip_object_on_last_ref_t) NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
NULL
......
......@@ -162,6 +162,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_stream_channel_t)
(belle_sip_object_destroy_t)stream_channel_uninit,
NULL,
NULL,
(belle_sip_object_on_first_ref_t) NULL,
(belle_sip_object_on_last_ref_t) NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
"TCP",
......
......@@ -454,6 +454,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_tls_channel_t)
(belle_sip_object_destroy_t)tls_channel_uninit,
NULL,
NULL,
(belle_sip_object_on_first_ref_t) NULL,
(belle_sip_object_on_last_ref_t) NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
"TLS",
......
......@@ -132,7 +132,10 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_tunnel_channel_t)
BELLE_SIP_VPTR_INIT(belle_sip_tunnel_channel_t,belle_sip_channel_t,FALSE),
(belle_sip_object_destroy_t)tunnel_channel_uninit,
NULL,
NULL
NULL,
(belle_sip_object_on_first_ref_t) NULL,
(belle_sip_object_on_last_ref_t) NULL,
0
},
"UDP",
0, /*is_reliable*/
......
......@@ -38,7 +38,10 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_tunnel_listening_point_t)
BELLE_SIP_VPTR_INIT(belle_sip_tunnel_listening_point_t, belle_sip_listening_point_t,TRUE),
NULL,
NULL,
NULL
NULL,
(belle_sip_object_on_first_ref_t) NULL,
(belle_sip_object_on_last_ref_t) NULL,
0
},
"UDP",
tunnel_create_channel
......
......@@ -95,6 +95,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_udp_channel_t)
(belle_sip_object_destroy_t)udp_channel_uninit,
NULL,
NULL,
(belle_sip_object_on_first_ref_t) NULL,
(belle_sip_object_on_last_ref_t) NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
"UDP",
......
......@@ -52,6 +52,8 @@ BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_udp_listening_point_t)
(belle_sip_object_destroy_t)belle_sip_udp_listening_point_uninit,
NULL,
NULL,
(belle_sip_object_on_first_ref_t) NULL,
(belle_sip_object_on_last_ref_t) NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
"UDP",
......
......@@ -28,7 +28,7 @@
static belle_sip_stack_t *stack;
static void resolver_callback(void *data, const char *queried_name, struct addrinfo *ai_list){
static void resolver_callback(void *data, const char *queried_name, struct addrinfo *ai_list, unsigned int ttl){
int err;
struct addrinfo *ai_it;
char name[NI_MAXHOST];
......@@ -39,7 +39,7 @@ static void resolver_callback(void *data, const char *queried_name, struct addri
if (err!=0){
fprintf(stderr,"getnameinfo error: %s",gai_strerror(err));
}else{
printf("\t%s %s\n",name,port);
printf("\t%s %s (ttl:%u)\n",name,port,ttl);
}
}
belle_sip_main_loop_quit(belle_sip_stack_get_main_loop(stack));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment