updated for GUSITTY Sockets

This commit is contained in:
chombier 2001-03-17 13:14:36 +00:00
parent 1ebdfdbce5
commit be79f793e3
15 changed files with 260 additions and 126 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -38,7 +38,6 @@ int dup(int s);
int socket(int domain, int type, int protocol);
int close(int s);
Boolean can_read();
void ssh2_doevent(long sleepTime);
void add_one_file(struct lshcontext *context, int fd);
void remove_one_file(struct lshcontext *context, int fd);
@ -341,7 +340,7 @@ void ssh2_init()
if ( !sGUSISetup ) {
GUSIContext::Setup(true);
GUSISetupConsole();
/*GUSISetupConsole();*/
sGUSISetup = true;
}
}

View File

@ -26,6 +26,7 @@
#include "werror.h"
#include <assert.h>
/*#include <console.h>*/
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
@ -36,9 +37,12 @@
#include <setjmp.h>
#include <termios.h>
#include <CodeFragments.h>
#include <TextUtils.h>
#include "MemPool.h"
@ -48,8 +52,6 @@ extern pascal void __terminate(void);
pascal OSErr __lsh_initialize(const CFragInitBlock * theInitBlock);
pascal void __lsh_terminate(void);
FSSpec gDLLFileSpec;
Boolean gLogStdIO = 0;
@ -537,6 +539,152 @@ pascal Ptr PLstrrchr(ConstStr255Param s, short c)
}
#pragma mark -
/*
* InstallTTY
*/
int InstallTTY(int fd, int flags)
{
#pragma unused (fd)
return 0;
}
/*
* RemoveTTY
*/
void RemoveTTY(int fd, int flags)
{
#pragma unused (fd)
}
/*
* WriteCharsToTTY
*/
int WriteCharsToTTY(int fd, int flags, char *buffer, int n)
{
long written = 0;
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
char *buf = buffer;
char c;
if ( !context ) {
return 0;
}
if ( context->_gConsoleOutBufMax ) {
if ( context->_socket == -1 ) {
while (n > 0) {
if ( context->_gConsoleOutBufLen < context->_gConsoleOutBufMax ) {
long len = n;
if ( len > context->_gConsoleOutBufMax - context->_gConsoleOutBufLen ) {
len = context->_gConsoleOutBufMax - context->_gConsoleOutBufLen;
}
if ( context->_convertLFs ) {
long inlen = 0;
long outlen = context->_gConsoleOutBufLen;
/*
while (inlen < len && outlen < context->_gConsoleOutBufMax - 1) {
c = buf[inlen++];
if ( c == 0x0a ) {
context->_gConsoleOutBuf[outlen++] = 0x0d;
}
context->_gConsoleOutBuf[outlen++] = c;
}
*/
while (inlen < len && outlen < context->_gConsoleOutBufMax - 1) {
c = buf[inlen++];
if ( context->_lastCR ) {
if ( c != 0x0a && c != 0x1b )
context->_gConsoleOutBuf[outlen++] = 0x0a;
} else {
if ( c == 0x0a )
context->_gConsoleOutBuf[outlen++] = 0x0d;
}
context->_gConsoleOutBuf[outlen++] = c;
context->_lastCR = (c == 0x0d);
}
context->_gConsoleOutBufLen = outlen;
buf += inlen;
written += inlen;
n -= inlen;
} else {
BlockMoveData( buf, context->_gConsoleOutBuf + context->_gConsoleOutBufLen, len);
/*context->_lastCR = (buf[len-1] == 0x0d);*/
context->_gConsoleOutBufLen += len;
buf += len;
written += len;
n -= len;
}
}
ssh2_sched();
}
}
} else {
written = n;
}
/*
syslog( 0, "write\n");
dumpln(0, 0, buffer, written);
*/
return written;
}
/*
* ReadCharsFromTTY
*/
int ReadCharsFromTTY(int fd, int flags, char *buffer, int n)
{
long len = 0;
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
if ( !context ) {
return 0;
}
if ( context->_gConsoleInBufMax ) {
while (!len && n > 0) {
if (context->_gConsoleInEOF) {
buffer[0] = EOF;
return 0;
}
if (context->_gConsoleInBufLen && context->_socket == -1 ) {
len = context->_gConsoleInBufLen;
if ( len > n ) {
len = n;
}
BlockMoveData( context->_gConsoleInBuf, buffer, len );
context->_gConsoleInBufLen -= len;
if ( context->_gConsoleInBufLen ) {
BlockMoveData( context->_gConsoleInBuf + len, context->_gConsoleInBuf, context->_gConsoleInBufLen );
}
}
ssh2_sched();
}
} else {
buffer[0] = EOF;
}
/*
syslog( 0, "read\n");
dumpln(0, 0, buffer, len);
*/
return len;
}
/*
* AvailableFromTTY
*/
int AvailableFromTTY(int id, int flags)
{
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
if ( !context ) {
return 0;
}
return context->_gConsoleInBufLen || context->_gConsoleInEOF;
}
#pragma mark -
/*
@ -634,7 +782,6 @@ void ssh2_doevent(long sleepTime)
}
}
#pragma mark -
@ -1183,7 +1330,7 @@ pascal void __lsh_terminate(void)
{
__terminate();
/* kill pending threads in local thread poll */
/* kill pending threads in local thread pool */
/* TODO */
}

