Changes made for RPC
Embed:
(wiki syntax)
Show/hide line numbers
HTTPConnection.h
00001 /* HTTPConnection.h */ 00002 /* 00003 Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de) 00004 00005 Permission is hereby granted, free of charge, to any person obtaining a copy 00006 of this software and associated documentation files (the "Software"), to deal 00007 in the Software without restriction, including without limitation the rights 00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 copies of the Software, and to permit persons to whom the Software is 00010 furnished to do so, subject to the following conditions: 00011 00012 The above copyright notice and this permission notice shall be included in 00013 all copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 THE SOFTWARE. 00022 */ 00023 #ifndef __HTTPConnection_H__ 00024 #define __HTTPConnection_H__ 00025 00026 #include "mbed.h" 00027 #include "TCPSocketConnection.h" 00028 00029 #include <string> 00030 #include <map> 00031 00032 class HTTPServer; 00033 00034 /** Type HTTPRequestType enumerates request types 00035 */ 00036 typedef enum 00037 { 00038 HTTP_RT_GET, /*!< GET request */ 00039 HTTP_RT_POST, /*!< POST request */ 00040 HTTP_RT_PUT, /*!< PUT request */ 00041 HTTP_RT_OPTIONS, /*!< OPTIONS request */ 00042 HTTP_RT_HEAD, /*!< HEAD request */ 00043 HTTP_RT_DELETE, /*!< DELETE request */ 00044 HTTP_RT_TRACE, /*!< TRACE request */ 00045 HTTP_RT_CONNECT /*!< CONNECT request */ 00046 } HTTPRequestType; 00047 00048 /** class HTTPConnection, encapsulates one connection being made throught the HTTPServer 00049 * 00050 */ 00051 class HTTPConnection { 00052 public: 00053 00054 /** HTTPMessage contains all the details of the request received by external HTTP client. 00055 */ 00056 typedef struct 00057 { 00058 /** Specifies the request type received 00059 */ 00060 HTTPRequestType request; 00061 /** The uri associated with the request. 00062 */ 00063 std::string uri; 00064 /** Contains the HTTP/1.1 or HTTP/1.0 version requested by client. 00065 */ 00066 std::string version; 00067 /** Map of headers provided by the client in the form <HeaderName>:<HeaderValue> 00068 */ 00069 std::map<std::string, std::string> headers; 00070 /** Map of arguments that came with the uri string 00071 */ 00072 std::map<std::string, std::string> args; 00073 } HTTPMessage; 00074 00075 /** Public constructor for HTTPConnection objects. 00076 * 00077 */ 00078 HTTPConnection (TCPSocketConnection& clnt); 00079 00080 /** Destructor for HTTPConnection objects. 00081 * 00082 */ 00083 ~HTTPConnection(); 00084 00085 /** Query if this connection is already closed and can be deleted. 00086 @returns true, if connection is closed. 00087 */ 00088 bool is_closed(); 00089 00090 /** Polling function for the connection. 00091 * @returns -1 if connection is not required anymore. In the current version of this library this should be the normal case. This may change in future versions. 00092 */ 00093 int poll(); 00094 00095 protected: 00096 00097 /** Function to close this connection. To be called from internally. 00098 */ 00099 void close(); 00100 00101 friend class HTTPServer; 00102 00103 TCPSocketConnection m_Tcp; 00104 HTTPMessage m_Msg; 00105 00106 /** parse a HTTP request line from the content of the buffer. 00107 * @param buffer : the request received from the client in the form <RequestType> <uri> <Http Version> 00108 * @returns -1 if the request is invalid or 0 if the request is valid 00109 */ 00110 int parse(char *buffer); 00111 00112 /** parses the received string in \c buffer for HTTP request headers. 00113 * @param buffer : buffer which contains the string to parse for headers. 00114 * @returns -1 in case of an error, otherwise returns 0 00115 */ 00116 int parseHeader(char *buffer); 00117 int receiveHeaders(const char* buffer, int nBuffSize); 00118 00119 /** Function which receives a line from the current Socket 00120 * @param szline : will contain one line received from the socket 00121 * @param nMaxLen : the size of the buffer. If the line is longer than the buffer the line is cropped at the end. 00122 * @param nTimeout : if the timeout elapses, only the portion that has been received within this time will be returned. 00123 * @param szLineTerm : the \c end-of-line character to be used to detect the end of the line. 00124 * @returns -1 in case of an error or timeout, -2 in case of an empty line or the number of received characters. 00125 */ 00126 int receiveLine(char* szLine, int nMaxLen, int nTimeout = -1, char szLineTerm = '\n'); 00127 00128 00129 /** parse the receoved \c uri_string for arguments which will be stored in the \c args map. 00130 * @parse uri_string : the uri string which was received from the client. 00131 * @parse args : the args map which will receive the argument:value touples from the \c uri_string. 00132 * @returns -1 if an error occured, otherwise returns 0. 00133 */ 00134 int parseUriArgs(char *uri_string, map<string,string>& args); 00135 00136 }; 00137 00138 #endif // __HTTPConnection_H__
Generated on Mon Jul 18 2022 11:51:41 by
