lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #ifndef _h_WEBS |
| 2 | #define _h_WEBS 1 |
| 3 | |
| 4 | #include "ej.h" |
| 5 | #ifdef WEBS_SSL_SUPPORT |
| 6 | #include "websSSL.h" |
| 7 | #else |
| 8 | static 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 | |
| 87 | typedef 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 | |
| 142 | typedef websRec *webs_t; |
| 143 | typedef websRec websType; |
| 144 | |
| 145 | extern void websSetDefaultDir(char_t *dir); |
| 146 | extern void websSetDefaultPage(char_t *page); |
| 147 | |
| 148 | extern int websAccept(int sid, char *ipaddr, int port, int listenSid); |
| 149 | extern int websAspDefine(char_t *name, |
| 150 | int (*fn)(int ejid, webs_t wp, int argc, char_t **argv)); |
| 151 | extern int websAspRequest(webs_t wp, char_t *lpath); |
| 152 | |
| 153 | extern void websFooter(webs_t wp); |
| 154 | extern int websFormDefine(char_t *name, void (*fn)(webs_t wp, |
| 155 | char_t *path, char_t *query)); |
| 156 | |
| 157 | extern int websDecode64(char_t *outbuf, char_t *string, int buflen); |
| 158 | extern void websDecodeUrl(char_t *token, char_t *decoded, int len); |
| 159 | |
| 160 | extern void websEncode64(char_t *outbuf, char_t *string, int buflen); |
| 161 | |
| 162 | |
| 163 | extern void websCloseListen(); |
| 164 | extern void websDone(webs_t wp, int code); |
| 165 | |
| 166 | extern void websError(webs_t wp, int code, char_t *msg, ...); |
| 167 | extern char_t *websErrorMsg(int code); |
| 168 | |
| 169 | extern char_t *websGetDefaultDir(); |
| 170 | extern char_t *websGetDefaultPage(); |
| 171 | |
| 172 | extern char_t *websGetRealm(); |
| 173 | extern int websGetRequestBytes(webs_t wp); |
| 174 | extern char_t *websGetRequestDir(webs_t wp); |
| 175 | extern int websGetRequestFlags(webs_t wp); |
| 176 | |
| 177 | extern char_t *websGetHostUrl(); |
| 178 | extern char_t *websGetIpaddrUrl(); |
| 179 | extern char_t *websGetPassword(); |
| 180 | extern int websGetPort(); |
| 181 | |
| 182 | extern char_t *websGetPublishDir(char_t *path, char_t **urlPrefix); |
| 183 | extern char_t *websGetRequestType(webs_t wp); |
| 184 | extern int websGetRequestWritten(webs_t wp); |
| 185 | |
| 186 | extern char_t *websGetRequestIpaddr(webs_t wp); |
| 187 | extern int websGetSid(webs_t wp); |
| 188 | extern char_t *websGetRequestLpath(webs_t wp); |
| 189 | extern char_t *websGetRequestPath(webs_t wp); |
| 190 | extern char_t *websGetRequestPassword(webs_t wp); |
| 191 | |
| 192 | extern char_t *websGetVar(webs_t wp, char_t *var, char_t *def); |
| 193 | extern int websCompareVar(webs_t wp, char_t *var, char_t *value); |
| 194 | |
| 195 | |
| 196 | extern int websPublish(char_t *urlPrefix, char_t *path); |
| 197 | extern void websRedirect(webs_t wp, char_t *url); |
| 198 | extern void websSecurityDelete(); |
| 199 | extern 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 | |
| 203 | extern void websHeader(webs_t wp); |
| 204 | extern int websOpenListen(int port, int retries); |
| 205 | extern int websPageOpen(webs_t wp, char_t *lpath, char_t *path, |
| 206 | int mode, int perm); |
| 207 | extern void websPageClose(webs_t wp); |
| 208 | |
| 209 | extern void websSetEnv(webs_t wp); |
| 210 | extern void websSetHost(char_t *host); |
| 211 | extern void websSetIpaddr(char_t *ipaddr); |
| 212 | extern void websSetPassword(char_t *password); |
| 213 | extern void websSetRealm(char_t *realmName); |
| 214 | |
| 215 | extern void websSetVar(webs_t wp, char_t *var, char_t *value); |
| 216 | extern int websTestVar(webs_t wp, char_t *var); |
| 217 | |
| 218 | extern 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); |
| 222 | extern 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)); |
| 225 | extern int websUrlHandlerRequest(webs_t wp); |
| 226 | extern 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); |
| 229 | extern char_t *websUrlType(char_t *webs, char_t *buf, int charCnt); |
| 230 | |
| 231 | extern int websValid(webs_t wp); |
| 232 | extern int websValidateUrl(webs_t wp, char_t *path); |
| 233 | |
| 234 | extern void websSetRequestBytes(webs_t wp, int bytes); |
| 235 | extern void websSetRequestFlags(webs_t wp, int flags); |
| 236 | extern void websSetRequestLpath(webs_t wp, char_t *lpath); |
| 237 | extern void websSetRequestPath(webs_t wp, char_t *dir, char_t *path); |
| 238 | extern char_t *websGetRequestUserName(webs_t wp); |
| 239 | extern void websSetRequestWritten(webs_t wp, int written); |
| 240 | |
| 241 | extern int websWrite(webs_t wp, char_t* fmt, ...); |
| 242 | extern int websWriteBlock(webs_t wp, char_t *buf, int nChars); |
| 243 | extern int websWriteDataNonBlock(webs_t wp, char *buf, int nChars); |
| 244 | |
| 245 | |
| 246 | extern void websTimeout(void *arg, int id); |
| 247 | extern void websSetTimeMark(webs_t wp); |
| 248 | extern void websTimeoutCancel(webs_t wp); |
| 249 | |
| 250 | |
| 251 | extern int websAlloc(int sid); |
| 252 | extern void websFree(webs_t wp); |
| 253 | |
| 254 | extern void websReadEvent(webs_t wp); |
| 255 | |
| 256 | |
| 257 | extern char websRecvHttpBuffer[HTTP_BUFFER_SIZE]; |
| 258 | extern int is_print_str(char *str, int len); |
| 259 | |
| 260 | #ifdef EMF |
| 261 | extern void websFormExplain(webs_t wp, char_t *path, char_t *query); |
| 262 | #endif |
| 263 | |
| 264 | extern int web_make_salt_base64(char *id, int len); |
| 265 | |
| 266 | #endif /* _h_WEBS */ |
| 267 | |