Cleaned up shell-host and terminal related code
This commit is contained in:
parent
ce03c08333
commit
73180c876d
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -207,7 +207,8 @@ SendKeyStroke(HANDLE hInput, int keyStroke, char character)
|
|||
}
|
||||
|
||||
void
|
||||
ProcessIncomingKeys(char * ansikey) {
|
||||
ProcessIncomingKeys(char * ansikey)
|
||||
{
|
||||
int nKey = 0;
|
||||
int index = ARRAYSIZE(keys);
|
||||
|
||||
|
@ -228,7 +229,8 @@ ProcessIncomingKeys(char * ansikey) {
|
|||
* VT output routines
|
||||
*/
|
||||
void
|
||||
SendLF(HANDLE hInput) {
|
||||
SendLF(HANDLE hInput)
|
||||
{
|
||||
DWORD wr = 0;
|
||||
|
||||
if (bUseAnsiEmulation)
|
||||
|
@ -236,7 +238,8 @@ SendLF(HANDLE hInput) {
|
|||
}
|
||||
|
||||
void
|
||||
SendClearScreen(HANDLE hInput) {
|
||||
SendClearScreen(HANDLE hInput)
|
||||
{
|
||||
DWORD wr = 0;
|
||||
|
||||
if (bUseAnsiEmulation)
|
||||
|
@ -244,7 +247,8 @@ SendClearScreen(HANDLE hInput) {
|
|||
}
|
||||
|
||||
void
|
||||
SendClearScreenFromCursor(HANDLE hInput) {
|
||||
SendClearScreenFromCursor(HANDLE hInput)
|
||||
{
|
||||
DWORD wr = 0;
|
||||
|
||||
if (bUseAnsiEmulation)
|
||||
|
@ -252,7 +256,8 @@ SendClearScreenFromCursor(HANDLE hInput) {
|
|||
}
|
||||
|
||||
void
|
||||
SendHideCursor(HANDLE hInput) {
|
||||
SendHideCursor(HANDLE hInput)
|
||||
{
|
||||
DWORD wr = 0;
|
||||
|
||||
if (bUseAnsiEmulation)
|
||||
|
@ -260,7 +265,8 @@ SendHideCursor(HANDLE hInput) {
|
|||
}
|
||||
|
||||
void
|
||||
SendShowCursor(HANDLE hInput) {
|
||||
SendShowCursor(HANDLE hInput)
|
||||
{
|
||||
DWORD wr = 0;
|
||||
|
||||
if (bUseAnsiEmulation)
|
||||
|
@ -268,7 +274,8 @@ SendShowCursor(HANDLE hInput) {
|
|||
}
|
||||
|
||||
void
|
||||
SendCursorPositionRequest(HANDLE hInput) {
|
||||
SendCursorPositionRequest(HANDLE hInput)
|
||||
{
|
||||
DWORD wr = 0;
|
||||
|
||||
if (bUseAnsiEmulation)
|
||||
|
@ -276,7 +283,8 @@ SendCursorPositionRequest(HANDLE hInput) {
|
|||
}
|
||||
|
||||
void
|
||||
SendSetCursor(HANDLE hInput, int X, int Y) {
|
||||
SendSetCursor(HANDLE hInput, int X, int Y)
|
||||
{
|
||||
DWORD wr = 0;
|
||||
DWORD out = 0;
|
||||
char formatted_output[255];
|
||||
|
@ -287,7 +295,8 @@ SendSetCursor(HANDLE hInput, int X, int Y) {
|
|||
}
|
||||
|
||||
void
|
||||
SendVerticalScroll(HANDLE hInput, int lines) {
|
||||
SendVerticalScroll(HANDLE hInput, int lines)
|
||||
{
|
||||
DWORD wr = 0;
|
||||
DWORD out = 0;
|
||||
char formatted_output[255];
|
||||
|
@ -303,7 +312,8 @@ SendVerticalScroll(HANDLE hInput, int lines) {
|
|||
}
|
||||
|
||||
void
|
||||
SendHorizontalScroll(HANDLE hInput, int cells) {
|
||||
SendHorizontalScroll(HANDLE hInput, int cells)
|
||||
{
|
||||
DWORD wr = 0;
|
||||
DWORD out = 0;
|
||||
char formatted_output[255];
|
||||
|
@ -315,7 +325,8 @@ SendHorizontalScroll(HANDLE hInput, int cells) {
|
|||
}
|
||||
|
||||
void
|
||||
SendCharacter(HANDLE hInput, WORD attributes, wchar_t character) {
|
||||
SendCharacter(HANDLE hInput, WORD attributes, wchar_t character)
|
||||
{
|
||||
DWORD wr = 0;
|
||||
DWORD out = 0;
|
||||
DWORD current = 0;
|
||||
|
@ -403,7 +414,8 @@ SendCharacter(HANDLE hInput, WORD attributes, wchar_t character) {
|
|||
}
|
||||
|
||||
void
|
||||
SendBuffer(HANDLE hInput, CHAR_INFO *buffer, DWORD bufferSize) {
|
||||
SendBuffer(HANDLE hInput, CHAR_INFO *buffer, DWORD bufferSize)
|
||||
{
|
||||
if (bufferSize <= 0)
|
||||
return;
|
||||
|
||||
|
@ -412,14 +424,16 @@ SendBuffer(HANDLE hInput, CHAR_INFO *buffer, DWORD bufferSize) {
|
|||
}
|
||||
|
||||
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);
|
||||
currentLine = y;
|
||||
}
|
||||
|
||||
void
|
||||
SizeWindow(HANDLE hInput) {
|
||||
SizeWindow(HANDLE hInput)
|
||||
{
|
||||
SMALL_RECT srWindowRect;
|
||||
COORD coordScreen;
|
||||
BOOL bSuccess = FALSE;
|
||||
|
@ -472,7 +486,8 @@ SizeWindow(HANDLE hInput) {
|
|||
}
|
||||
|
||||
DWORD WINAPI
|
||||
MonitorChild(_In_ LPVOID lpParameter) {
|
||||
MonitorChild(_In_ LPVOID lpParameter)
|
||||
{
|
||||
WaitForSingleObject(child, INFINITE);
|
||||
GetExitCodeProcess(child, &child_exit_code);
|
||||
PostThreadMessage(hostThreadId, WM_APPEXIT, 0, 0);
|
||||
|
@ -480,7 +495,8 @@ MonitorChild(_In_ LPVOID lpParameter) {
|
|||
}
|
||||
|
||||
DWORD
|
||||
ProcessEvent(void *p) {
|
||||
ProcessEvent(void *p)
|
||||
{
|
||||
char f[255];
|
||||
wchar_t chUpdate;
|
||||
WORD wAttributes;
|
||||
|
@ -689,7 +705,8 @@ ProcessEvent(void *p) {
|
|||
}
|
||||
|
||||
DWORD WINAPI
|
||||
ProcessEventQueue(LPVOID p) {
|
||||
ProcessEventQueue(LPVOID p)
|
||||
{
|
||||
static SHORT lastX = 0;
|
||||
static SHORT lastY = 0;
|
||||
|
||||
|
@ -747,7 +764,8 @@ ProcessEventQueue(LPVOID p) {
|
|||
}
|
||||
|
||||
void
|
||||
QueueEvent(DWORD event, HWND hwnd, LONG idObject, LONG idChild) {
|
||||
QueueEvent(DWORD event, HWND hwnd, LONG idObject, LONG idChild)
|
||||
{
|
||||
consoleEvent* current = NULL;
|
||||
|
||||
EnterCriticalSection(&criticalSection);
|
||||
|
@ -786,7 +804,8 @@ QueueEvent(DWORD event, HWND hwnd, LONG idObject, LONG idChild) {
|
|||
}
|
||||
|
||||
DWORD WINAPI
|
||||
ProcessPipes(LPVOID p) {
|
||||
ProcessPipes(LPVOID p)
|
||||
{
|
||||
BOOL ret;
|
||||
DWORD dwStatus;
|
||||
|
||||
|
@ -838,12 +857,14 @@ ConsoleEventProc(HWINEVENTHOOK hWinEventHook,
|
|||
LONG idObject,
|
||||
LONG idChild,
|
||||
DWORD dwEventThread,
|
||||
DWORD dwmsEventTime) {
|
||||
DWORD dwmsEventTime)
|
||||
{
|
||||
QueueEvent(event, hwnd, idObject, idChild);
|
||||
}
|
||||
|
||||
DWORD
|
||||
ProcessMessages(void* p) {
|
||||
ProcessMessages(void* p)
|
||||
{
|
||||
BOOL ret;
|
||||
DWORD dwMode;
|
||||
DWORD dwStatus;
|
||||
|
@ -895,7 +916,8 @@ cleanup:
|
|||
}
|
||||
|
||||
int
|
||||
start_with_pty(int ac, wchar_t **av) {
|
||||
start_with_pty(int ac, wchar_t **av)
|
||||
{
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
wchar_t cmd[MAX_CMD_LEN];
|
||||
|
@ -1015,7 +1037,8 @@ HANDLE child_pipe_read;
|
|||
HANDLE child_pipe_write;
|
||||
|
||||
DWORD WINAPI
|
||||
MonitorChild_nopty( _In_ LPVOID lpParameter) {
|
||||
MonitorChild_nopty( _In_ LPVOID lpParameter)
|
||||
{
|
||||
WaitForSingleObject(child, INFINITE);
|
||||
GetExitCodeProcess(child, &child_exit_code);
|
||||
CloseHandle(pipe_in);
|
||||
|
@ -1023,7 +1046,8 @@ MonitorChild_nopty( _In_ LPVOID lpParameter) {
|
|||
}
|
||||
|
||||
int
|
||||
start_withno_pty(int ac, wchar_t **av) {
|
||||
start_withno_pty(int ac, wchar_t **av)
|
||||
{
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
wchar_t cmd[MAX_CMD_LEN];
|
||||
|
@ -1157,7 +1181,8 @@ cleanup:
|
|||
}
|
||||
|
||||
int
|
||||
wmain(int ac, wchar_t **av) {
|
||||
wmain(int ac, wchar_t **av)
|
||||
{
|
||||
/* create job to hold all child processes */
|
||||
HANDLE job = CreateJobObject(NULL, NULL);
|
||||
JOBOBJECT_EXTENDED_LIMIT_INFORMATION job_info;
|
||||
|
|
|
@ -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 */
|
||||
static VOID CALLBACK
|
||||
ReadAPCProc(_In_ ULONG_PTR dwParam) {
|
||||
ReadAPCProc(_In_ ULONG_PTR dwParam)
|
||||
{
|
||||
struct w32_io* pio = (struct w32_io*)dwParam;
|
||||
debug3("TermRead CB - io:%p, bytes: %d, pending: %d, error: %d", pio, read_status.transferred,
|
||||
pio->read_details.pending, read_status.error);
|
||||
|
@ -68,7 +69,8 @@ ReadAPCProc(_In_ ULONG_PTR dwParam) {
|
|||
|
||||
/* Read worker thread */
|
||||
static DWORD WINAPI
|
||||
ReadConsoleThread(_In_ LPVOID lpParameter) {
|
||||
ReadConsoleThread(_In_ LPVOID lpParameter)
|
||||
{
|
||||
int nBytesReturned = 0;
|
||||
struct w32_io* pio = (struct w32_io*)lpParameter;
|
||||
|
||||
|
@ -91,7 +93,8 @@ ReadConsoleThread(_In_ LPVOID lpParameter) {
|
|||
|
||||
/* Initiates read on tty */
|
||||
int
|
||||
termio_initiate_read(struct w32_io* pio) {
|
||||
termio_initiate_read(struct w32_io* pio)
|
||||
{
|
||||
HANDLE read_thread;
|
||||
|
||||
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 */
|
||||
static VOID CALLBACK
|
||||
WriteAPCProc(_In_ ULONG_PTR dwParam) {
|
||||
WriteAPCProc(_In_ ULONG_PTR dwParam)
|
||||
{
|
||||
struct w32_io* pio = (struct w32_io*)dwParam;
|
||||
debug3("TermWrite CB - io:%p, bytes: %d, pending: %d, error: %d", pio, write_status.transferred,
|
||||
pio->write_details.pending, write_status.error);
|
||||
|
@ -134,7 +138,8 @@ WriteAPCProc(_In_ ULONG_PTR dwParam) {
|
|||
|
||||
/* Write worker thread */
|
||||
static DWORD WINAPI
|
||||
WriteThread(_In_ LPVOID lpParameter) {
|
||||
WriteThread(_In_ LPVOID lpParameter)
|
||||
{
|
||||
struct w32_io* pio = (struct w32_io*)lpParameter;
|
||||
char *respbuf = NULL;
|
||||
size_t resplen = 0;
|
||||
|
@ -166,7 +171,8 @@ WriteThread(_In_ LPVOID lpParameter) {
|
|||
|
||||
/* Initiates write on tty */
|
||||
int
|
||||
termio_initiate_write(struct w32_io* pio, DWORD num_bytes) {
|
||||
termio_initiate_write(struct w32_io* pio, DWORD num_bytes)
|
||||
{
|
||||
HANDLE write_thread;
|
||||
debug3("TermWrite initiate io:%p", pio);
|
||||
memset(&write_status, 0, sizeof(write_status));
|
||||
|
@ -185,7 +191,8 @@ termio_initiate_write(struct w32_io* pio, DWORD num_bytes) {
|
|||
|
||||
/* tty close */
|
||||
int
|
||||
termio_close(struct w32_io* pio) {
|
||||
termio_close(struct w32_io* pio)
|
||||
{
|
||||
debug2("termio_close - pio:%p", pio);
|
||||
HANDLE h;
|
||||
CancelIoEx(WINHANDLE(pio), NULL);
|
||||
|
|
|
@ -79,7 +79,8 @@ void queue_terminal_window_change_event();
|
|||
* a global buffer setup by ReadConsoleForTermEmul().
|
||||
*/
|
||||
int
|
||||
NetWriteString2(SOCKET sock, char* source, size_t len, int options) {
|
||||
NetWriteString2(SOCKET sock, char* source, size_t len, int options)
|
||||
{
|
||||
while (len > 0) {
|
||||
if (glob_outlen >= glob_space)
|
||||
return glob_outlen;
|
||||
|
@ -91,7 +92,8 @@ NetWriteString2(SOCKET sock, char* source, size_t len, int options) {
|
|||
}
|
||||
|
||||
BOOL
|
||||
DataAvailable(HANDLE h) {
|
||||
DataAvailable(HANDLE h)
|
||||
{
|
||||
DWORD dwRet = WaitForSingleObject(h, INFINITE);
|
||||
if (dwRet == WAIT_OBJECT_0)
|
||||
return TRUE;
|
||||
|
@ -101,7 +103,8 @@ DataAvailable(HANDLE h) {
|
|||
}
|
||||
|
||||
int
|
||||
ReadConsoleForTermEmul(HANDLE hInput, char *destin, int destinlen) {
|
||||
ReadConsoleForTermEmul(HANDLE hInput, char *destin, int destinlen)
|
||||
{
|
||||
HANDLE hHandle[] = { hInput, NULL };
|
||||
DWORD nHandle = 1;
|
||||
DWORD dwInput = 0;
|
||||
|
|
|
@ -45,7 +45,8 @@
|
|||
* are hardcoded in the server and will be transformed to Windows Console commands.
|
||||
*/
|
||||
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* pszNewHead = NULL;
|
||||
unsigned char* pszHead = NULL;
|
||||
|
|
Loading…
Reference in New Issue