X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fgeneral.c;h=ae7cac0f2b06910c7ece07346208e42788a28e21;hb=ac77ffc12405483a2b65ec2b27006426719113aa;hp=5ebdd6ad9c935dedac15285e0137dfdf4442f208;hpb=49d8f5b423c87e34679a7df2c2fc3c91183da967;p=adns.git diff --git a/src/general.c b/src/general.c index 5ebdd6a..ae7cac0 100644 --- a/src/general.c +++ b/src/general.c @@ -204,6 +204,7 @@ adns_status adns_rr_info(adns_rrtype type, return st; } + #define SINFO(n,s) { adns_s_##n, #n, s } static const struct sinfo { @@ -240,7 +241,7 @@ static const struct sinfo { SINFO( querydomaintoolong, "Domain name is too long" ), SINFO( nxdomain, "No such domain" ), - SINFO( nodata, "No such data" ), + SINFO( nodata, "No such data" ) }; static int si_compar(const void *key, const void *elem) { @@ -268,6 +269,43 @@ const char *adns_errabbrev(adns_status st) { return si->abbrev; } + +#define STINFO(max) { adns_s_max_##max, #max } + +static const struct stinfo { + adns_status stmax; + const char *abbrev; +} stinfos[]= { + { adns_s_ok, "ok" }, + STINFO( localfail ), + STINFO( remotefail ), + STINFO( tempfail ), + STINFO( misconfig ), + STINFO( misquery ), + STINFO( permfail ) +}; + +static int sti_compar(const void *key, const void *elem) { + const adns_status *st= key; + const struct stinfo *sti= elem; + + adns_status here, min, max; + + here= *st; + min= (sti==stinfos) ? 0 : sti[-1].stmax+1; + max= sti->stmax; + + return here < min ? -1 : here > max ? 1 : 0; +} + +const char *adns_errtypeabbrev(adns_status st) { + const struct stinfo *sti; + + sti= bsearch(&st,stinfos,sizeof(stinfos)/sizeof(*stinfos),sizeof(*stinfos),sti_compar); + return sti->abbrev; +} + + void adns__isort(void *array, int nobjs, int sz, void *tempbuf, int (*needswap)(void *context, const void *a, const void *b), void *context) {