Option -X now makes it possible to stop YAZ proxy by sending
[yazproxy-moved-to-github.git] / src / proxyp.h
1 /* $Id: proxyp.h,v 1.3 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 #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_ProxyConfig {
56 public:
57     Yaz_ProxyConfig();
58     ~Yaz_ProxyConfig();
59     int read_xml(const char *fname);
60
61     int get_target_no(int no,
62                       const char **name,
63                       const char **url,
64                       int *limit_bw,
65                       int *limit_pdu,
66                       int *limit_req,
67                       int *target_idletime,
68                       int *client_idletime,
69                       int *max_clients,
70                       int *keepalive_limit_bw,
71                       int *keepalive_limit_pdu,
72                       int *pre_init,
73                       const char **cql2rpn,
74                       const char **authentication,
75                       const char **negotiation_charset,
76                       const char **negotiation_lang);
77     
78     void get_generic_info(int *log_mask, int *max_clients);
79
80     void get_target_info(const char *name, const char **url,
81                          int *limit_bw, int *limit_pdu, int *limit_req,
82                          int *target_idletime, int *client_idletime,
83                          int *max_clients,
84                          int *keepalive_limit_bw, int *keepalive_limit_pdu,
85                          int *pre_init,
86                          const char **cql2rpn,
87                          const char **negotiation_charset,
88                          const char **negotiation_lang);
89
90     const char *check_mime_type(const char *path);
91     int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo);
92     int check_syntax(ODR odr, const char *name,
93                      Odr_oid *syntax, Z_RecordComposition *comp,
94                      char **addinfo, char **stylesheet, char **schema,
95                      char **backend_type, char **backend_charset,
96                      char **usemarcon_ini_stage1, char **usemarcon_ini_stage2);
97
98     void target_authentication(const char *name,
99                                ODR odr,
100                                Z_InitRequest *req);
101
102     int client_authentication(const char *name,
103                               const char *user, const char *group,
104                               const char *password);
105     char *get_explain_doc(ODR odr, const char *name, const char *db,
106                           int *len);
107     const char *get_explain_name(const char *db, const char **backend_db);
108  private:
109     void operator=(const Yaz_ProxyConfig &conf);
110     class Yaz_ProxyConfigP *m_cp;
111 };
112
113 class Yaz_RecordCache {
114  public:
115     Yaz_RecordCache ();
116     ~Yaz_RecordCache ();
117     void add (ODR o, Z_NamePlusRecordList *npr, int start, int hits);
118     
119     int lookup (ODR o, Z_NamePlusRecordList **npr, int start, int num,
120                 Odr_oid *syntax, Z_RecordComposition *comp);
121     void clear();
122
123     void copy_searchRequest(Z_SearchRequest *sr);
124     void copy_presentRequest(Z_PresentRequest *pr);
125     void set_max_size(int sz);
126  private:
127     NMEM m_mem;
128     Yaz_RecordCache_Entry *m_entries;
129     Z_SearchRequest *m_searchRequest;
130     Z_PresentRequest *m_presentRequest;
131     int match (Yaz_RecordCache_Entry *entry,
132                Odr_oid *syntax, int offset,
133                Z_RecordComposition *comp);
134     int m_max_size;
135 };
136
137 class Yaz_ProxyClient : public Yaz_Z_Assoc {
138     friend class Yaz_Proxy;
139     Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable,
140                     Yaz_Proxy *parent);
141     ~Yaz_ProxyClient();
142     void recv_GDU(Z_GDU *apdu, int len);
143     void recv_Z_PDU(Z_APDU *apdu, int len);
144     void recv_HTTP_response(Z_HTTP_Response *apdu, int len);
145     IYaz_PDU_Observer* sessionNotify
146         (IYaz_PDU_Observable *the_PDU_Observable, int fd);
147     void shutdown();
148     Yaz_Proxy *m_server;
149     void failNotify();
150     void timeoutNotify();
151     void connectNotify();
152     int send_to_target(Z_APDU *apdu);
153     const char *get_session_str();
154     char *m_cookie;
155     Yaz_ProxyClient *m_next;
156     Yaz_ProxyClient **m_prev;
157     int m_init_flag;
158     Yaz_Z_Query *m_last_query;
159     Yaz_Z_Databases m_last_databases;
160     char *m_last_resultSetId;
161     int m_last_ok;
162     int m_last_resultCount;
163     int m_sr_transform;
164     int m_seqno;
165     int m_waiting;
166     int m_resultSetStartPoint;
167     int m_bytes_sent;
168     int m_bytes_recv;
169     int m_pdu_recv;
170     ODR m_init_odr;
171     Z_APDU *m_initResponse;
172     Z_Options *m_initResponse_options;
173     Z_ProtocolVersion *m_initResponse_version;
174     int m_initResponse_preferredMessageSize;
175     int m_initResponse_maximumRecordSize;
176     Yaz_RecordCache m_cache;
177     void pre_init_client();
178     int m_target_idletime;
179     Yaz_Proxy *m_root;
180 };
181