forked from mirrors/treebird
Query parser
FossilOrigin-Name: fb3dec10d90e0beac45bcef20f4f0b7ba9fcc1a446d602e4484a0d0fa5a9e856
This commit is contained in:
parent
9041c53b24
commit
31efb281a4
7 changed files with 150 additions and 9 deletions
22
src/cookie.h
Normal file
22
src/cookie.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* RatFE - Lightweight frontend for Pleroma
|
||||
* Copyright (C) 2022 Nekobit
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef COOKIE_H
|
||||
#define COOKIE_H
|
||||
|
||||
#endif // COOKIE_H
|
|
@ -17,8 +17,12 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include "../config.h"
|
||||
#include "page_config.h"
|
||||
#include "query.h"
|
||||
|
||||
// Pages
|
||||
#include "../static/index.chtml"
|
||||
|
@ -27,9 +31,45 @@
|
|||
void content_config(mastodont_t* api)
|
||||
{
|
||||
(void)api; // No need to use this
|
||||
|
||||
/* Output */
|
||||
char* request_method = getenv("REQUEST_METHOD");
|
||||
char* post_query, * p_query_read;
|
||||
struct http_query_info info;
|
||||
|
||||
// Output
|
||||
printf("Content-Length: %ld\r\n\r\n",
|
||||
data_index_html_size + data_config_html_size);
|
||||
|
||||
|
||||
// Handle POST
|
||||
if (request_method && (strcmp("POST", request_method) == 0))
|
||||
{
|
||||
int content_length = atoi(getenv("CONTENT_LENGTH"));
|
||||
post_query = malloc(content_length + 1);
|
||||
if (!post_query)
|
||||
{
|
||||
puts("Malloc error!");
|
||||
return;
|
||||
}
|
||||
read(STDIN_FILENO, post_query, content_length);
|
||||
post_query[content_length] = '\0';
|
||||
|
||||
// For parse_query to shift through, so we can still free the original
|
||||
p_query_read = post_query;
|
||||
|
||||
// Parse
|
||||
while (1)
|
||||
{
|
||||
p_query_read = parse_query(p_query_read, &info);
|
||||
|
||||
printf("%.*s,", (int)info.val_len, info.val);
|
||||
|
||||
if (p_query_read == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
free(post_query);
|
||||
}
|
||||
|
||||
printf(data_index_html, config_canonical_name, data_config_html);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "path.h"
|
||||
#include "index.h"
|
||||
|
||||
void handle_paths(mastodont_t* api, struct path_info* paths, size_t paths_len)
|
||||
{
|
||||
|
@ -28,11 +29,11 @@ void handle_paths(mastodont_t* api, struct path_info* paths, size_t paths_len)
|
|||
{
|
||||
content_index(api);
|
||||
}
|
||||
else if (path && path[1] == '@')
|
||||
else if (path[1] == '@')
|
||||
{ // Account path
|
||||
content_index(api);
|
||||
}
|
||||
else if (path)
|
||||
else
|
||||
{ // Generic path
|
||||
for (size_t i = 0; i < paths_len; ++i)
|
||||
{
|
||||
|
|
42
src/query.c
Normal file
42
src/query.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* RatFE - Lightweight frontend for Pleroma
|
||||
* Copyright (C) 2022 Nekobit
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "query.h"
|
||||
|
||||
char* parse_query(char* begin, struct http_query_info* info)
|
||||
{
|
||||
int end = 0;
|
||||
char* val_begin;
|
||||
info->key = begin;
|
||||
for (; *begin != '&' && *begin != '\0'; ++begin)
|
||||
{
|
||||
if (*begin == '=')
|
||||
{
|
||||
val_begin = begin+1;
|
||||
*begin = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
if (*begin == '\0') end = 1;
|
||||
if (*begin == '&') *begin = '\0';
|
||||
info->val = val_begin;
|
||||
// The val length may be large, so strlen can waste time
|
||||
info->val_len = (size_t)(begin - val_begin);
|
||||
|
||||
return end ? NULL : begin+1;
|
||||
}
|
33
src/query.h
Normal file
33
src/query.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* RatFE - Lightweight frontend for Pleroma
|
||||
* Copyright (C) 2022 Nekobit
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef QUERY_H
|
||||
#define QUERY_H
|
||||
#include <stddef.h>
|
||||
|
||||
struct http_query_info
|
||||
{
|
||||
char* key;
|
||||
char* val;
|
||||
size_t val_len; // Val may be large, like CSS property
|
||||
};
|
||||
|
||||
/* A stupidly quick query parser */
|
||||
char* parse_query(char* begin, struct http_query_info* info);
|
||||
|
||||
#endif // QUERY_H
|
|
@ -15,10 +15,6 @@
|
|||
<input type="checkbox" id="cfgjslive" name="jslive">
|
||||
<label for="cfgjslive">Live statuses - Statuses fetch on the fly</label>
|
||||
</li>
|
||||
<li>
|
||||
<input type="checkbox" id="cfgjsreply" name="jsreply">
|
||||
<label for="cfgjsreply">Quick reply - Replies don't require redirects</label>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- Appearance -->
|
||||
|
@ -44,5 +40,7 @@
|
|||
<label for="cfgdark">Dark</label>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<input type="submit" value="Save">
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -26,10 +26,15 @@
|
|||
<aside id="leftbar">
|
||||
<ul>
|
||||
<li><a class="sidebarbtn" href="#">Home</a></li>
|
||||
<li><a class="sidebarbtn" href="#">Notifications</a></li>
|
||||
<li><a class="sidebarbtn" href="#">Local</a></li>
|
||||
<li><a class="sidebarbtn" href="#">Federated</a></li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li><a class="sidebarbtn" href="#">Notifications</a></li>
|
||||
<li><a class="sidebarbtn" href="#">Lists</a></li>
|
||||
<li><a class="sidebarbtn" href="#">Direct</a></li>
|
||||
</ul>
|
||||
|
||||
<ul>
|
||||
<li><a class="sidebarbtn" href="/config">Config</a></li>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in a new issue