obex/obexprotocol/obex/src/TObexServerStateSetPathOp.cpp
changeset 54 4dc88a4ac6f4
parent 52 866b4af7ffbe
child 57 f6055a57ae18
equal deleted inserted replaced
52:866b4af7ffbe 54:4dc88a4ac6f4
     1 // Copyright (c) 2005-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 //
       
    15 
       
    16 #include <obex.h>
       
    17 #include <obex/internal/obexinternalheader.h>
       
    18 #include "obexserverstatemachine.h"
       
    19 #include "obexsetpathdata.h"
       
    20 
       
    21 /**
       
    22 @file
       
    23 @internalComponent
       
    24 
       
    25 SETPATH Operation State
       
    26 This state processes the SetPath operation, the SetPathIndication is asynchronous.
       
    27 So the state has to wait for RequestCompleteIndicationCallback before sending 
       
    28 response and transition to the ready state. 
       
    29 */
       
    30 
       
    31 TObexServerStateSetPathOp::TObexServerStateSetPathOp()
       
    32 	{
       
    33 #ifdef __FLOG_ACTIVE
       
    34 	_LIT8(KName, "SetPathOp");
       
    35 	iName = KName;
       
    36 #endif
       
    37 	}
       
    38 
       
    39 void TObexServerStateSetPathOp::Entry(CObexServerStateMachine& aContext)
       
    40 	{
       
    41 	TObexSetPathData data;
       
    42 	TBool authChallengePresent = EFalse;
       
    43 	CObexPacket& aPacket = aContext.LastReceivedPacket();
       
    44 
       
    45 	if(!aPacket.ExtractData(data))
       
    46 		{
       
    47 		aContext.Transport().Send(ERespBadRequest);
       
    48 		aContext.ChangeState(CObexServerStateMachine::EReady);
       
    49 		return;
       
    50 		}
       
    51 	TInt packetSize = aPacket.PacketSize();
       
    52 	// Check Connection ID
       
    53 	if (aContext.Owner().CheckPacketForConnectionId(aPacket))
       
    54 		{
       
    55 		CObex::TSetPathInfo info(data);
       
    56 
       
    57 		// Search for any name headers
       
    58 		TObexInternalHeader header;
       
    59 		while(aPacket.ExtractData(header))
       
    60 			{
       
    61 			if(!info.iNamePresent && header.HI() == TObexInternalHeader::EName && header.GetHVText(info.iName) == KErrNone)
       
    62 				{
       
    63 				info.iNamePresent = ETrue;
       
    64 				}
       
    65 			if (header.HI() == TObexInternalHeader::EAuthChallenge)
       
    66 				{
       
    67 				authChallengePresent = ETrue;	
       
    68 				}
       
    69 			}
       
    70 		if (authChallengePresent) // Auth challenge is present, send unauthorized response
       
    71 			{
       
    72 			aContext.Transport().Send(ERespUnauthorized);
       
    73 			aContext.ChangeState(CObexServerStateMachine::EReady);
       
    74 			}
       
    75 		else 
       
    76 			{
       
    77 			//There is no need to add a new state to wait for the RequestCompleteIndicationCallback because there is 
       
    78 			//no other actions required for SetPath. So just wait in this state.
       
    79 			aContext.Notification().SetPathIndication(info, KNullDesC8);
       
    80 			}
       
    81 		
       
    82 		}
       
    83 	else //bad or missing ConnectionID
       
    84 		{
       
    85 		aContext.Transport().Send(ERespServiceUnavailable);
       
    86 		aContext.ChangeState(CObexServerStateMachine::EReady);
       
    87 		}
       
    88 	}
       
    89 
       
    90 void TObexServerStateSetPathOp::Connect(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    91 	{
       
    92 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    93 	}
       
    94 
       
    95 void TObexServerStateSetPathOp::Disconnect(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
    96 	{
       
    97 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
    98 	}
       
    99 
       
   100 void TObexServerStateSetPathOp::Put(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
   101 	{
       
   102 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
   103 	}
       
   104 
       
   105 void TObexServerStateSetPathOp::Get(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
   106 	{
       
   107 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
   108 	}
       
   109 
       
   110 void TObexServerStateSetPathOp::SetPath(CObexServerStateMachine& aContext, CObexPacket& /*aPacket*/)
       
   111 	{
       
   112 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
   113 	}
       
   114 
       
   115 void TObexServerStateSetPathOp::Abort(CObexServerStateMachine& aContext)
       
   116 	{
       
   117 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
   118 	}
       
   119 	
       
   120 void TObexServerStateSetPathOp::OverrideRequestHandling(CObexServerStateMachine& aContext, TObexResponse /*aResponse*/)
       
   121 	{
       
   122 	aContext.Owner().Error(KErrIrObexPacketDuringWait);
       
   123 	}
       
   124 
       
   125 void TObexServerStateSetPathOp::Start(CObexServerStateMachine& /*aContext*/)
       
   126 	{
       
   127 	// Panic - trying to change interface during wait
       
   128 	IrOBEXUtil::Panic(EChangeInterfaceDuringWait);
       
   129 	}
       
   130 
       
   131 void TObexServerStateSetPathOp::Reset(CObexServerStateMachine& aContext)
       
   132 	{
       
   133 	// Cancel notification - if it has not already been activated
       
   134 	if (!aContext.IsCallBackActive())
       
   135 		{
       
   136 		aContext.Notification().CancelIndicationCallback();
       
   137 		}
       
   138 	aContext.CancelCallBack();
       
   139 	aContext.ChangeState(CObexServerStateMachine::EDisconnected);
       
   140 	}
       
   141 
       
   142 void TObexServerStateSetPathOp::RequestCompleteNotificationCompleted(CObexServerStateMachine& aContext, TObexResponse aAppResponse)
       
   143 	{
       
   144 	aContext.SetAppResponse(aAppResponse);
       
   145 	aContext.CallBack(TObexServerStateSetPathOp::ProcessNotification);
       
   146 	}
       
   147 	
       
   148 TInt TObexServerStateSetPathOp::ProcessNotification(TAny* aPtr)
       
   149 	{
       
   150 	CObexServerStateMachine& context = *static_cast<CObexServerStateMachine*>(aPtr);
       
   151 
       
   152 	context.Transport().Send(context.AppResponse());
       
   153 	context.ChangeState(CObexServerStateMachine::EReady);
       
   154 	
       
   155 	return KErrNone;
       
   156 	}
       
   157 
       
   158 TBool TObexServerStateSetPathOp::ValidResponse(TObexResponse aResponseCode)
       
   159 	{
       
   160 	return (aResponseCode>0 && aResponseCode<=255 && aResponseCode != ERespContinue);
       
   161 	}
       
   162