|
||||
File indexing completed on 2025-01-17 09:55:22
0001 /* 0002 * fcgiapp.h -- 0003 * 0004 * Definitions for FastCGI application server programs 0005 * 0006 * 0007 * Copyright (c) 1996 Open Market, Inc. 0008 * 0009 * See the file "LICENSE.TERMS" for information on usage and redistribution 0010 * of this file, and for a DISCLAIMER OF ALL WARRANTIES. 0011 * 0012 * $Id: fcgiapp.h,v 1.14 2003/06/22 00:16:44 robs Exp $ 0013 */ 0014 0015 #ifndef _FCGIAPP_H 0016 #define _FCGIAPP_H 0017 0018 /* Hack to see if we are building Tcl - Tcl needs varargs not stdarg */ 0019 #ifndef TCL_LIBRARY 0020 #include <stdarg.h> 0021 #else 0022 #include <varargs.h> 0023 #endif 0024 0025 #ifndef DLLAPI 0026 #if defined (_WIN32) && defined (_MSC_VER) 0027 #define DLLAPI __declspec(dllimport) 0028 #else 0029 #define DLLAPI 0030 #endif 0031 #endif 0032 0033 #if defined (c_plusplus) || defined (__cplusplus) 0034 extern "C" { 0035 #endif 0036 0037 /* 0038 * Error codes. Assigned to avoid conflict with EOF and errno(2). 0039 */ 0040 #define FCGX_UNSUPPORTED_VERSION -2 0041 #define FCGX_PROTOCOL_ERROR -3 0042 #define FCGX_PARAMS_ERROR -4 0043 #define FCGX_CALL_SEQ_ERROR -5 0044 0045 /* 0046 * This structure defines the state of a FastCGI stream. 0047 * Streams are modeled after the FILE type defined in stdio.h. 0048 * (We wouldn't need our own if platform vendors provided a 0049 * standard way to subclass theirs.) 0050 * The state of a stream is private and should only be accessed 0051 * by the procedures defined below. 0052 */ 0053 typedef struct FCGX_Stream { 0054 unsigned char *rdNext; /* reader: first valid byte 0055 * writer: equals stop */ 0056 unsigned char *wrNext; /* writer: first free byte 0057 * reader: equals stop */ 0058 unsigned char *stop; /* reader: last valid byte + 1 0059 * writer: last free byte + 1 */ 0060 unsigned char *stopUnget; /* reader: first byte of current buffer 0061 * fragment, for ungetc 0062 * writer: undefined */ 0063 int isReader; 0064 int isClosed; 0065 int wasFCloseCalled; 0066 int FCGI_errno; /* error status */ 0067 void (*fillBuffProc) (struct FCGX_Stream *stream); 0068 void (*emptyBuffProc) (struct FCGX_Stream *stream, int doClose); 0069 void *data; 0070 } FCGX_Stream; 0071 0072 /* 0073 * An environment (as defined by environ(7)): A NULL-terminated array 0074 * of strings, each string having the form name=value. 0075 */ 0076 typedef char **FCGX_ParamArray; 0077 0078 /* 0079 * FCGX_Request Flags 0080 * 0081 * Setting FCGI_FAIL_ACCEPT_ON_INTR prevents FCGX_Accept() from 0082 * restarting upon being interrupted. 0083 */ 0084 #define FCGI_FAIL_ACCEPT_ON_INTR 1 0085 0086 /* 0087 * FCGX_Request -- State associated with a request. 0088 * 0089 * Its exposed for API simplicity, I expect parts of it to change! 0090 */ 0091 typedef struct FCGX_Request { 0092 int requestId; /* valid if isBeginProcessed */ 0093 int role; 0094 FCGX_Stream *in; 0095 FCGX_Stream *out; 0096 FCGX_Stream *err; 0097 char **envp; 0098 0099 /* Don't use anything below here */ 0100 0101 struct Params *paramsPtr; 0102 int ipcFd; /* < 0 means no connection */ 0103 int isBeginProcessed; /* FCGI_BEGIN_REQUEST seen */ 0104 int keepConnection; /* don't close ipcFd at end of request */ 0105 int appStatus; 0106 int nWriters; /* number of open writers (0..2) */ 0107 int flags; 0108 int listen_sock; 0109 int detached; 0110 } FCGX_Request; 0111 0112 0113 /* 0114 *====================================================================== 0115 * Control 0116 *====================================================================== 0117 */ 0118 0119 /* 0120 *---------------------------------------------------------------------- 0121 * 0122 * FCGX_IsCGI -- 0123 * 0124 * Returns TRUE iff this process appears to be a CGI process 0125 * rather than a FastCGI process. 0126 * 0127 *---------------------------------------------------------------------- 0128 */ 0129 DLLAPI int FCGX_IsCGI(void); 0130 0131 /* 0132 *---------------------------------------------------------------------- 0133 * 0134 * FCGX_Init -- 0135 * 0136 * Initialize the FCGX library. Call in multi-threaded apps 0137 * before calling FCGX_Accept_r(). 0138 * 0139 * Returns 0 upon success. 0140 * 0141 *---------------------------------------------------------------------- 0142 */ 0143 DLLAPI int FCGX_Init(void); 0144 0145 /* 0146 *---------------------------------------------------------------------- 0147 * 0148 * FCGX_OpenSocket -- 0149 * 0150 * Create a FastCGI listen socket. 0151 * 0152 * path is the Unix domain socket (named pipe for WinNT), or a colon 0153 * followed by a port number. e.g. "/tmp/fastcgi/mysocket", ":5000" 0154 * 0155 * backlog is the listen queue depth used in the listen() call. 0156 * 0157 * Returns the socket's file descriptor or -1 on error. 0158 * 0159 *---------------------------------------------------------------------- 0160 */ 0161 DLLAPI int FCGX_OpenSocket(const char *path, int backlog); 0162 0163 /* 0164 *---------------------------------------------------------------------- 0165 * 0166 * FCGX_InitRequest -- 0167 * 0168 * Initialize a FCGX_Request for use with FCGX_Accept_r(). 0169 * 0170 * sock is a file descriptor returned by FCGX_OpenSocket() or 0 (default). 0171 * The only supported flag at this time is FCGI_FAIL_ON_INTR. 0172 * 0173 * Returns 0 upon success. 0174 *---------------------------------------------------------------------- 0175 */ 0176 DLLAPI int FCGX_InitRequest(FCGX_Request *request, int sock, int flags); 0177 0178 /* 0179 *---------------------------------------------------------------------- 0180 * 0181 * FCGX_Accept_r -- 0182 * 0183 * Accept a new request (multi-thread safe). Be sure to call 0184 * FCGX_Init() first. 0185 * 0186 * Results: 0187 * 0 for successful call, -1 for error. 0188 * 0189 * Side effects: 0190 * 0191 * Finishes the request accepted by (and frees any 0192 * storage allocated by) the previous call to FCGX_Accept. 0193 * Creates input, output, and error streams and 0194 * assigns them to *in, *out, and *err respectively. 0195 * Creates a parameters data structure to be accessed 0196 * via getenv(3) (if assigned to environ) or by FCGX_GetParam 0197 * and assigns it to *envp. 0198 * 0199 * DO NOT retain pointers to the envp array or any strings 0200 * contained in it (e.g. to the result of calling FCGX_GetParam), 0201 * since these will be freed by the next call to FCGX_Finish 0202 * or FCGX_Accept. 0203 * 0204 * DON'T use the FCGX_Request, its structure WILL change. 0205 * 0206 *---------------------------------------------------------------------- 0207 */ 0208 DLLAPI int FCGX_Accept_r(FCGX_Request *request); 0209 0210 /* 0211 *---------------------------------------------------------------------- 0212 * 0213 * FCGX_Finish_r -- 0214 * 0215 * Finish the request (multi-thread safe). 0216 * 0217 * Side effects: 0218 * 0219 * Finishes the request accepted by (and frees any 0220 * storage allocated by) the previous call to FCGX_Accept. 0221 * 0222 * DO NOT retain pointers to the envp array or any strings 0223 * contained in it (e.g. to the result of calling FCGX_GetParam), 0224 * since these will be freed by the next call to FCGX_Finish 0225 * or FCGX_Accept. 0226 * 0227 *---------------------------------------------------------------------- 0228 */ 0229 DLLAPI void FCGX_Finish_r(FCGX_Request *request); 0230 0231 /* 0232 *---------------------------------------------------------------------- 0233 * 0234 * FCGX_Free -- 0235 * 0236 * Free the memory and, if close is true, 0237 * IPC FD associated with the request (multi-thread safe). 0238 * 0239 *---------------------------------------------------------------------- 0240 */ 0241 DLLAPI void FCGX_Free(FCGX_Request * request, int close); 0242 0243 /* 0244 *---------------------------------------------------------------------- 0245 * 0246 * FCGX_Accept -- 0247 * 0248 * Accept a new request (NOT multi-thread safe). 0249 * 0250 * Results: 0251 * 0 for successful call, -1 for error. 0252 * 0253 * Side effects: 0254 * 0255 * Finishes the request accepted by (and frees any 0256 * storage allocated by) the previous call to FCGX_Accept. 0257 * Creates input, output, and error streams and 0258 * assigns them to *in, *out, and *err respectively. 0259 * Creates a parameters data structure to be accessed 0260 * via getenv(3) (if assigned to environ) or by FCGX_GetParam 0261 * and assigns it to *envp. 0262 * 0263 * DO NOT retain pointers to the envp array or any strings 0264 * contained in it (e.g. to the result of calling FCGX_GetParam), 0265 * since these will be freed by the next call to FCGX_Finish 0266 * or FCGX_Accept. 0267 * 0268 *---------------------------------------------------------------------- 0269 */ 0270 DLLAPI int FCGX_Accept( 0271 FCGX_Stream **in, 0272 FCGX_Stream **out, 0273 FCGX_Stream **err, 0274 FCGX_ParamArray *envp); 0275 0276 /* 0277 *---------------------------------------------------------------------- 0278 * 0279 * FCGX_Finish -- 0280 * 0281 * Finish the current request (NOT multi-thread safe). 0282 * 0283 * Side effects: 0284 * 0285 * Finishes the request accepted by (and frees any 0286 * storage allocated by) the previous call to FCGX_Accept. 0287 * 0288 * DO NOT retain pointers to the envp array or any strings 0289 * contained in it (e.g. to the result of calling FCGX_GetParam), 0290 * since these will be freed by the next call to FCGX_Finish 0291 * or FCGX_Accept. 0292 * 0293 *---------------------------------------------------------------------- 0294 */ 0295 DLLAPI void FCGX_Finish(void); 0296 0297 /* 0298 *---------------------------------------------------------------------- 0299 * 0300 * FCGX_StartFilterData -- 0301 * 0302 * stream is an input stream for a FCGI_FILTER request. 0303 * stream is positioned at EOF on FCGI_STDIN. 0304 * Repositions stream to the start of FCGI_DATA. 0305 * If the preconditions are not met (e.g. FCGI_STDIN has not 0306 * been read to EOF) sets the stream error code to 0307 * FCGX_CALL_SEQ_ERROR. 0308 * 0309 * Results: 0310 * 0 for a normal return, < 0 for error 0311 * 0312 *---------------------------------------------------------------------- 0313 */ 0314 DLLAPI int FCGX_StartFilterData(FCGX_Stream *stream); 0315 0316 /* 0317 *---------------------------------------------------------------------- 0318 * 0319 * FCGX_SetExitStatus -- 0320 * 0321 * Sets the exit status for stream's request. The exit status 0322 * is the status code the request would have exited with, had 0323 * the request been run as a CGI program. You can call 0324 * SetExitStatus several times during a request; the last call 0325 * before the request ends determines the value. 0326 * 0327 *---------------------------------------------------------------------- 0328 */ 0329 DLLAPI void FCGX_SetExitStatus(int status, FCGX_Stream *stream); 0330 0331 /* 0332 *====================================================================== 0333 * Parameters 0334 *====================================================================== 0335 */ 0336 0337 /* 0338 *---------------------------------------------------------------------- 0339 * 0340 * FCGX_GetParam -- obtain value of FCGI parameter in environment 0341 * 0342 * 0343 * Results: 0344 * Value bound to name, NULL if name not present in the 0345 * environment envp. Caller must not mutate the result 0346 * or retain it past the end of this request. 0347 * 0348 *---------------------------------------------------------------------- 0349 */ 0350 DLLAPI char *FCGX_GetParam(const char *name, FCGX_ParamArray envp); 0351 0352 /* 0353 *====================================================================== 0354 * Readers 0355 *====================================================================== 0356 */ 0357 0358 /* 0359 *---------------------------------------------------------------------- 0360 * 0361 * FCGX_GetChar -- 0362 * 0363 * Reads a byte from the input stream and returns it. 0364 * 0365 * Results: 0366 * The byte, or EOF (-1) if the end of input has been reached. 0367 * 0368 *---------------------------------------------------------------------- 0369 */ 0370 DLLAPI int FCGX_GetChar(FCGX_Stream *stream); 0371 0372 /* 0373 *---------------------------------------------------------------------- 0374 * 0375 * FCGX_UnGetChar -- 0376 * 0377 * Pushes back the character c onto the input stream. One 0378 * character of pushback is guaranteed once a character 0379 * has been read. No pushback is possible for EOF. 0380 * 0381 * Results: 0382 * Returns c if the pushback succeeded, EOF if not. 0383 * 0384 *---------------------------------------------------------------------- 0385 */ 0386 DLLAPI int FCGX_UnGetChar(int c, FCGX_Stream *stream); 0387 0388 /* 0389 *---------------------------------------------------------------------- 0390 * 0391 * FCGX_GetStr -- 0392 * 0393 * Reads up to n consecutive bytes from the input stream 0394 * into the character array str. Performs no interpretation 0395 * of the input bytes. 0396 * 0397 * Results: 0398 * Number of bytes read. If result is smaller than n, 0399 * the end of input has been reached. 0400 * 0401 *---------------------------------------------------------------------- 0402 */ 0403 DLLAPI int FCGX_GetStr(char *str, int n, FCGX_Stream *stream); 0404 0405 /* 0406 *---------------------------------------------------------------------- 0407 * 0408 * FCGX_GetLine -- 0409 * 0410 * Reads up to n-1 consecutive bytes from the input stream 0411 * into the character array str. Stops before n-1 bytes 0412 * have been read if '\n' or EOF is read. The terminating '\n' 0413 * is copied to str. After copying the last byte into str, 0414 * stores a '\0' terminator. 0415 * 0416 * Results: 0417 * NULL if EOF is the first thing read from the input stream, 0418 * str otherwise. 0419 * 0420 *---------------------------------------------------------------------- 0421 */ 0422 DLLAPI char *FCGX_GetLine(char *str, int n, FCGX_Stream *stream); 0423 0424 /* 0425 *---------------------------------------------------------------------- 0426 * 0427 * FCGX_HasSeenEOF -- 0428 * 0429 * Returns EOF if end-of-file has been detected while reading 0430 * from stream; otherwise returns 0. 0431 * 0432 * Note that FCGX_HasSeenEOF(s) may return 0, yet an immediately 0433 * following FCGX_GetChar(s) may return EOF. This function, like 0434 * the standard C stdio function feof, does not provide the 0435 * ability to peek ahead. 0436 * 0437 * Results: 0438 * EOF if end-of-file has been detected, 0 if not. 0439 * 0440 *---------------------------------------------------------------------- 0441 */ 0442 0443 DLLAPI int FCGX_HasSeenEOF(FCGX_Stream *stream); 0444 0445 /* 0446 *====================================================================== 0447 * Writers 0448 *====================================================================== 0449 */ 0450 0451 /* 0452 *---------------------------------------------------------------------- 0453 * 0454 * FCGX_PutChar -- 0455 * 0456 * Writes a byte to the output stream. 0457 * 0458 * Results: 0459 * The byte, or EOF (-1) if an error occurred. 0460 * 0461 *---------------------------------------------------------------------- 0462 */ 0463 DLLAPI int FCGX_PutChar(int c, FCGX_Stream *stream); 0464 0465 /* 0466 *---------------------------------------------------------------------- 0467 * 0468 * FCGX_PutStr -- 0469 * 0470 * Writes n consecutive bytes from the character array str 0471 * into the output stream. Performs no interpretation 0472 * of the output bytes. 0473 * 0474 * Results: 0475 * Number of bytes written (n) for normal return, 0476 * EOF (-1) if an error occurred. 0477 * 0478 *---------------------------------------------------------------------- 0479 */ 0480 DLLAPI int FCGX_PutStr(const char *str, int n, FCGX_Stream *stream); 0481 0482 /* 0483 *---------------------------------------------------------------------- 0484 * 0485 * FCGX_PutS -- 0486 * 0487 * Writes a null-terminated character string to the output stream. 0488 * 0489 * Results: 0490 * number of bytes written for normal return, 0491 * EOF (-1) if an error occurred. 0492 * 0493 *---------------------------------------------------------------------- 0494 */ 0495 DLLAPI int FCGX_PutS(const char *str, FCGX_Stream *stream); 0496 0497 /* 0498 *---------------------------------------------------------------------- 0499 * 0500 * FCGX_FPrintF, FCGX_VFPrintF -- 0501 * 0502 * Performs printf-style output formatting and writes the results 0503 * to the output stream. 0504 * 0505 * Results: 0506 * number of bytes written for normal return, 0507 * EOF (-1) if an error occurred. 0508 * 0509 *---------------------------------------------------------------------- 0510 */ 0511 DLLAPI int FCGX_FPrintF(FCGX_Stream *stream, const char *format, ...); 0512 0513 DLLAPI int FCGX_VFPrintF(FCGX_Stream *stream, const char *format, va_list arg); 0514 0515 /* 0516 *---------------------------------------------------------------------- 0517 * 0518 * FCGX_FFlush -- 0519 * 0520 * Flushes any buffered output. 0521 * 0522 * Server-push is a legitimate application of FCGX_FFlush. 0523 * Otherwise, FCGX_FFlush is not very useful, since FCGX_Accept 0524 * does it implicitly. Calling FCGX_FFlush in non-push applications 0525 * results in extra writes and therefore reduces performance. 0526 * 0527 * Results: 0528 * EOF (-1) if an error occurred. 0529 * 0530 *---------------------------------------------------------------------- 0531 */ 0532 DLLAPI int FCGX_FFlush(FCGX_Stream *stream); 0533 0534 /* 0535 *====================================================================== 0536 * Both Readers and Writers 0537 *====================================================================== 0538 */ 0539 0540 /* 0541 *---------------------------------------------------------------------- 0542 * 0543 * FCGX_FClose -- 0544 * 0545 * Closes the stream. For writers, flushes any buffered 0546 * output. 0547 * 0548 * Close is not a very useful operation since FCGX_Accept 0549 * does it implicitly. Closing the out stream before the 0550 * err stream results in an extra write if there's nothing 0551 * in the err stream, and therefore reduces performance. 0552 * 0553 * Results: 0554 * EOF (-1) if an error occurred. 0555 * 0556 *---------------------------------------------------------------------- 0557 */ 0558 DLLAPI int FCGX_FClose(FCGX_Stream *stream); 0559 0560 /* 0561 *---------------------------------------------------------------------- 0562 * 0563 * FCGX_GetError -- 0564 * 0565 * Return the stream error code. 0 means no error, > 0 0566 * is an errno(2) error, < 0 is an FastCGI error. 0567 * 0568 *---------------------------------------------------------------------- 0569 */ 0570 DLLAPI int FCGX_GetError(FCGX_Stream *stream); 0571 0572 /* 0573 *---------------------------------------------------------------------- 0574 * 0575 * FCGX_ClearError -- 0576 * 0577 * Clear the stream error code and end-of-file indication. 0578 * 0579 *---------------------------------------------------------------------- 0580 */ 0581 DLLAPI void FCGX_ClearError(FCGX_Stream *stream); 0582 0583 /* 0584 *---------------------------------------------------------------------- 0585 * 0586 * FCGX_CreateWriter -- 0587 * 0588 * Create a FCGX_Stream (used by cgi-fcgi). This shouldn't 0589 * be needed by a FastCGI applictaion. 0590 * 0591 *---------------------------------------------------------------------- 0592 */ 0593 DLLAPI FCGX_Stream *FCGX_CreateWriter( 0594 int socket, 0595 int requestId, 0596 int bufflen, 0597 int streamType); 0598 0599 /* 0600 *---------------------------------------------------------------------- 0601 * 0602 * FCGX_FreeStream -- 0603 * 0604 * Free a FCGX_Stream (used by cgi-fcgi). This shouldn't 0605 * be needed by a FastCGI applictaion. 0606 * 0607 *---------------------------------------------------------------------- 0608 */ 0609 DLLAPI void FCGX_FreeStream(FCGX_Stream **stream); 0610 0611 /* ---------------------------------------------------------------------- 0612 * 0613 * Prevent the lib from accepting any new requests. Signal handler safe. 0614 * 0615 * ---------------------------------------------------------------------- 0616 */ 0617 DLLAPI void FCGX_ShutdownPending(void); 0618 0619 0620 /* 0621 * Attach/Detach an accepted request from its listen socket. 0622 * XXX This is not fully implemented at this time (patch welcome). 0623 */ 0624 DLLAPI int FCGX_Attach(FCGX_Request * r); 0625 DLLAPI int FCGX_Detach(FCGX_Request * r); 0626 0627 0628 #if defined (__cplusplus) || defined (c_plusplus) 0629 } /* terminate extern "C" { */ 0630 #endif 0631 0632 #endif /* _FCGIAPP_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |