2 * Copyright (c) 1998-2003, Index Data.
3 * See the file LICENSE for details.
5 * $Id: proxy.h,v 1.16 2003-10-13 19:16:28 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 struct Yaz_RecordCache_Entry;
23 class YAZ_EXPORT Yaz_ProxyConfig {
27 int read_xml(const char *fname);
29 int get_target_no(int no,
38 int *keepalive_limit_bw,
39 int *keepalive_limit_pdu,
42 void get_target_info(const char *name, const char **url,
43 int *limit_bw, int *limit_pdu, int *limit_req,
44 int *target_idletime, int *client_idletime,
46 int *keepalive_limit_bw, int *keepalive_limit_pdu,
49 int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo);
50 int check_syntax(ODR odr, const char *name,
51 Odr_oid *syntax, char **addinfo);
53 void operator=(const Yaz_ProxyConfig &conf);
56 xmlNodePtr m_proxyPtr;
57 void return_target_info(xmlNodePtr ptr, const char **url,
58 int *limit_bw, int *limit_pdu, int *limit_req,
59 int *target_idletime, int *client_idletime,
60 int *keepalive_limit_bw, int *keepalive_limit_pdu,
62 void return_limit(xmlNodePtr ptr,
63 int *limit_bw, int *limit_pdu, int *limit_req);
64 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
66 xmlNodePtr find_target_node(const char *name);
67 const char *get_text(xmlNodePtr ptr);
68 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
69 Z_AttributeList *attrs,
71 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
75 int match_list(int v, const char *m);
76 int atoi_l(const char **cp);
80 class YAZ_EXPORT Yaz_RecordCache {
84 void add (ODR o, Z_NamePlusRecordList *npr, int start, int hits);
86 int lookup (ODR o, Z_NamePlusRecordList **npr, int start, int num,
87 Odr_oid *syntax, Z_RecordComposition *comp);
90 void copy_searchRequest(Z_SearchRequest *sr);
91 void copy_presentRequest(Z_PresentRequest *pr);
92 void set_max_size(int sz);
95 Yaz_RecordCache_Entry *m_entries;
96 Z_SearchRequest *m_searchRequest;
97 Z_PresentRequest *m_presentRequest;
98 int match (Yaz_RecordCache_Entry *entry,
99 Odr_oid *syntax, int offset,
100 Z_RecordComposition *comp);
104 class YAZ_EXPORT Yaz_bw {
108 void add_bytes(int m);
111 long m_sec; // time of most recent bucket
118 class YAZ_EXPORT Yaz_ProxyClient : public Yaz_Z_Assoc {
119 friend class Yaz_Proxy;
120 Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable,
123 void recv_Z_PDU(Z_APDU *apdu, int len);
124 IYaz_PDU_Observer* sessionNotify
125 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
129 void timeoutNotify();
130 void connectNotify();
131 int send_to_target(Z_APDU *apdu);
132 const char *get_session_str();
134 Yaz_ProxyClient *m_next;
135 Yaz_ProxyClient **m_prev;
137 Yaz_Z_Query *m_last_query;
138 Yaz_Z_Databases m_last_databases;
139 char *m_last_resultSetId;
141 int m_last_resultCount;
145 int m_resultSetStartPoint;
150 Z_APDU *m_initResponse;
151 Yaz_RecordCache m_cache;
152 void pre_init_client();
153 int m_target_idletime;
157 /// Information Retrieval Proxy Server.
158 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
160 char *get_cookie(Z_OtherInformation **otherInfo);
161 char *get_proxy(Z_OtherInformation **otherInfo);
162 Yaz_ProxyClient *get_client(Z_APDU *apdu);
163 Z_APDU *result_set_optimize(Z_APDU *apdu);
166 Yaz_ProxyClient *m_client;
167 IYaz_PDU_Observable *m_PDU_Observable;
168 Yaz_ProxyClient *m_clientPool;
172 int m_keepalive_limit_bw;
173 int m_keepalive_limit_pdu;
174 int m_client_idletime;
175 int m_target_idletime;
177 char *m_default_target;
178 char *m_proxy_authentication;
181 int m_session_no; // sequence for each client session
182 char m_session_str[30]; // session string (time:session_no)
183 Yaz_ProxyConfig *m_config;
184 char *m_config_fname;
191 Z_APDU *m_bw_hold_PDU;
192 int m_max_record_retrieve;
193 void handle_max_record_retrieve(Z_APDU *apdu);
194 void display_diagrecs(Z_DiagRec **pp, int num);
195 Z_Records *create_nonSurrogateDiagnostics(ODR o, int error,
196 const char *addinfo);
198 Z_APDU *handle_query_validation(Z_APDU *apdu);
199 Z_APDU *handle_syntax_validation(Z_APDU *apdu);
200 const char *load_balance(const char **url);
202 Yaz_ProxyConfig *check_reconfigure();
204 int m_invalid_session;
206 void convert_to_marcxml(Z_NamePlusRecordList *p);
208 Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable,
209 Yaz_Proxy *parent = 0);
211 void recv_Z_PDU(Z_APDU *apdu, int len);
212 void recv_Z_PDU_0(Z_APDU *apdu);
213 IYaz_PDU_Observer* sessionNotify
214 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
216 void timeoutNotify();
217 void connectNotify();
218 const char *option(const char *name, const char *value);
219 void set_default_target(const char *target);
220 void set_proxy_authentication (const char *auth);
221 char *get_proxy_target() { return m_proxyTarget; };
222 char *get_session_str() { return m_session_str; };
223 void set_max_clients(int m) { m_max_clients = m; };
224 void set_client_idletime (int t) { m_client_idletime = (t > 1) ? t : 600; };
225 void set_target_idletime (int t) { m_target_idletime = (t > 1) ? t : 600; };
226 int get_target_idletime () { return m_target_idletime; }
227 int set_config(const char *name);
228 int reconfig() { m_reconfig_flag = 1; }
229 int send_to_client(Z_APDU *apdu);
230 void server(const char *addr);