Skip to content

Commit

Permalink
Added the filetype attribute of the Apache finfo structure to the tuple
Browse files Browse the repository at this point in the history
returned when accessing req.finfo. This value is accessed using
req.finfo[apache.FINFO_FILETYPE]. New constants apache.APR_NOFILE,
apache.APR_REG, apache.APR_DIR etc, have been added for comparing with the
filetype value. (MODPYTHON-128)
  • Loading branch information
grahamd committed Mar 19, 2006
1 parent 3498b0b commit b9c7e54
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 7 deletions.
8 changes: 8 additions & 0 deletions Doc/appendixc.tex
Expand Up @@ -104,6 +104,14 @@ \chapter{Changes from Version (3.2.8)\label{app-changes-from-3.2.8}}
output after writing the content of the response back to the request
object. By not flushing output it is now possible to use the
"CONTENT_LENGTH" output filter to add a "Content-Length" header.
\item
(\citetitle[http://issues.apache.org/jira/browse/MODPYTHON-128]{MODPYTHON-128})
Added the \code{filetype} attribute of the Apache \code{finfo}
structure to the tuple returned when accessing \code{req.finfo}.
This value is accessed using \code{req.finfo[apache.FINFO_FILETYPE]}.
New constants \code{apache.APR_NOFILE}, \code{apache.APR_REG},
\code{apache.APR_DIR} etc, have been added for comparing with the
\code{filetype} value.
\end{itemize}

Bug Fixes
Expand Down
12 changes: 12 additions & 0 deletions lib/python/mod_python/apache.py
Expand Up @@ -955,6 +955,7 @@ def init(name, server):
FINFO_CTIME = 9
FINFO_FNAME = 10
FINFO_NAME = 11
FINFO_FILETYPE = 12
#FINFO_FILEHAND = 14

# the req.parsed_uri
Expand Down Expand Up @@ -1048,3 +1049,14 @@ def init(name, server):
AP_CONN_UNKNOWN = _apache.AP_CONN_UNKNOWN
AP_CONN_CLOSE = _apache.AP_CONN_CLOSE
AP_CONN_KEEPALIVE = _apache.AP_CONN_KEEPALIVE

# for req.finfo[apache.FINFO_FILETYPE]
APR_NOFILE = _apache.APR_NOFILE
APR_REG = _apache.APR_REG
APR_DIR = _apache.APR_DIR
APR_CHR = _apache.APR_CHR
APR_BLK = _apache.APR_BLK
APR_PIPE = _apache.APR_PIPE
APR_LNK = _apache.APR_LNK
APR_SOCK = _apache.APR_SOCK
APR_UNKFILE = _apache.APR_UNKFILE
28 changes: 28 additions & 0 deletions src/_apachemodule.c
Expand Up @@ -732,6 +732,34 @@ DL_EXPORT(void) init_apache()
o = PyInt_FromLong(AP_CONN_KEEPALIVE);
PyDict_SetItemString(d, "AP_CONN_KEEPALIVE", o);
Py_DECREF(o);

o = PyInt_FromLong(APR_NOFILE);
PyDict_SetItemString(d, "APR_NOFILE", o);
Py_DECREF(o);
o = PyInt_FromLong(APR_REG);
PyDict_SetItemString(d, "APR_REG", o);
Py_DECREF(o);
o = PyInt_FromLong(APR_DIR);
PyDict_SetItemString(d, "APR_DIR", o);
Py_DECREF(o);
o = PyInt_FromLong(APR_CHR);
PyDict_SetItemString(d, "APR_CHR", o);
Py_DECREF(o);
o = PyInt_FromLong(APR_BLK);
PyDict_SetItemString(d, "APR_BLK", o);
Py_DECREF(o);
o = PyInt_FromLong(APR_PIPE);
PyDict_SetItemString(d, "APR_PIPE", o);
Py_DECREF(o);
o = PyInt_FromLong(APR_LNK);
PyDict_SetItemString(d, "APR_LNK", o);
Py_DECREF(o);
o = PyInt_FromLong(APR_SOCK);
PyDict_SetItemString(d, "APR_SOCK", o);
Py_DECREF(o);
o = PyInt_FromLong(APR_UNKFILE);
PyDict_SetItemString(d, "APR_UNKFILE", o);
Py_DECREF(o);
}

PyObject *get_ServerReturn()
Expand Down
19 changes: 18 additions & 1 deletion src/requestobject.c
Expand Up @@ -1495,6 +1495,23 @@ static int setreq_recmbr(requestobject *self, PyObject *val, void *name)
}
self->request_rec->filename =
apr_pstrdup(self->request_rec->pool, PyString_AsString(val));

/* stat file to update finfo */
/* XXX Defer enabling of this for now. See MODPYTHON-128.
if (apr_stat(&self->request_rec->finfo, self->request_rec->filename,
APR_FINFO_NORM, self->request_rec->pool) != APR_SUCCESS) {
self->request_rec->finfo.filetype = APR_NOFILE;
}
*/
return 0;
}
else if (strcmp(name, "canonical_filename") == 0) {
if (! PyString_Check(val)) {
PyErr_SetString(PyExc_TypeError, "canonical_filename must be a string");
return -1;
}
self->request_rec->canonical_filename =
apr_pstrdup(self->request_rec->pool, PyString_AsString(val));
return 0;
}
else if (strcmp(name, "path_info") == 0) {
Expand Down Expand Up @@ -1720,7 +1737,7 @@ static PyGetSetDef request_getsets[] = {
{"unparsed_uri", (getter)getreq_recmbr, NULL, "The URI without any parsing performed", "unparsed_uri"},
{"uri", (getter)getreq_recmbr, (setter)setreq_recmbr, "The path portion of URI", "uri"},
{"filename", (getter)getreq_recmbr, (setter)setreq_recmbr, "The file name on disk that this request corresponds to", "filename"},
{"canonical_filename", (getter)getreq_recmbr, NULL, "The true filename (req.filename is canonicalized if they dont match)", "canonical_filename"},
{"canonical_filename", (getter)getreq_recmbr, (setter)setreq_recmbr, "The true filename (req.filename is canonicalized if they dont match)", "canonical_filename"},
{"path_info", (getter)getreq_recmbr, (setter)setreq_recmbr, "Path_info, if any", "path_info"},
{"args", (getter)getreq_recmbr, NULL, "QUERY_ARGS, if any", "args"},
{"finfo", (getter)getreq_rec_fi, NULL, "File information", "finfo"},
Expand Down
5 changes: 4 additions & 1 deletion src/util.c
Expand Up @@ -100,7 +100,10 @@ PyObject *tuple_from_finfo(apr_finfo_t *f)
return Py_None;
}

t = PyTuple_New(12);
t = PyTuple_New(13);

/* this should have been first, but was added later */
PyTuple_SET_ITEM(t, 12, PyInt_FromLong(f->filetype));

if (f->valid & APR_FINFO_PROT) {
PyTuple_SET_ITEM(t, 0, PyInt_FromLong(f->protection));
Expand Down
10 changes: 5 additions & 5 deletions test/htdocs/tests.py
Expand Up @@ -304,7 +304,7 @@ def test_req_members(self):

log(" req.unparsed_uri: %s" % `req.unparsed_uri`)
if req.unparsed_uri != "/tests.py":
self.fail("req.unparse_uri should be '/tests.py'")
self.fail("req.unparsed_uri should be '/tests.py'")

log(" req.uri: %s" % `req.uri`)
if req.uri != "/tests.py":
Expand All @@ -327,12 +327,12 @@ def test_req_members(self):
self.fail("req.args should be None")

log(" req.finfo: %s" % `req.finfo`)
if req.finfo[10] and (req.finfo[10] != req.canonical_filename):
self.fail("req.finfo[10] should be the (canonical) filename")
if req.finfo[apache.FINFO_FNAME] and (req.finfo[apache.FINFO_FNAME] != req.canonical_filename):
self.fail("req.finfo[apache.FINFO_FNAME] should be the (canonical) filename")

log(" req.parsed_uri: %s" % `req.parsed_uri`)
if req.parsed_uri[6] != '/tests.py':
self.fail("req.parsed_uri[6] should be '/tests.py'")
if req.parsed_uri[apache.URI_PATH] != '/tests.py':
self.fail("req.parsed_uri[apache.URI_PATH] should be '/tests.py'")

log(" req.used_path_info: %s" % `req.used_path_info`)
if req.used_path_info != 2:
Expand Down

0 comments on commit b9c7e54

Please sign in to comment.