+static Z_ItemOrder *encode_item_order(ZOOM_package p)
+{
+ Z_ItemOrder *req = (Z_ItemOrder *) odr_malloc(p->odr_out, sizeof(*req));
+ const char *str;
+
+ req->which = Z_IOItemOrder_esRequest;
+ req->u.esRequest = (Z_IORequest *)
+ odr_malloc(p->odr_out,sizeof(Z_IORequest));
+
+ /* to keep part ... */
+ req->u.esRequest->toKeep = (Z_IOOriginPartToKeep *)
+ odr_malloc(p->odr_out,sizeof(Z_IOOriginPartToKeep));
+ req->u.esRequest->toKeep->supplDescription = 0;
+ req->u.esRequest->toKeep->contact = (Z_IOContact *)
+ odr_malloc(p->odr_out, sizeof(*req->u.esRequest->toKeep->contact));
+
+ str = ZOOM_options_get(p->options, "contact-name");
+ req->u.esRequest->toKeep->contact->name = str ?
+ odr_strdup(p->odr_out, str) : 0;
+
+ str = ZOOM_options_get(p->options, "contact-phone");
+ req->u.esRequest->toKeep->contact->phone = str ?
+ odr_strdup(p->odr_out, str) : 0;
+
+ str = ZOOM_options_get(p->options, "contact-email");
+ req->u.esRequest->toKeep->contact->email = str ?
+ odr_strdup(p->odr_out, str) : 0;
+
+ req->u.esRequest->toKeep->addlBilling = 0;
+
+ /* not to keep part ... */
+ req->u.esRequest->notToKeep = (Z_IOOriginPartNotToKeep *)
+ odr_malloc(p->odr_out,sizeof(Z_IOOriginPartNotToKeep));
+
+ str = ZOOM_options_get(p->options, "itemorder-setname");
+ if (!str)
+ str = "default";
+
+ if (!*str)
+ req->u.esRequest->notToKeep->resultSetItem = 0;
+ else
+ {
+ req->u.esRequest->notToKeep->resultSetItem = (Z_IOResultSetItem *)
+ odr_malloc(p->odr_out, sizeof(Z_IOResultSetItem));
+
+ req->u.esRequest->notToKeep->resultSetItem->resultSetId =
+ odr_strdup(p->odr_out, str);
+ req->u.esRequest->notToKeep->resultSetItem->item =
+ (int *) odr_malloc(p->odr_out, sizeof(int));
+
+ str = ZOOM_options_get(p->options, "itemorder-item");
+ *req->u.esRequest->notToKeep->resultSetItem->item =
+ (str ? atoi(str) : 1);
+ }
+
+ str = ZOOM_options_get(p->options, "doc");
+ if (str)
+ {
+ req->u.esRequest->notToKeep->itemRequest =
+ z_ext_record_xml(p->odr_out, str, strlen(str));
+ }
+ else
+ req->u.esRequest->notToKeep->itemRequest = encode_ill_request(p);
+
+ return req;
+}
+
+Z_APDU *create_admin_package(ZOOM_package p, int type,
+ Z_ESAdminOriginPartToKeep **toKeepP,
+ Z_ESAdminOriginPartNotToKeep **notToKeepP)
+{
+ Z_APDU *apdu = create_es_package(p, yaz_oid_extserv_admin);
+ if (apdu)
+ {
+ Z_ESAdminOriginPartToKeep *toKeep;
+ Z_ESAdminOriginPartNotToKeep *notToKeep;
+ Z_External *r = (Z_External *) odr_malloc(p->odr_out, sizeof(*r));
+ const char *first_db = "Default";
+ int num_db;
+ char **db = set_DatabaseNames(p->connection, p->options, &num_db,
+ p->odr_out);
+ if (num_db > 0)
+ first_db = db[0];
+
+ r->direct_reference = odr_oiddup(p->odr_out, yaz_oid_extserv_admin);
+ r->descriptor = 0;
+ r->indirect_reference = 0;
+ r->which = Z_External_ESAdmin;
+
+ r->u.adminService = (Z_Admin *)
+ odr_malloc(p->odr_out, sizeof(*r->u.adminService));
+ r->u.adminService->which = Z_Admin_esRequest;
+ r->u.adminService->u.esRequest = (Z_AdminEsRequest *)
+ odr_malloc(p->odr_out, sizeof(*r->u.adminService->u.esRequest));
+
+ toKeep = r->u.adminService->u.esRequest->toKeep =
+ (Z_ESAdminOriginPartToKeep *)
+ odr_malloc(p->odr_out, sizeof(*r->u.adminService->u.esRequest->toKeep));
+ toKeep->which = type;
+ toKeep->databaseName = odr_strdup(p->odr_out, first_db);
+ toKeep->u.create = odr_nullval();
+ apdu->u.extendedServicesRequest->taskSpecificParameters = r;
+
+ r->u.adminService->u.esRequest->notToKeep = notToKeep =
+ (Z_ESAdminOriginPartNotToKeep *)
+ odr_malloc(p->odr_out,
+ sizeof(*r->u.adminService->u.esRequest->notToKeep));
+ notToKeep->which = Z_ESAdminOriginPartNotToKeep_recordsWillFollow;
+ notToKeep->u.recordsWillFollow = odr_nullval();
+ if (toKeepP)
+ *toKeepP = toKeep;
+ if (notToKeepP)
+ *notToKeepP = notToKeep;
+ }
+ return apdu;
+}
+
+static Z_APDU *create_xmlupdate_package(ZOOM_package p)
+{
+ Z_APDU *apdu = create_es_package(p, yaz_oid_extserv_xml_es);
+ Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
+ Z_External *ext = (Z_External *) odr_malloc(p->odr_out, sizeof(*ext));
+ const char *doc = ZOOM_options_get(p->options, "doc");
+
+ if (!doc)
+ doc = "";
+
+ req->taskSpecificParameters = ext;
+ ext->direct_reference = req->packageType;
+ ext->descriptor = 0;
+ ext->indirect_reference = 0;
+
+ ext->which = Z_External_octet;
+ ext->u.single_ASN1_type =
+ odr_create_Odr_oct(p->odr_out, (const unsigned char *) doc,
+ strlen(doc));
+ return apdu;
+}
+
+static Z_APDU *create_update_package(ZOOM_package p)
+{
+ Z_APDU *apdu = 0;
+ const char *first_db = "Default";
+ int num_db;
+ char **db = set_DatabaseNames(p->connection, p->options, &num_db, p->odr_out);
+ const char *action = ZOOM_options_get(p->options, "action");
+ const char *recordIdOpaque = ZOOM_options_get(p->options, "recordIdOpaque");
+ const char *recordIdNumber = ZOOM_options_get(p->options, "recordIdNumber");
+ const char *record_buf = ZOOM_options_get(p->options, "record");
+ const char *syntax_str = ZOOM_options_get(p->options, "syntax");
+ int action_no = -1;
+ Odr_oid *syntax_oid = 0;
+
+ if (!syntax_str)
+ syntax_str = "xml";
+ if (!record_buf)
+ {
+ record_buf = "void";
+ syntax_str = "SUTRS";
+ }
+
+ if (syntax_str)
+ {
+ syntax_oid = yaz_string_to_oid_odr(yaz_oid_std(),
+ CLASS_RECSYN, syntax_str,
+ p->odr_out);
+ }
+ if (!syntax_oid)
+ return 0;
+
+ if (num_db > 0)
+ first_db = db[0];