diff --git a/libs/freetdm/src/include/openzap.h b/libs/freetdm/src/include/openzap.h index 1b50a6d31b..a1fec59b89 100644 --- a/libs/freetdm/src/include/openzap.h +++ b/libs/freetdm/src/include/openzap.h @@ -263,7 +263,7 @@ #define zap_set_state_locked(obj, s) if ( obj->state == s ) { \ zap_log(ZAP_LOG_WARNING, "Why bother changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(obj->state), zap_channel_state2str(s)); \ } else if (zap_test_flag(obj, ZAP_CHANNEL_READY)) { \ - int st = obj->state; \ + zap_channel_state_t st = obj->state; \ zap_channel_set_state(obj, s, 1); \ if (obj->state == s) zap_log(ZAP_LOG_DEBUG, "Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ else zap_log(ZAP_LOG_WARNING, "VETO Changing state on %d:%d from %s to %s\n", obj->span_id, obj->chan_id, zap_channel_state2str(st), zap_channel_state2str(s)); \ @@ -770,10 +770,20 @@ ZIO_CODEC_FUNCTION(zio_alaw2ulaw); #endif /*! - \brief Allocate uninitialized memory - \command chunksize the chunk size + \brief Assert condition */ -#define zap_assert(assertion, retval, msg) \ +#define zap_assert(assertion, msg) \ + if (!(assertion)) { \ + zap_log(ZAP_LOG_CRIT, msg); \ + if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \ + abort(); \ + } \ + } + +/*! + \brief Assert condition and return +*/ +#define zap_assert_return(assertion, retval, msg) \ if (!(assertion)) { \ zap_log(ZAP_LOG_CRIT, msg); \ if (g_zap_crash_policy & ZAP_CRASH_ON_ASSERT) { \ diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c index 0522a627de..59b47c9100 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c @@ -382,7 +382,7 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) if (--boost_request_timeout <= 0) { status = ZAP_FAIL; *zchan = NULL; - zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response\n"); + zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_WAITING\n"); goto done; } } @@ -394,13 +394,14 @@ static ZIO_CHANNEL_REQUEST_FUNCTION(sangoma_boost_channel_request) zap_log(ZAP_LOG_DEBUG, "Channel state changed to PROGRESS [Csid:%d]\n", r); } - sanity = 5000; + boost_request_timeout = 5000; while(zap_running() && OUTBOUND_REQUESTS[r].status == BST_ACK) { zap_sleep(1); - if (--sanity <= 0) { - status = ZAP_FAIL; - *zchan = NULL; - goto done; + if (--boost_request_timeout <= 0) { + status = ZAP_FAIL; + *zchan = NULL; + zap_log(ZAP_LOG_CRIT, "Timed out waiting for boost channel request response, current status: BST_ACK\n"); + goto done; } //printf("WTF %d\n", sanity); } @@ -1654,7 +1655,7 @@ static BOOST_WRITE_MSG_FUNCTION(zap_boost_write_msg) zap_sangoma_boost_data_t *sangoma_boost_data = NULL; sangomabc_queue_element_t *element = NULL; - zap_assert(msg != NULL, ZAP_FAIL, "Boost message to write was null"); + zap_assert_return(msg != NULL, ZAP_FAIL, "Boost message to write was null"); if (!span) { shortmsg = msg; diff --git a/libs/freetdm/src/zap_io.c b/libs/freetdm/src/zap_io.c index b048d7a11b..7d6c0fbd6a 100644 --- a/libs/freetdm/src/zap_io.c +++ b/libs/freetdm/src/zap_io.c @@ -185,7 +185,7 @@ static __inline__ void *zap_std_malloc(void *pool, zap_size_t size) { void *ptr = malloc(size); pool = NULL; /* fix warning */ - zap_assert(ptr != NULL, NULL, "Out of memory"); + zap_assert_return(ptr != NULL, NULL, "Out of memory"); return ptr; } @@ -193,14 +193,14 @@ static __inline__ void *zap_std_calloc(void *pool, zap_size_t elements, zap_size { void *ptr = calloc(elements, size); pool = NULL; - zap_assert(ptr != NULL, NULL, "Out of memory"); + zap_assert_return(ptr != NULL, NULL, "Out of memory"); return ptr; } static __inline__ void zap_std_free(void *pool, void *ptr) { pool = NULL; - zap_assert(ptr != NULL, , "Attempted to free null pointer"); + zap_assert_return(ptr != NULL, , "Attempted to free null pointer"); free(ptr); } @@ -1263,8 +1263,8 @@ OZ_DECLARE(zap_status_t) zap_channel_outgoing_call(zap_channel_t *zchan) OZ_DECLARE(zap_status_t) zap_channel_get_sig_status(zap_channel_t *zchan, zap_channel_sig_status_t *sigstatus) { - zap_assert(zchan != NULL, ZAP_FAIL, "Null channel\n"); - zap_assert(sigstatus != NULL, ZAP_FAIL, "Null sig status"); + zap_assert_return(zchan != NULL, ZAP_FAIL, "Null channel\n"); + zap_assert_return(sigstatus != NULL, ZAP_FAIL, "Null sig status"); if (zchan->span->get_sig_status) { return zchan->span->get_sig_status(zchan, sigstatus); @@ -2814,10 +2814,10 @@ OZ_DECLARE(zap_status_t) zap_configure_span_signaling(const char *type, zap_span zap_module_t *mod = (zap_module_t *) hashtable_search(globals.module_hash, (void *)type); zap_status_t status = ZAP_FAIL; - zap_assert(type != NULL, ZAP_FAIL, "No signaling type"); - zap_assert(span != NULL, ZAP_FAIL, "No span"); - zap_assert(sig_cb != NULL, ZAP_FAIL, "No signaling callback"); - zap_assert(parameters != NULL, ZAP_FAIL, "No parameters"); + zap_assert_return(type != NULL, ZAP_FAIL, "No signaling type"); + zap_assert_return(span != NULL, ZAP_FAIL, "No span"); + zap_assert_return(sig_cb != NULL, ZAP_FAIL, "No signaling callback"); + zap_assert_return(parameters != NULL, ZAP_FAIL, "No parameters"); if (!mod) { zap_load_module_assume(type); diff --git a/libs/freetdm/src/zap_queue.c b/libs/freetdm/src/zap_queue.c index 7f40b036df..6a0a05d683 100644 --- a/libs/freetdm/src/zap_queue.c +++ b/libs/freetdm/src/zap_queue.c @@ -76,8 +76,8 @@ OZ_DECLARE(zap_status_t) zap_global_set_queue_handler(zap_queue_handler_t *handl static zap_status_t zap_std_queue_create(zap_queue_t **outqueue, zap_size_t capacity) { - zap_assert(outqueue, ZAP_FAIL, "Queue double pointer is null\n"); - zap_assert(capacity > 0, ZAP_FAIL, "Queue capacity is not bigger than 0\n"); + zap_assert_return(outqueue, ZAP_FAIL, "Queue double pointer is null\n"); + zap_assert_return(capacity > 0, ZAP_FAIL, "Queue capacity is not bigger than 0\n"); *outqueue = NULL; zap_queue_t *queue = zap_calloc(1, sizeof(*queue)); @@ -120,7 +120,7 @@ static zap_status_t zap_std_queue_enqueue(zap_queue_t *queue, void *obj) { zap_status_t status = ZAP_FAIL; - zap_assert(queue != NULL, ZAP_FAIL, "Queue is null!"); + zap_assert_return(queue != NULL, ZAP_FAIL, "Queue is null!"); zap_mutex_lock(queue->mutex); @@ -152,7 +152,7 @@ static void *zap_std_queue_dequeue(zap_queue_t *queue) { void *obj = NULL; - zap_assert(queue != NULL, NULL, "Queue is null!"); + zap_assert_return(queue != NULL, NULL, "Queue is null!"); zap_mutex_lock(queue->mutex); @@ -177,7 +177,7 @@ done: static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms) { zap_status_t ret; - zap_assert(queue != NULL, ZAP_FAIL, "Queue is null!"); + zap_assert_return(queue != NULL, ZAP_FAIL, "Queue is null!"); zap_mutex_lock(queue->mutex); @@ -199,8 +199,8 @@ static zap_status_t zap_std_queue_wait(zap_queue_t *queue, int ms) static zap_status_t zap_std_queue_destroy(zap_queue_t **inqueue) { zap_queue_t *queue = NULL; - zap_assert(inqueue != NULL, ZAP_FAIL, "Queue is null!"); - zap_assert(*inqueue != NULL, ZAP_FAIL, "Queue is null!"); + zap_assert_return(inqueue != NULL, ZAP_FAIL, "Queue is null!"); + zap_assert_return(*inqueue != NULL, ZAP_FAIL, "Queue is null!"); queue = *inqueue; zap_condition_destroy(&queue->condition); diff --git a/libs/freetdm/src/zap_threadmutex.c b/libs/freetdm/src/zap_threadmutex.c index 0661decfd7..3e894737c0 100644 --- a/libs/freetdm/src/zap_threadmutex.c +++ b/libs/freetdm/src/zap_threadmutex.c @@ -242,8 +242,8 @@ OZ_DECLARE(zap_status_t) zap_condition_create(zap_condition_t **incondition, zap { zap_condition_t *condition = NULL; - zap_assert(incondition != NULL, ZAP_FAIL, "Condition double pointer is null!\n"); - zap_assert(mutex != NULL, ZAP_FAIL, "Mutex for condition must not be null!\n"); + zap_assert_return(incondition != NULL, ZAP_FAIL, "Condition double pointer is null!\n"); + zap_assert_return(mutex != NULL, ZAP_FAIL, "Mutex for condition must not be null!\n"); condition = zap_calloc(1, sizeof(*condition)); if (!condition) { @@ -277,7 +277,7 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) #ifdef WIN32 DWORD res = 0; #endif - zap_assert(condition != NULL, ZAP_FAIL, "Condition is null!\n"); + zap_assert_return(condition != NULL, ZAP_FAIL, "Condition is null!\n"); #ifdef WIN32 res = WaitForSingleObject(condition->condition, ms > 0 ? ms : INFINITE); switch (res) { @@ -311,7 +311,7 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *condition) { - zap_assert(condition != NULL, ZAP_FAIL, "Condition is null!\n"); + zap_assert_return(condition != NULL, ZAP_FAIL, "Condition is null!\n"); #ifdef WIN32 if (!SetEvent(condition->condition)) { return ZAP_FAIL; @@ -329,7 +329,7 @@ OZ_DECLARE(zap_status_t) zap_condition_signal(zap_condition_t *condition) OZ_DECLARE(zap_status_t) zap_condition_destroy(zap_condition_t **incondition) { zap_condition_t *condition = NULL; - zap_assert(incondition != NULL, ZAP_FAIL, "Condition null when destroying!\n"); + zap_assert_return(incondition != NULL, ZAP_FAIL, "Condition null when destroying!\n"); condition = *incondition; #ifdef WIN32 CloseHandle(condition->condition);