Hi

I just dowloaded the latest version last night although i've been subscribed for quite a while.

Play around with it for a while and I noticed that the alerting message is automatically generated by the stack when call is received.

I think to some manual alerting is important especially  telco appliance like asterisk since it needs to correctly indicates whether the end point has been alerted to provide call supervisioning.

Anyhow, I tried to implement it as the following, feel free to integrated with the sourcecode for the next version or just throw it away :-)

First. I need a flag for this, I use the endpoint flag:
ooCalls.h:
#define OO_M_MANUALRING 0x10000000

Now I need the API to set the flag:
ooh323ep.c/h:
int ooH323EpEnableManualRingback(void)
{
   OO_SETFLAG(gH323ep.flags, OO_M_MANUALRING);
   return OO_OK;
}

int ooH323EpDisableManualRingback(void)
{
   OO_CLRFLAG( gH323ep.flags, OO_M_MANUALRING);
   return OO_OK;
}

------

EXTERN int ooH323EpEnableManualRingback(void);
EXTERN int ooH323EpDisableManualRingback(void);


now I need to prevent the stack to do the automatic alerting:
ooq931.c[1865]
else { /* An incoming call */
      if(gH323ep.h323Callbacks.onIncomingCall)
         gH323ep.h323Callbacks.onIncomingCall(call);
     
      if (!OO_TESTFLAG(gH323ep.flags, OO_M_MANUALRING)) // <-- Benni
        ooSendAlerting(call); /* Send alerting message */

      if(OO_TESTFLAG(gH323ep.flags, OO_M_AUTOANSWER))
         ooSendConnect(call); /* Send connect message - call accepted */
   }

Ok, now that I'm set to prevent that for happening, I need to allow the user to generate ringback/alerting using API:

First I need to define the command:
ooStackCmds.h:
typedef enum OOStackCmdID {
   ....
   , OO_CMD_MANUALRING
}

Give the user API to send the command:
ooStackCmds.h:
EXTERN int ooManualRingback(char *callToken, int media);

ooStackCmds.c:
int ooManualRingback(char *callToken, int media)
{
    OOStackCommand *cmd;
   
   if(!callToken)
   {
      OOTRACEERR1("ERROR: Invalid callToken passed to ooHangCall\n");
      return OO_FAILED;
   }

#ifdef _WIN32
   EnterCriticalSection(&gCmdMutex);
#else
   pthread_mutex_lock(&gCmdMutex);
#endif
 
   cmd = (OOStackCommand*)memAlloc(&gH323ep.ctxt, sizeof(OOStackCommand));
   if(!cmd)
   {
      OOTRACEERR1("Error:Allocating memory for command structure - HangCall\n");
      return OO_FAILED;
   }

   memset(cmd, 0, sizeof(OOStackCommand));
   cmd->type = OO_CMD_MANUALRING;
   cmd->param1 = (void*) memAlloc(&gH323ep.ctxt, strlen(callToken)+1);
   cmd->param2 = (void*)memAlloc(&gH323ep.ctxt, sizeof(int));
   if(!cmd->param1 || !cmd->param2)
   {
      OOTRACEERR1("ERROR:Allocating memory for cmd param1/param2- HangCall\n");
      return OO_FAILED;
   }
   strcpy((char*)cmd->param1, callToken);
   *((int*)cmd->param2) = media;
  
   dListAppend(&gH323ep.ctxt, &gH323ep.stkCmdList, cmd);
  
#ifdef HAVE_PIPE
   if(write(gH323ep.cmdPipe[1], "c", 1)<0)
   {
      OOTRACEERR1("ERROR:Failed to write to command pipe\n");
   }
#endif
#ifdef _WIN32
   LeaveCriticalSection(&gCmdMutex);
#else
   pthread_mutex_unlock(&gCmdMutex);
#endif

   return OO_OK;
}

Handle that message on ooProcStackCmds()
ooStackCmds.c:
            case OO_CMD_MANUALRING:
                if (OO_TESTFLAG(gH323ep.flags, OO_M_MANUALRING))
                {       
                    OOTRACEINFO3("Manual Ring call %s. Media: %s\n", (char*)cmd->param1,
                                                                        *((int*)cmd->param2)?"Yes":"No");

                   
                    ooSendAlerting(ooFindCallByToken((char*)cmd->param1));
                }
               
                dListRemove(&gH323ep.stkCmdList, pNode);
                memFreePtr(&gH323ep.ctxt, pNode);
                break;

That's it, I tested with a commercial stacks in it works very well, including the normal mode (ooH323EpDisableManualRingback
). You might notice that theres int media parameter on the cmd. This for the next enhancement, to reply media using faststart reply under alerting message. Thats the next thing I want to know :-) Anyone to give hint?

Cheers guys, and well done on ooh323c

Benni-

Reply via email to