1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2012, 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 https://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 ***************************************************************************/
22 #include "tool_setup.h"
24 #include "tool_mfiles.h"
26 #include "memdebug.h" /* keep this as LAST include */
28 static void AppendNode(struct multi_files **first,
29 struct multi_files **last,
30 struct multi_files *new)
32 DEBUGASSERT(((*first) && (*last)) || ((!*first) && (!*last)));
42 * AddMultiFiles: Add a new list node possibly followed with a type_name.
44 * multi_first argument is the address of a pointer to the first element
45 * of the multi_files linked list. A NULL pointer indicates empty list.
47 * multi_last argument is the address of a pointer to the last element
48 * of the multi_files linked list. A NULL pointer indicates empty list.
50 * Pointers stored in multi_first and multi_last are modified while
51 * function is executed. An out of memory condition free's the whole
52 * list and returns with pointers stored in multi_first and multi_last
53 * set to NULL and a NULL function result.
55 * Function returns same pointer as stored at multi_last.
58 struct multi_files *AddMultiFiles(const char *file_name,
59 const char *type_name,
60 const char *show_filename,
61 struct multi_files **multi_first,
62 struct multi_files **multi_last)
64 struct multi_files *multi;
65 struct multi_files *multi_type;
66 struct multi_files *multi_name;
68 multi = calloc(1, sizeof(struct multi_files));
70 multi->form.option = CURLFORM_FILE;
71 multi->form.value = file_name;
72 AppendNode(multi_first, multi_last, multi);
75 FreeMultiInfo(multi_first, multi_last);
80 multi_type = calloc(1, sizeof(struct multi_files));
82 multi_type->form.option = CURLFORM_CONTENTTYPE;
83 multi_type->form.value = type_name;
84 AppendNode(multi_first, multi_last, multi_type);
87 FreeMultiInfo(multi_first, multi_last);
93 multi_name = calloc(1, sizeof(struct multi_files));
95 multi_name->form.option = CURLFORM_FILENAME;
96 multi_name->form.value = show_filename;
97 AppendNode(multi_first, multi_last, multi_name);
100 FreeMultiInfo(multi_first, multi_last);
109 * FreeMultiInfo: Free the items of the list.
112 void FreeMultiInfo(struct multi_files **multi_first,
113 struct multi_files **multi_last)
115 struct multi_files *next;
116 struct multi_files *item = *multi_first;