ソースの整理中ですが、利用はできます。

Dependencies:   EthernetInterface HttpServer TextLCD mbed-rpc mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
yueee_yt
Date:
Wed Mar 12 04:39:15 2014 +0000
Revision:
2:14b689a85306
Parent:
0:7766f6712673
bug fix

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yueee_yt 0:7766f6712673 1
yueee_yt 0:7766f6712673 2 /*
yueee_yt 0:7766f6712673 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
yueee_yt 0:7766f6712673 4
yueee_yt 0:7766f6712673 5 Permission is hereby granted, free of charge, to any person obtaining a copy
yueee_yt 0:7766f6712673 6 of this software and associated documentation files (the "Software"), to deal
yueee_yt 0:7766f6712673 7 in the Software without restriction, including without limitation the rights
yueee_yt 0:7766f6712673 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
yueee_yt 0:7766f6712673 9 copies of the Software, and to permit persons to whom the Software is
yueee_yt 0:7766f6712673 10 furnished to do so, subject to the following conditions:
yueee_yt 0:7766f6712673 11
yueee_yt 0:7766f6712673 12 The above copyright notice and this permission notice shall be included in
yueee_yt 0:7766f6712673 13 all copies or substantial portions of the Software.
yueee_yt 0:7766f6712673 14
yueee_yt 0:7766f6712673 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
yueee_yt 0:7766f6712673 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
yueee_yt 0:7766f6712673 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
yueee_yt 0:7766f6712673 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
yueee_yt 0:7766f6712673 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
yueee_yt 0:7766f6712673 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
yueee_yt 0:7766f6712673 21 THE SOFTWARE.
yueee_yt 0:7766f6712673 22 */
yueee_yt 0:7766f6712673 23
yueee_yt 0:7766f6712673 24 /**
yueee_yt 0:7766f6712673 25 HTTP Request Handler header file.
yueee_yt 0:7766f6712673 26 */
yueee_yt 0:7766f6712673 27
yueee_yt 0:7766f6712673 28 #ifndef HTTP_REQUEST_HANDLER_H
yueee_yt 0:7766f6712673 29 #define HTTP_REQUEST_HANDLER_H
yueee_yt 0:7766f6712673 30
yueee_yt 0:7766f6712673 31 //#include "HTTPServer.h"
yueee_yt 0:7766f6712673 32
yueee_yt 0:7766f6712673 33 #include "mbed.h"
yueee_yt 0:7766f6712673 34 #include "EthernetInterface.h"
yueee_yt 0:7766f6712673 35
yueee_yt 0:7766f6712673 36 #include <string>
yueee_yt 0:7766f6712673 37 using std::string;
yueee_yt 0:7766f6712673 38
yueee_yt 0:7766f6712673 39 #include <map>
yueee_yt 0:7766f6712673 40 using std::map;
yueee_yt 0:7766f6712673 41
yueee_yt 0:7766f6712673 42 ///HTTP Server's generic request handler
yueee_yt 0:7766f6712673 43 class HTTPRequestHandler
yueee_yt 0:7766f6712673 44 {
yueee_yt 0:7766f6712673 45 public:
yueee_yt 0:7766f6712673 46 ///Instantiated by the HTTP Server
yueee_yt 0:7766f6712673 47 HTTPRequestHandler(const char* rootPath, const char* path, TCPSocketConnection* pTCPSocketConnection);
yueee_yt 0:7766f6712673 48 virtual ~HTTPRequestHandler();
yueee_yt 0:7766f6712673 49
yueee_yt 0:7766f6712673 50 //protected:
yueee_yt 0:7766f6712673 51 virtual void doGet() = 0;
yueee_yt 0:7766f6712673 52 virtual void doPost() = 0;
yueee_yt 0:7766f6712673 53 virtual void doHead() = 0;
yueee_yt 0:7766f6712673 54
yueee_yt 0:7766f6712673 55 virtual void onReadable() = 0; //Data has been read
yueee_yt 0:7766f6712673 56 virtual void onWriteable() = 0; //Data has been written & buf is free
yueee_yt 0:7766f6712673 57 virtual void onTimeout(); //Connection has timed out
yueee_yt 0:7766f6712673 58 virtual void onClose() = 0; //Connection is closing
yueee_yt 0:7766f6712673 59
yueee_yt 0:7766f6712673 60 virtual void close(); //Close socket and destroy data
yueee_yt 0:7766f6712673 61
yueee_yt 0:7766f6712673 62 protected:
yueee_yt 0:7766f6712673 63 // map<string, string>& reqHeaders() /*const*/;
yueee_yt 0:7766f6712673 64 void reqHeaders(string *key,string *value,unsigned char *count);
yueee_yt 0:7766f6712673 65 string& path() /*const*/;
yueee_yt 0:7766f6712673 66 int dataLen() const;
yueee_yt 0:7766f6712673 67 int readData(char* buf, int len);
yueee_yt 0:7766f6712673 68 string& rootPath() /*const*/;
yueee_yt 0:7766f6712673 69
yueee_yt 0:7766f6712673 70 void setErrCode(int errc);
yueee_yt 0:7766f6712673 71 void setContentLen(int len);
yueee_yt 0:7766f6712673 72
yueee_yt 0:7766f6712673 73 // map<string, string>& respHeaders();
yueee_yt 0:7766f6712673 74 void respHeaders(string *key,string *value,unsigned char *count );
yueee_yt 0:7766f6712673 75
yueee_yt 0:7766f6712673 76 int writeData(const char* buf, int len);
yueee_yt 0:7766f6712673 77 char* getAddress(void);
yueee_yt 0:7766f6712673 78 string& getRequestData(void);
yueee_yt 0:7766f6712673 79 void addRespHeaders(string key,string value);
yueee_yt 0:7766f6712673 80
yueee_yt 0:7766f6712673 81 void readReqData();
yueee_yt 0:7766f6712673 82
yueee_yt 0:7766f6712673 83 //* void setTimeout(int ms);
yueee_yt 0:7766f6712673 84 //* void resetTimeout();
yueee_yt 0:7766f6712673 85
yueee_yt 0:7766f6712673 86 private:
yueee_yt 0:7766f6712673 87 void readHeaders(); //Called at instanciation
yueee_yt 0:7766f6712673 88 void writeHeaders(); //Called at the first writeData call
yueee_yt 0:7766f6712673 89 //**void onTCPSocketEvent(/**TCPSocketEvent e**/);
yueee_yt 0:7766f6712673 90
yueee_yt 0:7766f6712673 91 TCPSocketConnection* m_pTCPSocketConnection;
yueee_yt 0:7766f6712673 92 //map<string, string> m_reqHeaders;
yueee_yt 0:7766f6712673 93 //map<string, string> m_respHeaders;
yueee_yt 0:7766f6712673 94 string req_headers_key[10];
yueee_yt 0:7766f6712673 95 string req_headers_value[10];
yueee_yt 0:7766f6712673 96 unsigned char req_headers_count;
yueee_yt 0:7766f6712673 97 string resp_headers_key[10];
yueee_yt 0:7766f6712673 98 string resp_headers_value[10];
yueee_yt 0:7766f6712673 99 unsigned char resp_headers_count;
yueee_yt 0:7766f6712673 100 string m_rootPath;
yueee_yt 0:7766f6712673 101 string m_path;
yueee_yt 0:7766f6712673 102 string m_reqData;
yueee_yt 0:7766f6712673 103
yueee_yt 0:7766f6712673 104 int m_errc; //Response code
yueee_yt 0:7766f6712673 105
yueee_yt 0:7766f6712673 106 //* Timeout m_watchdog;
yueee_yt 0:7766f6712673 107 //* int m_timeout;
yueee_yt 0:7766f6712673 108
yueee_yt 0:7766f6712673 109 bool m_closed;
yueee_yt 0:7766f6712673 110 bool m_headersSent;
yueee_yt 0:7766f6712673 111
yueee_yt 0:7766f6712673 112 int readLine(char* str, int maxLen);
yueee_yt 0:7766f6712673 113 int clength;
yueee_yt 2:14b689a85306 114 bool chunkmode;
yueee_yt 0:7766f6712673 115 };
yueee_yt 0:7766f6712673 116
yueee_yt 0:7766f6712673 117 #endif
yueee_yt 0:7766f6712673 118
yueee_yt 0:7766f6712673 119