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