pazpar2  1.13.0
Data Structures | Macros | Functions | Variables
http.c File Reference
#include <stdio.h>
#include <sys/types.h>
#include <yaz/snprintf.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <errno.h>
#include <assert.h>
#include <yaz/yaz-util.h>
#include <yaz/comstack.h>
#include <yaz/nmem.h>
#include <yaz/mutex.h>
#include "ppmutex.h"
#include "session.h"
#include "http.h"
#include "parameters.h"

Go to the source code of this file.

Data Structures

struct  http_buf
 
struct  http_server
 
struct  http_channel_observer_s
 

Macros

#define MAX_HTTP_HEADER   4096
 
#define HTTP_BUF_SIZE   4096
 
#define CLOSESOCKET(x)   close(x)
 

Functions

static void proxy_io (IOCHAN i, int event)
 
static struct http_channelhttp_channel_create (http_server_t http_server, const char *addr, struct conf_server *server)
 
static void http_channel_destroy (IOCHAN i)
 
static http_server_t http_server_create (void)
 
static void http_server_incref (http_server_t hs)
 
const char * http_lookup_header (struct http_header *header, const char *name)
 
static struct http_bufhttp_buf_create (http_server_t hs)
 
static void http_buf_destroy (http_server_t hs, struct http_buf *b)
 
static void http_buf_destroy_queue (http_server_t hs, struct http_buf *b)
 
static struct http_bufhttp_buf_bybuf (http_server_t hs, char *b, int len)
 
static void http_buf_enqueue (struct http_buf **queue, struct http_buf *b)
 
static struct http_bufhttp_buf_bywrbuf (http_server_t hs, WRBUF wrbuf)
 
static void http_buf_peek (struct http_buf *b, char *buf, int len)
 
static int http_buf_size (struct http_buf *b)
 
static int http_buf_read (http_server_t hs, struct http_buf **b, char *buf, int len)
 
static void urldecode (char *i, char *o)
 
void urlencode (const char *i, char *o)
 
void http_addheader (struct http_response *r, const char *name, const char *value)
 
const char * http_argbyname (struct http_request *r, const char *name)
 
const char * http_headerbyname (struct http_header *h, const char *name)
 
struct http_responsehttp_create_response (struct http_channel *c)
 
static const char * next_crlf (const char *cp, size_t *skipped)
 
static int package_check (const char *buf, int sz)
 
static int request_check (struct http_buf *queue)
 
struct http_responsehttp_parse_response_buf (struct http_channel *c, const char *buf, int len)
 
static int http_parse_arguments (struct http_request *r, NMEM nmem, const char *args)
 
struct http_requesthttp_parse_request (struct http_channel *c, struct http_buf **queue, int len)
 
static struct http_bufhttp_serialize_response (struct http_channel *c, struct http_response *r)
 
static struct http_bufhttp_serialize_request (struct http_request *r)
 
static int http_weshouldproxy (struct http_request *rq)
 
struct http_headerhttp_header_append (struct http_channel *ch, struct http_header *hp, const char *name, const char *value)
 
static int is_inprogress (void)
 
static void enable_nonblock (int sock)
 
static int http_proxy (struct http_request *rq)
 
void http_send_response (struct http_channel *ch)
 
static void http_error (struct http_channel *hc, int no, const char *msg)
 
static void http_io (IOCHAN i, int event)
 
static void http_fire_observers (struct http_channel *c)
 
static void http_destroy_observers (struct http_channel *c)
 
static void http_accept (IOCHAN i, int event)
 
int http_init (struct conf_server *server, const char *record_fname)
 
void http_close_server (struct conf_server *server)
 
void http_set_proxyaddr (const char *host, struct conf_server *server)
 
http_channel_observer_t http_add_observer (struct http_channel *c, void *data, http_channel_destroy_t des)
 
void http_remove_observer (http_channel_observer_t obs)
 
struct http_channelhttp_channel_observer_chan (http_channel_observer_t obs)
 
void http_observer_set_data2 (http_channel_observer_t obs, void *data2)
 
void http_server_destroy (http_server_t hs)
 
void http_mutex_init (struct conf_server *server)
 

Variables

static int log_level_post = 0
 

Macro Definition Documentation

#define CLOSESOCKET (   x)    close(x)

Definition at line 97 of file http.c.

Referenced by http_accept(), http_channel_destroy(), http_init(), and proxy_io().

#define HTTP_BUF_SIZE   4096

Definition at line 77 of file http.c.

Referenced by http_buf_bybuf(), http_io(), and proxy_io().

#define MAX_HTTP_HEADER   4096

Definition at line 68 of file http.c.

Referenced by http_parse_response_buf(), package_check(), and request_check().

Function Documentation

static void enable_nonblock ( int  sock)
static

Definition at line 743 of file http.c.

Referenced by http_accept(), and http_proxy().

static void http_accept ( IOCHAN  i,
int  event 
)
static
http_channel_observer_t http_add_observer ( struct http_channel c,
void *  data,
http_channel_destroy_t  des 
)
void http_addheader ( struct http_response r,
const char *  name,
const char *  value 
)
const char* http_argbyname ( struct http_request r,
const char *  name 
)
static struct http_buf* http_buf_bybuf ( http_server_t  hs,
char *  b,
int  len 
)
static

Definition at line 153 of file http.c.

References http_buf_create(), HTTP_BUF_SIZE, http_buf::len, and http_buf::next.

Referenced by http_buf_bywrbuf().

static struct http_buf* http_buf_bywrbuf ( http_server_t  hs,
WRBUF  wrbuf 
)
static

Definition at line 181 of file http.c.

References http_buf_bybuf().

Referenced by http_serialize_request(), and http_serialize_response().

static struct http_buf* http_buf_create ( http_server_t  hs)
static

Definition at line 128 of file http.c.

References http_buf::len, http_buf::next, and http_buf::offset.

Referenced by http_buf_bybuf(), http_io(), and proxy_io().

static void http_buf_destroy ( http_server_t  hs,
struct http_buf b 
)
static

Definition at line 137 of file http.c.

Referenced by http_buf_destroy_queue(), http_buf_read(), http_io(), and proxy_io().

static void http_buf_destroy_queue ( http_server_t  hs,
struct http_buf b 
)
static

Definition at line 142 of file http.c.

References http_buf_destroy(), and http_buf::next.

Referenced by http_channel_destroy().

static void http_buf_enqueue ( struct http_buf **  queue,
struct http_buf b 
)
static

Definition at line 174 of file http.c.

References http_buf::next.

Referenced by http_io(), http_proxy(), http_send_response(), and proxy_io().

static void http_buf_peek ( struct http_buf b,
char *  buf,
int  len 
)
static

Definition at line 189 of file http.c.

References http_buf::buf, http_buf::len, http_buf::next, and http_buf::offset.

Referenced by request_check().

static int http_buf_read ( http_server_t  hs,
struct http_buf **  b,
char *  buf,
int  len 
)
static

Definition at line 213 of file http.c.

References http_buf_destroy(), and http_buf::next.

Referenced by http_parse_request().

static int http_buf_size ( struct http_buf b)
static

Definition at line 204 of file http.c.

References http_buf::len, and http_buf::next.

Referenced by request_check().

static struct http_channel * http_channel_create ( http_server_t  http_server,
const char *  addr,
struct conf_server server 
)
static
static void http_channel_destroy ( IOCHAN  i)
static
struct http_channel* http_channel_observer_chan ( http_channel_observer_t  obs)
void http_close_server ( struct conf_server server)

Definition at line 1359 of file http.c.

References conf_server::http_server, and http_server::listener_socket.

Referenced by cmd_exit(), and config_stop_listeners().

struct http_response* http_create_response ( struct http_channel c)
static void http_destroy_observers ( struct http_channel c)
static

Definition at line 1417 of file http.c.

References http_channel_observer_s::next, and http_channel::observers.

Referenced by http_channel_destroy(), and proxy_io().

static void http_error ( struct http_channel hc,
int  no,
const char *  msg 
)
static
static void http_fire_observers ( struct http_channel c)
static
struct http_header* http_header_append ( struct http_channel ch,
struct http_header hp,
const char *  name,
const char *  value 
)

Definition at line 702 of file http.c.

References http_header::name, http_header::next, http_channel::nmem, and http_header::value.

Referenced by http_proxy().

const char* http_headerbyname ( struct http_header h,
const char *  name 
)

Definition at line 303 of file http.c.

References http_header::name, http_header::next, and http_header::value.

int http_init ( struct conf_server server,
const char *  record_fname 
)
static void http_io ( IOCHAN  i,
int  event 
)
static
const char* http_lookup_header ( struct http_header header,
const char *  name 
)

Definition at line 119 of file http.c.

References http_header::name, http_header::next, and http_header::value.

Referenced by cmd_init(), cmd_settings(), http_parse_request(), and http_proxy().

void http_mutex_init ( struct conf_server server)
void http_observer_set_data2 ( http_channel_observer_t  obs,
void *  data2 
)

Definition at line 1457 of file http.c.

References http_channel_observer_s::data2.

static int http_parse_arguments ( struct http_request r,
NMEM  nmem,
const char *  args 
)
static
struct http_request* http_parse_request ( struct http_channel c,
struct http_buf **  queue,
int  len 
)
struct http_response* http_parse_response_buf ( struct http_channel c,
const char *  buf,
int  len 
)
static int http_proxy ( struct http_request rq)
static
void http_remove_observer ( http_channel_observer_t  obs)
void http_send_response ( struct http_channel ch)
static struct http_buf* http_serialize_request ( struct http_request r)
static
static struct http_buf* http_serialize_response ( struct http_channel c,
struct http_response r 
)
static
http_server_t http_server_create ( void  )
static
void http_server_destroy ( http_server_t  hs)
void http_server_incref ( http_server_t  hs)
static

Definition at line 1498 of file http.c.

References http_server::mutex, and http_server::ref_count.

Referenced by http_channel_create().

void http_set_proxyaddr ( const char *  host,
struct conf_server server 
)

Definition at line 1372 of file http.c.

References conf_server::http_server, and http_server::proxy_addr.

Referenced by config_start_listeners().

static int http_weshouldproxy ( struct http_request rq)
static
static int is_inprogress ( void  )
static

Definition at line 731 of file http.c.

Referenced by http_proxy(), and proxy_io().

static const char* next_crlf ( const char *  cp,
size_t *  skipped 
)
static

Definition at line 324 of file http.c.

Referenced by http_parse_request(), and package_check().

static int package_check ( const char *  buf,
int  sz 
)
static

Definition at line 339 of file http.c.

References http_buf::buf, http_buf::len, MAX_HTTP_HEADER, and next_crlf().

Referenced by request_check().

static void proxy_io ( IOCHAN  i,
int  event 
)
static
static int request_check ( struct http_buf queue)
static

Definition at line 382 of file http.c.

References http_buf_peek(), http_buf_size(), MAX_HTTP_HEADER, and package_check().

Referenced by http_io().

static void urldecode ( char *  i,
char *  o 
)
static

Definition at line 242 of file http.c.

Referenced by http_parse_arguments().

void urlencode ( const char *  i,
char *  o 
)

Definition at line 266 of file http.c.

Variable Documentation

int log_level_post = 0
static

Definition at line 84 of file http.c.

Referenced by http_io(), and http_server_create().