VTTelnetSession.h
上传用户:wsk323
上传日期:2007-01-05
资源大小:403k
文件大小:4k
- /*---------------------------------------------------------------------------
- Copyright: E. Brady Trexler
- Creation: March 13, 1998 (based on MicroSoft Win32.hlp code snippet
- and F. Piette's telnet server demo).
- Description: VTTelnetSession -- class starting a command interpreter with pipes
- inherited from main application. Anonymous pipes are created for
- STDIN, STDOUT, and STDERR. Then, the child process (the command
- interpreter) is started. One thread is started that continuously
- checks for data from a socket and feeds this data to STDIN. Two
- other threads continously check for output from STDOUT and
- STDERR feed that back to the socket. If the "exit" command is
- given to the command interpreter, the STDOUT listening thread is
- exited and the socket is disconnected.
- Legal issues: Copyright (C) 1998 by E. Brady Trexler and Fran鏾is Piette
- This software is provided 'as-is', without any express or
- implied warranty. In no event will the author be held liable
- for any damages arising from the use of this software.
- Permission is granted to anyone to use this software for any
- purpose, excluding commercial applications, and to alter it
- and redistribute it freely, subject to the following
- restrictions:
- 1. The origin of this software must not be misrepresented,
- you must not claim that you wrote the original software.
- If you use this software in a product, an acknowledgment
- in the product documentation would be appreciated but is
- not required.
- 2. Altered source versions must be plainly marked as such, and
- must not be misrepresented as being the original software.
- 3. This notice may not be removed or altered from any source
- distribution.
- Updates:
- ---------------------------------------------------------------------------*/
- //---------------------------------------------------------------------------
- #ifndef VTSessionH
- #define VTSessionH
- //---------------------------------------------------------------------------
- #include <vclvcl.h>
- #pragma hdrstop
- #include "WSocket.hpp"
- #include "VTTelnetDaemon.h"
- #define BUFSIZE 4096
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- class VTSession : public TObject
- {
- private:
- PROCESS_INFORMATION piProcInfo;
- STARTUPINFO siStartInfo;
- protected:
- public:
- TVTDaemon* TheDaemon;
- HANDLE hChildStdinRd, hChildStdinWr, hChildStdinWrDup,
- hChildStdoutRd, hChildStdoutWr,
- hInputFile, hSaveStdin, hSaveStdout,
- hChildStderrRd, hChildStderrWr, hSaveStderr;
- HANDLE UserToken;
- TWSocket* Socket;
- AnsiString FCommand;
- AnsiString Connected, UserName, PassWord;
- AnsiString HomeDirectory;
- bool Leko;
- bool LoginSuccessful, userOK, passOK;
- bool SocketDataIsHere;
- bool SocketSessionIsOpen;
- bool FlushSocket;
- bool ChildProcessCreated;
- int EscSeq;
- int BufferLength;
- int numtries;
- char Buffer[4096];
- char hostname[256];
- sockaddr_in ConnectedAddr;
- void __fastcall ErrorExit (LPTSTR lpszMessage);
- void __fastcall SocketDataAvailable(TObject *Sender, WORD Error);
- void __fastcall SocketSessionClosed(TObject *Sender, WORD Error);
- void __fastcall StartCommandInterpreterAsChild();
- bool __fastcall CreateChildProcess();
- void __fastcall CommandInterpreter();
- void __fastcall ProcessChar(char Ch);
- bool __fastcall WaitForSocketData(char *data, DWORD &numchar);
- void __fastcall Validate();
- __fastcall VTSession(TVTDaemon *daemon);
- __fastcall ~VTSession(){}
- };
- void FeedSocketDataToSTDIN(void *session);
- void FeedSTDOUTDataToSocket(void *session);
- void FeedSTDERRDataToSocket(void *session);
- //---------------------------------------------------------------------------
- #endif