Compare commits

...

7 Commits

Author SHA1 Message Date
nekobit c3e8efd394 Show login page (what's it doing in conversations.c?)
FossilOrigin-Name: 6757a70f24f25445893fa991cdedfee3298004e392285459b05eeba180fc899b
2023-06-01 01:54:23 +00:00
nekobit 9b476d3ab5 OpenBSD Pledge support
FossilOrigin-Name: 8cedfc5118348282ee78d14830a8d64326a62f91d34492e2f6b31e924cda0d5d
2023-06-01 01:10:47 +00:00
nekobit d4cd539019 Shorten OpenHTTPD example
FossilOrigin-Name: 3a32415027a7411ca7daac0f6b53261c4b20acf81005c9ef3196e04a36ce3298
2023-06-01 00:53:34 +00:00
nekobit 87586c6060 Fix paths, add debug, OpenHTTPD config
FossilOrigin-Name: 1aae905aee3907546c8cbe87a5990a6f09e9c91fb0dbcc064a06be5976fe01bb
2023-05-31 22:45:03 +00:00
nekobit b798501cc3 Fix - Building again :)
FossilOrigin-Name: 1781fda1a0fdc7705c1bc3d23d8f3118f93e4aad74971d71a635bb9195161300
2023-05-31 19:43:48 +00:00
nekobit ab6f8a58f4 Build again (with some hacks)
FossilOrigin-Name: 16e1c0939fda0e73429904ab72c386555a859d7a3ae4327d77b2aa55db9ae7b4
2023-05-31 16:47:17 +00:00
nekobit e003337b5c Makefile
FossilOrigin-Name: 9b32280cb809c26ca511f8dcda5fff3a8bc19a517ff60c095cde46ad3ad606e2
2023-05-31 15:30:42 +00:00
15 changed files with 286 additions and 324 deletions

View File

