Use session struct instead of globals

Later, when we want to implement multithreading, we need to use separate variables. This is also a bit cleaner

FossilOrigin-Name: b720083c13871db7a6b0f8573a91a7ac057d39d3a409df2232574bc001821e74
This commit is contained in:
me@ow.nekobit.net 2022-03-30 18:31:30 +00:00
parent 6492402f96
commit 321f4ddf71
31 changed files with 169 additions and 155 deletions

View file

@ -65,7 +65,7 @@ char* construct_account_page(struct mstdnt_account* acct,
return result;
}
void content_account(mastodont_t* api, char** data, size_t size)
void content_account(struct session* ssn, mastodont_t* api, char** data)
{
int cleanup = 0;
char* account_page;
@ -100,7 +100,7 @@ void content_account(mastodont_t* api, char** data, size_t size)
};
/* Output */
render_base_page(&b, api);
render_base_page(&b, ssn, api);
/* Cleanup */
mastodont_storage_cleanup(&storage);

View file

@ -20,11 +20,12 @@
#define ACCOUNT_H
#include <stddef.h>
#include <mastodont.h>
#include "session.h"
char* construct_account_page(struct mstdnt_account* acct,
struct mstdnt_status* statuses,
size_t statuses_len,
size_t* res_size);
void content_account(mastodont_t* api, char** data, size_t data_size);
void content_account(struct session* ssn, mastodont_t* api, char** data);
#endif // ACCOUNT_H

View file

