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