Use compspec in match in record cache lookup
[yazpp-moved-to-github.git] / include / yaz++ / proxy.h
1 /*
2  * Copyright (c) 1998-2003, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: proxy.h,v 1.5 2003-07-25 08:57:01 adam Exp $
6  */
7
8 #include <yaz++/z-assoc.h>
9 #include <yaz++/z-query.h>
10 #include <yaz++/z-databases.h>
11
12 class Yaz_Proxy;
13
14 class Yaz_RecordCache_Entry;
15
16 class YAZ_EXPORT Yaz_RecordCache {
17  public:
18     Yaz_RecordCache ();
19     ~Yaz_RecordCache ();
20     void add (ODR o, Z_NamePlusRecordList *npr, int start, int hits);
21     
22     int lookup (ODR o, Z_NamePlusRecordList **npr, int start, int num,
23                 Odr_oid *syntax, Z_RecordComposition *comp);
24     void clear();
25
26     void copy_searchRequest(Z_SearchRequest *sr);
27     void copy_presentRequest(Z_PresentRequest *pr);
28  private:
29     NMEM m_mem;
30     Yaz_RecordCache_Entry *m_entries;
31     Z_SearchRequest *m_searchRequest;
32     Z_PresentRequest *m_presentRequest;
33     int match (Yaz_RecordCache_Entry *entry,
34                Odr_oid *syntax, int offset,
35                Z_RecordComposition *comp);
36 };
37
38 /// Private class
39 class YAZ_EXPORT Yaz_ProxyClient : public Yaz_Z_Assoc {
40     friend class Yaz_Proxy;
41     Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable);
42     ~Yaz_ProxyClient();
43     void recv_Z_PDU(Z_APDU *apdu);
44     IYaz_PDU_Observer* sessionNotify
45         (IYaz_PDU_Observable *the_PDU_Observable, int fd);
46     void shutdown();
47     Yaz_Proxy *m_server;
48     void failNotify();
49     void timeoutNotify();
50     void connectNotify();
51     char m_cookie[32];
52     Yaz_ProxyClient *m_next;
53     Yaz_ProxyClient **m_prev;
54     int m_init_flag;
55     Yaz_Z_Query *m_last_query;
56     Yaz_Z_Databases m_last_databases;
57     char *m_last_resultSetId;
58     int m_last_ok;
59     int m_last_resultCount;
60     int m_sr_transform;
61     int m_seqno;
62     int m_waiting;
63     int m_resultSetStartPoint;
64     ODR m_init_odr;
65     Z_APDU *m_initResponse;
66     Yaz_RecordCache m_cache;
67 };
68
69 /// Information Retrieval Proxy Server.
70 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
71  private:
72     char *get_cookie(Z_OtherInformation **otherInfo);
73     char *get_proxy(Z_OtherInformation **otherInfo);
74     Yaz_ProxyClient *get_client(Z_APDU *apdu);
75     Z_APDU *result_set_optimize(Z_APDU *apdu);
76     void shutdown();
77     
78     Yaz_ProxyClient *m_client;
79     IYaz_PDU_Observable *m_PDU_Observable;
80     Yaz_ProxyClient *m_clientPool;
81     Yaz_Proxy *m_parent;
82     int m_seqno;
83     int m_max_clients;
84     int m_keepalive;
85     int m_idletime;
86     char *m_proxyTarget;
87     char *m_proxy_authentication;
88     long m_seed;
89     char *m_optimize;
90  public:
91     Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable);
92     ~Yaz_Proxy();
93     void recv_Z_PDU(Z_APDU *apdu);
94     IYaz_PDU_Observer* sessionNotify
95         (IYaz_PDU_Observable *the_PDU_Observable, int fd);
96     void failNotify();
97     void timeoutNotify();
98     void connectNotify();
99     const char *option(const char *name, const char *value);
100     void set_proxy_target(const char *target);
101     void set_proxy_authentication (const char *auth);
102     char *get_proxy_target() { return m_proxyTarget; };
103     void set_max_clients(int m) { m_max_clients = m; };
104     void set_idletime (int t) { m_idletime = (t > 1) ? t : 600; };
105 };
106