treebird/src/main.c
me@ow.nekobit.net 3bfedc3d32 Switch to fcgi_stdio
FossilOrigin-Name: 4c4dbf4b391b2e37376de65f75cb05404950d52339b10f6619e413979c681b9c
2022-03-21 14:18:56 +00:00

95 lines
2.8 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 <fcgi_stdio.h>
#include <string.h>
#include <mastodont.h>
#include <stdlib.h>
#include "../config.h"
#include "index.h"
#include "page_config.h"
#include "path.h"
#include "account.h"
#include "login.h"
#include "local_config.h"
#include "cookie.h"
#include "query.h"
#include "status.h"
#include "lists.h"
#include "timeline.h"
#include "notifications.h"
#include "test.h"
int main(void)
{
// Global init
mastodont_global_curl_init();
unsigned run_count = 0;
// API
for (;FCGI_Accept() >= 0; ++run_count)
{
mastodont_t api;
api.url = config_instance_url;
mastodont_init(&api, MSTDNT_FLAG_NO_URI_SANITIZE);
// Load cookies
char* cookies_str = read_cookies_env();
api.token = cookies.access_token; // Load token now
char* post_str = read_post_data();
// Config defaults
g_config.theme = "treebird20";
/*******************
* Path handling *
******************/
struct path_info paths[] = {
{ "/config", content_config },
{ "/login", content_login },
{ "/test", content_test },
{ "/@:", content_account },
{ "/status/:/interact", status_interact },
{ "/status/:/reply", status_reply },
{ "/status/:", status_view },
{ "/lists/for/:", content_tl_list },
{ "/lists", content_lists },
{ "/federated", content_tl_federated },
{ "/local", content_tl_local },
{ "/notifications", content_notifications },
};
printf("Run: %d\r\n", run_count);
handle_paths(&api, paths, sizeof(paths)/sizeof(paths[0]));
// Cleanup
if (cookies_str) free(cookies_str);
if (post_str) free(post_str);
mastodont_free(&api);
// Obliterate all global values, so the next client
// can't even think reading them
memset(&cookies, 0, sizeof(cookies));
memset(&post, 0, sizeof(post));
}
mastodont_global_curl_cleanup();
}