GainSpan Wi-Fi library see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
Dependents: GSwifi_httpd GSwifi_websocket GSwifi_tcpclient GSwifi_tcpserver ... more
Fork of GSwifi by
GainSpan Wi-Fi library
The GS1011 is an ultra low power 802.11b wireless module from GainSpan.
see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
ゲインスパン Wi-Fi モジュール ライブラリ
ゲインスパン社の低電力 Wi-Fiモジュール(無線LAN) GS1011 シリーズ用のライブラリです。
解説: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
Diff: GSwifi_httpd.cpp
- Revision:
- 35:515ec79792d3
- Parent:
- 31:0abdc584823d
--- a/GSwifi_httpd.cpp Fri Mar 29 14:58:07 2013 +0000 +++ b/GSwifi_httpd.cpp Fri Jun 21 06:08:37 2013 +0000 @@ -20,14 +20,15 @@ * GS1011MIC, GS1011MIP, GainSpan WiFi Breakout, etc. */ +#include "GSwifi_conf.h" +#ifdef GS_ENABLE_HTTPD + #include "dbg.h" #include "mbed.h" #include "GSwifi.h" #include "sha1.h" #include <string.h> -#ifdef GS_USE_HTTPD - #define MIMETABLE_NUM 9 static const struct { char ext[5]; @@ -72,13 +73,13 @@ _httpd[cid].mode = GSHTTPDMODE_REQUEST; _httpd[cid].len = 0; _httpd[cid].keepalive = 0; -#ifdef GS_USE_WEBSOCKET +#ifdef GS_ENABLE_WEBSOCKET _httpd[cid].websocket = 0; #endif return; } -#ifdef GS_USE_WEBSOCKET +#ifdef GS_ENABLE_WEBSOCKET if (_httpd[cid].mode >= GSHTTPDMODE_WEBSOCKET) { poll_websocket(cid, len); return; @@ -88,7 +89,7 @@ while (_gs_sock[cid].connect && (! _gs_sock[cid].data->isEmpty())) { flg = 0; if (_httpd[cid].buf == NULL) { - _httpd[cid].buf = new char[HTTPD_BUF_SIZE]; + _httpd[cid].buf = (char*)malloc(HTTPD_BUF_SIZE); } // get 1 line for (j = 0; j < len; j ++) { @@ -130,7 +131,7 @@ i = i - j; if (i) { if (_httpd[cid].uri == NULL) { - _httpd[cid].uri = new char[HTTPD_URI_SIZE]; + _httpd[cid].uri = (char*)malloc(HTTPD_URI_SIZE); } strncpy(_httpd[cid].uri, &_httpd[cid].buf[j], i); _httpd[cid].uri[i] = 0; @@ -145,7 +146,7 @@ // blank line (end of header) _httpd[cid].mode = GSHTTPDMODE_BODY; if (_httpd[cid].length == 0) flg = 1; // no body -#ifdef GS_USE_WEBSOCKET +#ifdef GS_ENABLE_WEBSOCKET if (_httpd[cid].websocket && _httpd[cid].websocket_key) { // enter websocket _httpd[cid].mode = GSHTTPDMODE_WEBSOCKET; @@ -161,7 +162,7 @@ if (! _httpd[cid].keepalive) { _httpd[cid].keepalive = HTTPD_KEEPALIVE; } -#ifdef GS_USE_WEBSOCKET +#ifdef GS_ENABLE_WEBSOCKET } else if (strnicmp(_httpd[cid].buf, "Upgrade: websocket", 18) == 0) { if (! _httpd[cid].websocket) _httpd[cid].websocket = 1; @@ -171,7 +172,7 @@ } else if (strnicmp(_httpd[cid].buf, "Sec-WebSocket-Key: ", 19) == 0) { if (_httpd[cid].websocket_key == NULL) { - _httpd[cid].websocket_key = new char[30]; + _httpd[cid].websocket_key = (char*)malloc(30); } strncpy(_httpd[cid].websocket_key, &_httpd[cid].buf[19], 30); #endif @@ -187,7 +188,7 @@ } -#ifdef GS_USE_WEBSOCKET +#ifdef GS_ENABLE_WEBSOCKET if (flg && _httpd[cid].mode == GSHTTPDMODE_WEBSOCKET) { // websocket i = get_handler(_httpd[cid].uri); @@ -393,9 +394,9 @@ int GSwifi::attach_httpd (const char *uri, const char *dir) { if (_handler_count < HTTPD_HANDLE) { - _handler[_handler_count].uri = new char[strlen(uri) + 1]; + _handler[_handler_count].uri = (char*)malloc(strlen(uri) + 1); strcpy(_handler[_handler_count].uri, uri); - _handler[_handler_count].dir = new char[strlen(dir) + 1]; + _handler[_handler_count].dir = (char*)malloc(strlen(dir) + 1); strcpy(_handler[_handler_count].dir, dir); _handler[_handler_count].onHttpCgi = NULL; _handler_count ++; @@ -407,7 +408,7 @@ int GSwifi::attach_httpd (const char *uri, onHttpdCgiFunc ponHttpCgi) { if (_handler_count < HTTPD_HANDLE) { - _handler[_handler_count].uri = new char[strlen(uri) + 1]; + _handler[_handler_count].uri = (char*)malloc(strlen(uri) + 1); strcpy(_handler[_handler_count].uri, uri); _handler[_handler_count].dir = NULL; _handler[_handler_count].onHttpCgi = ponHttpCgi; @@ -418,7 +419,7 @@ } } -#ifdef GS_USE_WEBSOCKET +#ifdef GS_ENABLE_WEBSOCKET void GSwifi::poll_websocket (int cid, int len) { int i, j, flg; unsigned char c; @@ -576,6 +577,6 @@ LOG("%d.%d.%d.%d ", _httpd[cid].host.getIp()[0], _httpd[cid].host.getIp()[1], _httpd[cid].host.getIp()[2], _httpd[cid].host.getIp()[3]); LOG("%s %s %d 101 - %s\r\n", _httpd[cid].type == GSPROT_HTTPGET ? "GET" : "POST", _httpd[cid].uri, _httpd[cid].length, buf); } -#endif +#endif // GS_ENABLE_WEBSOCKET #endif