1 /*
2 NETWIB
3 Network library
4 Copyright(c) 1999-2010 Laurent Constantin
5 -----
6
7 Main server : http://www.laurentconstantin.com/
8 Backup server : http://laurentconstantin.free.fr/
9 [my current email address is on the web servers]
10
11 -----
12 This file is part of Netwib.
13
14 Netwib is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License version 3
16 as published by the Free Software Foundation.
17
18 Netwib is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details (http://www.gnu.org/).
22
23 ------------------------------------------------------------------------
24 */
25
26 #include <netwib/inc/maininc.h>
27
28 /*-------------------------------------------------------------*/
netwib_buf_append_decodetype(netwib_decodetype decodetype,netwib_buf * pbuf)29 netwib_err netwib_buf_append_decodetype(netwib_decodetype decodetype,
30 netwib_buf *pbuf)
31 {
32 netwib_conststring pc;
33
34 pc = NULL;
35
36 switch (decodetype) {
37 case NETWIB_DECODETYPE_DATA:
38 pc = "exact data";
39 break;
40 case NETWIB_DECODETYPE_HEXA:
41 pc = "hexadecimal";
42 break;
43 case NETWIB_DECODETYPE_MIXED:
44 pc = "mixed";
45 break;
46 case NETWIB_DECODETYPE_BASE64:
47 pc = "base64";
48 break;
49 default :
50 return(NETWIB_ERR_PAINVALIDTYPE);
51 }
52
53 netwib_er(netwib_buf_append_string(pc, pbuf));
54
55 return(NETWIB_ERR_OK);
56 }
57
58 /*-------------------------------------------------------------*/
59 #define NETWIB_PRIV_DECODETYPE_MAX 10
netwib_decodetype_init_kbd(netwib_constbuf * pmessage,netwib_decodetype defaultdecodetype,netwib_decodetype * pdecodetype)60 netwib_err netwib_decodetype_init_kbd(netwib_constbuf *pmessage,
61 netwib_decodetype defaultdecodetype,
62 netwib_decodetype *pdecodetype)
63 {
64 netwib_decodetype array[NETWIB_PRIV_DECODETYPE_MAX];
65 netwib_buf msg, buf;
66 netwib_uint32 i, choice, defaultchoice;
67
68 netwib_er(netwib_buf_init_mallocdefault(&buf));
69 if (pmessage != NULL) {
70 netwib_er(netwib_buf_append_buf(pmessage, &buf));
71 netwib_er(netwib_buf_append_string("\n", &buf));
72 }
73
74 i = 0;
75 defaultchoice = NETWIB_UINT32_INIT_KBD_NODEF;
76
77 #define netwib_decodetype_li(ot) {netwib_er(netwib_buf_append_fmt(&buf, " %{r 2;uint32} - ", i)); netwib_er(netwib_buf_append_decodetype(ot, &buf)); netwib_er(netwib_buf_append_fmt(&buf, "\n")); if (defaultdecodetype == ot) defaultchoice = i; array[i++] = ot; }
78
79 netwib_decodetype_li(NETWIB_DECODETYPE_DATA);
80 netwib_decodetype_li(NETWIB_DECODETYPE_HEXA);
81 netwib_decodetype_li(NETWIB_DECODETYPE_MIXED);
82 netwib_decodetype_li(NETWIB_DECODETYPE_BASE64);
83
84 if (i >= NETWIB_PRIV_DECODETYPE_MAX) {
85 return(NETWIB_ERR_LOINTERNALERROR);
86 }
87 netwib_er(netwib_buf_display(&buf, NETWIB_ENCODETYPE_DATA));
88 netwib_er(netwib_buf_close(&buf));
89
90 if (defaultdecodetype == NETWIB_DECODETYPE_INIT_KBD_NODEF) {
91 defaultchoice = NETWIB_UINT32_INIT_KBD_NODEF;
92 }
93
94 netwib_er(netwib_buf_init_ext_string("Your choice", &msg));
95 netwib_er(netwib_uint32_init_kbd(&msg, 0, i-1, defaultchoice, &choice));
96
97 if (pdecodetype != NULL) *pdecodetype = (netwib_decodetype)choice;
98 return(NETWIB_ERR_OK);
99 }
100