[Asterisk-cvs] asterisk-addons/asterisk-ooh323c/ooh323c/src ooCmdChannel.c, NONE, 1.1 ooCmdChannel.h, NONE, 1.1

vphirke vphirke
Thu Oct 27 09:34:59 CDT 2005


Update of /usr/cvsroot/asterisk-addons/asterisk-ooh323c/ooh323c/src
In directory mongoose.digium.com:/tmp/cvs-serv24232

Added Files:
	ooCmdChannel.c ooCmdChannel.h 
Log Message:
Added

--- NEW FILE: ooCmdChannel.c ---
/*
 * Copyright (C) 2004-2005 by Objective Systems, Inc.
 *
 * This software is furnished under an open source license and may be 
 * used and copied only in accordance with the terms of this license. 
 * The text of the license may generally be found in the root 
 * directory of this installation in the COPYING file.  It 
 * can also be viewed online at the following URL:
 *
 *   http://www.obj-sys.com/open/license.html
 *
 * Any redistributions of this file including modified versions must 
 * maintain this copyright notice.
 *
 *****************************************************************************/

#include "ooStackCmds.h"
#include "ootrace.h"
#include "ooq931.h"
#include "ooh245.h"
#include "ooh323ep.h"
#include "oochannels.h"
#include "ooCalls.h"
#include "ooCmdChannel.h"

/** Global endpoint structure */
extern OOH323EndPoint gH323ep;

OOSOCKET gCmdChan = 0;
char gCmdIP[20];
int gCmdPort = OO_DEFAULT_CMDLISTENER_PORT;

int ooCreateCmdListener()
{
   int ret=0;
   OOIPADDR ipaddrs;

   OOTRACEINFO3("Creating CMD listener at %s:%d\n", 
                  gH323ep.signallingIP, gH323ep.cmdPort);
   if((ret=ooSocketCreate (&gH323ep.cmdListener))!=ASN_OK)
   {
      OOTRACEERR1("ERROR: Failed to create socket for CMD listener\n");
      return OO_FAILED;
   }
   ret= ooSocketStrToAddr (gH323ep.signallingIP, &ipaddrs);
   if((ret=ooSocketBind (gH323ep.cmdListener, ipaddrs, 
                         gH323ep.cmdPort))==ASN_OK) 
   {
      ooSocketListen(gH323ep.cmdListener,5); /*listen on socket*/
      OOTRACEINFO1("CMD listener creation - successful\n");
      return OO_OK;
   }
   else
   {
      OOTRACEERR1("ERROR:Failed to create CMD listener\n");
      return OO_FAILED;
   }

   return OO_OK;
}

int ooCreateCmdConnection()
{
   int ret=0;
   if((ret=ooSocketCreate (&gCmdChan))!=ASN_OK)
   {
      return OO_FAILED;
   }
   else
   {

     //TODO:Need to add support for multihomed to work with channel driver

      /*
         bind socket to a port before connecting. Thus avoiding
         implicit bind done by a connect call. Avoided on windows as 
         windows sockets have problem in reusing the addresses even after
         setting SO_REUSEADDR, hence in windows we just allow os to bind
         to any random port.
      */
#ifndef _WIN32
      ret = ooBindPort(OOTCP,gCmdChan, gCmdIP); 
#else
      ret = ooBindOSAllocatedPort(gCmdChan, gCmdIP);
#endif
      
      if(ret == OO_FAILED)
      {
         return OO_FAILED;
      }


      if((ret=ooSocketConnect(gCmdChan, gCmdIP,
                           gCmdPort)) != ASN_OK)
         return OO_FAILED;

   }
   return OO_OK;
}


int ooCloseCmdConnection()
{
   ooSocketClose(gH323ep.cmdSock);
   gH323ep.cmdSock = 0;

   return OO_OK;
}

int ooAcceptCmdConnection()    
{
   int ret;

   ret = ooSocketAccept (gH323ep.cmdListener, &gH323ep.cmdSock, 
                         NULL, NULL);
   if(ret != ASN_OK)
   {
      OOTRACEERR1("Error:Accepting CMD connection\n");
      return OO_FAILED;
   }
   OOTRACEINFO1("Cmd connection accepted\n");   
   return OO_OK;
}

int ooWriteStackCommand(OOStackCommand *cmd)
{
   if(ASN_OK != ooSocketSend(gCmdChan, (char*)cmd, sizeof(OOStackCommand)))
      return OO_FAILED;
   
   return OO_OK;
}


int ooReadAndProcessStackCommand()
{
   OOH323CallData *call = NULL;   
   unsigned char buffer[MAXMSGLEN];
   int i, recvLen = 0;
   OOStackCommand cmd;
   memset(&cmd, 0, sizeof(OOStackCommand));
   recvLen = ooSocketRecv (gH323ep.cmdSock, buffer, MAXMSGLEN);
   if(recvLen <= 0)
   {
      OOTRACEERR1("Error:Failed to read CMD message\n");
      return OO_FAILED;
   }

   for(i=0; (int)(i+sizeof(OOStackCommand)) <= recvLen; i += sizeof(OOStackCommand))
   {
      memcpy(&cmd, buffer+i, sizeof(OOStackCommand));

      if(cmd.type == OO_CMD_NOOP)
         continue;

      if(gH323ep.gkClient && gH323ep.gkClient->state != GkClientRegistered)
      {
         OOTRACEINFO1("Ignoring stack command as Gk Client is not registered"
                      " yet\n");
      }else {
         switch(cmd.type) {
            case OO_CMD_MAKECALL: 
               OOTRACEINFO2("Processing MakeCall command %s\n", 
                                    (char*)cmd.param2);
 
               ooH323MakeCall ((char*)cmd.param1, (char*)cmd.param2, 
                                                 (ooCallOptions*)cmd.param3);
               break;

            case OO_CMD_MANUALRINGBACK:
               if(OO_TESTFLAG(gH323ep.flags, OO_M_MANUALRINGBACK))
               {
                  ooSendAlerting(ooFindCallByToken((char*)cmd.param1));
                  if(OO_TESTFLAG(gH323ep.flags, OO_M_AUTOANSWER))
                     ooSendConnect(ooFindCallByToken((char*)cmd.param1));
               }
               break;
 
            case OO_CMD_ANSCALL:
               OOTRACEINFO2("Processing Answer Call command for %s\n",
                            (char*)cmd.param1);
               ooSendConnect(ooFindCallByToken((char*)cmd.param1));
               break;

            case OO_CMD_FWDCALL:
               OOTRACEINFO3("Forwarding call %s to %s\n", (char*)cmd.param1,
                                                          (char*)cmd.param2);
               ooH323ForwardCall((char*)cmd.param1, (char*)cmd.param2);
               break;

            case OO_CMD_HANGCALL: 
               OOTRACEINFO2("Processing Hang call command %s\n", 
                                   (char*)cmd.param1);
               ooH323HangCall((char*)cmd.param1, 
                                          *(OOCallClearReason*)cmd.param2);
               break;
          
            case OO_CMD_SENDDIGIT:
               call = ooFindCallByToken((char*)cmd.param1);
               if(!call)
               {
                  OOTRACEERR2("Error:Invalid calltoken %s\n", 
                                                         (char*)cmd.param1);
                  break;
               }
               if(call->jointDtmfMode & OO_CAP_DTMF_H245_alphanumeric)
                  ooSendH245UserInputIndication_alphanumeric(call, 
                                                      (const char*)cmd.param2);
               else if(call->jointDtmfMode & OO_CAP_DTMF_H245_signal)
                  ooSendH245UserInputIndication_signal(call, 
                                                  (const char*)cmd.param2);
               else
                  ooQ931SendDTMFAsKeyPadIE(call, (const char*)cmd.param2);

               break;

            case OO_CMD_STOPMONITOR: 
               OOTRACEINFO1("Processing StopMonitor command\n");
               ooStopMonitorCalls();
               break;

            default: OOTRACEERR1("ERROR:Unknown command\n");
         }
      }
      if(cmd.param1) free(cmd.param1);
      if(cmd.param2) free(cmd.param2);
      if(cmd.param3) free(cmd.param3);
   }


   return OO_OK;
}
   

--- NEW FILE: ooCmdChannel.h ---
/*
 * Copyright (C) 2004-2005 by Objective Systems, Inc.
 *
 * This software is furnished under an open source license and may be 
 * used and copied only in accordance with the terms of this license. 
 * The text of the license may generally be found in the root 
 * directory of this installation in the COPYING file.  It 
 * can also be viewed online at the following URL:
 *
 *   http://www.obj-sys.com/open/license.html
 *
 * Any redistributions of this file including modified versions must 
 * maintain this copyright notice.
 *
 *****************************************************************************/
/**
 * @file ooCmdChannel.h 
 * This file contains stack commands which an user application can use to make
 * call, hang call etc. 
 */

#ifndef OO_CMDCHANNEL_H
#define OO_CMDCHANNEL_H

#include "ootypes.h"
#include "ooStackCmds.h"
#ifdef __cplusplus
extern "C" {
#endif

#ifndef EXTERN
#if defined (MAKE_DLL)
#define EXTERN __declspec(dllexport)
#else
#define EXTERN
#endif /* MAKE_DLL */
#endif /* EXTERN */


#define OO_DEFAULT_CMDLISTENER_PORT 7575

/**
 * @addtogroup channels 
 * @{
 */

/**
 * This function creates a command listener. This is nothing but a tcp socket
 * in listen mode waiting for incoming connection on which the stack thread 
 * will receive commands.
 *
 * @return          OO_OK, on success; OO_FAILED, on failure
 */
EXTERN int ooCreateCmdListener();

/**
 * This function is used to accept an incoming connection request for command 
 * channel.
 * 
 * @return          OO_OK, on success; OO_FAILED, on failure
 */
EXTERN  int ooAcceptCmdConnection();

/**
 * This function is used to setup a command connection with the main stack 
 * thread. The application commands are sent over this connection to stack 
 * thread.
 *
 * @return          OO_OK, on success; OO_FAILED, on failure
 */
EXTERN int ooCreateCmdConnection();

/**
 * This function is used to close a command channel setup with the stack 
 * thread.
 *
 * @return          OO_OK, on success; OO_FAILED, on failure
 */
EXTERN int ooCloseCmdConnection();


/**
 * This function is used by stack api to write stack commands to command 
 * channel.
 *
 * @return          OO_OK, on success; OO_FAILED, on failure
 */
EXTERN int ooWriteStackCommand(OOStackCommand *cmd);

/**
 * This function is used by stack thread to read and process stack commands 
 * received over command channel.
 *
 * @return          OO_OK, on success; OO_FAILED, on failure
 */
EXTERN int ooReadAndProcessStackCommand();


/** 
 * @} 
 */

#ifdef __cplusplus
}
#endif

#endif




More information about the svn-commits mailing list