tool_mfiles.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "tool_setup.h"
00023 
00024 #include "tool_mfiles.h"
00025 
00026 #include "memdebug.h" /* keep this as LAST include */
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  * AddMultiFiles: Add a new list node possibly followed with a type_name.
00043  *
00044  * multi_first argument is the address of a pointer to the first element
00045  * of the multi_files linked list. A NULL pointer indicates empty list.
00046  *
00047  * multi_last argument is the address of a pointer to the last element
00048  * of the multi_files linked list. A NULL pointer indicates empty list.
00049  *
00050  * Pointers stored in multi_first and multi_last are modified while
00051  * function is executed. An out of memory condition free's the whole
00052  * list and returns with pointers stored in multi_first and multi_last
00053  * set to NULL and a NULL function result.
00054  *
00055  * Function returns same pointer as stored at multi_last.
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  * FreeMultiInfo: Free the items of the list.
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 


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:07