#include "pazpar2_config.h"
-static NMEM nmem = 0;
static char confdir[256] = ".";
struct conf_config *config = 0;
}
-struct conf_service * conf_service_create(NMEM nmem,
- int num_metadata, int num_sortkeys)
+struct conf_service * conf_service_create(int num_metadata, int num_sortkeys)
{
struct conf_service * service = 0;
+ NMEM nmem = nmem_create();
//assert(nmem);
= nmem_malloc(nmem,
sizeof(struct conf_sortkey) * service->num_sortkeys);
- service->nmem = 0;
+ service->nmem = nmem;
service->dictionary = 0;
return service;
}
-struct conf_metadata* conf_service_add_metadata(NMEM nmem,
- struct conf_service *service,
+struct conf_metadata* conf_service_add_metadata(struct conf_service *service,
int field_id,
const char *name,
enum conf_metadata_type type,
//md = &((service->metadata)[field_id]);
md = service->metadata + field_id;
- md = conf_metadata_assign(nmem, md, name, type, merge, setting,
+ md = conf_metadata_assign(service->nmem, md, name, type, merge, setting,
brief, termlist, rank, sortkey_offset,
mt);
return md;
}
-struct conf_sortkey * conf_service_add_sortkey(NMEM nmem,
- struct conf_service *service,
+struct conf_sortkey * conf_service_add_sortkey(struct conf_service *service,
int field_id,
const char *name,
enum conf_sortkey_type type)
//sk = &((service->sortkeys)[field_id]);
sk = service->sortkeys + field_id;
- sk = conf_sortkey_assign(nmem, sk, name, type);
+ sk = conf_sortkey_assign(service->nmem, sk, name, type);
return sk;
}
xmlFree(sortkey);
}
- service = conf_service_create(nmem, num_metadata, num_sortkeys);
+ service = conf_service_create(num_metadata, num_sortkeys);
for (n = node->children; n; n = n->next)
{
}
sortkey_offset = sk_node;
- conf_service_add_sortkey(nmem, service, sk_node,
+ conf_service_add_sortkey(
+service, sk_node,
(const char *) xml_name, sk_type);
sk_node++;
// metadata known, assign values
- conf_service_add_metadata(nmem, service, md_node,
+ conf_service_add_metadata(service, md_node,
(const char *) xml_name,
type, merge, setting,
brief, termlist, rank, sortkey_offset,
return service;
}
-static char *parse_settings(xmlNode *node)
+static char *parse_settings(NMEM nmem, xmlNode *node)
{
xmlChar *src = xmlGetProp(node, (xmlChar *) "src");
char *r;
return r;
}
-static struct conf_server *parse_server(xmlNode *node)
+static struct conf_server *parse_server(NMEM nmem, xmlNode *node)
{
xmlNode *n;
struct conf_server *server = nmem_malloc(nmem, sizeof(struct conf_server));
yaz_log(YLOG_FATAL, "Can't repeat 'settings'");
return 0;
}
- if (!(server->settings = parse_settings(n)))
+ if (!(server->settings = parse_settings(nmem, n)))
return 0;
}
else if (!strcmp((const char *) n->name, "relevance"))
return xsltParseStylesheetFile((xmlChar *) path);
}
-static struct conf_targetprofiles *parse_targetprofiles(xmlNode *node)
+static struct conf_targetprofiles *parse_targetprofiles(NMEM nmem,
+ xmlNode *node)
{
struct conf_targetprofiles *r = nmem_malloc(nmem, sizeof(*r));
xmlChar *type = xmlGetProp(node, (xmlChar *) "type");
static struct conf_config *parse_config(xmlNode *root)
{
+ NMEM nmem = nmem_create();
xmlNode *n;
struct conf_config *r = nmem_malloc(nmem, sizeof(struct conf_config));
+ r->nmem = nmem;
r->servers = 0;
r->targetprofiles = 0;
continue;
if (!strcmp((const char *) n->name, "server"))
{
- struct conf_server *tmp = parse_server(n);
+ struct conf_server *tmp = parse_server(nmem, n);
if (!tmp)
return 0;
tmp->next = r->servers;
yaz_log(YLOG_FATAL, "Can't repeat targetprofiles");
return 0;
}
- if (!(r->targetprofiles = parse_targetprofiles(n)))
+ if (!(r->targetprofiles = parse_targetprofiles(nmem, n)))
return 0;
}
else
xmlDoc *doc = xmlParseFile(fname);
const char *p;
- if (!nmem) // Initialize
- {
- nmem = nmem_create();
- xmlSubstituteEntitiesDefault(1);
- xmlLoadExtDtdDefaultValue = 1;
- }
+ xmlSubstituteEntitiesDefault(1);
+ xmlLoadExtDtdDefaultValue = 1;
if (!doc)
{
yaz_log(YLOG_FATAL, "Failed to read %s", fname);
NMEM nmem;
};
-struct conf_service * conf_service_create(NMEM nmem,
- int num_metadata, int num_sortkeys);
+struct conf_service * conf_service_create(int num_metadata, int num_sortkeys);
-struct conf_metadata* conf_service_add_metadata(NMEM nmem,
- struct conf_service *service,
+struct conf_metadata* conf_service_add_metadata(struct conf_service *service,
int field_id,
const char *name,
enum conf_metadata_type type,
int sortkey_offset,
enum conf_metadata_mergekey mt);
-struct conf_sortkey * conf_service_add_sortkey(NMEM nmem,
- struct conf_service *service,
+struct conf_sortkey * conf_service_add_sortkey(struct conf_service *service,
int field_id,
const char *name,
enum conf_sortkey_type type);
struct conf_config
{
+ NMEM nmem;
struct conf_server *servers;
struct conf_targetprofiles *targetprofiles;
};
#include <string.h>
+#include <assert.h>
#include <stdio.h>
#include <sys/types.h>
#include "direntz.h"
{
struct setting_dictionary *new;
- service->nmem = nmem_create();
+ assert(service->nmem);
new = nmem_malloc(service->nmem, sizeof(*new));
memset(new, 0, sizeof(*new));
void test_conf_service(int argc, char **argv)
{
- NMEM nmem = nmem_create();
-
struct conf_service *service = 0;
- service = conf_service_create(nmem, 4, 3);
+ service = conf_service_create(4, 3);
YAZ_CHECK(service);
// expected metadata failures
- YAZ_CHECK(!conf_service_add_metadata(0, service, 0, "dead_nmem",
- Metadata_type_generic,
- Metadata_merge_unique,
- Metadata_setting_no,
- 1, 1, 1, 0,
- Metadata_mergekey_no));
-
- YAZ_CHECK(!conf_service_add_metadata(nmem, 0, 0, "service_needed",
+ YAZ_CHECK(!conf_service_add_metadata(0, 0, "service_needed",
Metadata_type_generic,
Metadata_merge_unique,
Metadata_setting_no,
1, 1, 1, 0,
Metadata_mergekey_no));
- YAZ_CHECK(!conf_service_add_metadata(nmem, service, -1, "out_of_bounds",
+ YAZ_CHECK(!conf_service_add_metadata(service, -1, "out_of_bounds",
Metadata_type_generic,
Metadata_merge_unique,
Metadata_setting_no,
1, 1, 1, 0,
Metadata_mergekey_no));
- YAZ_CHECK(!conf_service_add_metadata(nmem, service, 4, "out_of_bounds",
+ YAZ_CHECK(!conf_service_add_metadata(service, 4, "out_of_bounds",
Metadata_type_generic,
Metadata_merge_unique,
Metadata_setting_no,
1, 1, 1, 0,
Metadata_mergekey_no));
- YAZ_CHECK(!conf_service_add_metadata(nmem, service, 0, 0, //missing name
+ YAZ_CHECK(!conf_service_add_metadata(service, 0, 0, //missing name
Metadata_type_generic,
Metadata_merge_unique,
Metadata_setting_no,
Metadata_mergekey_no));
// expected metadata sucesses
- YAZ_CHECK(conf_service_add_metadata(nmem, service, 0, "title",
+ YAZ_CHECK(conf_service_add_metadata(service, 0, "title",
Metadata_type_generic,
Metadata_merge_unique,
Metadata_setting_no,
1, 1, 1, 0,
Metadata_mergekey_no));
- YAZ_CHECK(conf_service_add_metadata(nmem, service, 1, "author",
+ YAZ_CHECK(conf_service_add_metadata(service, 1, "author",
Metadata_type_generic,
Metadata_merge_longest,
Metadata_setting_no,
1, 1, 1, 0,
Metadata_mergekey_no));
- YAZ_CHECK(conf_service_add_metadata(nmem, service, 2, "isbn",
+ YAZ_CHECK(conf_service_add_metadata(service, 2, "isbn",
Metadata_type_number,
Metadata_merge_no,
Metadata_setting_no,
1, 1, 1, 0,
Metadata_mergekey_no));
- YAZ_CHECK(conf_service_add_metadata(nmem, service, 3, "year",
+ YAZ_CHECK(conf_service_add_metadata(service, 3, "year",
Metadata_type_year,
Metadata_merge_range,
Metadata_setting_no,
// expected sortkey failures
- YAZ_CHECK(!conf_service_add_sortkey(0, service, 0, "dead_nmem",
- Metadata_sortkey_relevance));
-
- YAZ_CHECK(!conf_service_add_sortkey(nmem, 0, 0, "service_neeeded",
- Metadata_sortkey_numeric));
-
- YAZ_CHECK(!conf_service_add_sortkey(nmem, service, -1, "out_of_bounds",
+ YAZ_CHECK(!conf_service_add_sortkey(service, -1, "out_of_bounds",
Metadata_sortkey_skiparticle));
- YAZ_CHECK(!conf_service_add_sortkey(nmem, service, -1, "out_of_bounds",
+ YAZ_CHECK(!conf_service_add_sortkey(service, -1, "out_of_bounds",
Metadata_sortkey_string));
- YAZ_CHECK(!conf_service_add_sortkey(nmem, service, 3, "out_of_bounds",
+ YAZ_CHECK(!conf_service_add_sortkey(service, 3, "out_of_bounds",
Metadata_sortkey_relevance));
- YAZ_CHECK(!conf_service_add_sortkey(nmem, service, 0, 0, //missing name
+ YAZ_CHECK(!conf_service_add_sortkey(service, 0, 0, //missing name
Metadata_sortkey_relevance));
// expected sortkey sucess
- YAZ_CHECK(conf_service_add_sortkey(nmem, service, 0, "relevance",
+ YAZ_CHECK(conf_service_add_sortkey(service, 0, "relevance",
Metadata_sortkey_relevance));
- YAZ_CHECK(conf_service_add_sortkey(nmem, service, 1, "title",
+ YAZ_CHECK(conf_service_add_sortkey(service, 1, "title",
Metadata_sortkey_string));
- YAZ_CHECK(conf_service_add_sortkey(nmem, service, 2, "year",
+ YAZ_CHECK(conf_service_add_sortkey(service, 2, "year",
Metadata_sortkey_numeric));
-
-
-
-
-
-
- nmem_destroy(nmem);
-
- //YAZ_CHECK(0 == 0);
- //YAZ_CHECK_EQ(0, 1);
-
}
data_num.number.max = 5;
- service = conf_service_create(nmem, 4, 3);
+ service = conf_service_create(4, 3);
YAZ_CHECK(service);
YAZ_CHECK(conf_service_add_metadata(
- nmem, service, 0, "title",
+ service, 0, "title",
Metadata_type_generic, Metadata_merge_unique,
Metadata_setting_no, 1, 1, 1, 0,
Metadata_mergekey_no
));
YAZ_CHECK(conf_service_add_metadata(
- nmem, service, 1, "author",
+ service, 1, "author",
Metadata_type_generic, Metadata_merge_longest,
Metadata_setting_no,1, 1, 1, 0,
Metadata_mergekey_no));
YAZ_CHECK(conf_service_add_metadata(
- nmem, service, 2, "isbn",
+ service, 2, "isbn",
Metadata_type_number, Metadata_merge_no,
Metadata_setting_no, 1, 1, 1, 0,
Metadata_mergekey_no));
YAZ_CHECK(conf_service_add_metadata(
- nmem, service, 3, "year",
+ service, 3, "year",
Metadata_type_year, Metadata_merge_range,
Metadata_setting_no, 1, 1, 1, 0,
Metadata_mergekey_no));
YAZ_CHECK(conf_service_add_sortkey(
- nmem, service, 0, "relevance",
+ service, 0, "relevance",
Metadata_sortkey_relevance));
YAZ_CHECK(conf_service_add_sortkey(
- nmem, service, 1, "title",
+ service, 1, "title",
Metadata_sortkey_string));
YAZ_CHECK(conf_service_add_sortkey(
- nmem, service, 2, "year",
+ service, 2, "year",
Metadata_sortkey_numeric));