1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
24 #include <curl/curl.h>
26 #include "tool_mfiles.h"
28 #include "memdebug.h" /* keep this as LAST include */
30 static void AppendNode(struct multi_files **first,
31 struct multi_files **last,
32 struct multi_files *new)
34 DEBUGASSERT(((*first) && (*last)) || ((!*first) && (!*last)));
44 * AddMultiFiles: Add a new list node possibly followed with a type_name.
46 * multi_first argument is the address of a pointer to the first element
47 * of the multi_files linked list. A NULL pointer indicates empty list.
49 * multi_last argument is the address of a pointer to the last element
50 * of the multi_files linked list. A NULL pointer indicates empty list.
52 * Pointers stored in multi_first and multi_last are modified while
53 * function is executed. An out of memory condition free's the whole
54 * list and returns with pointers stored in multi_first and multi_last
55 * set to NULL and a NULL function result.
57 * Function returns same pointer as stored at multi_last.
60 struct multi_files *AddMultiFiles(const char *file_name,
61 const char *type_name,
62 const char *show_filename,
63 struct multi_files **multi_first,
64 struct multi_files **multi_last)
66 struct multi_files *multi;
67 struct multi_files *multi_type;
68 struct multi_files *multi_name;
70 multi = calloc(1, sizeof(struct multi_files));
72 multi->form.option = CURLFORM_FILE;
73 multi->form.value = file_name;
74 AppendNode(multi_first, multi_last, multi);
77 FreeMultiInfo(multi_first, multi_last);
82 multi_type = calloc(1, sizeof(struct multi_files));
84 multi_type->form.option = CURLFORM_CONTENTTYPE;
85 multi_type->form.value = type_name;
86 AppendNode(multi_first, multi_last, multi_type);
89 FreeMultiInfo(multi_first, multi_last);
95 multi_name = calloc(1, sizeof(struct multi_files));
97 multi_name->form.option = CURLFORM_FILENAME;
98 multi_name->form.value = show_filename;
99 AppendNode(multi_first, multi_last, multi_name);
102 FreeMultiInfo(multi_first, multi_last);
111 * FreeMultiInfo: Free the items of the list.
114 void FreeMultiInfo(struct multi_files **multi_first,
115 struct multi_files **multi_last)
117 struct multi_files *next;
118 struct multi_files *item = *multi_first;