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")
# }}}
rfc2047.c
rfc2231.c
rfc3676.c
+
+ parameter.d
)
ADD_LIBRARY(mime ${libmimesrc})
/* 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 */
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.
};
};
-/****************************************************************************/
-/* 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 */
/****************************************************************************/
void body_wipe(BODY *b)
{
- if (b->parameter)
- parameter_list_wipe(&b->parameter);
-
+ b->parameter = NULL;
if (b->unlink && b->filename) {
unlink (b->filename);
}
/****************************************************************************/
int rfc2231_encode_string(char **);
-void rfc2231_decode_parameters(parameter_t **);
+void rfc2231_decode_parameters(parameters_t *);
#endif /* MUTT_LIB_MIME_MIME_H */
--- /dev/null
+/*
+ * 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]);
+}
*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;
size_t l, vl;
while (par) {
- value = NULL;
l = 0;
m_strcpy(attribute, sizeof(attribute), par->attribute);
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);
}
/****************************************************************************/
/****************************************************************************/
/* 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;
if (!headp)
return;
- purge_empty_parameters (headp);
+ parameter_purge_empty(headp);
for (last = &head, p = *headp; p; p = q) {
q = p->next;
*headp = head;
if (dirty)
- purge_empty_parameters (headp);
+ parameter_purge_empty(headp);
+#endif
}
#define RFC2231_SPECIALS "@.,;:<>[]\\\"()?/= \t*'%"
}
}
-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);
}
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 = */
}
}
- 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;
}
char *subtype;
p_delete(&ct->subtype);
- parameter_list_wipe(&ct->parameter);
+ ct->parameter = NULL;
/* First extract any existing parameters */
if ((pc = strchr(s, ';')) != NULL) {
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));
}
}
/* 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);
}
}
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);
}
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;
}
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);
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);