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