processor.h File Reference

Go to the source code of this file.

Data Structures

struct  entry
struct  inetaddress
struct  request
struct  requestwrapper
struct  response
struct  ServiceImpl

Defines

#define SERVER_NAME   "monit"
#define SERVER_VERSION   VERSION
#define SERVER_URL   "http://www.tildeslash.com/monit/"
#define SERVER_PROTOCOL   "HTTP/1.0"
#define DATEFMT   "%a, %d %b %Y %H:%M:%S GMT"
#define METHOD_GET   "GET"
#define METHOD_POST   "POST"
#define SC_CONTINUE   100
#define SC_SWITCHING_PROTOCOLS   101
#define SC_PROCESSING   102
#define SC_OK   200
#define SC_CREATED   201
#define SC_ACCEPTED   202
#define SC_NON_AUTHORITATIVE   203
#define SC_NO_CONTENT   204
#define SC_RESET_CONTENT   205
#define SC_PARTIAL_CONTENT   206
#define SC_MULTI_STATUS   207
#define SC_MULTIPLE_CHOICES   300
#define SC_MOVED_PERMANENTLY   301
#define SC_MOVED_TEMPORARILY   302
#define SC_SEE_OTHER   303
#define SC_NOT_MODIFIED   304
#define SC_USE_PROXY   305
#define SC_TEMPORARY_REDIRECT   307
#define SC_BAD_REQUEST   400
#define SC_UNAUTHORIZED   401
#define SC_PAYMENT_REQUIRED   402
#define SC_FORBIDDEN   403
#define SC_NOT_FOUND   404
#define SC_METHOD_NOT_ALLOWED   405
#define SC_NOT_ACCEPTABLE   406
#define SC_PROXY_AUTHENTICATION_REQUIRED   407
#define SC_REQUEST_TIMEOUT   408
#define SC_CONFLICT   409
#define SC_GONE   410
#define SC_LENGTH_REQUIRED   411
#define SC_PRECONDITION_FAILED   412
#define SC_REQUEST_ENTITY_TOO_LARGE   413
#define SC_REQUEST_URI_TOO_LARGE   414
#define SC_UNSUPPORTED_MEDIA_TYPE   415
#define SC_RANGE_NOT_SATISFIABLE   416
#define SC_EXPECTATION_FAILED   417
#define SC_UNPROCESSABLE_ENTITY   422
#define SC_LOCKED   423
#define SC_FAILED_DEPENDENCY   424
#define SC_INTERNAL_SERVER_ERROR   500
#define SC_NOT_IMPLEMENTED   501
#define SC_BAD_GATEWAY   502
#define SC_SERVICE_UNAVAILABLE   503
#define SC_GATEWAY_TIMEOUT   504
#define SC_VERSION_NOT_SUPPORTED   505
#define SC_VARIANT_ALSO_VARIES   506
#define SC_INSUFFICIENT_STORAGE   507
#define SC_NOT_EXTENDED   510
#define STRLEN   256
#define REQ_STRLEN   1024
#define RES_STRLEN   2048
#define REQUEST_TIMEOUT   30
#define TRUE   1
#define FALSE   0

Typedefs

typedef entryHttpHeader
typedef entryHttpParameter
typedef inetaddressInetAddress
typedef requestwrapperRequestWrapper
typedef requestHttpRequest
typedef responseHttpResponse

Functions

void * http_processor (void *)
 Process a HTTP request.

void add_Impl (void *doGetFunc, void *doPostFunc)
 Callback for implementors of cervlet functions.

void send_error (HttpResponse, int status, char *message)
 Send an error message.

void send_redirect (HttpResponse res, char *location)
 Sends a temporary redirect response to the client using the specified redirect Location URL.

void out_print (HttpResponse res, const char *,...)
 Prints a string into the given HttpResponse output buffer.

void set_header (HttpResponse res, char *name, char *value)
 Adds a response header with the given name and value.

void set_status (HttpResponse res, int status, char *status_message)
 Sets the status code for the response.

void set_content_type (HttpResponse res, char *mime)
 Set the response content-type.

char * get_header (HttpRequest req, const char *header_name)
 Returns the value of the specified header.

char * get_headers (HttpResponse res)
 Returns a string containing all (extra) headers found in the response.

char * get_parameter (HttpRequest req, const char *parameter_name)
 Returns the value of the specified parameter.

