IAX2: refactor nativebridge transfer
authorAlec L Davis <sivad.a@paradise.net.nz>
Mon, 10 Jun 2013 08:30:31 +0000 (08:30 +0000)
committerAlec L Davis <sivad.a@paradise.net.nz>
Mon, 10 Jun 2013 08:30:31 +0000 (08:30 +0000)
remove triple checking of iaxs[fr->callno]->transferring

reduce indentation.

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

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

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

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

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

channels/chan_iax2.c

index 8fe51b4..ee215bb 100644 (file)
@@ -11224,57 +11224,65 @@ immediatedial:
                                        }
                                }
 
-                               if ((iaxs[fr->callno]->transferring == TRANSFER_BEGIN) ||
-                                   (iaxs[fr->callno]->transferring == TRANSFER_MBEGIN)) {
-                                       if (iaxs[fr->callno]->transferring == TRANSFER_MBEGIN)
-                                               iaxs[fr->callno]->transferring = TRANSFER_MREADY;
-                                       else
-                                               iaxs[fr->callno]->transferring = TRANSFER_READY;
-                                       ast_verb(3, "Channel '%s' ready to transfer\n", iaxs[fr->callno]->owner ? ast_channel_name(iaxs[fr->callno]->owner) : "<Unknown>");
+                               if (iaxs[fr->callno]->transferring == TRANSFER_BEGIN) {
+                                       iaxs[fr->callno]->transferring = TRANSFER_MREADY;
+                               } else if (iaxs[fr->callno]->transferring == TRANSFER_MBEGIN) {
+                                       iaxs[fr->callno]->transferring = TRANSFER_READY;
+                               } else {
                                        if (iaxs[fr->callno]->bridgecallno) {
-                                               if ((iaxs[iaxs[fr->callno]->bridgecallno]->transferring == TRANSFER_READY) ||
-                                                   (iaxs[iaxs[fr->callno]->bridgecallno]->transferring == TRANSFER_MREADY)) {
-                                                       /* They're both ready, now release them. */
-                                                       if (iaxs[fr->callno]->transferring == TRANSFER_MREADY) {
-                                                               ast_verb(3, "Attempting media bridge of %s and %s\n", iaxs[fr->callno]->owner ? ast_channel_name(iaxs[fr->callno]->owner) : "<Unknown>",
-                                                                               iaxs[iaxs[fr->callno]->bridgecallno]->owner ? ast_channel_name(iaxs[iaxs[fr->callno]->bridgecallno]->owner) : "<Unknown>");
+                                               ast_mutex_unlock(&iaxsl[iaxs[fr->callno]->bridgecallno]);
+                                       }
+                                       break;
+                               }
+                               ast_verb(3, "Channel '%s' ready to transfer\n", iaxs[fr->callno]->owner ? ast_channel_name(iaxs[fr->callno]->owner) : "<Unknown>");
 
-                                                               iaxs[iaxs[fr->callno]->bridgecallno]->transferring = TRANSFER_MEDIA;
-                                                               iaxs[fr->callno]->transferring = TRANSFER_MEDIA;
+                               if (!iaxs[fr->callno]->bridgecallno) {
+                                       break;
+                               }
 
-                                                               memset(&ied0, 0, sizeof(ied0));
-                                                               memset(&ied1, 0, sizeof(ied1));
-                                                               iax_ie_append_short(&ied0, IAX_IE_CALLNO, iaxs[iaxs[fr->callno]->bridgecallno]->peercallno);
-                                                               iax_ie_append_short(&ied1, IAX_IE_CALLNO, iaxs[fr->callno]->peercallno);
-                                                               send_command(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_TXMEDIA, 0, ied0.buf, ied0.pos, -1);
-                                                               send_command(iaxs[iaxs[fr->callno]->bridgecallno], AST_FRAME_IAX, IAX_COMMAND_TXMEDIA, 0, ied1.buf, ied1.pos, -1);
-                                                       } else {
-                                                               ast_verb(3, "Releasing %s and %s\n", iaxs[fr->callno]->owner ? ast_channel_name(iaxs[fr->callno]->owner) : "<Unknown>",
-                                                                               iaxs[iaxs[fr->callno]->bridgecallno]->owner ? ast_channel_name(iaxs[iaxs[fr->callno]->bridgecallno]->owner) : "<Unknown>");
+                               if (!(iaxs[iaxs[fr->callno]->bridgecallno]->transferring == TRANSFER_READY) &&
+                                   !(iaxs[iaxs[fr->callno]->bridgecallno]->transferring == TRANSFER_MREADY)) {
+                                       break;
+                               }
 
-                                                               iaxs[iaxs[fr->callno]->bridgecallno]->transferring = TRANSFER_RELEASED;
-                                                               iaxs[fr->callno]->transferring = TRANSFER_RELEASED;
-                                                               ast_set_flag64(iaxs[iaxs[fr->callno]->bridgecallno], IAX_ALREADYGONE);
-                                                               ast_set_flag64(iaxs[fr->callno], IAX_ALREADYGONE);
+                               /* Both sides are ready */
 
-                                                               /* Stop doing lag & ping requests */
-                                                               stop_stuff(fr->callno);
-                                                               stop_stuff(iaxs[fr->callno]->bridgecallno);
+                               /* XXX what isn't checked here is that both sides match transfer types. */
 
-                                                               memset(&ied0, 0, sizeof(ied0));
-                                                               memset(&ied1, 0, sizeof(ied1));
-                                                               iax_ie_append_short(&ied0, IAX_IE_CALLNO, iaxs[iaxs[fr->callno]->bridgecallno]->peercallno);
-                                                               iax_ie_append_short(&ied1, IAX_IE_CALLNO, iaxs[fr->callno]->peercallno);
-                                                               send_command(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_TXREL, 0, ied0.buf, ied0.pos, -1);
-                                                               send_command(iaxs[iaxs[fr->callno]->bridgecallno], AST_FRAME_IAX, IAX_COMMAND_TXREL, 0, ied1.buf, ied1.pos, -1);
-                                                       }
+                               if (iaxs[fr->callno]->transferring == TRANSFER_MREADY) {
+                                       ast_verb(3, "Attempting media bridge of %s and %s\n", iaxs[fr->callno]->owner ? ast_channel_name(iaxs[fr->callno]->owner) : "<Unknown>",
+                                                       iaxs[iaxs[fr->callno]->bridgecallno]->owner ? ast_channel_name(iaxs[iaxs[fr->callno]->bridgecallno]->owner) : "<Unknown>");
 
-                                               }
-                                       }
-                               }
-                               if (iaxs[fr->callno]->bridgecallno) {
-                                       ast_mutex_unlock(&iaxsl[iaxs[fr->callno]->bridgecallno]);
+                                       iaxs[iaxs[fr->callno]->bridgecallno]->transferring = TRANSFER_MEDIA;
+                                       iaxs[fr->callno]->transferring = TRANSFER_MEDIA;
+
+                                       memset(&ied0, 0, sizeof(ied0));
+                                       memset(&ied1, 0, sizeof(ied1));
+                                       iax_ie_append_short(&ied0, IAX_IE_CALLNO, iaxs[iaxs[fr->callno]->bridgecallno]->peercallno);
+                                       iax_ie_append_short(&ied1, IAX_IE_CALLNO, iaxs[fr->callno]->peercallno);
+                                       send_command(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_TXMEDIA, 0, ied0.buf, ied0.pos, -1);
+                                       send_command(iaxs[iaxs[fr->callno]->bridgecallno], AST_FRAME_IAX, IAX_COMMAND_TXMEDIA, 0, ied1.buf, ied1.pos, -1);
+                               } else {
+                                       ast_verb(3, "Releasing %s and %s\n", iaxs[fr->callno]->owner ? ast_channel_name(iaxs[fr->callno]->owner) : "<Unknown>",
+                                                       iaxs[iaxs[fr->callno]->bridgecallno]->owner ? ast_channel_name(iaxs[iaxs[fr->callno]->bridgecallno]->owner) : "<Unknown>");
+
+                                       iaxs[iaxs[fr->callno]->bridgecallno]->transferring = TRANSFER_RELEASED;
+                                       iaxs[fr->callno]->transferring = TRANSFER_RELEASED;
+                                       ast_set_flag64(iaxs[iaxs[fr->callno]->bridgecallno], IAX_ALREADYGONE);
+                                       ast_set_flag64(iaxs[fr->callno], IAX_ALREADYGONE);
+
+                                       /* Stop doing lag & ping requests */
+                                       stop_stuff(fr->callno);
+                                       stop_stuff(iaxs[fr->callno]->bridgecallno);
+
+                                       memset(&ied0, 0, sizeof(ied0));
+                                       memset(&ied1, 0, sizeof(ied1));
+                                       iax_ie_append_short(&ied0, IAX_IE_CALLNO, iaxs[iaxs[fr->callno]->bridgecallno]->peercallno);
+                                       iax_ie_append_short(&ied1, IAX_IE_CALLNO, iaxs[fr->callno]->peercallno);
+                                       send_command(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_TXREL, 0, ied0.buf, ied0.pos, -1);
+                                       send_command(iaxs[iaxs[fr->callno]->bridgecallno], AST_FRAME_IAX, IAX_COMMAND_TXREL, 0, ied1.buf, ied1.pos, -1);
                                }
+                               ast_mutex_unlock(&iaxsl[iaxs[fr->callno]->bridgecallno]);
                                break;
                        case IAX_COMMAND_TXREQ:
                                try_transfer(iaxs[fr->callno], &ies);