aboutsummaryrefslogtreecommitdiff
path: root/doc/examples/tlsauthentication.c
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples/tlsauthentication.c')
-rw-r--r--doc/examples/tlsauthentication.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/doc/examples/tlsauthentication.c b/doc/examples/tlsauthentication.c
index 437d795a..efbc6e06 100644
--- a/doc/examples/tlsauthentication.c
+++ b/doc/examples/tlsauthentication.c
@@ -33,24 +33,30 @@ get_file_size (const char *filename)
33 return 0; 33 return 0;
34} 34}
35 35
36char* 36char *
37load_file (const char* filename) 37load_file (const char *filename)
38{ 38{
39 FILE *fp; 39 FILE *fp;
40 char *buffer; 40 char *buffer;
41 long size; 41 long size;
42 42
43 size = get_file_size (filename); 43 size = get_file_size (filename);
44 if (size == 0) return NULL; 44 if (size == 0)
45 return NULL;
45 46
46 fp = fopen (filename, "rb"); 47 fp = fopen (filename, "rb");
47 if (!fp) return NULL; 48 if (!fp)
49 return NULL;
48 50
49 buffer = malloc (size); 51 buffer = malloc (size);
50 if (!buffer) {fclose (fp); return NULL;} 52 if (!buffer)
53 {
54 fclose (fp);
55 return NULL;
56 }
51 57
52 if (size != fread (buffer, 1, size, fp)) 58 if (size != fread (buffer, 1, size, fp))
53 { 59 {
54 free (buffer); 60 free (buffer);
55 buffer = NULL; 61 buffer = NULL;
56 } 62 }
@@ -184,22 +190,23 @@ main ()
184 cert_pem = load_file (SERVERCERTFILE); 190 cert_pem = load_file (SERVERCERTFILE);
185 191
186 if ((key_pem == NULL) || (cert_pem == NULL)) 192 if ((key_pem == NULL) || (cert_pem == NULL))
187 { 193 {
188 printf ("The key/certificate files could not be read.\n"); 194 printf ("The key/certificate files could not be read.\n");
189 return 1; 195 return 1;
190 } 196 }
191 197
192 daemon = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_SSL, PORT, NULL, NULL, 198 daemon =
193 &answer_to_connection, NULL, 199 MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_SSL, PORT, NULL,
194 MHD_OPTION_HTTPS_MEM_KEY, key_pem, MHD_OPTION_HTTPS_MEM_CERT, cert_pem, 200 NULL, &answer_to_connection, NULL,
195 MHD_OPTION_END); 201 MHD_OPTION_HTTPS_MEM_KEY, key_pem,
202 MHD_OPTION_HTTPS_MEM_CERT, cert_pem, MHD_OPTION_END);
196 if (NULL == daemon) 203 if (NULL == daemon)
197 { 204 {
198 printf ("%s\n", cert_pem); 205 printf ("%s\n", cert_pem);
199 206
200 free (key_pem); 207 free (key_pem);
201 free (cert_pem); 208 free (cert_pem);
202 209
203 return 1; 210 return 1;
204 } 211 }
205 212
@@ -208,7 +215,7 @@ main ()
208 MHD_stop_daemon (daemon); 215 MHD_stop_daemon (daemon);
209 free (key_pem); 216 free (key_pem);
210 free (cert_pem); 217 free (cert_pem);
211 218
212 return 0; 219 return 0;
213} 220}
214 221
@@ -250,4 +257,3 @@ string_to_base64 (const char *message)
250 257
251 return tmp; 258 return tmp;
252} 259}
253