Commit e2b201b0 authored by atraczyk's avatar atraczyk Committed by Andreas Traczyk

vcard: fix vcard deserialization and remove appx files

Change-Id: I52650075971a653dbc8adcbfdc0e2406eb2efdc6
parent 3783b3f5
......@@ -251,3 +251,6 @@ _Pvt_Extensions
!config.h
Generated\ Files/
# Visual Studio generated app install files
.appx
\ No newline at end of file
<?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">
<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" />
<Properties>
<DisplayName>GNU Ring</DisplayName>
......
......@@ -99,45 +99,48 @@ VCard::receiveChunk(const std::string& args, const std::string& payload)
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
VCard::parseFromString()
{
std::stringstream _data(m_data);
std::string _line;
// save hash of old photo
auto md5_0 = Utils::computeMD5(Utils::toPlatformString(m_mParts[Property::PHOTO]));
m_mParts.clear();
bool foundUID = false;
while (std::getline(_data, _line)) {
if (_line.find("UID:") != std::string::npos) {
foundUID = true;
break;
}
}
if (foundUID)
m_mParts[Property::UID] = _line.substr(4);
else
m_mParts[Property::UID] = getVCardValue(m_data, "UID:");
if (m_mParts[Property::UID].empty())
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)) {
if (_line.find("FN:") != std::string::npos) {
foundFN = true;
if (_line.find("PHOTO;") != std::string::npos)
break;
}
}
if (foundFN)
m_mParts[Property::FN] = _line.substr(3);
while (std::getline(_data, _line)) {
if (_line.find("PHOTO;") != std::string::npos)
break;
}
// because android client builds vcard differently (TYPE=PNG: vs PNG:)
size_t pos = _line.find("PNG:");
if (pos == std::string::npos) {
pos = _line.find("JPEG:");
......@@ -147,13 +150,6 @@ VCard::parseFromString()
else
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;
}
......@@ -323,5 +319,12 @@ VCard::setData(const std::string& data)
std::string
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
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