bagajjal 2017-01-24 10:18:42 -08:00 committed by Manoj Ampalam
parent d10d8a8f36
commit e4da8db4d2
4 changed files with 43 additions and 35 deletions

View File

@ -74,6 +74,7 @@ typedef struct _SCREEN_RECORD{
}SCREEN_RECORD,*PSCREEN_RECORD; }SCREEN_RECORD,*PSCREEN_RECORD;
PSCREEN_RECORD pSavedScreenRec = NULL; PSCREEN_RECORD pSavedScreenRec = NULL;
int in_raw_mode = 0;
/* ************************************************************ */ /* ************************************************************ */
/* Function: ConInit */ /* Function: ConInit */
@ -135,6 +136,7 @@ int ConInit( DWORD OutputHandle, BOOL fSmartInit )
if (GetConsoleScreenBufferInfo(hOutputConsole, &csbi)) if (GetConsoleScreenBufferInfo(hOutputConsole, &csbi))
SavedViewRect = csbi.srWindow; SavedViewRect = csbi.srWindow;
in_raw_mode = 1;
return 0; return 0;
} }
@ -147,6 +149,7 @@ int ConUnInit( void )
{ {
CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo; CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo;
in_raw_mode = 0;
if ( hOutputConsole == NULL ) if ( hOutputConsole == NULL )
return 0; return 0;

View File

@ -1069,15 +1069,15 @@ int start_with_pty(int ac, wchar_t **av) {
/*TODO - pick this up from system32*/ /*TODO - pick this up from system32*/
cmd[0] = L'\0'; cmd[0] = L'\0';
if (ac) if (ac)
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, L"cmd.exe")); GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, L"cmd.exe"));
ac--; ac--;
av++; av++;
if (ac) if (ac)
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, L" /c")); GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, L" /c"));
while (ac) { while (ac) {
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, L" ")); GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, L" "));
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, *av)); GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, *av));
ac--; ac--;
av++; av++;
} }
@ -1183,14 +1183,14 @@ int start_withno_pty(int ac, wchar_t **av) {
/*TODO - pick this up from system32*/ /*TODO - pick this up from system32*/
cmd[0] = L'\0'; cmd[0] = L'\0';
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, L"cmd.exe")); GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, L"cmd.exe"));
ac -= 2; ac -= 2;
av += 2; av += 2;
if (ac) if (ac)
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, L" /c")); GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, L" /c"));
while (ac) { while (ac) {
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, L" ")); GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, L" "));
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, *av)); GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, *av));
ac--; ac--;
av++; av++;
} }

View File

