/* * Copyright (C) 2019 Weber Yann * * This file is part of PyFCGI. * * PyFCGI is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * PyFCGI is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with PyFCGI. If not, see . */ /**@defgroup lib_ioin Defines libpyfcgi.IoIn class * @brief The IoIn class implement base IO interface allowing python to read * HTTP request from FCGI * @ingroup libpyfcgi */ /**@file python_ioin.h * @ingroup lib_ioin */ #ifndef _PYTHON_IOIN__H__ #define _PYTHON_IOIN__H__ #include "config.h" #include #include /* fcgi library; put it first */ #define PY_SSIZE_T_CLEAN #include #include "structmember.h" #include #include typedef int (*write_f)(const char*, size_t); #define IoIn__FromString(self, str) \ (((PyIO_t*)self)->bin?PyBytes_FromString:PyUnicode_FromString)(str) #define IoIn__FromBuff(self) IoIn__FromString(self, ((PyIO_t*)self)->buff) extern PyMethodDef IoIn_methods[]; extern PyMemberDef IoIn_members[]; extern PyTypeObject IoInType; extern PyMethodDef IoOut_methods[]; extern PyMemberDef IoOut_members[]; extern PyTypeObject IoOutType; typedef struct { PyObject_VAR_HEAD; PyObject *closed; FCGX_Stream **io_stream; char *buff; /**@brief buffer size */ int buff_sz; /**@brief 1 if binary stream (sending PyBytes) 0 if sending PyUnicode */ short bin; /**@brief 1 if EOF encountered, else 0 */ short eof; write_f write; } PyIO_t; int pyfcgi_io_init(PyObject *self); int pyfcgi_ioin_init(PyObject *self, PyObject *args, PyObject *kwds); int pyfcgi_ioout_init(PyObject *self, PyObject *args, PyObject *kwds); void pyfcgi_io_del(PyIO_t *self); PyObject* pyfcgi_io_close(PyObject *self, PyObject **argv, Py_ssize_t argc); PyObject* pyfcgi_io_fileno(PyObject *self, PyObject **argv, Py_ssize_t argc); PyObject* pyfcgi_io_flush(PyObject *self, PyObject **argv, Py_ssize_t argc); PyObject* pyfcgi_io_truncate(PyObject *self, PyObject **argv, Py_ssize_t argc); PyObject* pyfcgi_io_seekable(PyObject *self, PyObject **argv, Py_ssize_t argc); #define pyfcgi_io_seekable pyfcgi_io_false #define pyfcgi_io_isatty pyfcgi_io_false PyObject* pyfcgi_io_SeekError(PyObject *self, PyObject **argv, Py_ssize_t argc); #define pyfcgi_io_seek pyfcgi_io_SeekError #define pyfcgi_io_tell pyfcgi_io_SeekError PyObject* pyfcgi_io_WriteError(PyObject *self, PyObject **argv, Py_ssize_t argc); PyObject* pyfcgi_io_ReadError(PyObject *self, PyObject **argv, Py_ssize_t argc); #define pyfcgi_ioin_readable pyfcgi_io_true PyObject* pyfcgi_ioin_readline(PyObject *self, PyObject **argv, Py_ssize_t argc); PyObject* pyfcgi_ioin_readlines(PyObject *self, PyObject **argv, Py_ssize_t argc); PyObject* pyfcgi_ioin_read(PyObject *self, PyObject **argv, Py_ssize_t argc); PyObject* pyfcgi_ioin_readall(PyObject *self, PyObject **argv, Py_ssize_t argc); PyObject* pyfcgi_ioin_readinto(PyObject *self, PyObject **argv, Py_ssize_t argc); #define pyfcgi_ioin_writable pyfcgi_io_true #define pyfcgi_ioin_writelines pyfcgi_io_WriteError #define pyfcgi_ioin_write pyfcgi_io_WriteError #define pyfcgi_ioout_readable pyfcgi_io_false #define pyfcgi_ioout_readline pyfcgi_io_ReadError #define pyfcgi_ioout_readlines pyfcgi_io_ReadError #define pyfcgi_ioout_read pyfcgi_io_ReadError #define pyfcgi_ioout_readall pyfcgi_io_ReadError #define pyfcgi_ioout_readinto pyfcgi_io_ReadError #define pyfcgi_ioout_writable pyfcgi_io_true PyObject* pyfcgi_ioout_writelines(PyObject *self, PyObject **argv, Py_ssize_t argc); PyObject* pyfcgi_ioout_write(PyObject *self, PyObject **argv, Py_ssize_t argc); #endif