2 * Copyright (c) 2000-2003, Index Data.
3 * See the file LICENSE for details.
5 * $Id: yaz-z-server.cpp,v 1.19 2004-11-30 21:10:31 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_GDU (Z_GDU *apdu, int len)
53 if (apdu->which == Z_GDU_Z3950)
54 recv_Z_PDU(apdu->u.z3950, len);
59 void Yaz_Z_Server::recv_Z_PDU (Z_APDU *apdu_request, int len)
61 Yaz_Z_Server_Facility_Info *f = m_facilities;
63 if (apdu_request->which == Z_APDU_initRequest)
65 Z_APDU *apdu_response = create_Z_PDU(Z_APDU_initResponse);
67 Z_InitRequest *req = apdu_request->u.initRequest;
68 Z_InitResponse *resp = apdu_response->u.initResponse;
70 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_1))
72 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_1);
74 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_2))
76 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_2);
78 if (ODR_MASK_GET(req->protocolVersion, Z_ProtocolVersion_3))
80 ODR_MASK_SET(resp->protocolVersion, Z_ProtocolVersion_3);
84 f->m_facility->init(this, req, resp);
87 transfer_referenceId(apdu_request, apdu_response);
88 send_Z_PDU(apdu_response, 0);
96 taken = f->m_facility->recv(this, apdu_request);
103 yaz_log (YLOG_WARN, "unhandled request = %d", apdu_request->which);
112 void Yaz_Z_ServerUtility::create_databaseRecord (
113 ODR odr, Z_NamePlusRecord *rec, const char *dbname, int format,
114 const void *buf, int len)
116 rec->databaseName = dbname ? odr_strdup (odr, dbname) : 0;
117 rec->which = Z_NamePlusRecord_databaseRecord;
118 rec->u.databaseRecord = z_ext_record (odr, format,
119 (const char *) buf, len);
123 * surrogate diagnostic.
125 void Yaz_Z_ServerUtility::create_surrogateDiagnostics(
126 ODR odr, Z_NamePlusRecord *rec, const char *dbname,
127 int error, char *const addinfo)
129 int *err = (int *)odr_malloc (odr, sizeof(*err));
130 Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (odr, sizeof(*drec));
131 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
132 odr_malloc (odr, sizeof(*dr));
134 yaz_log(YLOG_DEBUG, "SurrogateDiagnotic: %d -- %s", error, addinfo);
136 rec->databaseName = dbname ? odr_strdup (odr, dbname) : 0;
137 rec->which = Z_NamePlusRecord_surrogateDiagnostic;
138 rec->u.surrogateDiagnostic = drec;
139 drec->which = Z_DiagRec_defaultFormat;
140 drec->u.defaultFormat = dr;
141 dr->diagnosticSetId =
142 yaz_oidval_to_z3950oid (odr, CLASS_DIAGSET, VAL_BIB1);
145 dr->which = Z_DefaultDiagFormat_v2Addinfo;
146 dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : "");
149 Z_Records *Yaz_Z_ServerUtility::create_nonSurrogateDiagnostics (
150 ODR odr, int error, const char *addinfo)
152 Z_Records *rec = (Z_Records *)
153 odr_malloc (odr, sizeof(*rec));
155 odr_malloc (odr, sizeof(*err));
156 Z_DiagRec *drec = (Z_DiagRec *)
157 odr_malloc (odr, sizeof(*drec));
158 Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
159 odr_malloc (odr, sizeof(*dr));
162 rec->which = Z_Records_NSD;
163 rec->u.nonSurrogateDiagnostic = dr;
164 dr->diagnosticSetId =
165 yaz_oidval_to_z3950oid (odr, CLASS_DIAGSET, VAL_BIB1);
168 dr->which = Z_DefaultDiagFormat_v2Addinfo;
169 dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : "");
173 void Yaz_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 =
188 yaz_oidval_to_z3950oid (odr, CLASS_DIAGSET, VAL_BIB1);
189 dr->condition = odr_intdup (odr, error);
190 dr->which = Z_DefaultDiagFormat_v2Addinfo;
191 dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : "");