Disk ARchive  2.4.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
libdar_4_4.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 // $Id: libdar_4_4.hpp,v 1.21.2.4 2012/04/15 10:36:44 edrusb Exp $
22 //
23 /*********************************************************************/
24 //
25 
35 
36 
37 #ifndef LIBDAR_4_4_HPP
38 #define LIBDAR_4_4_HPP
39 
40 #include "../my_config.h"
41 
42 extern "C"
43 {
44 #if MUTEX_WORKS
45 #if HAVE_PTHREAD_H
46 #include <pthread.h>
47 #endif
48 #endif
49 }
50 
51 #include <string>
52 
53 
54 #include "erreurs.hpp"
55 
57 namespace libdar_4_4
58 {
59 
62 
63  typedef libdar::Egeneric Egeneric;
64  typedef libdar::Ememory Ememory;
65  typedef libdar::Ebug Ebug;
68  typedef libdar::Erange Erange;
69  typedef libdar::Edeci Edeci;
70  typedef libdar::Efeature Efeature;
73  typedef libdar::Edata Edata;
74  typedef libdar::Escript Escript;
75  typedef libdar::Elibcall Elibcall;
78 }
79 
80 #include "compressor.hpp"
81 namespace libdar_4_4
82 {
83  typedef libdar::compression compression;
84 
85  const compression none = libdar::none;
86  const compression zip = libdar::gzip;
87  const compression gzip = libdar::gzip;
88  const compression bzip2 = libdar::bzip2;
89 
91  inline char compression2char(compression c) { return libdar::compression2char(c); }
92  inline std::string compression2string(compression c) { return libdar::compression2string(c); }
93  inline compression string2compression(const std::string & a) { return libdar::string2compression(a); }
94 
95  typedef libdar::compressor compressor;
96 }
97 
98 #include "path.hpp"
99 namespace libdar_4_4
100 {
101  typedef libdar::path path;
102 }
103 
104 #include "mask.hpp"
105 namespace libdar_4_4
106 {
107  typedef libdar::mask mask;
108  typedef libdar::bool_mask bool_mask;
109  typedef libdar::simple_mask simple_mask;
110  typedef libdar::bool_mask bool_mask;
111  typedef libdar::regular_mask regular_mask;
112  typedef libdar::not_mask not_mask;
113  typedef libdar::et_mask et_mask;
114  typedef libdar::ou_mask ou_mask;
115  typedef libdar::simple_path_mask simple_path_mask;
116  typedef libdar::same_path_mask same_path_mask;
117  typedef libdar::exclude_dir_mask exclude_dir_mask;
118 }
119 
120 #include "integers.hpp" // OK
121 namespace libdar_4_4
122 {
123  typedef libdar::U_8 U_8;
124  typedef libdar::U_16 U_16;
125  typedef libdar::U_32 U_32;
126  typedef libdar::U_64 U_64;
127  typedef libdar::U_I U_I;
128  typedef libdar::S_8 S_8;
129  typedef libdar::S_16 S_16;
130  typedef libdar::S_32 S_32;
131  typedef libdar::S_64 S_64;
132  typedef libdar::S_I S_I;
133 }
134 
135 
136 #include "infinint.hpp"
137 namespace libdar_4_4
138 {
139  typedef libdar::infinint infinint;
140 }
141 
142 #include "statistics.hpp"
143 namespace libdar_4_4
144 {
145  typedef libdar::statistics statistics;
146 }
147 
148 #include "user_interaction.hpp" // OK
149 namespace libdar_4_4
150 {
152 
154  {
155  public:
156 
157  virtual void dar_manager_show_version(U_I number,
158  const std::string & data_date,
159  const std::string & ea_date);
160  protected:
161  libdar::secu_string get_secu_string(const std::string & message, bool echo)
162  {
163  // this is a backward compatibile API, yes, we loose the secured storage feature for keys
164  std::string tmp = get_string(message, echo);
165  libdar::secu_string ret = libdar::secu_string(tmp.c_str(), tmp.size());
166 
167  return ret;
168  };
169  private:
170  void dar_manager_show_version(U_I number,
171  const std::string & data_date,
172  const std::string & data_presence,
173  const std::string & ea_date,
174  const std::string & ea_presence)
175  {
176  dar_manager_show_version(number, data_date, ea_date);
177  }
178  };
179 
180  typedef libdar::user_interaction_callback user_interaction_callback;
181 }
182 
183 #include "deci.hpp"
184 namespace libdar_4_4
185 {
186  typedef libdar::deci deci;
187 }
188 
189 #include "archive_version.hpp"
190 namespace libdar_4_4
191 {
192  typedef libdar::archive_version dar_version;
193 }
194 
195 #include "crypto.hpp"
196 namespace libdar_4_4
197 {
199 
203  const crypto_algo crypto_blowfish_weak = libdar::crypto_blowfish;
204 
205  libdar::secu_string string2secu_string(const std::string & st);
206 
207  inline void crypto_split_algo_pass(const std::string & all, crypto_algo & algo, std::string & pass)
208  {
209  libdar::secu_string sall = string2secu_string(all);
210  libdar::secu_string spass;
211  libdar::crypto_split_algo_pass(sall, algo, spass);
212  pass = spass.c_str();
213  }
214 
216 
218  {
219  blowfish(user_interaction & dialog,
220  U_32 block_size,
221  const std::string & password,
222  generic_file & encrypted_side,
223  const dar_version & reading_ver,
224  bool weak_mode)
225  : libdar::crypto_sym(block_size, string2secu_string(password), encrypted_side, false, reading_ver, libdar::crypto_blowfish) {};
226  };
227 }
228 
229 #include "catalogue.hpp"
230 namespace libdar_4_4
231 {
232  typedef libdar::inode inode;
233 }
234 
235 #include "archive.hpp"
236 namespace libdar_4_4
237 {
238 
239 
241 
242  class archive : public libdar::archive
243  {
244  public:
246 
256  static archive *piggy_convert(libdar::archive * ref);
257 
260  static const listformat normal = libdar::archive_options_listing::normal;
261  static const listformat tree = libdar::archive_options_listing::tree;
262  static const listformat xml = libdar::archive_options_listing::xml;
263 
264  archive(user_interaction & dialog,
265  const path & chem,
266  const std::string & basename,
267  const std::string & extension,
268  crypto_algo crypto,
269  const std::string &pass,
270  U_32 crypto_size,
271  const std::string & input_pipe,
272  const std::string & output_pipe,
273  const std::string & execute,
274  bool info_details); // read constructor
275 
276  archive(user_interaction & dialog,
277  const path & fs_root,
278  const path & sauv_path,
279  archive *ref_arch,
280  const mask & selection,
281  const mask & subtree,
282  const std::string & filename,
283  const std::string & extension,
284  bool allow_over,
285  bool warn_over,
286  bool info_details,
287  const infinint & pause,
288  bool empty_dir,
289  compression algo,
290  U_I compression_level,
291  const infinint &file_size,
292  const infinint &first_file_size,
293  const mask & ea_mask,
294  const std::string & execute,
295  crypto_algo crypto,
296  const std::string & pass,
297  U_32 crypto_size,
298  const mask & compr_mask,
299  const infinint & min_compr_size,
300  bool nodump,
301  inode::comparison_fields what_to_check,
302  const infinint & hourshift,
303  bool empty,
304  bool alter_atime,
305  bool same_fs,
306  bool snapshot,
307  bool cache_directory_tagging,
308  bool display_skipped,
309  const infinint & fixed_date,
310  statistics * progressive_report); // create constructor
311 
312  archive(user_interaction & dialog,
313  const path &sauv_path,
314  archive *ref_arch,
315  const std::string & filename,
316  const std::string & extension,
317  bool allow_over,
318  bool warn_over,
319  bool info_details,
320  const infinint & pause,
321  compression algo,
322  U_I compression_level,
323  const infinint &file_size,
324  const infinint &first_file_size,
325  const std::string & execute,
326  crypto_algo crypto,
327  const std::string & pass,
328  U_32 crypto_size,
329  bool empty); // isolate constructor
330 
331 
332  archive(user_interaction & dialog,
333  const path & sauv_path,
334  archive *ref_arch1,
335  archive *ref_arch2,
336  const mask & selection,
337  const mask & subtree,
338  const std::string & filename,
339  const std::string & extension,
340  bool allow_over,
341  bool warn_over,
342  bool info_details,
343  const infinint & pause,
344  bool empty_dir,
345  compression algo,
346  U_I compression_level,
347  const infinint & file_size,
348  const infinint & first_file_size,
349  const mask & ea_mask,
350  const std::string & execute,
351  crypto_algo crypto,
352  const std::string & pass,
353  U_32 crypto_size,
354  const mask & compr_mask,
355  const infinint & min_compr_size,
356  bool empty,
357  bool display_skipped,
358  bool keep_compressed,
359  statistics * progressive_report); // merging constructor
360 
361  statistics op_extract(user_interaction & dialog,
362  const path &fs_root,
363  const mask &selection,
364  const mask &subtree,
365  bool allow_over,
366  bool warn_over,
367  bool info_details,
368  bool detruire,
369  bool only_more_recent,
370  const mask & ea_mask,
371  bool flat,
372  inode::comparison_fields what_to_check,
373  bool warn_remove_no_match,
374  const infinint & hourshift,
375  bool empty,
376  bool ea_erase,
377  bool display_skipped,
378  statistics *progressive_report);
379 
380  void op_listing(user_interaction & dialog,
381  bool info_details,
382  archive::listformat list_mode,
383  const mask &selection,
384  bool filter_unsaved);
385 
386  statistics op_diff(user_interaction & dialog,
387  const path & fs_root,
388  const mask &selection,
389  const mask &subtree,
390  bool info_details,
391  const mask & ea_mask,
392  inode::comparison_fields what_to_check,
393  bool alter_atime,
394  bool display_skipped,
395  statistics * progressive_report,
396  const infinint & hourshift = 0);
397 
398  statistics op_test(user_interaction & dialog,
399  const mask &selection,
400  const mask &subtree,
401  bool info_details,
402  bool display_skipped,
403  statistics * progressive_report);
404  };
405 }
406 
407 
408 #include "thread_cancellation.hpp"
409 namespace libdar_4_4
410 {
411  typedef libdar::thread_cancellation thread_cancellation;
412 }
413 
415 #define LIBDAR_XXXXXXXX
416 
418 #define LIBDAR_NOEXCEPT 0
419 
420 #define LIBDAR_EMEMORY 1
421 
422 
424 #define LIBDAR_EBUG 2
425 
426 #define LIBDAR_EINFININT 3
427 
428 #define LIBDAR_ELIMITINT 4
429 
430 #define LIBDAR_ERANGE 5
431 
432 #define LIBDAR_EDECI 6
433 
434 #define LIBDAR_EFEATURE 7
435 
436 #define LIBDAR_EHARDWARE 8
437 
438 #define LIBDAR_EUSER_ABORT 9
439 
440 #define LIBDAR_EDATA 10
441 
442 #define LIBDAR_ESCRIPT 11
443 
444 #define LIBDAR_ELIBCALL 12
445 
446 #define LIBDAR_UNKNOWN 13
447 
448 #define LIBDAR_ECOMPILATION 14
449 
450 #define LIBDAR_THREAD_CANCEL 15
451 
452 namespace libdar_4_4
453 {
454 
458  // the last libdar version of releases 2.3.x is 4.5.0, so we skip by one the medium to make the difference,
459  // but we keep the major to 4 (to avoid alarming external programs expecting the libdar API version 4)
463 
465  // LIBDAR INITIALIZATION METHODS //
466  // //
467  // A FUNCTION OF THE get_version*() FAMILY *MUST* BE CALLED //
468  // BEFORE ANY OTHER FUNCTION OF THIS LIBRARY //
469  // //
470  // CLIENT PROGRAM MUST CHECK THAT THE MAJOR NUMBER RETURNED //
471  // BY THIS CALL IS NOT GREATER THAN THE VERSION USED AT COMPILATION //
472  // TIME. IF SO, THE PROGRAM MUST ABORT AND RETURN A WARNING TO THE //
473  // USER TELLING THE DYNAMICALLY LINKED VERSION IS TOO RECENT AND NOT //
474  // COMPATIBLE WITH THIS SOFTWARE. THE MESSAGE MUST INVITE THE USER //
475  // TO UPGRADE HIS SOFTWARE WITH A MORE RECENT VERSION COMPATIBLE WITH //
476  // THIS LIBDAR RELEASE. //
478 
480  void get_version(U_I & major, U_I & minor, bool init_libgcrypt = true);
481 
483  void get_version_noexcept(U_I & major, U_I & minor, U_16 & exception, std::string & except_msg, bool init_libgcrypt = true);
484 
486 
495  void get_version(U_I & major, U_I & medium, U_I & minor, bool init_libgcrypt = true);
496 
498 
510  void get_version_noexcept(U_I & major, U_I & medium, U_I & minor, U_16 & exception, std::string & except_msg, bool init_libgcrypt = true);
511 
512 
514 
527  void get_compile_time_features(bool & ea, bool & largefile, bool & nodump, bool & special_alloc, U_I & bits,
528  bool & thread_safe,
529  bool & libz, bool & libbz2, bool & libcrypto,
530  bool & new_blowfish);
531 
533  // WRAPPER FUNCTIONS AROUND archive class methods to trap exceptions and convert them in error code and message
534  // these are intended for C program/programmers not enough confident with C++.
535  //
536  // FOR LIBDAR C++ APPLICATIONS, YOU WOULD RATHER USE THE archive C++ CLASS THAN THESE FOLLOWING WRAPPERS
537  //
539 
540 
542 
547  const path & chem, const std::string & basename,
548  const std::string & extension,
549  crypto_algo crypto, const std::string &pass, U_32 crypto_size,
550  const std::string & input_pipe, const std::string & output_pipe,
551  const std::string & execute, bool info_details,
552  U_16 & exception,
553  std::string & except_msg);
554 
556 
561  const path & fs_root,
562  const path & sauv_path,
563  archive *ref_arch,
564  const mask & selection,
565  const mask & subtree,
566  const std::string & filename,
567  const std::string & extension,
568  bool allow_over,
569  bool warn_over,
570  bool info_details,
571  const infinint & pause,
572  bool empty_dir,
573  compression algo,
574  U_I compression_level,
575  const infinint &file_size,
576  const infinint &first_file_size,
577  const mask & ea_mask,
578  const std::string & execute,
579  crypto_algo crypto,
580  const std::string & pass,
581  U_32 crypto_size,
582  const mask & compr_mask,
583  const infinint & min_compr_size,
584  bool nodump,
585  inode::comparison_fields what_to_check,
586  const infinint & hourshift,
587  bool empty,
588  bool alter_atime,
589  bool same_fs,
590  bool snapshot,
591  bool cache_directory_tagging,
592  bool display_skipped,
593  const infinint & fixed_date,
594  statistics * progressive_report,
595  U_16 & exception,
596  std::string & except_msg);
597 
598 
600 
605  const path &sauv_path,
606  archive *ref_arch,
607  const std::string & filename,
608  const std::string & extension,
609  bool allow_over,
610  bool warn_over,
611  bool info_details,
612  const infinint & pause,
613  compression algo,
614  U_I compression_level,
615  const infinint &file_size,
616  const infinint &first_file_size,
617  const std::string & execute,
618  crypto_algo crypto,
619  const std::string & pass,
620  U_32 crypto_size,
621  bool empty,
622  U_16 & exception,
623  std::string & except_msg);
624 
626 
631  const path & sauv_path,
632  archive *ref_arch1,
633  archive *ref_arch2,
634  const mask & selection,
635  const mask & subtree,
636  const std::string & filename,
637  const std::string & extension,
638  bool allow_over,
639  bool warn_over,
640  bool info_details,
641  const infinint & pause,
642  bool empty_dir,
643  compression algo,
644  U_I compression_level,
645  const infinint & file_size,
646  const infinint & first_file_size,
647  const mask & ea_mask,
648  const std::string & execute,
649  crypto_algo crypto,
650  const std::string & pass,
651  U_32 crypto_size,
652  const mask & compr_mask,
653  const infinint & min_compr_size,
654  bool empty,
655  bool display_skipped,
656  bool keep_compressed,
657  statistics * progressive_report,
658  U_16 & exception,
659  std::string & except_msg);
660 
661 
663 
667  extern void close_archive_noexcept(archive *ptr,
668  U_16 & exception,
669  std::string & except_msg);
670 
671 
673 
678  archive *ptr,
679  const path &fs_root,
680  const mask &selection,
681  const mask &subtree,
682  bool allow_over,
683  bool warn_over,
684  bool info_details,
685  bool detruire,
686  bool only_more_recent,
687  const mask & ea_mask,
688  bool flat,
689  inode::comparison_fields what_to_check,
690  bool warn_remove_no_match,
691  const infinint & hourshift,
692  bool empty,
693  bool ea_erase,
694  bool display_skipped,
695  statistics * progressive_report,
696  U_16 & exception,
697  std::string & except_msg);
698 
699 
701 
705  extern void op_listing_noexcept(user_interaction & dialog,
706  archive *ptr,
707  bool info_details,
708  archive::listformat list_mode,
709  const mask &selection,
710  bool filter_unsaved,
711  U_16 & exception,
712  std::string & except_msg);
713 
714 
716 
721  archive *ptr,
722  const path & fs_root,
723  const mask &selection,
724  const mask &subtree,
725  bool info_details,
726  const mask & ea_mask,
727  inode::comparison_fields what_to_check,
728  bool alter_atime,
729  bool display_skipped,
730  statistics * progressive_report,
731  U_16 & exception,
732  std::string & except_msg);
733 
734 
736 
741  archive *ptr,
742  const mask &selection,
743  const mask &subtree,
744  bool info_details,
745  bool display_skipped,
746  statistics * progressive_report,
747  U_16 & exception,
748  std::string & except_msg);
749 
750 
752 
756  extern bool get_children_of_noexcept(user_interaction & dialog,
757  archive *ptr,
758  const std::string & dir,
759  U_16 & exception,
760  std::string & except_msg);
761 
762 
763 
765  // TOOLS ROUTINES //
767 
768 
770 
780  extern char *libdar_str2charptr_noexcept(const std::string & x, U_16 & exception, std::string & except_msg);
781 }
782 
783 #include "criterium.hpp"
784 
785 namespace libdar_4_4
786 {
787 
789 
796  extern void tools_4_4_build_compatible_overwriting_policy(bool allow_over,
797  bool detruire,
798  bool more_recent,
799  const libdar::infinint & hourshift,
800  bool ea_erase,
801  const libdar::crit_action * & overwrite);
802 
803 
805  // THREAD CANCELLATION ROUTINES //
807 
808 #if MUTEX_WORKS
809 
810 
816  inline void cancel_thread(pthread_t tid, bool immediate = true, U_64 flag = 0) { thread_cancellation::cancel(tid, immediate, flag); }
817 
819 
822  inline bool cancel_status(pthread_t tid) { return thread_cancellation::cancel_status(tid); }
823 
825 
829  inline bool cancel_clear(pthread_t tid) { return thread_cancellation::clear_pending_request(tid); }
830 #endif
831 
832 
834 
835 } // end of namespace
836 
837 
838 #endif