1 /* recdb.h - recursive/record database implementation
2 * Copyright 2000-2004 srvx Development Team
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version. Important limitations are
8 * listed in the COPYING file that accompanies this software.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, email srvx-maintainers@srvx.net.
37 struct string_list *slist;
42 #define SET_RECORD_QSTRING(rec, qs) do { const char *s = (qs); (rec)->type = RECDB_QSTRING; (rec)->d.qstring = (s) ? strdup(s) : NULL; } while (0)
43 #define GET_RECORD_QSTRING(rec) (((rec)->type == RECDB_QSTRING) ? (rec)->d.qstring : 0)
44 #define SET_RECORD_OBJECT(rec, obj) do { (rec)->type = RECDB_OBJECT; (rec)->d.object = (obj); } while (0)
45 #define GET_RECORD_OBJECT(rec) (((rec)->type == RECDB_OBJECT) ? (rec)->d.object : 0)
46 #define SET_RECORD_STRING_LIST(rec, sl) do { (rec)->type = RECDB_STRING_LIST; (rec)->d.slist = (sl); } while (0)
47 #define GET_RECORD_STRING_LIST(rec) (((rec)->type == RECDB_STRING_LIST) ? (rec)->d.slist : 0)
50 unsigned int used, size;
53 void string_list_append(struct string_list *slist, char *string);
54 struct string_list *string_list_copy(struct string_list *orig);
55 void string_list_sort(struct string_list *slist);
56 #define string_list_delete(slist, n) (free((slist)->list[n]), (slist)->list[n] = (slist)->list[--(slist)->used])
58 /* allocation functions */
59 struct string_list *alloc_string_list(int size);
60 struct record_data *alloc_record_data_qstring(const char *string);
61 struct record_data *alloc_record_data_object(dict_t obj);
62 struct record_data *alloc_record_data_string_list(struct string_list *slist);
63 dict_t alloc_database(void);
64 #define alloc_object() alloc_database()
67 /* note: once you give a string list a string, it frees it automatically */
68 struct record_data *database_get_path(dict_t db, const char *path);
69 void *database_get_data(dict_t db, const char *path, enum recdb_type type);
72 void free_string_list(struct string_list *slist);
73 void free_record_data(void *rdata);
74 #define free_object(obj) dict_delete(obj)
75 #define free_database(db) dict_delete(db)
77 /* parsing stuff from disk */
78 const char *parse_record(const char *text, char **pname, struct record_data **prd);
79 dict_t parse_database(const char *filename);