|
|
@ -2,7 +2,11 @@ |
|
|
|
/* Copyright 2022 Ivan Polyakov */ |
|
|
|
/* Copyright 2022 Ivan Polyakov */ |
|
|
|
|
|
|
|
|
|
|
|
#include "../include/servers/fcgi.h" |
|
|
|
#include "../include/servers/fcgi.h" |
|
|
|
|
|
|
|
#include "../c/utils.h" |
|
|
|
|
|
|
|
#include <ctype.h> |
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
#include <string.h> |
|
|
|
|
|
|
|
|
|
|
|
#ifdef MT_ENABLED |
|
|
|
#ifdef MT_ENABLED |
|
|
|
#include <pthread.h> |
|
|
|
#include <pthread.h> |
|
|
@ -56,6 +60,8 @@ static int read_fcgx_req_body(char **dest, FCGX_Request *req); |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static void send_response(rpd_res *res, FCGX_Stream *out); |
|
|
|
static void send_response(rpd_res *res, FCGX_Stream *out); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int env_to_req_header(char **key, char **val, const char *envp); |
|
|
|
|
|
|
|
|
|
|
|
int rpd_fcgi_server_start(rpd_app *app, const char *sock_path) |
|
|
|
int rpd_fcgi_server_start(rpd_app *app, const char *sock_path) |
|
|
|
{ |
|
|
|
{ |
|
|
|
FCGX_Init(); |
|
|
|
FCGX_Init(); |
|
|
@ -155,9 +161,39 @@ static int fcgx_to_rpd_req(rpd_req *dest, FCGX_Request *req) |
|
|
|
|
|
|
|
|
|
|
|
dest->method = rpd_req_smethod(FCGX_GetParam("REQUEST_METHOD", req->envp)); |
|
|
|
dest->method = rpd_req_smethod(FCGX_GetParam("REQUEST_METHOD", req->envp)); |
|
|
|
rpd_url_parse(&dest->path, FCGX_GetParam("DOCUMENT_URI", req->envp)); |
|
|
|
rpd_url_parse(&dest->path, FCGX_GetParam("DOCUMENT_URI", req->envp)); |
|
|
|
dest->auth = FCGX_GetParam("HTTP_AUTHORIZATION", req->envp); |
|
|
|
// dest->auth = FCGX_GetParam("HTTP_AUTHORIZATION", req->envp);
|
|
|
|
dest->cookie = FCGX_GetParam("HTTP_COOKIE", req->envp); |
|
|
|
// dest->cookie = FCGX_GetParam("HTTP_COOKIE", req->envp);
|
|
|
|
rpd_keyval_init(&dest->params, 0); |
|
|
|
rpd_keyval_init(&dest->params, 0); |
|
|
|
|
|
|
|
rpd_keyval_init(&dest->headers, 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char **env = req->envp; |
|
|
|
|
|
|
|
char *key = NULL, *val = NULL; |
|
|
|
|
|
|
|
while (*(++env)) { |
|
|
|
|
|
|
|
char *ptr = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* keep only http request fields */ |
|
|
|
|
|
|
|
ptr = strstr(*env, "HTTP"); |
|
|
|
|
|
|
|
if (ptr == NULL || ptr - *env != 0) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
env_to_req_header(&key, &val, *env); |
|
|
|
|
|
|
|
if (!val || !key) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
rpd_strerase(key, 5); |
|
|
|
|
|
|
|
ptr = key; |
|
|
|
|
|
|
|
while (*ptr) { |
|
|
|
|
|
|
|
*ptr = tolower(*ptr); |
|
|
|
|
|
|
|
if (ptr == key || *(ptr - 1) == '-') |
|
|
|
|
|
|
|
*ptr = toupper(*ptr); |
|
|
|
|
|
|
|
if (*ptr == '_') |
|
|
|
|
|
|
|
*ptr = '-'; |
|
|
|
|
|
|
|
ptr++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rpd_keyval_insert(&dest->headers, key, val); |
|
|
|
|
|
|
|
free(key); |
|
|
|
|
|
|
|
free(val); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (dest->method != GET) { |
|
|
|
if (dest->method != GET) { |
|
|
|
if (read_fcgx_req_body(&dest->body, req)) { |
|
|
|
if (read_fcgx_req_body(&dest->body, req)) { |
|
|
@ -186,3 +222,19 @@ static int read_fcgx_req_body(char **dest, FCGX_Request *req) |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int env_to_req_header(char **key, char **val, const char *env) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
const char *ptr = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rpd_splitbyc(key, val, env, '='); |
|
|
|
|
|
|
|
if (!*key || !*val) { |
|
|
|
|
|
|
|
if (*key) |
|
|
|
|
|
|
|
free(*key); |
|
|
|
|
|
|
|
if (*val) |
|
|
|
|
|
|
|
free(*val); |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|