00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __AWHANDLER_WWW__
00024 #define __AWHANDLER_WWW__
00025
00026 #include "monitor.h"
00027
00028 #include "trie.h"
00029
00031
00032
00058 #ifndef AW_WWWHANDLER_SERVER
00059 #define AW_WWWHANDLER_SERVER "wwwhandler/Aware" AW_VERSION
00060 #endif
00061
00062
00063 #define AW_WWWHANDLER_CGIPAGE_MAXSIZE (10 * (1024 * 1024))
00064
00068 typedef enum {
00069
00070 AW_WWWHANDLER_FLAG_NOFILEOPS = 0x1,
00072 } aw_wwwhandler_flags_t;
00073
00074
00078 typedef enum {
00079
00080 AW_WWWHANDLER_XTN_HEAD,
00081 AW_WWWHANDLER_XTN_GET,
00082
00083 } aw_wwwhandler_xtn_type_cd_t;
00084
00085
00089 typedef enum {
00090
00091 AW_WWWHANDLER_XTN_WAIT_REQUEST,
00092 AW_WWWHANDLER_XTN_WAIT_HDR_REPLY,
00093 AW_WWWHANDLER_XTN_WAIT_SND_REPLY,
00094 AW_WWWHANDLER_XTN_DONE,
00096 } aw_wwwhandler_xtn_state_cd_t;
00097
00098
00099 typedef enum {
00100
00101 IO_OK,
00102 IO_CONT,
00103 IO_ERR,
00104 IO_KEEP_ALIVE_CLOSE
00105
00106 } aw_wwwhandler_io_code_t;
00107
00108
00112 typedef struct {
00113
00114
00115 u_int64_t
00116 writesize;
00117
00118
00119 int32_t
00120 fd;
00121
00122
00123 byte_t
00124 *data;
00125
00126
00127 int64_t
00128 partial_offset, partial_len;
00129
00130 } aw_wwwhandler_xtn_getinfo_t;
00131
00135 typedef struct aw_wwwhandler_xtn_s {
00136
00137 aw_wwwhandler_xtn_type_cd_t
00138 type_cd;
00139
00140 aw_wwwhandler_xtn_state_cd_t
00141 state_cd;
00142
00143
00144 int32_t
00145 response_cd;
00146
00147
00148 aw_monitor_t
00149 *mon;
00150
00151
00152 struct aw_wwwhandler_s
00153 *h;
00154
00155
00156 int32_t
00157 txfd;
00158
00159
00160 aw_ip_addr_t
00161 clientip;
00162
00163
00164 byte_t
00165 *eoheader;
00166
00167
00168 int32_t
00169 keep_alive;
00170
00171
00172 int32_t
00173 count;
00174
00175
00176 aw_timestamp_t
00177 starttime,
00178 timeout;
00179
00180
00181 aw_address_t
00182 timeout_eventid;
00183
00184
00185 int32_t
00186 forkpid;
00187
00188
00189
00190
00191 byte_t
00192 *appendlog;
00193
00194
00195 u_int32_t
00196 nbytes;
00197
00198
00199 byte_t
00200 path[1024];
00201
00202
00203 byte_t
00204 buffer[2048];
00205
00206
00207 aw_wwwhandler_xtn_getinfo_t
00208 getinfo;
00209
00210
00211 struct {
00212
00213
00214 byte_t
00215 *header_block;
00216
00217
00218 byte_t
00219 *message_block;
00220
00221
00222 u_int32_t
00223 content_length;
00224
00225
00226 byte_t
00227 *command, *args, *headers;
00228
00229
00230 byte_t
00231 *args_end;
00232
00233
00234 aw_hashString_t
00235 *args_dict;
00236
00237
00238 aw_wwwhandler_io_code_t (*header)(aw_handler_args_t *args, struct aw_wwwhandler_xtn_s *xtn);
00239
00240
00241 aw_wwwhandler_io_code_t (*handler)(aw_handler_args_t *args, struct aw_wwwhandler_xtn_s *xtn);
00242
00243 struct {
00244
00245
00246
00247 u_int32_t
00248 nbytes_allocated,
00249 nbytes;
00250
00251 byte_t
00252 *data;
00253
00254 } page ;
00255
00256 } cgi;
00257
00258
00259 aw_wwwhandler_io_code_t (*do_reply)(aw_handler_args_t *args, struct aw_wwwhandler_xtn_s *xtn);
00260
00261 } aw_wwwhandler_xtn_t;
00262
00263
00267 typedef struct {
00268
00269
00270 int32_t
00271 sfd;
00272
00273 aw_cache_allocator_t
00274 xtn_factory;
00275
00276
00277 aw_hash32_t
00278 *fd2xtn,
00279 *eventid2xtn;
00281 } aw_wwwhandler_state_t;
00282
00286 typedef struct {
00287
00288 aw_event_sig_t
00289 xtn_info;
00291 } aw_wwwhandler_xtn_events_t;
00292
00296 typedef struct aw_wwwhandler_s {
00297
00298 aw_handler_t
00299 handler_header;
00300
00301 aw_wwwhandler_state_t
00302 state;
00303
00304 u_int32_t
00305 port;
00306
00307
00308 aw_ip_addr_t
00309 bind;
00310
00311
00312 byte_t
00313 *docroot;
00314
00315
00316 aw_wwwhandler_xtn_events_t
00317 events;
00318
00319
00320 aw_wwwhandler_flags_t
00321 flags;
00322
00323
00324 int32_t
00325 get_cache_control_max_age;
00326
00327
00328 u_int32_t
00329 max_connections;
00330
00331
00332 byte_t
00333 default_charset[16];
00334
00335
00336 aw_trie_t
00337 *suffix2mime;
00338
00339 int32_t (*dispatch_cgi)(aw_wwwhandler_xtn_t *xtn);
00341 aw_handler_code_t (*start)(aw_monitor_t *mon, struct aw_wwwhandler_s *);
00343 aw_handler_code_t (*stop)(aw_monitor_t *mon, struct aw_wwwhandler_s *);
00345 } aw_wwwhandler_t ;
00346
00347
00348
00349 typedef struct {
00350
00351 byte_t *suffix;
00352
00353 u_int32_t suffixlen;
00354
00355 byte_t *mime_type;
00356
00357 } aw_suffix2mime_t;
00358
00359
00360 typedef struct {
00361
00362 byte_t *mime_types_path;
00364 byte_t *default_charset;
00366 aw_wwwhandler_flags_t flags;
00368 aw_ip_addr_t bind;
00370 int32_t get_cache_control_max_age;
00372 u_int32_t max_connections;
00374 aw_wwwhandler_xtn_events_t events;
00375
00376 int32_t (*dispatch_cgi)(aw_wwwhandler_xtn_t *xtn);
00378 aw_handler_code_t (*start)(aw_monitor_t *mon, struct aw_wwwhandler_s *);
00380 aw_handler_code_t (*stop)(aw_monitor_t *mon, struct aw_wwwhandler_s *);
00382 } aw_wwwhandler_options_t;
00383
00394 aw_wwwhandler_io_code_t aw_wwwhandler_do_exec(aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn,
00395 const byte_t *prog, const byte_t *prog_argv[],
00396 const byte_t *httpheader);
00397
00405 aw_wwwhandler_io_code_t aw_wwwhandler_tx_file(aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn);
00406
00414 aw_wwwhandler_io_code_t aw_wwwhandler_tx_header(aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn);
00415
00423 inline const byte_t *aw_wwwhandler_find_cgiheader_line(aw_wwwhandler_xtn_t *xtn, byte_t *key);
00424
00432 inline const byte_t *aw_wwwhandler_get_cgiarg(aw_wwwhandler_xtn_t *xtn, const byte_t *key);
00433
00442 inline const byte_t *aw_wwwhandler_get_multi_cgiarg(aw_wwwhandler_xtn_t *xtn, const byte_t *key, const byte_t *last);
00443
00451 int32_t aw_wwwhandler_printf_cgipage(aw_wwwhandler_xtn_t *xtn, const char *fmt, ... ) __attribute__ ((format (printf, 2, 3)));
00452
00461 int32_t aw_wwwhandler_append_cgipage(aw_wwwhandler_xtn_t *xtn, void *data, u_int32_t nbytes);
00462
00463
00472 aw_wwwhandler_io_code_t aw_wwwhandler_tx_cgi200(aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn, byte_t *headers);
00473
00481 aw_wwwhandler_io_code_t aw_wwwhandler_tx_cgipage(aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn);
00482
00496 aw_wwwhandler_io_code_t aw_wwwhandler_tx_200(aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn,
00497 time_t lastmod, u_int64_t size,
00498 int32_t max_age,
00499 byte_t *mime_type, byte_t *charset,
00500 byte_t *headers);
00501
00510 aw_wwwhandler_io_code_t aw_wwwhandler_tx_metadata(aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn, u_int32_t dir);
00511
00521 aw_wwwhandler_io_code_t aw_wwwhandler_tx_error(aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn,
00522 u_int32_t code, byte_t *message);
00523
00533 int32_t aw_init_wwwhandler(aw_wwwhandler_t *h,
00534 u_int32_t port,
00535 byte_t *docroot,
00536 aw_wwwhandler_options_t *options,
00537 aw_logger_t *logger
00538 );
00539
00540
00549 aw_wwwhandler_t *aw_create_wwwhandler( u_int32_t port,
00550 byte_t *docroot,
00551 aw_wwwhandler_options_t *options,
00552 aw_logger_t *logger
00553 );
00554
00559 void aw_free_wwwhandler(aw_wwwhandler_t *p);
00560
00561
00562
00563 #endif
00564