#include <stdio.h> #include <stdlib.h> #define NI_MAXHOST 20 #define CGI_ENV_MAX 50 #define SOCKETBUF_SIZE 8192 #define MAX_HEADER_LENGTH 1024 #define CLIENT_STREAM_SIZE SOCKETBUF_SIZE #define BUFFER_SIZE CLIENT_STREAM_SIZE struct mmap_entry { dev_t dev; ino_t ino; char *mmap; int use_count; size_t len; }; struct request { /* pending requests */ int fd; /* client's socket fd */ int status; /* see #defines.h */ time_t time_last; /* time of last succ. op. */ char *pathname; /* pathname of requested file */ int simple; /* simple request? */ int keepalive; /* keepalive status */ int kacount; /* keepalive count */ int data_fd; /* fd of data */ unsigned long filesize; /* filesize */ unsigned long filepos; /* position in file */ char *data_mem; /* mmapped/malloced char array */ int method; /* M_GET, M_POST, etc. */ char *logline; /* line to log file */ char *header_line; /* beginning of un or incompletely processed header line */ char *header_end; /* last known end of header, or end of processed data */ int parse_pos; /* how much have we parsed */ int client_stream_pos; /* how much have we read... */ int buffer_start; /* where the buffer starts */ int buffer_end; /* where the buffer ends */ char *http_version; /* HTTP/?.? of req */ int response_status; /* R_NOT_FOUND etc. */ char *if_modified_since; /* If-Modified-Since */ time_t last_modified; /* Last-modified: */ char local_ip_addr[NI_MAXHOST]; /* for virtualhost */ /* CGI vars */ int remote_port; /* could be used for ident */ char remote_ip_addr[NI_MAXHOST]; /* after inet_ntoa */ int is_cgi; /* true if CGI/NPH */ int cgi_status; int cgi_env_index; /* index into array */ /* Agent and referer for logfiles */ char *header_user_agent; char *header_referer; int post_data_fd; /* fd for post data tmpfile */ char *path_info; /* env variable */ char *path_translated; /* env variable */ char *script_name; /* env variable */ char *query_string; /* env variable */ char *content_type; /* env variable */ char *content_length; /* env variable */ struct mmap_entry *mmap_entry_var; struct request *next; /* next */ struct request *prev; /* previous */ /* everything below this line is kept regardless */ char buffer[BUFFER_SIZE + 1]; /* generic I/O buffer */ char request_uri[MAX_HEADER_LENGTH + 1]; /* uri */ char client_stream[CLIENT_STREAM_SIZE]; /* data from client - fit or be hosed */ char *cgi_env[CGI_ENV_MAX + 4]; /* CGI environment */ #ifdef ACCEPT_ON char accept[MAX_ACCEPT_LENGTH]; /* Accept: fields */ #endif }; typedef struct request request; int main (int argc, char **argv) { void (*child_func)(request *req,int *pipes,int use_pipes); request *req; int *pipes; int use_pipes; child_func = (void *) atoi(argv[0]); req = (request *)atoi(argv[1]); pipes = (int *) atoi(argv[2]); use_pipes = *((int *) atoi(argv[3])); child_func(req,pipes,use_pipes); return (0); } |