View File

@ -2,33 +2,19 @@
#include "lsh_context.h"
#include <GUSIInternal.h>
#include <GUSIBasics.h>
#include <GUSIContext.h>
#include <GUSIConfig.h>
#include <GUSIDiag.h>
#include <GUSISocket.h>
#include <GUSIPThread.h>
#include <GUSIFactory.h>
#include <GUSIDevice.h>
#include <GUSIDescriptor.h>
#include <GUSIFileSpec.h>
#include <pthread.h>
#include <sched.h>
#include <sys/stat.h>
#include <unistd.h>
#ifndef __CONSOLE__
#include <console.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
void ssh2_sched();
Boolean can_read();
void ssh2_doevent(long sleepTime);
char *getprefsd(char *name, char *buf, size_t size, short *vRefNum, long *dirID);
#ifdef __cplusplus
@ -36,60 +22,6 @@ char *getprefsd(char *name, char *buf, size_t size, short *vRefNum, long *dirID)
#endif
/*
* default GUSIHandleNextEvent is GUSI's main event loop
*/
void GUSIHandleNextEvent(long sleepTime)
{
ssh2_doevent( sleepTime );
}
/*
* default GUSISIOUXSocket::select checks for keyDown or
* autoKey events from MacOS's EventQueue.
* we use an internal buffer.
*/
class GUSISIOUXSocket : public GUSISocket {
public:
~GUSISIOUXSocket();
ssize_t read(const GUSIScatterer & buffer);
ssize_t write(const GUSIGatherer & buffer);
virtual int ioctl(unsigned int request, va_list arg);
virtual int fstat(struct stat * buf);
virtual int isatty();
bool select(bool * canRead, bool * canWrite, bool *);
static GUSISIOUXSocket * Instance();
private:
static GUSISIOUXSocket * sInstance;
GUSISIOUXSocket();
};
bool GUSISIOUXSocket::select(bool * canRead, bool * canWrite, bool *)
{
bool cond = false;
if (canRead) {
if (*canRead = can_read())
cond = true;
}
if (canWrite)
cond = *canWrite = true;
return cond;
}
/* we don't use SIOUX event handler */
GUSISIOUXSocket::GUSISIOUXSocket()
{
InstallConsole(0);
}
/*
* ssh2_sched
*/
@ -99,8 +31,6 @@ void ssh2_sched()
sched_yield();
}
/*
* getprefsd return the full path of prefs directory
*/

View File

@ -6,6 +6,7 @@
#include "lsh_context.h"
#include <pthread.h>
#include <console.h>
#include <sched.h>
#include "GUSIMSLSetup.h"
@ -14,6 +15,8 @@
extern "C" {
#endif
void GUSIwithTTYSockets();
void ssh2_init();
void add_one_file(struct lshcontext *context, int fd);
@ -23,6 +26,11 @@ void remove_one_file(struct lshcontext *context, int fd);
}
#endif
/*
GusiMSLWriteConsole sWriteConsole = 0L;
GusiMSLWriteConsole sInConsole = 0L;
*/
static void myGusiMSLAddFile(int fd)
{
lshcontext *context = (lshcontext *)pthread_getspecific(ssh2threadkey);
@ -48,8 +56,18 @@ void ssh2_init()
static Boolean sGUSISetup = false;
if ( !sGUSISetup ) {
GUSIwithTTYSockets();
GusiMSLSetAddFile(myGusiMSLAddFile);
GusiMSLSetRemoveFile(myGusiMSLRemoveFile);
/*
sWriteConsole = GusiMSLGetWriteConsole();
sInConsole = GusiMSLGetInConsole();
GusiMSLSetWriteConsole(WriteCharsToConsole);
GusiMSLSetInConsole(ReadCharsFromConsole);
*/
}
}

