ANSC_STATUS
CosaUsersRegSetUserInfo
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus      = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_USERS           pMyObject         = (PCOSA_DATAMODEL_USERS   )hThisObject;
    
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoUser          = (PPOAM_IREP_FOLDER_OBJECT )pMyObject->hIrepFolderUser;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoEnumUser      = (PPOAM_IREP_FOLDER_OBJECT )NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaUserContext  = NULL;
    PCOSA_DML_USER                  pCosaUser         = NULL;

    PSINGLE_LINK_ENTRY              pSLinkEntry       = (PSINGLE_LINK_ENTRY       )NULL;    
    PSLAP_VARIABLE                  pSlapVariable     = NULL;
    ULONG                           ulEntryCount      = 0;
    ULONG                           ulIndex           = 0;
    ULONG                           uInstanceNumber   = 0;
    char*                           pAliasUser        = NULL;
    char*                           pFolderName       = NULL;
    char                            FolderName[16]    = {0};

    
    if ( !pPoamIrepFoUser )
    {
        return ANSC_STATUS_FAILURE;
    }
    else
    {
        pPoamIrepFoUser->EnableFileSync((ANSC_HANDLE)pPoamIrepFoUser, FALSE);
    }

    if ( TRUE )
    {
        pPoamIrepFoUser->Clear((ANSC_HANDLE)pPoamIrepFoUser);

        SlapAllocVariable(pSlapVariable);

        if ( !pSlapVariable )
        {
            returnStatus = ANSC_STATUS_RESOURCES;

            goto  EXIT1;
        }
    }

    /* This is saved structure for user
        *****************************************
              <User>
                  <NextInstanceNumber> xxx </>
                  <1>
                       <alias>xxx</>
                       <bNew>false</>
                 </1>
                 <2>
                      <alias>xxx</>
                      <bNew>false</>
                </2>
            </User>
      ****************************************************
      */

    /* add client.{i}.maxInstanceNumber  */
    if ( TRUE )
    {
        pSlapVariable->Syntax            = SLAP_VAR_SYNTAX_uint32;
        pSlapVariable->Variant.varUint32 = pMyObject->maxInstanceOfUser;
    
        returnStatus =
            pPoamIrepFoUser->AddRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoUser,
                    COSA_DML_RR_NAME_UserNextInsNunmber,
                    SYS_REP_RECORD_TYPE_UINT,
                    SYS_RECORD_CONTENT_DEFAULT,
                    pSlapVariable,
                    0
                );
    
        SlapCleanVariable(pSlapVariable);
        SlapInitVariable (pSlapVariable);
    }
    
    pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->UserList);

    while ( pSLinkEntry )
    {
        /* create user.{i} */
        
        pCosaUserContext = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry);
        pSLinkEntry       = AnscSListGetNextEntry(pSLinkEntry);

        pCosaUser = (PCOSA_DML_USER)pCosaUserContext->hContext;

        if ( !pCosaUserContext->bNew)
        {
            continue;
        }

        _ansc_sprintf(FolderName, "%d", pCosaUser->InstanceNumber);

        pPoamIrepFoEnumUser =
            pPoamIrepFoUser->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoUser,
                    FolderName,
                    0
                );

        if ( !pPoamIrepFoEnumUser )
        {
            continue;
        }

        /* add  user.{i}.Username */
        if ( TRUE )
        {
            pSlapVariable->Syntax            = SLAP_VAR_SYNTAX_string;
            pSlapVariable->Variant.varString = AnscCloneString(pCosaUser->Username);

            returnStatus =
                pPoamIrepFoEnumUser->AddRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumUser,
                        COSA_DML_RR_NAME_UserAlias,
                        SYS_REP_RECORD_TYPE_ASTR,
                        SYS_RECORD_CONTENT_DEFAULT,
                        pSlapVariable,
                        0
                    );

            SlapCleanVariable(pSlapVariable);
            SlapInitVariable (pSlapVariable);
        }

        /* add  user.{i}.bNew */
        if ( TRUE )
        {
            pSlapVariable->Syntax            = SLAP_VAR_SYNTAX_bool;
            pSlapVariable->Variant.varBool   = pCosaUserContext->bNew;

            returnStatus =
                pPoamIrepFoEnumUser->AddRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumUser,
                        COSA_DML_RR_NAME_UserbNew,
                        SYS_REP_RECORD_TYPE_BOOL,
                        SYS_RECORD_CONTENT_DEFAULT,
                        pSlapVariable,
                        0
                    );

            SlapCleanVariable(pSlapVariable);
            SlapInitVariable (pSlapVariable);
        }
       

        /*release some resource */        
        pPoamIrepFoEnumUser->Remove((ANSC_HANDLE)pPoamIrepFoEnumUser);
        pPoamIrepFoEnumUser = NULL;
    }
        

EXIT1:
    if ( pSlapVariable )
    {
        SlapFreeVariable(pSlapVariable);
        pSlapVariable = NULL;
    }

    if ( pPoamIrepFoEnumUser )
        pPoamIrepFoEnumUser->Remove((ANSC_HANDLE)pPoamIrepFoEnumUser);

    pPoamIrepFoUser->EnableFileSync((ANSC_HANDLE)pPoamIrepFoUser, TRUE);

    return returnStatus;
}
Esempio n. 2
0
ANSC_STATUS
CosaNatSyncPortTrigger
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus        = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_NAT             pMyObject           = (PCOSA_DATAMODEL_NAT     )hThisObject;
    PCOSA_CONTEXT_LINK_OBJECT       pCxtLink            = NULL;
    PSINGLE_LINK_ENTRY              pSListEntry         = NULL;
    PCOSA_DML_NAT_PTRIGGER          pPortTrigger        = NULL;
    PCOSA_DML_NAT_PTRIGGER          pPtEntry            = NULL;
    ULONG                           entryCount          = 0;
    ULONG                           i                   = 0;
    BOOL*                           pbFoundPt           = NULL;

    CcspTraceWarning(("!!!!!!!! in CosaNatSyncPortTrigger !!!!!!!!\n"));

    pPortTrigger = CosaDmlNatGetPortTriggers(NULL,&entryCount,TRUE);

    if ( !pPortTrigger )
    {
        /* Get Error, we don't del link because next time, it may be successful */
        return ANSC_STATUS_FAILURE;
    }

    pbFoundPt     = (BOOL*)AnscAllocateMemory(sizeof(BOOL) * entryCount);
    AnscZeroMemory(pbFoundPt, (sizeof(BOOL) * entryCount));

    if ( !pbFoundPt )
    {
        AnscFreeMemory(pPortTrigger); /*RDKB-6742, CID-32996, free unused resources before exit*/
        return ANSC_STATUS_RESOURCES;
    }

    pSListEntry =   AnscSListGetFirstEntry(&pMyObject->NatPTriggerList);

    while( pSListEntry )
    {
        pCxtLink          = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSListEntry);
        pSListEntry       = AnscSListGetNextEntry(pSListEntry);

        pPtEntry          = (PCOSA_DML_NAT_PTRIGGER)pCxtLink->hContext;

        for ( i = 0; i < entryCount; i++)
        {
            if ( pPtEntry->InstanceNumber == pPortTrigger[i].InstanceNumber )
            {
                /* If found, update the content also */
                CcspTraceWarning(("!!!!!!!! Ready to copy 1 !!!!!!!!\n"));
                AnscCopyMemory(pPtEntry, &pPortTrigger[i], sizeof(COSA_DML_NAT_PTRIGGER)); /* pOriAlias is NULL, no deep copy needed */

                pCxtLink->bNew = FALSE;
                pbFoundPt[i]   = TRUE;

                break;
            }
        }
    }

    /* Check those in backend but not yet in middle layer */

    for ( i = 0; i < entryCount; i++ )
    {
        if ( pbFoundPt[i] == FALSE )
        {
            /* We add new entry into our link table */
            pCxtLink = AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));
            if ( !pCxtLink )
            {
                goto EXIT1;
            }

            pPtEntry = AnscAllocateMemory(sizeof(COSA_DML_NAT_PTRIGGER));
            if ( !pPtEntry )
            {
                goto EXIT2;
            }

            /* copy new content which should include InstanceNumber and Alias */
            CcspTraceWarning(("!!!!!!!! Ready to copy 2 &pPortTrigger[%d]->InsNumber: %d !!!!!!!!\n", i, pPortTrigger[i].InstanceNumber));
            AnscCopyMemory(pPtEntry, &pPortTrigger[i], sizeof(COSA_DML_NAT_PTRIGGER)); /* pOriAlias is NULL, no deep copy needed */
            CcspTraceWarning(("!!!!!!!! After copy 2 pPtEntry->InsNumber: %d !!!!!!!!\n", pPtEntry->InstanceNumber));

            pCxtLink->hContext       = (ANSC_HANDLE)pPtEntry;
            pCxtLink->InstanceNumber = pPtEntry->InstanceNumber;
            pCxtLink->bNew           = FALSE;

            CosaSListPushEntryByInsNum(&pMyObject->NatPTriggerList, (PCOSA_CONTEXT_LINK_OBJECT)pCxtLink);
        }
    }

    returnStatus = ANSC_STATUS_SUCCESS;

    goto EXIT1;


EXIT2:

    AnscFreeMemory(pCxtLink);

EXIT1:

    AnscFreeMemory(pbFoundPt);
    AnscFreeMemory(pPortTrigger);

    CcspTraceWarning(("!!!!!!!! out CosaNatSyncPortTrigger !!!!!!!!\n"));

    return returnStatus;
}
ANSC_STATUS
BbhmDiagnsRecv
    (
        ANSC_HANDLE                 hThisObject,
        ANSC_HANDLE                 hXsinkObject,
        PVOID                       buffer,
        ULONG                       ulSize
    )
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PBBHM_DIAG_NS_LOOKUP_OBJECT     pMyObject    = (PBBHM_DIAG_NS_LOOKUP_OBJECT )hThisObject;
    PBBHM_NS_LOOKUP_PROPERTY        pProperty    = (PBBHM_NS_LOOKUP_PROPERTY    )&pMyObject->Property;
    PBBHM_NS_LOOKUP_TDO_OBJECT      pStateTimer  = (PBBHM_NS_LOOKUP_TDO_OBJECT  )pMyObject->hStateTimer;
    PBBHM_NS_LOOKUP_XSINK_OBJECT    pXsink       = (PBBHM_NS_LOOKUP_XSINK_OBJECT)hXsinkObject;
    PANSC_XSOCKET_OBJECT            pXsocket     = (PANSC_XSOCKET_OBJECT        )pXsink->GetXsocket((ANSC_HANDLE)pXsink);
    PDSLH_NSLOOKUP_INFO             pDiagInfo    = (PDSLH_NSLOOKUP_INFO         )pMyObject->hDslhDiagInfo;
    PDNS_HEADER                     pDnsHeader   = (PDNS_HEADER)buffer;
    PBBHM_NS_LOOKUP_ECHO_ENTRY      pEchoEntry   = NULL;
    PBBHM_NS_LOOKUP_QUERY_ENTRY     pQuery       = NULL;
    ULONG                           StopTime     = 0;
    PSINGLE_LINK_ENTRY              pSLinkEntry  = NULL;
    char*                           p            = NULL;

    StopTime = AnscGetTickInMilliSeconds();


    if ( pProperty->Status != BBHM_NS_LOOKUP_STATUS_RUNNING )
    {
        return  ANSC_STATUS_UNAPPLICABLE;
    }

    /* Temporarily disable this check since we will check pQuery later */
/*
    if ( pXsocket->PeerAddress.Value != pProperty->DstIp.Value )
    {
        return  ANSC_STATUS_FAILURE;
    }
*/

    pQuery = pMyObject->GetPqueryById(pMyObject, AnscDnsGetId(pDnsHeader));
    if ( pQuery )
    {
        if ( AnscDnsGetRcode(pDnsHeader) != 0 )
        {
            if ( AnscDnsGetRcode(pDnsHeader) == DNS_RCODE_NAME_ERROR )
            {
                p = pDiagInfo->HostName + AnscSizeOfString(pDiagInfo->HostName) + 1;

                if ( AnscSizeOfString(p) )
                {
                    if ( !AnscEqualString(p - AnscSizeOfString(p) - 1, p, TRUE) )
                    {
                        pStateTimer->Stop((ANSC_HANDLE)pStateTimer);
                        pProperty->Control = BBHM_NS_LOOKUP_CONTROL_STOP;
                        pMyObject->DelAllPqueries(hThisObject);
                        pMyObject->PopEchoEntry(hThisObject);
                        pMyObject->ResetPropertyCounter(hThisObject);

                        *(p - 1) = '.';
                        pMyObject->SetControl   ((ANSC_HANDLE)pMyObject, BBHM_NS_LOOKUP_CONTROL_START);
                        BbhmDiageoStartDiag     ((ANSC_HANDLE)pMyObject);
                        return  ANSC_STATUS_SUCCESS;
                    }
                }
            }


            pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->EchoTable);

            while ( pSLinkEntry )
            {
                pEchoEntry  = ACCESS_BBHM_NS_LOOKUP_ECHO_ENTRY(pSLinkEntry);
                pSLinkEntry = AnscSListGetNextEntry(pSLinkEntry);

                if ( pQuery->QueryId == pEchoEntry->QueryId )
                {
                    break;
                }
            }

            if ( AnscDnsGetRcode(pDnsHeader) == DNS_RCODE_NAME_ERROR )
            {
                pEchoEntry->Status = BBHM_NS_LOOKUP_STATUS_Error_HostNameNotResolved;
            }
            else if ( AnscDnsGetRcode(pDnsHeader) == DNS_RCODE_SERVER_FAILURE ||  AnscDnsGetRcode(pDnsHeader) == DNS_RCODE_REFUSED )
            {
                pEchoEntry->Status = BBHM_NS_LOOKUP_STATUS_Error_DNSServerNotAvailable;
            }
            else
            {
                pEchoEntry->Status = BBHM_NS_LOOKUP_STATUS_Error_Other;
            }
            pEchoEntry->AnswerType = AnscDnsIsAuthoritativeAnswer(pDnsHeader) ? BBHM_NS_LOOKUP_RESULT_Authoritative : BBHM_NS_LOOKUP_RESULT_NonAuthoritative;
            pEchoEntry->HostNameReturned = NULL;
            pEchoEntry->IPAddresses = NULL;
            pMyObject->DelPquery(pMyObject, pQuery);

            pProperty->PktsRecv++;
        }
        else
        {
            returnStatus = pMyObject->SetStopTime((ANSC_HANDLE)pMyObject, pQuery, pDnsHeader, StopTime);

            if ( returnStatus == ANSC_STATUS_SUCCESS )
            {
                pProperty->PktsRecv++;
            }
        }

        if ( pProperty->PktsRecv == pProperty->NumPkts )
        {
            pMyObject->SetStatus((ANSC_HANDLE)pMyObject, BBHM_NS_LOOKUP_STATUS_COMPLETE);
            pMyObject->Stop((ANSC_HANDLE)pMyObject);
        }

        return  returnStatus;
    }

    return  ANSC_STATUS_SUCCESS;
}
ANSC_HANDLE
HttpAuthcoFindAuthInfo2
    (
        ANSC_HANDLE                 hThisObject,
        ANSC_HANDLE                 hRequest,
        PBOOL                       pbParentUri
    )
{
    ANSC_STATUS                     status       = ANSC_STATUS_SUCCESS;
    PHTTP_AUTH_CLIENT_OBJECT        pMyObject    = (PHTTP_AUTH_CLIENT_OBJECT)hThisObject;
    PHTTP_BMO_REQ_OBJECT            pRequest     = (PHTTP_BMO_REQ_OBJECT    )hRequest;
    PHTTP_AUTHO_INFO                pAuthInfo    = NULL;
    PSINGLE_LINK_ENTRY              pSLinkEntry  = NULL;
    ANSC_HANDLE                     hAuthInfo    = (ANSC_HANDLE)NULL;
    PUCHAR                          pHostName    = NULL;
    PUCHAR                          pUriPath     = NULL;
    USHORT                          HostPort     = 0;
    PUCHAR                          pDomain      = NULL;
    PUCHAR                          pMatchStr;

    *pbParentUri    = FALSE;

    status = pMyObject->GetRequestHostUri((ANSC_HANDLE)pMyObject, hRequest, &pHostName, &HostPort, &pUriPath);

    if ( status != ANSC_STATUS_SUCCESS || !pUriPath || !pHostName )
    {
        goto EXIT;
    }

    pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->AuthInfoList);
    while (pSLinkEntry)
    {
        pAuthInfo   = ACCESS_HTTP_AUTHO_INFO_OBJECT(pSLinkEntry);
        pSLinkEntry = AnscSListGetNextEntry(pSLinkEntry);

        if ( pAuthInfo->HostPort != HostPort )
        {
            continue;
        }

        if ( !AnscEqualString(pAuthInfo->pHostName, pHostName, FALSE) )
        {
            continue;
        }

        if ( AnscEqualString(pAuthInfo->pUri, pUriPath, TRUE ) )
        {
            hAuthInfo       = (ANSC_HANDLE)pAuthInfo;
            break;
        }

        pMatchStr   = (PUCHAR)_ansc_strstr(pUriPath, pAuthInfo->pUri);
        if ( pMatchStr == pUriPath )
        {
            hAuthInfo       = (ANSC_HANDLE)pAuthInfo;
            break;
        }

        pMatchStr   = (PUCHAR)_ansc_strstr(pAuthInfo->pUri, pUriPath);
        if ( pMatchStr == pAuthInfo->pUri )
        {
            hAuthInfo       = (ANSC_HANDLE)pAuthInfo;
            *pbParentUri    = TRUE;
            break;
        }

        if ( pAuthInfo->AuthType == HTTP_AUTH_TYPE_DIGEST )
        {
            PUCHAR                          *pURIs;
            ULONG                           i, ulCount;
            BOOL                            bMatch  = FALSE;

            if ( pAuthInfo->pDigest->pDomainURIs )
            {
                ulCount = pAuthInfo->pDigest->pDomainURIs->NumURIs;
                pURIs   = pAuthInfo->pDigest->pDomainURIs->pURIs;

                for ( i = 0; i < ulCount; i ++)
                {
                    pMatchStr   = (PUCHAR)_ansc_strstr(pUriPath, pURIs[i]);
                    if ( pMatchStr == pUriPath )
                    {
                        bMatch  = TRUE;
                        break;
                    }
                }

                if ( bMatch )
                {
                    hAuthInfo   = (ANSC_HANDLE)pAuthInfo;
                    break;
                }
            }
            else
            {
                pDomain = pAuthInfo->pDigest->pDomain;

                pMatchStr   = (PUCHAR)_ansc_strstr(pUriPath, pDomain);
                if ( pMatchStr == pUriPath )
                {
                    hAuthInfo   = (ANSC_HANDLE)pAuthInfo;
                    break;
                }
            }
        }
    }

