ref: b408b386e1b996a8b5e6041e68c1801547b4487e
parent: d6fb42f496c6053598907ce2cbb0b6536a25d201
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Aug 1 09:06:24 EDT 2015
mothra: cleanup url handling
--- a/sys/src/cmd/mothra/getpix.c
+++ b/sys/src/cmd/mothra/getpix.c
@@ -25,7 +25,7 @@
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;
@@ -32,7 +32,8 @@
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;
@@ -39,10 +40,10 @@
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 @@
t->b=b;
w->changed=1;
Out:
- free(url.basename);
- free(url.reltext);
+ freeurl(url);
}
void getpix(Rtext *t, Www *w){
--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -991,7 +991,7 @@
selurl(urlname);
selection->map=map;
- message("getting %s", selection->reltext);
+ message("getting %s", urlstr(selection));
esetcursor(&patientcurs);
for(;;){
if((fd=urlget(selection, post)) < 0){
--- a/sys/src/cmd/mothra/mothra.h
+++ b/sys/src/cmd/mothra/mothra.h
@@ -82,6 +82,7 @@
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 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 *);