示例#1
0
EXPORT_C TInt TEFparser::GetIniFileInfo(TDesC& aBuf, 
											  TPtrC& aIniFileName, 
											  TPtrC& aIniSectionName)
	{
	TInt pos =0;
	TInt startPos = 0, endPos = 0;
	
	
	TPtrC temp = aBuf.Mid(pos);
	
	endPos = temp.Find(KIniExtension);
	endPos += 4;
	
	if (endPos != KErrNotFound)
		{
		TInt len = endPos - startPos;
		TPtrC iniFileName = temp.Mid(startPos, len);
		aIniFileName.Set(iniFileName);
		
		TPtrC iniSectionName = temp.Mid(iniFileName.Length());
		aIniSectionName.Set(Trim(iniSectionName));
		
		return KErrNone;
		}
	else
		{
		return KErrNotFound;
		}
	
	}
示例#2
0
EXPORT_C HBufC* CScriptFile::ReplaceLC(const TDesC& aOld, const TDesC& aNew, const TDesC& aOldString)
	{
	HBufC* rString = aOldString.AllocLC();
	TInt oldLen = aOld.Length();
	TInt newLen = aNew.Length();

	if (!oldLen)
		return rString;

	for (TInt pos = 0; pos < rString->Length(); pos += newLen)
		{
		TPtrC ptrC = rString->Mid(pos);
		TInt find = ptrC.Find(aOld);

		if (find == KErrNotFound)
			return rString;
	
		pos += find;

		if (newLen > oldLen)
			{
			rString = rString->ReAllocL(rString->Length() + newLen - oldLen);
			CleanupStack::Pop();
			CleanupStack::PushL(rString);
			}

		TPtr ptr(rString->Des());
		ptr.Replace(pos, oldLen, aNew);
		}

	return rString;
	}
示例#3
0
/*
-------------------------------------------------------------------------------

    Class: CStifSectionParser

    Method: FindTag

    Description: Searches for selected tag in text

    Parameters: const TPtrC& aText: in: text,
				const TPtrC& aTag: in: tag,
				TInt& aStartPos: out: tag start position,
				TInt& aEndPos: out: tag end position.

    Return Values: TInt: KErrNone, if tag was found. KErrNotFound if it was not found. 

    Errors/Exceptions: None

    Status: Proposal

-------------------------------------------------------------------------------
*/
TInt CStifSectionParser::FindTag( const TDesC& aText, const TDesC& aTag, TInt& aStartPos, TInt& aEndPos ) {
	TBool tagWithEqualChar = EFalse;

	HBufC* tagBuf = NULL;
	TRAPD( err, tagBuf = aTag.AllocL() );
	if ( err != KErrNone )
		{
		return err;
		}

	RBuf tag( tagBuf );
	tag.Trim();
	if ( tag.Right( 1 ) == _L("=") )
		{
		tagWithEqualChar = ETrue;
		tag.SetLength( tag.Length() - 1 );
		}
	
	TLex lex(aText);
	lex.SkipSpaceAndMark();
	TInt startPos = lex.Offset();
	TPtrC token = lex.NextToken(); 
	
	
	if ( !tagWithEqualChar )
		{
		if ( token == tag )
			{
			aStartPos = startPos;
			lex.SkipSpace();
			aEndPos = lex.Offset();
			tag.Close();
			return KErrNone;
			}
		}
	else
		{
		lex.UnGetToMark();
		TPtrC remText = lex.Remainder();
		if ( remText.Find( tag ) == 0 )
			{
			lex.SkipAndMark( tag.Length() );
			lex.SkipSpaceAndMark();
			if ( !lex.Eos() )
				{
				if ( lex.Get() == '=' )
					{
					aStartPos = startPos;
					lex.SkipSpace();					
					aEndPos = lex.Offset();
					tag.Close();
					return KErrNone;
					}
				}
			}
		}
	
	tag.Close();
	return KErrNotFound;
}
示例#4
0
TInt CIniData::OpenBlock(const TDesC &aSection)
/**
Reads in the entire table section of all ADD / SET blocks into 'section'

@param aSection Section to work with
@return ETrue if successful or EFalse
*/
	{
    if (BlockState != E_UNKNOWN)
		{
	    blockStart = 0;
	    blockEnd = 0;
	    scanStart = 0;

	    TPtr sectionToken = iToken->Des();
		_LIT(sectionTokenString,"[%S]");
		sectionToken.Format(sectionTokenString,&aSection);

	    // locate the section
		TInt sectionStart = iPtr.FindF(sectionToken);
	    if (sectionStart == KErrNotFound)
			{
	        return EFalse;
			}

		// step to the end of the section name
		TPtrC tempSection = iPtr.Mid(sectionStart);
        sectionStart += tempSection.Find(TPtrC(_S("]")));

		if (sectionStart == KErrNotFound)
			{
			return EFalse;
			}
		sectionStart++;

		// we are now at the start of the section data
        tempSection.Set(iPtr.Mid(sectionStart));

		// loop until we reach the end of the section
		TUint32 i=0;
		TUint32 lMaxLen = tempSection.Length();

        for (i=0;i<lMaxLen;i++)
			{
	        if (tempSection.Ptr()[i] == '[' &&
		        tempSection.Ptr()[i - 1] != '\\')
				{
			    i--;
			    break;
				}
			}
		
		// set the actual section to work with
        tempSection.Set(iPtr.Mid(sectionStart, i));
		section.Set((unsigned short *)tempSection.Ptr(), tempSection.Length(), tempSection.Size());
		}

	return StepToNextBlock();	// find the first block
	}
示例#5
0
EXPORT_C TPtrC TEFparser::GetRunTestStep(TPtrC& aBuf, 
									const TDesC& aTag,
									TInt& aPos,
									TInt& aError)
	{
	TInt endPos = 0;
	TInt startPos = 0;
	TInt tempPos = 0;
	
	TPtrC data = aBuf.Mid(aPos);
	
	tempPos = data.Find(aTag);
	
	if (tempPos != KErrNotFound)
		{
		tempPos += aTag.Length();
//			
		TPtrC temprunStepData = data.Mid(tempPos);		
//		
		endPos = temprunStepData.Find(KNewline);
		if (endPos == KErrNotFound)
			{
			endPos = temprunStepData.Find(KReturn);
			}
		if (endPos == KErrNotFound)
			{
			endPos = temprunStepData.Length();
			}
//		
		TInt len = 0;
		len = (endPos - startPos) + 1;
		TPtrC runStepData = temprunStepData.Mid(startPos,len);
		aPos += tempPos + runStepData.Length();
		aError = KErrNone;
		return Trim(runStepData);
		}
	else
		{
		aError = KErrNotFound;
		return TPtrC();
		}

	}
LOCAL_C void TestUpdateContactL()
{
    test.Next(_L("TestUpdateContactL"));

    SETUP;

    CContactItem* contact = CContactItem::NewLC(KUidContactCard);

    TContactItemId id = cntClient.CreateContactL(*contact);
    CleanupStack::PopAndDestroy(contact);

    // View definition to read image field
    CContactItemViewDef* imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields);
    imageViewDef->AddL(KUidContactFieldMatchAll);

    contact = cntClient.OpenContactLX(imageViewDef ,id);
    CleanupStack::PushL(contact);

    CContactItemField* newField = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldCodImage);
    newField->SetMapping(KUidContactFieldVCardMapUnknown);
    newField->TextStorage()->SetTextL(KSrcImage());
    contact->AddFieldL(*newField); // Takes ownership
    CleanupStack::Pop(newField);

    cntClient.CommitContactL(*contact, EFalse);
    CleanupStack::PopAndDestroy(2);  //  contact, imageViewDef

    // View definition to read image field
    imageViewDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EMaskHiddenFields);
    imageViewDef->AddL(KUidContactFieldCodImage);

    contact = cntClient.ReadContactL(imageViewDef ,id);

    TInt index = contact->CardFields().Find(KUidContactFieldCodImage, KUidContactFieldVCardMapUnknown);

    // Test image field found
    test(index != KErrNotFound);

    CContactItemField& field = contact->CardFields()[index];
    TPtrC imagePtr = field.TextStorage()->Text();

    // Image should exist
    test(BaflUtils::FileExists(fs, imagePtr));

    // Test for GUID
    TPtrC guid = contact->Guid();
    test(imagePtr.Find(guid));

    cntClient.CloseContact(id);
    CleanupStack::PopAndDestroy(2);  //  contact, imageViewDef

    TEAR_DOWN;
}
示例#7
0
HBufC* CSwiEngine::FindInJadLC(HBufC* aJad, const TDesC& aProp)
	{
	TInt lineIndex = aJad->Find(aProp);
	TPtrC tmpPtr = aJad->Right(aJad->Length()-lineIndex-aProp.Length());
	TInt crlfIndex = tmpPtr.Find(KCRLF);
	if(crlfIndex == -1)
		{
		// maybe bad jad
		crlfIndex = tmpPtr.Find(KLF);
		}
		
	TPtrC tmpPtr2 = tmpPtr;
	
	if(crlfIndex != -1)
		{
		// maybe this is the last line and there is no newline at the eol
		tmpPtr2.Set(tmpPtr.Left(crlfIndex));
		}
		
	HBufC* ret = tmpPtr2.AllocLC();
	TPtr ptr= ret->Des();
	ptr.Trim();
	return ret;
	}
/**
CountLinesOfBodyTextL()
Counts the lines of body text in the email aEntry

@param aEntry
A reference to an object representing the email

@param aFooterExists
Reference to a boolean variable - set to ETrue if the footer string is found in the body text

@param aFooterSize
Expected KB left on server inserted into footer string if present 

@return
Number of lines in the body text 
*/
TInt CT_MsgComparePopEmailMsgs::CountLinesOfBodyTextL(CMsvEntry& aEntry, TBool& aFooterExists, TInt& aFooterSize)
	{
	TInt lines = 0;
	aFooterExists=EFalse;
	aFooterSize=0;
	aEntry.SetEntryL(aEntry.EntryId());
	if(aEntry.HasStoreL())
		{
		CMsvStore*	msvStore1= aEntry.ReadStoreL();
		CleanupStack::PushL(msvStore1);
		CParaFormatLayer*	paraFormatLayer1 = CParaFormatLayer::NewL();
		CleanupStack::PushL(paraFormatLayer1);
		CCharFormatLayer*	charFormatLayer1 = CCharFormatLayer::NewL(); 
		CleanupStack::PushL(charFormatLayer1);
		CRichText*	bodyText1=CRichText::NewL(paraFormatLayer1, charFormatLayer1, CEditableText::EFlatStorage, 256);
		CleanupStack::PushL(bodyText1);

		bodyText1->Reset();
		if (msvStore1->HasBodyTextL())
			{
			msvStore1->RestoreBodyTextL(*bodyText1);
			TUint16 val = CEditableText::ELineBreak;
			TInt n = 0;
			TInt pos = 0;
			for(;;)
				{
				TPtrC bodyText = bodyText1->Read(pos);
				n = bodyText.Find(&val, 1);
				if(n < 0)
					break;
				lines++;
				pos += n+1;
				
				//This Check is needed to delete the extra line introduced by communigate Pro Server
				TInt fpos = CheckIfServerMessageExists(bodyText);
				if (fpos != KErrNotFound)
					{
					lines--;
					}
				}
			TPtrC	pBt = bodyText1->Read(0);
			aFooterExists = CheckIfFooterMessageExistsL(pBt , aFooterSize);
			}		
		CleanupStack::PopAndDestroy(4, msvStore1);  //bodyText1,charFormatLayer1,paraFormatLayer1,msvStore1.
		}
	return lines;
	}
