#include <yaz/querytowrbuf.h>
#include <yaz/oid_db.h>
#include <yaz/diagbib1.h>
+#include <yaz/snprintf.h>
#define USE_TIMING 0
#if USE_TIMING
elements = cl->show_raw->esn;
else
elements = session_setting_oneval(sdb, PZ_ELEMENTS);
- ZOOM_resultset_option_set(set, "elementSetName", elements);
+ if (elements && *elements)
+ ZOOM_resultset_option_set(set, "elementSetName", elements);
- ZOOM_resultset_records(set, 0, offset, 1);
+ ZOOM_resultset_records(set, 0, offset-1, 1);
cl->show_raw->active = 1;
- ZOOM_connection_process(connection_get_link(co));
+
+ connection_continue(co);
+}
+
+static void ingest_raw_record(struct client *cl, ZOOM_record rec)
+{
+ const char *buf;
+ int len;
+ char type[50];
+
+ if (cl->show_raw->binary)
+ strcpy(type, "raw");
+ else
+ {
+ struct session_database *sdb = client_get_database(cl);
+ const char *cset;
+
+ const char *nativesyntax = session_setting_oneval(sdb, PZ_NATIVESYNTAX);
+ if (*nativesyntax && (cset = strchr(nativesyntax, ';')))
+ yaz_snprintf(type, sizeof(type)-1, "xml; charset=%s", cset);
+ else
+ strcpy(type, "xml");
+ }
+
+ buf = ZOOM_record_get(rec, type, &len);
+ cl->show_raw->record_handler(cl->show_raw->data, buf, len);
+ client_show_raw_dequeue(cl);
}
#ifdef RETIRED
ZOOM_resultset resultset = connection_get_resultset(co);
const char *error, *addinfo;
+ yaz_log(YLOG_LOG, "client_record_response");
if (ZOOM_connection_error(link, &error, &addinfo))
{
cl->state = Client_Error;
ZOOM_record rec;
int offset = cl->records;
const char *msg, *addinfo;
-
+
if ((rec = ZOOM_resultset_record(resultset, offset)))
{
yaz_log(YLOG_LOG, "Record with offset %d", offset);
- cl->records++;
- if (ZOOM_record_error(rec, &msg, &addinfo, 0))
- yaz_log(YLOG_WARN, "Record error %s (%s): %s (rec #%d)",
- error, addinfo, client_get_url(cl), cl->records);
+
+ yaz_log(YLOG_LOG, "show_raw=%p show_raw->active=%d",
+ cl->show_raw, cl->show_raw ? cl->show_raw->active : 0);
+ if (cl->show_raw && cl->show_raw->active)
+ {
+ cl->show_raw->active = 0;
+ ingest_raw_record(cl, rec);
+ }
else
{
- struct session_database *sdb = client_get_database(cl);
- const char *xmlrec;
- char type[128] = "xml";
- const char *nativesyntax =
- session_setting_oneval(sdb, PZ_NATIVESYNTAX);
- char *cset;
-
- if (*nativesyntax && (cset = strchr(nativesyntax, ';')))
- sprintf(type, "xml; charset=%s", cset + 1);
-
- if ((xmlrec = ZOOM_record_get(rec, type, NULL)))
+ cl->records++;
+ if (ZOOM_record_error(rec, &msg, &addinfo, 0))
+ yaz_log(YLOG_WARN, "Record error %s (%s): %s (rec #%d)",
+ error, addinfo, client_get_url(cl), cl->records);
+ else
{
- if (ingest_record(cl, xmlrec, cl->records))
+ struct session_database *sdb = client_get_database(cl);
+ const char *xmlrec;
+ char type[128] = "xml";
+ const char *nativesyntax =
+ session_setting_oneval(sdb, PZ_NATIVESYNTAX);
+ char *cset;
+
+ if (*nativesyntax && (cset = strchr(nativesyntax, ';')))
+ sprintf(type, "xml; charset=%s", cset + 1);
+
+ if ((xmlrec = ZOOM_record_get(rec, type, NULL)))
{
- session_alert_watch(cl->session, SESSION_WATCH_SHOW);
- session_alert_watch(cl->session, SESSION_WATCH_RECORD);
+ if (ingest_record(cl, xmlrec, cl->records))
+ {
+ session_alert_watch(cl->session, SESSION_WATCH_SHOW);
+ session_alert_watch(cl->session, SESSION_WATCH_RECORD);
+ }
+ else
+ yaz_log(YLOG_WARN, "Failed to ingest");
}
else
- yaz_log(YLOG_WARN, "Failed to ingest");
+ yaz_log(YLOG_WARN, "Failed to extract ZOOM record");
}
- else
- yaz_log(YLOG_WARN, "Failed to extract ZOOM record");
}
}
rs = ZOOM_connection_search_pqf(link, cl->pquery);
connection_set_resultset(co, rs);
- ZOOM_connection_process(link);
+ connection_continue(co);
}
struct client *client_create(void)
assert(*conp == 0);
}
+void connection_continue(struct connection *co)
+{
+#if 1
+ yaz_log(YLOG_LOG, "connection_continue");
+ iochan_setevent(co->iochan, EVENT_OUTPUT);
+#endif
+}
+
// Close connection and recycle structure
void connection_destroy(struct connection *co)
{
if (ZOOM_event(1, &link))
{
- do {
+ do
+ {
int event = ZOOM_connection_last_event(link);
switch (event)
{
- case ZOOM_EVENT_END:
- break;
- case ZOOM_EVENT_SEND_DATA:
- break;
- case ZOOM_EVENT_RECV_DATA:
- break;
- case ZOOM_EVENT_UNKNOWN:
- break;
- case ZOOM_EVENT_SEND_APDU:
- client_set_state(co->client, Client_Working);
- break;
- case ZOOM_EVENT_RECV_APDU:
- client_set_state(co->client, Client_Idle);
- break;
- case ZOOM_EVENT_CONNECT:
- yaz_log(YLOG_LOG, "Connected to %s", client_get_url(cl));
- co->state = Conn_Open;
- client_set_state(co->client, Client_Connected);
- iochan_settimeout(i, global_parameters.z3950_session_timeout);
- break;
- case ZOOM_EVENT_RECV_SEARCH:
- yaz_log(YLOG_LOG, "Search response from %s", client_get_url(cl));
- client_search_response(cl);
- break;
- case ZOOM_EVENT_RECV_RECORD:
- yaz_log(YLOG_LOG, "Record from %s", client_get_url(cl));
- client_record_response(cl);
- break;
- default:
- yaz_log(YLOG_LOG, "Unhandled event (%d) from %s",
+ case ZOOM_EVENT_END:
+ break;
+ case ZOOM_EVENT_SEND_DATA:
+ break;
+ case ZOOM_EVENT_RECV_DATA:
+ break;
+ case ZOOM_EVENT_UNKNOWN:
+ break;
+ case ZOOM_EVENT_SEND_APDU:
+ client_set_state(co->client, Client_Working);
+ break;
+ case ZOOM_EVENT_RECV_APDU:
+ client_set_state(co->client, Client_Idle);
+ break;
+ case ZOOM_EVENT_CONNECT:
+ yaz_log(YLOG_LOG, "Connected to %s", client_get_url(cl));
+ co->state = Conn_Open;
+ client_set_state(co->client, Client_Connected);
+ iochan_settimeout(i, global_parameters.z3950_session_timeout);
+ break;
+ case ZOOM_EVENT_RECV_SEARCH:
+ yaz_log(YLOG_LOG, "Search response from %s", client_get_url(cl));
+ client_search_response(cl);
+ break;
+ case ZOOM_EVENT_RECV_RECORD:
+ yaz_log(YLOG_LOG, "Record from %s", client_get_url(cl));
+ client_record_response(cl);
+ break;
+ default:
+ yaz_log(YLOG_LOG, "Unhandled event (%d) from %s",
event, client_get_url(cl));
}
}
- while(ZOOM_event_nonblock(1, &link));
+ while (ZOOM_event_nonblock(1, &link));
}
}
}