ANSC_STATUS
CosaNatRegGetNatInfo
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus      = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_NAT             pMyObject         = ( PCOSA_DATAMODEL_NAT )hThisObject;

    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoNat      = (PPOAM_IREP_FOLDER_OBJECT )pMyObject->hIrepFolderNat;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoNatPt    = (PPOAM_IREP_FOLDER_OBJECT )pMyObject->hIrepFolderNatPt;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoEnumNat  = (PPOAM_IREP_FOLDER_OBJECT )NULL;
    PCOSA_CONTEXT_PMAPPING_LINK_OBJECT     pCosaNatContext   = NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaNatPtContext   = NULL;
    PCOSA_DML_NAT_PMAPPING          pCosaNat          = NULL;
    PCOSA_DML_NAT_PTRIGGER          pCosaNatPt        = NULL;
    PSLAP_VARIABLE                  pSlapVariable     = NULL;
    ULONG                           ulEntryCount      = 0;
    ULONG                           ulIndex           = 0;
    ULONG                           uInstanceNumber   = 0;
    BOOL                            bNew              = FALSE;
    char*                           pAliasNat         = NULL;
    char*                           pFolderName       = NULL;

    CcspTraceWarning(("!!!!!! In CosaNatRegGetNatInfo !!!!!!\n"));

    if ( !pPoamIrepFoNat || !pPoamIrepFoNatPt )
    {
        CcspTraceWarning(("!!!!!! pPoamIrepFoNat: %p, pPoamIrepFoNatPt: %p !!!!!!\n", pPoamIrepFoNat, pPoamIrepFoNatPt));
        return ANSC_STATUS_FAILURE;
    }

    /* This is saved structure for nat
        *****************************************
              <Nat>
                  <1>
                       <alias>xxx</>
                       <bNew>false</>
                 </1>
                 <2>
                      <alias>xxx</>
                      <bNew>false</>
                 </2>
            </Nat>
      ****************************************************
      */

    /* enumerate Portmapping.{i} */
    ulEntryCount = pPoamIrepFoNat->GetFolderCount((ANSC_HANDLE)pPoamIrepFoNat);
    for ( ulIndex = 0; ulIndex < ulEntryCount; ulIndex++ )
    {
        /* Get i in Portmapping.{i} */
        pFolderName =
            pPoamIrepFoNat->EnumFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoNat,
                    ulIndex
                );

        if ( !pFolderName )
        {
            continue;
        }

        uInstanceNumber = _ansc_atol(pFolderName);

        if ( uInstanceNumber == 0 )
        {
            AnscFreeMemory(pFolderName);
            continue;
        }

        pPoamIrepFoEnumNat = pPoamIrepFoNat->GetFolder((ANSC_HANDLE)pPoamIrepFoNat, pFolderName);

        AnscFreeMemory(pFolderName);

        if ( !pPoamIrepFoEnumNat )
        {
            continue;
        }

        /* Get PortMapping.{i}.Alias value*/
        if ( TRUE )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoEnumNat->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumNat,
                        COSA_DML_RR_NAME_NATAlias,
                        NULL
                    );

            if ( pSlapVariable )
            {
                pAliasNat = AnscCloneString(pSlapVariable->Variant.varString);

                SlapFreeVariable(pSlapVariable);
            }
        }

        /* Get PortMapping.{i}.bNew value*/
        if ( TRUE )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoEnumNat->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumNat,
                        COSA_DML_RR_NAME_NATbNew,
                        NULL
                    );

            if ( pSlapVariable )
            {
                bNew = pSlapVariable->Variant.varBool;

                SlapFreeVariable(pSlapVariable);
            }
            else
            {
                bNew = TRUE;
            }
        }

        /* Create one entry and keep this delay_added entry */
        pCosaNat = (PCOSA_DML_NAT_PMAPPING)AnscAllocateMemory(sizeof(COSA_DML_NAT_PMAPPING));
        if ( !pCosaNat )
        {
            returnStatus = ANSC_STATUS_FAILURE;
            goto EXIT1;
        }

        /* set some default value firstly */
        NAT_PORTMAPPING_SET_DEFAULTVALUE(pCosaNat);

        /* save alias and instanceNumber */
        pCosaNat->InstanceNumber = uInstanceNumber;
        AnscCopyString( pCosaNat->Alias, pAliasNat );

        /* Create one link point */
        pCosaNatContext = (PCOSA_CONTEXT_PMAPPING_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_PMAPPING_LINK_OBJECT));
        if ( !pCosaNatContext )
        {
            returnStatus = ANSC_STATUS_FAILURE;
            goto EXIT2;
        }

        NAT_PMAPPING_INITIATION_CONTEXT(pCosaNatContext)

        pCosaNatContext->InstanceNumber = pCosaNat->InstanceNumber;
        pCosaNatContext->hContext       = (ANSC_HANDLE)pCosaNat;
        pCosaNat                        = 0;
        pCosaNatContext->bNew           = bNew;

        CosaSListPushEntryByInsNum(&pMyObject->NatPMappingList, (PCOSA_CONTEXT_LINK_OBJECT)pCosaNatContext);

        /* release some memory */
        if (pAliasNat)
        {
            AnscFreeMemory(pAliasNat);
            pAliasNat = NULL;
        }

        pPoamIrepFoEnumNat->Remove((ANSC_HANDLE)pPoamIrepFoEnumNat);
        pPoamIrepFoEnumNat = NULL;
    }

    /* This is saved structure for nat port trigger
        *****************************************
              <Nat>
                <PortTrigger>
                  <Record>NextInsNumber</Record>
                  <1>
                       <alias>xxx</>
                       <bNew>true</>
                 </1>
                 <2>
                      <alias>xxx</>
                      <bNew>true</>
                 </2>
                 </PortTrigger>
            </Nat>
      ****************************************************
      */

    /* enumerate PortTrigger.{i} */
    ulEntryCount = pPoamIrepFoNatPt->GetFolderCount((ANSC_HANDLE)pPoamIrepFoNatPt);
    CcspTraceWarning(("!!!!!! ulEntryCount for PortTrigger: %d !!!!!!\n", ulEntryCount));

    for ( ulIndex = 0; ulIndex < ulEntryCount; ulIndex++ )
    {
        /* Get i in PortTrigger.{i} */
        pFolderName =
            pPoamIrepFoNatPt->EnumFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoNatPt,
                    ulIndex
                );
        CcspTraceWarning(("!!!!!! pFolderName: %s !!!!!!\n", pFolderName));

        if ( !pFolderName )
        {
            continue;
        }

        uInstanceNumber = _ansc_atol(pFolderName);

        if ( uInstanceNumber == 0 )
        {
            AnscFreeMemory(pFolderName);
            continue;
        }

        pPoamIrepFoEnumNat = pPoamIrepFoNatPt->GetFolder((ANSC_HANDLE)pPoamIrepFoNatPt, pFolderName);

        AnscFreeMemory(pFolderName);

        if ( !pPoamIrepFoEnumNat )
        {
            continue;
        }

        /* Get PortTrigger.{i}.Alias value*/
        if ( TRUE )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoEnumNat->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumNat,
                        COSA_DML_RR_NAME_NATAlias,
                        NULL
                    );

            if ( pSlapVariable )
            {
                pAliasNat = AnscCloneString(pSlapVariable->Variant.varString);

                SlapFreeVariable(pSlapVariable);
            }
        }

        /* Get PortTrigger.{i}.bNew value*/
        if ( TRUE )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoEnumNat->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumNat,
                        COSA_DML_RR_NAME_NATbNew,
                        NULL
                    );

            if ( pSlapVariable )
            {
                bNew = pSlapVariable->Variant.varBool;

                SlapFreeVariable(pSlapVariable);
            }
            else
            {
                bNew = TRUE;
            }
        }

        /* Create one entry and keep this delay_added entry */
        pCosaNatPt = (PCOSA_DML_NAT_PTRIGGER)AnscAllocateMemory(sizeof(COSA_DML_NAT_PTRIGGER));

        if ( !pCosaNatPt )
        {
            returnStatus = ANSC_STATUS_RESOURCES;
            goto EXIT1;
        }

        /* set some default value firstly */
        COSA_DML_NAT_PTRIGGER_INIT(pCosaNatPt);

        /* save alias and instanceNumber */
        pCosaNatPt->InstanceNumber = uInstanceNumber;
        AnscCopyString( pCosaNatPt->Alias, pAliasNat );

        CcspTraceWarning(("!!!!!! pCosaNatPt->InstanceNumber: %d, pCosaNatPt->Alias: %s !!!!!!\n", pCosaNatPt->InstanceNumber, pCosaNatPt->Alias));

        /* Create one link point */
        pCosaNatPtContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));
        if ( !pCosaNatPtContext )
        {
            AnscFreeMemory(pCosaNatPt); /*RDKB-6742, CID-33206, Free unused resources after use*/
            pCosaNatPt = NULL;
            returnStatus = ANSC_STATUS_FAILURE;
            goto EXIT2;
        }

         COSA_CONTEXT_LINK_INITIATION_CONTENT(pCosaNatPtContext)

        pCosaNatPtContext->InstanceNumber = pCosaNatPt->InstanceNumber;
        pCosaNatPtContext->hContext       = (ANSC_HANDLE)pCosaNatPt;
        pCosaNatPtContext->bNew           = bNew;

        CosaSListPushEntryByInsNum(&pMyObject->NatPTriggerList, (PCOSA_CONTEXT_LINK_OBJECT)pCosaNatPtContext);

        /* release some memory */
        if (pAliasNat)
        {
            AnscFreeMemory(pAliasNat);
            pAliasNat = NULL;
        }

        pPoamIrepFoEnumNat->Remove((ANSC_HANDLE)pPoamIrepFoEnumNat);
        pPoamIrepFoEnumNat = NULL;
    }



EXIT2:
    if(pCosaNat)
        AnscFreeMemory(pCosaNat);

EXIT1:

    if(pAliasNat)
        AnscFreeMemory(pAliasNat);

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

    return returnStatus;
}
ANSC_STATUS
DslhDmagntEngage
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus           = ANSC_STATUS_SUCCESS;
    PDSLH_DATAMODEL_AGENT_OBJECT    pMyObject              = (PDSLH_DATAMODEL_AGENT_OBJECT)hThisObject;
    PANSC_ATOM_TABLE_OBJECT         pAtomFunctions         = (PANSC_ATOM_TABLE_OBJECT)pMyObject->hAtomFunctions;
    PDSLH_CPE_CONTROLLER_OBJECT     pDslhCpeController     = (PDSLH_CPE_CONTROLLER_OBJECT)pMyObject->hDslhCpeController;
    PSLAP_OBJECT_DESCRIPTOR         pObjDescriptor         = (PSLAP_OBJECT_DESCRIPTOR    )NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoRoot        = (PPOAM_IREP_FOLDER_OBJECT   )NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoProvision   = (PPOAM_IREP_FOLDER_OBJECT   )NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoCOSA        = (PPOAM_IREP_FOLDER_OBJECT   )pMyObject->hIrepFolderCOSA;

    PDSLH_MWS_INTERFACE             pDslhMwsIf             = (PDSLH_MWS_INTERFACE        )pMyObject->hDslhMwsIf;

    if ( pMyObject->bActive )
    {
        return  ANSC_STATUS_SUCCESS;
    }

    if( pDslhMwsIf != NULL)
    {
        pDslhCpeController->AddInterface(pDslhCpeController, pMyObject->hDslhMwsIf);
    }

    pMyObject->hDslhCcdIf = pDslhCpeController->GetInterfaceByName(pDslhCpeController, CCSP_CCD_INTERFACE_NAME);
    pMyObject->hDslhLcbIf = pDslhCpeController->GetInterfaceByName(pDslhCpeController, CCSP_LIBCBK_INTERFACE_NAME);

    /* register internal apis */
    if( pAtomFunctions == NULL)
    {
        pMyObject->hAtomFunctions =
            AnscCreateAtomTable
                (
                    pMyObject->hContainerContext,
                    (ANSC_HANDLE)pMyObject,
                    NULL
                );

        pAtomFunctions    = (PANSC_ATOM_TABLE_OBJECT)pMyObject->hAtomFunctions;
    }

    if( pAtomFunctions != NULL)
    {                                                                                         
        /* Register the API exported by framework */
        pMyObject->RegisterInternalApi(pMyObject, "COSANotifyValueChange",            COSANotifyValueChange);
        pMyObject->RegisterInternalApi(pMyObject, "COSANotifyDiagComplete",           COSANotifyDiagComplete);
        pMyObject->RegisterInternalApi(pMyObject, "COSAValidateHierarchyInterface",   COSAValidateHierarchyInterface);
        pMyObject->RegisterInternalApi(pMyObject, "COSAGetParamValueBool",            COSAGetParamValueBool);
        pMyObject->RegisterInternalApi(pMyObject, "COSAGetParamValueInt",             COSAGetParamValueInt);
        pMyObject->RegisterInternalApi(pMyObject, "COSAGetParamValueUlong",           COSAGetParamValueUlong);
        pMyObject->RegisterInternalApi(pMyObject, "COSAGetParamValueString",          COSAGetParamValueString);
        pMyObject->RegisterInternalApi(pMyObject, "COSAGetParamValue",                COSAGetParamValue);
        pMyObject->RegisterInternalApi(pMyObject, "COSASetParamValueBool",            COSASetParamValueBool);
        pMyObject->RegisterInternalApi(pMyObject, "COSASetParamValueInt",             COSASetParamValueInt);
        pMyObject->RegisterInternalApi(pMyObject, "COSASetParamValueUlong",           COSASetParamValueUlong);
        pMyObject->RegisterInternalApi(pMyObject, "COSASetParamValueString",          COSASetParamValueString);

        pMyObject->RegisterInternalApi(pMyObject, "COSAGetRegistryRootFolder",        COSAGetRegistryRootFolder);
        pMyObject->RegisterInternalApi(pMyObject, "COSAGetInstanceNumberByIndex",     COSAGetInstanceNumberByIndex);
        pMyObject->RegisterInternalApi(pMyObject, "COSAGetInterfaceByName",           COSAGetInterfaceByName);
        pMyObject->RegisterInternalApi(pMyObject, "COSAGetMessageBusHandle",          COSAGetMessageBusHandle);
        pMyObject->RegisterInternalApi(pMyObject, "COSARegisterCallBackAfterInitDml", COSARegisterCallBackAfterInitDml);
        pMyObject->RegisterInternalApi(pMyObject, "COSAGetSubsystemPrefix",           COSAGetSubsystemPrefix);
        pMyObject->RegisterInternalApi(pMyObject, "COSARepopulateTable",              COSARepopulateTable);
        pMyObject->RegisterInternalApi(pMyObject, "COSAGetParamValueByPathName",      COSAGetParamValueByPathName);
        pMyObject->RegisterInternalApi(pMyObject, "COSASetParamValueByPathName",      COSASetParamValueByPathName);
        pMyObject->RegisterInternalApi(pMyObject, "COSAGetInstanceNumbers",           COSAGetInstanceNumbers);

        /* Register the API  for CCSP Common Components*/
#if 0
        pMyObject->RegisterInternalApi(pMyObject, "CcspComp_GetParamUlongValue",      CcspComp_GetParamUlongValue);
        pMyObject->RegisterInternalApi(pMyObject, "CcspComp_GetParamStringValue",     CcspComp_GetParamStringValue);
#endif
        pMyObject->RegisterInternalApi(pMyObject, "CcspComp_GetBulkParamValues",      CcspComp_GetBulkParamValues);
        pMyObject->RegisterInternalApi(pMyObject, "CcspComp_SetParamBoolValue",       CcspComp_SetParamBoolValue);

        pMyObject->RegisterInternalApi(pMyObject, "CcspLog_GetParamBoolValue",        CcspLog_GetParamBoolValue);
        pMyObject->RegisterInternalApi(pMyObject, "CcspLog_GetParamUlongValue",       CcspLog_GetParamUlongValue);
        pMyObject->RegisterInternalApi(pMyObject, "CcspLog_SetParamBoolValue",        CcspLog_SetParamBoolValue);
        pMyObject->RegisterInternalApi(pMyObject, "CcspLog_SetParamUlongValue",       CcspLog_SetParamUlongValue);
        pMyObject->RegisterInternalApi(pMyObject, "CcspLog_Validate",                 CcspLog_Validate );
        pMyObject->RegisterInternalApi(pMyObject, "CcspLog_Commit",                   CcspLog_Commit );
        pMyObject->RegisterInternalApi(pMyObject, "CcspLog_Rollback",                 CcspLog_Rollback );
        pMyObject->RegisterInternalApi(pMyObject, "CcspMem_GetParamUlongValue",       CcspMem_GetParamUlongValue);
        pMyObject->RegisterInternalApi(pMyObject, "CcspLog_GetBulkParamValues",       CcspLog_GetBulkParamValues);
        pMyObject->RegisterInternalApi(pMyObject, "CcspLog_SetBulkParamValues",       CcspLog_SetBulkParamValues);

    }

    /*
     * Enroll and create PoamIrepFolder object.
     */
    if ( TRUE )
    {

        pPoamIrepFoRoot =
            (PPOAM_IREP_FOLDER_OBJECT)PoamIrepFoCreate(NULL, NULL, ""); 

        if ( !pPoamIrepFoRoot )
        {
            AnscTrace("DslhDataModelAgent: Cannot access Root Folder!!\n");

            returnStatus = ANSC_STATUS_FAILURE;

            goto  EXIT2;
        }

        pPoamIrepFoProvision =
            (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoRoot->GetFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoRoot,
                    "Provision"
                );

        if ( !pPoamIrepFoProvision )
        {
            AnscTrace("DslhDataModelAgent: Cannot access /Configuration/Provision folder!!\n");

            returnStatus = ANSC_STATUS_FAILURE;

            goto  EXIT3;
        }

        pPoamIrepFoCOSA =
            (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoProvision->GetFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoProvision,
                    COSA_IREP_FOLDER_NAME
                );

        if ( !pPoamIrepFoCOSA )
        {
            pPoamIrepFoCOSA =
                pPoamIrepFoProvision->AddFolder
                    (
                        (ANSC_HANDLE)pPoamIrepFoProvision,
                        COSA_IREP_FOLDER_NAME,
                        0
                    );
        }

        if ( !pPoamIrepFoCOSA )
        {
            AnscTrace("DslhDataModelAgent: Cannot access /Configuration/Provision/%s folder!!\n", COSA_IREP_FOLDER_NAME);

            returnStatus = ANSC_STATUS_FAILURE;

            goto  EXIT4;
        }
        else
        {
            pMyObject->hIrepFolderCOSA = (ANSC_HANDLE)pPoamIrepFoCOSA;
        }
    }

    pMyObject->bActive = TRUE;

    returnStatus = ANSC_STATUS_SUCCESS;


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

EXIT4:

    if ( pPoamIrepFoProvision )
    {
        pPoamIrepFoProvision->Remove((ANSC_HANDLE)pPoamIrepFoProvision);
    }

EXIT3:

    if ( pPoamIrepFoRoot )
    {
        pPoamIrepFoRoot->Remove((ANSC_HANDLE)pPoamIrepFoRoot);
    }

EXIT2:

    return  returnStatus;
}
ANSC_STATUS
CosaNatInitialize
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus     = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_NAT             pMyObject        = (PCOSA_DATAMODEL_NAT)hThisObject;
    PSLAP_VARIABLE                  pSlapVariable    = (PSLAP_VARIABLE             )NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoCOSA  = NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoNat   = NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoNatPt = NULL;

    /* Call Initiation */
    returnStatus = CosaDmlNatInit(NULL, NULL, CosaNatGen);
    if ( returnStatus != ANSC_STATUS_SUCCESS )
    {
        return returnStatus;
    }

    /* Initiation all functions */
    AnscSListInitializeHeader( &pMyObject->NatPMappingList );
    AnscSListInitializeHeader( &pMyObject->NatPTriggerList );
    pMyObject->MaxInstanceNumber        = 0;
    pMyObject->ulPtNextInstanceNumber   = 1;
    pMyObject->PreviousVisitTime        = 0;

    /*Create NAT folder in configuration */
    pPoamIrepFoCOSA = (PPOAM_IREP_FOLDER_OBJECT)g_GetRegistryRootFolder(g_pDslhDmlAgent);

    if ( !pPoamIrepFoCOSA )
    {
        returnStatus = ANSC_STATUS_FAILURE;

        goto  EXIT;
    }

    pPoamIrepFoNat =
        (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoCOSA->GetFolder
            (
                (ANSC_HANDLE)pPoamIrepFoCOSA,
                COSA_IREP_FOLDER_NAME_NAT
            );

    if ( !pPoamIrepFoNat )
    {
        pPoamIrepFoCOSA->EnableFileSync((ANSC_HANDLE)pPoamIrepFoCOSA, FALSE);

        pPoamIrepFoNat =
            pPoamIrepFoCOSA->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoCOSA,
                    COSA_IREP_FOLDER_NAME_NAT,
                    0
                );

        pPoamIrepFoCOSA->EnableFileSync((ANSC_HANDLE)pPoamIrepFoCOSA, TRUE);
    }

    if ( !pPoamIrepFoNat )
    {
        returnStatus = ANSC_STATUS_FAILURE;

        goto  EXIT;
    }
    else
    {
        pMyObject->hIrepFolderNat = (ANSC_HANDLE)pPoamIrepFoNat;
    }

    pPoamIrepFoNatPt =
        (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoNat->GetFolder
            (
                (ANSC_HANDLE)pPoamIrepFoNat,
                COSA_IREP_FOLDER_NAME_PORTTRIGGER
            );

    if ( !pPoamIrepFoNatPt )
    {
        /* pPoamIrepFoCOSA->EnableFileSync((ANSC_HANDLE)pPoamIrepFoCOSA, FALSE); */

        pPoamIrepFoNatPt =
            pPoamIrepFoCOSA->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoNat,
                    COSA_IREP_FOLDER_NAME_PORTTRIGGER,
                    0
                );

        /* pPoamIrepFoCOSA->EnableFileSync((ANSC_HANDLE)pPoamIrepFoCOSA, TRUE); */
    }

    if ( !pPoamIrepFoNatPt )
    {
        returnStatus = ANSC_STATUS_FAILURE;

        goto  EXIT;
    }
    else
    {
        pMyObject->hIrepFolderNatPt = (ANSC_HANDLE)pPoamIrepFoNatPt;
    }

    /* Retrieve the next instance number for Port Trigger */

    if ( TRUE )
    {
        if ( pPoamIrepFoNatPt )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoNatPt->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoNatPt,
                        COSA_DML_RR_NAME_NATNextInsNumber,
                        NULL
                    );

            if ( pSlapVariable )
            {
                pMyObject->ulPtNextInstanceNumber = pSlapVariable->Variant.varUint32;

                SlapFreeVariable(pSlapVariable);
            }
        }
    }

    CosaDmlNatGetLanIP(NULL);

    /* Sync with backend */
    CosaDmlNatGetDmz(NULL, &pMyObject->Dmz);

    CosaNatSyncPortTrigger((ANSC_HANDLE)pMyObject);

    /* We need get NextInstanceNumber from backend. By the way, the whole tree
            was created. Moreover, we also need get delay-added entry and put them
            into our tree. */
    CosaNatRegGetNatInfo((ANSC_HANDLE)pMyObject);

EXIT:

    return returnStatus;
}
ANSC_STATUS
CosaDdnsInitialize
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus    = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_DDNS            pMyObject       = (PCOSA_DATAMODEL_DDNS     )hThisObject;
    PSLIST_HEADER                   pListHead       = (PSLIST_HEADER            )&pMyObject->ContextHead;
    PCOSA_DML_DDNS_CFG              pDdnsCfg        = (PCOSA_DML_DDNS_CFG       )NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaContext    = (PCOSA_CONTEXT_LINK_OBJECT)NULL;
    PCOSA_DML_DDNS_SERVICE          pDdnsService    = (PCOSA_DML_DDNS_SERVICE   )NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoCOSA = (PPOAM_IREP_FOLDER_OBJECT )NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoDdns = (PPOAM_IREP_FOLDER_OBJECT )NULL;
    PSLAP_VARIABLE                  pSlapVariable   = (PSLAP_VARIABLE           )NULL;
    ULONG                           ulServiceCount  = 0;
    ULONG                           ulIndex         = 0;
    
    returnStatus = CosaDmlDdnsInit(NULL, NULL);

    if ( returnStatus != ANSC_STATUS_SUCCESS )
    {
        return returnStatus;
    }

    /* Initiation all functions */
    pMyObject->ulNextInstance      = 1;

    AnscSListInitializeHeader(&pMyObject->ContextHead);

    pDdnsCfg = AnscAllocateMemory(sizeof(COSA_DML_DDNS_CFG));

    if ( !pDdnsCfg )
    {
        CcspTraceWarning(("X_CISCO_COM_DDNS Resource allocation error\n"));

        return ANSC_STATUS_RESOURCES;
    }

    returnStatus = CosaDmlDdnsGetConfig(NULL, pDdnsCfg);

    if ( returnStatus != ANSC_STATUS_SUCCESS )
    {
        goto EXIT1;
    }

    pMyObject->DdnsConfig.bEnabled = pDdnsCfg->bEnabled;

    pMyObject->hIrepFolderCOSA = g_GetRegistryRootFolder(g_pDslhDmlAgent);

    pPoamIrepFoCOSA = (PPOAM_IREP_FOLDER_OBJECT)pMyObject->hIrepFolderCOSA;

    if ( !pPoamIrepFoCOSA )
    {
        returnStatus = ANSC_STATUS_FAILURE;

        goto  EXIT1;
    }

    pPoamIrepFoDdns = 
        (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoCOSA->GetFolder
            (
                (ANSC_HANDLE)pPoamIrepFoCOSA,
                COSA_IREP_FOLDER_NAME_DDNS
            );

    if ( !pPoamIrepFoDdns )
    {
        pPoamIrepFoDdns =
            pPoamIrepFoCOSA->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoCOSA,
                    COSA_IREP_FOLDER_NAME_DDNS,
                    0
                );
    }

    if ( !pPoamIrepFoDdns )
    {
        returnStatus = ANSC_STATUS_FAILURE;

        goto  EXIT1;
    }
    else
    {
        pMyObject->hIrepFolderDdns = (ANSC_HANDLE)pPoamIrepFoDdns;
    }

    /* Retrieve Next Instance Number */

    if ( TRUE )
    {
        pSlapVariable =
            (PSLAP_VARIABLE)pPoamIrepFoDdns->GetRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoDdns,
                    COSA_DML_RR_NAME_DdnsServiceNextInsNumber,
                    NULL
                );

        if ( pSlapVariable )
        {
            pMyObject->ulNextInstance = pSlapVariable->Variant.varUint32;

            SlapFreeVariable(pSlapVariable);
        }
    }

    /* Initialize middle layer */

    ulServiceCount = CosaDmlDdnsGetNumberOfServices(NULL);

    for ( ulIndex = 0; ulIndex < ulServiceCount; ulIndex++ )
    {
        pDdnsService = (PCOSA_DML_DDNS_SERVICE)AnscAllocateMemory(sizeof(COSA_DML_DDNS_SERVICE));

        if ( !pDdnsService )
        {
            returnStatus = ANSC_STATUS_RESOURCES;

            goto EXIT1;
        }

        returnStatus = CosaDmlDdnsGetService(NULL, ulIndex, pDdnsService);

        if ( returnStatus == ANSC_STATUS_SUCCESS )
        {
            pCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));

            if ( !pCosaContext )
            {
                returnStatus = ANSC_STATUS_RESOURCES;

                goto EXIT2;
            }

            if ( pDdnsService->InstanceNumber != 0 )
            {
                pCosaContext->InstanceNumber = pDdnsService->InstanceNumber;

                if ( pMyObject->ulNextInstance <= pDdnsService->InstanceNumber )
                {
                    pMyObject->ulNextInstance = pDdnsService->InstanceNumber + 1;

                    if ( pMyObject->ulNextInstance == 0 )
                    {
                        pMyObject->ulNextInstance = 1;
                    }
                }  
            }
            else
            {
                pDdnsService->InstanceNumber = pCosaContext->InstanceNumber = pMyObject->ulNextInstance;

                pMyObject->ulNextInstance++;

                if ( pMyObject->ulNextInstance == 0 )
                {
                    pMyObject->ulNextInstance = 1;
                }

                /* Generate Alias */
                _ansc_sprintf(pDdnsService->Alias, "DdnsService%d", pCosaContext->InstanceNumber);

                returnStatus = 
                    CosaDmlDdnsServiceSetValues
                        (
                            NULL, 
                            ulIndex, 
                            pCosaContext->InstanceNumber, 
                            pDdnsService->Alias
                        );

                if ( returnStatus != ANSC_STATUS_SUCCESS )
                {
                    CcspTraceWarning(("!!! CosaDmlDdnsServiceSetValues index: %d-- fail !!!\n", ulIndex));
                    
                    AnscFreeMemory(pDdnsService);
                    AnscFreeMemory(pCosaContext);

                    continue;
                }
            }

            pCosaContext->hContext     = (ANSC_HANDLE)pDdnsService;
            pCosaContext->hParentTable = NULL;
            pCosaContext->bNew         = FALSE;

            CosaSListPushEntryByInsNum(pListHead, pCosaContext);
        }
    }

    /* Load the newly added but not yet committed entries, if exist */

    CosaDdnsRegGetDdnsInfo((ANSC_HANDLE)pMyObject);

    goto EXIT1;

EXIT2:

    AnscFreeMemory(pDdnsService);

EXIT1:

    AnscFreeMemory(pDdnsCfg);

    return returnStatus;
}
ANSC_STATUS
CosaDdnsRegGetDdnsInfo
    (
        ANSC_HANDLE                 hThisObject
    )
{
    PCOSA_DATAMODEL_DDNS            pMyObject         = (PCOSA_DATAMODEL_DDNS     )hThisObject;
    PSLIST_HEADER                   pListHead         = (PSLIST_HEADER            )&pMyObject->ContextHead;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoDdns   = (PPOAM_IREP_FOLDER_OBJECT )pMyObject->hIrepFolderDdns;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoDdnsSp = (PPOAM_IREP_FOLDER_OBJECT )NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaContext      = (PCOSA_CONTEXT_LINK_OBJECT)NULL;
    PCOSA_DML_DDNS_SERVICE          pDdnsService      = (PCOSA_DML_DDNS_SERVICE   )NULL;
    PSINGLE_LINK_ENTRY              pSLinkEntry       = (PSINGLE_LINK_ENTRY       )NULL;
    PSLAP_VARIABLE                  pSlapVariable     = (PSLAP_VARIABLE           )NULL;
    ULONG                           ulEntryCount      = 0;
    ULONG                           ulIndex           = 0;
    ULONG                           ulInstanceNumber  = 0;
    char*                           pFolderName       = NULL;
    char*                           pAlias            = NULL;

    if ( !pPoamIrepFoDdns )
    {
        return ANSC_STATUS_FAILURE;
    }

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

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

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

        if ( !pFolderName )
        {
            continue;
        }

        pPoamIrepFoDdnsSp = pPoamIrepFoDdns->GetFolder((ANSC_HANDLE)pPoamIrepFoDdns, pFolderName);

        AnscFreeMemory(pFolderName);

        if ( !pPoamIrepFoDdnsSp )
        {
            continue;
        }

        if ( TRUE )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoDdnsSp->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoDdnsSp,
                        COSA_DML_RR_NAME_DdnsServiceInsNum,
                        NULL
                    );

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

                SlapFreeVariable(pSlapVariable);
            }
        }

        if ( TRUE )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoDdnsSp->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoDdnsSp,
                        COSA_DML_RR_NAME_DdnsServiceAlias,
                        NULL
                    );

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

                SlapFreeVariable(pSlapVariable);
            }

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

        pPoamIrepFoDdnsSp->Remove((ANSC_HANDLE)pPoamIrepFoDdnsSp);

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

        if ( !pCosaContext )
        {
            AnscFreeMemory(pAlias);

            return ANSC_STATUS_RESOURCES;
        }

        pDdnsService = (PCOSA_DML_DDNS_SERVICE)AnscAllocateMemory(sizeof(COSA_DML_DDNS_SERVICE));

        if ( !pDdnsService )
        {
            AnscFreeMemory(pCosaContext);
            AnscFreeMemory(pAlias);

            return ANSC_STATUS_RESOURCES;
        }

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

        AnscFreeMemory(pAlias);

        pCosaContext->InstanceNumber   = ulInstanceNumber;
        pCosaContext->bNew             = TRUE;
        pCosaContext->hContext         = (ANSC_HANDLE)pDdnsService;
        pCosaContext->hParentTable     = NULL;
        pCosaContext->hPoamIrepUpperFo = (ANSC_HANDLE)pPoamIrepFoDdns;
        pCosaContext->hPoamIrepFo      = (ANSC_HANDLE)pPoamIrepFoDdnsSp;

        CosaSListPushEntryByInsNum(pListHead, pCosaContext);    
    }

    return ANSC_STATUS_SUCCESS;
}
ANSC_STATUS
CosaUsersInitialize
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus      = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_USERS           pMyObject         = (PCOSA_DATAMODEL_USERS)hThisObject;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoCOSA   = NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoUser   = NULL;
 
    /* We need call the initiation function of backend firstly */
    returnStatus = CosaDmlUserInit( NULL, NULL );
    if ( returnStatus != ANSC_STATUS_SUCCESS )
    {
        return returnStatus;
    }

    /* Initiation all functions */
    AnscSListInitializeHeader( &pMyObject->UserList );
    pMyObject->maxInstanceOfUser    = 0;
    pMyObject->hIrepFolderUser      = NULL;
    AnscZeroMemory(pMyObject->AliasOfUser, sizeof(pMyObject->AliasOfUser));

    /*We need to get Instance Info from cosa configuration*/
    pPoamIrepFoCOSA = (PPOAM_IREP_FOLDER_OBJECT)g_GetRegistryRootFolder(g_pDslhDmlAgent);

    if ( !pPoamIrepFoCOSA )
    {
        returnStatus = ANSC_STATUS_FAILURE;

        goto  EXIT;
    }

    pPoamIrepFoUser = 
        (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoCOSA->GetFolder
            (
                (ANSC_HANDLE)pPoamIrepFoCOSA,
                COSA_IREP_FOLDER_NAME_USER
            );

    if ( !pPoamIrepFoUser )
    {
        pPoamIrepFoCOSA->EnableFileSync((ANSC_HANDLE)pPoamIrepFoCOSA, FALSE);
    
        pPoamIrepFoUser =
            pPoamIrepFoCOSA->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoCOSA,
                    COSA_IREP_FOLDER_NAME_USER,
                    0
                );

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

    }

    if ( !pPoamIrepFoUser )
    {
        returnStatus = ANSC_STATUS_FAILURE;

        goto  EXIT;
    }
    else
    {
        pMyObject->hIrepFolderUser = (ANSC_HANDLE)pPoamIrepFoUser;
    }

    /* We need get NextInstanceNumber from backend. By the way, the whole tree 
            was created. Moreover, we also need get delay-added entry and put them
            into our tree. */
    CosaUsersRegGetUserInfo((ANSC_HANDLE)pMyObject);

    /* Firstly we create the whole system from backend */
    CosaUsersBackendGetUserInfo((ANSC_HANDLE)pMyObject);

EXIT:
    
    return returnStatus;

}
ANSC_STATUS
CosaUsersRegGetUserInfo
    (
        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;
    
    PSLAP_VARIABLE                  pSlapVariable     = NULL;
    ULONG                           ulEntryCount      = 0;
    ULONG                           ulIndex           = 0;
    ULONG                           uInstanceNumber   = 0;
    BOOL                            bNew              = FALSE;
    char*                           pAliasUser        = NULL;
    char*                           pFolderName       = NULL;


    if ( !pPoamIrepFoUser )
    {
        return ANSC_STATUS_FAILURE;
    }

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

    /* Get Maximum number */
    if ( TRUE )
    {
        pSlapVariable =
            (PSLAP_VARIABLE)pPoamIrepFoUser->GetRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoUser,
                    COSA_DML_RR_NAME_UserNextInsNunmber,
                    NULL
                );

        if ( pSlapVariable )
        {
            pMyObject->maxInstanceOfUser = pSlapVariable->Variant.varUint32;

            SlapFreeVariable(pSlapVariable);
        }
    }

    /* enumerate user.{i} */
    ulEntryCount = pPoamIrepFoUser->GetFolderCount((ANSC_HANDLE)pPoamIrepFoUser);
    for ( ulIndex = 0; ulIndex < ulEntryCount; ulIndex++ )
    {
        /* Get i in user.{i} */
        pFolderName =
            pPoamIrepFoUser->EnumFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoUser,
                    ulIndex
                );

        if ( !pFolderName )
        {
            continue;
        }

        uInstanceNumber = _ansc_atol(pFolderName);

        if ( uInstanceNumber == 0 )
        {
            AnscFreeMemory(pFolderName);
            continue;
        }

        pPoamIrepFoEnumUser = pPoamIrepFoUser->GetFolder((ANSC_HANDLE)pPoamIrepFoUser, pFolderName);

        AnscFreeMemory(pFolderName);

        if ( !pPoamIrepFoEnumUser )
        {
            continue;
        }

        /* Get user.{i}.Username value*/
        if ( TRUE )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoEnumUser->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumUser,
                        COSA_DML_RR_NAME_UserAlias,
                        NULL
                    );

            if ( pSlapVariable )
            {
                pAliasUser = AnscCloneString(pSlapVariable->Variant.varString);

                SlapFreeVariable(pSlapVariable);
            }
        }

        /* Get user.{i}.bNew value*/
        if ( TRUE )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoEnumUser->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumUser,
                        COSA_DML_RR_NAME_UserbNew,
                        NULL
                    );

            if ( pSlapVariable )
            {
                bNew = pSlapVariable->Variant.varBool;

                SlapFreeVariable(pSlapVariable);
            }
            else
            {
                bNew = TRUE;
            }
        }

        /* Create one entry and keep this delay_added entry */
        pCosaUser = (PCOSA_DML_USER)AnscAllocateMemory(sizeof(COSA_DML_USER));
        if ( !pCosaUser )
        {
            returnStatus = ANSC_STATUS_FAILURE;            
            goto EXIT1;
        }

        /* set some default value firstly */
        USERS_USER_SET_DEFAULTVALUE(pCosaUser);

        /* save alias and instanceNumber */
        pCosaUser->InstanceNumber = uInstanceNumber;
        AnscCopyString( pCosaUser->Username, pAliasUser );

        /* Create one link point */
        pCosaUserContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));
        if ( !pCosaUserContext )
        {
            returnStatus = ANSC_STATUS_FAILURE;
            goto EXIT2;
        }

        COSA_CONTEXT_LINK_INITIATION_CONTENT(pCosaUserContext)

        pCosaUserContext->InstanceNumber = uInstanceNumber;
        pCosaUserContext->hContext       = (ANSC_HANDLE)pCosaUser;
        pCosaUser                        = 0;
        pCosaUserContext->bNew           = bNew;

        CosaSListPushEntryByInsNum(&pMyObject->UserList, (PCOSA_CONTEXT_LINK_OBJECT)pCosaUserContext);

        /* release some memory */
        if (pAliasUser)
        {
            AnscFreeMemory(pAliasUser);
            pAliasUser = NULL;
        }
        
        pPoamIrepFoEnumUser->Remove((ANSC_HANDLE)pPoamIrepFoEnumUser);
        pPoamIrepFoEnumUser = NULL;
    }


    
EXIT2:
    if(pCosaUser)
        AnscFreeMemory(pCosaUser);
        
