75 lines
2.0 KiB
C++
75 lines
2.0 KiB
C++
/**
|
|
This file is a part of r0nk, atlas_moon, and rexy's matrix client
|
|
Copyright (C) 2019 rexy712
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef RAII_CURLER_HPP
|
|
#define RAII_CURLER_HPP
|
|
|
|
#include <curl/curl.h>
|
|
|
|
#include "raii/curl_llist.hpp"
|
|
#include "raii/curl_string.hpp"
|
|
|
|
namespace raii{
|
|
|
|
//RAII wrapper for CURL* with some convenience functions added
|
|
class curler
|
|
{
|
|
private:
|
|
CURL* m_curl;
|
|
|
|
public:
|
|
curler(void);
|
|
curler(const curler& c);
|
|
curler(curler&& c)noexcept;
|
|
~curler(void);
|
|
|
|
template<class T>
|
|
curler& setopt(CURLoption option, T&& t){
|
|
curl_easy_setopt(m_curl, option, t);
|
|
return *this;
|
|
}
|
|
|
|
curler& putreq(void);
|
|
curler& postreq(void);
|
|
curler& getreq(void);
|
|
curler& setheader(const curl_llist& h);
|
|
curler& seturl(const char* s);
|
|
curler& seturl(const string_base& s);
|
|
curler& setuseragent(const char* s);
|
|
curler& setuseragent(const string_base& s);
|
|
curler& setuserpwd(const char* s);
|
|
curler& setuserpwd(const string_base& s);
|
|
curler& setpostdata(const char* s, curl_off_t len = -1);
|
|
curler& setpostdata(const string_base& s);
|
|
curler& forcessl(long version = CURL_SSLVERSION_DEFAULT);
|
|
void reset(void);
|
|
decltype(curl_easy_perform(m_curl)) perform(void);
|
|
|
|
curl_string encode(const char* data, int len = 0);
|
|
curl_string decode(const char* data, int* outlen = nullptr, int len = 0);
|
|
|
|
CURL* get(void);
|
|
const CURL* get(void)const;
|
|
operator CURL*(void);
|
|
operator const CURL*(void)const;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|