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
42typedef void CURL;
43struct curl_slist;
44
63typedef std::function<int( size_t, size_t, size_t, size_t )> TRANSFER_CALLBACK;
64struct CURL_PROGRESS;
65
66
68{
69public:
72
76 int Perform();
77
84 void SetHeader( const std::string& aName, const std::string& aValue );
85
92 bool SetUserAgent( const std::string& aAgent );
93
100 bool SetPostFields( const std::vector<std::pair<std::string, std::string>>& aFields );
101
108 bool SetPostFields( const std::string& aField );
109
116 bool SetURL( const std::string& aURL );
117
125 bool SetFollowRedirects( bool aFollow );
126
133 const std::string GetErrorText( int aCode );
134
135 int GetTransferTotal( uint64_t& aDownloadedBytes ) const;
136
140 const std::string& GetBuffer() { return m_buffer; }
141
143 std::string Escape( const std::string& aUrl );
144
145 bool SetTransferCallback( const TRANSFER_CALLBACK& aCallback, size_t aInterval );
146
147 bool SetOutputStream( const std::ostream* aOutput );
148
149 CURL* GetCurl() { return m_CURL; }
150
151 int GetResponseStatusCode();
152
153private:
161 template <typename T>
162 int setOption( int aOption, T aArg );
163
165 curl_slist* m_headers;
166 std::string m_buffer;
167 std::unique_ptr<CURL_PROGRESS> progress;
168};
169
170
171#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