Mbed asked me to commit the library. Probably because it's an older version
Fork of HTTPServer by
Diff: HTTPConnection.h
- Revision:
- 4:d065642c32cc
- Parent:
- 3:d6224049b3bf
- Child:
- 13:aa5338a5e452
--- a/HTTPConnection.h Tue May 28 01:56:14 2013 +0000 +++ b/HTTPConnection.h Tue May 28 21:20:58 2013 +0000 @@ -45,7 +45,6 @@ HTTP_RT_CONNECT /*!< CONNECT request */ } HTTPRequestType; - /** class HTTPConnection, encapsulates one connection being made throught the HTTPServer * */ @@ -58,17 +57,21 @@ { /** Specifies the request type received */ - HTTPRequestType request; + HTTPRequestType request; /** The uri associated with the request. */ - std::string uri; + std::string uri; /** Contains the HTTP/1.1 or HTTP/1.0 version requested by client. */ - std::string version; + std::string version; /** Map of headers provided by the client in the form <HeaderName>:<HeaderValue> */ - std::map<std::string, std::string> headers; + std::map<std::string, std::string> headers; + /** Map of arguments that came with the uri string + */ + std::map<std::string, std::string> args; } HTTPMessage; + /** Public constructor for HTTPConnection objects. * */ @@ -99,11 +102,37 @@ TCPSocketConnection m_Tcp; HTTPMessage m_Msg; + + /** parse a HTTP request line from the content of the buffer. + * @param buffer : the request received from the client in the form <RequestType> <uri> <Http Version> + * @returns -1 if the request is invalid or 0 if the request is valid + */ int parse(char *buffer); + + /** parses the received string in \c buffer for HTTP request headers. + * @param buffer : buffer which contains the string to parse for headers. + * @returns -1 in case of an error, otherwise returns 0 + */ int parseHeader(char *buffer); int receiveHeaders(const char* buffer, int nBuffSize); + + /** Function which receives a line from the current Socket + * @param szline : will contain one line received from the socket + * @param nMaxLen : the size of the buffer. If the line is longer than the buffer the line is cropped at the end. + * @param nTimeout : if the timeout elapses, only the portion that has been received within this time will be returned. + * @param szLineTerm : the \c end-of-line character to be used to detect the end of the line. + * @returns -1 in case of an error or timeout, -2 in case of an empty line or the number of received characters. + */ int receiveLine(char* szLine, int nMaxLen, int nTimeout = -1, char szLineTerm = '\n'); + + /** parse the receoved \c uri_string for arguments which will be stored in the \c args map. + * @parse uri_string : the uri string which was received from the client. + * @parse args : the args map which will receive the argument:value touples from the \c uri_string. + * @returns -1 if an error occured, otherwise returns 0. + */ + int parseUriArgs(char *uri_string, map<string,string>& args); + }; #endif // __HTTPConnection_H__ \ No newline at end of file