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