EXIT:

    if ( pHostName )
    {
        AnscFreeMemory(pHostName);
    }

    if ( pUriPath )
    {
        AnscFreeMemory(pUriPath);
    }

    /* move this info to front-most */
    if ( hAuthInfo )
    {
        pAuthInfo   = (PHTTP_AUTHO_INFO)hAuthInfo;

        AnscSListPopEntryByLink(&pMyObject->AuthInfoList, &pAuthInfo->Linkage);
        AnscSListPushEntry(&pMyObject->AuthInfoList, &pAuthInfo->Linkage);
    }

    return hAuthInfo;
}
Esempio n. 5
0
ANSC_STATUS
CosaRARemove
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus    = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_RA              pMyObject       = (PCOSA_DATAMODEL_RA)hThisObject;
    PSLIST_HEADER                   pRAIFHead       = (PSLIST_HEADER)&pMyObject->InterfaceList;
    PSLIST_HEADER                   pRAOptionHead       = (PSLIST_HEADER)NULL;
    PCOSA_DML_RA_IF_FULL2           pRAInterface    = (PCOSA_DML_RA_IF_FULL2)NULL;
    PCOSA_DML_RA_OPTION             pRAOption       = (PCOSA_DML_RA_OPTION)NULL;
    PSINGLE_LINK_ENTRY              pLink           = (PSINGLE_LINK_ENTRY )NULL;
    PSINGLE_LINK_ENTRY              pSubLink        = (PSINGLE_LINK_ENTRY )NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaContext    = (PCOSA_CONTEXT_LINK_OBJECT)NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pSubCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoTemp = (PPOAM_IREP_FOLDER_OBJECT)NULL;

    /*free the back end memory*/
    CosaDmlRaIfBERemove();

    /* RA Interface List */
    pLink = AnscSListGetFirstEntry(pRAIFHead);

    while ( pLink )
    {
        pCosaContext = ACCESS_COSA_CONTEXT_LINK_OBJECT(pLink);
        pLink   = AnscSListGetNextEntry(pLink);

        pRAInterface = (PCOSA_DML_RA_IF_FULL2)pCosaContext->hContext;

        if ( pRAInterface )
        {
            AnscSListPopEntryByLink(pRAIFHead, &pCosaContext->Linkage);

            pRAOptionHead    = &pRAInterface->OptionList;

            /* Option List */            
            pSubLink = AnscSListGetFirstEntry(pRAOptionHead);
        
            while ( pSubLink )
            {
                pSubCosaContext = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSubLink);
                
                pSubLink  = AnscSListGetNextEntry(pSubLink);
            
                pRAOption = (PCOSA_DML_RA_OPTION)pSubCosaContext->hContext;
            
                AnscSListPopEntryByLink(pRAOptionHead, &pSubCosaContext->Linkage);
            
                if ( pRAOption )
                {
                    AnscFreeMemory(pRAOption);
                }
            
                AnscFreeMemory(pSubCosaContext);
            }

            AnscFreeMemory(pRAInterface);
            AnscFreeMemory(pCosaContext);
        }
    }


    /* Remove self */
    pPoamIrepFoTemp = (PPOAM_IREP_FOLDER_OBJECT)pMyObject->hIrepFolderRAInterfaceHA;
    if ( pPoamIrepFoTemp )
    {
        pPoamIrepFoTemp->Remove(pPoamIrepFoTemp);
    }

    
    pPoamIrepFoTemp = (PPOAM_IREP_FOLDER_OBJECT)pMyObject->hIrepFolderRAInterface;
    if ( pPoamIrepFoTemp )
    {
        pPoamIrepFoTemp->Remove(pPoamIrepFoTemp);
    }
 

    AnscFreeMemory((ANSC_HANDLE)pMyObject);

    return returnStatus;
}
Esempio n. 6
0
ANSC_STATUS
CosaRaRegGetInfo

    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus    = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_RA              pMyObject       = (PCOSA_DATAMODEL_RA)hThisObject;
    PSLIST_HEADER                   pRAIFHead       = (PSLIST_HEADER)&pMyObject->InterfaceList;
    PCOSA_DML_RA_IF_FULL2           pRAInterface    = (PCOSA_DML_RA_IF_FULL2)NULL;
    PCOSA_DML_RA_IF_FULL2           pRAEntry        = (PCOSA_DML_RA_IF_FULL2)NULL;
    PCOSA_DML_RA_OPTION             pRAOption       = (PCOSA_DML_RA_OPTION)NULL;
    PSINGLE_LINK_ENTRY              pLink           = (PSINGLE_LINK_ENTRY )NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaContext    = (PCOSA_CONTEXT_LINK_OBJECT)NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pSubCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoRAHA = (PPOAM_IREP_FOLDER_OBJECT)pMyObject->hIrepFolderRAInterfaceHA;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoRAIF = (PPOAM_IREP_FOLDER_OBJECT)NULL;
    PSLAP_VARIABLE                  pSlapVariable   = (PSLAP_VARIABLE          )NULL;
    ULONG                           ulEntryCount            = 0;
    ULONG                           ulIndex                 = 0;
    ULONG                           ulInstanceNumber        = 0;
    ULONG                           ulUpperInstanceNumber   = 0;
    char*                           pFolderName             = NULL;
    char*                           pAlias                  = NULL;

    if ( !pPoamIrepFoRAHA )
    {
        return ANSC_STATUS_FAILURE;
    }

    /* Load the newly added but not yet commited entries */

    ulEntryCount = pPoamIrepFoRAHA->GetFolderCount((ANSC_HANDLE)pPoamIrepFoRAHA);

    for ( ulIndex = 0; ulIndex < ulEntryCount; ulIndex++ )
    {
        pFolderName = pPoamIrepFoRAHA->EnumFolder
            (
                (ANSC_HANDLE)pPoamIrepFoRAHA,
                ulIndex
            );

        if ( !pFolderName )
        {
            continue;
        }

        pPoamIrepFoRAIF = (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoRAHA->GetFolder
            (
                (ANSC_HANDLE)pPoamIrepFoRAHA, 
                pFolderName
            );

        if ( !pPoamIrepFoRAIF )
        {
            continue;
        }

        if ( _ansc_strstr(pFolderName, COSA_DML_RR_NAME_RAIF_Prefix) )
        {

            pSlapVariable = (PSLAP_VARIABLE)pPoamIrepFoRAIF->GetRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoRAIF,
                    COSA_DML_RR_NAME_RAIF_InsNum,
                    NULL
                );

            if ( pSlapVariable )
            {
                ulInstanceNumber = pSlapVariable->Variant.varUint32;
                SlapFreeVariable(pSlapVariable);
            }
            


            pSlapVariable = (PSLAP_VARIABLE)pPoamIrepFoRAIF->GetRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoRAIF,
                    COSA_DML_RR_NAME_RAIF_Alias,
                    NULL
                );

            if ( pSlapVariable )
            {
                pAlias = AnscCloneString(pSlapVariable->Variant.varString);  
                    
                SlapFreeVariable(pSlapVariable);
            }


            pCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));

            if ( !pCosaContext )
            {
                returnStatus = ANSC_STATUS_RESOURCES;
                goto EXIT;
            }

            pRAInterface = (PCOSA_DML_RA_IF_FULL2)AnscAllocateMemory(sizeof(COSA_DML_RA_IF_FULL2));

            if ( !pRAInterface )
            {
                AnscFreeMemory(pCosaContext);
                
                returnStatus = ANSC_STATUS_RESOURCES;
                
                goto EXIT;
            }

            AnscSListInitializeHeader(&pRAInterface->OptionList);
            
            pRAInterface->ulNextOptionInsNum    = 1;
            
            pRAInterface->Cfg.InstanceNumber = ulInstanceNumber;
            AnscCopyString(pRAInterface->Cfg.Alias, pAlias);

            pCosaContext->InstanceNumber   = ulInstanceNumber;
            pCosaContext->bNew             = TRUE;
            pCosaContext->hContext         = (ANSC_HANDLE)pRAInterface;
            pCosaContext->hParentTable     = NULL;
            pCosaContext->hPoamIrepUpperFo = (ANSC_HANDLE)pPoamIrepFoRAHA;
            pCosaContext->hPoamIrepFo      = (ANSC_HANDLE)pPoamIrepFoRAIF;
            
            CosaSListPushEntryByInsNum(pRAIFHead, pCosaContext);
        }
        else
        {
            pSlapVariable = (PSLAP_VARIABLE)pPoamIrepFoRAIF->GetRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoRAIF,
                    COSA_DML_RR_NAME_RAIF_Upper_InsNum,
                    NULL
                );

            if ( pSlapVariable )
            {
                ulUpperInstanceNumber = pSlapVariable->Variant.varUint32;
                    
                SlapFreeVariable(pSlapVariable);
            }

            if ( ulUpperInstanceNumber != 0 )
            {
                pLink = AnscSListGetFirstEntry(pRAIFHead);

                while ( pLink )
                {
                    pCosaContext  = ACCESS_COSA_CONTEXT_LINK_OBJECT(pLink);
                    pLink   = AnscSListGetNextEntry(pLink);

                    pRAEntry = (PCOSA_DML_RA_IF_FULL2)pCosaContext->hContext;

                    if ( pRAEntry && (pRAEntry->Cfg.InstanceNumber == ulUpperInstanceNumber) )
                    {
                        break;
                    }
                }

                if ( !pRAEntry )
                {
                    returnStatus = ANSC_STATUS_FAILURE;

                    goto EXIT;
                }
            }
            else
            {
                returnStatus = ANSC_STATUS_FAILURE;

                goto EXIT;
            }


            pSlapVariable = (PSLAP_VARIABLE)pPoamIrepFoRAIF->GetRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoRAIF,
                    COSA_DML_RR_NAME_RAIF_InsNum,
                    NULL
                );
            
            if ( pSlapVariable )
            {
                ulInstanceNumber = pSlapVariable->Variant.varUint32;            

                SlapFreeVariable(pSlapVariable);
            }
            

            pSlapVariable = (PSLAP_VARIABLE)pPoamIrepFoRAIF->GetRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoRAIF,
                    COSA_DML_RR_NAME_RAIF_Alias,
                    NULL
                );
            
            if ( pSlapVariable )
            {
                pAlias = AnscCloneString(pSlapVariable->Variant.varString);            

                SlapFreeVariable(pSlapVariable);
            }
            
            if ( _ansc_strstr(pFolderName, COSA_DML_RR_NAME_RAIF_OPTION_Prefix) )
            {
                pRAOption = (PCOSA_DML_RA_OPTION)AnscAllocateMemory(sizeof(COSA_DML_RA_OPTION));

                if ( !pRAOption )
                {
                    returnStatus = ANSC_STATUS_RESOURCES;

                    goto EXIT;
                }

                pSubCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));

                if ( !pSubCosaContext )
                {
                    AnscFreeMemory(pRAOption);            

                    returnStatus = ANSC_STATUS_RESOURCES;

                    goto EXIT;
                }

                pRAOption->InstanceNumber = ulInstanceNumber;
                AnscCopyString(pRAOption->Alias, pAlias);

                pSubCosaContext->InstanceNumber  = ulInstanceNumber;
                pSubCosaContext->hContext        = (ANSC_HANDLE)pRAOption;
                pSubCosaContext->hParentTable    = (ANSC_HANDLE)pRAEntry;
                pSubCosaContext->bNew            = TRUE;
                pSubCosaContext->hPoamIrepUpperFo = (ANSC_HANDLE)pPoamIrepFoRAHA;
                pSubCosaContext->hPoamIrepFo      = (ANSC_HANDLE)pPoamIrepFoRAIF;

                CosaSListPushEntryByInsNum(&pRAEntry->OptionList, pSubCosaContext);
            }

        }
    
        if ( pAlias )
        {
            AnscFreeMemory(pAlias);
            pAlias = NULL;
        }

        if ( pFolderName )
        {
            AnscFreeMemory(pFolderName);
            pFolderName = NULL;
        }
    }

