ANSC_STATUS
CosaNatRegSetNatInfo
    (
        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)NULL;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoEnumNat  = (PPOAM_IREP_FOLDER_OBJECT)NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaNatContext     = NULL;
    PCOSA_DML_NAT_PMAPPING          pCosaNat            = NULL;
    PCOSA_DML_NAT_PTRIGGER          pCosaNatPt          = NULL;

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


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

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

        SlapAllocVariable(pSlapVariable);

        if ( !pSlapVariable )
        {
            returnStatus = ANSC_STATUS_RESOURCES;

            goto  EXIT1;
        }
    }

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

    pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->NatPMappingList);

    while ( pSLinkEntry )
    {
        /* create nat.{i} */

        pCosaNatContext = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry);
        pSLinkEntry       = AnscSListGetNextEntry(pSLinkEntry);

        pCosaNat = (PCOSA_DML_NAT_PMAPPING)pCosaNatContext->hContext;

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

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

        pPoamIrepFoEnumNat =
            pPoamIrepFoNat->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoNat,
                    FolderName,
                    0
                );

        if ( !pPoamIrepFoEnumNat )
        {
            continue;
        }

        /* add  nat.{i}.Alias */
        if ( TRUE )
        {
            pSlapVariable->Syntax            = SLAP_VAR_SYNTAX_string;
            pSlapVariable->Variant.varString = AnscCloneString(pCosaNat->Alias);

            returnStatus =
                pPoamIrepFoEnumNat->AddRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumNat,
                        COSA_DML_RR_NAME_NATAlias,
                        SYS_REP_RECORD_TYPE_ASTR,
                        SYS_RECORD_CONTENT_DEFAULT,
                        pSlapVariable,
                        0
                    );

            SlapCleanVariable(pSlapVariable);
            SlapInitVariable (pSlapVariable);
        }

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

            returnStatus =
                pPoamIrepFoEnumNat->AddRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumNat,
                        COSA_DML_RR_NAME_NATbNew,
                        SYS_REP_RECORD_TYPE_BOOL,
                        SYS_RECORD_CONTENT_DEFAULT,
                        pSlapVariable,
                        0
                    );

            SlapCleanVariable(pSlapVariable);
            SlapInitVariable (pSlapVariable);
        }


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

    /* For PortTrigger */

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

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

    if ( !pPoamIrepFoNatPt )
    {
        returnStatus = ANSC_STATUS_FAILURE;

        goto EXIT1;
    }

    /* Save next instance number for port trigger */
    if ( TRUE )
    {
        pSlapVariable->Syntax            = SLAP_VAR_SYNTAX_uint32;
        pSlapVariable->Variant.varUint32 = pMyObject->ulPtNextInstanceNumber;

        returnStatus =
            pPoamIrepFoNatPt->AddRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoNatPt,
                    COSA_DML_RR_NAME_NATNextInsNumber,
                    SYS_REP_RECORD_TYPE_UINT,
                    SYS_RECORD_CONTENT_DEFAULT,
                    pSlapVariable,
                    0
                );

        SlapCleanVariable(pSlapVariable);
        SlapInitVariable (pSlapVariable);
    }

    pSLinkEntry = AnscSListGetFirstEntry(&pMyObject->NatPTriggerList);

    while ( pSLinkEntry )
    {
        /* create nat.PortTrigger.{i} */

        pCosaNatContext = ACCESS_COSA_CONTEXT_LINK_OBJECT(pSLinkEntry);
        pSLinkEntry       = AnscSListGetNextEntry(pSLinkEntry);

        pCosaNatPt = (PCOSA_DML_NAT_PTRIGGER)pCosaNatContext->hContext;

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

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

        pPoamIrepFoEnumNat =
            pPoamIrepFoNatPt->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoNatPt,
                    FolderName,
                    0
                );

        if ( !pPoamIrepFoEnumNat )
        {
            continue;
        }

        /* add  PortTrigger.{i}.Alias */
        if ( TRUE )
        {
            pSlapVariable->Syntax            = SLAP_VAR_SYNTAX_string;
            pSlapVariable->Variant.varString = AnscCloneString(pCosaNatPt->Alias);

            returnStatus =
                pPoamIrepFoEnumNat->AddRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumNat,
                        COSA_DML_RR_NAME_NATAlias,
                        SYS_REP_RECORD_TYPE_ASTR,
                        SYS_RECORD_CONTENT_DEFAULT,
                        pSlapVariable,
                        0
                    );

            SlapCleanVariable(pSlapVariable);
            SlapInitVariable (pSlapVariable);
        }

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

            returnStatus =
                pPoamIrepFoEnumNat->AddRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoEnumNat,
                        COSA_DML_RR_NAME_NATbNew,
                        SYS_REP_RECORD_TYPE_BOOL,
                        SYS_RECORD_CONTENT_DEFAULT,
                        pSlapVariable,
                        0
                    );

            SlapCleanVariable(pSlapVariable);
            SlapInitVariable (pSlapVariable);
        }


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


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

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

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

    return returnStatus;
}
ANSC_STATUS
CosaDdnsRegAddDdnsInfo
    (
        ANSC_HANDLE                 hThisObject,
        ANSC_HANDLE                 hCosaContext
    )
{
    ANSC_STATUS                     returnStatus      = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_DDNS            pMyObject         = (PCOSA_DATAMODEL_DDNS     )hThisObject;
    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)hCosaContext;
    PCOSA_DML_DDNS_SERVICE          pDdnsService      = (PCOSA_DML_DDNS_SERVICE   )pCosaContext->hContext;
    PSLAP_VARIABLE                  pSlapVariable     = (PSLAP_VARIABLE           )NULL;

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

    if ( TRUE )
    {
        SlapAllocVariable(pSlapVariable);

        if ( !pSlapVariable )
        {
            returnStatus = ANSC_STATUS_RESOURCES;

            goto  EXIT1;
        }
    }

    if ( TRUE )
    {
        returnStatus = 
            pPoamIrepFoDdns->DelRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoDdns,
                    COSA_DML_RR_NAME_DdnsServiceNextInsNumber
                );

        pSlapVariable->Syntax            = SLAP_VAR_SYNTAX_uint32;
        pSlapVariable->Variant.varUint32 = pMyObject->ulNextInstance;

        returnStatus =
            pPoamIrepFoDdns->AddRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoDdns,
                    COSA_DML_RR_NAME_DdnsServiceNextInsNumber,
                    SYS_REP_RECORD_TYPE_UINT,
                    SYS_RECORD_CONTENT_DEFAULT,
                    pSlapVariable,
                    0
                );

        SlapCleanVariable(pSlapVariable);
        SlapInitVariable (pSlapVariable);
    }

    if ( TRUE )
    {
        pPoamIrepFoDdnsSp =
            pPoamIrepFoDdns->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoDdns,
                    pDdnsService->Alias,
                    0
                );

        if ( !pPoamIrepFoDdnsSp )
        {
            returnStatus = ANSC_STATUS_FAILURE;

            goto  EXIT1;
        }

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

            returnStatus =
                pPoamIrepFoDdnsSp->AddRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoDdnsSp,
                        COSA_DML_RR_NAME_DdnsServiceInsNum,
                        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(pDdnsService->Alias);

            returnStatus =
                pPoamIrepFoDdnsSp->AddRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoDdnsSp,
                        COSA_DML_RR_NAME_DdnsServiceAlias,
                        SYS_REP_RECORD_TYPE_ASTR,
                        SYS_RECORD_CONTENT_DEFAULT,
                        pSlapVariable,
                        0
                    );

            SlapCleanVariable(pSlapVariable);
            SlapInitVariable (pSlapVariable);
        }

        pCosaContext->hPoamIrepUpperFo = (ANSC_HANDLE)pPoamIrepFoDdns;
        pCosaContext->hPoamIrepFo      = (ANSC_HANDLE)pPoamIrepFoDdnsSp;
    }

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

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

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

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

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

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

        SlapAllocVariable(pSlapVariable);

        if ( !pSlapVariable )
        {
            returnStatus = ANSC_STATUS_RESOURCES;

            goto  EXIT1;
        }
    }

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

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

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

        pCosaUser = (PCOSA_DML_USER)pCosaUserContext->hContext;

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

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

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

        if ( !pPoamIrepFoEnumUser )
        {
            continue;
        }

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

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

            SlapCleanVariable(pSlapVariable);
            SlapInitVariable (pSlapVariable);
        }

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

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

            SlapCleanVariable(pSlapVariable);
            SlapInitVariable (pSlapVariable);
        }
       

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

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

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

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

    return returnStatus;
}
ANSC_STATUS
DslhVarroNotifyValueChanged
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus        = ANSC_STATUS_SUCCESS;
    PDSLH_VAR_RECORD_OBJECT         pMyObject           = (PDSLH_VAR_RECORD_OBJECT      )hThisObject;
    PDSLH_OBJ_RECORD_OBJECT         pObjRecord          = (PDSLH_OBJ_RECORD_OBJECT      )pMyObject->hDslhObjRecord;
    PDSLH_CPE_CONTROLLER_OBJECT     pDslhCpeController  = (PDSLH_CPE_CONTROLLER_OBJECT  )pObjRecord->hDslhCpeController;
    PCCC_MBI_INTERFACE              pDslhMbiIf          = (PCCC_MBI_INTERFACE           )pDslhCpeController->GetInterfaceByName((ANSC_HANDLE)pDslhCpeController, CCC_MBI_INTERFACE_NAME);
    PDSLH_VAR_ENTITY_OBJECT         pVarEntity          = (PDSLH_VAR_ENTITY_OBJECT      )pMyObject->hDslhVarEntity;
    PSLAP_VARIABLE                  pNewValue           = (PSLAP_VARIABLE               )NULL;
    char*                           pParamFullName      = NULL;
    char*                           pAccessList         = NULL;

    if ( !pDslhMbiIf )
    {
        AnscTraceError(("DslhVarroNotifyValueChanged: pDslhMbiIf is NULL\n"));

        return ANSC_STATUS_FAILURE;
    }

    pParamFullName = pMyObject->GetFullName((ANSC_HANDLE)pMyObject);

    if ( pMyObject->TempParamValue )
    {
        SlapAllocVariable(pNewValue);

        if ( !pNewValue )
        {
            returnStatus = ANSC_STATUS_RESOURCES;

            return returnStatus;
        }
        
        SlapCloneVariable(pMyObject->TempParamValue, pNewValue);
    }
    else
    {
        /* New value has to be present all the time. Get current value */
        pNewValue = pMyObject->GetValue((ANSC_HANDLE)pMyObject);
    }
	if(pNewValue != NULL)
	{
		pNewValue->ReqSenderID = pMyObject->ReqSenderID;
	}
    pAccessList = AnscCloneString(pMyObject->AccessList);

    returnStatus =
        pDslhMbiIf->SendParameterValueChangeSignal
            (
                (void*)pDslhMbiIf->hOwnerContext,
                pParamFullName,
                pMyObject->OldParamValue,
                pNewValue,
                pAccessList
            );

    if ( pNewValue )
    {
        SlapFreeVariable(pNewValue);
    }

    if ( pParamFullName )
    {
        AnscFreeMemory(pParamFullName);
    }

    if ( pAccessList )
    {
        AnscFreeMemory(pAccessList);
    }

    return returnStatus;
}
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
CosaTSIPSubnetRegAddInfo
    (
        ANSC_HANDLE                 hThisObject,
        ANSC_HANDLE                 hCosaContext
    )
{
    ANSC_STATUS                     returnStatus            = ANSC_STATUS_SUCCESS;
    PCOSA_DATAMODEL_TSIP            pMyObject               = (PCOSA_DATAMODEL_TSIP     )hThisObject;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoTSIPSubnet   = (PPOAM_IREP_FOLDER_OBJECT )pMyObject->hIrepFolderTSIPSubnet;
    PPOAM_IREP_FOLDER_OBJECT        pPoamIrepFoTSIPSubnetSp = (PPOAM_IREP_FOLDER_OBJECT )NULL;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaContext            = (PCOSA_CONTEXT_LINK_OBJECT)hCosaContext;
    PCOSA_DML_TSIP_SUBNET_ENTRY     pEntry                  = (PCOSA_DML_TSIP_SUBNET_ENTRY)pCosaContext->hContext;
    PSLAP_VARIABLE                  pSlapVariable           = (PSLAP_VARIABLE           )NULL;

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

    if ( TRUE )
    {
        SlapAllocVariable(pSlapVariable);

        if ( !pSlapVariable )
        {
            returnStatus = ANSC_STATUS_RESOURCES;

            goto  EXIT1;
        }
    }

    if ( TRUE )
    {
        returnStatus = 
            pPoamIrepFoTSIPSubnet->DelRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoTSIPSubnet,
                    COSA_DML_RR_NAME_TSIP_SUBNETNextInsNunmber
                );

        pSlapVariable->Syntax            = SLAP_VAR_SYNTAX_uint32;
        pSlapVariable->Variant.varUint32 = pMyObject->ulSubnetNextInsNum;

        returnStatus =
            pPoamIrepFoTSIPSubnet->AddRecord
                (
                    (ANSC_HANDLE)pPoamIrepFoTSIPSubnet,
                    COSA_DML_RR_NAME_TSIP_SUBNETNextInsNunmber,
                    SYS_REP_RECORD_TYPE_UINT,
                    SYS_RECORD_CONTENT_DEFAULT,
                    pSlapVariable,
                    0
                );

        SlapCleanVariable(pSlapVariable);
        SlapInitVariable (pSlapVariable);
    }

    if ( TRUE )
    {
        pPoamIrepFoTSIPSubnetSp =
            pPoamIrepFoTSIPSubnet->AddFolder
                (
                    (ANSC_HANDLE)pPoamIrepFoTSIPSubnet,
                    pEntry->Alias,
                    0
                );

        if ( !pPoamIrepFoTSIPSubnetSp )
        {
            returnStatus = ANSC_STATUS_FAILURE;

            goto  EXIT1;
        }

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

            returnStatus =
                pPoamIrepFoTSIPSubnetSp->AddRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoTSIPSubnetSp,
                        COSA_DML_RR_NAME_TSIP_SUBNETInsNum,
                        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(pEntry->Alias);

            returnStatus =
                pPoamIrepFoTSIPSubnetSp->AddRecord
                    (
                        (ANSC_HANDLE)pPoamIrepFoTSIPSubnetSp,
                        COSA_DML_RR_NAME_TSIP_SUBNETAlias,
                        SYS_REP_RECORD_TYPE_ASTR,
                        SYS_RECORD_CONTENT_DEFAULT,
                        pSlapVariable,
                        0
                    );

            SlapCleanVariable(pSlapVariable);
            SlapInitVariable (pSlapVariable);
        }

        pCosaContext->hPoamIrepUpperFo = (ANSC_HANDLE)pPoamIrepFoTSIPSubnet;
        pCosaContext->hPoamIrepFo      = (ANSC_HANDLE)pPoamIrepFoTSIPSubnetSp;
    }

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

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

    return returnStatus;
}