#include "session.h" #include "packet.h" #include "plugin.h" #include #include #include static char *g_handler = NULL; struct http_session_ctx { char data[16]; /* data */; }; static struct http_session_ctx *http_session_ctx_create() { struct http_session_ctx *ctx = (struct http_session_ctx *)calloc(1, sizeof(struct http_session_ctx)); return ctx; } static void http_session_ctx_destory(struct http_session_ctx *ctx) { if (ctx) { free(ctx); ctx = NULL; } } extern "C" void http_event_plugin_entry(const struct stellar_session *session, enum session_event_type event, const char *payload, size_t len, void **ctx) { struct http_session_ctx **per_http_session_ctx = (struct http_session_ctx **)ctx; printf("RUN http_event_plugin_entry, event: %d\n", event); if (event & SESSION_EVENT_OPENING) { if (*per_http_session_ctx == NULL) { struct http_session_ctx *cur_ctx = http_session_ctx_create(); memcpy(cur_ctx->data, "http_event_plugin_entry", strlen("http_event_plugin_entry")); *per_http_session_ctx = *&cur_ctx; } } if (event & SESSION_EVENT_RAWPKT) { // TODO pm_session_dettach_me(session); } if (event & SESSION_EVENT_ORDPKT) { // TODO pm_session_take_over(session); } if (event & SESSION_EVENT_META) { // TODO } if (event & SESSION_EVENT_CLOSING) { http_session_ctx_destory(*per_http_session_ctx); } } extern "C" int http_event_plugin_init(void) { printf("RUN http_event_plugin_init\n"); if (g_handler == NULL) { g_handler = (char *)malloc(1024); snprintf(g_handler, 1024, "111111"); } return 0; } extern "C" void http_event_plugin_exit(void) { printf("RUN http_event_plugin_exit\n"); if (g_handler) { free(g_handler); g_handler = NULL; } }