/* Package Name : twhttpd * File Name : structs.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. */ #ifndef STRUCT_H #define STRUCT_H 1 typedef struct decision_tree_st { int inverted ; int (*f)() ; void *value ; void *value2 ; int property ; struct decision_tree_st *and ; struct decision_tree_st *or ; int return_code ; } decision_tree; typedef struct ip_range_struct { unsigned long start_addr; unsigned long end_addr; } ip_range_t; typedef struct cfg_variable_struct { int type; int (*f)(); } cfg_variable; /* proxy specific options */ typedef struct srv_cfg_struct { int fd; /* listening file descriptor */ struct sockaddr_in ip; /* listening IP */ struct sockaddr_in forward; /* destination server */ int forward_proxy; /* proxy mode: web/proxy */ int local; /* local server or proxy server */ FILE *alog; /* fd for access log */ FILE *elog; /* fd for error log */ int enable_cache; /* enable caching function */ int enable_cookie_chk; /* enable cookie validation */ int safe_url; /* enable safe url check */ int enable_ftp; /* enable FTP server on port 21 */ int enable_https; /* enable HTTPS server on port 433 */ int srv_hd_chk; /* enable header checks for client request */ int clt_hd_chk; /* enable header checks for server response */ char *srv_ver; /* server version string */ char *browser_ver; /* browser version string */ decision_tree *dt; /* decision tree */ } srv_cfg; /* HTTP server general config there is only one general config per daemon define generic options */ typedef struct gen_cfg_struct { char *work_dir; /* working dir (if defined) */ char *cache_dir; /* caching directory (if enable cache) */ char *cookie_dir; /* cookie check directory */ int enable_chroot; /* enable chroot */ uid_t uid; /* setuid, only valid for chroot */ gid_t gid; /* setgid, only valid for chroot */ int cache_tout; /* normal cache timeout, default 24hr */ int cache_fast_tout; /* fast cache timeout, use when user agent issue reload */ char *mime_type; /* mime type defination */ /* server configs */ struct srv_cfg_struct *sclist[MAX_SC] ; /* srv_cfg ponter array */ } gen_cfg; /* read ahead buffer */ typedef struct rabuf_struct { char a[MAX_RAB]; /* array buffer */ char *p; /* pointer */ int n; /* number of bytes in a */ } rabuf; /* lazy write buffer */ typedef struct lzbuf_struct { char a[MAX_LZB]; /* array buffer */ int n; /* number of bytes in a */ } lzbuf; /* each http instance will have one http_header */ typedef struct http_header_struct { /* config */ struct srv_cfg_struct *sc; /* each http header bind to one cfg */ struct sockaddr_in *forward; /* destination web server address */ /* usually point to sc->foward */ /* except for policy route */ int *forward_proxy; /* proxy mode */ /* mode = 0 means web server mode */ /* mode = 1 means proxy server mode */ /* usually copy from sc->forward_proxy */ int return_code; /* return code use by ACL and logging */ int wrap_301; /* do a 301/302 object move page wrap up */ /* wrap_301 = 1 means do the wrap up */ /* wrap_301 = 0 means do nothing */ /* addresses */ struct sockaddr_in srv_addr; /* local server address */ struct sockaddr_in clt_addr; /* client address */ struct sockaddr_in remote_addr; /* remote address for proxy use */ /* socket elements */ int fd; /* socket file descriptor */ rabuf fd_rab; /* http header buffer for fd */ lzbuf fd_lzb; /* lazy write buffer for fd */ int proxy; /* proxy socket file descriptor */ rabuf proxy_rab; /* http header buffer for proxy */ lzbuf proxy_lzb; /* lazy write buffer for proxy */ /* MUST have these headers for http to work */ char *method; /* GET POST HEAD PUT */ char *version; /* HTTP/1.0 or HTTP/1.1 */ char host[MAX_LINE]; /* request url hostname in host byte order for IPv4 */ struct hostent *host_ent; /* point to gethostbyname hostent result */ int port; /* request url port number in host byte order */ char opath[MAX_LINE]; /* original user request url */ char path[MAX_LINE]; /* request file path */ char *ext; /* request file extension, if any */ char abs_url[MAX_LINE]; /* md5 hash of host:port/path?query */ char hash[MAX_LINE]; /* hash = [hash data].header */ char *hashptr; /* hashptr point to the dot to get header file, set *hashptr = '.' to get hash data file, set *hashptr = '\0' */ /* this is mainly for 301/302 Object Moved */ char location[MAX_LINE]; /* internal use flags */ int local; /* local request or proxy request, 0/1 */ int cgi; /* is it a cgi request, 0/1 */ int post_len; /* POST form data length */ int no_cache; /* pragma: no-cache, HTTP POST, or with Query String */ int dir; /* directory access or file access */ int byte_count; /* total number of data send */ /* http header options */ char *query; /* get query string, point to path array */ char *sessionid; /* Java Servlet sessionid in URL, point to path array */ char *cookie; /* cookie */ char *referer; /* referer */ char *user_agent; /* user-agent */ char *content_type; /* content-type */ char *accept; /* accept type */ char *accept_charset; /* accept-charset */ char *accept_encoding; /* accept-encoding */ char *accept_language; /* accept-language */ char *range; /* range */ time_t if_mod_since; /* if-modified-since */ char *auth; /* authorization */ char auth_username[MAX_AUTH]; /* decoded auth username */ char *auth_passwd; /* decoded auth passwd */ char *proxy_auth; /* proxy authorization */ char pauth_username[MAX_AUTH]; /* decoded proxy auth username */ char *pauth_passwd; /* decoded proxy auth passwd */ /* can add any other header info like broswer type, referer url, etc. */ } http_header; #endif /* STRUCT_H */