1 /* $Id: proxy.h,v 1.4 2004-04-22 07:46:21 adam Exp $
2 Copyright (c) 1998-2004, 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 #include <yaz++/z-assoc.h>
23 #include <yaz++/z-query.h>
24 #include <yaz++/z-databases.h>
25 #include <yaz++/cql2rpn.h>
27 #include <yazproxy/bw.h>
31 #define MAX_ZURL_PLEX 10
33 #define PROXY_LOG_APDU_CLIENT 1
34 #define PROXY_LOG_APDU_SERVER 2
35 #define PROXY_LOG_REQ_CLIENT 4
36 #define PROXY_LOG_REQ_SERVER 8
38 struct Yaz_RecordCache_Entry;
39 class Yaz_ProxyConfigP;
41 class YAZ_EXPORT Yaz_ProxyConfig {
45 int read_xml(const char *fname);
47 int get_target_no(int no,
56 int *keepalive_limit_bw,
57 int *keepalive_limit_pdu,
59 const char **cql2rpn);
61 void get_generic_info(int *log_mask, int *max_clients);
63 void get_target_info(const char *name, const char **url,
64 int *limit_bw, int *limit_pdu, int *limit_req,
65 int *target_idletime, int *client_idletime,
67 int *keepalive_limit_bw, int *keepalive_limit_pdu,
69 const char **cql2rpn);
71 int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo);
72 int check_syntax(ODR odr, const char *name,
73 Odr_oid *syntax, Z_RecordComposition *comp,
74 char **addinfo, char **stylesheet, char **schema);
75 char *get_explain(ODR odr, const char *name, const char *db,
78 void operator=(const Yaz_ProxyConfig &conf);
79 class Yaz_ProxyConfigP *m_cp;
82 class YAZ_EXPORT Yaz_RecordCache {
86 void add (ODR o, Z_NamePlusRecordList *npr, int start, int hits);
88 int lookup (ODR o, Z_NamePlusRecordList **npr, int start, int num,
89 Odr_oid *syntax, Z_RecordComposition *comp);
92 void copy_searchRequest(Z_SearchRequest *sr);
93 void copy_presentRequest(Z_PresentRequest *pr);
94 void set_max_size(int sz);
97 Yaz_RecordCache_Entry *m_entries;
98 Z_SearchRequest *m_searchRequest;
99 Z_PresentRequest *m_presentRequest;
100 int match (Yaz_RecordCache_Entry *entry,
101 Odr_oid *syntax, int offset,
102 Z_RecordComposition *comp);
107 class YAZ_EXPORT Yaz_ProxyClient : public Yaz_Z_Assoc {
108 friend class Yaz_Proxy;
109 Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable,
112 void recv_GDU(Z_GDU *apdu, int len);
113 void recv_Z_PDU(Z_APDU *apdu, int len);
114 void recv_HTTP_response(Z_HTTP_Response *apdu, int len);
115 IYaz_PDU_Observer* sessionNotify
116 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
120 void timeoutNotify();
121 void connectNotify();
122 int send_to_target(Z_APDU *apdu);
123 const char *get_session_str();
125 Yaz_ProxyClient *m_next;
126 Yaz_ProxyClient **m_prev;
128 Yaz_Z_Query *m_last_query;
129 Yaz_Z_Databases m_last_databases;
130 char *m_last_resultSetId;
132 int m_last_resultCount;
136 int m_resultSetStartPoint;
141 Z_APDU *m_initResponse;
142 Z_Options *m_initResponse_options;
143 Z_ProtocolVersion *m_initResponse_version;
144 int m_initResponse_preferredMessageSize;
145 int m_initResponse_maximumRecordSize;
146 Yaz_RecordCache m_cache;
147 void pre_init_client();
148 int m_target_idletime;
153 /// Information Retrieval Proxy Server.
154 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
156 char *get_cookie(Z_OtherInformation **otherInfo);
157 char *get_proxy(Z_OtherInformation **otherInfo);
158 Yaz_ProxyClient *get_client(Z_APDU *apdu, const char *cookie,
159 const char *proxy_host);
160 Z_APDU *result_set_optimize(Z_APDU *apdu);
163 Yaz_ProxyClient *m_client;
164 IYaz_PDU_Observable *m_PDU_Observable;
165 Yaz_ProxyClient *m_clientPool;
170 int m_keepalive_limit_bw;
171 int m_keepalive_limit_pdu;
172 int m_client_idletime;
173 int m_target_idletime;
175 char *m_default_target;
176 char *m_proxy_authentication;
179 int m_session_no; // sequence for each client session
180 char m_session_str[30]; // session string (time:session_no)
181 Yaz_ProxyConfig *m_config;
182 char *m_config_fname;
189 Z_GDU *m_bw_hold_PDU;
190 int m_max_record_retrieve;
191 void handle_max_record_retrieve(Z_APDU *apdu);
192 void display_diagrecs(Z_DiagRec **pp, int num);
193 Z_Records *create_nonSurrogateDiagnostics(ODR o, int error,
194 const char *addinfo);
196 Z_APDU *handle_query_validation(Z_APDU *apdu);
197 Z_APDU *handle_query_transformation(Z_APDU *apdu);
199 Z_APDU *handle_syntax_validation(Z_APDU *apdu);
200 const char *load_balance(const char **url);
202 Yaz_ProxyConfig *check_reconfigure();
204 int m_invalid_session;
206 void *m_stylesheet_xsp; // Really libxslt's xsltStylesheetPtr
207 int m_stylesheet_offset;
208 Z_APDU *m_stylesheet_apdu;
209 Z_NamePlusRecordList *m_stylesheet_nprl;
211 void convert_to_marcxml(Z_NamePlusRecordList *p);
212 int convert_xsl(Z_NamePlusRecordList *p, Z_APDU *apdu);
213 void convert_xsl_delay();
214 Z_APDU *m_initRequest_apdu;
215 int m_initRequest_preferredMessageSize;
216 int m_initRequest_maximumRecordSize;
217 Z_Options *m_initRequest_options;
218 Z_ProtocolVersion *m_initRequest_version;
219 NMEM m_initRequest_mem;
220 Z_APDU *m_apdu_invalid_session;
221 NMEM m_mem_invalid_session;
222 int send_PDU_convert(Z_APDU *apdu);
224 ODR m_s2z_odr_search;
227 char *m_s2z_database;
228 Z_APDU *m_s2z_init_apdu;
229 Z_APDU *m_s2z_search_apdu;
230 Z_APDU *m_s2z_present_apdu;
231 char *m_s2z_stylesheet;
233 int send_to_srw_client_error(int error, const char *add);
234 int send_to_srw_client_ok(int hits, Z_Records *records, int start);
235 int send_http_response(int code);
236 int send_srw_response(Z_SRW_PDU *srw_pdu);
237 int send_srw_explain_response(Z_SRW_diagnostic *diagnostics,
238 int num_diagnostics);
239 int z_to_srw_diag(ODR o, Z_SRW_searchRetrieveResponse *srw_res,
240 Z_DefaultDiagFormat *ddf);
241 int m_http_keepalive;
242 const char *m_http_version;
243 Yaz_cql2rpn m_cql2rpn;
246 Z_ElementSetNames *mk_esn_from_schema(ODR o, const char *schema);
247 Z_ReferenceId *m_referenceId;
248 NMEM m_referenceId_mem;
249 #define NO_SPARE_SOLARIS_FD 10
250 int m_lo_fd[NO_SPARE_SOLARIS_FD];
251 void low_socket_open();
252 void low_socket_close();
254 Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable,
255 Yaz_Proxy *parent = 0);
257 void inc_request_no();
258 void recv_GDU(Z_GDU *apdu, int len);
259 void handle_incoming_HTTP(Z_HTTP_Request *req);
260 void handle_incoming_Z_PDU(Z_APDU *apdu);
261 IYaz_PDU_Observer* sessionNotify
262 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
264 void timeoutNotify();
265 void connectNotify();
267 const char *option(const char *name, const char *value);
268 void set_default_target(const char *target);
269 void set_proxy_authentication (const char *auth);
270 char *get_proxy_target() { return m_proxyTarget; };
271 char *get_session_str() { return m_session_str; };
272 void set_max_clients(int m) { m_max_clients = m; };
273 void set_client_idletime (int t) { m_client_idletime = (t > 1) ? t : 600; };
274 void set_target_idletime (int t) { m_target_idletime = (t > 1) ? t : 600; };
275 int get_target_idletime () { return m_target_idletime; }
276 int set_config(const char *name);
277 void reconfig() { m_reconfig_flag = 1; }
278 int send_to_client(Z_APDU *apdu);
279 int server(const char *addr);
281 int get_log_mask() { return m_log_mask; };
282 int handle_init_response_for_invalid_session(Z_APDU *apdu);