85 lines
3.0 KiB
C++
85 lines
3.0 KiB
C++
/**
|
|
This file is a part of 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 MATRIX_CONNECTION_HPP
|
|
#define MATRIX_CONNECTION_HPP
|
|
|
|
#include "raii/curler.hpp"
|
|
#include "raii/string.hpp"
|
|
#include "raii/rjp_string.hpp"
|
|
#include "raii/binary.hpp"
|
|
#include "matrix/session_info.hpp"
|
|
#include <memory> //shared_ptr
|
|
|
|
namespace matrix{
|
|
|
|
//Base class of all interactive network classes.
|
|
class connection
|
|
{
|
|
protected:
|
|
mutable raii::curler m_curl = {};
|
|
std::shared_ptr<internal::session_info> m_ses = {};
|
|
protected:
|
|
connection(const std::shared_ptr<internal::session_info>&);
|
|
connection(const connection&) = default;
|
|
connection(connection&&) = default;
|
|
connection& operator=(const connection&) = default;
|
|
connection& operator=(connection&&) = default;
|
|
|
|
public:
|
|
~connection(void) = default;
|
|
|
|
/*
|
|
* NOT thread safe.
|
|
* Returns: the current access token.
|
|
*/
|
|
const raii::rjp_string& access_token(void)const;
|
|
/*
|
|
* NOT thread safe
|
|
* Returns: the logged in user's userid.
|
|
*/
|
|
const raii::rjp_string& userid(void)const;
|
|
/*
|
|
* NOT thread safe
|
|
* Returns: the current useragent.
|
|
*/
|
|
const raii::string& useragent(void)const;
|
|
|
|
/*
|
|
* Returns: the http status code of the last operation performed.
|
|
*/
|
|
long http_status(void)const;
|
|
|
|
protected:
|
|
void _set_curl_useragent(const raii::string_base& useragent);
|
|
raii::string _get_curl(const raii::string_base& url)const;
|
|
raii::binary _get_curl_binary(const raii::string_base& url)const;
|
|
raii::string _post_curl(const raii::string_base& postdata, const raii::string_base& url, const raii::curl_llist& header)const;
|
|
raii::binary _post_curl_binary(const raii::string_base& postdata, const raii::string_base& url, const raii::curl_llist& header)const;
|
|
raii::string _put_curl(const raii::string_base& postdata, const raii::string_base& url, const raii::curl_llist& header)const;
|
|
raii::binary _put_curl_binary(const raii::string_base& postdata, const raii::string_base& url, const raii::curl_llist& header)const;
|
|
raii::rjp_string _post_and_find(const raii::string_base& data, const raii::string_base& url, const raii::curl_llist& header, const raii::string_base& target)const;
|
|
raii::rjp_string _get_and_find(const raii::string_base& url, const raii::string_base& search)const;
|
|
raii::rjp_string _curl_reply_search(const raii::string_base& reply, const raii::string_base& search)const;
|
|
void _set_curl_defaults(const raii::string_base& useragent)const;
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|