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