Minor updates.
[yazpp-moved-to-github.git] / src / yaz-z-server-ill.cpp
1 /*
2  * Copyright (c) 2000-2001, Index Data.
3  * See the file LICENSE for details.
4  * 
5  * $Log: yaz-z-server-ill.cpp,v $
6  * Revision 1.2  2001-03-29 15:14:26  adam
7  * Minor updates.
8  *
9  * Revision 1.1  2001/03/27 14:47:45  adam
10  * New server facility scheme.
11  *
12  */
13
14 #include <yaz/log.h>
15 #include <yaz++/yaz-z-server.h>
16
17 /*
18  * database record.
19  */
20 void Yaz_Facility_ILL::create_databaseRecord (
21     Z_NamePlusRecord *rec, const char *dbname, int format,
22     const void *buf, int len)
23 {
24     rec->databaseName = dbname ? odr_strdup (m_odr, dbname) : 0;
25     rec->which = Z_NamePlusRecord_databaseRecord;
26     rec->u.databaseRecord = z_ext_record (m_odr, format,
27                                           (const char *) buf, len);
28 }
29
30 /*
31  * surrogate diagnostic.
32  */
33 void Yaz_Facility_ILL::create_surrogateDiagnostics(
34     Z_NamePlusRecord *rec, const char *dbname, int error, char *const addinfo)
35 {
36     int oid[OID_SIZE];
37     int *err = (int *)odr_malloc (m_odr, sizeof(*err));
38     oident bib1;
39     Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (m_odr, sizeof(*drec));
40     Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
41         odr_malloc (m_odr, sizeof(*dr));
42     
43     bib1.proto = PROTO_Z3950;
44     bib1.oclass = CLASS_DIAGSET;
45     bib1.value = VAL_BIB1;
46
47     yaz_log(LOG_DEBUG, "SurrogateDiagnotic: %d -- %s", error, addinfo);
48     *err = error;
49     rec->databaseName = dbname ? odr_strdup (m_odr, dbname) : 0;
50     rec->which = Z_NamePlusRecord_surrogateDiagnostic;
51     rec->u.surrogateDiagnostic = drec;
52     drec->which = Z_DiagRec_defaultFormat;
53     drec->u.defaultFormat = dr;
54     dr->diagnosticSetId = odr_oiddup (m_odr,
55                                       oid_ent_to_oid(&bib1, oid));
56     dr->condition = err;
57     dr->which = Z_DefaultDiagFormat_v2Addinfo;
58     dr->u.v2Addinfo = odr_strdup (m_odr, addinfo ? addinfo : "");
59 }
60
61 ODR Yaz_Facility_ILL::odr_encode()
62 {
63     return m_odr;
64 }
65
66 int Yaz_Facility_ILL::init(Yaz_Z_Server *s, Z_InitRequest *initRequest,
67                            Z_InitResponse *initResponse)
68 {
69     Z_Options *req = initRequest->options;
70     Z_Options *res = initResponse->options;
71     
72     if (ODR_MASK_GET(req, Z_Options_extendedServices))
73         ODR_MASK_SET(res, Z_Options_extendedServices);
74     return ill_init (initRequest, initResponse);
75 }
76
77 int Yaz_Facility_ILL::recv(Yaz_Z_Server *s, Z_APDU *apdu_request)
78 {   
79     Z_APDU *apdu_response;
80
81     m_odr = s->odr_encode();
82     if (apdu_request->which != Z_APDU_extendedServicesRequest)
83         return 0;
84     
85     yaz_log (LOG_LOG, "got extendedSericesRequest p=%p", this);
86     apdu_response = s->create_Z_PDU(Z_APDU_extendedServicesResponse);
87     s->send_Z_PDU(apdu_response);
88     return 1;
89 }