Commit Graph

85 Commits

Author SHA1 Message Date
Ryan Prichard
44554d5e9d Add an MIT copyright notice to all the source files. 2012-03-23 03:11:34 -07:00
Ryan Prichard
d3667e38a8 Review the named pipe setup code.
The goal is to setup pipes between the libpconsole process and the new
agent process in a way that's secure and doesn't create an unnecessary
burden on the library's user.  This is apparently hard.

I think this code is good enough.
2012-03-23 02:19:09 -07:00
Ryan Prichard
d568fbdeb4 Add DsrSender.h. 2012-03-21 03:31:34 -07:00
Ryan Prichard
d418679741 Include stdint.h to provide int32_t.
* This fixed a libpconsole build error that happened with mingw-w64.
2012-03-21 03:30:18 -07:00
Ryan Prichard
f66e877cba Improve error handling in libpconsole.
If we couldn't create the new pipes, then perhaps some other process has
already created them.  I think it's a security hole to start the agent if
the pipe creation failed.
2012-03-21 03:28:31 -07:00
Ryan Prichard
7e6f8195ba Turn on -Wall and fix build warnings. No bug fixes. 2012-03-21 00:14:04 -07:00
Ryan Prichard
0afc69c733 Move the three output binaries into a build directory. 2012-03-21 00:13:46 -07:00
Ryan Prichard
4cfb5e1c73 Expand a comment. 2012-03-20 23:46:12 -07:00
Ryan Prichard
f397150b6c Add some TODO items. 2012-03-20 23:45:59 -07:00
Ryan Prichard
0260b423a3 Continue working on console input.
* Remove most of the encoding table and instead generate the KeyDescriptor
   entries dynamically at startup.

 * I think I'm handling input tolerably well for TERM=xterm terminals, but
   I removed the support I had for rxvt for now.  I don't think it makes
   sense to fill out the table, but the new code I have for TERM=xterm is
   also bloated.
2012-03-20 04:15:25 -07:00
Ryan Prichard
1fdda9e1d4 Work on console input handling.
* If bytes are still queued after processing as many keypresses as
   possible, send a DSR to the console.  The console should respond with
   a DSR reply, which will flush out the input buffer without having to
   wait for a timeout.

 * Add ah hoc code for ALT-<character> rather than listing every character
   in the table.

 * When keypresses have Alt/Ctrl/Shift modifiers, generate extra
   INPUT_RECORDS to press and release each modifier.  EDIT.COM seemed to
   require these for some Ctrl-<key> keypresses I tried.
2012-03-20 02:04:46 -07:00
Ryan Prichard
d32e36032d Fix an bug in ConsoleInput::appendChar: set dwControlKeyState. 2012-03-19 22:14:34 -07:00
Ryan Prichard
98970ead5c Use ESC and CSI macros in ConsoleInput::keyDescriptorTable. 2012-03-19 22:14:06 -07:00
Ryan Prichard
ac76cbcc20 Initial checkin of improved console input handling.
* Generate Ctrl-C events by calling GenerateConsoleCtrlEvent.

   I noticed that calls to this routine don't behave exactly the same as
   a real Ctrl-C keypress.  In Python, pressing Ctrl-C immediately
   displays a new "KeyboardInterrupt" line.  Calling
   GenerateConsoleCtrlEvent has no immediate effect, but after pressing
   Enter, Python displays a stack trace where a KeyboardInterrupt was
   raised.  After some testing, I suspect the issue is that a real Ctrl-C
   keypress interrupts a blocking console read, but
   GenerateConsoleCtrlEvent does not.

   I also tried synthesizing Ctrl-C using (a) PostMessage with
   WM_{CHAR,KEYDOWN}, and (b) SendInput.  I couldn't get either to work.

 * Recognize ESC sequences.  The set of recognized sequences is ad hoc.

 * Recognize UTF-8-encoded characters and convert them to UTF-16.

 * The code currently uses a timeout to differentiate between pressing ESC
   and pressing a key that generates an ESC sequence.  I have a theory that
   I can use the "Device Status Report" ESC sequences to avoid this
   timeout.
2012-03-19 21:30:16 -07:00
Ryan Prichard
0554f9fbde In Agent::handleStartProcessPacket, call GetLastError immediately after
CreateProcess.
2012-03-19 21:17:43 -07:00
Ryan Prichard
7dbe7537c3 Display Ctrl-C events in the ShowConsoleInput test program.
Now that Ctrl-C doesn't exit ShowConsoleInput, make the program exit when
the user hits ESC three times (3 up and 3 down for a total of 6 events).
2012-03-19 21:13:10 -07:00
Ryan Prichard
6b87c54d0d Try to improve the way color works in the agent.
* Assume that either:
    - The console has a white-on-black color scheme.  This could be set
      at agent startup.
    - The remote terminal also has a white-on-black color scheme, OR...
    - With a different color scheme, the white/black colors could be
      reversed, but the console is still usable.

 * The COMMON_LVB_REVERSE_VIDEO flag apparently has no effect in a Windows
   console, so ignore it in the agent too.

 * Start handling Unicode characters.  I noticed that box drawing
   characters (mc.exe / edit.com) are displayed correctly now.  I'm calling
   WideCharToMultiByte once per character, though, and I'm wondering if
   this is inefficient.
2012-03-15 04:08:58 -07:00
Ryan Prichard
affceb9ffd Fix a bug involving the Terminal::finishOutput call.
Before the Qt removal, Terminal::finishOutput accepted a QPoint object with
a 32-bit line number.  Changing it to accept Coord introduced a bug because
the Coord line number is only 16-bits.  The moveTerminalToLine and sendLine
methods still accepted a 32-bit line number, though.

The result was, after 32768 lines of output, the
Terminal::moveTerminalToLine function would be called alternately with
truncated and untruncated line numbers (e.g. -32000 and 33536), and the
function would generate massive amounts of "cursor up" and "newline"
output.
2012-03-15 02:11:03 -07:00
Ryan Prichard
81dcc5efe7 Fix SmallRect::intersected.
* Win32Console::reposition's resize/move API calls were failing because of
   this bug.
2012-03-15 02:01:41 -07:00
Ryan Prichard
a4f26594f0 Various changes intended to help with debugging.
* Replace Buffer::isEof with Buffer::eof so I can use the agent-specific
   ASSERT macro instead of the standard assert().

 * If an API call in Win32Console fails, print a message using Trace.

 * Add Coord::toString and SmallRect::toString functions.
2012-03-15 01:59:12 -07:00
Ryan Prichard
76f25ae5dd Checkpoint work on the EventLoop and NamedPipe classes.
* Make the agent work correctly when the child process exits.
2012-03-14 02:37:18 -07:00
Ryan Prichard
3dcda5d15d Remove these two unused C++ files. 2012-03-13 22:39:27 -07:00
Ryan Prichard
119c5e0117 Finish removing the Qt dependency. 2012-03-13 22:39:14 -07:00
Ryan Prichard
00eee82468 Add TODO comments. 2012-03-13 22:15:02 -07:00
Ryan Prichard
c949e03164 Checkpoint work to replace the Qt event loop and I/O code. 2012-03-13 22:14:39 -07:00
Ryan Prichard
39e07ca4d2 Fix a typo. 2012-03-13 22:03:48 -07:00
Ryan Prichard
d8b8403651 Begin removing the Qt dependency.
* Replace QPoint and QSize with Coord, a C++ class derived from COORD.

 * Replace QRect with SmallRect, a C++ class derived from SMALL_RECT.

 * Turn Win32Console into a non-QObject class.
2012-03-13 00:16:51 -07:00
Ryan Prichard
1901ed62d6 Add some TODO comments. 2012-02-20 04:54:18 -08:00
Ryan Prichard
8a89620cc3 Use -MMD instead of -MD. It keeps the dependency files smaller. 2012-02-20 03:36:36 -08:00
Ryan Prichard
e7c5342479 Make the unix-adapter work on MSYS.
- In my MSYS environment, gcc/g++ are the MinGW compilers that target
   Win32.  We really need compilers that target the MSYS environment.
   Add a config-unix.mk for building the unix-adapter.

 - My MSYS environment lacks a pipe2 function, but I can get the same
   effect using pipe and fcntl, so do that instead.
2012-02-20 03:34:14 -08:00
Ryan Prichard
00a6c3b90e Shut down the unix-adapter when the child process exits.
- In the agent, poll for the process exit at the same time we pull for
   output.  Once the child exits, record the exit code and close the data
   pipe.

 - In the unix-adapter, shut the program down once the input or output
   handlers abort.  Before exiting, query the agent for the exit code.

 - Also: in the unix-adapter, apparently receiving the SIGWINCH signal can
   interrupt both select and the InputHandler's read system call.  I hope
   it doesn't affect the blocking Win32 APIs, but I'm not really sure.
