1 /* This file is part of the yazpp toolkit.
2 * Copyright (C) 1998-2009 Index Data and Mike Taylor
3 * See the file LICENSE for details.
7 #include <yazpp/z-server.h>
8 #include <yaz/oid_db.h>
10 using namespace yazpp_1;
12 Z_Server::Z_Server(IPDU_Observable *the_PDU_Observable)
13 : Z_Assoc(the_PDU_Observable)
23 void Z_Server::facility_reset ()
25 Z_Server_Facility_Info *p = m_facilities;
28 Z_Server_Facility_Info *p_next = p->m_next;
37 void Z_Server::facility_add(IServer_Facility *facility,
40 Z_Server_Facility_Info **p = &m_facilities;
44 *p = new Z_Server_Facility_Info;
47 (*p)->m_name = new char [strlen(name)+1];
48 strcpy ((*p)->m_name, name);
49 (*p)->m_facility = facility;
52 void Z_Server::recv_GDU (Z_GDU *apdu, int len)
54 if (apdu->which == Z_GDU_Z3950)
55 recv_Z_PDU(apdu->u.z3950, len);
60 void Z_Server::recv_Z_PDU (Z_APDU *apdu_request, int len)
62 Z_Server_Facility_Info *f = m_facilities;
64 if (apdu_request->which == Z_APDU_initRequest)
66 Z_APDU *apdu_response = create_Z_PDU(Z_APDU_initResponse);
68 Z_InitRequest *req = apdu_request->u.initRequest;
69 Z_InitResponse *resp = apdu_response->u.initResponse;
71 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_1))
73 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_1);
75 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_2))
77 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_2);
79 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_3))
81 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_3);
85 f->m_facility->init(this, req, resp);
88 transfer_referenceId(apdu_request, apdu_response);
89 send_Z_PDU(apdu_response, 0);
97 taken = f->m_facility->recv(this, apdu_request);
104 yaz_log (YLOG_WARN, "unhandled request = %d", apdu_request->which);
113 void Z_ServerUtility::create_databaseRecord (
114 ODR odr, Z_NamePlusRecord *rec, const char *dbname, const Odr_oid *format,
115 const void *buf, int len)
117 Odr_oid *oid = odr_oiddup(odr, format);
118 rec->databaseName = dbname ? odr_strdup (odr, dbname) : 0;
119 rec->which = Z_NamePlusRecord_databaseRecord;
120 rec->u.databaseRecord = z_ext_record_oid(odr, oid,
121 (const char *) buf, len);
125 * surrogate diagnostic.
127 void Z_ServerUtility::create_surrogateDiagnostics(
128 ODR odr, Z_NamePlusRecord *rec, const char *dbname,
129 int error, char *const addinfo)
131 int *err = (int *)odr_malloc (odr, sizeof(*err));
132 Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (odr, sizeof(*drec));
133 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
134 odr_malloc (odr, sizeof(*dr));
136 yaz_log(YLOG_DEBUG, "SurrogateDiagnotic: %d -- %s", error, addinfo);
138 rec->databaseName = dbname ? odr_strdup (odr, dbname) : 0;
139 rec->which = Z_NamePlusRecord_surrogateDiagnostic;
140 rec->u.surrogateDiagnostic = drec;
141 drec->which = Z_DiagRec_defaultFormat;
142 drec->u.defaultFormat = dr;
143 dr->diagnosticSetId = odr_oiddup(odr, yaz_oid_diagset_bib_1);
146 dr->which = Z_DefaultDiagFormat_v2Addinfo;
147 dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : "");
150 Z_Records *Z_ServerUtility::create_nonSurrogateDiagnostics (
151 ODR odr, int error, const char *addinfo)
153 Z_Records *rec = (Z_Records *)
154 odr_malloc (odr, sizeof(*rec));
156 odr_malloc (odr, sizeof(*err));
157 Z_DiagRec *drec = (Z_DiagRec *)
158 odr_malloc (odr, sizeof(*drec));
159 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
160 odr_malloc (odr, sizeof(*dr));
163 rec->which = Z_Records_NSD;
164 rec->u.nonSurrogateDiagnostic = dr;
165 dr->diagnosticSetId = odr_oiddup(odr, yaz_oid_diagset_bib_1);
168 dr->which = Z_DefaultDiagFormat_v2Addinfo;
169 dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : "");
173 void Z_ServerUtility::create_diagnostics (
174 ODR odr, int error, const char *addinfo,
175 Z_DiagRec ***dreca, int *num)
177 Z_DiagRec *drec = (Z_DiagRec *) odr_malloc (odr, sizeof(*drec));
178 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
179 odr_malloc (odr, sizeof(*dr));
182 *dreca = (Z_DiagRec **) odr_malloc (odr, sizeof(*dreca));
185 drec->which = Z_DiagRec_defaultFormat;
186 drec->u.defaultFormat = dr;
187 dr->diagnosticSetId = odr_oiddup(odr, yaz_oid_diagset_bib_1);
188 dr->condition = odr_intdup (odr, error);
189 dr->which = Z_DefaultDiagFormat_v2Addinfo;
190 dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : "");
195 * indent-tabs-mode: nil
197 * vim: shiftwidth=4 tabstop=8 expandtab