/* * 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 . */ #ifndef _PYUTILS__H__ #define _PYUTILS__H__ #include "config.h" #include #include /* fcgi library; put it first*/ #define PY_SSIZE_T_CLEAN #include #include "logger.h" #include "python_pyfcgi.h" /* Imports from libpyfcgi python module header */ extern PyObject* response_status; extern PyObject* response_headers; extern PyObject* libpyfcgi_self; /**@brief Call Py_Initialize & update_python_path */ void pyinit(); /**@brief Add . to the embed pythonpath * @deprecated Py_SetPath breaks Py_GetPrefix()... now */ void update_python_path(); /**@brief Fetch stdout & stderr python flush() function * @param pystdout_flush will point on &sys.stdout.flush() python function * @param pystderr_flush will point on &sys.stderr.flush() python function */ void fetch_pyflush(PyObject** pystdout_flush, PyObject** pystderr_flush); /**@brief Create two pipes for stdout & stderr * @ingroup worker_process * @param pipe_out pipe for stdout * @param pipe_err pipe for stderr * @warning Deprecated behavior. We will us ioin like classes for std & err * output */ void update_python_fd(int pipe_out[2], int pipe_err[2]); /**@brief Clear then update python sys.environ using current FCGI environ * @ingroup worker_process * @note The environ has to be set without a call to os.putenv, the problem * is that the os.environ is a special mapping calling putenv on setitem... * For these reason the os.environ will be replaced by a new dict instance for * each request... * @param py_osmod Python os module * @param environ The environ string provided by libfcgi * @return Python env dict */ PyObject* update_pyenv(PyObject* py_osmod, char** environ); /**@brief Import & return the python entrypoint callable * from PyFCGI_conf.py_entrymod & PyFCGI_conf.py_entryfun */ PyObject* import_entrypoint(); /**@brief Init and return libpyfcgi */ PyObject* pyinit_libpyfcgi(); /**@brief Return the start_response() python function for pep333 worker */ PyObject* get_start_response(); /**@brief Logs an exception */ void log_expt(int priority); /**@brief Set python version * @param version version buffer */ void pyfcgi_python_version(char version[16]); /**@brief Import os module and exit on error * @return Imported module */ PyObject* python_osmod(); #endif