Mercurial > octave-nkf
comparison liboctave/util/url-transfer.cc @ 17601:9e507e30c9ea
keep a copy of user+password data for older cURL libraries
* url-transfer.cc (curl_transfer::userpwd): New data member.
(curl_transfer::curl_transfer): Initialize it.
(curl_transfer::init): Set it to USER:PASSWORD.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 08 Oct 2013 09:44:51 -0400 |
parents | d8d71c89fff2 |
children | ce7b9abf6600 |
comparison
equal
deleted
inserted
replaced
17600:e89f6dcb37f0 | 17601:9e507e30c9ea |
---|---|
274 class curl_transfer : public base_url_transfer | 274 class curl_transfer : public base_url_transfer |
275 { | 275 { |
276 public: | 276 public: |
277 | 277 |
278 curl_transfer (void) | 278 curl_transfer (void) |
279 : base_url_transfer (), curl (curl_easy_init ()), errnum () | 279 : base_url_transfer (), curl (curl_easy_init ()), errnum (), userpwd () |
280 { | 280 { |
281 if (curl) | 281 if (curl) |
282 valid = true; | 282 valid = true; |
283 else | 283 else |
284 errmsg = "can not create curl object"; | 284 errmsg = "can not create curl object"; |
285 } | 285 } |
286 | 286 |
287 curl_transfer (const std::string& host, const std::string& user_arg, | 287 curl_transfer (const std::string& host, const std::string& user_arg, |
288 const std::string& passwd, std::ostream& os) | 288 const std::string& passwd, std::ostream& os) |
289 : base_url_transfer (host, user_arg, passwd, os), | 289 : base_url_transfer (host, user_arg, passwd, os), |
290 curl (curl_easy_init ()), errnum () | 290 curl (curl_easy_init ()), errnum (), userpwd () |
291 { | 291 { |
292 if (curl) | 292 if (curl) |
293 valid = true; | 293 valid = true; |
294 else | 294 else |
295 { | 295 { |
305 // Set up the link, with no transfer. | 305 // Set up the link, with no transfer. |
306 perform (); | 306 perform (); |
307 } | 307 } |
308 | 308 |
309 curl_transfer (const std::string& url, std::ostream& os) | 309 curl_transfer (const std::string& url, std::ostream& os) |
310 : base_url_transfer (url, os), curl (curl_easy_init ()), errnum () | 310 : base_url_transfer (url, os), curl (curl_easy_init ()), errnum (), |
311 userpwd () | |
311 { | 312 { |
312 if (curl) | 313 if (curl) |
313 valid = true; | 314 valid = true; |
314 else | 315 else |
315 { | 316 { |
640 } | 641 } |
641 } | 642 } |
642 | 643 |
643 private: | 644 private: |
644 | 645 |
646 // Pointer to cURL object. | |
645 CURL *curl; | 647 CURL *curl; |
648 | |
649 // cURL error code. | |
646 CURLcode errnum; | 650 CURLcode errnum; |
651 | |
652 // The cURL library changed the curl_easy_setopt call to make an | |
653 // internal copy of string parameters in version 7.17.0. Prior | |
654 // versions only held a pointer to a string provided by the caller | |
655 // that must persist for the lifetime of the CURL handle. | |
656 // | |
657 // The associated API did not change, only the behavior of the library | |
658 // implementing the function call. | |
659 // | |
660 // To be compatible with any version of cURL, the caller must keep a | |
661 // copy of all string parameters associated with a CURL handle until | |
662 // the handle is released. The curl_handle::curl_handle_rep class | |
663 // contains the pointer to the CURL handle and so is the best | |
664 // candidate for storing the strings as well. (bug #36717) | |
665 std::string userpwd; | |
647 | 666 |
648 // No copying! | 667 // No copying! |
649 | 668 |
650 curl_transfer (const curl_transfer&); | 669 curl_transfer (const curl_transfer&); |
651 | 670 |
656 { | 675 { |
657 // No data transfer by default | 676 // No data transfer by default |
658 SETOPT (CURLOPT_NOBODY, 1); | 677 SETOPT (CURLOPT_NOBODY, 1); |
659 | 678 |
660 // Set the username and password | 679 // Set the username and password |
661 std::string userpwd = user; | 680 userpwd = user; |
662 if (! passwd.empty ()) | 681 if (! passwd.empty ()) |
663 userpwd += ":" + passwd; | 682 userpwd += ":" + passwd; |
664 if (! userpwd.empty ()) | 683 if (! userpwd.empty ()) |
665 SETOPT (CURLOPT_USERPWD, userpwd.c_str ()); | 684 SETOPT (CURLOPT_USERPWD, userpwd.c_str ()); |
666 | 685 |