pazpar2  1.14.1
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

◆ CLOSESOCKET

#define CLOSESOCKET (   x)    close(x)

Definition at line 97 of file http.c.

◆ HTTP_BUF_SIZE

#define HTTP_BUF_SIZE   4096

Definition at line 77 of file http.c.

◆ MAX_HTTP_HEADER

#define MAX_HTTP_HEADER   4096

Definition at line 68 of file http.c.

Function Documentation

◆ enable_nonblock()

static void enable_nonblock ( int  sock)
static

Definition at line 743 of file http.c.

Referenced by http_accept(), and http_proxy().

◆ http_accept()

static void http_accept ( IOCHAN  i,
int  event 
)
static

◆ http_add_observer()

http_channel_observer_t http_add_observer ( struct http_channel c,
void *  data,
http_channel_destroy_t  des 
)

◆ http_addheader()

void http_addheader ( struct http_response r,
const char *  name,
const char *  value 
)

◆ http_argbyname()

const char* http_argbyname ( struct http_request r,
const char *  name 
)

◆ http_buf_bybuf()

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().

◆ 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().

◆ http_buf_create()

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().

◆ http_buf_destroy()

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().

◆ http_buf_destroy_queue()

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().

◆ http_buf_enqueue()

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().

◆ http_buf_peek()

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().

◆ http_buf_read()

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::buf, http_buf_destroy(), http_buf::len, and http_buf::next.

Referenced by http_parse_request().

◆ http_buf_size()

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().

◆ http_channel_create()

static struct http_channel * http_channel_create ( http_server_t  http_server,
const char *  addr,
struct conf_server server 
)
static

◆ http_channel_destroy()

static void http_channel_destroy ( IOCHAN  i)
static

◆ http_channel_observer_chan()

struct http_channel* http_channel_observer_chan ( http_channel_observer_t  obs)

◆ http_close_server()

void http_close_server ( struct conf_server server)

Definition at line 1362 of file http.c.

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

Referenced by cmd_exit(), and config_stop_listeners().

◆ http_create_response()

struct http_response* http_create_response ( struct http_channel c)

◆ http_destroy_observers()

static void http_destroy_observers ( struct http_channel c)
static

Definition at line 1420 of file http.c.

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

Referenced by http_channel_destroy().

◆ http_error()

static void http_error ( struct http_channel hc,
int  no,
const char *  msg 
)
static

◆ http_fire_observers()

static void http_fire_observers ( struct http_channel c)
static

◆ http_header_append()

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, name, http_header::next, http_channel::nmem, and http_header::value.

Referenced by http_proxy().

◆ http_headerbyname()

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

Definition at line 303 of file http.c.

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

◆ http_init()

int http_init ( struct conf_server server,
const char *  record_fname 
)

◆ http_io()

static void http_io ( IOCHAN  i,
int  event 
)
static

◆ http_lookup_header()

const char* http_lookup_header ( struct http_header header,
const char *  name 
)

◆ http_mutex_init()

void http_mutex_init ( struct conf_server server)

◆ http_observer_set_data2()

void http_observer_set_data2 ( http_channel_observer_t  obs,
void *  data2 
)

Definition at line 1460 of file http.c.

References http_channel_observer_s::data2.

◆ http_parse_arguments()

static int http_parse_arguments ( struct http_request r,
NMEM  nmem,
const char *  args 
)
static

◆ http_parse_request()

struct http_request* http_parse_request ( struct http_channel c,
struct http_buf **  queue,
int  len 
)

◆ http_parse_response_buf()

struct http_response* http_parse_response_buf ( struct http_channel c,
const char *  buf,
int  len 
)

◆ http_proxy()

static int http_proxy ( struct http_request rq)
static

◆ http_remove_observer()

void http_remove_observer ( http_channel_observer_t  obs)

◆ http_send_response()

void http_send_response ( struct http_channel ch)

◆ http_serialize_request()

static struct http_buf* http_serialize_request ( struct http_request r)
static

◆ http_serialize_response()

static struct http_buf* http_serialize_response ( struct http_channel c,
struct http_response r 
)
static

◆ http_server_create()

http_server_t http_server_create ( void  )
static

◆ http_server_destroy()

void http_server_destroy ( http_server_t  hs)

◆ http_server_incref()

void http_server_incref ( http_server_t  hs)
static

Definition at line 1501 of file http.c.

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

Referenced by http_channel_create().

◆ http_set_proxyaddr()

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

Definition at line 1375 of file http.c.

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

Referenced by config_start_listeners().

◆ http_weshouldproxy()

static int http_weshouldproxy ( struct http_request rq)
static

◆ is_inprogress()

static int is_inprogress ( void  )
static

Definition at line 731 of file http.c.

Referenced by http_proxy(), and proxy_io().

◆ next_crlf()

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().

◆ package_check()

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

Definition at line 339 of file http.c.

References MAX_HTTP_HEADER, and next_crlf().

Referenced by request_check().

◆ proxy_io()

static void proxy_io ( IOCHAN  i,
int  event 
)
static

◆ request_check()

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().

◆ urldecode()

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

Definition at line 242 of file http.c.

Referenced by http_parse_arguments().

◆ urlencode()

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

Definition at line 266 of file http.c.

Variable Documentation

◆ log_level_post

int log_level_post = 0
static

Definition at line 84 of file http.c.

Referenced by http_io(), and http_server_create().