NeoMutt  2020-06-26-89-g172cd3
Teaching an old dog new tricks
DOXYGEN
subset.c File Reference

Subset of config items. More...

#include "config.h"
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "mutt/lib.h"
#include "subset.h"
#include "set.h"
+ Include dependency graph for subset.c:

Go to the source code of this file.

Functions

int elem_list_sort (const void *a, const void *b)
 Sort two HashElem pointers to config. More...
 
struct HashElem ** get_elem_list (struct ConfigSet *cs)
 Create a sorted list of all config items. More...
 
void cs_subset_free (struct ConfigSubset **ptr)
 Free a Config Subset. More...
 
struct ConfigSubsetcs_subset_new (const char *name, struct ConfigSubset *sub_parent, struct Notify *not_parent)
 Create a new Config Subset. More...
 
struct HashElemcs_subset_lookup (const struct ConfigSubset *sub, const char *name)
 Find an inherited config item. More...
 
struct HashElemcs_subset_create_inheritance (const struct ConfigSubset *sub, const char *name)
 Create a Subset config item (inherited) More...
 
void cs_subset_notify_observers (const struct ConfigSubset *sub, struct HashElem *he, enum NotifyConfig ev)
 Notify all observers of an event. More...
 
intptr_t cs_subset_he_native_get (const struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
 Natively get the value of a HashElem config item. More...
 
intptr_t cs_subset_str_native_get (const struct ConfigSubset *sub, const char *name, struct Buffer *err)
 Natively get the value of a string config item. More...
 
int cs_subset_he_native_set (const struct ConfigSubset *sub, struct HashElem *he, intptr_t value, struct Buffer *err)
 Natively set the value of a HashElem config item. More...
 
int cs_subset_str_native_set (const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
 Natively set the value of a string config item. More...
 
int cs_subset_he_reset (const struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
 Reset a config item to its initial value. More...
 
int cs_subset_str_reset (const struct ConfigSubset *sub, const char *name, struct Buffer *err)
 Reset a config item to its initial value. More...
 
int cs_subset_he_string_get (const struct ConfigSubset *sub, struct HashElem *he, struct Buffer *result)
 Get a config item as a string. More...
 
int cs_subset_str_string_get (const struct ConfigSubset *sub, const char *name, struct Buffer *result)
 Get a config item as a string. More...
 
int cs_subset_he_string_set (const struct ConfigSubset *sub, struct HashElem *he, const char *value, struct Buffer *err)
 Set a config item by string. More...
 
int cs_subset_str_string_set (const struct ConfigSubset *sub, const char *name, const char *value, struct Buffer *err)
 Set a config item by string. More...
 
int cs_subset_he_string_plus_equals (const struct ConfigSubset *sub, struct HashElem *he, const char *value, struct Buffer *err)
 Add to a config item by string. More...
 
int cs_subset_str_string_plus_equals (const struct ConfigSubset *sub, const char *name, const char *value, struct Buffer *err)
 Add to a config item by string. More...
 
int cs_subset_he_string_minus_equals (const struct ConfigSubset *sub, struct HashElem *he, const char *value, struct Buffer *err)
 Remove from a config item by string. More...
 
int cs_subset_str_string_minus_equals (const struct ConfigSubset *sub, const char *name, const char *value, struct Buffer *err)
 Remove from a config item by string. More...
 

Detailed Description

Subset 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 subset.c.

Function Documentation

◆ elem_list_sort()

int elem_list_sort ( const void *  a,
const void *  b 
)

Sort two HashElem pointers to config.

Parameters
aFirst HashElem
bSecond HashElem
Return values
-1a precedes b
0a and b are identical
1b precedes a

Definition at line 48 of file subset.c.

49 {
50  if (!a || !b)
51  return 0;
52 
53  const struct HashElem *hea = *(struct HashElem const *const *) a;
54  const struct HashElem *heb = *(struct HashElem const *const *) b;
55 
56  return mutt_istr_cmp(hea->key.strkey, heb->key.strkey);
57 }
int mutt_istr_cmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:585
union HashKey key
Key representing the data.
Definition: hash.h:46
const char * strkey
String key.
Definition: hash.h:36
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_elem_list()

struct HashElem** get_elem_list ( struct ConfigSet cs)

Create a sorted list of all config items.

Parameters
csConfigSet to read
Return values
ptrNull-terminated array of HashElem

Definition at line 64 of file subset.c.

65 {
66  if (!cs)
67  return NULL;
68 
69  struct HashElem **list = mutt_mem_calloc(1024, sizeof(struct HashElem *));
70  size_t index = 0;
71 
72  struct HashWalkState walk = { 0 };
73  struct HashElem *he = NULL;
74 
75  while ((he = mutt_hash_walk(cs->hash, &walk)))
76  {
77  list[index++] = he;
78  if (index == 1022)
79  break; /* LCOV_EXCL_LINE */
80  }
81 
82  qsort(list, index, sizeof(struct HashElem *), elem_list_sort);
83 
84  return list;
85 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
Cursor to iterate through a Hash Table.
Definition: hash.h:119
struct HashTable * hash
HashTable storing the config items.
Definition: set.h:229
int elem_list_sort(const void *a, const void *b)
Sort two HashElem pointers to config.
Definition: subset.c:48
struct HashElem * mutt_hash_walk(const struct HashTable *table, struct HashWalkState *state)
Iterate through all the HashElem&#39;s in a Hash Table.
Definition: hash.c:479
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_free()

void cs_subset_free ( struct ConfigSubset **  ptr)

Free a Config Subset.

Parameters
ptrSubset to free
Note
Config items matching this Subset will be freed

Definition at line 93 of file subset.c.

94 {
95  if (!ptr || !*ptr)
96  return;
97 
98  struct ConfigSubset *sub = *ptr;
99 
100  if (sub->cs && sub->name)
101  {
102  char scope[256];
103  snprintf(scope, sizeof(scope), "%s:", sub->name);
104 
105  // We don't know if any config items have been set,
106  // so search for anything with a matching scope.
107  struct HashElem **list = get_elem_list(sub->cs);
108  for (size_t i = 0; list[i]; i++)
109  {
110  const char *item = list[i]->key.strkey;
111  if (mutt_str_startswith(item, scope) != 0)
112  {
113  cs_uninherit_variable(sub->cs, item);
114  }
115  }
116  FREE(&list);
117  }
118 
119  notify_free(&sub->notify);
120  FREE(&sub->name);
121  FREE(ptr);
122 }
union HashKey key
Key representing the data.
Definition: hash.h:46
struct HashElem ** get_elem_list(struct ConfigSet *cs)
Create a sorted list of all config items.
Definition: subset.c:64
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:62
const char * name
Scope name of Subset.
Definition: subset.h:48
void cs_uninherit_variable(const struct ConfigSet *cs, const char *name)
Remove an inherited config item.
Definition: set.c:333
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
A set of inherited config items.
Definition: subset.h:46
struct Notify * notify
Notifications system.
Definition: subset.h:52
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:165
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition: subset.h:49
const char * strkey
String key.
Definition: hash.h:36
#define FREE(x)
Definition: memory.h:40
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_new()

struct ConfigSubset* cs_subset_new ( const char *  name,
struct ConfigSubset sub_parent,
struct Notify not_parent 
)

Create a new Config Subset.

Parameters
nameName for this Subset
sub_parentParent Subset
not_parentParent Notification
Return values
ptrNew Subset
Note
The name will be combined with the parents' names

Definition at line 133 of file subset.c.

135 {
136  struct ConfigSubset *sub = mutt_mem_calloc(1, sizeof(*sub));
137 
138  if (sub_parent)
139  {
140  sub->parent = sub_parent;
141  sub->cs = sub_parent->cs;
142  }
143 
144  if (name)
145  {
146  char scope[256];
147 
148  if (sub_parent && sub_parent->name)
149  snprintf(scope, sizeof(scope), "%s:%s", sub_parent->name, name);
150  else
151  mutt_str_copy(scope, name, sizeof(scope));
152 
153  sub->name = mutt_str_dup(scope);
154  }
155 
156  sub->notify = notify_new();
157  notify_set_parent(sub->notify, not_parent);
158 
159  return sub;
160 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct ConfigSubset * parent
Parent Subset.
Definition: subset.h:50
const char * name
Scope name of Subset.
Definition: subset.h:48
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:375
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:49
A set of inherited config items.
Definition: subset.h:46
struct Notify * notify
Notifications system.
Definition: subset.h:52
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition: subset.h:49
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:721
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_lookup()

struct HashElem* cs_subset_lookup ( const struct ConfigSubset sub,
const char *  name 
)

Find an inherited config item.

Parameters
subSubset to search
nameName of Config item to find
Return values
ptrHashElem of the config item

Definition at line 168 of file subset.c.

169 {
170  if (!sub || !name)
171  return NULL;
172 
173  char scope[256];
174  if (sub->name)
175  snprintf(scope, sizeof(scope), "%s:%s", sub->name, name);
176  else
177  mutt_str_copy(scope, name, sizeof(scope));
178 
179  return cs_get_elem(sub->cs, scope);
180 }
const char * name
Scope name of Subset.
Definition: subset.h:48
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
struct HashElem * cs_get_elem(const struct ConfigSet *cs, const char *name)
Get the HashElem representing a config item.
Definition: set.c:206
enum ConfigScope scope
Scope of Subset, e.g. SET_SCOPE_ACCOUNT.
Definition: subset.h:49
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:721
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_create_inheritance()

struct HashElem* cs_subset_create_inheritance ( const struct ConfigSubset sub,
const char *  name 
)

Create a Subset config item (inherited)

Parameters
subConfig Subset
nameName of config item
Return values
ptrHashElem of the config item
NULLError

Definition at line 189 of file subset.c.

190 {
191  if (!sub)
192  return NULL;
193 
194  struct HashElem *he = cs_subset_lookup(sub, name);
195  if (he)
196  return he;
197 
198  if (sub->parent)
199  {
200  // Create parent before creating name
201  he = cs_subset_create_inheritance(sub->parent, name);
202  }
203 
204  if (!he)
205  return NULL;
206 
207  char scope[256];
208  snprintf(scope, sizeof(scope), "%s:%s", sub->name, name);
209  return cs_inherit_variable(sub->cs, he, scope);
210 }
struct ConfigSubset * parent
Parent Subset.
Definition: subset.h:50
const char * name
Scope name of Subset.
Definition: subset.h:48
struct HashElem * cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *parent, const char *name)
Create in inherited config item.
Definition: set.c:308
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
struct HashElem * cs_subset_lookup(const struct ConfigSubset *sub, const char *name)
Find an inherited config item.
Definition: subset.c:168
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_notify_observers()

void cs_subset_notify_observers ( const struct ConfigSubset sub,
struct HashElem he,
enum NotifyConfig  ev 
)

Notify all observers of an event.

Parameters
subConfig Subset
heHashElem representing config item
evType of event

Definition at line 218 of file subset.c.

220 {
221  if (!sub || !he)
222  return;
223 
224  struct HashElem *he_base = cs_get_base(he);
225  struct EventConfig ec = { sub, he_base->key.strkey, he };
226  notify_send(sub->notify, NT_CONFIG, ev, &ec);
227 }
union HashKey key
Key representing the data.
Definition: hash.h:46
A config-change event.
Definition: subset.h:70
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:191
struct Notify * notify
Notifications system.
Definition: subset.h:52
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:36
const char * strkey
String key.
Definition: hash.h:36
The item stored in a Hash Table.
Definition: hash.h:43
const struct ConfigSubset * sub
Config Subset.
Definition: subset.h:72
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:137
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_he_native_get()

intptr_t cs_subset_he_native_get ( const struct ConfigSubset sub,
struct HashElem he,
struct Buffer err 
)

Natively get the value of a HashElem config item.

Parameters
subConfig Subset
heHashElem representing config item
errBuffer for error messages
Return values
intptr_tNative pointer/value
INT_MINError

Definition at line 237 of file subset.c.

239 {
240  if (!sub)
241  return INT_MIN;
242 
243  return cs_he_native_get(sub->cs, he, err);
244 }
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
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:792
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_str_native_get()

intptr_t cs_subset_str_native_get ( const struct ConfigSubset sub,
const char *  name,
struct Buffer err 
)

Natively get the value of a string config item.

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

Definition at line 254 of file subset.c.

256 {
257  struct HashElem *he = cs_subset_create_inheritance(sub, name);
258 
259  return cs_subset_he_native_get(sub, he, err);
260 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
intptr_t cs_subset_he_native_get(const struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
Natively get the value of a HashElem config item.
Definition: subset.c:237
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_he_native_set()

int cs_subset_he_native_set ( const struct ConfigSubset sub,
struct HashElem he,
intptr_t  value,
struct Buffer err 
)

Natively set the value of a HashElem config item.

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

Definition at line 270 of file subset.c.

272 {
273  if (!sub)
274  return CSR_ERR_CODE;
275 
276  int rc = cs_he_native_set(sub->cs, he, value, err);
277 
278  if ((CSR_RESULT(rc) == CSR_SUCCESS) && !(rc & CSR_SUC_NO_CHANGE))
280 
281  return rc;
282 }
#define CSR_RESULT(x)
Definition: set.h:52
void cs_subset_notify_observers(const struct ConfigSubset *sub, struct HashElem *he, enum NotifyConfig ev)
Notify all observers of an event.
Definition: subset.c:218
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
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.
Definition: set.c:687
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
Config item has been set.
Definition: subset.h:62
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
#define CSR_SUC_NO_CHANGE
The value hasn&#39;t changed.
Definition: set.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_str_native_set()

int cs_subset_str_native_set ( const struct ConfigSubset sub,
const char *  name,
intptr_t  value,
struct Buffer err 
)

Natively set the value of a string config item.

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

Definition at line 292 of file subset.c.

294 {
295  struct HashElem *he = cs_subset_create_inheritance(sub, name);
296 
297  return cs_subset_he_native_set(sub, he, value, err);
298 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
The item stored in a Hash Table.
Definition: hash.h:43
int cs_subset_he_native_set(const struct ConfigSubset *sub, struct HashElem *he, intptr_t value, struct Buffer *err)
Natively set the value of a HashElem config item.
Definition: subset.c:270
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_he_reset()

int cs_subset_he_reset ( const struct ConfigSubset sub,
struct HashElem he,
struct Buffer err 
)

Reset a config item to its initial value.

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

Definition at line 307 of file subset.c.

308 {
309  if (!sub)
310  return CSR_ERR_CODE;
311 
312  int rc = cs_he_reset(sub->cs, he, err);
313 
314  if ((CSR_RESULT(rc) == CSR_SUCCESS) && !(rc & CSR_SUC_NO_CHANGE))
316 
317  return rc;
318 }
#define CSR_RESULT(x)
Definition: set.h:52
void cs_subset_notify_observers(const struct ConfigSubset *sub, struct HashElem *he, enum NotifyConfig ev)
Notify all observers of an event.
Definition: subset.c:218
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
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:348
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
Config item has been reset to initial, or parent, value.
Definition: subset.h:63
#define CSR_SUC_NO_CHANGE
The value hasn&#39;t changed.
Definition: set.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_str_reset()

int cs_subset_str_reset ( const struct ConfigSubset sub,
const char *  name,
struct Buffer err 
)

Reset a config item to its initial value.

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

Definition at line 327 of file subset.c.

328 {
329  struct HashElem *he = cs_subset_create_inheritance(sub, name);
330 
331  return cs_subset_he_reset(sub, he, err);
332 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
The item stored in a Hash Table.
Definition: hash.h:43
int cs_subset_he_reset(const struct ConfigSubset *sub, struct HashElem *he, struct Buffer *err)
Reset a config item to its initial value.
Definition: subset.c:307
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_he_string_get()

int cs_subset_he_string_get ( const struct ConfigSubset sub,
struct HashElem he,
struct Buffer result 
)

Get a config item as a string.

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

Definition at line 341 of file subset.c.

343 {
344  if (!sub)
345  return CSR_ERR_CODE;
346 
347  return cs_he_string_get(sub->cs, he, result);
348 }
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
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:620
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_str_string_get()

int cs_subset_str_string_get ( const struct ConfigSubset sub,
const char *  name,
struct Buffer result 
)

Get a config item as a string.

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

Definition at line 357 of file subset.c.

359 {
360  struct HashElem *he = cs_subset_create_inheritance(sub, name);
361 
362  return cs_subset_he_string_get(sub, he, result);
363 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
int cs_subset_he_string_get(const struct ConfigSubset *sub, struct HashElem *he, struct Buffer *result)
Get a config item as a string.
Definition: subset.c:341
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_he_string_set()

int cs_subset_he_string_set ( const struct ConfigSubset sub,
struct HashElem he,
const char *  value,
struct Buffer err 
)

Set a config item by string.

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

Definition at line 373 of file subset.c.

375 {
376  if (!sub)
377  return CSR_ERR_CODE;
378 
379  int rc = cs_he_string_set(sub->cs, he, value, err);
380 
381  if ((CSR_RESULT(rc) == CSR_SUCCESS) && !(rc & CSR_SUC_NO_CHANGE))
383 
384  return rc;
385 }
#define CSR_RESULT(x)
Definition: set.h:52
void cs_subset_notify_observers(const struct ConfigSubset *sub, struct HashElem *he, enum NotifyConfig ev)
Notify all observers of an event.
Definition: subset.c:218
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
Config item has been set.
Definition: subset.h:62
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
#define CSR_SUC_NO_CHANGE
The value hasn&#39;t changed.
Definition: set.h:44
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:545
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_str_string_set()

int cs_subset_str_string_set ( const struct ConfigSubset sub,
const char *  name,
const char *  value,
struct Buffer err 
)

Set a config item by string.

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

Definition at line 395 of file subset.c.

397 {
398  struct HashElem *he = cs_subset_create_inheritance(sub, name);
399 
400  return cs_subset_he_string_set(sub, he, value, err);
401 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
int cs_subset_he_string_set(const struct ConfigSubset *sub, struct HashElem *he, const char *value, struct Buffer *err)
Set a config item by string.
Definition: subset.c:373
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_he_string_plus_equals()

int cs_subset_he_string_plus_equals ( const struct ConfigSubset sub,
struct HashElem he,
const char *  value,
struct Buffer err 
)

Add to a config item by string.

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

Definition at line 411 of file subset.c.

413 {
414  if (!sub)
415  return CSR_ERR_CODE;
416 
417  int rc = cs_he_string_plus_equals(sub->cs, he, value, err);
418 
419  if ((CSR_RESULT(rc) == CSR_SUCCESS) && !(rc & CSR_SUC_NO_CHANGE))
421 
422  return rc;
423 }
#define CSR_RESULT(x)
Definition: set.h:52
void cs_subset_notify_observers(const struct ConfigSubset *sub, struct HashElem *he, enum NotifyConfig ev)
Notify all observers of an event.
Definition: subset.c:218
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
int cs_he_string_plus_equals(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
Add to a config item by string.
Definition: set.c:860
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
Config item has been set.
Definition: subset.h:62
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
#define CSR_SUC_NO_CHANGE
The value hasn&#39;t changed.
Definition: set.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_str_string_plus_equals()

int cs_subset_str_string_plus_equals ( const struct ConfigSubset sub,
const char *  name,
const char *  value,
struct Buffer err 
)

Add to a config item by string.

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

Definition at line 433 of file subset.c.

435 {
436  struct HashElem *he = cs_subset_create_inheritance(sub, name);
437 
438  return cs_subset_he_string_plus_equals(sub, he, value, err);
439 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
int cs_subset_he_string_plus_equals(const struct ConfigSubset *sub, struct HashElem *he, const char *value, struct Buffer *err)
Add to a config item by string.
Definition: subset.c:411
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_he_string_minus_equals()

int cs_subset_he_string_minus_equals ( const struct ConfigSubset sub,
struct HashElem he,
const char *  value,
struct Buffer err 
)

Remove from a config item by string.

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

Definition at line 449 of file subset.c.

451 {
452  if (!sub)
453  return CSR_ERR_CODE;
454 
455  int rc = cs_he_string_minus_equals(sub->cs, he, value, err);
456 
457  if ((CSR_RESULT(rc) == CSR_SUCCESS) && !(rc & CSR_SUC_NO_CHANGE))
459 
460  return rc;
461 }
int cs_he_string_minus_equals(const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err)
Remove from a config item by string.
Definition: set.c:943
#define CSR_RESULT(x)
Definition: set.h:52
void cs_subset_notify_observers(const struct ConfigSubset *sub, struct HashElem *he, enum NotifyConfig ev)
Notify all observers of an event.
Definition: subset.c:218
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
Config item has been set.
Definition: subset.h:62
#define CSR_ERR_CODE
Problem with the code.
Definition: set.h:36
#define CSR_SUC_NO_CHANGE
The value hasn&#39;t changed.
Definition: set.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_str_string_minus_equals()

int cs_subset_str_string_minus_equals ( const struct ConfigSubset sub,
const char *  name,
const char *  value,
struct Buffer err 
)

Remove from a config item by string.

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

Definition at line 471 of file subset.c.

473 {
474  struct HashElem *he = cs_subset_create_inheritance(sub, name);
475 
476  return cs_subset_he_string_minus_equals(sub, he, value, err);
477 }
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:189
int cs_subset_he_string_minus_equals(const struct ConfigSubset *sub, struct HashElem *he, const char *value, struct Buffer *err)
Remove from a config item by string.
Definition: subset.c:449
The item stored in a Hash Table.
Definition: hash.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function: