Added Support OPAC to XML conversion. Triggered by backendtype="opac"
[yazproxy-moved-to-github.git] / include / yazproxy / proxy.h
1 /* $Id: proxy.h,v 1.14 2005-02-22 10:08:19 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
45 enum YAZ_Proxy_MARCXML_mode {
46     none,
47     marcxml,
48 };
49
50 /// Information Retrieval Proxy Server.
51 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
52  private:
53     char *get_cookie(Z_OtherInformation **otherInfo);
54     char *get_proxy(Z_OtherInformation **otherInfo);
55     void get_charset_and_lang_negotiation(Z_OtherInformation **otherInfo,
56         char **charstes, char **langs, int *selected);
57     Yaz_ProxyClient *get_client(Z_APDU *apdu, const char *cookie,
58                                 const char *proxy_host);
59     void srw_get_client(const char *db, const char **backend_db);
60     Z_APDU *result_set_optimize(Z_APDU *apdu);
61     void shutdown();
62     void releaseClient();    
63     Yaz_ProxyClient *m_client;
64     IYaz_PDU_Observable *m_PDU_Observable;
65     Yaz_ProxyClient *m_clientPool;
66     Yaz_Proxy *m_parent;
67     int m_seqno;
68     int m_max_clients;
69     int m_log_mask;
70     int m_keepalive_limit_bw;
71     int m_keepalive_limit_pdu;
72     int m_client_idletime;
73     int m_target_idletime;
74     int m_debug_mode;
75     char *m_proxyTarget;
76     char *m_default_target;
77     char *m_proxy_negotiation_charset;
78     char *m_proxy_negotiation_lang;
79     long m_seed;
80     char *m_optimize;
81     int m_session_no;         // sequence for each client session
82     char m_session_str[30];  // session string (time:session_no)
83     Yaz_ProxyConfig *m_config;
84     char *m_config_fname;
85     int m_bytes_sent;
86     int m_bytes_recv;
87     int m_bw_max;
88     Yaz_bw m_bw_stat;
89     int m_pdu_max;
90     Yaz_bw m_pdu_stat;
91     Z_GDU *m_bw_hold_PDU;
92     int m_max_record_retrieve;
93     void handle_max_record_retrieve(Z_APDU *apdu);
94     int handle_authentication(Z_APDU *apdu);
95     void display_diagrecs(Z_DiagRec **pp, int num);
96     Z_Records *create_nonSurrogateDiagnostics(ODR o, int error,
97                                               const char *addinfo);
98
99     Z_APDU *handle_query_validation(Z_APDU *apdu);
100     Z_APDU *handle_query_transformation(Z_APDU *apdu);
101
102     Z_APDU *handle_syntax_validation(Z_APDU *apdu);
103
104     void handle_charset_lang_negotiation(Z_APDU *apdu);
105
106     const char *load_balance(const char **url);
107     int m_reconfig_flag;
108     Yaz_ProxyConfig *check_reconfigure();
109     int m_request_no;
110     int m_invalid_session;
111     YAZ_Proxy_MARCXML_mode m_marcxml_mode;
112     void *m_stylesheet_xsp;  // Really libxslt's xsltStylesheetPtr 
113     int m_stylesheet_offset;
114     Z_APDU *m_stylesheet_apdu;
115     Z_NamePlusRecordList *m_stylesheet_nprl;
116     char *m_schema;
117     char *m_backend_type;
118     char *m_backend_charset;
119     int m_frontend_type;
120     void convert_to_frontend_type(Z_NamePlusRecordList *p);
121     void convert_to_marcxml(Z_NamePlusRecordList *p, const char *charset);
122     int convert_xsl(Z_NamePlusRecordList *p, Z_APDU *apdu);
123     void convert_xsl_delay();
124     Z_APDU *m_initRequest_apdu;
125     int m_initRequest_preferredMessageSize;
126     int m_initRequest_maximumRecordSize;
127     Z_Options *m_initRequest_options;
128     Z_ProtocolVersion *m_initRequest_version;
129     char **m_initRequest_oi_negotiation_charsets;
130     int m_initRequest_oi_negotiation_num_charsets;
131     char **m_initRequest_oi_negotiation_langs;
132     int m_initRequest_oi_negotiation_num_langs;
133     int m_initRequest_oi_negotiation_selected;
134     NMEM m_initRequest_mem;
135     Z_APDU *m_apdu_invalid_session;
136     NMEM m_mem_invalid_session;
137     int send_PDU_convert(Z_APDU *apdu);
138     ODR m_s2z_odr_init;
139     ODR m_s2z_odr_search;
140     int m_s2z_hit_count;
141     int m_s2z_packing;
142     char *m_s2z_database;
143     Z_APDU *m_s2z_init_apdu;
144     Z_APDU *m_s2z_search_apdu;
145     Z_APDU *m_s2z_present_apdu;
146     char *m_s2z_stylesheet;
147     char *m_soap_ns;
148     int file_access(Z_HTTP_Request *hreq);
149     int send_to_srw_client_error(int error, const char *add);
150     int send_to_srw_client_ok(int hits, Z_Records *records, int start);
151     int send_http_response(int code);
152     int send_srw_response(Z_SRW_PDU *srw_pdu);
153     int send_srw_explain_response(Z_SRW_diagnostic *diagnostics,
154                                   int num_diagnostics);
155     int z_to_srw_diag(ODR o, Z_SRW_searchRetrieveResponse *srw_res,
156                       Z_DefaultDiagFormat *ddf);
157     int m_http_keepalive;
158     const char *m_http_version;
159     Yaz_cql2rpn m_cql2rpn;
160     void *m_time_tv;
161     void logtime();
162     Z_ElementSetNames *mk_esn_from_schema(ODR o, const char *schema);
163     Z_ReferenceId *m_referenceId;
164     NMEM m_referenceId_mem;
165 #define NO_SPARE_SOLARIS_FD 10
166     int m_lo_fd[NO_SPARE_SOLARIS_FD];
167     void low_socket_open();
168     void low_socket_close();
169     char *m_usemarcon_ini_stage1;
170     char *m_usemarcon_ini_stage2;
171     Yaz_usemarcon *m_usemarcon;
172  public:
173     Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable,
174               Yaz_Proxy *parent = 0);
175     ~Yaz_Proxy();
176     void inc_request_no();
177     void recv_GDU(Z_GDU *apdu, int len);
178     void handle_incoming_HTTP(Z_HTTP_Request *req);
179     void handle_incoming_Z_PDU(Z_APDU *apdu);
180     IYaz_PDU_Observer* sessionNotify
181         (IYaz_PDU_Observable *the_PDU_Observable, int fd);
182     void failNotify();
183     void timeoutNotify();
184     void connectNotify();
185     void markInvalid();
186     const char *option(const char *name, const char *value);
187     void set_default_target(const char *target);
188     void set_proxy_negotiation (const char *charset, const char *lang);
189     char *get_proxy_target() { return m_proxyTarget; };
190     char *get_session_str() { return m_session_str; };
191     void set_max_clients(int m) { m_max_clients = m; };
192     void set_client_idletime (int t) { m_client_idletime = (t > 1) ? t : 600; };
193     void set_target_idletime (int t) { m_target_idletime = (t > 1) ? t : 600; };
194     int get_target_idletime () { return m_target_idletime; }
195     int set_config(const char *name);
196     void reconfig() { m_reconfig_flag = 1; }
197     int send_to_client(Z_APDU *apdu);
198     int server(const char *addr);
199     void pre_init();
200     int get_log_mask() { return m_log_mask; };
201     int handle_init_response_for_invalid_session(Z_APDU *apdu);
202     void set_debug_mode(int mode);
203 };
204
205 #endif