NeoMutt  2024-04-25-100-gcb3684
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
config_type.c File Reference

Config type representing an email address. More...

#include "config.h"
#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "config_type.h"
#include "address.h"
+ Include dependency graph for config_type.c:

Go to the source code of this file.

Functions

struct Addressaddress_new (const char *addr)
 Create an Address from a string.
 
static void address_destroy (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
 Destroy an Address object - Implements ConfigSetType::destroy() -.
 
static int address_string_set (const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
 Set an Address by string - Implements ConfigSetType::string_set() -.
 
static int address_string_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
 Get an Address as a string - Implements ConfigSetType::string_get() -.
 
static struct Addressaddress_dup (struct Address *addr)
 Create a copy of an Address object.
 
static int address_native_set (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Set an Address config item by Address object - Implements ConfigSetType::native_set() -.
 
static intptr_t address_native_get (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Get an Address object from an Address config item - Implements ConfigSetType::native_get() -.
 
static int address_reset (const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
 Reset an Address to its initial value - Implements ConfigSetType::reset() -.
 
const struct Addresscs_subset_address (const struct ConfigSubset *sub, const char *name)
 Get an Address config item by name.
 

Variables

const struct ConfigSetType CstAddress
 Config type representing an Email Address.
 

Detailed Description

Config type representing an email address.

Authors
  • Richard Russon
  • Pietro Cerutti
  • Dennis Schön

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 config_type.c.

Function Documentation

◆ address_new()

struct Address * address_new ( const char *  addr)

Create an Address from a string.

Parameters
addrEmail address to parse
Return values
ptrNew Address object

Definition at line 52 of file config_type.c.

53{
54 struct Address *a = mutt_mem_calloc(1, sizeof(*a));
55 a->mailbox = buf_new(addr);
56 return a;
57}
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition: buffer.c:304
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
An email address.
Definition: address.h:36
struct Buffer * mailbox
Mailbox and host address.
Definition: address.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ address_dup()

static struct Address * address_dup ( struct Address addr)
static

Create a copy of an Address object.

Parameters
addrAddress to duplicate
Return values
ptrNew Address object

Definition at line 164 of file config_type.c.

165{
166 if (!addr)
167 return NULL; /* LCOV_EXCL_LINE */
168
169 struct Address *a = mutt_mem_calloc(1, sizeof(*a));
170 a->personal = buf_dup(addr->personal);
171 a->mailbox = buf_dup(addr->mailbox);
172 return a;
173}
struct Buffer * buf_dup(const struct Buffer *buf)
Copy a Buffer into a new allocated buffer.
Definition: buffer.c:586
struct Buffer * personal
Real name of address.
Definition: address.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cs_subset_address()

const struct Address * cs_subset_address ( const struct ConfigSubset sub,
const char *  name 
)

Get an Address config item by name.

Parameters
subConfig Subset
nameName of config item
Return values
ptrAddress
NULLEmpty address

Definition at line 272 of file config_type.c.

273{
274 ASSERT(sub && name);
275
276 struct HashElem *he = cs_subset_create_inheritance(sub, name);
277 ASSERT(he);
278
279#ifndef NDEBUG
280 struct HashElem *he_base = cs_get_base(he);
281 ASSERT(DTYPE(he_base->type) == DT_ADDRESS);
282#endif
283
284 intptr_t value = cs_subset_he_native_get(sub, he, NULL);
285 ASSERT(value != INT_MIN);
286
287 return (const struct Address *) value;
288}
struct HashElem * cs_get_base(struct HashElem *he)
Find the root Config Item.
Definition: set.c:160
#define ASSERT(COND)
Definition: signal2.h:58
The item stored in a Hash Table.
Definition: hash.h:43
int type
Type of data stored in Hash Table, e.g. DT_STRING.
Definition: hash.h:44
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
struct HashElem * cs_subset_create_inheritance(const struct ConfigSubset *sub, const char *name)
Create a Subset config item (inherited)
Definition: subset.c:208
#define DTYPE(t)
Definition: types.h:50
@ DT_ADDRESS
e-mail address
Definition: types.h:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ CstAddress

const struct ConfigSetType CstAddress
Initial value:
= {
"address",
NULL,
NULL,
}
static void address_destroy(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef)
Destroy an Address object - Implements ConfigSetType::destroy() -.
Definition: config_type.c:62
static intptr_t address_native_get(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Get an Address object from an Address config item - Implements ConfigSetType::native_get() -.
Definition: config_type.c:207
static int address_native_set(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Set an Address config item by Address object - Implements ConfigSetType::native_set() -.
Definition: config_type.c:178
static int address_reset(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *err)
Reset an Address to its initial value - Implements ConfigSetType::reset() -.
Definition: config_type.c:218
static int address_string_get(const struct ConfigSet *cs, void *var, const struct ConfigDef *cdef, struct Buffer *result)
Get an Address as a string - Implements ConfigSetType::string_get() -.
Definition: config_type.c:137
static int address_string_set(const struct ConfigSet *cs, void *var, struct ConfigDef *cdef, const char *value, struct Buffer *err)
Set an Address by string - Implements ConfigSetType::string_set() -.
Definition: config_type.c:74

Config type representing an Email Address.

Definition at line 252 of file config_type.c.