From: Adam Dickmeiss Date: Fri, 16 Oct 1998 08:14:28 +0000 (+0000) Subject: Updated record control system. X-Git-Tag: ZEBRA.1.0~161 X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=commitdiff_plain;h=75049be3951292bbbbd53d83ca38ccbd191e4b08 Updated record control system. --- diff --git a/include/recctrl.h b/include/recctrl.h index 4736bd8..d35c3ac 100644 --- a/include/recctrl.h +++ b/include/recctrl.h @@ -1,10 +1,13 @@ /* - * Copyright (C) 1994-1998, Index Data I/S + * Copyright (C) 1994-1998, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: recctrl.h,v $ - * Revision 1.26 1998-05-20 10:12:12 adam + * Revision 1.27 1998-10-16 08:14:28 adam + * Updated record control system. + * + * Revision 1.26 1998/05/20 10:12:12 adam * Implemented automatic EXPLAIN database maintenance. * Modified Zebra to work with ASN.1 compiled version of YAZ. * @@ -163,15 +166,25 @@ struct recRetrieveCtrl { char *message; }; -typedef struct recType +typedef struct recType *RecType; + +struct recType { - char *name; /* Name of record type */ - void (*init)(void); /* Init function - called once */ - int (*extract)(struct recExtractCtrl *ctrl); /* Extract proc */ - int (*retrieve)(struct recRetrieveCtrl *ctrl); /* Retrieve proc */ -} *RecType; + char *name; /* Name of record type */ + void (*init)(RecType recType); /* Init function - called once */ + void (*destroy)(RecType recType); /* Destroy function */ + int (*extract)(struct recExtractCtrl *ctrl); /* Extract proc */ + int (*retrieve)(struct recRetrieveCtrl *ctrl); /* Retrieve proc */ + void *clientData; /* data handle */ +}; + +typedef struct recTypes *RecTypes; + +RecTypes recTypes_init (data1_handle dh); +void recTypes_destroy (RecTypes recTypes); +void recTypes_default_handlers (RecTypes recTypes); -RecType recType_byName (const char *name, char *subType); +RecType recType_byName (RecTypes rts, const char *name, char *subType); int grs_extract_tree(struct recExtractCtrl *p, data1_node *n); diff --git a/index/extract.c b/index/extract.c index 711e360..de9e04f 100644 --- a/index/extract.c +++ b/index/extract.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: extract.c,v $ - * Revision 1.87 1998-10-15 13:10:33 adam + * Revision 1.88 1998-10-16 08:14:29 adam + * Updated record control system. + * + * Revision 1.87 1998/10/15 13:10:33 adam * Fixed bug in Zebra that caused it to stop indexing when empty * record was read. * @@ -1515,7 +1518,8 @@ int fileExtract (SYSNO *sysno, const char *fname, } if (!*rGroup->recordType) return 0; - if (!(recType = recType_byName (rGroup->recordType, subType))) + if (!(recType = + recType_byName (rGroup->recTypes, rGroup->recordType, subType))) { logf (LOG_WARN, "No such record type: %s", rGroup->recordType); return 0; diff --git a/index/index.h b/index/index.h index 6ba88da..2cf0f58 100644 --- a/index/index.h +++ b/index/index.h @@ -1,10 +1,13 @@ /* - * Copyright (C) 1995-1998, Index Data I/S + * Copyright (C) 1995-1998, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: index.h,v $ - * Revision 1.59 1998-06-08 14:43:11 adam + * Revision 1.60 1998-10-16 08:14:31 adam + * Updated record control system. + * + * Revision 1.59 1998/06/08 14:43:11 adam * Added suport for EXPLAIN Proxy servers - added settings databasePath * and explainDatabase to facilitate this. Increased maximum number * of databases and attributes in one register. @@ -223,6 +226,7 @@ #include #include #include +#include #define IT_MAX_WORD 256 #define IT_KEY_HAVE_SEQNO 1 @@ -250,7 +254,6 @@ struct dirs_entry { time_t mtime; }; - struct recordGroup { char *groupName; char *databaseName; @@ -266,6 +269,7 @@ struct recordGroup { data1_handle dh; BFiles bfs; ZebraMaps zebra_maps; + RecTypes recTypes; }; void getFnameTmp (char *fname, int no); diff --git a/index/main.c b/index/main.c index 149c9c8..45da827 100644 --- a/index/main.c +++ b/index/main.c @@ -1,10 +1,13 @@ /* - * Copyright (C) 1994-1998, Index Data I/S + * Copyright (C) 1994-1998, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: main.c,v $ - * Revision 1.58 1998-06-08 14:43:13 adam + * Revision 1.59 1998-10-16 08:14:32 adam + * Updated record control system. + * + * Revision 1.58 1998/06/08 14:43:13 adam * Added suport for EXPLAIN Proxy servers - added settings databasePath * and explainDatabase to facilitate this. Increased maximum number * of databases and attributes in one register. @@ -260,6 +263,8 @@ int main (int argc, char **argv) rGroupDef.fileVerboseLimit = 100000; rGroupDef.zebra_maps = NULL; rGroupDef.dh = data1_create (); + rGroupDef.recTypes = recTypes_init (rGroupDef.dh); + recTypes_default_handlers (rGroupDef.recTypes); prog = *argv; if (argc < 2) diff --git a/index/retrieve.c b/index/retrieve.c index f138bbf..2bdadcf 100644 --- a/index/retrieve.c +++ b/index/retrieve.c @@ -1,10 +1,13 @@ /* - * Copyright (C) 1995-1998, Index Data I/S + * Copyright (C) 1995-1998, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: retrieve.c,v $ - * Revision 1.1 1998-03-05 08:45:13 adam + * Revision 1.2 1998-10-16 08:14:33 adam + * Updated record control system. + * + * Revision 1.1 1998/03/05 08:45:13 adam * New result set model and modular ranking system. Moved towards * descent server API. System information stored as "SGML" records. * @@ -101,7 +104,7 @@ int zebra_record_fetch (ZebraHandle zh, int sysno, int score, ODR stream, *basenamep = odr_malloc (stream, strlen(basename)+1); strcpy (*basenamep, basename); - if (!(rt = recType_byName (file_type, subType))) + if (!(rt = recType_byName (zh->recTypes, file_type, subType))) { logf (LOG_WARN, "Retrieve: Cannot handle type %s", file_type); return 14; diff --git a/index/zebraapi.c b/index/zebraapi.c index 6f56a05..6bd19b9 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zebraapi.c,v $ - * Revision 1.10 1998-09-22 10:03:42 adam + * Revision 1.11 1998-10-16 08:14:34 adam + * Updated record control system. + * + * Revision 1.10 1998/09/22 10:03:42 adam * Changed result sets to be persistent in the sense that they can * be re-searched if needed. * Fixed memory leak in rsm_or. @@ -178,7 +181,9 @@ ZebraHandle zebra_open (const char *configName) zh->sets = NULL; zh->registerState = -1; /* trigger open of registers! */ zh->registerChange = 0; - + zh->recTypes = recTypes_init (zh->dh); + recTypes_default_handlers (zh->recTypes); + zh->records = NULL; zh->zebra_maps = zebra_maps_open (zh->res); zh->rank_classes = NULL; @@ -215,6 +220,7 @@ void zebra_close (ZebraHandle zh) rec_close (&zh->records); zebra_register_unlock (zh); } + recTypes_destroy (zh->recTypes); zebra_maps_close (zh->zebra_maps); zebraRankDestroy (zh); bfs_destroy (zh->bfs); diff --git a/index/zserver.h b/index/zserver.h index 7bebbad..43de5fe 100644 --- a/index/zserver.h +++ b/index/zserver.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zserver.h,v $ - * Revision 1.38 1998-09-22 10:03:44 adam + * Revision 1.39 1998-10-16 08:14:35 adam + * Updated record control system. + * + * Revision 1.38 1998/09/22 10:03:44 adam * Changed result sets to be persistent in the sense that they can * be re-searched if needed. * Fixed memory leak in rsm_or. @@ -199,6 +202,7 @@ struct zebra_info { #endif ZebraMaps zebra_maps; ZebraRankClass rank_classes; + RecTypes recTypes; Passwd_db passwd_db; }; diff --git a/recctrl/recctrl.c b/recctrl/recctrl.c index b0e7b9b..cd4359b 100644 --- a/recctrl/recctrl.c +++ b/recctrl/recctrl.c @@ -1,10 +1,13 @@ /* - * Copyright (C) 1994-1996, Index Data I/S + * Copyright (C) 1994-1998, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: recctrl.c,v $ - * Revision 1.2 1996-10-29 14:03:16 adam + * Revision 1.3 1998-10-16 08:14:36 adam + * Updated record control system. + * + * Revision 1.2 1996/10/29 14:03:16 adam * Include zebrautl.h instead of alexutil.h. * * Revision 1.1 1996/10/11 10:57:24 adam @@ -37,8 +40,50 @@ #include "rectext.h" #include "recgrs.h" -RecType recType_byName (const char *name, char *subType) +struct recTypeEntry { + RecType recType; + struct recTypeEntry *next; + int init_flag; +}; + +struct recTypes { + data1_handle dh; + struct recTypeEntry *entries; +}; + +RecTypes recTypes_init (data1_handle dh) +{ + RecTypes p = (RecTypes) nmem_malloc (data1_nmem_get (dh), sizeof(*p)); + + p->dh = dh; + p->entries = 0; + return p; +} + +void recTypes_destroy (RecTypes rts) +{ + struct recTypeEntry *rte; + + for (rte = rts->entries; rte; rte = rte->next) + if (rte->init_flag) + (*(rte->recType)->destroy)(rte->recType); +} + +void recTypes_add_handler (RecTypes rts, RecType rt) { + struct recTypeEntry *rte; + + rte = nmem_malloc (data1_nmem_get (rts->dh), sizeof(*rte)); + + rte->recType = rt; + rte->init_flag = 0; + rte->next = rts->entries; + rts->entries = rte; +} + +RecType recType_byName (RecTypes rts, const char *name, char *subType) +{ + struct recTypeEntry *rte; char *p; char tmpname[256]; @@ -50,10 +95,21 @@ RecType recType_byName (const char *name, char *subType) } else *subType = '\0'; - if (!strcmp (recTypeGrs->name, tmpname)) - return recTypeGrs; - if (!strcmp (recTypeText->name, tmpname)) - return recTypeText; - return NULL; + for (rte = rts->entries; rte; rte = rte->next) + if (!strcmp (rte->recType->name, tmpname)) + { + if (!rte->init_flag) + { + rte->init_flag = 1; + (*(rte->recType)->init)(rte->recType); + } + return rte->recType; + } + return 0; } +void recTypes_default_handlers (RecTypes rts) +{ + recTypes_add_handler (rts, recTypeGrs); + recTypes_add_handler (rts, recTypeText); +} diff --git a/recctrl/recgrs.c b/recctrl/recgrs.c index 0b7feea..6d0327b 100644 --- a/recctrl/recgrs.c +++ b/recctrl/recgrs.c @@ -1,10 +1,13 @@ /* - * Copyright (C) 1994-1998, Index Data I/S + * Copyright (C) 1994-1998, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: recgrs.c,v $ - * Revision 1.21 1998-07-01 09:16:10 adam + * Revision 1.22 1998-10-16 08:14:37 adam + * Updated record control system. + * + * Revision 1.21 1998/07/01 09:16:10 adam * Element localno only added when it's greater than 0. * * Revision 1.20 1998/05/20 10:12:26 adam @@ -201,7 +204,11 @@ static data1_node *read_grs_type (struct grs_read_info *p, const char *type) return NULL; } -static void grs_init(void) +static void grs_init(RecType recType) +{ +} + +static void grs_destroy(RecType recType) { } @@ -648,6 +655,7 @@ static struct recType grs_type = { "grs", grs_init, + grs_destroy, grs_extract, grs_retrieve }; diff --git a/recctrl/rectext.c b/recctrl/rectext.c index cd78a76..4c27522 100644 --- a/recctrl/rectext.c +++ b/recctrl/rectext.c @@ -1,10 +1,13 @@ /* - * Copyright (C) 1994-1998, Index Data I/S + * Copyright (C) 1994-1998, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: rectext.c,v $ - * Revision 1.8 1998-05-20 10:12:27 adam + * Revision 1.9 1998-10-16 08:14:38 adam + * Updated record control system. + * + * Revision 1.8 1998/05/20 10:12:27 adam * Implemented automatic EXPLAIN database maintenance. * Modified Zebra to work with ASN.1 compiled version of YAZ. * @@ -64,7 +67,11 @@ #include #include "rectext.h" -static void text_init (void) +static void text_init (RecType recType) +{ +} + +static void text_destroy (RecType recType) { } @@ -211,6 +218,7 @@ static int text_retrieve (struct recRetrieveCtrl *p) static struct recType text_type = { "text", text_init, + text_destroy, text_extract, text_retrieve };