Build again (with some hacks)

FossilOrigin-Name: 16e1c0939fda0e73429904ab72c386555a859d7a3ae4327d77b2aa55db9ae7b4
This commit is contained in:
nekobit 2023-05-31 16:47:17 +00:00
parent e003337b5c
commit ab6f8a58f4
6 changed files with 94 additions and 85 deletions

View File

@ -9,9 +9,9 @@ endif
CFLAGS += -Wall -I $(MASTODONT_DIR)/include/ -Wno-unused-variable -Wno-ignored-qualifiers \
-I/usr/include/ -I $(MASTODONT_DIR)/libs $(shell pkg-config --cflags libcurl) \
-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) -lfcgi \
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)

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

@ -31,86 +31,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 +124,84 @@ register_app(PATH_ARGS)
args_app);
}
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))
{
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;
#if 0
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);
}
#endif
}
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);
}
int
content_login(PATH_ARGS)
{
@ -216,6 +214,6 @@ content_login(PATH_ARGS)
register_app(PATH_ARGS_PASS);
}
else {
render_login_page(req, ssn, api);
//render_login_page(req, ssn, api);
}
}

View File

@ -8,7 +8,7 @@
#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"

View File

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

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
}