1 /* $Id: proxy.h,v 1.16 2005-05-18 20:15:22 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++/z-assoc.h>
26 #include <yaz++/z-query.h>
27 #include <yaz++/z-databases.h>
28 #include <yaz++/cql2rpn.h>
30 #include <yazproxy/bw.h>
34 #define MAX_ZURL_PLEX 10
36 #define PROXY_LOG_APDU_CLIENT 1
37 #define PROXY_LOG_APDU_SERVER 2
38 #define PROXY_LOG_REQ_CLIENT 4
39 #define PROXY_LOG_REQ_SERVER 8
42 class Yaz_ProxyConfig;
43 class Yaz_ProxyClient;
44 class Yaz_CharsetConverter;
46 enum YAZ_Proxy_MARCXML_mode {
51 /// Information Retrieval Proxy Server.
52 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
54 char *get_cookie(Z_OtherInformation **otherInfo);
55 char *get_proxy(Z_OtherInformation **otherInfo);
56 void get_charset_and_lang_negotiation(Z_OtherInformation **otherInfo,
57 char **charstes, char **langs, int *selected);
58 Yaz_ProxyClient *get_client(Z_APDU *apdu, const char *cookie,
59 const char *proxy_host);
60 void srw_get_client(const char *db, const char **backend_db);
61 Z_APDU *result_set_optimize(Z_APDU *apdu);
64 Yaz_ProxyClient *m_client;
65 IYaz_PDU_Observable *m_PDU_Observable;
66 Yaz_ProxyClient *m_clientPool;
71 int m_keepalive_limit_bw;
72 int m_keepalive_limit_pdu;
73 int m_client_idletime;
74 int m_target_idletime;
77 char *m_default_target;
78 char *m_proxy_negotiation_charset;
79 char *m_proxy_negotiation_lang;
82 int m_session_no; // sequence for each client session
83 char m_session_str[30]; // session string (time:session_no)
84 Yaz_ProxyConfig *m_config;
93 int m_max_record_retrieve;
94 void handle_max_record_retrieve(Z_APDU *apdu);
95 int handle_authentication(Z_APDU *apdu);
96 void display_diagrecs(Z_DiagRec **pp, int num);
97 Z_Records *create_nonSurrogateDiagnostics(ODR o, int error,
100 Z_APDU *handle_query_validation(Z_APDU *apdu);
101 Z_APDU *handle_query_transformation(Z_APDU *apdu);
102 Z_APDU *handle_target_charset_conversion(Z_APDU *apdu);
104 Z_APDU *handle_syntax_validation(Z_APDU *apdu);
106 void handle_charset_lang_negotiation(Z_APDU *apdu);
108 const char *load_balance(const char **url);
110 Yaz_ProxyConfig *check_reconfigure();
112 int m_invalid_session;
113 YAZ_Proxy_MARCXML_mode m_marcxml_mode;
114 void *m_stylesheet_xsp; // Really libxslt's xsltStylesheetPtr
115 int m_stylesheet_offset;
116 Z_APDU *m_stylesheet_apdu;
117 Z_NamePlusRecordList *m_stylesheet_nprl;
119 char *m_backend_type;
120 char *m_backend_charset;
122 void convert_to_frontend_type(Z_NamePlusRecordList *p);
123 void convert_to_marcxml(Z_NamePlusRecordList *p, const char *charset);
124 void convert_records_charset(Z_NamePlusRecordList *p, const char *charset);
125 int convert_xsl(Z_NamePlusRecordList *p, Z_APDU *apdu);
126 void convert_xsl_delay();
127 Z_APDU *m_initRequest_apdu;
128 int m_initRequest_preferredMessageSize;
129 int m_initRequest_maximumRecordSize;
130 Z_Options *m_initRequest_options;
131 Z_ProtocolVersion *m_initRequest_version;
132 char **m_initRequest_oi_negotiation_charsets;
133 int m_initRequest_oi_negotiation_num_charsets;
134 char **m_initRequest_oi_negotiation_langs;
135 int m_initRequest_oi_negotiation_num_langs;
136 int m_initRequest_oi_negotiation_selected;
137 NMEM m_initRequest_mem;
138 Z_APDU *m_apdu_invalid_session;
139 NMEM m_mem_invalid_session;
140 int send_PDU_convert(Z_APDU *apdu);
142 ODR m_s2z_odr_search;
145 char *m_s2z_database;
146 Z_APDU *m_s2z_init_apdu;
147 Z_APDU *m_s2z_search_apdu;
148 Z_APDU *m_s2z_present_apdu;
149 char *m_s2z_stylesheet;
151 int file_access(Z_HTTP_Request *hreq);
152 int send_to_srw_client_error(int error, const char *add);
153 int send_to_srw_client_ok(int hits, Z_Records *records, int start);
154 int send_http_response(int code);
155 int send_srw_response(Z_SRW_PDU *srw_pdu);
156 int send_srw_explain_response(Z_SRW_diagnostic *diagnostics,
157 int num_diagnostics);
158 int z_to_srw_diag(ODR o, Z_SRW_searchRetrieveResponse *srw_res,
159 Z_DefaultDiagFormat *ddf);
160 int m_http_keepalive;
161 const char *m_http_version;
162 Yaz_cql2rpn m_cql2rpn;
165 Z_ElementSetNames *mk_esn_from_schema(ODR o, const char *schema);
166 Z_ReferenceId *m_referenceId;
167 NMEM m_referenceId_mem;
168 #define NO_SPARE_SOLARIS_FD 10
169 int m_lo_fd[NO_SPARE_SOLARIS_FD];
170 void low_socket_open();
171 void low_socket_close();
172 char *m_usemarcon_ini_stage1;
173 char *m_usemarcon_ini_stage2;
174 Yaz_usemarcon *m_usemarcon;
175 Yaz_CharsetConverter *m_charset_converter;
177 Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable,
178 Yaz_Proxy *parent = 0);
180 void inc_request_no();
181 void recv_GDU(Z_GDU *apdu, int len);
182 void handle_incoming_HTTP(Z_HTTP_Request *req);
183 void handle_incoming_Z_PDU(Z_APDU *apdu);
184 IYaz_PDU_Observer* sessionNotify
185 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
187 void timeoutNotify();
188 void connectNotify();
190 const char *option(const char *name, const char *value);
191 void set_default_target(const char *target);
192 void set_proxy_negotiation (const char *charset, const char *lang);
193 void set_target_charset(const char *charset);
194 char *get_proxy_target() { return m_proxyTarget; };
195 char *get_session_str() { return m_session_str; };
196 void set_max_clients(int m) { m_max_clients = m; };
197 void set_client_idletime (int t) { m_client_idletime = (t > 1) ? t : 600; };
198 void set_target_idletime (int t) { m_target_idletime = (t > 1) ? t : 600; };
199 int get_target_idletime () { return m_target_idletime; }
200 int set_config(const char *name);
201 void reconfig() { m_reconfig_flag = 1; }
202 int send_to_client(Z_APDU *apdu);
203 int server(const char *addr);
205 int get_log_mask() { return m_log_mask; };
206 int handle_init_response_for_invalid_session(Z_APDU *apdu);
207 void set_debug_mode(int mode);