This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar-2022/sdk/example/http_plugin.cpp

70 lines
1.1 KiB
C++

#include <stdlib.h>
#include "session.h"
static char *g_handler = NULL;
struct session_ctx
{
char data[64];
};
static struct session_ctx *session_ctx_create()
{
struct session_ctx *ctx = (struct session_ctx *)calloc(1, sizeof(struct session_ctx));
return ctx;
}
static void session_ctx_destory(struct session_ctx *ctx)
{
if (ctx)
{
free(ctx);
ctx = NULL;
}
}
extern "C" void http_plugin_entry(struct stellar_session *session, enum session_state state, int thread_id, void **ctx)
{
struct session_ctx **sctx = (struct session_ctx **)ctx;
if (state & SESSION_STATE_OPENING)
{
if (*sctx == NULL)
{
struct session_ctx *cur_ctx = session_ctx_create();
memcpy(cur_ctx->data, "http_plugin_entry", 17);
*sctx = *&cur_ctx;
}
}
if (state & SESSION_STATE_ACTIVE)
{
// TODO
}
if (state & SESSION_STATE_CLOSING)
{
session_ctx_destory(*sctx);
*sctx = NULL;
}
}
extern "C" int http_plugin_init(void)
{
if (g_handler == NULL)
{
g_handler = (char *)malloc(1024);
}
return 0;
}
extern "C" void http_plugin_exit(void)
{
if (g_handler)
{
free(g_handler);
g_handler = NULL;
}
}