Browse code

Minor code tidy

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

Nigel Horne authored on 2004/10/01 22:50:47
Showing 5 changed files
... ...
@@ -16,6 +16,9 @@
16 16
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  *
18 18
  * $Log: blob.c,v $
19
+ * Revision 1.24  2004/10/01 13:50:47  nigelhorne
20
+ * Minor code tidy
21
+ *
19 22
  * Revision 1.23  2004/09/21 09:26:35  nigelhorne
20 23
  * Closing a closed blob is no longer fatal
21 24
  *
... ...
@@ -71,7 +74,7 @@
71 71
  * Change LOG to Log
72 72
  *
73 73
  */
74
-static	char	const	rcsid[] = "$Id: blob.c,v 1.23 2004/09/21 09:26:35 nigelhorne Exp $";
74
+static	char	const	rcsid[] = "$Id: blob.c,v 1.24 2004/10/01 13:50:47 nigelhorne Exp $";
75 75
 
76 76
 #if HAVE_CONFIG_H
77 77
 #include "clamav-config.h"
... ...
@@ -83,7 +86,7 @@ static	char	const	rcsid[] = "$Id: blob.c,v 1.23 2004/09/21 09:26:35 nigelhorne E
83 83
 #include <errno.h>
84 84
 #include <fcntl.h>
85 85
 
86
-#include <sys/param.h>        /* for NAME_MAX */
86
+#include <sys/param.h>	/* for NAME_MAX */
87 87
 
88 88
 #if	C_DARWIN
89 89
 #include <sys/types.h>
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: mbox.c,v $
20
+ * Revision 1.145  2004/10/01 13:49:22  nigelhorne
21
+ * Minor code tidy
22
+ *
20 23
  * Revision 1.144  2004/10/01 07:55:36  nigelhorne
21 24
  * Better error message on message/partial
22 25
  *
... ...
@@ -420,7 +423,7 @@
420 420
  * Compilable under SCO; removed duplicate code with message.c
421 421
  *
422 422
  */
423
-static	char	const	rcsid[] = "$Id: mbox.c,v 1.144 2004/10/01 07:55:36 nigelhorne Exp $";
423
+static	char	const	rcsid[] = "$Id: mbox.c,v 1.145 2004/10/01 13:49:22 nigelhorne Exp $";
424 424
 
425 425
 #if HAVE_CONFIG_H
426 426
 #include "clamav-config.h"
... ...
@@ -1029,6 +1032,7 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
1029 1029
 	/* Anything left to be parsed? */
