Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
static ret_t
local_file_exists (cherokee_rule_extensions_t *rule,
		   cherokee_connection_t      *conn,
		   cherokee_config_entry_t    *ret_conf)
{
	ret_t                     ret;
	struct stat              *info;
	struct stat               nocache_info;
	cherokee_boolean_t        is_file;
	cherokee_iocache_entry_t *io_entry      = NULL;
	cherokee_server_t        *srv           = CONN_SRV(conn);
	cherokee_buffer_t        *tmp           = THREAD_TMP_BUF1(CONN_THREAD(conn));

	UNUSED(rule);

	/* Build the full path
	 */
	cherokee_buffer_clean (tmp);

	if (ret_conf->document_root != NULL) {
		/* A previous non-final rule set a custom document root */
		cherokee_buffer_add_buffer (tmp, ret_conf->document_root);
	} else {
		cherokee_buffer_add_buffer (tmp, &conn->local_directory);
	}

	cherokee_buffer_add_str    (tmp, "/");
	cherokee_buffer_add_buffer (tmp, &conn->request);

	/* Check the local file
	 */
	ret = cherokee_io_stat (srv->iocache, tmp, rule->use_iocache,
				&nocache_info, &io_entry, &info);

	is_file = S_ISREG(info->st_mode);

	if (io_entry) {
		cherokee_iocache_entry_unref (&io_entry);
	}

	/* Report and return
	 */
	if (ret != ret_ok) {
		TRACE(ENTRIES, "Rule extensions: almost matched '%s', but file does not exist\n", tmp->buf);
		return ret_not_found;
	}

	if (! is_file) {
		TRACE(ENTRIES, "Rule extensions: almost matched '%s', but it is not a file\n", tmp->buf);
		return ret_not_found;
	}

	return ret_ok;
}