Pass-through x-username and omitted password to Z39.50 target.
[yazproxy-moved-to-github.git] / src / proxyp.h
1 /* This file is part of YAZ proxy
2    Copyright (C) 1998-2009 Index Data
3
4 YAZ proxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19 #if YAZ_HAVE_XSLT
20 #include <libxml/parser.h>
21 #include <libxml/tree.h>
22 #include <libxml/xinclude.h>
23 #include <libxslt/xsltutils.h>
24 #include <libxslt/transform.h>
25 #endif
26
27 #if HAVE_USEMARCON
28 #include <usemarconlib.h>
29 #endif
30
31 #include <yazpp/record-cache.h>
32 #include <yazproxy/proxy.h>
33 #include <yazproxy/module.h>
34
35 struct Yaz_RecordCache_Entry;
36
37 class Yaz_usemarcon {
38  public:
39     Yaz_usemarcon();
40     ~Yaz_usemarcon();
41
42     int convert(const char *stage1, const char *stage2,
43                 const char *input, int input_len,
44                 char **output, int *output_len);
45 #if HAVE_USEMARCON
46     Usemarcon *m_stage1;
47     Usemarcon *m_stage2;
48 #else
49     int dummy;
50 #endif
51 };
52
53 class Yaz_CharsetConverter {
54 public:
55     Yaz_CharsetConverter();
56     ~Yaz_CharsetConverter();
57     void set_target_query_charset(const char *s);
58     void set_client_query_charset(const char *org);
59     const char *get_client_query_charset(void);
60     const char *get_target_query_charset(void);
61     void convert_type_1(Z_RPNQuery *q, ODR o);
62     void set_client_charset_selected(int sel);
63     int get_client_charset_selected();
64 private:
65     void convert_type_1(char *buf_in, int len_in,
66                         char **buf_out, int *len_out,
67                         ODR o);
68     void convert_type_1(Z_Term *q, ODR o);
69     void convert_type_1(Z_RPNStructure *q, ODR o);
70     void convert_type_1(Z_Operand *q, ODR o);
71     char *m_target_query_charset;
72     char *m_client_query_charset;
73     int m_client_charset_selected;
74     yaz_iconv_t m_ct;
75     WRBUF m_wrbuf;
76 };
77
78 class Yaz_ProxyConfig {
79 public:
80     Yaz_ProxyConfig();
81     ~Yaz_ProxyConfig();
82     int read_xml(const char *fname);
83
84     int get_target_no(int no,
85                       const char **name,
86                       const char **url,
87                       int *limit_bw,
88                       int *limit_pdu,
89                       int *limit_req,
90                       int *limit_search,
91                       int *target_idletime,
92                       int *client_idletime,
93                       int *max_sockets,
94                       int *max_clients,
95                       int *keepalive_limit_bw,
96                       int *keepalive_limit_pdu,
97                       int *pre_init,
98                       const char **cql2rpn,
99                       const char **authentication,
100                       const char **negotiation_charset,
101                       const char **negotiation_lang,
102                       const char **query_charset,
103                       const char **default_client_query_charset);
104
105     void get_generic_info(int *log_mask, int *max_clients,
106                           int *max_connect, int *limit_connect,
107                           int *period_connect,
108                           int *msg_threads);
109
110     int get_file_access_info(const char *path);
111
112     void get_target_info(const char *name, const char **url,
113                          int *limit_bw, int *limit_pdu, int *limit_req,
114                          int *limit_search,
115                          int *target_idletime, int *client_idletime,
116                          int *max_sockets,
117                          int *max_clients,
118                          int *keepalive_limit_bw, int *keepalive_limit_pdu,
119                          int *pre_init,
120                          const char **cql2rpn,
121                          const char **negotiation_charset,
122                          const char **negotiation_lang,
123                          const char **query_charset,
124                          const char **default_client_query_charset);
125
126     const char *check_mime_type(const char *path);
127     int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo);
128     int check_syntax(ODR odr, const char *name,
129                      Odr_oid *syntax, Z_RecordComposition *comp,
130                      char **addinfo, char **stylesheet, char **schema,
131                      char **backend_type, char **backend_charset,
132                      char **usemarcon_ini_stage1, char **usemarcon_ini_stage2);
133
134     void target_authentication(const char *name,
135                                ODR odr,
136                                Z_InitRequest *req);
137
138     int client_authentication(const char *name,
139                               const char *user, const char *group,
140                               const char *password,
141                               const char *peer_IP);
142     int global_client_authentication(const char *user, const char *group,
143                                      const char *password,
144                                      const char *peer_IP);
145     char *get_explain_doc(ODR odr, const char *name, const char *db,
146                           int *len, int *http_status);
147     const char *get_explain_name(const char *db, const char **backend_db);
148  private:
149     void operator=(const Yaz_ProxyConfig &conf);
150     class Yaz_ProxyConfigP *m_cp;
151 };
152
153 class Yaz_ProxyClient : public yazpp_1::Z_Assoc {
154     friend class Yaz_Proxy;
155     Yaz_ProxyClient(yazpp_1::IPDU_Observable *the_PDU_Observable,
156                     Yaz_Proxy *parent);
157     ~Yaz_ProxyClient();
158     void recv_GDU(Z_GDU *apdu, int len);
159     void recv_Z_PDU(Z_APDU *apdu, int len);
160     void recv_HTTP_response(Z_HTTP_Response *apdu, int len);
161     IPDU_Observer* sessionNotify
162         (yazpp_1::IPDU_Observable *the_PDU_Observable, int fd);
163     void shutdown();
164     Yaz_Proxy *m_server;
165     void failNotify();
166     void timeoutNotify();
167     void connectNotify();
168     int send_to_target(Z_APDU *apdu);
169     const char *get_session_str();
170     char *m_cookie;
171     Yaz_ProxyClient *m_next;
172     Yaz_ProxyClient **m_prev;
173     int m_init_flag;
174     yazpp_1::Yaz_Z_Query *m_last_query;
175     yazpp_1::Yaz_Z_Databases m_last_databases;
176     char *m_last_resultSetId;
177     int m_last_ok;
178     int m_last_resultCount;
179     int m_sr_transform;
180     int m_seqno;
181     int m_waiting;
182     int m_resultSetStartPoint;
183     int m_bytes_sent;
184     int m_bytes_recv;
185     int m_pdu_recv;
186     ODR m_init_odr;
187     Z_APDU *m_initResponse;
188     Z_Options *m_initResponse_options;
189     Z_ProtocolVersion *m_initResponse_version;
190     int m_initResponse_preferredMessageSize;
191     int m_initResponse_maximumRecordSize;
192     yazpp_1::RecordCache m_cache;
193     void pre_init_client();
194     int m_target_idletime;
195     Yaz_Proxy *m_root;
196     char *m_idAuthentication_ber_buf;
197     int m_idAuthentication_ber_size;
198     ODR m_idAuthentication_odr;
199     void set_idAuthentication(Z_APDU *apdu);
200     bool compare_idAuthentication(Z_APDU *apdu);
201     bool compare_charset(Z_APDU *apdu);
202 };
203
204 /*
205  * Local variables:
206  * c-basic-offset: 4
207  * c-file-style: "Stroustrup"
208  * indent-tabs-mode: nil
209  * End:
210  * vim: shiftwidth=4 tabstop=8 expandtab
211  */
212