Change ContactStorage, the schema of SelfProfile is changed.
diff --git a/src/addcontactpanel.h b/src/addcontactpanel.h
index 5b35afe..9a5fe75 100644
--- a/src/addcontactpanel.h
+++ b/src/addcontactpanel.h
@@ -41,7 +41,7 @@
 
 private:
   Ui::AddContactPanel *ui;
-  Ptr<EndorseCertificate> m_selfEndorseCertificate;
+  ndn::Ptr<EndorseCertificate> m_selfEndorseCertificate;
 };
 
 #endif // ADDCONTACTPANEL_H
diff --git a/src/contact-storage.cpp b/src/contact-storage.cpp
index 3eb8ac1..b8842d7 100644
--- a/src/contact-storage.cpp
+++ b/src/contact-storage.cpp
@@ -24,12 +24,14 @@
 const string INIT_SP_TABLE = "\
 CREATE TABLE IF NOT EXISTS                                           \n \
   SelfProfile(                                                       \n \
-      profile_id        INTEGER PRIMARY KEY AUTOINCREMENT,           \n \
+      profile_identity  BLOB NOT NULL,                               \n \
       profile_type      BLOB NOT NULL,                               \n \
-      profile_value     BLOB NOT NULL                                \n \
+      profile_value     BLOB NOT NULL,                               \n \
+                                                                     \
+      PRIMARY KEY (profile_identity, profile_type)                   \n \
   );                                                                 \n \
                                                                      \
-CREATE INDEX sp_index ON SelfProfile(profile_type);                  \n \
+CREATE INDEX sp_index ON SelfProfile(profile_identity,profile_type); \n \
 ";
 
 const string INIT_PD_TABLE = "\
@@ -153,13 +155,14 @@
 }
 
 bool
