comparison src/DLD-FUNCTIONS/urlwrite.cc @ 6984:827be634619e

[project @ 2007-10-09 15:55:13 by jwe]
author jwe
date Tue, 09 Oct 2007 15:55:14 +0000
parents 6ade2b60d1c2
children 4ad04ff722d7
comparison
equal deleted inserted replaced
6983:056fa4423303 6984:827be634619e
56 std::ostream& stream = *(static_cast<std::ostream*> (streamp)); 56 std::ostream& stream = *(static_cast<std::ostream*> (streamp));
57 stream.write (static_cast<const char*> (buffer), size*nmemb); 57 stream.write (static_cast<const char*> (buffer), size*nmemb);
58 return (stream.fail () ? 0 : size * nmemb); 58 return (stream.fail () ? 0 : size * nmemb);
59 } 59 }
60 60
61 // Progress callback function for curl.
62
63 int
64 progress_func (const char *url, double dltotal, double dlnow,
65 double /*ultotal*/, double /*ulnow*/)
66 {
67 // macro that picks up Ctrl-C signalling
68 OCTAVE_QUIT;
69
70 #if !defined (URL_QUITE_DOWNLOAD)
71 if (dltotal != 0)
72 {
73 // Is the carriage return character "\r" portable?
74 octave_stdout << "\r" << url << ": "
75 << std::fixed << std::setw(5) << std::setprecision(1)
76 << dlnow*100.0/dltotal << " %";
77
78 octave_stdout.flush ();
79 }
80 #endif
81
82 return 0;
83 }
84
85 // Form the query string based on param. 61 // Form the query string based on param.
86 62
87 std::string 63 std::string
88 form_query_string (CURL *curl, const Cell& param) 64 form_query_string (CURL *curl, const Cell& param)
89 { 65 {
155 131
156 // Follow redirects. 132 // Follow redirects.
157 curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1); 133 curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1);
158 134
159 curl_easy_setopt (curl, CURLOPT_NOPROGRESS, false); 135 curl_easy_setopt (curl, CURLOPT_NOPROGRESS, false);
160 curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, progress_func);
161 curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, url.c_str ()); 136 curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, url.c_str ());
162 curl_easy_setopt (curl, CURLOPT_FAILONERROR, true); 137 curl_easy_setopt (curl, CURLOPT_FAILONERROR, true);
163 138
164 // Switch on full protocol/debug output 139 // Switch on full protocol/debug output
165 // curl_easy_setopt(curl, CURLOPT_VERBOSE, true); 140 // curl_easy_setopt(curl, CURLOPT_VERBOSE, true);
166 141
167 CURLcode res = curl_easy_perform(curl); 142 CURLcode res = curl_easy_perform(curl);
168
169 #if !defined (URL_QUITE_DOWNLOAD)
170 if (res == CURLE_OK)
171 {
172 // download is complete
173 progress_func (url.c_str (), 1, 1, 0, 0);
174 // new line after progress_func
175 octave_stdout << std::endl;
176 }
177 #endif
178 143
179 // always cleanup 144 // always cleanup
180 curl_easy_cleanup (curl); 145 curl_easy_cleanup (curl);
181 146
182 curl_global_cleanup (); 147 curl_global_cleanup ();