private fork
Fork of GSwifiInterface by
GSwifi/GSwifi_httpd.cpp@18:20970aec3ad3, 2014-05-12 (annotated)
- Committer:
- gsfan
- Date:
- Mon May 12 01:24:09 2014 +0000
- Revision:
- 18:20970aec3ad3
- Parent:
- 16:105b56570533
- Child:
- 19:d035412a7803
bug fix http server
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gsfan | 12:057089026a20 | 1 | /* Copyright (C) 2013 gsfan, MIT License |
gsfan | 12:057089026a20 | 2 | * |
gsfan | 12:057089026a20 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
gsfan | 12:057089026a20 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
gsfan | 12:057089026a20 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
gsfan | 12:057089026a20 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
gsfan | 12:057089026a20 | 7 | * furnished to do so, subject to the following conditions: |
gsfan | 12:057089026a20 | 8 | * |
gsfan | 12:057089026a20 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
gsfan | 12:057089026a20 | 10 | * substantial portions of the Software. |
gsfan | 12:057089026a20 | 11 | * |
gsfan | 12:057089026a20 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
gsfan | 12:057089026a20 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
gsfan | 12:057089026a20 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
gsfan | 12:057089026a20 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
gsfan | 12:057089026a20 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
gsfan | 12:057089026a20 | 17 | */ |
gsfan | 12:057089026a20 | 18 | |
gsfan | 12:057089026a20 | 19 | #include "GSwifi.h" |
gsfan | 12:057089026a20 | 20 | |
gsfan | 12:057089026a20 | 21 | #ifdef CFG_ENABLE_HTTPD |
gsfan | 12:057089026a20 | 22 | |
gsfan | 12:057089026a20 | 23 | int GSwifi::httpd (int port) { |
gsfan | 12:057089026a20 | 24 | int i; |
gsfan | 12:057089026a20 | 25 | |
gsfan | 12:057089026a20 | 26 | if (!isAssociated() || _state.status != STAT_READY) return -1; |
gsfan | 12:057089026a20 | 27 | |
gsfan | 12:057089026a20 | 28 | memset(&_httpd, 0, sizeof(_httpd)); |
gsfan | 12:057089026a20 | 29 | for (i = 0; i < 16; i ++) { |
gsfan | 12:057089026a20 | 30 | _httpd[i].mode = HTTPDMODE_REQUEST; |
gsfan | 12:057089026a20 | 31 | } |
gsfan | 12:057089026a20 | 32 | _handler_count = 0; |
gsfan | 12:057089026a20 | 33 | |
gsfan | 12:057089026a20 | 34 | _httpd_cid = listen(PROTO_TCP, port); |
gsfan | 12:057089026a20 | 35 | if (_httpd_cid < 0) return -1; |
gsfan | 12:057089026a20 | 36 | |
gsfan | 12:057089026a20 | 37 | _con[_httpd_cid].protocol = PROTO_HTTPD; |
gsfan | 12:057089026a20 | 38 | return _httpd_cid; |
gsfan | 12:057089026a20 | 39 | } |
gsfan | 12:057089026a20 | 40 | |
gsfan | 12:057089026a20 | 41 | void GSwifi::httpdRecvData (int cid, char c) { |
gsfan | 12:057089026a20 | 42 | |
gsfan | 12:057089026a20 | 43 | switch (_httpd[cid].mode) { |
gsfan | 12:057089026a20 | 44 | case HTTPDMODE_REQUEST: |
gsfan | 16:105b56570533 | 45 | #ifndef CFG_ENABLE_RTOS |
gsfan | 16:105b56570533 | 46 | if (_con[cid].buf == NULL) { |
gsfan | 12:057089026a20 | 47 | _con[cid].buf = new CircBuffer<char>(CFG_DATA_SIZE); |
gsfan | 16:105b56570533 | 48 | } |
gsfan | 16:105b56570533 | 49 | #endif |
gsfan | 12:057089026a20 | 50 | _httpd[cid].buf = _con[cid].buf; |
gsfan | 16:105b56570533 | 51 | if (_httpd[cid].buf != NULL) { |
gsfan | 16:105b56570533 | 52 | _httpd[cid].buf->flush(); |
gsfan | 16:105b56570533 | 53 | } |
gsfan | 15:086d1a33a197 | 54 | _httpd[cid].keepalive = 0; |
gsfan | 12:057089026a20 | 55 | if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) { |
gsfan | 16:105b56570533 | 56 | if (_httpd[cid].buf != NULL) { |
gsfan | 16:105b56570533 | 57 | _httpd[cid].buf->queue(c); |
gsfan | 16:105b56570533 | 58 | } |
gsfan | 12:057089026a20 | 59 | _httpd[cid].mode = HTTPDMODE_REQUEST_STR; |
gsfan | 12:057089026a20 | 60 | } |
gsfan | 12:057089026a20 | 61 | break; |
gsfan | 12:057089026a20 | 62 | case HTTPDMODE_REQUEST_STR: |
gsfan | 12:057089026a20 | 63 | switch (c) { |
gsfan | 12:057089026a20 | 64 | case 0: |
gsfan | 12:057089026a20 | 65 | case 0x0d: // CR |
gsfan | 12:057089026a20 | 66 | break; |
gsfan | 12:057089026a20 | 67 | case 0x0a: // LF |
gsfan | 12:057089026a20 | 68 | if (httpdParseRequest(cid)) { |
gsfan | 12:057089026a20 | 69 | _httpd[cid].mode = HTTPDMODE_REQUEST_STR; |
gsfan | 12:057089026a20 | 70 | } else { |
gsfan | 12:057089026a20 | 71 | _httpd[cid].mode = HTTPDMODE_HEADER; |
gsfan | 12:057089026a20 | 72 | } |
gsfan | 12:057089026a20 | 73 | _httpd[cid].enter = 0; |
gsfan | 12:057089026a20 | 74 | break; |
gsfan | 12:057089026a20 | 75 | default: |
gsfan | 16:105b56570533 | 76 | if (_httpd[cid].buf != NULL) { |
gsfan | 16:105b56570533 | 77 | _httpd[cid].buf->queue(c); |
gsfan | 16:105b56570533 | 78 | } |
gsfan | 12:057089026a20 | 79 | break; |
gsfan | 12:057089026a20 | 80 | } |
gsfan | 12:057089026a20 | 81 | break; |
gsfan | 12:057089026a20 | 82 | case HTTPDMODE_HEADER: |
gsfan | 12:057089026a20 | 83 | switch (c) { |
gsfan | 12:057089026a20 | 84 | case 0: |
gsfan | 12:057089026a20 | 85 | case 0x0d: // CR |
gsfan | 12:057089026a20 | 86 | break; |
gsfan | 12:057089026a20 | 87 | case 0x0a: // LF |
gsfan | 18:20970aec3ad3 | 88 | // if (_httpd[cid].buf != NULL && _httpd[cid].buf->available() == 0) { |
gsfan | 12:057089026a20 | 89 | // if ((_httpd[cid].enter == 0x0d && c == 0x0a) || (_httpd[cid].enter == 0x0a && c == 0x0a)) { |
gsfan | 12:057089026a20 | 90 | if (_httpd[cid].enter == 0x0a && c == 0x0a) { |
gsfan | 18:20970aec3ad3 | 91 | if (_httpd[cid].buf != NULL) { |
gsfan | 18:20970aec3ad3 | 92 | _httpd[cid].buf->flush(); |
gsfan | 18:20970aec3ad3 | 93 | } |
gsfan | 12:057089026a20 | 94 | #ifdef CFG_ENABLE_WEBSOCKET |
gsfan | 12:057089026a20 | 95 | if (_httpd[cid].websocket) { |
gsfan | 15:086d1a33a197 | 96 | INFO("MODE_WEBSOCKET_BEGIN"); |
gsfan | 15:086d1a33a197 | 97 | _httpd[cid].mode = HTTPDMODE_WEBSOCKET_BEGIN; |
gsfan | 12:057089026a20 | 98 | } else |
gsfan | 12:057089026a20 | 99 | #endif |
gsfan | 12:057089026a20 | 100 | if (_httpd[cid].length) { |
gsfan | 12:057089026a20 | 101 | INFO("MODE_BODY"); |
gsfan | 12:057089026a20 | 102 | _httpd[cid].mode = HTTPDMODE_BODY; |
gsfan | 12:057089026a20 | 103 | } else { |
gsfan | 12:057089026a20 | 104 | INFO("MODE_ENTER"); |
gsfan | 12:057089026a20 | 105 | _httpd[cid].mode = HTTPDMODE_ENTER; |
gsfan | 12:057089026a20 | 106 | _con[cid].received = true; |
gsfan | 12:057089026a20 | 107 | } |
gsfan | 12:057089026a20 | 108 | } |
gsfan | 18:20970aec3ad3 | 109 | // break; |
gsfan | 18:20970aec3ad3 | 110 | // } |
gsfan | 12:057089026a20 | 111 | |
gsfan | 18:20970aec3ad3 | 112 | _httpd[cid].enter = c; |
gsfan | 12:057089026a20 | 113 | httpdParseHeader(cid); |
gsfan | 12:057089026a20 | 114 | break; |
gsfan | 12:057089026a20 | 115 | default: |
gsfan | 16:105b56570533 | 116 | if (_httpd[cid].buf != NULL) { |
gsfan | 16:105b56570533 | 117 | _httpd[cid].buf->queue(c); |
gsfan | 16:105b56570533 | 118 | } |
gsfan | 12:057089026a20 | 119 | _httpd[cid].enter = 0; |
gsfan | 12:057089026a20 | 120 | break; |
gsfan | 12:057089026a20 | 121 | } |
gsfan | 12:057089026a20 | 122 | break; |
gsfan | 12:057089026a20 | 123 | case HTTPDMODE_BODY: |
gsfan | 16:105b56570533 | 124 | if (_httpd[cid].buf != NULL) { |
gsfan | 16:105b56570533 | 125 | _httpd[cid].buf->queue(c); |
gsfan | 16:105b56570533 | 126 | if (_httpd[cid].buf->available() >= _httpd[cid].length) { |
gsfan | 16:105b56570533 | 127 | _httpd[cid].mode = HTTPDMODE_ENTER; |
gsfan | 16:105b56570533 | 128 | _con[cid].received = true; |
gsfan | 16:105b56570533 | 129 | } |
gsfan | 12:057089026a20 | 130 | } |
gsfan | 12:057089026a20 | 131 | break; |
gsfan | 12:057089026a20 | 132 | #ifdef CFG_ENABLE_WEBSOCKET |
gsfan | 12:057089026a20 | 133 | case HTTPDMODE_WEBSOCKET: |
gsfan | 12:057089026a20 | 134 | case HTTPDMODE_WEBSOCKET_MASK: |
gsfan | 12:057089026a20 | 135 | case HTTPDMODE_WEBSOCKET_BODY: |
gsfan | 12:057089026a20 | 136 | wsRecvData(cid, c); |
gsfan | 12:057089026a20 | 137 | break; |
gsfan | 12:057089026a20 | 138 | #endif |
gsfan | 12:057089026a20 | 139 | } |
gsfan | 12:057089026a20 | 140 | } |
gsfan | 12:057089026a20 | 141 | |
gsfan | 12:057089026a20 | 142 | void GSwifi::httpdPoll () { |
gsfan | 12:057089026a20 | 143 | for (int cid = 0; cid < 16; cid ++) { |
gsfan | 12:057089026a20 | 144 | if (isConnected(cid) && _con[cid].protocol == PROTO_HTTPD) { |
gsfan | 12:057089026a20 | 145 | |
gsfan | 12:057089026a20 | 146 | if (_httpd[cid].mode == HTTPDMODE_ENTER) { |
gsfan | 12:057089026a20 | 147 | int i = httpdGetHandler(_httpd[cid].uri); |
gsfan | 12:057089026a20 | 148 | if (i >= 0) { |
gsfan | 12:057089026a20 | 149 | if (_httpd_handler[i].dir) { |
gsfan | 12:057089026a20 | 150 | // file |
gsfan | 12:057089026a20 | 151 | httpdFile(cid, _httpd_handler[i].dir); |
gsfan | 12:057089026a20 | 152 | } else |
gsfan | 15:086d1a33a197 | 153 | if (_httpd_handler[i].func && !_httpd_handler[i].ws) { |
gsfan | 12:057089026a20 | 154 | // cgi |
gsfan | 12:057089026a20 | 155 | _httpd_handler[i].func(cid); |
gsfan | 12:057089026a20 | 156 | // _httpd[cid].keepalive = 0; |
gsfan | 12:057089026a20 | 157 | } else { |
gsfan | 12:057089026a20 | 158 | httpdError(cid, 403); |
gsfan | 12:057089026a20 | 159 | } |
gsfan | 12:057089026a20 | 160 | } else { |
gsfan | 12:057089026a20 | 161 | httpdError(cid, 404); |
gsfan | 12:057089026a20 | 162 | } |
gsfan | 12:057089026a20 | 163 | |
gsfan | 12:057089026a20 | 164 | if (_httpd[cid].keepalive) { |
gsfan | 12:057089026a20 | 165 | DBG("keepalive %d", _httpd[cid].keepalive); |
gsfan | 12:057089026a20 | 166 | _httpd[cid].keepalive --; |
gsfan | 12:057089026a20 | 167 | } else { |
gsfan | 12:057089026a20 | 168 | close(cid); |
gsfan | 12:057089026a20 | 169 | } |
gsfan | 12:057089026a20 | 170 | _httpd[cid].mode = HTTPDMODE_REQUEST; |
gsfan | 12:057089026a20 | 171 | #ifdef CFG_ENABLE_WEBSOCKET |
gsfan | 12:057089026a20 | 172 | } else |
gsfan | 15:086d1a33a197 | 173 | if (_httpd[cid].mode == HTTPDMODE_WEBSOCKET_BEGIN) { |
gsfan | 15:086d1a33a197 | 174 | wsAccept(cid); |
gsfan | 15:086d1a33a197 | 175 | _httpd[cid].mode = HTTPDMODE_WEBSOCKET; |
gsfan | 15:086d1a33a197 | 176 | } else |
gsfan | 12:057089026a20 | 177 | if (_httpd[cid].mode == HTTPDMODE_WEBSOCKET_ENTER) { |
gsfan | 12:057089026a20 | 178 | wsParseRequest(cid); |
gsfan | 12:057089026a20 | 179 | _httpd[cid].mode = HTTPDMODE_WEBSOCKET; |
gsfan | 12:057089026a20 | 180 | #endif |
gsfan | 12:057089026a20 | 181 | } |
gsfan | 12:057089026a20 | 182 | |
gsfan | 15:086d1a33a197 | 183 | } // PROTO_HTTPD |
gsfan | 15:086d1a33a197 | 184 | } // for |
gsfan | 12:057089026a20 | 185 | } |
gsfan | 12:057089026a20 | 186 | |
gsfan | 12:057089026a20 | 187 | int GSwifi::httpdParseRequest (int cid) { |
gsfan | 12:057089026a20 | 188 | int i, j, len; |
gsfan | 12:057089026a20 | 189 | char buf[CFG_CMD_SIZE]; |
gsfan | 12:057089026a20 | 190 | |
gsfan | 16:105b56570533 | 191 | if (_httpd[cid].buf == NULL) return 0; |
gsfan | 12:057089026a20 | 192 | for (len = 0; len < sizeof(buf); len++) { |
gsfan | 12:057089026a20 | 193 | if (_httpd[cid].buf->dequeue(&buf[len]) == false) break; |
gsfan | 12:057089026a20 | 194 | } |
gsfan | 12:057089026a20 | 195 | buf[len] = 0; |
gsfan | 12:057089026a20 | 196 | |
gsfan | 12:057089026a20 | 197 | if (strnicmp(buf, "GET ", 4) == 0) { |
gsfan | 12:057089026a20 | 198 | _httpd[cid].req = REQ_HTTPGET; |
gsfan | 12:057089026a20 | 199 | j = 4; |
gsfan | 12:057089026a20 | 200 | } else |
gsfan | 12:057089026a20 | 201 | if (strnicmp(buf, "POST ", 5) == 0) { |
gsfan | 12:057089026a20 | 202 | _httpd[cid].req = REQ_HTTPPOST; |
gsfan | 12:057089026a20 | 203 | j = 5; |
gsfan | 12:057089026a20 | 204 | } else { |
gsfan | 12:057089026a20 | 205 | return -1; |
gsfan | 12:057089026a20 | 206 | } |
gsfan | 12:057089026a20 | 207 | |
gsfan | 12:057089026a20 | 208 | if (_httpd[cid].uri == NULL) |
gsfan | 12:057089026a20 | 209 | _httpd[cid].uri = (char*)malloc(CFG_CMD_SIZE); |
gsfan | 12:057089026a20 | 210 | |
gsfan | 12:057089026a20 | 211 | for (i = 0; i < len - j; i ++) { |
gsfan | 12:057089026a20 | 212 | _httpd[cid].uri[i] = buf[i + j]; |
gsfan | 12:057089026a20 | 213 | if (buf[i + j] == ' ' || i >= CFG_CMD_SIZE - 1) { |
gsfan | 12:057089026a20 | 214 | _httpd[cid].uri[i] = 0; |
gsfan | 12:057089026a20 | 215 | INFO("URI %d '%s'", _httpd[cid].req, _httpd[cid].uri); |
gsfan | 12:057089026a20 | 216 | _httpd[cid].mode = HTTPDMODE_HEADER; |
gsfan | 12:057089026a20 | 217 | _httpd[cid].buf->flush(); |
gsfan | 12:057089026a20 | 218 | _httpd[cid].length = 0; |
gsfan | 12:057089026a20 | 219 | _httpd[cid].n = 0; |
gsfan | 12:057089026a20 | 220 | _httpd[cid].filename = NULL; |
gsfan | 12:057089026a20 | 221 | _httpd[cid].querystring = NULL; |
gsfan | 12:057089026a20 | 222 | #ifdef CFG_ENABLE_WEBSOCKET |
gsfan | 12:057089026a20 | 223 | _httpd[cid].websocket = 0; |
gsfan | 12:057089026a20 | 224 | #endif |
gsfan | 12:057089026a20 | 225 | break; |
gsfan | 12:057089026a20 | 226 | } |
gsfan | 12:057089026a20 | 227 | } |
gsfan | 12:057089026a20 | 228 | |
gsfan | 12:057089026a20 | 229 | i = httpdGetHandler(_httpd[cid].uri); |
gsfan | 12:057089026a20 | 230 | if (i >= 0) { |
gsfan | 12:057089026a20 | 231 | _httpd[cid].filename = &_httpd[cid].uri[strlen(_httpd_handler[i].uri)]; |
gsfan | 12:057089026a20 | 232 | for (i = 0; i < strlen(_httpd[cid].filename); i ++) { |
gsfan | 12:057089026a20 | 233 | if (_httpd[cid].filename[i] == '?') { |
gsfan | 12:057089026a20 | 234 | _httpd[cid].filename[i] = 0; |
gsfan | 12:057089026a20 | 235 | _httpd[cid].querystring = _httpd[cid].filename + i + 1; |
gsfan | 12:057089026a20 | 236 | break; |
gsfan | 12:057089026a20 | 237 | } |
gsfan | 12:057089026a20 | 238 | } |
gsfan | 12:057089026a20 | 239 | INFO("FILE '%s' QUERY '%s'", _httpd[cid].filename, _httpd[cid].querystring); |
gsfan | 12:057089026a20 | 240 | } |
gsfan | 12:057089026a20 | 241 | return 0; |
gsfan | 12:057089026a20 | 242 | } |
gsfan | 12:057089026a20 | 243 | |
gsfan | 12:057089026a20 | 244 | #define HEADER_TABLE_NUM 5 |
gsfan | 12:057089026a20 | 245 | int GSwifi::httpdParseHeader (int cid) { |
gsfan | 12:057089026a20 | 246 | int i; |
gsfan | 12:057089026a20 | 247 | char buf[CFG_CMD_SIZE]; |
gsfan | 12:057089026a20 | 248 | static const struct HEADER_TABLE { |
gsfan | 12:057089026a20 | 249 | const char header[24]; |
gsfan | 12:057089026a20 | 250 | void (GSwifi::*func)(int id, const char*); |
gsfan | 12:057089026a20 | 251 | } header_table[HEADER_TABLE_NUM] = { |
gsfan | 12:057089026a20 | 252 | {"Content-Length:", &GSwifi::reqContentLength}, |
gsfan | 12:057089026a20 | 253 | {"Connection:", &GSwifi::reqConnection}, |
gsfan | 12:057089026a20 | 254 | {"Upgrade: websocket", &GSwifi::reqUpgrade}, |
gsfan | 12:057089026a20 | 255 | {"Sec-WebSocket-Version:", &GSwifi::reqWebSocketVersion}, |
gsfan | 12:057089026a20 | 256 | {"Sec-WebSocket-Key:", &GSwifi::reqWebSocketKey}, |
gsfan | 12:057089026a20 | 257 | }; |
gsfan | 16:105b56570533 | 258 | |
gsfan | 16:105b56570533 | 259 | if (_httpd[cid].buf == NULL) return 0; |
gsfan | 12:057089026a20 | 260 | for (i = 0; i < sizeof(buf); i++) { |
gsfan | 12:057089026a20 | 261 | if (_httpd[cid].buf->dequeue(&buf[i]) == false) break; |
gsfan | 12:057089026a20 | 262 | } |
gsfan | 12:057089026a20 | 263 | buf[i] = 0; |
gsfan | 12:057089026a20 | 264 | |
gsfan | 12:057089026a20 | 265 | for (i = 0; i < HEADER_TABLE_NUM; i ++) { |
gsfan | 12:057089026a20 | 266 | if (strnicmp(buf, header_table[i].header, strlen(header_table[i].header)) == 0) { |
gsfan | 12:057089026a20 | 267 | DBG("parse header %d '%s'\r\n", i, buf); |
gsfan | 12:057089026a20 | 268 | if (header_table[i].func != NULL) { |
gsfan | 12:057089026a20 | 269 | (this->*(header_table[i].func))(cid, buf); |
gsfan | 12:057089026a20 | 270 | } |
gsfan | 12:057089026a20 | 271 | return 0; |
gsfan | 12:057089026a20 | 272 | } |
gsfan | 12:057089026a20 | 273 | } |
gsfan | 12:057089026a20 | 274 | |
gsfan | 12:057089026a20 | 275 | return -1; |
gsfan | 12:057089026a20 | 276 | } |
gsfan | 12:057089026a20 | 277 | |
gsfan | 12:057089026a20 | 278 | void GSwifi::reqContentLength (int cid, const char *buf) { |
gsfan | 12:057089026a20 | 279 | _httpd[cid].length = atoi(&buf[16]); |
gsfan | 12:057089026a20 | 280 | } |
gsfan | 12:057089026a20 | 281 | |
gsfan | 12:057089026a20 | 282 | void GSwifi::reqConnection (int cid, const char *buf) { |
gsfan | 15:086d1a33a197 | 283 | if (strnicmp(&buf[12], "Keep-Alive", 10) == 0) { |
gsfan | 15:086d1a33a197 | 284 | if (_httpd[cid].keepalive == 0) |
gsfan | 15:086d1a33a197 | 285 | _httpd[cid].keepalive = CFG_HTTPD_KEEPALIVE; |
gsfan | 12:057089026a20 | 286 | } else { |
gsfan | 12:057089026a20 | 287 | _httpd[cid].keepalive = 0; |
gsfan | 12:057089026a20 | 288 | } |
gsfan | 12:057089026a20 | 289 | } |
gsfan | 12:057089026a20 | 290 | |
gsfan | 12:057089026a20 | 291 | #ifdef CFG_ENABLE_WEBSOCKET |
gsfan | 12:057089026a20 | 292 | void GSwifi::reqUpgrade (int cid, const char *buf) { |
gsfan | 12:057089026a20 | 293 | if (! _httpd[cid].websocket) _httpd[cid].websocket = 1; |
gsfan | 12:057089026a20 | 294 | } |
gsfan | 12:057089026a20 | 295 | |
gsfan | 12:057089026a20 | 296 | void GSwifi::reqWebSocketVersion (int cid, const char *buf) { |
gsfan | 12:057089026a20 | 297 | _httpd[cid].websocket = atoi(&buf[23]); |
gsfan | 12:057089026a20 | 298 | } |
gsfan | 12:057089026a20 | 299 | |
gsfan | 12:057089026a20 | 300 | void GSwifi::reqWebSocketKey (int cid, const char *buf) { |
gsfan | 12:057089026a20 | 301 | if (_httpd[cid].websocket_key == NULL) { |
gsfan | 12:057089026a20 | 302 | _httpd[cid].websocket_key = (char*)malloc(30); |
gsfan | 12:057089026a20 | 303 | } |
gsfan | 12:057089026a20 | 304 | strncpy(_httpd[cid].websocket_key, &buf[19], 30); |
gsfan | 12:057089026a20 | 305 | } |
gsfan | 12:057089026a20 | 306 | #else |
gsfan | 12:057089026a20 | 307 | void GSwifi::reqUpgrade (int cid, const char *buf) { |
gsfan | 12:057089026a20 | 308 | } |
gsfan | 12:057089026a20 | 309 | void GSwifi::reqWebSocketVersion (int cid, const char *buf) { |
gsfan | 12:057089026a20 | 310 | } |
gsfan | 12:057089026a20 | 311 | void GSwifi::reqWebSocketKey (int cid, const char *buf) { |
gsfan | 12:057089026a20 | 312 | } |
gsfan | 12:057089026a20 | 313 | #endif |
gsfan | 12:057089026a20 | 314 | |
gsfan | 12:057089026a20 | 315 | #endif |