1030 1030
 	if(mainMessage && (messageGetBody(mainMessage) != NULL)) {
1031 1031
 		mime_type mimeType;
1032
+		int subtype;
1032 1033
 		const char *mimeSubtype;
1033 1034
 		const text *t_line;
1034 1035
 		/*bool isAlternative;*/
... ...
@@ -1040,13 +1044,15 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
1040 1040
 		mimeType = messageGetMimeType(mainMessage);
1041 1041
 		mimeSubtype = messageGetMimeSubtype(mainMessage);
1042 1042
 
1043
-		if((mimeType == TEXT) && (tableFind(subtypeTable, mimeSubtype) == PLAIN)) {
1043
+		subtype = tableFind(subtypeTable, mimeSubtype);
1044
+		if((mimeType == TEXT) && (subtype == PLAIN)) {
1044 1045
 			/*
1045 1046
 			 * This is effectively no encoding, notice that we
1046 1047
 			 * don't check that charset is us-ascii
1047 1048
 			 */
1048 1049
 			cli_dbgmsg("assume no encoding\n");
1049 1050
 			mimeType = NOMIME;
1051
+			messageSetMimeSubtype(mainMessage, NULL);
1050 1052
 		}
1051 1053
 
1052 1054
 		cli_dbgmsg("mimeType = %d\n", mimeType);
... ...
@@ -1056,7 +1062,7 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
1056 1056
 			aText = textAddMessage(aText, mainMessage);
1057 1057
 			break;
1058 1058
 		case TEXT:
1059
-			if(tableFind(subtypeTable, mimeSubtype) == PLAIN)
1059
+			if(subtype == PLAIN)
1060 1060
 				/*
1061 1061
 				 * Consider what to do if this fails
1062 1062
 				 * (i.e. aText == NULL):
... ...
@@ -1067,9 +1073,8 @@ parseEmailBody(message *messageIn, text *textIn, const char *dir, const table_t
1067 1067
 				 * able to scan anyway and we lose nothing
1068 1068
 				 */
1069 1069
 				aText = textCopy(messageGetBody(mainMessage));
1070
-			else if(options&CL_SCAN_MAILURL)
1071
-				if(tableFind(subtypeTable, mimeSubtype) == HTML)
1072
-					checkURLs(mainMessage, dir);
1070
+			else if((options&CL_SCAN_MAILURL) && (subtype == HTML))
1071
+				checkURLs(mainMessage, dir);
1073 1072
 			break;
1074 1073
 		case MULTIPART:
1075 1074
 			boundary = messageFindArgument(mainMessage, "boundary");
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: message.c,v $
20
+ * Revision 1.93  2004/10/01 13:49:22  nigelhorne
21
+ * Minor code tidy
22
+ *
20 23
  * Revision 1.92  2004/09/30 08:58:56  nigelhorne
21 24
  * Remove empty lines
22 25
  *
... ...
@@ -273,7 +276,7 @@
273 273
  * uuencodebegin() no longer static
274 274
  *
275 275
  */
276
-static	char	const	rcsid[] = "$Id: message.c,v 1.92 2004/09/30 08:58:56 nigelhorne Exp $";
276
+static	char	const	rcsid[] = "$Id: message.c,v 1.93 2004/10/01 13:49:22 nigelhorne Exp $";
277 277
 
278 278
 #if HAVE_CONFIG_H
279 279
 #include "clamav-config.h"
... ...
@@ -975,7 +978,7 @@ messageAddStr(message *m, const char *data)
975 975
 
976 976
 	if(data) {
977 977
 		int isblank = 1;
978
-		char *p;
978
+		const char *p;
979 979
 
980 980
 		for(p = data; *p != '\0'; p++)
981 981
 			if(!isspace(*p)) {
... ...
@@ -1414,7 +1417,6 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1414 1414
 			if(filename == NULL) {
1415 1415
 				cli_dbgmsg("Attachment sent with no filename\n");
1416 1416
 				messageAddArgument(m, "name=attachment");
1417
-				filename = strdup("attachment");
1418 1417
 			} else
1419 1418
 				/*
1420 1419
 				 * Some virus attachments don't say how they've
... ...
@@ -1423,9 +1425,10 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1423 1423
 				messageSetEncoding(m, "base64");
1424 1424
 		}
1425 1425
 
1426
-		(*setFilename)(ret, dir, filename);
1426
+		(*setFilename)(ret, dir, (filename) ? filename : "attachment");
1427 1427
 
1428
-		free((char *)filename);
1428
+		if(filename)
1429
+			free((char *)filename);
1429 1430
 
1430 1431
 		if(m->numberOfEncTypes == 0) {
1431 1432
 			if(uuencodeBegin(m))
... ...
@@ -1478,11 +1481,13 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1478 1478
 					strstrip(filename);
1479 1479
 					cli_dbgmsg("Set yEnc filename to \"%s\"\n", filename);
1480 1480
 				}
1481
-			} else
1482
-				filename = strdup("attachment");
1481
+			}
1483 1482
 
1484
-			if(filename)
1485
-				(*setFilename)(ret, dir, filename);
1483
+			(*setFilename)(ret, dir, (filename) ? filename : "attchment");
1484
+			if(filename) {
1485
+				free((char *)filename);
1486
+				filename = NULL;
1487
+			}
1486 1488
 			t_line = t_line->t_next;
1487 1489
 			enctype = YENCODE;
1488 1490
 		} else {
... ...
@@ -1493,7 +1498,6 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1493 1493
 				if(filename == NULL) {
1494 1494
 					cli_dbgmsg("Attachment sent with no filename\n");
1495 1495
 					messageAddArgument(m, "name=attachment");
1496
-					filename = strdup("attachment");
1497 1496
 				} else if(enctype == NOENCODING)
1498 1497
 					/*
1499 1498
 					 * Some virus attachments don't say how they've
... ...
@@ -1502,7 +1506,7 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1502 1502
 					messageSetEncoding(m, "base64");
1503 1503
 			}
1504 1504
 
1505
-			(*setFilename)(ret, dir, filename);
1505
+			(*setFilename)(ret, dir, (filename) ? filename : "attchment");
1506 1506
 
1507 1507
 			t_line = messageGetBody(m);
1508 1508
 		}
... ...
@@ -1542,7 +1546,7 @@ messageExport(message *m, const char *dir, void *(*create)(void), void (*destroy
1542 1542
 			} else if(enctype == YENCODE) {
1543 1543
 				if(line == NULL)
1544 1544
 					continue;
1545
-				if(strncmp(line, "=end ", 5) == 0)
1545
+				if(strncmp(line, "=yend ", 6) == 0)
1546 1546
 					break;
1547 1547
 			}
1548 1548
 
... ...
@@ -1746,11 +1750,13 @@ messageToText(message *m)
1746 1746
 			 * strcmp - that'd be bad for MIME decoders, but is OK
1747 1747
 			 * for AV software
1748 1748
 			 */
1749
-			if(line && (strncmp(data, line, strlen(line)) == 0)) {
1749
+			if((data[0] == '\n') || (data[0] == '\0'))
1750
+				last->t_line = NULL;
1751
+			else if(line && (strncmp(data, line, strlen(line)) == 0)) {
1750 1752
 				cli_dbgmsg("messageToText: decoded line is the same(%s)\n", data);
1751 1753
 				last->t_line = lineLink(t_line->t_line);
1752 1754
 			} else
1753
-				last->t_line = ((data[0] != '\n') && data[0]) ? lineCreate((char *)data) : NULL;
1755
+				last->t_line = lineCreate((char *)data);
1754 1756
 
1755 1757
 			if(line && enctype == BASE64)
1756 1758
 				if(strchr(line, '='))
... ...
@@ -1760,7 +1766,7 @@ messageToText(message *m)
1760 1760
 			unsigned char data[4];
1761 1761
 
1762 1762
 			memset(data, '\0', sizeof(data));
1763
-			if(decode(m, NULL, data, base64, FALSE)) {
1763
+			if(decode(m, NULL, data, base64, FALSE) && data[0]) {
1764 1764
 				if(first == NULL)
1765 1765
 					first = last = cli_malloc(sizeof(text));
1766 1766
 				else {
... ...
@@ -1769,7 +1775,7 @@ messageToText(message *m)
1769 1769
 				}
1770 1770
 
1771 1771
 				if(last != NULL)
1772
-					last->t_line = data[0] ? lineCreate((char *)data) : NULL;
1772
+					last->t_line = lineCreate((char *)data);
1773 1773
 			}
1774 1774
 			m->base64chars = 0;
1775 1775
 		}
... ...
@@ -16,6 +16,14 @@
16 16
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  */
18 18
 
19
+#if HAVE_CONFIG_H
20
+#include "clamav-config.h"
21
+#endif
22
+
23
+#ifndef	CL_DEBUG
24
+#define	NDEBUG	/* map CLAMAV debug onto standard */
25
+#endif
26
+
19 27
 #include <stdlib.h>
20 28
 #include <string.h>
21 29
 #include <strings.h>
... ...
@@ -89,6 +97,9 @@ int
89 89
 tableFind(const table_t *table, const char *key)
90 90
 {
91 91
 	const tableEntry *tableItem;
92
+#ifdef	CL_DEBUG
93
+	int cost;
94
+#endif
92 95
 
93 96
 	assert(table != NULL);
94 97
 
... ...
@@ -98,9 +109,19 @@ tableFind(const table_t *table, const char *key)
98 98
 	if(table->tableHead == NULL)
99 99
 		return -1;	/* not populated yet */
100 100
 
101
-	for(tableItem = table->tableHead; tableItem; tableItem = tableItem->next)
102
-		if(strcasecmp(tableItem->key, key) == 0)
101
+	cost = 0;
102
+
103
+	for(tableItem = table->tableHead; tableItem; tableItem = tableItem->next) {
104
+#ifdef	CL_DEBUG
105
+		cost++;
106
+#endif
107
+		if(strcasecmp(tableItem->key, key) == 0) {
108
+#ifdef	CL_DEBUG
109
+			cli_dbgmsg("tableFind: Cost of '%s' = %d\n", key, cost);
110
+#endif
103 111
 			return(tableItem->value);
112
+		}
113
+	}
104 114
 
105 115
 	return -1;	/* not found */
106 116
 }
... ...
@@ -20,6 +20,9 @@
20 20
  *
21 21
  * Change History:
22 22
  * $Log: untar.c,v $
23
+ * Revision 1.11  2004/10/01 13:50:47  nigelhorne
24
+ * Minor code tidy
25
+ *
23 26
  * Revision 1.10  2004/09/20 13:37:44  kojm
24 27
  * 0.80rc
25 28
  *
... ...
@@ -51,7 +54,7 @@
51 51
  * First draft
52 52
  *
53 53
  */
54
-static	char	const	rcsid[] = "$Id: untar.c,v 1.10 2004/09/20 13:37:44 kojm Exp $";
54
+static	char	const	rcsid[] = "$Id: untar.c,v 1.11 2004/10/01 13:50:47 nigelhorne Exp $";
55 55
 
56 56
 #include <stdio.h>
57 57
 #include <errno.h>
... ...
@@ -59,7 +62,7 @@ static	char	const	rcsid[] = "$Id: untar.c,v 1.10 2004/09/20 13:37:44 kojm Exp $"
59 59
 #include <unistd.h>
60 60
 #include <sys/stat.h>
61 61
 #include <fcntl.h>
62
-#include <sys/param.h>        /* for NAME_MAX */
62
+#include <sys/param.h>	/* for NAME_MAX */
63 63
 
64 64
 #include "clamav.h"
65 65
 #include "others.h"
... ...
@@ -137,7 +140,7 @@ cli_untar(const char *dir, int desc)
137 137
 				outfile = (FILE*)0;
138 138
 			}
139 139
 
140
-			if(block[0] == '\0')  /* We're done */
140
+			if(block[0] == '\0')	/* We're done */
141 141
 				break;
142 142
 
143 143
 			/* Notice assumption that BLOCKSIZE > 262 */