X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=index%2Fzinfo.c;h=d9fce2bc03c3829f3abab790f2a44bb21482ea55;hp=a29f76a648ae1f36676a7c508a9137b7e94099fc;hb=5437b50633032595afe6f87dc0f989bc92a5aea8;hpb=d9a9544ebf605f5141ced91c4cf2c2fc97b93539 diff --git a/index/zinfo.c b/index/zinfo.c index a29f76a..d9fce2b 100644 --- a/index/zinfo.c +++ b/index/zinfo.c @@ -1,17 +1,31 @@ -/* - * Copyright (C) 1994-2002, Index Data - * All rights reserved. - * Sebastian Hammer, Adam Dickmeiss - * - * $Id: zinfo.c,v 1.30 2002-05-13 14:13:43 adam Exp $ - */ +/* $Id: zinfo.c,v 1.41 2004-11-19 10:27:05 heikki Exp $ + Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 + Index Data Aps + +This file is part of the Zebra server. + +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 Zebra; see the file LICENSE.zebra. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. +*/ #include #include #include #include -#include +#include #include "zinfo.h" #define ZINFO_DEBUG 0 @@ -30,7 +44,7 @@ struct zebSUInfoB { typedef struct zebAccessObjectB *zebAccessObject; struct zebAccessObjectB { void *handle; - int sysno; + SYSNO sysno; Odr_oid *oid; zebAccessObject next; }; @@ -43,7 +57,7 @@ struct zebAccessInfoB { typedef struct { struct zebSUInfoB *SUInfo; - int sysno; + SYSNO sysno; int dirty; int readFlag; data1_node *data1_tree; @@ -53,9 +67,9 @@ struct zebDatabaseInfoB { zebAttributeDetails attributeDetails; char *databaseName; data1_node *data1_database; - int recordCount; /* records in db */ - int recordBytes; /* size of records */ - int sysno; /* sysno of database info */ + zint recordCount; /* records in db */ + zint recordBytes; /* size of records */ + SYSNO sysno; /* sysno of database info */ int readFlag; /* 1: read is needed when referenced; 0 if not */ int dirty; /* 1: database is dirty: write is needed */ struct zebDatabaseInfoB *next; @@ -70,14 +84,14 @@ struct zebraExplainAttset { struct zebraCategoryListInfo { int dirty; - int sysno; + SYSNO sysno; data1_node *data1_categoryList; }; struct zebraExplainInfo { - int ordinalSU; - int runNumber; - int dirty; + int ordinalSU; + zint runNumber; + int dirty; int write_flag; Records records; data1_handle dh; @@ -118,7 +132,7 @@ static void zebraExplain_writeCategoryList (ZebraExplainInfo zei, int key_flush); -static Record createRecord (Records records, int *sysno) +static Record createRecord (Records records, SYSNO *sysno) { Record rec; if (*sysno) @@ -184,7 +198,7 @@ void zebraExplain_flush (ZebraExplainInfo zei, void *handle) void zebraExplain_close (ZebraExplainInfo zei) { #if ZINFO_DEBUG - yaz_log (LOG_LOG, "zebraExplain_close"); + yaz_log (YLOG_LOG, "zebraExplain_close"); #endif if (!zei) return; @@ -257,6 +271,52 @@ void zebraExplain_mergeAccessInfo (ZebraExplainInfo zei, data1_node *n, } } +/* Explain structure + root record + of type targetInfo + and has sysno = 1 + + databaseList (list of databases) +*/ +/* +Example root: +explain: + targetInfo: TargetInfo + name: Zebra + namedResultSets: 1 + multipleDbSearch: 1 + nicknames: + name: Zebra + commonInfo: + dateAdded: 20030630190601 + dateChanged: 20030630190601 + languageCode: EN + accessinfo: + unitSystems: + string: ISO + attributeSetIds: + oid: 1.2.840.10003.3.2 + oid: 1.2.840.10003.3.5 + oid: 1.2.840.10003.3.1 + schemas: + oid: 1.2.840.10003.13.1000.81.2 + oid: 1.2.840.10003.13.2 + zebraInfo: + version: 1.3.12 + databaseList: + database: + name: Default + id: 50 + attributeDetailsId: 51 + database: + name: IR-Explain-1 + id: 52 + attributeDetailsId: 53 + ordinalSU: 38 + runNumber: 1 +nextResultSetPosition = 2 +*/ + ZebraExplainInfo zebraExplain_open ( Records records, data1_handle dh, Res res, @@ -272,7 +332,7 @@ ZebraExplainInfo zebraExplain_open ( NMEM nmem = nmem_create (); #if ZINFO_DEBUG - logf (LOG_LOG, "zebraExplain_open wr=%d", writeFlag); + yaz_log (YLOG_LOG, "zebraExplain_open wr=%d", writeFlag); #endif zei = (ZebraExplainInfo) nmem_malloc (nmem, sizeof(*zei)); zei->write_flag = writeFlag; @@ -291,12 +351,17 @@ ZebraExplainInfo zebraExplain_open ( zei->categoryList->dirty = 0; zei->categoryList->data1_categoryList = NULL; - time (&our_time); - tm = localtime (&our_time); - sprintf (zei->date, "%04d%02d%02d%02d%02d%02d", - tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec); - + if ( atoi (res_get_def (res, "notimestamps", "0") )== 0) + { + time (&our_time); + tm = localtime (&our_time); + sprintf (zei->date, "%04d%02d%02d%02d%02d%02d", + tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec); + } else { + sprintf (zei->date, "%04d%02d%02d%02d%02d%02d", + 0, 0, 0, 0, 0, 0); + } zdip = &zei->databaseInfo; trec = rec_get (records, 1); /* get "root" record */ @@ -315,15 +380,15 @@ ZebraExplainInfo zebraExplain_open ( if (!zei->data1_target) #endif { - logf (LOG_FATAL, "Explain schema missing. Check profilePath"); + yaz_log (YLOG_FATAL, "Explain schema missing. Check profilePath"); nmem_destroy (zei->nmem); return 0; } #if ZINFO_DEBUG data1_pr_tree (zei->dh, zei->data1_target, stderr); #endif - node_tgtinfo = data1_search_tag (zei->dh, zei->data1_target->child, - "targetInfo"); + node_tgtinfo = data1_search_tag (zei->dh, zei->data1_target, + "/targetInfo"); zebraExplain_mergeAccessInfo (zei, node_tgtinfo, &zei->accessInfo); @@ -372,12 +437,12 @@ ZebraExplainInfo zebraExplain_open ( memcpy ((*zdip)->databaseName, node_name->u.data.data, node_name->u.data.len); (*zdip)->databaseName[node_name->u.data.len] = '\0'; - (*zdip)->sysno = atoi_n (node_id->u.data.data, - node_id->u.data.len); + (*zdip)->sysno = atoi_zn (node_id->u.data.data, + node_id->u.data.len); (*zdip)->attributeDetails = (zebAttributeDetails) nmem_malloc (zei->nmem, sizeof(*(*zdip)->attributeDetails)); - (*zdip)->attributeDetails->sysno = atoi_n (node_aid->u.data.data, - node_aid->u.data.len); + (*zdip)->attributeDetails->sysno = atoi_zn (node_aid->u.data.data, + node_aid->u.data.len); (*zdip)->attributeDetails->readFlag = 1; (*zdip)->attributeDetails->dirty = 0; (*zdip)->attributeDetails->SUInfo = NULL; @@ -396,8 +461,8 @@ ZebraExplainInfo zebraExplain_open ( "runNumber"); np = np->child; assert (np && np->which == DATA1N_data); - zei->runNumber = atoi_n (np->u.data.data, np->u.data.len); - yaz_log (LOG_LOG, "READ runnumber = %d", zei->runNumber); + zei->runNumber = atoi_zn (np->u.data.data, np->u.data.len); + yaz_log (YLOG_DEBUG, "read runnumber=" ZINT_FORMAT, zei->runNumber); *zdip = NULL; } rec_rm (&trec); @@ -422,12 +487,12 @@ ZebraExplainInfo zebraExplain_open ( "\n" ); if (!zei->data1_target) { - logf (LOG_FATAL, "Explain schema missing. Check profilePath"); + yaz_log (YLOG_FATAL, "Explain schema missing. Check profilePath"); nmem_destroy (zei->nmem); return 0; } - node_tgtinfo = data1_search_tag (zei->dh, zei->data1_target->child, - "targetInfo"); + node_tgtinfo = data1_search_tag (zei->dh, zei->data1_target, + "/targetInfo"); assert (node_tgtinfo); zebraExplain_initCommonInfo (zei, node_tgtinfo); @@ -464,10 +529,8 @@ ZebraExplainInfo zebraExplain_open ( if (zcl->data1_categoryList) { - assert (zcl->data1_categoryList->child); - node_cl = data1_search_tag (zei->dh, - zcl->data1_categoryList->child, - "categoryList"); + node_cl = data1_search_tag (zei->dh, zcl->data1_categoryList, + "/categoryList"); assert (node_cl); zebraExplain_initCommonInfo (zei, node_cl); } @@ -488,8 +551,8 @@ static void zebraExplain_readAttributeDetails (ZebraExplainInfo zei, zad->data1_tree = read_sgml_rec (zei->dh, zei->nmem, rec); - node_adinfo = data1_search_tag (zei->dh, zad->data1_tree->child, - "attributeDetails"); + node_adinfo = data1_search_tag (zei->dh, zad->data1_tree, + "/attributeDetails"); node_zebra = data1_search_tag (zei->dh, node_adinfo->child, "zebraInfo"); node_list = data1_search_tag (zei->dh, node_zebra->child, @@ -533,7 +596,7 @@ static void zebraExplain_readAttributeDetails (ZebraExplainInfo zei, node_use->u.data.len); (*zsuip)->info.ordinal = atoi_n (node_ordinal->u.data.data, node_ordinal->u.data.len); - logf (LOG_DEBUG, "set=%d use=%d ordinal=%d", + yaz_log (YLOG_DEBUG, "set=%d use=%d ordinal=%d", (*zsuip)->info.set, (*zsuip)->info.use, (*zsuip)->info.ordinal); zsuip = &(*zsuip)->next; } @@ -553,8 +616,9 @@ static void zebraExplain_readDatabase (ZebraExplainInfo zei, zdi->data1_database = read_sgml_rec (zei->dh, zei->nmem, rec); - node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database->child, - "databaseInfo"); + node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database, + "/databaseInfo"); + assert (node_dbinfo); zebraExplain_mergeAccessInfo (zei, node_dbinfo, &zdi->accessInfo); node_zebra = data1_search_tag (zei->dh, node_dbinfo->child, @@ -563,21 +627,60 @@ static void zebraExplain_readDatabase (ZebraExplainInfo zei, && (np = data1_search_tag (zei->dh, node_zebra->child, "recordBytes")) && np->child && np->child->which == DATA1N_data) - zdi->recordBytes = atoi_n (np->child->u.data.data, - np->child->u.data.len); + zdi->recordBytes = atoi_zn (np->child->u.data.data, + np->child->u.data.len); if ((np = data1_search_tag (zei->dh, node_dbinfo->child, "recordCount")) && (np = data1_search_tag (zei->dh, np->child, "recordCountActual")) && np->child->which == DATA1N_data) { - zdi->recordCount = atoi_n (np->child->u.data.data, - np->child->u.data.len); + zdi->recordCount = atoi_zn (np->child->u.data.data, + np->child->u.data.len); } zdi->readFlag = 0; rec_rm (&rec); } +int zebraExplain_removeDatabase(ZebraExplainInfo zei, void *update_handle) +{ + struct zebDatabaseInfoB **zdip = &zei->databaseInfo; + + while (*zdip) + { + if (*zdip == zei->curDatabaseInfo) + { + struct zebDatabaseInfoB *zdi = *zdip; + Record rec; + + zei->dirty = 1; + zei->updateHandle = update_handle; + + if (zdi->attributeDetails) + { + /* remove attribute details keys and delete it */ + zebAttributeDetails zad = zdi->attributeDetails; + + rec = rec_get(zei->records, zad->sysno); + (*zei->updateFunc)(zei->updateHandle, rec, 0); + rec_rm(&rec); + } + /* remove database record keys and delete it */ + rec = rec_get (zei->records, zdi->sysno); + (*zei->updateFunc)(zei->updateHandle, rec, 0); + rec_rm(&rec); + + /* remove from list */ + *zdip = zdi->next; + + /* current database is IR-Explain-1 */ + return 0; + } + zdip = &(*zdip)->next; + } + return -1; +} + int zebraExplain_curDatabase (ZebraExplainInfo zei, const char *database) { struct zebDatabaseInfoB *zdi; @@ -590,29 +693,29 @@ int zebraExplain_curDatabase (ZebraExplainInfo zei, const char *database) assert (zei); if (zei->curDatabaseInfo && - !strcmp (zei->curDatabaseInfo->databaseName, database)) + !STRCASECMP (zei->curDatabaseInfo->databaseName, database)) return 0; for (zdi = zei->databaseInfo; zdi; zdi=zdi->next) { - if (!strcmp (zdi->databaseName, database_n)) + if (!STRCASECMP (zdi->databaseName, database_n)) break; } if (!zdi) return -1; #if ZINFO_DEBUG - logf (LOG_LOG, "zebraExplain_curDatabase: %s", database); + yaz_log (YLOG_LOG, "zebraExplain_curDatabase: %s", database); #endif if (zdi->readFlag) { #if ZINFO_DEBUG - logf (LOG_LOG, "zebraExplain_readDatabase: %s", database); + yaz_log (YLOG_LOG, "zebraExplain_readDatabase: %s", database); #endif zebraExplain_readDatabase (zei, zdi); } if (zdi->attributeDetails->readFlag) { #if ZINFO_DEBUG - logf (LOG_LOG, "zebraExplain_readAttributeDetails: %s", database); + yaz_log (YLOG_LOG, "zebraExplain_readAttributeDetails: %s", database); #endif zebraExplain_readAttributeDetails (zei, zdi->attributeDetails); } @@ -684,12 +787,12 @@ int zebraExplain_newDatabase (ZebraExplainInfo zei, const char *database, database_n = database; #if ZINFO_DEBUG - logf (LOG_LOG, "zebraExplain_newDatabase: %s", database); + yaz_log (YLOG_LOG, "zebraExplain_newDatabase: %s", database); #endif assert (zei); for (zdi = zei->databaseInfo; zdi; zdi=zdi->next) { - if (!strcmp (zdi->databaseName, database_n)) + if (!STRCASECMP (zdi->databaseName, database_n)) break; } if (zdi) @@ -715,9 +818,9 @@ int zebraExplain_newDatabase (ZebraExplainInfo zei, const char *database, "\n"); if (!zdi->data1_database) return -2; - - node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database->child, - "databaseInfo"); + + node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database, + "/databaseInfo"); assert (node_dbinfo); zebraExplain_initCommonInfo (zei, node_dbinfo); @@ -754,9 +857,8 @@ int zebraExplain_newDatabase (ZebraExplainInfo zei, const char *database, "AttributeDetails\n" "\n"); - node_adinfo = - data1_search_tag (zei->dh, zdi->attributeDetails->data1_tree->child, - "attributeDetails"); + node_adinfo = data1_search_tag (zei->dh, zdi->attributeDetails->data1_tree, + "/attributeDetails"); assert (node_adinfo); zebraExplain_initCommonInfo (zei, node_adinfo); @@ -798,7 +900,7 @@ static void zebraExplain_writeCategoryList (ZebraExplainInfo zei, int i; Record drec; data1_node *node_ci, *node_categoryList; - int sysno = 0; + SYSNO sysno = 0; static char *category[] = { "CategoryList", "TargetInfo", @@ -814,13 +916,13 @@ static void zebraExplain_writeCategoryList (ZebraExplainInfo zei, node_categoryList = zcl->data1_categoryList; #if ZINFO_DEBUG - logf (LOG_LOG, "zebraExplain_writeCategoryList"); + yaz_log (YLOG_LOG, "zebraExplain_writeCategoryList"); #endif drec = createRecord (zei->records, &sysno); - - node_ci = data1_search_tag (zei->dh, node_categoryList->child, - "categoryList"); + + node_ci = data1_search_tag (zei->dh, node_categoryList, + "/categoryList"); assert (node_ci); node_ci = data1_mk_tag (zei->dh, zei->nmem, "categories", 0 /* attr */, node_ci); @@ -868,13 +970,14 @@ static void zebraExplain_writeAttributeDetails (ZebraExplainInfo zei, zad->dirty = 0; #if ZINFO_DEBUG - logf (LOG_LOG, "zebraExplain_writeAttributeDetails"); + yaz_log (YLOG_LOG, "zebraExplain_writeAttributeDetails"); #endif drec = createRecord (zei->records, &zad->sysno); assert (zad->data1_tree); - node_adinfo = data1_search_tag (zei->dh, zad->data1_tree->child, - "attributeDetails"); + + node_adinfo = data1_search_tag (zei->dh, zad->data1_tree, + "/attributeDetails"); zebraExplain_updateCommonInfo (zei, node_adinfo); data1_mk_tag_data_text (zei->dh, node_adinfo, "name", @@ -995,13 +1098,15 @@ static void zebraExplain_writeDatabase (ZebraExplainInfo zei, zdi->dirty = 0; #if ZINFO_DEBUG - logf (LOG_LOG, "zebraExplain_writeDatabase %s", zdi->databaseName); + yaz_log (YLOG_LOG, "zebraExplain_writeDatabase %s", zdi->databaseName); #endif drec = createRecord (zei->records, &zdi->sysno); assert (zdi->data1_database); - node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database->child, - "databaseInfo"); + node_dbinfo = data1_search_tag (zei->dh, zdi->data1_database, + "/databaseInfo"); + + assert (node_dbinfo); zebraExplain_updateCommonInfo (zei, node_dbinfo); zebraExplain_updateAccessInfo (zei, node_dbinfo, zdi->accessInfo); @@ -1012,13 +1117,13 @@ static void zebraExplain_writeDatabase (ZebraExplainInfo zei, /* record count */ node_count = data1_mk_tag_uni (zei->dh, zei->nmem, "recordCount", node_dbinfo); - data1_mk_tag_data_int (zei->dh, node_count, "recordCountActual", - zdi->recordCount, zei->nmem); + data1_mk_tag_data_zint (zei->dh, node_count, "recordCountActual", + zdi->recordCount, zei->nmem); /* zebra info (private) */ node_zebra = data1_mk_tag_uni (zei->dh, zei->nmem, "zebraInfo", node_dbinfo); - data1_mk_tag_data_int (zei->dh, node_zebra, + data1_mk_tag_data_zint (zei->dh, node_zebra, "recordBytes", zdi->recordBytes, zei->nmem); /* convert to "SGML" and write it */ #if ZINFO_DEBUG @@ -1077,7 +1182,7 @@ static void zebraExplain_writeAttributeSet (ZebraExplainInfo zei, attset = data1_attset_search_id (zei->dh, entp->value); #if ZINFO_DEBUG - logf (LOG_LOG, "zebraExplain_writeAttributeSet %s", + yaz_log (YLOG_LOG, "zebraExplain_writeAttributeSet %s", attset ? attset->name : ""); #endif @@ -1087,9 +1192,10 @@ static void zebraExplain_writeAttributeSet (ZebraExplainInfo zei, "AttributeSetInfo\n" "\n" ); - node_attinfo = data1_search_tag (zei->dh, node_root->child, - "attributeSetInfo"); + node_attinfo = data1_search_tag (zei->dh, node_root, + "/attributeSetInfo"); + assert (node_attinfo); zebraExplain_initCommonInfo (zei, node_attinfo); zebraExplain_updateCommonInfo (zei, node_attinfo); @@ -1145,8 +1251,8 @@ static void zebraExplain_writeTarget (ZebraExplainInfo zei, int key_flush) trec = rec_get (zei->records, 1); xfree (trec->info[recInfo_storeData]); - node_tgtinfo = data1_search_tag (zei->dh, zei->data1_target->child, - "targetInfo"); + node_tgtinfo = data1_search_tag (zei->dh, zei->data1_target, + "/targetInfo"); assert (node_tgtinfo); zebraExplain_updateCommonInfo (zei, node_tgtinfo); @@ -1169,16 +1275,16 @@ static void zebraExplain_writeTarget (ZebraExplainInfo zei, int key_flush) "database", 0 /* attr */, node_list); data1_mk_tag_data_text (zei->dh, node_db, "name", zdi->databaseName, zei->nmem); - data1_mk_tag_data_int (zei->dh, node_db, "id", - zdi->sysno, zei->nmem); - data1_mk_tag_data_int (zei->dh, node_db, "attributeDetailsId", - zdi->attributeDetails->sysno, zei->nmem); + data1_mk_tag_data_zint (zei->dh, node_db, "id", + zdi->sysno, zei->nmem); + data1_mk_tag_data_zint (zei->dh, node_db, "attributeDetailsId", + zdi->attributeDetails->sysno, zei->nmem); } data1_mk_tag_data_int (zei->dh, node_zebra, "ordinalSU", zei->ordinalSU, zei->nmem); - data1_mk_tag_data_int (zei->dh, node_zebra, "runNumber", - zei->runNumber, zei->nmem); + data1_mk_tag_data_zint (zei->dh, node_zebra, "runNumber", + zei->runNumber, zei->nmem); #if ZINFO_DEBUG data1_pr_tree (zei->dh, zei->data1_target, stderr); @@ -1204,6 +1310,19 @@ int zebraExplain_lookupSU (ZebraExplainInfo zei, int set, int use) return -1; } +int zebraExplain_trav_ord(ZebraExplainInfo zei, void *handle, + int (*f)(void *handle, int ord)) +{ + struct zebDatabaseInfoB *zdb = zei->curDatabaseInfo; + if (zdb) + { + struct zebSUInfoB *zsui = zdb->attributeDetails->SUInfo; + for ( ;zsui; zsui = zsui->next) + (*f)(handle, zsui->info.ordinal); + } + return 0; +} + int zebraExplain_lookup_ord (ZebraExplainInfo zei, int ord, const char **db, int *set, int *use) { @@ -1311,12 +1430,11 @@ void zebraExplain_recordCountIncrement (ZebraExplainInfo zei, int adjust_num) } } -int zebraExplain_runNumberIncrement (ZebraExplainInfo zei, int adjust_num) +zint zebraExplain_runNumberIncrement (ZebraExplainInfo zei, int adjust_num) { if (adjust_num) { zei->dirty = 1; - yaz_log (LOG_LOG, "zinfo run number=%d", zei->runNumber+adjust_num); } return zei->runNumber += adjust_num; } @@ -1341,7 +1459,7 @@ static void att_loadset(void *p, const char *n, const char *name) { data1_handle dh = (data1_handle) p; if (!data1_get_attset (dh, name)) - logf (LOG_WARN, "Directive attset failed for %s", name); + yaz_log (YLOG_WARN, "Directive attset failed for %s", name); } void zebraExplain_loadAttsets (data1_handle dh, Res res)