* Copyright (C) 1995-2005, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: zoom-c.c,v 1.35 2005-01-15 19:47:15 adam Exp $
+ * $Id: zoom-c.c,v 1.40 2005-05-02 19:33:55 adam Exp $
*/
/**
* \file zoom-c.c
#include <yaz/ill.h>
#include <yaz/srw.h>
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
#if HAVE_SYS_POLL_H
#include <sys/poll.h>
#endif
+#if HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+#ifdef WIN32
+#include <winsock.h>
+#endif
-static int log_level=0;
-static int log_level_initialized=0;
+static int log_level = 0;
+static int log_level_initialized = 0;
typedef enum {
zoom_pending,
char *cp;
if (!log_level_initialized)
{
- log_level=yaz_log_module_level("zoom");
- log_level_initialized=1;
+ log_level = yaz_log_module_level("zoom");
+ log_level_initialized = 1;
}
xfree (c->addinfo);
if (!log_level_initialized)
{
- log_level=yaz_log_module_level("zoom");
- log_level_initialized=1;
+ log_level = yaz_log_module_level("zoom");
+ log_level_initialized = 1;
}
c->proto = PROTO_Z3950;
int *num)
{
char **databaseNames;
- const char *c;
- int no = 2;
const char *cp = ZOOM_options_get (options, "databaseName");
if (!cp || !*cp)
{
if (strncmp (con->host_port, "unix:", 5) == 0)
- cp = strchr (con->host_port+5, ':');
+ cp = strchr(con->host_port+5, ':');
else
- cp = strchr (con->host_port, '/');
+ cp = strchr(con->host_port, '/');
if (cp)
cp++;
}
- if (cp)
- {
- c = cp;
- while ((c = strchr(c, '+')))
- {
- c++;
- no++;
- }
- }
- else
+ if (!cp)
cp = "Default";
- databaseNames = (char**)
- odr_malloc (con->odr_out, no * sizeof(*databaseNames));
- no = 0;
- while (*cp)
- {
- c = strchr (cp, '+');
- if (!c)
- c = cp + strlen(cp);
- else if (c == cp)
- {
- cp++;
- continue;
- }
- /* cp ptr to first char of db name, c is char
- following db name */
- databaseNames[no] = (char*) odr_malloc (con->odr_out, 1+c-cp);
- memcpy (databaseNames[no], cp, c-cp);
- databaseNames[no++][c-cp] = '\0';
- cp = c;
- if (*cp)
- cp++;
- }
- databaseNames[no] = NULL;
- *num = no;
+ nmem_strsplit(con->odr_out->mem, "+", cp, &databaseNames, num);
return databaseNames;
}
if (!log_level_initialized)
{
- log_level=yaz_log_module_level("zoom");
- log_level_initialized=1;
+ log_level = yaz_log_module_level("zoom");
+ log_level_initialized = 1;
}
if (c->cs)
if (!log_level_initialized)
{
- log_level=yaz_log_module_level("zoom");
- log_level_initialized=1;
+ log_level = yaz_log_module_level("zoom");
+ log_level_initialized = 1;
}
yaz_log (log_level, "ZOOM_resultset_create r = %p", r);
const char *effective_host;
if (!log_level_initialized)
{
- log_level=yaz_log_module_level("zoom");
- log_level_initialized=1;
+ log_level = yaz_log_module_level("zoom");
+ log_level_initialized = 1;
}
val = ZOOM_options_get (c->options, buf);
if (!val)
break;
- cp = strchr (val, ':');
+ cp = strchr(val, ':');
if (!cp)
continue;
len = cp - val;
ZOOM_options_get(c->options, "implementationName"),
odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName));
- version = odr_strdup(c->odr_out, "$Revision: 1.35 $");
+ version = odr_strdup(c->odr_out, "$Revision: 1.40 $");
if (strlen(version) > 10) /* check for unexpanded CVS strings */
version[strlen(version)-2] = '\0';
ireq->implementationVersion = odr_prepend(c->odr_out,
if (c->proxy)
yaz_oi_set_string_oidval(&ireq->otherInfo, c->odr_out,
VAL_PROXY, 1, c->host_port);
- if (c->charset||c->lang)
+ if (c->charset || c->lang)
{
Z_OtherInformation **oi;
Z_OtherInformationUnit *oi_unit;
if ((oi_unit = yaz_oi_update(oi, c->odr_out, NULL, 0, 0)))
{
+ char **charsets_addresses = 0;
+ char **langs_addresses = 0;
+ int charsets_count = 0;
+ int langs_count = 0;
+
+ if (c->charset)
+ nmem_strsplit_blank(c->odr_out->mem, c->charset,
+ &charsets_addresses, &charsets_count);
+ if (c->lang)
+ nmem_strsplit_blank(c->odr_out->mem, c->lang,
+ &langs_addresses, &langs_count);
ODR_MASK_SET(ireq->options, Z_Options_negotiationModel);
-
oi_unit->which = Z_OtherInfo_externallyDefinedInfo;
oi_unit->information.externallyDefinedInfo =
- yaz_set_proposal_charneg
- (c->odr_out,
- (const char **)&c->charset, (c->charset) ? 1:0,
- (const char **)&c->lang, (c->lang) ? 1:0, 1);
+ yaz_set_proposal_charneg(c->odr_out,
+ (const char **) charsets_addresses,
+ charsets_count,
+ (const char **) langs_addresses,
+ langs_count,
+ 1);
}
}
assert (apdu);
if (record_charset && *record_charset)
{
/* Use "from,to" or just "from" */
- const char *cp =strchr(record_charset, ',');
+ const char *cp = strchr(record_charset, ',');
int clen = strlen(record_charset);
if (cp && cp[1])
{
if (record_charset && *record_charset)
{
/* Use "from,to" or just "from" */
- const char *cp =strchr(record_charset, ',');
+ const char *cp = strchr(record_charset, ',');
int clen = strlen(record_charset);
if (cp && cp[1])
{
Z_NamePlusRecord *myrec =
zget_surrogateDiagRec(resultset->odr, 0, 14, 0);
record_cache_add(resultset, myrec, resultset->start);
- yaz_log(YLOG_LOG, "pseudo record 1, at pos %d",
- resultset->start);
}
}
else if (present_phase)
Z_NamePlusRecord *myrec =
zget_surrogateDiagRec(resultset->odr, 0, 14, 0);
record_cache_add(resultset, myrec, resultset->start);
- yaz_log(YLOG_LOG, "pseudo record 1, at pos %d",
- resultset->start);
}
}
}
Z_ItemOrder *req = (Z_ItemOrder *) odr_malloc (p->odr_out, sizeof(*req));
const char *str;
- req->which=Z_IOItemOrder_esRequest;
+ req->which = Z_IOItemOrder_esRequest;
req->u.esRequest = (Z_IORequest *)
odr_malloc(p->odr_out,sizeof(Z_IORequest));
toKeep = r->u.adminService->u.esRequest->toKeep =
(Z_ESAdminOriginPartToKeep *)
odr_malloc(p->odr_out, sizeof(*r->u.adminService->u.esRequest->toKeep));
- toKeep->which=type;
+ toKeep->which = type;
toKeep->databaseName = odr_strdup(p->odr_out, first_db);
- toKeep->u.create=odr_nullval();
+ toKeep->u.create = odr_nullval();
apdu->u.extendedServicesRequest->taskSpecificParameters = r;
r->u.adminService->u.esRequest->notToKeep = notToKeep =
(Z_ESAdminOriginPartNotToKeep *)
odr_malloc(p->odr_out,
sizeof(*r->u.adminService->u.esRequest->notToKeep));
- notToKeep->which=Z_ESAdminOriginPartNotToKeep_recordsWillFollow;
- notToKeep->u.recordsWillFollow=odr_nullval();
+ notToKeep->which = Z_ESAdminOriginPartNotToKeep_recordsWillFollow;
+ notToKeep->u.recordsWillFollow = odr_nullval();
if (toKeepP)
*toKeepP = toKeep;
if (notToKeepP)
if (p)
{
- char *charset=NULL, *lang=NULL;
+ char *charset = NULL, *lang = NULL;
int sel;
yaz_get_response_charneg(tmpmem, p, &charset, &lang, &sel);
if (lang)
ZOOM_connection_option_set (c, "negotiation-lang",
lang);
+
+ ZOOM_connection_option_set (
+ c, "negotiation-charset-in-effect-for-records",
+ (sel != 0) ? "1" : "0");
nmem_destroy(tmpmem);
}
}
ZOOM_connection_put_event (c, event);
yaz_log (log_level, "do_write_ex len=%d", len_out);
- if ((r=cs_put (c->cs, buf_out, len_out)) < 0)
+ if ((r = cs_put(c->cs, buf_out, len_out)) < 0)
{
if (c->reconnect_ok)
{
ZOOM_API(int)
ZOOM_event (int no, ZOOM_connection *cs)
{
- int timeout = 5000;
+ int timeout = 30; /* default timeout in seconds */
+ int timeout_set = 0; /* whether it was overriden at all */
#if HAVE_SYS_POLL_H
struct pollfd pollfds[1024];
ZOOM_connection poll_cs[1024];
continue;
if (max_fd < fd)
max_fd = fd;
-
- this_timeout = ZOOM_options_get_int (c->options, "timeout", -1);
- if (this_timeout != -1 && this_timeout < timeout)
- timeout = this_timeout;
+
+ /* -1 is used for indefinite timeout (no timeout), so -2 here. */
+ this_timeout = ZOOM_options_get_int (c->options, "timeout", -2);
+ if (this_timeout != -2)
+ {
+ /* ensure the minimum timeout is used */
+ if (!timeout_set)
+ timeout = this_timeout;
+ else if (this_timeout != -1 && this_timeout < timeout)
+ timeout = this_timeout;
+ timeout_set = 1;
+ }
#if HAVE_SYS_POLL_H
if (mask)
{
}
#endif
}
- if (timeout >= 5000)
- timeout = 30;
-
if (!nfds)
return 0;
#if HAVE_SYS_POLL_H
- r = poll (pollfds, nfds, timeout * 1000);
+ r = poll (pollfds, nfds, (timeout == -1 ? -1 : timeout * 1000));
for (i = 0; i<nfds; i++)
{
ZOOM_connection c = poll_cs[i];
tv.tv_sec = timeout;
tv.tv_usec = 0;
yaz_log (log_level, "select start");
- r = select (max_fd+1, &input, &output, &except, &tv);
+ r = select (max_fd+1, &input, &output, &except, (timeout == -1 ? 0 : &tv));
yaz_log (log_level, "select stop, returned r=%d", r);
for (i = 0; i<no; i++)
{