//xmlChar *xmlstr = 0;
//int size = 0;
//xmlDocDumpMemory(icu_doc, size);
-
+
yaz_log(YLOG_FATAL, "Could not parse ICU chain config:\n"
"<%s>\n ... \n</%s>",
xml_node->name, xml_node->name);
yaz_log(YLOG_FATAL, "Error: ICU support requested with element:\n"
"<%s>\n ... \n</%s>",
xml_node->name, xml_node->name);
- yaz_log(YLOG_FATAL,
+ yaz_log(YLOG_FATAL,
"But no ICU support is compiled into the YAZ library.");
return 0;
#endif // YAZ_HAVE_ICU
void pp2_charset_token_first(pp2_charset_token_t prt,
const char *buf, int skip_article)
-{
+{
if (skip_article)
{
const char *p = buf;
char firstword[64];
char *pout = firstword;
char articles[] = "the den der die des an a "; // must end in space
-
+
for (; *p && *p != ' ' && pout - firstword < (sizeof(firstword)-2); p++)
*pout++ = tolower(*(unsigned char *)p);
*pout++ = ' ';
if (prt->iter)
icu_iter_destroy(prt->iter);
#endif
- if(prt->norm_str)
+ if(prt->norm_str)
wrbuf_destroy(prt->norm_str);
- if(prt->sort_str)
+ if(prt->sort_str)
wrbuf_destroy(prt->sort_str);
xfree(prt);
}
char *tmp = xstrdup(prt->last_cp);
char *result = 0;
result = normalize7bit_mergekey(tmp);
-
+
wrbuf_rewind(prt->sort_str);
wrbuf_puts(prt->sort_str, result);
xfree(tmp);
*/
/** \file client.c
- \brief Z39.50 client
+ \brief Z39.50 client
*/
#if HAVE_CONFIG_H
if (!cl->connection)
return -1;
-
+
rr = xmalloc(sizeof(*rr));
rr->position = position;
assert(nativesyntax);
rr->nativesyntax = xstrdup(nativesyntax);
-
+
rr->next = 0;
-
+
for (rrp = &cl->show_raw; *rrp; rrp = &(*rrp)->next)
;
*rrp = rr;
-
+
if (cl->state == Client_Failed)
{
client_show_raw_error(cl, "client failed");
ZOOM_resultset resultset = cl->resultset;
const char *error, *addinfo = 0;
-
+
if (ZOOM_connection_error(link, &error, &addinfo))
{
cl->hits = 0;
NMEM nmem = nmem_create();
const char *xmlrec;
char type[80];
-
+
const char *s = session_setting_oneval(sdb, PZ_NATIVESYNTAX);
if (nativesyntax_to_type(s, type, rec))
yaz_log(YLOG_WARN, "Failed to determine record type");
struct session_database *sdb = client_get_database(cl);
WRBUF w = wrbuf_alloc();
-
+
struct setting *s;
for (s = sdb->settings[PZ_FACETMAP]; s; s = s->next)
struct setting *s;
const char *strategy_plus_sort = 0;
-
+
for (s = sdb->settings[PZ_SORTMAP]; s; s = s->next)
{
char *p = strchr(s->name + 3, ':');
else
{
yaz_log(YLOG_LOG, "Client %s: Search PQF: %s", client_get_id(cl), cl->pquery);
-
+
ZOOM_query_prefix(q, cl->pquery);
}
if (se->sorted_results)
assert(id);
cl->id = xstrdup(id);
client_use(1);
-
+
return cl;
}
else
{
r = xstrdup(wrbuf_cstr(wrb));
- }
+ }
wrbuf_destroy(wrb);
cql_transform_close(cqlt);
return r;
char *r = 0;
WRBUF wrb = wrbuf_alloc();
int status;
-
+
if ((status = solr_transform_rpn2solr_wrbuf(sqlt, wrb, zquery)))
{
yaz_log(YLOG_WARN, "Failed to generate SOLR query, code=%d", status);
for (; (name = facet_limits_get(cl->facet_limits, *l, &value)); (*l)++)
{
struct setting *s = 0;
-
+
for (s = sdb->settings[PZ_LIMITMAP]; s; s = s->next)
{
const char *p = strchr(s->name + 3, ':');
const char *cp = s->value + 6;
while (*cp == ' ')
cp++;
-
+
nmem_strsplit_escape2(nmem, "|", value, values,
num, 1, '\\', 1);
(*l)++;
wrbuf_puts(ccl_w, values[i]);
wrbuf_puts(ccl_w, "\"");
- cn = ccl_find_str(ccl_map, wrbuf_cstr(ccl_w),
+ cn = ccl_find_str(ccl_map, wrbuf_cstr(ccl_w),
&cerror, &cpos);
if (cn)
{
nmem_destroy(nmem_tmp);
return ret;
}
-
+
// Parse the query given the settings specific to this client
// return 0 if query is OK but different from before
// return 1 if query is OK but same as before
ret_value = 0;
}
wrbuf_destroy(w_pqf);
-
+
xfree(cl->cqlquery);
cl->cqlquery = 0;
- odr_out = odr_createmem(ODR_ENCODE);
+ odr_out = odr_createmem(ODR_ENCODE);
zquery = p_query_rpn(odr_out, cl->pquery);
if (!zquery)
{
{
session_log(se, YLOG_LOG, "PQF for Client %s: %s",
client_get_id(cl), cl->pquery);
-
+
/* Support for PQF on SRU targets. */
if (strcmp(query_syntax, "pqf") != 0 && *sru)
{
*/
/** \file client.h
- \brief Z39.50 client
+ \brief Z39.50 client
*/
#ifndef CLIENT_H
connection_use(-1);
}
-// Creates a new connection for client, associated with the host of
+// Creates a new connection for client, associated with the host of
// client's database
static struct connection *connection_create(struct client *cl,
struct host *host,
co->state = Conn_Closed;
co->operation_timeout = operation_timeout;
co->session_timeout = session_timeout;
-
+
if (host->ipport)
connection_connect(co, iochan_man);
if (!cl)
continue;
ev = ZOOM_connection_last_event(link);
-
+
#if 1
yaz_log(YLOG_DEBUG, "%p Connection ZOOM_EVENT_%s", co, ZOOM_get_event_str(ev));
#endif
- switch (ev)
+ switch (ev)
{
case ZOOM_EVENT_END:
{
yaz_mutex_enter(host->mutex);
cl = co->client;
- if (!cl)
+ if (!cl)
{
/* no client associated with it.. We are probably getting
a closed connection from the target.. Or, perhaps, an unexpected
non_block_events(co);
ZOOM_connection_fire_event_socket(co->link, event);
-
+
non_block_events(co);
client_unlock(cl);
ZOOM_options_set(zoptions, "async", "1");
ZOOM_options_set(zoptions, "implementationName", PACKAGE_NAME);
ZOOM_options_set(zoptions, "implementationVersion", VERSION);
-
+
if ((charset = session_setting_oneval(sdb, PZ_NEGOTIATION_CHARSET)))
ZOOM_options_set(zoptions, "charset", charset);
-
+
assert(host->ipport);
if (host->proxy)
{
assert(host->tproxy);
yaz_log(YLOG_LOG, "tproxy=%s", host->ipport);
ZOOM_options_set(zoptions, "tproxy", host->ipport);
- }
+ }
if (apdulog && *apdulog)
ZOOM_options_set(zoptions, "apdulog", apdulog);
ZOOM_options_set(zoptions, "user", auth);
if ((sru = session_setting_oneval(sdb, PZ_SRU)) && *sru)
ZOOM_options_set(zoptions, "sru", sru);
- if ((sru_version = session_setting_oneval(sdb, PZ_SRU_VERSION))
+ if ((sru_version = session_setting_oneval(sdb, PZ_SRU_VERSION))
&& *sru_version)
ZOOM_options_set(zoptions, "sru_version", sru_version);
if (!(con->link = ZOOM_connection_create(zoptions)))
PZ_MAX_CONNECTIONS);
if (v && *v)
max_connections = atoi(v);
-
+
v = session_setting_oneval(client_get_database(cl),
PZ_REUSE_CONNECTIONS);
if (v && *v)
for (p = service->databases; p; p = p->next)
if (!strcmp(p->id, id))
return p;
-
+
yaz_log(YLOG_DEBUG, "new database %s under service %s", id,
service->id ? service->id : "null");
p = new_database_inherit_settings(id, service->nmem, service->settings);
// This will be generalized at some point
static int match_criterion(struct setting **settings,
- struct conf_service *service,
+ struct conf_service *service,
struct database_criterion *c)
{
int offset = settings_lookup_offset(service, c->name);
if (match_zurl(settings[offset]->value, v->value))
break;
}
- else
+ else
{
if (!strcmp(settings[offset]->value, v->value))
break;
}
- }
+ }
else if (c->type == PAZPAR2_SUBSTRING_MATCH)
{
if (strstr(settings[offset]->value, v->value))
// returns AF_INET address.
if ((res = getaddrinfo(hostport, port, &hints, &addrinfo)))
{
- yaz_log(YLOG_WARN, "Failed to resolve %s %s",
+ yaz_log(YLOG_WARN, "Failed to resolve %s %s",
w->hostport, gai_strerror(res));
}
else
char ipport[128];
unsigned char addrbuf[4];
assert(addrinfo->ai_family == PF_INET);
- memcpy(addrbuf,
+ memcpy(addrbuf,
&((struct sockaddr_in*)addrinfo->ai_addr)->sin_addr.s_addr, 4);
sprintf(ipport, "%u.%u.%u.%u:%s",
addrbuf[0], addrbuf[1], addrbuf[2], addrbuf[3], port);
static void getaddrinfo_start(iochan_man_t iochan_man)
{
int fd;
- sel_thread_t p = resolver_thread =
+ sel_thread_t p = resolver_thread =
sel_thread_create(work_handler, 0 /* work_destroy */, &fd,
3 /* no of resolver threads */);
if (!p)
else
{
char *cp;
-
+
host->tproxy = xmalloc (strlen(url) + 10); /* so we can add :port */
strcpy(host->tproxy, url);
for (cp = host->tproxy; *cp; cp++)
}
-struct http_header * http_header_append(struct http_channel *ch,
- struct http_header * hp,
- const char *name,
+struct http_header * http_header_append(struct http_channel *ch,
+ struct http_header * hp,
+ const char *name,
const char *value)
{
- struct http_header *hpnew = 0;
+ struct http_header *hpnew = 0;
if (!hp | !ch)
return 0;
hpnew = nmem_malloc(ch->nmem, sizeof *hpnew);
hpnew->name = nmem_strdup(ch->nmem, name);
hpnew->value = nmem_strdup(ch->nmem, value);
-
+
hpnew->next = 0;
hp->next = hpnew;
hp = hp->next;
-
+
return hpnew;
}
return hp;
}
-
+
static int is_inprogress(void)
{
#ifdef WIN32
return 1;
#endif
return 0;
-}
+}
static void enable_nonblock(int sock)
{
if (ioctlsocket(sock, FIONBIO, &flags) < 0)
yaz_log(YLOG_FATAL|YLOG_ERRNO, "ioctlsocket");
#else
- if ((flags = fcntl(sock, F_GETFL, 0)) < 0)
+ if ((flags = fcntl(sock, F_GETFL, 0)) < 0)
yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl");
if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0)
yaz_log(YLOG_FATAL|YLOG_ERRNO, "fcntl2");
abort();
enable_nonblock(sock);
if (connect(sock, (struct sockaddr *)
- c->server->http_server->proxy_addr,
+ c->server->http_server->proxy_addr,
sizeof(*c->server->http_server->proxy_addr)) < 0)
{
- if (!is_inprogress())
+ if (!is_inprogress())
{
yaz_log(YLOG_WARN|YLOG_ERRNO, "Proxy connect");
return -1;
yaz_log(YLOG_WARN, "Failed to find Host header in proxy");
return -1;
}
-
+
// Add new header about paraz2 version, host, remote client address, etc.
{
char server_via[128];
hp = rq->headers;
- hp = http_header_append(c, hp,
+ hp = http_header_append(c, hp,
"X-Pazpar2-Version", PACKAGE_VERSION);
- hp = http_header_append(c, hp,
+ hp = http_header_append(c, hp,
"X-Pazpar2-Server-Host", ser->host);
sprintf(server_port, "%d", ser->port);
- hp = http_header_append(c, hp,
+ hp = http_header_append(c, hp,
"X-Pazpar2-Server-Port", server_port);
- yaz_snprintf(server_via, sizeof(server_via),
- "1.1 %s:%s (%s/%s)",
+ yaz_snprintf(server_via, sizeof(server_via),
+ "1.1 %s:%s (%s/%s)",
ser->host ? ser->host : "@",
server_port, PACKAGE_NAME, PACKAGE_VERSION);
hp = http_header_append(c, hp, "Via" , server_via);
hp = http_header_append(c, hp, "X-Forwarded-For", c->addr);
}
-
+
requestbuf = http_serialize_request(rq);
http_buf_enqueue(&p->oqueue, requestbuf);
{
int res, reqlen;
struct http_buf *htbuf;
-
+
htbuf = http_buf_create(hc->http_server);
res = recv(iochan_getfd(i), htbuf->buf, HTTP_BUF_SIZE -1, 0);
if (res == -1 && errno == EAGAIN)
}
}
}
- if (!hc->oqueue && hc->proxy && !hc->proxy->iochan)
+ if (!hc->oqueue && hc->proxy && !hc->proxy->iochan)
http_channel_destroy(i); // Server closed; we're done
}
else
return;
}
if (res == htbuf->len)
- {
+ {
struct http_buf *np = htbuf->next;
http_buf_destroy(hc->http_server, htbuf);
pc->oqueue = np;
yaz_log(YLOG_DEBUG, "New command connection");
c = iochan_create(s, http_io, EVENT_INPUT | EVENT_EXCEPT, "http_session_socket");
-
+
ch = http_channel_create(server->http_server, inet_ntoa(addr.sin_addr),
server);
ch->iochan = c;
&one, sizeof(one)) < 0)
return 1;
- if (bind(l, (struct sockaddr *) &myaddr, sizeof myaddr) < 0)
+ if (bind(l, (struct sockaddr *) &myaddr, sizeof myaddr) < 0)
{
yaz_log(YLOG_FATAL|YLOG_ERRNO, "bind");
return 1;
}
- if (listen(l, SOMAXCONN) < 0)
+ if (listen(l, SOMAXCONN) < 0)
{
yaz_log(YLOG_FATAL|YLOG_ERRNO, "listen");
return 1;
int http_init(const char *addr, struct conf_server *ser,
const char *record_fname);
void http_close_server(struct conf_server *ser);
-void http_addheader(struct http_response *r,
+void http_addheader(struct http_response *r,
const char *name, const char *value);
const char *http_lookup_header(struct http_header *header,
const char *name);
-struct http_header * http_header_append(struct http_channel *ch,
- struct http_header * hp,
- const char *name,
+struct http_header * http_header_append(struct http_channel *ch,
+ struct http_header * hp,
+ const char *name,
const char *value);
const char *http_argbyname(struct http_request *r, const char *name);
const char *http_headerbyname(struct http_header *r, const char *name);
struct mallinfo minfo;
minfo = mallinfo();
wrbuf_printf(wrbuf, " <memory>\n"
- " <arena>%d</arena>\n"
+ " <arena>%d</arena>\n"
" <uordblks>%d</uordblks>\n"
" <fordblks>%d</fordblks>\n"
" <ordblks>%d</ordblks>\n"
" <keepcost>%d</keepcost>\n"
- " <hblks>%d</hblks>\n"
+ " <hblks>%d</hblks>\n"
" <hblkhd>%d</hblkhd>\n"
" <virt>%d</virt>\n"
" <virtuse>%d</virtuse>\n"
- " </memory>\n",
+ " </memory>\n",
minfo.arena, minfo.uordblks, minfo.fordblks,minfo.ordblks, minfo.keepcost, minfo.hblks, minfo.hblkhd, minfo.arena + minfo.hblkhd, minfo.uordblks + minfo.hblkhd);
}
return "No error";
}
-static void error(struct http_response *rs,
+static void error(struct http_response *rs,
enum pazpar2_error_code code,
const char *addinfo)
{
WRBUF text = wrbuf_alloc();
const char *http_status = "417";
const char *msg = get_msg(code);
-
+
rs->msg = nmem_strdup(c->nmem, msg);
strcpy(rs->code, http_status);
yaz_log(YLOG_WARN|YLOG_ERRNO, "gettimeofday");
exit(1);
}
- /* at most 256 sessions per second ..
+ /* at most 256 sessions per second ..
(long long would be more appropriate)*/
res = t.tv_sec;
res = ((res << 8) | (seq & 0xff)) & ((1U << 31) - 1);
struct http_session *s;
struct http_response *rs = c->response;
struct conf_service *service = 0; /* no service (yet) */
-
- if (r->content_len && content_type &&
+
+ if (r->content_len && content_type &&
!yaz_strcmp_del("text/xml", content_type, "; "))
{
xmlDoc *doc = xmlParseMemory(r->content_buf, r->content_len);
return;
}
}
-
+
if (!service)
{
const char *service_name = http_argbyname(c->request, "service");
}
sesid = make_sessionid();
s = http_session_create(service, c->http_sessions, sesid);
-
+
yaz_log(c->http_sessions->log_level, "Session init %u ", sesid);
if (!clear || *clear == '0')
session_init_databases(s->psession);
else
yaz_log(YLOG_LOG, "Session %u init: No databases preloaded", sesid);
-
+
if (process_settings(s->psession, c->request, c->response) < 0)
return;
}
wrbuf_puts(c->wrbuf, "</session>"
"<protocol>" PAZPAR2_PROTOCOL_VERSION "</protocol>");
-
+
wrbuf_printf(c->wrbuf, "<keepAlive>%d</keepAlive>\n", 1000 * ((s->psession->service->session_timeout >= 20) ?
(s->psession->service->session_timeout - 10) : 50));
response_close(c, "init");
if (!s)
return;
- if (rq->content_len && content_type &&
+ if (rq->content_len && content_type &&
!yaz_strcmp_del("text/xml", content_type, "; "))
{
xmlDoc *doc = xmlParseMemory(rq->content_buf, rq->content_len);
error(rs, PAZPAR2_MALFORMED_SETTING, 0);
release_session(c,s);
return;
- }
+ }
}
if (process_settings(s->psession, rq, rs) < 0)
{
wrbuf_xmlputs(c->wrbuf, ht[i].id);
wrbuf_puts(c->wrbuf, "</id>\n");
- if (ht[i].name && ht[i].name[0])
+ if (ht[i].name && ht[i].name[0])
{
wrbuf_puts(c->wrbuf, "<name>");
wrbuf_xmlputs(c->wrbuf, ht[i].name);
const char *offsetstr = http_argbyname(rq, "offset");
const char *binarystr = http_argbyname(rq, "binary");
const char *checksumstr = http_argbyname(rq, "checksum");
-
+
if (!s)
return;
service = s->psession->service;
struct record*r = rec->records;
int binary = 0;
const char *nativesyntax = http_argbyname(rq, "nativesyntax");
-
+
if (binarystr && *binarystr != '0')
binary = 1;
syntax, esn,
obs /* data */,
show_raw_record_error,
- (binary ?
- show_raw_record_ok_binary :
+ (binary ?
+ show_raw_record_ok_binary :
show_raw_record_ok),
(binary ? 1 : 0),
nativesyntax);
wrbuf_xmlputs(c->wrbuf, next_r->recid);
wrbuf_puts(c->wrbuf, "</nextrecid>\n");
}
- wrbuf_printf(c->wrbuf, "<activeclients>%d</activeclients>\n",
+ wrbuf_printf(c->wrbuf, "<activeclients>%d</activeclients>\n",
session_active_clients(s->psession));
write_metadata(c->wrbuf, service, rec->metadata, 1);
for (r = rec->records; r; r = r->next)
return;
}
-
+
rl = show_range_start(s->psession, sp, startn, &numn, &total, &total_hits, &approx_hits);
response_open(c, "show");
int report_error = 0;
if (block_error && !strcmp("1", block_error)) {
report_error = 1;
- }
+ }
if (!s)
return;
if (!sort)
sort = "relevance";
-
+
if (!(sp = reclist_parse_sortparms(c->nmem, sort, s->psession->service)))
{
error(c->response, PAZPAR2_MALFORMED_PARAMETER_VALUE, "sort");
}
else
{
- yaz_log(YLOG_WARN, "Session %u: Attempt to block multiple times on show (preferred targets) block. Not supported!",
+ yaz_log(YLOG_WARN, "Session %u: Attempt to block multiple times on show (preferred targets) block. Not supported!",
s->session_id);
if (report_error) {
error(rs, PAZPAR2_ALREADY_BLOCKED, "show (preferred targets)");
wrbuf_puts(c->wrbuf, "</yaz>\n");
wrbuf_puts(c->wrbuf, " </version>\n");
-
+
info_services(c->server, c->wrbuf);
response_close(c, "info");
*/
-/** \file
+/** \file
\brief Jenkins hash function
*/
*/
-/** \file
+/** \file
\brief MARC MAP utilities (hash lookup etc)
*/
if (field)
{
sub_node = field_node->children;
- while (sub_node)
+ while (sub_node)
{
if ((sub_node->type == XML_ELEMENT_NODE) &&
!strcmp((const char *) sub_node->name, "subfield"))
xmlFree(code);
}
sub_node = sub_node->next;
- }
+ }
}
}
field_node = field_node->next;
int slot;
struct marcfield *new;
struct marcfield *last;
-
+
slot = jenkins_hash((const unsigned char *) key) & MARCHASH_MASK;
new = marchash->table[slot];
last = NULL;
-
- while (new)
+
+ while (new)
{
- last = new;
- new = new->next;
+ last = new;
+ new = new->next;
}
new = nmem_malloc(marchash->nmem, sizeof (struct marcfield));
new->next = NULL;
new->subfields = NULL;
strncpy(new->key, key, 4);
-
- // only 3 char in a marc field name
+
+ // only 3 char in a marc field name
if (new->key[3] != '\0')
return 0;
struct marcfield *cur;
if (last)
cur = last->next;
- else
+ else
cur = marchash->table[jenkins_hash((const unsigned char *)key) & MARCHASH_MASK];
while (cur)
{
{
outsize += strlen(cur->val) + delimsize;
cur = cur->next;
- }
+ }
if (outsize > 0)
- output = nmem_malloc(nmem, outsize);
+ output = nmem_malloc(nmem, outsize);
else
return NULL;
*output = '\0';
{
strtrimcat(output, cur->val);
if (cur->next)
- strcat(output, delim);
+ strcat(output, delim);
cur = cur->next;
- }
+ }
return output;
}
/*
mmhead = NULL;
fp = fopen(filename, "r");
- while ((c = getc(fp) ) != EOF)
+ while ((c = getc(fp) ) != EOF)
{
// allocate some space
if (newrec)
{
- if (mm != NULL)
+ if (mm != NULL)
{
mm->next = nmem_malloc(nmem, sizeof(struct marcmap));
mm = mm->next;
}
// first one!
- else
+ else
{ mm = nmem_malloc(nmem, sizeof(struct marcmap));
mmhead = mm;
}
mm->subfield = buf[len-2];
}
// third, pz fieldname
- else if (field == 2)
- {
+ else if (field == 2)
+ {
mm->pz = nmem_malloc(nmem, len * sizeof(char));
strncpy(mm->pz, buf, len);
}
xmlDocPtr xml_out;
xmlNodePtr xml_out_root;
xmlNodePtr rec_node;
- xmlNodePtr meta_node;
+ xmlNodePtr meta_node;
struct marchash *marchash;
struct marcfield *field;
struct marcsubfield *subfield;
struct marcmap *mmcur;
-
+
xml_out = xmlNewDoc(BAD_CAST "1.0");
xml_out->encoding = xmlCharStrdup("UTF-8");
xml_out_root = xmlNewNode(NULL, BAD_CAST "record");
xmlDocSetRootElement(xml_out, xml_out_root);
- ns_pz = xmlNewNs(xml_out_root, BAD_CAST "http://www.indexdata.com/pazpar2/1.0", BAD_CAST "pz");
+ ns_pz = xmlNewNs(xml_out_root, BAD_CAST "http://www.indexdata.com/pazpar2/1.0", BAD_CAST "pz");
xmlSetNs(xml_out_root, ns_pz);
nmem = nmem_create();
rec_node = xmlDocGetRootElement(xml_in);
if ((mmcur->subfield == '$') && (s = field->val))
{
meta_node = xmlNewChild(xml_out_root, ns_pz, BAD_CAST "metadata", BAD_CAST s);
- xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz);
+ xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz);
}
// catenate all subfields
else if ((mmcur->subfield == '*') && (s = marchash_catenate_subfields(field, " ", nmem)))
xmlSetProp(meta_node, BAD_CAST "type", BAD_CAST mmcur->pz);
}
// subfield value
- else if (mmcur->subfield)
+ else if (mmcur->subfield)
{
subfield = 0;
- while ((subfield =
+ while ((subfield =
marchash_get_subfield(mmcur->subfield,
field, subfield)) != 0)
{
}
}
}
-
+
}
mmcur = mmcur->next;
}
*(pout--) = '\0';
}
while (pout > buf && *pout == ' ');
-
+
return buf;
}
(*m)->marcmap = NULL;
(*m)->stylesheet = NULL;
(*m)->stylesheet2 = NULL;
-
-
+
+
(*m)->stylesheet = xsltParseStylesheetDoc(xsp_doc);
if (!(*m)->stylesheet)
no_errors++;
for (i = 0; i < num; i++)
{
WRBUF fname = conf_get_fname(conf, stylesheets[i]);
-
+
*m = nmem_malloc(nt->nmem, sizeof(**m));
(*m)->marcmap = NULL;
(*m)->stylesheet = NULL;
-
+
(*m)->stylesheet2 = service_xslt_get(service, stylesheets[i]);
if ((*m)->stylesheet2)
;
- else if (!strcmp(&stylesheets[i][strlen(stylesheets[i])-4], ".xsl"))
- {
+ else if (!strcmp(&stylesheets[i][strlen(stylesheets[i])-4], ".xsl"))
+ {
if (!((*m)->stylesheet =
xsltParseStylesheetFile((xmlChar *) wrbuf_cstr(fname))))
{
yaz_log(YLOG_FATAL, "Cannot handle stylesheet: %s", stylesheets[i]);
no_errors++;
}
-
+
wrbuf_destroy(fname);
m = &(*m)->next;
}
ndoc = 0;
xmlFreeDoc(*doc);
*doc = 0;
-
+
if (ndoc)
root = xmlDocGetRootElement(ndoc);
static void show_version(void)
{
char yaz_version_str[80];
- printf("Pazpar2 " PACKAGE_VERSION
+ printf("Pazpar2 " PACKAGE_VERSION
#ifdef PAZPAR2_VERSION_SHA1
" "
PAZPAR2_VERSION_SHA1
printf(" yaz:%s", yaz_version_str);
printf("\n");
exit(0);
-}
+}
#ifdef WIN32
static int tcpip_init (void)
static int sc_main(
- yaz_sc_t s,
+ yaz_sc_t s,
int argc, char **argv)
{
int daemon = 0;
#else
chdir
#endif
- (arg))
+ (arg))
{
yaz_log(YLOG_FATAL|YLOG_ERRNO, "chdir %s", arg);
return 1;
return 1;
}
pazpar2_mutex_init();
-
+
config = config_create(config_fname, global_parameters.dump_records);
if (!config)
return 1;
ret = config_start_listeners(config, listener_override, record_fname);
if (ret)
return ret; /* error starting http listener */
-
+
yaz_sc_running(s);
-
+
yaz_daemon("pazpar2",
(global_parameters.debug_mode ? YAZ_DAEMON_DEBUG : 0) +
(daemon ? YAZ_DAEMON_FORK : 0) + YAZ_DAEMON_KEEPALIVE,
{
int ret;
yaz_sc_t s = yaz_sc_create("pazpar2", "Pazpar2");
-
+
#ifdef MTRACE
mtrace();
#endif
{
NMEM nmem; /* for conf_config and servers memory */
struct conf_server *servers;
-
+
int no_threads;
WRBUF confdir;
iochan_man_t iochan_man;
xsltStylesheetPtr xsp;
struct service_xslt *next;
};
-
-static void conf_metadata_assign(NMEM nmem,
+
+static void conf_metadata_assign(NMEM nmem,
struct conf_metadata * metadata,
const char *name,
enum conf_metadata_type type,
const char *limitmap)
{
assert(nmem && metadata && name);
-
+
metadata->name = nmem_strdup(nmem, name);
metadata->type = type;
if (metadata->type == Metadata_type_year)
metadata->merge = Metadata_merge_range;
else
- metadata->merge = merge;
+ metadata->merge = merge;
metadata->setting = setting;
- metadata->brief = brief;
+ metadata->brief = brief;
metadata->termlist = termlist;
metadata->rank = nmem_strdup_null(nmem, rank);
metadata->sortkey_offset = sortkey_offset;
}
-static void conf_sortkey_assign(NMEM nmem,
+static void conf_sortkey_assign(NMEM nmem,
struct conf_sortkey * sortkey,
const char *name,
enum conf_sortkey_type type)
{
assert(nmem && sortkey && name);
-
+
sortkey->name = nmem_strdup(nmem, name);
sortkey->type = type;
}
service->metadata = 0;
if (service->num_metadata)
- service->metadata
- = nmem_malloc(nmem,
+ service->metadata
+ = nmem_malloc(nmem,
sizeof(struct conf_metadata) * service->num_metadata);
service->num_sortkeys = num_sortkeys;
service->sortkeys = 0;
if (service->num_sortkeys)
- service->sortkeys
- = nmem_malloc(nmem,
+ service->sortkeys
+ = nmem_malloc(nmem,
sizeof(struct conf_sortkey) * service->num_sortkeys);
- return service;
+ return service;
}
static struct conf_metadata* conf_service_add_metadata(
if (!service || !service->metadata || !service->num_metadata)
return -1;
-
+
for (i = 0; i < service->num_metadata; i++)
if (!strcmp(name, (service->metadata[i]).name))
return i;
return -1;
}
}
-
+
// now do the parsing logic
if (!xml_name)
{
return -1;
}
}
-
+
if (xml_termlist)
{
if (!strcmp((const char *) xml_termlist, "yes"))
return -1;
}
}
-
+
if (xml_type)
{
if (!strcmp((const char *) xml_type, "generic"))
type = Metadata_type_date;
else
{
- yaz_log(YLOG_FATAL,
+ yaz_log(YLOG_FATAL,
"Unknown value for metadata/type: %s", xml_type);
return -1;
}
}
-
+
if (xml_merge)
{
if (!strcmp((const char *) xml_merge, "no"))
merge = Metadata_merge_all;
else
{
- yaz_log(YLOG_FATAL,
+ yaz_log(YLOG_FATAL,
"Unknown value for metadata/merge: %s", xml_merge);
return -1;
}
}
-
+
if (xml_setting)
{
if (!strcmp((const char *) xml_setting, "no"))
return -1;
}
}
-
+
// add a sortkey if so specified
if (xml_sortkey && strcmp((const char *) xml_sortkey, "no"))
{
enum conf_sortkey_type sk_type;
if (merge == Metadata_merge_no)
{
- yaz_log(YLOG_FATAL,
+ yaz_log(YLOG_FATAL,
"Can't specify sortkey on a non-merged field");
return -1;
}
else
{
yaz_log(YLOG_FATAL,
- "Unknown sortkey in metadata element: %s",
+ "Unknown sortkey in metadata element: %s",
xml_sortkey);
return -1;
}
sortkey_offset = *sk_node;
-
+
conf_service_add_sortkey(service, *sk_node,
- (const char *) xml_name, sk_type);
+ (const char *) xml_name, sk_type);
(*sk_node)++;
}
else
sortkey_offset = -1;
-
+
if (xml_mergekey)
{
if (!strcmp((const char *) xml_mergekey, "required"))
int num_metadata = 0;
int num_sortkeys = 0;
int got_settings = 0;
-
+
// count num_metadata and num_sortkeys
for (n = node->children; n; n = n->next)
if (n->type == XML_ELEMENT_NODE && !strcmp((const char *)
}
value = (char *) xmlGetProp(n, (xmlChar *) "value");
if (!value)
- {
+ {
xmlFree(name);
yaz_log(YLOG_FATAL, "ccldirective: missing @value");
return 0;
init_settings(s);
}
}
-
+
/* use relevance/sort/mergekey/facet from server if not defined
for this service.. */
if (!s->charsets)
{
yaz_log(YLOG_FATAL, "ICU chain definition error");
return 0;
- }
- }
+ }
+ }
else if (!strcmp((const char *) n->name, "service"))
{
char *service_id = (char *)
config->database_hosts = database_hosts_create();
config->confdir = wrbuf_alloc();
- if ((p = strrchr(fname,
+ if ((p = strrchr(fname,
#ifdef WIN32
'\\'
#else
wrbuf_write(config->confdir, fname, len);
}
wrbuf_puts(config->confdir, "");
-
+
n = xmlDocGetRootElement(doc);
r = yaz_xml_include_simple(n, wrbuf_cstr(config->confdir));
if (r == 0) /* OK */
if (config)
{
struct conf_server *server = config->servers;
- iochan_man_destroy(&config->iochan_man);
+ iochan_man_destroy(&config->iochan_man);
while (server)
{
struct conf_server *s_next = server->next;
void config_process_events(struct conf_config *conf)
{
struct conf_server *ser;
-
+
for (ser = conf->servers; ser; ser = ser->next)
{
struct conf_service *s = ser->service;
// An array of these structure provides a 'map' against which
// discovered metadata elements are matched. It also governs storage,
// to minimize number of cycles needed at various tages of processing
-struct conf_metadata
+struct conf_metadata
{
char *name; // The field name. Output by normalization stylesheet
int brief; // Is this element to be returned in the brief format?
}
else
spec.tv_usec = tv_usec1 - tv_usec0;
-
+
select(0, 0, 0, 0, &spec);
}
tv_sec0 = tv_sec1;
hints.ai_addr = NULL;
hints.ai_canonname = NULL;
hints.ai_next = NULL;
-
+
cp = strchr(host, ':');
if (*cp)
{
if (!(cpp = strchr(parms, ',')))
cpp = parms + strlen(parms);
- strncpy(parm, parms, cpp - parms);
+ strncpy(parm, parms, cpp - parms);
parm[cpp-parms] = '\0';
if ((pp = strchr(parm, ':')))
yaz_log(YLOG_FATAL, "Bad sortkey modifier: %s", parm);
return 0;
}
-
+
if (pp[2])
{
if (pp[2] == 'p')
if (!strcmp(parm, "relevance"))
{
type = Metadata_sortkey_relevance;
- }
+ }
else if (!strcmp(parm, "position"))
{
type = Metadata_sortkey_position;
static int reclist_cmp(const void *p1, const void *p2)
{
- struct reclist_sortparms *sortparms =
+ struct reclist_sortparms *sortparms =
(*(struct reclist_bucket **) p1)->sort_parms;
struct record_cluster *r1 = (*(struct reclist_bucket**) p1)->record;
struct record_cluster *r2 = (*(struct reclist_bucket**) p2)->record;
{
struct reclist *res = nmem_malloc(nmem, sizeof(struct reclist));
res->hash_size = 399;
- res->hashtable
+ res->hashtable
= nmem_malloc(nmem, res->hash_size * sizeof(struct reclist_bucket*));
memset(res->hashtable, 0, res->hash_size * sizeof(struct reclist_bucket*));
res->nmem = nmem;
// Insert a record. Return record cluster (newly formed or pre-existing)
struct record_cluster *reclist_insert(struct reclist *l,
- struct conf_service *service,
+ struct conf_service *service,
struct record *record,
const char *merge_key, int *total)
{
unsigned int bucket;
struct reclist_bucket **p;
struct record_cluster *cluster = 0;
-
+
assert(service);
assert(l);
assert(record);
{
if (re->client == record->client &&
record_compare(record, re, service))
- {
+ {
yaz_mutex_leave(l->mutex);
return 0;
}
nmem_malloc(l->nmem, sizeof(*new));
cluster = nmem_malloc(l->nmem, sizeof(*cluster));
-
+
record->next = 0;
new->record = cluster;
new->hnext = 0;
cluster->metadata =
nmem_malloc(l->nmem,
sizeof(struct record_metadata*) * service->num_metadata);
- memset(cluster->metadata, 0,
+ memset(cluster->metadata, 0,
sizeof(struct record_metadata*) * service->num_metadata);
- cluster->sortkeys =
+ cluster->sortkeys =
nmem_malloc(l->nmem, sizeof(struct record_metadata*) * service->num_sortkeys);
memset(cluster->sortkeys, 0,
sizeof(union data_types*) * service->num_sortkeys);
-
+
/* attach to hash list */
- *p = new;
+ *p = new;
/* append to sorted_list */
*l->last = new;
#include "client.h"
#include "record.h"
-union data_types * data_types_assign(NMEM nmem,
- union data_types ** data1,
+union data_types * data_types_assign(NMEM nmem,
+ union data_types ** data1,
union data_types data2)
{
// assert(nmem);
else
*data1 = nmem_malloc(nmem, sizeof(union data_types));
}
-
+
**data1 = data2;
return *data1;
}
int i = 0;
const char *name = client_get_id(client);
unsigned h = position;
-
+
// assert(nmem);
record = nmem_malloc(nmem, sizeof(struct record));
record->next = 0;
record->client = client;
- record->metadata
- = nmem_malloc(nmem,
+ record->metadata
+ = nmem_malloc(nmem,
sizeof(struct record_metadata*) * num_metadata);
for (i = 0; i < num_metadata; i++)
record->metadata[i] = 0;
-
- record->sortkeys
- = nmem_malloc(nmem,
+
+ record->sortkeys
+ = nmem_malloc(nmem,
sizeof(union data_types*) * num_sortkeys);
for (i = 0; i < num_sortkeys; i++)
record->sortkeys[i] = 0;
h = h * 65509 + ((unsigned char *) name)[i];
record->checksum = h;
-
+
return record;
}
struct record_metadata * record_metadata_create(NMEM nmem)
{
- struct record_metadata * rec_md
+ struct record_metadata * rec_md
= nmem_malloc(nmem, sizeof(struct record_metadata));
rec_md->next = 0;
rec_md->attributes = 0;
{
struct conf_metadata *ser_md = &service->metadata[i];
enum conf_metadata_type type = ser_md->type;
-
+
struct record_metadata *m1 = r1->metadata[i];
struct record_metadata *m2 = r2->metadata[i];
while (m1 && m2)
/* work on this item */
p->work_handler(work_this->data);
-
+
/* put it back into output queue */
yaz_mutex_enter(p->mutex);
work_this->next = p->output_queue;
#else
(void) write(p->write_fd, "", 1);
#endif
- }
+ }
yaz_mutex_leave(p->mutex);
return 0;
}
{
nmem_destroy(nmem);
return 0;
- }
+ }
*read_fd = p->read_fd = yaz_spipe_get_read_fd(p->spipe);
p->write_fd = yaz_spipe_get_write_fd(p->spipe);
p->stop_flag = 1;
yaz_cond_broadcast(p->input_data);
yaz_mutex_leave(p->mutex);
-
+
for (i = 0; i< p->no_threads; i++)
yaz_thread_join(&p->thread_id[i], 0);
/* put freed item in free list */
work_this->next = p->free_queue;
p->free_queue = work_this;
-
+
data = work_this->data;
#ifdef WIN32
(void) recv(p->read_fd, read_buf, 1, 0);
xsltStylesheetPtr xsp;
struct service_xslt *next;
};
-
+
xsltStylesheetPtr service_xslt_get(struct conf_service *service,
const char *id)
{
yaz_log(YLOG_FATAL, "Multiple xslt with id=%s", id);
return -1;
}
-
+
sx = nmem_malloc(service->nmem, sizeof(*sx));
sx->id = nmem_strdup(service->nmem, id);
sx->next = service->xslt_list;
service->xslt_list = sx;
-
+
xsp_doc = xmlNewDoc(BAD_CAST "1.0");
xmlDocSetRootElement(xsp_doc, xmlCopyNode(root, 1));
sx->xsp = xsltParseStylesheetDoc(xsp_doc);
#define MAX(a,b) ((a)>(b)?(a):(b))
// Note: Some things in this structure will eventually move to configuration
-struct parameters global_parameters =
+struct parameters global_parameters =
{
0, // dump_records
0, // debug_mode
WRBUF display_wrbuf = wrbuf_alloc();
session_normalize_facet(s, type, value, display_wrbuf, facet_wrbuf);
-
+
if (wrbuf_len(facet_wrbuf))
{
int i;
wrbuf_destroy(display_wrbuf);
return;
}
-
+
s->termlists[i].name = nmem_strdup(s->nmem, type);
s->termlists[i].termlist = termlist_create(s->nmem);
s->num_termlists = i + 1;
}
-
+
#if 0
session_log(s, YLOG_LOG, "Facets for %s: %s norm:%s (%d)", type, value, wrbuf_cstr(facet_wrbuf), count);
#endif
if (rdoc)
{
char *parms[MAX_XSLT_ARGS*2+1];
-
+
insert_settings_parameters(sdb, service, parms, nmem);
-
+
if (normalize_record_transform(sdb->map, &rdoc, (const char **)parms))
{
session_log(se, YLOG_WARN, "Normalize failed from %s",
else
{
insert_settings_values(sdb, rdoc, service);
-
+
if (global_parameters.dump_records)
{
- session_log(se, YLOG_LOG, "Normalized record from %s",
+ session_log(se, YLOG_LOG, "Normalized record from %s",
sdb->database->id);
log_xml_doc(rdoc);
}
const char *s;
if (sdb->settings[PZ_XSLT] &&
- (s = session_setting_oneval(sdb, PZ_XSLT)))
+ (s = session_setting_oneval(sdb, PZ_XSLT)))
{
char auto_stylesheet[256];
-
+
if (!strcmp(s, "auto"))
{
const char *request_syntax = session_setting_oneval(
}
// set watch. Returns 0=OK, -1 if watch is already set
-int session_set_watch(struct session *s, int what,
+int session_set_watch(struct session *s, int what,
session_watchfun fun, void *data,
struct http_channel *chan)
{
ret = -1;
else
{
-
+
s->watchlist[what].fun = fun;
s->watchlist[what].data = data;
s->watchlist[what].obs = http_add_observer(chan, &s->watchlist[what],
{
struct client_list *l_next = l->next;
- client_lock(l->client);
+ client_lock(l->client);
client_set_session(l->client, 0); /* mark client inactive */
client_unlock(l->client);
}
// Associates a set of clients with a session;
-// Note: Session-databases represent databases with per-session
+// Note: Session-databases represent databases with per-session
// setting overrides
static int select_targets(struct session *se, const char *filter)
{
nmem_reset(se->nmem);
se->total_records = se->total_merged = 0;
se->num_termlists = 0;
-
+
/* reset list of sorted results and clear to relevance search */
se->sorted_results = nmem_malloc(se->nmem, sizeof(*se->sorted_results));
se->sorted_results->field = nmem_strdup(se->nmem, sort_field);
se->sorted_results->increasing = increasing;
se->sorted_results->position = position;
se->sorted_results->next = 0;
-
+
se->reclist = reclist_create(se->nmem);
}
se->sorted_results = sr;
}
yaz_log(YLOG_DEBUG, "Restarting search for clients due to change in sort order");
-
+
for (l = se->clients_active; l; l = l->next)
{
struct client *cl = l->client;
session_remove_cached_clients(se);
else
session_reset_active_clients(se, 0);
-
+
session_enter(se);
se->settings_modified = 0;
session_clear_set(se, sort_field, increasing, 0); /* hardcoded position */
}
yaz_gettimeofday(&tval);
-
+
tval.tv_sec += 5;
facet_limits = facet_limits_create(limit);
int i;
new->database = db;
-
+
new->map = 0;
assert(db->settings);
new->settings = nmem_malloc(se->session_nmem,
// Probably session_init_databases_fun should be refactored instead of
// called here.
-static struct session_database *load_session_database(struct session *se,
+static struct session_database *load_session_database(struct session *se,
char *id)
{
struct database *db = new_database_inherit_settings(id, se->session_nmem, se->service->settings);
}
// Find an existing session database. If not found, load it
-static struct session_database *find_session_database(struct session *se,
+static struct session_database *find_session_database(struct session *se,
char *id)
{
struct session_database *sdb;
{
// do only print terms which have display names
-
+
wrbuf_puts(wrbuf, "<term>\n");
wrbuf_puts(wrbuf, "<id>");
wrbuf_xmlputs(wrbuf, ht[i].id);
wrbuf_puts(wrbuf, "</id>\n");
-
+
wrbuf_puts(wrbuf, "<name>");
if (!ht[i].name || !ht[i].name[0])
wrbuf_xmlputs(wrbuf, "NO TARGET NAME");
else
wrbuf_xmlputs(wrbuf, ht[i].name);
wrbuf_puts(wrbuf, "</name>\n");
-
+
wrbuf_printf(wrbuf, "<frequency>" ODR_INT_PRINTF "</frequency>\n",
ht[i].hits);
wrbuf_puts(wrbuf, "<state>");
wrbuf_xmlputs(wrbuf, ht[i].state);
wrbuf_puts(wrbuf, "</state>\n");
-
- wrbuf_printf(wrbuf, "<diagnostic>%d</diagnostic>\n",
+
+ wrbuf_printf(wrbuf, "<diagnostic>%d</diagnostic>\n",
ht[i].diagnostic);
wrbuf_puts(wrbuf, "</term>\n");
}
// prevent sending empty term elements
if (!p[i]->display_term || !p[i]->display_term[0])
continue;
-
+
wrbuf_puts(c->wrbuf, "<term>");
wrbuf_puts(c->wrbuf, "<name>");
wrbuf_xmlputs(c->wrbuf, p[i]->display_term);
wrbuf_puts(c->wrbuf, "</name>");
-
- wrbuf_printf(c->wrbuf,
- "<frequency>%d</frequency>",
+
+ wrbuf_printf(c->wrbuf,
+ "<frequency>%d</frequency>",
p[i]->frequency);
wrbuf_puts(c->wrbuf, "</term>\n");
}
nmem_get_memory_in_use(&in_use);
nmem_get_memory_free(&is_free);
- yaz_log(YLOG_LOG, "nmem stat: use=%ld free=%ld",
+ yaz_log(YLOG_LOG, "nmem stat: use=%ld free=%ld",
(long) in_use, (long) is_free);
}
#endif
}
struct record_cluster **show_range_start(struct session *se,
- struct reclist_sortparms *sp,
+ struct reclist_sortparms *sp,
int start, int *num, int *total, Odr_int *sumhits, Odr_int *approx_hits)
{
struct record_cluster **recs;
struct reclist_sortparms *spp;
int i;
-#if USE_TIMING
+#if USE_TIMING
yaz_timing_t t = yaz_timing_create();
#endif
session_enter(se);
{
*num = 0;
*total = 0;
- *sumhits = 0;
+ *sumhits = 0;
*approx_hits = 0;
recs = 0;
}
else
{
struct client_list *l;
-
+
for (spp = sp; spp; spp = spp->next)
if (spp->type == Metadata_sortkey_relevance)
{
break;
}
reclist_sort(se->reclist, sp);
-
+
reclist_enter(se->reclist);
*total = reclist_get_num_records(se->reclist);
recs = 0;
break;
}
-
+
for (i = 0; i < *num; i++)
{
struct record_cluster *r = reclist_read_record(se->reclist);
}
#if USE_TIMING
yaz_timing_stop(t);
- yaz_log(YLOG_LOG, "show %6.5f %3.2f %3.2f",
+ yaz_log(YLOG_LOG, "show %6.5f %3.2f %3.2f",
yaz_timing_get_real(t), yaz_timing_get_user(t),
yaz_timing_get_sys(t));
yaz_timing_destroy(&t);
{
struct record_metadata *rec_md = record_metadata_create(nmem);
struct record_metadata_attr **attrp = &rec_md->attributes;
-
+
for (; attr; attr = attr->next)
{
if (attr->children && attr->children->content)
char *p = nmem_strdup(nmem, value);
p = normalize7bit_generic(p, " ,/.:([");
-
+
rec_md->data.text.disp = p;
rec_md->data.text.sort = 0;
}
const char *norm_str;
pp2_charset_token_t prt =
pp2_charset_token_create(service->charsets, "mergekey");
-
+
pp2_charset_token_first(prt, (const char *) value, 0);
if (wrbuf_len(norm_wr) > 0)
wrbuf_puts(norm_wr, " ");
service, norm_wr);
if (r == 0 && ser_md->mergekey == Metadata_mergekey_required)
{
- /* no mergekey on this one and it is required..
+ /* no mergekey on this one and it is required..
Generate unique key instead */
wrbuf_rewind(norm_wr);
break;
return mergekey_norm;
}
-/** \brief see if metadata for pz:recordfilter exists
+/** \brief see if metadata for pz:recordfilter exists
\param root xml root element of normalized record
\param sdb session database for client
\retval 0 if there is no metadata for pz:recordfilter
If there is no pz:recordfilter defined, this function returns 1
as well.
*/
-
+
static int check_record_filter(xmlNode *root, struct session_database *sdb)
{
int match = 0;
xmlDoc *xdoc = normalize_record(se, sdb, service, rec, nmem);
xmlNode *root;
const char *mergekey_norm;
-
+
if (!xdoc)
return -1;
-
+
root = xmlDocGetRootElement(xdoc);
-
+
if (!check_record_filter(root, sdb))
{
session_log(se, YLOG_LOG, "Filtered out record no %d from %s", record_no, sdb->database->id);
xmlFreeDoc(xdoc);
return -2;
}
-
+
mergekey_norm = get_mergekey(xdoc, cl, record_no, service, nmem);
if (!mergekey_norm)
{
if (client_get_session(cl) == se)
ret = ingest_to_cluster(cl, xdoc, root, record_no, mergekey_norm);
session_leave(se);
-
+
xmlFreeDoc(xdoc);
return ret;
}
int md_field_id;
char **values = 0;
int i, num_v = 0;
-
+
const char *name = client_get_facet_limit_local(cl, sdb, &l, nmem_tmp, &num_v, &values);
if (!name)
break;
-
+
md_field_id = conf_service_metadata_field_id(service, name);
if (md_field_id < 0)
{
{
if (rec_md)
{
- if (ser_md->type == Metadata_type_year
+ if (ser_md->type == Metadata_type_year
|| ser_md->type == Metadata_type_date)
{
int y = atoi(values[i]);
- if (y >= rec_md->data.number.min
+ if (y >= rec_md->data.number.min
&& y <= rec_md->data.number.max)
break;
}
nmem_destroy(nmem_tmp);
return skip_record;
}
-
+
static int ingest_to_cluster(struct client *cl,
xmlDoc *xdoc,
xmlNode *root,
int term_factor = 1;
struct record_cluster *cluster;
struct session_database *sdb = client_get_database(cl);
- struct record *record = record_create(se->nmem,
+ struct record *record = record_create(se->nmem,
service->num_metadata,
service->num_sortkeys, cl,
record_no);
if (value)
xmlFree(value);
type = value = 0;
-
+
if (n->type != XML_ELEMENT_NODE)
continue;
if (!strcmp((const char *) n->name, "metadata"))
struct record_metadata **wheretoput = 0;
struct record_metadata *rec_md = 0;
int md_field_id = -1;
-
+
type = xmlGetProp(n, (xmlChar *) "type");
value = xmlNodeListGetString(xdoc, n->children, 1);
-
+
if (!type || !value || !*value)
continue;
-
- md_field_id
+
+ md_field_id
= conf_service_metadata_field_id(service, (const char *) type);
if (md_field_id < 0)
{
if (se->number_of_warnings_unknown_metadata == 0)
{
- session_log(se, YLOG_WARN,
+ session_log(se, YLOG_WARN,
"Ignoring unknown metadata element: %s", type);
}
se->number_of_warnings_unknown_metadata++;
continue;
}
-
+
ser_md = &service->metadata[md_field_id];
// non-merged metadata
relevance_newrec(se->relevance, cluster);
-
+
// now parsing XML record and adding data to cluster or record metadata
for (n = root->children; n; n = n->next)
{
if (value)
xmlFree(value);
type = value = 0;
-
+
if (n->type != XML_ELEMENT_NODE)
continue;
if (!strcmp((const char *) n->name, "metadata"))
int sk_field_id = -1;
const char *rank;
xmlChar *xml_rank;
-
+
type = xmlGetProp(n, (xmlChar *) "type");
value = xmlNodeListGetString(xdoc, n->children, 1);
-
+
if (!type || !value || !*value)
continue;
-
- md_field_id
+
+ md_field_id
= conf_service_metadata_field_id(service, (const char *) type);
if (md_field_id < 0)
continue;
-
+
ser_md = &service->metadata[md_field_id];
if (ser_md->sortkey_offset >= 0)
{
while (*wheretoput)
{
- if (!strcmp((const char *) (*wheretoput)->data.text.disp,
+ if (!strcmp((const char *) (*wheretoput)->data.text.disp,
rec_md->data.text.disp))
break;
wheretoput = &(*wheretoput)->next;
}
else if (ser_md->merge == Metadata_merge_longest)
{
- if (!*wheretoput
- || strlen(rec_md->data.text.disp)
+ if (!*wheretoput
+ || strlen(rec_md->data.text.disp)
> strlen((*wheretoput)->data.text.disp))
{
*wheretoput = rec_md;
if (ser_sk)
{
const char *sort_str = 0;
- int skip_article =
+ int skip_article =
ser_sk->type == Metadata_sortkey_skiparticle;
if (!cluster->sortkeys[sk_field_id])
- cluster->sortkeys[sk_field_id] =
- nmem_malloc(se->nmem,
+ cluster->sortkeys[sk_field_id] =
+ nmem_malloc(se->nmem,
sizeof(union data_types));
-
+
prt =
pp2_charset_token_create(service->charsets, "sort");
skip_article);
pp2_charset_token_next(prt);
-
+
sort_str = pp2_get_sort(prt);
-
- cluster->sortkeys[sk_field_id]->text.disp =
+
+ cluster->sortkeys[sk_field_id]->text.disp =
rec_md->data.text.disp;
if (!sort_str)
{
sort_str = rec_md->data.text.disp;
- session_log(se, YLOG_WARN,
+ session_log(se, YLOG_WARN,
"Could not make sortkey. Bug #1858");
}
- cluster->sortkeys[sk_field_id]->text.sort =
+ cluster->sortkeys[sk_field_id]->text.sort =
nmem_strdup(se->nmem, sort_str);
pp2_charset_token_destroy(prt);
}
{
*wheretoput = rec_md;
if (ser_sk)
- cluster->sortkeys[sk_field_id]
+ cluster->sortkeys[sk_field_id]
= &rec_md->data;
}
else
}
}
- // ranking of _all_ fields enabled ...
+ // ranking of _all_ fields enabled ...
if (rank)
{
- relevance_countwords(se->relevance, cluster,
+ relevance_countwords(se->relevance, cluster,
(char *) value, rank, ser_md->name);
}
size_t maxlen;
int i;
const char *p;
-
+
assert(name);
if (!strncmp("pz:", name, 3) && (p = strchr(name + 3, ':')))
xmlDocSetRootElement(doc, xmlCopyNode(root, 1));
xmlDocDumpMemory(doc, &buf_out, &len_out);
/* xmlDocDumpMemory 0-terminates */
- set.value = (char *) buf_out;
+ set.value = (char *) buf_out;
xmlFreeDoc(doc);
}
}
}
else
{
- yaz_log(YLOG_WARN, "Unknown element %s in settings file",
+ yaz_log(YLOG_WARN, "Unknown element %s in settings file",
(char*) n->name);
ret_val = -1;
}
xmlFree(targeta);
return ret_val;
}
-
+
static int read_settings_file(const char *path,
void *client_data,
void (*fun)(void *client_data,
}
-// Recursively read files or directories, invoking a
+// Recursively read files or directories, invoking a
// callback for each one
static int read_settings(const char *path,
void *client_data,
{
struct setting *set = ((struct update_database_context *)
context)->set;
- struct conf_service *service = ((struct update_database_context *)
+ struct conf_service *service = ((struct update_database_context *)
context)->service;
struct setting **sp;
int offset;
// Also create setting for some metadata attributes.
if (md->limitmap) {
- int index;
+ int index;
WRBUF wrbuf = wrbuf_alloc();
yaz_log(YLOG_DEBUG, "Metadata %s has limitmap: %s ",md->name, md->limitmap);
wrbuf_printf(wrbuf, "pz:limitmap:%s", md->name);
void init_settings(struct conf_service *service)
{
struct setting_dictionary *new;
-
+
assert(service->nmem);
-
+
new = nmem_malloc(service->nmem, sizeof(*new));
memset(new, 0, sizeof(*new));
service->dictionary = new;
struct termlist_score **highscore =
(struct termlist_score **)
nmem_malloc(nmem, tl->no_entries * sizeof(*highscore));
-
+
int no = 0;
unsigned bucket;
for (bucket = 0; bucket < tl->hash_size; bucket++)
#include "normalize7bit.h"
-int test_normalize7bit_generic(const char *rm_chars, const char *input,
+int test_normalize7bit_generic(const char *rm_chars, const char *input,
const char *expect_output)
{
int ret = 0;
int main(int argc, char **argv)
{
- YAZ_CHECK_INIT(argc, argv);
+ YAZ_CHECK_INIT(argc, argv);
YAZ_CHECK_LOG();
YAZ_CHECK(test_normalize7bit_generic("/; ", " how are you; ", "how are you"));
YAZ_CHECK(!test_normalize7bit_generic("/; ", " how are you; ", "how are youx"));
-
+
YAZ_CHECK(test_normalize7bit_generic("/; "," ", ""));
YAZ_CHECK(test_normalize7bit_mergekey("the art of computer", "the art of computer"));
YAZ_CHECK(test_normalize7bit_mergekey("The Art Of Computer", "the art of computer"));
-
+
YAZ_CHECK_TERM;
}
static void test_for_real_work(int no_threads)
{
int thread_fd;
- sel_thread_t p = sel_thread_create(work_handler, work_destroy,
+ sel_thread_t p = sel_thread_create(work_handler, work_destroy,
&thread_fd, no_threads);
YAZ_CHECK(p);
if (p)
int main(int argc, char **argv)
{
- YAZ_CHECK_INIT(argc, argv);
- YAZ_CHECK_LOG();
+ YAZ_CHECK_INIT(argc, argv);
+ YAZ_CHECK_LOG();
test_create_destroy();
test_for_real_work(1);