rfc822: Rename RFC822_HDR_BAD_NAME constant
authorDavid Gibson <david@gibson.dropbear.id.au>
Thu, 4 Oct 2012 14:17:10 +0000 (00:17 +1000)
committerDavid Gibson <david@gibson.dropbear.id.au>
Thu, 4 Oct 2012 14:17:22 +0000 (00:17 +1000)
This error constant is actually more specific than the name suggests - it
indicates that a header field name contains characters which are not
permitted in a header field name.  Rename the constant to better reflect
this, likewise rename the testcase based around it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ccan/rfc822/rfc822.c
ccan/rfc822/rfc822.h
ccan/rfc822/test/run-bad-header-name-chars.c [new file with mode: 0644]
ccan/rfc822/test/run-bad-header-name.c [deleted file]

index 4a5e4ccdcc709d130fb6c7222ff215d9858e91ac..6a0f95fc5f31ed7d9246c21719328b9641823774 100644 (file)
@@ -257,7 +257,7 @@ enum rfc822_header_errors rfc822_header_errors(struct rfc822_msg *msg,
                        assert(c != ':');
 
                        if ((c < 33) || (c > 126)) {
-                               err |= RFC822_HDR_BAD_NAME;
+                               err |= RFC822_HDR_BAD_NAME_CHARS;
                                break;
                        }
                }
