for TwitterMbed
Fork of GSwifi_old by
Diff: GSwifi.h
- Revision:
- 18:4b97804c37d1
- Parent:
- 17:6828b084e74b
- Child:
- 19:cad912f5a6ba
--- a/GSwifi.h Sun Oct 28 14:26:31 2012 +0000 +++ b/GSwifi.h Thu Nov 01 02:55:57 2012 +0000 @@ -14,6 +14,7 @@ #define _GSWIFI_H_ #include "mbed.h" +#include "GSwifi_net.h" #include "RingBuffer.h" #include "host.h" #include "ipaddr.h" @@ -27,7 +28,8 @@ #define GS_TIMEOUT2 30000 // ms #define GS_CMD_SIZE 100 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) -#define GS_DATA_SIZE 1500 +//#define GS_DATA_SIZE 1500 +#define GS_DATA_SIZE 1000 #elif defined(TARGET_LPC11U24) #define GS_DATA_SIZE 500 #endif @@ -55,6 +57,7 @@ GSPROT_TCP = 1, GSPROT_HTTPGET, GSPROT_HTTPPOST, + GSPROT_HTTPD, }; /** @@ -270,6 +273,14 @@ * @return CID, -1:failure */ int listen (int port, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive = NULL); +/* + template<typename T> + int listen2 (T* tptr, int port, GSPROTOCOL pro, void (T::*mptr)(int,int)) { + if((mptr != NULL) && (tptr != NULL)) { + return listen(port, pro, reinterpret_cast<onGsReceiveFunc>(mptr)); + } + } +*/ /** * close client/server */ @@ -298,44 +309,90 @@ bool isConnected (int cid); /** - * http request - * @return CID, -1:failure - * If you use ssl, please set system time. + * http request (GET method) */ int httpGet (Host &host, char *uri, char *user, char *pwd, int ssl = 0, onGsReceiveFunc ponGsReceive = NULL); int httpGet (Host &host, char *uri, int ssl = 0, onGsReceiveFunc ponGsReceive = NULL); /** - * http request - * @return CID, -1:failure - * If you use ssl, please set system time. + * http request (POST method) */ int httpPost (Host &host, char *uri, char *body, char *user, char *pwd, int ssl = 0, onGsReceiveFunc ponGsReceive = NULL); int httpPost (Host &host, char *uri, char *body, int ssl = 0, onGsReceiveFunc ponGsReceive = NULL); + /** * certificate */ int certAdd (char *name, char *cert, int len); + /** + * send mail (smtp) + * @param host SMTP server + * @param to To address + * @param from From address + * @param subject Subject + * @param mesg Message + * @param user username (SMTP Auth) + * @param pwd password (SMTP Auth) + * @retval 0 success + * @retval -1 failure + */ + int mail (Host &host, char *to, char *from, char *subject, char *mesg, char *user = NULL, char *pwd = NULL); + + /** + * start http server + * @param port + */ + int httpd (int port = 80); + /** + * attach uri to dirctory handler + */ + void send_httpd_error (int cid, int err); + /** + * attach uri to dirctory handler + */ + int attach_httpd (char *uri, char *dir); + /** + * attach uri to cgi handler + */ + int attach_httpd (char *uri, onHttpdCgiFunc ponHttpCgi); + + /** + * base64 encode + */ int base64encode (const char *input, int length, char *output, int len); + /** + * url encode + */ int urlencode (char *str, char *buf, int len); +#ifdef DEBUF void test (); int getc(); void putc(char c); int readable(); +#endif protected: + void poll_cmd (); int x2i (char c); char i2x (int i); void isr_recv (); void newSock (int cid, GSTYPE type, GSPROTOCOL pro, onGsReceiveFunc ponGsReceive); + // send mail (smtp) + int wait_smtp (int cid, int code); + + // http server + void poll_httpd (int cid, int len); + int httpd_request (int cid, char *dir, char *file, int keep); + private: Serial _gs; bool _rts; volatile bool _connect; volatile GSSTATUS _status; volatile int _gs_ok, _gs_failure, _gs_enter; + volatile int _response; GSMODE _gs_mode; int _escape; int _cid, _rssi; @@ -345,6 +402,10 @@ RingBuffer _buf_cmd; struct GS_Socket _gs_sock[16]; time_t _time; + + struct GS_httpd _httpd[16]; + struct GS_httpd_handler _handler[10]; + int _handler_count; }; #endif