X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Fdatabase.c;h=d580c65ec943b05f85d8f5e19e8849e14c2090d7;hb=c61cbac9542ca9443e4fb0c215240bd9053a54f8;hp=92281628553f595eb73b506ec327df09e3cd7402;hpb=52793fbdcc6099f1c86e0b4c2c918767c22f7bcc;p=pazpar2-moved-to-github.git diff --git a/src/database.c b/src/database.c index 9228162..d580c65 100644 --- a/src/database.c +++ b/src/database.c @@ -1,7 +1,5 @@ -/* $Id: database.c,v 1.29 2007-06-28 09:36:10 adam Exp $ - Copyright (c) 2006-2007, Index Data. - -This file is part of Pazpar2. +/* This file is part of Pazpar2. + Copyright (C) 2006-2009 Index Data Pazpar2 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -14,31 +12,38 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Pazpar2; see the file LICENSE. If not, write to the -Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. - */ +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#if HAVE_CONFIG_H +#include +#endif #include #include -#include -#include -#include #include #include #include #include "pazpar2.h" #include "host.h" -#include "config.h" #include "settings.h" #include "http.h" #include "zeerex.h" +#include "database.h" #include +#if HAVE_SYS_SOCKET_H #include +#endif +#if HAVE_NETDB_H #include +#endif +#if HAVE_NETINET_IN_H #include +#endif static struct host *hosts = 0; // The hosts we know about static struct database *databases = 0; // The databases we know about @@ -99,7 +104,8 @@ static struct host *find_host(const char *hostport) 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; @@ -127,7 +133,7 @@ static struct database *load_database(const char *id) if ((dbname = strchr(hostport, '/'))) *(dbname++) = '\0'; else - dbname = "Default"; + dbname = ""; if (!(host = find_host(hostport))) return 0; db = nmem_malloc(nmem, sizeof(*db)); @@ -142,8 +148,9 @@ static struct database *load_database(const char *id) 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"; @@ -159,7 +166,8 @@ static struct database *load_database(const char *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) @@ -168,16 +176,18 @@ struct database *find_database(const char *id, int 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 int match_zurl(const char *zurl, const char *pattern) { + int len; + if (!strcmp(pattern, "*")) return 1; - else if (!strncmp(pattern, "*/", 2)) + else if (!strncmp(pattern, "*/", 2)) // host wildcard.. what the heck is that for? { char *db = strchr(zurl, '/'); if (!db) @@ -187,6 +197,13 @@ int match_zurl(const char *zurl, const char *pattern) else return 0; } + else if (*(pattern + (len = strlen(pattern) - 1)) == '*') // db wildcard + { + if (!strncmp(pattern, zurl, len)) + return 1; + else + return 2; + } else if (!strcmp(pattern, zurl)) return 1; else @@ -194,9 +211,11 @@ int match_zurl(const char *zurl, const char *pattern) } // 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) @@ -225,10 +244,12 @@ static int match_criterion(struct setting **settings, struct database_criterion 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; @@ -250,7 +271,7 @@ int session_grep_databases(struct session *se, struct database_criterion *cl, 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++; @@ -259,14 +280,15 @@ int session_grep_databases(struct session *se, struct database_criterion *cl, 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++; @@ -277,7 +299,9 @@ int predef_grep_databases(void *context, struct database_criterion *cl, /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab */ +