git-svn: trunk@2322
Nigel Horne authored on 2006/09/28 01:30:12... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Wed Sep 27 17:29:24 BST 2006 (njh) |
|
2 |
+---------------------------------- |
|
3 |
+ * libclamav/mbox.c: CL_EXPERIMENTAL now compiles under VS2005 |
|
4 |
+ |
|
1 | 5 |
Wed Sep 27 15:26:45 BST 2006 (njh) |
2 | 6 |
---------------------------------- |
3 | 7 |
* libclamav: Ported the experimental anti-phish code to VS2005 |
... | ... |
@@ -16,7 +16,11 @@ |
16 | 16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
17 | 17 |
* MA 02110-1301, USA. |
18 | 18 |
*/ |
19 |
-static char const rcsid[] = "$Id: mbox.c,v 1.345 2006/09/26 19:41:43 njh Exp $"; |
|
19 |
+static char const rcsid[] = "$Id: mbox.c,v 1.346 2006/09/27 16:28:48 njh Exp $"; |
|
20 |
+ |
|
21 |
+#ifdef _MSC_VER |
|
22 |
+#include <winsock.h> /* only needed in CL_EXPERIMENTAL */ |
|
23 |
+#endif |
|
20 | 24 |
|
21 | 25 |
#if HAVE_CONFIG_H |
22 | 26 |
#include "clamav-config.h" |
... | ... |
@@ -142,6 +146,44 @@ typedef enum { FALSE = 0, TRUE = 1 } bool; |
142 | 142 |
|
143 | 143 |
#ifdef FOLLOWURLS |
144 | 144 |
|
145 |
+#ifdef CL_EXPERIMENTAL /* dropping curl support */ |
|
146 |
+ |
|
147 |
+#ifndef C_WINDOWS |
|
148 |
+#include <netdb.h> |
|
149 |
+#include <sys/socket.h> |
|
150 |
+#include <netinet/in.h> |
|
151 |
+#include <net/if.h> |
|
152 |
+#include <arpa/inet.h> |
|
153 |
+#endif |
|
154 |
+#include <fcntl.h> |
|
155 |
+#ifndef C_WINDOWS |
|
156 |
+#include <sys/time.h> |
|
157 |
+#endif |
|
158 |
+ |
|
159 |
+#ifndef HAVE_IN_PORT_T |
|
160 |
+typedef unsigned short in_port_t; |
|
161 |
+#endif |
|
162 |
+ |
|
163 |
+#ifndef HAVE_IN_ADDR_T |
|
164 |
+typedef unsigned int in_addr_t; |
|
165 |
+#endif |
|
166 |
+ |
|
167 |
+#if (!defined(EALREADY)) && (defined(WSAEALREADY)) |
|
168 |
+#define EALREADY WSAEALREADY |
|
169 |
+#endif |
|
170 |
+#if (!defined(EINPROGRESS)) && (defined(WSAEINPROGRESS)) |
|
171 |
+#define EINPROGRESS WSAEINPROGRESS |
|
172 |
+#endif |
|
173 |
+#if (!defined(EISCONN)) && (defined(WSAEISCONN)) |
|
174 |
+#define EISCONN WSAEISCONN |
|
175 |
+#endif |
|
176 |
+ |
|
177 |
+#ifndef C_WINDOWS |
|
178 |
+#define closesocket(s) close(s) |
|
179 |
+#endif |
|
180 |
+ |
|
181 |
+#else |
|
182 |
+ |
|
145 | 183 |
#ifdef WITH_CURL /* Set in configure */ |
146 | 184 |
/* |
147 | 185 |
* To build with WITH_CURL: |
... | ... |
@@ -183,6 +225,8 @@ typedef enum { FALSE = 0, TRUE = 1 } bool; |
183 | 183 |
|
184 | 184 |
#endif /*WITH_CURL*/ |
185 | 185 |
|
186 |
+#endif /* CL_EXPERIMENTAL */ |
|
187 |
+ |
|
186 | 188 |
#else /*!FOLLOWURLS*/ |
187 | 189 |
#undef WITH_CURL |
188 | 190 |
#endif /*FOLLOWURLS*/ |
... | ... |
@@ -250,10 +294,10 @@ static void hrefs_done(blob *b,tag_arguments_t* hrefs); |
250 | 250 |
|
251 | 251 |
#ifdef WITH_CURL |
252 | 252 |
struct arg { |
253 |
- CURL *curl; |
|
254 | 253 |
#ifdef CL_EXPERIMENTAL |
255 | 254 |
char *url; |
256 | 255 |
#else |
256 |
+ CURL *curl; |
|
257 | 257 |
const char *url; |
258 | 258 |
#endif |
259 | 259 |
const char *dir; |
... | ... |
@@ -1180,7 +1224,7 @@ cli_parse_mbox(const char *dir, int desc, cli_ctx *ctx) |
1180 | 1180 |
char tmpfilename[16]; |
1181 | 1181 |
int tmpfd; |
1182 | 1182 |
#endif |
1183 |
-#ifdef FOLLOWURLS |
|
1183 |
+#if defined(FOLLOWURLS) && (!defined(CL_EXPERIMENTAL)) |
|
1184 | 1184 |
static int initialised = 0; |
1185 | 1185 |
#ifdef CL_THREAD_SAFE |
1186 | 1186 |
static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER; |
... | ... |
@@ -1193,7 +1237,7 @@ cli_parse_mbox(const char *dir, int desc, cli_ctx *ctx) |
1193 | 1193 |
cli_dbgmsg("in mbox()\n"); |
1194 | 1194 |
#endif |
1195 | 1195 |
|
1196 |
-#ifdef FOLLOWURLS |
|
1196 |
+#if defined(FOLLOWURLS) && (!defined(CL_EXPERIMENTAL)) |
|
1197 | 1197 |
if(ctx->options&CL_SCAN_MAILURL) { |
1198 | 1198 |
#ifdef CL_THREAD_SAFE |
1199 | 1199 |
pthread_mutex_lock(&init_mutex); |
... | ... |
@@ -3824,7 +3868,7 @@ getHrefs(message *m, tag_arguments_t *hrefs) |
3824 | 3824 |
hrefs->contents = NULL; |
3825 | 3825 |
|
3826 | 3826 |
cli_dbgmsg("getHrefs: calling html_normalise_mem\n"); |
3827 |
- if(!html_normalise_mem(blobGetData(b), len, NULL, hrefs)) { |
|
3827 |
+ if(!html_normalise_mem(blobGetData(b), (off_t)len, NULL, hrefs)) { |
|
3828 | 3828 |
blobDestroy(b); |
3829 | 3829 |
return NULL; |
3830 | 3830 |
} |
... | ... |
@@ -3941,22 +3985,11 @@ do_checkURLs(message *m, const char *dir, tag_arguments_t *hrefs) |
3941 | 3941 |
|
3942 | 3942 |
#ifdef WITH_CURL |
3943 | 3943 |
#ifdef CL_THREAD_SAFE |
3944 |
- args[n].curl = curl_easy_init(); |
|
3945 |
- if(args[n].curl == NULL) { |
|
3946 |
- cli_errmsg("curl_easy_init failed\n"); |
|
3947 |
- continue; |
|
3948 |
- } |
|
3949 | 3944 |
args[n].dir = dir; |
3950 | 3945 |
args[n].url = strdup(url); |
3951 | 3946 |
args[n].filename = strdup(name); |
3952 | 3947 |
pthread_create(&tid[n], NULL, getURL, &args[n]); |
3953 | 3948 |
#else |
3954 |
- /* easy isn't the word I'd use... */ |
|
3955 |
- arg.curl = curl_easy_init(); |
|
3956 |
- if(arg.curl == NULL) { |
|
3957 |
- cli_errmsg("curl_easy_init failed\n"); |
|
3958 |
- continue; |
|
3959 |
- } |
|
3960 | 3949 |
arg.url = strdup(url); |
3961 | 3950 |
arg.dir = dir; |
3962 | 3951 |
arg.filename = name; |
... | ... |
@@ -4008,7 +4041,6 @@ do_checkURLs(message *m, const char *dir, tag_arguments_t *hrefs) |
4008 | 4008 |
pthread_join(tid[n], NULL); |
4009 | 4009 |
free(args[n].filename); |
4010 | 4010 |
free(args[n].url); |
4011 |
- curl_easy_cleanup(args[n].curl); |
|
4012 | 4011 |
} |
4013 | 4012 |
#endif |
4014 | 4013 |
} |
... | ... |
@@ -4226,17 +4258,6 @@ checkURLs(message *m, mbox_ctx *mctx, int* rc, int is_html) |
4226 | 4226 |
* Includes some of the freshclam hacks by Everton da Silva Marques |
4227 | 4227 |
* everton.marques@gmail.com> |
4228 | 4228 |
*/ |
4229 |
-#include <netdb.h> |
|
4230 |
-#include <sys/socket.h> |
|
4231 |
-#include <netinet/in.h> |
|
4232 |
-#include <net/if.h> |
|
4233 |
-#include <arpa/inet.h> |
|
4234 |
-#include <ctype.h> |
|
4235 |
-#include <errno.h> |
|
4236 |
-#include <fcntl.h> |
|
4237 |
-#include <sys/time.h> |
|
4238 |
-#include <stdlib.h> |
|
4239 |
- |
|
4240 | 4229 |
#ifndef timercmp |
4241 | 4230 |
# define timercmp(a, b, cmp) \ |
4242 | 4231 |
(((a)->tv_sec == (b)->tv_sec) ? \ |
... | ... |
@@ -4280,9 +4301,18 @@ getURL(struct arg *arg) |
4280 | 4280 |
const char *dir = arg->dir; |
4281 | 4281 |
const char *filename = arg->filename; |
4282 | 4282 |
char fout[NAME_MAX + 1]; |
4283 |
- int sd, n; |
|
4283 |
+#ifdef C_WINDOWS |
|
4284 |
+ SOCKET sd; |
|
4285 |
+#else |
|
4286 |
+ int sd; |
|
4287 |
+#endif |
|
4288 |
+ int n; |
|
4284 | 4289 |
struct sockaddr_in server; |
4290 |
+#ifdef HAVE_IN_ADDR_T |
|
4285 | 4291 |
in_addr_t ip; |
4292 |
+#else |
|
4293 |
+ int ip; |
|
4294 |
+#endif |
|
4286 | 4295 |
char buf[BUFSIZ]; |
4287 | 4296 |
char site[BUFSIZ]; |
4288 | 4297 |
in_port_t port; |
... | ... |
@@ -4317,7 +4347,9 @@ getURL(struct arg *arg) |
4317 | 4317 |
return NULL; |
4318 | 4318 |
} |
4319 | 4319 |
tcp = proto->p_proto; |
4320 |
+#ifndef C_WINDOWS |
|
4320 | 4321 |
endprotoent(); |
4322 |
+#endif |
|
4321 | 4323 |
} |
4322 | 4324 |
if(default_port == 0) { |
4323 | 4325 |
const struct servent *servent = getservbyname("http", "tcp"); |
... | ... |
@@ -4326,7 +4358,9 @@ getURL(struct arg *arg) |
4326 | 4326 |
default_port = (in_port_t)ntohs(servent->s_port); |
4327 | 4327 |
else |
4328 | 4328 |
default_port = 80; |
4329 |
+#ifndef C_WINDOWS |
|
4329 | 4330 |
endservent(); |
4331 |
+#endif |
|
4330 | 4332 |
} |
4331 | 4333 |
port = default_port; |
4332 | 4334 |
|
... | ... |
@@ -4419,7 +4453,7 @@ getURL(struct arg *arg) |
4419 | 4419 |
} |
4420 | 4420 |
flags = nonblock_fcntl(sd); |
4421 | 4421 |
if(nonblock_connect(sd, (struct sockaddr *)&server, sizeof(struct sockaddr_in), 5) < 0) { |
4422 |
- close(sd); |
|
4422 |
+ closesocket(sd); |
|
4423 | 4423 |
fclose(fp); |
4424 | 4424 |
return NULL; |
4425 | 4425 |
} |
... | ... |
@@ -4437,13 +4471,17 @@ getURL(struct arg *arg) |
4437 | 4437 |
|
4438 | 4438 |
cli_dbgmsg("%s\n", buf); |
4439 | 4439 |
|
4440 |
- if(send(sd, buf, strlen(buf), 0) < 0) { |
|
4441 |
- close(sd); |
|
4440 |
+ if(send(sd, buf, (int)strlen(buf), 0) < 0) { |
|
4441 |
+ closesocket(sd); |
|
4442 | 4442 |
fclose(fp); |
4443 | 4443 |
return NULL; |
4444 | 4444 |
} |
4445 | 4445 |
|
4446 |
+#ifdef SHUT_WR |
|
4446 | 4447 |
shutdown(sd, SHUT_WR); |
4448 |
+#else |
|
4449 |
+ shutdown(sd, 1); |
|
4450 |
+#endif |
|
4447 | 4451 |
|
4448 | 4452 |
firstpacket = 1; |
4449 | 4453 |
|
... | ... |
@@ -4460,20 +4498,20 @@ getURL(struct arg *arg) |
4460 | 4460 |
if(select(sd + 1, &set, NULL, NULL, &tv) < 0) { |
4461 | 4461 |
if(errno == EINTR) |
4462 | 4462 |
continue; |
4463 |
- close(sd); |
|
4463 |
+ closesocket(sd); |
|
4464 | 4464 |
fclose(fp); |
4465 | 4465 |
return NULL; |
4466 | 4466 |
} |
4467 | 4467 |
if(!FD_ISSET(sd, &set)) { |
4468 | 4468 |
fclose(fp); |
4469 |
- close(sd); |
|
4469 |
+ closesocket(sd); |
|
4470 | 4470 |
return NULL; |
4471 | 4471 |
} |
4472 | 4472 |
n = recv(sd, buf, BUFSIZ, 0); |
4473 | 4473 |
|
4474 | 4474 |
if(n < 0) { |
4475 | 4475 |
fclose(fp); |
4476 |
- close(sd); |
|
4476 |
+ closesocket(sd); |
|
4477 | 4477 |
return NULL; |
4478 | 4478 |
} |
4479 | 4479 |
if(n == 0) |
... | ... |
@@ -4505,7 +4543,7 @@ getURL(struct arg *arg) |
4505 | 4505 |
char *end; |
4506 | 4506 |
|
4507 | 4507 |
fclose(fp); |
4508 |
- close(sd); |
|
4508 |
+ closesocket(sd); |
|
4509 | 4509 |
unlink(fout); |
4510 | 4510 |
|
4511 | 4511 |
location += 11; |
... | ... |
@@ -4542,7 +4580,7 @@ getURL(struct arg *arg) |
4542 | 4542 |
} |
4543 | 4543 |
|
4544 | 4544 |
fclose(fp); |
4545 |
- close(sd); |
|
4545 |
+ closesocket(sd); |
|
4546 | 4546 |
return NULL; |
4547 | 4547 |
} |
4548 | 4548 |
|
... | ... |
@@ -4576,7 +4614,7 @@ my_r_gethostbyname(const char *hostname, struct hostent *hp, char *buf, size_t l |
4576 | 4576 |
if(gethostbyname_r(hostname, &hp, (struct hostent_data *)buf) < 0) |
4577 | 4577 |
return h_errno; |
4578 | 4578 |
#else |
4579 |
- /* Single thread the code */ |
|
4579 |
+ /* Single thread the code e.g. VS2005 */ |
|
4580 | 4580 |
struct hostent *hp2; |
4581 | 4581 |
#ifdef CL_THREAD_SAFE |
4582 | 4582 |
static pthread_mutex_t hostent_mutex = PTHREAD_MUTEX_INITIALIZER; |
... | ... |
@@ -4605,6 +4643,7 @@ my_r_gethostbyname(const char *hostname, struct hostent *hp, char *buf, size_t l |
4605 | 4605 |
static long |
4606 | 4606 |
nonblock_fcntl(int sock) |
4607 | 4607 |
{ |
4608 |
+#ifdef F_GETFL |
|
4608 | 4609 |
long fcntl_flags; /* Save fcntl() flags */ |
4609 | 4610 |
|
4610 | 4611 |
fcntl_flags = fcntl(sock, F_GETFL, 0); |
... | ... |
@@ -4616,16 +4655,21 @@ nonblock_fcntl(int sock) |
4616 | 4616 |
sock, errno, strerror(errno)); |
4617 | 4617 |
|
4618 | 4618 |
return fcntl_flags; |
4619 |
+#else |
|
4620 |
+ return 0L; |
|
4621 |
+#endif |
|
4619 | 4622 |
} |
4620 | 4623 |
|
4621 | 4624 |
static void |
4622 | 4625 |
restore_fcntl(int sock, long fcntl_flags) |
4623 | 4626 |
{ |
4627 |
+#ifdef F_SETFL |
|
4624 | 4628 |
if(fcntl_flags != -1) |
4625 | 4629 |
if(fcntl(sock, F_SETFL, fcntl_flags)) { |
4626 | 4630 |
cli_warnmsg("restore_fcntl: restoring: fcntl(%d, F_SETFL): errno=%d: %s\n", |
4627 | 4631 |
sock, errno, strerror(errno)); |
4628 | 4632 |
} |
4633 |
+#endif |
|
4629 | 4634 |
} |
4630 | 4635 |
|
4631 | 4636 |
static int |