2 * Copyright (c) 1998-2003, Index Data.
3 * See the file LICENSE for details.
5 * $Id: proxy.h,v 1.18 2003-10-16 13:40:41 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 1
22 #define PROXY_LOG_REQ 1
24 struct Yaz_RecordCache_Entry;
26 class YAZ_EXPORT Yaz_ProxyConfig {
30 int read_xml(const char *fname);
32 int get_target_no(int no,
41 int *keepalive_limit_bw,
42 int *keepalive_limit_pdu,
46 void get_target_info(const char *name, const char **url,
47 int *limit_bw, int *limit_pdu, int *limit_req,
48 int *target_idletime, int *client_idletime,
50 int *keepalive_limit_bw, int *keepalive_limit_pdu,
51 int *pre_init, int *log_mask);
53 int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo);
54 int check_syntax(ODR odr, const char *name,
55 Odr_oid *syntax, char **addinfo);
57 void operator=(const Yaz_ProxyConfig &conf);
60 xmlNodePtr m_proxyPtr;
61 void return_target_info(xmlNodePtr ptr, const char **url,
62 int *limit_bw, int *limit_pdu, int *limit_req,
63 int *target_idletime, int *client_idletime,
64 int *keepalive_limit_bw, int *keepalive_limit_pdu,
65 int *pre_init, int *log_mask);
66 void return_limit(xmlNodePtr ptr,
67 int *limit_bw, int *limit_pdu, int *limit_req);
68 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
70 xmlNodePtr find_target_node(const char *name);
71 const char *get_text(xmlNodePtr ptr);
72 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
73 Z_AttributeList *attrs,
75 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
79 int match_list(int v, const char *m);
80 int atoi_l(const char **cp);
84 class YAZ_EXPORT Yaz_RecordCache {
88 void add (ODR o, Z_NamePlusRecordList *npr, int start, int hits);
90 int lookup (ODR o, Z_NamePlusRecordList **npr, int start, int num,
91 Odr_oid *syntax, Z_RecordComposition *comp);
94 void copy_searchRequest(Z_SearchRequest *sr);
95 void copy_presentRequest(Z_PresentRequest *pr);
96 void set_max_size(int sz);
99 Yaz_RecordCache_Entry *m_entries;
100 Z_SearchRequest *m_searchRequest;
101 Z_PresentRequest *m_presentRequest;
102 int match (Yaz_RecordCache_Entry *entry,
103 Odr_oid *syntax, int offset,
104 Z_RecordComposition *comp);
108 class YAZ_EXPORT Yaz_bw {
112 void add_bytes(int m);
115 long m_sec; // time of most recent bucket
122 class YAZ_EXPORT Yaz_ProxyClient : public Yaz_Z_Assoc {
123 friend class Yaz_Proxy;
124 Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable,
127 void recv_Z_PDU(Z_APDU *apdu, int len);
128 IYaz_PDU_Observer* sessionNotify
129 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
133 void timeoutNotify();
134 void connectNotify();
135 int send_to_target(Z_APDU *apdu);
136 const char *get_session_str();
138 Yaz_ProxyClient *m_next;
139 Yaz_ProxyClient **m_prev;
141 Yaz_Z_Query *m_last_query;
142 Yaz_Z_Databases m_last_databases;
143 char *m_last_resultSetId;
145 int m_last_resultCount;
149 int m_resultSetStartPoint;
154 Z_APDU *m_initResponse;
155 Yaz_RecordCache m_cache;
156 void pre_init_client();
157 int m_target_idletime;
161 /// Information Retrieval Proxy Server.
162 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
164 char *get_cookie(Z_OtherInformation **otherInfo);
165 char *get_proxy(Z_OtherInformation **otherInfo);
166 Yaz_ProxyClient *get_client(Z_APDU *apdu);
167 Z_APDU *result_set_optimize(Z_APDU *apdu);
170 Yaz_ProxyClient *m_client;
171 IYaz_PDU_Observable *m_PDU_Observable;
172 Yaz_ProxyClient *m_clientPool;
176 int m_keepalive_limit_bw;
177 int m_keepalive_limit_pdu;
178 int m_client_idletime;
179 int m_target_idletime;
181 char *m_default_target;
182 char *m_proxy_authentication;
185 int m_session_no; // sequence for each client session
186 char m_session_str[30]; // session string (time:session_no)
187 Yaz_ProxyConfig *m_config;
188 char *m_config_fname;
195 Z_APDU *m_bw_hold_PDU;
196 int m_max_record_retrieve;
197 void handle_max_record_retrieve(Z_APDU *apdu);
198 void display_diagrecs(Z_DiagRec **pp, int num);
199 Z_Records *create_nonSurrogateDiagnostics(ODR o, int error,
200 const char *addinfo);
202 Z_APDU *handle_query_validation(Z_APDU *apdu);
203 Z_APDU *handle_syntax_validation(Z_APDU *apdu);
204 const char *load_balance(const char **url);
206 Yaz_ProxyConfig *check_reconfigure();
208 int m_invalid_session;
210 void convert_to_marcxml(Z_NamePlusRecordList *p);
212 Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable,
213 Yaz_Proxy *parent = 0);
215 void recv_Z_PDU(Z_APDU *apdu, int len);
216 void recv_Z_PDU_0(Z_APDU *apdu);
217 IYaz_PDU_Observer* sessionNotify
218 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
220 void timeoutNotify();
221 void connectNotify();
222 const char *option(const char *name, const char *value);
223 void set_default_target(const char *target);
224 void set_proxy_authentication (const char *auth);
225 char *get_proxy_target() { return m_proxyTarget; };
226 char *get_session_str() { return m_session_str; };
227 void set_max_clients(int m) { m_max_clients = m; };
228 void set_client_idletime (int t) { m_client_idletime = (t > 1) ? t : 600; };
229 void set_target_idletime (int t) { m_target_idletime = (t > 1) ? t : 600; };
230 int get_target_idletime () { return m_target_idletime; }
231 int set_config(const char *name);
232 void reconfig() { m_reconfig_flag = 1; }
233 int send_to_client(Z_APDU *apdu);
234 void server(const char *addr);