diff -r d680536f8c2f -r 7b235fa88008 src/server/safs/init.c --- a/src/server/safs/init.c Sat Jan 21 16:37:35 2012 +0100 +++ b/src/server/safs/init.c Sat Jan 28 16:01:07 2012 +0100 @@ -26,9 +26,63 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include + #include "init.h" +#include "../ucx/string.h" +#include "../daemon/func.h" int init_test(pblock *pb, Session *sn, Request *rq) { printf("init-test\n"); return REQ_PROCEED; } + +int load_modules(pblock *pb, Session *sn, Request *rq) { + printf("load_modules\n"); + + char *shlib = pblock_findval("shlib", pb); + char *funcs = pblock_findval("funcs", pb); + + if(shlib == NULL || funcs == NULL) { + fprintf(stderr, "load-modules: missing parameter\n"); + } + + /* load lib */ + void *lib = dlopen(shlib, RTLD_GLOBAL | RTLD_NOW); + if(lib == NULL) { + fprintf(stderr, "Cannot load library %s\n", shlib); + return REQ_ABORTED; + } + + /* load function symbols */ + int b = 0; + for(int i=0;;i++) { + if(funcs[i] == ',' || funcs[i] == 0) { + if(funcs[i] == 0) { + b = 1; + } + + funcs[i] = 0; + + /* we have a function name */ + void *sym = dlsym(lib, funcs); + if(sym == NULL) { + fprintf(stderr, "Cannot load symbol %s\n", funcs); + return REQ_ABORTED; + } + struct FuncStruct fc; + fc.func = (FuncPtr)sym; + fc.name = sstrdub(sstr(funcs)).ptr; + add_function(&fc); + + if(b) { + break; + } + + funcs += i + 1; + i = 0; + } + } + + return REQ_PROCEED; +}