NeoMutt  2018-07-16 +2481-68dcde
Teaching an old dog new tricks
DOXYGEN
parameter.c File Reference

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

#include "config.h"
#include <stddef.h>
#include <stdbool.h>
#include "mutt/mutt.h"
#include "parameter.h"
+ Include dependency graph for parameter.c:

Go to the source code of this file.

Functions

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

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

Function Documentation

◆ mutt_param_new()

struct Parameter* mutt_param_new ( void  )

Create a new Parameter.

Return values
ptrNewly allocated Parameter

Definition at line 39 of file parameter.c.

40 {
41  return mutt_mem_calloc(1, sizeof(struct Parameter));
42 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
Attribute associated with a MIME part.
Definition: parameter.h:32
+ 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 48 of file parameter.c.

49 {
50  if (!p || !*p)
51  return;
52  FREE(&(*p)->attribute);
53  FREE(&(*p)->value);
54  FREE(p);
55 }
#define FREE(x)
Definition: memory.h:40
+ 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 61 of file parameter.c.

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 }
#define TAILQ_FIRST(head)
Definition: queue.h:717
#define TAILQ_INIT(head)
Definition: queue.h:759
void mutt_param_free_one(struct Parameter **p)
Free a Parameter.
Definition: parameter.c:48
Attribute associated with a MIME part.
Definition: parameter.h:32
#define TAILQ_NEXT(elm, field)
Definition: queue.h:816
+ Here is the call graph for this function:
+ 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 84 of file parameter.c.

85 {
86  if (!pl)
87  return NULL;
88 
89  struct Parameter *np = NULL;
90  TAILQ_FOREACH(np, pl, entries)
91  {
92  if (mutt_str_strcasecmp(s, np->attribute) == 0)
93  return np->value;
94  }
95 
96  return NULL;
97 }
char * attribute
Parameter name.
Definition: parameter.h:34
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
char * value
Parameter value.
Definition: parameter.h:35
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
Attribute associated with a MIME part.
Definition: parameter.h:32
+ 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 110 of file parameter.c.

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  {
124  if (mutt_str_strcasecmp(attribute, np->attribute) == 0)
125  {
127  return;
128  }
129  }
130 
131  np = mutt_param_new();
133  np->value = mutt_str_strdup(value);
134  TAILQ_INSERT_HEAD(pl, np, entries);
135 }
char * attribute
Parameter name.
Definition: parameter.h:34
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
struct Parameter * mutt_param_new(void)
Create a new Parameter.
Definition: parameter.c:39
void mutt_param_delete(struct ParameterList *pl, const char *attribute)
Delete a matching Parameter.
Definition: parameter.c:142
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:453
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:790
char * value
Parameter value.
Definition: parameter.h:35
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
Attribute associated with a MIME part.
Definition: parameter.h:32
+ 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 142 of file parameter.c.

143 {
144  if (!pl)
145  return;
146 
147  struct Parameter *np = NULL;
148  TAILQ_FOREACH(np, pl, entries)
149  {
150  if (mutt_str_strcasecmp(attribute, np->attribute) == 0)
151  {
152  TAILQ_REMOVE(pl, np, entries);
153  mutt_param_free_one(&np);
154  return;
155  }
156  }
157 }
char * attribute
Parameter name.
Definition: parameter.h:34
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:719
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:821
void mutt_param_free_one(struct Parameter **p)
Free a Parameter.
Definition: parameter.c:48
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:628
Attribute associated with a MIME part.
Definition: parameter.h:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 165 of file parameter.c.

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_strcmp(np1->attribute, np2->attribute) != 0) ||
179  (mutt_str_strcmp(np1->value, np2->value) != 0))
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 }
char * attribute
Parameter name.
Definition: parameter.h:34
#define TAILQ_FIRST(head)
Definition: queue.h:717
char * value
Parameter value.
Definition: parameter.h:35
Attribute associated with a MIME part.
Definition: parameter.h:32
#define TAILQ_NEXT(elm, field)
Definition: queue.h:816
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
+ Here is the call graph for this function:
+ Here is the caller graph for this function: