NeoMutt  2023-11-03-85-g512e01
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
config_cache.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stdbool.h>
31#include <string.h>
32#include "mutt/lib.h"
33#include "config/lib.h"
34#include "config_cache.h"
35#include "neomutt.h"
36
38static bool CacheActive = false;
40static const struct Slist *CachedAssumedCharset = NULL;
42static const char *CachedCharset = NULL;
44static const char *CachedMaildirFieldDelimiter = NULL;
45
49static int cc_config_observer(struct NotifyCallback *nc)
50{
51 if (nc->event_type != NT_CONFIG)
52 return 0; // LCOV_EXCL_LINE
53 if (!nc->event_data)
54 return -1; // LCOV_EXCL_LINE
55
56 struct EventConfig *ev_c = nc->event_data;
57 if (!ev_c->name || !ev_c->he)
58 return 0; // LCOV_EXCL_LINE
59
60 if (mutt_str_equal(ev_c->name, "assumed_charset"))
61 {
63 ev_c->he, NULL);
64 }
65 else if (mutt_str_equal(ev_c->name, "charset"))
66 {
67 CachedCharset = (const char *) cs_subset_he_native_get(ev_c->sub, ev_c->he, NULL);
68 }
69 else if (mutt_str_equal(ev_c->name, "maildir_field_delimiter"))
70 {
72 ev_c->he, NULL);
73 }
74
75 mutt_debug(LL_DEBUG5, "config done\n");
76 return 0;
77}
78
82static void cache_setup(void)
83{
84 if (CacheActive)
85 return; // LCOV_EXCL_LINE
86
88
89 CachedAssumedCharset = cs_subset_slist(NeoMutt->sub, "assumed_charset");
91 CachedMaildirFieldDelimiter = cs_subset_string(NeoMutt->sub, "maildir_field_delimiter");
92
93 CacheActive = true;
94}
95
100const struct Slist *cc_assumed_charset(void)
101{
102 if (!CacheActive)
103 {
104 cache_setup();
105 CachedAssumedCharset = cs_subset_slist(NeoMutt->sub, "assumed_charset");
106 }
107
109}
110
115const char *cc_charset(void)
116{
117 if (!CacheActive)
118 {
119 cache_setup();
121 }
122
123 return CachedCharset;
124}
125
131{
132 if (!CacheActive)
133 {
134 cache_setup();
135 CachedMaildirFieldDelimiter = cs_subset_string(NeoMutt->sub, "maildir_field_delimiter");
136 }
137
139}
140
145{
146 if (NeoMutt)
148
149 // Don't free them, the config system owns the data
151 CachedCharset = NULL;
153
154 CacheActive = false;
155}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition: helpers.c:243
Convenience wrapper for the config headers.
const char * cc_charset(void)
Get the cached value of $charset.
Definition: config_cache.c:115
const char * cc_maildir_field_delimiter(void)
Get the cached value of $maildir_field_delimiter.
Definition: config_cache.c:130
static const char * CachedMaildirFieldDelimiter
Cached value of $maildir_field_delimiter.
Definition: config_cache.c:44
static void cache_setup(void)
Setup a cache of some config variables.
Definition: config_cache.c:82
void config_cache_cleanup(void)
Cleanup the cache of charset config variables.
Definition: config_cache.c:144
static const struct Slist * CachedAssumedCharset
Cached value of $assumed_charset.
Definition: config_cache.c:40
const struct Slist * cc_assumed_charset(void)
Get the cached value of $assumed_charset.
Definition: config_cache.c:100
static const char * CachedCharset
Cached value of $charset.
Definition: config_cache.c:42
static bool CacheActive
Is the cache enabled?
Definition: config_cache.c:38
Cache of config variables.
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
static int cc_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: config_cache.c:49
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
Convenience wrapper for the library headers.
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition: notify.c:230
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:191
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:798
Container for Accounts, Notifications.
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
struct Notify * notify
Notifications: NotifyConfig, EventConfig.
Definition: subset.h:52
A config-change event.
Definition: subset.h:71
const struct ConfigSubset * sub
Config Subset.
Definition: subset.h:72
const char * name
Name of config item that changed.
Definition: subset.h:73
struct HashElem * he
Config item that changed.
Definition: subset.h:74
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
Data passed to a notification function.
Definition: observer.h:34
void * event_data
Data from notify_send()
Definition: observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:36
String list.
Definition: slist.h:47
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:249