Example #1
0
/*
-------------------------------------------------------------------------------

    Class: CStifParser

    Method: NextSectionFileL

    Description: Parses sections from configuration files.

    Open and read configuration source and parses a required section.
    If start tag is empty the parsing starts beginning of the configuration
    file. If end tag is empty the parsing goes end of configuration file.
    This method will parse next section after the earlier section if aSeeked
    parameter is not given.
    If configuration file includes several sections with both start and end
    tags so aSeeked parameter seeks the required section. The aSeeked
    parameters indicates section that will be parsed.

    Parameters: const TDesC& aStartTag: in: Indicates a start tag for parsing
                const TDesC& aEndTag: in: Indicates an end tag for parsing
                TInt aSeeked: in: a seeked section which will be parsed

    Return Values:  CStifSectionParser* : pointer to CStifSectionParser object
                    NULL will return if file size or aSeeked is not positive
                    NULL will return if start tag is not found
                    NULL will return if end tag is not found
                    NULL will return if parsed section length is not positive

    Errors/Exceptions:  Leaves if called Size method fails
                        Leaves if HBufC::NewLC method leaves
                        Leaves if called Read method fails
                        Leaves if CStifSectionParser::NewL methods leaves

    Status: Proposal

-------------------------------------------------------------------------------
*/
CStifSectionParser* CStifParser::NextSectionFileL( const TDesC& aStartTag,
                                                   const TDesC& aEndTag,
                                                   TInt aSeeked )
    {
	HBufC *bufSection = iFileParser->NextSectionL(aStartTag, aEndTag, iOffset, aSeeked);

	if(bufSection)
		{
		CleanupStack::PushL(bufSection);
		TPtr bufSectionPtr(bufSection->Des());

		if(iCommentType == ECStyleComments)
			{
			ParseCommentsOff(bufSectionPtr);
			}

		// Make CStifSectionParser object and alloc required length
		CStifSectionParser* section = CStifSectionParser::NewL(bufSection->Length());
		CleanupStack::PushL(section);

		// Copy required data to the section object
		section->SetData(bufSectionPtr, 0, bufSection->Length());

		// Clean
		CleanupStack::Pop(section);
		CleanupStack::PopAndDestroy(bufSection);

		return section;
		}

	return NULL;
    }
Example #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;
	}
Example #3
0
HBufC* CPolicyStore::MakeNewPolicyNameL(const TDes& aOriginalPolicyName, 
                                     TInt aSequenceNumber)
    {
    LOG_("-> CPolicyStore::MakeNewPolicyName");

    const TInt KMaxSequenceNumberStringLength = 32;
    _LIT(KSequenceNumberFormat, "(%d)");
    HBufC* sequenceNumberString = HBufC::NewLC(KMaxSequenceNumberStringLength);
    sequenceNumberString->Des().Format(KSequenceNumberFormat, aSequenceNumber);

    // New name string to be returned
    HBufC* retBuf(NULL);
    // Usage of Trim method in PinParser decreases the length by 2 items
    TInt spaceLeft = aOriginalPolicyName.MaxLength() - 2 - aOriginalPolicyName.Length();
    TInt sequenceNumberStringLength = sequenceNumberString->Length();
                                      
    if (sequenceNumberStringLength <= spaceLeft)
        {
        // There's enough free space for the sequence
        // number, so we can just add append it
        LOG_1(" Sequence number string: '%S'", &(*sequenceNumberString)); 

        // Determine final string length for dynamic allocation
        TInt len = aOriginalPolicyName.Length() + sequenceNumberString->Length();
        retBuf = HBufC::NewLC(len);

        // Construct the final name string
        TPtr16 ptr = retBuf->Des();
        ptr.Append(aOriginalPolicyName.Left(aOriginalPolicyName.Length()));
        ptr.Append(sequenceNumberString->Left(sequenceNumberString->Length()));
        }
    else
        {
        // There's not enough space for the sequence
        // number so we override the end of the policy
        // name with the sequence number
        TInt lengap = sequenceNumberStringLength - spaceLeft;

        // Determine final string length for dynamic allocation
        TInt len = aOriginalPolicyName.MaxLength();
        retBuf = HBufC::NewLC(len);

        // Construct the final name string
        TPtr16 ptr = retBuf->Des();
        ptr.Append(aOriginalPolicyName.Left(aOriginalPolicyName.Length() - lengap));
        ptr.Append(sequenceNumberString->Left(sequenceNumberString->Length()));
        }

    // Just pop, and delete the non-returned value explicitly
    CleanupStack::Pop(2); // retBuf, sequenceNumberString
    delete sequenceNumberString;

    LOG_("<- CPolicyStore::MakeNewPolicyName");
    return retBuf;
    }
