From b408b386e1b996a8b5e6041e68c1801547b4487e Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 1 Aug 2015 13:06:24 +0200 Subject: [PATCH] mothra: cleanup url handling --- sys/src/cmd/mothra/getpix.c | 12 ++++++------ sys/src/cmd/mothra/mothra.c | 2 +- sys/src/cmd/mothra/mothra.h | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/sys/src/cmd/mothra/getpix.c b/sys/src/cmd/mothra/getpix.c index 4428959d5..0ab52afc5 100644 --- a/sys/src/cmd/mothra/getpix.c +++ b/sys/src/cmd/mothra/getpix.c @@ -25,24 +25,25 @@ char *pixcmd[]={ void getimage(Rtext *t, Www *w){ int pfd[2]; Action *ap; - Url url; + Url *url; Image *b; int fd, typ; char err[512], buf[80], *s; Pix *p; ap=t->user; - seturl(&url, ap->image, w->url->fullname); + url=emalloc(sizeof(Url)); + seturl(url, ap->image, w->url->fullname); for(p=w->pix;p!=nil; p=p->next) if(strcmp(ap->image, p->name)==0 && ap->width==p->width && ap->height==p->height){ t->b = p->b; w->changed=1; return; } - fd=urlget(&url, -1); + fd=urlget(url, -1); if(fd==-1){ Err: - snprint(err, sizeof(err), "[img: %s: %r]", url.reltext); + snprint(err, sizeof(err), "[img: %s: %r]", urlstr(url)); free(t->text); t->text=strdup(err); w->changed=1; @@ -82,8 +83,7 @@ void getimage(Rtext *t, Www *w){ t->b=b; w->changed=1; Out: - free(url.basename); - free(url.reltext); + freeurl(url); } void getpix(Rtext *t, Www *w){ diff --git a/sys/src/cmd/mothra/mothra.c b/sys/src/cmd/mothra/mothra.c index abb5750f0..b35c08a1b 100644 --- a/sys/src/cmd/mothra/mothra.c +++ b/sys/src/cmd/mothra/mothra.c @@ -991,7 +991,7 @@ void geturl(char *urlname, int post, int plumb, int map){ selurl(urlname); selection->map=map; - message("getting %s", selection->reltext); + message("getting %s", urlstr(selection)); esetcursor(&patientcurs); for(;;){ if((fd=urlget(selection, post)) < 0){ diff --git a/sys/src/cmd/mothra/mothra.h b/sys/src/cmd/mothra/mothra.h index 80d79269c..0d4553cf8 100644 --- a/sys/src/cmd/mothra/mothra.h +++ b/sys/src/cmd/mothra/mothra.h @@ -82,6 +82,7 @@ void plrdhtml(char *, int, Www *); void plrdplain(char *, int, Www *); void htmlerror(char *, int, char *, ...); /* user-supplied routine */ void seturl(Url *, char *, char *); +void freeurl(Url *); Url *selurl(char *); void getpix(Rtext *, Www *); ulong countpix(void *p); @@ -99,6 +100,7 @@ int filetype(int, char *, int); int snooptype(int); void mkfieldpanel(Rtext *); void geturl(char *, int, int, int); +char *urlstr(Url *); int urlpost(Url*, char*); int urlget(Url*, int); int urlresolve(Url *);