+Z_APDU *create_admin_package(ZOOM_package p, int type,
+ Z_ESAdminOriginPartToKeep **toKeepP,
+ Z_ESAdminOriginPartNotToKeep **notToKeepP)
+{
+ Z_APDU *apdu = create_es_package (p, VAL_ADMINSERVICE);
+ 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);
+ if (num_db > 0)
+ first_db = db[0];
+
+ r->direct_reference =
+ yaz_oidval_to_z3950oid(p->odr_out, CLASS_EXTSERV,
+ VAL_ADMINSERVICE);
+ 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, VAL_XMLES);
+ 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");
+
+ 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_oct *)
+ odr_malloc (p->odr_out, sizeof(Odr_oct));
+
+ if (!doc)
+ doc = "";
+ ext->u.single_ASN1_type->buf = (unsigned char*)
+ odr_strdup(p->odr_out, doc);
+ ext->u.single_ASN1_type->size = ext->u.single_ASN1_type->len = 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);
+ 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 syntax_oid = VAL_NONE;
+ int action_no = -1;
+
+ if (syntax_str)
+ syntax_oid = oid_getvalbyname(syntax_str);
+ if (!record_buf)
+ {
+ record_buf = "void";
+ syntax_oid = VAL_SUTRS;
+ }
+ if (syntax_oid == VAL_NONE)
+ syntax_oid = VAL_TEXT_XML;
+
+ if (num_db > 0)
+ first_db = db[0];
+
+ if (!action)
+ action = "specialUpdate";
+
+ if (!strcmp(action, "recordInsert"))
+ action_no = Z_IUOriginPartToKeep_recordInsert;
+ else if (!strcmp(action, "recordReplace"))
+ action_no = Z_IUOriginPartToKeep_recordReplace;
+ else if (!strcmp(action, "recordDelete"))
+ action_no = Z_IUOriginPartToKeep_recordDelete;
+ else if (!strcmp(action, "elementUpdate"))
+ action_no = Z_IUOriginPartToKeep_elementUpdate;
+ else if (!strcmp(action, "specialUpdate"))
+ action_no = Z_IUOriginPartToKeep_specialUpdate;
+ else
+ return 0;
+
+ apdu = create_es_package (p, VAL_DBUPDATE);
+ if (apdu)
+ {
+ Z_IUOriginPartToKeep *toKeep;
+ Z_IUSuppliedRecords *notToKeep;
+ Z_External *r = (Z_External *)
+ odr_malloc (p->odr_out, sizeof(*r));
+
+ apdu->u.extendedServicesRequest->taskSpecificParameters = r;
+
+ r->direct_reference =
+ yaz_oidval_to_z3950oid(p->odr_out, CLASS_EXTSERV,
+ VAL_DBUPDATE);
+ r->descriptor = 0;
+ r->which = Z_External_update;
+ r->indirect_reference = 0;
+ r->u.update = (Z_IUUpdate *)
+ odr_malloc(p->odr_out, sizeof(*r->u.update));
+
+ r->u.update->which = Z_IUUpdate_esRequest;
+ r->u.update->u.esRequest = (Z_IUUpdateEsRequest *)
+ odr_malloc(p->odr_out, sizeof(*r->u.update->u.esRequest));
+ toKeep = r->u.update->u.esRequest->toKeep =
+ (Z_IUOriginPartToKeep *)
+ odr_malloc(p->odr_out, sizeof(*toKeep));
+
+ toKeep->databaseName = odr_strdup(p->odr_out, first_db);
+ toKeep->schema = 0;
+ toKeep->elementSetName = 0;
+ toKeep->actionQualifier = 0;
+ toKeep->action = odr_intdup(p->odr_out, action_no);
+
+ notToKeep = r->u.update->u.esRequest->notToKeep =
+ (Z_IUSuppliedRecords *)
+ odr_malloc(p->odr_out, sizeof(*notToKeep));
+ notToKeep->num = 1;
+ notToKeep->elements = (Z_IUSuppliedRecords_elem **)
+ odr_malloc(p->odr_out, sizeof(*notToKeep->elements));
+ notToKeep->elements[0] = (Z_IUSuppliedRecords_elem *)
+ odr_malloc(p->odr_out, sizeof(**notToKeep->elements));
+ notToKeep->elements[0]->which = Z_IUSuppliedRecords_elem_opaque;
+ if (recordIdOpaque)
+ {
+ notToKeep->elements[0]->u.opaque = (Odr_oct *)
+ odr_malloc (p->odr_out, sizeof(Odr_oct));
+ notToKeep->elements[0]->u.opaque->size =
+ notToKeep->elements[0]->u.opaque->len = strlen(recordIdOpaque);
+ notToKeep->elements[0]->u.opaque->buf = (unsigned char*)
+ odr_strdup(p->odr_out, recordIdOpaque);
+ }
+ else if (recordIdNumber)
+ {
+ notToKeep->elements[0]->which = Z_IUSuppliedRecords_elem_number;
+
+ notToKeep->elements[0]->u.number =
+ odr_intdup(p->odr_out, atoi(recordIdNumber));
+ }
+ else
+ notToKeep->elements[0]->u.opaque = 0;
+ notToKeep->elements[0]->supplementalId = 0;
+ notToKeep->elements[0]->correlationInfo = 0;
+ notToKeep->elements[0]->record =
+ z_ext_record(p->odr_out, syntax_oid,
+ record_buf, strlen(record_buf));
+ }
+ if (0 && apdu)
+ {
+ ODR print = odr_createmem(ODR_PRINT);
+
+ z_APDU(print, &apdu, 0, 0);
+ odr_destroy(print);
+ }
+ return apdu;
+}
+