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 _MXCACHE_CONNECTION_H_INCLUDED_ 00023 #define _MXCACHE_CONNECTION_H_INCLUDED_ 00024 00025 #include <ngx_config.h> 00026 #include <ngx_core.h> 00027 #include <ngx_http.h> 00028 #include "ngx_connection_pool.h" 00029 00030 #define NGX_HTTP_MXCACHE_BUFFER_SIZE 4096 00031 00032 typedef struct ngx_http_mxcache_conn_s ngx_http_mxcache_conn_t; 00033 typedef void (*ngx_http_mxcache_conn_handler_pt)(ngx_http_mxcache_conn_t *conn); 00034 00036 struct ngx_http_mxcache_conn_s { 00037 ngx_http_request_t *r; 00038 00040 u_char *key; 00042 ngx_uint_t flag; 00044 ngx_uint_t exp_time; 00046 ngx_chain_t *request; 00047 00049 u_char *res_uri; 00051 u_char *err; 00052 00054 ngx_uint_t read_timeout; 00056 ngx_uint_t write_timeout; 00057 00059 ngx_pooled_connection_t *connection; 00060 00062 ngx_buf_t *buffer; 00064 ngx_chain_t *out_bufs; 00066 ngx_chain_t *out_bufs_tail; 00067 00069 u_char *data_begin; 00070 00072 ngx_uint_t response_length; 00074 ngx_uint_t bytes; 00076 ngx_int_t header_len; 00078 ngx_int_t state; 00079 00081 ngx_int_t terminated; 00083 ngx_int_t error; 00085 ngx_int_t done; 00086 00087 ngx_pool_t *pool; 00088 ngx_pool_t *rpool; 00089 ngx_log_t *log; 00090 00092 ngx_http_mxcache_conn_handler_pt done_handler; 00093 00095 void *data; 00096 }; 00097 00099 typedef struct { 00101 ngx_msec_t server_timeout; 00103 ngx_str_t server_ip; 00105 ngx_uint_t server_port; 00107 ngx_msec_t expire; 00108 00110 struct sockaddr_in *sockaddr; 00112 ngx_pool_t *pool; 00114 ngx_log_t *log; 00115 00117 ngx_connection_pool_t *connection_pool; 00118 00120 ngx_flag_t enabled; 00121 00122 } ngx_http_mxcache_conf_t; 00123 00124 00125 // check if the module is enabled in config file 00126 ngx_int_t 00127 ngx_http_mxcache_is_enabled(ngx_http_request_t *r); 00128 00129 // create and initialize new mxcache structure 00130 ngx_http_mxcache_conn_t * 00131 ngx_http_mxcache_create_new(ngx_http_request_t *r); 00132 00133 // get data from memcached 00134 ngx_int_t 00135 ngx_http_mxcache_get(ngx_http_mxcache_conn_t *conn); 00136 00137 // set data to memcached 00138 ngx_int_t 00139 ngx_http_mxcache_set(ngx_http_mxcache_conn_t *conn); 00140 00141 // cancel mxcache, free all mxcache resources 00142 ngx_int_t 00143 ngx_http_mxcache_cleanup(ngx_http_mxcache_conn_t *conn); 00144 00145 #endif 00146