Multithreading
FossilOrigin-Name: cadee06c6bb43e3b8f40ea06b3c4decf781a6c215b0c50ee5f71d013331d10b9
This commit is contained in:
parent
12020d7e6c
commit
f4ced103be
44 changed files with 401 additions and 326 deletions
10
src/about.c
10
src/about.c
|
@ -23,7 +23,7 @@
|
|||
#include "../static/about.ctmpl"
|
||||
#include "../static/license.ctmpl"
|
||||
|
||||
void content_about(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_about(PATH_ARGS)
|
||||
{
|
||||
struct base_page b = {
|
||||
.category = BASE_CAT_NONE,
|
||||
|
@ -32,14 +32,14 @@ void content_about(struct session* ssn, mastodont_t* api, char** data)
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
}
|
||||
|
||||
|
||||
void content_about_license(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_about_license(PATH_ARGS)
|
||||
{
|
||||
char* page;
|
||||
char* referer = getenv("HTTP_REFERER");
|
||||
char* referer = GET_ENV("HTTP_REFERER", req);
|
||||
struct license_template tdata = {
|
||||
.back_ref = referer,
|
||||
.license_str = "License"
|
||||
|
@ -53,7 +53,7 @@ void content_about_license(struct session* ssn, mastodont_t* api, char** data)
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
free(page);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
#define ABOUT_H
|
||||
#include <mastodont.h>
|
||||
#include "session.h"
|
||||
#include "path.h"
|
||||
|
||||
void content_about_license(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_about(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_about_license(PATH_ARGS);
|
||||
void content_about(PATH_ARGS);
|
||||
|
||||
#endif /* ABOUT_H */
|
||||
|
|
|
@ -299,7 +299,8 @@ void get_account_info(mastodont_t* api, struct session* ssn)
|
|||
}
|
||||
}
|
||||
|
||||
static void fetch_account_page(struct session* ssn,
|
||||
static void fetch_account_page(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
char* id,
|
||||
void* args,
|
||||
|
@ -347,7 +348,7 @@ static void fetch_account_page(struct session* ssn,
|
|||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
|
||||
/* Output */
|
||||
mstdnt_cleanup_account(&acct);
|
||||
|
@ -566,7 +567,7 @@ char* load_account_page(struct session* ssn,
|
|||
return result;
|
||||
}
|
||||
|
||||
void content_account_statuses(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_account_statuses(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_account_statuses_args args = {
|
||||
.pinned = 0,
|
||||
|
@ -582,25 +583,25 @@ void content_account_statuses(struct session* ssn, mastodont_t* api, char** data
|
|||
.limit = 20,
|
||||
};
|
||||
|
||||
fetch_account_page(ssn, api, data[0], &args, ACCT_TAB_STATUSES, account_statuses_cb);
|
||||
fetch_account_page(req, ssn, api, data[0], &args, ACCT_TAB_STATUSES, account_statuses_cb);
|
||||
}
|
||||
|
||||
void content_account_followers(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_account_followers(PATH_ARGS)
|
||||
{
|
||||
fetch_account_page(ssn, api, data[0], NULL, ACCT_TAB_NONE, account_followers_cb);
|
||||
fetch_account_page(req, ssn, api, data[0], NULL, ACCT_TAB_NONE, account_followers_cb);
|
||||
}
|
||||
|
||||
void content_account_following(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_account_following(PATH_ARGS)
|
||||
{
|
||||
fetch_account_page(ssn, api, data[0], NULL, ACCT_TAB_NONE, account_following_cb);
|
||||
fetch_account_page(req, ssn, api, data[0], NULL, ACCT_TAB_NONE, account_following_cb);
|
||||
}
|
||||
|
||||
void content_account_scrobbles(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_account_scrobbles(PATH_ARGS)
|
||||
{
|
||||
fetch_account_page(ssn, api, data[0], NULL, ACCT_TAB_SCROBBLES, account_scrobbles_cb);
|
||||
fetch_account_page(req, ssn, api, data[0], NULL, ACCT_TAB_SCROBBLES, account_scrobbles_cb);
|
||||
}
|
||||
|
||||
void content_account_pinned(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_account_pinned(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_account_statuses_args args = {
|
||||
.pinned = 1,
|
||||
|
@ -616,10 +617,10 @@ void content_account_pinned(struct session* ssn, mastodont_t* api, char** data)
|
|||
.limit = 20,
|
||||
};
|
||||
|
||||
fetch_account_page(ssn, api, data[0], &args, ACCT_TAB_PINNED, account_statuses_cb);
|
||||
fetch_account_page(req, ssn, api, data[0], &args, ACCT_TAB_PINNED, account_statuses_cb);
|
||||
}
|
||||
|
||||
void content_account_media(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_account_media(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_account_statuses_args args = {
|
||||
.pinned = 0,
|
||||
|
@ -635,12 +636,12 @@ void content_account_media(struct session* ssn, mastodont_t* api, char** data)
|
|||
.limit = 20,
|
||||
};
|
||||
|
||||
fetch_account_page(ssn, api, data[0], &args, ACCT_TAB_MEDIA, account_statuses_cb);
|
||||
fetch_account_page(req, ssn, api, data[0], &args, ACCT_TAB_MEDIA, account_statuses_cb);
|
||||
}
|
||||
|
||||
void content_account_action(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_account_action(PATH_ARGS)
|
||||
{
|
||||
char* referer = getenv("HTTP_REFERER");
|
||||
char* referer = GET_ENV("HTTP_REFERER", req);
|
||||
struct mstdnt_storage storage = { 0 };
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -665,10 +666,10 @@ void content_account_action(struct session* ssn, mastodont_t* api, char** data)
|
|||
|
||||
mastodont_storage_cleanup(&storage);
|
||||
|
||||
redirect(REDIRECT_303, referer);
|
||||
redirect(req, REDIRECT_303, referer);
|
||||
}
|
||||
|
||||
void content_account_bookmarks(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_account_bookmarks(PATH_ARGS)
|
||||
{
|
||||
size_t status_count = 0, statuses_html_count = 0;
|
||||
struct mstdnt_status* statuses = NULL;
|
||||
|
@ -722,7 +723,7 @@ void content_account_bookmarks(struct session* ssn, mastodont_t* api, char** dat
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
|
||||
// Cleanup
|
||||
mastodont_storage_cleanup(&storage);
|
||||
|
@ -732,7 +733,8 @@ void content_account_bookmarks(struct session* ssn, mastodont_t* api, char** dat
|
|||
free(output);
|
||||
}
|
||||
|
||||
static void accounts_page(mastodont_t* api,
|
||||
static void accounts_page(FCGX_Request* req,
|
||||
mastodont_t* api,
|
||||
struct session* ssn,
|
||||
struct mstdnt_storage* storage,
|
||||
char* header,
|
||||
|
@ -758,7 +760,7 @@ static void accounts_page(mastodont_t* api,
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
|
||||
mastodont_storage_cleanup(storage);
|
||||
free(output);
|
||||
|
@ -766,7 +768,7 @@ static void accounts_page(mastodont_t* api,
|
|||
}
|
||||
|
||||
|
||||
void content_account_blocked(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_account_blocked(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_account_args args = {
|
||||
.max_id = keystr(ssn->post.max_id),
|
||||
|
@ -784,11 +786,11 @@ void content_account_blocked(struct session* ssn, mastodont_t* api, char** data)
|
|||
|
||||
mastodont_get_blocks(api, &m_args, &args, &storage, &accts, &accts_len);
|
||||
|
||||
accounts_page(api, ssn, &storage, "Blocked users", accts, accts_len);
|
||||
accounts_page(req, api, ssn, &storage, "Blocked users", accts, accts_len);
|
||||
mstdnt_cleanup_accounts(accts, accts_len);
|
||||
}
|
||||
|
||||
void content_account_muted(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_account_muted(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_account_args args = {
|
||||
.max_id = keystr(ssn->post.max_id),
|
||||
|
@ -806,11 +808,11 @@ void content_account_muted(struct session* ssn, mastodont_t* api, char** data)
|
|||
|
||||
mastodont_get_mutes(api, &m_args, &args, &storage, &accts, &accts_len);
|
||||
|
||||
accounts_page(api, ssn, &storage, "Muted users", accts, accts_len);
|
||||
accounts_page(req, api, ssn, &storage, "Muted users", accts, accts_len);
|
||||
mstdnt_cleanup_accounts(accts, accts_len);
|
||||
}
|
||||
|
||||
void content_account_favourites(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_account_favourites(PATH_ARGS)
|
||||
{
|
||||
size_t status_count = 0, statuses_html_count = 0;
|
||||
struct mstdnt_status* statuses = NULL;
|
||||
|
@ -864,7 +866,7 @@ void content_account_favourites(struct session* ssn, mastodont_t* api, char** da
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
|
||||
// Cleanup
|
||||
mastodont_storage_cleanup(&storage);
|
||||
|
|
|
@ -83,16 +83,16 @@ char* load_account_page(struct session* ssn,
|
|||
char* load_account_info(struct mstdnt_account* acct,
|
||||
size_t* size);
|
||||
|
||||
void content_account_followers(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_account_following(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_account_statuses(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_account_scrobbles(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_account_pinned(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_account_blocked(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_account_muted(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_account_media(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_account_action(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_account_favourites(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_account_bookmarks(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_account_followers(PATH_ARGS);
|
||||
void content_account_following(PATH_ARGS);
|
||||
void content_account_statuses(PATH_ARGS);
|
||||
void content_account_scrobbles(PATH_ARGS);
|
||||
void content_account_pinned(PATH_ARGS);
|
||||
void content_account_blocked(PATH_ARGS);
|
||||
void content_account_muted(PATH_ARGS);
|
||||
void content_account_media(PATH_ARGS);
|
||||
void content_account_action(PATH_ARGS);
|
||||
void content_account_favourites(PATH_ARGS);
|
||||
void content_account_bookmarks(PATH_ARGS);
|
||||
|
||||
#endif // ACCOUNT_H
|
||||
|
|
|
@ -197,7 +197,7 @@ char* construct_attachments(struct session* ssn,
|
|||
return att_view;
|
||||
}
|
||||
|
||||
void api_attachment_create(struct session* ssn, mastodont_t* api, char** data)
|
||||
void api_attachment_create(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_storage *att_storage = NULL;
|
||||
struct mstdnt_attachment* attachments = NULL;
|
||||
|
@ -216,11 +216,11 @@ void api_attachment_create(struct session* ssn, mastodont_t* api, char** data)
|
|||
if (media_ids)
|
||||
{
|
||||
string = cJSON_Print(root);
|
||||
send_result(NULL, "application/json", string, 0);
|
||||
send_result(req, NULL, "application/json", string, 0);
|
||||
free(string);
|
||||
}
|
||||
else
|
||||
send_result(NULL, "application/json", "{\"status\":\"Couldn't\"}", 0);
|
||||
send_result(req, NULL, "application/json", "{\"status\":\"Couldn't\"}", 0);
|
||||
|
||||
// Cleanup media stuff
|
||||
cleanup_media_storages(ssn, att_storage);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#ifndef ATTACHMENTS_H
|
||||
#define ATTACHMENTS_H
|
||||
#include <mastodont.h>
|
||||
#include "path.h"
|
||||
#include "session.h"
|
||||
|
||||
#define FILES_READY(ssn) (ssn->post.files.type.f.array_size && \
|
||||
|
@ -34,6 +35,6 @@ void cleanup_media_storages(struct session* ssn, struct mstdnt_storage* storage)
|
|||
void cleanup_media_ids(struct session* ssn, char** media_ids);
|
||||
char* construct_attachment(struct session* ssn, mstdnt_bool sensitive, struct mstdnt_attachment* att, size_t* str_size);
|
||||
char* construct_attachments(struct session* ssn, mstdnt_bool sensitive, struct mstdnt_attachment* atts, size_t atts_len, size_t* str_size);
|
||||
void api_attachment_create(struct session* ssn, mastodont_t* api, char** data);
|
||||
void api_attachment_create(PATH_ARGS);
|
||||
|
||||
#endif // ATTACHMENTS_H
|
||||
|
|
|
@ -36,11 +36,11 @@
|
|||
|
||||
#define BODY_STYLE "style=\"background:url('%s');\""
|
||||
|
||||
void render_base_page(struct base_page* page, struct session* ssn, mastodont_t* api)
|
||||
void render_base_page(struct base_page* page, FCGX_Request* req, struct session* ssn, mastodont_t* api)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
char* cookie = getenv("HTTP_COOKIE");
|
||||
char* cookie = GET_ENV("HTTP_COOKIE", req);
|
||||
enum l10n_locale locale = l10n_normalize(ssn->config.lang);
|
||||
char* theme_str = NULL;
|
||||
const char* login_string = "<a href=\"login\" id=\"login-header\">Login / Register</a>";
|
||||
|
@ -189,7 +189,7 @@ void render_base_page(struct base_page* page, struct session* ssn, mastodont_t*
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
send_result(NULL, "text/html", data, len);
|
||||
send_result(req, NULL, "text/html", data, len);
|
||||
|
||||
// Cleanup
|
||||
/* cleanup_all: */
|
||||
|
@ -203,14 +203,23 @@ cleanup:
|
|||
free(theme_str);
|
||||
}
|
||||
|
||||
void send_result(char* status, char* content_type, char* data, size_t data_len)
|
||||
void send_result(FCGX_Request* req, char* status, char* content_type, char* data, size_t data_len)
|
||||
{
|
||||
if (data_len == 0) data_len = strlen(data);
|
||||
printf("Status: %s\r\n"
|
||||
"Content-type: %s\r\n"
|
||||
"Content-Length: %d\r\n\r\n",
|
||||
status ? status : "200 OK",
|
||||
content_type ? content_type : "text/html",
|
||||
data_len + 1);
|
||||
puts(data);
|
||||
#ifdef SINGLE_THREADED
|
||||
printf(
|
||||
#else
|
||||
FCGX_FPrintF(req->out,
|
||||
#endif
|
||||
"Status: %s\r\n"
|
||||
"Content-type: %s\r\n"
|
||||
"Content-Length: %d\r\n\r\n",
|
||||
status ? status : "200 OK",
|
||||
content_type ? content_type : "text/html",
|
||||
data_len + 1);
|
||||
#ifdef SINGLE_THREADED
|
||||
puts(data);
|
||||
#else
|
||||
FCGX_PutStr(data, data_len, req->out);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -18,9 +18,12 @@
|
|||
|
||||
#ifndef BASE_PAGE_H
|
||||
#define BASE_PAGE_H
|
||||
#include <fcgi_stdio.h>
|
||||
#include <fcgiapp.h>
|
||||
#include <mastodont.h>
|
||||
#include "l10n.h"
|
||||
#include "local_config.h"
|
||||
#include "path.h"
|
||||
#include "session.h"
|
||||
|
||||
enum base_category
|
||||
|
@ -45,16 +48,17 @@ struct base_page
|
|||
char* sidebar_left;
|
||||
};
|
||||
|
||||
void render_base_page(struct base_page* page, struct session* ssn, mastodont_t* api);
|
||||
void render_base_page(struct base_page* page, FCGX_Request* req, struct session* ssn, mastodont_t* api);
|
||||
|
||||
/**
|
||||
* Outputs HTML in format for CGI. This can only be called once!
|
||||
*
|
||||
* @param req The FCGI request
|
||||
* @param status The full HTTP status. if NULL, then status is "200 OK"
|
||||
* @param content_type The Content-Type to display. if NULL, assume "text/html"
|
||||
* @param data HTML content
|
||||
* @param data_len Length of data. If 0, calls strlen(data)
|
||||
*/
|
||||
void send_result(char* status, char* content_type, char* data, size_t data_len);
|
||||
void send_result(FCGX_Request* req, char* status, char* content_type, char* data, size_t data_len);
|
||||
|
||||
#endif // BASE_PAGE_H
|
||||
|
|
|
@ -156,7 +156,7 @@ char* construct_chats_view(char* lists_string, size_t* size)
|
|||
return tmpl_gen_chats_page(&data, size);
|
||||
}
|
||||
|
||||
void content_chats(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_chats(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -193,7 +193,7 @@ void content_chats(struct session* ssn, mastodont_t* api, char** data)
|
|||
};
|
||||
|
||||
// Outpuot
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
|
||||
// Cleanup
|
||||
mastodont_storage_cleanup(&storage);
|
||||
|
@ -256,7 +256,7 @@ char* construct_chat_view(struct session* ssn, mastodont_t* api, char* id, size_
|
|||
return chats_page;
|
||||
}
|
||||
|
||||
void content_chat_view(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_chat_view(PATH_ARGS)
|
||||
{
|
||||
char* chat_view = construct_chat_view(ssn, api, data[0], NULL);
|
||||
|
||||
|
@ -267,13 +267,13 @@ void content_chat_view(struct session* ssn, mastodont_t* api, char** data)
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
|
||||
free(chat_view);
|
||||
}
|
||||
|
||||
|
||||
void content_chat_embed(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_chat_embed(PATH_ARGS)
|
||||
{
|
||||
size_t result_len;
|
||||
char* result;
|
||||
|
@ -287,7 +287,7 @@ void content_chat_embed(struct session* ssn, mastodont_t* api, char** data)
|
|||
result = tmpl_gen_embed(&tmpl, &result_len);
|
||||
|
||||
// Output
|
||||
send_result(NULL, NULL, result, result_len);
|
||||
send_result(req, NULL, NULL, result, result_len);
|
||||
|
||||
free(chat_view);
|
||||
free(result);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#ifndef CONVERSATIONS_H
|
||||
#define CONVERSATIONS_H
|
||||
#include "path.h"
|
||||
#include <stddef.h>
|
||||
#include <mastodont.h>
|
||||
#include "session.h"
|
||||
|
@ -43,9 +44,9 @@ char* construct_messages(struct mstdnt_message* message,
|
|||
size_t size,
|
||||
size_t* ret_size);
|
||||
|
||||
void content_chats(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_chats(PATH_ARGS);
|
||||
char* construct_chat_view(struct session* ssn, mastodont_t* api, char* id, size_t* len);
|
||||
void content_chat_embed(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_chat_view(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_chat_embed(PATH_ARGS);
|
||||
void content_chat_view(PATH_ARGS);
|
||||
|
||||
#endif // LISTS_H
|
||||
|
|
|
@ -17,9 +17,11 @@
|
|||
*/
|
||||
|
||||
#include <fcgi_stdio.h>
|
||||
#include <fcgiapp.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "cookie.h"
|
||||
#include "env.h"
|
||||
|
||||
enum cookie_state
|
||||
{
|
||||
|
@ -29,12 +31,10 @@ enum cookie_state
|
|||
STATE_V_START,
|
||||
};
|
||||
|
||||
char* read_cookies_env(struct cookie_values* cookies)
|
||||
char* read_cookies_env(FCGX_Request* req, struct cookie_values* cookies)
|
||||
{
|
||||
struct http_cookie_info info;
|
||||
char* cookies_env = getenv("HTTP_COOKIE");
|
||||
|
||||
// Is it even work bothering with?
|
||||
char* cookies_env = GET_ENV("HTTP_COOKIE", req);
|
||||
if (!cookies_env)
|
||||
return NULL;
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ struct http_cookie_info
|
|||
|
||||
// Stupidly fast simple cookie parser
|
||||
char* parse_cookies(char* begin, struct http_cookie_info* info);
|
||||
char* read_cookies_env(struct cookie_values* cookies);
|
||||
char* read_cookies_env(FCGX_Request* req, struct cookie_values* cookies);
|
||||
int cookie_get_val(char* src, char* key, struct http_cookie_info* info);
|
||||
|
||||
#endif // COOKIE_H
|
||||
|
|
|
@ -110,11 +110,11 @@ static char* construct_emoji_voidwrap(void* passed, size_t index, size_t* res)
|
|||
|
||||
#define EMOJI_PICKER_ARGS(this_index) { .status_id = status_id, .index = this_index }
|
||||
|
||||
void content_emoji_picker(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_emoji_picker(PATH_ARGS)
|
||||
{
|
||||
char* picker = construct_emoji_picker(NULL, NULL);
|
||||
|
||||
send_result(NULL, NULL, picker, 0);
|
||||
send_result(req, NULL, NULL, picker, 0);
|
||||
|
||||
free(picker);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ enum emoji_picker_cat
|
|||
|
||||
char* emojify(char* content, struct mstdnt_emoji* emos, size_t emos_len);
|
||||
char* construct_emoji(struct emoji_info* emoji, char* status_id, size_t* size);
|
||||
void content_emoji_picker(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_emoji_picker(PATH_ARGS);
|
||||
char* construct_emoji_picker(char* status_id, size_t* size);
|
||||
|
||||
#endif // EMOJI_H
|
||||
|
|
|
@ -48,7 +48,7 @@ char* construct_error(const char* error, enum error_type type, unsigned pad, siz
|
|||
return tmpl_gen_error(&data, size);
|
||||
}
|
||||
|
||||
void content_not_found(struct session* ssn, mastodont_t* api, char* path)
|
||||
void content_not_found(FCGX_Request* req, struct session* ssn, mastodont_t* api, char* path)
|
||||
{
|
||||
char* page;
|
||||
struct error_404_template data = {
|
||||
|
@ -61,6 +61,6 @@ void content_not_found(struct session* ssn, mastodont_t* api, char* path)
|
|||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
free(page);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <mastodont.h>
|
||||
#include <stddef.h>
|
||||
#include "session.h"
|
||||
#include "path.h"
|
||||
|
||||
enum error_type
|
||||
{
|
||||
|
@ -30,6 +31,6 @@ enum error_type
|
|||
};
|
||||
|
||||
char* construct_error(const char* error, enum error_type type, unsigned pad, size_t* size);
|
||||
void content_not_found(struct session* ssn, mastodont_t* api, char* path);
|
||||
void content_not_found(FCGX_Request* req, struct session* ssn, mastodont_t* api, char* path);
|
||||
|
||||
#endif // ERROR_H
|
||||
|
|
15
src/http.c
15
src/http.c
|
@ -27,14 +27,15 @@
|
|||
#define REDIR_HTML_END "</body>" \
|
||||
"</html>"
|
||||
|
||||
void redirect(char* status, char* location)
|
||||
void redirect(FCGX_Request* req, char* status, char* location)
|
||||
{
|
||||
char* loc_str = location ? location : "/";
|
||||
|
||||
printf("Status: %s\r\n"
|
||||
"Location: %s\r\n\r\n"
|
||||
REDIR_HTML_BEGIN "Redirecting to <a href=\"\">%s</a>..." REDIR_HTML_END,
|
||||
status,
|
||||
loc_str,
|
||||
loc_str);
|
||||
FCGX_FPrintF(req->out,
|
||||
"Status: %s\r\n"
|
||||
"Location: %s\r\n\r\n"
|
||||
REDIR_HTML_BEGIN "Redirecting to <a href=\"\">%s</a>..." REDIR_HTML_END,
|
||||
status,
|
||||
loc_str,
|
||||
loc_str);
|
||||
}
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
#ifndef HTTP_H
|
||||
#define HTTP_H
|
||||
#include <fcgi_stdio.h>
|
||||
#include <fcgiapp.h>
|
||||
|
||||
#define REDIRECT_303 "303 See Other"
|
||||
|
||||
void redirect(char* status, char* location);
|
||||
void redirect(FCGX_Request* req, char* status, char* location);
|
||||
|
||||
#endif // HTTP_H
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
#include <stdlib.h>
|
||||
#include "timeline.h"
|
||||
|
||||
void content_index(struct session* ssn, mastodont_t* api)
|
||||
void content_index(FCGX_Request* req, struct session* ssn, mastodont_t* api)
|
||||
{
|
||||
// Check logins
|
||||
content_tl_home(ssn, api, NULL);
|
||||
content_tl_home(req, ssn, api, NULL);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,6 @@
|
|||
#include <mastodont.h>
|
||||
#include "session.h"
|
||||
|
||||
void content_index(struct session* ssn, mastodont_t* api);
|
||||
void content_index(FCGX_Request* req, struct session* ssn, mastodont_t* api);
|
||||
|
||||
#endif // INDEX_H
|
||||
|
|
|
@ -68,7 +68,7 @@ char* construct_lists_view(char* lists_string, size_t* size)
|
|||
return tmpl_gen_lists(&data, size);
|
||||
}
|
||||
|
||||
void content_lists(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_lists(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -107,7 +107,7 @@ void content_lists(struct session* ssn, mastodont_t* api, char** data)
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
|
||||
// Cleanup
|
||||
mastodont_storage_cleanup(&storage);
|
||||
|
@ -116,7 +116,7 @@ void content_lists(struct session* ssn, mastodont_t* api, char** data)
|
|||
mstdnt_cleanup_lists(lists);
|
||||
}
|
||||
|
||||
void list_edit(struct session* ssn, mastodont_t* api, char** data)
|
||||
void list_edit(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -136,6 +136,6 @@ void list_edit(struct session* ssn, mastodont_t* api, char** data)
|
|||
&storage,
|
||||
NULL);
|
||||
|
||||
redirect(REDIRECT_303, referer);
|
||||
redirect(req, REDIRECT_303, referer);
|
||||
mastodont_storage_cleanup(&storage);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
char* construct_list(struct mstdnt_list* list, size_t* size);
|
||||
char* construct_lists(struct mstdnt_list* lists, size_t size, size_t* ret_size);
|
||||
char* construct_lists_view(char* lists_string, size_t* size);
|
||||
void content_lists(struct session* ssn, mastodont_t* api, char** data);
|
||||
void list_edit(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_lists(PATH_ARGS);
|
||||
void list_edit(PATH_ARGS);
|
||||
|
||||
#endif // LISTS_H
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <fcgi_stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "local_config_set.h"
|
||||
|
||||
#define post_bool_intp(post) (post->is_set ? keypint(post) : 0)
|
||||
|
||||
void set_config_str(struct session* ssn,
|
||||
void set_config_str(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
char** v,
|
||||
char* cookie_name,
|
||||
struct key* post,
|
||||
|
@ -34,8 +34,9 @@ void set_config_str(struct session* ssn,
|
|||
{
|
||||
if (ssn->post.set.is_set && post->is_set && page == curr_page)
|
||||
{
|
||||
printf("Set-Cookie: %s=%s; HttpOnly; Path=/; Max-Age=31536000; SameSite=Strict;\r\n",
|
||||
cookie_name, keypstr(post));
|
||||
FCGX_FPrintF(req->out,
|
||||
"Set-Cookie: %s=%s; HttpOnly; Path=/; Max-Age=31536000; SameSite=Strict;\r\n",
|
||||
cookie_name, keypstr(post));
|
||||
}
|
||||
|
||||
if ((ssn->post.set.is_set && post->is_set) || cookie->is_set)
|
||||
|
@ -44,10 +45,10 @@ void set_config_str(struct session* ssn,
|
|||
else
|
||||
// Set it to the cookie
|
||||
*v = keypstr(cookie);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void set_config_int(struct session* ssn,
|
||||
void set_config_int(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
int* v,
|
||||
char* cookie_name,
|
||||
struct key* post,
|
||||
|
@ -59,8 +60,9 @@ void set_config_int(struct session* ssn,
|
|||
{
|
||||
if (ssn->post.set.is_set && page == curr_page)
|
||||
{
|
||||
printf("Set-Cookie: %s=%d; HttpOnly; Path=/; Max-Age=31536000; SameSite=Strict;\r\n",
|
||||
cookie_name, post_bool_intp(post));
|
||||
FCGX_FPrintF(req->out,
|
||||
"Set-Cookie: %s=%d; HttpOnly; Path=/; Max-Age=31536000; SameSite=Strict;\r\n",
|
||||
cookie_name, post_bool_intp(post));
|
||||
}
|
||||
|
||||
// Checks if boolean option
|
||||
|
@ -70,14 +72,15 @@ void set_config_int(struct session* ssn,
|
|||
}
|
||||
else
|
||||
*v = keypint(cookie);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Shorthand for the arguments passed into functions below
|
||||
#define LOAD_CFG_SIM(strcookie, varname) ssn, &(ssn->config.varname), (strcookie), &(ssn->post.varname), &(ssn->cookies.varname), page
|
||||
#define LOAD_CFG_SIM(strcookie, varname) req, ssn, &(ssn->config.varname), (strcookie), &(ssn->post.varname), &(ssn->cookies.varname), page
|
||||
|
||||
struct mstdnt_storage* load_config(struct session* ssn, mastodont_t* api, enum config_page page)
|
||||
struct mstdnt_storage* load_config(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
enum config_page page)
|
||||
{
|
||||
struct mstdnt_attachment* attachments = NULL;
|
||||
struct mstdnt_storage* storage = NULL;
|
||||
|
@ -87,7 +90,7 @@ struct mstdnt_storage* load_config(struct session* ssn, mastodont_t* api, enum c
|
|||
try_upload_media(&storage, ssn, api, &attachments, NULL);
|
||||
}
|
||||
struct key atm = { .type.s = attachments ? attachments[0].url : NULL, .is_set = attachments ? 1 : 0 };
|
||||
set_config_str(ssn, &(ssn->config.background_url), "background_url", &(atm), &(ssn->cookies.background_url), page, CONFIG_APPEARANCE);
|
||||
set_config_str(req, ssn, &(ssn->config.background_url), "background_url", &(atm), &(ssn->cookies.background_url), page, CONFIG_APPEARANCE);
|
||||
set_config_int(LOAD_CFG_SIM("sidebaropacity", sidebar_opacity), CONFIG_APPEARANCE);
|
||||
set_config_str(LOAD_CFG_SIM("theme", theme), CONFIG_APPEARANCE);
|
||||
set_config_int(LOAD_CFG_SIM("themeclr", themeclr), CONFIG_APPEARANCE);
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#ifndef LOCAL_CONFIG_SET_H
|
||||
#define LOCAL_CONFIG_SET_H
|
||||
#include <mastodont.h>
|
||||
#include <fcgi_stdio.h>
|
||||
#include <fcgiapp.h>
|
||||
#include "local_config.h"
|
||||
#include "session.h"
|
||||
#include "attachments.h"
|
||||
|
@ -30,52 +32,57 @@ enum config_page
|
|||
CONFIG_APPEARANCE,
|
||||
};
|
||||
|
||||
/*!
|
||||
/**
|
||||
* Sets a config string
|
||||
*
|
||||
* \param ssn The session to modify
|
||||
* \param v The (config) character pointer to modify
|
||||
* \param cookie_name The cookie name to match
|
||||
* \param post The post value to check
|
||||
* \param cookie The cookie value to store into
|
||||
* \param page The page that this value is expected to be set on.
|
||||
* \param curr_page The page to check against
|
||||
* @param ssn The session to modify
|
||||
* @param v The (config) character pointer to modify
|
||||
* @param cookie_name The cookie name to match
|
||||
* @param post The post value to check
|
||||
* @param cookie The cookie value to store into
|
||||
* @param page The page that this value is expected to be set on.
|
||||
* @param curr_page The page to check against
|
||||
*/
|
||||
void set_config_str(struct session* ssn,
|
||||
char** v,
|
||||
char* cookie_name,
|
||||
struct key* post,
|
||||
struct key* cookie,
|
||||
enum config_page page,
|
||||
enum config_page curr_page);
|
||||
void set_config_str(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
char** v,
|
||||
char* cookie_name,
|
||||
struct key* post,
|
||||
struct key* cookie,
|
||||
enum config_page page,
|
||||
enum config_page curr_page);
|
||||
|
||||
/*!
|
||||
/**
|
||||
* Sets a config integer
|
||||
*
|
||||
* \param ssn The session to modify
|
||||
* \param v The (config) integer pointer to modify
|
||||
* \param cookie_name The cookie name to match
|
||||
* \param post The post value to check
|
||||
* \param cookie The cookie value to store into
|
||||
* \param page The page that this value is expected to be set on.
|
||||
* \param curr_page The page to check against
|
||||
* @param ssn The session to modify
|
||||
* @param v The (config) integer pointer to modify
|
||||
* @param cookie_name The cookie name to match
|
||||
* @param post The post value to check
|
||||
* @param cookie The cookie value to store into
|
||||
* @param page The page that this value is expected to be set on.
|
||||
* @param curr_page The page to check against
|
||||
*/
|
||||
void set_config_int(struct session* ssn,
|
||||
int* v,
|
||||
char* cookie_name,
|
||||
struct key* post,
|
||||
struct key* cookie,
|
||||
enum config_page page,
|
||||
enum config_page curr_page);
|
||||
void set_config_int(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
int* v,
|
||||
char* cookie_name,
|
||||
struct key* post,
|
||||
struct key* cookie,
|
||||
enum config_page page,
|
||||
enum config_page curr_page);
|
||||
|
||||
/*!
|
||||
/**
|
||||
* Loads the config and sets the values based on POST or session
|
||||
*
|
||||
* \param ssn The session
|
||||
* \param api mastodont-c api
|
||||
* \param page Page enum, to ensure that config changes on different pages don't effect other cookies
|
||||
* \return Storage if files were uploaded, must free. This might change
|
||||
* @param ssn The session
|
||||
* @param api mastodont-c api
|
||||
* @param page Page enum, to ensure that config changes on different pages don't effect other cookies
|
||||
* @return Storage if files were uploaded, must free. This might change
|
||||
*/
|
||||
struct mstdnt_storage* load_config(struct session* ssn, mastodont_t* api, enum config_page page);
|
||||
struct mstdnt_storage* load_config(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
enum config_page page);
|
||||
|
||||
#endif // LOCAL_CONFIG_SET_H
|
||||
|
|
32
src/login.c
32
src/login.c
|
@ -34,16 +34,16 @@
|
|||
|
||||
#define LOGIN_SCOPE "read+write+follow+push"
|
||||
|
||||
void apply_access_token(char* token)
|
||||
void apply_access_token(FCGX_Request* req, char* token)
|
||||
{
|
||||
printf("Set-Cookie: access_token=%s; Path=/; Max-Age=31536000\r\n", token);
|
||||
printf("Set-Cookie: logged_in=t; Path=/; Max-Age=31536000\r\n");
|
||||
FCGX_FPrintF(req->out, "Set-Cookie: access_token=%s; Path=/; Max-Age=31536000\r\n", token);
|
||||
FCGX_FPrintF(req->out, "Set-Cookie: logged_in=t; Path=/; Max-Age=31536000\r\n");
|
||||
// if config_url_prefix is empty, make it root
|
||||
redirect(REDIRECT_303, config_url_prefix &&
|
||||
redirect(req, REDIRECT_303, config_url_prefix &&
|
||||
config_url_prefix[0] != '\0' ? config_url_prefix : "/");
|
||||
}
|
||||
|
||||
void content_login_oauth(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_login_oauth(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -75,7 +75,7 @@ void content_login_oauth(struct session* ssn, mastodont_t* api, char** data)
|
|||
&oauth_storage,
|
||||
&token) == 0)
|
||||
{
|
||||
apply_access_token(token.access_token);
|
||||
apply_access_token(req, token.access_token);
|
||||
}
|
||||
}
|
||||
else if (keystr(ssn->post.instance))
|
||||
|
@ -102,11 +102,11 @@ void content_login_oauth(struct session* ssn, mastodont_t* api, char** data)
|
|||
decode_url, encode_id, urlify_redirect_url);
|
||||
|
||||
// Set cookie and redirect
|
||||
printf("Set-Cookie: instance_url=%s; Path=/; Max-Age=3153600\r\n", decode_url);
|
||||
printf("Set-Cookie: client_id=%s; Path=/; Max-Age=3153600\r\n", app.client_id);
|
||||
printf("Set-Cookie: client_secret=%s; Path=/; Max-Age=3153600\r\n", app.client_secret);
|
||||
FCGX_FPrintF(req->out, "Set-Cookie: instance_url=%s; Path=/; Max-Age=3153600\r\n", decode_url);
|
||||
FCGX_FPrintF(req->out, "Set-Cookie: client_id=%s; Path=/; Max-Age=3153600\r\n", app.client_id);
|
||||
FCGX_FPrintF(req->out, "Set-Cookie: client_secret=%s; Path=/; Max-Age=3153600\r\n", app.client_secret);
|
||||
|
||||
redirect(REDIRECT_303, url);
|
||||
redirect(req, REDIRECT_303, url);
|
||||
free(url);
|
||||
curl_free(encode_id);
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ void content_login_oauth(struct session* ssn, mastodont_t* api, char** data)
|
|||
|
||||
m_args.url = orig_url;
|
||||
|
||||
redirect(REDIRECT_303, config_url_prefix &&
|
||||
redirect(req, REDIRECT_303, config_url_prefix &&
|
||||
config_url_prefix[0] != '\0' ? config_url_prefix : "/");
|
||||
|
||||
mastodont_storage_cleanup(&storage);
|
||||
|
@ -123,7 +123,7 @@ void content_login_oauth(struct session* ssn, mastodont_t* api, char** data)
|
|||
if (decode_url) curl_free(decode_url);
|
||||
}
|
||||
|
||||
void content_login(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_login(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -187,12 +187,12 @@ void content_login(struct session* ssn, mastodont_t* api, char** data)
|
|||
}
|
||||
else {
|
||||
if (url_link)
|
||||
printf("Set-Cookie: instance_url=%s; Path=/; Max-Age=31536000\r\n", url_link);
|
||||
FCGX_FPrintF(req->out, "Set-Cookie: instance_url=%s; Path=/; Max-Age=31536000\r\n", url_link);
|
||||
else
|
||||
// Clear
|
||||
printf("Set-Cookie: instance_url=; Path=/; Max-Age=-1\r\n");
|
||||
FCGX_FPrintF(req->out, "Set-Cookie: instance_url=; Path=/; Max-Age=-1\r\n");
|
||||
|
||||
apply_access_token(token.access_token);
|
||||
apply_access_token(req, token.access_token);
|
||||
free(url_link);
|
||||
return;
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ void content_login(struct session* ssn, mastodont_t* api, char** data)
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
|
||||
// Cleanup
|
||||
mastodont_storage_cleanup(&storage);
|
||||
|
|
|
@ -21,8 +21,9 @@
|
|||
#include <stddef.h>
|
||||
#include <mastodont.h>
|
||||
#include "session.h"
|
||||
#include "path.h"
|
||||
|
||||
void content_login_oauth(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_login(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_login_oauth(PATH_ARGS);
|
||||
void content_login(PATH_ARGS);
|
||||
|
||||
#endif // LOGIN_H
|
||||
|
|
13
src/main.c
13
src/main.c
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include <pthread.h>
|
||||
#include <fcgi_stdio.h>
|
||||
#include <fcgiapp.h>
|
||||
#include <string.h>
|
||||
#include <mastodont.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -138,21 +139,21 @@ static void application(mastodont_t* api, FCGX_Request* req)
|
|||
};
|
||||
|
||||
// Load cookies
|
||||
char* cookies_str = read_cookies_env(&(ssn.cookies));
|
||||
char* post_str = read_post_data(&(ssn.post));
|
||||
char* get_str = read_get_data(&(ssn.query));
|
||||
char* cookies_str = read_cookies_env(req, &(ssn.cookies));
|
||||
char* post_str = read_post_data(req, &(ssn.post));
|
||||
char* get_str = read_get_data(req, &(ssn.query));
|
||||
|
||||
// Read config options
|
||||
enum config_page page = CONFIG_GENERAL;
|
||||
char* path_info = GET_ENV("PATH_INFO", req);
|
||||
if (path_info && strcmp(path_info, "/config/appearance") == 0)
|
||||
page = CONFIG_APPEARANCE;
|
||||
struct mstdnt_storage* attachments = load_config(&ssn, api, page);
|
||||
struct mstdnt_storage* attachments = load_config(req, &ssn, api, page);
|
||||
|
||||
// Load current account information
|
||||
get_account_info(api, &ssn);
|
||||
|
||||
handle_paths(&ssn, api, paths, sizeof(paths)/sizeof(paths[0]));
|
||||
handle_paths(req, &ssn, api, paths, sizeof(paths)/sizeof(paths[0]));
|
||||
|
||||
// Cleanup
|
||||
if (cookies_str) free(cookies_str);
|
||||
|
@ -208,7 +209,7 @@ int main(void)
|
|||
pthread_create(&id[i], NULL, cgi_start, &api);
|
||||
|
||||
// Hell, let's not sit around here either
|
||||
application(&api, NULL);
|
||||
cgi_start(&api);
|
||||
|
||||
|
||||
free_instance_info_cache();
|
||||
|
|
|
@ -27,10 +27,10 @@
|
|||
char* get_mime_boundary(char* content_type_str, char** bound)
|
||||
{
|
||||
// If neither values are set, get out
|
||||
if (!(getenv("CONTENT_TYPE") || content_type_str))
|
||||
if (!content_type_str)
|
||||
return NULL;
|
||||
|
||||
char* content = content_type_str ? content_type_str : getenv("CONTENT_TYPE");
|
||||
char* content = content_type_str;
|
||||
|
||||
// Data gets changed in place
|
||||
char* content_type = malloc(strlen(content)+1);
|
||||
|
|
|
@ -190,7 +190,7 @@ char* construct_notifications_compact(struct session* ssn,
|
|||
ret_size);
|
||||
}
|
||||
|
||||
void content_notifications(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_notifications(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -250,14 +250,14 @@ void content_notifications(struct session* ssn, mastodont_t* api, char** data)
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
mastodont_storage_cleanup(&storage);
|
||||
if (notif_html) free(notif_html);
|
||||
if (navigation_box) free(navigation_box);
|
||||
if (page) free(page);
|
||||
}
|
||||
|
||||
void content_notifications_compact(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_notifications_compact(PATH_ARGS)
|
||||
{
|
||||
char* theme_str = NULL;
|
||||
struct mstdnt_args m_args;
|
||||
|
@ -327,7 +327,7 @@ void content_notifications_compact(struct session* ssn, mastodont_t* api, char**
|
|||
|
||||
page = tmpl_gen_notifications_embed(&tdata, &len);
|
||||
|
||||
send_result(NULL, NULL, page, len);
|
||||
send_result(req, NULL, NULL, page, len);
|
||||
|
||||
mastodont_storage_cleanup(&storage);
|
||||
free(notif_html);
|
||||
|
@ -336,7 +336,7 @@ void content_notifications_compact(struct session* ssn, mastodont_t* api, char**
|
|||
free(theme_str);
|
||||
}
|
||||
|
||||
void api_notifications(struct session* ssn, mastodont_t* api, char** data)
|
||||
void api_notifications(PATH_ARGS)
|
||||
{
|
||||
send_result(NULL, "application/json", "{\"status\":0}", 0);
|
||||
send_result(req, NULL, "application/json", "{\"status\":0}", 0);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,10 @@
|
|||
#ifndef NOTIFICATIONS_H
|
||||
#define NOTIFICATIONS_H
|
||||
#include <mastodont.h>
|
||||
#include <fcgi_stdio.h>
|
||||
#include <fcgiapp.h>
|
||||
#include "session.h"
|
||||
#include "path.h"
|
||||
#include "type_string.h"
|
||||
|
||||
char* construct_notification(struct session* ssn,
|
||||
|
@ -43,9 +46,9 @@ char* construct_notifications_compact(struct session* ssn,
|
|||
size_t* ret_size);
|
||||
|
||||
// Page contents
|
||||
void content_notifications(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_notifications_compact(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_notifications(PATH_ARGS);
|
||||
void content_notifications_compact(PATH_ARGS);
|
||||
|
||||
void api_notifications(struct session* ssn, mastodont_t* api, char** data);
|
||||
void api_notifications(PATH_ARGS);
|
||||
|
||||
#endif // NOTIFICATION_H
|
||||
|
|
|
@ -59,7 +59,7 @@ static char* construct_config_sidebar(enum config_category cat, size_t* size)
|
|||
return tmpl_gen_config_sidebar(&tdata, size);
|
||||
}
|
||||
|
||||
void content_config_general(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_config_general(PATH_ARGS)
|
||||
{
|
||||
char* sidebar_html = construct_config_sidebar(CONFIG_CAT_GENERAL, NULL);
|
||||
|
||||
|
@ -87,14 +87,14 @@ void content_config_general(struct session* ssn, mastodont_t* api, char** data)
|
|||
.sidebar_left = sidebar_html
|
||||
};
|
||||
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
// Cleanup
|
||||
free(sidebar_html);
|
||||
free(general_page);
|
||||
}
|
||||
|
||||
|
||||
void content_config_appearance(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_config_appearance(PATH_ARGS)
|
||||
{
|
||||
char* sidebar_html = construct_config_sidebar(CONFIG_CAT_APPEARANCE, NULL);
|
||||
|
||||
|
@ -104,12 +104,12 @@ void content_config_appearance(struct session* ssn, mastodont_t* api, char** dat
|
|||
.sidebar_left = sidebar_html
|
||||
};
|
||||
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
// Cleanup
|
||||
free(sidebar_html);
|
||||
}
|
||||
|
||||
void content_config(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_config(PATH_ARGS)
|
||||
{
|
||||
redirect(REDIRECT_303, "/config/general");
|
||||
redirect(req, REDIRECT_303, "/config/general");
|
||||
}
|
||||
|
|
|
@ -20,11 +20,14 @@
|
|||
#define PAGE_CONFIG_H
|
||||
#include <stddef.h>
|
||||
#include <mastodont.h>
|
||||
#include <fcgi_stdio.h>
|
||||
#include <fcgiapp.h>
|
||||
#include "path.h"
|
||||
#include "session.h"
|
||||
|
||||
void content_config_appearance(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_config_general(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_config_account(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_config(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_config_appearance(PATH_ARGS);
|
||||
void content_config_general(PATH_ARGS);
|
||||
void content_config_account(PATH_ARGS);
|
||||
void content_config(PATH_ARGS);
|
||||
|
||||
#endif // PAGE_CONFIG_H
|
||||
|
|
18
src/path.c
18
src/path.c
|
@ -23,14 +23,15 @@
|
|||
#include "account.h"
|
||||
#include "error.h"
|
||||
|
||||
int parse_path(struct session* ssn,
|
||||
int parse_path(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
struct path_info* path_info)
|
||||
{
|
||||
int res = 0;
|
||||
int fail = 0, fin = 0;
|
||||
char* p = path_info->path + 1;
|
||||
char* p2 = getenv("PATH_INFO") + 1;
|
||||
char* p2 = GET_ENV("PATH_INFO", req) + 1;
|
||||
|
||||
// Stored into data
|
||||
char* tmp = NULL;
|
||||
|
@ -84,7 +85,7 @@ int parse_path(struct session* ssn,
|
|||
breakpt:
|
||||
if (!fail)
|
||||
{
|
||||
path_info->callback(ssn, api, data);
|
||||
path_info->callback(req, ssn, api, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -100,25 +101,26 @@ breakpt:
|
|||
return res;
|
||||
}
|
||||
|
||||
void handle_paths(struct session* ssn,
|
||||
void handle_paths(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
struct path_info* paths,
|
||||
size_t paths_len)
|
||||
{
|
||||
char* path = getenv("PATH_INFO");
|
||||
char* path = GET_ENV("PATH_INFO", req);
|
||||
// "default" path
|
||||
if (path == NULL || (path && strcmp(path, "/") == 0))
|
||||
{
|
||||
content_index(ssn, api);
|
||||
content_index(req, ssn, api);
|
||||
}
|
||||
else { // Generic path
|
||||
for (size_t i = 0; i < paths_len; ++i)
|
||||
{
|
||||
if (parse_path(ssn, api, paths + i) == 0)
|
||||
if (parse_path(req, ssn, api, paths + i) == 0)
|
||||
return;
|
||||
}
|
||||
|
||||
// Fell out, return 404
|
||||
content_not_found(ssn, api, path);
|
||||
content_not_found(req, ssn, api, path);
|
||||
}
|
||||
}
|
||||
|
|
15
src/path.h
15
src/path.h
|
@ -18,24 +18,29 @@
|
|||
|
||||
#ifndef PATH_H
|
||||
#define PATH_H
|
||||
#include <fcgi_stdio.h>
|
||||
#include <fcgiapp.h>
|
||||
#include <mastodont.h>
|
||||
#include <stddef.h>
|
||||
#include "env.h"
|
||||
#include "session.h"
|
||||
|
||||
#define PATH_ARGS FCGX_Request* req, struct session* ssn, mastodont_t* api, char** data
|
||||
|
||||
struct path_info
|
||||
{
|
||||
char* path;
|
||||
void (*callback)(struct session* ssn,
|
||||
mastodont_t*,
|
||||
char**);
|
||||
void (*callback)(PATH_ARGS);
|
||||
};
|
||||
|
||||
void handle_paths(struct session* ssn,
|
||||
void handle_paths(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
struct path_info* paths,
|
||||
size_t paths_len);
|
||||
|
||||
int parse_path(struct session* ssn,
|
||||
int parse_path(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
struct path_info* path_info);
|
||||
|
||||
|
|
28
src/query.c
28
src/query.c
|
@ -17,17 +17,19 @@
|
|||
*/
|
||||
|
||||
#include <fcgi_stdio.h>
|
||||
#include <fcgiapp.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "query.h"
|
||||
#include "env.h"
|
||||
#include "mime.h"
|
||||
|
||||
char* read_get_data(struct get_values* query)
|
||||
char* read_get_data(FCGX_Request* req, struct get_values* query)
|
||||
{
|
||||
struct http_query_info info = { 0 };
|
||||
char* query_string = getenv("QUERY_STRING");
|
||||
char* query_string = GET_ENV("QUERY_STRING", req);
|
||||
char* get_query = NULL, *g_query_read;
|
||||
|
||||
// BEGIN Query references
|
||||
|
@ -73,14 +75,14 @@ char* read_get_data(struct get_values* query)
|
|||
|
||||
|
||||
|
||||
char* read_post_data(struct post_values* post)
|
||||
char* read_post_data(FCGX_Request* req, struct post_values* post)
|
||||
{
|
||||
ptrdiff_t begin_curr_size;
|
||||
struct http_query_info query_info;
|
||||
struct http_form_info form_info;
|
||||
struct file_content form_props;
|
||||
char* request_method = getenv("REQUEST_METHOD");
|
||||
char* content_length = getenv("CONTENT_LENGTH");
|
||||
char* request_method = GET_ENV("REQUEST_METHOD", req);
|
||||
char* content_length = GET_ENV("CONTENT_LENGTH", req);
|
||||
char* post_query = NULL, *p_query_read;
|
||||
|
||||
// BEGIN Query references
|
||||
|
@ -130,8 +132,8 @@ char* read_post_data(struct post_values* post)
|
|||
content_length)
|
||||
{
|
||||
char* mime_boundary;
|
||||
char* mime_mem = get_mime_boundary(NULL, &mime_boundary);
|
||||
int content_length = atoi(getenv("CONTENT_LENGTH"));
|
||||
char* mime_mem = get_mime_boundary(GET_ENV("CONTENT_TYPE", req), &mime_boundary);
|
||||
int content_length = atoi(GET_ENV("CONTENT_LENGTH", req));
|
||||
post_query = malloc(content_length + 1);
|
||||
if (!post_query)
|
||||
{
|
||||
|
@ -140,7 +142,7 @@ char* read_post_data(struct post_values* post)
|
|||
}
|
||||
|
||||
// fread should be a macro to FCGI_fread, which is set by FCGI_Accept in previous definitions
|
||||
size_t len = fread(post_query, 1, content_length, stdin);
|
||||
size_t len = FCGX_GetStr(post_query, content_length, req->in);
|
||||
post_query[content_length] = '\0';
|
||||
|
||||
// For shifting through
|
||||
|
@ -209,23 +211,27 @@ char* parse_query(char* begin, struct http_query_info* info)
|
|||
return end ? NULL : begin+1;
|
||||
}
|
||||
|
||||
char* try_handle_post(void (*call)(struct http_query_info*, void*), void* arg)
|
||||
char* try_handle_post(FCGX_Request* req, void (*call)(struct http_query_info*, void*), void* arg)
|
||||
{
|
||||
char* request_method = getenv("REQUEST_METHOD");
|
||||
char* request_method = GET_ENV("REQUEST_METHOD", req);
|
||||
char* post_query = NULL, * p_query_read;
|
||||
struct http_query_info info;
|
||||
|
||||
// Handle POST
|
||||
if (request_method && (strcmp("POST", request_method) == 0))
|
||||
{
|
||||
int content_length = atoi(getenv("CONTENT_LENGTH"));
|
||||
int content_length = atoi(GET_ENV("CONTENT_LENGTH", req));
|
||||
post_query = malloc(content_length + 1);
|
||||
if (!post_query)
|
||||
{
|
||||
puts("Malloc error!");
|
||||
return NULL;
|
||||
}
|
||||
#ifdef SINGLE_THREADED
|
||||
read(STDIN_FILENO, post_query, content_length);
|
||||
#else
|
||||
FCGX_GetStr(post_query, content_length, req->in);
|
||||
#endif
|
||||
post_query[content_length] = '\0';
|
||||
|
||||
|
||||
|
|
|
@ -81,11 +81,11 @@ struct get_values
|
|||
struct key code; // String
|
||||
};
|
||||
|
||||
char* read_get_data(struct get_values* query);
|
||||
char* read_post_data(struct post_values* post);
|
||||
char* read_get_data(FCGX_Request* req, struct get_values* query);
|
||||
char* read_post_data(FCGX_Request* req, struct post_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);
|
||||
char* try_handle_post(FCGX_Request* req, void (*call)(struct http_query_info*, void*), void* arg);
|
||||
|
||||
void free_files(struct file_array* files);
|
||||
|
||||
|
|
25
src/search.c
25
src/search.c
|
@ -33,7 +33,11 @@
|
|||
#include "../static/search.ctmpl"
|
||||
#include "../static/search_all.ctmpl"
|
||||
|
||||
void search_page(struct session* ssn, mastodont_t* api, enum search_tab tab, char* content)
|
||||
void search_page(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
enum search_tab tab,
|
||||
char* content)
|
||||
{
|
||||
char* out_data;
|
||||
struct search_template tdata = {
|
||||
|
@ -56,11 +60,11 @@ void search_page(struct session* ssn, mastodont_t* api, enum search_tab tab, cha
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
free(out_data);
|
||||
}
|
||||
|
||||
void content_search_all(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_search_all(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -142,7 +146,8 @@ void content_search_all(struct session* ssn, mastodont_t* api, char** data)
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
|
||||
free(out_data);
|
||||
free(statuses_html);
|
||||
free(accounts_html);
|
||||
|
@ -153,7 +158,7 @@ void content_search_all(struct session* ssn, mastodont_t* api, char** data)
|
|||
mastodont_storage_cleanup(&storage);
|
||||
}
|
||||
|
||||
void content_search_statuses(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_search_statuses(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -190,14 +195,14 @@ void content_search_statuses(struct session* ssn, mastodont_t* api, char** data)
|
|||
else
|
||||
statuses_html = construct_error("An error occured.", E_ERROR, 1, NULL);
|
||||
|
||||
search_page(ssn, api, SEARCH_STATUSES, STR_NULL_EMPTY(statuses_html));
|
||||
search_page(req, ssn, api, SEARCH_STATUSES, STR_NULL_EMPTY(statuses_html));
|
||||
|
||||
if (statuses_html) free(statuses_html);
|
||||
mstdnt_cleanup_search_results(&results);
|
||||
mastodont_storage_cleanup(&storage);
|
||||
}
|
||||
|
||||
void content_search_accounts(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_search_accounts(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -231,14 +236,14 @@ void content_search_accounts(struct session* ssn, mastodont_t* api, char** data)
|
|||
else
|
||||
accounts_html = construct_error("An error occured.", E_ERROR, 1, NULL);
|
||||
|
||||
search_page(ssn, api, SEARCH_ACCOUNTS, STR_NULL_EMPTY(accounts_html));
|
||||
search_page(req, ssn, api, SEARCH_ACCOUNTS, STR_NULL_EMPTY(accounts_html));
|
||||
|
||||
if (accounts_html) free(accounts_html);
|
||||
mstdnt_cleanup_search_results(&results);
|
||||
mastodont_storage_cleanup(&storage);
|
||||
}
|
||||
|
||||
void content_search_hashtags(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_search_hashtags(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -286,7 +291,7 @@ void content_search_hashtags(struct session* ssn, mastodont_t* api, char** data)
|
|||
|
||||
easprintf(&tags_page, "%s%s", STR_NULL_EMPTY(tags_graph), tags_html);
|
||||
|
||||
search_page(ssn, api, SEARCH_HASHTAGS, tags_page);
|
||||
search_page(req, ssn, api, SEARCH_HASHTAGS, tags_page);
|
||||
|
||||
if (tags_html) free(tags_html);
|
||||
if (tags_graph) free(tags_graph);
|
||||
|
|
15
src/search.h
15
src/search.h
|
@ -20,6 +20,7 @@
|
|||
#define SEARCH_H
|
||||
#include <mastodont.h>
|
||||
#include "session.h"
|
||||
#include "path.h"
|
||||
|
||||
enum search_tab
|
||||
{
|
||||
|
@ -28,10 +29,14 @@ enum search_tab
|
|||
SEARCH_HASHTAGS,
|
||||
};
|
||||
|
||||
void search_page(struct session* ssn, mastodont_t* api, enum search_tab tab, char* content);
|
||||
void content_search_all(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_search_statuses(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_search_accounts(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_search_hashtags(struct session* ssn, mastodont_t* api, char** data);
|
||||
void search_page(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
enum search_tab tab,
|
||||
char* content);
|
||||
void content_search_all(PATH_ARGS);
|
||||
void content_search_statuses(PATH_ARGS);
|
||||
void content_search_accounts(PATH_ARGS);
|
||||
void content_search_hashtags(PATH_ARGS);
|
||||
|
||||
#endif /* SEARCH_H */
|
||||
|
|
64
src/status.c
64
src/status.c
|
@ -166,22 +166,22 @@ int try_react_status(struct session* ssn, mastodont_t* api, char* id, char* emoj
|
|||
return 0;
|
||||
}
|
||||
|
||||
void content_status_create(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_status_create(PATH_ARGS)
|
||||
{
|
||||
char* referer = getenv("HTTP_REFERER");
|
||||
|
||||
try_post_status(ssn, api);
|
||||
|
||||
redirect(REDIRECT_303, referer);
|
||||
redirect(req, REDIRECT_303, referer);
|
||||
}
|
||||
|
||||
void content_status_react(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_status_react(PATH_ARGS)
|
||||
{
|
||||
char* referer = getenv("HTTP_REFERER");
|
||||
|
||||
try_react_status(ssn, api, data[0], data[1]);
|
||||
|
||||
redirect(REDIRECT_303, referer);
|
||||
redirect(req, REDIRECT_303, referer);
|
||||
}
|
||||
|
||||
const char* status_visibility_str(enum l10n_locale loc,
|
||||
|
@ -912,46 +912,47 @@ char* construct_statuses(struct session* ssn,
|
|||
return construct_func_strings(construct_status_voidwrap, &stat_args, size, ret_size);
|
||||
}
|
||||
|
||||
void status_interact(struct session* ssn, mastodont_t* api, char** data)
|
||||
void status_interact(PATH_ARGS)
|
||||
{
|
||||
char* referer = getenv("HTTP_REFERER");
|
||||
char* referer = GET_ENV("HTTP_REFERER", req);
|
||||
|
||||
try_interact_status(ssn, api, data[0]);
|
||||
|
||||
printf("Status: 303 See Other\r\n"
|
||||
"Location: %s#id-%s\r\n"
|
||||
"Content-Length: 14\r\n\r\n"
|
||||
"Redirecting...",
|
||||
referer ? referer : "/",
|
||||
data[0]);
|
||||
FCGX_FPrintF(req->out,
|
||||
"Status: 303 See Other\r\n"
|
||||
"Location: %s#id-%s\r\n"
|
||||
"Content-Length: 14\r\n\r\n"
|
||||
"Redirecting...",
|
||||
referer ? referer : "/",
|
||||
data[0]);
|
||||
}
|
||||
|
||||
void api_status_interact(struct session* ssn, mastodont_t* api, char** data)
|
||||
void api_status_interact(PATH_ARGS)
|
||||
{
|
||||
if (try_interact_status(ssn, api, keystr(ssn->post.id)) == 0)
|
||||
{
|
||||
send_result(NULL, "application/json", "{\"status\":\"Success\"}", 0);
|
||||
send_result(req, NULL, "application/json", "{\"status\":\"Success\"}", 0);
|
||||
}
|
||||
else
|
||||
send_result(NULL, "application/json", "{\"status\":\"Couldn't load status\"}", 0);
|
||||
send_result(req, NULL, "application/json", "{\"status\":\"Couldn't load status\"}", 0);
|
||||
}
|
||||
|
||||
void status_view(struct session* ssn, mastodont_t* api, char** data)
|
||||
void status_view(PATH_ARGS)
|
||||
{
|
||||
content_status(ssn, api, data, STATUS_FOCUSED);
|
||||
content_status(req, ssn, api, data, STATUS_FOCUSED);
|
||||
}
|
||||
|
||||
void status_emoji(struct session* ssn, mastodont_t* api, char** data)
|
||||
void status_emoji(PATH_ARGS)
|
||||
{
|
||||
content_status(ssn, api, data, STATUS_FOCUSED | STATUS_EMOJI_PICKER);
|
||||
content_status(req, ssn, api, data, STATUS_FOCUSED | STATUS_EMOJI_PICKER);
|
||||
}
|
||||
|
||||
void status_reply(struct session* ssn, mastodont_t* api, char** data)
|
||||
void status_reply(PATH_ARGS)
|
||||
{
|
||||
content_status(ssn, api, data, STATUS_FOCUSED | STATUS_REPLY);
|
||||
content_status(req, ssn, api, data, STATUS_FOCUSED | STATUS_REPLY);
|
||||
}
|
||||
|
||||
void status_view_reblogs(struct session* ssn, mastodont_t* api, char** data)
|
||||
void status_view_reblogs(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -968,6 +969,7 @@ void status_view_reblogs(struct session* ssn, mastodont_t* api, char** data)
|
|||
&reblogs_len);
|
||||
|
||||
content_status_interactions(
|
||||
req,
|
||||
ssn,
|
||||
api,
|
||||
"Reblogs",
|
||||
|
@ -978,7 +980,7 @@ void status_view_reblogs(struct session* ssn, mastodont_t* api, char** data)
|
|||
mstdnt_cleanup_accounts(reblogs, reblogs_len);
|
||||
}
|
||||
|
||||
void status_view_favourites(struct session* ssn, mastodont_t* api, char** data)
|
||||
void status_view_favourites(PATH_ARGS)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -995,6 +997,7 @@ void status_view_favourites(struct session* ssn, mastodont_t* api, char** data)
|
|||
&favourites_len);
|
||||
|
||||
content_status_interactions(
|
||||
req,
|
||||
ssn,
|
||||
api,
|
||||
"Favorites",
|
||||
|
@ -1005,7 +1008,8 @@ void status_view_favourites(struct session* ssn, mastodont_t* api, char** data)
|
|||
mstdnt_cleanup_accounts(favourites, favourites_len);
|
||||
}
|
||||
|
||||
void content_status_interactions(struct session* ssn,
|
||||
void content_status_interactions(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
char* label,
|
||||
struct mstdnt_account* accts,
|
||||
|
@ -1016,7 +1020,7 @@ void content_status_interactions(struct session* ssn,
|
|||
accounts_html = construct_error("No accounts", E_NOTICE, 1, NULL);
|
||||
|
||||
struct interactions_page_template tmpl = {
|
||||
.back_ref = getenv("HTTP_REFERER"),
|
||||
.back_ref = GET_ENV("HTTP_REFERER", req),
|
||||
.interaction_str = label,
|
||||
.accts = accounts_html
|
||||
};
|
||||
|
@ -1028,14 +1032,14 @@ void content_status_interactions(struct session* ssn,
|
|||
.content = output,
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
render_base_page(&page, ssn, api);
|
||||
render_base_page(&page, req, ssn, api);
|
||||
|
||||
// Cleanup
|
||||
free(accounts_html);
|
||||
free(output);
|
||||
}
|
||||
|
||||
void content_status(struct session* ssn, mastodont_t* api, char** data, uint8_t flags)
|
||||
void content_status(PATH_ARGS, uint8_t flags)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -1121,7 +1125,7 @@ void content_status(struct session* ssn, mastodont_t* api, char** data, uint8_t
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
|
||||
// Cleanup
|
||||
free(before_html);
|
||||
|
@ -1138,10 +1142,10 @@ void content_status(struct session* ssn, mastodont_t* api, char** data, uint8_t
|
|||
mastodont_storage_cleanup(&status_storage);
|
||||
}
|
||||
|
||||
void notice_redirect(struct session* ssn, mastodont_t* api, char** data)
|
||||
void notice_redirect(PATH_ARGS)
|
||||
{
|
||||
char* url;
|
||||
easprintf(&url, "%s/status/%s", config_url_prefix, data[0]);
|
||||
redirect(REDIRECT_303, url);
|
||||
redirect(req, REDIRECT_303, url);
|
||||
free(url);
|
||||
}
|
||||
|
|
28
src/status.h
28
src/status.h
|
@ -21,6 +21,7 @@
|
|||
#include <stdint.h>
|
||||
#include <mastodont.h>
|
||||
#include "l10n.h"
|
||||
#include "path.h"
|
||||
#include "session.h"
|
||||
|
||||
// Flags
|
||||
|
@ -47,8 +48,8 @@ struct interact_profile_args
|
|||
|
||||
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);
|
||||
void content_status_react(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_status_create(PATH_ARGS);
|
||||
void content_status_react(PATH_ARGS);
|
||||
|
||||
// HTML Builders
|
||||
char* construct_status(struct session* ssn,
|
||||
|
@ -59,7 +60,7 @@ char* construct_status(struct session* ssn,
|
|||
struct construct_statuses_args* args,
|
||||
uint8_t flags);
|
||||
char* construct_statuses(struct session* ssn,
|
||||
mastodont_t* api,
|
||||
mastodont_t* api,
|
||||
struct mstdnt_status* statuses,
|
||||
size_t size,
|
||||
struct construct_statuses_args* args,
|
||||
|
@ -104,32 +105,33 @@ char* reformat_status(struct session* ssn,
|
|||
char* greentextify(char* content);
|
||||
char* make_mentions_local(char* content);
|
||||
|
||||
void status_view_reblogs(struct session* ssn, mastodont_t* api, char** data);
|
||||
void status_view_favourites(struct session* ssn, mastodont_t* api, char** data);
|
||||
void status_view_reblogs(PATH_ARGS);
|
||||
void status_view_favourites(PATH_ARGS);
|
||||
|
||||
const char* status_visibility_str(enum l10n_locale locale, enum mstdnt_visibility_type visibility);
|
||||
|
||||
void content_status_interactions(struct session* ssn,
|
||||
void content_status_interactions(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
char* label,
|
||||
struct mstdnt_account* accts,
|
||||
size_t accts_len);
|
||||
|
||||
// Status frontends
|
||||
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);
|
||||
void status_emoji(struct session* ssn, mastodont_t* api, char** data);
|
||||
void status_view(PATH_ARGS);
|
||||
void status_reply(PATH_ARGS);
|
||||
void status_interact(PATH_ARGS);
|
||||
void status_emoji(PATH_ARGS);
|
||||
// Above wraps to the below function
|
||||
void content_status(struct session* ssn, mastodont_t* api, char** data, uint8_t flags);
|
||||
void content_status(PATH_ARGS, uint8_t flags);
|
||||
|
||||
// Cleanup
|
||||
void cleanup_media_ids(struct session* ssn, char** media_ids);
|
||||
|
||||
// Redirects
|
||||
void notice_redirect(struct session* ssn, mastodont_t* api, char** data);
|
||||
void notice_redirect(PATH_ARGS);
|
||||
|
||||
// API
|
||||
void api_status_interact(struct session* ssn, mastodont_t* api, char** data);
|
||||
void api_status_interact(PATH_ARGS);
|
||||
|
||||
#endif // STATUS_H
|
||||
|
|
20
src/test.c
20
src/test.c
|
@ -42,17 +42,17 @@ enum env_tbl_index
|
|||
|
||||
#define ENV_TBL_GET(index) (env_tbl[(index)] ? env_tbl[(index)] : ENV_NOT_FOUND)
|
||||
|
||||
void content_test(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_test(PATH_ARGS)
|
||||
{
|
||||
char* env_tbl[] = {
|
||||
getenv("HTTP_COOKIE"),
|
||||
getenv("PATH_INFO"),
|
||||
getenv("QUERY_STRING"),
|
||||
getenv("REQUEST_METHOD"),
|
||||
getenv("SCRIPT_NAME"),
|
||||
getenv("HTTP_REFERER"),
|
||||
getenv("HTTP_USER_AGENT"),
|
||||
getenv("CONTENT_LENGTH")
|
||||
GET_ENV("HTTP_COOKIE", req),
|
||||
GET_ENV("PATH_INFO", req),
|
||||
GET_ENV("QUERY_STRING", req),
|
||||
GET_ENV("REQUEST_METHOD", req),
|
||||
GET_ENV("SCRIPT_NAME", req),
|
||||
GET_ENV("HTTP_REFERER", req),
|
||||
GET_ENV("HTTP_USER_AGENT", req),
|
||||
GET_ENV("CONTENT_LENGTH", req)
|
||||
};
|
||||
|
||||
char* page;
|
||||
|
@ -75,6 +75,6 @@ void content_test(struct session* ssn, mastodont_t* api, char** data)
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
if (page) free(page);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
#include <stddef.h>
|
||||
#include <mastodont.h>
|
||||
#include "session.h"
|
||||
#include "path.h"
|
||||
|
||||
void content_test(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_test(PATH_ARGS);
|
||||
|
||||
#endif /* TEST_H */
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "timeline.h"
|
||||
#include <stdlib.h>
|
||||
#include "helpers.h"
|
||||
|
||||
#include "base_page.h"
|
||||
#include "../config.h"
|
||||
#include "index.h"
|
||||
|
@ -33,7 +34,8 @@
|
|||
#include "../static/timeline_options.ctmpl"
|
||||
#include "../static/navigation.ctmpl"
|
||||
|
||||
void content_timeline(struct session* ssn,
|
||||
void content_timeline(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses,
|
||||
|
@ -105,7 +107,7 @@ void content_timeline(struct session* ssn,
|
|||
};
|
||||
|
||||
// Output
|
||||
render_base_page(&b, ssn, api);
|
||||
render_base_page(&b, req, ssn, api);
|
||||
|
||||
// Cleanup
|
||||
mastodont_storage_cleanup(storage);
|
||||
|
@ -118,7 +120,7 @@ void content_timeline(struct session* ssn,
|
|||
free(output);
|
||||
}
|
||||
|
||||
void tl_home(struct session* ssn, mastodont_t* api, int local)
|
||||
void tl_home(FCGX_Request* req, struct session* ssn, mastodont_t* api, int local)
|
||||
{
|
||||
struct mstdnt_args m_args = { 0 };
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -146,10 +148,10 @@ void tl_home(struct session* ssn, mastodont_t* api, int local)
|
|||
|
||||
mastodont_timeline_home(api, &m_args, &args, &storage, &statuses, &statuses_len);
|
||||
|
||||
content_timeline(ssn, api, &storage, statuses, statuses_len, BASE_CAT_HOME, NULL, 1);
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_HOME, NULL, 1);
|
||||
}
|
||||
|
||||
void tl_direct(struct session* ssn, mastodont_t* api)
|
||||
void tl_direct(FCGX_Request* req, struct session* ssn, mastodont_t* api)
|
||||
{
|
||||
struct mstdnt_args m_args = { 0 };
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -174,10 +176,10 @@ void tl_direct(struct session* ssn, mastodont_t* api)
|
|||
|
||||
mastodont_timeline_direct(api, &m_args, &args, &storage, &statuses, &statuses_len);
|
||||
|
||||
content_timeline(ssn, api, &storage, statuses, statuses_len, BASE_CAT_DIRECT, "Direct", 0);
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_DIRECT, "Direct", 0);
|
||||
}
|
||||
|
||||
void tl_public(struct session* ssn, mastodont_t* api, int local, enum base_category cat)
|
||||
void tl_public(FCGX_Request* req, struct session* ssn, mastodont_t* api, int local, enum base_category cat)
|
||||
{
|
||||
struct mstdnt_args m_args = { 0 };
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -204,10 +206,10 @@ void tl_public(struct session* ssn, mastodont_t* api, int local, enum base_categ
|
|||
|
||||
mastodont_timeline_public(api, &m_args, &args, &storage, &statuses, &statuses_len);
|
||||
|
||||
content_timeline(ssn, api, &storage, statuses, statuses_len, cat, NULL, 1);
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, cat, NULL, 1);
|
||||
}
|
||||
|
||||
void tl_list(struct session* ssn, mastodont_t* api, char* list_id)
|
||||
void tl_list(FCGX_Request* req, struct session* ssn, mastodont_t* api, char* list_id)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -231,11 +233,11 @@ void tl_list(struct session* ssn, mastodont_t* api, char* list_id)
|
|||
|
||||
mastodont_timeline_list(api, &m_args, list_id, &args, &storage, &statuses, &statuses_len);
|
||||
|
||||
content_timeline(ssn, api, &storage, statuses, statuses_len, BASE_CAT_LISTS, "List timeline", 0);
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_LISTS, "List timeline", 0);
|
||||
}
|
||||
|
||||
|
||||
void tl_tag(struct session* ssn, mastodont_t* api, char* tag_id)
|
||||
void tl_tag(FCGX_Request* req, struct session* ssn, mastodont_t* api, char* tag_id)
|
||||
{
|
||||
struct mstdnt_args m_args;
|
||||
set_mstdnt_args(&m_args, ssn);
|
||||
|
@ -260,42 +262,42 @@ void tl_tag(struct session* ssn, mastodont_t* api, char* tag_id)
|
|||
|
||||
easprintf(&header, "Hashtag - #%s", tag_id);
|
||||
|
||||
content_timeline(ssn, api, &storage, statuses, statuses_len, BASE_CAT_NONE, header, 0);
|
||||
content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_NONE, header, 0);
|
||||
free(header);
|
||||
}
|
||||
|
||||
void content_tl_home(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_tl_home(PATH_ARGS)
|
||||
{
|
||||
if (keystr(ssn->cookies.logged_in))
|
||||
tl_home(ssn, api, 0);
|
||||
tl_home(req, ssn, api, 0);
|
||||
else
|
||||
content_tl_federated(ssn, api, data);
|
||||
content_tl_federated(req, ssn, api, data);
|
||||
}
|
||||
|
||||
void content_tl_direct(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_tl_direct(PATH_ARGS)
|
||||
{
|
||||
(void)data;
|
||||
tl_direct(ssn, api);
|
||||
tl_direct(req, ssn, api);
|
||||
}
|
||||
|
||||
void content_tl_federated(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_tl_federated(PATH_ARGS)
|
||||
{
|
||||
(void)data;
|
||||
tl_public(ssn, api, 0, BASE_CAT_FEDERATED);
|
||||
tl_public(req, ssn, api, 0, BASE_CAT_FEDERATED);
|
||||
}
|
||||
|
||||
void content_tl_local(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_tl_local(PATH_ARGS)
|
||||
{
|
||||
(void)data;
|
||||
tl_public(ssn, api, 1, BASE_CAT_LOCAL);
|
||||
tl_public(req, ssn, api, 1, BASE_CAT_LOCAL);
|
||||
}
|
||||
|
||||
void content_tl_list(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_tl_list(PATH_ARGS)
|
||||
{
|
||||
tl_list(ssn, api, data[0]);
|
||||
tl_list(req, ssn, api, data[0]);
|
||||
}
|
||||
|
||||
void content_tl_tag(struct session* ssn, mastodont_t* api, char** data)
|
||||
void content_tl_tag(PATH_ARGS)
|
||||
{
|
||||
tl_tag(ssn, api, data[0]);
|
||||
tl_tag(req, ssn, api, data[0]);
|
||||
}
|
||||
|
|
|
@ -18,25 +18,29 @@
|
|||
|
||||
#ifndef TIMELINE_H
|
||||
#define TIMELINE_H
|
||||
#include <fcgi_stdio.h>
|
||||
#include <fcgiapp.h>
|
||||
#include <stddef.h>
|
||||
#include <mastodont.h>
|
||||
#include "path.h"
|
||||
#include "session.h"
|
||||
#include "base_page.h"
|
||||
|
||||
// Federated and local are here
|
||||
void tl_home(struct session* ssn, mastodont_t* api, int local);
|
||||
void tl_direct(struct session* ssn, mastodont_t* api);
|
||||
void tl_public(struct session* ssn, mastodont_t* api, int local, enum base_category cat);
|
||||
void tl_list(struct session* ssn, mastodont_t* api, char* list_id);
|
||||
void tl_tag(struct session* ssn, mastodont_t* api, char* tag);
|
||||
void tl_home(FCGX_Request* req, struct session* ssn, mastodont_t* api, int local);
|
||||
void tl_direct(FCGX_Request* req, struct session* ssn, mastodont_t* api);
|
||||
void tl_public(FCGX_Request* req, struct session* ssn, mastodont_t* api, int local, enum base_category cat);
|
||||
void tl_list(FCGX_Request* req, struct session* ssn, mastodont_t* api, char* list_id);
|
||||
void tl_tag(FCGX_Request* req, struct session* ssn, mastodont_t* api, char* tag);
|
||||
|
||||
void content_tl_federated(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_tl_home(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_tl_direct(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);
|
||||
void content_tl_tag(struct session* ssn, mastodont_t* api, char** data);
|
||||
void content_timeline(struct session* ssn,
|
||||
void content_tl_federated(PATH_ARGS);
|
||||
void content_tl_home(PATH_ARGS);
|
||||
void content_tl_direct(PATH_ARGS);
|
||||
void content_tl_local(PATH_ARGS);
|
||||
void content_tl_list(PATH_ARGS);
|
||||
void content_tl_tag(PATH_ARGS);
|
||||
void content_timeline(FCGX_Request* req,
|
||||
struct session* ssn,
|
||||
mastodont_t* api,
|
||||
struct mstdnt_storage* storage,
|
||||
struct mstdnt_status* statuses,
|
||||
|
|
Loading…
Reference in a new issue