EXIT:

    if ( pAlias )
    {
        AnscFreeMemory(pAlias);
    }

    return returnStatus;
}
ANSC_STATUS
AnscDetoRecvTask
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus  = ANSC_STATUS_SUCCESS;
    PANSC_DAEMON_ENGINE_TCP_OBJECT  pMyObject     = (PANSC_DAEMON_ENGINE_TCP_OBJECT)hThisObject;
    PANSC_DAEMON_SERVER_TCP_OBJECT  pServer       = (PANSC_DAEMON_SERVER_TCP_OBJECT)pMyObject->hDaemonServer;
    PANSC_DSTO_WORKER_OBJECT        pWorker       = (PANSC_DSTO_WORKER_OBJECT      )pServer->hWorker;
#if !defined(_ANSC_KERNEL) || !defined(_ANSC_LINUX)
    ansc_fd_set*                    pRecvSet1     = (ansc_fd_set*                  )pMyObject->RecvSocketSet;
    xskt_fd_set*                    pRecvSet2     = (xskt_fd_set*                  )pMyObject->RecvSocketSet;
#endif
    PANSC_DAEMON_SOCKET_TCP_OBJECT  pSocket       = NULL;
    ULONG                           ulLastCleanAt = AnscGetTickInSecondsAbs();
    ANSC_SOCKET                     s_socket      = ANSC_SOCKET_INVALID_SOCKET;
    int                             s_result      = 0;
    int                             s_result_excp = 0;
    int                             s_error       = 0;
    int                             i             = 0;
#if !defined(_ANSC_KERNEL) || !defined(_ANSC_LINUX)
    ansc_fd_set*                    read_fd_set1  = NULL;
    xskt_fd_set*                    read_fd_set2  = NULL;
    ansc_fd_set*                    excp_fd_set1  = NULL;
    xskt_fd_set*                    excp_fd_set2  = NULL;
    ansc_timeval                    timeval1;
    xskt_timeval                    timeval2;
#endif

    AnscTrace("AnscDetoRecvTask is activated ...!\n");

#if !defined(_ANSC_KERNEL) || !defined(_ANSC_LINUX)
    read_fd_set1 = (ansc_fd_set*)AnscAllocateMemory(sizeof(ansc_fd_set));
    read_fd_set2 = (xskt_fd_set*)AnscAllocateMemory(sizeof(xskt_fd_set));
    excp_fd_set1 = (ansc_fd_set*)AnscAllocateMemory(sizeof(ansc_fd_set));
    excp_fd_set2 = (xskt_fd_set*)AnscAllocateMemory(sizeof(xskt_fd_set));

    if ( !read_fd_set1 || !read_fd_set2 || !excp_fd_set1 || !excp_fd_set2 )
    {
        goto  EXIT1;
    }
