NeoMutt  2024-04-25-89-g194907
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
parameter.h File Reference

Store attributes associated with a MIME part. More...

#include <stdbool.h>
#include "mutt/lib.h"
+ Include dependency graph for parameter.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Parameter
 Attribute associated with a MIME part. More...
 

Functions

 TAILQ_HEAD (ParameterList, Parameter)
 
bool mutt_param_cmp_strict (const struct ParameterList *pl1, const struct ParameterList *pl2)
 Strictly compare two ParameterLists.
 
void mutt_param_delete (struct ParameterList *pl, const char *attribute)
 Delete a matching Parameter.
 
void mutt_param_free (struct ParameterList *pl)
 Free a ParameterList.
 
void mutt_param_free_one (struct Parameter **pl)
 Free a Parameter.
 
char * mutt_param_get (const struct ParameterList *pl, const char *s)
 Find a matching Parameter.
 
struct Parametermutt_param_new (void)
 Create a new Parameter.
 
void mutt_param_set (struct ParameterList *pl, const char *attribute, const char *value)
 Set a Parameter.
 

Detailed Description

Store attributes associated with a MIME part.

Authors
  • Richard Russon

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 parameter.h.

Function Documentation

◆ TAILQ_HEAD()

TAILQ_HEAD ( ParameterList  ,
Parameter   
)

◆ mutt_param_cmp_strict()

bool mutt_param_cmp_strict ( const struct ParameterList *  pl1,
const struct ParameterList *  pl2 
)

Strictly compare two ParameterLists.

Parameters
pl1First parameter
pl2Second parameter
Return values
trueParameters are strictly identical

Definition at line 166 of file parameter.c.

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}
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_NEXT(elm, field)
Definition: queue.h:832
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_param_delete()

void mutt_param_delete ( struct ParameterList *  pl,
const char *  attribute 
)

Delete a matching Parameter.

Parameters
[in]plParameterList
[in]attributeAttribute to match

Definition at line 143 of file parameter.c.

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}
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:672
void mutt_param_free_one(struct Parameter **p)
Free a Parameter.
Definition: parameter.c:49
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:841
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_param_free()

void mutt_param_free ( struct ParameterList *  pl)

Free a ParameterList.

Parameters
plParameterList to free

Definition at line 62 of file parameter.c.

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}
#define TAILQ_INIT(head)
Definition: queue.h:765
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_param_free_one()

void mutt_param_free_one ( struct Parameter **  p)

Free a Parameter.

Parameters
[out]pParameter to free

Definition at line 49 of file parameter.c.

50{
51 if (!p || !*p)
52 return;
53 FREE(&(*p)->attribute);
54 FREE(&(*p)->value);
55 FREE(p);
56}
#define FREE(x)
Definition: memory.h:45
+ Here is the caller graph for this function:

◆ mutt_param_get()

char * mutt_param_get ( const struct ParameterList *  pl,
const char *  s 
)

Find a matching Parameter.

Parameters
plParameterList
sString to match
Return values
ptrMatching Parameter
NULLNo match

Definition at line 85 of file parameter.c.

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}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_param_new()

struct Parameter * mutt_param_new ( void  )

Create a new Parameter.

Return values
ptrNewly allocated Parameter

Definition at line 40 of file parameter.c.

41{
42 return mutt_mem_calloc(1, sizeof(struct Parameter));
43}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_param_set()

void mutt_param_set ( struct ParameterList *  pl,
const char *  attribute,
const char *  value 
)

Set a Parameter.

Parameters
[in]plParameterList
[in]attributeAttribute to match
[in]valueValue to set
Note
If value is NULL, the Parameter will be deleted
If a matching Parameter isn't found a new one will be allocated. The new Parameter will be inserted at the front of the list.

Definition at line 111 of file parameter.c.

112{
113 if (!pl)
114 return;
115
116 if (!value)
117 {
118 mutt_param_delete(pl, attribute);
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}
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:280
void mutt_param_delete(struct ParameterList *pl, const char *attribute)
Delete a matching Parameter.
Definition: parameter.c:143
struct Parameter * mutt_param_new(void)
Create a new Parameter.
Definition: parameter.c:40
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:796
+ Here is the call graph for this function:
+ Here is the caller graph for this function: