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 "strcase.h"
00025
00026 #define ENABLE_CURLX_PRINTF
00027
00028 #include "curlx.h"
00029
00030 #include "tool_cfgable.h"
00031 #include "tool_convert.h"
00032 #include "tool_doswin.h"
00033 #include "tool_operhlp.h"
00034 #include "tool_metalink.h"
00035
00036 #include "memdebug.h"
00037
00038 void clean_getout(struct OperationConfig *config)
00039 {
00040 struct getout *next;
00041 struct getout *node = config->url_list;
00042
00043 while(node) {
00044 next = node->next;
00045 Curl_safefree(node->url);
00046 Curl_safefree(node->outfile);
00047 Curl_safefree(node->infile);
00048 Curl_safefree(node);
00049 node = next;
00050 }
00051 config->url_list = NULL;
00052 }
00053
00054 bool output_expected(const char *url, const char *uploadfile)
00055 {
00056 if(!uploadfile)
00057 return TRUE;
00058 if(checkprefix("http://", url) || checkprefix("https://", url))
00059 return TRUE;
00060
00061 return FALSE;
00062 }
00063
00064 bool stdin_upload(const char *uploadfile)
00065 {
00066 return (!strcmp(uploadfile, "-") ||
00067 !strcmp(uploadfile, ".")) ? TRUE : FALSE;
00068 }
00069
00070
00071
00072
00073
00074 char *add_file_name_to_url(CURL *curl, char *url, const char *filename)
00075 {
00076
00077 char *ptr = strstr(url, "://");
00078 if(ptr)
00079 ptr += 3;
00080 else
00081 ptr = url;
00082 ptr = strrchr(ptr, '/');
00083 if(!ptr || !strlen(++ptr)) {
00084
00085
00086
00087
00088
00089
00090 const char *filep = strrchr(filename, '/');
00091 char *file2 = strrchr(filep?filep:filename, '\\');
00092 char *encfile;
00093
00094 if(file2)
00095 filep = file2 + 1;
00096 else if(filep)
00097 filep++;
00098 else
00099 filep = filename;
00100
00101
00102 encfile = curl_easy_escape(curl, filep, 0 );
00103 if(encfile) {
00104 char *urlbuffer;
00105 if(ptr)
00106
00107 urlbuffer = aprintf("%s%s", url, encfile);
00108 else
00109
00110 urlbuffer = aprintf("%s/%s", url, encfile);
00111
00112 curl_free(encfile);
00113 Curl_safefree(url);
00114
00115 if(!urlbuffer)
00116 return NULL;
00117
00118 url = urlbuffer;
00119 }
00120 else
00121 Curl_safefree(url);
00122 }
00123 return url;
00124 }
00125
00126
00127
00128
00129
00130 CURLcode get_url_file_name(char **filename, const char *url)
00131 {
00132 const char *pc, *pc2;
00133
00134 *filename = NULL;
00135
00136
00137 pc = strstr(url, "://");
00138 if(pc)
00139 pc += 3;
00140 else
00141 pc = url;
00142
00143 pc2 = strrchr(pc, '\\');
00144 pc = strrchr(pc, '/');
00145 if(pc2 && (!pc || pc < pc2))
00146 pc = pc2;
00147
00148 if(pc)
00149
00150 pc++;
00151 else
00152
00153 pc = "";
00154
00155 *filename = strdup(pc);
00156 if(!*filename)
00157 return CURLE_OUT_OF_MEMORY;
00158
00159 #if defined(MSDOS) || defined(WIN32)
00160 {
00161 char *sanitized;
00162 SANITIZEcode sc = sanitize_file_name(&sanitized, *filename, 0);
00163 Curl_safefree(*filename);
00164 if(sc)
00165 return CURLE_URL_MALFORMAT;
00166 *filename = sanitized;
00167 }
00168 #endif
00169
00170
00171
00172
00173
00174 #ifdef DEBUGBUILD
00175 {
00176 char *tdir = curlx_getenv("CURL_TESTDIR");
00177 if(tdir) {
00178 char buffer[512];
00179 snprintf(buffer, sizeof(buffer), "%s/%s", tdir, *filename);
00180 Curl_safefree(*filename);
00181 *filename = strdup(buffer);
00182 curl_free(tdir);
00183 if(!*filename)
00184 return CURLE_OUT_OF_MEMORY;
00185 }
00186 }
00187 #endif
00188
00189 return CURLE_OK;
00190 }