diff --git a/Makefile b/Makefile index e0bb7f0..dab9b70 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CC ?= cc GIT ?= git MASTODONT_DIR = mastodont-c/ MASTODONT = $(MASTODONT_DIR)libmastodont.a -CFLAGS += -Wall -I $(MASTODONT_DIR)include/ +CFLAGS += -Wall -I $(MASTODONT_DIR)include/ -Wno-unused-variable -Wno-discarded-qualifiers LDFLAGS = -L$(MASTODONT_DIR) -lcurl -lmastodont -lcjson SRC = $(wildcard src/*.c) OBJ = $(patsubst %.c,%.o,$(SRC)) diff --git a/src/base_page.c b/src/base_page.c index b2e2c56..951b366 100644 --- a/src/base_page.c +++ b/src/base_page.c @@ -35,7 +35,6 @@ void render_base_page(struct base_page* page) if (!g_config.changed && cookie) { - if (cookies.theme) g_config.theme = cookies.theme; if (cookies.logged_in && strcmp(cookies.logged_in, "t") == 0) @@ -65,7 +64,7 @@ void render_base_page(struct base_page* page) return; } - printf("Content-Length: %d\r\n\r\n%s", len + 1, data); + printf("Content-Length: %d\r\n\r\n", len + 1); puts(data); free(data); diff --git a/src/login.c b/src/login.c index ebe4b19..073054d 100644 --- a/src/login.c +++ b/src/login.c @@ -27,32 +27,13 @@ // Files #include "../static/login.chtml" -struct login_info -{ - char* username; - char* password; -}; - -static void authenticate(struct http_query_info* info, void* _args) -{ - struct login_info* login = _args; - - if (strcmp(info->key, "username") == 0) - login->username = info->val; - else if (strcmp(info->key, "password") == 0) - login->password = info->val; -} - void content_login(mastodont_t* api, char** data, size_t data_size) { - char* post_query; struct mstdnt_storage storage, oauth_store; struct mstdnt_app app; struct mstdnt_oauth_token token; - struct login_info info = { 0 }; - post_query = try_handle_post(authenticate, &info); - if (post_query) + if (post.username && post.password) { // Getting the client id/secret struct mstdnt_app_register_args args_app = { @@ -68,16 +49,15 @@ void content_login(mastodont_t* api, char** data, size_t data_size) .grant_type = "password", .client_id = app.client_id, .client_secret = app.client_secret, - .username = info.username, - .password = info.password + .username = post.username, + .password = post.password }; mastodont_obtain_oauth_token(api, &args_token, &oauth_store, &token); // TODO checking, also ^ returns non-zero printf("Set-Cookie: access_token=%s; HttpOnly; SameSite=Strict;\r\n", token.access_token); - printf("Set-Cookie: logged_in=t; SameSite=Strict"); -// cookie_get_val(cookies, key, http_cookie_info* &info) + printf("Set-Cookie: logged_in=t; SameSite=Strict\r\n"); } struct base_page b = { @@ -88,7 +68,4 @@ void content_login(mastodont_t* api, char** data, size_t data_size) // Output render_base_page(&b); - - // Cleanup - if (post_query) free(post_query); } diff --git a/src/main.c b/src/main.c index 8a2d1f6..5cd72e8 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,7 @@ #include "login.h" #include "local_config.h" #include "cookie.h" +#include "query.h" int main(void) { diff --git a/src/page_config.c b/src/page_config.c index fea5cf3..c226ff9 100644 --- a/src/page_config.c +++ b/src/page_config.c @@ -30,21 +30,8 @@ #include "../static/index.chtml" #include "../static/config.chtml" -static void config_post(struct http_query_info* info, void* args) -{ - (void)args; - - if (strcmp(info->key, "theme") == 0) - { - g_config.theme = info->val; - - g_config.changed = 1; - } -} - void content_config(mastodont_t* api, char** data, size_t size) { - char* post_query; (void)api; // No need to use this if (post.theme) diff --git a/src/query.c b/src/query.c index 5f2be61..a74135f 100644 --- a/src/query.c +++ b/src/query.c @@ -36,7 +36,9 @@ char* read_post_data() { "content", &(post.content) }, { "itype", &(post.itype) }, { "id", &(post.id) }, - { "theme", &(post.theme) } + { "theme", &(post.theme) }, + { "username", &(post.username) }, + { "password", &(post.password) }, }; // END Query references diff --git a/src/query.h b/src/query.h index a4e4ec1..ce54542 100644 --- a/src/query.h +++ b/src/query.h @@ -32,6 +32,8 @@ struct query_values char* content; char* itype; char* id; + char* username; + char* password; }; extern struct query_values post; diff --git a/src/status.c b/src/status.c index cdbc932..7302180 100644 --- a/src/status.c +++ b/src/status.c @@ -50,7 +50,7 @@ int try_post_status(mastodont_t* api) mastodont_create_status(api, &args, &storage); // TODO cleanup when errors are properly implemented - // mastodont_storage_cleanup(&storage); + mastodont_storage_cleanup(&storage); return 0; }