Added a warning (always to stderr) when opening the log file fails
[yaz-moved-to-github.git] / src / seshigh.c
index 2bd951f..025b16f 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2004, Index Data
  * See the file LICENSE for details.
  *
- * $Id: seshigh.c,v 1.36 2004-11-18 15:18:13 heikki Exp $
+ * $Id: seshigh.c,v 1.42 2004-12-30 00:25:33 adam Exp $
  */
 /**
  * \file seshigh.c
@@ -50,7 +50,7 @@
 #include "session.h"
 #include <yaz/proto.h>
 #include <yaz/oid.h>
-#include <yaz/ylog.h>
+#include <yaz/log.h>
 #include <yaz/logrpn.h>
 #include <yaz/statserv.h>
 #include <yaz/diagbib1.h>
@@ -68,7 +68,8 @@ void backend_response(IOCHAN i, int event);
 static int process_gdu_response(association *assoc, request *req, Z_GDU *res);
 static int process_z_response(association *assoc, request *req, Z_APDU *res);
 static Z_APDU *process_initRequest(association *assoc, request *reqb);
-static Z_External *init_diagnostics(ODR odr, int errcode, char *errstring);
+static Z_External *init_diagnostics(ODR odr, int errcode,
+                                   const char *errstring);
 static Z_APDU *process_searchRequest(association *assoc, request *reqb,
     int *fd);
 static Z_APDU *response_searchRequest(association *assoc, request *reqb,
@@ -106,6 +107,14 @@ static void get_logbits()
     }
 }
 
+static void wr_diag(WRBUF w, int error, const char *addinfo)
+{
+    wrbuf_printf(w, "ERROR [%d] %s%s%s",
+                error, diagbib1_str(error),
+                addinfo ? "--" : "", addinfo ? addinfo : "");
+}
+
+
 /*
  * Create and initialize a new association-handle.
  *  channel  : iochannel for the current line.
@@ -162,7 +171,7 @@ association *create_association(IOCHAN channel, COMSTACK link)
             }
             else 
             {
-                sprintf(filename + strlen(filename), ".%d", getpid());
+                sprintf(filename + strlen(filename), ".%ld", (long)getpid());
                 if (!(f = fopen(filename, "w")))
                 {
                     yaz_log(YLOG_WARN|YLOG_ERRNO, "%s", filename);
@@ -287,7 +296,6 @@ void ir_session(IOCHAN h, int event)
     }
     if (event & assoc->cs_accept_mask)
     {
-        yaz_log (log_session, "ir_session (accept)");
         if (!cs_accept (conn))
         {
             yaz_log (YLOG_WARN, "accept failed");
@@ -618,7 +626,8 @@ static void srw_bend_search(association *assoc, request *req,
     int srw_error = 0;
     bend_search_rr rr;
     Z_External *ext;
-    char *querystr="";
+    const char *querystr = 0;
+    const char *querytype = 0;
     
     *http_code = 200;
     yaz_log(log_requestdetail, "Got SRW SearchRetrieveRequest");
@@ -632,7 +641,7 @@ static void srw_bend_search(association *assoc, request *req,
 
             yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
                                    &srw_res->num_diagnostics, 1, 0);
-            yaz_log(log_request,"Search SRW: backend init failed");
+            yaz_log(log_request, "Search SRW: backend init failed");
             return;
         }
     }
@@ -654,7 +663,8 @@ static void srw_bend_search(association *assoc, request *req,
         ext->descriptor = 0;
         ext->which = Z_External_CQL;
         ext->u.cql = srw_req->query.cql;
-        querystr=srw_req->query.cql;
+        querystr = srw_req->query.cql;
+       querytype = "CQL";
 
         rr.query->which = Z_Query_type_104;
         rr.query->u.type_104 =  ext;
@@ -666,7 +676,8 @@ static void srw_bend_search(association *assoc, request *req,
 
         pqf_parser = yaz_pqf_create ();
 
-        querystr=srw_req->query.pqf;
+        querystr = srw_req->query.pqf;
+       querytype = "PQF";
         RPNquery = yaz_pqf_parse (pqf_parser, assoc->decode,
                                   srw_req->query.pqf);
         if (!RPNquery)
@@ -697,11 +708,11 @@ static void srw_bend_search(association *assoc, request *req,
     {
         if (log_request)
         {
-            WRBUF wr=wrbuf_alloc();
-            wrbuf_printf(wr, "Search: SRW: %s ",querystr);
-            wrbuf_printf(wr," ERROR %d ", srw_error);
-            yaz_log(log_request, "Search %s", wrbuf_buf(wr) );
-            wrbuf_free(wr,1);
+            WRBUF wr = wrbuf_alloc();
+            wrbuf_printf(wr, "Search: %s: %s ", querytype, querystr);
+            wrbuf_printf(wr, " ERROR %d ", srw_error);
+            yaz_log(log_request, "%s", wrbuf_buf(wr) );
+            wrbuf_free(wr, 1);
         }
         srw_res->num_diagnostics = 1;
         srw_res->diagnostics = (Z_SRW_diagnostic *)
@@ -726,20 +737,19 @@ static void srw_bend_search(association *assoc, request *req,
     (assoc->init->bend_search)(assoc->backend, &rr);
     if (rr.errcode)
     {
-        yaz_log(log_request, "bend_search returned Bib-1 code %d", rr.errcode);
+        yaz_log(log_request, "bend_search returned Bib-1 diagnostic %d",
+               rr.errcode);
         if (rr.errcode == 109) /* database unavailable */
         {
             *http_code = 404;
             return;
         }
