X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fzoom-record-cache.c;h=b999e59ce2166044e96edab4f64d55aac1eaac6a;hp=b9d7a1e2568d623c0bf170b0199a804ab47f9939;hb=ea0ffea1d02fe623b4da5b7b8aa972aa9f32f071;hpb=43a9d38d20c1b1bcd1a03b2445a501d27526bd35 diff --git a/src/zoom-record-cache.c b/src/zoom-record-cache.c index b9d7a1e..b999e59 100644 --- a/src/zoom-record-cache.c +++ b/src/zoom-record-cache.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2011 Index Data + * Copyright (C) Index Data * See the file LICENSE for details. */ /** @@ -49,16 +49,6 @@ struct ZOOM_record_cache_p { ZOOM_record_cache next; }; - -static int strcmp_null(const char *v1, const char *v2) -{ - if (!v1 && !v2) - return 0; - if (!v1 || !v2) - return -1; - return strcmp(v1, v2); -} - static size_t record_hash(int pos) { if (pos < 0) @@ -66,23 +56,25 @@ static size_t record_hash(int pos) return pos % RECORD_HASH_SIZE; } -void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr, - int pos, - const char *syntax, const char *elementSetName, - const char *schema, - Z_SRW_diagnostic *diag) +static ZOOM_record record_cache_add(ZOOM_resultset r, + Z_NamePlusRecord *npr, + int pos, + const char *syntax, + const char *elementSetName, + const char *schema, + Z_SRW_diagnostic *diag) { ZOOM_record_cache rc = 0; - + ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_RECV_RECORD); ZOOM_connection_put_event(r->connection, event); for (rc = r->record_hash[record_hash(pos)]; rc; rc = rc->next) { - if (pos == rc->pos - && strcmp_null(r->schema, rc->schema) == 0 - && strcmp_null(elementSetName,rc->elementSetName) == 0 - && strcmp_null(syntax, rc->syntax) == 0) + if (pos == rc->pos + && yaz_strcmp_null(schema, rc->schema) == 0 + && yaz_strcmp_null(elementSetName,rc->elementSetName) == 0 + && yaz_strcmp_null(syntax, rc->syntax) == 0) break; } if (!rc) @@ -96,15 +88,17 @@ void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr, rc->rec.wrbuf = 0; #endif rc->elementSetName = odr_strdup_null(r->odr, elementSetName); - + rc->syntax = odr_strdup_null(r->odr, syntax); - - rc->schema = odr_strdup_null(r->odr, r->schema); + + rc->schema = odr_strdup_null(r->odr, schema); rc->pos = pos; rc->next = r->record_hash[record_hash(pos)]; r->record_hash[record_hash(pos)] = rc; + } + rc->rec.npr = npr; rc->rec.schema = odr_strdup_null(r->odr, schema); rc->rec.diag_set = 0; @@ -121,30 +115,47 @@ void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr, *cp = '\0'; rc->rec.diag_uri = odr_strdup(r->odr, diag->uri); } - rc->rec.diag_message = odr_strdup_null(r->odr, diag->message); + rc->rec.diag_message = odr_strdup_null(r->odr, diag->message); rc->rec.diag_details = odr_strdup_null(r->odr, diag->details); } + return &rc->rec; +} + +void ZOOM_record_cache_add(ZOOM_resultset r, Z_NamePlusRecord *npr, + int pos, + const char *syntax, const char *elementSetName, + const char *schema, + Z_SRW_diagnostic *diag) +{ + record_cache_add(r, npr, pos, syntax, elementSetName, schema, diag); + ZOOM_memcached_add(r, npr, pos, syntax, elementSetName, schema, diag); } ZOOM_record ZOOM_record_cache_lookup(ZOOM_resultset r, int pos, const char *syntax, - const char *elementSetName) + const char *elementSetName, + const char *schema) { ZOOM_record_cache rc; - + Z_NamePlusRecord *npr; + for (rc = r->record_hash[record_hash(pos)]; rc; rc = rc->next) { if (pos == rc->pos) { - if (strcmp_null(r->schema, rc->schema)) + if (yaz_strcmp_null(schema, rc->schema)) continue; - if (strcmp_null(elementSetName,rc->elementSetName)) + if (yaz_strcmp_null(elementSetName,rc->elementSetName)) continue; - if (strcmp_null(syntax, rc->syntax)) + if (yaz_strcmp_null(syntax, rc->syntax)) continue; return &rc->rec; } } + npr = ZOOM_memcached_lookup(r, pos, syntax, elementSetName, schema); + if (npr) + return record_cache_add(r, npr, pos, syntax, elementSetName, + schema, 0); return 0; } @@ -160,7 +171,7 @@ ZOOM_API(ZOOM_record) if (!z_NamePlusRecord(odr_enc, &srec->npr, 0, 0)) return 0; buf = odr_getbuf(odr_enc, &size, 0); - + nrec = (ZOOM_record) xmalloc(sizeof(*nrec)); nrec->odr = odr_createmem(ODR_DECODE); #if SHPTR @@ -170,7 +181,7 @@ ZOOM_API(ZOOM_record) #endif odr_setbuf(nrec->odr, buf, size, 0); z_NamePlusRecord(nrec->odr, &nrec->npr, 0, 0); - + nrec->schema = odr_strdup_null(nrec->odr, srec->schema); nrec->diag_uri = odr_strdup_null(nrec->odr, srec->diag_uri); nrec->diag_message = odr_strdup_null(nrec->odr, srec->diag_message); @@ -217,10 +228,10 @@ ZOOM_API(const char *) ZOOM_record_get(ZOOM_record rec, const char *type_spec, int *len) { WRBUF wrbuf; - + if (len) *len = 0; /* default return */ - + if (!rec || !rec->npr) return 0; @@ -244,7 +255,7 @@ ZOOM_API(int) const char **addinfo, const char **diagset) { Z_NamePlusRecord *npr; - + if (!rec) return 0; @@ -269,7 +280,7 @@ ZOOM_API(int) { Z_DefaultDiagFormat *ddf = diag_rec->u.defaultFormat; oid_class oclass; - + error = *ddf->condition; switch (ddf->which) {