2 #include <microhttpd.h>
4 #include "canned_responses.h"
6 void init_responses() {
7 #define CONTENT_401 "<html><head><title>401 Unauthorized</title></head><body><h1>401 Unauthorized</h1>DENIED</body></html>"
8 response_401 = MHD_create_response_from_data(strlen (CONTENT_401), CONTENT_401, MHD_NO, MHD_NO);
10 #define CONTENT_404 "<html><head><title>404 Not Found</title></head><body><h1>404 Not Found</h1>I couldn't find that.</body></html>"
11 response_404 = MHD_create_response_from_data(strlen(CONTENT_404), CONTENT_404, MHD_NO, MHD_NO);
13 #define CONTENT_405 "<html><head><title>405 Method Not Allowed</title></head><body><h1>405 Method Not Allowed</h1>I'm sorry, Dave. I'm afraid I can't do that.</body></html>"
14 response_405 = MHD_create_response_from_data(strlen(CONTENT_405), CONTENT_405, MHD_NO, MHD_NO);
16 #define JSON_SUCCESS "{status: \"success\"}"
17 response_JSON_Success = MHD_create_response_from_data(strlen(JSON_SUCCESS), JSON_SUCCESS, MHD_NO, MHD_NO);
19 #define JSON_FAILURE "{status: \"failure\"}"
20 response_JSON_Failure = MHD_create_response_from_data(strlen(JSON_FAILURE), JSON_FAILURE, MHD_NO, MHD_NO);
23 #define OPAQUE "d29fb6db8f21a6e99903651a9f87470e"
24 int respond_401(struct MHD_Connection *connection, int signal_stale) {
25 return MHD_queue_auth_fail_response(connection, REALM, OPAQUE, response_401, signal_stale);
28 int respond_404(struct MHD_Connection *connection) {
29 return MHD_queue_response(connection, MHD_HTTP_NOT_FOUND, response_404);
32 int respond_405(struct MHD_Connection *connection) {
33 return MHD_queue_response(connection, MHD_HTTP_METHOD_NOT_ALLOWED, response_405);
36 int respond_JSON_Success(struct MHD_Connection *connection) {
37 return MHD_queue_response(connection, MHD_HTTP_OK, response_JSON_Success);
40 int respond_JSON_Failure(struct MHD_Connection *connection) {
41 return MHD_queue_response(connection, MHD_HTTP_OK, response_JSON_Failure);