00001 /* 00002 * Copyright 2009 DreamLab Onet.pl Sp. z o.o. 00003 * Licensed under the Apache License, Version 2.0 (the "License"); 00004 * you may not use this file except in compliance with the License. 00005 * You may obtain a copy of the License at 00006 * 00007 * http://www.apache.org/licenses/LICENSE-2.0 00008 * 00009 * Unless required by applicable law or agreed to in writing, software 00010 * distributed under the License is distributed on an "AS IS" BASIS, 00011 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00012 * See the License for the specific language governing permissions and 00013 * limitations under the License. 00014 * 00015 * 00016 * Authors: 00017 * Przemyslaw Gajda, email: quermit(malpa)gmail.com 00018 * Piotr Janik, email: janik.piotrek(malpa)gmail.com 00019 * malpa = @ 00020 */ 00021 00022 #ifndef _DOWNLOAD_CONNECTION_H_INCLUDED_ 00023 #define _DOWNLOAD_CONNECTION_H_INCLUDED_ 00024 00025 #define BUFFER_SIZE 4096 00026 00027 typedef struct ngx_http_download_conn_s ngx_http_download_conn_t; 00028 typedef void (*ngx_http_download_conn_handler_pt)(ngx_http_download_conn_t *conn); 00029 00032 struct ngx_http_download_conn_s { 00034 ngx_http_request_t *r; 00035 00037 u_char *host; 00039 ngx_int_t port; 00041 u_char *uri; 00043 u_char *args; 00044 00046 u_char *err; 00047 00048 u_char *fulluri; 00049 00051 ngx_uint_t connect_timeout; 00053 ngx_uint_t read_timeout; 00055 ngx_uint_t write_timeout; 00056 00058 ngx_buf_t *request; 00059 00060 ngx_peer_connection_t *p; 00061 ngx_buf_t *buffer; 00062 00064 ngx_chain_t *out_bufs; 00066 ngx_chain_t *out_bufs_tail; 00068 u_char *body_start; 00070 ngx_int_t status; 00071 00073 ngx_uint_t response_length; 00074 00076 ngx_int_t terminated; 00078 ngx_int_t error; 00080 ngx_int_t done; 00081 00082 ngx_pool_t *pool; 00083 ngx_pool_t *rpool; 00084 ngx_log_t *log; 00085 00087 ngx_http_download_conn_handler_pt done_handler; 00088 00090 void *data; 00091 }; 00092 00095 typedef struct { 00096 ngx_log_t *log; 00097 ngx_msec_t server_timeout; 00098 } ngx_http_download_conf_t; 00099 00100 // create and initialize new download structure 00101 ngx_http_download_conn_t * ngx_http_download_create_new(); 00102 00103 // enqueue download, need correct ngx_http_download_conn_t structure 00104 // when finished done_handler will be called 00105 ngx_int_t ngx_http_download_enqueue(ngx_http_download_conn_t *conn); 00106 00107 // parse url and put all required data in conn structure 00108 ngx_int_t ngx_http_download_parse_url(ngx_str_t *url, ngx_http_download_conn_t *conn); 00109 00110 // cancel download and free all allocated data 00111 void ngx_http_download_cleanup(ngx_http_download_conn_t *conn); 00112 00113 #endif 00114