-/* $Id: config.c,v 1.39 2007-07-30 11:52:08 quinn Exp $
+/* $Id: config.c,v 1.40 2007-07-30 23:16:33 quinn Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
02111-1307, USA.
*/
-/* $Id: config.c,v 1.39 2007-07-30 11:52:08 quinn Exp $ */
+/* $Id: config.c,v 1.40 2007-07-30 23:16:33 quinn Exp $ */
#include <string.h>
else if (!strcmp((const char *) xml_setting, "postproc"))
setting = Metadata_setting_postproc;
else if (!strcmp((const char *) xml_setting, "parameter"))
- setting = Metadata_setting_no;
+ setting = Metadata_setting_parameter;
else
{
yaz_log(YLOG_FATAL,
-/* $Id: logic.c,v 1.57 2007-07-30 11:52:08 quinn Exp $
+/* $Id: logic.c,v 1.58 2007-07-30 23:16:33 quinn Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
return rdoc;
}
+#define MAX_XSLT_ARGS 16
+
+// Add static values from session database settings if applicable
+static void insert_settings_parameters(struct session_database *sdb,
+ struct session *se, char **parms)
+{
+ struct conf_service *service = global_parameters.server->service;
+ int i;
+ int nparms = 0;
+ int offset = 0;
+
+ for (i = 0; i < service->num_metadata; i++)
+ {
+ struct conf_metadata *md = &service->metadata[i];
+ int setting;
+
+ if (md->setting == Metadata_setting_parameter &&
+ (setting = settings_offset(md->name)) > 0)
+ {
+ char *val = session_setting_oneval(sdb, setting);
+ if (val && nparms < MAX_XSLT_ARGS)
+ {
+ char *buf;
+ int len = strlen(val);
+ buf = nmem_malloc(se->nmem, len + 3);
+ buf[0] = '\'';
+ strcpy(buf + 1, val);
+ buf[len+1] = '\'';
+ buf[len+2] = '\0';
+ parms[offset++] = md->name;
+ parms[offset++] = buf;
+ nparms++;
+ }
+ }
+ }
+ parms[offset] = 0;
+}
+
// Add static values from session database settings if applicable
static void insert_settings_values(struct session_database *sdb, xmlDoc *doc)
{
}
}
-xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec)
+xmlDoc *normalize_record(struct session_database *sdb, struct session *se,
+ Z_External *rec)
{
struct database_retrievalmap *m;
xmlDoc *rdoc = record_to_xml(sdb, rec);
{
xmlNodePtr root = 0;
- new = xsltApplyStylesheet(m->stylesheet, rdoc, 0);
+ char *parms[MAX_XSLT_ARGS*2+1];
+
+ insert_settings_parameters(sdb, se, parms);
+
+ new = xsltApplyStylesheet(m->stylesheet, rdoc, (const char **) parms);
root= xmlDocGetRootElement(new);
if (!new || !root || !(root->children))
{
struct record *ingest_record(struct client *cl, Z_External *rec,
int record_no)
{
- xmlDoc *xdoc = normalize_record(client_get_database(cl), rec);
+ xmlDoc *xdoc = normalize_record(client_get_database(cl),
+ client_get_session(cl), rec);
xmlNode *root, *n;
struct record *record;
struct record_cluster *cluster;
-/* $Id: pazpar2.h,v 1.45 2007-07-16 17:01:46 adam Exp $
+/* $Id: pazpar2.h,v 1.46 2007-07-30 23:16:33 quinn Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
int host_getaddrinfo(struct host *host);
-xmlDoc *normalize_record(struct session_database *sdb, Z_External *rec);
+xmlDoc *normalize_record(struct session_database *sdb, struct session *se,
+ Z_External *rec);
xmlDoc *record_to_xml(struct session_database *sdb, Z_External *rec);
struct record *ingest_record(struct client *cl, Z_External *rec,
-/* $Id: settings.c,v 1.25 2007-07-03 11:21:48 adam Exp $
+/* $Id: settings.c,v 1.26 2007-07-30 23:16:33 quinn Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
dict->num = dict->size;
}
+// Read any settings names introduced in service definition (config) and add to dictionary
+// This is done now to avoid errors if user settings are declared in session overrides
+static void initialize_soft_settings()
+{
+ struct conf_service *service = config->servers->service;
+ int i;
+
+ for (i = 0; i < service->num_metadata; i++)
+ {
+ struct setting set;
+ struct conf_metadata *md = &service->metadata[i];
+
+ if (md->setting == Metadata_setting_no)
+ continue;
+
+ set.precedence = 0;
+ set.target = "";
+ set.name = md->name;
+ set.value = "";
+ set.next = 0;
+ prepare_dictionary(&set);
+ }
+}
+
// If we ever decide we need to be able to specify multiple settings directories,
// the two calls to read_settings must be split -- so the dictionary is prepared
// for the contents of every directory before the databases are updated.
memset(new, 0, sizeof(*new));
initialize_hard_settings(new);
dictionary = new;
+ initialize_soft_settings();
}
/*
-/* $Id: test_config.c,v 1.3 2007-04-25 07:00:33 marc Exp $
+/* $Id: test_config.c,v 1.4 2007-07-30 23:16:33 quinn Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
YAZ_CHECK(!conf_service_add_metadata(0, service, 0, "dead_nmem",
Metadata_type_generic,
Metadata_merge_unique,
+ Metadata_setting_no,
1, 1, 1, 0));
YAZ_CHECK(!conf_service_add_metadata(nmem, 0, 0, "service_needed",
Metadata_type_generic,
Metadata_merge_unique,
+ Metadata_setting_no,
1, 1, 1, 0));
YAZ_CHECK(!conf_service_add_metadata(nmem, service, -1, "out_of_bounds",
Metadata_type_generic,
Metadata_merge_unique,
+ Metadata_setting_no,
1, 1, 1, 0));
YAZ_CHECK(!conf_service_add_metadata(nmem, service, 4, "out_of_bounds",
Metadata_type_generic,
Metadata_merge_unique,
+ Metadata_setting_no,
1, 1, 1, 0));
YAZ_CHECK(!conf_service_add_metadata(nmem, service, 0, 0, //missing name
Metadata_type_generic,
Metadata_merge_unique,
+ Metadata_setting_no,
1, 1, 1, 0));
// expected metadata sucesses
YAZ_CHECK(conf_service_add_metadata(nmem, service, 0, "title",
Metadata_type_generic,
Metadata_merge_unique,
+ Metadata_setting_no,
1, 1, 1, 0));
YAZ_CHECK(conf_service_add_metadata(nmem, service, 1, "author",
Metadata_type_generic,
Metadata_merge_longest,
+ Metadata_setting_no,
1, 1, 1, 0));
YAZ_CHECK(conf_service_add_metadata(nmem, service, 2, "isbn",
Metadata_type_number,
Metadata_merge_no,
+ Metadata_setting_no,
1, 1, 1, 0));
YAZ_CHECK(conf_service_add_metadata(nmem, service, 3, "year",
Metadata_type_year,
Metadata_merge_range,
+ Metadata_setting_no,
1, 1, 1, 0));
-/* $Id: test_record.c,v 1.7 2007-06-13 21:30:08 adam Exp $
+/* $Id: test_record.c,v 1.8 2007-07-30 23:16:33 quinn Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
YAZ_CHECK(conf_service_add_metadata(nmem, service, 0, "title",
Metadata_type_generic, Metadata_merge_unique,
- 1, 1, 1, 0));
+ Metadata_setting_no, 1, 1, 1, 0));
YAZ_CHECK(conf_service_add_metadata(nmem, service, 1, "author",
Metadata_type_generic, Metadata_merge_longest,
- 1, 1, 1, 0));
+ Metadata_setting_no,1, 1, 1, 0));
YAZ_CHECK(conf_service_add_metadata(nmem, service, 2, "isbn",
Metadata_type_number, Metadata_merge_no,
- 1, 1, 1, 0));
+ Metadata_setting_no, 1, 1, 1, 0));
YAZ_CHECK(conf_service_add_metadata(nmem, service, 3, "year",
Metadata_type_year, Metadata_merge_range,
- 1, 1, 1, 0));
+ Metadata_setting_no, 1, 1, 1, 0));
YAZ_CHECK(conf_service_add_sortkey(nmem, service, 0, "relevance",
Metadata_sortkey_relevance));