Handle get queries

FossilOrigin-Name: e125357cd01e8393307cae6fccf3e7b79317b60293d479934b51742f2eb22a3e
This commit is contained in:
me@ow.nekobit.net 2022-03-28 18:37:35 +00:00
parent 0324f5fde6
commit 4a88dcb68d
3 changed files with 53 additions and 2 deletions

View file

@ -53,7 +53,8 @@ int main(void)
char* cookies_str = read_cookies_env();
api.token = cookies.access_token; // Load token now
char* post_str = read_post_data();
char* get_str = read_query_data();
// Config defaults
g_config.theme = "treebird20";
@ -81,6 +82,7 @@ int main(void)
// Cleanup
if (cookies_str) free(cookies_str);
if (post_str) free(post_str);
if (get_str) free(get_str);
mastodont_free(&api);
// Obliterate all global values, so the next client

View file

@ -24,6 +24,47 @@
#include "key.h"
struct query_values post = { 0 };
struct get_values query = { 0 };
char* read_query_data()
{
struct http_query_info info;
char* query_string = getenv("QUERY_STRING");
char* get_query = NULL, *g_query_read;
// BEGIN Query references
struct key_value_refs refs[] = {
{ "offset", &(query.offset) },
{ "id", &(query.id) },
};
// END Query references
if (query_string)
{
get_query = malloc(strlen(query_string) + 1);
if (!get_query)
{
perror("malloc");
return NULL;
}
strcpy(get_query, query_string);
// For shifting through
g_query_read = get_query;
do
{
g_query_read = parse_query(g_query_read, &info);
if (!(info.key && info.val)) break;
for (size_t i = 0; i < (sizeof(refs)/sizeof(refs[0])); ++i)
if (strcmp(info.key, refs[i].key) == 0)
*(refs[i].val) = info.val;
}
while (g_query_read);
}
return get_query;
}
char* read_post_data()
{

View file

@ -38,8 +38,16 @@ struct query_values
char* replyid;
};
extern struct query_values post;
struct get_values
{
char* offset;
char* id;
};
extern struct query_values post;
extern struct get_values query;
char* read_query_data();
char* read_post_data();
/* A stupidly quick query parser */
char* parse_query(char* begin, struct http_query_info* info);