-ContactStorage::doesSelfEntryExist(const string& profileType)
+ContactStorage::doesSelfEntryExist(const Name& identity, const string& profileType)
 {
   bool result = false;
   
   sqlite3_stmt *stmt;
-  sqlite3_prepare_v2 (m_db, "SELECT count(*) FROM SelfProfile WHERE profile_type=?", -1, &stmt, 0);
+  sqlite3_prepare_v2 (m_db, "SELECT count(*) FROM SelfProfile WHERE profile_type=? and profile_identity=?", -1, &stmt, 0);
   sqlite3_bind_text(stmt, 1, profileType.c_str(), profileType.size(), SQLITE_TRANSIENT);
+  sqlite3_bind_text(stmt, 2, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
 
   int res = sqlite3_step (stmt);
     
@@ -173,69 +176,59 @@
   return result;
 }
 
-void
-ContactStorage::setSelfProfileIdentity(const Name& identity)
-{
-  string profileType("IDENTITY");
-  Blob identityBlob(identity.toUri().c_str(), identity.toUri().size());
+// void
+// ContactStorage::setSelfProfileIdentity(const Name& identity)
+// {
+//   string profileType("IDENTITY");
+//   Blob identityBlob(identity.toUri().c_str(), identity.toUri().size());
   
-  sqlite3_stmt *stmt;  
-  if(doesSelfEntryExist(profileType))
-    {
-      sqlite3_prepare_v2 (m_db, "UPDATE SelfProfile SET profile_value=? WHERE profile_type=?", -1, &stmt, 0);
-      sqlite3_bind_text(stmt, 1, identityBlob.buf(), identityBlob.size(), SQLITE_TRANSIENT);
-      sqlite3_bind_text(stmt, 2, profileType.c_str(), profileType.size(), SQLITE_TRANSIENT);
-    }
-  else
-    {
-      sqlite3_prepare_v2 (m_db, "INSERT INTO SelfProfile (profile_type, profile_value) values (?, ?)", -1, &stmt, 0);
-      sqlite3_bind_text(stmt, 1, profileType.c_str(), profileType.size(), SQLITE_TRANSIENT);
-      sqlite3_bind_text(stmt, 2, identityBlob.buf(), identityBlob.size(), SQLITE_TRANSIENT);
-    }
-  sqlite3_step (stmt);
-  sqlite3_finalize (stmt);
-}
+//   sqlite3_stmt *stmt;  
+//   if(doesSelfEntryExist(profileType))
+//     {
+//       sqlite3_prepare_v2 (m_db, "UPDATE SelfProfile SET profile_value=? WHERE profile_type=?", -1, &stmt, 0);
+//       sqlite3_bind_text(stmt, 1, identityBlob.buf(), identityBlob.size(), SQLITE_TRANSIENT);
+//       sqlite3_bind_text(stmt, 2, profileType.c_str(), profileType.size(), SQLITE_TRANSIENT);
+//     }
+//   else
+//     {
+//       sqlite3_prepare_v2 (m_db, "INSERT INTO SelfProfile (profile_type, profile_value) values (?, ?)", -1, &stmt, 0);
+//       sqlite3_bind_text(stmt, 1, profileType.c_str(), profileType.size(), SQLITE_TRANSIENT);
+//       sqlite3_bind_text(stmt, 2, identityBlob.buf(), identityBlob.size(), SQLITE_TRANSIENT);
+//     }
+//   sqlite3_step (stmt);
+//   sqlite3_finalize (stmt);
+// }
 
 void
-ContactStorage::setSelfProfileEntry(const string& profileType, const Blob& profileValue)
+ContactStorage::setSelfProfileEntry(const Name& identity, const string& profileType, const Blob& profileValue)
 {
-  if(profileType == string("IDENTITY"))
-    return;
-
   sqlite3_stmt *stmt;  
-  if(doesSelfEntryExist(profileType))
+  if(doesSelfEntryExist(identity, profileType))
     {
-      sqlite3_prepare_v2 (m_db, "UPDATE SelfProfile SET profile_value=? WHERE profile_type=?", -1, &stmt, 0);
+      sqlite3_prepare_v2 (m_db, "UPDATE SelfProfile SET profile_value=? WHERE profile_type=? and profile_identity=?", -1, &stmt, 0);
       sqlite3_bind_text(stmt, 1, profileValue.buf(), profileValue.size(), SQLITE_TRANSIENT);
       sqlite3_bind_text(stmt, 2, profileType.c_str(), profileType.size(), SQLITE_TRANSIENT);
+      sqlite3_bind_text(stmt, 3, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
     }
   else
     {
-      sqlite3_prepare_v2 (m_db, "INSERT INTO SelfProfile (profile_type, profile_value) values (?, ?)", -1, &stmt, 0);
-      sqlite3_bind_text(stmt, 1, profileType.c_str(), profileType.size(), SQLITE_TRANSIENT);
-      sqlite3_bind_text(stmt, 2, profileValue.buf(), profileValue.size(), SQLITE_TRANSIENT);
+      sqlite3_prepare_v2 (m_db, "INSERT INTO SelfProfile (profile_identity, profile_type, profile_value) values (?, ?, ?)", -1, &stmt, 0);
+      sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
+      sqlite3_bind_text(stmt, 2, profileType.c_str(), profileType.size(), SQLITE_TRANSIENT);
+      sqlite3_bind_text(stmt, 3, profileValue.buf(), profileValue.size(), SQLITE_TRANSIENT);
     }
   sqlite3_step (stmt);
   sqlite3_finalize (stmt);
 }
 
 Ptr<Profile>
-ContactStorage::getSelfProfile()
+ContactStorage::getSelfProfile(const Name& identity)
 {
-  string idString("IDENTITY");
   sqlite3_stmt *stmt;
-  sqlite3_prepare_v2(m_db, "SELECT profile_value FROM SelfProfile WHERE profile_type=?", -1, &stmt, 0);
-  sqlite3_bind_text(stmt, 1, idString.c_str(), idString.size(), SQLITE_TRANSIENT);
-
-  Name nameSpace;
-  int res = sqlite3_step (stmt);
-  if (res == SQLITE_ROW)
-    nameSpace.append(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
-
-  Ptr<Profile> profile = Ptr<Profile>(new Profile(nameSpace));
+  Ptr<Profile> profile = Ptr<Profile>(new Profile(identity));
   
-  sqlite3_prepare_v2(m_db, "SELECT profile_type, profile_value FROM SelfProfile WHERE profile_type!=?", -1, &stmt, 0);
-  sqlite3_bind_text(stmt, 1, idString.c_str(), idString.size(), SQLITE_TRANSIENT);
+  sqlite3_prepare_v2(m_db, "SELECT profile_type, profile_value FROM SelfProfile WHERE profile_identity=", -1, &stmt, 0);
+  sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
   
   while( sqlite3_step (stmt) == SQLITE_ROW)
     {
@@ -370,75 +363,55 @@
 }
 
 void
-ContactStorage::updateProfileData() const
+ContactStorage::updateProfileData(const Name& identity) const
 {
+  // 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 identity, profile_data FROM ProfileData", -1, &stmt, 0);
+  sqlite3_prepare_v2 (m_db, "SELECT profile_data FROM ProfileData where identity=?", -1, &stmt, 0);
+  sqlite3_bind_text(stmt, 1, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
 
   if(sqlite3_step (stmt) != SQLITE_ROW)
     {
       sqlite3_finalize (stmt);
-      return;
-    }
-
-  Name identity(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
-
-  Ptr<Blob> profileDataBlob = Ptr<Blob>(new Blob(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 1)), sqlite3_column_bytes (stmt, 1)));
-  Ptr<Data> plainData = Data::decodeFromWire(profileDataBlob);
-  const Blob& oldProfileBlob = plainData->content();
-  sqlite3_finalize (stmt);
-  
-  Ptr<Profile> newProfile = getSelfProfile();
-  if(NULL == newProfile)
-    return;
-  Ptr<Blob> newProfileBlob = newProfile->toDerBlob();
-  
-  if(oldProfileBlob == *newProfileBlob)
-    return;
-  
-  string idString("IDENTITY");
-  Ptr<const Blob> identityBlob = newProfile->getProfileEntry(idString);
-  Name newIdentity(string(identityBlob->buf(), identityBlob->size()));
-
-  Ptr<ProfileData> newProfileData = getSignedSelfProfileData(newIdentity, *newProfile);
-  Ptr<Blob> newProfileDataBlob = newProfileData->encodeToWire();
-
-  if(identity == newIdentity)
-    {
-      sqlite3_prepare_v2 (m_db, "UPDATE ProfileData SET profile_data=? WHERE identity=?", -1, &stmt, 0);
+      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, 2, newIdentity.toUri().c_str(), newIdentity.toUri().size(), SQLITE_TRANSIENT);
     }
   else
     {
-      sqlite3_prepare_v2 (m_db, "INSERT INTO ProfileData (identity, profile_data) values (?, ?)", -1, &stmt, 0);
-      sqlite3_bind_text(stmt, 2, newIdentity.toUri().c_str(), newIdentity.toUri().size(), SQLITE_TRANSIENT);
+      Ptr<Blob> profileDataBlob = Ptr<Blob>(new Blob(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
+      Ptr<Data> plainData = Data::decodeFromWire(profileDataBlob);
+      const Blob& oldProfileBlob = plainData->content();
+      sqlite3_finalize (stmt);
+
+      if(oldProfileBlob == *newProfileBlob)
+        return;
+
+      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);
     }
 }
 
 Ptr<Profile>
-ContactStorage::getSelfProfile() const
-{
-  string idString("IDENTITY");
-
-  sqlite3_stmt *stmt;
-  sqlite3_prepare_v2 (m_db, "SELECT profile_value FROM SelfProfile WHERE profile_type=?", -1, &stmt, 0);
-  sqlite3_bind_text(stmt, 1, idString.c_str(), idString.size(), SQLITE_TRANSIENT);
-
-  if(sqlite3_step (stmt) != SQLITE_ROW)
-    {
-      sqlite3_finalize (stmt);
-      return NULL;
-    }
-
-  Name identity(string(reinterpret_cast<const char *>(sqlite3_column_text(stmt, 0)), sqlite3_column_bytes (stmt, 0)));
-  
+ContactStorage::getSelfProfile(const Name& identity) const
+{  
   Ptr<Profile> profile = Ptr<Profile>(new Profile(identity));
-  sqlite3_finalize (stmt);
-  
-  sqlite3_prepare_v2 (m_db, "SELECT profile_type, profile_value FROM SelfProfile WHERE profile_type!=? and profile_type!=?", -1, &stmt, 0);
-  sqlite3_bind_text(stmt, 1, idString.c_str(), idString.size(), SQLITE_TRANSIENT);
+  sqlite3_stmt *stmt;
+  sqlite3_prepare_v2 (m_db, "SELECT profile_type, profile_value FROM SelfProfile WHERE profile_identity=?", -1, &stmt, 0);
+  sqlite3_bind_text (stmt, 1, identity.toUri().c_str(), identity.toUri().size(), SQLITE_TRANSIENT);
 
   while( sqlite3_step (stmt) == SQLITE_ROW)
     {
@@ -455,6 +428,9 @@
                          const Profile& profile) const
 {
   Name certificateName = m_identityManager->getDefaultCertificateNameByIdentity(identity);
+  if(0 == certificateName.size())
+    return NULL;
+
   Ptr<ProfileData> profileData = Ptr<ProfileData>(new ProfileData(identity, profile));
   m_identityManager->signByCertificate(*profileData, certificateName);
 
diff --git a/src/contact-storage.h b/src/contact-storage.h
index deb330a..62a0e8b 100644
--- a/src/contact-storage.h
+++ b/src/contact-storage.h
@@ -26,13 +26,10 @@
   ~ContactStorage() {}
 
   void
-  setSelfProfileIdentity(const ndn::Name& identity);
-
-  void
-  setSelfProfileEntry(const std::string& profileType, const ndn::Blob& profileValue);
+  setSelfProfileEntry(const ndn::Name& identity, const std::string& profileType, const ndn::Blob& profileValue);
 
   ndn::Ptr<Profile>
-  getSelfProfile();
+  getSelfProfile(const ndn::Name& identity);
 
   void
   addTrustedContact(const TrustedContact& trustedContact);
@@ -47,11 +44,11 @@
   getAllNormalContacts() const;
 
   void
-  updateProfileData() const;
+  updateProfileData(const ndn::Name& identity) const;
 
 private:
   bool
-  doesSelfEntryExist(const std::string& profileType);
+  doesSelfEntryExist(const ndn::Name& identity, const std::string& profileType);
 
   inline bool
   doesTrustedContactExist(const ndn::Name& name)
@@ -65,7 +62,7 @@
   doesContactExist(const ndn::Name& name, bool normal);
 
   ndn::Ptr<Profile>
-  getSelfProfile() const;
+  getSelfProfile(const ndn::Name& identity) const;
 
   ndn::Ptr<ProfileData>
   getSignedSelfProfileData(const ndn::Name& identity,
diff --git a/src/profileeditor.ui b/src/profileeditor.ui
index 89a0612..720d572 100644
--- a/src/profileeditor.ui
+++ b/src/profileeditor.ui
@@ -16,13 +16,40 @@
   <widget class="QWidget" name="">
    <property name="geometry">
     <rect>
-     <x>10</x>
-     <y>11</y>
+     <x>11</x>
+     <y>10</y>
      <width>381</width>
      <height>491</height>
     </rect>
    </property>
-   <layout class="QVBoxLayout" name="verticalLayout">
+   <layout class="QVBoxLayout" name="profileEditorLayout" stretch="1,20,1">
+    <item>
+     <layout class="QHBoxLayout" name="identityLayout" stretch="1,5,1">
+      <item>
+       <widget class="QLabel" name="identityLabel">
+        <property name="font">
+         <font>
+          <weight>75</weight>
+          <bold>true</bold>
+         </font>
+        </property>
+        <property name="text">
+         <string>Identity:</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QLineEdit" name="identityInput"/>
+      </item>
+      <item>
+       <widget class="QPushButton" name="getButton">
+        <property name="text">
+         <string>Get Profile</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </item>
     <item>
      <widget class="QTableView" name="profileTable">
       <attribute name="horizontalHeaderCascadingSectionResizes">