+static void srw_bend_update(association *assoc, request *req,
+ Z_SRW_updateRequest *srw_req,
+ Z_SRW_updateResponse *srw_res,
+ int *http_code)
+{
+ yaz_log(YLOG_DEBUG, "Got SRW UpdateRequest");
+ 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);
+ if (assoc->init)
+ {
+ bend_update_rr rr;
+
+ 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_version = 0;
+ rr.record_checksum = 0;
+ rr.record_old_version = 0;
+ rr.record_packing = "xml";
+ rr.record_schema = 0;
+ rr.record_data = 0;
+ rr.request_extra_record = 0;
+ rr.response_extra_record = 0;
+ rr.extra_request_data = 0;
+ rr.extra_response_data = 0;
+ rr.errcode = 0;
+ rr.errstring = 0;
+
+ 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->recordId ){
+ yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
+ &srw_res->num_diagnostics,
+ 7, "recordId" );
+ }
+ else {
+ rr.record_id = srw_req->recordId;
+ }
+ if ( !srw_req->recordVersion ){
+ yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
+ &srw_res->num_diagnostics,
+ 7, "recordVersion" );
+ }
+ else {
+ rr.record_version = odr_strdup( assoc->encode,
+ srw_req->recordVersion );
+
+ }
+ if ( srw_req->recordOldVersion ){
+ rr.record_old_version = odr_strdup(assoc->encode,
+ srw_req->recordOldVersion );
+ }
+ if ( srw_req->extraRequestData ){
+ rr.extra_request_data = odr_strdup(assoc->encode,
+ srw_req->extraRequestData );
+ }
+ }
+ else if ( !strcmp( rr.operation, "replace" ) ){
+ if ( !srw_req->recordId ){
+ yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
+ &srw_res->num_diagnostics,
+ 7, "recordId" );
+ }
+ else {
+ rr.record_id = srw_req->recordId;
+ }
+ if ( srw_req->record.recordSchema == 0 ){
+ yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
+ &srw_res->num_diagnostics,
+ 7, "recordSchema" );
+ }
+ else {
+ rr.record_schema = odr_strdup(assoc->encode,
+ srw_req->record.recordSchema );
+ }
+ switch (srw_req->record.recordPacking)
+ {
+ case Z_SRW_recordPacking_string:
+ rr.record_packing = "string";
+ break;
+ case Z_SRW_recordPacking_XML:
+ rr.record_packing = "xml";
+ break;
+ case Z_SRW_recordPacking_URL:
+ rr.record_packing = "url";
+ break;
+ }
+ if ( srw_req->record.recordData_len ){
+ rr.record_data = odr_strdupn(assoc->encode,
+ srw_req->record.recordData_buf,
+ srw_req->record.recordData_len );
+ rr.request_extra_record = srw_req->extra_record;
+ }
+ else {
+ yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
+ &srw_res->num_diagnostics,
+ 7, "recordData" );
+ }
+ if (srw_req->extraRequestData)
+ rr.extra_request_data = odr_strdup(assoc->encode,
+ srw_req->extraRequestData );
+ }
+ else if ( !strcmp( rr.operation, "insert" ) )
+ {
+ if ( srw_req->record.recordSchema == 0 ){
+ yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
+ &srw_res->num_diagnostics,
+ 7, "recordSchema" );
+ }
+ else {
+ rr.record_schema = odr_strdup(assoc->encode,
+ srw_req->record.recordSchema);
+ }
+ switch (srw_req->record.recordPacking)
+ {
+ case Z_SRW_recordPacking_string:
+ rr.record_packing = "string";
+ break;
+ case Z_SRW_recordPacking_XML:
+ rr.record_packing = "xml";
+ break;
+ case Z_SRW_recordPacking_URL:
+ rr.record_packing = "url";
+ break;
+ }
+
+ if (srw_req->record.recordData_len)
+ {
+ rr.record_data = odr_strdupn(assoc->encode,
+ srw_req->record.recordData_buf,
+ srw_req->record.recordData_len );
+ rr.request_extra_record = srw_req->extra_record;
+ }
+ else
+ yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
+ &srw_res->num_diagnostics,
+ 7, "recordData" );
+ if ( srw_req->extraRequestData )
+ rr.extra_request_data = odr_strdup(assoc->encode,
+ srw_req->extraRequestData );
+ }
+ if (srw_res->num_diagnostics == 0)
+ {
+ if ( assoc->init->bend_srw_update)
+ (*assoc->init->bend_srw_update)(assoc->backend, &rr);
+ else {
+ yaz_log( YLOG_WARN, "Got No Update function!");
+ return;
+ }
+ }
+ if (rr.errcode)
+ yaz_add_srw_diagnostic(assoc->encode,
+ &srw_res->diagnostics,
+ &srw_res->num_diagnostics,
+ rr.errcode, rr.errstring);
+ srw_res->recordId = rr.record_id;
+ srw_res->operationStatus = rr.operation_status;
+ srw_res->recordVersion = rr.record_version;
+ srw_res->recordChecksum = rr.record_checksum;
+ srw_res->extraResponseData = rr.extra_response_data;
+ srw_res->record.recordPosition = 0;
+ if (srw_res->num_diagnostics == 0 && rr.record_data)
+ {
+ srw_res->record.recordSchema = rr.record_schema;
+ srw_res->record.recordPacking = srw_req->record.recordPacking;
+ srw_res->record.recordData_buf = rr.record_data;
+ srw_res->record.recordData_len = strlen(rr.record_data);
+ srw_res->extra_record = rr.response_extra_record;
+
+ }
+ else
+ srw_res->record.recordData_len = 0;
+ *http_code = 200;
+ }
+}