@ -1,4 +1,3 @@
Makefile
template
ctemplate
filec
@ -8,13 +7,14 @@ emojitoc
static/*.ctmpl
static/*.c
mastodont-c
treebird.make
config.h
treebird
test/tests
scripts/*.o
templates/*.ctt
test/unit/*.bin
treebird.core
filec.core
compile_commands.json
build/
obj/

103
Makefile Normal file
View File

@ -0,0 +1,103 @@
CC ?= cc
MASTODONT_DIR = mastodont-c
ifneq ($(wildcard $(MASTODONT_DIR)/bin/Release),)
MASTODONT = $(MASTODONT_DIR)/bin/Release/
else ifneq ($(wildcard $(MASTODONT_DIR)/bin/Debug),)
MASTODONT = $(MASTODONT_DIR)/bin/Debug/
endif
CFLAGS += -Wall -g -I $(MASTODONT_DIR)/include/ -Wno-unused-variable -Wno-ignored-qualifiers \
-I/usr/include/ -I $(MASTODONT_DIR)/libs $(shell pkg-config --cflags libcurl libcjson) \
`perl -MExtUtils::Embed -e ccopts` -DDEBUGGING_MSTATS
LDFLAGS += -L$(MASTODONT) -lmastodont $(shell pkg-config --libs libcurl libcjson) -lfcgi \
-lpthread `perl -MExtUtils::Embed -e ldopts` -DDEBUGGING_MSTATS
# libpcre2-8 (?)
SRC = $(wildcard src/*.c)
OBJ = $(patsubst %.c,%.o,$(SRC))
HEADERS = $(wildcard src/*.h) config.h
TMPL_DIR = templates
TMPLS = $(wildcard $(TMPL_DIR)/*.tt)
TMPLS_C = $(patsubst %.tt,%.ctt,$(TMPLS))
TEST_DIR = test/unit
TESTS = $(wildcard $(TEST_DIR)/t*.c)
UNIT_TESTS = $(patsubst %.c,%.bin,$(TESTS))
DIST = dist/
PREFIX ?= /usr/local
TARGET = treebird
# For tests
OBJ_NO_MAIN = $(filter-out src/main.o,$(OBJ))
MASTODONT_URL = https://fossil.nekobit.net/mastodont-c
# Not parallel friendly
#all: $(MASTODONT_DIR) dep_build $(TARGET)
ifneq ($(strip $(DEBUG)),)
CFLAGS += -DDEBUG
endif
all:
ifeq ($(wildcard $(MASTODONT_DIR)),)
@echo "[ERROR] Mastodont-c/ not found. Link it with ln -s in this directory."
@exit 1
endif
$(MAKE) filec
$(MAKE) make_tmpls
$(MAKE) $(TARGET)
install_deps:
cpan Template::Toolkit
$(TARGET): $(HEADERS) $(OBJ)
$(CC) -o $(TARGET) $(OBJ) $(PAGES_C_OBJ) $(LDFLAGS)
filec: src/file-to-c/main.o
$(CC) $(LDFLAGS) -o filec $<
emojitoc: scripts/emoji-to.o
$(CC) -o emojitoc $< $(LDFLAGS)
./emojitoc meta/emoji.json > src/emoji_codes.h
$(TMPL_DIR)/%.ctt: $(TMPL_DIR)/%.tt
./filec $< data_$(notdir $*)_tt > $@
make_tmpls: $(TMPLS_C)
$(MASTODONT_DIR):
cd ..; fossil clone $(MASTODONT_URL) || true
cd treebird; ln -s ../mastodont-c .
install: $(TARGET)
install -m 755 treebird $(PREFIX)/bin/
install -d $(PREFIX)/share/treebird/
cp -r dist/ $(PREFIX)/share/treebird/
test: all $(UNIT_TESTS)
@echo " ... Tests ready"
@./test/test.pl
%.o: %.c %.h $(PAGES)
$(CC) $(CFLAGS) -c $< -o $@
# For tests
%.bin: %.c
@$(CC) $(CFLAGS) $< -o $@ $(OBJ_NO_MAIN) $(PAGES_C_OBJ) $(LDFLAGS)
@echo -n " $@"
clean:
rm -f $(OBJ) src/file-to-c/main.o
rm -f $(TMPLS_C)
rm -f test/unit/*.bin
rm -f filec ctemplate
rm $(TARGET) || true
make -C $(MASTODONT_DIR) clean
clean_deps:
rm -r $(MASTODONT_DIR)
clean_all: clean clean_deps
.PHONY: all filec clean update clean clean_deps clean_all test install_deps

View File

@ -1,37 +0,0 @@
# For ease of development, you can enable and disable pages. This is useful if
# the code doesn't compile correctly, for which you can do an `#ifdef' with the
# C Preprocessor
function(append_and_def TARGET SCOPE NAME)
math(EXPR LEN "${ARGC}-1")
foreach(I RANGE 3 ${LEN})
list(GET ARGV ${I} filename)
# Convert name partto uppercase for the definition
get_filename_component(name ${filename} NAME_WE)
string(TOUPPER ${name} file_up)
get_target_property(
targ_comp
${TARGET}
COMPILE_DEFINITIONS
)
if ("${targ_comp}" STREQUAL "targ_comp-NOTFOUND")
set_target_properties(
${TARGET}
PROPERTIES COMPILE_DEFINITIONS "${file_up}"
)
else()
set_target_properties(
${TARGET}
PROPERTIES COMPILE_DEFINITIONS "${targ_comp};${file_up}"
)
endif()
# Will return copy of files
list(APPEND out_list ${filename})
endforeach()
# Return
set(${NAME} ${out_list} PARENT_SCOPE)
endfunction()

View File

@ -1,2 +0,0 @@
# TODO set some FreeBSD bullshit i gotta deal with

View File

@ -0,0 +1,7 @@
server "default" {
listen on * port 80
location match "/(.+).([pc]?[nsj][sg])" { root "htdocs/treebird" }
location match "^/.*$" {
fastcgi socket tcp localhost 4008
}
}

View File

@ -1,130 +0,0 @@
if not os.isfile('config.h') then
print("Note: `config.h' not found, until a new Treebird release comes out,");
print(" please copy `config.def.h' and edit it.");
os.exit(1);
end
workspace "Treebird";
project("file-to-c");
kind("ConsoleApp");
language("C");
files { "src/file-to-c/main.c" };
configurations { "Debug", "Release" };
local c_files = {
'main.c',
'types.c',
'cookie.c',
'easprintf.c',
'error.c',
'memory.c',
'helpers.c',
'key.c',
'local_config.c',
'local_config_set.c',
'query.c',
'string.c',
'string_helpers.c',
'request.c',
'session.c',
'path.c',
'mime.c',
};
-- Not actually real 'pages', but the ones we compile in / create definitions
-- This setup is pretty jank, but it helped me transition the Async refactor
local pages = {
'about.c',
'account.c',
'applications.c',
'attachments.c',
'base_page.c',
'conversations.c',
'emoji.c',
'emoji_reaction.c',
'global_cache.c',
'global_perl.c',
'hashtag.c',
'http.c',
'index.c',
'lists.c',
-- 'login.c',
-- 'memory_page.c',
'notifications.c',
-- 'page_config.c',
'scrobble.c',
-- 'search.c',
'status.c',
'timeline.c',
};
local definitions = {};
-- Create definitions for page enabling
for i=1, #pages do
local def = 'CMP_ENABLE_' .. string.upper(string.sub(pages[i], 0, -3));
table.insert(definitions, def);
end
-- Prepend with 'src/'
for i=1, #c_files do c_files[i] = 'src/'.. c_files[i] end
for i=1, #pages do pages[i] = 'src/'.. pages[i] end
-- BEGIN Mastodont project
project("treebird");
dependson("file-to-c");
kind("ConsoleApp");
language("C");
-- Merge pages into c_files
for _, v in ipairs(pages) do
table.insert(c_files, v);
end
files(c_files);
includedirs { "include/" };
defines(definitions);
-- For some reason this one doesn't have a pkg-config file
local libfcgi = os.findlib("libfcgi");
if not libfcgi then
print("Couldn't find libfcgi (aka fcgi-devkit). Probably gonna need that.\n");
os.exit(1);
end
rule "filec"
display "filec"
fileextension ".ctt"
buildmessage "Building %(filename)"
buildcommands 'filec -c "%(FullPath)" -o "%(IntDir)/%(Filename).obj"'
buildoutputs '%(IntDir)/%(Filename).obj'
filter { "action:gmake*" };
linkoptions{ "`pkg-config --libs mastodont` `perl -MExtUtils::Embed -e ldopts`" };
buildoptions{ "`pkg-config --cflags mastodont` `perl -MExtUtils::Embed -e ccopts`" };
links{"fcgi"};
filter { "toolset:clang" };
buildoptions{"-Wno-compound-token-split-by-macro"};
filter { "configurations:Debug" };
defines { "DEBUG" };
symbols("On");
filter { "configurations:Release" };
defines { "NDEBUG" };
optimize("On");
-- END Mastodont-c
local prefix = os.getenv("PREFIX") or "/usr/local";
newaction {
trigger = "install",
description = "install binary",
execute = function()
os.copyfile("treebird", prefix .. "/bin");
os.mkdir(prefix .. "/share/treebird");
os.execute("cp -r dist/ " .. prefix .. "/share/treebird/dist/");
os.execute("cp -r perl/ " .. prefix .. "/share/treebird/perl/");
end
}

View File

@ -57,6 +57,7 @@ static int
request_cb_base_page(mstdnt_request_cb_data* cb_data,
void* args)
{
#if 0
struct mstdnt_notifications* notifs = MSTDNT_CB_DATA(cb_data);
struct path_args_data* path_data = args;
@ -67,6 +68,7 @@ request_cb_base_page(mstdnt_request_cb_data* cb_data,
notifs);
path_args_data_destroy(path_data);
#endif
return MSTDNT_REQUEST_DONE;
}

View File

@ -14,39 +14,6 @@
#include "error.h"
#include "base_page.h"
static void
render_login_page(REQUEST_T req,
struct session* ssn,
mastodont_t* api)
{
char* page;
PERL_STACK_INIT;
HV* session_hv = perlify_session(ssn);
XPUSHs(newRV_noinc((SV*)session_hv));
XPUSHs(newRV_noinc((SV*)template_files));
#if 0
if (storage.error || oauth_store.error)
mXPUSHs(newSVpv(storage.error ? storage.error : oauth_store.error, 0));
#endif
PERL_STACK_SCALAR_CALL("login::content_login");
page = PERL_GET_STACK_EXIT;
struct base_page b = {
.category = BASE_CAT_NONE,
.content = page,
.session = session_hv,
.sidebar_left = NULL
};
// Output
render_base_page(&b, req, ssn, api);
// Cleanup
tb_free(page);
}
// Callback: request_cb_content_chats

View File

@ -5,7 +5,9 @@
*/
#include <stdio.h>
#include <stdarg.h>
/* These following two functions use the classic printf to stdout. */
void
print_treebird_logo(void)
{
@ -48,6 +50,19 @@ print_treebird_logo(void)
" Press ^C to quit.\n");
}
int
debug(char const* msg, ...)
{
int res;
va_list ap;
va_start(ap, msg);
printf("[DEBUG] ");
res = vprintf(msg, ap);
puts("");
va_end(ap);
return res;
}
#include "../config.h"
#include "helpers.h"

View File

@ -11,5 +11,6 @@
void set_mstdnt_args(struct mstdnt_args* args, struct session* ssn);
void print_treebird_logo();
int debug(char const* msg, ...);
#endif /* HELPERS_H */

View File

@ -21,6 +21,40 @@
#define LOGIN_SCOPE "read+write+follow+push"
static void
render_login_page(REQUEST_T req,
struct session* ssn,
mastodont_t* api)
{
char* page;
PERL_STACK_INIT;
HV* session_hv = perlify_session(ssn);
XPUSHs(newRV_noinc((SV*)session_hv));
XPUSHs(newRV_noinc((SV*)template_files));
#if 0
if (storage.error || oauth_store.error)
mXPUSHs(newSVpv(storage.error ? storage.error : oauth_store.error, 0));
#endif
PERL_STACK_SCALAR_CALL("login::content_login");
page = PERL_GET_STACK_EXIT;
struct base_page b = {
.category = BASE_CAT_NONE,
.content = page,
.session = session_hv,
.sidebar_left = NULL
};
// Output
render_base_page(&b, req, ssn, api);
// Cleanup
tb_free(page);
}
static void
apply_access_token(REQUEST_T req, char* token)
{
@ -31,86 +65,6 @@ apply_access_token(REQUEST_T req, char* token)
config_url_prefix[0] != '\0' ? config_url_prefix : "/");
}
int
content_login_oauth(PATH_ARGS)
{
struct mstdnt_args m_args;
set_mstdnt_args(&m_args, ssn);
const char* orig_url = m_args.url;
char* redirect_url = getenv("SERVER_NAME");
char* decode_url = NULL;
char* urlify_redirect_url = NULL;
easprintf(&urlify_redirect_url, "http%s://%s/login/oauth",
config_host_url_insecure ? "" : "s",
config_host_url ? config_host_url : redirect_url );
if (keystr(ssn->query.code))
{
struct mstdnt_application_args args_token = {
.grant_type = "authorization_code",
.client_id = keystr(ssn->cookies.client_id),
.client_secret = keystr(ssn->cookies.client_secret),
.redirect_uri = urlify_redirect_url,
.scope = LOGIN_SCOPE,
.code = keystr(ssn->query.code),
};
if (mstdnt_obtain_oauth_token(api,
&m_args,
NULL, NULL,
&args_token,
&oauth_storage,
&token) == 0)
{
apply_access_token(req, token.access_token);
}
}
else if (keystr(ssn->post.instance))
{
decode_url = curl_easy_unescape(api->curl, keystr(ssn->post.instance), 0, NULL);
m_args.url = decode_url;
struct mstdnt_application_args args_app = {
.client_name = "Treebird",
.redirect_uris = urlify_redirect_url,
.scopes = "read+write+follow+push",
.website = keystr(ssn->post.instance)
};
if (mstdnt_register_app(api,
&m_args,
NULL,
NULL,
args_app) == 0)
{
char* url;
char* encode_id = curl_easy_escape(api->curl, app.client_id, 0);
easprintf(&url, "%s/oauth/authorize?response_type=code&scope=" LOGIN_SCOPE "&client_id=%s&redirect_uri=%s",
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);
redirect(req, REDIRECT_303, url);
tb_free(url);
curl_free(encode_id);
}
}
m_args.url = orig_url;
redirect(req, REDIRECT_303, config_url_prefix &&
config_url_prefix[0] != '\0' ? config_url_prefix : "/");
mstdnt_storage_cleanup(&storage);
mstdnt_storage_cleanup(&oauth_storage);
if (urlify_redirect_url) tb_free(urlify_redirect_url);
if (decode_url) curl_free(decode_url);
}
static int
request_cb_oauth_token(struct mstdnt_request_cb_data* cb_data,
void* args)
@ -204,6 +158,83 @@ register_app(PATH_ARGS)
args_app);
}
int
content_login_oauth(PATH_ARGS)
{
#if 0
struct mstdnt_args m_args;
set_mstdnt_args(&m_args, ssn);
const char* orig_url = m_args.url;
char* redirect_url = getenv("SERVER_NAME");
char* decode_url = NULL;
char* urlify_redirect_url = NULL;
easprintf(&urlify_redirect_url, "http%s://%s/login/oauth",
config_host_url_insecure ? "" : "s",
config_host_url ? config_host_url : redirect_url );
if (keystr(ssn->query.code))
{
mstdnt_obtain_oauth_token(api,
&m_args,
request_cb_oauth_token,
path_args_data_create(req, ssn, api, NULL),
(struct mstdnt_application_args)
{
.grant_type = "authorization_code",
.client_id = keystr(ssn->cookies.client_id),
.client_secret = keystr(ssn->cookies.client_secret),
.redirect_uri = urlify_redirect_url,
.scope = LOGIN_SCOPE,
.code = keystr(ssn->query.code),
});
}
else if (keystr(ssn->post.instance))
{
decode_url = curl_easy_unescape(api->curl, keystr(ssn->post.instance), 0, NULL);
m_args.url = decode_url;
mstdnt_register_app(api,
&m_args,
NULL,
NULL,
(struct mstdnt_application_rags)
{
.client_name = "Treebird",
.redirect_uris = urlify_redirect_url,
.scopes = "read+write+follow+push",
.website = keystr(ssn->post.instance)
});
{
char* url;
char* encode_id = curl_easy_escape(api->curl, app.client_id, 0);
easprintf(&url, "%s/oauth/authorize?response_type=code&scope=" LOGIN_SCOPE "&client_id=%s&redirect_uri=%s",
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);
redirect(req, REDIRECT_303, url);
tb_free(url);
curl_free(encode_id);
}
}
m_args.url = orig_url;
redirect(req, REDIRECT_303, config_url_prefix &&
config_url_prefix[0] != '\0' ? config_url_prefix : "/");
if (urlify_redirect_url) tb_free(urlify_redirect_url);
if (decode_url) curl_free(decode_url);
#endif
}
int
content_login(PATH_ARGS)
{

View File

@ -5,10 +5,13 @@
*/
#include "global_perl.h"
#ifdef __OpenBSD__
# include <unistd.h>
#endif
#include <pthread.h>
#include <string.h>
#include "memory.h"
#include <mastodont/mastodont.h>
#include <mastodont.h>
#include <stdlib.h>
#include "../config.h"
#include "index.h"
@ -52,24 +55,17 @@ static int exit_treebird(PATH_ARGS)
* Path handling *
******************/
static struct path_info paths[] = {
#ifdef CMP_ENABLE_CONFIG
{ "/config/general", content_config_general },
{ "/config/appearance", content_config_appearance },
//{ "/config/account", content_config_account },
{ "/config", content_config },
#endif
#ifdef CMP_ENABLE_ATTACHMENTS
// API
{ "/treebird_api/v1/attachment", api_attachment_create },
#endif
#ifdef CMP_ENABLE_LOGIN
{ "/login/oauth", content_login_oauth },
{ "/login", content_login },
#endif
#ifdef CMP_ENABLE_ACCOUNT
{ "/user/:/action/:", content_account_action },
{ "/user/:", content_account_statuses },
{ "/@:/scrobbles", content_account_scrobbles },
@ -82,9 +78,7 @@ static struct path_info paths[] = {
{ "/favourites", content_account_favourites },
{ "/blocked", content_account_blocked },
{ "/muted", content_account_muted },
#endif
#ifdef CMP_ENABLE_STATUS
{ "/status/:/react/:", content_status_react },
{ "/status/:/react", status_emoji },
{ "/status/create", content_status_create },
@ -96,41 +90,27 @@ static struct path_info paths[] = {
{ "/status/:", status_view },
{ "/notice/:", notice_redirect },
{ "/treebird_api/v1/interact", api_status_interact },
#endif
#ifdef CMP_ENABLE_ABOUT
{ "/about/license", content_about_license },
{ "/about", content_about },
#endif
#ifdef CMP_ENABLE_SEARCH
{ "/search/statuses", content_search_statuses },
{ "/search/accounts", content_search_accounts },
{ "/search/hashtags", content_search_hashtags },
{ "/search", content_search_all },
#endif
#if defined(CMP_ENABLE_EMOJI) && defined(CMP_ENABLE_EMOJI_REACTION)
{ "/emoji_picker", content_emoji_picker },
#endif
#ifdef CMP_ENABLE_LISTS
{ "/lists/edit/:", list_edit },
{ "/lists", content_lists },
#endif
#ifdef CMP_ENABLE_TIMELINE
{ "/local", content_tl_local },
{ "/federated", content_tl_federated },
{ "/direct", content_tl_direct },
{ "/bookmarks", content_account_bookmarks },
{ "/lists/for/:", content_tl_list },
# ifdef CMP_ENABLE_HASHTAG
{ "/tag/:", content_tl_tag },
# endif
#endif
{ "/tag/:", content_tl_tag },
#ifdef CMP_ENABLE_NOTIFICATIONS
{ "/notifications_compact", content_notifications_compact },
{ "/notification/:/read", content_notifications_read },
{ "/notification/:/delete", content_notifications_clear },
@ -138,20 +118,14 @@ static struct path_info paths[] = {
{ "/notifications/clear", content_notifications_clear },
{ "/notifications", content_notifications },
{ "/treebird_api/v1/notifications", api_notifications },
#endif
#ifdef CMP_ENABLE_CONVERSATIONS
{ "/chats/:", content_chat_view },
{ "/chats", content_chats },
#endif
#ifdef DEBUG
{ "/quit", exit_treebird },
{ "/exit", exit_treebird },
#endif
// Debug, but cool to see
#ifdef CMP_ENABLE_MEMORY
{ "/memory_stats", content_memory_stats },
#endif
};
@ -214,6 +188,7 @@ static int application(mastodont_t* api, REQUEST_T req)
// This is a direct page, no requests made, so cleanup now
if (rc == 0)
{
debug("Direct page, cleaning up...");
session_cleanup(ssn);
}
@ -229,24 +204,28 @@ static void fcgi_start(mastodont_t* api)
while (1)
{
req = malloc(sizeof(FCGX_Request));
FCGX_InitRequest(req, 0, 0);
if (FCGX_InitRequest(req, 0, 0) != 0)
{
free(req);
continue;
}
struct mstdnt_fd fds = {
// The docs says not to use this directly, but we don't care
// what the docs say
// what the docs say :^)
.fd = req->listen_sock,
.events = MSTDNT_POLLIN,
.revents = 0
};
// Will poll until we get a request
mstdnt_await(api, 0, &fds, 1);
int res = mstdnt_await(api, 0, &fds, 1);
if (fds.revents != 0)
{
rc = FCGX_Accept_r(req);
if (rc < 0) break;
rc = application(api, req);
if (rc == 0)
@ -255,6 +234,10 @@ static void fcgi_start(mastodont_t* api)
free(req);
}
}
else {
FCGX_Finish_r(req);
free(req);
}
}
}
@ -292,13 +275,23 @@ int main(int argc, char **argv, char **env)
#endif
#ifdef __OpenBSD__
if (pledge("stdio rpath inet dns unveil prot_exec", "") == -1)
{
perror("pledge");
exit(2);
}
#endif
// Global init
mstdnt_global_curl_init();
#ifndef CGI_MODE
FCGX_Init();
if (FCGX_Init() != 0)
{
exit(1);
}
#endif
// Initialize Perl
PERL_SYS_INIT3(&argc, &argv, &env);
my_perl = perl_alloc();

View File

@ -5,7 +5,6 @@
*/
#include <stdlib.h>
#include <malloc.h>
#include "memory.h"
#ifdef __GLIBC__

View File

@ -11,6 +11,7 @@
#include "account.h"
#include "error.h"
#include "session.h"
#include "helpers.h"
int parse_path(REQUEST_T req,
struct session* ssn,
@ -125,12 +126,13 @@ int handle_paths(REQUEST_T req,
{
int res;
char* path = GET_ENV("PATH_INFO", req);
// "default" path
if (path == NULL || (path && strcmp(path, "/") == 0))
// "default" path OpenBSD httpd likes to return this one vv
if (path == NULL || (path && (strcmp(path, "/") == 0 || strcmp(path, "") == 0)))
{
return content_index(req, ssn, api);
}
else { // Generic path
debug("Path: %s", path);
for (size_t i = 0; i < paths_len; ++i)
{
if ((res = parse_path(req, ssn, api, paths + i)) != -1)
@ -139,5 +141,6 @@ int handle_paths(REQUEST_T req,
// Fell out, return 404
content_not_found(req, ssn, api, path);
return 0;
}
}

View File

@ -19,6 +19,7 @@
int content_search_all(PATH_ARGS)
{
#if 0
struct mstdnt_args m_args;
set_mstdnt_args(&m_args, ssn);
struct mstdnt_storage storage = { 0 };
@ -88,10 +89,12 @@ int content_search_all(PATH_ARGS)
mstdnt_cleanup_search_results(&results);
mstdnt_storage_cleanup(&storage);
tb_free(dup);
#endif
}
int content_search_statuses(PATH_ARGS)
{
#if 0
struct mstdnt_args m_args;
set_mstdnt_args(&m_args, ssn);
char* statuses_html;
@ -135,10 +138,12 @@ int content_search_statuses(PATH_ARGS)
mstdnt_cleanup_search_results(&results);
mstdnt_storage_cleanup(&storage);
tb_free(dup);
#endif
}
int content_search_accounts(PATH_ARGS)
{
#if 0
struct mstdnt_args m_args;
set_mstdnt_args(&m_args, ssn);
struct mstdnt_storage storage = { 0 };
@ -181,10 +186,12 @@ int content_search_accounts(PATH_ARGS)
mstdnt_cleanup_search_results(&results);
mstdnt_storage_cleanup(&storage);
tb_free(dup);
#endif
}
int content_search_hashtags(PATH_ARGS)
{
#if 0
struct mstdnt_args m_args;
set_mstdnt_args(&m_args, ssn);
struct mstdnt_storage storage = { 0 };
@ -209,10 +216,12 @@ int content_search_hashtags(PATH_ARGS)
mstdnt_cleanup_search_results(&results);
mstdnt_storage_cleanup(&storage);
// tb_free(dup);
#endif
}
HV* perlify_search_results(struct mstdnt_search_results* results)
{
#if 0
if (!results) return NULL;
HV* search_hv = newHV();
@ -221,4 +230,5 @@ HV* perlify_search_results(struct mstdnt_search_results* results)
// TODO tags
return search_hv;
#endif
}