X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=data1%2Fd1_expout.c;h=85a7b050aebae8c277c54b46104a177438b1fba0;hp=3757f284c5cb5e7250db80520a6a823447b3cba8;hb=e2e073b5c947e996304ed7d577497af5e9a879ee;hpb=1872e3fc60b482771bbd1cb4b0290b8d6a9ef5d0 diff --git a/data1/d1_expout.c b/data1/d1_expout.c index 3757f28..85a7b05 100644 --- a/data1/d1_expout.c +++ b/data1/d1_expout.c @@ -1,8 +1,5 @@ -/* $Id: d1_expout.c,v 1.10 2007-04-16 08:44:31 adam Exp $ - Copyright (C) 1995-2007 - Index Data ApS - -This file is part of the Zebra server. +/* 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 @@ -21,9 +18,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ /* - * This module converts data1 tree to Z39.50 Explain records + * This module converts data1 tree to Z39.50 Explain records */ +#if HAVE_CONFIG_H +#include +#endif #include #include #include @@ -71,18 +71,15 @@ static int is_data_tag (ExpHandle *eh, data1_node *c) 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) @@ -119,7 +116,7 @@ static Odr_oid *f_oid(ExpHandle *eh, data1_node *c, oid_class oclass) c = c->child; if (!is_data_tag (eh, c) || c->u.data.len > 63) return 0; - yaz_snprintf(oidstr, sizeof(oidstr)-1, + yaz_snprintf(oidstr, sizeof(oidstr)-1, "%.*s", c->u.data.len, c->u.data.data); return yaz_string_to_oid_odr(yaz_oid_std(), @@ -187,13 +184,13 @@ Odr_oid **f_oid_seq (ExpHandle *eh, data1_node *n, int *num, oid_class oclass) ++(*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; @@ -254,7 +251,7 @@ Z_RpnCapabilities *f_rpnCapabilities (ExpHandle *eh, data1_node *n) (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) @@ -391,9 +388,8 @@ static Z_AccessInfo *f_accessInfo(ExpHandle *eh, data1_node *n) 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]; @@ -406,11 +402,11 @@ static int *f_recordCount(ExpHandle *eh, data1_node *c, int *which) *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) @@ -418,13 +414,13 @@ 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)) @@ -444,10 +440,10 @@ static Z_DatabaseList *f_databaseList(ExpHandle *eh, data1_node *n) 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; } @@ -455,7 +451,7 @@ static Z_DatabaseList *f_databaseList(ExpHandle *eh, data1_node *n) 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; @@ -473,7 +469,7 @@ static Z_NetworkAddressIA *f_networkAddressIA(ExpHandle *eh, data1_node *n) Z_NetworkAddressIA *res = (Z_NetworkAddressIA *) odr_malloc (eh->o, sizeof(*res)); data1_node *c; - + res->hostAddress = 0; res->port = 0; @@ -509,13 +505,13 @@ static Z_NetworkAddressOther *f_networkAddressOther(ExpHandle *eh, 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) { @@ -530,7 +526,7 @@ static Z_NetworkAddress **f_networkAddresses(ExpHandle *eh, data1_node *n, 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)) @@ -599,7 +595,7 @@ static Z_CategoryList *f_categoryList(ExpHandle *eh, data1_node *n) } 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) { @@ -644,7 +640,7 @@ static Z_TargetInfo *f_targetInfo(ExpHandle *eh, data1_node *n) res->num_languages = 0; res->languages = NULL; res->commonAccessInfo = 0; - + for (c = n->child; c; c = c->next) { int i = 0; @@ -664,7 +660,7 @@ static Z_TargetInfo *f_targetInfo(ExpHandle *eh, data1_node *n) 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) { @@ -674,7 +670,7 @@ static Z_TargetInfo *f_targetInfo(ExpHandle *eh, data1_node *n) } 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) { @@ -705,7 +701,7 @@ static Z_TargetInfo *f_targetInfo(ExpHandle *eh, data1_node *n) res->dbCombinations[i++] = f_databaseList (eh, n); } break; - case 119: + case 119: res->addresses = f_networkAddresses (eh, c, &res->num_addresses); break; @@ -775,7 +771,7 @@ static Z_DatabaseInfo *f_databaseInfo(ExpHandle *eh, data1_node *n) res->supplierContactInfo = 0; res->submissionContactInfo = 0; res->accessInfo = 0; - + for (c = n->child; c; c = c->next) { int i = 0; @@ -796,7 +792,7 @@ static Z_DatabaseInfo *f_databaseInfo(ExpHandle *eh, data1_node *n) } 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) { @@ -820,7 +816,7 @@ static Z_DatabaseInfo *f_databaseInfo(ExpHandle *eh, data1_node *n) } 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) { @@ -893,7 +889,7 @@ Z_AttributeDescription *f_attributeDescription ( odr_malloc(eh->o, sizeof(*res)); data1_node *c; int i = 0; - + res->name = 0; res->description = 0; res->attributeValue = 0; @@ -1146,7 +1142,7 @@ Z_AttributeSetDetails *f_attributeSetDetails (ExpHandle *eh, data1_node *n) Z_AttributeSetDetails *res = (Z_AttributeSetDetails *) odr_malloc(eh->o, sizeof(*res)); data1_node *c; - + res->attributeSet = 0; res->num_attributesByType = 0; res->attributesByType = 0; @@ -1378,7 +1374,7 @@ Z_ExplainRecord *data1_nodetoexplain (data1_handle dh, data1_node *n, 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))) @@ -1393,7 +1389,7 @@ Z_ExplainRecord *data1_nodetoexplain (data1_handle dh, data1_node *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))) @@ -1407,6 +1403,7 @@ Z_ExplainRecord *data1_nodetoexplain (data1_handle dh, data1_node *n, /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab