realtimenetprots/sipfw/ClientResolver/Resolver/src/CSdpMLineStrategyBase.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     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 // Name          : CSdpMLineStrategyBase.cpp
       
    15 // Part of       : SIP Client Resolver
       
    16 // Version       : 1.0
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 #include "CSdpMLineStrategyBase.h"
       
    22 #include "MSipClients.h"
       
    23 #include "MSipClient.h"
       
    24 #include "sipresponse.h"
       
    25 #include "sdpdocument.h"
       
    26 #include "sipstrings.h"
       
    27 #include "sipstrconsts.h"
       
    28 
       
    29 const TUint K488ResponseCode = 488;
       
    30 
       
    31 // ----------------------------------------------------------------------------
       
    32 // CSdpMLineStrategyBase::CSdpMLineStrategyBase
       
    33 // ----------------------------------------------------------------------------
       
    34 //
       
    35 CSdpMLineStrategyBase::CSdpMLineStrategyBase(const MSipClients& aSipClients)
       
    36 : CSdpStrategyBase(aSipClients)
       
    37 	{
       
    38 	}
       
    39 
       
    40 // ----------------------------------------------------------------------------
       
    41 // CSdpMLineStrategyBase::~CSdpMLineStrategyBase
       
    42 // ----------------------------------------------------------------------------
       
    43 //
       
    44 CSdpMLineStrategyBase::~CSdpMLineStrategyBase()
       
    45 	{	
       
    46 	}
       
    47 
       
    48 // ----------------------------------------------------------------------------
       
    49 // CSdpMLineStrategyBase::ApplyL
       
    50 // ----------------------------------------------------------------------------
       
    51 //
       
    52 CSIPResponse* CSdpMLineStrategyBase::ApplyL(
       
    53     CSdpDocument& aDocument, 
       
    54     RArray<TUid>& aUids)
       
    55 	{
       
    56 	CSIPResponse* response = MediaLineExistL(aDocument);
       
    57 	if (!response && IsApplicable(aDocument))
       
    58 	    {
       
    59 	    FindApplicationL(aDocument,aUids);
       
    60 	    if(aUids.Count() == 0)
       
    61 		    {
       
    62 			response = CSIPResponse::NewL(
       
    63 			    K488ResponseCode,
       
    64 			    SIPStrings::StringF(SipStrConsts::EPhraseNotAcceptableHere));
       
    65 		    }
       
    66 	    }
       
    67 	return response;
       
    68 	}
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // CSdpMLineStrategyBase::FindApplicationL
       
    72 // ----------------------------------------------------------------------------
       
    73 //
       
    74 void CSdpMLineStrategyBase::FindApplicationL(CSdpDocument& aDocument,
       
    75                                              RArray<TUid>& aUids)
       
    76     {
       
    77 	for(TInt i=0; i < aUids.Count();i++)
       
    78 		{
       
    79 		MSipClient* client = iSipClients.GetByUID(aUids[i]);
       
    80 		if (!client || !MatchL(aDocument,*client))
       
    81 			{
       
    82 			aUids.Remove(i);
       
    83 			i--;
       
    84 			}		
       
    85 		}
       
    86     }
       
    87 
       
    88 // ----------------------------------------------------------------------------
       
    89 // CSdpMLineStrategyBase::MediaLineExist
       
    90 // ----------------------------------------------------------------------------
       
    91 //
       
    92 CSIPResponse* CSdpMLineStrategyBase::MediaLineExistL(CSdpDocument& aDocument)
       
    93  	{
       
    94    	if(aDocument.MediaFields().Count() == 0)
       
    95         {
       
    96         return CSIPResponse::NewL(K488ResponseCode,
       
    97             SIPStrings::StringF(SipStrConsts::EPhraseNotAcceptableHere));
       
    98         }
       
    99     return NULL;
       
   100     }
       
   101 	
       
   102 // ----------------------------------------------------------------------------
       
   103 // CSdpMLineStrategyBase::MatchL
       
   104 // ----------------------------------------------------------------------------
       
   105 //
       
   106 TBool CSdpMLineStrategyBase::MatchL(CSdpDocument& aDocument,
       
   107                                     MSipClient& aClient)
       
   108     {
       
   109 	const RPointerArray<CSdpMediaField>& clientMedias = 
       
   110 	    aClient.SdpDocument().MediaFields();
       
   111 	
       
   112 	const RPointerArray<CSdpMediaField>& receivedMedias = 
       
   113 	    aDocument.MediaFields();	
       
   114 	
       
   115 	// All the media fields in received request must be supported 
       
   116 	// by the client. If not the client is removed from the list of clients,
       
   117 	// that are capable of handling the request.  
       
   118 	for (TInt i=0; i < receivedMedias.Count(); i++)
       
   119 	    {
       
   120 	    CSdpMediaField* receivedMedia = receivedMedias[i];
       
   121 	    if (IsApplicable(*receivedMedia))
       
   122 	        {
       
   123 	        TBool mediaFound = EFalse;
       
   124 	        for (TInt j=0; j < clientMedias.Count() && !mediaFound; j++)
       
   125 	            {
       
   126 	            if (FieldsMatchL(*receivedMedia,*(clientMedias[j])))
       
   127 	                {
       
   128 	                mediaFound = ETrue;
       
   129 	                }
       
   130 	            }
       
   131 	        if (!mediaFound)
       
   132 	            {
       
   133 	            return EFalse;
       
   134 	            }
       
   135 	        }
       
   136 	    }
       
   137 
       
   138 	return ETrue;
       
   139 	}
       
   140 
       
   141 // ----------------------------------------------------------------------------
       
   142 // CSdpMLineStrategyBase::IsApplicable
       
   143 // ----------------------------------------------------------------------------
       
   144 //	
       
   145 TBool CSdpMLineStrategyBase::IsApplicable(CSdpDocument& aDocument)
       
   146     {
       
   147  	RPointerArray<CSdpMediaField>& mediaFields = aDocument.MediaFields();
       
   148 	for (TInt i=0; i < mediaFields.Count(); i++)
       
   149 	    {
       
   150 	    if (IsApplicable(*mediaFields[i]))
       
   151 	        {
       
   152 	        return ETrue;
       
   153 	        }
       
   154 	    }
       
   155     return EFalse;
       
   156     }
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 // CSdpMLineStrategyBase::IsApplicable
       
   160 // ----------------------------------------------------------------------------
       
   161 //	
       
   162 TBool CSdpMLineStrategyBase::IsApplicable(CSdpMediaField& /*aMediaField*/)
       
   163     {
       
   164     // default implementation
       
   165     return ETrue;
       
   166     }