Changeset 189
- Timestamp:
- 02/03/08 15:34:06 (4 years ago)
- Files:
-
- branches/2.3.2beta3/src/httpDownloader.cpp (modified) (3 diffs)
- branches/2.3.2beta3/src/include/httpDownloader.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/2.3.2beta3/src/httpDownloader.cpp
r148 r189 31 31 32 32 33 /**34 * Create a temporary file and download the remote resource to this file35 *36 * The path to the temporary file is stored in the parameter localFileName, empty string if it could not be created37 * This file must be deleted by the caller, if this is needed, regardless of the return value38 *39 * Use the defined proxy in preferences, if any40 *41 * Using wxURL would have been a lot easier, but wxURL::SetProxy() doesn't work, and I can't ask42 * users to patch their version of wxWindows to compile this app43 **/44 33 HTTPDownloader::DownloadStatus HTTPDownloader::DownloadFile(const wxString& host, wxUint32 port, const wxString& resource, wxString& localFileName, ProgressManager& progressManager) 45 34 { … … 197 186 198 187 199 /**200 * Return the value of the content-length field, if found201 * Return 0 otherwise202 *203 * ! buffer will be modified !204 **/205 188 wxUint32 HTTPDownloader::ExtractContentSize(wxByte* buffer, wxUint32 bufferSize) 206 189 { … … 239 222 } 240 223 241 /** 242 * Decontructs a "real" url into its Server, Port and Resource fields 243 * and downloads the file 244 **/ 224 245 225 HTTPDownloader::DownloadStatus HTTPDownloader::Url(const wxString& url, wxString& localFileName, ProgressManager& progressManager) 246 226 { branches/2.3.2beta3/src/include/httpDownloader.h
r122 r189 15 15 */ 16 16 17 /** 18 * \file httpDownloader 19 * Create a class to download files over http. 20 * \author François Ingelrest 21 * \author Andrew Schofield 22 **/ 23 17 24 #ifndef _HTTPDOWNLOADER_H 18 25 #define _HTTPDOWNLOADER_H … … 23 30 24 31 25 /** 26 * Preferences used by this class 27 **/ 28 #define PREF_HTTPDOWNLOADER_USEPROXY wxT("HTTPDownloader.UseProxy") 29 #define PREF_HTTPDOWNLOADER_USEPROXY_DV false 32 #define PREF_HTTPDOWNLOADER_USEPROXY wxT("HTTPDownloader.UseProxy") /**< Preference setting for whether a proxy should be used */ 33 #define PREF_HTTPDOWNLOADER_USEPROXY_DV false /**< Default value for use of proxy setting */ 30 34 31 #define PREF_HTTPDOWNLOADER_PROXYADDRESS wxT("HTTPDownloader.ProxyAddress") 32 #define PREF_HTTPDOWNLOADER_PROXYADDRESS_DV wxT("") 35 #define PREF_HTTPDOWNLOADER_PROXYADDRESS wxT("HTTPDownloader.ProxyAddress") /**< Preference setting for proxy address */ 36 #define PREF_HTTPDOWNLOADER_PROXYADDRESS_DV wxT("") /**< Default value for proxy address */ 33 37 34 #define PREF_HTTPDOWNLOADER_PROXYPORT wxT("HTTPDownloader.ProxyPort") 35 #define PREF_HTTPDOWNLOADER_PROXYPORT_DV 8080 38 #define PREF_HTTPDOWNLOADER_PROXYPORT wxT("HTTPDownloader.ProxyPort") /**< Preference setting for proxy port */ 39 #define PREF_HTTPDOWNLOADER_PROXYPORT_DV 8080 /**< Default value for proxy port */ 36 40 37 #define PREF_HTTPDOWNLOADER_USE_PROXY_AUTHENTICATION wxT("HTTPDownloader.UseProxyAuthentication") 38 #define PREF_HTTPDOWNLOADER_USE_PROXY_AUTHENTICATION_DV false 41 #define PREF_HTTPDOWNLOADER_USE_PROXY_AUTHENTICATION wxT("HTTPDownloader.UseProxyAuthentication") /**< Preference setting for whether proxy authentication should be used */ 42 #define PREF_HTTPDOWNLOADER_USE_PROXY_AUTHENTICATION_DV false /**< Default value for proxy authentication */ 39 43 40 #define PREF_HTTPDOWNLOADER_PROXY_USERNAME wxT("HTTPDownloader.ProxyUsername") 41 #define PREF_HTTPDOWNLOADER_PROXY_USERNAME_DV wxT("") 44 #define PREF_HTTPDOWNLOADER_PROXY_USERNAME wxT("HTTPDownloader.ProxyUsername") /**< Preference setting for proxy username */ 45 #define PREF_HTTPDOWNLOADER_PROXY_USERNAME_DV wxT("") /**< Default value for proxy username */ 42 46 43 #define PREF_HTTPDOWNLOADER_PROXY_PASSWORD wxT("HTTPDownloader.ProxyPassword") 44 #define PREF_HTTPDOWNLOADER_PROXY_PASSWORD_DV wxT("") 47 #define PREF_HTTPDOWNLOADER_PROXY_PASSWORD wxT("HTTPDownloader.ProxyPassword") /**< Preference setting for proxy password */ 48 #define PREF_HTTPDOWNLOADER_PROXY_PASSWORD_DV wxT("") /**< Default value for proxy password */ 45 49 46 #define PREF_HTTPDOWNLOADER_USEALTERNATEUPDATE wxT("HTTPDownloader.UseAlternateUpdate") 47 #define PREF_HTTPDOWNLOADER_USEALTERNATEUPDATE_DV true 50 #define PREF_HTTPDOWNLOADER_USEALTERNATEUPDATE wxT("HTTPDownloader.UseAlternateUpdate") /**< Preference setting for use of alternate update source */ 51 #define PREF_HTTPDOWNLOADER_USEALTERNATEUPDATE_DV true /**< Default value for alternate update source */ 48 52 49 #define PREF_HTTPDOWNLOADER_USELOCALFILE wxT("HTTPDownloader.UseLocalFile") 50 #define PREF_HTTPDOWNLOADER_USELOCALFILE_DV false 53 #define PREF_HTTPDOWNLOADER_USELOCALFILE wxT("HTTPDownloader.UseLocalFile") /**< Preference setting for use of a local file as update source */ 54 #define PREF_HTTPDOWNLOADER_USELOCALFILE_DV false /**< Default value for local file */ 51 55 52 #define PREF_HTTPDOWNLOADER_LOCALFILELOCATION wxT("HTTPDownloader.LocalFileLocation") 53 #define PREF_HTTPDOWNLOADER_LOCALFILELOCATION_DV wxT("") 56 #define PREF_HTTPDOWNLOADER_LOCALFILELOCATION wxT("HTTPDownloader.LocalFileLocation") /**< Preference setting for local file location */ 57 #define PREF_HTTPDOWNLOADER_LOCALFILELOCATION_DV wxT("") /**< Default value for local file location */ 54 58 55 #define PREF_HTTPDOWNLOADER_ALTERNATEUPDATEADDRESS wxT("HTTPDownloader.AlternateUpdateAddress") 56 #define PREF_HTTPDOWNLOADER_ALTERNATEUPDATEADDRESS_DV wxT("http://fah-web.stanford.edu/psummary.html") 59 #define PREF_HTTPDOWNLOADER_ALTERNATEUPDATEADDRESS wxT("HTTPDownloader.AlternateUpdateAddress") /**< Preference setting for alternate update address */ 60 #define PREF_HTTPDOWNLOADER_ALTERNATEUPDATEADDRESS_DV wxT("http://fah-web.stanford.edu/psummary.html") /**< Default value for alternate update address */ 57 61 58 62 59 60 // This class allows one to easily download files from a web server 63 /** 64 * HTTPDownloader class. 65 * This class allows one to easily download files from a web server. 66 **/ 61 67 class HTTPDownloader 62 68 { 63 69 public: 70 /** 71 * Download Status definition. 72 **/ 64 73 typedef enum _DOWNLOAD_STATUS 65 74 { 66 STATUS_TEMP_FILE_CREATION_ERROR, 67 STATUS_TEMP_FILE_OPEN_ERROR, 68 STATUS_CONNECT_ERROR, 69 STATUS_SEND_REQUEST_ERROR, 70 STATUS_ABORTED, 71 STATUS_NO_ERROR 75 STATUS_TEMP_FILE_CREATION_ERROR, /**< Temporary file creation error */ 76 STATUS_TEMP_FILE_OPEN_ERROR, /**< Temporary file opening error */ 77 STATUS_CONNECT_ERROR, /**< Connection error */ 78 STATUS_SEND_REQUEST_ERROR, /**< Send request error */ 79 STATUS_ABORTED, /**< Connection aborted */ 80 STATUS_NO_ERROR /**< Connection successful */ 72 81 } DownloadStatus; 73 82 74 83 75 84 protected: 85 /** 86 * Get the size of the downloaded content. 87 * Uses the content-size field. 88 * If no field is found, value is 0. 89 * ! buffer will be modified by this function! 90 * @param buffer The downloaded content buffer. 91 * @param bufferSize The size of the downloaded content buffer. 92 * @return The content size. 93 **/ 76 94 static wxUint32 ExtractContentSize(wxByte* buffer, wxUint32 bufferSize); 77 95 78 96 public: 97 /** 98 * Create a temporary file and download the remote resource to this file. 99 * 100 * The path to the temporary file is stored in the parameter localFileName, empty string if it could not be created 101 * This file must be deleted by the caller, if this is needed, regardless of the return value 102 * 103 * Use the defined proxy in preferences, if any 104 * 105 * Using wxURL would have been a lot easier, but wxURL::SetProxy() doesn't work, and I can't ask 106 * users to patch their version of wxWindows to compile this app 107 * @param host host part of the url 108 * @param port port part of url (default is 80) 109 * @param resource location of file on host 110 * @param locaFileName Location to download file to 111 * @param progressManager The progressManager object 112 * @return A download status object. 113 **/ 79 114 static DownloadStatus DownloadFile(const wxString& host, wxUint32 port, const wxString& resource, wxString& localFileName, ProgressManager& progressManager); 115 116 /** 117 * Decontructs a "real" url into its Server, Port and Resource fields. 118 * This is a wrapper around the DownloadFile method to allow access by a readable url. 119 * @param url The real url like 'http://fah-web.stanford.edu/psummary.html' 120 * @param localFileName Location to download file to 121 * @param progressManager The progressManager object 122 * @return A download status object. 123 **/ 80 124 static DownloadStatus Url(const wxString& url, wxString& localFileName, ProgressManager& progressManager); 81 125 };
