Tests about a simple python3 fastcgi runner using libfcgi and the Python-C API.
python
c
wsgi
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

python_ioin.h 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (C) 2019 Weber Yann
  3. *
  4. * This file is part of PyFCGI.
  5. *
  6. * PyFCGI is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * PyFCGI is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PyFCGI. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**@defgroup lib_ioin Defines libpyfcgi.IoIn class
  20. * @brief The IoIn class implement base IO interface allowing python to read
  21. * HTTP request from FCGI
  22. * @ingroup libpyfcgi
  23. */
  24. /**@file python_ioin.h
  25. * @ingroup lib_ioin
  26. */
  27. #ifndef _PYTHON_IOIN__H__
  28. #define _PYTHON_IOIN__H__
  29. #include "config.h"
  30. #include <fcgiapp.h>
  31. #include <fcgi_stdio.h> /* fcgi library; put it first */
  32. #define PY_SSIZE_T_CLEAN
  33. #include <Python.h>
  34. #include "structmember.h"
  35. #include <limits.h>
  36. #include <stdlib.h>
  37. typedef int (*write_f)(const char*, size_t);
  38. #define IoIn__FromString(self, str) \
  39. (((PyIO_t*)self)->bin?PyBytes_FromString:PyUnicode_FromString)(str)
  40. #define IoIn__FromBuff(self) IoIn__FromString(self, ((PyIO_t*)self)->buff)
  41. extern PyMethodDef IoIn_methods[];
  42. extern PyMemberDef IoIn_members[];
  43. extern PyTypeObject IoInType;
  44. extern PyMethodDef IoOut_methods[];
  45. extern PyMemberDef IoOut_members[];
  46. extern PyTypeObject IoOutType;
  47. typedef struct
  48. {
  49. PyObject_VAR_HEAD;
  50. PyObject *closed;
  51. FCGX_Stream **io_stream;
  52. char *buff;
  53. /**@brief buffer size */
  54. int buff_sz;
  55. /**@brief 1 if binary stream (sending PyBytes) 0 if sending PyUnicode */
  56. short bin;
  57. /**@brief 1 if EOF encountered, else 0 */
  58. short eof;
  59. write_f write;
  60. } PyIO_t;
  61. int pyfcgi_io_init(PyObject *self);
  62. int pyfcgi_ioin_init(PyObject *self, PyObject *args, PyObject *kwds);
  63. int pyfcgi_ioout_init(PyObject *self, PyObject *args, PyObject *kwds);
  64. void pyfcgi_io_del(PyIO_t *self);
  65. PyObject* pyfcgi_io_close(PyObject *self, PyObject **argv, Py_ssize_t argc);
  66. PyObject* pyfcgi_io_fileno(PyObject *self, PyObject **argv, Py_ssize_t argc);
  67. PyObject* pyfcgi_io_flush(PyObject *self, PyObject **argv, Py_ssize_t argc);
  68. PyObject* pyfcgi_io_truncate(PyObject *self, PyObject **argv, Py_ssize_t argc);
  69. PyObject* pyfcgi_io_seekable(PyObject *self, PyObject **argv, Py_ssize_t argc);
  70. #define pyfcgi_io_seekable pyfcgi_io_false
  71. #define pyfcgi_io_isatty pyfcgi_io_false
  72. PyObject* pyfcgi_io_SeekError(PyObject *self, PyObject **argv, Py_ssize_t argc);
  73. #define pyfcgi_io_seek pyfcgi_io_SeekError
  74. #define pyfcgi_io_tell pyfcgi_io_SeekError
  75. PyObject* pyfcgi_io_WriteError(PyObject *self, PyObject **argv, Py_ssize_t argc);
  76. PyObject* pyfcgi_io_ReadError(PyObject *self, PyObject **argv, Py_ssize_t argc);
  77. #define pyfcgi_ioin_readable pyfcgi_io_true
  78. PyObject* pyfcgi_ioin_readline(PyObject *self, PyObject **argv, Py_ssize_t argc);
  79. PyObject* pyfcgi_ioin_readlines(PyObject *self, PyObject **argv, Py_ssize_t argc);
  80. PyObject* pyfcgi_ioin_read(PyObject *self, PyObject **argv, Py_ssize_t argc);
  81. PyObject* pyfcgi_ioin_readall(PyObject *self, PyObject **argv, Py_ssize_t argc);
  82. PyObject* pyfcgi_ioin_readinto(PyObject *self, PyObject **argv, Py_ssize_t argc);
  83. #define pyfcgi_ioin_writable pyfcgi_io_true
  84. #define pyfcgi_ioin_writelines pyfcgi_io_WriteError
  85. #define pyfcgi_ioin_write pyfcgi_io_WriteError
  86. #define pyfcgi_ioout_readable pyfcgi_io_false
  87. #define pyfcgi_ioout_readline pyfcgi_io_ReadError
  88. #define pyfcgi_ioout_readlines pyfcgi_io_ReadError
  89. #define pyfcgi_ioout_read pyfcgi_io_ReadError
  90. #define pyfcgi_ioout_readall pyfcgi_io_ReadError
  91. #define pyfcgi_ioout_readinto pyfcgi_io_ReadError
  92. #define pyfcgi_ioout_writable pyfcgi_io_true
  93. PyObject* pyfcgi_ioout_writelines(PyObject *self, PyObject **argv, Py_ssize_t argc);
  94. PyObject* pyfcgi_ioout_write(PyObject *self, PyObject **argv, Py_ssize_t argc);
  95. #endif