View File

@ -306,8 +306,8 @@
#define MACOS 1
#define LSH 1
#define HAVE_STDTTY_FILENO 1
#define STDTTY_FILENO 0
/*#define HAVE_STDTTY_FILENO 1*/
/*#define STDTTY_FILENO 0*/
#define SIOUX_USE_WASTE 1
#define exit macosexit

View File

@ -11,6 +11,7 @@
#include "werror.h"
#include <assert.h>
#include <console.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
@ -21,7 +22,10 @@
#include <setjmp.h>
#include <termios.h>
#include <Events.h>
#include <Fonts.h>
#include <LowMem.h>
#include <OSUtils.h>
#include "PasswordDialog.h"
#include "MemPool.h"
@ -483,6 +487,63 @@ pascal Ptr PLstrrchr(ConstStr255Param s, short c)
return NULL;
}
#pragma mark -
/*
* InstallTTY
*/
int InstallTTY(int id, int flags)
{
#pragma unused (id, flags)
return 0;
}
/*
* RemoveTTY
*/
void RemoveTTY(int id, int flags)
{
#pragma unused (id, flags)
}
/*
* WriteCharsToTTY
*/
int WriteCharsToTTY(int id, int flags, char *buffer, int n)
{
#pragma unused (id, flags)
return WriteCharsToConsole(buffer, n);
}
/*
* ReadCharsFromTTY
*/
int ReadCharsFromTTY(int id, int flags, char *buffer, int n)
{
#pragma unused (id, flags)
return ReadCharsFromConsole(buffer, n);
}
/*
* AvailableFromTTY
*/
int AvailableFromTTY(int id, int flags)
{
#pragma unused (id, flags)
extern short gSIOUXBufSize;
if ( !gSIOUXBufSize ) {
QHdrPtr eventQueue = LMGetEventQueue();
EvQElPtr element = (EvQElPtr)eventQueue->qHead;
// now, count the number of pending keyDown events.
while (element != nil) {
if (element->evtQWhat == keyDown || element->evtQWhat == autoKey)
return true;
element = (EvQElPtr)element->qLink;
}
return false;
}
return true;
}
#pragma mark -

View File

