1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2013 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>
29 #include <yaz/matchstr.h>
36 #include <sys/types.h>
38 struct database_hosts {
43 // Create a new host structure for hostport
44 static struct host *create_host(const char *proxy,
47 iochan_man_t iochan_man)
51 host = xmalloc(sizeof(struct host));
55 host->proxy = xstrdup(proxy);
59 host->tproxy = xstrdup(tproxy);
61 host->connections = 0;
65 if (cs_type == unix_type)
66 host->ipport = xstrdup(host->tproxy);
69 if (host_getaddrinfo(host, iochan_man))
78 pazpar2_mutex_create(&host->mutex, "host");
80 yaz_cond_create(&host->cond_ready);
85 struct host *find_host(database_hosts_t hosts, const char *url,
86 const char *proxy, iochan_man_t iochan_man)
93 char *connect_host = 0;
94 if (!cs_parse_host(url, &host, &t, &proto, &connect_host))
99 tproxy = xstrdup(url);
104 /* plain proxy host already given, but we get CS_TYPE t */
111 tproxy = connect_host;
116 tproxy = xstrdup(host);
117 for (cp = tproxy; *cp; cp++)
118 if (strchr("/?#~", *cp))
127 yaz_mutex_enter(hosts->mutex);
128 for (p = hosts->hosts; p; p = p->next)
130 if (!yaz_strcmp_null(p->tproxy, tproxy) &&
131 !yaz_strcmp_null(p->proxy, proxy))
138 p = create_host(proxy, tproxy, t, iochan_man);
141 p->next = hosts->hosts;
145 yaz_mutex_leave(hosts->mutex);
150 database_hosts_t database_hosts_create(void)
152 database_hosts_t p = xmalloc(sizeof(*p));
155 pazpar2_mutex_create(&p->mutex, "database");
159 void database_hosts_destroy(database_hosts_t *pp)
163 struct host *p = (*pp)->hosts;
166 struct host *p_next = p->next;
167 yaz_mutex_destroy(&p->mutex);
168 yaz_cond_destroy(&p->cond_ready);
173 yaz_mutex_destroy(&(*pp)->mutex);
181 * c-file-style: "Stroustrup"
182 * indent-tabs-mode: nil
184 * vim: shiftwidth=4 tabstop=8 expandtab