1 | /* |
---|
2 | * webs.h -- GoAhead Web public header |
---|
3 | * |
---|
4 | * Copyright (c) GoAhead Software Inc., 1992-2000. All Rights Reserved. |
---|
5 | * |
---|
6 | * See the file "license.txt" for information on usage and redistribution |
---|
7 | * |
---|
8 | * $Id$ |
---|
9 | */ |
---|
10 | |
---|
11 | #ifndef _h_WEBS |
---|
12 | #define _h_WEBS 1 |
---|
13 | |
---|
14 | /******************************** Description *********************************/ |
---|
15 | |
---|
16 | /* |
---|
17 | * GoAhead Web Server header. This defines the Web public APIs. |
---|
18 | * Include this header for files that contain ASP or Form procedures. |
---|
19 | * Include wsIntrn.h when creating URL handlers. |
---|
20 | */ |
---|
21 | |
---|
22 | /********************************* Includes ***********************************/ |
---|
23 | |
---|
24 | #include "ej.h" |
---|
25 | #ifdef WEBS_SSL_SUPPORT |
---|
26 | #include "websSSL.h" |
---|
27 | #endif |
---|
28 | |
---|
29 | /********************************** Defines ***********************************/ |
---|
30 | /* |
---|
31 | * By license terms the server software name defined in the following line of |
---|
32 | * code must not be modified. |
---|
33 | */ |
---|
34 | #define WEBS_NAME T("GoAhead-Webs") |
---|
35 | #define WEBS_VERSION T("2.1.3") |
---|
36 | |
---|
37 | #define WEBS_HEADER_BUFINC 512 /* Header buffer size */ |
---|
38 | #define WEBS_ASP_BUFINC 512 /* Asp expansion increment */ |
---|
39 | #define WEBS_MAX_PASS 32 /* Size of password */ |
---|
40 | #define WEBS_BUFSIZE 1000 /* websWrite max output string */ |
---|
41 | #define WEBS_MAX_HEADER (5 * 1024) /* Sanity check header */ |
---|
42 | #define WEBS_MAX_URL 4096 /* Maximum URL size for sanity */ |
---|
43 | #define WEBS_SOCKET_BUFSIZ 256 /* Bytes read from socket */ |
---|
44 | |
---|
45 | #define WEBS_HTTP_PORT T("httpPort") |
---|
46 | #define CGI_BIN T("cgi-bin") |
---|
47 | |
---|
48 | /* |
---|
49 | * Request flags. Also returned by websGetRequestFlags(). |
---|
50 | */ |
---|
51 | #define WEBS_LOCAL_PAGE 0x1 /* Request for local webs page */ |
---|
52 | #define WEBS_KEEP_ALIVE 0x2 /* HTTP/1.1 keep alive */ |
---|
53 | #define WEBS_DONT_USE_CACHE 0x4 /* Not implemented cache support */ |
---|
54 | #define WEBS_COOKIE 0x8 /* Cookie supplied in request */ |
---|
55 | #define WEBS_IF_MODIFIED 0x10 /* If-modified-since in request */ |
---|
56 | #define WEBS_POST_REQUEST 0x20 /* Post request operation */ |
---|
57 | #define WEBS_LOCAL_REQUEST 0x40 /* Request from this system */ |
---|
58 | #define WEBS_HOME_PAGE 0x80 /* Request for the home page */ |
---|
59 | #define WEBS_ASP 0x100 /* ASP request */ |
---|
60 | #define WEBS_HEAD_REQUEST 0x200 /* Head request */ |
---|
61 | #define WEBS_CLEN 0x400 /* Request had a content length */ |
---|
62 | #define WEBS_FORM 0x800 /* Request is a form */ |
---|
63 | #define WEBS_REQUEST_DONE 0x1000 /* Request complete */ |
---|
64 | #define WEBS_POST_DATA 0x2000 /* Already appended post data */ |
---|
65 | #define WEBS_CGI_REQUEST 0x4000 /* cgi-bin request */ |
---|
66 | #define WEBS_SECURE 0x8000 /* connection uses SSL */ |
---|
67 | #define WEBS_AUTH_BASIC 0x10000 /* Basic authentication request */ |
---|
68 | #define WEBS_AUTH_DIGEST 0x20000 /* Digest authentication request */ |
---|
69 | #define WEBS_HEADER_DONE 0x40000 /* Already output the HTTP header */ |
---|
70 | |
---|
71 | /* |
---|
72 | * URL handler flags |
---|
73 | */ |
---|
74 | #define WEBS_HANDLER_FIRST 0x1 /* Process this handler first */ |
---|
75 | #define WEBS_HANDLER_LAST 0x2 /* Process this handler last */ |
---|
76 | |
---|
77 | /* |
---|
78 | * Per socket connection webs structure |
---|
79 | */ |
---|
80 | typedef struct websRec { |
---|
81 | ringq_t header; /* Header dynamic string */ |
---|
82 | time_t since; /* Parsed if-modified-since time */ |
---|
83 | sym_fd_t cgiVars; /* CGI standard variables */ |
---|
84 | sym_fd_t cgiQuery; /* CGI decoded query string */ |
---|
85 | time_t timestamp; /* Last transaction with browser */ |
---|
86 | int timeout; /* Timeout handle */ |
---|
87 | char_t ipaddr[32]; /* Connecting ipaddress */ |
---|
88 | char_t type[64]; /* Mime type */ |
---|
89 | char_t *dir; /* Directory containing the page */ |
---|
90 | char_t *path; /* Path name without query */ |
---|
91 | char_t *url; /* Full request url */ |
---|
92 | char_t *host; /* Requested host */ |
---|
93 | char_t *lpath; /* Cache local path name */ |
---|
94 | char_t *query; /* Request query */ |
---|
95 | char_t *decodedQuery; /* Decoded request query */ |
---|
96 | char_t *authType; /* Authorization type (Basic/DAA) */ |
---|
97 | char_t *password; /* Authorization password */ |
---|
98 | char_t *userName; /* Authorization username */ |
---|
99 | char_t *cookie; /* Cookie string */ |
---|
100 | char_t *userAgent; /* User agent (browser) */ |
---|
101 | char_t *protocol; /* Protocol (normally HTTP) */ |
---|
102 | char_t *protoVersion; /* Protocol version */ |
---|
103 | int sid; /* Socket id (handler) */ |
---|
104 | int listenSid; /* Listen Socket id */ |
---|
105 | int port; /* Request port number */ |
---|
106 | int state; /* Current state */ |
---|
107 | int flags; /* Current flags -- see above */ |
---|
108 | int code; /* Request result code */ |
---|
109 | int clen; /* Content length */ |
---|
110 | int wid; /* Index into webs */ |
---|
111 | char_t *cgiStdin; /* filename for CGI stdin */ |
---|
112 | int docfd; /* Document file descriptor */ |
---|
113 | int numbytes; /* Bytes to transfer to browser */ |
---|
114 | int written; /* Bytes actually transferred */ |
---|
115 | void (*writeSocket)(struct websRec *wp); |
---|
116 | #ifdef DIGEST_ACCESS_SUPPORT |
---|
117 | char_t *realm; /* usually the same as "host" from websRec */ |
---|
118 | char_t *nonce; /* opaque-to-client string sent by server */ |
---|
119 | char_t *digest; /* digest form of user password */ |
---|
120 | char_t *uri; /* URI found in DAA header */ |
---|
121 | char_t *opaque; /* opaque value passed from server */ |
---|
122 | char_t *nc; /* nonce count */ |
---|
123 | char_t *cnonce; /* check nonce */ |
---|
124 | char_t *qop; /* quality operator */ |
---|
125 | #endif |
---|
126 | #ifdef WEBS_SSL_SUPPORT |
---|
127 | websSSL_t *wsp; /* SSL data structure */ |
---|
128 | #endif |
---|
129 | } websRec; |
---|
130 | |
---|
131 | typedef websRec *webs_t; |
---|
132 | typedef websRec websType; |
---|
133 | |
---|
134 | /******************************** Prototypes **********************************/ |
---|
135 | extern int websAccept(int sid, char *ipaddr, int port, int listenSid); |
---|
136 | extern int websAspDefine(char_t *name, |
---|
137 | int (*fn)(int ejid, webs_t wp, int argc, char_t **argv)); |
---|
138 | extern int websAspRequest(webs_t wp, char_t *lpath); |
---|
139 | extern void websCloseListen(); |
---|
140 | extern int websDecode64(char_t *outbuf, char_t *string, int buflen); |
---|
141 | extern void websDecodeUrl(char_t *token, char_t *decoded, int len); |
---|
142 | extern void websDone(webs_t wp, int code); |
---|
143 | extern void websEncode64(char_t *outbuf, char_t *string, int buflen); |
---|
144 | extern void websError(webs_t wp, int code, char_t *msg, ...); |
---|
145 | /* function websErrorMsg() made extern 03 Jun 02 BgP */ |
---|
146 | extern char_t *websErrorMsg(int code); |
---|
147 | extern void websFooter(webs_t wp); |
---|
148 | extern int websFormDefine(char_t *name, void (*fn)(webs_t wp, |
---|
149 | char_t *path, char_t *query)); |
---|
150 | extern char_t *websGetDefaultDir(); |
---|
151 | extern char_t *websGetDefaultPage(); |
---|
152 | extern char_t *websGetHostUrl(); |
---|
153 | extern char_t *websGetIpaddrUrl(); |
---|
154 | extern char_t *websGetPassword(); |
---|
155 | extern int websGetPort(); |
---|
156 | extern char_t *websGetPublishDir(char_t *path, char_t **urlPrefix); |
---|
157 | extern char_t *websGetRealm(); |
---|
158 | extern int websGetRequestBytes(webs_t wp); |
---|
159 | extern char_t *websGetRequestDir(webs_t wp); |
---|
160 | extern int websGetRequestFlags(webs_t wp); |
---|
161 | extern char_t *websGetRequestIpaddr(webs_t wp); |
---|
162 | extern char_t *websGetRequestLpath(webs_t wp); |
---|
163 | extern char_t *websGetRequestPath(webs_t wp); |
---|
164 | extern char_t *websGetRequestPassword(webs_t wp); |
---|
165 | extern char_t *websGetRequestType(webs_t wp); |
---|
166 | extern int websGetRequestWritten(webs_t wp); |
---|
167 | extern char_t *websGetVar(webs_t wp, char_t *var, char_t *def); |
---|
168 | extern int websCompareVar(webs_t wp, char_t *var, char_t *value); |
---|
169 | extern void websHeader(webs_t wp); |
---|
170 | extern int websOpenListen(int port, int retries); |
---|
171 | extern int websPageOpen(webs_t wp, char_t *lpath, char_t *path, |
---|
172 | int mode, int perm); |
---|
173 | extern void websPageClose(webs_t wp); |
---|
174 | extern int websPublish(char_t *urlPrefix, char_t *path); |
---|
175 | extern void websRedirect(webs_t wp, char_t *url); |
---|
176 | extern void websSecurityDelete(); |
---|
177 | extern int websSecurityHandler(webs_t wp, char_t *urlPrefix, |
---|
178 | char_t *webDir, int arg, char_t *url, char_t *path, |
---|
179 | char_t *query); |
---|
180 | extern void websSetDefaultDir(char_t *dir); |
---|
181 | extern void websSetDefaultPage(char_t *page); |
---|
182 | extern void websSetEnv(webs_t wp); |
---|
183 | extern void websSetHost(char_t *host); |
---|
184 | extern void websSetIpaddr(char_t *ipaddr); |
---|
185 | extern void websSetPassword(char_t *password); |
---|
186 | extern void websSetRealm(char_t *realmName); |
---|
187 | extern void websSetRequestBytes(webs_t wp, int bytes); |
---|
188 | extern void websSetRequestFlags(webs_t wp, int flags); |
---|
189 | extern void websSetRequestLpath(webs_t wp, char_t *lpath); |
---|
190 | extern void websSetRequestPath(webs_t wp, char_t *dir, char_t *path); |
---|
191 | extern char_t *websGetRequestUserName(webs_t wp); |
---|
192 | extern void websSetRequestWritten(webs_t wp, int written); |
---|
193 | extern void websSetVar(webs_t wp, char_t *var, char_t *value); |
---|
194 | extern int websTestVar(webs_t wp, char_t *var); |
---|
195 | extern void websTimeoutCancel(webs_t wp); |
---|
196 | extern int websUrlHandlerDefine(char_t *urlPrefix, char_t *webDir, |
---|
197 | int arg, int (*fn)(webs_t wp, char_t *urlPrefix, |
---|
198 | char_t *webDir, int arg, char_t *url, char_t *path, |
---|
199 | char_t *query), int flags); |
---|
200 | extern int websUrlHandlerDelete(int (*fn)(webs_t wp, char_t *urlPrefix, |
---|
201 | char_t *webDir, int arg, char_t *url, char_t *path, |
---|
202 | char_t *query)); |
---|
203 | extern int websUrlHandlerRequest(webs_t wp); |
---|
204 | extern int websUrlParse(char_t *url, char_t **buf, char_t **host, |
---|
205 | char_t **path, char_t **port, char_t **query, |
---|
206 | char_t **proto, char_t **tag, char_t **ext); |
---|
207 | extern char_t *websUrlType(char_t *webs, char_t *buf, int charCnt); |
---|
208 | extern int websWrite(webs_t wp, char_t* fmt, ...); |
---|
209 | extern int websWriteBlock(webs_t wp, char_t *buf, int nChars); |
---|
210 | extern int websWriteDataNonBlock(webs_t wp, char *buf, int nChars); |
---|
211 | extern int websValid(webs_t wp); |
---|
212 | extern int websValidateUrl(webs_t wp, char_t *path); |
---|
213 | extern void websSetTimeMark(webs_t wp); |
---|
214 | |
---|
215 | /* |
---|
216 | * The following prototypes are used by the SSL patch found in websSSL.c |
---|
217 | */ |
---|
218 | extern int websAlloc(int sid); |
---|
219 | extern void websFree(webs_t wp); |
---|
220 | extern void websTimeout(void *arg, int id); |
---|
221 | extern void websReadEvent(webs_t wp); |
---|
222 | |
---|
223 | /* |
---|
224 | * Prototypes for functions available when running as part of the |
---|
225 | * GoAhead Embedded Management Framework (EMF) |
---|
226 | */ |
---|
227 | #ifdef EMF |
---|
228 | extern void websFormExplain(webs_t wp, char_t *path, char_t *query); |
---|
229 | #endif |
---|
230 | |
---|
231 | #endif /* _h_WEBS */ |
---|
232 | |
---|
233 | /******************************************************************************/ |
---|