summaryrefslogtreecommitdiff
path: root/decoders
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-11-06 13:53:03 +0800
committeryangwei <[email protected]>2024-11-06 13:53:03 +0800
commit526c110868cec72677660fcc75dfa15dbb43fff0 (patch)
tree79f5b4865e82e5fde4469997abc76dbdf586909c /decoders
parent8ddef31bb58c529763d565674ba5036584323921 (diff)
🦄 refactor(appid api): remove appid module
Diffstat (limited to 'decoders')
-rw-r--r--decoders/CMakeLists.txt1
-rw-r--r--decoders/appid/CMakeLists.txt1
-rw-r--r--decoders/appid/appid.c49
-rw-r--r--decoders/appid/appid_internal.h25
-rw-r--r--decoders/lpi_plus/CMakeLists.txt2
-rw-r--r--decoders/lpi_plus/lpi_plus.h7
-rw-r--r--decoders/lpi_plus/lpi_plus_internal.h16
-rw-r--r--decoders/lpi_plus/lpip_module.c70
-rw-r--r--decoders/lpi_plus/version.map2
9 files changed, 73 insertions, 100 deletions
diff --git a/decoders/CMakeLists.txt b/decoders/CMakeLists.txt
index efad779..7946822 100644
--- a/decoders/CMakeLists.txt
+++ b/decoders/CMakeLists.txt
@@ -1,4 +1,3 @@
-add_subdirectory(appid)
add_subdirectory(lpi_plus)
#add_subdirectory(http)
#add_subdirectory(socks)
diff --git a/decoders/appid/CMakeLists.txt b/decoders/appid/CMakeLists.txt
deleted file mode 100644
index acb1939..0000000
--- a/decoders/appid/CMakeLists.txt
+++ /dev/null
@@ -1 +0,0 @@
-add_library(appid appid.c) \ No newline at end of file
diff --git a/decoders/appid/appid.c b/decoders/appid/appid.c
deleted file mode 100644
index 6182dd8..0000000
--- a/decoders/appid/appid.c
+++ /dev/null
@@ -1,49 +0,0 @@
-#include "appid_internal.h"
-
-#include "stellar/utils.h"
-#include "stellar/mq.h"
-
-
-
-static void appid_message_free(void *msg, void *msg_free_arg __unused)
-{
- if(msg==NULL)return;
- FREE(msg);
-}
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wcast-function-type"
-
-static void stellar_appid_on_msg_dispatch(int topic_id __unused,
- void *msg,
- on_msg_cb_func* on_msg_cb,
- void *on_msg_cb_arg,
- void *dispatch_arg __unused)
-{
- on_appid_callback *appid_cb = (on_appid_callback *)on_msg_cb;
- struct appid_message *appid_msg=(struct appid_message *)msg;
- appid_cb(appid_msg->sess, appid_msg->origin, appid_msg->appid, appid_msg->appid_num, on_msg_cb_arg);
-}
-
-int stellar_appid_subscribe(struct module_manager *mod_mgr, on_appid_callback *cb, void *args)
-{
- if(mod_mgr==NULL)return -1;
- int appid_topic_id=mq_schema_get_topic_id(module_manager_get_mq_schema(mod_mgr), APPID_MESSAGE_TOPIC);
- if(appid_topic_id<0)
- {
- appid_topic_id=mq_schema_create_topic(module_manager_get_mq_schema(mod_mgr), APPID_MESSAGE_TOPIC, stellar_appid_on_msg_dispatch, mod_mgr, appid_message_free, NULL);
- }
- return mq_schema_subscribe(module_manager_get_mq_schema(mod_mgr), appid_topic_id, (on_msg_cb_func *)cb, args);
-}
-
-#pragma GCC diagnostic pop
-
-int stellar_appid_create_topic(struct module_manager *mod_mgr)
-{
- int app_topic_id=mq_schema_get_topic_id(module_manager_get_mq_schema(mod_mgr), APPID_MESSAGE_TOPIC);
- if(app_topic_id < 0)
- {
- app_topic_id=mq_schema_create_topic(module_manager_get_mq_schema(mod_mgr), APPID_MESSAGE_TOPIC, stellar_appid_on_msg_dispatch, NULL,appid_message_free, NULL);
- }
- return app_topic_id;
-} \ No newline at end of file
diff --git a/decoders/appid/appid_internal.h b/decoders/appid/appid_internal.h
deleted file mode 100644
index b107806..0000000
--- a/decoders/appid/appid_internal.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#pragma once
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include "stellar/appid.h"
-
-#define MAX_APPID_NUM 8
-#define APPID_MESSAGE_TOPIC "TOPIC_APPID"
-
-struct appid_message
-{
- struct session *sess;
- enum APPID_ORIGIN origin;
- uint32_t appid_num;
- int32_t appid[MAX_APPID_NUM];
- uint32_t surrogate_id[MAX_APPID_NUM];
- uint32_t packet_sequence[MAX_APPID_NUM];
-};
-
-#ifdef __cplusplus
-}
-#endif \ No newline at end of file
diff --git a/decoders/lpi_plus/CMakeLists.txt b/decoders/lpi_plus/CMakeLists.txt
index b5da11a..91b097f 100644
--- a/decoders/lpi_plus/CMakeLists.txt
+++ b/decoders/lpi_plus/CMakeLists.txt
@@ -5,7 +5,7 @@ add_library(lpi_plus lpip_module.c lpip_extend.c)
target_include_directories(lpi_plus PUBLIC ${CMAKE_SOURCE_DIR}/deps/)
target_include_directories(lpi_plus PUBLIC ${CMAKE_SOURCE_DIR}/decoders/)
-target_link_libraries(lpi_plus libprotoident appid)
+target_link_libraries(lpi_plus libprotoident)
set_target_properties(lpi_plus PROPERTIES LINK_FLAGS
"-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/version.map")
diff --git a/decoders/lpi_plus/lpi_plus.h b/decoders/lpi_plus/lpi_plus.h
deleted file mode 100644
index cb55a5f..0000000
--- a/decoders/lpi_plus/lpi_plus.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#pragma once
-
-#include "stellar/module.h"
-#define LPI_PLUS_MODULE_NAME "LPI_PLUS"
-struct lpi_plus_mapper;
-struct lpi_plus_mapper *module_to_lpip_mapper(struct module *mod);
-const char *lpi_plus_appid2name(struct lpi_plus_mapper *mapper, int appid); \ No newline at end of file
diff --git a/decoders/lpi_plus/lpi_plus_internal.h b/decoders/lpi_plus/lpi_plus_internal.h
new file mode 100644
index 0000000..87136bf
--- /dev/null
+++ b/decoders/lpi_plus/lpi_plus_internal.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "stellar/lpi_plus.h"
+
+#define MAX_APPID_NUM 8
+#define LPIP_APPID_MESSAGE_TOPIC "TOPIC_LPIP_APPID"
+
+struct appid_message
+{
+ struct session *sess;
+ uint32_t appid_num;
+ int32_t appid[MAX_APPID_NUM];
+ uint32_t packet_sequence[MAX_APPID_NUM];
+};
+
+const char *lpi_plus_appid2name(struct lpi_plus *lpip, int appid); \ No newline at end of file
diff --git a/decoders/lpi_plus/lpip_module.c b/decoders/lpi_plus/lpip_module.c
index 5fd4aa4..1d254c6 100644
--- a/decoders/lpi_plus/lpip_module.c
+++ b/decoders/lpi_plus/lpip_module.c
@@ -17,9 +17,7 @@
#include "stellar/packet.h"
#include "stellar/session.h"
-#include "appid/appid_internal.h"
-
-#include "lpi_plus.h"
+#include "lpi_plus_internal.h"
#include "lpip_extend.h"
@@ -40,7 +38,7 @@ struct lpi_plus_mapper
struct lpi_plus_appid_info *hash_appid2name;
};
-struct lpi_plus_env
+struct lpi_plus
{
unsigned int max_pkts;
int lpip_session_exdata_idx;
@@ -93,13 +91,11 @@ static void lpi_plus_get_host_order_port(struct session *sess __unused, unsigned
static struct appid_message *lpi_plus_message_new(struct session *sess, int *id_array, size_t id_num)
{
struct appid_message *result=CALLOC(struct appid_message, 1);
- result->origin=ORIGIN_LPI_PLUS;
result->sess=sess;
result->appid_num=id_num;
for(unsigned int i=0; i<result->appid_num; i++)
{
result->appid[i]=(int)(id_array[i]);
- result->surrogate_id[i]=0;
}
return result;
@@ -136,10 +132,10 @@ static int lpi_plus_name2appid(struct lpi_plus_mapper *mapper, const char *lpi_n
return out->appid;
}
-const char *lpi_plus_appid2name(struct lpi_plus_mapper *mapper, int appid)
+const char *lpi_plus_appid2name(struct lpi_plus *lpip, int appid)
{
struct lpi_plus_appid_info *out=NULL;
- HASH_FIND(hh_appid, mapper->hash_appid2name, &appid, sizeof(int), out);
+ HASH_FIND(hh_appid, lpip->mapper->hash_appid2name, &appid, sizeof(int), out);
if(out==NULL)return NULL;
return out->app_name;
}
@@ -293,7 +289,7 @@ static void lpi_plus_on_session(struct session *sess, enum session_state state,
assert(pkt == NULL);
return;
}
- struct lpi_plus_env *env=(struct lpi_plus_env *)args;
+ struct lpi_plus *env=(struct lpi_plus *)args;
struct lpi_plus_exdata *exdata = (struct lpi_plus_exdata *)session_get_exdata(sess, env->lpip_session_exdata_idx);
if(exdata==NULL)
{
@@ -331,7 +327,7 @@ void lpi_plus_exit(struct module_manager *mod_mgr, struct module *mod)
if(mod_mgr==NULL)return;
if(mod)
{
- struct lpi_plus_env *env=(struct lpi_plus_env *)module_get_ctx(mod);
+ struct lpi_plus *env=(struct lpi_plus *)module_get_ctx(mod);
lpi_free_library();
lpi_plus_mapper_free(env->mapper);
FREE(env);
@@ -339,11 +335,55 @@ void lpi_plus_exit(struct module_manager *mod_mgr, struct module *mod)
}
}
+static void appid_message_free(void *msg, void *msg_free_arg __unused)
+{
+ if(msg==NULL)return;
+ FREE(msg);
+}
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-function-type"
+
+static void lpi_plus_appid_on_msg_dispatch(int topic_id __unused,
+ void *msg,
+ on_msg_cb_func* on_msg_cb,
+ void *on_msg_cb_arg,
+ void *dispatch_arg __unused)
+{
+ on_appid_callback *appid_cb = (on_appid_callback *)on_msg_cb;
+ struct appid_message *appid_msg=(struct appid_message *)msg;
+ appid_cb(appid_msg->sess, appid_msg->appid, appid_msg->appid_num, on_msg_cb_arg);
+}
+
+int lpi_plus_appid_subscribe(struct lpi_plus *lpip, on_appid_callback *cb, void *args)
+{
+ if(lpip==NULL)return -1;
+ struct module_manager *mod_mgr=lpip->mod_mgr;
+ int appid_topic_id=mq_schema_get_topic_id(module_manager_get_mq_schema(mod_mgr), LPIP_APPID_MESSAGE_TOPIC);
+ if(appid_topic_id<0)
+ {
+ appid_topic_id=mq_schema_create_topic(module_manager_get_mq_schema(mod_mgr), LPIP_APPID_MESSAGE_TOPIC, lpi_plus_appid_on_msg_dispatch, mod_mgr, appid_message_free, NULL);
+ }
+ return mq_schema_subscribe(module_manager_get_mq_schema(mod_mgr), appid_topic_id, (on_msg_cb_func *)cb, args);
+}
+
+#pragma GCC diagnostic pop
+
+int lpi_plus_create_appid_topic(struct module_manager *mod_mgr)
+{
+ int app_topic_id=mq_schema_get_topic_id(module_manager_get_mq_schema(mod_mgr), LPIP_APPID_MESSAGE_TOPIC);
+ if(app_topic_id < 0)
+ {
+ app_topic_id=mq_schema_create_topic(module_manager_get_mq_schema(mod_mgr), LPIP_APPID_MESSAGE_TOPIC, lpi_plus_appid_on_msg_dispatch, NULL,appid_message_free, NULL);
+ }
+ return app_topic_id;
+}
+
struct module *lpi_plus_init(struct module_manager *mod_mgr)
{
if(mod_mgr==NULL)return NULL;
- struct lpi_plus_env *env=CALLOC(struct lpi_plus_env, 1);
+ struct lpi_plus *env=CALLOC(struct lpi_plus, 1);
struct module *mod=module_new("LPI_PLUS", env);
env->mod_mgr=mod_mgr;
env->max_pkts=16;//TODO: load from toml
@@ -370,7 +410,7 @@ struct module *lpi_plus_init(struct module_manager *mod_mgr)
session_manager_subscribe_udp(sess_mgr, lpi_plus_on_session, env);
env->lpip_session_exdata_idx = session_manager_new_session_exdata_index(sess_mgr, "EXDATA_LPI", lpi_plus_exdata_free, NULL);
- env->topic_appid=stellar_appid_create_topic(mod_mgr);
+ env->topic_appid=lpi_plus_create_appid_topic(mod_mgr);
if(env->topic_appid<0)
{
goto INIT_ERROR;
@@ -385,11 +425,11 @@ INIT_ERROR:
}
-struct lpi_plus_mapper *module_to_lpip_mapper(struct module *mod)
+struct lpi_plus *module_to_lpi_plus(struct module *mod)
{
if(mod==NULL)return NULL;
assert(strcmp(module_get_name(mod), LPI_PLUS_MODULE_NAME) == 0);
- struct lpi_plus_env *lpi_p=(struct lpi_plus_env *)module_get_ctx(mod);
+ struct lpi_plus *lpi_p=(struct lpi_plus *)module_get_ctx(mod);
if(lpi_p==NULL)return NULL;
- return lpi_p->mapper;
+ return lpi_p;
} \ No newline at end of file
diff --git a/decoders/lpi_plus/version.map b/decoders/lpi_plus/version.map
index 179b07f..6028219 100644
--- a/decoders/lpi_plus/version.map
+++ b/decoders/lpi_plus/version.map
@@ -3,7 +3,7 @@ global:
extern "C" {
lpi_plus_init;
lpi_plus_exit;
- stellar_appid_subscribe;
+ lpi_plus_appid_subscribe;
GIT_VERSION_*;
};