diff options
| author | yangwei <[email protected]> | 2024-05-28 02:07:20 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2024-05-28 04:40:31 +0800 |
| commit | ba8450caed9876a463fbfefc7a521cc62bce432e (patch) | |
| tree | 552986583d706751572d39b180422811d5bb3e03 /src | |
| parent | 0737ab92295eca2690e875db240f1b0af495d7dc (diff) | |
🧪 test(remove http decoder): rm related source code
Diffstat (limited to 'src')
| -rw-r--r-- | src/http_decoder/CMakeLists.txt | 12 | ||||
| -rw-r--r-- | src/http_decoder/http_content_decompress.c | 268 | ||||
| -rw-r--r-- | src/http_decoder/http_content_decompress.h | 52 | ||||
| -rw-r--r-- | src/http_decoder/http_decoder.c | 592 | ||||
| -rw-r--r-- | src/http_decoder/http_decoder.h | 115 | ||||
| -rw-r--r-- | src/http_decoder/http_decoder.toml | 4 | ||||
| -rw-r--r-- | src/http_decoder/http_decoder_half.c | 803 | ||||
| -rw-r--r-- | src/http_decoder/http_decoder_half.h | 104 | ||||
| -rw-r--r-- | src/http_decoder/http_decoder_result_queue.c | 155 | ||||
| -rw-r--r-- | src/http_decoder/http_decoder_result_queue.h | 67 | ||||
| -rw-r--r-- | src/http_decoder/http_decoder_string.c | 193 | ||||
| -rw-r--r-- | src/http_decoder/http_decoder_string.h | 89 | ||||
| -rw-r--r-- | src/http_decoder/http_decoder_table.c | 443 | ||||
| -rw-r--r-- | src/http_decoder/http_decoder_table.h | 74 | ||||
| -rw-r--r-- | src/http_decoder/http_decoder_utils.c | 25 | ||||
| -rw-r--r-- | src/http_decoder/http_decoder_utils.h | 66 | ||||
| -rw-r--r-- | src/http_decoder/version.map | 7 | ||||
| -rw-r--r-- | src/plugin_manager/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/plugin_manager/plugin_manager.c | 120 | ||||
| -rw-r--r-- | src/stellar_on_sapp/stellar_on_sapp_api.c | 1 |
20 files changed, 47 insertions, 3145 deletions
diff --git a/src/http_decoder/CMakeLists.txt b/src/http_decoder/CMakeLists.txt deleted file mode 100644 index a17fcd8..0000000 --- a/src/http_decoder/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_definitions(-fPIC) - -include_directories(/opt/MESA/include/) - -set(HTTP_SRC http_decoder.c http_decoder_utils.c http_decoder_half.c - http_decoder_table.c http_decoder_string.c http_content_decompress.c - http_decoder_result_queue.c) - -add_library(http_decoder SHARED ${HTTP_SRC}) -#set_target_properties(http_decoder_shared PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/version.map") -target_link_libraries(http_decoder z brotlidec llhttp-static fieldstat4) -set_target_properties(http_decoder PROPERTIES PREFIX "")
\ No newline at end of file diff --git a/src/http_decoder/http_content_decompress.c b/src/http_decoder/http_content_decompress.c deleted file mode 100644 index b887487..0000000 --- a/src/http_decoder/http_content_decompress.c +++ /dev/null @@ -1,268 +0,0 @@ -/* -********************************************************************************************** -* File: http_content_decompress.c -* Description: -* Authors: LuWenPeng <[email protected]> -* 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 "stellar/utils.h" -#include "http_decoder_utils.h" -#include "http_content_decompress.h" - -#define BUFFER_SIZE (1024 * 1024 * 4) - -struct http_content_decompress { - enum http_content_encoding encoding; - - z_stream *z_stream_ptr; - BrotliDecoderState *br_state; - - char *buffer; - size_t buffer_size; -}; - -enum http_content_encoding -http_content_encoding_str2int(const char *content_encoding) -{ - if (strcasestr(content_encoding, "gzip") != NULL) { - return HTTP_CONTENT_ENCODING_GZIP; - } - - if (strcasestr(content_encoding, "deflate") != NULL) { - return HTTP_CONTENT_ENCODING_DEFLATE; - } - - 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) -{ - if (content_encoding == HTTP_CONTENT_ENCODING_GZIP) { - return "gzip"; - } - - if (content_encoding == HTTP_CONTENT_ENCODING_DEFLATE) { - return "deflate"; - } - - 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 *decompress = - CALLOC(struct http_content_decompress, 1); - assert(decompress); - - decompress->encoding = encoding; - decompress->z_stream_ptr = NULL; - decompress->br_state = NULL; - - decompress->buffer = CALLOC(char, BUFFER_SIZE); - assert(decompress->buffer); - decompress->buffer_size = BUFFER_SIZE; - - if (encoding == HTTP_CONTENT_ENCODING_GZIP - || encoding == HTTP_CONTENT_ENCODING_DEFLATE) { - decompress->z_stream_ptr = CALLOC(z_stream, 1); - assert(decompress->z_stream_ptr); - - decompress->z_stream_ptr->zalloc = NULL; - decompress->z_stream_ptr->zfree = NULL; - decompress->z_stream_ptr->opaque = NULL; - 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) { - goto error; - } - } - - if (encoding == HTTP_CONTENT_ENCODING_DEFLATE) { - if (inflateInit2(decompress->z_stream_ptr, -MAX_WBITS) != Z_OK) { - goto error; - } - } - } - - if (encoding == HTTP_CONTENT_ENCODING_BR) { - decompress->br_state = BrotliDecoderCreateInstance(NULL, NULL, NULL); - if (decompress->br_state == NULL) { - goto error; - } - } - - return decompress; - -error: - http_content_decompress_destroy(decompress); - return NULL; -} - -void http_content_decompress_destroy(struct http_content_decompress *decompress) -{ - if (NULL == decompress) { - return; - } - - if (decompress->z_stream_ptr != NULL) { - inflateEnd(decompress->z_stream_ptr); - FREE(decompress->z_stream_ptr); - } - - if (decompress->br_state) { - BrotliDecoderDestroyInstance(decompress->br_state); - decompress->br_state = NULL; - } - - FREE(decompress->buffer); - 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) -{ - z_stream *z_stream_ptr = decompress->z_stream_ptr; - z_stream_ptr->avail_in = (unsigned int)indata_len; - z_stream_ptr->next_in = (unsigned char *)indata; - z_stream_ptr->avail_out = (unsigned int)decompress->buffer_size; - z_stream_ptr->next_out = (unsigned char *)decompress->buffer; - - *outdata = NULL; - *outdata_len = 0; - - int ret = 0; - do { - 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) { - (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) { - 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), - decompress->buffer_size); - z_stream_ptr->avail_out = have; - z_stream_ptr->next_out = (unsigned char *)decompress->buffer + - (decompress->buffer_size - have); - } else { - *outdata = decompress->buffer; - *outdata_len = have; - } - } - } while (z_stream_ptr->avail_in != 0); - - 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) -{ - size_t available_in = indata_len; - const unsigned char *next_in = (const unsigned char *)indata; - size_t available_out = decompress->buffer_size; - unsigned char *next_out = (unsigned char *)decompress->buffer; - - *outdata = NULL; - *outdata_len = 0; - - int ret; - for (;;) { - 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) { - decompress->buffer_size += have; - decompress->buffer = REALLOC(char, decompress->buffer, - decompress->buffer_size); - *outdata = decompress->buffer; - *outdata_len = *outdata_len + have; - available_out = have; - next_out = (unsigned char *)decompress->buffer + - (decompress->buffer_size - have); - } else { - *outdata = decompress->buffer; - *outdata_len = have; - } - } - - if (ret == BROTLI_DECODER_RESULT_SUCCESS - || ret == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT) { - return 0; - } - - if (ret == BROTLI_DECODER_RESULT_ERROR) { - BrotliDecoderErrorCode errcode = - BrotliDecoderGetErrorCode(decompress->br_state); - http_decoder_log(ERROR, - "BrotliDecoderDecompressStream() failed: errno = %d, %s", - errcode, BrotliDecoderErrorString(errcode)); - return -1; - } - - assert(ret == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT); - } -} - -int http_content_decompress_write(struct http_content_decompress *decompress, - const char *indata, size_t indata_len, - char **outdata, size_t *outdata_len) -{ - assert(decompress); - assert(indata); - assert(indata_len > 0); - assert(outdata); - assert(outdata_len); - - *outdata = NULL; - *outdata_len = 0; - - 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); - } - - if (decompress->encoding == HTTP_CONTENT_ENCODING_BR) { - return http_content_decompress_write_br(decompress, indata, indata_len, - outdata, outdata_len); - } - - assert(0); - return -1; -}
\ No newline at end of file diff --git a/src/http_decoder/http_content_decompress.h b/src/http_decoder/http_content_decompress.h deleted file mode 100644 index 3c2ba48..0000000 --- a/src/http_decoder/http_content_decompress.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -********************************************************************************************** -* File: http_content_decompress.h -* Description: -* Authors: LuWenPeng <[email protected]> -* Date: 2022-10-31 -* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. -*********************************************************************************************** -*/ - - -#ifndef _HTTP_CONTENT_DECOMPRESS_H_ -#define _HTTP_CONTENT_DECOMPRESS_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#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, -}; - -struct http_content_decompress; - -enum http_content_encoding -http_content_encoding_str2int(const char *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); - -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); - -#ifdef __cplusplus -} -#endif - -#endif
\ No newline at end of file diff --git a/src/http_decoder/http_decoder.c b/src/http_decoder/http_decoder.c deleted file mode 100644 index 523253b..0000000 --- a/src/http_decoder/http_decoder.c +++ /dev/null @@ -1,592 +0,0 @@ -/* -********************************************************************************************** -* File: http_decoder.c -* Description: -* Authors: Liu WenTan <[email protected]> -* Date: 2024-01-10 -* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. -*********************************************************************************************** -*/ - -#include <assert.h> -#include <stdio.h> -#include <unistd.h> - -#include "stellar/utils.h" -#include "stellar/session.h" -#include "stellar/session_mq.h" -#include "stellar/session_exdata.h" -#include "http_decoder.h" -#include "http_decoder_half.h" -#include "http_decoder_table.h" -#include "http_decoder_result_queue.h" -#include "llhttp.h" -#include "fieldstat/fieldstat_easy.h" - -#define HTTP_IDENTIFY_LEN 16 -#define HD_RESULT_QUEUE_SIZE 16 -#define HD_IS_CACHE_BODY 1 - -const char *http_decoder_topic = "HTTP_DECODER_MESSAGE"; -const char *fs_file_name = "http_decoder.fs"; - -/** - * NOTE: http_message don't have the ownership of data -*/ -struct http_message { - enum http_message_type type; - struct http_decoder_half_data *data; -}; - -struct http_decoder { - struct http_decoder_half *c2s_half; - struct http_decoder_half *s2c_half; -}; - -struct http_decoder_exdata { - struct http_decoder_result_queue *queue; - struct http_decoder *decoder; -}; - -struct http_decoder_context { - int plugin_id; - int topic_id; - int ex_data_idx; - int fs_incoming_bytes_id; - int fs_incoming_pkts_id; - int fs_incoming_trans_id; - struct fieldstat_easy *fse; - struct stellar *st; -}; - -static void http_event_handler(enum http_event event, - struct http_decoder_half_data **data, - struct http_event_context *ev_ctx) -{ - assert(ev_ctx); - - struct http_decoder_result_queue *queue = ev_ctx->ref_queue; - struct http_message *msg = NULL; - struct http_decoder_half_data *half_data = NULL; - int ret = 0; - - switch (event) { - case HTTP_EVENT_REQ_INIT: - half_data = http_decoder_result_queue_peek_req(queue); - if (half_data != NULL) { - http_decoder_result_queue_inc_req_index(queue); - } - - half_data = http_decoder_result_queue_peek_req(queue); - if (half_data != NULL) { - half_data = http_decoder_result_queue_pop_req(queue); - http_decoder_half_data_free(half_data); - half_data = NULL; - } - - half_data = http_decoder_half_data_new(); - ret = http_decoder_result_queue_push_req(queue, half_data); - if (ret < 0) { - fprintf(stderr, "http_decoder_result_queue_push req failed."); - http_decoder_half_data_free(half_data); - half_data = NULL; - } - *data = half_data; - break; - case HTTP_EVENT_REQ_LINE: - msg = CALLOC(struct http_message, 1); - msg->type = HTTP_MESSAGE_REQ_LINE; - msg->data = *data; - session_mq_publish_message(ev_ctx->ref_session, ev_ctx->topic_id, msg); - break; - case HTTP_EVENT_REQ_HDR_END: - msg = CALLOC(struct http_message, 1); - msg->type = HTTP_MESSAGE_REQ_HEADER; - msg->data = *data; - session_mq_publish_message(ev_ctx->ref_session, ev_ctx->topic_id, msg); - break; - case HTTP_EVENT_REQ_BODY_BEGIN: - break; - case HTTP_EVENT_REQ_BODY_DATA: - msg = CALLOC(struct http_message, 1); - msg->type = HTTP_MESSAGE_REQ_BODY; - msg->data = *data; - session_mq_publish_message(ev_ctx->ref_session, ev_ctx->topic_id, msg); - break; - case HTTP_EVENT_REQ_BODY_END: - break; - case HTTP_EVENT_REQ_END: - http_decoder_result_queue_inc_req_index(queue); - half_data = http_decoder_result_queue_pop_req(queue); - if (half_data != NULL) { - http_decoder_half_data_free(half_data); - half_data = NULL; - } - break; - case HTTP_EVENT_RES_INIT: - half_data = http_decoder_result_queue_peek_res(queue); - if (half_data != NULL) { - http_decoder_result_queue_inc_res_index(queue); - } - - half_data = http_decoder_result_queue_peek_res(queue); - if (half_data != NULL) { - half_data = http_decoder_result_queue_pop_res(queue); - http_decoder_half_data_free(half_data); - half_data = NULL; - } - - half_data = http_decoder_half_data_new(); - ret = http_decoder_result_queue_push_res(queue, half_data); - if (ret < 0) { - fprintf(stderr, "http_decoder_result_queue_push res failed."); - http_decoder_half_data_free(half_data); - half_data = NULL; - } - *data = half_data; - break; - case HTTP_EVENT_RES_LINE: - msg = CALLOC(struct http_message, 1); - msg->type = HTTP_MESSAGE_RES_LINE; - msg->data = *data; - session_mq_publish_message(ev_ctx->ref_session, ev_ctx->topic_id, msg); - break; - case HTTP_EVENT_RES_HDR: - break; - case HTTP_EVENT_RES_HDR_END: - msg = CALLOC(struct http_message, 1); - msg->type = HTTP_MESSAGE_RES_HEADER; - msg->data = *data; - session_mq_publish_message(ev_ctx->ref_session, ev_ctx->topic_id, msg); - break; - case HTTP_EVENT_RES_BODY_BEGIN: - break; - case HTTP_EVENT_RES_BODY_DATA: - msg = CALLOC(struct http_message, 1); - msg->type = HTTP_MESSAGE_RES_BODY; - msg->data = *data; - session_mq_publish_message(ev_ctx->ref_session, ev_ctx->topic_id, msg); - break; - case HTTP_EVENT_RES_BODY_END: - break; - case HTTP_EVENT_RES_END: - http_decoder_result_queue_inc_res_index(queue); - half_data = http_decoder_result_queue_pop_res(queue); - if (half_data != NULL) { - http_decoder_half_data_free(half_data); - half_data = NULL; - } - break; - default: - assert(0); - break; - } -} - -static struct http_decoder * -http_decoder_new(http_event_cb *ev_cb, int is_cache_body) -{ - struct http_decoder *decoder = CALLOC(struct http_decoder, 1); - assert(decoder); - - decoder->c2s_half = http_decoder_half_new(ev_cb, is_cache_body, HTTP_REQUEST); - decoder->s2c_half = http_decoder_half_new(ev_cb, is_cache_body, HTTP_RESPONSE); - - return decoder; -} - -static void http_decoder_free(struct http_decoder *decoder) -{ - if (NULL == decoder) { - return; - } - - if (decoder->c2s_half != NULL) { - http_decoder_half_free(decoder->c2s_half); - decoder->c2s_half = NULL; - } - - if (decoder->s2c_half != NULL) { - http_decoder_half_free(decoder->s2c_half); - decoder->s2c_half = NULL; - } - - FREE(decoder); -} - -static struct http_decoder_exdata *http_decoder_exdata_new(size_t queue_size) -{ - struct http_decoder_exdata *ex_data = CALLOC(struct http_decoder_exdata, 1); - - ex_data->decoder = http_decoder_new(http_event_handler, 0); - ex_data->queue = http_decoder_result_queue_new(HD_RESULT_QUEUE_SIZE); - - return ex_data; -} - -static void http_decoder_exdata_free(struct http_decoder_exdata *ex_data) -{ - if (NULL == ex_data) { - return; - } - - if (ex_data->decoder != NULL) { - http_decoder_free(ex_data->decoder); - ex_data->decoder = NULL; - } - - if (ex_data->queue != NULL) { - http_decoder_result_queue_free(ex_data->queue); - ex_data->queue = NULL; - } - - FREE(ex_data); -} - -static int http_protocol_identify(const char *data, size_t data_len) -{ - llhttp_t parser; - llhttp_settings_t settings; - enum llhttp_errno error; - - llhttp_settings_init(&settings); - llhttp_init(&parser, HTTP_BOTH, &settings); - - error = llhttp_execute(&parser, data, data_len); - if (error != HPE_OK) { - return -1; - } - - return 0; -} - -int http_decoder_entry(struct session *sess, int events, - const struct packet *pkt, void *cb_arg) -{ - struct http_decoder_context *decoder_ctx = (struct http_decoder_context *)cb_arg; - size_t payload_len = 0; - uint64_t inner_flag = 0; - - int ret = session_is_inner_most(sess, &inner_flag); - if (0 == ret) { - return 0; - } - - struct http_decoder_exdata *ex_data = - session_get_ex_data(sess, decoder_ctx->ex_data_idx); - - if (events & SESS_EV_CLOSING) { - if (ex_data != NULL) { - http_decoder_exdata_free(ex_data); - session_set_ex_data(sess, decoder_ctx->ex_data_idx, NULL); - } - - return 0; - } - - const char *payload = session_get0_current_payload(sess, &payload_len); - - if (events & SESS_EV_OPENING) { - assert(ex_data == NULL); - - //If not http, ignore this session - if (payload_len > 0) { - size_t http_identify_len = payload_len > HTTP_IDENTIFY_LEN - ? HTTP_IDENTIFY_LEN - : payload_len; - - ret = http_protocol_identify(payload, http_identify_len); - if (ret < 0) { - // ignore this session's event - struct session_event *s_event = - session_get_intrinsic_event(sess, decoder_ctx->plugin_id); - - session_event_assign(s_event, decoder_ctx->st, sess, 0, - http_decoder_entry, decoder_ctx); - return 0; - } - } - - ex_data = http_decoder_exdata_new(HD_RESULT_QUEUE_SIZE); - session_set_ex_data(sess, decoder_ctx->ex_data_idx, ex_data); - } - - if (0 == payload_len || NULL == ex_data) { - return 0; - } - - int dir = packet_get_direction(pkt); - if (dir < 0) { - return -1; - } - - struct http_decoder_half *cur_half = NULL; - if (dir == PACKET_DIRECTION_C2S) { - cur_half = ex_data->decoder->c2s_half; - } else { - cur_half = ex_data->decoder->s2c_half; - } - - http_decoder_half_reinit(cur_half, decoder_ctx->topic_id, ex_data->queue, sess); - http_decoder_half_parse(cur_half, payload, payload_len); - - int thread_id = session_get_current_thread_id(sess); - - fieldstat_easy_counter_incrby(decoder_ctx->fse, thread_id, - decoder_ctx->fs_incoming_bytes_id, - NULL, 0, payload_len); - - fieldstat_easy_counter_incrby(decoder_ctx->fse, thread_id, - decoder_ctx->fs_incoming_pkts_id, - NULL, 0, 1); - - long long trans_cnt = http_decoder_half_trans_count(cur_half); - fieldstat_easy_counter_incrby(decoder_ctx->fse, thread_id, - decoder_ctx->fs_incoming_trans_id, - NULL, 0, trans_cnt); - - return 0; -} - -static void http_message_free(void *msg, void *cb_arg) -{ - if (NULL == msg) { - return; - } - - struct http_message *message = (struct http_message *)msg; - message->data = NULL; //don't have memory's ownership - - FREE(message); -} - -static void _http_decoder_context_free(struct http_decoder_context *ctx) -{ - if (NULL == ctx) { - return; - } - - if (ctx->fse != NULL) { - fieldstat_easy_free(ctx->fse); - ctx->fse = NULL; - } - - if (ctx->topic_id >= 0) { - session_mq_destroy_topic(ctx->st, ctx->topic_id); - ctx->topic_id = -1; - } - - FREE(ctx); -} - -static void http_decoder_ex_data_free(struct session *s, int idx, - void *ex_data, void *arg) -{ - if (NULL == ex_data) { - return; - } - - struct http_decoder_exdata *exdata = (struct http_decoder_exdata *)ex_data; - http_decoder_exdata_free(exdata); -} - -#define FS_OUTPUT_INTERVAL_S 1 -void *http_decoder_init(struct stellar *st) -{ - struct http_decoder_context *ctx = CALLOC(struct http_decoder_context, 1); - - ctx->st = st; - ctx->ex_data_idx = stellar_session_get_ex_new_index(st, "HTTP_DECODER", - http_decoder_ex_data_free, - NULL); - - int plugin_id = stellar_plugin_register(st, SESS_EV_TCP|SESS_EV_CLOSING, - http_decoder_entry, ctx); - if (plugin_id >= 0) { - ctx->plugin_id = plugin_id; - } - - int topic_id = session_mq_get_topic_id(st, http_decoder_topic); - if (topic_id < 0) { - topic_id = session_mq_create_topic(st, http_decoder_topic, - http_message_free, NULL); - } - ctx->topic_id = topic_id; - - int thread_num = stellar_get_worker_thread_num(st); - - ctx->fse = fieldstat_easy_new(thread_num, "http_decoder_statistics", NULL, 0); - if (NULL == ctx->fse) { - fprintf(stderr, "fieldstat_easy_new failed."); - goto failed; - } - - ctx->fs_incoming_bytes_id = - fieldstat_easy_register_counter(ctx->fse, "incoming_bytes"); - if (ctx->fs_incoming_bytes_id < 0) { - fprintf(stderr, "fieldstat_easy_register_counter incoming_bytes failed."); - goto failed; - } - - ctx->fs_incoming_trans_id = - fieldstat_easy_register_counter(ctx->fse, "incoming_trans"); - if (ctx->fs_incoming_trans_id < 0) { - fprintf(stderr, "fieldstat_easy_register_counter incoming_trans failed."); - goto failed; - } - - ctx->fs_incoming_pkts_id = - fieldstat_easy_register_counter(ctx->fse, "incoming_pkts"); - if (ctx->fs_incoming_pkts_id < 0) { - fprintf(stderr, "fieldstat_easy_register_counter incoming_pkts failed."); - goto failed; - } - - int ret = fieldstat_easy_enable_auto_output(ctx->fse, fs_file_name, - FS_OUTPUT_INTERVAL_S); - if (ret < 0) { - fprintf(stderr, "fieldstat_easy_enable_auto_output failed."); - goto failed; - } - sleep(1); - - printf("http_decoder_init: ex_data_idx:%d, plugin_id:%d, topic_id:%d\n", - ctx->ex_data_idx, ctx->plugin_id, ctx->topic_id); - - return ctx; - -failed: - _http_decoder_context_free(ctx); - return NULL; -} - -void http_decoder_exit(void *decoder_ctx) -{ - if (NULL == decoder_ctx) { - return; - } - - struct http_decoder_context *ctx = - (struct http_decoder_context *)decoder_ctx; - - _http_decoder_context_free(ctx); -} - -enum http_message_type http_message_type(struct http_message *msg) -{ - if (NULL == msg) { - return HTTP_MESSAGE_MAX; - } - - return msg->type; -} - -int http_message_get_request_line(struct http_message *msg, - struct http_request_line *line) -{ - if (NULL == msg || msg->type != HTTP_MESSAGE_REQ_LINE || - NULL == line) { - return -1; - } - - return http_decoder_half_data_get_request_line(msg->data, line); -} - -int http_message_get_response_line(struct http_message *msg, - struct http_response_line *line) -{ - if (NULL == msg || msg->type != HTTP_MESSAGE_RES_LINE || - NULL == line) { - return -1; - } - - return http_decoder_half_data_get_response_line(msg->data, line); -} - -int http_message_get_request_header(struct http_message *msg, struct hstring *key, - struct http_header *hdr_array, size_t array_size) -{ - if (NULL == msg || msg->type != HTTP_MESSAGE_REQ_HEADER || - NULL == key || NULL == hdr_array || 0 == array_size) { - return -1; - } - - return http_decoder_half_data_get_header(msg->data, key, hdr_array, array_size); -} - -int http_message_get_response_header(struct http_message *msg, struct hstring *key, - struct http_header *hdr_array, size_t array_size) -{ - if (NULL == msg || msg->type != HTTP_MESSAGE_RES_HEADER || NULL == key || - NULL == hdr_array || 0 == array_size) { - return -1; - } - - return http_decoder_half_data_get_header(msg->data, key, hdr_array, array_size); -} - -int http_message_request_header_next(struct http_message *msg, - struct http_header *hdr) -{ - if (NULL == msg || msg->type != HTTP_MESSAGE_REQ_HEADER - || NULL == hdr) { - return -1; - } - - return http_decoder_half_data_iter_header(msg->data, hdr); -} - -int http_message_response_header_next(struct http_message *msg, - struct http_header *hdr) -{ - if (NULL == msg || msg->type != HTTP_MESSAGE_RES_HEADER || - NULL == hdr) { - return -1; - } - - return http_decoder_half_data_iter_header(msg->data, hdr); -} - -int http_message_get_request_raw_body(struct http_message *msg, - struct hstring *body) -{ - if (NULL == msg || (msg->type != HTTP_MESSAGE_REQ_BODY) || - NULL == body) { - return -1; - } - - return http_decoder_half_data_get_raw_body(msg->data, body); -} - -int http_message_get_response_raw_body(struct http_message *msg, - struct hstring *body) -{ - if (NULL == msg || (msg->type != HTTP_MESSAGE_RES_BODY) || - NULL == body) { - return -1; - } - - return http_decoder_half_data_get_raw_body(msg->data, body); -} - -int http_message_get_request_decompress_body(struct http_message *msg, - struct hstring *body) -{ - if (NULL == msg || (msg->type != HTTP_MESSAGE_REQ_BODY) || - NULL == body) { - return -1; - } - - return http_decoder_half_data_get_decompress_body(msg->data, body); -} - -int http_message_get_response_decompress_body(struct http_message *msg, - struct hstring *body) -{ - if (NULL == msg || (msg->type != HTTP_MESSAGE_RES_BODY) || - NULL == body) { - return -1; - } - - return http_decoder_half_data_get_decompress_body(msg->data, body); -}
\ No newline at end of file diff --git a/src/http_decoder/http_decoder.h b/src/http_decoder/http_decoder.h deleted file mode 100644 index 24b96c6..0000000 --- a/src/http_decoder/http_decoder.h +++ /dev/null @@ -1,115 +0,0 @@ -/* -********************************************************************************************** -* File: http_decoder.h -* Description: -* Authors: Liu WenTan <[email protected]> -* Date: 2024-01-10 -* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. -*********************************************************************************************** -*/ - -#ifndef _HTTP_DECODER_H_ -#define _HTTP_DECODER_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include <stddef.h> - -enum http_message_type { - HTTP_MESSAGE_REQ_LINE, - HTTP_MESSAGE_REQ_HEADER, - HTTP_MESSAGE_REQ_BODY, - HTTP_MESSAGE_RES_LINE, - HTTP_MESSAGE_RES_HEADER, - HTTP_MESSAGE_RES_BODY, - HTTP_MESSAGE_MAX -}; - -//http string -struct hstring { - char *str; - size_t str_len; -}; - -struct http_header { - struct hstring key; - struct hstring val; -}; - -struct http_request_line { - struct hstring method; - struct hstring uri; - struct hstring version; - - int major_version; - int minor_version; -}; - -struct http_response_line { - struct hstring version; - struct hstring status; - - int major_version; - int minor_version; - int status_code; -}; - -struct http_message; - -enum http_message_type http_message_type(struct http_message *msg); - -/** - * @retval succeed(0) failed(-1) -*/ -int http_message_get_request_line(struct http_message *msg, - struct http_request_line *line); - -int http_message_get_response_line(struct http_message *msg, - struct http_response_line *line); - -/* same key may has multiple kv */ -int http_message_get_request_header(struct http_message *msg, struct hstring *key, - struct http_header *hdr_array, size_t array_size); - -int http_message_get_response_header(struct http_message *msg, struct hstring *key, - struct http_header *hdr_array, size_t array_size); - -/** - * @brief loop reading all headers - * - * @retval succeed(1) failed(<= 0) -*/ -int http_message_request_header_next(struct http_message *msg, - struct http_header *header); - -int http_message_response_header_next(struct http_message *msg, - struct http_header *header); - -/** - * @retval succeed(0) failed(-1) -*/ -int http_message_get_request_raw_body(struct http_message *msg, - struct hstring *body); - -int http_message_get_response_raw_body(struct http_message *msg, - struct hstring *body); - -/** - * @brief If the body hasn't been compressed, return raw body - * - * @retval succeed(0) failed(-1) -*/ -int http_message_get_request_decompress_body(struct http_message *msg, - struct hstring *body); - -int http_message_get_response_decompress_body(struct http_message *msg, - struct hstring *body); - -#ifdef __cplusplus -} -#endif - -#endif
\ No newline at end of file diff --git a/src/http_decoder/http_decoder.toml b/src/http_decoder/http_decoder.toml deleted file mode 100644 index f7717a7..0000000 --- a/src/http_decoder/http_decoder.toml +++ /dev/null @@ -1,4 +0,0 @@ -[[plugin]] -path = "./src/http_decoder/http_decoder.so" -init = "http_decoder_init" -exit = "http_decoder_exit"
\ No newline at end of file diff --git a/src/http_decoder/http_decoder_half.c b/src/http_decoder/http_decoder_half.c deleted file mode 100644 index d97cd25..0000000 --- a/src/http_decoder/http_decoder_half.c +++ /dev/null @@ -1,803 +0,0 @@ -/* -********************************************************************************************** -* File: http_decoder_half.c -* Description: -* Authors: Liu WenTan <[email protected]> -* Date: 2024-01-10 -* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. -*********************************************************************************************** -*/ - -#include <assert.h> -#include <stdio.h> - -#include "stellar/utils.h" -#include "llhttp.h" -#include "http_decoder_utils.h" -#include "http_decoder_half.h" -#include "http_decoder_table.h" -#include "http_content_decompress.h" - -struct http_decoder_half_data { - struct http_decoder_table *table; - - int major_version; - int minor_version; - int status_code; - - enum http_content_encoding content_encoding; - struct http_content_decompress *decompress; - char *ref_decompress_body; - size_t decompress_body_len; -}; - -struct http_decoder_half { - llhttp_t parser; - llhttp_settings_t settings; - enum llhttp_errno error; - - int is_cache_body; - - struct http_decoder_half_data *ref_data; - enum http_event event; - http_event_cb *http_ev_cb; - struct http_event_context *http_ev_ctx; - long long trans_counter; -}; - -// #define HTTP_DECODER_DEBUG -#ifdef HTTP_DECODER_DEBUG -static void printf_debug_info(const char *desc, const char *at, size_t length) -{ - if (at) - { - char *temp = safe_dup(at, length); - printf("HTTP PARSER STAGE: %s: %s\n", desc, temp); - FREE(temp); - } - else - { - printf("HTTP PARSER STAGE: %s\n", desc); - } -} -#else -#define printf_debug_info(desc, at, length) -#endif - -static void -http_decoder_half_data_decompress(struct http_decoder_half_data *data) -{ - assert(data); - - if (data->content_encoding == HTTP_CONTENT_ENCODING_NONE) { - return; - } - - struct hstring raw_body = {0}; - http_decoder_table_get_body(data->table, &raw_body); - if (raw_body.str == NULL || raw_body.str_len == 0) { - return; - } - - if (NULL == data->decompress) { - data->decompress = http_content_decompress_create(data->content_encoding); - } - - assert(data->decompress); - if (http_content_decompress_write(data->decompress, raw_body.str, - raw_body.str_len, - &data->ref_decompress_body, - &data->decompress_body_len) == -1) { - // log error - http_content_decompress_destroy(data->decompress); - data->decompress = NULL; - } -} - -/* Possible return values 0, -1, `HPE_PAUSED` */ -static int on_message_begin(llhttp_t *http) -{ - printf_debug_info("on_message_begin", NULL, 0); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - if (half->parser.type == HTTP_REQUEST) { - half->event = HTTP_EVENT_REQ_INIT; - } else { - half->event = HTTP_EVENT_RES_INIT; - } - - half->ref_data = NULL; - - assert(half->http_ev_cb != NULL); - half->http_ev_cb(half->event, &half->ref_data, half->http_ev_ctx); - - half->trans_counter++; - - return 0; -} - -static int on_message_complete(llhttp_t *http) -{ - printf_debug_info("on_message_complete", NULL, 0); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - if (half->parser.type == HTTP_REQUEST) { - if (half->event == HTTP_EVENT_REQ_BODY_DATA) { - half->event = HTTP_EVENT_REQ_BODY_END; - if (half->http_ev_cb != NULL) { - half->http_ev_cb(half->event, &half->ref_data, - half->http_ev_ctx); - } - } - } else { - if (half->event == HTTP_EVENT_RES_BODY_DATA) { - half->event = HTTP_EVENT_RES_BODY_END; - if (half->http_ev_cb != NULL) { - half->http_ev_cb(half->event, &half->ref_data, - half->http_ev_ctx); - } - } - } - - //trigger req_end/res_end - if (half->parser.type == HTTP_REQUEST) { - half->event = HTTP_EVENT_REQ_END; - if (half->http_ev_cb != NULL) { - half->http_ev_cb(half->event, &half->ref_data, half->http_ev_ctx); - } - } else { - half->event = HTTP_EVENT_RES_END; - if (half->http_ev_cb != NULL) { - half->http_ev_cb(half->event, &half->ref_data, half->http_ev_ctx); - } - } - - return 0; -} - -static int on_reset(llhttp_t *http) -{ - printf_debug_info("on_reset", NULL, 0); - - return 0; -} - -static int on_method(llhttp_t *http, const char *at, size_t length) -{ - printf_debug_info("on_method", at, length); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - http_decoder_table_refer(half->ref_data->table, HTTP_ITEM_METHOD, - at, length); - return 0; -} - -/* Information-only callbacks, return value is ignored */ -static int on_method_complete(llhttp_t *http) -{ - printf_debug_info("on_method_complete", NULL, 0); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - if (http_decoder_table_state(half->ref_data->table, HTTP_ITEM_METHOD) == - STRING_STATE_REFER) { - http_decoder_table_cache(half->ref_data->table, HTTP_ITEM_METHOD); - } - http_decoder_table_commit(half->ref_data->table, HTTP_ITEM_METHOD); - - return 0; -} - -/* Possible return values 0, -1, HPE_USER */ -static int on_uri(llhttp_t *http, const char *at, size_t length) -{ - printf_debug_info("on_uri", at, length); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - http_decoder_table_refer(half->ref_data->table, HTTP_ITEM_URI, - at, length); - return 0; -} - -/* Information-only callbacks, return value is ignored */ -static int on_uri_complete(llhttp_t *http) -{ - printf_debug_info("on_uri_complete", NULL, 0); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - if (http_decoder_table_state(half->ref_data->table, HTTP_ITEM_URI) == - STRING_STATE_REFER) { - http_decoder_table_cache(half->ref_data->table, HTTP_ITEM_URI); - } - http_decoder_table_commit(half->ref_data->table, HTTP_ITEM_URI); - - return 0; -} - -/* Possible return values 0, -1, HPE_USER */ -static int on_version(llhttp_t *http, const char *at, size_t length) -{ - printf_debug_info("on_version", at, length); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - http_decoder_table_refer(half->ref_data->table, HTTP_ITEM_VERSION, - at, length); - return 0; -} - -/* Information-only callbacks, return value is ignored */ -static int on_version_complete(llhttp_t *http) -{ - printf_debug_info("on_version_complete", NULL, 0); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - if (http_decoder_table_state(half->ref_data->table, HTTP_ITEM_VERSION) == - STRING_STATE_REFER) { - http_decoder_table_cache(half->ref_data->table, HTTP_ITEM_VERSION); - } - http_decoder_table_commit(half->ref_data->table, HTTP_ITEM_VERSION); - - half->ref_data->major_version = llhttp_get_http_major(&half->parser); - half->ref_data->minor_version = llhttp_get_http_minor(&half->parser); - - if (half->parser.type == HTTP_REQUEST) { - half->event = HTTP_EVENT_REQ_LINE; - if (half->http_ev_cb) { - half->http_ev_cb(half->event, &half->ref_data, half->http_ev_ctx); - } - } - - return 0; -} - -/* Possible return values 0, -1, HPE_USER */ -static int on_status(llhttp_t *http, const char *at, size_t length) -{ - printf_debug_info("on_status", at, length); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - http_decoder_table_refer(half->ref_data->table, HTTP_ITEM_STATUS, - at, length); - return 0; -} - -/* Information-only callbacks, return value is ignored */ -static int on_status_complete(llhttp_t *http) -{ - printf_debug_info("on_status_complete", NULL, 0); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - if (http_decoder_table_state(half->ref_data->table, HTTP_ITEM_STATUS) == - STRING_STATE_REFER) { - http_decoder_table_cache(half->ref_data->table, HTTP_ITEM_STATUS); - } - http_decoder_table_commit(half->ref_data->table, HTTP_ITEM_STATUS); - - half->ref_data->status_code = llhttp_get_status_code(&half->parser); - - half->event = HTTP_EVENT_RES_LINE; - if (half->http_ev_cb != NULL) { - half->http_ev_cb(half->event, &half->ref_data, half->http_ev_ctx); - } - - return 0; -} - -/* Possible return values 0, -1, HPE_USER */ -static int on_header_field(llhttp_t *http, const char *at, size_t length) -{ - printf_debug_info("on_header_field", at, length); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - http_decoder_table_refer(half->ref_data->table, HTTP_ITEM_HDRKEY, - at, length); - return 0; -} - -/* Information-only callbacks, return value is ignored */ -static int on_header_field_complete(llhttp_t *http) -{ - printf_debug_info("on_header_field_complete", NULL, 0); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - if (http_decoder_table_state(half->ref_data->table, HTTP_ITEM_HDRKEY) == - STRING_STATE_REFER) { - http_decoder_table_cache(half->ref_data->table, HTTP_ITEM_HDRKEY); - } - http_decoder_table_commit(half->ref_data->table, HTTP_ITEM_HDRKEY); - - return 0; -} - -/* Possible return values 0, -1, HPE_USER */ -static int on_header_value(llhttp_t *http, const char *at, size_t length) -{ - printf_debug_info("on_header_value", at, length); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - http_decoder_table_refer(half->ref_data->table, HTTP_ITEM_HDRVAL, - at, length); - return 0; -} - -/* Information-only callbacks, return value is ignored */ -static int on_header_value_complete(llhttp_t *http) -{ - printf_debug_info("on_header_value_complete", NULL, 0); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - if (http_decoder_table_state(half->ref_data->table, HTTP_ITEM_HDRVAL) == - STRING_STATE_REFER) { - http_decoder_table_cache(half->ref_data->table, HTTP_ITEM_HDRVAL); - } - http_decoder_table_commit(half->ref_data->table, HTTP_ITEM_HDRVAL); - - if (half->ref_data->content_encoding == HTTP_CONTENT_ENCODING_NONE) { - struct http_header http_hdr = {0}; - struct hstring key = {.str = (char *)"Content-Encoding", .str_len = 16}; - - if (http_decoder_table_get_header(half->ref_data->table, &key, - &http_hdr, 1) == 1) { - char *str = safe_dup(http_hdr.val.str, http_hdr.val.str_len); - half->ref_data->content_encoding = - http_content_encoding_str2int(str); - FREE(str); - } - } - - return 0; -} - -/* When on_chunk_header is called, the current chunk length is stored - * in parser->content_length. - * Possible return values 0, -1, `HPE_PAUSED` - */ -static int on_chunk_header(llhttp_t *http) -{ - printf_debug_info("on_chunk_header", NULL, 0); - - return 0; -} - -/* When on_chunk_header is called, the current chunk length is stored - * in parser->content_length. - * Possible return values 0, -1, `HPE_PAUSED` - */ -static int on_chunk_header_complete(llhttp_t *http) -{ - printf_debug_info("on_chunk_header_complete", NULL, 0); - - return 0; -} - -/* Possible return values: - * 0 - Proceed normally - * 1 - Assume that request/response has no body, and proceed to parsing the next message - * 2 - Assume absence of body (as above) and make `llhttp_execute()` return `HPE_PAUSED_UPGRADE` - * -1 - Error `HPE_PAUSED` - */ -static int on_headers_complete(llhttp_t *http) -{ - printf_debug_info("on_headers_complete", NULL, 0); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - if (half->parser.type == HTTP_REQUEST) { - half->event = HTTP_EVENT_REQ_HDR_END; - if (half->http_ev_cb) { - half->http_ev_cb(half->event, &half->ref_data, half->http_ev_ctx); - } - } - - if (half->parser.type == HTTP_RESPONSE) { - half->event = HTTP_EVENT_RES_HDR_END; - if (half->http_ev_cb) { - half->http_ev_cb(half->event, &half->ref_data, half->http_ev_ctx); - } - } - - return 0; -} - -/* Possible return values 0, -1, HPE_USER */ -static int on_body(llhttp_t *http, const char *at, size_t length) -{ - printf_debug_info("on_body", at, length); - - struct http_decoder_half *half = - container_of(http, struct http_decoder_half, parser); - assert(half); - - // trigger body_begin event - if (half->parser.type == HTTP_REQUEST) { - if (half->event == HTTP_EVENT_REQ_HDR_END) { - half->event = HTTP_EVENT_REQ_BODY_BEGIN; - if (half->http_ev_cb) { - half->http_ev_cb(half->event, &half->ref_data, - half->http_ev_ctx); - } - } - } else { - if (half->event == HTTP_EVENT_RES_HDR_END) { - half->event = HTTP_EVENT_RES_BODY_BEGIN; - if (half->http_ev_cb) { - half->http_ev_cb(half->event, &half->ref_data, - half->http_ev_ctx); - } - } - } - - if (half->ref_data != NULL) { - if (http_decoder_table_state(half->ref_data->table, HTTP_ITEM_BODY) == - STRING_STATE_COMMIT) { - http_decoder_table_reset(half->ref_data->table, HTTP_ITEM_BODY); - } - - http_decoder_table_refer(half->ref_data->table, HTTP_ITEM_BODY, at, - length); - http_decoder_table_commit(half->ref_data->table, HTTP_ITEM_BODY); - } - - if (half->ref_data->content_encoding != HTTP_CONTENT_ENCODING_NONE) { - http_decoder_half_data_decompress(half->ref_data); - } - - if (half->parser.type == HTTP_REQUEST) { - half->event = HTTP_EVENT_REQ_BODY_DATA; - if (half->http_ev_cb) { - half->http_ev_cb(half->event, &half->ref_data, half->http_ev_ctx); - } - } else { - half->event = HTTP_EVENT_RES_BODY_DATA; - if (half->http_ev_cb) { - half->http_ev_cb(half->event, &half->ref_data, half->http_ev_ctx); - } - } - - return 0; -} - -static void http_decoder_half_init(struct http_decoder_half *half, - http_event_cb *http_ev_cb, - int is_cache_body, int type) -{ - if (NULL == half) { - return; - } - - llhttp_settings_init(&half->settings); - llhttp_init(&half->parser, type, &half->settings); - - half->settings.on_message_begin = on_message_begin; - half->settings.on_message_complete = on_message_complete; - half->settings.on_reset = on_reset; - - half->settings.on_url = on_uri; - half->settings.on_url_complete = on_uri_complete; - - half->settings.on_status = on_status; - half->settings.on_status_complete = on_status_complete; - - half->settings.on_method = on_method; - half->settings.on_method_complete = on_method_complete; - - half->settings.on_version = on_version; - half->settings.on_version_complete = on_version_complete; - - half->settings.on_header_field = on_header_field; - half->settings.on_header_field_complete = on_header_field_complete; - - half->settings.on_header_value = on_header_value; - half->settings.on_header_value_complete = on_header_value_complete; - - half->settings.on_chunk_header = on_chunk_header; - half->settings.on_chunk_complete = on_chunk_header_complete; - - half->settings.on_headers_complete = on_headers_complete; - half->settings.on_body = on_body; - - half->error = HPE_OK; - - half->http_ev_cb = http_ev_cb; - half->is_cache_body = is_cache_body; - - half->ref_data = NULL; -} - -struct http_decoder_half * -http_decoder_half_new(http_event_cb *ev_cb, int is_cache_body, int type) -{ - struct http_decoder_half *half = CALLOC(struct http_decoder_half, 1); - assert(half); - - half->http_ev_ctx = CALLOC(struct http_event_context, 1); - http_decoder_half_init(half, ev_cb, is_cache_body, type); - - return half; -} - -void http_decoder_half_free(struct http_decoder_half *half) -{ - if (NULL == half) { - return; - } - - if (half->http_ev_ctx != NULL) { - FREE(half->http_ev_ctx); - } - - FREE(half); -} - -void http_decoder_half_reinit(struct http_decoder_half *half, int topic_id, - struct http_decoder_result_queue *queue, - struct session *sess) -{ - assert(half != NULL); - - half->http_ev_ctx->topic_id = topic_id; - half->http_ev_ctx->ref_session = sess; - half->http_ev_ctx->ref_queue = queue; -} - -int http_decoder_half_parse(struct http_decoder_half *half, - const char *data, size_t data_len) -{ - if (NULL == half || NULL == data || 0 == data_len) { - return -1; - } - - half->error = llhttp_execute(&half->parser, data, data_len); - - int ret = 0; - uint8_t type = 0; - struct http_decoder_half_data *half_data = NULL; - - switch (half->error) { - case HPE_OK: - break; - case HPE_PAUSED: - llhttp_resume(&half->parser); - break; - case HPE_PAUSED_UPGRADE: - llhttp_resume_after_upgrade(&half->parser); - ret = 0; - break; - default: - type = half->parser.type; - llhttp_init(&half->parser, type, &half->settings); - ret = -1; - break; - } - - if (ret < 0) { - // fprintf(stdout, - // "llhttp_execute parse error: %s err_reason:%s\n", - // llhttp_errno_name(half->error), half->parser.reason); - return half->error; - } - - if (half->ref_data != NULL) { - if (http_decoder_table_state(half->ref_data->table, HTTP_ITEM_URI) - == STRING_STATE_REFER) { - http_decoder_table_cache(half->ref_data->table, HTTP_ITEM_URI); - } - - if (http_decoder_table_state(half->ref_data->table, HTTP_ITEM_STATUS) - == STRING_STATE_REFER) { - http_decoder_table_cache(half->ref_data->table, HTTP_ITEM_STATUS); - } - - if (http_decoder_table_state(half->ref_data->table, HTTP_ITEM_METHOD) - == STRING_STATE_REFER) { - http_decoder_table_cache(half->ref_data->table, HTTP_ITEM_METHOD); - } - - if (http_decoder_table_state(half->ref_data->table, HTTP_ITEM_VERSION) - == STRING_STATE_REFER) { - http_decoder_table_cache(half->ref_data->table, HTTP_ITEM_VERSION); - } - - if (http_decoder_table_state(half->ref_data->table, HTTP_ITEM_HDRKEY) - == STRING_STATE_REFER) { - http_decoder_table_cache(half->ref_data->table, HTTP_ITEM_HDRKEY); - } - - if (http_decoder_table_state(half->ref_data->table, HTTP_ITEM_HDRVAL) - == STRING_STATE_REFER) { - http_decoder_table_cache(half->ref_data->table, HTTP_ITEM_HDRVAL); - } - - if (http_decoder_table_state(half->ref_data->table, HTTP_ITEM_BODY) - == STRING_STATE_REFER) { - http_decoder_table_cache(half->ref_data->table, HTTP_ITEM_BODY); - } - } - - return 0; -} - -long long http_decoder_half_trans_count(struct http_decoder_half *half) -{ - if (NULL == half) { - return 0; - } - - long long trans_cnt = half->trans_counter; - half->trans_counter = 0; - - return trans_cnt; -} - -struct http_decoder_half_data *http_decoder_half_data_new() -{ - struct http_decoder_half_data *data = - CALLOC(struct http_decoder_half_data, 1); - assert(data); - - data->table = http_decoder_table_new(); - assert(data->table); - - data->major_version = -1; - data->minor_version = -1; - data->status_code = -1; - - data->content_encoding = HTTP_CONTENT_ENCODING_NONE; - data->ref_decompress_body = NULL; - data->decompress_body_len = 0; - - return data; -} - -void http_decoder_half_data_free(struct http_decoder_half_data *data) -{ - if (NULL == data) { - return; - } - - if (data->table != NULL) { - http_decoder_table_free(data->table); - data->table = NULL; - } - - if (data->decompress != NULL) { - http_content_decompress_destroy(data->decompress); - data->decompress = NULL; - } - - FREE(data); -} - -int http_decoder_half_data_get_request_line(struct http_decoder_half_data *data, - struct http_request_line *line) -{ - if (NULL == data || NULL == line) { - return -1; - } - - http_decoder_table_get_method(data->table, &line->method); - http_decoder_table_get_uri(data->table, &line->uri); - http_decoder_table_get_version(data->table, &line->version); - - line->major_version = data->major_version; - line->minor_version = data->minor_version; - - return 0; -} - -int http_decoder_half_data_get_response_line(struct http_decoder_half_data *data, - struct http_response_line *line) -{ - if (NULL == data || NULL == line) { - return -1; - } - - http_decoder_table_get_version(data->table, &line->version); - http_decoder_table_get_status(data->table, &line->status); - - line->major_version = data->major_version; - line->minor_version = data->minor_version; - line->status_code = data->status_code; - - return 0; -} - -int http_decoder_half_data_get_header(struct http_decoder_half_data *data, - struct hstring *key, struct http_header *hdr_array, - size_t array_size) -{ - if (NULL == data) { - return -1; - } - - return http_decoder_table_get_header(data->table, key, hdr_array, array_size); -} - -int http_decoder_half_data_iter_header(struct http_decoder_half_data *data, - struct http_header *header) -{ - if (NULL == data || NULL == header) { - return -1; - } - - return http_decoder_table_iter_header(data->table, header); -} - -int http_decoder_half_data_get_raw_body(struct http_decoder_half_data *data, - struct hstring *body) -{ - if (NULL == data || NULL == body) { - return -1; - } - - return http_decoder_table_get_body(data->table, body); -} - -int http_decoder_half_data_get_decompress_body(struct http_decoder_half_data *data, - struct hstring *body) -{ - if (NULL == data || NULL == body) { - return -1; - } - - if (HTTP_CONTENT_ENCODING_NONE == data->content_encoding) { - return http_decoder_table_get_body(data->table, body); - } - - - body->str = data->ref_decompress_body; - body->str_len = data->decompress_body_len; - return 0; -} - -void http_decoder_half_data_dump(struct http_decoder_half *half) -{ - if (NULL == half || NULL == half->ref_data) { - return; - } - - http_decoder_table_dump(half->ref_data->table); -}
\ No newline at end of file diff --git a/src/http_decoder/http_decoder_half.h b/src/http_decoder/http_decoder_half.h deleted file mode 100644 index 99cc260..0000000 --- a/src/http_decoder/http_decoder_half.h +++ /dev/null @@ -1,104 +0,0 @@ -/* -********************************************************************************************** -* File: http_decoder_half.h -* Description: -* Authors: Liu WenTan <[email protected]> -* Date: 2024-01-10 -* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. -*********************************************************************************************** -*/ - - -#ifndef _HTTP_DECODER_HALF_H_ -#define _HTTP_DECODER_HALF_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include <stddef.h> - -#include "stellar/session.h" -#include "http_decoder.h" -#include "http_content_decompress.h" -#include "http_decoder_result_queue.h" - -// only one http event is fired at a time -enum http_event { - HTTP_EVENT_REQ_INIT = 1 << 1, - HTTP_EVENT_REQ_LINE = 1 << 2, - HTTP_EVENT_REQ_HDR = 1 << 3, - HTTP_EVENT_REQ_HDR_END = 1 << 4, - HTTP_EVENT_REQ_BODY_BEGIN = 1 << 5, - HTTP_EVENT_REQ_BODY_DATA = 1 << 6, - HTTP_EVENT_REQ_BODY_END = 1 << 7, - HTTP_EVENT_REQ_END = 1 << 8, - - HTTP_EVENT_RES_INIT = 1 << 9, - HTTP_EVENT_RES_LINE = 1 << 10, - HTTP_EVENT_RES_HDR = 1 << 11, - HTTP_EVENT_RES_HDR_END = 1 << 12, - HTTP_EVENT_RES_BODY_BEGIN = 1 << 13, - HTTP_EVENT_RES_BODY_DATA = 1 << 14, - HTTP_EVENT_RES_BODY_END = 1 << 15, - HTTP_EVENT_RES_END = 1 << 16, -}; - -struct http_event_context { - int topic_id; - struct session *ref_session; - struct http_decoder_result_queue *ref_queue; -}; - -struct http_decoder_half; -struct http_decoder_half_data; - -typedef void http_event_cb(enum http_event event, struct http_decoder_half_data **data, - struct http_event_context *ev_ctx); - -struct http_decoder_half * -http_decoder_half_new(http_event_cb *event_cb, int is_cache_body, int type); - -void http_decoder_half_free(struct http_decoder_half *half); - -void http_decoder_half_reinit(struct http_decoder_half *half, int topic_id, - struct http_decoder_result_queue *queue, - struct session *sess); - -int http_decoder_half_parse(struct http_decoder_half *half, - const char *data, size_t len); - -long long http_decoder_half_trans_count(struct http_decoder_half *half); - -//http decoder half data API -struct http_decoder_half_data *http_decoder_half_data_new(); - -void http_decoder_half_data_free(struct http_decoder_half_data *data); - -int http_decoder_half_data_get_request_line(struct http_decoder_half_data *data, - struct http_request_line *line); - -int http_decoder_half_data_get_response_line(struct http_decoder_half_data *data, - struct http_response_line *line); - -int http_decoder_half_data_get_header(struct http_decoder_half_data *data, - struct hstring *key, struct http_header *hdr_array, - size_t array_size); - -int http_decoder_half_data_iter_header(struct http_decoder_half_data *data, - struct http_header *header); - -int http_decoder_half_data_get_raw_body(struct http_decoder_half_data *data, - struct hstring *body); - -int http_decoder_half_data_get_decompress_body(struct http_decoder_half_data *data, - struct hstring *body); - -void http_decoder_half_data_dump(struct http_decoder_half *half); - -#ifdef __cplusplus -} -#endif - -#endif
\ No newline at end of file diff --git a/src/http_decoder/http_decoder_result_queue.c b/src/http_decoder/http_decoder_result_queue.c deleted file mode 100644 index eb7b2d1..0000000 --- a/src/http_decoder/http_decoder_result_queue.c +++ /dev/null @@ -1,155 +0,0 @@ -/* -********************************************************************************************** -* File: http_decoder_result_queue.c -* Description: -* Authors: Liuwentan <[email protected]> -* Date: 2024-01-15 -* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. -*********************************************************************************************** -*/ - -#include <assert.h> - -#include "stellar/utils.h" -#include "http_decoder_half.h" -#include "http_decoder_result_queue.h" - -struct http_decoder_result_queue * -http_decoder_result_queue_new(size_t queue_size) -{ - struct http_decoder_result_queue *queue = - CALLOC(struct http_decoder_result_queue, 1); - assert(queue); - - queue->req_index = 0; - queue->res_index = 0; - queue->queue_size = queue_size; - - queue->array = CALLOC(struct http_decoder_result, queue->queue_size); - assert(queue->array); - - return queue; -} - -void http_decoder_result_queue_free(struct http_decoder_result_queue *queue) -{ - 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(queue->array[i].req_data); - queue->array[i].req_data = NULL; - } - - if (queue->array[i].res_data != NULL) { - http_decoder_half_data_free(queue->array[i].res_data); - queue->array[i].res_data = NULL; - } - } - - FREE(queue->array); - } - - FREE(queue); -} - -void http_decoder_result_queue_inc_req_index(struct http_decoder_result_queue *queue) -{ - assert(queue); - - queue->req_index++; - queue->req_index = queue->req_index % queue->queue_size; -} - -void http_decoder_result_queue_inc_res_index(struct http_decoder_result_queue *queue) -{ - assert(queue); - - queue->res_index++; - queue->res_index = queue->res_index % queue->queue_size; -} - -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) { - return -1; - } - - assert(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; - return 0; -} - -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) { - return -1; - } - - assert(queue->array[queue->res_index].res_data == NULL); - if (queue->array[queue->res_index].res_data != NULL) { - return -1; - } - - queue->array[queue->res_index].res_data = res_data; - return 0; -} - -struct http_decoder_half_data * -http_decoder_result_queue_pop_req(struct http_decoder_result_queue *queue) -{ - if (NULL == queue) { - return NULL; - } - - struct http_decoder_half_data *req_data = - queue->array[queue->req_index].req_data; - queue->array[queue->req_index].req_data = NULL; - - return req_data; -} - -struct http_decoder_half_data * -http_decoder_result_queue_pop_res(struct http_decoder_result_queue *queue) -{ - if (NULL == queue) { - return NULL; - } - - struct http_decoder_half_data *res_data = - queue->array[queue->res_index].res_data; - queue->array[queue->res_index].res_data = NULL; - - return res_data; -} - -struct http_decoder_half_data * -http_decoder_result_queue_peek_req(struct http_decoder_result_queue *queue) -{ - if (NULL == queue) { - return NULL; - } - - assert(queue->req_index < queue->queue_size); - return queue->array[queue->req_index].req_data; -} - -struct http_decoder_half_data * -http_decoder_result_queue_peek_res(struct http_decoder_result_queue *queue) -{ - if (NULL == queue) { - return NULL; - } - - assert(queue->res_index < queue->queue_size); - return queue->array[queue->res_index].res_data; -}
\ No newline at end of file diff --git a/src/http_decoder/http_decoder_result_queue.h b/src/http_decoder/http_decoder_result_queue.h deleted file mode 100644 index eef68ba..0000000 --- a/src/http_decoder/http_decoder_result_queue.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -********************************************************************************************** -* File: http_decoder_result_queue.h -* Description: -* Authors: Liuwentan <[email protected]> -* 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_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include <stddef.h> - -#include "http_decoder_half.h" - -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 * -http_decoder_result_queue_new(size_t queue_size); - -void http_decoder_result_queue_free(struct http_decoder_result_queue *queue); - -void http_decoder_result_queue_inc_req_index(struct http_decoder_result_queue *queue); - -void http_decoder_result_queue_inc_res_index(struct http_decoder_result_queue *queue); - -struct http_decoder_half_data * -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); - -int http_decoder_result_queue_push_req(struct http_decoder_result_queue *queue, - struct http_decoder_half_data *req_data); - -int http_decoder_result_queue_push_res(struct http_decoder_result_queue *queue, - struct http_decoder_half_data *res_data); - -struct http_decoder_half_data * -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); - -#ifdef __cplusplus -} -#endif - -#endif
\ No newline at end of file diff --git a/src/http_decoder/http_decoder_string.c b/src/http_decoder/http_decoder_string.c deleted file mode 100644 index cfaeb4c..0000000 --- a/src/http_decoder/http_decoder_string.c +++ /dev/null @@ -1,193 +0,0 @@ -/* -********************************************************************************************** -* File: http_decoder_string.h -* Description: -* Authors: LuWenPeng <[email protected]> -* Date: 2022-10-31 -* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. -*********************************************************************************************** -*/ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <assert.h> - -#include "stellar/utils.h" -#include "http_decoder_utils.h" -#include "http_decoder_string.h" - -static const char *string_state_to_desc(enum string_state state) -{ - switch (state) { - case STRING_STATE_INIT: - return "init"; - break; - case STRING_STATE_REFER: - return "refer"; - break; - case STRING_STATE_CACHE: - return "cache"; - break; - case STRING_STATE_COMMIT: - return "commit"; - break; - default: - return "unknown"; - break; - } -} - -void http_decoder_string_refer(struct http_decoder_string *rstr, - const char *at, size_t length) -{ - if (NULL == rstr) { - return; - } - - switch (rstr->state) { - case STRING_STATE_INIT: - case STRING_STATE_CACHE: - rstr->refer.str = (char *)at; - rstr->refer.str_len = length; - break; - default: - abort(); - break; - } - - rstr->state = STRING_STATE_REFER; -} - -void http_decoder_string_cache(struct http_decoder_string *rstr) -{ - if (NULL == rstr) { - return; - } - - size_t length = 0; - - switch (rstr->state) { - case STRING_STATE_REFER: - if (rstr->refer.str_len > 0) { - if (NULL == rstr->cache.str) { - length = rstr->refer.str_len + 1; - rstr->cache.str = CALLOC(char, length); - } else { - length = rstr->cache.str_len + rstr->refer.str_len + 2; - rstr->cache.str = REALLOC(char, rstr->cache.str, length); - } - - memcpy(rstr->cache.str + rstr->cache.str_len, rstr->refer.str, - rstr->refer.str_len); - rstr->cache.str_len += rstr->refer.str_len; - - rstr->refer.str = NULL; - rstr->refer.str_len = 0; - } - break; - default: - abort(); - break; - } - - rstr->state = STRING_STATE_CACHE; -} - -void http_decoder_string_commit(struct http_decoder_string *rstr) -{ - if (NULL == rstr) { - return; - } - - switch (rstr->state) { - case STRING_STATE_REFER: - if (rstr->cache.str_len) { - http_decoder_string_cache(rstr); - - rstr->commit.str = rstr->cache.str; - rstr->commit.str_len = rstr->cache.str_len; - // not overwrite rstr->cache.str - } else { - rstr->commit.str = rstr->refer.str; - rstr->commit.str_len = rstr->refer.str_len; - - rstr->refer.str = NULL; - rstr->refer.str_len = 0; - } - break; - case STRING_STATE_CACHE: - rstr->commit.str = rstr->cache.str; - rstr->commit.str_len = rstr->cache.str_len; - // not overwrite rstr->cache.str - break; - default: - //abort(); - break; - } - - rstr->state = STRING_STATE_COMMIT; -} - -void http_decoder_string_reset(struct http_decoder_string *rstr) -{ - assert(rstr); - - switch (rstr->state) { - case STRING_STATE_INIT: - case STRING_STATE_REFER: - case STRING_STATE_CACHE: - case STRING_STATE_COMMIT: - FREE(rstr->cache.str); - memset(rstr, 0, sizeof(struct http_decoder_string)); - break; - default: - abort(); - break; - } - - rstr->state = STRING_STATE_INIT; -} - -enum string_state http_decoder_string_state(struct http_decoder_string *rstr) -{ - return rstr->state; -} - -int http_decoder_string_get(struct http_decoder_string *rstr, struct hstring *out) -{ - if (NULL == rstr || NULL == out) { - return -1; - } - - if (http_decoder_string_state(rstr) == STRING_STATE_COMMIT) { - out->str = rstr->commit.str; - out->str_len = rstr->commit.str_len; - } else { - out->str = NULL; - out->str_len = 0; - } - - return 0; -} - -void http_decoder_string_dump(struct http_decoder_string *rstr, const char *desc) -{ - if (NULL == rstr) { - return; - } - - char *refer_str = safe_dup(rstr->refer.str, rstr->refer.str_len); - char *cache_str = safe_dup(rstr->cache.str, rstr->cache.str_len); - char *commit_str = safe_dup(rstr->commit.str, rstr->commit.str_len); - - printf("%s: state: %s, refer: {len: %02zu, str: %s}, cache: {len: %02zu, str: %s}, commit: {len: %02zu, str: %s}\n", - desc, string_state_to_desc(rstr->state), - rstr->refer.str_len, refer_str, - rstr->cache.str_len, cache_str, - rstr->commit.str_len, commit_str); - - FREE(refer_str); - FREE(cache_str); - FREE(commit_str); -}
\ No newline at end of file diff --git a/src/http_decoder/http_decoder_string.h b/src/http_decoder/http_decoder_string.h deleted file mode 100644 index 804a7ff..0000000 --- a/src/http_decoder/http_decoder_string.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -********************************************************************************************** -* File: http_decoder_string.h -* Description: -* Authors: LuWenPeng <[email protected]> -* Date: 2022-10-31 -* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. -*********************************************************************************************** -*/ - -#ifndef _HTTP_DECODER_STRING_H_ -#define _HTTP_DECODER_STRING_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include "http_decoder.h" - - -enum string_state { - STRING_STATE_INIT, - STRING_STATE_REFER, - STRING_STATE_CACHE, - STRING_STATE_COMMIT, -}; - -/* state transition diagram - * +----------+ - * | | - * \|/ | - * +------+ | - * | init | | - * +------+ | - * | | - * +---->| | - * | \|/ | - * | +-------+ | - * | | refer |--+ | - * | +-------+ | | - * | | | | - * | \|/ | | - * | +-------+ | | - * +--| cache | | | - * +-------+ | | - * | | | - * |<------+ | - * \|/ | - * +--------+ | - * | commit | | - * +--------+ | - * | | - * \|/ | - * +--------+ | - * | reset |----+ - * +--------+ - */ - - -//http decoder string -struct http_decoder_string { - struct hstring refer; // shallow copy - struct hstring cache; // deep copy - struct hstring commit; - - enum string_state state; -}; - -void http_decoder_string_refer(struct http_decoder_string *rstr, - const char *at, size_t length); - -void http_decoder_string_cache(struct http_decoder_string *rstr); - -void http_decoder_string_commit(struct http_decoder_string *rstr); - -void http_decoder_string_reset(struct http_decoder_string *rstr); - -enum string_state http_decoder_string_state(struct http_decoder_string *rstr); - -int http_decoder_string_get(struct http_decoder_string *rstr, struct hstring *out); - -void http_decoder_string_dump(struct http_decoder_string *rstr, const char *desc); - -#ifdef __cplusplus -} -#endif - -#endif
\ No newline at end of file diff --git a/src/http_decoder/http_decoder_table.c b/src/http_decoder/http_decoder_table.c deleted file mode 100644 index 300994d..0000000 --- a/src/http_decoder/http_decoder_table.c +++ /dev/null @@ -1,443 +0,0 @@ -/* -********************************************************************************************** -* File: http_decoder_table.c -* Description: -* Authors: LuWenPeng <[email protected]> -* Date: 2022-10-31 -* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. -*********************************************************************************************** -*/ - - -#include <assert.h> -#include <stdlib.h> -#include <string.h> - -#include "http_decoder_table.h" -#include "http_decoder.h" -#include "http_decoder_string.h" -#include "stellar/utils.h" - -#define MAX_HEADER_SIZE 16 - - -struct http_decoder_header { - struct http_decoder_string key; - struct http_decoder_string val; -}; - -struct http_decoder_table { - struct http_decoder_string uri; - struct http_decoder_string status; - struct http_decoder_string method; - struct http_decoder_string version; - struct http_decoder_string body; - - size_t header_size; - size_t header_index; - size_t header_iter; - struct http_decoder_header *headers; -}; - -struct http_decoder_table *http_decoder_table_new() -{ - struct http_decoder_table *table = CALLOC(struct http_decoder_table, 1); - assert(table); - - table->header_index = 0; - table->header_size = MAX_HEADER_SIZE; - table->headers = CALLOC(struct http_decoder_header, table->header_size); - - return table; -} - -void http_decoder_table_free(struct http_decoder_table *table) -{ - if (NULL == table) { - return; - } - - if (table->uri.cache.str != NULL) { - FREE(table->uri.cache.str); - } - - if (table->status.cache.str != NULL) { - FREE(table->status.cache.str); - } - - if (table->method.cache.str != NULL) { - FREE(table->method.cache.str); - } - - if (table->version.cache.str != NULL) { - FREE(table->version.cache.str); - } - - if (table->body.cache.str != NULL) { - FREE(table->body.cache.str); - } - - if (table->headers != NULL) { - for (size_t i = 0; i < table->header_size; i++) { - if (table->headers[i].key.cache.str != NULL) { - FREE(table->headers[i].key.cache.str); - } - - if (table->headers[i].val.cache.str != NULL) { - FREE(table->headers[i].val.cache.str); - } - } - - FREE(table->headers); - } - - FREE(table); -} - -enum string_state -http_decoder_table_state(struct http_decoder_table *table, enum http_item type) -{ - if (NULL == table) { - return STRING_STATE_INIT; - } - - struct http_decoder_header *header = NULL; - enum string_state state = STRING_STATE_INIT; - assert(table); - - switch (type) { - case HTTP_ITEM_URI: - state = http_decoder_string_state(&table->uri); - break; - case HTTP_ITEM_STATUS: - state = http_decoder_string_state(&table->status); - break; - case HTTP_ITEM_METHOD: - state = http_decoder_string_state(&table->method); - break; - case HTTP_ITEM_VERSION: - state = http_decoder_string_state(&table->version); - break; - case HTTP_ITEM_HDRKEY: - assert(table->header_index < table->header_size); - header = &table->headers[table->header_index]; - state = http_decoder_string_state(&header->key); - break; - case HTTP_ITEM_HDRVAL: - assert(table->header_index < table->header_size); - header = &table->headers[table->header_index]; - state = http_decoder_string_state(&header->val); - break; - case HTTP_ITEM_BODY: - state = http_decoder_string_state(&table->body); - break; - default: - abort(); - break; - } - - return state; -} - -void http_decoder_table_refer(struct http_decoder_table *table, enum http_item type, - const char *at, size_t len) -{ - if (NULL == table) { - return; - } - - struct http_decoder_header *header = NULL; - assert(table); - - switch (type) { - case HTTP_ITEM_URI: - http_decoder_string_refer(&table->uri, at, len); - break; - case HTTP_ITEM_STATUS: - http_decoder_string_refer(&table->status, at, len); - break; - case HTTP_ITEM_METHOD: - http_decoder_string_refer(&table->method, at, len); - break; - case HTTP_ITEM_VERSION: - http_decoder_string_refer(&table->version, at, len); - break; - case HTTP_ITEM_HDRKEY: - assert(table->header_index < table->header_size); - header = &table->headers[table->header_index]; - http_decoder_string_refer(&header->key, at, len); - break; - case HTTP_ITEM_HDRVAL: - assert(table->header_index < table->header_size); - header = &table->headers[table->header_index]; - http_decoder_string_refer(&header->val, at, len); - break; - case HTTP_ITEM_BODY: - http_decoder_string_refer(&table->body, at, len); - break; - default: - abort(); - break; - } -} - -void http_decoder_table_cache(struct http_decoder_table *table, enum http_item type) -{ - if (NULL == table) { - return; - } - - struct http_decoder_header *header = NULL; - assert(table); - - switch (type) { - case HTTP_ITEM_URI: - http_decoder_string_cache(&table->uri); - break; - case HTTP_ITEM_STATUS: - http_decoder_string_cache(&table->status); - break; - case HTTP_ITEM_METHOD: - http_decoder_string_cache(&table->method); - break; - case HTTP_ITEM_VERSION: - http_decoder_string_cache(&table->version); - break; - case HTTP_ITEM_HDRKEY: - assert(table->header_index < table->header_size); - header = &table->headers[table->header_index]; - http_decoder_string_cache(&header->key); - break; - case HTTP_ITEM_HDRVAL: - assert(table->header_index < table->header_size); - header = &table->headers[table->header_index]; - http_decoder_string_cache(&header->val); - break; - case HTTP_ITEM_BODY: - http_decoder_string_cache(&table->body); - break; - default: - abort(); - break; - } -} - -void http_decoder_table_commit(struct http_decoder_table *table, enum http_item type) -{ - if (NULL == table) { - return; - } - - struct http_decoder_header *header = NULL; - assert(table); - - switch (type) { - case HTTP_ITEM_URI: - http_decoder_string_commit(&table->uri); - break; - case HTTP_ITEM_STATUS: - http_decoder_string_commit(&table->status); - break; - case HTTP_ITEM_METHOD: - http_decoder_string_commit(&table->method); - break; - case HTTP_ITEM_VERSION: - http_decoder_string_commit(&table->version); - break; - case HTTP_ITEM_HDRKEY: - assert(table->header_index < table->header_size); - header = &table->headers[table->header_index]; - http_decoder_string_commit(&header->key); - break; - case HTTP_ITEM_HDRVAL: - header = &table->headers[table->header_index]; - http_decoder_string_commit(&header->val); - // inc index - if ((table->header_index + 1) >= table->header_size) { - table->headers = REALLOC(struct http_decoder_header, table->headers, - table->header_size * 2); - table->header_size *= 2; - for (size_t i = table->header_index + 1; i < table->header_size; i++) { - header = &table->headers[i]; - memset(header, 0, sizeof(struct http_decoder_header)); - } - } - table->header_index++; - break; - case HTTP_ITEM_BODY: - http_decoder_string_commit(&table->body); - break; - default: - abort(); - break; - } -} - -void http_decoder_table_reset(struct http_decoder_table *table, enum http_item type) -{ - if (NULL == table) { - return; - } - - struct http_decoder_header *header = NULL; - assert(table); - - switch (type) { - case HTTP_ITEM_URI: - http_decoder_string_reset(&table->uri); - break; - case HTTP_ITEM_STATUS: - http_decoder_string_reset(&table->status); - break; - case HTTP_ITEM_METHOD: - http_decoder_string_reset(&table->method); - break; - case HTTP_ITEM_VERSION: - http_decoder_string_reset(&table->version); - break; - case HTTP_ITEM_HDRKEY: - header = &table->headers[table->header_index]; - http_decoder_string_reset(&header->key); - break; - case HTTP_ITEM_HDRVAL: - header = &table->headers[table->header_index]; - http_decoder_string_reset(&header->val); - break; - case HTTP_ITEM_BODY: - http_decoder_string_reset(&table->body); - break; - default: - abort(); - break; - } -} - -void http_decoder_table_dump(struct http_decoder_table *table) -{ - if (NULL == table) { - return; - } - - http_decoder_string_dump(&table->uri, "uri"); - http_decoder_string_dump(&table->status, "status"); - http_decoder_string_dump(&table->method, "method"); - http_decoder_string_dump(&table->version, "version"); - http_decoder_string_dump(&table->body, "body"); - - for (size_t i = 0; i < table->header_size; i++) { - struct http_decoder_header *header = &table->headers[i]; - if (NULL == header) { - continue; - } - - http_decoder_string_dump(&header->key, "key"); - http_decoder_string_dump(&header->val, "val"); - } -} - -int http_decoder_table_get_uri(struct http_decoder_table *table, struct hstring *out) -{ - if (NULL == table || NULL == out) { - return -1; - } - - return http_decoder_string_get(&table->uri, out); -} - -int http_decoder_table_get_method(struct http_decoder_table *table, struct hstring *out) -{ - if (NULL == table || NULL == out) { - return -1; - } - - return http_decoder_string_get(&table->method, out); -} - -int http_decoder_table_get_status(struct http_decoder_table *table, struct hstring *out) -{ - if (NULL == table || NULL == out) { - return -1; - } - - return http_decoder_string_get(&table->status, out); -} - -int http_decoder_table_get_version(struct http_decoder_table *table, struct hstring *out) -{ - if (NULL == table || NULL == out) { - return -1; - } - - return http_decoder_string_get(&table->version, out); -} - -int http_decoder_table_get_body(struct http_decoder_table *table, struct hstring *out) -{ - if (NULL == table || NULL == out) { - return -1; - } - - return http_decoder_string_get(&table->body, out); -} - -int http_decoder_table_get_header(struct http_decoder_table *table, struct hstring *key, - struct http_header *hdr_array, size_t array_size) -{ - if (NULL == table || NULL == key->str || 0 == key->str_len) { - return 0; - } - - int header_cnt = 0; - for (int i = 0; i < table->header_size && header_cnt < array_size; i++) { - struct http_decoder_header *tmp_header = &table->headers[i]; - if (NULL == tmp_header) { - continue; - } - - if (http_decoder_string_state(&tmp_header->key) == STRING_STATE_COMMIT - && http_decoder_string_state(&tmp_header->val) == STRING_STATE_COMMIT) { - struct hstring tmp_key; - http_decoder_string_get(&tmp_header->key, &tmp_key); - - if (tmp_key.str_len == key->str_len - && (0 == strncasecmp(tmp_key.str, key->str, key->str_len))) { - http_decoder_string_get(&tmp_header->key, &hdr_array[header_cnt].key); - http_decoder_string_get(&tmp_header->val, &hdr_array[header_cnt].val); - header_cnt++; - } - } - } - - return header_cnt; -} - -int http_decoder_table_iter_header(struct http_decoder_table *table, - struct http_header *hdr) -{ - if (NULL == table || NULL == hdr) { - return -1; - } - - if (table->header_iter >= table->header_size) { - return 0; - } - - struct http_decoder_header *tmp_header = &table->headers[table->header_iter++]; - 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_get(&tmp_header->key, &hdr->key); - http_decoder_string_get(&tmp_header->val, &hdr->val); - return 1; - } - } - - hdr->key.str = NULL; - hdr->key.str_len = 0; - - hdr->val.str = NULL; - hdr->val.str_len = 0; - - return 0; -}
\ No newline at end of file diff --git a/src/http_decoder/http_decoder_table.h b/src/http_decoder/http_decoder_table.h deleted file mode 100644 index 19a4811..0000000 --- a/src/http_decoder/http_decoder_table.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -********************************************************************************************** -* File: http_decoder_table.h -* Description: -* Authors: LuWenPeng <[email protected]> -* Date: 2022-10-31 -* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. -*********************************************************************************************** -*/ - - -#ifndef _HTTP_DECODER_TABLE_H_ -#define _HTTP_DECODER_TABLE_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stddef.h> - -#include "http_decoder.h" -#include "http_decoder_string.h" - - -enum http_item { - HTTP_ITEM_URI = 0x01, - HTTP_ITEM_STATUS = 0x02, - HTTP_ITEM_METHOD = 0x03, - HTTP_ITEM_VERSION = 0x04, - HTTP_ITEM_HDRKEY = 0x05, - HTTP_ITEM_HDRVAL = 0x06, - HTTP_ITEM_BODY = 0x07, -}; - -struct http_decoder_table; - -struct http_decoder_table *http_decoder_table_new(); - -void http_decoder_table_free(struct http_decoder_table *table); - -enum string_state -http_decoder_table_state(struct http_decoder_table *table, enum http_item type); - -void http_decoder_table_refer(struct http_decoder_table *table, enum http_item type, - const char *at, size_t len); - -void http_decoder_table_cache(struct http_decoder_table *table, enum http_item type); - -void http_decoder_table_commit(struct http_decoder_table *table, enum http_item type); - -void http_decoder_table_reset(struct http_decoder_table *table, enum http_item type); - -void http_decoder_table_dump(struct http_decoder_table *table); - -int http_decoder_table_get_uri(struct http_decoder_table *table, struct hstring *out); - -int http_decoder_table_get_method(struct http_decoder_table *table, struct hstring *out); - -int http_decoder_table_get_status(struct http_decoder_table *table, struct hstring *out); - -int http_decoder_table_get_version(struct http_decoder_table *table, struct hstring *out); - -int http_decoder_table_get_body(struct http_decoder_table *table, struct hstring *out); - -int http_decoder_table_get_header(struct http_decoder_table *table, struct hstring *key, - struct http_header *hdr_array, size_t array_size); - -int http_decoder_table_iter_header(struct http_decoder_table *table, struct http_header *hdr); - -#ifdef __cplusplus -} -#endif - -#endif
\ No newline at end of file diff --git a/src/http_decoder/http_decoder_utils.c b/src/http_decoder/http_decoder_utils.c deleted file mode 100644 index a5dfbe1..0000000 --- a/src/http_decoder/http_decoder_utils.c +++ /dev/null @@ -1,25 +0,0 @@ -/* -********************************************************************************************** -* File: http_decoder_utils.c -* Description: -* Authors: LuWenPeng <[email protected]> -* Date: 2022-10-31 -* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. -*********************************************************************************************** -*/ - -#include <string.h> - -#include "stellar/utils.h" - -char *safe_dup(const char *str, size_t len) -{ - if (str == NULL || len == 0) { - return NULL; - } - - char *dup = CALLOC(char, len + 1); - memcpy(dup, str, len); - - return dup; -}
\ No newline at end of file diff --git a/src/http_decoder/http_decoder_utils.h b/src/http_decoder/http_decoder_utils.h deleted file mode 100644 index 9c031a3..0000000 --- a/src/http_decoder/http_decoder_utils.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -********************************************************************************************** -* File: http_decoder_utils.h -* Description: -* Authors: LuWenPeng <[email protected]> -* Date: 2022-10-31 -* Copyright: (c) Since 2022 Geedge Networks, Ltd. All rights reserved. -*********************************************************************************************** -*/ - - -#ifndef _HTTP_DECODER_UTILS_H_ -#define _HTTP_DECODER_UTILS_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include <stdlib.h> -#include <stdio.h> - - -char *safe_dup(const char *str, size_t len); - -/****************************************************************************** - * Logger - ******************************************************************************/ - -enum http_decoder_log_level { - DEBUG = 0x11, - WARN = 0x12, - INFO = 0x13, - ERROR = 0x14, -}; - -#ifndef http_decoder_log -#define http_decoder_log(level, format, ...) \ - { \ - switch (level) \ - { \ - case DEBUG: \ - fprintf(stdout, "HTTP_DECODER [DEBUG] " format "\n", ##__VA_ARGS__); \ - fflush(stdout); \ - break; \ - case WARN: \ - fprintf(stdout, "HTTP_DECODER [WARN] " format "\n", ##__VA_ARGS__); \ - fflush(stdout); \ - break; \ - case INFO: \ - fprintf(stdout, "HTTP_DECODER [INFO] " format "\n", ##__VA_ARGS__); \ - fflush(stdout); \ - break; \ - case ERROR: \ - fprintf(stderr, "HTTP_DECODER [ERROR] " format "\n", ##__VA_ARGS__); \ - fflush(stderr); \ - break; \ - } \ - } -#endif - -#ifdef __cplusplus -} -#endif - -#endif
\ No newline at end of file diff --git a/src/http_decoder/version.map b/src/http_decoder/version.map deleted file mode 100644 index a0ba8a4..0000000 --- a/src/http_decoder/version.map +++ /dev/null @@ -1,7 +0,0 @@ -VERS_3.0{ -global: - extern "C" { - http_message_*; - }; -local: *; -};
\ No newline at end of file diff --git a/src/plugin_manager/CMakeLists.txt b/src/plugin_manager/CMakeLists.txt index cc17074..ed3aff9 100644 --- a/src/plugin_manager/CMakeLists.txt +++ b/src/plugin_manager/CMakeLists.txt @@ -4,4 +4,4 @@ include_directories(${CMAKE_SOURCE_DIR}/deps) include_directories(${CMAKE_SOURCE_DIR}/src/stellar_on_sapp) add_library(plugin_manager STATIC plugin_manager.c) -target_link_libraries(plugin_manager toml bitmap) +target_link_libraries(plugin_manager toml bitmap)
\ No newline at end of file diff --git a/src/plugin_manager/plugin_manager.c b/src/plugin_manager/plugin_manager.c index 744b160..09cee97 100644 --- a/src/plugin_manager/plugin_manager.c +++ b/src/plugin_manager/plugin_manager.c @@ -16,13 +16,22 @@ #include <threads.h> -struct per_thread_exdata_array; -struct per_thread_mq_array; + +struct per_thread_exdata_array +{ + struct stellar_exdata *exdata_array; +}; + +struct stellar_message; +struct per_thread_mq_array +{ + struct stellar_message *mq; +}; struct plugin_manger_per_thread_data { - struct per_thread_exdata_array *per_thread_pkt_exdata_array; - struct per_thread_mq_array *per_thread_pkt_mq_array; + struct per_thread_exdata_array per_thread_pkt_exdata_array; + struct per_thread_mq_array per_thread_pkt_mq_array; }; struct plugin_manager_schema @@ -48,11 +57,7 @@ struct plugin_manager_schema struct plugin_manger_per_thread_data *per_thread_data; }; -struct stellar_message; -struct per_thread_mq_array -{ - struct stellar_message *mq; -}; + struct stellar_exdata @@ -60,10 +65,6 @@ struct stellar_exdata void *exdata; }; -struct per_thread_exdata_array -{ - struct stellar_exdata *exdata_array; -}; struct stellar_exdata_schema @@ -248,18 +249,32 @@ PLUGIN_SPEC_LOAD_ERROR: return NULL; } -static struct per_thread_exdata_array *per_thread_packet_exdata_arrary_new(struct stellar *st, struct plugin_manager_schema *plug_mgr); -static struct per_thread_mq_array *per_thread_mq_arrary_new(struct stellar *st); -static struct plugin_manger_per_thread_data *plugin_manager_per_thread_data_new(struct stellar *st, struct plugin_manager_schema *plug_mgr) +static struct plugin_manger_per_thread_data *plugin_manager_per_thread_data_new(struct stellar *st) { - if(st == NULL || plug_mgr == NULL)return NULL; - struct plugin_manger_per_thread_data *per_thread_data = CALLOC(struct plugin_manger_per_thread_data, 1); - per_thread_data->per_thread_pkt_exdata_array = per_thread_packet_exdata_arrary_new(st, plug_mgr); - per_thread_data->per_thread_pkt_mq_array = per_thread_mq_arrary_new(st); + if(st == NULL)return NULL; + int thread_num=stellar_get_worker_thread_num(st); + struct plugin_manger_per_thread_data *per_thread_data = CALLOC(struct plugin_manger_per_thread_data, thread_num); return per_thread_data; } + +static void plugin_manager_per_thread_data_free(struct plugin_manger_per_thread_data *per_thread_data, struct stellar *st) +{ + if(per_thread_data == NULL || st == NULL)return; + int thread_num=stellar_get_worker_thread_num(st); + struct plugin_manger_per_thread_data *p_data; + for (int i = 0; i < thread_num; i++) + { + p_data=per_thread_data+i; + if(p_data->per_thread_pkt_exdata_array.exdata_array)FREE(p_data->per_thread_pkt_exdata_array.exdata_array); + if(p_data->per_thread_pkt_mq_array.mq)FREE(p_data->per_thread_pkt_mq_array.mq); + } + FREE(per_thread_data); + return; +} + + struct plugin_manager_schema *plugin_manager_init(struct stellar *st, const char *plugin_spec_file_path) { int spec_num; @@ -294,21 +309,10 @@ struct plugin_manager_schema *plugin_manager_init(struct stellar *st, const char } } FREE(specs); - plug_mgr->per_thread_data = plugin_manager_per_thread_data_new(st, plug_mgr); + plug_mgr->per_thread_data = plugin_manager_per_thread_data_new(st); return plug_mgr; } -static void per_thread_packet_exdata_arrary_free(struct stellar *st, struct per_thread_exdata_array *exdata_array); -static void per_thread_mq_arrary_free(struct per_thread_mq_array *mq_array); - -static void plugin_manager_per_thread_data_free(struct plugin_manger_per_thread_data *per_thread_data, struct stellar *st) -{ - if(per_thread_data == NULL || st == NULL)return; - per_thread_packet_exdata_arrary_free(st, per_thread_data->per_thread_pkt_exdata_array); - per_thread_mq_arrary_free(per_thread_data->per_thread_pkt_mq_array); - FREE(per_thread_data); - return; -} void plugin_manager_exit(struct plugin_manager_schema *plug_mgr) { @@ -436,43 +440,25 @@ void *stellar_exdata_get(UT_array *exdata_schema, struct stellar_exdata *exdata_ * PACKET EXDATA * *******************************/ -static struct per_thread_exdata_array *per_thread_packet_exdata_arrary_new(struct stellar *st, struct plugin_manager_schema *plug_mgr) -{ - if(st == NULL || plug_mgr == NULL || plug_mgr->packet_exdata_schema_array == NULL )return NULL; - int thread_num=stellar_get_worker_thread_num(st); - struct per_thread_exdata_array *per_thread_pkt_exdata_array = CALLOC(struct per_thread_exdata_array, thread_num); - unsigned int len=utarray_len(plug_mgr->packet_exdata_schema_array); - for (int i = 0; i < thread_num; i++) - { - (per_thread_pkt_exdata_array+i)->exdata_array = CALLOC(struct stellar_exdata, len); - } - return per_thread_pkt_exdata_array; -} - -static void per_thread_packet_exdata_arrary_free(struct stellar *st, struct per_thread_exdata_array *exdata_array) -{ - if(st == NULL || exdata_array == NULL)return; - int thread_num=stellar_get_worker_thread_num(st); - for (int i = 0; i < thread_num; i++) - { - FREE((exdata_array+i)->exdata_array); - } - FREE(exdata_array); - return; -} static struct stellar_exdata *per_thread_packet_exdata_arrary_get(struct plugin_manager_schema *plug_mgr) { if(plug_mgr==NULL || plug_mgr->packet_exdata_schema_array == NULL)return NULL; int tid=stellar_get_current_thread_id(plug_mgr->st); - return (plug_mgr->per_thread_data->per_thread_pkt_exdata_array+tid)->exdata_array; + if((plug_mgr->per_thread_data+tid)->per_thread_pkt_exdata_array.exdata_array == NULL) + { + unsigned int len = utarray_len(plug_mgr->packet_exdata_schema_array); + (plug_mgr->per_thread_data+tid)->per_thread_pkt_exdata_array.exdata_array = CALLOC(struct stellar_exdata, len); + } + return (plug_mgr->per_thread_data+tid)->per_thread_pkt_exdata_array.exdata_array; } static void per_thread_packet_exdata_arrary_clean(struct plugin_manager_schema *plug_mgr, struct packet *pkt) { - if(plug_mgr==NULL || plug_mgr->packet_exdata_schema_array == NULL || plug_mgr->per_thread_data->per_thread_pkt_exdata_array == NULL)return; + if(plug_mgr==NULL || plug_mgr->packet_exdata_schema_array == NULL)return; unsigned int len=utarray_len(plug_mgr->packet_exdata_schema_array); struct stellar_exdata *per_thread_pkt_exdata_arrary = per_thread_packet_exdata_arrary_get(plug_mgr); + if(per_thread_pkt_exdata_arrary == NULL)return; for (unsigned int i = 0; i < len; i++) { void *exdata = (per_thread_pkt_exdata_arrary + i)->exdata; @@ -656,20 +642,6 @@ UT_icd stellar_mq_subscriber_info_icd = {sizeof(struct stellar_mq_subscriber_inf * PACKET MQ * *******************************/ -static struct per_thread_mq_array *per_thread_mq_arrary_new(struct stellar *st) -{ - if(st == NULL)return NULL; - int thread_num=stellar_get_worker_thread_num(st); - struct per_thread_mq_array *per_thread_pkt_mq_array = CALLOC(struct per_thread_mq_array, thread_num); - return per_thread_pkt_mq_array; -} - -static void per_thread_mq_arrary_free(struct per_thread_mq_array *mq_array) -{ - if(mq_array == NULL)return; - FREE(mq_array); - return; -} int stellar_packet_mq_create_topic(struct stellar *st, const char *topic_name, packet_msg_free_cb_func *msg_free_cb, void *msg_free_arg) { @@ -753,7 +725,7 @@ int packet_mq_publish_message(struct packet *pkt, int topic_id, void *msg) struct plugin_manager_schema *plug_mgr = stellar_plugin_manager_schema_get(st); assert(plug_mgr); int tid = stellar_get_current_thread_id(st); - return stellar_mq_publish_message(topic_id, msg, plug_mgr->packet_mq_schema_array, &(plug_mgr->per_thread_data->per_thread_pkt_mq_array+tid)->mq); + return stellar_mq_publish_message(topic_id, msg, plug_mgr->packet_mq_schema_array, &((plug_mgr->per_thread_data+tid)->per_thread_pkt_mq_array.mq)); } static void plugin_manager_packet_message_dispatch(struct packet *pkt) @@ -768,7 +740,7 @@ static void plugin_manager_packet_message_dispatch(struct packet *pkt) int tid = stellar_get_current_thread_id(st); - struct stellar_message **mq= &(plug_mgr->per_thread_data->per_thread_pkt_mq_array+tid)->mq; + struct stellar_message **mq= &((plug_mgr->per_thread_data+tid)->per_thread_pkt_mq_array.mq); struct stellar_message *mq_elt=NULL, *mq_tmp=NULL; struct stellar_mq_subscriber *sub_elt, *sub_tmp; diff --git a/src/stellar_on_sapp/stellar_on_sapp_api.c b/src/stellar_on_sapp/stellar_on_sapp_api.c index b40a246..ed10683 100644 --- a/src/stellar_on_sapp/stellar_on_sapp_api.c +++ b/src/stellar_on_sapp/stellar_on_sapp_api.c @@ -49,7 +49,6 @@ inline struct plugin_manager_schema * stellar_plugin_manager_schema_get(struct s inline int stellar_plugin_manager_schema_set(struct stellar *st, struct plugin_manager_schema *pm) { - if(st->plug_mgr)return -1; st->plug_mgr=pm; return 0; } |
