aboutsummaryrefslogtreecommitdiff
path: root/src/examples/https_fileserver_example.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-10-05 23:16:19 +0200
committerChristian Grothoff <christian@grothoff.org>2017-10-05 23:16:19 +0200
commit1a23dd25c36bdb0e0be264730e9088a49a1e8152 (patch)
tree0df4a2329e32c5908b6ffd9d5aa9eda2cd075a4c /src/examples/https_fileserver_example.c
parent111e08fbe3f436bd21f78ab8c6c4c3b79e728bba (diff)
downloadlibmicrohttpd-1a23dd25c36bdb0e0be264730e9088a49a1e8152.tar.gz
libmicrohttpd-1a23dd25c36bdb0e0be264730e9088a49a1e8152.zip
misc style improvements, fixing some tiny rare memory leaks in examples
Diffstat (limited to 'src/examples/https_fileserver_example.c')
-rw-r--r--src/examples/https_fileserver_example.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/examples/https_fileserver_example.c b/src/examples/https_fileserver_example.c
index 453ca2ff..818c8d55 100644
--- a/src/examples/https_fileserver_example.c
+++ b/src/examples/https_fileserver_example.c
@@ -191,38 +191,44 @@ int
191main (int argc, char *const *argv) 191main (int argc, char *const *argv)
192{ 192{
193 struct MHD_Daemon *TLS_daemon; 193 struct MHD_Daemon *TLS_daemon;
194 int port;
194 195
195 if (argc == 2) 196 if (argc != 2)
196 { 197 {
197 /* TODO check if this is truly necessary - disallow usage of the blocking /dev/random */ 198 printf ("%s PORT\n", argv[0]);
198 /* gcry_control(GCRYCTL_ENABLE_QUICK_RANDOM, 0); */ 199 return 1;
199 TLS_daemon =
200 MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
201 MHD_USE_TLS, atoi (argv[1]), NULL, NULL, &http_ahc,
202 NULL, MHD_OPTION_CONNECTION_TIMEOUT, 256,
203 MHD_OPTION_HTTPS_MEM_KEY, key_pem,
204 MHD_OPTION_HTTPS_MEM_CERT, cert_pem,
205 MHD_OPTION_END);
206 } 200 }
207 else 201 port = atoi (argv[1]);
202 if ( (1 > port) ||
203 (port > UINT16_MAX) )
208 { 204 {
209 printf ("Usage: %s HTTP-PORT\n", argv[0]); 205 fprintf (stderr,
206 "Port must be a number between 1 and 65535\n");
210 return 1; 207 return 1;
211 } 208 }
212 209
213 if (TLS_daemon == NULL) 210 /* TODO check if this is truly necessary - disallow usage of the blocking /dev/random */
211 /* gcry_control(GCRYCTL_ENABLE_QUICK_RANDOM, 0); */
212 TLS_daemon =
213 MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG |
214 MHD_USE_TLS,
215 (uint16_t) port,
216 NULL, NULL,
217 &http_ahc, NULL,
218 MHD_OPTION_CONNECTION_TIMEOUT, 256,
219 MHD_OPTION_HTTPS_MEM_KEY, key_pem,
220 MHD_OPTION_HTTPS_MEM_CERT, cert_pem,
221 MHD_OPTION_END);
222 if (NULL == TLS_daemon)
214 { 223 {
215 fprintf (stderr, "Error: failed to start TLS_daemon\n"); 224 fprintf (stderr, "Error: failed to start TLS_daemon\n");
216 return 1; 225 return 1;
217 } 226 }
218 else 227 printf ("MHD daemon listening on port %u\n",
219 { 228 (unsigned int) port);
220 printf ("MHD daemon listening on port %d\n", atoi (argv[1]));
221 }
222 229
223 (void) getc (stdin); 230 (void) getc (stdin);
224 231
225 MHD_stop_daemon (TLS_daemon); 232 MHD_stop_daemon (TLS_daemon);
226
227 return 0; 233 return 0;
228} 234}