/**
CheckIfFooterMessageExistsL()
Checks the email for the presence of the footer string

@param aRecvBodyText
Reference to a descriptor holding the body text

@param aFooterSize
The expected number of KB remaining on the server which has been inserted into the footer string

@return
ETrue if footer string found otherwise EFalse 
*/
TBool CT_MsgComparePopEmailMsgs::CheckIfFooterMessageExistsL(TPtrC& aRecvBodyText , TInt& aFooterSize)
	{
	RResourceFile resFile;
	CT_MsgUtils ::OpenResourceFileL(resFile, iFs, KImEngineResourceFile);	// NB leaves if file not found
	TCleanupItem close(CT_MsgUtils ::CloseResourceFile, &resFile);
	CleanupStack::PushL(close);
	
	HBufC8* buf = NULL;
	buf = resFile.AllocReadLC(PARTIAL_DOWNLOAD_FOOTER_MESSAGE);
	TResourceReader reader;
	reader.SetBuffer(buf);

	HBufC* resourceBuf = (reader.ReadTPtrC()).AllocL();
	CleanupStack::PushL(resourceBuf);

	TInt len = resourceBuf->Find(_L("%d"));
	const TInt KBufLen = 256;
	TBuf<KBufLen> findBuf;

	if(len == KErrNotFound)
		{
		len = resourceBuf->Length();
		}

	if(len > KBufLen)
		{
		len = KBufLen;
		}
	
	findBuf.Copy(resourceBuf->Ptr(), len);
	len = aRecvBodyText.Find(findBuf);

	if(len>=0)
		{
		TPtrC rest=aRecvBodyText.Right(aRecvBodyText.Length()-len-findBuf.Length());
		TLex lex(rest.Left(rest.Locate(TChar(' '))));
		lex.Val(aFooterSize);
		}
	else
		{
		aFooterSize=0;
		}

	CT_MsgUtils ::CloseResourceFile(&resFile);
	CleanupStack::PopAndDestroy(3); // buf, resourceBuf, close
	return (len != KErrNotFound);
	}
/**
 * Validates & completes the construction of this class.
 */
void CMultipartBinIterator::ConstructL() 
	{
#ifdef _DEBUG
	_LIT(KMultipartBin, "application/vnd.wap.multipart.");
	TPtrC contentType;
	iPushMessage.GetContentType(contentType);
	__ASSERT_DEBUG( contentType.Find(KMultipartBin) == 0 , User::Panic(KPushInvalidContentType,0));
#endif
	
	TPtrC8 msgBody;
	if (!iPushMessage.GetMessageBody(msgBody))
		User::Leave(KErrNotFound);
	
	// get the nEntries field from the start of the binary multipart
	TWapBinCodex::ExtractUIntvarL(msgBody, 0, iMultiNumEntries);
		
	if (iMultiNumEntries.iValue == 0) // No multiparts
		User::Leave(KErrCorrupt);

		
	// move the iterator to start off after the multipart header
	iCurrentPartStart = iMultiNumEntries.iOctetSize;		
	}
/**
CountLinesOfBodyTextL()
Counts the lines of body text in the email aEntry

@param aEntry
A reference to an object representing the email

@param aFooterExists
Reference to a boolean variable - set to ETrue if the footer string is found in the body text

@param aFooterSize
Expected KB left on server inserted into footer string if present 

@return
Number of lines in the body text 
*/
TInt CT_MsgComparePopEmailMsgs::CountLinesOfBodyTextL(CMsvEntry& aEntry, TBool& aFooterExists, TInt& aFooterSize)
	{
	TInt lines = 0;
	TInt count =0;
	aFooterExists=EFalse;
	aFooterSize=0;
	aEntry.SetEntryL(aEntry.EntryId());
	if(aEntry.HasStoreL())
		{
		CMsvStore*	msvStore1= aEntry.ReadStoreL();
		CleanupStack::PushL(msvStore1);
		CParaFormatLayer*	paraFormatLayer1 = CParaFormatLayer::NewL();
		CleanupStack::PushL(paraFormatLayer1);
		CCharFormatLayer*	charFormatLayer1 = CCharFormatLayer::NewL(); 
		CleanupStack::PushL(charFormatLayer1);
		CRichText*	bodyText1=CRichText::NewL(paraFormatLayer1, charFormatLayer1, CEditableText::EFlatStorage, 256);
		CleanupStack::PushL(bodyText1);

		bodyText1->Reset();
		if (msvStore1->HasBodyTextL())
			{
			msvStore1->RestoreBodyTextL(*bodyText1);
			TUint16 val = CEditableText::ELineBreak;
			TUint16 val1 = CEditableText::EParagraphDelimiter;
			TUint16 val2 = KUnicodeValue;
			
			TInt n = 0;
			TInt pos = 0;
			for(;;)
				{
				TPtrC bodyText = bodyText1->Read(pos);
				n = bodyText.Find(&val, 1);
								
				// if iStore8BitData flag is set, the line is terminated by "CEditableText::EParagraphDelimiter"			
				if(msvStore1->IsPresentL(KMsvPlainBodyText8))
					{
					if ( 0 == count )
						{
						TPtrC buffer = bodyText.Mid(0,n+2);
						// eg for 8bit the body look as : This is a simple email message.\x2028\x2029\x2029
						// eg for 16bit the body look as: This is a simple email message.\x2028\x2028\x2029
						if((bodyText.Right(2).Compare(KParagraphDelimiter)==KErrNone) && \
									 buffer.Find(&val2,1) != 75)
							{
							lines++;	
							count++;
							}				
							// Increment the line if EParagraphDelimiter or 0x0046 is found sequence as eg:1. \x2028\x2029
							// 2. \x2028\x2029\x2028\x2029\x0046 3. \x2028\x2029\x2028\x2029\x2028\x2029
						else if ( (buffer.Find(&val1,1)==0 && n==-1) || (buffer.Find(&val2,1)==1) \
										|| (buffer.Find(&val1,1)>0) )
							{
							lines++;		
							}
						}
					}
				if(n < 0)
					break;
				lines++;
				pos += n+1;
								
				//This Check is needed to delete the extra line introduced by communigate Pro Server
				TInt fpos = CheckIfServerMessageExists(bodyText);
				if (fpos != KErrNotFound)
					{
					lines--;
					}
				}
			TPtrC	pBt = bodyText1->Read(0);
			aFooterExists = CheckIfFooterMessageExistsL(pBt , aFooterSize);
			}		
		CleanupStack::PopAndDestroy(4, msvStore1);  //bodyText1,charFormatLayer1,paraFormatLayer1,msvStore1.
		}
	return lines;
	}
TBool CTe_LbsIniFileReader::FindNextSection()
{
    _LIT(KSectionHeaderStart, "[");
    _LIT(KSectionHeaderEnd, "]");

    // Clear the previous section information.
    iSection.Set(KNullDesC);

    // Early check to see if we have already searched
    // to the end of the file.
    if (iSectionEnd == iPtr.Length())
    {
        return (EFalse);
    }

    // Begin searching from the end of the last section.
    TPtrC ptrSection = iPtr.Mid(iSectionEnd);

    // Search for the section header '[<text>]'.
    TInt sectionHeaderEnd(KErrNotFound);
    TInt sectionHeaderStart = ptrSection.Find(KSectionHeaderStart);
    if (sectionHeaderStart == KErrNotFound)
    {
        // No match, so no more sections in the file.
        iSectionEnd = iPtr.Length();
        return (EFalse);
    }
    else
    {
        sectionHeaderEnd = ptrSection.Find(KSectionHeaderEnd);
        if ((sectionHeaderEnd == KErrNotFound)
                || (sectionHeaderEnd < sectionHeaderStart))
        {
            // Parsing error - the section header was not closed properly
            iSectionEnd = iPtr.Length();
            return (EFalse);
        }
        else if (sectionHeaderEnd == ptrSection.Length())
        {
            // Parsing error - the section header ends at the end
            // of the file, so the section is empty!
            iSectionEnd = iPtr.Length();
            return (EFalse);
        }
    }
    iSection.Set(ptrSection.Mid(sectionHeaderEnd + 1));

    // Search for the start of the next section
    // - take this to be the end of the current section.
    TInt sectionEnd = iSection.Find(KSectionHeaderStart);
    if (sectionEnd != KErrNotFound)
    {
        iSection.Set(iSection.Left(sectionEnd));
        iSectionEnd += (sectionHeaderStart + sectionEnd + 1);
    }
    else
    {
        // No more sections after this one, so set the index to the end.
        iSectionEnd = iPtr.Length();
    }

    return (ETrue);
}
/**
 * Finds the java attribute specified by
 * aAttributeName from aJad and returns the value of that attribute
 * in HBufC.
 * @param[in] aJad contents of Jad file
 * @param[in] aAttributeName the name of a java attribute
 * @return the value of the attribute. Caller gets the ownership of the
 * returned HBufC.
 * If the attribute is not found, returns NULL
 */
HBufC *CSilentMIDletInstall::ParseAttribute(const HBufC *aJad, const TDesC& aAttributeName)
{
    JELOG2(EJavaPreinstaller);

    TInt    nInd(0);
    TBool   fullNameFound(EFalse);
    TUint32 ch;

    // Start parsing from the beginning of the Jad file
    TPtrC parsePtr = aJad->Mid(nInd);

    do
    {
        // Find attribute name
        nInd = parsePtr.Find(aAttributeName);
        if (nInd < 0)
        {
            // Returns NULL if the attribute cannot be found
            return NULL;
        }

        // Check that the attribute name was preceded by line break or
        // it was at the beginning of the Jad file
        if (nInd == 0)
        {
            fullNameFound = ETrue;
        }
        else
        {
            ch = parsePtr[nInd-1];
            if ((ch == CR) || (ch == LF))
            {
                fullNameFound = ETrue;
            }
            else
            {
                // Name was just a part of longer string (not 'word match')
                fullNameFound = EFalse;
                // Skip to the last character of the found match.
                // We can skip because we are insterested only in 'word' matches
                // so the next cannot start inside the area we are skipping now.
                parsePtr.Set(parsePtr.Mid(nInd + aAttributeName.Length() - 1));
                continue;
            }
        }

        // Check whether Jad file ends after attribute name
        if (nInd + aAttributeName.Length() >= parsePtr.Length())
        {
            // Jad file ends immediately after the found
            // attribute name instance. No attribute value
            return NULL;
        }

        // Check that there is a white space character or colon after
        // attribute name
        ch = parsePtr[nInd + aAttributeName.Length()];
        if ((ch == COLON) || (ch == SP) || (ch == HT))
        {
            fullNameFound = ETrue;
        }
        else
        {
            // Name was just a part of longer string (not 'word match')
            fullNameFound = EFalse;
            // Skip to the next character after the found match
            parsePtr.Set(parsePtr.Mid(nInd + aAttributeName.Length()));
            continue;
        }
    }
    while (!fullNameFound);

    // Skip to the end of the attribute name and find ':' after the name.
    // The skipped characters must be white space chacraters, otherwise
    // the attribute name is illegal and Java Installer will not accept
    // the Jad file.
    parsePtr.Set(parsePtr.Mid(nInd + aAttributeName.Length() - 1));
    nInd = parsePtr.Locate(COLON);
    if (nInd < 0)
    {
        return NULL;
    }
    nInd++;

    // Parse attribute value (CR or LF ends)
    TInt nEndInd = parsePtr.Locate(CR);
    TInt nTmpInd = parsePtr.Locate(LF);

    if (KErrNotFound == nEndInd)
    {
        nEndInd = parsePtr.Length() - 1;
    }
    if (KErrNotFound == nTmpInd)
    {
        nTmpInd = parsePtr.Length() - 1;
    }

    if (nTmpInd < nEndInd)
    {
        nEndInd = nTmpInd;
    }

    if (nEndInd < nInd)
    {
        return NULL;
    }

    TPtrC attributeValue = parsePtr.Mid(nInd, (nEndInd - nInd));

    // Remove possible white space from the beginning and end of the value
    HBufC *bufValue = attributeValue.Alloc();
    if (NULL == bufValue)
    {
        return NULL;
    }
    TPtr value = bufValue->Des();
    value.Trim();

    return bufValue;
} // parseAttribute
TBool CDataWrapperBase::GetCommandStringParameterL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult)
	{
	TBool	ret=EFalse;

	if ( aSectName.Length()!=0 )
		{
		ret=CDataWrapper::GetStringFromConfig(aSectName, aKeyName, aResult);

		for ( TInt index=iInclude.Count(); (index>0) && (!ret); )
			{
			ret=iInclude[--index]->FindVar(aSectName, aKeyName, aResult);
			}
		}

	if ( ret )
		{
		if ( aResult.Match(KMatch)!=KErrNotFound )
			{
			//	We have an entry of the format
			//	entry =*{section,entry}*
			//	where * is one or more characters
			//	We need to construct this from other data in the ini file replacing {*,*}
			//	with the data from
			//	[section]
			//	entry =some_value
			HBufC*	buffer=HBufC::NewLC(aResult.Length());
			buffer->Des().Copy(aResult);

			TInt	startLength=KStart().Length();
			TInt	sparatorLength=KSeparator().Length();
			TInt	endLength=KEnd().Length();
			TInt	bufferLength;
			TInt	start;
			TInt	sparator;
			TInt	end;
			TPtrC	remaining;
			TLex	lex;
			do
				{
				bufferLength=buffer->Length();
				start=buffer->Find(KStart);

				remaining.Set(buffer->Des().Right(bufferLength-start-startLength));
				sparator=remaining.Find(KSeparator);
				remaining.Set(remaining.Right(remaining.Length()-sparator-sparatorLength));
				sparator += (start + startLength);

				end=remaining.Find(KEnd) + sparator + sparatorLength;

				TPtrC	sectionName(buffer->Ptr()+start+startLength, sparator-start-startLength);
				TPtrC	keyName(buffer->Ptr()+sparator+sparatorLength, end-sparator-sparatorLength);
				sectionName.Set(TLex(sectionName).NextToken());
				keyName.Set(TLex(keyName).NextToken());

				TInt	entrySize=0;
				TPtrC	entryData;
				TBool	found=CDataWrapper::GetStringFromConfig(sectionName, keyName, entryData);
				for ( TInt index=iInclude.Count(); (index>0) && (!found);  )
					{
					found=iInclude[--index]->FindVar(sectionName, keyName, entryData);
					}
				if ( found )
					{
					entrySize=entryData.Length();
					}

				TInt	newLength=start + bufferLength - end - endLength + entrySize;
				HBufC*	bufferNew=HBufC::NewLC(newLength);
				bufferNew->Des().Copy(buffer->Ptr(), start);
				if ( entrySize>0 )
					{
					bufferNew->Des().Append(entryData);
					}
				bufferNew->Des().Append(buffer->Ptr() + end + endLength, bufferLength - end - endLength);
				CleanupStack::Pop(bufferNew);
				CleanupStack::PopAndDestroy(buffer);
				buffer=bufferNew;
				CleanupStack::PushL(buffer);
				}
			while ( buffer->Match(KMatch)!=KErrNotFound );
			iBuffer.Append(buffer);
			CleanupStack::Pop(buffer);
			aResult.Set(*buffer);
			INFO_PRINTF4(KDataRead, &aSectName, &aKeyName , &aResult);
			}
		}

	return ret;
	}
/**
Finds the keystring from the source string and replaces it with the
replacement string. The formated string is stored in the destination
descriptor.
*/
TInt CResourceLoader::Formater(TDes& aDest, const TDesC& aSource, const TDesC& aKey, const TDesC& aSubs, TBidiText::TDirectionality aDirectionality)    
    {
    // substitute string must not contain KSubStringSeparator, 
    // or results will be unpredictable 
    __ASSERT_DEBUG(aSubs.Locate(KSubStringSeparator) == KErrNotFound, 
        User::Panic(KPanicCategory, EInvalidSubstitute));

    TInt keylength(aKey.Length());

    //aDest must be empty.
    aDest.Zero();

    // offset indicates end of last handled key in source
    TInt offset(0);

    // offset in destination string
    TInt desOffset(0);

    // Substring directionalities are adjusted after all changes are done.
    TBool checkSubstringDirectionalities(EFalse);

    // count is the position in the source from which the substring starts
    TInt count(0);

    // Replaced parameters count
    TInt replaceCount(0);

    while (count != KErrNotFound)
        {
        // desCount is the position of the substring starts in destination.
        TInt desCount(0);

        TPtrC remainder = aSource.Right(aSource.Length() - offset);
        count = remainder.Find(aKey);

        TInt maxSubLength = -1;
        if (count != KErrNotFound)
            {
            replaceCount++;
            desOffset += count;
            offset += count;
            count = offset;
            desCount = desOffset;

            // copy source to destination if first time
            if (aDest.Length() == 0)
                aDest.Append(aSource);

            // delete found key from destination
            aDest.Delete(desCount, keylength);

            offset += keylength; // increase offset by key length

            if (count + keylength < (aSource.Length()-1)) // aKey is not at the end of string
                {
                if (aSource[count+keylength] == '[') // Key includes max datalength
                    {
                    maxSubLength = 10*(aSource[count+keylength+1]-'0') 
                                   + (aSource[count+keylength+2]-'0');
                    aDest.Delete(desCount,4); // Length information stored->delete from descriptor
                    offset += 4; // increase offset by max sub length indicator
                    }
                }
         
            aDest.Insert(desCount, aSubs);
        
            desOffset = desCount + aSubs.Length();

            if (maxSubLength > 0 && aSubs.Length() > maxSubLength)
                {
                aDest.Delete(desCount+maxSubLength-1, aSubs.Length()+1-maxSubLength);     
                TText ellipsis(KEllipsis);
                aDest.Insert(desCount+maxSubLength-1, TPtrC(&ellipsis,1));
                desOffset = desCount + maxSubLength;
                }

            TBidiText::TDirectionality subsDir =
                TBidiText::TextDirectionality(aDest.Mid(desCount, desOffset - desCount));

            // If inserted string has different directionality,
            // insert directionality markers so that bidi algorithm works in a desired way.
            if (aDirectionality != subsDir)
                {
                checkSubstringDirectionalities = ETrue;

                TInt freeSpace = aDest.MaxLength() - aDest.Length();

                // Protect the directionality of the inserted string.
                if (freeSpace >= KExtraSpaceForSubStringDirMarkers)
                    {
                    TBuf<1> subsMarker;
                    subsMarker.Append(subsDir == TBidiText::ELeftToRight ?
                        KLRMarker : KRLMarker);

                    aDest.Insert(desOffset, subsMarker);
                    aDest.Insert(desCount, subsMarker);
                    desOffset += KExtraSpaceForSubStringDirMarkers;
                    }
                }
            }
        }

    // Adjust substring directionality markers if necessary
    // and if there is enough room in destination string
    if (checkSubstringDirectionalities)
        {
        TText mainMarker = (aDirectionality == TBidiText::ELeftToRight ? 
            KLRMarker : KRLMarker);

        TInt freeSpace = aDest.MaxLength() - aDest.Length();

        // If not already done, protect the directionality of the original string
        // and all of the KSubStringSeparator separated substrings.
        if (freeSpace > 0 
            && aDest.Length()
            && aDest[0] != mainMarker 
            && aDest[0] != KSubStringSeparator
            && aDest[0] != KDirNotFound)  
            {
            aDest.Insert(0, TPtrC(&mainMarker, 1));
            freeSpace--;
            }

        // Find and protect KSubStringSeparator separated substrings.
        // Go through string backwards so that any changes will not affect indexes 
        // that are not yet checked.
        TInt j(aDest.Length()-1);
        while (freeSpace > 0 && j >= 0) 
            {
            if (aDest[j] == KSubStringSeparator && j < (aDest.Length() - 1) 
                && aDest[j+1] != mainMarker && aDest[j+1] != KDirNotFound)
                {
                aDest.Insert(j+1, TPtrC(&mainMarker, 1));
                freeSpace--;
                }
            j--;
            }
        }

    return replaceCount;
    }
