[Cherokee-commits] [3337] cherokee/trunk:
SVN at cherokee-project.com
SVN at cherokee-project.com
Sat Jun 13 19:56:59 CEST 2009
Revision: 3337
http://svn.cherokee-project.com/changeset/3337
Author: alo
Date: 2009-06-13 19:56:59 +0200 (Sat, 13 Jun 2009)
Log Message:
-----------
Modified Paths:
--------------
cherokee/trunk/ChangeLog
cherokee/trunk/admin/ModuleExists.py
cherokee/trunk/cherokee/rule_exists.c
cherokee/trunk/cherokee/rule_exists.h
Modified: cherokee/trunk/ChangeLog
===================================================================
--- cherokee/trunk/ChangeLog 2009-06-13 17:38:35 UTC (rev 3336)
+++ cherokee/trunk/ChangeLog 2009-06-13 17:56:59 UTC (rev 3337)
@@ -1,5 +1,9 @@
2009-06-13 Alvaro Lopez Ortega <alvaro at octality.com>
+ * cherokee/rule_exists.h, cherokee/rule_exists.c,
+ admin/ModuleExists.py: Add a new option to the exists rule, so it
+ checks for index file when a local directory is found.
+
* cherokee/handler_common.c, cherokee/virtual_server.c: The index
files list entries are now buffers instead of char*.
Modified: cherokee/trunk/admin/ModuleExists.py
===================================================================
--- cherokee/trunk/admin/ModuleExists.py 2009-06-13 17:38:35 UTC (rev 3336)
+++ cherokee/trunk/admin/ModuleExists.py 2009-06-13 17:56:59 UTC (rev 3337)
@@ -6,10 +6,11 @@
# For gettext
N_ = lambda x: x
-NOTE_EXISTS = N_("Comma separated list of files. Rule applies if one exists.")
-NOTE_IOCACHE = N_("Uses cache during file detection. Disable if directory contents change frequently. Enable otherwise.")
-NOTE_ANY = N_("Match the request if any file exists.")
-NOTE_ONLY_FILES = N_("Only match regular files. If unset directories will be matched as well.")
+NOTE_EXISTS = N_("Comma separated list of files. Rule applies if one exists.")
+NOTE_IOCACHE = N_("Uses cache during file detection. Disable if directory contents change frequently. Enable otherwise.")
+NOTE_ANY = N_("Match the request if any file exists.")
+NOTE_ONLY_FILES = N_("Only match regular files. If unset directories will be matched as well.")
+NOTE_INDEX_FILES = N_("If a directory is request, check the index files inside it.")
OPTIONS = [('0', _('Match a specific list of files')),
('1', _('Match any file'))]
@@ -24,7 +25,8 @@
# Special case: there is a check in the rule
self.checks = ['%s!iocache'%(self._prefix),
'%s!match_any'%(self._prefix),
- '%s!match_only_files'%(self._prefix)]
+ '%s!match_only_files'%(self._prefix),
+ '%s!match_index_files'%(self._prefix)]
def _op_render (self):
if self._prefix.startswith('tmp!'):
@@ -55,7 +57,8 @@
if specific_file:
self.AddPropEntry (table, _('Files'), '%s!exists'%(self._prefix), _(NOTE_EXISTS))
self.AddPropCheck (table, _('Use I/O cache'), '%s!iocache'%(self._prefix), False, _(NOTE_IOCACHE))
- self.AddPropCheck (table, _('Only match files'), '%s!match_only_files'%(self._prefix), True, _(NOTE_ONLY_FILES))
+ self.AddPropCheck (table, _('Only match files'), '%s!match_only_files'%(self._prefix), True, _(NOTE_ONLY_FILES))
+ self.AddPropCheck (table, _('If dir, check index files'),'%s!match_index_files'%(self._prefix), True, _(NOTE_INDEX_FILES))
return str(table)
def _op_apply_changes (self, uri, post):
Modified: cherokee/trunk/cherokee/rule_exists.c
===================================================================
--- cherokee/trunk/cherokee/rule_exists.c 2009-06-13 17:38:35 UTC (rev 3336)
+++ cherokee/trunk/cherokee/rule_exists.c 2009-06-13 17:56:59 UTC (rev 3337)
@@ -82,9 +82,10 @@
UNUSED(vsrv);
- cherokee_config_node_read_bool (conf, "iocache", &rule->use_iocache);
- cherokee_config_node_read_bool (conf, "match_any", &rule->match_any);
- cherokee_config_node_read_bool (conf, "match_only_files", &rule->match_only_files);
+ cherokee_config_node_read_bool (conf, "iocache", &rule->use_iocache);
+ cherokee_config_node_read_bool (conf, "match_any", &rule->match_any);
+ cherokee_config_node_read_bool (conf, "match_only_files", &rule->match_only_files);
+ cherokee_config_node_read_bool (conf, "match_index_files", &rule->match_index_files);
if (rule->match_any == false) {
ret = cherokee_config_node_read (conf, "exists", &tmp);
@@ -118,6 +119,35 @@
return ret_ok;
}
+static cherokee_boolean_t
+check_is_file (cherokee_server_t *srv,
+ cherokee_boolean_t use_iocache,
+ cherokee_buffer_t *fullpath)
+{
+ ret_t ret;
+ cherokee_boolean_t is_file;
+ struct stat nocache_info;
+ struct stat *info;
+ cherokee_iocache_entry_t *io_entry = NULL;
+
+ ret = cherokee_io_stat (srv->iocache,
+ fullpath,
+ use_iocache,
+ &nocache_info,
+ &io_entry,
+ &info);
+
+ if (ret == ret_ok) {
+ is_file = S_ISREG(info->st_mode);
+ }
+
+ if (io_entry) {
+ cherokee_iocache_entry_unref (&io_entry);
+ }
+
+ return (ret == ret_ok) ? is_file : false;
+}
+
static ret_t
match_file (cherokee_rule_exists_t *rule,
cherokee_connection_t *conn,
@@ -126,7 +156,8 @@
ret_t ret;
struct stat nocache_info;
struct stat *info;
- cherokee_boolean_t *is_file;
+ cherokee_boolean_t is_dir;
+ cherokee_boolean_t is_file;
cherokee_iocache_entry_t *io_entry = NULL;
cherokee_server_t *srv = CONN_SRV(conn);
@@ -138,6 +169,7 @@
&info);
if (ret == ret_ok) {
+ is_dir = S_ISDIR(info->st_mode);
is_file = S_ISREG(info->st_mode);
}
@@ -145,18 +177,63 @@
cherokee_iocache_entry_unref (&io_entry);
}
+ /* Not found
+ */
if (ret != ret_ok) {
TRACE(ENTRIES, "Rule exists: did not match '%s'\n", fullpath->buf);
return ret_not_found;
}
- if ((rule->match_only_files) && (! is_file)) {
+ /* File
+ */
+ if (is_file) {
+ TRACE(ENTRIES, "Match exists: '%s'\n", fullpath->buf);
+ return ret_ok;
+ }
+
+ /* Check directory indexes
+ */
+ if (is_dir) {
+ if (rule->match_index_files) {
+ cherokee_list_t *i;
+ cherokee_buffer_t *index_file;
+ cherokee_boolean_t is_file;
+
+ list_for_each (i, &CONN_VSRV(conn)->index_list) {
+ index_file = BUF(LIST_ITEM_INFO(i));
+
+ cherokee_buffer_add_buffer (fullpath, index_file);
+ is_file = check_is_file (srv, rule->use_iocache, fullpath);
+ cherokee_buffer_drop_ending (fullpath, index_file->len);
+
+ if (is_file) {
+ TRACE(ENTRIES, "Match exists (dir): '%s' (Index: '%s')\n",
+ fullpath->buf, index_file->buf);
+ return ret_ok;
+ }
+ }
+ }
+
+ if (rule->match_only_files) {
+ TRACE(ENTRIES, "Rule exists: is dir, no index. Rejecting '%s'\n", fullpath->buf);
+ return ret_not_found;
+ }
+
+ TRACE(ENTRIES, "Rule exists: No index. Matching dir '%s' anyway\n", fullpath->buf);
+ return ret_ok;
+ }
+
+ /* Only files are checked, not found
+ */
+ if (rule->match_only_files) {
TRACE(ENTRIES, "Rule exists: isn't a regular file '%s'\n", fullpath->buf);
return ret_not_found;
}
-
- TRACE(ENTRIES, "Match exists: '%s'\n", fullpath->buf);
- return ret_ok;
+
+ /* Unusual case
+ */
+ TRACE(ENTRIES, "Rule exists: Neither a file, nor a dir. Rejecting: '%s'\n", fullpath->buf);
+ return ret_not_found;
}
static ret_t
@@ -246,9 +323,10 @@
*/
INIT_LIST_HEAD (&n->files);
- n->use_iocache = false;
- n->match_any = false;
- n->match_only_files = true;
+ n->use_iocache = false;
+ n->match_any = false;
+ n->match_only_files = true;
+ n->match_index_files = true;
*rule = n;
return ret_ok;
Modified: cherokee/trunk/cherokee/rule_exists.h
===================================================================
--- cherokee/trunk/cherokee/rule_exists.h 2009-06-13 17:38:35 UTC (rev 3336)
+++ cherokee/trunk/cherokee/rule_exists.h 2009-06-13 17:56:59 UTC (rev 3337)
@@ -42,6 +42,7 @@
cherokee_boolean_t use_iocache;
cherokee_boolean_t match_any;
cherokee_boolean_t match_only_files;
+ cherokee_boolean_t match_index_files;
} cherokee_rule_exists_t;
#define RULE_EXISTS(x) ((cherokee_rule_exists_t *)(x))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.octality.com/pipermail/cherokee-commits/attachments/20090613/f81b41fa/attachment.htm
More information about the Cherokee-commits
mailing list