From: Pierre Habouzit Date: Wed, 28 Nov 2007 19:14:37 +0000 (+0100) Subject: tmp X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=refs%2Fheads%2Ftry-some-d;p=apps%2Fmadmutt.git tmp Signed-off-by: Pierre Habouzit --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a37c4cb..709050e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -268,7 +268,7 @@ SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Wsign-compare") SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Wunused") SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Wno-unused-parameter") # warn about variable use before initialization -SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Wuninitialized") +SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Wno-uninitialized") # let's read GPGME's Reference Manual SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64") # }}} diff --git a/lib-mime/CMakeLists.txt b/lib-mime/CMakeLists.txt index 2f4be7d..e08b55c 100644 --- a/lib-mime/CMakeLists.txt +++ b/lib-mime/CMakeLists.txt @@ -20,6 +20,8 @@ MADMUTT_SOURCES(libmimesrc libmimegen rfc2047.c rfc2231.c rfc3676.c + + parameter.d ) ADD_LIBRARY(mime ${libmimesrc}) diff --git a/lib-mime/mime-types.h b/lib-mime/mime-types.h index ac99d87..179e7b2 100644 --- a/lib-mime/mime-types.h +++ b/lib-mime/mime-types.h @@ -89,28 +89,20 @@ DO_SLIST(address_t, address, address_delete); /* rfc822 header parameters */ /****************************************************************************/ -typedef struct parameter_t { - struct parameter_t *next; - char *attribute; - char *value; -} parameter_t; - -DO_INIT(parameter_t, parameter); -static inline void parameter_wipe(parameter_t *param) { - p_delete(¶m->attribute); - p_delete(¶m->value); -} +typedef struct parameters_t parameters_t; -DO_NEW(parameter_t, parameter); -DO_DELETE(parameter_t, parameter); -DO_SLIST(parameter_t, parameter, parameter_delete); +parameters_t *parameter_new(); +parameters_t *parameter_dup(parameters_t *); +char *parameter_getval(parameters_t *, const char *); +void parameter_setval(parameters_t *, const char *, const char *); +void parameter_delval(parameters_t * p, const char *); +void parameter_set_boundary(parameters_t *); +void parameter_purge_empty(parameters_t *); -char *parameter_getval(parameter_t *, const char *); -void parameter_setval(parameter_t **, const char *, const char *); -void parameter_delval(parameter_t ** p, const char *); -void parameter_set_boundary(parameter_t **); +int parameter_equal(const parameters_t *, const parameters_t *); -int parameter_equal(const parameter_t *, const parameter_t *); +void parameter_foreach(const parameters_t *, + void (*f)(const char *, const char *)); /****************************************************************************/ /* rfc822 envelopes */ @@ -175,7 +167,7 @@ typedef struct body { char *xtype; /* content-type if x-unknown */ char *subtype; /* content-type subtype */ - parameter_t *parameter; /* parameters of the content-type */ + parameters_t *parameter; /* parameters of the content-type */ char *description; /* content-description */ char *form_name; /* Content-Disposition form-data name param */ off_t hdr_offset; /* offset in stream where the headers begin. diff --git a/lib-mime/mime.cpkg b/lib-mime/mime.cpkg index c128636..b936a4c 100644 --- a/lib-mime/mime.cpkg +++ b/lib-mime/mime.cpkg @@ -185,86 +185,6 @@ static char *mailcap_init(void) }; }; -/****************************************************************************/ -/* rfc822 header parameters */ -/****************************************************************************/ - -char *parameter_getval(parameter_t *parm, const char *s) -{ - while (parm) { - if (!ascii_strcasecmp(parm->attribute, s)) - return parm->value; - parm = parm->next; - } - return NULL; -} - -void parameter_setval(parameter_t **p, const char *attribute, const char *value) -{ - while (*p) { - if (!ascii_strcasecmp(attribute, (*p)->attribute)) { - if (value) { - m_strreplace(&(*p)->value, value); - } else { - parameter_t *q = parameter_list_pop(p); - parameter_delete(&q); - } - return; - } - p = &(*p)->next; - } - - if (value) { - (*p) = parameter_new(); - (*p)->attribute = m_strdup(attribute); - (*p)->value = m_strdup(value); - } -} - -void parameter_delval(parameter_t **p, const char *attribute) -{ - while (*p) { - if (!ascii_strcasecmp(attribute, (*p)->attribute)) { - parameter_t *q = parameter_list_pop(p); - parameter_delete(&q); - return; - } - - p = &(*p)->next; - } -} - -int parameter_equal(const parameter_t *p1, const parameter_t *p2) -{ - while (p1 && p2) { - if (m_strcmp(p1->attribute, p2->attribute) - || m_strcmp(p1->value, p2->value)) - return 0; - - p1 = p1->next; - p2 = p2->next; - } - - if (p1 || p2) - return 0; - - return 1; -} - -void parameter_set_boundary(parameter_t **parm) -{ - char rs[BOUNDARYLEN + 1]; - int i; - - for (i = 0; i < BOUNDARYLEN; i++) { - rs[i] = __m_b64chars[lrand48() % sizeof(__m_b64chars)]; - } - rs[BOUNDARYLEN] = '\0'; - - parameter_setval(parm, "boundary", rs); -} - - /****************************************************************************/ /* XXX */ /****************************************************************************/ @@ -297,9 +217,7 @@ void envelope_wipe(ENVELOPE *p) void body_wipe(BODY *b) { - if (b->parameter) - parameter_list_wipe(&b->parameter); - + b->parameter = NULL; if (b->unlink && b->filename) { unlink (b->filename); } diff --git a/lib-mime/mime.h b/lib-mime/mime.h index 297576e..8eb31b8 100644 --- a/lib-mime/mime.h +++ b/lib-mime/mime.h @@ -157,6 +157,6 @@ void rfc2047_decode_envelope(ENVELOPE* e); /****************************************************************************/ int rfc2231_encode_string(char **); -void rfc2231_decode_parameters(parameter_t **); +void rfc2231_decode_parameters(parameters_t *); #endif /* MUTT_LIB_MIME_MIME_H */ diff --git a/lib-mime/parameter.d b/lib-mime/parameter.d new file mode 100644 index 0000000..bb992d4 --- /dev/null +++ b/lib-mime/parameter.d @@ -0,0 +1,99 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ +/* + * Copyright © 2006 Pierre Habouzit + */ + +import std.c.string; +import std.string; +import std.random; + +extern(C) char *strdup(char*); +extern(C) char __m_b64chars[64]; + +alias char*[char[]]* parameters_t; + +extern(C): + +parameters_t *parameter_new() { + return new parameters_t; +} + +parameters_t *parameter_dup(parameters_t *orig) +{ + parameters_t *res = new parameters_t; + foreach (k, v; **orig) { + (**res)[k] = v; + } + return res; +} + +void parameter_foreach(parameters_t *parms, void (*f)(char *, char *)) +{ + foreach (k, v; **parms) { + f(toStringz(k), v); + } +} + +char *parameter_getval(parameters_t *parms, char *name) +{ + return (**parms)[name[0..strlen(name)]]; +} + +void parameter_setval(parameters_t *parms, char *attribute, char *value) +{ + ulong len = strlen(attribute); + if (len > 0) + (**parms)[attribute[0..len]] = strdup(value); +} + +void parameter_delval(parameters_t *parms, char *attribute) +{ + (**parms).remove(attribute[0..strlen(attribute)]); +} + +bool parameter_equal(parameters_t *p1, parameters_t *p2) +{ + if ((**p1).length != (**p2).length) + return false; + + foreach (k, v; **p1) { + if (k in **p2) { + if (strcmp(v, (**p2)[k])) + return false; + } + } + return true; +} + +void parameter_purge_empty(parameters_t *parms) +{ + foreach (k, v; **parms) { + if (!v || !strlen(v)) + (**parms).remove(k); + } +} + +void parameter_set_boundary(parameters_t *parms) +{ + char rs[17]; + for (int i = 0; i < rs.length - 1; i++) { + rs[i] = __m_b64chars[rand() % 64]; + } + rs[16] = '\0'; + parameter_setval(parms, cast(char*)"boundary", &rs[0]); +} diff --git a/lib-mime/rfc2231.c b/lib-mime/rfc2231.c index 27c9c0e..760bf11 100644 --- a/lib-mime/rfc2231.c +++ b/lib-mime/rfc2231.c @@ -128,24 +128,10 @@ rfc2231_list_insert(rfc2231_param **list, rfc2231_param *par) *list = par; } -static void purge_empty_parameters(parameter_t **headp) -{ - while (*headp) { - parameter_t *p = *headp; - - if (!p->attribute || !p->value) { - p = parameter_list_pop(headp); - parameter_delete(&p); - } else { - headp = &(*headp)->next; - } - } -} - /* process continuation parameters */ /* XXX: MC: not read */ static void -rfc2231_join_continuations(parameter_t **head, rfc2231_param *par) +rfc2231_join_continuations(parameters_t *head, rfc2231_param *par) { rfc2231_param *q; @@ -158,7 +144,6 @@ rfc2231_join_continuations(parameter_t **head, rfc2231_param *par) size_t l, vl; while (par) { - value = NULL; l = 0; m_strcpy(attribute, sizeof(attribute), par->attribute); @@ -184,15 +169,13 @@ rfc2231_join_continuations(parameter_t **head, rfc2231_param *par) valp = par->value; } while (par && !m_strcmp(par->attribute, attribute)); - if (value) { - if (encoded) - mutt_convert_string (&value, charset, mod_cset.charset, M_ICONV_HOOK_FROM); - *head = parameter_new(); - (*head)->attribute = m_strdup(attribute); - (*head)->value = value; - head = &(*head)->next; - } + if (!value) + continue; + if (encoded) + mutt_convert_string (&value, charset, mod_cset.charset, M_ICONV_HOOK_FROM); + parameter_setval(head, attribute, value); } + p_delete(&value); } /****************************************************************************/ @@ -200,8 +183,9 @@ rfc2231_join_continuations(parameter_t **head, rfc2231_param *par) /****************************************************************************/ /* XXX: MC: not read */ -void rfc2231_decode_parameters (parameter_t ** headp) +void rfc2231_decode_parameters(parameters_t *headp) { +#if 0 parameter_t *head = NULL; parameter_t **last; parameter_t *p, *q; @@ -219,7 +203,7 @@ void rfc2231_decode_parameters (parameter_t ** headp) if (!headp) return; - purge_empty_parameters (headp); + parameter_purge_empty(headp); for (last = &head, p = *headp; p; p = q) { q = p->next; @@ -288,7 +272,8 @@ void rfc2231_decode_parameters (parameter_t ** headp) *headp = head; if (dirty) - purge_empty_parameters (headp); + parameter_purge_empty(headp); +#endif } #define RFC2231_SPECIALS "@.,;:<>[]\\\"()?/= \t*'%" diff --git a/lib-mime/rfc822parse.c b/lib-mime/rfc822parse.c index 49e806d..121efb1 100644 --- a/lib-mime/rfc822parse.c +++ b/lib-mime/rfc822parse.c @@ -188,14 +188,13 @@ int mutt_check_mime_type(const char *s) } } -static parameter_t *parse_parameters(const char *s) +static parameters_t *parse_parameters(const char *s) { - parameter_t *res = NULL; - parameter_t **list = &res; + parameters_t *res = parameter_new(); while (*s) { + char *attr, *val; const char *p; - parameter_t *new; int i; s = skipspaces(s); @@ -213,11 +212,10 @@ static parameter_t *parse_parameters(const char *s) } i = p - s; - new = parameter_new(); - new->attribute = p_dupstr(s, i); + attr = p_dupstr(s, i); - while (--i >= 0 && ISSPACE(new->attribute[i])) { - new->attribute[i] = '\0'; + while (--i >= 0 && ISSPACE(attr[i])) { + attr[i] = '\0'; } s = skipspaces(p + 1); /* skip over the = */ @@ -242,21 +240,21 @@ static parameter_t *parse_parameters(const char *s) } } - new->value = p_dupstr(buffer, i); + val = p_dupstr(buffer, i); } else { for (p = s; *p && *p != ' ' && *p != ';'; p++); - new->value = p_dupstr(s, p - s); + val = p_dupstr(s, p - s); } - *list = new; - list = &new->next; - + parameter_setval(res, attr, val); + p_delete(&attr); + p_delete(&val); s = strchr(s, ';'); /* Find the next parameter */ if (!s) break; /* no more parameters */ } - rfc2231_decode_parameters(&res); + rfc2231_decode_parameters(res); return res; } @@ -266,7 +264,7 @@ void mutt_parse_content_type(char *s, BODY *ct) char *subtype; p_delete(&ct->subtype); - parameter_list_wipe(&ct->parameter); + ct->parameter = NULL; /* First extract any existing parameters */ if ((pc = strchr(s, ';')) != NULL) { @@ -330,7 +328,7 @@ void mutt_parse_content_type(char *s, BODY *ct) if (ct->type == TYPETEXT) { pc = parameter_getval(ct->parameter, "charset"); if (!pc) { - parameter_setval(&ct->parameter, "charset", + parameter_setval(ct->parameter, "charset", charset_getfirst(mod_cset.assumed_charset)); } } @@ -348,14 +346,12 @@ static void parse_content_disposition(const char *s, BODY *ct) /* Check to see if a default filename was given */ if ((s = strchr (s, ';'))) { - parameter_t *parms = parse_parameters(vskipspaces(s)); + parameters_t *parms = parse_parameters(vskipspaces(s)); if ((s = parameter_getval(parms, "filename"))) m_strreplace(&ct->filename, s); if ((s = parameter_getval(parms, "name"))) ct->form_name = m_strdup(s); - - parameter_list_wipe(&parms); } } diff --git a/lib-mx/hcache.c b/lib-mx/hcache.c index 01db5bd..de0e3e0 100644 --- a/lib-mx/hcache.c +++ b/lib-mx/hcache.c @@ -187,8 +187,9 @@ static const void *restore_list(const char *d, string_list_t **l) return d; } -static void dump_parameter(buffer_t *buf, parameter_t *p) +static void dump_parameter(buffer_t *buf, parameters_t *p) { +#if 0 int pos = buf->len, counter = 0; dump_int(buf, counter); @@ -199,22 +200,24 @@ static void dump_parameter(buffer_t *buf, parameter_t *p) } memcpy(buf->data + pos, &counter, sizeof(counter)); +#endif } -static const void *restore_parameter(const char *d, parameter_t ** p) +static const void *restore_parameter(const char *d, parameters_t *p) { int counter; d = restore_int(d, &counter); for (; counter > 0; counter--) { - *p = parameter_new(); - d = restore_cstr(d, &(*p)->attribute); - d = restore_cstr(d, &(*p)->value); - p = &(*p)->next; + char *k, *v; + d = restore_cstr(d, &k); + d = restore_cstr(d, &v); + parameter_setval(p, k, v); + p_delete(&k); + p_delete(&v); } - *p = NULL; return d; } @@ -240,7 +243,7 @@ static const void *restore_body(const char *d, BODY *c) d = restore_cstr(d, &c->xtype); d = restore_cstr(d, &c->subtype); - d = restore_parameter(d, &c->parameter); + d = restore_parameter(d, c->parameter); d = restore_cstr(d, &c->description); d = restore_cstr(d, &c->form_name); @@ -341,6 +344,7 @@ HEADER *mutt_hcache_restore(const void *_d, HEADER **oh) d = restore_envelope(d, h->env); h->content = body_new(); + h->content->parameter = parameter_new(); d = restore_body(d, h->content); d = restore_cstr(d, &h->maildir_flags);