X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=http%2Fcanned_responses.c;fp=http%2Fcanned_responses.c;h=c61e2a763f844f4a9a3b3d1a10699adcb4b7b3b0;hb=1cf0f1ebfbd5b5a621af2a49ac0328fd0cec4bf4;hp=0000000000000000000000000000000000000000;hpb=da5af7e043fdf8992ae30ac19f33446f8133f178;p=blerg.git diff --git a/http/canned_responses.c b/http/canned_responses.c new file mode 100644 index 0000000..c61e2a7 --- /dev/null +++ b/http/canned_responses.c @@ -0,0 +1,43 @@ +#include +#include +#include "http.h" +#include "canned_responses.h" + +void init_responses() { +#define CONTENT_401 "401 Unauthorized

401 Unauthorized

DENIED" + response_401 = MHD_create_response_from_data(strlen (CONTENT_401), CONTENT_401, MHD_NO, MHD_NO); + +#define CONTENT_404 "404 Not Found

404 Not Found

I couldn't find that." + response_404 = MHD_create_response_from_data(strlen(CONTENT_404), CONTENT_404, MHD_NO, MHD_NO); + +#define CONTENT_405 "405 Method Not Allowed

405 Method Not Allowed

I'm sorry, Dave. I'm afraid I can't do that." + response_405 = MHD_create_response_from_data(strlen(CONTENT_405), CONTENT_405, MHD_NO, MHD_NO); + +#define JSON_SUCCESS "{status: \"success\"}" + response_JSON_Success = MHD_create_response_from_data(strlen(JSON_SUCCESS), JSON_SUCCESS, MHD_NO, MHD_NO); + +#define JSON_FAILURE "{status: \"failure\"}" + response_JSON_Failure = MHD_create_response_from_data(strlen(JSON_FAILURE), JSON_FAILURE, MHD_NO, MHD_NO); +} + +#define OPAQUE "d29fb6db8f21a6e99903651a9f87470e" +int respond_401(struct MHD_Connection *connection, int signal_stale) { + return MHD_queue_auth_fail_response(connection, REALM, OPAQUE, response_401, signal_stale); +} + +int respond_404(struct MHD_Connection *connection) { + return MHD_queue_response(connection, MHD_HTTP_NOT_FOUND, response_404); +} + +int respond_405(struct MHD_Connection *connection) { + return MHD_queue_response(connection, MHD_HTTP_METHOD_NOT_ALLOWED, response_405); +} + +int respond_JSON_Success(struct MHD_Connection *connection) { + return MHD_queue_response(connection, MHD_HTTP_OK, response_JSON_Success); +} + +int respond_JSON_Failure(struct MHD_Connection *connection) { + return MHD_queue_response(connection, MHD_HTTP_OK, response_JSON_Failure); +} +