// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
TBool PosLmLandmarkHandler::ReadIconPathIdL(
    CPosLmLocalDbAccess& aDbAccess,
    const TPosLmItemId& aLandmarkId,
    TUint32& aIconPathId)
    {
    HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
    sql->Des().Format(KPosLmSqlFindUint, &KPosLmIconIdCol,
        &KPosLmLandmarkTable, &KPosLmLandmarkIdCol, aLandmarkId);

    RDbView view;
    aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EUpdatablePreparation, view,
        *sql);

    TBool iconIsSet = EFalse;

    if (view.NextL())
        {
        view.GetL();

        if (!view.IsColNull(1))
            {
            aIconPathId = view.ColUint32(1);
            iconIsSet = ETrue;
            }
        }

    CleanupStack::PopAndDestroy(2, sql); //&view

    return iconIsSet;
    }
// -----------------------------------------------------------------------------
// PosLmIconHandler::GetIconPathIdL
//
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
void PosLmIconHandler::GetIconPathIdL(
    CPosLmLocalDbAccess& aDbAccess,
    const TDesC& aIconPath,
    TUint32& aIconPathId)
    {
    // First search icon table for icon path
    HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen+KMaxFileName);
    sql->Des().Format(KPosLmSqlFindString, &KPosLmIconIdCol, &KPosLmIconTable,
        &KPosLmIconPathCol, &aIconPath);

    RDbView view;
    aDbAccess.PrepareViewLC(
        CPosLmLocalDbAccess::EUpdatablePreparation, view, *sql);

    if (!view.NextL())
        {
        // Icon path not found. Add icon path to database.
        AddIconPathL(aDbAccess, aIconPath, aIconPathId);
        }
    else
        {
        // Icon path found. Fetch number.
        view.GetL();
        aIconPathId = view.ColUint32(1);
        }

    CleanupStack::PopAndDestroy(2, sql); //&view
    }
TUint32 CAlmSettingsSession::CategoryL(const TAny* aSrc)
{
  _LIT(KSQL,"select id from categories where name='%S'");
  RDbView view;
  TBuf<128> sql;
  HBufC8* param0=ValueLC(aSrc);
  TPtrC name((const TUint16*)param0->Ptr(),param0->Length()/2);
  sql.Format(KSQL,&name);
  User::LeaveIfError(view.Prepare(iServer.DbL(),TDbQuery(sql),RDbView::EReadOnly));
  CleanupClosePushL(view);
  User::LeaveIfError(view.EvaluateAll());
  if(!view.FirstL()) User::Leave(KErrNotFound);
  view.GetL();
  TUint32 cid=view.ColUint32(1);
  CleanupStack::PopAndDestroy(2); //view,param1
  return cid;
}
// -----------------------------------------------------------------------------
// PosLmIconHandler::AddIconPathL
//
// (other items were commented in a header).
// -----------------------------------------------------------------------------
//
void PosLmIconHandler::AddIconPathL(
    CPosLmLocalDbAccess& aDbAccess,
    const TDesC& aIconPath,
    TUint32& aIconPathId)
    {
    HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
    sql->Des().Format(KPosLmSqlSelect, &KPosLmSqlAll, &KPosLmIconTable);

    RDbView view;
    aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EAddPreparation, view, *sql);

    view.InsertL();
    PosLmLongTextColHandler::WriteToLongTextColumnL(aIconPath, view,
        EPosLmIcIconPathCol);
    view.PutL();

    aIconPathId = view.ColUint32(EPosLmIcIconIdCol);

    CleanupStack::PopAndDestroy(2, sql); //&view
    }
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
void PosLmLandmarkHandler::ReadCategoriesL(
    CPosLmLocalDbAccess& aDbAccess,
    CPosLandmark& aLandmark)
    {
    HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
    sql->Des().Format(KPosLmSqlFindUint, &KPosLmSqlAll,
        &KPosLmLandmarkCategoryTable, &KPosLmLandmarkIdCol,
        aLandmark.LandmarkId());

    RDbView view;
    aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EUpdatablePreparation, view,
        *sql);

    while (view.NextL())
        {
        view.GetL();
        aLandmark.AddCategoryL(view.ColUint32(EPosLmLccCategoryIdCol));
        }

    CleanupStack::PopAndDestroy(2, sql); //&view
    }
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
EXPORT_C void PosLmLandmarkHandler::GetAllLandmarkIdsL(
    CPosLmLocalDbAccess& aDbAccess,
    TBool aUseSort,
    TBool aSortDescending,
    RArray<TPosLmItemId>& aLandmarkIds)
    {
    aLandmarkIds.Reset();

    HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);

    if (aUseSort)
        {
        sql->Des().Format(KPosLmSqlSelectOrderByString, &KPosLmLandmarkIdCol,
            &KPosLmLandmarkTable, &KPosLmNameCol);

        if (aSortDescending)
            {
            sql->Des().Append(KPosLmSqlDescOrder);
            }
        }
    else
        {
        sql->Des().Format(KPosLmSqlSelect, &KPosLmLandmarkIdCol,
            &KPosLmLandmarkTable);
        }

    RDbView view;
    aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EUpdatablePreparation, view,
        *sql, EDbCompareCollated);

    aLandmarkIds.ReserveL( view.CountL() );
    while ( view.NextL() )
        {
        view.GetL();
        aLandmarkIds.AppendL( view.ColUint32(1) );
        }

    CleanupStack::PopAndDestroy(2, sql); //&view
    }
예제 #7
0
// --------------------------------
// CNSmlRoamTable::GetItemsForIdL( TInt aProfileId )
// Return array of IAPs for profile id
// --------------------------------
//
EXPORT_C CNSmlIAPArray* CNSmlRoamTable::GetItemsForIdL( TInt aProfileId )
	{
	RDbView view;
	CleanupClosePushL( view );
	
	CNSmlIAPArray* array = new (ELeave) CArrayFixFlat<TUint32>(4);
	CleanupStack::PushL( array );
	
	IsNewItemL(view, aProfileId);
	
	view.FirstL();
		
	while (view.AtRow())
		{
		view.GetL();
		array->AppendL( view.ColUint32( iColSet->ColNo( KColIapId ) ));
		view.NextL();
		}
	
	CleanupStack::Pop(); //array
	CleanupStack::PopAndDestroy(); //view
	return array;
	}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
//
void PosLmLandmarkHandler::AddBasicLandmarkInfoL(
    CPosLmLocalDbAccess& aDbAccess,
    CPosLandmark& aLandmark)
    {
    TPtrC iconPath;
    TInt iconIndex;
    TInt maskIndex;
    TUint32 iconPathId = 0;

    // Fetch icon path id if the landmark has an icon.
    if (aLandmark.GetIcon(iconPath, iconIndex, maskIndex) == KErrNone)
        {
        PosLmIconHandler::GetIconPathIdL(aDbAccess, iconPath, iconPathId);
        }

    HBufC* sql = HBufC::NewLC(KPosLmSqlStatementMaxLen);
    sql->Des().Format(KPosLmSqlSelect, &KPosLmSqlAll, &KPosLmLandmarkTable);

    RDbView view;
    aDbAccess.PrepareViewLC(CPosLmLocalDbAccess::EAddPreparation, view, *sql);

    view.InsertL();

    SetPositionL(view, aLandmark);
    SetCoverageRadiusL(view, aLandmark);
    SetIconL(view, aLandmark, iconPathId);
    SetLandmarkNameL(view, aLandmark);
    SetLandmarkDescriptionL(view, aLandmark);

    view.PutL();

    // Fetch and set the landmark id
    PosLmImplExtension::SetLandmarkIdL(aLandmark,
        view.ColUint32(EPosLmLcLandmarkIdCol));

    CleanupStack::PopAndDestroy(2, sql); //&view
    }
void eapol_am_wlan_authentication_symbian_c::read_configureL(
	const TDesC& aDbName,
	const TDesC& aTableName,
	eap_config_string field,
	const u32_t /*field_length*/,
	eap_variable_data_c * const data)
{	
	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT, 
		(EAPL("eapol_am_wlan_authentication_symbian_c::read_configureL(): %s, this = 0x%08x => 0x%08x\n"),
		 (m_is_client == true) ? "client": "server",
		 this,
		 dynamic_cast<abs_eap_base_timer_c *>(this)));
	EAP_TRACE_RETURN_STRING_FLAGS(m_am_tools, TRACE_FLAGS_DEFAULT, "returns: eapol_am_wlan_authentication_symbian_c::read_configureL()");

	// Open database
	RDbNamedDatabase db;

	TInt error = db.Open(m_session, aDbName);

	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT, 
		(EAPL("eapol_am_wlan_authentication_symbian_c::read_configureL(): db.Open(), error = %d\n"),
		 error));

	User::LeaveIfError(error);
	
	CleanupClosePushL(db);


	// Create a buffer for the ascii strings - initialised with the argument
	HBufC8* asciibuf = HBufC8::NewLC(128);
	TPtr8 asciiString = asciibuf->Des();
	asciiString.Copy(reinterpret_cast<const unsigned char *>(field));
		
	// Buffer for unicode parameter
	HBufC* unicodebuf = HBufC::NewLC(128);
	TPtr unicodeString = unicodebuf->Des();
	
	// Convert to unicode 
	unicodeString.Copy(asciiString);

	// Now do the database query
	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
	TPtr sqlStatement = buf->Des();
	_LIT(KSQLQueryRow, "SELECT %S FROM %S");
	sqlStatement.Format( KSQLQueryRow, &unicodeString, &aTableName );
	
	RDbView view;
	User::LeaveIfError(view.Prepare(db, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
	CleanupClosePushL(view);
	User::LeaveIfError(view.EvaluateAll());	
	if (view.FirstL())
	{
		eap_status_e status(eap_status_process_general_error);
		view.GetL();		
		switch (view.ColType(1))
		{
		case EDbColText:				
			{
				unicodeString = view.ColDes(1);
				// Convert to 8-bit
				asciiString.Copy(unicodeString);
				if (asciiString.Size() > 0)
				{
					status = data->set_copy_of_buffer(asciiString.Ptr(), asciiString.Size());
					if (status != eap_status_ok)
					{
						User::Leave(m_am_tools->convert_eapol_error_to_am_error(
							EAP_STATUS_RETURN(m_am_tools, status)));
					}
				} 
				else 
				{
					// Empty field. Do nothing...data remains invalid and the stack knows what to do hopefully.
					break;
				}
			}
			break;
		case EDbColUint32:
			{
				TUint value;
				value = view.ColUint32(1);
				status = data->set_copy_of_buffer((const unsigned char *) &value, sizeof(value));
				if (status != eap_status_ok)
				{
					User::Leave(m_am_tools->convert_eapol_error_to_am_error(
						EAP_STATUS_RETURN(m_am_tools, status)));
				}
			}
			break;
		default:
			EAP_TRACE_DEBUG(
				m_am_tools,
				TRACE_FLAGS_DEFAULT,
				(EAPL("ERROR: read_configureL: Unexpected column type.\n")));
			User::Panic(_L("EAPOL"), 1);			
		}
	} 
	else 
	{
		// Could not find parameter
		EAP_TRACE_DEBUG(
			m_am_tools,
			TRACE_FLAGS_DEFAULT,
			(EAPL("ERROR: read_configureL: Could not find configuration parameter.\n")));
		User::Leave(m_am_tools->convert_eapol_error_to_am_error(
							EAP_STATUS_RETURN(m_am_tools, eap_status_not_found)));
	}		
	
	// Close database
	CleanupStack::PopAndDestroy(&view);
	CleanupStack::PopAndDestroy(buf);
	CleanupStack::PopAndDestroy(unicodebuf);
	CleanupStack::PopAndDestroy(asciibuf);
	CleanupStack::PopAndDestroy(&db);


	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
}
void eapol_am_wlan_authentication_symbian_c::SavePSKL(TPSKEntry& entry)
{
	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT, 
		(EAPL("eapol_am_wlan_authentication_symbian_c::SavePSKL(): this = 0x%08x\n"),
		this));
	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eapol_am_wlan_authentication_symbian_c::SavePSKL()");

	// Connect to CommDBif so that we can delete PSK entries that have no IAP associated anymore.
	CWLanSettings* wlan_settings = new(ELeave) CWLanSettings;
	CleanupStack::PushL(wlan_settings);
	
	SWLANSettings wlanSettings;

	if (wlan_settings->Connect() != KErrNone)
	{
		// Could not connect to CommDB			
		User::Leave(KErrCouldNotConnect);
	}

	// Open database
	RDbNamedDatabase db;

	TFileName aPrivateDatabasePathName;

	EapPluginTools::GetPrivatePathL(
		m_session,
		aPrivateDatabasePathName);

	aPrivateDatabasePathName.Append(KEapolDatabaseName);

	EAP_TRACE_DATA_DEBUG_SYMBIAN(("aPrivateDatabasePathName",
		aPrivateDatabasePathName.Ptr(),
		aPrivateDatabasePathName.Size()));

	User::LeaveIfError(db.Open(m_session, aPrivateDatabasePathName));	
	
	CleanupClosePushL(db);

	HBufC* sqlbuf = HBufC::NewLC(KMaxSqlQueryLength);
	TPtr sqlStatement = sqlbuf->Des();

	RDbView view;

	_LIT(KSQL, "SELECT %S, %S, %S, %S, %S FROM %S");
	
	sqlStatement.Format(KSQL, &KServiceType, &KServiceIndex, &KSSID, &KPassword, &KPSK,
		&KEapolPSKTableName);

	User::LeaveIfError(view.Prepare(db, TDbQuery(sqlStatement), TDbWindow::EUnlimited));	
	CleanupClosePushL(view);
	User::LeaveIfError(view.EvaluateAll());
	
	// Get column set so we get the correct column numbers
	CDbColSet* colSet = view.ColSetL();		
	CleanupStack::PushL(colSet);
	
	// Delete old row and also rows that have no associated IAP settings.
	if (view.FirstL())
	{
		do {
			view.GetL();

			if ((wlan_settings->GetWlanSettingsForService(view.ColUint32(colSet->ColNo(KServiceIndex)), wlanSettings) != KErrNone)
				|| (view.ColUint32(colSet->ColNo(KServiceType)) == static_cast<TUint>(entry.indexType)
					&& view.ColUint32(colSet->ColNo(KServiceIndex)) == static_cast<TUint>(entry.index)))
			{	
				// Not found or current IAP
				view.DeleteL();	
			}
			
		} while (view.NextL() != EFalse);
	}

	wlan_settings->Disconnect();
	
	view.InsertL();
	
	view.SetColL(colSet->ColNo(KServiceType), (TUint)entry.indexType);
	view.SetColL(colSet->ColNo(KServiceIndex), (TUint)entry.index);
	view.SetColL(colSet->ColNo(KSSID), entry.ssid);
	view.SetColL(colSet->ColNo(KPassword), entry.password);
	view.SetColL(colSet->ColNo(KPSK), entry.psk);	
	
	view.PutL();
	
	CleanupStack::PopAndDestroy( colSet ); // Delete colSet.	

	CleanupStack::PopAndDestroy(&view);
	CleanupStack::PopAndDestroy(sqlbuf);
	CleanupStack::PopAndDestroy(&db);
	CleanupStack::PopAndDestroy(wlan_settings);

}
void eap_am_type_securid_symbian_c::type_configure_readL(
	eap_config_string field,
	const u32_t field_length,
	eap_variable_data_c * const data)
{
	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
	EAP_TRACE_DEBUG(
		m_am_tools, 
		TRACE_FLAGS_DEFAULT,
		(EAPL("eap_am_type_securid_symbian_c::type_configure_readL(): 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()));

	EAP_UNREFERENCED_PARAMETER(field_length);

	// Create a buffer for the ascii strings - initialised with the argument
	HBufC16* unicodeBuf = HBufC16::NewLC(KMaxDBFieldNameLength);
	TPtr16 unicodeString = unicodeBuf->Des();

	TPtrC8 fieldPtr(reinterpret_cast<const TUint8 *> (field), field_length);

	unicodeString.Copy(fieldPtr);
			
	// Now do the database query
	
	HBufC* buf = HBufC::NewLC(KMaxSqlQueryLength);
	TPtr sqlStatement = buf->Des();

	_LIT(KSQLQueryRow, "SELECT %S FROM %S WHERE %S=%d AND %S=%d AND %S=%d AND %S=%d");
	if (m_eap_type == eap_type_securid)
	{
		sqlStatement.Format(
			KSQLQueryRow,
			&unicodeString,
			&KSecurIDTableName, 
			&KServiceType,
			m_index_type,
			&KServiceIndex,
			m_index,
			&KTunnelingTypeVendorId,
			m_tunneling_type.get_vendor_id(),
			&KTunnelingType, 
			m_tunneling_type.get_vendor_type());
	}
	else
	{
		sqlStatement.Format(
			KSQLQueryRow,
			&unicodeString,
			&KGtcTableName, 
			&KServiceType,
			m_index_type,
			&KServiceIndex,
			m_index,
			&KTunnelingTypeVendorId,
			m_tunneling_type.get_vendor_id(),
			&KTunnelingType, 
			m_tunneling_type.get_vendor_type());
	}

	RDbView view;
	User::LeaveIfError(view.Prepare(m_database, TDbQuery(sqlStatement), TDbWindow::EUnlimited));
	CleanupClosePushL(view);
	
	User::LeaveIfError(view.EvaluateAll());	
	
	if (view.FirstL())
	{
		eap_status_e status = eap_status_ok;
		view.GetL();		

		switch (view.ColType(KDefaultColumnInView_One))
		{
		case EDbColText:
			{
				if (view.ColLength(KDefaultColumnInView_One) > 0)
				{
					TPtrC16 value = view.ColDes16(KDefaultColumnInView_One);

					eap_variable_data_c string_unicode(m_am_tools);

					status = string_unicode.set_copy_of_buffer(value.Ptr(), value.Size());
					if (status != eap_status_ok)
					{
						User::Leave(
							m_am_tools->convert_eapol_error_to_am_error(
								EAP_STATUS_RETURN(m_am_tools, status)));
					}

					status = m_am_tools->convert_unicode_to_utf8(
						*data,
						string_unicode);
					if (status != eap_status_ok)
					{
						User::Leave(
							m_am_tools->convert_eapol_error_to_am_error(
								EAP_STATUS_RETURN(m_am_tools, status)));
					}
				} 
				else 
				{
					data->reset();
					status = data->set_copy_of_buffer("", 0);
					if (status != eap_status_ok)
					{
						User::Leave(
							m_am_tools->convert_eapol_error_to_am_error(
								EAP_STATUS_RETURN(m_am_tools, status)));
					}
				}
			}
			break;

		case EDbColUint32:
			{
				TUint value = view.ColUint32(KDefaultColumnInView_One);
				status = data->set_copy_of_buffer(reinterpret_cast<unsigned char *> (&value), sizeof(value));
				if (status != eap_status_ok)
				{
					User::Leave(
						m_am_tools->convert_eapol_error_to_am_error(
							EAP_STATUS_RETURN(m_am_tools, status)));
				}
			}
			break;

		default:
			EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("type_configure_readL: Unexpected column type.\n")));
			User::Leave(KErrGeneral);
			break;
		}
	} 
	else 
	{
		// Could not find parameter
		EAP_TRACE_DEBUG(m_am_tools, TRACE_FLAGS_DEFAULT, (EAPL("type_configure_readL: Could not find configuration parameter.\n")));
		User::Leave(KErrArgument);
	}		
	
	CleanupStack::PopAndDestroy(3); // Close view, 2 x buf

	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
}