Re: Spec. for check_field()?

Ralph Corderoy <[email protected]>
Newsgroups gmane.network.sn
Message-ID <[email protected]>
Hi PAtrik,

> > snstore is giving me `append: bad header' errors.  On looking at
> 
> That's a warning message, the headers are added to the database
> anyway, so no need to worry.  As for what standard to follow, "Son of
> RFC 1036" is probably the one.

Ah, I see that now, thanks.  If there is interest if changing it to be
more liberal in some ways, especially for those `i18n' headers that
start off =iso-8859-1..., then here's a patch to vet.


Ralph.


--- sn-0.3.4a.orig/field.c	Fri Oct  5 02:08:26 2001
+++ sn-0.3.4a/field.c	Mon May 27 23:42:40 2002
@@ -9,30 +9,35 @@
  * Check the field name of a header line.
  */
 
+#include <ctype.h>
+
+/* return length of $1 if /^([\x21-\x39\x3b-\x7e]+):/ else 0. */
+
 int check_field (char *field, int len)
 {
-   int i;
+    int state;
+    int i;
+    int c;
+
+    state = 0;
+    for (i = 0; i < len; i++) {
+        c = field[i];
+
+        switch (state) {
+        case 0:
+            if (isgraph(c) && c != ':') {
+                state = 1;
+            }
+            return 0;
+        case 1:
+            if (c == ':') {
+                return i;
+            } else if (isgraph(c)) {
+                continue;
+            }
+            return 0;
+        }
+    }
 
-   for (i = 0; i < len; i++)
-   {
-      if (field[i] >= 'a' && field[i] <= 'z')
-         continue;
-      if (field[i] >= 'A' && field[i] <= 'Z')
-         continue;
-      if (field[i] >= '0' && field[i] <= '9')
-         continue;
-      if ('-' == field[i])
-         continue;
-      if (':' == field[i])
-         return (i);
-      if (' ' == field[i] || '\t' == field[i])
-         break;
-      return (0);
-   }
-   do
-      i++;
-   while (field[i] == ' ' || field[i] == '\t');
-   if (':' != field[i])
-      return (0);
-   return (i);
+    return 0;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.