aboutsummaryrefslogtreecommitdiff
path: root/src/examples/authorization_example.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/authorization_example.c')
-rw-r--r--src/examples/authorization_example.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/examples/authorization_example.c b/src/examples/authorization_example.c
index 8d26869a..fab6bd45 100644
--- a/src/examples/authorization_example.c
+++ b/src/examples/authorization_example.c
@@ -52,8 +52,7 @@ ahc_echo (void *cls,
52 static int aptr; 52 static int aptr;
53 struct MHD_Response *response; 53 struct MHD_Response *response;
54 enum MHD_Result ret; 54 enum MHD_Result ret;
55 char *user; 55 struct MHD_BasicAuthInfo *auth_info;
56 char *pass;
57 int fail; 56 int fail;
58 (void) cls; /* Unused. Silent compiler warning. */ 57 (void) cls; /* Unused. Silent compiler warning. */
59 (void) url; /* Unused. Silent compiler warning. */ 58 (void) url; /* Unused. Silent compiler warning. */
@@ -72,18 +71,26 @@ ahc_echo (void *cls,
72 *req_cls = NULL; /* reset when done */ 71 *req_cls = NULL; /* reset when done */
73 72
74 /* require: "Aladdin" with password "open sesame" */ 73 /* require: "Aladdin" with password "open sesame" */
75 pass = NULL; 74 auth_info = MHD_basic_auth_get_username_password3 (connection);
76 user = MHD_basic_auth_get_username_password (connection, 75 fail = ( (NULL == auth_info) ||
77 &pass); 76 (strlen ("Aladdin") != auth_info->username_len) ||
78 fail = ( (NULL == user) || 77 (0 != memcmp (auth_info->username, "Aladdin",
79 (0 != strcmp (user, "Aladdin")) || 78 auth_info->username_len)) ||
80 (0 != strcmp (pass, "open sesame") ) ); 79 /* The next check against NULL is optional,
80 * if 'password' is NULL then 'password_len' is always zero. */
81 (NULL == auth_info->password) ||
82 (strlen ("open sesame") != auth_info->password_len) ||
83 (0 != memcmp (auth_info->password, "open sesame",
84 auth_info->password_len)) );
81 if (fail) 85 if (fail)
82 { 86 {
83 response = 87 response =
84 MHD_create_response_from_buffer_static (strlen (DENIED), 88 MHD_create_response_from_buffer_static (strlen (DENIED),
85 (const void *) DENIED); 89 (const void *) DENIED);
86 ret = MHD_queue_basic_auth_fail_response (connection,"TestRealm",response); 90 ret = MHD_queue_basic_auth_fail_response3 (connection,
91 "TestRealm",
92 MHD_NO,
93 response);
87 } 94 }
88 else 95 else
89 { 96 {
@@ -92,10 +99,8 @@ ahc_echo (void *cls,
92 (const void *) PAGE); 99 (const void *) PAGE);
93 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 100 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
94 } 101 }
95 if (NULL != user) 102 if (NULL != auth_info)
96 MHD_free (user); 103 MHD_free (auth_info);
97 if (NULL != pass)
98 MHD_free (pass);
99 MHD_destroy_response (response); 104 MHD_destroy_response (response);
100 return ret; 105 return ret;
101} 106}