index 2beae410cda27e80f4905aca63aa37cb776cd70d..1170c113e92a236f149e677d45024980574a8cdb 100644 (file)
@@ -117,7 +117,7 @@ struct bytestring rfc822_body(struct rfc822_msg *msg);
 
 enum rfc822_header_errors {
        RFC822_HDR_NO_COLON = 1,
-       RFC822_HDR_BAD_NAME = 2,
+       RFC822_HDR_BAD_NAME_CHARS = 2,
 };
 
 enum rfc822_header_errors rfc822_header_errors(struct rfc822_msg *msg,
diff --git a/ccan/rfc822/test/run-bad-header-name-chars.c b/ccan/rfc822/test/run-bad-header-name-chars.c
new file mode 100644 (file)
index 0000000..532f307
--- /dev/null
@@ -0,0 +1,95 @@
+#include <ccan/foreach/foreach.h>
+#include <ccan/failtest/failtest_override.h>
+#include <ccan/failtest/failtest.h>
+#include <ccan/tap/tap.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define CCAN_RFC822_DEBUG
+
+#include <ccan/rfc822/rfc822.h>
+
+#include <ccan/rfc822/rfc822.c>
+
+#include "testdata.h"
+#include "helper.h"
+
+#define NAME_TEMPLATE          "X-Bad-Header"
+#define NAME_TEMPLATE_LEN      (strlen(NAME_TEMPLATE))
+
+const char bad_name_template[] =
+       NAME_TEMPLATE ": This is a good header that will become bad\n";
+
+static bool bad_name(const char *buf, char c)
+{
+       struct rfc822_msg *msg;
+       struct rfc822_header *hdr;
+       enum rfc822_header_errors errs;
+       struct bytestring hname;
+
+       msg = rfc822_start(NULL, buf, strlen(buf));
+
+       allocation_failure_check();
+
+       hdr = rfc822_first_header(msg);
+       ok1(hdr);
+
+       allocation_failure_check();
+
+       errs = rfc822_header_errors(msg, hdr);
+
+       allocation_failure_check();
+
+       ok1(!(errs & ~RFC822_HDR_BAD_NAME_CHARS));
+
+       /* Check raw_name still works properly */
+       hname = rfc822_header_raw_name(msg, hdr);
+
+       allocation_failure_check();
+
+       ok1(hname.ptr && hname.len == NAME_TEMPLATE_LEN);
+       ok1((hname.ptr[0] == c) &&
+           (memcmp(hname.ptr + 1, NAME_TEMPLATE + 1, NAME_TEMPLATE_LEN - 1) == 0));
+
+       rfc822_free(msg);
+
+       allocation_failure_check();
+
+       return !!(errs & RFC822_HDR_BAD_NAME_CHARS);
+}
+
+int main(int argc, char *argv[])
+{
+       char c;
+
+       failtest_setup(argc, argv);
+
+       plan_tests(5 * (1 + 3 + 4));
+
+       ok1(!bad_name(bad_name_template, bad_name_template[0]));
+
+       /* Good characters */
+       foreach_int(c, 'a', 'Z', '3') {
+               char *tmp = strdup(bad_name_template);
+
+               tmp[0] = c;
+
+               ok1(!bad_name(tmp, c));
+
+               free(tmp);
+       }
+
+       /* Bad characters */
+       foreach_int(c, ' ', '\t', '\b', '\x80') {
+               char *tmp = strdup(bad_name_template);
+
+               tmp[0] = c;
+
+               ok1(bad_name(tmp, c));
+
+               free(tmp);
+       }
+
+       /* This exits depending on whether all tests passed */
+       failtest_exit(exit_status());
+}
diff --git a/ccan/rfc822/test/run-bad-header-name.c b/ccan/rfc822/test/run-bad-header-name.c
deleted file mode 100644 (file)
index 7b4eac1..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-#include <ccan/foreach/foreach.h>
-#include <ccan/failtest/failtest_override.h>
-#include <ccan/failtest/failtest.h>
-#include <ccan/tap/tap.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define CCAN_RFC822_DEBUG
-
-#include <ccan/rfc822/rfc822.h>
-
-#include <ccan/rfc822/rfc822.c>
-
-#include "testdata.h"
-#include "helper.h"
-
-#define NAME_TEMPLATE          "X-Bad-Header"
-#define NAME_TEMPLATE_LEN      (strlen(NAME_TEMPLATE))
-
-const char bad_name_template[] =
-       NAME_TEMPLATE ": This is a good header that will become bad\n";
-
-static bool bad_name(const char *buf, char c)
-{
-       struct rfc822_msg *msg;
-       struct rfc822_header *hdr;
-       enum rfc822_header_errors errs;
-       struct bytestring hname;
-
-       msg = rfc822_start(NULL, buf, strlen(buf));
-
-       allocation_failure_check();
-
-       hdr = rfc822_first_header(msg);
-       ok1(hdr);
-
-       allocation_failure_check();
-
-       errs = rfc822_header_errors(msg, hdr);
-
-       allocation_failure_check();
-
-       ok1(!(errs & ~RFC822_HDR_BAD_NAME));
-
-       /* Check raw_name still works properly */
-       hname = rfc822_header_raw_name(msg, hdr);
-
-       allocation_failure_check();
-
-       ok1(hname.ptr && hname.len == NAME_TEMPLATE_LEN);
-       ok1((hname.ptr[0] == c) &&
-           (memcmp(hname.ptr + 1, NAME_TEMPLATE + 1, NAME_TEMPLATE_LEN - 1) == 0));
-
-       rfc822_free(msg);
-
-       allocation_failure_check();
-
-       return !!(errs & RFC822_HDR_BAD_NAME);
-}
-
-int main(int argc, char *argv[])
-{
-       char c;
-
-       failtest_setup(argc, argv);
-
-       plan_tests(5 * (1 + 3 + 4));
-
-       ok1(!bad_name(bad_name_template, bad_name_template[0]));
-
-       /* Good characters */
-       foreach_int(c, 'a', 'Z', '3') {
-               char *tmp = strdup(bad_name_template);
-
-               tmp[0] = c;
-
-               ok1(!bad_name(tmp, c));
-
-               free(tmp);
-       }
-
-       /* Bad characters */
-       foreach_int(c, ' ', '\t', '\b', '\x80') {
-               char *tmp = strdup(bad_name_template);
-
-               tmp[0] = c;
-
-               ok1(bad_name(tmp, c));
-
-               free(tmp);
-       }
-
-       /* This exits depending on whether all tests passed */
-       failtest_exit(exit_status());
-}