2 * Copyright (c) 1998-2003, Index Data.
3 * See the file LICENSE for details.
5 * $Id: proxy.h,v 1.8 2003-10-01 13:13:51 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 void operator=(const Yaz_ProxyConfig &conf);
32 xmlNodePtr m_proxyPtr;
33 void return_target_info(xmlNodePtr ptr, const char **url, int *keepalive,
34 int *limit_bw, int *limit_pdu, int *limit_req);
35 void return_limit(xmlNodePtr ptr,
36 int *limit_bw, int *limit_pdu, int *limit_req);
37 const char *get_text(xmlNodePtr ptr);
42 class YAZ_EXPORT Yaz_RecordCache {
46 void add (ODR o, Z_NamePlusRecordList *npr, int start, int hits);
48 int lookup (ODR o, Z_NamePlusRecordList **npr, int start, int num,
49 Odr_oid *syntax, Z_RecordComposition *comp);
52 void copy_searchRequest(Z_SearchRequest *sr);
53 void copy_presentRequest(Z_PresentRequest *pr);
56 Yaz_RecordCache_Entry *m_entries;
57 Z_SearchRequest *m_searchRequest;
58 Z_PresentRequest *m_presentRequest;
59 int match (Yaz_RecordCache_Entry *entry,
60 Odr_oid *syntax, int offset,
61 Z_RecordComposition *comp);
64 class YAZ_EXPORT Yaz_bw {
68 void add_bytes(int m);
71 long m_sec; // time of most recent bucket
78 class YAZ_EXPORT Yaz_ProxyClient : public Yaz_Z_Assoc {
79 friend class Yaz_Proxy;
80 Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable);
82 void recv_Z_PDU(Z_APDU *apdu, int len);
83 IYaz_PDU_Observer* sessionNotify
84 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
90 int send_to_target(Z_APDU *apdu);
91 const char *get_session_str();
93 Yaz_ProxyClient *m_next;
94 Yaz_ProxyClient **m_prev;
96 Yaz_Z_Query *m_last_query;
97 Yaz_Z_Databases m_last_databases;
98 char *m_last_resultSetId;
100 int m_last_resultCount;
104 int m_resultSetStartPoint;
108 Z_APDU *m_initResponse;
109 Yaz_RecordCache m_cache;
112 /// Information Retrieval Proxy Server.
113 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
115 char *get_cookie(Z_OtherInformation **otherInfo);
116 char *get_proxy(Z_OtherInformation **otherInfo);
117 Yaz_ProxyClient *get_client(Z_APDU *apdu);
118 Z_APDU *result_set_optimize(Z_APDU *apdu);
121 Yaz_ProxyClient *m_client;
122 IYaz_PDU_Observable *m_PDU_Observable;
123 Yaz_ProxyClient *m_clientPool;
128 int m_client_idletime;
129 int m_target_idletime;
131 char *m_default_target;
132 char *m_proxy_authentication;
135 int m_session_no; // sequence for each client session
136 char m_session_str[20]; // session string (time:session_no)
137 Yaz_ProxyConfig m_config;
144 Z_APDU *m_bw_hold_PDU;
145 int m_max_record_retrieve;
146 void handle_max_record_retrieve(Z_APDU *apdu);
147 void display_diagrecs(Z_DiagRec **pp, int num);
149 Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable);
151 void recv_Z_PDU(Z_APDU *apdu, int len);
152 void recv_Z_PDU_0(Z_APDU *apdu);
153 IYaz_PDU_Observer* sessionNotify
154 (IYaz_PDU_Observable *the_PDU_Observable, int fd);
156 void timeoutNotify();
157 void connectNotify();
158 const char *option(const char *name, const char *value);
159 void set_default_target(const char *target);
160 void set_proxy_authentication (const char *auth);
161 char *get_proxy_target() { return m_proxyTarget; };
162 char *get_session_str() { return m_session_str; };
163 void set_max_clients(int m) { m_max_clients = m; };
164 void set_client_idletime (int t) { m_client_idletime = (t > 1) ? t : 600; };
165 void set_target_idletime (int t) { m_target_idletime = (t > 1) ? t : 600; };
166 int get_target_idletime () { return m_target_idletime; }
167 int set_config(const char *name);
168 int send_to_client(Z_APDU *apdu);