Example #4
0
TBool CBgAnimHost::GetPluginConfigurationL()
    {
    // dig out the skin config from skin server
    HBufC* configstr = NULL;
    CAknsSrvChunkLookup* cl = iSkinSrv.CreateChunkLookupL();
    CleanupStack::PushL(cl);
    CAknsStringItemDef* configitem = static_cast<CAknsStringItemDef*>(cl->LookupAndCreateDefL( KAknsIIDPropertyAnimBgParam )); 
    User::LeaveIfNull(configitem);
    CleanupStack::PushL(configitem);
    configstr = configitem->String().AllocL();
    CleanupStack::PopAndDestroy(2); // cl, configitem
    CleanupStack::PushL(configstr);
    
    TLex lex(*configstr);
    HBufC* dllname = lex.NextToken().AllocL();
    CleanupStack::PushL(dllname);
    if (!dllname || !dllname->Length())
        {
        User::Leave(KErrNotFound);
        }

    HBufC* assetdir = lex.NextToken().AllocL();
    CleanupStack::PushL(assetdir);
    if (!assetdir || !assetdir->Length())
        {
        User::Leave(KErrNotFound);
        }
    
    TBool confchanged = EFalse;
    if (!iCurrentPluginDllName || !iCurrentPluginAssetDir || 
        (iCurrentPluginDllName && !iCurrentPluginDllName->CompareF(*dllname)) ||
        (iCurrentPluginAssetDir && !iCurrentPluginAssetDir->CompareF(*assetdir)) )
        
        {
        confchanged = ETrue;
        delete iCurrentPluginDllName;
        delete iCurrentPluginAssetDir;
        iCurrentPluginDllName = dllname;    
        iCurrentPluginAssetDir = assetdir;
        CleanupStack::Pop(2); // dllname, assetdir
        }
    else
        {
        CleanupStack::PopAndDestroy(2); // dllname, assetdir
        }
        
    CleanupStack::PopAndDestroy(); // configstr
    
    return confchanged;
    }
EXPORT_C HBufC* CResourceLoader::Load2L(TInt aResourceId, TInt aInt )
    {
    HBufC* resbuf = Load2LC( aResourceId );
    TPtr retptr = resbuf->Des();
    //
    //Converting input TInt to a descriptor. This way the size
    //of the return string can be controlled.
    //
    TBuf<KIntSize> intbuf;
    intbuf.Num(aInt);

    if (LanguageSpecificNumberConverter::IsConversionNeeded())
        LanguageSpecificNumberConverter::Convert(intbuf);
    //
    // Get number of sub strings
    TInt count = GetSubStringCount(retptr); 
    TBool marker(EFalse); 
    
    if (count >= 1)
        {
        HBufC* buffer = ResolveSubStringDirsL(retptr, count, &marker);
        CleanupStack::PushL(buffer);
        
        TBool found(EFalse);
        TBidiText::TDirectionality mainDir = DirectionalityL(*buffer , &found);
        
        //Adding int    
        HBufC* retbuf = FormatStringL(*buffer, KNumKeyBuf, intbuf, mainDir);
        
        CleanupStack::PopAndDestroy(buffer);
        CleanupStack::PopAndDestroy(resbuf);
                        
        if (marker && retbuf->Length())
            {
            TPtr ptr = retbuf->Des();
            RemoveNoDirMarkers(ptr);
            } 
        __ASSERT_DEBUG(retbuf->Length(), 
                    User::Panic(KPanicCategory, EKeyStringNotFound));
        return retbuf;
        }
     else
        {
        CleanupStack::PopAndDestroy(resbuf);
        HBufC* retbuf = HBufC::NewL(0); // return empty buffer
        __ASSERT_DEBUG(retbuf->Length(), 
                    User::Panic(KPanicCategory, EKeyStringNotFound));
        return retbuf;
        }
    }
// ---------------------------------------------------------------------------
// CServerAuthFailOperation::SaveServerCertToTrustedSiteCertStoreL()
// ---------------------------------------------------------------------------
//
void CServerAuthFailOperation::SaveServerCertToTrustedSiteCertStoreL()
    {
    TRACE( "CServerAuthFailOperation::SaveServerCertToTrustedSiteCertStoreL" );

    ASSERT( iCertLabel == NULL );
    CX509Certificate* serverCert = CX509Certificate::NewLC( iEncodedServerCert );
    const CX500DistinguishedName& dName = serverCert->SubjectName();
    HBufC* commonName = dName.ExtractFieldL( KX520CommonName );
    if( commonName )
        {
        CleanupStack::PushL( commonName );
        TInt commonNameLen = commonName->Length();
        if( commonNameLen > 0 && commonNameLen <= KMaxCommonNameLength )
            {
            iCertLabel = commonName->AllocL();
            }
        CleanupStack::PopAndDestroy( commonName );
        }
    CleanupStack::PopAndDestroy( serverCert );

    if( !iCertLabel )
        {
        iCertLabel = iServerName->AllocL();
        }

    iTrustedSiteCertStore->Add( *iCertLabel, EX509Certificate, EPeerCertificate,
            NULL, NULL, iEncodedServerCert, iStatus );
    iMode = ESavingServerCert;
    SetActive();
    }
