4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
35 #include <avahi-common/malloc.h>
40 static GDBM_FILE gdbm_file = NULL;
43 static DBM *dbm_file = NULL;
45 static char *buffer = NULL;
46 static char *enum_key = NULL;
48 static int init(void) {
54 if (!(gdbm_file = gdbm_open((char*) DATABASE_FILE, 0, GDBM_READER, 0, NULL)))
61 if (!(dbm_file = dbm_open((char*) DATABASE_FILE, O_RDONLY, 0)))
68 const char* stdb_lookup(const char *name) {
78 if ((loc = setlocale(LC_MESSAGES, NULL))) {
81 snprintf(k, sizeof(k), "%s[%s]", name, loc);
83 key.dsize = strlen(k);
85 data = gdbm_fetch(gdbm_file, key);
88 data = dbm_fetch(dbm_file, key);
93 snprintf(l, sizeof(l), "%s", loc);
95 if ((e = strchr(l, '@'))) {
97 snprintf(k, sizeof(k), "%s[%s]", name, l);
99 key.dsize = strlen(k);
101 data = gdbm_fetch(gdbm_file, key);
104 data = dbm_fetch(dbm_file, key);
109 if ((e = strchr(l, '_'))) {
111 snprintf(k, sizeof(k), "%s[%s]", name, l);
113 key.dsize = strlen(k);
115 data = gdbm_fetch(gdbm_file, key);
118 data = dbm_fetch(dbm_file, key);
126 key.dptr = (char*) name;
127 key.dsize = strlen(name);
129 data = gdbm_fetch(gdbm_file, key);
132 data = dbm_fetch(dbm_file, key);
140 buffer = avahi_strndup(data.dptr, data.dsize);
150 void stdb_shutdown(void) {
153 gdbm_close(gdbm_file);
165 avahi_free(enum_key);
167 buffer = enum_key = NULL;
170 char *stdb_getent(void) {
180 key = gdbm_firstkey(gdbm_file);
183 key = dbm_firstkey(dbm_file);
187 key.dsize = strlen(enum_key);
190 key = gdbm_nextkey(gdbm_file, key);
193 key = dbm_nextkey(dbm_file);
197 avahi_free(enum_key);
203 enum_key = avahi_strndup(key.dptr, key.dsize);
206 if (!strchr(enum_key, '['))
211 void stdb_setent(void) {
212 avahi_free(enum_key);