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