@ -29,7 +29,7 @@
// Files
#include "../static/index.chtml"
void render_base_page(struct base_page* page, mastodont_t* api)
void render_base_page(struct base_page* page, struct session* ssn, mastodont_t* api)
{
char* cookie = getenv("HTTP_COOKIE");
enum l10n_locale locale = page->locale;
@ -40,16 +40,16 @@ void render_base_page(struct base_page* page, mastodont_t* api)
struct mstdnt_notification* notifs = NULL;
size_t notifs_len;
if (!g_config.changed && cookie)
if (!ssn->config.changed && cookie)
{
if (cookies.theme)
g_config.theme = cookies.theme;
if (cookies.logged_in)
if (ssn->cookies.theme)
ssn->config.theme = ssn->cookies.theme;
if (ssn->cookies.logged_in)
login_string = "";
}
// Get / Show notifications on sidebar
if (cookies.logged_in && cookies.access_token)
if (ssn->cookies.logged_in && ssn->cookies.access_token)
{
struct mstdnt_get_notifications_args args = {
.exclude_types = 0,
@ -73,7 +73,7 @@ void render_base_page(struct base_page* page, mastodont_t* api)
char* data;
int len = easprintf(&data, data_index_html,
L10N[locale][L10N_APP_NAME],
g_config.theme,
ssn->config.theme,
config_url_prefix,
L10N[locale][L10N_APP_NAME],
login_string,

View file

@ -21,7 +21,7 @@
#include <mastodont.h>
#include "l10n.h"
#include "local_config.h"
#include "session.h"
enum base_category
{
BASE_CAT_NONE,
@ -42,6 +42,6 @@ struct base_page
char* sidebar_left;
};
void render_base_page(struct base_page* page, mastodont_t* api);
void render_base_page(struct base_page* page, struct session* ssn, mastodont_t* api);
#endif // BASE_PAGE_H

View file

@ -30,9 +30,7 @@ enum cookie_state
STATE_V_START,
};
struct cookie_values cookies = { 0 };
char* read_cookies_env()
char* read_cookies_env(struct cookie_values* cookies)
{
struct http_cookie_info info;
char* cookies_env = getenv("HTTP_COOKIE");
@ -52,9 +50,9 @@ char* read_cookies_env()
// Will loop through these
struct key_value_refs refs[] = {
{ "access_token", &(cookies.access_token) },
{ "logged_in", &(cookies.logged_in) },
{ "theme", &(cookies.theme) }
{ "access_token", &(cookies->access_token) },
{ "logged_in", &(cookies->logged_in) },
{ "theme", &(cookies->theme) }
};
do

View file

@ -34,11 +34,9 @@ struct http_cookie_info
size_t val_len; // Val may be large, like CSS property
};
extern struct cookie_values cookies;
// Stupidly fast simple cookie parser
char* parse_cookies(char* begin, struct http_cookie_info* info);
char* read_cookies_env();
char* read_cookies_env(struct cookie_values* cookies);
int cookie_get_val(char* src, char* key, struct http_cookie_info* info);
#endif // COOKIE_H

View file

@ -34,7 +34,7 @@ char* construct_error(char* error, size_t* size)
return error_html;
}
void content_not_found(mastodont_t* api, char* path)
void content_not_found(struct session* ssn, mastodont_t* api, char* path)
{
char* page;
easprintf(&page,
@ -47,6 +47,6 @@ void content_not_found(mastodont_t* api, char* path)
.sidebar_left = NULL
};
render_base_page(&b, api);
render_base_page(&b, ssn, api);
free(page);
}

View file

@ -20,8 +20,9 @@
#define ERROR_H
#include <mastodont.h>
#include <stddef.h>
#include "session.h"
char* construct_error(char* message, size_t* size);
void content_not_found(mastodont_t* api, char* path);
void content_not_found(struct session* ssn, mastodont_t* api, char* path);
#endif // ERROR_H

View file

@ -19,8 +19,8 @@
#include <stdlib.h>
#include "timeline.h"
void content_index(mastodont_t* api)
void content_index(struct session* ssn, mastodont_t* api)
{
// Check logins
tl_public(api, 0);
tl_public(ssn, api, 0);
}

View file

@ -19,7 +19,8 @@
#ifndef INDEX_H
#define INDEX_H
#include <mastodont.h>
#include "session.h"
void content_index(mastodont_t* api);
void content_index(struct session* ssn, mastodont_t* api);
#endif // INDEX_H

View file

@ -61,7 +61,7 @@ char* construct_lists_view(char* lists_string, int* size)
return list_string;
}
void content_lists(mastodont_t* api, char** data, size_t size)
void content_lists(struct session* ssn, mastodont_t* api, char** data)
{
int cleanup = 0;
struct mstdnt_list* lists;
@ -90,7 +90,7 @@ void content_lists(mastodont_t* api, char** data, size_t size)
};
// Output
render_base_page(&b, api);
render_base_page(&b, ssn, api);
// Cleanup
mastodont_storage_cleanup(&storage);

View file

@ -20,10 +20,11 @@
#define LISTS_H
#include <stddef.h>
#include <mastodont.h>
#include "session.h"
char* construct_list(struct mstdnt_list* list, int* size);
char* construct_lists(struct mstdnt_list* lists, size_t size, size_t* ret_size);
char* construct_lists_view(char* lists_string, int* size);
void content_lists(mastodont_t* api, char** data, size_t size);
void content_lists(struct session* ssn, mastodont_t* api, char** data);
#endif // LISTS_H

View file

@ -25,6 +25,4 @@ struct local_config
char* theme;
};
extern struct local_config g_config;
#endif // LOCAL_CONFIG_H

View file

