diff --git a/sys/include/libc.h b/sys/include/libc.h index 80e38787a..0c34f1740 100644 --- a/sys/include/libc.h +++ b/sys/include/libc.h @@ -527,8 +527,8 @@ struct NetConnInfo extern NetConnInfo* getnetconninfo(char*, int); extern void freenetconninfo(NetConnInfo*); -extern char* idn2utf(char*, char*, int); -extern char* utf2idn(char*, char*, int); +extern int idn2utf(char*, char*, int); +extern int utf2idn(char*, char*, int); /* * system calls diff --git a/sys/src/cmd/ip/dhcp6d.c b/sys/src/cmd/ip/dhcp6d.c index ca87f0c00..8250518a0 100644 --- a/sys/src/cmd/ip/dhcp6d.c +++ b/sys/src/cmd/ip/dhcp6d.c @@ -571,7 +571,7 @@ odomainlist(uchar *w, int n, Otab *o, Req *q) for(t = q->t; t != nil; t = t->entry){ if(strcmp(t->attr, o->q[0]) != 0) continue; - if(utf2idn(t->val, val, sizeof(val)) == nil) + if(utf2idn(t->val, val, sizeof(val)) <= 0) continue; for(s = val; *s != 0; s++){ for(l = 0; *s != 0 && *s != '.'; l++) diff --git a/sys/src/cmd/ip/dhcpd/dhcpd.c b/sys/src/cmd/ip/dhcpd/dhcpd.c index d468c8190..df7a0d2b8 100644 --- a/sys/src/cmd/ip/dhcpd/dhcpd.c +++ b/sys/src/cmd/ip/dhcpd/dhcpd.c @@ -1591,7 +1591,7 @@ dnsnamesopt(Req *rp, int t, char *attr, Ndbtuple *nt) for(; nt != nil; nt = nt->entry){ if(strcmp(nt->attr, attr) != 0) continue; - if(utf2idn(nt->val, val, sizeof(val)) == nil) + if(utf2idn(nt->val, val, sizeof(val)) <= 0) continue; d = &rp->p[2]; for(s = val; *s != 0; s++){ diff --git a/sys/src/cmd/ip/dhcpd/ndb.c b/sys/src/cmd/ip/dhcpd/ndb.c index ffadbf389..d750248c2 100644 --- a/sys/src/cmd/ip/dhcpd/ndb.c +++ b/sys/src/cmd/ip/dhcpd/ndb.c @@ -305,7 +305,7 @@ lookupname(char *val, int len, Ndbtuple *t) for(nt = t; nt != nil; nt = nt->entry) if(strcmp(nt->attr, "dom") == 0){ - if(utf2idn(nt->val, val, len) == nil) + if(utf2idn(nt->val, val, len) < 0) strncpy(val, nt->val, len-1); val[len-1] = 0; break; diff --git a/sys/src/cmd/ip/ipconfig/main.c b/sys/src/cmd/ip/ipconfig/main.c index 8201e50d5..5b63035b3 100644 --- a/sys/src/cmd/ip/ipconfig/main.c +++ b/sys/src/cmd/ip/ipconfig/main.c @@ -350,7 +350,7 @@ main(int argc, char **argv) plan9 = 0; break; case 'h': - if(utf2idn(EARGF(usage()), conf.hostname, sizeof(conf.hostname)) == nil) + if(utf2idn(EARGF(usage()), conf.hostname, sizeof(conf.hostname)) <= 0) sysfatal("bad hostname"); sendhostname = 1; break; @@ -980,7 +980,7 @@ Ufmt(Fmt *f) char d[256], *s; s = va_arg(f->args, char*); - if(idn2utf(s, d, sizeof(d)) != nil) + if(idn2utf(s, d, sizeof(d)) >= 0) s = d; fmtprint(f, "%s", s); return 0; @@ -1040,7 +1040,7 @@ ndb2conf(Ndb *db, uchar *myip) t = ndbipinfo(db, "ip", val, attrs, nattr); for(nt = t; nt != nil; nt = nt->entry) { if(strcmp(nt->attr, "dnsdomain") == 0) { - if(utf2idn(nt->val, val, sizeof(val)) == nil) + if(utf2idn(nt->val, val, sizeof(val)) <= 0) continue; addnames(conf.dnsdomain, val, sizeof(conf.dnsdomain)); continue; diff --git a/sys/src/cmd/ndb/dblookup.c b/sys/src/cmd/ndb/dblookup.c index 601bf893f..ec3f94d1c 100644 --- a/sys/src/cmd/ndb/dblookup.c +++ b/sys/src/cmd/ndb/dblookup.c @@ -262,7 +262,7 @@ dblookup1(char *name, int type, int auth, int ttl) for(x=0; x<4; x++){ switch(x){ case 1: /* try unicode */ - if(idn2utf(name, dname, sizeof dname) == nil){ + if(idn2utf(name, dname, sizeof dname) < 0){ nstrcpy(dname, name, sizeof dname); continue; } @@ -270,7 +270,7 @@ dblookup1(char *name, int type, int auth, int ttl) continue; break; case 3: /* try ascii (lower case) */ - if(utf2idn(name, dname, sizeof dname) == nil) + if(utf2idn(name, dname, sizeof dname) < 0) continue; case 2: mklowcase(dname); diff --git a/sys/src/cmd/ndb/dn.c b/sys/src/cmd/ndb/dn.c index dd566be06..fbcc9ac51 100644 --- a/sys/src/cmd/ndb/dn.c +++ b/sys/src/cmd/ndb/dn.c @@ -228,7 +228,7 @@ idnlookup(char *name, int class, int enter) { char dom[Domlen]; - if(utf2idn(name, dom, sizeof dom) != nil) + if(utf2idn(name, dom, sizeof dom) >= 0) name = dom; return dnlookup(name, class, enter); } @@ -1172,7 +1172,7 @@ idnname(DN *dn, char *buf, int nbuf) char *name; name = dnname(dn); - if(idn2utf(name, buf, nbuf) != nil) + if(idn2utf(name, buf, nbuf) >= 0) return buf; return name; } diff --git a/sys/src/cmd/ndb/inform.c b/sys/src/cmd/ndb/inform.c index 7837c03c0..1ebcfa35c 100644 --- a/sys/src/cmd/ndb/inform.c +++ b/sys/src/cmd/ndb/inform.c @@ -174,10 +174,10 @@ main(int argc, char *argv[]) sysfatal("no relevant dnsdomain="); - if(utf2idn(dom, dn, sizeof(dn)) == nil) + if(utf2idn(dom, dn, sizeof(dn)) <= 0) sysfatal("cannot convert dom"); - if(utf2idn(dnsdomain, ds, sizeof(ds)) == nil) + if(utf2idn(dnsdomain, ds, sizeof(ds)) <= 0) sysfatal("cannot convert dnsdomain"); if(debug){ diff --git a/sys/src/cmd/webfs/url.c b/sys/src/cmd/webfs/url.c index 65ed53802..5d0a4c44b 100644 --- a/sys/src/cmd/webfs/url.c +++ b/sys/src/cmd/webfs/url.c @@ -76,7 +76,7 @@ Nfmt(Fmt *f) char d[Domlen], *s; s = va_arg(f->args, char*); - if(utf2idn(s, d, sizeof(d)) != nil) + if(utf2idn(s, d, sizeof(d)) >= 0) s = d; fmtprint(f, "%s", s); return 0; @@ -320,7 +320,7 @@ Out: if(s = u->host){ t = emalloc(Domlen); - if(idn2utf(s, t, Domlen)){ + if(idn2utf(s, t, Domlen) >= 0){ u->host = estrdup(t); free(s); } diff --git a/sys/src/libc/9sys/idn.c b/sys/src/libc/9sys/idn.c index 94ff023a5..d3ad55dd8 100644 --- a/sys/src/libc/9sys/idn.c +++ b/sys/src/libc/9sys/idn.c @@ -184,7 +184,7 @@ punydecode(uint input_length, char input[], uint max_out, Rune output[]) * convert punycode encoded internationalized * domain name to unicode string */ -char* +int idn2utf(char *name, char *buf, int nbuf) { char *dp, *de, *cp; @@ -205,24 +205,24 @@ idn2utf(char *name, char *buf, int nbuf) } if(cistrncmp(cp, "xn--", 4) == 0) if((nr = punydecode(nc-4, cp+4, nelem(rb), rb)) < 0) - return nil; + return -1; dp = seprint(dp, de, "%.*S", nr, rb); if(dp >= de) - return nil; + return -1; if(cp[nc] == 0) break; *dp++ = '.'; cp += nc+1; } *dp = 0; - return buf; + return dp - buf; } /* * convert unicode string to punycode * encoded internationalized domain name */ -char* +int utf2idn(char *name, char *buf, int nbuf) { char *dp, *de, *cp; @@ -246,17 +246,17 @@ utf2idn(char *name, char *buf, int nbuf) else { dp = seprint(dp, de, "xn--"); if((n = punyencode(nr, rb, de - dp, dp)) < 0) - return nil; + return -1; dp += n; } if(dp >= de) - return nil; + return -1; if(cp[nc] == 0) break; *dp++ = '.'; cp += nc+1; } *dp = 0; - return buf; + return dp - buf; }