From 4db0dea58b53a44f38acf05b87bef5e4fcaf2b1b Mon Sep 17 00:00:00 2001 From: nekobit Date: Fri, 19 Aug 2022 15:30:49 +0000 Subject: [PATCH] Broken redirect FossilOrigin-Name: 72feef8ae694f79bab1eb6295b38e07b3b70cc16722490fac7751a6002a799fe --- src/query.c | 3 ++ src/query.h | 1 + src/search.c | 95 ++++++++++++++--------------------------------- templates/main.tt | 9 +++-- 4 files changed, 36 insertions(+), 72 deletions(-) diff --git a/src/query.c b/src/query.c index ede43f2..4943799 100644 --- a/src/query.c +++ b/src/query.c @@ -37,6 +37,7 @@ char* read_get_data(FCGX_Request* req, struct get_values* query) { "offset", &(query->offset), key_string }, { "q", &(query->query), key_string }, { "code", &(query->code), key_string }, + { "type", &(query->type), key_int }, }; // END Query references @@ -263,6 +264,7 @@ void free_files(struct file_array* files) free(content); } +// TODO use hvstores_XXX macros HV* perlify_post_values(struct post_values* post) { HV* ssn_post_hv = newHV(); @@ -315,6 +317,7 @@ HV* perlify_get_values(struct get_values* get) hv_stores(ssn_query_hv, "offset", newSVpv(keystr(get->offset), 0)); hv_stores(ssn_query_hv, "query", newSVpv(keystr(get->query), 0)); hv_stores(ssn_query_hv, "code", newSVpv(keystr(get->code), 0)); + hvstores_int(ssn_query_hv, "type", keyint(get->type)); return ssn_query_hv; } diff --git a/src/query.h b/src/query.h index b78dfde..a7953bd 100644 --- a/src/query.h +++ b/src/query.h @@ -80,6 +80,7 @@ struct get_values struct key offset; // String struct key query; // String struct key code; // String + struct key type; // Int }; char* read_get_data(FCGX_Request* req, struct get_values* query); diff --git a/src/search.c b/src/search.c index 89a5f2b..0863eb4 100644 --- a/src/search.c +++ b/src/search.c @@ -17,6 +17,7 @@ */ #include +#include "http.h" #include "helpers.h" #include "search.h" #include "easprintf.h" @@ -83,6 +84,24 @@ void content_search_all(PATH_ARGS) }; struct mstdnt_search_results results = { 0 }; + // Perform redirect to correct direct page + if (ssn->query.type.is_set) + { + // Note: This can be zero, which is just "nothing" + switch (keyint(ssn->query.type)) + { + case 1: + redirect(req, REDIRECT_303, "/search/statuses"); + return; + case 2: + redirect(req, REDIRECT_303, "/search/accounts"); + return; + case 3: + redirect(req, REDIRECT_303, "/search/hashtags"); + return; + } + } + mastodont_search(api, &m_args, keystr(ssn->query.query), &storage, &args, &results); PERL_STACK_INIT; @@ -130,26 +149,10 @@ void content_search_statuses(PATH_ARGS) }; struct mstdnt_search_results results = { 0 }; - if (mastodont_search(api, - &m_args, - keystr(ssn->query.query), - &storage, - &args, - &results) == 0) - { - struct construct_statuses_args statuses_args = { - .highlight_word = keystr(ssn->query.query), - }; - statuses_html = construct_statuses(ssn, api, results.statuses, results.statuses_len, &statuses_args, NULL); - if (!statuses_html) - statuses_html = construct_error("No statuses", E_ERROR, 1, NULL); - } - else - statuses_html = construct_error("An error occured.", E_ERROR, 1, NULL); - - search_page(req, ssn, api, SEARCH_STATUSES, STR_NULL_EMPTY(statuses_html)); - - if (statuses_html) free(statuses_html); + mastodont_search(api, &m_args, keystr(ssn->query.query), &storage, &args, &results); + + // TODO + mstdnt_cleanup_search_results(&results); mastodont_storage_cleanup(&storage); } @@ -158,7 +161,6 @@ void content_search_accounts(PATH_ARGS) { struct mstdnt_args m_args; set_mstdnt_args(&m_args, ssn); - char* accounts_html; struct mstdnt_storage storage = { 0 }; struct mstdnt_search_args args = { .account_id = NULL, @@ -174,23 +176,10 @@ void content_search_accounts(PATH_ARGS) }; struct mstdnt_search_results results = { 0 }; - if (mastodont_search(api, - &m_args, - keystr(ssn->query.query), - &storage, - &args, - &results) == 0) - { - accounts_html = construct_accounts(api, results.accts, results.accts_len, 0, NULL); - if (!accounts_html) - accounts_html = construct_error("No accounts", E_ERROR, 1, NULL); - } - else - accounts_html = construct_error("An error occured.", E_ERROR, 1, NULL); + mastodont_search(api, &m_args, keystr(ssn->query.query), &storage, &args, &results); - search_page(req, ssn, api, SEARCH_ACCOUNTS, STR_NULL_EMPTY(accounts_html)); + // TODO - if (accounts_html) free(accounts_html); mstdnt_cleanup_search_results(&results); mastodont_storage_cleanup(&storage); } @@ -199,10 +188,6 @@ void content_search_hashtags(PATH_ARGS) { struct mstdnt_args m_args; set_mstdnt_args(&m_args, ssn); - char* tags_html; - char* tags_graph = NULL; - char* tags_bars = NULL; - char* tags_page; struct mstdnt_storage storage = { 0 }; struct mstdnt_search_args args = { .account_id = NULL, @@ -218,36 +203,10 @@ void content_search_hashtags(PATH_ARGS) }; struct mstdnt_search_results results = { 0 }; - if (mastodont_search(api, - &m_args, - keystr(ssn->query.query), - &storage, - &args, - &results) == 0) - { - tags_html = construct_hashtags(results.tags, results.tags_len, NULL); - if (!tags_html) - tags_html = construct_error("No hashtags", E_ERROR, 1, NULL); - - tags_bars = construct_hashtags_graph(results.tags, - results.tags_len, - 14, - NULL); - if (tags_bars) - tags_graph = construct_bar_graph_container(tags_bars, NULL); - - if (tags_bars) free(tags_bars); - } - else - tags_html = construct_error("An error occured.", E_ERROR, 1, NULL); - - easprintf(&tags_page, "%s%s", STR_NULL_EMPTY(tags_graph), tags_html); + mastodont_search(api, &m_args, keystr(ssn->query.query), &storage, &args, &results); - search_page(req, ssn, api, SEARCH_HASHTAGS, tags_page); + // TODO - if (tags_html) free(tags_html); - if (tags_graph) free(tags_graph); - free(tags_page); mstdnt_cleanup_search_results(&results); mastodont_storage_cleanup(&storage); } diff --git a/templates/main.tt b/templates/main.tt index 966a0bb..5fbaadf 100644 --- a/templates/main.tt +++ b/templates/main.tt @@ -48,7 +48,8 @@
  • @@ -56,7 +57,7 @@
  • @@ -64,7 +65,7 @@
  • @@ -72,7 +73,7 @@