Read NTP time from Ethernet and drive six 7-segment LEDs using a MAX7221 to show time, date, month, week, year etc....
Dependencies: NTPClient_NetServices mbed
LPC1768/services/http/client/HTTPClient.h@0:e083abcfe7a8, 2011-06-22 (annotated)
- Committer:
- cheungderek
- Date:
- Wed Jun 22 01:31:47 2011 +0000
- Revision:
- 0:e083abcfe7a8
First release.
Just some testing but working code to read NTP time and drive 6 LEDs to display time, date, month, year etc...
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cheungderek | 0:e083abcfe7a8 | 1 | |
cheungderek | 0:e083abcfe7a8 | 2 | /* |
cheungderek | 0:e083abcfe7a8 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
cheungderek | 0:e083abcfe7a8 | 4 | |
cheungderek | 0:e083abcfe7a8 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
cheungderek | 0:e083abcfe7a8 | 6 | of this software and associated documentation files (the "Software"), to deal |
cheungderek | 0:e083abcfe7a8 | 7 | in the Software without restriction, including without limitation the rights |
cheungderek | 0:e083abcfe7a8 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
cheungderek | 0:e083abcfe7a8 | 9 | copies of the Software, and to permit persons to whom the Software is |
cheungderek | 0:e083abcfe7a8 | 10 | furnished to do so, subject to the following conditions: |
cheungderek | 0:e083abcfe7a8 | 11 | |
cheungderek | 0:e083abcfe7a8 | 12 | The above copyright notice and this permission notice shall be included in |
cheungderek | 0:e083abcfe7a8 | 13 | all copies or substantial portions of the Software. |
cheungderek | 0:e083abcfe7a8 | 14 | |
cheungderek | 0:e083abcfe7a8 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
cheungderek | 0:e083abcfe7a8 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
cheungderek | 0:e083abcfe7a8 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
cheungderek | 0:e083abcfe7a8 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
cheungderek | 0:e083abcfe7a8 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
cheungderek | 0:e083abcfe7a8 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
cheungderek | 0:e083abcfe7a8 | 21 | THE SOFTWARE. |
cheungderek | 0:e083abcfe7a8 | 22 | */ |
cheungderek | 0:e083abcfe7a8 | 23 | |
cheungderek | 0:e083abcfe7a8 | 24 | /** \file |
cheungderek | 0:e083abcfe7a8 | 25 | HTTP Client header file |
cheungderek | 0:e083abcfe7a8 | 26 | */ |
cheungderek | 0:e083abcfe7a8 | 27 | |
cheungderek | 0:e083abcfe7a8 | 28 | #ifndef HTTP_CLIENT_H |
cheungderek | 0:e083abcfe7a8 | 29 | #define HTTP_CLIENT_H |
cheungderek | 0:e083abcfe7a8 | 30 | |
cheungderek | 0:e083abcfe7a8 | 31 | class HTTPData; |
cheungderek | 0:e083abcfe7a8 | 32 | |
cheungderek | 0:e083abcfe7a8 | 33 | #include "core/net.h" |
cheungderek | 0:e083abcfe7a8 | 34 | #include "api/TCPSocket.h" |
cheungderek | 0:e083abcfe7a8 | 35 | #include "api/DNSRequest.h" |
cheungderek | 0:e083abcfe7a8 | 36 | #include "HTTPData.h" |
cheungderek | 0:e083abcfe7a8 | 37 | #include "mbed.h" |
cheungderek | 0:e083abcfe7a8 | 38 | |
cheungderek | 0:e083abcfe7a8 | 39 | #include <string> |
cheungderek | 0:e083abcfe7a8 | 40 | using std::string; |
cheungderek | 0:e083abcfe7a8 | 41 | |
cheungderek | 0:e083abcfe7a8 | 42 | #include <map> |
cheungderek | 0:e083abcfe7a8 | 43 | using std::map; |
cheungderek | 0:e083abcfe7a8 | 44 | |
cheungderek | 0:e083abcfe7a8 | 45 | ///HTTP client results |
cheungderek | 0:e083abcfe7a8 | 46 | enum HTTPResult |
cheungderek | 0:e083abcfe7a8 | 47 | { |
cheungderek | 0:e083abcfe7a8 | 48 | HTTP_OK, ///<Success |
cheungderek | 0:e083abcfe7a8 | 49 | HTTP_PROCESSING, ///<Processing |
cheungderek | 0:e083abcfe7a8 | 50 | HTTP_PARSE, ///<URI Parse error |
cheungderek | 0:e083abcfe7a8 | 51 | HTTP_DNS, ///<Could not resolve name |
cheungderek | 0:e083abcfe7a8 | 52 | HTTP_PRTCL, ///<Protocol error |
cheungderek | 0:e083abcfe7a8 | 53 | HTTP_NOTFOUND, ///<HTTP 404 Error |
cheungderek | 0:e083abcfe7a8 | 54 | HTTP_REFUSED, ///<HTTP 403 Error |
cheungderek | 0:e083abcfe7a8 | 55 | HTTP_ERROR, ///<HTTP xxx error |
cheungderek | 0:e083abcfe7a8 | 56 | HTTP_TIMEOUT, ///<Connection timeout |
cheungderek | 0:e083abcfe7a8 | 57 | HTTP_CONN ///<Connection error |
cheungderek | 0:e083abcfe7a8 | 58 | }; |
cheungderek | 0:e083abcfe7a8 | 59 | |
cheungderek | 0:e083abcfe7a8 | 60 | #include "core/netservice.h" |
cheungderek | 0:e083abcfe7a8 | 61 | |
cheungderek | 0:e083abcfe7a8 | 62 | ///A simple HTTP Client |
cheungderek | 0:e083abcfe7a8 | 63 | /** |
cheungderek | 0:e083abcfe7a8 | 64 | The HTTPClient is composed of: |
cheungderek | 0:e083abcfe7a8 | 65 | - The actual client (HTTPClient) |
cheungderek | 0:e083abcfe7a8 | 66 | - Classes that act as a data repository, each of which deriving from the HTTPData class (HTTPText for short text content, HTTPFile for file I/O, HTTPMap for key/value pairs, and HTTPStream for streaming purposes) |
cheungderek | 0:e083abcfe7a8 | 67 | */ |
cheungderek | 0:e083abcfe7a8 | 68 | class HTTPClient : protected NetService |
cheungderek | 0:e083abcfe7a8 | 69 | { |
cheungderek | 0:e083abcfe7a8 | 70 | public: |
cheungderek | 0:e083abcfe7a8 | 71 | ///Instantiates the HTTP client |
cheungderek | 0:e083abcfe7a8 | 72 | HTTPClient(); |
cheungderek | 0:e083abcfe7a8 | 73 | virtual ~HTTPClient(); |
cheungderek | 0:e083abcfe7a8 | 74 | |
cheungderek | 0:e083abcfe7a8 | 75 | ///Provides a basic authentification feature (Base64 encoded username and password) |
cheungderek | 0:e083abcfe7a8 | 76 | void basicAuth(const char* user, const char* password); //Basic Authentification |
cheungderek | 0:e083abcfe7a8 | 77 | |
cheungderek | 0:e083abcfe7a8 | 78 | //High Level setup functions |
cheungderek | 0:e083abcfe7a8 | 79 | ///Executes a GET Request (blocking) |
cheungderek | 0:e083abcfe7a8 | 80 | /** |
cheungderek | 0:e083abcfe7a8 | 81 | Executes a GET request on the URI uri |
cheungderek | 0:e083abcfe7a8 | 82 | @param uri : URI on which to execute the request |
cheungderek | 0:e083abcfe7a8 | 83 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
cheungderek | 0:e083abcfe7a8 | 84 | Blocks until completion |
cheungderek | 0:e083abcfe7a8 | 85 | */ |
cheungderek | 0:e083abcfe7a8 | 86 | HTTPResult get(const char* uri, HTTPData* pDataIn); //Blocking |
cheungderek | 0:e083abcfe7a8 | 87 | |
cheungderek | 0:e083abcfe7a8 | 88 | ///Executes a GET Request (non blocking) |
cheungderek | 0:e083abcfe7a8 | 89 | /** |
cheungderek | 0:e083abcfe7a8 | 90 | Executes a GET request on the URI uri |
cheungderek | 0:e083abcfe7a8 | 91 | @param uri : URI on which to execute the request |
cheungderek | 0:e083abcfe7a8 | 92 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
cheungderek | 0:e083abcfe7a8 | 93 | @param pMethod : callback function |
cheungderek | 0:e083abcfe7a8 | 94 | The function returns immediately and calls the callback on completion or error |
cheungderek | 0:e083abcfe7a8 | 95 | */ |
cheungderek | 0:e083abcfe7a8 | 96 | HTTPResult get(const char* uri, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking |
cheungderek | 0:e083abcfe7a8 | 97 | |
cheungderek | 0:e083abcfe7a8 | 98 | ///Executes a GET Request (non blocking) |
cheungderek | 0:e083abcfe7a8 | 99 | /** |
cheungderek | 0:e083abcfe7a8 | 100 | Executes a GET request on the URI uri |
cheungderek | 0:e083abcfe7a8 | 101 | @param uri : URI on which to execute the request |
cheungderek | 0:e083abcfe7a8 | 102 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
cheungderek | 0:e083abcfe7a8 | 103 | @param pItem : instance of class on which to execute the callback method |
cheungderek | 0:e083abcfe7a8 | 104 | @param pMethod : callback method |
cheungderek | 0:e083abcfe7a8 | 105 | The function returns immediately and calls the callback on completion or error |
cheungderek | 0:e083abcfe7a8 | 106 | */ |
cheungderek | 0:e083abcfe7a8 | 107 | template<class T> |
cheungderek | 0:e083abcfe7a8 | 108 | HTTPResult get(const char* uri, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking |
cheungderek | 0:e083abcfe7a8 | 109 | { |
cheungderek | 0:e083abcfe7a8 | 110 | setOnResult(pItem, pMethod); |
cheungderek | 0:e083abcfe7a8 | 111 | doGet(uri, pDataIn); |
cheungderek | 0:e083abcfe7a8 | 112 | return HTTP_PROCESSING; |
cheungderek | 0:e083abcfe7a8 | 113 | } |
cheungderek | 0:e083abcfe7a8 | 114 | |
cheungderek | 0:e083abcfe7a8 | 115 | ///Executes a POST Request (blocking) |
cheungderek | 0:e083abcfe7a8 | 116 | /** |
cheungderek | 0:e083abcfe7a8 | 117 | Executes a POST request on the URI uri |
cheungderek | 0:e083abcfe7a8 | 118 | @param uri : URI on which to execute the request |
cheungderek | 0:e083abcfe7a8 | 119 | @param dataOut : a HTTPData instance that contains the data that will be posted |
cheungderek | 0:e083abcfe7a8 | 120 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
cheungderek | 0:e083abcfe7a8 | 121 | Blocks until completion |
cheungderek | 0:e083abcfe7a8 | 122 | */ |
cheungderek | 0:e083abcfe7a8 | 123 | HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); //Blocking |
cheungderek | 0:e083abcfe7a8 | 124 | |
cheungderek | 0:e083abcfe7a8 | 125 | ///Executes a POST Request (non blocking) |
cheungderek | 0:e083abcfe7a8 | 126 | /** |
cheungderek | 0:e083abcfe7a8 | 127 | Executes a POST request on the URI uri |
cheungderek | 0:e083abcfe7a8 | 128 | @param uri : URI on which to execute the request |
cheungderek | 0:e083abcfe7a8 | 129 | @param dataOut : a HTTPData instance that contains the data that will be posted |
cheungderek | 0:e083abcfe7a8 | 130 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
cheungderek | 0:e083abcfe7a8 | 131 | @param pMethod : callback function |
cheungderek | 0:e083abcfe7a8 | 132 | The function returns immediately and calls the callback on completion or error |
cheungderek | 0:e083abcfe7a8 | 133 | */ |
cheungderek | 0:e083abcfe7a8 | 134 | HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, void (*pMethod)(HTTPResult)); //Non blocking |
cheungderek | 0:e083abcfe7a8 | 135 | |
cheungderek | 0:e083abcfe7a8 | 136 | ///Executes a POST Request (non blocking) |
cheungderek | 0:e083abcfe7a8 | 137 | /** |
cheungderek | 0:e083abcfe7a8 | 138 | Executes a POST request on the URI uri |
cheungderek | 0:e083abcfe7a8 | 139 | @param uri : URI on which to execute the request |
cheungderek | 0:e083abcfe7a8 | 140 | @param dataOut : a HTTPData instance that contains the data that will be posted |
cheungderek | 0:e083abcfe7a8 | 141 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
cheungderek | 0:e083abcfe7a8 | 142 | @param pItem : instance of class on which to execute the callback method |
cheungderek | 0:e083abcfe7a8 | 143 | @param pMethod : callback method |
cheungderek | 0:e083abcfe7a8 | 144 | The function returns immediately and calls the callback on completion or error |
cheungderek | 0:e083abcfe7a8 | 145 | */ |
cheungderek | 0:e083abcfe7a8 | 146 | template<class T> |
cheungderek | 0:e083abcfe7a8 | 147 | HTTPResult post(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn, T* pItem, void (T::*pMethod)(HTTPResult)) //Non blocking |
cheungderek | 0:e083abcfe7a8 | 148 | { |
cheungderek | 0:e083abcfe7a8 | 149 | setOnResult(pItem, pMethod); |
cheungderek | 0:e083abcfe7a8 | 150 | doPost(uri, dataOut, pDataIn); |
cheungderek | 0:e083abcfe7a8 | 151 | return HTTP_PROCESSING; |
cheungderek | 0:e083abcfe7a8 | 152 | } |
cheungderek | 0:e083abcfe7a8 | 153 | |
cheungderek | 0:e083abcfe7a8 | 154 | ///Executes a GET Request (non blocking) |
cheungderek | 0:e083abcfe7a8 | 155 | /** |
cheungderek | 0:e083abcfe7a8 | 156 | Executes a GET request on the URI uri |
cheungderek | 0:e083abcfe7a8 | 157 | @param uri : URI on which to execute the request |
cheungderek | 0:e083abcfe7a8 | 158 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
cheungderek | 0:e083abcfe7a8 | 159 | The function returns immediately and calls the previously set callback on completion or error |
cheungderek | 0:e083abcfe7a8 | 160 | */ |
cheungderek | 0:e083abcfe7a8 | 161 | void doGet(const char* uri, HTTPData* pDataIn); |
cheungderek | 0:e083abcfe7a8 | 162 | |
cheungderek | 0:e083abcfe7a8 | 163 | ///Executes a POST Request (non blocking) |
cheungderek | 0:e083abcfe7a8 | 164 | /** |
cheungderek | 0:e083abcfe7a8 | 165 | Executes a POST request on the URI uri |
cheungderek | 0:e083abcfe7a8 | 166 | @param uri : URI on which to execute the request |
cheungderek | 0:e083abcfe7a8 | 167 | @param dataOut : a HTTPData instance that contains the data that will be posted |
cheungderek | 0:e083abcfe7a8 | 168 | @param pDataIn : pointer to an HTTPData instance that will collect the data returned by the request, can be NULL |
cheungderek | 0:e083abcfe7a8 | 169 | @param pMethod : callback function |
cheungderek | 0:e083abcfe7a8 | 170 | The function returns immediately and calls the previously set callback on completion or error |
cheungderek | 0:e083abcfe7a8 | 171 | */ |
cheungderek | 0:e083abcfe7a8 | 172 | void doPost(const char* uri, const HTTPData& dataOut, HTTPData* pDataIn); |
cheungderek | 0:e083abcfe7a8 | 173 | |
cheungderek | 0:e083abcfe7a8 | 174 | ///Setups the result callback |
cheungderek | 0:e083abcfe7a8 | 175 | /** |
cheungderek | 0:e083abcfe7a8 | 176 | @param pMethod : callback function |
cheungderek | 0:e083abcfe7a8 | 177 | */ |
cheungderek | 0:e083abcfe7a8 | 178 | void setOnResult( void (*pMethod)(HTTPResult) ); |
cheungderek | 0:e083abcfe7a8 | 179 | |
cheungderek | 0:e083abcfe7a8 | 180 | ///Setups the result callback |
cheungderek | 0:e083abcfe7a8 | 181 | /** |
cheungderek | 0:e083abcfe7a8 | 182 | @param pItem : instance of class on which to execute the callback method |
cheungderek | 0:e083abcfe7a8 | 183 | @param pMethod : callback method |
cheungderek | 0:e083abcfe7a8 | 184 | */ |
cheungderek | 0:e083abcfe7a8 | 185 | class CDummy; |
cheungderek | 0:e083abcfe7a8 | 186 | template<class T> |
cheungderek | 0:e083abcfe7a8 | 187 | void setOnResult( T* pItem, void (T::*pMethod)(HTTPResult) ) |
cheungderek | 0:e083abcfe7a8 | 188 | { |
cheungderek | 0:e083abcfe7a8 | 189 | m_pCb = NULL; |
cheungderek | 0:e083abcfe7a8 | 190 | m_pCbItem = (CDummy*) pItem; |
cheungderek | 0:e083abcfe7a8 | 191 | m_pCbMeth = (void (CDummy::*)(HTTPResult)) pMethod; |
cheungderek | 0:e083abcfe7a8 | 192 | } |
cheungderek | 0:e083abcfe7a8 | 193 | |
cheungderek | 0:e083abcfe7a8 | 194 | ///Setups timeout |
cheungderek | 0:e083abcfe7a8 | 195 | /** |
cheungderek | 0:e083abcfe7a8 | 196 | @param ms : time of connection inactivity in ms after which the request should timeout |
cheungderek | 0:e083abcfe7a8 | 197 | */ |
cheungderek | 0:e083abcfe7a8 | 198 | void setTimeout(int ms); |
cheungderek | 0:e083abcfe7a8 | 199 | |
cheungderek | 0:e083abcfe7a8 | 200 | virtual void poll(); //Called by NetServices |
cheungderek | 0:e083abcfe7a8 | 201 | |
cheungderek | 0:e083abcfe7a8 | 202 | ///Gets last request's HTTP response code |
cheungderek | 0:e083abcfe7a8 | 203 | /** |
cheungderek | 0:e083abcfe7a8 | 204 | @return The HTTP response code of the last request |
cheungderek | 0:e083abcfe7a8 | 205 | */ |
cheungderek | 0:e083abcfe7a8 | 206 | int getHTTPResponseCode(); |
cheungderek | 0:e083abcfe7a8 | 207 | |
cheungderek | 0:e083abcfe7a8 | 208 | ///Sets a specific request header |
cheungderek | 0:e083abcfe7a8 | 209 | void setRequestHeader(const string& header, const string& value); |
cheungderek | 0:e083abcfe7a8 | 210 | |
cheungderek | 0:e083abcfe7a8 | 211 | ///Gets a response header |
cheungderek | 0:e083abcfe7a8 | 212 | string& getResponseHeader(const string& header); |
cheungderek | 0:e083abcfe7a8 | 213 | |
cheungderek | 0:e083abcfe7a8 | 214 | ///Clears request headers |
cheungderek | 0:e083abcfe7a8 | 215 | void resetRequestHeaders(); |
cheungderek | 0:e083abcfe7a8 | 216 | |
cheungderek | 0:e083abcfe7a8 | 217 | protected: |
cheungderek | 0:e083abcfe7a8 | 218 | void resetTimeout(); |
cheungderek | 0:e083abcfe7a8 | 219 | |
cheungderek | 0:e083abcfe7a8 | 220 | void init(); |
cheungderek | 0:e083abcfe7a8 | 221 | void close(); |
cheungderek | 0:e083abcfe7a8 | 222 | |
cheungderek | 0:e083abcfe7a8 | 223 | void setup(const char* uri, HTTPData* pDataOut, HTTPData* pDataIn); //Setup request, make DNS Req if necessary |
cheungderek | 0:e083abcfe7a8 | 224 | void connect(); //Start Connection |
cheungderek | 0:e083abcfe7a8 | 225 | |
cheungderek | 0:e083abcfe7a8 | 226 | int tryRead(); //Read data and try to feed output |
cheungderek | 0:e083abcfe7a8 | 227 | void readData(); //Data has been read |
cheungderek | 0:e083abcfe7a8 | 228 | void writeData(); //Data has been written & buf is free |
cheungderek | 0:e083abcfe7a8 | 229 | |
cheungderek | 0:e083abcfe7a8 | 230 | void onTCPSocketEvent(TCPSocketEvent e); |
cheungderek | 0:e083abcfe7a8 | 231 | void onDNSReply(DNSReply r); |
cheungderek | 0:e083abcfe7a8 | 232 | void onResult(HTTPResult r); //Called when exchange completed or on failure |
cheungderek | 0:e083abcfe7a8 | 233 | void onTimeout(); //Connection has timed out |
cheungderek | 0:e083abcfe7a8 | 234 | |
cheungderek | 0:e083abcfe7a8 | 235 | private: |
cheungderek | 0:e083abcfe7a8 | 236 | HTTPResult blockingProcess(); //Called in blocking mode, calls Net::poll() until return code is available |
cheungderek | 0:e083abcfe7a8 | 237 | |
cheungderek | 0:e083abcfe7a8 | 238 | bool readHeaders(); //Called first when receiving data |
cheungderek | 0:e083abcfe7a8 | 239 | bool writeHeaders(); //Called to create req |
cheungderek | 0:e083abcfe7a8 | 240 | int readLine(char* str, int maxLen, bool* pIncomplete = NULL); |
cheungderek | 0:e083abcfe7a8 | 241 | |
cheungderek | 0:e083abcfe7a8 | 242 | enum HTTP_METH |
cheungderek | 0:e083abcfe7a8 | 243 | { |
cheungderek | 0:e083abcfe7a8 | 244 | HTTP_GET, |
cheungderek | 0:e083abcfe7a8 | 245 | HTTP_POST, |
cheungderek | 0:e083abcfe7a8 | 246 | HTTP_HEAD |
cheungderek | 0:e083abcfe7a8 | 247 | }; |
cheungderek | 0:e083abcfe7a8 | 248 | |
cheungderek | 0:e083abcfe7a8 | 249 | HTTP_METH m_meth; |
cheungderek | 0:e083abcfe7a8 | 250 | |
cheungderek | 0:e083abcfe7a8 | 251 | CDummy* m_pCbItem; |
cheungderek | 0:e083abcfe7a8 | 252 | void (CDummy::*m_pCbMeth)(HTTPResult); |
cheungderek | 0:e083abcfe7a8 | 253 | |
cheungderek | 0:e083abcfe7a8 | 254 | void (*m_pCb)(HTTPResult); |
cheungderek | 0:e083abcfe7a8 | 255 | |
cheungderek | 0:e083abcfe7a8 | 256 | TCPSocket* m_pTCPSocket; |
cheungderek | 0:e083abcfe7a8 | 257 | map<string, string> m_reqHeaders; |
cheungderek | 0:e083abcfe7a8 | 258 | map<string, string> m_respHeaders; |
cheungderek | 0:e083abcfe7a8 | 259 | |
cheungderek | 0:e083abcfe7a8 | 260 | Timer m_watchdog; |
cheungderek | 0:e083abcfe7a8 | 261 | int m_timeout; |
cheungderek | 0:e083abcfe7a8 | 262 | |
cheungderek | 0:e083abcfe7a8 | 263 | DNSRequest* m_pDnsReq; |
cheungderek | 0:e083abcfe7a8 | 264 | |
cheungderek | 0:e083abcfe7a8 | 265 | Host m_server; |
cheungderek | 0:e083abcfe7a8 | 266 | string m_path; |
cheungderek | 0:e083abcfe7a8 | 267 | |
cheungderek | 0:e083abcfe7a8 | 268 | bool m_closed; |
cheungderek | 0:e083abcfe7a8 | 269 | |
cheungderek | 0:e083abcfe7a8 | 270 | enum HTTPStep |
cheungderek | 0:e083abcfe7a8 | 271 | { |
cheungderek | 0:e083abcfe7a8 | 272 | // HTTP_INIT, |
cheungderek | 0:e083abcfe7a8 | 273 | HTTP_WRITE_HEADERS, |
cheungderek | 0:e083abcfe7a8 | 274 | HTTP_WRITE_DATA, |
cheungderek | 0:e083abcfe7a8 | 275 | HTTP_READ_HEADERS, |
cheungderek | 0:e083abcfe7a8 | 276 | HTTP_READ_DATA, |
cheungderek | 0:e083abcfe7a8 | 277 | HTTP_READ_DATA_INCOMPLETE, |
cheungderek | 0:e083abcfe7a8 | 278 | HTTP_DONE, |
cheungderek | 0:e083abcfe7a8 | 279 | HTTP_CLOSED |
cheungderek | 0:e083abcfe7a8 | 280 | }; |
cheungderek | 0:e083abcfe7a8 | 281 | |
cheungderek | 0:e083abcfe7a8 | 282 | HTTPStep m_state; |
cheungderek | 0:e083abcfe7a8 | 283 | |
cheungderek | 0:e083abcfe7a8 | 284 | HTTPData* m_pDataOut; |
cheungderek | 0:e083abcfe7a8 | 285 | HTTPData* m_pDataIn; |
cheungderek | 0:e083abcfe7a8 | 286 | |
cheungderek | 0:e083abcfe7a8 | 287 | bool m_dataChunked; //Data is encoded as chunks |
cheungderek | 0:e083abcfe7a8 | 288 | int m_dataPos; //Position in data |
cheungderek | 0:e083abcfe7a8 | 289 | int m_dataLen; //Data length |
cheungderek | 0:e083abcfe7a8 | 290 | char* m_buf; |
cheungderek | 0:e083abcfe7a8 | 291 | char* m_pBufRemaining; //Remaining |
cheungderek | 0:e083abcfe7a8 | 292 | int m_bufRemainingLen; //Data length in m_pBufRemaining |
cheungderek | 0:e083abcfe7a8 | 293 | |
cheungderek | 0:e083abcfe7a8 | 294 | int m_httpResponseCode; |
cheungderek | 0:e083abcfe7a8 | 295 | |
cheungderek | 0:e083abcfe7a8 | 296 | HTTPResult m_blockingResult; //Result if blocking mode |
cheungderek | 0:e083abcfe7a8 | 297 | |
cheungderek | 0:e083abcfe7a8 | 298 | }; |
cheungderek | 0:e083abcfe7a8 | 299 | |
cheungderek | 0:e083abcfe7a8 | 300 | //Including data containers here for more convenience |
cheungderek | 0:e083abcfe7a8 | 301 | #include "data/HTTPFile.h" |
cheungderek | 0:e083abcfe7a8 | 302 | #include "data/HTTPStream.h" |
cheungderek | 0:e083abcfe7a8 | 303 | #include "data/HTTPText.h" |
cheungderek | 0:e083abcfe7a8 | 304 | #include "data/HTTPMap.h" |
cheungderek | 0:e083abcfe7a8 | 305 | |
cheungderek | 0:e083abcfe7a8 | 306 | #endif |