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 _eos, _requestComplete;
00041     const byte *_sendingContentsBuffer;
00042     uint32 _sendingContentsSize;
00043     uint32 _sendingContentsPos;
00044     byte* _bufferCopy; // To use with old curl version where CURLOPT_COPYPOSTFIELDS is not available
00045     Common::String _responseHeaders;
00046     uint64 _progressDownloaded, _progressTotal;
00047     void init(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post);
00048     void init(const char *url, curl_slist *headersList, Common::HashMap<Common::String, Common::String> formFields, Common::HashMap<Common::String, Common::String> formFiles);
00049 
00057     uint32 fillWithSendingContents(char *bufferToFill, uint32 maxSize);
00058 
00064     uint32 addResponseHeaders(char *buffer, uint32 bufferSize);
00065 
00066     static size_t curlDataCallback(char *d, size_t n, size_t l, void *p);
00067     static size_t curlReadDataCallback(char *d, size_t n, size_t l, void *p);
00068     static size_t curlHeadersCallback(char *d, size_t n, size_t l, void *p);
00069     static int curlProgressCallbackOlder(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
00070 public:
00072     NetworkReadStream(const char *url, curl_slist *headersList, Common::String postFields, bool uploading = false, bool usingPatch = false);
00074     NetworkReadStream(
00075         const char *url, curl_slist *headersList,
00076         Common::HashMap<Common::String, Common::String> formFields,
00077         Common::HashMap<Common::String, Common::String> formFiles);
00079     NetworkReadStream(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading = false, bool usingPatch = false, bool post = true);
00080     virtual ~NetworkReadStream();
00081 
00092     virtual bool eos() const;
00093 
00106     virtual uint32 read(void *dataPtr, uint32 dataSize);
00107 
00114     void finished();
00115 
00122     long httpResponseCode() const;
00123 
00130     Common::String currentLocation() const;
00131 
00137     Common::String responseHeaders() const;
00138 
00140     double getProgress() const;
00141 
00143     void setProgress(uint64 downloaded, uint64 total);
00144 };
00145 
00146 } // End of namespace Networking
00147 
00148 #endif


Generated on Sat Feb 9 2019 05:00:37 for ResidualVM by doxygen 1.7.1
curved edge   curved edge