@ -29,7 +29,7 @@
// Files
#include "../static/login.chtml"
void content_login(mastodont_t* api, char** data, size_t data_size)
void content_login(struct session* ssn, mastodont_t* api, char** data)
{
struct mstdnt_storage storage = { 0 }, oauth_store = { 0 };
struct mstdnt_app app;
@ -37,8 +37,8 @@ void content_login(mastodont_t* api, char** data, size_t data_size)
char* error = NULL;
char* page;
printf("%s: %s\r\n", post.username ? post.username: "none", post.password ? post.password : "none");
if (post.username && post.password)
printf("%s: %s\r\n", ssn->post.username ? ssn->post.username: "none", ssn->post.password ? ssn->post.password : "none");
if (ssn->post.username && ssn->post.password)
{
// Getting the client id/secret
struct mstdnt_args args_app = {
@ -57,8 +57,8 @@ void content_login(mastodont_t* api, char** data, size_t data_size)
.redirect_uri = NULL,
.scope = NULL,
.code = NULL,
.username = post.username,
.password = post.password
.username = ssn->post.username,
.password = ssn->post.password
};
if (mastodont_obtain_oauth_token(api, &args_token, &oauth_store,
@ -96,7 +96,7 @@ void content_login(mastodont_t* api, char** data, size_t data_size)
};
// Output
render_base_page(&b, api);
render_base_page(&b, ssn, api);
// Cleanup
mastodont_storage_cleanup(&storage);

View file

@ -20,7 +20,8 @@
#define LOGIN_H
#include <stddef.h>
#include <mastodont.h>
#include "session.h"
void content_login(mastodont_t* api, char** data, size_t data_size);
void content_login(struct session* ssn, mastodont_t* api, char** data);
#endif // LOGIN_H

View file

@ -32,6 +32,7 @@
#include "status.h"
#include "lists.h"
#include "timeline.h"
#include "session.h"
#include "notifications.h"
#include "test.h"
@ -49,15 +50,19 @@ int main(void)
api.url = config_instance_url;
mastodont_init(&api, MSTDNT_FLAG_NO_URI_SANITIZE | config_library_flags);
// Load cookies
char* cookies_str = read_cookies_env();
api.token = cookies.access_token; // Load token now
char* post_str = read_post_data();
char* get_str = read_query_data();
// Config defaults
g_config.theme = "treebird20";
struct session ssn = {
.config = {
.changed = 0,
.theme = "treebird20"
}
};
// Load cookies
char* cookies_str = read_cookies_env(&(ssn.cookies));
api.token = ssn.cookies.access_token; // Load token now
char* post_str = read_post_data(&(ssn.post));
char* get_str = read_query_data(&(ssn.query));
/*******************
* Path handling *
******************/
@ -77,7 +82,7 @@ int main(void)
{ "/notifications", content_notifications },
};
handle_paths(&api, paths, sizeof(paths)/sizeof(paths[0]));
handle_paths(&ssn, &api, paths, sizeof(paths)/sizeof(paths[0]));
// Cleanup
if (cookies_str) free(cookies_str);
@ -85,11 +90,6 @@ int main(void)
if (get_str) free(get_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));
++run_count;
}

View file

@ -107,14 +107,14 @@ char* construct_notifications_compact(struct mstdnt_notification* notifs,
ret_size);
}
void content_notifications(mastodont_t* api, char** data, size_t data_size)
void content_notifications(struct session* ssn, mastodont_t* api, char** data)
{
char* page, *notif_html = NULL;
struct mstdnt_storage storage;
struct mstdnt_notification* notifs;
size_t notifs_len;
if (cookies.logged_in)
if (ssn->cookies.logged_in)
{
struct mstdnt_get_notifications_args args = {
.exclude_types = 0,
@ -146,7 +146,7 @@ void content_notifications(mastodont_t* api, char** data, size_t data_size)
};
// Output
render_base_page(&b, api);
render_base_page(&b, ssn, api);
if (notif_html) free(notif_html);
if (page) free(page);
}

View file

@ -19,7 +19,7 @@
#ifndef NOTIFICATIONS_H
#define NOTIFICATIONS_H
#include <mastodont.h>
#include "cookie.h"
#include "session.h"
#include "type_string.h"
char* construct_notification(struct mstdnt_notification* notif, int* size);
@ -32,6 +32,6 @@ char* construct_notifications_compact(struct mstdnt_notification* notifs,
size_t* ret_size);
// Page contents
void content_notifications(mastodont_t* api, char** data, size_t data_size);
void content_notifications(struct session* ssn, mastodont_t* api, char** data);
#endif // NOTIFICATION_H

View file

@ -58,15 +58,15 @@ static char* construct_config_sidebar(enum config_category cat, size_t* size)
return sidebar_html;
}
void content_config(mastodont_t* api, char** data, size_t size)
void content_config(struct session* ssn, mastodont_t* api, char** data)
{
char* sidebar_html = construct_config_sidebar(CONFIG_CAT_GENERAL, NULL);
if (post.theme)
if (ssn->post.theme)
{
g_config.theme = post.theme;
ssn->config.theme = ssn->post.theme;
printf("Set-Cookie: %s=%s; HttpOnly; SameSite=Strict;",
"theme", post.theme);
g_config.changed = 1;
"theme", ssn->post.theme);
ssn->config.changed = 1;
}
struct base_page b = {
@ -76,7 +76,7 @@ void content_config(mastodont_t* api, char** data, size_t size)
.sidebar_left = sidebar_html
};
render_base_page(&b, api);
render_base_page(&b, ssn, api);
// Cleanup
free(sidebar_html);
}

View file

@ -20,7 +20,8 @@
#define PAGE_CONFIG_H
#include <stddef.h>
#include <mastodont.h>
#include "session.h"
void content_config(mastodont_t* api, char** data, size_t data_size);
void content_config(struct session* ssn, mastodont_t* api, char** data);
#endif // PAGE_CONFIG_H

View file

@ -29,7 +29,9 @@ enum path_state
PARSE_READ,
};
int parse_path(mastodont_t* api, struct path_info* path_info)
int parse_path(struct session* ssn,
mastodont_t* api,
struct path_info* path_info)
{
int fail = 0, fin = 0;
enum path_state state = PARSE_NEUTRAL;
@ -103,7 +105,7 @@ breakpt:
if (fail)
return 1;
path_info->callback(api, data, size);
path_info->callback(ssn, api, data);
// Cleanup
for (size_t i = 0; i < size; ++i)
@ -114,22 +116,25 @@ breakpt:
return 0;
}
void handle_paths(mastodont_t* api, struct path_info* paths, size_t paths_len)
void handle_paths(struct session* ssn,
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);
content_index(ssn, api);
}
else { // Generic path
for (size_t i = 0; i < paths_len; ++i)
{
if (parse_path(api, paths + i) == 0)
if (parse_path(ssn, api, paths + i) == 0)
return;
}
// Fell out, return 404
content_not_found(api, path);
content_not_found(ssn, api, path);
}
}

View file

@ -20,14 +20,23 @@
#define PATH_H
#include <mastodont.h>
#include <stddef.h>
#include "session.h"
struct path_info
{
char* path;
void (*callback)(mastodont_t*, char**, size_t);
void (*callback)(struct session* ssn,
mastodont_t*,
char**);
};
void handle_paths(mastodont_t* api, struct path_info* paths, size_t paths_len);
int parse_path(mastodont_t* api, struct path_info* path_info);
void handle_paths(struct session* ssn,
mastodont_t* api,
struct path_info* paths,
size_t paths_len);
int parse_path(struct session* ssn,
mastodont_t* api,
struct path_info* path_info);
#endif // PATH_H

View file

@ -26,7 +26,7 @@
struct query_values post = { 0 };
struct get_values query = { 0 };
char* read_query_data()
char* read_query_data(struct get_values* query)
{
struct http_query_info info;
char* query_string = getenv("QUERY_STRING");
@ -34,7 +34,7 @@ char* read_query_data()
// BEGIN Query references
struct key_value_refs refs[] = {
{ "offset", &(query.offset) },
{ "offset", &(query->offset) },
};
// END Query references
@ -65,7 +65,7 @@ char* read_query_data()
return get_query;
}
char* read_post_data()
char* read_post_data(struct query_values* post)
{
struct http_query_info info;
char* request_method = getenv("REQUEST_METHOD");
@ -73,16 +73,16 @@ char* read_post_data()
// BEGIN Query references
struct key_value_refs refs[] = {
{ "content", &(post.content) },
{ "itype", &(post.itype) },
{ "id", &(post.id) },
{ "theme", &(post.theme) },
{ "username", &(post.username) },
{ "password", &(post.password) },
{ "replyid", &(post.replyid) },
{ "min_id", &(post.min_id) },
{ "max_id", &(post.max_id) },
{ "start_id", &(post.start_id) },
{ "content", &(post->content) },
{ "itype", &(post->itype) },
{ "id", &(post->id) },
{ "theme", &(post->theme) },
{ "username", &(post->username) },
{ "password", &(post->password) },
{ "replyid", &(post->replyid) },
{ "min_id", &(post->min_id) },
{ "max_id", &(post->max_id) },
{ "start_id", &(post->start_id) },
};
// END Query references

View file

@ -46,11 +46,8 @@ struct get_values
char* offset;
};
extern struct query_values post;
extern struct get_values query;
char* read_query_data();
char* read_post_data();
char* read_query_data(struct get_values* query);
char* read_post_data(struct query_values* post);
/* A stupidly quick query parser */
char* parse_query(char* begin, struct http_query_info* info);
char* try_handle_post(void (*call)(struct http_query_info*, void*), void* arg);

