Profile signing is working
diff --git a/src/contact-storage.cpp b/src/contact-storage.cpp
index b8842d7..8026644 100644
--- a/src/contact-storage.cpp
+++ b/src/contact-storage.cpp
@@ -365,18 +365,13 @@
void
ContactStorage::updateProfileData(const Name& identity) const
{
+ _LOG_DEBUG("Enter updateProfileData!");
// Get current profile;
Ptr<Profile> newProfile = getSelfProfile(identity);
if(NULL == newProfile)
return;
Ptr<Blob> newProfileBlob = newProfile->toDerBlob();
- Ptr<ProfileData> newProfileData = getSignedSelfProfileData(identity, *newProfile);
- if(NULL != newProfileData)
- return;
- Ptr<Blob> newProfileDataBlob = newProfileData->encodeToWire();
-
-
// Check if profile exists
sqlite3_stmt *stmt;
sqlite3_prepare_v2 (m_db, "SELECT profile_data FROM ProfileData where identity=?", -1, &stmt, 0);
@@ -385,9 +380,19 @@
if(sqlite3_step (stmt) != SQLITE_ROW)
{
sqlite3_finalize (stmt);
+
+ Ptr<ProfileData> newProfileData = getSignedSelfProfileData(identity, *newProfile);
+ _LOG_DEBUG("Signing DONE!");
+ if(NULL == newProfileData)
+ return;
+ Ptr<Blob> newProfileDataBlob = newProfileData->encodeToWire();
+
+ _LOG_DEBUG("Before Inserting!");
+
sqlite3_prepare_v2 (m_db, "INSERT INTO ProfileData (identity, profile_data) values (?, ?)", -1, &stmt, 0);
- sqlite3_bind_text(stmt, 2, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
- sqlite3_bind_text(stmt, 1, newProfileDataBlob->buf(), newProfileDataBlob->size(), SQLITE_TRANSIENT);
+ sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
+ sqlite3_bind_text(stmt, 2, newProfileDataBlob->buf(), newProfileDataBlob->size(), SQLITE_TRANSIENT);
+ sqlite3_step(stmt);
}
else
{
@@ -399,9 +404,18 @@
if(oldProfileBlob == *newProfileBlob)
return;
+ Ptr<ProfileData> newProfileData = getSignedSelfProfileData(identity, *newProfile);
+ _LOG_DEBUG("Signing DONE!");
+ if(NULL == newProfileData)
+ return;
+ Ptr<Blob> newProfileDataBlob = newProfileData->encodeToWire();
+
+ _LOG_DEBUG("Before Updating!");
+
sqlite3_prepare_v2 (m_db, "UPDATE ProfileData SET profile_data=? WHERE identity=?", -1, &stmt, 0);
sqlite3_bind_text(stmt, 1, newProfileDataBlob->buf(), newProfileDataBlob->size(), SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 2, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
+ sqlite3_step(stmt);
}
}
@@ -432,6 +446,8 @@
return NULL;
Ptr<ProfileData> profileData = Ptr<ProfileData>(new ProfileData(identity, profile));
+ _LOG_DEBUG("Get ProfileData, size: " << profileData->content().size());
+ _LOG_DEBUG("Get SigningCert, name: " << certificateName.toUri());
m_identityManager->signByCertificate(*profileData, certificateName);
return profileData;
diff --git a/src/contact-storage.h b/src/contact-storage.h
index 62a0e8b..5b87146 100644
--- a/src/contact-storage.h
+++ b/src/contact-storage.h
@@ -45,7 +45,11 @@
void
updateProfileData(const ndn::Name& identity) const;
-
+
+ inline ndn::Ptr<ndn::security::IdentityManager>
+ getIdentityManager()
+ { return m_identityManager; }
+
private:
bool
doesSelfEntryExist(const ndn::Name& identity, const std::string& profileType);
diff --git a/src/contactpanel.cpp b/src/contactpanel.cpp
index f103100..985d0a8 100644
--- a/src/contactpanel.cpp
+++ b/src/contactpanel.cpp
@@ -33,7 +33,6 @@
, ui(new Ui::ContactPanel)
, m_contactStorage(contactStorage)
, m_contactListModel(new QStringListModel)
- , m_profileEditor(new ProfileEditor(m_contactStorage))
, m_addContactPanel(new AddContactPanel())
{
@@ -45,6 +44,8 @@
db.setDatabaseName(path);
bool ok = db.open();
+ m_profileEditor = new ProfileEditor(m_contactStorage);
+
QStringList contactNameList;
contactNameList << "Alex" << "Wentao" << "Yingdi";
diff --git a/src/contactpanel.ui b/src/contactpanel.ui
index d2f156e..442fdae 100644
--- a/src/contactpanel.ui
+++ b/src/contactpanel.ui
@@ -56,7 +56,7 @@
<item>
<widget class="QTabWidget" name="ContactInfo">
<property name="currentIndex">
- <number>2</number>
+ <number>0</number>
</property>
<widget class="QWidget" name="General">
<attribute name="title">
@@ -179,7 +179,7 @@
<attribute name="title">
<string>Trust Scope</string>
</attribute>
- <widget class="QWidget" name="">
+ <widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>20</x>
diff --git a/src/profileeditor.cpp b/src/profileeditor.cpp
index 9b75f50..14eeff4 100644
--- a/src/profileeditor.cpp
+++ b/src/profileeditor.cpp
@@ -23,31 +23,28 @@
INIT_LOGGER("ProfileEditor");
-ProfileEditor::ProfileEditor(Ptr<ContactStorage> contactStorage, QWidget *parent)
+ProfileEditor::ProfileEditor(Ptr<ContactStorage> contactStorage,
+ QWidget *parent)
: QDialog(parent)
, ui(new Ui::ProfileEditor)
, m_tableModel(new QSqlTableModel())
, m_contactStorage(contactStorage)
{
- ui->setupUi(this);
+ ui->setupUi(this);
+
+ Name defaultIdentity = contactStorage->getIdentityManager()->getDefaultIdentity();
+ ui->identityInput->setText(defaultIdentity.toUri().c_str());
- connect(ui->addRowButton, SIGNAL(clicked()),
- this, SLOT(onAddClicked()));
- connect(ui->deleteRowButton, SIGNAL(clicked()),
- this, SLOT(onDeleteClicked()));
- connect(ui->okButton, SIGNAL(clicked()),
- this, SLOT(onOkClicked()));
-
- m_tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
- m_tableModel->setTable("SelfProfile");
- m_tableModel->select();
- m_tableModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Index"));
- m_tableModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Type"));
- m_tableModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Value"));
+ connect(ui->addRowButton, SIGNAL(clicked()),
+ this, SLOT(onAddClicked()));
+ connect(ui->deleteRowButton, SIGNAL(clicked()),
+ this, SLOT(onDeleteClicked()));
+ connect(ui->okButton, SIGNAL(clicked()),
+ this, SLOT(onOkClicked()));
+ connect(ui->getButton, SIGNAL(clicked()),
+ this, SLOT(onGetClicked()));
- ui->profileTable->setModel(m_tableModel);
- ui->profileTable->setColumnHidden(0, true);
- ui->profileTable->show();
+
}
@@ -61,19 +58,12 @@
ProfileEditor::onAddClicked()
{
int rowCount = m_tableModel->rowCount();
-
- // QSqlRecord record;
- // QSqlField typeField("profile_type", QVariant::String);
- // QSqlField valueField("profile_value", QVariant::String);
- // record.append(typeField);
- // record.append(valueField);
- // record.setValue("profile_type", QString("N/A"));
- // record.setValue("profile_value", QString("N/A"));
-
- // bool res = m_tableModel->insertRecord(-1, record);
-
- // res = m_tableModel->submitAll();
+ QSqlRecord record;
+ QSqlField identityField("profile_identity", QVariant::String);
+ record.append(identityField);
+ record.setValue("profile_identity", QString(m_currentIdentity.toUri().c_str()));
m_tableModel->insertRow(rowCount);
+ m_tableModel->setRecord(rowCount, record);
}
void
@@ -84,10 +74,8 @@
int i = indexList.size() - 1;
for(; i >= 0; i--)
- {
- if(0 != indexList[i].row())
- m_tableModel->removeRow(indexList[i].row());
- }
+ m_tableModel->removeRow(indexList[i].row());
+
m_tableModel->submitAll();
}
@@ -95,9 +83,31 @@
ProfileEditor::onOkClicked()
{
m_tableModel->submitAll();
+ m_contactStorage->updateProfileData(m_currentIdentity);
this->hide();
}
+void
+ProfileEditor::onGetClicked()
+{
+ QString inputIdentity = ui->identityInput->text();
+ m_currentIdentity = Name(inputIdentity.toUtf8().constData());
+ string filter("profile_identity = '");
+ filter.append(m_currentIdentity.toUri()).append("'");
+
+ m_tableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
+ m_tableModel->setTable("SelfProfile");
+ m_tableModel->setFilter(filter.c_str());
+ m_tableModel->select();
+ m_tableModel->setHeaderData(0, Qt::Horizontal, QObject::tr("Identity"));
+ m_tableModel->setHeaderData(1, Qt::Horizontal, QObject::tr("Type"));
+ m_tableModel->setHeaderData(2, Qt::Horizontal, QObject::tr("Value"));
+
+ ui->profileTable->setModel(m_tableModel);
+ ui->profileTable->setColumnHidden(0, true);
+ ui->profileTable->show();
+}
+
#if WAF
#include "profileeditor.moc"
#include "profileeditor.cpp.moc"
diff --git a/src/profileeditor.h b/src/profileeditor.h
index 4bb073b..78d949d 100644
--- a/src/profileeditor.h
+++ b/src/profileeditor.h
@@ -27,7 +27,8 @@
Q_OBJECT
public:
- explicit ProfileEditor(ndn::Ptr<ContactStorage> contactStorage, QWidget *parent = 0);
+ explicit ProfileEditor(ndn::Ptr<ContactStorage> contactStorage,
+ QWidget *parent = 0);
~ProfileEditor();
@@ -41,11 +42,16 @@
void
onOkClicked();
+ void
+ onGetClicked();
+
private:
Ui::ProfileEditor *ui;
QSqlTableModel* m_tableModel;
ndn::Ptr<ContactStorage> m_contactStorage;
+ ndn::Name m_defaultIdentity;
+ ndn::Name m_currentIdentity;
};
#endif // PROFILEEDITOR_H
diff --git a/src/profileeditor.ui b/src/profileeditor.ui
index 720d572..f3bdafd 100644
--- a/src/profileeditor.ui
+++ b/src/profileeditor.ui
@@ -46,6 +46,9 @@
<property name="text">
<string>Get Profile</string>
</property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
</widget>
</item>
</layout>
@@ -76,6 +79,9 @@
<property name="text">
<string>Add</string>
</property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
</widget>
</item>
<item>
@@ -83,6 +89,9 @@
<property name="text">
<string>Delete</string>
</property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
</widget>
</item>
<item>
@@ -90,6 +99,9 @@
<property name="text">
<string>OK</string>
</property>
+ <property name="autoDefault">
+ <bool>false</bool>
+ </property>
</widget>
</item>
</layout>