4904e455cecf251733a506a6e2ffbfa3fc9c77c7
[platform/upstream/libwebsockets.git] / test-server / test-server-http.c
1 /*
2  * libwebsockets-test-server - libwebsockets test implementation
3  *
4  * Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
5  *
6  * This file is made available under the Creative Commons CC0 1.0
7  * Universal Public Domain Dedication.
8  *
9  * The person who associated a work with this deed has dedicated
10  * the work to the public domain by waiving all of his or her rights
11  * to the work worldwide under copyright law, including all related
12  * and neighboring rights, to the extent allowed by law. You can copy,
13  * modify, distribute and perform the work, even for commercial purposes,
14  * all without asking permission.
15  *
16  * The test apps are intended to be adapted for use in your code, which
17  * may be proprietary.  So unlike the library itself, they are licensed
18  * Public Domain.
19  */
20 #include "test-server.h"
21
22 /*
23  * This demo server shows how to use libwebsockets for one or more
24  * websocket protocols in the same server
25  *
26  * It defines the following websocket protocols:
27  *
28  *  dumb-increment-protocol:  once the socket is opened, an incrementing
29  *                              ascii string is sent down it every 50ms.
30  *                              If you send "reset\n" on the websocket, then
31  *                              the incrementing number is reset to 0.
32  *
33  *  lws-mirror-protocol: copies any received packet to every connection also
34  *                              using this protocol, including the sender
35  */
36
37 #if defined(LWS_USE_POLARSSL)
38 #else
39 #if defined(LWS_USE_MBEDTLS)
40 #else
41 #if defined(LWS_OPENSSL_SUPPORT) && defined(LWS_HAVE_SSL_CTX_set1_param)
42 /* location of the certificate revocation list */
43 extern char crl_path[1024];
44 #endif
45 #endif
46 #endif
47
48 extern int debug_level;
49
50 enum demo_protocols {
51         /* always first */
52         PROTOCOL_HTTP = 0,
53
54         PROTOCOL_DUMB_INCREMENT,
55         PROTOCOL_LWS_MIRROR,
56
57         /* always last */
58         DEMO_PROTOCOL_COUNT
59 };
60
61 /*
62  * We take a strict whitelist approach to stop ../ attacks
63  */
64 struct serveable {
65         const char *urlpath;
66         const char *mimetype;
67 };
68
69 /*
70  * this is just an example of parsing handshake headers, you don't need this
71  * in your code unless you will filter allowing connections by the header
72  * content
73  */
74 void
75 dump_handshake_info(struct lws *wsi)
76 {
77         int n = 0, len;
78         char buf[256];
79         const unsigned char *c;
80
81         do {
82                 c = lws_token_to_string(n);
83                 if (!c) {
84                         n++;
85                         continue;
86                 }
87
88                 len = lws_hdr_total_length(wsi, n);
89                 if (!len || len > sizeof(buf) - 1) {
90                         n++;
91                         continue;
92                 }
93
94                 lws_hdr_copy(wsi, buf, sizeof buf, n);
95                 buf[sizeof(buf) - 1] = '\0';
96
97                 fprintf(stderr, "    %s = %s\n", (char *)c, buf);
98                 n++;
99         } while (c);
100 }
101
102 const char * get_mimetype(const char *file)
103 {
104         int n = strlen(file);
105
106         if (n < 5)
107                 return NULL;
108
109         if (!strcmp(&file[n - 4], ".ico"))
110                 return "image/x-icon";
111
112         if (!strcmp(&file[n - 4], ".png"))
113                 return "image/png";
114
115         if (!strcmp(&file[n - 5], ".html"))
116                 return "text/html";
117
118         if (!strcmp(&file[n - 4], ".css"))
119                 return "text/css";
120
121         return NULL;
122 }
123
124 /* this protocol server (always the first one) handles HTTP,
125  *
126  * Some misc callbacks that aren't associated with a protocol also turn up only
127  * here on the first protocol server.
128  */
129
130 int callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
131                   void *in, size_t len)
132 {
133         struct per_session_data__http *pss =
134                         (struct per_session_data__http *)user;
135         unsigned char buffer[4096 + LWS_PRE];
136         unsigned long amount, file_len, sent;
137         char leaf_path[1024];
138         const char *mimetype;
139         char *other_headers;
140         unsigned char *end;
141         struct timeval tv;
142         unsigned char *p;
143 #ifndef LWS_NO_CLIENT
144         struct per_session_data__http *pss1;
145         struct lws *wsi1;
146 #endif
147         char buf[256];
148         char b64[64];
149         int n, m;
150 #ifdef EXTERNAL_POLL
151         struct lws_pollargs *pa = (struct lws_pollargs *)in;
152 #endif
153
154
155         switch (reason) {
156         case LWS_CALLBACK_HTTP:
157
158                 lwsl_notice("lws_http_serve: %s\n",in);
159
160                 if (debug_level & LLL_INFO) {
161                         dump_handshake_info(wsi);
162
163                         /* dump the individual URI Arg parameters */
164                         n = 0;
165                         while (lws_hdr_copy_fragment(wsi, buf, sizeof(buf),
166                                                      WSI_TOKEN_HTTP_URI_ARGS, n) > 0) {
167                                 lwsl_notice("URI Arg %d: %s\n", ++n, buf);
168                         }
169                 }
170
171                 {
172                         char name[100], rip[50];
173                         lws_get_peer_addresses(wsi, lws_get_socket_fd(wsi), name,
174                                                sizeof(name), rip, sizeof(rip));
175                         sprintf(buf, "%s (%s)", name, rip);
176                         lwsl_notice("HTTP connect from %s\n", buf);
177                 }
178
179                 if (len < 1) {
180                         lws_return_http_status(wsi,
181                                                 HTTP_STATUS_BAD_REQUEST, NULL);
182                         goto try_to_reuse;
183                 }
184
185 #ifndef LWS_NO_CLIENT
186                 if (!strncmp(in, "/proxytest", 10)) {
187                         struct lws_client_connect_info i;
188                         char *rootpath = "/";
189                         const char *p = (const char *)in;
190
191                         if (lws_get_child(wsi))
192                                 break;
193
194                         pss->client_finished = 0;
195                         memset(&i,0, sizeof(i));
196                         i.context = lws_get_context(wsi);
197                         i.address = "git.libwebsockets.org";
198                         i.port = 80;
199                         i.ssl_connection = 0;
200                         if (p[10])
201                                 i.path = (char *)in + 10;
202                         else
203                                 i.path = rootpath;
204                         i.host = "git.libwebsockets.org";
205                         i.origin = NULL;
206                         i.method = "GET";
207                         i.parent_wsi = wsi;
208                         i.uri_replace_from = "git.libwebsockets.org/";
209                         i.uri_replace_to = "/proxytest/";
210                         if (!lws_client_connect_via_info(&i)) {
211                                 lwsl_err("proxy connect fail\n");
212                                 break;
213                         }
214
215
216
217                         break;
218                 }
219 #endif
220
221 #if 1
222                 /* this example server has no concept of directories */
223                 if (strchr((const char *)in + 1, '/')) {
224                         lws_return_http_status(wsi, HTTP_STATUS_NOT_ACCEPTABLE, NULL);
225                         goto try_to_reuse;
226                 }
227 #endif
228
229                 /* if a legal POST URL, let it continue and accept data */
230                 if (lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI))
231                         return 0;
232
233                 /* check for the "send a big file by hand" example case */
234
235                 if (!strcmp((const char *)in, "/leaf.jpg")) {
236                         if (strlen(resource_path) > sizeof(leaf_path) - 10)
237                                 return -1;
238                         sprintf(leaf_path, "%s/leaf.jpg", resource_path);
239
240                         /* well, let's demonstrate how to send the hard way */
241
242                         p = buffer + LWS_PRE;
243                         end = p + sizeof(buffer) - LWS_PRE;
244
245                         pss->fd = lws_plat_file_open(wsi, leaf_path, &file_len,
246                                                      LWS_O_RDONLY);
247
248                         if (pss->fd == LWS_INVALID_FILE) {
249                                 lwsl_err("faild to open file %s\n", leaf_path);
250                                 return -1;
251                         }
252
253                         /*
254                          * we will send a big jpeg file, but it could be
255                          * anything.  Set the Content-Type: appropriately
256                          * so the browser knows what to do with it.
257                          *
258                          * Notice we use the APIs to build the header, which
259                          * will do the right thing for HTTP 1/1.1 and HTTP2
260                          * depending on what connection it happens to be working
261                          * on
262                          */
263                         if (lws_add_http_header_status(wsi, 200, &p, end))
264                                 return 1;
265                         if (lws_add_http_header_by_token(wsi, WSI_TOKEN_HTTP_SERVER,
266                                         (unsigned char *)"libwebsockets",
267                                         13, &p, end))
268                                 return 1;
269                         if (lws_add_http_header_by_token(wsi,
270                                         WSI_TOKEN_HTTP_CONTENT_TYPE,
271                                         (unsigned char *)"image/jpeg",
272                                         10, &p, end))
273                                 return 1;
274                         if (lws_add_http_header_content_length(wsi,
275                                                                file_len, &p,
276                                                                end))
277                                 return 1;
278                         if (lws_finalize_http_header(wsi, &p, end))
279                                 return 1;
280
281                         /*
282                          * send the http headers...
283                          * this won't block since it's the first payload sent
284                          * on the connection since it was established
285                          * (too small for partial)
286                          *
287                          * Notice they are sent using LWS_WRITE_HTTP_HEADERS
288                          * which also means you can't send body too in one step,
289                          * this is mandated by changes in HTTP2
290                          */
291
292                         *p = '\0';
293                         lwsl_info("%s\n", buffer + LWS_PRE);
294
295                         n = lws_write(wsi, buffer + LWS_PRE,
296                                       p - (buffer + LWS_PRE),
297                                       LWS_WRITE_HTTP_HEADERS);
298                         if (n < 0) {
299                                 lws_plat_file_close(wsi, pss->fd);
300                                 return -1;
301                         }
302                         /*
303                          * book us a LWS_CALLBACK_HTTP_WRITEABLE callback
304                          */
305                         lws_callback_on_writable(wsi);
306                         break;
307                 }
308
309                 /* if not, send a file the easy way */
310                 if (!strncmp(in, "/cgit-data/", 11)) {
311                         in = (char *)in + 11;
312                         strcpy(buf, "/usr/share/cgit");
313                 } else
314                         strcpy(buf, resource_path);
315
316                 if (strcmp(in, "/")) {
317                         if (*((const char *)in) != '/')
318                                 strcat(buf, "/");
319                         strncat(buf, in, sizeof(buf) - strlen(buf) - 1);
320                 } else /* default file to serve */
321                         strcat(buf, "/test.html");
322                 buf[sizeof(buf) - 1] = '\0';
323
324                 /* refuse to serve files we don't understand */
325                 mimetype = get_mimetype(buf);
326                 if (!mimetype) {
327                         lwsl_err("Unknown mimetype for %s\n", buf);
328                         lws_return_http_status(wsi,
329                                       HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE, NULL);
330                         return -1;
331                 }
332
333                 /* demonstrates how to set a cookie on / */
334
335                 other_headers = leaf_path;
336                 p = (unsigned char *)leaf_path;
337                 if (!strcmp((const char *)in, "/") &&
338                            !lws_hdr_total_length(wsi, WSI_TOKEN_HTTP_COOKIE)) {
339                         /* this isn't very unguessable but it'll do for us */
340                         gettimeofday(&tv, NULL);
341                         n = sprintf(b64, "test=LWS_%u_%u_COOKIE;Max-Age=360000",
342                                 (unsigned int)tv.tv_sec,
343                                 (unsigned int)tv.tv_usec);
344
345                         if (lws_add_http_header_by_name(wsi,
346                                 (unsigned char *)"set-cookie:",
347                                 (unsigned char *)b64, n, &p,
348                                 (unsigned char *)leaf_path + sizeof(leaf_path)))
349                                 return 1;
350                 }
351                 if (lws_is_ssl(wsi) && lws_add_http_header_by_name(wsi,
352                                                 (unsigned char *)
353                                                 "Strict-Transport-Security:",
354                                                 (unsigned char *)
355                                                 "max-age=15768000 ; "
356                                                 "includeSubDomains", 36, &p,
357                                                 (unsigned char *)leaf_path +
358                                                         sizeof(leaf_path)))
359                         return 1;
360                 n = (char *)p - leaf_path;
361
362                 n = lws_serve_http_file(wsi, buf, mimetype, other_headers, n);
363                 if (n < 0 || ((n > 0) && lws_http_transaction_completed(wsi)))
364                         return -1; /* error or can't reuse connection: close the socket */
365
366                 /*
367                  * notice that the sending of the file completes asynchronously,
368                  * we'll get a LWS_CALLBACK_HTTP_FILE_COMPLETION callback when
369                  * it's done
370                  */
371                 break;
372
373         case LWS_CALLBACK_HTTP_BODY:
374                 strncpy(buf, in, 20);
375                 buf[20] = '\0';
376                 if (len < 20)
377                         buf[len] = '\0';
378
379                 lwsl_notice("LWS_CALLBACK_HTTP_BODY: %s... len %d\n",
380                                 (const char *)buf, (int)len);
381
382                 break;
383
384         case LWS_CALLBACK_HTTP_BODY_COMPLETION:
385                 lwsl_notice("LWS_CALLBACK_HTTP_BODY_COMPLETION\n");
386                 /* the whole of the sent body arrived, close or reuse the connection */
387                 lws_return_http_status(wsi, HTTP_STATUS_OK, NULL);
388                 goto try_to_reuse;
389
390         case LWS_CALLBACK_HTTP_FILE_COMPLETION:
391                 goto try_to_reuse;
392
393         case LWS_CALLBACK_HTTP_WRITEABLE:
394                 lwsl_info("LWS_CALLBACK_HTTP_WRITEABLE\n");
395
396                 if (pss->client_finished)
397                         return -1;
398
399                 if (pss->fd == LWS_INVALID_FILE)
400                         goto try_to_reuse;
401
402 #ifndef LWS_NO_CLIENT
403                 if (pss->reason_bf & 2) {
404                         char *px = buf + LWS_PRE;
405                         int lenx = sizeof(buf) - LWS_PRE;
406                         /*
407                          * our sink is writeable and our source has something
408                          * to read.  So read a lump of source material of
409                          * suitable size to send or what's available, whichever
410                          * is the smaller.
411                          */
412                         pss->reason_bf &= ~2;
413                         wsi1 = lws_get_child(wsi);
414                         if (!wsi1)
415                                 break;
416                         if (lws_http_client_read(wsi1, &px, &lenx) < 0)
417                                 goto bail;
418
419                         if (pss->client_finished)
420                                 return -1;
421                         break;
422                 }
423 #endif
424                 /*
425                  * we can send more of whatever it is we were sending
426                  */
427                 sent = 0;
428                 do {
429                         /* we'd like the send this much */
430                         n = sizeof(buffer) - LWS_PRE;
431
432                         /* but if the peer told us he wants less, we can adapt */
433                         m = lws_get_peer_write_allowance(wsi);
434
435                         /* -1 means not using a protocol that has this info */
436                         if (m == 0)
437                                 /* right now, peer can't handle anything */
438                                 goto later;
439
440                         if (m != -1 && m < n)
441                                 /* he couldn't handle that much */
442                                 n = m;
443
444                         n = lws_plat_file_read(wsi, pss->fd,
445                                                &amount, buffer + LWS_PRE, n);
446                         /* problem reading, close conn */
447                         if (n < 0) {
448                                 lwsl_err("problem reading file\n");
449                                 goto bail;
450                         }
451                         n = (int)amount;
452                         /* sent it all, close conn */
453                         if (n == 0)
454                                 goto penultimate;
455                         /*
456                          * To support HTTP2, must take care about preamble space
457                          *
458                          * identification of when we send the last payload frame
459                          * is handled by the library itself if you sent a
460                          * content-length header
461                          */
462                         m = lws_write(wsi, buffer + LWS_PRE, n, LWS_WRITE_HTTP);
463                         if (m < 0) {
464                                 lwsl_err("write failed\n");
465                                 /* write failed, close conn */
466                                 goto bail;
467                         }
468                         if (m) /* while still active, extend timeout */
469                                 lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT, 5);
470                         sent += m;
471
472                 } while (!lws_send_pipe_choked(wsi) && (sent < 1024 * 1024));
473 later:
474                 lws_callback_on_writable(wsi);
475                 break;
476 penultimate:
477                 lws_plat_file_close(wsi, pss->fd);
478                 pss->fd = LWS_INVALID_FILE;
479                 goto try_to_reuse;
480
481 bail:
482                 lws_plat_file_close(wsi, pss->fd);
483
484                 return -1;
485
486         /*
487          * callback for confirming to continue with client IP appear in
488          * protocol 0 callback since no websocket protocol has been agreed
489          * yet.  You can just ignore this if you won't filter on client IP
490          * since the default unhandled callback return is 0 meaning let the
491          * connection continue.
492          */
493         case LWS_CALLBACK_FILTER_NETWORK_CONNECTION:
494                 /* if we returned non-zero from here, we kill the connection */
495                 break;
496
497 #ifndef LWS_NO_CLIENT
498         case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: {
499                 char ctype[64], ctlen = 0;
500                 lwsl_err("LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP\n");
501                 p = buffer + LWS_PRE;
502                 end = p + sizeof(buffer) - LWS_PRE;
503                 if (lws_add_http_header_status(lws_get_parent(wsi), 200, &p, end))
504                         return 1;
505                 if (lws_add_http_header_by_token(lws_get_parent(wsi),
506                                 WSI_TOKEN_HTTP_SERVER,
507                                 (unsigned char *)"libwebsockets",
508                                 13, &p, end))
509                         return 1;
510
511                 ctlen = lws_hdr_copy(wsi, ctype, sizeof(ctype), WSI_TOKEN_HTTP_CONTENT_TYPE);
512                 if (ctlen > 0) {
513                         if (lws_add_http_header_by_token(lws_get_parent(wsi),
514                                 WSI_TOKEN_HTTP_CONTENT_TYPE,
515                                 (unsigned char *)ctype, ctlen, &p, end))
516                                 return 1;
517                 }
518 #if 0
519                 if (lws_add_http_header_content_length(lws_get_parent(wsi),
520                                                        file_len, &p, end))
521                         return 1;
522 #endif
523                 if (lws_finalize_http_header(lws_get_parent(wsi), &p, end))
524                         return 1;
525
526                 *p = '\0';
527                 lwsl_info("%s\n", buffer + LWS_PRE);
528
529                 n = lws_write(lws_get_parent(wsi), buffer + LWS_PRE,
530                               p - (buffer + LWS_PRE),
531                               LWS_WRITE_HTTP_HEADERS);
532                 if (n < 0)
533                         return -1;
534
535                 break; }
536         case LWS_CALLBACK_CLOSED_CLIENT_HTTP:
537                 //lwsl_err("LWS_CALLBACK_CLOSED_CLIENT_HTTP\n");
538                 return -1;
539                 break;
540         case LWS_CALLBACK_RECEIVE_CLIENT_HTTP:
541                 //lwsl_err("LWS_CALLBACK_RECEIVE_CLIENT_HTTP: wsi %p\n", wsi);
542                 assert(lws_get_parent(wsi));
543                 if (!lws_get_parent(wsi))
544                         break;
545                 // lwsl_err("LWS_CALLBACK_RECEIVE_CLIENT_HTTP: wsi %p: sock: %d, parent_wsi: %p, parent_sock:%d,  len %d\n",
546                 //              wsi, lws_get_socket_fd(wsi),
547                 //              lws_get_parent(wsi),
548                 //              lws_get_socket_fd(lws_get_parent(wsi)), len);
549                 pss1 = lws_wsi_user(lws_get_parent(wsi));
550                 pss1->reason_bf |= 2;
551                 lws_callback_on_writable(lws_get_parent(wsi));
552                 break;
553         case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ:
554                 //lwsl_err("LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ len %d\n", len);
555                 assert(lws_get_parent(wsi));
556                 m = lws_write(lws_get_parent(wsi), (unsigned char *)in,
557                                 len, LWS_WRITE_HTTP);
558                 if (m < 0)
559                         return -1;
560                 break;
561         case LWS_CALLBACK_COMPLETED_CLIENT_HTTP:
562                 //lwsl_err("LWS_CALLBACK_COMPLETED_CLIENT_HTTP\n");
563                 assert(lws_get_parent(wsi));
564                 if (!lws_get_parent(wsi))
565                         break;
566                 pss1 = lws_wsi_user(lws_get_parent(wsi));
567                 pss1->client_finished = 1;
568                 break;
569 #endif
570
571         /*
572          * callbacks for managing the external poll() array appear in
573          * protocol 0 callback
574          */
575
576         case LWS_CALLBACK_LOCK_POLL:
577                 /*
578                  * lock mutex to protect pollfd state
579                  * called before any other POLL related callback
580                  * if protecting wsi lifecycle change, len == 1
581                  */
582                 test_server_lock(len);
583                 break;
584
585         case LWS_CALLBACK_UNLOCK_POLL:
586                 /*
587                  * unlock mutex to protect pollfd state when
588                  * called after any other POLL related callback
589                  * if protecting wsi lifecycle change, len == 1
590                  */
591                 test_server_unlock(len);
592                 break;
593
594 #ifdef EXTERNAL_POLL
595         case LWS_CALLBACK_ADD_POLL_FD:
596
597                 if (count_pollfds >= max_poll_elements) {
598                         lwsl_err("LWS_CALLBACK_ADD_POLL_FD: too many sockets to track\n");
599                         return 1;
600                 }
601
602                 fd_lookup[pa->fd] = count_pollfds;
603                 pollfds[count_pollfds].fd = pa->fd;
604                 pollfds[count_pollfds].events = pa->events;
605                 pollfds[count_pollfds++].revents = 0;
606                 break;
607
608         case LWS_CALLBACK_DEL_POLL_FD:
609                 if (!--count_pollfds)
610                         break;
611                 m = fd_lookup[pa->fd];
612                 /* have the last guy take up the vacant slot */
613                 pollfds[m] = pollfds[count_pollfds];
614                 fd_lookup[pollfds[count_pollfds].fd] = m;
615                 break;
616
617         case LWS_CALLBACK_CHANGE_MODE_POLL_FD:
618                 pollfds[fd_lookup[pa->fd]].events = pa->events;
619                 break;
620 #endif
621
622         case LWS_CALLBACK_GET_THREAD_ID:
623                 /*
624                  * if you will call "lws_callback_on_writable"
625                  * from a different thread, return the caller thread ID
626                  * here so lws can use this information to work out if it
627                  * should signal the poll() loop to exit and restart early
628                  */
629
630                 /* return pthread_getthreadid_np(); */
631
632                 break;
633
634 #if defined(LWS_USE_POLARSSL)
635 #else
636 #if defined(LWS_USE_MBEDTLS)
637 #else
638 #if defined(LWS_OPENSSL_SUPPORT)
639         case LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION:
640                 /* Verify the client certificate */
641                 if (!len || (SSL_get_verify_result((SSL*)in) != X509_V_OK)) {
642                         int err = X509_STORE_CTX_get_error((X509_STORE_CTX*)user);
643                         int depth = X509_STORE_CTX_get_error_depth((X509_STORE_CTX*)user);
644                         const char* msg = X509_verify_cert_error_string(err);
645                         lwsl_err("LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION: SSL error: %s (%d), depth: %d\n", msg, err, depth);
646                         return 1;
647                 }
648                 break;
649 #if defined(LWS_HAVE_SSL_CTX_set1_param)
650         case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS:
651                 if (crl_path[0]) {
652                         /* Enable CRL checking */
653                         X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_new();
654                         X509_VERIFY_PARAM_set_flags(param, X509_V_FLAG_CRL_CHECK);
655                         SSL_CTX_set1_param((SSL_CTX*)user, param);
656                         X509_STORE *store = SSL_CTX_get_cert_store((SSL_CTX*)user);
657                         X509_LOOKUP *lookup = X509_STORE_add_lookup(store, X509_LOOKUP_file());
658                         n = X509_load_cert_crl_file(lookup, crl_path, X509_FILETYPE_PEM);
659                         X509_VERIFY_PARAM_free(param);
660                         if (n != 1) {
661                                 char errbuf[256];
662                                 n = ERR_get_error();
663                                 lwsl_err("LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS: SSL error: %s (%d)\n", ERR_error_string(n, errbuf), n);
664                                 return 1;
665                         }
666                 }
667                 break;
668 #endif
669 #endif
670 #endif
671 #endif
672
673         default:
674                 break;
675         }
676
677         return 0;
678
679         /* if we're on HTTP1.1 or 2.0, will keep the idle connection alive */
680 try_to_reuse:
681         if (lws_http_transaction_completed(wsi))
682                 return -1;
683
684         return 0;
685 }