Commit ab0f6d5a authored by Simon Morlat's avatar Simon Morlat
Browse files

add checks to log formatting and fix detected problems in logs

parent 1e24c0f0
...@@ -40,6 +40,13 @@ typedef enum { ...@@ -40,6 +40,13 @@ typedef enum {
typedef void (*belle_sip_log_function_t)(belle_sip_log_level lev, const char *fmt, va_list args); typedef void (*belle_sip_log_function_t)(belle_sip_log_level lev, const char *fmt, va_list args);
#ifdef __GNUC__
#define BELLE_SIP_CHECK_FORMAT_ARGS(m,n) __attribute__((format(printf,m,n)))
#else
#define BELLE_SIP_CHECK_FORMAT_ARGS(m,n)
#endif
BELLE_SIP_BEGIN_DECLS BELLE_SIP_BEGIN_DECLS
extern belle_sip_log_function_t belle_sip_logv_out; extern belle_sip_log_function_t belle_sip_logv_out;
...@@ -82,14 +89,14 @@ static BELLESIP_INLINE void belle_sip_debug(const char *fmt,...) ...@@ -82,14 +89,14 @@ static BELLESIP_INLINE void belle_sip_debug(const char *fmt,...)
#else #else
static BELLESIP_INLINE void belle_sip_log(belle_sip_log_level lev, const char *fmt,...){ static BELLESIP_INLINE void BELLE_SIP_CHECK_FORMAT_ARGS(2,3) belle_sip_log(belle_sip_log_level lev, const char *fmt,...){
va_list args; va_list args;
va_start (args, fmt); va_start (args, fmt);
belle_sip_logv(lev, fmt, args); belle_sip_logv(lev, fmt, args);
va_end (args); va_end (args);
} }
static BELLESIP_INLINE void belle_sip_message(const char *fmt,...) static BELLESIP_INLINE void BELLE_SIP_CHECK_FORMAT_ARGS(1,2) belle_sip_message(const char *fmt,...)
{ {
va_list args; va_list args;
va_start (args, fmt); va_start (args, fmt);
...@@ -97,7 +104,7 @@ static BELLESIP_INLINE void belle_sip_message(const char *fmt,...) ...@@ -97,7 +104,7 @@ static BELLESIP_INLINE void belle_sip_message(const char *fmt,...)
va_end (args); va_end (args);
} }
static BELLESIP_INLINE void belle_sip_warning(const char *fmt,...) static BELLESIP_INLINE void BELLE_SIP_CHECK_FORMAT_ARGS(1,2) belle_sip_warning(const char *fmt,...)
{ {
va_list args; va_list args;
va_start (args, fmt); va_start (args, fmt);
...@@ -107,7 +114,7 @@ static BELLESIP_INLINE void belle_sip_warning(const char *fmt,...) ...@@ -107,7 +114,7 @@ static BELLESIP_INLINE void belle_sip_warning(const char *fmt,...)
#endif #endif
static BELLESIP_INLINE void belle_sip_error(const char *fmt,...) static BELLESIP_INLINE void BELLE_SIP_CHECK_FORMAT_ARGS(1,2) belle_sip_error(const char *fmt,...)
{ {
va_list args; va_list args;
va_start (args, fmt); va_start (args, fmt);
...@@ -115,7 +122,7 @@ static BELLESIP_INLINE void belle_sip_error(const char *fmt,...) ...@@ -115,7 +122,7 @@ static BELLESIP_INLINE void belle_sip_error(const char *fmt,...)
va_end (args); va_end (args);
} }
static BELLESIP_INLINE void belle_sip_fatal(const char *fmt,...) static BELLESIP_INLINE void BELLE_SIP_CHECK_FORMAT_ARGS(1,2) belle_sip_fatal(const char *fmt,...)
{ {
va_list args; va_list args;
va_start (args, fmt); va_start (args, fmt);
...@@ -128,7 +135,7 @@ static BELLESIP_INLINE void belle_sip_fatal(const char *fmt,...) ...@@ -128,7 +135,7 @@ static BELLESIP_INLINE void belle_sip_fatal(const char *fmt,...)
BELLESIP_EXPORT void belle_sip_set_log_file(FILE *file); BELLESIP_EXPORT void belle_sip_set_log_file(FILE *file);
BELLESIP_EXPORT void belle_sip_set_log_handler(belle_sip_log_function_t func); BELLESIP_EXPORT void belle_sip_set_log_handler(belle_sip_log_function_t func);
BELLESIP_EXPORT char *belle_sip_strdup_printf(const char *fmt,...); BELLESIP_EXPORT char * BELLE_SIP_CHECK_FORMAT_ARGS(1,2) belle_sip_strdup_printf(const char *fmt,...);
BELLESIP_EXPORT void belle_sip_set_log_level(int level); BELLESIP_EXPORT void belle_sip_set_log_level(int level);
......
...@@ -466,7 +466,7 @@ void belle_sip_object_pool_clean(belle_sip_object_pool_t *pool){ ...@@ -466,7 +466,7 @@ void belle_sip_object_pool_clean(belle_sip_object_pool_t *pool){
belle_sip_list_t *elem,*next; belle_sip_list_t *elem,*next;
if (!belle_sip_object_pool_cleanable(pool)){ if (!belle_sip_object_pool_cleanable(pool)){
belle_sip_warning("Thread pool [%p] cannot be cleaned from thread [%ul] because it was created for thread [%ul]", belle_sip_warning("Thread pool [%p] cannot be cleaned from thread [%lu] because it was created for thread [%lu]",
pool,(unsigned long)belle_sip_thread_self(),(unsigned long)pool->thread_id); pool,(unsigned long)belle_sip_thread_self(),(unsigned long)pool->thread_id);
return; return;
} }
...@@ -502,7 +502,7 @@ static void cleanup_pool_stack(void *data){ ...@@ -502,7 +502,7 @@ static void cleanup_pool_stack(void *data){
* Instead, we mark them as detached, so that when the thread that will attempt to destroy them will do it, * Instead, we mark them as detached, so that when the thread that will attempt to destroy them will do it,
* we'll accept (since anyway these object pool are no longer needed. * we'll accept (since anyway these object pool are no longer needed.
*/ */
belle_sip_warning("There were still [%i] object pools for thread [%u] while the thread exited. ", belle_sip_warning("There were still [%i] object pools for thread [%lu] while the thread exited. ",
belle_sip_list_size(*pool_stack),(unsigned long)belle_sip_thread_self()); belle_sip_list_size(*pool_stack),(unsigned long)belle_sip_thread_self());
belle_sip_list_free_with_data(*pool_stack,(void (*)(void*)) belle_sip_object_pool_detach_from_thread); belle_sip_list_free_with_data(*pool_stack,(void (*)(void*)) belle_sip_object_pool_detach_from_thread);
} }
...@@ -573,7 +573,7 @@ belle_sip_object_pool_t *belle_sip_object_pool_get_current(void){ ...@@ -573,7 +573,7 @@ belle_sip_object_pool_t *belle_sip_object_pool_get_current(void){
if (pools==NULL) return NULL; if (pools==NULL) return NULL;
if (*pools==NULL ){ if (*pools==NULL ){
if (first_time) { if (first_time) {
belle_sip_warning("There is no object pool created in thread [%ul]. " belle_sip_warning("There is no object pool created in thread [%lu]. "
"Use belle_sip_object_pool_push() to create one. Unowned objects not unref'd will be leaked.", "Use belle_sip_object_pool_push() to create one. Unowned objects not unref'd will be leaked.",
(unsigned long)belle_sip_thread_self()); (unsigned long)belle_sip_thread_self());
} }
......
...@@ -89,7 +89,7 @@ static struct dns_hosts *hosts(belle_sip_resolver_context_t *ctx) { ...@@ -89,7 +89,7 @@ static struct dns_hosts *hosts(belle_sip_resolver_context_t *ctx) {
if (ctx->stack->dns_user_hosts_file) { if (ctx->stack->dns_user_hosts_file) {
error = dns_hosts_loadpath(ctx->hosts, ctx->stack->dns_user_hosts_file); error = dns_hosts_loadpath(ctx->hosts, ctx->stack->dns_user_hosts_file);
if (error) { if (error) {
belle_sip_error("%s dns_hosts_loadfile(\"%s\"): %s for %s", __FUNCTION__, dns_strerror(error),ctx->stack->dns_user_hosts_file); belle_sip_error("%s dns_hosts_loadfile(\"%s\"): %s", __FUNCTION__,ctx->stack->dns_user_hosts_file,dns_strerror(error));
} }
} }
......
...@@ -185,7 +185,7 @@ static void belle_sip_channel_parse_stream(belle_sip_channel_t *obj){ ...@@ -185,7 +185,7 @@ static void belle_sip_channel_parse_stream(belle_sip_channel_t *obj){
,&read_size); ,&read_size);
obj->input_stream.read_ptr+=read_size; obj->input_stream.read_ptr+=read_size;
if (obj->input_stream.msg && read_size > 0){ if (obj->input_stream.msg && read_size > 0){
belle_sip_message("channel [%p] [%i] bytes parsed",obj,read_size); belle_sip_message("channel [%p] [%i] bytes parsed",obj,(int)read_size);
belle_sip_object_ref(obj->input_stream.msg); belle_sip_object_ref(obj->input_stream.msg);
if (belle_sip_message_is_request(obj->input_stream.msg)) fix_incoming_via(BELLE_SIP_REQUEST(obj->input_stream.msg),obj->current_peer); if (belle_sip_message_is_request(obj->input_stream.msg)) fix_incoming_via(BELLE_SIP_REQUEST(obj->input_stream.msg),obj->current_peer);
/*check for body*/ /*check for body*/
......
...@@ -436,7 +436,7 @@ belle_sip_dialog_t *belle_sip_dialog_new(belle_sip_transaction_t *t){ ...@@ -436,7 +436,7 @@ belle_sip_dialog_t *belle_sip_dialog_new(belle_sip_transaction_t *t){
obj->route_set=belle_sip_list_append(obj->route_set,belle_sip_object_ref(predefined_routes->data)); obj->route_set=belle_sip_list_append(obj->route_set,belle_sip_object_ref(predefined_routes->data));
} }
} }
belle_sip_message("New %s dialog [%x] , local tag [%s], remote tag [%s]" belle_sip_message("New %s dialog [%p] , local tag [%s], remote tag [%s]"
,obj->is_server?"server":"client" ,obj->is_server?"server":"client"
,obj ,obj
,obj->local_tag ,obj->local_tag
......
...@@ -147,7 +147,7 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even ...@@ -147,7 +147,7 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even
belle_sip_message_remove_header(BELLE_SIP_MESSAGE(request),"SIP-If-Match"); belle_sip_message_remove_header(BELLE_SIP_MESSAGE(request),"SIP-If-Match");
belle_sip_message_add_header(BELLE_SIP_MESSAGE(request),sip_if_match); belle_sip_message_add_header(BELLE_SIP_MESSAGE(request),sip_if_match);
} else { } else {
belle_sip_warning("Refresher [%p] receive 200ok to a publish without etag"); belle_sip_warning("Refresher [%p] receive 200ok to a publish without etag",refresher);
} }
} }
/*update expire if needed*/ /*update expire if needed*/
...@@ -156,7 +156,7 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even ...@@ -156,7 +156,7 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even
belle_sip_refresher_stop(refresher); /*doesn not make sens to refresh if expire =0;*/ belle_sip_refresher_stop(refresher); /*doesn not make sens to refresh if expire =0;*/
} }
if (refresher->state==started) schedule_timer(refresher); /*re-arm timer*/ if (refresher->state==started) schedule_timer(refresher); /*re-arm timer*/
else belle_sip_message("Refresher [%p] not scheduling next refresh, because it was stopped"); else belle_sip_message("Refresher [%p] not scheduling next refresh, because it was stopped",refresher);
break; break;
case 401: case 401:
case 407: case 407:
......
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