VCardUtils.h 3.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
/**************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux                                *
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com>              *
* Author: Traczyk Andreas <traczyk.andreas@savoirfairelinux.com>          *
*                                                                         *
* This program is free software; you can redistribute it and/or modify    *
* it under the terms of the GNU General Public License as published by    *
* the Free Software Foundation; either version 3 of the License, or       *
* (at your option) any later version.                                     *
*                                                                         *
* This program is distributed in the hope that it will be useful,         *
* but WITHOUT ANY WARRANTY; without even the implied warranty of          *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
* GNU General Public License for more details.                            *
*                                                                         *
* You should have received a copy of the GNU General Public License       *
* along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
**************************************************************************/
#pragma once

#define VCARD_INCOMPLETE    0
#define VCARD_COMPLETE      1
#define VCARD_CHUNK_ERROR   -1

using namespace Platform;

namespace RingClientUWP
{

ref class Contact;

namespace VCardUtils
{

const std::string PROFILE_VCF = "x-ring/ring.profile.vcard";

struct Symbols {
    constexpr static const char* BEGIN_TOKEN            =   "BEGIN:VCARD";
    constexpr static const char* END_TOKEN              =   "END:VCARD";
    constexpr static const char* END_LINE_TOKEN         =   "\n";
    constexpr static const char* ID_TOKEN               =   "id=";
    constexpr static const char* PART_TOKEN             =   "part=";
    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";
47
    constexpr static const char* PHOTO_TYPE             =   "TYPE=PNG";
48 49 50 51 52 53 54 55 56 57 58 59 60
};

struct Property {
    constexpr static const char* UID                    =   "UID";
    constexpr static const char* VERSION                =   "VERSION";
    constexpr static const char* FN                     =   "FN";
    constexpr static const char* PHOTO                  =   "PHOTO";
    constexpr static const char* X_RINGACCOUNT          =   "X-RINGACCOUNTID";
};

public ref class VCard sealed
{
public:
61
    VCard(Contact^ owner, String^ accountId);
62 63 64 65 66 67

internal:
    int                     receiveChunk(const std::string& args, const std::string& payload);
    void                    sendChunk(std::string callID, std::map<std::string, std::string> chunk);
    void                    send(std::string callID, const char* file = nullptr);
    std::string             asString();
68
    std::string             getPart(const std::string& part);
69 70 71 72
    int                     saveToFile();
    void                    decodeBase64ToPNGFile();
    void                    encodePNGToBase64();

73
    void                    completeReception();
74
    int                     parseFromString();
75
    void                    setData(std::map<std::string, std::string> data);
76
    void                    setData(const std::string& data);
77 78

private:
79 80
    std::string             m_data;
    std::map<std::string, std::string>  m_mParts;
81
    Contact^                m_Owner;
82
    int                     m_type;
83
    std::string             m_accountId;
84 85
};

86 87
std::map<std::string, std::string> parseContactRequestPayload(const std::string& payload);

88 89
}
}