Commit b14f9e69 authored by atraczyk's avatar atraczyk Committed by Adrien Béraud

vcard: fix serialization/deserialization of vcard

- Fixes regression in parseFromString causing poor
  deserialization of the vcard's image.
- Fixes crash on empty trustrequest vcard.
- Fixes typo in vcard image serialization attribute string.
- Prevents connectivity changes from triggering ring API calls
  before the daemon has started.

Change-Id: I72fb9aee5ebedab9b878c04f9617cb7bd7728023
parent b03802b5
......@@ -234,7 +234,9 @@ RingD::parseAccountDetails(const AccountDetailsBlob& allAccountDetails)
void
RingD::connectivityChanged()
{
DRing::connectivityChanged();
if (daemonRunning_) {
DRing::connectivityChanged();
}
}
void
......@@ -1206,11 +1208,14 @@ RingD::registerCallbacks()
// Otherwise, if it is not already been trusted, we can ignore it completely.
if (contact) {
if (contact->_trustStatus == TrustStatus::CONTACT_REQUEST_SENT) {
// get the vcard first
auto vcard = contact->getVCard();
auto parsedPayload = VCardUtils::parseContactRequestPayload(payloadString);
vcard->setData(parsedPayload.at("VCARD"));
vcard->completeReception();
if (!payloadString.empty()) {
auto vcard = contact->getVCard();
auto parsedPayload = VCardUtils::parseContactRequestPayload(payloadString);
vcard->setData(parsedPayload.at("VCARD"));
vcard->completeReception();
contact->_displayName = Utils::toPlatformString(vcard->getPart("FN"));
}
DRing::acceptTrustRequest(account_id, from);
MSG_("Auto accepted IncomingTrustRequest");
......@@ -1224,33 +1229,38 @@ RingD::registerCallbacks()
else {
// No contact found, so add a new contact with the INCOMNG_CONTACT_REQUEST trust status flag
contact = contactListModel->addNewContact("", fromP, TrustStatus::INCOMING_CONTACT_REQUEST, false);
}
// The visible ring id will potentially be replaced by a username after a lookup
RingD::instance->lookUpAddress(account_id, Utils::toPlatformString(from));
// The visible ring id will potentially be replaced by a username after a lookup
RingD::instance->lookUpAddress(account_id, Utils::toPlatformString(from));
auto vcard = contact->getVCard();
auto parsedPayload = VCardUtils::parseContactRequestPayload(payloadString);
vcard->setData(parsedPayload.at("VCARD"));
vcard->completeReception();
if (!contact)
return;
// The name is the ring id for now
contact->_name = Utils::toPlatformString(from);
contact->_displayName = Utils::toPlatformString(vcard->getPart("FN"));
auto vcard = contact->getVCard();
if (!payloadString.empty()) {
auto parsedPayload = VCardUtils::parseContactRequestPayload(payloadString);
vcard->setData(parsedPayload.at("VCARD"));
vcard->completeReception();
contact->_displayName = Utils::toPlatformString(vcard->getPart("FN"));
}
contactListModel->saveContactsToFile();
AccountsViewModel::instance->raiseUnreadContactRequest();
// The name is the ring id for now
contact->_name = Utils::toPlatformString(from);
SmartPanelItemsViewModel::instance->refreshFilteredItemsList();
SmartPanelItemsViewModel::instance->update(ViewModel::NotifyStrings::notifySmartPanelItem);
contactListModel->saveContactsToFile();
AccountsViewModel::instance->raiseUnreadContactRequest();
SmartPanelItemsViewModel::instance->refreshFilteredItemsList();
SmartPanelItemsViewModel::instance->update(ViewModel::NotifyStrings::notifySmartPanelItem);
// Add a corresponding contact request control item to the list.
auto newContactRequest = ref new ContactRequestItem();
newContactRequest->_contact = contact;
ContactRequestItemsViewModel::instance->itemsList->InsertAt(0, newContactRequest);
// Add a corresponding contact request control item to the list.
auto newContactRequest = ref new ContactRequestItem();
newContactRequest->_contact = contact;
ContactRequestItemsViewModel::instance->itemsList->InsertAt(0, newContactRequest);
ContactRequestItemsViewModel::instance->refreshFilteredItemsList();
ContactRequestItemsViewModel::instance->update(ViewModel::NotifyStrings::notifyContactRequestItem);
ContactRequestItemsViewModel::instance->refreshFilteredItemsList();
ContactRequestItemsViewModel::instance->update(ViewModel::NotifyStrings::notifyContactRequestItem);
}
}
}));
}),
......@@ -1504,12 +1514,12 @@ RingD::startDaemon()
IAsyncAction^ action = ThreadPool::RunAsync(ref new WorkItemHandler([=](IAsyncAction^ spAction)
{
CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal,
ref new DispatchedHandler([=]() {
if (!isInWizard) {
setOverlayStatusText("Loading from config...", "#ff000000");
}
}));
if (!isInWizard) {
CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(CoreDispatcherPriority::Normal,
ref new DispatchedHandler([=]() {
setOverlayStatusText("Loading from config...", "#ff000000");
}));
}
daemonRunning_ = DRing::start();
......
......@@ -136,11 +136,6 @@ VCard::parseFromString()
break;
}
while (std::getline(_data, _line)) {
if (_line.find("PHOTO;") != std::string::npos)
break;
}
size_t pos = _line.find("PNG:");
if (pos == std::string::npos) {
pos = _line.find("JPEG:");
......
......@@ -43,7 +43,7 @@ struct Symbols {
constexpr static const char* OF_TOKEN = "of=";
constexpr static const char* SEPERATOR1 = ";";
constexpr static const char* SEPERATOR2 = ":";
constexpr static const char* PHOTO_ENC = "ENDCODING=BASE64";
constexpr static const char* PHOTO_ENC = "ENCODING=BASE64";
constexpr static const char* PHOTO_TYPE = "TYPE=PNG";
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment