Added support for character set conversion of query terms. The XML
[yazproxy-moved-to-github.git] / src / proxyp.h
1 /* $Id: proxyp.h,v 1.4 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 #if HAVE_XSLT
23 #include <libxml/parser.h>
24 #include <libxml/tree.h>
25 #include <libxml/xinclude.h>
26 #include <libxslt/xsltutils.h>
27 #include <libxslt/transform.h>
28 #endif
29
30 #if HAVE_USEMARCON
31 #include <objectlist.h>
32 #endif
33
34 #include <yazproxy/proxy.h>
35 #include <yazproxy/module.h>
36
37 struct Yaz_RecordCache_Entry;
38
39 class Yaz_usemarcon {
40  public:
41     Yaz_usemarcon();
42     ~Yaz_usemarcon();
43
44     int convert(const char *stage1, const char *stage2,
45                 const char *input, int input_len,
46                 char **output, int *output_len);
47 #if HAVE_USEMARCON
48     CDetails *m_stage1;
49     CDetails *m_stage2;
50 #else
51     int dummy;
52 #endif
53 };
54
55 class Yaz_CharsetConverter {
56 public:
57     Yaz_CharsetConverter();
58     ~Yaz_CharsetConverter();
59     void set_target_query_charset(const char *s);
60     void set_client_query_charset(const char *org);
61     void convert_type_1(Z_RPNQuery *q, ODR o);
62 private:
63     void convert_type_1(char *buf_in, int len_in,
64                         char **buf_out, int *len_out,
65                         ODR o);
66     void convert_type_1(Z_Term *q, ODR o);
67     void convert_type_1(Z_RPNStructure *q, ODR o);
68     void convert_type_1(Z_Operand *q, ODR o);
69     char *m_target_query_charset;
70     char *m_client_query_charset;
71     yaz_iconv_t m_ct;
72     WRBUF m_wrbuf;
73 };
74
75 class Yaz_ProxyConfig {
76 public:
77     Yaz_ProxyConfig();
78     ~Yaz_ProxyConfig();
79     int read_xml(const char *fname);
80
81     int get_target_no(int no,
82                       const char **name,
83                       const char **url,
84                       int *limit_bw,
85                       int *limit_pdu,
86                       int *limit_req,
87                       int *target_idletime,
88                       int *client_idletime,
89                       int *max_clients,
90                       int *keepalive_limit_bw,
91                       int *keepalive_limit_pdu,
92                       int *pre_init,
93                       const char **cql2rpn,
94                       const char **authentication,
95                       const char **negotiation_charset,
96                       const char **negotiation_lang,
97                       const char **query_charset);
98     
99     void get_generic_info(int *log_mask, int *max_clients);
100
101     void get_target_info(const char *name, const char **url,
102                          int *limit_bw, int *limit_pdu, int *limit_req,
103                          int *target_idletime, int *client_idletime,
104                          int *max_clients,
105                          int *keepalive_limit_bw, int *keepalive_limit_pdu,
106                          int *pre_init,
107                          const char **cql2rpn,
108                          const char **negotiation_charset,
109                          const char **negotiation_lang,
110                          const char **query_charset);
111
112     const char *check_mime_type(const char *path);
113     int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo);
114     int check_syntax(ODR odr, const char *name,
115                      Odr_oid *syntax, Z_RecordComposition *comp,
116                      char **addinfo, char **stylesheet, char **schema,
117                      char **backend_type, char **backend_charset,
118                      char **usemarcon_ini_stage1, char **usemarcon_ini_stage2);
119
120     void target_authentication(const char *name,
121                                ODR odr,
122                                Z_InitRequest *req);
123
124     int client_authentication(const char *name,
125                               const char *user, const char *group,
126                               const char *password);
127     char *get_explain_doc(ODR odr, const char *name, const char *db,
128                           int *len);
129     const char *get_explain_name(const char *db, const char **backend_db);
130  private:
131     void operator=(const Yaz_ProxyConfig &conf);
132     class Yaz_ProxyConfigP *m_cp;
133 };
134
135 class Yaz_RecordCache {
136  public:
137     Yaz_RecordCache ();
138     ~Yaz_RecordCache ();
139     void add (ODR o, Z_NamePlusRecordList *npr, int start, int hits);
140     
141     int lookup (ODR o, Z_NamePlusRecordList **npr, int start, int num,
142                 Odr_oid *syntax, Z_RecordComposition *comp);
143     void clear();
144
145     void copy_searchRequest(Z_SearchRequest *sr);
146     void copy_presentRequest(Z_PresentRequest *pr);
147     void set_max_size(int sz);
148  private:
149     NMEM m_mem;
150     Yaz_RecordCache_Entry *m_entries;
151     Z_SearchRequest *m_searchRequest;
152     Z_PresentRequest *m_presentRequest;
153     int match (Yaz_RecordCache_Entry *entry,
154                Odr_oid *syntax, int offset,
155                Z_RecordComposition *comp);
156     int m_max_size;
157 };
158
159 class Yaz_ProxyClient : public Yaz_Z_Assoc {
160     friend class Yaz_Proxy;
161     Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable,
162                     Yaz_Proxy *parent);
163     ~Yaz_ProxyClient();
164     void recv_GDU(Z_GDU *apdu, int len);
165     void recv_Z_PDU(Z_APDU *apdu, int len);
166     void recv_HTTP_response(Z_HTTP_Response *apdu, int len);
167     IYaz_PDU_Observer* sessionNotify
168         (IYaz_PDU_Observable *the_PDU_Observable, int fd);
169     void shutdown();
170     Yaz_Proxy *m_server;
171     void failNotify();
172     void timeoutNotify();
173     void connectNotify();
174     int send_to_target(Z_APDU *apdu);
175     const char *get_session_str();
176     char *m_cookie;
177     Yaz_ProxyClient *m_next;
178     Yaz_ProxyClient **m_prev;
179     int m_init_flag;
180     Yaz_Z_Query *m_last_query;
181     Yaz_Z_Databases m_last_databases;
182     char *m_last_resultSetId;
183     int m_last_ok;
184     int m_last_resultCount;
185     int m_sr_transform;
186     int m_seqno;
187     int m_waiting;
188     int m_resultSetStartPoint;
189     int m_bytes_sent;
190     int m_bytes_recv;
191     int m_pdu_recv;
192     ODR m_init_odr;
193     Z_APDU *m_initResponse;
194     Z_Options *m_initResponse_options;
195     Z_ProtocolVersion *m_initResponse_version;
196     int m_initResponse_preferredMessageSize;
197     int m_initResponse_maximumRecordSize;
198     Yaz_RecordCache m_cache;
199     void pre_init_client();
200     int m_target_idletime;
201     Yaz_Proxy *m_root;
202 };
203