pazpar2
1.14.1
|
#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_channel * | http_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_buf * | http_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_buf * | http_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_buf * | http_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_response * | http_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_response * | http_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_request * | http_parse_request (struct http_channel *c, struct http_buf **queue, int len) |
static struct http_buf * | http_serialize_response (struct http_channel *c, struct http_response *r) |
static struct http_buf * | http_serialize_request (struct http_request *r) |
static int | http_weshouldproxy (struct http_request *rq) |
struct http_header * | http_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_channel * | http_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 |
|
static |
Definition at line 743 of file http.c.
Referenced by http_accept(), and http_proxy().
|
static |
Definition at line 1197 of file http.c.
References CLOSESOCKET, enable_nonblock(), EVENT_EXCEPT, EVENT_INPUT, conf_server::host, http_channel_create(), http_channel_destroy(), http_io(), conf_server::http_server, http_channel::iochan, iochan_add(), iochan_create(), iochan_getdata, iochan_getfd, conf_server::iochan_man, iochan_setdata, and iochan_settimeout.
Referenced by http_init().
http_channel_observer_t http_add_observer | ( | struct http_channel * | c, |
void * | data, | ||
http_channel_destroy_t | des | ||
) |
Definition at line 1430 of file http.c.
References http_channel_observer_s::chan, http_channel_observer_s::data, http_channel_observer_s::data2, http_channel_observer_s::destroy, http_channel_observer_s::next, and http_channel::observers.
Referenced by session_set_watch(), and show_record().
void http_addheader | ( | struct http_response * | r, |
const char * | name, | ||
const char * | value | ||
) |
Definition at line 282 of file http.c.
References http_response::channel, http_response::headers, http_header::name, name, http_header::next, http_channel::nmem, and http_header::value.
Referenced by http_command().
const char* http_argbyname | ( | struct http_request * | r, |
const char * | name | ||
) |
Definition at line 292 of file http.c.
References http_request::arguments, http_argument::name, name, http_argument::next, and http_argument::value.
Referenced by bytarget_response(), cmd_bytarget(), cmd_init(), cmd_search(), cmd_show(), cmd_termlist(), get_version(), http_command(), locate_session(), show_record(), show_records(), termlist_response(), and termlist_result_ready().
|
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 |
Definition at line 181 of file http.c.
References http_buf_bybuf().
Referenced by http_serialize_request(), and http_serialize_response().
|
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 |
Definition at line 137 of file http.c.
Referenced by http_buf_destroy_queue(), http_buf_read(), http_io(), and proxy_io().
|
static |
Definition at line 142 of file http.c.
References http_buf_destroy(), and http_buf::next.
Referenced by http_channel_destroy().
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 |
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 |
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().
|
static |
Definition at line 204 of file http.c.
References http_buf::len, and http_buf::next.
Referenced by request_check().
|
static |
Definition at line 1161 of file http.c.
References http_channel::addr, http_channel::Http_Idle, http_channel::http_server, http_server_incref(), http_server::http_sessions, http_channel::http_sessions, http_channel::iochan, http_channel::iqueue, http_channel::keep_alive, http_channel::nmem, http_channel::observers, http_channel::oqueue, http_channel::proxy, http_channel::request, http_channel::response, http_channel::server, http_channel::state, http_channel::version, http_channel::wrbuf, and http_channel::yt.
Referenced by http_accept().
|
static |
Definition at line 1128 of file http.c.
References CLOSESOCKET, http_buf_destroy_queue(), http_destroy_observers(), http_fire_observers(), http_channel::http_server, http_server_destroy(), http_proxy::iochan, iochan_destroy(), iochan_getdata, iochan_getfd, http_channel::iqueue, http_channel::nmem, http_channel::oqueue, http_proxy::oqueue, http_channel::proxy, http_channel::wrbuf, and http_channel::yt.
Referenced by http_accept(), http_io(), http_send_response(), and proxy_io().
struct http_channel* http_channel_observer_chan | ( | http_channel_observer_t | obs | ) |
Definition at line 1455 of file http.c.
References http_channel_observer_s::chan.
Referenced by show_raw_record_error(), show_raw_record_ok(), and show_raw_record_ok_binary().
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().
struct http_response* http_create_response | ( | struct http_channel * | c | ) |
Definition at line 311 of file http.c.
References http_response::channel, http_response::code, http_response::content_type, http_response::headers, http_response::msg, http_channel::nmem, and http_response::payload.
Referenced by http_command(), http_error(), and http_parse_response_buf().
|
static |
Definition at line 1420 of file http.c.
References http_channel_observer_s::next, and http_channel::observers.
Referenced by http_channel_destroy().
|
static |
Definition at line 874 of file http.c.
References http_response::code, http_create_response(), http_send_response(), http_channel::keep_alive, http_response::msg, http_channel::nmem, http_response::payload, and http_channel::response.
Referenced by http_io().
|
static |
Definition at line 1410 of file http.c.
References http_channel_observer_s::data, http_channel_observer_s::data2, http_channel_observer_s::destroy, http_channel_observer_s::next, and http_channel::observers.
Referenced by http_channel_destroy().
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().
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.
int http_init | ( | struct conf_server * | server, |
const char * | record_fname | ||
) |
Definition at line 1238 of file http.c.
References CLOSESOCKET, error(), EVENT_EXCEPT, EVENT_INPUT, conf_server::host, http_accept(), conf_server::http_server, http_server_create(), iochan_add(), iochan_create(), iochan_destroy(), conf_server::iochan_man, iochan_setdata, http_server::listener_socket, conf_server::port, and http_server::record_file.
Referenced by config_start_listeners().
|
static |
Definition at line 890 of file http.c.
References http_buf::buf, http_request::content_buf, EVENT_INPUT, EVENT_OUTPUT, http_buf_create(), http_buf_destroy(), http_buf_enqueue(), HTTP_BUF_SIZE, http_channel_destroy(), http_command(), http_error(), http_parse_request(), http_proxy(), http_channel::http_server, http_weshouldproxy(), http_channel::iochan, http_proxy::iochan, iochan_clearflag, iochan_getdata, iochan_getfd, http_channel::iqueue, http_channel::keep_alive, http_buf::len, log_level_post, http_request::method, http_buf::next, http_channel::nmem, http_buf::offset, http_channel::oqueue, http_request::path, http_channel::proxy, http_server::record_file, http_channel::request, request_check(), http_channel::response, http_request::search, http_channel::state, and http_channel::yt.
Referenced by http_accept().
const char* http_lookup_header | ( | struct http_header * | header, |
const char * | name | ||
) |
Definition at line 119 of file http.c.
References http_header::name, 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 | ) |
Definition at line 1509 of file http.c.
References conf_server::http_server, http_server::http_sessions, http_sessions_create(), http_server::mutex, pazpar2_mutex_create(), and http_channel::server.
Referenced by config_process_events().
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.
|
static |
Definition at line 443 of file http.c.
References http_request::arguments, http_argument::name, http_argument::next, urldecode(), and http_argument::value.
Referenced by http_parse_request().
struct http_request* http_parse_request | ( | struct http_channel * | c, |
struct http_buf ** | queue, | ||
int | len | ||
) |
Definition at line 479 of file http.c.
References http_request::arguments, http_request::channel, http_request::content_buf, http_request::content_len, http_request::headers, http_buf_read(), http_lookup_header(), http_parse_arguments(), http_channel::http_server, http_request::http_version, http_channel::keep_alive, http_request::method, http_header::name, http_header::next, next_crlf(), http_channel::nmem, http_request::path, http_request::search, http_header::value, and http_channel::version.
Referenced by http_io().
struct http_response* http_parse_response_buf | ( | struct http_channel * | c, |
const char * | buf, | ||
int | len | ||
) |
Definition at line 392 of file http.c.
References http_response::code, http_response::headers, http_create_response(), MAX_HTTP_HEADER, http_header::name, http_header::next, http_channel::nmem, and http_header::value.
|
static |
Definition at line 758 of file http.c.
References http_channel::addr, http_proxy::channel, http_request::channel, enable_nonblock(), EVENT_INPUT, EVENT_OUTPUT, http_proxy::first_response, http_request::headers, conf_server::host, http_buf_enqueue(), http_header_append(), http_lookup_header(), http_serialize_request(), conf_server::http_server, http_proxy::iochan, iochan_add(), iochan_create(), iochan_destroy(), conf_server::iochan_man, iochan_setdata, iochan_setflag, is_inprogress(), http_proxy::oqueue, PACKAGE_NAME, PACKAGE_VERSION, conf_server::port, http_channel::proxy, http_server::proxy_addr, proxy_io(), and http_channel::server.
Referenced by http_io().
void http_remove_observer | ( | http_channel_observer_t | obs | ) |
Definition at line 1443 of file http.c.
References http_channel_observer_s::chan, http_channel_observer_s::next, and http_channel::observers.
Referenced by session_alert_watch(), show_raw_record_error(), show_raw_record_ok(), show_raw_record_ok_binary(), and show_record().
void http_send_response | ( | struct http_channel * | ch | ) |
Definition at line 844 of file http.c.
References EVENT_OUTPUT, http_buf_enqueue(), http_channel_destroy(), http_serialize_response(), http_channel::iochan, iochan_getfd, iochan_setflag, http_channel::oqueue, http_request::path, http_channel::request, http_channel::response, http_request::search, http_channel::state, and http_channel::yt.
Referenced by error2(), http_error(), response_close(), show_raw_record_ok(), and show_raw_record_ok_binary().
|
static |
Definition at line 666 of file http.c.
References http_request::channel, http_request::content_buf, http_request::content_len, http_request::headers, http_buf_bywrbuf(), http_channel::http_server, http_request::http_version, http_request::method, http_header::name, http_header::next, http_request::path, http_request::search, http_header::value, and http_channel::wrbuf.
Referenced by http_proxy().
|
static |
Definition at line 620 of file http.c.
References http_response::code, http_response::content_type, parameters::dump_records, global_parameters, http_response::headers, http_buf_bywrbuf(), http_channel::http_server, http_response::msg, http_header::name, http_header::next, http_response::payload, http_header::value, http_channel::version, and http_channel::wrbuf.
Referenced by http_send_response().
|
static |
Definition at line 1465 of file http.c.
References http_server::http_sessions, log_level_post, http_server::mutex, http_server::proxy_addr, http_server::record_file, and http_server::ref_count.
Referenced by http_init().
void http_server_destroy | ( | http_server_t | hs | ) |
Definition at line 1479 of file http.c.
References http_server::http_sessions, http_sessions_destroy(), http_server::mutex, http_server::proxy_addr, http_server::record_file, and http_server::ref_count.
Referenced by http_channel_destroy(), and server_destroy().
|
static |
Definition at line 1501 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 1375 of file http.c.
References conf_server::http_server, and http_server::proxy_addr.
Referenced by config_start_listeners().
|
static |
Definition at line 693 of file http.c.
References http_request::channel, conf_server::http_server, http_request::path, http_server::proxy_addr, and http_channel::server.
Referenced by http_io().
|
static |
Definition at line 731 of file http.c.
Referenced by http_proxy(), and proxy_io().
|
static |
Definition at line 324 of file http.c.
Referenced by http_parse_request(), and package_check().
|
static |
Definition at line 339 of file http.c.
References MAX_HTTP_HEADER, and next_crlf().
Referenced by request_check().
|
static |
Definition at line 1047 of file http.c.
References http_buf::buf, http_proxy::channel, CLOSESOCKET, EVENT_INPUT, EVENT_OUTPUT, http_buf_create(), http_buf_destroy(), http_buf_enqueue(), HTTP_BUF_SIZE, http_channel_destroy(), http_channel::http_server, http_channel::iochan, http_proxy::iochan, iochan_clearflag, iochan_destroy(), iochan_getdata, iochan_getfd, iochan_setflag, iochan_setflags, is_inprogress(), http_buf::len, http_buf::next, http_buf::offset, http_channel::oqueue, and http_proxy::oqueue.
Referenced by http_proxy().
|
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 |
Definition at line 242 of file http.c.
Referenced by http_parse_arguments().
|
static |
Definition at line 84 of file http.c.
Referenced by http_io(), and http_server_create().