messagingfw/biomsgfw/IACPSRC/ISSP.CPP
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 1998-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 // Internet Script Settings Parser
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <txtetext.h>	// CEditableText
       
    19 #include <msventry.h>
       
    20 
       
    21 #include "BSP.H"
       
    22 #include "IACP.H"
       
    23 #include "ISSP.H"
       
    24 #include "IACPDEF.H"
       
    25 #include "IACPERR.H"
       
    26 
       
    27 //
       
    28 // Constructor
       
    29 //
       
    30 CScriptParser::CScriptParser()
       
    31 	{
       
    32 	}
       
    33 
       
    34 //
       
    35 // Factory fns
       
    36 //
       
    37 CScriptParser* CScriptParser::NewLC()
       
    38 	{
       
    39 	CScriptParser* self=new (ELeave) CScriptParser();
       
    40 	CleanupStack::PushL(self);
       
    41 	self->ConstructL();
       
    42 	return self;
       
    43 	}
       
    44 
       
    45 CScriptParser* CScriptParser::NewL()
       
    46 	{
       
    47 	CScriptParser* self=CScriptParser::NewLC();
       
    48 	CleanupStack::Pop();
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 //
       
    53 // 2nd stage of construction
       
    54 //
       
    55 void CScriptParser::ConstructL()
       
    56 	{
       
    57 	iScriptMode=ENewScript;
       
    58 	iUseLoginScript=EFalse;
       
    59 	iDbSession = CMDBSession::NewL(CMDBSession::LatestVersion());
       
    60 	}
       
    61 
       
    62 //
       
    63 // Destruction
       
    64 //
       
    65 CScriptParser::~CScriptParser()
       
    66 	{
       
    67 	delete iScriptName;
       
    68 	delete iScriptType;
       
    69 	delete iLoginScript;
       
    70 	delete iDbSession;
       
    71 	}
       
    72 
       
    73 //
       
    74 // 
       
    75 //
       
    76 void CScriptParser::ParseL(CParsedFieldCollection& aIacpFields)
       
    77 	{
       
    78 	TPtrC aFieldValueBuf;
       
    79 
       
    80 	if (aIacpFields.GetFieldValueAndLength(SMS_SCRIPT_NAME, aFieldValueBuf) != 0)
       
    81 		{
       
    82 		delete iScriptName;
       
    83 		iScriptName = NULL;
       
    84 		iScriptName= aFieldValueBuf.AllocL();
       
    85 		}
       
    86 
       
    87 	if (aIacpFields.GetFieldValueAndLength(SMS_SCRIPT_TYPE, aFieldValueBuf) != 0)
       
    88 		{
       
    89 		delete iScriptType;
       
    90 		iScriptType = NULL;
       
    91 		iScriptType= aFieldValueBuf.AllocL();
       
    92 		}
       
    93 
       
    94 	//login Script
       
    95 	if (aIacpFields.GetFieldValueAndLength(SMS_SCRIPT_DATA, aFieldValueBuf) != 0)
       
    96 		iScriptMode= ENewScript;
       
    97 	else if (aIacpFields.GetFieldValueAndLength(SMS_SCRIPT_ADD, aFieldValueBuf) != 0)
       
    98 		iScriptMode= EAddToScript;
       
    99 	else
       
   100 		User::Leave(KIacpMandatoryDataNotSet);
       
   101 	
       
   102 	//if function does'nt leave, it means login script has been assigned to 'aFieldValueBuf'
       
   103 	delete iLoginScript;
       
   104 	iLoginScript = NULL;
       
   105 	iLoginScript= aFieldValueBuf.AllocL();
       
   106 	iUseLoginScript= ETrue;
       
   107 	}
       
   108 //
       
   109 //
       
   110 //
       
   111 void CScriptParser::ProcessL(CMsvEntry& aEntry)
       
   112 	{
       
   113 	if (iScriptMode== EAddToScript)
       
   114 		{
       
   115 		if(aEntry.Entry().MtmData3() == KBIO_MSG_ENTRY_PROCESSED)
       
   116 			User::Leave(KIacpErrScriptAlreadyAdd);//we cannot append script more than once for the same Bio Msg
       
   117 		}
       
   118 
       
   119 		CCDDialOutISPRecord* dialOutISPRecord = static_cast<CCDDialOutISPRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdDialOutISPRecord));
       
   120 		CleanupStack::PushL(dialOutISPRecord);
       
   121 		dialOutISPRecord->iRecordName.SetMaxLengthL(iScriptName->Length());
       
   122 		dialOutISPRecord->iRecordName = iScriptName->Des();
       
   123 		if (dialOutISPRecord->FindL(*iDbSession))
       
   124 			{
       
   125 			if (iScriptMode== EAddToScript)
       
   126 				{
       
   127 				TPtrC existingScript = TPtrC(dialOutISPRecord->iLoginScript);
       
   128 				if (existingScript.Length()==0)
       
   129 					{
       
   130 					User::Leave(KIacpErrScriptNotFoundInDB);
       
   131 					}
       
   132 				HBufC* tempBuf= HBufC::NewLC(existingScript.Length() + iLoginScript->Length());
       
   133 				tempBuf->Des().Copy(existingScript);
       
   134 				tempBuf->Des().Append(iLoginScript->Des());
       
   135 				//Realloc into iLoginScript then wrtie it to DB
       
   136 				delete iLoginScript; 
       
   137 				iLoginScript = NULL;
       
   138 				iLoginScript= tempBuf->AllocL();
       
   139 				iLoginScript->Des().Copy(*tempBuf);
       
   140 				CleanupStack::PopAndDestroy(tempBuf);//tempBuf	
       
   141 				}
       
   142 				if(iLoginScript)
       
   143 					{
       
   144 					ChangeLoginScriptToNewlines();	
       
   145 					dialOutISPRecord->iUseLoginScript = iUseLoginScript;
       
   146 					dialOutISPRecord->iLoginScript.SetMaxLengthL(iLoginScript->Length());
       
   147 					dialOutISPRecord->iLoginScript = *iLoginScript;
       
   148 					dialOutISPRecord->ModifyL(*iDbSession);				
       
   149 					}
       
   150 				else
       
   151 					{
       
   152 					User::Leave(KIacpErrScriptNotDefined);	
       
   153 					}
       
   154 			}
       
   155 		else
       
   156 			{
       
   157 			User::Leave(KIacpScriptErrISPNotFound);//there are no records in table
       
   158 			}
       
   159 		CleanupStack::PopAndDestroy(dialOutISPRecord);
       
   160 		
       
   161 	}
       
   162 //
       
   163 //
       
   164 //
       
   165 void CScriptParser::ChangeLoginScriptToNewlines()
       
   166 	{
       
   167 	TPtr ptr(iLoginScript->Des());
       
   168 	for (TInt cc=ptr.Length()-1; cc>=0; --cc)
       
   169 		{
       
   170 		if (ptr[cc]==CEditableText::EParagraphDelimiter)
       
   171 			ptr[cc]=0x0a;
       
   172 		}
       
   173 	}