+ ZebraHandle zh = (ZebraHandle) handle;
+
+ yaz_log(LOG_LOG, "function: %d", *rr->esr->function);
+ if (rr->esr->packageName)
+ yaz_log(LOG_LOG, "packagename: %s", rr->esr->packageName);
+ yaz_log(LOG_LOG, "Waitaction: %d", *rr->esr->waitAction);
+
+ if (!rr->esr->taskSpecificParameters)
+ {
+ yaz_log (LOG_WARN, "No task specific parameters");
+ }
+ else if (rr->esr->taskSpecificParameters->which == Z_External_ESAdmin)
+ {
+ es_admin (zh, rr->esr->taskSpecificParameters->u.adminService);
+
+ zebra_result (zh, &rr->errcode, &rr->errstring);
+ }
+ else if (rr->esr->taskSpecificParameters->which == Z_External_update)
+ {
+ Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update;
+ yaz_log (LOG_LOG, "Received DB Update");
+ if (up->which == Z_IUUpdate_esRequest)
+ {
+ Z_IUUpdateEsRequest *esRequest = up->u.esRequest;
+ Z_IUOriginPartToKeep *toKeep = esRequest->toKeep;
+ Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep;
+
+ yaz_log (LOG_LOG, "action");
+ if (toKeep->action)
+ {
+ switch (*toKeep->action)
+ {
+ case Z_IUOriginPartToKeep_recordInsert:
+ yaz_log (LOG_LOG, "recordInsert");
+ break;
+ case Z_IUOriginPartToKeep_recordReplace:
+ yaz_log (LOG_LOG, "recordUpdate");
+ break;
+ case Z_IUOriginPartToKeep_recordDelete:
+ yaz_log (LOG_LOG, "recordDelete");
+ break;
+ case Z_IUOriginPartToKeep_elementUpdate:
+ yaz_log (LOG_LOG, "elementUpdate");
+ break;
+ case Z_IUOriginPartToKeep_specialUpdate:
+ yaz_log (LOG_LOG, "specialUpdate");
+ break;
+ case Z_ESAdminOriginPartToKeep_shutdown:
+ yaz_log (LOG_LOG, "shutDown");
+ break;
+ case Z_ESAdminOriginPartToKeep_start:
+ yaz_log (LOG_LOG, "start");
+ break;
+ default:
+ yaz_log (LOG_LOG, " unknown (%d)", *toKeep->action);
+ }
+ }
+ if (toKeep->databaseName)
+ {
+ yaz_log (LOG_LOG, "database: %s", toKeep->databaseName);
+
+ if (zebra_select_database(zh, toKeep->databaseName))
+ return 0;
+ }
+ else
+ {
+ yaz_log (LOG_WARN, "no database supplied for ES Update");
+ rr->errcode = 1008;
+ rr->errstring = "database";
+ return 0;
+ }
+ if (notToKeep)
+ {
+ int i;
+ zebra_begin_trans (zh, 1);
+ for (i = 0; i < notToKeep->num; i++)
+ {
+ Z_External *rec = notToKeep->elements[i]->record;
+ struct oident *oident = 0;
+ Odr_oct *opaque_recid = 0;
+ int sysno = 0;
+
+ if (notToKeep->elements[i]->u.opaque)
+ {
+ switch(notToKeep->elements[i]->which)
+ {
+ case Z_IUSuppliedRecords_elem_opaque:
+ opaque_recid = notToKeep->elements[i]->u.opaque;
+ break; /* OK, recid already set */
+ case Z_IUSuppliedRecords_elem_number:
+ sysno = *notToKeep->elements[i]->u.number;
+ break;
+ }
+ }
+ if (rec->direct_reference)
+ {
+ oident = oid_getentbyoid(rec->direct_reference);
+ if (oident)
+ yaz_log (LOG_LOG, "record %d type %s", i,
+ oident->desc);
+ }
+ switch (rec->which)
+ {
+ case Z_External_sutrs:
+ if (rec->u.octet_aligned->len > 170)
+ yaz_log (LOG_LOG, "%d bytes:\n%.168s ...",
+ rec->u.sutrs->len,
+ rec->u.sutrs->buf);
+ else
+ yaz_log (LOG_LOG, "%d bytes:\n%s",
+ rec->u.sutrs->len,
+ rec->u.sutrs->buf);
+ break;
+ case Z_External_octet:
+ if (rec->u.octet_aligned->len > 170)
+ yaz_log (LOG_LOG, "%d bytes:\n%.168s ...",
+ rec->u.octet_aligned->len,
+ rec->u.octet_aligned->buf);
+ else
+ yaz_log (LOG_LOG, "%d bytes\n%s",
+ rec->u.octet_aligned->len,
+ rec->u.octet_aligned->buf);
+ }
+ if (oident && oident->value != VAL_TEXT_XML)
+ {
+ rr->errcode = 224;
+ rr->errstring = "only XML update supported";
+ break;
+ }
+ if (rec->which == Z_External_octet)
+ {
+ int action = 0;
+
+ if (*toKeep->action ==
+ Z_IUOriginPartToKeep_recordInsert)
+ action = 1;
+ if (*toKeep->action ==
+ Z_IUOriginPartToKeep_recordReplace)
+ action = 2;
+ if (*toKeep->action ==
+ Z_IUOriginPartToKeep_recordDelete)
+ action = 3;
+ if (*toKeep->action ==
+ Z_IUOriginPartToKeep_specialUpdate)
+ action = 4;
+
+ if (!action)
+ {
+ rr->errcode = 224;
+ rr->errstring = "unsupported ES Update action";
+ break;
+ }
+ else if (opaque_recid)
+ {
+ int r = zebra_admin_exchange_record (
+ zh,
+ rec->u.octet_aligned->buf,
+ rec->u.octet_aligned->len,
+ opaque_recid->buf, opaque_recid->len,
+ action);
+ if (r)
+ {
+ rr->errcode = 224;
+ rr->errstring = "record exchange failed";
+ break;
+ }
+ }
+ else
+ {
+ int r = -1;
+ switch(action) {
+ case 1:
+ r = zebra_insert_record(
+ zh,
+ 0, /* recordType */
+ &sysno,
+ 0, /* match */
+ 0, /* fname */
+ rec->u.octet_aligned->buf,
+ rec->u.octet_aligned->len,
+ 0);
+ if (r)
+ {
+ rr->errcode = 224;
+ rr->errstring = "insert_record failed";
+ }
+ break;
+ case 2:
+ case 4:
+ r = zebra_update_record(
+ zh,
+ 0, /* recordType */
+ &sysno,
+ 0, /* match */
+ 0, /* fname */
+ rec->u.octet_aligned->buf,
+ rec->u.octet_aligned->len,
+ 1);
+ if (r)
+ {
+ rr->errcode = 224;
+ rr->errstring = "update_record failed";
+ }
+ break;
+ case 3:
+ r = zebra_delete_record(
+ zh,
+ 0, /* recordType */
+ &sysno,
+ 0, /* match */
+ 0, /* fname */
+ rec->u.octet_aligned->buf,
+ rec->u.octet_aligned->len,
+ 0);
+ if (r)
+ {
+ rr->errcode = 224;
+ rr->errstring = "delete_record failed";
+ }
+ break;
+ }
+ }
+ }
+ }
+ zebra_end_trans (zh);
+ }
+ }
+ }
+ else
+ {
+ yaz_log (LOG_WARN, "Unknown Extended Service(%d)",
+ rr->esr->taskSpecificParameters->which);
+ rr->errcode = 221;
+
+ }
+ return 0;
+}
+
+static void bend_start (struct statserv_options_block *sob)
+{
+ if (sob->handle)
+ zebra_stop((ZebraService) sob->handle);
+ sob->handle = zebra_start(sob->configname);
+ if (!sob->handle)
+ {
+ yaz_log (LOG_FATAL, "Failed to read config `%s'", sob->configname);
+ exit (1);
+ }
+#ifdef WIN32
+