|
@@ -21,7 +21,7 @@
|
21
|
21
|
|
22
|
22
|
/* Globals definitions */
|
23
|
23
|
/* libpyfcgi context */
|
24
|
|
-libpyfcgi_context_t libpyfcgi = { NULL, NULL, NULL, NULL, 0, NULL, NULL, 0 };
|
|
24
|
+libpyfcgi_context_t libpyfcgi = { NULL, NULL, NULL, NULL, {NULL, NULL}, 0, NULL, NULL, 0 };
|
25
|
25
|
/* Python module methods specs */
|
26
|
26
|
/**@todo Add doc in last field */
|
27
|
27
|
PyMethodDef pyfcgimodule_methods[] = {
|
|
@@ -308,6 +308,12 @@ PyInit_libpyfcgi(void)
|
308
|
308
|
{
|
309
|
309
|
return NULL;
|
310
|
310
|
}
|
|
311
|
+ // init IoOut type
|
|
312
|
+ IoOutType.tp_new = PyType_GenericNew;
|
|
313
|
+ if(PyType_Ready(&IoOutType) < 0)
|
|
314
|
+ {
|
|
315
|
+ return NULL;
|
|
316
|
+ }
|
311
|
317
|
|
312
|
318
|
// init module & globals
|
313
|
319
|
libpyfcgi.status = NULL;
|
|
@@ -316,19 +322,28 @@ PyInit_libpyfcgi(void)
|
316
|
322
|
libpyfcgi.self = PyModule_Create(&pyfcgimodule);
|
317
|
323
|
if(libpyfcgi.self == NULL) { return NULL; }
|
318
|
324
|
|
319
|
|
- // Add type to module (optionnal)
|
|
325
|
+ // Add type to module
|
320
|
326
|
PyModule_AddObject(libpyfcgi.self, "IoIn", (PyObject*)&IoInType);
|
|
327
|
+ PyModule_AddObject(libpyfcgi.self, "IoOut", (PyObject*)&IoOutType);
|
321
|
328
|
|
322
|
329
|
// Create a new instance of IoIn
|
323
|
|
- libpyfcgi.ioin = (IoIn*)PyObject_CallObject((PyObject*)&IoInType, NULL);
|
|
330
|
+ libpyfcgi.ioin = (PyIO_t*)PyObject_CallObject((PyObject*)&IoInType, NULL);
|
324
|
331
|
Py_INCREF(libpyfcgi.ioin);
|
325
|
332
|
if(!libpyfcgi.ioin)
|
326
|
333
|
{
|
327
|
334
|
return NULL;
|
328
|
335
|
}
|
329
|
|
- libpyfcgi.ioin->in_stream = &libpyfcgi.in; // point on stream pointer
|
|
336
|
+ libpyfcgi.ioin->io_stream = &libpyfcgi.in; // point on stream pointer
|
330
|
337
|
libpyfcgi.ioin->bin = 1; // binary stream (bytes for python)
|
331
|
338
|
|
|
339
|
+ // Add stdout & stderr
|
|
340
|
+pyfcgi_log(LOG_DEBUG, "libpyfcgi INIT0");
|
|
341
|
+ libpyfcgi.stdio[0] = (PyIO_t*)PyObject_CallObject((PyObject*)&IoOutType, NULL);
|
|
342
|
+pyfcgi_log(LOG_DEBUG, "libpyfcgi INIT1");
|
|
343
|
+ libpyfcgi.stdio[0]->write = _libpyfcgi_stdout_write;
|
|
344
|
+ libpyfcgi.stdio[1] = (PyIO_t*)PyObject_CallObject((PyObject*)&IoOutType, NULL);
|
|
345
|
+ libpyfcgi.stdio[1]->write = _libpyfcgi_stderr_write;
|
|
346
|
+
|
332
|
347
|
// Add it to wsgi dict
|
333
|
348
|
if(PyDict_SetItemString(PyFCGI_conf.context.wsgi_dict, "wsgi.input",
|
334
|
349
|
(PyObject*)libpyfcgi.ioin))
|
|
@@ -542,3 +557,13 @@ void libpyfcgi_timeout()
|
542
|
557
|
}
|
543
|
558
|
}
|
544
|
559
|
|
|
560
|
+int _libpyfcgi_stdout_write(const char* buff, size_t sz)
|
|
561
|
+{
|
|
562
|
+ pyfcgi_log(LOG_INFO, "stdout : '%s'", buff);
|
|
563
|
+ return 1;
|
|
564
|
+}
|
|
565
|
+int _libpyfcgi_stderr_write(const char* buff, size_t sz)
|
|
566
|
+{
|
|
567
|
+ pyfcgi_log(LOG_ERR, "stderr : '%s'", buff);
|
|
568
|
+ return 1;
|
|
569
|
+}
|