aboutsummaryrefslogtreecommitdiff
path: root/src/examples/digest_auth_example.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-09-04 19:55:40 +0000
committerChristian Grothoff <christian@grothoff.org>2010-09-04 19:55:40 +0000
commit5bb652c3df7c46bf509321f90048128ae900d381 (patch)
treec21584f7e3758484d9eee9cef54954dd8ebe6f54 /src/examples/digest_auth_example.c
parent4f372879cc1273fd87ad346ccc31b7086ac65fcc (diff)
downloadlibmicrohttpd-5bb652c3df7c46bf509321f90048128ae900d381.tar.gz
libmicrohttpd-5bb652c3df7c46bf509321f90048128ae900d381.zip
fix parser issue, allow client to specify access-denied response body
Diffstat (limited to 'src/examples/digest_auth_example.c')
-rw-r--r--src/examples/digest_auth_example.c39
1 files changed, 29 insertions, 10 deletions
diff --git a/src/examples/digest_auth_example.c b/src/examples/digest_auth_example.c
index 8f3ed4ec..51c81b83 100644
--- a/src/examples/digest_auth_example.c
+++ b/src/examples/digest_auth_example.c
@@ -26,7 +26,9 @@
26#include <microhttpd.h> 26#include <microhttpd.h>
27#include <stdlib.h> 27#include <stdlib.h>
28 28
29#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" 29#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>"
30
31#define DENIED "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>"
30 32
31#define OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4" 33#define OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4"
32 34
@@ -46,20 +48,37 @@ ahc_echo (void *cls,
46 48
47 username = MHD_digest_auth_get_username(connection); 49 username = MHD_digest_auth_get_username(connection);
48 if (username == NULL) 50 if (username == NULL)
49 return MHD_queue_auth_fail_response(connection, realm, 51 {
50 OPAQUE, 52 response = MHD_create_response_from_data(strlen (DENIED),
51 MHD_NO); 53 DENIED,
54 MHD_NO, MHD_NO);
55 ret = MHD_queue_auth_fail_response(connection, realm,
56 OPAQUE,
57 response,
58 MHD_NO);
59 MHD_destroy_response(response);
60 return ret;
61 }
52 ret = MHD_digest_auth_check(connection, realm, 62 ret = MHD_digest_auth_check(connection, realm,
53 username, 63 username,
54 password, 64 password,
55 300); 65 300);
56 free(username); 66 free(username);
57 if (ret == MHD_INVALID_NONCE) 67 if ( (ret == MHD_INVALID_NONCE) ||
58 return MHD_queue_auth_fail_response(connection, realm, 68 (ret == MHD_NO) )
59 OPAQUE, MHD_YES); 69 {
60 if (ret == MHD_NO) 70 response = MHD_create_response_from_data(strlen (DENIED),
61 return MHD_queue_auth_fail_response(connection, realm, 71 DENIED,
62 OPAQUE, MHD_NO); 72 MHD_NO, MHD_NO);
73 if (NULL == response)
74 return MHD_NO;
75 ret = MHD_queue_auth_fail_response(connection, realm,
76 OPAQUE,
77 response,
78 (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO);
79 MHD_destroy_response(response);
80 return ret;
81 }
63 response = MHD_create_response_from_data(strlen(PAGE), PAGE, 82 response = MHD_create_response_from_data(strlen(PAGE), PAGE,
64 MHD_NO, MHD_NO); 83 MHD_NO, MHD_NO);
65 ret = MHD_queue_response(connection, MHD_HTTP_OK, response); 84 ret = MHD_queue_response(connection, MHD_HTTP_OK, response);