C++ fixes.
[yaz-moved-to-github.git] / server / seshigh.c
index 18f604b..3a4b6b0 100644 (file)
@@ -1,9 +1,19 @@
 /*
- * Copyright (c) 1995-2000, Index Data
+ * Copyright (c) 1995-2001, Index Data
  * See the file LICENSE for details.
  *
  * $Log: seshigh.c,v $
- * Revision 1.111  2000-11-23 10:58:32  adam
+ * Revision 1.114  2001-02-21 13:46:53  adam
+ * C++ fixes.
+ *
+ * Revision 1.113  2001/01/30 21:34:17  adam
+ * Added step-size for Scan backend interface.
+ *
+ * Revision 1.112  2001/01/29 09:38:22  adam
+ * Fixed bug that made the frontend server crash when no attribute set
+ * was specified for scan.
+ *
+ * Revision 1.111  2000/11/23 10:58:32  adam
  * SSL comstack support. Separate POSIX thread support library.
  *
  * Revision 1.110  2000/10/02 13:05:32  adam
@@ -923,7 +933,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb)
     char options[100];
 
     xfree (assoc->init);
-    assoc->init = xmalloc (sizeof(*assoc->init));
+    assoc->init = (bend_initrequest *) xmalloc (sizeof(*assoc->init));
 
     yaz_log(LOG_LOG, "Got initRequest");
     if (req->implementationId)
@@ -1087,14 +1097,14 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb)
  * These functions should be merged.
  */
 
-static void set_addinfo (Z_DefaultDiagFormat *dr, char *addinfo)
+static void set_addinfo (Z_DefaultDiagFormat *dr, char *addinfo, ODR odr)
 {
 #if ASN_COMPILED
     dr->which = Z_DefaultDiagFormat_v2Addinfo;
-    dr->u.v2Addinfo = addinfo ? addinfo : "";
+    dr->u.v2Addinfo = odr_strdup (odr, addinfo ? addinfo : "");
 #else
     dr->which = Z_DiagForm_v2AddInfo;
-    dr->addinfo = addinfo ? addinfo : "";
+    dr->addinfo = odr_strdup (odr, addinfo ? addinfo : "");
 #endif
 }
 
@@ -1132,7 +1142,7 @@ static Z_Records *diagrec(association *assoc, int error, char *addinfo)
     dr->diagnosticSetId =
        odr_oiddup (assoc->encode, oid_ent_to_oid(&bib1, oid));
     dr->condition = err;
-    set_addinfo (dr, addinfo);
+    set_addinfo (dr, addinfo, assoc->encode);
     return rec;
 }
 
@@ -1165,7 +1175,7 @@ static Z_NamePlusRecord *surrogatediagrec(association *assoc, char *dbname,
     dr->diagnosticSetId = odr_oiddup (assoc->encode,
                                       oid_ent_to_oid(&bib1, oid));
     dr->condition = err;
-    set_addinfo (dr, addinfo);
+    set_addinfo (dr, addinfo, assoc->encode);
 
     return rec;
 }
@@ -1201,10 +1211,10 @@ static Z_DiagRecs *diagrecs(association *assoc, int error, char *addinfo)
 
 #ifdef ASN_COMPILED
     rec->which = Z_DefaultDiagFormat_v2Addinfo;
-    rec->u.v2Addinfo = addinfo ? addinfo : "";
+    rec->u.v2Addinfo = odr_strdup (assoc->encode, addinfo ? addinfo : "");
 #else
     rec->which = Z_DiagForm_v2AddInfo;
-    rec->addinfo = addinfo ? addinfo : "";
+    rec->addinfo = odr_strdup (assoc->encode, addinfo ? addinfo : "");
 #endif
     return recs;
 }
@@ -1610,34 +1620,6 @@ static Z_APDU *process_presentRequest(association *assoc, request *reqb,
     return apdu;
 }
 
