diff --git a/actube.workspace b/actube.workspace
index b8870938..e0162c79 100644
--- a/actube.workspace
+++ b/actube.workspace
@@ -3,9 +3,9 @@
-
+
-
+
diff --git a/src/ac/conf.c b/src/ac/conf.c
index bf683a1e..1d67ee1a 100644
--- a/src/ac/conf.c
+++ b/src/ac/conf.c
@@ -38,7 +38,7 @@ uint8_t conf_macaddress_len = 0;
long conf_strict_capwap = 1;
long conf_strict_headers = 0;
-char *conf_capwap_mode_str = NULL;
+//char *conf_capwap_mode_str = NULL;
int conf_capwap_mode = CW_MODE_CAPWAP;
@@ -540,7 +540,7 @@ static int conf_read_dbg_level(cfg_t * cfg)
struct cw_Mod ** conf_mods; //[10];
-
+char *conf_mods_dir = NULL;
static int init_mods()
@@ -571,20 +571,29 @@ static int conf_read_mods(cfg_t *cfg){
n = cfg_size(cfg,CFG_ENTRY_MODS);
conf_mods = malloc(sizeof(struct cw_Mod *)*(n+1));
-
+
+ cw_dbg(DBG_INFO,"Mods directory: %s",conf_mods_dir);
+
for (i=0; i < n; i++){
char *modname = cfg_getnstr(cfg, CFG_ENTRY_MODS, i);
- conf_mods[i] = NULL; //modload_ac(modname);
+
+ struct cw_Mod * mod = cw_mod_add_dynamic(conf_mods_dir,modname);
+ if (!mod)
+ return 0;
+
+/* conf_mods[i] = NULL; //modload_ac(modname);
if (!conf_mods[i]){
cw_log(LOG_ERR,"Can't load mod: %s",modname);
return 0;
}
+*/
+
}
- conf_mods[i]=NULL;
+
return 1;
}
-
+/*
void conf_init_capwap_mode()
{
if (conf_capwap_mode_str == NULL)
@@ -600,7 +609,7 @@ void conf_init_capwap_mode()
}
-
+*/
int conf_parse_listen_addr(const char *addrstr, char *saddr, char *port, int *proto)
@@ -700,6 +709,8 @@ int read_config(const char *filename)
cfg_opt_t opts[] = {
CFG_STR_LIST("mods", "{}", CFGF_NONE),
+ CFG_SIMPLE_STR("mods_dir", &conf_mods_dir),
+
CFG_STR_LIST("dbg", "{}", CFGF_NONE),
CFG_STR_LIST("listen", "{}", CFGF_NONE),
CFG_STR_LIST("mcast_groups", "{}", CFGF_NONE),
@@ -710,7 +721,7 @@ int read_config(const char *filename)
CFG_SIMPLE_BOOL("strict_capwap", &conf_strict_capwap),
CFG_SIMPLE_BOOL("strict_headers", &conf_strict_headers),
CFG_SIMPLE_BOOL("use_loopback", &conf_use_loopback),
- CFG_SIMPLE_STR("capwap_mode", &conf_capwap_mode_str),
+// CFG_SIMPLE_STR("capwap_mode", &conf_capwap_mode_str),
#ifdef WITH_LWAPP
@@ -817,7 +828,7 @@ int read_config(const char *filename)
init_mods();
- conf_init_capwap_mode();
+// conf_init_capwap_mode();
init_listen_addrs();
diff --git a/src/cw/Makefile b/src/cw/Makefile
index 420b45fa..8984a7c5 100644
--- a/src/cw/Makefile
+++ b/src/cw/Makefile
@@ -3,7 +3,8 @@ include ../CWConfig.mak
-include ../Config.local.mak
-LIBARCHDIR := ../../lib/$(ARCH)
+LIBDIR := ../../lib
+LIBARCHDIR := $(LIBDIR)/$(ARCH)
OBJDIR := ../../obj/cw/$(ARCH)
SNAME := $(LIBARCHDIR)/libcw.a
diff --git a/src/cw/mod.c b/src/cw/mod.c
index fd6ce57b..ca391e22 100644
--- a/src/cw/mod.c
+++ b/src/cw/mod.c
@@ -144,9 +144,9 @@ struct cw_actiondef *mod_cache_add(struct conn *conn, struct cw_Mod *c, struct c
/* static mavl to store modules */
static struct mavl * modlist = NULL;
static int mod_cmp(const void *e1, const void *e2){
- struct cw_Mod * (*m1fn)() = e1;
- struct cw_Mod * (*m2fn)() = e2;
- return strcmp(m1fn()->name,m2fn()->name);
+ struct cw_Mod * m1 = e1;
+ struct cw_Mod * m2 = e2;
+ return strcmp(m1->name,m2->name);
}
@@ -182,32 +182,50 @@ int cw_mod_add(struct cw_Mod * (*modfn)() ){
}
-int cw_mod_add_dynamic(const char * path, const char * mod_name){
-
- char * filename = malloc(strlen(path)+strlen(mod_name)+8);
+struct cw_Mod * cw_mod_add_dynamic(const char * path, const char * mod_name){
+
+ /* Search for the module in modlist, to see if it is
+ * already loaded or was statically linked */
+ struct cw_Mod search;
+ memset(&search,0,sizeof(search));
+ search.name=mod_name;
+ struct cw_Mod * mod;
+ mod = mavl_find(modlist,&search);
+ if (mod){
+ return mod;
+ }
+
+
+ int n = strlen(path)+strlen(mod_name)+8;
+
+ char * filename = malloc(n);
+
if (!filename)
return 0;
strcpy(filename,path);
strcat(filename,"/");
strcat(filename,mod_name);
strcat(filename,".so");
-
- int rc=0;
-
+
+ /* Open the DLL */
void * handle;
handle = dlopen(filename,RTLD_NOW);
+
if (!handle){
cw_log(LOG_ERROR,"Failed to load module: %s",dlerror());
goto errX;
}
- void * ifu = dlsym(handle,"mod_get_interface");
- if (!ifu){
+ struct cw_Mod * (*mod_get_interface)();
+ mod_get_interface = dlsym(handle,"mod_get_interface");
+ if (!mod_get_interface){
cw_log(LOG_ERROR,"Failed to load module: %s",dlerror());
goto errX;
}
+ mod = mod_get_interface();
+ mod->init();
errX:
free(filename);
- return rc;
+ return mod;
}
\ No newline at end of file
diff --git a/src/cw/mod.h b/src/cw/mod.h
index e5d8d26c..bdb4e498 100644
--- a/src/cw/mod.h
+++ b/src/cw/mod.h
@@ -64,6 +64,11 @@ struct cw_Mod {
int (*register_actions) (struct cw_actiondef * def,int mode);
struct cw_MsgSet * (*register_messages)(struct cw_MsgSet set, int mode);
+
+ /**
+ * Handle returned by dlopen, if this module was loaded dynamically
+ * with dlopen */
+ void * handle;
};
@@ -84,6 +89,6 @@ extern int mod_caching;
#define mod_set_caching(var) (mod_caching=var)
#define mod_get_caching() (mod_caching)
-extern int cw_mod_add_dynamic(const char * path, const char * file);
+struct cw_Mod * cw_mod_add_dynamic(const char * path, const char * file);
#endif
diff --git a/src/mod/Mod.mak b/src/mod/Mod.mak
index 389f663f..8ad1d35a 100644
--- a/src/mod/Mod.mak
+++ b/src/mod/Mod.mak
@@ -10,7 +10,7 @@ CFLAGS = -fPIC -Wall -g -O0 -D_REENTRANT -DWITH_IPV6 $(COMPDEFS) -DWITH_RMAC_SUP
SRCS = $(OBJS:.o=.c)
-all: $(SNAME) $(DNAME)
+all: $(SNAME) $(DNAME) $(MODNAME)
$(OBJDIR)/%.o:%.c
@mkdir -p $(OBJDIR)
@@ -19,20 +19,25 @@ $(OBJDIR)/%.o:%.c
$(SNAME) : $(OBJS) $(MODOBJS)
- @mkdir -p $(LIBDIR)
+ @mkdir -p $(LIBARCHDIR)
@echo " $(AR) $(SNAME)"
@$(AR) rcs $(SNAME) $(OBJS) $(MODOBJS)
$(DNAME) : $(OBJS) $(MODOBJS)
- @mkdir -p $(LIBDIR)
+ @mkdir -p $(LIBARCHDIR)
@echo " $(CC) $(DNAME)"
- @$(CC) $(LDFLAGS) -shared -o $(DNAME) $(OBJS) $(MODOBJS) $(LIBS)
+ @$(CC) -L$(LIBARCHDIR) $(LDFLAGS) -shared -o $(DNAME) $(OBJS) $(MODOBJS) $(SLIBS) $(LIBS)
-# $(CC) -L$(LIBDIR) $(OBJS) $(MODOBJS) $(SLIBS) -v -shared -o ../../../lib/actube/capwap.so
+$(MODNAME) : $(DNAME)
+ cp $(DNAME) $(MODNAME)
+
+# $(CC) -L$(LIBARCHDIR) $(OBJS) $(MODOBJS) $(SLIBS) -v -shared -o ../../../lib/actube/capwap.so
clean:
rm -rf $(OBJDIR)
rm -f $(SNAME)
+ rm -f $(DNAME)
+ rm -f $(MODNAME)
diff --git a/src/mod/capwap/Makefile b/src/mod/capwap/Makefile
index 0ebbce86..42ef6bda 100644
--- a/src/mod/capwap/Makefile
+++ b/src/mod/capwap/Makefile
@@ -19,10 +19,12 @@ OBJS=\
capwap_in_session_id.o \
-LIBDIR := ../../../lib/$(ARCH)
+LIBDIR := ../../../lib
+LIBARCHDIR := $(LIBDIR)/$(ARCH)
OBJDIR := ../../../obj/mod_capwap/$(ARCH)
-SNAME := $(LIBDIR)/libcapwap.a
-DNAME := $(LIBDIR)/capwap.so
+SNAME := $(LIBARCHDIR)/libcapwap.a
+DNAME := $(LIBARCHDIR)/capwap.so
+MODNAME := $(LIBDIR)/capwap.so
SLIBS := -lcw
include ../Mod.mak