X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zutil%2Fzoom-c.c;h=648fba2beb2767935be940c60b062efa97f5e6be;hb=94c77ca831e55b3dee31184347f25dd0583085d2;hp=1d6a2f2fb3abec34624b6be149b2d431b4b42c2c;hpb=660689d0e3d249b5d6c10fa695e621ec5b8e36a9;p=yaz-moved-to-github.git diff --git a/zutil/zoom-c.c b/zutil/zoom-c.c index 1d6a2f2..648fba2 100644 --- a/zutil/zoom-c.c +++ b/zutil/zoom-c.c @@ -2,7 +2,7 @@ * Copyright (c) 2000-2003, Index Data * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.36 2003-05-30 10:24:58 adam Exp $ + * $Id: zoom-c.c,v 1.39 2003-07-14 12:59:23 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -604,6 +604,8 @@ ZOOM_resultset_destroy(ZOOM_resultset r) wrbuf_free (rc->rec.wrbuf_marc, 1); if (rc->rec.wrbuf_iconv) wrbuf_free (rc->rec.wrbuf_iconv, 1); + if (rc->rec.wrbuf_opac) + wrbuf_free (rc->rec.wrbuf_opac, 1); } if (r->connection) { @@ -1199,7 +1201,6 @@ static zoom_ret ZOOM_connection_send_search (ZOOM_connection c) *search_req->largeSetLowerBound = 2000000000; *search_req->smallSetUpperBound = 0; *search_req->mediumSetPresentNumber = r->step>0 ? r->step : r->count; - smallSetElementSetName = 0; } else { @@ -1305,9 +1306,7 @@ ZOOM_record_clone (ZOOM_record srec) nrec->odr = odr_createmem(ODR_DECODE); nrec->wrbuf_marc = 0; nrec->wrbuf_iconv = 0; - nrec->record_charset = 0; - if (srec->record_charset) - nrec->record_charset = odr_strdup(nrec->odr, srec->record_charset); + nrec->wrbuf_opac = 0; odr_setbuf (nrec->odr, buf, size, 0); z_NamePlusRecord (nrec->odr, &nrec->npr, 0, 0); @@ -1341,12 +1340,17 @@ ZOOM_record_destroy (ZOOM_record rec) return; if (rec->wrbuf_marc) wrbuf_free (rec->wrbuf_marc, 1); + if (rec->wrbuf_iconv) + wrbuf_free (rec->wrbuf_iconv, 1); + if (rec->wrbuf_opac) + wrbuf_free (rec->wrbuf_opac, 1); odr_destroy (rec->odr); xfree (rec); } static const char *record_iconv_return(ZOOM_record rec, int *len, - const char *buf, int sz) + const char *buf, int sz, + const char *record_charset) { char to[40]; char from[40]; @@ -1354,26 +1358,26 @@ static const char *record_iconv_return(ZOOM_record rec, int *len, *from = '\0'; strcpy(to, "UTF-8"); - if (rec->record_charset) + if (record_charset && *record_charset) { /* Use "from,to" or just "from" */ - const char *cp =strchr(rec->record_charset, ','); - int clen = strlen(rec->record_charset); + const char *cp =strchr(record_charset, ','); + int clen = strlen(record_charset); if (cp && cp[1]) { strncpy( to, cp+1, sizeof(to)-1); to[sizeof(to)-1] = '\0'; - clen = cp - rec->record_charset; + clen = cp - record_charset; } if (clen > sizeof(from)-1) clen = sizeof(from)-1; if (clen) - strncpy(from, rec->record_charset, clen); + strncpy(from, record_charset, clen); from[clen] = '\0'; } - if (*from && *to && (cd = yaz_iconv_open("UTF-8", rec->record_charset))) + if (*from && *to && (cd = yaz_iconv_open(to, from))) { char outbuf[12]; size_t inbytesleft = sz; @@ -1410,8 +1414,12 @@ static const char *record_iconv_return(ZOOM_record rec, int *len, } ZOOM_API(const char *) -ZOOM_record_get (ZOOM_record rec, const char *type, int *len) +ZOOM_record_get (ZOOM_record rec, const char *type_spec, int *len) { + char type[40]; + char charset[40]; + const char *cp; + int i; Z_NamePlusRecord *npr; if (len) @@ -1422,6 +1430,34 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) npr = rec->npr; if (!npr) return 0; + + cp = type_spec; + for (i = 0; cp[i] && i < sizeof(type)-1; i++) + { + if (cp[i] == ';' || cp[i] == ' ') + break; + type[i] = cp[i]; + } + type[i] = '\0'; + charset[0] = '\0'; + if (type_spec[i] == ';') + { + i++; + while (type_spec[i] == ' ') + i++; + if (!strncmp(type_spec+i, "charset=", 8)) + { + cp = type_spec+i+8; + for (i = 0; cp[i] && i < sizeof(charset)-1; i++) + { + if (cp[i] == ';' || cp[i] == ' ') + break; + charset[i] = cp[i]; + } + charset[i] = '\0'; + } + } + if (!strcmp (type, "database")) { if (len) @@ -1449,10 +1485,19 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) { Z_External *r = (Z_External *) npr->u.databaseRecord; oident *ent = oid_getentbyoid(r->direct_reference); - + + /* render bibliographic record .. */ + if (r->which == Z_External_OPAC) + { + r = r->u.opac->bibliographicRecord; + if (!r) + return 0; + ent = oid_getentbyoid(r->direct_reference); + } if (r->which == Z_External_sutrs) return record_iconv_return(rec, len, - r->u.sutrs->buf, r->u.sutrs->len); + r->u.sutrs->buf, r->u.sutrs->len, + charset); else if (r->which == Z_External_octet) { yaz_marc_t mt; @@ -1479,13 +1524,15 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) yaz_marc_destroy(mt); return record_iconv_return(rec, len, wrbuf_buf(rec->wrbuf_marc), - wrbuf_len(rec->wrbuf_marc)); + wrbuf_len(rec->wrbuf_marc), + charset); } yaz_marc_destroy(mt); } return record_iconv_return(rec, len, (const char *) r->u.octet_aligned->buf, - r->u.octet_aligned->len); + r->u.octet_aligned->len, + charset); } else if (r->which == Z_External_grs1) { @@ -1495,7 +1542,8 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) yaz_display_grs1(rec->wrbuf_marc, r->u.grs1, 0); return record_iconv_return(rec, len, wrbuf_buf(rec->wrbuf_marc), - wrbuf_len(rec->wrbuf_marc)); + wrbuf_len(rec->wrbuf_marc), + charset); } return 0; } @@ -1504,11 +1552,21 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) { Z_External *r = (Z_External *) npr->u.databaseRecord; oident *ent = oid_getentbyoid(r->direct_reference); + + /* render bibliographic record .. */ + if (r->which == Z_External_OPAC) + { + r = r->u.opac->bibliographicRecord; + if (!r) + return 0; + ent = oid_getentbyoid(r->direct_reference); + } if (r->which == Z_External_sutrs) return record_iconv_return(rec, len, (const char *) r->u.sutrs->buf, - r->u.sutrs->len); + r->u.sutrs->len, + charset); else if (r->which == Z_External_octet) { yaz_marc_t mt; @@ -1540,24 +1598,21 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) yaz_marc_destroy(mt); return record_iconv_return(rec, len, wrbuf_buf(rec->wrbuf_marc), - wrbuf_len(rec->wrbuf_marc)); + wrbuf_len(rec->wrbuf_marc), + charset); } yaz_marc_destroy(mt); } return record_iconv_return(rec, len, (const char *) r->u.octet_aligned->buf, - r->u.octet_aligned->len); + r->u.octet_aligned->len, + charset); } else if (r->which == Z_External_grs1) { if (len) *len = 5; return "GRS-1"; } - else if (r->which == Z_External_OPAC) - { - if (len) *len = 4; - return "OPAC"; - } return 0; } else if (!strcmp (type, "raw")) @@ -1576,7 +1631,7 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) if (len) *len = r->u.octet_aligned->len; return (const char *) r->u.octet_aligned->buf; } - else /* grs-1, explain, ... */ + else /* grs-1, explain, OPAC, ... */ { if (len) *len = -1; return (const char *) npr->u.databaseRecord; @@ -1590,6 +1645,23 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) return (const char *) npr->u.databaseRecord; return 0; } + else if (npr->which == Z_NamePlusRecord_databaseRecord && + !strcmp (type, "opac")) + + { + Z_External *r = (Z_External *) npr->u.databaseRecord; + if (r->which == Z_External_OPAC) + { + if (!rec->wrbuf_opac) + rec->wrbuf_opac = wrbuf_alloc(); + wrbuf_rewind (rec->wrbuf_opac); + yaz_display_OPAC(rec->wrbuf_opac, r->u.opac, 0); + return record_iconv_return(rec, len, + wrbuf_buf(rec->wrbuf_opac), + wrbuf_len(rec->wrbuf_opac), + charset); + } + } return 0; } @@ -1610,8 +1682,6 @@ static void record_cache_add (ZOOM_resultset r, Z_NamePlusRecord *npr, ZOOM_resultset_option_get (r, "elementSetName"); const char *syntax = ZOOM_resultset_option_get (r, "preferredRecordSyntax"); - const char *recordCharset = - ZOOM_resultset_option_get (r, "recordCharset"); ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_RECV_RECORD); ZOOM_connection_put_event(r->connection, event); @@ -1626,8 +1696,6 @@ static void record_cache_add (ZOOM_resultset r, Z_NamePlusRecord *npr, continue; if (strcmp_null(syntax, rc->syntax)) continue; - if (strcmp_null(recordCharset, rc->rec.record_charset)) - continue; /* not destroying rc->npr (it's handled by nmem )*/ rc->rec.npr = npr; /* keeping wrbuf_marc too */ @@ -1639,6 +1707,7 @@ static void record_cache_add (ZOOM_resultset r, Z_NamePlusRecord *npr, rc->rec.odr = 0; rc->rec.wrbuf_marc = 0; rc->rec.wrbuf_iconv = 0; + rc->rec.wrbuf_opac = 0; if (elementSetName) rc->elementSetName = odr_strdup (r->odr, elementSetName); else @@ -1654,10 +1723,6 @@ static void record_cache_add (ZOOM_resultset r, Z_NamePlusRecord *npr, else rc->schema = 0; - rc->rec.record_charset = 0; - if (recordCharset) - rc->rec.record_charset = odr_strdup(r->odr, recordCharset); - rc->pos = pos; rc->next = r->record_cache; r->record_cache = rc;