-#if 0
-static int bend_default_scan (void *handle, bend_scan_rr *rr)
-{
-    bend_scanrequest srq;
-    bend_scanresult *srs;
-
-    srq.num_bases = rr->num_bases;
-    srq.basenames = rr->basenames;
-    srq.attributeset = rr->attributeset;
-    srq.referenceId = rr->referenceId;
-    srq.term = rr->term;
-    srq.term_position = rr->term_position;
-    srq.num_entries = rr->num_entries;
-    srq.stream = rr->stream;
-    srq.print = rr->print;
-    
-    srs = bend_scan(handle, &srq, 0);
-
-    rr->term_position = srs->term_position;
-    rr->num_entries = srs->num_entries;
-    rr->entries = srs->entries;
-    rr->status = srs->status;
-    rr->errcode = srs->errcode;
-    rr->errstring = srs->errstring;
-    return 0;
-}
-#endif
-
 /*
  * Scan was implemented rather in a hurry, and with support for only the basic
  * elements of the service in the backend API. Suggestions are welcome.
@@ -1665,7 +1647,10 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd)
     apdu->which = Z_APDU_scanResponse;
     apdu->u.scanResponse = res;
     res->referenceId = req->referenceId;
-    res->stepSize = 0;
+    res->stepSize = (int*) odr_malloc (assoc->encode, sizeof(*res->stepSize));
+    *res->stepSize = 0;
+    if (req->stepSize)
+       *res->stepSize = *req->stepSize;
     res->scanStatus = scanStatus;
     res->numberOfEntriesReturned = numberOfEntriesReturned;
     res->positionOfTerm = 0;
@@ -1700,12 +1685,13 @@ static Z_APDU *process_scanRequest(association *assoc, request *reqb, int *fd)
        bsrr->referenceId = req->referenceId;
        bsrr->stream = assoc->encode;
        bsrr->print = assoc->print;
+       bsrr->step_size = res->stepSize;
        if (!(attset = oid_getentbyoid(req->attributeSet)) ||
            attset->oclass != CLASS_RECSYN)
            bsrr->attributeset = VAL_NONE;
        else
            bsrr->attributeset = attset->value;
-       log_scan_term (req->termListAndStartPoint, attset->value);
+       log_scan_term (req->termListAndStartPoint, bsrr->attributeset);
        bsrr->term_position = req->preferredPositionInResponse ?
            *req->preferredPositionInResponse : 1;
        ((int (*)(void *, bend_scan_rr *))
@@ -1860,8 +1846,9 @@ static Z_APDU *process_deleteRequest(association *assoc, request *reqb,
     if (bdrr->num_setnames > 0)
     {
        int i;
-       bdrr->statuses = odr_malloc(assoc->encode, sizeof(*bdrr->statuses) *
-                                   bdrr->num_setnames);
+       bdrr->statuses = (int*) 
+           odr_malloc(assoc->encode, sizeof(*bdrr->statuses) *
+                      bdrr->num_setnames);
        for (i = 0; i < bdrr->num_setnames; i++)
            bdrr->statuses[i] = 0;
     }
@@ -1877,16 +1864,18 @@ static Z_APDU *process_deleteRequest(association *assoc, request *reqb,
     if (bdrr->num_setnames > 0)
     {
        int i;
-       res->deleteListStatuses = odr_malloc(assoc->encode,
-                                            sizeof(*res->deleteListStatuses));
+       res->deleteListStatuses = (Z_ListStatuses *)
+           odr_malloc(assoc->encode, sizeof(*res->deleteListStatuses));
        res->deleteListStatuses->num = bdrr->num_setnames;
        res->deleteListStatuses->elements =
-           odr_malloc (assoc->encode,
+           (Z_ListStatus **)
+           odr_malloc (assoc->encode, 
                        sizeof(*res->deleteListStatuses->elements) *
                        bdrr->num_setnames);
        for (i = 0; i<bdrr->num_setnames; i++)
        {
            res->deleteListStatuses->elements[i] =
+               (Z_ListStatus *)
                odr_malloc (assoc->encode,
                            sizeof(**res->deleteListStatuses->elements));
            res->deleteListStatuses->elements[i]->status = bdrr->statuses+i;