src/server/daemon/httplistener.c

Sun, 27 Nov 2022 13:33:30 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 27 Nov 2022 13:33:30 +0100
changeset 443
ef3c8a0e1fee
parent 441
797aeb31a2c6
child 444
96d2ba2f28db
permissions
-rw-r--r--

improve daemon startup
parent will wait until daemon is started and returns error code if startup failed
daemon startup log messages will be printed by parent

1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
44
3da1f7b6847f added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 41
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
14
b8bf95b39952 New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 9
diff changeset
29 #include "../public/nsapi.h"
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <stdio.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <stdlib.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <fcntl.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include <sys/shm.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include <sys/types.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include <sys/ipc.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include <sys/socket.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include <sys/file.h>
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
39 #include <arpa/inet.h>
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 #include <netinet/in.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 #include <netdb.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 #include <stdio.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 #include <stdlib.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 #include <fcntl.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 #include <unistd.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 #include <strings.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 #include <stdbool.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 #include <pthread.h>
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
50 #include <arpa/inet.h>
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
51 #include <netinet/in.h>
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
52 #include <stdio.h>
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
53 #include <stdlib.h>
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
54 #include <sys/socket.h>
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
55 #include <unistd.h>
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
56
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 398
diff changeset
57
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 398
diff changeset
58 #include <cx/hash_map.h>
92
382bff43c6eb fixed some includes
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 87
diff changeset
59
41
bb7a1f5a8b48 added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
60 #include "../util/atomic.h"
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 #include "httplistener.h"
171
af7e2d80dee6 adds wrapper for close syscall with error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
62 #include "netsite.h"
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 #include "session.h"
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
65 #include "configmanager.h"
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
66 #include "log.h"
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 398
diff changeset
68 #define LISTENER_MAX_PROTOCOL_TOKENS 1024
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 398
diff changeset
69
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
70
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
71 #define LISTENER_PROTO_IPV4 "ipv4"
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
72 #define LISTENER_PROTO_IPV6 "ipv6"
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
73
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
74
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
75 /*
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
76 * key: string format: <protocol>:<port>
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
77 * value: WSSocket*
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
78 *
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
79 * protocol: ipv4 | ipv6
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
80 * port: short
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
81 */
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
82 static CxMap *listener_socket_map;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
83
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
84 static pthread_mutex_t listener_mutex;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
85
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
86
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
87 int http_listener_global_init(void) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
88 listener_socket_map = cxHashMapCreate(cxDefaultAllocator, 4);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
89 if(!listener_socket_map) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
90 return 1;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
91 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
92
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
93 listener_mutex = PTHREAD_MUTEX_INITIALIZER;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
94
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
95 return 0;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
96 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 int start_all_listener() {
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
99 ServerConfiguration *conf = cfgmgr_get_server_config();
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 398
diff changeset
100 CxList *ls = conf->listeners;
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 398
diff changeset
101 CxIterator iter = cxListIterator(ls, 0);
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 398
diff changeset
102 cx_foreach(HttpListener *, listener, iter) {
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
103 http_listener_start(listener);
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
104 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 return 0;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
109 static HttpSSL* create_http_ssl(ListenerConfig *conf) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
110 SSL_CTX *ctx = SSL_CTX_new(SSLv23_server_method());
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
111 if(!ctx) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
112 return NULL;
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
113 }
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
114 SSL_CTX_set_options(
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
115 ctx,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
116 SSL_OP_SINGLE_DH_USE | SSL_OP_NO_SSLv3);
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
117
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
118 int error = 0;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
119 if(conf->disable_proto.ptr) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
120 cxstring *plist = NULL;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
121 ssize_t n = cx_strsplit_a(cxDefaultAllocator, conf->disable_proto, cx_str(","), LISTENER_MAX_PROTOCOL_TOKENS, &plist);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
122 if(plist) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
123 for(int i=0;i<n;i++) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
124 cxstring proto = plist[i];
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
125 log_ereport(
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
126 LOG_VERBOSE,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
127 "Listener %s: Disable protocol %s",
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
128 conf->name.ptr,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
129 proto.ptr);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
130 if(!cx_strcasecmp(cx_strtrim(proto), cx_str("SSLv2"))) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
131 SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
132 } else if(!cx_strcasecmp(cx_strtrim(proto), cx_str("SSLv3"))) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
133 SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv3);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
134 } else if(!cx_strcasecmp(cx_strtrim(proto), cx_str("TLSv1"))) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
135 SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
136 } else if(!cx_strcasecmp(cx_strtrim(proto), cx_str("TLSv1.1"))) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
137 #ifdef SSL_OP_NO_TLSv1_1
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
138 SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_1);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
139 #else
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
140 log_ereport(
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
141 LOG_WARN,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
142 "Listener: %s: TLSv1.1 not supported",
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
143 conf->name.ptr);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
144 #endif
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
145 } else if(cx_strcasecmp(cx_strtrim(proto), cx_str("TLSv1.2"))) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
146 #ifdef SSL_OP_NO_TLSv1_2
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
147 SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_2);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
148 #else
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
149 log_ereport(
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
150 LOG_WARN,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
151 "Listener: %s: TLSv1.2 not supported",
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
152 conf->name.ptr);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
153 #endif
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
154 } else if(cx_strcasecmp(cx_strtrim(proto), cx_str("TLSv1.3"))) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
155 #ifdef SSL_OP_NO_TLSv1_3
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
156 SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_3);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
157 #else
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
158 log_ereport(
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
159 LOG_WARN,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
160 "Listener: %s: TLSv1.3 not supported",
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
161 conf->name.ptr);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
162 #endif
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
163 } else {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
164 error = 1;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
165 log_ereport(
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
166 LOG_MISCONFIG,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
167 "Listener: %s: Unknown protocol %s",
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
168 conf->name.ptr,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
169 proto.ptr);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
170 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
171 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
172 free(plist);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
173 }
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
174 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
175
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
176 if(error) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
177 SSL_CTX_free(ctx);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
178 return NULL;
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
179 }
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
180
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
181 int ret;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
182 char errbuf[512];
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
183
441
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
184 // get TLS cert
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
185 error = 0;
441
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
186 if(conf->chainfile.ptr) {
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
187 ret = SSL_CTX_use_certificate_chain_file(ctx, conf->chainfile.ptr);
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
188 if(!ret) {
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
189 ERR_error_string(ERR_get_error(), errbuf);
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
190 log_ereport(LOG_MISCONFIG, "Cannot load ssl cert file: %s", errbuf);
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
191 error = 1;
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
192 }
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
193 } else if(conf->certfile.ptr) {
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
194 ret = SSL_CTX_use_certificate_file(ctx, conf->certfile.ptr, SSL_FILETYPE_PEM);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
195 if(!ret) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
196 ERR_error_string(ERR_get_error(), errbuf);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
197 log_ereport(LOG_MISCONFIG, "Cannot load ssl chain file: %s", errbuf);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
198 error = 1;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
199 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
200 } else {
441
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
201 log_ereport(LOG_MISCONFIG, "Listener %s: no CertChain/Cert specified", conf->name.ptr);
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
202 error = 1;
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
203 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
204
441
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
205 // get private key
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
206 ret = SSL_CTX_use_PrivateKey_file(ctx, conf->privkeyfile.ptr, SSL_FILETYPE_PEM);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
207 if(!ret) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
208 ERR_error_string(ERR_get_error(), errbuf);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
209 log_ereport(LOG_MISCONFIG, "Cannot load ssl key file: %s", errbuf);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
210 error = 1;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
211 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
212
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
213 if(error) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
214 SSL_CTX_free(ctx);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
215 return NULL;
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
216 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
217
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
218 HttpSSL *ssl = pool_malloc(conf->cfg->pool, sizeof(HttpSSL));
441
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
219 if(!ssl) {
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
220 SSL_CTX_free(ctx);
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
221 return NULL;
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
222 }
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
223 ZERO(ssl, sizeof(HttpSSL));
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
224 ssl->sslctx = ctx;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
225
441
797aeb31a2c6 fix listener ssl initialization
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 440
diff changeset
226 return ssl;
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
227 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
228
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
229 static WSSocket* create_socket(ListenerConfig *conf, const char *protocol) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
230 WSBool ipv4 = !strcmp(protocol, "ipv4") ? TRUE : FALSE;
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
231
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
232 int s = -1;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
233 if(ipv4) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
234 // ipv4 socket
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
235 s = socket(AF_INET, SOCK_STREAM, 0);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
236 } else {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
237 // ipv6 socket
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
238 s = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
239 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
240 if(s < 0) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
241 log_ereport(
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
242 LOG_FAILURE,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
243 "cannot create socket: protocol: %s port: %d error: %s",
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
244 protocol,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
245 conf->port,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
246 strerror(errno));
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
247 return NULL;
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
248 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
249
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
250 // socket options
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
251 int o = 1;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
252 setsockopt(
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
253 s,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
254 SOL_SOCKET, SO_REUSEADDR,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
255 &o,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
256 sizeof(int));
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
257
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
258 #ifdef LINUX
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
259 if(!ipv4) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
260 o = 1;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
261 setsockopt(
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
262 listener->server_socket6,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
263 IPPROTO_IPV6,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
264 IPV6_V6ONLY,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
265 &o,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
266 sizeof(int));
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
267 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
268 #endif
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
269
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
270 // bind server socket to address
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
271 struct sockaddr_in servaddr4;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
272 struct sockaddr_in6 servaddr6;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
273 struct sockaddr *servaddr;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
274 size_t servaddr_size;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
275 if(ipv4) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
276 // ipv4
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
277 memset(&servaddr4, 0, sizeof(servaddr4));
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
278 servaddr4.sin_family = AF_INET;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
279 servaddr4.sin_addr.s_addr = htonl(INADDR_ANY);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
280 servaddr4.sin_port = htons(conf->port);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
281 servaddr = (struct sockaddr *)&servaddr4;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
282 servaddr_size = sizeof(servaddr4);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
283 } else {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
284 // ipv6
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
285 memset(&servaddr6, 0, sizeof(servaddr6));
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
286 servaddr6.sin6_family = AF_INET6;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
287 servaddr6.sin6_addr = in6addr_any;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
288 servaddr6.sin6_port = htons(conf->port);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
289 servaddr = (struct sockaddr *)&servaddr6;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
290 servaddr_size = sizeof(servaddr6);
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
291 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
292
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
293 if(bind(s, servaddr, servaddr_size)) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
294 log_ereport(
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
295 LOG_FAILURE,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
296 "cannot bind socket: protocol: %s port: %d error: %s",
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
297 protocol,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
298 conf->port,
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
299 strerror(errno));
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
300 close(s);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
301 return NULL;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
302 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
303
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
304 // everything is ok, create WSSocket object
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
305 WSSocket *wssocket = malloc(sizeof(WSSocket));
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
306 if(!wssocket) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
307 close(s);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
308 return NULL;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
309 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
310 ZERO(wssocket, sizeof(WSSocket));
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
311 wssocket->socket = s;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
312
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
313 return wssocket;
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
314 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
316 static WSSocket* get_socket(ListenerConfig *conf, const char *protocol) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
317 char key_data[32];
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
318 size_t key_len = snprintf(key_data, 32, "%s:%d", protocol, conf->port);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
319 CxHashKey key = cx_hash_key(key_data, key_len);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
320
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
321 WSSocket *sock = cxMapGet(listener_socket_map, key);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
322 if(!sock) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
323 sock = create_socket(conf, protocol);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
324 if(sock) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
325 cxMapPut(listener_socket_map, key, sock);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
326 }
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
327 }
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
328 return sock;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
329 }
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
330
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
331 /*
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
332 * returns HttpSSL of socket1 or socket2 if ssl is available
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
333 */
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
334 static HttpSSL* socket_get_ssl(WSSocket *socket1, WSSocket *socket2) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
335 if(socket1 && socket1->ssl) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
336 return socket1->ssl;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
337 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
338 if(socket2 && socket2->ssl) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
339 return socket2->ssl;
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
340 }
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
341 return NULL;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
342 }
23
a2c8fc23c90e Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
343
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
344 static HttpListener* listener_create(ListenerConfig *conf) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
345 pool_handle_t *pool = conf->cfg->pool;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
346 HttpListener *listener = pool_malloc(pool, sizeof(HttpListener));
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
347 if(!listener) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
348 return NULL;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
349 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
350 ZERO(listener, sizeof(HttpListener));
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
351
74
5bc6d078fb2c listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
352 listener->running = 0;
38
d07810b02147 added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
353 listener->cfg = conf->cfg;
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
354 listener->name = cx_strdup_a(pool_allocator(pool), cx_strcast(conf->name));
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
355 listener->default_vs.vs_name = pool_strdup(pool, conf->vs.ptr);
81
d25825f37967 preparation for admin interface
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 78
diff changeset
356 listener->threadpool = NULL;
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
357 if(conf->threadpool.ptr != NULL) {
415
d938228c382e switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 398
diff changeset
358 listener->threadpool = get_threadpool(cx_strcast(conf->threadpool));
37
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
359 }
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
360 if(listener->threadpool == NULL) {
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
361 listener->threadpool = get_default_threadpool();
360b9aabe17e added support for asynchronous safs
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 36
diff changeset
362 }
134
44415e4399ce adds blockingio config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
363 if(conf->blockingio) {
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
364 listener->session_handler = create_basic_session_handler(pool);
134
44415e4399ce adds blockingio config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
365 } else {
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
366 listener->session_handler = create_event_session_handler(pool);
134
44415e4399ce adds blockingio config
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 133
diff changeset
367 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
368 listener->nacceptors = conf->nacceptors;
29
e8619defde14 added event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 25
diff changeset
369 listener->port = conf->port;
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
370 listener->ref = 1;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
371 listener->next = NULL;
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
372 listener->ssl = NULL;
130
198ad9d8cec1 adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
373
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
374 // create sockets
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
375 listener->server_socket = get_socket(conf, LISTENER_PROTO_IPV4);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
376 listener->server_socket6 = get_socket(conf, LISTENER_PROTO_IPV6);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
377 if(!listener->server_socket && !listener->server_socket6) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
378 log_ereport(LOG_FAILURE, "Listener %s: no server socket", conf->name.ptr);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
379 return NULL;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
380 }
130
198ad9d8cec1 adds ssl protocol configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 129
diff changeset
381
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
382 if(listener->server_socket) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
383 wssocket_ref(listener->server_socket);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
384 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
385 if(listener->server_socket6) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
386 wssocket_ref(listener->server_socket6);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
387 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
388
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
389 // create SSL context
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
390 if(conf->ssl) {
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
391 HttpSSL *ssl = socket_get_ssl(listener->server_socket, listener->server_socket6);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
392 if(!ssl) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
393 ssl = create_http_ssl(conf);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
394 if(!ssl) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
395 log_ereport(LOG_FAILURE, "Listener %s: cannot create SSL context", conf->name.ptr);
129
fd324464f56f adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
396 return NULL;
fd324464f56f adds support for ssl cert chain files and improves ssl error handling
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
397 }
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
398 }
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
399 if(listener->server_socket) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
400 listener->server_socket->ssl = ssl;
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
401 }
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
402 if(listener->server_socket6) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
403 listener->server_socket6->ssl = ssl;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
404 }
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
405 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
406
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
407 // create acceptors
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
408 listener->acceptors = calloc(listener->nacceptors, sizeof(void*));
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
409 listener->acceptors6 = calloc(listener->nacceptors, sizeof(void*));
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
410 for (int i=0;i<listener->nacceptors;i++) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
411 listener->acceptors[i] = acceptor_new(listener);
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
412 listener->acceptors6[i] = acceptor_new(listener);
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
413 listener->acceptors6[i]->ipv6 = TRUE;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
414 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
415
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
416 return listener;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
417 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
418
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
419 HttpListener* http_listener_create(ListenerConfig *conf) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
420 pthread_mutex_lock(&listener_mutex);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
421 HttpListener *listener = listener_create(conf);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
422 pthread_mutex_unlock(&listener_mutex);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
423 return listener;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
424 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
425
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
426 int http_listener_start(HttpListener *listener) {
74
5bc6d078fb2c listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
427 if(listener->running) {
5bc6d078fb2c listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
428 return 0;
5bc6d078fb2c listeners can be dynamically added
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 69
diff changeset
429 }
60
feb2f1e115c6 improved logging
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 46
diff changeset
430 log_ereport(LOG_INFORM, "start listener on port %d", listener->port);
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
431
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
432 WSBool ipv4 = listener->server_socket ? TRUE : FALSE;
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
433 WSBool ipv6 = listener->server_socket6 ? TRUE: FALSE;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
434
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
435 if (ipv4 && !listener->server_socket->listening && listen(listener->server_socket->socket, 256) == -1) {
398
83234bc3bee9 use IPV6_V6ONLY socket option on linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
436 log_ereport(LOG_FAILURE, "http_listener_start: listen failed: %s", strerror(errno));
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
437 return -1;
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
438 } else {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
439 listener->server_socket->listening = TRUE;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
440 }
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
441 if (ipv6 && !listener->server_socket6->listening && listen(listener->server_socket6->socket, 256) == -1) {
398
83234bc3bee9 use IPV6_V6ONLY socket option on linux
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 396
diff changeset
442 log_ereport(LOG_FAILURE, "http_listener_start: listen v6 failed: %s", strerror(errno));
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
443 return -1;
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
444 } else {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
445 listener->server_socket6->listening = TRUE;
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
446 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
447
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
448 // start acceptor threads
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
449 for (int i=0;i<listener->nacceptors;i++) {
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
450 if(ipv4) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
451 acceptor_start(listener->acceptors[i]);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
452 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
453 if(ipv6) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
454 acceptor_start(listener->acceptors6[i]);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
455 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
456 }
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
457 listener->running = TRUE;
19
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
458
d680536f8c2f Added configuration manager
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 15
diff changeset
459 return 0;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
460 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
461
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
462 void http_listener_ref(HttpListener *listener) {
41
bb7a1f5a8b48 added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
463 ws_atomic_inc32(&listener->ref);
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
464 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
465
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
466 void http_listener_unref(HttpListener *listener) {
41
bb7a1f5a8b48 added Linux support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 38
diff changeset
467 uint32_t ref = ws_atomic_dec32(&listener->ref);
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
468 if(ref == 0) {
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
469 log_ereport(LOG_VERBOSE, "HttpListener %s: destroy", listener->name.ptr);
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
470 free(listener->acceptors);
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
471 // TODO: unref cfg
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
472 // TODO: unref session handler
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
473 free(listener);
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
474 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
475 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
476
440
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
477 int http_listener_socket_eq(HttpListener *l1, HttpListener *l2) {
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
478 if(l1->server_socket && l2->server_socket && l1->server_socket == l2->server_socket) {
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
479 return TRUE;
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
480 }
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
481 if(l1->server_socket6 && l2->server_socket6 && l1->server_socket6 == l2->server_socket6) {
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
482 return TRUE;
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
483 }
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
484 return FALSE;
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
485 }
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
486
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
487 void http_listener_set_next(HttpListener *listener, HttpListener *next) {
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
488 while(listener->next) {
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
489 listener = listener->next;
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
490 }
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
491
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
492 http_listener_ref(next);
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
493 listener->next = next;
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
494 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
495
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
496
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
497 Acceptor* acceptor_new(HttpListener *listener) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
498 Acceptor *acceptor = malloc(sizeof(Acceptor));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
499 acceptor->listener = listener;
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
500 acceptor->ipv6 = WS_FALSE;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
501 return acceptor;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
502 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
503
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
504 void acceptor_start(Acceptor *a) {
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
505 if(pthread_create(
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
506 &a->tid,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
507 NULL,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
508 (void*(*)(void*))acceptor_thread,
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
509 a) != 0)
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
510 {
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
511 log_ereport(LOG_FAILURE, "Listener %s: acceptor_start: %s", a->listener->name.ptr, strerror(errno));
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
512 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
513 }
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
514
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
515 void* acceptor_thread(Acceptor *acceptor) {
87
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
516 WS_ASSERT(acceptor);
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
517 WS_ASSERT(acceptor->listener);
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
518 WS_ASSERT(acceptor->listener->session_handler);
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
519 WS_ASSERT(acceptor->listener->session_handler->enqueue_connection);
bdec069d2239 fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 81
diff changeset
520
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
521 HttpListener *listener = acceptor->listener;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
522
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
523 int server_socket;
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
524
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
525 ConnectionAddr ca;
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
526 struct sockaddr *ca_ptr;
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
527 socklen_t ca_length;
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
528 ConnectionAddrType addr_type;
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
529 if(acceptor->ipv6) {
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
530 server_socket = listener->server_socket6->socket;
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
531 ca_ptr = (struct sockaddr*)&ca.address_v6;
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
532 ca_length = sizeof(ca.address_v6);
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
533 addr_type = CONN_ADDR_IPV6;
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
534 } else {
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
535 server_socket = listener->server_socket->socket;
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
536 ca_ptr = (struct sockaddr*)&ca.address_v4;
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
537 ca_length = sizeof(ca.address_v4);
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
538 addr_type = CONN_ADDR_IPV4;
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
539 }
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
540
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
541
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
542 for (;;) {
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
543 // accept connections
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
544 int clientfd;
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
545 socklen_t length = ca_length;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
546
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
547 // accept a connection
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
548 clientfd = accept(
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
549 server_socket,
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
550 ca_ptr,
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
551 &length);
440
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
552 log_ereport(LOG_DEBUG, "acceptor: %p listener: %p: accept(): %d", acceptor, acceptor->listener, clientfd);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
553 if (clientfd == -1) {
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
554 log_ereport(LOG_FAILURE, "accept %s failed: %s", acceptor->ipv6 ? "ipv6" : "ipv4", strerror(errno));
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
555 continue;
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
556 }
145
1c93281ca4bf fixes memory leaks in request_stat_path and send_cgi
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 134
diff changeset
557
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
558 // check listener
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
559 HttpListener *ls = listener;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
560 int acceptor_exit = 0;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
561 while(ls->next) {
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
562 ls = ls->next;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
563 acceptor_exit = 1;
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
564 }
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
565
440
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
566 // create Connection object
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
567 Connection *conn = malloc(sizeof(Connection));
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
568 conn->address = ca;
396
77d81f2bb9f7 add initial ipv6 support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 256
diff changeset
569 conn->addr_type = addr_type;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
570 conn->fd = clientfd;
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
571 conn->listener = ls;
194
6345f50208d5 fixes keep-alive with ssl
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 193
diff changeset
572 conn->ssl_accepted = 0;
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
573 if(ls->ssl) {
191
391ccd490d97 moves IOStream creation to the sessionhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
574 // SSL connections are always non-blocking
188
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
575 // set socket non blocking
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
576 int flags;
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
577 if((flags = fcntl(conn->fd, F_GETFL, 0)) == -1) {
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
578 flags = 0;
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
579 }
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
580 if(fcntl(conn->fd, F_SETFL, flags | O_NONBLOCK)) {
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
581 perror("Error: acceptor_thread: fcntl");
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
582 // TODO: error
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
583 }
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
584
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
585 SSL *ssl = SSL_new(ls->ssl->sslctx);
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
586 SSL_set_fd(ssl, clientfd);
188
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
587
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
588 conn->ssl = ssl;
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
589 conn->read = connection_ssl_read;
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
590 conn->write = connection_ssl_write;
0e6a05c779e0 using non-blocking IO for SSL_accept
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 152
diff changeset
591 conn->close = connection_ssl_close;
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
592 } else {
111
c93be34fde76 fixed NetBSD build and an uninitialized struct member
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 106
diff changeset
593 conn->ssl = NULL;
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
594 conn->read = connection_read;
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
595 conn->write = connection_write;
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
596 conn->close = connection_close;
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
597 }
61
c858850f3d3a improved configuration reloading
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 60
diff changeset
598
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
599 if(conn) {
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
600 cfg_ref(ls->cfg);
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
601
440
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
602 // enqueue the connection
106
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
603 ls->session_handler->enqueue_connection(
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
604 ls->session_handler,
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
605 conn);
b122f34ddc80 added minimal ssl support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 101
diff changeset
606 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
607
440
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
608 // ready for new connection
38
d07810b02147 added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 37
diff changeset
609
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
610 if(acceptor_exit) {
46
636e05eb48f6 cleaning up resources after requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 44
diff changeset
611 // this acceptor is outdated
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
612 log_ereport(LOG_VERBOSE, "acceptor thread %p: exit", (void*)acceptor->tid);
25
5dee29c7c530 Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
613 break;
5dee29c7c530 Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
614 }
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
615 }
25
5dee29c7c530 Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
616
440
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
617 if(listener->next) {
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
618 http_listener_unref(listener->next);
d77b8f3e14e2 implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 438
diff changeset
619 }
36
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
620 http_listener_unref(listener);
450d2d5f4735 server can reload configuration
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 35
diff changeset
621
25
5dee29c7c530 Fixed config parser bug
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 23
diff changeset
622 return NULL;
1
3c066d52342d added source
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
623 }
438
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
624
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
625 void wssocket_ref(WSSocket *ws) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
626 ws_atomic_inc32(&ws->ref);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
627 }
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
628
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
629 void wssocket_unref(WSSocket *ws) {
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
630 // does nothing yet, because maybe it is not a good idea to destroy
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
631 // a socket
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
632 ws_atomic_dec32(&ws->ref);
22eca559aded refactore http listener creation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 415
diff changeset
633 }

mercurial