pEp_utility.h
author Markus Schaber <markus@pep-security.net>
Tue, 04 Oct 2016 23:07:42 +0200
branchkeysync
changeset 178 9f30e2a5f72c
parent 172 112b0fac353d
child 217 7ebb44e5bf85
permissions -rw-r--r--
COM-30 COM-24: Refactorings
Drop unused enum.
vb@8
     1
#pragma once
vb@8
     2
vb@8
     3
#include "stdafx.h"
vb@8
     4
#include "pEpComServerAdapter_i.h"
vb@8
     5
#include "utf8_helper.h"
vb@8
     6
vb@8
     7
using namespace std;
vb@8
     8
vb@10
     9
namespace pEp {
vb@10
    10
    namespace utility {
vb@8
    11
vb@10
    12
        struct pEp_identity_cpp {
vb@10
    13
            string address;
vb@10
    14
            string fpr;
vb@10
    15
            string user_id;
vb@10
    16
            string username;
markus@172
    17
            pEpComType comm_type;
vb@10
    18
            string lang;
vb@10
    19
            bool me;
vb@8
    20
vb@10
    21
            pEp_identity_cpp(
vb@10
    22
                string _address = string(),
vb@10
    23
                string _fpr = string(),
vb@10
    24
                string _user_id = string(),
vb@10
    25
                string _username = string(),
markus@172
    26
                pEpComType _comm_type = pEpCtUnknown,
vb@10
    27
                string _lang = string()
vb@10
    28
                ) : address(_address), fpr(_fpr), user_id(_user_id), username(_username), comm_type(_comm_type), lang(_lang), me(false)
vb@10
    29
            { }
vb@8
    30
vb@10
    31
            pEp_identity_cpp(const ::pEp_identity *_ident);
markus@172
    32
            pEp_identity_cpp(const pEpIdentity *_ident);
vb@8
    33
vb@10
    34
            pEp_identity * to_pEp_identity();
markus@172
    35
            pEpIdentity * to_pEp_identity_s();
vb@10
    36
        };
vb@8
    37
markus@172
    38
        void copy_identity(pEpIdentity * ident_s, const pEp_identity * ident);
markus@172
    39
        void free_identity_strings(pEpIdentity * ident_s);
markus@172
    40
        void clear_identity_s(pEpIdentity& ident);
markus@172
    41
        void clear_text_message(TextMessage *msg);
markus@172
    42
        ::pEp_identity *new_identity(const pEpIdentity * ident);
vb@8
    43
krista@157
    44
		void opt_field_array_from_C(stringpair_list_t* spair_list, LPSAFEARRAY* pair_list_out);
krista@158
    45
		void clear_opt_field_array(LPSAFEARRAY* pair_list);
krista@157
    46
vb@39
    47
        static LPTYPELIB pTypelib = NULL;
vb@39
    48
vb@13
    49
        template< class UDType > static IRecordInfo *getRecordInfo()
vb@13
    50
        {
vb@13
    51
            LPTYPEINFO pTypeInfo = NULL;
vb@13
    52
            LPSAFEARRAY psaUDType = NULL;
vb@13
    53
            IRecordInfo* pRecInfo = NULL;
vb@13
    54
vb@13
    55
            // Fetch the IRecordInfo interface describing the UDT
vb@39
    56
            if (pTypelib == NULL)
vb@39
    57
                LoadRegTypeLib(LIBID_pEpCOMServerAdapterLib, 1, 0, GetUserDefaultLCID(), &pTypelib);
vb@13
    58
vb@39
    59
            assert(pTypelib);
vb@39
    60
vb@41
    61
            GUID guid = __uuidof(UDType);
vb@41
    62
            HRESULT hr = pTypelib->GetTypeInfoOfGuid(guid, &pTypeInfo);
vb@13
    63
            assert(SUCCEEDED(hr) && pTypeInfo);
vb@13
    64
            hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecInfo);
vb@13
    65
            assert(SUCCEEDED(hr) && pRecInfo);
vb@13
    66
            pTypeInfo->Release();
vb@13
    67
vb@13
    68
            return pRecInfo;
vb@13
    69
        }
vb@13
    70
vb@13
    71
        template< class UDType > LPSAFEARRAY newSafeArray(ULONG cElements)
vb@13
    72
        {
vb@13
    73
            IRecordInfo *pRecInfo = getRecordInfo< UDType >();
vb@13
    74
            SAFEARRAYBOUND rgbounds = { cElements, 0 };
vb@13
    75
            LPSAFEARRAY psaUDType = SafeArrayCreateEx(VT_RECORD, 1, &rgbounds, pRecInfo);
vb@13
    76
            pRecInfo->Release();
vb@13
    77
            assert(psaUDType);
vb@13
    78
vb@13
    79
            return psaUDType;
vb@13
    80
        }
vb@13
    81
markus@172
    82
        ::message * text_message_to_C(TextMessage *msg);
markus@172
    83
        void text_message_from_C(TextMessage *msg2, const ::message *msg);
vb@8
    84
    }
vb@8
    85
}