Fix: proxy doesn't cache searches/result sets when errors occur.
[yazpp-moved-to-github.git] / include / yaz++ / yaz-z-server.h
1 /*
2  * Copyright (c) 2000-2001, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Id: yaz-z-server.h,v 1.10 2001-05-17 14:18:03 adam Exp $
6  */
7
8 #include <yaz++/yaz-z-assoc.h>
9 #if HAVE_YAZ_URSULA_H
10 #include <yaz/zes-ursula.h>
11 #endif
12
13 class Yaz_Z_Server;
14
15 class YAZ_EXPORT Yaz_Z_ServerUtility {
16  public:
17     void create_databaseRecord (ODR odr, Z_NamePlusRecord *rec,
18                                 const char *dbname, int format,
19                                 const void *buf, int len);
20     void create_surrogateDiagnostics(ODR odr, Z_NamePlusRecord *rec,
21                                      const char *dbname, int error,
22                                      char *const addinfo);
23     
24     Z_Records *create_nonSurrogateDiagnostics (ODR odr, int error,
25                                                const char *addinfo);
26 };
27
28 class YAZ_EXPORT IYaz_Server_Facility {
29  public:
30     virtual int init(Yaz_Z_Server *server,
31                      Z_InitRequest *initRequest,
32                      Z_InitResponse *initResponse) = 0;
33     virtual int recv(Yaz_Z_Server *server, Z_APDU *apdu) = 0;
34 };
35
36
37 #if HAVE_YAZ_URSULA_H
38 class YAZ_EXPORT Yaz_Facility_Ursula : public IYaz_Server_Facility {
39  public:
40 //    virtual void ursula_service (Z_ExtendedServicesRequest *req,
41 //                               Z_UrsPDU *u,
42 //                               Z_ExtendedServicesResponse *res) = 0;
43     virtual void ursula_service (Z_ExtendedServicesRequest *req,
44                          Z_UrsPDU *u_req,
45                          Z_ExtendedServicesResponse *res,
46                          Z_UrsPDU *u_res) =0;
47
48     int init(Yaz_Z_Server *server,
49              Z_InitRequest *initRequest,
50              Z_InitResponse *initResponse);
51     int recv(Yaz_Z_Server *server, Z_APDU *apdu);
52 };
53 #endif
54
55 class YAZ_EXPORT Yaz_Facility_ILL : public IYaz_Server_Facility {
56  public:
57     virtual void ill_service (Z_ExtendedServicesRequest *req,
58                               Z_ItemOrder *io,
59                               Z_ExtendedServicesResponse *res) = 0;
60
61     int init(Yaz_Z_Server *server,
62              Z_InitRequest *initRequest,
63              Z_InitResponse *initResponse);
64     int recv(Yaz_Z_Server *server, Z_APDU *apdu);
65 };
66
67 class YAZ_EXPORT Yaz_Facility_Update : public IYaz_Server_Facility {
68  public:
69     virtual void update_service (Z_ExtendedServicesRequest *req,
70                                  Z_IUUpdate *io,
71                                  Z_ExtendedServicesResponse *res) = 0;
72
73     virtual void update_service0 (Z_ExtendedServicesRequest *req,
74                                  Z_IU0Update *io,
75                                  Z_ExtendedServicesResponse *res) = 0;
76
77     int init(Yaz_Z_Server *server,
78              Z_InitRequest *initRequest,
79              Z_InitResponse *initResponse);
80     int recv(Yaz_Z_Server *server, Z_APDU *apdu);
81 };
82
83
84 class YAZ_EXPORT Yaz_Facility_Retrieval : public IYaz_Server_Facility,
85     public Yaz_Z_ServerUtility {
86  public:
87
88     virtual int sr_init (Z_InitRequest *initRequest,
89                          Z_InitResponse *initResponse) = 0;
90     virtual void sr_search (Z_SearchRequest *searchRequest,
91                             Z_SearchResponse *searchResponse) = 0;
92     virtual void sr_present (Z_PresentRequest *presentRequest,
93                              Z_PresentResponse *presentResponse) = 0;
94     virtual void sr_record (const char *resultSetName,
95                             int position,
96                             int *format,
97                                 Z_RecordComposition *comp,
98                                 Z_NamePlusRecord *namePlusRecord,
99                                 Z_Records *diagnostics) = 0;
100     int init(Yaz_Z_Server *server,
101              Z_InitRequest *initRequest,
102              Z_InitResponse *initResponse);
103     int recv(Yaz_Z_Server *server, Z_APDU *apdu);
104
105     ODR odr_encode();
106     ODR odr_decode();
107  private:
108     Z_Records *pack_records (Yaz_Z_Server *s,
109                              const char *resultSetName,
110                              int start, int num,
111                              Z_RecordComposition *comp,
112                              int *next, int *pres,
113                              int *oid);
114
115     void fetch_via_piggyback (Yaz_Z_Server *s,
116                               Z_SearchRequest *searchRequest,
117                               Z_SearchResponse *searchResponse);
118     void fetch_via_present (Yaz_Z_Server *s,
119                             Z_PresentRequest *req, Z_PresentResponse *res);
120
121     int m_preferredMessageSize;
122     int m_maximumRecordSize;
123     ODR m_odr_encode;
124     ODR m_odr_decode;
125 };
126
127 class YAZ_EXPORT Yaz_Z_Server_Facility_Info {
128     friend class Yaz_Z_Server;
129     IYaz_Server_Facility *m_facility;
130     char *m_name;
131     Yaz_Z_Server_Facility_Info *m_next;
132 };
133
134
135
136 class YAZ_EXPORT Yaz_Z_Server : public Yaz_Z_Assoc {
137 public:
138     Yaz_Z_Server(IYaz_PDU_Observable *the_PDU_Observable);
139     virtual ~Yaz_Z_Server();
140     virtual void recv_Z_PDU(Z_APDU *apdu);
141     void facility_add(IYaz_Server_Facility *facility, const char *name);
142     void facility_reset ();
143
144
145  private:
146     Yaz_Z_Server_Facility_Info *m_facilities;
147 };
148
149 class YAZ_EXPORT Yaz_USMARC {
150  public:
151     const char *get_record(int position);
152 };