+static adns_status qdparselabel(adns_state ads,
+ const char **p_io, const char *pe,
+ char label_r[], int *ll_io,
+ adns_queryflags flags) {
+ int ll, c;
+ const char *p;
+
+ ll= 0;
+ p= *p_io;
+
+ while (p!=pe && (c= *p++)!='.') {
+ if (c=='\\') {
+ if (!(flags & adns_qf_quoteok_query)) return adns_s_querydomaininvalid;
+ if (p==pe) return adns_s_querydomaininvalid;
+ if (ctype_digit(p[0])) {
+ if (p+1==pe || p+2==pe) return adns_s_querydomaininvalid;
+ if (ctype_digit(p[1]) && ctype_digit(p[2])) {
+ c= (*p++ - '0')*100;
+ c += (*p++ - '0')*10;
+ c += (*p++ - '0');
+ if (c >= 256) return adns_s_querydomaininvalid;
+ } else {
+ return adns_s_querydomaininvalid;
+ }
+ } else if (!(c= *p++)) {
+ return adns_s_querydomaininvalid;
+ }
+ }
+ if (ll == *ll_io) return adns_s_querydomaininvalid;
+ label_r[ll++]= c;
+ }
+
+ *p_io= p;
+ *ll_io= ll;
+ return adns_s_ok;
+}
+