33 #include <sys/types.h>
34 #include <yaz/dirent.h>
35 #include <yaz/xml_get.h>
39 #include <libxml/parser.h>
40 #include <libxml/tree.h>
71 "pz:negotiation_charset",
73 "pz:reuse_connections",
74 "pz:termlist_term_factor",
75 "pz:termlist_term_count",
86 "pz:authentication_mode",
102 #define SETTING_WILDCARD_NO 0
103 #define SETTING_WILDCARD_DB 1
104 #define SETTING_WILDCARD_YES 2
121 if (!strncmp(
"pz:",
name, 3) && (p = strchr(
name + 3,
':')))
122 maxlen = (p -
name) + 1;
124 maxlen = strlen(
name) + 1;
125 for (i = 0; i < dictionary->
num; i++)
126 if (!strncmp(
name, dictionary->
dict[i], maxlen))
130 if (!strncmp(
"pz:",
name, 3))
131 yaz_log(YLOG_WARN,
"Adding pz-type setting name %s",
name);
132 if (dictionary->
num + 1 > dictionary->
size)
135 nmem_malloc(nmem, dictionary->
size * 2 *
sizeof(
char*));
136 memcpy(tmp, dictionary->
dict, dictionary->
size *
sizeof(
char*));
137 dictionary->
dict = tmp;
138 dictionary->
size *= 2;
140 dictionary->
dict[dictionary->
num] = nmem_strdup(nmem,
name);
141 dictionary->
dict[dictionary->
num][maxlen-1] =
'\0';
142 return dictionary->
num++;
157 assert(offset < service->dictionary->num);
165 if (stat(path, &st) < 0)
167 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"stat %s", path);
170 return st.st_mode & S_IFDIR;
176 void (*
fun)(
void *client_data,
180 const char *namea = yaz_xml_get_prop(n,
"name");
181 const char *targeta = yaz_xml_get_prop(n,
"target");
182 const char *valuea = yaz_xml_get_prop(n,
"value");
183 const char *precedencea = yaz_xml_get_prop(n,
"precedence");
185 for (n = n->children; n; n = n->next)
187 if (n->type != XML_ELEMENT_NODE)
189 if (!strcmp((
const char *) n->name,
"set"))
191 xmlNode *root = n->children;
193 const char *
name = yaz_xml_get_prop(n,
"name");
194 const char *
target = yaz_xml_get_prop(n,
"target");
195 const char *
value = yaz_xml_get_prop(n,
"value");
196 const char *
precedence = yaz_xml_get_prop(n,
"precedence");
197 xmlChar *buf_out = 0;
203 else if (precedencea)
211 while (root && root->type != XML_ELEMENT_NODE)
217 xmlDoc *doc = xmlNewDoc(BAD_CAST
"1.0");
221 yaz_log(YLOG_WARN,
"bad XML content for setting "
222 "name=%s", set.
name);
224 yaz_log(YLOG_WARN,
"bad XML content for setting");
230 xmlDocSetRootElement(doc, xmlCopyNode(root, 1));
231 xmlDocDumpMemory(doc, &buf_out, &len_out);
233 set.
value = (
const char *) buf_out;
239 (*fun)(client_data, &set);
243 yaz_log(YLOG_WARN,
"missing value and/or target for "
244 "setting name=%s", set.
name);
246 yaz_log(YLOG_WARN,
"missing name/value/target for setting");
253 yaz_log(YLOG_WARN,
"Unknown element %s in settings file",
263 void (*
fun)(
void *client_data,
266 xmlDoc *doc = xmlParseFile(path);
272 yaz_log(YLOG_FATAL,
"Failed to parse %s", path);
275 n = xmlDocGetRootElement(doc);
287 void (*
fun)(
void *client_data,
297 if (!(d = opendir(path)))
299 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"%s", path);
302 while ((de = readdir(d)))
305 if (*de->d_name ==
'.' || !strcmp(de->d_name,
"CVS"))
307 sprintf(tmp,
"%s/%s", path, de->d_name);
313 else if ((dot = strrchr(path,
'.')) && !strcmp(dot + 1,
"xml"))
325 else if (*(zurl + strlen(zurl) - 1) ==
'*')
343 int i, n_num = offset + 10;
344 struct setting **n_ar = nmem_malloc(nmem, n_num *
sizeof(*n_ar));
345 for (i = 0; i < *num; i++)
346 n_ar[i] = (*set_ar)[i];
347 for (; i < n_num; i++)
360 int i, n_num = offset + 10;
361 struct setting **n_ar = nmem_malloc(nmem, n_num *
sizeof(*n_ar));
364 for (; i < n_num; i++)
374 yaz_log(YLOG_DEBUG,
"update service settings offset %d with %s=%s", offset, set->
name, set->
value);
379 assert(offset < settings->num_settings);
380 for (sp = &settings->
settings[offset]; *sp; )
381 if (!strcmp((*sp)->name, set->
name))
408 struct setting *
new = nmem_malloc(nmem,
sizeof(*
new));
409 memset(
new, 0,
sizeof(*
new));
411 new->target = nmem_strdup_null(nmem, set->
target);
412 new->name = nmem_strdup_null(nmem, set->
name);
413 new->value = nmem_strdup_null(nmem, set->
value);
414 new->next = settings->
settings[offset];
440 assert(offset < db->num_settings);
441 for (sp = &db->
settings[offset]; *sp; )
442 if (!strcmp((*sp)->name, set->
name))
469 struct setting *
new = nmem_malloc(service->
nmem,
sizeof(*
new));
471 memset(
new, 0,
sizeof(*
new));
473 new->target = nmem_strdup(service->
nmem, set->
target);
474 new->name = nmem_strdup(service->
nmem, set->
name);
475 new->value = nmem_strdup(service->
nmem, set->
value);
518 WRBUF wrbuf = wrbuf_alloc();
519 yaz_log(YLOG_DEBUG,
"Metadata %s has limitmap: %s ",md->
name, md->
limitmap);
520 wrbuf_printf(wrbuf,
"pz:limitmap:%s", md->
name);
525 yaz_log(YLOG_DEBUG,
"Service %s default %s=%s",
526 (service->
id ? service->
id:
"unknown"), wrbuf_cstr(wrbuf), md->
limitmap);
527 new.name = (
char *) wrbuf_cstr(wrbuf);
535 wrbuf_destroy(wrbuf);
554 assert(service->
nmem);
556 new = nmem_malloc(service->
nmem,
sizeof(*
new));
557 memset(
new, 0,
sizeof(*
new));
struct database * create_database_for_service(const char *id, struct conf_service *service)
int predef_grep_databases(void *context, struct conf_service *service, void(*fun)(void *context, struct database *db))
int match_zurl(const char *zurl, const char *pattern)
void(* fun)(struct http_channel *c)
int settings_read_node_x(xmlNode *n, void *client_data, void(*fun)(void *client_data, struct setting *set))
#define SETTING_WILDCARD_YES
char * settings_name(struct conf_service *service, int offset)
void expand_settings_array2(struct settings_array *settings, int offset, NMEM nmem)
int settings_read_node(struct conf_service *service, xmlNode *n, int pass)
static int read_settings_file(const char *path, void *client_data, void(*fun)(void *client_data, struct setting *set))
static void initialize_hard_settings(struct conf_service *service)
static void update_databases(void *client_data, struct setting *set)
static int read_settings(const char *path, void *client_data, void(*fun)(void *client_data, struct setting *set))
static void prepare_target_dictionary(void *client_data, struct setting *set)
static int isdir(const char *path)
#define SETTING_WILDCARD_NO
#define SETTING_WILDCARD_DB
static int zurl_wildcard(const char *zurl)
static int settings_index_lookup(struct setting_dictionary *dictionary, const char *name, NMEM nmem)
void init_settings(struct conf_service *service)
static void update_settings(struct setting *set, struct settings_array *settings, int offset, NMEM nmem)
int settings_read_file(struct conf_service *service, const char *path, int pass)
void expand_settings_array(struct setting ***set_ar, int *num, int offset, NMEM nmem)
void initialize_soft_settings(struct conf_service *service)
int settings_num(struct conf_service *service)
int settings_create_offset(struct conf_service *service, const char *name)
static void update_database_fun(void *context, struct database *db)
static char * hard_settings[]
int settings_lookup_offset(struct conf_service *service, const char *name)
struct setting_dictionary * dictionary
struct conf_metadata * metadata
struct settings_array * settings
struct setting ** settings
struct setting ** settings
struct conf_service * service