Added support for character set conversion of query terms. The XML
[yazproxy-moved-to-github.git] / include / yazproxy / proxy.h
1 /* $Id: proxy.h,v 1.15 2005-05-04 08:31:44 adam Exp $
2    Copyright (c) 1998-2005, Index Data.
3
4 This file is part of the yaz-proxy.
5
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
9 version.
10
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
14 for more details.
15
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
19 02111-1307, USA.
20  */
21
22 #ifndef YAZ_PROXY_H_INCLUDED
23 #define YAZ_PROXY_H_INCLUDED
24
25 #include <yaz++/z-assoc.h>
26 #include <yaz++/z-query.h>
27 #include <yaz++/z-databases.h>
28 #include <yaz++/cql2rpn.h>
29 #include <yaz/cql.h>
30 #include <yazproxy/bw.h>
31
32 class Yaz_Proxy;
33
34 #define MAX_ZURL_PLEX 10
35
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
40
41 class Yaz_usemarcon;
42 class Yaz_ProxyConfig;
43 class Yaz_ProxyClient;
44 class Yaz_CharsetConverter;
45
46 enum YAZ_Proxy_MARCXML_mode {
47     none,
48     marcxml,
49 };
50
51 /// Information Retrieval Proxy Server.
52 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
53  private:
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);
62     void shutdown();
63     void releaseClient();    
64     Yaz_ProxyClient *m_client;
65     IYaz_PDU_Observable *m_PDU_Observable;
66     Yaz_ProxyClient *m_clientPool;
67     Yaz_Proxy *m_parent;
68     int m_seqno;
69     int m_max_clients;
70     int m_log_mask;
71     int m_keepalive_limit_bw;
72     int m_keepalive_limit_pdu;
73     int m_client_idletime;
74     int m_target_idletime;
75     int m_debug_mode;
76     char *m_proxyTarget;
77     char *m_default_target;
78     char *m_proxy_negotiation_charset;
79     char *m_proxy_negotiation_lang;
80     long m_seed;
81     char *m_optimize;
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;
85     char *m_config_fname;
86     int m_bytes_sent;
87     int m_bytes_recv;
88     int m_bw_max;
89     Yaz_bw m_bw_stat;
90     int m_pdu_max;
91     Yaz_bw m_pdu_stat;
92     Z_GDU *m_bw_hold_PDU;
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,
98                                               const char *addinfo);
99
100     Z_APDU *handle_query_validation(Z_APDU *apdu);
101     Z_APDU *handle_query_transformation(Z_APDU *apdu);
102     Z_APDU *handle_query_charset_conversion(Z_APDU *apdu);
103
104     Z_APDU *handle_syntax_validation(Z_APDU *apdu);
105
106     void handle_charset_lang_negotiation(Z_APDU *apdu);
107
108     const char *load_balance(const char **url);
109     int m_reconfig_flag;
110     Yaz_ProxyConfig *check_reconfigure();
111     int m_request_no;
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;
118     char *m_schema;
119     char *m_backend_type;
120     char *m_backend_charset;
121     int m_frontend_type;
122     void convert_to_frontend_type(Z_NamePlusRecordList *p);
123     void convert_to_marcxml(Z_NamePlusRecordList *p, const char *charset);
124     int convert_xsl(Z_NamePlusRecordList *p, Z_APDU *apdu);
125     void convert_xsl_delay();
126     Z_APDU *m_initRequest_apdu;
127     int m_initRequest_preferredMessageSize;
128     int m_initRequest_maximumRecordSize;
129     Z_Options *m_initRequest_options;
130     Z_ProtocolVersion *m_initRequest_version;
131     char **m_initRequest_oi_negotiation_charsets;
132     int m_initRequest_oi_negotiation_num_charsets;
133     char **m_initRequest_oi_negotiation_langs;
134     int m_initRequest_oi_negotiation_num_langs;
135     int m_initRequest_oi_negotiation_selected;
136     NMEM m_initRequest_mem;
137     Z_APDU *m_apdu_invalid_session;
138     NMEM m_mem_invalid_session;
139     int send_PDU_convert(Z_APDU *apdu);
140     ODR m_s2z_odr_init;
141     ODR m_s2z_odr_search;
142     int m_s2z_hit_count;
143     int m_s2z_packing;
144     char *m_s2z_database;
145     Z_APDU *m_s2z_init_apdu;
146     Z_APDU *m_s2z_search_apdu;
147     Z_APDU *m_s2z_present_apdu;
148     char *m_s2z_stylesheet;
149     char *m_soap_ns;
150     int file_access(Z_HTTP_Request *hreq);
151     int send_to_srw_client_error(int error, const char *add);
152     int send_to_srw_client_ok(int hits, Z_Records *records, int start);
153     int send_http_response(int code);
154     int send_srw_response(Z_SRW_PDU *srw_pdu);
155     int send_srw_explain_response(Z_SRW_diagnostic *diagnostics,
156                                   int num_diagnostics);
157     int z_to_srw_diag(ODR o, Z_SRW_searchRetrieveResponse *srw_res,
158                       Z_DefaultDiagFormat *ddf);
159     int m_http_keepalive;
160     const char *m_http_version;
161     Yaz_cql2rpn m_cql2rpn;
162     void *m_time_tv;
163     void logtime();
164     Z_ElementSetNames *mk_esn_from_schema(ODR o, const char *schema);
165     Z_ReferenceId *m_referenceId;
166     NMEM m_referenceId_mem;
167 #define NO_SPARE_SOLARIS_FD 10
168     int m_lo_fd[NO_SPARE_SOLARIS_FD];
169     void low_socket_open();
170     void low_socket_close();
171     char *m_usemarcon_ini_stage1;
172     char *m_usemarcon_ini_stage2;
173     Yaz_usemarcon *m_usemarcon;
174     Yaz_CharsetConverter *m_charset_converter;
175  public:
176     Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable,
177               Yaz_Proxy *parent = 0);
178     ~Yaz_Proxy();
179     void inc_request_no();
180     void recv_GDU(Z_GDU *apdu, int len);
181     void handle_incoming_HTTP(Z_HTTP_Request *req);
182     void handle_incoming_Z_PDU(Z_APDU *apdu);
183     IYaz_PDU_Observer* sessionNotify
184         (IYaz_PDU_Observable *the_PDU_Observable, int fd);
185     void failNotify();
186     void timeoutNotify();
187     void connectNotify();
188     void markInvalid();
189     const char *option(const char *name, const char *value);
190     void set_default_target(const char *target);
191     void set_proxy_negotiation (const char *charset, const char *lang);
192     void set_query_charset(const char *charset);
193     char *get_proxy_target() { return m_proxyTarget; };
194     char *get_session_str() { return m_session_str; };
195     void set_max_clients(int m) { m_max_clients = m; };
196     void set_client_idletime (int t) { m_client_idletime = (t > 1) ? t : 600; };
197     void set_target_idletime (int t) { m_target_idletime = (t > 1) ? t : 600; };
198     int get_target_idletime () { return m_target_idletime; }
199     int set_config(const char *name);
200     void reconfig() { m_reconfig_flag = 1; }
201     int send_to_client(Z_APDU *apdu);
202     int server(const char *addr);
203     void pre_init();
204     int get_log_mask() { return m_log_mask; };
205     int handle_init_response_for_invalid_session(Z_APDU *apdu);
206     void set_debug_mode(int mode);
207 };
208
209 #endif