Browse code

Use configure WITH_CURL value

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@761 77e5149b-7576-45b1-b177-96237e5ba77b

Nigel Horne authored on 2004/08/18 16:46:59
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Wed Aug 18 08:45:38 BST 2004 (njh)
2
+----------------------------------
3
+  * libclamav/mbox.c:	If CHECKURLS is compiled in, use libcurl automatically
4
+  				if it is detected
5
+
1 6
 Tue Aug 17 21:02:06 CEST 2004 (tk)
2 7
 ----------------------------------
3 8
   * configure: Test for libcurl. Define foo "inline" if needed.
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: mbox.c,v $
20
+ * Revision 1.102  2004/08/18 07:45:20  nigelhorne
21
+ * Use configure WITH_CURL value
22
+ *
20 23
  * Revision 1.101  2004/08/17 08:28:32  nigelhorne
21 24
  * Support multitype/fax-message
22 25
  *
... ...
@@ -291,7 +294,7 @@
291 291
  * Compilable under SCO; removed duplicate code with message.c
292 292
  *
293 293
  */
294
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.101 2004/08/17 08:28:32 nigelhorne Exp $";
294
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.102 2004/08/18 07:45:20 nigelhorne Exp $";
295 295
 
296 296
 #if HAVE_CONFIG_H
297 297
 #include "clamav-config.h"
... ...
@@ -367,18 +370,23 @@ static	void	print_trace(int use_syslog);
367 367
 typedef enum	{ FALSE = 0, TRUE = 1 } bool;
368 368
 
369 369
 #define	SAVE_TO_DISC	/* multipart/message are saved in a temporary file */
370
-#define	CHECKURLS	/* If an email contains URLs, check them */
371 370
 
372
-#ifdef	CHECKURLS
373
-#define	LIBCURL		/* To build with LIBCURL:
374
-			 * LDFLAGS=`curl-config --libs` ./configure ...
371
+#define	CHECKURLS	/*
372
+			 * If an email contains URLs, check them - helps to
373
+			 * find Dialer.gen-45
375 374
 			 */
376 375
 
377
-#define	MAX_URLS	10	/*
376
+#ifdef	CHECKURLS
377
+
378
+#define	MAX_URLS	5	/*
378 379
 				 * Maximum number of URLs scanned in a message
379 380
 				 * part
380 381
 				 */
381
-#ifdef	LIBCURL
382
+#ifdef	WITH_CURL	/* Set in configure */
383
+/*
384
+ * To build with WITH_CURL:
385
+ * LDFLAGS=`curl-config --libs` ./configure ...
386
+ */
382 387
 #include <curl/curl.h>
383 388
 #endif
384 389
 #endif
... ...
@@ -397,7 +405,7 @@ static	void	saveTextPart(message *m, const char *dir);
397 397
 static	bool	saveFile(const blob *b, const char *dir);
398 398
 
399 399
 static	void	checkURLs(message *m, const char *dir);
400
-#ifdef	LIBCURL
400
+#ifdef	WITH_CURL
401 401
 static	void	getURL(const char *url, const char *dir, const char *filename);
402 402
 #endif
403 403
 
... ...
@@ -775,21 +783,21 @@ parseEmailHeaders(message *m, const table_t *rfc821, bool destroy)
775 775
 static int
776 776
 parseEmailHeader(message *m, const char *line, const table_t *rfc821)
777 777
 {
778
-	char *copy, *cmd;
778
+	char *cmd;
779 779
 	int ret = -1;
780 780
 #ifdef CL_THREAD_SAFE
781 781
 	char *strptr;
782 782
 #endif
783
+	char copy[LINE_LENGTH+1];
783 784
 
784 785
 	cli_dbgmsg("parseEmailHeader '%s'\n", line);
785 786
 
786 787
 	if(strchr(line, ':') == NULL)
787 788
 		return -1;
788 789
 
789
-	copy = strdup(line);
790
+	assert(strlen(line) <= LINE_LENGTH);	/* RFC 821 */
790 791
 
791
-	if(copy == NULL)
792
-		return -1;
792
+	strcpy(copy, line);
793 793
 
794 794
 	cmd = strtok_r(copy, ":", &strptr);
795 795
 
... ...
@@ -806,8 +814,6 @@ parseEmailHeader(message *m, const char *line, const table_t *rfc821)
806 806
 			 */
807 807
 			ret = parseMimeHeader(m, cmd, rfc821, arg);
808 808
 	}
