|
Disk ARchive 2.4.0
|
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 // $Id: libdar_4_4.hpp,v 1.21 2011/03/06 21:05:59 edrusb Rel $ 00022 // 00023 /*********************************************************************/ 00024 // 00025 00035 00036 00037 #ifndef LIBDAR_4_4_HPP 00038 #define LIBDAR_4_4_HPP 00039 00040 #include "../my_config.h" 00041 00042 extern "C" 00043 { 00044 #if MUTEX_WORKS 00045 #if HAVE_PTHREAD_H 00046 #include <pthread.h> 00047 #endif 00048 #endif 00049 } 00050 00051 #include <string> 00052 00053 00054 #include "erreurs.hpp" 00055 00057 namespace libdar_4_4 00058 { 00059 00062 00063 typedef libdar::Egeneric Egeneric; 00064 typedef libdar::Ememory Ememory; 00065 typedef libdar::Ebug Ebug; 00066 typedef libdar::Einfinint Einfinint; 00067 typedef libdar::Elimitint Elimitint; 00068 typedef libdar::Erange Erange; 00069 typedef libdar::Edeci Edeci; 00070 typedef libdar::Efeature Efeature; 00071 typedef libdar::Ehardware Ehardware; 00072 typedef libdar::Euser_abort Euser_abort; 00073 typedef libdar::Edata Edata; 00074 typedef libdar::Escript Escript; 00075 typedef libdar::Elibcall Elibcall; 00076 typedef libdar::Ecompilation Ecompilation; 00077 typedef libdar::Ethread_cancel Ethread_cancel; 00078 } 00079 00080 #include "compressor.hpp" 00081 namespace libdar_4_4 00082 { 00083 typedef libdar::compression compression; 00084 00085 const compression none = libdar::none; 00086 const compression zip = libdar::gzip; 00087 const compression gzip = libdar::gzip; 00088 const compression bzip2 = libdar::bzip2; 00089 00090 inline compression char2compression(char a) { return libdar::char2compression(a); } 00091 inline char compression2char(compression c) { return libdar::compression2char(c); } 00092 inline std::string compression2string(compression c) { return libdar::compression2string(c); } 00093 inline compression string2compression(const std::string & a) { return libdar::string2compression(a); } 00094 00095 typedef libdar::compressor compressor; 00096 } 00097 00098 #include "path.hpp" 00099 namespace libdar_4_4 00100 { 00101 typedef libdar::path path; 00102 } 00103 00104 #include "mask.hpp" 00105 namespace libdar_4_4 00106 { 00107 typedef libdar::mask mask; 00108 typedef libdar::bool_mask bool_mask; 00109 typedef libdar::simple_mask simple_mask; 00110 typedef libdar::bool_mask bool_mask; 00111 typedef libdar::regular_mask regular_mask; 00112 typedef libdar::not_mask not_mask; 00113 typedef libdar::et_mask et_mask; 00114 typedef libdar::ou_mask ou_mask; 00115 typedef libdar::simple_path_mask simple_path_mask; 00116 typedef libdar::same_path_mask same_path_mask; 00117 typedef libdar::exclude_dir_mask exclude_dir_mask; 00118 } 00119 00120 #include "integers.hpp" // OK 00121 namespace libdar_4_4 00122 { 00123 typedef libdar::U_8 U_8; 00124 typedef libdar::U_16 U_16; 00125 typedef libdar::U_32 U_32; 00126 typedef libdar::U_64 U_64; 00127 typedef libdar::U_I U_I; 00128 typedef libdar::S_8 S_8; 00129 typedef libdar::S_16 S_16; 00130 typedef libdar::S_32 S_32; 00131 typedef libdar::S_64 S_64; 00132 typedef libdar::S_I S_I; 00133 } 00134 00135 00136 #include "infinint.hpp" 00137 namespace libdar_4_4 00138 { 00139 typedef libdar::infinint infinint; 00140 } 00141 00142 #include "statistics.hpp" 00143 namespace libdar_4_4 00144 { 00145 typedef libdar::statistics statistics; 00146 } 00147 00148 #include "user_interaction.hpp" // OK 00149 namespace libdar_4_4 00150 { 00152 00153 class user_interaction : public libdar::user_interaction 00154 { 00155 public: 00156 00157 virtual void dar_manager_show_version(U_I number, 00158 const std::string & data_date, 00159 const std::string & ea_date); 00160 protected: 00161 libdar::secu_string get_secu_string(const std::string & message, bool echo) 00162 { 00163 // this is a backward compatibile API, yes, we loose the secured storage feature for keys 00164 std::string tmp = get_string(message, echo); 00165 libdar::secu_string ret = libdar::secu_string(tmp.c_str(), tmp.size()); 00166 00167 return ret; 00168 }; 00169 private: 00170 void dar_manager_show_version(U_I number, 00171 const std::string & data_date, 00172 const std::string & data_presence, 00173 const std::string & ea_date, 00174 const std::string & ea_presence) 00175 { 00176 dar_manager_show_version(number, data_date, ea_date); 00177 } 00178 }; 00179 00180 typedef libdar::user_interaction_callback user_interaction_callback; 00181 } 00182 00183 #include "deci.hpp" 00184 namespace libdar_4_4 00185 { 00186 typedef libdar::deci deci; 00187 } 00188 00189 #include "archive_version.hpp" 00190 namespace libdar_4_4 00191 { 00192 typedef libdar::archive_version dar_version; 00193 } 00194 00195 #include "crypto.hpp" 00196 namespace libdar_4_4 00197 { 00198 typedef libdar::crypto_algo crypto_algo; 00199 00200 const crypto_algo crypto_none = libdar::crypto_none; 00201 const crypto_algo crypto_scrambling = libdar::crypto_scrambling; 00202 const crypto_algo crypto_blowfish = libdar::crypto_blowfish; 00203 const crypto_algo crypto_blowfish_weak = libdar::crypto_blowfish; 00204 00205 libdar::secu_string string2secu_string(const std::string & st); 00206 00207 inline void crypto_split_algo_pass(const std::string & all, crypto_algo & algo, std::string & pass) 00208 { 00209 libdar::secu_string sall = string2secu_string(all); 00210 libdar::secu_string spass; 00211 libdar::crypto_split_algo_pass(sall, algo, spass); 00212 pass = spass.c_str(); 00213 } 00214 00216 00217 class blowfish : public libdar::crypto_sym 00218 { 00219 blowfish(user_interaction & dialog, 00220 U_32 block_size, 00221 const std::string & password, 00222 generic_file & encrypted_side, 00223 const dar_version & reading_ver, 00224 bool weak_mode) 00225 : libdar::crypto_sym(block_size, string2secu_string(password), encrypted_side, false, reading_ver, libdar::crypto_blowfish) {}; 00226 }; 00227 } 00228 00229 #include "catalogue.hpp" 00230 namespace libdar_4_4 00231 { 00232 typedef libdar::inode inode; 00233 } 00234 00235 #include "archive.hpp" 00236 namespace libdar_4_4 00237 { 00238 00239 00241 00242 class archive : public libdar::archive 00243 { 00244 public: 00246 00256 static archive *piggy_convert(libdar::archive * ref); 00257 00259 typedef libdar::archive_options_listing::listformat listformat; 00260 static const listformat normal = libdar::archive_options_listing::normal; 00261 static const listformat tree = libdar::archive_options_listing::tree; 00262 static const listformat xml = libdar::archive_options_listing::xml; 00263 00264 archive(user_interaction & dialog, 00265 const path & chem, 00266 const std::string & basename, 00267 const std::string & extension, 00268 crypto_algo crypto, 00269 const std::string &pass, 00270 U_32 crypto_size, 00271 const std::string & input_pipe, 00272 const std::string & output_pipe, 00273 const std::string & execute, 00274 bool info_details); // read constructor 00275 00276 archive(user_interaction & dialog, 00277 const path & fs_root, 00278 const path & sauv_path, 00279 archive *ref_arch, 00280 const mask & selection, 00281 const mask & subtree, 00282 const std::string & filename, 00283 const std::string & extension, 00284 bool allow_over, 00285 bool warn_over, 00286 bool info_details, 00287 const infinint & pause, 00288 bool empty_dir, 00289 compression algo, 00290 U_I compression_level, 00291 const infinint &file_size, 00292 const infinint &first_file_size, 00293 const mask & ea_mask, 00294 const std::string & execute, 00295 crypto_algo crypto, 00296 const std::string & pass, 00297 U_32 crypto_size, 00298 const mask & compr_mask, 00299 const infinint & min_compr_size, 00300 bool nodump, 00301 inode::comparison_fields what_to_check, 00302 const infinint & hourshift, 00303 bool empty, 00304 bool alter_atime, 00305 bool same_fs, 00306 bool snapshot, 00307 bool cache_directory_tagging, 00308 bool display_skipped, 00309 const infinint & fixed_date, 00310 statistics * progressive_report); // create constructor 00311 00312 archive(user_interaction & dialog, 00313 const path &sauv_path, 00314 archive *ref_arch, 00315 const std::string & filename, 00316 const std::string & extension, 00317 bool allow_over, 00318 bool warn_over, 00319 bool info_details, 00320 const infinint & pause, 00321 compression algo, 00322 U_I compression_level, 00323 const infinint &file_size, 00324 const infinint &first_file_size, 00325 const std::string & execute, 00326 crypto_algo crypto, 00327 const std::string & pass, 00328 U_32 crypto_size, 00329 bool empty); // isolate constructor 00330 00331 00332 archive(user_interaction & dialog, 00333 const path & sauv_path, 00334 archive *ref_arch1, 00335 archive *ref_arch2, 00336 const mask & selection, 00337 const mask & subtree, 00338 const std::string & filename, 00339 const std::string & extension, 00340 bool allow_over, 00341 bool warn_over, 00342 bool info_details, 00343 const infinint & pause, 00344 bool empty_dir, 00345 compression algo, 00346 U_I compression_level, 00347 const infinint & file_size, 00348 const infinint & first_file_size, 00349 const mask & ea_mask, 00350 const std::string & execute, 00351 crypto_algo crypto, 00352 const std::string & pass, 00353 U_32 crypto_size, 00354 const mask & compr_mask, 00355 const infinint & min_compr_size, 00356 bool empty, 00357 bool display_skipped, 00358 bool keep_compressed, 00359 statistics * progressive_report); // merging constructor 00360 00361 statistics op_extract(user_interaction & dialog, 00362 const path &fs_root, 00363 const mask &selection, 00364 const mask &subtree, 00365 bool allow_over, 00366 bool warn_over, 00367 bool info_details, 00368 bool detruire, 00369 bool only_more_recent, 00370 const mask & ea_mask, 00371 bool flat, 00372 inode::comparison_fields what_to_check, 00373 bool warn_remove_no_match, 00374 const infinint & hourshift, 00375 bool empty, 00376 bool ea_erase, 00377 bool display_skipped, 00378 statistics *progressive_report); 00379 00380 void op_listing(user_interaction & dialog, 00381 bool info_details, 00382 archive::listformat list_mode, 00383 const mask &selection, 00384 bool filter_unsaved); 00385 00386 statistics op_diff(user_interaction & dialog, 00387 const path & fs_root, 00388 const mask &selection, 00389 const mask &subtree, 00390 bool info_details, 00391 const mask & ea_mask, 00392 inode::comparison_fields what_to_check, 00393 bool alter_atime, 00394 bool display_skipped, 00395 statistics * progressive_report, 00396 const infinint & hourshift = 0); 00397 00398 statistics op_test(user_interaction & dialog, 00399 const mask &selection, 00400 const mask &subtree, 00401 bool info_details, 00402 bool display_skipped, 00403 statistics * progressive_report); 00404 }; 00405 } 00406 00407 00408 #include "thread_cancellation.hpp" 00409 namespace libdar_4_4 00410 { 00411 typedef libdar::thread_cancellation thread_cancellation; 00412 } 00413 00415 #define LIBDAR_XXXXXXXX 00416 00418 #define LIBDAR_NOEXCEPT 0 00419 00420 #define LIBDAR_EMEMORY 1 00421 00422 00424 #define LIBDAR_EBUG 2 00425 00426 #define LIBDAR_EINFININT 3 00427 00428 #define LIBDAR_ELIMITINT 4 00429 00430 #define LIBDAR_ERANGE 5 00431 00432 #define LIBDAR_EDECI 6 00433 00434 #define LIBDAR_EFEATURE 7 00435 00436 #define LIBDAR_EHARDWARE 8 00437 00438 #define LIBDAR_EUSER_ABORT 9 00439 00440 #define LIBDAR_EDATA 10 00441 00442 #define LIBDAR_ESCRIPT 11 00443 00444 #define LIBDAR_ELIBCALL 12 00445 00446 #define LIBDAR_UNKNOWN 13 00447 00448 #define LIBDAR_ECOMPILATION 14 00449 00450 #define LIBDAR_THREAD_CANCEL 15 00451 00452 namespace libdar_4_4 00453 { 00454 00456 const U_I LIBDAR_COMPILE_TIME_MAJOR = 4; 00458 const U_I LIBDAR_COMPILE_TIME_MEDIUM = 4; 00460 const U_I LIBDAR_COMPILE_TIME_MINOR = 3; 00461 00463 // LIBDAR INITIALIZATION METHODS // 00464 // // 00465 // A FUNCTION OF THE get_version*() FAMILY *MUST* BE CALLED // 00466 // BEFORE ANY OTHER FUNCTION OF THIS LIBRARY // 00467 // // 00468 // CLIENT PROGRAM MUST CHECK THAT THE MAJOR NUMBER RETURNED // 00469 // BY THIS CALL IS NOT GREATER THAN THE VERSION USED AT COMPILATION // 00470 // TIME. IF SO, THE PROGRAM MUST ABORT AND RETURN A WARNING TO THE // 00471 // USER TELLING THE DYNAMICALLY LINKED VERSION IS TOO RECENT AND NOT // 00472 // COMPATIBLE WITH THIS SOFTWARE. THE MESSAGE MUST INVITE THE USER // 00473 // TO UPGRADE HIS SOFTWARE WITH A MORE RECENT VERSION COMPATIBLE WITH // 00474 // THIS LIBDAR RELEASE. // 00476 00478 void get_version(U_I & major, U_I & minor, bool init_libgcrypt = true); 00479 00481 void get_version_noexcept(U_I & major, U_I & minor, U_16 & exception, std::string & except_msg, bool init_libgcrypt = true); 00482 00484 00493 void get_version(U_I & major, U_I & medium, U_I & minor, bool init_libgcrypt = true); 00494 00496 00508 void get_version_noexcept(U_I & major, U_I & medium, U_I & minor, U_16 & exception, std::string & except_msg, bool init_libgcrypt = true); 00509 00510 00512 00525 void get_compile_time_features(bool & ea, bool & largefile, bool & nodump, bool & special_alloc, U_I & bits, 00526 bool & thread_safe, 00527 bool & libz, bool & libbz2, bool & libcrypto, 00528 bool & new_blowfish); 00529 00531 // WRAPPER FUNCTIONS AROUND archive class methods to trap exceptions and convert them in error code and message 00532 // these are intended for C program/programmers not enough confident with C++. 00533 // 00534 // FOR LIBDAR C++ APPLICATIONS, YOU WOULD RATHER USE THE archive C++ CLASS THAN THESE FOLLOWING WRAPPERS 00535 // 00537 00538 00540 00544 archive* open_archive_noexcept(user_interaction & dialog, 00545 const path & chem, const std::string & basename, 00546 const std::string & extension, 00547 crypto_algo crypto, const std::string &pass, U_32 crypto_size, 00548 const std::string & input_pipe, const std::string & output_pipe, 00549 const std::string & execute, bool info_details, 00550 U_16 & exception, 00551 std::string & except_msg); 00552 00554 00558 extern archive *create_archive_noexcept(user_interaction & dialog, 00559 const path & fs_root, 00560 const path & sauv_path, 00561 archive *ref_arch, 00562 const mask & selection, 00563 const mask & subtree, 00564 const std::string & filename, 00565 const std::string & extension, 00566 bool allow_over, 00567 bool warn_over, 00568 bool info_details, 00569 const infinint & pause, 00570 bool empty_dir, 00571 compression algo, 00572 U_I compression_level, 00573 const infinint &file_size, 00574 const infinint &first_file_size, 00575 const mask & ea_mask, 00576 const std::string & execute, 00577 crypto_algo crypto, 00578 const std::string & pass, 00579 U_32 crypto_size, 00580 const mask & compr_mask, 00581 const infinint & min_compr_size, 00582 bool nodump, 00583 inode::comparison_fields what_to_check, 00584 const infinint & hourshift, 00585 bool empty, 00586 bool alter_atime, 00587 bool same_fs, 00588 bool snapshot, 00589 bool cache_directory_tagging, 00590 bool display_skipped, 00591 const infinint & fixed_date, 00592 statistics * progressive_report, 00593 U_16 & exception, 00594 std::string & except_msg); 00595 00596 00598 00602 extern archive *isolate_archive_noexcept(user_interaction & dialog, 00603 const path &sauv_path, 00604 archive *ref_arch, 00605 const std::string & filename, 00606 const std::string & extension, 00607 bool allow_over, 00608 bool warn_over, 00609 bool info_details, 00610 const infinint & pause, 00611 compression algo, 00612 U_I compression_level, 00613 const infinint &file_size, 00614 const infinint &first_file_size, 00615 const std::string & execute, 00616 crypto_algo crypto, 00617 const std::string & pass, 00618 U_32 crypto_size, 00619 bool empty, 00620 U_16 & exception, 00621 std::string & except_msg); 00622 00624 00628 extern archive *merge_archive_noexcept(user_interaction & dialog, 00629 const path & sauv_path, 00630 archive *ref_arch1, 00631 archive *ref_arch2, 00632 const mask & selection, 00633 const mask & subtree, 00634 const std::string & filename, 00635 const std::string & extension, 00636 bool allow_over, 00637 bool warn_over, 00638 bool info_details, 00639 const infinint & pause, 00640 bool empty_dir, 00641 compression algo, 00642 U_I compression_level, 00643 const infinint & file_size, 00644 const infinint & first_file_size, 00645 const mask & ea_mask, 00646 const std::string & execute, 00647 crypto_algo crypto, 00648 const std::string & pass, 00649 U_32 crypto_size, 00650 const mask & compr_mask, 00651 const infinint & min_compr_size, 00652 bool empty, 00653 bool display_skipped, 00654 bool keep_compressed, 00655 statistics * progressive_report, 00656 U_16 & exception, 00657 std::string & except_msg); 00658 00659 00661 00665 extern void close_archive_noexcept(archive *ptr, 00666 U_16 & exception, 00667 std::string & except_msg); 00668 00669 00671 00675 extern statistics op_extract_noexcept(user_interaction & dialog, 00676 archive *ptr, 00677 const path &fs_root, 00678 const mask &selection, 00679 const mask &subtree, 00680 bool allow_over, 00681 bool warn_over, 00682 bool info_details, 00683 bool detruire, 00684 bool only_more_recent, 00685 const mask & ea_mask, 00686 bool flat, 00687 inode::comparison_fields what_to_check, 00688 bool warn_remove_no_match, 00689 const infinint & hourshift, 00690 bool empty, 00691 bool ea_erase, 00692 bool display_skipped, 00693 statistics * progressive_report, 00694 U_16 & exception, 00695 std::string & except_msg); 00696 00697 00699 00703 extern void op_listing_noexcept(user_interaction & dialog, 00704 archive *ptr, 00705 bool info_details, 00706 archive::listformat list_mode, 00707 const mask &selection, 00708 bool filter_unsaved, 00709 U_16 & exception, 00710 std::string & except_msg); 00711 00712 00714 00718 extern statistics op_diff_noexcept(user_interaction & dialog, 00719 archive *ptr, 00720 const path & fs_root, 00721 const mask &selection, 00722 const mask &subtree, 00723 bool info_details, 00724 const mask & ea_mask, 00725 inode::comparison_fields what_to_check, 00726 bool alter_atime, 00727 bool display_skipped, 00728 statistics * progressive_report, 00729 U_16 & exception, 00730 std::string & except_msg); 00731 00732 00734 00738 extern statistics op_test_noexcept(user_interaction & dialog, 00739 archive *ptr, 00740 const mask &selection, 00741 const mask &subtree, 00742 bool info_details, 00743 bool display_skipped, 00744 statistics * progressive_report, 00745 U_16 & exception, 00746 std::string & except_msg); 00747 00748 00750 00754 extern bool get_children_of_noexcept(user_interaction & dialog, 00755 archive *ptr, 00756 const std::string & dir, 00757 U_16 & exception, 00758 std::string & except_msg); 00759 00760 00761 00763 // TOOLS ROUTINES // 00765 00766 00768 00778 extern char *libdar_str2charptr_noexcept(const std::string & x, U_16 & exception, std::string & except_msg); 00779 } 00780 00781 #include "criterium.hpp" 00782 00783 namespace libdar_4_4 00784 { 00785 00787 00794 extern void tools_4_4_build_compatible_overwriting_policy(bool allow_over, 00795 bool detruire, 00796 bool more_recent, 00797 const libdar::infinint & hourshift, 00798 bool ea_erase, 00799 const libdar::crit_action * & overwrite); 00800 00801 00803 // THREAD CANCELLATION ROUTINES // 00805 00806 #if MUTEX_WORKS 00807 00808 00814 inline void cancel_thread(pthread_t tid, bool immediate = true, U_64 flag = 0) { thread_cancellation::cancel(tid, immediate, flag); } 00815 00817 00820 inline bool cancel_status(pthread_t tid) { return thread_cancellation::cancel_status(tid); } 00821 00823 00827 inline bool cancel_clear(pthread_t tid) { return thread_cancellation::clear_pending_request(tid); } 00828 #endif 00829 00830 00832 00833 } // end of namespace 00834 00835 00836 #endif
1.7.4