git-svn: trunk@4394
aCaB authored on 2008/11/13 11:11:21... | ... |
@@ -80,6 +80,7 @@ static pthread_mutex_t cli_ctime_mutex = PTHREAD_MUTEX_INITIALIZER; |
80 | 80 |
#include "md5.h" |
81 | 81 |
#include "cltypes.h" |
82 | 82 |
#include "regex/regex.h" |
83 |
+#include "ltdl.h" |
|
83 | 84 |
|
84 | 85 |
#ifndef O_BINARY |
85 | 86 |
#define O_BINARY 0 |
... | ... |
@@ -110,6 +111,38 @@ static unsigned char name_salt[16] = { 16, 38, 97, 12, 8, 4, 72, 196, 217, 144, |
110 | 110 |
fputs(buff, stderr); \ |
111 | 111 |
va_end(args) |
112 | 112 |
|
113 |
+int (*cli_unrar_open)(int fd, const char *dirname, unrar_state_t *state); |
|
114 |
+int (*cli_unrar_extract_next_prepare)(unrar_state_t *state, const char *dirname); |
|
115 |
+int (*cli_unrar_extract_next)(unrar_state_t *state, const char *dirname); |
|
116 |
+void (*cli_unrar_close)(unrar_state_t *state); |
|
117 |
+int have_rar = 0; |
|
118 |
+static int is_rar_initd = 0; |
|
119 |
+ |
|
120 |
+static void cli_rarload(void) { |
|
121 |
+ lt_dlhandle rhandle; |
|
122 |
+ |
|
123 |
+ if(is_rar_initd) return; |
|
124 |
+ is_rar_initd = 1; |
|
125 |
+ if(lt_dlinit()) { |
|
126 |
+ cli_warnmsg("Cannot init ltdl - unrar support unavailable\n"); |
|
127 |
+ return; |
|
128 |
+ } |
|
129 |
+ rhandle = lt_dlopenext("libclamunrar_iface"); |
|
130 |
+ if (!rhandle) { |
|
131 |
+ cli_dbgmsg("Cannot dlopen: %s - unrar support unavailable\n", lt_dlerror()); |
|
132 |
+ return; |
|
133 |
+ } |
|
134 |
+ if (!(cli_unrar_open = (int(*)(int, const char *, unrar_state_t *))lt_dlsym(rhandle, "unrar_open")) || |
|
135 |
+ !(cli_unrar_extract_next_prepare = (int(*)(unrar_state_t *, const char *))lt_dlsym(rhandle, "unrar_extract_next_prepare")) || |
|
136 |
+ !(cli_unrar_extract_next = (int(*)(unrar_state_t *, const char *))lt_dlsym(rhandle, "unrar_extract_next")) || |
|
137 |
+ !(cli_unrar_close = (void(*)(unrar_state_t *))lt_dlsym(rhandle, "unrar_close")) |
|
138 |
+ ) { |
|
139 |
+ /* ideally we should never land here, we'd better warn so */ |
|
140 |
+ cli_warnmsg("Cannot resolve: %s (version mismatch?) - unrar support unavailable\n", lt_dlerror()); |
|
141 |
+ return; |
|
142 |
+ } |
|
143 |
+ have_rar = 1; |
|
144 |
+} |
|
113 | 145 |
|
114 | 146 |
void cli_warnmsg(const char *str, ...) |
115 | 147 |
{ |
... | ... |
@@ -200,6 +233,7 @@ const char *cl_strerror(int clerror) |
200 | 200 |
int cl_init(unsigned int options) |
201 | 201 |
{ |
202 | 202 |
/* put dlopen() stuff here, etc. */ |
203 |
+ cli_rarload(); |
|
203 | 204 |
return CL_SUCCESS; |
204 | 205 |
} |
205 | 206 |
|
... | ... |
@@ -33,6 +33,7 @@ |
33 | 33 |
|
34 | 34 |
#include "clamav.h" |
35 | 35 |
#include "dconf.h" |
36 |
+#include "libclamunrar_iface/unrar_iface.h" |
|
36 | 37 |
|
37 | 38 |
extern uint8_t cli_debug_flag, cli_leavetemps_flag; |
38 | 39 |
|
... | ... |
@@ -154,6 +155,12 @@ struct cl_engine { |
154 | 154 |
mp_t *mempool; |
155 | 155 |
}; |
156 | 156 |
|
157 |
+extern int (*cli_unrar_open)(int fd, const char *dirname, unrar_state_t *state); |
|
158 |
+extern int (*cli_unrar_extract_next_prepare)(unrar_state_t *state, const char *dirname); |
|
159 |
+extern int (*cli_unrar_extract_next)(unrar_state_t *state, const char *dirname); |
|
160 |
+extern void (*cli_unrar_close)(unrar_state_t *state); |
|
161 |
+extern int have_rar; |
|
162 |
+ |
|
157 | 163 |
#define SCAN_ARCHIVE (ctx->options & CL_SCAN_ARCHIVE) |
158 | 164 |
#define SCAN_MAIL (ctx->options & CL_SCAN_MAIL) |
159 | 165 |
#define SCAN_OLE2 (ctx->options & CL_SCAN_OLE2) |
... | ... |
@@ -67,51 +67,12 @@ |
67 | 67 |
#include <stddef.h> |
68 | 68 |
#endif |
69 | 69 |
|
70 |
-#include "ltdl.h" |
|
71 | 70 |
#include "mpool.h" |
72 |
-#include "libclamunrar_iface/unrar_iface.h" |
|
73 | 71 |
|
74 | 72 |
#ifdef CL_THREAD_SAFE |
75 | 73 |
# include <pthread.h> |
76 | 74 |
static pthread_mutex_t cli_ref_mutex = PTHREAD_MUTEX_INITIALIZER; |
77 |
-static pthread_once_t is_rar_initd = PTHREAD_ONCE_INIT; |
|
78 |
-#else |
|
79 |
-static int is_rar_initd = 0; |
|
80 |
-#endif |
|
81 |
- |
|
82 |
-int (*cli_unrar_open)(int fd, const char *dirname, unrar_state_t *state); |
|
83 |
-int (*cli_unrar_extract_next_prepare)(unrar_state_t *state, const char *dirname); |
|
84 |
-int (*cli_unrar_extract_next)(unrar_state_t *state, const char *dirname); |
|
85 |
-void (*cli_unrar_close)(unrar_state_t *state); |
|
86 |
-int have_rar = 0; |
|
87 |
- |
|
88 |
-static void cli_rarload(void) { |
|
89 |
- lt_dlhandle rhandle; |
|
90 |
- |
|
91 |
-#ifndef CL_THREAD_SAFE |
|
92 |
- if(is_rar_initd) return; |
|
93 |
- is_rar_initd = 1; |
|
94 | 75 |
#endif |
95 |
- if(lt_dlinit()) { |
|
96 |
- cli_warnmsg("Cannot init ltdl - unrar support unavailable\n"); |
|
97 |
- return; |
|
98 |
- } |
|
99 |
- rhandle = lt_dlopenext("libclamunrar_iface"); |
|
100 |
- if (!rhandle) { |
|
101 |
- cli_dbgmsg("Cannot dlopen: %s - unrar support unavailable\n", lt_dlerror()); |
|
102 |
- return; |
|
103 |
- } |
|
104 |
- if (!(cli_unrar_open = (int(*)(int, const char *, unrar_state_t *))lt_dlsym(rhandle, "unrar_open")) || |
|
105 |
- !(cli_unrar_extract_next_prepare = (int(*)(unrar_state_t *, const char *))lt_dlsym(rhandle, "unrar_extract_next_prepare")) || |
|
106 |
- !(cli_unrar_extract_next = (int(*)(unrar_state_t *, const char *))lt_dlsym(rhandle, "unrar_extract_next")) || |
|
107 |
- !(cli_unrar_close = (void(*)(unrar_state_t *))lt_dlsym(rhandle, "unrar_close")) |
|
108 |
- ) { |
|
109 |
- /* ideally we should never land here, we'd better warn so */ |
|
110 |
- cli_warnmsg("Cannot resolve: %s (version mismatch?) - unrar support unavailable\n", lt_dlerror()); |
|
111 |
- return; |
|
112 |
- } |
|
113 |
- have_rar = 1; |
|
114 |
-} |
|
115 | 76 |
|
116 | 77 |
struct cli_ignsig { |
117 | 78 |
char *dbname, *signame; |
... | ... |
@@ -2066,12 +2027,6 @@ int cl_engine_compile(struct cl_engine *engine) |
2066 | 2066 |
if(!engine) |
2067 | 2067 |
return CL_ENULLARG; |
2068 | 2068 |
|
2069 |
-#ifdef CL_THREAD_SAFE |
|
2070 |
- pthread_once(&is_rar_initd, cli_rarload); |
|
2071 |
-#else |
|
2072 |
- cli_rarload(); |
|
2073 |
-#endif |
|
2074 |
- |
|
2075 | 2069 |
if(!engine->ftypes) |
2076 | 2070 |
if((ret = cli_loadftm(NULL, engine, 0, 1, NULL))) |
2077 | 2071 |
return ret; |
... | ... |
@@ -96,19 +96,11 @@ |
96 | 96 |
#include <bzlib.h> |
97 | 97 |
#endif |
98 | 98 |
|
99 |
-#include "libclamunrar_iface/unrar_iface.h" |
|
100 |
- |
|
101 | 99 |
#if defined(HAVE_READDIR_R_3) || defined(HAVE_READDIR_R_2) |
102 | 100 |
#include <limits.h> |
103 | 101 |
#include <stddef.h> |
104 | 102 |
#endif |
105 | 103 |
|
106 |
-extern int (*cli_unrar_open)(int fd, const char *dirname, unrar_state_t *state); |
|
107 |
-extern int (*cli_unrar_extract_next_prepare)(unrar_state_t *state, const char *dirname); |
|
108 |
-extern int (*cli_unrar_extract_next)(unrar_state_t *state, const char *dirname); |
|
109 |
-extern void (*cli_unrar_close)(unrar_state_t *state); |
|
110 |
-extern int have_rar; |
|
111 |
- |
|
112 | 104 |
static int cli_scanfile(const char *filename, cli_ctx *ctx); |
113 | 105 |
|
114 | 106 |
static int cli_scandir(const char *dirname, cli_ctx *ctx, cli_file_t container) |