~samiam/MaraDNS

ref: 3.5.0002 MaraDNS/update/1.3.03/maradns-1.3.02-tilde_wks_loc.patch -rw-r--r-- 5.1 KiB View raw
db09084f — Sam Trenholme MaraDNS release 3.5.0002 5 months ago
                                                                                
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
--- maradns-1.3.02/parse/Csv2_rr_wks.c	2006-10-08 16:32:42.000000000 -0700
+++ maradns-1.3.03/parse/Csv2_rr_wks.c	2007-02-04 19:53:08.000000000 -0800
@@ -1,4 +1,4 @@
-/* Copyright (c) 2004-2006 Sam Trenholme
+/* Copyright (c) 2004-2007 Sam Trenholme
  *
  * TERMS
  *
@@ -86,22 +86,38 @@
 
 	/* Read the port numbers, putting them in the ports
 	 * array */
+	/* Allow the tilde to end a list */
+	if(stream->tilde_handling == 103) {
+		csv2_allow_tilde(stream);
+	}
 	look = csv2_justread(stream);
 	num = 0;
-	for(x = 0; x < 100; x++) {
-		/* This is one of the few places where we treat a newline
-		 * differently than a space or tab; a newline (or EOF) ends
-		 * the WKS list of ports */
-		if(look == -2 || look == '\n' || look == '\r') {
-			break;
-		}
-		/* Comments also end the WKS list of ports */
-		else if(csv2_is_hash(look)) {
-			process_comment(stream);
-			break;
+	for(x = 0; x < 1000; x++) {
+		if(stream->tilde_handling != 103) {
+			/* This is one of the few places where we treat a 
+                         * newline differently than a space or tab; a newline 
+                         * (or EOF) ends the WKS list of ports */
+			if(look == -2 || look == '\n' || look == '\r') {
+				break;
+			}
+			/* Comments also end the WKS list of ports */
+			else if(csv2_is_hash(look)) {
+				process_comment(stream);
+				break;
+			}
+                } else { /* If we use the tilde as a record separator, 
+                          * no need to use hacks to determine when we
+                          * are at the end of the record */
+			if(look == '~') {
+				break;
+			} else if(csv2_is_hash(look)) {
+				process_comment(stream);
+				look = csv2_read_unicode(stream);
+				continue;
+			}	
 		}
 		/* Numbers are processed one byte at a time */
-		else if(csv2_is_number(look)) {
+		if(csv2_is_number(look)) {
 			num *= 10; /* Decimal */
 			num += look - '0'; /* Random thought: It would have
                                             * made hexadecimal processing
@@ -113,8 +129,10 @@
 				return 0;
 			}
 		}
-		/* If it's a space, tab, or comma... */
-		else if(csv2_is_wks(look)) {
+		/* If it's a space, tab, or comma... (or newline 
+                 * if we use the tilde to separate records) */
+		else if(csv2_is_wks(look) || (stream->tilde_handling == 103
+                        && (look == '\r' || look == '\n'))) {
 			/* Take the number we've been processing and add it
 			 * to the list of ports */
 			if(portindex >= CSV2_WKS_PORTS_MAX) {
@@ -502,7 +520,13 @@
 	/* (optionally) get the size, horizontal precision, and vertical 
          * precision */	
 	get = -2;
-	for(x = 0; x < 100; x++) {
+
+	/* Allow the tilde to end a list */
+	if(stream->tilde_handling == 103) {
+		csv2_allow_tilde(stream);
+	}
+
+	for(x = 0; x < 1000; x++) {
 		if(csv2_is_wks(look) || look == '\r' || look == '\n' ||
                    look == -2 || csv2_is_hash(look)) {
 			int q = 1;
@@ -534,22 +558,40 @@
 				get = -2;
 			}
 		}
-		if(look == -2 || look == '\n' || look == '\r') {
-			break;
-		}
-		else if(csv2_is_hash(look)) {
-			process_comment(stream);
-			break;
+		/* If we are not using the ~ to separate records */
+		if(stream->tilde_handling != 103) {
+			if(look == -2 || look == '\n' || look == '\r') {
+				break;
+			}
+			else if(csv2_is_hash(look)) {
+				process_comment(stream);
+				break;
+			}
+		} else { /* When we use the tilde to separate records, we 
+                          * don't need hacks to determine when we are at the
+                          * end of a record */
+			if(look == '~') {
+				break;
+			} else if(csv2_is_hash(look)) {
+				process_comment(stream);
+				look = csv2_read_unicode(stream);
+				continue;
+			}
 		}
-		else if(csv2_is_number(look)) {
+		/* Numbers are processed one character at a time */
+		if(csv2_is_number(look)) {
 			if(get < 0) {
 				get = 0;
 			}
 			get *= 10;
 			get += look - '0';
 		}
-		else if(!csv2_is_wks(look) && look != 'm') {
-			return 0;
+		/* Error if not space, 'm', or, optionally, newline
+                 * if we're using tildes (~) to separate records */
+		else if(!csv2_is_wks(look) && look != 'm' &&
+                        !(stream->tilde_handling == 103 &&
+                        (look == '\r' || look == '\n'))) {
+			return 0; /* Error */
 		}
 		look = csv2_read_unicode(stream);
 	}	
--- maradns-1.3.03/parse/Csv2_parse.c.orig	2007-02-04 19:29:19.000000000 -0800
+++ maradns-1.3.03/parse/Csv2_parse.c	2007-02-04 19:29:19.000000000 -0800
@@ -453,7 +453,8 @@
 	/* If this character is not OK (is not a character we're looking for)
          * and is not a delimiter (whitespace, comment, or |), then it's an 
          * error */
-	if(in != -328 && !csv2_is_delimiter(in)) {
+	if(in != -328 && !csv2_is_delimiter(in) && !(in == '~' && 
+           stream->tilde_handling == 103)) {
 		csv2_error(stream,"Unexpected character");
 		return FATAL_CSV2_READ;
 	}
@@ -476,6 +477,10 @@
 		}
 	/* Reset the count of the number of tildes we have seen */
 	csv2_reset_tilde_seen(stream);
+	/* If the current character is a tilde, increment the count */
+        if(in == '~') {
+		stream->tilde_seen++;
+		}
 	}
 
 	for(x = 0; x < 10000; x++) {