messagingfw/msgurlhandler/urlhandler/src/SMSSCH.CPP
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2001-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 // This file contains the implementation for the class defined in SmsSch.h
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @see	SmsSch.h
       
    21 */
       
    22 
       
    23 // System includes
       
    24 //
       
    25 #include <inetprottextutils.h>
       
    26 #include <sendas2.h>
       
    27 
       
    28 // Local includes
       
    29 //
       
    30 #include "SMSSCH.H"
       
    31 #include "msgurlparser.h"
       
    32 
       
    33 // Allowed characters
       
    34 _LIT(KAllowedChars,"0123456789-.");
       
    35 
       
    36 // Field name
       
    37 _LIT(KVia,"via");
       
    38 
       
    39 // Constants
       
    40 //
       
    41 const TUid KSmsMtm = {0x1000102c};
       
    42 const TInt KPlusChar = '+';
       
    43 const TInt KSemiColonChar = ';';
       
    44 const TInt KEqualChar = '=';
       
    45 
       
    46 CSmsSchemeHandler::CSmsSchemeHandler()
       
    47 	{
       
    48 	}
       
    49 
       
    50 CSmsSchemeHandler* CSmsSchemeHandler::NewLC()
       
    51 	{
       
    52 	CSmsSchemeHandler* self=new (ELeave) CSmsSchemeHandler();
       
    53 	CleanupStack::PushL(self);
       
    54 	self->ConstructL();
       
    55 	return self;
       
    56 	}
       
    57 
       
    58 CSmsSchemeHandler* CSmsSchemeHandler::NewL()
       
    59 	{
       
    60 	CSmsSchemeHandler* self = NewLC();
       
    61 	CleanupStack::Pop(self);
       
    62 	return self;
       
    63 	}
       
    64 
       
    65 void CSmsSchemeHandler::ConstructL()
       
    66 	{
       
    67 	CMsgSchemeHandlerBase::ConstructL();
       
    68 	}
       
    69 
       
    70 CSmsSchemeHandler::~CSmsSchemeHandler()
       
    71 	{
       
    72 	iNumbers.Close();
       
    73 	}
       
    74 
       
    75 void CSmsSchemeHandler::ParseUrlL(const TDesC& aUrl)
       
    76 	{
       
    77 	// Get the scheme specific part
       
    78 	TPtrC smsPart; 
       
    79 	GetSchemeSpecificPartL(aUrl, smsPart);
       
    80 
       
    81 	// Format of sms url:	sms:<segment>,<segment>,....
       
    82 	// Format of segment is: <sms-number>;via=<service center number>
       
    83 	TPtrC segment;
       
    84 
       
    85 	// The sms-number
       
    86 	TPtrC numData;
       
    87 
       
    88 	// The service center segment i.e	via=<service center number>
       
    89 	TPtrC serviceData;
       
    90 
       
    91 	// Parse the scheme specific part
       
    92 	TDelimitedSmsParser parser;
       
    93 	parser.Parse(smsPart);
       
    94 
       
    95 	SSmsNumber num;
       
    96 	while (parser.GetNext(segment) != KErrNotFound)
       
    97 		{
       
    98 		// Look for field separator
       
    99 		TInt pos = segment.Locate(KSemiColonChar);
       
   100 		if (pos != KErrNotFound)
       
   101 			{
       
   102 			numData.Set(segment.Left(pos));
       
   103 
       
   104 			// Set everything after the semicolon.
       
   105 			serviceData.Set(segment.Mid(pos+1));
       
   106 			}
       
   107 		else 
       
   108 			{
       
   109 			numData.Set(segment);
       
   110 			serviceData.Set(KNullDesC);
       
   111 			}
       
   112 
       
   113 		// Parse the sms-number
       
   114 		InetProtTextUtils::RemoveWhiteSpace(numData, InetProtTextUtils::ERemoveBoth);
       
   115 		ParseSmsNumber(numData, num.iNumber);
       
   116 
       
   117 		// Parse the service center segment
       
   118 		TPtrC serviceCenter;
       
   119 		GetServiceCenter(serviceData, serviceCenter);
       
   120 		ParseSmsNumber(serviceCenter, num.iServiceCentre);
       
   121 
       
   122 		// This contains sms-number and service center number
       
   123 		User::LeaveIfError(iNumbers.Append(num));	
       
   124 		}	
       
   125 	}
       
   126 
       
   127 TInt CSmsSchemeHandler::ParseSmsNumber(const TPtrC& aNumber, TPtrC& aParsedNumber)
       
   128 	{
       
   129 	if (aNumber.Length() == 0)
       
   130 		{
       
   131 		aParsedNumber.Set(KNullDesC);
       
   132 		return KErrNotFound;
       
   133 		}
       
   134 
       
   135 	// Look for '+' at start of data. 	
       
   136 	if (aNumber[0] != KPlusChar)
       
   137 		// Local number 
       
   138 		{
       
   139 		// Parse and set the sms-number. Sets the leftmost part of the descriptor up 
       
   140 		// to the first non-allowable character.
       
   141 		ParseUtil::Subset(aNumber, KAllowedChars, aParsedNumber);
       
   142 		}
       
   143 	else
       
   144 		// International number
       
   145 		{
       
   146 		// Parse the number without the '+'. Sets the leftmost part of the descriptor up 
       
   147 		// to the first non-allowable character.
       
   148 		TPtrC number;
       
   149 		ParseUtil::Subset(aNumber.Mid(1), KAllowedChars, number); 
       
   150 
       
   151 		// Number length including the '+'
       
   152 		TInt numberLength = 1 + number.Length();
       
   153 		
       
   154 		// Set the parsed number
       
   155 		aParsedNumber.Set(aNumber.Left(numberLength));
       
   156 		}
       
   157 
       
   158 	return KErrNone;
       
   159 	}
       
   160 
       
   161 void CSmsSchemeHandler::GetServiceCenter(const TPtrC& aComponent, TPtrC& aServiceCenter)
       
   162 	{
       
   163 	// Look for field separator
       
   164 	TInt pos = aComponent.Locate(KEqualChar);
       
   165 	if (pos != KErrNotFound)
       
   166 		{
       
   167 		// Set field name
       
   168 		TPtrC fieldName = aComponent.Left(pos);
       
   169 		InetProtTextUtils::RemoveWhiteSpace(fieldName, InetProtTextUtils::ERemoveBoth);
       
   170 
       
   171 		// Check field name is valid 
       
   172 		if (fieldName.CompareF(KVia) == 0)
       
   173 			{
       
   174 			// Set service center number - excludes '='
       
   175 			aServiceCenter.Set(aComponent.Mid(pos+1));
       
   176 			InetProtTextUtils::RemoveWhiteSpace(aServiceCenter, InetProtTextUtils::ERemoveBoth);
       
   177 			}
       
   178 		}
       
   179 	else 
       
   180 		aServiceCenter.Set(KNullDesC);
       
   181 	} 
       
   182 
       
   183 void CSmsSchemeHandler::SendL()
       
   184 	{
       
   185 	RSendAs sendAs;
       
   186 	CleanupClosePushL(sendAs);
       
   187 	User::LeaveIfError(sendAs.Connect());
       
   188 
       
   189 	RSendAsMessage smsMessage;
       
   190 	CleanupClosePushL(smsMessage);
       
   191 	smsMessage.CreateL(sendAs, KSmsMtm);
       
   192 
       
   193 	const TInt count = iNumbers.Count();
       
   194 	for (TInt i = 0; i < count; ++i)
       
   195 		{
       
   196 		smsMessage.AddRecipientL(iNumbers[i].iNumber, RSendAsMessage::ESendAsRecipientTo);
       
   197 		}
       
   198 	smsMessage.LaunchEditorAndCloseL();
       
   199 	CleanupStack::Pop(&smsMessage); // Closed by LaunchEditorAndCloseL
       
   200 	CleanupStack::PopAndDestroy(&sendAs);
       
   201 
       
   202 	}
       
   203