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 "test.h"
00023
00024 #ifdef HAVE_FCNTL_H
00025 #include <fcntl.h>
00026 #endif
00027
00028 #include "memdebug.h"
00029
00030
00031
00032
00033
00034
00035
00036
00037 int test(char *URL)
00038 {
00039 CURL *curl;
00040 CURLcode res = CURLE_OK;
00041 FILE *hd_src;
00042 int hd;
00043 struct_stat file_info;
00044 struct curl_slist *hl;
00045 int error;
00046
00047 struct curl_slist *headerlist=NULL;
00048 const char *buf_1 = "RNFR 505";
00049 const char *buf_2 = "RNTO 505-forreal";
00050
00051 if(!libtest_arg2) {
00052 fprintf(stderr, "Usage: <url> <file-to-upload>\n");
00053 return TEST_ERR_USAGE;
00054 }
00055
00056 hd_src = fopen(libtest_arg2, "rb");
00057 if(NULL == hd_src) {
00058 error = ERRNO;
00059 fprintf(stderr, "fopen failed with error: %d %s\n",
00060 error, strerror(error));
00061 fprintf(stderr, "Error opening file: %s\n", libtest_arg2);
00062 return TEST_ERR_MAJOR_BAD;
00063 }
00064
00065
00066 hd = fstat(fileno(hd_src), &file_info);
00067 if(hd == -1) {
00068
00069 error = ERRNO;
00070 fprintf(stderr, "fstat() failed with error: %d %s\n",
00071 error, strerror(error));
00072 fprintf(stderr, "ERROR: cannot open file %s\n", libtest_arg2);
00073 fclose(hd_src);
00074 return TEST_ERR_MAJOR_BAD;
00075 }
00076
00077 if(! file_info.st_size) {
00078 fprintf(stderr, "ERROR: file %s has zero size!\n", libtest_arg2);
00079 fclose(hd_src);
00080 return TEST_ERR_MAJOR_BAD;
00081 }
00082
00083 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00084 fprintf(stderr, "curl_global_init() failed\n");
00085 fclose(hd_src);
00086 return TEST_ERR_MAJOR_BAD;
00087 }
00088
00089
00090 curl = curl_easy_init();
00091 if(!curl) {
00092 fprintf(stderr, "curl_easy_init() failed\n");
00093 curl_global_cleanup();
00094 fclose(hd_src);
00095 return TEST_ERR_MAJOR_BAD;
00096 }
00097
00098
00099
00100 hl = curl_slist_append(headerlist, buf_1);
00101 if(!hl) {
00102 fprintf(stderr, "curl_slist_append() failed\n");
00103 curl_easy_cleanup(curl);
00104 curl_global_cleanup();
00105 fclose(hd_src);
00106 return TEST_ERR_MAJOR_BAD;
00107 }
00108 headerlist = curl_slist_append(hl, buf_2);
00109 if(!headerlist) {
00110 fprintf(stderr, "curl_slist_append() failed\n");
00111 curl_slist_free_all(hl);
00112 curl_easy_cleanup(curl);
00113 curl_global_cleanup();
00114 fclose(hd_src);
00115 return TEST_ERR_MAJOR_BAD;
00116 }
00117 headerlist = hl;
00118
00119
00120 test_setopt(curl, CURLOPT_UPLOAD, 1L);
00121
00122
00123 test_setopt(curl, CURLOPT_VERBOSE, 1L);
00124
00125
00126 test_setopt(curl, CURLOPT_URL, URL);
00127
00128
00129 test_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
00130
00131
00132 test_setopt(curl, CURLOPT_READDATA, hd_src);
00133
00134
00135 test_setopt(curl, CURLOPT_INFILESIZE_LARGE,
00136 (curl_off_t)file_info.st_size);
00137
00138
00139 res = curl_easy_perform(curl);
00140
00141 test_cleanup:
00142
00143
00144 curl_slist_free_all(headerlist);
00145
00146
00147 fclose(hd_src);
00148
00149 curl_easy_cleanup(curl);
00150 curl_global_cleanup();
00151
00152 return res;
00153 }