NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
config_cache.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stdbool.h>
32#include <string.h>
33#include "mutt/lib.h"
34#include "config/lib.h"
35#include "config_cache.h"
36#include "neomutt.h"
37
39static bool CacheActive = false;
41static const struct Slist *CachedAssumedCharset = NULL;
43static const char *CachedCharset = NULL;
45static const char *CachedMaildirFieldDelimiter = NULL;
46
50static int cc_config_observer(struct NotifyCallback *nc)
51{
52 if (nc->event_type != NT_CONFIG)
53 return 0; // LCOV_EXCL_LINE
54 if (!nc->event_data)
55 return -1; // LCOV_EXCL_LINE
56
57 struct EventConfig *ev_c = nc->event_data;
58 if (!ev_c->name || !ev_c->he)
59 return 0; // LCOV_EXCL_LINE
60
61 if (mutt_str_equal(ev_c->name, "assumed_charset"))
62 {
64 ev_c->he, NULL);
65 }
66 else if (mutt_str_equal(ev_c->name, "charset"))
67 {
68 CachedCharset = (const char *) cs_subset_he_native_get(ev_c->sub, ev_c->he, NULL);
69 }
70 else if (mutt_str_equal(ev_c->name, "maildir_field_delimiter"))
71 {
73 ev_c->he, NULL);
74 }
75
76 mutt_debug(LL_DEBUG5, "config done\n");
77 return 0;
78}
79
83static void cache_setup(void)
84{
85 if (CacheActive)
86 return; // LCOV_EXCL_LINE
87
89
90 CachedAssumedCharset = cs_subset_slist(NeoMutt->sub, "assumed_charset");
92 CachedMaildirFieldDelimiter = cs_subset_string(NeoMutt->sub, "maildir_field_delimiter");
93
94 CacheActive = true;
95}
96
101const struct Slist *cc_assumed_charset(void)
102{
103 if (!CacheActive)
104 {
105 cache_setup();
106 CachedAssumedCharset = cs_subset_slist(NeoMutt->sub, "assumed_charset");
107 }
108
110}
111
116const char *cc_charset(void)
117{
118 if (!CacheActive)
119 {
120 cache_setup();
122 }
123
124 return CachedCharset;
125}
126
132{
133 if (!CacheActive)
134 {
135 cache_setup();
136 CachedMaildirFieldDelimiter = cs_subset_string(NeoMutt->sub, "maildir_field_delimiter");
137 }
138
140}
141
146{
147 if (NeoMutt)
149
150 // Don't free them, the config system owns the data
152 CachedCharset = NULL;
154
155 CacheActive = false;
156}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:291
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition: helpers.c:242
Convenience wrapper for the config headers.
const char * cc_charset(void)
Get the cached value of $charset.
Definition: config_cache.c:116
const char * cc_maildir_field_delimiter(void)
Get the cached value of $maildir_field_delimiter.
Definition: config_cache.c:131
static const char * CachedMaildirFieldDelimiter
Cached value of $maildir_field_delimiter.
Definition: config_cache.c:45
static void cache_setup(void)
Setup a cache of some config variables.
Definition: config_cache.c:83
void config_cache_cleanup(void)
Cleanup the cache of charset config variables.
Definition: config_cache.c:145
static const struct Slist * CachedAssumedCharset
Cached value of $assumed_charset.
Definition: config_cache.c:41
const struct Slist * cc_assumed_charset(void)
Get the cached value of $assumed_charset.
Definition: config_cache.c:101
static const char * CachedCharset
Cached value of $charset.
Definition: config_cache.c:43
static bool CacheActive
Is the cache enabled?
Definition: config_cache.c:39
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:50
@ 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:660
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:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
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:37
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:258