-/*
+/*
* fcgiapp.h --
*
* Definitions for FastCGI application server programs
* 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.8 2001/06/22 14:19:23 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 <stdarg.h>
#else
#include <varargs.h>
-#endif /* TCL_LIBARARY */
-#include "fcgi_config.h"
+#endif
#if defined (c_plusplus) || defined (__cplusplus)
extern "C" {
#endif
+#ifndef DLLAPI
+#ifdef _WIN32
+#define DLLAPI __declspec(dllimport)
+#else
+#define DLLAPI
+#endif
+#endif
+
/*
* Error codes. Assigned to avoid conflict with EOF and errno(2).
*/
*/
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;
+
\f
/*
*======================================================================
/*
*----------------------------------------------------------------------
*
+ * 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, if close is true,
+ * IPC FD associated with the request (multi-thread safe).
+ *
+ *----------------------------------------------------------------------
+ */
+DLLAPI void FCGX_Free(FCGX_Request * request, int close);
+
+/*
+ *----------------------------------------------------------------------
+ *
* 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.
*
* FCGX_Finish --
*
- * Finishes the current request from the HTTP server.
+ * Finish the current request (NOT multi-thread safe).
*
* Side effects:
*
* FCGX_CALL_SEQ_ERROR.
*
* Results:
- * 0 for a normal return, < 0 for error
+ * 0 for a normal return, < 0 for error
*
*----------------------------------------------------------------------
*/
*
* Results:
* The byte, or EOF (-1) if an error occurred.
- *
+ *
*----------------------------------------------------------------------
*/
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);
* Results:
* number of bytes written for normal return,
* EOF (-1) if an error occurred.
- *
+ *
*----------------------------------------------------------------------
*/
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, ...);
*
* Results:
* EOF (-1) if an error occurred.
- *
+ *
*----------------------------------------------------------------------
*/
DLLAPI int FCGX_FFlush(FCGX_Stream *stream);
*
* Results:
* EOF (-1) if an error occurred.
- *
+ *
*----------------------------------------------------------------------
*/
DLLAPI int FCGX_FClose(FCGX_Stream *stream);
*/
DLLAPI void FCGX_ClearError(FCGX_Stream *stream);
+/*
+ *----------------------------------------------------------------------
+ *
+ * FCGX_CreateWriter --
+ *
+ * Create a FCGX_Stream (used by cgi-fcgi). This shouldn't
+ * be needed by a FastCGI applictaion.
+ *
+ *----------------------------------------------------------------------
+ */
+DLLAPI FCGX_Stream *FCGX_CreateWriter(
+ int socket,
+ int requestId,
+ int bufflen,
+ int streamType);
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * FCGX_FreeStream --
+ *
+ * Free a FCGX_Stream (used by cgi-fcgi). This shouldn't
+ * be needed by a FastCGI applictaion.
+ *
+ *----------------------------------------------------------------------
+ */
+DLLAPI void FCGX_FreeStream(FCGX_Stream **stream);
+
#if defined (__cplusplus) || defined (c_plusplus)
} /* terminate extern "C" { */