예제 #1
0
ANSC_STATUS
HttpBmoBccAddHeaderField
    (
        ANSC_HANDLE                 hThisObject,
        ANSC_HANDLE                 hHfo
    )
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PHTTP_BASIC_MESSAGE_OBJECT      pMyObject    = (PHTTP_BASIC_MESSAGE_OBJECT)hThisObject;
    PHTTP_HFP_INTERFACE             pHfpIf       = (PHTTP_HFP_INTERFACE       )pMyObject->hHfpIf;

    return  pMyObject->AddHeaderField((ANSC_HANDLE)pMyObject, hHfo);
}
ANSC_STATUS
HttpBmoParseHeaders
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus  = ANSC_STATUS_SUCCESS;
    PHTTP_BASIC_MESSAGE_OBJECT      pMyObject     = (PHTTP_BASIC_MESSAGE_OBJECT)hThisObject;
    PHTTP_HFP_INTERFACE             pHfpIf        = (PHTTP_HFP_INTERFACE       )pMyObject->hHfpIf;
    PANSC_BUFFER_DESCRIPTOR         pHeaderBdo    = (PANSC_BUFFER_DESCRIPTOR   )pMyObject->hHeaderBdo;
    PHTTP_HEADER_FIELD              pHttpHfo      = NULL;
    PVOID                           pHeaderBuffer = NULL;
    ULONG                           ulBufferSize  = 0;
    char*                           pHfStart      = NULL;
    ULONG                           ulSkipSize    = 0;
    char*                           pRawHfLine    = NULL;
    char*                           pStdHfLine    = (char*)pMyObject->ScratchPad1;
    ULONG                           ulRawLineSize = 0;
    ULONG                           ulStdLineSize = 0;

    pMyObject->DelStartLine((ANSC_HANDLE)pMyObject);
    pMyObject->DelAllHfos  ((ANSC_HANDLE)pMyObject);

    returnStatus = pMyObject->ParseStartLine((ANSC_HANDLE)pMyObject);

    if ( returnStatus != ANSC_STATUS_SUCCESS )
    {
        return  returnStatus;
    }
    else if ( !pHeaderBdo )
    {
        return  ANSC_STATUS_UNAPPLICABLE;
    }
    else
    {
        pHeaderBuffer = AnscBdoGetBlock    (pHeaderBdo);
        ulBufferSize  = AnscBdoGetBlockSize(pHeaderBdo);
    }

    AnscHttpFindHfStart(pHeaderBuffer, ulBufferSize, pHfStart);

    if ( !pHfStart )
    {
        return  ANSC_STATUS_UNAPPLICABLE;
    }
    else
    {
        ulSkipSize    = (ULONG)pHfStart - (ULONG)pHeaderBuffer;
        ulBufferSize -= ulSkipSize;
        pRawHfLine    = pHfStart;
    }

    /*
     * Skip the first line, which is the start line: request-line in client message and status-line
     * in server message.
     */
    AnscHttpGetHfLineSize(pRawHfLine, ulBufferSize, ulRawLineSize);

    pRawHfLine   += ulRawLineSize;
    ulBufferSize -= ulRawLineSize;

    /*
     * We don't have to verify the completeness of the header fields, since the caller SHOULD have
     * done so already. We create a separate HTTP Header Field Object for each header line and add
     * it into the distributed hash table. The end of header fields is signalled by the presece of
     * a CRLF pair.
     */
    while ( (ulBufferSize > 0) && pRawHfLine && !AnscHttpIsCr(*pRawHfLine) && !AnscHttpIsLf(*pRawHfLine) )
    {
        AnscHttpGetHfLineSize(pRawHfLine, ulBufferSize, ulRawLineSize);

        if ( ulRawLineSize <= pMyObject->PadSize1 )
        {
            AnscHttpPrepareHeader(pRawHfLine, ulRawLineSize, pStdHfLine, ulStdLineSize);

            pStdHfLine[ulStdLineSize + 0] = HTTP_CARRIAGE_RETURN;
            pStdHfLine[ulStdLineSize + 1] = HTTP_LINE_FEED;

            pHttpHfo =
                (PHTTP_HEADER_FIELD)pHfpIf->ParseHeader
                    (
                        pHfpIf->hOwnerContext,
                        pStdHfLine,
                        ulStdLineSize
                    );

            if ( pHttpHfo )
            {
                returnStatus =
                    pMyObject->AddHeaderField
                        (
                            (ANSC_HANDLE)pMyObject,
                            (ANSC_HANDLE)pHttpHfo
                        );
            }
        }

        pRawHfLine   += ulRawLineSize;
        ulBufferSize -= ulRawLineSize;
    }

    return  ANSC_STATUS_SUCCESS;
}
ANSC_STATUS
HttpBmoSetHeaderValueByName
    (
        ANSC_HANDLE                 hThisObject,
        char*                       name,
        char*                       value
    )
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PHTTP_BASIC_MESSAGE_OBJECT      pMyObject    = (PHTTP_BASIC_MESSAGE_OBJECT   )hThisObject;
    PHTTP_HFP_INTERFACE             pHfpIf       = (PHTTP_HFP_INTERFACE          )pMyObject->hHfpIf;
#ifndef _CCSP_CWMP_TCP_CONNREQ_HANDLER
    PHTTP_HELPER_CONTAINER_OBJECT   pHttpHco     = (PHTTP_HELPER_CONTAINER_OBJECT)pMyObject->hContainerContext;
#endif
    PHTTP_HEADER_FIELD              pHttpHfo     = NULL;
    char*                           pHttpHfValue = NULL;
    char*                           pHfLine      = (char*)pMyObject->ScratchPad1;
    ULONG                           ulLineSize   = 0;

    if ( (AnscSizeOfString(name) + AnscSizeOfString(value) + 4) >= pMyObject->PadSize1 )
    {
        return  ANSC_STATUS_RESOURCES;
    }
    else
    {
        AnscCopyString(pHfLine, name);

        ulLineSize  = AnscSizeOfString(name);
        pHfLine[ulLineSize + 0] = HTTP_COLON;
        pHfLine[ulLineSize + 1] = HTTP_SPACE;
        ulLineSize += 2;

        AnscCopyString(pHfLine + ulLineSize, value);

        ulLineSize += AnscSizeOfString(value);
        pHfLine[ulLineSize + 0] = HTTP_CARRIAGE_RETURN;
        pHfLine[ulLineSize + 1] = HTTP_LINE_FEED;
    }

    pHttpHfo =
        (PHTTP_HEADER_FIELD)pHfpIf->ParseHeader
            (
                pHfpIf->hOwnerContext,
                pHfLine,
                ulLineSize
            );

    if ( !pHttpHfo )
    {
        return  ANSC_STATUS_UNAPPLICABLE;
    }
    else
    {
        returnStatus =
            pMyObject->AddHeaderField
                (
                    (ANSC_HANDLE)pMyObject,
                    (ANSC_HANDLE)pHttpHfo
                );
    }

    return  returnStatus;
}