// ---------------------------------------------------------------------------
//  CNSmlDmFotaAdapterDb::GetEmptyFinalResultsL()
//  Finds all the rows in FwMgmtObject table that have null final result, 
//  server id equals to aServerId and management uri is not an empty string.
//  Puts the PkgIds of those rows to aArray.
// ---------------------------------------------------------------------------
// 
void CNSmlDmFotaAdapterDb::GetEmptyFinalResultsL( RNSmlDmFwObjectArray& aArray, 
                                                  const TDesC8& aServerId )
    {
    _DBG_FILE("CNSmlDmFotaAdapterDb::GetEmptyFinalResultsL(serverid): begin");
    
    aArray.Reset();
    
    HBufC* serverId = ConvertTo16BitLC( aServerId );
    
    HBufC* sql = HBufC::NewLC( 
                        KNSmlGetUnfinishedFwMgmtObjectByServerId().Length() + 
                        KNSmlFwMgmtObjectIntLength + 
                        serverId->Length() );
    
    sql->Des().Format( KNSmlGetUnfinishedFwMgmtObjectByServerId, 
                       KNSmlFotaNullResult, 
                       serverId );
    
    PrepareViewL( *sql, iView.EReadOnly );

    CleanupStack::PopAndDestroy( sql );
    CleanupStack::PopAndDestroy( serverId );
    
    while ( iView.NextL() )
        {
        // get final result and append it to aArray
        iView.GetL();
        aArray.AppendL( iView.ColUint( 
                        iColSet->ColNo( KNSmlFwMgmtObjectId ) ) );
        }
    
    _DBG_FILE("CNSmlDmFotaAdapterDb::GetEmptyFinalResultsL( serverid ): end");
    }
void readFromStreamLX(QMimeData* aData,RReadStream& aStream)
{
    // This function both leaves and throws exceptions. There must be no destructor
    // dependencies between cleanup styles, and no cleanup stack dependencies on stacked objects.
    TCardinality mimeTypeCount;
    aStream >> mimeTypeCount;
    for (int i = 0; i< mimeTypeCount;i++)
    {
        // mime type
        TCardinality mimeTypeSize;
        aStream >> mimeTypeSize;
        HBufC* mimeTypeBuf = HBufC::NewLC(aStream,mimeTypeSize);
        QString mimeType = QString::fromUtf16(mimeTypeBuf->Des().Ptr(),mimeTypeBuf->Length());
        CleanupStack::PopAndDestroy(mimeTypeBuf);
        // mime data
        TCardinality dataSize;
        aStream >> dataSize;
        QByteArray ba;
        ba.reserve(dataSize);
        aStream.ReadL(reinterpret_cast<uchar*>(ba.data_ptr()->data),dataSize);
        ba.data_ptr()->size = dataSize;
        qDebug() << "paste from clipboard mime: " << mimeType << " data: " << ba;
        aData->setData(mimeType,ba);
    }
}
// -----------------------------------------------------------------------------
// CClientInstallerApplication::StartBrowser(URL)
// Start up a NETFRONT browser on a given URL
// -----------------------------------------------------------------------------
//
void CClientInstallerApplication::StartBrowser(const TDesC& aUrl)
	{
	HBufC* param = HBufC::NewLC( 256 );
	param->Des().Format( _L( "4 %S" ),&aUrl );

	const TInt KWmlBrowserUid = ${browser.UID};  // NETFRONT Browser 3.3

	TUid id( TUid::Uid( KWmlBrowserUid ) );

	TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
	TApaTask task = taskList.FindApp( id );
	if ( task.Exists() )
	{
	     HBufC8* param8 = HBufC8::NewLC( param->Length() );
	     param8->Des().Append( *param );
	     task.SendMessage( TUid::Uid( 0 ), *param8 ); // Uid is not used
	     CleanupStack::PopAndDestroy(); // param8
	}
	else
	{
	     RApaLsSession appArcSession;
	     User::LeaveIfError(appArcSession.Connect()); // connect to AppArc server
	     TThreadId id;
	     appArcSession.StartDocument( *param, TUid::Uid( KWmlBrowserUid ), id );
	     appArcSession.Close();
	}
	CleanupStack::PopAndDestroy(); // param
	}
// -----------------------------------------------------------------------------
// CUpnpUploadCommand::ExecuteL
// -----------------------------------------------------------------------------
// 
void CUpnpUploadCommand::ExecuteL()
	{
	//ASSERT(iType == EPutFile);
    
    HBufC8* uuid = NULL;
    HBufC8* dstPath = NULL;
    HBufC* srcPath = NULL;

   	DEBUGSTRING(("Execute Upload command"));
    	            
    uuid = ReadDes8FromMessageLC(0); 
    DEBUGSTRING8(("  uuid: %S",uuid));       
	srcPath = ReadDes16FromMessageLC(1);                     	
	DEBUGSTRING16(("  srcPath: %S",srcPath));   			
	dstPath = ReadDes8FromMessageLC(2); 
	DEBUGSTRING8(("  dstPath: %S",dstPath));   		

    // convert to 8-bit representation 
    iSrcPath = HBufC8::NewL(srcPath->Length()); 
    iSrcPath->Des().Copy(*srcPath);
                      
    iPathResolver = &(iAVCPManager.PathResolverL(*uuid, &iSession));
    	 
    iPathResolver->ResolveIdL(*dstPath, *this);
    
    CleanupStack::PopAndDestroy(dstPath);          
    CleanupStack::PopAndDestroy(srcPath);          
	CleanupStack::PopAndDestroy(uuid);          
	}
Example #11
0
void CCmdClipboard::DoRunL()
	{
	if (iString)
		{
		CopyToClipboardL(*iString);
		}
	else if (iPipe)
		{
		// Copy to clipboard from stdin
		CTextBuffer* buffer = CTextBuffer::NewLC(0x100);
		Stdin().SetReadMode(RIoReadHandle::EOneOrMore);
		TBuf<0x100> buf;
		while (Stdin().Read(buf) == KErrNone)
			{
			buffer->AppendL(buf);
			}

		CopyToClipboardL(buffer->Descriptor());
		CleanupStack::PopAndDestroy(buffer);
		}
	else
		{
		HBufC* res = NULL;
		TRAPD(err, res = GetFromClipboardL());
		LeaveIfErr(err, _L("Couldn't read clipboard (clipboard is empty?)"));

		TBool cons = Stdout().AttachedToConsole();
		if (cons) Printf(_L("Clipboard contents, length=%d:\r\n"), res->Length());
		Write(*res);
		if (cons) Write(_L("\r\n"));
		delete res;
		}
	}
Example #12
0
void CT_FIELD1::test1()
// Tests that all CTextFieldSet methods exist as specced
//
	{
	INFO_PRINTF1(_L("- Testing that all CTextFieldSet methods exist"));
	// inform TheFieldSet about an imaginary insertion, then an imaginary deletion
	TheFieldSet->NotifyInsertion(0,10); // pos=0, len=10
	TheFieldSet->NotifyDeletion(2,5); // pos=2, len=5
	// insert a field & get its initial value
	CTextField* field = TheFieldSet->NewFieldL(KDummyFieldUid);
	TInt ret = TheFieldSet->InsertFieldL(1,field,KDummyFieldUid); // pos=1
		test(ret==KErrNone);
	HBufC* buf = HBufC::NewLC(20); // max length 20
	TheFieldSet->NewFieldValueL(buf,1); // pos=1
	CleanupStack::Pop();
	CleanupStack::PushL(buf);
	TheFieldSet->NotifyFieldUpdate(1,buf->Length());
	CleanupStack::PopAndDestroy(); // buf
	// count number of fields & characters
	TheFieldSet->FieldCount();
	TheFieldSet->CharCount();
	// find the inserted field
	TheFieldSet->FindFields(0); // pos=0
	TFindFieldInfo info;
	TheFieldSet->FindFields(info,0,3); // pos=0, range=3
	// remove the field
	TheFieldSet->RemoveField(2);
	// reset the field array
	TheFieldSet->Reset();
	}
EXPORT_C TBool AknPhoneNumberTextUtils::WrapPhoneNumberToArrayL( 
    const TDesC& aPhoneNumberToWrap,
    TInt aLineWidthInPixels,
    TInt aMaxLines,
    const CFont& aFont,
    CArrayFix<TPtrC>& aWrappedArray )
    {
    TBool retVal( EFalse ); // Not truncated
 
    HBufC* reversedText = aPhoneNumberToWrap.AllocLC();
    TPtr revPtr = reversedText->Des();

    ReverseDescriptor( revPtr );

    CArrayFix<TInt>* lineWidthArray = new (ELeave) CArrayFixFlat<TInt>(KLineArrayGranularity);
    CleanupStack::PushL( lineWidthArray );

    lineWidthArray->AppendL( aLineWidthInPixels, aMaxLines );

    // Perform the wrap on the reversed text
    AknTextUtils::WrapToArrayL( revPtr, *lineWidthArray, aFont, aWrappedArray );

    // Now rearrange the TPtrCs to point to the original array
    TInt totalLen = reversedText->Length();
    TInt count = aWrappedArray.Count();
    TInt usedLen = 0; // Accumulates the length actually used
    for ( TInt index = 0; index < count; index++)
        {
        TPtrC& currentPtr = aWrappedArray.At(index);
        // The TPtrCs have to be moved. The reversing is taken into effect, but not purely reversed
        // because their otherwise they would have negative lengths.  That is, {a,b} does not go to
        // { final - a, final - b }, but rather to {final - b, final - a}; they are flipped, to get
        // their start points before the end points
        //
        // Now, representing the start position by pos, and the end by pos+len-1 we have the TPtrC at
        // {pos, pos+len-1} inclusive, in reversed array. 
        // The TPtrC must be modified to point to {total_len-1 - (pos+len-1), total_len-1 - pos} 
        // in the unreversed array:
        TInt len = currentPtr.Length();
        usedLen += len;
        TInt pos = currentPtr.Ptr() - reversedText->Ptr(); // pointer arithmetic
        TInt newPos = totalLen - pos - len;
        // If the TPtr is zero length then it must get special treatment, as the normal
        // calculations give an end point before the start point! i.e. {pos, pos-1}
        // We handle this by NOT flipping in this case.
        // { pos, pos-1 } -> {totalLen-1-pos, totalLen-1 - (pos-1)}
        // Note that a zero length wrapped line is completely possible amoung a bunch of other 
        // lines with characters on them, as the line lengths may be of wildly different lengths.
        if ( len == 0 ) 
            newPos--;
        currentPtr.Set( aPhoneNumberToWrap.Mid(newPos, len) );
        }

    // If the accumulated length is less than that in the entire input descriptor, then text does not fit
    if ( usedLen < totalLen )
        retVal = ETrue;

    CleanupStack::PopAndDestroy(2); // lineWidthArray first, and then reversedText
    return retVal;
    }