char * get_status_string (int status_code)
 Lookup the corresponding HTTP status string for the given status code.

void destroy_wrapper (RequestWrapper wrapper)
 Free a RequestWrapper object.


Variables

ServiceImpl Impl


Define Documentation

#define DATEFMT   "%a, %d %b %Y %H:%M:%S GMT"
 

Definition at line 36 of file processor.h.

#define FALSE   0
 

Definition at line 101 of file processor.h.

#define METHOD_GET   "GET"
 

Definition at line 39 of file processor.h.

#define METHOD_POST   "POST"
 

Definition at line 40 of file processor.h.

#define REQ_STRLEN   1024
 

Definition at line 94 of file processor.h.

#define REQUEST_TIMEOUT   30
 

Definition at line 98 of file processor.h.

#define RES_STRLEN   2048
 

Definition at line 95 of file processor.h.

Referenced by get_headers(), and out_print().

#define SC_ACCEPTED   202
 

Definition at line 48 of file processor.h.

Referenced by get_status_string().

#define SC_BAD_GATEWAY   502
 

Definition at line 84 of file processor.h.

Referenced by get_status_string().

#define SC_BAD_REQUEST   400
 

Definition at line 61 of file processor.h.

Referenced by get_status_string().

#define SC_CONFLICT   409
 

Definition at line 70 of file processor.h.

Referenced by get_status_string().

#define SC_CONTINUE   100
 

Definition at line 43 of file processor.h.

Referenced by get_status_string().

#define SC_CREATED   201
 

Definition at line 47 of file processor.h.

Referenced by get_status_string().

#define SC_EXPECTATION_FAILED   417
 

Definition at line 78 of file processor.h.

Referenced by get_status_string().

#define SC_FAILED_DEPENDENCY   424
 

Definition at line 81 of file processor.h.

#define SC_FORBIDDEN   403
 

Definition at line 64 of file processor.h.

Referenced by get_status_string().

#define SC_GATEWAY_TIMEOUT   504
 

Definition at line 86 of file processor.h.

Referenced by get_status_string().

#define SC_GONE   410
 

Definition at line 71 of file processor.h.

Referenced by get_status_string().

#define SC_INSUFFICIENT_STORAGE   507
 

Definition at line 89 of file processor.h.

#define SC_INTERNAL_SERVER_ERROR   500
 

Definition at line 82 of file processor.h.

Referenced by get_status_string().

#define SC_LENGTH_REQUIRED   411
 

Definition at line 72 of file processor.h.

Referenced by get_status_string().

#define SC_LOCKED   423
 

Definition at line 80 of file processor.h.

#define SC_METHOD_NOT_ALLOWED   405
 

Definition at line 66 of file processor.h.

Referenced by get_status_string().

#define SC_MOVED_PERMANENTLY   301
 

Definition at line 55 of file processor.h.

Referenced by get_status_string().

#define SC_MOVED_TEMPORARILY   302
 

Definition at line 56 of file processor.h.

Referenced by get_status_string(), and send_redirect().

#define SC_MULTI_STATUS   207
 

Definition at line 53 of file processor.h.

#define SC_MULTIPLE_CHOICES   300
 

Definition at line 54 of file processor.h.

Referenced by get_status_string().

#define SC_NO_CONTENT   204
 

Definition at line 50 of file processor.h.

Referenced by get_status_string().

#define SC_NON_AUTHORITATIVE   203
 

Definition at line 49 of file processor.h.

Referenced by get_status_string().

#define SC_NOT_ACCEPTABLE   406
 

Definition at line 67 of file processor.h.

Referenced by get_status_string().

#define SC_NOT_EXTENDED   510
 

Definition at line 90 of file processor.h.

#define SC_NOT_FOUND   404
 

Definition at line 65 of file processor.h.

Referenced by get_status_string().

#define SC_NOT_IMPLEMENTED   501
 

Definition at line 83 of file processor.h.

Referenced by get_status_string().

#define SC_NOT_MODIFIED   304
 

Definition at line 58 of file processor.h.

Referenced by get_status_string().

#define SC_OK   200
 

Definition at line 46 of file processor.h.

Referenced by get_status_string().

#define SC_PARTIAL_CONTENT   206
 

Definition at line 52 of file processor.h.

Referenced by get_status_string().

#define SC_PAYMENT_REQUIRED   402
 

Definition at line 63 of file processor.h.

Referenced by get_status_string().

#define SC_PRECONDITION_FAILED   412
 

Definition at line 73 of file processor.h.

Referenced by get_status_string().

#define SC_PROCESSING   102
 

Definition at line 45 of file processor.h.

#define SC_PROXY_AUTHENTICATION_REQUIRED   407
 

Definition at line 68 of file processor.h.

Referenced by get_status_string().

#define SC_RANGE_NOT_SATISFIABLE   416
 

Definition at line 77 of file processor.h.

Referenced by get_status_string().

#define SC_REQUEST_ENTITY_TOO_LARGE   413
 

Definition at line 74 of file processor.h.

Referenced by get_status_string().

#define SC_REQUEST_TIMEOUT   408
 

Definition at line 69 of file processor.h.

Referenced by get_status_string(), and http_processor().

#define SC_REQUEST_URI_TOO_LARGE   414
 

Definition at line 75 of file processor.h.

Referenced by get_status_string().

#define SC_RESET_CONTENT   205
 

Definition at line 51 of file processor.h.

Referenced by get_status_string().

#define SC_SEE_OTHER   303
 

Definition at line 57 of file processor.h.

Referenced by get_status_string().

#define SC_SERVICE_UNAVAILABLE   503
 

Definition at line 85 of file processor.h.

Referenced by get_status_string().

#define SC_SWITCHING_PROTOCOLS   101
 

Definition at line 44 of file processor.h.

Referenced by get_status_string().

#define SC_TEMPORARY_REDIRECT   307
 

Definition at line 60 of file processor.h.

#define SC_UNAUTHORIZED   401
 

Definition at line 62 of file processor.h.

Referenced by get_status_string().

#define SC_UNPROCESSABLE_ENTITY   422
 

Definition at line 79 of file processor.h.

#define SC_UNSUPPORTED_MEDIA_TYPE   415
 

Definition at line 76 of file processor.h.

Referenced by get_status_string().

#define SC_USE_PROXY   305
 

Definition at line 59 of file processor.h.

Referenced by get_status_string().

#define SC_VARIANT_ALSO_VARIES   506
 

Definition at line 88 of file processor.h.

#define SC_VERSION_NOT_SUPPORTED   505
 

Definition at line 87 of file processor.h.

Referenced by get_status_string().

#define SERVER_NAME   "monit"
 

Definition at line 32 of file processor.h.

#define SERVER_PROTOCOL   "HTTP/1.0"
 

Definition at line 35 of file processor.h.

#define SERVER_URL   "http://www.tildeslash.com/monit/"
 

Definition at line 34 of file processor.h.

Referenced by send_error().

#define SERVER_VERSION   VERSION
 

Definition at line 33 of file processor.h.

#define STRLEN   256
 

Definition at line 93 of file processor.h.

#define TRUE   1
 

Definition at line 100 of file processor.h.


Typedef Documentation

typedef struct entry* HttpHeader
 

Definition at line 109 of file processor.h.

typedef struct entry* HttpParameter
 

Definition at line 110 of file processor.h.

typedef struct request * HttpRequest
 

typedef struct response * HttpResponse
 

typedef struct inetaddress * InetAddress
 

typedef struct requestwrapper * RequestWrapper
 


Function Documentation

void add_Impl void *    doGetFunc,
void *    doPostFunc
 

Callback for implementors of cervlet functions.

Parameters:
doGetFunc  doGet function
doPostFunc  doPost function

Definition at line 149 of file processor.c.

References ServiceImpl::doGet, ServiceImpl::doPost, and Impl.

Referenced by init_service().

void destroy_wrapper RequestWrapper    w
 

Free a RequestWrapper object.

Parameters:
w  A RequestWrapper object (Should not be NULL)

Definition at line 303 of file processor.c.

References close_accepted_ssl_socket(), close_socket(), myrun::httpdssl, requestwrapper::inetaddr, inetaddress::local_host, mySSLServerConnection, inetaddress::remote_host, Run, requestwrapper::socket, and requestwrapper::ssl.

Referenced by http_processor(), and start_httpd().

char* get_header HttpRequest    req,
const char *    name
 

Returns the value of the specified header.

Parameters:
req  HttpRequest object
name  Header name to lookup the value for
Returns:
The value of the specified header, NULL if not found

Definition at line 406 of file processor.c.

References request::headers, entry::name, entry::next, entry::value, and xstrdup().

char* get_headers HttpResponse    res
 

Returns a string containing all (extra) headers found in the response.

The headers are newline separated in the returned string.

Parameters:
res  HttpResponse object
Returns:
A String containing all headers set in the Response object

Definition at line 457 of file processor.c.

References response::headers, entry::name, entry::next, RES_STRLEN, entry::value, and xstrdup().

char* get_parameter HttpRequest    req,
const char *    name
 

Returns the value of the specified parameter.

Parameters:
req  HttpRequest object
name  The request parameter key to lookup the value for
Returns:
The value of the specified parameter, or NULL if not found

Definition at line 431 of file processor.c.

References entry::name, entry::next, request::params, entry::value, and xstrdup().

char* get_status_string int    status
 

Lookup the corresponding HTTP status string for the given status code.

Parameters:
status  A HTTP status code
Returns:
A default status message for the specified HTTP status code.

Definition at line 481 of file processor.c.

References SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_GATEWAY_TIMEOUT, SC_GONE, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_RANGE_NOT_SATISFIABLE, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LARGE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY, SC_VERSION_NOT_SUPPORTED, and xstrdup().

Referenced by send_error(), and send_redirect().

void* http_processor void *    wrapper
 

Process a HTTP request.

This is done by dispatching to the service function. Before the dispatch, an alarm clock is setup for handling request timeout.

Parameters:
wrapper  A Wrapper object wrapping the client socket connection

Definition at line 123 of file processor.c.

References destroy_wrapper(), SC_REQUEST_TIMEOUT, and requestwrapper::socket.

Referenced by start_httpd().

void out_print HttpResponse    res,
const char *    format,
...   
 

Prints a string into the given HttpResponse output buffer.

The actual response to the client is done in the service function, which will call the private function send_response. Cervlets should use this function (i.e. out_print) for sending a response, and never use the HttpResponse outputstream directly.

Despite the above warning, IF the HttpResponse.outputstream was used directly by a cervlet THEN the cervlet MUST set the is_committed flag in the HttpResponse object and is responsible for sending all HTTP headers and content by itself.

Parameters:
res  HttpResponse object
format  A formated string to be sent to the client

Definition at line 217 of file processor.c.

References response::bufsize, response::bufused, log(), response::outputbuffer, RES_STRLEN, xmalloc(), and xresize().

Referenced by send_error().

void send_error HttpResponse    res,
int    code,
char *    msg
 

Send an error message.

Parameters:
res  HttpResponse object
code  Error Code to lookup and send
msg  Optional error message (may be NULL)

Definition at line 166 of file processor.c.

References get_status_string(), out_print(), SERVER_URL, set_content_type(), and set_status().

void send_redirect HttpResponse    res,
char *    location
 

Sends a temporary redirect response to the client using the specified redirect Location URL.

The url must be absolute.

Parameters:
res  HttpResponse object
location  An absolute url to redirect to

Definition at line 192 of file processor.c.

References get_status_string(), SC_MOVED_TEMPORARILY, set_header(), and set_status().

void set_content_type HttpResponse    res,
char *    mime
 

Set the response content-type.

Parameters:
res  HttpResponse object
mime  Mime content type, e.g. text/html

Definition at line 393 of file processor.c.

References set_header().

Referenced by send_error().

void set_header HttpResponse    res,
char *    name,
char *    value
 

Adds a response header with the given name and value.

If the header had already been set the new value overwrites the previous one.

Parameters:
res  HttpResponse object
name  Header key name
value  Header key value

Definition at line 338 of file processor.c.

References response::headers, entry::name, NEW, entry::next, entry::value, and xstrdup().

Referenced by send_redirect(), and set_content_type().

void set_status HttpResponse    res,
int    code,
char *    msg
 

Sets the status code for the response.

Parameters:
res  HttpResponse object
code  A HTTP status code <100-510>
msg  The status code string message

Definition at line 379 of file processor.c.

References response::status, response::status_msg, and xstrdup().

Referenced by send_error(), and send_redirect().


Variable Documentation

struct ServiceImpl Impl
 

Definition at line 161 of file processor.h.

Referenced by add_Impl().