Add state to the on_session_message parameter.
* When state is closed, it implies that packet is null and the session will be destroyed
This commit is contained in:
@@ -168,7 +168,7 @@ static void session_debugger_exdata_free_callback(int idx, void *ex_ptr, void *a
|
||||
session_debugger_exdata_free((struct session_debugger_exdata *)ex_ptr);
|
||||
}
|
||||
|
||||
static void on_session_free(struct session *sess, void *arg)
|
||||
static void on_session_closed(struct session *sess, void *arg)
|
||||
{
|
||||
struct session_debugger *dbg = (struct session_debugger *)arg;
|
||||
struct session_debugger_exdata *exdata = (struct session_debugger_exdata *)session_get_exdata(sess, dbg->sess_exdata_idx);
|
||||
@@ -201,9 +201,17 @@ static void on_session_free(struct session *sess, void *arg)
|
||||
session_debugger_log(exdata->dbg->fd, "session %lu %s statistics:\n%s", session_get_id(exdata->sess), session_get0_readable_addr(exdata->sess), buff);
|
||||
}
|
||||
|
||||
static void on_session_packet(struct session *sess, struct packet *pkt, void *arg)
|
||||
static void on_session_message(struct session *sess, enum session_state state, struct packet *pkt, void *arg)
|
||||
{
|
||||
struct session_debugger *dbg = (struct session_debugger *)arg;
|
||||
|
||||
if (state == SESSION_STATE_CLOSED)
|
||||
{
|
||||
on_session_closed(sess, dbg);
|
||||
assert(pkt == NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
int is_ctrl = packet_is_ctrl(pkt);
|
||||
|
||||
char buff[PATH_MAX];
|
||||
@@ -256,10 +264,17 @@ static void on_session_packet(struct session *sess, struct packet *pkt, void *ar
|
||||
pthread_spin_unlock(&dbg->lock);
|
||||
}
|
||||
|
||||
static void on_tcp_stream(struct session *sess, const char *tcp_payload, uint32_t tcp_payload_len, void *arg)
|
||||
static void on_tcp_payload_message(struct session *sess, enum session_state state, const char *tcp_payload, uint32_t tcp_payload_len, void *arg)
|
||||
{
|
||||
struct session_debugger *dbg = (struct session_debugger *)arg;
|
||||
|
||||
if (state == SESSION_STATE_CLOSED)
|
||||
{
|
||||
assert(tcp_payload == NULL);
|
||||
assert(tcp_payload_len == 0);
|
||||
return;
|
||||
}
|
||||
|
||||
char buff[PATH_MAX];
|
||||
enum flow_type flow = session_get_flow_type(sess);
|
||||
assert(flow == FLOW_TYPE_C2S || flow == FLOW_TYPE_S2C);
|
||||
@@ -292,10 +307,16 @@ static void on_tcp_stream(struct session *sess, const char *tcp_payload, uint32_
|
||||
pthread_spin_unlock(&dbg->lock);
|
||||
}
|
||||
|
||||
static void on_udp_payload(struct session *sess, struct packet *pkt, void *arg)
|
||||
static void on_udp_payload_message(struct session *sess, enum session_state state, struct packet *pkt, void *arg)
|
||||
{
|
||||
struct session_debugger *dbg = (struct session_debugger *)arg;
|
||||
|
||||
if (state == SESSION_STATE_CLOSED)
|
||||
{
|
||||
assert(pkt == NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
char buff[PATH_MAX];
|
||||
enum flow_type flow = session_get_flow_type(sess);
|
||||
assert(flow == FLOW_TYPE_C2S || flow == FLOW_TYPE_S2C);
|
||||
@@ -373,32 +394,27 @@ static struct session_debugger *session_debugger_new(struct session_manager *ses
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
if (session_manager_subscribe_free(sess_mgr, on_session_free, dbg) == -1)
|
||||
{
|
||||
session_debugger_log(STDERR_FILENO, "subscribe free failed\n");
|
||||
goto error_out;
|
||||
}
|
||||
if (session_manager_subscribe_tcp(sess_mgr, on_session_packet, dbg) == -1)
|
||||
if (session_manager_subscribe_tcp(sess_mgr, on_session_message, dbg) == -1)
|
||||
{
|
||||
session_debugger_log(STDERR_FILENO, "subscribe tcp failed\n");
|
||||
goto error_out;
|
||||
}
|
||||
if (session_manager_subscribe_udp(sess_mgr, on_session_packet, dbg) == -1)
|
||||
if (session_manager_subscribe_udp(sess_mgr, on_session_message, dbg) == -1)
|
||||
{
|
||||
session_debugger_log(STDERR_FILENO, "subscribe udp failed\n");
|
||||
goto error_out;
|
||||
}
|
||||
if (session_manager_subscribe_control_packet(sess_mgr, on_session_packet, dbg) == -1)
|
||||
if (session_manager_subscribe_control_packet(sess_mgr, on_session_message, dbg) == -1)
|
||||
{
|
||||
session_debugger_log(STDERR_FILENO, "subscribe control packet failed\n");
|
||||
goto error_out;
|
||||
}
|
||||
if (session_manager_subscribe_tcp_stream(sess_mgr, on_tcp_stream, dbg) == -1)
|
||||
if (session_manager_subscribe_tcp_stream(sess_mgr, on_tcp_payload_message, dbg) == -1)
|
||||
{
|
||||
session_debugger_log(STDERR_FILENO, "subscribe tcp stream failed\n");
|
||||
goto error_out;
|
||||
}
|
||||
if (session_manager_subscribe_udp(sess_mgr, on_udp_payload, dbg) == -1)
|
||||
if (session_manager_subscribe_udp(sess_mgr, on_udp_payload_message, dbg) == -1)
|
||||
{
|
||||
session_debugger_log(STDERR_FILENO, "subscribe udp failed\n");
|
||||
goto error_out;
|
||||
|
||||
Reference in New Issue
Block a user