Example #14
0
void CMainMenuListContainer::AddItemL(TInt aBitmapId, TInt aMaskId,
                                      TInt aFirstLabelId, TInt aSecondLabelId)
{
    CArrayPtr<CGulIcon>* icons =
        iListBox->ItemDrawer()->FormattedCellData()->IconArray();
    if (!icons) {
        icons = new ( ELeave ) CAknIconArray(3);
        iListBox->ItemDrawer()->FormattedCellData()->SetIconArrayL(icons);
    }
    CleanupStack::PushL(icons);

    CFbsBitmap* bitmap;
    CFbsBitmap* mask;

    AknIconUtils::CreateIconL(bitmap, mask, iView->GetMbmName(),
                              aBitmapId, aMaskId);

    CleanupStack::PushL(bitmap);
    CleanupStack::PushL(mask);

    icons->AppendL(CGulIcon::NewL(bitmap, mask));

    CleanupStack::Pop(mask);
    CleanupStack::Pop(bitmap);
    CleanupStack::Pop(icons);

    HBufC* firstLabel = CEikonEnv::Static()->AllocReadResourceLC(aFirstLabelId);
    HBufC* secondLabel = CEikonEnv::Static()->AllocReadResourceLC(aSecondLabelId);

    HBufC* itemText = HBufC::NewLC(firstLabel->Length() +
                                   secondLabel->Length() + 16);

    itemText->Des().Format(KItem(), (icons->Count() - 1), firstLabel, secondLabel);

    CDesCArray* itemArray =
        static_cast<CDesC16ArrayFlat*>(iListBox->Model()->ItemTextArray());

    itemArray->AppendL(*itemText);

    CleanupStack::PopAndDestroy(itemText);
    CleanupStack::PopAndDestroy(secondLabel);
    CleanupStack::PopAndDestroy(firstLabel);

    iListBox->HandleItemAdditionL();
}
HBufC* TestUniDataModelVCalPlugin::ReadFromFileL(const TDesC& aFile)
{
		RFile file;
		TBuf8<1024> lineBuffer;
		TInt err = KErrNone;

		err = file.Open(iFs, aFile, EFileStreamText | EFileRead | EFileShareAny);

		if (err != KErrNone) // Didn't find the file, so leave - should only get valid filenames!
			{
				User::Leave(KErrNotFound);
			}

		HBufC* bioBuf = HBufC::NewLC(65535); // Create a new descriptor on the heap.
		HBufC* copyBuffer = HBufC::NewLC(1024);

		do // Read in the text from file, and also check if there is a name field:
			{
				err = file.Read(lineBuffer);// Read upto 256 chars, '\n' and all...
				//err = ReadLineL(file,lineBuffer);
				if (err == KErrNone) // Made a valid read,
					if (lineBuffer.Length() == 0) // but read 0 chars
                err = KErrEof; // so set err value to end processing

				if (err == KErrNone)
					{	
						copyBuffer->Des().Copy(lineBuffer);// Copy, and overwrite existing text
						if ( (bioBuf->Length() + copyBuffer->Length())
								> bioBuf->Des().MaxLength())
							{
								bioBuf = bioBuf->ReAllocL(bioBuf->Length()
										+ copyBuffer->Length());
							}
						bioBuf->Des().Append(*copyBuffer);
						//bioBuf->Des().Append(_L("\n"));
					}
    }while (err != KErrEof);

    CleanupStack::PopAndDestroy(); // Destroy the copyBuffer.
    CleanupStack::Pop();// Remove the bioBuf.

    file.Close();
    return bioBuf;
}
TBool
LaunchWapBrowserUtil::LaunchWapBrowser(const TDesC& aUrl)
{
#if defined NAV2_CLIENT_SERIES60_V2 || defined NAV2_CLIENT_SERIES60_V3
   TInt urlLen = aUrl.Length();
   HBufC* fixedUrl;

   if (KFourHttpString().Compare(aUrl.Left(KFourHttpString().Length()))) {
      /* Not 4 http:// at the beginning. */

      if (KHttpString().Compare(aUrl.Left(KHttpString().Length()))) {
         /* Not http:// at the beginning. */
         urlLen += KFourHttpString().Length() + 1;
         fixedUrl = HBufC::NewLC(urlLen);
         fixedUrl->Des().Copy(KFourHttpString);
      } else {
         urlLen += KFourString().Length() + 1;
         fixedUrl = HBufC::NewLC(urlLen);
         fixedUrl->Des().Copy(KFourString);
      }
      fixedUrl->Des().Append(aUrl);
   } else {
      fixedUrl = aUrl.AllocLC();
   }

   RApaLsSession aApaLsSession;

   TUid id( KPhoneUidWmlBrowser );
   TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
   TApaTask task = taskList.FindApp( id );

   if ( task.Exists() ) {
      HBufC8* param8 = HBufC8::NewLC( fixedUrl->Length() );
      param8->Des().Append( *fixedUrl );
      task.SendMessage( TUid::Uid( 0 ), *param8 ); // UID is not used
      CleanupStack::PopAndDestroy( param8 );
   } else {
      if ( !aApaLsSession.Handle() )
      {
         User::LeaveIfError( aApaLsSession.Connect() );
      }
      TThreadId thread;
      User::LeaveIfError( aApaLsSession.StartDocument( *fixedUrl,
               KPhoneUidWmlBrowser, thread ) );
   }
   CleanupStack::PopAndDestroy(fixedUrl);

   aApaLsSession.Close();

#elif defined NAV2_CLIENT_SERIES60_V1
   return EFalse;
#else
# error This code not implemented!
#endif
   return ETrue;
}
Example #17
0
QString QNFCNdefUtility::TDesC82QStringL(const TDesC8& aDescriptor)
    {
    HBufC* newBuf = NULL;
    QT_TRAP_THROWING(newBuf = HBufC::NewL(aDescriptor.Length()));
    TPtr des = newBuf->Des();
    des.Copy(aDescriptor);
    QString ret = QString::fromUtf16(newBuf->Ptr(),newBuf->Length());
    delete newBuf;
    return ret;
    }
