Ejemplo n.º 1
0
static ANSC_STATUS  
CcspTr069PaSsp_XML_GetMultipleItemWithSameName
    (
        PANSC_XML_DOM_NODE_OBJECT   pRootNode,
        char*                       ItemName,
        char**                      retVal
    )
{
    ANSC_STATUS                     returnStatus       = ANSC_STATUS_SUCCESS;
    PANSC_XML_DOM_NODE_OBJECT       pChildNode         = (PANSC_XML_DOM_NODE_OBJECT)NULL;
    char                            buffer[512]        = {0};
    ULONG                           uLength            = 511; 
    
    if (pRootNode && ItemName && retVal)
    {
        if(*retVal) { CcspTr069PaFreeMemory(*retVal); *retVal = NULL; }
        
        pChildNode = (PANSC_XML_DOM_NODE_OBJECT)
            AnscXmlDomNodeGetChildByName(pRootNode, ItemName);
        
        while( pChildNode != NULL)
        {
            if (AnscEqualString(pChildNode->Name, ItemName, TRUE))
            {
                uLength = 511;  // uLength: passes in max buffer length; gets out actual length
                
                if (pChildNode->GetDataString(pChildNode, NULL, buffer, &uLength) == ANSC_STATUS_SUCCESS && 
                    uLength > 0) 
                {
                    if(*retVal) 
                    {
                        char* sptr = (char*)CcspTr069PaAllocateMemory(AnscSizeOfString(*retVal)+1+uLength+1);
                        if(sptr == NULL) 
                        {
                            CcspTr069PaTraceWarning(("Failed to reallocate returnCA\n"));
                            CcspTr069PaFreeMemory(*retVal);
                            *retVal = NULL;
                            returnStatus =  ANSC_STATUS_RESOURCES;
                            goto EXIT;
                        }

                        _ansc_sprintf(sptr, "%s,%s", *retVal, buffer);
                        CcspTr069PaFreeMemory(*retVal);
                        *retVal = sptr;
                    }
                    else *retVal = CcspTr069PaCloneString(buffer);
                }
            }
            
            pChildNode = (PANSC_XML_DOM_NODE_OBJECT) AnscXmlDomNodeGetNextChild(pRootNode, pChildNode);
        }
        CcspTr069PaTraceDebug(("%s: %s = %s\n", __FUNCTION__, (ItemName)?(ItemName):"NULL", (*retVal)?(*retVal):"NULL"));
        //        fprintf(stderr, "%s: %s = %s\n", __FUNCTION__, (ItemName)?(ItemName):"NULL", (*retVal)?(*retVal):"NULL");
    }

 EXIT:
    return returnStatus;
}
/**********************************************************************

    prototype:

        ANSC_STATUS
        CcspCwmpSoappoUtilProcessErrorRequest
            (
                ANSC_HANDLE                 hCcspCwmpMcoIf,
                char*                       pRequestID,
                char*                       pMethodName
            )

    description:

        This function is called to process error requests..

    argument:
                ANSC_HANDLE                 hCcspCwmpMcoIf,
                The CCSP CWMP MCO interface handle;

                char*                       pRequestID,
                The request id;

                char*                       pMethodName,
                The request method name;

    return:     The status of the operation;

**********************************************************************/
ANSC_STATUS
CcspCwmpSoappoUtilProcessInvalidArgumentRequest
    (
        ANSC_HANDLE                 hCcspCwmpMcoIf,
        char*                       pRequestID,
        char*                       pMethodName
    )
{
    ANSC_STATUS                     returnStatus     = ANSC_STATUS_SUCCESS;
    PCCSP_CWMP_SOAP_FAULT           pCwmpSoapFault   = (PCCSP_CWMP_SOAP_FAULT)NULL;
    PCCSP_CWMP_MCO_INTERFACE             pCcspCwmpMcoIf       = (PCCSP_CWMP_MCO_INTERFACE)hCcspCwmpMcoIf;

    pCwmpSoapFault = (PCCSP_CWMP_SOAP_FAULT)CcspTr069PaAllocateMemory(sizeof(CCSP_CWMP_SOAP_FAULT));

    if ( !pCwmpSoapFault )
    {
        return returnStatus;
    }
    else
    {
        pCwmpSoapFault->soap_faultcode           = CcspTr069PaCloneString(CCSP_CWMP_CPE_SOAP_faultcode_invalidArgs);
        pCwmpSoapFault->soap_faultstring         = CcspTr069PaCloneString(CCSP_CWMP_CPE_SOAP_faulttext_invalidArgs);
        pCwmpSoapFault->Fault.FaultCode          = CCSP_CWMP_CPE_CWMP_FaultCode_invalidArgs;
        pCwmpSoapFault->Fault.FaultString        = CcspTr069PaCloneString(CCSP_CWMP_CPE_CWMP_FaultText_invalidArgs);
        pCwmpSoapFault->SetParamValuesFaultCount = 0;
    }

    if( pCcspCwmpMcoIf != NULL)
    {
        returnStatus =
            pCcspCwmpMcoIf->ProcessSoapError
                (
                    pCcspCwmpMcoIf->hOwnerContext,
                    pRequestID,
                    pMethodName,
                    (ANSC_HANDLE)pCwmpSoapFault
                );
    }

    if ( pCwmpSoapFault )
    {
        CcspCwmpFreeSoapFault(pCwmpSoapFault);
    }

    return returnStatus;
}
Ejemplo n.º 3
0
ANSC_HANDLE
CcspCwmpsoCreate
    (
        ANSC_HANDLE                 hContainerContext,
        ANSC_HANDLE                 hOwnerContext,
        ANSC_HANDLE                 hAnscReserved
    )
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PANSC_COMPONENT_OBJECT          pBaseObject  = NULL;
    PCCSP_CWMP_SESSION_OBJECT        pMyObject    = NULL;

    /*
     * We create object by first allocating memory for holding the variables and member functions.
     */
    pMyObject = (PCCSP_CWMP_SESSION_OBJECT)CcspTr069PaAllocateMemory(sizeof(CCSP_CWMP_SESSION_OBJECT));

    if ( !pMyObject )
    {
        return  (ANSC_HANDLE)NULL;
    }
    else
    {
        pBaseObject = (PANSC_COMPONENT_OBJECT)pMyObject;
    }

    /*
     * Initialize the common variables and functions for a container object.
     */
    /* AnscCopyString(pBaseObject->Name, CCSP_CWMP_SESSION_NAME); */

    pBaseObject->hContainerContext = hContainerContext;
    pBaseObject->hOwnerContext     = hOwnerContext;
    pBaseObject->Oid               = CCSP_CWMP_SESSION_OID;
    pBaseObject->Create            = CcspCwmpsoCreate;
    pBaseObject->Remove            = CcspCwmpsoRemove;
    pBaseObject->EnrollObjects     = CcspCwmpsoEnrollObjects;
    pBaseObject->Initialize        = CcspCwmpsoInitialize;

    pBaseObject->EnrollObjects((ANSC_HANDLE)pBaseObject);
    pBaseObject->Initialize   ((ANSC_HANDLE)pBaseObject);

    return  (ANSC_HANDLE)pMyObject;
}
/**********************************************************************

    prototype:

        ANSC_STATUS
        CcspCwmpSoappoUtilProcessTooManyEnvelopes
            (
                ANSC_HANDLE                 hCcspCwmpMcoIf
            )

    description:

        This function is called to process error requests..

    argument:
                ANSC_HANDLE                 hCcspCwmpMcoIf,
                The CCSP CWMP MCO interface handle;

    return:     The status of the operation;

**********************************************************************/
ANSC_STATUS
CcspCwmpSoappoUtilProcessTooManyEnvelopes
    (
        ANSC_HANDLE                 hCcspCwmpMcoIf
    )
{
    ANSC_STATUS                     returnStatus     = ANSC_STATUS_SUCCESS;
    PCCSP_CWMP_SOAP_FAULT           pCwmpSoapFault   = (PCCSP_CWMP_SOAP_FAULT)NULL;
    PCCSP_CWMP_MCO_INTERFACE             pCcspCwmpMcoIf       = (PCCSP_CWMP_MCO_INTERFACE)hCcspCwmpMcoIf;

    pCwmpSoapFault = (PCCSP_CWMP_SOAP_FAULT)CcspTr069PaAllocateMemory(sizeof(CCSP_CWMP_SOAP_FAULT));

    if ( !pCwmpSoapFault )
    {
        return returnStatus;
    }
    else
    {
        pCwmpSoapFault->soap_faultcode           = CcspTr069PaCloneString(CCSP_CWMP_CPE_SOAP_faultcode_maxEnvExceeded);
        pCwmpSoapFault->soap_faultstring         = CcspTr069PaCloneString(CCSP_CWMP_CPE_SOAP_faulttext_maxEnvExceeded);
        pCwmpSoapFault->Fault.FaultCode          = CCSP_CWMP_CPE_CWMP_FaultCode_maxEnvExceeded;
        pCwmpSoapFault->Fault.FaultString        = CcspTr069PaCloneString(CCSP_CWMP_CPE_CWMP_FaultText_maxEnvExceeded);
        pCwmpSoapFault->SetParamValuesFaultCount = 0;
    }

    if( pCcspCwmpMcoIf != NULL)
    {
        returnStatus =
            pCcspCwmpMcoIf->ProcessSoapError
                (
                    pCcspCwmpMcoIf->hOwnerContext,
                    NULL,
                    NULL,
                    (ANSC_HANDLE)pCwmpSoapFault
                );
    }

    if ( pCwmpSoapFault )
    {
        CcspCwmpFreeSoapFault(pCwmpSoapFault);
    }

    return returnStatus;
}
ANSC_HANDLE
CcspCwmppoGetPeriodicInformTime
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus        = ANSC_STATUS_SUCCESS;
    PCCSP_CWMP_PROCESSOR_OBJECT      pMyObject           = (PCCSP_CWMP_PROCESSOR_OBJECT  )hThisObject;
    PCCSP_CWMP_CPE_CONTROLLER_OBJECT pCcspCwmpCpeController  = (PCCSP_CWMP_CPE_CONTROLLER_OBJECT )pMyObject->hCcspCwmpCpeController;
    PCCSP_CWMP_PROCESSOR_PROPERTY    pProperty           = (PCCSP_CWMP_PROCESSOR_PROPERTY)&pMyObject->Property;
    PANSC_UNIVERSAL_TIME            pInformTime          = NULL;
    PANSC_UNIVERSAL_TIME            pCalendarTime       = NULL;
    char*                           pPeriodicInformTime = NULL;

	pInformTime = (PANSC_UNIVERSAL_TIME)CcspTr069PaAllocateMemory(sizeof(ANSC_UNIVERSAL_TIME));

	if ( !pInformTime ) return NULL;
    AnscZeroMemory(pInformTime, sizeof(ANSC_UNIVERSAL_TIME));
    
	pPeriodicInformTime = 
        CcspManagementServer_GetPeriodicInformTimeStr
            (
                pCcspCwmpCpeController->PANameWithPrefix
            );

    if ( pPeriodicInformTime && AnscSizeOfString(pPeriodicInformTime) != 0 )
    {
        pCalendarTime = CcspStringToCalendarTime(pPeriodicInformTime);

        if ( pCalendarTime )
        {
            *pInformTime = *pCalendarTime;
            CcspTr069PaFreeMemory(pCalendarTime);
        }
    }

    if ( pPeriodicInformTime )
    {
        CcspTr069PaFreeMemory(pPeriodicInformTime);
    }

    return  (ANSC_HANDLE)pInformTime;
}
ANSC_STATUS
CcspCwmpTcpcrhoEnrollObjects
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus  = ANSC_STATUS_SUCCESS;
    PCCSP_CWMP_TCPCR_HANDLER_OBJECT      pMyObject     = (PCCSP_CWMP_TCPCR_HANDLER_OBJECT    )hThisObject;
    PANSC_DSTO_WORKER_OBJECT        pDstoWorker   = (PANSC_DSTO_WORKER_OBJECT      )pMyObject->hDstoWorker;

    if ( !pDstoWorker )
    {
        pDstoWorker = (PANSC_DSTO_WORKER_OBJECT)CcspTr069PaAllocateMemory(sizeof(ANSC_DSTO_WORKER_OBJECT));

        if ( !pDstoWorker )
        {
            return  ANSC_STATUS_RESOURCES;
        }
        else
        {
            pMyObject->hDstoWorker = (ANSC_HANDLE)pDstoWorker;
        }

        pDstoWorker->hWorkerContext = (ANSC_HANDLE)pMyObject;
        pDstoWorker->Init           = CcspCwmpTcpcrhoWorkerInit;
        pDstoWorker->Unload         = CcspCwmpTcpcrhoWorkerUnload;

        pDstoWorker->Accept         = CcspCwmpTcpcrhoDstowoAccept;
        pDstoWorker->SetOut         = CcspCwmpTcpcrhoDstowoSetOut;
        pDstoWorker->Remove         = CcspCwmpTcpcrhoDstowoRemove;
        pDstoWorker->Query          = CcspCwmpTcpcrhoDstowoQuery;
        pDstoWorker->ProcessSync    = CcspCwmpTcpcrhoDstowoProcessSync;
        pDstoWorker->ProcessAsync   = CcspCwmpTcpcrhoDstowoProcessAsync;
        pDstoWorker->SendComplete   = CcspCwmpTcpcrhoDstowoSendComplete;
        pDstoWorker->Notify         = CcspCwmpTcpcrhoDstowoNotify;
    }

    AnscCoEnrollObjects((ANSC_HANDLE)pMyObject);

    return  ANSC_STATUS_SUCCESS;
}
ANSC_STATUS
CcspCwmpsoAddModifiedParameter
    (
        ANSC_HANDLE                 hThisObject,
        char*                       pParamName,
        char*                       pParamValue,
        ULONG                       CwmpDataType,
        BOOL                        bConnectNow
    )
{
    ANSC_STATUS                     returnStatus       		= ANSC_STATUS_SUCCESS;
    PCCSP_CWMP_SESSION_OBJECT       pMyObject          		= (PCCSP_CWMP_SESSION_OBJECT)hThisObject;
    PCCSP_CWMP_ACS_CONNECTION_OBJECT     
									pCcspCwmpAcsConnection 	= (PCCSP_CWMP_ACS_CONNECTION_OBJECT)pMyObject->hCcspCwmpAcsConnection;
    PCCSP_CWMP_CPE_CONTROLLER_OBJECT     
									pCcspCwmpCpeController 	= (PCCSP_CWMP_CPE_CONTROLLER_OBJECT)pMyObject->hCcspCwmpCpeController;
    PCCSP_CWMP_PROCESSOR_OBJECT     pCcspCwmpProcessor  	= (PCCSP_CWMP_PROCESSOR_OBJECT)pMyObject->hCcspCwmpProcessor;
    ULONG                           i                  		= 0;
    ULONG                           bExist             		= FALSE;

    CcspTr069PaTraceDebug(("AddModifiedParameter - '%s'\n", pParamName));

    if ( pMyObject->ModifiedParamCount >= CCSP_CWMPSO_MAX_PARAM_NUMBER )
    {
        CcspTr069PaFreeMemory(pParamName);

        return  ANSC_STATUS_RESOURCES;
    }

    for ( i = 0; i < pMyObject->ModifiedParamCount; i++ )
    {
        if ( pMyObject->ModifiedParamArray[i] )
        {
            if ( AnscEqualString
                    (
                        pParamName,
                        pMyObject->ModifiedParamArray[i],
                        TRUE
                    ) )
            {
                bExist = TRUE;

                if ( pMyObject->ModifiedParamValueArray[i] )
                {
                    CcspTr069PaFreeMemory(pMyObject->ModifiedParamValueArray[i]);
                }

                pMyObject->ModifiedParamValueArray[i] = CcspTr069PaCloneString(pParamValue);
                pMyObject->ModifiedParamTypeArray [i] = CwmpDataType;

                break;
            }
        }
    }

    if( !bExist)
    {
        pMyObject->ModifiedParamArray     [pMyObject->ModifiedParamCount]   = CcspTr069PaCloneString(pParamName);
        pMyObject->ModifiedParamValueArray[pMyObject->ModifiedParamCount]   = CcspTr069PaCloneString(pParamValue);
        pMyObject->ModifiedParamTypeArray [pMyObject->ModifiedParamCount++] = CwmpDataType;
    }

    /*
     * Bin: We are supposed to add "ValueChange" event for passive notification as well.
     */
    if ( TRUE )
    {
        PCCSP_CWMP_EVENT            pCcspCwmpEvent = (PCCSP_CWMP_EVENT)CcspTr069PaAllocateMemory(sizeof(CCSP_CWMP_EVENT));

        if ( !pCcspCwmpEvent )
        {
            return  ANSC_STATUS_RESOURCES;
        }
        else
        {
            pCcspCwmpEvent->EventCode  = CcspTr069PaCloneString(CCSP_CWMP_INFORM_EVENT_NAME_ValueChange);
            pCcspCwmpEvent->CommandKey = NULL;
        }

        returnStatus =
            pMyObject->AddCwmpEvent
                (
                    (ANSC_HANDLE)pMyObject,
                    pCcspCwmpEvent,
                    bConnectNow && pCcspCwmpCpeController->bBootInformSent
                );
    }

    return  returnStatus;
}
ANSC_STATUS
CcspCwmpAcscoHttpAddCookie
    (
        ANSC_HANDLE                 hThisObject,
        PCHAR                       pCookie
    )
{
    PCCSP_CWMP_ACS_CONNECTION_OBJECT pMyObject         = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)hThisObject;
    ANSC_STATUS                     returnStatus      = ANSC_STATUS_SUCCESS;
    PHTTP_SIMPLE_CLIENT_OBJECT      pHttpSimpleClient = (PHTTP_SIMPLE_CLIENT_OBJECT)pMyObject->hHttpSimpleClient;
    PHTTP_HFP_INTERFACE             pHttpHfpIf        = (PHTTP_HFP_INTERFACE)pHttpSimpleClient->GetHfpIf((ANSC_HANDLE)pHttpSimpleClient);
    char*                           pCookieValue      = NULL;
    PHTTP_HFO_SET_COOKIE            pHfoSetCookie     = NULL;

    if ( !pCookie || AnscSizeOfString(pCookie) <= 5)
    {
        CcspTr069PaTraceDebug(("!!!Empty Cookie, ignored.\n"));

        return ANSC_STATUS_SUCCESS;
    }

    if ( pMyObject->NumCookies >= CCSP_CWMP_ACSCO_MAX_COOKIE )
    {
        CcspTr069PaTraceDebug(("!!!Too many cookies, over the limit %d.\n", CCSP_CWMP_ACSCO_MAX_COOKIE));

        return ANSC_STATUS_DISCARD;
    }

    pCookieValue = (PCHAR)CcspTr069PaAllocateMemory(AnscSizeOfString(pCookie) + 64);

    if( NULL == pCookieValue )
    {
        return ANSC_STATUS_RESOURCES;
    }

    pHfoSetCookie = (PHTTP_HFO_SET_COOKIE)pHttpHfpIf->ParseHeader(pHttpHfpIf->hOwnerContext, pCookie, AnscSizeOfString(pCookie));

    if ( pHfoSetCookie )
    {
        ULONG                       ulCookieSize = 0;
        int                         nIndex;
        ULONG                       i;

        /* play a trick here - suppose the definitions of Cookie and Set-Cookie/2 are the same */
        pHfoSetCookie->HeaderId = HTTP_HEADER_ID_COOKIE;
        pHfoSetCookie->Flags &= ~HTTP_FIELD_FLAG_VALUE_PRESENT;
        pHfoSetCookie->Flags &= ~HTTP_FIELD_FLAG_LINE_PRESENT;

        ulCookieSize = pHttpHfpIf->GetHeaderSize(pHttpHfpIf->hOwnerContext, (ANSC_HANDLE)pHfoSetCookie);
        pHttpHfpIf->BuildHeader(pHttpHfpIf->hOwnerContext, (ANSC_HANDLE)pHfoSetCookie, pCookieValue, ulCookieSize);
        pCookieValue[ulCookieSize] = 0;

        /* remove old cookies */
        for ( i = 0; i < pHfoSetCookie->CookieCount; i ++ )
        {
            nIndex = pMyObject->FindCookie((ANSC_HANDLE)pMyObject, pHfoSetCookie->CookieArray[i].Name);
            if ( nIndex >= 0 )
            {
                pMyObject->DelCookie((ANSC_HANDLE)pMyObject, (ULONG)nIndex);
            }
        }

        pMyObject->Cookies[pMyObject->NumCookies++] = CcspTr069PaCloneString(pCookieValue + 8);

        CcspTr069PaFreeMemory(pHfoSetCookie);
    }

    CcspTr069PaFreeMemory(pCookieValue);

    return returnStatus;
}
ANSC_STATUS
CcspCwmpAcscoHttpBspBrowse
    (
        ANSC_HANDLE                 hThisObject,
        ANSC_HANDLE                 hBmoReq,
        ANSC_HANDLE                 hBmoRep,
        ANSC_HANDLE                 hReqContext
    )
{
    ANSC_STATUS                     returnStatus      = ANSC_STATUS_SUCCESS;
    PCCSP_CWMP_ACS_CONNECTION_OBJECT pMyObject         = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)hThisObject;
    PHTTP_BMO_REQ_OBJECT            pHttpBmoReq       = (PHTTP_BMO_REQ_OBJECT      )hBmoReq;
    PHTTP_BMO_REP_OBJECT            pHttpBmoRep       = (PHTTP_BMO_REP_OBJECT      )hBmoRep;
    PANSC_ACS_INTERN_HTTP_CONTENT   pHttpGetReq       = (PANSC_ACS_INTERN_HTTP_CONTENT )hReqContext;
    PHTTP_RESPONSE_INFO             pHttpRepInfo      = (PHTTP_RESPONSE_INFO       )pHttpBmoRep->GetRepInfo ((ANSC_HANDLE)pHttpBmoRep);
    ULONG                           ulResponseSize    = (ULONG                     )pHttpBmoRep->GetBodySize((ANSC_HANDLE)pHttpBmoRep);
    char*                           pHttpResponse     = (char*                     )NULL;
    char*                           pHeaderLocation   = NULL;
    char*                           pCookie           = NULL;
    ULONG                           ulCode            = 0;
    char*                           pCookieHeader     = NULL;
    ULONG                           ulCookieIndex     = 0;
    BOOL                            bCookiesRemoved   = FALSE;

    if ( pHttpGetReq == NULL)
    {
        return ANSC_STATUS_FAILURE;
    }

    ulCode = pHttpBmoRep->GetCode((ANSC_HANDLE)pHttpBmoRep);

    if( HTTP_STATUS_NO_CONTENT == ulCode) /* ACS has nothing to say */
    {
        if( pHttpGetReq != NULL)
        {
            pHttpGetReq->ulContentSize = 0;
            pHttpGetReq->pContent      = NULL;
            pHttpGetReq->bIsRedirect   = FALSE;
        }

        returnStatus = ANSC_STATUS_SUCCESS;

        goto EXIT1;
    }
    else if( HTTP_STATUS_MOVED_PERMANENTLY != ulCode &&
             HTTP_STATUS_FOUND != ulCode             &&
             HTTP_STATUS_OK != ulCode                &&
             HTTP_STATUS_UNAUTHORIZED != ulCode		 &&
			 HTTP_STATUS_TEMP_REDIRECT != ulCode
           )
    {
        returnStatus = ANSC_STATUS_FAILURE;

        CcspTr069PaTraceDebug(("HttpClient returned code: %d\n", (int)ulCode));

        goto  EXIT1;
    }

    /* save Authorization header value */
    if ( TRUE )
    {
        char*                       pAuthHeaderValue   = NULL;

        /* Authorization header in request */
        pAuthHeaderValue = pHttpBmoReq->GetHeaderValueById((ANSC_HANDLE)pHttpBmoReq, HTTP_HEADER_ID_AUTHORIZATION);

        if ( pMyObject->AuthHeaderValue ) CcspTr069PaFreeMemory(pMyObject->AuthHeaderValue);
        pMyObject->AuthHeaderValue = CcspTr069PaCloneString(pAuthHeaderValue);
    }

    /* look for Set-Cookie headers */
    pCookie = pHttpBmoRep->GetHeaderValueById2((ANSC_HANDLE)pHttpBmoRep, HTTP_HEADER_ID_SET_COOKIE2, ulCookieIndex);

    if ( pCookie && AnscSizeOfString(pCookie) > 0 )
    {
        /*
        pMyObject->RemoveCookies((ANSC_HANDLE)pMyObject);
        bCookiesRemoved = TRUE;
        */

        while ( pCookie != NULL && AnscSizeOfString(pCookie) > 0)
        {
            pCookieHeader = CcspTr069PaAllocateMemory(AnscSizeOfString(pCookie) + 16);

            if ( pCookieHeader )
                _ansc_sprintf(pCookieHeader, "Set-Cookie2: %s", pCookie);

            pMyObject->AddCookie((ANSC_HANDLE)pMyObject, pCookieHeader);
            CcspTr069PaFreeMemory(pCookieHeader);

            pCookie = pHttpBmoRep->GetHeaderValueById2((ANSC_HANDLE)pHttpBmoRep, HTTP_HEADER_ID_SET_COOKIE2, ++ulCookieIndex);
        }
    }

    /* If Set-Cookie and Set-Cookie2 co-exist happily, we save them all */
    ulCookieIndex = 0;
    pCookie = pHttpBmoRep->GetHeaderValueById2((ANSC_HANDLE)pHttpBmoRep, HTTP_HEADER_ID_SET_COOKIE, ulCookieIndex);

    if( pCookie != NULL && AnscSizeOfString(pCookie) > 0)
    {
        /*
        if ( !bCookiesRemoved )
        {
            pMyObject->RemoveCookies((ANSC_HANDLE)pMyObject);
            bCookiesRemoved = TRUE;
        }
        */

        while ( pCookie && AnscSizeOfString(pCookie) )
        {
            pCookieHeader = CcspTr069PaAllocateMemory(AnscSizeOfString(pCookie) + 16);

            if ( pCookieHeader )
                _ansc_sprintf(pCookieHeader, "Set-Cookie: %s", pCookie);

            pMyObject->AddCookie((ANSC_HANDLE)pMyObject, pCookieHeader);
            CcspTr069PaFreeMemory(pCookieHeader);

            pCookie = pHttpBmoRep->GetHeaderValueById2((ANSC_HANDLE)pHttpBmoRep, HTTP_HEADER_ID_SET_COOKIE, ++ulCookieIndex);
        }
    }

    /*
    if ( !bCookiesRemoved )
    {
        CcspTr069PaTraceDebug(("No Cookie in the response.\n"));

        if( pMyObject->NumCookies != 0)
        {
            for ( i = 0; i < pMyObject->NumCookies; i ++ )
            {
                CcspTr069PaTraceDebug(("Keep the old cookie: %s\n", pMyObject->Cookies[i]));
            }
        }
        else
        {
            CcspTr069PaTraceDebug(("???No cookie exists...\n"));
        }
    }
    */

    if( HTTP_STATUS_UNAUTHORIZED == ulCode)
    {
        /* make sure if server sends back challenge, terminates the session if otherwise */
        char*                       pWwwAuth = NULL;

        pHttpGetReq->bUnauthorized = TRUE;
        
        pWwwAuth = pHttpBmoRep->GetHeaderValueByName((ANSC_HANDLE)pHttpBmoRep, "WWW-Authenticate");
        if ( pWwwAuth )
        {
            returnStatus = ANSC_STATUS_DO_IT_AGAIN; /* ANSC_STATUS_SUCCESS; */
        }
        else
        {
            returnStatus = ANSC_STATUS_FAILURE;
        }

        goto EXIT1;
    }

    if( ulCode == HTTP_STATUS_MOVED_PERMANENTLY || HTTP_STATUS_FOUND == ulCode || HTTP_STATUS_TEMP_REDIRECT == ulCode)
    {
        pHeaderLocation     = pHttpBmoRep->GetHeaderValueByName((ANSC_HANDLE)pHttpBmoRep, "Location"     );

        if( pHeaderLocation == NULL || AnscSizeOfString(pHeaderLocation) == 0)
        {
            returnStatus = ANSC_STATUS_FAILURE;

            goto  EXIT1;
        }

        CcspTr069PaTraceInfo(("ACS URL moved (HTTP code=%u) to: %s\n", ulCode, pHeaderLocation));

        pHttpGetReq->ulContentSize = AnscSizeOfString(pHeaderLocation);
        pHttpGetReq->pContent      = CcspTr069PaCloneString(pHeaderLocation);
        pHttpGetReq->bIsRedirect   = TRUE;

        /* notify underlying HTTP Webc Transaction object to clearn request
         * otherwise, in case ACS closes the socket first, we will get notified
         * again and current session will be terminated prematurely.
         */
        returnStatus = ANSC_STATUS_NO_MORE_DATA;
    }
    else
    {
        if ( ulResponseSize == 0 )
        {
             returnStatus = ANSC_STATUS_FAILURE;

            goto  EXIT1;
        }
        else
        {
            pHttpResponse = (char*)CcspTr069PaAllocateMemory(ulResponseSize + 1);  /* we must leave room for the NULL terminator */

            if ( !pHttpResponse )
            {
                returnStatus = ANSC_STATUS_RESOURCES;

                goto  EXIT1;
            }
            else
            {
                returnStatus =
                    pHttpBmoRep->CopyBodyFrom
                        (
                            (ANSC_HANDLE)pHttpBmoRep,
                            pHttpResponse,
                            &ulResponseSize
                        );
            }
        }

        pHttpGetReq->ulContentSize = ulResponseSize;
        pHttpGetReq->pContent      = (PVOID)pHttpResponse;
        pHttpGetReq->bIsRedirect   = FALSE;
    }

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

EXIT1:

    if ( pHttpGetReq )
    {
        pHttpGetReq->CompleteStatus = 
            (returnStatus == ANSC_STATUS_DO_IT_AGAIN || returnStatus == ANSC_STATUS_NO_MORE_DATA) ? ANSC_STATUS_SUCCESS : returnStatus;

        AnscSetEvent(&pHttpGetReq->CompleteEvent);
    }

    return  returnStatus;
}
ANSC_STATUS
CcspCwmpAcscoHttpBspPolish
    (
        ANSC_HANDLE                 hThisObject,
        ANSC_HANDLE                 hBmoReq,
        ANSC_HANDLE                 hReqContext
    )
{
    PCCSP_CWMP_ACS_CONNECTION_OBJECT pMyObject       = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)hThisObject;
    PANSC_ACS_INTERN_HTTP_CONTENT    pHttpGetReq     = (PANSC_ACS_INTERN_HTTP_CONTENT)hReqContext;
    ANSC_STATUS                      returnStatus    = ANSC_STATUS_SUCCESS;
    PHTTP_BMO_REQ_OBJECT             pBmoReqObj      = (PHTTP_BMO_REQ_OBJECT)hBmoReq;
    char                             pBuffer[64]     = { 0 };
    ULONG                            i, len          = 0;

    /* add Authorization header - last good one */
    if ( pMyObject->AuthHeaderValue )
    {
        pBmoReqObj->SetHeaderValueByName((ANSC_HANDLE)pBmoReqObj, "Authorization", pMyObject->AuthHeaderValue);
    }

    /*
     * If there's a cookie returned, add the cookie
     */
    for ( i = 0; i < pMyObject->NumCookies; i ++ )
    {
    	if ( pMyObject->Cookies[i] == NULL )
    		break;

    	len += _ansc_strlen(pMyObject->Cookies[i]);
    }

    if ( pMyObject->NumCookies == 0 )
    {
        CcspTr069PaTraceDebug(("No Cookie will be added.\n"));
    }
    else
    {
    	char *cookies = (char *)CcspTr069PaAllocateMemory(len + pMyObject->NumCookies*2);

    	if (cookies) {
        	AnscZeroMemory(cookies, len + pMyObject->NumCookies*2);

            for ( i = 0; i < pMyObject->NumCookies; i ++ )
            {
            	if ( pMyObject->Cookies[i] == NULL )
            		break;

            	_ansc_strcat(cookies, pMyObject->Cookies[i]);
            	if ( i < pMyObject->NumCookies - 1 )
            		_ansc_strcat(cookies, "; ");
            }

            pBmoReqObj->SetHeaderValueByName
				(
					(ANSC_HANDLE)pBmoReqObj,
					"Cookie",
					cookies
				);

			CcspTr069PaTraceDebug(("Add Cookie into message: %s\n", cookies));
			CcspTr069PaFreeMemory(cookies);
    	}

    }

    /* When there is more than one envelope in a single HTTP Request,
     * when there is a SOAP response in an HTTP Request, or when there is a
     * SOAP Fault response in an HTTP Request, the SOAPAction header in the
     * HTTP Request MUST have no value (with no quotes), indicating that this
     * header provides no information as to the intent of the message."
     */
    if( pHttpGetReq ==NULL || pHttpGetReq->SoapMessage == NULL || AnscSizeOfString(pHttpGetReq->SoapMessage) == 0)
    {
        /*
         * An empty HTTP POST MUST NOT contain a SOAPAction header.
         * An empty HTTP POST MUST NOT contain a Content-Type header.
         */
        pBmoReqObj->SetHeaderValueByName((ANSC_HANDLE)pBmoReqObj, "Content-Length", "0");
        /* pBmoReqObj->SetHeaderValueByName((ANSC_HANDLE)pBmoReqObj, "Content-Type", "text/xml;charset=utf-8"); */
    }
    else
    {
        pBmoReqObj->SetHeaderValueByName((ANSC_HANDLE)pBmoReqObj, "Content-Type", "text/xml;charset=utf-8");

        _ansc_sprintf(pBuffer, "%u", (unsigned int)AnscSizeOfString(pHttpGetReq->SoapMessage));
        pBmoReqObj->SetHeaderValueByName((ANSC_HANDLE)pBmoReqObj, "Content-Length", pBuffer);

        if( pHttpGetReq->MethodName == NULL || AnscSizeOfString(pHttpGetReq->MethodName) == 0)
        {
            pBmoReqObj->SetHeaderValueByName((ANSC_HANDLE)pBmoReqObj, "SOAPAction", "");
        }
        else
        {
            _ansc_sprintf(pBuffer, "\"%s\"", pHttpGetReq->MethodName);
            pBmoReqObj->SetHeaderValueByName((ANSC_HANDLE)pBmoReqObj, "SOAPAction", pBuffer);
        }

        returnStatus =
            pBmoReqObj->AppendBody
                (
                    pBmoReqObj,
                    pHttpGetReq->SoapMessage,
                    AnscSizeOfString(pHttpGetReq->SoapMessage)
                );
    }

    return  returnStatus;
}
Ejemplo n.º 11
0
ANSC_STATUS
CcspCwmpsoEnrollObjects
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus       = ANSC_STATUS_SUCCESS;
    PCCSP_CWMP_SESSION_OBJECT       pMyObject          = (PCCSP_CWMP_SESSION_OBJECT    )hThisObject;
    PANSC_TIMER_DESCRIPTOR_OBJECT   pSessionTimerObj   = (PANSC_TIMER_DESCRIPTOR_OBJECT)pMyObject->hSessionTimerObj;
    PANSC_TDO_CLIENT_OBJECT         pSessionTimerIf    = (PANSC_TDO_CLIENT_OBJECT      )pMyObject->hSessionTimerIf;
    PCCSP_CWMP_ACS_CONNECTION_OBJECT pCcspCwmpAcsConnection 
													   = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)pMyObject->hCcspCwmpAcsConnection;
    PANSC_TIMER_DESCRIPTOR_OBJECT   pRetryTimerObj     = (PANSC_TIMER_DESCRIPTOR_OBJECT)pMyObject->hRetryTimerObj;
    PANSC_TDO_CLIENT_OBJECT         pRetryTimerIf      = (PANSC_TDO_CLIENT_OBJECT      )pMyObject->hRetryTimerIf;
    PANSC_TIMER_DESCRIPTOR_OBJECT   pDelayedActiveNotifTimerObj     
													   = (PANSC_TIMER_DESCRIPTOR_OBJECT)pMyObject->hDelayedActiveNotifTimerObj;
    PANSC_TDO_CLIENT_OBJECT         pDelayedActiveNotifTimerIf      
													   = (PANSC_TDO_CLIENT_OBJECT      )pMyObject->hDelayedActiveNotifTimerIf;
    PCCSP_CWMP_MCO_INTERFACE        pCcspCwmpMcoIf     = (PCCSP_CWMP_MCO_INTERFACE     )pMyObject->hCcspCwmpMcoIf;

    if ( !pSessionTimerObj )
    {
        pSessionTimerObj =
            (PANSC_TIMER_DESCRIPTOR_OBJECT)AnscCreateTimerDescriptor
                (
                    pMyObject->hContainerContext,
                    (ANSC_HANDLE)pMyObject,
                    (ANSC_HANDLE)NULL
                );

        if ( !pSessionTimerObj )
        {
            return  ANSC_STATUS_RESOURCES;
        }
        else
        {
            pMyObject->hSessionTimerObj = (ANSC_HANDLE)pSessionTimerObj;
        }

        pSessionTimerObj->SetTimerType((ANSC_HANDLE)pSessionTimerObj, ANSC_TIMER_TYPE_SPORADIC         );
        pSessionTimerObj->SetInterval ((ANSC_HANDLE)pSessionTimerObj, CCSP_CWMPSO_SESSION_TIMEOUT * 1000);
        /* _ansc_strcpy(pSessionTimerObj->Name, "CcspCwmpsoSessionTimer"); */

    }

    if ( !pSessionTimerIf )
    {
        pSessionTimerIf = (PANSC_TDO_CLIENT_OBJECT)CcspTr069PaAllocateMemory(sizeof(ANSC_TDO_CLIENT_OBJECT));

        if ( !pSessionTimerIf )
        {
            return  ANSC_STATUS_RESOURCES;
        }
        else
        {
            pMyObject->hSessionTimerIf = (ANSC_HANDLE)pSessionTimerIf;
        }

        pSessionTimerIf->hClientContext = (ANSC_HANDLE)pMyObject;
        pSessionTimerIf->Invoke         = CcspCwmpsoSessionTimerInvoke;

        pSessionTimerObj->SetClient((ANSC_HANDLE)pSessionTimerObj, (ANSC_HANDLE)pSessionTimerIf);
    }

    if ( !pRetryTimerObj )
    {
        /* use separate timer scehduler to run retry alg, otherwise, we will observe delays of timer expiration */
        pRetryTimerObj =
            (PANSC_TIMER_DESCRIPTOR_OBJECT)AnscCreateTimerDescriptor
                (
                    (ANSC_HANDLE)NULL, /* pMyObject->hContainerContext,*/ 
                    (ANSC_HANDLE)pMyObject,
                    (ANSC_HANDLE)NULL
                );

        if ( !pRetryTimerObj )
        {
            return  ANSC_STATUS_RESOURCES;
        }
        else
        {
            pMyObject->hRetryTimerObj = (ANSC_HANDLE)pRetryTimerObj;
        }

        pRetryTimerObj->SetTimerType((ANSC_HANDLE)pRetryTimerObj, ANSC_TIMER_TYPE_SPORADIC         );
        pRetryTimerObj->SetInterval ((ANSC_HANDLE)pRetryTimerObj, 1000 * 1000);
        /* _ansc_strcpy(pSessionTimerObj->Name, "CcspCwmpsoSessionRetryTimer"); */

    }

    if ( !pRetryTimerIf )
    {
        pRetryTimerIf = (PANSC_TDO_CLIENT_OBJECT)CcspTr069PaAllocateMemory(sizeof(ANSC_TDO_CLIENT_OBJECT));

        if ( !pRetryTimerIf )
        {
            return  ANSC_STATUS_RESOURCES;
        }
        else
        {
            pMyObject->hRetryTimerIf = (ANSC_HANDLE)pRetryTimerIf;
        }

        pRetryTimerIf->hClientContext = (ANSC_HANDLE)pMyObject;
        pRetryTimerIf->Invoke         = CcspCwmpsoSessionRetryTimerInvoke;

        pRetryTimerObj->SetClient((ANSC_HANDLE)pRetryTimerObj, (ANSC_HANDLE)pRetryTimerIf);
    }

    if ( !pDelayedActiveNotifTimerObj )
    {
        /* use separate timer scehduler to run retry alg, otherwise, we will observe delays of timer expiration */
        pDelayedActiveNotifTimerObj =
            (PANSC_TIMER_DESCRIPTOR_OBJECT)AnscCreateTimerDescriptor
                (
                    (ANSC_HANDLE)NULL, /* pMyObject->hContainerContext,*/ 
                    (ANSC_HANDLE)pMyObject,
                    (ANSC_HANDLE)NULL
                );

        if ( !pDelayedActiveNotifTimerObj )
        {
            return  ANSC_STATUS_RESOURCES;
        }
        else
        {
            pMyObject->hDelayedActiveNotifTimerObj = (ANSC_HANDLE)pDelayedActiveNotifTimerObj;
        }

        pDelayedActiveNotifTimerObj->SetTimerType((ANSC_HANDLE)pDelayedActiveNotifTimerObj, ANSC_TIMER_TYPE_SPORADIC);
        pDelayedActiveNotifTimerObj->SetInterval ((ANSC_HANDLE)pDelayedActiveNotifTimerObj, 5000 * 1000);
    }

    if ( !pDelayedActiveNotifTimerIf )
    {
        pDelayedActiveNotifTimerIf = (PANSC_TDO_CLIENT_OBJECT)CcspTr069PaAllocateMemory(sizeof(ANSC_TDO_CLIENT_OBJECT));

        if ( !pDelayedActiveNotifTimerIf )
        {
            return  ANSC_STATUS_RESOURCES;
        }
        else
        {
            pMyObject->hDelayedActiveNotifTimerIf = (ANSC_HANDLE)pDelayedActiveNotifTimerIf;
        }

        pDelayedActiveNotifTimerIf->hClientContext = (ANSC_HANDLE)pMyObject;
        pDelayedActiveNotifTimerIf->Invoke         = CcspCwmpsoDelayedActiveNotifTimerInvoke;

        pDelayedActiveNotifTimerObj->SetClient((ANSC_HANDLE)pDelayedActiveNotifTimerObj, (ANSC_HANDLE)pDelayedActiveNotifTimerIf);
    }


    if ( !pCcspCwmpAcsConnection )
    {
        pCcspCwmpAcsConnection =
            (PCCSP_CWMP_ACS_CONNECTION_OBJECT)CcspCwmpCreateAcsConnection
                (
                    pMyObject->hContainerContext,
                    (ANSC_HANDLE)pMyObject,
                    (ANSC_HANDLE)NULL
                );

        if ( !pCcspCwmpAcsConnection )
        {
            return  ANSC_STATUS_RESOURCES;
        }
        else
        {
            pMyObject->hCcspCwmpAcsConnection = (ANSC_HANDLE)pCcspCwmpAcsConnection;

            pCcspCwmpAcsConnection->SetCcspCwmpSession((ANSC_HANDLE)pCcspCwmpAcsConnection, (ANSC_HANDLE)pMyObject);
        }
    }

    if ( !pCcspCwmpMcoIf )
    {
        pCcspCwmpMcoIf = (PCCSP_CWMP_MCO_INTERFACE)CcspTr069PaAllocateMemory(sizeof(CCSP_CWMP_MCO_INTERFACE));

        if ( !pCcspCwmpMcoIf )
        {
            return  ANSC_STATUS_RESOURCES;
        }
        else
        {
            pMyObject->hCcspCwmpMcoIf = (ANSC_HANDLE)pCcspCwmpMcoIf;
        }

        AnscCopyString(pCcspCwmpMcoIf->Name, CCSP_CWMP_MCO_INTERFACE_NAME);

        pCcspCwmpMcoIf->InterfaceId            = CCSP_CWMP_MCO_INTERFACE_ID;
        pCcspCwmpMcoIf->hOwnerContext          = (ANSC_HANDLE)pMyObject;
        pCcspCwmpMcoIf->Size                   = sizeof(CCSP_CWMP_MCO_INTERFACE);

        pCcspCwmpMcoIf->NotifyAcsStatus        = CcspCwmpsoMcoNotifyAcsStatus;
        pCcspCwmpMcoIf->GetNextMethod          = CcspCwmpsoMcoGetNextMethod;
        pCcspCwmpMcoIf->ProcessSoapResponse    = CcspCwmpsoMcoProcessSoapResponse;
        pCcspCwmpMcoIf->ProcessSoapError       = CcspCwmpsoMcoProcessSoapError;
        pCcspCwmpMcoIf->InvokeUnknownMethod    = CcspCwmpsoMcoInvokeUnknownMethod;

        pCcspCwmpMcoIf->GetRpcMethods          = CcspCwmpsoMcoGetRpcMethods;
        pCcspCwmpMcoIf->SetParameterValues     = CcspCwmpsoMcoSetParameterValues;
        pCcspCwmpMcoIf->GetParameterValues     = CcspCwmpsoMcoGetParameterValues;
        pCcspCwmpMcoIf->GetParameterNames      = CcspCwmpsoMcoGetParameterNames;
        pCcspCwmpMcoIf->SetParameterAttributes = CcspCwmpsoMcoSetParameterAttributes;
        pCcspCwmpMcoIf->GetParameterAttributes = CcspCwmpsoMcoGetParameterAttributes;
        pCcspCwmpMcoIf->AddObject              = CcspCwmpsoMcoAddObject;
        pCcspCwmpMcoIf->DeleteObject           = CcspCwmpsoMcoDeleteObject;
        pCcspCwmpMcoIf->Download               = CcspCwmpsoMcoDownload;
        pCcspCwmpMcoIf->Reboot                 = CcspCwmpsoMcoReboot;

        pCcspCwmpMcoIf->GetQueuedTransfers     = CcspCwmpsoMcoGetQueuedTransfers;
        pCcspCwmpMcoIf->ScheduleInform         = CcspCwmpsoMcoScheduleInform;
        pCcspCwmpMcoIf->SetVouchers            = CcspCwmpsoMcoSetVouchers;
        pCcspCwmpMcoIf->GetOptions             = CcspCwmpsoMcoGetOptions;
        pCcspCwmpMcoIf->Upload                 = CcspCwmpsoMcoUpload;
        pCcspCwmpMcoIf->FactoryReset           = CcspCwmpsoMcoFactoryReset;
        pCcspCwmpMcoIf->ChangeDUState          = CcspCwmpsoMcoChangeDUState;

        pCcspCwmpMcoIf->GetParamDataType       = CcspCwmpsoMcoGetParamDataType;
    }

    AnscCoEnrollObjects((ANSC_HANDLE)pMyObject);

    return  ANSC_STATUS_SUCCESS;
}
Ejemplo n.º 12
0
ANSC_STATUS
CcspCwmpAcscoEnrollObjects
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus    = ANSC_STATUS_SUCCESS;
    PCCSP_CWMP_ACS_CONNECTION_OBJECT     pMyObject       = (PCCSP_CWMP_ACS_CONNECTION_OBJECT)hThisObject;
    PHTTP_BSP_INTERFACE             pHttpBspIf      = (PHTTP_BSP_INTERFACE    )pMyObject->hHttpBspIf;
    PHTTP_ACM_INTERFACE             pHttpAcmIf      = (PHTTP_ACM_INTERFACE    )pMyObject->hHttpAcmIf;
    PHTTP_SIMPLE_CLIENT_OBJECT      pHttpClient     = (PHTTP_SIMPLE_CLIENT_OBJECT)NULL;
    PHTTP_HFP_INTERFACE             pHttpHfpIf      = (PHTTP_HFP_INTERFACE)NULL;

    if ( !pHttpBspIf )
    {
        pHttpBspIf = (PHTTP_BSP_INTERFACE)CcspTr069PaAllocateMemory(sizeof(HTTP_BSP_INTERFACE));

        if ( !pHttpBspIf )
        {
            return  ANSC_STATUS_RESOURCES;
        }
        else
        {
            pMyObject->hHttpBspIf = (ANSC_HANDLE)pHttpBspIf;
        }

        AnscCopyString(pHttpBspIf->Name, HTTP_BSP_INTERFACE_NAME);

        pHttpBspIf->InterfaceId   = HTTP_BSP_INTERFACE_ID;
        pHttpBspIf->hOwnerContext = (ANSC_HANDLE)pMyObject;
        pHttpBspIf->Size          = sizeof(HTTP_BSP_INTERFACE);

        pHttpBspIf->Polish        = CcspCwmpAcscoHttpBspPolish;
        pHttpBspIf->Browse        = CcspCwmpAcscoHttpBspBrowse;
        pHttpBspIf->Notify        = CcspCwmpAcscoHttpBspNotify;
    }

    if ( !pHttpAcmIf )
    {
        pHttpAcmIf = (PHTTP_ACM_INTERFACE)CcspTr069PaAllocateMemory(sizeof(HTTP_ACM_INTERFACE));

        if ( !pHttpAcmIf )
        {
            return  ANSC_STATUS_RESOURCES;
        }
        else
        {
            pMyObject->hHttpAcmIf = (ANSC_HANDLE)pHttpAcmIf;
        }

        pHttpAcmIf->hOwnerContext = (ANSC_HANDLE)pMyObject;
        pHttpAcmIf->Size          = sizeof(HTTP_ACM_INTERFACE);

        pHttpAcmIf->GetCredential = CcspCwmpAcscoHttpGetCredential;
    }

    /*
     *  Create Http Simple Client
     */
    pHttpClient =
        (PHTTP_SIMPLE_CLIENT_OBJECT)HttpCreateSimpleClient
            (
                (ANSC_HANDLE)pMyObject->hHttpHelpContainer,
                (ANSC_HANDLE)pMyObject,
                (ANSC_HANDLE)NULL
            );


    if( pHttpClient == NULL)
    {
        return ANSC_STATUS_RESOURCES;
    }

    pHttpClient->SetProductName(pHttpClient, "HTTP Client V1.0");
    pHttpClient->SetBspIf((ANSC_HANDLE)pHttpClient, pMyObject->hHttpBspIf);
    pHttpClient->SetClientMode(pHttpClient, HTTP_SCO_MODE_XSOCKET | HTTP_SCO_MODE_COMPACT | HTTP_SCO_MODE_NOTIFY_ON_ALL_CONN_ONCE);

    pMyObject->hHttpSimpleClient = (ANSC_HANDLE)pHttpClient;

    AnscCoEnrollObjects((ANSC_HANDLE)pMyObject);

    return  ANSC_STATUS_SUCCESS;
}
/**********************************************************************

    prototype:

        ANSC_STATUS
        CcspCwmpSoappoUtilGetParamValue
            (
                ANSC_HANDLE                 hXmlHandle,
                ANSC_HANDLE                 hParamHandle
            );

    description:

        This function is called to get the parameter value from the
        xml handle.

    argument:
                ANSC_HANDLE                 hXmlHandle,
                The XML node;

                ANSC_HANDLE                 hParamHandle
                The parameter handle

    return:     the status of the operation.

**********************************************************************/
ANSC_STATUS
CcspCwmpSoappoUtilGetParamValue
    (
        ANSC_HANDLE                 hCcspCwmpMcoIf,
        ANSC_HANDLE                 hXmlHandle,
        ANSC_HANDLE                 hParamHandle
    )
{
    PCCSP_CWMP_MCO_INTERFACE        pCcspCwmpMcoIf = (PCCSP_CWMP_MCO_INTERFACE)hCcspCwmpMcoIf;
    PANSC_XML_DOM_NODE_OBJECT       pXmlNode     = (PANSC_XML_DOM_NODE_OBJECT)hXmlHandle;
    PANSC_XML_DOM_NODE_OBJECT       pNameNode    = (PANSC_XML_DOM_NODE_OBJECT)NULL;
    PANSC_XML_DOM_NODE_OBJECT       pValueNode   = (PANSC_XML_DOM_NODE_OBJECT)NULL;
    PCCSP_CWMP_PARAM_VALUE          pCwmpParam   = (PCCSP_CWMP_PARAM_VALUE)hParamHandle;
    PSLAP_VARIABLE                  pSlapVariable= (PSLAP_VARIABLE)NULL;
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    CHAR                            pValue[1024] = { 0 };
    ULONG                           dataType     = CCSP_CWMP_TR069_DATA_TYPE_Unspecified;
    ULONG                           length       = 1024;
    ULONG                           uLongValue   = 0;
    LONG                            longValue    = 0;
    BOOL                            bBool        = FALSE;
    BOOL                            bIsInteger   = FALSE;
    PANSC_XML_ATTRIBUTE             pAttribute   = NULL;
	char*							pDataType    = NULL;
    char                            pTemp[64]    = { 0 };
    CHAR                            pHugeValue[32000]
                                                 = { 0 };  /* Config file value could be as big as 32K */

    pCwmpParam->Value          = NULL;

    /***************************************************************************
    * Argument     | Type         | Description                               *
    ***************************************************************************
    * Name         | string(256)  | This is the name of a Parameter.          *
    *-------------------------------------------------------------------------*
    * Value        | any          | Teh is the value to be set               .*
    ***************************************************************************/

    pNameNode = (PANSC_XML_DOM_NODE_OBJECT)
		AnscXmlDomNodeGetHeadChild(pXmlNode);

    pValueNode = (PANSC_XML_DOM_NODE_OBJECT)
		AnscXmlDomNodeGetTailChild(pXmlNode);

    if( pNameNode == NULL || pValueNode == NULL || pNameNode == pValueNode)
    {
        CcspTr069PaTraceError(("Invalid arguments for ParameterValueStruct.\n"));

        return ANSC_STATUS_FAILURE;
    }

    /*
     * Get the name first;
     */
    length = 256;

    returnStatus =
    	AnscXmlDomNodeGetDataString
            (
                pNameNode,
                NULL,
                pValue,
                &length
            );

    if( returnStatus != ANSC_STATUS_SUCCESS)
    {
        CcspTr069PaTraceError(("Failed to get the parameter name.\n"));

        return returnStatus;
    }

	if( length == 0)
	{
		CcspTr069PaTraceError(("Empty parameter name in SetParameterValues.\n"));

		return ANSC_STATUS_FAILURE;
	}

    pCwmpParam->Name = CcspTr069PaCloneString(pValue);

    length = 1024;
    AnscZeroMemory(pValue, length);

    pSlapVariable = (PSLAP_VARIABLE)CcspTr069PaAllocateMemory(sizeof(SLAP_VARIABLE));

    if ( !pSlapVariable )
    {
        return ANSC_STATUS_RESOURCES;
    }

    SlapInitVariable(pSlapVariable);

    pCwmpParam->Value          = pSlapVariable;

    pSlapVariable->Name        = NULL;
    pSlapVariable->ContentType = 0;
    pSlapVariable->UsageType   = 0;

    /* check the value */
    length = 32000;

    returnStatus =
        AnscXmlDomNodeGetDataString
            (
                pValueNode,
                NULL,
                pHugeValue,
                &length
            );

    if( returnStatus != ANSC_STATUS_SUCCESS)
    {
        CcspTr069PaTraceError(("Failed to get the string parameter value.\n"));

        CcspTr069PaFreeMemory(pSlapVariable);

        pCwmpParam->Value = NULL;
    }
    else
    {
        pSlapVariable->ContentType       = SLAP_CONTENT_TYPE_UNSPECIFIED;
        pSlapVariable->UsageType         = 0;
        pSlapVariable->Syntax            = SLAP_VAR_SYNTAX_string;
        pSlapVariable->Variant.varString = CcspTr069PaCloneString(pHugeValue);
    }

    pCwmpParam->Tr069DataType = CCSP_CWMP_TR069_DATA_TYPE_Unspecified;

    /* retrieve data type */
    if ( TRUE )
    {
        PANSC_XML_ATTRIBUTE         pAttribute;
        
        pCwmpParam->Tr069DataType  = pCcspCwmpMcoIf->GetParamDataType(pCcspCwmpMcoIf->hOwnerContext, pCwmpParam->Name);
        pAttribute = (PANSC_XML_ATTRIBUTE)AnscXmlDomNodeGetFirstAttr(pValueNode);
        if ( pAttribute )
        {
            char*                   pDataType;

            AnscCopyMemory(pValue, pAttribute->StringData, pAttribute->DataSize);

            pDataType = _ansc_strstr(pValue, ":");

            if ( !pDataType )
            {
                pDataType = pValue;
            }
            else
            {
                pDataType ++;
            }

            if ( AnscEqualString(pDataType, CCSP_CWMP_DATA_NAME_string, TRUE) )
            {
                pCwmpParam->Tr069DataType = CCSP_CWMP_TR069_DATA_TYPE_String;
            }
            else if ( AnscEqualString(pDataType, CCSP_CWMP_DATA_NAME_int, TRUE) )
            {
                pCwmpParam->Tr069DataType = CCSP_CWMP_TR069_DATA_TYPE_Int;
            }
            else if ( AnscEqualString(pDataType, CCSP_CWMP_DATA_NAME_unsignedInt, TRUE) )
            {
                pCwmpParam->Tr069DataType = CCSP_CWMP_TR069_DATA_TYPE_UnsignedInt;
            }
            else if ( AnscEqualString(pDataType, CCSP_CWMP_DATA_NAME_boolean, TRUE) )
            {
                pCwmpParam->Tr069DataType = CCSP_CWMP_TR069_DATA_TYPE_Boolean;
            }
            else if ( AnscEqualString(pDataType, CCSP_CWMP_DATA_NAME_dateTime, TRUE) )
            {
                pCwmpParam->Tr069DataType = CCSP_CWMP_TR069_DATA_TYPE_DateTime;
            }
            else if ( AnscEqualString(pDataType, CCSP_CWMP_DATA_NAME_base64, TRUE) )
            {
                pCwmpParam->Tr069DataType = CCSP_CWMP_TR069_DATA_TYPE_Base64;
            }
            else
            {
                pCwmpParam->Tr069DataType = CCSP_CWMP_TR069_DATA_TYPE_Unspecified;
            }
        }
    }    

    if ( pCwmpParam->Tr069DataType == CCSP_CWMP_TR069_DATA_TYPE_Unspecified )
    {
        return  ANSC_STATUS_BAD_PARAMETER;
    }

    return ANSC_STATUS_SUCCESS;
}
ANSC_STATUS
CcspCwmpSoappoUtilProcessInvalidArgumentSPVRequest
    (
        ANSC_HANDLE                 hCcspCwmpMcoIf,
        char*                       pRequestID,
        char*                       pParamName,
        ULONG                       CwmpSpvFaultCode
    )
{
    ANSC_STATUS                     returnStatus     = ANSC_STATUS_SUCCESS;
    PCCSP_CWMP_SOAP_FAULT           pCwmpSoapFault   = (PCCSP_CWMP_SOAP_FAULT)NULL;
    PCCSP_CWMP_MCO_INTERFACE             pCcspCwmpMcoIf       = (PCCSP_CWMP_MCO_INTERFACE)hCcspCwmpMcoIf;

    pCwmpSoapFault = (PCCSP_CWMP_SOAP_FAULT)CcspTr069PaAllocateMemory(sizeof(CCSP_CWMP_SOAP_FAULT) + sizeof(CCSP_CWMP_SET_PARAM_FAULT));

    if ( !pCwmpSoapFault )
    {
        return returnStatus;
    }
    else
    {
        pCwmpSoapFault->soap_faultcode           = CcspTr069PaCloneString(CCSP_CWMP_CPE_SOAP_faultcode_invalidArgs);
        pCwmpSoapFault->soap_faultstring         = CcspTr069PaCloneString(CCSP_CWMP_CPE_SOAP_faulttext_invalidArgs);
        pCwmpSoapFault->Fault.FaultCode          = CCSP_CWMP_CPE_CWMP_FaultCode_invalidArgs;
        pCwmpSoapFault->Fault.FaultString        = CcspTr069PaCloneString(CCSP_CWMP_CPE_CWMP_FaultText_invalidArgs);
        pCwmpSoapFault->SetParamValuesFaultCount = 0;

        if ( pParamName && *pParamName != 0 )
        {
            pCwmpSoapFault->SetParamValuesFaultCount = 1;
            pCwmpSoapFault->SetParamValuesFaultArray[0].ParameterName = CcspTr069PaCloneString(pParamName);
            pCwmpSoapFault->SetParamValuesFaultArray[0].FaultCode     = CwmpSpvFaultCode;

            switch ( CwmpSpvFaultCode )
            {
                case    CCSP_CWMP_CPE_CWMP_FaultCode_invalidParamName: 
                        pCwmpSoapFault->SetParamValuesFaultArray[0].FaultString = 
                            CcspTr069PaCloneString(CCSP_CWMP_CPE_CWMP_FaultText_invalidParamName);
                        break;
                case    CCSP_CWMP_CPE_CWMP_FaultCode_invalidParamType: 
                        pCwmpSoapFault->SetParamValuesFaultArray[0].FaultString = 
                            CcspTr069PaCloneString(CCSP_CWMP_CPE_CWMP_FaultText_invalidParamType);
                        break;
                case    CCSP_CWMP_CPE_CWMP_FaultCode_invalidParamValue: 
                        pCwmpSoapFault->SetParamValuesFaultArray[0].FaultString = 
                            CcspTr069PaCloneString(CCSP_CWMP_CPE_CWMP_FaultText_invalidParamValue);
                        break;
                case    CCSP_CWMP_CPE_CWMP_FaultCode_notWritable: 
                        pCwmpSoapFault->SetParamValuesFaultArray[0].FaultString = 
                            CcspTr069PaCloneString(CCSP_CWMP_CPE_CWMP_FaultText_notWritable);
                        break;
            }
        }
    }

    if( pCcspCwmpMcoIf != NULL)
    {
        returnStatus =
            pCcspCwmpMcoIf->ProcessSoapError
                (
                    pCcspCwmpMcoIf->hOwnerContext,
                    pRequestID,
                    "SetParameterValues",
                    (ANSC_HANDLE)pCwmpSoapFault
                );
    }

    if ( pCwmpSoapFault )
    {
        CcspCwmpFreeSoapFault(pCwmpSoapFault);
    }

    return returnStatus;
}