1 /***************************************************************************
2 begin : Fri Feb 07 2003
3 copyright : (C) 2003-2010 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 "nogui_p.h"
34
35
36
37
38 GWEN_INHERIT(GWEN_GUI, GWEN_GUI_NOGUI)
39
40
41
42 /* ------------------------------------------------------------------------------------------------
43 * forward declarations
44 * ------------------------------------------------------------------------------------------------
45 */
46
47 static void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p);
48
49 static int GWENHYWFAR_CB _messageBox(GWEN_GUI *gui,
50 uint32_t flags,
51 const char *title,
52 const char *text,
53 const char *b1,
54 const char *b2,
55 const char *b3,
56 uint32_t guiid);
57
58 static int GWENHYWFAR_CB _inputBox(GWEN_GUI *gui,
59 uint32_t flags,
60 const char *title,
61 const char *text,
62 char *buffer,
63 int minLen,
64 int maxLen,
65 uint32_t guiid);
66
67
68 static uint32_t GWENHYWFAR_CB _showBox(GWEN_GUI *gui,
69 uint32_t flags,
70 const char *title,
71 const char *text,
72 uint32_t guiid);
73 static void GWENHYWFAR_CB _hideBox(GWEN_GUI *gui, uint32_t id);
74
75
76 static uint32_t GWENHYWFAR_CB _progressStart(GWEN_GUI *gui,
77 uint32_t progressFlags,
78 const char *title,
79 const char *text,
80 uint64_t total,
81 uint32_t guiid);
82 static int GWENHYWFAR_CB _progressAdvance(GWEN_GUI *gui, uint32_t pid, uint64_t progress);
83 static int GWENHYWFAR_CB _progressSetTotal(GWEN_GUI *gui, uint32_t pid, uint64_t total);
84 static int GWENHYWFAR_CB _progressLog(GWEN_GUI *gui, uint32_t pid, GWEN_LOGGER_LEVEL level, const char *text);
85 static int GWENHYWFAR_CB _progressEnd(GWEN_GUI *gui, uint32_t pid);
86
87 static int GWENHYWFAR_CB _print(GWEN_GUI *gui,
88 const char *docTitle,
89 const char *docType,
90 const char *descr,
91 const char *text,
92 uint32_t guiid);
93
94
95 static int GWENHYWFAR_CB _getPassword(GWEN_GUI *gui,
96 uint32_t flags,
97 const char *token,
98 const char *title,
99 const char *text,
100 char *buffer,
101 int minLen,
102 int maxLen,
103 GWEN_GUI_PASSWORD_METHOD methodId,
104 GWEN_DB_NODE *methodParams,
105 uint32_t guiid);
106
107 static int GWENHYWFAR_CB _setPasswordStatus(GWEN_GUI *gui,
108 const char *token,
109 const char *pin,
110 GWEN_GUI_PASSWORD_STATUS status,
111 GWEN_UNUSED uint32_t guiid);
112
113 static int GWENHYWFAR_CB _logHook(GWEN_GUI *gui, const char *logDomain, GWEN_LOGGER_LEVEL priority, const char *s);
114
115
116 static int GWENHYWFAR_CB _waitForSockets(GWEN_GUI *gui,
117 GWEN_SOCKET_LIST2 *readSockets,
118 GWEN_SOCKET_LIST2 *writeSockets,
119 int msecs,
120 uint32_t guiid);
121
122 static int GWENHYWFAR_CB _checkCert(GWEN_GUI *gui,
123 const GWEN_SSLCERTDESCR *cert,
124 GWEN_SYNCIO *sio,
125 uint32_t guiid);
126
127 static int GWENHYWFAR_CB _keyDataFromTextOpenSsl(GWEN_GUI *gui,
128 const char *text,
129 unsigned char *buffer,
130 unsigned int bufLength);
131
132
133 static int GWENHYWFAR_CB _execDialog(GWEN_GUI *gui,
134 GWEN_DIALOG *dlg,
135 uint32_t guiid);
136
137
138 static int GWENHYWFAR_CB _openDialog(GWEN_GUI *gui,
139 GWEN_DIALOG *dlg,
140 uint32_t guiid);
141
142 static int GWENHYWFAR_CB _closeDialog(GWEN_GUI *gui, GWEN_DIALOG *dlg);
143
144 static int GWENHYWFAR_CB _runDialog(GWEN_GUI *gui, GWEN_DIALOG *dlg, int timeout);
145
146
147 static int GWENHYWFAR_CB _readDialogPrefs(GWEN_GUI *gui,
148 const char *groupName,
149 const char *altName,
150 GWEN_DB_NODE **pDb);
151
152 static int GWENHYWFAR_CB _writeDialogPrefs(GWEN_GUI *gui,
153 const char *groupName,
154 GWEN_DB_NODE *db);
155
156
157 static int GWENHYWFAR_CB _getFilename(GWEN_GUI *gui,
158 const char *caption,
159 GWEN_GUI_FILENAME_TYPE fnt,
160 uint32_t flags,
161 const char *patterns,
162 GWEN_BUFFER *pathBuffer,
163 uint32_t guiid);
164
165
166 static int GWENHYWFAR_CB _getSyncio(GWEN_GUI *gui,
167 const char *url,
168 const char *defaultProto,
169 int defaultPort,
170 GWEN_SYNCIO **pSio);
171
172
173
174 /* ------------------------------------------------------------------------------------------------
175 * code
176 * ------------------------------------------------------------------------------------------------
177 */
178
179
180
181
GWEN_NoGui_new(void)182 GWEN_GUI *GWEN_NoGui_new(void)
183 {
184 GWEN_GUI *gui;
185 GWEN_GUI_NOGUI *xgui;
186
187 gui=GWEN_Gui_new();
188 GWEN_NEW_OBJECT(GWEN_GUI_NOGUI, xgui);
189
190 GWEN_INHERIT_SETDATA(GWEN_GUI, GWEN_GUI_NOGUI, gui, xgui, _freeData);
191
192 xgui->messageBoxFn=GWEN_Gui_SetMessageBoxFn(gui, _messageBox);
193 xgui->inputBoxFn=GWEN_Gui_SetInputBoxFn(gui, _inputBox);
194 xgui->showBoxFn=GWEN_Gui_SetShowBoxFn(gui, _showBox);
195 xgui->hideBoxFn=GWEN_Gui_SetHideBoxFn(gui, _hideBox);
196 xgui->progressStartFn=GWEN_Gui_SetProgressStartFn(gui, _progressStart);
197 xgui->progressAdvanceFn=GWEN_Gui_SetProgressAdvanceFn(gui, _progressAdvance);
198 xgui->progressSetTotalFn=GWEN_Gui_SetProgressSetTotalFn(gui, _progressSetTotal);
199 xgui->progressLogFn=GWEN_Gui_SetProgressLogFn(gui, _progressLog);
200 xgui->progressEndFn=GWEN_Gui_SetProgressEndFn(gui, _progressEnd);
201 xgui->printFn=GWEN_Gui_SetPrintFn(gui, _print);
202 xgui->getPasswordFn=GWEN_Gui_SetGetPasswordFn(gui, _getPassword);
203 xgui->setPasswordStatusFn=GWEN_Gui_SetSetPasswordStatusFn(gui, _setPasswordStatus);
204 xgui->logHookFn=GWEN_Gui_SetLogHookFn(gui, _logHook);
205 xgui->waitForSocketsFn=GWEN_Gui_SetWaitForSocketsFn(gui, _waitForSockets);
206 xgui->checkCertFn=GWEN_Gui_SetCheckCertFn(gui, _checkCert);
207 xgui->keyDataFromTextOpenSslFn=GWEN_Gui_SetKeyDataFromTextOpenSslFn(gui, _keyDataFromTextOpenSsl);
208 xgui->execDialogFn=GWEN_Gui_SetExecDialogFn(gui, _execDialog);
209 xgui->openDialogFn=GWEN_Gui_SetOpenDialogFn(gui, _openDialog);
210 xgui->closeDialogFn=GWEN_Gui_SetCloseDialogFn(gui, _closeDialog);
211 xgui->runDialogFn=GWEN_Gui_SetRunDialogFn(gui, _runDialog);
212 xgui->readDialogPrefsFn=GWEN_Gui_SetReadDialogPrefsFn(gui, _readDialogPrefs);
213 xgui->writeDialogPrefsFn=GWEN_Gui_SetWriteDialogPrefsFn(gui, _writeDialogPrefs);
214 xgui->getFileNameFn=GWEN_Gui_SetGetFileNameFn(gui, _getFilename);
215 xgui->getSyncIoFn=GWEN_Gui_SetGetSyncIoFn(gui, _getSyncio);
216
217 return gui;
218 }
219
220
221
_freeData(GWEN_UNUSED void * bp,void * p)222 void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p)
223 {
224 GWEN_GUI_NOGUI *xgui;
225
226 xgui=(GWEN_GUI_NOGUI*) p;
227
228 GWEN_FREE_OBJECT(xgui);
229 }
230
231
232
_messageBox(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED uint32_t flags,GWEN_UNUSED const char * title,GWEN_UNUSED const char * text,GWEN_UNUSED const char * b1,GWEN_UNUSED const char * b2,GWEN_UNUSED const char * b3,GWEN_UNUSED uint32_t guiid)233 int GWENHYWFAR_CB _messageBox(GWEN_UNUSED GWEN_GUI *gui,
234 GWEN_UNUSED uint32_t flags,
235 GWEN_UNUSED const char *title,
236 GWEN_UNUSED const char *text,
237 GWEN_UNUSED const char *b1,
238 GWEN_UNUSED const char *b2,
239 GWEN_UNUSED const char *b3,
240 GWEN_UNUSED uint32_t guiid)
241 {
242 return 0;
243 }
244
245
246
_inputBox(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED uint32_t flags,GWEN_UNUSED const char * title,GWEN_UNUSED const char * text,GWEN_UNUSED char * buffer,GWEN_UNUSED int minLen,GWEN_UNUSED int maxLen,GWEN_UNUSED uint32_t guiid)247 int GWENHYWFAR_CB _inputBox(GWEN_UNUSED GWEN_GUI *gui,
248 GWEN_UNUSED uint32_t flags,
249 GWEN_UNUSED const char *title,
250 GWEN_UNUSED const char *text,
251 GWEN_UNUSED char *buffer,
252 GWEN_UNUSED int minLen,
253 GWEN_UNUSED int maxLen,
254 GWEN_UNUSED uint32_t guiid)
255 {
256 return 0;
257 }
258
259
260
_showBox(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED uint32_t flags,GWEN_UNUSED const char * title,GWEN_UNUSED const char * text,GWEN_UNUSED uint32_t guiid)261 uint32_t GWENHYWFAR_CB _showBox(GWEN_UNUSED GWEN_GUI *gui,
262 GWEN_UNUSED uint32_t flags,
263 GWEN_UNUSED const char *title,
264 GWEN_UNUSED const char *text,
265 GWEN_UNUSED uint32_t guiid)
266 {
267 return 0;
268 }
269
270
271
_hideBox(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED uint32_t id)272 void GWENHYWFAR_CB _hideBox(GWEN_UNUSED GWEN_GUI *gui, GWEN_UNUSED uint32_t id)
273 {
274 }
275
276
277
_progressStart(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED uint32_t progressFlags,GWEN_UNUSED const char * title,GWEN_UNUSED const char * text,GWEN_UNUSED uint64_t total,GWEN_UNUSED uint32_t guiid)278 uint32_t GWENHYWFAR_CB _progressStart(GWEN_UNUSED GWEN_GUI *gui,
279 GWEN_UNUSED uint32_t progressFlags,
280 GWEN_UNUSED const char *title,
281 GWEN_UNUSED const char *text,
282 GWEN_UNUSED uint64_t total,
283 GWEN_UNUSED uint32_t guiid)
284 {
285 return 0;
286 }
287
288
289
_progressAdvance(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED uint32_t pid,GWEN_UNUSED uint64_t progress)290 int GWENHYWFAR_CB _progressAdvance(GWEN_UNUSED GWEN_GUI *gui,
291 GWEN_UNUSED uint32_t pid,
292 GWEN_UNUSED uint64_t progress)
293 {
294 return 0;
295 }
296
297
298
_progressSetTotal(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED uint32_t pid,GWEN_UNUSED uint64_t total)299 int GWENHYWFAR_CB _progressSetTotal(GWEN_UNUSED GWEN_GUI *gui,
300 GWEN_UNUSED uint32_t pid,
301 GWEN_UNUSED uint64_t total)
302 {
303 return 0;
304 }
305
306
307
_progressLog(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED uint32_t pid,GWEN_UNUSED GWEN_LOGGER_LEVEL level,GWEN_UNUSED const char * text)308 int GWENHYWFAR_CB _progressLog(GWEN_UNUSED GWEN_GUI *gui,
309 GWEN_UNUSED uint32_t pid,
310 GWEN_UNUSED GWEN_LOGGER_LEVEL level,
311 GWEN_UNUSED const char *text)
312 {
313 return 0;
314 }
315
316
317
_progressEnd(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED uint32_t pid)318 int GWENHYWFAR_CB _progressEnd(GWEN_UNUSED GWEN_GUI *gui,
319 GWEN_UNUSED uint32_t pid)
320 {
321 return 0;
322 }
323
324
325
_print(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED const char * docTitle,GWEN_UNUSED const char * docType,GWEN_UNUSED const char * descr,GWEN_UNUSED const char * text,GWEN_UNUSED uint32_t guiid)326 int GWENHYWFAR_CB _print(GWEN_UNUSED GWEN_GUI *gui,
327 GWEN_UNUSED const char *docTitle,
328 GWEN_UNUSED const char *docType,
329 GWEN_UNUSED const char *descr,
330 GWEN_UNUSED const char *text,
331 GWEN_UNUSED uint32_t guiid)
332 {
333 return 0;
334 }
335
336
337
_getPassword(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED uint32_t flags,GWEN_UNUSED const char * token,GWEN_UNUSED const char * title,GWEN_UNUSED const char * text,GWEN_UNUSED char * buffer,GWEN_UNUSED int minLen,GWEN_UNUSED int maxLen,GWEN_UNUSED GWEN_GUI_PASSWORD_METHOD methodId,GWEN_UNUSED GWEN_DB_NODE * methodParams,GWEN_UNUSED uint32_t guiid)338 int GWENHYWFAR_CB _getPassword(GWEN_UNUSED GWEN_GUI *gui,
339 GWEN_UNUSED uint32_t flags,
340 GWEN_UNUSED const char *token,
341 GWEN_UNUSED const char *title,
342 GWEN_UNUSED const char *text,
343 GWEN_UNUSED char *buffer,
344 GWEN_UNUSED int minLen,
345 GWEN_UNUSED int maxLen,
346 GWEN_UNUSED GWEN_GUI_PASSWORD_METHOD methodId,
347 GWEN_UNUSED GWEN_DB_NODE *methodParams,
348 GWEN_UNUSED uint32_t guiid)
349 {
350 return 0;
351 }
352
353
354
_setPasswordStatus(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED const char * token,GWEN_UNUSED const char * pin,GWEN_UNUSED GWEN_GUI_PASSWORD_STATUS status,GWEN_UNUSED uint32_t guiid)355 int GWENHYWFAR_CB _setPasswordStatus(GWEN_UNUSED GWEN_GUI *gui,
356 GWEN_UNUSED const char *token,
357 GWEN_UNUSED const char *pin,
358 GWEN_UNUSED GWEN_GUI_PASSWORD_STATUS status,
359 GWEN_UNUSED uint32_t guiid)
360 {
361 return 0;
362 }
363
364
365
_logHook(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED const char * logDomain,GWEN_UNUSED GWEN_LOGGER_LEVEL priority,GWEN_UNUSED const char * s)366 int GWENHYWFAR_CB _logHook(GWEN_UNUSED GWEN_GUI *gui,
367 GWEN_UNUSED const char *logDomain,
368 GWEN_UNUSED GWEN_LOGGER_LEVEL priority,
369 GWEN_UNUSED const char *s)
370 {
371 return 1;
372 }
373
374
375
_waitForSockets(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED GWEN_SOCKET_LIST2 * readSockets,GWEN_UNUSED GWEN_SOCKET_LIST2 * writeSockets,GWEN_UNUSED int msecs,GWEN_UNUSED uint32_t guiid)376 int GWENHYWFAR_CB _waitForSockets(GWEN_UNUSED GWEN_GUI *gui,
377 GWEN_UNUSED GWEN_SOCKET_LIST2 *readSockets,
378 GWEN_UNUSED GWEN_SOCKET_LIST2 *writeSockets,
379 GWEN_UNUSED int msecs,
380 GWEN_UNUSED uint32_t guiid)
381 {
382 return 0;
383 }
384
385
386
_checkCert(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED const GWEN_SSLCERTDESCR * cert,GWEN_UNUSED GWEN_SYNCIO * sio,GWEN_UNUSED uint32_t guiid)387 int GWENHYWFAR_CB _checkCert(GWEN_UNUSED GWEN_GUI *gui,
388 GWEN_UNUSED const GWEN_SSLCERTDESCR *cert,
389 GWEN_UNUSED GWEN_SYNCIO *sio,
390 GWEN_UNUSED uint32_t guiid)
391 {
392 return 0;
393 }
394
395
396
_keyDataFromTextOpenSsl(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED const char * text,GWEN_UNUSED unsigned char * buffer,GWEN_UNUSED unsigned int bufLength)397 int GWENHYWFAR_CB _keyDataFromTextOpenSsl(GWEN_UNUSED GWEN_GUI *gui,
398 GWEN_UNUSED const char *text,
399 GWEN_UNUSED unsigned char *buffer,
400 GWEN_UNUSED unsigned int bufLength)
401 {
402 return 0;
403 }
404
405
406
_execDialog(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED GWEN_DIALOG * dlg,GWEN_UNUSED uint32_t guiid)407 int GWENHYWFAR_CB _execDialog(GWEN_UNUSED GWEN_GUI *gui,
408 GWEN_UNUSED GWEN_DIALOG *dlg,
409 GWEN_UNUSED uint32_t guiid)
410 {
411 return 0;
412 }
413
414
415
_openDialog(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED GWEN_DIALOG * dlg,GWEN_UNUSED uint32_t guiid)416 int GWENHYWFAR_CB _openDialog(GWEN_UNUSED GWEN_GUI *gui,
417 GWEN_UNUSED GWEN_DIALOG *dlg,
418 GWEN_UNUSED uint32_t guiid)
419 {
420 return 0;
421 }
422
423
424
_closeDialog(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED GWEN_DIALOG * dlg)425 int GWENHYWFAR_CB _closeDialog(GWEN_UNUSED GWEN_GUI *gui,
426 GWEN_UNUSED GWEN_DIALOG *dlg)
427 {
428 return 0;
429 }
430
431
432
_runDialog(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED GWEN_DIALOG * dlg,GWEN_UNUSED int timeout)433 int GWENHYWFAR_CB _runDialog(GWEN_UNUSED GWEN_GUI *gui,
434 GWEN_UNUSED GWEN_DIALOG *dlg,
435 GWEN_UNUSED int timeout)
436 {
437 return 0;
438 }
439
440
441
_readDialogPrefs(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED const char * groupName,GWEN_UNUSED const char * altName,GWEN_UNUSED GWEN_DB_NODE ** pDb)442 int GWENHYWFAR_CB _readDialogPrefs(GWEN_UNUSED GWEN_GUI *gui,
443 GWEN_UNUSED const char *groupName,
444 GWEN_UNUSED const char *altName,
445 GWEN_UNUSED GWEN_DB_NODE **pDb)
446 {
447 return 0;
448 }
449
450
451
_writeDialogPrefs(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED const char * groupName,GWEN_UNUSED GWEN_DB_NODE * db)452 int GWENHYWFAR_CB _writeDialogPrefs(GWEN_UNUSED GWEN_GUI *gui,
453 GWEN_UNUSED const char *groupName,
454 GWEN_UNUSED GWEN_DB_NODE *db)
455 {
456 return 0;
457 }
458
459
460
_getFilename(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED const char * caption,GWEN_UNUSED GWEN_GUI_FILENAME_TYPE fnt,GWEN_UNUSED uint32_t flags,GWEN_UNUSED const char * patterns,GWEN_UNUSED GWEN_BUFFER * pathBuffer,GWEN_UNUSED uint32_t guiid)461 int GWENHYWFAR_CB _getFilename(GWEN_UNUSED GWEN_GUI *gui,
462 GWEN_UNUSED const char *caption,
463 GWEN_UNUSED GWEN_GUI_FILENAME_TYPE fnt,
464 GWEN_UNUSED uint32_t flags,
465 GWEN_UNUSED const char *patterns,
466 GWEN_UNUSED GWEN_BUFFER *pathBuffer,
467 GWEN_UNUSED uint32_t guiid)
468 {
469 return 0;
470 }
471
472
473
_getSyncio(GWEN_UNUSED GWEN_GUI * gui,GWEN_UNUSED const char * url,GWEN_UNUSED const char * defaultProto,GWEN_UNUSED int defaultPort,GWEN_UNUSED GWEN_SYNCIO ** pSio)474 int GWENHYWFAR_CB _getSyncio(GWEN_UNUSED GWEN_GUI *gui,
475 GWEN_UNUSED const char *url,
476 GWEN_UNUSED const char *defaultProto,
477 GWEN_UNUSED int defaultPort,
478 GWEN_UNUSED GWEN_SYNCIO **pSio)
479 {
480 return 0;
481 }
482
483
484
485
486
487