EXPORT_C HBufC* CResourceLoader::Load2L( TInt aResourceId, const TDesC& aString )
    {
    HBufC* resbuf = Load2LC( aResourceId );
    TPtr retptr(resbuf->Des());
        
    // Get number of sub strings
    TInt count = GetSubStringCount( retptr ); 
    TBool marker(EFalse); 
    
    if (count >= 1)
        {
        HBufC* buffer = ResolveSubStringDirsL( retptr, count, &marker );
        CleanupStack::PushL(buffer);
        
        TBool found(EFalse);
        TBidiText::TDirectionality mainDir = DirectionalityL(*buffer , &found);
        
        //Formating the return string with FormatStringL.
        HBufC* retbuf = FormatStringL(*buffer, KStringKeyBuf, aString, mainDir);
        
        CleanupStack::PopAndDestroy(buffer);
        CleanupStack::PopAndDestroy(resbuf);
                        
        if (marker && retbuf->Length())
            {
            TPtr ptr = retbuf->Des();
            RemoveNoDirMarkers(ptr);
            } 
            
        __ASSERT_DEBUG(retbuf->Length(), 
                    User::Panic(KPanicCategory, EKeyStringNotFound));    
        return retbuf;
        }
     else
        {
        CleanupStack::PopAndDestroy(resbuf);
        HBufC* retbuf = HBufC::NewL(0); // return empty buffer
        __ASSERT_DEBUG(retbuf->Length(), 
                    User::Panic(KPanicCategory, EKeyStringNotFound));
        return retbuf;
        }
    }
Example #19
0
HBufC* CAknIconArray::GetBmpNameLC(TResourceReader& aReader)
    {
    HBufC* bmpName = aReader.ReadHBufCL();
    CleanupStack::PushL(bmpName);

    TBool drivePresent =
        (bmpName->Length() >= 3 &&
        (*bmpName)[1] == ':' &&
        (*bmpName)[2] == '\\' );

    RFs& fs = CCoeEnv::Static()->FsSession();

    TBool found = EFalse;
    if ( drivePresent )
        {
        found = BaflUtils::FileExists( fs, *bmpName );
        }

    // If drive letter is not specified, or not found in the specified drive,
    // FindByDir scans the drives in order E:, D:, C:, Z:

    if (!found)
        {
        TFindFile find( fs );
        if (find.FindByDir(*bmpName, KNullDesC) == KErrNone)
            {
            if (bmpName->Length() < find.File().Length())
                {
                bmpName = bmpName->ReAllocL(find.File().Length());
                CleanupStack::Pop(); // old bmpName
                CleanupStack::PushL( bmpName );
                }
    
            *bmpName = find.File();
            }
        }

    return bmpName;
    }
// ---------------------------------------------------------------------------
// Create an array representing the table that is generated
// ---------------------------------------------------------------------------
//     
RPointerArray<CMPXHarvesterDbItem>* CMPXHarvesterDatabaseTable::CreateTableRepresentationL()
    {
    MPX_DEBUG1("CMPXHarvesterDatabaseTable::CreateTableRepresentationL <---");
    
    RPointerArray<CMPXHarvesterDbItem>* array = 
                              new (ELeave) RPointerArray<CMPXHarvesterDbItem>;
    CleanupStack::PushL( TCleanupItem( CleanupArray, array) );
    
    for (iView.FirstL();iView.AtRow();iView.NextL())
        {
        // Retrieve the row
        iView.GetL();
        
        CMPXHarvesterDbItem* item = new(ELeave) CMPXHarvesterDbItem();
        CleanupStack::PushL( item );
        
        // Setup the item
        HBufC* filepath = ReadLongTextLC( KHarPathNameColumn );
        HBufC* songname = ReadLongTextLC( KHarFileNameColumn );
        item->iFile = HBufC::NewL( filepath->Length() + songname->Length() );
        TPtr buf = item->iFile->Des();
        buf.Append( *filepath );
        buf.Append( *songname );
        CleanupStack::PopAndDestroy( 2, filepath );
        
        item->iLastModifiedTime = iView.ColTime( KHarModTimeColumn );
        item->iColId = iView.ColInt( KHarColDBIDColumn );
        item->iDrm   = iView.ColUint( KHarDRMColumn );
        
        User::LeaveIfError( array->InsertInOrderAllowRepeats( item, 
                            CMPXHarvesterDbItem::Compare ) );
        CleanupStack::Pop( item );
        }
  
    CleanupStack::Pop();  // cleanup
    MPX_DEBUG1("CMPXHarvesterDatabaseTable::CreateTableRepresentationL --->");
    return array;
    }
// -----------------------------------------------------------------------------
// CTestSDKQueries::TestPhoneValueL
// -----------------------------------------------------------------------------
//
TInt CTestSDKQueries::TestPhoneValueL( CStifItemParser& /*aItem*/ )
    {
    CAknQueryValuePhone* valuePhone = CAknQueryValuePhone::NewLC();
    STIF_ASSERT_NOT_NULL( valuePhone );
    
    HBufC* value = valuePhone->Value();
    CleanupStack::PushL( value );
    STIF_ASSERT_TRUE( value->Length() == 0 );
    
    CleanupStack::Pop( value );
    CleanupStack::PopAndDestroy( valuePhone );
    
    return KErrNone;
    }
// ---------------------------------------------------------------------------
//  CNSmlDmFotaAdapterDb::SetLongStrValueL()
//  Streams aValue and its length as the value of aColumn in FW object 
//  identified by aObject.
// ---------------------------------------------------------------------------
// 
TInt CNSmlDmFotaAdapterDb::SetLongStrValueL( const TDesC& aColumn, 
                                             const TDesC8& aValue, 
                                             const TNSmlDmFwObjectId aObject )
    {
    _DBG_FILE("CNSmlDmFotaAdapterDb::SetLongStrValueL(): begin");
    
    HBufC* value = ConvertTo16BitLC( aValue );
    
    DBG_ARGS( _S16("CNSmlDmFotaAdapterDb::SetStrValueL(): ('%S', '%S', %d)"),
              &aColumn, value, aObject );
    
    TInt ret = UpdateRowL( aObject );
    
    if ( ret == KErrNone )
        {
        // do update
        
        RDbColWriteStream wStream;
        wStream.OpenL( iView, iColSet->ColNo( aColumn ) );
        CleanupClosePushL( wStream );
        
        wStream.WriteInt32L( value->Length() );
        wStream.WriteL( *value, value->Length() );
        
        CleanupStack::PopAndDestroy( &wStream );
        
        iView.PutL();
        }
    
    CommitAndCompact();
    
    CleanupStack::PopAndDestroy( value );
    
    _DBG_FILE("CNSmlDmFotaAdapterDb::SetLongStrValueL(): end");
    
    return ret;
    }
// ----------------------------------------------------------------------------
// UntrustedCertificateInfoSymbian::CommonNameMatchesL()
// ----------------------------------------------------------------------------
//
bool UntrustedCertificateInfoSymbian::CommonNameMatchesL(const QString &siteName) const
{
    bool matches = false;
    const CX500DistinguishedName& distinguishedName = mCert->SubjectName();
    HBufC* commonNameSymbian = distinguishedName.ExtractFieldL( KX520CommonName );
    if (commonNameSymbian) {
        CleanupStack::PushL(commonNameSymbian);
        QString commonName = QString::fromRawData(
            reinterpret_cast<const QChar*>(commonNameSymbian->Ptr()),
            commonNameSymbian->Length());
        matches = ( commonName == siteName );       // TODO: accept '*' chars in commonName?
        CleanupStack::PopAndDestroy(commonNameSymbian);
    }
    return matches;
}
// ---------------------------------------------------------------------------
// Get full path wildcard for files residing in a directory
// with given index
// ---------------------------------------------------------------------------
//
HBufC* CXIMPTestFileTool::GetWildcardLC( 
        const TDesC& aDirTemplate )
    {
    HBufC* dirName = GetDirNameAndBackslashLC( aDirTemplate );
    HBufC* wildcard = HBufC::NewLC(
            dirName->Length() + KFileToolWildcard().Length() );
    wildcard->Des().Append( *dirName );
    wildcard->Des().Append( KFileToolWildcard );

    CleanupStack::Pop( 2 ); // wildcard, dirName
    delete dirName;

    CleanupStack::PushL( wildcard );
    return wildcard;
    }
