-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManager.h
More file actions
228 lines (191 loc) · 6.46 KB
/
Manager.h
File metadata and controls
228 lines (191 loc) · 6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Manager.h : Declaration of the CManager
#ifndef __MANAGER_H_
#define __MANAGER_H_
#include "resource.h" // main symbols
#define PTP_IMANAGER 0x01
#include "ptp.h" // point to point definition
// If using ATL 7.0 do not use "USE_CONVERSION" macro and use CW2A otherwise
// use macro with OLE2A ( this is only for the sending routines )
// the receiving routines use ATL 3.0 allways.
#if _ATL_VER < 0x0700
#define CW2A OLE2A
#ifndef SOMETIMES_USES_CONVERSION
#define SOMETIMES_USES_CONVERSION USES_CONVERSION;
#endif
#else
#ifndef SOMETIMES_USES_CONVERSION
#define SOMETIMES_USES_CONVERSION ""
#endif
#endif
/////////////////////////////////////////////////////////////////////////////
// CManager
class ATL_NO_VTABLE CManager :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CManager, &CLSID_Manager>,
public IDispatchImpl<IManager, &IID_IManager, &LIBID_POINTTPOINTLib>
{
public:
CManager()
{
WORD wVersionRequested;
WSADATA wsaData;
// Setup windows sockets
wVersionRequested = MAKEWORD( 0x01, 0x01 );
if ( WSAStartup( wVersionRequested, &wsaData ) != 0x00 )
{
zPTPLog( ( FILE * ) NULL, 0x03, "CManager", PTP_LOG_LEVEL_ERROR , 0x00, "%s", "Error initlializing Windows sockets" );
}
m_Log = 0x00;
m_Script = 0x00;
m_Language = 0x00;
m_Failed = 0x00;
m_Encrypt = 0x00;
m_BufferSize = 0x00;
m_SocketFd = 0x00;
m_Host = m_FailoverHost = NULL;
m_Port = 0x4D2;
m_FailoverPort = 0x00;
m_Timeout = 0x00;
m_TemporaryPointer = NULL;
m_Application = NULL;
}
~CManager()
{
// Disconnect if exists
PTP_Cleanup( &m_SocketFd );
// Release windows sockets
WSACleanup();
// Release memory allcated previously
if ( m_TemporaryPointer )
{
free ( m_TemporaryPointer );
}
if ( m_Host )
{
free ( m_Host );
}
if ( m_FailoverHost )
{
free ( m_FailoverHost );
}
if ( m_Application )
{
free ( m_Application );
}
}
DECLARE_REGISTRY_RESOURCEID(IDR_MANAGER)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CManager)
COM_INTERFACE_ENTRY(IManager)
COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()
// IManager
public:
STDMETHOD(put_Application)(/*[in]*/ BSTR newVal);
STDMETHOD(get_BufferSize)(/*[out, retval]*/ long *pVal);
STDMETHOD(get_Encrypt)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_Encrypt)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_HeaderSize)(/*[out, retval]*/ long *pVal);
STDMETHOD(ParseFileHeader)(/*[in]*/ BSTR *filePath, /*[out,retval]*/ long *rval);
STDMETHOD(put_Script)(/*[in]*/ VARIANT_BOOL newVal);
STDMETHOD(get_ReceivedBuffer)(/*[out, retval]*/ BSTR *pVal);
STDMETHOD(get_Language)(/*[out, retval]*/ long *pVal);
STDMETHOD(put_Language)(/*[in]*/ long newVal);
STDMETHOD(put_Timeout)(/*[in]*/ long newVal);
STDMETHOD(put_FailoverPort)(/*[in]*/ long newVal);
STDMETHOD(put_FailoverHost)(/*[in]*/ BSTR newVal);
STDMETHOD(put_Port)(/*[in]*/ long newVal);
STDMETHOD(put_Host)(/*[in]*/ BSTR newVal);
STDMETHOD(ReceiveReply)(/*[out]*/ BSTR *buffer, /*[out,retval]*/ long *rval);
STDMETHOD(SendReply)(/*[in]*/ BSTR *buffer, /*[out,retval]*/ long *rval);
STDMETHOD(ReceiveRequest)(/*[out]*/ BSTR *buffer, /*[out,retval]*/ long *rval);
STDMETHOD(SendSafeRequest)(/*[in]*/ BSTR *buffer,/*[in]*/ BSTR *path, /*[out,retval]*/ long *rval);
STDMETHOD(SendRequest)(/*[in]*/ BSTR *buffer,/*[out,retval]*/ long *rval);
STDMETHOD(Connect)(/*[out,retval]*/ long *rval);
private:
///////////////////////////////////////////
// PTP_Log
// Write information to
// eventlog
// is not registered.
// Information can be errors or data you
// always want to log.
// returns privateVoid
////////////////////////////////////////////
privateVoid zPTPLog( FILE *fp, char outLevel, char *funcName, int type, int code, const char *fmt, ... )
{
va_list ap;
char message[PTP_MAX_LOG_MESSAGE_SIZE];
char details[0x64];
char machineName[MAX_COMPUTERNAME_LENGTH + 0x01];
DWORD machineNameLen = MAX_COMPUTERNAME_LENGTH + 0x01;
char *logLevel[] = { "-E-",
"-I-",
"-W-",
"-D-",
"-S-",
"" };
if ( !outLevel || type == PTP_LOG_LEVEL_NOTHING )
{
return;
}
va_start( ap, fmt );
int rc = GetLastError();
// Check if file pointer defined then write to file pointer
if( fp )
{
if ( type != PTP_LOG_LEVEL_NOTHING )
{
message[(vsprintf( message, fmt, ap ))] = '\x00';
fprintf( fp, "%s%s%s, system msg:%s, errno:%d\n", funcName, logLevel[type], message,
strerror( PTP_ERROR ), PTP_ERROR );
}
else
{
vfprintf( fp, fmt, ap );
}
}
else
{
GetComputerName( machineName, &machineNameLen );
message[(vsprintf( message, fmt, ap ))] = '\x00';
sprintf( details, ", system msg:%s, errno:%d\n", strerror( PTP_ERROR ), PTP_ERROR );
strcat( message, ( const char * ) details );
// Incase the error was in file I/O log the error number here
sprintf( details, ", %d ", rc );
strcat( message, ( const char * ) details );
LPTSTR lpszStrings[1];
lpszStrings[0] = message;
HANDLE hEventSource = RegisterEventSource( machineName, m_Application == NULL ? "PointTPoint" : m_Application );
if ( hEventSource != 0x00 )
{
ReportEvent( hEventSource,
type == PTP_LOG_LEVEL_ERROR ? EVENTLOG_ERROR_TYPE : EVENTLOG_INFORMATION_TYPE,
0x00,
0x00,
NULL,
0x01,
0x00,
( LPCTSTR * ) &lpszStrings[0],
NULL );
DeregisterEventSource( hEventSource );
}
}
}
IAppLogPtr m_Log;
char *m_TemporaryPointer;
PTP_SOCKET m_SocketFd;
long m_Timeout;
long m_Port;
long m_FailoverPort;
long m_Language;
long m_Encrypt;
long m_Failed;
long m_Script;
long m_BufferSize;
char *m_Host;
char *m_FailoverHost;
char *m_Application;
#include "ptp.cpp" // point to point API
};
#endif //__MANAGER_H_