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