Modify backend to use new auth cookie format
[blerg.git] / http / canned_responses.c
1 /* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a
2  * BSD-style license.  Please see the COPYING file for details.
3  */
4 #include <string.h>
5 #include <microhttpd.h>
6 #include "app.h"
7 #include "canned_responses.h"
8
9 void init_responses() {
10         response_401 = MHD_create_response_from_data(strlen(CONTENT_401), CONTENT_401, MHD_NO, MHD_NO);  
11         response_403 = MHD_create_response_from_data(strlen(CONTENT_403), CONTENT_403, MHD_NO, MHD_NO);
12         response_404 = MHD_create_response_from_data(strlen(CONTENT_404), CONTENT_404, MHD_NO, MHD_NO);
13         response_405 = MHD_create_response_from_data(strlen(CONTENT_405), CONTENT_405, MHD_NO, MHD_NO);
14         response_JSON_Success = MHD_create_response_from_data(strlen(JSON_SUCCESS), JSON_SUCCESS, MHD_NO, MHD_NO);
15         response_JSON_Failure = MHD_create_response_from_data(strlen(JSON_FAILURE), JSON_FAILURE, MHD_NO, MHD_NO);
16 }
17
18 #define OPAQUE "d29fb6db8f21a6e99903651a9f87470e"
19 int respond_401(struct MHD_Connection *connection, int signal_stale) {
20         return MHD_queue_auth_fail_response(connection, REALM, OPAQUE, response_401, signal_stale);    
21 }
22
23 int respond_403(struct MHD_Connection *connection) {
24         return MHD_queue_response(connection, MHD_HTTP_FORBIDDEN, response_403);
25 }
26
27 int respond_404(struct MHD_Connection *connection) {
28         return MHD_queue_response(connection, MHD_HTTP_NOT_FOUND, response_404);
29 }
30
31 int respond_405(struct MHD_Connection *connection) {
32         return MHD_queue_response(connection, MHD_HTTP_METHOD_NOT_ALLOWED, response_405);
33 }
34
35 int respond_JSON_Success(struct MHD_Connection *connection) {
36         return MHD_queue_response(connection, MHD_HTTP_OK, response_JSON_Success);
37 }
38
39 int respond_JSON_Failure(struct MHD_Connection *connection) {
40         return MHD_queue_response(connection, MHD_HTTP_OK, response_JSON_Failure);
41 }
42