/* Package Name : twhttpd * File Name : twhttpd.h * Author : Sam NG * * This package is an secure HTTP application proxy writen by Sam Ng. * Copyright (C) 2001 SAM NG * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ #include "config.h" #include "structs.h" /* time format */ #define RFC1123 "%a, %d %b %Y %H:%M:%S GMT" /* here are some common HTTP response code */ #define OK 200 #define MOVED 301 #define MOVED_TEMPORARILY 302 #define NOT_MODIFIED 304 #define BAD_REQUEST 400 #define UNAUTHORIZED 401 #define FORBIDDEN 403 #define NOT_FOUND 404 #define METHOD_NOT_ALLOWED 405 #define PROXY_AUTHENTICATION_REQUIRED 407 #define REQUEST_TIMEOUT 408 #define REQUEST_ENTITY_TOO_LARGE 413 #define REQUEST_URI_TOO_LONG 414 #define INTERNAL_SERVER_ERROR 500 #define NOT_IMPLEMENTED 501 #define BAD_GATEWAY 502 #define SERVICE_UNAVAILABLE 503 #define GATEWAY_TIMEOUT 504 #define HTTP_VERSION_NOT_SUPPORTED 505 /* here are internal use error code */ #define E_SOCK 1001 #define E_SOCK_READ 1002 #define E_SOCK_WRITE 1003 #define WITH_CACHE 1 #define NO_CACHE 0 #define DOMAIN_REGEX "^([0-9a-z]+((\\_|\\-)[0-9a-z]+)*\\.)+(com|net|org|edu|gov|mil|int|[a-z][a-z])$" #define HOST_REGEX "^([0-9a-z]+((\\_|\\-)[0-9a-z]+)*\\.)+(com|net|org|edu|gov|mil|int|[a-z][a-z])(\\:[0-9]{1,3})*$" void daemonize(void); void handle_sigchld(int x); // http library void init_rab(rabuf *rab); void init_lzb(lzbuf *lzb); void init_http_header(http_header *hd); void clean_http_header(http_header *hd); void http_srv(http_header *hd); int http_proxy(http_header *hd); int gen_abs_url(http_header *hd); int parse_location(http_header *hd, char *line); int parse_request(http_header *hd, char *line); int parse_path(http_header *hd); int send_file (http_header *hd, int cache); int send_dir (http_header *hd); int send_request(http_header *hd); int send_header (http_header *hd, int cache, int length, char *mime, time_t at_time); int send_error (http_header *hd, int error_no); // socket related char *read_line(int fd, rabuf *rab); int read_line2(int fd, char *newline, int max, rabuf *rab); int lz_write(int fd, char *line, int length, lzbuf *lzb); int lz_flush(int write_fd, lzbuf *lzb); int wait_writable(int fd); int relay_data(int read_fd, rabuf *rab, int write_fd, int cache_fd, int n); int relay_2way(int fd1, int fd2); int set_nonblock(int fd); int set_block(int fd); int nonb_connect(int fd, struct sockaddr_in *addr, int addr_len); int slow_close(int fd); int Listen_srv(struct sockaddr_in *srv_addr); // string parser and condition checker int hex2int (char c); void de_hexcode (char *str); int hex_encode (char *str, int max_buf); void de_dotdot (char *str); int expand_link (char *path, int link); int search_index (http_header *hd); char *check_mime_type (char *path); char *mode2str (mode_t mode, char *string, int i); int is_dir (char *path); int is_cgi_path (char *path); int resolv_remote(http_header *hd); char *find_ext(char *fname); int invalid_ext(char *ext); int non_ascii(char *fname); int is_hidden(char *fname); int is_dotdotdot(char *fname); int has_meta(char *string, char *meta); int is_valid (char *text, char *pattern); int hash(http_header *); time_t decode_time(char *); int is_cached(http_header *); void show_usage(char *name); void show_version(char *name); /* global variables */ int debug;