source: set.h @ e9eee04

Last change on this file since e9eee04 was e41ba05, checked in by Dennis Kaarsemaker <dennis@…>, at 2016-03-23T06:44:13Z

Allow individual settings to be locked down

This allows a site admin who pregenerates configs to mark certain
settings as untouchable, ensuring that users cannot mess up their
settings too badly.

  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[5ebff60]1/********************************************************************\
[b7d3cc34]2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
[5c9512f]4  * Copyright 2002-2006 Wilmer van der Gaast and others                *
[b7d3cc34]5  \********************************************************************/
6
7/* Some stuff to register, handle and save user preferences             */
8
9/*
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License with
21  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
[6f10697]22  if not, write to the Free Software Foundation, Inc., 51 Franklin St.,
23  Fifth Floor, Boston, MA  02110-1301  USA
[b7d3cc34]24*/
25
[7bee5af]26#ifndef __SET_H__
27#define __SET_H__
28
[7738014]29struct set;
30
[d5ccd83]31/* This used to be specific to irc_t structures, but it's more generic now
32   (so it can also be used for account_t structs). It's pretty simple, but
33   so far pretty useful.
[5ebff60]34
[d5ccd83]35   In short, it just keeps a linked list of settings/variables and it also
36   remembers a default value for every setting. And to prevent the user
37   from setting invalid values, you can write an evaluator function for
38   every setting, which can check a new value and block it by returning
[f6f5eee]39   NULL, or replace it by returning a new value. See struct set.eval. */
[d5ccd83]40
[5ebff60]41typedef char *(*set_eval) (struct set *set, char *value);
[0383943]42
[7125cb3]43extern char *SET_INVALID;
44
[5ebff60]45typedef enum {
[bb5ce568]46        SET_NOSAVE = 0x0001,   /* Don't save this setting (i.e. stored elsewhere). */
47        SET_NULL_OK = 0x0100,  /* set->value == NULL is allowed. */
48        SET_HIDDEN = 0x0200,   /* Don't show up in setting lists. Mostly for internal storage. */
49        SET_PASSWORD = 0x0400, /* Value shows up in settings list as "********". */
50        SET_HIDDEN_DEFAULT = 0x0800, /* Hide unless changed from default. */
[e41ba05]51        SET_LOCKED = 0x1000    /* Setting is locked, don't allow changing it */
[180ab31]52} set_flags_t;
[7125cb3]53
[5ebff60]54typedef struct set {
[d5ccd83]55        void *data;     /* Here you can save a pointer to the
56                           object this settings belongs to. */
[5ebff60]57
[b7d3cc34]58        char *key;
[88eaf4b]59        char *old_key;  /* Previously known as; for smooth upgrades. */
[b7d3cc34]60        char *value;
[d5ccd83]61        char *def;      /* Default value. If the set_setstr() function
62                           notices a new value is exactly the same as
63                           the default, value gets set to NULL. So when
[723e611]64                           you read a setting, don't forget about this!
65                           In fact, you should only read values using
66                           set_getstr/int(). */
[5ebff60]67
[180ab31]68        set_flags_t flags; /* Mostly defined per user. */
[5ebff60]69
[f6f5eee]70        /* Eval: Returns SET_INVALID if the value is incorrect, exactly
71           the passed value variable, or a corrected value. In case of
72           the latter, set_setstr() will free() the returned string! */
[0383943]73        set_eval eval;
[56244c0]74        void *eval_data;
[b7d3cc34]75        struct set *next;
76} set_t;
77
[5ebff60]78#define set_value(set) ((set)->value) ? ((set)->value) : ((set)->def)
[ce199b7]79
[d5ccd83]80/* Should be pretty clear. */
[5ebff60]81set_t *set_add(set_t **head, const char *key, const char *def, set_eval eval, void *data);
[d5ccd83]82
83/* Returns the raw set_t. Might be useful sometimes. */
[5ebff60]84set_t *set_find(set_t **head, const char *key);
[d5ccd83]85
86/* Returns a pointer to the string value of this setting. Don't modify the
87   returned string, and don't free() it! */
[5ebff60]88G_MODULE_EXPORT char *set_getstr(set_t **head, const char *key);
[d5ccd83]89
[723e611]90/* Get an integer. In previous versions set_getint() was also used to read
91   boolean values, but this SHOULD be done with set_getbool() now! */
[5ebff60]92G_MODULE_EXPORT int set_getint(set_t **head, const char *key);
93G_MODULE_EXPORT int set_getbool(set_t **head, const char *key);
[d5ccd83]94
95/* set_setstr() strdup()s the given value, so after using this function
96   you can free() it, if you want. */
[5ebff60]97int set_setstr(set_t **head, const char *key, char *value);
98int set_setint(set_t **head, const char *key, int value);
99void set_del(set_t **head, const char *key);
100int set_reset(set_t **head, const char *key);
[b7d3cc34]101
[06b5893]102/* returns true if a setting shall be shown to the user */
[5ebff60]103int set_isvisible(set_t *set);
[06b5893]104
[d5ccd83]105/* Two very useful generic evaluators. */
[5ebff60]106char *set_eval_int(set_t *set, char *value);
107char *set_eval_bool(set_t *set, char *value);
[1719464]108
[56244c0]109/* Another more complicated one. */
[5ebff60]110char *set_eval_list(set_t *set, char *value);
[56244c0]111
[d5ccd83]112/* Some not very generic evaluators that really shouldn't be here... */
[5ebff60]113char *set_eval_to_char(set_t *set, char *value);
114char *set_eval_oauth(set_t *set, char *value);
[7bee5af]115
116#endif /* __SET_H__ */
Note: See TracBrowser for help on using the repository browser.