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  static struct curl_slist *requestHeadersToSlist(const RequestHeaders *headersList);
49 
50  static size_t curlDataCallback(char *d, size_t n, size_t l, void *p);
51  static size_t curlReadDataCallback(char *d, size_t n, size_t l, void *p);
52  static size_t curlHeadersCallback(char *d, size_t n, size_t l, void *p);
53  static int curlProgressCallbackOlder(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
54 
55  // CURL-specific methods
56  CURL *getEasyHandle() const { return _easy; }
57  void resetStream();
58  void setupBufferContents(const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post);
59  void setupFormMultipart(const Common::HashMap<Common::String, Common::String> &formFields, const Common::HashMap<Common::String, Common::Path> &formFiles);
60 
61 public:
62  NetworkReadStreamCurl(const char *url, RequestHeaders *headersList, const Common::String &postFields, bool uploading, bool usingPatch, bool keepAlive, long keepAliveIdle, long keepAliveInterval);
63 
64  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);
65 
66  NetworkReadStreamCurl(const char *url, RequestHeaders *headersList, const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post, bool keepAlive, long keepAliveIdle, long keepAliveInterval);
67 
69  void finished(CURLcode errorCode);
70 
72  bool reuse(const char *url, RequestHeaders *headersList, const Common::String &postFields, bool uploading = false, bool usingPatch = false) override;
74  bool reuse(
75  const char *url, RequestHeaders *headersList,
77  const Common::HashMap<Common::String, Common::Path> &formFiles) override;
79  bool reuse(const char *url, RequestHeaders *headersList, const byte *buffer, uint32 bufferSize, bool uploading = false, bool usingPatch = false, bool post = true) override;
80 
81  long httpResponseCode() const override;
82  Common::String currentLocation() const override;
90 
91  bool hasError() const override;
92  const char *getError() const override;
93 };
94 
95 } // End of namespace Networking
96 
97 #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