/**
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);
	}
void PosLmUnzipUtil::ExtractFileL(RFs& aFs, CZipFileMember* aMember, CZipFile* aZipFile, TFileName* aFileName) 
{
	TInt loop=0;
	HBufC* name = aMember->Name()->AllocLC();
	// Change any instances of '/' to '\' in zipped file paths
	while (loop < name->Length()) 
	{
		if ((*name)[loop] == '/') 
		{
			name->Des()[loop] = '\\';
		}
		loop++;
	}
	//set target path
	TBuf<KMaxDirName> privatePath;
	aFs.PrivatePath(privatePath);
	TFileName fn;
	fn.Append(privatePath);
	fn.Append(KExtractZipPath);
	fn.Append(*name);
	
	//create target path if not exist.
	TInt err = aFs.MkDirAll(fn);
	if (err != KErrNone && err != KErrAlreadyExists) 
	{
		User::Leave(err);
	}
	RFile expandedMember;
	User::LeaveIfError(expandedMember.Replace(aFs, fn, EFileShareAny|EFileWrite));
	CleanupClosePushL(expandedMember);
	RZipFileMemberReaderStream* fileStream; 
	
	// KCompressionMethodNotSupported is possible in decompressing file here
	User::LeaveIfError(aZipFile->GetInputStreamL(aMember, fileStream));
	CleanupStack::PushL(fileStream); 
	
	// Assume file contents are 8-bit data
	TUint32 size = aMember->UncompressedSize();
	HBufC8* bytes = HBufC8::NewLC(size);
	TPtr8 ptr = bytes->Des(); //Obtain a modifiable descriptor
	fileStream->Read(ptr, size); 
	// save the unzipped contents to file
	User::LeaveIfError(expandedMember.Write(ptr));
	expandedMember.Close();
	CleanupStack::PopAndDestroy(4); //bytes, fileStream, expandedMember, name
}
Example #27
0
TBool CT_FIELD1::UpdateField(TInt aPos)
	{
	// find out which field aPos is in
	TFindFieldInfo info;
	TBool inField=TheFieldSet->FindFields(info,aPos);
		test(inField);
	// get the new value
	HBufC* buf = HBufC::NewLC(5); 
 	TInt ret=TheFieldSet->NewFieldValueL(buf,aPos); 
	CleanupStack::Pop();
	CleanupStack::PushL(buf);
		test(ret==KErrNone);
	// Notify FieldSet of update
	TheFieldSet->NotifyFieldUpdate(aPos,buf->Length());
	// tidy up
	CleanupStack::PopAndDestroy();
	return ret;
	}
QString UsbUiSettingModel::getFriendlyName(RUsb &usbman, TInt personalityId)
{
    myDebug() << ">>> UsbUiSettingModel::getFriendlyName";
    QString friendlyName;
    HBufC* description = NULL;
    TInt err = usbman.GetDescription(personalityId, description);
    if (err == KErrNone) {
        friendlyName = QString::fromUtf16(description->Ptr(), description->Length());
        friendlyName.replace( QChar(' '), QChar('_') );
        delete description;
    } else {
        myDebug() << "    UsbUiSettingModel::getFriendlyName RUsb error "
            << err;    
    }
    myDebug() << "    UsbUiSettingModel::getFriendlyName friendlyName=" << friendlyName;
    myDebug() << "<<< UsbUiSettingModel::getFriendlyName";
    return friendlyName;
}
/**
 * This function sets up a console, a log file and checks
 * whether we need to wait for a key pressed after test 
 * completion.
 * First DoThreadedTestsL is called, if everything is ok
 * it return ETrue and we move on to the standard tests.
 * If something went amiss (return EFalse) we skip 
 * the standard test and return. 
 */
LOCAL_D void SetupAndRunTests() 
{

	CConsoleBase* console = Console::NewL(_L("Test code"), TSize(KConsFullScreen, KConsFullScreen));
	
	HBufC* logFile = GetArgument(1);
	
	if (logFile->Length()==0) 
		{
		_LIT(defaultLog, "\\tcertstore.log");
		TDriveUnit sysDrive (RFs::GetSystemDrive());
		TDriveName sysdriveName (sysDrive.Name());
		TBuf <18> fileName (sysdriveName);
		fileName.Append(defaultLog);
		logFile->ReAlloc(18);
		TPtr16 plog = logFile->Des();
		plog.Append(fileName);
		}
		
	HBufC* wait = GetArgument(2);

	TBool waitAfterCompletion = EFalse;
	if (wait->Find(_L("-w")) != KErrNotFound) 
		{
		waitAfterCompletion = ETrue;
		}
	
	TBool res = EFalse;	
	TRAPD(err, res = DoThreadedTestsL(console, logFile, waitAfterCompletion));
	
	if (res) 
		{
		// Now run a normal tcertstore test to check store integrity
		TRAP(err, DoTests());
		}
		
	delete console;
	delete wait;
	delete logFile;
}
void CDesktopHotKeyAppUi::About()
	{
	TFileName filename;
	GetAppPath(filename);
	HBufC* textResource = StringLoader::LoadLC(R_ABOUT_FILE);
	filename.Append(textResource->Des());
	CleanupStack::PopAndDestroy(textResource);

	RFile file;
	TInt nErr = file.Open(CEikonEnv::Static()->FsSession(), filename, EFileRead
			| EFileShareAny);
	if (nErr != KErrNone)
		return;

	TFileText fileText;
	fileText.Set(file);
	TBuf<128> linePtr;
	HBufC* iText = NULL;

	while (fileText.Read(linePtr) == KErrNone)
		{
		if (iText!=NULL)
			{
			iText = iText->ReAllocL(iText->Length() + linePtr.Length() + 2);
			iText->Des().Append(linePtr);
			}
		else
			{
			iText = HBufC::NewL(linePtr.Length() + 2);
			iText->Des().Append(linePtr);
			}
		iText->Des().Append(CEditableText::ELineBreak);
		}
	file.Close();

	ShowModalAboutDlgL(R_ABOUT_DIALOG_TITLE,iText->Des());
	
	
	delete iText;
	}