static char cql_fields[512] = "/usr/local/share/yaz/etc/pqf.properties";
static char *esPackageName = 0;
static char *yazProxy = 0;
+static int proxy_mode = 0;
static int kilobytes = 64 * 1024;
static char *negotiationCharset = 0;
static int negotiationCharsetRecords = 1;
req->referenceId = set_refid(out);
- if (yazProxy && type_and_host)
+ if (proxy_mode && type_and_host)
{
yaz_oi_set_string_oid(&req->otherInfo, out, yaz_oid_userinfo_proxy,
1, type_and_host);
Z_DefaultDiagFormat *dd = ds->u.defaultDiagRec;
/* ### should check `dd->diagnosticSetId' */
printf("code=" ODR_INT_PRINTF " (%s)", *dd->condition,
- diagbib1_str(*dd->condition));
+ diagbib1_str((int) *dd->condition));
/* Both types of addinfo are the same, so use type-pun */
if (dd->u.v2Addinfo != 0)
printf(",\n\taddinfo='%s'", dd->u.v2Addinfo);
strncpy(type_and_host, arg, sizeof(type_and_host)-1);
type_and_host[sizeof(type_and_host)-1] = '\0';
- conn = cs_create_host_proxy(arg, 1, &add, yazProxy);
+ conn = cs_create_host2(arg, 1, &add, yazProxy, &proxy_mode);
if (!conn)
{
printf("Could not resolve address %s\n", arg);
printf("Unknown diagset: %s\n", diag_name);
}
printf(" [" ODR_INT_PRINTF "] %s",
- *r->condition, diagbib1_str(*r->condition));
+ *r->condition, diagbib1_str((int) *r->condition));
switch (r->which)
{
case Z_DefaultDiagFormat_v2Addinfo:
const char *charset = negotiationCharset;
Z_GDU *gdu;
- gdu = z_get_HTTP_Request_host_path(out, host_port, path);
+ gdu = z_get_HTTP_Request_uri(out, host_port, path, proxy_mode);
if (auth)
{
static int send_srw(Z_SRW_PDU *sr)
{
- char *path = yaz_encode_sru_dbpath_odr(out, databaseNames[0]);
- return send_srw_host_path(sr, wrbuf_cstr(cur_host), path);
+ return send_srw_host_path(sr, wrbuf_cstr(cur_host), databaseNames[0]);
}
static int send_SRW_redirect(const char *uri)
num_entries = res->entries->num_entries;
for (i = 0; i < num_entries; i++)
{
- int pos_term = res->positionOfTerm ? *res->positionOfTerm : -1;
+ Odr_int pos_term = res->positionOfTerm ? *res->positionOfTerm : -1;
if (entries[i]->which == Z_Entry_termInfo)
{
printf("%c ", i + 1 == pos_term ? '*' : ' ');
static int cmd_elements(const char *arg)
{
- static Z_ElementSetNames esn;
- static char what[100];
-
- if (!arg || !*arg)
+ if (elementSetNames)
{
- elementSetNames = 0;
- return 1;
+ xfree(elementSetNames->u.generic);
+ xfree(elementSetNames);
+ }
+ elementSetNames = 0;
+ if (arg && *arg)
+ {
+ elementSetNames = (Z_ElementSetNames *)
+ xmalloc(sizeof(*elementSetNames));
+ elementSetNames->which = Z_ElementSetNames_generic;
+ elementSetNames->u.generic = xstrdup(arg);
}
- strcpy(what, arg);
- esn.which = Z_ElementSetNames_generic;
- esn.u.generic = what;
- elementSetNames = &esn;
return 1;
}
while(conn)
{
res = cs_get(conn, &netbuffer, &netbufferlen);
- if (reconnect_ok && res <= 0 && protocol == PROTO_HTTP)
+ if (res <= 0)
{
- cs_close(conn);
- conn = 0;
- session_connect();
- reconnect_ok = 0;
- if (conn)
+ if (reconnect_ok && protocol == PROTO_HTTP)
{
- char *buf_out;
- int len_out;
-
- buf_out = odr_getbuf(out, &len_out, 0);
-
- do_hex_dump(buf_out, len_out);
-
- cs_put(conn, buf_out, len_out);
-
- odr_reset(out);
- continue;
+ cs_close(conn);
+ conn = 0;
+ session_connect();
+ reconnect_ok = 0;
+ if (conn)
+ {
+ char *buf_out;
+ int len_out;
+ buf_out = odr_getbuf(out, &len_out, 0);
+ do_hex_dump(buf_out, len_out);
+ cs_put(conn, buf_out, len_out);
+ odr_reset(out);
+ continue;
+ }
+ }
+ else
+ {
+ printf("Target closed connection\n");
+ close_session();
+ break;
}
- }
- else if (res <= 0)
- {
- printf("Target closed connection\n");
- close_session();
- break;
}
#if HAVE_GETTIMEOFDAY
if (got_tv_end == 0)
gettimeofday(&tv_end, 0); /* count first one only */
got_tv_end++;
#endif
- odr_reset(out);
odr_reset(in); /* release APDU from last round */
record_last = 0;
do_hex_dump(netbuffer, res);
if (!z_GDU(in, &gdu, 0, 0))
{
- FILE *f = ber_file ? ber_file : stdout;
- odr_perror(in, "Decoding incoming APDU");
- fprintf(f, "[Near %ld]\n", (long) odr_offset(in));
- fprintf(f, "Packet dump:\n---------\n");
- odr_dumpBER(f, netbuffer, res);
- fprintf(f, "---------\n");
- if (apdu_file)
+ if (reconnect_ok && protocol == PROTO_HTTP)
{
- z_GDU(print, &gdu, 0, 0);
- odr_reset(print);
+ fprintf(stderr, "Decoding error. Reconnecting\n");
+ cs_close(conn);
+ conn = 0;
+ session_connect();
+ reconnect_ok = 0;
+ if (conn)
+ {
+ char *buf_out;
+ int len_out;
+ buf_out = odr_getbuf(out, &len_out, 0);
+ do_hex_dump(buf_out, len_out);
+ cs_put(conn, buf_out, len_out);
+ odr_reset(out);
+ continue;
+ }
+ }
+ else
+ {
+ FILE *f = ber_file ? ber_file : stdout;
+ odr_perror(in, "Decoding incoming APDU");
+ fprintf(f, "[Near %ld]\n", (long) odr_offset(in));
+ fprintf(f, "Packet dump:\n---------\n");
+ odr_dumpBER(f, netbuffer, res);
+ fprintf(f, "---------\n");
+ if (apdu_file)
+ {
+ z_GDU(print, &gdu, 0, 0);
+ odr_reset(print);
+ }
+ if (conn && cs_more(conn))
+ continue;
+ break;
}
- if (conn && cs_more(conn))
- continue;
- break;
}
+ odr_reset(out);
if (ber_file)
odr_dumpBER(ber_file, netbuffer, res);
if (apdu_file && !z_GDU(print, &gdu, 0, 0))
static void process_cmd_line(char* line)
{
int i, res;
- char word[32], arg[10240];
+ char word[32], *arg;
+ int no_read = 0;
#if HAVE_GETTIMEOFDAY
gettimeofday(&tv_start, 0);
#endif
- if ((res = sscanf(line, "%31s %10239[^;]", word, arg)) <= 0)
+ sscanf(line, "%31s%n", word, &no_read);
+ if (no_read == 0)
{
strcpy(word, last_cmd);
- *arg = '\0';
+ arg = line + strlen(line);
}
- else if (res == 1)
- *arg = 0;
+ else
+ arg = line + no_read;
strcpy(last_cmd, word);
- /* removed tailing spaces from the arg command */
+ /* whitespace chop */
{
- char* p = arg;
- char* lastnonspace=NULL;
+ char *p;
+ char *lastnonspace = 0;
- for (; *p; ++p)
+ while (*arg && yaz_isspace(*arg))
+ arg++;
+ for (p = arg; *p; ++p)
{
if (!yaz_isspace(*p))
lastnonspace = p;
}
else
{
- char arg[10240],word[32];
- int i ,res;
- if ((res = sscanf(rl_line_buffer, "%31s %10239[^;]", word, arg)) <= 0)
+ char word[32];
+ int i;
+ if (sscanf(rl_line_buffer, "%31s", word) <= 0)
{
rl_attempted_completion_over = 1;
return NULL;