00001 // 00002 // aegis - project change supervisor 00003 // Copyright (C) 2003, 2005, 2006, 2008 Peter Miller 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program. If not, see 00017 // <http://www.gnu.org/licenses/>. 00018 // 00019 00020 #ifndef LIBAEGIS_INPUT_CURL_H 00021 #define LIBAEGIS_INPUT_CURL_H 00022 00023 #include <common/ac/curl/curl.h> 00024 00025 #include <libaegis/input.h> 00026 00031 class input_curl: 00032 public input_ty 00033 { 00034 public: 00038 virtual ~input_curl(); 00039 00043 input_curl(const nstring &url); 00044 00050 static bool looks_likely(const nstring &fn); 00051 00052 // This is only public so that the CURL progress callback can access it. 00053 void progress_callback(double down_total, double down_current); 00054 00055 // This is only public so that the CURL write callback can access it. 00056 size_t write_callback(char *data, size_t nbytes); 00057 00058 // This is only public so that the CURL write callback can access it. 00059 void read_error(); 00060 00061 // See base class for documentation. 00062 nstring name(); 00063 00064 // See base class for documentation. 00065 long length(); 00066 00067 // See base class for documentation. 00068 long read_inner(void *data, size_t nbytes); 00069 00070 // See base class for documentation. 00071 long ftell_inner(); 00072 00073 // See base class for documentation. 00074 bool is_remote() const; 00075 00076 bool verify_handle(CURL *x) const { return (x == handle); } 00077 00078 void eof_notify() { eof = true; } 00079 00080 private: 00081 CURL *handle; 00082 nstring fn; 00083 long pos; 00084 00085 // buffer to store cached data 00086 char *curl_buffer; 00087 00088 // currently allocated buffers length 00089 size_t curl_buffer_maximum; 00090 00091 // start of data in buffer 00092 size_t curl_buffer_position; 00093 00094 // end of data in buffer 00095 size_t curl_buffer_length; 00096 00097 // end of file has been reached 00098 bool eof; 00099 00100 char errbuf[CURL_ERROR_SIZE]; 00101 00102 time_t progress_start; 00103 char *progress_buffer; 00104 int progress_buflen; 00105 int progress_cleanup; 00106 #if (LIBCURL_VERSION_NUM < 0x070b01) 00107 nstring proxy; 00108 nstring userpass; 00109 #endif 00110 00111 long read_data(void *data, size_t len); 00112 00116 input_curl(); 00117 00121 input_curl(const input_curl &arg); 00122 00126 input_curl &operator=(const input_curl &arg); 00127 }; 00128 00134 inline input_ty * 00135 input_curl_open(struct string_ty *fn) 00136 { 00137 return new input_curl(nstring(fn)); 00138 } 00139 00145 inline bool 00146 input_curl_looks_likely(struct string_ty *fn) 00147 { 00148 return input_curl::looks_likely(nstring(fn)); 00149 } 00150 00151 #endif // LIBAEGIS_INPUT_CURL_H