httpd.c File Reference

#include <config.h>
#include <isc/buffer.h>
#include <isc/httpd.h>
#include <isc/mem.h>
#include <isc/socket.h>
#include <isc/string.h>
#include <isc/task.h>
#include <isc/time.h>
#include <isc/util.h>

Go to the source code of this file.

Data Structures

struct  isc_httpd
 http client More...
struct  isc_httpdmgr
 lightweight socket manager for httpd output More...

Defines

#define MSHUTTINGDOWN(cm)   ((cm->flags & ISC_HTTPDMGR_FLAGSHUTTINGDOWN) != 0)
 TODO:.
#define MSETSHUTTINGDOWN(cm)   (cm->flags |= ISC_HTTPDMGR_FLAGSHUTTINGDOWN)
#define ENTER(x)   do { } while(0)
#define EXIT(x)   do { } while(0)
#define NOTICE(x)   do { } while(0)
#define HTTP_RECVLEN   1024
#define HTTP_SENDGROW   1024
#define HTTP_SEND_MAXLEN   10240
#define HTTPD_CLOSE   0x0001
#define HTTPD_FOUNDHOST   0x0002
#define ISC_HTTPD_METHODUNKNOWN   0
 HTTP methods.
#define ISC_HTTPD_METHODGET   1
#define ISC_HTTPD_METHODPOST   2
#define ISC_HTTPD_STATEIDLE   0
 Client states.
#define ISC_HTTPD_STATERECV   1
#define ISC_HTTPD_STATERECVDONE   2
#define ISC_HTTPD_STATESEND   3
#define ISC_HTTPD_STATESENDDONE   4
#define ISC_HTTPD_ISRECV(c)   ((c)->state == ISC_HTTPD_STATERECV)
#define ISC_HTTPD_ISRECVDONE(c)   ((c)->state == ISC_HTTPD_STATERECVDONE)
#define ISC_HTTPD_ISSEND(c)   ((c)->state == ISC_HTTPD_STATESEND)
#define ISC_HTTPD_ISSENDDONE(c)   ((c)->state == ISC_HTTPD_STATESENDDONE)
#define ISC_HTTPD_SETRECV(c)   ((c)->state = ISC_HTTPD_STATERECV)
 Overall magic test that means we're not idle.
#define ISC_HTTPD_SETRECVDONE(c)   ((c)->state = ISC_HTTPD_STATERECVDONE)
#define ISC_HTTPD_SETSEND(c)   ((c)->state = ISC_HTTPD_STATESEND)
#define ISC_HTTPD_SETSENDDONE(c)   ((c)->state = ISC_HTTPD_STATESENDDONE)
#define LENGTHOK(s)   (httpd->recvbuf - (s) < (int)httpd->recvlen)
#define BUFLENOK(s)   (httpd->recvbuf - (s) < HTTP_RECVLEN)

Functions

static void isc_httpd_accept (isc_task_t *, isc_event_t *)
static void isc_httpd_recvdone (isc_task_t *, isc_event_t *)
static void isc_httpd_senddone (isc_task_t *, isc_event_t *)
static void destroy_client (isc_httpd_t **)
static isc_result_t process_request (isc_httpd_t *, int)
static void httpdmgr_destroy (isc_httpdmgr_t *)
static isc_result_t grow_headerspace (isc_httpd_t *)
static void reset_client (isc_httpd_t *httpd)
isc_result_t isc_httpdmgr_create (isc_mem_t *mctx, isc_socket_t *sock, isc_task_t *task, isc_httpdclientok_t *client_ok, isc_httpdondestroy_t *ondestroy, void *cb_arg, isc_timermgr_t *tmgr, isc_httpdmgr_t **httpdp)
static isc_result_t render_404 (const char *url, isc_httpdurl_t *urlinfo, const char *querystring, const char *headers, void *arg, unsigned int *retcode, const char **retmsg, const char **mimetype, isc_buffer_t *b, isc_httpdfree_t **freecb, void **freecb_args)
static isc_result_t render_500 (const char *url, isc_httpdurl_t *urlinfo, const char *querystring, const char *headers, void *arg, unsigned int *retcode, const char **retmsg, const char **mimetype, isc_buffer_t *b, isc_httpdfree_t **freecb, void **freecb_args)
void isc_httpdmgr_shutdown (isc_httpdmgr_t **httpdmgrp)
isc_result_t isc_httpd_response (isc_httpd_t *httpd)
isc_result_t isc_httpd_addheader (isc_httpd_t *httpd, const char *name, const char *val)
isc_result_t isc_httpd_endheaders (isc_httpd_t *httpd)
isc_result_t isc_httpd_addheaderuint (isc_httpd_t *httpd, const char *name, int val)
isc_result_t isc_httpdmgr_addurl (isc_httpdmgr_t *httpdmgr, const char *url, isc_httpdaction_t *func, void *arg)
isc_result_t isc_httpdmgr_addurl2 (isc_httpdmgr_t *httpdmgr, const char *url, isc_boolean_t isstatic, isc_httpdaction_t *func, void *arg)

