#include <yaz/copy_types.h>
#include <yaz/snprintf.h>
+#include <yaz/shptr.h>
+
+#if SHPTR
+YAZ_SHPTR_TYPE(WRBUF)
+#endif
+
static int log_api = 0;
static int log_details = 0;
r->num_databaseNames = 0;
r->mutex = 0;
yaz_mutex_create(&r->mutex);
+#if SHPTR
+ {
+ WRBUF w = wrbuf_alloc();
+ YAZ_SHPTR_INIT(r->record_wrbuf, w);
+ }
+#endif
return r;
}
{
if (!rec)
return;
+
+#if SHPTR
+ if (rec->record_wrbuf)
+ YAZ_SHPTR_DEC(rec->record_wrbuf, wrbuf_destroy);
+#else
if (rec->wrbuf)
wrbuf_destroy(rec->wrbuf);
+#endif
+
#if YAZ_HAVE_XML2
if (rec->xml_mem)
xmlFree(rec->xml_mem);
if (r->refcount == 0)
{
yaz_mutex_leave(r->mutex);
+
yaz_log(log_details, "%p ZOOM_connection resultset_destroy: Deleting resultset (%p) ", r->connection, r);
ZOOM_resultset_cache_reset(r);
ZOOM_query_destroy(r->query);
xfree(r->setname);
xfree(r->schema);
yaz_mutex_destroy(&r->mutex);
+#if SHPTR
+ YAZ_SHPTR_DEC(r->record_wrbuf, wrbuf_destroy);
+#endif
xfree(r);
}
else
nrec = (ZOOM_record) xmalloc(sizeof(*nrec));
nrec->odr = odr_createmem(ODR_DECODE);
+#if SHPTR
+ nrec->record_wrbuf = 0;
+#else
nrec->wrbuf = 0;
+#endif
#if YAZ_HAVE_XML2
nrec->xml_mem = 0;
nrec->xml_size = 0;
return cd;
}
-static const char *return_marc_record(ZOOM_record rec, int marc_type,
+static const char *return_marc_record(ZOOM_record rec, WRBUF wrbuf,
+ int marc_type,
int *len,
const char *buf, int sz,
const char *record_charset)
if (cd)
yaz_marc_iconv(mt, cd);
yaz_marc_xml(mt, marc_type);
- if (!rec->wrbuf)
- rec->wrbuf = wrbuf_alloc();
- wrbuf_rewind(rec->wrbuf);
- if (yaz_marc_decode_wrbuf(mt, buf, sz, rec->wrbuf) > 0)
+ if (yaz_marc_decode_wrbuf(mt, buf, sz, wrbuf) > 0)
{
if (len)
- *len = wrbuf_len(rec->wrbuf);
- ret_string = wrbuf_cstr(rec->wrbuf);
+ *len = wrbuf_len(wrbuf);
+ ret_string = wrbuf_cstr(wrbuf);
}
yaz_marc_destroy(mt);
if (cd)
return ret_string;
}
-static const char *return_opac_record(ZOOM_record rec, int marc_type,
+static const char *return_opac_record(ZOOM_record rec, WRBUF wrbuf,
+ int marc_type,
int *len,
Z_OPACRecord *opac_rec,
const char *record_charset)
yaz_marc_iconv(mt, cd);
yaz_marc_xml(mt, marc_type);
- if (!rec->wrbuf)
- rec->wrbuf = wrbuf_alloc();
- wrbuf_rewind(rec->wrbuf);
-
- yaz_opac_decode_wrbuf(mt, opac_rec, rec->wrbuf);
+ yaz_opac_decode_wrbuf(mt, opac_rec, wrbuf);
yaz_marc_destroy(mt);
if (cd)
yaz_iconv_close(cd);
if (len)
- *len = wrbuf_len(rec->wrbuf);
- return wrbuf_cstr(rec->wrbuf);
+ *len = wrbuf_len(wrbuf);
+ return wrbuf_cstr(wrbuf);
}
-static const char *return_string_record(ZOOM_record rec, int *len,
+static const char *return_string_record(ZOOM_record rec, WRBUF wrbuf,
+ int *len,
const char *buf, int sz,
const char *record_charset)
{
if (cd)
{
- if (!rec->wrbuf)
- rec->wrbuf = wrbuf_alloc();
-
- wrbuf_rewind(rec->wrbuf);
+ wrbuf_iconv_write(wrbuf, cd, buf, sz);
+ wrbuf_iconv_reset(wrbuf, cd);
- wrbuf_iconv_write(rec->wrbuf, cd, buf, sz);
- wrbuf_iconv_reset(rec->wrbuf, cd);
-
- buf = wrbuf_cstr(rec->wrbuf);
- sz = wrbuf_len(rec->wrbuf);
+ buf = wrbuf_cstr(wrbuf);
+ sz = wrbuf_len(wrbuf);
yaz_iconv_close(cd);
}
if (len)
{
Z_External *r = (Z_External *) npr->u.databaseRecord;
const Odr_oid *oid = r->direct_reference;
-
+ WRBUF wrbuf;
+
+#if SHPTR
+ if (!rec->record_wrbuf)
+ {
+ WRBUF w = wrbuf_alloc();
+ YAZ_SHPTR_INIT(rec->record_wrbuf, w);
+ }
+ wrbuf = rec->record_wrbuf->ptr;
+#else
+ if (!rec->wrbuf)
+ rec->wrbuf = wrbuf_alloc();
+ wrbuf = rec->wrbuf;
+#endif
+ wrbuf_rewind(wrbuf);
/* render bibliographic record .. */
if (r->which == Z_External_OPAC)
{
- return return_opac_record(rec, marctype, len,
+ return return_opac_record(rec, wrbuf, marctype, len,
r->u.opac, charset);
}
if (r->which == Z_External_sutrs)
- return return_string_record(rec, len,
+ return return_string_record(rec, wrbuf, len,
(char*) r->u.sutrs->buf,
r->u.sutrs->len,
charset);
if (yaz_oid_is_iso2709(oid))
{
const char *ret_buf = return_marc_record(
- rec, marctype, len,
+ rec, wrbuf, marctype, len,
(const char *) r->u.octet_aligned->buf,
r->u.octet_aligned->len,
charset);
if (marctype != YAZ_MARC_ISO2709)
return 0;
}
- return return_string_record(rec, len,
+ return return_string_record(rec, wrbuf, len,
(const char *) r->u.octet_aligned->buf,
r->u.octet_aligned->len,
charset);
}
else if (r->which == Z_External_grs1)
{
- if (!rec->wrbuf)
- rec->wrbuf = wrbuf_alloc();
- wrbuf_rewind(rec->wrbuf);
- yaz_display_grs1(rec->wrbuf, r->u.grs1, 0);
- return return_string_record(rec, len,
- wrbuf_buf(rec->wrbuf),
- wrbuf_len(rec->wrbuf),
+ yaz_display_grs1(wrbuf, r->u.grs1, 0);
+ return return_string_record(rec, wrbuf, len,
+ wrbuf_buf(wrbuf),
+ wrbuf_len(wrbuf),
charset);
}
return 0;
{
rc = (ZOOM_record_cache) odr_malloc(r->odr, sizeof(*rc));
rc->rec.odr = 0;
+#if SHPTR
+ YAZ_SHPTR_INC(r->record_wrbuf);
+ rc->rec.record_wrbuf = r->record_wrbuf;
+#else
rc->rec.wrbuf = 0;
+#endif
#if YAZ_HAVE_XML2
rc->rec.xml_mem = 0;
#endif