void
RTSPParser::lookForResync()
{
    bool found = false;

    for (; eorptr < mainBufferSpace - 1; ++eorptr)
    {
        if (CHAR_LF == *eorptr || CHAR_CR == *eorptr)
        {
            if (*eorptr == *(eorptr + 1))
            {
                found = true;
                eorptr += 2;
                break;
            }
            else if ((eorptr <= mainBufferSpace - 4)
                     && (CHAR_CR == *(eorptr)) && (CHAR_LF == *(eorptr + 1))
                     && (CHAR_CR == *(eorptr + 2)) && (CHAR_LF == *(eorptr + 3))
                    )
            {
                found = true;
                eorptr += 4;
                break;
            }
        }
    }

    if (found)
    {
        mainBufferEntry = eorptr;

        if (mainBufferEntry == mainBufferSpace)
        {
            mainBufferEntry = mainBuffer;
            eorptr = mainBufferEntry;
            mainBufferSpace = mainBufferEntry;
        }

        internalState = IS_WAITING_FOR_REQUEST_MEMORY;

        continueProcessing();
    }
    else
    {
        int sizeToMove = (RTSP_RESYNC_PRESERVE_SIZE < (mainBufferSpace - mainBufferEntry)) ?
                         RTSP_RESYNC_PRESERVE_SIZE : (mainBufferSpace - mainBufferEntry);

        oscl_memmove(mainBuffer, mainBufferSpace - sizeToMove, sizeToMove);
        mainBufferEntry = mainBuffer;
        mainBufferSpace = mainBufferEntry + sizeToMove;
        eorptr = mainBuffer;
    }

    return;
}
Exemple #2
0
Word16 D_plsf_reset(D_plsfState *state, const Word16* mean_lsf_5_ptr)
{
    Word16 i;

    if (state == (D_plsfState *) NULL)
    {
        /* fprintf(stderr, "D_plsf_reset: invalid parameter\n"); */
        return -1;
    }

    for (i = 0; i < M; i++)
    {
        state->past_r_q[i] = 0;             /* Past quantized prediction error */
    }

    /* Past dequantized lsfs */
    oscl_memmove((void *)&state->past_lsf_q[0], mean_lsf_5_ptr, M*sizeof(*mean_lsf_5_ptr));

    return 0;

}
void
RTSPParser::dealWithLineContinuations(RTSPIncomingMessage * theStruct)
{
    char * cPtr;      // current pointer
    char * nlEnd;     // new-line end pointer
    char * finishPtr; // end-of-buffer pointer

    finishPtr = theStruct->secondaryBuffer + theStruct->secondaryBufferSizeUsed;

    for (cPtr = theStruct->secondaryBuffer;
            cPtr < finishPtr;
        )
    {
        // check if this point is suspicious
        //
        if (CHAR_CR == *cPtr)
        {
            if (cPtr < finishPtr - 1      // there's room for CR-LF
                    &&  CHAR_LF == *(cPtr + 1)  // next char is LF
               )
            {
                nlEnd = cPtr + 1;

                // newline, CR-LF
            }
            else
            {
                nlEnd = cPtr;

                // newline, CR
            }
        }
        else if (CHAR_LF == *cPtr)
        {
            nlEnd = cPtr;

            // newline, LF
        }
        else
        { // not a newline
            ++cPtr;
            continue;
        }

        // it was a newline

        // now, is there a whitespace after it?
        if (nlEnd >= finishPtr      // could be no room for a whitespace
                || (CHAR_SPACE != *(nlEnd + 1)      // could be a non-whitespace
                    &&  CHAR_TAB   != *(nlEnd + 1)
                   )
           )
        {
            cPtr = nlEnd + 1;
            continue;
        }

        char * sPtr;
        for (sPtr = nlEnd + 1;
                sPtr < finishPtr
                && (CHAR_SPACE == *sPtr
                    ||  CHAR_TAB   == *sPtr
                   );
                ++sPtr
            )
        { // nothing
            ;;;;
        }

        size_t sizeToMove = finishPtr - sPtr + 1;
        size_t sizeCut = sPtr - cPtr - 1;

        // set a space
        * cPtr = CHAR_SPACE;

        // move the rest, careful with overlaps
        oscl_memmove(cPtr + 1, sPtr, sizeToMove);

        // reset the length
        theStruct->secondaryBufferSizeUsed -= sizeCut;

        // reiterate
        finishPtr -= sizeCut;
        ++cPtr; // safe enough, still one whitespace has been written

        continue;
    }
}
void
RTSPParser::lookForEndOfRequest()
{
    // eorptr = mainBufferEntry;
    uint32	 newMessageSize;

    *mainBufferSpace = CHAR_NULL;

    bool  shouldMoveOverToBeginning = false;

    // now, it's either a binary data thing, or a regular message thing
    if (CHAR_DOLLAR == *mainBufferEntry)
    { // interesting, could be it

        if (mainBufferSpace - mainBufferEntry < 4)
        { // not a complete message
            shouldMoveOverToBeginning = true;
        }
        else
        { // it is a complete thing!
            requestStruct->msgType = RTSPRequestMsg;
            requestStruct->method = METHOD_BINARY_DATA;

            requestStruct->contentLength =
                ((static_cast<uint16>(
                      (*(reinterpret_cast<unsigned char*>(mainBufferEntry + 2))
                      ))) << 8)
                + static_cast<uint16>(
                    *(reinterpret_cast<unsigned char*>(mainBufferEntry + 3))
                );
            requestStruct->contentLengthIsSet = true;

            *(mainBufferEntry + 2) = CHAR_NULL;
            requestStruct->contentType = mainBufferEntry + 1;
            requestStruct->contentTypeIsSet = true;

            requestStruct->channelID = static_cast<uint8>(
                                           *(reinterpret_cast<unsigned char*>(mainBufferEntry + 1)));

            mainBufferEntry += 4;

            eorptr = mainBufferEntry;

            ebFullSizeExpected = requestStruct->contentLength;

            internalState = IS_REQUEST_IS_READY;

            return;
        }
    }

    else
    { // it's a normal message
        bool found = false;

        for (/*eorptr = mainBufferEntry*/; eorptr < mainBufferSpace - 1; ++eorptr)
        {
            if (CHAR_LF == *eorptr || CHAR_CR == *eorptr)
            {	// it's a possible

                // is it two newlines?
                if (*eorptr == *(eorptr + 1))
                {	// yes, CR-CR or LF-LF format

                    found = true;
                    eorptr += 2;
                    break;
                }
                else if ((eorptr <= mainBufferSpace - 4)
                         && (CHAR_CR == *(eorptr)) && (CHAR_LF == *(eorptr + 1))
                         && (CHAR_CR == *(eorptr + 2)) && (CHAR_LF == *(eorptr + 3))
                        )
                {	// yes, MS-WINDOWS format

                    found = true;
                    eorptr += 4;
                    break;
                }
                // else, continue on
            }
        }

        if (found)
        {
            // transfer the buffer, if necessary

            newMessageSize = eorptr - mainBufferEntry;

            // quickly take a peek at content-length
            char * cl = ci_local_strstr(mainBufferEntry, newMessageSize,
                                        RtspRecognizedFieldContentLength);
            if (NULL == cl)
            { // nothing visible
                ebFullSizeExpected = 0;
            }
            else if (cl >= mainBufferEntry + newMessageSize)
            { // it's not part of this particular message
                ebFullSizeExpected = 0;
            }
            else
            {
                cl += oscl_strlen(RtspRecognizedFieldContentLength);
                while (cl < eorptr && (isspaceNotNL(*cl) || (CHAR_COLON == *cl)))
                {
                    ++cl;
                }

                uint32 atoi_tmp;
                PV_atoi(cl, 'd', atoi_tmp);
                ebFullSizeExpected = atoi_tmp;
//        fflush(stdout);
            }

            // now, on with the moving around ...

            if (RTSP_MAX_FULL_REQUEST_SIZE < newMessageSize)
            {
                // request too big

                oscl_memcpy(requestStruct->secondaryBuffer, mainBufferEntry,
                            RTSP_MAX_FULL_REQUEST_SIZE);
                requestStruct->secondaryBuffer[RTSP_MAX_FULL_REQUEST_SIZE] = CHAR_NULL;

                requestStruct->secondaryBufferSizeUsed = newMessageSize;

                requestStruct->amMalformed = RTSPErrorTooBig;

                mainBufferEntry += newMessageSize;

                eorptr = mainBufferEntry;

                internalState = IS_ERROR_REQUEST_TOO_BIG;
            }
            else
            {
                // everything is peachy

                oscl_memcpy(requestStruct->secondaryBuffer, mainBufferEntry,
                            newMessageSize);
                requestStruct->secondaryBuffer[ newMessageSize ] = CHAR_NULL;

                requestStruct->secondaryBufferSizeUsed = newMessageSize;

                mainBufferEntry += newMessageSize;

                eorptr = mainBufferEntry;

                internalState = IS_REQUEST_IS_READY;
            }

            dealWithLineContinuations(requestStruct);

            requestStruct->parseFirstFields();

        }
        else
        {
            shouldMoveOverToBeginning = true;
        }
    }

    if (shouldMoveOverToBeginning)
    {
        // i.e. end of request was not found

        int sizeUsedSoFar = mainBufferSpace - mainBufferEntry;

        if (RTSP_PARSER_BUFFER_SIZE == sizeUsedSoFar)
        {	// we hit the parser's buffer size
            internalState = IS_START_LOOKING_FOR_RESYNC;
            continueProcessing();   // xxx

            return;
        }

        if (mainBufferEntry != mainBuffer)
        {
            oscl_memmove(mainBuffer, mainBufferEntry, sizeUsedSoFar);
            mainBufferEntry = mainBuffer;
            eorptr = mainBufferEntry;
            mainBufferSpace = mainBufferEntry + sizeUsedSoFar;
        }
        else
        { // rewind eorptr

            eorptr -= 4;

            eorptr = (eorptr < mainBufferEntry) ? mainBufferEntry : eorptr;
        }
    }
}
OsclAny* Oscl_Vector_Base::move(OsclAny* first, OsclAny* last, OsclAny* result)
{
    oscl_memmove(result, first, (uint32)last - (uint32)first);
    return last;
}