pEp_utility.h
author Volker Birk <vb@pep-project.org>
Wed, 07 Dec 2016 20:53:29 +0100
changeset 227 5bc3d8cb9415
parent 220 92489901bb81
child 251 ded328cde93f
child 258 794f2468ccec
permissions -rw-r--r--
changing interface for sync handshake
     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 			int flags;
    21 
    22             pEp_identity_cpp(
    23                 string _address = string(),
    24                 string _fpr = string(),
    25                 string _user_id = string(),
    26                 string _username = string(),
    27                 pEpComType _comm_type = pEpCtUnknown,
    28                 string _lang = string()
    29                 ) : address(_address), fpr(_fpr), user_id(_user_id), username(_username), comm_type(_comm_type), lang(_lang), me(false)
    30             { }
    31 
    32             pEp_identity_cpp(const ::pEp_identity *_ident);
    33             pEp_identity_cpp(const pEpIdentity *_ident);
    34 
    35             pEp_identity * to_pEp_identity();
    36             pEpIdentity * to_pEp_identity_s();
    37         };
    38 
    39         void copy_identity(pEpIdentity * ident_s, const pEp_identity * ident);
    40         void free_identity_strings(pEpIdentity * ident_s);
    41         void clear_identity_s(pEpIdentity& ident);
    42         void clear_text_message(TextMessage *msg);
    43         ::pEp_identity *new_identity(const pEpIdentity * ident);
    44 
    45 		void opt_field_array_from_C(stringpair_list_t* spair_list, LPSAFEARRAY* pair_list_out);
    46 		void clear_opt_field_array(LPSAFEARRAY* pair_list);
    47 		template< class T2, class T > SAFEARRAY * array_from_C(T *tl);
    48 
    49         static LPTYPELIB pTypelib = NULL;
    50 
    51         template< class UDType > static IRecordInfo *getRecordInfo()
    52         {
    53             LPTYPEINFO pTypeInfo = NULL;
    54             LPSAFEARRAY psaUDType = NULL;
    55             IRecordInfo* pRecInfo = NULL;
    56 
    57             // Fetch the IRecordInfo interface describing the UDT
    58             if (pTypelib == NULL)
    59                 LoadRegTypeLib(LIBID_pEpCOMServerAdapterLib, 1, 0, GetUserDefaultLCID(), &pTypelib);
    60 
    61             assert(pTypelib);
    62 
    63             GUID guid = __uuidof(UDType);
    64             HRESULT hr = pTypelib->GetTypeInfoOfGuid(guid, &pTypeInfo);
    65             assert(SUCCEEDED(hr) && pTypeInfo);
    66             hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecInfo);
    67             assert(SUCCEEDED(hr) && pRecInfo);
    68             pTypeInfo->Release();
    69 
    70             return pRecInfo;
    71         }
    72 
    73         template< class UDType > LPSAFEARRAY newSafeArray(ULONG cElements)
    74         {
    75             IRecordInfo *pRecInfo = getRecordInfo< UDType >();
    76             SAFEARRAYBOUND rgbounds = { cElements, 0 };
    77             LPSAFEARRAY psaUDType = SafeArrayCreateEx(VT_RECORD, 1, &rgbounds, pRecInfo);
    78             pRecInfo->Release();
    79             assert(psaUDType);
    80 
    81             return psaUDType;
    82         }
    83 
    84         ::message * text_message_to_C(TextMessage *msg);
    85         void text_message_from_C(TextMessage *msg2, const ::message *msg);
    86     }
    87 }