feat(http decoder): register http with session free hook

This commit is contained in:
yangwei
2024-09-04 14:56:05 +08:00
parent 2846142c7c
commit 95581a437e

View File

@@ -773,26 +773,27 @@ extern "C"
return;
}
static void http_decoder_on_session_free(struct session *sess,void *per_session_ctx, void *plugin_env)
{
struct http_decoder_env *httpd_env = (struct http_decoder_env *)plugin_env;
struct http_decoder_exdata *exdata = (struct http_decoder_exdata *)session_exdata_get(sess, httpd_env->topic_exdata_compose[HTTPD_TOPIC_TCP_STREAM_INDEX].exdata_id);
if (httpd_in_tunnel_transmitting(httpd_env, exdata))
{
http_decoder_push_tunnel_data(sess, exdata, HTTP_TUNNEL_CLOSING, NULL, 0);
}
else
{
http_half_pre_context_free(sess, exdata);
}
return;
}
void http_decoder_tcp_stream_msg_cb(struct session *sess, int topic_id, const void *msg, void *nouse_session_ctx, void *plugin_env)
{
struct http_decoder_env *httpd_env = (struct http_decoder_env *)plugin_env;
struct http_decoder_exdata *exdata = (struct http_decoder_exdata *)session_exdata_get(sess, httpd_env->topic_exdata_compose[HTTPD_TOPIC_TCP_STREAM_INDEX].exdata_id);
enum session_state sess_state = session_get_current_state(sess);
const char *payload = NULL;
uint16_t payload_len = 0;
if (SESSION_STATE_CLOSED == sess_state)
{
if (httpd_in_tunnel_transmitting(httpd_env, exdata))
{
http_decoder_push_tunnel_data(sess, exdata, HTTP_TUNNEL_CLOSING, NULL, 0);
}
else
{
http_half_pre_context_free(sess, exdata);
}
return;
}
assert(msg != NULL);
payload_len = tcp_segment_get_len((struct tcp_segment *)msg);
@@ -877,8 +878,8 @@ extern "C"
goto failed;
}
httpd_env->st = st;
httpd_env->plugin_id = stellar_session_plugin_register(st, httpd_session_ctx_new_cb,
httpd_session_ctx_free_cb, (void *)httpd_env);
httpd_env->plugin_id = stellar_session_plugin_register_with_hook(st, httpd_session_ctx_new_cb,
httpd_session_ctx_free_cb, NULL,http_decoder_on_session_free,(void *)httpd_env);
if (httpd_env->plugin_id < 0)
{
goto failed;