+int client_show_raw_begin(struct client *cl, int position,
+ const char *syntax, const char *esn,
+ void *data,
+ void (*error_handler)(void *data, const char *addinfo),
+ void (*record_handler)(void *data, const char *buf,
+ size_t sz))
+{
+ if (cl->show_raw)
+ return -1;
+ cl->show_raw = xmalloc(sizeof(*cl->show_raw));
+ cl->show_raw->position = position;
+ cl->show_raw->active = 0;
+ cl->show_raw->data = data;
+ cl->show_raw->error_handler = error_handler;
+ cl->show_raw->record_handler = record_handler;
+ if (syntax)
+ cl->show_raw->syntax = xstrdup(syntax);
+ else
+ cl->show_raw->syntax = 0;
+ if (esn)
+ cl->show_raw->esn = xstrdup(esn);
+ else
+ cl->show_raw->esn = 0;
+
+
+ if (cl->state == Client_Failed || cl->state == Client_Disconnected)
+ {
+ client_show_raw_error(cl, "not connected");
+ }
+ else
+ {
+ client_continue(cl);
+ }
+ return 0;
+}
+
+void client_show_raw_reset(struct client *cl)
+{
+ xfree(cl->show_raw);
+ cl->show_raw = 0;
+}
+
+static void client_show_raw_error(struct client *cl, const char *addinfo)
+{
+ if (cl->show_raw)
+ {
+ cl->show_raw->error_handler(cl->show_raw->data, addinfo);
+ client_show_raw_reset(cl);
+ }
+}
+
+static void client_show_raw_cancel(struct client *cl)
+{
+ if (cl->show_raw)
+ {
+ cl->show_raw->error_handler(cl->show_raw->data, "cancel");
+ client_show_raw_reset(cl);
+ }
+}
+
+void client_send_raw_present(struct client *cl)
+{
+ Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
+ int toget = 1;
+ int start = cl->show_raw->position;
+
+ assert(cl->show_raw);
+
+ yaz_log(YLOG_DEBUG, "%s: trying to present %d record(s) from %d",
+ client_get_url(cl), toget, start);
+
+ a->u.presentRequest->resultSetStartPoint = &start;
+ a->u.presentRequest->numberOfRecordsRequested = &toget;
+
+ if (cl->show_raw->syntax) // syntax is optional
+ a->u.presentRequest->preferredRecordSyntax =
+ yaz_string_to_oid_odr(yaz_oid_std(),
+ CLASS_RECSYN, cl->show_raw->syntax,
+ global_parameters.odr_out);
+ if (cl->show_raw->esn) // element set is optional
+ {
+ Z_ElementSetNames *elementSetNames =
+ odr_malloc(global_parameters.odr_out, sizeof(*elementSetNames));
+ Z_RecordComposition *compo =
+ odr_malloc(global_parameters.odr_out, sizeof(*compo));
+ a->u.presentRequest->recordComposition = compo;
+
+ compo->which = Z_RecordComp_simple;
+ compo->u.simple = elementSetNames;
+
+ elementSetNames->which = Z_ElementSetNames_generic;
+ elementSetNames->u.generic =
+ odr_strdup(global_parameters.odr_out, cl->show_raw->esn);
+ }
+ if (send_apdu(cl, a) >= 0)
+ {
+ cl->show_raw->active = 1;
+ cl->state = Client_Presenting;
+ }
+ else
+ {
+ client_show_raw_error(cl, "send_apdu failed");
+ cl->state = Client_Error;
+ }
+ odr_reset(global_parameters.odr_out);
+}
+