diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-12-01 14:24:24 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-12-01 14:24:24 +0000 |
commit | de35faa11a8bcfb8a771a924f183694be7ba0ddb (patch) | |
tree | d42507b5eed7604f48b0748e2dccac155d4e15a7 | |
parent | 5f6d6b2ccc8dfaeef9c961a7c91d62597fa406d3 (diff) | |
download | libmicrohttpd-de35faa11a8bcfb8a771a924f183694be7ba0ddb.tar.gz libmicrohttpd-de35faa11a8bcfb8a771a924f183694be7ba0ddb.zip |
Hi there,
am I right in the assumption, that the documentation at
http://www.gnu.org/s/libmicrohttpd/tutorial.html#Supporting-basic-authentication
is newer than authorization_example.c in the src/examples/ subdirectory?
If so here is a patch to make authorization_example.c use the functions from
the tutorial instead of raw base64 strings.
Regards
Sven
-
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/examples/authorization_example.c | 27 |
3 files changed, 18 insertions, 14 deletions
@@ -35,6 +35,7 @@ Zhimin Huang <zhimin.huang@bqvision.com> | |||
35 | Jan Seeger <jan.seeger@thenybble.de> | 35 | Jan Seeger <jan.seeger@thenybble.de> |
36 | Will Bryant <will.bryant@gmail.com> | 36 | Will Bryant <will.bryant@gmail.com> |
37 | LRN <lrn1986@gmail.com> | 37 | LRN <lrn1986@gmail.com> |
38 | Sven Geggus <sts@fuchsschwanzdomain.de> | ||
38 | 39 | ||
39 | Documentation contributions also came from: | 40 | Documentation contributions also came from: |
40 | Marco Maggi <marco.maggi-ipsu@poste.it> | 41 | Marco Maggi <marco.maggi-ipsu@poste.it> |
@@ -1,3 +1,7 @@ | |||
1 | Thu Dec 1 15:22:57 CET 2011 | ||
2 | Updated authorization_example.c to actually demonstrate the current | ||
3 | MHD API. -SG | ||
4 | |||
1 | Mon Nov 21 18:51:30 CET 2011 | 5 | Mon Nov 21 18:51:30 CET 2011 |
2 | Added option to suppress generation of the 'Date:' header to be | 6 | Added option to suppress generation of the 'Date:' header to be |
3 | used on embedded systems without RTC. Documented the new option | 7 | used on embedded systems without RTC. Documented the new option |
diff --git a/src/examples/authorization_example.c b/src/examples/authorization_example.c index 60512183..bb480267 100644 --- a/src/examples/authorization_example.c +++ b/src/examples/authorization_example.c | |||
@@ -44,8 +44,9 @@ ahc_echo (void *cls, | |||
44 | const char *me = cls; | 44 | const char *me = cls; |
45 | struct MHD_Response *response; | 45 | struct MHD_Response *response; |
46 | int ret; | 46 | int ret; |
47 | int code; | 47 | char *user; |
48 | const char *auth; | 48 | char *pass; |
49 | int fail; | ||
49 | 50 | ||
50 | if (0 != strcmp (method, "GET")) | 51 | if (0 != strcmp (method, "GET")) |
51 | return MHD_NO; /* unexpected method */ | 52 | return MHD_NO; /* unexpected method */ |
@@ -56,28 +57,26 @@ ahc_echo (void *cls, | |||
56 | return MHD_YES; | 57 | return MHD_YES; |
57 | } | 58 | } |
58 | *ptr = NULL; /* reset when done */ | 59 | *ptr = NULL; /* reset when done */ |
59 | auth = MHD_lookup_connection_value (connection, | 60 | |
60 | MHD_HEADER_KIND, | 61 | /* require: "Aladdin" with password "open sesame" */ |
61 | MHD_HTTP_HEADER_AUTHORIZATION); | 62 | pass = NULL; |
62 | if ((auth == NULL) || | 63 | user = MHD_basic_auth_get_username_password (connection, &pass); |
63 | (0 != strcmp (auth, "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="))) | 64 | fail = ( (user == NULL) || (0 != strcmp (user, "Aladdin")) || (0 != strcmp (pass, "open sesame") ) ); |
64 | { | 65 | if (fail) |
65 | /* require: "Aladdin" with password "open sesame" */ | 66 | { |
66 | response = MHD_create_response_from_buffer (strlen (DENIED), | 67 | response = MHD_create_response_from_buffer (strlen (DENIED), |
67 | (void *) DENIED, | 68 | (void *) DENIED, |
68 | MHD_RESPMEM_PERSISTENT); | 69 | MHD_RESPMEM_PERSISTENT); |
69 | MHD_add_response_header (response, MHD_HTTP_HEADER_WWW_AUTHENTICATE, | 70 | ret = MHD_queue_basic_auth_fail_response (connection,"TestRealm",response); |
70 | "Basic realm=\"TestRealm\""); | ||
71 | code = MHD_HTTP_UNAUTHORIZED; | ||
72 | } | 71 | } |
73 | else | 72 | else |
74 | { | 73 | { |
75 | response = MHD_create_response_from_buffer (strlen (me), | 74 | response = MHD_create_response_from_buffer (strlen (me), |
76 | (void *) me, | 75 | (void *) me, |
77 | MHD_RESPMEM_PERSISTENT); | 76 | MHD_RESPMEM_PERSISTENT); |
78 | code = MHD_HTTP_OK; | 77 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
79 | } | 78 | } |
80 | ret = MHD_queue_response (connection, code, response); | 79 | |
81 | MHD_destroy_response (response); | 80 | MHD_destroy_response (response); |
82 | return ret; | 81 | return ret; |
83 | } | 82 | } |