/*
- * Copyright (C) 1995-2006, Index Data ApS
+ * Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: client.c,v 1.313 2006-09-07 08:14:04 ja7 Exp $
+ * $Id: client.c,v 1.322 2007-01-03 08:42:13 adam Exp $
*/
/** \file client.c
* \brief yaz-client program
static void close_session (void);
-ODR getODROutputStream()
+ODR getODROutputStream(void)
{
return out;
}
conn = cs_create_host(arg, 1, &add);
if (!conn)
{
- printf ("Couldn't create comstack\n");
+ printf ("Could not resolve address %s\n", arg);
return 0;
}
#if YAZ_HAVE_XML2
if (cs_connect(conn, add) < 0)
{
printf ("error = %s\n", cs_strerror(conn));
- if (conn->cerrno == CSYSERR)
- {
- char msg[256];
- yaz_strerror(msg, sizeof(msg));
- printf ("%s\n", msg);
- }
cs_close(conn);
conn = 0;
return 0;
return session_connect(cur_host);
}
-void try_reconnect()
+void try_reconnect(void)
{
char* open_command;
if (record_schema)
sr->u.request->recordSchema = record_schema;
if (recordsyntax_size == 1 && recordsyntax_list[0] == VAL_TEXT_XML)
- sr->u.explain_request->recordPacking = "xml";
+ sr->u.request->recordPacking = "xml";
return send_srw(sr);
}
#endif
return 0;
}
-static Z_External *create_external_itemRequest()
+static Z_External *create_external_itemRequest(void)
{
struct ill_get_ctl ctl;
ILL_ItemRequest *req;
return 0;
}
-static int only_z3950()
+static int only_z3950(void)
{
if (!conn)
{
return cmd_update_common(arg, 0);
}
+static int cmd_update_Z3950(int version, int action_no, const char *recid,
+ char *rec_buf, int rec_len);
+
+static int cmd_update_SRW(int action_no, const char *recid,
+ char *rec_buf, int rec_len);
+
static int cmd_update_common(const char *arg, int version)
{
- Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest );
- Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
- Z_External *r;
char action[20], recid[20];
char *rec_buf;
int rec_len;
int action_no;
int noread = 0;
- Z_External *record_this = 0;
- if (only_z3950())
- return 1;
*action = 0;
*recid = 0;
sscanf (arg, "%19s %19s%n", action, recid, &noread);
if (parse_cmd_doc(&arg, out, &rec_buf, &rec_len, 1) == 0)
return 0;
+#if YAZ_HAVE_XML2
+ if (protocol == PROTO_HTTP)
+ return cmd_update_SRW(action_no, recid, rec_buf, rec_len);
+#endif
+ return cmd_update_Z3950(version, action_no, recid, rec_buf, rec_len);
+}
+
+#if YAZ_HAVE_XML2
+static int cmd_update_SRW(int action_no, const char *recid,
+ char *rec_buf, int rec_len)
+{
+ if (!conn)
+ cmd_open(0);
+ if (!conn)
+ return 0;
+ else
+ {
+ Z_SRW_PDU *srw = yaz_srw_get(out, Z_SRW_update_request);
+ Z_SRW_updateRequest *sr = srw->u.update_request;
+
+ switch(action_no)
+ {
+ case Z_IUOriginPartToKeep_recordInsert:
+ sr->operation = "info:srw/action/1/create";
+ break;
+ case Z_IUOriginPartToKeep_recordReplace:
+ sr->operation = "info:srw/action/1/replace";
+ break;
+ case Z_IUOriginPartToKeep_recordDelete:
+ sr->operation = "info:srw/action/1/delete";
+ break;
+ }
+ if (rec_buf)
+ {
+ sr->record = yaz_srw_get_record(out);
+ sr->record->recordData_buf = rec_buf;
+ sr->record->recordData_len = rec_len;
+ sr->record->recordSchema = record_schema;
+ }
+ if (recid)
+ sr->recordId = odr_strdup(out, recid);
+ return send_srw(srw);
+ }
+}
+#endif
+
+static int cmd_update_Z3950(int version, int action_no, const char *recid,
+ char *rec_buf, int rec_len)
+{
+ Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest );
+ Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
+ Z_External *r;
+ Z_External *record_this = 0;
+
if (rec_buf)
record_this = z_ext_record (out, VAL_TEXT_XML, rec_buf, rec_len);
else
notToKeep->elements[0] = (Z_IU0SuppliedRecords_elem *)
odr_malloc(out, sizeof(**notToKeep->elements));
notToKeep->elements[0]->which = Z_IUSuppliedRecords_elem_opaque;
- if (*recid)
+ if (*recid && strcmp(recid, "none"))
{
notToKeep->elements[0]->u.opaque = (Odr_oct *)
odr_malloc (out, sizeof(Odr_oct));
return 1;
else
{
+ char *asn_buf = 0;
int noread = 0;
char oid_str[51];
int oid_value_xmles = VAL_XMLES;
Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest);
Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
- req->referenceId = set_refid (out);
Z_External *ext = (Z_External *) odr_malloc(out, sizeof(*ext));
+ req->referenceId = set_refid (out);
req->taskSpecificParameters = ext;
ext->indirect_reference = 0;
ext->descriptor = 0;
printf("Bad OID: %s\n", oid_str);
return 0;
}
-
- if (parse_cmd_doc(&arg, out, (char **) &ext->u.single_ASN1_type->buf,
+
+ if (parse_cmd_doc(&arg, out, &asn_buf,
&ext->u.single_ASN1_type->len, 0) == 0)
return 0;
+
+ ext->u.single_ASN1_type->buf = (unsigned char *) asn_buf;
+
req->packageType = yaz_oidval_to_z3950oid(out, CLASS_EXTSERV,
oid_value_xmles);
return 1;
}
-void source_rcfile()
+void source_rcfile(void)
{
/* Look for a $HOME/.yazclientrc and source it if it exists */
struct stat statbuf;
{
Z_SOAP *soap_package = 0;
ODR o = odr_createmem(ODR_DECODE);
- Z_SOAP_Handler soap_handlers[2] = {
- {"http://www.loc.gov/zing/srw/", 0,
- (Z_SOAP_fun) yaz_srw_codec},
+ Z_SOAP_Handler soap_handlers[3] = {
+ {YAZ_XMLNS_SRU_v1_1, 0, (Z_SOAP_fun) yaz_srw_codec},
+ {YAZ_XMLNS_UPDATE_v0_9, 0, (Z_SOAP_fun) yaz_ucp_codec},
{0, 0, 0}
};
ret = z_soap_codec(o, &soap_package,
&hres->content_buf, &hres->content_len,
soap_handlers);
- if (!ret && soap_package->which == Z_SOAP_generic &&
- soap_package->u.generic->no == 0)
+ if (!ret && soap_package->which == Z_SOAP_generic)
{
Z_SRW_PDU *sr = soap_package->u.generic->p;
if (sr->which == Z_SRW_searchRetrieve_response)
handle_srw_explain_response(sr->u.explain_response);
else if (sr->which == Z_SRW_scan_response)
handle_srw_scan_response(sr->u.scan_response);
+ else if (sr->which == Z_SRW_update_response)
+ printf("Got update response. Status: %s\n",
+ sr->u.update_response->operationStatus);
else
ret = -1;
}
else if (soap_package && (soap_package->which == Z_SOAP_fault
- || soap_package->which == Z_SOAP_error))
+ || soap_package->which == Z_SOAP_error))
{
printf ("HTTP Error Status=%d\n", hres->code);
printf ("SOAP Fault code %s\n",
soap_package->u.fault->details);
}
else
+ {
+ printf("z_soap_codec failed. (no SOAP error)\n");
ret = -1;
+ }
odr_destroy(o);
}
if (ret)