+ZOOM_API(ZOOM_scanset)
+ ZOOM_connection_scan1(ZOOM_connection c, ZOOM_query q)
+{
+ char *start;
+ char *freeme = 0;
+ ZOOM_scanset scan = 0;
+
+ /*
+ * We need to check the query-type, so we can recognise CQL and
+ * CCL and compile them into a form that we can use here. The
+ * ZOOM_query structure has no explicit `type' member, but
+ * inspection of the ZOOM_query_prefix() and ZOOM_query_cql()
+ * functions shows how the structure is set up in each case.
+ */
+ if (!q->z_query)
+ return 0;
+ else if (q->z_query->which == Z_Query_type_1)
+ {
+ yaz_log(log_api, "%p ZOOM_connection_scan1 q=%p PQF '%s'",
+ c, q, q->query_string);
+ start = q->query_string;
+ }
+ else if (q->z_query->which == Z_Query_type_104)
+ {
+ yaz_log(log_api, "%p ZOOM_connection_scan1 q=%p CQL '%s'",
+ c, q, q->query_string);
+ /*
+ * ### This is wrong: if ZOOM_query_cql2rpn() was used, then
+ * the query already been translated to PQF, so we'd be in the
+ * previous branch. We only get here if the client submitted
+ * CQL to be interepreted by the server using
+ * ZOOM_query_cql(), in which case we should send it as-is.
+ * We can't do that in Z39.50 as the ScanRequest APDU has no
+ * slot in which to place the CQL, but we could and should do
+ * it for SRU connections. At present, we can't do that
+ * because there is no slot in the ZOOM_scanset structure to
+ * save the CQL so that it can be sent when the ZOOM_TASK_SCAN
+ * fires.
+ */
+ start = freeme = cql2pqf(c, q->query_string);
+ if (start == 0)
+ return 0;
+ }
+ else
+ {
+ yaz_log(YLOG_FATAL, "%p ZOOM_connection_scan1 q=%p unknown type '%s'",
+ c, q, q->query_string);
+ abort();
+ }
+
+ scan = (ZOOM_scanset) xmalloc(sizeof(*scan));