ret_t cherokee_logger_writer_new (cherokee_logger_writer_t **writer) { CHEROKEE_NEW_STRUCT(n,logger_writer); INIT_LIST_HEAD (&n->listed); n->type = cherokee_logger_writer_syslog; n->fd = -1; n->max_bufsize = DEFAULT_LOGGER_MAX_BUFSIZE; cherokee_buffer_init (&n->command); cherokee_buffer_init (&n->filename); cherokee_buffer_init (&n->buffer); cherokee_buffer_ensure_size (&n->buffer, n->max_bufsize); n->priv = malloc (sizeof(priv_t)); if (n->priv == NULL) { cherokee_buffer_mrproper (&n->buffer); free(n); return ret_nomem; } CHEROKEE_MUTEX_INIT (&PRIV(n)->mutex, NULL); n->initialized = false; *writer = n; return ret_ok; }
ret_t cherokee_handler_proxy_conn_new (cherokee_handler_proxy_conn_t **pconn) { CHEROKEE_NEW_STRUCT (n, handler_proxy_conn); /* Socket stuff */ cherokee_socket_init (&n->socket); n->post.sent = 0; n->post.do_buf_sent = true; cherokee_buffer_init (&n->post.buf_temp); cherokee_buffer_init (&n->header_in_raw); cherokee_buffer_ensure_size (&n->header_in_raw, 512); n->poll_ref = NULL; n->keepalive_in = false; n->size_in = 0; n->sent_out = 0; n->enc = pconn_enc_none; *pconn = n; return ret_ok; }
ret_t cherokee_plugin_loader_init (cherokee_plugin_loader_t *loader) { ret_t ret; ret = cherokee_avl_init (&loader->table); if (unlikely(ret < ret_ok)) return ret; /* Plug-in dir */ ret = cherokee_buffer_init (&loader->module_dir); if (unlikely(ret < ret_ok)) return ret; cherokee_buffer_add_str (&loader->module_dir, CHEROKEE_PLUGINDIR); /* Plug-in dependencies dir */ ret = cherokee_buffer_init (&loader->deps_dir); if (unlikely(ret < ret_ok)) return ret; cherokee_buffer_add_str (&loader->deps_dir, CHEROKEE_DEPSDIR); ret = load_static_linked_modules (loader); if (unlikely(ret < ret_ok)) return ret; return ret_ok; }
ret_t cherokee_request_header_init (cherokee_request_header_t *request) { ret_t ret; /* Init the node list information */ INIT_LIST_HEAD (LIST(&request->list_node)); /* Set default values */ request->method = http_get; request->version = http_version_11; request->auth = http_auth_nothing; request->proxy = false; request->keepalive = true; request->pipeline = 1; request->post_len = 0; ret = cherokee_url_init (&request->url); if (unlikely(ret < ret_ok)) return ret; cherokee_buffer_init (&request->extra_headers); cherokee_buffer_init (&request->user); cherokee_buffer_init (&request->password); return ret_ok; }
ret_t cherokee_handler_ssi_new (cherokee_handler_t **hdl, cherokee_connection_t *cnt, cherokee_module_props_t *props) { CHEROKEE_NEW_STRUCT (n, handler_ssi); /* Init the base class object */ cherokee_handler_init_base (HANDLER(n), cnt, HANDLER_PROPS(props), PLUGIN_INFO_HANDLER_PTR(ssi)); MODULE(n)->free = (module_func_free_t) cherokee_handler_ssi_free; MODULE(n)->init = (handler_func_init_t) cherokee_handler_ssi_init; HANDLER(n)->step = (handler_func_step_t) cherokee_handler_ssi_step; HANDLER(n)->add_headers = (handler_func_add_headers_t) cherokee_handler_ssi_add_headers; /* Supported features */ HANDLER(n)->support = hsupport_nothing; /* Init */ n->mime = NULL; cherokee_buffer_init (&n->dir); cherokee_buffer_init (&n->source); cherokee_buffer_init (&n->render); /* Return the object */ *hdl = HANDLER(n); return ret_ok; }
ret_t cherokee_handler_dbslayer_configure (cherokee_config_node_t *conf, cherokee_server_t *srv, cherokee_module_props_t **_props) { ret_t ret; cherokee_list_t *i; cherokee_handler_dbslayer_props_t *props; /* Instance a new property object */ if (*_props == NULL) { CHEROKEE_NEW_STRUCT (n, handler_dbslayer_props); cherokee_handler_props_init_base (HANDLER_PROPS(n), MODULE_PROPS_FREE(props_free)); n->balancer = NULL; cherokee_buffer_init (&n->user); cherokee_buffer_init (&n->password); cherokee_buffer_init (&n->db); *_props = MODULE_PROPS(n); } props = PROP_DBSLAYER(*_props); /* Parse the configuration tree */ cherokee_config_node_foreach (i, conf) { cherokee_config_node_t *subconf = CONFIG_NODE(i); if (equal_buf_str (&subconf->key, "balancer")) { ret = cherokee_balancer_instance (&subconf->val, subconf, srv, &props->balancer); if (ret != ret_ok) return ret; } else if (equal_buf_str (&subconf->key, "user")) { cherokee_buffer_clean (&props->user); cherokee_buffer_add_buffer (&props->user, &subconf->val); } else if (equal_buf_str (&subconf->key, "password")) { cherokee_buffer_clean (&props->password); cherokee_buffer_add_buffer (&props->password, &subconf->val); } else if (equal_buf_str (&subconf->key, "db")) { cherokee_buffer_clean (&props->db); cherokee_buffer_add_buffer (&props->db, &subconf->val); } else if (equal_buf_str (&subconf->key, "lang")) { ret = cherokee_dwriter_lang_to_type (&subconf->val, &props->lang); if (ret != ret_ok) { LOG_CRITICAL (CHEROKEE_ERROR_HANDLER_DBSLAYER_LANG, subconf->val.buf); return ret_error; } } }
ret_t cherokee_header_op_new (cherokee_header_op_t **op) { CHEROKEE_NEW_STRUCT (n, header_op); INIT_LIST_HEAD (&n->entry); cherokee_buffer_init (&n->header); cherokee_buffer_init (&n->value); *op = n; return ret_ok; }
/* Entries */ static ret_t entry_new (cherokee_resolv_cache_entry_t **entry) { CHEROKEE_NEW_STRUCT(n, resolv_cache_entry); n->addr = NULL; cherokee_buffer_init (&n->ip_str); cherokee_buffer_init (&n->ip_str_all); *entry = n; return ret_ok; }
ret_t cherokee_source_init (cherokee_source_t *src) { cherokee_buffer_init (&src->original); cherokee_buffer_init (&src->unix_socket); cherokee_buffer_init (&src->host); src->type = source_host; src->port = -1; src->free = NULL; src->addr_current = NULL; return ret_ok; }
ret_t cherokee_handler_zeromq_new (cherokee_handler_t **hdl, void *cnt, cherokee_module_props_t *props) { CHEROKEE_NEW_STRUCT (n, handler_zeromq); /* Init the base class object */ cherokee_handler_init_base (HANDLER(n), cnt, HANDLER_PROPS(props), PLUGIN_INFO_HANDLER_PTR(zeromq)); MODULE(n)->init = (handler_func_init_t) cherokee_handler_zeromq_init; MODULE(n)->free = (module_func_free_t) zeromq_free; HANDLER(n)->read_post = (handler_func_read_post_t) cherokee_handler_zeromq_read_post; HANDLER(n)->add_headers = (handler_func_add_headers_t) cherokee_handler_zeromq_add_headers; HANDLER(n)->step = (handler_func_step_t) cherokee_handler_zeromq_step; /* Supported features */ HANDLER(n)->support = hsupport_nothing; cherokee_buffer_init (&n->output); cherokee_buffer_ensure_size (&n->output, 2097152); n->encoder = NULL; *hdl = HANDLER(n); return ret_ok; }
ret_t cherokee_handler_admin_new (cherokee_handler_t **hdl, void *cnt, cherokee_module_props_t *props) { CHEROKEE_NEW_STRUCT (n, handler_admin); /* Init the base class object */ cherokee_handler_init_base (HANDLER(n), cnt, HANDLER_PROPS(props), PLUGIN_INFO_HANDLER_PTR(admin)); MODULE(n)->init = (module_func_init_t) cherokee_handler_admin_init; MODULE(n)->free = (module_func_free_t) cherokee_handler_admin_free; HANDLER(n)->add_headers = (handler_func_add_headers_t) cherokee_handler_admin_add_headers; HANDLER(n)->read_post = (handler_func_read_post_t) cherokee_handler_admin_read_post; HANDLER(n)->step = (handler_func_step_t) cherokee_handler_admin_step; /* Supported features */ HANDLER(n)->support = hsupport_nothing; cherokee_buffer_init (&n->reply); /* Configure the data writer object */ cherokee_dwriter_init (&n->dwriter, THREAD_TMP_BUF1(CONN_THREAD(cnt))); cherokee_dwriter_set_buffer (&n->dwriter, &n->reply); /* Return the object */ *hdl = HANDLER(n); return ret_ok; }
ret_t cherokee_handler_error_new (cherokee_handler_t **hdl, cherokee_connection_t *cnt, cherokee_module_props_t *props) { ret_t ret; CHEROKEE_NEW_STRUCT (n, handler_error); /* Init the base class object */ cherokee_handler_init_base (HANDLER(n), cnt, HANDLER_PROPS(props), PLUGIN_INFO_HANDLER_PTR(error)); /* Supported features */ HANDLER(n)->support = hsupport_error; MODULE(n)->init = (handler_func_init_t) cherokee_handler_error_init; MODULE(n)->free = (module_func_free_t) cherokee_handler_error_free; HANDLER(n)->step = (handler_func_step_t) cherokee_handler_error_step; HANDLER(n)->add_headers = (handler_func_add_headers_t) cherokee_handler_error_add_headers; /* Init */ ret = cherokee_buffer_init (&n->content); if (unlikely(ret < ret_ok)) return ret; /* Return the object */ *hdl = HANDLER(n); return ret_ok; }
ret_t cherokee_rule_header_new (cherokee_rule_header_t **rule) { CHEROKEE_NEW_STRUCT (n, rule_header); /* Parent class constructor */ cherokee_rule_init_base (RULE(n), PLUGIN_INFO_PTR(header)); /* Virtual methods */ RULE(n)->match = (rule_func_match_t) match; RULE(n)->configure = (rule_func_configure_t) configure; MODULE(n)->free = (module_func_free_t) _free; /* Properties */ n->pcre = NULL; n->type = rule_header_type_regex; cherokee_buffer_init (&n->match); *rule = n; return ret_ok; }
ret_t cherokee_url_init (cherokee_url_t *url) { ret_t ret; /* New buffer objects */ ret = cherokee_buffer_init (&url->host); if (unlikely(ret < ret_ok)) return ret; ret = cherokee_buffer_init (&url->request); if (unlikely(ret < ret_ok)) return ret; /* Set default values */ url->port = 80; return ret_ok; }
ret_t cherokee_handler_proxy_hosts_init (cherokee_handler_proxy_hosts_t *hosts) { CHEROKEE_MUTEX_INIT (&hosts->hosts_mutex, CHEROKEE_MUTEX_FAST); cherokee_avl_init (&hosts->hosts); cherokee_buffer_init (&hosts->tmp); return ret_ok; }
ret_t cherokee_validator_file_props_init_base (cherokee_validator_file_props_t *props, module_func_props_free_t free_func) { props->password_path_type = val_path_full; cherokee_buffer_init (&props->password_file); return cherokee_validator_props_init_base (VALIDATOR_PROPS(props), free_func); }
ret_t cherokee_handler_zeromq_configure (cherokee_config_node_t *conf, cherokee_server_t *srv, cherokee_module_props_t **_props) { ret_t ret; cherokee_list_t *i; cherokee_handler_zeromq_props_t *props; cherokee_plugin_info_t *info = NULL; /* Instance a new property object */ if (*_props == NULL) { CHEROKEE_NEW_STRUCT (n, handler_zeromq_props); cherokee_handler_props_init_base (HANDLER_PROPS(n), MODULE_PROPS_FREE(props_free)); cherokee_buffer_init (&n->endpoint); n->io_threads = 1; CHEROKEE_MUTEX_INIT (&n->mutex, CHEROKEE_MUTEX_FAST); *_props = MODULE_PROPS(n); } props = PROP_ZEROMQ(*_props); /* Voodoo to get our own backend gzipper */ ret = cherokee_plugin_loader_get (&srv->loader, "gzip", &info); if (ret != ret_ok) { return ret; } /* Parse the configuration tree */ cherokee_config_node_foreach (i, conf) { cherokee_config_node_t *subconf = CONFIG_NODE(i); if (equal_buf_str (&subconf->key, "endpoint")) { cherokee_buffer_clean (&props->endpoint); cherokee_buffer_add_buffer (&props->endpoint, &subconf->val); } else if (equal_buf_str (&subconf->key, "io_threads")) { props->io_threads = atoi(subconf->val.buf); } else if (equal_buf_str (&subconf->key, "encoder") && info->configure) { encoder_func_configure_t configure = info->configure; props->encoder_props = NULL; ret = configure (subconf, srv, (cherokee_module_props_t **)&props->encoder_props); if (ret != ret_ok) { return ret; } props->encoder_props->instance_func = PLUGIN_INFO(info)->instance; } }
ret_t cherokee_shm_init (cherokee_shm_t *shm) { shm->len = 0; shm->mem = NULL; cherokee_buffer_init (&shm->name); return ret_ok; }
ret_t cherokee_logger_ncsa_init_base (cherokee_logger_ncsa_t *logger, cherokee_virtual_server_t *vsrv, cherokee_config_node_t *config) { ret_t ret; cherokee_config_node_t *subconf; static int callback_init = 0; /* Init the local buffers */ cherokee_buffer_init (&logger->now_dtm); cherokee_buffer_init (&logger->referer); cherokee_buffer_init (&logger->useragent); cherokee_buffer_ensure_size (&logger->now_dtm, 64); cherokee_buffer_ensure_size (&logger->referer, 1024); cherokee_buffer_ensure_size (&logger->useragent, 512); /* Init the logger writer */ ret = cherokee_config_node_get (config, "access", &subconf); if (ret != ret_ok) { LOG_CRITICAL (CHEROKEE_ERROR_LOGGER_NO_KEY, "access"); return ret_error; } ret = cherokee_server_get_log_writer (VSERVER_SRV(vsrv), subconf, &logger->writer_access); if (ret != ret_ok) { return ret_error; } /* Callback init */ if (callback_init == 0) { cherokee_buffer_init (&now); cherokee_bogotime_add_callback (bogotime_callback, logger, 1); } return ret_ok; }
ret_t cherokee_validator_init_base (cherokee_validator_t *validator, cherokee_validator_props_t *props, cherokee_plugin_info_validator_t *info) { cherokee_module_init_base (MODULE(validator), MODULE_PROPS(props), PLUGIN_INFO(info)); validator->check = NULL; cherokee_buffer_init (&validator->user); cherokee_buffer_init (&validator->passwd); cherokee_buffer_init (&validator->realm); cherokee_buffer_init (&validator->response); cherokee_buffer_init (&validator->uri); cherokee_buffer_init (&validator->qop); cherokee_buffer_init (&validator->nonce); cherokee_buffer_init (&validator->cnonce); cherokee_buffer_init (&validator->algorithm); cherokee_buffer_init (&validator->nc); return ret_ok; }
static int openssl_sni_servername_cb (SSL *ssl, int *ad, void *arg) { ret_t ret; int re; const char *servername; cherokee_connection_t *conn; cherokee_buffer_t tmp; cherokee_server_t *srv = SRV(arg); cherokee_virtual_server_t *vsrv = NULL; UNUSED(ad); /* Get the pointer to the socket */ conn = SSL_get_app_data (ssl); if (unlikely (conn == NULL)) { LOG_ERROR (CHEROKEE_ERROR_SSL_SOCKET, ssl); return SSL_TLSEXT_ERR_ALERT_FATAL; } cherokee_buffer_init(&tmp); cherokee_buffer_ensure_size(&tmp, 40); /* Read the SNI server name */ servername = SSL_get_servername (ssl, TLSEXT_NAMETYPE_host_name); if (servername == NULL) { /* Set the server name to the IP address if we couldn't get the host name via SNI */ cherokee_socket_ntop (&conn->socket, tmp.buf, tmp.size); TRACE (ENTRIES, "No SNI: Did not provide a server name, using IP='%s' as servername.\n", tmp.buf); } else { cherokee_buffer_add (&tmp, servername, strlen(servername)); TRACE (ENTRIES, "SNI: Switching to servername='%s'\n", servername); } /* Look up and change the vserver */ ret = cherokee_cryptor_libssl_find_vserver(ssl, srv, &tmp, conn); if (ret != ret_ok) { re = SSL_TLSEXT_ERR_NOACK; } else { re = SSL_TLSEXT_ERR_OK; } cherokee_buffer_mrproper (&tmp); return re; }
ret_t cherokee_post_init (cherokee_post_t *post) { post->len = 0; post->has_info = false; post->encoding = post_enc_regular; post->read_header_phase = cherokee_post_read_header_init; post->send.phase = cherokee_post_send_phase_read; post->send.read = 0; post->chunked.last = false; post->chunked.processed = 0; post->chunked.retransmit = false; cherokee_buffer_init (&post->send.buffer); cherokee_buffer_init (&post->chunked.buffer); cherokee_buffer_init (&post->read_header_100cont); cherokee_buffer_init (&post->header_surplus); cherokee_buffer_init (&post->progress_id); return ret_ok; }
ret_t cherokee_downloader_init (cherokee_downloader_t *n) { ret_t ret; /* Build */ ret = cherokee_request_header_init (&n->request); if (unlikely(ret != ret_ok)) return ret; ret = cherokee_buffer_init (&n->request_header); if (unlikely(ret != ret_ok)) return ret; ret = cherokee_buffer_init (&n->reply_header); if (unlikely(ret != ret_ok)) return ret; ret = cherokee_buffer_init (&n->body); if (unlikely(ret != ret_ok)) return ret; ret = cherokee_socket_init (&n->socket); if (unlikely(ret != ret_ok)) return ret; ret = cherokee_header_new (&n->header, header_type_response); if (unlikely(ret != ret_ok)) return ret; cherokee_buffer_init (&n->proxy); n->proxy_port = 0; cherokee_buffer_init (&n->tmp1); cherokee_buffer_init (&n->tmp2); cherokee_buffer_init (&n->post); /* Init the properties */ n->phase = downloader_phase_init; /* Lengths */ n->content_length = 0; /* Info */ n->info.request_sent = 0; n->info.headers_recv = 0; n->info.post_sent = 0; n->info.body_recv = 0; n->status = downloader_status_none; return ret_ok; }
ret_t cherokee_mime_entry_new (cherokee_mime_entry_t **mentry) { CHEROKEE_NEW_STRUCT(n, mime_entry); INIT_LIST_HEAD(&n->base); n->maxage = -1; n->maxage_set = false; cherokee_buffer_init (&n->mime_name); *mentry = n; return ret_ok; }
static ret_t configure_rewrite_entry (cherokee_list_t *list, cherokee_config_node_t *conf, cherokee_regex_table_t *regexs) { ret_t ret; cherokee_regex_entry_t *n; cherokee_buffer_t *substring; cherokee_boolean_t hidden = true; pcre *re = NULL; cherokee_buffer_t *regex = NULL; TRACE(ENTRIES, "Converting rewrite rule '%s'\n", conf->key.buf); /* Query conf */ cherokee_config_node_read_bool (conf, "show", &hidden); hidden = !hidden; ret = cherokee_config_node_read (conf, "regex", ®ex); if (ret == ret_ok) { ret = cherokee_regex_table_get (regexs, regex->buf, (void **)&re); if (ret != ret_ok) return ret; } ret = cherokee_config_node_read (conf, "substring", &substring); if (ret != ret_ok) return ret; /* New RegEx */ n = (cherokee_regex_entry_t *) malloc(sizeof(cherokee_regex_entry_t)); if (unlikely (n == NULL)) return ret_nomem; INIT_LIST_HEAD (&n->listed); n->re = re; n->hidden = hidden; cherokee_buffer_init (&n->subs); cherokee_buffer_add_buffer (&n->subs, substring); /* Add the list */ cherokee_list_add_tail (&n->listed, list); return ret_ok; }
/* Private type */ static ret_t file_entry_new (file_entry_t **file, cuint_t extra_size) { file_entry_t *n; n = (file_entry_t *) malloc (sizeof(file_entry_t) + extra_size); if (unlikely(n == NULL)) { return ret_nomem; } INIT_LIST_HEAD (&n->list_node); cherokee_buffer_init (&n->realpath); *file = n; return ret_ok; }
static ret_t init_tmp_dir (void) { ret_t ret; cherokee_buffer_init (&cherokee_tmp_dir); cherokee_tmp_dir_copy (&cherokee_tmp_dir); cherokee_buffer_add_str (&cherokee_tmp_dir, "/cherokee.XXXXXXXXXXX"); ret = cherokee_mkdtemp (cherokee_tmp_dir.buf); if (unlikely (ret != ret_ok)) { return ret_error; } return ret_ok; }
/* Private type */ static ret_t file_match_new (file_match_t **file) { file_match_t *n; n = (file_match_t *) malloc (sizeof(file_match_t)); if (unlikely(n == NULL)) { return ret_nomem; } INIT_LIST_HEAD (&n->list_node); cherokee_buffer_init (&n->filename); n->is_wildcard = false; *file = n; return ret_ok; }
ret_t cherokee_handler_cgi_new (cherokee_handler_t **hdl, void *cnt, cherokee_module_props_t *props) { int i; CHEROKEE_NEW_STRUCT (n, handler_cgi); /* Init the base class */ cherokee_handler_cgi_base_init (HDL_CGI_BASE(n), cnt, PLUGIN_INFO_HANDLER_PTR(cgi), HANDLER_PROPS(props), cherokee_handler_cgi_add_env_pair, read_from_cgi); /* Virtual methods */ MODULE(n)->init = (module_func_init_t) cherokee_handler_cgi_init; MODULE(n)->free = (module_func_free_t) cherokee_handler_cgi_free; HANDLER(n)->read_post = (handler_func_read_post_t) cherokee_handler_cgi_read_post; /* Virtual methods: implemented by handler_cgi_base */ HANDLER(n)->add_headers = (handler_func_add_headers_t) cherokee_handler_cgi_base_add_headers; HANDLER(n)->step = (handler_func_step_t) cherokee_handler_cgi_base_step; /* Init */ n->pipeInput = -1; n->pipeOutput = -1; #ifdef _WIN32 n->process = NULL; n->thread = NULL; cherokee_buffer_init (&n->envp); #else n->pid = -1; n->envp_last = 0; for (i=0; i<ENV_VAR_NUM; i++) n->envp[i] = NULL; #endif /* Return the object */ *hdl = HANDLER(n); return ret_ok; }
ret_t cherokee_handler_secdownload_configure (cherokee_config_node_t *conf, cherokee_server_t *srv, cherokee_module_props_t **_props) { ret_t ret; cherokee_handler_secdownload_props_t *props; if (*_props == NULL) { CHEROKEE_NEW_STRUCT (n, handler_secdownload_props); cherokee_handler_props_init_base (HANDLER_PROPS(n), MODULE_PROPS_FREE(cherokee_handler_secdownload_props_free)); cherokee_buffer_init (&n->secret); n->timeout = 60; *_props = MODULE_PROPS(n); } props = PROP_SECDOWN(*_props); /* Parse 'file' parameters */ props->props_file = NULL; ret = cherokee_handler_file_configure (conf, srv, (cherokee_module_props_t **)&props->props_file); if ((ret != ret_ok) && (ret != ret_deny)) return ret; /* Properties */ ret = cherokee_config_node_copy (conf, "secret", &props->secret); if (ret != ret_ok) { LOG_CRITICAL_S (CHEROKEE_ERROR_HANDLER_SECDOWN_SECRET); return ret_error; } cherokee_config_node_read_int (conf, "timeout", (int*)&props->timeout); return ret_ok; }