2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2013-01-23 23:23:48 +01:00
|
|
|
* Copyright (C) 2010-2013 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2013-01-24 17:47:50 +01:00
|
|
|
#include "autofill.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "qupzilla.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
#include "webpage.h"
|
|
|
|
#include "tabbedwebview.h"
|
|
|
|
#include "popupwebview.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "mainapplication.h"
|
2011-03-03 15:54:12 +01:00
|
|
|
#include "autofillnotification.h"
|
2013-01-24 17:47:50 +01:00
|
|
|
#include "pageformcompleter.h"
|
2011-12-08 21:52:03 +01:00
|
|
|
#include "databasewriter.h"
|
2012-01-11 21:58:25 +01:00
|
|
|
#include "settings.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QXmlStreamWriter>
|
|
|
|
#include <QXmlStreamReader>
|
|
|
|
#include <QWebFrame>
|
|
|
|
#include <QNetworkRequest>
|
|
|
|
|
2012-12-20 14:45:35 +01:00
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
#include <QUrlQuery>
|
|
|
|
#endif
|
|
|
|
|
2013-01-24 17:47:50 +01:00
|
|
|
AutoFill::AutoFill(QupZilla* mainClass, QObject* parent)
|
2011-12-12 21:14:43 +01:00
|
|
|
: QObject(parent)
|
2011-11-06 17:01:23 +01:00
|
|
|
, p_QupZilla(mainClass)
|
|
|
|
, m_isStoring(false)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:27:45 +01:00
|
|
|
loadSettings();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2013-01-24 17:47:50 +01:00
|
|
|
void AutoFill::loadSettings()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-11 21:58:25 +01:00
|
|
|
Settings settings;
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.beginGroup("Web-Browser-Settings");
|
2011-11-02 12:52:55 +01:00
|
|
|
m_isStoring = settings.value("SavePasswordsOnSites", true).toBool();
|
2011-03-02 16:57:41 +01:00
|
|
|
settings.endGroup();
|
|
|
|
}
|
|
|
|
|
2013-01-24 17:47:50 +01:00
|
|
|
bool AutoFill::isStored(const QUrl &url)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!isStoringEnabled(url)) {
|
2011-11-02 12:52:55 +01:00
|
|
|
return false;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-11-02 12:52:55 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QString server = url.host();
|
2012-01-21 20:27:45 +01:00
|
|
|
if (server.isEmpty()) {
|
|
|
|
server = url.toString();
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QSqlQuery query;
|
2012-08-23 15:37:43 +02:00
|
|
|
query.prepare("SELECT count(id) FROM autofill WHERE server=?");
|
|
|
|
query.addBindValue(server);
|
|
|
|
query.exec();
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
query.next();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (query.value(0).toInt() > 0) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return true;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-24 17:47:50 +01:00
|
|
|
bool AutoFill::isStoringEnabled(const QUrl &url)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!m_isStoring) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return false;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-11-02 12:52:55 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QString server = url.host();
|
2012-01-21 20:27:45 +01:00
|
|
|
if (server.isEmpty()) {
|
|
|
|
server = url.toString();
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QSqlQuery query;
|
2012-08-23 15:37:43 +02:00
|
|
|
query.prepare("SELECT count(id) FROM autofill_exceptions WHERE server=?");
|
|
|
|
query.addBindValue(server);
|
|
|
|
query.exec();
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
query.next();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (query.value(0).toInt() > 0) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return false;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-08 13:02:53 +01:00
|
|
|
void AutoFill::blockStoringforUrl(const QUrl &url)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
QString server = url.host();
|
2012-01-21 20:27:45 +01:00
|
|
|
if (server.isEmpty()) {
|
|
|
|
server = url.toString();
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QSqlQuery query;
|
2011-12-08 21:52:03 +01:00
|
|
|
query.prepare("INSERT INTO autofill_exceptions (server) VALUES (?)");
|
|
|
|
query.addBindValue(server);
|
|
|
|
mApp->dbWriter()->executeQuery(query);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2013-02-08 15:07:56 +01:00
|
|
|
AutoFillData AutoFill::getFirstFormData(const QUrl &url)
|
|
|
|
{
|
2013-02-26 12:56:11 +01:00
|
|
|
const QVector<AutoFillData> &list = getFormData(url, 1);
|
2013-02-08 15:07:56 +01:00
|
|
|
|
|
|
|
if (list.isEmpty()) {
|
|
|
|
AutoFillData data;
|
|
|
|
data.id = -1;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return list.first();
|
|
|
|
}
|
|
|
|
|
2013-02-26 12:56:11 +01:00
|
|
|
QVector<AutoFillData> AutoFill::getFormData(const QUrl &url, int limit)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2013-02-26 12:56:11 +01:00
|
|
|
QVector<AutoFillData> list;
|
2013-02-08 13:02:53 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QString server = url.host();
|
2012-01-21 20:27:45 +01:00
|
|
|
if (server.isEmpty()) {
|
|
|
|
server = url.toString();
|
|
|
|
}
|
|
|
|
|
2013-02-08 15:07:56 +01:00
|
|
|
QString queryString = "SELECT id, username, password, data FROM autofill "
|
|
|
|
"WHERE server=? ORDER BY last_used DESC";
|
|
|
|
if (limit > 0) {
|
|
|
|
queryString.append(QLatin1String(" LIMIT ?"));
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QSqlQuery query;
|
2013-02-08 15:07:56 +01:00
|
|
|
query.prepare(queryString);
|
2012-08-23 15:37:43 +02:00
|
|
|
query.addBindValue(server);
|
2013-02-08 15:07:56 +01:00
|
|
|
|
|
|
|
if (limit > 0) {
|
|
|
|
query.addBindValue(limit);
|
|
|
|
}
|
|
|
|
|
2012-08-23 15:37:43 +02:00
|
|
|
query.exec();
|
|
|
|
|
2013-02-08 13:02:53 +01:00
|
|
|
while (query.next()) {
|
|
|
|
AutoFillData data;
|
|
|
|
data.id = query.value(0).toInt();
|
|
|
|
data.username = query.value(1).toString();
|
|
|
|
data.password = query.value(2).toString();
|
|
|
|
data.postData = query.value(3).toByteArray();
|
|
|
|
|
|
|
|
list.append(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
2013-02-08 15:07:56 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2013-02-08 13:02:53 +01:00
|
|
|
void AutoFill::updateLastUsed(int id)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2013-02-08 13:02:53 +01:00
|
|
|
if (id < 0) {
|
|
|
|
return;
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QSqlQuery query;
|
2013-02-08 13:02:53 +01:00
|
|
|
query.prepare("UPDATE autofill SET last_used=strftime('%s', 'now') WHERE id=?");
|
|
|
|
query.addBindValue(id);
|
2012-08-23 15:37:43 +02:00
|
|
|
query.exec();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///HTTP Authorization
|
2013-01-24 17:47:50 +01:00
|
|
|
void AutoFill::addEntry(const QUrl &url, const QString &name, const QString &pass)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
QSqlQuery query;
|
2013-02-04 12:11:27 +01:00
|
|
|
QString server = url.host();
|
|
|
|
if (server.isEmpty()) {
|
|
|
|
server = url.toString();
|
|
|
|
}
|
|
|
|
|
2013-02-08 18:44:26 +01:00
|
|
|
// Multiple-usernames for HTTP Authorization not supported
|
2012-08-23 15:37:43 +02:00
|
|
|
query.prepare("SELECT username FROM autofill WHERE server=?");
|
2013-02-04 12:11:27 +01:00
|
|
|
query.addBindValue(server);
|
2012-08-23 15:37:43 +02:00
|
|
|
query.exec();
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (query.next()) {
|
2011-12-08 21:52:03 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-01-21 20:27:45 +01:00
|
|
|
|
2013-02-08 13:02:53 +01:00
|
|
|
query.prepare("INSERT INTO autofill (server, username, password, last_used) "
|
|
|
|
"VALUES (?,?,?,strftime('%s', 'now'))");
|
2012-01-21 20:27:45 +01:00
|
|
|
query.bindValue(0, server);
|
2011-03-02 16:57:41 +01:00
|
|
|
query.bindValue(1, name);
|
|
|
|
query.bindValue(2, pass);
|
2011-12-08 21:52:03 +01:00
|
|
|
mApp->dbWriter()->executeQuery(query);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///WEB Form
|
2013-01-24 17:47:50 +01:00
|
|
|
void AutoFill::addEntry(const QUrl &url, const PageFormData &formData)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2013-02-04 12:11:27 +01:00
|
|
|
QString server = url.host();
|
|
|
|
if (server.isEmpty()) {
|
|
|
|
server = url.toString();
|
|
|
|
}
|
|
|
|
|
2013-02-08 18:44:26 +01:00
|
|
|
QSqlQuery query;
|
2013-02-08 13:02:53 +01:00
|
|
|
query.prepare("INSERT INTO autofill (server, data, username, password, last_used) "
|
|
|
|
"VALUES (?,?,?,?,strftime('%s', 'now'))");
|
2012-01-21 20:27:45 +01:00
|
|
|
query.bindValue(0, server);
|
2013-01-24 17:47:50 +01:00
|
|
|
query.bindValue(1, formData.postData);
|
|
|
|
query.bindValue(2, formData.username);
|
|
|
|
query.bindValue(3, formData.password);
|
2011-12-08 21:52:03 +01:00
|
|
|
mApp->dbWriter()->executeQuery(query);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2013-02-04 12:11:27 +01:00
|
|
|
void AutoFill::updateEntry(const QUrl &url, const QString &name, const QString &pass)
|
2013-01-31 23:11:57 +01:00
|
|
|
{
|
|
|
|
QSqlQuery query;
|
2013-02-04 12:11:27 +01:00
|
|
|
QString server = url.host();
|
|
|
|
if (server.isEmpty()) {
|
|
|
|
server = url.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
query.prepare("SELECT username FROM autofill WHERE server=?");
|
|
|
|
query.addBindValue(server);
|
2013-01-31 23:11:57 +01:00
|
|
|
query.exec();
|
|
|
|
|
|
|
|
if (!query.next()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-04 12:11:27 +01:00
|
|
|
query.prepare("UPDATE autofill SET username=?, password=? WHERE server=?");
|
|
|
|
query.bindValue(0, name);
|
|
|
|
query.bindValue(1, pass);
|
|
|
|
query.bindValue(2, server);
|
|
|
|
mApp->dbWriter()->executeQuery(query);
|
|
|
|
}
|
|
|
|
|
2013-02-08 15:07:56 +01:00
|
|
|
void AutoFill::updateEntry(const PageFormData &formData, const AutoFillData &updateData)
|
2013-02-04 12:11:27 +01:00
|
|
|
{
|
|
|
|
QSqlQuery query;
|
2013-02-08 15:07:56 +01:00
|
|
|
query.prepare("UPDATE autofill SET data=?, username=?, password=? WHERE id=?");
|
2013-01-31 23:11:57 +01:00
|
|
|
query.addBindValue(formData.postData);
|
|
|
|
query.addBindValue(formData.username);
|
|
|
|
query.addBindValue(formData.password);
|
2013-02-08 15:07:56 +01:00
|
|
|
query.addBindValue(updateData.id);
|
|
|
|
|
2013-01-31 23:11:57 +01:00
|
|
|
mApp->dbWriter()->executeQuery(query);
|
|
|
|
}
|
|
|
|
|
2013-02-25 15:03:53 +01:00
|
|
|
// If password was filled in the page, returns all saved passwords on this page
|
2013-02-26 12:56:11 +01:00
|
|
|
QVector<AutoFillData> AutoFill::completePage(WebPage* page)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2013-02-25 15:03:53 +01:00
|
|
|
bool completed = false;
|
2013-02-26 12:56:11 +01:00
|
|
|
QVector<AutoFillData> list;
|
2013-02-08 18:44:26 +01:00
|
|
|
|
2012-01-21 20:27:45 +01:00
|
|
|
if (!page) {
|
2013-02-08 18:44:26 +01:00
|
|
|
return list;
|
2012-01-21 20:27:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QUrl pageUrl = page->url();
|
|
|
|
if (!isStored(pageUrl)) {
|
2013-02-08 18:44:26 +01:00
|
|
|
return list;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2013-02-08 18:44:26 +01:00
|
|
|
list = getFormData(pageUrl);
|
|
|
|
|
|
|
|
if (!list.isEmpty()) {
|
|
|
|
const AutoFillData data = getFirstFormData(pageUrl);
|
2012-01-21 20:27:45 +01:00
|
|
|
|
2013-02-08 15:07:56 +01:00
|
|
|
PageFormCompleter completer(page);
|
2013-02-25 15:03:53 +01:00
|
|
|
completed = completer.completePage(data.postData);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!completed) {
|
|
|
|
list.clear();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2013-02-08 18:44:26 +01:00
|
|
|
|
|
|
|
return list;
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2013-01-24 00:00:57 +01:00
|
|
|
|
2013-01-24 17:47:50 +01:00
|
|
|
void AutoFill::post(const QNetworkRequest &request, const QByteArray &outgoingData)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-07-10 22:15:07 +02:00
|
|
|
// Don't save in private browsing
|
2012-06-26 11:49:39 +02:00
|
|
|
if (mApp->isPrivateSession()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-11-05 15:04:29 +01:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
|
2012-01-21 20:27:45 +01:00
|
|
|
WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
|
2012-04-02 19:33:05 +02:00
|
|
|
if (!WebPage::isPointerSafeToUse(webPage)) {
|
2012-01-21 20:27:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
WebView* webView = qobject_cast<WebView*>(webPage->view());
|
|
|
|
if (!webView) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2013-01-31 23:11:57 +01:00
|
|
|
const QUrl &siteUrl = webPage->url();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2013-01-31 23:11:57 +01:00
|
|
|
if (!isStoringEnabled(siteUrl)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2013-01-31 23:11:57 +01:00
|
|
|
PageFormCompleter completer(webPage);
|
2013-02-08 12:10:12 +01:00
|
|
|
const PageFormData formData = completer.extractFormData(outgoingData);
|
2011-05-05 16:27:48 +02:00
|
|
|
|
2013-01-31 23:11:57 +01:00
|
|
|
if (!formData.found) {
|
2011-11-20 17:09:10 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-08 15:07:56 +01:00
|
|
|
AutoFillData updateData = { -1, QString(), QString(), QByteArray() };
|
|
|
|
|
2013-01-31 23:11:57 +01:00
|
|
|
if (isStored(siteUrl)) {
|
2013-02-26 12:56:11 +01:00
|
|
|
const QVector<AutoFillData> &list = getFormData(siteUrl);
|
2013-01-31 23:11:57 +01:00
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const AutoFillData &data, list) {
|
2013-02-08 15:07:56 +01:00
|
|
|
if (data.username == formData.username) {
|
|
|
|
updateLastUsed(data.id);
|
2013-01-31 23:11:57 +01:00
|
|
|
|
2013-02-08 15:07:56 +01:00
|
|
|
if (data.password == formData.password) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateData = data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-31 23:11:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AutoFillNotification* aWidget = new AutoFillNotification(siteUrl, formData, updateData);
|
2011-03-02 16:57:41 +01:00
|
|
|
webView->addNotification(aWidget);
|
|
|
|
}
|
2011-11-20 17:09:10 +01:00
|
|
|
|
2013-01-24 17:47:50 +01:00
|
|
|
QByteArray AutoFill::exportPasswords()
|
2012-02-06 20:10:50 +01:00
|
|
|
{
|
|
|
|
QByteArray output;
|
|
|
|
|
|
|
|
QXmlStreamWriter stream(&output);
|
|
|
|
stream.setCodec("UTF-8");
|
|
|
|
stream.setAutoFormatting(true);
|
|
|
|
|
|
|
|
stream.writeStartDocument();
|
|
|
|
stream.writeStartElement("passwords");
|
|
|
|
stream.writeAttribute("version", "1.0");
|
|
|
|
|
|
|
|
QSqlQuery query;
|
|
|
|
query.exec("SELECT server, username, password, data FROM autofill");
|
|
|
|
while (query.next()) {
|
|
|
|
stream.writeStartElement("entry");
|
|
|
|
stream.writeTextElement("server", query.value(0).toString());
|
|
|
|
stream.writeTextElement("username", query.value(1).toString());
|
|
|
|
stream.writeTextElement("password", query.value(2).toString());
|
|
|
|
stream.writeTextElement("data", query.value(3).toString());
|
|
|
|
stream.writeEndElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
query.exec("SELECT server FROM autofill_exceptions");
|
|
|
|
while (query.next()) {
|
|
|
|
stream.writeStartElement("exception");
|
|
|
|
stream.writeTextElement("server", query.value(0).toString());
|
|
|
|
stream.writeEndElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
stream.writeEndElement();
|
|
|
|
stream.writeEndDocument();
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2013-01-24 17:47:50 +01:00
|
|
|
bool AutoFill::importPasswords(const QByteArray &data)
|
2012-02-06 20:10:50 +01:00
|
|
|
{
|
2012-03-23 14:23:54 +01:00
|
|
|
QSqlDatabase db = QSqlDatabase::database();
|
|
|
|
db.transaction();
|
|
|
|
|
2012-02-06 20:10:50 +01:00
|
|
|
QXmlStreamReader xml(data);
|
|
|
|
|
|
|
|
while (!xml.atEnd()) {
|
|
|
|
xml.readNext();
|
|
|
|
|
|
|
|
if (xml.isStartElement()) {
|
2012-09-04 12:42:45 +02:00
|
|
|
if (xml.name() == QLatin1String("entry")) {
|
2012-02-06 20:10:50 +01:00
|
|
|
QString server;
|
|
|
|
QString username;
|
|
|
|
QString password;
|
|
|
|
QByteArray data;
|
|
|
|
|
|
|
|
while (xml.readNext()) {
|
2012-09-04 12:42:45 +02:00
|
|
|
if (xml.name() == QLatin1String("server")) {
|
2012-02-06 20:10:50 +01:00
|
|
|
server = xml.readElementText();
|
|
|
|
}
|
2012-09-04 12:42:45 +02:00
|
|
|
else if (xml.name() == QLatin1String("username")) {
|
2012-02-06 20:10:50 +01:00
|
|
|
username = xml.readElementText();
|
|
|
|
}
|
2012-09-04 12:42:45 +02:00
|
|
|
else if (xml.name() == QLatin1String("password")) {
|
2012-02-06 20:10:50 +01:00
|
|
|
password = xml.readElementText();
|
|
|
|
}
|
2012-09-04 12:42:45 +02:00
|
|
|
else if (xml.name() == QLatin1String("data")) {
|
2012-02-06 20:10:50 +01:00
|
|
|
data = xml.readElementText().toUtf8();
|
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (xml.isEndElement() && xml.name() == QLatin1String("entry")) {
|
2012-02-06 20:10:50 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!server.isEmpty() && !password.isEmpty() && !data.isEmpty()) {
|
|
|
|
QSqlQuery query;
|
|
|
|
query.prepare("SELECT id FROM autofill WHERE server=? AND password=? AND data=?");
|
|
|
|
query.addBindValue(server);
|
|
|
|
query.addBindValue(password);
|
|
|
|
query.addBindValue(data);
|
|
|
|
query.exec();
|
|
|
|
|
|
|
|
if (!query.next()) {
|
|
|
|
query.prepare("INSERT INTO autofill (server, username, password, data) VALUES (?,?,?,?)");
|
|
|
|
query.addBindValue(server);
|
|
|
|
query.addBindValue(username);
|
|
|
|
query.addBindValue(password);
|
|
|
|
query.addBindValue(data);
|
|
|
|
query.exec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-04 12:42:45 +02:00
|
|
|
else if (xml.name() == QLatin1String("exception")) {
|
2012-02-06 20:10:50 +01:00
|
|
|
QString server;
|
|
|
|
|
|
|
|
while (xml.readNext()) {
|
2012-09-04 12:42:45 +02:00
|
|
|
if (xml.name() == QLatin1String("server")) {
|
2012-02-06 20:10:50 +01:00
|
|
|
server = xml.readElementText();
|
|
|
|
}
|
|
|
|
|
2012-09-04 12:42:45 +02:00
|
|
|
if (xml.isEndElement() && xml.name() == QLatin1String("exception")) {
|
2012-02-06 20:10:50 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!server.isEmpty()) {
|
|
|
|
QSqlQuery query;
|
|
|
|
query.prepare("SELECT id FROM autofill_exceptions WHERE server=?");
|
|
|
|
query.addBindValue(server);
|
|
|
|
query.exec();
|
|
|
|
|
|
|
|
if (!query.next()) {
|
|
|
|
query.prepare("INSERT INTO autofill_exceptions (server) VALUES (?)");
|
|
|
|
query.addBindValue(server);
|
|
|
|
query.exec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-23 14:23:54 +01:00
|
|
|
db.commit();
|
2012-02-06 20:10:50 +01:00
|
|
|
|
2012-03-23 14:23:54 +01:00
|
|
|
return !xml.hasError();
|
2012-02-06 20:10:50 +01:00
|
|
|
}
|