Plugin Management support C plugin
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
|
||||
add_definitions(-fPIC)
|
||||
|
||||
add_library(custom_event_plugin
|
||||
add_library(custom_event_plugin SHARED
|
||||
custom_event_plugin.cpp
|
||||
)
|
||||
set_target_properties(custom_event_plugin PROPERTIES PREFIX "")
|
||||
set_target_properties(custom_event_plugin PROPERTIES PREFIX "")
|
||||
|
||||
add_library(http_event_plugin
|
||||
http_event_plugin.cpp
|
||||
add_library(http_event_plugin SHARED
|
||||
http_event_plugin.cpp
|
||||
)
|
||||
set_target_properties(http_event_plugin PROPERTIES PREFIX "")
|
||||
set_target_properties(http_event_plugin PROPERTIES PREFIX "")
|
||||
@@ -2,37 +2,57 @@
|
||||
#include "packet.h"
|
||||
#include "plugin.h"
|
||||
|
||||
struct custom_session_event *_event = nullptr;
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void *custom_decode(const char *payload, uint32_t len, void **pme)
|
||||
static char *g_handler = NULL;
|
||||
|
||||
static void *custom_decode(const char *payload, uint16_t len, void **pme)
|
||||
{
|
||||
return nullptr;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int custom_plugin_entry(const struct stellar_session *s, int what, struct stellar_packet *p, const char *payload, uint32_t len, void **pme)
|
||||
extern "C" void custom_plugin_tcp_entry(const struct stellar_session *s, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
|
||||
{
|
||||
struct stellar_session_event_extras *info= (struct stellar_session_event_extras *)custom_decode(payload, len, pme);
|
||||
struct stellar_session *new_session=session_manager_session_derive(s, "CUSTOM_A");
|
||||
char **per_session_pme = (char **)pme;
|
||||
|
||||
printf("RUN custom_plugin_tcp_entry, event: %d\n", event);
|
||||
|
||||
struct stellar_session_event_extras *info = (struct stellar_session_event_extras *)custom_decode(payload, len, pme);
|
||||
struct stellar_session *new_session = session_manager_session_derive(s, "CUSTOM");
|
||||
|
||||
session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info);
|
||||
session_manager_trigger_event(new_session, SESSION_EVENT_META, info);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int custom_event_plugin_entry(const struct stellar_session *s, int what, struct stellar_packet *p, const char *payload, uint32_t len, void **pme)
|
||||
extern "C" void custom_plugin_custom_entry(const struct stellar_session *s, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
|
||||
{
|
||||
return 0;
|
||||
char **per_session_pme = (char **)pme;
|
||||
|
||||
printf("RUN custom_plugin_custom_entry, event: %d\n", event);
|
||||
}
|
||||
|
||||
int custom_plugin_init()
|
||||
extern "C" int custom_plugin_init(void)
|
||||
{
|
||||
//plugin_manager_event_register("TCP", custom_plugin_entry, nullptr);
|
||||
//plugin_manager_event_register("CUSTOM_A", custom_event_plugin_entry, nullptr);
|
||||
printf("RUN custom_plugin_init\n");
|
||||
|
||||
if (g_handler == NULL)
|
||||
{
|
||||
g_handler = (char *)malloc(1024);
|
||||
snprintf(g_handler, 1024, "222222");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void custom_plugin_destroy()
|
||||
extern "C" void custom_plugin_exit(void)
|
||||
{
|
||||
return ;
|
||||
printf("RUN custom_plugin_exit\n");
|
||||
|
||||
if (g_handler)
|
||||
{
|
||||
free(g_handler);
|
||||
g_handler = NULL;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,82 @@
|
||||
#include "session.h"
|
||||
#include "packet.h"
|
||||
#include "plugin.h"
|
||||
#include "http.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static char *g_handler = NULL;
|
||||
|
||||
int http_event_plugin_entry(const struct stellar_session *s, int what, struct stellar_packet *p, const char *payload, uint32_t len, void **pme)
|
||||
struct per_session_pme_info
|
||||
{
|
||||
int flag;
|
||||
char data[16];
|
||||
};
|
||||
|
||||
extern "C" void http_event_plugin_entry(const struct stellar_session *s, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
|
||||
{
|
||||
struct per_session_pme_info **per_session_pme = (struct per_session_pme_info **)pme;
|
||||
|
||||
printf("RUN http_event_plugin_entry, event: %d\n", event);
|
||||
|
||||
if (event & SESSION_EVENT_OPENING)
|
||||
{
|
||||
if (*per_session_pme == NULL)
|
||||
{
|
||||
struct per_session_pme_info *cur_ctx = (struct per_session_pme_info *)malloc(sizeof(struct per_session_pme_info));
|
||||
snprintf(cur_ctx->data, 6, "******");
|
||||
*per_session_pme = *&cur_ctx;
|
||||
printf("http_event_plugin_entry->opening_handler\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_RAWPKT)
|
||||
{
|
||||
printf("http_event_plugin_entry->rawpkt_handler\n");
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_ORDPKT)
|
||||
{
|
||||
printf("http_event_plugin_entry->ordpkt_handler\n");
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_META)
|
||||
{
|
||||
printf("http_event_plugin_entry->meta_handler\n");
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_CLOSING)
|
||||
{
|
||||
if (*per_session_pme)
|
||||
{
|
||||
printf("http_event_plugin_entry->closing_hanler\n");
|
||||
|
||||
free(*per_session_pme);
|
||||
*per_session_pme = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int http_event_plugin_init()
|
||||
extern "C" void http_event_plugin_exit(void)
|
||||
{
|
||||
//plugin_manager_event_register("HTTP", http_event_plugin_entry, nullptr);
|
||||
return 0;
|
||||
}
|
||||
printf("RUN http_event_plugin_exit\n");
|
||||
|
||||
void http_event_plugin_destroy()
|
||||
{
|
||||
return ;
|
||||
if (g_handler)
|
||||
{
|
||||
free(g_handler);
|
||||
g_handler = NULL;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,14 @@
|
||||
[PLUGINFO]
|
||||
INIT_FUNC=custom_plugin_init
|
||||
EXIT_FUNC=custom_plugin_exit
|
||||
LIBRARY_PATH=./plugins/custom_event_plugin/custom_event_plugin.so
|
||||
INIT_FUNC="custom_plugin_init"
|
||||
EXIT_FUNC="custom_plugin_exit"
|
||||
LIBRARY_PATH="./plugins/custom_event_plugin/custom_event_plugin.so"
|
||||
|
||||
# Support SESSION_EVENT_TYPE: "SESSION_EVENT_OPENING", "SESSION_EVENT_RAWPKT", "SESSION_EVENT_ORDPKT", "SESSION_EVENT_META", "SESSION_EVENT_CLOSING", "SESSION_EVENT_ALL"
|
||||
|
||||
# Support SESSION_EVENT_TYPE
|
||||
# OPENING,RAWPKT,ORDPKT,META,CLOSING,ALL
|
||||
[SESSION_NAME.TCP]
|
||||
SESSION_EVENT_TYPE=["SESSION_EVENT_ALL"]
|
||||
SESSION_EVENT_CALLBACK="custom_plugin_tcp_entry"
|
||||
|
||||
[SESSION_TYPE.TCP]
|
||||
SESSION_EVENT_TYPE=ALL
|
||||
SESSION_EVENT_CALLBACK=custom_plugin_entry
|
||||
|
||||
[SESSION_TYPE.CUSTOM_A]
|
||||
SESSION_EVENT_TYPE=OPENING,ORDPKT,CLOSING
|
||||
SESSION_EVENT_CALLBACK=custom_event_plugin_entry
|
||||
[SESSION_NAME.CUSTOM]
|
||||
SESSION_EVENT_TYPE=["SESSION_EVENT_OPENING","SESSION_EVENT_ORDPKT","SESSION_EVENT_CLOSING"]
|
||||
SESSION_EVENT_CALLBACK="custom_plugin_custom_entry"
|
||||
@@ -1,8 +1,10 @@
|
||||
[PLUGINFO]
|
||||
INIT_FUNC=http_event_plugin_init
|
||||
EXIT_FUNC=http_event_plugin_exit
|
||||
LIBRARY_PATH=./plugins/http_event_plugin/http_event_plugin.so
|
||||
INIT_FUNC="http_event_plugin_init"
|
||||
EXIT_FUNC="http_event_plugin_exit"
|
||||
LIBRARY_PATH="./plugins/http_event_plugin/http_event_plugin.so"
|
||||
|
||||
[SESSION_TYPE.HTTP]
|
||||
SESSION_EVENT_TYPE=ALL
|
||||
SESSION_EVENT_CALLBACK=http_event_plugin_entry
|
||||
# Support SESSION_EVENT_TYPE: "SESSION_EVENT_OPENING", "SESSION_EVENT_RAWPKT", "SESSION_EVENT_ORDPKT", "SESSION_EVENT_META", "SESSION_EVENT_CLOSING", "SESSION_EVENT_ALL"
|
||||
|
||||
[SESSION_NAME.HTTP]
|
||||
SESSION_EVENT_TYPE=["SESSION_EVENT_ALL"]
|
||||
SESSION_EVENT_CALLBACK="http_event_plugin_entry"
|
||||
@@ -1,2 +1,4 @@
|
||||
./http_event_plugin/http_event_plugin.inf
|
||||
./custom_event_plugin/custom_event_plugin.inf
|
||||
# Relative path, relative to the installation path of stellar
|
||||
|
||||
./plugins/http_event_plugin/http_event_plugin.inf
|
||||
./plugins/custom_event_plugin/custom_event_plugin.inf
|
||||
Reference in New Issue
Block a user