2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 * Copyright © 2006 Pierre Habouzit
25 extern(C) char *strdup(char*);
26 extern(C) char __m_b64chars[64];
28 alias char*[char[]]* parameters_t;
32 parameters_t *parameter_new() {
33 return new parameters_t;
36 parameters_t *parameter_dup(parameters_t *orig)
38 parameters_t *res = new parameters_t;
39 foreach (k, v; **orig) {
45 void parameter_foreach(parameters_t *parms, void (*f)(char *, char *))
47 foreach (k, v; **parms) {
52 char *parameter_getval(parameters_t *parms, char *name)
54 return (**parms)[name[0..strlen(name)]];
57 void parameter_setval(parameters_t *parms, char *attribute, char *value)
59 ulong len = strlen(attribute);
61 (**parms)[attribute[0..len]] = strdup(value);
64 void parameter_delval(parameters_t *parms, char *attribute)
66 (**parms).remove(attribute[0..strlen(attribute)]);
69 bool parameter_equal(parameters_t *p1, parameters_t *p2)
71 if ((**p1).length != (**p2).length)
74 foreach (k, v; **p1) {
76 if (strcmp(v, (**p2)[k]))
83 void parameter_purge_empty(parameters_t *parms)
85 foreach (k, v; **parms) {
91 void parameter_set_boundary(parameters_t *parms)
94 for (int i = 0; i < rs.length - 1; i++) {
95 rs[i] = __m_b64chars[rand() % 64];
98 parameter_setval(parms, cast(char*)"boundary", &rs[0]);