KiCad PCB EDA Suite
Loading...
Searching...
No Matches
kicad_curl_easy.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2015 Mark Roszko <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (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 <https://www.gnu.org/licenses/>.
19 */
20#ifndef KICAD_CURL_EASY_H_
21#define KICAD_CURL_EASY_H_
22
23/*
24 * curl.h, and therefore kicad_curl.h must be included before wxWidgets headers because on Windows,
25 * wxWidgets ends up including windows.h before winsocks2.h
26 * curl and curl.h causes build warnings if included before any wxxxx.h
27 *
28 * So kicad_curl_easy.h does not include curl.h to avoid constraints,
29 * and including kicad_curl.h could be needed in a few sources
30 */
31
32#include <kicommon.h>
33#include <functional>
34#include <memory>
35#include <ostream>
36#include <string>
37#include <cstdint>
38#include <shared_mutex>
39
40typedef void CURL;
41struct curl_slist;
42
59
60
61typedef std::function<int( size_t, size_t, size_t, size_t )> TRANSFER_CALLBACK;
62struct CURL_PROGRESS;
63
64
66{
67public:
70
74 int Perform();
75
82 void SetHeader( const std::string& aName, const std::string& aValue );
83
90 bool SetUserAgent( const std::string& aAgent );
91
98 bool SetPostFields( const std::vector<std::pair<std::string, std::string>>& aFields );
99
107 bool SetPostFields( const std::string& aField );
108
115 bool SetURL( const std::string& aURL );
116
124 bool SetFollowRedirects( bool aFollow );
125
132 const std::string GetErrorText( int aCode );
133
134 int GetTransferTotal( uint64_t& aDownloadedBytes ) const;
135
139 const std::string& GetBuffer() { return m_buffer; }
140
142 std::string Escape( const std::string& aUrl );
143
144 bool SetTransferCallback( const TRANSFER_CALLBACK& aCallback, size_t aInterval );
145
146 bool SetOutputStream( const std::ostream* aOutput );
147
157 bool SetConnectTimeout( long aTimeoutSecs );
158
171 bool SetTimeout( long aTimeoutSecs );
172
186 bool SetStallTimeout( long aMinBytesPerSec, long aDurationSecs );
187
188 CURL* GetCurl() { return m_CURL; }
189
190 int GetResponseStatusCode();
191
192private:
200 template <typename T>
201 int setOption( int aOption, T aArg );
202
204 curl_slist* m_headers;
205 std::string m_buffer;
206 std::unique_ptr<CURL_PROGRESS> progress;
207 std::shared_lock<std::shared_mutex> m_curlSharedLock;
208};
209
210
211#endif // KICAD_CURL_EASY_H_
std::string m_buffer
int Perform()
Equivalent to curl_easy_perform.
bool SetPostFields(const std::vector< std::pair< std::string, std::string > > &aFields)
Set fields for application/x-www-form-urlencoded POST request.
std::unique_ptr< CURL_PROGRESS > progress
bool SetUserAgent(const std::string &aAgent)
Set the request user agent.
std::shared_lock< std::shared_mutex > m_curlSharedLock
curl_slist * m_headers
void SetHeader(const std::string &aName, const std::string &aValue)
Set an arbitrary header for the HTTP(s) request.
const std::string & GetBuffer()
Return a reference to the received data buffer.
bool SetURL(const std::string &aURL)
Set the request URL.
bool SetFollowRedirects(bool aFollow)
Enable the following of HTTP(s) and other redirects, by default curl does not follow redirects.
int GetTransferTotal(uint64_t &aDownloadedBytes) const
const std::string GetErrorText(int aCode)
Fetch CURL's "friendly" error string for a given error code.
void CURL
std::function< int(size_t, size_t, size_t, size_t)> TRANSFER_CALLBACK
Wrapper interface around the curl_easy API/.
#define KICOMMON_API
Definition kicommon.h:27