Plugin management support pm_session_dettach_me and pm_session_dettach_others
Add test cases for pm_session_dettach_me and pm_session_dettach_others
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static char *g_handler = NULL;
|
||||
|
||||
@@ -13,29 +14,121 @@ static void *custom_decode(const char *payload, uint16_t len, void **pme)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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 tcp_session_pme
|
||||
{
|
||||
char **per_session_pme = (char **)pme;
|
||||
char data[16];
|
||||
/* data */
|
||||
};
|
||||
|
||||
printf("RUN custom_plugin_tcp_entry, event: %d\n", event);
|
||||
struct custom_session_pme
|
||||
{
|
||||
char data[16];
|
||||
/* data */
|
||||
};
|
||||
|
||||
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);
|
||||
static struct tcp_session_pme *tcp_session_pme_create()
|
||||
{
|
||||
struct tcp_session_pme *pme = (struct tcp_session_pme *)calloc(1, sizeof(struct tcp_session_pme));
|
||||
return 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)
|
||||
static void tcp_session_pme_destory(struct tcp_session_pme *pme)
|
||||
{
|
||||
char **per_session_pme = (char **)pme;
|
||||
|
||||
printf("RUN custom_plugin_custom_entry, event: %d\n", event);
|
||||
if (pme)
|
||||
{
|
||||
free(pme);
|
||||
pme = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int custom_plugin_init(void)
|
||||
static struct custom_session_pme *custom_session_pme_create()
|
||||
{
|
||||
printf("RUN custom_plugin_init\n");
|
||||
struct custom_session_pme *pme = (struct custom_session_pme *)calloc(1, sizeof(struct custom_session_pme));
|
||||
return pme;
|
||||
}
|
||||
|
||||
static void custom_session_pme_destory(struct custom_session_pme *pme)
|
||||
{
|
||||
if (pme)
|
||||
{
|
||||
free(pme);
|
||||
pme = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void custom_event_plugin_error(const struct stellar_session *session, enum error_event_type event, void **pme)
|
||||
{
|
||||
if (strcmp(stellar_session_get_name(session), "TCP") == 0)
|
||||
{
|
||||
struct tcp_session_pme **per_tcp_session_pme = (struct tcp_session_pme **)pme;
|
||||
printf("RUN custom_event_plugin_error, session_name: 'TCP', error_event_type: %d, pme->data: %s\n", event, (*per_tcp_session_pme) == NULL ? "NULL" : (*per_tcp_session_pme)->data);
|
||||
tcp_session_pme_destory(*per_tcp_session_pme);
|
||||
}
|
||||
|
||||
if (strcmp(stellar_session_get_name(session), "CUSTOM") == 0)
|
||||
{
|
||||
struct custom_session_pme **per_custom_session_pme = (struct custom_session_pme **)pme;
|
||||
printf("RUN custom_event_plugin_error, session_name: 'CUSTOM', error_event_type: %d, pme->data: %s\n", event, (*per_custom_session_pme) == NULL ? "NULL" : (*per_custom_session_pme)->data);
|
||||
custom_session_pme_destory(*per_custom_session_pme);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *session, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
|
||||
{
|
||||
struct tcp_session_pme **per_tcp_session_pme = (struct tcp_session_pme **)pme;
|
||||
|
||||
printf("RUN custom_event_plugin_tcp_entry, event: %d\n", event);
|
||||
|
||||
if (event & SESSION_EVENT_OPENING)
|
||||
{
|
||||
if (*per_tcp_session_pme == NULL)
|
||||
{
|
||||
struct tcp_session_pme *cur_ctx = tcp_session_pme_create();
|
||||
snprintf(cur_ctx->data, 6, "tcp******");
|
||||
*per_tcp_session_pme = *&cur_ctx;
|
||||
}
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_ORDPKT)
|
||||
{
|
||||
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(session, "CUSTOM");
|
||||
|
||||
session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info);
|
||||
session_manager_trigger_event(new_session, SESSION_EVENT_META, info);
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_CLOSING)
|
||||
{
|
||||
tcp_session_pme_destory(*per_tcp_session_pme);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void custom_event_plugin_custom_entry(const struct stellar_session *session, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme)
|
||||
{
|
||||
struct custom_session_pme **per_custom_session_pme = (struct custom_session_pme **)pme;
|
||||
|
||||
printf("RUN custom_event_plugin_custom_entry, event: %d\n", event);
|
||||
|
||||
if (event & SESSION_EVENT_OPENING)
|
||||
{
|
||||
if (*per_custom_session_pme == NULL)
|
||||
{
|
||||
struct custom_session_pme *cur_ctx = custom_session_pme_create();
|
||||
snprintf(cur_ctx->data, 6, "custom******");
|
||||
*per_custom_session_pme = *&cur_ctx;
|
||||
}
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_CLOSING)
|
||||
{
|
||||
custom_session_pme_destory(*per_custom_session_pme);
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" int custom_event_plugin_init(void)
|
||||
{
|
||||
printf("RUN custom_event_plugin_init\n");
|
||||
|
||||
if (g_handler == NULL)
|
||||
{
|
||||
@@ -46,9 +139,9 @@ extern "C" int custom_plugin_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" void custom_plugin_exit(void)
|
||||
extern "C" void custom_event_plugin_exit(void)
|
||||
{
|
||||
printf("RUN custom_plugin_exit\n");
|
||||
printf("RUN custom_event_plugin_exit\n");
|
||||
|
||||
if (g_handler)
|
||||
{
|
||||
|
||||
@@ -4,56 +4,77 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static char *g_handler = NULL;
|
||||
|
||||
struct per_session_pme_info
|
||||
struct http_session_pme
|
||||
{
|
||||
int flag;
|
||||
char data[16];
|
||||
/* data */;
|
||||
};
|
||||
|
||||
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)
|
||||
static struct http_session_pme *http_session_pme_create()
|
||||
{
|
||||
struct per_session_pme_info **per_session_pme = (struct per_session_pme_info **)pme;
|
||||
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_session_pme == NULL)
|
||||
if (*per_http_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");
|
||||
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)
|
||||
{
|
||||
printf("http_event_plugin_entry->rawpkt_handler\n");
|
||||
// TODO
|
||||
pm_session_dettach_me(session);
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_ORDPKT)
|
||||
{
|
||||
printf("http_event_plugin_entry->ordpkt_handler\n");
|
||||
// TODO
|
||||
pm_session_dettach_others(session);
|
||||
}
|
||||
|
||||
if (event & SESSION_EVENT_META)
|
||||
{
|
||||
printf("http_event_plugin_entry->meta_handler\n");
|
||||
// TODO
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
http_session_pme_destory(*per_http_session_pme);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
[PLUGINFO]
|
||||
INIT_FUNC="custom_plugin_init"
|
||||
EXIT_FUNC="custom_plugin_exit"
|
||||
INIT_FUNC="custom_event_plugin_init"
|
||||
EXIT_FUNC="custom_event_plugin_exit"
|
||||
ERROR_FUNC="custom_event_plugin_error"
|
||||
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"
|
||||
|
||||
[SESSION_NAME.TCP]
|
||||
SESSION_EVENT_TYPE=["SESSION_EVENT_ALL"]
|
||||
SESSION_EVENT_CALLBACK="custom_plugin_tcp_entry"
|
||||
SESSION_EVENT_CALLBACK="custom_event_plugin_tcp_entry"
|
||||
|
||||
[SESSION_NAME.CUSTOM]
|
||||
SESSION_EVENT_TYPE=["SESSION_EVENT_OPENING","SESSION_EVENT_ORDPKT","SESSION_EVENT_CLOSING"]
|
||||
SESSION_EVENT_CALLBACK="custom_plugin_custom_entry"
|
||||
SESSION_EVENT_CALLBACK="custom_event_plugin_custom_entry"
|
||||
@@ -1,6 +1,7 @@
|
||||
[PLUGINFO]
|
||||
INIT_FUNC="http_event_plugin_init"
|
||||
EXIT_FUNC="http_event_plugin_exit"
|
||||
ERROR_FUNC="http_event_plugin_error"
|
||||
LIBRARY_PATH="./plugins/http_event_plugin/http_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"
|
||||
|
||||
Reference in New Issue
Block a user