Variables

static isc_httpdaction_t render_404
static isc_httpdaction_t render_500


Detailed Description

Definition in file httpd.c.


Define Documentation

#define MSHUTTINGDOWN ( cm   )     ((cm->flags & ISC_HTTPDMGR_FLAGSHUTTINGDOWN) != 0)

TODO:.

o Put in better checks to make certain things are passed in correctly. This includes a magic number for externally-visible structures, checking for NULL-ness before dereferencing, etc. o Make the URL processing external functions which will fill-in a buffer structure we provide, or return an error and we will render a generic page and close the client.

Definition at line 45 of file httpd.c.

Referenced by httpdmgr_destroy(), and isc_httpd_accept().

#define MSETSHUTTINGDOWN ( cm   )     (cm->flags |= ISC_HTTPDMGR_FLAGSHUTTINGDOWN)

Definition at line 46 of file httpd.c.

Referenced by isc_httpdmgr_shutdown().

#define ENTER (  )     do { } while(0)

Definition at line 53 of file httpd.c.

Referenced by cancel_refresh(), create_keydata(), dns_zone_maintenance(), dump_done(), forward_callback(), httpdmgr_destroy(), isc_httpd_accept(), isc_httpd_recvdone(), isc_httpd_senddone(), isc_httpdmgr_shutdown(), keydone(), ns_query(), process_request(), queue_soa_query(), queue_xfrin(), receive_secure_serial(), refresh_callback(), set_refreshkeytimer(), soa_query(), stub_callback(), zone_dump(), zone_gotwritehandle(), zone_journal(), zone_loaddone(), zone_maintenance(), zone_needdump(), zone_nsec3chain(), zone_refreshkeys(), zone_resigninc(), zone_settimer(), zone_sign(), and zone_timer().

#define EXIT (  )     do { } while(0)

Definition at line 54 of file httpd.c.

Referenced by httpdmgr_destroy(), isc_httpd_accept(), isc_httpd_recvdone(), isc_httpd_senddone(), isc_httpdmgr_shutdown(), and process_request().

#define NOTICE (  )     do { } while(0)

Definition at line 55 of file httpd.c.

Referenced by httpdmgr_destroy(), isc_httpd_accept(), isc_httpd_recvdone(), and isc_httpd_senddone().

#define HTTP_RECVLEN   1024

Definition at line 58 of file httpd.c.

#define HTTP_SENDGROW   1024

Definition at line 59 of file httpd.c.

Referenced by grow_headerspace(), and isc_httpd_accept().

#define HTTP_SEND_MAXLEN   10240

Definition at line 60 of file httpd.c.

Referenced by grow_headerspace().

#define HTTPD_CLOSE   0x0001

Definition at line 62 of file httpd.c.

Referenced by isc_httpd_senddone(), and process_request().

#define HTTPD_FOUNDHOST   0x0002

Definition at line 63 of file httpd.c.

Referenced by process_request().

#define ISC_HTTPD_METHODUNKNOWN   0

HTTP methods.

Definition at line 148 of file httpd.c.

Referenced by reset_client().

#define ISC_HTTPD_METHODGET   1

Definition at line 149 of file httpd.c.

Referenced by process_request().

#define ISC_HTTPD_METHODPOST   2

Definition at line 150 of file httpd.c.

Referenced by process_request().

#define ISC_HTTPD_STATEIDLE   0

Client states.

_IDLE The client is not doing anything at all. This state should only occur just after creation, and just before being destroyed.

_RECV The client is waiting for data after issuing a socket recv().

_RECVDONE Data has been received, and is being processed.

_SEND All data for a response has completed, and a reply was sent via a socket send() call.

_SENDDONE Send is completed.

Badly formatted state table:

IDLE -> RECV when client has a recv() queued.

RECV -> RECVDONE when recvdone event received.

RECVDONE -> SEND if the data for a reply is at hand.

SEND -> RECV when a senddone event was received.

At any time -> RECV on error. If RECV fails, the client will self-destroy, closing the socket and freeing memory.

Definition at line 181 of file httpd.c.

#define ISC_HTTPD_STATERECV   1

Definition at line 182 of file httpd.c.

#define ISC_HTTPD_STATERECVDONE   2

Definition at line 183 of file httpd.c.

#define ISC_HTTPD_STATESEND   3

Definition at line 184 of file httpd.c.

#define ISC_HTTPD_STATESENDDONE   4

Definition at line 185 of file httpd.c.

#define ISC_HTTPD_ISRECV (  )     ((c)->state == ISC_HTTPD_STATERECV)

Definition at line 187 of file httpd.c.

Referenced by isc_httpd_recvdone(), and reset_client().

#define ISC_HTTPD_ISRECVDONE (  )     ((c)->state == ISC_HTTPD_STATERECVDONE)

Definition at line 188 of file httpd.c.

#define ISC_HTTPD_ISSEND (  )     ((c)->state == ISC_HTTPD_STATESEND)

Definition at line 189 of file httpd.c.

Referenced by isc_httpd_senddone().

#define ISC_HTTPD_ISSENDDONE (  )     ((c)->state == ISC_HTTPD_STATESENDDONE)

Definition at line 190 of file httpd.c.

#define ISC_HTTPD_SETRECV (  )     ((c)->state = ISC_HTTPD_STATERECV)

Overall magic test that means we're not idle.

Definition at line 195 of file httpd.c.

Referenced by isc_httpd_accept(), and isc_httpd_senddone().

#define ISC_HTTPD_SETRECVDONE (  )     ((c)->state = ISC_HTTPD_STATERECVDONE)

Definition at line 196 of file httpd.c.

#define ISC_HTTPD_SETSEND (  )     ((c)->state = ISC_HTTPD_STATESEND)

Definition at line 197 of file httpd.c.

Referenced by isc_httpd_recvdone().

#define ISC_HTTPD_SETSENDDONE (  )     ((c)->state = ISC_HTTPD_STATESENDDONE)

Definition at line 198 of file httpd.c.

#define LENGTHOK ( s   )     (httpd->recvbuf - (s) < (int)httpd->recvlen)

Definition at line 357 of file httpd.c.

Referenced by process_request().

#define BUFLENOK ( s   )     (httpd->recvbuf - (s) < HTTP_RECVLEN)

Definition at line 358 of file httpd.c.

Referenced by process_request().


Function Documentation

static void isc_httpd_accept ( isc_task_t task,
isc_event_t ev 
) [static]

Definition at line 497 of file httpd.c.

References isc_region::base, isc_httpdmgr::cb_arg, isc_httpdmgr::client_ok, ENTER, EXIT, HTTP_SENDGROW, httpdmgr_destroy(), isc_buffer_init, isc_buffer_initnull, isc_event_free(), isc_httpd_recvdone(), ISC_HTTPD_SETRECV, ISC_LINK_INIT, ISC_LIST_APPEND, ISC_LIST_INIT, isc_mem_get, isc_mem_put, ISC_R_CANCELED, ISC_R_SUCCESS, isc_socket_accept(), isc_socket_detach(), isc_socket_getpeername(), isc_socket_recv(), isc_socket_setname(), isc_region::length, LOCK, isc_httpdmgr::mctx, isc_httpd::mgr, MSHUTTINGDOWN, isc_socket_newconnev::newsocket, NOTICE, POST, r, reset_client(), isc_socket_newconnev::result, isc_httpdmgr::sock, and UNLOCK.

Referenced by isc_httpdmgr_create().

static void isc_httpd_recvdone ( isc_task_t task,
isc_event_t ev 
) [static]

Definition at line 644 of file httpd.c.

References isc_httpdurl::action, isc_httpdurl::action_arg, isc_region::base, destroy_client(), ENTER, EXIT, INSIST, isc_buffer_initnull, isc_buffer_length, isc_buffer_usedlength, isc_event_free(), ISC_FORMATHTTPTIMESTAMP_SIZE, isc_httpd_addheader(), isc_httpd_addheaderuint(), isc_httpd_endheaders(), ISC_HTTPD_ISRECV, isc_httpd_response(), isc_httpd_senddone(), ISC_HTTPD_SETSEND, ISC_LIST_APPEND, ISC_LIST_HEAD, ISC_LIST_NEXT, ISC_R_NOTFOUND, ISC_R_SUCCESS, isc_socket_recv(), isc_socket_sendv(), isc_time_formathttptimestamp(), isc_time_now(), isc_httpdurl::isstatic, isc_region::length, isc_httpdurl::loadtime, isc_httpd::mgr, isc_socketevent::n, NOTICE, now, process_request(), r, isc_socketevent::result, RUNTIME_CHECK, and isc_httpdurl::url.

