add socks_decoder, stratum_decoder and session_flags
This commit is contained in:
210
test/decoders/session_flags/session_flags_test_plugin.cpp
Normal file
210
test/decoders/session_flags/session_flags_test_plugin.cpp
Normal file
@@ -0,0 +1,210 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
#include "stellar/stellar.h"
|
||||
#include "stellar/session.h"
|
||||
#include "stellar/stellar_mq.h"
|
||||
#include "stellar/stellar_exdata.h"
|
||||
|
||||
#include "stellar/session_flags.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
int commit_test_result_json(cJSON *node, const char *name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define unused(x) ((void)(x))
|
||||
|
||||
int g_test_session_flags_plugin_id;
|
||||
int g_session_flags_topic_id;
|
||||
|
||||
int g_receive_msg_count = 0;
|
||||
|
||||
static void session_flags_2_str(uint64_t flags, char *str, int str_len)
|
||||
{
|
||||
if (str == NULL || str_len == 0)
|
||||
return;
|
||||
|
||||
int offset = 0;
|
||||
str[0] = '[';
|
||||
offset += 1;
|
||||
|
||||
if (flags & SESSION_FLAGS_BULKY && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "Bulky,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
if (flags & SESSION_FLAGS_CBR && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "CBR Streaming,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
if (flags & SESSION_FLAGS_LOCAL_CLIENT && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "Client is Local,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
if (flags & SESSION_FLAGS_LOCAL_SERVER && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "Server is Local,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
if (flags & SESSION_FLAGS_DOWNLOAD && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "Download,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
if (flags & SESSION_FLAGS_INTERACTIVE && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "Interactive,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
if (flags & SESSION_FLAGS_INBOUND && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "Inbound,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
if (flags & SESSION_FLAGS_OUTBOUND && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "Outbound,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
if (flags & SESSION_FLAGS_PSEUDO_UNIDIRECTIONAL && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "Pseudo Unidirectional,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
|
||||
if (flags & SESSION_FLAGS_STREAMING && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "Streaming,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
if (flags & SESSION_FLAGS_UNIDIRECTIONAL && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "Unidirectional,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
if (flags & SESSION_FLAGS_RANDOM_LOOKING && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "Random Looking,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
if (flags & SESSION_FLAGS_C2S && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "C2S,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
if (flags & SESSION_FLAGS_S2C && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "S2C,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
if (flags & SESSION_FLAGS_BIDIRECTIONAL && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "Bidirectional,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
if (flags & SESSION_FLAGS_TUNNELING && str_len > offset)
|
||||
{
|
||||
snprintf(&str[offset], str_len-offset, "Tunneling,");
|
||||
offset = strlen(str);
|
||||
}
|
||||
|
||||
|
||||
str[offset-1] = ']';
|
||||
}
|
||||
|
||||
static void append_json(cJSON *root, struct session_flags_message *sf_message)
|
||||
{
|
||||
char key[128] = {0};
|
||||
snprintf(key, 128, "common_flags_%d", g_receive_msg_count);
|
||||
cJSON_AddNumberToObject(root, (const char *)key, sf_message->flags);
|
||||
|
||||
char str[1024] = {0};
|
||||
session_flags_2_str(sf_message->flags, str, 1024);
|
||||
snprintf(key, 128, "common_flags_str_%d", g_receive_msg_count);
|
||||
cJSON_AddStringToObject(root, (const char *)key, str);
|
||||
|
||||
char identify_str[1024] = {0};
|
||||
int offset = 0;
|
||||
for (unsigned int i = 0; i < sf_message->array_num; i++)
|
||||
{
|
||||
offset += snprintf(identify_str + offset, 1024-offset, "%u,", sf_message->packet_sequence_array[i]);
|
||||
}
|
||||
snprintf(key, 128, "common_flags_identify_info_%d", g_receive_msg_count);
|
||||
cJSON_AddStringToObject(root, (const char *)key, identify_str);
|
||||
|
||||
g_receive_msg_count++;
|
||||
}
|
||||
|
||||
void test_session_flags_entry(struct session *session, int topic_id, const void *msg, void *per_session_ctx, void *plugin_env)
|
||||
{
|
||||
unused(plugin_env);
|
||||
unused(session);
|
||||
unused(topic_id);
|
||||
|
||||
if (msg == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
struct session_flags_message *sf_message = (struct session_flags_message *)msg;
|
||||
cJSON *json_root = (cJSON *)per_session_ctx;
|
||||
|
||||
append_json(json_root, sf_message);
|
||||
|
||||
}
|
||||
|
||||
void *ctx_new(struct session *session, void *plugin_env)
|
||||
{
|
||||
unused(plugin_env);
|
||||
unused(session);
|
||||
|
||||
cJSON *root = cJSON_CreateObject();
|
||||
return (void *)root;
|
||||
}
|
||||
|
||||
void ctx_free(struct session *sess, void *session_ctx, void *plugin_env)
|
||||
{
|
||||
unused(sess);
|
||||
unused(plugin_env);
|
||||
|
||||
commit_test_result_json((cJSON *)session_ctx, "session_flags_test");
|
||||
}
|
||||
|
||||
extern "C" void *SESSION_FLAGS_TEST_PLUG_INIT(struct stellar *st)
|
||||
{
|
||||
g_test_session_flags_plugin_id = stellar_session_plugin_register(st, ctx_new, ctx_free, NULL);
|
||||
g_session_flags_topic_id = stellar_mq_get_topic_id(st, SESSION_FLAGS_MESSAGE_TOPIC);
|
||||
|
||||
stellar_session_mq_subscribe(st, g_session_flags_topic_id, test_session_flags_entry, g_test_session_flags_plugin_id);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern "C" void SESSION_FLAGS_TEST_PLUG_DESTROY(void *ctx)
|
||||
{
|
||||
unused(ctx);
|
||||
return;
|
||||
}
|
||||
Reference in New Issue
Block a user