Change order of sending TCS and MSD packets
[asterisk/asterisk.git] / addons / ooh323c / src / oochannels.c
index fd6cbb3..7fa8509 100644 (file)
@@ -13,8 +13,9 @@
  * maintain this copyright notice.
  *
  *****************************************************************************/
  * maintain this copyright notice.
  *
  *****************************************************************************/
-#include <asterisk.h>
-#include <asterisk/lock.h>
+#include "asterisk.h"
+#include "asterisk/lock.h"
+#include "asterisk/poll-compat.h"
 
 #include "ooports.h" 
 #include "oochannels.h"
 
 #include "ooports.h" 
 #include "oochannels.h"
@@ -134,7 +135,7 @@ int ooCreateH245Connection(OOH323CallData *call)
          call->pH245Channel->sock = channelSocket;
          call->h245SessionState = OO_H245SESSION_ACTIVE;
 
          call->pH245Channel->sock = channelSocket;
          call->h245SessionState = OO_H245SESSION_ACTIVE;
 
-         OOTRACEINFO3("H245 connection creation succesful (%s, %s)\n",
+         OOTRACEINFO3("H245 connection creation successful (%s, %s)\n",
                       call->callType, call->callToken);
 
          /*Start terminal capability exchange and master slave determination */
                       call->callType, call->callToken);
 
          /*Start terminal capability exchange and master slave determination */
@@ -145,13 +146,6 @@ int ooCreateH245Connection(OOH323CallData *call)
                          call->callType, call->callToken);
             return ret;
          }
                          call->callType, call->callToken);
             return ret;
          }
-         ret = ooSendMasterSlaveDetermination(call);
-         if(ret != OO_OK)
-         {
-            OOTRACEERR3("ERROR:Sending Master-slave determination message "
-                        "(%s, %s)\n", call->callType, call->callToken);
-            return ret;
-         }
       }
       else
       {
       }
       else
       {
@@ -300,7 +294,7 @@ int ooCreateH225Connection(OOH323CallData *call)
       {
          call->pH225Channel->sock = channelSocket;
 
       {
          call->pH225Channel->sock = channelSocket;
 
-         OOTRACEINFO3("H2250 transmiter channel creation - succesful "
+         OOTRACEINFO3("H2250 transmiter channel creation - successful "
                       "(%s, %s)\n", call->callType, call->callToken);
 
          /* If multihomed, get ip from socket */
                       "(%s, %s)\n", call->callType, call->callToken);
 
          /* If multihomed, get ip from socket */
@@ -488,13 +482,6 @@ int ooAcceptH245Connection(OOH323CallData *call)
                    call->callType, call->callToken);
       return ret;
    }
                    call->callType, call->callToken);
       return ret;
    }
-   ret = ooSendMasterSlaveDetermination(call);
-   if(ret != OO_OK)
-   {
-      OOTRACEERR3("ERROR:Sending Master-slave determination message "
-                  "(%s, %s)\n", call->callType, call->callToken);
-      return ret;
-   }   
    return OO_OK;
 }
 
    return OO_OK;
 }
 
@@ -748,8 +735,9 @@ int ooProcessCallFDSETsAndTimers
            ast_mutex_lock(&call->Lock);
             ooEndCall(call);
            ast_mutex_unlock(&call->Lock);
            ast_mutex_lock(&call->Lock);
             ooEndCall(call);
            ast_mutex_unlock(&call->Lock);
-           ooStopMonitorCallChannels(call);
      }
      }
+     if(call->callState >= OO_CALL_CLEARED)
+               ooStopMonitorCallChannels(call);
    }
 
    return OO_OK;
    }
 
    return OO_OK;
@@ -980,7 +968,7 @@ int ooH2250Receive(OOH323CallData *call)
    ASN1OCTET message[MAXMSGLEN], message1[MAXMSGLEN];
    int len;
    Q931Message *pmsg;
    ASN1OCTET message[MAXMSGLEN], message1[MAXMSGLEN];
    int len;
    Q931Message *pmsg;
-   OOCTXT *pctxt = call->pctxt;
+   OOCTXT *pctxt = call->msgctxt;
    
    struct timeval timeout;
 
    
    struct timeval timeout;
 
@@ -1114,6 +1102,7 @@ int ooH2250Receive(OOH323CallData *call)
 
    initializePrintHandler(&printHandler, "Received H.2250 Message");
    setEventHandler (pctxt, &printHandler);
 
    initializePrintHandler(&printHandler, "Received H.2250 Message");
    setEventHandler (pctxt, &printHandler);
+   setPERBuffer (pctxt, message, len, TRUE);
    ret = ooQ931Decode (call, pmsg, len, message, 1);
    if(ret != OO_OK) {
       OOTRACEERR3("Error:Failed to decode received H.2250 message. (%s, %s)\n",
    ret = ooQ931Decode (call, pmsg, len, message, 1);
    if(ret != OO_OK) {
       OOTRACEERR3("Error:Failed to decode received H.2250 message. (%s, %s)\n",
@@ -1124,7 +1113,7 @@ int ooH2250Receive(OOH323CallData *call)
    finishPrint();
    removeEventHandler(pctxt);
    if(ret == OO_OK) {
    finishPrint();
    removeEventHandler(pctxt);
    if(ret == OO_OK) {
-      ooHandleH2250Message(call, pmsg);
+      ret = ooHandleH2250Message(call, pmsg);
    }
    return ret;
 }
    }
    return ret;
 }
@@ -1979,22 +1968,12 @@ int ooStopMonitorCalls()
 
 OOBOOL ooChannelsIsConnectionOK(OOH323CallData *call, OOSOCKET sock)
 {
 
 OOBOOL ooChannelsIsConnectionOK(OOH323CallData *call, OOSOCKET sock)
 {
-   struct timeval to;
-   fd_set readfds;
-   int ret = 0, nfds=0; 
-
-   to.tv_sec = 0;
-   to.tv_usec = 500;
-   FD_ZERO(&readfds);
+   struct timeval to = { .tv_usec = 500 };
+   struct pollfd pfds = { .fd = sock, .events = POLLIN };
+   int ret = 0;
 
 
-   FD_SET(sock, &readfds);
-   if(nfds < (int)sock)
-      nfds = (int)sock;
+   ret = ast_poll2(&pfds, 1, &to);
 
 
-   nfds++;
-
-   ret = ooSocketSelect(nfds, &readfds, NULL, NULL, &to);
-      
    if(ret == -1)
    {
       OOTRACEERR3("Error in select ...broken pipe check(%s, %s)\n",
    if(ret == -1)
    {
       OOTRACEERR3("Error in select ...broken pipe check(%s, %s)\n",
@@ -2002,9 +1981,8 @@ OOBOOL ooChannelsIsConnectionOK(OOH323CallData *call, OOSOCKET sock)
       return FALSE;
    }
 
       return FALSE;
    }
 
-   if(FD_ISSET(sock, &readfds))
-   {
-      char buf[2];      
+   if (pfds.events & POLLIN) {
+      char buf[2];
       if(ooSocketRecvPeek(sock, (ASN1OCTET*) buf, 2) == 0)
       {
          OOTRACEWARN3("Broken pipe detected. (%s, %s)", call->callType, 
       if(ooSocketRecvPeek(sock, (ASN1OCTET*) buf, 2) == 0)
       {
          OOTRACEWARN3("Broken pipe detected. (%s, %s)", call->callType,