Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
}
else {
outs.filename = config.outfile;
outs.stream = NULL; /* open when needed */
}
}
if (config.infile) {
/*
* We have specified a file to upload
*/
struct stat fileinfo;
/* If no file name part is given in the URL, we add this file name */
char *ptr=strstr(url, "://");
if(ptr)
ptr+=3;
else
ptr=url;
ptr = strrchr(ptr, '/');
if(!ptr || !strlen(++ptr)) {
/* The URL has no file name part, add the local file name. In order
to be able to do so, we have to create a new URL in another buffer.*/
urlbuffer=(char *)malloc(strlen(url) + strlen(config.infile) + 3);
if(!urlbuffer) {
helpf("out of memory\n");
return URG_OUT_OF_MEMORY;
}
if(ptr)
/* there is a trailing slash on the URL */
sprintf(urlbuffer, "%s%s", url, config.infile);
else
/* thers is no trailing slash on the URL */
sprintf(urlbuffer, "%s/%s", url, config.infile);
url = urlbuffer; /* use our new URL instead! */
}
infd=(FILE *) fopen(config.infile, "rb");
if (!infd || stat(config.infile, &fileinfo)) {
helpf("Can't open '%s'!\n", config.infile);
return URG_READ_ERROR;
}
infilesize=fileinfo.st_size;
}
if((config.conf&CONF_UPLOAD) &&
config.use_resume &&
(0==config.resume_from)) {
config.resume_from = -1; /* -1 will then force get-it-yourself */
}
if(config.headerfile) {
/* open file for output: */
if(strcmp(config.headerfile,"-"))
{
headerfilep=(FILE *) fopen(config.headerfile, "wb");
if (!headerfilep) {
helpf("Can't open '%s'!\n", config.headerfile);
return URG_WRITE_ERROR;
}
}
else
headerfilep=stdout;
}
Daniel Stenberg
committed
if(outs.stream && isatty(fileno(outs.stream)) &&
!(config.conf&(CONF_UPLOAD|CONF_HTTPPOST)))
/* we send the output to a tty and it isn't an upload operation, therefore
we switch off the progress meter */
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
config.conf |= CONF_NOPROGRESS;
#ifdef GLOBURL
if (urlnum > 1) {
fprintf(stderr, "\n[%d/%d]: %s --> %s\n", i+1, urlnum, url, config.outfile ? config.outfile : "<stdout>");
if (separator) {
#ifdef CURL_SEPARATORS
printf("%s%s\n", CURLseparator, url);
#endif
#ifdef MIME_SEPARATORS
printf("--%s\n", MIMEseparator);
printf("Content-ID: %s\n\n", url);
#endif
}
}
#endif
if(!config.errors)
config.errors = stderr;
res = curl_urlget(URGTAG_FILE, (FILE *)&outs, /* where to store */
URGTAG_WRITEFUNCTION, my_fwrite, /* what call to write */
URGTAG_INFILE, infd, /* for uploads */
URGTAG_INFILESIZE, infilesize, /* size of uploaded file */
URGTAG_URL, url, /* what to fetch */
URGTAG_PROXY, config.proxy, /* proxy to use */
URGTAG_FLAGS, config.conf, /* flags */
URGTAG_USERPWD, config.userpwd, /* user + passwd */
URGTAG_PROXYUSERPWD, config.proxyuserpwd, /* Proxy user + passwd */
URGTAG_RANGE, config.range, /* range of document */
URGTAG_ERRORBUFFER, errorbuffer,
URGTAG_TIMEOUT, config.timeout,
URGTAG_POSTFIELDS, config.postfields,
URGTAG_REFERER, config.referer,
URGTAG_USERAGENT, config.useragent,
URGTAG_FTPPORT, config.ftpport,
URGTAG_LOW_SPEED_LIMIT, config.low_speed_limit,
URGTAG_LOW_SPEED_TIME, config.low_speed_time,
URGTAG_RESUME_FROM, config.use_resume?config.resume_from:0,
URGTAG_COOKIE, config.cookie,
URGTAG_HTTPHEADER, config.headers,
URGTAG_HTTPPOST, config.httppost,
URGTAG_SSLCERT, config.cert,
URGTAG_SSLCERTPASSWD, config.cert_passwd,
URGTAG_CRLF, config.crlf,
URGTAG_QUOTE, config.quote,
URGTAG_WRITEHEADER, headerfilep,
URGTAG_COOKIEFILE, config.cookiefile,
URGTAG_SSLVERSION, config.ssl_version,
URGTAG_TIMECONDITION, config.timecond,
URGTAG_TIMEVALUE, config.condtime,
URGTAG_CUSTOMREQUEST, config.customrequest,
URGTAG_STDERR, config.errors,
URGTAG_PROGRESSMODE, config.progressmode,
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
URGTAG_DONE); /* always terminate the list of tags */
if((res!=URG_OK) && config.showerror)
fprintf(config.errors, "curl: (%d) %s\n", res, errorbuffer);
if((config.errors != stderr) &&
(config.errors != stdout))
/* it wasn't directed to stdout or stderr so close the file! */
fclose(config.errors);
if(urlbuffer)
free(urlbuffer);
if (config.outfile && outs.stream)
fclose(outs.stream);
if (config.infile)
fclose(infd);
if(headerfilep)
fclose(headerfilep);
if(config.url)
free(config.url);
#ifdef GLOBURL
if(url)
free(url);
if(config.outfile && !config.remotefile)
free(config.outfile);
}
#ifdef MIME_SEPARATORS
if (separator)
printf("--%s--\n", MIMEseparator);
#endif
#endif
curl_slist_free_all(config.quote); /* the checks for config.quote == NULL */
return(res);
}
Daniel Stenberg
committed
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
static char *my_get_line(FILE *fp)
{
char buf[4096];
char *nl = NULL;
char *retval = NULL;
do
{
if (NULL == fgets(buf, sizeof(buf), fp))
break;
if (NULL == retval)
retval = strdup(buf);
else
{
if (NULL == (retval = realloc(retval,
strlen(retval) + strlen(buf) + 1)))
break;
strcat(retval, buf);
}
}
while (NULL == (nl = strchr(retval, '\n')));
if (NULL != nl)
*nl = '\0';
return retval;
}
static char *my_get_token(const char *line)
{
static const char *save = NULL;
const char *first = NULL;
const char *last = NULL;
char *retval = NULL;
size_t size;
if (NULL == line)
line = save;
if (NULL == line)
return NULL;
while (('\0' != *line) && (isspace(*line)))
line++;
first = line;
while (('\0' != *line) && (!isspace(*line)))
line++;
save = line;
while ('\0' != *line)
line++;
last = line;
size = last - first;
if (0 == size)
return NULL;
if (NULL == (retval = malloc(size + 1)))
return NULL;
memcpy(retval, first, size);
retval[size] = '\0';
return retval;
}