Changeset 106234 in webkit


Ignore:
Timestamp:
Jan 30, 2012 4:50:00 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[BlackBerry] Credential backing store implementation
https://bugs.webkit.org/show_bug.cgi?id=76761

Patch by Jonathan Dong <Jonathan Dong> on 2012-01-30
Reviewed by Antonio Gomes.

Implemented credential backing store database and related
operations in class CredentialBackingStore.

  • platform/network/blackberry/CredentialBackingStore.cpp:

(WebCore::CredentialBackingStore::~CredentialBackingStore):
(WebCore::CredentialBackingStore::open):
(WebCore::CredentialBackingStore::close):
(WebCore::CredentialBackingStore::addLogin):
(WebCore::CredentialBackingStore::updateLogin):
(WebCore::CredentialBackingStore::hasLogin):
(WebCore::CredentialBackingStore::getLogin):
(WebCore::CredentialBackingStore::removeLogin):
(WebCore::CredentialBackingStore::clear):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r106232 r106234  
     12012-01-30  Jonathan Dong  <jonathan.dong@torchmobile.com.cn>
     2
     3        [BlackBerry] Credential backing store implementation
     4        https://bugs.webkit.org/show_bug.cgi?id=76761
     5
     6        Reviewed by Antonio Gomes.
     7
     8        Implemented credential backing store database and related
     9        operations in class CredentialBackingStore.
     10
     11        * platform/network/blackberry/CredentialBackingStore.cpp:
     12        (WebCore::CredentialBackingStore::~CredentialBackingStore):
     13        (WebCore::CredentialBackingStore::open):
     14        (WebCore::CredentialBackingStore::close):
     15        (WebCore::CredentialBackingStore::addLogin):
     16        (WebCore::CredentialBackingStore::updateLogin):
     17        (WebCore::CredentialBackingStore::hasLogin):
     18        (WebCore::CredentialBackingStore::getLogin):
     19        (WebCore::CredentialBackingStore::removeLogin):
     20        (WebCore::CredentialBackingStore::clear):
     21
    1222012-01-30  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
    223
  • trunk/Source/WebCore/platform/network/blackberry/CredentialBackingStore.cpp

    r101668 r106234  
    2929#include <wtf/UnusedParam.h>
    3030
     31#define HANDLE_SQL_EXEC_FAILURE(statement, returnValue, ...) \
     32    if (statement) { \
     33        LOG_ERROR(__VAR_ARGS__); \
     34        return returnValue; \
     35    }
     36
    3137namespace WebCore {
    3238
     
    5056CredentialBackingStore::~CredentialBackingStore()
    5157{
     58    if (m_database.isOpen())
     59        m_database.close();
    5260}
    5361
    5462bool CredentialBackingStore::open(const String& dbPath)
    5563{
    56     UNUSED_PARAM(dbPath);
    57 
    58     notImplemented();
     64    ASSERT(!m_database.isOpen());
     65
     66    HANDLE_SQL_EXEC_FAILURE(!m_database.open(dbPath), false,
     67        "Failed to open database file %s for login database", dbPath.utf8().data());
     68
     69    if (!m_database.tableExists("logins")) {
     70        HANDLE_SQL_EXEC_FAILURE(!m_database.executeCommand("CREATE TABLE logins (origin_url VARCHAR NOT NULL, host VARCHAR NOT NULL, port INTEGER, service_type INTEGER NOT NULL, realm VARCHAR, auth_scheme INTEGER NOT NULL, username VARCHAR, password BLOB) "),
     71            false, "Failed to create table logins for login database");
     72
     73        // Create index for table logins.
     74        HANDLE_SQL_EXEC_FAILURE(!m_database.executeCommand("CREATE INDEX logins_signon ON logins (host)"),
     75            false, "Failed to create index for table logins");
     76    } else { // Initiate CredentialStorage.
     77        SQLiteStatement query(m_database, "SELECT origin_url, host, port, service_type, realm, auth_scheme, username, password FROM logins");
     78        HANDLE_SQL_EXEC_FAILURE(query.prepare() != SQLResultOk,
     79            false, "Failed to prepare query statement to initiate CredentialStorage");
     80
     81        int result = query.step();
     82        while (result == SQLResultRow) {
     83            String strUrl = query.getColumnText(1);
     84            String strHost = query.getColumnText(2);
     85            int intPort = query.getColumnInt(3);
     86            ProtectionSpaceServerType serviceType = static_cast<ProtectionSpaceServerType>(query.getColumnInt(4));
     87            String strRealm = query.getColumnText(5);
     88            ProtectionSpaceAuthenticationScheme authScheme = static_cast<ProtectionSpaceAuthenticationScheme>(query.getColumnInt(6));
     89            String strUserName = query.getColumnText(7);
     90            String strPassword = decryptedString(query.getColumnText(8));
     91
     92            KURL url(ParsedURLString, strUrl);
     93            ProtectionSpace protectionSpace(strHost, intPort, serviceType, strRealm, authScheme);
     94            Credential credential(strUserName, strPassword, CredentialPersistencePermanent);
     95            CredentialStorage::set(credential, protectionSpace, url);
     96
     97            result = query.step();
     98        }
     99    }
     100
     101    // Prepare the statements.
     102    m_addStatement = new SQLiteStatement(m_database, "INSERT OR REPLACE INTO logins (origin_url, host, port, service_type, realm, auth_scheme, username, password) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
     103    HANDLE_SQL_EXEC_FAILURE(m_addStatement->prepare() != SQLResultOk,
     104        false, "Failed to prepare addLogin statement");
     105
     106    m_updateStatement = new SQLiteStatement(m_database, "UPDATE logins SET username = ?, password = ? WHERE origin_url = ? AND host = ? AND port = ? AND service_type = ? AND realm = ? AND auth_scheme = ?");
     107    HANDLE_SQL_EXEC_FAILURE(m_updateStatement->prepare() != SQLResultOk,
     108        false, "Failed to prepare updateLogin statement");
     109
     110    m_hasStatement = new SQLiteStatement(m_database, "SELECT COUNT(*) FROM logins WHERE host = ? AND port = ? AND service_type = ? AND realm = ? AND auth_scheme = ?");
     111    HANDLE_SQL_EXEC_FAILURE(m_hasStatement->prepare() != SQLResultOk,
     112        false, "Failed to prepare hasLogin statement");
     113
     114    m_getStatement = new SQLiteStatement(m_database, "SELECT username, password FROM logins WHERE host = ? AND port = ? AND service_type = ? AND realm = ? AND auth_scheme = ?");
     115    HANDLE_SQL_EXEC_FAILURE(m_getStatement->prepare() != SQLResultOk,
     116        false, "Failed to prepare getLogin statement");
     117
     118    m_removeStatement = new SQLiteStatement(m_database, "DELETE FROM logins WHERE host = ? AND port = ? AND service_type = ? AND realm = ? AND auth_scheme = ?");
     119    HANDLE_SQL_EXEC_FAILURE(m_removeStatement->prepare() != SQLResultOk,
     120        false, "Failed to prepare removeLogin statement");
     121
     122    return true;
     123}
     124
     125void CredentialBackingStore::close()
     126{
     127    delete m_addStatement;
     128    m_addStatement = 0;
     129    delete m_updateStatement;
     130    m_updateStatement = 0;
     131    delete m_hasStatement;
     132    m_hasStatement = 0;
     133    delete m_getStatement;
     134    m_getStatement = 0;
     135    delete m_removeStatement;
     136    m_removeStatement = 0;
     137
     138    if (m_database.isOpen())
     139        m_database.close();
     140}
     141
     142bool CredentialBackingStore::addLogin(const KURL& url, const ProtectionSpace& protectionSpace, const Credential& credential)
     143{
     144    ASSERT(m_database.isOpen());
     145    ASSERT(m_database.tableExists("logins"));
     146
     147    if (!m_addStatement)
     148        return false;
     149
     150    m_addStatement->bindText(1, url.string());
     151    m_addStatement->bindText(2, protectionSpace.host());
     152    m_addStatement->bindInt(3, protectionSpace.port());
     153    m_addStatement->bindInt(4, static_cast<int>(protectionSpace.serverType()));
     154    m_addStatement->bindText(5, protectionSpace.realm());
     155    m_addStatement->bindInt(6, static_cast<int>(protectionSpace.authenticationScheme()));
     156    m_addStatement->bindText(7, credential.user());
     157    m_addStatement->bindBlob(8, encryptedString(credential.password()));
     158
     159    int result = m_addStatement->step();
     160    HANDLE_SQL_EXEC_FAILURE(result != SQLResultDone, false,
     161        "Failed to add login info into table logins - %i", result);
     162
     163    return true;
     164}
     165
     166bool CredentialBackingStore::updateLogin(const KURL& url, const ProtectionSpace& protectionSpace, const Credential& credential)
     167{
     168    ASSERT(m_database.isOpen());
     169    ASSERT(m_database.tableExists("logins"));
     170
     171    if (!m_updateStatement)
     172        return false;
     173
     174    m_updateStatement->bindText(1, url.string());
     175    m_updateStatement->bindText(2, credential.user());
     176    m_updateStatement->bindBlob(3, encryptedString(credential.password()));
     177    m_updateStatement->bindText(4, protectionSpace.host());
     178    m_updateStatement->bindInt(5, protectionSpace.port());
     179    m_updateStatement->bindInt(6, static_cast<int>(protectionSpace.serverType()));
     180    m_updateStatement->bindText(7, protectionSpace.realm());
     181    m_updateStatement->bindInt(8, static_cast<int>(protectionSpace.authenticationScheme()));
     182
     183    int result = m_updateStatement->step();
     184    HANDLE_SQL_EXEC_FAILURE(result != SQLResultDone, false,
     185        "Failed to update login info in table logins - %i", result);
     186
     187    return true;
     188}
     189
     190bool CredentialBackingStore::hasLogin(const ProtectionSpace& protectionSpace)
     191{
     192    ASSERT(m_database.isOpen());
     193    ASSERT(m_database.tableExists("logins"));
     194
     195    if (!m_hasStatement)
     196        return false;
     197
     198    m_hasStatement->bindText(1, protectionSpace.host());
     199    m_hasStatement->bindInt(2, protectionSpace.port());
     200    m_hasStatement->bindInt(3, static_cast<int>(protectionSpace.serverType()));
     201    m_hasStatement->bindText(4, protectionSpace.realm());
     202    m_hasStatement->bindInt(5, static_cast<int>(protectionSpace.authenticationScheme()));
     203
     204    int result = m_hasStatement->step();
     205    HANDLE_SQL_EXEC_FAILURE(result != SQLResultRow, false,
     206        "Failed to execute select login info from table logins in hasLogin - %i", result);
     207
     208    if (m_hasStatement->getColumnInt(0))
     209        return true;
    59210    return false;
    60211}
    61212
    62 void CredentialBackingStore::close()
    63 {
    64     notImplemented();
    65 }
    66 
    67 bool CredentialBackingStore::addLogin(const KURL& url, const ProtectionSpace& protectionSpace, const Credential& credential)
    68 {
    69     UNUSED_PARAM(url);
    70     UNUSED_PARAM(protectionSpace);
    71     UNUSED_PARAM(credential);
    72 
    73     notImplemented();
    74     return false;
    75 }
    76 
    77 bool CredentialBackingStore::updateLogin(const KURL& url, const ProtectionSpace& protectionSpace, const Credential& credential)
    78 {
    79     UNUSED_PARAM(url);
    80     UNUSED_PARAM(protectionSpace);
    81     UNUSED_PARAM(credential);
    82 
    83     notImplemented();
    84     return false;
    85 }
    86 
    87 bool CredentialBackingStore::hasLogin(const ProtectionSpace& protectionSpace)
    88 {
    89     UNUSED_PARAM(protectionSpace);
    90 
    91     notImplemented();
    92     return false;
    93 }
    94 
    95213Credential CredentialBackingStore::getLogin(const ProtectionSpace& protectionSpace)
    96214{
    97     UNUSED_PARAM(protectionSpace);
    98 
    99     notImplemented();
    100     return Credential();
     215    ASSERT(m_database.isOpen());
     216    ASSERT(m_database.tableExists("logins"));
     217
     218    if (!m_getStatement)
     219        return Credential();
     220
     221    m_getStatement->bindText(1, protectionSpace.host());
     222    m_getStatement->bindInt(2, protectionSpace.port());
     223    m_getStatement->bindInt(3, static_cast<int>(protectionSpace.serverType()));
     224    m_getStatement->bindText(4, protectionSpace.realm());
     225    m_getStatement->bindInt(5, static_cast<int>(protectionSpace.authenticationScheme()));
     226
     227    int result = m_getStatement->step();
     228    HANDLE_SQL_EXEC_FAILURE(result != SQLResultRow, Credential(),
     229        "Failed to execute select login info from table logins in getLogin - %i", result);
     230
     231    return Credential(m_getStatement->getColumnText(0), decryptedString(m_getStatement->getColumnText(1)), CredentialPersistencePermanent);
    101232}
    102233
    103234bool CredentialBackingStore::removeLogin(const ProtectionSpace& protectionSpace)
    104235{
    105     UNUSED_PARAM(protectionSpace);
    106 
    107     notImplemented();
    108     return false;
     236    ASSERT(m_database.isOpen());
     237    ASSERT(m_database.tableExists("logins"));
     238
     239    if (!m_removeStatement)
     240        return false;
     241
     242    m_removeStatement->bindText(1, protectionSpace.host());
     243    m_removeStatement->bindInt(2, protectionSpace.port());
     244    m_removeStatement->bindInt(3, static_cast<int>(protectionSpace.serverType()));
     245    m_removeStatement->bindText(4, protectionSpace.realm());
     246    m_removeStatement->bindInt(5, static_cast<int>(protectionSpace.authenticationScheme()));
     247
     248    int result = m_removeStatement->step();
     249    HANDLE_SQL_EXEC_FAILURE(result != SQLResultDone, false,
     250        "Failed to remove login info from table logins - %i", result);
     251
     252    return true;
    109253}
    110254
    111255bool CredentialBackingStore::clear()
    112256{
    113     notImplemented();
    114     return false;
     257    ASSERT(m_database.isOpen());
     258    ASSERT(m_database.tableExists("logins"));
     259
     260    HANDLE_SQL_EXEC_FAILURE(!m_database.executeCommand("DELETE * FROM logins"),
     261        false, "Failed to clear table logins");
     262
     263    return true;
    115264}
    116265
Note: See TracChangeset for help on using the changeset viewer.