#endif

    /*
     * As a scalable server implemention, we shall accept as many incoming client connections as
     * possible and can only be limited by the system resources. Once the listening socket becomes
     * readable, which means an incoming connection attempt has arrived. We create a new socket
     * object and associate it with the client. This is a repeated process until the socket owner
     * closes the socket.
     */
    while ( pMyObject->bStarted )
    {
        ANSC_COMMIT_TASK();

        /*
         * To avoid letting the old half-dead sockets hogging up the system resource, we need to
         * periodically invoke the cleaning routine. The default interval is 10 seconds, and the
         * idle timeout value is 90 seconds.
         */
	#if !defined(_ANSC_KERNEL) || !defined(_ANSC_LINUX)
        if ( pMyObject->bCleaningDemanded )
	#else
		if ( FALSE ) /*if ( pMyObject->bCleaningDemanded )*/
	#endif
        {
            pMyObject->Clean((ANSC_HANDLE)pMyObject);

            ulLastCleanAt                = AnscGetTickInSecondsAbs();
            pMyObject->bCleaningDemanded = FALSE;
        }
        else if ( (AnscGetTickInSecondsAbs() - ulLastCleanAt) >= ANSC_DETO_CLEAN_TASK_INTERVAL )
        {
            pMyObject->Clean((ANSC_HANDLE)pMyObject);

            ulLastCleanAt                = AnscGetTickInSecondsAbs();
            pMyObject->bCleaningDemanded = FALSE;
        }

        /*
         * Since the original bsd compatible socket api doesn't support asynchronous operation, the
         * nonblocking status polling is the best we can get. As a matter of fact, the current unix
         * and linux actually still don't support asynchronous notification on any socket operation.
         */
    #if defined(_ANSC_KERNEL) && defined(_ANSC_LINUX)
        if ( !pMyObject->CurSocketCount)
        {
            if ( pServer->Mode & ANSC_DSTO_MODE_EVENT_SYNC )
            {
                AnscWaitEvent (&pMyObject->NewSocketEvent, ANSC_DETO_WAIT_EVENT_INTERVAL);
                AnscResetEvent(&pMyObject->NewSocketEvent);

                if (!pMyObject->CurSocketCount)
                {
                    AnscTaskRelinquish();

                    continue;
                }
            }
            else
            {
                AnscSleep(ANSC_DETO_TASK_BREAK_INTERVAL);

                continue;
            }
        }
    #else
        if ( pServer->Mode & ANSC_DSTO_MODE_XSOCKET )
        {
            AnscAcquireLock(&pMyObject->RecvSocketSetLock);
            *read_fd_set2 = *pRecvSet2;
            AnscReleaseLock(&pMyObject->RecvSocketSetLock);
        }
        else
        {
            AnscAcquireLock(&pMyObject->RecvSocketSetLock);
            *read_fd_set1 = *pRecvSet1;
            AnscReleaseLock(&pMyObject->RecvSocketSetLock);
        }

        if ( ( (pServer->Mode & ANSC_DSTO_MODE_XSOCKET) && XSKT_SOCKET_FD_ISNUL(read_fd_set2)) ||
             (!(pServer->Mode & ANSC_DSTO_MODE_XSOCKET) && ANSC_SOCKET_FD_ISNUL(read_fd_set1)) )
        {
            if ( pServer->Mode & ANSC_DSTO_MODE_EVENT_SYNC )
            {
                AnscWaitEvent (&pMyObject->NewSocketEvent, ANSC_DETO_WAIT_EVENT_INTERVAL);
                AnscResetEvent(&pMyObject->NewSocketEvent);

                if ( pServer->Mode & ANSC_DSTO_MODE_XSOCKET )
                {
                    AnscAcquireLock(&pMyObject->RecvSocketSetLock);
                    *read_fd_set2 = *pRecvSet2;
                    AnscReleaseLock(&pMyObject->RecvSocketSetLock);
                }
                else
                {
                    AnscAcquireLock(&pMyObject->RecvSocketSetLock);
                    *read_fd_set1 = *pRecvSet1;
                    AnscReleaseLock(&pMyObject->RecvSocketSetLock);
                }

                if ( ( (pServer->Mode & ANSC_DSTO_MODE_XSOCKET) && XSKT_SOCKET_FD_ISNUL(read_fd_set2)) ||
                     (!(pServer->Mode & ANSC_DSTO_MODE_XSOCKET) && ANSC_SOCKET_FD_ISNUL(read_fd_set1)) )
                {
                    AnscTaskRelinquish();

                    continue;
                }
            }
            else
            {
                AnscSleep(ANSC_DETO_TASK_BREAK_INTERVAL);

                continue;
            }
        }

        if ( pServer->Mode & ANSC_DSTO_MODE_XSOCKET )
        {
            timeval2.tv_sec  = (ANSC_DETO_POLL_INTERVAL_MS / 1000);          /* number of seconds      */
            timeval2.tv_usec = (ANSC_DETO_POLL_INTERVAL_MS % 1000) * 1000;   /* number of microseconds */
        }
        else
        {
            timeval1.tv_sec  = (ANSC_DETO_POLL_INTERVAL_MS / 1000);          /* number of seconds      */
            timeval1.tv_usec = (ANSC_DETO_POLL_INTERVAL_MS % 1000) * 1000;   /* number of microseconds */
        }

        /*
         * The _ansc_select() function returns the total number of socket handles that are ready
         * and contained in the fd_set structures, zero if the time limit expired, or SOCKET_ERROR
         * if an error occurred. Upon return, the structures are updated to reflect the subset of
         * these sockets that meet the specified condition.
         */
        if ( pServer->Mode & ANSC_DSTO_MODE_XSOCKET )
        {
            s_result = _xskt_select(XSKT_SOCKET_FD_SETSIZE, read_fd_set2, NULL, NULL, &timeval2);
        }
        else
        {
            s_result = _ansc_select(ANSC_SOCKET_FD_SETSIZE, read_fd_set1, NULL, NULL, &timeval1);
        }

        if ( s_result == 0 )
        {
            continue;
        }
        else if ( ( (pServer->Mode & ANSC_DSTO_MODE_XSOCKET) && (s_result == XSKT_SOCKET_ERROR)) ||
                  (!(pServer->Mode & ANSC_DSTO_MODE_XSOCKET) && (s_result == ANSC_SOCKET_ERROR)) )
        {
            s_error = (pServer->Mode & ANSC_DSTO_MODE_XSOCKET)? _xskt_get_last_error() : _ansc_get_last_error();

            /*
             * Previously we simply reset everything when _ansc_select() fails, which is not a good
             * solution: we shall notify the worker module and gracefully shutdown the socket(s)
             * that caused the error.
             */
            /*
            pMyObject->Reset((ANSC_HANDLE)pMyObject);
            */
            pMyObject->ExpAllSockets((ANSC_HANDLE)pMyObject);

            continue;
        }
        else if ( !pMyObject->bStarted )
        {
            break;
        }
	#endif

        /*
         * If there're multiple sockets are receiving data, we loop through the returned fd_set
         * structure and process them one-by-one. However, we have a slight problem: the resulted
         * fd_set consists of only the native socket handles, not the associated Socket Objects.
         * We have to first retrieve the peer's IP address from the socket, and use it to find
         * the associated socket object.
         */
	#if defined(_ANSC_KERNEL) && defined(_ANSC_LINUX)
        if (TRUE)
        {
            int                             i; 
            PSINGLE_LINK_ENTRY              pSLinkEntry;

            for ( i = 0; i < ANSC_DETO_SOCKET_TABLE_SIZE ; i++)
            {
                if (!AnscSListQueryDepth(&pMyObject->SocketTable[i]))
                {
                    continue;
                }

                AnscAcquireLock(&pMyObject->SocketTableLock);

                pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->SocketTable[i]);

                AnscReleaseLock(&pMyObject->SocketTableLock);

                while ( pSLinkEntry )
                {
                    pSocket     = ACCESS_ANSC_DAEMON_SOCKET_TCP_OBJECT(pSLinkEntry);
                    pSLinkEntry = AnscSListGetNextEntry(pSLinkEntry);

					if ( pSocket->bTlsEnabled )
					{
                        pMyObject->bBusy = TRUE;

                        returnStatus =
                            pMyObject->Recv2
                                (
                                    (ANSC_HANDLE)pMyObject,
                                    (ANSC_HANDLE)pSocket
                                );

                        pMyObject->bBusy = FALSE;
					}
                    else
                    {
                        pMyObject->bBusy = TRUE;

						returnStatus =
							pMyObject->Recv
								(
									(ANSC_HANDLE)pMyObject,
									(ANSC_HANDLE)pSocket
								);

                        pMyObject->bBusy = FALSE;
                    }
                }

                if ( !pMyObject->bStarted )
                {
                    break;
                }
            }

            AnscSleep(10);
        }
	#else
        for ( i = 0; i < s_result; i++ )
        {
            if ( pServer->Mode & ANSC_DSTO_MODE_XSOCKET )
            {
                XSKT_SOCKET_FD_GET(read_fd_set2, s_socket, (ULONG)i);
            }
            else
            {
                ANSC_SOCKET_FD_GET(read_fd_set1, s_socket, (ULONG)i);
            }

            if ( ( (pServer->Mode & ANSC_DSTO_MODE_XSOCKET) && (s_socket == XSKT_SOCKET_INVALID_SOCKET)) ||
                 (!(pServer->Mode & ANSC_DSTO_MODE_XSOCKET) && (s_socket == ANSC_SOCKET_INVALID_SOCKET)) )
            {
                break;
            }
            else
            {
                pSocket =
                    (PANSC_DAEMON_SOCKET_TCP_OBJECT)pMyObject->GetSocketByOsocket
                        (
                            (ANSC_HANDLE)pMyObject,
                            s_socket
                        );
                /*
                 * We should make sure this socket is still valid before proceeding with the socket
                 * receive operations. For example, the peer may have already closed or reset the
                 * TCP connection while we're serving the previous socket request.
                 *
                 * 10/06/04 - It's believed this modification is slowing down the GUI and we're not
                 * seeing tangible evidence that GUI responsivenss has been improved. So we disable
                 * it for now.
                 */
                /*
                if ( pServer->Mode & ANSC_DSTO_MODE_XSOCKET )
                {
                    XSKT_SOCKET_FD_ZERO(excp_fd_set2);
                    XSKT_SOCKET_FD_SET ((XSKT_SOCKET)s_socket, excp_fd_set2);

                    timeval2.tv_sec  = 0;
                    timeval2.tv_usec = 0;

                    s_result_excp = _xskt_select(XSKT_SOCKET_FD_SETSIZE, NULL, NULL, excp_fd_set2, &timeval2);
                }
                else
                {
                    ANSC_SOCKET_FD_ZERO(excp_fd_set1);
                    ANSC_SOCKET_FD_SET (s_socket, excp_fd_set1);

                    timeval1.tv_sec  = 0;
                    timeval1.tv_usec = 0;

                    s_result_excp = _ansc_select(ANSC_SOCKET_FD_SETSIZE, NULL, NULL, excp_fd_set1, &timeval1);
                }
                */
            }

            /*
            if ( ((s_result_excp == 1                )                                             ) ||
                 ((s_result_excp == XSKT_SOCKET_ERROR) &&  (pServer->Mode & ANSC_DSTO_MODE_XSOCKET)) ||
                 ((s_result_excp == ANSC_SOCKET_ERROR) && !(pServer->Mode & ANSC_DSTO_MODE_XSOCKET)) )
            {
                if ( TRUE )
                {
                    pSocket->bBroken = TRUE;

                    pMyObject->EnableRecv((ANSC_HANDLE)pMyObject, (ANSC_HANDLE)pSocket, FALSE);
                    pMyObject->EnableSend((ANSC_HANDLE)pMyObject, (ANSC_HANDLE)pSocket, FALSE);
                }

                if ( pSocket->bTlsEnabled )
                {
                    if ( pSocket->bTlsEnabled && pSocket->bTlsConnected && !pSocket->bTlsInitializing )
                    {
                        returnStatus =
                            pWorker->Notify
                                (
                                    pWorker->hWorkerContext,
                                    (ANSC_HANDLE)pSocket,
                                    ANSC_DSTOWO_EVENT_SOCKET_ERROR,
                                    (ANSC_HANDLE)NULL
                                );
                    }
                    else
                    {
                        AnscSetEvent(&pSocket->TlsConnEvent);
                    }
                }
                else
                {
                    returnStatus =
                        pWorker->Notify
                            (
                                pWorker->hWorkerContext,
                                (ANSC_HANDLE)pSocket,
                                ANSC_DSTOWO_EVENT_SOCKET_ERROR,
                                (ANSC_HANDLE)NULL
                            );
                }

                if ( pServer->Mode & ANSC_DSTO_MODE_AUTO_CLOSE )
                {
                    pMyObject->DelSocket((ANSC_HANDLE)pMyObject, (ANSC_HANDLE)pSocket);
                }

                pMyObject->TrcCount++;

                continue;
            }
            else
            {
                pSocket =
                    (PANSC_DAEMON_SOCKET_TCP_OBJECT)pMyObject->GetSocketByOsocket
                        (
                            (ANSC_HANDLE)pMyObject,
                            s_socket
                        );
            }
            */

            if ( !pSocket )
            {
                continue;
            }
            else if ( pSocket->bTlsEnabled )
            {
#ifdef _ANSC_USE_OPENSSL_
                pMyObject->bBusy = TRUE;

                returnStatus =
                    pMyObject->Recv
                        (
                            (ANSC_HANDLE)pMyObject,
                            (ANSC_HANDLE)pSocket
                        );

                pMyObject->bBusy = FALSE;
#else
                pMyObject->bBusy = TRUE;

                returnStatus =
                    pMyObject->Recv2
                        (
                            (ANSC_HANDLE)pMyObject,
                            (ANSC_HANDLE)pSocket
                        );

                pMyObject->bBusy = FALSE;
#endif
            }
            else
            {
                pMyObject->bBusy = TRUE;

                returnStatus =
                    pMyObject->Recv
                        (
                            (ANSC_HANDLE)pMyObject,
                            (ANSC_HANDLE)pSocket
                        );

                pMyObject->bBusy = FALSE;
            }

            /*
             * Check whether 'bToBeCleaned' flag is set for this socket: if it is, we should close
             * this socket right away; otherwise, we continue the processing. WARNING!!! This new
             * change seems to incur instability in SLAP, we have to roll back to the initial
             * approach.
             */
            /*
            if ( pSocket->bToBeCleaned )
            {
                returnStatus =
                    pMyObject->DelSocket
                        (
                            (ANSC_HANDLE)pMyObject,
                            (ANSC_HANDLE)pSocket
                        );
            }
            */

            if ( !pMyObject->bStarted )
            {
                break;
            }
        }
	#endif
    }


    /******************************************************************
                GRACEFUL ROLLBACK PROCEDURES AND EXIT DOORS
    ******************************************************************/

EXIT1:

    AnscSetEvent(&pMyObject->RecvEvent);

#if !defined(_ANSC_KERNEL) || !defined(_ANSC_LINUX)
    if ( read_fd_set1 )
    {
        AnscFreeMemory(read_fd_set1);
    }

    if ( read_fd_set2 )
    {
        AnscFreeMemory(read_fd_set2);
    }

    if ( excp_fd_set1 )
    {
        AnscFreeMemory(excp_fd_set1);
    }

    if ( excp_fd_set2 )
    {
        AnscFreeMemory(excp_fd_set2);
    }
#endif

    return  ANSC_STATUS_SUCCESS;
}
ANSC_HANDLE
AdvPKIEntityExportPKCS12Handle
    (
        ANSC_HANDLE                 hThisObject,
        PCHAR                       pPassword,
        BOOLEAN                     bExportCA
    )
{
    PPKI_CLIENT_ENTITY              pThisObject  = (PPKI_CLIENT_ENTITY)hThisObject;
    PANSC_ASN1_PFX                  pPKCS12      = NULL;
    PANSC_ASN1_OBJECT               pCert;
    PSINGLE_LINK_ENTRY              pSListEntry;
    PUCHAR                          pEncoding,pKeyEncoding;
    ULONG                           length, keyLength;

    /* create the pkcs12 object */
    pPKCS12 = (PANSC_ASN1_PFX)AnscAsn1CreatePFX(NULL);

    if( pPKCS12 == NULL)
    {
        return NULL;
    }

    if( bExportCA)
    {
        /* export the CA one by one */
        pSListEntry =   AnscSListGetFirstEntry(&pThisObject->sCAList);

        while( pSListEntry != NULL)
        {
            pCert      = ACCESS_ANSC_ASN1_OBJECT(pSListEntry);
            pSListEntry = AnscSListGetNextEntry(pSListEntry);

            if( pCert != NULL)
            {
                pEncoding = pCert->GetEncodedData(pCert, &length);

                if( pEncoding != NULL)
                {
                    pPKCS12->AddCertificate
                        (
                            pPKCS12,
                            pEncoding,
                            length
                        );

                    AnscFreeMemory(pPKCS12);
                }
            }              
        }
    }

    /* export the user's certificate */
    if( pThisObject->ExportInfo
            (
                pThisObject,
                &pEncoding,
                &length,
                &pKeyEncoding,
                &keyLength
            ) == ANSC_STATUS_SUCCESS
       )
    {
        pPKCS12->AddCertAndKeyInfo(pPKCS12, pEncoding, length, pKeyEncoding, keyLength);

        if( pEncoding != NULL)
        {
            AnscFreeMemory(pEncoding);
        }

        if( pKeyEncoding != NULL)
        {
            AnscFreeMemory(pKeyEncoding);
        }
    }

    /* encrypt it */
    pPKCS12->EncryptAndSign
         (
            pPKCS12,
            pThisObject->pUtilityApi,
            pPassword
         );

    return pPKCS12;
}
ANSC_HANDLE
WebVhoGetGso
(
    ANSC_HANDLE                 hThisObject,
    ULONG                       ulSessionId,
    char*                       identifier,
    PUCHAR                      address,
    USHORT                      port
)
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PWEB_VIRTUAL_HOST_OBJECT        pMyObject    = (PWEB_VIRTUAL_HOST_OBJECT  )hThisObject;
    PWEB_SITE_MANAGER_OBJECT        pSiteManager = (PWEB_SITE_MANAGER_OBJECT  )pMyObject->hOwnerContext;
    WEB_SITE_MANAGER_PROPERTY       SMProperty;
    PWEB_VIRTUAL_HOST_PROPERTY      pProperty    = (PWEB_VIRTUAL_HOST_PROPERTY)&pMyObject->Property;
    PHTTP_HFP_INTERFACE             pHfpIf       = (PHTTP_HFP_INTERFACE       )pMyObject->hHfpIf;
    PWEB_LSM_INTERFACE              pLsmIf       = (PWEB_LSM_INTERFACE        )pMyObject->hLsmIf;
    PWEB_GENERAL_SESSION_OBJECT     pSession     = NULL;
    ULONG                           ulClientAddr = 0;
    USHORT                          usClientPort = 0;
    PSINGLE_LINK_ENTRY              pSLinkEntry  = NULL;
    ULONG                           ulHashIndex  = AnscHashUlong(ulSessionId, WEB_VHO_GSO_TABLE_SIZE);
    ULONG                           i;
    ULONG                           ulCSessCount = 0;
    PWEB_GENERAL_SESSION_OBJECT     pOldSession  = NULL;

    AnscAcquireLock(&pMyObject->GsoTableLock);

    if ( ulSessionId != 0xFFFFFFFF )
    {
        pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->GsoTable[ulHashIndex]);

        while ( pSLinkEntry )
        {
            pSession     = ACCESS_WEB_GENERAL_SESSION_OBJECT(pSLinkEntry);
            ulClientAddr = *(PULONG)pSession->GetClientAddr((ANSC_HANDLE)pSession);
            usClientPort = pSession->GetClientPort((ANSC_HANDLE)pSession);
            pSLinkEntry  = AnscSListGetNextEntry(pSLinkEntry);

            if ( pSession->GetLsmMaxAge((ANSC_HANDLE)pSession) == 0 )
            {
                /* this session is marked to be closed */
                continue;
            }

            if ( (pSession->GetSessionId((ANSC_HANDLE)pSession) == ulSessionId) &&
                    (ulClientAddr == AnscReadUlong(address)) )
            {
                char*               pLsmId       = pSession->GetLsmIdentifier((ANSC_HANDLE)pSession);

                if ( !identifier )
                {
                    if ( !pLsmId || AnscSizeOfString(pLsmId) == 0 )
                    {
                        AnscReleaseLock(&pMyObject->GsoTableLock);

                        pSession->AcquireAccess((ANSC_HANDLE)pSession);

                        return  (ANSC_HANDLE)pSession;
                    }
                    else
                    {
                        break;
                    }
                }
                else if ( AnscEqualString
                          (
                              pLsmId,
                              identifier,
                              TRUE
                          ) )
                {
                    AnscReleaseLock(&pMyObject->GsoTableLock);

                    pSession->AcquireAccess((ANSC_HANDLE)pSession);

                    return  (ANSC_HANDLE)pSession;
                }
                else
                {
                    break;
                }
            }
        }
    }
    else
    {
        for ( i = 0; i < WEB_VHO_GSO_TABLE_SIZE; i ++ )
        {
            pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->GsoTable[i]);

            while ( pSLinkEntry )
            {
                pSession     = ACCESS_WEB_GENERAL_SESSION_OBJECT(pSLinkEntry);
                ulClientAddr = *(PULONG)pSession->GetClientAddr((ANSC_HANDLE)pSession);
                usClientPort = pSession->GetClientPort((ANSC_HANDLE)pSession);
                pSLinkEntry  = AnscSListGetNextEntry(pSLinkEntry);

                if ( (ulClientAddr == AnscReadUlong(address)) && usClientPort == port )
                {
                    AnscReleaseLock(&pMyObject->GsoTableLock);

                    /* same connection */
                    pSession->AcquireAccess((ANSC_HANDLE)pSession);

                    return  (ANSC_HANDLE)pSession;
                }
            }
        }
    }

    pSiteManager->GetProperty((ANSC_HANDLE)pSiteManager, &SMProperty);

    pOldSession =
        (PWEB_GENERAL_SESSION_OBJECT)WebVhoGetOldestGso
        (
            (ANSC_HANDLE)pMyObject,
            ulSessionId,
            identifier,
            address,
            &ulCSessCount
        );

    if ( pOldSession && SMProperty.MaxSessionCountPerPeer != 0 && ulCSessCount >= SMProperty.MaxSessionCountPerPeer )
    {
        pOldSession->Terminate((ANSC_HANDLE)pOldSession);
    }

    AnscReleaseLock(&pMyObject->GsoTableLock);

    /*
     * We couldn't find a general session object for this client, we shall create a new one and
     * let the Logical Session Manager classify the client based on his/her identifier.
     */
    pSession =
        (PWEB_GENERAL_SESSION_OBJECT)pMyObject->AddGso
        (
            (ANSC_HANDLE)pMyObject,
            identifier,
            address,
            port
        );

    return  (ANSC_HANDLE)pSession;
}
ANSC_STATUS
CosaBridgingRegGetInfo
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus            = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_BRIDGING        pMyObject               = (PCOSA_DATAMODEL_BRIDGING    )hThisObject;
    PSLIST_HEADER                   pBridgeHead             = (PSLIST_HEADER               )&pMyObject->BridgeList;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoBRGHA        = (PPOAM_IREP_FOLDER_OBJECT    )pMyObject->hIrepFolderBRGHA;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoBRGBrg       = (PPOAM_IREP_FOLDER_OBJECT    )NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaContext            = (PCOSA_CONTEXT_LINK_OBJECT   )NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaContext2           = (PCOSA_CONTEXT_LINK_OBJECT   )NULL;
    PCOSA_DML_BRG_FULL_ALL          pDmlBridge              = (PCOSA_DML_BRG_FULL_ALL      )NULL;
    PCOSA_DML_BRG_FULL_ALL          pDmlBrgEntry            = (PCOSA_DML_BRG_FULL_ALL      )NULL;
    PCOSA_DML_BRG_PORT_FULL         pPort                   = (PCOSA_DML_BRG_PORT_FULL     )NULL;
    PSLAP_VARIABLE                  pSlapVariable           = (PSLAP_VARIABLE              )NULL;
    PSINGLE_LINK_ENTRY              pSLinkEntry             = (PSINGLE_LINK_ENTRY          )NULL;
    ULONG                           ulEntryCount            = 0;
    ULONG                           ulIndex                 = 0;
    ULONG                           ulInstanceNumber        = 0;
    ULONG                           ulUpperInstanceNumber   = 0;
    char*                           pFolderName             = NULL;
    char*                           pBridgeName             = NULL;
    char*                           pAlias                  = NULL;
    BOOLEAN                         found = FALSE;
    if ( !pPoamIrepFoBRGHA )
    {
        return ANSC_STATUS_FAILURE;
    }

    /* Load the newly added but not yet commited entries */

    ulEntryCount = pPoamIrepFoBRGHA->GetFolderCount((ANSC_HANDLE)pPoamIrepFoBRGHA);

    for ( ulIndex = 0; ulIndex < ulEntryCount; ulIndex++ )
    {
        pFolderName =
            pPoamIrepFoBRGHA->EnumFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoBRGHA,
                    ulIndex
                );

        if ( !pFolderName )
        {
            continue;
        }

        pPoamIrepFoBRGBrg = pPoamIrepFoBRGHA->GetFolder((ANSC_HANDLE)pPoamIrepFoBRGHA, pFolderName);

        if ( !pPoamIrepFoBRGBrg )
        {
            continue;
        }


        if ( _ansc_strstr(pFolderName, "Bridge") )
        {
            if ( TRUE )
            {
                pSlapVariable =
                    (PSLAP_VARIABLE)pPoamIrepFoBRGBrg->GetRecord
                        (
                            (ANSC_HANDLE)pPoamIrepFoBRGBrg,
                            COSA_DML_RR_NAME_Bridge_InsNum,
                            NULL
                        );

                if ( pSlapVariable )
                {
                    ulInstanceNumber = pSlapVariable->Variant.varUint32;
                    SlapFreeVariable(pSlapVariable);
                }
            }

            if ( TRUE )
            {
                pSlapVariable =
                    (PSLAP_VARIABLE)pPoamIrepFoBRGBrg->GetRecord
                        (
                            (ANSC_HANDLE)pPoamIrepFoBRGBrg,
                            COSA_DML_RR_NAME_Bridge_Alias,
                            NULL
                        );

                if ( pSlapVariable )
                {
                    pAlias = AnscCloneString(pSlapVariable->Variant.varString);
                    SlapFreeVariable(pSlapVariable);
                }
            }

            pCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));

            if ( !pCosaContext )
            {
                returnStatus = ANSC_STATUS_RESOURCES;

                goto EXIT;
            }

            pDmlBridge = (PCOSA_DML_BRG_FULL_ALL)AnscAllocateMemory(sizeof(COSA_DML_BRG_FULL_ALL));

            if ( !pDmlBridge )
            {
                AnscFreeMemory(pCosaContext);

                returnStatus = ANSC_STATUS_RESOURCES;

                goto EXIT;
            }

            AnscSListInitializeHeader(&pDmlBridge->PortList   );
            AnscSListInitializeHeader(&pDmlBridge->VLANList   );
            AnscSListInitializeHeader(&pDmlBridge->VLANPortList);

            pDmlBridge->ulNextPortInsNum = 1;
            pDmlBridge->ulNextVLANInsNum = 1;
            pDmlBridge->ulNextVLANPortInsNum = 1;
            pDmlBridge->Cfg.bAllowDelete = TRUE;
            pDmlBridge->Cfg.InstanceNumber = ulInstanceNumber;
            AnscCopyString(pDmlBridge->Cfg.Alias, pAlias);

            pCosaContext->InstanceNumber   = ulInstanceNumber;
            pCosaContext->bNew             = TRUE;
            pCosaContext->hContext         = (ANSC_HANDLE)pDmlBridge;
            pCosaContext->hParentTable     = NULL;
            pCosaContext->hPoamIrepUpperFo = (ANSC_HANDLE)pPoamIrepFoBRGHA;
            pCosaContext->hPoamIrepFo      = (ANSC_HANDLE)pPoamIrepFoBRGBrg;
            
            CosaSListPushEntryByInsNum(pBridgeHead, pCosaContext);            
        }
        else
        {
            found = FALSE;
            if ( TRUE )
            {
                pSlapVariable =
                    (PSLAP_VARIABLE)pPoamIrepFoBRGBrg->GetRecord
                        (
                            (ANSC_HANDLE)pPoamIrepFoBRGBrg,
                            COSA_DML_RR_NAME_Bridge_Upper_InsNum,
                            NULL
                        );

                if ( pSlapVariable )
                {
                    ulUpperInstanceNumber = pSlapVariable->Variant.varUint32;
                    SlapFreeVariable(pSlapVariable);
                }

                if ( ulUpperInstanceNumber != 0 )
                {
                    pSLinkEntry = AnscSListGetFirstEntry(pBridgeHead);

                    while ( pSLinkEntry )
                    {
                        pCosaContext  = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry);
                        pSLinkEntry   = AnscSListGetNextEntry(pSLinkEntry);

                        pDmlBrgEntry  = (PCOSA_DML_BRG_FULL_ALL)pCosaContext->hContext;

                        if ( pDmlBrgEntry && (pDmlBrgEntry->Cfg.InstanceNumber == ulUpperInstanceNumber) )
                        {
                            found = TRUE;
                            break;
                        }
                    }
                }
                else
                {
                    return ANSC_STATUS_FAILURE;
                }
            }

            if (found==FALSE)
            {
                //$HL 4/29/2013
                pPoamIrepFoBRGHA->EnableFileSync((ANSC_HANDLE)pPoamIrepFoBRGHA, FALSE);
                pPoamIrepFoBRGBrg->Close((ANSC_HANDLE)pPoamIrepFoBRGBrg);
        
                pPoamIrepFoBRGHA->DelFolder
                    (
                        (ANSC_HANDLE)pPoamIrepFoBRGHA, 
                        pPoamIrepFoBRGBrg->GetFolderName((ANSC_HANDLE)pPoamIrepFoBRGBrg)
                    );

                pPoamIrepFoBRGHA->EnableFileSync((ANSC_HANDLE)pPoamIrepFoBRGHA, TRUE);

                AnscFreeMemory(pPoamIrepFoBRGBrg);
                continue;
            }
            if ( TRUE )
            {
                pSlapVariable =
                    (PSLAP_VARIABLE)pPoamIrepFoBRGBrg->GetRecord
                        (
                            (ANSC_HANDLE)pPoamIrepFoBRGBrg,
                            COSA_DML_RR_NAME_Bridge_InsNum,
                            NULL
                        );

                if ( pSlapVariable )
                {
                    ulInstanceNumber = pSlapVariable->Variant.varUint32;
                    SlapFreeVariable(pSlapVariable);
                }
            }

            if ( TRUE )
            {
                pSlapVariable =
                    (PSLAP_VARIABLE)pPoamIrepFoBRGBrg->GetRecord
                        (
                            (ANSC_HANDLE)pPoamIrepFoBRGBrg,
                            COSA_DML_RR_NAME_Bridge_Alias,
                            NULL
                        );

                if ( pSlapVariable )
                {
                    pAlias = AnscCloneString(pSlapVariable->Variant.varString);
                    SlapFreeVariable(pSlapVariable);
                }
            }

            if ( _ansc_strstr(pFolderName, "Port") )
            {
                pPort = (PCOSA_DML_BRG_PORT_FULL)AnscAllocateMemory(sizeof(COSA_DML_BRG_PORT_FULL));

                if ( !pPort )
                {
                    returnStatus = ANSC_STATUS_RESOURCES;

                    goto EXIT;
                }

                pCosaContext2 = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));

                if ( !pCosaContext2 )
                {
                    AnscFreeMemory(pPort);
            
                    returnStatus = ANSC_STATUS_RESOURCES;

                    goto EXIT;
                }

                pPort->Cfg.InstanceNumber = ulInstanceNumber;
                AnscCopyString(pPort->Cfg.Alias, pAlias);
                pPort->Cfg.bAllowDelete = TRUE;
                pCosaContext2->InstanceNumber  = ulInstanceNumber;
                pCosaContext2->hContext        = (ANSC_HANDLE)pPort;
                pCosaContext2->hParentTable    = (ANSC_HANDLE)pDmlBrgEntry;
                pCosaContext2->bNew            = TRUE;
                pCosaContext2->hPoamIrepUpperFo = (ANSC_HANDLE)pPoamIrepFoBRGHA;
                pCosaContext2->hPoamIrepFo      = (ANSC_HANDLE)pPoamIrepFoBRGBrg;

                //$HL 5/1/2013
                pDmlBrgEntry->ulNextPortInsNum = ulInstanceNumber >=pDmlBrgEntry->ulNextPortInsNum ? 
                    ulInstanceNumber+1:pDmlBrgEntry->ulNextPortInsNum;
                CosaSListPushEntryByInsNum(&pDmlBrgEntry->PortList, pCosaContext2);
            }
        }
    }