+       srw_error = yaz_diag_bib1_to_srw (rr.errcode);
         srw_res->num_diagnostics = 1;
         srw_res->diagnostics = (Z_SRW_diagnostic *)
             odr_malloc(assoc->encode, sizeof(*srw_res->diagnostics));
         yaz_mk_std_diagnostic(assoc->encode, srw_res->diagnostics,
-                              yaz_diag_bib1_to_srw (rr.errcode),
-                              rr.errstring);
-        yaz_log(log_request, "srw_bend_search returned SRW error %s",
-                srw_res->diagnostics[0].uri);
+                             srw_error, rr.errstring);
     }
     else
     {
@@ -809,17 +819,17 @@ static void srw_bend_search(association *assoc, request *req,
     if (log_request)
     {
         WRBUF wr=wrbuf_alloc();
-        wrbuf_printf(wr,"SRW: %s",querystr );
+        wrbuf_printf(wr,"Search %s: %s", querytype, querystr);
         if (srw_error)
-            wrbuf_printf(wr," ERROR %d ", srw_error);
+            wrbuf_printf(wr, " ERROR %d", srw_error);
         else
         {
-            wrbuf_printf(wr," OK:%d hits ",rr.hits);
+            wrbuf_printf(wr, " OK:%d hits", rr.hits);
             if (srw_res->num_records)
-                wrbuf_printf(wr," Returned %d records", srw_res->num_records);
+                wrbuf_printf(wr, " %d records returned", srw_res->num_records);
         }
-        yaz_log(log_request, "Search %s", wrbuf_buf(wr) );
-        wrbuf_free(wr,1);
+        yaz_log(log_request, "%s", wrbuf_buf(wr) );
+        wrbuf_free(wr, 1);
     }
 }
 
@@ -1023,7 +1033,7 @@ static void process_http_request(association *assoc, request *req)
         int t;
         const char *alive = z_HTTP_header_lookup(hreq->headers, "Keep-Alive");
 
-        if (alive && isdigit(*alive))
+        if (alive && isdigit(*(const unsigned char *) alive))
             t = atoi(alive);
         else
             t = 15;
@@ -1220,7 +1230,6 @@ static int process_gdu_response(association *assoc, request *req, Z_GDU *res)
         yaz_log(YLOG_WARN, "ODR error when encoding PDU: %s [element %s]",
                 odr_errmsg(odr_geterror(assoc->decode)),
                 odr_getelement(assoc->decode));
-        request_release(req);
         return -1;
     }
     req->response = odr_getbuf(assoc->encode, &req->len_response,
@@ -1420,7 +1429,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb)
                 assoc->init->implementation_name,
                 odr_prepend(assoc->encode, "GFS", resp->implementationName));
 
-    version = odr_strdup(assoc->encode, "$Revision: 1.36 $");
+    version = odr_strdup(assoc->encode, "$Revision: 1.42 $");
     if (strlen(version) > 10)   /* check for unexpanded CVS strings */
         version[strlen(version)-2] = '\0';
     resp->implementationVersion = odr_prepend(assoc->encode,
@@ -1430,105 +1439,43 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb)
 
     if (binitres->errcode)
     {
-        yaz_log(YLOG_DEBUG, "Connection rejected by backend.");
+       WRBUF wr = wrbuf_alloc();
         *resp->result = 0;
         assoc->state = ASSOC_DEAD;
-        resp->userInformationField = init_diagnostics(assoc->encode,
-                                                      binitres->errcode,
-                                                      binitres->errstring);
-        yaz_log(log_request,"Init from '%s' (%s) (ver %s) Error %d %s",
-            req->implementationName ? req->implementationName :"??",
-            req->implementationId ? req->implementationId :"?", 
-            req->implementationVersion ? req->implementationVersion: "?",
-            binitres->errcode,binitres->errstring );
+        resp->userInformationField =
+           init_diagnostics(assoc->encode, binitres->errcode,
+                            binitres->errstring);
+       wr_diag(wr, binitres->errcode, binitres->errstring);
+        yaz_log(log_request, "Init from '%s' (%s) (ver %s) %s",
+               req->implementationName ? req->implementationName :"??",
+               req->implementationId ? req->implementationId :"?", 
+               req->implementationVersion ? req->implementationVersion: "?",
+               wrbuf_buf(wr));
+       wrbuf_free(wr, 1);
     }
     else
     {
         assoc->state = ASSOC_UP;
-        yaz_log(log_request,"Init from '%s' (%s) (ver %s) OK",
-            req->implementationName ? req->implementationName :"??",
-            req->implementationId ? req->implementationId :"?", 
-            req->implementationVersion ? req->implementationVersion: "?");
+        yaz_log(log_request, "Init from '%s' (%s) (ver %s) OK",
+               req->implementationName ? req->implementationName :"??",
+               req->implementationId ? req->implementationId :"?", 
+               req->implementationVersion ? req->implementationVersion: "?");
     }
 
     return apdu;
 }
 
 /*
- * Diagnostic in default format, to be returned as either a surrogate
- * or non-surrogate diagnostic in the context of an open session, or
- * as User-information when an Init is refused.
- */
-static Z_DefaultDiagFormat *justdiag(ODR odr, int error, char *addinfo)
-{
-    int *err = odr_intdup(odr, error);
-    Z_DefaultDiagFormat *dr = (Z_DefaultDiagFormat *)
-        odr_malloc (odr, sizeof(*dr));
-
-    yaz_log(log_requestdetail, "[%d] %s%s%s", error, diagbib1_str(error),
-        addinfo ? " -- " : "", addinfo ? addinfo : "");
-
-    dr->diagnosticSetId =
-        yaz_oidval_to_z3950oid (odr, CLASS_DIAGSET, VAL_BIB1);
-    dr->condition = err;
-    dr->which = Z_DefaultDiagFormat_v2Addinfo;
-    dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : "");
-    return dr;
-}
-
-/*
  * Set the specified `errcode' and `errstring' into a UserInfo-1
  * external to be returned to the client in accordance with Z35.90
  * Implementor Agreement 5 (Returning diagnostics in an InitResponse):
  *      http://lcweb.loc.gov/z3950/agency/agree/initdiag.html
  */
