+ }
+ if (log_request)
+ {
+ WRBUF wr = wrbuf_alloc();
+ const char *querytype = 0;
+ const char *querystr = 0;
+
+ switch(srw_req->query_type)
+ {
+ case Z_SRW_query_type_pqf:
+ querytype = "PQF";
+ querystr = srw_req->scanClause.pqf;
+ break;
+ case Z_SRW_query_type_cql:
+ querytype = "CQL";
+ querystr = srw_req->scanClause.cql;
+ break;
+ default:
+ querytype = "UNKNOWN";
+ querystr = "";
+ }
+
+ wrbuf_printf(wr, "SRWScan %s ", srw_req->database);
+
+ if (srw_res->num_diagnostics)
+ wrbuf_printf(wr, "ERROR %s - ", srw_res->diagnostics[0].uri);
+ else if (srw_res->num_terms)
+ wrbuf_printf(wr, "OK %d - ", srw_res->num_terms);
+ else
+ wrbuf_printf(wr, "OK - - ");
+
+ wrbuf_printf(wr, ODR_INT_PRINTF "+" ODR_INT_PRINTF " ",
+ (srw_req->responsePosition ?
+ *srw_req->responsePosition : 1),
+ (srw_req->maximumTerms ?
+ *srw_req->maximumTerms : 1));
+ /* there is no step size in SRU/W ??? */
+ wrbuf_printf(wr, "%s: %s ", querytype, querystr);
+ yaz_log(log_request, "%s ", wrbuf_cstr(wr) );
+ wrbuf_destroy(wr);
+ }
+
+}
+
+static void srw_bend_update(association *assoc, request *req,
+ Z_SRW_PDU *sr,
+ Z_SRW_updateResponse *srw_res,
+ int *http_code)
+{
+ Z_SRW_updateRequest *srw_req = sr->u.update_request;
+ yaz_log(log_session, "SRWUpdate action=%s", srw_req->operation);
+ yaz_log(YLOG_DEBUG, "num_diag = %d", srw_res->num_diagnostics );
+ *http_code = 404;
+ srw_bend_init(assoc, &srw_res->diagnostics, &srw_res->num_diagnostics, sr);
+ if (assoc->init)
+ {
+ bend_update_rr rr;
+ Z_SRW_extra_record *extra = srw_req->extra_record;
+
+ rr.stream = assoc->encode;
+ rr.print = assoc->print;
+ rr.num_bases = 1;
+ rr.basenames = &srw_req->database;
+ rr.operation = srw_req->operation;
+ rr.operation_status = "failed";
+ rr.record_id = 0;
+ rr.record_versions = 0;
+ rr.num_versions = 0;
+ rr.record_packing = "string";
+ rr.record_schema = 0;
+ rr.record_data = 0;
+ rr.extra_record_data = 0;
+ rr.extra_request_data = 0;
+ rr.extra_response_data = 0;
+ rr.uri = 0;
+ rr.message = 0;
+ rr.details = 0;
+
+ *http_code = 200;
+ if (rr.operation == 0)
+ {
+ yaz_add_sru_update_diagnostic(
+ assoc->encode, &srw_res->diagnostics,
+ &srw_res->num_diagnostics,
+ YAZ_SRU_UPDATE_MISSING_MANDATORY_ELEMENT_RECORD_REJECTED,
+ "action" );
+ return;
+ }
+ yaz_log(YLOG_DEBUG, "basename = %s", rr.basenames[0] );
+ yaz_log(YLOG_DEBUG, "Operation = %s", rr.operation );
+ if (!strcmp( rr.operation, "delete"))
+ {
+ if (srw_req->record && !srw_req->record->recordSchema)
+ {
+ rr.record_schema = odr_strdup(
+ assoc->encode,
+ srw_req->record->recordSchema);
+ }
+ if (srw_req->record)
+ {
+ rr.record_data = odr_strdupn(
+ assoc->encode,
+ srw_req->record->recordData_buf,
+ srw_req->record->recordData_len );
+ }
+ if (extra && extra->extraRecordData_len)
+ {
+ rr.extra_record_data = odr_strdupn(
+ assoc->encode,
+ extra->extraRecordData_buf,
+ extra->extraRecordData_len );
+ }
+ if (srw_req->recordId)
+ rr.record_id = srw_req->recordId;
+ else if (extra && extra->recordIdentifier)
+ rr.record_id = extra->recordIdentifier;
+ }
+ else if (!strcmp(rr.operation, "replace"))
+ {
+ if (srw_req->recordId)
+ rr.record_id = srw_req->recordId;
+ else if (extra && extra->recordIdentifier)
+ rr.record_id = extra->recordIdentifier;
+ else
+ {
+ yaz_add_sru_update_diagnostic(
+ assoc->encode, &srw_res->diagnostics,
+ &srw_res->num_diagnostics,
+ YAZ_SRU_UPDATE_MISSING_MANDATORY_ELEMENT_RECORD_REJECTED,
+ "recordIdentifier");
+ }
+ if (!srw_req->record)
+ {
+ yaz_add_sru_update_diagnostic(
+ assoc->encode, &srw_res->diagnostics,
+ &srw_res->num_diagnostics,
+ YAZ_SRU_UPDATE_MISSING_MANDATORY_ELEMENT_RECORD_REJECTED,
+ "record");
+ }
+ else
+ {
+ if (srw_req->record->recordSchema)
+ rr.record_schema = odr_strdup(
+ assoc->encode, srw_req->record->recordSchema);
+ if (srw_req->record->recordData_len )
+ {
+ rr.record_data = odr_strdupn(assoc->encode,
+ srw_req->record->recordData_buf,
+ srw_req->record->recordData_len );
+ }
+ else