1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2012 Index Data
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <sys/types.h>
34 #include <sys/types.h>
36 struct database_hosts {
41 // Create a new host structure for hostport
42 static struct host *create_host(const char *url, const char *proxy,
44 iochan_man_t iochan_man)
49 host = xmalloc(sizeof(struct host));
50 host->url = xstrdup(url);
54 host->proxy = xstrdup(proxy);
59 host->tproxy = xmalloc (strlen(url) + 10); /* so we can add :port */
60 strcpy(host->tproxy, url);
61 for (cp = host->tproxy; *cp; cp++)
62 if (strchr("/?#~", *cp))
67 if (!strchr(host->tproxy, ':'))
68 sprintf(cp, ":%d", default_port); /* no port given, add it */
71 db_comment = strchr(host->url, '#');
74 host->connections = 0;
78 if (host_getaddrinfo(host, iochan_man))
87 pazpar2_mutex_create(&host->mutex, "host");
89 yaz_cond_create(&host->cond_ready);
94 struct host *find_host(database_hosts_t hosts, const char *url,
95 const char *proxy, int port,
96 iochan_man_t iochan_man)
99 yaz_mutex_enter(hosts->mutex);
100 for (p = hosts->hosts; p; p = p->next)
101 if (!strcmp(p->url, url))
105 p = create_host(url, proxy, port, iochan_man);
108 p->next = hosts->hosts;
112 yaz_mutex_leave(hosts->mutex);
116 database_hosts_t database_hosts_create(void)
118 database_hosts_t p = xmalloc(sizeof(*p));
121 pazpar2_mutex_create(&p->mutex, "database");
125 void database_hosts_destroy(database_hosts_t *pp)
129 struct host *p = (*pp)->hosts;
132 struct host *p_next = p->next;
133 yaz_mutex_destroy(&p->mutex);
134 yaz_cond_destroy(&p->cond_ready);
140 yaz_mutex_destroy(&(*pp)->mutex);
148 * c-file-style: "Stroustrup"
149 * indent-tabs-mode: nil
151 * vim: shiftwidth=4 tabstop=8 expandtab