Skip to content
Snippets Groups Projects
Commit e2b201b0 authored by Andreas Traczyk's avatar Andreas Traczyk Committed by Andreas Traczyk
Browse files

vcard: fix vcard deserialization and remove appx files

Change-Id: I52650075971a653dbc8adcbfdc0e2406eb2efdc6
parent 3783b3f5
Branches
No related tags found
No related merge requests found
...@@ -251,3 +251,6 @@ _Pvt_Extensions ...@@ -251,3 +251,6 @@ _Pvt_Extensions
!config.h !config.h
Generated\ Files/ Generated\ Files/
# Visual Studio generated app install files
.appx
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" IgnorableNamespaces="uap uap3 mp"> <Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" IgnorableNamespaces="uap uap3 mp">
<Identity Name="Savoir-faireLinux.GNURing" Publisher="CN=8121A5F7-3CA1-4CAA-92B2-4F595B011941" Version="0.0.1.0" /> <Identity Name="Savoir-faireLinux.GNURing" Publisher="CN=8121A5F7-3CA1-4CAA-92B2-4F595B011941" Version="1.0.1.0" />
<mp:PhoneIdentity PhoneProductId="2385953f-9019-423d-aa82-d1bbacfa258b" PhonePublisherId="00000000-0000-0000-0000-000000000000" /> <mp:PhoneIdentity PhoneProductId="2385953f-9019-423d-aa82-d1bbacfa258b" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
<Properties> <Properties>
<DisplayName>GNU Ring</DisplayName> <DisplayName>GNU Ring</DisplayName>
......
...@@ -99,45 +99,48 @@ VCard::receiveChunk(const std::string& args, const std::string& payload) ...@@ -99,45 +99,48 @@ VCard::receiveChunk(const std::string& args, const std::string& payload)
return VCARD_INCOMPLETE; return VCARD_INCOMPLETE;
} }
std::string
getVCardValue(std::string data, std::string key)
{
std::string value;
std::stringstream _data(data);
std::string _line;
while (std::getline(_data, _line)) {
if (_line.find(key) != std::string::npos) {
value = _line.substr(key.length());
break;
}
}
value.erase(std::remove(value.begin(), value.end(), '\r'), value.end());
return value;
}
int int
VCard::parseFromString() VCard::parseFromString()
{ {
std::stringstream _data(m_data); std::stringstream _data(m_data);
std::string _line; std::string _line;
// save hash of old photo
auto md5_0 = Utils::computeMD5(Utils::toPlatformString(m_mParts[Property::PHOTO]));
m_mParts.clear(); m_mParts.clear();
bool foundUID = false; m_mParts[Property::UID] = getVCardValue(m_data, "UID:");
while (std::getline(_data, _line)) { if (m_mParts[Property::UID].empty())
if (_line.find("UID:") != std::string::npos) {
foundUID = true;
break;
}
}
if (foundUID)
m_mParts[Property::UID] = _line.substr(4);
else
m_mParts[Property::UID] = Utils::genID(0LL, 9999999999999LL); m_mParts[Property::UID] = Utils::genID(0LL, 9999999999999LL);
MSG_(m_mParts[Property::UID]);
m_mParts[Property::FN] = getVCardValue(m_data, "FN:");
MSG_(m_mParts[Property::FN]);
bool foundFN = false;
while (std::getline(_data, _line)) { while (std::getline(_data, _line)) {
if (_line.find("FN:") != std::string::npos) { if (_line.find("PHOTO;") != std::string::npos)
foundFN = true;
break; break;
} }
}
if (foundFN)
m_mParts[Property::FN] = _line.substr(3);
while (std::getline(_data, _line)) { while (std::getline(_data, _line)) {
if (_line.find("PHOTO;") != std::string::npos) if (_line.find("PHOTO;") != std::string::npos)
break; break;
} }
// because android client builds vcard differently (TYPE=PNG: vs PNG:)
size_t pos = _line.find("PNG:"); size_t pos = _line.find("PNG:");
if (pos == std::string::npos) { if (pos == std::string::npos) {
pos = _line.find("JPEG:"); pos = _line.find("JPEG:");
...@@ -147,13 +150,6 @@ VCard::parseFromString() ...@@ -147,13 +150,6 @@ VCard::parseFromString()
else else
m_mParts[Property::PHOTO].append(_line.substr(pos + 4)); m_mParts[Property::PHOTO].append(_line.substr(pos + 4));
// avoid updating an unchanged photo
auto md5_1 = Utils::computeMD5(Utils::toPlatformString(m_mParts[Property::PHOTO]));
if (md5_0 == md5_1) {
MSG_("Duplicate Vcard PHOTO received");
return 0;
}
return 1; return 1;
} }
...@@ -323,5 +319,12 @@ VCard::setData(const std::string& data) ...@@ -323,5 +319,12 @@ VCard::setData(const std::string& data)
std::string std::string
VCard::getPart(const std::string& part) VCard::getPart(const std::string& part)
{ {
return m_mParts.at(part); std::string p;
try {
p = m_mParts.at(part);
}
catch (std::exception& e) {
MSG_(e.what());
}
return p;
} }
\ No newline at end of file
File deleted
File deleted
File deleted
File deleted
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment