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