IAX2: Transfer Reject: Lock bridgecallno before touching it, refactor
authorAlec L Davis <sivad.a@paradise.net.nz>
Tue, 11 Jun 2013 08:13:39 +0000 (08:13 +0000)
committerAlec L Davis <sivad.a@paradise.net.nz>
Tue, 11 Jun 2013 08:13:39 +0000 (08:13 +0000)
1). When touching the bridgecallno, we need to lock it.

2). Remove magic number '0' and replace with TRANSFER_NONE.

3). Exit early if no bridgecallno.

4). Reduce indentation.

Reported by: alecdavis
Tested by: alecdavis
alecdavis (license 585)

Review https://reviewboard.asterisk.org/r/2613/
........

Merged revisions 391333 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 391334 from http://svn.asterisk.org/svn/asterisk/branches/11

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@391335 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c

index a428011..7c0de99 100644 (file)
@@ -11204,15 +11204,28 @@ immediatedial:
                                }
                                break;
                        case IAX_COMMAND_TXREJ:
-                               iaxs[fr->callno]->transferring = 0;
-                               ast_verb(3, "Channel '%s' unable to transfer\n", iaxs[fr->callno]->owner ? ast_channel_name(iaxs[fr->callno]->owner) : "<Unknown>");
-                               memset(&iaxs[fr->callno]->transfer, 0, sizeof(iaxs[fr->callno]->transfer));
                                if (iaxs[fr->callno]->bridgecallno) {
-                                       if (iaxs[iaxs[fr->callno]->bridgecallno]->transferring) {
-                                               iaxs[iaxs[fr->callno]->bridgecallno]->transferring = 0;
-                                               send_command(iaxs[iaxs[fr->callno]->bridgecallno], AST_FRAME_IAX, IAX_COMMAND_TXREJ, 0, NULL, 0, -1);
+                                       while (ast_mutex_trylock(&iaxsl[iaxs[fr->callno]->bridgecallno])) {
+                                               DEADLOCK_AVOIDANCE(&iaxsl[fr->callno]);
+                                       }
+                                       if (!iaxs[fr->callno]) {
+                                               break;
                                        }
                                }
+
+                               iaxs[fr->callno]->transferring = TRANSFER_NONE;
+                               ast_verb(3, "Channel '%s' unable to transfer\n", iaxs[fr->callno]->owner ? ast_channel_name(iaxs[fr->callno]->owner) : "<Unknown>");
+                               memset(&iaxs[fr->callno]->transfer, 0, sizeof(iaxs[fr->callno]->transfer));
+
+                               if (!iaxs[fr->callno]->bridgecallno) {
+                                       break;
+                               }
+
+                               if (iaxs[iaxs[fr->callno]->bridgecallno]->transferring) {
+                                       iaxs[iaxs[fr->callno]->bridgecallno]->transferring = TRANSFER_NONE;
+                                       send_command(iaxs[iaxs[fr->callno]->bridgecallno], AST_FRAME_IAX, IAX_COMMAND_TXREJ, 0, NULL, 0, -1);
+                               }
+                               ast_mutex_unlock(&iaxsl[iaxs[fr->callno]->bridgecallno]);
                                break;
                        case IAX_COMMAND_TXREADY:
                                if (iaxs[fr->callno]->bridgecallno) {