24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
27 */ |
27 */ |
28 |
28 |
|
29 #include <dlfcn.h> |
|
30 |
29 #include "init.h" |
31 #include "init.h" |
|
32 #include "../ucx/string.h" |
|
33 #include "../daemon/func.h" |
30 |
34 |
31 int init_test(pblock *pb, Session *sn, Request *rq) { |
35 int init_test(pblock *pb, Session *sn, Request *rq) { |
32 printf("init-test\n"); |
36 printf("init-test\n"); |
33 return REQ_PROCEED; |
37 return REQ_PROCEED; |
34 } |
38 } |
|
39 |
|
40 int load_modules(pblock *pb, Session *sn, Request *rq) { |
|
41 printf("load_modules\n"); |
|
42 |
|
43 char *shlib = pblock_findval("shlib", pb); |
|
44 char *funcs = pblock_findval("funcs", pb); |
|
45 |
|
46 if(shlib == NULL || funcs == NULL) { |
|
47 fprintf(stderr, "load-modules: missing parameter\n"); |
|
48 } |
|
49 |
|
50 /* load lib */ |
|
51 void *lib = dlopen(shlib, RTLD_GLOBAL | RTLD_NOW); |
|
52 if(lib == NULL) { |
|
53 fprintf(stderr, "Cannot load library %s\n", shlib); |
|
54 return REQ_ABORTED; |
|
55 } |
|
56 |
|
57 /* load function symbols */ |
|
58 int b = 0; |
|
59 for(int i=0;;i++) { |
|
60 if(funcs[i] == ',' || funcs[i] == 0) { |
|
61 if(funcs[i] == 0) { |
|
62 b = 1; |
|
63 } |
|
64 |
|
65 funcs[i] = 0; |
|
66 |
|
67 /* we have a function name */ |
|
68 void *sym = dlsym(lib, funcs); |
|
69 if(sym == NULL) { |
|
70 fprintf(stderr, "Cannot load symbol %s\n", funcs); |
|
71 return REQ_ABORTED; |
|
72 } |
|
73 struct FuncStruct fc; |
|
74 fc.func = (FuncPtr)sym; |
|
75 fc.name = sstrdub(sstr(funcs)).ptr; |
|
76 add_function(&fc); |
|
77 |
|
78 if(b) { |
|
79 break; |
|
80 } |
|
81 |
|
82 funcs += i + 1; |
|
83 i = 0; |
|
84 } |
|
85 } |
|
86 |
|
87 return REQ_PROCEED; |
|
88 } |