2 * Copyright (c) 2000-2001, Index Data.
3 * See the file LICENSE for details.
5 * $Id: yaz-z-server.cpp,v 1.15 2002-10-09 12:50:26 adam Exp $
9 #include <yaz++/z-server.h>
11 Yaz_Z_Server::Yaz_Z_Server(IYaz_PDU_Observable *the_PDU_Observable)
12 : Yaz_Z_Assoc(the_PDU_Observable)
17 Yaz_Z_Server::~Yaz_Z_Server()
22 void Yaz_Z_Server::facility_reset ()
24 Yaz_Z_Server_Facility_Info *p = m_facilities;
27 Yaz_Z_Server_Facility_Info *p_next = p->m_next;
36 void Yaz_Z_Server::facility_add(IYaz_Server_Facility *facility,
39 Yaz_Z_Server_Facility_Info **p = &m_facilities;
43 *p = new Yaz_Z_Server_Facility_Info;
46 (*p)->m_name = new char [strlen(name)+1];
47 strcpy ((*p)->m_name, name);
48 (*p)->m_facility = facility;
51 void Yaz_Z_Server::recv_Z_PDU (Z_APDU *apdu_request)
53 Yaz_Z_Server_Facility_Info *f = m_facilities;
55 if (apdu_request->which == Z_APDU_initRequest)
57 Z_APDU *apdu_response = create_Z_PDU(Z_APDU_initResponse);
59 Z_InitRequest *req = apdu_request->u.initRequest;
60 Z_InitResponse *resp = apdu_response->u.initResponse;
62 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_1))
64 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_1);
66 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_2))
68 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_2);
70 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_3))
72 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_3);
76 f->m_facility->init(this, req, resp);
79 transfer_referenceId(apdu_request, apdu_response);
80 send_Z_PDU(apdu_response);
88 taken = f->m_facility->recv(this, apdu_request);
95 yaz_log (LOG_WARN, "unhandled request = %d", apdu_request->which);
104 void Yaz_Z_ServerUtility::create_databaseRecord (
105 ODR odr, Z_NamePlusRecord *rec, const char *dbname, int format,
106 const void *buf, int len)
108 rec->databaseName = dbname ? odr_strdup (odr, dbname) : 0;
109 rec->which = Z_NamePlusRecord_databaseRecord;
110 rec->u.databaseRecord = z_ext_record (odr, format,
111 (const char *) buf, len);
115 * surrogate diagnostic.
117 void Yaz_Z_ServerUtility::create_surrogateDiagnostics(
118 ODR odr, Z_NamePlusRecord *rec, const char *dbname,
119 int error, char *const addinfo)
121 int *err = (int *)odr_malloc (odr, sizeof(*err));
122 Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (odr, sizeof(*drec));
123 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
124 odr_malloc (odr, sizeof(*dr));
126 yaz_log(LOG_DEBUG, "SurrogateDiagnotic: %d -- %s", error, addinfo);
128 rec->databaseName = dbname ? odr_strdup (odr, dbname) : 0;
129 rec->which = Z_NamePlusRecord_surrogateDiagnostic;
130 rec->u.surrogateDiagnostic = drec;
131 drec->which = Z_DiagRec_defaultFormat;
132 drec->u.defaultFormat = dr;
133 dr->diagnosticSetId =
134 yaz_oidval_to_z3950oid (odr, CLASS_DIAGSET, VAL_BIB1);
137 dr->which = Z_DefaultDiagFormat_v2Addinfo;
138 dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : "");
141 Z_Records *Yaz_Z_ServerUtility::create_nonSurrogateDiagnostics (
142 ODR odr, int error, const char *addinfo)
144 Z_Records *rec = (Z_Records *)
145 odr_malloc (odr, sizeof(*rec));
147 odr_malloc (odr, sizeof(*err));
148 Z_DiagRec *drec = (Z_DiagRec *)
149 odr_malloc (odr, sizeof(*drec));
150 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
151 odr_malloc (odr, sizeof(*dr));
154 rec->which = Z_Records_NSD;
155 rec->u.nonSurrogateDiagnostic = dr;
156 dr->diagnosticSetId =
157 yaz_oidval_to_z3950oid (odr, CLASS_DIAGSET, VAL_BIB1);
160 dr->which = Z_DefaultDiagFormat_v2Addinfo;
161 dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : "");
165 void Yaz_Z_ServerUtility::create_diagnostics (
166 ODR odr, int error, const char *addinfo,
167 Z_DiagRec ***dreca, int *num)
169 Z_DiagRec *drec = (Z_DiagRec *) odr_malloc (odr, sizeof(*drec));
170 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
171 odr_malloc (odr, sizeof(*dr));
174 *dreca = (Z_DiagRec **) odr_malloc (odr, sizeof(*dreca));
177 drec->which = Z_DiagRec_defaultFormat;
178 drec->u.defaultFormat = dr;
179 dr->diagnosticSetId =
180 yaz_oidval_to_z3950oid (odr, CLASS_DIAGSET, VAL_BIB1);
181 dr->condition = odr_intdup (odr, error);
182 dr->which = Z_DefaultDiagFormat_v2Addinfo;
183 dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : "");