Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ int cmd_adm_import(const char *arg)
if (fread(oct->buf, 1, oct->len, inf) != (size_t) oct->len)
{
printf("Incomplete read of file %s\n", fname);
oct->buf = 0;
}
}
if (fclose(inf))
Expand Down
31 changes: 2 additions & 29 deletions client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ static void close_session(void);
static void marc_file_write(const char *buf, size_t sz);

static void wait_and_handle_response(int one_response_only);
static Z_GDU *get_HTTP_Request_url(ODR odr, const char *url);

ODR getODROutputStream(void)
{
Expand Down Expand Up @@ -1411,7 +1410,7 @@ static int send_SRW_redirect(const char *uri)
{
const char *username = 0;
const char *password = 0;
Z_GDU *gdu = get_HTTP_Request_url(out, uri);
Z_GDU *gdu = z_get_HTTP_Request_uri(out, uri, 0, 0);

gdu->u.HTTP_Request->method = odr_strdup(out, "GET");
z_HTTP_header_add(out, &gdu->u.HTTP_Request->headers, "Accept",
Expand Down Expand Up @@ -2715,39 +2714,13 @@ static int cmd_init(const char *arg)
return 2;
}

static Z_GDU *get_HTTP_Request_url(ODR odr, const char *url)
{
Z_GDU *p = z_get_HTTP_Request(odr);
const char *host = url;
const char *cp0 = strstr(host, "://");
const char *cp1 = 0;
if (cp0)
cp0 = cp0+3;
else
cp0 = host;

cp1 = strchr(cp0, '/');
if (!cp1)
cp1 = cp0 + strlen(cp0);

if (cp0 && cp1)
{
char *h = (char*) odr_malloc(odr, cp1 - cp0 + 1);
memcpy (h, cp0, cp1 - cp0);
h[cp1-cp0] = '\0';
z_HTTP_header_add(odr, &p->u.HTTP_Request->headers, "Host", h);
}
p->u.HTTP_Request->path = odr_strdup(odr, *cp1 ? cp1 : "/");
return p;
}

static WRBUF get_url(const char *uri, WRBUF username, WRBUF password,
int *code, int show_headers)
{
WRBUF result = 0;
ODR out = odr_createmem(ODR_ENCODE);
ODR in = odr_createmem(ODR_DECODE);
Z_GDU *gdu = get_HTTP_Request_url(out, uri);
Z_GDU *gdu = z_get_HTTP_Request_uri(out, uri, 0, 0);

gdu->u.HTTP_Request->method = odr_strdup(out, "GET");
if (username && password)
Expand Down
8 changes: 6 additions & 2 deletions doc/gfs-virtual.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,15 @@
<listitem>
<para>
Specifies a path for local file access using HTTP. All URLs with
a leading prefix (/ excluded) that matches the value of <literal>docpath</literal>
a path (leading / excluded) that is the value of <literal>docpath</literal>
or begins with <literal>docpath</literal> followed by /
are used for file access. For example, if the server is to offer
access in directory <literal>xsl</literal>, the docpath would be
<literal>xsl</literal> and all URLs of the form
<literal>http://host/xsl</literal> will result in a local file access.
<literal>http://host/xsl/...</literal> will result in a local file
access. URLs for other names that merely begin with
<literal>xsl</literal>, such as <literal>http://host/xslt/...</literal>,
are not.
</para>
</listitem>
</varlistentry>
Expand Down
9 changes: 8 additions & 1 deletion src/comstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ int cs_get_error(COMSTACK cs, const char **details)
void cs_get_host_args(const char *type_and_host, const char **args)
{
*args = "";
if (!strncmp(type_and_host, "unix:", 5))
if (!strncmp(type_and_host, "connect:", 8))
{
/* As in cs_parse_host, the proxy part is not part of the target. */
const char *cp = strchr(type_and_host, ',');
if (cp)
type_and_host = cp + 1;
}
else if (!strncmp(type_and_host, "unix:", 5))
{
const char *cp = strchr(type_and_host + 5, ':');
if (!cp)
Expand Down
1 change: 1 addition & 0 deletions src/eventl.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void statserv_remove (IOCHAN pIOChannel);
void statserv_reap_children(void);
int statserv_request_timeout(void);
int statserv_max_scan_terms(void);
int statserv_max_recv_bytes(int chan_id);
#endif
/*
* Local variables:
Expand Down
40 changes: 30 additions & 10 deletions src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,34 @@ Z_GDU *z_get_HTTP_Request(ODR o)
}


/* Locate the host where cs_parse_host does, so that Host names what the
transport connects to: http: and https: need no slashes, and *uri is
advanced past a connect:[user:password@]proxy, wrapper. The wrapper is
for the transport only and must not appear in any request. */
static const char *http_host_start(const char **uri)
{
const char *cp;

if (!strncmp(*uri, "connect:", 8))
{
cp = strchr(*uri, ',');
if (cp)
*uri = cp + 1;
}
if (!strncmp(*uri, "http:", 5))
cp = *uri + 5;
else if (!strncmp(*uri, "https:", 6))
cp = *uri + 6;
else
{
cp = strstr(*uri, "://");
return cp ? cp + 3 : *uri;
}
while (*cp == '/')
cp++;
return cp;
}

Z_GDU *z_get_HTTP_Request_host_path(ODR odr,
const char *host,
const char *path)
Expand All @@ -233,12 +261,8 @@ Z_GDU *z_get_HTTP_Request_host_path(ODR odr,

if (host)
{
const char *cp0 = strstr(host, "://");
const char *cp0 = http_host_start(&host);
const char *cp1 = 0;
if (cp0)
cp0 = cp0+3;
else
cp0 = host;

cp1 = strchr(cp0, '/');
if (!cp1)
Expand All @@ -257,12 +281,8 @@ Z_GDU *z_get_HTTP_Request_uri(ODR odr, const char *uri, const char *args,
int use_full_uri)
{
Z_GDU *p = z_get_HTTP_Request(odr);
const char *cp0 = strstr(uri, "://");
const char *cp0 = http_host_start(&uri);
const char *cp1 = 0;
if (cp0)
cp0 = cp0+3;
else
cp0 = uri;

cp1 = strchr(cp0, '/');
if (!cp1)
Expand Down
13 changes: 5 additions & 8 deletions src/iconv_encode_marc8.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,10 @@ static size_t yaz_write_marc8_generic(yaz_iconv_t cd, struct encoder_data *w,
unsigned long x1, x2;
if (yaz_iso_8859_1_lookup_y(x, &x1, &x2))
{
/* save the output pointers .. */
/* save the output pointers and encoder state .. */
char *outbuf0 = *outbuf;
size_t outbytesleft0 = *outbytesleft;
unsigned long last_ch = w->write_marc8_last;
int ncr = w->write_marc8_ncr;
const char *lpage = w->write_marc8_lpage;
struct encoder_data w0 = *w;

size_t r =
yaz_write_marc8_2(cd, w, x1, outbuf, outbytesleft, loss_mode);
Expand All @@ -370,12 +368,11 @@ static size_t yaz_write_marc8_generic(yaz_iconv_t cd, struct encoder_data *w,
outbuf, outbytesleft, loss_mode);
if (r && yaz_iconv_error(cd) == YAZ_ICONV_E2BIG)
{
/* not enough room. reset output to original values */
/* not enough room. reset output and encoder state to original
values (G0/G1 too, as their escapes are taken back) */
*outbuf = outbuf0;
*outbytesleft = outbytesleft0;
w->write_marc8_last = last_ch;
w->write_marc8_ncr = ncr;
w->write_marc8_lpage = lpage;
*w = w0;
}
return r;
}
Expand Down
3 changes: 3 additions & 0 deletions src/marc_read_sax.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ static void yaz_end_element_ns(void *vp, const xmlChar *localname,
{
yaz_marc_add_controlfield(ctx->mt, wrbuf_cstr(ctx->tag),
wrbuf_buf(ctx->cdata), wrbuf_len(ctx->cdata));
/* tag belongs to this element only; an enclosing controlfield
must not add it again */
wrbuf_rewind(ctx->tag);
}
else if (strcmp((const char *)localname, "subfield") == 0)
{
Expand Down
16 changes: 16 additions & 0 deletions src/marcdisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,18 @@ static size_t pow10i(int n)
return res;
}

/* Blank field and record terminators in wr from offset pos on. Content
read from ISO2709 has none, but character set conversion may produce
them (MARC-8 0x9D/0x9E with ASCII as G1, danMARC @001D) and so may
other readers (JSON). Same length, so the directory is unaffected. */
static void iso2709_blank_terminators(WRBUF wr, size_t pos)
{
char *buf = wrbuf_buf(wr);
for (; pos < wrbuf_len(wr); pos++)
if (buf[pos] == ISO2709_FS || buf[pos] == ISO2709_RS)
buf[pos] = ' ';
}

int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wr)
{
struct yaz_marc_node *n, *cap_node = 0;
Expand Down Expand Up @@ -1254,6 +1266,7 @@ int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wr)
return -1;
}
wrbuf_printf(wr_dir, "%3.3s", tag);
iso2709_blank_terminators(wr_dir, wrbuf_len(wr_dir) - 3);
wrbuf_printf(wr_dir, "%0*ld", length_data_entry, (long) data_length);
wrbuf_printf(wr_dir, "%0*ld", length_starting, (long) data_offset);
data_offset += data_length;
Expand Down Expand Up @@ -1291,6 +1304,7 @@ int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wr)
for (n = mt->nodes; n != cap_node; n = n->next)
{
struct yaz_marc_subfield *s;
size_t pos = wrbuf_len(wr);

switch(n->which)
{
Expand All @@ -1302,11 +1316,13 @@ int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wr)
wrbuf_iconv_puts(wr, mt->iconv_cd, s->code_data);
marc_iconv_reset(mt, wr);
}
iso2709_blank_terminators(wr, pos);
wrbuf_putc(wr, ISO2709_FS);
break;
case YAZ_MARC_CONTROLFIELD:
wrbuf_iconv_puts(wr, mt->iconv_cd, n->u.controlfield.data);
marc_iconv_reset(mt, wr);
iso2709_blank_terminators(wr, pos);
wrbuf_putc(wr, ISO2709_FS);
break;
case YAZ_MARC_COMMENT:
Expand Down
Loading
Loading