diff options
| author | lijia <[email protected]> | 2024-05-24 22:47:32 +0800 |
|---|---|---|
| committer | lijia <[email protected]> | 2024-06-03 11:08:06 +0800 |
| commit | 1c232f0176c43c93c3e787ac83f3573bf42c58f1 (patch) | |
| tree | 734c31a97ec38847972b70a18ec075fd415bb5f6 /test/http_decoder_perf_plug.cpp | |
| parent | 22d071e23ff423242f51dce2eab1477b5fb9d106 (diff) | |
Adapt to stellar2.0;update API,add HDR_END,BODY_END,TRANSACTION_NEW,FREE msg.v2.0.2
Diffstat (limited to 'test/http_decoder_perf_plug.cpp')
| -rw-r--r-- | test/http_decoder_perf_plug.cpp | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/test/http_decoder_perf_plug.cpp b/test/http_decoder_perf_plug.cpp new file mode 100644 index 0000000..f588683 --- /dev/null +++ b/test/http_decoder_perf_plug.cpp @@ -0,0 +1,138 @@ +#include <stdio.h> +#include <time.h> +#include <unistd.h> +#include <assert.h> +#include <string.h> + +#ifdef __cplusplus +extern "C" +{ +#include "http_decoder_inc.h" +#include "cJSON.h" +} +#endif + +#define MAX_KEY_STR_LEN 2048 + +static int g_result_count = 0; +static int g_header_count = 1; +static int g_exdata_idx = -1; +static int g_topic_id = -1; +static int g_plugin_id = -1; + +#define DEBUG_PRINT(fmt, ...) ///printf(fmt, ##__VA_ARGS__) + +extern "C" void http_decoder_perf_entry(struct session *sess, int topic_id, const void *raw_msg, void *per_session_ctx, void *plugin_env) +// extern "C" int http_decoder_perf_entry(struct session *sess, int topic_id, const void *data, void *cb_arg) +{ + struct http_request_line req_line = {0}; + struct http_response_line res_line = {0}; + struct http_header header = {0}; + struct hstring url = {0}; + struct hstring body = {0}; + struct http_message *msg = (struct http_message *)raw_msg; + enum http_message_type msg_type = http_message_type_get(msg); + void *ret1, *ret2; + + switch (msg_type) + { + case HTTP_MESSAGE_REQ_LINE: + DEBUG_PRINT("---------------------------------------------------------------\n"); + http_message_get_request_line(msg, &req_line); + if (req_line.uri.str) + { + DEBUG_PRINT("req_line.method.str: %.*s\n", req_line.method.str_len, req_line.method.str); + ret1 = memmem(req_line.method.str, req_line.method.str_len, "PUT", 3); + DEBUG_PRINT("req_line.version.str: %.*s\n", req_line.version.str_len, req_line.version.str); + } + break; + case HTTP_MESSAGE_REQ_HEADER: + while (http_message_header_next(msg, &header) >= 0) + { + ret1 = memmem(header.key.str, header.key.str_len, "key", 3); + ret2 = memmem(header.val.str, header.val.str_len, "val", 3); + DEBUG_PRINT("REQ header: %.*s : %.*s\n", (int)header.key.str_len, header.key.str, (int)header.val.str_len, header.val.str); + } + http_message_get_url(msg, &url); + if(url.str && url.str_len){ + DEBUG_PRINT("URL: %.*s\n", url.str_len, url.str); + } + break; + case HTTP_MESSAGE_REQ_BODY: + // http_message_get_request_raw_body(msg, &body); + // output_http_body(&body, 0); + http_message_get_decompress_body(msg, &body); + // output_http_body(&body, 1); + ret1 = memmem(body.str, body.str_len, "</html>", 7); + break; + case HTTP_MESSAGE_RES_LINE: + http_message_get_response_line(msg, &res_line); + ret1 = memmem(res_line.status.str, res_line.status.str_len, "OK", 2); + DEBUG_PRINT("res_line.status.str: %.*s\n", (int)res_line.status.str_len, res_line.status.str); + break; + case HTTP_MESSAGE_RES_HEADER: + while (http_message_header_next(msg, &header) >= 0) + { + ret1 = memmem(header.key.str, header.key.str_len, "key", 3); + ret2 = memmem(header.val.str, header.val.str_len, "val", 3); + DEBUG_PRINT("RES header: %.*s : %.*s\n", (int)header.key.str_len, header.key.str, (int)header.val.str_len, header.val.str); + } + break; + case HTTP_MESSAGE_RES_BODY: + http_message_get_raw_body(msg, &body); + DEBUG_PRINT("res raw body: %.*s\n", body.str_len, body.str); + // output_http_body(&body, 0); + http_message_get_decompress_body(msg, &body); + // output_http_body(&body, 1); + ret1 = memmem(body.str, body.str_len, "</html>", 7); + DEBUG_PRINT("res unzip body: %.*s\n", body.str_len, body.str); + DEBUG_PRINT("---------------------------------------------------------------\n"); + break; + + // to do: check payload + default: + break; + } + return; +} + +static on_session_msg_cb_func*g_entry_fun = &http_decoder_perf_entry; + +static void http_decoder_test_exdata_free(struct session *sess, int idx, void *ex_ptr, void *arg) +{ + return; +} + +extern "C" void *http_decoder_perf_init(struct stellar *st) +{ + g_plugin_id = stellar_session_plugin_register(st, NULL, NULL, NULL); + g_exdata_idx = stellar_session_exdata_new_index(st, "HTTP_DECODER_REQ_TEST", + http_decoder_test_exdata_free, + NULL); + if (g_exdata_idx < 0) + { + printf("[%s:%d]: can't get http_decoder exdata index !!!\n", __FUNCTION__, __LINE__); + exit(-1); + } + + g_topic_id = stellar_session_mq_get_topic_id(st, "HTTP_DECODER_MESSAGE"); + if (g_topic_id < 0) + { + printf("[%s:%d]: can't get http_decoder topic id !!!\n", __FUNCTION__, __LINE__); + exit(-1); + } + + stellar_session_mq_subscribe(st, g_topic_id, g_entry_fun, g_plugin_id); + // printf("http_decoder_test_init OK!\n"); + + return NULL; +} + +extern "C" void http_decoder_perf_exit(void *test_ctx) +{ + if (test_ctx != NULL) + { + FREE(test_ctx); + } + printf("http_decoder_perf plug exit OK!\n"); +} |
