make google redirectors work. Reference: /n/patches.lsub.org/patch/abacourl Date: Tue Jul 3 18:06:53 CES 2012 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/abaco/urls.c Thu Apr 12 12:25:21 2012 +++ /sys/src/cmd/abaco/urls.c Tue Jul 3 16:05:24 2012 @@ -52,8 +52,7 @@ return b; } -static -Runestr +static Runestr getattr(int conn, char *s) { char buf[BUFSIZE]; @@ -126,56 +125,76 @@ } void -urlcanon(Rune *name){ - Rune *s, *t; +urlcanon(Rune *name) +{ + Rune *s, *e, *tail, tailr; Rune **comp, **p, **q; - int rooted; + int n; + + name = runestrstr(name, L"://"); + if(name == nil) + return; + name = runestrchr(name+3, '/'); + if(name == nil) + return; + if(*name == L'/') + name++; + + n = 0; + for(e = name; *e != 0; e++) + if(*e == L'/') + n++; + comp = emalloc((n+2)*sizeof *comp); - name = runestrchr(name, L'/')+2; - rooted=name[0]==L'/'; /* * Break the name into a list of components */ - comp=emalloc(runestrlen(name)*sizeof(char *)); - p=comp; - *p++=name; - for(s=name;;s++){ - if(*s==L'/'){ - *p++=s+1; - *s='\0'; - } - else if(*s=='\0') + p = comp; + *p++ = name; + tail = nil; + tailr = L'☺'; /* silence compiler */ + for(s = name; *s != 0; s++){ + if(*s == '?' || *s == '#'){ + tail = s+1; + tailr = *s; + *s = 0; break; + } + else if(*s == L'/'){ + *p++ = s+1; + *s = 0; + } } - *p=0; + /* * go through the component list, deleting components that are empty (except - * the last component) or ., and any .. and its non-.. predecessor. + * the last component) or ., and any .. and its predecessor. */ - p=q=comp; - while(*p){ - if(runestrcmp(*p, L"")==0 && p[1]!=0 - || runestrcmp(*p, L".")==0) - p++; - else if(runestrcmp(*p, L"..")==0 && q!=comp && runestrcmp(q[-1], L"..")!=0){ - --q; - p++; - } + for(p = q = comp; *p != nil; p++){ + if(runestrcmp(*p, L"") == 0 && p[1] != nil + || runestrcmp(*p, L".") == 0) + continue; + else if(q>comp && runestrcmp(*p, L"..") == 0 && runestrcmp(q[-1], L"..") != 0) + q--; else - *q++=*p++; + *q++ = *p; } - *q=0; + *q = nil; + /* * rebuild the path name */ - s=name; - if(rooted) *s++='/'; - for(p=comp;*p;p++){ - t=*p; - while(*t) *s++=*t++; - if(p[1]!=0) *s++='/'; - } - *s='\0'; + s = name; + for(p = comp; p