From: Miek Gieben Date: Wed, 6 Apr 2005 08:59:53 +0000 (+0000) Subject: \'port\' of zoctect - see the comments. What to do? X-Git-Tag: release-0.50~163 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a3b6042a8338eb15752af2a87810150a92307fa;p=thirdparty%2Fldns.git \'port\' of zoctect - see the comments. What to do? --- diff --git a/ldns/parse.h b/ldns/parse.h index 5d770a5a..d6f7b0d6 100644 --- a/ldns/parse.h +++ b/ldns/parse.h @@ -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 aa770c08..21d3d9e4 100644 --- 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; +}