GSwifiInterface library (interface for GainSpan Wi-Fi GS1011 modules) Please see https://mbed.org/users/gsfan/notebook/GSwifiInterface/
Dependents: GSwifiInterface_HelloWorld GSwifiInterface_HelloServo GSwifiInterface_UDPEchoServer GSwifiInterface_UDPEchoClient ... more
Fork of WiflyInterface by
GainSpan Wi-Fi library
The GS1011/GS2100 is an ultra low power 802.11b wireless module from GainSpan.
mbed RTOS supported.
- about this library: http://mbed.org/users/gsfan/notebook/GSwifiInterface/
- about Wi-Fi module: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
ゲインスパン Wi-Fi モジュール ライブラリ
ゲインスパン社の低電力 Wi-Fiモジュール(無線LAN) GS1011/GS2100 シリーズ用のライブラリです。
mbed RTOS に対応しています。(mbed2.0)
- このライブラリについて: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
- Wi-FIモジュールについて: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
- UARTコマンド、SPIデータインターフェースに対応しました。(2019/09)
GSwifi/GSwifi_httpd_ws.cpp@12:057089026a20, 2013-11-22 (annotated)
- Committer:
- gsfan
- Date:
- Fri Nov 22 14:03:07 2013 +0000
- Revision:
- 12:057089026a20
- Child:
- 15:086d1a33a197
add more function (smtp, http, httpd, websocket); fix some function;
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_WEBSOCKET |
gsfan | 12:057089026a20 | 22 | |
gsfan | 12:057089026a20 | 23 | #include "sha1.h" |
gsfan | 12:057089026a20 | 24 | |
gsfan | 12:057089026a20 | 25 | int GSwifi::wsOpen (const char *host, int port, const char *uri, const char *user, const char *pwd) { |
gsfan | 12:057089026a20 | 26 | int cid; |
gsfan | 12:057089026a20 | 27 | char cmd[CFG_CMD_SIZE], tmp[CFG_CMD_SIZE]; |
gsfan | 12:057089026a20 | 28 | char ip[17]; |
gsfan | 12:057089026a20 | 29 | |
gsfan | 12:057089026a20 | 30 | if (!isAssociated() || _state.status != STAT_READY) return -1; |
gsfan | 12:057089026a20 | 31 | |
gsfan | 12:057089026a20 | 32 | if (getHostByName(host, ip)) return -1; |
gsfan | 12:057089026a20 | 33 | if (! port) { |
gsfan | 12:057089026a20 | 34 | port = 80; |
gsfan | 12:057089026a20 | 35 | } |
gsfan | 12:057089026a20 | 36 | |
gsfan | 12:057089026a20 | 37 | cid = open(PROTO_TCP, ip, port); |
gsfan | 12:057089026a20 | 38 | if (cid < 0) return -1; |
gsfan | 12:057089026a20 | 39 | DBG("ws cid %d\r\n", cid); |
gsfan | 12:057089026a20 | 40 | |
gsfan | 12:057089026a20 | 41 | // request |
gsfan | 12:057089026a20 | 42 | snprintf(cmd, sizeof(cmd), "GET %d HTTP/1.1\r\n", uri); |
gsfan | 12:057089026a20 | 43 | send(cid, cmd, strlen(cmd)); |
gsfan | 12:057089026a20 | 44 | if (host) { |
gsfan | 12:057089026a20 | 45 | snprintf(cmd, sizeof(cmd), "Host: %s\r\n", host); |
gsfan | 12:057089026a20 | 46 | send(cid, cmd, strlen(cmd)); |
gsfan | 12:057089026a20 | 47 | } |
gsfan | 12:057089026a20 | 48 | if (user && pwd) { |
gsfan | 12:057089026a20 | 49 | snprintf(cmd, sizeof(cmd), "%s:%s", user, pwd); |
gsfan | 12:057089026a20 | 50 | base64encode(cmd, strlen(cmd), tmp, sizeof(tmp)); |
gsfan | 12:057089026a20 | 51 | snprintf(cmd, sizeof(cmd), "Authorization: Basic %s\r\n", tmp); |
gsfan | 12:057089026a20 | 52 | send(cid, cmd, strlen(cmd)); |
gsfan | 12:057089026a20 | 53 | } |
gsfan | 12:057089026a20 | 54 | strcpy(cmd, "Upgrade: websocket\r\n"); |
gsfan | 12:057089026a20 | 55 | send(cid, cmd, strlen(cmd)); |
gsfan | 12:057089026a20 | 56 | strcpy(cmd, "Connection: Upgrade\r\n"); |
gsfan | 12:057089026a20 | 57 | send(cid, cmd, strlen(cmd)); |
gsfan | 12:057089026a20 | 58 | getMacAddress(tmp); |
gsfan | 12:057089026a20 | 59 | memcpy(&tmp[6], host, 10); |
gsfan | 12:057089026a20 | 60 | base64encode(tmp, 16, cmd, sizeof(cmd)); |
gsfan | 12:057089026a20 | 61 | snprintf(cmd, sizeof(cmd), "Sec-WebSocket-Key: %s\r\n", tmp); |
gsfan | 12:057089026a20 | 62 | send(cid, cmd, strlen(cmd)); |
gsfan | 12:057089026a20 | 63 | strcpy(cmd, "Sec-WebSocket-Version: 13\r\n\r\n"); |
gsfan | 12:057089026a20 | 64 | send(cid, cmd, strlen(cmd)); |
gsfan | 12:057089026a20 | 65 | |
gsfan | 12:057089026a20 | 66 | if (wsWait(cid, 101)) { |
gsfan | 12:057089026a20 | 67 | close(cid); |
gsfan | 12:057089026a20 | 68 | return -1; |
gsfan | 12:057089026a20 | 69 | } |
gsfan | 12:057089026a20 | 70 | wsWait(cid, 0); |
gsfan | 12:057089026a20 | 71 | return cid; |
gsfan | 12:057089026a20 | 72 | } |
gsfan | 12:057089026a20 | 73 | |
gsfan | 12:057089026a20 | 74 | int GSwifi::wsWait (int cid, int code) { |
gsfan | 12:057089026a20 | 75 | Timer timeout; |
gsfan | 12:057089026a20 | 76 | int i, n, len; |
gsfan | 12:057089026a20 | 77 | char buf[CFG_DATA_SIZE], data[CFG_CMD_SIZE]; |
gsfan | 12:057089026a20 | 78 | |
gsfan | 12:057089026a20 | 79 | if (code == 0) { |
gsfan | 12:057089026a20 | 80 | // dummy read |
gsfan | 12:057089026a20 | 81 | timeout.start(); |
gsfan | 12:057089026a20 | 82 | while (timeout.read_ms() < CFG_TIMEOUT) { |
gsfan | 12:057089026a20 | 83 | wait_ms(10); |
gsfan | 12:057089026a20 | 84 | if (!readable(cid)) break; |
gsfan | 12:057089026a20 | 85 | n = recv(cid, buf, sizeof(buf)); |
gsfan | 12:057089026a20 | 86 | if (n <= 0) break; |
gsfan | 12:057089026a20 | 87 | } |
gsfan | 12:057089026a20 | 88 | timeout.stop(); |
gsfan | 12:057089026a20 | 89 | return 0; |
gsfan | 12:057089026a20 | 90 | } |
gsfan | 12:057089026a20 | 91 | |
gsfan | 12:057089026a20 | 92 | // wait responce |
gsfan | 12:057089026a20 | 93 | len = 0; |
gsfan | 12:057089026a20 | 94 | timeout.start(); |
gsfan | 12:057089026a20 | 95 | while (timeout.read_ms() < CFG_TIMEOUT) { |
gsfan | 12:057089026a20 | 96 | wait_ms(10); |
gsfan | 12:057089026a20 | 97 | n = recv(cid, buf, sizeof(buf)); |
gsfan | 12:057089026a20 | 98 | for (i = 0; i < n; i ++) { |
gsfan | 12:057089026a20 | 99 | if (buf[i] == '\r') continue; |
gsfan | 12:057089026a20 | 100 | if (buf[i] == '\n') { |
gsfan | 12:057089026a20 | 101 | if (len == 0) continue; |
gsfan | 12:057089026a20 | 102 | goto next; |
gsfan | 12:057089026a20 | 103 | } else |
gsfan | 12:057089026a20 | 104 | if (len < sizeof(data) - 1) { |
gsfan | 12:057089026a20 | 105 | data[len] = buf[i]; |
gsfan | 12:057089026a20 | 106 | len ++; |
gsfan | 12:057089026a20 | 107 | } |
gsfan | 12:057089026a20 | 108 | } |
gsfan | 12:057089026a20 | 109 | } |
gsfan | 12:057089026a20 | 110 | next: |
gsfan | 12:057089026a20 | 111 | data[len] = 0; |
gsfan | 12:057089026a20 | 112 | timeout.stop(); |
gsfan | 12:057089026a20 | 113 | DBG("ws: %s\r\n", data); |
gsfan | 12:057089026a20 | 114 | |
gsfan | 12:057089026a20 | 115 | // check return code |
gsfan | 12:057089026a20 | 116 | if (strncmp(data, "HTTP/1.1 ", 9) != 0) return -1; |
gsfan | 12:057089026a20 | 117 | i = atoi(&data[9]); |
gsfan | 12:057089026a20 | 118 | DBG("ws status %d\r\n", i); |
gsfan | 12:057089026a20 | 119 | return i == code ? 0 : -1; |
gsfan | 12:057089026a20 | 120 | } |
gsfan | 12:057089026a20 | 121 | |
gsfan | 12:057089026a20 | 122 | int GSwifi::wsSend (int cid, const char *buf, int len, const char *mask) { |
gsfan | 12:057089026a20 | 123 | int i = 0, r; |
gsfan | 12:057089026a20 | 124 | char tmp[10]; |
gsfan | 12:057089026a20 | 125 | |
gsfan | 12:057089026a20 | 126 | tmp[i++] = 0x81; // single, text frame |
gsfan | 12:057089026a20 | 127 | if (len < 126) { |
gsfan | 12:057089026a20 | 128 | tmp[i++] = (mask == NULL ? 0 : 0x80) | len; |
gsfan | 12:057089026a20 | 129 | } else { |
gsfan | 12:057089026a20 | 130 | tmp[i++] = (mask == NULL ? 0 : 0x80) | 126; |
gsfan | 12:057089026a20 | 131 | tmp[i++] = (len >> 8) & 0xff; |
gsfan | 12:057089026a20 | 132 | tmp[i++] = len & 0xff; |
gsfan | 12:057089026a20 | 133 | } |
gsfan | 12:057089026a20 | 134 | if (mask) { |
gsfan | 12:057089026a20 | 135 | memcpy(&tmp[i], mask, 4); |
gsfan | 12:057089026a20 | 136 | i += 4; |
gsfan | 12:057089026a20 | 137 | } |
gsfan | 12:057089026a20 | 138 | r = send(cid, tmp, strlen(tmp)); |
gsfan | 12:057089026a20 | 139 | |
gsfan | 12:057089026a20 | 140 | if (r == 0) { |
gsfan | 12:057089026a20 | 141 | if (mask) { |
gsfan | 12:057089026a20 | 142 | char tmp2[len]; |
gsfan | 12:057089026a20 | 143 | for (i = 0; i < len; i ++) { |
gsfan | 12:057089026a20 | 144 | tmp2[i] = buf[i] ^ mask[i & 0x03]; |
gsfan | 12:057089026a20 | 145 | } |
gsfan | 12:057089026a20 | 146 | r = send(cid, tmp2, len); |
gsfan | 12:057089026a20 | 147 | } else { |
gsfan | 12:057089026a20 | 148 | r = send(cid, buf, len); |
gsfan | 12:057089026a20 | 149 | } |
gsfan | 12:057089026a20 | 150 | } |
gsfan | 12:057089026a20 | 151 | return r; |
gsfan | 12:057089026a20 | 152 | } |
gsfan | 12:057089026a20 | 153 | |
gsfan | 12:057089026a20 | 154 | #ifdef CFG_ENABLE_HTTPD |
gsfan | 12:057089026a20 | 155 | |
gsfan | 12:057089026a20 | 156 | void GSwifi::wsRecvData (int cid, char c) { |
gsfan | 12:057089026a20 | 157 | |
gsfan | 12:057089026a20 | 158 | switch (_httpd[cid].mode) { |
gsfan | 12:057089026a20 | 159 | case HTTPDMODE_WEBSOCKET: |
gsfan | 12:057089026a20 | 160 | if (_httpd[cid].n == 0) { |
gsfan | 12:057089026a20 | 161 | // flag |
gsfan | 12:057089026a20 | 162 | _httpd[cid].websocket_opcode = c & 0x0f; |
gsfan | 12:057089026a20 | 163 | _httpd[cid].websocket_flg = c << 8; |
gsfan | 12:057089026a20 | 164 | _httpd[cid].n ++; |
gsfan | 12:057089026a20 | 165 | } else |
gsfan | 12:057089026a20 | 166 | if (_httpd[cid].n == 1) { |
gsfan | 12:057089026a20 | 167 | // length 7bit |
gsfan | 12:057089026a20 | 168 | _httpd[cid].websocket_flg |= c; |
gsfan | 12:057089026a20 | 169 | _httpd[cid].length = c & 0x7f; |
gsfan | 12:057089026a20 | 170 | _httpd[cid].n ++; |
gsfan | 12:057089026a20 | 171 | if (_httpd[cid].length < 126) { |
gsfan | 12:057089026a20 | 172 | _httpd[cid].n = 0; |
gsfan | 12:057089026a20 | 173 | if (_httpd[cid].length) { |
gsfan | 12:057089026a20 | 174 | if (_httpd[cid].websocket_flg & 0x0080) { |
gsfan | 12:057089026a20 | 175 | _httpd[cid].mode = HTTPDMODE_WEBSOCKET_MASK; |
gsfan | 12:057089026a20 | 176 | } else { |
gsfan | 12:057089026a20 | 177 | _httpd[cid].mode = HTTPDMODE_WEBSOCKET_BODY; |
gsfan | 12:057089026a20 | 178 | } |
gsfan | 12:057089026a20 | 179 | } else { |
gsfan | 12:057089026a20 | 180 | _httpd[cid].mode = HTTPDMODE_WEBSOCKET_ENTER; |
gsfan | 12:057089026a20 | 181 | } |
gsfan | 12:057089026a20 | 182 | DBG("ws length %d\r\n", _httpd[cid].length); |
gsfan | 12:057089026a20 | 183 | } |
gsfan | 12:057089026a20 | 184 | } else { |
gsfan | 12:057089026a20 | 185 | // length 16bit,64bit |
gsfan | 12:057089026a20 | 186 | if (_httpd[cid].n == 2) { |
gsfan | 12:057089026a20 | 187 | _httpd[cid].length = c; |
gsfan | 12:057089026a20 | 188 | _httpd[cid].n ++; |
gsfan | 12:057089026a20 | 189 | } else |
gsfan | 12:057089026a20 | 190 | if (_httpd[cid].n < 9 && (_httpd[cid].websocket_flg & 0x7f) == 127) { |
gsfan | 12:057089026a20 | 191 | // 64bit |
gsfan | 12:057089026a20 | 192 | _httpd[cid].length = (_httpd[cid].length << 8) | c; |
gsfan | 12:057089026a20 | 193 | _httpd[cid].n ++; |
gsfan | 12:057089026a20 | 194 | } else { |
gsfan | 12:057089026a20 | 195 | // end |
gsfan | 12:057089026a20 | 196 | _httpd[cid].length = (_httpd[cid].length << 8) | c; |
gsfan | 12:057089026a20 | 197 | _httpd[cid].n = 0; |
gsfan | 12:057089026a20 | 198 | if (_httpd[cid].websocket_flg & 0x0080) { |
gsfan | 12:057089026a20 | 199 | _httpd[cid].mode = HTTPDMODE_WEBSOCKET_MASK; |
gsfan | 12:057089026a20 | 200 | } else { |
gsfan | 12:057089026a20 | 201 | _httpd[cid].mode = HTTPDMODE_WEBSOCKET_BODY; |
gsfan | 12:057089026a20 | 202 | } |
gsfan | 12:057089026a20 | 203 | DBG("ws length2 %d\r\n", _httpd[cid].length); |
gsfan | 12:057089026a20 | 204 | } |
gsfan | 12:057089026a20 | 205 | } |
gsfan | 12:057089026a20 | 206 | break; |
gsfan | 12:057089026a20 | 207 | case HTTPDMODE_WEBSOCKET_MASK: |
gsfan | 12:057089026a20 | 208 | // masking key |
gsfan | 12:057089026a20 | 209 | _httpd[cid].websocket_mask[_httpd[cid].n] = c; |
gsfan | 12:057089026a20 | 210 | _httpd[cid].n ++; |
gsfan | 12:057089026a20 | 211 | if (_httpd[cid].n >= 4) { |
gsfan | 12:057089026a20 | 212 | _httpd[cid].n = 0; |
gsfan | 12:057089026a20 | 213 | _httpd[cid].mode = HTTPDMODE_WEBSOCKET_BODY; |
gsfan | 12:057089026a20 | 214 | DBG("ws mask\r\n"); |
gsfan | 12:057089026a20 | 215 | } |
gsfan | 12:057089026a20 | 216 | break; |
gsfan | 12:057089026a20 | 217 | case HTTPDMODE_WEBSOCKET_BODY: |
gsfan | 12:057089026a20 | 218 | // payload |
gsfan | 12:057089026a20 | 219 | if (_httpd[cid].websocket_flg & 0x0080) { |
gsfan | 12:057089026a20 | 220 | // un-mask |
gsfan | 12:057089026a20 | 221 | _httpd[cid].buf->queue(c ^ _httpd[cid].websocket_mask[_httpd[cid].n & 0x03]); |
gsfan | 12:057089026a20 | 222 | } else { |
gsfan | 12:057089026a20 | 223 | _httpd[cid].buf->queue(c); |
gsfan | 12:057089026a20 | 224 | } |
gsfan | 12:057089026a20 | 225 | _httpd[cid].n ++; |
gsfan | 12:057089026a20 | 226 | if (_httpd[cid].n >= _httpd[cid].length) { |
gsfan | 12:057089026a20 | 227 | _httpd[cid].mode = HTTPDMODE_WEBSOCKET_ENTER; |
gsfan | 12:057089026a20 | 228 | _con[cid].received = true; |
gsfan | 12:057089026a20 | 229 | } |
gsfan | 12:057089026a20 | 230 | break; |
gsfan | 12:057089026a20 | 231 | } |
gsfan | 12:057089026a20 | 232 | } |
gsfan | 12:057089026a20 | 233 | |
gsfan | 12:057089026a20 | 234 | int GSwifi::wsParseRequest (int cid) { |
gsfan | 12:057089026a20 | 235 | int i; |
gsfan | 12:057089026a20 | 236 | |
gsfan | 12:057089026a20 | 237 | DBG("ws opcode %d\r\n", _httpd[cid].websocket_opcode); |
gsfan | 12:057089026a20 | 238 | switch (_httpd[cid].websocket_opcode) { |
gsfan | 12:057089026a20 | 239 | case 0x00: // continuation |
gsfan | 12:057089026a20 | 240 | break; |
gsfan | 12:057089026a20 | 241 | case 0x01: // text |
gsfan | 12:057089026a20 | 242 | case 0x02: // binary |
gsfan | 12:057089026a20 | 243 | i = httpdGetHandler(_httpd[cid].uri); |
gsfan | 12:057089026a20 | 244 | if (i >= 0) { |
gsfan | 12:057089026a20 | 245 | if (_httpd_handler[i].func) { |
gsfan | 12:057089026a20 | 246 | // cgi |
gsfan | 12:057089026a20 | 247 | _httpd_handler[i].func(cid); |
gsfan | 12:057089026a20 | 248 | } |
gsfan | 12:057089026a20 | 249 | } |
gsfan | 12:057089026a20 | 250 | break; |
gsfan | 12:057089026a20 | 251 | case 0x08: // close |
gsfan | 12:057089026a20 | 252 | close(cid); |
gsfan | 12:057089026a20 | 253 | break; |
gsfan | 12:057089026a20 | 254 | case 0x09: // ping |
gsfan | 12:057089026a20 | 255 | { |
gsfan | 12:057089026a20 | 256 | char pong[_httpd[cid].n + 2]; |
gsfan | 12:057089026a20 | 257 | pong[0] = 0x8a; |
gsfan | 12:057089026a20 | 258 | pong[1] = 0x04; |
gsfan | 12:057089026a20 | 259 | for (i = 0; i < _httpd[cid].length; i ++) { |
gsfan | 12:057089026a20 | 260 | if (_httpd[cid].buf->dequeue(&pong[i + 2]) == false) break; |
gsfan | 12:057089026a20 | 261 | } |
gsfan | 12:057089026a20 | 262 | send(cid, pong, _httpd[cid].length + 2); |
gsfan | 12:057089026a20 | 263 | } |
gsfan | 12:057089026a20 | 264 | break; |
gsfan | 12:057089026a20 | 265 | case 0x0a: // pong |
gsfan | 12:057089026a20 | 266 | break; |
gsfan | 12:057089026a20 | 267 | default: |
gsfan | 12:057089026a20 | 268 | break; |
gsfan | 12:057089026a20 | 269 | } |
gsfan | 12:057089026a20 | 270 | _httpd[cid].n = 0; |
gsfan | 12:057089026a20 | 271 | _httpd[cid].length = 0; |
gsfan | 12:057089026a20 | 272 | return 0; |
gsfan | 12:057089026a20 | 273 | } |
gsfan | 12:057089026a20 | 274 | |
gsfan | 12:057089026a20 | 275 | int GSwifi::wsAccept (int cid) { |
gsfan | 12:057089026a20 | 276 | char buf[CFG_CMD_SIZE], buf2[CFG_CMD_SIZE]; |
gsfan | 12:057089026a20 | 277 | |
gsfan | 12:057089026a20 | 278 | DBG("websocket accept: %d\r\n", cid); |
gsfan | 12:057089026a20 | 279 | |
gsfan | 12:057089026a20 | 280 | strcpy(buf, "HTTP/1.1 101 Switching Protocols\r\n"); |
gsfan | 12:057089026a20 | 281 | send(cid, buf, strlen(buf)); |
gsfan | 12:057089026a20 | 282 | strcpy(buf, "Upgrade: websocket\r\n"); |
gsfan | 12:057089026a20 | 283 | send(cid, buf, strlen(buf)); |
gsfan | 12:057089026a20 | 284 | strcpy(buf, "Connection: Upgrade\r\n"); |
gsfan | 12:057089026a20 | 285 | send(cid, buf, strlen(buf)); |
gsfan | 12:057089026a20 | 286 | |
gsfan | 12:057089026a20 | 287 | strcpy(buf, "Sec-WebSocket-Accept: "); |
gsfan | 12:057089026a20 | 288 | send(cid, buf, strlen(buf)); |
gsfan | 12:057089026a20 | 289 | strcpy(buf, _httpd[cid].websocket_key); |
gsfan | 12:057089026a20 | 290 | strcat(buf, "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"); |
gsfan | 12:057089026a20 | 291 | sha1(buf, strlen(buf), buf2); |
gsfan | 12:057089026a20 | 292 | base64encode(buf2, 20, buf, sizeof(buf)); |
gsfan | 12:057089026a20 | 293 | send(cid, buf, strlen(buf)); |
gsfan | 12:057089026a20 | 294 | strcpy(buf, "\r\n\r\n"); |
gsfan | 12:057089026a20 | 295 | send(cid, buf, strlen(buf)); |
gsfan | 12:057089026a20 | 296 | return 0; |
gsfan | 12:057089026a20 | 297 | } |
gsfan | 12:057089026a20 | 298 | |
gsfan | 12:057089026a20 | 299 | #endif |
gsfan | 12:057089026a20 | 300 | #endif |