Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "tool_setup.h"
00023
00024 #include "tool_mfiles.h"
00025
00026 #include "memdebug.h"
00027
00028 static void AppendNode(struct multi_files **first,
00029 struct multi_files **last,
00030 struct multi_files *new)
00031 {
00032 DEBUGASSERT(((*first) && (*last)) || ((!*first) && (!*last)));
00033
00034 if(*last)
00035 (*last)->next = new;
00036 else
00037 *first = new;
00038 *last = new;
00039 }
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 struct multi_files *AddMultiFiles(const char *file_name,
00059 const char *type_name,
00060 const char *show_filename,
00061 struct multi_files **multi_first,
00062 struct multi_files **multi_last)
00063 {
00064 struct multi_files *multi;
00065 struct multi_files *multi_type;
00066 struct multi_files *multi_name;
00067
00068 multi = calloc(1, sizeof(struct multi_files));
00069 if(multi) {
00070 multi->form.option = CURLFORM_FILE;
00071 multi->form.value = file_name;
00072 AppendNode(multi_first, multi_last, multi);
00073 }
00074 else {
00075 FreeMultiInfo(multi_first, multi_last);
00076 return NULL;
00077 }
00078
00079 if(type_name) {
00080 multi_type = calloc(1, sizeof(struct multi_files));
00081 if(multi_type) {
00082 multi_type->form.option = CURLFORM_CONTENTTYPE;
00083 multi_type->form.value = type_name;
00084 AppendNode(multi_first, multi_last, multi_type);
00085 }
00086 else {
00087 FreeMultiInfo(multi_first, multi_last);
00088 return NULL;
00089 }
00090 }
00091
00092 if(show_filename) {
00093 multi_name = calloc(1, sizeof(struct multi_files));
00094 if(multi_name) {
00095 multi_name->form.option = CURLFORM_FILENAME;
00096 multi_name->form.value = show_filename;
00097 AppendNode(multi_first, multi_last, multi_name);
00098 }
00099 else {
00100 FreeMultiInfo(multi_first, multi_last);
00101 return NULL;
00102 }
00103 }
00104
00105 return *multi_last;
00106 }
00107
00108
00109
00110
00111
00112 void FreeMultiInfo(struct multi_files **multi_first,
00113 struct multi_files **multi_last)
00114 {
00115 struct multi_files *next;
00116 struct multi_files *item = *multi_first;
00117
00118 while(item) {
00119 next = item->next;
00120 Curl_safefree(item);
00121 item = next;
00122 }
00123 *multi_first = NULL;
00124 if(multi_last)
00125 *multi_last = NULL;
00126 }
00127