Exemplo n.º 1
0
const char* http_get_request_uri(void* parser)
{
	struct http_context *ctx;
	ctx = (struct http_context*)parser;
	assert(ctx->stateM>=SM_BODY);
	assert(is_server_mode(ctx));
	return ctx->raw + ctx->req.uri_pos;
}
Exemplo n.º 2
0
const char* http_get_status_reason(void* parser)
{
	struct http_context *ctx;
	ctx = (struct http_context*)parser;
	assert(ctx->stateM>=SM_BODY);
	assert(!is_server_mode(ctx));
	return ctx->raw + ctx->reply.reason_pos;
}
Exemplo n.º 3
0
int http_get_status_code(void* parser)
{
	struct http_context *ctx;
	ctx = (struct http_context*)parser;
	assert(ctx->stateM>=SM_BODY);
	assert(!is_server_mode(ctx));
	return ctx->reply.code;
}
Exemplo n.º 4
0
const char* http_get_location(void* parser)
{
	struct http_context *ctx;
	ctx = (struct http_context*)parser;
	assert(ctx->stateM>=SM_BODY);
	assert(!is_server_mode(ctx));
	if(0 == ctx->location)
		return NULL;
	return ctx->raw + ctx->location;
}
Exemplo n.º 5
0
static void
gipsec_init (GIPSec *gipsec)
{
	g_debug ("gipsec_init...");

	g_return_if_fail (gipsec != NULL);

	if (is_server_mode ())
		gipsec->run_mode = 1;
	else
		gipsec->run_mode = 0;
}
Exemplo n.º 6
0
int http_get_content_length(void* parser)
{
	struct http_context *ctx;
	ctx = (struct http_context*)parser;
	assert(ctx->stateM>=SM_BODY);
	if(-1 == ctx->content_length)
	{
		assert(!is_server_mode(ctx));
		return ctx->raw_size - ctx->offset;
	}
	return ctx->content_length;
}
Exemplo n.º 7
0
int http_parser_input(void* parser, const void* data, size_t *bytes)
{
	enum { INPUT_NEEDMORE = 1, INPUT_DONE = 0, };

	int r;
	struct http_context *ctx;
	ctx = (struct http_context*)parser;

	// save raw data
	r = http_rawdata(ctx, data, *bytes);
	if(0 != r)
	{
		assert(r < 0);
		return r;
	}

	if(SM_FIRSTLINE <= ctx->stateM && ctx->stateM < SM_HEADER)
	{
		r = is_server_mode(ctx) ? http_parse_request_line(ctx) : http_parse_status_line(ctx);
	}

	if(SM_HEADER <= ctx->stateM && ctx->stateM < SM_BODY)
	{
		r = http_parse_header_line(ctx);
	}

	assert(r <= 0);
	if(SM_BODY <= ctx->stateM && ctx->stateM < SM_DONE)
	{
		if(is_transfer_encoding_chunked(ctx))
		{
			r = http_parse_chunked(ctx);
		}
		else
		{
			if(-1 == ctx->content_length)
			{
				if(is_server_mode(ctx))
				{
					ctx->content_length = 0;
					ctx->stateM = SM_DONE;
				}
				else
				{
					// H4.4 Message Length, section 5, server closing the connection
					// receive all until socket closed
					assert(!is_server_mode(ctx));
					if(0 == *bytes /*|| ctx->raw_size == ctx->offset*/)
					{
						ctx->content_length = ctx->raw_size - ctx->offset;
						ctx->stateM = SM_DONE;
					}
				}
			}
			else
			{
				assert(ctx->raw_size <= ctx->offset + ctx->content_length);
				if(ctx->raw_size >= ctx->offset + ctx->content_length)
					ctx->stateM = SM_DONE;
			}
		}
	}

	if(r < 0)
		return r;

	*bytes = 0;
	return ctx->stateM == SM_DONE ? INPUT_DONE : INPUT_NEEDMORE;
}