blob: 9c926bd02c023c7eb2e7d080027c9298a0960375 [file] [log] [blame]
Linus Nielsen Feltzing897fb632004-07-21 13:46:42 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Linus Nielsen Feltzing
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
Linus Nielsen Feltzing897fb632004-07-21 13:46:42 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef CONFIGFILE_H
22#define CONFIGFILE_H
23
24#define TYPE_INT 1
25#define TYPE_ENUM 2
26#define TYPE_STRING 3
27
28struct configdata
29{
30 int type; /* See TYPE_ macros above */
31 int min; /* Min value for integers, should be 0 for enums */
32 int max; /* Max value for enums and integers,
33 buffer size for strings */
34 int *val; /* Pointer to integer/enum value,
35 NULL if the item is a string */
36 char *name; /* Pointer to the name of the item */
37 char **values; /* List of strings for enums, NULL if not enum */
38 char *string; /* Pointer to a string buffer if the item is a string,
39 NULL otherwise */
40};
41
Steve Bavin65265772008-05-13 09:57:56 +000042void configfile_init(const struct plugin_api* newrb);
Robert Kuklafd3fe452007-10-09 20:42:20 +000043
44/* configfile_save - Given configdata entries this function will
45 create a config file with these entries, destroying any
46 previous config file of the same name */
Linus Nielsen Feltzinge93aa4b2004-07-22 07:51:02 +000047int configfile_save(const char *filename, struct configdata *cfg,
48 int num_items, int version);
Robert Kuklafd3fe452007-10-09 20:42:20 +000049
Linus Nielsen Feltzinge93aa4b2004-07-22 07:51:02 +000050int configfile_load(const char *filename, struct configdata *cfg,
51 int num_items, int min_version);
Linus Nielsen Feltzing897fb632004-07-21 13:46:42 +000052
Robert Kuklafd3fe452007-10-09 20:42:20 +000053/* configfile_get_value - Given a key name, this function will
54 return the integer value for that key.
55
56 Input:
57 filename = config file filename
58 name = (name/value) pair name entry
59 Return:
60 value if (name/value) pair is found
61 -1 if entry is not found
62*/
63int configfile_get_value(const char* filename, const char* name);
64
65/* configure_update_entry - Given a key name and integer value
66 this function will update the entry if found, or add it if
67 not found.
68
69 Input:
70 filename = config file filename
71 name = (name/value) pair name entry
72 val = new value for (name/value) pair
73 Return:
74 1 if the (name/value) pair was found and updated with the new value
75 0 if the (name/value) pair was added as a new entry
76 -1 if error
77*/
78int configfile_update_entry(const char* filename, const char* name, int val);
79
Linus Nielsen Feltzing897fb632004-07-21 13:46:42 +000080#endif