applayerprotocols/telnetengine/SRC/TELSESS.CPP
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Telnet Protocol API
       
    15 // CTelnetSession implementation
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file
       
    21 */
       
    22 
       
    23 #include "TELDEBUG.H"
       
    24 #include "TELSESS.H"
       
    25 #include "TELRESOL.H"
       
    26 #include "IOBUFFER.H"
       
    27 #include "TELCTRL.H"
       
    28 #include "TELFSM.H"
       
    29 
       
    30 
       
    31 
       
    32 // CTelnetSession implementation 
       
    33 
       
    34 CTelnetSession::CTelnetSession()
       
    35 /**
       
    36 Constructor
       
    37 */
       
    38     {
       
    39     }
       
    40 
       
    41 CTelnetSession::~CTelnetSession()
       
    42 	/** Destructor. */
       
    43     {
       
    44 	delete iTelnetProtocol;
       
    45 
       
    46 	// DEBUG Close
       
    47 	__FLOG_STATIC(KTelnetLoggingCompnt(),KTelnetLoggingTag(),_L("CTelnetSession D'Tor"));
       
    48 
       
    49     }
       
    50 
       
    51 EXPORT_C CTelnetSession* CTelnetSession::NewL(const TTelnetConfig& aConfig,const MTelnetNotification* aNotifier)
       
    52 	/** Allocates and constructs a new telnet session object.
       
    53 	*
       
    54 	* @param aConfig	The TTelnetConfig object to use. The client should derive from
       
    55 	*					the TTelnetConfig class and pass this pointer into NewL().
       
    56 	* @param aNotifier	The MTelnetNotification object to use. The client should derive from
       
    57 	*					the MTelnetNotification class and pass this pointer into NewL().
       
    58 	* @return			The newly created telnet session.
       
    59 	*/
       
    60     {
       
    61 
       
    62     CTelnetSession* self=new (ELeave) CTelnetSession();
       
    63     CleanupStack::PushL(self);
       
    64     self->ConstructL(aConfig,aNotifier);
       
    65     CleanupStack::Pop();
       
    66     return self;
       
    67     }
       
    68 
       
    69 
       
    70 EXPORT_C void CTelnetSession::ConstructL(const TTelnetConfig& aConfig,const MTelnetNotification* aNotifier)
       
    71 	/** Second-phase protected constructor, called by NewL(). 
       
    72 	* 
       
    73 	* @see CTelnetSession::NewL() 
       
    74 	*/
       
    75     {
       
    76 
       
    77 
       
    78 	__FLOG_STATIC(KTelnetLoggingCompnt(),KTelnetLoggingTag(),_L("CTelnetSession::ConstructL"));
       
    79 
       
    80 	iNotifier = CONST_CAST(MTelnetNotification*, aNotifier);
       
    81 	iTelnetProtocol = CTelnetControl::NewL(aConfig,iNotifier);
       
    82     }
       
    83 
       
    84 EXPORT_C TInt CTelnetSession::Connect(const TInetAddr& aNetAddr)
       
    85 	/** Initiates connection to the specified IP address on the standard telnet port (port 23).
       
    86 	* 
       
    87 	* The client is asynchronously notified of successful connection by the MTelnetNotification::Connected() function.
       
    88 	*
       
    89 	* @param aNetAddr	The IP address to which connection is to be made.
       
    90 	* @return			@li KErrNone,	if successful 
       
    91 	*					@li KErrInUse,	if already connected or if an attempt to connect is already in progress.
       
    92 	*/
       
    93     {
       
    94     TBuf<20> aBuf;
       
    95     aNetAddr.Output(aBuf);
       
    96     return (iTelnetProtocol->Connect(aNetAddr, 23));
       
    97     }
       
    98 
       
    99 EXPORT_C TInt CTelnetSession::Connect(const TInetAddr& aNetAddr, TUint aPort)
       
   100 	/** Initiates connection to the specified IP address and telnet port.
       
   101 	*
       
   102 	* The client is asynchronously notified of successful connection by the MTelnetNotification::Connected() 
       
   103 	* function.
       
   104 	* 
       
   105 	* @param aNetAddr	The address to which connection is to be made.
       
   106 	* @param aPort		The port through which connection is to be made.
       
   107 	* @return			@li KErrNone,	if successful
       
   108 	*					@li KErrInUse,	if already connected or if an attempt to connect is already in progress. 
       
   109 	*/
       
   110     {
       
   111     TBuf<20> aBuf;
       
   112     aNetAddr.Output(aBuf);
       
   113     return (iTelnetProtocol->Connect(aNetAddr, aPort));
       
   114     }
       
   115 
       
   116 EXPORT_C TInt CTelnetSession::Connect(const TDesC& aServerName)
       
   117 	/** Connects to the specified server on the standard telnet port (port 23).
       
   118 	*
       
   119 	* The client is asynchronously notified of successful connection by the 
       
   120 	* MTelnetNotification::Connected() function.
       
   121 	*
       
   122 	* @param aServerName	The hostname of the server to which connection is to be made.
       
   123 	* @return				@li KErrNone,	if successful
       
   124 	*						@li KErrInUse,	if already connected or an attempt to connect is already in progress. 
       
   125 	*/
       
   126     {
       
   127     return (iTelnetProtocol->Connect(aServerName, 23));
       
   128     }
       
   129 
       
   130 EXPORT_C TInt CTelnetSession::Connect(const TDesC& aServerName, TUint aPort)
       
   131 	/** Connects to the specified server on the specified port.
       
   132 	* 
       
   133 	* The client is asynchronously notified of successful connection by the MTelnetNotification::Connected() 
       
   134 	* function.
       
   135 	*
       
   136 	* @param aServerName	The hostname of the server to which connection is to be made.
       
   137 	* @param aPort			The port through which connection is to be made.
       
   138 	* @return				@li KErrNone,	if successful
       
   139 	*						@li KErrInUse,	if already connected or if an attempt to connect is already in progress. 
       
   140 	*/
       
   141     {
       
   142     return (iTelnetProtocol->Connect(aServerName, aPort));
       
   143     }
       
   144 
       
   145 EXPORT_C TInt CTelnetSession::Disconnect()
       
   146 	/** Requests disconnection from the server.
       
   147 	* 
       
   148 	* @return	@li KErrNone,			if successful; this will be followed by a Disconnected() notification
       
   149 	* 									if the client previously received a Connected() notification 
       
   150 	* 			@li KErrServerBusy,		if the socket is in a connecting state; in this case the client will
       
   151 	*									not receive a ConnectionClosed() notification 
       
   152 			@li KErrDisconnected,	if already already disconnecting. 
       
   153 	*/
       
   154     {
       
   155     // Send Disconnect request to Server.
       
   156     __FLOG_STATIC(KTelnetLoggingCompnt(),KTelnetLoggingTag(),_L("TTelnetSession()::Disconnect()"));
       
   157     return iTelnetProtocol->Disconnect();
       
   158     }
       
   159 
       
   160 EXPORT_C TInt CTelnetSession::Write(const TDesC8& aBuffer)
       
   161 	/** Writes a byte stream over the open telnet connection to the telnet server.
       
   162 	*
       
   163 	* The client is notified asynchronously by the: 
       
   164 	* @li MTelnetNotification::WriteComplete() function, if the write is successful 
       
   165 	* @li MTelnetNotification::Error() function, if the write is not successful.
       
   166 	* 
       
   167 	* @param aBuffer	The data to write. 
       
   168 	* @return			@li KErrNone,			if successful
       
   169 	* 					@li KErrOverflow,		if a write buffer overflow occurred
       
   170 	* 					@li KErrGeneral,		if an invalid control code was issued 
       
   171 	* 					@li KErrDisconnected,	if disconnected
       
   172 	* 					@li KErrNotSupported,	when in binary mode. 
       
   173 	*/    
       
   174 	{
       
   175     return (iTelnetProtocol->Write(aBuffer));
       
   176     }
       
   177 
       
   178 EXPORT_C TInt CTelnetSession::Write(TTelnetUserControl& aControlCode)
       
   179 	/** Writes telnet-defined code over the open telnet connection to the telnet server.
       
   180 	* 
       
   181 	* The client is asynchronously notified by the: 
       
   182 	* @li MTelnetNotification::WriteComplete() function, if the write is successful 
       
   183 	* @li MTelnetNotification::Error() function, if the write is not successful.
       
   184 	* 
       
   185 	* @param aControlCode	The telnet control code to write. See TTelnetUserControl enum.
       
   186 	* @return				@li KErrNone,			if successful
       
   187 	* 						@li KErrOverflow,		if a write buffer overflow occurred
       
   188 	* 						@li KErrGeneral,		if an invalid control code was issued
       
   189 	* 						@li KErrDisconnected,	if disconnected
       
   190 	* 						@li KErrNotSupported,	when in binary mode. 
       
   191 	*/    
       
   192 	{
       
   193     // Should return eg KErrNotSupported? when in Binary_Mode
       
   194 	return(iTelnetProtocol->Write(aControlCode));
       
   195     }
       
   196 
       
   197 EXPORT_C TInt CTelnetSession::Read()
       
   198 	/** Reads the data received over the telnet buffer. 
       
   199 	* 
       
   200 	* The client is asynchronously notified by the:* 
       
   201 	* @li MTelnetNotification::ReadComplete() function, if the read is successful* 
       
   202 	* @li MTelnetNotification::Error() function, if the read is not successful.
       
   203 	* 
       
   204 	* @return	@li KErrNone,			if successful
       
   205 	*			@li KErrDisconnected,	if disconnected. 
       
   206 	*/
       
   207     {
       
   208     return (iTelnetProtocol->Read());
       
   209     }
       
   210 
       
   211 EXPORT_C TInt CTelnetSession::DoForceLogout()
       
   212 	/** Forces a logout from the server.
       
   213 	* 
       
   214 	* @return	@li KErrNone,			if successful
       
   215 	*			@li KErrDisconnected,	if disconnected. 
       
   216 	*/
       
   217 	{
       
   218 	return(iTelnetProtocol->SetOption(KTelnetProtOptionLogoff));
       
   219 	}
       
   220 
       
   221 EXPORT_C TInt CTelnetSession::DoModifyConfig(TTelnetConfig& aConfig)
       
   222 	/** Sets the telnet connection configuration.
       
   223 	* 
       
   224 	* If any options change status as a result, the client is notified through an OptionsChanged() call. 
       
   225 	* 
       
   226 	* @param aConfig	Telnet connection configuration.
       
   227 	* @return			KErrNone, if successful; otherwise, one of the system wide error codes. 
       
   228 	*/	
       
   229 	{
       
   230 	return(iTelnetProtocol->SetConfig(aConfig));
       
   231 	}
       
   232 
       
   233 EXPORT_C TInt CTelnetSession::OptionStatus(TOptionStatus& aStatus)
       
   234 	/** Gets the status of the supported RFC-defined options.
       
   235 	* 
       
   236 	* See TOptionStatus for a description of options.
       
   237 	* 
       
   238 	* @param aStatus	On return, the status of the RFC-defined options.
       
   239 	* @return			@li KErrNone,			if successful 
       
   240 	* 					@li KErrDisconnected,	if disconnected. 
       
   241 	*/
       
   242 	{
       
   243 	return(iTelnetProtocol->OptionStatus(aStatus));
       
   244 	}
       
   245 
       
   246 
       
   247 EXPORT_C void ClientStubOrdinal1() 
       
   248 	{
       
   249 	_LIT(KStubPanic, "TelSess.dll Stub");
       
   250 	User::Panic(KStubPanic, KErrNotSupported);
       
   251 	}