/**
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 .
*/
#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/curler.hpp"
#include "raii/string.hpp"
#include "matrix/connection.hpp"
#include //pair
namespace matrix{
class session : protected connection
{
private:
bool m_valid = false;
public:
session(void);
session(const auth_data&);
session(const session&) = default;
session(session&&) = default;
~session(void);
session& operator=(const session&) = default;
session& operator=(session&&) = default;
void set_useragent(const raii::string_base&);
void set_useragent(raii::string&&);
void set_access_token(const raii::string_base&);
void set_access_token(raii::string&&);
void set_homeserver(const raii::string_base&);
void set_homeserver(raii::string&&);
bool login(void);
bool login(const raii::string_base& username, const raii::string_base& pass);
bool valid(void)const;
client spawn_client(void)const;
syncer spawn_syncer(void)const;
void invalidate(void);
private:
bool _do_login(const raii::string_base& username, const raii::string_base& pass);
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 _get_new_access_token(const raii::string_base& name, const raii::string_base& pass, const raii::string_base& loginurl);
};
}
#endif