1 /* $Id: proxy.h,v 1.25 2005-10-13 09:58:52 adam Exp $
2 Copyright (c) 1998-2005, Index Data.
4 This file is part of the yaz-proxy.
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 <yaz++/socket-observer.h>
26 #include <yaz++/z-assoc.h>
27 #include <yaz++/z-query.h>
28 #include <yaz++/z-databases.h>
29 #include <yaz++/cql2rpn.h>
31 #include <yaz++/gdu.h>
32 #include <yaz++/gduqueue.h>
33 #include <yazproxy/bw.h>
37 #define MAX_ZURL_PLEX 10
39 #define PROXY_LOG_APDU_CLIENT 1
40 #define PROXY_LOG_APDU_SERVER 2
41 #define PROXY_LOG_REQ_CLIENT 4
42 #define PROXY_LOG_REQ_SERVER 8
45 class Yaz_ProxyConfig;
46 class Yaz_ProxyClient;
47 class Yaz_CharsetConverter;
49 enum YAZ_Proxy_MARCXML_mode {
56 /// Information Retrieval Proxy Server.
57 class YAZ_EXPORT Yaz_Proxy : public yazpp_1::Z_Assoc {
58 friend class Proxy_Msg;
62 char *get_cookie(Z_OtherInformation **otherInfo);
63 char *get_proxy(Z_OtherInformation **otherInfo);
64 void get_charset_and_lang_negotiation(Z_OtherInformation **otherInfo,
65 char **charstes, char **langs, int *selected);
66 Yaz_ProxyClient *get_client(Z_APDU *apdu, const char *cookie,
67 const char *proxy_host);
68 void srw_get_client(const char *db, const char **backend_db);
69 Z_APDU *result_set_optimize(Z_APDU *apdu);
71 Yaz_ProxyClient *m_client;
72 yazpp_1::IPDU_Observable *m_PDU_Observable;
73 yazpp_1::ISocketObservable *m_socket_observable;
74 Yaz_ProxyClient *m_clientPool;
79 int m_keepalive_limit_bw;
80 int m_keepalive_limit_pdu;
81 int m_client_idletime;
82 int m_target_idletime;
85 char *m_default_target;
86 char *m_proxy_negotiation_charset;
87 char *m_proxy_negotiation_lang;
90 int m_session_no; // sequence for each client session
91 char m_session_str[30]; // session string (time:session_no)
92 Yaz_ProxyConfig *m_config;
98 yazpp_1::GDU *m_timeout_gdu;
111 int m_max_record_retrieve;
112 void handle_max_record_retrieve(Z_APDU *apdu);
113 void display_diagrecs(Z_DiagRec **pp, int num);
114 Z_Records *create_nonSurrogateDiagnostics(ODR o, int error,
115 const char *addinfo);
117 Z_APDU *handle_query_validation(Z_APDU *apdu);
118 Z_APDU *handle_query_transformation(Z_APDU *apdu);
119 Z_APDU *handle_target_charset_conversion(Z_APDU *apdu);
121 Z_APDU *handle_syntax_validation(Z_APDU *apdu);
123 void handle_charset_lang_negotiation(Z_APDU *apdu);
125 const char *load_balance(const char **url);
127 Yaz_ProxyConfig *check_reconfigure();
129 int m_flag_invalid_session;
130 YAZ_Proxy_MARCXML_mode m_marcxml_mode;
131 void *m_stylesheet_xsp; // Really libxslt's xsltStylesheetPtr
132 int m_stylesheet_offset;
133 Z_APDU *m_stylesheet_apdu;
134 Z_NamePlusRecordList *m_stylesheet_nprl;
136 char *m_backend_type;
137 char *m_backend_charset;
139 void convert_to_frontend_type(Z_NamePlusRecordList *p);
140 void convert_to_marcxml(Z_NamePlusRecordList *p, const char *charset);
141 void convert_records_charset(Z_NamePlusRecordList *p, const char *charset);
142 int convert_xsl(Z_NamePlusRecordList *p, Z_APDU *apdu);
143 void convert_xsl_delay();
144 Z_APDU *m_initRequest_apdu;
145 int m_initRequest_preferredMessageSize;
146 int m_initRequest_maximumRecordSize;
147 Z_Options *m_initRequest_options;
148 Z_ProtocolVersion *m_initRequest_version;
149 char **m_initRequest_oi_negotiation_charsets;
150 int m_initRequest_oi_negotiation_num_charsets;
151 char **m_initRequest_oi_negotiation_langs;
152 int m_initRequest_oi_negotiation_num_langs;
153 int m_initRequest_oi_negotiation_selected;
154 NMEM m_initRequest_mem;
155 Z_APDU *m_apdu_invalid_session;
156 NMEM m_mem_invalid_session;
157 int send_PDU_convert(Z_APDU *apdu);
159 ODR m_s2z_odr_search;
162 char *m_s2z_database;
163 Z_APDU *m_s2z_init_apdu;
164 Z_APDU *m_s2z_search_apdu;
165 Z_APDU *m_s2z_present_apdu;
166 char *m_s2z_stylesheet;
168 int file_access(Z_HTTP_Request *hreq);
169 int send_to_srw_client_error(int error, const char *add);
170 int send_to_srw_client_ok(int hits, Z_Records *records, int start);
171 int send_http_response(int code);
172 int send_srw_response(Z_SRW_PDU *srw_pdu);
173 int send_srw_explain_response(Z_SRW_diagnostic *diagnostics,
174 int num_diagnostics);
175 int z_to_srw_diag(ODR o, Z_SRW_searchRetrieveResponse *srw_res,
176 Z_DefaultDiagFormat *ddf);
177 int m_http_keepalive;
178 const char *m_http_version;
179 yazpp_1::Yaz_cql2rpn m_cql2rpn;
182 Z_ElementSetNames *mk_esn_from_schema(ODR o, const char *schema);
183 Z_ReferenceId *m_referenceId;
184 NMEM m_referenceId_mem;
186 #define NO_SPARE_SOLARIS_FD 10
187 int m_lo_fd[NO_SPARE_SOLARIS_FD];
188 void low_socket_open();
189 void low_socket_close();
190 char *m_usemarcon_ini_stage1;
191 char *m_usemarcon_ini_stage2;
192 Yaz_usemarcon *m_usemarcon;
193 Yaz_CharsetConverter *m_charset_converter;
194 yazpp_1::GDUQueue m_in_queue;
196 Yaz_Proxy(yazpp_1::IPDU_Observable *the_PDU_Observable,
197 yazpp_1::ISocketObservable *the_socket_observable,
198 Yaz_Proxy *parent = 0);
206 int handle_authentication(Z_APDU *apdu);
207 void result_authentication(Z_APDU *apdu, int ret);
208 void handle_init(Z_APDU *apdu);
209 void inc_request_no();
210 void recv_GDU(Z_GDU *apdu, int len);
211 void recv_GDU_reduce(yazpp_1::GDU *gdu);
212 void recv_GDU_normal(yazpp_1::GDU *gdu);
213 void recv_GDU_more(bool normal);
214 void handle_incoming_HTTP(Z_HTTP_Request *req);
215 void handle_incoming_Z_PDU(Z_APDU *apdu);
216 void handle_incoming_Z_PDU_2(Z_APDU *apdu);
217 IPDU_Observer *sessionNotify(yazpp_1::IPDU_Observable *the_PDU_Observable,
220 void timeoutNotify();
221 void connectNotify();
223 const char *option(const char *name, const char *value);
224 void set_default_target(const char *target);
225 void set_proxy_negotiation (const char *charset, const char *lang);
226 void set_target_charset(const char *charset);
227 char *get_proxy_target() { return m_proxyTarget; };
228 char *get_session_str() { return m_session_str; };
229 void set_max_clients(int m) { m_max_clients = m; };
230 void set_client_idletime (int t) { m_client_idletime = (t > 1) ? t : 600; };
231 void set_target_idletime (int t) { m_target_idletime = (t > 1) ? t : 600; };
232 int get_target_idletime () { return m_target_idletime; }
233 int set_config(const char *name);
234 void reconfig() { m_reconfig_flag = 1; }
235 int send_to_client(Z_APDU *apdu);
236 int server(const char *addr);
238 int get_log_mask() { return m_log_mask; };
239 int handle_init_response_for_invalid_session(Z_APDU *apdu);
240 void set_debug_mode(int mode);
241 Msg_Thread *m_my_thread;
248 * indent-tabs-mode: nil
250 * vim: shiftwidth=4 tabstop=8 expandtab