summaryrefslogtreecommitdiff
path: root/sys/src/cmd/webfs/url.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2013-11-24 11:56:33 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2013-11-24 11:56:33 +0100
commitf2bd1de5bdba2449f01085984483702adb833fea (patch)
treefa9555065cbf71382d4a8a11037e7aaab333560f /sys/src/cmd/webfs/url.c
parent3720b5ab9c4cb485c64e83d8af740aea3680123b (diff)
webfs: support for internationalized domain name urls
Diffstat (limited to 'sys/src/cmd/webfs/url.c')
-rw-r--r--sys/src/cmd/webfs/url.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/sys/src/cmd/webfs/url.c b/sys/src/cmd/webfs/url.c
index 784a67393..ebd538dbf 100644
--- a/sys/src/cmd/webfs/url.c
+++ b/sys/src/cmd/webfs/url.c
@@ -69,6 +69,21 @@ Efmt(Fmt *f)
}
int
+Hfmt(Fmt *f)
+{
+ char *d, *s;
+
+ s = va_arg(f->args, char*);
+ d = emalloc(Domlen);
+ if(utf2idn(s, d, Domlen) == nil)
+ d = s;
+ fmtprint(f, "%s", d);
+ if(d != s)
+ free(d);
+ return 0;
+}
+
+int
Ufmt(Fmt *f)
{
char *s;
@@ -87,7 +102,7 @@ Ufmt(Fmt *f)
fmtprint(f, "@");
}
if(u->host){
- fmtprint(f, strchr(u->host, ':') ? "[%s]" : "%s", u->host);
+ fmtprint(f, strchr(u->host, ':') ? "[%s]" : "%H", u->host);
if(u->port)
fmtprint(f, ":%s", u->port);
}
@@ -184,12 +199,17 @@ pstrdup(char **p)
static char*
mklowcase(char *s)
{
- char *p;
-
+ char *cp;
+ Rune r;
+
if(s == nil)
return s;
- for(p = s; *p; p++)
- *p = tolower(*p);
+ cp = s;
+ while(*cp != 0){
+ chartorune(&r, cp);
+ r = tolowerrune(r);
+ cp += runetochar(cp, &r);
+ }
return s;
}
@@ -299,6 +319,15 @@ Out:
while(s = strchr(s, '+'))
*s++ = ' ';
+ if(s = u->host){
+ t = emalloc(Domlen);
+ if(idn2utf(s, t, Domlen)){
+ u->host = estrdup(t);
+ free(s);
+ }
+ free(t);
+ }
+
unescape(u->user, "");
unescape(u->pass, "");
unescape(u->path, "/");