void CT_LbsPrivFwBaseRequest::VerifyPrivNotifierData(CPosNetworkPrivacyRequestInfo* aNetPrivReqInfo, const TLbsTestRequestInfo& aExtReqInfo)
	{
	INFO_PRINTF1(_L("CT_LbsPrivFwBaseRequest::VerifyPrivNotifierData()"));

	TBuf<KLbsMaxClientNameSize2> testNotifClientName;
	TLbsTestRequestInfo::TFormatIndicator testNotifClientId;
	aExtReqInfo.GetClientName(testNotifClientName);
	testNotifClientId = aExtReqInfo.ClientNameFormat();
	
	TBuf<KLbsMaxRequesterIdSize2> testNotifRequesterName;
	TLbsTestRequestInfo::TFormatIndicator testNotifRequesterId;
	aExtReqInfo.GetRequesterId(testNotifRequesterName);
	testNotifRequesterId = aExtReqInfo.RequesterIdFormat();

	TLbsTestRequestInfo::TRequestType storedRequestType;
	TLbsTestRequestInfo::TRequestType receivedRequestType;

	receivedRequestType = aExtReqInfo.RequestType();
	
	TPtrC testApiClient;
	TPtrC testApiRequestor;
	
	if(iRequestInfoType == ERequestInfoTypeSupl)
		{
		CPosSUPLPrivacyRequestInfo* suplReqInfo = static_cast<CPosSUPLPrivacyRequestInfo*>(aNetPrivReqInfo);
		CPosSUPLPrivacyRequestInfo::TIdType testApiRequestorId;
		CPosSUPLPrivacyRequestInfo::TIdType testApiClientId;	
		
		suplReqInfo->GetLCSClient(testApiClient, testApiClientId);
		suplReqInfo->GetRequestor(testApiRequestor, testApiRequestorId);
		storedRequestType = suplReqInfo->RequestType();
		
		if(storedRequestType != receivedRequestType)
			{
			ERR_PRINTF3(_L("CT_LbsPrivFwBaseRequest::VerifyPrivNotifierData() - Failed Client RequestTypes Differ, sent value %d, recieved value %d."), storedRequestType, receivedRequestType);
			iStep->SetTestStepResult(EFail);
			}
		
		if(!CompareRequestInfoType(testNotifClientId, testApiClientId))
			{
			ERR_PRINTF1(_L("CT_LbsPrivFwBaseRequest::VerifyPrivNotifierData() - Failed Client Ids Differ"));
			iStep->SetTestStepResult(EFail);
			}
		if(!CompareRequestInfoType(testNotifRequesterId, testApiRequestorId))
			{
			ERR_PRINTF1(_L("CT_LbsPrivFwBaseRequest::VerifyPrivNotifierData() - Failed Requester Ids Differ"));
			iStep->SetTestStepResult(EFail);
			}
		}
	else if(iRequestInfoType == ERequestInfoTypeGsm)
		{
		CPosGSMPrivacyRequestInfo* gsmReqInfo = static_cast<CPosGSMPrivacyRequestInfo*>(aNetPrivReqInfo);
		CPosGSMPrivacyRequestInfo::TIdType testApiRequestorId;
		CPosGSMPrivacyRequestInfo::TIdType testApiClientId;
		
		gsmReqInfo->GetLCSClient(testApiClient, testApiClientId);
		gsmReqInfo->GetRequestor(testApiRequestor, testApiRequestorId);
		storedRequestType = gsmReqInfo->RequestType();
		
		if(storedRequestType != receivedRequestType)
			{
			ERR_PRINTF3(_L("CT_LbsPrivFwBaseRequest::VerifyPrivNotifierData() - Failed Client RequestTypes Differ, sent value %d, recieved value %d."), storedRequestType, receivedRequestType);
			iStep->SetTestStepResult(EFail);
			}
			
		if(!CompareRequestInfoType(testNotifClientId, testApiClientId))
			{
			ERR_PRINTF1(_L("CT_LbsPrivFwBaseRequest::VerifyPrivNotifierData() - Failed Client Ids Differ"));
			iStep->SetTestStepResult(EFail);
			}
		if(!CompareRequestInfoType(testNotifRequesterId, testApiRequestorId))
			{
			ERR_PRINTF1(_L("CT_LbsPrivFwBaseRequest::VerifyPrivNotifierData() - Failed Requester Ids Differ"));
			iStep->SetTestStepResult(EFail);
			}
		}
	// Notifier Names may be truncated as a shorter buffer is used.
	if(iPrivacyHandler != EPrivacyHandleByNotifier)
		{
		if(testApiClient.CompareC(testNotifClientName) != 0)
			{
			ERR_PRINTF1(_L("CT_LbsPrivFwBaseRequest::VerifyPrivNotifierData() - Failed Client Names Differ"));
			iStep->SetTestStepResult(EFail);
			}
		if(testApiRequestor.CompareC(testNotifRequesterName) != 0)
			{
			ERR_PRINTF1(_L("CT_LbsPrivFwBaseRequest::VerifyPrivNotifierData() - Failed Requester Names Differ"));
			iStep->SetTestStepResult(EFail);
			}
		}
	else
		{
		/**
		 * Notifier validation here
		 * -Requestor Id should be max32 characters
		 * -Client name should be max64 Characters
		 * -The first 32/64 or less characters of each should match.
		 * testApiClient is longest, testNotifClientName comes back from notifier and SHOULD be truncated
		 */
		

		TPtrC rwClientName(testNotifClientName);
		TPtrC rwRequesterName(testNotifRequesterName);
		
		TInt numOfCharactersInClientName = rwClientName.Length();
		TInt numOfCharactersInRequesterName = rwRequesterName.Length();
		
		if(	numOfCharactersInClientName > KLbsMaxClientNameSize)
			{
			ERR_PRINTF1(_L("CT_LbsPrivFwBaseRequest::VerifyPrivNotifierData() - Failed, Client too long."));
			iStep->SetTestStepResult(EFail);
			}
		
		if(	numOfCharactersInRequesterName > KLbsMaxRequesterIdSize)
			{
			ERR_PRINTF1(_L("CT_LbsPrivFwBaseRequest::VerifyPrivNotifierData() - Failed, Requestor too long."));
			iStep->SetTestStepResult(EFail);
			}
		
		if( testApiClient.Find(testNotifClientName) == KErrNotFound ||
			testApiClient.Find(testNotifClientName) > 0	)
			{
			ERR_PRINTF1(_L("CT_LbsPrivFwBaseRequest::VerifyPrivNotifierData() - Failed, Client name mismatch."));
			iStep->SetTestStepResult(EFail);
			}
		
		if( testApiRequestor.Find(testNotifRequesterName) == KErrNotFound ||
			testApiRequestor.Find(testNotifRequesterName) > 0 )
			{
			ERR_PRINTF1(_L("CT_LbsPrivFwBaseRequest::VerifyPrivNotifierData() - Failed, Requester name mismatch."));
			iStep->SetTestStepResult(EFail);
			}
		
		}
	}
示例#17
0
TBool CIniFile::FindVar(const TDesC &aSection,
						const TDesC &aVarName,
						TPtrC &aResult)
//
// Find a variable's value given a section name and a var name
//
	{
	__ASSERT_DEBUG(aSection.Length()<=(TInt)KTokenSize,Panic(ESectionNameTooBig));
	__ASSERT_DEBUG(aVarName.Length()<=(TInt)KTokenSize,Panic(EVarNameTooBig));

	TPtr sectionToken = iToken->Des();
	_LIT(KSectionTokenString,"[%S]");
	sectionToken.Format(KSectionTokenString,&aSection);
	TInt sectionStart = iPtr.Find(sectionToken);
	TInt ret = ETrue;
	if (sectionStart == KErrNotFound)
		{
		ret = EFalse;
		}
	else
		{		
		TPtrC section = iPtr.Mid(sectionStart);
		TInt endBracket = section.Find(TPtrC(_S("]")));
		if (endBracket == KErrNotFound)
			{
			ret = EFalse;
			}
		else
			{
			sectionStart += endBracket + 1;
			section.Set(iPtr.Mid(sectionStart));
			
			TInt sectionEnd = section.Find(TPtrC(_S("[")));
			if (sectionEnd == KErrNotFound)
				{
				sectionEnd = iPtr.Length() - sectionStart;
				}
			else
				{
				sectionEnd--;
				}
			section.Set(iPtr.Mid(sectionStart,sectionEnd));
			TPtr varToken = iToken->Des();
			_LIT(KVarTokenString,"%S=");
			varToken.Format(KVarTokenString,&aVarName);
			TInt pos = section.Find(varToken);
			if (pos == KErrNotFound)
				{
				ret = EFalse;
				}
			else
				{
				// 'lex' points at the start of the data
				TPtrC lex(section.Mid(pos));
				TInt startpos = lex.Locate(TChar('='));
				startpos++; // startpos points immediately after the =.
				while ( TChar(lex[startpos]).IsSpace() )
					{
					startpos++; // skip to start of data
					}
				TInt endpos = lex.Locate(TChar('\n')); // assumes \n is after =.
				if ( endpos == KErrNotFound ) // may not be \n on last line
					{
					endpos = section.Length()-1;
					}
				aResult.Set(lex.Mid(startpos).Ptr(),endpos-startpos-1);
				}
			}
		}

	return ret;
	}
