4 * Definitions for FastCGI application server programs
7 * Copyright (c) 1996 Open Market, Inc.
9 * See the file "LICENSE.TERMS" for information on usage and redistribution
10 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12 * $Id: fcgiapp.h,v 1.11 2001/11/17 03:58:30 robs Exp $
18 /* Hack to see if we are building TCL - TCL needs varargs not stdarg */
27 #define DLLAPI __declspec(dllimport)
\r
33 #if defined (c_plusplus) || defined (__cplusplus)
38 * Error codes. Assigned to avoid conflict with EOF and errno(2).
40 #define FCGX_UNSUPPORTED_VERSION -2
41 #define FCGX_PROTOCOL_ERROR -3
42 #define FCGX_PARAMS_ERROR -4
43 #define FCGX_CALL_SEQ_ERROR -5
46 * This structure defines the state of a FastCGI stream.
47 * Streams are modeled after the FILE type defined in stdio.h.
48 * (We wouldn't need our own if platform vendors provided a
49 * standard way to subclass theirs.)
50 * The state of a stream is private and should only be accessed
51 * by the procedures defined below.
53 typedef struct FCGX_Stream {
54 unsigned char *rdNext; /* reader: first valid byte
55 * writer: equals stop */
56 unsigned char *wrNext; /* writer: first free byte
57 * reader: equals stop */
58 unsigned char *stop; /* reader: last valid byte + 1
59 * writer: last free byte + 1 */
60 unsigned char *stopUnget; /* reader: first byte of current buffer
61 * fragment, for ungetc
62 * writer: undefined */
66 int FCGI_errno; /* error status */
67 void (*fillBuffProc) (struct FCGX_Stream *stream);
68 void (*emptyBuffProc) (struct FCGX_Stream *stream, int doClose);
73 * An environment (as defined by environ(7)): A NULL-terminated array
74 * of strings, each string having the form name=value.
76 typedef char **FCGX_ParamArray;
81 * Setting FCGI_FAIL_ACCEPT_ON_INTR prevents FCGX_Accept() from
82 * restarting upon being interrupted.
84 #define FCGI_FAIL_ACCEPT_ON_INTR 1
87 * FCGX_Request -- State associated with a request.
89 * Its exposed for API simplicity, I expect parts of it to change!
91 typedef struct FCGX_Request {
92 int requestId; /* valid if isBeginProcessed */
99 /* Don't use anything below here */
101 struct Params *paramsPtr;
102 int ipcFd; /* < 0 means no connection */
103 int isBeginProcessed; /* FCGI_BEGIN_REQUEST seen */
104 int keepConnection; /* don't close ipcFd at end of request */
106 int nWriters; /* number of open writers (0..2) */
113 *======================================================================
115 *======================================================================
119 *----------------------------------------------------------------------
123 * Returns TRUE iff this process appears to be a CGI process
124 * rather than a FastCGI process.
126 *----------------------------------------------------------------------
128 DLLAPI int FCGX_IsCGI(void);
131 *----------------------------------------------------------------------
135 * Initialize the FCGX library. Call in multi-threaded apps
136 * before calling FCGX_Accept_r().
138 * Returns 0 upon success.
140 *----------------------------------------------------------------------
142 DLLAPI int FCGX_Init(void);
145 *----------------------------------------------------------------------
149 * Create a FastCGI listen socket.
151 * path is the Unix domain socket (named pipe for WinNT), or a colon
152 * followed by a port number. e.g. "/tmp/fastcgi/mysocket", ":5000"
154 * backlog is the listen queue depth used in the listen() call.
156 * Returns the socket's file descriptor or -1 on error.
158 *----------------------------------------------------------------------
160 DLLAPI int FCGX_OpenSocket(const char *path, int backlog);
163 *----------------------------------------------------------------------
165 * FCGX_InitRequest --
167 * Initialize a FCGX_Request for use with FCGX_Accept_r().
169 * sock is a file descriptor returned by FCGX_OpenSocket() or 0 (default).
170 * The only supported flag at this time is FCGI_FAIL_ON_INTR.
172 * Returns 0 upon success.
173 *----------------------------------------------------------------------
175 DLLAPI int FCGX_InitRequest(FCGX_Request *request, int sock, int flags);
178 *----------------------------------------------------------------------
182 * Accept a new request (multi-thread safe). Be sure to call
186 * 0 for successful call, -1 for error.
190 * Finishes the request accepted by (and frees any
191 * storage allocated by) the previous call to FCGX_Accept.
192 * Creates input, output, and error streams and
193 * assigns them to *in, *out, and *err respectively.
194 * Creates a parameters data structure to be accessed
195 * via getenv(3) (if assigned to environ) or by FCGX_GetParam
196 * and assigns it to *envp.
198 * DO NOT retain pointers to the envp array or any strings
199 * contained in it (e.g. to the result of calling FCGX_GetParam),
200 * since these will be freed by the next call to FCGX_Finish
203 * DON'T use the FCGX_Request, its structure WILL change.
205 *----------------------------------------------------------------------
207 DLLAPI int FCGX_Accept_r(FCGX_Request *request);
210 *----------------------------------------------------------------------
214 * Finish the request (multi-thread safe).
218 * Finishes the request accepted by (and frees any
219 * storage allocated by) the previous call to FCGX_Accept.
221 * DO NOT retain pointers to the envp array or any strings
222 * contained in it (e.g. to the result of calling FCGX_GetParam),
223 * since these will be freed by the next call to FCGX_Finish
226 *----------------------------------------------------------------------
228 DLLAPI void FCGX_Finish_r(FCGX_Request *request);
231 *----------------------------------------------------------------------
235 * Free the memory and, if close is true,
236 * IPC FD associated with the request (multi-thread safe).
238 *----------------------------------------------------------------------
240 DLLAPI void FCGX_Free(FCGX_Request * request, int close);
243 *----------------------------------------------------------------------
247 * Accept a new request (NOT multi-thread safe).
250 * 0 for successful call, -1 for error.
254 * Finishes the request accepted by (and frees any
255 * storage allocated by) the previous call to FCGX_Accept.
256 * Creates input, output, and error streams and
257 * assigns them to *in, *out, and *err respectively.
258 * Creates a parameters data structure to be accessed
259 * via getenv(3) (if assigned to environ) or by FCGX_GetParam
260 * and assigns it to *envp.
262 * DO NOT retain pointers to the envp array or any strings
263 * contained in it (e.g. to the result of calling FCGX_GetParam),
264 * since these will be freed by the next call to FCGX_Finish
267 *----------------------------------------------------------------------
269 DLLAPI int FCGX_Accept(
273 FCGX_ParamArray *envp);
276 *----------------------------------------------------------------------
280 * Finish the current request (NOT multi-thread safe).
284 * Finishes the request accepted by (and frees any
285 * storage allocated by) the previous call to FCGX_Accept.
287 * DO NOT retain pointers to the envp array or any strings
288 * contained in it (e.g. to the result of calling FCGX_GetParam),
289 * since these will be freed by the next call to FCGX_Finish
292 *----------------------------------------------------------------------
294 DLLAPI void FCGX_Finish(void);
297 *----------------------------------------------------------------------
299 * FCGX_StartFilterData --
301 * stream is an input stream for a FCGI_FILTER request.
302 * stream is positioned at EOF on FCGI_STDIN.
303 * Repositions stream to the start of FCGI_DATA.
304 * If the preconditions are not met (e.g. FCGI_STDIN has not
305 * been read to EOF) sets the stream error code to
306 * FCGX_CALL_SEQ_ERROR.
309 * 0 for a normal return, < 0 for error
311 *----------------------------------------------------------------------
313 DLLAPI int FCGX_StartFilterData(FCGX_Stream *stream);
316 *----------------------------------------------------------------------
318 * FCGX_SetExitStatus --
320 * Sets the exit status for stream's request. The exit status
321 * is the status code the request would have exited with, had
322 * the request been run as a CGI program. You can call
323 * SetExitStatus several times during a request; the last call
324 * before the request ends determines the value.
326 *----------------------------------------------------------------------
328 DLLAPI void FCGX_SetExitStatus(int status, FCGX_Stream *stream);
331 *======================================================================
333 *======================================================================
337 *----------------------------------------------------------------------
339 * FCGX_GetParam -- obtain value of FCGI parameter in environment
343 * Value bound to name, NULL if name not present in the
344 * environment envp. Caller must not mutate the result
345 * or retain it past the end of this request.
347 *----------------------------------------------------------------------
349 DLLAPI char *FCGX_GetParam(const char *name, FCGX_ParamArray envp);
352 *======================================================================
354 *======================================================================
358 *----------------------------------------------------------------------
362 * Return the next byte without removing it from the stream.
365 * The byte, or EOF if the end of input has been reached.
367 *----------------------------------------------------------------------
369 DLLAPI int FCGX_Peek(FCGX_Stream * stream);
\r
372 *----------------------------------------------------------------------
376 * Reads a byte from the input stream and returns it.
379 * The byte, or EOF (-1) if the end of input has been reached.
381 *----------------------------------------------------------------------
383 DLLAPI int FCGX_GetChar(FCGX_Stream *stream);
386 *----------------------------------------------------------------------
390 * Pushes back the character c onto the input stream. One
391 * character of pushback is guaranteed once a character
392 * has been read. No pushback is possible for EOF.
395 * Returns c if the pushback succeeded, EOF if not.
397 *----------------------------------------------------------------------
399 DLLAPI int FCGX_UnGetChar(int c, FCGX_Stream *stream);
402 *----------------------------------------------------------------------
406 * Reads up to n consecutive bytes from the input stream
407 * into the character array str. Performs no interpretation
408 * of the input bytes.
411 * Number of bytes read. If result is smaller than n,
412 * the end of input has been reached.
414 *----------------------------------------------------------------------
416 DLLAPI int FCGX_GetStr(char *str, int n, FCGX_Stream *stream);
419 *----------------------------------------------------------------------
423 * Reads up to n-1 consecutive bytes from the input stream
424 * into the character array str. Stops before n-1 bytes
425 * have been read if '\n' or EOF is read. The terminating '\n'
426 * is copied to str. After copying the last byte into str,
427 * stores a '\0' terminator.
430 * NULL if EOF is the first thing read from the input stream,
433 *----------------------------------------------------------------------
435 DLLAPI char *FCGX_GetLine(char *str, int n, FCGX_Stream *stream);
438 *----------------------------------------------------------------------
442 * Returns EOF if end-of-file has been detected while reading
443 * from stream; otherwise returns 0.
445 * Note that FCGX_HasSeenEOF(s) may return 0, yet an immediately
446 * following FCGX_GetChar(s) may return EOF. This function, like
447 * the standard C stdio function feof, does not provide the
448 * ability to peek ahead.
451 * EOF if end-of-file has been detected, 0 if not.
453 *----------------------------------------------------------------------
456 DLLAPI int FCGX_HasSeenEOF(FCGX_Stream *stream);
459 *======================================================================
461 *======================================================================
465 *----------------------------------------------------------------------
469 * Writes a byte to the output stream.
472 * The byte, or EOF (-1) if an error occurred.
474 *----------------------------------------------------------------------
476 DLLAPI int FCGX_PutChar(int c, FCGX_Stream *stream);
479 *----------------------------------------------------------------------
483 * Writes n consecutive bytes from the character array str
484 * into the output stream. Performs no interpretation
485 * of the output bytes.
488 * Number of bytes written (n) for normal return,
489 * EOF (-1) if an error occurred.
491 *----------------------------------------------------------------------
493 DLLAPI int FCGX_PutStr(const char *str, int n, FCGX_Stream *stream);
496 *----------------------------------------------------------------------
500 * Writes a null-terminated character string to the output stream.
503 * number of bytes written for normal return,
504 * EOF (-1) if an error occurred.
506 *----------------------------------------------------------------------
508 DLLAPI int FCGX_PutS(const char *str, FCGX_Stream *stream);
511 *----------------------------------------------------------------------
513 * FCGX_FPrintF, FCGX_VFPrintF --
515 * Performs printf-style output formatting and writes the results
516 * to the output stream.
519 * number of bytes written for normal return,
520 * EOF (-1) if an error occurred.
522 *----------------------------------------------------------------------
524 DLLAPI int FCGX_FPrintF(FCGX_Stream *stream, const char *format, ...);
526 DLLAPI int FCGX_VFPrintF(FCGX_Stream *stream, const char *format, va_list arg);
529 *----------------------------------------------------------------------
533 * Flushes any buffered output.
535 * Server-push is a legitimate application of FCGX_FFlush.
536 * Otherwise, FCGX_FFlush is not very useful, since FCGX_Accept
537 * does it implicitly. Calling FCGX_FFlush in non-push applications
538 * results in extra writes and therefore reduces performance.
541 * EOF (-1) if an error occurred.
543 *----------------------------------------------------------------------
545 DLLAPI int FCGX_FFlush(FCGX_Stream *stream);
548 *======================================================================
549 * Both Readers and Writers
550 *======================================================================
554 *----------------------------------------------------------------------
558 * Closes the stream. For writers, flushes any buffered
561 * Close is not a very useful operation since FCGX_Accept
562 * does it implicitly. Closing the out stream before the
563 * err stream results in an extra write if there's nothing
564 * in the err stream, and therefore reduces performance.
567 * EOF (-1) if an error occurred.
569 *----------------------------------------------------------------------
571 DLLAPI int FCGX_FClose(FCGX_Stream *stream);
574 *----------------------------------------------------------------------
578 * Return the stream error code. 0 means no error, > 0
579 * is an errno(2) error, < 0 is an FastCGI error.
581 *----------------------------------------------------------------------
583 DLLAPI int FCGX_GetError(FCGX_Stream *stream);
586 *----------------------------------------------------------------------
590 * Clear the stream error code and end-of-file indication.
592 *----------------------------------------------------------------------
594 DLLAPI void FCGX_ClearError(FCGX_Stream *stream);
597 *----------------------------------------------------------------------
599 * FCGX_CreateWriter --
601 * Create a FCGX_Stream (used by cgi-fcgi). This shouldn't
602 * be needed by a FastCGI applictaion.
604 *----------------------------------------------------------------------
606 DLLAPI FCGX_Stream *FCGX_CreateWriter(
613 *----------------------------------------------------------------------
617 * Free a FCGX_Stream (used by cgi-fcgi). This shouldn't
618 * be needed by a FastCGI applictaion.
620 *----------------------------------------------------------------------
622 DLLAPI void FCGX_FreeStream(FCGX_Stream **stream);
624 /* ----------------------------------------------------------------------
626 * Prevent the lib from accepting any new requests. Signal handler safe.
628 * ----------------------------------------------------------------------
630 DLLAPI void FCGX_ShutdownPending(void);
632 #if defined (__cplusplus) || defined (c_plusplus)
633 } /* terminate extern "C" { */
636 #endif /* _FCGIAPP_H */