58 lines
1.8 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 MATRIX_SESSION_HPP
#define MATRIX_SESSION_HPP
#include "matrix/client.hpp"
#include "matrix/syncer.hpp"
#include "matrix/session_info.hpp"
#include "matrix/auth.hpp"
#include "raii/string.hpp"
#include <memory> //shared_ptr
#include <utility> //pair
namespace matrix{
class session
{
private:
std::shared_ptr<internal::session_info> m_ses;
client m_client;
syncer m_sync;
public:
session(const auth_data&);
//local setter
void set_useragent(const raii::string_base&);
void set_useragent(raii::string&&);
client& get_client(void);
const client& get_client(void)const;
syncer& get_syncer(void);
const syncer& get_syncer(void)const;
void invalidate(void);
private:
void _populate_session_info(const auth_data& a);
raii::rjp_string _get_userid(void);
raii::string _request_access_token(const raii::string_base& name, const raii::string_base& pass, const raii::string_base& loginurl)const;
std::pair<raii::rjp_string,raii::rjp_string> _get_new_access_token(const raii::string_base& name, const raii::string_base& pass, const raii::string_base& loginurl);
};
}
#endif