uses exported cw_Mod struct from dll
using an exported function from dlsym which is a void * ptr is not portable FossilOrigin-Name: c3abfc7581aba9f8e050cdbcb0a452a74fbb076c65a5a243aa8e2483a098129d
This commit is contained in:
parent
4718bcf3bb
commit
00b51bacf9
49
src/cw/mod.c
49
src/cw/mod.c
@ -33,20 +33,21 @@
|
|||||||
#include "cw.h"
|
#include "cw.h"
|
||||||
#include "cw/msgset.h"
|
#include "cw/msgset.h"
|
||||||
|
|
||||||
|
/*
|
||||||
static void (*actions_registered_cb) (struct cw_Mod * capwap, struct cw_Mod * bindings,
|
static void (*actions_registered_cb) (struct cw_Mod * capwap, struct cw_Mod * bindings,
|
||||||
struct cw_actiondef * actions) = NULL;
|
struct cw_actiondef * actions) = NULL;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
void mod_set_actions_registered_cb(void (*fun)
|
void mod_set_actions_registered_cb(void (*fun)
|
||||||
(struct cw_Mod *, struct cw_Mod *,
|
(struct cw_Mod *, struct cw_Mod *,
|
||||||
struct cw_actiondef *))
|
struct cw_actiondef *))
|
||||||
{
|
{
|
||||||
actions_registered_cb = fun;
|
actions_registered_cb = fun;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
struct cache_item {
|
struct cache_item {
|
||||||
const char *capwap;
|
const char *capwap;
|
||||||
@ -71,7 +72,6 @@ struct cw_Mod mod_null = {
|
|||||||
NULL, /* init_config */
|
NULL, /* init_config */
|
||||||
NULL, /* detect */
|
NULL, /* detect */
|
||||||
NULL /* data */
|
NULL /* data */
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -97,7 +97,8 @@ struct cw_actiondef *mod_cache_get(const char *capwap, const char *bindings)
|
|||||||
|
|
||||||
|
|
||||||
struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
|
struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
|
||||||
struct cw_Mod * capwap_mod, struct cw_Mod *bindings_mod)
|
struct cw_Mod *capwap_mod,
|
||||||
|
struct cw_Mod *bindings_mod)
|
||||||
{
|
{
|
||||||
struct cache_item search;
|
struct cache_item search;
|
||||||
struct cache_item *cached_set;
|
struct cache_item *cached_set;
|
||||||
@ -118,7 +119,8 @@ struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
|
|||||||
|
|
||||||
cached_set = mavl_get_ptr(msgset_cache, &search);
|
cached_set = mavl_get_ptr(msgset_cache, &search);
|
||||||
if (cached_set) {
|
if (cached_set) {
|
||||||
cw_dbg(DBG_INFO, "Using cached message set for %s,%s", capwap_mod->name, bindings_mod->name);
|
cw_dbg(DBG_INFO, "Using cached message set for %s,%s", capwap_mod->name,
|
||||||
|
bindings_mod->name);
|
||||||
return cached_set->msgset;
|
return cached_set->msgset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +144,8 @@ struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
cw_dbg(DBG_INFO, "Loading message set for %s,%s", capwap_mod->name, bindings_mod->name);
|
cw_dbg(DBG_INFO, "Loading message set for %s,%s", capwap_mod->name,
|
||||||
|
bindings_mod->name);
|
||||||
|
|
||||||
|
|
||||||
if (capwap_mod) {
|
if (capwap_mod) {
|
||||||
@ -164,13 +167,15 @@ struct cw_MsgSet *cw_mod_get_msg_set(struct conn *conn,
|
|||||||
|
|
||||||
/* static mavl to store modules */
|
/* static mavl to store modules */
|
||||||
static struct mavl *mods_loaded = NULL;
|
static struct mavl *mods_loaded = NULL;
|
||||||
static int mod_cmp_mavl(const void *e1, const void *e2){
|
static int mod_cmp_mavl(const void *e1, const void *e2)
|
||||||
|
{
|
||||||
const struct cw_Mod *m1 = *((const struct cw_Mod **) e1);
|
const struct cw_Mod *m1 = *((const struct cw_Mod **) e1);
|
||||||
const struct cw_Mod *m2 = *((const struct cw_Mod **) e2);
|
const struct cw_Mod *m2 = *((const struct cw_Mod **) e2);
|
||||||
return strcmp(m1->name, m2->name);
|
return strcmp(m1->name, m2->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mod_cmp_mlist(const void *e1, const void *e2){
|
static int mod_cmp_mlist(const void *e1, const void *e2)
|
||||||
|
{
|
||||||
const struct cw_Mod *m1 = e1;
|
const struct cw_Mod *m1 = e1;
|
||||||
const struct cw_Mod *m2 = e2;
|
const struct cw_Mod *m2 = e2;
|
||||||
return strcmp(m1->name, m2->name);
|
return strcmp(m1->name, m2->name);
|
||||||
@ -184,7 +189,8 @@ static const char * mod_path="";
|
|||||||
* @brief Set module path, where to search for modules
|
* @brief Set module path, where to search for modules
|
||||||
* @param path Path to search
|
* @param path Path to search
|
||||||
*/
|
*/
|
||||||
void cw_mod_set_path(const char * path){
|
void cw_mod_set_path(const char *path)
|
||||||
|
{
|
||||||
mod_path = path;
|
mod_path = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,13 +199,13 @@ void cw_mod_set_path(const char * path){
|
|||||||
* @param mod_name Name of the module
|
* @param mod_name Name of the module
|
||||||
* @return a pointer to the module interface
|
* @return a pointer to the module interface
|
||||||
*/
|
*/
|
||||||
struct cw_Mod * cw_mod_load(const char * mod_name, mavl_t global_cfg, int role){
|
struct cw_Mod *cw_mod_load(const char *mod_name, mavl_t global_cfg, int role)
|
||||||
|
{
|
||||||
struct cw_Mod search;
|
struct cw_Mod search;
|
||||||
struct cw_Mod *mod;
|
struct cw_Mod *mod;
|
||||||
char mod_filename[CW_MOD_MAX_MOD_NAME_LEN + 5];
|
char mod_filename[CW_MOD_MAX_MOD_NAME_LEN + 5];
|
||||||
char *filename;
|
char *filename;
|
||||||
void *handle;
|
void *handle;
|
||||||
struct cw_Mod * (*mod_get_interface)();
|
|
||||||
|
|
||||||
/* if modlist is not initialized, initialize ... */
|
/* if modlist is not initialized, initialize ... */
|
||||||
if (mods_loaded == NULL) {
|
if (mods_loaded == NULL) {
|
||||||
@ -249,15 +255,12 @@ struct cw_Mod * cw_mod_load(const char * mod_name, mavl_t global_cfg, int role){
|
|||||||
goto errX;
|
goto errX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod = dlsym(handle, mod_filename);
|
||||||
mod_get_interface = (struct cw_Mod*(*)()) dlsym(handle,mod_filename);
|
if (mod == NULL) {
|
||||||
|
|
||||||
if (!mod_get_interface){
|
|
||||||
cw_log(LOG_ERROR, "Failed to load module: %s", dlerror());
|
cw_log(LOG_ERROR, "Failed to load module: %s", dlerror());
|
||||||
goto errX;
|
goto errX;
|
||||||
}
|
}
|
||||||
|
|
||||||
mod = mod_get_interface();
|
|
||||||
mod->dll_handle = handle;
|
mod->dll_handle = handle;
|
||||||
|
|
||||||
if (!mavl_add_ptr(mods_loaded, mod)) {
|
if (!mavl_add_ptr(mods_loaded, mod)) {
|
||||||
@ -275,7 +278,8 @@ errX:
|
|||||||
|
|
||||||
static struct mlist *mods_list = NULL;
|
static struct mlist *mods_list = NULL;
|
||||||
|
|
||||||
struct cw_Mod * cw_mod_add_to_list(struct cw_Mod * mod ){
|
struct cw_Mod *cw_mod_add_to_list(struct cw_Mod *mod)
|
||||||
|
{
|
||||||
mlistelem_t *elem;
|
mlistelem_t *elem;
|
||||||
if (!mods_list) {
|
if (!mods_list) {
|
||||||
mods_list = mlist_create(mod_cmp_mlist, NULL, sizeof(struct cw_Mod *));
|
mods_list = mlist_create(mod_cmp_mlist, NULL, sizeof(struct cw_Mod *));
|
||||||
@ -289,14 +293,12 @@ struct cw_Mod * cw_mod_add_to_list(struct cw_Mod * mod ){
|
|||||||
if (elem == NULL)
|
if (elem == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
return mlistelem_dataptr(elem);
|
return mlistelem_dataptr(elem);
|
||||||
|
|
||||||
/*return mlist_append(mods_list,mod)->data;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cw_Mod *cw_mod_detect(struct conn *conn,
|
struct cw_Mod *cw_mod_detect(struct conn *conn,
|
||||||
uint8_t * rawmsg, int len,
|
uint8_t * rawmsg, int len,
|
||||||
int elems_len, struct sockaddr *from,
|
int elems_len, struct sockaddr *from, int mode)
|
||||||
int mode){
|
{
|
||||||
|
|
||||||
struct mlistelem *e;
|
struct mlistelem *e;
|
||||||
|
|
||||||
@ -305,11 +307,10 @@ struct cw_Mod * cw_mod_detect(struct conn *conn,
|
|||||||
|
|
||||||
|
|
||||||
mlist_foreach(e, mods_list) {
|
mlist_foreach(e, mods_list) {
|
||||||
/* /// 1312 */
|
|
||||||
struct cw_Mod *mod = *(struct cw_Mod **) (mlistelem_dataptr(e)); /* = e->data; */
|
struct cw_Mod *mod = *(struct cw_Mod **) (mlistelem_dataptr(e)); /* = e->data; */
|
||||||
cw_dbg(DBG_MOD, "Checking mod: %s", mod->name);
|
cw_dbg(DBG_MOD, "Checking mod: %s", mod->name);
|
||||||
|
|
||||||
/*printf("Got the mod %p\n",mod);*/
|
|
||||||
/* if there is no detect method, skip */
|
/* if there is no detect method, skip */
|
||||||
if (!mod->detect)
|
if (!mod->detect)
|
||||||
continue;
|
continue;
|
||||||
|
@ -31,9 +31,6 @@
|
|||||||
#include "conn.h"
|
#include "conn.h"
|
||||||
|
|
||||||
|
|
||||||
struct cw_actiondef;
|
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
CW_MOD_MODE_CAPWAP,
|
CW_MOD_MODE_CAPWAP,
|
||||||
CW_MOD_MODE_BINDINGS
|
CW_MOD_MODE_BINDINGS
|
||||||
@ -85,12 +82,15 @@ extern struct cw_Mod mod_null;
|
|||||||
|
|
||||||
#define MOD_NULL (&mod_null)
|
#define MOD_NULL (&mod_null)
|
||||||
|
|
||||||
|
/*
|
||||||
struct cw_actiondef * mod_cache_add(struct conn *conn,struct cw_Mod *c, struct cw_Mod *b);
|
struct cw_actiondef * mod_cache_add(struct conn *conn,struct cw_Mod *c, struct cw_Mod *b);
|
||||||
|
*/
|
||||||
|
|
||||||
#define mod_init_config(mod,cfg) (mod->init_config ? mod->init_config(cfg):1)
|
#define mod_init_config(mod,cfg) (mod->init_config ? mod->init_config(cfg):1)
|
||||||
|
|
||||||
|
/*
|
||||||
void mod_set_actions_registered_cb(void (*fun) (struct cw_Mod *, struct cw_Mod *, struct cw_actiondef *));
|
void mod_set_actions_registered_cb(void (*fun) (struct cw_Mod *, struct cw_Mod *, struct cw_actiondef *));
|
||||||
|
*/
|
||||||
|
|
||||||
extern int mod_caching;
|
extern int mod_caching;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user