Example #1
0
File: urls.c Project: 99years/plan9
Url *
urlalloc(Runestr *src, Runestr *post, int m)
{
	Url *u;

	u = emalloc(sizeof(Url));
	copyrunestr(&u->src, src);
	if(m==HPost)
		copyrunestr(&u->post, post);
	u->method = m;
	incref(u);
	return u;
}
Example #2
0
File: urls.c Project: 99years/plan9
Url *
urldup(Url *a)
{
	Url *b;

	b = emalloc(sizeof(Url));
	b->method = a->method;
	copyrunestr(&b->src, &a->src);
	copyrunestr(&b->act, &a->act);
	copyrunestr(&b->post, &a->post);
	copyrunestr(&b->ctype, &a->ctype);
	return b;
}
Example #3
0
int
urlopen(Url *u)
{
	char buf[BUFSIZE];
	int cfd, fd, conn, n;

	urlconvience(u);
	snprint(buf, sizeof(buf), "%s/clone", webmountpt);
	cfd = open(buf, ORDWR);
	if(cfd < 0)
		error("can't open clone file");

	n = read(cfd, buf, sizeof(buf)-1);
	if(n <= 0)
		error("reading clone");

	buf[n] = '\0';
	conn = atoi(buf);

	snprint(buf, sizeof(buf), "url %S", u->src.r);
	if(write(cfd, buf, strlen(buf)) < 0){
//		fprint(2, "write: %s: %r\n", buf);
    Err:
		close(cfd);
		return -1;
	}
	if(u->method==HPost && u->post.r != nil){
		snprint(buf, sizeof(buf), "%s/%d/postbody", webmountpt, conn);
		fd = open(buf, OWRITE);
		if(fd < 0){
//			fprint(2, "urlopen: bad query: %s: %r\n", buf);
			goto Err;
		}
		snprint(buf, sizeof(buf), "%S", u->post.r);
		if(write(fd, buf, strlen(buf)) < 0)
			fprint(2, "urlopen: bad query: %s: %r\n", buf);

		close(fd);
	}
	snprint(buf, sizeof(buf), "%s/%d/body", webmountpt, conn);
	fd = open(buf, OREAD);
	if(fd < 0){
//		fprint(2, "open: %S: %r\n", u->src.r);
		goto Err;
	}
	u->ctype = getattr(conn, "contenttype");
	u->act = getattr(conn, "parsed/url");
	if(u->act.nr == 0)
		copyrunestr(&u->act, &u->src);
	close(cfd);
	return fd;
}