Browse code

DBG_MSG_QA changed to scan for long whitespaces only in message header (body ignored now)

Jiri Kuthan authored on 29/08/2002 16:43:27
Showing 1 changed files
... ...
@@ -235,31 +235,66 @@ int udp_send(struct socket_info *source, char *buf, unsigned len,
235 235
 
236 236
 	int n;
237 237
 
238
+/* message quality assurance -- frequently, bugs in ser have
239
+   been indicated by zero characters or long whitespaces
240
+   in generated messages; this debugging option aborts if
241
+   any such message is sighted
242
+*/
238 243
 #ifdef DBG_MSG_QA
239 244
 #define _DBG_WS_LEN 3
240 245
 #define _DBG_WS "   "
241 246
 
242
-	char *space;
247
+	char *scan;
243 248
 	int my_len;
249
+	int space_cnt;
250
+	enum { QA_ANY, QA_SPACE, QA_EOL1 } state;
244 251
 
252
+
253
+	/* is there a zero character inthere ? */	
245 254
 	if (memchr(buf, 0, len)) {
246 255
 		LOG(L_CRIT, "BUG: message being sent with 0 in it\n");
247 256
 		abort();
248 257
 	}
258
+
249 259
 	my_len=len;
250
-	space=buf;
251
-	while((space=memchr(space, ' ', my_len ))) {
252
-		/* how much we have after the space */
253
-		my_len=len-(space-buf)+1;
254
-		/* EoM -- stop checks */
255
-		if (my_len<_DBG_WS_LEN) break;
256
-		if (memcmp(space+1, _DBG_WS, _DBG_WS_LEN)==0) {
257
-			LOG(L_CRIT, "BUG(probably): "
258
-				"message with four spaces in it\n");
259
-			abort();
260
+	scan=buf;
261
+	state=QA_ANY;
262
+	space_cnt=0;
263
+
264
+	while(my_len) {
265
+		switch(*scan) {
266
+			case ' ':	if (state==QA_SPACE) {
267
+							space_cnt++;
268
+							if (space_cnt==4) {
269
+								LOG(L_CRIT, "BUG(propably): DBG_MSG_QA: "
270
+									"too many spaces\n");
271
+								abort();
272
+							}
273
+						} else space_cnt=0;
274
+						state=QA_SPACE; 
275
+						break;
276
+
277
+			case '\r':	/* ignore */
278
+						space_cnt=0;
279
+						break;
280
+
281
+			case '\n': /* don't proceed to body on EoH */
282
+						if (state==QA_EOL1) goto qa_passed;
283
+						space_cnt=0;
284
+						state=QA_EOL1;
285
+						break;
286
+
287
+			default:	space_cnt=0;
288
+						state=QA_ANY;
289
+						break;
260 290
 		}
261
-		space+=_DBG_WS_LEN;my_len-=_DBG_WS_LEN;
291
+		scan++;
292
+		my_len--;
262 293
 	}
294
+
295
+
296
+qa_passed:
297
+
263 298
 #endif
264 299
 
265 300
 again: