NeoMutt  2018-07-16 +2481-68dcde
Teaching an old dog new tricks
DOXYGEN
set.h File Reference

A collection of config items. More...

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
+ Include dependency graph for set.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ConfigDef
 Config item definition. More...
 
struct  ConfigSetType
 Type definition for a config item. More...
 
struct  ConfigSet
 Container for lots of config items. More...
 
struct  EventConfig
 A config-change event. More...
 

Macros

#define CSR_SUCCESS   0
 Action completed successfully. More...
 
#define CSR_ERR_CODE   1
 Problem with the code. More...
 
#define CSR_ERR_UNKNOWN   2
 Unrecognised config item. More...
 
#define CSR_ERR_INVALID   3
 Value hasn't been set. More...
 
#define CSR_SUC_INHERITED   (1 << 4)
 Value is inherited. More...
 
#define CSR_SUC_EMPTY   (1 << 5)
 Value is empty/unset. More...
 
#define CSR_SUC_WARNING   (1 << 6)
 Notify the user of a warning. More...
 
#define CSR_SUC_NO_CHANGE   (1 << 7)
 The value hasn't changed. More...
 
#define CSR_INV_TYPE   (1 << 4)
 Value is not valid for the type. More...
 
#define CSR_INV_VALIDATOR   (1 << 5)
 Value was rejected by the validator. More...
 
#define CSR_RESULT_MASK   0x0F
 
#define CSR_RESULT(x)   ((x) & CSR_RESULT_MASK)
 
#define IP   (intptr_t)
 
#define CS_REG_DISABLED   (1 << 0)
 

Typedefs

typedef int(* cs_validator) (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 typedef cs_validator - Validate the "charset" config variable More...
 
typedef int(* cst_string_set) (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 typedef cst_string_set - Set a config item by string More...
 
typedef int(* cst_string_get) (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 typedef cst_string_get - Get a config item as a string More...
 
typedef int(* cst_native_set) (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 typedef cst_native_set - Set a config item by string More...
 
typedef intptr_t(* cst_native_get) (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 typedef cst_native_get - Get a string from a config item More...
 
typedef int(* cst_reset) (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 typedef cst_reset - Reset a config item to its initial value More...
 
typedef void(* cst_destroy) (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
 typedef cst_destroy - Destroy a config item More...
 

Enumerations

enum  NotifyConfig { NT_CONFIG_SET = 1, NT_CONFIG_RESET, NT_CONFIG_INITIAL_SET }
 Config notification types. More...
 
enum  CsObserverAction { CSOA_CONTINUE = 1, CSOA_STOP }
 Config Observer responses. More...
 

Functions

struct ConfigSetcs_new (size_t size)
 Create a new Config Set. More...
 
void cs_init (struct ConfigSet *cs, size_t size)
 Initialise a Config Set. More...
 
void cs_free (struct ConfigSet **ptr)
 Free a Config Set. More...
 
struct HashElemcs_get_elem (const struct ConfigSet *cs, const char *name)
 Get the HashElem representing a config item. More...
 
const struct ConfigSetTypecs_get_type_def (const struct ConfigSet *cs, unsigned int type)
 Get the definition for a type. More...
 
bool cs_register_type (struct ConfigSet *cs, unsigned int type, const struct ConfigSetType *cst)
 Register a type of config item. More...
 
bool cs_register_variables (const struct ConfigSet *cs, struct ConfigDef vars[], int flags)
 Register a set of config items. More...
 
struct HashElemcs_inherit_variable (const struct ConfigSet *cs, struct HashElem *parent, const char *name)
 Create in inherited config item. More...
 
void cs_uninherit_variable (const struct ConfigSet *cs, const char *name)
 Remove an inherited config item. More...
 
void cs_notify_observers (const struct ConfigSet *cs, struct HashElem *he, const char *name, enum NotifyConfig ev)
 Notify all observers of an event. More...
 
int cs_he_initial_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
 Get the initial, or parent, value of a config item. More...
 
int cs_he_initial_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
 Set the initial value of a config item. More...
 
intptr_t cs_he_native_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
 Natively get the value of a HashElem config item. More...
 
int cs_he_native_set (const struct ConfigSet *cs, struct HashElem *he, intptr_t value, struct Buffer *err)
 Natively set the value of a HashElem config item. More...
 
int cs_he_reset (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
 Reset a config item to its initial value. More...
 
int cs_he_string_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
 Get a config item as a string. More...
 
int cs_he_string_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
 Set a config item by string. More...
 
int cs_str_initial_get (const struct ConfigSet *cs, const char *name, struct Buffer *result)
 Get the initial, or parent, value of a config item. More...
 
int cs_str_initial_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
 Set the initial value of a config item. More...
 
intptr_t cs_str_native_get (const struct ConfigSet *cs, const char *name, struct Buffer *err)
 Natively get the value of a string config item. More...
 
int cs_str_native_set (const struct ConfigSet *cs, const char *name, intptr_t value, struct Buffer *err)
 Natively set the value of a string config item. More...
 
int cs_str_reset (const struct ConfigSet *cs, const char *name, struct Buffer *err)
 Reset a config item to its initial value. More...
 
int cs_str_string_get (const struct ConfigSet *cs, const char *name, struct Buffer *result)
 Get a config item as a string. More...
 
int cs_str_string_set (const struct ConfigSet *cs, const char *name, const char *value, struct Buffer *err)
 Set a config item by string. More...
 

Detailed Description

A collection of config items.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file set.h.

Macro Definition Documentation

◆ CSR_SUCCESS

#define CSR_SUCCESS   0

Action completed successfully.

Definition at line 46 of file set.h.

◆ CSR_ERR_CODE

#define CSR_ERR_CODE   1

Problem with the code.

Definition at line 47 of file set.h.

◆ CSR_ERR_UNKNOWN

#define CSR_ERR_UNKNOWN   2

Unrecognised config item.

Definition at line 48 of file set.h.

◆ CSR_ERR_INVALID

#define CSR_ERR_INVALID   3

Value hasn't been set.

Definition at line 49 of file set.h.

◆ CSR_SUC_INHERITED

#define CSR_SUC_INHERITED   (1 << 4)

Value is inherited.

Definition at line 52 of file set.h.

◆ CSR_SUC_EMPTY

#define CSR_SUC_EMPTY   (1 << 5)

Value is empty/unset.

Definition at line 53 of file set.h.

◆ CSR_SUC_WARNING

#define CSR_SUC_WARNING   (1 << 6)

Notify the user of a warning.

Definition at line 54 of file set.h.

◆ CSR_SUC_NO_CHANGE

#define CSR_SUC_NO_CHANGE   (1 << 7)

The value hasn't changed.

Definition at line 55 of file set.h.

◆ CSR_INV_TYPE

#define CSR_INV_TYPE   (1 << 4)

Value is not valid for the type.

Definition at line 58 of file set.h.

◆ CSR_INV_VALIDATOR

#define CSR_INV_VALIDATOR   (1 << 5)

Value was rejected by the validator.

Definition at line 59 of file set.h.

◆ CSR_RESULT_MASK

#define CSR_RESULT_MASK   0x0F

Definition at line 61 of file set.h.

◆ CSR_RESULT

#define CSR_RESULT (   x)    ((x) & CSR_RESULT_MASK)

Definition at line 62 of file set.h.

◆ IP

#define IP   (intptr_t)

Definition at line 144 of file set.h.

◆ CS_REG_DISABLED

#define CS_REG_DISABLED   (1 << 0)

Definition at line 146 of file set.h.

Typedef Documentation

◆ cs_validator

typedef int(* cs_validator) (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)

typedef cs_validator - Validate the "charset" config variable

Parameters
csConfig items
cdefConfig definition
valueNative value
errMessage for the user
Return values
CSR_SUCCESSSuccess
CSR_ERR_INVALIDFailure

Definition at line 82 of file set.h.

◆ cst_string_set

typedef int(* cst_string_set) (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)

typedef cst_string_set - Set a config item by string

Parameters
csConfig items
varVariable to set
cdefVariable definition
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

If var is NULL, then the config item's initial value will be set.

Definition at line 94 of file set.h.

◆ cst_string_get

typedef int(* cst_string_get) (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)

typedef cst_string_get - Get a config item as a string

Parameters
csConfig items
varVariable to get
cdefVariable definition
resultBuffer for results or error messages
Return values
numResult, e.g. CSR_SUCCESS

If var is NULL, then the config item's initial value will be returned.

Definition at line 105 of file set.h.

◆ cst_native_set

typedef int(* cst_native_set) (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)

typedef cst_native_set - Set a config item by string

Parameters
csConfig items
varVariable to set
cdefVariable definition
valueNative pointer/value to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 115 of file set.h.

◆ cst_native_get

typedef intptr_t(* cst_native_get) (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)

typedef cst_native_get - Get a string from a config item

Parameters
csConfig items
varVariable to get
cdefVariable definition
errBuffer for error messages
Return values
intptr_tConfig item string
INT_MINError

Definition at line 125 of file set.h.

◆ cst_reset

typedef int(* cst_reset) (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)

typedef cst_reset - Reset a config item to its initial value

Parameters
csConfig items
varVariable to reset
cdefVariable definition
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 135 of file set.h.

◆ cst_destroy

typedef void(* cst_destroy) (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)

typedef cst_destroy - Destroy a config item

Parameters
csConfig items
varVariable to destroy
cdefVariable definition

Definition at line 142 of file set.h.

Enumeration Type Documentation

◆ NotifyConfig

Config notification types.

Enumerator
NT_CONFIG_SET 

Config item has been set.

NT_CONFIG_RESET 

Config item has been reset to initial, or parent, value.

NT_CONFIG_INITIAL_SET 

Config item's initial value has been set.

Definition at line 38 of file set.h.

39 {
40  NT_CONFIG_SET = 1,
43 };
Config item has been reset to initial, or parent, value.
Definition: set.h:41
Config item has been set.
Definition: set.h:40
Config item&#39;s initial value has been set.
Definition: set.h:42

◆ CsObserverAction

Config Observer responses.

Enumerator
CSOA_CONTINUE 

Continue notifying observers.

CSOA_STOP 

Stop notifying observers.

Definition at line 67 of file set.h.

68 {
69  CSOA_CONTINUE = 1,
70  CSOA_STOP,
71 };
Continue notifying observers.
Definition: set.h:69
Stop notifying observers.
Definition: set.h:70

Function Documentation

◆ cs_new()

struct ConfigSet* cs_new ( size_t  size)

Create a new Config Set.

Parameters
sizeNumber of expected config items
Return values
ptrNew ConfigSet object

Definition at line 171 of file set.c.

172 {
173  struct ConfigSet *cs = mutt_mem_malloc(sizeof(*cs));
174  cs_init(cs, size);
175  return cs;
176 }
Container for lots of config items.
Definition: set.h:187
void cs_init(struct ConfigSet *cs, size_t size)
Initialise a Config Set.
Definition: set.c:183
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_init()

void cs_init ( struct ConfigSet cs,
size_t  size 
)

Initialise a Config Set.

Parameters
csConfig items
sizeNumber of expected config items

Definition at line 183 of file set.c.

184 {
185  if (!cs)
186  return;
187 
188  memset(cs, 0, sizeof(*cs));
190  mutt_hash_set_destructor(cs->hash, destroy, (intptr_t) cs);
191  cs->notify = notify_new(cs, NT_CONFIG);
192 }
struct Hash * hash
HashTable storing the config items.
Definition: set.h:189
static void destroy(int type, void *obj, intptr_t data)
Callback function for the Hash Table - Implements hashelem_free_t.
Definition: set.c:65
struct Notify * notify_new(void *object, enum NotifyType type)
Create a new notifications handler.
Definition: notify.c:54
struct Hash * mutt_hash_new(size_t nelem, HashFlags flags)
Create a new Hash table (with string keys)
Definition: hash.c:276
Config has changed.
Definition: notify_type.h:33
struct Notify * notify
Notifications system.
Definition: set.h:191
void mutt_hash_set_destructor(struct Hash *table, hashelem_free_t fn, intptr_t fn_data)
Set the destructor for a Hash Table.
Definition: hash.c:318
#define MUTT_HASH_NO_FLAGS
No flags are set.
Definition: hash.h:74
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_free()

void cs_free ( struct ConfigSet **  ptr)

Free a Config Set.

Parameters
[out]ptrConfig items

Definition at line 198 of file set.c.

199 {
200  if (!ptr || !*ptr)
201  return;
202 
203  struct ConfigSet *cs = *ptr;
204 
205  mutt_hash_free(&cs->hash);
206  notify_free(&cs->notify);
207  FREE(ptr);
208 }
Container for lots of config items.
Definition: set.h:187
struct Hash * hash
HashTable storing the config items.
Definition: set.h:189
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:69
struct Notify * notify
Notifications system.
Definition: set.h:191
#define FREE(x)
Definition: memory.h:40
void mutt_hash_free(struct Hash **ptr)
free_hdata a hash table
Definition: hash.c:472
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_get_elem()

struct HashElem* cs_get_elem ( const struct ConfigSet cs,
const char *  name 
)

Get the HashElem representing a config item.

Parameters
csConfig items
nameName of config item
Return values
ptrHashElem representing the config item

Definition at line 216 of file set.c.

217 {
218  if (!cs || !name)
219  return NULL;
220 
221  struct HashElem *he = mutt_hash_find_elem(cs->hash, name);
222  if (!he)
223  return NULL;
224 
225  if (he->type != DT_SYNONYM)
226  return he;
227 
228  const struct ConfigDef *cdef = he->data;
229 
230  return cdef->var;
231 }
struct Hash * hash
HashTable storing the config items.
Definition: set.h:189
Config item definition.
Definition: set.h:153
const char * name
Definition: pgpmicalg.c:45
struct HashElem * mutt_hash_find_elem(const struct Hash *table, const char *strkey)
Find the HashElem in a Hash table element using a key.
Definition: hash.c:394
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:157
#define DT_SYNONYM
synonym for another variable
Definition: types.h:41
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_get_type_def()

const struct ConfigSetType* cs_get_type_def ( const struct ConfigSet cs,
unsigned int  type 
)

Get the definition for a type.

Parameters
csConfig items
typeType to lookup, e.g. DT_NUMBER
Return values
ptrConfigSetType representing the type

Definition at line 239 of file set.c.

240 {
241  if (!cs)
242  return NULL;
243 
244  type = DTYPE(type);
245  if ((type < 1) || (type >= mutt_array_size(cs->types)))
246  return NULL;
247 
248  if (!cs->types[type].name)
249  return NULL;
250 
251  return &cs->types[type];
252 }
struct ConfigSetType types[18]
All the defined config types.
Definition: set.h:190
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:43
#define mutt_array_size(x)
Definition: memory.h:33
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:156
const char * name
Name of the type, e.g.
Definition: set.h:170
+ Here is the caller graph for this function:

◆ cs_register_type()

bool cs_register_type ( struct ConfigSet cs,
unsigned int  type,
const struct ConfigSetType cst 
)

Register a type of config item.

Parameters
csConfig items
typeObject type, e.g. DT_BOOL
cstStructure defining the type
Return values
boolTrue, if type was registered successfully

Definition at line 261 of file set.c.

262 {
263  if (!cs || !cst)
264  return false;
265 
266  if (!cst->name || !cst->string_set || !cst->string_get || !cst->reset ||
267  !cst->native_set || !cst->native_get)
268  {
269  return false;
270  }
271 
272  if (type >= mutt_array_size(cs->types))
273  return false;
274 
275  if (cs->types[type].name)
276  return false; /* already registered */
277 
278  cs->types[type] = *cst;
279  return true;
280 }
cst_reset reset
Reset the variable to its initial, or parent, value.
Definition: set.h:175
struct ConfigSetType types[18]
All the defined config types.
Definition: set.h:190
cst_string_get string_get
Initialise a variable from a string.
Definition: set.h:172
#define mutt_array_size(x)
Definition: memory.h:33
cst_native_get native_get
Get the variable&#39;s value as a C-native type.
Definition: set.h:174
cst_string_set string_set
Convert the variable to a string.
Definition: set.h:171
cst_native_set native_set
Set the variable using a C-native type.
Definition: set.h:173
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:156
const char * name
Name of the type, e.g.
Definition: set.h:170
+ Here is the caller graph for this function:

◆ cs_register_variables()

bool cs_register_variables ( const struct ConfigSet cs,
struct ConfigDef  vars[],
int  flags 
)

Register a set of config items.

Parameters
csConfig items
varsVariable definition
flagsFlags, e.g. CS_REG_DISABLED
Return values
boolTrue, if all variables were registered successfully

Definition at line 289 of file set.c.

290 {
291  if (!cs || !vars)
292  return false;
293 
294  struct Buffer err = mutt_buffer_make(0);
295 
296  bool rc = true;
297 
298  for (size_t i = 0; vars[i].name; i++)
299  {
300  if (!reg_one_var(cs, &vars[i], &err))
301  {
302  mutt_debug(LL_DEBUG1, "%s\n", mutt_b2s(&err));
303  rc = false;
304  }
305  }
306 
307  mutt_buffer_dealloc(&err);
308  return rc;
309 }
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:61
String manipulation buffer.
Definition: buffer.h:33
static struct HashElem * reg_one_var(const struct ConfigSet *cs, struct ConfigDef *cdef, struct Buffer *err)
Register one config item.
Definition: set.c:139
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:293
const char * name
User-visible name.
Definition: set.h:155
#define mutt_b2s(buf)
Definition: buffer.h:41
Log at debug level 1.
Definition: logging.h:56
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_inherit_variable()

struct HashElem* cs_inherit_variable ( const struct ConfigSet cs,
struct HashElem parent,
const char *  name 
)

Create in inherited config item.

Parameters
csConfig items
parentHashElem of parent config item
nameName of account-specific config item
Return values
ptrNew HashElem representing the inherited config item

Definition at line 318 of file set.c.

320 {
321  if (!cs || !parent)
322  return NULL;
323 
324  struct Inheritance *i = mutt_mem_calloc(1, sizeof(*i));
325  i->parent = parent;
326  i->name = mutt_str_strdup(name);
327 
328  struct HashElem *he = mutt_hash_typed_insert(cs->hash, i->name, DT_INHERITED, i);
329  if (!he)
330  {
331  FREE(&i->name);
332  FREE(&i);
333  }
334 
335  return he;
336 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct Hash * hash
HashTable storing the config items.
Definition: set.h:189
const char * name
Name of this config item.
Definition: inheritance.h:34
An inherited config item.
Definition: inheritance.h:31
const char * name
Definition: pgpmicalg.c:45
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define FREE(x)
Definition: memory.h:40
The item stored in a Hash Table.
Definition: hash.h:42
struct HashElem * parent
HashElem of parent config item.
Definition: inheritance.h:33
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
struct HashElem * mutt_hash_typed_insert(struct Hash *table, const char *strkey, int type, void *data)
Insert a string with type info into a Hash Table.
Definition: hash.c:334
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_uninherit_variable()

void cs_uninherit_variable ( const struct ConfigSet cs,
const char *  name 
)

Remove an inherited config item.

Parameters
csConfig items
nameName of config item to remove

Definition at line 343 of file set.c.

344 {
345  if (!cs || !name)
346  return;
347 
348  mutt_hash_delete(cs->hash, name, NULL);
349 }
void mutt_hash_delete(struct Hash *table, const char *strkey, const void *data)
Remove an element from a Hash table.
Definition: hash.c:444
struct Hash * hash
HashTable storing the config items.
Definition: set.h:189
const char * name
Definition: pgpmicalg.c:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_notify_observers()

void cs_notify_observers ( const struct ConfigSet cs,
struct HashElem he,
const char *  name,
enum NotifyConfig  ev 
)

Notify all observers of an event.

Parameters
csConfig items
heHashElem representing config item
nameName of config item
evType of event

Definition at line 358 of file set.c.

360 {
361  if (!cs || !he || !name)
362  return;
363 
364  struct EventConfig ec = { cs, he, name };
365  notify_send(cs->notify, NT_CONFIG, ev, IP & ec);
366 }
A config-change event.
Definition: set.h:199
struct HashElem * he
Config item that changed.
Definition: set.h:202
const struct ConfigSet * cs
Config set.
Definition: set.h:201
const char * name
Definition: pgpmicalg.c:45
Config has changed.
Definition: notify_type.h:33
struct Notify * notify
Notifications system.
Definition: set.h:191
#define IP
Definition: set.h:144
bool notify_send(struct Notify *notify, int type, int subtype, intptr_t data)
Send out a notification message.
Definition: notify.c:145
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_initial_get()

int cs_he_initial_get ( const struct ConfigSet cs,
struct HashElem he,
struct Buffer result 
)

Get the initial, or parent, value of a config item.

Parameters
csConfig items
heHashElem representing config item
resultBuffer for results or error messages
Return values
numResult, e.g. CSR_SUCCESS

If a config item is inherited from another, then this will get the parent's value. Otherwise, it will get the config item's initial value.

Definition at line 513 of file set.c.

514 {
515  if (!cs || !he)
516  return CSR_ERR_CODE;
517 
518  const struct ConfigDef *cdef = NULL;
519  const struct ConfigSetType *cst = NULL;
520 
521  if (he->type & DT_INHERITED)
522  {
523  struct HashElem *he_base = get_base(he);
524  cdef = he_base->data;
525  cst = cs_get_type_def(cs, he_base->type);
526  }
527  else
528  {
529  cdef = he->data;
530  cst = cs_get_type_def(cs, he->type);
531  }
532 
533  if (!cst)
534  {
535  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name,
536  DTYPE(he->type));
537  return CSR_ERR_CODE;
538  }
539 
540  return cst->string_get(cs, NULL, cdef, result);
541 }
Type definition for a config item.
Definition: set.h:168
cst_string_get string_get
Initialise a variable from a string.
Definition: set.h:172
Config item definition.
Definition: set.h:153
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:43
const char * name
User-visible name.
Definition: set.h:155
void * data
Definition: hash.h:46
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:47
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:239
Log at debug level 1.
Definition: logging.h:56
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct HashElem * get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:50
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_initial_set()

int cs_he_initial_set ( const struct ConfigSet cs,
struct HashElem he,
const char *  value,
struct Buffer err 
)

Set the initial value of a config item.

Parameters
csConfig items
heHashElem representing config item
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 446 of file set.c.

448 {
449  if (!cs || !he)
450  return CSR_ERR_CODE;
451 
452  struct ConfigDef *cdef = NULL;
453  const struct ConfigSetType *cst = NULL;
454 
455  if (he->type & DT_INHERITED)
456  {
457  struct HashElem *he_base = get_base(he);
458  cdef = he_base->data;
459  mutt_debug(LL_DEBUG1, "Variable '%s' is inherited type\n", cdef->name);
460  return CSR_ERR_CODE;
461  }
462 
463  cdef = he->data;
464  cst = cs_get_type_def(cs, he->type);
465  if (!cst)
466  {
467  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
468  return CSR_ERR_CODE;
469  }
470 
471  int rc = cst->string_set(cs, NULL, cdef, value, err);
472  if (CSR_RESULT(rc) != CSR_SUCCESS)
473  return rc;
474 
476  return CSR_SUCCESS;
477 }
union HashKey key
Definition: hash.h:45
Type definition for a config item.
Definition: set.h:168
#define CSR_RESULT(x)
Definition: set.h:62
Config item definition.
Definition: set.h:153
void cs_notify_observers(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum NotifyConfig ev)
Notify all observers of an event.
Definition: set.c:358
const char * name
User-visible name.
Definition: set.h:155
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:46
cst_string_set string_set
Convert the variable to a string.
Definition: set.h:171
void * data
Definition: hash.h:46
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:47
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:239
Log at debug level 1.
Definition: logging.h:56
const char * strkey
Definition: hash.h:35
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
Config item&#39;s initial value has been set.
Definition: set.h:42
struct HashElem * get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:50
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_native_get()

intptr_t cs_he_native_get ( const struct ConfigSet cs,
struct HashElem he,
struct Buffer err 
)

Natively get the value of a HashElem config item.

Parameters
csConfig items
heHashElem representing config item
errBuffer for results or error messages
Return values
intptr_tNative pointer/value
INT_MINError

Definition at line 827 of file set.c.

828 {
829  if (!cs || !he)
830  return INT_MIN;
831 
832  const struct ConfigDef *cdef = NULL;
833  const struct ConfigSetType *cst = NULL;
834  void *var = NULL;
835 
836  if (he->type & DT_INHERITED)
837  {
838  struct Inheritance *i = he->data;
839 
840  // inherited, value not set
841  if (DTYPE(he->type) == 0)
842  return cs_he_native_get(cs, i->parent, err);
843 
844  // inherited, value set
845  struct HashElem *he_base = get_base(he);
846  cdef = he_base->data;
847  cst = cs_get_type_def(cs, he_base->type);
848  var = &i->var;
849  }
850  else
851  {
852  // not inherited
853  cdef = he->data;
854  cst = cs_get_type_def(cs, he->type);
855  var = cdef->var;
856  }
857 
858  if (!cst)
859  {
860  mutt_buffer_printf(err, "Variable '%s' has an invalid type %d", cdef->name, he->type);
861  return INT_MIN;
862  }
863 
864  return cst->native_get(cs, var, cdef, err);
865 }
Type definition for a config item.
Definition: set.h:168
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Config item definition.
Definition: set.h:153
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:43
An inherited config item.
Definition: inheritance.h:31
const char * name
User-visible name.
Definition: set.h:155
cst_native_get native_get
Get the variable&#39;s value as a C-native type.
Definition: set.h:174
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:157
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:239
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
struct HashElem * parent
HashElem of parent config item.
Definition: inheritance.h:33
intptr_t cs_he_native_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Natively get the value of a HashElem config item.
Definition: set.c:827
struct HashElem * get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:50
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_native_set()

int cs_he_native_set ( const struct ConfigSet cs,
struct HashElem he,
intptr_t  value,
struct Buffer err 
)

Natively set the value of a HashElem config item.

Parameters
csConfig items
heHashElem representing config item
valueNative pointer/value to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 721 of file set.c.

723 {
724  if (!cs || !he)
725  return CSR_ERR_CODE;
726 
727  const struct ConfigDef *cdef = NULL;
728  const struct ConfigSetType *cst = NULL;
729  void *var = NULL;
730 
731  if (he->type & DT_INHERITED)
732  {
733  struct Inheritance *i = he->data;
734  struct HashElem *he_base = get_base(he);
735  cdef = he_base->data;
736  cst = cs_get_type_def(cs, he_base->type);
737  var = &i->var;
738  }
739  else
740  {
741  cdef = he->data;
742  cst = cs_get_type_def(cs, he->type);
743  var = cdef->var;
744  }
745 
746  if (!cst)
747  {
748  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
749  return CSR_ERR_CODE;
750  }
751 
752  int rc = cst->native_set(cs, var, cdef, value, err);
753  if (CSR_RESULT(rc) != CSR_SUCCESS)
754  return rc;
755 
756  if (he->type & DT_INHERITED)
757  he->type = cdef->type | DT_INHERITED;
758 
759  if (!(rc & CSR_SUC_NO_CHANGE))
760  cs_notify_observers(cs, he, cdef->name, NT_CONFIG_SET);
761  return rc;
762 }
Type definition for a config item.
Definition: set.h:168
#define CSR_RESULT(x)
Definition: set.h:62
Config item definition.
Definition: set.h:153
An inherited config item.
Definition: inheritance.h:31
void cs_notify_observers(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum NotifyConfig ev)
Notify all observers of an event.
Definition: set.c:358
const char * name
User-visible name.
Definition: set.h:155
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:46
cst_native_set native_set
Set the variable using a C-native type.
Definition: set.h:173
Config item has been set.
Definition: set.h:40
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:157
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:47
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:156
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:239
Log at debug level 1.
Definition: logging.h:56
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define CSR_SUC_NO_CHANGE
The value hasn&#39;t changed.
Definition: set.h:55
struct HashElem * get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:50
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_reset()

int cs_he_reset ( const struct ConfigSet cs,
struct HashElem he,
struct Buffer err 
)

Reset a config item to its initial value.

Parameters
csConfig items
heHashElem representing config item
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 375 of file set.c.

376 {
377  if (!cs || !he)
378  return CSR_ERR_CODE;
379 
380  /* An inherited var that's already pointing to its parent.
381  * Return 'success', but don't send a notification. */
382  if ((he->type & DT_INHERITED) && (DTYPE(he->type) == 0))
383  return CSR_SUCCESS;
384 
385  const struct ConfigDef *cdef = NULL;
386  const struct ConfigSetType *cst = NULL;
387 
388  int rc = CSR_SUCCESS;
389 
390  if (he->type & DT_INHERITED)
391  {
392  struct Inheritance *i = he->data;
393  struct HashElem *he_base = get_base(he);
394  cdef = he_base->data;
395  cst = cs_get_type_def(cs, he_base->type);
396 
397  if (cst && cst->destroy)
398  cst->destroy(cs, (void **) &i->var, cdef);
399 
400  he->type = DT_INHERITED;
401  }
402  else
403  {
404  cdef = he->data;
405  cst = cs_get_type_def(cs, he->type);
406 
407  if (cst)
408  rc = cst->reset(cs, cdef->var, cdef, err);
409  }
410 
411  if ((CSR_RESULT(rc) == CSR_SUCCESS) && !(rc & CSR_SUC_NO_CHANGE))
413  return rc;
414 }
union HashKey key
Definition: hash.h:45
Type definition for a config item.
Definition: set.h:168
cst_reset reset
Reset the variable to its initial, or parent, value.
Definition: set.h:175
#define CSR_RESULT(x)
Definition: set.h:62
Config item definition.
Definition: set.h:153
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:43
An inherited config item.
Definition: inheritance.h:31
void cs_notify_observers(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum NotifyConfig ev)
Notify all observers of an event.
Definition: set.c:358
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:46
Config item has been reset to initial, or parent, value.
Definition: set.h:41
cst_destroy destroy
Free the resources for a variable.
Definition: set.h:176
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:157
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:47
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:239
const char * strkey
Definition: hash.h:35
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
#define CSR_SUC_NO_CHANGE
The value hasn&#39;t changed.
Definition: set.h:55
struct HashElem * get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:50
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_string_get()

int cs_he_string_get ( const struct ConfigSet cs,
struct HashElem he,
struct Buffer result 
)

Get a config item as a string.

Parameters
csConfig items
heHashElem representing config item
resultBuffer for results or error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 650 of file set.c.

651 {
652  if (!cs || !he)
653  return CSR_ERR_CODE;
654 
655  const struct ConfigDef *cdef = NULL;
656  const struct ConfigSetType *cst = NULL;
657  void *var = NULL;
658 
659  if (he->type & DT_INHERITED)
660  {
661  struct Inheritance *i = he->data;
662 
663  // inherited, value not set
664  if (DTYPE(he->type) == 0)
665  return cs_he_string_get(cs, i->parent, result);
666 
667  // inherited, value set
668  struct HashElem *he_base = get_base(he);
669  cdef = he_base->data;
670  cst = cs_get_type_def(cs, he_base->type);
671  var = &i->var;
672  }
673  else
674  {
675  // not inherited
676  cdef = he->data;
677  cst = cs_get_type_def(cs, he->type);
678  var = cdef->var;
679  }
680 
681  if (!cst)
682  {
683  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name,
684  DTYPE(he->type));
685  return CSR_ERR_CODE;
686  }
687 
688  return cst->string_get(cs, var, cdef, result);
689 }
Type definition for a config item.
Definition: set.h:168
cst_string_get string_get
Initialise a variable from a string.
Definition: set.h:172
Config item definition.
Definition: set.h:153
#define DTYPE(x)
Mask for the Data Type.
Definition: types.h:43
An inherited config item.
Definition: inheritance.h:31
const char * name
User-visible name.
Definition: set.h:155
int cs_he_string_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
Definition: set.c:650
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:157
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:47
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:239
Log at debug level 1.
Definition: logging.h:56
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct HashElem * parent
HashElem of parent config item.
Definition: inheritance.h:33
struct HashElem * get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:50
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_he_string_set()

int cs_he_string_set ( const struct ConfigSet cs,
struct HashElem he,
const char *  value,
struct Buffer err 
)

Set a config item by string.

Parameters
csConfig items
heHashElem representing config item
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 576 of file set.c.

578 {
579  if (!cs || !he)
580  return CSR_ERR_CODE;
581 
582  struct ConfigDef *cdef = NULL;
583  const struct ConfigSetType *cst = NULL;
584  void *var = NULL;
585 
586  if (he->type & DT_INHERITED)
587  {
588  struct Inheritance *i = he->data;
589  struct HashElem *he_base = get_base(he);
590  cdef = he_base->data;
591  cst = cs_get_type_def(cs, he_base->type);
592  var = &i->var;
593  }
594  else
595  {
596  cdef = he->data;
597  cst = cs_get_type_def(cs, he->type);
598  var = cdef->var;
599  }
600 
601  if (!cst)
602  {
603  mutt_debug(LL_DEBUG1, "Variable '%s' has an invalid type %d\n", cdef->name, he->type);
604  return CSR_ERR_CODE;
605  }
606 
607  int rc = cst->string_set(cs, var, cdef, value, err);
608  if (CSR_RESULT(rc) != CSR_SUCCESS)
609  return rc;
610 
611  if (he->type & DT_INHERITED)
612  he->type = cdef->type | DT_INHERITED;
613 
614  if (!(rc & CSR_SUC_NO_CHANGE))
616  return rc;
617 }
union HashKey key
Definition: hash.h:45
Type definition for a config item.
Definition: set.h:168
#define CSR_RESULT(x)
Definition: set.h:62
Config item definition.
Definition: set.h:153
An inherited config item.
Definition: inheritance.h:31
void cs_notify_observers(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum NotifyConfig ev)
Notify all observers of an event.
Definition: set.c:358
const char * name
User-visible name.
Definition: set.h:155
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:46
cst_string_set string_set
Convert the variable to a string.
Definition: set.h:171
Config item has been set.
Definition: set.h:40
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:157
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:47
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:156
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:239
Log at debug level 1.
Definition: logging.h:56
const char * strkey
Definition: hash.h:35
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
#define CSR_SUC_NO_CHANGE
The value hasn&#39;t changed.
Definition: set.h:55
struct HashElem * get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:50
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_initial_get()

int cs_str_initial_get ( const struct ConfigSet cs,
const char *  name,
struct Buffer result 
)

Get the initial, or parent, value of a config item.

Parameters
csConfig items
nameName of config item
resultBuffer for results or error messages
Return values
numResult, e.g. CSR_SUCCESS

If a config item is inherited from another, then this will get the parent's value. Otherwise, it will get the config item's initial value.

Definition at line 553 of file set.c.

554 {
555  if (!cs || !name)
556  return CSR_ERR_CODE;
557 
558  struct HashElem *he = cs_get_elem(cs, name);
559  if (!he)
560  {
561  mutt_buffer_printf(result, "Unknown var '%s'", name);
562  return CSR_ERR_UNKNOWN;
563  }
564 
565  return cs_he_initial_get(cs, he, result);
566 }
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
Definition: pgpmicalg.c:45
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:216
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:48
int cs_he_initial_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get the initial, or parent, value of a config item.
Definition: set.c:513
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:47
The item stored in a Hash Table.
Definition: hash.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_initial_set()

int cs_str_initial_set ( const struct ConfigSet cs,
const char *  name,
const char *  value,
struct Buffer err 
)

Set the initial value of a config item.

Parameters
csConfig items
nameName of config item
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 487 of file set.c.

489 {
490  if (!cs || !name)
491  return CSR_ERR_CODE;
492 
493  struct HashElem *he = cs_get_elem(cs, name);
494  if (!he)
495  {
496  mutt_buffer_printf(err, "Unknown var '%s'", name);
497  return CSR_ERR_UNKNOWN;
498  }
499 
500  return cs_he_initial_set(cs, he, value, err);
501 }
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
Definition: pgpmicalg.c:45
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:216
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:48
int cs_he_initial_set(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
Set the initial value of a config item.
Definition: set.c:446
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:47
The item stored in a Hash Table.
Definition: hash.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_native_get()

intptr_t cs_str_native_get ( const struct ConfigSet cs,
const char *  name,
struct Buffer err 
)

Natively get the value of a string config item.

Parameters
csConfig items
nameName of config item
errBuffer for error messages
Return values
intptr_tNative pointer/value
INT_MINError

Definition at line 875 of file set.c.

876 {
877  if (!cs || !name)
878  return INT_MIN;
879 
880  struct HashElem *he = cs_get_elem(cs, name);
881  return cs_he_native_get(cs, he, err);
882 }
const char * name
Definition: pgpmicalg.c:45
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:216
The item stored in a Hash Table.
Definition: hash.h:42
intptr_t cs_he_native_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Natively get the value of a HashElem config item.
Definition: set.c:827
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_native_set()

int cs_str_native_set ( const struct ConfigSet cs,
const char *  name,
intptr_t  value,
struct Buffer err 
)

Natively set the value of a string config item.

Parameters
csConfig items
nameName of config item
valueNative pointer/value to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 772 of file set.c.

774 {
775  if (!cs || !name)
776  return CSR_ERR_CODE;
777 
778  struct HashElem *he = cs_get_elem(cs, name);
779  if (!he)
780  {
781  mutt_buffer_printf(err, "Unknown var '%s'", name);
782  return CSR_ERR_UNKNOWN;
783  }
784 
785  const struct ConfigDef *cdef = NULL;
786  const struct ConfigSetType *cst = NULL;
787  void *var = NULL;
788 
789  if (he->type & DT_INHERITED)
790  {
791  struct Inheritance *i = he->data;
792  struct HashElem *he_base = get_base(he);
793  cdef = he_base->data;
794  cst = cs_get_type_def(cs, he_base->type);
795  var = &i->var;
796  }
797  else
798  {
799  cdef = he->data;
800  cst = cs_get_type_def(cs, he->type);
801  var = cdef->var;
802  }
803 
804  if (!cst)
805  return CSR_ERR_CODE; /* LCOV_EXCL_LINE */
806 
807  int rc = cst->native_set(cs, var, cdef, value, err);
808  if (CSR_RESULT(rc) != CSR_SUCCESS)
809  return rc;
810 
811  if (he->type & DT_INHERITED)
812  he->type = cdef->type | DT_INHERITED;
813 
814  if (!(rc & CSR_SUC_NO_CHANGE))
815  cs_notify_observers(cs, he, cdef->name, NT_CONFIG_SET);
816  return rc;
817 }
Type definition for a config item.
Definition: set.h:168
#define CSR_RESULT(x)
Definition: set.h:62
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Config item definition.
Definition: set.h:153
An inherited config item.
Definition: inheritance.h:31
const char * name
Definition: pgpmicalg.c:45
void cs_notify_observers(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum NotifyConfig ev)
Notify all observers of an event.
Definition: set.c:358
const char * name
User-visible name.
Definition: set.h:155
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:216
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:46
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:48
cst_native_set native_set
Set the variable using a C-native type.
Definition: set.h:173
Config item has been set.
Definition: set.h:40
void * data
Definition: hash.h:46
void * var
Pointer to the global variable.
Definition: set.h:157
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:47
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:156
const struct ConfigSetType * cs_get_type_def(const struct ConfigSet *cs, unsigned int type)
Get the definition for a type.
Definition: set.c:239
int type
Definition: hash.h:44
The item stored in a Hash Table.
Definition: hash.h:42
#define CSR_SUC_NO_CHANGE
The value hasn&#39;t changed.
Definition: set.h:55
struct HashElem * get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:50
#define DT_INHERITED
Config item is inherited.
Definition: types.h:78
intptr_t var
(Pointer to) value, of config item
Definition: inheritance.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_reset()

int cs_str_reset ( const struct ConfigSet cs,
const char *  name,
struct Buffer err 
)

Reset a config item to its initial value.

Parameters
csConfig items
nameName of config item
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 423 of file set.c.

424 {
425  if (!cs || !name)
426  return CSR_ERR_CODE;
427 
428  struct HashElem *he = cs_get_elem(cs, name);
429  if (!he)
430  {
431  mutt_buffer_printf(err, "Unknown var '%s'", name);
432  return CSR_ERR_UNKNOWN;
433  }
434 
435  return cs_he_reset(cs, he, err);
436 }
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
Definition: pgpmicalg.c:45
int cs_he_reset(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *err)
Reset a config item to its initial value.
Definition: set.c:375
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:216
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:48
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:47
The item stored in a Hash Table.
Definition: hash.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_string_get()

int cs_str_string_get ( const struct ConfigSet cs,
const char *  name,
struct Buffer result 
)

Get a config item as a string.

Parameters
csConfig items
nameName of config item
resultBuffer for results or error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 698 of file set.c.

699 {
700  if (!cs || !name)
701  return CSR_ERR_CODE;
702 
703  struct HashElem *he = cs_get_elem(cs, name);
704  if (!he)
705  {
706  mutt_buffer_printf(result, "Unknown var '%s'", name);
707  return CSR_ERR_UNKNOWN;
708  }
709 
710  return cs_he_string_get(cs, he, result);
711 }
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
Definition: pgpmicalg.c:45
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:216
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:48
int cs_he_string_get(const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
Definition: set.c:650
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:47
The item stored in a Hash Table.
Definition: hash.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_str_string_set()

int cs_str_string_set ( const struct ConfigSet cs,
const char *  name,
const char *  value,
struct Buffer err 
)

Set a config item by string.

Parameters
csConfig items
nameName of config item
valueValue to set
errBuffer for error messages
Return values
numResult, e.g. CSR_SUCCESS

Definition at line 627 of file set.c.

629 {
630  if (!cs || !name)
631  return CSR_ERR_CODE;
632 
633  struct HashElem *he = cs_get_elem(cs, name);
634  if (!he)
635  {
636  mutt_buffer_printf(err, "Unknown var '%s'", name);
637  return CSR_ERR_UNKNOWN;
638  }
639 
640  return cs_he_string_set(cs, he, value, err);
641 }
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
const char * name
Definition: pgpmicalg.c:45
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:216
#define CSR_ERR_UNKNOWN
Unrecognised config item.
Definition: set.h:48
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:47
The item stored in a Hash Table.
Definition: hash.h:42
int cs_he_string_set(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
Set a config item by string.
Definition: set.c:576
+ Here is the call graph for this function:
+ Here is the caller graph for this function: