+/* This file is part of the Zebra server.
+ Copyright (C) Index Data
+
+Zebra is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+*/
+
/*
- * Copyright (c) 1995-1999, Index Data.
- * See the file LICENSE for details.
- * Sebastian Hammer, Adam Dickmeiss
- *
- * $Log: d1_expout.c,v $
- * Revision 1.1 2002-10-22 12:53:33 adam
- * data1 part of zebra
- *
- * Revision 1.17 1999/11/30 13:47:12 adam
- * Improved installation. Moved header files to include/yaz.
- *
- * Revision 1.16 1999/08/27 09:40:32 adam
- * Renamed logf function to yaz_log. Removed VC++ project files.
- *
- * Revision 1.15 1998/09/28 12:44:40 adam
- * Fixed bug in f_integer.
- *
- * Revision 1.14 1998/06/08 14:26:41 adam
- * Fixed bug in f_queryTypeDetails.
- *
- * Revision 1.13 1998/06/05 08:58:48 adam
- * Fixed un-initialised var in f_rpnCapabilities.
- *
- * Revision 1.12 1998/05/18 13:07:04 adam
- * Changed the way attribute sets are handled by the retriaval module.
- * Extended Explain conversion / schema.
- * Modified server and client to work with ASN.1 compiled protocol handlers.
- *
- * Revision 1.11 1998/04/02 08:27:37 adam
- * Minor change in definition of Z_TargetInfo. Furhter work on Explain
- * schema - added AttributeDetails.
- *
- * Revision 1.10 1998/03/31 15:13:20 adam
- * Development towards compiled ASN.1.
- *
- * Revision 1.9 1998/03/05 08:07:58 adam
- * Make data1 to EXPLAIN ignore local tags in root.
- *
- * Revision 1.8 1998/02/11 11:53:35 adam
- * Changed code so that it compiles as C++.
- *
- * Revision 1.7 1997/12/09 16:18:16 adam
- * Work on EXPLAIN schema. First implementation of sub-schema facility
- * in the *.abs files.
- *
- * Revision 1.6 1997/11/24 11:33:56 adam
- * Using function odr_nullval() instead of global ODR_NULLVAL when
- * appropriate.
- *
- * Revision 1.5 1997/11/19 10:30:06 adam
- * More explain work.
- *
- * Revision 1.4 1997/11/18 09:51:08 adam
- * Removed element num_children from data1_node. Minor changes in
- * data1 to Explain.
- *
- * Revision 1.3 1997/09/17 12:10:36 adam
- * YAZ version 1.4.
- *
- * Revision 1.2 1995/12/14 16:28:30 quinn
- * More explain stuff.
- *
- * Revision 1.1 1995/12/14 11:09:51 quinn
- * Work on Explain
- *
- *
+ * This module converts data1 tree to Z39.50 Explain records
*/
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <yaz/log.h>
#include <yaz/proto.h>
-#include <data1.h>
+#include <yaz/oid_db.h>
+#include <yaz/snprintf.h>
+#include <idzebra/data1.h>
typedef struct {
data1_handle dh;
return 0;
if (!c->u.tag.element)
{
- yaz_log(LOG_WARN, "Tag %s is local", c->u.tag.tag);
+ yaz_log(YLOG_WARN, "Tag %s is local", c->u.tag.tag);
return 0;
}
if (c->u.tag.element->tag->which != DATA1T_numeric)
{
- yaz_log(LOG_WARN, "Tag %s is not numeric", c->u.tag.tag);
+ yaz_log(YLOG_WARN, "Tag %s is not numeric", c->u.tag.tag);
return 0;
}
if (eh->select && !c->u.tag.node_selected)
return 1;
}
-static int *f_integer(ExpHandle *eh, data1_node *c)
+static Odr_int *f_integer(ExpHandle *eh, data1_node *c)
{
- int *r;
char intbuf[64];
c = c->child;
- if (!is_data_tag (eh, c) || c->u.data.len > 63)
+ if (!is_data_tag (eh, c) || c->u.data.len >= sizeof(intbuf))
return 0;
- r = (int *)odr_malloc(eh->o, sizeof(*r));
sprintf(intbuf, "%.*s", c->u.data.len, c->u.data.data);
- *r = atoi(intbuf);
- return r;
+ return odr_intdup(eh->o, atoi(intbuf));
}
static char *f_string(ExpHandle *eh, data1_node *c)
static Odr_oid *f_oid(ExpHandle *eh, data1_node *c, oid_class oclass)
{
char oidstr[64];
- int oid_this[20];
- oid_value value_for_this;
c = c->child;
if (!is_data_tag (eh, c) || c->u.data.len > 63)
return 0;
- sprintf(oidstr, "%.*s", c->u.data.len, c->u.data.data);
- value_for_this = oid_getvalbyname(oidstr);
- if (value_for_this == VAL_NONE)
- {
- Odr_oid *oid = odr_getoidbystr(eh->o, oidstr);
- assert (oid);
- return oid;
- }
- else
- {
- struct oident ident;
+ yaz_snprintf(oidstr, sizeof(oidstr)-1,
+ "%.*s", c->u.data.len, c->u.data.data);
- ident.oclass = oclass;
- ident.proto = PROTO_Z3950;
- ident.value = value_for_this;
-
- oid_ent_to_oid (&ident, oid_this);
- }
- return odr_oiddup (eh->o, oid_this);
+ return yaz_string_to_oid_odr(yaz_oid_std(),
+ CLASS_GENERAL, oidstr, eh->o);
}
static Z_IntUnit *f_intunit(ExpHandle *eh, data1_node *c)
++(*num);
if (!*num)
return NULL;
- res = (int **)odr_malloc (eh->o, sizeof(*res) * (*num));
+ res = (Odr_oid **)odr_malloc (eh->o, sizeof(*res) * (*num));
for (c = n->child, i = 0 ; c; c = c->next)
if (is_numeric_tag (eh, c) == 1000)
res[i++] = f_oid (eh, c, oclass);
return res;
}
-
+
char **f_string_seq (ExpHandle *eh, data1_node *n, int *num)
{
char **res;
(res->num_operators)++;
}
if (res->num_operators)
- res->operators = (int **)
+ res->operators = (Odr_int **)
odr_malloc (eh->o, res->num_operators
* sizeof(*res->operators));
for (n = c->child; n; n = n->next)
return res;
}
-static int *f_recordCount(ExpHandle *eh, data1_node *c, int *which)
+static Odr_int *f_recordCount(ExpHandle *eh, data1_node *c, int *which)
{
- int *r= (int *)odr_malloc(eh->o, sizeof(*r));
int *wp = which;
char intbuf[64];
*wp = Z_DatabaseInfo_approxNumber;
else
return 0;
- if (!c->child || c->child->which != DATA1N_data)
+ if (!c->child || c->child->which != DATA1N_data ||
+ c->child->u.data.len >= sizeof(intbuf))
return 0;
sprintf(intbuf, "%.*s", c->child->u.data.len, c->child->u.data.data);
- *r = atoi(intbuf);
- return r;
+ return odr_intdup(eh->o, atoi(intbuf));
}
static Z_ContactInfo *f_contactInfo(ExpHandle *eh, data1_node *n)
Z_ContactInfo *res = (Z_ContactInfo *)
odr_malloc (eh->o, sizeof(*res));
data1_node *c;
-
+
res->name = 0;
res->description = 0;
res->address = 0;
res->email = 0;
res->phone = 0;
-
+
for (c = n->child; c; c = c->next)
{
switch (is_numeric_tag (eh, c))
data1_node *c;
Z_DatabaseList *res;
int i = 0;
-
+
for (c = n->child; c; c = c->next)
{
- if (!is_numeric_tag (eh, c) != 102)
+ if (!is_numeric_tag (eh, c) != 102)
continue;
++i;
}
return NULL;
res = (Z_DatabaseList *)odr_malloc (eh->o, sizeof(*res));
-
+
res->num_databases = i;
res->databases = (char **)odr_malloc (eh->o, sizeof(*res->databases) * i);
i = 0;
Z_NetworkAddressIA *res = (Z_NetworkAddressIA *)
odr_malloc (eh->o, sizeof(*res));
data1_node *c;
-
+
res->hostAddress = 0;
res->port = 0;
return res;
}
-static Z_NetworkAddress **f_networkAddresses(ExpHandle *eh, data1_node *n,
+static Z_NetworkAddress **f_networkAddresses(ExpHandle *eh, data1_node *n,
int *num)
{
Z_NetworkAddress **res = NULL;
data1_node *c;
int i = 0;
-
+
*num = 0;
for (c = n->child; c; c = c->next)
{
if (*num)
res = (Z_NetworkAddress **) odr_malloc (eh->o, sizeof(*res) * (*num));
-
+
for (c = n->child; c; c = c->next)
{
switch (is_numeric_tag (eh, c))
}
if (res->num_categories)
res->categories =
- (Z_CategoryInfo **)odr_malloc (eh->o, res->num_categories
+ (Z_CategoryInfo **)odr_malloc (eh->o, res->num_categories
* sizeof(*res->categories));
for (n = c->child; n; n = n->next)
{
res->num_languages = 0;
res->languages = NULL;
res->commonAccessInfo = 0;
-
+
for (c = n->child; c; c = c->next)
{
int i = 0;
case 111: res->welcomeMessage = f_humstring(eh, c); break;
case 112: res->contactInfo = f_contactInfo(eh, c); break;
case 113: res->description = f_humstring(eh, c); break;
- case 114:
+ case 114:
res->num_nicknames = 0;
for (n = c->child; n; n = n->next)
{
}
if (res->num_nicknames)
res->nicknames =
- (char **)odr_malloc (eh->o, res->num_nicknames
+ (char **)odr_malloc (eh->o, res->num_nicknames
* sizeof(*res->nicknames));
for (n = c->child; n; n = n->next)
{
res->dbCombinations[i++] = f_databaseList (eh, n);
}
break;
- case 119:
+ case 119:
res->addresses =
f_networkAddresses (eh, c, &res->num_addresses);
break;
res->supplierContactInfo = 0;
res->submissionContactInfo = 0;
res->accessInfo = 0;
-
+
for (c = n->child; c; c = c->next)
{
int i = 0;
}
if (res->num_nicknames)
res->nicknames =
- (char **)odr_malloc (eh->o, res->num_nicknames
+ (char **)odr_malloc (eh->o, res->num_nicknames
* sizeof(*res->nicknames));
for (n = c->child; n; n = n->next)
{
}
if (res->num_keywords)
res->keywords =
- (Z_HumanString **)odr_malloc (eh->o, res->num_keywords
+ (Z_HumanString **)odr_malloc (eh->o, res->num_keywords
* sizeof(*res->keywords));
for (n = c->child; n; n = n->next)
{
odr_malloc(eh->o, sizeof(*res));
data1_node *c;
int i = 0;
-
+
res->name = 0;
res->description = 0;
res->attributeValue = 0;
Z_AttributeSetDetails *res = (Z_AttributeSetDetails *)
odr_malloc(eh->o, sizeof(*res));
data1_node *c;
-
+
res->attributeSet = 0;
res->num_attributesByType = 0;
res->attributesByType = 0;
assert(n->which == DATA1N_root);
if (strcmp(n->u.root.type, "explain"))
{
- yaz_log(LOG_WARN, "Attempt to convert a non-Explain record");
+ yaz_log(YLOG_WARN, "Attempt to convert a non-Explain record");
return 0;
}
for (n = n->child; n; n = n->next)
res->which = Z_Explain_categoryList;
if (!(res->u.categoryList = f_categoryList(&eh, n)))
return 0;
- return res;
+ return res;
case 2:
res->which = Z_Explain_targetInfo;
if (!(res->u.targetInfo = f_targetInfo(&eh, n)))
res->which = Z_Explain_attributeSetInfo;
if (!(res->u.attributeSetInfo = f_attributeSetInfo(&eh, n)))
return 0;
- return res;
+ return res;
case 10:
res->which = Z_Explain_attributeDetails;
if (!(res->u.attributeDetails = f_attributeDetails(&eh, n)))
return res;
}
}
- yaz_log(LOG_WARN, "No category in Explain record");
+ yaz_log(YLOG_WARN, "No category in Explain record");
return 0;
}
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+