This seems nicer and is going to be more convenient.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
#define REVDOMAIN_MAP(rps, labnum) \
((labnum) ? (rps)->map : (1 << NREVDOMAINS) - 1)
-int adns__revparse_label(struct revparse_state *rps, int labnum,
- const char *dgram, int labstart, int lablen) {
+bool adns__revparse_label(struct revparse_state *rps, int labnum,
+ const char *dgram, int labstart, int lablen) {
const char *label = dgram+labstart;
unsigned f= REVDOMAIN_MAP(rps, labnum);
const struct revparse_domain *rpd;
mismatch:
f &= ~d;
- if (!f) return -1;
+ if (!f) return 0;
}
rps->map= f;
- return 0;
+ return 1;
}
-int adns__revparse_done(struct revparse_state *rps,
- const char *dgram, int nlabels,
- adns_rrtype *rrtype_r, adns_sockaddr *addr_r) {
+bool adns__revparse_done(struct revparse_state *rps,
+ const char *dgram, int nlabels,
+ adns_rrtype *rrtype_r, adns_sockaddr *addr_r) {
unsigned f= REVDOMAIN_MAP(rps, nlabels);
const struct revparse_domain *rpd;
unsigned d;
if (nlabels >= rpd->nrevlab && !rpd->tail[nlabels - rpd->nrevlab])
{ found = i; continue; }
f &= ~d;
- if (!f) return -1;
+ if (!f) return 0;
}
assert(found >= 0); assert(f == (1 << found));
*rrtype_r= rpd->rrtype;
addr_r->sa.sa_family= rpd->af;
rpd->rev_mkaddr(addr_r, rps->ipv[found]);
- return 0;
+ return 1;
}
* allocate an output buffer failed.
*/
-extern int adns__revparse_label(struct revparse_state *rps, int labnum,
- const char *dgram,
- int labstart, int lablen);
+extern bool adns__revparse_label(struct revparse_state *rps, int labnum,
+ const char *dgram,
+ int labstart, int lablen);
/* Parse a label in a reverse-domain name, given its index labnum (starting
* from zero), a pointer to its contents (which need not be null-terminated),
* and its length. The state in *rps is initialized implicitly when labnum
* is zero.
*
- * Returns zero if the parse was successful, nonzero if the domain name is
- * definitely invalid and the parse must be abandoned.
+ * Returns 1 if the parse is proceeding successfully, 0 if the domain
+ * name is definitely invalid and the parse must be abandoned.
*/
-extern int adns__revparse_done(struct revparse_state *rps,
- const char *dgram, int nlabels,
- adns_rrtype *rrtype_r, adns_sockaddr *addr_r);
+extern bool adns__revparse_done(struct revparse_state *rps,
+ const char *dgram, int nlabels,
+ adns_rrtype *rrtype_r, adns_sockaddr *addr_r);
/* Finishes parsing a reverse-domain name, given the total number of
* labels in the name. On success, fills in the af and protocol
* address in *addr_r, and the forward query type in *rrtype_r
- * (because that turns out to be useful). Returns nonzero if the
- * parse must be abandoned.
+ * (because that turns out to be useful). Returns 1 if the parse
+ * was successful.
*/
/* From setup.c: */
int labnum, const char *dgram,
int labstart, int lablen) {
if (lablen) {
- if (adns__revparse_label(&cls->ptr, labnum, dgram,labstart,lablen))
+ if (!adns__revparse_label(&cls->ptr, labnum, dgram,labstart,lablen))
return adns_s_querydomainwrong;
} else {
- if (adns__revparse_done(&cls->ptr, dgram, labnum,
- &ctx->tinfo.ptr.rev_rrtype,
- &ctx->tinfo.ptr.addr))
+ if (!adns__revparse_done(&cls->ptr, dgram, labnum,
+ &ctx->tinfo.ptr.rev_rrtype,
+ &ctx->tinfo.ptr.addr))
return adns_s_querydomainwrong;
}
return adns_s_ok;