pEp_utility.h
author Markus Schaber <markus@pep-security.net>
Tue, 03 May 2016 20:15:26 +0200
changeset 71 8d19e1c194f0
parent 41 c55eaabd5ea6
child 74 f2531096699e
permissions -rw-r--r--
Fix com server registration via /Regserver
     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         ::pEp_identity *new_identity(const pEp_identity_s * ident);
    40 
    41         static LPTYPELIB pTypelib = NULL;
    42 
    43         template< class UDType > static IRecordInfo *getRecordInfo()
    44         {
    45             LPTYPEINFO pTypeInfo = NULL;
    46             LPSAFEARRAY psaUDType = NULL;
    47             IRecordInfo* pRecInfo = NULL;
    48 
    49             // Fetch the IRecordInfo interface describing the UDT
    50             if (pTypelib == NULL)
    51                 LoadRegTypeLib(LIBID_pEpCOMServerAdapterLib, 1, 0, GetUserDefaultLCID(), &pTypelib);
    52 
    53             assert(pTypelib);
    54 
    55             GUID guid = __uuidof(UDType);
    56             HRESULT hr = pTypelib->GetTypeInfoOfGuid(guid, &pTypeInfo);
    57             assert(SUCCEEDED(hr) && pTypeInfo);
    58             hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecInfo);
    59             assert(SUCCEEDED(hr) && pRecInfo);
    60             pTypeInfo->Release();
    61 
    62             return pRecInfo;
    63         }
    64 
    65         template< class UDType > LPSAFEARRAY newSafeArray(ULONG cElements)
    66         {
    67             IRecordInfo *pRecInfo = getRecordInfo< UDType >();
    68             SAFEARRAYBOUND rgbounds = { cElements, 0 };
    69             LPSAFEARRAY psaUDType = SafeArrayCreateEx(VT_RECORD, 1, &rgbounds, pRecInfo);
    70             pRecInfo->Release();
    71             assert(psaUDType);
    72 
    73             return psaUDType;
    74         }
    75 
    76         ::message * text_message_to_C(text_message *msg);
    77         void text_message_from_C(text_message *msg2, ::message *msg);
    78     }
    79 }