Paths
FossilOrigin-Name: 6de5faf50051d45a938e107eb4d58d0b1eb2ae82b2f660c158594db12e0286b9
This commit is contained in:
parent
55eeccf277
commit
13a577dca1
7 changed files with 144 additions and 15 deletions
|
@ -34,10 +34,10 @@ void content_index(mastodont_t* api)
|
|||
char* status_format;
|
||||
mastodont_timeline_public(api, NULL, &storage, &statuses, &status_count);
|
||||
|
||||
/* Calculate statuses */
|
||||
/* Construct statuses into HTML */
|
||||
status_format = construct_statuses(statuses, status_count, &statuses_html_count);
|
||||
if (status_format == NULL)
|
||||
status_format = "Error in malloc! Something has gone terribly wrong...";
|
||||
status_format = "Error in malloc!";
|
||||
|
||||
/* Output */
|
||||
printf("Content-Length: %ld\r\n\r\n",
|
||||
|
|
24
src/main.c
24
src/main.c
|
@ -17,30 +17,34 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <mastodont.h>
|
||||
#include "../config.h"
|
||||
#include "index.h"
|
||||
#include "page_config.h"
|
||||
#include "path.h"
|
||||
|
||||
int main()
|
||||
int main(void)
|
||||
{
|
||||
char* path = getenv("PATH_INFO");
|
||||
// Content type is always HTML
|
||||
fputs("Content-type: text/html\r\n", stdout);
|
||||
|
||||
// Global init
|
||||
mastodont_global_curl_init();
|
||||
|
||||
|
||||
// API
|
||||
mastodont_t api;
|
||||
api.url = config_instance_url;
|
||||
mastodont_init(&api);
|
||||
|
||||
// Default index
|
||||
if (path == NULL || (path && strcmp(path, "/")))
|
||||
{
|
||||
content_index(&api);
|
||||
}
|
||||
|
||||
/*******************
|
||||
* Path handling *
|
||||
******************/
|
||||
struct path_info paths[] = {
|
||||
{ "/config", content_config }
|
||||
};
|
||||
|
||||
handle_paths(&api, paths, sizeof(paths)/sizeof(paths[0]));
|
||||
|
||||
// Cleanup
|
||||
mastodont_free(&api);
|
||||
|
|
25
src/page_config.c
Normal file
25
src/page_config.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* RatFE - 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 <stdio.h>
|
||||
#include "page_config.h"
|
||||
|
||||
void content_config(mastodont_t* api)
|
||||
{
|
||||
|
||||
}
|
25
src/page_config.h
Normal file
25
src/page_config.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* RatFE - 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/>.
|
||||
*/
|
||||
|
||||
#ifndef PAGE_CONFIG_H
|
||||
#define PAGE_CONFIG_H
|
||||
#include <mastodont.h>
|
||||
|
||||
void content_config(mastodont_t* api);
|
||||
|
||||
#endif // PAGE_CONFIG_H
|
43
src/path.c
Normal file
43
src/path.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* RatFE - 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 <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "path.h"
|
||||
|
||||
void handle_paths(mastodont_t* api, struct path_info* paths, size_t paths_len)
|
||||
{
|
||||
char* path = getenv("PATH_INFO");
|
||||
// "default" path
|
||||
if (path == NULL || (path && strcmp(path, "/") == 0))
|
||||
{
|
||||
content_index(api);
|
||||
}
|
||||
else if (path && path[1] == '@')
|
||||
{ // Account path
|
||||
content_index(api);
|
||||
}
|
||||
else if (path)
|
||||
{ // Generic path
|
||||
for (size_t i = 0; i < paths_len; ++i)
|
||||
{
|
||||
if (strcmp(path, paths[i].path) == 0)
|
||||
paths[i].callback(api);
|
||||
}
|
||||
}
|
||||
}
|
32
src/path.h
Normal file
32
src/path.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* RatFE - 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/>.
|
||||
*/
|
||||
|
||||
#ifndef PATH_H
|
||||
#define PATH_H
|
||||
#include <mastodont.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct path_info
|
||||
{
|
||||
char* path;
|
||||
void (*callback)(mastodont_t*);
|
||||
};
|
||||
|
||||
void handle_paths(mastodont_t* api, struct path_info* paths, size_t paths_len);
|
||||
|
||||
#endif // PATH_H
|
|
@ -3,15 +3,15 @@
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>%s</title>
|
||||
<link rel="icon" type="image/png" href="favicon.png">
|
||||
<link rel="stylesheet" type="text/css" href="ratfe.css">
|
||||
<link rel="icon" type="image/png" href="/favicon.png">
|
||||
<link rel="stylesheet" type="text/css" href="/ratfe.css">
|
||||
<!-- <link rel="stylesheet" type="text/css" href="../dist/ratfe.css"> -->
|
||||
</head>
|
||||
<body>
|
||||
<div id="display-wrapper">
|
||||
<div id="display">
|
||||
<header id="navbar">
|
||||
<a href="/"><img src="ratfe_logo.png" height="42"></a>
|
||||
<a href="/"><img src="/ratfe_logo.png" height="42"></a>
|
||||
<span class="info">RatFE</span>
|
||||
<div id="navbar-right" class="alignend">
|
||||
<!-- Searchbox -->
|
||||
|
|
Loading…
Reference in a new issue