52 #include <stdio.h> |
52 #include <stdio.h> |
53 #include <stdlib.h> |
53 #include <stdlib.h> |
54 #include <sys/socket.h> |
54 #include <sys/socket.h> |
55 #include <unistd.h> |
55 #include <unistd.h> |
56 |
56 |
57 #include <ucx/map.h> |
57 |
|
58 #include <cx/hash_map.h> |
58 |
59 |
59 #include "../util/atomic.h" |
60 #include "../util/atomic.h" |
60 #include "httplistener.h" |
61 #include "httplistener.h" |
61 #include "netsite.h" |
62 #include "netsite.h" |
62 |
63 |
63 #include "session.h" |
64 #include "session.h" |
64 #include "configmanager.h" |
65 #include "configmanager.h" |
65 #include "log.h" |
66 #include "log.h" |
66 |
67 |
67 UcxMap *listener_map = NULL; |
68 #define LISTENER_MAX_PROTOCOL_TOKENS 1024 |
|
69 |
|
70 CxMap *listener_map = NULL; |
68 |
71 |
69 int start_all_listener() { |
72 int start_all_listener() { |
70 ServerConfiguration *conf = cfgmgr_get_server_config(); |
73 ServerConfiguration *conf = cfgmgr_get_server_config(); |
71 UcxList *ls = conf->listeners; |
74 CxList *ls = conf->listeners; |
72 while(ls) { |
75 CxIterator iter = cxListIterator(ls, 0); |
73 HttpListener *listener = ls->data; |
76 cx_foreach(HttpListener *, listener, iter) { |
74 http_listener_start(listener); |
77 http_listener_start(listener); |
75 ls = ls->next; |
|
76 } |
78 } |
77 |
79 |
78 return 0; |
80 return 0; |
79 } |
81 } |
80 |
82 |
81 HttpListener* http_listener_create(ListenerConfig *conf) { |
83 HttpListener* http_listener_create(ListenerConfig *conf) { |
82 if(listener_map == NULL) { |
84 if(listener_map == NULL) { |
83 listener_map = ucx_map_new(16); |
85 listener_map = cxHashMapCreate(cxDefaultAllocator, 16); |
84 } |
86 } |
85 |
87 |
86 HttpListener *fl = ucx_map_sstr_get(listener_map, conf->name); |
88 HttpListener *fl = cxMapGet(listener_map, cx_hash_key(conf->name.ptr, conf->name.length)); |
87 if(fl == NULL) { |
89 if(fl == NULL) { |
88 return http_listener_new(conf); |
90 return http_listener_new(conf); |
89 } |
91 } |
90 |
92 |
91 HttpListener* newls = calloc(1, sizeof(HttpListener)); |
93 HttpListener* newls = calloc(1, sizeof(HttpListener)); |
163 listener->cfg = conf->cfg; |
165 listener->cfg = conf->cfg; |
164 listener->name = conf->name; |
166 listener->name = conf->name; |
165 listener->default_vs.vs_name = conf->vs.ptr; |
167 listener->default_vs.vs_name = conf->vs.ptr; |
166 listener->threadpool = NULL; |
168 listener->threadpool = NULL; |
167 if(conf->threadpool.ptr != NULL) { |
169 if(conf->threadpool.ptr != NULL) { |
168 listener->threadpool = get_threadpool(conf->threadpool); |
170 listener->threadpool = get_threadpool(cx_strcast(conf->threadpool)); |
169 } |
171 } |
170 if(listener->threadpool == NULL) { |
172 if(listener->threadpool == NULL) { |
171 listener->threadpool = get_default_threadpool(); |
173 listener->threadpool = get_default_threadpool(); |
172 } |
174 } |
173 if(conf->blockingio) { |
175 if(conf->blockingio) { |
189 SSL_CTX *ctx = SSL_CTX_new(SSLv23_server_method()); |
191 SSL_CTX *ctx = SSL_CTX_new(SSLv23_server_method()); |
190 SSL_CTX_set_options( |
192 SSL_CTX_set_options( |
191 ctx, |
193 ctx, |
192 SSL_OP_SINGLE_DH_USE | SSL_OP_NO_SSLv3); |
194 SSL_OP_SINGLE_DH_USE | SSL_OP_NO_SSLv3); |
193 if(conf->disable_proto.ptr) { |
195 if(conf->disable_proto.ptr) { |
194 ssize_t n = 0; |
196 cxstring *plist = NULL; |
195 sstr_t *plist = sstrsplit(conf->disable_proto, S(","), &n); |
197 ssize_t n = cx_strsplit_a(cxDefaultAllocator, conf->disable_proto, cx_str(","), LISTENER_MAX_PROTOCOL_TOKENS, &plist); |
196 if(plist) { |
198 if(plist) { |
197 for(int i=0;i<n;i++) { |
199 for(int i=0;i<n;i++) { |
198 sstr_t proto = plist[i]; |
200 cxstring proto = plist[i]; |
199 log_ereport( |
201 log_ereport( |
200 LOG_VERBOSE, |
202 LOG_VERBOSE, |
201 "Listener %s: Disable protocol %s", |
203 "Listener %s: Disable protocol %s", |
202 listener->name.ptr, |
204 listener->name.ptr, |
203 proto.ptr); |
205 proto.ptr); |
204 if(!sstrcasecmp(sstrtrim(proto), S("SSLv2"))) { |
206 if(!cx_strcasecmp(cx_strtrim(proto), cx_str("SSLv2"))) { |
205 SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2); |
207 SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2); |
206 } else if(!sstrcasecmp(sstrtrim(proto), S("SSLv3"))) { |
208 } else if(!cx_strcasecmp(cx_strtrim(proto), cx_str("SSLv3"))) { |
207 SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv3); |
209 SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv3); |
208 } else if(!sstrcasecmp(sstrtrim(proto), S("TLSv1"))) { |
210 } else if(!cx_strcasecmp(cx_strtrim(proto), cx_str("TLSv1"))) { |
209 SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1); |
211 SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1); |
210 } else if(!sstrcasecmp(sstrtrim(proto), S("TLSv1.1"))) { |
212 } else if(!cx_strcasecmp(cx_strtrim(proto), cx_str("TLSv1.1"))) { |
211 #ifdef SSL_OP_NO_TLSv1_1 |
213 #ifdef SSL_OP_NO_TLSv1_1 |
212 SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_1); |
214 SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_1); |
213 #else |
215 #else |
214 log_ereport( |
216 log_ereport( |
215 LOG_WARN, |
217 LOG_WARN, |
216 "Listener: %s: TLSv1.1 already not supported", |
218 "Listener: %s: TLSv1.1 already not supported", |
217 listener->name.ptr); |
219 listener->name.ptr); |
218 #endif |
220 #endif |
219 } else if(sstrcasecmp(sstrtrim(proto), S("TLSv1.2"))) { |
221 } else if(cx_strcasecmp(cx_strtrim(proto), cx_str("TLSv1.2"))) { |
220 #ifdef SSL_OP_NO_TLSv1_2 |
222 #ifdef SSL_OP_NO_TLSv1_2 |
221 SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_2); |
223 SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_2); |
222 #else |
224 #else |
223 log_ereport( |
225 log_ereport( |
224 LOG_WARN, |
226 LOG_WARN, |
225 "Listener: %s: TLSv1.2 already not supported", |
227 "Listener: %s: TLSv1.2 already not supported", |
226 listener->name.ptr); |
228 listener->name.ptr); |
227 #endif |
229 #endif |
228 } else if(sstrcasecmp(sstrtrim(proto), S("TLSv1.3"))) { |
230 } else if(cx_strcasecmp(cx_strtrim(proto), cx_str("TLSv1.3"))) { |
229 #ifdef SSL_OP_NO_TLSv1_3 |
231 #ifdef SSL_OP_NO_TLSv1_3 |
230 SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_3); |
232 SSL_CTX_set_options(ctx, SSL_OP_NO_TLSv1_3); |
231 #else |
233 #else |
232 log_ereport( |
234 log_ereport( |
233 LOG_WARN, |
235 LOG_WARN, |