]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
\'port\' of zoctect - see the comments. What to do?
authorMiek Gieben <miekg@NLnetLabs.nl>
Wed, 6 Apr 2005 08:59:53 +0000 (08:59 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Wed, 6 Apr 2005 08:59:53 +0000 (08:59 +0000)
ldns/parse.h
parse.c

index 5d770a5a26a38b086467585df7bdad4ddfe4a03b..d6f7b0d6e07b9429e0e888985195501b6ddb3609 100644 (file)
@@ -55,6 +55,9 @@ ssize_t ldns_bget_token(ldns_buffer *b, char *token, const char *delim, size_t l
 ssize_t 
 ldns_bget_keyword_data(ldns_buffer *b, const char *keyword, const char *k_del, char *data, const char *d_del);
 
-
+/*
+ * Remove \DDD constructs from the input. See RFC 1035, section 5.1.
+ */
+size_t zoctet(char *text);
 
 #endif /*  _PARSE_H_ */
diff --git a/parse.c b/parse.c
index aa770c08f750434283143e7790841cb710a841e8..21d3d9e434ec37362519c3f8603ee4c1c35d4d5b 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -245,3 +245,47 @@ tokenread:
                return (ssize_t)i;
        }
 }
+
+/* should text be writeable? Or should we return a new
+ * string??
+ */
+size_t
+zoctet(char *text)
+{
+        /*
+         * s follows the string, p lags behind and rebuilds 
+        * the new string
+         */
+        char *s;
+        char *p;
+
+        for (s = p = text; *s; ++s, ++p) {
+                assert(p <= s);
+                if (s[0] != '\\') {
+                        /* Ordinary character.  */
+                        *p = *s;
+                } else if (isdigit(s[1]) && isdigit(s[2]) && isdigit(s[3])) {
+                        /* \DDD escape.  */
+                        int val = (hexdigit_to_int(s[1]) * 100 +
+                                   hexdigit_to_int(s[2]) * 10 +
+                                   hexdigit_to_int(s[3]));
+                        if (0 <= val && val <= 255) {
+                                s += 3;
+                                *p = val;
+                        } else {
+                                printf("text escape \\DDD overflow");
+                               /* kuch, another printf... */
+                                *p = *++s;
+                        }
+                } else if (s[1] != '\0') {
+                        /* \X where X is any character, keep X.  */
+                        *p = *++s;
+                } else {
+                        /* Trailing backslash, ignore it.  */
+                        /* zc_warning("trailing backslash ignored"); */
+                        --p;
+                }
+        }
+        *p = '\0';
+        return p - text;
+}