2012-02-20 03:30:43 -08:00
Ryan Prichard
90164c34a9 Get the agent + libpconsole + unix-adapter trio working.
- Update the Agent to use separate control and data pipes and to receive
   arbitrary-sized packets.  Handle child process creation in the agent.

 - Fix bugs in libpconsole:
    - Insert a space between the pipe names on the agent command line.
    - Don't close the desktop and window station until after connecting
      to the agent's pipes.

 - Change the format of the pconsole_start_process env parameter from an
   array of wide-character-string pointers to a single contiguous block of
   memory, like that accepted by CreateProcess.
2012-02-20 01:23:46 -08:00
Ryan Prichard
27f0c4d156 Get pconsole.exe and pconsole.dll building simultaneously.
* Remove obsolete comments and APIs.

 * In pconsole.exe, use two threads to handle pconsole<->pty communication.
   I use blocking I/O for the pty.  For the Win32 pipe to the pconsole
   agent, I use overlapped I/O and emulate blocking I/O.

   I'm not sure I *have* to open the pipe in overlapped mode.  When I last
   tried using non-overlapped I/O, I had a problem where a pending read
   would block writes (or vice versa).  Maybe setting the overlapped
   parameter to {Read,Write}File would be sufficient.
2012-02-16 03:49:17 -08:00
Ryan Prichard
40c7e87528 Checkpoint work on libpconsole. 2012-02-10 02:09:38 -08:00
Ryan Prichard
a53fcbbea6 Checkpoint work on libpconsole. 2012-01-31 00:45:04 -08:00
Ryan Prichard
19d9c1832c Add a Unix pty<->pconsole adapter. 2012-01-28 14:23:31 -08:00
Ryan Prichard
1aaf102905 Get libpconsole.dll building again with stubbed out functions. 2012-01-27 10:08:21 -08:00
Ryan Prichard
c0918b6db4 Update pconsole.h with a new non-blocking pconsole API.
This API is not implemented yet, so the code no longer builds after this
commit.
2012-01-27 09:05:34 -08:00
Ryan Prichard
b0555bbbcf Update the libpconsole's agent-finding code.
Look for the new pconsole-agent.exe program, and look for it in its new
location.
2012-01-23 22:05:37 -08:00
Ryan Prichard
410749a1b9 Update the TestNetServer.
- Replace the qmake pro file with a Makefile.

 - Move the AgentClient from Shared to TestNetServer.  This file is
   obsoleted by libpconsole.
2012-01-23 22:04:34 -08:00
Ryan Prichard
3abee55179 Work on agent's build system. 2012-01-21 17:39:22 -08:00
Ryan Prichard
4350fd40d5 Remove cruft. 2012-01-21 17:33:41 -08:00
Ryan Prichard
7e4c06c2e1 Rename Agent to agent. 2012-01-21 17:32:26 -08:00
Ryan Prichard
a4df196ed4 Work on switching from qmake to makefiles and reorganize code a little.
My plan now is to integrate the PseudoConsole with Cygwin and MSYS ptys,
with initial focus on Cygwin.  I think I'll keep the separate Agent and DLL
binaries, and they'll continue to be native Win32 binaries.  I don't want
to have two build systems (qmake vs whatever MSYS/Cygwin uses), and since
I'd like to remove the Qt dependency anyway, I'm trying to switch to
makefiles.
2012-01-21 17:30:41 -08:00
Ryan Prichard
e4e0effb03 Delete some dead code (Console directory) and reorganize. 2012-01-21 02:31:27 -08:00
Ryan Prichard
626849b253 Add TODO items. 2012-01-10 00:56:29 -08:00
Ryan Prichard
2aa8c26b55 Remove an unnecessary comment.
size_t wouldn't really be a reasonable type for Windows I/O because
ReadFile and WriteFile use a DWORD for byte counts.  A single I/O operation
of more than 2GB seems unreasonable anyway.
2012-01-09 01:02:11 -08:00
Ryan Prichard
a9d3250574 Remove an unused variable from AgentClient.cc. 2012-01-09 00:57:08 -08:00
Ryan Prichard
2345672c55 Add a PseudoConsole.dll library providing a client to the PseudoConsole
agent.

 * The code is based on that from AgentClient.cc, but without the Qt
   dependency.

 * The API currently uses blocking I/O.  The intent is for users to use
   a separate read thread and write thread.
2012-01-09 00:56:55 -08:00
Ryan Prichard
9ed85125db Comment out this line to reduce debug noise while I do performance testing. 2012-01-02 23:09:03 -08:00