1 |
1026 |
ivang |
/*
|
2 |
|
|
* wsIntrn.h -- Internal GoAhead Web server 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_INTERNAL
|
10 |
|
|
#define _h_WEBS_INTERNAL 1
|
11 |
|
|
|
12 |
|
|
/******************************** Description *********************************/
|
13 |
|
|
|
14 |
|
|
/*
|
15 |
|
|
* Internal GoAhead Web Server header. This defines the Web private APIs
|
16 |
|
|
* Include this header when you want to create URL handlers.
|
17 |
|
|
*/
|
18 |
|
|
|
19 |
|
|
/*********************************** Defines **********************************/
|
20 |
|
|
|
21 |
|
|
/*
|
22 |
|
|
* Define this to enable login of web accesses to a file
|
23 |
|
|
* #define WEBS_LOG_SUPPORT 1
|
24 |
|
|
*
|
25 |
|
|
* Define this to enable HTTP/1.1 keep alive support
|
26 |
|
|
* #define WEBS_KEEP_ALIVE_SUPPORT 1
|
27 |
|
|
*
|
28 |
|
|
* Define this to enable if-modified-since support
|
29 |
|
|
* #define WEBS_IF_MODIFIED_SUPPORT 1
|
30 |
|
|
*
|
31 |
|
|
* Define this to support proxy capability and track local vs remote request
|
32 |
|
|
* Note: this is not yet fully implemented.
|
33 |
|
|
* #define WEBS_PROXY_SUPPORT 1
|
34 |
|
|
*
|
35 |
|
|
* Define this to support reading pages from ROM
|
36 |
|
|
* #define WEBS_PAGE_ROM 1
|
37 |
|
|
*
|
38 |
|
|
* Define this to enable memory allocation and stack usage tracking
|
39 |
|
|
* #define B_STATS 1
|
40 |
|
|
*/
|
41 |
|
|
|
42 |
|
|
/********************************** Includes **********************************/
|
43 |
|
|
|
44 |
|
|
#include <ctype.h>
|
45 |
|
|
#include <stdlib.h>
|
46 |
|
|
#include <string.h>
|
47 |
|
|
#include <stdarg.h>
|
48 |
|
|
|
49 |
|
|
#if WIN
|
50 |
|
|
#include <fcntl.h>
|
51 |
|
|
#include <sys/stat.h>
|
52 |
|
|
#include <io.h>
|
53 |
|
|
#endif
|
54 |
|
|
|
55 |
|
|
#if CE
|
56 |
|
|
#if ! UEMF
|
57 |
|
|
#include <io.h>
|
58 |
|
|
#endif
|
59 |
|
|
#endif
|
60 |
|
|
|
61 |
|
|
#if NW
|
62 |
|
|
#include <fcntl.h>
|
63 |
|
|
#include <sys/stat.h>
|
64 |
|
|
#endif
|
65 |
|
|
|
66 |
|
|
#if SCOV5
|
67 |
|
|
#include <fcntl.h>
|
68 |
|
|
#include <sys/stat.h>
|
69 |
|
|
#include <signal.h>
|
70 |
|
|
#include <unistd.h>
|
71 |
|
|
#endif
|
72 |
|
|
|
73 |
|
|
#if LYNX
|
74 |
|
|
#include <fcntl.h>
|
75 |
|
|
#include <sys/stat.h>
|
76 |
|
|
#include <signal.h>
|
77 |
|
|
#include <unistd.h>
|
78 |
|
|
#endif
|
79 |
|
|
|
80 |
|
|
#if UNIX
|
81 |
|
|
#include <fcntl.h>
|
82 |
|
|
#include <sys/stat.h>
|
83 |
|
|
#include <signal.h>
|
84 |
|
|
#include <unistd.h>
|
85 |
|
|
#endif
|
86 |
|
|
|
87 |
|
|
#if QNX4
|
88 |
|
|
#include <fcntl.h>
|
89 |
|
|
#include <sys/stat.h>
|
90 |
|
|
#include <signal.h>
|
91 |
|
|
#include <unistd.h>
|
92 |
|
|
#include <unix.h>
|
93 |
|
|
#endif
|
94 |
|
|
|
95 |
|
|
#if UW
|
96 |
|
|
#include <fcntl.h>
|
97 |
|
|
#include <sys/stat.h>
|
98 |
|
|
#endif
|
99 |
|
|
|
100 |
|
|
#if VXWORKS
|
101 |
|
|
#include <vxWorks.h>
|
102 |
|
|
#include <fcntl.h>
|
103 |
|
|
#include <sys/stat.h>
|
104 |
|
|
#endif
|
105 |
|
|
|
106 |
|
|
#if SOLARIS
|
107 |
|
|
#include <macros.h>
|
108 |
|
|
#include <fcntl.h>
|
109 |
|
|
#include <sys/stat.h>
|
110 |
|
|
#endif
|
111 |
|
|
|
112 |
|
|
#if UEMF
|
113 |
|
|
#include "uemf.h"
|
114 |
|
|
#include "ejIntrn.h"
|
115 |
|
|
#else
|
116 |
|
|
#include "emf/emfInternal.h"
|
117 |
|
|
#include "ej/ejIntrn.h"
|
118 |
|
|
#endif
|
119 |
|
|
|
120 |
|
|
#include "webs.h"
|
121 |
|
|
|
122 |
|
|
/********************************** Defines ***********************************/
|
123 |
|
|
/*
|
124 |
|
|
* Read handler flags and state
|
125 |
|
|
*/
|
126 |
|
|
#define WEBS_BEGIN 0x1 /* Beginning state */
|
127 |
|
|
#define WEBS_HEADER 0x2 /* Ready to read first line */
|
128 |
|
|
#define WEBS_POST 0x4 /* POST without content */
|
129 |
|
|
#define WEBS_POST_CLEN 0x8 /* Ready to read content for POST */
|
130 |
|
|
#define WEBS_PROCESSING 0x10 /* Processing request */
|
131 |
|
|
#define WEBS_KEEP_TIMEOUT 15000 /* Keep-alive timeout (15 secs) */
|
132 |
|
|
#define WEBS_TIMEOUT 60000 /* General request timeout (60) */
|
133 |
|
|
|
134 |
|
|
#define PAGE_READ_BUFSIZE 512 /* bytes read from page files */
|
135 |
|
|
#define MAX_PORT_LEN 10 /* max digits in port number */
|
136 |
|
|
#define WEBS_SYM_INIT 64 /* initial # of sym table entries */
|
137 |
|
|
#define WEBS_VERSION_STR T("2.1.3") /* version of web server s/w */
|
138 |
|
|
|
139 |
|
|
/*
|
140 |
|
|
* URL handler structure. Stores the leading URL path and the handler
|
141 |
|
|
* function to call when the URL path is seen.
|
142 |
|
|
*/
|
143 |
|
|
typedef struct {
|
144 |
|
|
int (*handler)(webs_t wp, char_t *urlPrefix, char_t *webDir, int arg,
|
145 |
|
|
char_t *url, char_t *path,
|
146 |
|
|
char_t *query); /* Callback URL handler function */
|
147 |
|
|
char_t *webDir; /* Web directory if required */
|
148 |
|
|
char_t *urlPrefix; /* URL leading prefix */
|
149 |
|
|
int len; /* Length of urlPrefix for speed */
|
150 |
|
|
int arg; /* Argument to provide to handler */
|
151 |
|
|
int flags; /* Flags */
|
152 |
|
|
} websUrlHandlerType;
|
153 |
|
|
|
154 |
|
|
/*
|
155 |
|
|
* Webs statistics
|
156 |
|
|
*/
|
157 |
|
|
typedef struct {
|
158 |
|
|
long errors; /* General errors */
|
159 |
|
|
long redirects;
|
160 |
|
|
long net_requests;
|
161 |
|
|
long activeNetRequests;
|
162 |
|
|
long activeBrowserRequests;
|
163 |
|
|
long timeouts;
|
164 |
|
|
long access; /* Access violations */
|
165 |
|
|
long localHits;
|
166 |
|
|
long remoteHits;
|
167 |
|
|
long formHits;
|
168 |
|
|
long cgiHits;
|
169 |
|
|
long handlerHits;
|
170 |
|
|
} websStatsType;
|
171 |
|
|
|
172 |
|
|
extern websStatsType websStats; /* Web access stats */
|
173 |
|
|
|
174 |
|
|
/*
|
175 |
|
|
* Error code list
|
176 |
|
|
*/
|
177 |
|
|
typedef struct {
|
178 |
|
|
int code; /* HTTP error code */
|
179 |
|
|
char_t *msg; /* HTTP error message */
|
180 |
|
|
} websErrorType;
|
181 |
|
|
|
182 |
|
|
/*
|
183 |
|
|
* Mime type list
|
184 |
|
|
*/
|
185 |
|
|
typedef struct {
|
186 |
|
|
char_t *type; /* Mime type */
|
187 |
|
|
char_t *ext; /* File extension */
|
188 |
|
|
} websMimeType;
|
189 |
|
|
|
190 |
|
|
/*
|
191 |
|
|
* File information structure.
|
192 |
|
|
*/
|
193 |
|
|
typedef struct {
|
194 |
|
|
unsigned long size; /* File length */
|
195 |
|
|
int isDir; /* Set if directory */
|
196 |
|
|
time_t mtime; /* Modified time */
|
197 |
|
|
} websStatType;
|
198 |
|
|
|
199 |
|
|
/*
|
200 |
|
|
* Compiled Rom Page Index
|
201 |
|
|
*/
|
202 |
|
|
typedef struct {
|
203 |
|
|
char_t *path; /* Web page URL path */
|
204 |
|
|
const unsigned char *page; /* Web page data */
|
205 |
|
|
int size; /* Size of web page in bytes */
|
206 |
|
|
int pos; /* Current read position */
|
207 |
|
|
} websRomPageIndexType;
|
208 |
|
|
|
209 |
|
|
/*
|
210 |
|
|
* Defines for file open.
|
211 |
|
|
*/
|
212 |
|
|
#ifndef CE
|
213 |
|
|
#define SOCKET_RDONLY O_RDONLY
|
214 |
|
|
#define SOCKET_BINARY O_BINARY
|
215 |
|
|
#else /* CE */
|
216 |
|
|
#define SOCKET_RDONLY 0x1
|
217 |
|
|
#define SOCKET_BINARY 0x2
|
218 |
|
|
#endif /* CE */
|
219 |
|
|
|
220 |
|
|
extern websRomPageIndexType websRomPageIndex[];
|
221 |
|
|
extern websMimeType websMimeList[]; /* List of mime types */
|
222 |
|
|
extern sym_fd_t websMime; /* Set of mime types */
|
223 |
|
|
extern webs_t* webs; /* Session list head */
|
224 |
|
|
extern int websMax; /* List size */
|
225 |
|
|
extern char_t websHost[64]; /* Name of this host */
|
226 |
|
|
extern char_t websIpaddr[64]; /* IP address of this host */
|
227 |
|
|
extern char_t *websHostUrl; /* URL for this host */
|
228 |
|
|
extern char_t *websIpaddrUrl; /* URL for this host */
|
229 |
|
|
extern int websPort; /* Port number */
|
230 |
|
|
|
231 |
|
|
/******************************** Prototypes **********************************/
|
232 |
|
|
|
233 |
|
|
extern int websAspOpen();
|
234 |
|
|
extern void websAspClose();
|
235 |
|
|
extern void websFormOpen();
|
236 |
|
|
extern void websFormClose();
|
237 |
|
|
extern int websAspWrite(int ejid, webs_t wp, int argc, char_t **argv);
|
238 |
|
|
extern void websDefaultClose();
|
239 |
|
|
extern int websDefaultHandler(webs_t wp, char_t *urlPrefix,
|
240 |
|
|
char_t *webDir, int arg, char_t *url, char_t *path,
|
241 |
|
|
char_t *query);
|
242 |
|
|
extern int websFormHandler(webs_t wp, char_t *urlPrefix, char_t *webDir,
|
243 |
|
|
int arg, char_t *url, char_t *path, char_t *query);
|
244 |
|
|
extern int websCgiHandler(webs_t wp, char_t *urlPrefix, char_t *webDir,
|
245 |
|
|
int arg, char_t *url, char_t *path, char_t *query);
|
246 |
|
|
extern void websCgiCleanup();
|
247 |
|
|
extern int websCheckCgiProc(int handle);
|
248 |
|
|
extern char_t *websGetCgiCommName();
|
249 |
|
|
|
250 |
|
|
extern int websLaunchCgiProc(char_t *cgiPath, char_t **argp,
|
251 |
|
|
char_t **envp, char_t *stdIn, char_t *stdOut);
|
252 |
|
|
extern int websOpen(int sid);
|
253 |
|
|
extern void websResponse(webs_t wp, int code, char_t *msg,
|
254 |
|
|
char_t *redirect);
|
255 |
|
|
extern int websJavaScriptEval(webs_t wp, char_t *script);
|
256 |
|
|
extern int websPageReadData(webs_t wp, char *buf, int nBytes);
|
257 |
|
|
extern int websPageOpen(webs_t wp, char_t *lpath, char_t *path, int mode,
|
258 |
|
|
int perm);
|
259 |
|
|
extern void websPageClose(webs_t wp);
|
260 |
|
|
extern void websPageSeek(webs_t wp, long offset);
|
261 |
|
|
extern int websPageStat(webs_t wp, char_t *lpath, char_t *path,
|
262 |
|
|
websStatType *sbuf);
|
263 |
|
|
extern int websPageIsDirectory(char_t *lpath);
|
264 |
|
|
extern int websRomOpen();
|
265 |
|
|
extern void websRomClose();
|
266 |
|
|
extern int websRomPageOpen(webs_t wp, char_t *path, int mode, int perm);
|
267 |
|
|
extern void websRomPageClose(int fd);
|
268 |
|
|
extern int websRomPageReadData(webs_t wp, char *buf, int len);
|
269 |
|
|
extern int websRomPageStat(char_t *path, websStatType *sbuf);
|
270 |
|
|
extern long websRomPageSeek(webs_t wp, long offset, int origin);
|
271 |
|
|
extern void websSetRequestSocketHandler(webs_t wp, int mask,
|
272 |
|
|
void (*fn)(webs_t wp));
|
273 |
|
|
extern int websSolutionHandler(webs_t wp, char_t *urlPrefix,
|
274 |
|
|
char_t *webDir, int arg, char_t *url, char_t *path,
|
275 |
|
|
char_t *query);
|
276 |
|
|
extern void websUrlHandlerClose();
|
277 |
|
|
extern int websUrlHandlerOpen();
|
278 |
|
|
extern int websOpenServer(int port, int retries);
|
279 |
|
|
extern void websCloseServer();
|
280 |
|
|
extern char_t* websGetDateString(websStatType* sbuf);
|
281 |
|
|
|
282 |
|
|
extern int strcmpci(char_t* s1, char_t* s2);
|
283 |
|
|
|
284 |
|
|
/*
|
285 |
|
|
* Prototypes for functions available when running as part of the
|
286 |
|
|
* GoAhead Embedded Management Framework (EMF)
|
287 |
|
|
*/
|
288 |
|
|
#if EMF
|
289 |
|
|
extern int websEmfOpen();
|
290 |
|
|
extern void websEmfClose();
|
291 |
|
|
extern void websSetEmfEnvironment(webs_t wp);
|
292 |
|
|
#endif
|
293 |
|
|
|
294 |
|
|
#if CE
|
295 |
|
|
extern int writeUniToAsc(int fid, void *buf, unsigned int len);
|
296 |
|
|
extern int readAscToUni(int fid, void **buf, unsigned int len);
|
297 |
|
|
#endif
|
298 |
|
|
|
299 |
|
|
#endif /* _h_WEBS_INTERNAL */
|
300 |
|
|
|
301 |
|
|
/******************************************************************************/
|