EXIT1:
    
    if(pAliasUser)
        AnscFreeMemory(pAliasUser);
        
    if ( pPoamIrepFoEnumUser )
        pPoamIrepFoEnumUser->Remove((ANSC_HANDLE)pPoamIrepFoEnumUser);

    return returnStatus;
}
Example #8
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;
}
Example #9
0
ANSC_STATUS
CosaRARegAddInfo
    (
        ANSC_HANDLE                 hThisObject,
        char*                       pNextInsNumName,
        ULONG                       ulNextInsNum,
        char*                       pPreffix,
        ULONG                       ulUpperInsNum,
        char*                       pAlias,
        ANSC_HANDLE                 hCosaContext
    )
{
    ANSC_STATUS                     returnStatus      = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_RA              pMyObject         = (PCOSA_DATAMODEL_RA )hThisObject;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaContext      = (PCOSA_CONTEXT_LINK_OBJECT)hCosaContext;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoRAIF   = (PPOAM_IREP_FOLDER_OBJECT )pMyObject->hIrepFolderRAInterface;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoUpper  = (PPOAM_IREP_FOLDER_OBJECT )pCosaContext->hPoamIrepUpperFo;  
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFo       = (PPOAM_IREP_FOLDER_OBJECT )NULL;
    PSLAP_VARIABLE                  pSlapVariable     = (PSLAP_VARIABLE           )NULL;
    char                            FolderName[32]    = {0};

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

    if ( TRUE )
    {
        SlapAllocVariable(pSlapVariable);

        if ( !pSlapVariable )
        {
            returnStatus = ANSC_STATUS_RESOURCES;

            goto  EXIT1;
        }
    }

    _ansc_sprintf(FolderName, "%s%d", pNextInsNumName, (int)ulUpperInsNum);

    if ( TRUE )
    {
        pPoamIrepFo = (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoRAIF->GetFolder
                        (
                            (ANSC_HANDLE)pPoamIrepFoRAIF,
                            FolderName
                        );

        if ( !pPoamIrepFo )
        {
            pPoamIrepFo = pPoamIrepFoRAIF->AddFolder
                            (
                                (ANSC_HANDLE)pPoamIrepFoRAIF,
                                FolderName,
                                0
                            );
        }
    }

    if ( TRUE )
    {
        returnStatus = pPoamIrepFo->DelRecord
                        (
                            (ANSC_HANDLE)pPoamIrepFo,
                            pNextInsNumName
                        );

        pSlapVariable->Syntax            = SLAP_VAR_SYNTAX_uint32;
        pSlapVariable->Variant.varUint32 = ulNextInsNum;

        returnStatus = pPoamIrepFo->AddRecord
                        (
                            (ANSC_HANDLE)pPoamIrepFo,
                            pNextInsNumName,
                            SYS_REP_RECORD_TYPE_UINT,
                            SYS_RECORD_CONTENT_DEFAULT,
                            pSlapVariable,
                            0
                        );

        SlapCleanVariable(pSlapVariable);
        SlapInitVariable (pSlapVariable);
    }

    pPoamIrepFo->Remove((ANSC_HANDLE)pPoamIrepFo);
    pPoamIrepFo = NULL;

    if ( TRUE )
    {
        _ansc_sprintf(FolderName, "%s%d%d", pPreffix, (int)ulUpperInsNum, (int)pCosaContext->InstanceNumber);

        pPoamIrepFo = pPoamIrepFoUpper->AddFolder
                        (
                            (ANSC_HANDLE)pPoamIrepFoUpper,
                            FolderName,
                            0
                        );

        if ( !pPoamIrepFo )
        {
            returnStatus = ANSC_STATUS_FAILURE;

            goto  EXIT1;
        }

        if ( 0 != ulUpperInsNum )
        {
            pSlapVariable->Syntax            = SLAP_VAR_SYNTAX_uint32;
            pSlapVariable->Variant.varUint32 = ulUpperInsNum;

            returnStatus = pPoamIrepFo->AddRecord
                            (
                                (ANSC_HANDLE)pPoamIrepFo,
                                COSA_DML_RR_NAME_RAIF_Upper_InsNum,
                                SYS_REP_RECORD_TYPE_UINT,
                                SYS_RECORD_CONTENT_DEFAULT,
                                pSlapVariable,
                                0
                            );
      
            SlapCleanVariable(pSlapVariable);
            SlapInitVariable (pSlapVariable);
        }

        if ( TRUE )
        {
            pSlapVariable->Syntax            = SLAP_VAR_SYNTAX_uint32;
            pSlapVariable->Variant.varUint32 = pCosaContext->InstanceNumber;

            returnStatus = pPoamIrepFo->AddRecord
                            (
                                (ANSC_HANDLE)pPoamIrepFo,
                                COSA_DML_RR_NAME_RAIF_InsNum,
                                SYS_REP_RECORD_TYPE_UINT,
                                SYS_RECORD_CONTENT_DEFAULT,
                                pSlapVariable,
                                0
                            );

            SlapCleanVariable(pSlapVariable);
            SlapInitVariable (pSlapVariable);
        }

        if ( TRUE )
        {
            pSlapVariable->Syntax            = SLAP_VAR_SYNTAX_string;
            pSlapVariable->Variant.varString = AnscCloneString(pAlias);

            returnStatus = pPoamIrepFo->AddRecord
                            (
                                (ANSC_HANDLE)pPoamIrepFo,
                                COSA_DML_RR_NAME_RAIF_Alias,
                                SYS_REP_RECORD_TYPE_ASTR,
                                SYS_RECORD_CONTENT_DEFAULT,
                                pSlapVariable,
                                0
                            );

            SlapCleanVariable(pSlapVariable);
            SlapInitVariable (pSlapVariable);
        }

        pCosaContext->hPoamIrepFo = (ANSC_HANDLE)pPoamIrepFo;
    }

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

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

    return returnStatus;
}
ANSC_STATUS
CosaNeighdiscRegGetInfo

    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus    = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_NEIGHDISC       pMyObject       = (PCOSA_DATAMODEL_NEIGHDISC)hThisObject;
    PSLIST_HEADER                   pNeighdiscIFHead       = (PSLIST_HEADER)&pMyObject->InterfaceList;
    PCOSA_DML_NEIGHDISC_IF_FULL     pNeighdiscInterface    = (PCOSA_DML_NEIGHDISC_IF_FULL)NULL;
    PCOSA_DML_NEIGHDISC_IF_FULL     pNeighdiscEntry        = (PCOSA_DML_NEIGHDISC_IF_FULL)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        pPoamIrepFoNeighdiscHA = (PPOAM_IREP_FOLDER_OBJECT)pMyObject->hIrepFolderNeighdiscInterfaceHA;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoNeighdiscIF = (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 ( !pPoamIrepFoNeighdiscHA )
    {
        return ANSC_STATUS_FAILURE;
    }

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

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

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

        if ( !pFolderName )
        {
            continue;
        }

        pPoamIrepFoNeighdiscIF = (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoNeighdiscHA->GetFolder
            (
                (ANSC_HANDLE)pPoamIrepFoNeighdiscHA, 
                pFolderName
            );

        if ( !pPoamIrepFoNeighdiscIF )
        {
            continue;
        }

        if ( _ansc_strstr(pFolderName, COSA_DML_RR_NAME_NeighdiscIF_Prefix) )
        {

            pSlapVariable = (PSLAP_VARIABLE)pPoamIrepFoNeighdiscIF->GetRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoNeighdiscIF,
                    COSA_DML_RR_NAME_NeighdiscIF_InsNum,
                    NULL
                );

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

            pSlapVariable = (PSLAP_VARIABLE)pPoamIrepFoNeighdiscIF->GetRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoNeighdiscIF,
                    COSA_DML_RR_NAME_NeighdiscIF_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;
            }

            pNeighdiscInterface = (PCOSA_DML_NEIGHDISC_IF_FULL)AnscAllocateMemory(sizeof(COSA_DML_NEIGHDISC_IF_FULL));

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

            pNeighdiscInterface->Cfg.InstanceNumber = ulInstanceNumber;
            AnscCopyString(pNeighdiscInterface->Cfg.Alias, pAlias);

            pCosaContext->InstanceNumber   = ulInstanceNumber;
            pCosaContext->bNew             = TRUE;
            pCosaContext->hContext         = (ANSC_HANDLE)pNeighdiscInterface;
            pCosaContext->hParentTable     = NULL;
            pCosaContext->hPoamIrepUpperFo = (ANSC_HANDLE)pPoamIrepFoNeighdiscHA;
            pCosaContext->hPoamIrepFo      = (ANSC_HANDLE)pPoamIrepFoNeighdiscIF;
            
            CosaSListPushEntryByInsNum(pNeighdiscIFHead, pCosaContext);
        }
    
        if ( pAlias )
        {
            AnscFreeMemory(pAlias);
            pAlias = NULL;
        }

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

EXIT:

    if ( pAlias )
    {
        AnscFreeMemory(pAlias);
    }

    return returnStatus;
}
Example #11
0
ANSC_STATUS
CosaRAInitialize
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus    = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_RA              pMyObject       = (PCOSA_DATAMODEL_RA)hThisObject;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoCOSA = (PPOAM_IREP_FOLDER_OBJECT)NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoRAIF = (PPOAM_IREP_FOLDER_OBJECT)NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoRAHA = (PPOAM_IREP_FOLDER_OBJECT)NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoNextIns 
                                                    = (PPOAM_IREP_FOLDER_OBJECT)NULL;
    PSLAP_VARIABLE                  pSlapVariable   = (PSLAP_VARIABLE          )NULL;
    PCOSA_DML_RA_IF_FULL2           pRAInterface    = (PCOSA_DML_RA_IF_FULL2   )NULL;
    PCOSA_DML_RA_OPTION             pRAOption       = (PCOSA_DML_RA_OPTION     )NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaContext    = (PCOSA_CONTEXT_LINK_OBJECT)NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pSubCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)NULL;
    char                            FolderName[32]  = {0};
    ULONG                           ulEntryCount    = 0;
    ULONG                           ulIndex         = 0;
    ULONG                           ulSubEntryCount = 0;
    ULONG                           ulSubIndex      = 0;

    CosaDmlRAInit(NULL, NULL);

    /* Initiation all functions */
    pMyObject->ulInterfaceCount                = 0;
    pMyObject->ulNextInterfaceInsNum           = 1;
    
    AnscSListInitializeHeader(&pMyObject->InterfaceList);

    pMyObject->hIrepFolderCOSA = g_GetRegistryRootFolder(g_pDslhDmlAgent);

    pPoamIrepFoCOSA = (PPOAM_IREP_FOLDER_OBJECT)pMyObject->hIrepFolderCOSA;
    
    if ( !pPoamIrepFoCOSA )
    {
        returnStatus = ANSC_STATUS_FAILURE;
        
        goto  EXIT;
    }

    pPoamIrepFoRAIF = (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoCOSA->GetFolder
                        (
                            (ANSC_HANDLE)pPoamIrepFoCOSA,
                            COSA_IREP_FOLDER_NAME_RAIF
                        );

    if ( !pPoamIrepFoRAIF )
    {
        pPoamIrepFoRAIF = pPoamIrepFoCOSA->AddFolder
                            (
                                (ANSC_HANDLE)pPoamIrepFoCOSA,
                                COSA_IREP_FOLDER_NAME_RAIF,
                                0
                            );
    }

    if ( !pPoamIrepFoRAIF )
    {
        returnStatus = ANSC_STATUS_FAILURE;
        
        goto  EXIT;
    }
    else
    {        
        pMyObject->hIrepFolderRAInterface = (ANSC_HANDLE)pPoamIrepFoRAIF;
    }

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

    if ( !pPoamIrepFoRAHA )
    {
        pPoamIrepFoRAHA = pPoamIrepFoRAIF->AddFolder
                            (
                                (ANSC_HANDLE)pPoamIrepFoRAIF,
                                COSA_IREP_FOLDER_NAME_RAIF_HA,
                                0
                            );
    }

    if ( !pPoamIrepFoRAHA )
    {
        returnStatus = ANSC_STATUS_FAILURE;
        
        goto  EXIT;
    }
    else
    {
        pMyObject->hIrepFolderRAInterfaceHA = (ANSC_HANDLE)pPoamIrepFoRAHA;
    }

    /* Retrieve the next Instance Number for RA interface */
    
    if ( TRUE )
    {
        _ansc_sprintf
        (
            FolderName, 
            "%s%d", 
            COSA_DML_RR_NAME_RAIF_NextInsNum,
            0
        );
        
        pPoamIrepFoNextIns = (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoRAIF->GetFolder
                                (
                                    (ANSC_HANDLE)pPoamIrepFoRAIF,
                                    FolderName
                                );

        AnscZeroMemory(FolderName, 32);

        if ( pPoamIrepFoNextIns )
        {
            pSlapVariable = (PSLAP_VARIABLE)pPoamIrepFoNextIns->GetRecord
                                (
                                    (ANSC_HANDLE)pPoamIrepFoNextIns,
                                    COSA_DML_RR_NAME_RAIF_NextInsNum,
                                    NULL
                                );

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

            pPoamIrepFoNextIns->Remove((ANSC_HANDLE)pPoamIrepFoNextIns);
            pPoamIrepFoNextIns = NULL;
        }
    }

    /* Initialize middle layer for Device.RouterAdvertisement.InterfaceSetting.{i}. */

    ulEntryCount = CosaDmlRaIfGetNumberOfEntries(NULL);
    
    for ( ulIndex = 0; ulIndex < ulEntryCount; ulIndex++ )
    {
        pRAInterface = (PCOSA_DML_RA_IF_FULL2)AnscAllocateMemory(sizeof(COSA_DML_RA_IF_FULL2));

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

        AnscSListInitializeHeader(&pRAInterface->OptionList);
        
        pRAInterface->ulNextOptionInsNum = 1;
                
        CosaDmlRaIfGetEntry(NULL, ulIndex,(PCOSA_DML_RA_IF_FULL)pRAInterface);

        if ( TRUE )
        {
            pCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));

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

            if ( 0 != pRAInterface->Cfg.InstanceNumber )
            {
                pCosaContext->InstanceNumber = pRAInterface->Cfg.InstanceNumber;
                
                if ( pMyObject->ulNextInterfaceInsNum <=  pRAInterface->Cfg.InstanceNumber )
                {
                    pMyObject->ulNextInterfaceInsNum =  pRAInterface->Cfg.InstanceNumber + 1;

                    if ( 0 == pMyObject->ulNextInterfaceInsNum )
                    {
                        pMyObject->ulNextInterfaceInsNum = 1;
                    }
                }
            }
            else
            {
                pCosaContext->InstanceNumber = pMyObject->ulNextInterfaceInsNum;  
                
                pRAInterface->Cfg.InstanceNumber = pCosaContext->InstanceNumber ;
                
                pMyObject->ulNextInterfaceInsNum++;
                
                if ( 0 == pMyObject->ulNextInterfaceInsNum )
                {
                    pMyObject->ulNextInterfaceInsNum = 1;
                }

                /* Generate Alias */
                _ansc_sprintf(pRAInterface->Cfg.Alias, "Interface%d", (int)pMyObject->ulNextInterfaceInsNum);

                CosaDmlRaIfSetValues
                (
                    NULL,
                    ulIndex,
                    pRAInterface->Cfg.InstanceNumber,
                    pRAInterface->Cfg.Alias
                );
            }

            pCosaContext->hContext      = (ANSC_HANDLE)pRAInterface;            
            pCosaContext->hParentTable  = NULL;            
            pCosaContext->bNew          = FALSE;

            CosaSListPushEntryByInsNum(&pMyObject->InterfaceList, pCosaContext);
                  
        }

        /* Initialize middle layer for Device.RouterAdvertisement.InterfaceSetting.{i}.Option.{i}.  */
        if ( TRUE )
        {
            _ansc_sprintf
            (
                FolderName, 
                "%s%d", 
                COSA_DML_RR_NAME_RAIF_OPTION_NextInsNum, 
                (int)pRAInterface->Cfg.InstanceNumber
            );
            
            pPoamIrepFoNextIns = 
                (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoRAIF->GetFolder
                    (
                        (ANSC_HANDLE)pPoamIrepFoRAIF,
                        FolderName
                    );

            if ( pPoamIrepFoNextIns )
            {
                pSlapVariable =
                    (PSLAP_VARIABLE)pPoamIrepFoNextIns->GetRecord
                        (
                            (ANSC_HANDLE)pPoamIrepFoNextIns,
                            COSA_DML_RR_NAME_RAIF_OPTION_NextInsNum,
                            NULL
                        );

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

                pPoamIrepFoNextIns->Remove((ANSC_HANDLE)pPoamIrepFoNextIns);
                pPoamIrepFoNextIns = NULL;
            } 
        }
        
        ulSubEntryCount = CosaDmlRaIfGetNumberOfOptions(NULL, pRAInterface->Cfg.InstanceNumber);

        for ( ulSubIndex = 0; ulSubIndex < ulSubEntryCount; ulSubIndex++ )
        {
            pRAOption = (PCOSA_DML_RA_OPTION)AnscAllocateMemory(sizeof(COSA_DML_RA_OPTION));
        
            if ( !pRAOption )
            {
                returnStatus = ANSC_STATUS_RESOURCES;
                
                goto  EXIT;
            }
        
            CosaDmlRaIfGetOption(NULL, pRAInterface->Cfg.InstanceNumber, ulSubIndex, pRAOption);
        
            if ( TRUE )
            {
                pSubCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));

                if ( !pSubCosaContext )
                {
                    AnscFreeMemory(pRAOption);

                    returnStatus = ANSC_STATUS_RESOURCES;
                    
                    goto  EXIT;  
                }

                if ( 0 != pRAOption->InstanceNumber )
                {
                    pSubCosaContext->InstanceNumber = pRAOption->InstanceNumber;

                    if ( pRAInterface->ulNextOptionInsNum <= pRAOption->InstanceNumber )
                    {
                        pRAInterface->ulNextOptionInsNum = pRAOption->InstanceNumber + 1;

                        if ( pRAInterface->ulNextOptionInsNum == 0 )
                        {
                            pRAInterface->ulNextOptionInsNum = 1;
                        }
                    }  
                }
                else
                {
                    pSubCosaContext->InstanceNumber = pRAOption->InstanceNumber = pRAInterface->ulNextOptionInsNum;

                    pRAInterface->ulNextOptionInsNum++;

                    if ( pRAInterface->ulNextOptionInsNum == 0 )
                    {
                        pRAInterface->ulNextOptionInsNum = 1;
                    }

                    /* Generate Alias */
                    _ansc_sprintf(pRAOption->Alias, "Option%d", (int)pSubCosaContext->InstanceNumber);

                    /* TODO: Set InstanceNumber Alias back */
                    CosaDmlRaIfSetOptionValues
                    (
                        NULL, 
                        pRAInterface->Cfg.InstanceNumber, 
                        ulSubIndex, 
                        pRAOption->InstanceNumber,
                        pRAOption->Alias
                    );
                }                

                pSubCosaContext->hContext     = (ANSC_HANDLE)pRAOption;
                pSubCosaContext->hParentTable = (ANSC_HANDLE)pRAInterface;
                pSubCosaContext->bNew         = FALSE;

                CosaSListPushEntryByInsNum(&pRAInterface->OptionList, pSubCosaContext);

            }
        }

    }

    CosaRaRegGetInfo((ANSC_HANDLE)pMyObject);

    EXIT:
        
    return returnStatus;
}
ANSC_STATUS
CosaTSIPSubnetRegGetInfo
    (
        ANSC_HANDLE                 hThisObject
    )
{
    PCOSA_DATAMODEL_TSIP            pMyObject               = (PCOSA_DATAMODEL_TSIP     )hThisObject;
    PSLIST_HEADER                   pListHead               = (PSLIST_HEADER            )&pMyObject->SubnetList;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoTSIPSubnet   = (PPOAM_IREP_FOLDER_OBJECT )pMyObject->hIrepFolderTSIPSubnet;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoTSIPSubnetSp = (PPOAM_IREP_FOLDER_OBJECT )NULL;
    PCOSA_DML_TSIP_SUBNET_ENTRY     pEntry                  = (PCOSA_DML_TSIP_SUBNET_ENTRY)NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaContext            = (PCOSA_CONTEXT_LINK_OBJECT)NULL;
    PSLAP_VARIABLE                  pSlapVariable           = (PSLAP_VARIABLE           )NULL;
    ULONG                           ulEntryCount            = 0;
    ULONG                           ulIndex                 = 0;
    ULONG                           ulInstanceNumber        = 0;
    char*                           pFolderName             = NULL;
    char*                           pAlias                  = NULL;

    if ( !pPoamIrepFoTSIPSubnet )
    {
        return ANSC_STATUS_FAILURE;
    }

    /* Load the newly added but not yet commited entries */
    
    ulEntryCount = pPoamIrepFoTSIPSubnet->GetFolderCount((ANSC_HANDLE)pPoamIrepFoTSIPSubnet);

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

        if ( !pFolderName )
        {
            continue;
        }

        pPoamIrepFoTSIPSubnetSp = pPoamIrepFoTSIPSubnet->GetFolder((ANSC_HANDLE)pPoamIrepFoTSIPSubnet, pFolderName);

        AnscFreeMemory(pFolderName);

        if ( !pPoamIrepFoTSIPSubnetSp )
        {
            continue;
        }

        if ( TRUE )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoTSIPSubnetSp->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoTSIPSubnetSp,
                        COSA_DML_RR_NAME_TSIP_SUBNETInsNum,
                        NULL
                    );

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

                SlapFreeVariable(pSlapVariable);
            }
        }

        if ( TRUE )
        {
            pSlapVariable =
                (PSLAP_VARIABLE)pPoamIrepFoTSIPSubnetSp->GetRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoTSIPSubnetSp,
                        COSA_DML_RR_NAME_TSIP_SUBNETAlias,
                        NULL
                    );

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

                SlapFreeVariable(pSlapVariable);
            }
        }

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

        if ( !pCosaContext )
        {
            AnscFreeMemory(pAlias);

            return ANSC_STATUS_RESOURCES;
        }

        pEntry = (PCOSA_DML_TSIP_SUBNET_ENTRY)AnscAllocateMemory(sizeof(COSA_DML_TSIP_SUBNET_ENTRY));

        if ( !pEntry )
        {
            AnscFreeMemory(pAlias);
            AnscFreeMemory(pCosaContext);

            return ANSC_STATUS_RESOURCES;
        }

        AnscCopyString(pEntry->Alias, pAlias);

        pEntry->InstanceNumber = ulInstanceNumber;

        pCosaContext->InstanceNumber        = ulInstanceNumber;
        pCosaContext->bNew                  = TRUE;
        pCosaContext->hContext              = (ANSC_HANDLE)pEntry;
        pCosaContext->hParentTable          = NULL;
        pCosaContext->hPoamIrepUpperFo      = (ANSC_HANDLE)pPoamIrepFoTSIPSubnet;
        pCosaContext->hPoamIrepFo           = (ANSC_HANDLE)pPoamIrepFoTSIPSubnetSp;

        CosaSListPushEntryByInsNum(pListHead, pCosaContext);

        if ( pAlias )
        {
            AnscFreeMemory(pAlias);

            pAlias = NULL;
        }
    }
    
    return ANSC_STATUS_SUCCESS;
}
ANSC_STATUS
CosaTSIPInitialize
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus           = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_TSIP            pMyObject              = (PCOSA_DATAMODEL_TSIP)hThisObject;
    PCOSA_DATAMODEL_FILETRANSFER    pFtObject              = (PCOSA_DATAMODEL_FILETRANSFER)g_pCosaBEManager->hFileTransfer;
    PCOSA_DML_FILETRANSFER_CFG      pCfg                   = (PCOSA_DML_FILETRANSFER_CFG  )&pFtObject->Cfg;
    PANSC_ATOM_TABLE_OBJECT         pAtomNamespace         = NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoCOSA        = (PPOAM_IREP_FOLDER_OBJECT)NULL;
    PPOAM_IREP_FOLDER_OBJECT        hIrepFolderTSIPSubnet  = (PPOAM_IREP_FOLDER_OBJECT)NULL;
    PPOAM_IREP_FOLDER_OBJECT        hIrepFolderTSIPRule    = (PPOAM_IREP_FOLDER_OBJECT)NULL;
    PSLAP_VARIABLE                  pSlapVariable          = (PSLAP_VARIABLE          )NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaContext           = (PCOSA_CONTEXT_LINK_OBJECT)NULL;
    PCOSA_DML_TSIP_SUBNET_ENTRY     pEntry                 = (PCOSA_DML_TSIP_SUBNET_ENTRY)NULL;
    PCOSA_DML_TSIP_RULE_ENTRY       pEntry2                = (PCOSA_DML_TSIP_RULE_ENTRY)NULL;
    ULONG                           ulEntryCount           = 0;
    ULONG                           ulIndex                = 0;
    ULONG                           ulNextInsNum           = 0;

    /* Initiation all functions */

    CosaDmlTSIPInit(NULL, NULL);

    pMyObject->hFtCfg = (ANSC_HANDLE)pCfg;
    pMyObject->ulSubnetNextInsNum = 1;

    pMyObject->hIrepFolderCOSA = g_GetRegistryRootFolder(g_pDslhDmlAgent);

    /* Load Mapping file */
    pAtomNamespace =
        AnscCreateAtomTable
            (
                (ANSC_HANDLE)NULL,
                (ANSC_HANDLE)NULL,
                NULL
            );

    if ( pAtomNamespace != NULL )
    {
        pMyObject->hAtomNamespace = pAtomNamespace;
    }

    CosaDmlTSIPLoadMappingFile((ANSC_HANDLE)pMyObject);

    /* Initialize Device.X_CISCO_COM_TrueStaticIP. */
    CosaDmlTSIPGetCfg(NULL, &pMyObject->TSIPCfg);

    /* Initiation Device.X_CISCO_COM_TrueStaticIP.Subnet.{i} */
    AnscSListInitializeHeader(&pMyObject->SubnetList);
    CosaDmlAdditionalSubnetLoadPsm((ANSC_HANDLE)pMyObject);


    pPoamIrepFoCOSA = (PPOAM_IREP_FOLDER_OBJECT)pMyObject->hIrepFolderCOSA;
    if ( !pPoamIrepFoCOSA )
    {
        return ANSC_STATUS_FAILURE;
    }
#if 0
    hIrepFolderTSIPSubnet =
        (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoCOSA->GetFolder
            (
                (ANSC_HANDLE)pPoamIrepFoCOSA,
                COSA_IREP_FOLDER_NAME_TSIP_SUBNET
            );

    if ( !hIrepFolderTSIPSubnet )
    {
        hIrepFolderTSIPSubnet =
            pPoamIrepFoCOSA->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoCOSA,
                    COSA_IREP_FOLDER_NAME_TSIP_SUBNET,
                    0
                );
    }

    if ( !hIrepFolderTSIPSubnet )
    {
        return ANSC_STATUS_FAILURE;
    }
    else
    {
        pMyObject->hIrepFolderTSIPSubnet = (ANSC_HANDLE)hIrepFolderTSIPSubnet;
    }

    /* Retrieve Next Instance Number */
    
    if ( TRUE )
    {
        pSlapVariable =
            (PSLAP_VARIABLE)hIrepFolderTSIPSubnet->GetRecord
                (
                    (ANSC_HANDLE)hIrepFolderTSIPSubnet,
                    COSA_DML_RR_NAME_TSIP_SUBNETNextInsNunmber,
                    NULL
                );

        if ( pSlapVariable )
        {
            pMyObject->ulSubnetNextInsNum = pSlapVariable->Variant.varUint32;

            SlapFreeVariable(pSlapVariable);
        }
    }
#endif
    /* Initiation Device.X_CISCO_COM_TrueStaticIP.PortManagement.Rule.{i}. */

    AnscSListInitializeHeader(&pMyObject->RuleList);

    pMyObject->ulRuleNextInsNum = 1;

    pPoamIrepFoCOSA = (PPOAM_IREP_FOLDER_OBJECT)pMyObject->hIrepFolderCOSA;
    if ( !pPoamIrepFoCOSA )
    {
        return ANSC_STATUS_FAILURE;
    }

    hIrepFolderTSIPRule =
        (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoCOSA->GetFolder
            (
                (ANSC_HANDLE)pPoamIrepFoCOSA,
                COSA_IREP_FOLDER_NAME_TSIP_RULE
            );

    if ( !hIrepFolderTSIPRule )
    {
        hIrepFolderTSIPRule =
            pPoamIrepFoCOSA->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoCOSA,
                    COSA_IREP_FOLDER_NAME_TSIP_RULE,
                    0
                );
    }

    if ( !hIrepFolderTSIPRule )
    {
        return ANSC_STATUS_FAILURE;
    }
    else
    {
        pMyObject->hIrepFolderTSIPRule = (ANSC_HANDLE)hIrepFolderTSIPRule;
    }

    /* Retrieve Next Instance Number */
    
    if ( TRUE )
    {
        pSlapVariable =
            (PSLAP_VARIABLE)hIrepFolderTSIPRule->GetRecord
                (
                    (ANSC_HANDLE)hIrepFolderTSIPRule,
                    COSA_DML_RR_NAME_TSIP_RULENextInsNunmber,
                    NULL
                );

        if ( pSlapVariable )
        {
            pMyObject->ulRuleNextInsNum = pSlapVariable->Variant.varUint32;

            SlapFreeVariable(pSlapVariable);
        }
    }

    /* Initialize middle layer */

    /* CosaDmlTSIPGetCfg(NULL, &pMyObject->TSIPCfg); */

    CosaDmlTSIPPortManagementGetCfg(NULL, &pMyObject->PortManagementCfg);

#if 0
    ulEntryCount = CosaDmlTSIPSubnetGetNumberOfEntries(NULL);

    for ( ulIndex = 0; ulIndex < ulEntryCount; ulIndex++ )
    {
        pEntry = (PCOSA_DML_TSIP_SUBNET_ENTRY)AnscAllocateMemory(sizeof(COSA_DML_TSIP_SUBNET_ENTRY));

        if ( !pEntry )
        {
            return ANSC_STATUS_RESOURCES;
        }
        
        CosaDmlTSIPSubnetGetEntry(NULL, ulIndex, pEntry);

        if ( TRUE )
        {
            pCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));

            if ( !pCosaContext )
            {
                AnscFreeMemory(pEntry);
                
                return ANSC_STATUS_RESOURCES;
            }

            if ( pEntry->InstanceNumber != 0 )
            {
                pCosaContext->InstanceNumber = pEntry->InstanceNumber;

                if ( pMyObject->ulSubnetNextInsNum <= pEntry->InstanceNumber )
                {
                    pMyObject->ulSubnetNextInsNum = pEntry->InstanceNumber + 1;

                    if ( pMyObject->ulSubnetNextInsNum == 0 )
                    {
                        pMyObject->ulSubnetNextInsNum = 1;
                    }
                }
            }
            else
            {
                pEntry->InstanceNumber = pCosaContext->InstanceNumber = pMyObject->ulSubnetNextInsNum;

                pMyObject->ulSubnetNextInsNum++;

                if ( pMyObject->ulSubnetNextInsNum == 0 )
                {
                    pMyObject->ulSubnetNextInsNum = 1;
                }

                /* Generate Alias */
                _ansc_sprintf(pEntry->Alias, "Subnet%d", pCosaContext->InstanceNumber);

                CosaDmlTSIPSubnetSetValues
                (
                    NULL,
                    ulIndex,
                    pCosaContext->InstanceNumber,
                    pEntry->Alias
                );
            }

            pCosaContext->hContext      = (ANSC_HANDLE)pEntry;
            pCosaContext->hParentTable  = NULL;
            pCosaContext->bNew          = FALSE;
            pCosaContext->hPoamIrepUpperFo = NULL;
            pCosaContext->hPoamIrepFo      = NULL;

            CosaSListPushEntryByInsNum(&pMyObject->SubnetList, pCosaContext);
        }
    }
#endif
    ulEntryCount = CosaDmlTSIPRuleGetNumberOfEntries(NULL);

    for ( ulIndex = 0; ulIndex < ulEntryCount; ulIndex++ )
    {
        pEntry2 = (PCOSA_DML_TSIP_RULE_ENTRY)AnscAllocateMemory(sizeof(COSA_DML_TSIP_RULE_ENTRY));

        if ( !pEntry2 )
        {
            return ANSC_STATUS_RESOURCES;
        }
        
        CosaDmlTSIPRuleGetEntry(NULL, ulIndex, pEntry2);

        if ( TRUE )
        {
            pCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));

            if ( !pCosaContext )
            {
                AnscFreeMemory(pEntry2);
                
                return ANSC_STATUS_RESOURCES;
            }

            if ( pEntry2->InstanceNumber != 0 )
            {
                pCosaContext->InstanceNumber = pEntry2->InstanceNumber;

                if ( pMyObject->ulRuleNextInsNum <= pEntry2->InstanceNumber )
                {
                    pMyObject->ulRuleNextInsNum = pEntry2->InstanceNumber + 1;

                    if ( pMyObject->ulRuleNextInsNum == 0 )
                    {
                        pMyObject->ulRuleNextInsNum = 1;
                    }
                }
            }
            else
            {
                pEntry2->InstanceNumber = pCosaContext->InstanceNumber = pMyObject->ulRuleNextInsNum;

                pMyObject->ulRuleNextInsNum++;

                if ( pMyObject->ulRuleNextInsNum == 0 )
                {
                    pMyObject->ulRuleNextInsNum = 1;
                }

                /* Generate Alias */
                _ansc_sprintf(pEntry2->Alias, "Rule%d", pCosaContext->InstanceNumber);

                CosaDmlTSIPRuleSetValues
                (
                    NULL,
                    ulIndex,
                    pCosaContext->InstanceNumber,
                    pEntry2->Alias
                );
            }

            pCosaContext->hContext      = (ANSC_HANDLE)pEntry2;
            pCosaContext->hParentTable  = NULL;
            pCosaContext->bNew          = FALSE;
            pCosaContext->hPoamIrepUpperFo = NULL;
            pCosaContext->hPoamIrepFo      = NULL;

            CosaSListPushEntryByInsNum(&pMyObject->RuleList, pCosaContext);
        }
    }

    /* Load the newly added but not yet commited entries, if exist */
#if 0
    CosaTSIPSubnetRegGetInfo((ANSC_HANDLE)pMyObject);
#endif
    CosaTSIPRuleRegGetInfo((ANSC_HANDLE)pMyObject);


    return returnStatus;
}
ANSC_STATUS
CosaUserinterfaceInitialize
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                         returnStatus = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_USERINTERFACE       pMyObject    = (PCOSA_DATAMODEL_USERINTERFACE)hThisObject;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoCOSA        = (PPOAM_IREP_FOLDER_OBJECT)NULL;
    PPOAM_IREP_FOLDER_OBJECT        hIrepFolderUIIPRange   = (PPOAM_IREP_FOLDER_OBJECT)NULL;
    PSLAP_VARIABLE                  pSlapVariable          = (PSLAP_VARIABLE          )NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaContext           = (PCOSA_CONTEXT_LINK_OBJECT)NULL;
    PCOSA_DML_UI_IPRANGE_ENTRY      pEntry                 = (PCOSA_DML_UI_IPRANGE_ENTRY)NULL;
    ULONG                           ulEntryCount           = 0;
    ULONG                           ulIndex                = 0;
    ULONG                           ulNextInsNum           = 0;

    /* Initiation all functions */
    _ansc_memset(&pMyObject->RaCfg, 0, sizeof(COSA_DML_RA_CFG));
    
    CosaDmlRaInit(NULL, NULL);

    CosaDmlRaGetCfg(NULL, &pMyObject->RaCfg);

    pMyObject->hIrepFolderCOSA = g_GetRegistryRootFolder(g_pDslhDmlAgent);


    /* Initiation Device.UserInterface.X_CISCO_COM_RemoteAccess.iprange.{i}. */

    AnscSListInitializeHeader(&pMyObject->iprangeList);

    pMyObject->uliprangeNextInsNum = 1;

    pPoamIrepFoCOSA = (PPOAM_IREP_FOLDER_OBJECT)pMyObject->hIrepFolderCOSA;
    if ( !pPoamIrepFoCOSA )
    {
        return ANSC_STATUS_FAILURE;
    }

    hIrepFolderUIIPRange =
        (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoCOSA->GetFolder
            (
                (ANSC_HANDLE)pPoamIrepFoCOSA,
                COSA_IREP_FOLDER_NAME_UserInterface_IPRange
            );

    if ( !hIrepFolderUIIPRange )
    {
        hIrepFolderUIIPRange =
            pPoamIrepFoCOSA->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoCOSA,
                    COSA_IREP_FOLDER_NAME_UserInterface_IPRange,
                    0
                );
    }

    if ( !hIrepFolderUIIPRange )
    {
        return ANSC_STATUS_FAILURE;
    }
    else
    {
        pMyObject->hIrepFolderUIIPRange = (ANSC_HANDLE)hIrepFolderUIIPRange;
    }

    /* Retrieve Next Instance Number */
    
    if ( TRUE )
    {
        pSlapVariable =
            (PSLAP_VARIABLE)hIrepFolderUIIPRange->GetRecord
                (
                    (ANSC_HANDLE)hIrepFolderUIIPRange,
                    COSA_DML_RR_NAME_UserInterface_IPRangeNextInsNunmber,
                    NULL
                );

        if ( pSlapVariable )
        {
            pMyObject->uliprangeNextInsNum = pSlapVariable->Variant.varUint32;

            SlapFreeVariable(pSlapVariable);
        }
    }

    /* Initialize middle layer */

    ulEntryCount = CosaDmlUIIPRangeGetNumberOfEntries(NULL);

    for ( ulIndex = 0; ulIndex < ulEntryCount; ulIndex++ )
    {
        pEntry = (PCOSA_DML_UI_IPRANGE_ENTRY)AnscAllocateMemory(sizeof(COSA_DML_UI_IPRANGE_ENTRY));

        if ( !pEntry )
        {
            return ANSC_STATUS_RESOURCES;
        }
        
        CosaDmlUIIPRangeGetEntry(NULL, ulIndex, pEntry);

        if ( TRUE )
        {
            pCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));

            if ( !pCosaContext )
            {
                AnscFreeMemory(pEntry);
                
                return ANSC_STATUS_RESOURCES;
            }

            if ( pEntry->InstanceNumber != 0 )
            {
                pCosaContext->InstanceNumber = pEntry->InstanceNumber;

                if ( pMyObject->uliprangeNextInsNum <= pEntry->InstanceNumber )
                {
                    pMyObject->uliprangeNextInsNum = pEntry->InstanceNumber + 1;

                    if ( pMyObject->uliprangeNextInsNum == 0 )
                    {
                        pMyObject->uliprangeNextInsNum = 1;
                    }
                }
            }
            else
            {
                pEntry->InstanceNumber = pCosaContext->InstanceNumber = pMyObject->uliprangeNextInsNum;

                pMyObject->uliprangeNextInsNum++;

                if ( pMyObject->uliprangeNextInsNum == 0 )
                {
                    pMyObject->uliprangeNextInsNum = 1;
                }

                /* Generate Alias */
                _ansc_sprintf(pEntry->Alias, "iprange%d", pCosaContext->InstanceNumber);

                CosaDmlUIIPRangeSetValues
                (
                    NULL,
                    ulIndex,
                    pCosaContext->InstanceNumber,
                    pEntry->Alias
                );
            }

            pCosaContext->hContext      = (ANSC_HANDLE)pEntry;
            pCosaContext->hParentTable  = NULL;
            pCosaContext->bNew          = FALSE;
            pCosaContext->hPoamIrepUpperFo = NULL;
            pCosaContext->hPoamIrepFo      = NULL;

            CosaSListPushEntryByInsNum(&pMyObject->iprangeList, pCosaContext);
        }
    }
    
    return returnStatus;
}
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_STATUS
CosaBridgingInitialize
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus        = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_BRIDGING        pMyObject           = (PCOSA_DATAMODEL_BRIDGING)hThisObject;
    PSLAP_VARIABLE                  pSlapVariable       = (PSLAP_VARIABLE             )NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoCOSA     = (PPOAM_IREP_FOLDER_OBJECT   )NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoBRG      = (PPOAM_IREP_FOLDER_OBJECT   )NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoBRGHA    = (PPOAM_IREP_FOLDER_OBJECT   )NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoNextIns  = (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_CONTEXT_LINK_OBJECT       pCosaContext3       = (PCOSA_CONTEXT_LINK_OBJECT  )NULL;
    PCOSA_DML_BRG_FULL_ALL          pDmlBridge          = (PCOSA_DML_BRG_FULL_ALL     )NULL;
    PCOSA_DML_BRG_PORT_FULL         pPort               = (PCOSA_DML_BRG_PORT_FULL    )NULL;
    ULONG                           ulBridgeCount       = 0;
    ULONG                           ulSubCount          = 0;
    ULONG                           ulIndex             = 0;
    ULONG                           ulSubIndex          = 0;
    char                            FolderName[32]      = {0};
    PCOSA_DML_BRG_VLAN_FULL         pVLAN           = (PCOSA_DML_BRG_VLAN_FULL  )NULL;

    /* Initiation all functions */

//$HL 4/24/2013
    pMyObject->ulNextBridgeInstance = 1;

	AnscSListInitializeHeader(&pMyObject->BridgeList);

    //$HL 4/25/2013
    pMyObject->BridgeList.Depth = 0;
    
    pMyObject->hIrepFolderCOSA = g_GetRegistryRootFolder(g_pDslhDmlAgent);

    pPoamIrepFoCOSA = (PPOAM_IREP_FOLDER_OBJECT)pMyObject->hIrepFolderCOSA;

    if ( !pPoamIrepFoCOSA )
    {
        returnStatus = ANSC_STATUS_FAILURE;

        goto EXIT;
    }

    pPoamIrepFoBRG =
        (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoCOSA->GetFolder
            (
			    (ANSC_HANDLE)pPoamIrepFoCOSA,
                COSA_IREP_FOLDER_NAME_BRIDGING
            );

    if ( !pPoamIrepFoBRG )
    {
        pPoamIrepFoBRG =
            pPoamIrepFoCOSA->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoCOSA,
                    COSA_IREP_FOLDER_NAME_BRIDGING,
                    0
                );
    }

    if ( !pPoamIrepFoBRG )
    {
        returnStatus = ANSC_STATUS_FAILURE;

        goto  EXIT;
    }
    else
    {
        pMyObject->hIrepFolderBRG = (ANSC_HANDLE)pPoamIrepFoBRG;
    }

    pPoamIrepFoBRGHA = 
        (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoBRG->GetFolder
            (
                (ANSC_HANDLE)pPoamIrepFoCOSA,
                COSA_IREP_FOLDER_NAME_BRIDGINGHA
            );

    if ( !pPoamIrepFoBRGHA )
    {
        pPoamIrepFoBRGHA =
            pPoamIrepFoBRG->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoBRG,
                    COSA_IREP_FOLDER_NAME_BRIDGINGHA,
                    0
                );
    }

    if ( !pPoamIrepFoBRGHA )
    {
        returnStatus = ANSC_STATUS_FAILURE;

        goto  EXIT;
    }
    else
    {
        pMyObject->hIrepFolderBRGHA = (ANSC_HANDLE)pPoamIrepFoBRGHA;
    }

    if ( TRUE )
    {
        _ansc_sprintf
        (
            FolderName, 
            "%s%d", 
            COSA_DML_RR_NAME_Bridge_NextInsNunmber,
            0
        );
        
        pPoamIrepFoNextIns = (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoBRG->GetFolder
                                (
                                    (ANSC_HANDLE)pPoamIrepFoBRG,
                                    FolderName
                                );

        AnscZeroMemory(FolderName, 32);

        if ( pPoamIrepFoNextIns )
        {
            pSlapVariable = (PSLAP_VARIABLE)pPoamIrepFoNextIns->GetRecord
                                (
                                    (ANSC_HANDLE)pPoamIrepFoNextIns,
                                    COSA_DML_RR_NAME_Bridge_NextInsNunmber,
                                    NULL
                                );

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

            pPoamIrepFoNextIns->Remove((ANSC_HANDLE)pPoamIrepFoNextIns);
            pPoamIrepFoNextIns = NULL;
        }
    }

    ulBridgeCount = CosaDmlBrgGetNumberOfEntries(NULL);

    for ( ulIndex = 0; ulIndex < ulBridgeCount; ulIndex++ )
    {
        pDmlBridge = (PCOSA_DML_BRG_FULL_ALL)AnscAllocateMemory(sizeof(COSA_DML_BRG_FULL_ALL));
        _ansc_memset(pDmlBridge, 0, sizeof(COSA_DML_BRG_FULL_ALL));
        if ( !pDmlBridge )
        {
            returnStatus = ANSC_STATUS_RESOURCES;

            goto EXIT;
        }

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

        pDmlBridge->ulNextPortInsNum = 1;
        pDmlBridge->ulNextVLANInsNum = 1;
        pDmlBridge->ulNextVLANPortInsNum = 1;

        //$HL 4/25/2013
        if (CosaDmlBrgGetEntry(NULL, ulIndex, (PCOSA_DML_BRG_FULL)pDmlBridge)!= ANSC_STATUS_SUCCESS)
        {
            AnscFreeMemory(pDmlBridge);
            break;    
        }
        else
        //if ( TRUE )
        {
            pCosaContext = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));
            _ansc_memset(pCosaContext, 0, sizeof(COSA_CONTEXT_LINK_OBJECT));
            if ( !pCosaContext )
            {
                AnscFreeMemory(pDmlBridge);

                returnStatus = ANSC_STATUS_RESOURCES;

                AnscTraceFlow(("<HL>%s cannot allocate pCosaContext\n", __FUNCTION__));
                goto  EXIT;
            }
            
            if ( pDmlBridge->Cfg.InstanceNumber !=0 )
            {
                pCosaContext->InstanceNumber = pDmlBridge->Cfg.InstanceNumber;

                if ( pMyObject->ulNextBridgeInstance <= pDmlBridge->Cfg.InstanceNumber )
                {
                    pMyObject->ulNextBridgeInstance = pDmlBridge->Cfg.InstanceNumber + 1;

                    if ( pMyObject->ulNextBridgeInstance == 0 )
                    {
                        pMyObject->ulNextBridgeInstance = 1;
                    }
                }
            }
            else
            {
                pDmlBridge->Cfg.InstanceNumber = pCosaContext->InstanceNumber = pMyObject->ulNextBridgeInstance;

                pMyObject->ulNextBridgeInstance++;

                if ( pMyObject->ulNextBridgeInstance == 0)
                {
                    pMyObject->ulNextBridgeInstance = 1;
                }

                _ansc_sprintf(pDmlBridge->Cfg.Alias, "DmlBridge%d", pMyObject->ulNextBridgeInstance);

                CosaDmlBrgSetValues(NULL, ulIndex, pDmlBridge->Cfg.InstanceNumber, pDmlBridge->Cfg.Alias);
            }

            pCosaContext->hContext     = (ANSC_HANDLE)pDmlBridge;
            pCosaContext->hParentTable = NULL;
            pCosaContext->bNew         = FALSE;
            //$HL 4/29/2013
            //pCosaContext->hPoamIrepUpperFo = NULL;
            CosaSListPushEntryByInsNum(&pMyObject->BridgeList, pCosaContext);
        }

        /* Port */
        
        if ( TRUE )
        {
            _ansc_sprintf
                (
                    FolderName, 
                    "%s%d", 
                    COSA_DML_RR_NAME_Bridge_Port_NextInsNumber, 
                    pDmlBridge->Cfg.InstanceNumber
                );

            pPoamIrepFoNextIns = 
                (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoBRG->GetFolder
                    (
                        (ANSC_HANDLE)pPoamIrepFoBRG,
                        FolderName
                    );

            if ( pPoamIrepFoNextIns )
            {
                pSlapVariable =
                    (PSLAP_VARIABLE)pPoamIrepFoNextIns->GetRecord
                        (
                            (ANSC_HANDLE)pPoamIrepFoNextIns,
                            COSA_DML_RR_NAME_Bridge_Port_NextInsNumber,
                            NULL
                        );

                if ( pSlapVariable )
                {
                    
                    pDmlBridge->ulNextPortInsNum = pSlapVariable->Variant.varUint32;
                    SlapFreeVariable(pSlapVariable);
                }
                else
                {
                    AnscTraceFlow(("<HL>%s pSlapVariable == NULL\n", __FUNCTION__));
                }

                pPoamIrepFoNextIns->Remove((ANSC_HANDLE)pPoamIrepFoNextIns);
                pPoamIrepFoNextIns = NULL;
            }
            else
            {
                AnscTraceFlow(("<HL>%s pPoamIrepFoNextIns == NULL\n", __FUNCTION__));
            }            
        }

        ulSubCount = CosaDmlBrgPortGetNumberOfEntries(NULL, pDmlBridge->Cfg.InstanceNumber);

        for ( ulSubIndex = 0; ulSubIndex < ulSubCount; ulSubIndex++ )
        {
            pPort = (PCOSA_DML_BRG_PORT_FULL)AnscAllocateMemory(sizeof(COSA_DML_BRG_PORT_FULL));

            if ( !pPort )
            {
                returnStatus = ANSC_STATUS_RESOURCES;

                goto EXIT;
            }

            _ansc_memset(pPort, 0, sizeof(COSA_DML_BRG_PORT_FULL));

            if(CosaDmlBrgPortGetEntry(NULL, pDmlBridge->Cfg.InstanceNumber, ulSubIndex, pPort)
                != ANSC_STATUS_SUCCESS)
            {
                AnscFreeMemory(pPort);
                break;
            }
            else 
            {
                pCosaContext2 = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));

                if ( !pCosaContext2 )
                {  
                    AnscFreeMemory(pPort);
                    returnStatus = ANSC_STATUS_RESOURCES;
                    AnscTraceFlow(("<$HL> %s bridge instance:%d cannot allocate any memory for pCosaContext2\n",__FUNCTION__,
                        pDmlBridge->Cfg.InstanceNumber));
                    AnscFreeMemory(pPort);
                    goto EXIT;
                }

                _ansc_memset(pCosaContext2, 0, sizeof(COSA_CONTEXT_LINK_OBJECT));

                if ( pPort->Cfg.InstanceNumber != 0 )
                {
                    pCosaContext2->InstanceNumber = pPort->Cfg.InstanceNumber;

                    if ( pDmlBridge->ulNextPortInsNum <= pPort->Cfg.InstanceNumber )
                    {
                        pDmlBridge->ulNextPortInsNum = pPort->Cfg.InstanceNumber + 1;

                        if ( pDmlBridge->ulNextPortInsNum == 0 )
                        {
                            pDmlBridge->ulNextPortInsNum = 1;
                        }
                    }
                }
                else
                {
                    pCosaContext2->InstanceNumber = pPort->Cfg.InstanceNumber = pDmlBridge->ulNextPortInsNum;

                    pDmlBridge->ulNextPortInsNum++;

                    if ( pDmlBridge->ulNextPortInsNum == 0 )
                    {
                        pDmlBridge->ulNextPortInsNum = 1;
                    }

                    _ansc_sprintf(pPort->Cfg.Alias, "Port%d", pCosaContext2->InstanceNumber);

                    CosaDmlBrgPortSetValues
                        (
                            NULL,
                            pDmlBridge->Cfg.InstanceNumber,
                            ulSubIndex,
                            pPort->Cfg.InstanceNumber,
                            pPort->Cfg.Alias
                        );
                }

                pCosaContext2->hContext     = (ANSC_HANDLE)pPort;
                pCosaContext2->hParentTable = (ANSC_HANDLE)pDmlBridge;
                pCosaContext2->bNew         = FALSE;

                CosaSListPushEntryByInsNum(&pDmlBridge->PortList, pCosaContext2);
            }
        }
    

        //$HL 7/3/2013
        /* VLAN */
        
        if ( TRUE )
        {
            _ansc_sprintf
                (
                    FolderName, 
                    "%s%d", 
                    COSA_DML_RR_NAME_Bridge_VLAN_NextInsNumber, 
                    pDmlBridge->Cfg.InstanceNumber
                );

            pPoamIrepFoNextIns = 
                (PPOAM_IREP_FOLDER_OBJECT)pPoamIrepFoBRG->GetFolder
                    (
                        (ANSC_HANDLE)pPoamIrepFoBRG,
                        FolderName
                    );

            if ( pPoamIrepFoNextIns )
            {
                pSlapVariable =
                    (PSLAP_VARIABLE)pPoamIrepFoNextIns->GetRecord
                        (
                            (ANSC_HANDLE)pPoamIrepFoNextIns,
                            COSA_DML_RR_NAME_Bridge_VLAN_NextInsNumber,
                            NULL
                        );

                if ( pSlapVariable )
                {
                    
                    pDmlBridge->ulNextVLANInsNum = pSlapVariable->Variant.varUint32;
                    SlapFreeVariable(pSlapVariable);
                }
                else
                {
                    AnscTraceFlow(("<HL>%s pSlapVariable == NULL\n", __FUNCTION__));
                }

                pPoamIrepFoNextIns->Remove((ANSC_HANDLE)pPoamIrepFoNextIns);
                pPoamIrepFoNextIns = NULL;
            }
            else
            {
                AnscTraceFlow(("<HL>%s pPoamIrepFoNextIns == NULL\n", __FUNCTION__));
            }            
        }

        ulSubCount = CosaDmlBrgVlanGetNumberOfEntries(NULL, pDmlBridge->Cfg.InstanceNumber);

        for ( ulSubIndex = 0; ulSubIndex < ulSubCount; ulSubIndex++ )
        {
            pVLAN = (PCOSA_DML_BRG_VLAN_FULL)AnscAllocateMemory(sizeof(COSA_DML_BRG_VLAN_FULL));

            if ( !pVLAN )
            {
                returnStatus = ANSC_STATUS_RESOURCES;

                goto EXIT;
            }

            _ansc_memset(pVLAN, 0, sizeof(COSA_DML_BRG_VLAN_FULL));

            if(CosaDmlBrgVlanGetEntry(NULL, pDmlBridge->Cfg.InstanceNumber, ulSubIndex, pVLAN)
                != ANSC_STATUS_SUCCESS)
            {
                AnscFreeMemory(pVLAN);
                break;
            }
            else 
            {
                pCosaContext3 = (PCOSA_CONTEXT_LINK_OBJECT)AnscAllocateMemory(sizeof(COSA_CONTEXT_LINK_OBJECT));

                if ( !pCosaContext3 )
                {  
                    returnStatus = ANSC_STATUS_RESOURCES;
                    AnscTraceFlow(("<$HL> %s bridge instance:%d cannot allocate any memory for pCosaContext3\n",__FUNCTION__,
                        pDmlBridge->Cfg.InstanceNumber));
                    AnscFreeMemory(pVLAN);
                    goto EXIT;
                }

                _ansc_memset(pCosaContext3, 0, sizeof(COSA_CONTEXT_LINK_OBJECT));

                if ( pVLAN->Cfg.InstanceNumber != 0 )
                {
                    pCosaContext3->InstanceNumber = pVLAN->Cfg.InstanceNumber;

                    if ( pDmlBridge->ulNextVLANInsNum <= pVLAN->Cfg.InstanceNumber )
                    {
                        pDmlBridge->ulNextVLANInsNum = pVLAN->Cfg.InstanceNumber + 1;

                        if ( pDmlBridge->ulNextVLANInsNum == 0 )
                        {
                            pDmlBridge->ulNextVLANInsNum = 1;
                        }
                    }
                }
                else
                {
                    pCosaContext2->InstanceNumber = pVLAN->Cfg.InstanceNumber = pDmlBridge->ulNextPortInsNum;

                    pDmlBridge->ulNextVLANInsNum++;

                    if ( pDmlBridge->ulNextVLANInsNum == 0 )
                    {
                        pDmlBridge->ulNextVLANInsNum = 1;
                    }

                    _ansc_sprintf(pVLAN->Cfg.Alias, "VLAN%d", pCosaContext2->InstanceNumber);

                    CosaDmlBrgVlanSetValues //new sbAPI
                        (
                            NULL,
                            pDmlBridge->Cfg.InstanceNumber,
                            ulSubIndex,
                            pVLAN->Cfg.InstanceNumber,
                            pVLAN->Cfg.Alias
                        );
                }

                pCosaContext3->hContext     = (ANSC_HANDLE)pVLAN;
                pCosaContext3->hParentTable = (ANSC_HANDLE)pDmlBridge;
                pCosaContext3->bNew         = FALSE;

                CosaSListPushEntryByInsNum(&pDmlBridge->VLANList, pCosaContext3);
            }
        }
    }
    //$HL 4/29/2013
    CosaBridgingRegGetInfo((ANSC_HANDLE)pMyObject);

EXIT:

    return returnStatus;
}