use GUSITTY socket instead of GUSISIOUX

This commit is contained in:
chombier 2001-03-17 13:08:36 +00:00
parent df8be15e20
commit abbdb88474
1 changed files with 172 additions and 116 deletions

View File

@ -31,12 +31,15 @@
#include "Connections.proto.h" #include "Connections.proto.h"
#include "ssh2.h" #include "ssh2.h"
#include "GUSITTY.h"
extern void syslog( int priority, const char *format, ...); extern void syslog( int priority, const char *format, ...);
static void accept_call(); static void accept_call();
static void check_listener(); static void check_listener();
/* /*
* The following four functions provide the UI for the console package. * The following four functions provide the UI for the console package.
* Users wishing to replace SIOUX with their own console package need * Users wishing to replace SIOUX with their own console package need
@ -73,6 +76,117 @@ void RemoveConsole(void)
{ {
} }
/*
* extern long WriteCharsToConsole(char *buffer, long n);
*
* Writes a stream of output to the Console window. This function is
* called by write.
*
* char *buffer: Pointer to the buffer to be written.
* long n: The length of the buffer to be written.
* returns short: Actual number of characters written to the stream,
* -1 if an error occurred.
*/
long WriteCharsToConsole(char *buffer, long n)
{
/* since we redirect stdin/out/err to our 'sockets'
* this shouldn't occur ! (or lsh calls printf ? (; )
*/
DebugStr("\pWriteCharsToConsole");
return n;
}
/*
* extern long ReadCharsFromConsole(char *buffer, long n);
*
* Reads from the Console into a buffer. This function is called by
* read.
*
* char *buffer: Pointer to the buffer which will recieve the input.
* long n: The maximum amount of characters to be read (size of
* buffer).
* returns short: Actual number of characters read from the stream,
* -1 if an error occurred.
*/
long ReadCharsFromConsole(char *buffer, long n)
{
/* since we redirect stdin/out/err to our 'sockets'
* this shouldn't occur ! (or lsh calls printf ? (; )
*/
DebugStr("\pReadCharsFromConsole");
return 0;
}
/*
* extern char *__ttyname(long fildes);
*
* Return the name of the current terminal (only valid terminals are
* the standard stream (ie stdin, stdout, stderr).
*
* long fildes: The stream to query.
*
* returns char*: A pointer to static global data which contains a C string
* or NULL if the stream is not valid.
*/
extern char *__ttyname(long fildes)
{
#pragma unused (fildes)
/* all streams have the same name */
static char *__devicename = "null device";
if (fildes >= 0 && fildes <= 2)
return (__devicename);
return (0L);
}
/* Begin mm 981218 */
/*
*
* int kbhit()
*
* returns true if any keyboard key is pressed without retrieving the key
* used for stopping a loop by pressing any key
*/
int kbhit(void)
{
return 0;
}
/*
*
* int getch()
*
* returns the keyboard character pressed when an ascii key is pressed
* used for console style menu selections for immediate actions.
*/
int getch(void)
{
return 0;
}
/*
* void clrscr()
*
* clears screen
*/
void clrscr()
{
return;
}
/* End mm 981218 */
/* Change record
* mm 981218 Added stubs for kbhit(), getch(), and clrscr()
*/
#pragma mark -
/* /*
* accept_call * accept_call
*/ */
@ -173,61 +287,29 @@ static long read_local_socket(lshcontext *context, char *buffer, long n)
} }
#pragma mark -
/* /*
* can_read * InstallTTY
*/ */
int InstallTTY(int fd, int flags)
Boolean can_read()
{ {
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); #pragma unused (fd)
return 0;
if ( !context ) {
return 0;
}
if ( context->_listener != -1 ) {
struct fd_set rfds;
struct fd_set efds;
struct timeval timeout;
FD_ZERO( &rfds );
FD_ZERO( &efds );
FD_SET( context->_listener, &rfds );
if ( context->_socket != -1 ) {
FD_SET( context->_socket, &rfds );
FD_SET( context->_socket, &efds );
}
timeout.tv_sec = 0;
timeout.tv_usec = 0;
if ( select( 32, &rfds, NULL, &efds, &timeout ) ) {
if ( context->_socket == -1 ) {
if ( FD_ISSET( context->_listener, &rfds ) ) {
accept_call();
}
} else {
if ( FD_ISSET( context->_socket, &efds ) ) {
close( context->_socket );
context->_socket = -1;
} else if ( FD_ISSET( context->_socket, &rfds ) ) {
return 1;
}
}
}
}
return context->_gConsoleInBufLen || context->_gConsoleInEOF;
} }
/* /*
* extern long WriteCharsToConsole(char *buffer, long n); * RemoveTTY
*
* Writes a stream of output to the Console window. This function is
* called by write.
*
* char *buffer: Pointer to the buffer to be written.
* long n: The length of the buffer to be written.
* returns short: Actual number of characters written to the stream,
* -1 if an error occurred.
*/ */
void RemoveTTY(int fd, int flags)
{
#pragma unused (fd)
}
long WriteCharsToConsole(char *buffer, long n) /*
* WriteCharsToTTY
*/
int WriteCharsToTTY(int fd, int flags, char *buffer, int n)
{ {
long written = 0; long written = 0;
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
@ -238,6 +320,12 @@ long WriteCharsToConsole(char *buffer, long n)
return 0; return 0;
} }
if ( fd == 2 ) {
// log stderr to console
putlln( buffer, n );
return n;
}
if ( context->_listener != -1 ) { if ( context->_listener != -1 ) {
/* write data to local socket */ /* write data to local socket */
check_listener(); check_listener();
@ -321,19 +409,9 @@ long WriteCharsToConsole(char *buffer, long n)
} }
/* /*
* extern long ReadCharsFromConsole(char *buffer, long n); * ReadCharsFromTTY
*
* Reads from the Console into a buffer. This function is called by
* read.
*
* char *buffer: Pointer to the buffer which will recieve the input.
* long n: The maximum amount of characters to be read (size of
* buffer).
* returns short: Actual number of characters read from the stream,
* -1 if an error occurred.
*/ */
int ReadCharsFromTTY(int fd, int flags, char *buffer, int n)
long ReadCharsFromConsole(char *buffer, long n)
{ {
long len = 0; long len = 0;
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey); lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
@ -383,65 +461,43 @@ long ReadCharsFromConsole(char *buffer, long n)
} }
/* /*
* extern char *__ttyname(long fildes); * AvailableFromTTY
*
* Return the name of the current terminal (only valid terminals are
* the standard stream (ie stdin, stdout, stderr).
*
* long fildes: The stream to query.
*
* returns char*: A pointer to static global data which contains a C string
* or NULL if the stream is not valid.
*/ */
int AvailableFromTTY(int id, int flags)
extern char *__ttyname(long fildes)
{ {
#pragma unused (fildes) lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
/* all streams have the same name */
static char *__devicename = "null device";
if (fildes >= 0 && fildes <= 2) if ( !context ) {
return (__devicename); return 0;
}
return (0L); if ( context->_listener != -1 ) {
struct fd_set rfds;
struct fd_set efds;
struct timeval timeout;
FD_ZERO( &rfds );
FD_ZERO( &efds );
FD_SET( context->_listener, &rfds );
if ( context->_socket != -1 ) {
FD_SET( context->_socket, &rfds );
FD_SET( context->_socket, &efds );
}
timeout.tv_sec = 0;
timeout.tv_usec = 0;
if ( select( 32, &rfds, NULL, &efds, &timeout ) ) {
if ( context->_socket == -1 ) {
if ( FD_ISSET( context->_listener, &rfds ) ) {
accept_call();
}
} else {
if ( FD_ISSET( context->_socket, &efds ) ) {
close( context->_socket );
context->_socket = -1;
} else if ( FD_ISSET( context->_socket, &rfds ) ) {
return 1;
}
}
}
}
return context->_gConsoleInBufLen || context->_gConsoleInEOF;
} }
/* Begin mm 981218 */
/*
*
* int kbhit()
*
* returns true if any keyboard key is pressed without retrieving the key
* used for stopping a loop by pressing any key
*/
int kbhit(void)
{
return 0;
}
/*
*
* int getch()
*
* returns the keyboard character pressed when an ascii key is pressed
* used for console style menu selections for immediate actions.
*/
int getch(void)
{
return 0;
}
/*
* void clrscr()
*
* clears screen
*/
void clrscr()
{
return;
}
/* End mm 981218 */
/* Change record
* mm 981218 Added stubs for kbhit(), getch(), and clrscr()
*/