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