示例#18
0
void CUrl::Part(TComponent aComponent, const TDesC& aUrl, TInt& aStartPos, TInt& aEndPos) const
//
// Takes a descriptor as a url and parses it for the start and end positions of a particular component. 
// KCUrlInvalidCharPos is used to indicate that component is not in url.
// 
// Based on RFC2396
	{
	aStartPos = aEndPos = KCUrlInvalidCharPos;

	TPtrC url = aUrl;
	// search for first of ':' | '/' | '?' | '#'
	TInt stripped =0;

	TInt colonPos = aUrl.Locate(':');
	__ASSERT_ALWAYS(colonPos != 0,Panic(EInvalidUrl));		// if ':' is first character then it is invalid
	TInt hashPos = aUrl.Locate('#');
	TInt slashPos = aUrl.Locate('/');
	TInt queryPos = aUrl.Locate('?');

	colonPos = colonPos == KErrNotFound ? KMaxTInt : colonPos;
	hashPos = hashPos == KErrNotFound ? KMaxTInt : hashPos;
	slashPos = slashPos == KErrNotFound ? KMaxTInt : slashPos;
	queryPos = queryPos == KErrNotFound ? KMaxTInt : queryPos;

	// if ':' is before others then there is a scheme so extract it
	if (colonPos < hashPos && colonPos < slashPos && colonPos < queryPos)
		{
		if (aComponent == EUrlScheme)
			{
			aStartPos = stripped;
			aEndPos = colonPos -1;
			return;
			}

		if (url.Length() == colonPos + 1) // reached the end of the url
			return;	
		url.Set(url.Mid(colonPos+1));
		stripped += colonPos+1;
		hashPos -= colonPos+1;
		slashPos -= colonPos+1;
		queryPos -= colonPos+1;
		}

	// if first 2 characters are '//' then a host exists, 
	if (url.Find(KUrlLoc) == 0)
		{
		TInt urlLocLength = KUrlLoc().Length();
		if (url.Length() == urlLocLength) // reached the end of the url
			return;
		// extract '//' and rescan for '/'
		url.Set(url.Mid(urlLocLength));
		stripped += urlLocLength;
		hashPos -= urlLocLength;
		queryPos -= urlLocLength;
		slashPos = url.Locate('/');
		slashPos = slashPos == KErrNotFound ? KMaxTInt : slashPos;

		// host is ended by first of '#' | '?' | '/' | end of url
		TInt hostEndCharPos = slashPos;
		hostEndCharPos = hashPos < hostEndCharPos ? hashPos : hostEndCharPos;
		hostEndCharPos = queryPos < hostEndCharPos ? queryPos : hostEndCharPos;
		hostEndCharPos = url.Length() < hostEndCharPos ? url.Length() : hostEndCharPos;
	
		if (aComponent == EUrlAuthority)
			{
			aStartPos = stripped;
			aEndPos = hostEndCharPos+stripped-1;
			return;
			}
		if (aComponent == EUrlLocation ||
			aComponent == EUrlUsername ||
			aComponent == EUrlPassword)
			{
			aStartPos = stripped;
			aEndPos = hostEndCharPos+stripped-1;
			// We need part of the authority. Extract it
			PartOfAuthority(aComponent, aUrl, aStartPos, aEndPos);
			return;
			}
		//	Have we reached the end of the url
		if (url.Length() == hostEndCharPos)
			return; 
		// extract host	
		url.Set(url.Mid(hostEndCharPos));
		stripped += hostEndCharPos;
		slashPos -= hostEndCharPos;
		hashPos -= hostEndCharPos;
		queryPos -= hostEndCharPos;		
		}

	//	If first character is '/' | this is the start of a relative url | there is no authority then path exists
	//	as long as it isn't just a query or fragment
	if ((slashPos == 0 || stripped == 0 || stripped == colonPos +1 ) && hashPos != 0 && queryPos !=0)
		{ 
		TInt pathEndCharPos = queryPos;
		pathEndCharPos = hashPos < pathEndCharPos ? hashPos : pathEndCharPos;
		pathEndCharPos = url.Length() < pathEndCharPos ? url.Length() : pathEndCharPos;
		if (aComponent == EUrlPath)
			{
			aStartPos = stripped;
			aEndPos = pathEndCharPos+stripped-1;
			return;
			}
		if (url.Length() == pathEndCharPos) // reached the end of the url
			return;
		//	extractPath
		url.Set(url.Mid(pathEndCharPos));
		stripped += pathEndCharPos ;
		queryPos -= pathEndCharPos ;
		hashPos -= pathEndCharPos ;
		}

	// if first is '?' then query exists
	if (queryPos == 0) 	
		{
		// extract ?, query is ended by '#' | end of url
		if (url.Length() == 1)	// reached the end of the url
			return;
		url.Set(url.Mid(1));
		stripped += 1;
		hashPos -= 1;
		// extract query
		TInt queryEndCharPos = hashPos;
		queryEndCharPos = url.Length() < queryEndCharPos ? url.Length() : queryEndCharPos;
		if (aComponent == EUrlQuery)
			{
			aStartPos = stripped;
			aEndPos = queryEndCharPos+stripped-1;
			return;
			}
		if (url.Length() == queryEndCharPos) // reached the end of the url
			return;
		url.Set(url.Mid(queryEndCharPos));
		stripped += queryEndCharPos;
		hashPos -= queryEndCharPos;
		}

	if (hashPos == 0)
		{
		if (url.Length() == 1)	// reached the end of the url
			return;
		// extract hash
		url.Set(url.Mid(1));
		stripped += 1;
		// fragment left
		if (aComponent == EUrlFragment)
			{
			aStartPos = stripped;
			aEndPos = stripped + url.Length() -1;
			return;
			}
		}
	__ASSERT_DEBUG(	aStartPos == aEndPos && aEndPos == KCUrlInvalidCharPos, Panic(EInvalidUrl));
	}