]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix improper usage of scheduler exposed by 5c713fdf18f 85/1385/1
authorMatt Jordan <mjordan@digium.com>
Tue, 6 Oct 2015 02:34:41 +0000 (21:34 -0500)
committerMatt Jordan <mjordan@digium.com>
Tue, 6 Oct 2015 12:41:48 +0000 (07:41 -0500)
When 5c713fdf18f was merged, it allowed for scheduled items to have an ID of
'0' returned. While this was valid per the documentation for the API, it was
apparently never returned previously. As a result, several users of the
scheduler API viewed the result as being invalid, causing them to reschedule
already scheduled items or otherwise fail in interesting ways.

This patch corrects the users such that they view '0' as valid, and a returned
ID of -1 as being invalid.

Note that the failing HEP RTCP tests now pass with this patch. These tests
failed due to a duplicate scheduling of the RTCP transmissions.

ASTERISK-25449 #close

Change-Id: I019a9aa8b6997584f66876331675981ac9e07e39

channels/chan_sip.c
channels/chan_skinny.c
res/res_rtp_asterisk.c

index ed249c68fda871479608ebedb1bab5d8d23b0428..53070cdbe47a12421993c7f130468adef2befa4f 100644 (file)
@@ -4341,7 +4341,7 @@ void sip_scheddestroy(struct sip_pvt *p, int ms)
        }
        p->autokillid = ast_sched_add(sched, ms, __sip_autodestruct, dialog_ref(p, "setting ref as passing into ast_sched_add for __sip_autodestruct"));
 
-       if (p->stimer && p->stimer->st_active == TRUE && p->stimer->st_schedid > 0) {
+       if (p->stimer && p->stimer->st_active == TRUE && p->stimer->st_schedid > -1) {
                stop_session_timer(p);
        }
 }
@@ -22290,7 +22290,7 @@ static void check_pendings(struct sip_pvt *p)
                sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
        } else if (ast_test_flag(&p->flags[0], SIP_NEEDREINVITE)) {
                /* if we can't REINVITE, hold it for later */
-               if (p->pendinginvite || p->invitestate == INV_CALLING || p->invitestate == INV_PROCEEDING || p->invitestate == INV_EARLY_MEDIA || p->waitid > 0) {
+               if (p->pendinginvite || p->invitestate == INV_CALLING || p->invitestate == INV_PROCEEDING || p->invitestate == INV_EARLY_MEDIA || p->waitid > -1) {
                        ast_debug(2, "NOT Sending pending reinvite (yet) on '%s'\n", p->callid);
                } else {
                        ast_debug(2, "Sending pending reinvite on '%s'\n", p->callid);
index 874eedd972db69fda1e1603995204c78a4af9de5..c64d8de505f3ea642e876fd60e6ff9e4008b9d23 100644 (file)
@@ -4327,7 +4327,7 @@ static int skinny_dialer_cb(const void *data)
 {
        struct skinny_subchannel *sub = (struct skinny_subchannel *)data;
        SKINNY_DEBUG(DEBUG_SUB, 3, "Sub %d - Dialer called from SCHED %d\n", sub->callid, sub->dialer_sched);
-       sub->dialer_sched = 0;
+       sub->dialer_sched = -1;
        skinny_dialer(sub, 1);
        return 0;
 }
@@ -4335,7 +4335,7 @@ static int skinny_dialer_cb(const void *data)
 static int skinny_autoanswer_cb(const void *data)
 {
        struct skinny_subchannel *sub = (struct skinny_subchannel *)data;
-       sub->aa_sched = 0;
+       sub->aa_sched = -1;
        setsubstate(sub, SKINNY_CONNECTED);
        return 0;
 }
@@ -4374,7 +4374,7 @@ static int skinny_call(struct ast_channel *ast, const char *dest, int timeout)
 
        AST_LIST_TRAVERSE(ast_channel_varshead(ast), current, entries) {
                if (!(strcasecmp(ast_var_name(current),"SKINNY_AUTOANSWER"))) {
-                       if (d->hookstate == SKINNY_ONHOOK && !sub->aa_sched) {
+                       if (d->hookstate == SKINNY_ONHOOK && !sub->aa_sched < 0) {
                                char buf[24];
                                int aatime;
                                char *stringp = buf, *curstr;
@@ -4836,8 +4836,8 @@ static struct ast_channel *skinny_new(struct skinny_line *l, struct skinny_subli
                        sub->xferor = 0;
                        sub->related = NULL;
                        sub->calldirection = direction;
-                       sub->aa_sched = 0;
-                       sub->dialer_sched = 0;
+                       sub->aa_sched = -1;
+                       sub->dialer_sched = -1;
 
                        if (subline) {
                                sub->subline = subline;
@@ -4978,12 +4978,12 @@ static void setsubstate(struct skinny_subchannel *sub, int state)
 
        if (sub->dialer_sched) {
                skinny_sched_del(sub->dialer_sched, sub);
-               sub->dialer_sched = 0;
+               sub->dialer_sched = -1;
        }
 
        if (state != SUBSTATE_RINGIN && sub->aa_sched) {
                skinny_sched_del(sub->aa_sched, sub);
-               sub->aa_sched = 0;
+               sub->aa_sched = -1;
                sub->aa_beep = 0;
                sub->aa_mute = 0;
        }
@@ -5637,7 +5637,7 @@ static int handle_keypad_button_message(struct skinny_req *req, struct skinnyses
        if ((sub->owner && ast_channel_state(sub->owner) <  AST_STATE_UP)) {
                if (sub->dialer_sched &&        !skinny_sched_del(sub->dialer_sched, sub)) {
                        SKINNY_DEBUG(DEBUG_SUB, 3, "Sub %d - Got a digit and not timed out, so try dialing\n", sub->callid);
-                       sub->dialer_sched = 0;
+                       sub->dialer_sched = -1;
                        len = strlen(sub->exten);
                        if (len == 0) {
                                transmit_stop_tone(d, l->instance, sub->callid);
@@ -6521,7 +6521,7 @@ static int handle_soft_key_event_message(struct skinny_req *req, struct skinnyse
                        d->name, instance, callreference);
                if (sub->dialer_sched && !skinny_sched_del(sub->dialer_sched, sub)) {
                        size_t len;
-                       sub->dialer_sched = 0;
+                       sub->dialer_sched = -1;
                        len = strlen(sub->exten);
                        if (len > 0) {
                                sub->exten[len-1] = '\0';
index 97e68c939a42dc7e9e682ed0c38ba4e9f483ff51..528b3986ca3545a3474a9ea873ff14d70f63eef8 100644 (file)
@@ -2910,7 +2910,7 @@ static int ast_rtp_raw_write(struct ast_rtp_instance *instance, struct ast_frame
                        rtp->txcount++;
                        rtp->txoctetcount += (res - hdrlen);
 
-                       if (rtp->rtcp && rtp->rtcp->schedid < 1) {
+                       if (rtp->rtcp && rtp->rtcp->schedid < 0) {
                                ast_debug(1, "Starting RTCP transmission on RTP instance '%p'\n", instance);
                                ao2_ref(instance, +1);
                                rtp->rtcp->schedid = ast_sched_add(rtp->sched, ast_rtcp_calc_interval(rtp), ast_rtcp_write, instance);
@@ -4037,7 +4037,7 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc
        }
 
        /* Do not schedule RR if RTCP isn't run */
-       if (rtp->rtcp && !ast_sockaddr_isnull(&rtp->rtcp->them) && rtp->rtcp->schedid < 1) {
+       if (rtp->rtcp && !ast_sockaddr_isnull(&rtp->rtcp->them) && rtp->rtcp->schedid < 0) {
                /* Schedule transmission of Receiver Report */
                ao2_ref(instance, +1);
                rtp->rtcp->schedid = ast_sched_add(rtp->sched, ast_rtcp_calc_interval(rtp), ast_rtcp_write, instance);