⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d1_expout.c

📁 harvest是一个下载html网页得机器人
💻 C
📖 第 1 页 / 共 3 页
字号:
/* $Id: d1_expout.c,v 1.2 2002/10/22 13:19:50 adam Exp $   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002   Index Data ApsThis file is part of the Zebra server.Zebra is free software; you can redistribute it and/or modify it underthe terms of the GNU General Public License as published by the FreeSoftware Foundation; either version 2, or (at your option) any laterversion.Zebra is distributed in the hope that it will be useful, but WITHOUT ANYWARRANTY; without even the implied warranty of MERCHANTABILITY orFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public Licensefor more details.You should have received a copy of the GNU General Public Licensealong with Zebra; see the file LICENSE.zebra.  If not, write to theFree Software Foundation, 59 Temple Place - Suite 330, Boston, MA02111-1307, USA.*//* * This module converts data1 tree to Z39.50 Explain records   */#include <assert.h>#include <string.h>#include <stdlib.h>#include <yaz/log.h>#include <yaz/proto.h>#include <data1.h>typedef struct {    data1_handle dh;    ODR o;    int select;    bool_t *false_value;    bool_t *true_value;} ExpHandle;static int is_numeric_tag (ExpHandle *eh, data1_node *c){    if (!c || c->which != DATA1N_tag)	return 0;    if (!c->u.tag.element)    {	yaz_log(LOG_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);	return 0;    }    if (eh->select && !c->u.tag.node_selected)	return 0;    return c->u.tag.element->tag->value.numeric;}static int is_data_tag (ExpHandle *eh, data1_node *c){    if (!c || c->which != DATA1N_data)	return 0;    if (eh->select && !c->u.tag.node_selected)	return 0;    return 1;}static 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)	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;}static char *f_string(ExpHandle *eh, data1_node *c){    char *r;    c = c->child;    if (!is_data_tag (eh, c))	return 0;    r = (char *)odr_malloc(eh->o, c->u.data.len+1);    memcpy(r, c->u.data.data, c->u.data.len);    r[c->u.data.len] = '\0';    return r;}static bool_t *f_bool(ExpHandle *eh, data1_node *c){    bool_t *tf;    char intbuf[64];    c = c->child;    if (!is_data_tag (eh, c) || c->u.data.len > 63)	return 0;    tf = (int *)odr_malloc (eh->o, sizeof(*tf));    sprintf(intbuf, "%.*s", c->u.data.len, c->u.data.data);    *tf = atoi(intbuf);    return tf;}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;	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);}static Z_IntUnit *f_intunit(ExpHandle *eh, data1_node *c){    /* fix */    return 0;}static Z_HumanString *f_humstring(ExpHandle *eh, data1_node *c){    Z_HumanString *r;    Z_HumanStringUnit *u;    c = c->child;    if (!is_data_tag (eh, c))	return 0;    r = (Z_HumanString *)odr_malloc(eh->o, sizeof(*r));    r->num_strings = 1;    r->strings = (Z_HumanStringUnit **)odr_malloc(eh->o, sizeof(Z_HumanStringUnit*));    r->strings[0] = u = (Z_HumanStringUnit *)odr_malloc(eh->o, sizeof(*u));    u->language = 0;    u->text = (char *)odr_malloc(eh->o, c->u.data.len+1);    memcpy(u->text, c->u.data.data, c->u.data.len);    u->text[c->u.data.len] = '\0';    return r;}static Z_CommonInfo *f_commonInfo(ExpHandle *eh, data1_node *n){    Z_CommonInfo *res = (Z_CommonInfo *)odr_malloc(eh->o, sizeof(*res));    data1_node *c;    res->dateAdded = 0;    res->dateChanged = 0;    res->expiry = 0;    res->humanStringLanguage = 0;    res->otherInfo = 0;    for (c = n->child; c; c = c->next)    {	switch (is_numeric_tag (eh, c))	{	    case 601: res->dateAdded = f_string(eh, c); break;	    case 602: res->dateChanged = f_string(eh, c); break;	    case 603: res->expiry = f_string(eh, c); break;	    case 604: res->humanStringLanguage = f_string(eh, c); break;	}    }    return res;}Odr_oid **f_oid_seq (ExpHandle *eh, data1_node *n, int *num, oid_class oclass){    Odr_oid **res;    data1_node *c;    int i;    *num = 0;    for (c = n->child ; c; c = c->next)	if (is_numeric_tag (eh, c) == 1000)	    ++(*num);    if (!*num)	return NULL;    res = (int **)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;    data1_node *c;    int i;    *num = 0;    for (c = n->child ; c; c = c->next)    {	if (is_numeric_tag (eh, c) != 1001)	    continue;	++(*num);    }    if (!*num)	return NULL;    res = (char **)odr_malloc (eh->o, sizeof(*res) * (*num));    for (c = n->child, i = 0 ; c; c = c->next)    {	if (is_numeric_tag (eh, c) != 1001)	    continue;	res[i++] = f_string (eh, c);    }    return res;}Z_ProximitySupport *f_proximitySupport (ExpHandle *eh, data1_node *n){    Z_ProximitySupport *res = (Z_ProximitySupport *)	odr_malloc (eh->o, sizeof(*res));    res->anySupport = eh->false_value;    res->num_unitsSupported = 0;    res->unitsSupported = 0;    return res;}Z_RpnCapabilities *f_rpnCapabilities (ExpHandle *eh, data1_node *n){    Z_RpnCapabilities *res = (Z_RpnCapabilities *)	odr_malloc (eh->o, sizeof(*res));    data1_node *c;    res->num_operators = 0;    res->operators = NULL;    res->resultSetAsOperandSupported = eh->false_value;    res->restrictionOperandSupported = eh->false_value;    res->proximity = NULL;    for (c = n->child; c; c = c->next)    {	int i = 0;	switch (is_numeric_tag(eh, c))	{	case 550:	    for (n = c->child; n; n = n->next)	    {		if (is_numeric_tag(eh, n) != 551)		    continue;		(res->num_operators)++;	    }	    if (res->num_operators)		res->operators = (int **)		    odr_malloc (eh->o, res->num_operators				* sizeof(*res->operators));	    for (n = c->child; n; n = n->next)	    {		if (is_numeric_tag(eh, n) != 551)		    continue;		res->operators[i++] = f_integer (eh, n);	    }	    break;	case 552:	    res->resultSetAsOperandSupported = f_bool (eh, c);	    break;	case 553:	    res->restrictionOperandSupported = f_bool (eh, c);	    break;	case 554:	    res->proximity = f_proximitySupport (eh, c);	    break;	}    }    return res;}Z_QueryTypeDetails *f_queryTypeDetails (ExpHandle *eh, data1_node *n){    Z_QueryTypeDetails *res = (Z_QueryTypeDetails *)	odr_malloc(eh->o, sizeof(*res));    data1_node *c;    res->which = Z_QueryTypeDetails_rpn;    res->u.rpn = 0;    for (c = n->child; c; c = c->next)    {	switch (is_numeric_tag(eh, c))	{	case 519:	    res->which = Z_QueryTypeDetails_rpn;	    res->u.rpn = f_rpnCapabilities (eh, c);	    break;	case 520:	    break;	case 521:	    break;	}    }    return res;}static Z_AccessInfo *f_accessInfo(ExpHandle *eh, data1_node *n){    Z_AccessInfo *res = (Z_AccessInfo *)odr_malloc(eh->o, sizeof(*res));    data1_node *c;    res->num_queryTypesSupported = 0;    res->queryTypesSupported = 0;    res->num_diagnosticsSets = 0;    res->diagnosticsSets = 0;    res->num_attributeSetIds = 0;    res->attributeSetIds = 0;    res->num_schemas = 0;    res->schemas = 0;    res->num_recordSyntaxes = 0;    res->recordSyntaxes = 0;    res->num_resourceChallenges = 0;    res->resourceChallenges = 0;    res->restrictedAccess = 0;    res->costInfo = 0;    res->num_variantSets = 0;    res->variantSets = 0;    res->num_elementSetNames = 0;    res->elementSetNames = 0;    res->num_unitSystems = 0;    res->unitSystems = 0;    for (c = n->child; c; c = c->next)    {	int i = 0;	switch (is_numeric_tag (eh, c))	{	case 501:	    for (n = c->child; n; n = n->next)	    {		if (is_numeric_tag(eh, n) != 518)		    continue;		(res->num_queryTypesSupported)++;	    }	    if (res->num_queryTypesSupported)		res->queryTypesSupported =		    (Z_QueryTypeDetails **)		    odr_malloc (eh->o, res->num_queryTypesSupported				* sizeof(*res->queryTypesSupported));	    for (n = c->child; n; n = n->next)	    {		if (is_numeric_tag(eh, n) != 518)		    continue;		res->queryTypesSupported[i++] = f_queryTypeDetails (eh, n);	    }	    break;	case 503:	    res->diagnosticsSets =		f_oid_seq(eh, c, &res->num_diagnosticsSets, CLASS_DIAGSET);	    break;	case 505:	    res->attributeSetIds =		f_oid_seq(eh, c, &res->num_attributeSetIds, CLASS_ATTSET);	    break;	case 507:	    res->schemas =		f_oid_seq(eh, c, &res->num_schemas, CLASS_SCHEMA);	    break;	case 509:	    res->recordSyntaxes =		f_oid_seq (eh, c, &res->num_recordSyntaxes, CLASS_RECSYN);	    break;	case 511:	    res->resourceChallenges =		f_oid_seq (eh, c, &res->num_resourceChallenges, CLASS_RESFORM);	    break;	case 513: res->restrictedAccess = NULL; break; /* fix */	case 514: res->costInfo = NULL; break; /* fix */	case 515:	    res->variantSets =		f_oid_seq (eh, c, &res->num_variantSets, CLASS_VARSET);	    break;	case 516:	    res->elementSetNames =		f_string_seq (eh, c, &res->num_elementSetNames);	    break;	case 517:	    res->unitSystems = f_string_seq (eh, c, &res->num_unitSystems);	    break;	}    }    return res;}static 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];    c = c->child;    if (!is_numeric_tag (eh, c))	return 0;    if (c->u.tag.element->tag->value.numeric == 210)	*wp = Z_DatabaseInfo_actualNumber;    else if (c->u.tag.element->tag->value.numeric == 211)	*wp = Z_DatabaseInfo_approxNumber;    else	return 0;    if (!c->child || c->child->which != DATA1N_data)	return 0;    sprintf(intbuf, "%.*s", c->child->u.data.len, c->child->u.data.data);    *r = atoi(intbuf);    return r;}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))	{	case 102: res->name = f_string (eh, c); break;	case 113: res->description = f_humstring (eh, c); break;	case 127: res->address = f_humstring (eh, c); break;	case 128: res->email = f_string (eh, c); break;	case 129: res->phone = f_string (eh, c); break;	}    }    return res;}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) 	    continue;	++i;    }    if (!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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -