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
	}
void CDbCreator::ParseCommandLineLC( CCommandLineArguments* aArgs,
                                     TFileName& aFileName,   
                                     TBool& aExt,
                                     TBool& aDump )
    {
    TPtrC arg;

    if ( aArgs->Count() > 1 )
        {

        for ( TInt i = 1; i < aArgs->Count(); i++ )
            {
            arg.Set( aArgs->Arg( i ) );
            
            if( arg.Size() > 0 )
                {
                switch( arg[0] )
                    {
                    case 'd':
                    case 'D'://fall-through 
                        // D means "dump" needed
                        aDump = ETrue;
                        break;
                    case 'f':
                    case 'F'://fall-through 
                        {
                        _LIT( KHeader,  "f:" );
                        if ( 0 == arg.FindF( KHeader ) )
                            {
                            //f: must be in the head position of file location
                            aFileName.Copy( arg.Right( arg.Length() - KFParamLength ) );
                            }
                        else
                            {
                            User::Leave( KErrInvalidParameter );    
                            }
                        
                        break;
                        }
                    // Only the CommsDat will be extended
                    case 'E':
                    case 'e'://fall-through 
                        {    
                        aExt = ETrue;    
                        break;
                        }
                    default:
                        {
                        User::Leave( KErrInvalidParameter );
                        }
                    }//swich
                }//if
            }//for
        }//if

    }         
TInt CCmdConnect::ProcessL( const TDesC& aCommand )
{
	// Complete the test machine - will then get the next cmd
	Machine()->CompleteRequest();

	TPtrC framework;
	TPtrC conname;

	TInt error;
	if (( error = ParseCmdArgs( aCommand, framework, conname )) != KErrNone)
		return error;
	
	if (conname.Size() != 0)
		{		
		//	Check if the connection already is defined. 
		//	If it is return error, if not create a session and ptr!
		CAnyObject *cnx = (CAnyObject *)Machine()->Domains()->Name(conname);
	
		if (cnx != NULL)		//	already exists
			return Error(KErrAlreadyExists, THA_KErrCnxionExists, &conname);
		else
			{
			CFrmwrkSession *cithc = CFrmwrkSession::NewLC(conname, framework, Machine());
			cithc->iEventDispatcher = iEventDispatcher ;

			TRAPD(error, cithc->OpenL());
			if (error == KErrNone)
				{
				cithc->SetPropertiesL();
			
				TRAP(error, cithc->ConnectL());
				
				if (error == KErrNone)
					{
					//	now create reference to name in domains
					//	note: the value is 1 for HTTP and 0 for WSP
					Machine()->Domains()->AddL(conname, 0, THA_KHTTP_Connect, (TAny *) cithc);
					WriteDateStamp();
					Log(_L("Connection '%S' has been opened!"), &conname);
					}
				else
					Error(error, KTxtErrConnectFailed);
				}
			
			CleanupStack::Pop();	// cithc
			}
		}
	else
		{		
		(void) ShowSessions () ;
		}

	return error;
}
Exemple #4
0
// -----------------------------------------------------------------------------
// Cosmo4AppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void COsmo4AppUi::ConstructL()
{
    // Initialise app UI with standard value.
    BaseConstructL(CAknAppUi::EAknEnableSkin);

    /*Create display*/
    iAppView = COsmo4AppView::NewL( ClientRect() );
	AddToStackL(iAppView);

	/*create playlist*/
#ifndef GPAC_GUI_ONLY
	iPlaylist = CPlaylist::NewL( ClientRect(), iAppView->GetUser() );

	iPlaylist->MakeVisible(EFalse);
#endif
	
	iAppView->MakeVisible(ETrue);
	view_mode = 0;

	m_title = NULL;

	//StatusPane ()->SwitchLayoutL ( R_AVKON_STATUS_PANE_LAYOUT_SMALL );

	nb_keys = 0;
	CaptureKeys(1);



	CCommandLineArguments *args = CCommandLineArguments::NewL();
#ifndef GPAC_GUI_ONLY
	if (args->Count() > 1) {
		TPtrC url = args->Arg(1);
#if defined(_UNICODE)
		char szURL[1024];
		u16 szURLUTF16[1024];
		size_t len;
		len = url.Size();
		memcpy(szURLUTF16, url.Ptr(), sizeof(u8)*len);
		szURLUTF16[len/2] = 0;
		const u16 *sptr = szURLUTF16;
		len = gf_utf8_wcstombs(szURL, 512, &sptr);
		if (len != (size_t) -1) {
			szURL[len] = 0;
			iAppView->Connect((const char *)szURL);
		}
#else
		iAppView->Connect((const char *)url.Ptr());
#endif
	}
#endif
	delete args;
}
TInt CIniData::StepToNextBlock()
/**
Locates the next available block of data within a section

@return ETrue if successful or EFalse
*/
	{
	if (BlockState != E_UNKNOWN)
		{
		// get unscanned portion of the section
		TPtrC temp = section.Mid(scanStart);

		// find the start of the next block
		if (BlockState == E_SET)
			{
			blockStart = temp.FindF(TPtrC(BEGIN_SET));
			blockEnd = temp.FindF(TPtrC(END_SET));
			}
		else if (BlockState == E_TEMPLATE)
			{
			blockStart = temp.FindF(TPtrC(BEGIN_TEMPLATE));
			blockEnd = temp.FindF(TPtrC(END_TEMPLATE));
			}
		else if (BlockState == E_ADD)
			{
			blockStart = temp.FindF(TPtrC(BEGIN_ADD));
			blockEnd = temp.FindF(TPtrC(END_ADD));
			}

		if (blockStart != KErrNotFound && blockEnd != KErrNotFound)
			{
			// set the start point for the next block search
			scanStart += blockEnd;
			scanStart++;

			// set the actual block to work with
			blockEnd -= blockStart;
			TPtrC tempBlock = temp.Mid(blockStart,blockEnd);
			block.Set((unsigned short *)tempBlock.Ptr(), tempBlock.Length(), tempBlock.Size());
			return ETrue;
			}
		}

	return EFalse;
	}
TInt CCmdTransaction::ProcessL(const TDesC& aCommand)
	{

	// Complete the test machine - will then get the next cmd
	Machine()->CompleteRequest();

	TPtrC transname;
	TPtrC conname;
	TPtrC transmthd;
	TPtrC transURI;
	TPtrC postData;

	TInt error;
	// ParseCmdArgs indirectly sets eStrIndex
	
	if (( error = ParseCmdArgs( aCommand, 
							    transname, 
								conname, 
								transmthd, 
								transURI, 
								postData)) != KErrNone)
		return error;

	if (conname.Size() == 0)
		{
		(void) ShowTransactions () ;
		return error;
		}

	//	Get the session object we need
	//	If it is return error, if not create a session and ptr!

	CAnyObject *cnx = (CAnyObject *)Machine()->Domains()->Name(conname);
	
	if (cnx == NULL)//	does not already exists
		return Error(KErrArgument, THA_KErrInvalidConnect, &conname);
	else
		{
		//	reset the received status 
		iReceivedError = -1;

		CFrmwrkSession *myConnection = (CFrmwrkSession *) cnx->Ptr();
		// TPtrC myName = myConnection->Name() ;
		
		RHTTPSession mySession = myConnection->Session();
	
		CTestTransaction *transaction = NULL;

		TRAPD(err, transaction = CTestTransaction::NewL( mySession,
														 eStrIndex, 
		                                                 transURI, 
		                                                 postData, 
		                                                 transname,
		                                                 Machine()));
		if (err != KErrNone) 
			{
			Log(_L("Failed to create Transaction %S"), &transname);
			return err;
			}
		else
			{
			Log(_L("Transaction %S created successfully"), &transname);
			}

		TRAP ( err, transaction->SubmitL());

		if (err != KErrNone) 
			{
			Log(_L("Transaction %S,  Submission failed"), &transname);
			return err;
			}
		else
			{
			Log(_L("Transaction %S,  Submission succeeded"), &transname);
			}


		Machine()->Domains()->AddL(transname, eStrIndex, THA_KHTTP_Transaction, (TAny *) transaction);
		}

	if (error != KErrNone)
		Log(TFR_KFmtErrFailed, &Keyphrase(), error);

	return error;
}
TInt COpenMAXALTestModule::al_metadataextractionitf_GetValue( CStifItemParser& aItem )
{
    iLog->Log( _L("al_metadataextractionitf_GetValue >>") );
    
    TInt status(KErrNotFound);
    XAresult res;
    
    XAMetadataInfo *key = NULL;
    
    if(m_MetadataExtractionItf)
    {
        TInt index;
        
        //Find Key Index
        TPtrC keyToFind;
        if(aItem.GetNextString(keyToFind) == KErrNone)
        {
            HBufC *pB = HBufC16::NewL(keyToFind.Size());
            TPtr tP = pB->Des();
            tP.Copy(keyToFind);
            iLog->Log( _L("Expected Key: %S"), pB);
            delete pB;
            
            XAuint32 numItems = 0;
            res = (*m_MetadataExtractionItf)->GetItemCount(m_MetadataExtractionItf, &numItems);              
    
            for(index = 0; (index < numItems) && (MapErr(res) == KErrNone) && (status == KErrNotFound); index++)
            {
                XAuint32 keySize = 0;
                res = (*m_MetadataExtractionItf)->GetKeySize(
                       m_MetadataExtractionItf, index, &keySize);  
          
                if(MapErr(res) == KErrNone)
                {
                    key = (XAMetadataInfo *)calloc(keySize,1);
                    if(key)
                    {
                        res = (*m_MetadataExtractionItf)->GetKey(
                                        m_MetadataExtractionItf, index , keySize, key);              
                        status = MapErr(res);
                        if(status==KErrNone)
                        {
                            HBufC*   temp  = NULL;
                            TDesC16* pdesc = NULL;
                                    
                            if(key->encoding == XA_CHARACTERENCODING_ASCII)
                            {
                                TPtrC8 des((TUint8*)(key->data), key->size - 1 );
                                temp = HBufC16::NewL(key->size - 1);
                                TPtr tempPtr = temp->Des();
                                tempPtr.Copy(des);                        
                                iLog->Log( _L("Key[%d]: %S"), index, temp);
                                pdesc = &tempPtr;
                            }
                            else if(key->encoding == XA_CHARACTERENCODING_UTF16LE)
                            {
                                TPtrC des((const TUint16*)key->data, key->size/2 - 1);
                                temp = HBufC16::NewL(key->size/2 - 1);
                                TPtr tempPtr = temp->Des();
                                tempPtr.Copy(des);                        
                                iLog->Log( _L("Key[%d]: %S"), index, temp);
                                pdesc = &tempPtr;
                            }
                                        
                            if(!keyToFind.Compare(*pdesc))
                            {
                                status = KErrNone;
                            }
                            else
                            {
                                status = KErrNotFound;
                            }
                            
                            if(temp)
                            {
                                delete temp;
                            }
                        }//end if(status==KErrNone)
                            
                        free(key);
                    }//end if(key)
                }//end if(MapErr(res) == KErrNone)
            }//end for
        }//end if(aItem.GetNextString(index) == KErrNone)
            
        if((status == KErrNone) && (--index >= 0))
        {
            XAMetadataInfo *value = NULL;
            XAuint32 valueSize;
        
            res = (*m_MetadataExtractionItf)->GetValueSize(
                                   m_MetadataExtractionItf, index, &valueSize);  
                
            if(MapErr(res) == KErrNone)
            {
                value = (XAMetadataInfo *)calloc(valueSize,1);
                if(value)
                {
                    res = (*m_MetadataExtractionItf)->GetValue(
                            m_MetadataExtractionItf, index, valueSize, value);              
                    status = MapErr(res);

                    HBufC*   temp  = NULL;
                    if(status == KErrNone)
                    {
                        if(value->encoding == XA_CHARACTERENCODING_ASCII)
                        {
                            TPtrC8 des((TUint8*)(value->data), value->size - 1 );
                            temp = HBufC16::NewL(value->size - 1);
                            TPtr tempPtr = temp->Des();
                            tempPtr.Copy(des);
                            iLog->Log( _L("Value[%d]: %S"), index, temp);
                        }
                        else if(value->encoding == XA_CHARACTERENCODING_UTF16LE)
                        {
                            TPtrC des((const TUint16*)value->data, value->size/2 - 1);
                            temp = HBufC16::NewL(value->size/2 - 1);
                            TPtr tempPtr = temp->Des();
                            tempPtr.Copy(des);
                            iLog->Log( _L("Value[%d]: %S"), index, temp);
                       }
                        else
                        {
                            iLog->Log( _L("Value[%d]: <Binary Value>"), index);
                        }					

                        if(value->encoding != XA_CHARACTERENCODING_BINARY)
                        {            
                            TPtrC expectedValue;
                            if(aItem.GetNextString(expectedValue) == KErrNone)
                            {            
                                HBufC *pB = HBufC16::NewL(expectedValue.Size());
                                TPtr tP = pB->Des();
                                tP.Copy(expectedValue);
                                iLog->Log( _L("Expected Value: %S"), pB);
								iLog->Log(_L("Size: Expected(%d), Actual(%d)"),expectedValue.Size(), temp->Des().Size());
                                delete pB;
                                if(temp && !expectedValue.Compare(temp->Des()))
                                {
                                    status = KErrNone;
                                }
                                else
                                {
                                    status = KErrNotFound;
                                }
                            }
                        }
                               
                        if(temp)
                        {
                            delete temp;
                        }
                    }//end if(status == KErrNone)
                    delete value;
                }//end if(value)
            }//end if(MapErr(res) == KErrNone)
        }//end if(status == KErrNone)   
    }//end   if(m_MetadataExtractionItf)
	
    iLog->Log( _L("al_metadataextractionitf_GetValue (%d)<<"), status );
    return status;
}
TInt COpenMAXALTestModule::al_metadataextractionitf_GetKey( CStifItemParser& aItem )
{
    iLog->Log( _L("al_metadataextractionitf_GetKey >>") );
    
    TInt status(KErrNotFound);
    XAresult res;
    XAMetadataInfo *key = NULL;
    
    if(m_MetadataExtractionItf)
    {
        TPtrC keyToFind;
        if(aItem.GetNextString(keyToFind) == KErrNone)
        {
            HBufC *pB = HBufC16::NewL(keyToFind.Size());
            TPtr tP = pB->Des();
            tP.Copy(keyToFind);
            iLog->Log( _L("Expected Key: %S"), pB);
            delete pB;
  		
            XAuint32 numItems = 0;
            res = (*m_MetadataExtractionItf)->GetItemCount(m_MetadataExtractionItf, &numItems);              

            for(int i = 0; (i < numItems) && (MapErr(res) == KErrNone) && (status == KErrNotFound); i++)
            {
                XAuint32 keySize = 0;
                res = (*m_MetadataExtractionItf)->GetKeySize(
                       m_MetadataExtractionItf, i, &keySize);  
      
                if(MapErr(res) == KErrNone)
                {
                    key = (XAMetadataInfo *)calloc(keySize,1);
                    if(key)
                    {
                        res = (*m_MetadataExtractionItf)->GetKey(
                                        m_MetadataExtractionItf, i , keySize, key);              
                        status = MapErr(res);
                        if(status==KErrNone)
                        {
                            HBufC*   temp  = NULL;
                            if(key->encoding == XA_CHARACTERENCODING_ASCII)
                            {
                                TPtrC8 des((TUint8*)(key->data), key->size-1 );
                                temp = HBufC16::NewL(key->size-1);
                                TPtr tempPtr = temp->Des();
                                tempPtr.Copy(des);                        
                                iLog->Log( _L("Key[%d]: %S"), i, temp);
							}
							else if(key->encoding == XA_CHARACTERENCODING_UTF16LE)
							{
                                TPtrC des((const TUint16*)key->data, key->size/2 - 1);
                                temp = HBufC16::NewL(key->size/2 - 1);
                                TPtr tempPtr = temp->Des();
                                tempPtr.Copy(des);                        
                                iLog->Log( _L("Key[%d]: %S"), i, temp);
							}
									
							if(temp && !keyToFind.Compare(temp->Des()))
							{
								status = KErrNone;
							}
							else
							{
								status = KErrNotFound;
							}
							
							if(temp)
							{
								delete temp;
							}
						}//end if(status==KErrNone)
						
						free(key);
                    }//end if(key)
                }//end if(MapErr(res) == KErrNone)
            }//end for
        }//end if(aItem.GetNextString(index) == KErrNone)
    }//end if(m_MetadataExtractionItf)
        
    iLog->Log( _L("al_metadataextractionitf_GetKey (%d)<<"), status );
    return status;
}
TInt eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL()
	{

	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL(): m_index_type=%d, m_index=%d, m_tunneling_type=0xfe%06x%08x\n"),
		m_index_type,
		m_index,
		m_tunneling_type.get_vendor_id(),
		m_tunneling_type.get_vendor_type()));

	TInt status = KErrNone;
	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
	TPtr sqlStatement = buf->Des();
	
	// Query all the relevant parameters
	_LIT(KSQLQuery, "SELECT %S, %S, %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
	
	sqlStatement.Format(
		KSQLQuery,
		&cf_str_EAP_GTC_passcode_prompt_literal,
		&cf_str_EAP_GTC_identity_literal,
		&cf_str_EAP_GTC_passcode_literal,
		&KGtcTableName,
		&KServiceType,
		m_index_type, 
		&KServiceIndex,
		m_index,
		&KTunnelingTypeVendorId,
		m_tunneling_type.get_vendor_id(),
		&KTunnelingType, 
		m_tunneling_type.get_vendor_type());
	

	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL(): Reads database\n")));

	RDbView view;
	// Evaluate view
	User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
	CleanupClosePushL(view);
	
	User::LeaveIfError(view.EvaluateAll());
	
	// Get the first (and only) row
	view.FirstL();
	view.GetL();
	
	// Get column set so we get the correct column numbers
	CDbColSet* colSet = view.ColSetL();
	CleanupStack::PushL(colSet);

	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL(): Reads database\n")));

	TPtrC username = view.ColDes(colSet->ColNo( cf_str_EAP_GTC_identity_literal ) );

	EAP_TRACE_DATA_DEBUG(
		m_am_tools,
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL(): username"),
		username.Ptr(),
		username.Size()));

	TPtrC password = view.ColDes(colSet->ColNo( cf_str_EAP_GTC_passcode_literal ) );

	EAP_TRACE_DATA_DEBUG(
		m_am_tools,
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL(): password"),
		password.Ptr(),
		password.Size()));

	TUint prompt = view.ColUint(colSet->ColNo(cf_str_EAP_GTC_passcode_prompt_literal));

	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL(): prompt=%d\n"),
		prompt));


	if ((EEapDbFalse != prompt)
		 || (username.Size() == 0) 
		 || (password.Size() == 0))
		{

		if (username.Size() == 0)
			{
			m_dialog_data_ptr->iUsername.Zero();
			}
		else
			{
			m_dialog_data_ptr->iUsername.Copy(username);
			}

		status = KErrCancel;
		}
	else
		{
		status = KErrNone;	
		m_dialog_data_ptr->iUsername.Copy(username);
		m_dialog_data_ptr->iPassword.Copy(password);
		}
		
	CleanupStack::PopAndDestroy(colSet); // Delete colSet.
	CleanupStack::PopAndDestroy(&view); // Close view.
	CleanupStack::PopAndDestroy(buf); // Delete buf.
		
	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::IsDlgReadyToCompleteL(): status=%d\n"),
		status));

	return status;
	}