View file

@ -16,9 +16,18 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef SESSION_H
#define SESSION_H
#include "query.h"
#include "local_config.h"
#include "cookie.h"
struct local_config g_config = {
.changed = 0,
.theme = "treebird20"
struct session
{
struct query_values post;
struct get_values query;
struct cookie_values cookies;
struct local_config config;
};
#endif // SESSION_H

View file

@ -36,9 +36,9 @@
#define NUM_STR "%u"
int try_post_status(mastodont_t* api)
int try_post_status(struct session* ssn, mastodont_t* api)
{
if (!post.content) return 1;
if (!(ssn->post.content)) return 1;
struct mstdnt_storage storage;
@ -47,7 +47,7 @@ int try_post_status(mastodont_t* api)
.content_type = "text/plain",
.expires_in = 0,
.in_reply_to_conversation_id = NULL,
.in_reply_to_id = post.replyid,
.in_reply_to_id = ssn->post.replyid,
.language = NULL,
.media_ids = NULL,
.poll = NULL,
@ -55,7 +55,7 @@ int try_post_status(mastodont_t* api)
.scheduled_at = NULL,
.sensitive = 0,
.spoiler_text = NULL,
.status = post.content,
.status = ssn->post.content,
.visibility = "public",
};
@ -67,11 +67,11 @@ int try_post_status(mastodont_t* api)
return 0;
}
void content_status_create(mastodont_t* api, char** data, size_t data_size)
void content_status_create(struct session* ssn, mastodont_t* api, char** data)
{
char* referer = getenv("HTTP_REFERER");
try_post_status(api);
try_post_status(ssn, api);
printf("Status: 303 See Other\r\n"
"Location: %s\r\n"
@ -80,19 +80,19 @@ void content_status_create(mastodont_t* api, char** data, size_t data_size)
referer ? referer : "/");
}
int try_interact_status(mastodont_t* api, char* id)
int try_interact_status(struct session* ssn, mastodont_t* api, char* id)
{
struct mstdnt_storage storage = { 0 };
if (!(post.itype && id)) return 1;
if (!(ssn->post.itype && id)) return 1;
// Pretty up the type
if (strcmp(post.itype, "like") == 0)
if (strcmp(ssn->post.itype, "like") == 0)
mastodont_favourite_status(api, id, &storage, NULL);
else if (strcmp(post.itype, "repeat") == 0)
else if (strcmp(ssn->post.itype, "repeat") == 0)
mastodont_reblog_status(api, id, &storage, NULL);
else if (strcmp(post.itype, "unlike") == 0)
else if (strcmp(ssn->post.itype, "unlike") == 0)
mastodont_unfavourite_status(api, id, &storage, NULL);
else if (strcmp(post.itype, "repeat") == 0)
else if (strcmp(ssn->post.itype, "unrepeat") == 0)
mastodont_unreblog_status(api, id, &storage, NULL);
mastodont_storage_cleanup(&storage);
@ -179,11 +179,11 @@ char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* re
return construct_func_strings(construct_status_voidwrap, statuses, size, ret_size);
}
void status_interact(mastodont_t* api, char** data, size_t data_size)
void status_interact(struct session* ssn, mastodont_t* api, char** data)
{
char* referer = getenv("HTTP_REFERER");
try_interact_status(api, data[0]);
try_interact_status(ssn, api, data[0]);
printf("Status: 303 See Other\r\n"
"Location: %s\r\n"
@ -192,17 +192,17 @@ void status_interact(mastodont_t* api, char** data, size_t data_size)
referer ? referer : "/");
}
void status_view(mastodont_t* api, char** data, size_t data_size)
void status_view(struct session* ssn, mastodont_t* api, char** data)
{
content_status(api, data, data_size, 0);
content_status(ssn, api, data, 0);
}
void status_reply(mastodont_t* api, char** data, size_t data_size)
void status_reply(struct session* ssn, mastodont_t* api, char** data)
{
content_status(api, data, data_size, 1);
content_status(ssn, api, data, 1);
}
void content_status(mastodont_t* api, char** data, size_t data_size, int is_reply)
void content_status(struct session* ssn, mastodont_t* api, char** data, int is_reply)
{
char* output;
// Status context
@ -211,11 +211,8 @@ void content_status(mastodont_t* api, char** data, size_t data_size, int is_repl
size_t stat_before_len, stat_after_len;
char* before_html = NULL, *stat_html = NULL, *after_html = NULL, *stat_reply = NULL;
try_post_status(api);
try_post_status(ssn, api);
#ifdef _TEST_
#include "test/status_test.h"
#else
// Get information
mastodont_get_status_context(api, data[0], &storage, &statuses_before, &statuses_after,
&stat_before_len, &stat_after_len);
@ -234,7 +231,6 @@ void content_status(mastodont_t* api, char** data, size_t data_size, int is_repl
// After...
after_html = construct_statuses(statuses_after, stat_after_len, NULL);
#endif
easprintf(&output, "%s%s%s%s",
before_html ? before_html : "",
@ -250,7 +246,7 @@ void content_status(mastodont_t* api, char** data, size_t data_size, int is_repl
};
// Output
render_base_page(&b, api);
render_base_page(&b, ssn, api);
// Cleanup
if (before_html) free(before_html);

View file

@ -19,10 +19,10 @@
#ifndef STATUS_H
#define STATUS_H
#include <mastodont.h>
int try_post_status(mastodont_t* api);
int try_interact_status(mastodont_t* api, char* id);
void content_status_create(mastodont_t* api, char** data, size_t data_size);
#include "session.h"
int try_post_status(struct session* ssn, mastodont_t* api);
int try_interact_status(struct session* ssn, mastodont_t* api, char* id);
void content_status_create(struct session* ssn, mastodont_t* api, char** data);
// HTML Builders
char* construct_post_box(char* reply_id,
@ -32,10 +32,10 @@ char* construct_status(struct mstdnt_status* status, int* size, struct mstdnt_no
char* construct_statuses(struct mstdnt_status* statuses, size_t size, size_t* ret_size);
// Status frontends
void status_view(mastodont_t* api, char** data, size_t data_size);
void status_reply(mastodont_t* api, char** data, size_t data_size);
void status_interact(mastodont_t* api, char** data, size_t data_size);
void status_view(struct session* ssn, mastodont_t* api, char** data);
void status_reply(struct session* ssn, mastodont_t* api, char** data);
void status_interact(struct session* ssn, mastodont_t* api, char** data);
// Above wraps to the below function
void content_status(mastodont_t* api, char** data, size_t data_size, int is_reply);
void content_status(struct session* ssn, mastodont_t* api, char** data, int is_reply);
#endif // STATUS_H

View file

@ -42,7 +42,7 @@ enum env_tbl_index
#define ENV_TBL_GET(index) (env_tbl[(index)] ? env_tbl[(index)] : ENV_NOT_FOUND)
void content_test(mastodont_t* api, char** data, size_t data_size)
void content_test(struct session* ssn, mastodont_t* api, char** data)
{
char* env_tbl[] = {
getenv("HTTP_COOKIES"),
@ -75,6 +75,6 @@ void content_test(mastodont_t* api, char** data, size_t data_size)
};
// Output
render_base_page(&b, api);
render_base_page(&b, ssn, api);
if (page) free(page);
}

View file

@ -20,7 +20,8 @@
#define TEST_H
#include <stddef.h>
#include <mastodont.h>
#include "session.h"
void content_test(mastodont_t* api, char** data, size_t data_size);
void content_test(struct session* ssn, mastodont_t* api, char** data);
#endif /* TEST_H */

View file

@ -30,7 +30,7 @@
#include "../static/navigation.chtml"
void tl_public(mastodont_t* api, int local)
void tl_public(struct session* ssn, mastodont_t* api, int local)
{
int cleanup = 0;
size_t status_count, statuses_html_count;
@ -46,13 +46,13 @@ void tl_public(mastodont_t* api, int local)
.local = local,
.remote = 0,
.only_media = 0,
.max_id = post.max_id,
.max_id = ssn->post.max_id,
.since_id = NULL,
.min_id = post.min_id,
.min_id = ssn->post.min_id,
.limit = 20
};
try_post_status(api);
try_post_status(ssn, api);
if (mastodont_timeline_public(api, &args, &storage, &statuses, &status_count))
{
@ -71,7 +71,7 @@ void tl_public(mastodont_t* api, int local)
if (statuses)
{
// If not set, set it
start_id = post.start_id ? post.start_id : statuses[0].id;
start_id = ssn->post.start_id ? ssn->post.start_id : statuses[0].id;
navigation_box = construct_navigation_box(start_id,
statuses[0].id,
statuses[status_count-1].id,
@ -90,7 +90,7 @@ void tl_public(mastodont_t* api, int local)
};
// Output
render_base_page(&b, api);
render_base_page(&b, ssn, api);
// Cleanup
mastodont_storage_cleanup(&storage);
@ -101,7 +101,7 @@ void tl_public(mastodont_t* api, int local)
if (output) free(output);
}
void tl_list(mastodont_t* api, char* list_id)
void tl_list(struct session* ssn, mastodont_t* api, char* list_id)
{
int cleanup = 0;
size_t status_count, statuses_html_count;
@ -117,7 +117,7 @@ void tl_list(mastodont_t* api, char* list_id)
.limit = 20,
};
try_post_status(api);
try_post_status(ssn, api);
if (mastodont_timeline_list(api, list_id, &args, &storage, &statuses, &status_count))
{
@ -145,7 +145,7 @@ void tl_list(mastodont_t* api, char* list_id)
};
// Output
render_base_page(&b, api);
render_base_page(&b, ssn, api);
// Cleanup
mastodont_storage_cleanup(&storage);
@ -156,23 +156,19 @@ void tl_list(mastodont_t* api, char* list_id)
}
void content_tl_federated(mastodont_t* api, char** data, size_t data_size)
void content_tl_federated(struct session* ssn, mastodont_t* api, char** data)
{
(void)data;
(void)data_size;
tl_public(api, 0);
tl_public(ssn, api, 0);
}
void content_tl_local(mastodont_t* api, char** data, size_t data_size)
void content_tl_local(struct session* ssn, mastodont_t* api, char** data)
{
(void)data;
(void)data_size;
tl_public(api, 1);
tl_public(ssn, api, 1);
}
void content_tl_list(mastodont_t* api, char** data, size_t data_size)
void content_tl_list(struct session* ssn, mastodont_t* api, char** data)
{
(void)data;
(void)data_size;
tl_list(api, data[0]);
tl_list(ssn, api, data[0]);
}

View file

@ -20,13 +20,14 @@
#define TIMELINE_H
#include <stddef.h>
#include <mastodont.h>
#include "session.h"
// Federated and local are here
void tl_public(mastodont_t* api, int local);
void tl_list(mastodont_t* api, char* list_id);
void tl_public(struct session* ssn, mastodont_t* api, int local);
void tl_list(struct session* ssn, mastodont_t* api, char* list_id);
void content_tl_federated(mastodont_t* api, char** data, size_t data_size);
void content_tl_local(mastodont_t* api, char** data, size_t data_size);
void content_tl_list(mastodont_t* api, char** data, size_t data_size);
void content_tl_federated(struct session* ssn, mastodont_t* api, char** data);
void content_tl_local(struct session* ssn, mastodont_t* api, char** data);
void content_tl_list(struct session* ssn, mastodont_t* api, char** data);
#endif // TIMELINE_H