Referenced by isc_httpd_accept(), and isc_httpd_senddone().

static void isc_httpd_senddone ( isc_task_t task,
isc_event_t ev 
) [static]

Definition at line 909 of file httpd.c.

References isc_region::base, isc_socketevent::bufferlist, destroy_client(), ENTER, EXIT, HTTPD_CLOSE, INSIST, isc_buffer_length, isc_event_free(), ISC_HTTPD_ISSEND, isc_httpd_recvdone(), ISC_HTTPD_SETRECV, ISC_LINK_LINKED, ISC_LIST_UNLINK, ISC_R_SUCCESS, isc_socket_recv(), isc_region::length, NOTICE, r, reset_client(), and isc_socketevent::result.

Referenced by isc_httpd_recvdone().

static void destroy_client ( isc_httpd_t **  httpdp  )  [static]

Definition at line 213 of file httpd.c.

References httpdmgr_destroy(), ISC_LIST_UNLINK, isc_mem_put, isc_socket_detach(), LOCK, isc_httpdmgr::mctx, isc_httpd::mgr, and UNLOCK.

Referenced by isc_httpd_recvdone(), and isc_httpd_senddone().

static isc_result_t process_request ( isc_httpd_t httpd,
int  length 
) [static]

Definition at line 361 of file httpd.c.

References BUFLENOK, ENTER, EXIT, HTTPD_CLOSE, HTTPD_FOUNDHOST, ISC_HTTPD_METHODGET, ISC_HTTPD_METHODPOST, ISC_R_NOMEMORY, ISC_R_NOTFOUND, ISC_R_RANGE, ISC_R_SUCCESS, LENGTHOK, and s.

Referenced by isc_httpd_recvdone(), and ns_lwdclient_recv().

static void httpdmgr_destroy ( isc_httpdmgr_t httpdmgr  )  [static]

Definition at line 304 of file httpd.c.

References isc_httpdmgr::cb_arg, ENTER, EXIT, ISC_LIST_EMPTY, ISC_LIST_HEAD, ISC_LIST_UNLINK, isc_mem_free, isc_mem_put, isc_mem_putanddetach, isc_mutex_destroy, isc_socket_detach(), isc_task_detach(), LOCK, isc_httpdmgr::mctx, MSHUTTINGDOWN, NOTICE, isc_httpdmgr::ondestroy, isc_httpdmgr::sock, isc_httpdmgr::task, isc_httpdmgr::timermgr, UNLOCK, and isc_httpdurl::url.

Referenced by destroy_client(), and isc_httpd_accept().

static isc_result_t grow_headerspace ( isc_httpd_t httpd  )  [static]

Definition at line 794 of file httpd.c.

References isc_region::base, HTTP_SEND_MAXLEN, HTTP_SENDGROW, isc_buffer_region, isc_buffer_reinit(), isc_mem_get, isc_mem_put, ISC_R_NOMEMORY, ISC_R_NOSPACE, ISC_R_SUCCESS, isc_region::length, isc_httpdmgr::mctx, isc_httpd::mgr, and r.

Referenced by isc_httpd_addheader(), isc_httpd_addheaderuint(), isc_httpd_endheaders(), and isc_httpd_response().

static void reset_client ( isc_httpd_t httpd  )  [static]

Definition at line 973 of file httpd.c.

References INSIST, isc_buffer_clear, isc_buffer_invalidate, ISC_HTTPD_ISRECV, ISC_HTTPD_METHODUNKNOWN, and ISC_LINK_LINKED.

Referenced by isc_httpd_accept(), and isc_httpd_senddone().

isc_result_t isc_httpdmgr_create ( isc_mem_t mctx,
isc_socket_t sock,
isc_task_t task,
isc_httpdclientok_t client_ok,
isc_httpdondestroy_t ondestroy,
void *  cb_arg,
isc_timermgr_t tmgr,
isc_httpdmgr_t **  httpdp 
)

Definition at line 236 of file httpd.c.

References isc_httpdmgr::cb_arg, cleanup(), isc_httpdmgr::client_ok, isc_httpd_accept(), ISC_LIST_INIT, isc_mem_attach(), isc_mem_detach(), isc_mem_get, isc_mem_put, isc_mutex_destroy, isc_mutex_init, ISC_R_NOMEMORY, ISC_R_SUCCESS, isc_result_totext(), isc_socket_accept(), isc_socket_attach(), isc_socket_detach(), isc_socket_filter(), isc_socket_listen(), isc_task_attach(), isc_task_detach(), isc_httpdmgr::mctx, isc_httpdmgr::ondestroy, REQUIRE, isc_httpdmgr::sock, isc_httpdmgr::task, isc_httpdmgr::timermgr, and UNEXPECTED_ERROR.

Referenced by add_listener().

static isc_result_t render_404 ( const char *  url,
isc_httpdurl_t urlinfo,
const char *  querystring,
const char *  headers,
void *  arg,
unsigned int *  retcode,
const char **  retmsg,
const char **  mimetype,
isc_buffer_t b,
isc_httpdfree_t **  freecb,
void **  freecb_args 
) [static]

Definition at line 592 of file httpd.c.

References isc_buffer_add, isc_buffer_reinit(), ISC_R_SUCCESS, and UNUSED.

static isc_result_t render_500 ( const char *  url,
isc_httpdurl_t urlinfo,
const char *  querystring,
const char *  headers,
void *  arg,
unsigned int *  retcode,
const char **  retmsg,
const char **  mimetype,
isc_buffer_t b,
isc_httpdfree_t **  freecb,
void **  freecb_args 
) [static]

Definition at line 618 of file httpd.c.

References isc_buffer_add, isc_buffer_reinit(), ISC_R_SUCCESS, and UNUSED.

void isc_httpdmgr_shutdown ( isc_httpdmgr_t **  httpdmgrp  ) 

Definition at line 767 of file httpd.c.

References ENTER, EXIT, ISC_LIST_HEAD, ISC_LIST_NEXT, ISC_SOCKCANCEL_ALL, isc_socket_cancel(), LOCK, MSETSHUTTINGDOWN, isc_httpdmgr::sock, isc_httpdmgr::task, and UNLOCK.

Referenced by shutdown_listener().

isc_result_t isc_httpd_response ( isc_httpd_t httpd  ) 

Definition at line 815 of file httpd.c.

References grow_headerspace(), isc_buffer_add, isc_buffer_availablelength, isc_buffer_used, and ISC_R_SUCCESS.

Referenced by isc_httpd_recvdone().

isc_result_t isc_httpd_addheader ( isc_httpd_t httpd,
const char *  name,
const char *  val 
)

Definition at line 837 of file httpd.c.

References grow_headerspace(), isc_buffer_add, isc_buffer_availablelength, isc_buffer_used, and ISC_R_SUCCESS.

Referenced by isc_httpd_recvdone().

isc_result_t isc_httpd_endheaders ( isc_httpd_t httpd  ) 

Definition at line 867 of file httpd.c.

References grow_headerspace(), isc_buffer_add, isc_buffer_availablelength, isc_buffer_used, and ISC_R_SUCCESS.

Referenced by isc_httpd_recvdone().

isc_result_t isc_httpd_addheaderuint ( isc_httpd_t httpd,
const char *  name,
int  val 
)

Definition at line 883 of file httpd.c.

References grow_headerspace(), isc_buffer_add, isc_buffer_availablelength, isc_buffer_used, and ISC_R_SUCCESS.

Referenced by isc_httpd_recvdone().

isc_result_t isc_httpdmgr_addurl ( isc_httpdmgr_t httpdmgr,
const char *  url,
isc_httpdaction_t func,
void *  arg 
)

Definition at line 996 of file httpd.c.

References ISC_FALSE, and isc_httpdmgr_addurl2().

Referenced by add_listener().

isc_result_t isc_httpdmgr_addurl2 ( isc_httpdmgr_t httpdmgr,
const char *  url,
isc_boolean_t  isstatic,
isc_httpdaction_t func,
void *  arg 
)

Definition at line 1003 of file httpd.c.

References isc_httpdurl::action, isc_httpdurl::action_arg, ISC_LINK_INIT, ISC_LIST_APPEND, isc_mem_get, isc_mem_put, isc_mem_strdup, ISC_R_NOMEMORY, ISC_R_SUCCESS, isc_time_now(), isc_httpdurl::isstatic, isc_httpdurl::loadtime, isc_httpdmgr::mctx, and isc_httpdurl::url.

Referenced by add_listener(), and isc_httpdmgr_addurl().


Variable Documentation

isc_httpdaction_t render_404 [static]

Definition at line 209 of file httpd.c.

isc_httpdaction_t render_500 [static]

Definition at line 210 of file httpd.c.


Generated on Tue Apr 28 17:41:14 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha