ScummVM API documentation
networkreadstream-curl.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BACKENDS_NETWORKING_HTTP_CURL_NETWORKREADSTREAMCURL_H
23 #define BACKENDS_NETWORKING_HTTP_CURL_NETWORKREADSTREAMCURL_H
24 
25 #define FORBIDDEN_SYMBOL_ALLOW_ALL
26 
27 #include "backends/networking/http/networkreadstream.h"
28 #include "common/hash-str.h"
29 #include "common/hashmap.h"
30 #include "common/memstream.h"
31 #include "common/path.h"
32 #include "common/str.h"
33 #include "common/stream.h"
34 
35 #include <curl/curl.h>
36 
37 namespace Networking {
38 
40 private:
41  CURL *_easy;
42  struct curl_slist *_headersSlist;
43  char *_errorBuffer;
44  CURLcode _errorCode;
45  byte *_bufferCopy; // To use with old curl version where CURLOPT_COPYPOSTFIELDS is not available
46  void initCurl(const char *url, RequestHeaders *headersList);
47  bool reuseCurl(const char *url, RequestHeaders *headersList);
48  void setupBufferContents(const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post) override;
49  void setupFormMultipart(const Common::HashMap<Common::String, Common::String> &formFields, const Common::HashMap<Common::String, Common::Path> &formFiles) override;
50  static struct curl_slist *requestHeadersToSlist(const RequestHeaders *headersList);
51 
52  static size_t curlDataCallback(char *d, size_t n, size_t l, void *p);
53  static size_t curlReadDataCallback(char *d, size_t n, size_t l, void *p);
54  static size_t curlHeadersCallback(char *d, size_t n, size_t l, void *p);
55  static int curlProgressCallbackOlder(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
56 
57  // CURL-specific methods
58  CURL *getEasyHandle() const { return _easy; }
59 
60 public:
61  NetworkReadStreamCurl(const char *url, RequestHeaders *headersList, const Common::String &postFields, bool uploading, bool usingPatch, bool keepAlive, long keepAliveIdle, long keepAliveInterval);
62 
63  NetworkReadStreamCurl(const char *url, RequestHeaders *headersList, const Common::HashMap<Common::String, Common::String> &formFields, const Common::HashMap<Common::String, Common::Path> &formFiles, bool keepAlive, long keepAliveIdle, long keepAliveInterval);
64 
65  NetworkReadStreamCurl(const char *url, RequestHeaders *headersList, const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post, bool keepAlive, long keepAliveIdle, long keepAliveInterval);
66 
68  void finished(CURLcode errorCode);
69 
71  bool reuse(const char *url, RequestHeaders *headersList, const Common::String &postFields, bool uploading = false, bool usingPatch = false) override;
73  bool reuse(
74  const char *url, RequestHeaders *headersList,
76  const Common::HashMap<Common::String, Common::Path> &formFiles) override;
78  bool reuse(const char *url, RequestHeaders *headersList, const byte *buffer, uint32 bufferSize, bool uploading = false, bool usingPatch = false, bool post = true) override;
79 
80  void resetStream() override;
81 
82  long httpResponseCode() const override;
83  Common::String currentLocation() const override;
91 
92  bool hasError() const override;
93  const char *getError() const override;
94 };
95 
96 } // End of namespace Networking
97 
98 #endif
Definition: str.h:59
Definition: scummvmcloud.h:32
bool reuse(const char *url, RequestHeaders *headersList, const Common::String &postFields, bool uploading=false, bool usingPatch=false) override
long httpResponseCode() const override
Definition: networkreadstream-curl.h:39
Common::HashMap< Common::String, Common::String > responseHeadersMap() const override
Definition: networkreadstream.h:37
Common::String currentLocation() const override