NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
parameter.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stddef.h>
31#include <stdbool.h>
32#include "mutt/lib.h"
33#include "parameter.h"
34
40{
41 return mutt_mem_calloc(1, sizeof(struct Parameter));
42}
43
49{
50 if (!p || !*p)
51 return;
52 FREE(&(*p)->attribute);
53 FREE(&(*p)->value);
54 FREE(p);
55}
56
61void mutt_param_free(struct ParameterList *pl)
62{
63 if (!pl)
64 return;
65
66 struct Parameter *np = TAILQ_FIRST(pl);
67 struct Parameter *next = NULL;
68 while (np)
69 {
70 next = TAILQ_NEXT(np, entries);
72 np = next;
73 }
74 TAILQ_INIT(pl);
75}
76
84char *mutt_param_get(const struct ParameterList *pl, const char *s)
85{
86 if (!pl)
87 return NULL;
88
89 struct Parameter *np = NULL;
90 TAILQ_FOREACH(np, pl, entries)
91 {
92 if (mutt_istr_equal(s, np->attribute))
93 return np->value;
94 }
95
96 return NULL;
97}
98
110void mutt_param_set(struct ParameterList *pl, const char *attribute, const char *value)
111{
112 if (!pl)
113 return;
114
115 if (!value)
116 {
118 return;
119 }
120
121 struct Parameter *np = NULL;
122 TAILQ_FOREACH(np, pl, entries)
123 {
125 {
127 return;
128 }
129 }
130
131 np = mutt_param_new();
133 np->value = mutt_str_dup(value);
134 TAILQ_INSERT_HEAD(pl, np, entries);
135}
136
142void mutt_param_delete(struct ParameterList *pl, const char *attribute)
143{
144 if (!pl)
145 return;
146
147 struct Parameter *np = NULL;
148 TAILQ_FOREACH(np, pl, entries)
149 {
151 {
152 TAILQ_REMOVE(pl, np, entries);
154 return;
155 }
156 }
157}
158
165bool mutt_param_cmp_strict(const struct ParameterList *pl1, const struct ParameterList *pl2)
166{
167 if (!pl1 && !pl2)
168 return false;
169
170 if ((pl1 == NULL) ^ (pl2 == NULL))
171 return true;
172
173 struct Parameter *np1 = TAILQ_FIRST(pl1);
174 struct Parameter *np2 = TAILQ_FIRST(pl2);
175
176 while (np1 && np2)
177 {
178 if (!mutt_str_equal(np1->attribute, np2->attribute) ||
179 !mutt_str_equal(np1->value, np2->value))
180 {
181 return false;
182 }
183
184 np1 = TAILQ_NEXT(np1, entries);
185 np2 = TAILQ_NEXT(np2, entries);
186 }
187
188 if (np1 || np2)
189 return false;
190
191 return true;
192}
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:810
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:798
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:327
bool mutt_param_cmp_strict(const struct ParameterList *pl1, const struct ParameterList *pl2)
Strictly compare two ParameterLists.
Definition: parameter.c:165
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
void mutt_param_delete(struct ParameterList *pl, const char *attribute)
Delete a matching Parameter.
Definition: parameter.c:142
void mutt_param_set(struct ParameterList *pl, const char *attribute, const char *value)
Set a Parameter.
Definition: parameter.c:110
void mutt_param_free_one(struct Parameter **p)
Free a Parameter.
Definition: parameter.c:48
void mutt_param_free(struct ParameterList *pl)
Free a ParameterList.
Definition: parameter.c:61
struct Parameter * mutt_param_new(void)
Create a new Parameter.
Definition: parameter.c:39
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