Team E1
Fork of HTTPServer by
HTTPConnection.h@2:8653bbcf7e58, 2013-05-26 (annotated)
- Committer:
- leihen
- Date:
- Sun May 26 23:22:36 2013 +0000
- Revision:
- 2:8653bbcf7e58
- Parent:
- 1:6b7472d5e9ee
- Child:
- 3:d6224049b3bf
Optimized for RAM.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leihen | 0:7a2421e63e74 | 1 | /* HTTPConnection.h */ |
leihen | 0:7a2421e63e74 | 2 | #ifndef __HTTPConnection_H__ |
leihen | 0:7a2421e63e74 | 3 | #define __HTTPConnection_H__ |
leihen | 0:7a2421e63e74 | 4 | |
leihen | 0:7a2421e63e74 | 5 | #include "mbed.h" |
leihen | 0:7a2421e63e74 | 6 | #include "TCPSocketConnection.h" |
leihen | 0:7a2421e63e74 | 7 | |
leihen | 0:7a2421e63e74 | 8 | #include <string> |
leihen | 0:7a2421e63e74 | 9 | #include <map> |
leihen | 0:7a2421e63e74 | 10 | |
leihen | 1:6b7472d5e9ee | 11 | class HTTPServer; |
leihen | 1:6b7472d5e9ee | 12 | |
leihen | 0:7a2421e63e74 | 13 | enum HTTPRequestType |
leihen | 0:7a2421e63e74 | 14 | { |
leihen | 0:7a2421e63e74 | 15 | HTTP_RT_GET, |
leihen | 0:7a2421e63e74 | 16 | HTTP_RT_POST, |
leihen | 0:7a2421e63e74 | 17 | HTTP_RT_PUT, |
leihen | 0:7a2421e63e74 | 18 | HTTP_RT_OPTIONS, |
leihen | 0:7a2421e63e74 | 19 | HTTP_RT_HEAD, |
leihen | 0:7a2421e63e74 | 20 | HTTP_RT_DELETE, |
leihen | 0:7a2421e63e74 | 21 | HTTP_RT_TRACE, |
leihen | 0:7a2421e63e74 | 22 | HTTP_RT_CONNECT |
leihen | 0:7a2421e63e74 | 23 | }; |
leihen | 0:7a2421e63e74 | 24 | |
leihen | 0:7a2421e63e74 | 25 | struct HTTPMessage |
leihen | 0:7a2421e63e74 | 26 | { |
leihen | 0:7a2421e63e74 | 27 | HTTPRequestType request; |
leihen | 0:7a2421e63e74 | 28 | std::string uri; |
leihen | 0:7a2421e63e74 | 29 | std::string version; |
leihen | 0:7a2421e63e74 | 30 | std::map<string, string> headers; |
leihen | 0:7a2421e63e74 | 31 | }; |
leihen | 0:7a2421e63e74 | 32 | |
leihen | 0:7a2421e63e74 | 33 | /** class HTTPConnection, encapsulates one connection being made throught the HTTPServer |
leihen | 0:7a2421e63e74 | 34 | * |
leihen | 0:7a2421e63e74 | 35 | */ |
leihen | 0:7a2421e63e74 | 36 | class HTTPConnection { |
leihen | 0:7a2421e63e74 | 37 | public: |
leihen | 0:7a2421e63e74 | 38 | /** public constructor |
leihen | 0:7a2421e63e74 | 39 | * |
leihen | 0:7a2421e63e74 | 40 | */ |
leihen | 0:7a2421e63e74 | 41 | HTTPConnection (); |
leihen | 0:7a2421e63e74 | 42 | ~HTTPConnection(); |
leihen | 0:7a2421e63e74 | 43 | |
leihen | 0:7a2421e63e74 | 44 | /** function to close this connection. To be called from internally. |
leihen | 0:7a2421e63e74 | 45 | */ |
leihen | 0:7a2421e63e74 | 46 | void close(); |
leihen | 0:7a2421e63e74 | 47 | |
leihen | 0:7a2421e63e74 | 48 | /** query if this connection is closed and can be deleted. |
leihen | 0:7a2421e63e74 | 49 | @returns true if connection is closed. |
leihen | 0:7a2421e63e74 | 50 | */ |
leihen | 0:7a2421e63e74 | 51 | bool is_closed(); |
leihen | 0:7a2421e63e74 | 52 | |
leihen | 0:7a2421e63e74 | 53 | /** |
leihen | 0:7a2421e63e74 | 54 | Polling function |
leihen | 0:7a2421e63e74 | 55 | @returns -1 if connection is not required anymore. Can happen if a fault occured or if the connection is not needed anymore. |
leihen | 0:7a2421e63e74 | 56 | */ |
leihen | 0:7a2421e63e74 | 57 | int poll(); |
leihen | 0:7a2421e63e74 | 58 | |
leihen | 0:7a2421e63e74 | 59 | protected: |
leihen | 1:6b7472d5e9ee | 60 | friend class HTTPServer; |
leihen | 1:6b7472d5e9ee | 61 | |
leihen | 0:7a2421e63e74 | 62 | TCPSocketConnection m_Tcp; |
leihen | 1:6b7472d5e9ee | 63 | HTTPMessage m_Msg; |
leihen | 0:7a2421e63e74 | 64 | |
leihen | 2:8653bbcf7e58 | 65 | int parse(char *buffer); |
leihen | 0:7a2421e63e74 | 66 | int parseHeader(const char *buffer); |
leihen | 0:7a2421e63e74 | 67 | int receiveHeaders(const char* buffer, int nBuffSize); |
leihen | 0:7a2421e63e74 | 68 | int receiveLine(char* szLine, int nMaxLen, int nTimeout = -1, char szLineTerm = '\n'); |
leihen | 0:7a2421e63e74 | 69 | |
leihen | 0:7a2421e63e74 | 70 | }; |
leihen | 0:7a2421e63e74 | 71 | |
leihen | 0:7a2421e63e74 | 72 | #endif // __HTTPConnection_H__ |