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