EXIT:

    AnscFreeMemory(pAlias);

    return returnStatus;
}
ANSC_HANDLE
HttpScoMapWcso
    (
        ANSC_HANDLE                 hThisObject,
        char*                       host,
        USHORT                      port,
        ANSC_HANDLE                 hReqContext,
        BOOL                        bUseTls
    )
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PHTTP_SIMPLE_CLIENT_OBJECT      pMyObject    = (PHTTP_SIMPLE_CLIENT_OBJECT  )hThisObject;
    PHTTP_SIMPLE_CLIENT_PROPERTY    pProperty    = (PHTTP_SIMPLE_CLIENT_PROPERTY)&pMyObject->Property;
    PHTTP_WEBC_SESSION_OBJECT       pWebcSession = NULL;
    PSINGLE_LINK_ENTRY              pSLinkEntry  = NULL;
    ULONG                           ulHashIndex  = AnscHashString2(host, AnscSizeOfString(host), HTTP_SCO_WCSO_TABLE_SIZE);
    ULONG                           ulClientMode = pMyObject->ClientMode;
    ULONG                           ulSessFlags;

    AnscAcquireLock(&pMyObject->WcsoTableLock);

    pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->WcsoTable[ulHashIndex]);

    while ( pSLinkEntry )
    {
        pWebcSession = ACCESS_HTTP_WEBC_SESSION_OBJECT(pSLinkEntry);
        pSLinkEntry  = AnscSListGetNextEntry(pSLinkEntry);

        if ( pWebcSession->bRemoveMe )
        {
            continue;
        }

        ulSessFlags = bUseTls? HTTP_WCSO_FLAG_tlsEnabled : 0;

        if ( pMyObject->ClientMode & HTTP_SCO_MODE_XSOCKET )
        {
            ulSessFlags |= HTTP_WCSO_FLAG_xsocketEnabled;
        }

        if ( pMyObject->ClientMode & HTTP_SCO_MODE_NOTIFY_ON_ALL_CONN_ONCE )
        {
            ulSessFlags |= HTTP_WCSO_FLAG_BspNotifyOnAllConnOnce;
        }

        if ( pWebcSession->MatchServer
                (
                    (ANSC_HANDLE)pWebcSession,
                    host,
                    port,
                    ulSessFlags
                ) )
        {
            pWebcSession->AcquireAccess((ANSC_HANDLE)pWebcSession);

            if ( pWebcSession->IsReadyToRequest((ANSC_HANDLE)pWebcSession) )
            {
                ANSC_IPV4_ADDRESS   ipAddr;

                AnscReleaseLock(&pMyObject->WcsoTableLock);

                ipAddr.Value    = pMyObject->GetCurPeerAddr((ANSC_HANDLE)pMyObject);

                if ( ipAddr.Value != 0 )
                {
                    pMyObject->ResetPeerAddrPick((ANSC_HANDLE)pMyObject, ipAddr.Value);
                }

                return  (ANSC_HANDLE)pWebcSession;
            }
            else
            {
                pWebcSession->ReleaseAccess((ANSC_HANDLE)pWebcSession);
            }
        }
    }

    AnscReleaseLock(&pMyObject->WcsoTableLock);

    return  pMyObject->AddWcso
                (
                    (ANSC_HANDLE)pMyObject,
                    host,
                    port,
                    hReqContext,
                    bUseTls
                );
}