src/t_htp_req.c
static size_t
t_htp_req_parseUrl( lua_State *L, const char **data, const char *end )
{
	const char *r = eat_lws( *data );  ///< runner char
	const char *u = r;                 ///< start of URI
	const char *q = NULL;              ///< runner for query
	const char *v = r;                 ///< value start marker

	lua_newtable( L );                 ///< parsed and decoded query parameters

	while (r <= end)
	{
		switch (*r)
		{
			case '/':
				break;
			case '?':
				lua_pushlstring( L, u, r-u );     // push path
				lua_setfield( L, 1, "path" );
				q = r+1;
				break;
			case '=':
				lua_pushlstring( L, q, r-q );     // push key
				//TODO: if key exists, create table
				v = r+1;
				break;
			case '&':
				lua_pushlstring( L, v, r-v );     // push value
				lua_rawset( L, -3 );
				q = r+1;
				break;
			case ' ':                            // last value
				lua_pushlstring( L, u, r-u );     // push full uri string
				lua_setfield( L, 1, "url" );
				if (NULL != q)
				{
					lua_pushlstring( L, v, r-v );  // push value
					lua_rawset( L, -3 );
					lua_setfield( L, 1, "query" );
				}
				else
				{
					lua_pop( L, 1 );               // pop empty table
					lua_pushlstring( L, u, r-u );  // push full uri string as path
					lua_setfield( L, 1, "path" );
				}

				lua_pushinteger( L, T_HTP_REQ_VERSION );
				lua_setfield( L, 1, "state" );
				(*data) = r;
				return r - u + 1;  //+1 on for space before URL
				break;
			default:           break;
		}
		r++;
	}
	lua_pop( L, lua_gettop( L ) - 3 );         // pop empty table and potentially pushed keys
	return 0;
}
/**--------------------------------------------------------------------------
 * Parse Uri and Query from the request.
 * Stack: requesttable
 * \param  lua_State   L.
 * \param  char **data pointer within to data stream.
 * \param  char *end   end of data strem.
 * \return bool        0 means not enough data, 1 means done successfully
 * --------------------------------------------------------------------------*/
Parse Uri and Query from the request.
Stack: requesttable
\param  lua_State   L.
\param  char **data pointer within to data stream.
\param  char *end   end of data strem.
\return bool        0 means not enough data, 1 means done successfully
Parse Uri and Query from the request . Stack : requesttable \ param lua_State L . \ param char ** data pointer within to data stream . \ param char * end end of data strem . \ return bool 0 means not enough data 1 means done successfully
static size_t
t_htp_req_parseUrl( lua_State *L, const char **data, const char *end )
{
	const char *r = eat_lws( *data );  
	const char *u = r;                 
	const char *q = NULL;              
	const char *v = r;                 
	lua_newtable( L );                 
	while (r <= end)
	{
		switch (*r)
		{
			case '/':
				break;
			case '?':
				lua_pushlstring( L, u, r-u );     
				lua_setfield( L, 1, "path" );
				q = r+1;
				break;
			case '=':
				lua_pushlstring( L, q, r-q );     
				v = r+1;
				break;
			case '&':
				lua_pushlstring( L, v, r-v );     
				lua_rawset( L, -3 );
				q = r+1;
				break;
			case ' ':                            
				lua_pushlstring( L, u, r-u );     
				lua_setfield( L, 1, "url" );
				if (NULL != q)
				{
					lua_pushlstring( L, v, r-v );  
					lua_rawset( L, -3 );
					lua_setfield( L, 1, "query" );
				}
				else
				{
					lua_pop( L, 1 );               
					lua_pushlstring( L, u, r-u );   as path
					lua_setfield( L, 1, "path" );
				}
				lua_pushinteger( L, T_HTP_REQ_VERSION );
				lua_setfield( L, 1, "state" );
				(*data) = r;
				return r - u + 1;  
				break;
			default:           break;
		}
		r++;
	}
	lua_pop( L, lua_gettop( L ) - 3 );          and potentially pushed keys
	return 0;
}
static size_t t_htp_req_parseUrl ( lua_State * L , const char * * data , const char * end ) { const char * r = eat_lws ( * data ) ; const char * u = r ; const char * q = NULL ; const char * v = r ; lua_newtable ( L ) ; while ( r <= end ) { switch ( * r ) { case ' ' : break ; case ' ' : lua_pushlstring ( L , u , r - u ) ; lua_setfield ( L , 1 , " " ) ; q = r + 1 ; break ; case ' ' : lua_pushlstring ( L , q , r - q ) ; v = r + 1 ; break ; case ' ' : lua_pushlstring ( L , v , r - v ) ; lua_rawset ( L , -3 ) ; q = r + 1 ; break ; case ' ' : lua_pushlstring ( L , u , r - u ) ; lua_setfield ( L , 1 , " " ) ; if ( NULL != q ) { lua_pushlstring ( L , v , r - v ) ; lua_rawset ( L , -3 ) ; lua_setfield ( L , 1 , " " ) ; } else { lua_pop ( L , 1 ) ; lua_pushlstring ( L , u , r - u ) ; lua_setfield ( L , 1 , " " ) ; } lua_pushinteger ( L , T_HTP_REQ_VERSION ) ; lua_setfield ( L , 1 , " " ) ; ( * data ) = r ; return r - u + 1 ; break ; default : break ; } r ++ ; } lua_pop ( L , lua_gettop ( L ) - 3 ) ; return 0 ; }
Parse Uri and Query from the request.
Parse Uri and Query from the request .
///< runner char ///< start of URI ///< runner for query ///< value start marker ///< parsed and decoded query parameters // push path // push key //TODO: if key exists, create table // push value // last value // push full uri string // push value // pop empty table // push full uri string as path //+1 on for space before URL // pop empty table and potentially pushed keys