~ubuntu-branches/ubuntu/gutsy/libapache2-mod-python/gutsy

« back to all changes in this revision

Viewing changes to src/requestobject.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski, Piotr Ozarowski
  • Date: 2006-10-12 17:14:47 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20061012171447-ji7e0w38nl37kknp
Tags: 3.2.10-2
[ Piotr Ozarowski ]
* Dependencies updated:
  + replaced apache2-common with apache2.2-common (closes: #391790)
  + bumped apache2-threaded-dev version (see above),
  + bumped python-central version (dh_python removed from debian/rules),
  + bumped debhelper version (see above),
  + added po-debconf to Build-Depends (lintian error).
* Removed deprecated dh_installmanpages from debian/rules
  (there are no manpages to install).
* Updated Dutch debconf translation from Vincent Zweije. (closes: #388834)
* Updated Czech debconf translation from Miroslav Kure. (closes: #384752)
* Updated Japanese debconf translation from Hideki Yamane. (closes: #391811)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *
19
19
 * requestobject.c 
20
20
 *
21
 
 * $Id: requestobject.c 367839 2006-01-11 00:03:06Z jgallacher $
 
21
 * $Id: requestobject.c 420297 2006-07-09 13:53:06Z nlehuen $
22
22
 *
23
23
 */
24
24
 
25
25
#include "mod_python.h"
26
26
 
 
27
/* mod_ssl.h is not safe for inclusion in 2.0, so duplicate the
 
28
 * optional function declarations. */
 
29
APR_DECLARE_OPTIONAL_FN(char *, ssl_var_lookup,
 
30
                        (apr_pool_t *, server_rec *,
 
31
                         conn_rec *, request_rec *,
 
32
                         char *));
 
33
APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *));
 
34
 
 
35
/* Optional functions imported from mod_ssl when loaded: */
 
36
static APR_OPTIONAL_FN_TYPE(ssl_var_lookup) *optfn_ssl_var_lookup = NULL;
 
37
static APR_OPTIONAL_FN_TYPE(ssl_is_https) *optfn_is_https = NULL;
 
38
 
 
39
 
27
40
/**
28
41
 **     MpRequest_FromRequest
29
42
 **
231
244
    return Py_None;
232
245
}
233
246
 
 
247
 
 
248
/**
 
249
 ** request.is_https(self)
 
250
 **
 
251
 * mod_ssl ssl_is_https() wrapper
 
252
 */
 
253
 
 
254
static PyObject * req_is_https(requestobject *self)
 
255
{
 
256
    int is_https;
 
257
    PyObject *result;
 
258
 
 
259
    if (!optfn_is_https)
 
260
        optfn_is_https = APR_RETRIEVE_OPTIONAL_FN(ssl_is_https);
 
261
 
 
262
    is_https = optfn_is_https && optfn_is_https(self->request_rec->connection);
 
263
 
 
264
    return PyInt_FromLong(is_https);
 
265
}
 
266
 
 
267
 
 
268
/**
 
269
 ** request.ssl_var_lookup(self, string variable_name)
 
270
 **
 
271
 * mod_ssl ssl_var_lookup() wrapper
 
272
 */
 
273
 
 
274
static PyObject * req_ssl_var_lookup(requestobject *self, PyObject *args)
 
275
{
 
276
    PyObject *result;
 
277
    char *var_name;
 
278
 
 
279
    if (! PyArg_ParseTuple(args, "s", &var_name))
 
280
        return NULL; /* error */
 
281
 
 
282
    if (!optfn_ssl_var_lookup)
 
283
        optfn_ssl_var_lookup = APR_RETRIEVE_OPTIONAL_FN(ssl_var_lookup);
 
284
 
 
285
    if (optfn_ssl_var_lookup) {
 
286
        const char *val;
 
287
        val = optfn_ssl_var_lookup(self->request_rec->pool,
 
288
                               self->request_rec->server,
 
289
                               self->request_rec->connection,
 
290
                               self->request_rec,
 
291
                               var_name);
 
292
        if (val)
 
293
            return PyString_FromString(val);
 
294
    }
 
295
 
 
296
    /* variable not found, or mod_ssl is not loaded */
 
297
    Py_INCREF(Py_None);
 
298
    return Py_None;
 
299
}
 
300
 
 
301
 
234
302
/**
235
303
 ** request.document_root(self)
236
304
 **
803
871
    PyObject *line, *rlargs;
804
872
    long sizehint = -1;
805
873
    long size = 0;
 
874
    long linesize;
806
875
 
807
876
    if (! PyArg_ParseTuple(args, "|l", &sizehint)) 
808
877
        return NULL;
815
884
        return PyErr_NoMemory();
816
885
 
817
886
    line = req_readline(self, rlargs);
818
 
    while (line && (PyString_Size(line)>0)) {
 
887
    while (line && ((linesize=PyString_Size(line))>0)) {
819
888
        PyList_Append(result, line);
820
 
        size += PyString_Size(line);
 
889
        size += linesize;
821
890
        if ((sizehint != -1) && (size >= size))
822
891
            break;
 
892
        Py_DECREF(line);
823
893
        line = req_readline(self, args);
824
894
    }
 
895
    Py_XDECREF(line);
825
896
 
826
897
    if (!line)
827
898
        return NULL;
1024
1095
 
1025
1096
    Py_BEGIN_ALLOW_THREADS
1026
1097
    status=apr_stat(&finfo, fname,
1027
 
                    APR_FINFO_NORM, self->request_rec->pool);
 
1098
                    APR_FINFO_SIZE, self->request_rec->pool);
1028
1099
    Py_END_ALLOW_THREADS
1029
1100
    if (status != APR_SUCCESS) {
1030
1101
        PyErr_SetString(PyExc_IOError, "Could not stat file for reading");
1033
1104
    
1034
1105
    Py_BEGIN_ALLOW_THREADS                         
1035
1106
    status=apr_file_open(&fd, fname,
1036
 
                         APR_READ, finfo.protection,
 
1107
                         APR_READ, APR_OS_DEFAULT,
1037
1108
                         self->request_rec->pool);
1038
1109
    Py_END_ALLOW_THREADS
1039
1110
    if (status != APR_SUCCESS) {
1073
1144
    {"get_session",           (PyCFunction) req_get_session,           METH_VARARGS},
1074
1145
    {"write",                 (PyCFunction) req_write,                 METH_VARARGS},
1075
1146
    {"internal_redirect",     (PyCFunction) req_internal_redirect,     METH_VARARGS},
 
1147
    {"is_https",              (PyCFunction) req_is_https,              METH_NOARGS},
1076
1148
    {"log_error",             (PyCFunction) req_log_error,             METH_VARARGS},
1077
1149
    {"meets_conditions",      (PyCFunction) req_meets_conditions,      METH_NOARGS},
1078
1150
    {"read",                  (PyCFunction) req_read,                  METH_VARARGS},
1083
1155
    {"send_http_header",      (PyCFunction) req_send_http_header,      METH_NOARGS},
1084
1156
    {"sendfile",              (PyCFunction) req_sendfile,              METH_VARARGS},
1085
1157
    {"set_content_length",    (PyCFunction) req_set_content_length,    METH_VARARGS},
 
1158
    {"ssl_var_lookup",        (PyCFunction) req_ssl_var_lookup,        METH_VARARGS},
1086
1159
    {"write",                 (PyCFunction) req_write,                 METH_VARARGS},
1087
1160
    { NULL, NULL } /* sentinel */
1088
1161
};