Record cache. syntax used for matching. Compspec is not (yet)
[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.4 2003-07-18 13:27:20 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);
21     int lookup (ODR o, Z_NamePlusRecordList **npr, int start, int num,
22                 Odr_oid *syntax);
23     void clear();
24  private:
25     NMEM m_mem;
26     Yaz_RecordCache_Entry *m_entries;
27 };
28
29 /// Private class
30 class YAZ_EXPORT Yaz_ProxyClient : public Yaz_Z_Assoc {
31     friend class Yaz_Proxy;
32     Yaz_ProxyClient(IYaz_PDU_Observable *the_PDU_Observable);
33     ~Yaz_ProxyClient();
34     void recv_Z_PDU(Z_APDU *apdu);
35     IYaz_PDU_Observer* sessionNotify
36         (IYaz_PDU_Observable *the_PDU_Observable, int fd);
37     void shutdown();
38     Yaz_Proxy *m_server;
39     void failNotify();
40     void timeoutNotify();
41     void connectNotify();
42     char m_cookie[32];
43     Yaz_ProxyClient *m_next;
44     Yaz_ProxyClient **m_prev;
45     int m_init_flag;
46     Yaz_Z_Query *m_last_query;
47     Yaz_Z_Databases m_last_databases;
48     char *m_last_resultSetId;
49     int m_last_ok;
50     int m_last_resultCount;
51     int m_sr_transform;
52     int m_seqno;
53     int m_waiting;
54     int m_resultSetStartPoint;
55     ODR m_init_odr;
56     Z_APDU *m_initResponse;
57     Yaz_RecordCache m_cache;
58 };
59
60 /// Information Retrieval Proxy Server.
61 class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc {
62  private:
63     char *get_cookie(Z_OtherInformation **otherInfo);
64     char *get_proxy(Z_OtherInformation **otherInfo);
65     Yaz_ProxyClient *get_client(Z_APDU *apdu);
66     Z_APDU *result_set_optimize(Z_APDU *apdu);
67     void shutdown();
68     
69     Yaz_ProxyClient *m_client;
70     IYaz_PDU_Observable *m_PDU_Observable;
71     Yaz_ProxyClient *m_clientPool;
72     Yaz_Proxy *m_parent;
73     int m_seqno;
74     int m_max_clients;
75     int m_keepalive;
76     int m_idletime;
77     char *m_proxyTarget;
78     char *m_proxy_authentication;
79     long m_seed;
80     char *m_optimize;
81  public:
82     Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable);
83     ~Yaz_Proxy();
84     void recv_Z_PDU(Z_APDU *apdu);
85     IYaz_PDU_Observer* sessionNotify
86         (IYaz_PDU_Observable *the_PDU_Observable, int fd);
87     void failNotify();
88     void timeoutNotify();
89     void connectNotify();
90     const char *option(const char *name, const char *value);
91     void set_proxy_target(const char *target);
92     void set_proxy_authentication (const char *auth);
93     char *get_proxy_target() { return m_proxyTarget; };
94     void set_max_clients(int m) { m_max_clients = m; };
95     void set_idletime (int t) { m_idletime = (t > 1) ? t : 600; };
96 };
97