treebird/src/session.c
nekobit bf3af231c8 Async stuff
FossilOrigin-Name: 65fba45d6d6e5cb9318b881b0b137be84030afe64200f793fb7f5cf55d41b48c
2022-10-31 18:08:54 +00:00

64 lines
2.1 KiB
C

/*
* Treebird - Lightweight frontend for Pleroma
* Copyright (C) 2022 Nekobit
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "account.h"
#include "session.h"
#include "../config.h"
const char* const get_instance(struct session* ssn)
{
return keystr(ssn->cookies.instance_url) ?
keystr(ssn->cookies.instance_url) : config_instance_url;
}
const char* const get_token(struct session* ssn)
{
return keystr(ssn->cookies.access_token);
}
HV* perlify_session(struct session* ssn)
{
HV* ssn_hv = newHV();
hvstores_int(ssn_hv, "logged_in", ssn->logged_in);
HV* ssn_post_values = perlify_post_values(&(ssn->post));
HV* ssn_get_values = perlify_get_values(&(ssn->query));
HV* ssn_cookie_values = perlify_cookies(&(ssn->cookies));
HV* acct_hv = perlify_account(&(ssn->acct));
// Config
HV* ssn_config = perlify_config(&(ssn->config));
hvstores_ref(ssn_hv, "config", ssn_config);
hvstores_ref(ssn_hv, "cookies", ssn_cookie_values);
hvstores_ref(ssn_hv, "query", ssn_get_values);
hvstores_ref(ssn_hv, "post", ssn_post_values);
hvstores_ref(ssn_hv, "account", acct_hv);
return ssn_hv;
}
void session_cleanup(struct session* ssn)
{
tb_free(ssn->cookies_str);
tb_free(ssn->post_str);
tb_free(ssn->get_str);
free_files(&(keyfile(ssn->post.files)));
if (ssn->logged_in) mstdnt_cleanup_account(&(ssn->acct));
mstdnt_storage_cleanup(&(ssn->acct_storage));
if (attachments)
cleanup_media_storages(ssn, attachments);
}