xref: /plan9/sys/src/cmd/webfs/dat.h (revision 9a747e4fd48b9f4522c70c07e8f882a15030f964)
1 typedef struct Client Client;
2 typedef struct Ctl Ctl;
3 typedef struct Ibuf Ibuf;
4 typedef struct Ioproc Ioproc;
5 typedef struct Url Url;
6 
7 /* simple buffered i/o for network connections; shared by http, ftp */
8 struct Ibuf
9 {
10 	int fd;
11 	Ioproc *io;
12 	char buf[4096];
13 	char *rp, *wp;
14 };
15 
16 struct Ctl
17 {
18 	int	acceptcookies;
19 	int	sendcookies;
20 	int	redirectlimit;
21 	char	*useragent;
22 };
23 
24 struct Client
25 {
26 	Url	*url;
27 	Url	*baseurl;
28 	Ctl ctl;
29 	Channel *creq;	/* chan(Req*) */
30 	int num;
31 	int plumbed;
32 	char *contenttype;
33 	char *postbody;
34 	char *redirect;
35 	char *ext;
36 	int npostbody;
37 	int havepostbody;
38 	int iobusy;
39 	int bodyopened;
40 	Ioproc *io;
41 	int ref;
42 	void *aux;
43 };
44 
45 /* asynchronous i/o in another proc */
46 struct Ioproc
47 {
48 	long (*read)(Ioproc*, int, void*, long);
49 	long (*write)(Ioproc*, int, void*, long);
50 	int (*dial)(Ioproc*, char*, char*, char*, int*, int);
51 	int (*close)(Ioproc*, int);
52 	int (*open)(Ioproc*, char*, int);
53 	int (*print)(Ioproc*, int, char*, ...);
54 	void (*interrupt)(Ioproc*);
55 
56 	int pid;	/* internal */
57 	Channel *c;
58 	int inuse;
59 	void (*op)(Ioproc*);
60 	long arg[10];
61 	long ret;
62 	char err[ERRMAX];
63 	Ioproc *next;
64 };
65 
66 /*
67  * If ischeme is USunknown, then the given URL is a relative
68  * URL which references the "current document" in the context of the base.
69  * If this is the case, only the "fragment" and "url" members will have
70  * meaning, and the given URL structure may not be used as a base URL itself.
71  */
72 enum
73 {
74 	USunknown,
75 	UShttp,
76 	UShttps,
77 	USftp,
78 	USfile,
79 	UScurrent,
80 };
81 
82 struct Url
83 {
84 	int		ischeme;
85 	char*	url;
86 	char*	scheme;
87 	int		(*open)(Client*, Url*);
88 	int		(*read)(Client*, Req*);
89 	void		(*close)(Client*);
90 	char*	schemedata;
91 	char*	authority;
92 	char*	user;
93 	char*	passwd;
94 	char*	host;
95 	char*	port;
96 	char*	path;
97 	char*	query;
98 	char*	fragment;
99 	union {
100 		struct {
101 			char *page_spec;
102 		} http;
103 		struct {
104 			char *path_spec;
105 			char *type;
106 		} ftp;
107 	};
108 };
109 
110 enum
111 {
112 	STACK = 8192,
113 };
114 
115 extern	Client**	client;
116 extern	int		cookiedebug;
117 extern	Srv		fs;
118 extern	int		fsdebug;
119 extern	Ctl		globalctl;
120 extern	int		nclient;
121 extern	int		urldebug;
122 extern	int		httpdebug;
123 extern	char*	status[];
124 
125