Implemented OtherInfo utility.
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 26 Apr 1999 07:25:25 +0000 (07:25 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 26 Apr 1999 07:25:25 +0000 (07:25 +0000)
include/otherinfo.h [new file with mode: 0644]
util/Makefile.in
util/otherinfo.c [new file with mode: 0644]

diff --git a/include/otherinfo.h b/include/otherinfo.h
new file mode 100644 (file)
index 0000000..538fe5f
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 1999, Index Data
+ * See the file LICENSE for details.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Id: otherinfo.h,v 1.1 1999-04-26 07:25:25 adam Exp $
+ */
+#ifndef OTHERINFO_H
+#define OTHERINFO_H
+
+#include <proto.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+YAZ_EXPORT void yaz_oi_APDU(Z_APDU *apdu, Z_OtherInformation ***oip);
+YAZ_EXPORT    Z_OtherInformationUnit *yaz_oi_update (
+    Z_OtherInformation **otherInformationP, ODR odr,
+    int *oid, int categoryValue);
+YAZ_EXPORT void yaz_oi_set_string_oid (
+    Z_OtherInformation **otherInformation, ODR odr,
+    int *oid, int categoryValue,
+    const char *str);
+YAZ_EXPORT void yaz_oi_set_string_oidval (
+    Z_OtherInformation **otherInformation, ODR odr,
+    int oidval, int categoryValue,
+    const char *str);
+YAZ_EXPORT char *yaz_oi_get_string_oid (
+    Z_OtherInformation **otherInformation,
+    int *oid, int categoryValue);
+YAZ_EXPORT char *yaz_oi_get_string_oidval(
+    Z_OtherInformation **otherInformation,
+    int oidval, int categoryValue);
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index e8d2cbb..2e9d30a 100644 (file)
@@ -1,7 +1,7 @@
 # Copyright (C) 1994-1998, Index Data
 # All rights reserved.
 # Sebastian Hammer, Adam Dickmeiss
-# $Id: Makefile.in,v 1.4 1998-11-16 16:02:34 adam Exp $
+# $Id: Makefile.in,v 1.5 1999-04-26 07:25:25 adam Exp $
 
 SHELL=/bin/sh
 
@@ -17,7 +17,7 @@ LIBDIR=../lib
 DEFS=$(INCLUDE) $(CDEFS)
 LIB=$(LIBDIR)/libutil.a
 PO = options.o log.o marcdisp.o yaz-ccl.o pquery.o oid.o wrbuf.o nmemsdup.o \
-   xmalloc.o readconf.o tpath.o nmem.o yaz-util.o atoin.o \
+   xmalloc.o readconf.o tpath.o nmem.o yaz-util.o atoin.o otherinfo.o \
    logrpn.o # dmalloc.o 
 
 all: $(LIB) marcdump
diff --git a/util/otherinfo.c b/util/otherinfo.c
new file mode 100644 (file)
index 0000000..ced403e
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 1999, Index Data
+ * See the file LICENSE for details.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: otherinfo.c,v $
+ * Revision 1.1  1999-04-26 07:25:25  adam
+ * Implemented OtherInfo utility.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <otherinfo.h>
+
+void yaz_oi_APDU(Z_APDU *apdu, Z_OtherInformation ***oip)
+{
+    switch (apdu->which)
+    {
+    case Z_APDU_initRequest:
+       *oip = &apdu->u.initRequest->otherInfo;
+       break;
+    case Z_APDU_searchRequest:
+       *oip = &apdu->u.searchRequest->otherInfo;
+       break;
+    case Z_APDU_presentRequest:
+       *oip = &apdu->u.presentRequest->otherInfo;
+       break;
+    case Z_APDU_sortRequest:
+       *oip = &apdu->u.sortRequest->otherInfo;
+       break;
+    case Z_APDU_scanRequest:
+       *oip = &apdu->u.scanRequest->otherInfo;
+       break;
+    case Z_APDU_initResponse:
+       *oip = &apdu->u.initResponse->otherInfo;
+       break;
+    case Z_APDU_searchResponse:
+       *oip = &apdu->u.searchResponse->otherInfo;
+       break;
+    case Z_APDU_presentResponse:
+       *oip = &apdu->u.presentResponse->otherInfo;
+       break;
+    case Z_APDU_sortResponse:
+       *oip = &apdu->u.sortResponse->otherInfo;
+       break;
+    case Z_APDU_scanResponse:
+       *oip = &apdu->u.scanResponse->otherInfo;
+       break;
+    default:
+       *oip = 0;
+       break;
+    }
+}
+
+Z_OtherInformationUnit *yaz_oi_update (
+    Z_OtherInformation **otherInformationP, ODR odr,
+    int *oid, int categoryValue)
+{
+    int i;
+    Z_OtherInformation *otherInformation = *otherInformationP;
+    if (!otherInformation)
+    {
+       if (!odr)
+           return 0;
+       otherInformation = *otherInformationP = (Z_OtherInformation *)
+           odr_malloc (odr, sizeof(*otherInformation));
+       otherInformation->num_elements = 0;
+       otherInformation->list = 0;
+    }
+    for (i = 0; i<otherInformation->num_elements; i++)
+    {
+       if (!oid)
+       {
+           if (!otherInformation->list[i]->category)
+               return otherInformation->list[i];
+       }
+       else
+       {
+           if (otherInformation->list[i]->category &&
+               categoryValue ==
+               *otherInformation->list[i]->category->categoryValue &&
+               !oid_oidcmp (oid, otherInformation->list[i]->category->
+                            categoryTypeId))
+               return otherInformation->list[i];
+       }
+    }
+    if (!odr)
+       return 0;
+    else
+    {
+       Z_OtherInformationUnit **newlist = (Z_OtherInformationUnit**)
+           odr_malloc(odr, otherInformation->num_elements+1 *
+                      sizeof(*newlist));
+       for (i = 0; i<otherInformation->num_elements; i++)
+           newlist[i] = otherInformation->list[i];
+       otherInformation->list = newlist;
+       
+       otherInformation->list[i] = (Z_OtherInformationUnit*)
+           odr_malloc (odr, sizeof(Z_OtherInformationUnit));
+       if (oid)
+       {
+           otherInformation->list[i]->category = (Z_InfoCategory*)
+               odr_malloc (odr, sizeof(Z_InfoCategory));
+           otherInformation->list[i]->category->categoryTypeId = (int*)
+               odr_oiddup (odr, oid);
+           otherInformation->list[i]->category->categoryValue = (int*)
+               odr_malloc (odr, sizeof(int));
+           *otherInformation->list[i]->category->categoryValue =
+               categoryValue;
+       }
+       else
+           otherInformation->list[i]->category = 0;
+       otherInformation->list[i]->which = Z_OtherInfo_characterInfo;
+       otherInformation->list[i]->information.characterInfo = 0;
+       
+       otherInformation->num_elements = i+1;
+       return otherInformation->list[i];
+    }
+}
+
+void yaz_oi_set_string_oid (
+    Z_OtherInformation **otherInformation, ODR odr,
+    int *oid, int categoryValue,
+    const char *str)
+{
+    Z_OtherInformationUnit *oi =
+       yaz_oi_update(otherInformation, odr, oid, categoryValue);
+    if (!oi)
+       return;
+    oi->which = Z_OtherInfo_characterInfo;
+    oi->information.characterInfo = odr_strdup (odr, str);
+}
+
+void yaz_oi_set_string_oidval (
+    Z_OtherInformation **otherInformation, ODR odr,
+    int oidval, int categoryValue,
+    const char *str)
+{
+    int oid[OID_SIZE];
+    struct oident ent;
+    ent.proto = PROTO_Z3950;
+    ent.oclass = CLASS_USERINFO;
+    ent.value = (oid_value) oidval;
+    if (!oid_ent_to_oid (&ent, oid))
+       return ;
+    yaz_oi_set_string_oid(otherInformation,
+                         odr, oid, categoryValue, str);
+}
+
+char *yaz_oi_get_string_oid (
+    Z_OtherInformation **otherInformation,
+    int *oid, int categoryValue)
+{
+    Z_OtherInformationUnit *oi;
+    
+    if ((oi = yaz_oi_update(otherInformation, 0, oid, 1)) &&
+       oi->which == Z_OtherInfo_characterInfo)
+       return oi->information.characterInfo;
+    return 0;
+}
+
+char *yaz_oi_get_string_oidval(Z_OtherInformation **otherInformation,
+                               int oidval, int categoryValue)    
+{
+    int oid[OID_SIZE];
+    struct oident ent;
+    ent.proto = PROTO_Z3950;
+    ent.oclass = CLASS_USERINFO;
+    ent.value = (oid_value) oidval;
+
+    if (!oid_ent_to_oid (&ent, oid))
+       return 0;
+    return yaz_oi_get_string_oid (otherInformation, oid, categoryValue);
+}
+