예제 #1
0
void Response::ProcessHeaderLine( std::string const& line )
{
	const char* p = line.c_str();
	if( line.empty() )
	{
		FlushHeader();
		// end of headers

		// HTTP code 100 handling (we ignore 'em)
		if( m_Status == CONTINUE )
			m_State = STATUSLINE;	// reset parsing, expect new status line
		else
			BeginBody();			// start on body now!
		return;
	}

	if( isspace(*p) )
	{
		// it's a continuation line - just add it to previous data
		++p;
		while( *p && isspace( *p ) )
			++p;

		m_HeaderAccum += ' ';
		m_HeaderAccum += p;
	}
	else
	{
		// begin a new header
		FlushHeader();
		m_HeaderAccum = p;
	}
}
예제 #2
0
static PGPError
DoFlush(AddHdrContext *context)
{
	PGPError	error = kPGPError_NoErr;
	size_t retlen;
	PGPByte const *p;
	PGPSize len;

	error = FlushHeader(context);
	if (error)
		return error;

	/* Next, try to flush anything that we have buffered in the fifo */
	p = pgpFifoPeek (context->fifod, context->fifo, &len);
	while (len) {
		retlen = context->tail->write(context->tail,
					       p, len, &error);
		pgpFifoSeek (context->fifod, context->fifo, retlen);
		if (error)
			return error;
		
		p = pgpFifoPeek (context->fifod, context->fifo, &len);
	}
	return error;
}
예제 #3
0
/* Only called after args are checked, so I don't have to check them */
static size_t
BufferWrite(PGPPipeline *myself, PGPByte const *buf, size_t size,
	     PGPError *error)
{
	AddHdrContext *context;
	size_t size0 = size;
	int t;

	pgpAssert(myself);
	pgpAssert(myself->magic == ADDHEADERMAGIC);
	pgpAssert(error);

	context = (AddHdrContext *)myself->priv;
	pgpAssert(context);
	pgpAssert(context->tail);
	pgpAssert(context->buffer);

	*error = FlushHeader(context);
	if (*error)
		return 0;

	do {
		/* If we are in the middle of a block, flush it out */
		if (context->dowrite) {
			*error = FlushBuffer(context);
			if (*error)
				break;

			context->dowrite = 0;
			context->bufptr = context->buffer + 2;
			context->bufwrite = context->bufptr;
		}

		/* Try to fill up the buffer */
		t = pgpMin(((size_t)(BUFFER_SIZE - context->buflen)), size);
		if (t) {
			memcpy(context->bufwrite, buf, t);
			buf += t;
			size -= t;
			context->bufwrite += t;
			context->buflen += t;
		}

		/*
		 * If we have a full block, write out the length
		 * and then write out the block
		 */
		if (context->buflen == BUFFER_SIZE) {
			context->dowrite = 1;
			context->bufptr--;
			context->buflen++;
			*(context->bufptr) = 0xE0 + BLOCK_SIZE;

			continue;
		}

	} while (size);

	return size0 - size;
}
예제 #4
0
void BlockManager::RecycleBlock( offset_type blockid )
{
    FileAutoLock lock(m_pLock);
    assert(blockid.offset >=0 && blockid < m_Header.Blocks && "Recycle out of range");
    assert(blockid != m_Header.Unused && "Recycle again?");
    if(blockid.offset == m_Header.Blocks.offset -1)//shrink file size
    {
        --m_Header.Blocks.offset;
        while (m_Header.Unused.offset == m_Header.Blocks.offset -1 && m_Header.Unused.offset >= 0)
        {
            offset_type header(-1);
            ReadEmptyBlockHeader(m_Header.Unused, header);
            m_Header.Unused = header;
            --m_Header.Blocks.offset;
            assert(m_Header.Blocks.offset >=0);
            assert(m_Header.Unused < m_Header.Blocks);
        }
        m_pFile->ReserveSpace(CalcOffset(m_Header.Blocks));
        FlushHeader();
    }
    else
    {
        if(blockid > m_Header.Unused)
        {
            offset_type header = m_Header.Unused;
            WriteEmptyBlockHeader(blockid, header);
            m_Header.Unused = blockid;
            FlushHeader();
        }
        else
        {
            offset_type unused = m_Header.Unused;
            offset_type found(0);
            offset_type header(-1);
            while (blockid < unused)
            {
                ReadEmptyBlockHeader(unused, header);
                found = unused;
                unused = header;
            }
            WriteEmptyBlockHeader(found, blockid);
            WriteEmptyBlockHeader(blockid, unused);
        }
    }
}
예제 #5
0
offset_type BlockManager::AllocNewBlock()
{
    CheckHeader();
    assert(m_Header.Unused.offset < 0);
    offset_type blockid = m_Header.Blocks;
    ++m_Header.Blocks.offset;
    m_pFile->ReserveSpace(CalcOffset(m_Header.Blocks));
    FlushHeader();
    return blockid;
}
예제 #6
0
static PGPError
BufferSizeAdvise(PGPPipeline *myself, unsigned long size)
{
	AddHdrContext *context;
	PGPError	error;
	int i;

	pgpAssert(myself);
	pgpAssert(myself->magic == ADDHEADERMAGIC);

	context = (AddHdrContext *)myself->priv;
	pgpAssert(context);
	pgpAssert(context->tail);
	pgpAssert(context->buffer);

	/* Do not pass non-zero sizeAdvise -- I can't do that! */
	if (size || context->scope_depth)
		return( kPGPError_NoErr );

	/* Okay, we're at end of input. */
	if (context->buflen) {
		/* We have a bug when file length is zero; we get here without having
		 * flushed the header.  We can't easily distinguish between a zero
		 * length file and the EOF sizeadvise, but we don't need to.
		 */
		error = FlushHeader(context);
		if (error)
			return error;
		if (context->dowrite) {
			error = FlushBuffer(context);
		} else if (context->midflush) {
			error = ForceFlush(context);
		} else {
			i = context->buflen;
			if (PKTLEN_ONE_BYTE(i)) {
				context->bufptr--;
				context->buflen++;
				context->bufptr[0] = PKTLEN_1BYTE(i);
			} else {
				context->bufptr -= 2;
				context->buflen += 2;
				context->bufptr[0] = PKTLEN_BYTE0(i);
				context->bufptr[1] = PKTLEN_BYTE1(i);
			}
			context->midflush = context->buflen;
			error = ForceFlush(context);
		}
		if (error)
			return error;
	}
	
	return context->tail->sizeAdvise(context->tail, 0);
}
예제 #7
0
offset_type BlockManager::AllocExistBlock()
{
    CheckHeader();
    assert(m_Header.Unused.offset >= 0);
    offset_type result = m_Header.Unused;
    offset_type header;
    ReadEmptyBlockHeader(result, header);
    m_Header.Unused = header;
    header = result;
    ZeroBlock(result);
    FlushHeader();
    return result;
}
예제 #8
0
static void StopRecording(void)
{
    if(suppressMovieStop)
        return;
    resetDMCacc=movieSyncHackOn=0;
    DoEncode(0,0,1);   /* Write a dummy timestamp value so that the movie will keep
                       "playing" after user input has stopped. */
// finish header
    FlushHeader();

// FIXME:  truncate movie to length
// ftruncate();
    fclose(slots[current - 1]);
    MovieStatus[current - 1] = 1;
    current=0;
    FCEU_DispMessage("Movie recording stopped.");
}
예제 #9
0
static PGPError
Flush(PGPPipeline *myself)
{
	AddHdrContext *context;
	PGPError	error;

	pgpAssert(myself);
	pgpAssert(myself->magic == ADDHEADERMAGIC);

	context = (AddHdrContext *)myself->priv;
	pgpAssert(context);
	pgpAssert(context->tail);

	if (context->buffer) {
		error = FlushHeader(context);
		if (error)
			return error;

		/* Using the new packets -- force a flush of the buffer */
		if (context->dowrite) {
			error = FlushBuffer(context);
			if (error)
				return error;
		} else {
			error = ForceFlush(context);
			if (error)
				return error;
		}

	} else {
		/* Using the fifo */

		if (!context->dowrite)
			return kPGPError_BadParams;

		error = DoFlush(context);
		if (error)
			return error;
	}

	return context->tail->flush(context->tail);
}