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

tcptxthandler.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_TCPTXT__
00024 #define __AWHANDLER_TCPTXT__
00025 
00026 #include <regex.h>
00027 
00028 #include "sysnet.h" 
00029 #include "monitor.h"
00030 #include "wire.h"
00031 
00117 typedef struct {
00118 
00119   aw_event_sig_t
00120    connect,                  /* could connect */
00121    noconnect,                /* could NOT connect */
00122    service,                  /* regex matched */
00123    noservice,                /* regex did NOT match */
00124    triptime;                 /* time to connect+handshake */
00125 
00126 
00127   u_int32_t
00128    statefull;            /* if non-zero then connect/noconnect, service/noservice events will be statefull,
00129                             meaning you only get events on transitions from connect <-> noconnect, service <-> noservice
00130                           */
00131 
00132 
00133 } aw_tcptxthandler_events_t;
00134 
00138 typedef enum {
00139 
00140   AW_TCPTXTHANDLER_IDLE,               /* not doing anything */
00141   AW_TCPTXTHANDLER_WAIT_CONNECT,       /* waiting on a connect() */
00142   AW_TCPTXTHANDLER_WAIT_WRITE,         /* waiting on a write() */
00143   AW_TCPTXTHANDLER_WAIT_READ,          /* waiting on a read() */
00144   AW_TCPTXTHANDLER_DONE                /* done */
00145 
00146 } aw_tcptxthandler_state_cd_t;
00147 
00148 /* should be bigger than the MTU you expect...usually, at least 1500 */
00149 #define AW_TCPTXTHANDLER_READ_BUFFER_SIZE 4096
00150 
00154 typedef struct {
00155 
00156   aw_tcptxthandler_state_cd_t
00157    state_cd;
00158 
00159   int32_t
00160    sfd;
00161 
00162   aw_event_t
00163    *current_event;
00164 
00165   /* marks start of connection */
00166   aw_timestamp_t
00167    starttime;
00168 
00169   /* bytes read or written (depending on state_cd) */
00170   u_int32_t
00171    nbytes;
00172 
00173   /* -1 on start and the value of Content-Length: (if present in header) plus header size */
00174   int32_t
00175    data_left;
00176 
00177   byte_t
00178    read_buffer[AW_TCPTXTHANDLER_READ_BUFFER_SIZE];
00179 
00180   /* 1 if last handler could connect, -1 if noconnect */
00181   int32_t
00182    connect;
00183 
00184   /* 1 if last handler could check service, -1 if noservice */
00185   int32_t
00186    service;
00187 
00188 } aw_tcptxthandler_state_t;
00189 
00193 typedef struct {
00194 
00195   aw_handler_t 
00196     handler_header;
00197 
00198   aw_tcptxthandler_state_t
00199    state;
00200 
00201   aw_tcptxthandler_events_t
00202    events;
00203 
00204   struct sockaddr_in
00205     service_addr;
00206 
00207   /* used for timeout callbacks */
00208   aw_address_t
00209    timeout_event_id;
00210 
00211   /* sched for timeout alarm */
00212   aw_alarm_sched_t
00213    timeout_sched;
00214 
00215   byte_t
00216     *url,                      /* full URL */
00217     *protocol,                 /* parsed from URL */
00218     *hostname,                 /* parsed from URL */
00219     *path,                     /* parsed from URL */
00220     *cmd;                      /* request */
00221 
00222   /* holds compiled regular expression  */
00223   regex_t
00224    pattern;
00225 
00226   /* called for every event to allow altering of cmd (optional) */
00227   void (*process_event)(aw_handler_args_t *args, aw_event_t *event);
00228 
00229 } aw_tcptxthandler_t ;
00230 
00231 
00246 aw_tcptxthandler_t *aw_create_tcptxthandler(const aw_tcptxthandler_events_t *events,
00247                                             const byte_t *url,
00248                                             const u_int32_t default_port,
00249                                             const byte_t *cmd,
00250                                             const byte_t *regexp,
00251                                             const aw_timestamp_t timeout,
00252                                             int32_t (*regevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
00253                                             int32_t (*regmaskevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
00254                                             const aw_alarm_sched_t *sched,
00255                                             aw_logger_t *logger
00256                                             );
00257 
00273 int32_t aw_init_tcptxthandler(aw_tcptxthandler_t *h,
00274                               const aw_tcptxthandler_events_t *events,
00275                               const byte_t *url,
00276                               const u_int32_t default_port,
00277                               const byte_t *cmd,
00278                               const byte_t *regexp,
00279                               const aw_timestamp_t timeout,
00280                               int32_t (*regevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
00281                               int32_t (*regmaskevent)(aw_handler_t *h, aw_address_t *eventid, u_int32_t index),
00282                               const aw_alarm_sched_t *sched,
00283                               aw_logger_t *logger
00284                               );
00285 
00286 
00291 void aw_free_tcptxthandler(aw_tcptxthandler_t *p);
00292 
00293 
00297 aw_handler_t *aw_wire_tcptxthandler(aw_wire_mkhandler_args_t *args);
00298 
00306 aw_handler_t *aw_wire_tcptxthandler_wrapper(const u_int32_t default_port, const byte_t *cmd, 
00307                                             const byte_t *regexp,
00308                                             aw_wire_mkhandler_args_t *args);
00309 
00310 
00311 #endif
00312 
00313 
Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)