Reuse sessions with same idAuthentication information.
[yazproxy-moved-to-github.git] / src / proxyp.h
1 /* $Id: proxyp.h,v 1.11 2006-03-09 14:12:57 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 <yaz++/record-cache.h>
35 #include <yazproxy/proxy.h>
36 #include <yazproxy/module.h>
37
38 struct Yaz_RecordCache_Entry;
39
40 class Yaz_usemarcon {
41  public:
42     Yaz_usemarcon();
43     ~Yaz_usemarcon();
44
45     int convert(const char *stage1, const char *stage2,
46                 const char *input, int input_len,
47                 char **output, int *output_len);
48 #if HAVE_USEMARCON
49     CDetails *m_stage1;
50     CDetails *m_stage2;
51 #else
52     int dummy;
53 #endif
54 };
55
56 class Yaz_CharsetConverter {
57 public:
58     Yaz_CharsetConverter();
59     ~Yaz_CharsetConverter();
60     void set_target_query_charset(const char *s);
61     void set_client_query_charset(const char *org);
62     const char *get_client_query_charset(void);
63     const char *get_target_query_charset(void);
64     void convert_type_1(Z_RPNQuery *q, ODR o);
65     void set_client_charset_selected(int sel);
66     int get_client_charset_selected();
67 private:
68     void convert_type_1(char *buf_in, int len_in,
69                         char **buf_out, int *len_out,
70                         ODR o);
71     void convert_type_1(Z_Term *q, ODR o);
72     void convert_type_1(Z_RPNStructure *q, ODR o);
73     void convert_type_1(Z_Operand *q, ODR o);
74     char *m_target_query_charset;
75     char *m_client_query_charset;
76     int m_client_charset_selected;
77     yaz_iconv_t m_ct;
78     WRBUF m_wrbuf;
79 };
80
81 class Yaz_ProxyConfig {
82 public:
83     Yaz_ProxyConfig();
84     ~Yaz_ProxyConfig();
85     int read_xml(const char *fname);
86
87     int get_target_no(int no,
88                       const char **name,
89                       const char **url,
90                       int *limit_bw,
91                       int *limit_pdu,
92                       int *limit_req,
93                       int *limit_search,
94                       int *limit_connect,
95                       int *target_idletime,
96                       int *client_idletime,
97                       int *max_clients,
98                       int *keepalive_limit_bw,
99                       int *keepalive_limit_pdu,
100                       int *pre_init,
101                       const char **cql2rpn,
102                       const char **authentication,
103                       const char **negotiation_charset,
104                       const char **negotiation_lang,
105                       const char **query_charset);
106     
107     void get_generic_info(int *log_mask, int *max_clients);
108
109     void get_target_info(const char *name, const char **url,
110                          int *limit_bw, int *limit_pdu, int *limit_req,
111                          int *limit_search, int *limit_connect,
112                          int *target_idletime, int *client_idletime,
113                          int *max_clients,
114                          int *keepalive_limit_bw, int *keepalive_limit_pdu,
115                          int *pre_init,
116                          const char **cql2rpn,
117                          const char **negotiation_charset,
118                          const char **negotiation_lang,
119                          const char **query_charset);
120
121     const char *check_mime_type(const char *path);
122     int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo);
123     int check_syntax(ODR odr, const char *name,
124                      Odr_oid *syntax, Z_RecordComposition *comp,
125                      char **addinfo, char **stylesheet, char **schema,
126                      char **backend_type, char **backend_charset,
127                      char **usemarcon_ini_stage1, char **usemarcon_ini_stage2);
128
129     void target_authentication(const char *name,
130                                ODR odr,
131                                Z_InitRequest *req);
132
133     int client_authentication(const char *name,
134                               const char *user, const char *group,
135                               const char *password,
136                               const char *peer_IP);
137     char *get_explain_doc(ODR odr, const char *name, const char *db,
138                           int *len);
139     const char *get_explain_name(const char *db, const char **backend_db);
140  private:
141     void operator=(const Yaz_ProxyConfig &conf);
142     class Yaz_ProxyConfigP *m_cp;
143 };
144
145 class Yaz_ProxyClient : public yazpp_1::Z_Assoc {
146     friend class Yaz_Proxy;
147     Yaz_ProxyClient(yazpp_1::IPDU_Observable *the_PDU_Observable,
148                     Yaz_Proxy *parent);
149     ~Yaz_ProxyClient();
150     void recv_GDU(Z_GDU *apdu, int len);
151     void recv_Z_PDU(Z_APDU *apdu, int len);
152     void recv_HTTP_response(Z_HTTP_Response *apdu, int len);
153     IPDU_Observer* sessionNotify
154         (yazpp_1::IPDU_Observable *the_PDU_Observable, int fd);
155     void shutdown();
156     Yaz_Proxy *m_server;
157     void failNotify();
158     void timeoutNotify();
159     void connectNotify();
160     int send_to_target(Z_APDU *apdu);
161     const char *get_session_str();
162     char *m_cookie;
163     Yaz_ProxyClient *m_next;
164     Yaz_ProxyClient **m_prev;
165     int m_init_flag;
166     yazpp_1::Yaz_Z_Query *m_last_query;
167     yazpp_1::Yaz_Z_Databases m_last_databases;
168     char *m_last_resultSetId;
169     int m_last_ok;
170     int m_last_resultCount;
171     int m_sr_transform;
172     int m_seqno;
173     int m_waiting;
174     int m_resultSetStartPoint;
175     int m_bytes_sent;
176     int m_bytes_recv;
177     int m_pdu_recv;
178     ODR m_init_odr;
179     Z_APDU *m_initResponse;
180     Z_Options *m_initResponse_options;
181     Z_ProtocolVersion *m_initResponse_version;
182     int m_initResponse_preferredMessageSize;
183     int m_initResponse_maximumRecordSize;
184     yazpp_1::RecordCache m_cache;
185     void pre_init_client();
186     int m_target_idletime;
187     Yaz_Proxy *m_root;
188     char *m_idAuthentication_ber_buf;
189     int m_idAuthentication_ber_size;
190     ODR m_idAuthentication_odr;
191     void set_idAuthentication(Z_APDU *apdu);
192     bool compare_idAuthentication(Z_APDU *apdu);
193 };
194
195 /*
196  * Local variables:
197  * c-basic-offset: 4
198  * indent-tabs-mode: nil
199  * End:
200  * vim: shiftwidth=4 tabstop=8 expandtab
201  */
202