diff options
Diffstat (limited to 'src/examples/authorization_example.c')
-rw-r--r-- | src/examples/authorization_example.c | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/src/examples/authorization_example.c b/src/examples/authorization_example.c index d8a88203..c07d7827 100644 --- a/src/examples/authorization_example.c +++ b/src/examples/authorization_example.c | |||
@@ -32,9 +32,11 @@ | |||
32 | #include <windows.h> | 32 | #include <windows.h> |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" | 35 | #define PAGE \ |
36 | "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" | ||
36 | 37 | ||
37 | #define DENIED "<html><head><title>Access denied</title></head><body>Access denied</body></html>" | 38 | #define DENIED \ |
39 | "<html><head><title>Access denied</title></head><body>Access denied</body></html>" | ||
38 | 40 | ||
39 | 41 | ||
40 | 42 | ||
@@ -53,19 +55,19 @@ ahc_echo (void *cls, | |||
53 | char *user; | 55 | char *user; |
54 | char *pass; | 56 | char *pass; |
55 | int fail; | 57 | int fail; |
56 | (void)url; /* Unused. Silent compiler warning. */ | 58 | (void) url; /* Unused. Silent compiler warning. */ |
57 | (void)version; /* Unused. Silent compiler warning. */ | 59 | (void) version; /* Unused. Silent compiler warning. */ |
58 | (void)upload_data; /* Unused. Silent compiler warning. */ | 60 | (void) upload_data; /* Unused. Silent compiler warning. */ |
59 | (void)upload_data_size; /* Unused. Silent compiler warning. */ | 61 | (void) upload_data_size; /* Unused. Silent compiler warning. */ |
60 | 62 | ||
61 | if (0 != strcmp (method, "GET")) | 63 | if (0 != strcmp (method, "GET")) |
62 | return MHD_NO; /* unexpected method */ | 64 | return MHD_NO; /* unexpected method */ |
63 | if (&aptr != *ptr) | 65 | if (&aptr != *ptr) |
64 | { | 66 | { |
65 | /* do never respond on first call */ | 67 | /* do never respond on first call */ |
66 | *ptr = &aptr; | 68 | *ptr = &aptr; |
67 | return MHD_YES; | 69 | return MHD_YES; |
68 | } | 70 | } |
69 | *ptr = NULL; /* reset when done */ | 71 | *ptr = NULL; /* reset when done */ |
70 | 72 | ||
71 | /* require: "Aladdin" with password "open sesame" */ | 73 | /* require: "Aladdin" with password "open sesame" */ |
@@ -77,18 +79,18 @@ ahc_echo (void *cls, | |||
77 | (0 != strcmp (pass, "open sesame") ) ); | 79 | (0 != strcmp (pass, "open sesame") ) ); |
78 | if (fail) | 80 | if (fail) |
79 | { | 81 | { |
80 | response = MHD_create_response_from_buffer (strlen (DENIED), | 82 | response = MHD_create_response_from_buffer (strlen (DENIED), |
81 | (void *) DENIED, | 83 | (void *) DENIED, |
82 | MHD_RESPMEM_PERSISTENT); | 84 | MHD_RESPMEM_PERSISTENT); |
83 | ret = MHD_queue_basic_auth_fail_response (connection,"TestRealm",response); | 85 | ret = MHD_queue_basic_auth_fail_response (connection,"TestRealm",response); |
84 | } | 86 | } |
85 | else | 87 | else |
86 | { | 88 | { |
87 | response = MHD_create_response_from_buffer (strlen (me), | 89 | response = MHD_create_response_from_buffer (strlen (me), |
88 | (void *) me, | 90 | (void *) me, |
89 | MHD_RESPMEM_PERSISTENT); | 91 | MHD_RESPMEM_PERSISTENT); |
90 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 92 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); |
91 | } | 93 | } |
92 | if (NULL != user) | 94 | if (NULL != user) |
93 | MHD_free (user); | 95 | MHD_free (user); |
94 | if (NULL != pass) | 96 | if (NULL != pass) |
@@ -107,13 +109,14 @@ main (int argc, char *const *argv) | |||
107 | if ( (argc != 2) || | 109 | if ( (argc != 2) || |
108 | (1 != sscanf (argv[1], "%u", &port)) || | 110 | (1 != sscanf (argv[1], "%u", &port)) || |
109 | (UINT16_MAX < port) ) | 111 | (UINT16_MAX < port) ) |
110 | { | 112 | { |
111 | fprintf (stderr, | 113 | fprintf (stderr, |
112 | "%s PORT\n", argv[0]); | 114 | "%s PORT\n", argv[0]); |
113 | return 1; | 115 | return 1; |
114 | } | 116 | } |
115 | 117 | ||
116 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | 118 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION |
119 | | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, | ||
117 | atoi (argv[1]), | 120 | atoi (argv[1]), |
118 | NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END); | 121 | NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END); |
119 | if (d == NULL) | 122 | if (d == NULL) |