Disk ARchive  2.4.15
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
hash_fichier.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
29 
30 #ifndef HASH_FICHIER_HPP
31 #define HASH_FICHIER_HPP
32 
33 #include "../my_config.h"
34 
35 extern "C"
36 {
37 #if HAVE_GCRYPT_H
38 #ifndef GCRYPT_NO_DEPRECATED
39 #define GCRYPT_NO_DEPRECATED
40 #endif
41 #include <gcrypt.h>
42 #endif
43 }
44 
45 #include "generic_file.hpp"
46 #include "fichier.hpp"
47 
48 namespace libdar
49 {
50 
53 
54  enum hash_algo
55  {
56  hash_none, //< no hashing algorithm
57  hash_md5, //< MD5 algorithm
58  hash_sha1 //< SHA1 algorithm
59  };
60 
61 
64 
65  extern std::string hash_algo_to_string(hash_algo algo);
66 
67  class hash_fichier : public fichier
68  {
69  public:
70 
71  // constructors (same as those of class fichier)
72 
73  hash_fichier(user_interaction & dialog, S_I fd);
74  hash_fichier(user_interaction & dialog, const char *name, gf_mode m, U_I perm, bool furtive_mode = false);
75  hash_fichier(user_interaction & dialog, const std::string & chemin, gf_mode m, U_I perm, bool furtive_mode = false);
76  hash_fichier(const std::string & chemin, bool furtive_mode = false) : fichier(chemin, furtive_mode) { throw SRC_BUG; };
77  hash_fichier(const hash_fichier & ref) : fichier(ref) { throw SRC_BUG; };
78 
79  // assignment operator
80  const hash_fichier & operator = (const hash_fichier & ref) { throw SRC_BUG; };
81 
82  // destructor
83  ~hash_fichier();
84 
87 
94  void set_hash_file_name(const std::string & filename, hash_algo algo, const std::string & extension);
95 
97  void change_permission(U_I perm) { x_perm = perm; force_perm = true; fichier::change_permission(perm); };
98  void change_ownership(const std::string & user, const std::string & group) { user_ownership = user; group_ownership = group; fichier::change_ownership(user, group); };
99 
100  // inherited from generic_file
101 
102  bool skip(const infinint & pos) { if(pos != fichier::get_position()) throw SRC_BUG; else return true; };
103  bool skip_to_eof() { throw SRC_BUG; };
104  bool skip_relative(S_I x) { if(x != 0) throw SRC_BUG; else return true; };
105  // no need to overwrite the get_position() method
106 
107 #ifdef LIBDAR_SPECIAL_ALLOC
108  USE_SPECIAL_ALLOC(hash_fichier);
109 #endif
110  void set_only_hash() { only_hash = true; };
112 
113  protected:
114  U_I inherited_read(char *a, U_I size) { throw SRC_BUG; };
115  void inherited_write(const char *a, U_I size);
116  // no need to overwrite inherited_sync_write() method
117  void inherited_terminate();
118 
119  private:
120  bool only_hash; //< if set, avoids copying data to file, only compute hash (debugging purpose)
121  bool hash_ready;
122  std::string hash_filename;
123  std::string hash_extension;
124  bool force_perm;
125  U_I x_perm;
126  std::string user_ownership;
127  std::string group_ownership;
128 #if CRYPTO_AVAILABLE
129  gcry_md_hd_t hash_handle;
130 #endif
131  U_I hash_gcrypt;
132  bool eof;
133 
134 
135  void dump_hash();
136  };
137 
139 
140 } // end of namespace
141 
142 
143 #endif
class fichier definition. This is a full implementation of a generic_file applied to a plain file ...
class generic_file is defined here as well as class fichierthe generic_file interface is widely used ...
gf_mode
generic_file openning modes
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:43