blob: 9dcb6afdc5ec640702999d69184ab3d84e17f6ca [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#ifndef _h_WEBS
2#define _h_WEBS 1
3
4#include "ej.h"
5#ifdef WEBS_SSL_SUPPORT
6 #include "websSSL.h"
7#else
8static inline int websSSLIsOpen()
9{
10 return 0;
11}
12#endif
13
14
15#ifdef WEBINSPECT_FIX
16#define WEBS_NAME T("Demo-Webs")
17#else
18#define WEBS_NAME T("GoAhead-Webs")
19#endif
20#define WEBS_VERSION T("2.1.8")
21
22#define WEBS_HEADER_BUFINC 512
23#define WEBS_ASP_BUFINC 512
24#define WEBS_MAX_PASS 32
25
26#define WEBS_BUFSIZE (8*1024)
27
28#define WEBS_MAX_HEADER (5 * 1024)
29#define WEBS_MAX_URL 4096
30#ifdef FEATURE_ZTE_WEB_TCARD
31//added for http share 20111001 start
32#define WEBS_SOCKET_BUFSIZ 4*1024
33#else
34#define WEBS_SOCKET_BUFSIZ 4*1024
35//added for http share 20111001 end
36#endif
37//added for PC Client begin, 20120829
38#define HTTP_BUFFER_SIZE (5*1024)
39//added for PC Client end, 20120829
40#define WEBS_HTTP_PORT T("httpPort")
41#define CGI_BIN T("cgi-bin")
42#define CGI_BIN_UPLOAD T("cgi-bin/upload/")
43#define CGI_BIN_HTTPSHARE T("cgi-bin/httpshare/")
44
45
46#define WEBS_LOCAL_PAGE 0x1
47#define WEBS_KEEP_ALIVE 0x2
48#define WEBS_DONT_USE_CACHE 0x4
49#define WEBS_COOKIE 0x8
50#define WEBS_IF_MODIFIED 0x10
51#define WEBS_POST_REQUEST 0x20
52#define WEBS_LOCAL_REQUEST 0x40
53#define WEBS_HOME_PAGE 0x80
54#define WEBS_ASP 0x100
55#define WEBS_HEAD_REQUEST 0x200
56#define WEBS_CLEN 0x400
57#define WEBS_FORM 0x800
58#define WEBS_REQUEST_DONE 0x1000
59#define WEBS_POST_DATA 0x2000
60#define WEBS_CGI_REQUEST 0x4000
61#define WEBS_SECURE 0x8000
62#define WEBS_AUTH_BASIC 0x10000
63#define WEBS_AUTH_DIGEST 0x20000
64#define WEBS_HEADER_DONE 0x40000
65#define WEBS_CGI_UPLOAD 0x80000
66#define WEBS_CGI_FIRMWARE_UPLOAD 0x100000
67#define WEBS_CGI_HTTPSHARE_UPLOAD 0x200000
68
69
70#define CGI_UPLOAD T("upload")
71#define CGI_FIRMWARE_UPLOAD T("upload.cgi")
72#define CGI_FIRMWARE_WRITE T("upload.write")
73#define CGI_HTTPSHARE_UPLOAD T("httpshare.up")
74
75//#define FIRMWARE_TMP_FILE T("/var/firmware_tmp_file")
76#define FIRMWARE_TMP_FILE T("/firmware_tmp_file")
77
78//added by liuyingnan for PC Client begin, 20120829
79#define WEBS_REST_CLIENT_REQUEST 0x200000
80#define WEBS_XML_CLIENT_REQUEST 0x400000
81//added by liuyingnan for PC Client end, 20120829
82
83
84#define WEBS_HANDLER_FIRST 0x1
85#define WEBS_HANDLER_LAST 0x2
86
87typedef struct websRec {
88 ringq_t header;
89 time_t since;
90 sym_fd_t cgiVars;
91 sym_fd_t cgiQuery;
92 time_t timestamp;
93 int timeout;
94 char_t ipaddr[40];
95 char_t ifaddr[32];
96 char_t type[64];
97 char_t *dir;
98 char_t *path;
99 char_t *url;
100 char_t *host;
101 char_t *lpath;
102 char_t *query;
103 char_t *decodedQuery;
104 char_t *authType;
105 char_t *password;
106 char_t *userName;
107 char_t *cookie;
108 char_t *referer;
109 char_t *userAgent;
110 char_t *protocol;
111 char_t *protoVersion;
112 int sid;
113 int listenSid;
114 int port;
115 int state;
116 int flags;
117 int code;
118 int clen;
119 int wid;
120 char_t *cgiStdin;
121 int docfd;
122 int numbytes;
123 int written;
124 int has_firmware_upload_clean;
125 int has_firmware_upload_shell;
126 void (*writeSocket)(struct websRec *wp);
127#ifdef DIGEST_ACCESS_SUPPORT
128 char_t *realm;
129 char_t *nonce;
130 char_t *digest;
131 char_t *uri;
132 char_t *opaque;
133 char_t *nc;
134 char_t *cnonce;
135 char_t *qop;
136#endif
137#ifdef WEBS_SSL_SUPPORT
138 websSSL_t *wsp;
139#endif
140} websRec;
141
142typedef websRec *webs_t;
143typedef websRec websType;
144
145extern void websSetDefaultDir(char_t *dir);
146extern void websSetDefaultPage(char_t *page);
147
148extern int websAccept(int sid, char *ipaddr, int port, int listenSid);
149extern int websAspDefine(char_t *name,
150 int (*fn)(int ejid, webs_t wp, int argc, char_t **argv));
151extern int websAspRequest(webs_t wp, char_t *lpath);
152
153extern void websFooter(webs_t wp);
154extern int websFormDefine(char_t *name, void (*fn)(webs_t wp,
155 char_t *path, char_t *query));
156
157extern int websDecode64(char_t *outbuf, char_t *string, int buflen);
158extern void websDecodeUrl(char_t *token, char_t *decoded, int len);
159
160extern void websEncode64(char_t *outbuf, char_t *string, int buflen);
161
162
163extern void websCloseListen();
164extern void websDone(webs_t wp, int code);
165
166extern void websError(webs_t wp, int code, char_t *msg, ...);
167extern char_t *websErrorMsg(int code);
168
169extern char_t *websGetDefaultDir();
170extern char_t *websGetDefaultPage();
171
172extern char_t *websGetRealm();
173extern int websGetRequestBytes(webs_t wp);
174extern char_t *websGetRequestDir(webs_t wp);
175extern int websGetRequestFlags(webs_t wp);
176
177extern char_t *websGetHostUrl();
178extern char_t *websGetIpaddrUrl();
179extern char_t *websGetPassword();
180extern int websGetPort();
181
182extern char_t *websGetPublishDir(char_t *path, char_t **urlPrefix);
183extern char_t *websGetRequestType(webs_t wp);
184extern int websGetRequestWritten(webs_t wp);
185
186extern char_t *websGetRequestIpaddr(webs_t wp);
187extern int websGetSid(webs_t wp);
188extern char_t *websGetRequestLpath(webs_t wp);
189extern char_t *websGetRequestPath(webs_t wp);
190extern char_t *websGetRequestPassword(webs_t wp);
191
192extern char_t *websGetVar(webs_t wp, char_t *var, char_t *def);
193extern int websCompareVar(webs_t wp, char_t *var, char_t *value);
194
195
196extern int websPublish(char_t *urlPrefix, char_t *path);
197extern void websRedirect(webs_t wp, char_t *url);
198extern void websSecurityDelete();
199extern int websSecurityHandler(webs_t wp, char_t *urlPrefix,
200 char_t *webDir, int arg, char_t *url, char_t *path,
201 char_t *query);
202
203extern void websHeader(webs_t wp);
204extern int websOpenListen(int port, int retries);
205extern int websPageOpen(webs_t wp, char_t *lpath, char_t *path,
206 int mode, int perm);
207extern void websPageClose(webs_t wp);
208
209extern void websSetEnv(webs_t wp);
210extern void websSetHost(char_t *host);
211extern void websSetIpaddr(char_t *ipaddr);
212extern void websSetPassword(char_t *password);
213extern void websSetRealm(char_t *realmName);
214
215extern void websSetVar(webs_t wp, char_t *var, char_t *value);
216extern int websTestVar(webs_t wp, char_t *var);
217
218extern int websUrlHandlerDefine(char_t *urlPrefix, char_t *webDir,
219 int arg, int (*fn)(webs_t wp, char_t *urlPrefix,
220 char_t *webDir, int arg, char_t *url, char_t *path,
221 char_t *query), int flags);
222extern int websUrlHandlerDelete(int (*fn)(webs_t wp, char_t *urlPrefix,
223 char_t *webDir, int arg, char_t *url, char_t *path,
224 char_t *query));
225extern int websUrlHandlerRequest(webs_t wp);
226extern int websUrlParse(char_t *url, char_t **buf, char_t **host,
227 char_t **path, char_t **port, char_t **query,
228 char_t **proto, char_t **tag, char_t **ext);
229extern char_t *websUrlType(char_t *webs, char_t *buf, int charCnt);
230
231extern int websValid(webs_t wp);
232extern int websValidateUrl(webs_t wp, char_t *path);
233
234extern void websSetRequestBytes(webs_t wp, int bytes);
235extern void websSetRequestFlags(webs_t wp, int flags);
236extern void websSetRequestLpath(webs_t wp, char_t *lpath);
237extern void websSetRequestPath(webs_t wp, char_t *dir, char_t *path);
238extern char_t *websGetRequestUserName(webs_t wp);
239extern void websSetRequestWritten(webs_t wp, int written);
240
241extern int websWrite(webs_t wp, char_t* fmt, ...);
242extern int websWriteBlock(webs_t wp, char_t *buf, int nChars);
243extern int websWriteDataNonBlock(webs_t wp, char *buf, int nChars);
244
245
246extern void websTimeout(void *arg, int id);
247extern void websSetTimeMark(webs_t wp);
248extern void websTimeoutCancel(webs_t wp);
249
250
251extern int websAlloc(int sid);
252extern void websFree(webs_t wp);
253
254extern void websReadEvent(webs_t wp);
255
256
257extern char websRecvHttpBuffer[HTTP_BUFFER_SIZE];
258extern int is_print_str(char *str, int len);
259
260#ifdef EMF
261extern void websFormExplain(webs_t wp, char_t *path, char_t *query);
262#endif
263
264extern int web_make_salt_base64(char *id, int len);
265
266#endif /* _h_WEBS */
267