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