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

« back to all changes in this revision

Viewing changes to src/_apachemodule.c

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski
  • Date: 2007-04-12 20:52:05 UTC
  • mfrom: (1.2.4 upstream) (1.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20070412205205-j4qlsw3o4tl615iq
Tags: 3.3.1-1
* New upstream release
* Remove configure and mod_python.h files in clean rule to make the diff.gz
  file smaller
* Current Python version in libapache2-mod-pythonX.Y package name (Provides:
  field) filled in automatically.
* Added XS-Vcs-Browser field

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *
19
19
 * _apachemodule.c 
20
20
 *
21
 
 * $Id: _apachemodule.c 420297 2006-07-09 13:53:06Z nlehuen $
 
21
 * $Id: _apachemodule.c 478403 2006-11-23 00:08:36Z grahamd $
22
22
 *
23
23
 */
24
24
 
89
89
        return NULL; /* error */
90
90
 
91
91
    /* split query string by '&' and ';' into a list of pairs */
 
92
    /* PYTHON 2.5: 'PyList_New' uses Py_ssize_t for input parameters */ 
92
93
    pairs = PyList_New(0);
93
94
    if (pairs == NULL)
94
95
        return NULL;
102
103
        char *cpair;
103
104
        int j = 0;
104
105
 
 
106
        /* PYTHON 2.5: 'PyString_FromStringAndSize' uses Py_ssize_t for input parameters */ 
105
107
        pair = PyString_FromStringAndSize(NULL, len);
106
108
        if (pair == NULL)
107
109
            return NULL;
116
118
        }
117
119
 
