2 * Copyright (c) 1998-2003, Index Data.
3 * See the file LICENSE for details.
5 * $Id: proxy.h,v 1.14 2003-10-09 12:11:09 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);
28 void get_target_info(const char *name, const char **url,
29 int *limit_bw, int *limit_pdu, int *limit_req,
30 int *target_idletime, int *client_idletime,
32 int *keepalive_limit_bw, int *keepalive_limit_pdu);
33 void operator=(const Yaz_ProxyConfig &conf);
34 int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo);
35 int check_syntax(ODR odr, const char *name,
36 Odr_oid *syntax, char **addinfo);
40 xmlNodePtr m_proxyPtr;
41 void return_target_info(xmlNodePtr ptr, const char **url,
42 int *limit_bw, int *limit_pdu, int *limit_req,
43 int *target_idletime, int *client_idletime,
44 int *keepalive_limit_bw, int *keepalive_limit_pdu);
45 void return_limit(xmlNodePtr ptr,
46 int *limit_bw, int *limit_pdu, int *limit_req);
47 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
49 xmlNodePtr find_target_node(const char *name);
50 const char *get_text(xmlNodePtr ptr);
51 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
52 Z_AttributeList *attrs,
54 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
58 int match_list(int v, const char *m);
59 int atoi_l(const char **cp);
63 class YAZ_EXPORT Yaz_RecordCache {
67 void add (ODR o, Z_NamePlusRecordList *npr, int start, int hits);
69 int lookup (ODR o, Z_NamePlusRecordList **npr, int start, int num,
70 Odr_oid *syntax, Z_RecordComposition *comp);
73 void copy_searchRequest(Z_SearchRequest *sr);
74 void copy_presentRequest(Z_PresentRequest *pr);
75 void set_max_size(int sz);
78 Yaz_RecordCache_Entry *m_entries;
79 Z_SearchRequest *m_searchRequest;
80 Z_PresentRequest *m_presentRequest;
81 int match (Yaz_RecordCache_Entry *entry,
82 Odr_oid *syntax, int offset,
83 Z_RecordComposition *comp);
87 class YAZ_EXPORT Yaz_bw {
91 void add_bytes(int m);
94 long m_sec; // time of most recent bucket
101 class YAZ_EXPORT Yaz_ProxyClient : public Yaz_Z_Assoc {
102 friend class Yaz_Proxy;
103 Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable);
105 void recv_Z_PDU(Z_APDU *apdu, int len);
106 IYaz_PDU_Observer* sessionNotify
107 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
111 void timeoutNotify();
112 void connectNotify();
113 int send_to_target(Z_APDU *apdu);
114 const char *get_session_str();
116 Yaz_ProxyClient *m_next;
117 Yaz_ProxyClient **m_prev;
119 Yaz_Z_Query *m_last_query;
120 Yaz_Z_Databases m_last_databases;
121 char *m_last_resultSetId;
123 int m_last_resultCount;
127 int m_resultSetStartPoint;
132 Z_APDU *m_initResponse;
133 Yaz_RecordCache m_cache;
136 /// Information Retrieval Proxy Server.
137 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
139 char *get_cookie(Z_OtherInformation **otherInfo);
140 char *get_proxy(Z_OtherInformation **otherInfo);
141 Yaz_ProxyClient *get_client(Z_APDU *apdu);
142 Z_APDU *result_set_optimize(Z_APDU *apdu);
145 Yaz_ProxyClient *m_client;
146 IYaz_PDU_Observable *m_PDU_Observable;
147 Yaz_ProxyClient *m_clientPool;
151 int m_keepalive_limit_bw;
152 int m_keepalive_limit_pdu;
153 int m_client_idletime;
154 int m_target_idletime;
156 char *m_default_target;
157 char *m_proxy_authentication;
160 int m_session_no; // sequence for each client session
161 char m_session_str[30]; // session string (time:session_no)
162 Yaz_ProxyConfig m_config;
163 char *m_config_fname;
170 Z_APDU *m_bw_hold_PDU;
171 int m_max_record_retrieve;
172 void handle_max_record_retrieve(Z_APDU *apdu);
173 void display_diagrecs(Z_DiagRec **pp, int num);
174 Z_Records *create_nonSurrogateDiagnostics(ODR o, int error,
175 const char *addinfo);
177 Z_APDU *handle_query_validation(Z_APDU *apdu);
178 Z_APDU *handle_syntax_validation(Z_APDU *apdu);
179 const char *load_balance(const char **url);
181 void check_reconfigure();
183 int m_invalid_session;
185 Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable);
187 void recv_Z_PDU(Z_APDU *apdu, int len);
188 void recv_Z_PDU_0(Z_APDU *apdu);
189 IYaz_PDU_Observer* sessionNotify
190 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
192 void timeoutNotify();
193 void connectNotify();
194 const char *option(const char *name, const char *value);
195 void set_default_target(const char *target);
196 void set_proxy_authentication (const char *auth);
197 char *get_proxy_target() { return m_proxyTarget; };
198 char *get_session_str() { return m_session_str; };
199 void set_max_clients(int m) { m_max_clients = m; };
200 void set_client_idletime (int t) { m_client_idletime = (t > 1) ? t : 600; };
201 void set_target_idletime (int t) { m_target_idletime = (t > 1) ? t : 600; };
202 int get_target_idletime () { return m_target_idletime; }
203 int set_config(const char *name);
204 int reconfig() { m_reconfig_flag = 1; }
205 int send_to_client(Z_APDU *apdu);