Search in sources :

Example 1 with PwEntry

use of com.keepassdroid.database.PwEntry in project KeePassDX by Kunzisoft.

the class DeleteEntry method testDelete.

public void testDelete() {
    Database db;
    Context ctx = getContext();
    try {
        db = TestData.GetDb(ctx, ASSET, PASSWORD, KEYFILE, FILENAME);
    } catch (Exception e) {
        assertTrue("Failed to open database: " + e.getMessage(), false);
        return;
    }
    PwDatabaseV3 pm = (PwDatabaseV3) db.pm;
    PwGroup group1 = getGroup(pm, GROUP1_NAME);
    assertNotNull("Could not find group1", group1);
    // Delete the group
    DeleteGroup task = new DeleteGroup(db, group1, null, true);
    task.run();
    // Verify the entries were deleted
    PwEntry entry1 = getEntry(pm, ENTRY1_NAME);
    assertNull("Entry 1 was not removed", entry1);
    PwEntry entry2 = getEntry(pm, ENTRY2_NAME);
    assertNull("Entry 2 was not removed", entry2);
    // Verify the entries were removed from the search index
    SearchDbHelper dbHelp = new SearchDbHelper(ctx);
    PwGroup results1 = dbHelp.search(db, ENTRY1_NAME);
    PwGroup results2 = dbHelp.search(db, ENTRY2_NAME);
    assertEquals("Entry1 was not removed from the search results", 0, results1.numbersOfChildEntries());
    assertEquals("Entry2 was not removed from the search results", 0, results2.numbersOfChildEntries());
    // Verify the group was deleted
    group1 = getGroup(pm, GROUP1_NAME);
    assertNull("Group 1 was not removed.", group1);
}
Also used : Context(android.content.Context) PwDatabaseV3(com.keepassdroid.database.PwDatabaseV3) SearchDbHelper(com.keepassdroid.search.SearchDbHelper) PwDatabase(com.keepassdroid.database.PwDatabase) Database(com.keepassdroid.database.Database) PwEntry(com.keepassdroid.database.PwEntry) PwGroup(com.keepassdroid.database.PwGroup) DeleteGroup(com.keepassdroid.database.edit.DeleteGroup)

Example 2 with PwEntry

use of com.keepassdroid.database.PwEntry in project KeePassDX by Kunzisoft.

the class SprEngineV4 method findRefTarget.

public TargetResult findRefTarget(String fullRef, SprContextV4 ctx) {
    if (fullRef == null) {
        return null;
    }
    fullRef = fullRef.toUpperCase(Locale.ENGLISH);
    if (!fullRef.startsWith(STR_REF_START) || !fullRef.endsWith(STR_REF_END)) {
        return null;
    }
    String ref = fullRef.substring(STR_REF_START.length(), fullRef.length() - STR_REF_START.length() - STR_REF_END.length());
    if (ref.length() <= 4) {
        return null;
    }
    if (ref.charAt(1) != '@') {
        return null;
    }
    if (ref.charAt(3) != ':') {
        return null;
    }
    char scan = Character.MIN_VALUE;
    char wanted = Character.MIN_VALUE;
    scan = Character.toUpperCase(ref.charAt(2));
    wanted = Character.toUpperCase(ref.charAt(0));
    SearchParametersV4 sp = new SearchParametersV4();
    sp.setupNone();
    sp.searchString = ref.substring(4);
    if (scan == 'T') {
        sp.searchInTitles = true;
    } else if (scan == 'U') {
        sp.searchInUserNames = true;
    } else if (scan == 'A') {
        sp.searchInUrls = true;
    } else if (scan == 'P') {
        sp.searchInPasswords = true;
    } else if (scan == 'N') {
        sp.searchInNotes = true;
    } else if (scan == 'I') {
        sp.searchInUUIDs = true;
    } else if (scan == 'O') {
        sp.searchInOther = true;
    } else {
        return null;
    }
    List<PwEntry> list = new ArrayList<PwEntry>();
    ctx.db.rootGroup.searchEntries(sp, list);
    if (list.size() > 0) {
        return new TargetResult((PwEntryV4) list.get(0), wanted);
    }
    return null;
}
Also used : SearchParametersV4(com.keepassdroid.database.SearchParametersV4) PwEntry(com.keepassdroid.database.PwEntry) ArrayList(java.util.ArrayList)

Example 3 with PwEntry

use of com.keepassdroid.database.PwEntry in project KeePassDX by Kunzisoft.

the class SearchDbHelper method search.

public PwGroup search(Database db, String qStr) {
    PwDatabase pm = db.pm;
    PwGroup group;
    if (pm instanceof PwDatabaseV3) {
        group = new PwGroupV3();
    } else if (pm instanceof PwDatabaseV4) {
        group = new PwGroupV4();
    } else {
        Log.d("SearchDbHelper", "Tried to search with unknown db");
        return null;
    }
    group.setName(mCtx.getString(R.string.search_results));
    group.setEntries(new ArrayList<>());
    // Search all entries
    Locale loc = Locale.getDefault();
    qStr = qStr.toLowerCase(loc);
    boolean isOmitBackup = omitBackup();
    Queue<PwGroup> worklist = new LinkedList<PwGroup>();
    if (pm.rootGroup != null) {
        worklist.add(pm.rootGroup);
    }
    while (worklist.size() != 0) {
        PwGroup top = worklist.remove();
        if (pm.isGroupSearchable(top, isOmitBackup)) {
            for (PwEntry entry : top.getChildEntries()) {
                processEntries(entry, group.getChildEntries(), qStr, loc);
            }
            for (PwGroup childGroup : top.getChildGroups()) {
                if (childGroup != null) {
                    worklist.add(childGroup);
                }
            }
        }
    }
    return group;
}
Also used : PwDatabaseV3(com.keepassdroid.database.PwDatabaseV3) Locale(java.util.Locale) PwGroupV3(com.keepassdroid.database.PwGroupV3) PwGroupV4(com.keepassdroid.database.PwGroupV4) PwDatabase(com.keepassdroid.database.PwDatabase) PwEntry(com.keepassdroid.database.PwEntry) PwGroup(com.keepassdroid.database.PwGroup) LinkedList(java.util.LinkedList) PwDatabaseV4(com.keepassdroid.database.PwDatabaseV4)

Example 4 with PwEntry

use of com.keepassdroid.database.PwEntry in project KeePassDX by Kunzisoft.

the class DeleteGroup method run.

@Override
public void run() {
    PwDatabase pm = mDb.pm;
    PwGroup parent = mGroup.getParent();
    // Remove Group from parent
    boolean recycle = pm.canRecycle(mGroup);
    if (recycle) {
        pm.recycle(mGroup);
    } else {
        // TODO tests
        // Remove child entries
        List<PwEntry> childEnt = new ArrayList<>(mGroup.getChildEntries());
        for (int i = 0; i < childEnt.size(); i++) {
            DeleteEntry task = new DeleteEntry(mContext, mDb, childEnt.get(i), null, true);
            task.run();
        }
        // Remove child groups
        List<PwGroup> childGrp = new ArrayList<>(mGroup.getChildGroups());
        for (int i = 0; i < childGrp.size(); i++) {
            DeleteGroup task = new DeleteGroup(mContext, mDb, childGrp.get(i), null, true);
            task.run();
        }
        pm.deleteGroup(mGroup);
        // Remove from PwDatabaseV3
        // TODO ENcapsulate
        mDb.pm.getGroups().remove(mGroup);
    }
    // Save
    mFinish = new AfterDelete(mFinish, parent, mGroup, recycle);
    // Commit Database
    SaveDB save = new SaveDB(mContext, mDb, mFinish, mDontSave);
    save.run();
}
Also used : PwDatabase(com.keepassdroid.database.PwDatabase) PwEntry(com.keepassdroid.database.PwEntry) ArrayList(java.util.ArrayList) PwGroup(com.keepassdroid.database.PwGroup)

Example 5 with PwEntry

use of com.keepassdroid.database.PwEntry in project KeePassDX by Kunzisoft.

the class EntryEditActivity method populateNewEntry.

protected PwEntry populateNewEntry() {
    PwDatabase db = App.getDB().pm;
    PwEntry newEntry = mEntry.clone();
    newEntry.startToDecodeReference(db);
    newEntry.createBackup(db);
    newEntry.setLastAccessTime(new PwDate());
    newEntry.setLastModificationTime(new PwDate());
    newEntry.setTitle(entryTitleView.getText().toString());
    if (mSelectedIconID != -1)
        // or TODO icon factory newEntry.setIcon(App.getDB().pm.iconFactory.getIcon(mSelectedIconID));
        newEntry.setIcon(new PwIconStandard(mSelectedIconID));
    else {
        if (mIsNew) {
            newEntry.setIcon(App.getDB().pm.iconFactory.getIcon(0));
        } else {
            //  Keep previous icon, if no new one was selected
            newEntry.setIcon(mEntry.getIconStandard());
        }
    }
    newEntry.setUrl(entryUrlView.getText().toString());
    newEntry.setUsername(entryUserNameView.getText().toString());
    newEntry.setNotes(entryCommentView.getText().toString());
    newEntry.setPassword(entryPasswordView.getText().toString());
    if (newEntry.allowExtraFields()) {
        // Delete all new standard strings
        newEntry.removeExtraFields();
        // Add extra fields from views
        for (int i = 0; i < entryExtraFieldsContainer.getChildCount(); i++) {
            EntryEditNewField view = (EntryEditNewField) entryExtraFieldsContainer.getChildAt(i);
            String key = view.getLabel();
            String value = view.getValue();
            boolean protect = view.isProtected();
            newEntry.addField(key, new ProtectedString(protect, value));
        }
    }
    newEntry.endToDecodeReference(db);
    return newEntry;
}
Also used : PwDatabase(com.keepassdroid.database.PwDatabase) PwDate(com.keepassdroid.database.PwDate) PwEntry(com.keepassdroid.database.PwEntry) ProtectedString(com.keepassdroid.database.security.ProtectedString) PwIconStandard(com.keepassdroid.database.PwIconStandard) ProtectedString(com.keepassdroid.database.security.ProtectedString) EntryEditNewField(com.keepassdroid.view.EntryEditNewField)

Aggregations

PwEntry (com.keepassdroid.database.PwEntry)5 PwDatabase (com.keepassdroid.database.PwDatabase)4 PwGroup (com.keepassdroid.database.PwGroup)3 PwDatabaseV3 (com.keepassdroid.database.PwDatabaseV3)2 ArrayList (java.util.ArrayList)2 Context (android.content.Context)1 Database (com.keepassdroid.database.Database)1 PwDatabaseV4 (com.keepassdroid.database.PwDatabaseV4)1 PwDate (com.keepassdroid.database.PwDate)1 PwGroupV3 (com.keepassdroid.database.PwGroupV3)1 PwGroupV4 (com.keepassdroid.database.PwGroupV4)1 PwIconStandard (com.keepassdroid.database.PwIconStandard)1 SearchParametersV4 (com.keepassdroid.database.SearchParametersV4)1 DeleteGroup (com.keepassdroid.database.edit.DeleteGroup)1 ProtectedString (com.keepassdroid.database.security.ProtectedString)1 SearchDbHelper (com.keepassdroid.search.SearchDbHelper)1 EntryEditNewField (com.keepassdroid.view.EntryEditNewField)1 LinkedList (java.util.LinkedList)1 Locale (java.util.Locale)1