-static Z_External *init_diagnostics(ODR odr, int error, char *addinfo)
+static Z_External *init_diagnostics(ODR odr, int error, const char *addinfo)
 {
-    Z_External *x, *x2;
-    oident oid;
-    Z_OtherInformation *u;
-    Z_OtherInformationUnit *l;
-    Z_DiagnosticFormat *d;
-    Z_DiagnosticFormat_s *e;
-
-    x = (Z_External*) odr_malloc(odr, sizeof *x);
-    x->descriptor = 0;
-    x->indirect_reference = 0;  
-    oid.proto = PROTO_Z3950;
-    oid.oclass = CLASS_USERINFO;
-    oid.value = VAL_USERINFO1;
-    x->direct_reference = odr_oiddup(odr, oid_getoidbyent(&oid));
-    x->which = Z_External_userInfo1;
-
-    u = odr_malloc(odr, sizeof *u);
-    x->u.userInfo1 = u;
-    u->num_elements = 1;
-    u->list = (Z_OtherInformationUnit**) odr_malloc(odr, sizeof *u->list);
-    u->list[0] = (Z_OtherInformationUnit*) odr_malloc(odr, sizeof *u->list[0]);
-    l = u->list[0];
-    l->category = 0;
-    l->which = Z_OtherInfo_externallyDefinedInfo;
-
-    x2 = (Z_External*) odr_malloc(odr, sizeof *x);
-    l->information.externallyDefinedInfo = x2;
-    x2->descriptor = 0;
-    x2->indirect_reference = 0;
-    oid.oclass = CLASS_DIAGSET;
-    oid.value = VAL_DIAG1;
-    x2->direct_reference = odr_oiddup(odr, oid_getoidbyent(&oid));
-    x2->which = Z_External_diag1;
-
-    d = (Z_DiagnosticFormat*) odr_malloc(odr, sizeof *d);
-    x2->u.diag1 = d;
-    d->num = 1;
-    d->elements = (Z_DiagnosticFormat_s**) odr_malloc (odr, sizeof *d->elements);
-    d->elements[0] = (Z_DiagnosticFormat_s*) odr_malloc (odr, sizeof *d->elements[0]);
-    e = d->elements[0];
-
-    e->which = Z_DiagnosticFormat_s_defaultDiagRec;
-    e->u.defaultDiagRec = justdiag(odr, error, addinfo);
-    e->message = 0;
-    return x;
+    yaz_log(log_requestdetail, "[%d] %s%s%s", error, diagbib1_str(error),
+        addinfo ? " -- " : "", addinfo ? addinfo : "");
+    return zget_init_diagnostics(odr, error, addinfo);
 }
 
 /*
@@ -1536,60 +1483,27 @@ static Z_External *init_diagnostics(ODR odr, int error, char *addinfo)
  */
 static Z_Records *diagrec(association *assoc, int error, char *addinfo)
 {
-    Z_Records *rec = (Z_Records *)
-        odr_malloc (assoc->encode, sizeof(*rec));
-    rec->which = Z_Records_NSD;
-    rec->u.nonSurrogateDiagnostic = justdiag(assoc->encode, error, addinfo);
-    return rec;
-}
+    Z_Records *rec = (Z_Records *) odr_malloc (assoc->encode, sizeof(*rec));
 
