From 62e782c8f7a94349de6981e13126d2cb8690579c Mon Sep 17 00:00:00 2001 From: nekobit Date: Wed, 24 Aug 2022 12:36:19 +0000 Subject: [PATCH] Fix macros \nWe could use __VA_OPT__(,), but this is for a very new version of GCC FossilOrigin-Name: cd18b7747d55d6251bcabad7350629303e313b0f053a06a41fa7b188969b2071 --- src/http.c | 12 ++++++------ src/local_config_set.c | 4 ++-- src/login.c | 14 +++++++------- src/request.h | 9 ++++----- src/timeline.c | 12 ++++++------ 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/http.c b/src/http.c index 4611e29..a93d477 100644 --- a/src/http.c +++ b/src/http.c @@ -31,10 +31,10 @@ void redirect(REQUEST_T req, char* status, char* location) { char* loc_str = location ? location : "/"; - FPRINTF("Status: %s\r\n" - "Location: %s\r\n\r\n" - REDIR_HTML_BEGIN "Redirecting to %s..." REDIR_HTML_END, - status, - loc_str, - loc_str); + PRINTF("Status: %s\r\n" + "Location: %s\r\n\r\n" + REDIR_HTML_BEGIN "Redirecting to %s..." REDIR_HTML_END, + status, + loc_str, + loc_str); } diff --git a/src/local_config_set.c b/src/local_config_set.c index 81d5a32..595f6d0 100644 --- a/src/local_config_set.c +++ b/src/local_config_set.c @@ -34,7 +34,7 @@ void set_config_str(FCGX_Request* req, { if (ssn->post.set.is_set && post->is_set && page == curr_page) { - FPRINTF("Set-Cookie: %s=%s; HttpOnly; Path=/; Max-Age=31536000; SameSite=Strict;\r\n", + PRINTF("Set-Cookie: %s=%s; HttpOnly; Path=/; Max-Age=31536000; SameSite=Strict;\r\n", cookie_name, keypstr(post)); } @@ -59,7 +59,7 @@ void set_config_int(FCGX_Request* req, { if (ssn->post.set.is_set && page == curr_page) { - FPRINTF("Set-Cookie: %s=%d; HttpOnly; Path=/; Max-Age=31536000; SameSite=Strict;\r\n", + PRINTF("Set-Cookie: %s=%d; HttpOnly; Path=/; Max-Age=31536000; SameSite=Strict;\r\n", cookie_name, post_bool_intp(post)); } diff --git a/src/login.c b/src/login.c index 3cd7ff6..077ca11 100644 --- a/src/login.c +++ b/src/login.c @@ -34,8 +34,8 @@ static void apply_access_token(REQUEST_T req, char* token) { - FPRINTF("Set-Cookie: access_token=%s; Path=/; Max-Age=31536000\r\n", token); - PRINTF("Set-Cookie: logged_in=t; Path=/; Max-Age=31536000\r\n"); + PRINTF("Set-Cookie: access_token=%s; Path=/; Max-Age=31536000\r\n", token); + PUT("Set-Cookie: logged_in=t; Path=/; Max-Age=31536000\r\n"); // if config_url_prefix is empty, make it root redirect(req, REDIRECT_303, config_url_prefix && config_url_prefix[0] != '\0' ? config_url_prefix : "/"); @@ -100,9 +100,9 @@ void content_login_oauth(PATH_ARGS) decode_url, encode_id, urlify_redirect_url); // Set cookie and redirect - FPRINTF("Set-Cookie: instance_url=%s; Path=/; Max-Age=3153600\r\n", decode_url); - FPRINTF("Set-Cookie: client_id=%s; Path=/; Max-Age=3153600\r\n", app.client_id); - FPRINTF("Set-Cookie: client_secret=%s; Path=/; Max-Age=3153600\r\n", app.client_secret); + 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); free(url); @@ -185,10 +185,10 @@ void content_login(PATH_ARGS) } else { if (url_link) - FPRINTF("Set-Cookie: instance_url=%s; Path=/; Max-Age=31536000\r\n", url_link); + PRINTF("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"); + PUT("Set-Cookie: instance_url=; Path=/; Max-Age=-1\r\n"); apply_access_token(req, token.access_token); free(url_link); diff --git a/src/request.h b/src/request.h index 2aa7880..ccbeffd 100644 --- a/src/request.h +++ b/src/request.h @@ -20,13 +20,12 @@ #define REQUEST_H #ifdef SINGLE_THREADED -#define FPRINTF(str, ...) fprintf(str, __VA_ARGS__) -#define PRINTF(str) puts(str) +#define PRINTF(str, ...) printf(str, __VA_ARGS__) +#define PUT(str) printf(str) #define REQUEST_T void* #else -#define FPRINTF(str, ...) FCGX_FPrintF(req->out, str, __VA_ARGS__) -// If this adds a newline (it shouldn't) then this is probably -#define PRINTF(str) FCGX_PutS(str, req->out) +#define PRINTF(str, ...) FCGX_FPrintF(req->out, str, __VA_ARGS__) +#define PUT(str) FCGX_FPrintF(req->out, str) #define REQUEST_T FCGX_Request* #endif diff --git a/src/timeline.c b/src/timeline.c index d6151af..3802db4 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -30,7 +30,7 @@ #include "error.h" #include "string_helpers.h" -void content_timeline(FCGX_Request* req, +void content_timeline(REQUEST_T req, struct session* ssn, mastodont_t* api, struct mstdnt_storage* storage, @@ -78,7 +78,7 @@ void content_timeline(FCGX_Request* req, Safefree(dup); } -void tl_home(FCGX_Request* req, struct session* ssn, mastodont_t* api, int local) +void tl_home(REQUEST_T req, struct session* ssn, mastodont_t* api, int local) { struct mstdnt_args m_args = { 0 }; set_mstdnt_args(&m_args, ssn); @@ -109,7 +109,7 @@ void tl_home(FCGX_Request* req, struct session* ssn, mastodont_t* api, int local content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_HOME, NULL, 1, 0); } -void tl_direct(FCGX_Request* req, struct session* ssn, mastodont_t* api) +void tl_direct(REQUEST_T req, struct session* ssn, mastodont_t* api) { struct mstdnt_args m_args = { 0 }; set_mstdnt_args(&m_args, ssn); @@ -137,7 +137,7 @@ void tl_direct(FCGX_Request* req, struct session* ssn, mastodont_t* api) content_timeline(req, ssn, api, &storage, statuses, statuses_len, BASE_CAT_DIRECT, "Direct", 0, 0); } -void tl_public(FCGX_Request* req, struct session* ssn, mastodont_t* api, int local, enum base_category cat) +void tl_public(REQUEST_T 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); @@ -167,7 +167,7 @@ void tl_public(FCGX_Request* req, struct session* ssn, mastodont_t* api, int loc content_timeline(req, ssn, api, &storage, statuses, statuses_len, cat, NULL, 1, 0); } -void tl_list(FCGX_Request* req, struct session* ssn, mastodont_t* api, char* list_id) +void tl_list(REQUEST_T req, struct session* ssn, mastodont_t* api, char* list_id) { struct mstdnt_args m_args; set_mstdnt_args(&m_args, ssn); @@ -195,7 +195,7 @@ void tl_list(FCGX_Request* req, struct session* ssn, mastodont_t* api, char* lis } -void tl_tag(FCGX_Request* req, struct session* ssn, mastodont_t* api, char* tag_id) +void tl_tag(REQUEST_T req, struct session* ssn, mastodont_t* api, char* tag_id) { struct mstdnt_args m_args; set_mstdnt_args(&m_args, ssn);