set version - 2.4.2
[mod_fastcgi.git] / fcgi.h
blob1cce9e568c2d4dfdddee302d949e181b246be5db
1 /*
2 * $Id: fcgi.h,v 1.44 2003/02/03 23:07:37 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 #if (defined(HAVE_WRITEV) && !HAVE_WRITEV && !defined(NO_WRITEV)) || defined WIN32
77 #define NO_WRITEV
78 #endif
80 #else /* !APACHE2 */
82 #include "http_conf_globals.h"
83 typedef void apcb_t;
84 #define APCB_OK
86 #if MODULE_MAGIC_NUMBER < 19990320
87 #error "This version of mod_fastcgi is incompatible with Apache versions older than 1.3.6."
88 #endif
90 #endif /* !APACHE2 */
92 #ifndef NO_WRITEV
93 #include <sys/uio.h>
94 #endif
96 #ifdef WIN32
97 #ifndef APACHE2
98 #include "multithread.h"
99 #endif
100 #pragma warning(default : 4115)
101 #else
102 #include <sys/un.h>
103 #endif
105 /* FastCGI header files */
106 #include "mod_fastcgi.h"
107 /* @@@ This should go away when fcgi_protocol is re-written */
108 #include "fcgi_protocol.h"
110 typedef struct {
111 int size; /* size of entire buffer */
112 int length; /* number of bytes in current buffer */
113 char *begin; /* begining of valid data */
114 char *end; /* end of valid data */
115 char data[1]; /* buffer data */
116 } Buffer;
118 #ifdef WIN32
119 #define READER 0
120 #define WRITER 1
122 #define MBOX_EVENT 0 /* mboc is ready to be read */
123 #define TERM_EVENT 1 /* termination event */
124 #define WAKE_EVENT 2 /* notification of child Fserver dieing */
126 typedef struct _fcgi_pm_job {
127 char id;
128 char *fs_path;
129 char *user;
130 char * group;
131 unsigned long qsec;
132 unsigned long start_time;
133 struct _fcgi_pm_job *next;
134 } fcgi_pm_job;
135 #endif
137 enum process_state {
138 FCGI_RUNNING_STATE, /* currently running */
139 FCGI_START_STATE, /* needs to be started by PM */
140 FCGI_VICTIM_STATE, /* SIGTERM was sent by PM */
141 FCGI_KILLED_STATE, /* a wait() collected VICTIM */
142 FCGI_READY_STATE /* empty cell, init state */
146 * ServerProcess holds data for each process associated with
147 * a class. It is embedded in fcgi_server below.
149 typedef struct _FcgiProcessInfo {
150 #ifdef WIN32
151 HANDLE handle; /* process handle */
152 HANDLE terminationEvent; /* Event used to signal process termination */
153 #endif
154 pid_t pid; /* pid of associated process */
155 enum process_state state; /* state of the process */
156 time_t start_time; /* time the process was started */
157 } ServerProcess;
160 * fcgi_server holds info for each AppClass specified in this
161 * Web server's configuration.
163 typedef struct _FastCgiServerInfo {
164 int flush;
165 char *fs_path; /* pathname of executable */
166 array_header *pass_headers; /* names of headers to pass in the env */
167 u_int idle_timeout; /* fs idle secs allowed before aborting */
168 char **envp; /* if NOT NULL, this is the env to send
169 * to the fcgi app when starting a server
170 * managed app. */
171 u_int listenQueueDepth; /* size of listen queue for IPC */
172 u_int appConnectTimeout; /* timeout (sec) for connect() requests */
173 u_int numProcesses; /* max allowed processes of this class,
174 * or for dynamic apps, the number of
175 * processes actually running */
176 time_t startTime; /* the time the application was started */
177 time_t restartTime; /* most recent time when the process
178 * manager started a process in this
179 * class. */
180 int initStartDelay; /* min number of seconds to wait between
181 * starting of AppClass processes at init */
182 u_int restartDelay; /* number of seconds to wait between
183 * restarts after failure. Can be zero. */
184 int restartOnExit; /* = TRUE = restart. else terminate/free */
185 u_int numFailures; /* num restarts due to exit failure */
186 int bad; /* is [not] having start problems */
187 struct sockaddr *socket_addr; /* Socket Address of FCGI app server class */
188 #ifdef WIN32
189 struct sockaddr *dest_addr; /* for local apps on NT need socket address */
190 /* bound to localhost */
191 const char *mutex_env_string; /* string holding the accept mutex handle */
192 #endif
193 int socket_addr_len; /* Length of socket */
194 enum {APP_CLASS_UNKNOWN,
195 APP_CLASS_STANDARD,
196 APP_CLASS_EXTERNAL,
197 APP_CLASS_DYNAMIC}
198 directive; /* AppClass or ExternalAppClass */
199 const char *socket_path; /* Name used to create a socket */
200 const char *host; /* Hostname for externally managed
201 * FastCGI application processes */
202 unsigned short port; /* Port number either for externally
203 * managed FastCGI applications or for
204 * server managed FastCGI applications,
205 * where server became application mngr. */
206 int listenFd; /* Listener socket of FCGI app server
207 * class. Passed to app server process
208 * at process creation. */
209 u_int processPriority; /* If locally server managed process,
210 * this is the priority to run the
211 * processes in this class at. */
212 struct _FcgiProcessInfo *procs; /* Pointer to array of
213 * processes belonging to this class. */
214 int keepConnection; /* = 1 = maintain connection to app. */
215 uid_t uid; /* uid this app should run as (suexec) */
216 gid_t gid; /* gid this app should run as (suexec) */
217 const char *username; /* suexec user arg */
218 const char *group; /* suexec group arg, AND used in comm
219 * between RH and PM */
220 const char *user; /* used in comm between RH and PM */
221 /* Dynamic FastCGI apps configuration parameters */
222 u_long totalConnTime; /* microseconds spent by the web server
223 * waiting while fastcgi app performs
224 * request processing since the last
225 * dynamicUpdateInterval */
226 u_long smoothConnTime; /* exponentially decayed values of the
227 * connection times. */
228 u_long totalQueueTime; /* microseconds spent by the web server
229 * waiting to connect to the fastcgi app
230 * since the last dynamicUpdateInterval. */
231 struct _FastCgiServerInfo *next;
232 } fcgi_server;
236 * fcgi_request holds the state of a particular FastCGI request.
238 typedef struct {
239 #ifdef WIN32
240 SOCKET fd;
241 #else
242 int fd; /* connection to FastCGI server */
243 #endif
244 int gotHeader; /* TRUE if reading content bytes */
245 unsigned char packetType; /* type of packet */
246 int dataLen; /* length of data bytes */
247 int paddingLen; /* record padding after content */
248 fcgi_server *fs; /* FastCGI server info */
249 const char *fs_path; /* fcgi_server path */
250 Buffer *serverInputBuffer; /* input buffer from FastCgi server */
251 Buffer *serverOutputBuffer; /* output buffer to FastCgi server */
252 Buffer *clientInputBuffer; /* client input buffer */
253 Buffer *clientOutputBuffer; /* client output buffer */
254 table *authHeaders; /* headers received from an auth fs */
255 int auth_compat; /* whether the auth request is spec compat */
256 table *saved_subprocess_env; /* subprocess_env before auth handling */
257 int expectingClientContent; /* >0 => more content, <=0 => no more */
258 array_header *header;
259 char *fs_stderr;
260 int fs_stderr_len;
261 int parseHeader; /* TRUE iff parsing response headers */
262 request_rec *r;
263 int readingEndRequestBody;
264 FCGI_EndRequestBody endRequestBody;
265 Buffer *erBufPtr;
266 int exitStatus;
267 int exitStatusSet;
268 unsigned int requestId;
269 int eofSent;
270 int role; /* FastCGI Role: Authorizer or Responder */
271 int dynamic; /* whether or not this is a dynamic app */
272 struct timeval startTime; /* dynamic app's connect() attempt start time */
273 struct timeval queueTime; /* dynamic app's connect() complete time */
274 struct timeval completeTime; /* dynamic app's connection close() time */
275 int keepReadingFromFcgiApp; /* still more to read from fcgi app? */
276 const char *user; /* user used to invoke app (suexec) */
277 const char *group; /* group used to invoke app (suexec) */
278 #ifdef WIN32
279 BOOL using_npipe_io; /* named pipe io */
280 #endif
281 } fcgi_request;
283 /* Values of parseHeader field */
284 #define SCAN_CGI_READING_HEADERS 1
285 #define SCAN_CGI_FINISHED 0
286 #define SCAN_CGI_BAD_HEADER -1
287 #define SCAN_CGI_INT_REDIRECT -2
288 #define SCAN_CGI_SRV_REDIRECT -3
290 /* Opcodes for Server->ProcMgr communication */
291 #define FCGI_SERVER_START_JOB 83 /* 'S' - start */
292 #define FCGI_SERVER_RESTART_JOB 82 /* 'R' - restart */
293 #define FCGI_REQUEST_TIMEOUT_JOB 84 /* 'T' - timeout */
294 #define FCGI_REQUEST_COMPLETE_JOB 67 /* 'C' - complete */
296 /* Authorizer types, for auth directives handling */
297 #define FCGI_AUTH_TYPE_AUTHENTICATOR 0
298 #define FCGI_AUTH_TYPE_AUTHORIZER 1
299 #define FCGI_AUTH_TYPE_ACCESS_CHECKER 2
301 /* Bits for auth_options */
302 #define FCGI_AUTHORITATIVE 1
303 #define FCGI_COMPAT 2
305 typedef struct
307 const char *authorizer;
308 u_char authorizer_options;
309 const char *authenticator;
310 u_char authenticator_options;
311 const char *access_checker;
312 u_char access_checker_options;
313 } fcgi_dir_config;
315 #define FCGI_OK 0
316 #define FCGI_FAILED 1
318 #ifdef APACHE2
320 #ifdef WIN32
321 #define FCGI_LOG_EMERG __FILE__,__LINE__,APLOG_EMERG,APR_FROM_OS_ERROR(GetLastError())
322 #define FCGI_LOG_ALERT __FILE__,__LINE__,APLOG_ALERT,APR_FROM_OS_ERROR(GetLastError())
323 #define FCGI_LOG_CRIT __FILE__,__LINE__,APLOG_CRIT,APR_FROM_OS_ERROR(GetLastError())
324 #define FCGI_LOG_ERR __FILE__,__LINE__,APLOG_ERR,APR_FROM_OS_ERROR(GetLastError())
325 #define FCGI_LOG_WARN __FILE__,__LINE__,APLOG_WARNING,APR_FROM_OS_ERROR(GetLastError())
326 #define FCGI_LOG_NOTICE __FILE__,__LINE__,APLOG_NOTICE,APR_FROM_OS_ERROR(GetLastError())
327 #define FCGI_LOG_INFO __FILE__,__LINE__,APLOG_INFO,APR_FROM_OS_ERROR(GetLastError())
328 #define FCGI_LOG_DEBUG __FILE__,__LINE__,APLOG_DEBUG,APR_FROM_OS_ERROR(GetLastError())
329 #else /* !WIN32 */
330 #define FCGI_LOG_EMERG __FILE__,__LINE__,APLOG_EMERG,APR_FROM_OS_ERROR(errno)
331 #define FCGI_LOG_ALERT __FILE__,__LINE__,APLOG_ALERT,APR_FROM_OS_ERROR(errno)
332 #define FCGI_LOG_CRIT __FILE__,__LINE__,APLOG_CRIT,APR_FROM_OS_ERROR(errno)
333 #define FCGI_LOG_ERR __FILE__,__LINE__,APLOG_ERR,APR_FROM_OS_ERROR(errno)
334 #define FCGI_LOG_WARN __FILE__,__LINE__,APLOG_WARNING,APR_FROM_OS_ERROR(errno)
335 #define FCGI_LOG_NOTICE __FILE__,__LINE__,APLOG_NOTICE,APR_FROM_OS_ERROR(errno)
336 #define FCGI_LOG_INFO __FILE__,__LINE__,APLOG_INFO,APR_FROM_OS_ERROR(errno)
337 #define FCGI_LOG_DEBUG __FILE__,__LINE__,APLOG_DEBUG,APR_FROM_OS_ERROR(errno)
338 #endif
340 #define FCGI_LOG_EMERG_ERRNO __FILE__,__LINE__,APLOG_EMERG,APR_FROM_OS_ERROR(errno)
341 #define FCGI_LOG_ALERT_ERRNO __FILE__,__LINE__,APLOG_ALERT,APR_FROM_OS_ERROR(errno)
342 #define FCGI_LOG_CRIT_ERRNO __FILE__,__LINE__,APLOG_CRIT,APR_FROM_OS_ERROR(errno)
343 #define FCGI_LOG_ERR_ERRNO __FILE__,__LINE__,APLOG_ERR,APR_FROM_OS_ERROR(errno)
344 #define FCGI_LOG_WARN_ERRNO __FILE__,__LINE__,APLOG_WARNING,APR_FROM_OS_ERROR(errno)
345 #define FCGI_LOG_NOTICE_ERRNO __FILE__,__LINE__,APLOG_NOTICE,APR_FROM_OS_ERROR(errno)
346 #define FCGI_LOG_INFO_ERRNO __FILE__,__LINE__,APLOG_INFO,APR_FROM_OS_ERROR(errno)
347 #define FCGI_LOG_DEBUG_ERRNO __FILE__,__LINE__,APLOG_DEBUG,APR_FROM_OS_ERROR(errno)
349 #define FCGI_LOG_EMERG_NOERRNO __FILE__,__LINE__,APLOG_EMERG,0
350 #define FCGI_LOG_ALERT_NOERRNO __FILE__,__LINE__,APLOG_ALERT,0
351 #define FCGI_LOG_CRIT_NOERRNO __FILE__,__LINE__,APLOG_CRIT,0
352 #define FCGI_LOG_ERR_NOERRNO __FILE__,__LINE__,APLOG_ERR,0
353 #define FCGI_LOG_WARN_NOERRNO __FILE__,__LINE__,APLOG_WARNING,0
354 #define FCGI_LOG_NOTICE_NOERRNO __FILE__,__LINE__,APLOG_NOTICE,0
355 #define FCGI_LOG_INFO_NOERRNO __FILE__,__LINE__,APLOG_INFO,0
356 #define FCGI_LOG_DEBUG_NOERRNO __FILE__,__LINE__,APLOG_DEBUG,0
358 #else /* !APACHE2 */
360 #ifdef WIN32
361 #define FCGI_LOG_EMERG __FILE__,__LINE__,APLOG_EMERG|APLOG_WIN32ERROR
362 #define FCGI_LOG_ALERT __FILE__,__LINE__,APLOG_ALERT|APLOG_WIN32ERROR
363 #define FCGI_LOG_CRIT __FILE__,__LINE__,APLOG_CRIT|APLOG_WIN32ERROR
364 #define FCGI_LOG_ERR __FILE__,__LINE__,APLOG_ERR|APLOG_WIN32ERROR
365 #define FCGI_LOG_WARN __FILE__,__LINE__,APLOG_WARNING|APLOG_WIN32ERROR
366 #define FCGI_LOG_NOTICE __FILE__,__LINE__,APLOG_NOTICE|APLOG_WIN32ERROR
367 #define FCGI_LOG_INFO __FILE__,__LINE__,APLOG_INFO|APLOG_WIN32ERROR
368 #define FCGI_LOG_DEBUG __FILE__,__LINE__,APLOG_DEBUG|APLOG_WIN32ERROR
369 #else /* !WIN32 */
370 #define FCGI_LOG_EMERG __FILE__,__LINE__,APLOG_EMERG
371 #define FCGI_LOG_ALERT __FILE__,__LINE__,APLOG_ALERT
372 #define FCGI_LOG_CRIT __FILE__,__LINE__,APLOG_CRIT
373 #define FCGI_LOG_ERR __FILE__,__LINE__,APLOG_ERR
374 #define FCGI_LOG_WARN __FILE__,__LINE__,APLOG_WARNING
375 #define FCGI_LOG_NOTICE __FILE__,__LINE__,APLOG_NOTICE
376 #define FCGI_LOG_INFO __FILE__,__LINE__,APLOG_INFO
377 #define FCGI_LOG_DEBUG __FILE__,__LINE__,APLOG_DEBUG
378 #endif
380 #define FCGI_LOG_EMERG_ERRNO __FILE__,__LINE__,APLOG_EMERG /* system is unusable */
381 #define FCGI_LOG_ALERT_ERRNO __FILE__,__LINE__,APLOG_ALERT /* action must be taken immediately */
382 #define FCGI_LOG_CRIT_ERRNO __FILE__,__LINE__,APLOG_CRIT /* critical conditions */
383 #define FCGI_LOG_ERR_ERRNO __FILE__,__LINE__,APLOG_ERR /* error conditions */
384 #define FCGI_LOG_WARN_ERRNO __FILE__,__LINE__,APLOG_WARNING /* warning conditions */
385 #define FCGI_LOG_NOTICE_ERRNO __FILE__,__LINE__,APLOG_NOTICE /* normal but significant condition */
386 #define FCGI_LOG_INFO_ERRNO __FILE__,__LINE__,APLOG_INFO /* informational */
387 #define FCGI_LOG_DEBUG_ERRNO __FILE__,__LINE__,APLOG_DEBUG /* debug-level messages */
389 #define FCGI_LOG_EMERG_NOERRNO __FILE__,__LINE__,APLOG_EMERG|APLOG_NOERRNO
390 #define FCGI_LOG_ALERT_NOERRNO __FILE__,__LINE__,APLOG_ALERT|APLOG_NOERRNO
391 #define FCGI_LOG_CRIT_NOERRNO __FILE__,__LINE__,APLOG_CRIT|APLOG_NOERRNO
392 #define FCGI_LOG_ERR_NOERRNO __FILE__,__LINE__,APLOG_ERR|APLOG_NOERRNO
393 #define FCGI_LOG_WARN_NOERRNO __FILE__,__LINE__,APLOG_WARNING|APLOG_NOERRNO
394 #define FCGI_LOG_NOTICE_NOERRNO __FILE__,__LINE__,APLOG_NOTICE|APLOG_NOERRNO
395 #define FCGI_LOG_INFO_NOERRNO __FILE__,__LINE__,APLOG_INFO|APLOG_NOERRNO
396 #define FCGI_LOG_DEBUG_NOERRNO __FILE__,__LINE__,APLOG_DEBUG|APLOG_NOERRNO
398 #endif /* !APACHE2 */
400 #ifdef FCGI_DEBUG
401 #define FCGIDBG1(a) ap_log_error(FCGI_LOG_DEBUG,fcgi_apache_main_server,a);
402 #define FCGIDBG2(a,b) ap_log_error(FCGI_LOG_DEBUG,fcgi_apache_main_server,a,b);
403 #define FCGIDBG3(a,b,c) ap_log_error(FCGI_LOG_DEBUG,fcgi_apache_main_server,a,b,c);
404 #define FCGIDBG4(a,b,c,d) ap_log_error(FCGI_LOG_DEBUG,fcgi_apache_main_server,a,b,c,d);
405 #define FCGIDBG5(a,b,c,d,e) ap_log_error(FCGI_LOG_DEBUG,fcgi_apache_main_server,a,b,c,d,e);
406 #define FCGIDBG6(a,b,c,d,e,f) ap_log_error(FCGI_LOG_DEBUG,fcgi_apache_main_server,a,b,c,d,e,f);
407 #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);
408 #else
409 #define FCGIDBG1(a)
410 #define FCGIDBG2(a,b)
411 #define FCGIDBG3(a,b,c)
412 #define FCGIDBG4(a,b,c,d)
413 #define FCGIDBG5(a,b,c,d,e)
414 #define FCGIDBG6(a,b,c,d,e,f)
415 #define FCGIDBG7(a,b,c,d,e,f,g)
416 #endif
419 * Holds the status of the sending of the environment.
420 * A quick hack to dump the static vars for the NT port.
422 typedef struct {
423 enum { PREP, HEADER, NAME, VALUE } pass;
424 char **envp;
425 int headerLen, nameLen, valueLen, totalLen;
426 char *equalPtr;
427 unsigned char headerBuff[8];
428 } env_status;
431 * fcgi_config.c
433 void *fcgi_config_create_dir_config(pool *p, char *dummy);
434 const char *fcgi_config_make_dir(pool *tp, char *path);
435 const char *fcgi_config_make_dynamic_dir(pool *p, const int wax);
436 const char *fcgi_config_new_static_server(cmd_parms *cmd, void *dummy, const char *arg);
437 const char *fcgi_config_new_external_server(cmd_parms *cmd, void *dummy, const char *arg);
438 const char *fcgi_config_set_config(cmd_parms *cmd, void *dummy, const char *arg);
439 const char *fcgi_config_set_fcgi_uid_n_gid(int set);
441 const char *fcgi_config_new_auth_server(cmd_parms * cmd,
442 void *dir_config, const char *fs_path, const char * compat);
444 const char *fcgi_config_set_authoritative_slot(cmd_parms * cmd,
445 void * dir_config, int arg);
446 const char *fcgi_config_set_socket_dir(cmd_parms *cmd, void *dummy, const char *arg);
447 const char *fcgi_config_set_wrapper(cmd_parms *cmd, void *dummy, const char *arg);
448 apcb_t fcgi_config_reset_globals(void * dummy);
449 const char *fcgi_config_set_env_var(pool *p, char **envp, unsigned int *envc, char * var);
452 * fcgi_pm.c
454 #if defined(WIN32) || defined(APACHE2)
455 void fcgi_pm_main(void *dummy);
456 #else
457 int fcgi_pm_main(void *dummy, child_info *info);
458 #endif
461 * fcgi_protocol.c
463 void fcgi_protocol_queue_begin_request(fcgi_request *fr);
464 void fcgi_protocol_queue_client_buffer(fcgi_request *fr);
465 int fcgi_protocol_queue_env(request_rec *r, fcgi_request *fr, env_status *env);
466 int fcgi_protocol_dequeue(pool *p, fcgi_request *fr);
469 * fcgi_buf.c
471 #define BufferLength(b) ((b)->length)
472 #define BufferFree(b) ((b)->size - (b)->length)
474 void fcgi_buf_reset(Buffer *bufPtr);
475 Buffer *fcgi_buf_new(pool *p, int size);
477 #ifndef WIN32
478 typedef int SOCKET;
479 #endif
481 int fcgi_buf_socket_recv(Buffer *b, SOCKET socket);
482 int fcgi_buf_socket_send(Buffer *b, SOCKET socket);
484 void fcgi_buf_added(Buffer * const b, const unsigned int len);
485 void fcgi_buf_removed(Buffer * const b, unsigned int len);
486 void fcgi_buf_get_block_info(Buffer *bufPtr, char **beginPtr, int *countPtr);
487 void fcgi_buf_toss(Buffer *bufPtr, int count);
488 void fcgi_buf_get_free_block_info(Buffer *bufPtr, char **endPtr, int *countPtr);
489 void fcgi_buf_add_update(Buffer *bufPtr, int count);
490 int fcgi_buf_add_block(Buffer *bufPtr, char *data, int datalen);
491 int fcgi_buf_add_string(Buffer *bufPtr, char *str);
492 int fcgi_buf_get_to_block(Buffer *bufPtr, char *data, int datalen);
493 void fcgi_buf_get_to_buf(Buffer *toPtr, Buffer *fromPtr, int len);
494 void fcgi_buf_get_to_array(Buffer *buf, array_header *arr, int len);
497 * fcgi_util.c
500 char *fcgi_util_socket_hash_filename(pool *p, const char *path,
501 const char *user, const char *group);
502 const char *fcgi_util_socket_make_path_absolute(pool * const p,
503 const char *const file, const int dynamic);
504 #ifndef WIN32
505 const char *fcgi_util_socket_make_domain_addr(pool *p, struct sockaddr_un **socket_addr,
506 int *socket_addr_len, const char *socket_path);
507 #endif
508 const char *fcgi_util_socket_make_inet_addr(pool *p, struct sockaddr_in **socket_addr,
509 int *socket_addr_len, const char *host, unsigned short port);
510 const char *fcgi_util_check_access(pool *tp,
511 const char * const path, const struct stat *statBuf,
512 const int mode, const uid_t uid, const gid_t gid);
513 fcgi_server *fcgi_util_fs_get_by_id(const char *ePath, uid_t uid, gid_t gid);
514 fcgi_server *fcgi_util_fs_get(const char *ePath, const char *user, const char *group);
515 const char *fcgi_util_fs_is_path_ok(pool * const p, const char * const fs_path, struct stat *finfo);
516 fcgi_server *fcgi_util_fs_new(pool *p);
517 void fcgi_util_fs_add(fcgi_server *s);
518 const char *fcgi_util_fs_set_uid_n_gid(pool *p, fcgi_server *s, uid_t uid, gid_t gid);
519 ServerProcess *fcgi_util_fs_create_procs(pool *p, int num);
521 int fcgi_util_ticks(struct timeval *);
523 #ifdef WIN32
524 int fcgi_pm_add_job(fcgi_pm_job *new_job);
525 #endif
527 uid_t fcgi_util_get_server_uid(const server_rec * const s);
528 gid_t fcgi_util_get_server_gid(const server_rec * const s);
531 * Globals
534 extern pool *fcgi_config_pool;
536 extern server_rec *fcgi_apache_main_server;
538 extern const char *fcgi_wrapper; /* wrapper path */
539 extern uid_t fcgi_user_id; /* the run uid of Apache & PM */
540 extern gid_t fcgi_group_id; /* the run gid of Apache & PM */
542 extern fcgi_server *fcgi_servers;
544 extern char *fcgi_socket_dir; /* default FastCgiIpcDir */
546 /* pipe used for comm between the request handlers and the PM */
547 extern int fcgi_pm_pipe[];
549 extern pid_t fcgi_pm_pid;
551 extern char *fcgi_dynamic_dir; /* directory for the dynamic
552 * fastcgi apps' sockets */
554 extern char *fcgi_empty_env;
556 extern int fcgi_dynamic_total_proc_count;
557 extern time_t fcgi_dynamic_epoch;
558 extern time_t fcgi_dynamic_last_analyzed;
560 #ifdef WIN32
561 extern HANDLE *fcgi_dynamic_mbox_mutex;
562 extern HANDLE fcgi_event_handles[3];
563 extern fcgi_pm_job *fcgi_dynamic_mbox;
564 #endif
566 extern u_int dynamicMaxProcs;
567 extern int dynamicMinProcs;
568 extern int dynamicMaxClassProcs;
569 extern u_int dynamicKillInterval;
570 extern u_int dynamicUpdateInterval;
571 extern float dynamicGain;
572 extern int dynamicThreshold1;
573 extern int dynamicThresholdN;
574 extern u_int dynamicPleaseStartDelay;
575 extern u_int dynamicAppConnectTimeout;
576 extern char **dynamicEnvp;
577 extern u_int dynamicProcessSlack;
578 extern int dynamicAutoRestart;
579 extern int dynamicAutoUpdate;
580 extern u_int dynamicListenQueueDepth;
581 extern u_int dynamicInitStartDelay;
582 extern u_int dynamicRestartDelay;
583 extern array_header *dynamic_pass_headers;
584 extern u_int dynamic_idle_timeout;
585 extern int dynamicFlush;
587 extern module MODULE_VAR_EXPORT fastcgi_module;
589 #endif /* FCGI_H */