-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdecoder.c
91 lines (72 loc) · 2.42 KB
/
decoder.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <stdlib.h>
#include <dlfcn.h>
#include <stdio.h>
#include "decoder.h"
#define BUF_SIZE 1024
int sendbufsize = 0;
int recvbufsize = 0;
int (*client_decoder_init)(Client *client) = NULL;
int (*client_decoder_clear)(Client *client) = NULL;
int (*client_decode)(Client *client) = NULL;
int (*client_decoder_destroy)(Client *client) = NULL;
int load_decoder(char *decoder, char *decoder_dir)
{
void * hndl;
int * bufsize;
char path[BUF_SIZE];
snprintf(path, BUF_SIZE, "%s", decoder);
hndl = dlopen(path, RTLD_LAZY);
if (hndl != NULL) { goto loaded; }
snprintf(path, BUF_SIZE, "lib%s.so", decoder);
hndl = dlopen(path, RTLD_LAZY);
if (hndl != NULL) { goto loaded; }
if (decoder_dir != NULL) {
snprintf(path, BUF_SIZE, "%s/lib%s.so", decoder_dir, decoder);
hndl = dlopen(path, RTLD_LAZY);
if (hndl != NULL) { goto loaded; }
}
snprintf(path, BUF_SIZE, "/lib/tcphub/lib%s.so", decoder);
hndl = dlopen(path, RTLD_LAZY);
if (hndl != NULL) { goto loaded; }
snprintf(path, BUF_SIZE, "/usr/lib/tcphub/lib%s.so", decoder);
hndl = dlopen(path, RTLD_LAZY);
if (hndl != NULL) { goto loaded; }
snprintf(path, BUF_SIZE, "/usr/local/lib/tcphub/lib%s.so", decoder);
hndl = dlopen(path, RTLD_LAZY);
if (hndl != NULL) { goto loaded; }
return -1;
loaded:
printf("Decoder loaded from '%s'\n", path);
client_decoder_init = dlsym(hndl, "client_decoder_init");
if (client_decoder_init == NULL) {
fprintf(stderr, "dlsym: %s\n", dlerror());
return -1;
}
client_decoder_clear = dlsym(hndl, "client_decoder_clear");
if (client_decoder_clear == NULL) {
fprintf(stderr, "dlsym: %s\n", dlerror());
return -1;
}
client_decode = dlsym(hndl, "client_decode");
if (client_decode == NULL) {
fprintf(stderr, "dlsym: %s\n", dlerror());
return -1;
}
client_decoder_destroy = dlsym(hndl, "client_decoder_destroy");
if (client_decoder_destroy == NULL) {
fprintf(stderr, "dlsym: %s\n", dlerror());
return -1;
}
bufsize = dlsym(hndl, "sendbufsize");
if (bufsize == NULL) {
fprintf(stderr, "dlsym: %s\n", dlerror());
return -1;
}
sendbufsize = *bufsize;
bufsize = dlsym(hndl, "recvbufsize");
if (bufsize == NULL) {
fprintf(stderr, "dlsym: %s\n", dlerror());
return -1;
}
recvbufsize = *bufsize;
}