From a7781c07c78044b6039daa050a2eab79ca22d4a9 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Tue, 28 Nov 2017 20:42:22 +0000 Subject: [PATCH] move parameter functions --- body.c | 2 +- mbox.c | 27 +-------------------------- parameter.c | 36 +++++++++++++++++++++++++++++++++++- parameter.h | 19 ++++++------------- parse.c | 2 +- rfc2231.c | 2 +- 6 files changed, 45 insertions(+), 43 deletions(-) diff --git a/body.c b/body.c index 303dbfbb5..7acc19ceb 100644 --- a/body.c +++ b/body.c @@ -107,7 +107,7 @@ int mutt_copy_body(FILE *fp, struct Body **tgt, struct Body *src) /* copy parameters */ for (par = b->parameter, ppar = &b->parameter; par; ppar = &(*ppar)->next, par = par->next) { - *ppar = mutt_new_parameter(); + *ppar = mutt_param_new(); (*ppar)->attribute = mutt_str_strdup(par->attribute); (*ppar)->value = mutt_str_strdup(par->value); } diff --git a/mbox.c b/mbox.c index cad3bd3b2..efe5d1250 100644 --- a/mbox.c +++ b/mbox.c @@ -552,37 +552,12 @@ static int mbox_open_new_message(struct Message *msg, struct Context *dest, stru return 0; } -/** - * strict_cmp_parameters - strictly compare two parameters - * @param p1 first parameter - * @param p2 second parameter - * @retval true parameters are strictly identical - */ -static int strict_cmp_parameters(const struct Parameter *p1, const struct Parameter *p2) -{ - while (p1 && p2) - { - if ((mutt_str_strcmp(p1->attribute, p2->attribute) != 0) || - (mutt_str_strcmp(p1->value, p2->value) != 0)) - { - return 0; - } - - p1 = p1->next; - p2 = p2->next; - } - if (p1 || p2) - return 0; - - return 1; -} - static int strict_cmp_bodies(const struct Body *b1, const struct Body *b2) { if (b1->type != b2->type || b1->encoding != b2->encoding || (mutt_str_strcmp(b1->subtype, b2->subtype) != 0) || (mutt_str_strcmp(b1->description, b2->description) != 0) || - !strict_cmp_parameters(b1->parameter, b2->parameter) || b1->length != b2->length) + !mutt_param_cmp_strict(b1->parameter, b2->parameter) || b1->length != b2->length) return 0; return 1; } diff --git a/parameter.c b/parameter.c index c8411a65b..086661a60 100644 --- a/parameter.c +++ b/parameter.c @@ -36,6 +36,15 @@ #include "config.h" #include "parameter.h" +/** + * mutt_param_new - Create a new Parameter + * @retval ptr Newly allocated Parameter + */ +struct Parameter *mutt_param_new(void) +{ + return mutt_mem_calloc(1, sizeof(struct Parameter)); +} + /** * mutt_param_free - Free a Parameter * @param p Parameter to free @@ -102,7 +111,7 @@ void mutt_param_set(const char *attribute, const char *value, struct Parameter * } } - q = mutt_new_parameter(); + q = mutt_param_new(); q->attribute = mutt_str_strdup(attribute); q->value = mutt_str_strdup(value); q->next = *p; @@ -127,3 +136,28 @@ void mutt_param_delete(const char *attribute, struct Parameter **p) } } } + +/** + * mutt_param_cmp_strict - strictly compare two parameters + * @param p1 first parameter + * @param p2 second parameter + * @retval true parameters are strictly identical + */ +int mutt_param_cmp_strict(const struct Parameter *p1, const struct Parameter *p2) +{ + while (p1 && p2) + { + if ((mutt_str_strcmp(p1->attribute, p2->attribute) != 0) || + (mutt_str_strcmp(p1->value, p2->value) != 0)) + { + return 0; + } + + p1 = p1->next; + p2 = p2->next; + } + if (p1 || p2) + return 0; + + return 1; +} diff --git a/parameter.h b/parameter.h index 49486e247..c2e86068c 100644 --- a/parameter.h +++ b/parameter.h @@ -35,18 +35,11 @@ struct Parameter struct Parameter *next; }; -/** - * mutt_new_parameter - Create a new Parameter - * @retval ptr Newly allocated Parameter - */ -static inline struct Parameter *mutt_new_parameter(void) -{ - return mutt_mem_calloc(1, sizeof(struct Parameter)); -} - -void mutt_param_delete(const char *attribute, struct Parameter **p); -void mutt_param_set(const char *attribute, const char *value, struct Parameter **p); -void mutt_param_free(struct Parameter **p); -char *mutt_param_get(const char *s, struct Parameter *p); +struct Parameter *mutt_param_new(void); +int mutt_param_cmp_strict(const struct Parameter *p1, const struct Parameter *p2); +void mutt_param_delete(const char *attribute, struct Parameter **p); +void mutt_param_free(struct Parameter **p); +char * mutt_param_get(const char *s, struct Parameter *p); +void mutt_param_set(const char *attribute, const char *value, struct Parameter **p); #endif /* _MUTT_PARAMETER_H */ diff --git a/parse.c b/parse.c index 7a07e88a3..612105740 100644 --- a/parse.c +++ b/parse.c @@ -187,7 +187,7 @@ static struct Parameter *parse_parameters(const char *s) } else { - new = mutt_new_parameter(); + new = mutt_param_new(); new->attribute = mutt_str_substr_dup(s, s + i); } diff --git a/rfc2231.c b/rfc2231.c index db1503269..6f8b445b7 100644 --- a/rfc2231.c +++ b/rfc2231.c @@ -201,7 +201,7 @@ static void rfc2231_join_continuations(struct Parameter **head, struct Rfc2231Pa if (encoded) mutt_convert_string(&value, charset, Charset, MUTT_ICONV_HOOK_FROM); - *head = mutt_new_parameter(); + *head = mutt_param_new(); (*head)->attribute = mutt_str_strdup(attribute); (*head)->value = value; head = &(*head)->next; -- 2.40.0