X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=include%2Ffcgiapp.h;h=2d49152d09887a98fcdc87c767499019e0179f28;hb=60a09042dc4d66f5d2c1c81f26dc534dbce8e353;hp=ebde17a6575dbc21386779399bd3fd3a1ed91ef2;hpb=0198fd3ca83ad0dbdb1c3bfb967d1843a7d02296;p=catagits%2Ffcgi2.git diff --git a/include/fcgiapp.h b/include/fcgiapp.h index ebde17a..2d49152 100644 --- a/include/fcgiapp.h +++ b/include/fcgiapp.h @@ -1,4 +1,4 @@ -/* +/* * fcgiapp.h -- * * Definitions for FastCGI application server programs @@ -9,33 +9,35 @@ * See the file "LICENSE.TERMS" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * $Id: fcgiapp.h,v 1.1 1997/09/16 15:36:32 stanleyg Exp $ + * $Id: fcgiapp.h,v 1.5 2000/11/05 17:09:36 robs Exp $ */ #ifndef _FCGIAPP_H #define _FCGIAPP_H -#ifndef TCL_LIBRARY /* Hack to see if we are building TCL since TCL - * needs varargs not stdarg - */ -#ifdef _WIN32 -#ifndef DLLAPI -#define DLLAPI __declspec(dllimport) -#endif -#else -#define DLLAPI -#endif - +/* Hack to see if we are building TCL - TCL needs varargs not stdarg */ +#ifndef TCL_LIBRARY #include #else #include -#endif /* TCL_LIBARARY */ -#include "fcgi_config.h" +#endif #if defined (c_plusplus) || defined (__cplusplus) extern "C" { #endif +#ifdef _WIN32 + +#ifndef DLLAPI +#define DLLAPI __declspec(dllimport) +#endif + +#else /* !_WIN32 */ + +#define DLLAPI + +#endif /* !_WIN32 */ + /* * Error codes. Assigned to avoid conflict with EOF and errno(2). */ @@ -77,6 +79,39 @@ typedef struct FCGX_Stream { */ typedef char **FCGX_ParamArray; +/* + * FCGX_Request Flags + * + * Setting FCGI_FAIL_ACCEPT_ON_INTR prevents FCGX_Accept() from + * restarting upon being interrupted. + */ +#define FCGI_FAIL_ACCEPT_ON_INTR 1 + +/* + * FCGX_Request -- State associated with a request. + * + * Its exposed for API simplicity, I expect parts of it to change! + */ +typedef struct FCGX_Request { + int requestId; /* valid if isBeginProcessed */ + int role; + FCGX_Stream *in; + FCGX_Stream *out; + FCGX_Stream *err; + char **envp; + + /* Don't use anything below here */ + + struct Params *paramsPtr; + int ipcFd; /* < 0 means no connection */ + int isBeginProcessed; /* FCGI_BEGIN_REQUEST seen */ + int keepConnection; /* don't close ipcFd at end of request */ + int appStatus; + int nWriters; /* number of open writers (0..2) */ + int flags; + int listen_sock; +} FCGX_Request; + /* *====================================================================== @@ -99,9 +134,120 @@ DLLAPI int FCGX_IsCGI(void); /* *---------------------------------------------------------------------- * + * FCGX_Init -- + * + * Initialize the FCGX library. Call in multi-threaded apps + * before calling FCGX_Accept_r(). + * + * Returns 0 upon success. + * + *---------------------------------------------------------------------- + */ +DLLAPI int FCGX_Init(void); + +/* + *---------------------------------------------------------------------- + * + * FCGX_OpenSocket -- + * + * Create a FastCGI listen socket. + * + * path is the Unix domain socket (named pipe for WinNT), or a colon + * followed by a port number. e.g. "/tmp/fastcgi/mysocket", ":5000" + * + * backlog is the listen queue depth used in the listen() call. + * + * Returns the socket's file descriptor or -1 on error. + * + *---------------------------------------------------------------------- + */ +DLLAPI int FCGX_OpenSocket(const char *path, int backlog); + +/* + *---------------------------------------------------------------------- + * + * FCGX_InitRequest -- + * + * Initialize a FCGX_Request for use with FCGX_Accept_r(). + * + * sock is a file descriptor returned by FCGX_OpenSocket() or 0 (default). + * The only supported flag at this time is FCGI_FAIL_ON_INTR. + * + * Returns 0 upon success. + *---------------------------------------------------------------------- + */ +DLLAPI int FCGX_InitRequest(FCGX_Request *request, int sock, int flags); + +/* + *---------------------------------------------------------------------- + * + * FCGX_Accept_r -- + * + * Accept a new request (multi-thread safe). Be sure to call + * FCGX_Init() first. + * + * Results: + * 0 for successful call, -1 for error. + * + * Side effects: + * + * Finishes the request accepted by (and frees any + * storage allocated by) the previous call to FCGX_Accept. + * Creates input, output, and error streams and + * assigns them to *in, *out, and *err respectively. + * Creates a parameters data structure to be accessed + * via getenv(3) (if assigned to environ) or by FCGX_GetParam + * and assigns it to *envp. + * + * DO NOT retain pointers to the envp array or any strings + * contained in it (e.g. to the result of calling FCGX_GetParam), + * since these will be freed by the next call to FCGX_Finish + * or FCGX_Accept. + * + * DON'T use the FCGX_Request, its structure WILL change. + * + *---------------------------------------------------------------------- + */ +DLLAPI int FCGX_Accept_r(FCGX_Request *request); + +/* + *---------------------------------------------------------------------- + * + * FCGX_Finish_r -- + * + * Finish the request (multi-thread safe). + * + * Side effects: + * + * Finishes the request accepted by (and frees any + * storage allocated by) the previous call to FCGX_Accept. + * + * DO NOT retain pointers to the envp array or any strings + * contained in it (e.g. to the result of calling FCGX_GetParam), + * since these will be freed by the next call to FCGX_Finish + * or FCGX_Accept. + * + *---------------------------------------------------------------------- + */ +DLLAPI void FCGX_Finish_r(FCGX_Request *request); + +/* + *---------------------------------------------------------------------- + * + * FCGX_Free -- + * + * Free the memory and IPC FD associated with the request (multi-thread safe). + * + *---------------------------------------------------------------------- + */ +DLLAPI void FCGX_Free(FCGX_Request * request); + +/* + *---------------------------------------------------------------------- + * * FCGX_Accept -- * - * Accepts a new request from the HTTP server. + * Accept a new request (NOT multi-thread safe). * * Results: * 0 for successful call, -1 for error. @@ -134,7 +280,7 @@ DLLAPI int FCGX_Accept( * * FCGX_Finish -- * - * Finishes the current request from the HTTP server. + * Finish the current request (NOT multi-thread safe). * * Side effects: * @@ -163,7 +309,7 @@ DLLAPI void FCGX_Finish(void); * FCGX_CALL_SEQ_ERROR. * * Results: - * 0 for a normal return, < 0 for error + * 0 for a normal return, < 0 for error * *---------------------------------------------------------------------- */ @@ -313,7 +459,7 @@ DLLAPI int FCGX_HasSeenEOF(FCGX_Stream *stream); * * Results: * The byte, or EOF (-1) if an error occurred. - * + * *---------------------------------------------------------------------- */ DLLAPI int FCGX_PutChar(int c, FCGX_Stream *stream); @@ -330,7 +476,7 @@ DLLAPI int FCGX_PutChar(int c, FCGX_Stream *stream); * Results: * Number of bytes written (n) for normal return, * EOF (-1) if an error occurred. - * + * *---------------------------------------------------------------------- */ DLLAPI int FCGX_PutStr(const char *str, int n, FCGX_Stream *stream); @@ -345,7 +491,7 @@ DLLAPI int FCGX_PutStr(const char *str, int n, FCGX_Stream *stream); * Results: * number of bytes written for normal return, * EOF (-1) if an error occurred. - * + * *---------------------------------------------------------------------- */ DLLAPI int FCGX_PutS(const char *str, FCGX_Stream *stream); @@ -361,7 +507,7 @@ DLLAPI int FCGX_PutS(const char *str, FCGX_Stream *stream); * Results: * number of bytes written for normal return, * EOF (-1) if an error occurred. - * + * *---------------------------------------------------------------------- */ DLLAPI int FCGX_FPrintF(FCGX_Stream *stream, const char *format, ...); @@ -382,7 +528,7 @@ DLLAPI int FCGX_VFPrintF(FCGX_Stream *stream, const char *format, va_list arg); * * Results: * EOF (-1) if an error occurred. - * + * *---------------------------------------------------------------------- */ DLLAPI int FCGX_FFlush(FCGX_Stream *stream); @@ -408,7 +554,7 @@ DLLAPI int FCGX_FFlush(FCGX_Stream *stream); * * Results: * EOF (-1) if an error occurred. - * + * *---------------------------------------------------------------------- */ DLLAPI int FCGX_FClose(FCGX_Stream *stream);