Dependencies:   mbed

Dependents:   TCP

Committer:
slowness
Date:
Tue Sep 06 18:05:46 2011 +0000
Revision:
0:58c3d014a4e7

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
slowness 0:58c3d014a4e7 1
slowness 0:58c3d014a4e7 2 /*
slowness 0:58c3d014a4e7 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
slowness 0:58c3d014a4e7 4
slowness 0:58c3d014a4e7 5 Permission is hereby granted, free of charge, to any person obtaining a copy
slowness 0:58c3d014a4e7 6 of this software and associated documentation files (the "Software"), to deal
slowness 0:58c3d014a4e7 7 in the Software without restriction, including without limitation the rights
slowness 0:58c3d014a4e7 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
slowness 0:58c3d014a4e7 9 copies of the Software, and to permit persons to whom the Software is
slowness 0:58c3d014a4e7 10 furnished to do so, subject to the following conditions:
slowness 0:58c3d014a4e7 11
slowness 0:58c3d014a4e7 12 The above copyright notice and this permission notice shall be included in
slowness 0:58c3d014a4e7 13 all copies or substantial portions of the Software.
slowness 0:58c3d014a4e7 14
slowness 0:58c3d014a4e7 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
slowness 0:58c3d014a4e7 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
slowness 0:58c3d014a4e7 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
slowness 0:58c3d014a4e7 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
slowness 0:58c3d014a4e7 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
slowness 0:58c3d014a4e7 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
slowness 0:58c3d014a4e7 21 THE SOFTWARE.
slowness 0:58c3d014a4e7 22 */
slowness 0:58c3d014a4e7 23
slowness 0:58c3d014a4e7 24 #ifndef HTTP_REQUEST_DISPATCHER_H
slowness 0:58c3d014a4e7 25 #define HTTP_REQUEST_DISPATCHER_H
slowness 0:58c3d014a4e7 26
slowness 0:58c3d014a4e7 27 class HTTPServer;
slowness 0:58c3d014a4e7 28
slowness 0:58c3d014a4e7 29 #include "api/TCPSocket.h"
slowness 0:58c3d014a4e7 30 #include "HTTPServer.h"
slowness 0:58c3d014a4e7 31 #include "core/netservice.h"
slowness 0:58c3d014a4e7 32
slowness 0:58c3d014a4e7 33 #include "mbed.h"
slowness 0:58c3d014a4e7 34
slowness 0:58c3d014a4e7 35 #define HTTP_REQUEST_TIMEOUT 5000
slowness 0:58c3d014a4e7 36
slowness 0:58c3d014a4e7 37 #include <string>
slowness 0:58c3d014a4e7 38 using std::string;
slowness 0:58c3d014a4e7 39
slowness 0:58c3d014a4e7 40 class HTTPRequestDispatcher : public NetService
slowness 0:58c3d014a4e7 41 {
slowness 0:58c3d014a4e7 42 public:
slowness 0:58c3d014a4e7 43 HTTPRequestDispatcher(HTTPServer* pSvr, TCPSocket* pTCPSocket);
slowness 0:58c3d014a4e7 44 virtual ~HTTPRequestDispatcher();
slowness 0:58c3d014a4e7 45
slowness 0:58c3d014a4e7 46 private:
slowness 0:58c3d014a4e7 47
slowness 0:58c3d014a4e7 48 enum HTTP_METH
slowness 0:58c3d014a4e7 49 {
slowness 0:58c3d014a4e7 50 HTTP_GET,
slowness 0:58c3d014a4e7 51 HTTP_POST,
slowness 0:58c3d014a4e7 52 HTTP_HEAD
slowness 0:58c3d014a4e7 53 };
slowness 0:58c3d014a4e7 54
slowness 0:58c3d014a4e7 55 void dispatchRequest();
slowness 0:58c3d014a4e7 56
slowness 0:58c3d014a4e7 57 virtual void close(); //Close TCPSocket and destroy data
slowness 0:58c3d014a4e7 58
slowness 0:58c3d014a4e7 59 void onTCPSocketEvent(TCPSocketEvent e);
slowness 0:58c3d014a4e7 60
slowness 0:58c3d014a4e7 61 void onTimeout(); //Connection has timed out
slowness 0:58c3d014a4e7 62
slowness 0:58c3d014a4e7 63 bool getRequest(string* path, string* meth);
slowness 0:58c3d014a4e7 64
slowness 0:58c3d014a4e7 65 HTTPServer* m_pSvr;
slowness 0:58c3d014a4e7 66 TCPSocket* m_pTCPSocket;
slowness 0:58c3d014a4e7 67
slowness 0:58c3d014a4e7 68 Timeout m_watchdog;
slowness 0:58c3d014a4e7 69 bool m_closed;
slowness 0:58c3d014a4e7 70 };
slowness 0:58c3d014a4e7 71
slowness 0:58c3d014a4e7 72 #endif