* plugin_event_callback delete 'struct stellar_packet *p'
* plugin_event_callback rename 'uint16_t len' to 'size_t len'
* plugin_event_callback rename 'void **pme' to 'void **ctx'
93 lines
1.7 KiB
C++
93 lines
1.7 KiB
C++
#include "session.h"
|
|
#include "packet.h"
|
|
#include "plugin.h"
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
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;
|
|
}
|
|
} |