Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

httphandler.h

Go to the documentation of this file.
00001 
00002 /*
00003 ** Copyright (C) 2004 Russell Leighton
00004 **
00005 ** This program is free software; you can redistribute it and/or modify
00006 ** it under the terms of the GNU General Public License as published by
00007 ** the Free Software Foundation; either version 2 of the License, or
00008 ** (at your option) any later version.
00009 **
00010 ** This program is distributed in the hope that it will be useful,
00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ** GNU General Public License for more details.
00014 **
00015 ** You should have received a copy of the GNU General Public License
00016 ** along with this program; if not, write to the Free Software
00017 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 */
00019 
00020 
00021 
00022 
00023 #ifndef __AWHANDLER_HTTP__
00024 #define __AWHANDLER_HTTP__
00025 
00026 #include "regexmatch.h"
00027 
00028 #include "sysnet.h" 
00029 #include "monitor.h"
00030 #include "wire.h"
00031 
00152 /*
00153 
00154 Changes:
00155 
00156 03/12/04 Russell Leighton
00157 Port to handler
00158 
00159 05/04/02  Russell Leighton
00160 Added service,noservice events.
00161 
00162 04/16/02  Russell Leighton
00163 Made stateful.
00164 
00165 03/08/02 Russell Leighton
00166 Added triptime: support
00167 
00168 */
00169 
00173 typedef struct {
00174 
00175   aw_event_sig_t
00176    connect,                  
00177    noconnect,                
00178    service,                  
00179    noservice,                
00180    triptime;                 
00183   u_int32_t
00184    statefull;            /* if non-zero then connect/noconnect, service/noservice events will be statefull,
00185                             meaning you only get events on transitions from connect <-> noconnect, service <-> noservice
00186                           */
00187 
00188 } aw_httphandler_cevents_t;
00189 
00190 
00194 typedef struct {
00195 
00196   aw_event_sig_t
00197    match,                    
00198    nomatch;                  
00200 } aw_httphandler_revents_t;
00201 
00205 typedef enum {
00206 
00207   AW_HTTPHANDLER_IDLE,                    
00208   AW_HTTPHANDLER_WAIT_HEAD_CONNECT,       
00209   AW_HTTPHANDLER_WAIT_HEAD_WRITE,         
00210   AW_HTTPHANDLER_WAIT_HEAD_READ,          
00211   AW_HTTPHANDLER_WAIT_GET_CONNECT,        
00212   AW_HTTPHANDLER_WAIT_GET_WRITE,          
00213   AW_HTTPHANDLER_WAIT_GET_READ,           
00214   AW_HTTPHANDLER_DONE                     
00216 } aw_httphandler_state_cd_t;
00217 
00218 /* should be bigger than the MTU you expect...usually, at least 1500 */
00219 #define AW_HTTPHANDLER_READ_BUFFER_SIZE 4096
00220 
00221 /* holds the last value for header (e.g., Last-Modified: Sat, 02 Feb 2002 17:00:14 GMT) */
00222 #define AW_HTTPHANDLER_LASTMODIFIED_BUFFER_SIZE 64
00223 
00224 
00228 typedef struct {
00229 
00230   aw_httphandler_state_cd_t
00231    state_cd;
00232 
00233   int32_t
00234    sfd;
00235 
00236   aw_event_t
00237    *current_event;
00238 
00239   /* marks start time of connection , used for timeouts */
00240   aw_timestamp_t
00241    starttime;
00242 
00243   /* bytes read or written (depending on state_cd) */
00244   u_int32_t
00245    nbytes;
00246 
00247   /* -1 on start and the value of Content-Length: (if present in header) plus header size */
00248   int64_t
00249    data_left;
00250 
00251   byte_t
00252    read_buffer[AW_HTTPHANDLER_READ_BUFFER_SIZE];
00253 
00254   time_t
00255    last_modified;
00256 
00257   /* array 1-1 with the watchers, each val marks
00258      if a match occured during the handler, could be a bitmap, but I am being lazy */
00259   u_int32_t
00260    *match_markers;
00261 
00262   /* 1 if last handler could connect, -1 if noconnect */
00263   int32_t
00264    connect;
00265 
00266   /* 1 if last handler could get service, -1 if noservice */
00267   int32_t
00268    service;
00269 
00270 } aw_httphandler_state_t;
00271 
00272 
00276 typedef struct {
00277 
00278   aw_httphandler_revents_t
00279     revents;
00280 
00281   /* regex string */
00282   const byte_t
00283    *regex;
00284 
00285   /* holds substitution string, may be NULL */
00286   const byte_t
00287    *subst;
00288 
00289 } aw_httphandler_regex_t;
00290 
00294 typedef struct {
00295 
00296   aw_httphandler_revents_t
00297     revents;
00298 
00299   /* holds compiled regular expression  */
00300   regex_t
00301    pattern;
00302 
00303   /* holds substitution string, may be NULL */
00304   byte_t
00305    *subst;
00306 
00307 } aw_httphandler_watcher_t;
00308 
00312 typedef struct {
00313 
00314   byte_t
00315    *filename;
00316 
00317   int32_t
00318    fd;
00319 
00320   aw_event_sig_t
00321    updated;                    /* done updating mirror */
00322 
00323 } aw_httphandler_mirror_t;
00324 
00325 
00329 typedef struct {
00330 
00331   aw_handler_t 
00332     handler_header;
00333 
00334   aw_httphandler_state_t
00335    state;
00336 
00337   aw_httphandler_cevents_t
00338    cevents;
00339 
00340   struct sockaddr_in
00341     service_addr;
00342 
00343   /* used for timeout callbacks */
00344   aw_address_t
00345    timeout_event_id;
00346 
00347   /* sched for timeout alarm */
00348   aw_alarm_sched_t
00349    timeout_sched;
00350 
00351   byte_t
00352     *url,                      /* full URL */
00353     *headreq,                  /* HEAD request */
00354     *getreq;                   /* GET request */
00355 
00356   u_int32_t
00357    nwatchers;
00358 
00359   aw_httphandler_watcher_t
00360    *watchers;
00361 
00362   aw_httphandler_mirror_t
00363    mirror;
00364 
00365 } aw_httphandler_t ;
00366 
00367 
00383 aw_httphandler_t *aw_create_httphandler(const byte_t *url,
00384                                         const aw_httphandler_cevents_t *cevents,
00385                                         const aw_timestamp_t timeout,
00386                                         u_int32_t nregexs,
00387                                         const aw_httphandler_regex_t *regexs,   
00388                                         const byte_t *mirror_filename,       
00389                                         const aw_event_sig_t *mirror_updated,
00390                                         int32_t (*regevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
00391                                         int32_t (*regmaskevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
00392                                         const aw_alarm_sched_t *sched,
00393                                         aw_logger_t *logger
00394                                         );
00395 
00396 
00401 void aw_free_httphandler(aw_httphandler_t *p);
00402 
00403 
00407 aw_handler_t *aw_wire_httphandler(aw_wire_mkhandler_args_t *args);
00408 
00409 
00410 #endif
00411 
Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)