809
-	free(copy);
810
-
811 809
 	return ret;
812 810
 }
813 811
 
... ...
@@ -2116,7 +2122,6 @@ parseMimeHeader(message *m, const char *cmd, const table_t *rfc821Table, const c
2116 2116
 				 * Some clients are broken and
2117 2117
 				 * put white space after the ;
2118 2118
 				 */
2119
-				/*strstrip(copy);*/
2120 2119
 				if(*arg == '/') {
2121 2120
 					cli_warnmsg("Content-type '/' received, assuming application/octet-stream\n");
2122 2121
 					messageSetMimeType(m, "application");
... ...
@@ -2317,7 +2322,7 @@ checkURLs(message *m, const char *dir)
2317 2317
 	while(len >= 8) {
2318 2318
 		/* FIXME: allow any number of white space */
2319 2319
 		if(strncasecmp(ptr, "<a href=", 8) == 0) {
2320
-#ifndef	LIBCURL
2320
+#ifndef	WITH_CURL
2321 2321
 #ifdef	CL_THREAD_SAFE
2322 2322
 			static pthread_mutex_t system_mutex = PTHREAD_MUTEX_INITIALIZER;
2323 2323
 #endif
... ...
@@ -2358,7 +2363,7 @@ checkURLs(message *m, const char *dir)
2358 2358
 				if(*p3 == '/')
2359 2359
 					*p3 = '_';
2360 2360
 
2361
-#ifdef	LIBCURL
2361
+#ifdef	WITH_CURL
2362 2362
 			getURL(p2, dir, name);
2363 2363
 #else
2364 2364
 			/*
... ...
@@ -2395,7 +2400,7 @@ checkURLs(message *m, const char *dir)
2395 2395
 	tableDestroy(t);
2396 2396
 }
2397 2397
 
2398
-#ifdef	LIBCURL
2398
+#ifdef	WITH_CURL
2399 2399
 static void
2400 2400
 getURL(const char *url, const char *dir, const char *filename)
2401 2401
 {
... ...
@@ -2414,6 +2419,7 @@ getURL(const char *url, const char *dir, const char *filename)
2414 2414
 	curl = curl_easy_init();
2415 2415
 	if(curl == NULL)
2416 2416
 		return;
2417
+
2417 2418
 	(void)curl_easy_setopt(curl, CURLOPT_USERAGENT, "www.clamav.net");
2418 2419
 
2419 2420
 	if(curl_easy_setopt(curl, CURLOPT_URL, url) != 0)
... ...
@@ -2421,8 +2427,10 @@ getURL(const char *url, const char *dir, const char *filename)
2421 2421
 
2422 2422
 	fout = cli_malloc(strlen(dir) + strlen(filename) + 2);
2423 2423
 
2424
-	if(fout == NULL)
2424
+	if(fout == NULL) {
2425
+		curl_easy_cleanup(curl);
2425 2426
 		return;
2427
+	}
2426 2428
 
2427 2429
 	sprintf(fout, "%s/%s", dir, filename);
2428 2430
 
... ...
@@ -2431,6 +2439,7 @@ getURL(const char *url, const char *dir, const char *filename)
2431 2431
 	if(fp == NULL) {
2432 2432
 		perror(fout);
2433 2433
 		free(fout);
2434
+		curl_easy_cleanup(curl);
2434 2435
 		return;
2435 2436
 	}
2436 2437
 	/*
... ...
@@ -2443,6 +2452,7 @@ getURL(const char *url, const char *dir, const char *filename)
2443 2443
 	if(curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp) != 0) {
2444 2444
 		fclose(fp);
2445 2445
 		free(fout);
2446
+		curl_easy_cleanup(curl);
2446 2447
 		return;
2447 2448
 	}
2448 2449