Linus Nielsen Feltzing | 897fb63 | 2004-07-21 13:46:42 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2002 Linus Nielsen Feltzing |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 12 | * 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 Feltzing | 897fb63 | 2004-07-21 13:46:42 +0000 | [diff] [blame] | 16 | * |
| 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 | |
| 28 | struct 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 Bavin | 6526577 | 2008-05-13 09:57:56 +0000 | [diff] [blame] | 42 | void configfile_init(const struct plugin_api* newrb); |
Robert Kukla | fd3fe45 | 2007-10-09 20:42:20 +0000 | [diff] [blame] | 43 | |
| 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 Feltzing | e93aa4b | 2004-07-22 07:51:02 +0000 | [diff] [blame] | 47 | int configfile_save(const char *filename, struct configdata *cfg, |
| 48 | int num_items, int version); |
Robert Kukla | fd3fe45 | 2007-10-09 20:42:20 +0000 | [diff] [blame] | 49 | |
Linus Nielsen Feltzing | e93aa4b | 2004-07-22 07:51:02 +0000 | [diff] [blame] | 50 | int configfile_load(const char *filename, struct configdata *cfg, |
| 51 | int num_items, int min_version); |
Linus Nielsen Feltzing | 897fb63 | 2004-07-21 13:46:42 +0000 | [diff] [blame] | 52 | |
Robert Kukla | fd3fe45 | 2007-10-09 20:42:20 +0000 | [diff] [blame] | 53 | /* 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 | */ |
| 63 | int 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 | */ |
| 78 | int configfile_update_entry(const char* filename, const char* name, int val); |
| 79 | |
Linus Nielsen Feltzing | 897fb63 | 2004-07-21 13:46:42 +0000 | [diff] [blame] | 80 | #endif |