#include "settings.h"
#include "http.h"
#include "zeerex.h"
+#include "database.h"
#include <sys/types.h>
#if HAVE_SYS_SOCKET_H
return create_host(hostport);
}
-static struct database *load_database(const char *id)
+static struct database *load_database(const char *id,
+ struct conf_service *service)
{
xmlDoc *doc = 0;
struct zr_explain *explain = 0;
db->settings = 0;
- db->settings = nmem_malloc(nmem, sizeof(struct settings*) * settings_num());
- memset(db->settings, 0, sizeof(struct settings*) * settings_num());
+ db->settings = nmem_malloc(nmem, sizeof(struct settings*) *
+ settings_num(service));
+ memset(db->settings, 0, sizeof(struct settings*) * settings_num(service));
idset = nmem_malloc(nmem, sizeof(*idset));
idset->precedence = 0;
idset->name = "pz:id";
// Return a database structure by ID. Load and add to list if necessary
// new==1 just means we know it's not in the list
-struct database *find_database(const char *id, int new)
+struct database *find_database(const char *id, int new,
+ struct conf_service *service)
{
struct database *p;
if (!new)
if (!strcmp(p->url, id))
return p;
}
- return load_database(id);
+ return load_database(id, service);
}
// This whole session_grep database thing should be moved elsewhere
}
// This will be generalized at some point
-static int match_criterion(struct setting **settings, struct database_criterion *c)
+static int match_criterion(struct setting **settings,
+ struct conf_service *service,
+ struct database_criterion *c)
{
- int offset = settings_offset(c->name);
+ int offset = settings_offset(service, c->name);
struct database_criterion_value *v;
if (offset < 0)
return 0;
}
-int database_match_criteria(struct setting **settings, struct database_criterion *cl)
+int database_match_criteria(struct setting **settings,
+ struct conf_service *service,
+ struct database_criterion *cl)
{
for (; cl; cl = cl->next)
- if (!match_criterion(settings, cl))
+ if (!match_criterion(settings, service, cl))
break;
if (cl) // one of the criteria failed to match -- skip this db
return 0;
continue;
if (!p->settings[PZ_NAME])
continue;
- if (database_match_criteria(p->settings, cl))
+ if (database_match_criteria(p->settings, se->service, cl))
{
(*fun)(se, p);
i++;
return i;
}
-int predef_grep_databases(void *context, struct database_criterion *cl,
+int predef_grep_databases(void *context, struct conf_service *service,
+ struct database_criterion *cl,
void (*fun)(void *context, struct database *db))
{
struct database *p;
int i = 0;
for (p = databases; p; p = p->next)
- if (database_match_criteria(p->settings, cl))
+ if (database_match_criteria(p->settings, service, cl))
{
(*fun)(context, p);
i++;