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 <kicommon.h>
37#include <functional>
38#include <memory>
39#include <ostream>
40#include <string>
41#include <cstdint>
42
43typedef void CURL;
44struct curl_slist;
45
64typedef std::function<int( size_t, size_t, size_t, size_t )> TRANSFER_CALLBACK;
65struct CURL_PROGRESS;
66
67
69{
70public:
73
77 int Perform();
78
85 void SetHeader( const std::string& aName, const std::string& aValue );
86
93 bool SetUserAgent( const std::string& aAgent );
94
101 bool SetPostFields( const std::vector<std::pair<std::string, std::string>>& aFields );
102
109 bool SetPostFields( const std::string& aField );
110
117 bool SetURL( const std::string& aURL );
118
126 bool SetFollowRedirects( bool aFollow );
127
134 const std::string GetErrorText( int aCode );
135
136 int GetTransferTotal( uint64_t& aDownloadedBytes ) const;
137
141 const std::string& GetBuffer() { return m_buffer; }
142
144 std::string Escape( const std::string& aUrl );
145
146 bool SetTransferCallback( const TRANSFER_CALLBACK& aCallback, size_t aInterval );
147
148 bool SetOutputStream( const std::ostream* aOutput );
149
150 CURL* GetCurl() { return m_CURL; }
151
152 int GetResponseStatusCode();
153
154private:
162 template <typename T>
163 int setOption( int aOption, T aArg );
164
166 curl_slist* m_headers;
167 std::string m_buffer;
168 std::unique_ptr<CURL_PROGRESS> progress;
169};
170
171
172#endif // KICAD_CURL_EASY_H_
std::string m_buffer
std::unique_ptr< CURL_PROGRESS > progress
curl_slist * m_headers
const std::string & GetBuffer()
Return a reference to the received data buffer.
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:28