karazeh
A cross-platform software updating library.
downloader.hpp
Go to the documentation of this file.
1 
21 #ifndef H_KARAZEH_DOWNLOADER_H
22 #define H_KARAZEH_DOWNLOADER_H
23 
24 #include <curl/curl.h>
25 #include <boost/filesystem.hpp>
26 #include "binreloc/binreloc.h"
27 #include "karazeh_export.h"
28 #include "karazeh/karazeh.hpp"
29 #include "karazeh/logger.hpp"
30 #include "karazeh/hasher.hpp"
31 #include "karazeh/file_manager.hpp"
32 #include "karazeh/config.hpp"
33 
34 namespace kzh {
35  struct download_t;
36 
37  class KARAZEH_EXPORT downloader : protected logger {
38  public:
39  downloader(config_t const&, file_manager const&);
40  virtual ~downloader();
41 
43  int retry_count() const;
44  void set_retry_count(int);
45 
53  bool fetch(string_t const& URI, string_t& out_buf) const;
54 
56  bool fetch(string_t const& URI, std::ostream& out_file) const;
57 
65  bool fetch(
66  string_t const& URI,
67  path_t const& path_to_file,
68  string_t const& checksum,
69  uint64_t expected_size_bytes = 0,
70  int* const nr_retries = NULL
71  ) const;
72 
73  private:
74  const config_t &config_;
75  const file_manager& file_manager_;
76 
77  bool fetch(string_t const& URI, download_t*, bool assume_ownership = true) const;
78 
79  int retry_count_;
80  };
81 
84  inline explicit
85  download_t(std::ostream& s)
86  : buf(nullptr),
87  to_file(false),
88  status(false),
89  size(0),
90  retry_no(0),
91  stream(s) {
92  }
93 
96  bool status;
97  bool to_file;
98  std::ostream &stream;
100  int retry_no;
101  };
102 } // end of namespace kzh
103 
104 #endif
std::ostream & stream
Definition: downloader.hpp:98
boost::filesystem::path path_t
Definition: karazeh.hpp:57
string_t uri
Definition: downloader.hpp:95
download_t(std::ostream &s)
Definition: downloader.hpp:85
std::string string_t
Definition: karazeh.hpp:55
Definition: config.hpp:32
int retry_no
Definition: downloader.hpp:100
string_t * buf
Definition: downloader.hpp:94
Definition: downloader.hpp:37
bool to_file
Definition: downloader.hpp:97
kzh::downloader const * downloader
Definition: config.hpp:37
unsigned long uint64_t
Definition: karazeh.hpp:56
Definition: logger.hpp:35
Definition: config.hpp:27
Definition: downloader.hpp:83
bool status
Definition: downloader.hpp:96
Definition: file_manager.hpp:33
uint64_t size
Definition: downloader.hpp:99