ULONG
Pam_GetParamStringValue
    (
        ANSC_HANDLE                 hInsContext,
        char*                       ParamName,
        char*                       pValue,
        ULONG*                      pulSize
    )
{
    int                             iReturnValue        = 0;
    PCOSA_CONTEXT_LINK_OBJECT       pCosaContext        = (PCOSA_CONTEXT_LINK_OBJECT)hInsContext;
    char                            IpIfObjName[128]    = {0};
    ULONG                           IpIfObjNameSize     = 0;
    ULONG                           ulInstNum           = 0;
    char                            Buffer[128]         = {0};
    ULONG                           BufferSize          = 0;


    CcspTraceInfo(("[%s] -- '%s', pValue addr: 0x%x, pulSize addr: 0x%x \n", __FUNCTION__, ParamName, pValue, pulSize));


    IpIfObjNameSize = sizeof(IpIfObjName) - 1;
    
    /* check the parameter name and return the corresponding value */
    if( AnscEqualString(ParamName, "FirstUpstreamIpInterface", TRUE))
    {
        /* We hardcode the value here temporarily. In the future, if LowerLayers mechanism works well, we can change back*/
        /*
        AnscCopyString(pValue, "Device.IP.Interface.1.");
        *pulSize = _ansc_strlen("Device.IP.Interface.1.");
        return  0;
        */

        if ( ANSC_STATUS_SUCCESS == Pam_GetFirstIpInterfaceObjectName(TRUE, IpIfObjName, &IpIfObjNameSize) )
        {
            if ( IpIfObjNameSize < *pulSize )
            {
                AnscCopyString(pValue, IpIfObjName);
                *pulSize = IpIfObjNameSize;
                return  0;
            }
            else
            {
                *pulSize = IpIfObjNameSize;
                return  1;
            }
        }
        else
        {
            return  -1;
        }
    }
    else if( AnscEqualString(ParamName, "FirstDownstreamIpInterface", TRUE))
    {
        /* We hardcode the value here temporarily. In the future, if LowerLayers mechanism works well, we can change back*/
        /*
        AnscCopyString(pValue, "Device.IP.Interface.4.");
        *pulSize = _ansc_strlen("Device.IP.Interface.4.");
        return  0;
        */

      //      CcspTraceInfo(("Pam_GetParamStringValue -- FirstDownstreamIpInterface case\n"));

        if ( ANSC_STATUS_SUCCESS == Pam_GetFirstIpInterfaceObjectName(FALSE, IpIfObjName, &IpIfObjNameSize) )
        {

	  //	  CcspTraceInfo(("Pam_GetParamStringValue -- '%s' Pam_GetFirstIpInterfaceObjectName ret success\n", ParamName));
	  CcspTraceInfo(("[%s] -- '%s' IpIfObjNameSize: %d, pulSize: %d\n", __FUNCTION__, ParamName, IpIfObjNameSize, *pulSize));

            if ( IpIfObjNameSize < *pulSize )
            {
                AnscCopyString(pValue, IpIfObjName);

		CcspTraceInfo(("[%s] -- pValue: %s\n", __FUNCTION__, pValue));
                *pulSize = IpIfObjNameSize;
                return  0;
            }
            else
            {
                *pulSize = IpIfObjNameSize;
                return  1;
            }
        }
        else
        { 
	  CcspTraceInfo(("[%s] -- '%s' Pam_GetFirstIpInterfaceObjectName ret failed\n", __FUNCTION__, ParamName));
            return  -1;
        }
    }
    else if( AnscEqualString(ParamName, "FirstUpstreamIpv4Address", TRUE))
    {
        if ( ANSC_STATUS_SUCCESS == Pam_GetFirstIpInterfaceObjectName(TRUE, IpIfObjName, &IpIfObjNameSize) )
        {
            _ansc_strcat(IpIfObjName, "IPv4Address.");            
            ulInstNum = CosaGetInstanceNumberByIndex(IpIfObjName, 0);
            
            if ( ulInstNum == 0 )
            {
                 return  -1;
            }
            else
            {
                _ansc_sprintf(Buffer, "%d.", ulInstNum);
                _ansc_strcat(IpIfObjName, Buffer);
                _ansc_strcat(IpIfObjName, "IPAddress");
            }

            BufferSize   = sizeof(Buffer);
            iReturnValue = CosaGetParamValueString(IpIfObjName, Buffer, &BufferSize);
            
            if ( iReturnValue != 0 )
            {
                CcspTraceWarning(("Pam_GetParamStringValue -- failed to retrieve IP address, error code %d!\n", iReturnValue));
                
                return  -1;
            }

            if ( BufferSize < *pulSize )
            {
                AnscCopyString(pValue, Buffer);
                *pulSize = IpIfObjNameSize;
                return  0;
            }
            else
            {
                _ansc_strncpy(pValue, Buffer, *pulSize);       
                *pulSize = IpIfObjNameSize;
                return  1;
            }
        }
        else
        {
            return  -1;
        }
    }
    else if( AnscEqualString(ParamName, "FirstUpstreamIpv4SubnetMask", TRUE))
    {
        if ( ANSC_STATUS_SUCCESS == Pam_GetFirstIpInterfaceObjectName(TRUE, IpIfObjName, &IpIfObjNameSize) )
        {
            _ansc_strcat(IpIfObjName, "IPv4Address.");
            ulInstNum = CosaGetInstanceNumberByIndex(IpIfObjName, 0);
            
            if ( ulInstNum == 0 )
            {
                 return  -1;
            }
            else
            {
                _ansc_sprintf(Buffer, "%d.", ulInstNum);
                _ansc_strcat(IpIfObjName, Buffer);
                _ansc_strcat(IpIfObjName, "SubnetMask");
            }

            BufferSize   = sizeof(Buffer);
            iReturnValue = CosaGetParamValueString(IpIfObjName, Buffer, &BufferSize);

            if ( iReturnValue != 0 )
            {
                CcspTraceWarning(("Pam_GetParamStringValue -- failed to retrieve subnet mask, error code %d!\n", iReturnValue));
                
                return  -1;
            }

            if ( BufferSize < *pulSize )
            {
                AnscCopyString(pValue, Buffer);
                *pulSize = IpIfObjNameSize;
                return  0;
            }
            else
            {
                _ansc_strncpy(pValue, Buffer, *pulSize);
                *pulSize = IpIfObjNameSize;
                return  1;
            }
        }
        else
        {
            return  -1;
        }
    }
    else if( AnscEqualString(ParamName, "FirstDownstreamIpv4Address", TRUE))
    {
        if ( ANSC_STATUS_SUCCESS == Pam_GetFirstIpInterfaceObjectName(FALSE, IpIfObjName, &IpIfObjNameSize) )
        {
            _ansc_strcat(IpIfObjName, "IPv4Address.");            
            ulInstNum = CosaGetInstanceNumberByIndex(IpIfObjName, 0);
            
            if ( ulInstNum == 0 )
            {
                 return  -1;
            }
            else
            {
                _ansc_sprintf(Buffer, "%d.", ulInstNum);
                _ansc_strcat(IpIfObjName, Buffer);
                _ansc_strcat(IpIfObjName, "IPAddress");
            }

            BufferSize   = sizeof(Buffer);
            iReturnValue = CosaGetParamValueString(IpIfObjName, Buffer, &BufferSize);
            
            if ( iReturnValue != 0 )
            {
                CcspTraceWarning(("Pam_GetParamStringValue -- failed to retrieve IP address, error code %d!\n", iReturnValue));
                
                return  -1;
            }

            if ( BufferSize < *pulSize )
            {
                AnscCopyString(pValue, Buffer);
                *pulSize = IpIfObjNameSize;
                return  0;
            }
            else
            {
                _ansc_strncpy(pValue, Buffer, *pulSize);       
                *pulSize = IpIfObjNameSize;
                return  1;
            }
        }
        else
        {
            return  -1;
        }
    }
    else if( AnscEqualString(ParamName, "FirstDownstreamIpv4SubnetMask", TRUE))
    {
        if ( ANSC_STATUS_SUCCESS == Pam_GetFirstIpInterfaceObjectName(FALSE, IpIfObjName, &IpIfObjNameSize) )
        {
            _ansc_strcat(IpIfObjName, "IPv4Address.");
            ulInstNum = CosaGetInstanceNumberByIndex(IpIfObjName, 0);
            
            if ( ulInstNum == 0 )
            {
                 return  -1;
            }
            else
            {
                _ansc_sprintf(Buffer, "%d.", ulInstNum);
                _ansc_strcat(IpIfObjName, Buffer);
                _ansc_strcat(IpIfObjName, "SubnetMask");
            }

            BufferSize   = sizeof(Buffer);
            iReturnValue = CosaGetParamValueString(IpIfObjName, Buffer, &BufferSize);

            if ( iReturnValue != 0 )
            {
                CcspTraceWarning(("Pam_GetParamStringValue -- failed to retrieve subnet mask, error code %d!\n", iReturnValue));
                
                return  -1;
            }

            if ( BufferSize < *pulSize )
            {
                AnscCopyString(pValue, Buffer);
                *pulSize = IpIfObjNameSize;
                return  0;
            }
            else
            {
                _ansc_strncpy(pValue, Buffer, *pulSize);
                *pulSize = IpIfObjNameSize;
                return  1;
            }
        }
        else
        {
            return  -1;
        }
    }

    /* CcspTraceWarning(("Unsupported parameter '%s'\n", ParamName)); */
    return -1;
}
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.º 3
0
void
AnscDumpMemory
    (
        PUCHAR                      pMem,
        ULONG                       ulSize,
        ULONG                       Format
    )
{
    /**************************************************************
                            Local Variables
    **************************************************************/
    UCHAR                           bStep               = 16;
    PUCHAR                          pCurr;
    UCHAR                           CurrByte;
    char                            PrintBuffer[128]    = {0};
    char                            CharBuffer[24]      = {0};
    ULONG                           Index;
    ULONG                           i;

    /**************************************************************
                            Code Section
    **************************************************************/

    pCurr = pMem;

    for( Index = 0; Index < ulSize/bStep; Index ++ )
    {
        /*
         *      Print the address
         */
        _ansc_sprintf(PrintBuffer, "0x%08X", (unsigned int)pCurr);
        _ansc_strcat (PrintBuffer, ": ");

        /*
         *      Print the memory image
         */
        AnscPrintMultiBytes( PrintBuffer + _ansc_strlen(PrintBuffer), pCurr, bStep, ' ', FALSE );

        for( i = 0; i < bStep; i++ )
        {
            CurrByte = *pCurr++;

            if ( CurrByte == '%' )                              /* escape the character '%' */
            {
                CharBuffer[ i ] = '.';
            }
            else if ( (CurrByte >= 0x20) && (CurrByte < 128) )  /* Non control charactor */
            {
                CharBuffer[ i ] = CurrByte;
            }
            else
            {
                CharBuffer[ i ] = '.';
            }
        }

        _ansc_strcat( PrintBuffer, " " );
        AnscTraceWrapper(PrintBuffer);

        CharBuffer[i    ] = '\r';
        CharBuffer[i + 1] = '\n';
        CharBuffer[i + 2] = 0;
        AnscTraceWrapper(CharBuffer);

    }   /*for( Index = 0; Index < ulSize/bStep; Index +=bStep )*/

    if ( pCurr < pMem+ulSize )
    {
        /*
         *      Print the address
         */
        _ansc_sprintf(PrintBuffer, "0x%08X", (unsigned int)pCurr);
        _ansc_strcat (PrintBuffer, ": " );

        /*
         *      Print the memory image
         */
        for( i = 0; i < bStep; i++ )
        {
            if ( pCurr < pMem+ulSize )
            {
                CurrByte = *pCurr++;
                AnscPrintMultiBytes( PrintBuffer + _ansc_strlen( PrintBuffer ), &CurrByte, 1, ' ', FALSE );
            }
            else
            {   /*Fill in spaces*/
                CurrByte = ' ';
                _ansc_strcat( PrintBuffer, "  " );
            }

            _ansc_strcat( PrintBuffer, " " );

            if ( CurrByte == '%' )                              /* escape the character '%' */
            {
                CharBuffer[ i ] = '%';
                CharBuffer[ i ] = CurrByte;
            }
            else if ( (CurrByte >= 0x20) && (CurrByte < 128) )  /* Non control charactor */
            {
                CharBuffer[ i ] = CurrByte;
            }
            else
            {
                CharBuffer[ i ] = '.';
            }
        }   /*for( i = 0; i < bStep; i++ )*/

        AnscTraceWrapper(PrintBuffer);

        CharBuffer[i    ] = '\r';
        CharBuffer[i + 1] = '\n';
        CharBuffer[i + 2] = 0;
        AnscTraceWrapper(CharBuffer);

    }   /*if ( pCurr < pMem )*/

    return;

}    /*AnscDumpMemory*/