ftp.nice.ch/pub/next/connectivity/protocol/GateKeeper.3.0.Beta.4.s.tar.gz#/GateKeeper.3.0.Beta.4.s/DialServer.m

This is DialServer.m in view mode; [Download] [Up]

//*****************************************************************************
//
//	DialServer.m.  
//
//		Distributed Objects server which communicates with MODEM tool
//		during Manual dial.
//
//			by	Felipe A. Rodriguez		
//
//	This code is supplied "as is" the author makes no warranty as to its 
//	suitability for any purpose.  This code is free and may be distributed 
//	in accordance with the terms of the:
//		
//			GNU GENERAL PUBLIC LICENSE
//			Version 2, June 1991
//			copyright (C) 1989, 1991 Free Software Foundation, Inc.
// 			675 Mass Ave, Cambridge, MA 02139, USA
//
//*****************************************************************************

#import <appkit/nextstd.h>
#import <remote/NXProxy.h>

#import "GKdefs.h"
#import "DialServer.h"
#import "OptionsEditor.h"
#import "DLDelegate.h"			
#import "Coordinator.h"
#import "SwapLaterView.h"



@implementation DialServer

//*****************************************************************************
//
//		show Dialer panel 
//
//*****************************************************************************

- showDialPanel 
{
	connecting = NO;						
    if(!gatePanel)
		[NXApp loadNibSection:"Inspector.nib" owner:self withNames:NO];
    [theInspector inspectName:"FirstInspector"];		// swap inspectors
	[gatePanel setFrameUsingName:"gatePanel"];			// remem loc/size
	[gatePanel setFrameAutosaveName:"gatePanel"];		// remem loc/size
    [gatePanel makeKeyAndOrderFront:self];	
	[phoneNumField setStringValue:NXGetDefaultValue([NXApp appName], 	
														"lastNumDialed")];
	[phoneNumField selectText:self];
	
    return self;
}
//*****************************************************************************
//
// 		called when GateTool's mach port becomes invalid 
//
//*****************************************************************************

- senderIsInvalid:sender 
{
	if(gatePanel)
		[gatePanel close];
	if(!connecting)							// if not connecting clean up
		[[NXApp delegate] DOFinished];
	
    return self;
}
//*****************************************************************************
//
// 		send to the gatetool server the phone num to dial 
//
//*****************************************************************************

- Dial:sender  
{
char dialStr[56] = {"SEND "};

	shouldExit = NO;						
	strncat(dialStr, NXGetDefaultValue([NXApp appName], "dialPrefix"), 8);
	strcat(dialStr, [phoneNumField stringValue]);
		// store last num dialed in defaults database
	if(!NXWriteDefault([NXApp appName], "lastNumDialed", 
												[phoneNumField stringValue]))
		[[NXApp delegate] showAlert:"ddbWriteError"];
	[gateToolProxy enScript:strcat(dialStr, " ")];
    [theInspector inspectName:"SecondInspector"];		// swap inspectors

    return self;
}
//*****************************************************************************
//
// 		send to the gatetool server quit tip instruction 
//
//*****************************************************************************

- cancelDial:sender  
{
char minBuffer[] = {" "};
	
	shouldExit = YES;						
	minBuffer[0] = CINTR;
	[gateToolProxy writePty:minBuffer];

    return self;
}
//*****************************************************************************
//
// 		send to the gatetool server quit tip instruction 
//
//*****************************************************************************

- hangUp:sender  
{
char prefix[16] = {"PASS "}, minBuffer[3] = {"b "}, dialStr[16];
	
	minBuffer[0] = CEOF;
	strcpy(dialStr, prefix);
	[gateToolProxy enScript:strcat(dialStr, minBuffer)];
    [theInspector inspectName:"FirstInspector"];		// swap inspectors

    return self;
}
//*****************************************************************************
//
// 		engage pppd 
//
//*****************************************************************************

- Attach:sender  
{													
	[[NXApp delegate] playSound:"Klaxxon_Switch"];		// play ppp switch snd
	shouldExit = YES;						
	connecting = YES;						
	[gateToolProxy unlockSerialPort];
	[gateToolProxy enScript:"PASS ~. "];
	[[NXApp delegate] linkWithFile:NULL];	

    return self;
}
//*****************************************************************************
//
// 		self activate 
//
//*****************************************************************************

- activateGateKeeper  
{
NXConnection *	myConnection;

	[NXApp perform:@selector(unhide:) with:self 
								afterDelay:100 
								cancelPrevious:YES];				
	gateToolProxy = [NXConnection connectToName:"GateToolServer"];
	if(gateToolProxy)			// use a protocol for DO efficiency 
		{
		[gateToolProxy setProtocolForProxy:@protocol(serverProtocol)];
				// return local NXconnection so that we can register for 	
				// invalidation of the proxy's port
		myConnection = [gateToolProxy connectionForProxy];
		[myConnection registerForInvalidationNotification:self];
		}

    return self;
}
//*****************************************************************************
//
// 		return modem initialization str to use in manual Dial 
//
//*****************************************************************************

- (const char *)modemInit  
{
char dialStr[MAXPATHLEN + 1] = {"SEND "};

	strncat(dialStr, NXGetDefaultValue([NXApp appName], DIALINIT), 
												MAXPATHLEN - strlen(dialStr));
	strncat(dialStr, " EXPECT OK ", MAXPATHLEN - strlen(dialStr));

    return dialStr;
}
//*****************************************************************************
//
// 		return the name of modem's serial port  
//
//*****************************************************************************

- (const char *)modemPort  
{
int fd;
												// if it exists
	if(fd = open("/etc/ppp/options", O_RDONLY) != -1)	
		{		
		close(fd);								// parse global options file
		[[[NXApp delegate] optionsEditor] parseOptions:"/etc/ppp/options"];
		}
								// parse selected Gatedoc options file
    return [[[[NXApp delegate] optionsEditor] parseOptions:
								[[[NXApp delegate] docLDelegate] 
											selGateDocOptionsPath]] devName];
}
//*****************************************************************************
//
// 		return the DTE speed of the serial port  
//
//*****************************************************************************

- (const char *)modemSpeed  
{
int fd;
												// if it exists
	if(fd = open("/etc/ppp/options", O_RDONLY) != -1)	
		{		
		close(fd);								// parse global options file
		[[[NXApp delegate] optionsEditor] parseOptions:"/etc/ppp/options"];
		}
								// parse selected Gatedoc options file
    return [[[[NXApp delegate] optionsEditor] parseOptions:
								[[[NXApp delegate] docLDelegate] 
											selGateDocOptionsPath]] speed];
}
//*****************************************************************************
//
// 		return whether MODEM should exit
//
//*****************************************************************************

- (BOOL)shouldExit 
{
    return shouldExit;
}

- free:sender
{
	if(gatePanel)
		{
		[gatePanel close];
		[gatePanel free];
		}

    return [super free];
}
//*****************************************************************************
//
// 	app will terminate, shutdown MODEM controller process
//
//*****************************************************************************

- appWillTerminate
{
	return [self cancelDial:self];
}

@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Marcel Waldvogel and Netfuture.ch.