@ -568,7 +568,7 @@ werror(const char *format, ...)
if (gLogStdIO || (!context->_tracing && !context->_verbosing && !context->_debugging)) {
if (!gLogStdIO) {
werror_flush();
set_error_stream(STDOUT_FILENO, 0);
set_error_stream(STDERR_FILENO, 0);
}
}
va_start(args, format);
@ -651,7 +651,7 @@ fatal(const char *format, ...)
if (context)
{
werror_flush();
set_error_stream(STDOUT_FILENO, 0);
set_error_stream(STDERR_FILENO, 0);
va_start(args, format);
werror_vformat(format, args);
va_end(args);

View File

@ -1080,7 +1080,7 @@ char *applname = "lsh";
//char *defargstr = "-lnono --debug --verbose --trace 192.168.1.41";
//char *defargstr = "-ljps -z --debug --verbose --trace 192.168.1.41";
//char *defargstr = "-ljps -zzlib --verbose -L22:192.168.1.41:22 192.168.1.41";
char *defargstr = "-ljps -zzlib --verbose 192.168.1.41";
char *defargstr = "-ljps -mmd5 -zzlib --stdin dev:tty --stdout dev:tty --sloppy-host-authentication --verbose 192.168.1.41";
//char *defargstr = "-ljps -zzlib --debug --verbose --trace -L23:192.168.1.41:22 192.168.1.41";
//char *defargstr = "-ljps -znone 192.168.1.41";
//char *defargstr = "-lwebmaster -znone --debug --verbose --trace --sloppy-host-authentication www.tldnames.com";

View File

@ -385,7 +385,11 @@ make_unix_interact(struct io_backend *backend)
if (isatty(STDTTY_FILENO))
self->tty_fd = STDTTY_FILENO;
#else /* ! HAVE_STDTTY_FILENO */
#if MACOS
self->tty_fd = open("dev:tty", O_RDWR);
#else
self->tty_fd = open("/dev/tty", O_RDWR);
#endif
#endif
if (backend && (self->tty_fd >= 0))

View File

@ -64,7 +64,6 @@ int socket(int domain, int type, int protocol);
int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
int close(int s);
Boolean can_read();
void ssh2_doevent(long sleepTime);
void add_one_file(struct lshcontext *context, int fd);
void remove_one_file(struct lshcontext *context, int fd);
@ -74,6 +73,7 @@ void remove_one_file(struct lshcontext *context, int fd);
#endif
extern pthread_key_t ssh2threadkey;
extern int g_error_fd;
/*
* ssh2_init
@ -89,10 +89,11 @@ void ssh2_init()
/* this call initializes the resolver with current context */
gethostid();
GUSISetupConsole();
/*GUSISetupConsole();*/
sGUSISetup = true;
}
g_error_fd = open("dev:ttyerr", O_WRONLY );
}
}
/*
@ -162,49 +163,13 @@ void GUSIHandleNextEvent(long sleepTime)
}
/*
* default GUSISIOUXSocket::select checks for keyDown or
* autoKey events from MacOS's EventQueue.
* we use an internal buffer.
*/
class GUSISIOUXSocket : public GUSISocket {
public:
~GUSISIOUXSocket();
ssize_t read(const GUSIScatterer & buffer);
ssize_t write(const GUSIGatherer & buffer);
virtual int ioctl(unsigned int request, va_list arg);
virtual int fstat(struct stat * buf);
virtual int isatty();
bool select(bool * canRead, bool * canWrite, bool *);
static GUSISIOUXSocket * Instance();
private:
static GUSISIOUXSocket * sInstance;
GUSISIOUXSocket();
};
bool GUSISIOUXSocket::select(bool * canRead, bool * canWrite, bool *)
{
bool cond = false;
if (canRead) {
if (*canRead = can_read())
cond = true;
}
if (canWrite)
cond = *canWrite = true;
return cond;
}
/* we don't use SIOUX event handler */
/*
GUSISIOUXSocket::GUSISIOUXSocket()
{
InstallConsole(0);
}
*/
/*
* default GUSIProcess::Yield has 20 ticks to remain in same state

View File

@ -153,6 +153,8 @@ const struct termios defaulttermios = {
/* true if we log werror/trace... to stdio, false => log to syslog */
Boolean gLogStdIO = 0;
int g_error_fd = -1;
pthread_key_t ssh2threadkey = NULL;
char homepath[256];
@ -1095,7 +1097,10 @@ void init_context(lshcontext *context, short port)
context->_verbose_flag = 0;
context->_trace_flag = 0;
context->_debug_flag = 0;
context->_error_fd = STDERR_FILENO;
/*context->_error_fd = STDERR_FILENO;*/
context->_error_fd = g_error_fd;
context->_error_pos = 0;
context->_error_write = write_raw;
context->_tracing = 0;
@ -1267,6 +1272,8 @@ static int build_cmdline(WindRec*w, char *argstr)
strcat(argstr, getenv("HOME")); /* 256 */
strcat(argstr, "known_hosts\"");
strcat(argstr, " --stdin dev:ttyin --stdout dev:ttyout --stderr dev:ttyerr");
if (!w->restricted)
strcat(argstr, " --sloppy-host-authentication");

View File

@ -68,6 +68,7 @@ int verbose_flag = 0;
int syslog_flag = 0;
#else
extern Boolean gLogStdIO;
extern int g_error_fd;
#endif
#define WERROR_TRACE -1
@ -568,7 +569,8 @@ werror(const char *format, ...)
if (gLogStdIO || (!context->_tracing && !context->_verbosing && !context->_debugging)) {
if (!gLogStdIO) {
werror_flush();
set_error_stream(STDOUT_FILENO, 0);
/*set_error_stream(STDOUT_FILENO, 0);*/
set_error_stream(g_error_fd, 0);
}
}
va_start(args, format);
@ -651,7 +653,8 @@ fatal(const char *format, ...)
if (context)
{
werror_flush();
set_error_stream(STDOUT_FILENO, 0);
/*set_error_stream(STDOUT_FILENO, 0);*/
set_error_stream(g_error_fd, 0);
va_start(args, format);
werror_vformat(format, args);
va_end(args);