+ZOOM_API(size_t)
+ZOOM_scanset_size (ZOOM_scanset scan)
+{
+ if (!scan || !scan->scan_response || !scan->scan_response->entries)
+ return 0;
+ return scan->scan_response->entries->num_entries;
+}
+
+ZOOM_API(const char *)
+ZOOM_scanset_term (ZOOM_scanset scan, size_t pos,
+ int *occ, int *len)
+{
+ const char *term = 0;
+ size_t noent = ZOOM_scanset_size (scan);
+ Z_ScanResponse *res = scan->scan_response;
+
+ *len = 0;
+ *occ = 0;
+ if (pos >= noent)
+ return 0;
+ if (res->entries->entries[pos]->which == Z_Entry_termInfo)
+ {
+ Z_TermInfo *t = res->entries->entries[pos]->u.termInfo;
+
+ if (t->term->which == Z_Term_general)
+ {
+ term = (const char *) t->term->u.general->buf;
+ *len = t->term->u.general->len;
+ }
+ *occ = t->globalOccurrences ? *t->globalOccurrences : 0;
+ }
+ return term;
+}
+
+ZOOM_API(const char *)
+ZOOM_scanset_option_get (ZOOM_scanset scan, const char *key)
+{
+ return ZOOM_options_get (scan->options, key);
+}
+
+ZOOM_API(void)
+ZOOM_scanset_option_set (ZOOM_scanset scan, const char *key,
+ const char *val)
+{
+ ZOOM_options_set (scan->options, key, val);
+}
+
+
+
+static Z_APDU *create_es_package (ZOOM_package p, int type)
+{
+ const char *str;
+ Z_APDU *apdu = zget_APDU(p->odr_out, Z_APDU_extendedServicesRequest);
+ Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
+
+ *req->function = Z_ExtendedServicesRequest_create;
+
+ str = ZOOM_options_get(p->options, "package-name");
+ if (str && *str)
+ req->packageName = nmem_strdup (p->odr_out->mem, str);
+
+ str = ZOOM_options_get(p->options, "user-id");
+ if (str)
+ req->userId = nmem_strdup (p->odr_out->mem, str);
+
+ req->packageType = yaz_oidval_to_z3950oid(p->odr_out, CLASS_EXTSERV,
+ type);
+
+ str = ZOOM_options_get(p->options, "function");
+ if (str)
+ {
+ if (!strcmp (str, "create"))
+ *req->function = 1;
+ if (!strcmp (str, "delete"))
+ *req->function = 2;
+ if (!strcmp (str, "modify"))
+ *req->function = 3;
+ }
+ return apdu;
+}
+
+static const char *ill_array_lookup (void *clientData, const char *idx)
+{
+ ZOOM_package p = (ZOOM_package) clientData;
+ return ZOOM_options_get (p->options, idx+4);
+}
+
+static Z_External *encode_ill_request (ZOOM_package p)
+{
+ ODR out = p->odr_out;
+ ILL_Request *req;
+ Z_External *r = 0;
+ struct ill_get_ctl ctl;
+
+ ctl.odr = p->odr_out;
+ ctl.clientData = p;
+ ctl.f = ill_array_lookup;
+
+ req = ill_get_ILLRequest(&ctl, "ill", 0);
+
+ if (!ill_Request (out, &req, 0, 0))
+ {
+ int ill_request_size;
+ char *ill_request_buf = odr_getbuf (out, &ill_request_size, 0);
+ if (ill_request_buf)
+ odr_setbuf (out, ill_request_buf, ill_request_size, 1);
+ return 0;
+ }
+ else
+ {
+ oident oid;
+ int illRequest_size = 0;
+ char *illRequest_buf = odr_getbuf (out, &illRequest_size, 0);
+
+ oid.proto = PROTO_GENERAL;
+ oid.oclass = CLASS_GENERAL;
+ oid.value = VAL_ISO_ILL_1;
+
+ r = (Z_External *) odr_malloc (out, sizeof(*r));
+ r->direct_reference = odr_oiddup(out,oid_getoidbyent(&oid));
+ r->indirect_reference = 0;
+ r->descriptor = 0;
+ r->which = Z_External_single;
+
+ r->u.single_ASN1_type = (Odr_oct *)
+ odr_malloc (out, sizeof(*r->u.single_ASN1_type));
+ r->u.single_ASN1_type->buf = odr_malloc (out, illRequest_size);
+ r->u.single_ASN1_type->len = illRequest_size;
+ r->u.single_ASN1_type->size = illRequest_size;
+ memcpy (r->u.single_ASN1_type->buf, illRequest_buf, illRequest_size);
+ }
+ return r;
+}
+
+static Z_ItemOrder *encode_item_order(ZOOM_package p)