src/t_htp_req.c
static int
lt_htp_req_parse( lua_State *L )
{
	size_t      d_len;
	const char  *data = luaL_checklstring( L, 2, &d_len );
	const char   *end = data + d_len-1; // marks the last character
	const char **tail = &data;
	size_t      state = (size_t) luaL_checkinteger( L, 3 );
	lua_pop( L, 1 );  // pop state

	switch (state)
	{
		case T_HTP_REQ_METHOD:
			//printf( "Parsing METHOD\n" );
			if (0 == t_htp_req_parseMethod( L, tail, end ))
				break;
			/* FALLTHRU */
		case T_HTP_REQ_URI:
			//printf( "Parsing URL\n" );
			if (0 == t_htp_req_parseUrl( L, tail, end ))
				break;
			/* FALLTHRU */
		case T_HTP_REQ_VERSION:
			//printf( "Parsing VERSION\n" );
			if (0 == t_htp_req_parseHttpVersion( L, tail, end ))
				break;
			/* FALLTHRU */
		case T_HTP_REQ_HEADERS:
			//printf( "Parsing HEADERS\n" );
			if (0 == t_htp_req_parseHeaders( L, tail, end ))
				break;
			/* FALLTHRU */
		default:
			break;
	}
	if (*tail == end)
		lua_pushnil( L );
	else
		lua_pushlstring( L, *tail, end - (*tail) + 1 );
	return 1;
}
/**--------------------------------------------------------------------------
 * Receive message
 * This is optimistic.  If a big chunk got received don't waste time moving
 * everyting between Lua and C.  Just keep parsing and fill the T.Http.Request
 * object.  Otherwise, preserve the state, store unparsed string in Lua and
 * re-parse upon next incoming data.
 * \param   L      Lua state.
 * \lparam  table  t.Http.Request userdata.
 * \lparam  string Lua string of received data.
 * \lparam  status current parsing status.
 * \return  int    # of values pushed onto the stack.
 * --------------------------------------------------------------------------*/
Receive message
This is optimistic.  If a big chunk got received don't waste time moving
everyting between Lua and C.  Just keep parsing and fill the T.Http.Request
object.  Otherwise, preserve the state, store unparsed string in Lua and
re-parse upon next incoming data.
\param   L      Lua state.
Receive message This is optimistic . If a big chunk got received don ' t waste time moving everyting between Lua and C . Just keep parsing and fill the T . Http . Request object . Otherwise preserve the state store unparsed string in Lua and re - parse upon next incoming data . \ param L Lua state .
static int
lt_htp_req_parse( lua_State *L )
{
	size_t      d_len;
	const char  *data = luaL_checklstring( L, 2, &d_len );
	const char   *end = data + d_len-1; 
	const char **tail = &data;
	size_t      state = (size_t) luaL_checkinteger( L, 3 );
	lua_pop( L, 1 );  
	switch (state)
	{
		case T_HTP_REQ_METHOD:
			if (0 == t_htp_req_parseMethod( L, tail, end ))
				break;
		case T_HTP_REQ_URI:
			if (0 == t_htp_req_parseUrl( L, tail, end ))
				break;
		case T_HTP_REQ_VERSION:
			if (0 == t_htp_req_parseHttpVersion( L, tail, end ))
				break;
		case T_HTP_REQ_HEADERS:
			if (0 == t_htp_req_parseHeaders( L, tail, end ))
				break;
		default:
			break;
	}
	if (*tail == end)
		lua_pushnil( L );
	else
		lua_pushlstring( L, *tail, end - (*tail) + 1 );
	return 1;
}
static int lt_htp_req_parse ( lua_State * L ) { size_t d_len ; const char * data = luaL_checklstring ( L , 2 , & d_len ) ; const char * end = data + d_len - 1 ; const char * * tail = & data ; size_t state = ( size_t ) luaL_checkinteger ( L , 3 ) ; lua_pop ( L , 1 ) ; switch ( state ) { case T_HTP_REQ_METHOD : if ( 0 == t_htp_req_parseMethod ( L , tail , end ) ) break ; case T_HTP_REQ_URI : if ( 0 == t_htp_req_parseUrl ( L , tail , end ) ) break ; case T_HTP_REQ_VERSION : if ( 0 == t_htp_req_parseHttpVersion ( L , tail , end ) ) break ; case T_HTP_REQ_HEADERS : if ( 0 == t_htp_req_parseHeaders ( L , tail , end ) ) break ; default : break ; } if ( * tail == end ) lua_pushnil ( L ) ; else lua_pushlstring ( L , * tail , end - ( * tail ) + 1 ) ; return 1 ; }
Receive message
 This is optimistic.
Receive message This is optimistic .
// marks the last character // pop state //printf( "Parsing METHOD\n" ); /* FALLTHRU */ //printf( "Parsing URL\n" ); /* FALLTHRU */ //printf( "Parsing VERSION\n" ); /* FALLTHRU */ //printf( "Parsing HEADERS\n" ); /* FALLTHRU */