103 lines
2.2 KiB
C++
103 lines
2.2 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_pme
|
|
{
|
|
char data[16];
|
|
/* data */;
|
|
};
|
|
|
|
static struct http_session_pme *http_session_pme_create()
|
|
{
|
|
struct http_session_pme *pme = (struct http_session_pme *)calloc(1, sizeof(struct http_session_pme));
|
|
return pme;
|
|
}
|
|
|
|
static void http_session_pme_destory(struct http_session_pme *pme)
|
|
{
|
|
if (pme)
|
|
{
|
|
free(pme);
|
|
pme = NULL;
|
|
}
|
|
}
|
|
|
|
extern "C" void http_event_plugin_error(const struct stellar_session *session, enum error_event_type event, void **pme)
|
|
{
|
|
if (strcmp(stellar_session_get_name(session), "HTTP") == 0)
|
|
{
|
|
struct http_session_pme **per_http_session_pme = (struct http_session_pme **)pme;
|
|
printf("RUN http_event_plugin_error, session_name: 'HTTP', error_event_type: %d, pme->data: %s\n", event, (*per_http_session_pme) == NULL ? "NULL" : (*per_http_session_pme)->data);
|
|
http_session_pme_destory(*per_http_session_pme);
|
|
}
|
|
}
|
|
|
|
extern "C" void http_event_plugin_entry(const struct stellar_session *session, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
|
|
{
|
|
struct http_session_pme **per_http_session_pme = (struct http_session_pme **)pme;
|
|
|
|
printf("RUN http_event_plugin_entry, event: %d\n", event);
|
|
|
|
if (event & SESSION_EVENT_OPENING)
|
|
{
|
|
if (*per_http_session_pme == NULL)
|
|
{
|
|
struct http_session_pme *cur_ctx = http_session_pme_create();
|
|
snprintf(cur_ctx->data, 6, "http******");
|
|
*per_http_session_pme = *&cur_ctx;
|
|
}
|
|
}
|
|
|
|
if (event & SESSION_EVENT_RAWPKT)
|
|
{
|
|
// TODO
|
|
pm_session_dettach_me(session);
|
|
}
|
|
|
|
if (event & SESSION_EVENT_ORDPKT)
|
|
{
|
|
// TODO
|
|
pm_session_dettach_others(session);
|
|
}
|
|
|
|
if (event & SESSION_EVENT_META)
|
|
{
|
|
// TODO
|
|
}
|
|
|
|
if (event & SESSION_EVENT_CLOSING)
|
|
{
|
|
http_session_pme_destory(*per_http_session_pme);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
} |