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

wwwhandler.h File Reference


Detailed Description

The wwwhandler is a simple http server.

Supports these standard requests (which may be disabled):

Used as a based class for other handlers.

Events generated:
Event NameTypeDescription
xtn_info AW_EVENT_TYPE_STRING Log file record of the form: action|clientip|url|response_code

#include "monitor.h"
#include "trie.h"

Go to the source code of this file.

Data Structures

struct  aw_suffix2mime_t
struct  aw_wwwhandler_options_t
struct  aw_wwwhandler_s
struct  aw_wwwhandler_state_t
 State of handler. More...

struct  aw_wwwhandler_xtn_events_t
struct  aw_wwwhandler_xtn_getinfo_t
 State info on GET. More...

struct  aw_wwwhandler_xtn_s

Defines

#define AW_WWWHANDLER_CGIPAGE_MAXSIZE   (10 * (1024 * 1024))
#define AW_WWWHANDLER_SERVER   "wwwhandler/Aware" AW_VERSION

Typedefs

typedef aw_wwwhandler_s aw_wwwhandler_t
typedef aw_wwwhandler_xtn_s aw_wwwhandler_xtn_t

Enumerations

enum  aw_wwwhandler_flags_t { AW_WWWHANDLER_FLAG_NOFILEOPS = 0x1 }
 boolean options More...

enum  aw_wwwhandler_io_code_t { IO_OK, IO_CONT, IO_ERR, IO_KEEP_ALIVE_CLOSE }
enum  aw_wwwhandler_xtn_state_cd_t { AW_WWWHANDLER_XTN_WAIT_REQUEST, AW_WWWHANDLER_XTN_WAIT_HDR_REPLY, AW_WWWHANDLER_XTN_WAIT_SND_REPLY, AW_WWWHANDLER_XTN_DONE }
 The state codes for each state on xtn, nominal path is straight thru. More...

enum  aw_wwwhandler_xtn_type_cd_t { AW_WWWHANDLER_XTN_HEAD, AW_WWWHANDLER_XTN_GET }
 The type codes for each xtn. More...


Functions

aw_wwwhandler_t * aw_create_wwwhandler (u_int32_t port, byte_t *docroot, aw_wwwhandler_options_t *options, aw_logger_t *logger)
 Create a www handler.

void aw_free_wwwhandler (aw_wwwhandler_t *p)
 Free handler and all associated resources.

int32_t aw_init_wwwhandler (aw_wwwhandler_t *h, u_int32_t port, byte_t *docroot, aw_wwwhandler_options_t *options, aw_logger_t *logger)
 Init a www handler.

int32_t aw_wwwhandler_append_cgipage (aw_wwwhandler_xtn_t *xtn, void *data, u_int32_t nbytes)
 Append to xtn->cgi.page.data.

aw_wwwhandler_io_code_t aw_wwwhandler_do_exec (aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn, const byte_t *prog, const byte_t *prog_argv[], const byte_t *httpheader)
 Run prog rebinding stdout to socket.

const byte_t * aw_wwwhandler_find_cgiheader_line (aw_wwwhandler_xtn_t *xtn, byte_t *key)
 Find string value associated with key from header in cgi GET or POST.

const byte_t * aw_wwwhandler_get_cgiarg (aw_wwwhandler_xtn_t *xtn, const byte_t *key)
 Find string value associated with key from form.

const byte_t * aw_wwwhandler_get_multi_cgiarg (aw_wwwhandler_xtn_t *xtn, const byte_t *key, const byte_t *last)
 Find string value associated with key from form for mutli select.

