libisoburn  1.5.4
About: libisoburn is a frontend for the libraries libburn and libisofs which enables creation and expansion of ISO-9660 filesystems on all media and file types supported by libburn. It implements the API and command interpreter of program xorriso, and installs this program as small dynamically linked binary. xorriso is suitable for incremental data backup and for production of bootable ISO 9660 images. A statically linked version is available as GNU xorriso.
  Fossies Dox: libisoburn-1.5.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

text_io.c
Go to the documentation of this file.
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 the implementation of text i/o functions.
9 */
10 
11 #ifdef HAVE_CONFIG_H
12 #include "../config.h"
13 #endif
14 
15 #include <ctype.h>
16 #include <sys/types.h>
17 #include <unistd.h>
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 #include <sys/stat.h>
22 #include <sys/time.h>
23 #include <time.h>
24 #include <errno.h>
25 #include <signal.h>
26 #include <pthread.h>
27 #include <fcntl.h>
28 
29 /* O_BINARY is needed for Cygwin but undefined elsewhere */
30 #ifndef O_BINARY
31 #define O_BINARY 0
32 #endif
33 
34 
35 /* for -charset */
36 #include <iconv.h>
37 #include <langinfo.h>
38 #include <locale.h>
39 
40 
41 #ifdef Xorriso_with_readlinE
42 #ifdef Xorriso_with_old_readlinE
43 #include <readline.h>
44 #include <history.h>
45 #else /* Xorriso_with_old_readlinE */
46 #include <readline/readline.h>
47 #include <readline/history.h>
48 #endif /* ! Xorriso_with_old_readlinE */
49 #define Xorriso_with_line_editoR yes
50 #endif /* Xorriso_with_readlinE */
51 
52 #ifdef Xorriso_with_editlinE
53 #include <histedit.h>
54 #define Xorriso_with_line_editoR yes
55 #endif /* Xorriso_with_editlinE */
56 
57 
58 #include "xorriso.h"
59 #include "xorriso_private.h"
60 #include "xorrisoburn.h"
61 
62 
63 int Xorriso_protect_stdout(struct XorrisO *xorriso, int flag)
64 {
65  if(xorriso->dev_fd_1>=0)
66  return(2);
67  xorriso->dev_fd_1= dup(1);
68  close(1);
69  dup2(2,1);
70  return(1);
71 }
72 
73 #ifdef Xorriso_with_editlinE
74 
75 /* These have to be global and shared by all XorrisOs which might be active.
76 */
77 static EditLine *editline_handle= NULL;
78 static History *editline_history= NULL;
79 static int editline_is_initialized= 0;
80 
81 
82 char *Xorriso__editline_prompt(EditLine *el_handle)
83 {
84  return "";
85 }
86 
87 
88 void Xorriso_init_editline(struct XorrisO *xorriso, int flag)
89 {
90  HistEvent ev;
91 
92  /* >>> Need mutex */
93 
94  if(editline_is_initialized != 0)
95  return;
96  editline_is_initialized= -1; /* Invalid */
97 
98  editline_handle= el_init(xorriso->progname, stdin, stdout, stderr);
99  if(editline_handle == NULL)
100  return;
101  el_set(editline_handle, EL_EDITOR, "emacs");
102  el_set(editline_handle, EL_PROMPT, &Xorriso__editline_prompt);
103 
104  editline_history= history_init();
105  if(editline_history == NULL)
106  return;
107  history(editline_history, &ev, H_SETSIZE, 1000);
108  el_set(editline_handle, EL_HIST, history, editline_history);
109 
110  editline_is_initialized= 1; /* Valid now */
111  return;
112 }
113 
114 
115 int Xorriso__shutdown_editline(int flag)
116 {
117  if(editline_history != NULL)
118  history_end(editline_history);
119  editline_history= NULL;
120  if(editline_handle != NULL)
121  el_end(editline_handle);
122  editline_handle= NULL;
123  editline_is_initialized= 0;
124  return(1);
125 }
126 
127 #endif /* Xorriso_with_editlinE */
128 
129 #ifdef Xorriso_with_readlinE
130 
131 /* http://lists.gnu.org/archive/html/bug-readline/2014-06/msg00005.html */
132 const char *Xorriso__readline_license(int flag)
133 {
134 #ifdef RL_VERSION_MAJOR
135 #if RL_VERSION_MAJOR > 5
136 
137  return("GPLv3+");
138 
139 #endif
140 #endif
141 
142  return("GPLv2+");
143 }
144 
145 #endif /* Xorriso_with_readlinE */
146 
147 #ifdef Xorriso_with_line_editoR
148 
149 char *Xorriso_emul_readline(struct XorrisO *xorriso, int flag)
150 {
151 
152 #ifdef Xorriso_with_editlinE
153 
154  const char *cpt;
155  int count= 0;
156  char *retpt;
157 
158  /* >>> Need mutex */
159 
160  Xorriso_init_editline(xorriso, 0);
161  if(editline_is_initialized < 0) {
162 
163  /* >>> fallback */;
164 
165  }
166 
167  cpt= el_gets(editline_handle, &count);
168  if(count == -1 || cpt == NULL)
169  return(NULL);
170  retpt= calloc(1, count + 1);
171  if(retpt == NULL)
172  return(NULL);
173  memcpy(retpt, cpt, count);
174  retpt[count]= 0;
175  return(retpt);
176 
177 #else
178 
179 #ifdef Xorriso_with_readlinE
180 
181  char *cpt;
182 
183  cpt= readline("");
184  return(cpt);
185 
186 #else
187 
188  return(NULL);
189 
190 #endif /* ! Xorriso_with_readlinE */
191 #endif /* ! Xorriso_with_editlinE */
192 }
193 
194 
195 void Xorriso_emul_add_history(struct XorrisO *xorriso, char *line, int flag)
196 {
197 #ifdef Xorriso_with_editlinE
198 
199  HistEvent ev;
200 
201  /* >>> Need mutex */
202 
203  Xorriso_init_editline(xorriso, 0);
204  if(editline_is_initialized < 0)
205  return;
206 
207  history(editline_history, &ev, H_ENTER, line);
208 
209 #else
210 
211 #ifdef Xorriso_with_readlinE
212 
213  add_history(line);
214 
215 #else
216 
217  /* ??? How to raise protest ? */;
218 
219 #endif /* ! Xorriso_with_readlinE */
220 #endif /* ! Xorriso_with_editlinE */
221 }
222 
223 
224 /* @param flag bit1= do only report to fp
225 */
226 int Xorriso_status_history(struct XorrisO *xorriso, char *filter, FILE *fp,
227  int flag)
228 {
229 
230 #ifdef Xorriso_with_editlinE
231 
232  int ret, l;
233  HistEvent ev;
234  int hc, i, was_end= 0;
235  char *str= NULL;
236 
237 
238  /* >>> Need mutex */
239 
240  Xorriso_init_editline(xorriso, 0);
241  if(editline_is_initialized < 0)
242  {ret= 0; goto ex;}
243 
244  Xorriso_alloc_meM(str, char, SfileadrL);
245 
246  ret= history(editline_history, &ev, H_LAST);
247  for(hc= 0; ret != -1; hc++) {
248  ret= history(editline_history, &ev, H_PREV);
249  was_end = (strcmp(ev.str, "-end") == 0);
250  }
251  if(was_end)
252  hc--;
253  if(hc >= xorriso->status_history_max)
254  i= hc - xorriso->status_history_max;
255  else
256  i= 0;
257 
258  ret= history(editline_history, &ev, H_LAST);
259  for(; i < hc && ret != -1; i++) {
260  /* Eat newline at line end */
261  strncpy(str, ev.str, SfileadrL - 1);
262  str[SfileadrL - 1]= 0;
263  l= strlen(str);
264  if(l > 0)
265  if(str[l - 1] == '\n')
266  str[l - 1]= 0;
267 
268  sprintf(xorriso->result_line, "-history ");
269  Text_shellsafe(str, xorriso->result_line, 1);
270  strcat(xorriso->result_line, "\n");
271  Xorriso_status_result(xorriso, filter, fp, flag & 2);
272  ret= history(editline_history, &ev, H_PREV);
273  }
274  ret= 1;
275 ex:;
276  Xorriso_free_meM(str);
277  return(ret);
278 
279 #else
280 #ifdef Xorriso_with_readlinE
281 
282  HIST_ENTRY **hl;
283  int hc, i;
284 
285  hl= history_list();
286  if(hl != NULL) {
287  for(hc= 0; hl[hc] != NULL; hc++);
288  if(hc > 0)
289  if(strcmp(hl[hc-1]->line, "-end") == 0)
290  hc--;
291  if(hc >= xorriso->status_history_max)
292  i= hc - xorriso->status_history_max;
293  else
294  i= 0;
295  for(; i < hc; i++) {
296  sprintf(xorriso->result_line, "-history ");
297  Text_shellsafe(hl[i]->line, xorriso->result_line, 1);
298  strcat(xorriso->result_line, "\n");
299  Xorriso_status_result(xorriso, filter, fp, flag & 2);
300  }
301  }
302  return(1);
303 
304 #else /* Xorriso_with_readlinE */
305 
306  return(0);
307 
308 #endif /* ! Xorriso_with_readlinE */
309 #endif /* ! Xorriso_with_editlinE */
310 
311 }
312 
313 #endif /* Xorriso_with_line_editoR */
314 
315 
316 int Xorriso_dialog_input(struct XorrisO *xorriso, char line[], int linesize,
317  int flag)
318 /*
319  bit0= do not write to history
320  bit1= do not read input (but eventually write to history)
321  bit2= do not write to history line which begin with "-history:" or "-history "
322  bit3= enforce single line dialog mode
323  bit4= do not read from xorriso->buffered_dialog
324  bit5= write to history in any case (if it is enabled at compile time)
325 */
326 {
327  char **argv= NULL, *linept, *why_append= "";
328  int ret, argc= 0, base_length= 0, l, append_line;
329 #ifdef Xorriso_with_line_editoR
330  static char last_input[SfileadrL]= {""};
331  int no_history= 0;
332  char *cpt= NULL;
333 #endif /* Xorriso_with_line_editoR */
334  double tdiff;
335  struct timeval tv;
336  struct Xorriso_lsT *next_lst;
337 
338  gettimeofday(&tv, NULL);
339  tdiff= tv.tv_sec+(1.e-6*(double) tv.tv_usec);
340 
341  fflush(stdout);
342  linept= line;
343 
344 #ifdef Xorriso_with_line_editoR
345  no_history= (flag & 1) || xorriso->use_stdin;
346 #endif
347 
348 get_single:;
349 
350  if(xorriso->buffered_dialog != NULL && !(flag & (16 | 2))) {
351  /* Consume next buffered line */
352  next_lst= Xorriso_lst_get_next(xorriso->buffered_dialog, 0);
353  strcpy(line, Xorriso_lst_get_text(xorriso->buffered_dialog, 0));
354  Xorriso_lst_destroy(&(xorriso->buffered_dialog), 0);
355  xorriso->buffered_dialog= next_lst;
356  goto process_single;
357  }
358 
359 #ifdef Xorriso_with_line_editoR
360 
361  if(xorriso->use_stdin || xorriso->dev_fd_1>=0 ||
362  xorriso->tolerate_stdin_eof) {
363  if(flag&2) {
364  if(flag & 32)
365  goto put_into_history;
366  {ret= 1; goto ex;}
367  }
368  if(Sfile_fgets_n(linept,linesize - base_length - 1, stdin,
369  (xorriso->dialog == 2)) == NULL) {
370  if(xorriso->tolerate_stdin_eof)
371  {ret= -2; goto ex;}
372  /* need a very dramatic end */
373  kill(getpid(),SIGHUP);
374  {ret= -1; goto ex;}
375  }
376  goto process_single;
377  }
378  if(flag&2) {
379  cpt= NULL;
380  } else {
381  cpt= Xorriso_emul_readline(xorriso, 0);
382  if(cpt==NULL) {
383  /* need a very dramatic end */
384  kill(getpid(),SIGHUP);
385  {ret= -1; goto ex;}
386  }
387  l= strlen(cpt);
388  if(l >= linesize - base_length - 1) {
389  strncpy(linept, cpt, linesize - 1);
390  line[linesize - 1]= 0;
391  sprintf(xorriso->info_text,"Input line too long !");
392  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
393  goto new_empty;
394  } else
395  strcpy(linept, cpt);
396  }
397 
398 #else /* Xorriso_with_line_editoR */
399 
400  if(flag&2)
401  {ret= 1; goto ex;}
402  if(Sfile_fgets_n(linept, linesize - base_length - 1, stdin,
403  (xorriso->dialog == 2)) == NULL) {
404  if(xorriso->tolerate_stdin_eof)
405  {ret= -2; goto ex;}
406  /* need a very dramatic end */
407  kill(getpid(),SIGHUP);
408  {ret= -1; goto ex;}
409  }
410 
411 #endif /* ! Xorriso_with_line_editoR */
412 
413 process_single:;
414 
415  if(xorriso->dialog == 2 && !(flag & 8)) {
416  append_line= 0;
417  if(linept != line && strcmp(linept, "@@@") == 0) {
418  sprintf(xorriso->info_text, "Incomplete input line cleared by %s",
419  linept);
420  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE",0);
421 new_empty:;
422  line[0]= 0;
423  linept= line;
424  sprintf(xorriso->info_text, "-------------------------------------\n");
425  Xorriso_info(xorriso,0);
426  sprintf(xorriso->info_text, "Enter new text for empty input line :\n");
427  Xorriso_info(xorriso,0);
428  goto get_single;
429  }
430  l= strlen(line);
431  ret= Sfile_make_argv("", line, &argc, &argv, 16);
432  if(ret < 0)
433  goto ex;
434  if(ret == 0 && !append_line) {
435  /* append a newline character */
436  if(l >= linesize - 1) {
437  sprintf(xorriso->info_text,"Input line too long !");
438  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
439  goto new_empty;
440  }
441  line[l]= '\n';
442  line[l + 1]= 0;
443  append_line= 1;
444  why_append= "Quoted newline char";
445  }
446  if(l > 0 && !append_line)
447  if(line[l - 1] == '\\') {
448  line[l - 1]= 0;
449  append_line= 1;
450  why_append= "Trailing backslash ";
451  }
452  if(append_line) {
453  base_length= strlen(line);
454  linept= line + base_length;
455  sprintf(xorriso->info_text,
456  "---------------------------------------------------------------\n");
457  Xorriso_info(xorriso,0);
458  sprintf(xorriso->info_text,
459  "%s : Enter rest of line (or @@@ to clear it) :\n", why_append);
460  Xorriso_info(xorriso,0);
461  goto get_single;
462  }
463  }
464 
465 #ifdef Xorriso_with_line_editoR
466 
467 put_into_history:;
468  if((flag & 32) || (line[0]!=0 && strcmp(last_input,line)!=0 && !no_history)) {
469  if(!((flag&4) &&
470  (strncmp(line,"-history:",9)==0 || strncmp(line,"-history ",9)==0))) {
471  Xorriso_emul_add_history(xorriso, line, 0);
472  strncpy(last_input,line,sizeof(last_input)-1);
473  last_input[sizeof(last_input)-1]= 0;
474  }
475  }
476 
477 #endif /* Xorriso_with_line_editoR */
478 
479  ret= 1;
480 ex:;
481 
482 #ifdef Xorriso_with_line_editoR
483  if(cpt!=NULL)
484  free(cpt);
485 #endif
486 
487  gettimeofday(&tv, NULL);
488  xorriso->idle_time+= tv.tv_sec+(1.e-6*(double) tv.tv_usec)-tdiff;
489  return(ret);
490 }
491 
492 
493 int Xorriso_request_confirmation(struct XorrisO *xorriso, int flag)
494 /*
495  bit0= important operation going on:
496  demand confirmation of abort, only abort on @@@
497  bit1= mark '@' and '@@' by return 4
498  bit2= accept: i|n= ignore | do not remove , r|y= retry | remove , q|x= abort
499  bit3= @@@ = 'done reading' rather than 'abort'
500  bit4= in non-dialog mode return 6 rather than 1
501 */
502 /* return: <=0 error
503  1= go on | do not remove existing file
504  2= abort
505  3= redo request for confirmation
506  4= see flag bit1
507  (5= skip volume)
508  6= retry failed operation | remove existing file
509  */
510 {
511  int ret;
512  char *line= NULL, *cpt, *previous_line= NULL;
513  char *abort_req_text,*abort_really_text;
514 
515  Xorriso_alloc_meM(line, char, SfileadrL);
516  Xorriso_alloc_meM(previous_line, char, SfileadrL);
517 
518  if(!xorriso->dialog) {
519  if(flag&16)
520  {ret= 6; goto ex;}
521  {ret= 1; goto ex;}
522  }
523  if(flag&8) {
524  abort_req_text= "request to end";
525  abort_really_text= "done reading";
526  } else {
527  abort_req_text= "request to abort";
528  abort_really_text= "abort this command";
529  }
530  ret= Xorriso_dialog_input(xorriso,line, SfileadrL, 1);
531  xorriso->result_line_counter= 0;
532  xorriso->result_page_counter++;
533  if(ret<=0)
534  if(xorriso->result_page_length>0)
535  xorriso->result_page_length= -xorriso->result_page_length;
536 
537  cpt= line;
538  if(strcmp(cpt,"@@@")==0 ||
539  strcmp(cpt,"x")==0 || strcmp(cpt,"X")==0 ||
540  strcmp(cpt,"q")==0 || strcmp(cpt,"Q")==0) {
541  if(flag&1) {
542  strcpy(previous_line,cpt);
543  sprintf(xorriso->info_text,
544  "... [%s = %s registered. Really %s ? (y/n) ] ...\n",
545  cpt,abort_req_text,abort_really_text);
546  Xorriso_info(xorriso,0);
547  ret= Xorriso_dialog_input(xorriso,line, SfileadrL, 1);
548  if(ret<=0)
549  goto ex;
550  cpt= line;
551  if(strcmp(cpt,previous_line)==0 ||
552  ((*cpt=='Y' || *cpt=='y' || *cpt=='j' || *cpt=='J' || *cpt=='1') &&
553  *(cpt+1)==0)) {
554  xorriso->request_to_abort= 1;
555  sprintf(xorriso->info_text,
556  "------- ( %s confirmed )\n",abort_req_text);
557  Xorriso_info(xorriso,0);
558  {ret= 2; goto ex;}
559  }
560  sprintf(xorriso->info_text, "....... ( %s revoked )\n",abort_req_text);
561  Xorriso_info(xorriso,0);
562  {ret= 3; goto ex;}
563  }
564  xorriso->request_to_abort= 1;
565  sprintf(xorriso->info_text,
566 "----------- [%s = request to abort registered. Operation ends ] ------------\n",
567  cpt);
568  Xorriso_info(xorriso,0);
569  {ret= 2; goto ex;}
570  } else if(*cpt=='@') {
571  if(strcmp(cpt,"@@")==0) {
572  goto klammer_affe;
573 
574  } else if(strcmp(cpt,"@")==0) {
575 klammer_affe:;
576  if(xorriso->result_page_length>0)
577  xorriso->result_page_length= -xorriso->result_page_length;
578  if(flag&1) {
579  sprintf(xorriso->info_text,
580 "... [@ = prompt suppression registered. Prompting disabled temporarily ] ...\n");
581  Xorriso_info(xorriso,0);
582  }
583 
584  } else {
585  Xorriso_dialog_input(xorriso,cpt,strlen(line)+1,2); /* write to history */
586  sprintf(xorriso->info_text,
587  "--- Unrecognized input beginning with @. Please enter something else.\n");
588  Xorriso_info(xorriso,0);
589  {ret= 3; goto ex;}
590  }
591  if(flag&2)
592  {ret= 4; goto ex;}
593  if(flag&1)
594  {ret= 3; goto ex;}
595  {ret= 1; goto ex;}
596  } else if(flag&4) {
597 
598  if(strcmp(cpt,"i")==0 || strcmp(cpt,"I")==0 ||
599  strcmp(cpt,"n")==0 || strcmp(cpt,"N")==0 ||
600  *cpt==0) {
601  {ret= 1; goto ex;}
602  } else if(strcmp(cpt,"r")==0 || strcmp(cpt,"R")==0 ||
603  strcmp(cpt,"y")==0 || strcmp(cpt,"Y")==0) {
604  {ret= 6; goto ex;}
605  } else {
606  /* >>> unknown input */
607  sprintf(xorriso->info_text,
608  "--- Please enter one of : empty line, i,n, r,y, q,x, @, @@@\n");
609  Xorriso_info(xorriso,0);
610  {ret= 3; goto ex;}
611  }
612 
613  } else if(*cpt!=0 && !(flag&1)) {
614  Xorriso_dialog_input(xorriso,cpt,strlen(line)+1,2); /* write to history */
615  strcpy(xorriso->pending_option,cpt);
616  xorriso->request_to_abort= 1;
617  sprintf(xorriso->info_text,
618 "-------------- [ Input of option registered. Operation ends ] ---------------\n");
619  Xorriso_info(xorriso,0);
620  {ret= 2; goto ex;}
621 
622  } else if(*cpt!=0) {
623  Xorriso_dialog_input(xorriso,cpt,strlen(line)+1,2); /* write to history */
624  sprintf(xorriso->info_text,
625  "--- Please enter one of : empty line, @, @@@\n");
626  Xorriso_info(xorriso,0);
627  {ret= 3; goto ex;}
628  }
629  ret= 1;
630 ex:;
631  Xorriso_free_meM(line);
632  Xorriso_free_meM(previous_line);
633  return(ret);
634 }
635 
636 
637 /* @param flag bit0= quoted multiline mode
638  bit1= release allocated memory and return 1
639  bit2= with bit0: warn of empty text arguments
640  bit3= deliver as single quoted text including all whitespace
641  and without any backslash interpretation
642  @return -1=out of memory , 0=line format error , 1=ok, go on , 2=done
643 */
644 int Xorriso_read_lines(struct XorrisO *xorriso, FILE *fp, int *linecount,
645  int *argc, char ***argv, int flag)
646 {
647  char *line= NULL, *linept, *fgot;
648  int l, base_length, append_line, ret, mem_linecount, i;
649 
650  Sfile_make_argv("", line, argc, argv, 2);
651  if(flag & 2)
652  {ret= 1; goto ex;}
653 
654  Xorriso_alloc_meM(line, char, 5 * SfileadrL + 2);
655 
656  mem_linecount= *linecount;
657  linept= line;
658  base_length= 0;
659  while(1) {
660  fgot= Sfile_fgets_n(linept, SfileadrL - base_length - 1, fp,
661  !!(flag & (1 | 8)));
662  if(fgot == NULL) {
663  if(ferror(fp))
664  {ret= 0; goto ex;}
665  if(linept != line) {
666  sprintf(xorriso->info_text,"Open quotation mark at end of input");
667  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
668  {ret= 0; goto ex;}
669  }
670  {ret= 2; goto ex;}
671  }
672  l= strlen(line);
673  (*linecount)++;
674  append_line= 0;
675  if(flag & 1) { /* check whether the line is incomplete yet */
676  ret= Sfile_make_argv("", line, argc, argv, 16);
677  if(ret < 0)
678  goto ex;
679  if(ret == 0 && !append_line) {
680  line[l]= '\n';
681  line[l + 1]= 0;
682  append_line= 1;
683  }
684  if(l > 0 && !append_line)
685  if(line[l - 1] == '\\') {
686  line[l - 1]= 0;
687  append_line= 1;
688  }
689  }
690  if(l >= SfileadrL) {
691  sprintf(xorriso->info_text,"Input line too long !");
692  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
693  {ret= 0; goto ex;}
694  }
695  if(!append_line)
696  break;
697  base_length= strlen(line);
698  linept= line + base_length;
699  }
700  if((flag & 1) && !(flag & 8)) {
701  ret= Sfile_make_argv("", line, argc, argv,
702  1 | ((xorriso->bsl_interpretation & 3) << 5));
703  if(ret < 0)
704  goto ex;
705  if(flag & 4)
706  for(i= 0; i < *argc; i++) {
707  if((*argv)[i][0] == 0) {
708  sprintf(xorriso->info_text, "Empty text as quoted argument in ");
709  } else if(strlen((*argv)[i]) >= SfileadrL) {
710  (*argv)[i][SfileadrL - 1]= 0;
711  sprintf(xorriso->info_text,
712  "Input text too long and now truncated in");
713  } else
714  continue;
715  if(mem_linecount + 1 < *linecount)
716  sprintf(xorriso->info_text + strlen(xorriso->info_text),
717  "lines %d to %d", mem_linecount + 1, *linecount);
718  else
719  sprintf(xorriso->info_text + strlen(xorriso->info_text),
720  "line %d", mem_linecount + 1);
721  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
722  }
723  } else {
724  (*argv)= Smem_malloC(sizeof(char *));
725  if(*argv == NULL)
726  {ret= -1; goto ex;}
727  (*argv)[0]= strdup(line);
728  if((*argv)[0] == NULL) {
729  free(*argv);
730  (*argv)= NULL;
731  {ret= -1; goto ex;}
732  }
733  *argc= 1;
734  }
735  ret= 1;
736 ex:;
737  Xorriso_free_meM(line);
738  return(ret);
739 }
740 
741 
742 int Xorriso_predict_linecount(struct XorrisO *xorriso, char *line,
743  int *linecount, int flag)
744 {
745  int width,l;
746  char *spt,*ept;
747 
748  *linecount= 0;
749  spt= line;
750  width= xorriso->result_page_width;
751  while(1) {
752  ept= strchr(spt,'\n');
753  if(ept==NULL)
754  l= strlen(spt);
755  else
756  l= ept-spt;
757  l+= xorriso->result_open_line_len;
758  if(ept!=NULL && l==0)
759  (*linecount)++;
760  else {
761  (*linecount)+= l/width;
762  if(ept==NULL) {
763  xorriso->result_open_line_len= l%width;
764  break;
765  }
766  (*linecount)+= !!(l%width);
767  }
768  xorriso->result_open_line_len= 0;
769  spt= ept+1;
770  }
771  return(1);
772 }
773 
774 
775 int Xorriso_pager(struct XorrisO *xorriso, char *line, int flag)
776 /*
777  bit1= mark '@' by return 4
778 */
779 /* return: <=0 error , 1=go on , 2=abort , 4=see flag bit1*/
780 {
781  int ret,linecount;
782  char *info_text= NULL;
783 
784  if(xorriso->result_page_length<=0 || xorriso->request_not_to_ask ||
785  xorriso->dialog == 0)
786  {ret= 1; goto ex;}
787  Xorriso_predict_linecount(xorriso,line,&linecount,0);
788  if(xorriso->result_line_counter+linecount>xorriso->result_page_length) {
789 ask_for_page:;
790  if(info_text == NULL)
791  Xorriso_alloc_meM(info_text, char, 10*SfileadrL);
792  strcpy(info_text,xorriso->info_text);
793  sprintf(xorriso->info_text,"\n");
794  Xorriso_info(xorriso,0);
795  sprintf(xorriso->info_text,
796 ".... [Press Enter to continue. @,Enter avoids further stops. @@@ aborts] ....\n");
797  Xorriso_info(xorriso,0);
798  ret= Xorriso_request_confirmation(xorriso,flag&2);
799  strcpy(xorriso->info_text,info_text);
800  if(ret<=0)
801  goto ex;
802  if(ret==2)
803  {ret= 2; goto ex;}
804  if(ret==3)
805  goto ask_for_page;
806  }
807  xorriso->result_line_counter+= linecount;
808  ret= 1;
809 ex:;
810  Xorriso_free_meM(info_text);
811  return(ret);
812 }
813 
814 
815 /* @param flag bit0= no error message in case of failure
816 */
817 static int Xorriso_obtain_lock(struct XorrisO *xorriso,
818  pthread_mutex_t *lock_handle,
819  char *purpose, int flag)
820 {
821  int ret;
822  static int complaints= 0, complaint_limit= 5;
823 
824  ret= pthread_mutex_lock(lock_handle);
825  if(ret != 0) {
826  if(flag & 1)
827  return(-1);
828  /* Cannot report failure through the failing message output system */
829  complaints++;
830  if(complaints <= complaint_limit)
831  fprintf(stderr,
832  "xorriso : pthread_mutex_lock() for %s returns %d\n",
833  purpose, ret);
834  return(-1);
835  }
836  return(1);
837 }
838 
839 
840 /* @param flag bit0= no error message in case of failure
841 */
842 static int Xorriso_release_lock(struct XorrisO *xorriso,
843  pthread_mutex_t *lock_handle,
844  char *purpose, int flag)
845 {
846  int ret;
847  static int complaints= 0, complaint_limit= 5;
848 
849  ret= pthread_mutex_unlock(lock_handle);
850  if(ret != 0) {
851  if(flag & 1)
852  return(0);
853  /* Cannot report failure through the failing message output system */
854  complaints++;
855  if(complaints <= complaint_limit)
856  fprintf(stderr,
857  "xorriso : pthread_mutex_unlock() for %s returns %d\n",
858  purpose, ret);
859  return(0);
860  }
861  return(1);
862 }
863 
864 
865 static int Xorriso_lock_outlists(struct XorrisO *xorriso, int flag)
866 {
867  int ret;
868 
869  ret= Xorriso_obtain_lock(xorriso, &(xorriso->result_msglists_lock),
870  "outlists", 0);
871  return(ret);
872 }
873 
874 
875 static int Xorriso_unlock_outlists(struct XorrisO *xorriso, int flag)
876 {
877  int ret;
878 
879  ret= Xorriso_release_lock(xorriso, &(xorriso->result_msglists_lock),
880  "outlists", 0);
881  return(ret);
882 }
883 
884 
885 static int Xorriso_write_to_msglist(struct XorrisO *xorriso,
886  struct Xorriso_lsT **xorriso_msglist,
887  char *text, int flag)
888 {
889  int ret, locked= 0;
890  struct Xorriso_lsT *msglist;
891 
892  ret= Xorriso_lock_outlists(xorriso, 0);
893  if(ret <= 0)
894  goto ex;
895  locked= 1;
896  msglist= *xorriso_msglist;
897  ret= Xorriso_lst_append_binary(&msglist, text, strlen(text) + 1, 0);
898  if(ret <= 0) {
899  ret= -1; goto ex;
900  }
901  if(*xorriso_msglist == NULL)
902  *xorriso_msglist= msglist;
903  ret= 1;
904 ex:;
905  if(locked)
906  Xorriso_unlock_outlists(xorriso, 0);
907  return(ret);
908 }
909 
910 
911 int Xorriso_write_to_channel(struct XorrisO *xorriso,
912  char *in_text, int channel_no, int flag)
913 /*
914  bit0= eventually backslash encode linefeeds
915  bit1= text is the name of the log file for the given channel
916  bit2= text is the name of the consolidated packet log file for all channels
917  bit3= text is the name of the stderr redirection file
918 bit15= with bit1 to bit3: close depicted log file
919 */
920 {
921  char *rpt, *npt, *text= NULL, *line= NULL;
922  int ret= 1, info_redirected= 0, result_redirected= 0, l;
923  char prefix[16];
924  FILE *logfile_fp, *pktlog_fp;
925  static int num_channels= 4;
926  static char channel_prefixes[4][4]= {".","R","I","M"};
927  int Xorriso_sieve_filter_msg(struct XorrisO *xorriso, char *msg, int flag);
928 
929 #ifdef Xorriso_fetch_with_msg_queueS
930  static int complaints= 0, complaint_limit= 5;
931  int locked= 0, uret;
932 #endif
933 
934  text= in_text; /* might change due to backslash encoding */
935 
936  if(channel_no<0 || channel_no>=num_channels)
937  {ret= -1; goto ex;}
938 
939 #ifdef Xorriso_fetch_with_msg_queueS
940  ret= pthread_mutex_lock(&(xorriso->write_to_channel_lock));
941  if(ret != 0) {
942  /* Cannot report failure through the failing message output system */
943  complaints++;
944  if(complaints <= complaint_limit)
945  fprintf(stderr,
946  "xorriso : pthread_mutex_lock() for write_to_channel returns %d\n",
947  ret);
948  /* Intentionally not aborting here */;
949  } else
950  locked= 1;
951 #endif /* Xorriso_fetch_with_msg_queueS */
952 
953  /* Logfiles */
954  logfile_fp= xorriso->logfile_fp[channel_no];
955  pktlog_fp= xorriso->pktlog_fp;
956  if((flag&2) && logfile_fp!=NULL) {
957  fprintf(logfile_fp,
958  "! end ! end ! end ! end ! end ! end ! end ! end xorriso log : %s : %s\n",
959  channel_prefixes[channel_no],Sfile_datestr(time(0),1|2|256));
960  fclose(logfile_fp);
961  xorriso->logfile_fp[channel_no]= logfile_fp= NULL;
962  }
963  if((flag&4) && pktlog_fp!=NULL) {
964  fprintf(pktlog_fp,
965  "I:1:! end ! end ! end ! end ! end ! end ! end ! end xorriso log : %s : %s\n",
966  channel_prefixes[channel_no],Sfile_datestr(time(0),1|2|256));
967  fclose(pktlog_fp);
968  xorriso->pktlog_fp= pktlog_fp= NULL;
969  }
970  if((flag & 8) && xorriso->stderr_fp != NULL) {
971  fclose(xorriso->stderr_fp);
972  xorriso->stderr_fp= NULL;
973  }
974  if(flag&(1<<15))
975  {ret= 1; goto ex;}
976  if((flag&2)) {
977  xorriso->logfile_fp[channel_no]= logfile_fp= fopen(text,"a");
978  if(logfile_fp==NULL)
979  {ret= 0; goto ex;}
980  fprintf(logfile_fp,
981  "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! xorriso log : %s : %s\n",
982  channel_prefixes[channel_no],Sfile_datestr(time(0),1|2|256));
983  fflush(logfile_fp);
984  }
985  if((flag&4)) {
986  xorriso->pktlog_fp= pktlog_fp= fopen(text,"a");
987  if(pktlog_fp==NULL)
988  {ret= 0; goto ex;}
989  fprintf(pktlog_fp,
990  "I:1:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! xorriso log : . : %s\n",
991  Sfile_datestr(time(0),1|2|256));
992  fflush(pktlog_fp);
993  }
994  if(flag & 8) {
995  ret= truncate(text, (off_t) 0);
996  if(ret == -1 && errno != ENOENT)
997  {ret= 0; goto ex;}
998  xorriso->stderr_fp= fopen(text, "a");
999  if(xorriso->stderr_fp == NULL)
1000  {ret= 0; goto ex;}
1001  }
1002  if(flag & (2 | 4 | 8))
1003  {ret= 1; goto ex;}
1004 
1005  /* Eventually perform backslash encoding of non-printable characters */
1006  if(((xorriso->bsl_interpretation & 32) && channel_no == 1) ||
1007  ((xorriso->bsl_interpretation & 64) && channel_no == 2)) {
1008  ret= Sfile_bsl_encoder(&text, text, strlen(text), 1 | 2 | 4);
1009  if(ret <= 0)
1010  {ret= -1; goto ex;}
1011  }
1012 
1013  /* Pick interesting words for the Xorriso_sieve API */
1014  Xorriso_sieve_filter_msg(xorriso, text,
1015  (channel_no > 0 ? channel_no - 1 : 0));
1016 
1017  /* Eventually perform message redirection */
1018  if(xorriso->msglist_stackfill > 0) {
1019  if(xorriso->msglist_flags[xorriso->msglist_stackfill - 1] & 1)
1020  result_redirected= 1;
1021  if(xorriso->msglist_flags[xorriso->msglist_stackfill - 1] & 2)
1022  info_redirected= 1;
1023  }
1024 
1025  /* Non-redirected output */
1026  if(!xorriso->packet_output) {
1027  if(channel_no==1 || channel_no==3) {
1028  if(result_redirected) {
1029  ret= Xorriso_write_to_msglist(xorriso,
1030  &(xorriso->result_msglists[xorriso->msglist_stackfill - 1]),
1031  text, 0);
1032  if(ret <= 0)
1033  { ret= -1; goto ex; }
1034  } else {
1035  printf("%s",text);
1036  fflush(stdout);
1037  }
1038  }
1039  if(channel_no==2 || channel_no==3) {
1040  if(info_redirected) {
1041  ret= Xorriso_write_to_msglist(xorriso,
1042  &(xorriso->info_msglists[xorriso->msglist_stackfill - 1]),
1043  text, 0);
1044  if(ret <= 0)
1045  { ret= -1; goto ex; }
1046  } else {
1047  if(xorriso->stderr_fp != NULL) {
1048  fprintf(xorriso->stderr_fp, "%s", text);
1049  fflush(xorriso->stderr_fp);
1050  } else
1051  fprintf(stderr, "%s", text);
1052  }
1053  }
1054  if(logfile_fp!=NULL) {
1055  fprintf(logfile_fp,"%s",text);
1056  fflush(logfile_fp);
1057  }
1058  if(pktlog_fp==NULL)
1059  {ret= 1; goto ex;}
1060  }
1061  rpt= text;
1062  sprintf(prefix,"%s:x: ",channel_prefixes[channel_no]);
1063  while(*rpt!=0) {
1064  npt= strchr(rpt,'\n');
1065  if(npt==NULL)
1066  prefix[2]= '0';
1067  else
1068  prefix[2]= '1';
1069  if(!result_redirected) {
1070  if(xorriso->packet_output) {
1071  ret= fwrite(prefix,5,1,stdout);
1072  if(ret<=0)
1073  {ret= 0; goto ex;}
1074  }
1075  }
1076  if(pktlog_fp!=NULL) {
1077  ret= fwrite(prefix,5,1,pktlog_fp);
1078  if(ret<=0)
1079  {ret= 0; goto ex;}
1080  }
1081  if(npt==NULL) {
1082  if(xorriso->packet_output) {
1083  if(result_redirected) {
1084  l= strlen(rpt);
1085  Xorriso_alloc_meM(line, char, 5 + l + 1 + 1);
1086  memcpy(line, prefix, 5);
1087  memcpy(line + 5, rpt, l);
1088  line[5 + l] = '\n';
1089  line[5 + l + 1] = 0;
1090  ret= Xorriso_write_to_msglist(xorriso,
1091  &(xorriso->result_msglists[xorriso->msglist_stackfill - 1]),
1092  line, 0);
1093  Xorriso_free_meM(line);
1094  line= NULL;
1095  if(ret <= 0)
1096  { ret= -1; goto ex; }
1097  } else {
1098  ret= fwrite(rpt,strlen(rpt),1,stdout);
1099  if(ret<=0)
1100  {ret= 0; goto ex;}
1101  ret= fwrite("\n",1,1,stdout);
1102  if(ret<=0)
1103  {ret= 0; goto ex;}
1104  }
1105  }
1106  if(pktlog_fp!=NULL) {
1107  ret= fwrite(rpt,strlen(rpt),1,pktlog_fp);
1108  if(ret<=0)
1109  {ret= 0; goto ex;}
1110  ret= fwrite("\n",1,1,pktlog_fp);
1111  if(ret<=0)
1112  {ret= 0; goto ex;}
1113  }
1114  break;
1115  } else {
1116  if(xorriso->packet_output) {
1117  if(result_redirected) {
1118  l= npt + 1 - rpt;
1119  Xorriso_alloc_meM(line, char, 5 + l + 1);
1120  memcpy(line, prefix, 5);
1121  memcpy(line + 5, rpt, l);
1122  line[5 + l] = 0;
1123  ret= Xorriso_write_to_msglist(xorriso,
1124  &(xorriso->result_msglists[xorriso->msglist_stackfill - 1]),
1125  line, 0);
1126  Xorriso_free_meM(line);
1127  line= NULL;
1128  if(ret <= 0)
1129  { ret= -1; goto ex; }
1130  } else {
1131  ret= fwrite(rpt,npt+1-rpt,1,stdout);
1132  if(ret<=0)
1133  {ret= 0; goto ex;}
1134  }
1135  }
1136  if(pktlog_fp!=NULL) {
1137  ret= fwrite(rpt,npt+1-rpt,1,pktlog_fp);
1138  if(ret<=0)
1139  {ret= 0; goto ex;}
1140  }
1141  }
1142  rpt= npt+1;
1143  }
1144  if(xorriso->packet_output)
1145  fflush(stdout);
1146  if(pktlog_fp!=NULL)
1147  fflush(pktlog_fp);
1148  ret= 1;
1149 ex:
1150  if(text != in_text && text != NULL)
1151  free(text);
1152  Xorriso_free_meM(line);
1153 
1154 #ifdef Xorriso_fetch_with_msg_queueS
1155 
1156  if(locked) {
1157  uret= pthread_mutex_unlock(&(xorriso->write_to_channel_lock));
1158  if(uret != 0) {
1159  /* Cannot report failure through the failing message output system */
1160  complaints++;
1161  if(complaints <= complaint_limit)
1162  fprintf(stderr,
1163  "xorriso : pthread_mutex_unlock() for write_to_channel returns %d\n",
1164  uret);
1165  }
1166  }
1167 
1168 #endif /* Xorriso_fetch_with_msg_queueS */
1169 
1170  return(ret);
1171 }
1172 
1173 
1174 int Xorriso_push_outlists(struct XorrisO *xorriso, int *stack_handle,
1175  int flag)
1176 {
1177  int ret, locked= 0;
1178 
1179  ret= Xorriso_lock_outlists(xorriso, 0);
1180  if(ret <= 0)
1181  goto ex;
1182  locked= 1;
1183  if(xorriso->msglist_stackfill + 1 >= Xorriso_max_outlist_stacK) {
1184  Xorriso_unlock_outlists(xorriso, 0);
1185  locked= 0;
1186  Xorriso_msgs_submit(xorriso, 0,
1187  "Overflow of message output redirection stack", 0, "FATAL", 0);
1188  ret= -1; goto ex;
1189  }
1190  if((flag & 3) == 0)
1191  flag|= 3;
1192  xorriso->msglist_stackfill++;
1193  xorriso->result_msglists[xorriso->msglist_stackfill - 1]= NULL;
1194  xorriso->info_msglists[xorriso->msglist_stackfill - 1]= NULL;
1195  xorriso->msglist_flags[xorriso->msglist_stackfill - 1]= flag & 3;
1196  *stack_handle= xorriso->msglist_stackfill - 1;
1197  ret= 1;
1198 ex:;
1199  if(locked)
1200  Xorriso_unlock_outlists(xorriso, 0);
1201  return(ret);
1202  return(1);
1203 }
1204 
1205 
1206 int Xorriso_fetch_outlists(struct XorrisO *xorriso, int stack_handle,
1207  struct Xorriso_lsT **result_list,
1208  struct Xorriso_lsT **info_list, int flag)
1209 {
1210  int ret, locked= 0;
1211 
1212 #ifdef Xorriso_fetch_with_msg_queueS
1213 
1214  ret= Xorriso_process_msg_queues(xorriso, 0);
1215  if(ret <= 0)
1216  goto ex;
1217 
1218 #endif /* Xorriso_fetch_with_msg_queueS */
1219 
1220  if((flag & 3) == 0)
1221  flag|= 3;
1222 
1223  ret= Xorriso_lock_outlists(xorriso, 0);
1224  if(ret <= 0)
1225  goto ex;
1226  locked= 1;
1227 
1228  if(stack_handle == -1)
1229  stack_handle= xorriso->msglist_stackfill - 1;
1230  if(stack_handle < 0 || stack_handle >= xorriso->msglist_stackfill) {
1231  Xorriso_unlock_outlists(xorriso, 0);
1232  locked= 0;
1233  Xorriso_msgs_submit(xorriso, 0,
1234  "Program error: Wrong message output redirection stack handle",
1235  0, "FATAL", 0);
1236  ret= -1; goto ex;
1237  }
1238 
1239  if(flag & 1) {
1240  *result_list= xorriso->result_msglists[stack_handle];
1241  xorriso->result_msglists[stack_handle]= NULL;
1242  }
1243  if(flag & 2) {
1244  *info_list= xorriso->info_msglists[stack_handle];
1245  xorriso->info_msglists[stack_handle]= NULL;
1246  }
1247 
1248  ret= 1;
1249 ex:;
1250  if(locked)
1251  Xorriso_unlock_outlists(xorriso, 0);
1252  return(ret);
1253 }
1254 
1255 
1256 int Xorriso_peek_outlists(struct XorrisO *xorriso, int stack_handle,
1257  int timeout, int flag)
1258 {
1259  int ret, locked= 0, yes= 0;
1260  static int u_wait= 19000;
1261  time_t start_time;
1262 
1263  if((flag & 3) == 0)
1264  flag|= 3;
1265  if(stack_handle == -1)
1266  stack_handle= xorriso->msglist_stackfill - 1;
1267  start_time= time(NULL);
1268 
1269 try_again:;
1270  ret= Xorriso_obtain_lock(xorriso, &(xorriso->msgw_fetch_lock),
1271  "message watcher fetch operation", 0);
1272  if(ret <= 0)
1273  {yes= -2; goto ex;}
1274  locked= 1;
1275 
1276  yes= 0;
1277  if(stack_handle < 0 || stack_handle >= xorriso->msglist_stackfill)
1278  {yes= -1; goto ex;}
1279  if(flag & 1)
1280  yes|= (xorriso->result_msglists[stack_handle] != NULL);
1281  if(flag & 2)
1282  yes|= (xorriso->info_msglists[stack_handle] != NULL);
1283  if(xorriso->msg_watcher_state == 2 && xorriso->msgw_msg_pending)
1284  yes|= 2;
1285 
1286  ret= Xorriso_release_lock(xorriso, &(xorriso->msgw_fetch_lock),
1287  "message watcher fetch operation", 0);
1288  if(ret <= 0)
1289  {yes= -2; goto ex;}
1290  locked= 0;
1291 
1292  if(yes && (flag & 4)) {
1293  usleep(u_wait);
1294  if(time(NULL) <= start_time + timeout)
1295  goto try_again;
1296  }
1297 
1298 ex:;
1299  if(locked) {
1300  ret= Xorriso_release_lock(xorriso, &(xorriso->msgw_fetch_lock),
1301  "message watcher fetch operation", 0);
1302  if(ret <= 0 && yes >= 0)
1303  yes= -2;
1304  }
1305  return(yes);
1306 }
1307 
1308 
1309 int Xorriso_pull_outlists(struct XorrisO *xorriso, int stack_handle,
1310  struct Xorriso_lsT **result_list,
1311  struct Xorriso_lsT **info_list, int flag)
1312 {
1313  int i, ret, locked= 0;
1314 
1315  ret= Xorriso_lock_outlists(xorriso, 0);
1316  if(ret <= 0)
1317  goto ex;
1318  locked= 1;
1319 
1320  if(stack_handle == -1)
1321  stack_handle= xorriso->msglist_stackfill - 1;
1322  if(stack_handle < 0 || stack_handle >= xorriso->msglist_stackfill) {
1323  Xorriso_unlock_outlists(xorriso, 0);
1324  locked= 0;
1325  Xorriso_msgs_submit(xorriso, 0,
1326  "Program error: Wrong message output redirection stack handle",
1327  0, "FATAL", 0);
1328  ret= -1; goto ex;
1329  }
1330 
1331  /* Concatenate all redirections above stack_handle */
1332  *result_list= NULL;
1333  *info_list= NULL;
1334  for(i = stack_handle; i < xorriso->msglist_stackfill; i++) {
1335  if(*result_list == NULL)
1336  *result_list= xorriso->result_msglists[i];
1337  else
1338  Xorriso_lst_concat(*result_list, xorriso->result_msglists[i], 0);
1339  if(*info_list == NULL)
1340  *info_list= xorriso->info_msglists[i];
1341  else
1342  Xorriso_lst_concat(*info_list, xorriso->info_msglists[i], 0);
1343  }
1344  xorriso->msglist_stackfill= stack_handle;
1345 
1346  ret= 1;
1347 ex:;
1348  if(locked)
1349  Xorriso_unlock_outlists(xorriso, 0);
1350  return(ret);
1351 }
1352 
1353 
1354 int Xorriso_info_handler_stderr(void *handle, char *text)
1355 {
1356  struct XorrisO *xorriso;
1357 
1358  xorriso= (struct XorrisO *) handle;
1359  if(xorriso->stderr_fp != NULL) {
1360  fprintf(xorriso->stderr_fp, "%s", text);
1361  fflush(xorriso->stderr_fp);
1362  } else {
1363  fprintf(stderr, "%s", text);
1364  fflush(stderr);
1365  }
1366  return(1);
1367 }
1368 
1369 
1370 int Xorriso_result_handler_stdout(void *handle, char *text)
1371 {
1372  printf("%s", text);
1373  fflush(stdout);
1374  return(1);
1375 }
1376 
1377 
1378 int Xorriso_result_handler_pkt(void *handle, char *text)
1379 {
1380  int nl= -1, ret, l;
1381  struct XorrisO *xorriso;
1382 
1383  xorriso= (struct XorrisO *) handle;
1384 
1385  if(!xorriso->packet_output)
1386  return Xorriso_result_handler_stdout(handle, text);
1387 
1388  /* Interpret pkt_output */
1389  l= strlen(text);
1390  if(l >= 5) {
1391  if(strchr("RIM", text[0]) != NULL && text[1] == ':' &&
1392  strchr("01", text[2]) != NULL && text[3] == ':' && text[4] == ' ')
1393  nl= (text[2] == '1');
1394  }
1395  if(nl < 0) /* Not pkt_output format */
1396  return Xorriso_result_handler_stdout(handle, text);
1397 
1398  if(nl == 0) {
1399  /* Suppress newline */
1400  if(text[l - 1] == '\n')
1401  l--;
1402  }
1403 
1404  if(text[0] == 'R') {
1405  ret= fwrite(text + 5, l - 5, 1, stdout);
1406  } else {
1407  ret= fwrite(text + 5, l - 5, 1,
1408  xorriso->stderr_fp != NULL ? xorriso->stderr_fp : stderr);
1409  }
1410  if(ret <= 0)
1411  return(0);
1412  return(1);
1413 }
1414 
1415 
1417  struct Xorriso_lsT *result_list,
1418  struct Xorriso_lsT *info_list,
1419  int *line_count, int flag)
1420 {
1421  struct Xorriso_lsT *lpt;
1422  int ret;
1423  int (*handler)(void *handle, char *text);
1424  void *handle;
1425 
1426  handler= xorriso->msgw_result_handler;
1427  handle= xorriso->msgw_result_handle;
1428  if(handler == NULL) {
1429  handler= Xorriso_result_handler_pkt;
1430  handle= xorriso;
1431  }
1432  for(lpt= result_list; lpt != NULL; lpt= lpt->next) {
1433  (*line_count)++;
1434  ret= (*handler)(handle, Xorriso_lst_get_text(lpt, 0));
1435  if(ret < 0)
1436  return(-1);
1437  }
1438  handler= xorriso->msgw_info_handler;
1439  handle= xorriso->msgw_info_handle;
1440  if(handler == NULL) {
1441  handler= Xorriso_info_handler_stderr;
1442  handle= xorriso;
1443  }
1444  for(lpt= info_list; lpt != NULL; lpt= lpt->next) {
1445  (*line_count)++;
1446  ret= (*handler)(handle, Xorriso_lst_get_text(lpt, 0));
1447  if(ret < 0)
1448  return(-1);
1449  }
1450  return(1);
1451 }
1452 
1453 
1454 static void *Xorriso_msg_watcher(void *state_pt)
1455 {
1456  struct XorrisO *xorriso;
1457  int ret, u_wait= 25000, line_count, sleep_thresh= 20, lock_failure= 0;
1458  struct Xorriso_lsT *result_list= NULL, *info_list= NULL;
1459  static int debug_sev= 0;
1460 
1461  xorriso= (struct XorrisO *) state_pt;
1462 
1463  if(debug_sev == 0)
1464  Xorriso__text_to_sev("DEBUG", &debug_sev, 0);
1465 
1466  xorriso->msg_watcher_state= 2;
1467  if(xorriso->msgw_info_handler != NULL &&
1468  debug_sev < xorriso->report_about_severity &&
1469  debug_sev < xorriso->abort_on_severity)
1470  (*xorriso->msgw_info_handler)(xorriso,
1471  "xorriso : DEBUG : Concurrent message watcher started\n");
1472  while(1) {
1473  line_count= 0;
1474 
1475  /* Watch out for end request in xorriso */
1476  if(xorriso->msg_watcher_state == 3)
1477  break;
1478 
1479  ret= Xorriso_obtain_lock(xorriso, &(xorriso->msgw_fetch_lock),
1480  "message watcher fetch operation", 1);
1481  if(ret <= 0) {
1482  lock_failure= 1;
1483  break;
1484  }
1485  xorriso->msgw_msg_pending= 1;
1486  ret= Xorriso_fetch_outlists(xorriso, -1, &result_list, &info_list, 3);
1487  if(ret > 0) {
1488  /* Process fetched lines */
1489  xorriso->msgw_msg_pending= 2;
1490  Xorriso_release_lock(xorriso, &(xorriso->msgw_fetch_lock),
1491  "message watcher fetch operation", 1);
1492  ret= Xorriso_process_msg_lists(xorriso, result_list, info_list,
1493  &line_count, 0);
1494  xorriso->msgw_msg_pending= 0;
1495  Xorriso_lst_destroy_all(&result_list, 0);
1496  Xorriso_lst_destroy_all(&info_list, 0);
1497  if(ret < 0)
1498  break;
1499  } else {
1500  xorriso->msgw_msg_pending= 0;
1501  Xorriso_release_lock(xorriso, &(xorriso->msgw_fetch_lock),
1502  "message watcher fetch operation", 1);
1503  }
1504  xorriso->msgw_msg_pending= 0;
1505 
1506  if(ret < 0)
1507  break;
1508 
1509  if(line_count < sleep_thresh)
1510  usleep(u_wait);
1511  }
1512  if(xorriso->msgw_info_handler != NULL &&
1513  debug_sev < xorriso->report_about_severity &&
1514  debug_sev < xorriso->abort_on_severity &&
1515  !lock_failure)
1516  (*xorriso->msgw_info_handler)(xorriso,
1517  "xorriso : DEBUG : Concurrent message watcher ended\n");
1518  xorriso->msg_watcher_state= 0;
1519  return(NULL);
1520 }
1521 
1522 
1524  int (*result_handler)(void *handle, char *text),
1525  void *result_handle,
1526  int (*info_handler)(void *handle, char *text),
1527  void *info_handle,
1528  int flag)
1529 {
1530  int ret, u_wait= 1000, locked= 0, pushed= 0, uret, line_count= 0;
1531  struct Xorriso_lsT *result_list= NULL, *info_list= NULL;
1532  pthread_attr_t attr;
1533  pthread_attr_t *attr_pt = NULL;
1534  pthread_t thread;
1535 
1536  ret= pthread_mutex_lock(&(xorriso->msg_watcher_lock));
1537  if(ret != 0) {
1538  Xorriso_msgs_submit(xorriso, 0,
1539  "Cannot acquire mutex lock for managing concurrent message watcher",
1540  ret, "FATAL", 0);
1541  ret= -1; goto ex;
1542  }
1543  locked= 1;
1544 
1545  /* Check for running watcher */
1546  if(xorriso->msg_watcher_state > 0) {
1547  sprintf(xorriso->info_text,
1548  "There is already a concurrent message watcher running");
1549  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
1550  ret= 0; goto ex;
1551  }
1552 
1553  ret= Xorriso_push_outlists(xorriso, &(xorriso->msgw_stack_handle), 3);
1554  if(ret <= 0)
1555  goto ex;
1556  pushed= 1;
1557 
1558  /* Register watcher */
1559  xorriso->msgw_result_handler= result_handler;
1560  xorriso->msgw_result_handle= result_handle;
1561  xorriso->msgw_info_handler= info_handler;
1562  xorriso->msgw_info_handle= info_handle;
1563  xorriso->msg_watcher_state= 1;
1564 
1565  /* Start thread */
1566  pthread_attr_init(&attr);
1567  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1568  attr_pt= &attr;
1569  ret= pthread_create(&thread, attr_pt, Xorriso_msg_watcher, xorriso);
1570  if(ret != 0) {
1571  sprintf(xorriso->info_text,
1572  "Cannot create thread for concurrent message watcher");
1573  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
1574  ret= 0; goto ex;
1575  }
1576 
1577  /* Wait until watcher has indicated start */
1578  while(xorriso->msg_watcher_state == 1) {
1579 
1580  /* >>> have a timeout ? */;
1581 
1582  usleep(u_wait);
1583  }
1584 
1585  ret= 1;
1586 ex:;
1587  if(ret <= 0 && pushed) {
1588  uret= Xorriso_pull_outlists(xorriso, xorriso->msgw_stack_handle,
1589  &result_list, &info_list, 0);
1590  if(uret > 0) {
1591  xorriso->msgw_result_handler= NULL;
1592  xorriso->msgw_info_handler= NULL;
1593  Xorriso_process_msg_lists(xorriso, result_list, info_list,
1594  &line_count, 0);
1595  Xorriso_lst_destroy_all(&result_list, 0);
1596  Xorriso_lst_destroy_all(&info_list, 0);
1597  }
1598  }
1599  if(locked) {
1600  uret= pthread_mutex_unlock(&(xorriso->msg_watcher_lock));
1601  if(uret != 0) {
1602  Xorriso_msgs_submit(xorriso, 0,
1603  "Cannot release mutex lock for managing concurrent message watcher",
1604  uret, "FATAL", 0);
1605  ret= -1;
1606  }
1607  }
1608  return(ret);
1609 }
1610 
1611 
1612 /* @param flag bit0= do not complain loudly if no wather is active
1613 */
1614 int Xorriso_stop_msg_watcher(struct XorrisO *xorriso, int flag)
1615 {
1616  int ret, u_wait= 1000, locked= 0, uret, line_count= 0;
1617  struct Xorriso_lsT *result_list= NULL, *info_list= NULL;
1618 
1619  if((flag & 1) && xorriso->msg_watcher_state != 2)
1620  /* Roughly tolerate non-running watcher */
1621  {ret= 0; goto ex;}
1622 
1623  ret= pthread_mutex_lock(&(xorriso->msg_watcher_lock));
1624  if(ret != 0) {
1625  Xorriso_msgs_submit(xorriso, 0,
1626  "Cannot acquire mutex lock for managing concurrent message watcher",
1627  ret, "FATAL", 0);
1628  ret= -1; goto ex;
1629  }
1630  locked= 1;
1631 
1632  /* Check for running watcher */
1633  if(xorriso->msg_watcher_state != 2) {
1634  sprintf(xorriso->info_text,
1635  "There is no concurrent message watcher running");
1636  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
1637  ret= 0; goto ex;
1638  }
1639 
1640  /* Inform watcher of desire to stop it */
1641  xorriso->msg_watcher_state= 3;
1642 
1643  /* Wait until watcher has indicated its end */
1644  while(xorriso->msg_watcher_state != 0) {
1645 
1646  /* >>> have a timeout ? */;
1647 
1648  usleep(u_wait);
1649  }
1650 
1651  ret= Xorriso_obtain_lock(xorriso, &(xorriso->msgw_fetch_lock),
1652  "message watcher fetch operation", 1);
1653  if(ret <= 0) {
1654  Xorriso_msgs_submit(xorriso, 0,
1655  "Cannot obtain mutex lock for managing concurrent message watcher",
1656  ret, "FATAL", 0);
1657  ret= -1;
1658  goto ex;
1659  }
1660  xorriso->msgw_msg_pending= 1;
1661  ret= Xorriso_pull_outlists(xorriso, xorriso->msgw_stack_handle,
1662  &result_list, &info_list, 0);
1663  if(ret > 0) {
1664  xorriso->msgw_msg_pending= 2;
1665  Xorriso_release_lock(xorriso, &(xorriso->msgw_fetch_lock),
1666  "message watcher fetch operation", 1);
1667  Xorriso_process_msg_lists(xorriso, result_list, info_list,
1668  &line_count, 0);
1669  xorriso->msgw_msg_pending= 0;
1670  Xorriso_lst_destroy_all(&result_list, 0);
1671  Xorriso_lst_destroy_all(&info_list, 0);
1672  } else {
1673  xorriso->msgw_msg_pending= 0;
1674  Xorriso_release_lock(xorriso, &(xorriso->msgw_fetch_lock),
1675  "message watcher fetch operation", 1);
1676  }
1677 
1678  xorriso->msgw_result_handler= NULL;
1679  xorriso->msgw_info_handler= NULL;
1680 
1681  ret= 1;
1682 ex:;
1683  if(locked) {
1684  uret= pthread_mutex_unlock(&(xorriso->msg_watcher_lock));
1685  if(uret != 0) {
1686  Xorriso_msgs_submit(xorriso, 0,
1687  "Cannot release mutex lock for managing concurrent message watcher",
1688  uret, "FATAL", 0);
1689  ret= -1;
1690  }
1691  }
1692  return(ret);
1693 }
1694 
1695 
1696 /* -------------------------- Xorriso_msg_sievE -------------------------- */
1697 
1699  char *name;
1700  char *prefix;
1701  char *separators;
1702  int channels; /* What to watch: bit0=result , bit1=info , bit2=mark */
1703 
1705  int *word_idx;
1707 
1708  /* Oldest result gets discarded when new surpassed threshold */
1710 
1711  struct Xorriso_lsT *results; /* Serialized tuples of num_words */
1715 
1718 };
1719 int Xorriso_msg_filter_destroy(struct Xorriso_msg_filteR **o, int flag);
1720 
1721 
1723  struct Xorriso_msg_filteR *prev,
1724  struct Xorriso_msg_filteR *next,
1725  int flag)
1726 {
1727  struct Xorriso_msg_filteR *m;
1728 
1729  m= (*o)= TSOB_FELD(struct Xorriso_msg_filteR, 1);
1730  if((*o) == NULL)
1731  return(-1);
1732  m->name= NULL;
1733  m->prefix= NULL;
1734  m->separators= NULL;
1735  m->channels= 7;
1736  m->num_words= 0;
1737  m->word_idx= NULL;
1738  m->last_word_line_end= flag & 1;
1739  m->max_results= 1;
1740  m->results= NULL;
1741  m->num_results= 0;
1742  m->num_delivered= 0;
1743  m->next_to_deliver= NULL;
1744 
1745  m->name= strdup(name);
1746  if(m->name == NULL)
1747  goto failure;
1748 
1749  m->prev= prev;
1750  if(prev != NULL)
1751  prev->next= m;
1752  m->next= next;
1753  if(next != NULL)
1754  next->prev= m;
1755  return(1);
1756 failure:
1758  return(-1);
1759 }
1760 
1761 
1763 {
1764  struct Xorriso_msg_filteR *m;
1765 
1766  if((*o)==NULL)
1767  return(0);
1768  m= *o;
1769  if(m->name != NULL)
1770  free(m->name);
1771  if(m->prefix != NULL)
1772  free(m->prefix);
1773  if(m->separators != NULL)
1774  free(m->separators);
1775  if(m->word_idx != NULL)
1776  free((char *) m->word_idx);
1777  if(m->results != NULL)
1778  Xorriso_lst_destroy_all(&(m->results), 0);
1779  if(m->prev != NULL)
1780  m->prev->next= m->next;
1781  if(m->next != NULL)
1782  m->next->prev= m->prev;
1783 
1784  free(*o);
1785  *o= NULL;
1786  return(1);
1787 }
1788 
1789 
1791  int num_words, int *word_idx, int flag)
1792 {
1793  int i;
1794 
1795  if(m->word_idx != NULL)
1796  free(m->word_idx);
1797  m->num_words= 0;
1798  if(num_words <= 0)
1799  return(1);
1800  m->word_idx= TSOB_FELD(int, num_words);
1801  if(m->word_idx == NULL)
1802  return(-1);
1803  for(i= 0; i < num_words; i++)
1804  m->word_idx[i]= word_idx[i];
1805  m->num_words= num_words;
1806  return(1);
1807 }
1808 
1809 
1811 
1813 
1815 
1816 };
1817 
1818 
1819 int Xorriso_msg_sieve_new(struct Xorriso_msg_sievE **o, int flag)
1820 {
1821  struct Xorriso_msg_sievE *m;
1822 
1823  m= (*o)= TSOB_FELD(struct Xorriso_msg_sievE, 1);
1824  if((*o) == NULL)
1825  return(-1);
1826  m->num_filters= 0;
1827  m->first_filter= NULL;
1828  return(1);
1829 }
1830 
1831 
1833 {
1834  struct Xorriso_msg_sievE *m;
1835  struct Xorriso_msg_filteR *f, *next_f= NULL;
1836 
1837  if((*o) == NULL)
1838  return(0);
1839  m= *o;
1840  for(f= m->first_filter; f != NULL; f= next_f) {
1841  next_f= f->next;
1843  }
1844  free(*o);
1845  *o= NULL;
1846  return(1);
1847 }
1848 
1849 
1850 /* API */
1851 int Xorriso_sieve_add_filter(struct XorrisO *xorriso, char *name,
1852  int channels, char *prefix, char *separators,
1853  int num_words, int *word_idx, int max_results,
1854  int flag)
1855 {
1856  int ret;
1857  struct Xorriso_msg_sievE *sieve= NULL;
1858  struct Xorriso_msg_filteR *filter;
1859 
1860  if(xorriso->msg_sieve == NULL) {
1861  ret= Xorriso_msg_sieve_new(&sieve, 0);
1862  if(ret <= 0)
1863  goto no_mem;
1864  xorriso->msg_sieve= sieve;
1865  } else
1866  sieve= xorriso->msg_sieve;
1867  ret= Xorriso_msg_filter_new(&filter, name, NULL, sieve->first_filter,
1868  flag & 1);
1869  if(ret <= 0)
1870  goto no_mem;
1871  sieve->first_filter= filter;
1873  if(ret <= 0)
1874  goto no_mem;
1875  if(prefix != NULL)
1876  filter->prefix= strdup(prefix);
1877  if(separators != NULL)
1878  filter->separators= strdup(separators);
1879  filter->channels= channels;
1880  filter->max_results= max_results;
1881  (sieve->num_filters)++;
1882  return(1);
1883 
1884 no_mem:;
1885  Xorriso_msg_sieve_destroy(&sieve, 0);
1886  Xorriso_no_malloc_memory(xorriso, NULL, 0);
1887  return(-1);
1888 }
1889 
1890 
1891 /* API */
1892 int Xorriso_sieve_dispose(struct XorrisO *xorriso, int flag)
1893 {
1894  Xorriso_msg_sieve_destroy(&(xorriso->msg_sieve), 0);
1895  return(1);
1896 }
1897 
1898 
1899 /* API */
1900 int Xorriso_sieve_clear_results(struct XorrisO *xorriso, int flag)
1901 {
1902  struct Xorriso_msg_filteR *f;
1903 
1904  if(xorriso->msg_sieve == NULL)
1905  return(1);
1906  for(f= xorriso->msg_sieve->first_filter; f != NULL; f= f->next) {
1907  f->num_results= 0;
1908  f->num_delivered= 0;
1909  if(f->results != NULL)
1910  Xorriso_lst_destroy_all(&(f->results), 0);
1911  f->next_to_deliver= NULL;
1912  }
1913  return(1);
1914 }
1915 
1916 
1917 /* API */
1918 /* @param flag bit0= Reset reading to first matching result
1919  bit1= Only inquire number of available results.
1920  Do not allocate memory.
1921  bit2= If *argv is not NULL, then free it before attaching
1922  new memory.
1923  bit3= Do not read recorded data but rather list all filter names
1924 */
1925 int Xorriso_sieve_get_result(struct XorrisO *xorriso, char *name,
1926  int *argc, char ***argv, int *available, int flag)
1927 {
1928  struct Xorriso_msg_filteR *f;
1929  struct Xorriso_lsT *lst;
1930  int i;
1931 
1932  if(flag & 4)
1933  Xorriso__dispose_words(argc, argv);
1934  *argc= 0;
1935  *argv= NULL;
1936 
1937  if(xorriso->msg_sieve == NULL)
1938  return(0);
1939 
1940  if(flag & 8) {
1941  if(xorriso->msg_sieve->num_filters <= 0)
1942  return(0);
1943  *argv= calloc(xorriso->msg_sieve->num_filters, sizeof(char *));
1944  if(*argv == NULL)
1945  goto no_mem;
1946  *argc= xorriso->msg_sieve->num_filters;
1947  for(i= 0; i < *argc; i++)
1948  (*argv)[i]= NULL;
1949  i= 0;
1950  for(f= xorriso->msg_sieve->first_filter; f != NULL; f= f->next) {
1951  (*argv)[*argc - i - 1]= strdup(f->name);
1952  if((*argv)[*argc - i - 1] == NULL)
1953  goto no_mem;
1954  i++;
1955  }
1956  *argc= i;
1957  return(1);
1958  }
1959 
1960  for(f= xorriso->msg_sieve->first_filter; f != NULL; f= f->next) {
1961  if(strcmp(f->name, name) != 0)
1962  continue;
1963  *available= f->num_results - f->num_delivered;
1964  if(*available <= 0)
1965  return(0);
1966  if(flag & 2)
1967  return(1);
1968 
1969  if(flag & 1) {
1970  f->num_delivered= 0;
1971  f->next_to_deliver= NULL;
1972  }
1973  if(f->next_to_deliver == NULL) {
1974  f->next_to_deliver= f->results;
1975  for(i= 0; i < f->num_words * f->num_delivered; i++)
1976  if(f->next_to_deliver != NULL)
1978  }
1979  if(f->next_to_deliver == NULL) {
1980  /* Should not happen */
1981  goto unexpected_null;
1982  }
1983  if(f->num_words <= 0)
1984  return(1);
1985 
1986  *argv= calloc(f->num_words, sizeof(char *));
1987  if(*argv == NULL)
1988  goto no_mem;
1989  *argc= f->num_words;
1990  for(i= 0; i < *argc; i++)
1991  (*argv)[i]= NULL;
1992 
1993  lst= f->next_to_deliver;
1994  for(i= 0; i < *argc; i++) {
1995  if(lst != NULL) {
1996  (*argv)[i]= strdup(Xorriso_lst_get_text(lst, 0));
1997  if((*argv)[i] == NULL)
1998  goto no_mem;
1999  } else {
2000  /* should not happen */
2001 unexpected_null:;
2002  Xorriso_msgs_submit(xorriso, 0,
2003  "Program error: Unexpected NULL pointer in message sieve.",
2004  0, "WARNING", 0);
2005  if(*argv != NULL)
2006  Xorriso__dispose_words(argc, argv);
2007  *available= 0;
2008  return(-2);
2009  }
2010  lst= Xorriso_lst_get_next(lst, 0);
2011  }
2012  f->next_to_deliver= lst;
2013  (f->num_delivered)++;
2014  (*available)--;
2015  return(1);
2016  }
2017  return(-2);
2018 no_mem:
2019  if(*argv != NULL)
2020  Xorriso__dispose_words(argc, argv);
2021  Xorriso_no_malloc_memory(xorriso, NULL, 0);
2022  return(-1);
2023 }
2024 
2025 
2026 int Xorriso_sieve_big(struct XorrisO *xorriso, int flag)
2027 {
2028  struct Xorriso_sieve_big_filteR {
2029  char *name;
2030  int channels;
2031  char *prefix;
2032  char *separators;
2033  int num_words;
2034  int word_idx[6];
2035  int max_results;
2036  int flag;
2037  };
2038  static struct Xorriso_sieve_big_filteR filters[] = {
2039  {"-changes_pending", 3, "-changes_pending", "", 1,
2040  { 0, -1, -1, -1, -1, -1}, 1, 0},
2041  {"? -dev", 3, "? -dev", "", 4, { 0, 1, 3, 4, -1, -1},
2042  10, 0},
2043  {"?? -dev", 3, "?? -dev", "", 4, { 0, 1, 3, 4, -1, -1},
2044  90, 0},
2045  {"Abstract File:", 3, "Abstract File: ", "", 1, { 0, -1, -1, -1, -1, -1},
2046  1, 1},
2047  {"After commit :", 3, "After commit :", "", 1, { 0, -1, -1, -1, -1, -1},
2048  1, 0},
2049  {"App Id :", 3, "App Id : ", "", 1, { 0, -1, -1, -1, -1, -1},
2050  1, 1},
2051  {"Biblio File :", 3, "Biblio File : ", "", 1, { 0, -1, -1, -1, -1, -1},
2052  1, 1},
2053  {"Build timestamp :", 3, "Build timestamp : ", "", 1,
2054  { 0, -1, -1, -1, -1, -1}, 1, 1},
2055  {"CopyrightFile:", 3, "CopyrightFile: ", "", 1, { 0, -1, -1, -1, -1, -1},
2056  1, 1},
2057  {"Creation Time:", 3, "Creation Time: ", "", 1, { 0, -1, -1, -1, -1, -1},
2058  1, 1},
2059  {"DVD obs 64 kB:", 3, "DVD obs 64 kB:", "", 1, { 0, -1, -1, -1, -1, -1},
2060  1, 0},
2061  {"Drive access :", 3, "Drive access : ", ": ", 2, { 0, 1, -1, -1, -1, -1},
2062  2, 0},
2063  {"Drive current:", 3, "Drive current:", "", 2, { 0, 1, -1, -1, -1, -1},
2064  2, 0},
2065  {"Drive id :", 3, "Drive id :", "", 1, { 0, -1, -1, -1, -1, -1},
2066  2, 0},
2067  {"Drive type :", 3, "Drive type :", "", 3, { 1, 3, 5, -1, -1, -1},
2068  2, 0},
2069  {"Eff. Time :", 3, "Eff. Time : ", "", 1, { 0, -1, -1, -1, -1, -1},
2070  1, 1},
2071  {"Expir. Time :", 3, "Expir. Time : ", "", 1, { 0, -1, -1, -1, -1, -1},
2072  1, 1},
2073  {"Ext. filters :", 3, "Ext. filters : ", "", 1, { 0, -1, -1, -1, -1, -1},
2074  1, 1},
2075  {"File damaged :", 3, "File damaged :", "", 4, { 0, 2, 4, 6, -1, -1},
2076  10000, 0},
2077  {"File data lba:", 3, "File data lba:", "", 5, { 0, 2, 4, 6, 8, -1},
2078  10000, 0},
2079  {"Format idx :", 3, "Format idx ", ",: ", 4, { 0, 1, 2, 3, -1, -1},
2080  100, 1},
2081  {"Format status:", 3, "Format status:", ", ", 2, { 0, 1, -1, -1, -1, -1},
2082  1, 1},
2083  {"ISO session :", 3, "ISO session :", "", 4, { 0, 2, 4, 6, -1, -1},
2084  10000, 1},
2085  {"Image size :", 3, "Image size :", "", 1, { 0, -1, -1, -1, -1, -1},
2086  1, 0},
2087  {"Jigdo files :", 3, "Jigdo files :", "", 1, { 0, -1, -1, -1, -1, -1},
2088  1, 0},
2089  {"Local ACL :", 3, "Local ACL :", "", 1, { 0, -1, -1, -1, -1, -1},
2090  1, 0},
2091  {"Local xattr :", 3, "Local xattr :", "", 1, { 0, -1, -1, -1, -1, -1},
2092  1, 0},
2093  {"MD5 MISMATCH:", 3, "MD5 MISMATCH:", "", 1, { 0, -1, -1, -1, -1, -1},
2094  10000, 0},
2095  {"MD5 tag range:", 3, "MD5 tag range:", "", 3, { 0, 2, 4, -1, -1, -1},
2096  10000, 1},
2097  {"Media blocks :", 3, "Media blocks :", "", 3, { 0, 3, 6, -1, -1, -1},
2098  2, 0},
2099  {"Media current:", 3, "Media current: ", "", 1, { 0, -1, -1, -1, -1, -1},
2100  2, 1},
2101  {"Media id :", 3, "Media id :", "", 1, { 0, -1, -1, -1, -1, -1},
2102  2, 0},
2103  {"Media nwa :", 3, "Media nwa :", "", 1, { 0, -1, -1, -1, -1, -1},
2104  1, 0},
2105  {"Media product:", 3, "Media product:", "", 2, { 0, 2, -1, -1, -1, -1},
2106  2, 1},
2107  {"Media region :", 3, "Media region :", "", 3, { 0, 2, 4, -1, -1, -1},
2108  10000, 1},
2109  {"Media space :", 3, "Media space :", "", 1, { 0, -1, -1, -1, -1, -1},
2110  1, 0},
2111  {"Media status :", 3, "Media status : ", "", 1, { 0, -1, -1, -1, -1, -1},
2112  2, 1},
2113  {"Media summary:", 3, "Media summary:", "", 4, { 0, 2, 5, 7, -1, -1},
2114  2, 0},
2115  {"Modif. Time :", 3, "Modif. Time : ", "", 1, { 0, -1, -1, -1, -1, -1},
2116  1, 1},
2117  {"PVD address :", 3, "PVD address :", "", 1, { 0, -1, -1, -1, -1, -1},
2118  1, 0},
2119  {"Preparer Id :", 3, "Preparer Id : ", "", 1, { 0, -1, -1, -1, -1, -1},
2120  1, 1},
2121  {"Profile :", 3, "Profile :", "", 2, { 0, 1, -1, -1, -1, -1},
2122  256, 1},
2123  {"Publisher Id :", 3, "Publisher Id : ", "", 1, { 0, -1, -1, -1, -1, -1},
2124  1, 1},
2125  {"Readline :", 3, "Readline :", "", 1, { 0, -1, -1, -1, -1, -1},
2126  1, 0},
2127  {"Size lower :", 3, "Size lower :", "", 1, { 0, -1, -1, -1, -1, -1},
2128  1, 0},
2129  {"Size upper :", 3, "Size upper :", "", 1, { 0, -1, -1, -1, -1, -1},
2130  1, 0},
2131  {"System Id :", 3, "System Id : ", "", 1, { 0, -1, -1, -1, -1, -1},
2132  1, 1},
2133  {"Version timestamp :", 3, "Version timestamp :", "", 1,
2134  { 0, -1, -1, -1, -1, -1}, 1, 0},
2135  {"Volume Id :", 3, "Volume Id : ", "", 1, { 0, -1, -1, -1, -1, -1},
2136  1, 1},
2137  {"Volume Set Id:", 3, "Volume Set Id: ", "", 1, { 0, -1, -1, -1, -1, -1},
2138  1, 1},
2139  {"Volume id :", 3, "Volume id :", "", 1, { 0, -1, -1, -1, -1, -1},
2140  2, 0},
2141  {"Write speed :", 3, "Write speed :", "", 2, { 0, 2, -1, -1, -1, -1},
2142  100, 0},
2143  {"Write speed H:", 3, "Write speed H:", "", 2, { 0, 2, -1, -1, -1, -1},
2144  1, 0},
2145  {"Write speed L:", 3, "Write speed L:", "", 2, { 0, 2, -1, -1, -1, -1},
2146  1, 0},
2147  {"Write speed h:", 3, "Write speed h:", "", 2, { 0, 2, -1, -1, -1, -1},
2148  1, 0},
2149  {"Write speed l:", 3, "Write speed l:", "", 2, { 0, 2, -1, -1, -1, -1},
2150  1, 0},
2151  {"libburn in use :", 3, "libburn in use :", "", 2,
2152  { 0, 1, -1, -1, -1, -1}, 1, 1},
2153  {"libburn OS adapter:", 3, "libburn OS adapter: ", "", 1,
2154  { 0, -1, -1, -1, -1, -1}, 1, 1},
2155  {"libisoburn in use :", 3, "libisoburn in use :", "", 2,
2156  { 0, 1, -1, -1, -1, -1}, 1, 1},
2157  {"libisofs in use :", 3, "libisofs in use :", "", 2,
2158  { 0, 1, -1, -1, -1, -1}, 1, 1},
2159  {"libjte in use :", 3, "libjte in use :", "", 2,
2160  { 0, 1, -1, -1, -1, -1}, 1, 1},
2161  {"xorriso version :", 3, "xorriso version :", "", 1,
2162  { 0, -1, -1, -1, -1, -1}, 1, 0},
2163  {"zisofs :", 3, "zisofs :", "", 1, { 0, -1, -1, -1, -1, -1},
2164  1, 0},
2165  {"@", 0, "@", "", 0, {-1, -1, -1, -1, -1, -1}, 0, 0}
2166  };
2167 
2168  struct Xorriso_sieve_big_filteR *f;
2169  int ret, i;
2170 
2171  for(i= 0; ; i++) {
2172  f= &(filters[i]);
2173  if(strcmp(f->name, "@") == 0)
2174  break;
2175  ret= Xorriso_sieve_add_filter(xorriso, f->name, f->channels, f->prefix,
2176  f->separators, f->num_words, f->word_idx,
2177  f->max_results, f->flag);
2178  if(ret <= 0)
2179  goto failure;
2180  }
2181  return(1);
2182 failure:
2183  Xorriso_sieve_dispose(xorriso, 0);
2184  return(-1);
2185 }
2186 
2187 
2188 /* Check for matching filter and eventually extract words.
2189  To be called by Xorriso_result, Xorriso_info, Xorriso_mark,
2190  and alike.
2191  Thus no own message output is allowed here !
2192  @param flag bit0-1= channel:
2193  0= result channel
2194  1= info channel
2195  2= mark channel
2196 */
2197 int Xorriso_sieve_filter_msg(struct XorrisO *xorriso, char *msg, int flag)
2198 {
2199  int channel, ret, argc= 0, i, max_words, l, widx, skip;
2200  char **argv= NULL, *prefix_storage= NULL, *prefix, *cpt, *to_parse= NULL;
2201  struct Xorriso_msg_filteR *f;
2202  struct Xorriso_lsT *lst, *prev_lst, *next_lst;
2203 
2204  if(xorriso->msg_sieve == NULL || xorriso->msg_sieve_disabled)
2205  return(1);
2206 
2207  channel= flag & 3;
2208 
2209  for(f= xorriso->msg_sieve->first_filter; f != NULL; f= f->next) {
2210  if(!(f->channels & (1 << channel)))
2211  continue;
2212  prefix= f->prefix;
2213 
2214  if(prefix[0] == '?') {
2215  skip= 0;
2216  for(cpt= prefix; *cpt; cpt++)
2217  if(*cpt == '?')
2218  skip++;
2219  else
2220  break;
2221  l= strlen(prefix);
2222  if(strlen(msg) >= (unsigned int) l) {
2223  if(l - skip == 0 || strncmp(prefix + skip, msg + skip, l - skip) == 0) {
2224  Xorriso_free_meM(prefix_storage);
2225  prefix_storage= NULL;
2226  Xorriso_alloc_meM(prefix_storage, char, l + 1);
2227  strncpy(prefix_storage, msg, l);
2228  prefix_storage[l]= 0;
2229  prefix= prefix_storage;
2230  }
2231  }
2232  }
2233  if(prefix[0])
2234  if(strncmp(prefix, msg, strlen(prefix)) != 0)
2235  continue;
2236 
2237  if (to_parse != NULL)
2238  free(to_parse);
2239  to_parse= strdup(msg);
2240  if(to_parse == NULL)
2241  goto no_mem;
2242  l= strlen(to_parse);
2243  if(l > 0)
2244  if(to_parse[l - 1] == '\n')
2245  to_parse[l - 1]= 0;
2246 
2247  max_words= 0;
2248  if(f->last_word_line_end)
2249  if(f->num_words > 0) /* Let last word take rest of line */
2250  max_words= f->word_idx[f->num_words - 1];
2251  if(max_words <= 0 && f->last_word_line_end) {
2252  /* Copy rest of line as single word because Xorriso_parse_line understands
2253  max_words == 0 as unlimited number of words. But here it is desired
2254  to get the rest of line already in argv[0].
2255  */
2256  max_words= 0;
2257  argv= calloc(1, sizeof(char *));
2258  if(argv == NULL)
2259  goto no_mem;
2260  argc= 1;
2261  argv[0]= strdup(to_parse + strlen(prefix));
2262  if(argv[0] == NULL)
2263  goto no_mem;
2264  ret= 1;
2265  } else {
2266  ret= Xorriso_parse_line(xorriso, to_parse, prefix, f->separators,
2267  max_words, &argc, &argv, 0);
2268  }
2269  if(ret < 0)
2270  goto ex;
2271  if(ret == 0)
2272  continue;
2273 
2274  if(f->last_word_line_end && argc > max_words) {
2275  l= strlen(argv[max_words]);
2276  if(l > 0)
2277  if(argv[max_words][l - 1] == '\n')
2278  argv[max_words][l - 1]= 0;
2279  }
2280 
2281  if(f->max_results > 0 && f->num_results >= f->max_results) {
2282  /* Dispose surplus results */
2283  for(i= 0; i < f->num_words; i++) {
2284  if(f->results != NULL) {
2285  next_lst= f->results->next;
2286  Xorriso_lst_destroy(&(f->results), 0);
2287  f->results= next_lst;
2288  }
2289  }
2290  if(f->num_delivered > 0)
2291  (f->num_delivered)--;
2292  if(f->num_delivered == 0)
2293  f->next_to_deliver= NULL;
2294  f->num_results--;
2295  }
2296 
2297  if(f->results == NULL) {
2298  prev_lst= NULL;
2299  } else {
2300  for(prev_lst= f->results; prev_lst->next != NULL;
2301  prev_lst= prev_lst->next);
2302  }
2303  for(i= 0; i < f->num_words; i++) {
2304  widx= f->word_idx[i];
2305  if(widx >= argc || widx < 0)
2306  ret= Xorriso_lst_new(&lst, "", prev_lst, 0);
2307  else if(argv[widx] == NULL)
2308  ret= Xorriso_lst_new(&lst, "", prev_lst, 0);
2309  else
2310  ret= Xorriso_lst_new(&lst, argv[widx], prev_lst, 0);
2311  if(ret <= 0)
2312  goto no_mem;
2313  if(prev_lst == NULL)
2314  f->results= lst;
2315  prev_lst= lst;
2316  }
2317  (f->num_results)++;
2318  Xorriso__dispose_words(&argc, &argv);
2319  }
2320  ret= 1;
2321 ex:
2322  if(to_parse != NULL)
2323  free(to_parse);
2324  Xorriso_free_meM(prefix_storage);
2325  Xorriso__dispose_words(&argc, &argv);
2326  return(ret);
2327 no_mem:;
2328  Xorriso_no_malloc_memory(xorriso, NULL, 1); /* reports to stderr */
2329  ret= -1;
2330  goto ex;
2331 }
2332 
2333 
2334 /* ^^^^^^^^^^^^^^^^^^^^^^^^^^ Xorriso_msg_sievE ^^^^^^^^^^^^^^^^^^^^^^^^^^ */
2335 
2336 
2337 int Xorriso_result(struct XorrisO *xorriso, int flag)
2338 /*
2339  bit0= no considerations or computations or dialog. Just put out.
2340 */
2341 {
2342  int ret, redirected= 0;
2343 
2344  if(flag&1)
2345  goto put_it_out;
2346  if(xorriso->request_to_abort)
2347  return(1);
2348  if(xorriso->msglist_stackfill > 0)
2349  if(xorriso->msglist_flags[xorriso->msglist_stackfill - 1] & 1)
2350  redirected= 1;
2351  if(xorriso->result_page_length>0 && !redirected) {
2352  ret= Xorriso_pager(xorriso,xorriso->result_line,2);
2353  if(ret<=0)
2354  return(ret);
2355  if(ret==2)
2356  return(1);
2357  if(xorriso->request_to_abort)
2358  return(1);
2359  }
2360 put_it_out:;
2361  xorriso->bar_is_fresh= 0;
2362  ret= Xorriso_write_to_channel(xorriso, xorriso->result_line, 1,0);
2363  return(ret);
2364 }
2365 
2366 
2367 int Xorriso_info(struct XorrisO *xorriso, int flag)
2368 /*
2369  bit0= use pager (as with result)
2370  bit1= permission to suppress output
2371  bit2= insist in showing output
2372 */
2373 {
2374  int ret;
2375  static int note_sev= 0;
2376 
2377  if(flag&2)
2378  if(xorriso->request_to_abort)
2379  return(1);
2380 
2381  if(note_sev==0)
2382  Xorriso__text_to_sev("NOTE", &note_sev, 0);
2383  if(note_sev<xorriso->report_about_severity &&
2384  note_sev<xorriso->abort_on_severity && !(flag&4))
2385  return(1);
2386 
2387  if(flag&1) {
2388  ret= Xorriso_pager(xorriso,xorriso->info_text,2);
2389  if(ret<=0)
2390  return(ret);
2391  if(ret==2)
2392  return(1);
2393  if(flag&2)
2394  if(xorriso->request_to_abort)
2395  return(1);
2396  }
2397  xorriso->bar_is_fresh= 0;
2398  ret=Xorriso_write_to_channel(xorriso, xorriso->info_text, 2, 0);
2399  return(ret);
2400 }
2401 
2402 
2403 int Xorriso_mark(struct XorrisO *xorriso, int flag)
2404 {
2405  int ret= 1,r_ret,i_ret;
2406 
2407  if(xorriso->mark_text[0]==0)
2408  return(1);
2409  if(xorriso->packet_output)
2410  ret=Xorriso_write_to_channel(xorriso, xorriso->mark_text, 3, 0);
2411  else {
2412  sprintf(xorriso->result_line,"%s\n",xorriso->mark_text);
2413  r_ret= Xorriso_result(xorriso,1);
2414  strcpy(xorriso->info_text,xorriso->result_line);
2415  i_ret= Xorriso_info(xorriso,0);
2416  if(r_ret==0 || i_ret==0)
2417  ret= 0;
2418  }
2419  return(ret);
2420 }
2421 
2422 
2423 int Xorriso_restxt(struct XorrisO *xorriso, char *text)
2424 {
2425  int ret;
2426 
2427  strncpy(xorriso->result_line,text,sizeof(xorriso->result_line)-1);
2428  xorriso->result_line[sizeof(xorriso->result_line)-1]= 0;
2429  ret= Xorriso_result(xorriso,0);
2430  return(ret);
2431 }
2432 
2433 
2434 /* @param flag bit0-7= purpose
2435  0= ERRFILE
2436  1= mark line (only to be put out if enabled)
2437 */
2438 int Xorriso_process_errfile(struct XorrisO *xorriso,
2439  int error_code, char msg_text[], int os_errno,
2440  int flag)
2441 {
2442  char ttx[41];
2443  int purpose;
2444 
2445  if(strlen(msg_text)>SfileadrL)
2446  return(-1);
2447 
2448  purpose= flag&255;
2449  if(purpose==1 && !(xorriso->errfile_mode&1))
2450  return(2);
2451  if(xorriso->errfile_fp!=NULL) {
2452  if(purpose==1)
2453  fprintf(xorriso->errfile_fp, "----------------- %s %s\n",
2454  msg_text, Ftimetxt(time(0), ttx, 1));
2455  else
2456  fprintf(xorriso->errfile_fp, "%s\n", msg_text);
2457  fflush(xorriso->errfile_fp);
2458  return(1);
2459  }
2460  if(xorriso->errfile_log[0]==0)
2461  return(1);
2462  if(strcmp(xorriso->errfile_log, "-")==0 ||
2463  strcmp(xorriso->errfile_log, "-R")==0) {
2464  if(purpose==1)
2465  sprintf(xorriso->result_line, "----------------- %s %s\n",
2466  msg_text, Ftimetxt(time(0), ttx, 1));
2467  else
2468  sprintf(xorriso->result_line, "%s\n", msg_text);
2469  Xorriso_result(xorriso, 1);
2470  return(1);
2471  }
2472  if(strcmp(xorriso->errfile_log, "-I") == 0 &&
2473  xorriso->info_text != msg_text) { /* (Beware of stepping on own foot) */
2474  if(purpose==1)
2475  sprintf(xorriso->info_text, "ERRFILE_MARK=%s %s\n",
2476  msg_text, Ftimetxt(time(0), ttx, 1));
2477  else
2478  sprintf(xorriso->info_text, "ERRFILE=%s\n", msg_text);
2479  Xorriso_info(xorriso, 0);
2480  return(1);
2481  }
2482  return(2);
2483 }
2484 
2485 
2486 #ifdef Xorriso_fetch_with_msg_queueS
2487 /* Important: This function must stay thread-safe with all use of xorriso. */
2488 #else
2489 /* Note: It is ok to submit xorriso->info_text as msg_text here. */
2490 #endif
2491 /* flag:
2492  bit0= for Xorriso_info() : use pager (as with result)
2493  bit1= for Xorriso_info() : permission to suppress output
2494  bit2..5= name prefix
2495  0="xorriso"
2496  1="libisofs"
2497  2="libburn"
2498  3="libisoburn"
2499  else: ""
2500  bit6= append carriage return rather than line feed (if not os_errno)
2501  bit7= perform Xorriso_process_msg_queues() first
2502  bit8= do not prepend name prefix and severity
2503 */
2504 int Xorriso_msgs_submit(struct XorrisO *xorriso,
2505  int error_code, char msg_text[], int os_errno,
2506  char severity[], int flag)
2507 {
2508  int ret, lt, li, sev, i;
2509  char *sev_text= "FATAL", prefix[80], *text= NULL;
2510  static char pfx_list[20][16]= {
2511  "xorriso : ", "libisofs: ", "libburn : ", "libisoburn: ",
2512  "", "", "", "", "", "", "", "", "", "", "", "" };
2513 
2514  if(flag&128)
2515  Xorriso_process_msg_queues(xorriso, 0);
2516 
2517  if(strcmp(severity, "ERRFILE")==0)
2518  Xorriso_process_errfile(xorriso, error_code, msg_text, os_errno, 0);
2519 
2520  /* Set problem status */
2521  ret= Xorriso__text_to_sev(severity, &sev, 0);
2522  if(ret<=0)
2523  Xorriso__text_to_sev(sev_text, &sev, 0);
2524  else
2525  sev_text= severity;
2526  if(xorriso->problem_status<sev)
2527  Xorriso_set_problem_status(xorriso, sev_text, 0);
2528 
2529  /* Report problem event */
2530  if(sev<xorriso->report_about_severity && sev<xorriso->abort_on_severity)
2531  {ret= 2; goto ex;}
2532  lt= strlen(msg_text);
2533  if(!(flag & 256)) {
2534  sprintf(prefix,"%s%s : ", pfx_list[(flag>>2)&15], sev_text);
2535  li= strlen(prefix);
2536  } else {
2537  prefix[0]= 0;
2538  li= 0;
2539  }
2540  if(lt > ((int) sizeof(xorriso->info_text)) - li - 2)
2541  lt= sizeof(xorriso->info_text)-li-2;
2542 
2543 #ifdef Xorriso_fetch_with_msg_queueS
2544 
2545  Xorriso_alloc_meM(text, char, sizeof(xorriso->info_text));
2546 
2547 #else /* Xorriso_fetch_with_msg_queueS */
2548 
2549  text= xorriso->info_text;
2550 
2551 #endif /* ! Xorriso_fetch_with_msg_queueS */
2552 
2553  if(msg_text == text) {
2554  if(li > 0) {
2555  for(i= lt; i>=0; i--)
2556  msg_text[i+li]= msg_text[i];
2557  for(i=0; i<li; i++)
2558  msg_text[i]= prefix[i];
2559  }
2560  } else {
2561  if(li > 0)
2562  strcpy(text, prefix);
2563  strncpy(text + li, msg_text, lt);
2564  }
2565  if((flag&64) && os_errno<=0)
2566  text[li+lt]= '\r';
2567  else
2568  text[li+lt]= '\n';
2569  text[li+lt+1]= 0;
2570  if(os_errno>0)
2571  sprintf(text + strlen(text) - 1, " : %s\n", strerror(os_errno));
2572 
2573 #ifdef Xorriso_fetch_with_msg_queueS
2574 
2575  Xorriso_write_to_channel(xorriso, text, 2, 0);
2576 
2577 #else /* Xorriso_fetch_with_msg_queueS */
2578 
2579  Xorriso_info(xorriso,4|(flag&3));
2580 
2581 #endif /* ! Xorriso_fetch_with_msg_queueS */
2582 
2583 ex:;
2584 
2585 #ifdef Xorriso_fetch_with_msg_queueS
2587 #endif /* ! Xorriso_fetch_with_msg_queueS */
2588 
2589  return(ret);
2590 }
2591 
2592 
2593 /* To be used with isoburn_set_msgs_submit()
2594 */
2595 int Xorriso_msgs_submit_void(void *xorriso,
2596  int error_code, char msg_text[], int os_errno,
2597  char severity[], int flag)
2598 {
2599  int ret;
2600 
2601  ret= Xorriso_msgs_submit((struct XorrisO *) xorriso, error_code, msg_text,
2602  os_errno, severity, flag);
2603  return(ret);
2604 }
2605 
2606 
2607 /** @return -1= abort , 0= no , 1= yes
2608 */
2609 int Xorriso_reassure(struct XorrisO *xorriso, char *cmd, char *which_will,
2610  int flag)
2611 {
2612  int ret;
2613 
2614  if(!xorriso->do_reassure)
2615  return(1);
2616  sprintf(xorriso->info_text, "Really perform %s which will %s ? (y/n)\n",
2617  cmd, which_will);
2618  Xorriso_info(xorriso, 4);
2619  do {
2620  ret= Xorriso_request_confirmation(xorriso, 2|4|16);
2621  } while(ret==3);
2622  if(ret==6 || ret==4) {
2623  sprintf(xorriso->info_text, "%s confirmed", cmd);
2624  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
2625  return(1);
2626  }
2627  if(ret==2) {
2628  sprintf(xorriso->info_text, "%s aborted", cmd);
2629  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
2630  return(-1);
2631  }
2632  sprintf(xorriso->info_text, "%s revoked", cmd);
2633  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
2634  return(0);
2635 }
2636 
2637 
2638 int Xorriso_write_session_log(struct XorrisO *xorriso, int flag)
2639 {
2640  FILE *fp= NULL;
2641  char *sfe= NULL, timetext[40], *rpt, *wpt;
2642  int ret;
2643 
2644  if(xorriso->session_logfile[0]==0)
2645  {ret= 2; goto ex;}
2646 
2647  Xorriso_alloc_meM(sfe, char, 5 * SfileadrL);
2648 
2649  fp= fopen(xorriso->session_logfile, "a");
2650  if(fp==0) {
2651  sprintf(xorriso->info_text, "-session_log: Cannot open file %s",
2652  Text_shellsafe(xorriso->session_logfile, sfe, 0));
2653  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
2654  {ret= 0; goto ex;}
2655  }
2656  wpt= sfe;
2657  for(rpt= xorriso->volid; *rpt!=0; rpt++) {
2658  if(*rpt=='\n') {
2659  *(wpt++)= '\\';
2660  *(wpt++)= 'n';
2661  } else
2662  *(wpt++)= *rpt;
2663  }
2664  *wpt= 0;
2665  fprintf(fp, "%s %d %d %s\n",
2666  Ftimetxt(time(0), timetext, 2), xorriso->session_lba,
2667  xorriso->session_blocks, sfe);
2668  fclose(fp);
2669  ret= 1;
2670 ex:;
2671  Xorriso_free_meM(sfe);
2672  return(ret);
2673 }
2674 
2675 
2676 int Xorriso_status_filter(struct XorrisO *xorriso, char *filter, char *line,
2677  int flag)
2678 {
2679  if(filter!=NULL)
2680  if(filter[0]=='-')
2681  if(strncmp(filter, line, strlen(filter))!=0)
2682  return(0);
2683  return(1);
2684 }
2685 
2686 
2687 int Xorriso_status_result(struct XorrisO *xorriso, char *filter, FILE *fp,
2688  int flag)
2689 /*
2690 bit1= do only report to fp
2691 */
2692 {
2693  int ret;
2694 
2695  ret= Xorriso_status_filter(xorriso, filter, xorriso->result_line, 0);
2696  if(ret <= 0)
2697  return(2);
2698  if(!(flag&2))
2699  Xorriso_result(xorriso,0);
2700  if(fp!=NULL) {
2701  ret= fwrite(xorriso->result_line,strlen(xorriso->result_line),1,fp);
2702  if(ret<=0)
2703  return(ret);
2704  }
2705  return(1);
2706 }
2707 
2708 
2709 /*
2710  bit0= do only report non-default settings
2711  bit1= do only report to fp
2712 */
2713 int Xorriso_boot_status_sysarea(struct XorrisO *xorriso, char *filter,
2714  FILE *fp, int flag)
2715 {
2716  char *line, *form= "any", *spec= "system_area=";
2717  int sa_type;
2718 
2719  line= xorriso->result_line;
2720 
2721  sa_type= (xorriso->system_area_options & 0xfc) >> 2;
2722  if(sa_type != 0)
2723  return(2);
2724  if (xorriso->system_area_disk_path[0] == 0 && (flag & 1))
2725  return(2);
2726 
2727  if(xorriso->system_area_options & 1) {
2728  form= "grub";
2729  if(xorriso->system_area_options & (1 << 14))
2730  spec= "grub2_mbr=";
2731  } else if(xorriso->system_area_options & 2) {
2732  form= "isolinux";
2733  } if(xorriso->system_area_options & (1 << 14)) {
2734  form= "grub";
2735  spec= "grub2_mbr=";
2736  }
2737  sprintf(line, "-boot_image %s %s", form, spec);
2738  Text_shellsafe(xorriso->system_area_disk_path, line, 1);
2739  strcat(line, "\n");
2740  Xorriso_status_result(xorriso, filter, fp, flag & 2);
2741  return(1);
2742 }
2743 
2744 
2745 static char *Xorriso__speedname(int speed)
2746 {
2747  static char name[64];
2748 
2749  if(speed > 0) {
2750  sprintf(name, "%dkB/s", speed);
2751  return(name);
2752  } else if(speed == 0) {
2753  return("max");
2754  } else if(speed == -1) {
2755  return("min");
2756  } else if(speed == -2) {
2757  return("none");
2758  }
2759  sprintf(name, "%d", speed);
2760  return(name);
2761 }
2762 
2763 
2764 int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
2765 /*
2766  bit0= do only report non-default settings
2767  bit1= do only report to fp
2768  bit2= report current -resume status even if bit0 is set, but only if valid
2769  bit3= report readline history
2770  bit4= report -resume options indirectly as
2771  -options_from_file:${resume_state_file}_pos
2772 */
2773 {
2774  int is_default, no_defaults, i, ret, adr_mode, do_single, behavior;
2775  int show_indev= 1, show_outdev= 1, show_dev= 0;
2776  int do_drive_access, did_drive_access;
2777  int part_table_implicit= 0;
2778  char *line, *sfe= NULL, mode[80], *form, *treatment;
2779  char *in_pt, *out_pt, *nl_charset, *local_charset, *mode_pt;
2780  char *dev_filter= NULL, *xorriso_id= NULL;
2781  static char channel_prefixes[4][4]= {".","R","I","M"};
2782  static char load_names[][20]= {"auto", "session", "track", "lba", "volid"};
2783  static int max_load_mode= 4;
2784  static char scsi_family[8][8]=
2785  {"default", "sr", "scd", "st", "sg", "", "", ""};
2786  struct Xorriso_lsT *paths, *leafs, *s, *plst, *vlst;
2787 
2788  Xorriso_alloc_meM(sfe, char, 5 * SfileadrL + 80);
2789  Xorriso_alloc_meM(xorriso_id, char, 129);
2790 
2791  no_defaults= flag&1;
2792  line= xorriso->result_line;
2793 
2794  if(xorriso->no_rc) {
2795  sprintf(line,"-no_rc\n");
2796  Xorriso_status_result(xorriso,filter,fp,flag&2);
2797  }
2798 
2799  is_default= strcmp(xorriso->list_delimiter, "--") == 0;
2800  sprintf(line,"-list_delimiter %s\n", xorriso->list_delimiter);
2801  if(!(is_default && no_defaults))
2802  Xorriso_status_result(xorriso,filter,fp,flag&2);
2803 
2804  is_default= 0;
2805  if(xorriso->dialog == 2)
2806  sprintf(line,"-dialog on\n");
2807  else if(xorriso->dialog == 1)
2808  sprintf(line,"-dialog single_line\n");
2809  else {
2810  sprintf(line,"-dialog off\n");
2811  is_default= 1;
2812  }
2813  if(!(is_default && no_defaults))
2814  Xorriso_status_result(xorriso,filter,fp,flag&2);
2815 
2816  is_default= (xorriso->result_page_length==0 && xorriso->result_page_width==80);
2817  sprintf(line,"-page %d %d\n",
2818  (xorriso->result_page_length>=0?xorriso->result_page_length
2819  :-xorriso->result_page_length),
2820  xorriso->result_page_width);
2821  if(!(is_default && no_defaults))
2822  Xorriso_status_result(xorriso,filter,fp,flag&2);
2823 
2824  is_default= (xorriso->use_stdin==0);
2825  sprintf(line,"-use_readline %s\n", (xorriso->use_stdin?"off":"on"));
2826  if(!(is_default && no_defaults))
2827  Xorriso_status_result(xorriso,filter,fp,flag&2);
2828 
2829  is_default= (xorriso->sh_style_result == 0);
2830  sprintf(line, "-sh_style_result %s\n",
2831  xorriso->sh_style_result ? "on" : "off");
2832  if(!(is_default && no_defaults))
2833  Xorriso_status_result(xorriso,filter,fp,flag&2);
2834 
2835  is_default= (xorriso->bsl_interpretation == 0);
2836  strcpy(line, "-backslash_codes ");
2837  if(xorriso->bsl_interpretation == 0)
2838  strcat(line, "off");
2839  else if(xorriso->bsl_interpretation == (3 | 16 | 32 | 64))
2840  strcat(line, "on");
2841  else {
2842  if((xorriso->bsl_interpretation & 3) == 1)
2843  strcat(line, "in_double_quotes");
2844  else if((xorriso->bsl_interpretation & 3) == 2)
2845  strcat(line, "in_quotes");
2846  else if((xorriso->bsl_interpretation & 3) == 3)
2847  strcat(line, "with_quoted_input");
2848  if(xorriso->bsl_interpretation & 16) {
2849  if(strlen(line) > 17)
2850  strcat(line, ":");
2851  strcat(line, "with_program_arguments");
2852  }
2853  if((xorriso->bsl_interpretation & (32 | 64)) == (32 | 64)) {
2854  if(strlen(line) > 17)
2855  strcat(line, ":");
2856  strcat(line, "encode_output");
2857  } else {
2858  if(xorriso->bsl_interpretation & 32) {
2859  if(strlen(line) > 17)
2860  strcat(line, ":");
2861  strcat(line, "encode_results");
2862  }
2863  if(xorriso->bsl_interpretation & 64) {
2864  if(strlen(line) > 17)
2865  strcat(line, ":");
2866  strcat(line, "encode_infos");
2867  }
2868  }
2869  }
2870  strcat(line, "\n");
2871  if(!(is_default && no_defaults))
2872  Xorriso_status_result(xorriso,filter,fp,flag&2);
2873 
2874  is_default= !xorriso->packet_output;
2875  sprintf(line,"-pkt_output %s\n",(xorriso->packet_output?"on":"off"));
2876  if(!(is_default && no_defaults))
2877  Xorriso_status_result(xorriso,filter,fp,flag&2);
2878 
2879  for(i=0;i<4;i++) {
2880  is_default= (xorriso->logfile[i][0] == 0);
2881  sprintf(line,"-logfile %s %s\n",
2882  channel_prefixes[i],Text_shellsafe(xorriso->logfile[i],sfe,0));
2883  if(!(is_default && no_defaults))
2884  Xorriso_status_result(xorriso,filter,fp,flag&2);
2885  }
2886 
2887  is_default= (xorriso->errfile_log[0]==0);
2888  sprintf(line,"-errfile_log %s\n",Text_shellsafe(xorriso->errfile_log,sfe,0));
2889  if(!(is_default && no_defaults))
2890  Xorriso_status_result(xorriso,filter,fp,flag&2);
2891 
2892  if(xorriso->check_media_default == NULL) {
2893  is_default= 1;
2894  sprintf(line, "-check_media_defaults reset=now %s\n",
2895  xorriso->list_delimiter);
2896  } else {
2897  ret= Xorriso_check_media_list_job(xorriso, xorriso->check_media_default,
2898  line, no_defaults);
2899  is_default= (ret == 2);
2900  strcat(line, "\n");
2901  }
2902  if(!(is_default && no_defaults))
2903  Xorriso_status_result(xorriso,filter,fp,flag&2);
2904 
2905  behavior= Xorriso__get_signal_behavior(0);
2906  is_default= (behavior == 1);
2907  treatment= "on";
2908  if(behavior == 0)
2909  treatment= "off";
2910  else if(behavior == 2)
2911  treatment= "sig_dfl";
2912  else if(behavior == 3)
2913  treatment= "sig_ign";
2914  sprintf(line,"-signal_handling %s\n", treatment);
2915  if(!(is_default && no_defaults))
2916  Xorriso_status_result(xorriso,filter,fp,flag&2);
2917 
2918  is_default= (xorriso->img_read_error_mode==2);
2919  treatment= "best_effort";
2920  if(xorriso->img_read_error_mode==1)
2921  treatment= "failure";
2922  else if(xorriso->img_read_error_mode==2)
2923  treatment= "fatal";
2924  sprintf(line,"-error_behavior image_loading %s\n", treatment);
2925  if(!(is_default && no_defaults))
2926  Xorriso_status_result(xorriso,filter,fp,flag&2);
2927  is_default= (xorriso->extract_error_mode == 1);
2928  treatment= "keep";
2929  if(xorriso->extract_error_mode == 0)
2930  treatment= "best_effort";
2931  else if(xorriso->extract_error_mode == 2)
2932  treatment= "delete";
2933  sprintf(line,"-error_behavior file_extraction %s\n", treatment);
2934  if(!(is_default && no_defaults))
2935  Xorriso_status_result(xorriso,filter,fp,flag&2);
2936 
2937  is_default= (xorriso->mark_text[0]==0);
2938  sprintf(line,"-mark %s\n",Text_shellsafe(xorriso->mark_text,sfe,0));
2939  if(!(is_default && no_defaults))
2940  Xorriso_status_result(xorriso,filter,fp,flag&2);
2941 
2942  is_default= (xorriso->temp_mem_limit==16*1024*1024);
2943  if((xorriso->temp_mem_limit/1024/1024)*1024*1024==xorriso->temp_mem_limit)
2944  sprintf(line,"-temp_mem_limit %dm\n", xorriso->temp_mem_limit/1024/1024);
2945  else
2946  sprintf(line,"-temp_mem_limit %dk\n", xorriso->temp_mem_limit/1024);
2947  if(!(is_default && no_defaults))
2948  Xorriso_status_result(xorriso,filter,fp,flag&2);
2949 
2950 
2951  sprintf(line,"-prog %s\n",Text_shellsafe(xorriso->progname,sfe,0));
2952  Xorriso_status_result(xorriso,filter,fp,flag&2);
2953 
2954  if(xorriso->ban_stdio_write) {
2955  sprintf(line,"-ban_stdio_write\n");
2956  Xorriso_status_result(xorriso,filter,fp,flag&2);
2957  }
2958 
2959  is_default= ((xorriso->early_stdio_test & 14) == 0);
2960  sprintf(line, "-early_stdio_test %s\n",
2961  xorriso->early_stdio_test & 6 ? xorriso->early_stdio_test & 8 ?
2962  "appendable_wo" : "on" : "off");
2963  if(!(is_default && no_defaults))
2964  Xorriso_status_result(xorriso,filter,fp,flag&2);
2965 
2966  is_default= ((xorriso->cache_default & 3) == 3);
2967  sprintf(line, "-data_cache_size ");
2968  if(xorriso->cache_default & 1)
2969  sprintf(line + strlen(line), "default ");
2970  else
2971  sprintf(line + strlen(line), "%d ", xorriso->cache_num_tiles);
2972  if(xorriso->cache_default & 2)
2973  sprintf(line + strlen(line), "default\n");
2974  else
2975  sprintf(line + strlen(line), "%d\n", xorriso->cache_tile_blocks);
2976  if(!(is_default && no_defaults))
2977  Xorriso_status_result(xorriso,filter,fp,flag&2);
2978 
2979  is_default= (xorriso->allow_restore==0 && xorriso->do_concat_split==1 &&
2980  xorriso->do_auto_chmod==0 && xorriso->drives_exclusive == 1);
2981  mode_pt= "off";
2982  if(xorriso->allow_restore == -2)
2983  mode_pt= "blocked";
2984  else if(xorriso->allow_restore == -1)
2985  mode_pt= "banned";
2986  else if(xorriso->allow_restore == 1)
2987  mode_pt= "on";
2988  else if(xorriso->allow_restore == 2)
2989  mode_pt= "device_files";
2990  if(xorriso->allow_restore == -1)
2991  sprintf(line,"-osirrox %s\n", mode_pt);
2992  else
2993  sprintf(line,"-osirrox %s:%s:%s:%s:%s\n", mode_pt,
2994  xorriso->do_concat_split ? "concat_split_on" : "concat_split_off",
2995  xorriso->do_auto_chmod ? "auto_chmod_on" : "auto_chmod_off",
2996  xorriso->do_restore_sort_lba ? "sort_lba_on" : "sort_lba_off",
2997  xorriso->drives_exclusive ? "o_excl_on" : "o_excl_off");
2998  if(!(is_default && no_defaults))
2999  Xorriso_status_result(xorriso,filter,fp,flag&2);
3000 
3001  is_default = ((xorriso->do_strict_acl & 1) == 0 &&
3002  (xorriso->do_md5 & (64 | 128)) == 0 &&
3003  xorriso->sparse_min_gap == 0);
3004  sprintf(line,"-osirrox %s:%s:sparse=",
3005  (xorriso->do_strict_acl & 1) ? "strict_acl_on" : "strict_acl_off",
3006  (xorriso->do_md5 & 64) ?
3007  (xorriso->do_md5 & 128) ? "check_md5_force" : "check_md5_on"
3008  : "check_md5_off");
3009  if(xorriso->sparse_min_gap <= 0)
3010  strcat(line, "off");
3011  else
3012  Sfile_off_t_text(line + strlen(line), xorriso->sparse_min_gap, 0);
3013  strcat(line, "\n");
3014  if(!(is_default && no_defaults))
3015  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3016 
3017  is_default= (xorriso->mount_opts_flag == 0);
3018  sprintf(line,"-mount_opts %s\n",
3019  xorriso->mount_opts_flag & 1 ? "shared" : "exclusive");
3020  if(!(is_default && no_defaults))
3021  Xorriso_status_result(xorriso,filter,fp,flag&2);
3022 
3023  Xorriso_boot_image_status(xorriso, filter, fp, flag & 3);
3024 
3025  Xorriso_boot_status_sysarea(xorriso, filter, fp, flag & 3);
3026 
3027  is_default= (xorriso->partition_offset == 0);
3028  sprintf(line,"-boot_image any partition_offset=%lu\n",
3029  (unsigned long int) xorriso->partition_offset);
3030  if(!(is_default && no_defaults))
3031  Xorriso_status_result(xorriso,filter,fp,flag&2);
3032  is_default= (xorriso->partition_secs_per_head == 0);
3033  sprintf(line,"-boot_image any partition_sec_hd=%lu\n",
3034  (unsigned long int) xorriso->partition_secs_per_head);
3035  if(!(is_default && no_defaults))
3036  Xorriso_status_result(xorriso,filter,fp,flag&2);
3037  is_default= (xorriso->partition_heads_per_cyl == 0);
3038  sprintf(line,"-boot_image any partition_hd_cyl=%lu\n",
3039  (unsigned long int) xorriso->partition_heads_per_cyl);
3040  if(!(is_default && no_defaults))
3041  Xorriso_status_result(xorriso,filter,fp,flag&2);
3042 
3043  ret= (xorriso->system_area_options & 0x300) >> 8;
3044  is_default= (ret == 0);
3045  sprintf(line,"-boot_image any partition_cyl_align=%s\n",
3046  ret == 0 ? "auto" : ret == 1 ? "on" : ret == 3 ? "all" : "off");
3047  if(!(is_default && no_defaults))
3048  Xorriso_status_result(xorriso,filter,fp,flag&2);
3049 
3050  if((xorriso->system_area_disk_path[0] || !part_table_implicit) &&
3051  (xorriso->partition_offset == 0 || (xorriso->system_area_options & 2))) {
3052  is_default= ((xorriso->system_area_options & 3) == 0);
3053  sprintf(line,"-boot_image %s partition_table=%s\n",
3054  xorriso->system_area_options & 2 ? "isolinux" : "grub",
3055  xorriso->system_area_options & 3 ? "on" : "off");
3056  if(!(is_default && no_defaults))
3057  Xorriso_status_result(xorriso,filter,fp,flag&2);
3058  }
3059 
3060  is_default= ((xorriso->system_area_options & (1 << 15)) == 0);
3061  sprintf(line, "-boot_image any mbr_force_bootable=%s\n",
3062  (xorriso->system_area_options & (1 << 15)) ? "on" : "off");
3063  if(!(is_default && no_defaults))
3064  Xorriso_status_result(xorriso,filter,fp,flag&2);
3065 
3066  is_default= (xorriso->appended_as_gpt == 0 && xorriso->appended_as_apm == 0);
3067  if(is_default) {
3068  sprintf(line, "-boot_image any appended_part_as=mbr\n");
3069  if(!no_defaults)
3070  Xorriso_status_result(xorriso,filter,fp,flag&2);
3071  } else {
3072  if(xorriso->appended_as_gpt) {
3073  sprintf(line, "-boot_image any appended_part_as=gpt\n");
3074  Xorriso_status_result(xorriso,filter,fp,flag&2);
3075  }
3076  if(xorriso->appended_as_apm) {
3077  sprintf(line, "-boot_image any appended_part_as=apm\n");
3078  Xorriso_status_result(xorriso,filter,fp,flag&2);
3079  }
3080  }
3081 
3082  is_default= (xorriso->part_like_isohybrid == 0);
3083  sprintf(line, "-boot_image any part_like_isohybrid=%s\n",
3084  xorriso->part_like_isohybrid ? "on" : "off");
3085  if(!(is_default && no_defaults))
3086  Xorriso_status_result(xorriso,filter,fp,flag&2);
3087 
3088  is_default= (xorriso->iso_mbr_part_type == -1);
3089  sprintf(line, "-boot_image any iso_mbr_part_type=");
3090  if(xorriso->iso_mbr_part_flag & 1) {
3091  Xorriso__format_guid(xorriso->iso_gpt_type_guid, line + strlen(line), 0);
3092  strcat(line, "\n");
3093  } else if(xorriso->iso_mbr_part_type == -1) {
3094  sprintf(line + strlen(line), "default\n");
3095  } else {
3096  sprintf(line + strlen(line), "0x%-2.2x\n",
3097  (unsigned int) xorriso->iso_mbr_part_type);
3098  }
3099  if(!(is_default && no_defaults))
3100  Xorriso_status_result(xorriso,filter,fp,flag&2);
3101 
3102  is_default= (xorriso->gpt_guid_mode == 0);
3103  sprintf(line, "-boot_image any gpt_disk_guid=%s",
3104  xorriso->gpt_guid_mode == 0 ? "random" :
3105  xorriso->gpt_guid_mode == 2 ? "volume_date_uuid" : "");
3106  if(xorriso->gpt_guid_mode == 1)
3107  for(i= 0; i < 16; i++)
3108  sprintf(line + strlen(line), "%-2.2x",
3109  (unsigned int) xorriso->gpt_guid[i]);
3110  strcat(line, "\n");
3111  if(!(is_default && no_defaults))
3112  Xorriso_status_result(xorriso,filter,fp,flag&2);
3113 
3114  ret= ((xorriso->system_area_options & 0x3cfc) == 0x400);
3115  is_default= (ret == 0);
3116  sprintf(line, "-boot_image any chrp_boot_part=%s\n",
3117  ret == 1 ? "on" : "off");
3118  if(!(is_default && no_defaults))
3119  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3120 
3121  is_default= (xorriso->prep_partition[0] == 0);
3122  sprintf(line,"-boot_image any prep_boot_part=%s\n",
3123  Text_shellsafe(xorriso->prep_partition, sfe, 0));
3124  if(!(is_default && no_defaults))
3125  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3126 
3127  is_default= (xorriso->efi_boot_partition[0] == 0);
3128  sprintf(line,"-boot_image any efi_boot_part=%s\n",
3129  Text_shellsafe(xorriso->efi_boot_partition, sfe, 0));
3130  if(!(is_default && no_defaults))
3131  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3132 
3133 #ifdef Xorriso_with_isohybriD
3134  if(strcmp(form, "isolinux") == 0) {
3135  static char modes[4][6]= {"off", "auto", "on", "force"};
3136  is_default= (xorriso->boot_image_isohybrid == 1);
3137  sprintf(line,"-boot_image isolinux isohybrid=%s\n",
3138  modes[xorriso->boot_image_isohybrid & 3]);
3139  if(!(is_default && no_defaults))
3140  Xorriso_status_result(xorriso,filter,fp,flag&2);
3141  }
3142 #endif /* Xorriso_with_isohybriD */
3143 
3144  is_default= 1;
3145  for(i= 0; i < 8; i++)
3146  if(xorriso->hfsp_serial_number[i])
3147  is_default= 0;
3148  sprintf(line, "-boot_image any hfsplus_serial=");
3149  for(i= 0; i < 8; i++)
3150  sprintf(line + strlen(line), "%-2.2X",
3151  (unsigned int) xorriso->hfsp_serial_number[i]);
3152  strcat(line, "\n");
3153  if(!(is_default && no_defaults))
3154  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3155 
3156  is_default= (xorriso->hfsp_block_size == 0);
3157  sprintf(line, "-boot_image any hfsplus_block_size=%d\n",
3158  xorriso->hfsp_block_size);
3159  if(!(is_default && no_defaults))
3160  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3161 
3162  is_default= (xorriso->apm_block_size == 0);
3163  sprintf(line, "-boot_image any apm_block_size=%d\n",
3164  xorriso->apm_block_size);
3165  if(!(is_default && no_defaults))
3166  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3167 
3168  sprintf(line,"-cd ");
3169  if(filter != NULL)
3170  if(strncmp(filter, "-cdi", 4) == 0)
3171  sprintf(line,"-cdi ");
3172  sprintf(line + strlen(line),"%s\n",
3173  (xorriso->wdi[0] ? Text_shellsafe(xorriso->wdi,sfe,0) : "'/'"));
3174  Xorriso_status_result(xorriso,filter,fp,flag&2);
3175  sprintf(line,"-cdx %s\n",
3176  (xorriso->wdx[0] ? Text_shellsafe(xorriso->wdx,sfe,0) : "'/'"));
3177  Xorriso_status_result(xorriso,filter,fp,flag&2);
3178 
3179  is_default= (xorriso->split_size==0);
3180  strcpy(line,"-split_size ");
3181  if(xorriso->split_size % (1024*1024) || xorriso->split_size==0) {
3182  Sfile_off_t_text(line+strlen(line), xorriso->split_size, 0);
3183  } else {
3184  Sfile_off_t_text(line+strlen(line), xorriso->split_size / (1024*1024), 0);
3185  strcat(line, "m");
3186  }
3187  strcat(line, "\n");
3188  if(!(is_default && no_defaults))
3189  Xorriso_status_result(xorriso,filter,fp,flag&2);
3190 
3191  is_default= (xorriso->add_plainly==0);
3192  sprintf(line,"-add_plainly %s\n",
3193  (xorriso->add_plainly == 1 ? "unknown" :
3194  xorriso->add_plainly == 2 ? "dashed" :
3195  xorriso->add_plainly == 3 ? "any" : "none"));
3196  if(!(is_default && no_defaults))
3197  Xorriso_status_result(xorriso,filter,fp,flag&2);
3198 
3199  ret= Exclusions_get_descrs(xorriso->disk_exclusions, &paths, &leafs, 0);
3200  if(ret>0) {
3201  for(; paths!=NULL; paths= paths->next) {
3202  sprintf(line, "-not_paths %s %s\n",
3203  Text_shellsafe(paths->text, sfe, 0), xorriso->list_delimiter);
3204  Xorriso_status_result(xorriso,filter,fp,flag&2);
3205  }
3206  for(; leafs!=NULL; leafs= leafs->next) {
3207  sprintf(line,"-not_leaf %s\n", Text_shellsafe(leafs->text, sfe, 0));
3208  Xorriso_status_result(xorriso,filter,fp,flag&2);
3209  }
3210  }
3211 
3212  is_default= (xorriso->file_name_limit == 255);
3213  sprintf(line, "-file_name_limit %d\n", xorriso->file_name_limit);
3214  if(!(is_default && no_defaults))
3215  Xorriso_status_result(xorriso,filter,fp,flag&2);
3216 
3217  is_default= (xorriso->file_size_limit ==
3219  if(xorriso->file_size_limit <= 0)
3220  sprintf(line, "-file_size_limit off %s\n", xorriso->list_delimiter);
3221  else
3222  sprintf(line, "-file_size_limit %.f %s\n",
3223  (double) xorriso->file_size_limit, xorriso->list_delimiter);
3224  if(!(is_default && no_defaults))
3225  Xorriso_status_result(xorriso,filter,fp,flag&2);
3226 
3227  is_default= (xorriso->disk_excl_mode==1);
3228  sprintf(line, "-not_mgt %s:%s:%s:%s\n",
3229  (xorriso->disk_excl_mode&1 ? "on" : "off"),
3230  (xorriso->disk_excl_mode&2 ? "param_on" : "param_off"),
3231  (xorriso->disk_excl_mode&4 ? "subtree_on" : "subtree_off"),
3232  (xorriso->disk_excl_mode&8 ? "ignore_on" : "ignore_off"));
3233  if(!(is_default && no_defaults))
3234  Xorriso_status_result(xorriso,filter,fp,flag&2);
3235 
3236  is_default= (xorriso->do_override_now_time == 0);
3237  if(xorriso->do_override_now_time)
3238  sprintf(line, "-iso_nowtime =%.f\n", (double) xorriso->now_time_override);
3239  else
3240  sprintf(line, "-iso_nowtime dynamic\n");
3241  if(!(is_default && no_defaults))
3242  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3243 
3244  is_default= (xorriso->do_iso_rr_pattern==1);
3245  sprintf(line,"-iso_rr_pattern %s\n",
3246  (xorriso->do_iso_rr_pattern == 1 ? "on" :
3247  (xorriso->do_iso_rr_pattern == 2 ? "ls" : "off")));
3248  if(!(is_default && no_defaults))
3249  Xorriso_status_result(xorriso,filter,fp,flag&2);
3250 
3251  is_default= (xorriso->do_disk_pattern==2);
3252  sprintf(line,"-disk_pattern %s\n",
3253  (xorriso->do_disk_pattern == 1 ? "on" :
3254  (xorriso->do_disk_pattern == 2 ? "ls" : "off")));
3255  if(!(is_default && no_defaults))
3256  Xorriso_status_result(xorriso,filter,fp,flag&2);
3257 
3258  is_default= xorriso->volid_default;
3259  sprintf(line,"-volid %s\n",Text_shellsafe(xorriso->volid,sfe,0));
3260  if(!(is_default && no_defaults))
3261  Xorriso_status_result(xorriso,filter,fp,flag&2);
3262  if(is_default && xorriso->loaded_volid[0] &&
3263  strcmp(xorriso->loaded_volid, xorriso->volid)!=0 && !no_defaults) {
3264  sprintf(line,"# loaded image effective -volid %s\n",
3265  Text_shellsafe(xorriso->loaded_volid,sfe,0));
3266  Xorriso_status_result(xorriso,filter,fp,flag&2);
3267  }
3268 
3269  Xorriso_preparer_string(xorriso, xorriso_id, 0);
3270  is_default= (strcmp(xorriso->preparer_id, xorriso_id) == 0);
3271  sprintf(line,"-preparer_id %s\n",Text_shellsafe(xorriso->preparer_id,sfe,0));
3272  if(!(is_default && no_defaults))
3273  Xorriso_status_result(xorriso,filter,fp,flag&2);
3274 
3275  is_default= (xorriso->publisher[0]==0);
3276  sprintf(line,"-publisher %s\n",Text_shellsafe(xorriso->publisher,sfe,0));
3277  if(!(is_default && no_defaults))
3278  Xorriso_status_result(xorriso,filter,fp,flag&2);
3279 
3280  is_default= (xorriso->application_id[0]==0);
3281  sprintf(line,"-application_id %s\n",
3282  Text_shellsafe(xorriso->application_id,sfe,0));
3283  if(!(is_default && no_defaults))
3284  Xorriso_status_result(xorriso,filter,fp,flag&2);
3285 
3286  is_default= (xorriso->system_id[0]==0);
3287  sprintf(line,"-system_id %s\n", Text_shellsafe(xorriso->system_id,sfe,0));
3288  if(!(is_default && no_defaults))
3289  Xorriso_status_result(xorriso,filter,fp,flag&2);
3290 
3291  is_default= (xorriso->volset_id[0]==0);
3292  sprintf(line,"-volset_id %s\n", Text_shellsafe(xorriso->volset_id,sfe,0));
3293  if(!(is_default && no_defaults))
3294  Xorriso_status_result(xorriso,filter,fp,flag&2);
3295 
3296  is_default= (xorriso->vol_creation_time == 0);
3297  sprintf(line,"-volume_date c %s\n",
3298  is_default ? "default" :
3299  Ftimetxt(xorriso->vol_creation_time, sfe, 2));
3300  if(!(is_default && no_defaults))
3301  Xorriso_status_result(xorriso,filter,fp,flag&2);
3302 
3303  is_default= (xorriso->vol_modification_time == 0);
3304  sprintf(line,"-volume_date m %s\n",
3305  xorriso->vol_uuid[0] ? "overridden" :
3306  is_default ? "default" :
3307  Ftimetxt(xorriso->vol_modification_time, sfe, 2));
3308  if(!(is_default && no_defaults))
3309  Xorriso_status_result(xorriso,filter,fp,flag&2);
3310 
3311  is_default= (xorriso->vol_expiration_time == 0);
3312  sprintf(line,"-volume_date x %s\n",
3313  is_default ? "default" :
3314  Ftimetxt(xorriso->vol_expiration_time, sfe, 2));
3315  if(!(is_default && no_defaults))
3316  Xorriso_status_result(xorriso,filter,fp,flag&2);
3317 
3318  is_default= (xorriso->vol_effective_time == 0);
3319  sprintf(line,"-volume_date f %s\n",
3320  is_default ? "default" :
3321  Ftimetxt(xorriso->vol_effective_time, sfe, 2));
3322  if(!(is_default && no_defaults))
3323  Xorriso_status_result(xorriso,filter,fp,flag&2);
3324 
3325  is_default= (xorriso->vol_uuid[0] == 0);
3326  sprintf(line,"-volume_date uuid %s\n",
3327  Text_shellsafe(xorriso->vol_uuid,sfe,0));
3328  if(!(is_default && no_defaults))
3329  Xorriso_status_result(xorriso,filter,fp,flag&2);
3330 
3331  is_default= (xorriso->all_file_dates[0] == 0);
3332  sprintf(line,"-volume_date all_file_dates %s\n",
3333  Text_shellsafe(xorriso->all_file_dates,sfe,0));
3334  if(!(is_default && no_defaults))
3335  Xorriso_status_result(xorriso,filter,fp,flag&2);
3336 
3337  is_default= (xorriso->copyright_file[0] == 0);
3338  sprintf(line,"-copyright_file %s\n",
3339  Text_shellsafe(xorriso->copyright_file,sfe,0));
3340  if(!(is_default && no_defaults))
3341  Xorriso_status_result(xorriso,filter,fp,flag&2);
3342 
3343  is_default= (xorriso->biblio_file[0]==0);
3344  sprintf(line,"-biblio_file %s\n",Text_shellsafe(xorriso->biblio_file,sfe,0));
3345  if(!(is_default && no_defaults))
3346  Xorriso_status_result(xorriso,filter,fp,flag&2);
3347 
3348  is_default= (xorriso->abstract_file[0]==0);
3349  sprintf(line,"-abstract_file %s\n",
3350  Text_shellsafe(xorriso->abstract_file,sfe,0));
3351  if(!(is_default && no_defaults))
3352  Xorriso_status_result(xorriso,filter,fp,flag&2);
3353 
3354  is_default= (strcmp(xorriso->application_use, " ") == 0);
3355  sprintf(line, "-application_use %s\n",
3356  Text_shellsafe(xorriso->application_use, sfe, 0));
3357  if(!(is_default && no_defaults))
3358  Xorriso_status_result(xorriso,filter,fp,flag&2);
3359 
3360  is_default= (xorriso->do_joliet==0);
3361  sprintf(line,"-joliet %s\n", (xorriso->do_joliet == 1 ? "on" : "off"));
3362  if(!(is_default && no_defaults))
3363  Xorriso_status_result(xorriso,filter,fp,flag&2);
3364 
3365  is_default= (xorriso->do_rockridge == 1);
3366  sprintf(line, "-rockridge %s\n", (xorriso->do_rockridge == 1 ? "on" : "off"));
3367  if(!(is_default && no_defaults))
3368  Xorriso_status_result(xorriso,filter,fp,flag&2);
3369 
3370  is_default= (xorriso->do_hfsplus == 0);
3371  sprintf(line,"-hfsplus %s\n", (xorriso->do_hfsplus == 1 ? "on" : "off"));
3372  if(!(is_default && no_defaults))
3373  Xorriso_status_result(xorriso,filter,fp,flag&2);
3374 
3375  Xorriso_lst_get_last(xorriso->jigdo_params, &plst, 0);
3376  Xorriso_lst_get_last(xorriso->jigdo_values, &vlst, 0);
3377  if(plst == NULL || vlst == NULL) {
3378  is_default= 1;
3379  sprintf(line,"-jigdo clear 'all'\n");
3380  if(!(is_default && no_defaults))
3381  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3382  }
3383  while(plst != NULL && vlst != NULL) {
3384  sprintf(line,"-jigdo %s %s\n", Xorriso_lst_get_text(plst, 0),
3385  Text_shellsafe(Xorriso_lst_get_text(vlst, 0), sfe, 0));
3386  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3387  plst= Xorriso_lst_get_prev(plst, 0);
3388  vlst= Xorriso_lst_get_prev(vlst, 0);
3389  }
3390 
3391  if(xorriso->do_global_uid) {
3392  sprintf(line,"-uid %lu\n", (unsigned long) xorriso->global_uid);
3393  Xorriso_status_result(xorriso,filter,fp,flag&2);
3394  }
3395 
3396  if(xorriso->do_global_gid) {
3397  sprintf(line,"-gid %lu\n", (unsigned long) xorriso->global_gid);
3398  Xorriso_status_result(xorriso,filter,fp,flag&2);
3399  }
3400 
3401  Xorriso_status_extf(xorriso, filter, fp, flag & 2);
3402  Xorriso_status_zisofs(xorriso, filter, fp, flag & 3);
3403 
3404  is_default= !xorriso->allow_graft_points;
3405  sprintf(line,"-pathspecs %s\n",
3406  (xorriso->allow_graft_points & 2) ? "as_mkisofs" :
3407  xorriso->allow_graft_points ? "on" : "off");
3408  if(!(is_default && no_defaults))
3409  Xorriso_status_result(xorriso,filter,fp,flag&2);
3410 
3411  is_default= (xorriso->do_follow_pattern && (!xorriso->do_follow_param)
3412  && xorriso->do_follow_mount && (!xorriso->do_follow_links)
3413  && xorriso->follow_link_limit==100
3414  && (!xorriso->do_follow_concat));
3415  mode[0]= 0;
3416  if(xorriso->do_follow_pattern &&
3417  !(xorriso->do_follow_links && xorriso->do_follow_mount))
3418  strcat(mode,":pattern");
3419  if(xorriso->do_follow_param && !(xorriso->do_follow_links))
3420  strcat(mode,":param");
3421  if(xorriso->do_follow_links)
3422  strcat(mode,":link");
3423  if(xorriso->do_follow_concat)
3424  strcat(mode,":concat");
3425  if(xorriso->do_follow_mount)
3426  strcat(mode,":mount");
3427  if(mode[0]==0)
3428  strcpy(mode, ":off");
3429  sprintf(mode+strlen(mode), ":limit=%d", xorriso->follow_link_limit);
3430  sprintf(line,"-follow %s\n", mode+1);
3431  if(!(is_default && no_defaults))
3432  Xorriso_status_result(xorriso,filter,fp,flag&2);
3433 
3434  is_default= (xorriso->do_overwrite==2);
3435  sprintf(line,"-overwrite %s\n",(xorriso->do_overwrite == 1 ? "on" :
3436  (xorriso->do_overwrite == 2 ? "nondir" : "off")));
3437  if(!(is_default && no_defaults))
3438  Xorriso_status_result(xorriso,filter,fp,flag&2);
3439 
3440  is_default= !xorriso->do_reassure;
3441  sprintf(line,"-reassure %s\n",(xorriso->do_reassure == 1 ? "on" :
3442  (xorriso->do_reassure == 2 ? "tree" : "off")));
3443  if(!(is_default && no_defaults))
3444  Xorriso_status_result(xorriso,filter,fp,flag&2);
3445 
3446  is_default= (xorriso->read_speed == -2);
3447  sprintf(line,"-read_speed %s\n", Xorriso__speedname(xorriso->read_speed));
3448  if(!(is_default && no_defaults))
3449  Xorriso_status_result(xorriso,filter,fp,flag&2);
3450  is_default= (xorriso->read_speed_force <= 0);
3451  sprintf(line,"-read_speed soft_force:%s\n",
3452  xorriso->read_speed_force <= 0 ?
3453  "0" : Xorriso__speedname(xorriso->read_speed_force));
3454  if(!(is_default && no_defaults))
3455  Xorriso_status_result(xorriso,filter,fp,flag&2);
3456  is_default= (xorriso->read_speed_corr == 250000);
3457  sprintf(line,"-read_speed soft_corr:%d\n", xorriso->read_speed_corr);
3458  if(!(is_default && no_defaults))
3459  Xorriso_status_result(xorriso,filter,fp,flag&2);
3460 
3461  is_default= !(xorriso->auto_close || xorriso->do_close);
3462  sprintf(line,"-close %s\n",xorriso->auto_close ? "as_needed" :
3463  xorriso->do_close ? "on" : "off");
3464  if(!(is_default && no_defaults))
3465  Xorriso_status_result(xorriso,filter,fp,flag&2);
3466 
3467  is_default= (xorriso->do_tao == 0);
3468  sprintf(line,"-write_type %s\n",
3469  xorriso->do_tao == 0 ? "auto" : xorriso->do_tao > 0 ? "tao" : "sao/dao");
3470  if(!(is_default && no_defaults))
3471  Xorriso_status_result(xorriso,filter,fp,flag&2);
3472 
3473  is_default= !xorriso->do_dummy;
3474  sprintf(line,"-dummy %s\n",(xorriso->do_dummy ? "on" : "off"));
3475  if(!(is_default && no_defaults))
3476  Xorriso_status_result(xorriso,filter,fp,flag&2);
3477 
3478  is_default= (xorriso->write_speed==0);
3479  sprintf(line,"-speed %s\n", Xorriso__speedname(xorriso->write_speed));
3480  if(!(is_default && no_defaults))
3481  Xorriso_status_result(xorriso,filter,fp,flag&2);
3482 
3483  is_default= (xorriso->do_stream_recording==0);
3484  strcpy(mode, "off");
3485  if(xorriso->do_stream_recording == 1)
3486  strcpy(mode, "full");
3487  if(xorriso->do_stream_recording == 2)
3488  strcpy(mode, "data");
3489  else if(xorriso->do_stream_recording == 32)
3490  strcpy(mode, "on");
3491  else if(xorriso->do_stream_recording >= 16)
3492  sprintf(mode, "%ds", xorriso->do_stream_recording);
3493  sprintf(line,"-stream_recording %s\n", mode);
3494  if(!(is_default && no_defaults))
3495  Xorriso_status_result(xorriso,filter,fp,flag&2);
3496 
3497  is_default= (xorriso->modesty_on_drive == 0 &&
3498  xorriso->min_buffer_usec == 5000 &&
3499  xorriso->max_buffer_usec == 25000 &&
3500  xorriso->buffer_timeout_sec == 120 &&
3501  xorriso->min_buffer_percent == 90 &&
3502  xorriso->max_buffer_percent == 95);
3503  if(xorriso->modesty_on_drive == 0)
3504  strcpy(mode, "off");
3505  else if(xorriso->modesty_on_drive == 1)
3506  strcpy(mode, "on");
3507  else
3508  sprintf(mode, "%d", xorriso->modesty_on_drive);
3509  sprintf(mode + strlen(mode), ":min_percent=%d", xorriso->min_buffer_percent);
3510  sprintf(mode + strlen(mode), ":max_percent=%d", xorriso->max_buffer_percent);
3511  if(xorriso->buffer_timeout_sec >= 0)
3512  sprintf(mode + strlen(mode), ":timeout_sec=%d", xorriso->buffer_timeout_sec);
3513  if(xorriso->min_buffer_usec >= 0)
3514  sprintf(mode + strlen(mode), ":min_usec=%d", xorriso->min_buffer_usec);
3515  if(xorriso->max_buffer_usec >= 0)
3516  sprintf(mode + strlen(mode), ":max_usec=%d", xorriso->max_buffer_usec);
3517  sprintf(line,"-modesty_on_drive %s\n", mode);
3518  if(!(is_default && no_defaults))
3519  Xorriso_status_result(xorriso,filter,fp,flag&2);
3520 
3521  is_default= (xorriso->dvd_obs == 0);
3522  strcpy(mode, "default");
3523  if(xorriso->dvd_obs == 32768 || xorriso->dvd_obs == 65536)
3524  sprintf(mode, "%dk", xorriso->dvd_obs / 1024);
3525  sprintf(line,"-dvd_obs %s\n", mode);
3526  if(!(is_default && no_defaults))
3527  Xorriso_status_result(xorriso,filter,fp,flag&2);
3528 
3529  is_default= (xorriso->use_immed_bit == 0);
3530  strcpy(line, "-use_immed_bit ");
3531  if(xorriso->use_immed_bit == 0) {
3532  strcat(line, "default");
3533  if(xorriso->use_immed_bit_default > 0)
3534  strcat(line, "/on");
3535  else if(xorriso->use_immed_bit_default < 0)
3536  strcat(line, "/off");
3537  strcat(line, "\n");
3538  } else if(xorriso->use_immed_bit > 0) {
3539  strcat(line, "on\n");
3540  } else if(xorriso->use_immed_bit < 0) {
3541  strcat(line, "off\n");
3542  }
3543  if(!(is_default && no_defaults))
3544  Xorriso_status_result(xorriso,filter,fp,flag&2);
3545 
3546  is_default= (xorriso->stdio_sync == 0);
3547  strcpy(line, "-stdio_sync ");
3548  if(xorriso->stdio_sync == -1)
3549  strcat(line, "off");
3550  else if(xorriso->stdio_sync == 0)
3551  strcat(line, "on");
3552  else if(xorriso->stdio_sync == 1)
3553  strcat(line, "end");
3554  else if(xorriso->stdio_sync % 512) {
3555  Sfile_off_t_text(line+strlen(line), (off_t) (xorriso->stdio_sync * 2048),
3556  0);
3557  } else {
3558  Sfile_off_t_text(line+strlen(line), (off_t) (xorriso->stdio_sync / 512), 0);
3559  strcat(line, "m");
3560  }
3561  strcat(line, "\n");
3562  if(!(is_default && no_defaults))
3563  Xorriso_status_result(xorriso,filter,fp,flag&2);
3564 
3565  is_default= (xorriso->fs==4*512);
3566  if((xorriso->fs/512)*512==xorriso->fs)
3567  sprintf(line,"-fs %dm\n", xorriso->fs/512);
3568  else
3569  sprintf(line,"-fs %dk\n", xorriso->fs*2);
3570  if(!(is_default && no_defaults))
3571  Xorriso_status_result(xorriso,filter,fp,flag&2);
3572 
3573  is_default= (xorriso->padding==300*1024);
3574  sprintf(line,"-padding %dk\n", xorriso->padding/1024);
3575  if(!(is_default && no_defaults))
3576  Xorriso_status_result(xorriso,filter,fp,flag&2);
3577  is_default= (xorriso->do_padding_by_libisofs == 0);
3578  sprintf(line,"-padding %s\n",
3579  xorriso->do_padding_by_libisofs ? "included" : "appended");
3580  if(!(is_default && no_defaults))
3581  Xorriso_status_result(xorriso,filter,fp,flag&2);
3582 
3583  is_default= (strcmp(xorriso->report_about_text,"UPDATE")==0);
3584  sprintf(line,"-report_about %s\n",xorriso->report_about_text);
3585  if(!(is_default && no_defaults))
3586  Xorriso_status_result(xorriso,filter,fp,flag&2);
3587 
3588  is_default= (xorriso->scsi_log == 0);
3589  sprintf(line,"-scsi_log %s\n", xorriso->scsi_log ? "on" : "off");
3590  if(!(is_default && no_defaults))
3591  Xorriso_status_result(xorriso,filter,fp,flag&2);
3592 
3593  is_default= (xorriso->session_logfile[0]==0);
3594  sprintf(line,"-session_log %s\n",
3595  Text_shellsafe(xorriso->session_logfile,sfe,0));
3596  if(!(is_default && no_defaults))
3597  Xorriso_status_result(xorriso,filter,fp,flag&2);
3598 
3599  is_default= (xorriso->pacifier_style==0);
3600  sprintf(line,"-pacifier '%s'\n",
3601  xorriso->pacifier_style==1 ? "mkisofs" :
3602  xorriso->pacifier_style==2 ? "cdrecord" : "xorriso");
3603  if(!(is_default && no_defaults))
3604  Xorriso_status_result(xorriso,filter,fp,flag&2);
3605  is_default= (xorriso->pacifier_interval == 1.0);
3606  sprintf(line,"-pacifier interval=%f\n", xorriso->pacifier_interval);
3607  if(!(is_default && no_defaults))
3608  Xorriso_status_result(xorriso,filter,fp,flag&2);
3609 
3610  is_default= (strcmp(xorriso->return_with_text,"SORRY")==0 &&
3611  xorriso->return_with_value==32);
3612  sprintf(line,"-return_with %s %d\n",
3613  xorriso->return_with_text, xorriso->return_with_value);
3614  if(!(is_default && no_defaults))
3615  Xorriso_status_result(xorriso,filter,fp,flag&2);
3616 
3617  is_default= 0;
3618  sprintf(line,"-abort_on %s\n",xorriso->abort_on_text);
3619  if(!(is_default && no_defaults))
3620  Xorriso_status_result(xorriso,filter,fp,flag&2);
3621 
3622  if(xorriso->status_history_max!=Xorriso_status_history_maX || !no_defaults) {
3623  sprintf(line,"-status_history_max %d\n",xorriso->status_history_max);
3624  Xorriso_status_result(xorriso,filter,fp,flag&2);
3625  }
3626 
3627 #ifdef Xorriso_with_line_editoR
3628 
3629  if((flag & 8) && xorriso->status_history_max > 0 && !xorriso->use_stdin)
3630  Xorriso_status_history(xorriso, filter, fp, flag & 2);
3631 
3632 #endif /* Xorriso_with_line_editoR */
3633 
3634  is_default= (xorriso->toc_emulation_flag == 0);
3635  sprintf(line,"-rom_toc_scan %s:%s:%s\n",
3636  xorriso->toc_emulation_flag & 4 ? "force" :
3637  xorriso->toc_emulation_flag & 1 ? "on" : "off",
3638  xorriso->toc_emulation_flag & 2 ? "emul_off" : "emul_on",
3639  xorriso->toc_emulation_flag & 8 ? "emul_wide" : "emul_narrow");
3640  if(!(is_default && no_defaults))
3641  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3642 
3643  is_default= (xorriso->displacement == 0);
3644  sprintf(line, "-displacement %s%lu\n",
3645  xorriso->displacement_sign < 0 ? "-" : "",
3646  (unsigned long) xorriso->displacement);
3647  if(!(is_default && no_defaults))
3648  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3649 
3650  adr_mode= xorriso->image_start_mode & 0xffff;
3651  if(adr_mode>=0 && adr_mode<=max_load_mode) {
3652  is_default= (adr_mode==0);
3653  sprintf(line,"-load %s ", load_names[adr_mode]);
3654  if(adr_mode==0)
3655  sprintf(line+strlen(line),"''\n");
3656  else if(adr_mode>=1 && adr_mode<=3)
3657  sprintf(line+strlen(line),"%s\n", xorriso->image_start_value);
3658  else
3659  sprintf(line+strlen(line),"%s\n",
3660  Text_shellsafe(xorriso->image_start_value, sfe, 0));
3661  if(!(is_default && no_defaults))
3662  Xorriso_status_result(xorriso,filter,fp,flag&2);
3663  }
3664 
3665  is_default= (xorriso->read_fs == 0);
3666  sprintf(line, "-read_fs %s\n",
3667  xorriso->read_fs == 0 ? "any" :
3668  xorriso->read_fs == 1 ? "norock" :
3669  xorriso->read_fs == 2 ? "nojoliet" : "ecma119");
3670  if(!(is_default && no_defaults))
3671  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3672 
3673  is_default= (xorriso->do_calm_drive & 1);
3674  sprintf(line,"-calm_drive %s\n", xorriso->do_calm_drive & 1 ? "on" : "off");
3675  if(!(is_default && no_defaults))
3676  Xorriso_status_result(xorriso,filter,fp,flag&2);
3677 
3678  is_default= (xorriso->grow_blindly_msc2<0);
3679  sprintf(sfe, "%d", xorriso->grow_blindly_msc2);
3680  sprintf(line,"-grow_blindly %s\n",
3681  xorriso->grow_blindly_msc2 < 0 ? "off" : sfe);
3682  if(!(is_default && no_defaults))
3683  Xorriso_status_result(xorriso,filter,fp,flag&2);
3684 
3685  Xorriso_get_local_charset(xorriso, &local_charset, 0);
3686  nl_charset= nl_langinfo(CODESET);
3687  is_default= (strcmp(local_charset, nl_charset) == 0);
3688  sprintf(line, "-local_charset %s\n", Text_shellsafe(local_charset, sfe, 0));
3689  if(!(is_default && no_defaults))
3690  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3691 
3692  is_default= (xorriso->out_charset == NULL && xorriso->in_charset == NULL);
3693  in_pt= "";
3694  if(xorriso->in_charset != NULL)
3695  in_pt= xorriso->in_charset;
3696  out_pt= "";
3697  if(xorriso->out_charset != NULL)
3698  out_pt= xorriso->out_charset;
3699  do_single= 0;
3700  ret= Xorriso_status_filter(xorriso, filter, "-in_charset", 0);
3701  if(ret <= 0)
3702  ret= Xorriso_status_filter(xorriso, filter, "-out_charset", 0);
3703  if(ret > 0)
3704  do_single= 1;
3705  if(strcmp(in_pt, out_pt) == 0 && !do_single) {
3706  sprintf(line, "-charset %s\n", Text_shellsafe(in_pt, sfe, 0));
3707  if(!(is_default && no_defaults))
3708  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3709  } else {
3710  sprintf(line, "-in_charset %s\n", Text_shellsafe(in_pt, sfe, 0));
3711  if(!(is_default && no_defaults))
3712  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3713  sprintf(line, "-out_charset %s\n", Text_shellsafe(out_pt, sfe, 0));
3714  if(!(is_default && no_defaults))
3715  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3716  }
3717  is_default= ((xorriso->do_aaip & (256 | 512)) == 0);
3718  sprintf(line,"-auto_charset %s\n", (xorriso->do_aaip & 256 ? "on" : "off"));
3719  if(!(is_default && no_defaults))
3720  Xorriso_status_result(xorriso,filter,fp,flag&2);
3721 
3722  is_default= ((xorriso->ino_behavior & 31) == 7);
3723  switch (xorriso->ino_behavior & 15) {
3724  case 0: form= "on";
3725  break; case 8: form= "without_update";
3726  break; default: form= "off";
3727  }
3728  sprintf(line,"-hardlinks %s:%s:%s\n", form,
3729  xorriso->ino_behavior & 32 ?
3730  "no_lsl_count" : "lsl_count",
3731  xorriso->ino_behavior & 16 ?
3732  "cheap_sorted_extract" : "normal_extract");
3733  if(!(is_default && no_defaults))
3734  Xorriso_status_result(xorriso,filter,fp,flag&2);
3735 
3736  is_default= ((xorriso->do_aaip & (1 | 4)) == 0);
3737  sprintf(line,"-acl %s\n", (xorriso->do_aaip & 1 ? "on" : "off"));
3738  if(!(is_default && no_defaults))
3739  Xorriso_status_result(xorriso,filter,fp,flag&2);
3740  is_default= ((xorriso->do_aaip & (2 | 8)) == 0);
3741  sprintf(line,"-xattr %s\n", (xorriso->do_aaip & 4 ?
3742  xorriso->do_aaip & 1024 ? "any" : "user"
3743  : "off"));
3744  if(!(is_default && no_defaults))
3745  Xorriso_status_result(xorriso,filter,fp,flag&2);
3746  is_default= ((xorriso->do_aaip & (16 | 32 | 64)) == 0);
3747  sprintf(line,"-disk_dev_ino %s\n",
3748  (xorriso->do_aaip & 16 ? (xorriso->do_aaip & 128 ? "ino_only" : "on" )
3749  : "off"));
3750  if(!(is_default && no_defaults))
3751  Xorriso_status_result(xorriso,filter,fp,flag&2);
3752 
3753  is_default= ((xorriso->do_md5 & 31) == 0);
3754  sprintf(line, "-md5 ");
3755  if(xorriso->do_md5 & 1) {
3756  if((xorriso->do_md5 & 8) == 8) {
3757  strcat(line, "all");
3758  } else {
3759  strcat(line, "on");
3760  if(xorriso->do_md5 & 8)
3761  strcat(line, ":stability_check_on");
3762  }
3763  if(xorriso->do_md5 & 32)
3764  strcat(line, ":load_check_off");
3765  strcat(line, "\n");
3766  } else
3767  strcat(line, "off\n");
3768  if(!(is_default && no_defaults))
3769  Xorriso_status_result(xorriso,filter,fp,flag&2);
3770 
3771  is_default= (xorriso->ecma119_map == 1);
3772  sprintf(line, "-ecma119_map ");
3773  if(xorriso->ecma119_map == 0)
3774  strcat(line, "unmapped\n");
3775  else if(xorriso->ecma119_map == 2)
3776  strcat(line, "uppercase\n");
3777  else if(xorriso->ecma119_map == 3)
3778  strcat(line, "lowercase\n");
3779  else
3780  strcat(line, "stripped\n");
3781  if(!(is_default && no_defaults))
3782  Xorriso_status_result(xorriso,filter,fp,flag&2);
3783 
3784  is_default= (xorriso->joliet_map == 1);
3785  sprintf(line, "-joliet_map ");
3786  if(xorriso->joliet_map == 0)
3787  strcat(line, "unmapped\n");
3788  else
3789  strcat(line, "stripped\n");
3790  if(!(is_default && no_defaults))
3791  Xorriso_status_result(xorriso,filter,fp,flag&2);
3792 
3793  is_default= (xorriso->scdbackup_tag_name[0] == 0 &&
3794  xorriso->scdbackup_tag_listname[0] == 0);
3795  sprintf(line, "-scdbackup_tag ");
3796  Text_shellsafe(xorriso->scdbackup_tag_listname, line, 1);
3797  strcat(line, " ");
3798  Text_shellsafe(xorriso->scdbackup_tag_name, line, 1);
3799  strcat(line, "\n");
3800  if(!(is_default && no_defaults))
3801  Xorriso_status_result(xorriso,filter,fp,flag&2);
3802 
3803  is_default= (Xorriso_get_relax_text(xorriso, sfe, 0) == 2);
3804  sprintf(line,"-compliance %s\n", sfe);
3805  if(!(is_default && no_defaults))
3806  Xorriso_status_result(xorriso,filter,fp,flag&2);
3807 
3808  is_default= (xorriso->rr_reloc_dir[0] == 0);
3809  sprintf(line, "-rr_reloc_dir ");
3810  Text_shellsafe(xorriso->rr_reloc_dir, line, 1);
3811  strcat(line, "\n");
3812  if(!(is_default && no_defaults))
3813  Xorriso_status_result(xorriso,filter,fp,flag&2);
3814 
3815  is_default= (xorriso->assert_volid[0] == 0);
3816  sprintf(line, "-assert_volid ");
3817  Text_shellsafe(xorriso->assert_volid, line, 1);
3818  strcat(line, " ");
3819  Text_shellsafe(xorriso->assert_volid_sev, line, 1);
3820  strcat(line, "\n");
3821  if(!(is_default && no_defaults))
3822  Xorriso_status_result(xorriso,filter,fp,flag&2);
3823 
3824  is_default= 1;
3825  if(xorriso->drive_blacklist != NULL || xorriso->drive_whitelist != NULL ||
3826  xorriso->drive_greylist == NULL)
3827  is_default= 0;
3828  if(xorriso->drive_greylist != NULL) {
3829  if(strcmp(Xorriso_get_pattern(xorriso, xorriso->drive_greylist, 0, 0),
3830  "/dev") != 0)
3831  is_default= 0;
3832  if(Xorriso_get_pattern(xorriso, xorriso->drive_greylist, 1, 0) != NULL)
3833  is_default= 0;
3834  }
3835  if(!(is_default && no_defaults)) {
3836  for(s= xorriso->drive_blacklist; s != NULL; s= Xorriso_lst_get_next(s, 0)) {
3837  sprintf(line, "-drive_class 'banned' %s\n",
3838  Text_shellsafe(Xorriso_lst_get_text(s, 0), sfe, 0));
3839  Xorriso_status_result(xorriso,filter,fp,flag&2);
3840  }
3841  for(s= xorriso->drive_greylist; s != NULL; s= Xorriso_lst_get_next(s, 0)) {
3842  sprintf(line, "-drive_class 'caution' %s\n",
3843  Text_shellsafe(Xorriso_lst_get_text(s, 0), sfe, 0));
3844  Xorriso_status_result(xorriso,filter,fp,flag&2);
3845  }
3846  for(s= xorriso->drive_whitelist; s != NULL; s= Xorriso_lst_get_next(s, 0)) {
3847  sprintf(line, "-drive_class 'harmless' %s\n",
3848  Text_shellsafe(Xorriso_lst_get_text(s, 0), sfe, 0));
3849  Xorriso_status_result(xorriso,filter,fp,flag&2);
3850  }
3851  }
3852 
3853  is_default= (xorriso->drives_exclusive == 1 && xorriso->drives_access == 1);
3854  sprintf(line, "-drive_access %s:%s\n",
3855  xorriso->drives_exclusive ? "exclusive" : "shared",
3856  xorriso->drives_access == 0 ? "readonly" : "unrestricted");
3857  if(!(is_default && no_defaults))
3858  Xorriso_status_result(xorriso, filter, fp, flag & 2);
3859 
3860  is_default= (xorriso->linux_scsi_dev_family == 0);
3861  sprintf(line, "-scsi_dev_family %s\n",
3862  scsi_family[xorriso->linux_scsi_dev_family & 7]);
3863  if(!(is_default && no_defaults))
3864  Xorriso_status_result(xorriso,filter,fp,flag&2);
3865 
3866  do_single= do_drive_access= 0;
3867  dev_filter= filter;
3868  if(dev_filter != NULL) {
3869  show_dev= Xorriso_status_filter(xorriso, filter, "-dev", 0);
3870  if(show_dev > 0)
3871  dev_filter= NULL;
3872  }
3873  if(dev_filter != NULL) {
3874  show_indev= Xorriso_status_filter(xorriso, filter, "-indev", 0);
3875  show_outdev= Xorriso_status_filter(xorriso, filter, "-outdev", 0);
3876  if(show_outdev > 0 || show_indev > 0)
3877  do_single= 1;
3878  }
3879  if((xorriso->drives_exclusive != xorriso->indev_is_exclusive ||
3880  xorriso->drives_access != xorriso->indev_access) && xorriso->indev[0]) {
3881  do_single= 1;
3882  do_drive_access|= 1;
3883  }
3884  if((xorriso->drives_exclusive != xorriso->outdev_is_exclusive ||
3885  xorriso->drives_access != xorriso->outdev_access) &&
3886  xorriso->outdev[0]) {
3887  do_single= 1;
3888  do_drive_access|= 2;
3889  }
3890  if(strcmp(xorriso->indev, xorriso->outdev) == 0 && !do_single) {
3891  sprintf(line,"-dev %s\n", Text_shellsafe(xorriso->indev,sfe,0));
3892  Xorriso_status_result(xorriso, dev_filter, fp, flag & 2);
3893  } else {
3894  did_drive_access= 0;
3895  if((do_drive_access & 1) && xorriso->indev[0] && show_indev) {
3896  sprintf(line,"-drive_access %s:%s\n",
3897  xorriso->indev_is_exclusive ? "exclusive" : "shared",
3898  xorriso->indev_access == 0 ? "readonly" : "unrestricted");
3899  Xorriso_status_result(xorriso, NULL, fp, flag & 2);
3900  did_drive_access= 1;
3901  }
3902  sprintf(line,"-indev %s\n", Text_shellsafe(xorriso->indev,sfe,0));
3903  Xorriso_status_result(xorriso, dev_filter, fp, flag & 2);
3904  if(did_drive_access) {
3905  sprintf(line,"-drive_access %s:%s\n",
3906  xorriso->drives_exclusive ? "exclusive" : "shared",
3907  xorriso->drives_access == 0 ? "readonly" : "unrestricted");
3908  Xorriso_status_result(xorriso, NULL, fp, flag & 2);
3909  }
3910 
3911  did_drive_access= 0;
3912  if((do_drive_access & 2) && xorriso->outdev[0] && show_outdev) {
3913  sprintf(line,"-drive_access %s:%s\n",
3914  xorriso->outdev_is_exclusive ? "exclusive" : "shared",
3915  xorriso->outdev_access == 0 ? "readonly" : "unrestricted");
3916  Xorriso_status_result(xorriso, NULL, fp, flag & 2);
3917  did_drive_access= 1;
3918  }
3919  sprintf(line,"-outdev %s\n", Text_shellsafe(xorriso->outdev,sfe,0));
3920  Xorriso_status_result(xorriso, dev_filter, fp, flag & 2);
3921  if(did_drive_access) {
3922  sprintf(line,"-drive_access %s:%s\n",
3923  xorriso->drives_exclusive ? "exclusive" : "shared",
3924  xorriso->drives_access == 0 ? "readonly" : "unrestricted");
3925  Xorriso_status_result(xorriso, NULL, fp, flag & 2);
3926  }
3927  }
3928 
3929  ret= 1;
3930 ex:;
3931  Xorriso_free_meM(sfe);
3932  Xorriso_free_meM(xorriso_id);
3933  return(ret);
3934 }
3935 
3936 
3937 int Xorriso_pacifier_reset(struct XorrisO *xorriso, int flag)
3938 {
3939  xorriso->start_time= Sfile_microtime(0);
3940  xorriso->last_update_time= xorriso->start_time;
3941  xorriso->pacifier_count= 0;
3942  xorriso->pacifier_prev_count= 0;
3943  xorriso->pacifier_total= 0;
3944  xorriso->pacifier_byte_count= 0;
3945  return(1);
3946 }
3947 
3948 
3949 /* This call is to be issued by long running workers in short intervals.
3950  It will check whether enough time has elapsed since the last pacifier
3951  message and eventually issue an update message.
3952  @param what_done A sparse description of the action, preferably in past
3953  tense. E.g. "done" , "files added".
3954  @param count The number of objects processed so far.
3955  Is ignored if <=0.
3956  @param todo The number of objects to be done in total.
3957  Is ignored if <=0.
3958  @param current_object A string telling the object currently processed.
3959  Ignored if "".
3960  @param flag bit0= report unconditionally, no time check
3961  bit1= report count <=0 (no thank you for being patient then)
3962  bit2= report xorriso->pacifier_byte_count
3963  bit3= report speed
3964  bit4= with bit3: count is in blocks, else in bytes
3965  bit5= with bit3: report total speed
3966  bit6= report with carriage return rather than line feed
3967  bit7= with bit5: speed unit for outdev rather than indev
3968 */
3969 int Xorriso_pacifier_callback(struct XorrisO *xorriso, char *what_done,
3970  off_t count, off_t todo, char *current_object,
3971  int flag)
3972 {
3973  double current_time, since, interval_time, speed, speed_factor;
3974  char count_text[80], byte_text[80], profile_name[80], *speed_unit;
3975  int ret, profile_number, short_sec;
3976  off_t amount;
3977 
3978  current_time= Sfile_microtime(0);
3979  interval_time= current_time - xorriso->last_update_time;
3980  if(interval_time < xorriso->pacifier_interval
3981  && !(flag&1))
3982  return(1);
3983  xorriso->last_update_time= Sfile_microtime(0);
3984  since= current_time - xorriso->start_time;
3985  if((flag & 1) && since < 1.0 && xorriso->pacifier_interval >= 1.0)
3986  since= 1.0;
3987  if((flag & 1) && since < 0.1)
3988  since= 0.1;
3989  byte_text[0]= 0;
3990  if(flag&4) {
3991  strcat(byte_text, " (");
3992  Sfile_scale((double) xorriso->pacifier_byte_count,
3993  byte_text+strlen(byte_text), 7, 1e5, 0);
3994  strcat(byte_text, ")");
3995  }
3996  short_sec= 0;
3997  if(count<=0.0 && !(flag&2)) {
3998  if(since < 2)
3999  return(2);
4000  sprintf(xorriso->info_text,
4001  "Thank you for being patient for");
4002  } else if(todo<=0.0) {
4003  if(count<10000000)
4004  sprintf(count_text, "%7.f", (double) count);
4005  else
4006  Sfile_scale((double) count, count_text, 7, 1e5, 1);
4007  sprintf(xorriso->info_text, "%s %s%s in",
4008  count_text, what_done, byte_text);
4009  short_sec= (flag & 64);
4010  } else {
4011  sprintf(xorriso->info_text, "%.f of %.f %s%s in",
4012  (double) count, (double) todo, what_done, byte_text);
4013  short_sec= (flag & (8 | 64));
4014  }
4015  if(xorriso->pacifier_interval < 1.0) {
4016  sprintf(xorriso->info_text + strlen(xorriso->info_text),
4017  " %.1f", since);
4018  } else {
4019  sprintf(xorriso->info_text + strlen(xorriso->info_text),
4020  " %.f", since);
4021  }
4022  sprintf(xorriso->info_text + strlen(xorriso->info_text),
4023  " %s", short_sec ? "s" : "seconds");
4024 
4025  speed= -1.0;
4026  if(flag & 4)
4027  amount= xorriso->pacifier_byte_count;
4028  else
4029  amount= count;
4030  if((flag & 8)) {
4031  if(flag & 32) {
4032  if(since > 0)
4033  speed= amount / since;
4034  } else if(amount >= xorriso->pacifier_prev_count) {
4035  if(interval_time > 0)
4036  speed= (amount - xorriso->pacifier_prev_count) / interval_time;
4037  }
4038  }
4039  if(speed >= 0.0) {
4040  if(flag & 16)
4041  speed*= 2048.0;
4042  ret= Xorriso_get_profile(xorriso, &profile_number, profile_name,
4043  (flag >> 6) & 2);
4044  speed_factor= 1385000;
4045  speed_unit= "D";
4046  if(ret == 2) {
4047  speed_factor= 150.0*1024;
4048  speed_unit= "C";
4049  } else if(ret == 3) {
4050  speed_factor= 4495625;
4051  speed_unit= "B";
4052  }
4053  sprintf(xorriso->info_text+strlen(xorriso->info_text), " %s %.1fx%s",
4054  (flag & 32 ? "=" : ","), speed / speed_factor, speed_unit);
4055  }
4056  xorriso->pacifier_prev_count= amount;
4057  if(current_object[0]!=0)
4058  sprintf(xorriso->info_text+strlen(xorriso->info_text),
4059  ", now at %s", current_object);
4060  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", (flag&64));
4061  return(1);
4062 }
4063 
4064 
4065 int Xorriso_reset_counters(struct XorrisO *xorriso, int flag)
4066 {
4067  xorriso->error_count= 0;
4068  xorriso->insert_count= 0;
4069  xorriso->insert_bytes= 0;
4070  Xorriso_pacifier_reset(xorriso, 0);
4071  return(1);
4072 }
4073 
4074 
4075 /* @param flag bit0= to stderr rather than Xorriso_msgs_submit
4076 */
4077 int Xorriso_no_malloc_memory(struct XorrisO *xorriso, char **to_free, int flag)
4078 {
4079  if(to_free!=NULL)
4080  if(*to_free!=NULL) {
4081  /* Eventual memory sacrifice to get on going */
4082  free(*to_free);
4083  *to_free= NULL;
4084  }
4085  sprintf(xorriso->info_text, "Out of virtual memory");
4086  if(flag & 1) {
4087  fprintf(stderr, "%s", xorriso->info_text);
4088  /* (No need to first check for problem status worse than ABORT) */
4089  Xorriso_set_problem_status(xorriso, "ABORT", 0);
4090  } else
4091  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "ABORT", 0);
4092  return(1);
4093 }
4094 
4095 
4096 /* @param flag bit0=path is in source filesystem , bit1= unconditionally */
4097 int Xorriso_much_too_long(struct XorrisO *xorriso, int len, int flag)
4098 {
4099  if(len>=SfileadrL || (flag&2)) {
4100  sprintf(xorriso->info_text,
4101  "Path given for file in %s is much too long (%d)",
4102  ((flag&1) ? "local filesystem" : "ISO image"), len);
4103  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
4104  return(0);
4105  }
4106  return(1);
4107 }
4108 
4109 
4110 int Xorriso_no_findjob(struct XorrisO *xorriso, char *cmd, int flag)
4111 {
4112  sprintf(xorriso->info_text, "%s: cannot create find job object", cmd);
4113  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
4114  return(1);
4115 }
4116 
4117 
4118 int Xorriso_report_md5_outcome(struct XorrisO *xorriso, char *severity,
4119  int flag)
4120 {
4121  int has_md5;
4122 
4123  has_md5= Xorriso_image_has_md5(xorriso, 0);
4124  if(xorriso->find_check_md5_result & 1) {
4125  sprintf(xorriso->result_line,
4126  "Mismatch detected between file contents and MD5 checksums.\n");
4127  } else if(xorriso->find_check_md5_result & 8) {
4128  sprintf(xorriso->result_line,
4129  "File contents and their MD5 checksums match.\n");
4130  } else {
4131  sprintf(xorriso->result_line,
4132  "Not a single file with MD5 checksum was found.");
4133  if(has_md5 <= 0)
4134  strcat(xorriso->result_line,
4135  " (There is no MD5 checksum array loaded.)\n");
4136  else
4137  strcat(xorriso->result_line, "\n");
4138  }
4139  Xorriso_result(xorriso,0);
4140  if(xorriso->find_check_md5_result & 2) {
4141  sprintf(xorriso->result_line,
4142  "Encountered errors other than non-match during MD5 checking.\n");
4143  Xorriso_result(xorriso,0);
4144  }
4145  if((xorriso->find_check_md5_result & 4) && has_md5) {
4146  sprintf(xorriso->result_line,
4147  "There were data files which have no MD5 and thus could not be checked.\n");
4148  Xorriso_result(xorriso,0);
4149  }
4150  if((xorriso->find_check_md5_result & 3) && strcmp(severity, "ALL") != 0) {
4151  sprintf(xorriso->info_text, "Event triggered by MD5 comparison mismatch");
4152  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, severity, 0);
4153  }
4154  return(1);
4155 }
4156 
4157 
4158 /* @param flag bit0= do not issue prompt messages on info channel
4159  bit1= use line rather than asking at dialog input
4160 */
4161 int Xorriso_msg_op_parse(struct XorrisO *xorriso, char *line,
4162  char *prefix, char *separators,
4163  int max_words, int pflag, int input_lines,
4164  int flag)
4165 {
4166  int ret, i, l, pargc= 0, bsl_mem;
4167  char *pline= NULL, **pargv= NULL, *parse_line, *text= NULL, *text_pt;
4168 
4169  Xorriso_alloc_meM(pline, char, SfileadrL);
4170 
4171  if(!(flag & 1)) {
4172  if(input_lines > 1)
4173  sprintf(xorriso->info_text, "-msg_op parse: Enter %d lines of text\n",
4174  input_lines);
4175  else
4176  sprintf(xorriso->info_text, "-msg_op parse: Enter text line\n");
4177  Xorriso_info(xorriso, 0);
4178  }
4179 
4180  if(flag & 2) {
4181  parse_line= line;
4182  } else {
4183  pline[0]= 0;
4184  for(i= 0; i < input_lines; i++) {
4185  l= strlen(pline);
4186  ret= Xorriso_dialog_input(xorriso, pline + l, SfileadrL - l - 1, 8 | 1);
4187  if(ret <= 0)
4188  goto ex;
4189  if(i < input_lines - 1)
4190  strcat(pline, "\n");
4191  }
4192  parse_line= pline;
4193  }
4194  ret= Xorriso_parse_line(xorriso, parse_line, prefix, separators, max_words,
4195  &pargc, &pargv, pflag);
4196 
4197  /* Temporarily disable backslash encoding of result channel */
4198  bsl_mem= xorriso->bsl_interpretation;
4199  xorriso->bsl_interpretation&= ~32;
4200 
4201  xorriso->msg_sieve_disabled= 1;
4202  sprintf(xorriso->result_line, "%d\n", ret);
4203  Xorriso_result(xorriso, 1);
4204  if(ret == 1) {
4205  sprintf(xorriso->result_line, "%d\n", pargc);
4206  Xorriso_result(xorriso, 1);
4207  for(i= 0; i < pargc; i++) {
4208  text_pt= pargv[i];
4209  if (bsl_mem & 32) {
4210  ret= Sfile_bsl_encoder(&text, pargv[i], strlen(pargv[i]), 4);
4211  if(ret > 0)
4212  text_pt= text;
4213  }
4214  ret= Sfile_count_char(text_pt, '\n') + 1;
4215  sprintf(xorriso->result_line, "%d\n", ret);
4216  Xorriso_result(xorriso, 1);
4217  Sfile_str(xorriso->result_line, text_pt, 0);
4218  strcat(xorriso->result_line, "\n");
4219  Xorriso_result(xorriso, 1);
4221  text= NULL;
4222  }
4223  } else {
4224  sprintf(xorriso->result_line, "0\n");
4225  Xorriso_result(xorriso, 1);
4226  }
4227  xorriso->bsl_interpretation= bsl_mem;
4228  ret= 1;
4229 ex:;
4230  Xorriso__dispose_words(&pargc, &pargv);
4232  Xorriso_free_meM(pline);
4233  return ret;
4234 }
4235 
4236 
4237 /* @param flag bit0= do not issue prompt messages on info channel
4238 */
4240  char *prefix, char *separators,
4241  int max_words, int pflag, int bulk_lines,
4242  int flag)
4243 {
4244  int ret, input_lines, i, j, l;
4245  char line[80];
4246  struct Xorriso_lsT *input_list= NULL, *input_end= NULL, *new_lst, *lst;
4247  char *pline= NULL;
4248 
4249  if(!(flag & 1)) {
4250  sprintf(xorriso->info_text,
4251  "Enter %d groups of lines. Each group begins by a line which tells the\n",
4252  bulk_lines);
4253  Xorriso_info(xorriso, 0);
4254  sprintf(xorriso->info_text,
4255  "number of following lines in the group. Then come the announced lines\n");
4256  Xorriso_info(xorriso, 0);
4257  sprintf(xorriso->info_text,
4258  "Do this blindly. No further prompt will appear. Best be a computer.\n");
4259  Xorriso_info(xorriso, 0);
4260  }
4261 
4262  Xorriso_alloc_meM(pline, char, SfileadrL);
4263 
4264  for(i= 0; i < bulk_lines; i++) {
4265  ret= Xorriso_dialog_input(xorriso, line, sizeof(line), 8 | 1);
4266  if(ret <= 0)
4267  goto ex;
4268  input_lines= -1;
4269  sscanf(line, "%d", &input_lines);
4270  pline[0]= 0;
4271  for(j= 0; j < input_lines; j++) {
4272  l= strlen(pline);
4273  ret= Xorriso_dialog_input(xorriso, pline + l, SfileadrL - l - 1, 8 | 1);
4274  if(ret <= 0)
4275  goto ex;
4276  if(j < input_lines - 1)
4277  strcat(pline, "\n");
4278  }
4279  ret= Xorriso_lst_new(&new_lst, pline, input_end, 0);
4280  if(ret <= 0)
4281  goto ex;
4282  if(input_list == NULL)
4283  input_list= new_lst;
4284  input_end= new_lst;
4285  }
4286 
4287  for(lst= input_list; lst != NULL; lst= Xorriso_lst_get_next(lst, 0)) {
4288  ret= Xorriso_msg_op_parse(xorriso, Xorriso_lst_get_text(lst, 0),
4289  prefix, separators, max_words, pflag,
4290  input_lines, 1 | 2);
4291  if(ret <= 0)
4292  goto ex;
4293  }
4294 
4295  ret= 1;
4296 ex:;
4297  Xorriso_lst_destroy_all(&input_list, 0);
4298  Xorriso_free_meM(pline);
4299  return(1);
4300 }
4301 
4302 
4303 int Xorriso_launch_frontend(struct XorrisO *xorriso, int argc, char **argv,
4304  char *cmd_pipe_adr, char *reply_pipe_adr, int flag)
4305 {
4306  int command_pipe[2], reply_pipe[2], ret, i, cpid, is_banned= 0;
4307  char **exec_argv= NULL, *sfe= NULL, *adrpt;
4308  struct stat stbuf;
4309 
4310  Xorriso_alloc_meM(sfe, char, 5 * SfileadrL);
4311  for(i= 0; i < 2; i++)
4312  command_pipe[i]= reply_pipe[i]= -1;
4313 
4314 #ifndef Xorriso_allow_launch_frontenD
4315  /* To be controlled by: configure --enable-external-filters */
4316 
4317  sprintf(xorriso->info_text, "-launch_frontend : Banned at compile time.");
4318  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
4319  sprintf(xorriso->info_text,
4320 "This may be changed at compile time by ./configure option --enable-external-filters");
4321  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "HINT", 0);
4322  is_banned= 1;
4323 
4324 #endif /* ! Xorriso_allow_launch_frontenD */
4325 
4326 #ifndef Xorriso_allow_launch_frontend_suiD
4327 
4328  /* To be controlled by: configure --enable-external-filters-setuid */
4329 
4330  if(getuid() != geteuid()) {
4331  sprintf(xorriso->info_text,
4332  "-set_filter: UID and EUID differ. Will not run external programs.");
4333  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
4334  sprintf(xorriso->info_text,
4335 "This may be changed at compile time by ./configure option --enable-external-filters-setuid");
4336  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "HINT", 0);
4337  is_banned= 1;
4338  }
4339 
4340 #endif /* ! Xorriso_allow_launch_frontend_suiD */
4341 
4342  if(is_banned)
4343  {ret= 0; goto ex;}
4344 
4345  if(argc > 0) {
4346  if(strchr(argv[0], '/') == NULL) {
4347  sprintf(xorriso->info_text,
4348  "-launch_frontend : Command path does not contain a '/'-character");
4349  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
4350  {ret= 0; goto ex;}
4351  }
4352 
4353  /* Add a NULL pointer for execv() */
4354  Xorriso_alloc_meM(exec_argv, char *, argc + 1);
4355  for(i= 0; i < argc; i++)
4356  exec_argv[i]= argv[i];
4357  exec_argv[argc]= NULL;
4358  } else if(cmd_pipe_adr[0] == 0 || reply_pipe_adr[0] == 0)
4359  {ret= 0; goto ex;}
4360 
4361  if(cmd_pipe_adr[0] && reply_pipe_adr[0]) {
4362  /* Create named pipes if needed */
4363  for(i= 0; i < 2; i++) {
4364  if(i == 0)
4365  adrpt= cmd_pipe_adr;
4366  else
4367  adrpt= reply_pipe_adr;
4368  ret= stat(adrpt, &stbuf);
4369  if(ret == -1) {
4370  ret= mknod(adrpt, S_IFIFO | S_IRWXU | S_IRWXG | S_IRWXO | S_IRWXO,
4371  (dev_t) 0);
4372  if(ret == -1) {
4373  sprintf(xorriso->info_text,
4374  "-launch_frontend: Cannot create named pipe %s",
4375  Text_shellsafe(adrpt, sfe, 0));
4376  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno,
4377  "FAILURE", 0);
4378  ret= 0; goto ex;
4379  }
4380  }
4381  }
4382  } else {
4383  ret= pipe(command_pipe);
4384  if (ret == -1) {
4385 no_pipe_open:
4386  sprintf(xorriso->info_text,
4387  "-launch_frontend: Failed to create a nameless pipe object");
4388  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
4389  ret= 0; goto ex;
4390  }
4391  ret= pipe(reply_pipe);
4392  if (ret == -1)
4393  goto no_pipe_open;
4394  }
4395 
4396  if(argc > 0) {
4397  cpid = fork();
4398  if (cpid == -1) {
4399  sprintf(xorriso->info_text,
4400  "-launch_frontend: Failed to create a child process");
4401  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
4402  ret= 0; goto ex;
4403  }
4404  } else
4405  cpid= -1; /* Dummy child id */
4406 
4407  if (cpid != 0) {
4408  /* Parent becomes the xorriso slave */
4409 
4410  xorriso->use_stdin= 1;
4411  if(cmd_pipe_adr[0] && reply_pipe_adr[0]) {
4412  command_pipe[0]= open(cmd_pipe_adr, O_RDONLY | O_BINARY);
4413  if(command_pipe[0] == -1) {
4414  sprintf(xorriso->info_text,
4415  "-launch_frontend: Failed to open named command pipe %s",
4416  Text_shellsafe(cmd_pipe_adr, sfe, 0));
4417  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno,
4418  "FAILURE", 0);
4419  ret= 0; goto ex;
4420  }
4421  reply_pipe[1]= open(reply_pipe_adr, O_WRONLY | O_APPEND | O_BINARY);
4422  if(reply_pipe[1] == -1) {
4423  sprintf(xorriso->info_text,
4424  "-launch_frontend: Failed to open named reply pipe %s",
4425  Text_shellsafe(reply_pipe_adr, sfe, 0));
4426  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno,
4427  "FAILURE", 0);
4428  ret= 0; goto ex;
4429  }
4430  } else {
4431  /* Close unused pipe ends */
4432  close(command_pipe[1]);
4433  close(reply_pipe[0]);
4434  }
4435  close(0);
4436  close(1);
4437  close(2);
4438  ret= dup2(command_pipe[0], 0);
4439  if(ret == -1) {
4440 no_dup:;
4441  sprintf(xorriso->info_text,
4442  "-launch_frontend: Failed to connect pipe to xorriso standard i/o channels");
4443  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
4444  ret= -1; goto ex;
4445  }
4446  ret= dup2(reply_pipe[1], 1);
4447  if(ret == -1)
4448  goto no_dup;
4449  ret= dup2(reply_pipe[1], 2);
4450  if(ret == -1)
4451  goto no_dup;
4452  ret= 1; goto ex;
4453  }
4454 
4455  /* Child becomes the frontend program */
4456 
4457  /* Close unused pipe ends */;
4458  if(cmd_pipe_adr[0] && reply_pipe_adr[0]) {
4459  command_pipe[1]= open(cmd_pipe_adr, O_WRONLY | O_APPEND | O_BINARY);
4460  if(command_pipe[1] == -1) {
4461  fprintf(stderr,
4462  "xorriso: -launch_frontend: Failed to open named command pipe '%s'\n",
4463  cmd_pipe_adr);
4464  perror("xorriso: -launch_frontend");
4465  exit(1);
4466  }
4467  reply_pipe[0]= open(reply_pipe_adr, O_RDONLY | O_BINARY);
4468  if(reply_pipe[0] == -1) {
4469  fprintf(stderr,
4470  "xorriso: -launch_frontend: Failed to open named reply pipe '%s'\n",
4471  reply_pipe_adr);
4472  exit(1);
4473  }
4474  } else {
4475  close(command_pipe[0]);
4476  close(reply_pipe[1]);
4477  }
4478  close(0);
4479  close(1);
4480  ret= dup2(command_pipe[1], 1);
4481  if(ret == -1) {
4482  perror("xorriso: -launch_frontend: Error on redirecting standard output for frontend");
4483  exit(1);
4484  }
4485  ret= dup2(reply_pipe[0], 0);
4486  if(ret == -1) {
4487  perror("xorriso: -launch_frontend: Error on redirecting standard input for frontend");
4488  exit(1);
4489  }
4490 
4491  execv(exec_argv[0], exec_argv);
4492  fprintf(stderr, "xorriso: -launch_frontend: Failure to start program '%s'\n",
4493  exec_argv[0]);
4494  perror("xorriso: -launch_frontend");
4495  exit(1);
4496 
4497 ex:;
4498  Xorriso_free_meM(exec_argv);
4499  Xorriso_free_meM(sfe);
4500  return(ret);
4501 }
4502 
4503 
4504 
4505 int Xorriso_open_named_pipe(struct XorrisO *xorriso, char fd_names[3][20],
4506  int mem_fds[], char *pipe_paths[], int pipe_fds[],
4507  int i, int flag)
4508 {
4509  if(mem_fds[i] == -1)
4510  return(2);
4511  pipe_fds[i]= open(pipe_paths[i], (i == 0 ? O_RDONLY : O_WRONLY) | O_BINARY);
4512  if(pipe_fds[i] == -1) {
4513  sprintf(xorriso->info_text,
4514  "-named_pipe_loop: Failed to open %s pipe ", fd_names[i]);
4515  Text_shellsafe(pipe_paths[i], xorriso->info_text, 1);
4516  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE",0);
4517  return(0);
4518  }
4519  close(i);
4520  dup2(pipe_fds[i], i);
4521  return(1);
4522 }
4523 
4524 
4525 /* Usage example via bash:
4526  in=/u/test/xorriso_stdin
4527  out=/u/test/xorriso_stdout
4528  mknod "$in" p
4529  mknod "$out" p
4530  xorriso -abort_on NEVER \
4531  -named_pipe_loop cleanup:buffered "$in" "$out" - &
4532 
4533  # Send command and receive result
4534  xorriso_cmd() {
4535  echo "$@" >/u/test/xorriso_stdin
4536  cat </u/test/xorriso_stdout
4537  }
4538  # Transport safety of filenames by wrapping in quotes and escaping quotes
4539  xorriso_esc() {
4540  echo -n "'"
4541  echo -n "$1" | sed -e "s/'/'"'"'"'"'"'"'/g"
4542  echo -n "'"
4543  }
4544  disk_path=...arbitrary.characters...
4545  iso_path=...arbitrary.characters...
4546  xorriso_cmd map $(xorriso_esc "$disk_path") $(xorriso_esc "$iso_path")
4547 */
4548 /* @param flag bit0= unlink pipes when the loop ends
4549  bit1= read all lines from pipe until EOF before executing them
4550 */
4551 int Xorriso_named_pipe_loop(struct XorrisO *xorriso,
4552  char *pipe_paths[3], int flag)
4553 {
4554  char *line= NULL;
4555  int i, ret, mem_fds[3], pipe_fds[3], first_line, hret, pipes_are_valid= 0;
4556  int lst_ret, filling_buffer= 0;
4557  off_t mem_used= 0, mem_needed;
4558  struct stat stbuf;
4559  struct Xorriso_lsT *prev_lst= NULL;
4560  static char fd_names[3][20] = {
4561  "standard input", "standard output", "standard error" };
4562  char mem_text[80], limit_text[80];
4563 
4564  for(i= 0; i < 3; i++ )
4565  mem_fds[i]= pipe_fds[i]= -1;
4566 
4567  if(xorriso->tolerate_stdin_eof) {
4568  sprintf(xorriso->info_text,
4569  "Already in -named_pipe_loop. Ignoring further -named_pipe_loop command.");
4570  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
4571  return(0); /* intentionally not goto ex */
4572  }
4573 
4574  Xorriso_alloc_meM(line, char, SfileadrL);
4575 
4576  /* Memorize stdin, stdout, and stderr. Close originals. */
4577  for(i= 0; i < 3; i++ ) {
4578  if(pipe_paths[i][0] == 0 || strcmp(pipe_paths[i], "-") == 0)
4579  continue;
4580  if(stat(pipe_paths[i], &stbuf) == -1) {
4581  sprintf(xorriso->info_text,
4582  "-named_pipe_loop: Cannot determine properties of file ");
4583  Text_shellsafe(pipe_paths[i], xorriso->info_text, 1);
4584  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
4585  ret= 0; goto ex;
4586  }
4587  if(!S_ISFIFO(stbuf.st_mode)) {
4588  sprintf(xorriso->info_text,
4589  "-named_pipe_loop: File is not a named pipe: ");
4590  Text_shellsafe(pipe_paths[i], xorriso->info_text, 1);
4591  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
4592  ret= 0; goto ex;
4593  }
4594  mem_fds[i]= dup(i);
4595  if(mem_fds[i] == -1) {
4596  sprintf(xorriso->info_text,
4597  "-named_pipe_loop: Cannot duplicate original %s", fd_names[i]);
4598  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
4599  ret= 0; goto ex;
4600  }
4601  }
4602  pipes_are_valid= 1;
4603 
4604  while(1) {
4605  /* Open input pipe */
4606  ret= Xorriso_open_named_pipe(xorriso, fd_names, mem_fds, pipe_paths,
4607  pipe_fds, 0, 0);
4608  if(ret <= 0)
4609  goto ex;
4610 
4611  /* As long as the input connection exists */
4612  xorriso->tolerate_stdin_eof= 1;
4613  first_line= 1;
4614  if(flag & 2) {
4615  filling_buffer= 8 | 16; /* single line, no reading from buffered_dialog */
4616  prev_lst= NULL;
4617  mem_used= 0;
4618  }
4619  while(1) {
4620  /* Fetch input line */
4621  if((flag & 2) && xorriso->buffered_dialog == NULL && !filling_buffer) {
4622  ret= -2; /* EOF */
4623  } else {
4624  ret= Xorriso_dialog_input(xorriso, line, SfileadrL, 1 | filling_buffer);
4625  }
4626  if((flag & 2) && filling_buffer) {
4627  /* Fetch and buffer lines before opening output pipes */
4628 
4629  if(ret > 0) {
4630 
4631  /* Check for excessive memory consumption */;
4632  mem_needed= strlen(line) + 8 + sizeof(struct Xorriso_lsT);
4633  if(mem_used + mem_needed > xorriso->temp_mem_limit) {
4634  Sfile_scale((double) (mem_used + mem_needed), mem_text, 5, 1e4, 0);
4635  Sfile_scale((double) xorriso->temp_mem_limit,
4636  limit_text, 5, 1e4, 0);
4637  sprintf(xorriso->info_text,
4638  "-named_pipe_loop: List of buffered input lines exceeds -temp_mem_limit (%s > %s)",
4639  mem_text, limit_text);
4640  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0,
4641  "FAILURE", 0);
4642  ret= -1; goto ex;
4643  }
4644  mem_used+= mem_needed;
4645 
4646  lst_ret= Xorriso_lst_new(&prev_lst, line, prev_lst, 0);
4647  if(lst_ret <= 0) {
4648  Xorriso_msgs_submit(xorriso, 0,
4649  "-named_pipe_loop: Cannot buffer all input lines", 0, "FATAL", 0);
4650  ret= -1; goto ex;
4651  } else {
4652  if(xorriso->buffered_dialog == NULL)
4653  xorriso->buffered_dialog= prev_lst;
4654  continue;
4655  }
4656  }
4657  filling_buffer= 0; /* start consuming buffer */
4658  continue;
4659  }
4660 
4661  /* Open output pipes late to allow the sender to open them after
4662  the first (and usually only) input line was transmitted:
4663  echo ... >stdin_pipe
4664  res=$(cat <stdout_pipe)
4665  This will work independently of the stdin_pipe buffer size.
4666  */
4667  if(first_line) {
4668  first_line= 0;
4669  for(i= 1; i < 3; i++) {
4670  hret= Xorriso_open_named_pipe(xorriso, fd_names, mem_fds, pipe_paths,
4671  pipe_fds, i, 0);
4672  if(hret <= 0 && ret > 0)
4673  {ret= hret; goto ex;}
4674  }
4675  }
4676 
4677  /* Now evaluate outcome of Xorriso_dialog_input() */
4678  if(ret == -2) /* EOF at stdin */
4679  break;
4680  if(ret <= 0) /* Other error */
4681  goto ex;
4682 
4683  /* Regular end of command */
4684  if(strcmp(line, "end_named_pipe_loop") == 0)
4685  {ret= 1; goto ex;}
4686 
4687  /* Perform xorriso command */
4688  ret= Xorriso_execute_option(xorriso, line, (1 << 16));
4689  if(ret <= 0)
4690  goto ex;
4691  if(ret == 3) /* e.g. -end command */
4692  goto ex;
4693  Xorriso_mark(xorriso,0);
4694  }
4695 
4696  /* Restore stdin, stdout and stderr */
4697  for(i= 0; i < 3; i++) {
4698  if(mem_fds[i] != -1) {
4699  if(pipe_fds[i] != -1)
4700  close(pipe_fds[i]);
4701  pipe_fds[i]= -1;
4702  close(i);
4703  dup2(mem_fds[i], i);
4704  }
4705  }
4706  }
4707 
4708  ret= 1;
4709 ex:;
4710  xorriso->tolerate_stdin_eof= 0;
4711  if(flag & 2)
4712  Xorriso_lst_destroy_all(&(xorriso->buffered_dialog), 0);
4713  /* Close any open pipes. Restore stdin, stdout and stderr. */
4714  for(i= 0; i < 3; i++) {
4715  if(pipe_fds[i] != -1) {
4716  if((flag & 1) && pipes_are_valid) {
4717  if(stat(pipe_paths[i], &stbuf) != -1) {
4718  if(S_ISFIFO(stbuf.st_mode)) {
4719  sprintf(xorriso->info_text, "Removing named pipe ");
4720  Text_shellsafe(pipe_paths[i], xorriso->info_text, 1);
4721  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
4722  unlink(pipe_paths[i]);
4723  }
4724  }
4725  }
4726  close(pipe_fds[i]);
4727  }
4728  if(mem_fds[i] != -1) {
4729  close(i);
4730  dup2(mem_fds[i], i);
4731  close(mem_fds[i]);
4732  }
4733  }
4734  Xorriso_free_meM(line);
4735  return(ret);
4736 }
4737 
4738 
4739 /* @param flag bit0= append to out_text rather than overwrite it
4740  bit1= length limit is 10 * SfileadrL rather than 5 *
4741 */
4742 char *Xorriso_esc_filepath(struct XorrisO *xorriso,
4743  char *in_text, char *out_text, int flag)
4744 {
4745  int l, w=0, limit= 5 * SfileadrL;
4746  char *res;
4747 
4748  if(xorriso->sh_style_result == 0) {
4749  res= Text_shellsafe(in_text, out_text, flag);
4750  return(res);
4751  }
4752  if(flag&1)
4753  w= strlen(out_text);
4754  if(flag & 2)
4755  limit= 10 * SfileadrL;
4756  l= strlen(in_text);
4757  if(w + l >= limit) {
4758  strcpy(out_text, "'xorriso: TEXT MUCH TOO LONG ... ");
4759  return(out_text);
4760  }
4761  strcpy(out_text + w, in_text);
4762  return(out_text);
4763 }
4764 
4765 
4766 /* @param flag bit=add to existing info_text
4767 */
4768 int Xorriso_set_info_text(struct XorrisO *xorriso, char *text,
4769  size_t trunc_len, int flag)
4770 {
4771  size_t offst= 0, maxl;
4772 
4773  maxl= sizeof(xorriso->info_text) - 1;
4774  if(flag & 1)
4775  offst= strlen(xorriso->info_text);
4776  if(offst >= maxl)
4777  return(0);
4778  maxl-= offst;
4779  if(maxl > trunc_len)
4780  maxl= trunc_len;
4781  strncpy(xorriso->info_text + offst, text, maxl + 1);
4782  if(strlen(text) > maxl) {
4783  strcpy(xorriso->info_text + offst + maxl - 12, "#[truncated]");
4784  return(2);
4785  }
4786  return(1);
4787 }
4788 
int Exclusions_get_descrs(struct ExclusionS *o, struct Xorriso_lsT **not_paths_descr, struct Xorriso_lsT **not_leafs_descr, int flag)
Definition: aux_objects.c:836
struct Xorriso_lsT * Xorriso_lst_get_next(struct Xorriso_lsT *entry, int flag)
Obtain the address of the next item in the chain of messages.
Definition: aux_objects.c:624
int Xorriso_lst_get_last(struct Xorriso_lsT *entry, struct Xorriso_lsT **last, int flag)
Definition: aux_objects.c:649
int Xorriso_lst_new(struct Xorriso_lsT **lstring, char *text, struct Xorriso_lsT *link, int flag)
Create a new list item with a 0-terminated text as content.
Definition: aux_objects.c:557
char * Xorriso_lst_get_text(struct Xorriso_lsT *entry, int flag)
Obtain the text message from the current list item.
Definition: aux_objects.c:636
int Xorriso_lst_concat(struct Xorriso_lsT *first, struct Xorriso_lsT *second, int flag)
Definition: aux_objects.c:659
int Xorriso_lst_destroy(struct Xorriso_lsT **lstring, int flag)
Destroy a single list item and connect its eventual list neighbors.
Definition: aux_objects.c:571
int Xorriso_lst_destroy_all(struct Xorriso_lsT **lstring, int flag)
Destroy all list items which are directly or indirectly connected to the given link item.
Definition: aux_objects.c:591
struct Xorriso_lsT * Xorriso_lst_get_prev(struct Xorriso_lsT *entry, int flag)
Obtain the address of the previous item in the chain of messages.
Definition: aux_objects.c:630
int Xorriso_lst_append_binary(struct Xorriso_lsT **entry, char *data, int data_len, int flag)
Create a new list item at the end of a given list.
Definition: aux_objects.c:609
int Xorriso__get_signal_behavior(int flag)
Definition: base_obj.c:799
int Xorriso_check_media_list_job(struct XorrisO *xorriso, struct CheckmediajoB *job, char *report, int flag)
Definition: check_media.c:841
int Xorriso_get_profile(struct XorrisO *xorriso, int *profile_number, char profile_name[80], int flag)
Definition: drive_mgt.c:2236
int Xorriso_status_extf(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
Definition: filters.c:619
int Xorriso_status_zisofs(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
Definition: filters.c:745
int parse_line(char *progname, char *line, char *prefix, char *separators, int max_words, int *argc, char ***argv, int flag)
#define SfileadrL
int Xorriso_boot_image_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
Definition: iso_img.c:662
int Xorriso_image_has_md5(struct XorrisO *xorriso, int flag)
Definition: iso_img.c:220
int Xorriso__text_to_sev(char *severity_name, int *severity_number, int flag)
Definition: lib_mgt.c:387
int Xorriso_get_local_charset(struct XorrisO *xorriso, char **name, int flag)
Definition: lib_mgt.c:476
int Xorriso_preparer_string(struct XorrisO *xorriso, char xorriso_id[129], int flag)
Definition: lib_mgt.c:683
int Xorriso_process_msg_queues(struct XorrisO *xorriso, int flag)
Forward any pending messages from the library message queues to the xorriso message system which puts...
Definition: lib_mgt.c:519
char * Xorriso_get_pattern(struct XorrisO *xorriso, struct Xorriso_lsT *patternlist, int index, int flag)
Definition: match.c:321
char * Text_shellsafe(char *in_text, char *out_text, int flag)
Definition: misc_funct.c:1044
char * Ftimetxt(time_t t, char timetext[40], int flag)
Definition: misc_funct.c:682
int Xorriso__format_guid(uint8_t guid[16], char *text, int flag)
Definition: misc_funct.c:1341
int Xorriso_execute_option(struct XorrisO *xorriso, char *line, int flag)
Definition: parse_exec.c:2126
int Xorriso_parse_line(struct XorrisO *xorriso, char *line, char *prefix, char *separators, int max_words, int *argc, char ***argv, int flag)
Definition: parse_exec.c:2066
int Xorriso_set_problem_status(struct XorrisO *xorriso, char *severity, int flag)
Set the current problem status of the xorriso handle.
Definition: parse_exec.c:231
void Xorriso__dispose_words(int *argc, char ***argv)
Definition: parse_exec.c:2120
int Sfile_off_t_text(char text[80], off_t num, int flag)
Definition: sfile.c:389
int Sfile_bsl_encoder(char **result, char *text, size_t text_len, int flag)
Definition: sfile.c:562
int Sfile_make_argv(char *progname, char *line, int *argc, char ***argv, int flag)
Definition: sfile.c:828
char * Sfile_fgets_n(char *line, int maxl, FILE *fp, int flag)
Definition: sfile.c:33
char * Sfile_datestr(time_t tim, short int flag)
Definition: sfile.c:294
double Sfile_microtime(int flag)
Return a double representing seconds and microseconds since 1 Jan 1970.
Definition: sfile.c:883
int Sfile_str(char target[4096], char *source, int flag)
Definition: sfile.c:836
int Sfile_count_char(char *text, char to_count)
Definition: sfile.c:49
int Sfile_scale(double value, char *result, int siz, double thresh, int flag)
Definition: sfile.c:331
#define TSOB_FELD(typ, count)
Definition: sfile.h:15
#define Xorriso_free_meM(pt)
Definition: sfile.h:27
#define Xorriso_alloc_meM(pt, typ, count)
Definition: sfile.h:19
#define Smem_malloC
Definition: sfile.h:16
double insert_bytes
int iso_mbr_part_type
int system_area_options
char publisher[129]
char volset_id[129]
int do_strict_acl
int part_like_isohybrid
int apm_block_size
char list_delimiter[81]
off_t pacifier_count
int do_follow_mount
int do_iso_rr_pattern
int msglist_stackfill
pthread_mutex_t result_msglists_lock
uid_t global_uid
int do_disk_pattern
off_t file_size_limit
pthread_mutex_t msg_watcher_lock
FILE * errfile_fp
int pacifier_style
int result_page_width
int linux_scsi_dev_family
int outdev_is_exclusive
FILE * pktlog_fp
time_t now_time_override
double start_time
struct Xorriso_msg_sievE * msg_sieve
struct ExclusionS * disk_exclusions
int displacement_sign
int do_padding_by_libisofs
char preparer_id[129]
int do_rockridge
int session_blocks
int modesty_on_drive
int read_speed_force
int allow_graft_points
int bsl_interpretation
double error_count
int errfile_mode
int partition_heads_per_cyl
int allow_restore
char efi_boot_partition[4096]
off_t sparse_min_gap
char errfile_log[4096]
char progname[4096]
char abstract_file[38]
int do_follow_pattern
off_t split_size
uint8_t gpt_guid[16]
char indev[4096]
off_t pacifier_byte_count
int early_stdio_test
int do_follow_links
int do_calm_drive
int appended_as_gpt
int img_read_error_mode
int appended_as_apm
time_t vol_effective_time
int cache_tile_blocks
char scdbackup_tag_listname[4096]
int find_check_md5_result
char * out_charset
int use_immed_bit
char system_id[33]
int ban_stdio_write
int ino_behavior
char all_file_dates[80]
int status_history_max
int do_overwrite
time_t vol_creation_time
int image_start_mode
int cache_num_tiles
int drives_access
int min_buffer_percent
char volid[33]
char result_line[10 *4096]
int result_page_counter
int sh_style_result
int abort_on_severity
FILE * stderr_fp
uint8_t hfsp_serial_number[8]
char prep_partition[4096]
gid_t global_gid
struct Xorriso_lsT * info_msglists[Xorriso_max_outlist_stacK]
int do_auto_chmod
int drives_exclusive
int bar_is_fresh
int cache_default
int do_restore_sort_lba
char info_text[10 *4096]
int do_follow_concat
int max_buffer_usec
double insert_count
char system_area_disk_path[4096]
uint32_t partition_offset
int msgw_msg_pending
int grow_blindly_msc2
int do_concat_split
char vol_uuid[17]
int iso_mbr_part_flag
int result_page_length
uint32_t displacement
char logfile[4][4096]
int min_buffer_usec
int mount_opts_flag
uint8_t iso_gpt_type_guid[16]
int file_name_limit
char abort_on_text[20]
int buffer_timeout_sec
char rr_reloc_dir[256]
double pacifier_interval
int do_override_now_time
int do_global_gid
int request_to_abort
int follow_link_limit
int(* msgw_result_handler)(void *handle, char *text)
int tolerate_stdin_eof
char scdbackup_tag_name[81]
int hfsp_block_size
int volid_default
off_t pacifier_prev_count
struct Xorriso_lsT * buffered_dialog
int request_not_to_ask
char * in_charset
int partition_secs_per_head
void * msgw_info_handle
char image_start_value[81]
int do_global_uid
int msg_watcher_state
time_t vol_modification_time
int outdev_access
char return_with_text[20]
int max_buffer_percent
struct Xorriso_lsT * drive_blacklist
int extract_error_mode
char session_logfile[4096]
char loaded_volid[33]
int return_with_value
char assert_volid[4096]
int disk_excl_mode
int report_about_severity
char wdx[4096]
int packet_output
char outdev[4096]
pthread_mutex_t write_to_channel_lock
char copyright_file[38]
int indev_access
struct Xorriso_lsT * result_msglists[Xorriso_max_outlist_stacK]
char application_use[4096]
char application_id[129]
char mark_text[4096]
double last_update_time
char report_about_text[20]
int result_line_counter
int do_follow_param
int temp_mem_limit
char assert_volid_sev[80]
void * msgw_result_handle
int msglist_flags[Xorriso_max_outlist_stacK]
double idle_time
int result_open_line_len
off_t pacifier_total
int gpt_guid_mode
struct Xorriso_lsT * jigdo_values
int use_immed_bit_default
int toc_emulation_flag
int do_stream_recording
struct Xorriso_lsT * jigdo_params
int(* msgw_info_handler)(void *handle, char *text)
struct Xorriso_lsT * drive_whitelist
char biblio_file[38]
struct CheckmediajoB * check_media_default
int msgw_stack_handle
time_t vol_expiration_time
int indev_is_exclusive
int msg_sieve_disabled
struct Xorriso_lsT * drive_greylist
int boot_image_isohybrid
char wdi[4096]
int read_speed_corr
FILE * logfile_fp[4]
pthread_mutex_t msgw_fetch_lock
int problem_status
char pending_option[4096]
struct Xorriso_lsT * next
Definition: aux_objects.h:70
char * text
Definition: aux_objects.h:69
struct Xorriso_msg_filteR * next
Definition: text_io.c:1717
struct Xorriso_lsT * next_to_deliver
Definition: text_io.c:1714
struct Xorriso_msg_filteR * prev
Definition: text_io.c:1716
struct Xorriso_lsT * results
Definition: text_io.c:1711
struct Xorriso_msg_filteR * first_filter
Definition: text_io.c:1814
int Xorriso_boot_status_sysarea(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
Definition: text_io.c:2713
int Xorriso_open_named_pipe(struct XorrisO *xorriso, char fd_names[3][20], int mem_fds[], char *pipe_paths[], int pipe_fds[], int i, int flag)
Definition: text_io.c:4505
int Xorriso_stop_msg_watcher(struct XorrisO *xorriso, int flag)
Revoke output redirection by Xorriso_start_msg_watcher() and end the watcher thread.
Definition: text_io.c:1614
int Xorriso_reset_counters(struct XorrisO *xorriso, int flag)
Definition: text_io.c:4065
int Xorriso_msgs_submit(struct XorrisO *xorriso, int error_code, char msg_text[], int os_errno, char severity[], int flag)
Submit a problem message to the xorriso problem reporting and handling system.
Definition: text_io.c:2504
int Xorriso_msg_filter_destroy(struct Xorriso_msg_filteR **o, int flag)
Definition: text_io.c:1762
int Xorriso_predict_linecount(struct XorrisO *xorriso, char *line, int *linecount, int flag)
Definition: text_io.c:742
int Xorriso_read_lines(struct XorrisO *xorriso, FILE *fp, int *linecount, int *argc, char ***argv, int flag)
Definition: text_io.c:644
static int Xorriso_write_to_msglist(struct XorrisO *xorriso, struct Xorriso_lsT **xorriso_msglist, char *text, int flag)
Definition: text_io.c:885
int Xorriso_launch_frontend(struct XorrisO *xorriso, int argc, char **argv, char *cmd_pipe_adr, char *reply_pipe_adr, int flag)
Definition: text_io.c:4303
int Xorriso_msg_sieve_new(struct Xorriso_msg_sievE **o, int flag)
Definition: text_io.c:1819
int Xorriso_sieve_filter_msg(struct XorrisO *xorriso, char *msg, int flag)
Definition: text_io.c:2197
int Xorriso_process_errfile(struct XorrisO *xorriso, int error_code, char msg_text[], int os_errno, int flag)
Write a message for option -errfile_log.
Definition: text_io.c:2438
int Xorriso_start_msg_watcher(struct XorrisO *xorriso, int(*result_handler)(void *handle, char *text), void *result_handle, int(*info_handler)(void *handle, char *text), void *info_handle, int flag)
Redirect output by Xorriso_push_outlists() and start a thread which fetches this output and performs ...
Definition: text_io.c:1523
#define O_BINARY
Definition: text_io.c:31
int Xorriso_no_findjob(struct XorrisO *xorriso, char *cmd, int flag)
Definition: text_io.c:4110
static int Xorriso_obtain_lock(struct XorrisO *xorriso, pthread_mutex_t *lock_handle, char *purpose, int flag)
Definition: text_io.c:817
static int Xorriso_release_lock(struct XorrisO *xorriso, pthread_mutex_t *lock_handle, char *purpose, int flag)
Definition: text_io.c:842
int Xorriso_request_confirmation(struct XorrisO *xorriso, int flag)
Definition: text_io.c:493
int Xorriso_sieve_big(struct XorrisO *xorriso, int flag)
Install a large sieve with filters for about any interesting message of xorriso.
Definition: text_io.c:2026
int Xorriso_pager(struct XorrisO *xorriso, char *line, int flag)
Definition: text_io.c:775
int Xorriso_pacifier_callback(struct XorrisO *xorriso, char *what_done, off_t count, off_t todo, char *current_object, int flag)
Definition: text_io.c:3969
int Xorriso_peek_outlists(struct XorrisO *xorriso, int stack_handle, int timeout, int flag)
Inquire whether messages are pending in redirected result and info channel.
Definition: text_io.c:1256
int Xorriso_result_handler_stdout(void *handle, char *text)
Definition: text_io.c:1370
int Xorriso_info_handler_stderr(void *handle, char *text)
Definition: text_io.c:1354
int Xorriso_no_malloc_memory(struct XorrisO *xorriso, char **to_free, int flag)
Definition: text_io.c:4077
int Xorriso_write_session_log(struct XorrisO *xorriso, int flag)
Definition: text_io.c:2638
static char * Xorriso__speedname(int speed)
Definition: text_io.c:2745
int Xorriso_push_outlists(struct XorrisO *xorriso, int *stack_handle, int flag)
Enable a new redirection of info and/or result channel.
Definition: text_io.c:1174
int Xorriso_named_pipe_loop(struct XorrisO *xorriso, char *pipe_paths[3], int flag)
Definition: text_io.c:4551
int Xorriso_info(struct XorrisO *xorriso, int flag)
Definition: text_io.c:2367
int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
Definition: text_io.c:2764
static int Xorriso_unlock_outlists(struct XorrisO *xorriso, int flag)
Definition: text_io.c:875
static int Xorriso_lock_outlists(struct XorrisO *xorriso, int flag)
Definition: text_io.c:865
int Xorriso_result_handler_pkt(void *handle, char *text)
Definition: text_io.c:1378
int Xorriso_pull_outlists(struct XorrisO *xorriso, int stack_handle, struct Xorriso_lsT **result_list, struct Xorriso_lsT **info_list, int flag)
Disable the redirection given by stack_handle.
Definition: text_io.c:1309
int Xorriso_write_to_channel(struct XorrisO *xorriso, char *in_text, int channel_no, int flag)
Definition: text_io.c:911
int Xorriso_msg_op_parse(struct XorrisO *xorriso, char *line, char *prefix, char *separators, int max_words, int pflag, int input_lines, int flag)
Definition: text_io.c:4161
int Xorriso_protect_stdout(struct XorrisO *xorriso, int flag)
Definition: text_io.c:63
int Xorriso_msg_filter_new(struct Xorriso_msg_filteR **o, char *name, struct Xorriso_msg_filteR *prev, struct Xorriso_msg_filteR *next, int flag)
Definition: text_io.c:1722
int Xorriso_sieve_get_result(struct XorrisO *xorriso, char *name, int *argc, char ***argv, int *available, int flag)
Inquire recorded results from a particular filter rule.
Definition: text_io.c:1925
int Xorriso_msg_filter_set_words(struct Xorriso_msg_filteR *m, int num_words, int *word_idx, int flag)
Definition: text_io.c:1790
int Xorriso_report_md5_outcome(struct XorrisO *xorriso, char *severity, int flag)
Definition: text_io.c:4118
int Xorriso_msg_op_parse_bulk(struct XorrisO *xorriso, char *prefix, char *separators, int max_words, int pflag, int bulk_lines, int flag)
Definition: text_io.c:4239
static void * Xorriso_msg_watcher(void *state_pt)
Definition: text_io.c:1454
char * Xorriso_esc_filepath(struct XorrisO *xorriso, char *in_text, char *out_text, int flag)
Definition: text_io.c:4742
int Xorriso_process_msg_lists(struct XorrisO *xorriso, struct Xorriso_lsT *result_list, struct Xorriso_lsT *info_list, int *line_count, int flag)
Definition: text_io.c:1416
int Xorriso_pacifier_reset(struct XorrisO *xorriso, int flag)
Definition: text_io.c:3937
int Xorriso_msgs_submit_void(void *xorriso, int error_code, char msg_text[], int os_errno, char severity[], int flag)
Alternative call interface of Xorriso_msgs_submit with void* instead of struct XorrisO*.
Definition: text_io.c:2595
int Xorriso_set_info_text(struct XorrisO *xorriso, char *text, size_t trunc_len, int flag)
Definition: text_io.c:4768
int Xorriso_msg_sieve_destroy(struct Xorriso_msg_sievE **o, int flag)
Definition: text_io.c:1832
int Xorriso_sieve_add_filter(struct XorrisO *xorriso, char *name, int channels, char *prefix, char *separators, int num_words, int *word_idx, int max_results, int flag)
Add a filter rule to the message sieve.
Definition: text_io.c:1851
int Xorriso_sieve_clear_results(struct XorrisO *xorriso, int flag)
Dispose all recorded results.
Definition: text_io.c:1900
int Xorriso_sieve_dispose(struct XorrisO *xorriso, int flag)
Dispose all filter rules.
Definition: text_io.c:1892
int Xorriso_fetch_outlists(struct XorrisO *xorriso, int stack_handle, struct Xorriso_lsT **result_list, struct Xorriso_lsT **info_list, int flag)
Obtain the currently collected text messages of redirected info and result channel.
Definition: text_io.c:1206
int Xorriso_reassure(struct XorrisO *xorriso, char *cmd, char *which_will, int flag)
Definition: text_io.c:2609
int Xorriso_status_filter(struct XorrisO *xorriso, char *filter, char *line, int flag)
Definition: text_io.c:2676
int Xorriso_much_too_long(struct XorrisO *xorriso, int len, int flag)
Definition: text_io.c:4097
int Xorriso_status_result(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
Definition: text_io.c:2687
int Xorriso_result(struct XorrisO *xorriso, int flag)
Definition: text_io.c:2337
int Xorriso_mark(struct XorrisO *xorriso, int flag)
Definition: text_io.c:2403
int Xorriso_restxt(struct XorrisO *xorriso, char *text)
Definition: text_io.c:2423
int Xorriso_dialog_input(struct XorrisO *xorriso, char line[], int linesize, int flag)
Definition: text_io.c:316
int Xorriso_get_relax_text(struct XorrisO *xorriso, char mode[1024], int flag)
Definition: write_run.c:2716
#define Xorriso_max_outlist_stacK
Maximum number of stacked redirections.
Definition: xorriso.h:998
#define Xorriso_default_file_size_limiT
#define Xorriso_status_history_maX