From b43317595030ed5f96a60c356fa15eb07d675272 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Fri, 18 Dec 2009 20:53:17 +0000 Subject: [PATCH] Fix for segfault on zap_queue wrap-around git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@942 a93c3328-9c30-0410-af19-c9cd2b2d52af --- .../ozmod_sangoma_boost/ozmod_sangoma_boost.c | 15 +++++++-------- .../ozmod_sangoma_boost/sangoma_boost_client.c | 18 +++++++++--------- .../src/ozmod/ozmod_sangoma_boost/sigboost.h | 2 +- libs/freetdm/src/zap_queue.c | 2 +- 4 files changed, 18 insertions(+), 19 deletions(-) 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 66cc64009a..5412738bb8 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 @@ -33,7 +33,7 @@ * Contributors: * * Moises Silva - * David Yatzin + * David Yat Sin * Nenad Corbic * */ @@ -711,8 +711,8 @@ static void handle_call_stop(zap_span_t *span, sangomabc_connection_t *mcon, san * itself through local initiated hangup */ sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); @@ -1036,8 +1036,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG); sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0); @@ -1058,8 +1058,8 @@ static __inline__ void state_advance(zap_channel_t *zchan) if (!zap_test_sflag(zchan, SFLAG_SENT_ACK)) { zap_set_sflag(zchan, SFLAG_SENT_ACK); sangomabc_exec_command(mcon, - zchan->physical_span_id-1, - zchan->physical_chan_id-1, + BOOST_SPAN(zchan), + BOOST_CHAN(zchan), 0, SIGBOOST_EVENT_CALL_START_ACK, 0); @@ -1716,7 +1716,6 @@ static BOOST_WRITE_MSG_FUNCTION(zap_boost_write_msg) zap_log(ZAP_LOG_ERROR, "Unexpected boost message %d\n", shortmsg->event_id); return ZAP_FAIL; } - /* duplicate the event and enqueue it */ element = zap_calloc(1, sizeof(*element)); if (!element) { diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c index 1ba67c9834..0af4664ee7 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sangoma_boost_client.c @@ -76,12 +76,13 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "%s EVENT: %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s] Rdnis=[%s]\n", - dir ? "TX":"RX", + zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "%s EVENT (%s): %s:(%X) [w%dg%d] CSid=%i Seq=%i Cn=[%s] Cd=[%s] Ci=[%s] Rdnis=[%s]\n", + dir ? "TX":"RX", + priority ? "P":"N", sangomabc_event_id_name(event->event_id), event->event_id, - event->span+1, - event->chan+1, + event->span, + event->chan, event->call_setup_id, event->fseqno, strlen(event->calling_name)?event->calling_name:"N/A", @@ -94,9 +95,9 @@ static void sangomabc_print_event_short(sangomabc_connection_t *mcon, sangomabc_ { if (event->event_id == SIGBOOST_EVENT_HEARTBEAT) return; - zap_log(file, func, line, ZAP_LOG_LEVEL_DEBUG, "%s EVENT (%s): %s:(%X) [s%dc%d] Rc=%i CSid=%i Seq=%i \n", + zap_log(file, func, line, ZAP_LOG_LEVEL_WARNING, "%s EVENT (%s): %s:(%X) [s%dc%d] Rc=%i CSid=%i Seq=%i \n", dir ? "TX":"RX", - priority ? "P":"N", + priority ? "P":"N", sangomabc_event_id_name(event->event_id), event->event_id, event->span, @@ -322,8 +323,7 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int msg_ok=0; } - if (msg_ok){ - + if (msg_ok) { if (sangomabc_test_flag(mcon, MSU_FLAG_DOWN)) { if (mcon->event.event_id != SIGBOOST_EVENT_SYSTEM_RESTART && mcon->event.event_id != SIGBOOST_EVENT_SYSTEM_RESTART_ACK && @@ -333,7 +333,7 @@ sangomabc_event_t *__sangomabc_connection_read(sangomabc_connection_t *mcon, int return NULL; } } - + if (boost_full_event(mcon->event.event_id)) { sangomabc_print_event_call(mcon, &mcon->event, 0, 0, file, func, line); } else { diff --git a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h index 47849c2c72..9e97e9014d 100644 --- a/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h +++ b/libs/freetdm/src/ozmod/ozmod_sangoma_boost/sigboost.h @@ -147,7 +147,7 @@ static __inline__ int boost_full_event(int event_id) switch (event_id) { case SIGBOOST_EVENT_CALL_START: case SIGBOOST_EVENT_DIGIT_IN: - case SIGBOOST_EVENT_CALL_PROGRESS: + case SIGBOOST_EVENT_CALL_PROGRESS: return 1; default: break; diff --git a/libs/freetdm/src/zap_queue.c b/libs/freetdm/src/zap_queue.c index 969e170783..a714af340c 100644 --- a/libs/freetdm/src/zap_queue.c +++ b/libs/freetdm/src/zap_queue.c @@ -163,7 +163,7 @@ static void *zap_std_queue_dequeue(zap_queue_t *queue) obj = queue->elements[queue->rindex]; queue->elements[queue->rindex++] = NULL; queue->size--; - if (queue->rindex == queue->size) { + if (queue->rindex == queue->capacity) { queue->rindex = 0; }