Disk ARchive  2.4.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
hash_fichier.hpp
Go to the documentation of this file.
00001 /*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (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, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 
00029 
00030 #ifndef HASH_FICHIER_HPP
00031 #define HASH_FICHIER_HPP
00032 
00033 #include "../my_config.h"
00034 
00035 extern "C"
00036 {
00037 #if HAVE_GCRYPT_H
00038 #include <gcrypt.h>
00039 #endif
00040 }
00041 
00042 #include "generic_file.hpp"
00043 #include "fichier.hpp"
00044 
00045 namespace libdar
00046 {
00047 
00050 
00051     enum hash_algo
00052     {
00053         hash_none, //< no hashing algorithm
00054         hash_md5,  //< MD5 algorithm
00055         hash_sha1  //< SHA1 algorithm
00056     };
00057 
00058 
00061 
00062     extern std::string hash_algo_to_string(hash_algo algo);
00063 
00064     class hash_fichier : public fichier
00065     {
00066     public:
00067 
00068             // constructors (same as those of class fichier)
00069 
00070         hash_fichier(user_interaction & dialog, S_I fd);
00071         hash_fichier(user_interaction & dialog, const char *name, gf_mode m, U_I perm, bool furtive_mode = false);
00072         hash_fichier(user_interaction & dialog, const std::string & chemin, gf_mode m, U_I perm,  bool furtive_mode = false);
00073         hash_fichier(const std::string & chemin, bool furtive_mode = false) : fichier(chemin, furtive_mode) { throw SRC_BUG; };
00074         hash_fichier(const hash_fichier & ref) : fichier(ref) { throw SRC_BUG; };
00075 
00076             // assignment operator
00077         const hash_fichier & operator = (const hash_fichier & ref) { throw SRC_BUG; };
00078 
00079             // destructor
00080         ~hash_fichier();
00081 
00084 
00091         void set_hash_file_name(const std::string & filename, hash_algo algo, const std::string & extension);
00092 
00094         void change_permission(U_I perm) { x_perm = perm; force_perm = true; fichier::change_permission(perm); };
00095         void change_ownership(const std::string & user, const std::string & group) { user_ownership = user; group_ownership = group; fichier::change_ownership(user, group); };
00096 
00097             // inherited from generic_file
00098 
00099         bool skip(const infinint & pos) { if(pos != fichier::get_position()) throw SRC_BUG; else return true; };
00100         bool skip_to_eof() { throw SRC_BUG; };
00101         bool skip_relative(S_I x) { if(x != 0) throw SRC_BUG; else return true; };
00102             // no need to overwrite the get_position() method
00103 
00104 #ifdef LIBDAR_SPECIAL_ALLOC
00105         USE_SPECIAL_ALLOC(hash_fichier);
00106 #endif
00107 
00108         void set_only_hash() { only_hash = true; };
00109 
00110     protected:
00111         U_I inherited_read(char *a, U_I size) { throw SRC_BUG; };
00112         void inherited_write(const char *a, U_I size);
00113             // no need to overwrite inherited_sync_write() method
00114         void inherited_terminate();
00115 
00116     private:
00117         bool only_hash; //< if set, avoids copying data to file, only compute hash (debugging purpose)
00118         bool hash_ready;
00119         std::string hash_filename;
00120         std::string hash_extension;
00121         bool force_perm;
00122         U_I x_perm;
00123         std::string user_ownership;
00124         std::string group_ownership;
00125 #if CRYPTO_AVAILABLE
00126         gcry_md_hd_t hash_handle;
00127 #endif
00128         U_I hash_gcrypt;
00129         bool eof;
00130 
00131 
00132         void dump_hash();
00133     };
00134 
00136 
00137 } // end of namespace
00138 
00139 
00140 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines