From 043c2f97c9b6fa76fbe50c27c4d145a0f16e9e82 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 21 Jul 2008 16:43:29 +0200 Subject: [PATCH] More work on contination/raw present --- src/client.c | 92 +++++++++++++++++++++++++++++++++++++++--------------- src/connection.c | 73 ++++++++++++++++++++++++------------------- src/connection.h | 1 + 3 files changed, 108 insertions(+), 58 deletions(-) diff --git a/src/client.c b/src/client.c index 5e91783..c978474 100644 --- a/src/client.c +++ b/src/client.c @@ -57,6 +57,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #define USE_TIMING 0 #if USE_TIMING @@ -293,11 +294,38 @@ static void client_send_raw_present(struct client *cl) 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 @@ -393,6 +421,7 @@ void client_record_response(struct client *cl) 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; @@ -404,38 +433,49 @@ void client_record_response(struct client *cl) 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"); } } @@ -579,7 +619,7 @@ void client_start_search(struct client *cl) 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) diff --git a/src/connection.c b/src/connection.c index 11de6b2..155619f 100644 --- a/src/connection.c +++ b/src/connection.c @@ -133,6 +133,14 @@ static void remove_connection_from_host(struct connection *con) 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) { @@ -221,44 +229,45 @@ static void connection_handler(IOCHAN i, int event) 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)); } } } diff --git a/src/connection.h b/src/connection.h index e0392f3..86b0ebf 100644 --- a/src/connection.h +++ b/src/connection.h @@ -48,6 +48,7 @@ void connection_release(struct connection *co); ZOOM_connection connection_get_link(struct connection *co); ZOOM_resultset connection_get_resultset(struct connection *co); void connection_set_resultset(struct connection *co, ZOOM_resultset rs); +void connection_continue(struct connection *co); #endif -- 1.7.10.4