From: Adam Dickmeiss Date: Tue, 17 May 2005 13:00:56 +0000 (+0000) Subject: Handle present out of range better in sample server. X-Git-Tag: YAZPP.yazxf.1.4.1~5 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=5e3f7e1a720a08d30c407049c94c6ca825a5ed27;p=yazpp-moved-to-github.git Handle present out of range better in sample server. --- diff --git a/src/yaz-marc-sample.cpp b/src/yaz-marc-sample.cpp index 4af243a..a3d05ab 100644 --- a/src/yaz-marc-sample.cpp +++ b/src/yaz-marc-sample.cpp @@ -2,7 +2,7 @@ * Copyright (c) 2000-2001, Index Data. * See the file LICENSE for details. * - * $Id: yaz-marc-sample.cpp,v 1.5 2003-10-16 10:26:58 adam Exp $ + * $Id: yaz-marc-sample.cpp,v 1.6 2005-05-17 13:00:56 adam Exp $ */ #include @@ -1480,7 +1480,8 @@ static const char *marc_records[] = { const char *Yaz_USMARC::get_record(int position) { - int max = sizeof(marc_records) / sizeof(*marc_records); - int eff_pos = (position-1) % max; - return marc_records[eff_pos]; + if (position >= 1 && position <= ( + sizeof(marc_records) / sizeof(*marc_records))) + return marc_records[position-1]; + return 0; } diff --git a/src/yaz-my-server.cpp b/src/yaz-my-server.cpp index bd9d7f6..adb63de 100644 --- a/src/yaz-my-server.cpp +++ b/src/yaz-my-server.cpp @@ -2,11 +2,12 @@ * Copyright (c) 1998-2001, Index Data. * See the file LICENSE for details. * - * $Id: yaz-my-server.cpp,v 1.15 2005-01-17 09:55:58 adam Exp $ + * $Id: yaz-my-server.cpp,v 1.16 2005-05-17 13:00:56 adam Exp $ */ #include #include +#include #include #include #include @@ -127,8 +128,12 @@ void MyRetrieval::sr_record (const char *resultSetName, { yaz_log (YLOG_LOG, "MyServer::recv_Z_record"); const char *rec = get_record(position); - create_databaseRecord (odr_encode(), namePlusRecord, 0, VAL_USMARC, rec, - strlen(rec)); + if (rec) + create_databaseRecord (odr_encode(), namePlusRecord, 0, + VAL_USMARC, rec, strlen(rec)); + else + create_surrogateDiagnostics(odr_encode(), namePlusRecord, 0, + YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE, 0); } MyServer::~MyServer()