1 /* $Id: proxy.h,v 1.39 2007-05-08 12:05:08 adam Exp $
2 Copyright (c) 1998-2007, Index Data.
4 This file is part of the yazproxy.
6 YAZ proxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with YAZ proxy; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #ifndef YAZ_PROXY_H_INCLUDED
23 #define YAZ_PROXY_H_INCLUDED
25 #include <yazpp/socket-observer.h>
26 #include <yazpp/z-assoc.h>
27 #include <yazpp/z-query.h>
28 #include <yazpp/z-databases.h>
29 #include <yazpp/cql2rpn.h>
31 #include <yazpp/gdu.h>
32 #include <yazpp/gduqueue.h>
33 #include <yazproxy/bw.h>
34 #include <yazproxy/limit-connect.h>
38 #define MAX_ZURL_PLEX 10
40 #define PROXY_LOG_APDU_CLIENT 1
41 #define PROXY_LOG_APDU_SERVER 2
42 #define PROXY_LOG_REQ_CLIENT 4
43 #define PROXY_LOG_REQ_SERVER 8
44 #define PROXY_LOG_IP_CLIENT 16
47 class Yaz_ProxyConfig;
48 class Yaz_ProxyClient;
49 class Yaz_CharsetConverter;
51 enum YAZ_Proxy_MARCXML_mode {
58 /// Information Retrieval Proxy Server.
59 class YAZ_EXPORT Yaz_Proxy : public yazpp_1::Z_Assoc {
60 friend class Proxy_Msg;
65 char *get_cookie(Z_OtherInformation **otherInfo);
66 char *get_proxy(Z_OtherInformation **otherInfo);
67 void get_charset_and_lang_negotiation(Z_OtherInformation **otherInfo,
68 char **charstes, char **langs, int *selected);
69 void HTTP_Forwarded(Z_GDU *z_gdu);
70 void connect_stat(bool &block, int &reduce);
71 Yaz_ProxyClient *get_client(Z_APDU *apdu, const char *cookie,
72 const char *proxy_host, int *http_code);
73 void srw_get_client(const char *db, const char **backend_db);
74 int get_number_of_connections();
75 Z_APDU *result_set_optimize(Z_APDU *apdu);
77 Yaz_ProxyClient *m_client;
78 yazpp_1::IPDU_Observable *m_PDU_Observable;
79 yazpp_1::ISocketObservable *m_socket_observable;
80 Yaz_ProxyClient *m_clientPool;
85 int m_keepalive_limit_bw;
86 int m_keepalive_limit_pdu;
87 int m_client_idletime;
88 int m_target_idletime;
92 char *m_default_target;
93 char *m_proxy_negotiation_charset;
94 char *m_proxy_negotiation_lang;
95 char *m_proxy_negotiation_default_charset;
98 int m_session_no; // sequence for each client session
99 char m_session_str[200]; // session string (time:session_no)
100 Yaz_ProxyConfig *m_config;
101 char *m_config_fname;
106 yazpp_1::GDU *m_timeout_gdu;
115 int m_max_connect_period;
117 int m_limit_connect_period;
122 int m_max_record_retrieve;
123 Yaz_bw m_search_stat;
125 void handle_max_record_retrieve(Z_APDU *apdu);
126 void display_diagrecs(Z_DiagRec **pp, int num);
127 Z_Records *create_nonSurrogateDiagnostics(ODR o, int error,
128 const char *addinfo);
130 Z_APDU *handle_query_validation(Z_APDU *apdu);
131 Z_APDU *handle_query_transformation(Z_APDU *apdu);
132 Z_APDU *handle_target_charset_conversion(Z_APDU *apdu);
134 Z_APDU *handle_syntax_validation(Z_APDU *apdu);
136 void handle_charset_lang_negotiation(Z_APDU *apdu);
138 const char *load_balance(const char **url);
140 Yaz_ProxyConfig *check_reconfigure();
142 int m_flag_invalid_session;
143 YAZ_Proxy_MARCXML_mode m_marcxml_mode;
144 void *m_stylesheet_xsp; // Really libxslt's xsltStylesheetPtr
145 int m_stylesheet_offset;
146 Z_APDU *m_stylesheet_apdu;
147 Z_NamePlusRecordList *m_stylesheet_nprl;
149 char *m_backend_type;
150 char *m_backend_charset;
151 Odr_oid m_frontend_type[OID_SIZE];
152 void convert_to_frontend_type(Z_NamePlusRecordList *p);
153 void convert_to_marcxml(Z_NamePlusRecordList *p, const char *charset);
154 void convert_records_charset(Z_NamePlusRecordList *p, const char *charset);
155 int convert_xsl(Z_NamePlusRecordList *p, Z_APDU *apdu);
156 void convert_xsl_delay();
157 Z_APDU *m_initRequest_apdu;
158 int m_initRequest_preferredMessageSize;
159 int m_initRequest_maximumRecordSize;
160 Z_Options *m_initRequest_options;
161 Z_ProtocolVersion *m_initRequest_version;
162 char **m_initRequest_oi_negotiation_charsets;
163 int m_initRequest_oi_negotiation_num_charsets;
164 char **m_initRequest_oi_negotiation_langs;
165 int m_initRequest_oi_negotiation_num_langs;
166 int m_initRequest_oi_negotiation_selected;
167 NMEM m_initRequest_mem;
168 Z_APDU *m_apdu_invalid_session;
169 NMEM m_mem_invalid_session;
170 int send_PDU_convert(Z_APDU *apdu);
172 ODR m_s2z_odr_search;
175 char *m_s2z_database;
176 Z_APDU *m_s2z_init_apdu;
177 Z_APDU *m_s2z_search_apdu;
178 Z_APDU *m_s2z_present_apdu;
179 char *m_s2z_stylesheet;
181 int file_access(Z_HTTP_Request *hreq);
182 int send_to_srw_client_error(int error, const char *add);
183 int send_to_srw_client_ok(int hits, Z_Records *records, int start);
184 int send_http_response(int code);
185 int send_srw_response(Z_SRW_PDU *srw_pdu, int http_code = 200);
186 int send_srw_search_response(Z_SRW_diagnostic *diagnostics,
188 int http_code = 200);
189 int send_srw_explain_response(Z_SRW_diagnostic *diagnostics,
190 int num_diagnostics);
191 int z_to_srw_diag(ODR o, Z_SRW_searchRetrieveResponse *srw_res,
192 Z_DefaultDiagFormat *ddf);
193 int m_http_keepalive;
194 const char *m_http_version;
195 yazpp_1::Yaz_cql2rpn m_cql2rpn;
198 Z_ElementSetNames *mk_esn_from_schema(ODR o, const char *schema);
199 Z_ReferenceId *m_referenceId;
200 NMEM m_referenceId_mem;
202 #define NO_SPARE_SOLARIS_FD 10
203 int m_lo_fd[NO_SPARE_SOLARIS_FD];
204 void low_socket_open();
205 void low_socket_close();
206 char *m_usemarcon_ini_stage1;
207 char *m_usemarcon_ini_stage2;
208 Yaz_usemarcon *m_usemarcon;
209 Yaz_CharsetConverter *m_charset_converter;
210 yazpp_1::GDUQueue m_in_queue;
211 LimitConnect m_connect;
213 Yaz_Proxy(yazpp_1::IPDU_Observable *the_PDU_Observable,
214 yazpp_1::ISocketObservable *the_socket_observable,
215 Yaz_Proxy *parent = 0);
221 int handle_authentication(Z_APDU *apdu);
222 int handle_global_authentication(Z_APDU *apdu);
223 void result_authentication(Z_APDU *apdu, int ret);
224 void handle_init(Z_APDU *apdu);
225 void inc_request_no();
226 void recv_GDU(Z_GDU *apdu, int len);
227 void recv_GDU_reduce(yazpp_1::GDU *gdu);
228 void recv_GDU_normal(yazpp_1::GDU *gdu);
229 void recv_GDU_more(bool normal);
230 void handle_incoming_HTTP(Z_HTTP_Request *req);
231 void handle_incoming_Z_PDU(Z_APDU *apdu);
232 void handle_incoming_Z_PDU_2(Z_APDU *apdu);
233 IPDU_Observer *sessionNotify(yazpp_1::IPDU_Observable *the_PDU_Observable,
236 void timeoutNotify();
237 void connectNotify();
239 const char *option(const char *name, const char *value);
240 void set_default_target(const char *target);
241 void set_proxy_negotiation(const char *charset, const char *lang,
242 const char *default_charset);
243 void set_target_charset(const char *charset);
244 char *get_proxy_target() { return m_proxyTarget; };
245 char *get_session_str() { return m_session_str; };
246 void set_max_clients(int m) { m_max_clients = m; };
247 void set_client_idletime (int t) { m_client_idletime = (t > 1) ? t : 600; };
248 void set_target_idletime (int t) { m_target_idletime = (t > 1) ? t : 600; };
249 int get_target_idletime () { return m_target_idletime; }
250 int set_config(const char *name);
251 void reconfig() { m_reconfig_flag = 1; }
252 int send_to_client(Z_APDU *apdu);
253 int server(const char *addr);
255 int get_log_mask() { return m_log_mask; };
256 int handle_init_response_for_invalid_session(Z_APDU *apdu);
257 void set_debug_mode(int mode);
258 void send_response_fail_client(const char *addr);
259 int m_num_msg_threads;
260 Msg_Thread *m_my_thread;
261 void base64_decode(const char *base64, char *buf, int buf_len);
268 * indent-tabs-mode: nil
270 * vim: shiftwidth=4 tabstop=8 expandtab