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 (C) 2015, 2021 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24#ifndef KICAD_CURL_EASY_H_
25#define KICAD_CURL_EASY_H_
26
27/*
28 * curl.h, and therefore kicad_curl.h must be included before wxWidgets headers because on Windows,
29 * wxWidgets ends up including windows.h before winsocks2.h
30 * curl and curl.h causes build warnings if included before any wxxxx.h
31 *
32 * So kicad_curl_easy.h does not include curl.h to avoid constraints,
33 * and including kicad_curl.h could be needed in a few sources
34 */
35
36#include <functional>
37#include <memory>
38#include <ostream>
39#include <string>
40
41typedef void CURL;
42struct curl_slist;
43
62typedef std::function<int( size_t, size_t, size_t, size_t )> TRANSFER_CALLBACK;
63struct CURL_PROGRESS;
64
65
67{
68public:
71
75 int Perform();
76
83 void SetHeader( const std::string& aName, const std::string& aValue );
84
91 bool SetUserAgent( const std::string& aAgent );
92
99 bool SetPostFields( const std::vector<std::pair<std::string, std::string>>& aFields );
100
107 bool SetURL( const std::string& aURL );
108
116 bool SetFollowRedirects( bool aFollow );
117
124 const std::string GetErrorText( int aCode );
125
126 int GetTransferTotal( uint64_t& aDownloadedBytes ) const;
127
131 const std::string& GetBuffer() { return m_buffer; }
132
134 std::string Escape( const std::string& aUrl );
135
136 bool SetTransferCallback( const TRANSFER_CALLBACK& aCallback, size_t aInterval );
137
138 bool SetOutputStream( const std::ostream* aOutput );
139
140 CURL* GetCurl() { return m_CURL; }
141
142
143private:
151 template <typename T>
152 int setOption( int aOption, T aArg );
153
155 curl_slist* m_headers;
156 std::string m_buffer;
157 std::unique_ptr<CURL_PROGRESS> progress;
158};
159
160
161#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
std::string Escape(const std::string &aUrl)
Escapes a string for use as a URL.
bool SetUserAgent(const std::string &aAgent)
Set the request user agent.
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 SetTransferCallback(const TRANSFER_CALLBACK &aCallback, size_t aInterval)
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
int setOption(int aOption, T aArg)
Set a curl option, only supports single parameter curl options.
bool SetOutputStream(const std::ostream *aOutput)
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/.