• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Virtual machine Management Terminal User Interface


Commit MetaInfo

Revision475b6623b10fa983e29a01be72907cfdb30d8b57 (tree)
Zeit2023-06-20 22:34:50
AutorKoine Yuusuke(koinec) <koinec@user...>
CommiterKoine Yuusuke(koinec)

Log Message

Improve TuiKey_ChangeMode()

Ändern Zusammenfassung

Diff

--- a/src/hvcmd.c
+++ b/src/hvcmd.c
@@ -29,6 +29,26 @@
2929 #define VMTUI_SRC_
3030 #include "vmtui.h"
3131
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+}
3252
3353 /* ===========================================================================*/
3454 VMTUI_HVCMD_EXTERN
@@ -77,7 +97,9 @@ int
7797 if( HVCMD_CONNECT_PHASE_REQUEST == b_phase ) {
7898 if(( 0x01 == b_nosshpasswd ) && ( HVISOR_CON_LOCALHOST != b_connection )) {
7999 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,
81103 "Input SSH PassWord / PassPhrase ? " );
82104 return 0x00;
83105 }
@@ -92,7 +114,9 @@ int
92114 if( HVCMD_CONNECT_PHASE_SUDOPASS_REQ == b_phase ) {
93115 if( 0x01 == b_nosudopasswd ) {
94116 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,
96120 "Input Login User's Password for sudo cmd. ? " );
97121 return 0x00;
98122 }
@@ -105,7 +129,8 @@ int
105129 b_phase = HVCMD_CONNECT_PHASE_CONNECTSTART;
106130 }
107131
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 );
109134 i_ret = ReqCtl_CreateRequest( REQUEST_CMD_HV_CONNECT, i_hvisor, GUEST_ID_NONE, NULL );
110135
111136 return i_ret;
--- a/src/hvcmd.h
+++ b/src/hvcmd.h
@@ -35,6 +35,9 @@
3535 #else
3636 #define VMTUI_HVCMD_EXTERN extern
3737 #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 );
3841 VMTUI_HVCMD_EXTERN int HvCmd_Connect( int i_hvisor, Byte b_phase, char *pstr_passwd );
3942 #define HVCMD_CONNECT_PHASE_NONE 0x00
4043 #define HVCMD_CONNECT_PHASE_REQUEST 0x01
--- a/src/tuiconsole.c
+++ b/src/tuiconsole.c
@@ -38,7 +38,8 @@ int
3838 switch( i_key ) {
3939 case NCURSES_KEY_ENTER:
4040 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 );
4243 break;
4344 }
4445
--- a/src/tuierrinfo.c
+++ b/src/tuierrinfo.c
@@ -38,7 +38,8 @@ int
3838 switch( i_key ) {
3939 case NCURSES_KEY_ENTER:
4040 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 );
4243 break;
4344 }
4445
--- a/src/tuiguest.c
+++ b/src/tuiguest.c
@@ -41,7 +41,8 @@ int
4141 switch( i_key ) {
4242 case NCURSES_KEY_ENTER:
4343 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 );
4546 break;
4647 case 'j':
4748 i_maxlines = TextBuf_GetMaxLine( &lt_guest.t_textbuf );
--- a/src/tuihelp.c
+++ b/src/tuihelp.c
@@ -40,7 +40,8 @@ int
4040 switch( i_key ) {
4141 case NCURSES_KEY_ENTER:
4242 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 );
4445 break;
4546 case 'j':
4647 i_max = TextBuf_GetMaxLine( &lt_help.t_textbuf ) - lt_help.i_line_start;
--- a/src/tuihvisor.c
+++ b/src/tuihvisor.c
@@ -40,7 +40,8 @@ int
4040 switch( i_key ) {
4141 case NCURSES_KEY_ENTER:
4242 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 );
4445 break;
4546 case 'j':
4647 i_maxlines = TextBuf_GetMaxLine( &lt_hvisor.t_textbuf );
--- a/src/tuikey.c
+++ b/src/tuikey.c
@@ -162,18 +162,22 @@ char *
162162 VMTUI_TUIKEY_EXTERN
163163 int
164164 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 )
171173 {
172174 gi_keymode = i_mode;
173175
174176 gt_input.b_reqcmd = b_reqcmd;
175177 gt_input.i_hvisor = i_hvisor;
176178 gt_input.i_guest = i_guest;
179+ gt_input.fp_inputstr = fp_handler;
180+ gt_input.i_retmode = i_retmode;
177181
178182 if( TUIKEY_MODE_INPUTSTR == i_mode ) {
179183 gt_input.i_inputlen = 0;
@@ -256,21 +260,17 @@ int
256260 }
257261 }
258262 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 );
268267 }
269268 }
270269 // KEY_ESC
271270 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 );
274274 }
275275 else if( KEY_BACKSPACE == i_key ) {
276276 if( 0 < gt_input.i_inputlen ) {
@@ -297,8 +297,9 @@ int
297297 { i_ret = 0x01; }
298298 }
299299
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 );
302303
303304 return i_ret;
304305 }
@@ -370,7 +371,8 @@ int
370371 memset( &gt_input, 0x00, sizeof( TuiKey_InputLine ) );
371372
372373 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 );
374376
375377 return 0x00;
376378 }
--- a/src/tuikey.h
+++ b/src/tuikey.h
@@ -30,6 +30,9 @@
3030
3131 #include "vmtui.h"
3232
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+
3336 #ifdef VMTUI_SRC_TUIKEY
3437 #define VMTUI_TUIKEY_EXTERN
3538 #else
@@ -43,7 +46,7 @@ VMTUI_TUIKEY_EXTERN char *TuiKey_GetInputStringAndPasswd( int *pi_len );
4346 VMTUI_TUIKEY_EXTERN char *TuiKey_GetPromptString( void );
4447 VMTUI_TUIKEY_EXTERN int TuiKey_ChangeMode(
4548 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 );
4750 VMTUI_TUIKEY_EXTERN int TuiKey_Dispatch( void );
4851 VMTUI_TUIKEY_EXTERN int TuiKey_Init( void );
4952 VMTUI_TUIKEY_EXTERN int TuiKey_Term( void );
@@ -58,6 +61,7 @@ VMTUI_TUIKEY_EXTERN int TuiKey_Term( void );
5861 #define TUIKEY_MODE_INPUTSTR 0x21
5962 #define TUIKEY_MODE_INPUTPASSWD 0x22
6063 #define TUIKEY_MODE_YESNO 0x23
64+#define TUIKEY_MODE_NONE 0xff
6165
6266 #define NCURSES_KEY_ENTER 10
6367 #define NCURSES_KEY_ESC 27
@@ -69,8 +73,6 @@ typedef struct {
6973 char *pstr_name;
7074 } TuiKey_StrTable;
7175
72-typedef int (* KeyEventFunction)( int i_hvisor, int i_guest, int i_option );
73-
7476 typedef struct {
7577 int i_key[2];
7678 Byte b_Mode;
@@ -86,6 +88,9 @@ typedef struct {
8688 int i_guest;
8789 Byte b_option;
8890
91+ int i_retmode;
92+ InputStrFunction fp_inputstr;
93+
8994 int i_inputlen;
9095 int i_input;
9196 char str_input[512];
--- a/src/tuivmlist_event.c
+++ b/src/tuivmlist_event.c
@@ -62,7 +62,8 @@ int
6262 int i_hvisor, int i_guest, int i_option )
6363 {
6464 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 );
6667
6768 return 0x00;
6869 }
@@ -99,7 +100,8 @@ int
99100 int i_hvisor, int i_guest, int i_option )
100101 {
101102 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 );
103105
104106 return 0x00;
105107 }
@@ -154,7 +156,8 @@ int
154156 int i_hvisor, int i_guest, int i_option )
155157 {
156158 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 );
158161
159162 return 0x00;
160163 }