2 * Copyright (c) 1998-2003, Index Data.
3 * See the file LICENSE for details.
5 * $Id: proxy.h,v 1.11 2003-10-08 08:15:01 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 struct Yaz_RecordCache_Entry;
21 class YAZ_EXPORT Yaz_ProxyConfig {
25 int read_xml(const char *fname);
26 void get_target_info(const char *name, const char **url, int *keepalive,
27 int *limit_bw, int *limit_pdu, int *limit_req,
28 int *target_idletime, int *client_idletime,
30 void operator=(const Yaz_ProxyConfig &conf);
31 int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo);
32 int check_syntax(ODR odr, const char *name,
33 Odr_oid *syntax, char **addinfo);
37 xmlNodePtr m_proxyPtr;
38 void return_target_info(xmlNodePtr ptr, const char **url, int *keepalive,
39 int *limit_bw, int *limit_pdu, int *limit_req,
40 int *target_idletime, int *client_idletime);
41 void return_limit(xmlNodePtr ptr,
42 int *limit_bw, int *limit_pdu, int *limit_req);
43 int check_type_1(ODR odr, xmlNodePtr ptr, Z_RPNQuery *query,
45 xmlNodePtr find_target_node(const char *name);
46 const char *get_text(xmlNodePtr ptr);
47 int check_type_1_attributes(ODR odr, xmlNodePtr ptr,
48 Z_AttributeList *attrs,
50 int check_type_1_structure(ODR odr, xmlNodePtr ptr, Z_RPNStructure *q,
54 int match_list(int v, const char *m);
55 int atoi_l(const char **cp);
59 class YAZ_EXPORT Yaz_RecordCache {
63 void add (ODR o, Z_NamePlusRecordList *npr, int start, int hits);
65 int lookup (ODR o, Z_NamePlusRecordList **npr, int start, int num,
66 Odr_oid *syntax, Z_RecordComposition *comp);
69 void copy_searchRequest(Z_SearchRequest *sr);
70 void copy_presentRequest(Z_PresentRequest *pr);
73 Yaz_RecordCache_Entry *m_entries;
74 Z_SearchRequest *m_searchRequest;
75 Z_PresentRequest *m_presentRequest;
76 int match (Yaz_RecordCache_Entry *entry,
77 Odr_oid *syntax, int offset,
78 Z_RecordComposition *comp);
81 class YAZ_EXPORT Yaz_bw {
85 void add_bytes(int m);
88 long m_sec; // time of most recent bucket
95 class YAZ_EXPORT Yaz_ProxyClient : public Yaz_Z_Assoc {
96 friend class Yaz_Proxy;
97 Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable);
99 void recv_Z_PDU(Z_APDU *apdu, int len);
100 IYaz_PDU_Observer* sessionNotify
101 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
105 void timeoutNotify();
106 void connectNotify();
107 int send_to_target(Z_APDU *apdu);
108 const char *get_session_str();
110 Yaz_ProxyClient *m_next;
111 Yaz_ProxyClient **m_prev;
113 Yaz_Z_Query *m_last_query;
114 Yaz_Z_Databases m_last_databases;
115 char *m_last_resultSetId;
117 int m_last_resultCount;
121 int m_resultSetStartPoint;
125 Z_APDU *m_initResponse;
126 Yaz_RecordCache m_cache;
129 /// Information Retrieval Proxy Server.
130 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
132 char *get_cookie(Z_OtherInformation **otherInfo);
133 char *get_proxy(Z_OtherInformation **otherInfo);
134 Yaz_ProxyClient *get_client(Z_APDU *apdu);
135 Z_APDU *result_set_optimize(Z_APDU *apdu);
138 Yaz_ProxyClient *m_client;
139 IYaz_PDU_Observable *m_PDU_Observable;
140 Yaz_ProxyClient *m_clientPool;
145 int m_client_idletime;
146 int m_target_idletime;
148 char *m_default_target;
149 char *m_proxy_authentication;
152 int m_session_no; // sequence for each client session
153 char m_session_str[20]; // session string (time:session_no)
154 Yaz_ProxyConfig m_config;
161 Z_APDU *m_bw_hold_PDU;
162 int m_max_record_retrieve;
163 void handle_max_record_retrieve(Z_APDU *apdu);
164 void display_diagrecs(Z_DiagRec **pp, int num);
165 Z_Records *create_nonSurrogateDiagnostics(ODR o, int error,
166 const char *addinfo);
168 Z_APDU *handle_query_validation(Z_APDU *apdu);
169 Z_APDU *handle_syntax_validation(Z_APDU *apdu);
171 Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable);
173 void recv_Z_PDU(Z_APDU *apdu, int len);
174 void recv_Z_PDU_0(Z_APDU *apdu);
175 IYaz_PDU_Observer* sessionNotify
176 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
178 void timeoutNotify();
179 void connectNotify();
180 const char *option(const char *name, const char *value);
181 void set_default_target(const char *target);
182 void set_proxy_authentication (const char *auth);
183 char *get_proxy_target() { return m_proxyTarget; };
184 char *get_session_str() { return m_session_str; };
185 void set_max_clients(int m) { m_max_clients = m; };
186 void set_client_idletime (int t) { m_client_idletime = (t > 1) ? t : 600; };
187 void set_target_idletime (int t) { m_target_idletime = (t > 1) ? t : 600; };
188 int get_target_idletime () { return m_target_idletime; }
189 int set_config(const char *name);
190 int send_to_client(Z_APDU *apdu);