/**
This file is a part of rexy's matrix client
Copyright (C) 2019-2020 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 .
*/
#ifndef RAII_CURLER_HPP
#define RAII_CURLER_HPP
#include
#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:
using write_function = size_t(*)(char*,size_t,size_t,void*);
using read_function = size_t(*)(char*,size_t,size_t,void*);
public:
curler(void);
curler(const curler& c);
curler(curler&& c)noexcept;
~curler(void);
curler& operator=(const curler&);
curler& operator=(curler&&);
template
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);
curler& setwritefun(write_function);
curler& setwritedata(void*);
curler& setreadfun(read_function);
curler& setreaddata(void*);
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);
long last_status(void)const;
CURL* get(void);
const CURL* get(void)const;
operator CURL*(void);
operator const CURL*(void)const;
};
}
#endif