aboutsummaryrefslogtreecommitdiff
path: root/src/examples/minimal_example_empty_tls.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/minimal_example_empty_tls.c')
-rw-r--r--src/examples/minimal_example_empty_tls.c150
1 files changed, 150 insertions, 0 deletions
diff --git a/src/examples/minimal_example_empty_tls.c b/src/examples/minimal_example_empty_tls.c
new file mode 100644
index 00000000..e3daca5f
--- /dev/null
+++ b/src/examples/minimal_example_empty_tls.c
@@ -0,0 +1,150 @@
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2007 Christian Grothoff (and other contributing authors)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19/**
20 * @file minimal_example_empty_ssl.c
21 * @brief minimal example for how to use libmicrohttpd
22 * @author Christian Grothoff
23 */
24
25#include "platform.h"
26#include <microhttpd.h>
27
28
29static int
30ahc_echo (void *cls,
31 struct MHD_Connection *connection,
32 const char *url,
33 const char *method,
34 const char *version,
35 const char *upload_data,
36 size_t *upload_data_size,
37 void **ptr)
38{
39 static int aptr;
40 struct MHD_Response *response;
41 int ret;
42
43 (void) url; /* Unused. Silent compiler warning. */
44 (void) version; /* Unused. Silent compiler warning. */
45 (void) upload_data; /* Unused. Silent compiler warning. */
46 (void) upload_data_size; /* Unused. Silent compiler warning. */
47
48 if (0 != strcmp (method, "GET"))
49 return MHD_NO; /* unexpected method */
50 if (&aptr != *ptr)
51 {
52 /* do never respond on first call */
53 *ptr = &aptr;
54 return MHD_YES;
55 }
56 *ptr = NULL; /* reset when done */
57 response = MHD_create_response_from_buffer (0,
58 NULL,
59 MHD_RESPMEM_PERSISTENT);
60 ret = MHD_queue_response (connection,
61 MHD_HTTP_NO_CONTENT,
62 response);
63 MHD_destroy_response (response);
64 return ret;
65}
66
67
68/* test server key */
69const char srv_signed_key_pem[] = "-----BEGIN RSA PRIVATE KEY-----\n"
70 "MIIEowIBAAKCAQEAvfTdv+3fgvVTKRnP/HVNG81cr8TrUP/iiyuve/THMzvFXhCW\n"
71 "+K03KwEku55QvnUndwBfU/ROzLlv+5hotgiDRNFT3HxurmhouySBrJNJv7qWp8IL\n"
72 "q4sw32vo0fbMu5BZF49bUXK9L3kW2PdhTtSQPWHEzNrCxO+YgCilKHkY3vQNfdJ0\n"
73 "20Q5EAAEseD1YtWCIpRvJzYlZMpjYB1ubTl24kwrgOKUJYKqM4jmF4DVQp4oOK/6\n"
74 "QYGGh1QmHRPAy3CBII6sbb+sZT9cAqU6GYQVB35lm4XAgibXV6KgmpVxVQQ69U6x\n"
75 "yoOl204xuekZOaG9RUPId74Rtmwfi1TLbBzo2wIDAQABAoIBADu09WSICNq5cMe4\n"
76 "+NKCLlgAT1NiQpLls1gKRbDhKiHU9j8QWNvWWkJWrCya4QdUfLCfeddCMeiQmv3K\n"
77 "lJMvDs+5OjJSHFoOsGiuW2Ias7IjnIojaJalfBml6frhJ84G27IXmdz6gzOiTIer\n"
78 "DjeAgcwBaKH5WwIay2TxIaScl7AwHBauQkrLcyb4hTmZuQh6ArVIN6+pzoVuORXM\n"
79 "bpeNWl2l/HSN3VtUN6aCAKbN/X3o0GavCCMn5Fa85uJFsab4ss/uP+2PusU71+zP\n"
80 "sBm6p/2IbGvF5k3VPDA7X5YX61sukRjRBihY8xSnNYx1UcoOsX6AiPnbhifD8+xQ\n"
81 "Tlf8oJUCgYEA0BTfzqNpr9Wxw5/QXaSdw7S/0eP5a0C/nwURvmfSzuTD4equzbEN\n"
82 "d+dI/s2JMxrdj/I4uoAfUXRGaabevQIjFzC9uyE3LaOyR2zhuvAzX+vVcs6bSXeU\n"
83 "pKpCAcN+3Z3evMaX2f+z/nfSUAl2i4J2R+/LQAWJW4KwRky/m+cxpfUCgYEA6bN1\n"
84 "b73bMgM8wpNt6+fcmS+5n0iZihygQ2U2DEud8nZJL4Nrm1dwTnfZfJBnkGj6+0Q0\n"
85 "cOwj2KS0/wcEdJBP0jucU4v60VMhp75AQeHqidIde0bTViSRo3HWKXHBIFGYoU3T\n"
86 "LyPyKndbqsOObnsFXHn56Nwhr2HLf6nw4taGQY8CgYBoSW36FLCNbd6QGvLFXBGt\n"
87 "2lMhEM8az/K58kJ4WXSwOLtr6MD/WjNT2tkcy0puEJLm6BFCd6A6pLn9jaKou/92\n"
88 "SfltZjJPb3GUlp9zn5tAAeSSi7YMViBrfuFiHObij5LorefBXISLjuYbMwL03MgH\n"
89 "Ocl2JtA2ywMp2KFXs8GQWQKBgFyIVv5ogQrbZ0pvj31xr9HjqK6d01VxIi+tOmpB\n"
90 "4ocnOLEcaxX12BzprW55ytfOCVpF1jHD/imAhb3YrHXu0fwe6DXYXfZV4SSG2vB7\n"
91 "IB9z14KBN5qLHjNGFpMQXHSMek+b/ftTU0ZnPh9uEM5D3YqRLVd7GcdUhHvG8P8Q\n"
92 "C9aXAoGBAJtID6h8wOGMP0XYX5YYnhlC7dOLfk8UYrzlp3xhqVkzKthTQTj6wx9R\n"
93 "GtC4k7U1ki8oJsfcIlBNXd768fqDVWjYju5rzShMpo8OCTS6ipAblKjCxPPVhIpv\n"
94 "tWPlbSn1qj6wylstJ5/3Z+ZW5H4wIKp5jmLiioDhcP0L/Ex3Zx8O\n"
95 "-----END RSA PRIVATE KEY-----\n";
96
97/* test server CA signed certificates */
98const char srv_signed_cert_pem[] = "-----BEGIN CERTIFICATE-----\n"
99 "MIIDGzCCAgWgAwIBAgIES0KCvTALBgkqhkiG9w0BAQUwFzEVMBMGA1UEAxMMdGVz\n"
100 "dF9jYV9jZXJ0MB4XDTEwMDEwNTAwMDcyNVoXD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OChPLnA3Q==\n"
116 "-----END CERTIFICATE-----\n";
117
118
119int
120main (int argc,
121 char *const *argv)
122{
123 struct MHD_Daemon *d;
124
125 if (argc != 2)
126 {
127 printf ("%s PORT\n", argv[0]);
128 return 1;
129 }
130 d = MHD_start_daemon (/* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */
131 MHD_USE_AUTO | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG
132 | MHD_USE_TLS,
133 /* MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */
134 /* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | MHD_USE_POLL, */
135 /* MHD_USE_THREAD_PER_CONNECTION | MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG, */
136 atoi (argv[1]),
137 NULL, NULL, &ahc_echo, NULL,
138 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120,
139 MHD_OPTION_STRICT_FOR_CLIENT, (int) 1,
140 /* Optionally, the gnutls_load_file() can be used to
141 load the key and the certificate from file. */
142 MHD_OPTION_HTTPS_MEM_KEY, srv_signed_key_pem,
143 MHD_OPTION_HTTPS_MEM_CERT, srv_signed_cert_pem,
144 MHD_OPTION_END);
145 if (d == NULL)
146 return 1;
147 (void) getc (stdin);
148 MHD_stop_daemon (d);
149 return 0;
150}