corrections in gk interface, small fixes in call clearing.
authorAlexandr Anikin <may@telecom-service.ru>
Sat, 27 Mar 2010 23:51:13 +0000 (23:51 +0000)
committerAlexandr Anikin <may@telecom-service.ru>
Sat, 27 Mar 2010 23:51:13 +0000 (23:51 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@255199 65c4cc65-6c06-0410-ace0-fbb531ad65f3

addons/chan_ooh323.c
addons/ooh323c/src/ooCalls.c
addons/ooh323c/src/ooGkClient.c
addons/ooh323c/src/ooh323.c
addons/ooh323c/src/ooh323.h
addons/ooh323c/src/ooq931.c

index 2ae95fa..30c4ab0 100644 (file)
@@ -609,6 +609,10 @@ static struct ast_channel *ooh323_request(const char *type, format_t format,
        if (dest) {
                peer = find_peer(dest, port);
        } else{
+               ast_mutex_lock(&iflock);
+               ast_mutex_unlock(&p->lock);
+               ooh323_destroy(p);
+               ast_mutex_unlock(&iflock);
                ast_log(LOG_ERROR, "Destination format is not supported\n");
                return NULL;
        }
@@ -642,6 +646,15 @@ static struct ast_channel *ooh323_request(const char *type, format_t format,
                ast_copy_string(p->accountcode, peer->accountcode, sizeof(p->accountcode));
                p->amaflags = peer->amaflags;
        } else {
+               if (gRasGkMode ==  RasNoGatekeeper) {
+                       /* no gk and no peer */
+                       ast_log(LOG_ERROR, "Call to undefined peer %s", dest);
+                       ast_mutex_lock(&iflock);
+                       ast_mutex_unlock(&p->lock);
+                       ooh323_destroy(p);
+                       ast_mutex_unlock(&iflock);
+                       return NULL;
+               }
                p->dtmfmode = gDTMFMode;
                p->dtmfcodec = gDTMFCodec;
                p->t38support = gT38Support;
@@ -672,23 +685,22 @@ static struct ast_channel *ooh323_request(const char *type, format_t format,
                ast_mutex_lock(&iflock);
                ooh323_destroy(p);
                ast_mutex_unlock(&iflock);
-   } else {
-      ast_mutex_lock(&p->lock);
-      p->callToken = (char*)ast_malloc(AST_MAX_EXTENSION);
-      if(!p->callToken)
-      {
-       ast_mutex_unlock(&p->lock);
-       ast_mutex_lock(&iflock);
-       ooh323_destroy(p);
-       ast_mutex_unlock(&iflock);
-       ast_log(LOG_ERROR, "Failed to allocate memory for callToken\n");
-       return NULL;
-      }
+       } else {
+               ast_mutex_lock(&p->lock);
+               p->callToken = (char*)ast_malloc(AST_MAX_EXTENSION);
+               if(!p->callToken) {
+                               ast_mutex_unlock(&p->lock);
+                               ast_mutex_lock(&iflock);
+                               ooh323_destroy(p);
+                               ast_mutex_unlock(&iflock);
+                               ast_log(LOG_ERROR, "Failed to allocate memory for callToken\n");
+                               return NULL;
+               }
 
-      ast_mutex_unlock(&p->lock);
-      ast_mutex_lock(&ooh323c_cmd_lock);
-      ooMakeCall(data, p->callToken, AST_MAX_EXTENSION, NULL);
-      ast_mutex_unlock(&ooh323c_cmd_lock);
+               ast_mutex_unlock(&p->lock);
+               ast_mutex_lock(&ooh323c_cmd_lock);
+               ooMakeCall(data, p->callToken, AST_MAX_EXTENSION, NULL);
+               ast_mutex_unlock(&ooh323c_cmd_lock);
        }
 
        restart_monitor();
@@ -955,17 +967,17 @@ static int ooh323_call(struct ast_channel *ast, char *dest, int timeout)
        else
                ast_copy_string(destination, dest, sizeof(destination));
 
-   destination[sizeof(destination)-1]='\0';
+       destination[sizeof(destination)-1]='\0';
 
-   opts.transfercap = ast->transfercapability;
+       opts.transfercap = ast->transfercapability;
 
-   for (i=0;i<480 && !isRunning(p->callToken);i++) usleep(12000);
+       for (i=0;i<480 && !isRunning(p->callToken);i++) usleep(12000);
 
-   if(OO_TESTFLAG(p->flags, H323_DISABLEGK)) {
-      res = ooRunCall(destination, p->callToken, AST_MAX_EXTENSION, &opts);
-   } else {
-      res = ooRunCall(destination, p->callToken, AST_MAX_EXTENSION, NULL);
-   }
+       if(OO_TESTFLAG(p->flags, H323_DISABLEGK)) {
+               res = ooRunCall(destination, p->callToken, AST_MAX_EXTENSION, &opts);
+       } else {
+               res = ooRunCall(destination, p->callToken, AST_MAX_EXTENSION, NULL);
+       }
 
        ast_mutex_unlock(&p->lock);
        if (res != OO_OK) {
index 71d6309..f924648 100644 (file)
@@ -217,6 +217,11 @@ int ooEndCall(OOH323CallData *call)
 
    if (call->callIdentifier.guid.numocts == 0) call->callState = OO_CALL_CLEARED;
 
+   if(!call->pH225Channel || call->pH225Channel->sock ==0)
+   {
+      call->callState = OO_CALL_CLEARED;
+   }
+
    if(call->callState == OO_CALL_CLEARED || call->callState == OO_CALL_CLEAR_RELEASESENT)
    {
       ooCleanCall(call); 
@@ -242,20 +247,14 @@ int ooEndCall(OOH323CallData *call)
    }
 
 
-   if(!call->pH225Channel || call->pH225Channel->sock ==0)
+   if(!OO_TESTFLAG(call->flags, OO_M_RELEASE_BUILT))   
    {
-      call->callState = OO_CALL_CLEARED;
-   }
-   else{
-      if(!OO_TESTFLAG(call->flags, OO_M_RELEASE_BUILT))   
-      {
-         if(call->callState == OO_CALL_CLEAR || 
-            call->callState == OO_CALL_CLEAR_RELEASERECVD)
-         {
-            ooSendReleaseComplete(call);
-            OO_SETFLAG(call->flags, OO_M_RELEASE_BUILT);
-         }
-      }
+     if(call->callState == OO_CALL_CLEAR || 
+        call->callState == OO_CALL_CLEAR_RELEASERECVD)
+     {
+        ooSendReleaseComplete(call);
+        OO_SETFLAG(call->flags, OO_M_RELEASE_BUILT);
+     }
    }
       
    return OO_OK;
index e5c6361..efbf983 100644 (file)
@@ -686,7 +686,7 @@ int ooGkClientSendGRQ(ooGkClient *pGkClient)
 
    pGkReq->m.endpointAliasPresent=TRUE;
    if(OO_OK != ooPopulateAliasList(&pGkClient->msgCtxt, gH323ep.aliases, 
-                                      &pGkReq->endpointAlias))
+                                      &pGkReq->endpointAlias, 0))
    {
       OOTRACEERR1("Error Failed to fill alias information for GRQ message\n");
       memReset(&pGkClient->msgCtxt);
@@ -1010,7 +1010,7 @@ int ooGkClientSendRRQ(ooGkClient *pGkClient, ASN1BOOL keepAlive)
 
    pRegReq->m.terminalAliasPresent=TRUE;
    if(OO_OK != ooPopulateAliasList(pctxt, gH323ep.aliases, 
-                                     &pRegReq->terminalAlias)) {
+                                     &pRegReq->terminalAlias, 0)) {
      OOTRACEERR1("Error filling alias for RRQ\n");
      memReset(pctxt); 
      pGkClient->state = GkClientFailed;
@@ -1457,7 +1457,7 @@ int ooGkClientSendURQ(ooGkClient *pGkClient, ooAliases *aliases)
    if(aliases)
    {
       pUnregReq->m.endpointAliasPresent = TRUE;
-      ooPopulateAliasList(pctxt, aliases, &pUnregReq->endpointAlias);
+      ooPopulateAliasList(pctxt, aliases, &pUnregReq->endpointAlias, 0);
    }
 
   
@@ -1716,7 +1716,7 @@ int ooGkClientSendAdmissionRequest
    {
       pAdmReq->m.destinationInfoPresent = 1;
       if(OO_OK != ooPopulateAliasList(&pGkClient->msgCtxt, destAliases,
-                                      &pAdmReq->destinationInfo))
+                      &pAdmReq->destinationInfo, T_H225AliasAddress_dialedDigits))
       {
          OOTRACEERR1("Error:Failed to populate destination aliases - "
                     "ARQ message\n");
@@ -1731,7 +1731,7 @@ int ooGkClientSendAdmissionRequest
    if(srcAliases)
    {
       iRet = ooPopulateAliasList(&pGkClient->msgCtxt, srcAliases,
-                                                          &pAdmReq->srcInfo);
+                              &pAdmReq->srcInfo, 0);
       if(OO_OK != iRet)
       {
          OOTRACEERR1("Error:Failed to populate source aliases -ARQ message\n");
@@ -2027,7 +2027,7 @@ int ooGkClientHandleAdmissionReject
                 "(%s, %s)\n", pAdmissionReject->rejectReason.t, call->callType,
                  call->callToken);
    
-   call->callState = OO_CALL_CLEAR;
+   call->callState = OO_CALL_CLEARED;
 
    switch(pAdmissionReject->rejectReason.t)
    {
@@ -2204,10 +2204,10 @@ int ooGkClientSendIRR
    if(srcAliases)
    {
       iRet = ooPopulateAliasList(&pGkClient->msgCtxt, srcAliases,
-                                                          &pIRR->endpointAlias);
+                             &pIRR->endpointAlias, T_H225AliasAddress_h323_ID);
       if(OO_OK != iRet)
       {
-         OOTRACEERR1("Error:Failed to populate source aliases -ARQ message\n");
+         OOTRACEERR1("Error:Failed to populate source aliases -IRR message\n");
          memReset(pctxt);
          pGkClient->state = GkClientFailed;
         ast_mutex_unlock(&pGkClient->Lock);
index 8f6b4cb..01cb7c7 100644 (file)
@@ -2219,7 +2219,7 @@ int ooPopulatePrefixList(OOCTXT *pctxt, OOAliases *pAliases,
    return OO_OK;
 }
 int ooPopulateAliasList(OOCTXT *pctxt, OOAliases *pAliases,
-                           H225_SeqOfH225AliasAddress *pAliasList )
+                           H225_SeqOfH225AliasAddress *pAliasList, int pAliasType)
 {
    H225AliasAddress *pAliasEntry=NULL;
    OOAliases * pAlias=NULL;
@@ -2243,23 +2243,27 @@ int ooPopulateAliasList(OOCTXT *pctxt, OOAliases *pAliases,
             OOTRACEERR1("ERROR:Memory - ooPopulateAliasList - pAliasEntry\n");
             return OO_FAILED;
          }
+
+        if (pAliasType && pAlias->type != pAliasType) {
+               pAlias = pAlias->next;
+               continue;
+        }
          switch(pAlias->type)
          {
-        /* Don't populate DialedDigits as alias they populate as prefixes
             case T_H225AliasAddress_dialedDigits:
-            pAliasEntry->t = T_H225AliasAddress_dialedDigits;
-            pAliasEntry->u.dialedDigits = (ASN1IA5String)memAlloc(pctxt,
+             pAliasEntry->t = T_H225AliasAddress_dialedDigits;
+             pAliasEntry->u.dialedDigits = (ASN1IA5String)memAlloc(pctxt,
                                                      strlen(pAlias->value)+1);
-            if(!pAliasEntry->u.dialedDigits)
-            {
+             if(!pAliasEntry->u.dialedDigits)
+             {
                OOTRACEERR1("ERROR:Memory - ooPopulateAliasList - "
                            "dialedDigits\n");
                memFreePtr(pctxt, pAliasEntry);
                return OO_FAILED;
-            }
-            strcpy(*(char**)&pAliasEntry->u.dialedDigits, pAlias->value);
-            bValid = TRUE;
-            break; */
+             }
+             strcpy(*(char**)&pAliasEntry->u.dialedDigits, pAlias->value);
+             bValid = TRUE;
+            break;
          case T_H225AliasAddress_h323_ID:
             pAliasEntry->t = T_H225AliasAddress_h323_ID;
             pAliasEntry->u.h323_ID.nchars = strlen(pAlias->value);
index 187b099..6b7edc2 100644 (file)
@@ -136,7 +136,7 @@ EXTERN int ooPopulatePrefixList(OOCTXT *pctxt, OOAliases *pAliases,
  * @return           OO_OK, on success. OO_FAILED, otherwise. 
  */
 EXTERN int ooPopulateAliasList(OOCTXT *pctxt, OOAliases *pAliases,
-                               H225_SeqOfH225AliasAddress *pAliasList); 
+                               H225_SeqOfH225AliasAddress *pAliasList, int pAliasType); 
 
 /**
  * This function is used to search a particular alias in the alias list. The
index 626f969..7e42a22 100644 (file)
@@ -1383,10 +1383,10 @@ int ooSendAlerting(OOH323CallData *call)
    alerting->m.alertingAddressPresent = TRUE;
    if(call->ourAliases)
       ret = ooPopulateAliasList(pctxt, call->ourAliases, 
-                                       &alerting->alertingAddress);
+                                       &alerting->alertingAddress, 0);
    else
       ret = ooPopulateAliasList(pctxt, gH323ep.aliases,
-                                       &alerting->alertingAddress);
+                                       &alerting->alertingAddress, 0);
    if(OO_OK != ret)
    {
       OOTRACEERR1("Error:Failed to populate alias list in Alert message\n");
@@ -1889,10 +1889,10 @@ int ooAcceptCall(OOH323CallData *call)
    connect->m.connectedAddressPresent = TRUE;
    if(call->ourAliases)
       ret = ooPopulateAliasList(pctxt, call->ourAliases, 
-                                      &connect->connectedAddress);
+                                      &connect->connectedAddress, 0);
    else
       ret =  ooPopulateAliasList(pctxt, gH323ep.aliases, 
-                                        &connect->connectedAddress);
+                                        &connect->connectedAddress, 0);
    if(OO_OK != ret)
    {
       OOTRACEERR1("Error:Failed to populate alias list in Connect message\n");
@@ -2114,7 +2114,7 @@ int ooH323MakeCall(char *dest, char *callToken, ooCallOptions *opts)
 {
    OOCTXT *pctxt;
    OOH323CallData *call;
-   int ret=0, i=0, irand=0;
+   int ret=OO_OK, i=0, irand=0;
    char tmp[30]="\0";
    char *ip=NULL, *port = NULL;
    struct timeval tv;
@@ -2211,14 +2211,15 @@ int ooH323MakeCall(char *dest, char *callToken, ooCallOptions *opts)
 
    /* Send as H225 message to calling endpoint */
    ast_mutex_lock(&call->Lock);
-   if (call->callState < OO_CALL_CLEAR) 
+   if (call->callState < OO_CALL_CLEAR) {
     if ((ret = ooH323CallAdmitted (call)) != OO_OK) {
      ast_mutex_unlock(&call->Lock);
      return ret;
     }
+   } else ret = OO_FAILED;
    ast_mutex_unlock(&call->Lock);
 
-   return OO_OK;
+   return ret;
 }
 
 
@@ -2376,10 +2377,10 @@ int ooH323MakeCall_helper(OOH323CallData *call)
       setup->m.sourceAddressPresent = TRUE;
       if(call->ourAliases)
          ret = ooPopulateAliasList(pctxt, call->ourAliases, 
-                                                       &setup->sourceAddress);
+                                                       &setup->sourceAddress, 0);
       else if(gH323ep.aliases)
          ret =  ooPopulateAliasList(pctxt, gH323ep.aliases, 
-                                                       &setup->sourceAddress);
+                                                       &setup->sourceAddress, 0);
       if(OO_OK != ret)
       {
          OOTRACEERR1("Error:Failed to populate alias list in SETUP message\n");
@@ -2404,7 +2405,7 @@ int ooH323MakeCall_helper(OOH323CallData *call)
    {
       setup->m.destinationAddressPresent = TRUE;
       ret = ooPopulateAliasList(pctxt, call->remoteAliases, 
-                                                 &setup->destinationAddress);
+                                                 &setup->destinationAddress, 0);
       if(OO_OK != ret)
       {
          OOTRACEERR1("Error:Failed to populate destination alias list in SETUP"
@@ -2953,7 +2954,7 @@ int ooH323ForwardCall(char* callToken, char *dest)
    {    
       facility->m.alternativeAliasAddressPresent = TRUE;
       ret = ooPopulateAliasList(pctxt, call->pCallFwdData->aliases, 
-                                        &facility->alternativeAliasAddress);
+                                        &facility->alternativeAliasAddress, 0);
       if(ret != OO_OK)
       {
          OOTRACEERR3("Error:Failed to populate alternate aliases in "