Disk ARchive  2.4.2
libdar_4_4.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 // $Id: libdar_4_4.hpp,v 1.21.2.2 2011/09/05 09:29:48 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         // the last libdar version of releases 2.3.x is 4.5.0, so we skip by one the medium to make the difference,
00459         // but we keep the major to 4 (to avoid alarming external programs expecting the libdar API version 4)
00460     const U_I LIBDAR_COMPILE_TIME_MEDIUM = 6;
00462     const U_I LIBDAR_COMPILE_TIME_MINOR = 2;
00463 
00465         // LIBDAR INITIALIZATION METHODS                                      //
00466         //                                                                    //
00467         //      A FUNCTION OF THE get_version*() FAMILY *MUST* BE CALLED      //
00468         //            BEFORE ANY OTHER FUNCTION OF THIS LIBRARY               //
00469         //                                                                    //
00470         // CLIENT PROGRAM MUST CHECK THAT THE MAJOR NUMBER RETURNED           //
00471         // BY THIS CALL IS NOT GREATER THAN THE VERSION USED AT COMPILATION   //
00472         // TIME. IF SO, THE PROGRAM MUST ABORT AND RETURN A WARNING TO THE    //
00473         // USER TELLING THE DYNAMICALLY LINKED VERSION IS TOO RECENT AND NOT  //
00474         // COMPATIBLE WITH THIS SOFTWARE. THE MESSAGE MUST INVITE THE USER    //
00475         // TO UPGRADE HIS SOFTWARE WITH A MORE RECENT VERSION COMPATIBLE WITH //
00476         // THIS LIBDAR RELEASE.                                               //
00478 
00480     void get_version(U_I & major, U_I & minor, bool init_libgcrypt = true);
00481 
00483     void get_version_noexcept(U_I & major, U_I & minor, U_16 & exception, std::string & except_msg, bool init_libgcrypt = true);
00484 
00486 
00495     void get_version(U_I & major, U_I & medium, U_I & minor, bool init_libgcrypt = true);
00496 
00498 
00510     void get_version_noexcept(U_I & major, U_I & medium, U_I & minor, U_16 & exception, std::string & except_msg, bool init_libgcrypt = true);
00511 
00512 
00514 
00527     void get_compile_time_features(bool & ea, bool & largefile, bool & nodump, bool & special_alloc, U_I & bits,
00528                                    bool & thread_safe,
00529                                    bool & libz, bool & libbz2, bool & libcrypto,
00530                                    bool & new_blowfish);
00531 
00533         // WRAPPER FUNCTIONS AROUND archive class methods to trap exceptions and convert them in error code and message
00534         // these are intended for C program/programmers not enough confident with C++.
00535         //
00536         // FOR LIBDAR C++ APPLICATIONS, YOU WOULD RATHER USE THE archive C++ CLASS THAN THESE FOLLOWING WRAPPERS
00537         //
00539 
00540 
00542 
00546     archive* open_archive_noexcept(user_interaction & dialog,
00547                                    const path & chem, const std::string & basename,
00548                                    const std::string & extension,
00549                                    crypto_algo crypto, const std::string &pass, U_32 crypto_size,
00550                                    const std::string & input_pipe, const std::string & output_pipe,
00551                                    const std::string & execute, bool info_details,
00552                                    U_16 & exception,
00553                                    std::string & except_msg);
00554 
00556 
00560     extern archive *create_archive_noexcept(user_interaction & dialog,
00561                                             const path & fs_root,
00562                                             const path & sauv_path,
00563                                             archive *ref_arch,
00564                                             const mask & selection,
00565                                             const mask & subtree,
00566                                             const std::string & filename,
00567                                             const std::string & extension,
00568                                             bool allow_over,
00569                                             bool warn_over,
00570                                             bool info_details,
00571                                             const infinint & pause,
00572                                             bool empty_dir,
00573                                             compression algo,
00574                                             U_I compression_level,
00575                                             const infinint &file_size,
00576                                             const infinint &first_file_size,
00577                                             const mask & ea_mask,
00578                                             const std::string & execute,
00579                                             crypto_algo crypto,
00580                                             const std::string & pass,
00581                                             U_32 crypto_size,
00582                                             const mask & compr_mask,
00583                                             const infinint & min_compr_size,
00584                                             bool nodump,
00585                                             inode::comparison_fields what_to_check,
00586                                             const infinint & hourshift,
00587                                             bool empty,
00588                                             bool alter_atime,
00589                                             bool same_fs,
00590                                             bool snapshot,
00591                                             bool cache_directory_tagging,
00592                                             bool display_skipped,
00593                                             const infinint & fixed_date,
00594                                             statistics * progressive_report,
00595                                             U_16 & exception,
00596                                             std::string & except_msg);
00597 
00598 
00600 
00604     extern archive *isolate_archive_noexcept(user_interaction & dialog,
00605                                              const path &sauv_path,
00606                                              archive *ref_arch,
00607                                              const std::string & filename,
00608                                              const std::string & extension,
00609                                              bool allow_over,
00610                                              bool warn_over,
00611                                              bool info_details,
00612                                              const infinint & pause,
00613                                              compression algo,
00614                                              U_I compression_level,
00615                                              const infinint &file_size,
00616                                              const infinint &first_file_size,
00617                                              const std::string & execute,
00618                                              crypto_algo crypto,
00619                                              const std::string & pass,
00620                                              U_32 crypto_size,
00621                                              bool empty,
00622                                              U_16 & exception,
00623                                              std::string & except_msg);
00624 
00626 
00630     extern archive *merge_archive_noexcept(user_interaction & dialog,
00631                                            const path & sauv_path,
00632                                            archive *ref_arch1,
00633                                            archive *ref_arch2,
00634                                            const mask & selection,
00635                                            const mask & subtree,
00636                                            const std::string & filename,
00637                                            const std::string & extension,
00638                                            bool allow_over,
00639                                            bool warn_over,
00640                                            bool info_details,
00641                                            const infinint & pause,
00642                                            bool empty_dir,
00643                                            compression algo,
00644                                            U_I compression_level,
00645                                            const infinint & file_size,
00646                                            const infinint & first_file_size,
00647                                            const mask & ea_mask,
00648                                            const std::string & execute,
00649                                            crypto_algo crypto,
00650                                            const std::string & pass,
00651                                            U_32 crypto_size,
00652                                            const mask & compr_mask,
00653                                            const infinint & min_compr_size,
00654                                            bool empty,
00655                                            bool display_skipped,
00656                                            bool keep_compressed,
00657                                            statistics * progressive_report,
00658                                            U_16 & exception,
00659                                            std::string & except_msg);
00660 
00661 
00663 
00667     extern void close_archive_noexcept(archive *ptr,
00668                                        U_16 & exception,
00669                                        std::string & except_msg);
00670 
00671 
00673 
00677     extern statistics op_extract_noexcept(user_interaction & dialog,
00678                                           archive *ptr,
00679                                           const path &fs_root,
00680                                           const mask &selection,
00681                                           const mask &subtree,
00682                                           bool allow_over,
00683                                           bool warn_over,
00684                                           bool info_details,
00685                                           bool detruire,
00686                                           bool only_more_recent,
00687                                           const mask & ea_mask,
00688                                           bool flat,
00689                                           inode::comparison_fields what_to_check,
00690                                           bool warn_remove_no_match,
00691                                           const infinint & hourshift,
00692                                           bool empty,
00693                                           bool ea_erase,
00694                                           bool display_skipped,
00695                                           statistics * progressive_report,
00696                                           U_16 & exception,
00697                                           std::string & except_msg);
00698 
00699 
00701 
00705     extern void op_listing_noexcept(user_interaction & dialog,
00706                                     archive *ptr,
00707                                     bool info_details,
00708                                     archive::listformat list_mode,
00709                                     const mask &selection,
00710                                     bool filter_unsaved,
00711                                     U_16 & exception,
00712                                     std::string & except_msg);
00713 
00714 
00716 
00720     extern statistics op_diff_noexcept(user_interaction & dialog,
00721                                        archive *ptr,
00722                                        const path & fs_root,
00723                                        const mask &selection,
00724                                        const mask &subtree,
00725                                        bool info_details,
00726                                        const mask & ea_mask,
00727                                        inode::comparison_fields what_to_check,
00728                                        bool alter_atime,
00729                                        bool display_skipped,
00730                                        statistics * progressive_report,
00731                                        U_16 & exception,
00732                                        std::string & except_msg);
00733 
00734 
00736 
00740     extern statistics op_test_noexcept(user_interaction & dialog,
00741                                        archive *ptr,
00742                                        const mask &selection,
00743                                        const mask &subtree,
00744                                        bool info_details,
00745                                        bool display_skipped,
00746                                        statistics * progressive_report,
00747                                        U_16 & exception,
00748                                        std::string & except_msg);
00749 
00750 
00752 
00756     extern bool get_children_of_noexcept(user_interaction & dialog,
00757                                          archive *ptr,
00758                                          const std::string & dir,
00759                                          U_16 & exception,
00760                                          std::string & except_msg);
00761 
00762 
00763 
00765         // TOOLS ROUTINES                            //
00767 
00768 
00770 
00780     extern char *libdar_str2charptr_noexcept(const std::string & x, U_16 & exception, std::string & except_msg);
00781 }
00782 
00783 #include "criterium.hpp"
00784 
00785 namespace libdar_4_4
00786 {
00787 
00789 
00796     extern void tools_4_4_build_compatible_overwriting_policy(bool allow_over,
00797                                                               bool detruire,
00798                                                               bool more_recent,
00799                                                               const libdar::infinint & hourshift,
00800                                                               bool ea_erase,
00801                                                               const libdar::crit_action * & overwrite);
00802 
00803 
00805         // THREAD CANCELLATION ROUTINES              //
00807 
00808 #if MUTEX_WORKS
00809 
00810 
00816     inline void cancel_thread(pthread_t tid, bool immediate = true, U_64 flag = 0) { thread_cancellation::cancel(tid, immediate, flag); }
00817 
00819 
00822     inline bool cancel_status(pthread_t tid) { return thread_cancellation::cancel_status(tid); }
00823 
00825 
00829     inline bool cancel_clear(pthread_t tid) { return thread_cancellation::clear_pending_request(tid); }
00830 #endif
00831 
00832 
00834 
00835 } // end of namespace
00836 
00837 
00838 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines