33 #include <microhttpd.h>
38 #define DATE_2822_LEN 100
43 #define EXPIRES_LENGTH 100
48 #define UTF8_ERROR_PAGE(location) \
50 "<head><title>Invalid request</title></head>" \
51 "<body>The request contained invalid UTF-8 in " location ".</body>" \
57 #define SID_COOKIE_NAME "GSAD_SID"
59 #define REMOVE_SID "0"
64 #define NOT_FOUND_TITLE "Invalid request"
69 #define NOT_FOUND_MESSAGE "The requested page or file does not exist."
74 #define ERROR_PAGE "<html><body>HTTP Method not supported</body></html>"
79 #define BAD_REQUEST_PAGE "<html><body>Bad request.</body></html>"
84 #define SERVER_ERROR \
85 "<html><body>An internal server error has occurred.</body></html>"
92 #define MAX_HOST_LEN 1000
94 #define LOGIN_URL "/login"
95 #define LOGOUT_URL "/logout"
100 #define POST_BUFFER_SIZE 500000
106 #ifndef MHD_HTTP_NOT_ACCEPTABLE
107 #define MHD_HTTP_NOT_ACCEPTABLE MHD_HTTP_METHOD_NOT_ACCEPTABLE
113 #define MAX_FILE_NAME_SIZE 128
172 int http_status_code,
178 const char *content_disposition,
size_t content_length);
207 #if MHD_VERSION < 0x00097002
212 serve_post (
void *coninfo_cls,
enum MHD_ValueKind kind,
const char *key,
214 const char *transfer_encoding,
const char *data, uint64_t off,
233 const char *client_address);
237 const char *chunk_data,
int chunk_size,
int chunk_offset);
Headers for Response Data struct.
Headers for content type.
content_type
Content types.
Definition: gsad_content_type.h:31
enum content_type content_type_t
Definition: gsad_content_type.h:53
GSAD credentials handling.
int attach_sid(http_response_t *response, const char *sid)
Attach SID cookie to a response, resetting "expire" arg.
Definition: gsad_http.c:535
struct gsad_connection_info gsad_connection_info_t
Connection information.
struct MHD_Response http_response_t
Definition: gsad_http.h:136
struct MHD_Connection http_connection_t
Definition: gsad_http.h:134
void add_forbid_caching_headers(http_response_t *response)
Add header to forbid caching to a HTTP response.
Definition: gsad_http.c:863
int handler_send_reauthentication(http_connection_t *connection, int http_status_code, authentication_reason_t reason)
Allow for reauthentication of a user.
Definition: gsad_http.c:433
content_type_t guess_content_type(const gchar *path)
Guess a content type from a file extension.
Definition: gsad_http.c:55
int exec_gmp_post(http_connection_t *connection, gsad_connection_info_t *con_info, const char *client_address)
int serve_post(void *coninfo_cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size)
Serves part of a POST request.
Definition: gsad_http.c:934
int send_redirect_to_uri(http_connection_t *connection, const char *uri, const gchar *sid)
Sends a HTTP redirection to an uri.
Definition: gsad_http.c:182
gchar * reconstruct_url(http_connection_t *connection, const char *url)
Reconstruct the URL for a connection.
Definition: gsad_http.c:788
int exec_gmp_get(http_connection_t *connection, gsad_connection_info_t *con_info, credentials_t *credentials)
enum authentication_reason authentication_reason_t
Definition: gsad_http.h:168
int handler_send_response(http_connection_t *connection, http_response_t *response, cmd_response_data_t *response_data, const gchar *sid)
Send response for handle_request.
Definition: gsad_http.c:293
int attach_remove_sid(http_response_t *response, const gchar *sid)
Definition: gsad_http.c:614
int handler_create_response(http_connection_t *connection, gchar *data, cmd_response_data_t *response_data, const gchar *sid)
Create and send a response.
Definition: gsad_http.c:366
int remove_sid(http_response_t *response)
Attach expired SID cookie to response.
Definition: gsad_http.c:489
authentication_reason
Content types.
Definition: gsad_http.h:156
@ GMP_SERVICE_DOWN
Definition: gsad_http.h:161
@ LOGOUT_ALREADY
Definition: gsad_http.h:160
@ BAD_MISSING_TOKEN
Definition: gsad_http.h:164
@ LOGOUT
Definition: gsad_http.h:159
@ BAD_MISSING_COOKIE
Definition: gsad_http.h:163
@ UNKOWN_ERROR
Definition: gsad_http.h:165
@ LOGIN_ERROR
Definition: gsad_http.h:158
@ LOGIN_FAILED
Definition: gsad_http.h:157
@ SESSION_EXPIRED
Definition: gsad_http.h:162
int params_append_mhd(params_t *params, const char *name, const char *filename, const char *chunk_data, int chunk_size, int chunk_offset)
void add_cors_headers(http_response_t *response)
Definition: gsad_http.c:843
int get_client_address(http_connection_t *conn, char *client_address)
Get the client's address.
Definition: gsad_http.c:881
void add_guest_chart_content_security_headers(http_response_t *response)
Add guest chart content security headers to a MHD response.
Definition: gsad_http.c:832
char * gsad_message(credentials_t *, const char *, const char *, int, const char *, cmd_response_data_t *)
Handles fatal errors.
Definition: gsad_http.c:964
int send_response(http_connection_t *connection, const char *content, int status_code, const gchar *sid, content_type_t content_type, const char *content_disposition, size_t content_length)
Sends a HTTP response.
Definition: gsad_http.c:242
void add_security_headers(http_response_t *response)
Add security headers to a MHD response.
Definition: gsad_http.c:810
http_response_t * file_content_response(http_connection_t *connection, const char *url, const char *path, cmd_response_data_t *response_data)
Create a response to serve a file from a path.
Definition: gsad_http.c:672
void gsad_add_content_type_header(http_response_t *response, content_type_t *ct)
Adds content-type header fields to a response.
Definition: gsad_http.c:88
#define params_t
Definition: gsad_params.h:30
Response information for commands.
Definition: gsad_cmd.c:33
Structure of credential related information.
Definition: gsad_credentials.c:34
Connection information.
Definition: gsad_http.h:125
int connectiontype
1=POST, 2=GET.
Definition: gsad_http.h:130
char * cookie
Value of SID cookie param.
Definition: gsad_http.h:128
params_t * params
Request parameters.
Definition: gsad_http.h:127
struct MHD_PostProcessor * postprocessor
POST processor.
Definition: gsad_http.h:126
char * language
Language code e.g. en.
Definition: gsad_http.h:129
gchar * redirect
Redirect URL.
Definition: gsad_http.h:131