int32_t aw_wwwhandler_printf_cgipage (aw_wwwhandler_xtn_t *xtn, const char *fmt,...) __attribute__((format(printf
 printf() to xtn->cgi.page.data

aw_wwwhandler_io_code_t aw_wwwhandler_tx_200 (aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn, time_t lastmod, u_int64_t size, int32_t max_age, byte_t *mime_type, byte_t *charset, byte_t *headers)
 Send a 200 response.

aw_wwwhandler_io_code_t aw_wwwhandler_tx_cgi200 (aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn, byte_t *headers)
 Send 200 reponse for cgi page.

aw_wwwhandler_io_code_t aw_wwwhandler_tx_cgipage (aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn)
 Write xtn->cgi.page.data to socket and free at end of xtn.

aw_wwwhandler_io_code_t aw_wwwhandler_tx_error (aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn, u_int32_t code, byte_t *message)
 Reply w/http error code.

aw_wwwhandler_io_code_t aw_wwwhandler_tx_file (aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn)
 Write file as content.

aw_wwwhandler_io_code_t aw_wwwhandler_tx_header (aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn)
 Write xtn->buffer to socket.

aw_wwwhandler_io_code_t aw_wwwhandler_tx_metadata (aw_handler_args_t *args, aw_wwwhandler_xtn_t *xtn, u_int32_t dir)
 Write metadata for file as HEAD response.


Define Documentation

#define AW_WWWHANDLER_CGIPAGE_MAXSIZE   (10 * (1024 * 1024))
 

#define AW_WWWHANDLER_SERVER   "wwwhandler/Aware" AW_VERSION
 


Typedef Documentation

typedef struct aw_wwwhandler_s aw_wwwhandler_t
 

typedef struct aw_wwwhandler_xtn_s aw_wwwhandler_xtn_t
 


Enumeration Type Documentation

enum aw_wwwhandler_flags_t
 

boolean options

Enumeration values:
AW_WWWHANDLER_FLAG_NOFILEOPS  don't allow default file GET and HEAD

enum aw_wwwhandler_io_code_t
 

Enumeration values:
IO_OK 
IO_CONT 
IO_ERR 
IO_KEEP_ALIVE_CLOSE 

enum aw_wwwhandler_xtn_state_cd_t
 

The state codes for each state on xtn, nominal path is straight thru.

Enumeration values:
AW_WWWHANDLER_XTN_WAIT_REQUEST  waiting on a read()
AW_WWWHANDLER_XTN_WAIT_HDR_REPLY  waiting on the header write
AW_WWWHANDLER_XTN_WAIT_SND_REPLY  waiting on the content write
AW_WWWHANDLER_XTN_DONE  no mo'

enum aw_wwwhandler_xtn_type_cd_t
 

The type codes for each xtn.

Enumeration values:
AW_WWWHANDLER_XTN_HEAD 
AW_WWWHANDLER_XTN_GET 


Function Documentation

aw_wwwhandler_t* aw_create_wwwhandler (  u_int32_t  port,
byte_t *  docroot,
aw_wwwhandler_options_t *  options,
aw_logger_t *  logger
) 
 

Create a www handler.

aw_create_wwwhandler

Parameters:
port Port
docroot Path of root of doc tree
options Constructor options (may be NULL)
logger Logger object
Returns:
Handler object

void aw_free_wwwhandler (  aw_wwwhandler_t *  p  ) 
 

Free handler and all associated resources.

aw_free_wwwhandler

Parameters:
p The handler

int32_t aw_init_wwwhandler (  aw_wwwhandler_t *  h,
u_int32_t  port,
byte_t *  docroot,
aw_wwwhandler_options_t *  options,
aw_logger_t *  logger
) 
 

Init a www handler.

aw_init_wwwhandler

Parameters:
h wwwhandler
port Port
docroot Path of root of doc tree
options Constructor options (may be NULL)
logger Logger object
Returns:
Non-zero on error

int32_t aw_wwwhandler_append_cgipage (  aw_wwwhandler_xtn_t *  xtn,
void *  data,
u_int32_t  nbytes
) 
 

Append to xtn->cgi.page.data.

aw_wwwhandler_append_cgipage

Parameters:
xtn Transaction
data Data to append
nbytes How much data
Returns:
0 on success, non-zero on error

aw_wwwhandler_io_code_t aw_wwwhandler_do_exec (  aw_handler_args_t *  args,
aw_wwwhandler_xtn_t *  xtn,
const byte_t *  prog,
const byte_t *  prog_argv[],
const byte_t *  httpheader
) 
 

Run prog rebinding stdout to socket.

aw_wwwhandler_do_exec

Parameters:
args Args
xtn Transaction
prog Path to prog
prog_argv Array of strings with prog 1st and NULL last (see execvp)
httpheader The http header string
Returns:
IO_OK on success

const byte_t* aw_wwwhandler_find_cgiheader_line (  aw_wwwhandler_xtn_t *  xtn,
byte_t *  key
)  [inline]
 

Find string value associated with key from header in cgi GET or POST.

aw_wwwhandler_find_cgiheader_line

Parameters:
xtn Transaction
key Header key
Returns:
Pointer to line or NULL if not found

const byte_t* aw_wwwhandler_get_cgiarg (  aw_wwwhandler_xtn_t *  xtn,
const byte_t *  key
)  [inline]
 

Find string value associated with key from form.

aw_wwwhandler_get_cgiarg

Parameters:
xtn Transaction
key Form key
Returns:
Pointer to value or NULL if not found

const byte_t* aw_wwwhandler_get_multi_cgiarg (  aw_wwwhandler_xtn_t *  xtn,
const byte_t *  key,
const byte_t *  last
)  [inline]
 

Find string value associated with key from form for mutli select.

aw_wwwhandler_get_multi_cgiarg

Parameters:
xtn Transaction
key Form key
last NULL on the 1st call then the output of previous calls to iterate
Returns:
Pointer to value or NULL if not found

int32_t aw_wwwhandler_printf_cgipage (  aw_wwwhandler_xtn_t *  xtn,
const char *  fmt,
... 
) 
 

printf() to xtn->cgi.page.data

aw_wwwhandler_prinf_cgipage

Parameters:
xtn Transaction
fmt Printf style format string (man printf)
Returns:
0 on success, non-zero on error

aw_wwwhandler_io_code_t aw_wwwhandler_tx_200 (  aw_handler_args_t *  args,
aw_wwwhandler_xtn_t *  xtn,
time_t  lastmod,
u_int64_t  size,
int32_t  max_age,
byte_t *  mime_type,
byte_t *  charset,
byte_t *  headers
) 
 

Send a 200 response.

aw_wwwhandler_tx_200

Parameters:
args Args
xtn Transaction
lastmod Last mod time for file
size File size for content
max_age If gt 0, then set Cache-Control: to max_age (seconds), else no-cache
mime_type Mime type for content
charset Character set to use (may be NULL to use handler default)
headers String of extra header lines
Returns:
IO_OK on success

aw_wwwhandler_io_code_t aw_wwwhandler_tx_cgi200 (  aw_handler_args_t *  args,
aw_wwwhandler_xtn_t *  xtn,
byte_t *  headers
) 
 

Send 200 reponse for cgi page.

aw_wwwhandler_tx_cgi200

Parameters:
args Args
xtn Transaction
headers String of extra header lines
Returns:
IO_OK on success

aw_wwwhandler_io_code_t aw_wwwhandler_tx_cgipage (  aw_handler_args_t *  args,
aw_wwwhandler_xtn_t *  xtn
) 
 

Write xtn->cgi.page.data to socket and free at end of xtn.

aw_wwwhandler_tx_cgibuffer

Parameters:
args Args
xtn Transaction
Returns:
IO_OK on success

aw_wwwhandler_io_code_t aw_wwwhandler_tx_error (  aw_handler_args_t *  args,
aw_wwwhandler_xtn_t *  xtn,
u_int32_t  code,
byte_t *  message
) 
 

Reply w/http error code.

aw_wwwhandler_tx_error

Parameters:
args Args
xtn Transaction
code Http error code
message HTML message (may be NULL)
Returns:
IO_OK on success

aw_wwwhandler_io_code_t aw_wwwhandler_tx_file (  aw_handler_args_t *  args,
aw_wwwhandler_xtn_t *  xtn
) 
 

Write file as content.

aw_wwwhandler_tx_file

Parameters:
args Args
xtn Transaction
Returns:
IO_OK on success

aw_wwwhandler_io_code_t aw_wwwhandler_tx_header (  aw_handler_args_t *  args,
aw_wwwhandler_xtn_t *  xtn
) 
 

Write xtn->buffer to socket.

aw_wwwhandler_tx_header

Parameters:
args Args
xtn Transaction
Returns:
IO_OK on success

aw_wwwhandler_io_code_t aw_wwwhandler_tx_metadata (  aw_handler_args_t *  args,
aw_wwwhandler_xtn_t *  xtn,
u_int32_t  dir
) 
 

Write metadata for file as HEAD response.

aw_wwwhandler_tx_metadata

Parameters:
args Args
xtn Transaction
dir If non-zero, append "/index.html" to end of path
Returns:
IO_OK on success

Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)