+ if (cs_put(conn, buf, len) < 0)
+ yaz_log(YLOG_WARN, "cs_put failed URL:%s", uri);
+ else
+ {
+ char *netbuffer = 0;
+ int netlen = 0;
+ int res = cs_get(conn, &netbuffer, &netlen);
+ if (res <= 0)
+ {
+ yaz_log(YLOG_WARN, "cs_get failed URL:%s", uri);
+ }
+ else
+ {
+ Z_GDU *gdu;
+ odr_setbuf(in, netbuffer, res, 0);
+ if (!z_GDU(in, &gdu, 0, 0)
+ || gdu->which != Z_GDU_HTTP_Response)
+ {
+ yaz_log(YLOG_WARN, "decode failed URL: %s", uri);
+ }
+ else
+ {
+ Z_HTTP_Response *res = gdu->u.HTTP_Response;
+ struct Z_HTTP_Header *h;
+ result = wrbuf_alloc();
+ if (show_headers)
+ {
+
+ wrbuf_printf(result, "HTTP %d\n", res->code);
+ for (h = res->headers; h; h = h->next)
+ wrbuf_printf(result, "%s: %s\n",
+ h->name, h->value);
+ }
+ *code = res->code;
+ wrbuf_write(result, res->content_buf, res->content_len);
+ }
+ }
+ xfree(netbuffer);
+ }
+ cs_close(conn);
+ }
+ }
+ odr_destroy(out);
+ odr_destroy(in);
+ return result;
+}
+
+
+static int cmd_url(const char *arg)
+{
+ int code = 0;
+ WRBUF res = get_url(arg, 0, 0, &code, 1);
+ if (res)
+ {
+ if (wrbuf_len(res) > 1200)
+ {
+ fwrite(wrbuf_buf(res), 1, 1200, stdout);
+ printf(".. out of %lld\n", (long long) wrbuf_len(res));
+ }
+ else
+ puts(wrbuf_cstr(res));
+ wrbuf_destroy(res);
+ }
+ return 0;
+}
+
+static int cmd_sru(const char *arg)
+{
+ if (!*arg)
+ {
+ printf("SRU method is: %s\n", sru_method);
+ printf("SRU version is: %s\n", sru_version);
+ }
+ else
+ {
+ int r = sscanf(arg, "%9s %9s", sru_method, sru_version);
+ if (r >= 1)
+ {
+ if (!yaz_matchstr(sru_method, "post"))
+ ;
+ else if (!yaz_matchstr(sru_method, "get"))
+ ;
+ else if (!yaz_matchstr(sru_method, "soap"))
+ ;
+ else if (!yaz_matchstr(sru_method, "solr"))
+ ;
+ else
+ {
+ strcpy(sru_method, "soap");
+ printf("Unknown SRU method: %s\n", arg);
+ printf("Specify one of POST, GET, SOAP, SOLR\n");
+ }
+ }
+ }
+ return 0;
+}
+
+static int cmd_find(const char *arg)
+{
+ if (!*arg)
+ {
+ printf("Find what?\n");
+ return 0;
+ }
+ if (protocol == PROTO_HTTP)
+ {
+#if YAZ_HAVE_XML2
+ if (!conn)
+ session_connect(cur_host);
+ if (!conn)
+ return 0;
+ if (!send_SRW_searchRequest(arg))
+ return 0;
+#else
+ return 0;
+#endif
+ }
+ else
+ {
+ if (*cur_host && auto_reconnect)
+ {
+ int i = 0;
+ for (;;)
+ {
+ if (conn)
+ {
+ if (!send_Z3950_searchRequest(arg))
+ return 0;
+ wait_and_handle_response(0);
+ if (conn)
+ break;
+ }
+ if (++i == 2)
+ {
+ printf("Unable to reconnect\n");
+ break;
+ }
+ session_connect(cur_host);
+ wait_and_handle_response(0);
+ }
+ return 0;
+ }
+ else if (conn)
+ {
+ if (!send_Z3950_searchRequest(arg))
+ return 0;
+ }
+ else
+ {
+ printf("Not connected yet\n");
+ return 0;
+ }
+ }
+ return 2;
+}
+
+static int cmd_facets(const char *arg)
+{
+ if (!facet_odr)
+ facet_odr = odr_createmem(ODR_ENCODE);
+ odr_reset(facet_odr);
+
+ if (!*arg)
+ {
+ facet_list = 0;
+ printf("Facets cleared.\n");
+ return 0;
+ }
+ facet_list = yaz_pqf_parse_facet_list(facet_odr, arg);
+ if (!facet_list)
+ {
+ printf("Invalid facet list: %s", arg);
+ return 0;
+ }
+ return 1;
+}
+
+static int cmd_delete(const char *arg)
+{
+ if (only_z3950())
+ return 0;
+ if (!send_Z3950_deleteResultSetRequest(arg))
+ return 0;
+ return 2;
+}