"Fossies" - the Fresh Open Source Software Archive

Member "libisoburn-1.5.4/xorriso/lib_mgt.c" (29 Oct 2020, 30165 Bytes) of package /linux/misc/libisoburn-1.5.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "lib_mgt.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.5.0_vs_1.5.2.

    1 
    2 /* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
    3 
    4    Copyright 2007-2020 Thomas Schmitt, <scdbackup@gmx.net>
    5 
    6    Provided under GPL version 2 or later.
    7 
    8    This file contains functions which manage the relation between xorriso
    9    and the libraries: libburn, libisofs, libisoburn.
   10 */
   11 
   12 #ifdef HAVE_CONFIG_H
   13 #include "../config.h"
   14 #endif
   15 
   16 #include <ctype.h>
   17 #include <sys/types.h>
   18 #include <unistd.h>
   19 #include <stdlib.h>
   20 #include <stdio.h>
   21 #include <string.h>
   22 #include <sys/stat.h>
   23 #include <sys/time.h>
   24 #include <time.h>
   25 #include <errno.h>
   26 #include <pthread.h>
   27 
   28 #ifdef HAVE_STDINT_H
   29 #include <stdint.h>
   30 #else
   31 #ifdef HAVE_INTTYPES_H
   32 #include <inttypes.h>
   33 #endif
   34 #endif
   35 
   36 /* for -charset */
   37 #include <iconv.h>
   38 #include <langinfo.h>
   39 
   40 #ifdef Xorriso_standalonE
   41 
   42 #ifdef Xorriso_with_libjtE
   43 #include "../libjte/libjte.h"
   44 #endif
   45 
   46 #else
   47 
   48 #ifdef Xorriso_with_libjtE
   49 #include <libjte/libjte.h>
   50 #endif
   51 
   52 #endif /* ! Xorriso_standalonE */
   53 
   54 #include "xorriso.h" 
   55 #include "xorriso_private.h"
   56 #include "xorrisoburn.h"
   57 
   58 #include "lib_mgt.h"
   59 #include "iso_manip.h"
   60 
   61 
   62 int Xorriso_abort(struct XorrisO *xorriso, int flag)
   63 {
   64  int ret;
   65 
   66  ret= burn_abort(4440, burn_abort_pacifier, "xorriso : ");
   67  if(ret<=0) {
   68    fprintf(stderr,
   69        "\nxorriso : ABORT : Cannot cancel burn session and release drive.\n");
   70    return(0);
   71  } 
   72  fprintf(stderr,
   73    "xorriso : ABORT : Drive is released and library is shut down now.\n");
   74  fprintf(stderr,
   75    "xorriso : ABORT : Program done. Even if you do not see a shell prompt.\n");
   76  fprintf(stderr, "\n");
   77  exit(1);
   78 }
   79 
   80 
   81 /* @param flag bit0= asynchronous handling (else catch thread, wait, and exit)
   82                bit1= dealing with MMC drive in critical state
   83                      behavior 2 -> behavior 1
   84 */
   85 int Xorriso_set_signal_handling(struct XorrisO *xorriso, int flag)
   86 {
   87  char *handler_prefix= NULL;
   88  int behavior, mode;
   89 
   90  behavior= Xorriso__get_signal_behavior(0);
   91  if(behavior == 0)
   92    return(2);
   93  if(behavior == 2 && !(flag & 2))
   94    mode= 1;
   95  else if(behavior == 3)
   96    mode= 2;
   97  else
   98    mode= (flag & 1) * 0x30;
   99  handler_prefix= calloc(strlen(xorriso->progname)+3+1, 1);
  100  if(handler_prefix==NULL) {
  101    sprintf(xorriso->info_text,
  102            "Cannot allocate memory for setting signal handler");
  103    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
  104    return(-1);
  105  }
  106  mode|= 256; /* Ignore SIGPIPE */
  107 
  108  /* <<< */
  109  sprintf(xorriso->info_text, "burn_set_signal_handling(%d)", mode);
  110  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
  111 
  112  sprintf(handler_prefix, "%s : ", xorriso->progname);
  113  burn_set_signal_handling(handler_prefix, NULL, mode);
  114  free(handler_prefix);
  115  return(1);
  116 }
  117 
  118 
  119 int Xorriso_startup_libraries(struct XorrisO *xorriso, int flag)
  120 {
  121  int ret, major, minor, micro;
  122  char *queue_sev, *print_sev, reason[1024];
  123  struct iso_zisofs_ctrl zisofs_ctrl;
  124 
  125 
  126 /* First an ugly compile time check for header version compatibility.
  127    If everything matches, then no C code is produced. In case of mismatch,
  128    intentionally faulty C code will be inserted.
  129 */
  130 
  131 /* The minimum requirement of xorriso towards the libisoburn header
  132    at compile time is defined in xorriso/xorrisoburn.h 
  133      xorriso_libisoburn_req_major
  134      xorriso_libisoburn_req_minor
  135      xorriso_libisoburn_req_micro
  136    It gets compared against the version macros in libburn/libburn.h :
  137      isoburn_header_version_major
  138      isoburn_header_version_minor
  139      isoburn_header_version_micro
  140    If the header is too old then the following code shall cause failure of
  141    cdrskin compilation rather than to allow production of a program with
  142    unpredictable bugs or memory corruption.
  143    The compiler messages supposed to appear in this case are:
  144       error: 'LIBISOBURN_MISCONFIGURATION' undeclared (first use in this function)
  145       error: 'INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libisoburn_dot_h_TOO_OLD__SEE_xorrisoburn_dot_c' undeclared (first use in this function)
  146       error: 'LIBISOBURN_MISCONFIGURATION_' undeclared (first use in this function)
  147 */
  148 /* The indentation is an advise of man gcc to help old compilers ignoring */
  149  #if xorriso_libisoburn_req_major > isoburn_header_version_major
  150  #define Isoburn_libisoburn_dot_h_too_olD 1
  151  #endif
  152  #if xorriso_libisoburn_req_major == isoburn_header_version_major && xorriso_libisoburn_req_minor > isoburn_header_version_minor
  153  #define Isoburn_libisoburn_dot_h_too_olD 1
  154  #endif
  155  #if xorriso_libisoburn_req_minor == isoburn_header_version_minor && xorriso_libisoburn_req_micro > isoburn_header_version_micro
  156  #define Isoburn_libisoburn_dot_h_too_olD 1
  157  #endif
  158 
  159 #ifdef Isoburn_libisoburn_dot_h_too_olD
  160 LIBISOBURN_MISCONFIGURATION = 0;
  161 INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libisoburn_dot_h_TOO_OLD__SEE_xorrisoburn_dot_c = 0;
  162 LIBISOBURN_MISCONFIGURATION_ = 0;
  163 #endif
  164 
  165 /* End of ugly compile time test (scroll up for explanation) */
  166 
  167  reason[0]= 0;
  168  ret= isoburn_initialize(reason, 0);
  169  if(ret==0) {
  170    sprintf(xorriso->info_text, "Cannot initialize libraries");
  171    if(reason[0])
  172      sprintf(xorriso->info_text+strlen(xorriso->info_text),
  173              ". Reason given:\n%s", reason);
  174    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
  175    return(0);
  176  }
  177  ret= isoburn_is_compatible(isoburn_header_version_major,
  178                             isoburn_header_version_minor,
  179                             isoburn_header_version_micro, 0);
  180  if(ret<=0) {
  181    isoburn_version(&major, &minor, &micro);
  182    sprintf(xorriso->info_text,
  183           "libisoburn version too old: %d.%d.%d . Need at least: %d.%d.%d .\n",
  184           major, minor, micro,
  185           isoburn_header_version_major, isoburn_header_version_minor,
  186           isoburn_header_version_micro);
  187    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
  188    return(-1);
  189  }
  190 
  191  xorriso->libs_are_started= 1;
  192 
  193  queue_sev= "ALL";
  194  if(xorriso->library_msg_direct_print) {
  195 
  196    /* >>> need option for controlling this in XorrisO.
  197           See also Xorriso_msgs_submit */;
  198 
  199    print_sev= xorriso->report_about_text;
  200  } else
  201    print_sev= "NEVER";
  202 
  203  iso_set_msgs_severities(queue_sev, print_sev, "libsofs : ");
  204  burn_msgs_set_severities(queue_sev, print_sev, "libburn : ");
  205 
  206  /* ??? >>> do we want united queues ? */
  207  /* burn_set_messenger(iso_get_messenger()); */
  208 
  209  isoburn_set_msgs_submit(Xorriso_msgs_submit_void, (void *) xorriso,
  210                          (3<<2) | 128 , 0);
  211 
  212  ret= Xorriso_set_signal_handling(xorriso, 0);
  213  if(ret <= 0)
  214    return(ret);
  215 
  216  memset(&zisofs_ctrl, 0, sizeof(zisofs_ctrl));
  217  zisofs_ctrl.version = 1;
  218  ret = iso_zisofs_get_params(&zisofs_ctrl, 0);
  219  if (ret == 1) {
  220    xorriso->zisofs_block_size= xorriso->zisofs_block_size_default=
  221        (1 << zisofs_ctrl.block_size_log2);
  222    xorriso->zlib_level= xorriso->zlib_level_default=
  223        zisofs_ctrl.compression_level;
  224    xorriso->zisofs_v2_enabled= zisofs_ctrl.v2_enabled;
  225    xorriso->zisofs_max_total_blocks=
  226      xorriso->zisofs_max_total_blocks_default= zisofs_ctrl.max_total_blocks;
  227    xorriso->zisofs_max_file_blocks=
  228      xorriso->zisofs_max_file_blocks_default= zisofs_ctrl.max_file_blocks;
  229    xorriso->zisofs_v2_block_size= xorriso->zisofs_v2_block_size_default=
  230        1 << zisofs_ctrl.v2_block_size_log2;
  231    xorriso->zisofs_block_number_target= zisofs_ctrl.block_number_target;
  232    xorriso->zisofs_bpt_discard_free_ratio=
  233    xorriso->zisofs_bpt_discard_free_ratio_default=
  234        zisofs_ctrl.bpt_discard_free_ratio;
  235  }
  236  xorriso->zisofs_susp_z2= xorriso->zisofs_susp_z2_default=
  237      iso_zisofs_ctrl_susp_z2(-1);
  238 
  239  iso_node_xinfo_make_clonable(Xorriso__mark_update_xinfo,
  240                               Xorriso__mark_update_cloner, 0);
  241 
  242  /* Second initialization. This time with libs. */
  243  Xorriso_preparer_string(xorriso, xorriso->preparer_id, 0);
  244 
  245  Xorriso_process_msg_queues(xorriso,0);
  246  if(reason[0]) {
  247    sprintf(xorriso->info_text, "%s", reason);
  248    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
  249  }
  250  strcpy(xorriso->info_text, "Using ");
  251  strncat(xorriso->info_text, burn_scsi_transport_id(0), 1024);
  252  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
  253  return(1);
  254 }
  255 
  256 
  257 /* @param flag bit0= global shutdown of libraries */
  258 int Xorriso_detach_libraries(struct XorrisO *xorriso, int flag)
  259 {
  260  Xorriso_give_up_drive(xorriso, 3);
  261  if(xorriso->in_volset_handle!=NULL) { /* standalone image */
  262    iso_image_unref((IsoImage *) xorriso->in_volset_handle);
  263    xorriso->in_volset_handle= NULL;
  264    Sectorbitmap_destroy(&(xorriso->in_sector_map), 0);
  265    Xorriso_destroy_di_array(xorriso, 0);
  266    Xorriso_destroy_hln_array(xorriso, 0);
  267    xorriso->boot_count= 0;
  268  }
  269  if(flag&1) {
  270    if(xorriso->libs_are_started==0)
  271      return(0);
  272    isoburn_finish();
  273 
  274 #ifdef Xorriso_with_editlinE
  275    Xorriso__shutdown_editline(0);
  276 #endif
  277 
  278  }
  279  return(1);
  280 }
  281 
  282 
  283 /* @param flag bit0= suppress messages below UPDATE
  284                bit1= suppress messages below FAILURE
  285 */
  286 int Xorriso_set_image_severities(struct XorrisO *xorriso, int flag)
  287 {
  288  char *queue_sev, *print_sev;
  289 
  290  if(flag&2)
  291    queue_sev= "FAILURE";
  292  else if(flag&1)
  293    queue_sev= "UPDATE";
  294  else
  295    queue_sev= "ALL";
  296  if(xorriso->library_msg_direct_print)
  297    print_sev= xorriso->report_about_text;
  298  else
  299    print_sev= "NEVER";
  300  iso_set_msgs_severities(queue_sev, print_sev, "libisofs : ");
  301  return(1);
  302 }
  303 
  304 
  305 /* @param flag bit0=prepare for a burn run */
  306 int Xorriso_set_abort_severity(struct XorrisO *xorriso, int flag)
  307 {
  308  int ret, abort_on_number;
  309  char *sev_text;
  310  static int note_number= -1, failure_number= -1;
  311 
  312  if(note_number==-1)
  313    Xorriso__text_to_sev("NOTE", &note_number, 0);
  314  if(failure_number==-1)
  315    Xorriso__text_to_sev("FAILURE", &failure_number, 0);
  316  sev_text= xorriso->abort_on_text;
  317  ret= Xorriso__text_to_sev(xorriso->abort_on_text, &abort_on_number, 0);
  318  if(ret<=0)
  319    return(ret);
  320  if(abort_on_number<note_number)
  321    sev_text= "NOTE";
  322  else if(abort_on_number>failure_number)
  323    sev_text= "FAILURE";
  324  ret= iso_set_abort_severity(sev_text);
  325  return(ret>=0);
  326 }
  327 
  328 
  329 int Xorriso_report_lib_versions(struct XorrisO *xorriso, int flag)
  330 {
  331  int major, minor, micro;
  332  int req_major, req_minor, req_micro;
  333 
  334  iso_lib_version(&major, &minor, &micro);
  335  isoburn_libisofs_req(&req_major, &req_minor, &req_micro);
  336  sprintf(xorriso->result_line,
  337          "libisofs   in use :  %d.%d.%d  (min. %d.%d.%d)\n",
  338          major, minor, micro, req_major, req_minor, req_micro);
  339  Xorriso_result(xorriso, 0);
  340 
  341 #ifdef Xorriso_with_libjtE
  342  libjte__version(&major, &minor, &micro);
  343  isoburn_libjte_req(&req_major, &req_minor, &req_micro);
  344  sprintf(xorriso->result_line,
  345          "libjte     in use :  %d.%d.%d  (min. %d.%d.%d)\n",
  346          major, minor, micro, req_major, req_minor, req_micro);
  347  Xorriso_result(xorriso, 0);
  348 #endif
  349 
  350  burn_version(&major, &minor, &micro);
  351  isoburn_libburn_req(&req_major, &req_minor, &req_micro);
  352  sprintf(xorriso->result_line,
  353          "libburn    in use :  %d.%d.%d  (min. %d.%d.%d)\n",
  354          major, minor, micro, req_major, req_minor, req_micro);
  355  Xorriso_result(xorriso, 0);
  356  strcpy(xorriso->result_line, "libburn OS adapter:  ");
  357  strncat(xorriso->result_line, burn_scsi_transport_id(0), 1024);
  358  strcat(xorriso->result_line, "\n");
  359  Xorriso_result(xorriso, 0);
  360  isoburn_version(&major, &minor, &micro);
  361  sprintf(xorriso->result_line,
  362          "libisoburn in use :  %d.%d.%d  (min. %d.%d.%d)\n",
  363          major, minor, micro,
  364          isoburn_header_version_major, isoburn_header_version_minor,
  365          isoburn_header_version_micro);
  366  Xorriso_result(xorriso, 0);
  367  return(1);
  368 }
  369 
  370 
  371 int Xorriso__sev_to_text(int severity, char **severity_name,
  372                          int flag)
  373 {
  374  int ret;
  375 
  376  ret= iso_sev_to_text(severity, severity_name);
  377  if(ret>0)
  378    return(ret);
  379  ret= burn_sev_to_text(severity, severity_name, 0);
  380  if(ret>0)
  381    return(ret);
  382  *severity_name= "";
  383  return(0);
  384 }
  385 
  386 
  387 int Xorriso__text_to_sev(char *severity_name, int *severity_number, int flag)
  388 {
  389  int ret= 1;
  390  char severity[20];
  391 
  392  Xorriso__to_upper(severity_name, severity, (int) sizeof(severity), 0);
  393  ret= iso_text_to_sev(severity, severity_number);
  394  if(ret>0)
  395    return(ret);
  396  ret= burn_text_to_sev(severity, severity_number, 0);
  397  return(ret);
  398 }
  399 
  400 
  401 int Xorriso__severity_cmp(char *sev1, char *sev2)
  402 {
  403  int s1= 0x7fffffff, s2= 0x7fffffff, ret;
  404  char *default_sev= "FATAL";
  405 
  406  ret= Xorriso__text_to_sev(sev1, &s1, 0);
  407  if(ret <= 0)
  408    Xorriso__text_to_sev(default_sev, &s1, 0);
  409  ret= Xorriso__text_to_sev(sev2, &s2, 0);
  410  if(ret <= 0)
  411    Xorriso__text_to_sev(default_sev, &s2, 0);
  412  if(s1 < s2)
  413    return -1;
  414  if(s1 > s2)
  415    return(1);
  416  return(0);
  417 }
  418 
  419 
  420 char *Xorriso__severity_list(int flag)
  421 {
  422  return(burn_list_sev_texts(0));
  423 }
  424 
  425 
  426 /* @param flag bit0= report libisofs error text
  427                bit1= victim is disk_path
  428                bit2= do not inquire libisofs, report msg_text and min_severity
  429 */
  430 int Xorriso_report_iso_error(struct XorrisO *xorriso, char *victim,
  431                         int iso_error_code, char msg_text[], int os_errno,
  432                         char min_severity[], int flag)
  433 {
  434  int error_code, iso_sev, min_sev, ret;
  435  char *sev_text_pt, *msg_text_pt= NULL;
  436  char *sfe= NULL;
  437  static int sorry_sev= -1;
  438 
  439  Xorriso_alloc_meM(sfe, char, 6 * SfileadrL);
  440 
  441  if(sorry_sev<0)
  442    Xorriso__text_to_sev("SORRY", &sorry_sev, 0);
  443 
  444  if(flag&4) {
  445    error_code= 0x00050000;
  446    Xorriso__text_to_sev(min_severity, &iso_sev, 0);
  447  } else {
  448    error_code= iso_error_get_code(iso_error_code);
  449    if(error_code < 0x00030000 || error_code >= 0x00040000)
  450      error_code= (error_code & 0xffff) | 0x00050000;
  451    if(flag&1)
  452      msg_text_pt= (char *) iso_error_to_msg(iso_error_code);
  453    iso_sev= iso_error_get_severity(iso_error_code);
  454  }
  455  if(msg_text_pt==NULL)
  456    msg_text_pt= msg_text;
  457 
  458  if(iso_sev >= sorry_sev && (flag & 2) && victim[0])
  459    Xorriso_msgs_submit(xorriso, 0, victim, 0, "ERRFILE", 0);
  460  sev_text_pt= min_severity;
  461  Xorriso__text_to_sev(min_severity, &min_sev, 0);
  462  if(min_sev < iso_sev && !(flag&4))
  463    Xorriso__sev_to_text(iso_sev, &sev_text_pt, 0);
  464  strcpy(sfe, msg_text_pt);
  465  if(victim[0]) {
  466    strcat(sfe, ": ");
  467    Text_shellsafe(victim, sfe+strlen(sfe), 0);
  468  }
  469  ret= Xorriso_msgs_submit(xorriso, error_code, sfe, os_errno, sev_text_pt, 4);
  470 ex:;
  471  Xorriso_free_meM(sfe);
  472  return(ret);
  473 }
  474 
  475 
  476 int Xorriso_get_local_charset(struct XorrisO *xorriso, char **name, int flag)
  477 {
  478  (*name)= iso_get_local_charset(0);
  479  return(1);
  480 }
  481 
  482 
  483 int Xorriso_set_local_charset(struct XorrisO *xorriso, char *name, int flag)
  484 {
  485  int ret;
  486  char *nl_charset;
  487  iconv_t iconv_ret= (iconv_t) -1;
  488 
  489  nl_charset= nl_langinfo(CODESET);
  490  if(name == NULL)
  491    name= nl_charset;
  492  if(name == NULL)
  493    goto cannot;
  494 
  495  iconv_ret= iconv_open(nl_charset, name);
  496  if(iconv_ret == (iconv_t) -1)
  497    goto cannot;
  498  else
  499    iconv_close(iconv_ret);
  500  ret= iso_set_local_charset(name, 0);
  501  if(ret <= 0) {
  502 cannot:;
  503    sprintf(xorriso->info_text,
  504            "-local_charset: Cannot assume as local character set: ");
  505    if(name != NULL)
  506      Text_shellsafe(name, xorriso->info_text, 1);
  507    else
  508      Text_shellsafe("(NULL-pointer)", xorriso->info_text, 1);
  509    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
  510    return(0);
  511  }
  512  sprintf(xorriso->info_text, "Local character set is now assumed as: ");
  513  Text_shellsafe(name, xorriso->info_text, 1);
  514  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
  515  return(1);
  516 }
  517 
  518 
  519 int Xorriso_process_msg_queues(struct XorrisO *xorriso, int flag)
  520 {
  521  int ret, error_code= 0, os_errno= 0, count= 0, pass, imgid, tunneled;
  522  int name_prefix_code;
  523  char severity[80], *text= NULL;
  524 
  525 #ifdef Xorriso_fetch_with_msg_queueS
  526  int locked= 0, uret;
  527 #endif
  528 
  529 #ifdef Xorriso_with_libjtE
  530  char *msg;
  531 #endif
  532 
  533  if(!xorriso->libs_are_started) {
  534    ret= 1; goto ex;
  535  }
  536 
  537 #ifdef Xorriso_fetch_with_msg_queueS
  538 
  539  Xorriso_alloc_meM(text, char, sizeof(xorriso->info_text));
  540 
  541  ret= pthread_mutex_lock(&(xorriso->lib_msg_queue_lock));
  542  if(ret != 0) {
  543    Xorriso_msgs_submit(xorriso, 0,
  544              "Cannot acquire mutex lock for processing library message queues",
  545                ret, "FATAL", 0);
  546  } else
  547    locked= 1;
  548 
  549 #else /* Xorriso_fetch_with_msg_queueS */
  550 
  551  text= xorriso->info_text;
  552 
  553 #endif /* ! Xorriso_fetch_with_msg_queueS */
  554 
  555 
  556  for(pass= 0; pass< 3; pass++) {
  557    while(1) {
  558      tunneled= 0;
  559      if(pass==0) {
  560 #ifdef Xorriso_with_libjtE
  561        ret= 0;
  562        if(xorriso->libjte_handle != NULL) {
  563          msg= libjte_get_next_message(xorriso->libjte_handle);
  564          if(msg != NULL) {
  565            sprintf(text, "%1.4095s", msg);
  566            free(msg);
  567            strcpy(severity, "NOTE");
  568            error_code= 0;
  569            os_errno= 0;
  570            ret= 1;
  571          }
  572        }
  573 #else
  574    break;
  575 #endif /* ! Xorriso_with_libjtE */
  576 
  577      } else if(pass==1)
  578        ret= iso_obtain_msgs("ALL", &error_code, &imgid, text, severity);
  579      else {
  580        ret= burn_msgs_obtain("ALL", &error_code, text, &os_errno, severity);
  581        if((error_code>=0x00030000 && error_code<0x00040000) ||
  582           (error_code>=0x00050000 && error_code<0x00060000))
  583          tunneled= -1; /* "libisofs:" */
  584        else if(error_code>=0x00060000 && error_code<0x00070000)
  585          tunneled= 1;  /* "libisoburn:" */
  586      }
  587      if(ret<=0)
  588    break;
  589 
  590      /* <<< tunneled MISHAP from libisoburn through libburn
  591             or well known error codes of MISHAP events
  592             With libburn-0.4.4 this is not necessary */
  593      if(error_code==0x5ff73 || error_code==0x3ff73 ||
  594         error_code==0x3feb9 || error_code==0x3feb2)
  595        strcpy(severity, "MISHAP");
  596      else if(error_code==0x51001)
  597        strcpy(severity, "ERRFILE");
  598 
  599 #ifdef Xorriso_with_libjtE
  600      if(pass == 0)
  601        name_prefix_code= 0;
  602      else
  603        name_prefix_code= pass + tunneled;
  604 #else
  605      name_prefix_code= pass + tunneled;
  606 #endif /* Xorriso_with_libjtE */
  607      Xorriso_msgs_submit(xorriso, error_code, text, os_errno, 
  608                          severity, name_prefix_code << 2);
  609      count++;
  610    }
  611  }
  612  if(xorriso->library_msg_direct_print && count>0) {
  613    sprintf(text,"   (%d library messages repeated by xorriso)\n", count);
  614 
  615 #ifdef Xorriso_fetch_with_msg_queueS
  616 
  617    Xorriso_msgs_submit(xorriso, 0, text, 0, "NOTE", 256);
  618 
  619 #else /* Xorriso_fetch_with_msg_queueS */
  620 
  621    Xorriso_info(xorriso, 0);
  622 
  623 #endif /* Xorriso_fetch_with_msg_queueS */
  624 
  625  }
  626  ret= 1;
  627 ex:;
  628 
  629 #ifdef Xorriso_fetch_with_msg_queueS
  630 
  631  if(locked) {
  632    uret= pthread_mutex_unlock(&(xorriso->lib_msg_queue_lock));
  633    if(uret != 0) {
  634      Xorriso_msgs_submit(xorriso, 0,
  635              "Cannot release mutex lock for processing library message queues",
  636               uret, "FATAL", 0);
  637      ret= -1;
  638    }
  639  }
  640  Xorriso_free_meM(text);
  641 
  642 #endif /* Xorriso_fetch_with_msg_queueS */
  643 
  644  return(ret);
  645 }
  646 
  647 
  648 int Xorriso_md5_start(struct XorrisO *xorriso, void **ctx, int flag)
  649 {
  650  int ret;
  651 
  652  ret= iso_md5_start(ctx);
  653  if(ret == 1)
  654    return(1);
  655  Xorriso_no_malloc_memory(xorriso, NULL, 0);
  656  return(-1);
  657 }
  658 
  659 
  660 int Xorriso_md5_compute(struct XorrisO *xorriso, void *ctx,
  661                         char *data, int datalen, int flag)
  662 {
  663  iso_md5_compute(ctx, data, datalen);
  664  return(1);
  665 }
  666 
  667 
  668 int Xorriso_md5_end(struct XorrisO *xorriso, void **ctx, char md5[16],
  669                     int flag)
  670 {
  671  int ret;
  672 
  673  ret= iso_md5_end(ctx, md5);
  674  Xorriso_process_msg_queues(xorriso,0);
  675  if(ret <= 0)
  676    return(0);
  677  return(1);
  678 }
  679 
  680 
  681 /* @param flag  bit0= avoid library calls
  682  */
  683 int Xorriso_preparer_string(struct XorrisO *xorriso, char xorriso_id[129],
  684                             int flag)
  685 {
  686  int major, minor, micro;
  687 
  688  xorriso_id[0]= 0;
  689  sprintf(xorriso_id, "XORRISO-%d.%d.%d ",
  690          Xorriso_header_version_majoR, Xorriso_header_version_minoR,
  691          Xorriso_header_version_micrO);
  692  if(strlen(xorriso_id) + strlen(Xorriso_timestamP) < 128)
  693    strcat(xorriso_id, Xorriso_timestamP);
  694  if(flag & 1)
  695    return(1);
  696  isoburn_version(&major, &minor, &micro);
  697  if(strlen(xorriso_id) < 100)
  698    sprintf(xorriso_id + strlen(xorriso_id),
  699            ", LIBISOBURN-%d.%d.%d", major, minor, micro);
  700  iso_lib_version(&major, &minor, &micro);
  701  if(strlen(xorriso_id) < 100)
  702    sprintf(xorriso_id + strlen(xorriso_id),
  703            ", LIBISOFS-%d.%d.%d", major, minor, micro);
  704  burn_version(&major, &minor, &micro);
  705  if(strlen(xorriso_id) < 100)
  706    sprintf(xorriso_id + strlen(xorriso_id),
  707            ", LIBBURN-%d.%d.%d", major, minor, micro);
  708  return(1);
  709 }
  710 
  711 
  712 #ifdef Xorriso_with_libjtE
  713 
  714 int Xorriso_assert_jte_handle(struct XorrisO *xorriso, int flag)
  715 {
  716  int ret;
  717  
  718  if(xorriso->libjte_handle == NULL) {
  719    ret= libjte_new(&(xorriso->libjte_handle), 0);
  720    if(ret <= 0 || xorriso->libjte_handle == NULL) {
  721      sprintf(xorriso->info_text,
  722              "-jigdo: Failed to create libjte environment object"); 
  723      Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
  724      return(-1);
  725    }
  726    /* no stderr, no exit() */
  727    libjte_set_error_behavior(xorriso->libjte_handle, 0, 0);
  728  }
  729  return(1);
  730 }
  731 
  732 #endif /* Xorriso_with_libjtE */
  733 
  734 
  735 int Xorriso_jigdo_interpreter(struct XorrisO *xorriso, char *aspect, char *arg,
  736                          int flag)
  737 {
  738 
  739 #ifdef Xorriso_with_libjtE
  740 
  741  int ret, num;
  742  struct libjte_env *jte;
  743  char *msg = NULL;
  744 
  745  if(strcmp(aspect, "clear") == 0) {
  746    if(xorriso->libjte_handle != NULL)
  747    libjte_destroy(&(xorriso->libjte_handle));
  748    Xorriso_lst_destroy_all(&(xorriso->jigdo_params), 0);
  749    Xorriso_lst_destroy_all(&(xorriso->jigdo_values), 0);
  750    xorriso->libjte_params_given= 0;
  751    return(1);
  752  }
  753  ret= Xorriso_assert_jte_handle(xorriso, 0);
  754  if(ret <= 0)
  755    return(ret);
  756  jte= xorriso->libjte_handle;
  757 
  758  if(strcmp(aspect, "verbose") == 0) {
  759    if(strcmp(arg, "on") == 0) {
  760      libjte_set_verbose(jte, 1);
  761      /* Direct libjte messages to stderr, rather than message list */
  762      libjte_set_error_behavior(xorriso->libjte_handle, 1, 0);
  763      xorriso->libjte_params_given|= 2;
  764    } else if(strcmp(arg, "off") == 0) {
  765      libjte_set_verbose(jte, 0);
  766      libjte_set_error_behavior(xorriso->libjte_handle, 0, 0);
  767      xorriso->libjte_params_given&= ~2;
  768    } else
  769      goto bad_arg;
  770  } else if(strcmp(aspect, "template_path") == 0 ||
  771            strcmp(aspect, "-jigdo-template") == 0) {
  772    ret= libjte_set_template_path(jte, arg);
  773    if(ret <= 0)
  774      goto jte_failed;
  775    xorriso->libjte_params_given|= 4;
  776  } else if(strcmp(aspect, "jigdo_path") == 0 ||
  777            strcmp(aspect, "-jigdo-jigdo") == 0) {
  778    ret= libjte_set_jigdo_path(jte, arg);
  779    if(ret <= 0)
  780      goto jte_failed;
  781    xorriso->libjte_params_given|= 8;
  782  } else if(strcmp(aspect, "md5_path") == 0 ||
  783            strcmp(aspect, "-md5-list") == 0 ||
  784            strcmp(aspect, "checksum_path") == 0 ||
  785            strcmp(aspect, "-checksum-list") == 0) {
  786    ret= libjte_set_checksum_path(jte, arg);
  787    if(ret <= 0)
  788      goto jte_failed;
  789    xorriso->libjte_params_given|= 16;
  790  } else if(strcmp(aspect, "min_size") == 0 ||
  791            strcmp(aspect, "-jigdo-min-file-size") == 0) {
  792    num= Scanf_io_size(arg, 0);
  793    ret= libjte_set_min_size(jte, num);
  794    if(ret <= 0)
  795      goto jte_failed;
  796    xorriso->libjte_params_given|= 32;
  797  } else if(strcmp(aspect, "checksum_iso") == 0 ||
  798            strcmp(aspect, "-checksum_algorithm_iso") == 0) {
  799    ret= libjte_set_checksum_iso(jte, arg);
  800    if(ret <= 0)
  801      goto jte_failed;
  802    xorriso->libjte_params_given|= 64;
  803  } else if(strcmp(aspect, "checksum_template") == 0 ||
  804            strcmp(aspect, "-checksum_algorithm_template") == 0) {
  805    ret= libjte_set_checksum_template(jte, arg);
  806    if(ret <= 0)
  807      goto jte_failed;
  808    xorriso->libjte_params_given|= 128;
  809  } else if(strcmp(aspect, "compression") == 0 ||
  810            strcmp(aspect, "-jigdo-template-compress") == 0) {
  811    ret= libjte_set_compression(jte, arg);
  812    if(ret <= 0)
  813      goto jte_failed;
  814    xorriso->libjte_params_given|= 256;
  815  } else if(strcmp(aspect, "exclude") == 0 ||
  816            strcmp(aspect, "-jigdo-exclude") == 0) {
  817    ret= libjte_add_exclude(jte, arg);
  818    if(ret <= 0)
  819      goto jte_failed;
  820    xorriso->libjte_params_given|= 512;
  821  } else if(strcmp(aspect, "demand_md5") == 0 ||
  822            strcmp(aspect, "-jigdo-force-md5") == 0 ||
  823            strcmp(aspect, "demand_checksum") == 0 ||
  824            strcmp(aspect, "-jigdo-force-checksum") == 0) {
  825    ret= libjte_add_checksum_demand(jte, arg);
  826    if(ret <= 0)
  827      goto jte_failed;
  828    xorriso->libjte_params_given|= 1024;
  829  } else if(strcmp(aspect, "mapping") == 0 ||
  830            strcmp(aspect, "-jigdo-map") == 0) {
  831    ret= libjte_add_mapping(jte, arg);
  832    if(ret <= 0)
  833      goto jte_failed;
  834    xorriso->libjte_params_given|= 2048;
  835  } else if(strcmp(aspect, "checksum_algorithm") == 0 ||
  836            strcmp(aspect, "-jigdo-checksum-algorithm") == 0) {
  837    int ck_size;
  838    ret= libjte_set_checksum_algorithm(jte, arg, &ck_size);
  839    if(ret <= 0)
  840      goto jte_failed;
  841    xorriso->libjte_params_given|= 4096;
  842  } else {
  843    sprintf(xorriso->info_text, "-jigdo: unknown aspect '%s'", aspect); 
  844    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  845    return(0);
  846  }
  847 
  848  ret= Xorriso_lst_new(&(xorriso->jigdo_params), aspect, xorriso->jigdo_params,
  849                       1);
  850  if(ret > 0)
  851    ret= Xorriso_lst_new(&(xorriso->jigdo_values), arg, xorriso->jigdo_values,
  852                         1);
  853  if(ret <= 0) {
  854    Xorriso_no_malloc_memory(xorriso, NULL, 0);
  855    return(-1);
  856  }
  857  Xorriso_process_msg_queues(xorriso, 0);
  858  return(1);
  859 
  860 bad_arg:
  861  sprintf(xorriso->info_text, "-jigdo %s : unknown argument '%s'", aspect, arg);
  862  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  863  return(0);
  864 
  865 jte_failed:
  866  while(1) {
  867    msg= libjte_get_next_message(xorriso->libjte_handle);
  868    if(msg == NULL)
  869  break;
  870    sprintf(xorriso->info_text, "%1.4095s", msg);
  871    free(msg);
  872    msg= NULL;
  873    Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  874  }
  875  sprintf(xorriso->info_text, "Experienced libjte failure with: -jigdo %s %s",
  876          aspect, arg);
  877  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  878  return(0);
  879 
  880 #else /* Xorriso_with_libjtE */
  881 
  882  sprintf(xorriso->info_text,
  883          "Jigdo Template Extraction was not enabled at compile time");
  884  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
  885  return(0);
  886 
  887 #endif /* ! Xorriso_with_libjtE */
  888 
  889 }
  890 
  891 
  892 int Xorriso_list_extras_result(struct XorrisO *xorriso, char *mode,
  893                                char *what, int flag)
  894 {
  895  if(mode[0] != 0 && strcmp(mode, "all") != 0) {
  896    if(strcmp(mode, what) != 0 &&
  897       (mode[0] != '-' || strcmp(mode + 1, what) != 0)) 
  898      return(2);
  899  }
  900  Xorriso_result(xorriso, 0);
  901  return(1);
  902 }
  903 
  904 
  905 int Xorriso_list_extras(struct XorrisO *xorriso, char *mode, int flag)
  906 {
  907  int ret;
  908 
  909  if(strcmp(mode, "codes") == 0) {
  910    sprintf(xorriso->result_line,
  911         "List of xorriso extra feature codes. Usable with or without dash.\n");
  912    Xorriso_result(xorriso, 0);
  913    sprintf(xorriso->result_line, "Local ACL    : -acl\n");
  914    Xorriso_result(xorriso, 0);
  915    sprintf(xorriso->result_line, "Local xattr  : -xattr\n");
  916    Xorriso_result(xorriso, 0);
  917    sprintf(xorriso->result_line, "Jigdo files  : -jigdo\n");
  918    Xorriso_result(xorriso, 0);
  919    sprintf(xorriso->result_line, "zisofs       : -zisofs\n");
  920    Xorriso_result(xorriso, 0);
  921    sprintf(xorriso->result_line, "Ext. filters : -external_filter\n");
  922    Xorriso_result(xorriso, 0);
  923    sprintf(xorriso->result_line, "DVD obs 64 kB: -dvd_obs\n");
  924    Xorriso_result(xorriso, 0);
  925    sprintf(xorriso->result_line, "Readline     : -use_readline\n");
  926    Xorriso_result(xorriso, 0);
  927    return(1);
  928  }
  929  sprintf(xorriso->result_line,
  930          "List of xorriso extra features. yes = enabled , no = disabled\n");
  931  Xorriso_list_extras_result(xorriso, mode, "list_extras", 0);
  932 
  933  ret= iso_local_attr_support(3);
  934  sprintf(xorriso->result_line, "Local ACL    : %s\n", ret & 1 ? "yes" : "no");
  935  Xorriso_list_extras_result(xorriso, mode, "acl", 0);
  936  sprintf(xorriso->result_line, "Local xattr  : %s\n", ret & 2 ? "yes" : "no");
  937  Xorriso_list_extras_result(xorriso, mode, "xattr", 0);
  938  
  939  sprintf(xorriso->result_line, "Jigdo files  : %s\n",
  940 #ifdef Xorriso_with_libjtE
  941          "yes");
  942 #else
  943          "no");
  944 #endif
  945  Xorriso_list_extras_result(xorriso, mode, "jigdo", 0);
  946 
  947  ret= iso_file_add_zisofs_filter(NULL, 4);
  948  sprintf(xorriso->result_line, "zisofs       : %s\n", ret == 2 ? "yes" : "no");
  949  Xorriso_list_extras_result(xorriso, mode, "zisofs", 0);
  950 
  951  sprintf(xorriso->result_line, "Ext. filters : %s\n",
  952 #ifdef Xorriso_allow_external_filterS
  953 #ifdef Xorriso_allow_extf_suiD
  954          "yes , setuid allowed");
  955 #else
  956          "yes , setuid banned");
  957 #endif
  958 #else
  959          "no");
  960 #endif
  961  Xorriso_list_extras_result(xorriso, mode, "external_filter", 0);
  962 
  963  sprintf(xorriso->result_line, "DVD obs 64 kB: %s\n",
  964 #ifdef Xorriso_dvd_obs_default_64K
  965          "yes");
  966 #else
  967          "no");
  968 #endif
  969  Xorriso_list_extras_result(xorriso, mode, "dvd_obs", 0);
  970 
  971  sprintf(xorriso->result_line, "Readline     : %s\n",
  972 #ifdef Xorriso_with_editlinE
  973          "yes , libedit");
  974 #else
  975 #ifdef Xorriso_with_readlinE
  976          "yes");
  977 #else
  978          "no");
  979 #endif
  980 #endif
  981  Xorriso_list_extras_result(xorriso, mode, "use_readline", 0);
  982 
  983  return(1);
  984 }
  985 
  986 
  987 /* @param flag bit0= set num_tiles to default value
  988                bit1= set tile_blocks to default value
  989 */
  990 int Xorriso_set_data_cache(struct XorrisO *xorriso, void *o,
  991                            int num_tiles, int tile_blocks, int flag)
  992 {
  993  int ret, tiles, blocks, set_flag;
  994  struct isoburn_read_opts *ropts;
  995 
  996  ropts= (struct isoburn_read_opts *) o;
  997  if(flag & (1 | 2)) {
  998    isoburn_ropt_get_data_cache(ropts, &tiles, &blocks, &set_flag, 1);
  999    if(flag & 1)
 1000      num_tiles= tiles;
 1001    if(flag & 2)
 1002      tile_blocks= blocks;
 1003  }
 1004  ret= isoburn_ropt_set_data_cache(ropts, num_tiles, tile_blocks, 0);
 1005  return(ret);
 1006 }
 1007 
 1008 
 1009 int Xorriso_format_guid(struct XorrisO *xorriso, uint8_t guid[16], char *line,
 1010                         int flag)
 1011 {
 1012 
 1013  /* >>> Maybe let the user switch between hex string and structured text */;
 1014 
 1015  Xorriso__format_guid(guid, line, 1);
 1016  return(1);
 1017 }
 1018 
 1019 
 1020 int Xorriso_make_guid(struct XorrisO *xorriso, char *line, int flag)
 1021 {
 1022  uint8_t guid[16];
 1023  int ret;
 1024 
 1025  iso_generate_gpt_guid(guid);
 1026  ret= Xorriso_format_guid(xorriso, guid, line, 0);
 1027  return(ret);
 1028 }
 1029 
 1030 
 1031 int Xorriso_set_libisofs_now(struct XorrisO *xorriso, int flag)
 1032 {
 1033  int ret;
 1034  time_t now;
 1035 
 1036  if(xorriso->do_override_now_time) {
 1037    now= xorriso->now_time_override;
 1038    ret= iso_nowtime(&now, 1);
 1039  } else {
 1040    ret= iso_nowtime(&now, 0);
 1041  }
 1042  return(ret);
 1043 }
 1044