blob: 635dbbbf59b580e3d8bf92c84a84daa208b27711 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#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;
}
}
|