118
120
        if (j) {
 
121
            /* PYTHON 2.5: '_PyString_Resize' uses Py_ssize_t for input parameters */ 
119
122
            _PyString_Resize(&pair, j);
120
123
            if (pair)
121
124
                PyList_Append(pairs, pair);
134
137
    if (dict == NULL)
135
138
        return NULL;
136
139
 
 
140
    /* PYTHON 2.5: 'PyList_Size' uses Py_ssize_t for input parameters */ 
137
141
    lsize = PyList_Size(pairs);
138
142
    n = 0;
139
143
 
147
151
        cpair = PyString_AS_STRING(pair);
148
152
 
149
153
        len = strlen(cpair);
 
154
        /* PYTHON 2.5: 'PyString_FromStringAndSize' uses Py_ssize_t for input parameters */ 
150
155
        key = PyString_FromStringAndSize(NULL, len);
151
156
        if (key == NULL) 
152
157
            return NULL;
 
158
        /* PYTHON 2.5: 'PyString_FromStringAndSize' uses Py_ssize_t for input parameters */ 
153
159
        val = PyString_FromStringAndSize(NULL, len);
154
160
        if (val == NULL) 
155
161
            return NULL;
184
190
            ap_unescape_url(ckey);
185
191
            ap_unescape_url(cval);
186
192
 
 
193
            /* PYTHON 2.5: '_PyString_Resize' uses Py_ssize_t for input parameters */ 
187
194
            _PyString_Resize(&key, strlen(ckey));
 
195
            /* PYTHON 2.5: '_PyString_Resize' uses Py_ssize_t for input parameters */ 
188
196
            _PyString_Resize(&val, strlen(cval));
189
197
 
190
198
            if (key && val) {
237
245
        return NULL; /* error */
238
246
 
239
247
    /* split query string by '&' and ';' into a list of pairs */
 
248
    /* PYTHON 2.5: 'PyList_New' uses Py_ssize_t for input parameters */ 
240
249
    pairs = PyList_New(0);
241
250
    if (pairs == NULL)
242
251
        return NULL;
250
259
        char *cpair, *ckey, *cval;
251
260
        int plen, j, p, k, v;
252
261
 
 
262
        /* PYTHON 2.5: 'PyString_FromStringAndSize' uses Py_ssize_t for input parameters */ 
253
263
        pair = PyString_FromStringAndSize(NULL, len);
254
264
        if (pair == NULL)
255
265
            return NULL;
271
281
        }
272
282
 
273
283
        cpair[j] = '\0';
 
284
        /* PYTHON 2.5: '_PyString_Resize' uses Py_ssize_t for input parameters */ 
274
285
        _PyString_Resize(&pair, j);
275
286
        cpair = PyString_AS_STRING(pair);
276
287
 
277
288
        /* split the "abc=def" pair */
278
289
        plen = strlen(cpair);
 
290
        /* PYTHON 2.5: 'PyString_FromStringAndSize' uses Py_ssize_t for input parameters */ 
279
291
        key = PyString_FromStringAndSize(NULL, plen);
280
292
        if (key == NULL) 
281
293
            return NULL;
 
294
        /* PYTHON 2.5: 'PyString_FromStringAndSize' uses Py_ssize_t for input parameters */ 
282
295
        val = PyString_FromStringAndSize(NULL, plen);
283
296
        if (val == NULL) 
284
297
            return NULL;
312
325
            ap_unescape_url(ckey);
313
326
            ap_unescape_url(cval);
314
327
 
 
328
            /* PYTHON 2.5: '_PyString_Resize' uses Py_ssize_t for input parameters */
315
329
            _PyString_Resize(&key, strlen(ckey));
 
330
            /* PYTHON 2.5: '_PyString_Resize' uses Py_ssize_t for input parameters */
316
331
            _PyString_Resize(&val, strlen(cval));
317
332
 
318
333
            if (key && val) {
486
501
        index = (hash % (glb->nlocks-1)+1);
487
502
    }
488
503
 
489
 
//      ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
490
 
//                "_global_trylock at index %d from pid %d", index, getpid());
 
504
    /*  
 
505
     * ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
 
506
     *           "_global_trylock at index %d from pid %d", index, getpid());
 
507
     */
491
508
    Py_BEGIN_ALLOW_THREADS
492
509
    rv = apr_global_mutex_trylock(glb->g_locks[index]);        
493
510
    Py_END_ALLOW_THREADS
494
511
    
495
512
    if (rv == APR_SUCCESS) {
496
 
//      ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
497
 
//                "_global_trylock DONE at index %d from pid %d", index, getpid());
 
513
        /*
 
514
         * ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
 
515
         *         "_global_trylock DONE at index %d from pid %d", index, getpid());
 
516
         */
498
517
        Py_INCREF(Py_True);
499
518
        return Py_True;
500
519
    }
501
520
    else if(APR_STATUS_IS_EBUSY(rv)) {
502
 
//      ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
503
 
//                "_global_trylock BUSY at index %d from pid %d", index, getpid());
 
521
        /*
 
522
         * ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,
 
523
         *         "_global_trylock BUSY at index %d from pid %d", index, getpid());
 
524
         */
504
525
        Py_INCREF(Py_False);
505
526
        return Py_False;
506
527
    }
682
703
    }
683
704
}
684
705
 
 
706
/**
 
707
 ** mp_stat(fname, wanted)
 
708
 **
 
709
 *  Wrapper for apr_stat().
 
710
 */
 
711
 
 
712
static PyObject *mp_stat(PyObject *self, PyObject *args)
 
713
{
 
714
    char *fname = NULL;
 
715
    apr_int32_t wanted = 0;
 
716
    finfoobject* finfo;
 
717
    apr_status_t result;
 
718
 
 
719
    if (! PyArg_ParseTuple(args, "si", &fname, &wanted))
 
720
        return NULL; 
 
721
 
 
722
    finfo = (finfoobject *)MpFinfo_New();
 
723
 
 
724
    fname = apr_pstrdup(finfo->pool, fname);
 
725
 
 
726
    result = apr_stat(finfo->finfo, fname, wanted, finfo->pool);
 
727
 
 
728
    if (result == APR_INCOMPLETE || result == APR_SUCCESS)
 
729
        return (PyObject *)finfo;
 
730
 
 
731
    if (result == APR_ENOENT)
 
732
        return (PyObject *)finfo;
 
733
 
 
734
    Py_DECREF(finfo);
 
735
 
 
736
    PyErr_SetObject(PyExc_OSError,
 
737
                    Py_BuildValue("is", result, "apr_stat() failed"));
 
738
 
 
739
    return NULL;
 
740
}
 
741
 
685
742
/* methods of _apache */
686
743
struct PyMethodDef _apache_module_methods[] = {
687
744
    {"config_tree",           (PyCFunction)config_tree,          METH_NOARGS},
692
749
    {"server_root",           (PyCFunction)server_root,          METH_NOARGS},
693
750
    {"register_cleanup",      (PyCFunction)register_cleanup,     METH_VARARGS},
694
751
    {"exists_config_define",  (PyCFunction)exists_config_define, METH_VARARGS},
 
752
    {"stat",                  (PyCFunction)mp_stat,              METH_VARARGS},
695
753
    {"_global_lock",          (PyCFunction)_global_lock,         METH_VARARGS},
696
754
    {"_global_trylock",       (PyCFunction)_global_trylock,      METH_VARARGS},
697
755
    {"_global_unlock",        (PyCFunction)_global_unlock,       METH_VARARGS},
702
760
 
703
761
DL_EXPORT(void) init_apache()
704
762
{
705
 
    PyObject *m, *d;
 
763
    PyObject *m, *d, *o;
706
764
 
707
765
    /* initialize types XXX break windows? */
708
766
    MpTable_Type.ob_type = &PyType_Type; 
722
780
 
723
781
    PyDict_SetItemString(d, "table", (PyObject *)&MpTable_Type);
724
782
 
 
783
    o = PyInt_FromLong(AP_CONN_UNKNOWN);
 
784
    PyDict_SetItemString(d, "AP_CONN_UNKNOWN", o);
 
785
    Py_DECREF(o);
 
786
    o = PyInt_FromLong(AP_CONN_CLOSE);
 
787
    PyDict_SetItemString(d, "AP_CONN_CLOSE", o);
 
788
    Py_DECREF(o);
 
789
    o = PyInt_FromLong(AP_CONN_KEEPALIVE);
 
790
    PyDict_SetItemString(d, "AP_CONN_KEEPALIVE", o);
 
791
    Py_DECREF(o);
 
792
 
 
793
    o = PyInt_FromLong(APR_NOFILE);
 
794
    PyDict_SetItemString(d, "APR_NOFILE", o);
 
795
    Py_DECREF(o);
 
796
    o = PyInt_FromLong(APR_REG);
 
797
    PyDict_SetItemString(d, "APR_REG", o);
 
798
    Py_DECREF(o);
 
799
    o = PyInt_FromLong(APR_DIR);
 
800
    PyDict_SetItemString(d, "APR_DIR", o);
 
801
    Py_DECREF(o);
 
802
    o = PyInt_FromLong(APR_CHR);
 
803
    PyDict_SetItemString(d, "APR_CHR", o);
 
804
    Py_DECREF(o);
 
805
    o = PyInt_FromLong(APR_BLK);
 
806
    PyDict_SetItemString(d, "APR_BLK", o);
 
807
    Py_DECREF(o);
 
808
    o = PyInt_FromLong(APR_PIPE);
 
809
    PyDict_SetItemString(d, "APR_PIPE", o);
 
810
    Py_DECREF(o);
 
811
    o = PyInt_FromLong(APR_LNK);
 
812
    PyDict_SetItemString(d, "APR_LNK", o);
 
813
    Py_DECREF(o);
 
814
    o = PyInt_FromLong(APR_SOCK);
 
815
    PyDict_SetItemString(d, "APR_SOCK", o);
 
816
    Py_DECREF(o);
 
817
    o = PyInt_FromLong(APR_UNKFILE);
 
818
    PyDict_SetItemString(d, "APR_UNKFILE", o);
 
819
    Py_DECREF(o);
725
820
}
726
821
 
727
822
PyObject *get_ServerReturn()