Fix read(0) bug
FCGI_stdio does not map stdin's socket, it only wraps the stdio FILE* FossilOrigin-Name: 0e068eda84d8938d2c47eca010cf828c661f76de29547bb6ce46855f09247bb4
This commit is contained in:
parent
0f181fc9bb
commit
0779ca5060
15 changed files with 28 additions and 26 deletions
|
@ -95,7 +95,7 @@ void content_account(mastodont_t* api, char** data, size_t size)
|
|||
struct base_page b = {
|
||||
.locale = L10N_EN_US,
|
||||
.content = account_page,
|
||||
.sidebar_right = NULL
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
/* Output */
|
||||
|
|
|
@ -93,6 +93,8 @@ void render_base_page(struct base_page* page, mastodont_t* api)
|
|||
L10N[locale][L10N_DIRECT],
|
||||
config_url_prefix,
|
||||
L10N[locale][L10N_CONFIG],
|
||||
page->sidebar_left ?
|
||||
page->sidebar_left : "",
|
||||
page->content,
|
||||
sidebar_str ? sidebar_str : "<p>Not logged in</p>");
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ struct base_page
|
|||
{
|
||||
enum l10n_locale locale;
|
||||
char* content;
|
||||
char* sidebar_right;
|
||||
char* sidebar_left;
|
||||
};
|
||||
|
||||
void render_base_page(struct base_page* page, mastodont_t* api);
|
||||
|
|
|
@ -44,7 +44,7 @@ void content_not_found(mastodont_t* api, char* path)
|
|||
struct base_page b = {
|
||||
.locale = L10N_EN_US,
|
||||
.content = page,
|
||||
.sidebar_right = NULL
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
render_base_page(&b, api);
|
||||
|
|
|
@ -85,7 +85,7 @@ void content_lists(mastodont_t* api, char** data, size_t size)
|
|||
struct base_page b = {
|
||||
.locale = L10N_EN_US,
|
||||
.content = lists_page,
|
||||
.sidebar_right = NULL
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
// Output
|
||||
|
|
|
@ -37,6 +37,7 @@ void content_login(mastodont_t* api, char** data, size_t data_size)
|
|||
char* error = NULL;
|
||||
char* page;
|
||||
|
||||
printf("%s: %s\r\n", post.username ? post.username: "none", post.password ? post.password : "none");
|
||||
if (post.username && post.password)
|
||||
{
|
||||
// Getting the client id/secret
|
||||
|
@ -71,7 +72,7 @@ void content_login(mastodont_t* api, char** data, size_t data_size)
|
|||
printf("Set-Cookie: access_token=%s; Path=/; Max-Age=31536000\r\n", token.access_token);
|
||||
printf("Set-Cookie: logged_in=t; Path=/; Max-Age=31536000\r\n");
|
||||
// if config_url_prefix is empty, make it root
|
||||
printf("Location: %s/\r\n",
|
||||
printf("Location: %s\r\n\r\nRedirecting...",
|
||||
config_url_prefix[0] == '\0' ?
|
||||
"/" : config_url_prefix);
|
||||
return;
|
||||
|
@ -90,7 +91,7 @@ void content_login(mastodont_t* api, char** data, size_t data_size)
|
|||
struct base_page b = {
|
||||
.locale = L10N_EN_US,
|
||||
.content = page,
|
||||
.sidebar_right = NULL
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
// Output
|
||||
|
|
|
@ -43,7 +43,7 @@ int main(void)
|
|||
unsigned run_count = 1;
|
||||
|
||||
// API
|
||||
for (;FCGI_Accept() >= 0; ++run_count)
|
||||
while (FCGI_Accept() >= 0)
|
||||
{
|
||||
mastodont_t api;
|
||||
api.url = config_instance_url;
|
||||
|
|
|
@ -91,7 +91,7 @@ void content_notifications(mastodont_t* api, char** data, size_t data_size)
|
|||
struct base_page b = {
|
||||
.locale = L10N_EN_US,
|
||||
.content = data_notifications_page_html,
|
||||
.sidebar_right = NULL
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
// Output
|
||||
|
|
|
@ -43,7 +43,7 @@ void content_config(mastodont_t* api, char** data, size_t size)
|
|||
struct base_page b = {
|
||||
.locale = L10N_EN_US,
|
||||
.content = data_config_html,
|
||||
.sidebar_right = NULL
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
render_base_page(&b, api);
|
||||
|
|
20
src/query.c
20
src/query.c
|
@ -16,9 +16,9 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <fcgi_stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "query.h"
|
||||
#include "key.h"
|
||||
|
@ -28,7 +28,6 @@ struct query_values post = { 0 };
|
|||
char* read_post_data()
|
||||
{
|
||||
struct http_query_info info;
|
||||
char* post_env = getenv("POST");
|
||||
char* request_method = getenv("REQUEST_METHOD");
|
||||
char* post_query = NULL, *p_query_read;
|
||||
|
||||
|
@ -44,22 +43,19 @@ char* read_post_data()
|
|||
};
|
||||
// END Query references
|
||||
|
||||
if ((request_method && (strcmp("POST", request_method) == 0)) || post_env)
|
||||
if (request_method && strcmp("POST", request_method) == 0)
|
||||
{
|
||||
int content_length = post_env ? strlen(post_env) : atoi(getenv("CONTENT_LENGTH"));
|
||||
int content_length = atoi(getenv("CONTENT_LENGTH"));
|
||||
post_query = malloc(content_length + 1);
|
||||
if (!post_query)
|
||||
{
|
||||
perror("malloc");
|
||||
return NULL;
|
||||
}
|
||||
if (post_env)
|
||||
strcpy(post_query, post_env);
|
||||
else {
|
||||
// Read in data
|
||||
read(STDIN_FILENO, post_query, content_length);
|
||||
post_query[content_length] = '\0';
|
||||
}
|
||||
|
||||
// fread should be a macro to FCGI_fread, which is set by FCGI_Accept in previous definitions
|
||||
size_t len = fread(post_query, 1, content_length, stdin);
|
||||
post_query[content_length] = '\0';
|
||||
|
||||
// For shifting through
|
||||
p_query_read = post_query;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#ifndef QUERY_H
|
||||
#define QUERY_H
|
||||
#include <fcgi_stdio.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct http_query_info
|
||||
|
|
|
@ -217,7 +217,7 @@ void content_status(mastodont_t* api, char** data, size_t data_size, int is_repl
|
|||
struct base_page b = {
|
||||
.locale = L10N_EN_US,
|
||||
.content = output,
|
||||
.sidebar_right = NULL
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
// Output
|
||||
|
|
|
@ -70,7 +70,7 @@ void content_test(mastodont_t* api, char** data, size_t data_size)
|
|||
struct base_page b = {
|
||||
.locale = L10N_EN_US,
|
||||
.content = page,
|
||||
.sidebar_right = NULL
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
// Output
|
||||
|
|
|
@ -65,7 +65,7 @@ void tl_public(mastodont_t* api, int local)
|
|||
struct base_page b = {
|
||||
.locale = L10N_EN_US,
|
||||
.content = output,
|
||||
.sidebar_right = NULL
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
// Output
|
||||
|
@ -116,7 +116,7 @@ void tl_list(mastodont_t* api, char* list_id)
|
|||
struct base_page b = {
|
||||
.locale = L10N_EN_US,
|
||||
.content = output,
|
||||
.sidebar_right = NULL
|
||||
.sidebar_left = NULL
|
||||
};
|
||||
|
||||
// Output
|
||||
|
|
|
@ -31,8 +31,10 @@
|
|||
<li><a class="sidebarbtn" href="%s/federated/">%s</a></li>
|
||||
<li><a class="sidebarbtn" href="%s/notifications">%s</a></li>
|
||||
<li><a class="sidebarbtn" href="%s/lists">%s</a></li>
|
||||
<li><a class="sidebarbtn" href="%s/direct">%s</a></li> <li><a class="sidebarbtn" href="%s/config">%s</a></li>
|
||||
<li><a class="sidebarbtn" href="%s/direct">%s</a></li>
|
||||
<li><a class="sidebarbtn" href="%s/config">%s</a></li>
|
||||
</ul>
|
||||
%s
|
||||
</td>
|
||||
|
||||
<!-- Display for posts -->
|
||||
|
|
Loading…
Reference in a new issue