@ -6,6 +6,8 @@
#define TERM_IO_BUF_SIZE 2048 #define TERM_IO_BUF_SIZE 2048
extern int in_raw_mode;
struct io_status { struct io_status {
DWORD to_transfer; DWORD to_transfer;
DWORD transferred; DWORD transferred;
@ -129,25 +131,19 @@ static DWORD WINAPI WriteThread(
DWORD dwSavedAttributes = ENABLE_PROCESSED_INPUT; DWORD dwSavedAttributes = ENABLE_PROCESSED_INPUT;
debug3("TermWrite thread, io:%p", pio); debug3("TermWrite thread, io:%p", pio);
/* decide to call parsing engine or directly write to console if (in_raw_mode == 0) {
* doing the following trick to decide -
* if console in handle is set to process Ctrl+C, then it is likely
* serving a PTY enabled session
*/
GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &dwSavedAttributes);
if (dwSavedAttributes & ENABLE_PROCESSED_INPUT) {
/* convert stream to utf16 and dump on console */ /* convert stream to utf16 and dump on console */
pio->write_details.buf[write_status.to_transfer] = '\0'; pio->write_details.buf[write_status.to_transfer] = '\0';
wchar_t* t = utf8_to_utf16(pio->write_details.buf); wchar_t* t = utf8_to_utf16(pio->write_details.buf);
WriteConsoleW(WINHANDLE(pio), t, wcslen(t), 0, 0); WriteConsoleW(WINHANDLE(pio), t, wcslen(t), 0, 0);
free(t); free(t);
write_status.transferred = write_status.to_transfer; write_status.transferred = write_status.to_transfer;
} else { } else {
/* console mode */
telProcessNetwork(pio->write_details.buf, write_status.to_transfer, &respbuf, &resplen); telProcessNetwork(pio->write_details.buf, write_status.to_transfer, &respbuf, &resplen);
/*TODO - respbuf is not null in some cases, this needs to be returned back via read stream*/ /*TODO - respbuf is not null in some cases, this needs to be returned back via read stream*/
write_status.transferred = write_status.to_transfer; write_status.transferred = write_status.to_transfer;
} }
if (0 == QueueUserAPC(WriteAPCProc, main_thread, (ULONG_PTR)pio)) { if (0 == QueueUserAPC(WriteAPCProc, main_thread, (ULONG_PTR)pio)) {
debug("TermWrite thread - ERROR QueueUserAPC failed %d, io:%p", GetLastError(), pio); debug("TermWrite thread - ERROR QueueUserAPC failed %d, io:%p", GetLastError(), pio);

37
sftp.c
View File

@ -296,19 +296,16 @@ help(void)
/* printf version to account for utf-8 input */ /* printf version to account for utf-8 input */
/* TODO - merge this with vfmprint */ /* TODO - merge this with vfmprint */
static void printf_utf8(char *fmt, ... ) { static void printf_utf8(char *fmt, ... ) {
/* TODO - is 1024 sufficient */ /* TODO - is 1024 sufficient */
char buf[1024]; char buf[1024];
wchar_t* wtmp; int length = 0;
va_list valist;
va_start(valist, fmt); va_list valist;
va_start(valist, fmt);
length = vsnprintf(buf, 1024, fmt, valist);
va_end(valist);
vsnprintf(buf, 1024, fmt, valist); write(STDOUT_FILENO, buf, length);
va_end(valist);
if ((wtmp = utf8_to_utf16(buf)) == NULL)
fatal("unable to allocate memory");
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
free(wtmp);
} }
/* override mprintf */ /* override mprintf */
@ -931,11 +928,17 @@ do_ls_dir(struct sftp_conn *conn, const char *path,
#ifdef WINDOWS #ifdef WINDOWS
/* cannot use printf_utf8 becuase of width specification */ /* cannot use printf_utf8 becuase of width specification */
/* printf_utf8 does not account for utf-16 based argument widths */ /* printf_utf8 does not account for utf-16 based argument widths */
char *p = NULL;
wchar_t buf[1024]; wchar_t buf[1024];
wchar_t* wtmp = utf8_to_utf16(fname); wchar_t* wtmp = utf8_to_utf16(fname);
swprintf(buf, 1024, L"%-*s", colspace, wtmp); swprintf(buf, 1024, L"%-*s", colspace, wtmp);
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), buf, wcslen(buf), 0, 0);
if ((p = utf16_to_utf8(buf)) == NULL)
continue;
write(STDOUT_FILENO, p, strlen(p));
free(wtmp); free(wtmp);
free(p);
#else #else
mprintf("%-*s", colspace, fname); mprintf("%-*s", colspace, fname);
#endif #endif
@ -1025,11 +1028,17 @@ do_globbed_ls(struct sftp_conn *conn, const char *path,
#ifdef WINDOWS #ifdef WINDOWS
/* cannot use printf_utf8 becuase of width specification */ /* cannot use printf_utf8 becuase of width specification */
/* printf_utf8 does not account for utf-16 based argument widths */ /* printf_utf8 does not account for utf-16 based argument widths */
char *p = NULL;
wchar_t buf[1024]; wchar_t buf[1024];
wchar_t* wtmp = utf8_to_utf16(fname); wchar_t* wtmp = utf8_to_utf16(fname);
swprintf(buf, 1024, L"%-*s", colspace, wtmp); swprintf(buf, 1024, L"%-*s", colspace, wtmp);
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), buf, wcslen(buf), 0, 0);
if ((p = utf16_to_utf8(buf)) == NULL)
continue;
write(STDOUT_FILENO, p, strlen(p));
free(wtmp); free(wtmp);
free(p);
#else #else
mprintf("%-*s", colspace, fname); mprintf("%-*s", colspace, fname);
#endif #endif