1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
/*
* Copyright (C) 2004-2008 Christos Tsantilas
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*/
/**
\defgroup ICAPCLIENT ICAP client request API
\ingroup API
* API for implementing ICAP clients
*/
#ifndef _REQUEST_H
#define _REQUEST_H
#include "header.h"
#include "service.h"
#include "net_io.h"
#include "array.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
\defgroup REQUEST ICAP request API
\ingroup API
* ICAP request related API.
*/
/**
\defgroup ICAPCLIENT ICAP client request API
\ingroup API
* API for implementing ICAP clients
*/
//enum REQUEST_STATUS { WAIT,SERVED };
enum GETDATA_STATUS {GET_NOTHING = 0,GET_HEADERS,GET_PREVIEW,GET_BODY,GET_EOF};
enum SENDDATA_STATUS {SEND_NOTHING = 0, SEND_RESPHEAD, SEND_HEAD1, SEND_HEAD2, SEND_HEAD3, SEND_BODY, SEND_EOF };
/*enum BODY_RESPONCE_STATUS{ CHUNK_DEF = 1,CHUNK_BODY,CHUNK_END};*/
enum CLIENT_STATUS {
CLIENT_INIT = 0,
CLIENT_SEND_HEADERS,
CLIENT_SEND_HEADERS_WRITE_NOTHING = CLIENT_SEND_HEADERS,
CLIENT_SEND_HEADERS_WRITE_ICAP_HEADERS,
CLIENT_SEND_HEADERS_WRITE_REQ_HEADERS,
CLIENT_SEND_HEADERS_WRITE_RES_HEADERS,
CLIENT_SEND_HEADERS_WRITE_PREVIEW_INFO,
CLIENT_SEND_HEADERS_WRITE_PREVIEW,
CLIENT_SEND_HEADERS_WRITE_EOF_INFO,
CLIENT_SEND_HEADERS_FINISHED,
CLIENT_READ_PREVIEW_RESPONSE,
CLIENT_PROCESS_DATA,
CLIENT_PROCESS_DATA_GET_NOTHING = CLIENT_PROCESS_DATA,
CLIENT_PROCESS_DATA_GET_HEADERS,
CLIENT_PROCESS_DATA_HEADERS_FINISHED,
CLIENT_PROCESS_DATA_GET_BODY,
CLIENT_PROCESS_DATA_GET_EOF
};
#define NEEDS_TO_READ_FROM_ICAP 0x1
#define NEEDS_TO_WRITE_TO_ICAP 0x2
#define NEEDS_TO_READ_USER_DATA 0x4
#define NEEDS_TO_WRITE_USER_DATA 0x8
#define CI_NO_STATUS 0
#define CI_OK 1
#define CI_NEEDS_MORE 2
#define CI_ERROR -1
#define CI_EOF -2
#define EXTRA_CHUNK_SIZE 30
#define MAX_CHUNK_SIZE 4064 /*4096 -EXTRA_CHUNK_SIZE-2*/
#define MAX_USERNAME_LEN 255
typedef struct ci_buf {
char *buf;
int size;
int used;
} ci_buf_t;
struct ci_service_module;
struct ci_ring_buf;
/**
\typedef ci_request_t
\ingroup REQUEST
* This is the struct which holds all the data which represent an ICAP
* request. The developers should not access directly the fields of
* this struct but better use the documented macros and functions
*/
typedef struct ci_request {
ci_connection_t *connection;
int packed;
int type;
char req_server[CI_MAXHOSTNAMELEN+1];
int access_type;
char user[MAX_USERNAME_LEN+1];
char service[MAX_SERVICE_NAME+1];
char args[MAX_SERVICE_ARGS];
int preview;
int keepalive;
int allow204;
int hasbody;
int responce_hasbody;
struct ci_buf preview_data;
struct ci_service_module *current_service_mod;
ci_headers_list_t *request_header;
ci_headers_list_t *response_header;
ci_encaps_entity_t *entities[5];//At most 3 and 1 for termination.....
ci_encaps_entity_t *trash_entities[7];
ci_headers_list_t *xheaders;
void *service_data;
char rbuf[BUFSIZE];
char wbuf[MAX_CHUNK_SIZE+EXTRA_CHUNK_SIZE+2];
int eof_received;
int eof_sent;
int data_locked;
char *pstrblock_read;
int pstrblock_read_len;
unsigned int current_chunk_len;
unsigned int chunk_bytes_read;
unsigned int write_to_module_pending;
int status;
int return_code;
char *pstrblock_responce;
int remain_send_block_bytes;
/*Used to echo data back to a client which does not support preview
in the case of 204 outside preview.*/
struct ci_ring_buf *echo_body;
/*Caching values for various subsystems*/
int preview_data_type;
int auth_required;
/*log string*/
char *log_str;
ci_str_array_t *attributes;
/* statistics */
uint64_t bytes_in; /*May include bytes from next pipelined request*/
uint64_t bytes_out;
uint64_t request_bytes_in; /*Current request input bytes*/
uint64_t http_bytes_in;
uint64_t http_bytes_out;
uint64_t body_bytes_in;
uint64_t body_bytes_out;
/* added flags/variables*/
int allow206;
int64_t i206_use_original_body;
ci_ip_t xclient_ip;
} ci_request_t;
#define lock_data(req) (req->data_locked = 1)
#define unlock_data(req) (req->data_locked = 0)
/*This functions needed in server (mpmt_server.c ) */
ci_request_t *newrequest(ci_connection_t *connection);
int recycle_request(ci_request_t *req,ci_connection_t *connection);
int keepalive_request(ci_request_t *req);
int process_request(ci_request_t *);
/*Functions used in both server and icap-client library*/
CI_DECLARE_FUNC(int) parse_chunk_data(ci_request_t *req, char **wdata);
CI_DECLARE_FUNC(int) net_data_read(ci_request_t *req);
CI_DECLARE_FUNC(int) process_encapsulated(ci_request_t *req, const char *buf);
/*********************************************/
/*Buffer functions (I do not know if they must included in ci library....) */
CI_DECLARE_FUNC(void) ci_buf_init(struct ci_buf *buf);
CI_DECLARE_FUNC(void) ci_buf_reset(struct ci_buf *buf);
CI_DECLARE_FUNC(int) ci_buf_mem_alloc(struct ci_buf *buf,int size);
CI_DECLARE_FUNC(void) ci_buf_mem_free(struct ci_buf *buf);
CI_DECLARE_FUNC(int) ci_buf_write(struct ci_buf *buf,char *data,int len);
CI_DECLARE_FUNC(int) ci_buf_reset_size(struct ci_buf *buf,int req_size);
/***************/
/*API defines */
#define ci_service_data(req) ((req)->service_data)
#define ci_allow204(req) ((req)->allow204)
#define ci_allow206(req) ((req)->allow206)
/*API functions ......*/
CI_DECLARE_FUNC(ci_request_t *) ci_request_alloc(ci_connection_t *connection);
CI_DECLARE_FUNC(void) ci_request_reset(ci_request_t *req);
CI_DECLARE_FUNC(void) ci_request_destroy(ci_request_t *req);
CI_DECLARE_FUNC(void) ci_request_pack(ci_request_t *req);
CI_DECLARE_FUNC(void) ci_response_pack(ci_request_t *req);
CI_DECLARE_FUNC(ci_encaps_entity_t *) ci_request_alloc_entity(ci_request_t *req,int type,int val);
CI_DECLARE_FUNC(int) ci_request_release_entity(ci_request_t *req,int pos);
CI_DECLARE_FUNC(char *) ci_request_set_log_str(ci_request_t *req, char *logstr);
CI_DECLARE_FUNC(int) ci_request_set_str_attribute(ci_request_t *req, const char *name, const char *value);
CI_DECLARE_FUNC(int) ci_request_206_origin_body(ci_request_t *req, uint64_t offset);
/*ICAP client api*/
CI_DECLARE_FUNC(ci_request_t *) ci_client_request(ci_connection_t *conn,const char *server,const char *service);
CI_DECLARE_FUNC(void) ci_client_request_reuse(ci_request_t *req);
CI_DECLARE_FUNC(int) ci_client_get_server_options(ci_request_t *req,int timeout);
CI_DECLARE_FUNC(int) ci_client_get_server_options_non_blocking(ci_request_t *req);
CI_DECLARE_FUNC(int) ci_client_icapfilter(ci_request_t *req,
int timeout,
ci_headers_list_t *req_headers,
ci_headers_list_t *resp_headers,
void *data_source,
int (*source_read)(void *,char *,int),
void *data_dest,
int (*dest_write) (void *,char *,int));
/**
\ingroup ICAPCLIENT
* Function to send HTTP objects to an ICAP server for processing. It sends
* the HTTP request headers, and the HTTP response from HTTP server (headers
* plus body data), and receives modified HTTP response headers and body data.
\param req The ci_request_t object.
\param io_action is a combination set of ci_wait_for_read and
* ci_wait_for_write flags. It has the meaning that the
* ci_client_icapfilter_nonblocking can read from or write to ICAP server.
\param req_headers The HTTP request headers to use.
\param resp_headers The HTTP response headers to use.
\param data_source User data to use with source_read callback function.
\param source_read Callback function to use for reading HTTP object body data.
\param data_dest User data to use with dest_write callback function.
\param dest_write Callback function to use for storing modified body data.
\return combination of the following flags: NEEDS_TO_READ_FROM_ICAP,
* NEEDS_TO_WRITE_TO_ICAP, NEEDS_TO_READ_USER_DATA and
* NEEDS_TO_WRITE_USER_DATA.
*/
CI_DECLARE_FUNC(int) ci_client_icapfilter_nonblocking(ci_request_t * req, int io_action,
ci_headers_list_t * req_headers,
ci_headers_list_t * resp_headers,
void *data_source,
int (*source_read) (void *, char *, int),
void *data_dest,
int (*dest_write) (void *, char *, int));
CI_DECLARE_FUNC(int) ci_client_http_headers_completed(ci_request_t * req);
CI_DECLARE_FUNC(void) ci_client_set_user_agent(const char *agent);
CI_DECLARE_FUNC(void) ci_client_library_init();
CI_DECLARE_FUNC(void) ci_client_library_release();
/** Deprecated. Use ci_connect_to declared in net_io.h instead. */
CI_DECLARE_FUNC(ci_connection_t *) ci_client_connect_to(char *servername,int port,int proto);
#ifdef __CI_COMPAT
#define request_t ci_request_t
#endif
#ifdef __cplusplus
}
#endif
#endif
|