-/*
- * surrogate diagnostic.
- */
-static Z_NamePlusRecord *surrogatediagrec(association *assoc, char *dbname,
-                                          int error, char *addinfo)
-{
-    Z_NamePlusRecord *rec = (Z_NamePlusRecord *)
-        odr_malloc (assoc->encode, sizeof(*rec));
-    Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (assoc->encode, sizeof(*drec));
-    
-    yaz_log(YLOG_DEBUG, "SurrogateDiagnotic: %d -- %s", error, addinfo);
-    rec->databaseName = dbname;
-    rec->which = Z_NamePlusRecord_surrogateDiagnostic;
-    rec->u.surrogateDiagnostic = drec;
-    drec->which = Z_DiagRec_defaultFormat;
-    drec->u.defaultFormat = justdiag(assoc->encode, error, addinfo);
+    yaz_log(log_requestdetail, "[%d] %s%s%s", error, diagbib1_str(error),
+           addinfo ? " -- " : "", addinfo ? addinfo : "");
 
+    rec->which = Z_Records_NSD;
+    rec->u.nonSurrogateDiagnostic = zget_DefaultDiagFormat(assoc->encode,
+                                                          error, addinfo);
     return rec;
 }
 
 /*
- * multiple nonsurrogate diagnostics.
+ * surrogate diagnostic.
  */
-static Z_DiagRecs *diagrecs(association *assoc, int error, char *addinfo)
+static Z_NamePlusRecord *surrogatediagrec(association *assoc, 
+                                         const char *dbname,
+                                          int error, const char *addinfo)
 {
-    Z_DiagRecs *recs = (Z_DiagRecs *)odr_malloc (assoc->encode, sizeof(*recs));
-    int *err = odr_intdup(assoc->encode, error);
-    Z_DiagRec **recp = (Z_DiagRec **)odr_malloc (assoc->encode, sizeof(*recp));
-    Z_DiagRec *drec = (Z_DiagRec *)odr_malloc (assoc->encode, sizeof(*drec));
-    Z_DefaultDiagFormat *rec = (Z_DefaultDiagFormat *)
-        odr_malloc (assoc->encode, sizeof(*rec));
-
-    yaz_log(YLOG_DEBUG, "DiagRecs: %d -- %s", error, addinfo ? addinfo : "");
-
-    recs->num_diagRecs = 1;
-    recs->diagRecs = recp;
-    recp[0] = drec;
-    drec->which = Z_DiagRec_defaultFormat;
-    drec->u.defaultFormat = rec;
-
-    rec->diagnosticSetId =
-        yaz_oidval_to_z3950oid (assoc->encode, CLASS_DIAGSET, VAL_BIB1);
-    rec->condition = err;
-
-    rec->which = Z_DefaultDiagFormat_v2Addinfo;
-    rec->u.v2Addinfo = odr_strdup (assoc->encode, addinfo ? addinfo : "");
-    return recs;
+    yaz_log(log_requestdetail, "[%d] %s%s%s", error, diagbib1_str(error),
+           addinfo ? " -- " : "", addinfo ? addinfo : "");
+    return zget_surrogateDiagRec(assoc->encode, dbname, error, addinfo);
 }
 
 static Z_Records *pack_records(association *a, char *setname, int start,
@@ -1606,7 +1520,6 @@ static Z_Records *pack_records(association *a, char *setname, int start,
     Z_NamePlusRecord **list =
         (Z_NamePlusRecord **) odr_malloc (a->encode, sizeof(*list) * toget);
 
-    *errcode=0;
     records->which = Z_Records_DBOSD;
     records->u.databaseOrSurDiagnostics = reclist;
     reclist->num_records = 0;
@@ -1664,7 +1577,7 @@ static Z_Records *pack_records(association *a, char *setname, int start,
                     freq.errstring = s;
                 }
                 if (errcode)
-                    *errcode=freq.errcode;
+                    *errcode = freq.errcode;
                 return diagrec(a, freq.errcode, freq.errstring);
             }
             reclist->records[reclist->num_records] =
@@ -1878,12 +1791,12 @@ static Z_APDU *response_searchRequest(association *assoc, request *reqb,
             else
                 form = prefformat->value;
             resp->records = pack_records(assoc, req->resultSetName, 1,
-                toget, compp, next, presst, form, req->referenceId,
-                               req->preferredRecordSyntax, NULL);
+                                        toget, compp, next, presst, form, req->referenceId,
+                                        req->preferredRecordSyntax, NULL);
             if (!resp->records)
                 return 0;
             resp->numberOfRecordsReturned = toget;
-            returnedrecs=*toget;
+            returnedrecs = *toget;
             resp->nextResultSetPosition = next;
             resp->searchStatus = sr;
             resp->resultSetStatus = 0;
@@ -1907,14 +1820,15 @@ static Z_APDU *response_searchRequest(association *assoc, request *reqb,
         WRBUF wr=wrbuf_alloc();
         wrbuf_put_zquery(wr, req->query);
         if (bsrt->errcode)
-            wrbuf_printf(wr," ERROR %d %s", bsrt->errcode, bsrt->errstring);
+           wr_diag(wr, bsrt->errcode, bsrt->errstring);
         else
         {
-            wrbuf_printf(wr," OK:%d hits ",bsrt->hits);
+            wrbuf_printf(wr," OK:%d hits", bsrt->hits);
             if (returnedrecs)
-                wrbuf_printf(wr," Returned %d records", returnedrecs);
+                wrbuf_printf(wr, " %d records returned", returnedrecs);
         }
-        yaz_log(log_request, "Search %s", wrbuf_buf(wr) );
+        yaz_log(log_request, "Search %s %s", req->resultSetName,
+               wrbuf_buf(wr));
         wrbuf_free(wr,1);
     }
     return apdu;
@@ -1945,7 +1859,8 @@ static Z_APDU *process_presentRequest(association *assoc, request *reqb,
     Z_PresentResponse *resp;
     int *next;
     int *num;
-    int errcode=0;
+    int errcode = 0;
+    const char *errstring = 0;
 
     yaz_log(log_requestdetail, "Got PresentRequest.");
 
@@ -1980,7 +1895,8 @@ static Z_APDU *process_presentRequest(association *assoc, request *reqb,
         {
             resp->records = diagrec(assoc, bprr->errcode, bprr->errstring);
             *resp->presentStatus = Z_PresentStatus_failure;
-            errcode=bprr->errcode;
+            errcode = bprr->errcode;
+           errstring = bprr->errstring;
         }
     }
     apdu = (Z_APDU *)odr_malloc (assoc->encode, sizeof(*apdu));
@@ -1997,32 +1913,31 @@ static Z_APDU *process_presentRequest(association *assoc, request *reqb,
         *num = *req->numberOfRecordsRequested;
         resp->records =
             pack_records(assoc, req->resultSetId, *req->resultSetStartPoint,
-                     num, req->recordComposition, next, resp->presentStatus,
+                        num, req->recordComposition, next,
+                        resp->presentStatus,
                          form, req->referenceId, req->preferredRecordSyntax, 
                          &errcode);
     }
-    if (!resp->records)
-        return 0;
-    resp->numberOfRecordsReturned = num;
-    resp->nextResultSetPosition = next;
     if (log_request)
     {
-        WRBUF wr=wrbuf_alloc();
-        wrbuf_printf(wr, "Present: [%s] %d+%d ",
+        WRBUF wr = wrbuf_alloc();
+        wrbuf_printf(wr, "Present %s %d+%d ",
                 req->resultSetId, *req->resultSetStartPoint,
                 *req->numberOfRecordsRequested);
         if (*resp->presentStatus == Z_PresentStatus_failure)
-        {
-            wrbuf_printf(wr," ERROR %d ", errcode);
-        }
+           wr_diag(wr, errcode, errstring);
         else if (*resp->presentStatus == Z_PresentStatus_success)
-            wrbuf_printf(wr," OK %d records returned ", *num);
+            wrbuf_printf(wr,"OK %d records returned ", *num);
         else
-            wrbuf_printf(wr," Partial (%d) OK %d records returned ", 
+            wrbuf_printf(wr,"Partial (%d) OK %d records returned ", 
                     *resp->presentStatus, *num);
         yaz_log(log_request, "%s", wrbuf_buf(wr) );
-        wrbuf_free(wr,1);
+        wrbuf_free(wr, 1);
     }
+    if (!resp->records)
+        return 0;
+    resp->numberOfRecordsReturned = num;
+    resp->nextResultSetPosition = next;
     
     return apdu;
 }
@@ -2123,7 +2038,8 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd)
      (*assoc->init->bend_scan))(assoc->backend, bsrr);
 
     if (bsrr->errcode)
-        diagrecs_p = diagrecs(assoc, bsrr->errcode, bsrr->errstring);
+        diagrecs_p = zget_DiagRecs(assoc->encode,
+                                  bsrr->errcode, bsrr->errstring);
     else
     {
         int i;
@@ -2180,9 +2096,9 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd)
             }
             else
             {
-                Z_DiagRecs *drecs = diagrecs (assoc,
-                                              bsrr->entries[i].errcode,
-                                              bsrr->entries[i].errstring);
+                Z_DiagRecs *drecs = zget_DiagRecs(assoc->encode,
+                                                 bsrr->entries[i].errcode,
+                                                 bsrr->entries[i].errstring);
                 assert (drecs->num_diagRecs == 1);
                 e->which = Z_Entry_surrogateDiagnostic;
                 assert (drecs->diagRecs[0]);
@@ -2257,7 +2173,8 @@ static Z_APDU *process_sortRequest(association *assoc, request *reqb,
     res->resultSetStatus = 0;
     if (bsrr->errcode)
     {
-        Z_DiagRecs *dr = diagrecs (assoc, bsrr->errcode, bsrr->errstring);
+        Z_DiagRecs *dr = zget_DiagRecs(assoc->encode,
+                                      bsrr->errcode, bsrr->errstring);
         res->diagnostics = dr->diagRecs;
         res->num_diagnostics = dr->num_diagRecs;
     }
@@ -2310,7 +2227,7 @@ static Z_APDU *process_deleteRequest(association *assoc, request *reqb,
 
     bdrr->num_setnames = req->num_resultSetList;
     bdrr->setnames = req->resultSetList;
-    for (i=0;i<req->num_resultSetList;i++)
+    for (i = 0; i<req->num_resultSetList; i++)
         yaz_log(log_requestdetail, "resultset: '%s'",
                 req->resultSetList[i]);
     bdrr->stream = assoc->encode;
@@ -2353,7 +2270,6 @@ static Z_APDU *process_deleteRequest(association *assoc, request *reqb,
             res->deleteListStatuses->elements[i]->status = bdrr->statuses+i;
             res->deleteListStatuses->elements[i]->id =
                 odr_strdup (assoc->encode, bdrr->setnames[i]);
-            
         }
     }
     res->numberNotDeleted = 0;
@@ -2367,7 +2283,7 @@ static Z_APDU *process_deleteRequest(association *assoc, request *reqb,
     {
         WRBUF wr=wrbuf_alloc();
         wrbuf_printf(wr, "Delete ");
-        for (i=0;i<req->num_resultSetList;i++)
+        for (i = 0; i<req->num_resultSetList; i++)
             wrbuf_printf(wr, " '%s' ", req->resultSetList[i]);
         if (bdrr->delete_status)
             wrbuf_printf(wr," ERROR %d", bdrr->delete_status);
@@ -2532,9 +2448,9 @@ static Z_APDU *process_ESRequest(association *assoc, request *reqb, int *fd)
     }
     else
     {
-        Z_DiagRecs *diagRecs = diagrecs (assoc, esrequest.errcode,
-                                         esrequest.errstring);
-
+        Z_DiagRecs *diagRecs =
+           zget_DiagRecs(assoc->encode, esrequest.errcode,
+                         esrequest.errstring);
         /* Backend indicates error, request will not be processed */
         yaz_log(YLOG_DEBUG,"Request could not be processed...failure !");
         *resp->operationStatus = Z_ExtendedServicesResponse_failure;