* - parsing assistance functions (mainly for domains inside datagrams)
*/
/*
- * This file is part of adns, which is Copyright (C) 1997-1999 Ian Jackson
+ * This file is
+ * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
+ *
+ * It is part of adns, which is
+ * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
+ * Copyright (C) 1999 Tony Finch <dot@dotat.at>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
qbuf[0]= 0;
for (i=0; i<len; i++) {
ch= buf[i];
- if (ch == '.' || ch == '"' || ch == '(' || ch == ')' ||
- ch == '@' || ch == ';' || ch == '$' || ch == '\\') {
- sprintf(qbuf,"\\%c",ch);
- break;
- } else if (ch <= ' ' || ch >= 127) {
+ if (ch <= ' ' || ch >= 127) {
sprintf(qbuf,"\\%03o",ch);
break;
+ } else if (!ctype_domainunquoted(ch)) {
+ sprintf(qbuf,"\\%c",ch);
+ break;
}
}
if (!adns__vbuf_append(vb,buf,i) || !adns__vbuf_append(vb,qbuf,strlen(qbuf)))
const byte *dgram, int dglen, int *cbyte_io, int max) {
findlabel_state fls;
- int lablen, labstart, i, ch;
- adns_status st;
-
adns__findlabel_start(&fls,ads, serv,qu, dgram,dglen,max, *cbyte_io,cbyte_io);
vb->used= 0;
+ return adns__parse_domain_more(&fls,ads,qu, vb,flags,dgram);
+}
+
+adns_status adns__parse_domain_more(findlabel_state *fls, adns_state ads,
+ adns_query qu, vbuf *vb, parsedomain_flags flags,
+ const byte *dgram) {
+ int lablen, labstart, i, ch, first;
+ adns_status st;
+
+ first= 1;
for (;;) {
- st= adns__findlabel_next(&fls,&lablen,&labstart);
+ st= adns__findlabel_next(fls,&lablen,&labstart);
if (st) return st;
if (lablen<0) { vb->used=0; return adns_s_ok; }
if (!lablen) break;
- if (vb->used)
+ if (first) {
+ first= 0;
+ } else {
if (!adns__vbuf_append(vb,".",1)) return adns_s_nomemory;
+ }
if (flags & pdf_quoteok) {
if (!vbuf__append_quoted1035(vb,dgram+labstart,lablen))
return adns_s_nomemory;