Cleaned up shell-host and terminal related code

This commit is contained in:
bagajjal 2017-02-07 12:21:01 -08:00 committed by Manoj Ampalam
parent ce03c08333
commit 73180c876d
6 changed files with 1701 additions and 1916 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -207,7 +207,8 @@ SendKeyStroke(HANDLE hInput, int keyStroke, char character)
} }
void void
ProcessIncomingKeys(char * ansikey) { ProcessIncomingKeys(char * ansikey)
{
int nKey = 0; int nKey = 0;
int index = ARRAYSIZE(keys); int index = ARRAYSIZE(keys);
@ -228,7 +229,8 @@ ProcessIncomingKeys(char * ansikey) {
* VT output routines * VT output routines
*/ */
void void
SendLF(HANDLE hInput) { SendLF(HANDLE hInput)
{
DWORD wr = 0; DWORD wr = 0;
if (bUseAnsiEmulation) if (bUseAnsiEmulation)
@ -236,7 +238,8 @@ SendLF(HANDLE hInput) {
} }
void void
SendClearScreen(HANDLE hInput) { SendClearScreen(HANDLE hInput)
{
DWORD wr = 0; DWORD wr = 0;
if (bUseAnsiEmulation) if (bUseAnsiEmulation)
@ -244,7 +247,8 @@ SendClearScreen(HANDLE hInput) {
} }
void void
SendClearScreenFromCursor(HANDLE hInput) { SendClearScreenFromCursor(HANDLE hInput)
{
DWORD wr = 0; DWORD wr = 0;
if (bUseAnsiEmulation) if (bUseAnsiEmulation)
@ -252,7 +256,8 @@ SendClearScreenFromCursor(HANDLE hInput) {
} }
void void
SendHideCursor(HANDLE hInput) { SendHideCursor(HANDLE hInput)
{
DWORD wr = 0; DWORD wr = 0;
if (bUseAnsiEmulation) if (bUseAnsiEmulation)
@ -260,7 +265,8 @@ SendHideCursor(HANDLE hInput) {
} }
void void
SendShowCursor(HANDLE hInput) { SendShowCursor(HANDLE hInput)
{
DWORD wr = 0; DWORD wr = 0;
if (bUseAnsiEmulation) if (bUseAnsiEmulation)
@ -268,7 +274,8 @@ SendShowCursor(HANDLE hInput) {
} }
void void
SendCursorPositionRequest(HANDLE hInput) { SendCursorPositionRequest(HANDLE hInput)
{
DWORD wr = 0; DWORD wr = 0;
if (bUseAnsiEmulation) if (bUseAnsiEmulation)
@ -276,7 +283,8 @@ SendCursorPositionRequest(HANDLE hInput) {
} }
void void
SendSetCursor(HANDLE hInput, int X, int Y) { SendSetCursor(HANDLE hInput, int X, int Y)
{
DWORD wr = 0; DWORD wr = 0;
DWORD out = 0; DWORD out = 0;
char formatted_output[255]; char formatted_output[255];
@ -287,7 +295,8 @@ SendSetCursor(HANDLE hInput, int X, int Y) {
} }
void void
SendVerticalScroll(HANDLE hInput, int lines) { SendVerticalScroll(HANDLE hInput, int lines)
{
DWORD wr = 0; DWORD wr = 0;
DWORD out = 0; DWORD out = 0;
char formatted_output[255]; char formatted_output[255];
@ -303,7 +312,8 @@ SendVerticalScroll(HANDLE hInput, int lines) {
} }
void void
SendHorizontalScroll(HANDLE hInput, int cells) { SendHorizontalScroll(HANDLE hInput, int cells)
{
DWORD wr = 0; DWORD wr = 0;
DWORD out = 0; DWORD out = 0;
char formatted_output[255]; char formatted_output[255];
@ -315,7 +325,8 @@ SendHorizontalScroll(HANDLE hInput, int cells) {
} }
void void
SendCharacter(HANDLE hInput, WORD attributes, wchar_t character) { SendCharacter(HANDLE hInput, WORD attributes, wchar_t character)
{
DWORD wr = 0; DWORD wr = 0;
DWORD out = 0; DWORD out = 0;
DWORD current = 0; DWORD current = 0;
@ -403,7 +414,8 @@ SendCharacter(HANDLE hInput, WORD attributes, wchar_t character) {
} }
void void
SendBuffer(HANDLE hInput, CHAR_INFO *buffer, DWORD bufferSize) { SendBuffer(HANDLE hInput, CHAR_INFO *buffer, DWORD bufferSize)
{
if (bufferSize <= 0) if (bufferSize <= 0)
return; return;
@ -412,14 +424,16 @@ SendBuffer(HANDLE hInput, CHAR_INFO *buffer, DWORD bufferSize) {
} }
void void
CalculateAndSetCursor(HANDLE hInput, UINT aboveTopLine, UINT viewPortHeight, UINT x, UINT y) { CalculateAndSetCursor(HANDLE hInput, UINT aboveTopLine, UINT viewPortHeight, UINT x, UINT y)
{
SendSetCursor(pipe_out, x + 1, y + 1); SendSetCursor(pipe_out, x + 1, y + 1);
currentLine = y; currentLine = y;
} }
void void
SizeWindow(HANDLE hInput) { SizeWindow(HANDLE hInput)
{
SMALL_RECT srWindowRect; SMALL_RECT srWindowRect;
COORD coordScreen; COORD coordScreen;
BOOL bSuccess = FALSE; BOOL bSuccess = FALSE;
@ -472,7 +486,8 @@ SizeWindow(HANDLE hInput) {
} }
DWORD WINAPI DWORD WINAPI
MonitorChild(_In_ LPVOID lpParameter) { MonitorChild(_In_ LPVOID lpParameter)
{
WaitForSingleObject(child, INFINITE); WaitForSingleObject(child, INFINITE);
GetExitCodeProcess(child, &child_exit_code); GetExitCodeProcess(child, &child_exit_code);
PostThreadMessage(hostThreadId, WM_APPEXIT, 0, 0); PostThreadMessage(hostThreadId, WM_APPEXIT, 0, 0);
@ -480,7 +495,8 @@ MonitorChild(_In_ LPVOID lpParameter) {
} }
DWORD DWORD
ProcessEvent(void *p) { ProcessEvent(void *p)
{
char f[255]; char f[255];
wchar_t chUpdate; wchar_t chUpdate;
WORD wAttributes; WORD wAttributes;
@ -689,7 +705,8 @@ ProcessEvent(void *p) {
} }
DWORD WINAPI DWORD WINAPI
ProcessEventQueue(LPVOID p) { ProcessEventQueue(LPVOID p)
{
static SHORT lastX = 0; static SHORT lastX = 0;
static SHORT lastY = 0; static SHORT lastY = 0;
@ -747,7 +764,8 @@ ProcessEventQueue(LPVOID p) {
} }
void void
QueueEvent(DWORD event, HWND hwnd, LONG idObject, LONG idChild) { QueueEvent(DWORD event, HWND hwnd, LONG idObject, LONG idChild)
{
consoleEvent* current = NULL; consoleEvent* current = NULL;
EnterCriticalSection(&criticalSection); EnterCriticalSection(&criticalSection);
@ -786,7 +804,8 @@ QueueEvent(DWORD event, HWND hwnd, LONG idObject, LONG idChild) {
} }
DWORD WINAPI DWORD WINAPI
ProcessPipes(LPVOID p) { ProcessPipes(LPVOID p)
{
BOOL ret; BOOL ret;
DWORD dwStatus; DWORD dwStatus;
@ -838,12 +857,14 @@ ConsoleEventProc(HWINEVENTHOOK hWinEventHook,
LONG idObject, LONG idObject,
LONG idChild, LONG idChild,
DWORD dwEventThread, DWORD dwEventThread,
DWORD dwmsEventTime) { DWORD dwmsEventTime)
{
QueueEvent(event, hwnd, idObject, idChild); QueueEvent(event, hwnd, idObject, idChild);
} }
DWORD DWORD
ProcessMessages(void* p) { ProcessMessages(void* p)
{
BOOL ret; BOOL ret;
DWORD dwMode; DWORD dwMode;
DWORD dwStatus; DWORD dwStatus;
@ -895,7 +916,8 @@ cleanup:
} }
int int
start_with_pty(int ac, wchar_t **av) { start_with_pty(int ac, wchar_t **av)
{
STARTUPINFO si; STARTUPINFO si;
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
wchar_t cmd[MAX_CMD_LEN]; wchar_t cmd[MAX_CMD_LEN];
@ -1015,7 +1037,8 @@ HANDLE child_pipe_read;
HANDLE child_pipe_write; HANDLE child_pipe_write;
DWORD WINAPI DWORD WINAPI
MonitorChild_nopty( _In_ LPVOID lpParameter) { MonitorChild_nopty( _In_ LPVOID lpParameter)
{
WaitForSingleObject(child, INFINITE); WaitForSingleObject(child, INFINITE);
GetExitCodeProcess(child, &child_exit_code); GetExitCodeProcess(child, &child_exit_code);
CloseHandle(pipe_in); CloseHandle(pipe_in);
@ -1023,7 +1046,8 @@ MonitorChild_nopty( _In_ LPVOID lpParameter) {
} }
int int
start_withno_pty(int ac, wchar_t **av) { start_withno_pty(int ac, wchar_t **av)
{
STARTUPINFO si; STARTUPINFO si;
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
wchar_t cmd[MAX_CMD_LEN]; wchar_t cmd[MAX_CMD_LEN];
@ -1157,7 +1181,8 @@ cleanup:
} }
int int
wmain(int ac, wchar_t **av) { wmain(int ac, wchar_t **av)
{
/* create job to hold all child processes */ /* create job to hold all child processes */
HANDLE job = CreateJobObject(NULL, NULL); HANDLE job = CreateJobObject(NULL, NULL);
JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info; JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info;

View File

@ -53,7 +53,8 @@ static struct io_status read_status, write_status;
/* APC that gets queued on main thread when a sync Read completes on worker thread */ /* APC that gets queued on main thread when a sync Read completes on worker thread */
static VOID CALLBACK static VOID CALLBACK
ReadAPCProc(_In_ ULONG_PTR dwParam) { ReadAPCProc(_In_ ULONG_PTR dwParam)
{
struct w32_io* pio = (struct w32_io*)dwParam; struct w32_io* pio = (struct w32_io*)dwParam;
debug3("TermRead CB - io:%p, bytes: %d, pending: %d, error: %d", pio, read_status.transferred, debug3("TermRead CB - io:%p, bytes: %d, pending: %d, error: %d", pio, read_status.transferred,
pio->read_details.pending, read_status.error); pio->read_details.pending, read_status.error);
@ -68,7 +69,8 @@ ReadAPCProc(_In_ ULONG_PTR dwParam) {
/* Read worker thread */ /* Read worker thread */
static DWORD WINAPI static DWORD WINAPI
ReadConsoleThread(_In_ LPVOID lpParameter) { ReadConsoleThread(_In_ LPVOID lpParameter)
{
int nBytesReturned = 0; int nBytesReturned = 0;
struct w32_io* pio = (struct w32_io*)lpParameter; struct w32_io* pio = (struct w32_io*)lpParameter;
@ -91,7 +93,8 @@ ReadConsoleThread(_In_ LPVOID lpParameter) {
/* Initiates read on tty */ /* Initiates read on tty */
int int
termio_initiate_read(struct w32_io* pio) { termio_initiate_read(struct w32_io* pio)
{
HANDLE read_thread; HANDLE read_thread;
debug3("TermRead initiate io:%p", pio); debug3("TermRead initiate io:%p", pio);
@ -118,7 +121,8 @@ termio_initiate_read(struct w32_io* pio) {
/* APC that gets queued on main thread when a sync Write completes on worker thread */ /* APC that gets queued on main thread when a sync Write completes on worker thread */
static VOID CALLBACK static VOID CALLBACK
WriteAPCProc(_In_ ULONG_PTR dwParam) { WriteAPCProc(_In_ ULONG_PTR dwParam)
{
struct w32_io* pio = (struct w32_io*)dwParam; struct w32_io* pio = (struct w32_io*)dwParam;
debug3("TermWrite CB - io:%p, bytes: %d, pending: %d, error: %d", pio, write_status.transferred, debug3("TermWrite CB - io:%p, bytes: %d, pending: %d, error: %d", pio, write_status.transferred,
pio->write_details.pending, write_status.error); pio->write_details.pending, write_status.error);
@ -134,7 +138,8 @@ WriteAPCProc(_In_ ULONG_PTR dwParam) {
/* Write worker thread */ /* Write worker thread */
static DWORD WINAPI static DWORD WINAPI
WriteThread(_In_ LPVOID lpParameter) { WriteThread(_In_ LPVOID lpParameter)
{
struct w32_io* pio = (struct w32_io*)lpParameter; struct w32_io* pio = (struct w32_io*)lpParameter;
char *respbuf = NULL; char *respbuf = NULL;
size_t resplen = 0; size_t resplen = 0;
@ -166,7 +171,8 @@ WriteThread(_In_ LPVOID lpParameter) {
/* Initiates write on tty */ /* Initiates write on tty */
int int
termio_initiate_write(struct w32_io* pio, DWORD num_bytes) { termio_initiate_write(struct w32_io* pio, DWORD num_bytes)
{
HANDLE write_thread; HANDLE write_thread;
debug3("TermWrite initiate io:%p", pio); debug3("TermWrite initiate io:%p", pio);
memset(&write_status, 0, sizeof(write_status)); memset(&write_status, 0, sizeof(write_status));
@ -185,7 +191,8 @@ termio_initiate_write(struct w32_io* pio, DWORD num_bytes) {
/* tty close */ /* tty close */
int int
termio_close(struct w32_io* pio) { termio_close(struct w32_io* pio)
{
debug2("termio_close - pio:%p", pio); debug2("termio_close - pio:%p", pio);
HANDLE h; HANDLE h;
CancelIoEx(WINHANDLE(pio), NULL); CancelIoEx(WINHANDLE(pio), NULL);

View File

@ -79,7 +79,8 @@ void queue_terminal_window_change_event();
* a global buffer setup by ReadConsoleForTermEmul(). * a global buffer setup by ReadConsoleForTermEmul().
*/ */
int int
NetWriteString2(SOCKET sock, char* source, size_t len, int options) { NetWriteString2(SOCKET sock, char* source, size_t len, int options)
{
while (len > 0) { while (len > 0) {
if (glob_outlen >= glob_space) if (glob_outlen >= glob_space)
return glob_outlen; return glob_outlen;
@ -91,7 +92,8 @@ NetWriteString2(SOCKET sock, char* source, size_t len, int options) {
} }
BOOL BOOL
DataAvailable(HANDLE h) { DataAvailable(HANDLE h)
{
DWORD dwRet = WaitForSingleObject(h, INFINITE); DWORD dwRet = WaitForSingleObject(h, INFINITE);
if (dwRet == WAIT_OBJECT_0) if (dwRet == WAIT_OBJECT_0)
return TRUE; return TRUE;
@ -101,7 +103,8 @@ DataAvailable(HANDLE h) {
} }
int int
ReadConsoleForTermEmul(HANDLE hInput, char *destin, int destinlen) { ReadConsoleForTermEmul(HANDLE hInput, char *destin, int destinlen)
{
HANDLE hHandle[] = { hInput, NULL }; HANDLE hHandle[] = { hInput, NULL };
DWORD nHandle = 1; DWORD nHandle = 1;
DWORD dwInput = 0; DWORD dwInput = 0;

View File

@ -45,7 +45,8 @@
* are hardcoded in the server and will be transformed to Windows Console commands. * are hardcoded in the server and will be transformed to Windows Console commands.
*/ */
size_t size_t
telProcessNetwork(char *buf, size_t len, unsigned char **respbuf, size_t *resplen) { telProcessNetwork(char *buf, size_t len, unsigned char **respbuf, size_t *resplen)
{
unsigned char szBuffer[dwBuffer + 8]; unsigned char szBuffer[dwBuffer + 8];
unsigned char* pszNewHead = NULL; unsigned char* pszNewHead = NULL;
unsigned char* pszHead = NULL; unsigned char* pszHead = NULL;