write_to_client: error out on disconnect
[mod_fastcgi.git] / fcgi.h
blob44c13b000415b0279b5519afc365c18f463242fd
1 /*
2 * $Id: fcgi.h,v 1.45 2004/01/07 01:56:00 robs Exp $
3 */
5 #ifndef FCGI_H
6 #define FCGI_H
8 #if defined(DEBUG) && ! defined(NDEBUG)
9 #define ASSERT(a) ap_assert(a)
10 #else
11 #define ASSERT(a) ((void) 0)
12 #endif
14 #ifdef WIN32
15 /* warning C4115: named type definition in parentheses */
16 #pragma warning(disable : 4115)
17 /* warning C4514: unreferenced inline function has been removed */
18 #pragma warning(disable:4514)
19 #endif
21 /* Apache header files */
22 #include "httpd.h"
23 #include "http_config.h"
24 #include "http_request.h"
25 #include "http_core.h"
26 #include "http_protocol.h"
27 #include "http_main.h"
28 #include "http_log.h"
29 #include "util_script.h"
30 #include "util_md5.h"
32 /* AP2TODO there's probably a better way */
33 #ifdef STANDARD20_MODULE_STUFF
34 #define APACHE2
35 #endif
37 #ifdef APACHE2
39 #include <sys/stat.h>
40 #include "ap_compat.h"
41 #include "apr_strings.h"
43 #ifdef WIN32
44 #if MODULE_MAGIC_NUMBER < 20020903
45 #error "mod_fastcgi is incompatible with Apache versions older than 2.0.41 under WIN"
46 #endif
47 #endif
49 typedef struct apr_array_header_t array_header;
50 typedef struct apr_table_t table;
51 typedef struct apr_pool_t pool;
52 #define NET_SIZE_T apr_socklen_t
54 typedef apr_status_t apcb_t;
55 #define APCB_OK APR_SUCCESS
57 #define XtOffsetOf APR_OFFSETOF
58 #define ap_select select
60 #define ap_user_id unixd_config.user_id
61 #define ap_group_id unixd_config.group_id
62 #define ap_user_name unixd_config.user_name
63 #define ap_suexec_enabled unixd_config.suexec_enabled
65 #ifndef S_ISDIR
66 #define S_ISDIR(m) (((m)&(S_IFMT)) == (S_IFDIR))
67 #endif
69 /* obsolete fns */
70 #define ap_hard_timeout(a,b)
71 #define ap_kill_timeout(a)
72 #define ap_block_alarms()
73 #define ap_reset_timeout(a)
74 #define ap_unblock_alarms()
76 /* starting with apache 2.2 the backward-compatibility defines for
77 * 1.3 APIs are not available anymore. Define them ourselves here.
79 #ifndef ap_copy_table
81 #define ap_copy_table apr_table_copy
82 #define ap_cpystrn apr_cpystrn
83 #define ap_destroy_pool apr_pool_destroy
84 #define ap_isspace apr_isspace
85 #define ap_make_array apr_array_make
86 #define ap_make_table apr_table_make
87 #define ap_null_cleanup apr_pool_cleanup_null
88 #define ap_palloc apr_palloc
89 #define ap_pcalloc apr_pcalloc
90 #define ap_psprintf apr_psprintf
91 #define ap_pstrcat apr_pstrcat
92 #define ap_pstrdup apr_pstrdup
93 #define ap_pstrndup apr_pstrndup
94 #define ap_push_array apr_array_push
95 #define ap_register_cleanup apr_pool_cleanup_register
96 #define ap_snprintf apr_snprintf
97 #define ap_table_add apr_table_add
98 #define ap_table_do apr_table_do
99 #define ap_table_get apr_table_get
100 #define ap_table_set apr_table_set
101 #define ap_table_setn apr_table_setn
102 #define ap_table_unset apr_table_unset
104 #endif /* defined(ap_copy_table) */
106 #if (defined(HAVE_WRITEV) && !HAVE_WRITEV && !defined(NO_WRITEV)) || defined WIN32
107 #define NO_WRITEV
108 #endif
110 #else /* !APACHE2 */
112 #include "http_conf_globals.h"
113 typedef void apcb_t;
114 #define APCB_OK
116 #if MODULE_MAGIC_NUMBER < 19990320
117 #error "This version of mod_fastcgi is incompatible with Apache versions older than 1.3.6."
118 #endif
120 #endif /* !APACHE2 */
122 #ifndef NO_WRITEV
123 #include <sys/uio.h>
124 #endif
126 #ifdef WIN32
127 #ifndef APACHE2
128 #include "multithread.h"
129 #endif
130 #pragma warning(default : 4115)
131 #else
132 #include <sys/un.h>
133 #endif
135 /* FastCGI header files */
136 #include "mod_fastcgi.h"
137 /* @@@ This should go away when fcgi_protocol is re-written */
138 #include "fcgi_protocol.h"
140 typedef struct {
141 int size; /* size of entire buffer */
142 int length; /* number of bytes in current buffer */
143 char *begin; /* begining of valid data */
144 char *end; /* end of valid data */
145 char data[1]; /* buffer data */
146 } Buffer;
148 #ifdef WIN32
149 #define READER 0
150 #define WRITER 1
152 #define MBOX_EVENT 0 /* mboc is ready to be read */
153 #define TERM_EVENT 1 /* termination event */
154 #define WAKE_EVENT 2 /* notification of child Fserver dieing */
156 typedef struct _fcgi_pm_job {
157 char id;
158 char *fs_path;
159 char *user;
160 char * group;
161 unsigned long qsec;
162 unsigned long start_time;
163 struct _fcgi_pm_job *next;
164 } fcgi_pm_job;
165 #endif
167 enum process_state {
168 FCGI_RUNNING_STATE, /* currently running */
169 FCGI_START_STATE, /* needs to be started by PM */
170 FCGI_VICTIM_STATE, /* SIGTERM was sent by PM */
171 FCGI_KILLED_STATE, /* a wait() collected VICTIM */
172 FCGI_READY_STATE /* empty cell, init state */
176 * ServerProcess holds data for each process associated with
177 * a class. It is embedded in fcgi_server below.
179 typedef struct _FcgiProcessInfo {
180 #ifdef WIN32
181 HANDLE handle; /* process handle */
182 HANDLE terminationEvent; /* Event used to signal process termination */
183 #endif
184 pid_t pid; /* pid of associated process */
185 enum process_state state; /* state of the process */
186 time_t start_time; /* time the process was started */
187 } ServerProcess;
190 * fcgi_server holds info for each AppClass specified in this
191 * Web server's configuration.
193 typedef struct _FastCgiServerInfo {
194 int flush;
195 char *fs_path; /* pathname of executable */
196 array_header *pass_headers; /* names of headers to pass in the env */
197 u_int idle_timeout; /* fs idle secs allowed before aborting */
198 char **envp; /* if NOT NULL, this is the env to send
199 * to the fcgi app when starting a server
200 * managed app. */
201 u_int listenQueueDepth; /* size of listen queue for IPC */
202 u_int appConnectTimeout; /* timeout (sec) for connect() requests */
203 u_int numProcesses; /* max allowed processes of this class,
204 * or for dynamic apps, the number of
205 * processes actually running */
206 time_t startTime; /* the time the application was started */
207 time_t restartTime; /* most recent time when the process
208 * manager started a process in this
209 * class. */
210 int initStartDelay; /* min number of seconds to wait between
211 * starting of AppClass processes at init */
212 u_int restartDelay; /* number of seconds to wait between
213 * restarts after failure. Can be zero. */
214 u_int minServerLife; /* minimum number of seconds a server must
215 * live before it's considered borked. */
216 int restartOnExit; /* = TRUE = restart. else terminate/free */
217 u_int numFailures; /* num restarts due to exit failure */
218 int bad; /* is [not] having start problems */
219 struct sockaddr *socket_addr; /* Socket Address of FCGI app server class */
220 #ifdef WIN32
221 struct sockaddr *dest_addr; /* for local apps on NT need socket address */
222 /* bound to localhost */
223 const char *mutex_env_string; /* string holding the accept mutex handle */
224 #endif
225 int socket_addr_len; /* Length of socket */
226 enum {APP_CLASS_UNKNOWN,
227 APP_CLASS_STANDARD,
228 APP_CLASS_EXTERNAL,
229 APP_CLASS_DYNAMIC}
230 directive; /* AppClass or ExternalAppClass */
231 const char *socket_path; /* Name used to create a socket */
232 const char *host; /* Hostname for externally managed
233 * FastCGI application processes */
234 unsigned short port; /* Port number either for externally
235 * managed FastCGI applications or for
236 * server managed FastCGI applications,
237 * where server became application mngr. */
238 int listenFd; /* Listener socket of FCGI app server
239 * class. Passed to app server process
240 * at process creation. */
241 u_int processPriority; /* If locally server managed process,
242 * this is the priority to run the
243 * processes in this class at. */
244 struct _FcgiProcessInfo *procs; /* Pointer to array of
245 * processes belonging to this class. */
246 int keepConnection; /* = 1 = maintain connection to app. */
247 uid_t uid; /* uid this app should run as (suexec) */
248 gid_t gid; /* gid this app should run as (suexec) */
249 const char *username; /* suexec user arg */
250 const char *group; /* suexec group arg, AND used in comm
251 * between RH and PM */
252 const char *user; /* used in comm between RH and PM */
253 /* Dynamic FastCGI apps configuration parameters */
254 u_long totalConnTime; /* microseconds spent by the web server
255 * waiting while fastcgi app performs
256 * request processing since the last
257 * dynamicUpdateInterval */
258 u_long smoothConnTime; /* exponentially decayed values of the
259 * connection times. */
260 u_long totalQueueTime; /* microseconds spent by the web server
261 * waiting to connect to the fastcgi app
262 * since the last dynamicUpdateInterval. */
263 struct _FastCgiServerInfo *next;
264 } fcgi_server;
268 * fcgi_request holds the state of a particular FastCGI request.
270 typedef struct {
271 #ifdef WIN32
272 SOCKET fd;
273 #else
274 int fd; /* connection to FastCGI server */
275 #endif
276 int gotHeader; /* TRUE if reading content bytes */
277 unsigned char packetType; /* type of packet */
278 int dataLen; /* length of data bytes */
279 int paddingLen; /* record padding after content */
280 fcgi_server *fs; /* FastCGI server info */
281 const char *fs_path; /* fcgi_server path */
282 Buffer *serverInputBuffer; /* input buffer from FastCgi server */
283 Buffer *serverOutputBuffer; /* output buffer to FastCgi server */
284 Buffer *clientInputBuffer; /* client input buffer */
285 Buffer *clientOutputBuffer; /* client output buffer */
286 table *authHeaders; /* headers received from an auth fs */
287 int auth_compat; /* whether the auth request is spec compat */
288 table *saved_subprocess_env; /* subprocess_env before auth handling */
289 int expectingClientContent; /* >0 => more content, <=0 => no more */
290 array_header *header;
291 char *fs_stderr;
292 int fs_stderr_len;
293 int parseHeader; /* TRUE iff parsing response headers */
294 request_rec *r;
295 int readingEndRequestBody;
296 FCGI_EndRequestBody endRequestBody;
297 Buffer *erBufPtr;
298 int exitStatus;
299 int exitStatusSet;
300 unsigned int requestId;
301 int eofSent;
302 int role; /* FastCGI Role: Authorizer or Responder */
303 int dynamic; /* whether or not this is a dynamic app */
304 struct timeval startTime; /* dynamic app's connect() attempt start time */
305 struct timeval queueTime; /* dynamic app's connect() complete time */
306 struct timeval completeTime; /* dynamic app's connection close() time */
307 int keepReadingFromFcgiApp; /* still more to read from fcgi app? */
308 const char *user; /* user used to invoke app (suexec) */
309 const char *group; /* group used to invoke app (suexec) */
310 #ifdef WIN32
311 BOOL using_npipe_io; /* named pipe io */
312 #endif
313 } fcgi_request;
315 /* Values of parseHeader field */
316 #define SCAN_CGI_READING_HEADERS 1
317 #define SCAN_CGI_FINISHED 0
318 #define SCAN_CGI_BAD_HEADER -1
319 #define SCAN_CGI_INT_REDIRECT -2
320 #define SCAN_CGI_SRV_REDIRECT -3
322 /* Opcodes for Server->ProcMgr communication */
323 #define FCGI_SERVER_START_JOB 83 /* 'S' - start */
324 #define FCGI_SERVER_RESTART_JOB 82 /* 'R' - restart */
325 #define FCGI_REQUEST_TIMEOUT_JOB 84 /* 'T' - timeout */
326 #define FCGI_REQUEST_COMPLETE_JOB 67 /* 'C' - complete */
328 /* Authorizer types, for auth directives handling */
329 #define FCGI_AUTH_TYPE_AUTHENTICATOR 0
330 #define FCGI_AUTH_TYPE_AUTHORIZER 1
331 #define FCGI_AUTH_TYPE_ACCESS_CHECKER 2
333 /* Bits for auth_options */
334 #define FCGI_AUTHORITATIVE 1
335 #define FCGI_COMPAT 2
337 typedef struct
339 const char *authorizer;
340 u_char authorizer_options;
341 const char *authenticator;
342 u_char authenticator_options;
343 const char *access_checker;
344 u_char access_checker_options;
345 } fcgi_dir_config;
347 #define FCGI_OK 0
348 #define FCGI_FAILED 1
350 #ifdef APACHE2
352 #ifdef WIN32
353 #define FCGI_LOG_EMERG __FILE__,__LINE__,APLOG_EMERG,APR_FROM_OS_ERROR(GetLastError())
354 #define FCGI_LOG_ALERT __FILE__,__LINE__,APLOG_ALERT,APR_FROM_OS_ERROR(GetLastError())
355 #define FCGI_LOG_CRIT __FILE__,__LINE__,APLOG_CRIT,APR_FROM_OS_ERROR(GetLastError())
356 #define FCGI_LOG_ERR __FILE__,__LINE__,APLOG_ERR,APR_FROM_OS_ERROR(GetLastError())
357 #define FCGI_LOG_WARN __FILE__,__LINE__,APLOG_WARNING,APR_FROM_OS_ERROR(GetLastError())
358 #define FCGI_LOG_NOTICE __FILE__,__LINE__,APLOG_NOTICE,APR_FROM_OS_ERROR(GetLastError())
359 #define FCGI_LOG_INFO __FILE__,__LINE__,APLOG_INFO,APR_FROM_OS_ERROR(GetLastError())
360 #define FCGI_LOG_DEBUG __FILE__,__LINE__,APLOG_DEBUG,APR_FROM_OS_ERROR(GetLastError())
361 #else /* !WIN32 */
362 #define FCGI_LOG_EMERG __FILE__,__LINE__,APLOG_EMERG,APR_FROM_OS_ERROR(errno)
363 #define FCGI_LOG_ALERT __FILE__,__LINE__,APLOG_ALERT,APR_FROM_OS_ERROR(errno)
364 #define FCGI_LOG_CRIT __FILE__,__LINE__,APLOG_CRIT,APR_FROM_OS_ERROR(errno)
365 #define FCGI_LOG_ERR __FILE__,__LINE__,APLOG_ERR,APR_FROM_OS_ERROR(errno)
366 #define FCGI_LOG_WARN __FILE__,__LINE__,APLOG_WARNING,APR_FROM_OS_ERROR(errno)
367 #define FCGI_LOG_NOTICE __FILE__,__LINE__,APLOG_NOTICE,APR_FROM_OS_ERROR(errno)
368 #define FCGI_LOG_INFO __FILE__,__LINE__,APLOG_INFO,APR_FROM_OS_ERROR(errno)
369 #define FCGI_LOG_DEBUG __FILE__,__LINE__,APLOG_DEBUG,APR_FROM_OS_ERROR(errno)
370 #endif
372 #define FCGI_LOG_EMERG_ERRNO __FILE__,__LINE__,APLOG_EMERG,APR_FROM_OS_ERROR(errno)
373 #define FCGI_LOG_ALERT_ERRNO __FILE__,__LINE__,APLOG_ALERT,APR_FROM_OS_ERROR(errno)
374 #define FCGI_LOG_CRIT_ERRNO __FILE__,__LINE__,APLOG_CRIT,APR_FROM_OS_ERROR(errno)
375 #define FCGI_LOG_ERR_ERRNO __FILE__,__LINE__,APLOG_ERR,APR_FROM_OS_ERROR(errno)
376 #define FCGI_LOG_WARN_ERRNO __FILE__,__LINE__,APLOG_WARNING,APR_FROM_OS_ERROR(errno)
377 #define FCGI_LOG_NOTICE_ERRNO __FILE__,__LINE__,APLOG_NOTICE,APR_FROM_OS_ERROR(errno)
378 #define FCGI_LOG_INFO_ERRNO __FILE__,__LINE__,APLOG_INFO,APR_FROM_OS_ERROR(errno)
379 #define FCGI_LOG_DEBUG_ERRNO __FILE__,__LINE__,APLOG_DEBUG,APR_FROM_OS_ERROR(errno)
381 #define FCGI_LOG_EMERG_NOERRNO __FILE__,__LINE__,APLOG_EMERG,0
382 #define FCGI_LOG_ALERT_NOERRNO __FILE__,__LINE__,APLOG_ALERT,0
383 #define FCGI_LOG_CRIT_NOERRNO __FILE__,__LINE__,APLOG_CRIT,0
384 #define FCGI_LOG_ERR_NOERRNO __FILE__,__LINE__,APLOG_ERR,0
385 #define FCGI_LOG_WARN_NOERRNO __FILE__,__LINE__,APLOG_WARNING,0
386 #define FCGI_LOG_NOTICE_NOERRNO __FILE__,__LINE__,APLOG_NOTICE,0
387 #define FCGI_LOG_INFO_NOERRNO __FILE__,__LINE__,APLOG_INFO,0
388 #define FCGI_LOG_DEBUG_NOERRNO __FILE__,__LINE__,APLOG_DEBUG,0
390 #else /* !APACHE2 */
392 #ifdef WIN32
393 #define FCGI_LOG_EMERG __FILE__,__LINE__,APLOG_EMERG|APLOG_WIN32ERROR
394 #define FCGI_LOG_ALERT __FILE__,__LINE__,APLOG_ALERT|APLOG_WIN32ERROR
395 #define FCGI_LOG_CRIT __FILE__,__LINE__,APLOG_CRIT|APLOG_WIN32ERROR
396 #define FCGI_LOG_ERR __FILE__,__LINE__,APLOG_ERR|APLOG_WIN32ERROR
397 #define FCGI_LOG_WARN __FILE__,__LINE__,APLOG_WARNING|APLOG_WIN32ERROR
398 #define FCGI_LOG_NOTICE __FILE__,__LINE__,APLOG_NOTICE|APLOG_WIN32ERROR
399 #define FCGI_LOG_INFO __FILE__,__LINE__,APLOG_INFO|APLOG_WIN32ERROR
400 #define FCGI_LOG_DEBUG __FILE__,__LINE__,APLOG_DEBUG|APLOG_WIN32ERROR
401 #else /* !WIN32 */
402 #define FCGI_LOG_EMERG __FILE__,__LINE__,APLOG_EMERG
403 #define FCGI_LOG_ALERT __FILE__,__LINE__,APLOG_ALERT
404 #define FCGI_LOG_CRIT __FILE__,__LINE__,APLOG_CRIT
405 #define FCGI_LOG_ERR __FILE__,__LINE__,APLOG_ERR
406 #define FCGI_LOG_WARN __FILE__,__LINE__,APLOG_WARNING
407 #define FCGI_LOG_NOTICE __FILE__,__LINE__,APLOG_NOTICE
408 #define FCGI_LOG_INFO __FILE__,__LINE__,APLOG_INFO
409 #define FCGI_LOG_DEBUG __FILE__,__LINE__,APLOG_DEBUG
410 #endif
412 #define FCGI_LOG_EMERG_ERRNO __FILE__,__LINE__,APLOG_EMERG /* system is unusable */
413 #define FCGI_LOG_ALERT_ERRNO __FILE__,__LINE__,APLOG_ALERT /* action must be taken immediately */
414 #define FCGI_LOG_CRIT_ERRNO __FILE__,__LINE__,APLOG_CRIT /* critical conditions */
415 #define FCGI_LOG_ERR_ERRNO __FILE__,__LINE__,APLOG_ERR /* error conditions */
416 #define FCGI_LOG_WARN_ERRNO __FILE__,__LINE__,APLOG_WARNING /* warning conditions */
417 #define FCGI_LOG_NOTICE_ERRNO __FILE__,__LINE__,APLOG_NOTICE /* normal but significant condition */
418 #define FCGI_LOG_INFO_ERRNO __FILE__,__LINE__,APLOG_INFO /* informational */
419 #define FCGI_LOG_DEBUG_ERRNO __FILE__,__LINE__,APLOG_DEBUG /* debug-level messages */
421 #define FCGI_LOG_EMERG_NOERRNO __FILE__,__LINE__,APLOG_EMERG|APLOG_NOERRNO
422 #define FCGI_LOG_ALERT_NOERRNO __FILE__,__LINE__,APLOG_ALERT|APLOG_NOERRNO
423 #define FCGI_LOG_CRIT_NOERRNO __FILE__,__LINE__,APLOG_CRIT|APLOG_NOERRNO
424 #define FCGI_LOG_ERR_NOERRNO __FILE__,__LINE__,APLOG_ERR|APLOG_NOERRNO
425 #define FCGI_LOG_WARN_NOERRNO __FILE__,__LINE__,APLOG_WARNING|APLOG_NOERRNO
426 #define FCGI_LOG_NOTICE_NOERRNO __FILE__,__LINE__,APLOG_NOTICE|APLOG_NOERRNO
427 #define FCGI_LOG_INFO_NOERRNO __FILE__,__LINE__,APLOG_INFO|APLOG_NOERRNO
428 #define FCGI_LOG_DEBUG_NOERRNO __FILE__,__LINE__,APLOG_DEBUG|APLOG_NOERRNO
430 #endif /* !APACHE2 */
432 #ifdef FCGI_DEBUG
433 #define FCGIDBG1(a) ap_log_error(FCGI_LOG_DEBUG,fcgi_apache_main_server,a);
434 #define FCGIDBG2(a,b) ap_log_error(FCGI_LOG_DEBUG,fcgi_apache_main_server,a,b);
435 #define FCGIDBG3(a,b,c) ap_log_error(FCGI_LOG_DEBUG,fcgi_apache_main_server,a,b,c);
436 #define FCGIDBG4(a,b,c,d) ap_log_error(FCGI_LOG_DEBUG,fcgi_apache_main_server,a,b,c,d);
437 #define FCGIDBG5(a,b,c,d,e) ap_log_error(FCGI_LOG_DEBUG,fcgi_apache_main_server,a,b,c,d,e);
438 #define FCGIDBG6(a,b,c,d,e,f) ap_log_error(FCGI_LOG_DEBUG,fcgi_apache_main_server,a,b,c,d,e,f);
439 #define FCGIDBG7(a,b,c,d,e,f,g) ap_log_error(FCGI_LOG_DEBUG,fcgi_apache_main_server,a,b,c,d,e,f,g);
440 #else
441 #define FCGIDBG1(a)
442 #define FCGIDBG2(a,b)
443 #define FCGIDBG3(a,b,c)
444 #define FCGIDBG4(a,b,c,d)
445 #define FCGIDBG5(a,b,c,d,e)
446 #define FCGIDBG6(a,b,c,d,e,f)
447 #define FCGIDBG7(a,b,c,d,e,f,g)
448 #endif
451 * Holds the status of the sending of the environment.
452 * A quick hack to dump the static vars for the NT port.
454 typedef struct {
455 enum { PREP, HEADER, NAME, VALUE } pass;
456 char **envp;
457 int headerLen, nameLen, valueLen, totalLen;
458 char *equalPtr;
459 unsigned char headerBuff[8];
460 } env_status;
463 * fcgi_config.c
465 void *fcgi_config_create_dir_config(pool *p, char *dummy);
466 const char *fcgi_config_make_dir(pool *tp, char *path);
467 const char *fcgi_config_make_dynamic_dir(pool *p, const int wax);
468 const char *fcgi_config_new_static_server(cmd_parms *cmd, void *dummy, const char *arg);
469 const char *fcgi_config_new_external_server(cmd_parms *cmd, void *dummy, const char *arg);
470 const char *fcgi_config_set_config(cmd_parms *cmd, void *dummy, const char *arg);
471 const char *fcgi_config_set_fcgi_uid_n_gid(int set);
473 const char *fcgi_config_new_auth_server(cmd_parms * cmd,
474 void *dir_config, const char *fs_path, const char * compat);
476 const char *fcgi_config_set_authoritative_slot(cmd_parms * cmd,
477 void * dir_config, int arg);
478 const char *fcgi_config_set_socket_dir(cmd_parms *cmd, void *dummy, const char *arg);
479 const char *fcgi_config_set_wrapper(cmd_parms *cmd, void *dummy, const char *arg);
480 apcb_t fcgi_config_reset_globals(void * dummy);
481 const char *fcgi_config_set_env_var(pool *p, char **envp, unsigned int *envc, char * var);
484 * fcgi_pm.c
486 #if defined(WIN32) || defined(APACHE2)
487 void fcgi_pm_main(void *dummy);
488 #else
489 int fcgi_pm_main(void *dummy, child_info *info);
490 #endif
493 * fcgi_protocol.c
495 void fcgi_protocol_queue_begin_request(fcgi_request *fr);
496 void fcgi_protocol_queue_client_buffer(fcgi_request *fr);
497 int fcgi_protocol_queue_env(request_rec *r, fcgi_request *fr, env_status *env);
498 int fcgi_protocol_dequeue(pool *p, fcgi_request *fr);
501 * fcgi_buf.c
503 #define BufferLength(b) ((b)->length)
504 #define BufferFree(b) ((b)->size - (b)->length)
506 void fcgi_buf_reset(Buffer *bufPtr);
507 Buffer *fcgi_buf_new(pool *p, int size);
509 #ifndef WIN32
510 typedef int SOCKET;
511 #endif
513 int fcgi_buf_socket_recv(Buffer *b, SOCKET socket);
514 int fcgi_buf_socket_send(Buffer *b, SOCKET socket);
516 void fcgi_buf_added(Buffer * const b, const unsigned int len);
517 void fcgi_buf_removed(Buffer * const b, unsigned int len);
518 void fcgi_buf_get_block_info(Buffer *bufPtr, char **beginPtr, int *countPtr);
519 void fcgi_buf_toss(Buffer *bufPtr, int count);
520 void fcgi_buf_get_free_block_info(Buffer *bufPtr, char **endPtr, int *countPtr);
521 void fcgi_buf_add_update(Buffer *bufPtr, int count);
522 int fcgi_buf_add_block(Buffer *bufPtr, char *data, int datalen);
523 int fcgi_buf_add_string(Buffer *bufPtr, char *str);
524 int fcgi_buf_get_to_block(Buffer *bufPtr, char *data, int datalen);
525 void fcgi_buf_get_to_buf(Buffer *toPtr, Buffer *fromPtr, int len);
526 void fcgi_buf_get_to_array(Buffer *buf, array_header *arr, int len);
529 * fcgi_util.c
532 char *fcgi_util_socket_hash_filename(pool *p, const char *path,
533 const char *user, const char *group);
534 const char *fcgi_util_socket_make_path_absolute(pool * const p,
535 const char *const file, const int dynamic);
536 #ifndef WIN32
537 const char *fcgi_util_socket_make_domain_addr(pool *p, struct sockaddr_un **socket_addr,
538 int *socket_addr_len, const char *socket_path);
539 #endif
540 const char *fcgi_util_socket_make_inet_addr(pool *p, struct sockaddr_in **socket_addr,
541 int *socket_addr_len, const char *host, unsigned short port);
542 const char *fcgi_util_check_access(pool *tp,
543 const char * const path, const struct stat *statBuf,
544 const int mode, const uid_t uid, const gid_t gid);
545 fcgi_server *fcgi_util_fs_get_by_id(const char *ePath, uid_t uid, gid_t gid);
546 fcgi_server *fcgi_util_fs_get(const char *ePath, const char *user, const char *group);
547 const char *fcgi_util_fs_is_path_ok(pool * const p, const char * const fs_path, struct stat *finfo);
548 fcgi_server *fcgi_util_fs_new(pool *p);
549 void fcgi_util_fs_add(fcgi_server *s);
550 const char *fcgi_util_fs_set_uid_n_gid(pool *p, fcgi_server *s, uid_t uid, gid_t gid);
551 ServerProcess *fcgi_util_fs_create_procs(pool *p, int num);
553 int fcgi_util_ticks(struct timeval *);
555 #ifdef WIN32
556 int fcgi_pm_add_job(fcgi_pm_job *new_job);
557 #endif
559 uid_t fcgi_util_get_server_uid(const server_rec * const s);
560 gid_t fcgi_util_get_server_gid(const server_rec * const s);
563 * Globals
566 extern pool *fcgi_config_pool;
568 extern server_rec *fcgi_apache_main_server;
570 extern const char *fcgi_wrapper; /* wrapper path */
571 extern uid_t fcgi_user_id; /* the run uid of Apache & PM */
572 extern gid_t fcgi_group_id; /* the run gid of Apache & PM */
574 extern fcgi_server *fcgi_servers;
576 extern char *fcgi_socket_dir; /* default FastCgiIpcDir */
578 /* pipe used for comm between the request handlers and the PM */
579 extern int fcgi_pm_pipe[];
581 extern pid_t fcgi_pm_pid;
583 extern char *fcgi_dynamic_dir; /* directory for the dynamic
584 * fastcgi apps' sockets */
586 extern char *fcgi_empty_env;
588 extern int fcgi_dynamic_total_proc_count;
589 extern time_t fcgi_dynamic_epoch;
590 extern time_t fcgi_dynamic_last_analyzed;
592 #ifdef WIN32
593 extern HANDLE *fcgi_dynamic_mbox_mutex;
594 extern HANDLE fcgi_event_handles[3];
595 extern fcgi_pm_job *fcgi_dynamic_mbox;
596 #endif
598 extern u_int dynamicMaxProcs;
599 extern int dynamicMinProcs;
600 extern int dynamicMaxClassProcs;
601 extern u_int dynamicKillInterval;
602 extern u_int dynamicUpdateInterval;
603 extern float dynamicGain;
604 extern int dynamicThreshold1;
605 extern int dynamicThresholdN;
606 extern u_int dynamicPleaseStartDelay;
607 extern u_int dynamicAppConnectTimeout;
608 extern char **dynamicEnvp;
609 extern u_int dynamicProcessSlack;
610 extern int dynamicAutoRestart;
611 extern int dynamicAutoUpdate;
612 extern u_int dynamicListenQueueDepth;
613 extern u_int dynamicInitStartDelay;
614 extern u_int dynamicRestartDelay;
615 extern array_header *dynamic_pass_headers;
616 extern u_int dynamic_idle_timeout;
617 extern int dynamicMinServerLife;
618 extern int dynamicFlush;
621 extern module MODULE_VAR_EXPORT fastcgi_module;
623 #endif /* FCGI_H */