gwenhywfar  5.14.1
cgui.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Tue Oct 02 2002
3  copyright : (C) 2002-2017 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU Lesser General Public *
10  * License as published by the Free Software Foundation; either *
11  * version 2.1 of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * Lesser General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU Lesser General Public *
19  * License along with this library; if not, write to the Free Software *
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21  * MA 02111-1307 USA *
22  * *
23  ***************************************************************************/
24 
25 
26 #ifdef HAVE_CONFIG_H
27 # include <config.h>
28 #endif
29 
30 #define DISABLE_DEBUGLOG
31 
32 
33 #include "cgui_p.h"
34 #include "i18n_l.h"
35 
36 #include <gwenhywfar/gui_be.h>
37 #include <gwenhywfar/inherit.h>
38 #include <gwenhywfar/debug.h>
39 #include <gwenhywfar/misc.h>
40 #include <gwenhywfar/db.h>
41 #include <gwenhywfar/gwentime.h>
42 #include <gwenhywfar/mdigest.h>
43 #include <gwenhywfar/text.h>
44 
45 
46 #include <stdlib.h>
47 #include <string.h>
48 #include <ctype.h>
49 #ifdef HAVE_TERMIOS_H
50 # include <termios.h>
51 #endif
52 #include <unistd.h>
53 #include <fcntl.h>
54 #include <stdio.h>
55 #include <errno.h>
56 
57 #ifdef HAVE_SIGNAL_H
58 # include <signal.h>
59 #endif
60 #ifdef HAVE_ICONV_H
61 # include <iconv.h>
62 #endif
63 #ifdef OS_WIN32
64 #include <windows.h>
65 #endif
66 #ifndef ICONV_CONST
67 # define ICONV_CONST
68 #endif
69 
70 
71 
72 GWEN_INHERIT(GWEN_GUI, GWEN_GUI_CGUI)
73 
74 
75 
76 
78 {
79  GWEN_GUI *gui;
80  GWEN_GUI_CGUI *cgui;
81 
82  gui=GWEN_Gui_new();
83  GWEN_NEW_OBJECT(GWEN_GUI_CGUI, cgui);
84  cgui->progressList=GWEN_Gui_CProgress_List_new();
85  GWEN_INHERIT_SETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui, cgui,
87 
97 
98  return gui;
99 }
100 
101 
102 
104 {
105  GWEN_GUI_CGUI *cgui;
106 
107  cgui=(GWEN_GUI_CGUI *)p;
108  GWEN_Gui_CProgress_List_free(cgui->progressList);
109  GWEN_FREE_OBJECT(cgui);
110 }
111 
112 
113 
115 {
116  int chr;
117 #ifdef HAVE_TERMIOS_H
118  struct termios OldAttr, NewAttr;
119  int AttrChanged = 0;
120 #endif
121 #if HAVE_DECL_SIGPROCMASK
122  sigset_t snew, sold;
123 #endif
124 
125  // disable canonical mode to receive a single character
126 #if HAVE_DECL_SIGPROCMASK
127  sigemptyset(&snew);
128  sigaddset(&snew, SIGINT);
129  sigaddset(&snew, SIGSTOP);
130  sigprocmask(SIG_BLOCK, &snew, &sold);
131 #endif
132 #ifdef HAVE_TERMIOS_H
133  if (0 == tcgetattr(fileno(stdin), &OldAttr)) {
134  NewAttr = OldAttr;
135  NewAttr.c_lflag &= ~ICANON;
136  NewAttr.c_lflag &= ~ECHO;
137  tcsetattr(fileno(stdin), TCSAFLUSH, &NewAttr);
138  AttrChanged = !0;
139  }
140 #endif
141 
142  for (;;) {
143  chr=getchar();
144  if (waitFor) {
145  if (chr==-1 ||
146  chr==GWEN_GUI_CGUI_CHAR_ABORT ||
147  chr==GWEN_GUI_CGUI_CHAR_ENTER ||
148  chr==waitFor)
149  break;
150  }
151  else
152  break;
153  }
154 
155 #ifdef HAVE_TERMIOS_H
156  /* re-enable canonical mode (if previously disabled) */
157  if (AttrChanged)
158  tcsetattr(fileno(stdin), TCSADRAIN, &OldAttr);
159 #endif
160 
161 #if HAVE_DECL_SIGPROCMASK
162  sigprocmask(SIG_BLOCK, &sold, 0);
163 #endif
164 
165  return chr;
166 }
167 
168 #ifdef OS_WIN32
170  uint32_t flags,
171  char *buffer,
172  int minLen,
173  int maxLen,
174  uint32_t guiid)
175 {
176  const char ABORT=3;
177  const char BACKSPACE=8;
178  const char RETURN=13;
179  const int show_asterisk=!(flags & GWEN_GUI_INPUT_FLAGS_SHOW);
180  int rv = 0;
181 
182  unsigned char ch=0;
183  char *p=buffer;
184 
185  DWORD con_mode;
186  DWORD dwRead;
187 
188  HANDLE hIn=GetStdHandle(STD_INPUT_HANDLE);
189  if (hIn == INVALID_HANDLE_VALUE) {
190  DBG_ERROR(GWEN_LOGDOMAIN, "Cannot get handle to stdin");
192  return rv;
193  }
194 
195  if (!GetConsoleMode(hIn, &con_mode)) {
196  DBG_ERROR(GWEN_LOGDOMAIN, "Error on getting console mode for stdin: %d", GetLastError());
198  return rv;
199  }
200 
201  if (!SetConsoleMode(hIn, con_mode & ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT | ENABLE_PROCESSED_OUTPUT))) {
202  DBG_ERROR(GWEN_LOGDOMAIN, "Error on seting console mode for stdin: %d", GetLastError());
204  return rv;
205  }
206 
207  while(ReadConsoleA(hIn, &ch, 1, &dwRead, NULL) && ch !=RETURN) {
208  if (ch==BACKSPACE) {
209  if (p>buffer) {
210  if (show_asterisk) {
211  putchar('\b');
212  putchar(' ');
213  putchar('\b');
214  }
215  *--p='\0';
216  }
217  } else if (ch==ABORT) {
218  DBG_INFO(GWEN_LOGDOMAIN, "User aborted");
220  break;
221  } else if (p-buffer<maxLen) {
222  *p++=ch;
223  *p='\0';
224  if (show_asterisk)
225  putchar('*');
226  else
227  putchar(ch);
228  }
229  }
230  putchar('\n');
231  if (!SetConsoleMode(hIn, con_mode)) {
232  DBG_ERROR(GWEN_LOGDOMAIN, "Error on resetting console mode for stdin: %d", GetLastError());
234  }
235  return rv;
236 }
237 #else
239  uint32_t flags,
240  char *buffer,
241  int minLen,
242  int maxLen,
243  uint32_t guiid)
244 {
245 #ifdef HAVE_TERMIOS_H
246  struct termios OldInAttr, NewInAttr;
247  struct termios OldOutAttr, NewOutAttr;
248  int AttrInChanged = 0;
249  int AttrOutChanged = 0;
250 #endif
251  int chr;
252  unsigned int pos;
253  char *pOutbuf;
254  int rv;
255 #if HAVE_DECL_SIGPROCMASK
256  sigset_t snew, sold;
257 #endif
258 #ifdef HAVE_ICONV
259 #define INBUFSIZE 6
260  char inbuf[INBUFSIZE];
261  iconv_t ic;
262  size_t inLeft;
263  size_t outLeft;
264  size_t done;
265  ICONV_CONST char *pInbuf;
266  const char *wantedCharSet;
267  char *nextchr;
268 
269  wantedCharSet=GWEN_Gui_GetCharSet(gui);
270  if (!wantedCharSet)
271  wantedCharSet="UTF-8";
272  ic=iconv_open("UTF-8", wantedCharSet);
273  if (ic==(iconv_t)-1) {
274  DBG_ERROR(GWEN_LOGDOMAIN, "Cannot convert from \"%s\" to \"UTF-8\", %s",
275  wantedCharSet, strerror(errno));
276  return GWEN_ERROR_GENERIC;
277  }
278 
279  pInbuf=inbuf;
280  outLeft=maxLen;
281 #endif
282 
283  /* if possible, disable echo from stdin to stdout during password
284  * entry */
285 #if HAVE_DECL_SIGPROCMASK
286  sigemptyset(&snew);
287  sigaddset(&snew, SIGINT);
288  sigaddset(&snew, SIGSTOP);
289  sigprocmask(SIG_BLOCK, &snew, &sold);
290 #endif
291 
292 #ifdef HAVE_TERMIOS_H
293  if (0 == tcgetattr(fileno(stdin), &OldInAttr)) {
294  NewInAttr = OldInAttr;
295  NewInAttr.c_lflag &= ~ECHO;
296  NewInAttr.c_lflag &= ~ICANON;
297  tcsetattr(fileno(stdin), TCSAFLUSH, &NewInAttr);
298  AttrInChanged = !0;
299  }
300  if (0 == tcgetattr(fileno(stdout), &OldOutAttr)) {
301  NewOutAttr = OldOutAttr;
302  NewOutAttr.c_lflag &= ~ICANON;
303  tcsetattr(fileno(stdout), TCSAFLUSH, &NewOutAttr);
304  AttrOutChanged = !0;
305  }
306 #endif
307 
308  pos=0;
309  pOutbuf=buffer;
310  for (;;) {
311 #ifdef HAVE_ICONV
312  nextchr=inbuf;
313  pInbuf=inbuf;
314  inLeft=0;
315  outLeft=maxLen-pos;
316  do {
317  chr=getchar();
318  if (chr==EOF)
319  break;
320  *nextchr++=chr;
321  inLeft++;
322  done=iconv(ic, &pInbuf, &inLeft, &pOutbuf, &outLeft);
323  }
324  while (done==(size_t)-1 && errno==EINVAL &&
325  nextchr-inbuf<INBUFSIZE);
326 
327  if (chr==EOF) {
328  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected EOF while reading from stdin");
330  break;
331  }
332  else if (done==(size_t)-1) {
333  if (errno==E2BIG || errno==EILSEQ) {
334  GWEN_Gui_StdPrintf(gui, stdout, "\007");
335  continue;
336  }
337  DBG_ERROR(GWEN_LOGDOMAIN, "Unrecoverable error in conversion: %s",
338  strerror(errno));
340  break;
341  }
342 #else /* HAVE_ICONV */
343  chr=getchar();
344  if (chr!=EOF)
345  *pOutbuf++=chr;
346  else {
347  DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected EOF while reading from stdin");
349  break;
350  }
351 #endif /* HAVE_ICONV */
352 
353  if (chr==GWEN_GUI_CGUI_CHAR_DELETE) {
354  if (pos) {
355  /* Look for the start of the previous UTF-8 character */
356  do
357  pos--;
358  while ((buffer[pos]&0xC0)==0x80 && pos);
359  GWEN_Gui_StdPrintf(gui, stdout, "%c %c", 8, 8);
360  }
361  pOutbuf=buffer+pos;
362  }
363  else if (chr==GWEN_GUI_CGUI_CHAR_ENTER) {
364  if (minLen && pos<minLen) {
365  if (pos==0 && (flags & GWEN_GUI_INPUT_FLAGS_ALLOW_DEFAULT)) {
369  I18N("Empty Input"),
370  I18N("Your input was empty.\n"
371  "Do you want to use the default?"),
372  I18N("Yes"),
373  I18N("No"),
374  I18N("Abort"), guiid);
375  if (rv==1) {
377  break;
378  }
379  else {
381  break;
382  }
383  }
384  else {
385  /* too few characters */
386  GWEN_Gui_StdPrintf(gui, stdout, "\007");
387  pOutbuf=buffer+pos;
388  }
389  }
390  else {
391  GWEN_Gui_StdPrintf(gui, stdout, "\n");
392  buffer[pos]=0;
393  rv=0;
394  break;
395  }
396  }
397  else if (chr==GWEN_GUI_CGUI_CHAR_ABORT) {
398  DBG_INFO(GWEN_LOGDOMAIN, "User aborted");
400  break;
401  }
402  else if (pOutbuf-buffer<maxLen) {
403  if ((flags & GWEN_GUI_INPUT_FLAGS_NUMERIC) &&
404  !isdigit(chr)) {
405  /* bad character */
406  GWEN_Gui_StdPrintf(gui, stdout, "\007");
407  pOutbuf=buffer+pos;
408  }
409  else {
410  if (flags & GWEN_GUI_INPUT_FLAGS_SHOW) {
411  *pOutbuf=0;
412  GWEN_Gui_StdPrintf(gui, stdout, "%s", buffer+pos);
413  }
414  else
415 #ifndef HAVE_ICONV
416  /* Do not print stars for continuation bytes */
417  if ((chr&0xC0)!=0x80)
418 #endif
419  GWEN_Gui_StdPrintf(gui, stdout, "*");
420  pos=pOutbuf-buffer;
421  }
422  }
423  else {
424  /* buffer full */
425  GWEN_Gui_StdPrintf(gui, stdout, "\007");
426  pOutbuf=buffer+pos;
427  }
428  } /* for */
429 
430 #ifdef HAVE_TERMIOS_H
431  /* re-enable echo (if previously disabled) */
432  if (AttrOutChanged)
433  tcsetattr(fileno(stdout), TCSADRAIN, &OldOutAttr);
434  if (AttrInChanged)
435  tcsetattr(fileno(stdin), TCSADRAIN, &OldInAttr);
436 #endif
437 
438 #if HAVE_DECL_SIGPROCMASK
439  sigprocmask(SIG_BLOCK, &sold, 0);
440 #endif
441 #ifdef HAVE_ICONV
442  iconv_close(ic);
443 #endif
444  return rv;
445 }
446 #endif
447 
448 
450  uint32_t flags,
451  const char *title,
452  const char *text,
453  const char *b1,
454  const char *b2,
455  const char *b3,
456  GWEN_UNUSED uint32_t guiid)
457 {
458  GWEN_BUFFER *tbuf;
459  int c;
460 
461  assert(gui);
462 
463  tbuf=GWEN_Buffer_new(0, 256, 0, 1);
464  GWEN_Gui_GetRawText(gui, text, tbuf);
465 
468  GWEN_Gui_StdPrintf(gui, stdout,
469  "Got the following dangerous message:\n%s\n",
470  GWEN_Buffer_GetStart(tbuf));
471  GWEN_Buffer_free(tbuf);
472  return 0;
473  }
474  else {
476  "Auto-answering the following message with %d:\n%s",
478  GWEN_Buffer_GetStart(tbuf));
479  GWEN_Buffer_free(tbuf);
480  return GWEN_GUI_MSG_FLAGS_CONFIRM_BUTTON(flags);
481  }
482  }
483 
484  GWEN_Gui_StdPrintf(gui, stdout, "===== %s =====\n", title);
485  GWEN_Gui_StdPrintf(gui, stdout, "%s\n", GWEN_Buffer_GetStart(tbuf));
486  GWEN_Buffer_free(tbuf);
487  tbuf=0;
488 
489  if (b1) {
490  GWEN_Gui_StdPrintf(gui, stdout, "(1) %s", b1);
491  if (b2) {
492  GWEN_Gui_StdPrintf(gui, stdout, " (2) %s", b2);
493  if (b3) {
494  GWEN_Gui_StdPrintf(gui, stdout, " (3) %s", b3);
495  }
496  }
497  GWEN_Gui_StdPrintf(gui, stdout, "\n");
498  }
499  GWEN_Gui_StdPrintf(gui, stdout, "Please enter your choice: ");
500  for (;;) {
502  if (c==EOF) {
503  GWEN_Gui_StdPrintf(gui, stdout, "Aborted.\n");
505  }
506  if (!b1 && c==13)
507  return 0;
508  if (c=='1' && b1) {
509  GWEN_Gui_StdPrintf(gui, stdout, "1\n");
510  return 1;
511  }
512  else if (c=='2' && b2) {
513  GWEN_Gui_StdPrintf(gui, stdout, "2\n");
514  return 2;
515  }
516  else if (c=='3' && b3) {
517  GWEN_Gui_StdPrintf(gui, stdout, "3\n");
518  return 3;
519  }
520  else {
521  GWEN_Gui_StdPrintf(gui, stdout, "%c", 7);
522  }
523  } /* for */
524 
525 }
526 
527 
528 
530  uint32_t flags,
531  const char *title,
532  const char *text,
533  char *buffer,
534  int minLen,
535  int maxLen,
536  uint32_t guiid)
537 {
538  int rv;
539  GWEN_BUFFER *tbuf;
540 
541  assert(gui);
542 
544  (flags & GWEN_GUI_INPUT_FLAGS_TAN)) {
545  DBG_ERROR(GWEN_LOGDOMAIN, "No TAN input in non-interactive mode");
547  }
548 
549 
550  tbuf=GWEN_Buffer_new(0, 256, 0, 1);
551  GWEN_Gui_GetRawText(gui, text, tbuf);
552 
553  GWEN_Gui_StdPrintf(gui, stdout, "===== %s =====\n", title);
554  GWEN_Gui_StdPrintf(gui, stdout, "%s\n", GWEN_Buffer_GetStart(tbuf));
555  GWEN_Buffer_free(tbuf);
556  tbuf=0;
557 
558  if (flags & GWEN_GUI_INPUT_FLAGS_CONFIRM) {
559  char *lbuffer=0;
560 
561  lbuffer=(char *)malloc(maxLen);
562  if (!lbuffer) {
563  DBG_ERROR(GWEN_LOGDOMAIN, "Not enough memory for %d bytes", maxLen);
564  return GWEN_ERROR_INVALID;
565  }
566  for (;;) {
567  GWEN_Gui_StdPrintf(gui, stdout, "Input: ");
568  rv=GWEN_Gui_CGui__input(gui, flags, lbuffer, minLen, maxLen, guiid);
569  if (rv) {
570  free(lbuffer);
571  return rv;
572  }
573 
574  GWEN_Gui_StdPrintf(gui, stdout, "Again: ");
575  rv=GWEN_Gui_CGui__input(gui, flags, buffer, minLen, maxLen, guiid);
576  if (rv) {
577  free(lbuffer);
578  return rv;
579  }
580  if (strcmp(lbuffer, buffer)!=0) {
581  GWEN_Gui_StdPrintf(gui, stdout,
582  "ERROR: Entries do not match, please try (again or abort)\n");
583  }
584  else {
585  rv=0;
586  break;
587  }
588 
589  } /* for */
590  free(lbuffer);
591  }
592  else {
593  GWEN_Gui_StdPrintf(gui, stdout, "Input: ");
594  rv=GWEN_Gui_CGui__input(gui, flags, buffer, minLen, maxLen, guiid);
595  }
596 
597  if ((rv==0) && (GWEN_Gui_GetFlags(gui) & GWEN_GUI_FLAGS_PERMPASSWORDS)) {
598  /* if the user allows it (by setting flag GWEN_GUI_FLAGS_PERMPASSWORDS)
599  * return 1, meaning the input may be stored in a permanent password store */
600  return 1;
601  }
602 
603  return rv;
604 }
605 
606 
607 
609  GWEN_UNUSED uint32_t flags,
610  const char *title,
611  const char *text,
612  GWEN_UNUSED uint32_t guiid)
613 {
614  GWEN_GUI_CGUI *cgui;
615  GWEN_BUFFER *tbuf;
616 
617  assert(gui);
618  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
619  assert(cgui);
620 
621  tbuf=GWEN_Buffer_new(0, 256, 0, 1);
622  GWEN_Gui_GetRawText(gui, text, tbuf);
623 
624  GWEN_Gui_StdPrintf(gui, stdout, "===== %s =====\n", title);
625  GWEN_Gui_StdPrintf(gui, stdout, "%s\n", GWEN_Buffer_GetStart(tbuf));
626  GWEN_Buffer_free(tbuf);
627  tbuf=0;
628 
629  return ++(cgui->nextBoxId);
630 }
631 
632 
633 
635 {
636  GWEN_GUI_CGUI *cgui;
637 
638  assert(gui);
639  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
640  assert(cgui);
641 
642  /* nothing to do right now */
643 }
644 
645 
646 
648  uint32_t progressFlags,
649  const char *title,
650  const char *text,
651  uint64_t total,
652  GWEN_UNUSED uint32_t guiid)
653 {
654  GWEN_GUI_CGUI *cgui;
655  GWEN_GUI_CPROGRESS *cp;
656 
657  assert(gui);
658  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
659  assert(cgui);
660 
661  cp=GWEN_Gui_CProgress_new(gui,
662  ++(cgui->nextProgressId),
663  progressFlags,
664  title,
665  text,
666  total);
667  GWEN_Gui_CProgress_List_Insert(cp, cgui->progressList);
668  return GWEN_Gui_CProgress_GetId(cp);
669 }
670 
671 
672 
674 {
675  GWEN_GUI_CGUI *cgui;
676  GWEN_GUI_CPROGRESS *cp;
677 
678  assert(gui);
679  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
680  assert(cgui);
681 
682  cp=GWEN_Gui_CProgress_List_First(cgui->progressList);
683  if (id==0)
684  return cp;
685  while (cp) {
686  if (GWEN_Gui_CProgress_GetId(cp)==id)
687  break;
688  cp=GWEN_Gui_CProgress_List_Next(cp);
689  } /* while */
690 
691  return cp;
692 }
693 
694 
695 
697  uint32_t id,
698  uint64_t progress)
699 {
700  GWEN_GUI_CGUI *cgui;
701  GWEN_GUI_CPROGRESS *cp;
702 
703  assert(gui);
704  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
705  assert(cgui);
706 
707  cp=GWEN_Gui_CGui__findProgress(gui, id);
708  if (!cp) {
709  DBG_DEBUG(GWEN_LOGDOMAIN, "Progress object %u not found", id);
710  return 0;
711  }
712  else {
713  return GWEN_Gui_CProgress_Advance(cp, progress);
714  }
715 }
716 
717 
718 
719 int GWENHYWFAR_CB GWEN_Gui_CGui_ProgressSetTotal(GWEN_GUI *gui, uint32_t id, uint64_t total)
720 {
721  GWEN_GUI_CGUI *cgui;
722  GWEN_GUI_CPROGRESS *cp;
723 
724  assert(gui);
725  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
726  assert(cgui);
727 
728  cp=GWEN_Gui_CGui__findProgress(gui, id);
729  if (!cp) {
730  DBG_DEBUG(GWEN_LOGDOMAIN, "Progress object %u not found", id);
731  }
732  else
733  GWEN_Gui_CProgress_SetTotal(cp, total);
734  return 0;
735 }
736 
737 
738 
740  uint32_t id,
741  GWEN_LOGGER_LEVEL level,
742  const char *text)
743 {
744  GWEN_GUI_CGUI *cgui;
745  GWEN_GUI_CPROGRESS *cp;
746 
747  assert(gui);
748  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
749  assert(cgui);
750 
751  cp=GWEN_Gui_CGui__findProgress(gui, id);
752  if (!cp) {
753  DBG_DEBUG(GWEN_LOGDOMAIN, "Progress object %u not found", id);
754  return 0;
755  }
756  else {
757  return GWEN_Gui_CProgress_Log(cp, level, text);
758  }
759 }
760 
761 
762 
764 {
765  GWEN_GUI_CGUI *cgui;
766  GWEN_GUI_CPROGRESS *cp;
767 
768  assert(gui);
769  cgui=GWEN_INHERIT_GETDATA(GWEN_GUI, GWEN_GUI_CGUI, gui);
770  assert(cgui);
771 
772  cp=GWEN_Gui_CGui__findProgress(gui, id);
773  if (!cp) {
774  DBG_DEBUG(GWEN_LOGDOMAIN, "Progress object %u not found", id);
775  return 0;
776  }
777  else {
778  int rv;
779 
780  rv=GWEN_Gui_CProgress_End(cp);
781  GWEN_Gui_CProgress_List_Del(cp);
783  return rv;
784  }
785 }
786 
787 
788 
GWEN_GUI_CPROGRESS * GWEN_Gui_CGui__findProgress(GWEN_GUI *gui, uint32_t id)
Definition: cgui.c:673
#define DBG_ERROR(dbg_logger, format,...)
Definition: debug.h:97
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
uint32_t GWENHYWFAR_CB GWEN_Gui_CGui_ProgressStart(GWEN_GUI *gui, uint32_t progressFlags, const char *title, const char *text, uint64_t total, GWEN_UNUSED uint32_t guiid)
Definition: cgui.c:647
#define I18N(m)
Definition: error.c:42
uint32_t GWEN_Gui_CProgress_GetId(const GWEN_GUI_CPROGRESS *cp)
Definition: cprogress.c:96
#define GWEN_ERROR_INVALID
Definition: error.h:67
#define GWEN_GUI_MSG_FLAGS_SEVERITY_IS_DANGEROUS(fl)
Definition: gui.h:338
int GWENHYWFAR_CB GWEN_Gui_CGui_ProgressLog(GWEN_GUI *gui, uint32_t id, GWEN_LOGGER_LEVEL level, const char *text)
Definition: cgui.c:739
#define DBG_DEBUG(dbg_logger, format,...)
Definition: debug.h:214
int GWENHYWFAR_CB GWEN_Gui_CGui_InputBox(GWEN_GUI *gui, uint32_t flags, const char *title, const char *text, char *buffer, int minLen, int maxLen, uint32_t guiid)
Definition: cgui.c:529
#define GWEN_GUI_INPUT_FLAGS_CONFIRM
Definition: gui.h:211
#define GWEN_GUI_FLAGS_NONINTERACTIVE
Definition: gui.h:992
GWEN_LOGGER_LEVEL
Definition: logger.h:61
#define GWEN_GUI_INPUT_FLAGS_ALLOW_DEFAULT
Definition: gui.h:220
int GWENHYWFAR_CB GWEN_Gui_CGui_ProgressEnd(GWEN_GUI *gui, uint32_t id)
Definition: cgui.c:763
GWENHYWFAR_API int GWEN_Gui_StdPrintf(const GWEN_GUI *gui, FILE *stream, const char *fmt,...) GWEN_FORMAT(printf
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:61
#define NULL
Definition: binreloc.c:300
#define GWEN_GUI_FLAGS_PERMPASSWORDS
Definition: gui.h:998
#define GWEN_GUI_INPUT_FLAGS_NUMERIC
Definition: gui.h:215
#define GWEN_LOGDOMAIN
Definition: logger.h:32
GWENHYWFAR_API int GWEN_Gui_MessageBox(uint32_t flags, const char *title, const char *text, const char *b1, const char *b2, const char *b3, uint32_t guiid)
Definition: gui_virtual.c:342
char GWEN_Gui_CGui__readCharFromStdin(int waitFor)
Definition: cgui.c:114
int GWENHYWFAR_CB GWEN_Gui_CGui_ProgressAdvance(GWEN_GUI *gui, uint32_t id, uint64_t progress)
Definition: cgui.c:696
void GWENHYWFAR_CB GWEN_Gui_CGui_FreeData(GWEN_UNUSED void *bp, void *p)
Definition: cgui.c:103
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:42
GWENHYWFAR_API GWEN_GUI_SHOWBOX_FN GWEN_Gui_SetShowBoxFn(GWEN_GUI *gui, GWEN_GUI_SHOWBOX_FN f)
Definition: gui_virtual.c:55
#define GWEN_GUI_MSG_FLAGS_TYPE_INFO
Definition: gui.h:281
int GWEN_Gui_CProgress_End(GWEN_GUI_CPROGRESS *cp)
Definition: cprogress.c:272
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:55
#define GWEN_GUI_MSG_FLAGS_CONFIRM_BUTTON(fl)
Definition: gui.h:305
#define GWEN_GUI_MSG_FLAGS_SEVERITY_DANGEROUS
Definition: gui.h:337
GWENHYWFAR_API GWEN_GUI_PROGRESS_START_FN GWEN_Gui_SetProgressStartFn(GWEN_GUI *gui, GWEN_GUI_PROGRESS_START_FN f)
Definition: gui_virtual.c:81
GWEN_GUI_CPROGRESS * GWEN_Gui_CProgress_new(GWEN_GUI *gui, uint32_t id, uint32_t progressFlags, const char *title, const char *text, uint64_t total)
Definition: cprogress.c:28
#define GWENHYWFAR_CB
Definition: gwenhywfarapi.h:89
#define GWEN_GUI_INPUT_FLAGS_TAN
Definition: gui.h:222
#define GWEN_ERROR_GENERIC
Definition: error.h:62
int GWENHYWFAR_CB GWEN_Gui_CGui_ProgressSetTotal(GWEN_GUI *gui, uint32_t id, uint64_t total)
Definition: cgui.c:719
int GWEN_Gui_CProgress_Log(GWEN_GUI_CPROGRESS *cp, GWEN_LOGGER_LEVEL level, const char *text)
Definition: cprogress.c:239
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:89
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
void GWENHYWFAR_CB GWEN_Gui_CGui_HideBox(GWEN_GUI *gui, GWEN_UNUSED uint32_t id)
Definition: cgui.c:634
#define GWEN_ERROR_DEFAULT_VALUE
Definition: error.h:117
int GWEN_Gui_CGui__input(GWEN_UNUSED GWEN_GUI *gui, uint32_t flags, char *buffer, int minLen, int maxLen, uint32_t guiid)
Definition: cgui.c:238
GWENHYWFAR_API GWEN_GUI_PROGRESS_LOG_FN GWEN_Gui_SetProgressLogFn(GWEN_GUI *gui, GWEN_GUI_PROGRESS_LOG_FN f)
Definition: gui_virtual.c:117
#define GWEN_GUI_INPUT_FLAGS_SHOW
Definition: gui.h:213
int GWEN_Gui_CProgress_Advance(GWEN_GUI_CPROGRESS *cp, uint64_t progress)
Definition: cprogress.c:164
GWENHYWFAR_API GWEN_GUI_PROGRESS_ADVANCE_FN GWEN_Gui_SetProgressAdvanceFn(GWEN_GUI *gui, GWEN_GUI_PROGRESS_ADVANCE_FN f)
Definition: gui_virtual.c:93
GWEN_GUI * GWEN_Gui_new(void)
Definition: gui.c:99
#define GWEN_GUI_MSG_FLAGS_CONFIRM_B1
Definition: gui.h:299
GWENHYWFAR_API GWEN_GUI_INPUTBOX_FN GWEN_Gui_SetInputBoxFn(GWEN_GUI *gui, GWEN_GUI_INPUTBOX_FN f)
Definition: gui_virtual.c:42
#define ICONV_CONST
Definition: cgui.c:67
struct GWEN_GUI GWEN_GUI
Definition: gui.h:176
void GWEN_Gui_CProgress_SetTotal(GWEN_GUI_CPROGRESS *cp, uint64_t i)
Definition: cprogress.c:128
GWENHYWFAR_API GWEN_GUI_HIDEBOX_FN GWEN_Gui_SetHideBoxFn(GWEN_GUI *gui, GWEN_GUI_HIDEBOX_FN f)
Definition: gui_virtual.c:68
struct GWEN_GUI_CPROGRESS GWEN_GUI_CPROGRESS
Definition: cprogress_l.h:14
#define GWEN_INHERIT(bt, t)
Definition: inherit.h:264
void GWEN_Gui_CProgress_free(GWEN_GUI_CPROGRESS *cp)
Definition: cprogress.c:75
#define DBG_INFO(dbg_logger, format,...)
Definition: debug.h:181
GWENHYWFAR_API GWEN_GUI_PROGRESS_END_FN GWEN_Gui_SetProgressEndFn(GWEN_GUI *gui, GWEN_GUI_PROGRESS_END_FN f)
Definition: gui_virtual.c:129
#define GWEN_ERROR_USER_ABORTED
Definition: error.h:65
GWENHYWFAR_API int GWENHYWFAR_API void GWEN_Gui_GetRawText(const GWEN_GUI *gui, const char *text, GWEN_BUFFER *tbuf)
#define GWEN_INHERIT_SETDATA(bt, t, element, data, fn)
Definition: inherit.h:300
GWEN_GUI * GWEN_Gui_CGui_new(void)
Definition: cgui.c:77
uint32_t GWEN_Gui_GetFlags(const GWEN_GUI *gui)
Definition: gui.c:195
GWENHYWFAR_API GWEN_GUI_PROGRESS_SETTOTAL_FN GWEN_Gui_SetProgressSetTotalFn(GWEN_GUI *gui, GWEN_GUI_PROGRESS_SETTOTAL_FN f)
Definition: gui_virtual.c:105
GWENHYWFAR_API GWEN_GUI_MESSAGEBOX_FN GWEN_Gui_SetMessageBoxFn(GWEN_GUI *gui, GWEN_GUI_MESSAGEBOX_FN f)
Definition: gui_virtual.c:29
#define GWEN_UNUSED
uint32_t GWENHYWFAR_CB GWEN_Gui_CGui_ShowBox(GWEN_GUI *gui, GWEN_UNUSED uint32_t flags, const char *title, const char *text, GWEN_UNUSED uint32_t guiid)
Definition: cgui.c:608
const char * GWEN_Gui_GetCharSet(const GWEN_GUI *gui)
Definition: gui.c:250
#define GWEN_INHERIT_GETDATA(bt, t, element)
Definition: inherit.h:279
int GWENHYWFAR_CB GWEN_Gui_CGui_MessageBox(GWEN_GUI *gui, uint32_t flags, const char *title, const char *text, const char *b1, const char *b2, const char *b3, GWEN_UNUSED uint32_t guiid)
Definition: cgui.c:449