+void Yaz_Proxy::convert_records_charset(Z_NamePlusRecordList *p,
+ const char *backend_charset)
+{
+ yaz_log(YLOG_LOG, "%sconvert_to_marc", m_session_str);
+ int sel = m_charset_converter->get_client_charset_selected();
+ const char *client_record_charset =
+ m_charset_converter->get_client_query_charset();
+ if (sel && backend_charset && client_record_charset &&
+ strcmp(backend_charset, client_record_charset))
+ {
+ int i;
+ yaz_iconv_t cd = yaz_iconv_open(client_record_charset,
+ backend_charset);
+ yaz_marc_t mt = yaz_marc_create();
+ yaz_marc_xml(mt, YAZ_MARC_ISO2709);
+ yaz_marc_iconv(mt, cd);
+ for (i = 0; i < p->num_records; i++)
+ {
+ Z_NamePlusRecord *npr = p->records[i];
+ if (npr->which == Z_NamePlusRecord_databaseRecord)
+ {
+ Z_External *r = npr->u.databaseRecord;
+ oident *ent = oid_getentbyoid(r->direct_reference);
+ if (!ent || ent->value == VAL_NONE)
+ continue;
+
+ if (ent->value == VAL_SUTRS)
+ {
+ WRBUF w = wrbuf_alloc();
+
+ wrbuf_iconv_write(w, cd, (char*) r->u.octet_aligned->buf,
+ r->u.octet_aligned->len);
+ npr->u.databaseRecord =
+ z_ext_record(odr_encode(), ent->value, wrbuf_buf(w),
+ wrbuf_len(w));
+ wrbuf_free(w, 1);
+ }
+ else if (ent->value == VAL_TEXT_XML)
+ {
+ ;
+ }
+ else if (r->which == Z_External_octet)
+ {
+ int rlen;
+ char *result;
+ if (yaz_marc_decode_buf(mt,
+ (char*) r->u.octet_aligned->buf,
+ r->u.octet_aligned->len,
+ &result, &rlen))
+ {
+ npr->u.databaseRecord =
+ z_ext_record(odr_encode(), ent->value, result, rlen);
+ yaz_log(YLOG_LOG, "%sRecoding MARC record",
+ m_session_str);
+ }
+ }
+ }
+ }
+ if (cd)
+ yaz_iconv_close(cd);
+ yaz_marc_destroy(mt);
+ }
+ else
+ {
+ yaz_log(YLOG_LOG, "%sSkipping marc convert", m_session_str);
+ }
+}
+