/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2008 Index Data
+ * Copyright (C) 1995-2009 Index Data
* See the file LICENSE for details.
*/
/** \file client.c
#include <sys/time.h>
#endif
-#if HAVE_OPENSSL_SSL_H
-#include <openssl/bio.h>
-#include <openssl/crypto.h>
-#include <openssl/x509.h>
-#include <openssl/pem.h>
-#include <openssl/ssl.h>
-#include <openssl/err.h>
-#endif
-
#ifdef WIN32
#include <sys/stat.h>
#include <io.h>
static void close_session(void);
+static void marc_file_write(const char *buf, size_t sz);
+
ODR getODROutputStream(void)
{
return out;
}
}
-static void do_hex_dump(const char* buf, int len)
+static void do_hex_dump(const char* buf, size_t len)
{
if (hex_dump)
{
- int i,x;
+ size_t i;
+ int x;
for (i = 0; i < len ; i = i+16 )
{
- printf(" %4.4d ",i);
+ printf(" %4.4ld ", (long) i);
for(x=0 ; i+x<len && x<16; ++x)
{
printf("%2.2X ",(unsigned int)((unsigned char)buf[i+x]));
sprintf(fname, "%s.%03d.raw", dump_file_prefix, no);
of = fopen(fname, "wb");
- fwrite(buf, 1, len, of);
-
- fclose(of);
+ if (fwrite(buf, 1, len, of) != len)
+ {
+ printf("write failed for %s", fname);
+ }
+ if (fclose(of))
+ {
+ printf("close failed for %s", fname);
+ }
}
}
}
negotiationCharsetRecords);
}
}
- else if (ODR_MASK_GET(req->options, Z_Options_negotiationModel))
- {
- Z_OtherInformation **p;
- Z_OtherInformationUnit *p0;
-
- yaz_oi_APDU(apdu, &p);
-
- if ((p0=yaz_oi_update(p, out, NULL, 0, 0)))
- {
- p0->which = Z_OtherInfo_externallyDefinedInfo;
- p0->information.externallyDefinedInfo =
- yaz_set_proposal_charneg(out, 0, 0, 0, 0, 0);
- }
-
- }
if (send_apdu(apdu))
printf("Sent initrequest.\n");
}
}
else if ((*arg)[0] == '<')
{
- long fsize;
+ size_t fsize;
FILE *inf;
const char *fname;
const char *arg_start = ++(*arg);
void *add;
char type_and_host[101];
const char *basep = 0;
-#if HAVE_OPENSSL_SSL_H
- SSL *ssl;
-#endif
if (conn)
{
cs_close(conn);
return 0;
}
printf("OK.\n");
-#if HAVE_OPENSSL_SSL_H
- if ((ssl = (SSL *) cs_get_ssl(conn)))
- {
- X509 *server_cert = SSL_get_peer_certificate (ssl);
-
- if (server_cert)
- {
- char *pem_buf;
- int pem_len;
- BIO *bio = BIO_new(BIO_s_mem());
-
- /* get PEM buffer in memory */
- PEM_write_bio_X509(bio, server_cert);
- pem_len = BIO_get_mem_data(bio, &pem_buf);
- fwrite(pem_buf, pem_len, 1, stdout);
-
- /* print all info on screen .. */
- X509_print_fp(stdout, server_cert);
- BIO_free(bio);
-
- X509_free (server_cert);
- }
- }
-#endif
+ cs_print_session_info(conn);
if (basep && *basep)
set_base (basep);
if (protocol == PROTO_Z3950)
{
print_record((const unsigned char *) r->u.octet_aligned->buf,
r->u.octet_aligned->len);
- if (marc_file)
- fwrite(r->u.octet_aligned->buf, 1, r->u.octet_aligned->len, marc_file);
+ marc_file_write((const char *) r->u.octet_aligned->buf,
+ r->u.octet_aligned->len);
}
else if (oid && r->which == Z_External_octet)
{
if (yaz_marc_decode_buf(mt, octet_buf, r->u.octet_aligned->len,
&result, &rlen)> 0)
{
- fwrite(result, rlen, 1, stdout);
+ if (fwrite(result, rlen, 1, stdout) != 1)
+ {
+ printf("write to stdout failed\n");
+ }
}
else
{
r->u.octet_aligned->len);
}
}
- if (marc_file)
- fwrite(octet_buf, 1, r->u.octet_aligned->len, marc_file);
+ marc_file_write(octet_buf, r->u.octet_aligned->len);
}
else if (oid && !oid_oidcmp(oid, yaz_oid_recsyn_sutrs))
{
return;
}
print_record(r->u.sutrs->buf, r->u.sutrs->len);
- if (marc_file)
- fwrite(r->u.sutrs->buf, 1, r->u.sutrs->len, marc_file);
+ marc_file_write((const char *) r->u.sutrs->buf, r->u.sutrs->len);
}
else if (oid && !oid_oidcmp(oid, yaz_oid_recsyn_grs_1))
{
static int cmd_update_Z3950(int version, int action_no, const char *recid,
char *rec_buf, int rec_len);
+#if YAZ_HAVE_XML2
static int cmd_update_SRW(int action_no, const char *recid,
char *rec_buf, int rec_len);
+#endif
static int cmd_update_common(const char *arg, int version)
{
printf("Usage: format <recordsyntax>\n");
return 0;
}
+ while (sscanf(cp, "%40s%n", form_str, &nor) >= 1 && nor > 0
+ && idx < RECORDSYNTAX_MAX)
+ {
+ if (strcmp(form_str, "none") &&
+ !yaz_string_to_oid_odr(yaz_oid_std(), CLASS_RECSYN, form_str, out))
+ {
+ printf("Bad format: %s\n", form_str);
+ return 0;
+ }
+ cp += nor;
+ }
for (i = 0; i < recordsyntax_size; i++)
{
xfree(recordsyntax_list[i]);
recordsyntax_list[i] = 0;
}
-
+
+ cp = arg;
while (sscanf(cp, "%40s%n", form_str, &nor) >= 1 && nor > 0
&& idx < RECORDSYNTAX_MAX)
{
FILE* includeFile;
char line[102400], *cp;
- if(strlen(arg)<1) {
- fprintf(stderr,"Error in source command use a filename\n");
+ if (strlen(arg) < 1)
+ {
+ fprintf(stderr, "Error in source command use a filename\n");
return -1;
}
includeFile = fopen(arg, "r");
- if(!includeFile) {
- fprintf(stderr,"Unable to open file %s for reading\n",arg);
+ if (!includeFile)
+ {
+ fprintf(stderr, "Unable to open file %s for reading\n",arg);
return -1;
}
- while(!feof(includeFile)) {
- memset(line,0,sizeof(line));
- fgets(line,sizeof(line),includeFile);
+ while (!feof(includeFile)) {
+ memset(line, 0, sizeof(line));
+ if (!fgets(line, sizeof(line), includeFile))
+ {
+ perror("fgets");
+ break;
+ }
- if(strlen(line) < 2) continue;
- if(line[0] == '#') continue;
+ if (strlen(line) < 2) continue;
+ if (line[0] == '#') continue;
if ((cp = strrchr(line, '\n')))
*cp = '\0';
- if( echo ) {
- printf( "processing line: %s\n",line );
- };
+ if (echo)
+ printf("processing line: %s\n", line);
process_cmd_line(line);
}
- if(fclose(includeFile)<0) {
+ if (fclose(includeFile))
+ {
perror("unable to close include file");
exit(1);
}
int cmd_subshell(const char* args)
{
- if(strlen(args))
- system(args);
- else
- system(getenv("SHELL"));
-
+ int ret = system(strlen(args) ? args : getenv("SHELL"));
printf("\n");
+ if (ret)
+ {
+ printf("Exit %d\n", ret);
+ }
return 1;
}
return 1;
}
+static void marc_file_write(const char *buf, size_t sz)
+{
+ if (marc_file)
+ {
+ if (fwrite(buf, 1, sz, marc_file) != sz)
+ {
+ perror("marcfile write");
+ }
+ }
+}
/*
this command takes 3 arge {name class oid}
*/
printf("\n");
if (rec->recordData_buf && rec->recordData_len)
{
- fwrite(rec->recordData_buf, 1, rec->recordData_len, stdout);
- if (marc_file)
- fwrite(rec->recordData_buf, 1, rec->recordData_len, marc_file);
+ if (fwrite(rec->recordData_buf, 1, rec->recordData_len, stdout) !=
+ (size_t) (rec->recordData_len))
+ {
+ printf("write to stdout failed\n");
+ }
+ printf("%.*s", rec->recordData_len, rec->recordData_buf);
+ marc_file_write(rec->recordData_buf, rec->recordData_len);
}
else
printf("No data!");
static void show_version(void)
{
- char vstr[20];
+ char vstr[20], sha1_str[41];
- yaz_version(vstr, 0);
- printf("YAZ version: %s\n", YAZ_VERSION);
- if (strcmp(vstr, YAZ_VERSION))
- printf("YAZ DLL/SO: %s\n", vstr);
+ yaz_version(vstr, sha1_str);
+ printf("YAZ version: %s %s\n", YAZ_VERSION, YAZ_VERSION_SHA1);
+ if (strcmp(sha1_str, YAZ_VERSION_SHA1))
+ printf("YAZ DLL/SO: %s %s\n", vstr, sha1_str);
exit(0);
}
ODR_MASK_SET(&z3950_options, Z_Options_sort);
ODR_MASK_SET(&z3950_options, Z_Options_extendedServices);
ODR_MASK_SET(&z3950_options, Z_Options_delSet);
- ODR_MASK_SET(&z3950_options, Z_Options_negotiationModel);
while ((ret = options("k:c:q:a:b:m:v:p:u:t:Vxd:f:", argv, argc, &arg)) != -2)
{
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab