#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include <ngx_log.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "ngx_http_download_module.h"
Go to the source code of this file.
Functions | |
static void * | ngx_http_download_create_conf (ngx_conf_t *cf) |
Nginx module configuration. | |
static char * | ngx_http_download_merge_conf (ngx_conf_t *cf, void *parent, void *child) |
Nginx module configuration. | |
static ngx_int_t | ngx_http_download_create_request (ngx_http_download_conn_t *conn) |
Creates HTTP request and store it in conn->request. | |
static ngx_int_t | ngx_http_download_flush_buffer (ngx_http_download_conn_t *conn, ssize_t bytes) |
Moves bufferded data from conn->buffer to conn->out_bufs. | |
static void | ngx_http_download_write_handler (ngx_event_t *wev) |
Handler called by nginx if socket is ready to write - write data to socket. | |
static void | ngx_http_download_read_handler (ngx_event_t *rev) |
Handler called by nginx if socket is ready to read - read data from socket. | |
static void | ngx_http_download_dummy_handler (ngx_event_t *ev) |
Handler that does nothing. | |
static void | ngx_http_download_parse_headers (ngx_http_download_conn_t *conn) |
Tries to parse HTTP error code from headers, set conn->status. | |
static void | ngx_http_download_finalize_connection (ngx_http_download_conn_t *conn, ngx_event_t *e, ngx_int_t rc) |
Closes connection and call done_handler if necessary. | |
ngx_http_download_conn_t * | ngx_http_download_create_new (ngx_http_request_t *r) |
Creates and initializes new download structure. | |
ngx_int_t | ngx_http_download_enqueue (ngx_http_download_conn_t *conn) |
Enqueues download, when finished done_handler will be called. | |
ngx_int_t | ngx_http_download_parse_url (ngx_str_t *url, ngx_http_download_conn_t *conn) |
Parses url and put all required data to download structure. | |
void | ngx_http_download_cleanup (ngx_http_download_conn_t *conn) |
Cancel download and free all allocated resources. | |
Variables | |
static ngx_command_t | ngx_http_download_commands [] |
Nginx config file commands configuration. | |
static ngx_http_module_t | ngx_http_download_module_ctx |
Nginx module context. | |
ngx_module_t | ngx_http_download_module |
Nginx module settings. |
void ngx_http_download_cleanup | ( | ngx_http_download_conn_t * | conn | ) |
Cancel download and free all allocated resources.
conn | download structure |
Definition at line 357 of file ngx_http_download_module.c.
References ngx_http_download_conn_s::done, ngx_http_download_conn_s::done_handler, ngx_http_download_conn_s::log, ngx_http_download_conn_s::p, ngx_http_download_conn_s::pool, and ngx_http_download_conn_s::terminated.
Referenced by ngx_http_download_finalize_connection(), ngx_http_xslt2_xml_cleanup(), ngx_http_xxslt_parse_cleanup(), and ngx_http_xxslt_parse_get_external_include().
static void * ngx_http_download_create_conf | ( | ngx_conf_t * | cf | ) | [static] |
Nginx module configuration.
cf | config |
Definition at line 747 of file ngx_http_download_module.c.
References ngx_http_download_conf_t::log, and ngx_http_download_conf_t::server_timeout.
ngx_http_download_conn_t* ngx_http_download_create_new | ( | ngx_http_request_t * | r | ) |
Creates and initializes new download structure.
r | nginx request |
Definition at line 99 of file ngx_http_download_module.c.
References BUFFER_SIZE, ngx_http_download_conn_s::connect_timeout, ngx_http_download_conn_s::log, ngx_http_download_module, ngx_http_download_conn_s::pool, ngx_http_download_conn_s::r, ngx_http_download_conn_s::read_timeout, ngx_http_download_conn_s::rpool, ngx_http_download_conf_t::server_timeout, and ngx_http_download_conn_s::write_timeout.
Referenced by ngx_http_xslt2_xml_get_external_stylesheet(), and ngx_http_xxslt_parse_get_external_include().
static ngx_int_t ngx_http_download_create_request | ( | ngx_http_download_conn_t * | conn | ) | [static] |
Creates HTTP request and store it in conn->request.
conn | correctly initialized download structure |
Definition at line 382 of file ngx_http_download_module.c.
References ngx_http_download_conn_s::host, ngx_http_download_conn_s::log, ngx_http_download_conn_s::pool, ngx_http_download_conn_s::request, and ngx_http_download_conn_s::uri.
Referenced by ngx_http_download_enqueue().
static void ngx_http_download_dummy_handler | ( | ngx_event_t * | ev | ) | [static] |
Handler that does nothing.
It's used by write_handler when all data was sent.
ev | nginx event |
Definition at line 530 of file ngx_http_download_module.c.
Referenced by ngx_http_download_write_handler().
ngx_int_t ngx_http_download_enqueue | ( | ngx_http_download_conn_t * | conn | ) |
Enqueues download, when finished done_handler will be called.
conn | correctly set download structure |
Definition at line 153 of file ngx_http_download_module.c.
References ngx_http_download_conn_s::buffer, BUFFER_SIZE, ngx_http_download_conn_s::connect_timeout, ngx_http_download_conn_s::data, ngx_http_download_conn_s::done, ngx_http_download_conn_s::host, ngx_http_download_conn_s::log, ngx_http_download_create_request(), ngx_http_download_finalize_connection(), ngx_http_download_read_handler(), ngx_http_download_write_handler(), ngx_http_download_conn_s::out_bufs, ngx_http_download_conn_s::out_bufs_tail, ngx_http_download_conn_s::p, ngx_http_download_conn_s::pool, ngx_http_download_conn_s::port, ngx_http_download_conn_s::r, ngx_http_download_conn_s::read_timeout, ngx_http_download_conn_s::request, ngx_http_download_conn_s::response_length, ngx_http_download_conn_s::rpool, and ngx_http_download_conn_s::write_timeout.
Referenced by ngx_http_xslt2_xml_get_external_stylesheet(), and ngx_http_xxslt_parse_get_external_include().
static void ngx_http_download_finalize_connection | ( | ngx_http_download_conn_t * | conn, | |
ngx_event_t * | e, | |||
ngx_int_t | rc | |||
) | [static] |
Closes connection and call done_handler if necessary.
conn | download structure | |
e | event cause finalize | |
rc | finalize status |
Definition at line 682 of file ngx_http_download_module.c.
References ngx_http_download_conn_s::body_start, ngx_http_download_conn_s::done, ngx_http_download_conn_s::done_handler, ngx_http_download_conn_s::error, ngx_http_download_conn_s::log, ngx_http_download_cleanup(), ngx_http_download_parse_headers(), ngx_http_download_conn_s::out_bufs, ngx_http_download_conn_s::out_bufs_tail, ngx_http_download_conn_s::p, and ngx_http_download_conn_s::r.
Referenced by ngx_http_download_enqueue(), ngx_http_download_read_handler(), and ngx_http_download_write_handler().
static ngx_int_t ngx_http_download_flush_buffer | ( | ngx_http_download_conn_t * | conn, | |
ssize_t | bytes | |||
) | [static] |
Moves bufferded data from conn->buffer to conn->out_bufs.
conn | download structure | |
bytes | number of bytes stored in conn->buffer |
Definition at line 417 of file ngx_http_download_module.c.
References ngx_http_download_conn_s::buffer, ngx_http_download_conn_s::out_bufs, ngx_http_download_conn_s::out_bufs_tail, ngx_http_download_conn_s::r, and ngx_http_download_conn_s::rpool.
Referenced by ngx_http_download_read_handler().
static char * ngx_http_download_merge_conf | ( | ngx_conf_t * | cf, | |
void * | parent, | |||
void * | child | |||
) | [static] |
Nginx module configuration.
cf | config | |
parent | previous config | |
child | config |
Definition at line 777 of file ngx_http_download_module.c.
References ngx_http_download_conf_t::server_timeout.
static void ngx_http_download_parse_headers | ( | ngx_http_download_conn_t * | conn | ) | [static] |
Tries to parse HTTP error code from headers, set conn->status.
Status will be set to -1 if parsing fail.
conn | download structure |
Definition at line 646 of file ngx_http_download_module.c.
References ngx_http_download_conn_s::body_start, ngx_http_download_conn_s::out_bufs, and ngx_http_download_conn_s::status.
Referenced by ngx_http_download_finalize_connection().
ngx_int_t ngx_http_download_parse_url | ( | ngx_str_t * | url, | |
ngx_http_download_conn_t * | conn | |||
) |
Parses url and put all required data to download structure.
url | correct url, ex. http://example.com/file.php?a=1 | |
conn | initialized download structure |
Definition at line 255 of file ngx_http_download_module.c.
References ngx_http_download_conn_s::err, ngx_http_download_conn_s::host, ngx_http_download_conn_s::pool, ngx_http_download_conn_s::port, and ngx_http_download_conn_s::uri.
Referenced by ngx_http_xslt2_xml_get_external_stylesheet(), and ngx_http_xxslt_parse_get_external_include().
static void ngx_http_download_read_handler | ( | ngx_event_t * | rev | ) | [static] |
Handler called by nginx if socket is ready to read - read data from socket.
rev | nginx write event |
Definition at line 540 of file ngx_http_download_module.c.
References ngx_http_download_conn_s::buffer, BUFFER_SIZE, ngx_http_download_conn_s::data, ngx_http_download_conn_s::host, ngx_http_download_conn_s::log, ngx_http_download_finalize_connection(), ngx_http_download_flush_buffer(), ngx_http_download_conn_s::p, ngx_http_download_conn_s::r, ngx_http_download_conn_s::read_timeout, ngx_http_download_conn_s::response_length, ngx_http_download_conn_s::rpool, and ngx_http_download_conn_s::terminated.
Referenced by ngx_http_download_enqueue().
static void ngx_http_download_write_handler | ( | ngx_event_t * | wev | ) | [static] |
Handler called by nginx if socket is ready to write - write data to socket.
wev | nginx write event |
Definition at line 457 of file ngx_http_download_module.c.
References ngx_http_download_conn_s::data, ngx_http_download_conn_s::host, ngx_http_download_conn_s::log, ngx_http_download_dummy_handler(), ngx_http_download_finalize_connection(), ngx_http_download_conn_s::p, ngx_http_download_conn_s::r, ngx_http_download_conn_s::request, ngx_http_download_conn_s::terminated, and ngx_http_download_conn_s::write_timeout.
Referenced by ngx_http_download_enqueue().
ngx_command_t ngx_http_download_commands[] [static] |
{ {ngx_string( "download_server_timeout" ), NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, ngx_conf_set_msec_slot, NGX_HTTP_LOC_CONF_OFFSET, offsetof(ngx_http_download_conf_t, server_timeout), NULL}, ngx_null_command }
Nginx config file commands configuration.
Definition at line 40 of file ngx_http_download_module.c.
ngx_module_t ngx_http_download_module |
{ NGX_MODULE_V1, &ngx_http_download_module_ctx, ngx_http_download_commands, NGX_HTTP_MODULE, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NGX_MODULE_V1_PADDING }
Nginx module settings.
Definition at line 59 of file ngx_http_download_module.c.
Referenced by ngx_http_download_create_new().
ngx_http_module_t ngx_http_download_module_ctx [static] |
{ NULL,NULL,NULL,NULL,NULL,NULL, ngx_http_download_create_conf, ngx_http_download_merge_conf }
Nginx module context.
Definition at line 52 of file ngx_http_download_module.c.