Copy of NetServicesMin with the HTTP Client library. Includes modification for HTTP servers which send the HTTP status line in its own packet.

Committer:
andrewbonney
Date:
Thu May 26 10:02:40 2011 +0000
Revision:
0:18dd877d2c77

        

Who changed what in which revision?

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