NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
parameter.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <stddef.h>
32#include <stdbool.h>
33#include "mutt/lib.h"
34#include "parameter.h"
35
41{
42 return mutt_mem_calloc(1, sizeof(struct Parameter));
43}
44
50{
51 if (!p || !*p)
52 return;
53 FREE(&(*p)->attribute);
54 FREE(&(*p)->value);
55 FREE(p);
56}
57
62void mutt_param_free(struct ParameterList *pl)
63{
64 if (!pl)
65 return;
66
67 struct Parameter *np = TAILQ_FIRST(pl);
68 struct Parameter *next = NULL;
69 while (np)
70 {
71 next = TAILQ_NEXT(np, entries);
73 np = next;
74 }
75 TAILQ_INIT(pl);
76}
77
85char *mutt_param_get(const struct ParameterList *pl, const char *s)
86{
87 if (!pl)
88 return NULL;
89
90 struct Parameter *np = NULL;
91 TAILQ_FOREACH(np, pl, entries)
92 {
93 if (mutt_istr_equal(s, np->attribute))
94 return np->value;
95 }
96
97 return NULL;
98}
99
111void mutt_param_set(struct ParameterList *pl, const char *attribute, const char *value)
112{
113 if (!pl)
114 return;
115
116 if (!value)
117 {
119 return;
120 }
121
122 struct Parameter *np = NULL;
123 TAILQ_FOREACH(np, pl, entries)
124 {
126 {
128 return;
129 }
130 }
131
132 np = mutt_param_new();
134 np->value = mutt_str_dup(value);
135 TAILQ_INSERT_HEAD(pl, np, entries);
136}
137
143void mutt_param_delete(struct ParameterList *pl, const char *attribute)
144{
145 if (!pl)
146 return;
147
148 struct Parameter *np = NULL;
149 TAILQ_FOREACH(np, pl, entries)
150 {
152 {
153 TAILQ_REMOVE(pl, np, entries);
155 return;
156 }
157 }
158}
159
166bool mutt_param_cmp_strict(const struct ParameterList *pl1, const struct ParameterList *pl2)
167{
168 if (!pl1 && !pl2)
169 return false;
170
171 if ((pl1 == NULL) ^ (pl2 == NULL))
172 return true;
173
174 struct Parameter *np1 = TAILQ_FIRST(pl1);
175 struct Parameter *np2 = TAILQ_FIRST(pl2);
176
177 while (np1 && np2)
178 {
179 if (!mutt_str_equal(np1->attribute, np2->attribute) ||
180 !mutt_str_equal(np1->value, np2->value))
181 {
182 return false;
183 }
184
185 np1 = TAILQ_NEXT(np1, entries);
186 np2 = TAILQ_NEXT(np2, entries);
187 }
188
189 if (np1 || np2)
190 return false;
191
192 return true;
193}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define FREE(x)
Definition: memory.h:45
Convenience wrapper for the library headers.
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:666
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:654
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:274
bool mutt_param_cmp_strict(const struct ParameterList *pl1, const struct ParameterList *pl2)
Strictly compare two ParameterLists.
Definition: parameter.c:166
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:85
void mutt_param_delete(struct ParameterList *pl, const char *attribute)
Delete a matching Parameter.
Definition: parameter.c:143
void mutt_param_set(struct ParameterList *pl, const char *attribute, const char *value)
Set a Parameter.
Definition: parameter.c:111
void mutt_param_free_one(struct Parameter **p)
Free a Parameter.
Definition: parameter.c:49
void mutt_param_free(struct ParameterList *pl)
Free a ParameterList.
Definition: parameter.c:62
struct Parameter * mutt_param_new(void)
Create a new Parameter.
Definition: parameter.c:40
Store attributes associated with a MIME part.
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define TAILQ_INIT(head)
Definition: queue.h:765
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
#define TAILQ_NEXT(elm, field)
Definition: queue.h:832
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:796
Attribute associated with a MIME part.
Definition: parameter.h:33
char * attribute
Parameter name.
Definition: parameter.h:34
char * value
Parameter value.
Definition: parameter.h:35