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.
     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             pEpComType 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                 pEpComType _comm_type = pEpCtUnknown,
    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 pEpIdentity *_ident);
    33 
    34             pEp_identity * to_pEp_identity();
    35             pEpIdentity * to_pEp_identity_s();
    36         };
    37 
    38         void copy_identity(pEpIdentity * ident_s, const pEp_identity * ident);
    39         void free_identity_strings(pEpIdentity * ident_s);
    40         void clear_identity_s(pEpIdentity& ident);
    41         void clear_text_message(TextMessage *msg);
    42         ::pEp_identity *new_identity(const pEpIdentity * ident);
    43 
    44 		void opt_field_array_from_C(stringpair_list_t* spair_list, LPSAFEARRAY* pair_list_out);
    45 		void clear_opt_field_array(LPSAFEARRAY* pair_list);
    46 
    47         static LPTYPELIB pTypelib = NULL;
    48 
    49         template< class UDType > static IRecordInfo *getRecordInfo()
    50         {
    51             LPTYPEINFO pTypeInfo = NULL;
    52             LPSAFEARRAY psaUDType = NULL;
    53             IRecordInfo* pRecInfo = NULL;
    54 
    55             // Fetch the IRecordInfo interface describing the UDT
    56             if (pTypelib == NULL)
    57                 LoadRegTypeLib(LIBID_pEpCOMServerAdapterLib, 1, 0, GetUserDefaultLCID(), &pTypelib);
    58 
    59             assert(pTypelib);
    60 
    61             GUID guid = __uuidof(UDType);
    62             HRESULT hr = pTypelib->GetTypeInfoOfGuid(guid, &pTypeInfo);
    63             assert(SUCCEEDED(hr) && pTypeInfo);
    64             hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecInfo);
    65             assert(SUCCEEDED(hr) && pRecInfo);
    66             pTypeInfo->Release();
    67 
    68             return pRecInfo;
    69         }
    70 
    71         template< class UDType > LPSAFEARRAY newSafeArray(ULONG cElements)
    72         {
    73             IRecordInfo *pRecInfo = getRecordInfo< UDType >();
    74             SAFEARRAYBOUND rgbounds = { cElements, 0 };
    75             LPSAFEARRAY psaUDType = SafeArrayCreateEx(VT_RECORD, 1, &rgbounds, pRecInfo);
    76             pRecInfo->Release();
    77             assert(psaUDType);
    78 
    79             return psaUDType;
    80         }
    81 
    82         ::message * text_message_to_C(TextMessage *msg);
    83         void text_message_from_C(TextMessage *msg2, const ::message *msg);
    84     }
    85 }