Main Page   Modules   Data Structures   File List   Data Fields   Globals  

libdarc.cpp

Go to the documentation of this file.
00001 /*
00002  * libdarc.cpp
00003  * Created on 25 Feb 2005
00004  * Authors:
00005  *    Wesley Leggette <wleggette@kaylix.net>
00006  * 
00007  * 
00008  * 
00009  * libdarc
00010  * 
00011  * 
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  * 
00026  * $Id: libdarc_8cpp-source.html 708 2005-03-21 12:30:37Z leggwes $
00027  */
00028 
00035 #include "libdarc.h"
00036 #include "user_interaction_specific.hpp"
00037 #if LIBDARC_HAVE_LIBDAR_HPP
00038 #include <dar/libdar.hpp>
00039 #endif
00040 
00041 #if HAVE_MALLOC_H
00042 #include <malloc.h>
00043 #endif
00044 
00045 #include <string>
00046 
00047 NAMESPACE_LIBDAR_START
00048 
00049 
00050 extern "C" void dar_sup_libversion_destroy( dar_sup_libversion* ref )
00051 {
00052     if ( ref->except_msg != NULL )
00053     {
00054         free(ref->except_msg);
00055         ref->except_msg = NULL;
00056     }
00057     return;
00058 }
00059 
00060 extern "C" bool dar_op_library_init( dar_sup_libversion* inout )
00061 {
00062     if ( inout->major != LIBDARC_MAJOR_VERSION ||
00063          inout->minor < LIBDARC_MINOR_VERSION )
00064     {
00065         inout->major = LIBDARC_MAJOR_VERSION;
00066         inout->minor = LIBDARC_MINOR_VERSION;
00067         inout->micro = LIBDARC_MICRO_VERSION;
00068         char* err = "runtime libdarc version does not match compatible values";
00069         char* ret = (char*)malloc(strlen(err) + 1);
00070         if ( ret != NULL ) // ret will be returned even if NULL
00071             strcpy( ret, err );
00072         inout->exception = LIBDAR_ELIBCALL;
00073         inout->except_msg = ret;
00074         return false;
00075     }
00076     // major version is already the same, will not reset
00077     inout->minor = LIBDARC_MINOR_VERSION;
00078     inout->micro = LIBDARC_MICRO_VERSION;
00079     
00080     /* call libdar's get_version_noexcept */
00081     
00082     std::string libdar_except_msg;
00083     U_16 libdar_except_code;
00084     U_I libdar_major;
00085     U_I libdar_medium;
00086     U_I libdar_minor;
00087     
00088     get_version_noexcept(libdar_major, libdar_medium, libdar_minor,
00089                             libdar_except_code, libdar_except_msg);
00090                             
00091     if ( libdar_major != LIBDARC_DAR_LINKED_MAJOR ||
00092          libdar_medium < LIBDARC_DAR_LINKED_MINOR )
00093     {
00094         char* err = "runtime libdar library version is not compatible with libdarc library";
00095         char* ret = (char*)malloc(strlen(err) + 1);
00096         if ( ret != NULL )
00097             strcpy( ret, err );
00098         inout->exception = LIBDAR_ELIBCALL;
00099         inout->except_msg = ret;
00100         return false;
00101     }
00102     
00103     if ( libdar_except_code != LIBDAR_NOEXCEPT )
00104     {
00105         char* ret = (char*)malloc(libdar_except_msg.length() + 1);
00106         if ( ret != NULL )
00107             strcpy( ret, libdar_except_msg.c_str() );
00108         inout->exception = libdar_except_code;
00109         inout->except_msg = ret;
00110         return false;
00111     }
00112     
00113     inout->exception = LIBDAR_NOEXCEPT;
00114     inout->except_msg = NULL;
00115     return true;
00116 }
00117 
00118 extern "C" void dar_sup_libfeature_destroy( dar_sup_libfeature* ref )
00119 {
00120     // libfeature currently does not have dynamically allocated members
00121     return;
00122 }
00123 
00124 extern "C" void dar_op_libfeature_query( dar_sup_libfeature* ref )
00125 {
00126     bool ld_ea;
00127     bool ld_largefile;
00128     bool ld_nodump;
00129     bool ld_special_alloc;
00130     bool ld_thread_safe;
00131     bool ld_libz;
00132     bool ld_libbz2;
00133     bool ld_libcrypto;
00134     get_compile_time_features(  ld_ea,
00135                                 ld_largefile,
00136                                 ld_nodump,
00137                                 ld_special_alloc,
00138                                 ref->os_bits,
00139                                 ld_thread_safe,
00140                                 ld_libz,
00141                                 ld_libbz2,
00142                                 ld_libcrypto
00143                              );
00144     ref->ea = ld_ea;
00145     ref->largefile = ld_largefile;
00146     ref->nodump = ld_nodump;
00147     ref->special_alloc = ld_special_alloc;
00148     ref->thread_safe = ld_thread_safe;
00149     ref->libz = ld_libz;
00150     ref->libbz2 = ld_libbz2;
00151     ref->libcrypto = ld_libcrypto;
00152     return;
00153 }
00154 
00155 extern "C" void dar_archive_destroy(dar_archive* ref)
00156 {
00157     archive* r = (archive*)ref;
00158     delete r;
00159     return;
00160 }
00161 
00162 extern "C" bool dar_sup_spec_defaults( dar_sup_spec* ref )
00163 {
00164     ref->root_path = NULL;
00165     ref->arc_path = NULL;
00166     ref->arc_name = NULL;
00167     ref->arc_ext = NULL;
00168     ref->input_pipe = NULL;
00169     ref->output_pipe = NULL;
00170     ref->selection = NULL;
00171     ref->subtree = NULL;
00172     
00173     return true;
00174 }
00175 
00176 extern "C" void dar_sup_spec_destroy( dar_sup_spec* ref )
00177 {
00178     if (ref->root_path != NULL)
00179         free(ref->root_path);
00180     if (ref->arc_path != NULL)
00181         free(ref->arc_path);
00182     if (ref->arc_name != NULL)
00183         free(ref->arc_name);
00184     if (ref->arc_ext != NULL)
00185         free(ref->arc_ext);
00186     if (ref->input_pipe != NULL)
00187         free(ref->input_pipe);
00188     if (ref->output_pipe != NULL)
00189         free(ref->output_pipe);
00190     if (ref->selection != NULL)
00191         dar_mask_destroy(ref->selection);
00192     if (ref->subtree != NULL)
00193         dar_mask_destroy(ref->subtree);
00194     
00195     ref->root_path = NULL;
00196     ref->arc_path = NULL;
00197     ref->arc_name = NULL;
00198     ref->arc_ext = NULL;
00199     ref->input_pipe = NULL;
00200     ref->output_pipe = NULL;
00201     ref->selection = NULL;
00202     ref->subtree = NULL;
00203 }
00204 
00205 /* The problem below is that allocating memory can cause memory leak mistakes */
00206 /*
00207 extern "C" bool dar_sup_storage_defaults( dar_sup_storage* ref )
00208 {
00209     bool memgood = true;;
00210     ref->compress_algo = dar_compression_none;
00211     ref->compress_level = 9;
00212     ref->compress_mask = dar_mask_create_bool(true);
00213     if (ref->compress_mask == NULL) { memgood = false; }
00214     ref->compress_min_size = dar_infpi(0);
00215     if (ref->compress_min_size == NULL) { memgood = false; }
00216     ref->crypto_algo = dar_crypto_none;
00217     ref->crypto_size = 10240;
00218     ref->crypto_pass = NULL;
00219     ref->file_size = dar_infpi(0);
00220     if (ref->file_size == NULL) { memgood = false; }
00221     ref->first_file_size = dar_infpi(0);
00222     if (ref->first_file_size == NULL) { memgood = false; }
00223     char* ex = "";
00224     ref->slice_execute = (char*)malloc( strlen(ex) + 1 );
00225     if (ref->slice_execute == NULL) { memgood = false; }
00226     strcpy( ref->slice_execute, ex );
00227     ref->hourshift = dar_infpi(0);
00228     if (ref->hourshift == NULL) { memgood = false; }
00229     
00230     return memgood;
00231 }
00232 */
00233 
00234 extern "C" bool dar_sup_storage_defaults( dar_sup_storage* ref )
00235 {
00236     ref->compress_algo = dar_compression_none;
00237     ref->compress_level = 9;
00238     ref->compress_mask = NULL;
00239     ref->compress_min_size = NULL;
00240     ref->crypto_algo = dar_crypto_none;
00241     ref->crypto_size = 10240;
00242     ref->crypto_pass = NULL;
00243     ref->file_size = NULL;
00244     ref->first_file_size = NULL;
00245     ref->slice_execute = NULL;
00246     ref->hourshift = NULL;
00247     return true;
00248 }
00249 
00250 /* insertion mask values, these indicate which values have been inserted*/
00251 
00252 #define STORAGE_DEFAULT_COMPRESS_MASK       0x01
00253 #define STORAGE_DEFAULT_COMPRESS_MIN_SIZE   0x02
00254 #define STORAGE_DEFAULT_CRYPTO_PASS         0x04
00255 #define STORAGE_DEFAULT_FILE_SIZE           0x08
00256 #define STORAGE_DEFAULT_FIRST_FILE_SIZE     0x10
00257 #define STORAGE_DEFAULT_SLICE_EXECUTE       0x20
00258 #define STORAGE_DEFAULT_HOURSHIFT           0x40
00259 
00260 static void dar_sup_storage_defaults_remove( dar_sup_storage* ref, int64_t insert_mask );
00261 
00262 /* Replaces null values with real defaults, returning insertion mask or -1 if error*/
00263 static int64_t dar_sup_storage_defaults_insert( dar_sup_storage* ref )
00264 {
00265     DEBUG("Function: dar_sup_storage_defaults_insert: Inserting default values.\n");
00266     int insert_mask = 0x00;
00267         
00268     bool memgood = true;
00269     
00270     if (ref->compress_mask == NULL)
00271     {
00272         DEBUG("Default set: compress_mask\n");
00273         ref->compress_mask = dar_mask_create_bool(true);
00274         if (ref->compress_mask == NULL)
00275             memgood = false;
00276         else
00277             insert_mask |= STORAGE_DEFAULT_COMPRESS_MASK;
00278     }
00279     if (ref->compress_min_size == NULL)
00280     {
00281         DEBUG("Default set: compress_min_size\n");
00282         ref->compress_min_size = dar_infpi(0);
00283         if (ref->compress_min_size == NULL)
00284             memgood = false;
00285         else
00286             insert_mask |= STORAGE_DEFAULT_COMPRESS_MIN_SIZE;
00287     }
00288     if (ref->crypto_pass == NULL)
00289     {
00290         DEBUG("Default set: crypto_pass\n");
00291         ref->crypto_pass = (char*)malloc(1);
00292         if (ref->crypto_pass == NULL)
00293             memgood = false;
00294         else
00295         {
00296             ref->crypto_pass[0] = '\0';
00297             insert_mask |= STORAGE_DEFAULT_CRYPTO_PASS;
00298         }
00299     }
00300     // crypto pass can be passed in as null
00301     if (ref->file_size == NULL)
00302     {
00303         DEBUG("Default set: file_size\n");
00304         ref->file_size = dar_infpi(0);
00305         if (ref->file_size == NULL)
00306             memgood = false;
00307         else
00308             insert_mask |= STORAGE_DEFAULT_FILE_SIZE;
00309     }
00310     if (ref->first_file_size == NULL)
00311     {
00312         DEBUG("Default set: first_file_size\n");
00313         ref->first_file_size = ref->file_size;
00314         insert_mask |= STORAGE_DEFAULT_FIRST_FILE_SIZE;
00315     }
00316     if (ref->slice_execute == NULL)
00317     {
00318         DEBUG("Default set: slice_execute\n");
00319         ref->slice_execute = (char*)malloc(1);
00320         if (ref->slice_execute == NULL)
00321             memgood = false;
00322         else
00323         {
00324             ref->slice_execute[0] = '\0';
00325             insert_mask |= STORAGE_DEFAULT_SLICE_EXECUTE;
00326         }
00327     }
00328     if (ref->hourshift == NULL)
00329     {
00330         DEBUG("Default set: hourshift\n");
00331         ref->hourshift = dar_infpi(0);
00332         if (ref->hourshift == NULL)
00333             memgood = false;
00334         else
00335             insert_mask |= STORAGE_DEFAULT_HOURSHIFT;
00336     }
00337     
00338     if (!memgood)
00339     {
00340         dar_sup_storage_defaults_remove(ref, insert_mask);
00341         return -1;
00342     }
00343     return insert_mask;
00344 }
00345 
00346 static void dar_sup_storage_defaults_remove( dar_sup_storage* ref, int64_t insert_mask )
00347 {
00348     DEBUG("Function: dar_sup_storage_default_remove: Freeing inserted default values.\n");
00349     
00350     if (insert_mask & STORAGE_DEFAULT_COMPRESS_MASK)
00351     {
00352         DEBUG("Default removed: compress_mask\n");
00353         dar_mask_destroy(ref->compress_mask);
00354         ref->compress_mask = NULL;
00355     }
00356     if (insert_mask & STORAGE_DEFAULT_COMPRESS_MIN_SIZE)
00357     {
00358         DEBUG("Default removed: compress_min_size\n");
00359         dar_infinint_destroy(ref->compress_min_size);
00360         ref->compress_min_size = NULL;
00361     }
00362     if (insert_mask & STORAGE_DEFAULT_CRYPTO_PASS)
00363     {
00364         DEBUG("Default removed: crypto_pass\n");
00365         free(ref->crypto_pass);
00366         ref->crypto_pass = NULL;
00367     }
00368     if (insert_mask & STORAGE_DEFAULT_FILE_SIZE)
00369     {
00370         DEBUG("Default removed: file_size\n");
00371         dar_infinint_destroy(ref->file_size);
00372         ref->file_size = NULL;
00373     }
00374     if (insert_mask & STORAGE_DEFAULT_FIRST_FILE_SIZE)
00375     {
00376         DEBUG("Default removed: first_file_size\n");
00377         ref->first_file_size = NULL;
00378     }
00379     if (insert_mask & STORAGE_DEFAULT_SLICE_EXECUTE)
00380     {
00381         DEBUG("Default removed: slice_execute\n");
00382         free(ref->slice_execute);
00383         ref->slice_execute = NULL;
00384     }
00385     if (insert_mask & STORAGE_DEFAULT_HOURSHIFT)
00386     {
00387         DEBUG("Default removed: hourshift\n");
00388         dar_infinint_destroy(ref->hourshift);
00389         ref->hourshift = NULL;
00390     }
00391     return;
00392 }
00393 
00394 
00395 
00396 extern "C" void dar_sup_storage_destroy( dar_sup_storage* ref )
00397 {
00398     if (ref->compress_mask != NULL)
00399         dar_mask_destroy(ref->compress_mask);
00400     if (ref->compress_min_size != NULL)
00401         dar_infinint_destroy(ref->compress_min_size);
00402     if (ref->crypto_pass != NULL)
00403         free(ref->crypto_pass);
00404     if (ref->file_size != NULL)
00405         dar_infinint_destroy(ref->file_size);
00406     if (ref->first_file_size != NULL)
00407         dar_infinint_destroy(ref->first_file_size);
00408     if (ref->slice_execute != NULL)
00409         free(ref->slice_execute);
00410     if (ref->hourshift != NULL)
00411         dar_infinint_destroy(ref->hourshift);
00412         
00413     ref->compress_mask = NULL;
00414     ref->compress_min_size = NULL;
00415     ref->crypto_pass = NULL;
00416     ref->file_size = NULL;
00417     ref->first_file_size = NULL;
00418     ref->slice_execute = NULL;
00419     ref->hourshift = NULL;
00420 }
00421 
00422 extern "C" void dar_sup_flags_defaults( dar_sup_flags* ref )
00423 {
00424     ref->allow_overwrite = false;
00425     ref->warn_overwrite = false;
00426     ref->slice_pause = false;
00427     ref->create_empty_stubs = false;
00428     ref->ea_system = false;
00429     ref->ea_user = false;
00430     ref->no_dump = false;
00431     ref->ignore_owner = true;
00432     ref->test_run = false;
00433     ref->alter_atime = false;
00434     ref->same_fs = false;
00435     ref->delete_marked = true;
00436     ref->restore_flat = false;
00437     ref->warn_remove_no_match = true;
00438     ref->only_more_recent = false;
00439     ref->tar_format = true;
00440     ref->filter_unsaved = false;
00441 }
00442 
00443 
00444 extern "C" void dar_sup_exception_destroy( dar_sup_exception* ref )
00445 {
00446     if (ref->message != NULL)
00447         free(ref->message);
00448     ref->message = NULL;
00449 }
00450 
00451 static void copy_statistics( dar_statistics* dest, statistics & src )
00452 {
00453     dest->treated = (dar_infinint*)(new infinint(src.treated));
00454     dest->hard_links = (dar_infinint*)(new infinint(src.hard_links));
00455     dest->skipped = (dar_infinint*)(new infinint(src.skipped));
00456     dest->ignored = (dar_infinint*)(new infinint(src.ignored));
00457     dest->target_changed = (dar_infinint*)(new infinint(src.tooold));
00458     dest->error = (dar_infinint*)(new infinint(src.errored));
00459     dest->deleted = (dar_infinint*)(new infinint(src.deleted));
00460     dest->ea_treated = (dar_infinint*)(new infinint(src.ea_treated));
00461     dest->total = (dar_infinint*)(new infinint(src.total()));
00462     return;
00463 }
00464     
00465 
00466 
00467 extern "C" dar_archive* dar_op_archive_create(  
00468                          dar_user_interaction_struct     dialog,
00469                          dar_archive*                    ref_archive,
00470                          dar_sup_spec                    archive_options,
00471                          dar_sup_storage                 format_options,
00472                          dar_sup_flags                   option_flags,
00473                          dar_statistics*                 operation_stats,
00474                          dar_sup_exception*              exception
00475                      )
00476 {
00477     DEBUG("Function: dar_op_archive_create: Creating archive.\n");
00478     
00479     /* call remove function for this */
00480     int64_t storage_mask = dar_sup_storage_defaults_insert(&format_options);
00481     if (storage_mask < 0)
00482     {
00483         LIBDARC_EXCEPTION(exception, LIBDAR_EMEMORY,
00484             "Memory exhausted, could not allocate default settings.");
00485         return NULL;
00486     }
00487     
00488     if ( !dar_user_interaction_struct_is_valid(dialog) )
00489     {
00490         LIBDARC_EXCEPTION(exception, LIBDAR_ELIBCALL,
00491             "Invalid user interaction struct.");
00492         return NULL;
00493     }
00494     
00495     user_interaction_callback_c dia(dialog);
00496     archive* ref_arc = (archive*)ref_archive;
00497     DEBUG("ref_arc = %X\n", ref_arc);
00498     mask* selection = (mask*)(archive_options.selection);
00499     mask* subtree = (mask*)(archive_options.subtree);
00500     std::string filename(archive_options.arc_name);
00501     std::string extension(archive_options.arc_ext);
00502     
00503     bool info_details = dialog.verbose;
00504     
00505     bool root_ea = option_flags.ea_system;
00506     bool user_ea = option_flags.ea_user;
00507     bool pause = option_flags.slice_pause;
00508     bool empty_dir = option_flags.create_empty_stubs;
00509     bool allow_over = option_flags.allow_overwrite;
00510     bool warn_over = option_flags.warn_overwrite;
00511     bool nodump = option_flags.no_dump;
00512     bool ignore_owner = option_flags.ignore_owner;
00513     bool empty = option_flags.test_run;
00514     bool alter_atime = option_flags.alter_atime;
00515     bool same_fs = option_flags.same_fs;
00516     
00517     compression algo = (compression)format_options.compress_algo;
00518     U_I compression_level = format_options.compress_level;
00519     mask* compr_mask = (mask*)(format_options.compress_mask);
00520     infinint* min_compr_size = (infinint*)(format_options.compress_min_size);
00521     
00522     crypto_algo crypto = (crypto_algo)format_options.crypto_algo;
00523     U_32 crypto_size = format_options.crypto_size;
00524     std::string pass(format_options.crypto_pass);
00525     
00526     infinint* file_size = (infinint*)(format_options.file_size);
00527     infinint* first_file_size = (infinint*)(format_options.first_file_size);
00528     infinint* hourshift = (infinint*)(format_options.hourshift);
00529     
00530     std::string execute(format_options.slice_execute);
00531     
00532     /* call delete on these */
00533     path* fs_root = NULL;
00534     path* sauv_path = NULL;
00535     
00536     
00537     try
00538     {
00539         fs_root = new path(archive_options.root_path);
00540     } catch (...) {
00541         LIBDARC_EXCEPTION(exception, LIBDAR_ELIBCALL,
00542             "Invalid root path string.");
00543         dar_sup_storage_defaults_remove(&format_options, storage_mask);
00544         return NULL;
00545     }
00546     
00547     try
00548     {
00549         sauv_path = new path(archive_options.arc_path);
00550     } catch (...) {
00551         LIBDARC_EXCEPTION(exception, LIBDAR_ELIBCALL,
00552             "Invalid archive path string.");
00553         delete fs_root;
00554         dar_sup_storage_defaults_remove(&format_options, storage_mask);
00555         return NULL;
00556     }
00557     
00558     statistics ret_stat;
00559     U_16 except_num;
00560     std::string except_msg;
00561     
00562     
00563     archive* ret = create_archive_noexcept( dia,
00564                                             *fs_root,
00565                                             *sauv_path,
00566                                             ref_arc,
00567                                             *selection,
00568                                             *subtree,
00569                                             filename,
00570                                             extension,
00571                                             allow_over,
00572                                             warn_over,
00573                                             info_details,
00574                                             pause,
00575                                             empty_dir,
00576                                             algo,
00577                                             compression_level,
00578                                             *file_size,
00579                                             *first_file_size,
00580                                             root_ea,
00581                                             user_ea,
00582                                             execute,
00583                                             crypto,
00584                                             pass,
00585                                             crypto_size,
00586                                             *compr_mask,
00587                                             *min_compr_size,
00588                                             nodump,
00589                                             ignore_owner,
00590                                             *hourshift,
00591                                             empty,
00592                                             alter_atime,
00593                                             same_fs,
00594                                             ret_stat,
00595                                             except_num,
00596                                             except_msg );
00597     
00598     delete fs_root;
00599     delete sauv_path;
00600     dar_sup_storage_defaults_remove(&format_options, storage_mask);
00601     
00602     if ( except_num != LIBDAR_NOEXCEPT )
00603     {
00604         LIBDARC_EXCEPTION(exception, except_num,
00605             except_msg.c_str());
00606         return NULL;
00607     }
00608     
00609     copy_statistics(operation_stats, ret_stat);
00610     return (dar_archive*)ret;
00611 }
00612  
00613 extern "C" bool dar_op_archive_get_children_of(
00614                          dar_user_interaction_struct     dialog,
00615                          dar_archive*                    archive,
00616                          char*                           directory,
00617                          dar_sup_exception*              exception
00618                      )
00619 {
00620     DEBUG("Function: dar_op_archive_get_children_of: Getting listing of path children.\n");
00621 
00622     if ( !dar_user_interaction_struct_is_valid(dialog) )
00623     {
00624         LIBDARC_EXCEPTION(exception, LIBDAR_ELIBCALL,
00625             "Invalid user interaction struct.");
00626         return false;
00627     }
00628     user_interaction_callback_c dia(dialog);
00629     libdar::archive* arc = (libdar::archive*)archive;
00630     
00631     std::string dir(directory);
00632     
00633     U_16 except_num;
00634     std::string except_msg;
00635     
00636     bool ret = get_children_of_noexcept(    dia,
00637                                             arc,
00638                                             dir,
00639                                             except_num,
00640                                             except_msg );
00641     
00642     if (except_num != LIBDAR_NOEXCEPT)
00643     {
00644         LIBDARC_EXCEPTION(exception, except_num,
00645             except_msg.c_str());
00646         return false;
00647     }
00648     
00649     return ret;
00650 }
00651 
00652 
00653 extern "C" dar_archive* dar_op_archive_isolate(
00654                          dar_user_interaction_struct     dialog,
00655                          dar_archive*                    ref_archive,
00656                          dar_sup_spec                    archive_options,
00657                          dar_sup_storage                 format_options,
00658                          dar_sup_flags                   option_flags,
00659                          dar_sup_exception*              exception
00660                      )
00661 {
00662     DEBUG("Function: dar_op_archive_isolate: Creating catalog isolation.\n");
00663     
00664     int64_t storage_mask = dar_sup_storage_defaults_insert(&format_options);
00665     if (storage_mask < 0)
00666     {
00667         LIBDARC_EXCEPTION(exception, LIBDAR_EMEMORY,
00668             "Memory exhausted, could not allocate default settings.");
00669             return NULL;
00670     }
00671     
00672     if ( !dar_user_interaction_struct_is_valid(dialog) )
00673     {
00674         LIBDARC_EXCEPTION(exception, LIBDAR_ELIBCALL,
00675             "Invalid user interaction struct.");
00676         return NULL;
00677     }
00678     
00679     user_interaction_callback_c dia(dialog);
00680     archive* ref_arc = (archive*)ref_archive;
00681     std::string filename(archive_options.arc_name);
00682     std::string extension(archive_options.arc_ext);
00683     
00684     bool info_details = dialog.verbose;
00685     
00686     bool allow_over = option_flags.create_empty_stubs;
00687     bool warn_over = option_flags.allow_overwrite;
00688     bool pause = option_flags.slice_pause;
00689     bool empty = option_flags.test_run;
00690     
00691     compression algo = (compression)format_options.compress_algo;
00692     U_I compression_level = format_options.compress_level;
00693     
00694     crypto_algo crypto = (crypto_algo)format_options.crypto_algo;
00695     std::string pass(format_options.crypto_pass);
00696     U_32 crypto_size = format_options.crypto_size;
00697     
00698     infinint* file_size = (infinint*)(format_options.file_size);
00699     infinint* first_file_size = (infinint*)(format_options.first_file_size);
00700     
00701     std::string execute(format_options.slice_execute);
00702     
00703     path* sauv_path = NULL;
00704     
00705     try
00706     {
00707         sauv_path = new path(archive_options.arc_path);
00708     } catch (...) {
00709         LIBDARC_EXCEPTION(exception, LIBDAR_ELIBCALL,
00710             "Invalid archive path string.");
00711         dar_sup_storage_defaults_remove(&format_options, storage_mask);
00712         return NULL;
00713     }
00714     
00715     U_16 except_num;
00716     std::string except_msg;
00717     
00718     archive* ret = isolate_archive_noexcept(    dia,
00719                                                 *sauv_path,
00720                                                 ref_arc,
00721                                                 filename,
00722                                                 extension,
00723                                                 allow_over,
00724                                                 warn_over,
00725                                                 info_details,
00726                                                 pause,
00727                                                 algo,
00728                                                 compression_level,
00729                                                 *file_size,
00730                                                 *first_file_size,
00731                                                 execute,
00732                                                 crypto,
00733                                                 pass,
00734                                                 crypto_size,
00735                                                 empty,
00736                                                 except_num,
00737                                                 except_msg );
00738     
00739     delete sauv_path;
00740     dar_sup_storage_defaults_remove(&format_options, storage_mask);
00741     
00742     if (except_num != LIBDAR_NOEXCEPT)
00743     {
00744         LIBDARC_EXCEPTION(exception, except_num,
00745             except_msg.c_str());
00746         return NULL;
00747     }
00748     
00749     return (dar_archive*)ret;
00750 }
00751  
00752  
00753 extern "C" bool dar_op_archive_diff(
00754                          dar_user_interaction_struct     dialog,
00755                          dar_archive*                    archive,
00756                          dar_sup_spec                    archive_options,
00757                          dar_sup_flags                   option_flags,
00758                          dar_statistics*                 operation_stats,
00759                          dar_sup_exception*              exception
00760                      )
00761 {
00762     DEBUG("Function: dar_op_archive_diff: Comparing archive to file system.\n");
00763     
00764     if ( !dar_user_interaction_struct_is_valid(dialog) )
00765     {
00766         LIBDARC_EXCEPTION(exception, LIBDAR_ELIBCALL,
00767             "Invalid user interaction struct.");
00768         return false;
00769     }
00770     
00771     user_interaction_callback_c dia(dialog);
00772     libdar::archive* arc = (libdar::archive*)archive;
00773     mask* selection = (mask*)(archive_options.selection);
00774     mask* subtree = (mask*)(archive_options.subtree);
00775     
00776     bool info_details = dialog.verbose;
00777     
00778     bool check_ea_root = option_flags.ea_system;
00779     bool check_ea_user = option_flags.ea_user;
00780     bool ignore_owner = option_flags.ignore_owner;
00781     bool alter_atime = option_flags.alter_atime;
00782     
00783     U_16 except_num;
00784     std::string except_msg;
00785     
00786     path* fs_root = NULL;
00787     
00788     try
00789     {
00790         fs_root = new path(archive_options.root_path);
00791     } catch (...) {
00792         LIBDARC_EXCEPTION(exception, LIBDAR_ELIBCALL,
00793             "Invalid root path string.");
00794         return false;
00795     }
00796     
00797     statistics ret = op_diff_noexcept(  dia,
00798                                         arc,
00799                                         *fs_root,
00800                                         *selection,
00801                                         *subtree,
00802                                         info_details,
00803                                         check_ea_root,
00804                                         check_ea_user,
00805                                         ignore_owner,
00806                                         alter_atime,
00807                                         except_num,
00808                                         except_msg );
00809     
00810     delete fs_root;
00811     
00812     if ( except_num != LIBDAR_NOEXCEPT )
00813     {
00814         LIBDARC_EXCEPTION(exception, except_num,
00815             except_msg.c_str());
00816         return false;
00817     }
00818     
00819     copy_statistics(operation_stats, ret);
00820     
00821     if ( ret.errored == 0 )
00822         return true;
00823     else
00824         return false;
00825 }
00826  
00827  
00828 extern "C" bool dar_op_archive_extract(
00829                          dar_user_interaction_struct     dialog,
00830                          dar_archive*                    archive,
00831                          dar_sup_spec                    archive_options,
00832                          dar_sup_storage                 format_options,
00833                          dar_sup_flags                   option_flags,
00834                          dar_statistics*                 operation_stats,
00835                          dar_sup_exception*              exception
00836                      )
00837 {
00838     DEBUG("Function: dar_op_archive_extract: Extracting files from archive.\n");
00839     
00840     if ( !dar_user_interaction_struct_is_valid(dialog) )
00841     {
00842         LIBDARC_EXCEPTION(exception, LIBDAR_ELIBCALL,
00843             "Invalid user interaction struct.");
00844         return false;
00845     }
00846     
00847     int64_t storage_mask = dar_sup_storage_defaults_insert(&format_options);
00848     if (storage_mask < 0)
00849     {
00850         LIBDARC_EXCEPTION(exception, LIBDAR_EMEMORY,
00851             "Memory exhausted, could not allocate default settings.");
00852             return false;
00853     }
00854     
00855     user_interaction_callback_c dia(dialog);
00856     libdar::archive* arc = (libdar::archive*)archive;
00857     mask* selection = (mask*)(archive_options.selection);
00858     mask* subtree = (mask*)(archive_options.subtree);
00859     
00860     bool info_details = dialog.verbose;
00861     
00862     bool allow_over = option_flags.allow_overwrite;
00863     bool warn_over = option_flags.warn_overwrite;
00864     bool detruire = option_flags.delete_marked;
00865     bool only_more_recent = option_flags.only_more_recent;
00866     bool restore_ea_root = option_flags.ea_system;
00867     bool restore_ea_user = option_flags.ea_user;
00868     bool flat = option_flags.restore_flat;
00869     bool ignore_owner = option_flags.ignore_owner;
00870     bool warn_remove_no_match = option_flags.warn_remove_no_match;
00871     bool empty = option_flags.test_run;
00872     
00873     infinint* hourshift = (infinint*)(format_options.hourshift);
00874     
00875     path* fs_root = NULL;
00876     
00877     try
00878     {
00879         fs_root = new path(archive_options.root_path);
00880     } catch (...) {
00881         LIBDARC_EXCEPTION(exception, LIBDAR_ELIBCALL,
00882             "Invalid root path string.");
00883         dar_sup_storage_defaults_remove(&format_options, storage_mask);
00884         return false;
00885     }
00886     
00887     U_16 except_num;
00888     std::string except_msg;
00889     
00890     statistics ret = op_extract_noexcept(   dia,
00891                                             arc,
00892                                             *fs_root,
00893                                             *selection,
00894                                             *subtree,
00895                                             allow_over,
00896                                             warn_over,
00897                                             info_details,
00898                                             detruire,
00899                                             only_more_recent,
00900                                             restore_ea_root,
00901                                             restore_ea_user,
00902                                             flat,
00903                                             ignore_owner,
00904                                             warn_remove_no_match,
00905                                             *hourshift,
00906                                             empty,
00907                                             except_num,
00908                                             except_msg );
00909 
00910     delete fs_root;
00911     dar_sup_storage_defaults_remove(&format_options, storage_mask);
00912     
00913     if (except_num != LIBDAR_NOEXCEPT)
00914     {
00915         LIBDARC_EXCEPTION(exception, except_num,
00916             except_msg.c_str());
00917         return false;
00918     }
00919     
00920     copy_statistics(operation_stats, ret);
00921     
00922     if ( ret.errored == 0 )
00923         return true;
00924     else
00925         return false;
00926 }
00927  
00928  
00929 
00930 extern "C" bool dar_op_archive_list(
00931                          dar_user_interaction_struct     dialog,
00932                          dar_archive*                    archive,
00933                          dar_sup_spec                    archive_options,
00934                          dar_sup_flags                   option_flags,
00935                          dar_sup_exception*              exception
00936                      )
00937 {
00938     DEBUG("Function: dar_op_archive_list: Listing archive contents.\n");
00939     
00940     if ( !dar_user_interaction_struct_is_valid(dialog) )
00941     {
00942         LIBDARC_EXCEPTION(exception, LIBDAR_ELIBCALL,
00943             "Invalid user interaction struct.");
00944         return false;
00945     }
00946     
00947     user_interaction_callback_c dia(dialog);
00948     libdar::archive* arc = (libdar::archive*)archive;
00949     mask* selection = (mask*)(archive_options.selection);
00950     
00951     bool info_details = dialog.verbose;
00952     
00953     bool tar_format = option_flags.tar_format;
00954     bool filter_unsaved = option_flags.filter_unsaved;
00955         
00956     U_16 except_num;
00957     std::string except_msg;
00958 
00959     op_listing_noexcept(    dia,
00960                             arc,
00961                             info_details,
00962                             tar_format,
00963                             *selection,
00964                             filter_unsaved,
00965                             except_num,
00966                             except_msg );
00967     
00968     if ( except_num != LIBDAR_NOEXCEPT )
00969     {
00970         LIBDARC_EXCEPTION(exception, except_num,
00971             except_msg.c_str());
00972         return false;
00973     }
00974     return true;
00975 }
00976  
00977  
00978 extern "C" bool dar_op_archive_test(
00979                          dar_user_interaction_struct     dialog,
00980                          dar_archive*                    archive,
00981                          dar_sup_spec                    archive_options,
00982                          dar_statistics*                 operation_stats,
00983                          dar_sup_exception*              exception
00984                      )
00985 {
00986     DEBUG("Function: dar_op_archive_test: Testing archive contents.\n");
00987     
00988     if ( !dar_user_interaction_struct_is_valid(dialog) )
00989     {
00990         LIBDARC_EXCEPTION(exception, LIBDAR_ELIBCALL,
00991             "Invalid user interaction struct.");
00992         return false;
00993     }
00994     
00995     user_interaction_callback_c dia(dialog);
00996     libdar::archive* arc = (libdar::archive*)archive;
00997     mask* selection = (mask*)(archive_options.selection);
00998     mask* subtree = (mask*)(archive_options.subtree);
00999     
01000     bool info_details = dialog.verbose;
01001     
01002     U_16 except_num;
01003     std::string except_msg;
01004     
01005     statistics ret = op_test_noexcept(  dia,
01006                                         arc,
01007                                         *selection,
01008                                         *subtree,
01009                                         info_details,
01010                                         except_num,
01011                                         except_msg );
01012     
01013     if ( except_num != LIBDAR_NOEXCEPT )
01014     {
01015         LIBDARC_EXCEPTION(exception, except_num,
01016             except_msg.c_str());
01017         return false;
01018     }
01019     
01020     copy_statistics(operation_stats, ret);
01021     
01022     if ( ret.errored == 0 )
01023         return true;
01024     else
01025         return false;
01026 }
01027 
01028 
01029 extern "C" bool dar_op_archive_close(
01030                          dar_archive*                    archive,
01031                          dar_sup_exception*              exception
01032                      )
01033 {
01034     DEBUG("Function: dar_op_archive_close: Closing archive.\n");
01035     
01036     libdar::archive* arc = (libdar::archive*)archive;
01037     
01038     U_16 except_num;
01039     std::string except_msg;
01040     
01041     close_archive_noexcept( arc,
01042                             except_num,
01043                             except_msg );
01044     
01045     if ( except_num != LIBDAR_NOEXCEPT )
01046     {
01047         LIBDARC_EXCEPTION(exception, except_num,
01048             except_msg.c_str());
01049         return false;
01050     }
01051     return true;
01052 }
01053 
01054  
01055 extern "C" dar_archive* dar_op_archive_open(
01056                          dar_user_interaction_struct     dialog,
01057                          dar_sup_spec                    archive_options,
01058                          dar_sup_storage                 format_options,
01059                          dar_sup_exception*              exception
01060                      )
01061 {
01062     DEBUG("Function: dar_op_archive_open: Open archive from file.\n");
01063     
01064     if ( !dar_user_interaction_struct_is_valid(dialog) )
01065     {
01066         LIBDARC_EXCEPTION(exception, LIBDAR_ELIBCALL,
01067             "Invalid user interaction struct.");
01068         return NULL;
01069     }
01070     
01071     int64_t storage_mask = dar_sup_storage_defaults_insert(&format_options);
01072     if (storage_mask < 0)
01073     {
01074         LIBDARC_EXCEPTION(exception, LIBDAR_EMEMORY,
01075             "Memory exhausted, could not allocate default settings.");
01076         return NULL;
01077     }
01078     
01079     user_interaction_callback_c dia(dialog);
01080     std::string basename(archive_options.arc_name);
01081     std::string extension(archive_options.arc_ext);
01082     
01083     crypto_algo crypto = (crypto_algo)format_options.crypto_algo;
01084     U_32 crypto_size = format_options.crypto_size;
01085     std::string pass(format_options.crypto_pass);
01086     
01087     std::string input_pipe(archive_options.input_pipe);
01088     std::string output_pipe(archive_options.output_pipe);
01089     
01090     std::string execute(format_options.slice_execute);
01091     
01092     bool info_details = dialog.verbose;
01093     
01094     U_16 except_num;
01095     std::string except_msg;
01096     
01097     path* chem = NULL;
01098 
01099     try
01100     {
01101         chem = new path(archive_options.arc_path);
01102         DEBUG("chem = %s\n", chem->display().c_str());
01103     } catch (...) {
01104         LIBDARC_EXCEPTION(exception, LIBDAR_ELIBCALL,
01105             "Invalid archive path string.");
01106         dar_sup_storage_defaults_remove(&format_options, storage_mask);
01107         return NULL;
01108     }
01109     
01110     archive* ret = open_archive_noexcept(   dia,
01111                                             *chem,
01112                                             basename,
01113                                             extension,
01114                                             crypto,
01115                                             pass,
01116                                             crypto_size,
01117                                             input_pipe,
01118                                             output_pipe,
01119                                             execute,
01120                                             info_details,
01121                                             except_num,
01122                                             except_msg );
01123 
01124     DEBUG("returned arc = %X\n", ret);
01125     
01126     dar_sup_storage_defaults_remove(&format_options, storage_mask);
01127     
01128     
01129     if ( except_num != LIBDAR_NOEXCEPT )
01130     {
01131         LIBDARC_EXCEPTION(exception, except_num,
01132             except_msg.c_str());
01133         return NULL;
01134     }
01135     
01136     return (dar_archive*)ret;
01137 }
01138  
01139 
01140 
01141 
01142 
01143 
01144 NAMESPACE_LIBDAR_END
01145