Virtual machine Management Terminal User Interface
Revision | 475b6623b10fa983e29a01be72907cfdb30d8b57 (tree) |
---|---|
Zeit | 2023-06-20 22:34:50 |
Autor | Koine Yuusuke(koinec) <koinec@user...> |
Commiter | Koine Yuusuke(koinec) |
Improve TuiKey_ChangeMode()
@@ -29,6 +29,26 @@ | ||
29 | 29 | #define VMTUI_SRC_ |
30 | 30 | #include "vmtui.h" |
31 | 31 | |
32 | +/* ===========================================================================*/ | |
33 | +VMTUI_HVCMD_EXTERN | |
34 | +int | |
35 | + HvCmd_Connect_InputPasswordHandler( | |
36 | + int i_hvisor, | |
37 | + int i_guest, | |
38 | + int i_request, | |
39 | + Byte b_option, | |
40 | + int i_len, | |
41 | + char *pstr_password ) | |
42 | +{ | |
43 | + | |
44 | + if( i_len >= HVISOR_SSH_MAXLEN_PASSWORD ) { | |
45 | + TuiKey_ChangeMode( TUIKEY_MODE_VMLIST, REQUEST_CMD_NONE, 0x00, 0x00, | |
46 | + NULL, 0x00, TUIKEY_MODE_NONE, NULL ); | |
47 | + return 0x00; | |
48 | + } | |
49 | + | |
50 | + return HvCmd_Connect( i_hvisor, b_option, pstr_password ); | |
51 | +} | |
32 | 52 | |
33 | 53 | /* ===========================================================================*/ |
34 | 54 | VMTUI_HVCMD_EXTERN |
@@ -77,7 +97,9 @@ int | ||
77 | 97 | if( HVCMD_CONNECT_PHASE_REQUEST == b_phase ) { |
78 | 98 | if(( 0x01 == b_nosshpasswd ) && ( HVISOR_CON_LOCALHOST != b_connection )) { |
79 | 99 | TuiKey_ChangeMode( TUIKEY_MODE_INPUTPASSWD, REQUEST_CMD_HV_CONNECT, |
80 | - i_hvisor, GUEST_ID_NONE, HVCMD_CONNECT_PHASE_SSHPASS_SET, | |
100 | + i_hvisor, GUEST_ID_NONE, | |
101 | + HvCmd_Connect_InputPasswordHandler, | |
102 | + HVCMD_CONNECT_PHASE_SSHPASS_SET, TUIKEY_MODE_VMLIST, | |
81 | 103 | "Input SSH PassWord / PassPhrase ? " ); |
82 | 104 | return 0x00; |
83 | 105 | } |
@@ -92,7 +114,9 @@ int | ||
92 | 114 | if( HVCMD_CONNECT_PHASE_SUDOPASS_REQ == b_phase ) { |
93 | 115 | if( 0x01 == b_nosudopasswd ) { |
94 | 116 | TuiKey_ChangeMode( TUIKEY_MODE_INPUTPASSWD, REQUEST_CMD_HV_CONNECT, |
95 | - i_hvisor, GUEST_ID_NONE, HVCMD_CONNECT_PHASE_SUDOPASS_SET, | |
117 | + i_hvisor, GUEST_ID_NONE, | |
118 | + HvCmd_Connect_InputPasswordHandler, | |
119 | + HVCMD_CONNECT_PHASE_SUDOPASS_SET, TUIKEY_MODE_VMLIST, | |
96 | 120 | "Input Login User's Password for sudo cmd. ? " ); |
97 | 121 | return 0x00; |
98 | 122 | } |
@@ -105,7 +129,8 @@ int | ||
105 | 129 | b_phase = HVCMD_CONNECT_PHASE_CONNECTSTART; |
106 | 130 | } |
107 | 131 | |
108 | - TuiKey_ChangeMode( TUIKEY_MODE_VMLIST, REQUEST_CMD_NONE, 0x00, 0x00, 0x00, NULL ); | |
132 | + TuiKey_ChangeMode( TUIKEY_MODE_VMLIST, REQUEST_CMD_NONE, 0x00, 0x00, NULL, 0x00, | |
133 | + TUIKEY_MODE_NONE, NULL ); | |
109 | 134 | i_ret = ReqCtl_CreateRequest( REQUEST_CMD_HV_CONNECT, i_hvisor, GUEST_ID_NONE, NULL ); |
110 | 135 | |
111 | 136 | return i_ret; |
@@ -35,6 +35,9 @@ | ||
35 | 35 | #else |
36 | 36 | #define VMTUI_HVCMD_EXTERN extern |
37 | 37 | #endif |
38 | +VMTUI_HVCMD_EXTERN int HvCmd_Connect_InputPasswordHandler( | |
39 | + int i_hvisor, int i_guest, int i_request, Byte b_option, | |
40 | + int i_len, char *pstr_password ); | |
38 | 41 | VMTUI_HVCMD_EXTERN int HvCmd_Connect( int i_hvisor, Byte b_phase, char *pstr_passwd ); |
39 | 42 | #define HVCMD_CONNECT_PHASE_NONE 0x00 |
40 | 43 | #define HVCMD_CONNECT_PHASE_REQUEST 0x01 |
@@ -38,7 +38,8 @@ int | ||
38 | 38 | switch( i_key ) { |
39 | 39 | case NCURSES_KEY_ENTER: |
40 | 40 | TuiKey_ChangeMode( TUIKEY_MODE_VMLIST, REQUEST_CMD_NONE, |
41 | - HVISOR_ID_NONE, GUEST_ID_NONE, 0x00, NULL ); | |
41 | + HVISOR_ID_NONE, GUEST_ID_NONE, NULL, 0x00, | |
42 | + TUIKEY_MODE_NONE, NULL ); | |
42 | 43 | break; |
43 | 44 | } |
44 | 45 |
@@ -38,7 +38,8 @@ int | ||
38 | 38 | switch( i_key ) { |
39 | 39 | case NCURSES_KEY_ENTER: |
40 | 40 | TuiKey_ChangeMode( TUIKEY_MODE_VMLIST, REQUEST_CMD_NONE, |
41 | - HVISOR_ID_NONE, GUEST_ID_NONE, 0x00, NULL ); | |
41 | + HVISOR_ID_NONE, GUEST_ID_NONE, NULL, 0x00, | |
42 | + TUIKEY_MODE_NONE, NULL ); | |
42 | 43 | break; |
43 | 44 | } |
44 | 45 |
@@ -41,7 +41,8 @@ int | ||
41 | 41 | switch( i_key ) { |
42 | 42 | case NCURSES_KEY_ENTER: |
43 | 43 | TuiKey_ChangeMode( TUIKEY_MODE_VMLIST, REQUEST_CMD_NONE, |
44 | - HVISOR_ID_NONE, GUEST_ID_NONE, 0x00, NULL ); | |
44 | + HVISOR_ID_NONE, GUEST_ID_NONE, NULL, 0x00, | |
45 | + TUIKEY_MODE_NONE, NULL ); | |
45 | 46 | break; |
46 | 47 | case 'j': |
47 | 48 | i_maxlines = TextBuf_GetMaxLine( <_guest.t_textbuf ); |
@@ -40,7 +40,8 @@ int | ||
40 | 40 | switch( i_key ) { |
41 | 41 | case NCURSES_KEY_ENTER: |
42 | 42 | TuiKey_ChangeMode( TUIKEY_MODE_VMLIST, REQUEST_CMD_NONE, |
43 | - HVISOR_ID_NONE, GUEST_ID_NONE, 0x00, NULL ); | |
43 | + HVISOR_ID_NONE, GUEST_ID_NONE, NULL, 0x00, | |
44 | + TUIKEY_MODE_NONE, NULL ); | |
44 | 45 | break; |
45 | 46 | case 'j': |
46 | 47 | i_max = TextBuf_GetMaxLine( <_help.t_textbuf ) - lt_help.i_line_start; |
@@ -40,7 +40,8 @@ int | ||
40 | 40 | switch( i_key ) { |
41 | 41 | case NCURSES_KEY_ENTER: |
42 | 42 | TuiKey_ChangeMode( TUIKEY_MODE_VMLIST, REQUEST_CMD_NONE, |
43 | - HVISOR_ID_NONE, GUEST_ID_NONE, 0x00, NULL ); | |
43 | + HVISOR_ID_NONE, GUEST_ID_NONE, NULL, 0x00, | |
44 | + TUIKEY_MODE_NONE, NULL ); | |
44 | 45 | break; |
45 | 46 | case 'j': |
46 | 47 | i_maxlines = TextBuf_GetMaxLine( <_hvisor.t_textbuf ); |
@@ -162,18 +162,22 @@ char * | ||
162 | 162 | VMTUI_TUIKEY_EXTERN |
163 | 163 | int |
164 | 164 | TuiKey_ChangeMode( |
165 | - int i_mode, | |
166 | - Byte b_reqcmd, | |
167 | - int i_hvisor, | |
168 | - int i_guest, | |
169 | - Byte b_option, | |
170 | - char *pstr_msg ) | |
165 | + int i_mode, | |
166 | + Byte b_reqcmd, | |
167 | + int i_hvisor, | |
168 | + int i_guest, | |
169 | + InputStrFunction fp_handler, | |
170 | + Byte b_option, | |
171 | + int i_retmode, | |
172 | + char *pstr_msg ) | |
171 | 173 | { |
172 | 174 | gi_keymode = i_mode; |
173 | 175 | |
174 | 176 | gt_input.b_reqcmd = b_reqcmd; |
175 | 177 | gt_input.i_hvisor = i_hvisor; |
176 | 178 | gt_input.i_guest = i_guest; |
179 | + gt_input.fp_inputstr = fp_handler; | |
180 | + gt_input.i_retmode = i_retmode; | |
177 | 181 | |
178 | 182 | if( TUIKEY_MODE_INPUTSTR == i_mode ) { |
179 | 183 | gt_input.i_inputlen = 0; |
@@ -256,21 +260,17 @@ int | ||
256 | 260 | } |
257 | 261 | } |
258 | 262 | else if(( KEY_ENTER == i_key) || ( 10 == i_key )) { |
259 | - if( REQUEST_CMD_HV_CONNECT == gt_input.b_reqcmd ) { | |
260 | - if( gt_input.i_inputlen >= HVISOR_SSH_MAXLEN_PASSWORD ) { | |
261 | - // Error | |
262 | - TuiKey_ChangeMode( TUIKEY_MODE_VMLIST, REQUEST_CMD_NONE, | |
263 | - 0x00, 0x00, 0x00, NULL ); | |
264 | - } | |
265 | - else { | |
266 | - HvCmd_Connect( gt_input.i_hvisor, gt_input.b_option, gt_input.str_input ); | |
267 | - } | |
263 | + if( NULL != gt_input.fp_inputstr ) { | |
264 | + gt_input.fp_inputstr( gt_input.i_hvisor, gt_input.i_guest, | |
265 | + gt_input.b_reqcmd, gt_input.b_option, | |
266 | + gt_input.i_inputlen, gt_input.str_input ); | |
268 | 267 | } |
269 | 268 | } |
270 | 269 | // KEY_ESC |
271 | 270 | else if( 27 == i_key ) { |
272 | - TuiKey_ChangeMode( TUIKEY_MODE_VMLIST, REQUEST_CMD_NONE, | |
273 | - 0x00, 0x00, 0x00, NULL ); | |
271 | + // Return mode --- | |
272 | + TuiKey_ChangeMode( gt_input.i_retmode, REQUEST_CMD_NONE, | |
273 | + 0x00, 0x00, NULL, 0x00, TUIKEY_MODE_NONE, NULL ); | |
274 | 274 | } |
275 | 275 | else if( KEY_BACKSPACE == i_key ) { |
276 | 276 | if( 0 < gt_input.i_inputlen ) { |
@@ -297,8 +297,9 @@ int | ||
297 | 297 | { i_ret = 0x01; } |
298 | 298 | } |
299 | 299 | |
300 | - TuiKey_ChangeMode( TUIKEY_MODE_VMLIST, REQUEST_CMD_NONE, | |
301 | - 0x00, 0x00, 0x00, NULL ); | |
300 | + // Return mode --- | |
301 | + TuiKey_ChangeMode( gt_input.i_retmode, REQUEST_CMD_NONE, | |
302 | + 0x00, 0x00, NULL, 0x00, TUIKEY_MODE_NONE, NULL ); | |
302 | 303 | |
303 | 304 | return i_ret; |
304 | 305 | } |
@@ -370,7 +371,8 @@ int | ||
370 | 371 | memset( >_input, 0x00, sizeof( TuiKey_InputLine ) ); |
371 | 372 | |
372 | 373 | TuiKey_ChangeMode( TUIKEY_MODE_VMLIST, REQUEST_ID_NONE, |
373 | - HVISOR_ID_NONE, GUEST_ID_NONE, 0x00, NULL ); | |
374 | + HVISOR_ID_NONE, GUEST_ID_NONE, NULL, 0x00, | |
375 | + TUIKEY_MODE_NONE, NULL ); | |
374 | 376 | |
375 | 377 | return 0x00; |
376 | 378 | } |
@@ -30,6 +30,9 @@ | ||
30 | 30 | |
31 | 31 | #include "vmtui.h" |
32 | 32 | |
33 | +typedef int (* KeyEventFunction)( int i_hvisor, int i_guest, int i_option ); | |
34 | +typedef int (* InputStrFunction)( int i_hvisor, int i_guest, int i_request, Byte b_option, int i_len, char *pstr_input ); | |
35 | + | |
33 | 36 | #ifdef VMTUI_SRC_TUIKEY |
34 | 37 | #define VMTUI_TUIKEY_EXTERN |
35 | 38 | #else |
@@ -43,7 +46,7 @@ VMTUI_TUIKEY_EXTERN char *TuiKey_GetInputStringAndPasswd( int *pi_len ); | ||
43 | 46 | VMTUI_TUIKEY_EXTERN char *TuiKey_GetPromptString( void ); |
44 | 47 | VMTUI_TUIKEY_EXTERN int TuiKey_ChangeMode( |
45 | 48 | int i_mode, Byte b_reqcmd, int i_hvisor, int i_guest, |
46 | - Byte b_option, char *pstr_msg ); | |
49 | + InputStrFunction fp_handler, Byte b_option, int i_retmode, char *pstr_msg ); | |
47 | 50 | VMTUI_TUIKEY_EXTERN int TuiKey_Dispatch( void ); |
48 | 51 | VMTUI_TUIKEY_EXTERN int TuiKey_Init( void ); |
49 | 52 | VMTUI_TUIKEY_EXTERN int TuiKey_Term( void ); |
@@ -58,6 +61,7 @@ VMTUI_TUIKEY_EXTERN int TuiKey_Term( void ); | ||
58 | 61 | #define TUIKEY_MODE_INPUTSTR 0x21 |
59 | 62 | #define TUIKEY_MODE_INPUTPASSWD 0x22 |
60 | 63 | #define TUIKEY_MODE_YESNO 0x23 |
64 | +#define TUIKEY_MODE_NONE 0xff | |
61 | 65 | |
62 | 66 | #define NCURSES_KEY_ENTER 10 |
63 | 67 | #define NCURSES_KEY_ESC 27 |
@@ -69,8 +73,6 @@ typedef struct { | ||
69 | 73 | char *pstr_name; |
70 | 74 | } TuiKey_StrTable; |
71 | 75 | |
72 | -typedef int (* KeyEventFunction)( int i_hvisor, int i_guest, int i_option ); | |
73 | - | |
74 | 76 | typedef struct { |
75 | 77 | int i_key[2]; |
76 | 78 | Byte b_Mode; |
@@ -86,6 +88,9 @@ typedef struct { | ||
86 | 88 | int i_guest; |
87 | 89 | Byte b_option; |
88 | 90 | |
91 | + int i_retmode; | |
92 | + InputStrFunction fp_inputstr; | |
93 | + | |
89 | 94 | int i_inputlen; |
90 | 95 | int i_input; |
91 | 96 | char str_input[512]; |
@@ -62,7 +62,8 @@ int | ||
62 | 62 | int i_hvisor, int i_guest, int i_option ) |
63 | 63 | { |
64 | 64 | TuiKey_ChangeMode( TUIKEY_MODE_YESNO, REQUEST_CMD_SYS_QUIT, |
65 | - HVISOR_ID_NONE, GUEST_ID_NONE, 0x00, NULL ); | |
65 | + HVISOR_ID_NONE, GUEST_ID_NONE, NULL, 0x00, | |
66 | + TUIKEY_MODE_VMLIST, NULL ); | |
66 | 67 | |
67 | 68 | return 0x00; |
68 | 69 | } |
@@ -99,7 +100,8 @@ int | ||
99 | 100 | int i_hvisor, int i_guest, int i_option ) |
100 | 101 | { |
101 | 102 | TuiKey_ChangeMode( TUIKEY_MODE_YESNO, REQUEST_CMD_VM_START, |
102 | - i_hvisor, i_guest, 0x00, NULL ); | |
103 | + i_hvisor, i_guest, NULL, 0x00, | |
104 | + TUIKEY_MODE_VMLIST, NULL ); | |
103 | 105 | |
104 | 106 | return 0x00; |
105 | 107 | } |
@@ -154,7 +156,8 @@ int | ||
154 | 156 | int i_hvisor, int i_guest, int i_option ) |
155 | 157 | { |
156 | 158 | TuiKey_ChangeMode( TUIKEY_MODE_INFO, REQUEST_CMD_NONE, |
157 | - i_hvisor, i_guest, 0x00, NULL ); | |
159 | + i_hvisor, i_guest, NULL, 0x00, | |
160 | + TUIKEY_MODE_NONE, NULL ); | |
158 | 161 | |
159 | 162 | return 0x00; |
160 | 163 | } |