2 * Copyright (c) 1998-2003, Index Data.
3 * See the file LICENSE for details.
5 * $Id: proxy.h,v 1.19 2003-10-16 16:10:43 adam Exp $
8 #include <yaz++/z-assoc.h>
9 #include <yaz++/z-query.h>
10 #include <yaz++/z-databases.h>
13 #include <libxml/parser.h>
14 #include <libxml/tree.h>
19 #define MAX_ZURL_PLEX 10
21 #define PROXY_LOG_APDU_CLIENT 1
22 #define PROXY_LOG_APDU_SERVER 2
23 #define PROXY_LOG_REQ_CLIENT 4
24 #define PROXY_LOG_REQ_SERVER 8
26 struct Yaz_RecordCache_Entry;
28 class YAZ_EXPORT Yaz_ProxyConfig {
32 int read_xml(const char *fname);
34 int get_target_no(int no,
43 int *keepalive_limit_bw,
44 int *keepalive_limit_pdu,
47 void get_generic_info(int *log_mask, int *max_clients);
49 void get_target_info(const char *name, const char **url,
50 int *limit_bw, int *limit_pdu, int *limit_req,
51 int *target_idletime, int *client_idletime,
53 int *keepalive_limit_bw, int *keepalive_limit_pdu,
56 int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo);
57 int check_syntax(ODR odr, const char *name,
58 Odr_oid *syntax, char **addinfo);
60 void operator=(const Yaz_ProxyConfig &conf);
62 int mycmp(const char *hay, const char *item, int len);
64 xmlNodePtr m_proxyPtr;
65 void return_target_info(xmlNodePtr ptr, const char **url,
66 int *limit_bw, int *limit_pdu, int *limit_req,
67 int *target_idletime, int *client_idletime,
68 int *keepalive_limit_bw, int *keepalive_limit_pdu,
70 void return_limit(xmlNodePtr ptr,
71 int *limit_bw, int *limit_pdu, int *limit_req);
72 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
74 xmlNodePtr find_target_node(const char *name);
75 const char *get_text(xmlNodePtr ptr);
76 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
77 Z_AttributeList *attrs,
79 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
83 int match_list(int v, const char *m);
84 int atoi_l(const char **cp);
88 class YAZ_EXPORT Yaz_RecordCache {
92 void add (ODR o, Z_NamePlusRecordList *npr, int start, int hits);
94 int lookup (ODR o, Z_NamePlusRecordList **npr, int start, int num,
95 Odr_oid *syntax, Z_RecordComposition *comp);
98 void copy_searchRequest(Z_SearchRequest *sr);
99 void copy_presentRequest(Z_PresentRequest *pr);
100 void set_max_size(int sz);
103 Yaz_RecordCache_Entry *m_entries;
104 Z_SearchRequest *m_searchRequest;
105 Z_PresentRequest *m_presentRequest;
106 int match (Yaz_RecordCache_Entry *entry,
107 Odr_oid *syntax, int offset,
108 Z_RecordComposition *comp);
112 class YAZ_EXPORT Yaz_bw {
116 void add_bytes(int m);
119 long m_sec; // time of most recent bucket
126 class YAZ_EXPORT Yaz_ProxyClient : public Yaz_Z_Assoc {
127 friend class Yaz_Proxy;
128 Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable,
131 void recv_Z_PDU(Z_APDU *apdu, int len);
132 IYaz_PDU_Observer* sessionNotify
133 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
137 void timeoutNotify();
138 void connectNotify();
139 int send_to_target(Z_APDU *apdu);
140 const char *get_session_str();
142 Yaz_ProxyClient *m_next;
143 Yaz_ProxyClient **m_prev;
145 Yaz_Z_Query *m_last_query;
146 Yaz_Z_Databases m_last_databases;
147 char *m_last_resultSetId;
149 int m_last_resultCount;
153 int m_resultSetStartPoint;
158 Z_APDU *m_initResponse;
159 Yaz_RecordCache m_cache;
160 void pre_init_client();
161 int m_target_idletime;
165 /// Information Retrieval Proxy Server.
166 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
168 char *get_cookie(Z_OtherInformation **otherInfo);
169 char *get_proxy(Z_OtherInformation **otherInfo);
170 Yaz_ProxyClient *get_client(Z_APDU *apdu);
171 Z_APDU *result_set_optimize(Z_APDU *apdu);
174 Yaz_ProxyClient *m_client;
175 IYaz_PDU_Observable *m_PDU_Observable;
176 Yaz_ProxyClient *m_clientPool;
181 int m_keepalive_limit_bw;
182 int m_keepalive_limit_pdu;
183 int m_client_idletime;
184 int m_target_idletime;
186 char *m_default_target;
187 char *m_proxy_authentication;
190 int m_session_no; // sequence for each client session
191 char m_session_str[30]; // session string (time:session_no)
192 Yaz_ProxyConfig *m_config;
193 char *m_config_fname;
200 Z_APDU *m_bw_hold_PDU;
201 int m_max_record_retrieve;
202 void handle_max_record_retrieve(Z_APDU *apdu);
203 void display_diagrecs(Z_DiagRec **pp, int num);
204 Z_Records *create_nonSurrogateDiagnostics(ODR o, int error,
205 const char *addinfo);
207 Z_APDU *handle_query_validation(Z_APDU *apdu);
208 Z_APDU *handle_syntax_validation(Z_APDU *apdu);
209 const char *load_balance(const char **url);
211 Yaz_ProxyConfig *check_reconfigure();
213 int m_invalid_session;
215 void convert_to_marcxml(Z_NamePlusRecordList *p);
217 Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable,
218 Yaz_Proxy *parent = 0);
220 void recv_Z_PDU(Z_APDU *apdu, int len);
221 void recv_Z_PDU_0(Z_APDU *apdu);
222 IYaz_PDU_Observer* sessionNotify
223 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
225 void timeoutNotify();
226 void connectNotify();
227 const char *option(const char *name, const char *value);
228 void set_default_target(const char *target);
229 void set_proxy_authentication (const char *auth);
230 char *get_proxy_target() { return m_proxyTarget; };
231 char *get_session_str() { return m_session_str; };
232 void set_max_clients(int m) { m_max_clients = m; };
233 void set_client_idletime (int t) { m_client_idletime = (t > 1) ? t : 600; };
234 void set_target_idletime (int t) { m_target_idletime = (t > 1) ? t : 600; };
235 int get_target_idletime () { return m_target_idletime; }
236 int set_config(const char *name);
237 void reconfig() { m_reconfig_flag = 1; }
238 int send_to_client(Z_APDU *apdu);
239 void server(const char *addr);
241 int get_log_mask() { return m_log_mask; };