Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 1 | /* |
| 2 | * libwebsockets web server application |
| 3 | * |
| 4 | * Copyright (C) 2010-2016 Andy Green <andy@warmcat.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public |
| 8 | * License as published by the Free Software Foundation: |
| 9 | * version 2.1 of the License. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 19 | * MA 02110-1301 USA |
| 20 | */ |
| 21 | |
Andy Green | 3358c53 | 2016-05-26 21:12:11 +0800 | [diff] [blame] | 22 | #include "private-libwebsockets.h" |
| 23 | #include "lejp.h" |
| 24 | |
| 25 | #ifndef _WIN32 |
| 26 | /* this is needed for Travis CI */ |
| 27 | #include <dirent.h> |
| 28 | #endif |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 29 | |
| 30 | static const char * const paths_global[] = { |
| 31 | "global.uid", |
| 32 | "global.gid", |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 33 | "global.count-threads", |
| 34 | "global.init-ssl", |
Andy Green | b21c20b | 2016-04-15 13:33:52 +0800 | [diff] [blame] | 35 | "global.server-string", |
Andy Green | cae57ad | 2016-05-02 10:03:25 +0800 | [diff] [blame] | 36 | "global.plugin-dir" |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | enum lejp_global_paths { |
| 40 | LEJPGP_UID, |
| 41 | LEJPGP_GID, |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 42 | LEJPGP_COUNT_THREADS, |
| 43 | LWJPGP_INIT_SSL, |
Andy Green | b21c20b | 2016-04-15 13:33:52 +0800 | [diff] [blame] | 44 | LEJPGP_SERVER_STRING, |
Andy Green | cae57ad | 2016-05-02 10:03:25 +0800 | [diff] [blame] | 45 | LEJPGP_PLUGIN_DIR |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | static const char * const paths_vhosts[] = { |
| 49 | "vhosts[]", |
| 50 | "vhosts[].mounts[]", |
| 51 | "vhosts[].name", |
| 52 | "vhosts[].port", |
Andy Green | 1042b34 | 2016-04-14 11:50:05 +0800 | [diff] [blame] | 53 | "vhosts[].interface", |
Andy Green | a1ab201 | 2016-04-14 12:18:33 +0800 | [diff] [blame] | 54 | "vhosts[].unix-socket", |
Andy Green | 868b9f2 | 2016-04-14 12:37:21 +0800 | [diff] [blame] | 55 | "vhosts[].sts", |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 56 | "vhosts[].host-ssl-key", |
| 57 | "vhosts[].host-ssl-cert", |
| 58 | "vhosts[].host-ssl-ca", |
Andy Green | 2f0bc93 | 2016-04-15 12:00:23 +0800 | [diff] [blame] | 59 | "vhosts[].access-log", |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 60 | "vhosts[].mounts[].mountpoint", |
| 61 | "vhosts[].mounts[].origin", |
Andy Green | 37098ae | 2016-04-08 13:25:34 +0800 | [diff] [blame] | 62 | "vhosts[].mounts[].default", |
Andy Green | f5efa74 | 2016-04-13 11:42:53 +0800 | [diff] [blame] | 63 | "vhosts[].mounts[].cgi-timeout", |
Andy Green | a5e73a1 | 2016-04-13 11:49:07 +0800 | [diff] [blame] | 64 | "vhosts[].mounts[].cgi-env[].*", |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 65 | "vhosts[].mounts[].cache-max-age", |
| 66 | "vhosts[].mounts[].cache-reuse", |
| 67 | "vhosts[].mounts[].cache-revalidate", |
| 68 | "vhosts[].mounts[].cache-intermediaries", |
Andy Green | 8ef14c0 | 2016-05-14 10:00:21 +0800 | [diff] [blame] | 69 | "vhosts[].mounts[].extra-mimetypes.*", |
Andy Green | 37098ae | 2016-04-08 13:25:34 +0800 | [diff] [blame] | 70 | "vhosts[].ws-protocols[].*.*", |
| 71 | "vhosts[].ws-protocols[].*", |
Andy Green | d459a6f | 2016-04-08 18:30:45 +0800 | [diff] [blame] | 72 | "vhosts[].ws-protocols[]", |
Andy Green | b46e4a8 | 2016-04-12 16:26:03 +0800 | [diff] [blame] | 73 | "vhosts[].keepalive_timeout", |
Andy Green | fb8be05 | 2016-05-12 19:39:29 +0800 | [diff] [blame] | 74 | "vhosts[].enable-client-ssl", |
Andy Green | 6954daa | 2016-05-14 09:50:34 +0800 | [diff] [blame] | 75 | "vhosts[].ciphers", |
| 76 | "vhosts[].ecdh-curve", |
Andy Green | 2dc7dde | 2016-06-03 21:19:40 +0800 | [diff] [blame] | 77 | "vhosts[].noipv6", |
Andy Green | 011f915 | 2016-06-04 09:01:28 +0800 | [diff] [blame] | 78 | "vhosts[].ipv6only", |
Andy Green | 1ec8ba8 | 2016-06-10 08:37:26 +0800 | [diff] [blame] | 79 | "vhosts[].ssl-option-set", |
| 80 | "vhosts[].ssl-option-clear", |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | enum lejp_vhost_paths { |
| 84 | LEJPVP, |
| 85 | LEJPVP_MOUNTS, |
| 86 | LEJPVP_NAME, |
| 87 | LEJPVP_PORT, |
Andy Green | 1042b34 | 2016-04-14 11:50:05 +0800 | [diff] [blame] | 88 | LEJPVP_INTERFACE, |
Andy Green | a1ab201 | 2016-04-14 12:18:33 +0800 | [diff] [blame] | 89 | LEJPVP_UNIXSKT, |
Andy Green | 868b9f2 | 2016-04-14 12:37:21 +0800 | [diff] [blame] | 90 | LEJPVP_STS, |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 91 | LEJPVP_HOST_SSL_KEY, |
| 92 | LEJPVP_HOST_SSL_CERT, |
| 93 | LEJPVP_HOST_SSL_CA, |
Andy Green | 2f0bc93 | 2016-04-15 12:00:23 +0800 | [diff] [blame] | 94 | LEJPVP_ACCESS_LOG, |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 95 | LEJPVP_MOUNTPOINT, |
| 96 | LEJPVP_ORIGIN, |
| 97 | LEJPVP_DEFAULT, |
Andy Green | f5efa74 | 2016-04-13 11:42:53 +0800 | [diff] [blame] | 98 | LEJPVP_CGI_TIMEOUT, |
Andy Green | a5e73a1 | 2016-04-13 11:49:07 +0800 | [diff] [blame] | 99 | LEJPVP_CGI_ENV, |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 100 | LEJPVP_MOUNT_CACHE_MAX_AGE, |
| 101 | LEJPVP_MOUNT_CACHE_REUSE, |
| 102 | LEJPVP_MOUNT_CACHE_REVALIDATE, |
| 103 | LEJPVP_MOUNT_CACHE_INTERMEDIARIES, |
Andy Green | 8ef14c0 | 2016-05-14 10:00:21 +0800 | [diff] [blame] | 104 | LEJPVP_MOUNT_EXTRA_MIMETYPES, |
Andy Green | 37098ae | 2016-04-08 13:25:34 +0800 | [diff] [blame] | 105 | LEJPVP_PROTOCOL_NAME_OPT, |
| 106 | LEJPVP_PROTOCOL_NAME, |
| 107 | LEJPVP_PROTOCOL, |
Andy Green | b46e4a8 | 2016-04-12 16:26:03 +0800 | [diff] [blame] | 108 | LEJPVP_KEEPALIVE_TIMEOUT, |
Andy Green | fb8be05 | 2016-05-12 19:39:29 +0800 | [diff] [blame] | 109 | LEJPVP_ENABLE_CLIENT_SSL, |
Andy Green | 6954daa | 2016-05-14 09:50:34 +0800 | [diff] [blame] | 110 | LEJPVP_CIPHERS, |
| 111 | LEJPVP_ECDH_CURVE, |
Andy Green | 2dc7dde | 2016-06-03 21:19:40 +0800 | [diff] [blame] | 112 | LEJPVP_NOIPV6, |
Andy Green | 011f915 | 2016-06-04 09:01:28 +0800 | [diff] [blame] | 113 | LEJPVP_IPV6ONLY, |
Andy Green | 1ec8ba8 | 2016-06-10 08:37:26 +0800 | [diff] [blame] | 114 | LEJPVP_SSL_OPTION_SET, |
| 115 | LEJPVP_SSL_OPTION_CLEAR, |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 116 | }; |
| 117 | |
Andy Green | 4bd5b96 | 2016-06-18 06:36:37 +0800 | [diff] [blame^] | 118 | static const char * const parser_errs[] = { |
| 119 | "", |
| 120 | "", |
| 121 | "No opening '{'", |
| 122 | "Expected closing '}'", |
| 123 | "Expected '\"'", |
| 124 | "String underrun", |
| 125 | "Illegal unescaped control char", |
| 126 | "Illegal escape format", |
| 127 | "Illegal hex number", |
| 128 | "Expected ':'", |
| 129 | "Illegal value start", |
| 130 | "Digit required after decimal point", |
| 131 | "Bad number format", |
| 132 | "Bad exponent format", |
| 133 | "Unknown token", |
| 134 | "Too many ']'", |
| 135 | "Mismatched ']'", |
| 136 | "Expected ']'", |
| 137 | "JSON nesting limit exceeded", |
| 138 | "Nesting tracking used up", |
| 139 | "Number too long", |
| 140 | "Comma or block end expected", |
| 141 | "Unknown", |
| 142 | "Parser callback errored (see earlier error)", |
| 143 | }; |
| 144 | |
Andy Green | cae57ad | 2016-05-02 10:03:25 +0800 | [diff] [blame] | 145 | #define MAX_PLUGIN_DIRS 10 |
| 146 | |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 147 | struct jpargs { |
| 148 | struct lws_context_creation_info *info; |
| 149 | struct lws_context *context; |
| 150 | const struct lws_protocols *protocols; |
| 151 | const struct lws_extension *extensions; |
| 152 | char *p, *end, valid; |
| 153 | struct lws_http_mount *head, *last; |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 154 | |
Andy Green | 37098ae | 2016-04-08 13:25:34 +0800 | [diff] [blame] | 155 | struct lws_protocol_vhost_options *pvo; |
Andy Green | 8ef14c0 | 2016-05-14 10:00:21 +0800 | [diff] [blame] | 156 | struct lws_protocol_vhost_options *pvo_em; |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 157 | struct lws_http_mount m; |
Andy Green | cae57ad | 2016-05-02 10:03:25 +0800 | [diff] [blame] | 158 | const char **plugin_dirs; |
| 159 | int count_plugin_dirs; |
Andy Green | fb8be05 | 2016-05-12 19:39:29 +0800 | [diff] [blame] | 160 | |
| 161 | unsigned int enable_client_ssl:1; |
Andy Green | 8ef14c0 | 2016-05-14 10:00:21 +0800 | [diff] [blame] | 162 | unsigned int fresh_mount:1; |
Andy Green | 92b0d8a | 2016-05-22 07:01:35 +0800 | [diff] [blame] | 163 | unsigned int any_vhosts:1; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 164 | }; |
| 165 | |
Andy Green | 37098ae | 2016-04-08 13:25:34 +0800 | [diff] [blame] | 166 | static void * |
| 167 | lwsws_align(struct jpargs *a) |
| 168 | { |
| 169 | if ((unsigned long)(a->p) & 15) |
| 170 | a->p += 16 - ((unsigned long)(a->p) & 15); |
| 171 | |
| 172 | return a->p; |
| 173 | } |
| 174 | |
Andy Green | a1ab201 | 2016-04-14 12:18:33 +0800 | [diff] [blame] | 175 | static int |
| 176 | arg_to_bool(const char *s) |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 177 | { |
| 178 | static const char * const on[] = { "on", "yes", "true" }; |
| 179 | int n = atoi(s); |
| 180 | |
| 181 | if (n) |
| 182 | return 1; |
| 183 | |
| 184 | for (n = 0; n < ARRAY_SIZE(on); n++) |
| 185 | if (!strcasecmp(s, on[n])) |
| 186 | return 1; |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | static char |
| 192 | lejp_globals_cb(struct lejp_ctx *ctx, char reason) |
| 193 | { |
| 194 | struct jpargs *a = (struct jpargs *)ctx->user; |
| 195 | |
| 196 | /* we only match on the prepared path strings */ |
| 197 | if (!(reason & LEJP_FLAG_CB_IS_VALUE) || !ctx->path_match) |
| 198 | return 0; |
| 199 | |
| 200 | switch (ctx->path_match - 1) { |
| 201 | case LEJPGP_UID: |
| 202 | a->info->uid = atoi(ctx->buf); |
| 203 | return 0; |
| 204 | case LEJPGP_GID: |
| 205 | a->info->gid = atoi(ctx->buf); |
| 206 | return 0; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 207 | case LEJPGP_COUNT_THREADS: |
| 208 | a->info->count_threads = atoi(ctx->buf); |
| 209 | return 0; |
| 210 | case LWJPGP_INIT_SSL: |
| 211 | if (arg_to_bool(ctx->buf)) |
| 212 | a->info->options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; |
| 213 | return 0; |
Andy Green | b21c20b | 2016-04-15 13:33:52 +0800 | [diff] [blame] | 214 | case LEJPGP_SERVER_STRING: |
| 215 | a->info->server_string = a->p; |
| 216 | break; |
Andy Green | cae57ad | 2016-05-02 10:03:25 +0800 | [diff] [blame] | 217 | case LEJPGP_PLUGIN_DIR: |
| 218 | if (a->count_plugin_dirs == MAX_PLUGIN_DIRS - 1) { |
| 219 | lwsl_err("Too many plugin dirs\n"); |
| 220 | return -1; |
| 221 | } |
| 222 | a->plugin_dirs[a->count_plugin_dirs++] = a->p; |
| 223 | break; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 224 | |
| 225 | default: |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | a->p += snprintf(a->p, a->end - a->p, "%s", ctx->buf); |
| 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | static char |
| 235 | lejp_vhosts_cb(struct lejp_ctx *ctx, char reason) |
| 236 | { |
| 237 | struct jpargs *a = (struct jpargs *)ctx->user; |
Andy Green | a5e73a1 | 2016-04-13 11:49:07 +0800 | [diff] [blame] | 238 | struct lws_protocol_vhost_options *pvo, *mp_cgienv; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 239 | struct lws_http_mount *m; |
| 240 | int n; |
| 241 | |
Andy Green | a5e73a1 | 2016-04-13 11:49:07 +0800 | [diff] [blame] | 242 | #if 0 |
| 243 | lwsl_notice(" %d: %s (%d)\n", reason, ctx->path, ctx->path_match); |
| 244 | for (n = 0; n < ctx->wildcount; n++) |
| 245 | lwsl_notice(" %d\n", ctx->wild[n]); |
| 246 | #endif |
Andy Green | 37098ae | 2016-04-08 13:25:34 +0800 | [diff] [blame] | 247 | |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 248 | if (reason == LEJPCB_OBJECT_START && ctx->path_match == LEJPVP + 1) { |
Andy Green | 37098ae | 2016-04-08 13:25:34 +0800 | [diff] [blame] | 249 | /* set the defaults for this vhost */ |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 250 | a->valid = 1; |
| 251 | a->head = NULL; |
| 252 | a->last = NULL; |
| 253 | a->info->port = 0; |
| 254 | a->info->iface = NULL; |
| 255 | a->info->protocols = a->protocols; |
| 256 | a->info->extensions = a->extensions; |
| 257 | a->info->ssl_cert_filepath = NULL; |
| 258 | a->info->ssl_private_key_filepath = NULL; |
| 259 | a->info->ssl_ca_filepath = NULL; |
| 260 | a->info->timeout_secs = 5; |
| 261 | a->info->ssl_cipher_list = "ECDHE-ECDSA-AES256-GCM-SHA384:" |
| 262 | "ECDHE-RSA-AES256-GCM-SHA384:" |
| 263 | "DHE-RSA-AES256-GCM-SHA384:" |
| 264 | "ECDHE-RSA-AES256-SHA384:" |
| 265 | "HIGH:!aNULL:!eNULL:!EXPORT:" |
| 266 | "!DES:!MD5:!PSK:!RC4:!HMAC_SHA1:" |
| 267 | "!SHA1:!DHE-RSA-AES128-GCM-SHA256:" |
| 268 | "!DHE-RSA-AES128-SHA256:" |
| 269 | "!AES128-GCM-SHA256:" |
| 270 | "!AES128-SHA256:" |
| 271 | "!DHE-RSA-AES256-SHA256:" |
| 272 | "!AES256-GCM-SHA384:" |
| 273 | "!AES256-SHA256"; |
Andy Green | 37098ae | 2016-04-08 13:25:34 +0800 | [diff] [blame] | 274 | a->info->pvo = NULL; |
Andy Green | b46e4a8 | 2016-04-12 16:26:03 +0800 | [diff] [blame] | 275 | a->info->keepalive_timeout = 60; |
Andy Green | 2f0bc93 | 2016-04-15 12:00:23 +0800 | [diff] [blame] | 276 | a->info->log_filepath = NULL; |
Andy Green | 868b9f2 | 2016-04-14 12:37:21 +0800 | [diff] [blame] | 277 | a->info->options &= ~(LWS_SERVER_OPTION_UNIX_SOCK | |
| 278 | LWS_SERVER_OPTION_STS); |
Andy Green | fb8be05 | 2016-05-12 19:39:29 +0800 | [diff] [blame] | 279 | a->enable_client_ssl = 0; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | if (reason == LEJPCB_OBJECT_START && |
Andy Green | 8ef14c0 | 2016-05-14 10:00:21 +0800 | [diff] [blame] | 283 | ctx->path_match == LEJPVP_MOUNTS + 1) { |
| 284 | a->fresh_mount = 1; |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 285 | memset(&a->m, 0, sizeof(a->m)); |
Andy Green | 8ef14c0 | 2016-05-14 10:00:21 +0800 | [diff] [blame] | 286 | } |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 287 | |
Andy Green | 37098ae | 2016-04-08 13:25:34 +0800 | [diff] [blame] | 288 | /* this catches, eg, vhosts[].ws-protocols[].xxx-protocol */ |
| 289 | if (reason == LEJPCB_OBJECT_START && |
| 290 | ctx->path_match == LEJPVP_PROTOCOL_NAME + 1) { |
| 291 | a->pvo = lwsws_align(a); |
| 292 | a->p += sizeof(*a->pvo); |
| 293 | |
| 294 | n = lejp_get_wildcard(ctx, 0, a->p, a->end - a->p); |
| 295 | /* ie, enable this protocol, no options yet */ |
| 296 | a->pvo->next = a->info->pvo; |
| 297 | a->info->pvo = a->pvo; |
| 298 | a->pvo->name = a->p; |
Andy Green | 8ef14c0 | 2016-05-14 10:00:21 +0800 | [diff] [blame] | 299 | lwsl_notice(" adding protocol %s\n", a->p); |
Andy Green | 37098ae | 2016-04-08 13:25:34 +0800 | [diff] [blame] | 300 | a->p += n; |
| 301 | a->pvo->value = a->p; |
| 302 | a->pvo->options = NULL; |
| 303 | a->p += snprintf(a->p, a->end - a->p, "%s", ctx->buf); |
| 304 | *(a->p)++ = '\0'; |
| 305 | } |
| 306 | |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 307 | if (reason == LEJPCB_OBJECT_END && |
| 308 | (ctx->path_match == LEJPVP + 1 || !ctx->path[0]) && |
| 309 | a->valid) { |
| 310 | |
Andy Green | fb8be05 | 2016-05-12 19:39:29 +0800 | [diff] [blame] | 311 | struct lws_vhost *vhost; |
| 312 | |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 313 | //lwsl_notice("%s\n", ctx->path); |
| 314 | if (!a->info->port) { |
| 315 | lwsl_err("Port required (eg, 443)"); |
| 316 | return 1; |
| 317 | } |
| 318 | a->valid = 0; |
Andy Green | 4664f71 | 2016-05-02 04:59:54 +0800 | [diff] [blame] | 319 | a->info->mounts = a->head; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 320 | |
Andy Green | fb8be05 | 2016-05-12 19:39:29 +0800 | [diff] [blame] | 321 | vhost = lws_create_vhost(a->context, a->info); |
| 322 | if (!vhost) { |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 323 | lwsl_err("Failed to create vhost %s\n", |
| 324 | a->info->vhost_name); |
| 325 | return 1; |
| 326 | } |
Andy Green | 92b0d8a | 2016-05-22 07:01:35 +0800 | [diff] [blame] | 327 | a->any_vhosts = 1; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 328 | |
Andy Green | fb8be05 | 2016-05-12 19:39:29 +0800 | [diff] [blame] | 329 | if (a->enable_client_ssl) { |
| 330 | memset(a->info, 0, sizeof(*a->info)); |
| 331 | a->info->options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; |
| 332 | lws_init_vhost_client_ssl(a->info, vhost); |
| 333 | } |
| 334 | |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | if (reason == LEJPCB_OBJECT_END && |
| 339 | ctx->path_match == LEJPVP_MOUNTS + 1) { |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 340 | static const char * const mount_protocols[] = { |
| 341 | "http://", |
| 342 | "https://", |
| 343 | "file://", |
| 344 | "cgi://", |
| 345 | ">http://", |
| 346 | ">https://", |
Andy Green | b24aaeb | 2016-05-09 09:37:01 +0800 | [diff] [blame] | 347 | "callback://" |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 348 | }; |
| 349 | |
Andy Green | 8ef14c0 | 2016-05-14 10:00:21 +0800 | [diff] [blame] | 350 | if (!a->fresh_mount) |
| 351 | return 0; |
| 352 | |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 353 | if (!a->m.mountpoint || !a->m.origin) { |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 354 | lwsl_err("mountpoint and origin required\n"); |
| 355 | return 1; |
| 356 | } |
Andy Green | 8ef14c0 | 2016-05-14 10:00:21 +0800 | [diff] [blame] | 357 | lwsl_debug("adding mount %s\n", a->m.mountpoint); |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 358 | m = lwsws_align(a); |
| 359 | memcpy(m, &a->m, sizeof(*m)); |
| 360 | if (a->last) |
| 361 | a->last->mount_next = m; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 362 | |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 363 | for (n = 0; n < ARRAY_SIZE(mount_protocols); n++) |
| 364 | if (!strncmp(a->m.origin, mount_protocols[n], |
| 365 | strlen(mount_protocols[n]))) { |
| 366 | m->origin_protocol = n; |
| 367 | m->origin = a->m.origin + strlen(mount_protocols[n]); |
| 368 | break; |
| 369 | } |
| 370 | |
| 371 | if (n == ARRAY_SIZE(mount_protocols)) { |
| 372 | lwsl_err("unsupported protocol:// %s\n", a->m.origin); |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 373 | return 1; |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | a->p += sizeof(*m); |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 377 | if (!a->head) |
| 378 | a->head = m; |
| 379 | |
| 380 | a->last = m; |
Andy Green | 8ef14c0 | 2016-05-14 10:00:21 +0800 | [diff] [blame] | 381 | a->fresh_mount = 0; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /* we only match on the prepared path strings */ |
| 385 | if (!(reason & LEJP_FLAG_CB_IS_VALUE) || !ctx->path_match) |
| 386 | return 0; |
| 387 | |
| 388 | switch (ctx->path_match - 1) { |
| 389 | case LEJPVP_NAME: |
| 390 | a->info->vhost_name = a->p; |
| 391 | break; |
| 392 | case LEJPVP_PORT: |
| 393 | a->info->port = atoi(ctx->buf); |
| 394 | return 0; |
Andy Green | 1042b34 | 2016-04-14 11:50:05 +0800 | [diff] [blame] | 395 | case LEJPVP_INTERFACE: |
| 396 | a->info->iface = a->p; |
| 397 | break; |
Andy Green | a1ab201 | 2016-04-14 12:18:33 +0800 | [diff] [blame] | 398 | case LEJPVP_UNIXSKT: |
| 399 | if (arg_to_bool(ctx->buf)) |
| 400 | a->info->options |= LWS_SERVER_OPTION_UNIX_SOCK; |
| 401 | else |
| 402 | a->info->options &= ~(LWS_SERVER_OPTION_UNIX_SOCK); |
| 403 | return 0; |
Andy Green | 868b9f2 | 2016-04-14 12:37:21 +0800 | [diff] [blame] | 404 | case LEJPVP_STS: |
| 405 | if (arg_to_bool(ctx->buf)) |
| 406 | a->info->options |= LWS_SERVER_OPTION_STS; |
| 407 | else |
| 408 | a->info->options &= ~(LWS_SERVER_OPTION_STS); |
| 409 | return 0; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 410 | case LEJPVP_HOST_SSL_KEY: |
| 411 | a->info->ssl_private_key_filepath = a->p; |
| 412 | break; |
| 413 | case LEJPVP_HOST_SSL_CERT: |
| 414 | a->info->ssl_cert_filepath = a->p; |
| 415 | break; |
| 416 | case LEJPVP_HOST_SSL_CA: |
| 417 | a->info->ssl_ca_filepath = a->p; |
| 418 | break; |
Andy Green | 2f0bc93 | 2016-04-15 12:00:23 +0800 | [diff] [blame] | 419 | case LEJPVP_ACCESS_LOG: |
| 420 | a->info->log_filepath = a->p; |
| 421 | break; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 422 | case LEJPVP_MOUNTPOINT: |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 423 | a->m.mountpoint = a->p; |
Andy Green | 7a9970f | 2016-05-15 08:29:37 +0800 | [diff] [blame] | 424 | a->m.mountpoint_len = (unsigned char)strlen(ctx->buf); |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 425 | break; |
| 426 | case LEJPVP_ORIGIN: |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 427 | a->m.origin = a->p; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 428 | break; |
| 429 | case LEJPVP_DEFAULT: |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 430 | a->m.def = a->p; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 431 | break; |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 432 | case LEJPVP_MOUNT_CACHE_MAX_AGE: |
| 433 | a->m.cache_max_age = atoi(ctx->buf); |
| 434 | return 0; |
| 435 | case LEJPVP_MOUNT_CACHE_REUSE: |
| 436 | a->m.cache_reusable = arg_to_bool(ctx->buf); |
| 437 | return 0; |
| 438 | case LEJPVP_MOUNT_CACHE_REVALIDATE: |
| 439 | a->m.cache_revalidate = arg_to_bool(ctx->buf); |
| 440 | return 0; |
| 441 | case LEJPVP_MOUNT_CACHE_INTERMEDIARIES: |
| 442 | a->m.cache_intermediaries = arg_to_bool(ctx->buf);; |
| 443 | return 0; |
Andy Green | f5efa74 | 2016-04-13 11:42:53 +0800 | [diff] [blame] | 444 | case LEJPVP_CGI_TIMEOUT: |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 445 | a->m.cgi_timeout = atoi(ctx->buf); |
Andy Green | f5efa74 | 2016-04-13 11:42:53 +0800 | [diff] [blame] | 446 | return 0; |
Andy Green | b46e4a8 | 2016-04-12 16:26:03 +0800 | [diff] [blame] | 447 | case LEJPVP_KEEPALIVE_TIMEOUT: |
| 448 | a->info->keepalive_timeout = atoi(ctx->buf); |
| 449 | return 0; |
Andy Green | 6954daa | 2016-05-14 09:50:34 +0800 | [diff] [blame] | 450 | case LEJPVP_CIPHERS: |
| 451 | a->info->ssl_cipher_list = a->p; |
| 452 | break; |
| 453 | case LEJPVP_ECDH_CURVE: |
| 454 | a->info->ecdh_curve = a->p; |
| 455 | break; |
Andy Green | a5e73a1 | 2016-04-13 11:49:07 +0800 | [diff] [blame] | 456 | case LEJPVP_CGI_ENV: |
| 457 | mp_cgienv = lwsws_align(a); |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 458 | a->p += sizeof(*a->m.cgienv); |
Andy Green | 37098ae | 2016-04-08 13:25:34 +0800 | [diff] [blame] | 459 | |
Andy Green | 42e8b18 | 2016-04-22 08:53:49 +0800 | [diff] [blame] | 460 | mp_cgienv->next = a->m.cgienv; |
| 461 | a->m.cgienv = mp_cgienv; |
Andy Green | a5e73a1 | 2016-04-13 11:49:07 +0800 | [diff] [blame] | 462 | |
| 463 | n = lejp_get_wildcard(ctx, 0, a->p, a->end - a->p); |
| 464 | mp_cgienv->name = a->p; |
| 465 | a->p += n; |
| 466 | mp_cgienv->value = a->p; |
| 467 | mp_cgienv->options = NULL; |
| 468 | a->p += snprintf(a->p, a->end - a->p, "%s", ctx->buf); |
| 469 | *(a->p)++ = '\0'; |
| 470 | |
| 471 | lwsl_notice(" adding cgi-env '%s' = '%s'\n", mp_cgienv->name, |
| 472 | mp_cgienv->value); |
| 473 | |
| 474 | break; |
Andy Green | 37098ae | 2016-04-08 13:25:34 +0800 | [diff] [blame] | 475 | case LEJPVP_PROTOCOL_NAME_OPT: |
| 476 | /* this catches, eg, |
| 477 | * vhosts[].ws-protocols[].xxx-protocol.yyy-option |
| 478 | * ie, these are options attached to a protocol with { } |
| 479 | */ |
| 480 | pvo = lwsws_align(a); |
| 481 | a->p += sizeof(*a->pvo); |
| 482 | |
| 483 | n = lejp_get_wildcard(ctx, 1, a->p, a->end - a->p); |
| 484 | /* ie, enable this protocol, no options yet */ |
| 485 | pvo->next = a->pvo->options; |
| 486 | a->pvo->options = pvo; |
| 487 | pvo->name = a->p; |
| 488 | a->p += n; |
| 489 | pvo->value = a->p; |
| 490 | pvo->options = NULL; |
Andy Green | 37098ae | 2016-04-08 13:25:34 +0800 | [diff] [blame] | 491 | break; |
Andy Green | 8ef14c0 | 2016-05-14 10:00:21 +0800 | [diff] [blame] | 492 | |
| 493 | case LEJPVP_MOUNT_EXTRA_MIMETYPES: |
| 494 | a->pvo_em = lwsws_align(a); |
| 495 | a->p += sizeof(*a->pvo_em); |
| 496 | |
| 497 | n = lejp_get_wildcard(ctx, 0, a->p, a->end - a->p); |
| 498 | /* ie, enable this protocol, no options yet */ |
| 499 | a->pvo_em->next = a->m.extra_mimetypes; |
| 500 | a->m.extra_mimetypes = a->pvo_em; |
| 501 | a->pvo_em->name = a->p; |
| 502 | lwsl_notice(" adding extra-mimetypes %s -> %s\n", a->p, ctx->buf); |
| 503 | a->p += n; |
| 504 | a->pvo_em->value = a->p; |
| 505 | a->pvo_em->options = NULL; |
| 506 | break; |
| 507 | |
Andy Green | fb8be05 | 2016-05-12 19:39:29 +0800 | [diff] [blame] | 508 | case LEJPVP_ENABLE_CLIENT_SSL: |
| 509 | a->enable_client_ssl = arg_to_bool(ctx->buf); |
| 510 | return 0; |
Andy Green | 37098ae | 2016-04-08 13:25:34 +0800 | [diff] [blame] | 511 | |
Andy Green | 2dc7dde | 2016-06-03 21:19:40 +0800 | [diff] [blame] | 512 | case LEJPVP_NOIPV6: |
| 513 | if (arg_to_bool(ctx->buf)) |
| 514 | a->info->options |= LWS_SERVER_OPTION_DISABLE_IPV6; |
| 515 | else |
| 516 | a->info->options &= ~(LWS_SERVER_OPTION_DISABLE_IPV6); |
| 517 | return 0; |
| 518 | |
Andy Green | 011f915 | 2016-06-04 09:01:28 +0800 | [diff] [blame] | 519 | case LEJPVP_IPV6ONLY: |
| 520 | a->info->options |= LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY; |
| 521 | if (arg_to_bool(ctx->buf)) |
| 522 | a->info->options |= LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE; |
| 523 | else |
| 524 | a->info->options &= ~(LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE); |
| 525 | return 0; |
| 526 | |
Andy Green | 1ec8ba8 | 2016-06-10 08:37:26 +0800 | [diff] [blame] | 527 | case LEJPVP_SSL_OPTION_SET: |
| 528 | a->info->ssl_options_set |= atol(ctx->buf); |
| 529 | return 0; |
| 530 | case LEJPVP_SSL_OPTION_CLEAR: |
| 531 | a->info->ssl_options_clear |= atol(ctx->buf); |
| 532 | return 0; |
| 533 | |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 534 | default: |
| 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | a->p += snprintf(a->p, a->end - a->p, "%s", ctx->buf); |
| 539 | *(a->p)++ = '\0'; |
| 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | /* |
| 545 | * returns 0 = OK, 1 = can't open, 2 = parsing error |
| 546 | */ |
| 547 | |
| 548 | static int |
| 549 | lwsws_get_config(void *user, const char *f, const char * const *paths, |
| 550 | int count_paths, lejp_callback cb) |
| 551 | { |
| 552 | unsigned char buf[128]; |
| 553 | struct lejp_ctx ctx; |
| 554 | int n, m, fd; |
| 555 | |
| 556 | fd = open(f, O_RDONLY); |
| 557 | if (fd < 0) { |
| 558 | lwsl_err("Cannot open %s\n", f); |
Andy Green | 92b0d8a | 2016-05-22 07:01:35 +0800 | [diff] [blame] | 559 | return 2; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 560 | } |
| 561 | lwsl_info("%s: %s\n", __func__, f); |
| 562 | lejp_construct(&ctx, cb, user, paths, count_paths); |
| 563 | |
| 564 | do { |
| 565 | n = read(fd, buf, sizeof(buf)); |
| 566 | if (!n) |
| 567 | break; |
| 568 | |
Andy Green | 6e7b79b | 2016-04-09 09:32:01 +0800 | [diff] [blame] | 569 | m = (int)(signed char)lejp_parse(&ctx, buf, n); |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 570 | } while (m == LEJP_CONTINUE); |
| 571 | |
| 572 | close(fd); |
| 573 | n = ctx.line; |
| 574 | lejp_destruct(&ctx); |
| 575 | |
| 576 | if (m < 0) { |
Andy Green | 4bd5b96 | 2016-06-18 06:36:37 +0800 | [diff] [blame^] | 577 | lwsl_err("%s(%u): parsing error %d: %s\n", f, n, m, |
| 578 | parser_errs[-m]); |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 579 | return 2; |
| 580 | } |
| 581 | |
| 582 | return 0; |
| 583 | } |
| 584 | |
Andy Green | 0a18354 | 2016-04-09 07:22:40 +0800 | [diff] [blame] | 585 | #if defined(LWS_USE_LIBUV) && UV_VERSION_MAJOR > 0 |
| 586 | |
| 587 | static int |
| 588 | lwsws_get_config_d(void *user, const char *d, const char * const *paths, |
| 589 | int count_paths, lejp_callback cb) |
| 590 | { |
| 591 | uv_dirent_t dent; |
| 592 | uv_fs_t req; |
| 593 | char path[256]; |
| 594 | int ret = 0; |
| 595 | uv_loop_t loop; |
| 596 | |
| 597 | uv_loop_init(&loop); |
| 598 | |
| 599 | if (!uv_fs_scandir(&loop, &req, d, 0, NULL)) { |
| 600 | lwsl_err("Scandir on %s failed\n", d); |
Andy Green | 92b0d8a | 2016-05-22 07:01:35 +0800 | [diff] [blame] | 601 | return 2; |
Andy Green | 0a18354 | 2016-04-09 07:22:40 +0800 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | while (uv_fs_scandir_next(&req, &dent) != UV_EOF) { |
| 605 | snprintf(path, sizeof(path) - 1, "%s/%s", d, dent.name); |
| 606 | ret = lwsws_get_config(user, path, paths, count_paths, cb); |
| 607 | if (ret) |
| 608 | goto bail; |
| 609 | } |
| 610 | |
| 611 | bail: |
| 612 | uv_fs_req_cleanup(&req); |
| 613 | uv_loop_close(&loop); |
| 614 | |
| 615 | return ret; |
| 616 | } |
| 617 | |
| 618 | #else |
| 619 | |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 620 | #ifndef _WIN32 |
| 621 | static int filter(const struct dirent *ent) |
| 622 | { |
| 623 | if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) |
| 624 | return 0; |
| 625 | |
| 626 | return 1; |
| 627 | } |
| 628 | #endif |
| 629 | |
| 630 | static int |
| 631 | lwsws_get_config_d(void *user, const char *d, const char * const *paths, |
| 632 | int count_paths, lejp_callback cb) |
| 633 | { |
| 634 | #ifndef _WIN32 |
| 635 | struct dirent **namelist; |
| 636 | char path[256]; |
| 637 | int n, i, ret = 0; |
| 638 | |
| 639 | n = scandir(d, &namelist, filter, alphasort); |
| 640 | if (n < 0) { |
| 641 | lwsl_err("Scandir on %d failed\n", d); |
| 642 | } |
| 643 | |
| 644 | for (i = 0; i < n; i++) { |
| 645 | snprintf(path, sizeof(path) - 1, "%s/%s", d, |
| 646 | namelist[i]->d_name); |
| 647 | ret = lwsws_get_config(user, path, paths, count_paths, cb); |
| 648 | if (ret) { |
| 649 | while (i++ < n) |
| 650 | free(namelist[i]); |
| 651 | goto bail; |
| 652 | } |
| 653 | free(namelist[i]); |
| 654 | } |
| 655 | |
| 656 | bail: |
| 657 | free(namelist); |
| 658 | |
| 659 | return ret; |
| 660 | #else |
| 661 | return 0; |
| 662 | #endif |
| 663 | } |
| 664 | |
Andy Green | 0a18354 | 2016-04-09 07:22:40 +0800 | [diff] [blame] | 665 | #endif |
| 666 | |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 667 | int |
| 668 | lwsws_get_config_globals(struct lws_context_creation_info *info, const char *d, |
| 669 | char **cs, int *len) |
| 670 | { |
| 671 | struct jpargs a; |
Andy Green | cae57ad | 2016-05-02 10:03:25 +0800 | [diff] [blame] | 672 | const char * const *old = info->plugin_dirs; |
Andy Green | 92b0d8a | 2016-05-22 07:01:35 +0800 | [diff] [blame] | 673 | char dd[128]; |
Andy Green | cae57ad | 2016-05-02 10:03:25 +0800 | [diff] [blame] | 674 | |
| 675 | memset(&a, 0, sizeof(a)); |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 676 | |
| 677 | a.info = info; |
| 678 | a.p = *cs; |
Andy Green | a5e73a1 | 2016-04-13 11:49:07 +0800 | [diff] [blame] | 679 | a.end = (a.p + *len) - 1; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 680 | a.valid = 0; |
| 681 | |
Andy Green | cae57ad | 2016-05-02 10:03:25 +0800 | [diff] [blame] | 682 | lwsws_align(&a); |
| 683 | info->plugin_dirs = (void *)a.p; |
| 684 | a.plugin_dirs = (void *)a.p; /* writeable version */ |
| 685 | a.p += MAX_PLUGIN_DIRS * sizeof(void *); |
| 686 | |
| 687 | /* copy any default paths */ |
| 688 | |
| 689 | while (old && *old) { |
| 690 | a.plugin_dirs[a.count_plugin_dirs++] = *old; |
| 691 | old++; |
| 692 | } |
| 693 | |
Andy Green | 92b0d8a | 2016-05-22 07:01:35 +0800 | [diff] [blame] | 694 | snprintf(dd, sizeof(dd) - 1, "%s/conf", d); |
| 695 | if (lwsws_get_config(&a, dd, paths_global, |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 696 | ARRAY_SIZE(paths_global), lejp_globals_cb) > 1) |
| 697 | return 1; |
Andy Green | 92b0d8a | 2016-05-22 07:01:35 +0800 | [diff] [blame] | 698 | snprintf(dd, sizeof(dd) - 1, "%s/conf.d", d); |
| 699 | if (lwsws_get_config_d(&a, dd, paths_global, |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 700 | ARRAY_SIZE(paths_global), lejp_globals_cb) > 1) |
| 701 | return 1; |
| 702 | |
Andy Green | cae57ad | 2016-05-02 10:03:25 +0800 | [diff] [blame] | 703 | a.plugin_dirs[a.count_plugin_dirs] = NULL; |
| 704 | |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 705 | *cs = a.p; |
| 706 | *len = a.end - a.p; |
| 707 | |
| 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | int |
| 712 | lwsws_get_config_vhosts(struct lws_context *context, |
| 713 | struct lws_context_creation_info *info, const char *d, |
| 714 | char **cs, int *len) |
| 715 | { |
| 716 | struct jpargs a; |
Andy Green | 92b0d8a | 2016-05-22 07:01:35 +0800 | [diff] [blame] | 717 | char dd[128]; |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 718 | |
Andy Green | cae57ad | 2016-05-02 10:03:25 +0800 | [diff] [blame] | 719 | memset(&a, 0, sizeof(a)); |
| 720 | |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 721 | a.info = info; |
| 722 | a.p = *cs; |
| 723 | a.end = a.p + *len; |
| 724 | a.valid = 0; |
| 725 | a.context = context; |
| 726 | a.protocols = info->protocols; |
| 727 | a.extensions = info->extensions; |
| 728 | |
Andy Green | 92b0d8a | 2016-05-22 07:01:35 +0800 | [diff] [blame] | 729 | snprintf(dd, sizeof(dd) - 1, "%s/conf", d); |
| 730 | if (lwsws_get_config(&a, dd, paths_vhosts, |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 731 | ARRAY_SIZE(paths_vhosts), lejp_vhosts_cb) > 1) |
| 732 | return 1; |
Andy Green | 92b0d8a | 2016-05-22 07:01:35 +0800 | [diff] [blame] | 733 | snprintf(dd, sizeof(dd) - 1, "%s/conf.d", d); |
| 734 | if (lwsws_get_config_d(&a, dd, paths_vhosts, |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 735 | ARRAY_SIZE(paths_vhosts), lejp_vhosts_cb) > 1) |
| 736 | return 1; |
| 737 | |
| 738 | *cs = a.p; |
| 739 | *len = a.end - a.p; |
| 740 | |
Andy Green | 92b0d8a | 2016-05-22 07:01:35 +0800 | [diff] [blame] | 741 | if (!a.any_vhosts) { |
| 742 | lwsl_err("Need at least one vhost\n"); |
| 743 | return 1; |
| 744 | } |
| 745 | |
Andy Green | cd0c696 | 2016-03-28 10:12:37 +0800 | [diff] [blame] | 746 | lws_finalize_startup(context); |
| 747 | |
| 748 | return 0; |
| 749 | } |