ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

networkreadstream.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef BACKENDS_NETWORKING_CURL_NETWORKREADSTREAM_H
00024 #define BACKENDS_NETWORKING_CURL_NETWORKREADSTREAM_H
00025 
00026 #include "common/memstream.h"
00027 #include "common/stream.h"
00028 #include "common/str.h"
00029 #include "common/hashmap.h"
00030 #include "common/hash-str.h"
00031 
00032 typedef void CURL;
00033 struct curl_slist;
00034 
00035 namespace Networking {
00036 
00037 class NetworkReadStream: public Common::ReadStream {
00038     CURL *_easy;
00039     Common::MemoryReadWriteStream _backingStream;
00040     bool _keepAlive;
00041     long _keepAliveIdle, _keepAliveInterval;
00042     bool _eos, _requestComplete;
00043     char *_errorBuffer;
00044     const byte *_sendingContentsBuffer;
00045     uint32 _sendingContentsSize;
00046     uint32 _sendingContentsPos;
00047     byte *_bufferCopy; // To use with old curl version where CURLOPT_COPYPOSTFIELDS is not available
00048     Common::String _responseHeaders;
00049     uint64 _progressDownloaded, _progressTotal;
00050 
00051     void resetStream();
00052     void initCurl(const char *url, curl_slist *headersList);
00053     bool reuseCurl(const char *url, curl_slist *headersList);
00054     void setupBufferContents(const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post);
00055     void setupFormMultipart(Common::HashMap<Common::String, Common::String> formFields, Common::HashMap<Common::String, Common::String> formFiles);
00056 
00064     uint32 fillWithSendingContents(char *bufferToFill, uint32 maxSize);
00065 
00071     uint32 addResponseHeaders(char *buffer, uint32 bufferSize);
00072 
00073     static size_t curlDataCallback(char *d, size_t n, size_t l, void *p);
00074     static size_t curlReadDataCallback(char *d, size_t n, size_t l, void *p);
00075     static size_t curlHeadersCallback(char *d, size_t n, size_t l, void *p);
00076     static int curlProgressCallbackOlder(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
00077 public:
00079     NetworkReadStream(const char *url, curl_slist *headersList, Common::String postFields, bool uploading = false, bool usingPatch = false, bool keepAlive = false, long keepAliveIdle = 120, long keepAliveInterval = 60);
00081     NetworkReadStream(
00082         const char *url, curl_slist *headersList,
00083         Common::HashMap<Common::String, Common::String> formFields,
00084         Common::HashMap<Common::String, Common::String> formFiles,
00085         bool keepAlive = false, long keepAliveIdle = 120, long keepAliveInterval = 60);
00087     NetworkReadStream(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading = false, bool usingPatch = false, bool post = true, bool keepAlive = false, long keepAliveIdle = 120, long keepAliveInterval = 60);
00088     virtual ~NetworkReadStream();
00089 
00091     bool reuse(const char *url, curl_slist *headersList, Common::String postFields, bool uploading = false, bool usingPatch = false);
00093     bool reuse(
00094         const char *url, curl_slist *headersList,
00095         Common::HashMap<Common::String, Common::String> formFields,
00096         Common::HashMap<Common::String, Common::String> formFiles);
00098     bool reuse(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading = false, bool usingPatch = false, bool post = true);
00099 
00110     virtual bool eos() const;
00111 
00124     virtual uint32 read(void *dataPtr, uint32 dataSize);
00125 
00132     void finished(uint32 errorCode);
00133 
00140     long httpResponseCode() const;
00141 
00148     Common::String currentLocation() const;
00149 
00155     Common::String responseHeaders() const;
00156 
00163     Common::HashMap<Common::String, Common::String> responseHeadersMap() const;
00164 
00166     double getProgress() const;
00167 
00169     void setProgress(uint64 downloaded, uint64 total);
00170 
00171     bool keepAlive() const { return _keepAlive; }
00172 };
00173 
00174 } // End of namespace Networking
00175 
00176 #endif


Generated on Sat May 30 2020 05:00:33 for ResidualVM by doxygen 1.7.1
curved edge   curved edge