Adjust benchmark directory,enable HTTP test,rename variables,format codes
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
add_definitions(-fPIC)
|
||||
include_directories(${CMAKE_BINARY_DIR}/vendor/llhttp/include)
|
||||
include_directories(${CMAKE_BINARY_DIR}/vendor/brotli/include)
|
||||
include_directories(${CMAKE_SOURCE_DIR}/deps)
|
||||
|
||||
set(HTTP_SRC ${DEPS_SRC} http_decoder.cpp http_decoder_utils.cpp http_decoder_half.cpp
|
||||
set(HTTP_SRC http_decoder.cpp http_decoder_utils.cpp http_decoder_half.cpp
|
||||
http_decoder_table.cpp http_decoder_string.cpp http_content_decompress.cpp
|
||||
http_decoder_result_queue.cpp http_decoder_stat.cpp http_decoder_tunnel.cpp)
|
||||
|
||||
add_library(http_decoder STATIC ${HTTP_SRC})
|
||||
set_target_properties(http_decoder PROPERTIES LINK_FLAGS "-Wl,--version-script=${PROJECT_SOURCE_DIR}/src/version.map")
|
||||
target_include_directories(http_decoder PUBLIC ${CMAKE_SOURCE_DIR}/deps/)
|
||||
target_link_libraries(http_decoder z llhttp-static fieldstat4)
|
||||
target_link_libraries(http_decoder brotli-dec-static brotli-common-static )
|
||||
set_target_properties(http_decoder PROPERTIES PREFIX "")
|
||||
add_library(http STATIC ${HTTP_SRC})
|
||||
add_library(http_dyn SHARED ${HTTP_SRC})
|
||||
set_target_properties(http PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/version.map")
|
||||
target_include_directories(http PUBLIC ${CMAKE_SOURCE_DIR}/deps/)
|
||||
target_link_libraries(http z llhttp-static fieldstat4 brotli-dec-static brotli-common-static nmx_pool toml)
|
||||
set_target_properties(http PROPERTIES PREFIX "")
|
||||
|
||||
#install(TARGETS http_decoder LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/plugin/${lib_name} COMPONENT LIBRARIES)
|
||||
set_target_properties(http_dyn PROPERTIES PREFIX "")
|
||||
target_link_libraries(http_dyn z llhttp-static fieldstat4 brotli-dec-static brotli-common-static nmx_pool toml)
|
||||
@@ -1,21 +1,13 @@
|
||||
/*
|
||||
**********************************************************************************************
|
||||
* File: http_content_decompress.c
|
||||
* Description:
|
||||
* Authors: LuWenPeng <luwenpeng@geedgenetworks.com>
|
||||
* Date: 2022-10-31
|
||||
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
|
||||
***********************************************************************************************
|
||||
*/
|
||||
#include <zlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <brotli/decode.h>
|
||||
#include "http_decoder_inc.h"
|
||||
#include "http_decoder_private.h"
|
||||
|
||||
#define HTTP_DECOMPRESS_BUFFER_SIZE (4096)
|
||||
|
||||
struct http_content_decompress {
|
||||
struct http_content_decompress
|
||||
{
|
||||
enum http_content_encoding encoding;
|
||||
z_stream *z_stream_ptr;
|
||||
BrotliDecoderState *br_state;
|
||||
@@ -23,38 +15,41 @@ struct http_content_decompress {
|
||||
size_t buffer_size;
|
||||
};
|
||||
|
||||
enum http_content_encoding
|
||||
http_content_encoding_str2int(const char *content_encoding)
|
||||
enum http_content_encoding http_content_encoding_str2int(const char *content_encoding)
|
||||
{
|
||||
if (strcasestr(content_encoding, "gzip") != NULL) {
|
||||
if (strcasestr(content_encoding, "gzip") != NULL)
|
||||
{
|
||||
return HTTP_CONTENT_ENCODING_GZIP;
|
||||
}
|
||||
if (strcasestr(content_encoding, "deflate") != NULL) {
|
||||
if (strcasestr(content_encoding, "deflate") != NULL)
|
||||
{
|
||||
return HTTP_CONTENT_ENCODING_DEFLATE;
|
||||
}
|
||||
if (strcasestr(content_encoding, "br") != NULL) {
|
||||
if (strcasestr(content_encoding, "br") != NULL)
|
||||
{
|
||||
return HTTP_CONTENT_ENCODING_BR;
|
||||
}
|
||||
return HTTP_CONTENT_ENCODING_NONE;
|
||||
}
|
||||
|
||||
const char *
|
||||
http_content_encoding_int2str(enum http_content_encoding content_encoding)
|
||||
const char *http_content_encoding_int2str(enum http_content_encoding content_encoding)
|
||||
{
|
||||
if (content_encoding == HTTP_CONTENT_ENCODING_GZIP) {
|
||||
if (content_encoding == HTTP_CONTENT_ENCODING_GZIP)
|
||||
{
|
||||
return "gzip";
|
||||
}
|
||||
if (content_encoding == HTTP_CONTENT_ENCODING_DEFLATE) {
|
||||
if (content_encoding == HTTP_CONTENT_ENCODING_DEFLATE)
|
||||
{
|
||||
return "deflate";
|
||||
}
|
||||
if (content_encoding == HTTP_CONTENT_ENCODING_BR) {
|
||||
if (content_encoding == HTTP_CONTENT_ENCODING_BR)
|
||||
{
|
||||
return "br";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
struct http_content_decompress *
|
||||
http_content_decompress_create(enum http_content_encoding encoding)
|
||||
struct http_content_decompress *http_content_decompress_create(enum http_content_encoding encoding)
|
||||
{
|
||||
struct http_content_decompress *decompress =
|
||||
CALLOC(struct http_content_decompress, 1);
|
||||
@@ -64,8 +59,8 @@ http_content_decompress_create(enum http_content_encoding encoding)
|
||||
decompress->z_stream_ptr = NULL;
|
||||
decompress->br_state = NULL;
|
||||
|
||||
if (encoding == HTTP_CONTENT_ENCODING_GZIP
|
||||
|| encoding == HTTP_CONTENT_ENCODING_DEFLATE) {
|
||||
if (encoding == HTTP_CONTENT_ENCODING_GZIP || encoding == HTTP_CONTENT_ENCODING_DEFLATE)
|
||||
{
|
||||
decompress->z_stream_ptr = CALLOC(z_stream, 1);
|
||||
assert(decompress->z_stream_ptr);
|
||||
|
||||
@@ -75,22 +70,27 @@ http_content_decompress_create(enum http_content_encoding encoding)
|
||||
decompress->z_stream_ptr->avail_in = 0;
|
||||
decompress->z_stream_ptr->next_in = Z_NULL;
|
||||
|
||||
if (encoding == HTTP_CONTENT_ENCODING_GZIP) {
|
||||
if (inflateInit2(decompress->z_stream_ptr, MAX_WBITS + 16)
|
||||
!= Z_OK) {
|
||||
if (encoding == HTTP_CONTENT_ENCODING_GZIP)
|
||||
{
|
||||
if (inflateInit2(decompress->z_stream_ptr, MAX_WBITS + 16) != Z_OK)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if (encoding == HTTP_CONTENT_ENCODING_DEFLATE) {
|
||||
if (inflateInit2(decompress->z_stream_ptr, -MAX_WBITS) != Z_OK) {
|
||||
if (encoding == HTTP_CONTENT_ENCODING_DEFLATE)
|
||||
{
|
||||
if (inflateInit2(decompress->z_stream_ptr, -MAX_WBITS) != Z_OK)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (encoding == HTTP_CONTENT_ENCODING_BR) {
|
||||
if (encoding == HTTP_CONTENT_ENCODING_BR)
|
||||
{
|
||||
decompress->br_state = BrotliDecoderCreateInstance(NULL, NULL, NULL);
|
||||
if (decompress->br_state == NULL) {
|
||||
if (decompress->br_state == NULL)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
@@ -103,14 +103,17 @@ error:
|
||||
|
||||
void http_content_decompress_destroy(struct http_content_decompress *decompress)
|
||||
{
|
||||
if (NULL == decompress) {
|
||||
if (NULL == decompress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (decompress->z_stream_ptr != NULL) {
|
||||
if (decompress->z_stream_ptr != NULL)
|
||||
{
|
||||
inflateEnd(decompress->z_stream_ptr);
|
||||
FREE(decompress->z_stream_ptr);
|
||||
}
|
||||
if (decompress->br_state) {
|
||||
if (decompress->br_state)
|
||||
{
|
||||
BrotliDecoderDestroyInstance(decompress->br_state);
|
||||
decompress->br_state = NULL;
|
||||
}
|
||||
@@ -118,10 +121,9 @@ void http_content_decompress_destroy(struct http_content_decompress *decompress)
|
||||
FREE(decompress);
|
||||
}
|
||||
|
||||
static int
|
||||
http_content_decompress_write_zlib(struct http_content_decompress *decompress,
|
||||
const char *indata, size_t indata_len,
|
||||
char **outdata, size_t *outdata_len)
|
||||
static int http_content_decompress_write_zlib(struct http_content_decompress *decompress,
|
||||
const char *indata, size_t indata_len,
|
||||
char **outdata, size_t *outdata_len)
|
||||
{
|
||||
z_stream *z_stream_ptr = decompress->z_stream_ptr;
|
||||
z_stream_ptr->avail_in = (unsigned int)indata_len;
|
||||
@@ -132,35 +134,40 @@ http_content_decompress_write_zlib(struct http_content_decompress *decompress,
|
||||
*outdata = NULL;
|
||||
*outdata_len = 0;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
int ret = inflate(z_stream_ptr, Z_NO_FLUSH);
|
||||
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT
|
||||
|| ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) {
|
||||
if (ret == Z_STREAM_ERROR || ret == Z_NEED_DICT || ret == Z_DATA_ERROR || ret == Z_MEM_ERROR)
|
||||
{
|
||||
(void)inflateEnd(z_stream_ptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size_t have = decompress->buffer_size - z_stream_ptr->avail_out;
|
||||
if (have > 0) {
|
||||
if (0 == z_stream_ptr->avail_out) {
|
||||
fprintf(stderr, "realloc outbuffer,before: %zu bytes, after :%zu B\n", decompress->buffer_size , decompress->buffer_size + have); ;
|
||||
if (have > 0)
|
||||
{
|
||||
if (0 == z_stream_ptr->avail_out)
|
||||
{
|
||||
decompress->buffer_size += have;
|
||||
decompress->buffer = REALLOC(char, decompress->buffer,
|
||||
decompress->buffer_size);
|
||||
*outdata = decompress->buffer;
|
||||
*outdata_len = *outdata_len + have;
|
||||
// http_decoder_log(DEBUG, "%s realloc outbuffer %zu bytes",
|
||||
// http_content_encoding_int2str(decompress->encoding),
|
||||
// http_decoder_log(DEBUG, "%s realloc outbuffer %zu bytes",
|
||||
// http_content_encoding_int2str(decompress->encoding),
|
||||
// decompress->buffer_size);
|
||||
z_stream_ptr->avail_out = have;
|
||||
z_stream_ptr->next_out = (unsigned char *)decompress->buffer +
|
||||
z_stream_ptr->next_out = (unsigned char *)decompress->buffer +
|
||||
(decompress->buffer_size - have);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
*outdata = decompress->buffer;
|
||||
*outdata_len = have;
|
||||
}
|
||||
}
|
||||
if(Z_STREAM_END == ret){
|
||||
if (Z_STREAM_END == ret)
|
||||
{
|
||||
break;
|
||||
}
|
||||
} while (z_stream_ptr->avail_in != 0);
|
||||
@@ -169,10 +176,9 @@ http_content_decompress_write_zlib(struct http_content_decompress *decompress,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
http_content_decompress_write_br(struct http_content_decompress *decompress,
|
||||
const char *indata, size_t indata_len,
|
||||
char **outdata, size_t *outdata_len)
|
||||
static int http_content_decompress_write_br(struct http_content_decompress *decompress,
|
||||
const char *indata, size_t indata_len,
|
||||
char **outdata, size_t *outdata_len)
|
||||
{
|
||||
size_t available_in = indata_len;
|
||||
const unsigned char *next_in = (const unsigned char *)indata;
|
||||
@@ -182,12 +188,15 @@ http_content_decompress_write_br(struct http_content_decompress *decompress,
|
||||
*outdata = NULL;
|
||||
*outdata_len = 0;
|
||||
|
||||
for (;;) {
|
||||
int ret = BrotliDecoderDecompressStream(decompress->br_state, &available_in,
|
||||
&next_in, &available_out, &next_out, 0);
|
||||
for (;;)
|
||||
{
|
||||
int ret = BrotliDecoderDecompressStream(decompress->br_state, &available_in,
|
||||
&next_in, &available_out, &next_out, 0);
|
||||
size_t have = decompress->buffer_size - available_out;
|
||||
if (have > 0) {
|
||||
if (0 == available_out) {
|
||||
if (have > 0)
|
||||
{
|
||||
if (0 == available_out)
|
||||
{
|
||||
decompress->buffer_size += have;
|
||||
decompress->buffer = REALLOC(char, decompress->buffer,
|
||||
decompress->buffer_size);
|
||||
@@ -196,24 +205,28 @@ http_content_decompress_write_br(struct http_content_decompress *decompress,
|
||||
available_out = have;
|
||||
next_out = (unsigned char *)decompress->buffer +
|
||||
(decompress->buffer_size - have);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
*outdata = decompress->buffer;
|
||||
*outdata_len = have;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == BROTLI_DECODER_RESULT_SUCCESS ||
|
||||
ret == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT) {
|
||||
decompress->buffer =NULL;
|
||||
decompress->buffer_size = 0;
|
||||
ret == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT)
|
||||
{
|
||||
decompress->buffer = NULL;
|
||||
decompress->buffer_size = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ret == BROTLI_DECODER_RESULT_ERROR) {
|
||||
//BrotliDecoderErrorCode errcode =
|
||||
BrotliDecoderGetErrorCode(decompress->br_state);
|
||||
*outdata = NULL;
|
||||
*outdata_len = 0;
|
||||
if (ret == BROTLI_DECODER_RESULT_ERROR)
|
||||
{
|
||||
// BrotliDecoderErrorCode errcode =
|
||||
BrotliDecoderGetErrorCode(decompress->br_state);
|
||||
*outdata = NULL;
|
||||
*outdata_len = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -234,20 +247,21 @@ int http_content_decompress_write(struct http_content_decompress *decompress,
|
||||
*outdata = NULL;
|
||||
*outdata_len = 0;
|
||||
|
||||
if(NULL == decompress->buffer ){
|
||||
if (NULL == decompress->buffer)
|
||||
{
|
||||
decompress->buffer = CALLOC(char, HTTP_DECOMPRESS_BUFFER_SIZE);
|
||||
assert(decompress->buffer);
|
||||
decompress->buffer_size = HTTP_DECOMPRESS_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
if (decompress->encoding == HTTP_CONTENT_ENCODING_GZIP ||
|
||||
decompress->encoding == HTTP_CONTENT_ENCODING_DEFLATE) {
|
||||
return http_content_decompress_write_zlib(decompress, indata, indata_len,
|
||||
outdata, outdata_len);
|
||||
decompress->encoding == HTTP_CONTENT_ENCODING_DEFLATE)
|
||||
{
|
||||
return http_content_decompress_write_zlib(decompress, indata, indata_len, outdata, outdata_len);
|
||||
}
|
||||
if (decompress->encoding == HTTP_CONTENT_ENCODING_BR) {
|
||||
return http_content_decompress_write_br(decompress, indata, indata_len,
|
||||
outdata, outdata_len);
|
||||
if (decompress->encoding == HTTP_CONTENT_ENCODING_BR)
|
||||
{
|
||||
return http_content_decompress_write_br(decompress, indata, indata_len, outdata, outdata_len);
|
||||
}
|
||||
assert(0);
|
||||
return -1;
|
||||
|
||||
@@ -1,16 +1,4 @@
|
||||
/*
|
||||
**********************************************************************************************
|
||||
* File: http_content_decompress.h
|
||||
* Description:
|
||||
* Authors: LuWenPeng <luwenpeng@geedgenetworks.com>
|
||||
* Date: 2022-10-31
|
||||
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
|
||||
***********************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _HTTP_CONTENT_DECOMPRESS_H_
|
||||
#define _HTTP_CONTENT_DECOMPRESS_H_
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@@ -19,34 +7,30 @@ extern "C"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
enum http_content_encoding {
|
||||
HTTP_CONTENT_ENCODING_NONE = 0,
|
||||
HTTP_CONTENT_ENCODING_GZIP = 1 << 1,
|
||||
HTTP_CONTENT_ENCODING_DEFLATE = 1 << 2,
|
||||
HTTP_CONTENT_ENCODING_BR = 1 << 3,
|
||||
};
|
||||
enum http_content_encoding
|
||||
{
|
||||
HTTP_CONTENT_ENCODING_NONE = 0,
|
||||
HTTP_CONTENT_ENCODING_GZIP = 1 << 1,
|
||||
HTTP_CONTENT_ENCODING_DEFLATE = 1 << 2,
|
||||
HTTP_CONTENT_ENCODING_BR = 1 << 3,
|
||||
};
|
||||
|
||||
struct http_content_decompress;
|
||||
struct http_content_decompress;
|
||||
|
||||
enum http_content_encoding
|
||||
http_content_encoding_str2int(const char *content_encoding);
|
||||
enum http_content_encoding http_content_encoding_str2int(const char *content_encoding);
|
||||
|
||||
const char *
|
||||
http_content_encoding_int2str(enum http_content_encoding content_encoding);
|
||||
const char *http_content_encoding_int2str(enum http_content_encoding content_encoding);
|
||||
|
||||
struct http_content_decompress *
|
||||
http_content_decompress_create(enum http_content_encoding encoding);
|
||||
struct http_content_decompress *http_content_decompress_create(enum http_content_encoding encoding);
|
||||
|
||||
void http_content_decompress_destroy(struct http_content_decompress *decompress);
|
||||
void http_content_decompress_destroy(struct http_content_decompress *decompress);
|
||||
|
||||
// return 0 : success
|
||||
// return -1 : error
|
||||
int http_content_decompress_write(struct http_content_decompress *decompress,
|
||||
const char *indata, size_t indata_len,
|
||||
char **outdata, size_t *outdata_len);
|
||||
// return 0 : success
|
||||
// return -1 : error
|
||||
int http_content_decompress_write(struct http_content_decompress *decompress,
|
||||
const char *indata, size_t indata_len,
|
||||
char **outdata, size_t *outdata_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "http_decoder_inc.h"
|
||||
#include "http_decoder_private.h"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
|
||||
@@ -123,7 +123,7 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
|
||||
/* llhttp always call on_message_begin() even if llhttp_execute() error!!! */
|
||||
msg = http_message_new(HTTP_TRANSACTION_START, queue, queue_idx, HTTP_REQUEST);
|
||||
session_mq_publish_message(ev_ctx->ref_session, exdata->pub_topic_id, msg);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TRANSACTION_NEW, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_TRANSACTION_NEW, 1);
|
||||
break;
|
||||
case HTTP_EVENT_REQ_LINE:
|
||||
msg = http_message_new(HTTP_MESSAGE_REQ_LINE, queue, queue_idx, HTTP_REQUEST);
|
||||
@@ -131,7 +131,7 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
|
||||
if (httpd_tunnel_identify(httpd_env, FLOW_DIRECTION_C2S, half_data))
|
||||
{
|
||||
exdata->tunnel_state = HTTP_TUN_C2S_HDR_START;
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TUNNEL, 1);
|
||||
// http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TUNNEL, 1);
|
||||
}
|
||||
if (httpd_is_tunnel_session(httpd_env, exdata))
|
||||
{
|
||||
@@ -157,11 +157,11 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
|
||||
session_mq_publish_message(ev_ctx->ref_session, exdata->pub_topic_id, msg);
|
||||
|
||||
int tot_c2s_headers = http_half_data_get_total_parsed_header_count(half_data);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_HEADERS_C2S, tot_c2s_headers);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_C2S_HEADERS, tot_c2s_headers);
|
||||
|
||||
hstring tmp_url = {};
|
||||
http_half_data_get_url(half_data, &tmp_url);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_URL_BYTES, tmp_url.iov_len);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_URL_BYTES, tmp_url.iov_len);
|
||||
}
|
||||
break;
|
||||
case HTTP_EVENT_REQ_BODY_BEGIN:
|
||||
@@ -176,9 +176,10 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
|
||||
http_half_get_lastest_decompress_buffer(half_data, &decompress_body);
|
||||
msg = http_body_message_new(HTTP_MESSAGE_REQ_BODY, queue, queue_idx, HTTP_REQUEST, &raw_body, &decompress_body);
|
||||
session_mq_publish_message(ev_ctx->ref_session, exdata->pub_topic_id, msg);
|
||||
if(decompress_body.iov_base != NULL){
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_ZIP_BYTES, raw_body.iov_len);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_UNZIP_BYTES, decompress_body.iov_len);
|
||||
if (decompress_body.iov_base != NULL)
|
||||
{
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_C2S_ZIP_BYTES, raw_body.iov_len);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_C2S_UNZIP_BYTES, decompress_body.iov_len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -194,8 +195,8 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
|
||||
{
|
||||
msg = http_message_new(HTTP_TRANSACTION_END, queue, queue_idx, HTTP_REQUEST);
|
||||
session_mq_publish_message(ev_ctx->ref_session, exdata->pub_topic_id, msg);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TRANSACTION_FREE, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_ASYMMETRY_TRANSACTION_C2S, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_TRANSACTION_FREE, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_C2S_ASYMMETRY_TRANSACTION, 1);
|
||||
}
|
||||
if (httpd_is_tunnel_session(httpd_env, exdata))
|
||||
{
|
||||
@@ -285,7 +286,7 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
|
||||
session_mq_publish_message(ev_ctx->ref_session, exdata->pub_topic_id, msg);
|
||||
|
||||
int tot_s2c_headers = http_half_data_get_total_parsed_header_count(half_data);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_HEADERS_S2C, tot_s2c_headers);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_S2C_HEADERS, tot_s2c_headers);
|
||||
|
||||
if (httpd_is_tunnel_session(httpd_env, exdata))
|
||||
{
|
||||
@@ -304,13 +305,14 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
|
||||
hstring raw_body = {};
|
||||
http_decoder_half_data_get_raw_body(half_data, &raw_body);
|
||||
hstring decompress_body = {};
|
||||
http_half_get_lastest_decompress_buffer(half_data, &decompress_body);
|
||||
http_half_get_lastest_decompress_buffer(half_data, &decompress_body);
|
||||
msg = http_body_message_new(HTTP_MESSAGE_RES_BODY, queue, queue_idx, HTTP_RESPONSE, &raw_body, &decompress_body);
|
||||
session_mq_publish_message(ev_ctx->ref_session, exdata->pub_topic_id, msg);
|
||||
if(decompress_body.iov_base != NULL){
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_ZIP_BYTES, raw_body.iov_len);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_UNZIP_BYTES, decompress_body.iov_len);
|
||||
}
|
||||
if (decompress_body.iov_base != NULL)
|
||||
{
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_S2C_ZIP_BYTES, raw_body.iov_len);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_S2C_UNZIP_BYTES, decompress_body.iov_len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case HTTP_EVENT_RES_BODY_END:
|
||||
@@ -320,11 +322,11 @@ static void http_event_handler(enum http_event event, struct http_decoder_half_d
|
||||
case HTTP_EVENT_RES_END:
|
||||
msg = http_message_new(HTTP_TRANSACTION_END, queue, queue_idx, HTTP_RESPONSE);
|
||||
session_mq_publish_message(ev_ctx->ref_session, exdata->pub_topic_id, msg);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TRANSACTION_FREE, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_TRANSACTION_FREE, 1);
|
||||
session_is_symmetric(ev_ctx->ref_session, &flow_flag);
|
||||
if (SESSION_SEEN_S2C_FLOW == flow_flag)
|
||||
{
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_ASYMMETRY_TRANSACTION_S2C, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_S2C_ASYMMETRY_TRANSACTION, 1);
|
||||
}
|
||||
|
||||
http_half_update_state(half_data, event);
|
||||
@@ -604,7 +606,7 @@ static struct http_decoder_exdata *httpd_session_exdata_new(struct session *sess
|
||||
httpd_env, req_start_seq, res_start_seq);
|
||||
// exdata->sub_topic_id = sub_topic_id;
|
||||
int thread_id = stellar_get_current_thread_index();
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_SESSION_NEW, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_SESSION_NEW, 1);
|
||||
return exdata;
|
||||
}
|
||||
|
||||
@@ -645,13 +647,13 @@ extern "C"
|
||||
|
||||
if (SESSION_SEEN_C2S_FLOW == flow_flag)
|
||||
{
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_ASYMMETRY_SESSION_C2S, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_C2S_ASYMMETRY_SESSION, 1);
|
||||
}
|
||||
else if (SESSION_SEEN_S2C_FLOW == flow_flag)
|
||||
{
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_ASYMMETRY_SESSION_S2C, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_S2C_ASYMMETRY_SESSION, 1);
|
||||
}
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_SESSION_FREE, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_SESSION_FREE, 1);
|
||||
}
|
||||
|
||||
static void http_decoder_execute(struct session *sess, struct http_decoder_env *httpd_env, http_decoder_exdata *exdata, const char *payload, uint16_t payload_len)
|
||||
@@ -669,21 +671,21 @@ extern "C"
|
||||
if (FLOW_DIRECTION_C2S == sess_dir)
|
||||
{
|
||||
cur_half = exdata->decoder->c2s_half;
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_BYTES_C2S, payload_len);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TCP_SEG_C2S, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_C2S_BYTES, payload_len);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_C2S_TCP_SEG, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
cur_half = exdata->decoder->s2c_half;
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_BYTES_S2C, payload_len);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_TCP_SEG_S2C, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_S2C_BYTES, payload_len);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_S2C_TCP_SEG, 1);
|
||||
}
|
||||
|
||||
http_decoder_half_reinit(cur_half, exdata->queue, exdata->mempool, sess);
|
||||
int ret = http_decoder_half_parse(httpd_env->hd_cfg.proxy_enable, cur_half, payload, payload_len);
|
||||
if (ret < 0)
|
||||
{
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTPD_STAT_PARSE_ERR, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, thread_id, HTTP_STAT_PARSE_ERR, 1);
|
||||
stellar_session_plugin_dettach_current_session(sess);
|
||||
}
|
||||
}
|
||||
@@ -742,7 +744,7 @@ extern "C"
|
||||
if (NULL == exdata)
|
||||
{
|
||||
session_mq_ignore_message(sess, topic_id, httpd_env->plugin_id);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, stellar_get_current_thread_index(), HTTPD_STAT_PARSE_ERR, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, stellar_get_current_thread_index(), HTTP_STAT_PARSE_ERR, 1);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -750,7 +752,7 @@ extern "C"
|
||||
case HTTP_TUNNEL_CLOSING:
|
||||
if (NULL == exdata)
|
||||
{
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, stellar_get_current_thread_index(), HTTPD_STAT_PARSE_ERR, 1);
|
||||
http_decoder_stat_update(&httpd_env->hd_stat, stellar_get_current_thread_index(), HTTP_STAT_PARSE_ERR, 1);
|
||||
return;
|
||||
}
|
||||
if (exdata->in_tunnel_is_http)
|
||||
@@ -1086,23 +1088,20 @@ extern "C"
|
||||
}
|
||||
/**
|
||||
* @brief If the body hasn't been compressed, same as http_message_raw_body_get0().
|
||||
*
|
||||
*/
|
||||
|
||||
if (HTTP_MESSAGE_REQ_BODY_START == msg->type
|
||||
|| HTTP_MESSAGE_REQ_BODY == msg->type
|
||||
|| HTTP_MESSAGE_REQ_BODY_END == msg->type)
|
||||
*
|
||||
*/
|
||||
|
||||
if (HTTP_MESSAGE_REQ_BODY_START == msg->type || HTTP_MESSAGE_REQ_BODY == msg->type || HTTP_MESSAGE_REQ_BODY_END == msg->type)
|
||||
{
|
||||
ref_data = msg->ref_queue->array[msg->queue_index].req_data;
|
||||
}
|
||||
else if (HTTP_MESSAGE_RES_BODY_START == msg->type
|
||||
|| HTTP_MESSAGE_RES_BODY == msg->type
|
||||
|| HTTP_MESSAGE_RES_BODY_END == msg->type)
|
||||
else if (HTTP_MESSAGE_RES_BODY_START == msg->type || HTTP_MESSAGE_RES_BODY == msg->type || HTTP_MESSAGE_RES_BODY_END == msg->type)
|
||||
{
|
||||
ref_data = msg->ref_queue->array[msg->queue_index].res_data;
|
||||
}
|
||||
ecode = http_half_data_get_content_encoding(ref_data);
|
||||
if(ref_data != NULL && HTTP_CONTENT_ENCODING_NONE != ecode){
|
||||
if (ref_data != NULL && HTTP_CONTENT_ENCODING_NONE != ecode)
|
||||
{
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "http_decoder_inc.h"
|
||||
#include "http_decoder_private.h"
|
||||
#include "llhttp.h"
|
||||
#include "uthash/utlist.h"
|
||||
|
||||
@@ -85,8 +85,7 @@ void http_half_decompress_buffer_free(struct http_decoder_half_data *data, hstri
|
||||
struct http_decompress_buffer *el, *tmp;
|
||||
DL_FOREACH_SAFE(data->decompress_buffer_list, el, tmp)
|
||||
{
|
||||
if (el->iov.iov_base == decompress_body->iov_base
|
||||
&& el->iov.iov_len == decompress_body->iov_len)
|
||||
if (el->iov.iov_base == decompress_body->iov_base && el->iov.iov_len == decompress_body->iov_len)
|
||||
{
|
||||
DL_DELETE(data->decompress_buffer_list, el);
|
||||
if (el->iov.iov_base)
|
||||
@@ -157,7 +156,7 @@ static void http_decoder_half_data_decompress(struct http_decoder_half_data *dat
|
||||
return;
|
||||
}
|
||||
|
||||
if(local_outdata!= NULL && local_outdata_len > 0)
|
||||
if (local_outdata != NULL && local_outdata_len > 0)
|
||||
{
|
||||
struct http_decompress_buffer *decompress_buffer = CALLOC(struct http_decompress_buffer, 1);
|
||||
assert(decompress_buffer);
|
||||
@@ -873,7 +872,7 @@ static void http_decoder_half_decompress_buf_free(struct http_decoder_half_data
|
||||
if (el->iov.iov_base != NULL)
|
||||
{
|
||||
FREE(el->iov.iov_base);
|
||||
}
|
||||
}
|
||||
FREE(el);
|
||||
}
|
||||
ref_data->decompress_buffer_list = NULL;
|
||||
@@ -1208,7 +1207,7 @@ void http_half_get_max_transaction_seq(struct http_decoder_exdata *exdata, long
|
||||
|
||||
enum http_content_encoding http_half_data_get_content_encoding(struct http_decoder_half_data *hf_data)
|
||||
{
|
||||
if(NULL == hf_data)
|
||||
if (NULL == hf_data)
|
||||
{
|
||||
return HTTP_CONTENT_ENCODING_NONE;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
#ifndef _HTTP_DECODER_HALF_H_
|
||||
#define _HTTP_DECODER_HALF_H_
|
||||
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
#include "stellar/session.h"
|
||||
#include "stellar/http.h"
|
||||
#include "http_content_decompress.h"
|
||||
#include "http_decoder_result_queue.h"
|
||||
#include "llhttp.h"
|
||||
#include <llhttp.h>
|
||||
|
||||
// only one http event is fired at a time
|
||||
enum http_event {
|
||||
enum http_event
|
||||
{
|
||||
HTTP_EVENT_REQ_INIT = 1 << 1,
|
||||
HTTP_EVENT_REQ_LINE = 1 << 2,
|
||||
HTTP_EVENT_REQ_HDR = 1 << 3,
|
||||
@@ -29,7 +28,8 @@ enum http_event {
|
||||
HTTP_EVENT_RES_END = 1 << 16,
|
||||
};
|
||||
|
||||
struct http_event_context {
|
||||
struct http_event_context
|
||||
{
|
||||
struct http_decoder_exdata *ref_httpd_ctx;
|
||||
nmx_pool_t *ref_mempool;
|
||||
struct session *ref_session;
|
||||
@@ -43,12 +43,12 @@ typedef void http_event_cb(enum http_event event, struct http_decoder_half_data
|
||||
struct http_event_context *ev_ctx, void *httpd_plugin_env);
|
||||
|
||||
struct http_decoder_half *
|
||||
http_decoder_half_new(struct http_decoder_exdata *hd_ctx, nmx_pool_t *mempool, http_event_cb *event_cb,
|
||||
enum llhttp_type http_type, int decompress_switch, struct http_decoder_env *httpd_env,long long start_seq);
|
||||
http_decoder_half_new(struct http_decoder_exdata *hd_ctx, nmx_pool_t *mempool, http_event_cb *event_cb,
|
||||
enum llhttp_type http_type, int decompress_switch, struct http_decoder_env *httpd_env, long long start_seq);
|
||||
|
||||
void http_decoder_half_free(nmx_pool_t *mempool, struct http_decoder_half *half);
|
||||
|
||||
void http_decoder_half_reinit(struct http_decoder_half *half,
|
||||
void http_decoder_half_reinit(struct http_decoder_half *half,
|
||||
struct http_decoder_result_queue *queue,
|
||||
nmx_pool_t *mempool, struct session *sess);
|
||||
|
||||
@@ -56,7 +56,7 @@ int http_decoder_half_parse(int proxy_enable, struct http_decoder_half *half, co
|
||||
|
||||
long long http_decoder_half_trans_count(struct http_decoder_half *half);
|
||||
|
||||
//http decoder half data API
|
||||
// http decoder half data API
|
||||
struct http_decoder_half_data *
|
||||
http_decoder_half_data_new(nmx_pool_t *mempool);
|
||||
|
||||
@@ -90,16 +90,15 @@ void http_decoder_join_url(struct http_decoder_half_data *hfdata,
|
||||
nmx_pool_t *mempool,
|
||||
const struct http_header *host_hdr);
|
||||
int http_decoder_join_url_finally(struct http_event_context *ev_ctx,
|
||||
struct http_decoder_half_data *hfdata,
|
||||
nmx_pool_t *mempool);
|
||||
struct http_decoder_half_data *hfdata,
|
||||
nmx_pool_t *mempool);
|
||||
int http_half_data_get_url(struct http_decoder_half_data *res_data, hstring *url);
|
||||
int http_half_data_get_transaction_seq(struct http_decoder_half_data *hf_data);
|
||||
|
||||
void http_half_data_update_commit_index(struct http_decoder_half_data * half_data);
|
||||
void http_half_data_update_commit_index(struct http_decoder_half_data *half_data);
|
||||
void http_half_pre_context_free(struct session *sess, struct http_decoder_exdata *exdata);
|
||||
void http_half_update_state(struct http_decoder_half_data *hf_data, enum http_event state);
|
||||
int http_half_data_get_total_parsed_header_count(struct http_decoder_half_data * half_data);
|
||||
void http_half_get_max_transaction_seq(struct http_decoder_exdata *exdata, long long *max_req_seq, long long *max_res_seq);
|
||||
void http_half_update_state(struct http_decoder_half_data *hf_data, enum http_event state);
|
||||
int http_half_data_get_total_parsed_header_count(struct http_decoder_half_data *half_data);
|
||||
void http_half_get_max_transaction_seq(struct http_decoder_exdata *exdata, long long *max_req_seq, long long *max_res_seq);
|
||||
|
||||
enum http_content_encoding http_half_data_get_content_encoding(struct http_decoder_half_data *hf_data);
|
||||
#endif
|
||||
enum http_content_encoding http_half_data_get_content_encoding(struct http_decoder_half_data *hf_data);
|
||||
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
**********************************************************************************************
|
||||
* File: http_decoder_inc.h
|
||||
* Description:
|
||||
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
|
||||
* Date: 2024-01-10
|
||||
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
|
||||
***********************************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef _HTTP_DECODER_INC_H_
|
||||
#define _HTTP_DECODER_INC_H_
|
||||
|
||||
#ifndef __USE_MISC
|
||||
#define __USE_MISC 1
|
||||
#endif
|
||||
|
||||
#include <cstddef>
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#include <bits/types/struct_iovec.h>
|
||||
#include "stellar/stellar.h"
|
||||
#include "stellar/layer.h"
|
||||
#include "stellar/packet.h"
|
||||
#include "stellar/utils.h"
|
||||
#include "stellar/session.h"
|
||||
#include "stellar/stellar_mq.h"
|
||||
#include "stellar/stellar_exdata.h"
|
||||
|
||||
#include "nmx_pool/nmx_palloc.h"
|
||||
#include "stellar/utils.h"
|
||||
#include "stellar/http.h"
|
||||
#include "http_decoder_result_queue.h"
|
||||
#include "http_decoder_half.h"
|
||||
#include "http_decoder_table.h"
|
||||
#include "http_decoder_result_queue.h"
|
||||
#include "http_decoder_utils.h"
|
||||
#include "http_decoder_stat.h"
|
||||
#include "http_decoder_tunnel.h"
|
||||
#include "fieldstat/fieldstat_easy.h"
|
||||
#include "toml/toml.h"
|
||||
|
||||
#ifndef likely
|
||||
#define likely(x) __builtin_expect((x), 1)
|
||||
#endif
|
||||
#ifndef unlikely
|
||||
#define unlikely(x) __builtin_expect((x), 0)
|
||||
#endif
|
||||
|
||||
#define MEMPOOL_CALLOC(pool, type, number) ((type *)nmx_pcalloc(pool, sizeof(type) * number))
|
||||
#define MEMPOOL_REALLOC(pool)
|
||||
#define MEMPOOL_FREE(pool, p) nmx_pfree(pool, p)
|
||||
|
||||
#define ENABLE_MEMPOOL 0
|
||||
#if ENABLE_MEMPOOL
|
||||
#define HD_CALLOC(pool, type, number) MEMPOOL_CALLOC(pool, number, type)
|
||||
#define HD_FREE(pool, p) MEMPOOL_FREE(pool, p)
|
||||
#else
|
||||
#define HD_CALLOC(pool, type, number) CALLOC(type, number)
|
||||
#define HD_FREE(pool, p) FREE(p)
|
||||
#endif
|
||||
|
||||
#define HTTP_IDENTIFY_LEN 16
|
||||
#define HD_RESULT_QUEUE_LEN 16
|
||||
|
||||
#define DEFAULT_STAT_OUTPUT_INTERVAL 1
|
||||
#define DEFAULT_STAT_INTERVAL_PKTS 1000
|
||||
#define DEFAULT_MEMPOOL_SIZE (32 * 1024)
|
||||
|
||||
#define HTTPD_CFG_FILE "./etc/http/http_decoder.toml"
|
||||
#define FILEDSTAT_OUTPUT_FILE "./metrics/http_decoder_fs4.json"
|
||||
|
||||
#define HTTP_CTX_NOT_HTTP "__NOT_HTTP_SESS__"
|
||||
#define HTTP_CTX_IS_HTTP "__FAKE_HTTP_CTX__"
|
||||
|
||||
struct http_decoder_config
|
||||
{
|
||||
int decompress_switch;
|
||||
int stat_interval_pkts; // call fieldstat_incrby every stat_interval_pkts
|
||||
int stat_output_interval;
|
||||
int proxy_enable;
|
||||
size_t result_queue_len; // per session result queue length
|
||||
size_t mempool_size; // per session mempool size
|
||||
};
|
||||
|
||||
/**
|
||||
* NOTE: http_message don't have the ownership of data
|
||||
*/
|
||||
struct http_message
|
||||
{
|
||||
uint8_t flow_type;
|
||||
enum http_message_type type;
|
||||
size_t queue_index;
|
||||
struct http_decoder_result_queue *ref_queue;
|
||||
hstring raw_payload;//cause tcp reorder, maybe receive many tcp segments for one packet
|
||||
hstring decompress_payload;
|
||||
hstring tunnel_payload;
|
||||
};
|
||||
|
||||
struct http_decoder
|
||||
{
|
||||
struct http_decoder_half *c2s_half;
|
||||
struct http_decoder_half *s2c_half;
|
||||
};
|
||||
|
||||
enum httpd_topic_index{
|
||||
HTTPD_TOPIC_TCP_STREAM_INDEX = 0,
|
||||
HTTPD_TOPIC_HTTP_MSG_INDEX,
|
||||
HTTPD_TOPIC_HTTP_TUNNEL_INDEX,
|
||||
HTTPD_TOPIC_INDEX_MAX,
|
||||
};
|
||||
|
||||
struct http_decoder_exdata
|
||||
{
|
||||
int sub_topic_id; //tcp_stream
|
||||
int pub_topic_id; //http message or http tunnel msg
|
||||
struct http_decoder_result_queue *queue;
|
||||
struct http_decoder *decoder;
|
||||
nmx_pool_t *mempool;
|
||||
enum http_tunnel_state tunnel_state;
|
||||
int in_tunnel_is_http;
|
||||
};
|
||||
|
||||
// struct http_decoder_context{
|
||||
// int array_size;
|
||||
// struct http_decoder_exdata **exdata_array; //raw tcp stream for http msg; http tunnel for inner http transaction.
|
||||
// };
|
||||
|
||||
struct http_topic_exdata_compose{
|
||||
enum httpd_topic_index index;
|
||||
const char *topic_name;
|
||||
on_session_msg_cb_func *on_msg_cb;
|
||||
stellar_msg_free_cb_func *msg_free_cb;
|
||||
const char *exdata_name;
|
||||
stellar_exdata_free *exdata_free_cb;
|
||||
int sub_topic_id; //as consumer
|
||||
int exdata_id;
|
||||
};
|
||||
|
||||
struct http_decoder_env
|
||||
{
|
||||
struct stellar *st;
|
||||
int plugin_id;
|
||||
struct http_topic_exdata_compose topic_exdata_compose[HTTPD_TOPIC_INDEX_MAX];
|
||||
struct http_decoder_config hd_cfg;
|
||||
struct http_decoder_stat hd_stat;
|
||||
};
|
||||
|
||||
struct http_message;
|
||||
|
||||
struct http_message *http_message_new(enum http_message_type type, struct http_decoder_result_queue *queue,
|
||||
int queue_index, unsigned char flow_type);
|
||||
struct http_message *http_body_message_new(enum http_message_type type, struct http_decoder_result_queue *queue,
|
||||
int queue_index, uint8_t flow_type, hstring *raw_payload);
|
||||
int http_topic_exdata_compose_get_index(const struct http_decoder_env *httpd_env, int by_topic_id);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
152
decoders/http/http_decoder_private.h
Normal file
152
decoders/http/http_decoder_private.h
Normal file
@@ -0,0 +1,152 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __USE_MISC
|
||||
#define __USE_MISC 1
|
||||
#endif
|
||||
|
||||
#include <cstddef>
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#include <bits/types/struct_iovec.h>
|
||||
#include "stellar/stellar.h"
|
||||
#include "stellar/layer.h"
|
||||
#include "stellar/packet.h"
|
||||
#include "stellar/utils.h"
|
||||
#include "stellar/session.h"
|
||||
#include "stellar/stellar_mq.h"
|
||||
#include "stellar/stellar_exdata.h"
|
||||
|
||||
#include "nmx_pool/nmx_palloc.h"
|
||||
#include "stellar/utils.h"
|
||||
#include "stellar/http.h"
|
||||
#include "http_decoder_result_queue.h"
|
||||
#include "http_decoder_half.h"
|
||||
#include "http_decoder_table.h"
|
||||
#include "http_decoder_result_queue.h"
|
||||
#include "http_decoder_utils.h"
|
||||
#include "http_decoder_stat.h"
|
||||
#include "http_decoder_tunnel.h"
|
||||
#include "fieldstat/fieldstat_easy.h"
|
||||
#include "toml/toml.h"
|
||||
|
||||
#ifndef likely
|
||||
#define likely(x) __builtin_expect((x), 1)
|
||||
#endif
|
||||
#ifndef unlikely
|
||||
#define unlikely(x) __builtin_expect((x), 0)
|
||||
#endif
|
||||
|
||||
#define MEMPOOL_CALLOC(pool, type, number) ((type *)nmx_pcalloc(pool, sizeof(type) * number))
|
||||
#define MEMPOOL_REALLOC(pool)
|
||||
#define MEMPOOL_FREE(pool, p) nmx_pfree(pool, p)
|
||||
|
||||
#define ENABLE_MEMPOOL 0
|
||||
#if ENABLE_MEMPOOL
|
||||
#define HD_CALLOC(pool, type, number) MEMPOOL_CALLOC(pool, number, type)
|
||||
#define HD_FREE(pool, p) MEMPOOL_FREE(pool, p)
|
||||
#else
|
||||
#define HD_CALLOC(pool, type, number) CALLOC(type, number)
|
||||
#define HD_FREE(pool, p) FREE(p)
|
||||
#endif
|
||||
|
||||
#define HTTP_IDENTIFY_LEN 16
|
||||
#define HD_RESULT_QUEUE_LEN 16
|
||||
|
||||
#define DEFAULT_STAT_OUTPUT_INTERVAL 1
|
||||
#define DEFAULT_STAT_INTERVAL_PKTS 1000
|
||||
#define DEFAULT_MEMPOOL_SIZE (32 * 1024)
|
||||
|
||||
#define HTTPD_CFG_FILE "./etc/http/http_decoder.toml"
|
||||
#define FILEDSTAT_OUTPUT_FILE "./metrics/http_decoder_fs4.json"
|
||||
|
||||
#define HTTP_CTX_NOT_HTTP "__NOT_HTTP_SESS__"
|
||||
#define HTTP_CTX_IS_HTTP "__FAKE_HTTP_CTX__"
|
||||
|
||||
struct http_decoder_config
|
||||
{
|
||||
int decompress_switch;
|
||||
int stat_interval_pkts; // call fieldstat_incrby every stat_interval_pkts
|
||||
int stat_output_interval;
|
||||
int proxy_enable;
|
||||
size_t result_queue_len; // per session result queue length
|
||||
size_t mempool_size; // per session mempool size
|
||||
};
|
||||
|
||||
/**
|
||||
* NOTE: http_message don't have the ownership of data
|
||||
*/
|
||||
struct http_message
|
||||
{
|
||||
uint8_t flow_type;
|
||||
enum http_message_type type;
|
||||
size_t queue_index;
|
||||
struct http_decoder_result_queue *ref_queue;
|
||||
hstring raw_payload; // cause tcp reorder, maybe receive many tcp segments for one packet
|
||||
hstring decompress_payload;
|
||||
hstring tunnel_payload;
|
||||
};
|
||||
|
||||
struct http_decoder
|
||||
{
|
||||
struct http_decoder_half *c2s_half;
|
||||
struct http_decoder_half *s2c_half;
|
||||
};
|
||||
|
||||
enum httpd_topic_index
|
||||
{
|
||||
HTTPD_TOPIC_TCP_STREAM_INDEX = 0,
|
||||
HTTPD_TOPIC_HTTP_MSG_INDEX,
|
||||
HTTPD_TOPIC_HTTP_TUNNEL_INDEX,
|
||||
HTTPD_TOPIC_INDEX_MAX,
|
||||
};
|
||||
|
||||
struct http_decoder_exdata
|
||||
{
|
||||
int sub_topic_id; // tcp_stream
|
||||
int pub_topic_id; // http message or http tunnel msg
|
||||
struct http_decoder_result_queue *queue;
|
||||
struct http_decoder *decoder;
|
||||
nmx_pool_t *mempool;
|
||||
enum http_tunnel_state tunnel_state;
|
||||
int in_tunnel_is_http;
|
||||
};
|
||||
|
||||
// struct http_decoder_context{
|
||||
// int array_size;
|
||||
// struct http_decoder_exdata **exdata_array; //raw tcp stream for http msg; http tunnel for inner http transaction.
|
||||
// };
|
||||
|
||||
struct http_topic_exdata_compose
|
||||
{
|
||||
enum httpd_topic_index index;
|
||||
const char *topic_name;
|
||||
on_session_msg_cb_func *on_msg_cb;
|
||||
stellar_msg_free_cb_func *msg_free_cb;
|
||||
const char *exdata_name;
|
||||
stellar_exdata_free *exdata_free_cb;
|
||||
int sub_topic_id; // as consumer
|
||||
int exdata_id;
|
||||
};
|
||||
|
||||
struct http_decoder_env
|
||||
{
|
||||
struct stellar *st;
|
||||
int plugin_id;
|
||||
struct http_topic_exdata_compose topic_exdata_compose[HTTPD_TOPIC_INDEX_MAX];
|
||||
struct http_decoder_config hd_cfg;
|
||||
struct http_decoder_stat hd_stat;
|
||||
};
|
||||
|
||||
struct http_message;
|
||||
|
||||
struct http_message *http_message_new(enum http_message_type type, struct http_decoder_result_queue *queue,
|
||||
int queue_index, unsigned char flow_type);
|
||||
struct http_message *http_body_message_new(enum http_message_type type, struct http_decoder_result_queue *queue,
|
||||
int queue_index, uint8_t flow_type, hstring *raw_payload);
|
||||
int http_topic_exdata_compose_get_index(const struct http_decoder_env *httpd_env, int by_topic_id);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,14 +1,5 @@
|
||||
/*
|
||||
**********************************************************************************************
|
||||
* File: http_decoder_result_queue.c
|
||||
* Description:
|
||||
* Authors: Liuwentan <liuwentan@geedgenetworks.com>
|
||||
* Date: 2024-01-15
|
||||
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
|
||||
***********************************************************************************************
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include "http_decoder_inc.h"
|
||||
#include "http_decoder_private.h"
|
||||
|
||||
struct http_decoder_result_queue *
|
||||
http_decoder_result_queue_new(nmx_pool_t *mempool, size_t queue_size)
|
||||
@@ -28,23 +19,28 @@ http_decoder_result_queue_new(nmx_pool_t *mempool, size_t queue_size)
|
||||
|
||||
void http_decoder_result_queue_free(nmx_pool_t *mempool, struct http_decoder_result_queue *queue)
|
||||
{
|
||||
if (NULL == queue) {
|
||||
return;
|
||||
if (NULL == queue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (queue->array != NULL) {
|
||||
for (size_t i = 0; i < queue->queue_size; i++) {
|
||||
if (queue->array[i].req_data != NULL) {
|
||||
http_decoder_half_data_free(mempool, queue->array[i].req_data);
|
||||
queue->array[i].req_data = NULL;
|
||||
if (queue->array != NULL)
|
||||
{
|
||||
for (size_t i = 0; i < queue->queue_size; i++)
|
||||
{
|
||||
if (queue->array[i].req_data != NULL)
|
||||
{
|
||||
http_decoder_half_data_free(mempool, queue->array[i].req_data);
|
||||
queue->array[i].req_data = NULL;
|
||||
}
|
||||
|
||||
if (queue->array[i].res_data != NULL) {
|
||||
http_decoder_half_data_free(mempool, queue->array[i].res_data);
|
||||
queue->array[i].res_data = NULL;
|
||||
if (queue->array[i].res_data != NULL)
|
||||
{
|
||||
http_decoder_half_data_free(mempool, queue->array[i].res_data);
|
||||
queue->array[i].res_data = NULL;
|
||||
}
|
||||
}
|
||||
MEMPOOL_FREE(mempool, queue->array);
|
||||
MEMPOOL_FREE(mempool, queue->array);
|
||||
}
|
||||
MEMPOOL_FREE(mempool, queue);
|
||||
}
|
||||
@@ -78,11 +74,13 @@ size_t http_decoder_result_queue_res_index(struct http_decoder_result_queue *que
|
||||
int http_decoder_result_queue_push_req(struct http_decoder_result_queue *queue,
|
||||
struct http_decoder_half_data *req_data)
|
||||
{
|
||||
if (NULL == queue || NULL == req_data) {
|
||||
if (NULL == queue || NULL == req_data)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
assert(queue->array[queue->req_index].req_data == NULL);
|
||||
if (queue->array[queue->req_index].req_data != NULL) {
|
||||
if (queue->array[queue->req_index].req_data != NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
queue->array[queue->req_index].req_data = req_data;
|
||||
@@ -92,11 +90,13 @@ int http_decoder_result_queue_push_req(struct http_decoder_result_queue *queue,
|
||||
int http_decoder_result_queue_push_res(struct http_decoder_result_queue *queue,
|
||||
struct http_decoder_half_data *res_data)
|
||||
{
|
||||
if (NULL == queue || NULL == res_data) {
|
||||
if (NULL == queue || NULL == res_data)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
assert(queue->array[queue->res_index].res_data == NULL);
|
||||
if (queue->array[queue->res_index].res_data != NULL) {
|
||||
if (queue->array[queue->res_index].res_data != NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -107,7 +107,8 @@ int http_decoder_result_queue_push_res(struct http_decoder_result_queue *queue,
|
||||
struct http_decoder_half_data *
|
||||
http_decoder_result_queue_pop_req(struct http_decoder_result_queue *queue)
|
||||
{
|
||||
if (NULL == queue) {
|
||||
if (NULL == queue)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
struct http_decoder_half_data *req_data = queue->array[queue->req_index].req_data;
|
||||
@@ -118,7 +119,8 @@ http_decoder_result_queue_pop_req(struct http_decoder_result_queue *queue)
|
||||
struct http_decoder_half_data *
|
||||
http_decoder_result_queue_pop_res(struct http_decoder_result_queue *queue)
|
||||
{
|
||||
if (NULL == queue) {
|
||||
if (NULL == queue)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -130,7 +132,8 @@ http_decoder_result_queue_pop_res(struct http_decoder_result_queue *queue)
|
||||
struct http_decoder_half_data *
|
||||
http_decoder_result_queue_peek_req(struct http_decoder_result_queue *queue)
|
||||
{
|
||||
if (NULL == queue) {
|
||||
if (NULL == queue)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
assert(queue->req_index < queue->queue_size);
|
||||
@@ -140,7 +143,8 @@ http_decoder_result_queue_peek_req(struct http_decoder_result_queue *queue)
|
||||
struct http_decoder_half_data *
|
||||
http_decoder_result_queue_peek_res(struct http_decoder_result_queue *queue)
|
||||
{
|
||||
if (NULL == queue) {
|
||||
if (NULL == queue)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
assert(queue->res_index < queue->queue_size);
|
||||
|
||||
@@ -1,29 +1,21 @@
|
||||
/*
|
||||
**********************************************************************************************
|
||||
* File: http_decoder_result_queue.h
|
||||
* Description:
|
||||
* Authors: Liuwentan <liuwentan@geedgenetworks.com>
|
||||
* Date: 2024-01-15
|
||||
* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved.
|
||||
***********************************************************************************************
|
||||
*/
|
||||
#ifndef _HTTP_DECODER_RESULT_QUEUE_H_
|
||||
#define _HTTP_DECODER_RESULT_QUEUE_H_
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include "nmx_pool/nmx_palloc.h"
|
||||
#include "http_decoder_half.h"
|
||||
|
||||
struct http_decoder_result {
|
||||
struct http_decoder_result
|
||||
{
|
||||
struct http_decoder_half_data *req_data;
|
||||
struct http_decoder_half_data *res_data;
|
||||
};
|
||||
|
||||
struct http_decoder_result_queue {
|
||||
size_t req_index;
|
||||
size_t res_index;
|
||||
size_t queue_size;
|
||||
struct http_decoder_result *array;
|
||||
struct http_decoder_result_queue
|
||||
{
|
||||
size_t req_index;
|
||||
size_t res_index;
|
||||
size_t queue_size;
|
||||
struct http_decoder_result *array;
|
||||
};
|
||||
|
||||
struct http_decoder_result_queue *
|
||||
@@ -57,5 +49,3 @@ http_decoder_result_queue_peek_req(struct http_decoder_result_queue *queue);
|
||||
|
||||
struct http_decoder_half_data *
|
||||
http_decoder_result_queue_peek_res(struct http_decoder_result_queue *queue);
|
||||
|
||||
#endif
|
||||
@@ -2,41 +2,44 @@
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include "http_decoder_inc.h"
|
||||
#include "http_decoder_private.h"
|
||||
|
||||
static const struct hd_stat_config_tuple g_httpd_stat_tuple[HTTPD_STAT_MAX] =
|
||||
{
|
||||
{HTTPD_STAT_BYTES_C2S, "bytes_c2s"},
|
||||
{HTTPD_STAT_BYTES_S2C, "bytes_s2c"},
|
||||
{HTTPD_STAT_TCP_SEG_C2S, "tcp_seg_c2s"},
|
||||
{HTTPD_STAT_TCP_SEG_S2C, "tcp_seg_s2c"},
|
||||
{HTTPD_STAT_HEADERS_C2S, "headers_c2s"},
|
||||
{HTTPD_STAT_HEADERS_S2C, "headers_s2c"},
|
||||
{HTTPD_STAT_ZIP_BYTES, "zip_bytes"},
|
||||
{HTTPD_STAT_UNZIP_BYTES, "unzip_bytes"},
|
||||
{HTTPD_STAT_URL_BYTES, "url_bytes"},
|
||||
{HTTPD_STAT_SESSION_NEW, "session_new"},
|
||||
{HTTPD_STAT_SESSION_FREE, "session_free"},
|
||||
{HTTPD_STAT_SESSION_EXCEPTION, "sess_exception"},
|
||||
{HTTPD_STAT_TUNNEL, "tunnel"},
|
||||
{HTTPD_STAT_TRANSACTION_NEW, "trans_new"},
|
||||
{HTTPD_STAT_TRANSACTION_FREE, "trans_free"},
|
||||
{HTTPD_STAT_ASYMMETRY_SESSION_C2S, "asymmetry_sess_c2s"},
|
||||
{HTTPD_STAT_ASYMMETRY_SESSION_S2C, "asymmetry_sess_s2c"},
|
||||
{HTTPD_STAT_ASYMMETRY_TRANSACTION_C2S, "asymmetry_trans_c2s"},
|
||||
{HTTPD_STAT_ASYMMETRY_TRANSACTION_S2C, "asymmetry_trans_s2c"},
|
||||
{HTTPD_STAT_PARSE_ERR, "parse_err"},
|
||||
};
|
||||
static const struct hd_stat_config_tuple g_httpd_stat_tuple[HTTP_STAT_MAX] =
|
||||
{
|
||||
{HTTP_C2S_BYTES, "http_c2s_bytes"},
|
||||
{HTTP_S2C_BYTES, "http_s2c_bytes"},
|
||||
{HTTP_C2S_TCP_SEG, "http_c2s_tcp_seg"},
|
||||
{HTTP_S2C_TCP_SEG, "http_s2c_tcp_seg"},
|
||||
{HTTP_C2S_HEADERS, "http_c2s_headers"},
|
||||
{HTTP_S2C_HEADERS, "http_s2c_headers"},
|
||||
{HTTP_C2S_ZIP_BYTES, "http_c2s_zip_bytes"},
|
||||
{HTTP_S2C_ZIP_BYTES, "http_s2c_zip_bytes"},
|
||||
{HTTP_C2S_UNZIP_BYTES, "http_c2s_unzip_bytes"},
|
||||
{HTTP_S2C_UNZIP_BYTES, "http_s2c_unzip_bytes"},
|
||||
{HTTP_URL_BYTES, "http_url_bytes"},
|
||||
{HTTP_SESSION_NEW, "http_session_new"},
|
||||
{HTTP_SESSION_FREE, "http_session_free"},
|
||||
{HTTP_TRANSACTION_NEW, "http_transaction_new"},
|
||||
{HTTP_TRANSACTION_FREE, "http_transaction_free"},
|
||||
{HTTP_C2S_ASYMMETRY_SESSION, "http_c2s_asymmetry_sess"},
|
||||
{HTTP_S2C_ASYMMETRY_SESSION, "http_s2c_asymmetry_sess"},
|
||||
{HTTP_C2S_ASYMMETRY_TRANSACTION, "http_c2s_asymmetry_trans"},
|
||||
{HTTP_S2C_ASYMMETRY_TRANSACTION, "http_s2c_asymmetry_trans"},
|
||||
{HTTP_STAT_PARSE_ERR, "http_parse_error"},
|
||||
};
|
||||
|
||||
void http_decoder_stat_free(struct http_decoder_stat *hd_stat)
|
||||
{
|
||||
if(hd_stat->timer_pid != 0){
|
||||
if (hd_stat->timer_pid != 0)
|
||||
{
|
||||
pthread_cancel(hd_stat->timer_pid);
|
||||
}
|
||||
if(hd_stat->stats != NULL){
|
||||
if (hd_stat->stats != NULL)
|
||||
{
|
||||
free(hd_stat->stats);
|
||||
}
|
||||
if(hd_stat->fse != NULL){
|
||||
if (hd_stat->fse != NULL)
|
||||
{
|
||||
fieldstat_easy_free(hd_stat->fse);
|
||||
}
|
||||
}
|
||||
@@ -46,7 +49,8 @@ static void *httpd_stat_timer_thread(void *arg)
|
||||
pthread_setname_np(pthread_self(), "http_decoder_timer_thread");
|
||||
struct http_decoder_stat *hd_stat = (struct http_decoder_stat *)arg;
|
||||
struct timespec res;
|
||||
while(1){
|
||||
while (1)
|
||||
{
|
||||
clock_gettime(CLOCK_MONOTONIC, &res);
|
||||
hd_stat->current_time_ms = (res.tv_sec * 1000) + (res.tv_nsec / 1000000);
|
||||
usleep(800);
|
||||
@@ -56,8 +60,9 @@ static void *httpd_stat_timer_thread(void *arg)
|
||||
|
||||
int http_decoder_stat_init(struct http_decoder_stat *hd_stat, int thread_max, int stat_interval_pkts, int stat_interval_time)
|
||||
{
|
||||
assert(sizeof(g_httpd_stat_tuple)/sizeof(struct hd_stat_config_tuple) == HTTPD_STAT_MAX);
|
||||
if(sizeof(g_httpd_stat_tuple)/sizeof(struct hd_stat_config_tuple) != HTTPD_STAT_MAX){
|
||||
assert(sizeof(g_httpd_stat_tuple) / sizeof(struct hd_stat_config_tuple) == HTTP_STAT_MAX);
|
||||
if (sizeof(g_httpd_stat_tuple) / sizeof(struct hd_stat_config_tuple) != HTTP_STAT_MAX)
|
||||
{
|
||||
fprintf(stderr, "enum http_decoder_stat_type number not match with g_httpd_stat_tuple!");
|
||||
return -1;
|
||||
}
|
||||
@@ -68,7 +73,7 @@ int http_decoder_stat_init(struct http_decoder_stat *hd_stat, int thread_max, in
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(int i = 0; i < HTTPD_STAT_MAX; i++)
|
||||
for (int i = 0; i < HTTP_STAT_MAX; i++)
|
||||
{
|
||||
hd_stat->field_stat_id[i] = fieldstat_easy_register_counter(hd_stat->fse, g_httpd_stat_tuple[i].name);
|
||||
if (hd_stat->field_stat_id[i] < 0)
|
||||
@@ -79,13 +84,13 @@ int http_decoder_stat_init(struct http_decoder_stat *hd_stat, int thread_max, in
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ret = fieldstat_easy_enable_auto_output(hd_stat->fse, FILEDSTAT_OUTPUT_FILE, stat_interval_time);
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "fieldstat_easy_enable_auto_output failed.");
|
||||
fieldstat_easy_free(hd_stat->fse);
|
||||
hd_stat->fse = NULL;
|
||||
hd_stat->fse = NULL;
|
||||
return -1;
|
||||
}
|
||||
hd_stat->stats = (struct hd_statistics *)calloc(thread_max, sizeof(struct hd_statistics));
|
||||
@@ -100,9 +105,10 @@ void http_decoder_stat_update(struct http_decoder_stat *hd_stat, int thread_id,
|
||||
{
|
||||
assert(hd_stat);
|
||||
assert(thread_id >= 0);
|
||||
assert(type < HTTPD_STAT_MAX);
|
||||
assert(type < HTTP_STAT_MAX);
|
||||
|
||||
if(unlikely(hd_stat->stats == NULL)){
|
||||
if (unlikely(hd_stat->stats == NULL))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -111,11 +117,11 @@ void http_decoder_stat_update(struct http_decoder_stat *hd_stat, int thread_id,
|
||||
cur_hds->counter[type] += value;
|
||||
cur_hds->batch[type]++;
|
||||
|
||||
if(cur_hds->batch[type] >= hd_stat->stat_interval_pkts
|
||||
|| cur_hds->time_ms[type] + 1000 < hd_stat->current_time_ms){
|
||||
fieldstat_easy_counter_incrby(hd_stat->fse, thread_id, hd_stat->field_stat_id[type], NULL, 0, cur_hds->counter[type]);
|
||||
cur_hds->counter[type] = 0;
|
||||
cur_hds->batch[type] = 0;
|
||||
cur_hds->time_ms[type] = hd_stat->current_time_ms;
|
||||
if (cur_hds->batch[type] >= hd_stat->stat_interval_pkts || cur_hds->time_ms[type] + 1000 < hd_stat->current_time_ms)
|
||||
{
|
||||
fieldstat_easy_counter_incrby(hd_stat->fse, thread_id, hd_stat->field_stat_id[type], NULL, 0, cur_hds->counter[type]);
|
||||
cur_hds->counter[type] = 0;
|
||||
cur_hds->batch[type] = 0;
|
||||
cur_hds->time_ms[type] = hd_stat->current_time_ms;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,29 @@
|
||||
#ifndef _HTTP_DECODER_STAT_H_
|
||||
#define _HTTP_DECODER_STAT_H_ 1
|
||||
#pragma once
|
||||
|
||||
#include <fieldstat/fieldstat_easy.h>
|
||||
enum http_decoder_stat_type
|
||||
{
|
||||
HTTPD_STAT_BYTES_C2S = 0,
|
||||
HTTPD_STAT_BYTES_S2C,
|
||||
HTTPD_STAT_TCP_SEG_C2S,
|
||||
HTTPD_STAT_TCP_SEG_S2C,
|
||||
HTTPD_STAT_HEADERS_C2S,
|
||||
HTTPD_STAT_HEADERS_S2C,
|
||||
HTTPD_STAT_ZIP_BYTES, //only if Content-Encoding is gzip, deflate, br
|
||||
HTTPD_STAT_UNZIP_BYTES, //only if Content-Encoding is gzip, deflate, br
|
||||
HTTPD_STAT_URL_BYTES,
|
||||
HTTPD_STAT_SESSION_NEW,
|
||||
HTTPD_STAT_SESSION_FREE,
|
||||
HTTPD_STAT_SESSION_EXCEPTION, // rst, kickout, lost packet, etc.
|
||||
HTTPD_STAT_TUNNEL,
|
||||
HTTPD_STAT_TRANSACTION_NEW,
|
||||
HTTPD_STAT_TRANSACTION_FREE,
|
||||
HTTPD_STAT_ASYMMETRY_SESSION_C2S,
|
||||
HTTPD_STAT_ASYMMETRY_SESSION_S2C,
|
||||
HTTPD_STAT_ASYMMETRY_TRANSACTION_C2S,
|
||||
HTTPD_STAT_ASYMMETRY_TRANSACTION_S2C,
|
||||
HTTPD_STAT_PARSE_ERR,
|
||||
HTTPD_STAT_MAX,
|
||||
HTTP_C2S_BYTES = 0,
|
||||
HTTP_S2C_BYTES,
|
||||
HTTP_C2S_TCP_SEG,
|
||||
HTTP_S2C_TCP_SEG,
|
||||
HTTP_C2S_HEADERS,
|
||||
HTTP_S2C_HEADERS,
|
||||
HTTP_C2S_ZIP_BYTES, // only if Content-Encoding is gzip, deflate, br
|
||||
HTTP_S2C_ZIP_BYTES, // only if Content-Encoding is gzip, deflate, br
|
||||
HTTP_C2S_UNZIP_BYTES, // only if Content-Encoding is gzip, deflate, br
|
||||
HTTP_S2C_UNZIP_BYTES, // only if Content-Encoding is gzip, deflate, br
|
||||
HTTP_URL_BYTES,
|
||||
HTTP_SESSION_NEW,
|
||||
HTTP_SESSION_FREE,
|
||||
HTTP_TRANSACTION_NEW,
|
||||
HTTP_TRANSACTION_FREE,
|
||||
HTTP_C2S_ASYMMETRY_SESSION,
|
||||
HTTP_S2C_ASYMMETRY_SESSION,
|
||||
HTTP_C2S_ASYMMETRY_TRANSACTION,
|
||||
HTTP_S2C_ASYMMETRY_TRANSACTION,
|
||||
HTTP_STAT_PARSE_ERR,
|
||||
HTTP_STAT_MAX,
|
||||
};
|
||||
|
||||
struct hd_stat_config_tuple
|
||||
@@ -35,10 +34,10 @@ struct hd_stat_config_tuple
|
||||
|
||||
struct hd_statistics
|
||||
{
|
||||
long long time_ms[HTTPD_STAT_MAX];
|
||||
long long counter[HTTPD_STAT_MAX];
|
||||
int batch[HTTPD_STAT_MAX]; //call fieldstat_easy_counter_incrby() per batch
|
||||
}__attribute__ ((aligned (64)));
|
||||
long long time_ms[HTTP_STAT_MAX];
|
||||
long long counter[HTTP_STAT_MAX];
|
||||
int batch[HTTP_STAT_MAX]; // call fieldstat_easy_counter_incrby() per batch
|
||||
} __attribute__((aligned(64)));
|
||||
|
||||
struct http_decoder_stat
|
||||
{
|
||||
@@ -46,12 +45,11 @@ struct http_decoder_stat
|
||||
long long current_time_ms;
|
||||
struct fieldstat_easy *fse;
|
||||
int stat_interval_pkts; // call fieldstat_incrby every stat_interval_pkts
|
||||
int stat_interval_time; //second
|
||||
int field_stat_id[HTTPD_STAT_MAX];
|
||||
struct hd_statistics *stats; //size is thread number
|
||||
int stat_interval_time; // second
|
||||
int field_stat_id[HTTP_STAT_MAX];
|
||||
struct hd_statistics *stats; // size is thread number
|
||||
};
|
||||
|
||||
int http_decoder_stat_init(struct http_decoder_stat *hd_stat, int thread_max, int stat_interval_pkts, int stat_interval_time);
|
||||
void http_decoder_stat_free(struct http_decoder_stat *hd_stat);
|
||||
void http_decoder_stat_update(struct http_decoder_stat *hd_stat, int thread_id, enum http_decoder_stat_type type, long long value);
|
||||
#endif
|
||||
@@ -2,11 +2,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "http_decoder_inc.h"
|
||||
#include "http_decoder_private.h"
|
||||
|
||||
static const char *string_state_to_desc(enum string_state state)
|
||||
{
|
||||
switch (state) {
|
||||
switch (state)
|
||||
{
|
||||
case STRING_STATE_INIT:
|
||||
return "init";
|
||||
break;
|
||||
@@ -25,22 +26,23 @@ static const char *string_state_to_desc(enum string_state state)
|
||||
}
|
||||
}
|
||||
|
||||
void http_decoder_string_refer(struct http_decoder_string *rstr,
|
||||
const char *at, size_t length)
|
||||
void http_decoder_string_refer(struct http_decoder_string *rstr, const char *at, size_t length)
|
||||
{
|
||||
if (NULL == rstr) {
|
||||
if (NULL == rstr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (rstr->state) {
|
||||
case STRING_STATE_INIT:
|
||||
case STRING_STATE_CACHE:
|
||||
rstr->refer.iov_base = (char *)at;
|
||||
rstr->refer.iov_len = length;
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
break;
|
||||
switch (rstr->state)
|
||||
{
|
||||
case STRING_STATE_INIT:
|
||||
case STRING_STATE_CACHE:
|
||||
rstr->refer.iov_base = (char *)at;
|
||||
rstr->refer.iov_len = length;
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
break;
|
||||
}
|
||||
|
||||
rstr->state = STRING_STATE_REFER;
|
||||
@@ -48,22 +50,28 @@ void http_decoder_string_refer(struct http_decoder_string *rstr,
|
||||
|
||||
static void string_refer2cache(struct http_decoder_string *rstr)
|
||||
{
|
||||
if (0 == rstr->refer.iov_len) {
|
||||
if (0 == rstr->refer.iov_len)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (rstr->cache.iov_len >= rstr->max_cache_size) {
|
||||
if (rstr->cache.iov_len >= rstr->max_cache_size)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
size_t length = rstr->cache.iov_len + rstr->refer.iov_len;
|
||||
if (length > rstr->max_cache_size) {
|
||||
if (length > rstr->max_cache_size)
|
||||
{
|
||||
length = rstr->max_cache_size;
|
||||
}
|
||||
|
||||
if (NULL == rstr->cache.iov_base) {
|
||||
if (NULL == rstr->cache.iov_base)
|
||||
{
|
||||
rstr->cache.iov_base = CALLOC(char, length + 1);
|
||||
memcpy(rstr->cache.iov_base, rstr->refer.iov_base, length);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
rstr->cache.iov_base = REALLOC(char, rstr->cache.iov_base, length + 1);
|
||||
memcpy((char *)rstr->cache.iov_base + rstr->cache.iov_len, rstr->refer.iov_base,
|
||||
(length - rstr->cache.iov_len));
|
||||
@@ -77,24 +85,32 @@ static void string_refer2cache(struct http_decoder_string *rstr)
|
||||
static void string_commit2cache(struct http_decoder_string *rstr)
|
||||
{
|
||||
if (rstr->cache.iov_len == rstr->commit.iov_len &&
|
||||
rstr->cache.iov_base == rstr->commit.iov_base) {
|
||||
rstr->cache.iov_base == rstr->commit.iov_base)
|
||||
{
|
||||
rstr->commit.iov_base = NULL;
|
||||
rstr->commit.iov_len = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
//Only http header key need to backward to cache
|
||||
// Only http header key need to backward to cache
|
||||
size_t length = 0;
|
||||
if (rstr->commit.iov_len > rstr->max_cache_size) {
|
||||
if (rstr->commit.iov_len > rstr->max_cache_size)
|
||||
{
|
||||
length = rstr->max_cache_size;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
length = rstr->commit.iov_len;
|
||||
}
|
||||
|
||||
if (length > 0) {
|
||||
if (NULL == rstr->cache.iov_base) {
|
||||
if (length > 0)
|
||||
{
|
||||
if (NULL == rstr->cache.iov_base)
|
||||
{
|
||||
rstr->cache.iov_base = CALLOC(char, length + 1);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
abort();
|
||||
}
|
||||
memcpy(rstr->cache.iov_base, rstr->commit.iov_base, length);
|
||||
@@ -107,18 +123,20 @@ static void string_commit2cache(struct http_decoder_string *rstr)
|
||||
|
||||
void http_decoder_string_cache(struct http_decoder_string *rstr)
|
||||
{
|
||||
if (NULL == rstr) {
|
||||
if (NULL == rstr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (rstr->state) {
|
||||
switch (rstr->state)
|
||||
{
|
||||
case STRING_STATE_REFER:
|
||||
string_refer2cache(rstr);
|
||||
break;
|
||||
case STRING_STATE_CACHE:
|
||||
break;
|
||||
case STRING_STATE_COMMIT:
|
||||
//commit backward to cache
|
||||
// commit backward to cache
|
||||
string_commit2cache(rstr);
|
||||
break;
|
||||
default:
|
||||
@@ -130,34 +148,39 @@ void http_decoder_string_cache(struct http_decoder_string *rstr)
|
||||
|
||||
void http_decoder_string_commit(struct http_decoder_string *rstr)
|
||||
{
|
||||
if (NULL == rstr) {
|
||||
if (NULL == rstr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (rstr->state) {
|
||||
case STRING_STATE_REFER:
|
||||
if (rstr->cache.iov_len) {
|
||||
http_decoder_string_cache(rstr);
|
||||
switch (rstr->state)
|
||||
{
|
||||
case STRING_STATE_REFER:
|
||||
if (rstr->cache.iov_len)
|
||||
{
|
||||
http_decoder_string_cache(rstr);
|
||||
|
||||
rstr->commit.iov_base = rstr->cache.iov_base;
|
||||
rstr->commit.iov_len = rstr->cache.iov_len;
|
||||
// not overwrite rstr->cache.iov_base
|
||||
} else {
|
||||
rstr->commit.iov_base = rstr->refer.iov_base;
|
||||
rstr->commit.iov_len = rstr->refer.iov_len;
|
||||
|
||||
rstr->refer.iov_base = NULL;
|
||||
rstr->refer.iov_len = 0;
|
||||
}
|
||||
break;
|
||||
case STRING_STATE_CACHE:
|
||||
rstr->commit.iov_base = rstr->cache.iov_base;
|
||||
rstr->commit.iov_len = rstr->cache.iov_len;
|
||||
// not overwrite rstr->cache.iov_base
|
||||
break;
|
||||
default:
|
||||
//abort();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
rstr->commit.iov_base = rstr->refer.iov_base;
|
||||
rstr->commit.iov_len = rstr->refer.iov_len;
|
||||
|
||||
rstr->refer.iov_base = NULL;
|
||||
rstr->refer.iov_len = 0;
|
||||
}
|
||||
break;
|
||||
case STRING_STATE_CACHE:
|
||||
rstr->commit.iov_base = rstr->cache.iov_base;
|
||||
rstr->commit.iov_len = rstr->cache.iov_len;
|
||||
// not overwrite rstr->cache.iov_base
|
||||
break;
|
||||
default:
|
||||
// abort();
|
||||
break;
|
||||
}
|
||||
|
||||
rstr->state = STRING_STATE_COMMIT;
|
||||
@@ -167,7 +190,8 @@ void http_decoder_string_reset(struct http_decoder_string *rstr)
|
||||
{
|
||||
assert(rstr);
|
||||
|
||||
switch (rstr->state) {
|
||||
switch (rstr->state)
|
||||
{
|
||||
case STRING_STATE_INIT:
|
||||
case STRING_STATE_REFER:
|
||||
case STRING_STATE_CACHE:
|
||||
@@ -183,26 +207,27 @@ void http_decoder_string_reset(struct http_decoder_string *rstr)
|
||||
rstr->state = STRING_STATE_INIT;
|
||||
}
|
||||
|
||||
|
||||
void http_decoder_string_init(struct http_decoder_string *rstr,
|
||||
size_t max_cache_size)
|
||||
void http_decoder_string_init(struct http_decoder_string *rstr, size_t max_cache_size)
|
||||
{
|
||||
rstr->max_cache_size = max_cache_size;
|
||||
}
|
||||
|
||||
void http_decoder_string_reinit(struct http_decoder_string *rstr)
|
||||
{
|
||||
if (rstr->state == STRING_STATE_CACHE) {
|
||||
if (rstr->state == STRING_STATE_CACHE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (rstr->state == STRING_STATE_COMMIT &&
|
||||
rstr->cache.iov_base == rstr->commit.iov_base &&
|
||||
rstr->cache.iov_len == rstr->commit.iov_len) {
|
||||
rstr->cache.iov_len == rstr->commit.iov_len)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (rstr->cache.iov_base != NULL) {
|
||||
if (rstr->cache.iov_base != NULL)
|
||||
{
|
||||
FREE(rstr->cache.iov_base);
|
||||
rstr->cache.iov_len = 0;
|
||||
}
|
||||
@@ -213,7 +238,7 @@ void http_decoder_string_reinit(struct http_decoder_string *rstr)
|
||||
rstr->commit.iov_base = NULL;
|
||||
rstr->commit.iov_len = 0;
|
||||
rstr->state = STRING_STATE_INIT;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
enum string_state http_decoder_string_state(const struct http_decoder_string *rstr)
|
||||
@@ -223,14 +248,18 @@ enum string_state http_decoder_string_state(const struct http_decoder_string *rs
|
||||
|
||||
int http_decoder_string_get(const struct http_decoder_string *rstr, hstring *out)
|
||||
{
|
||||
if (NULL == rstr || NULL == out) {
|
||||
if (NULL == rstr || NULL == out)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (http_decoder_string_state(rstr) == STRING_STATE_COMMIT) {
|
||||
if (http_decoder_string_state(rstr) == STRING_STATE_COMMIT)
|
||||
{
|
||||
out->iov_base = rstr->commit.iov_base;
|
||||
out->iov_len = rstr->commit.iov_len;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
out->iov_base = NULL;
|
||||
out->iov_len = 0;
|
||||
}
|
||||
@@ -240,7 +269,8 @@ int http_decoder_string_get(const struct http_decoder_string *rstr, hstring *out
|
||||
|
||||
void http_decoder_string_dump(struct http_decoder_string *rstr, const char *desc)
|
||||
{
|
||||
if (NULL == rstr) {
|
||||
if (NULL == rstr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#ifndef _HTTP_DECODER_STRING_H_
|
||||
#define _HTTP_DECODER_STRING_H_
|
||||
#pragma once
|
||||
|
||||
#include "stellar/http.h"
|
||||
|
||||
@@ -71,4 +70,4 @@ enum string_state http_decoder_string_state(const struct http_decoder_string *rs
|
||||
int http_decoder_string_get(const struct http_decoder_string *rstr, hstring *out);
|
||||
|
||||
void http_decoder_string_dump(struct http_decoder_string *rstr, const char *desc);
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "http_decoder_inc.h"
|
||||
#include "http_decoder_private.h"
|
||||
|
||||
#define INIT_HEADER_CNT 16
|
||||
#define MAX_URI_CACHE_SIZE 2048
|
||||
@@ -11,12 +11,14 @@
|
||||
#define MAX_HEADER_KEY_CACHE_SIZE 4096
|
||||
#define MAX_HEADER_VALUE_CACHE_SIZE 4096
|
||||
|
||||
struct http_decoder_header {
|
||||
struct http_decoder_header
|
||||
{
|
||||
struct http_decoder_string key;
|
||||
struct http_decoder_string val;
|
||||
};
|
||||
|
||||
struct http_decoder_table {
|
||||
struct http_decoder_table
|
||||
{
|
||||
struct http_decoder_string uri;
|
||||
struct http_decoder_string status;
|
||||
struct http_decoder_string method;
|
||||
@@ -26,15 +28,16 @@ struct http_decoder_table {
|
||||
nmx_pool_t *ref_mempool;
|
||||
int header_complete; // flag for all headers parsed completely
|
||||
size_t header_cnt;
|
||||
size_t header_index; //current parsing header
|
||||
size_t header_iter; //plugins iterate cursor
|
||||
size_t commit_header_index; //pushed to plugins, whether has called http_message_header_next()
|
||||
size_t header_index; // current parsing header
|
||||
size_t header_iter; // plugins iterate cursor
|
||||
size_t commit_header_index; // pushed to plugins, whether has called http_message_header_next()
|
||||
struct http_decoder_header *headers;
|
||||
};
|
||||
|
||||
static void http_decoder_table_init(struct http_decoder_table *table)
|
||||
{
|
||||
if (NULL == table) {
|
||||
if (NULL == table)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,12 +49,13 @@ static void http_decoder_table_init(struct http_decoder_table *table)
|
||||
http_decoder_string_init(&table->method, MAX_METHOD_CACHE_SIZE);
|
||||
http_decoder_string_init(&table->version, MAX_METHOD_CACHE_SIZE);
|
||||
|
||||
for (size_t i = 0; i < table->header_cnt; i++) {
|
||||
for (size_t i = 0; i < table->header_cnt; i++)
|
||||
{
|
||||
header = &table->headers[i];
|
||||
http_decoder_string_init(&header->key, MAX_HEADER_KEY_CACHE_SIZE);
|
||||
http_decoder_string_init(&header->val, MAX_HEADER_VALUE_CACHE_SIZE);
|
||||
}
|
||||
|
||||
|
||||
http_decoder_string_init(&table->body, 0);
|
||||
}
|
||||
|
||||
@@ -73,32 +77,42 @@ struct http_decoder_table *http_decoder_table_new(nmx_pool_t *mempool)
|
||||
|
||||
void http_decoder_table_free(struct http_decoder_table *table)
|
||||
{
|
||||
if (NULL == table) {
|
||||
if (NULL == table)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (table->uri.cache.iov_base != NULL) {
|
||||
if (table->uri.cache.iov_base != NULL)
|
||||
{
|
||||
FREE(table->uri.cache.iov_base);
|
||||
}
|
||||
if (table->status.cache.iov_base != NULL) {
|
||||
if (table->status.cache.iov_base != NULL)
|
||||
{
|
||||
FREE(table->status.cache.iov_base);
|
||||
}
|
||||
if (table->method.cache.iov_base != NULL) {
|
||||
if (table->method.cache.iov_base != NULL)
|
||||
{
|
||||
FREE(table->method.cache.iov_base);
|
||||
}
|
||||
if (table->version.cache.iov_base != NULL) {
|
||||
if (table->version.cache.iov_base != NULL)
|
||||
{
|
||||
FREE(table->version.cache.iov_base);
|
||||
}
|
||||
if (table->body.cache.iov_base != NULL) {
|
||||
if (table->body.cache.iov_base != NULL)
|
||||
{
|
||||
FREE(table->body.cache.iov_base);
|
||||
}
|
||||
|
||||
if (table->headers != NULL) {
|
||||
for (size_t i = 0; i < table->header_cnt; i++) {
|
||||
if (table->headers[i].key.cache.iov_base != NULL) {
|
||||
if (table->headers != NULL)
|
||||
{
|
||||
for (size_t i = 0; i < table->header_cnt; i++)
|
||||
{
|
||||
if (table->headers[i].key.cache.iov_base != NULL)
|
||||
{
|
||||
FREE(table->headers[i].key.cache.iov_base);
|
||||
}
|
||||
|
||||
if (table->headers[i].val.cache.iov_base != NULL) {
|
||||
if (table->headers[i].val.cache.iov_base != NULL)
|
||||
{
|
||||
FREE(table->headers[i].val.cache.iov_base);
|
||||
}
|
||||
}
|
||||
@@ -109,17 +123,18 @@ void http_decoder_table_free(struct http_decoder_table *table)
|
||||
MEMPOOL_FREE(table->ref_mempool, table);
|
||||
}
|
||||
|
||||
enum string_state
|
||||
http_decoder_table_state(struct http_decoder_table *table, enum http_item type)
|
||||
enum string_state http_decoder_table_state(struct http_decoder_table *table, enum http_item type)
|
||||
{
|
||||
if (NULL == table) {
|
||||
if (NULL == table)
|
||||
{
|
||||
return STRING_STATE_INIT;
|
||||
}
|
||||
struct http_decoder_header *header = NULL;
|
||||
enum string_state state = STRING_STATE_INIT;
|
||||
assert(table);
|
||||
|
||||
switch (type) {
|
||||
switch (type)
|
||||
{
|
||||
case HTTP_ITEM_URI:
|
||||
state = http_decoder_string_state(&table->uri);
|
||||
break;
|
||||
@@ -153,17 +168,18 @@ http_decoder_table_state(struct http_decoder_table *table, enum http_item type)
|
||||
return state;
|
||||
}
|
||||
|
||||
void http_decoder_table_refer(struct http_decoder_table *table, enum http_item type,
|
||||
const char *at, size_t len)
|
||||
void http_decoder_table_refer(struct http_decoder_table *table, enum http_item type, const char *at, size_t len)
|
||||
{
|
||||
if (NULL == table) {
|
||||
if (NULL == table)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
struct http_decoder_header *header = NULL;
|
||||
assert(table);
|
||||
|
||||
switch (type) {
|
||||
switch (type)
|
||||
{
|
||||
case HTTP_ITEM_URI:
|
||||
http_decoder_string_refer(&table->uri, at, len);
|
||||
break;
|
||||
@@ -197,14 +213,16 @@ void http_decoder_table_refer(struct http_decoder_table *table, enum http_item t
|
||||
|
||||
void http_decoder_table_cache(struct http_decoder_table *table, enum http_item type)
|
||||
{
|
||||
if (NULL == table) {
|
||||
if (NULL == table)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
struct http_decoder_header *header = NULL;
|
||||
assert(table);
|
||||
|
||||
switch (type) {
|
||||
switch (type)
|
||||
{
|
||||
case HTTP_ITEM_URI:
|
||||
http_decoder_string_cache(&table->uri);
|
||||
break;
|
||||
@@ -238,7 +256,8 @@ void http_decoder_table_cache(struct http_decoder_table *table, enum http_item t
|
||||
|
||||
void http_decoder_table_commit(struct http_decoder_table *table, enum http_item type)
|
||||
{
|
||||
if (NULL == table) {
|
||||
if (NULL == table)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -246,7 +265,8 @@ void http_decoder_table_commit(struct http_decoder_table *table, enum http_item
|
||||
struct http_decoder_header *header = NULL;
|
||||
assert(table);
|
||||
|
||||
switch (type) {
|
||||
switch (type)
|
||||
{
|
||||
case HTTP_ITEM_URI:
|
||||
http_decoder_string_commit(&table->uri);
|
||||
break;
|
||||
@@ -268,20 +288,23 @@ void http_decoder_table_commit(struct http_decoder_table *table, enum http_item
|
||||
header = &table->headers[table->header_index];
|
||||
http_decoder_string_commit(&header->val);
|
||||
// inc index
|
||||
if ((table->header_index + 1) >= table->header_cnt) {
|
||||
if ((table->header_index + 1) >= table->header_cnt)
|
||||
{
|
||||
struct http_decoder_header *old_headers = table->headers;
|
||||
table->headers =
|
||||
MEMPOOL_CALLOC(table->ref_mempool, struct http_decoder_header,
|
||||
table->header_cnt * 2);
|
||||
table->header_cnt *= 2;
|
||||
|
||||
for (i = 0; i <= table->header_index; i++) {
|
||||
for (i = 0; i <= table->header_index; i++)
|
||||
{
|
||||
table->headers[i] = old_headers[i];
|
||||
}
|
||||
|
||||
MEMPOOL_FREE(table->ref_mempool, old_headers);
|
||||
|
||||
for (i = table->header_index + 1; i < table->header_cnt; i++) {
|
||||
for (i = table->header_index + 1; i < table->header_cnt; i++)
|
||||
{
|
||||
header = &table->headers[i];
|
||||
memset(header, 0, sizeof(struct http_decoder_header));
|
||||
http_decoder_string_init(&header->key, MAX_HEADER_KEY_CACHE_SIZE);
|
||||
@@ -301,14 +324,16 @@ void http_decoder_table_commit(struct http_decoder_table *table, enum http_item
|
||||
|
||||
void http_decoder_table_reset(struct http_decoder_table *table, enum http_item type)
|
||||
{
|
||||
if (NULL == table) {
|
||||
if (NULL == table)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
struct http_decoder_header *header = NULL;
|
||||
assert(table);
|
||||
|
||||
switch (type) {
|
||||
switch (type)
|
||||
{
|
||||
case HTTP_ITEM_URI:
|
||||
http_decoder_string_reset(&table->uri);
|
||||
break;
|
||||
@@ -342,14 +367,15 @@ void http_decoder_table_reinit(struct http_decoder_table *table)
|
||||
{
|
||||
assert(table);
|
||||
struct http_decoder_header *header = NULL;
|
||||
|
||||
|
||||
http_decoder_string_reinit(&table->uri);
|
||||
http_decoder_string_reinit(&table->status);
|
||||
http_decoder_string_reinit(&table->method);
|
||||
http_decoder_string_reinit(&table->version);
|
||||
// for (size_t i = 0; i < table->header_iter; i++) {
|
||||
for (size_t i = 0; i < table->commit_header_index; i++) {
|
||||
//todo, reset header_index, avoid realloc headers as much as possible
|
||||
for (size_t i = 0; i < table->commit_header_index; i++)
|
||||
{
|
||||
// todo, reset header_index, avoid realloc headers as much as possible
|
||||
header = &table->headers[i];
|
||||
http_decoder_string_reinit(&header->key);
|
||||
http_decoder_string_reinit(&header->val);
|
||||
@@ -360,7 +386,8 @@ void http_decoder_table_reinit(struct http_decoder_table *table)
|
||||
|
||||
void http_decoder_table_dump(struct http_decoder_table *table)
|
||||
{
|
||||
if (NULL == table) {
|
||||
if (NULL == table)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -370,9 +397,11 @@ void http_decoder_table_dump(struct http_decoder_table *table)
|
||||
http_decoder_string_dump(&table->version, "version");
|
||||
http_decoder_string_dump(&table->body, "body");
|
||||
|
||||
for (size_t i = 0; i < table->header_cnt; i++) {
|
||||
for (size_t i = 0; i < table->header_cnt; i++)
|
||||
{
|
||||
struct http_decoder_header *header = &table->headers[i];
|
||||
if (NULL == header) {
|
||||
if (NULL == header)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -383,7 +412,8 @@ void http_decoder_table_dump(struct http_decoder_table *table)
|
||||
|
||||
int http_decoder_table_get_uri(const struct http_decoder_table *table, hstring *out)
|
||||
{
|
||||
if (NULL == table || NULL == out) {
|
||||
if (NULL == table || NULL == out)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return http_decoder_string_get(&table->uri, out);
|
||||
@@ -391,7 +421,8 @@ int http_decoder_table_get_uri(const struct http_decoder_table *table, hstring *
|
||||
|
||||
int http_decoder_table_get_method(const struct http_decoder_table *table, hstring *out)
|
||||
{
|
||||
if (NULL == table || NULL == out) {
|
||||
if (NULL == table || NULL == out)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return http_decoder_string_get(&table->method, out);
|
||||
@@ -399,7 +430,8 @@ int http_decoder_table_get_method(const struct http_decoder_table *table, hstrin
|
||||
|
||||
int http_decoder_table_get_status(const struct http_decoder_table *table, hstring *out)
|
||||
{
|
||||
if (NULL == table || NULL == out) {
|
||||
if (NULL == table || NULL == out)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return http_decoder_string_get(&table->status, out);
|
||||
@@ -407,7 +439,8 @@ int http_decoder_table_get_status(const struct http_decoder_table *table, hstrin
|
||||
|
||||
int http_decoder_table_get_version(const struct http_decoder_table *table, hstring *out)
|
||||
{
|
||||
if (NULL == table || NULL == out) {
|
||||
if (NULL == table || NULL == out)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return http_decoder_string_get(&table->version, out);
|
||||
@@ -415,7 +448,8 @@ int http_decoder_table_get_version(const struct http_decoder_table *table, hstri
|
||||
|
||||
int http_decoder_table_get_body(const struct http_decoder_table *table, hstring *out)
|
||||
{
|
||||
if (NULL == table || NULL == out) {
|
||||
if (NULL == table || NULL == out)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return http_decoder_string_get(&table->body, out);
|
||||
@@ -424,19 +458,23 @@ int http_decoder_table_get_body(const struct http_decoder_table *table, hstring
|
||||
int http_decoder_table_get_header(const struct http_decoder_table *table, const hstring *key,
|
||||
struct http_header *hdr_result)
|
||||
{
|
||||
for (size_t i = 0; i < table->header_cnt; i++) {
|
||||
for (size_t i = 0; i < table->header_cnt; i++)
|
||||
{
|
||||
const struct http_decoder_header *tmp_header = &table->headers[i];
|
||||
if (tmp_header->key.commit.iov_len != key->iov_len) {
|
||||
if (tmp_header->key.commit.iov_len != key->iov_len)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (http_decoder_string_state(&tmp_header->key) == STRING_STATE_COMMIT &&
|
||||
http_decoder_string_state(&tmp_header->val) == STRING_STATE_COMMIT) {
|
||||
http_decoder_string_state(&tmp_header->val) == STRING_STATE_COMMIT)
|
||||
{
|
||||
hstring tmp_key;
|
||||
http_decoder_string_get(&tmp_header->key, &tmp_key);
|
||||
|
||||
if (tmp_key.iov_len == key->iov_len &&
|
||||
(0 == strncasecmp((char *)tmp_key.iov_base, (char *)key->iov_base, key->iov_len))) {
|
||||
(0 == strncasecmp((char *)tmp_key.iov_base, (char *)key->iov_base, key->iov_len)))
|
||||
{
|
||||
http_decoder_string_get(&tmp_header->key, &hdr_result->key);
|
||||
http_decoder_string_get(&tmp_header->val, &hdr_result->val);
|
||||
return 0;
|
||||
@@ -446,20 +484,23 @@ int http_decoder_table_get_header(const struct http_decoder_table *table, const
|
||||
return -1;
|
||||
}
|
||||
|
||||
int http_decoder_table_iter_header(struct http_decoder_table *table,
|
||||
struct http_header *hdr)
|
||||
int http_decoder_table_iter_header(struct http_decoder_table *table, struct http_header *hdr)
|
||||
{
|
||||
if (NULL == table || NULL == hdr) {
|
||||
if (NULL == table || NULL == hdr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (table->header_iter >= table->header_cnt) {
|
||||
if (table->header_iter >= table->header_cnt)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct http_decoder_header *tmp_header = &table->headers[table->header_iter];
|
||||
if (tmp_header != NULL) {
|
||||
if (tmp_header != NULL)
|
||||
{
|
||||
if (http_decoder_string_state(&tmp_header->key) == STRING_STATE_COMMIT &&
|
||||
http_decoder_string_state(&tmp_header->val) == STRING_STATE_COMMIT) {
|
||||
http_decoder_string_state(&tmp_header->val) == STRING_STATE_COMMIT)
|
||||
{
|
||||
|
||||
http_decoder_string_get(&tmp_header->key, &hdr->key);
|
||||
http_decoder_string_get(&tmp_header->val, &hdr->val);
|
||||
@@ -485,14 +526,15 @@ int http_decoder_table_reset_header_iter(struct http_decoder_table *table)
|
||||
int http_decoder_table_has_parsed_header(struct http_decoder_table *table)
|
||||
{
|
||||
// if (NULL == table || (table->header_iter == table->header_index)) {
|
||||
if (NULL == table || (table->commit_header_index == table->header_index)) {
|
||||
if (NULL == table || (table->commit_header_index == table->header_index))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct http_decoder_header *tmp_header = &table->headers[table->header_iter];
|
||||
|
||||
if (http_decoder_string_state(&tmp_header->key) == STRING_STATE_COMMIT
|
||||
&& http_decoder_string_state(&tmp_header->val) == STRING_STATE_COMMIT) {
|
||||
if (http_decoder_string_state(&tmp_header->key) == STRING_STATE_COMMIT && http_decoder_string_state(&tmp_header->val) == STRING_STATE_COMMIT)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -501,7 +543,8 @@ int http_decoder_table_has_parsed_header(struct http_decoder_table *table)
|
||||
|
||||
int http_decoder_table_header_complete(struct http_decoder_table *table)
|
||||
{
|
||||
if (NULL == table) {
|
||||
if (NULL == table)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return table->header_complete;
|
||||
@@ -509,7 +552,8 @@ int http_decoder_table_header_complete(struct http_decoder_table *table)
|
||||
|
||||
void http_decoder_table_set_header_complete(struct http_decoder_table *table)
|
||||
{
|
||||
if (NULL == table) {
|
||||
if (NULL == table)
|
||||
{
|
||||
return;
|
||||
}
|
||||
table->header_complete = 1;
|
||||
@@ -517,7 +561,8 @@ void http_decoder_table_set_header_complete(struct http_decoder_table *table)
|
||||
|
||||
void http_decoder_table_reset_header_complete(struct http_decoder_table *table)
|
||||
{
|
||||
if (NULL == table) {
|
||||
if (NULL == table)
|
||||
{
|
||||
return;
|
||||
}
|
||||
table->header_complete = 0;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#ifndef _HTTP_DECODER_TABLE_H_
|
||||
#define _HTTP_DECODER_TABLE_H_
|
||||
#pragma once
|
||||
#include <stddef.h>
|
||||
#include "stellar/http.h"
|
||||
#include "http_decoder_inc.h"
|
||||
#include "http_decoder_private.h"
|
||||
#include "http_decoder_string.h"
|
||||
|
||||
enum http_item {
|
||||
enum http_item
|
||||
{
|
||||
HTTP_ITEM_URI = 0x01,
|
||||
HTTP_ITEM_STATUS = 0x02,
|
||||
HTTP_ITEM_METHOD = 0x03,
|
||||
@@ -55,9 +55,9 @@ int http_decoder_table_iter_header(struct http_decoder_table *table,
|
||||
int http_decoder_table_reset_header_iter(struct http_decoder_table *table);
|
||||
/**
|
||||
* @brief Is there a parsed header
|
||||
*
|
||||
*
|
||||
* @retval yes(1) no(0)
|
||||
*/
|
||||
*/
|
||||
int http_decoder_table_has_parsed_header(struct http_decoder_table *table);
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ int http_decoder_table_header_complete(struct http_decoder_table *table);
|
||||
|
||||
/**
|
||||
* @brief set flag for headers parsed completely
|
||||
*/
|
||||
*/
|
||||
void http_decoder_table_set_header_complete(struct http_decoder_table *table);
|
||||
|
||||
void http_decoder_table_reset_header_complete(struct http_decoder_table *table);
|
||||
@@ -77,4 +77,3 @@ void http_decoder_table_reset_header_complete(struct http_decoder_table *table);
|
||||
void http_decoder_table_update_commit_index(struct http_decoder_table *table);
|
||||
|
||||
int http_decoder_table_get_total_parsed_header(struct http_decoder_table *table);
|
||||
#endif
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include "http_decoder_inc.h"
|
||||
#include "http_decoder_private.h"
|
||||
#include "llhttp.h"
|
||||
|
||||
struct http_tunnel_message
|
||||
@@ -12,28 +12,32 @@ struct http_tunnel_message
|
||||
hstring tunnel_payload;
|
||||
};
|
||||
|
||||
|
||||
int httpd_tunnel_identify(struct http_decoder_env *httpd_env, int curdir, struct http_decoder_half_data *hfdata)
|
||||
{
|
||||
if(0 == httpd_env->hd_cfg.proxy_enable){
|
||||
if (0 == httpd_env->hd_cfg.proxy_enable)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(FLOW_DIRECTION_C2S == curdir){
|
||||
if (FLOW_DIRECTION_C2S == curdir)
|
||||
{
|
||||
struct http_request_line reqline = {};
|
||||
http_decoder_half_data_get_request_line(hfdata, &reqline);
|
||||
if(0 == strncasecmp_safe("CONNECT", (char *)reqline.method.iov_base,
|
||||
7, reqline.method.iov_len)){
|
||||
if (0 == strncasecmp_safe("CONNECT", (char *)reqline.method.iov_base,
|
||||
7, reqline.method.iov_len))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}else{
|
||||
}
|
||||
else
|
||||
{
|
||||
struct http_response_line resline = {};
|
||||
http_decoder_half_data_get_response_line(hfdata, &resline);
|
||||
if(resline.status_code == HTTP_STATUS_OK
|
||||
&& 0 == strncasecmp_safe("Connection established", (char *)resline.status.iov_base,
|
||||
strlen("Connection established"), resline.status.iov_len)){
|
||||
if (resline.status_code == HTTP_STATUS_OK && 0 == strncasecmp_safe("Connection established", (char *)resline.status.iov_base,
|
||||
strlen("Connection established"), resline.status.iov_len))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -41,15 +45,17 @@ int httpd_tunnel_identify(struct http_decoder_env *httpd_env, int curdir, struct
|
||||
|
||||
int httpd_is_tunnel_session(const struct http_decoder_env *httpd_env, const struct http_decoder_exdata *ex_data)
|
||||
{
|
||||
if(0 == httpd_env->hd_cfg.proxy_enable){
|
||||
if (0 == httpd_env->hd_cfg.proxy_enable)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return (ex_data && ex_data->tunnel_state != HTTP_TUN_NON);
|
||||
}
|
||||
|
||||
int httpd_in_tunnel_transmitting(const struct http_decoder_env *httpd_env, struct http_decoder_exdata *ex_data)
|
||||
{
|
||||
if(0 == httpd_env->hd_cfg.proxy_enable){
|
||||
if (0 == httpd_env->hd_cfg.proxy_enable)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (ex_data && ex_data->tunnel_state >= HTTP_TUN_INNER_STARTING);
|
||||
@@ -57,10 +63,12 @@ int httpd_in_tunnel_transmitting(const struct http_decoder_env *httpd_env, struc
|
||||
|
||||
enum http_tunnel_message_type httpd_tunnel_state_to_msg(const struct http_decoder_exdata *ex_data)
|
||||
{
|
||||
if(ex_data->tunnel_state == HTTP_TUN_INNER_STARTING){
|
||||
if (ex_data->tunnel_state == HTTP_TUN_INNER_STARTING)
|
||||
{
|
||||
return HTTP_TUNNEL_OPENING;
|
||||
}
|
||||
if(ex_data->tunnel_state == HTTP_TUN_INNER_TRANS){
|
||||
if (ex_data->tunnel_state == HTTP_TUN_INNER_TRANS)
|
||||
{
|
||||
return HTTP_TUNNEL_ACTIVE;
|
||||
}
|
||||
return HTTP_TUNNEL_MSG_MAX;
|
||||
@@ -68,7 +76,8 @@ enum http_tunnel_message_type httpd_tunnel_state_to_msg(const struct http_decode
|
||||
|
||||
void httpd_tunnel_state_update(struct http_decoder_exdata *ex_data)
|
||||
{
|
||||
if(ex_data->tunnel_state == HTTP_TUN_INNER_STARTING){
|
||||
if (ex_data->tunnel_state == HTTP_TUN_INNER_STARTING)
|
||||
{
|
||||
ex_data->tunnel_state = HTTP_TUN_INNER_TRANS;
|
||||
}
|
||||
}
|
||||
@@ -86,21 +95,21 @@ void http_decoder_push_tunnel_data(struct session *sess, const struct http_decod
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
void http_tunnel_message_get_payload(const struct http_tunnel_message *tmsg,
|
||||
hstring *tunnel_payload)
|
||||
{
|
||||
if (unlikely(NULL == tmsg || tunnel_payload == NULL))
|
||||
void http_tunnel_message_get_payload(const struct http_tunnel_message *tmsg,
|
||||
hstring *tunnel_payload)
|
||||
{
|
||||
return;
|
||||
if (unlikely(NULL == tmsg || tunnel_payload == NULL))
|
||||
{
|
||||
return;
|
||||
}
|
||||
tunnel_payload->iov_base = tmsg->tunnel_payload.iov_base;
|
||||
tunnel_payload->iov_len = tmsg->tunnel_payload.iov_len;
|
||||
}
|
||||
tunnel_payload->iov_base = tmsg->tunnel_payload.iov_base;
|
||||
tunnel_payload->iov_len = tmsg->tunnel_payload.iov_len;
|
||||
}
|
||||
|
||||
enum http_tunnel_message_type http_tunnel_message_type_get(const struct http_tunnel_message *tmsg)
|
||||
{
|
||||
return tmsg->type;
|
||||
}
|
||||
enum http_tunnel_message_type http_tunnel_message_type_get(const struct http_tunnel_message *tmsg)
|
||||
{
|
||||
return tmsg->type;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
#pragma once
|
||||
#include "http_decoder_inc.h"
|
||||
#pragma once
|
||||
#include "http_decoder_private.h"
|
||||
#include "http_decoder_half.h"
|
||||
|
||||
enum http_tunnel_state{
|
||||
HTTP_TUN_NON = 0, // init, or not tunnel session
|
||||
HTTP_TUN_C2S_HDR_START, //CONNECT ...
|
||||
HTTP_TUN_C2S_END, //CONNECT request end
|
||||
HTTP_TUN_S2C_START, // HTTP 200 connet established
|
||||
HTTP_TUN_INNER_STARTING, // http inner tunnel protocol starting
|
||||
HTTP_TUN_INNER_TRANS, // http inner tunnel protocol transmitting
|
||||
enum http_tunnel_state
|
||||
{
|
||||
HTTP_TUN_NON = 0, // init, or not tunnel session
|
||||
HTTP_TUN_C2S_HDR_START, // CONNECT ...
|
||||
HTTP_TUN_C2S_END, // CONNECT request end
|
||||
HTTP_TUN_S2C_START, // HTTP 200 connet established
|
||||
HTTP_TUN_INNER_STARTING, // http inner tunnel protocol starting
|
||||
HTTP_TUN_INNER_TRANS, // http inner tunnel protocol transmitting
|
||||
};
|
||||
|
||||
/************************************************************
|
||||
* HTTP TUNNEL WITH CONNECT METHOD.
|
||||
*************************************************************/
|
||||
* HTTP TUNNEL WITH CONNECT METHOD.
|
||||
*************************************************************/
|
||||
struct http_tunnel_message;
|
||||
#define HTTP_DECODER_TUNNEL_TOPIC "HTTP_DECODER_TUNNEL_MESSAGE"
|
||||
#define HTTP_DECODER_TUNNEL_TOPIC "HTTP_DECODER_TUNNEL_MESSAGE"
|
||||
|
||||
enum http_tunnel_message_type {
|
||||
enum http_tunnel_message_type
|
||||
{
|
||||
HTTP_TUNNEL_OPENING,
|
||||
HTTP_TUNNEL_ACTIVE,
|
||||
HTTP_TUNNEL_CLOSING,
|
||||
@@ -26,7 +28,6 @@ enum http_tunnel_message_type {
|
||||
enum http_tunnel_message_type http_tunnel_message_type_get(const struct http_tunnel_message *tmsg);
|
||||
void http_tunnel_message_get_payload(const struct http_tunnel_message *tmsg, struct iovec *tunnel_payload);
|
||||
|
||||
|
||||
int httpd_tunnel_identify(struct http_decoder_env *httpd_env, int curdir, struct http_decoder_half_data *hfdata);
|
||||
int httpd_is_tunnel_session(const struct http_decoder_env *httpd_env, const struct http_decoder_exdata *ex_data);
|
||||
int httpd_in_tunnel_transmitting(const struct http_decoder_env *httpd_env, struct http_decoder_exdata *ex_data);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "stellar/http.h"
|
||||
#include "http_decoder_inc.h"
|
||||
#include "http_decoder_private.h"
|
||||
|
||||
char *safe_dup(const char *str, size_t len)
|
||||
{
|
||||
@@ -164,7 +164,8 @@ int http_event_is_req(enum http_event event)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int stellar_session_mq_get_topic_id_reliable(struct stellar *st, const char *topic_name, stellar_msg_free_cb_func *msg_free_cb, void *msg_free_arg)
|
||||
int stellar_session_mq_get_topic_id_reliable(struct stellar *st, const char *topic_name,
|
||||
stellar_msg_free_cb_func *msg_free_cb, void *msg_free_arg)
|
||||
{
|
||||
int topic_id = stellar_mq_get_topic_id(st, topic_name);
|
||||
if (topic_id < 0)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -29,7 +29,8 @@ int httpd_url_is_encoded(const char *url, size_t len);
|
||||
* Logger
|
||||
******************************************************************************/
|
||||
|
||||
enum http_decoder_log_level {
|
||||
enum http_decoder_log_level
|
||||
{
|
||||
DEBUG = 0x11,
|
||||
WARN = 0x12,
|
||||
INFO = 0x13,
|
||||
@@ -61,20 +62,19 @@ enum http_decoder_log_level {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
struct httpd_session_addr
|
||||
{
|
||||
uint8_t ipver; /* 4 or 6 */
|
||||
uint16_t sport; /* network order */
|
||||
uint16_t dport; /* network order */
|
||||
union
|
||||
{
|
||||
uint8_t ipver; /* 4 or 6 */
|
||||
uint16_t sport; /* network order */
|
||||
uint16_t dport; /* network order */
|
||||
union
|
||||
{
|
||||
uint32_t saddr4;
|
||||
uint32_t daddr4;
|
||||
struct in6_addr saddr6;
|
||||
struct in6_addr saddr6;
|
||||
struct in6_addr daddr6;
|
||||
};
|
||||
};
|
||||
};
|
||||
void httpd_session_get_addr(const struct session *sess, struct httpd_session_addr *addr);
|
||||
|
||||
Reference in New Issue
Block a user