/* ScummVM - Graphic Adventure Engine * * ScummVM is the legal property of its developers, whose names * are too numerous to list here. Please refer to the COPYRIGHT * file distributed with this source distribution. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ #ifndef BACKENDS_NETWORKING_CURL_NETWORKREADSTREAM_H #define BACKENDS_NETWORKING_CURL_NETWORKREADSTREAM_H #include "common/memstream.h" #include "common/stream.h" #include "common/str.h" #include "common/hashmap.h" #include "common/hash-str.h" typedef void CURL; struct curl_slist; namespace Networking { class NetworkReadStream: public Common::ReadStream { CURL *_easy; Common::MemoryReadWriteStream _backingStream; bool _eos, _requestComplete; char *_errorBuffer; const byte *_sendingContentsBuffer; uint32 _sendingContentsSize; uint32 _sendingContentsPos; byte* _bufferCopy; // To use with old curl version where CURLOPT_COPYPOSTFIELDS is not available Common::String _responseHeaders; uint64 _progressDownloaded, _progressTotal; void init(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post); void init(const char *url, curl_slist *headersList, Common::HashMap formFields, Common::HashMap formFiles); /** * Fills the passed buffer with _sendingContentsBuffer contents. * It works similarly to read(), expect it's not for reading * Stream's contents, but for sending our own data to the server. * * @returns how many bytes were actually read (filled in) */ uint32 fillWithSendingContents(char *bufferToFill, uint32 maxSize); /** * Remembers headers returned to CURL in server's response. * * @returns how many bytes were actually read */ uint32 addResponseHeaders(char *buffer, uint32 bufferSize); static size_t curlDataCallback(char *d, size_t n, size_t l, void *p); static size_t curlReadDataCallback(char *d, size_t n, size_t l, void *p); static size_t curlHeadersCallback(char *d, size_t n, size_t l, void *p); static int curlProgressCallbackOlder(void *p, double dltotal, double dlnow, double ultotal, double ulnow); public: /** Send , using POST by default. */ NetworkReadStream(const char *url, curl_slist *headersList, Common::String postFields, bool uploading = false, bool usingPatch = false); /** Send , , using POST multipart/form. */ NetworkReadStream( const char *url, curl_slist *headersList, Common::HashMap formFields, Common::HashMap formFiles); /** Send responseHeadersMap() const; /** Returns a number in range [0, 1], where 1 is "complete". */ double getProgress() const; /** Used in curl progress callback to pass current downloaded/total values. */ void setProgress(uint64 downloaded, uint64 total); }; } // End of namespace Networking #endif