Business Services - DB pool connection leak fixed
[public/netxms.git] / include / nxcpapi.h
CommitLineData
9fa031cd 1/*
0d9c1b96 2** NetXMS - Network Management System
9f2ad16c 3** NXCP API
68f384ea 4** Copyright (C) 2003-2010 Victor Kirhenshtein
0d9c1b96
VK
5**
6** This program is free software; you can redistribute it and/or modify
65d2c384
VK
7** it under the terms of the GNU Lesser General Public License as published by
8** the Free Software Foundation; either version 3 of the License, or
0d9c1b96
VK
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
68f384ea 16** You should have received a copy of the GNU Lesser General Public License
0d9c1b96
VK
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19**
9f2ad16c 20** File: nxcpapi.h
0d9c1b96
VK
21**
22**/
23
9f2ad16c
VK
24#ifndef _nxcpapi_h_
25#define _nxcpapi_h_
0d9c1b96 26
9f2ad16c 27#include <nms_util.h>
bf6fb6c3 28#include <nms_threads.h>
9c3bf7f4 29#include <nxcrypto.h>
de4af576 30#include <uuid.h>
8c290af0 31
bb8136f7
VK
32#ifdef _WIN32
33#include <wincrypt.h>
34#endif
35
bf306af3
VK
36#ifdef _WITH_ENCRYPTION
37#include <openssl/ssl.h>
38#endif
39
4af351c7 40/**
b368969c 41 * Temporary buffer structure for RecvNXCPMessage() function
4af351c7 42 */
0d9c1b96
VK
43typedef struct
44{
b368969c
VK
45 UINT32 bufferSize;
46 UINT32 bufferPos;
43a6f3ca 47 char buffer[NXCP_TEMP_BUF_SIZE];
b368969c 48} NXCP_BUFFER;
0d9c1b96
VK
49
50
9f2ad16c
VK
51#ifdef __cplusplus
52
5c44534b
VK
53struct MessageField;
54
4af351c7
VK
55/**
56 * Parsed NXCP message
57 */
b368969c 58class LIBNETXMS_EXPORTABLE NXCPMessage
0d9c1b96
VK
59{
60private:
b368969c
VK
61 UINT16 m_code;
62 UINT16 m_flags;
5c44534b 63 UINT32 m_id;
6be0a20b
VK
64 MessageField *m_fields; // Message fields
65 int m_version; // Protocol version
66 BYTE *m_data; // binary data
67 size_t m_dataSize; // binary data size
0d9c1b96 68
712b2760 69 void *set(UINT32 fieldId, BYTE type, const void *value, bool isSigned = false, size_t size = 0);
ca0a165b
VK
70 void *get(UINT32 fieldId, BYTE requiredType, BYTE *fieldType = NULL) const;
71 NXCP_MESSAGE_FIELD *find(UINT32 fieldId) const;
0d9c1b96
VK
72
73public:
b368969c
VK
74 NXCPMessage(int version = NXCP_VERSION);
75 NXCPMessage(NXCPMessage *msg);
76 NXCPMessage(NXCP_MESSAGE *rawMag, int version = NXCP_VERSION);
77 ~NXCPMessage();
0d9c1b96 78
9674aefa 79 NXCP_MESSAGE *createMessage(bool allowCompression = false) const;
0d9c1b96 80
ca0a165b 81 UINT16 getCode() const { return m_code; }
b368969c 82 void setCode(UINT16 code) { m_code = code; }
0d9c1b96 83
ca0a165b 84 UINT32 getId() const { return m_id; }
b368969c 85 void setId(UINT32 id) { m_id = id; }
0d9c1b96 86
4970ef34
VK
87 int getProtocolVersion() const { return m_version; }
88 void setProtocolVersion(int version) { m_version = version; }
89
ca0a165b
VK
90 bool isEndOfFile() const { return (m_flags & MF_END_OF_FILE) ? true : false; }
91 bool isEndOfSequence() const { return (m_flags & MF_END_OF_SEQUENCE) ? true : false; }
92 bool isReverseOrder() const { return (m_flags & MF_REVERSE_ORDER) ? true : false; }
93 bool isBinary() const { return (m_flags & MF_BINARY) ? true : false; }
94 bool isControl() const { return (m_flags & MF_CONTROL) ? true : false; }
3a1356ab 95 bool isCompressedStream() const { return ((m_flags & (MF_COMPRESSED | MF_STREAM)) == (MF_COMPRESSED | MF_STREAM)) ? true : false; }
6be0a20b 96
ca0a165b
VK
97 const BYTE *getBinaryData() const { return m_data; }
98 size_t getBinaryDataSize() const { return m_dataSize; }
4af351c7 99
ca0a165b
VK
100 bool isFieldExist(UINT32 fieldId) const { return find(fieldId) != NULL; }
101 int getFieldType(UINT32 fieldId) const;
4101571e 102
712b2760
VK
103 void setField(UINT32 fieldId, INT16 value) { set(fieldId, NXCP_DT_INT16, &value, true); }
104 void setField(UINT32 fieldId, UINT16 value) { set(fieldId, NXCP_DT_INT16, &value, false); }
105 void setField(UINT32 fieldId, INT32 value) { set(fieldId, NXCP_DT_INT32, &value, true); }
106 void setField(UINT32 fieldId, UINT32 value) { set(fieldId, NXCP_DT_INT32, &value, false); }
107 void setField(UINT32 fieldId, INT64 value) { set(fieldId, NXCP_DT_INT64, &value, true); }
108 void setField(UINT32 fieldId, UINT64 value) { set(fieldId, NXCP_DT_INT64, &value, false); }
b368969c 109 void setField(UINT32 fieldId, double value) { set(fieldId, NXCP_DT_FLOAT, &value); }
19a2cd39 110 void setField(UINT32 fieldId, bool value) { INT16 v = value ? 1 : 0; set(fieldId, NXCP_DT_INT16, &v, true); }
b368969c 111 void setField(UINT32 fieldId, const TCHAR *value) { if (value != NULL) set(fieldId, NXCP_DT_STRING, value); }
712b2760 112 void setField(UINT32 fieldId, const TCHAR *value, size_t maxLen) { if (value != NULL) set(fieldId, NXCP_DT_STRING, value, false, maxLen); }
5f573844 113 void setField(UINT32 fieldId, const BYTE *value, size_t size) { set(fieldId, NXCP_DT_BINARY, value, false, size); }
de4af576
VK
114 void setField(UINT32 fieldId, const InetAddress& value) { set(fieldId, NXCP_DT_INETADDR, &value); }
115 void setField(UINT32 fieldId, const uuid& value) { set(fieldId, NXCP_DT_BINARY, value.getValue(), false, UUID_LENGTH); }
35f836fe 116#ifdef UNICODE
b368969c 117 void setFieldFromMBString(UINT32 fieldId, const char *value);
35f836fe 118#else
b368969c 119 void setFieldFromMBString(UINT32 fieldId, const char *value) { set(fieldId, NXCP_DT_STRING, value); }
35f836fe 120#endif
b368969c 121 void setFieldFromTime(UINT32 fieldId, time_t value) { UINT64 t = (UINT64)value; set(fieldId, NXCP_DT_INT64, &t); }
14149881 122 void setFieldFromInt32Array(UINT32 fieldId, size_t numElements, const UINT32 *elements);
e30c2442 123 void setFieldFromInt32Array(UINT32 fieldId, const IntegerArray<UINT32> *data);
8f238fd7 124 bool setFieldFromFile(UINT32 fieldId, const TCHAR *pszFileName);
967893bb 125
ca0a165b
VK
126 INT16 getFieldAsInt16(UINT32 fieldId) const;
127 UINT16 getFieldAsUInt16(UINT32 fieldId) const;
128 INT32 getFieldAsInt32(UINT32 fieldId) const;
129 UINT32 getFieldAsUInt32(UINT32 fieldId) const;
130 INT64 getFieldAsInt64(UINT32 fieldId) const;
131 UINT64 getFieldAsUInt64(UINT32 fieldId) const;
132 double getFieldAsDouble(UINT32 fieldId) const;
133 bool getFieldAsBoolean(UINT32 fieldId) const;
134 time_t getFieldAsTime(UINT32 fieldId) const;
135 UINT32 getFieldAsInt32Array(UINT32 fieldId, UINT32 numElements, UINT32 *buffer) const;
136 UINT32 getFieldAsInt32Array(UINT32 fieldId, IntegerArray<UINT32> *data) const;
137 const BYTE *getBinaryFieldPtr(UINT32 fieldId, size_t *size) const;
138 TCHAR *getFieldAsString(UINT32 fieldId, TCHAR *buffer = NULL, size_t bufferSize = 0) const;
139 char *getFieldAsMBString(UINT32 fieldId, char *buffer = NULL, size_t bufferSize = 0) const;
140 char *getFieldAsUtf8String(UINT32 fieldId, char *buffer = NULL, size_t bufferSize = 0) const;
141 UINT32 getFieldAsBinary(UINT32 fieldId, BYTE *buffer, size_t bufferSize) const;
142 InetAddress getFieldAsInetAddress(UINT32 fieldId) const;
143 uuid getFieldAsGUID(UINT32 fieldId) const;
4101571e 144
b368969c 145 void deleteAllFields();
e44ac467 146
5c44534b
VK
147 void disableEncryption() { m_flags |= MF_DONT_ENCRYPT; }
148 void setEndOfSequence() { m_flags |= MF_END_OF_SEQUENCE; }
149 void setReverseOrderFlag() { m_flags |= MF_REVERSE_ORDER; }
934f53da 150
ca0a165b 151 static String dump(const NXCP_MESSAGE *msg, int version);
0d9c1b96
VK
152};
153
4af351c7
VK
154/**
155 * Message waiting queue element structure
156 */
deaa4491
VK
157typedef struct
158{
b368969c 159 void *msg; // Pointer to message, either to NXCPMessage object or raw message
14149881 160 UINT64 sequence; // Sequence number
f128c07c
VK
161 UINT32 id; // Message ID
162 UINT32 ttl; // Message time-to-live in milliseconds
163 UINT16 code; // Message code
164 UINT16 isBinary; // 1 for binary (raw) messages
deaa4491
VK
165} WAIT_QUEUE_ELEMENT;
166
4af351c7 167/**
f128c07c
VK
168 * Max number of waiting threads in message queue
169 */
170#define MAX_MSGQUEUE_WAITERS 32
171
172/**
4af351c7
VK
173 * Message waiting queue class
174 */
9f2ad16c 175class LIBNETXMS_EXPORTABLE MsgWaitQueue
deaa4491 176{
deaa4491 177private:
ef8a3c32 178#if defined(_WIN32)
f128c07c
VK
179 CRITICAL_SECTION m_mutex;
180 HANDLE m_wakeupEvents[MAX_MSGQUEUE_WAITERS];
181 BYTE m_waiters[MAX_MSGQUEUE_WAITERS];
ef8a3c32
VK
182#elif defined(_USE_GNU_PTH)
183 pth_mutex_t m_mutex;
184 pth_cond_t m_wakeupCondition;
f128c07c
VK
185#else
186 pthread_mutex_t m_mutex;
187 pthread_cond_t m_wakeupCondition;
188#endif
f128c07c
VK
189 UINT32 m_holdTime;
190 int m_size;
191 int m_allocated;
192 WAIT_QUEUE_ELEMENT *m_elements;
14149881 193 UINT64 m_sequence;
deaa4491 194
f128c07c
VK
195 void *waitForMessageInternal(UINT16 isBinary, UINT16 code, UINT32 id, UINT32 timeout);
196
197 void lock()
198 {
199#ifdef _WIN32
200 EnterCriticalSection(&m_mutex);
ef8a3c32
VK
201#elif defined(_USE_GNU_PTH)
202 pth_mutex_acquire(&m_mutex, FALSE, NULL);
f128c07c
VK
203#else
204 pthread_mutex_lock(&m_mutex);
205#endif
206 }
207
208 void unlock()
209 {
210#ifdef _WIN32
211 LeaveCriticalSection(&m_mutex);
ef8a3c32
VK
212#elif defined(_USE_GNU_PTH)
213 pth_mutex_release(&m_mutex);
f128c07c
VK
214#else
215 pthread_mutex_unlock(&m_mutex);
216#endif
217 }
cc022855 218
d87ddcc2
VK
219 void housekeeperRun();
220
c73c3ba9 221 static Mutex m_housekeeperLock;
669fcb92 222 static HashMap<UINT64, MsgWaitQueue> *m_activeQueues;
c73c3ba9 223 static Condition m_shutdownCondition;
d87ddcc2
VK
224 static THREAD m_housekeeperThread;
225 static EnumerationCallbackResult houseKeeperCallback(const void *key, const void *object, void *arg);
226 static THREAD_RESULT THREAD_CALL housekeeperThread(void *);
227 static EnumerationCallbackResult diagInfoCallback(const void *key, const void *object, void *arg);
deaa4491
VK
228
229public:
230 MsgWaitQueue();
231 ~MsgWaitQueue();
232
b368969c
VK
233 void put(NXCPMessage *pMsg);
234 void put(NXCP_MESSAGE *pMsg);
235 NXCPMessage *waitForMessage(WORD wCode, UINT32 dwId, UINT32 dwTimeOut)
deaa4491 236 {
b368969c 237 return (NXCPMessage *)waitForMessageInternal(0, wCode, dwId, dwTimeOut);
deaa4491 238 }
b368969c 239 NXCP_MESSAGE *waitForRawMessage(WORD wCode, UINT32 dwId, UINT32 dwTimeOut)
deaa4491 240 {
b368969c 241 return (NXCP_MESSAGE *)waitForMessageInternal(1, wCode, dwId, dwTimeOut);
deaa4491 242 }
cc022855 243
c17f6cbc 244 void clear();
f128c07c 245 void setHoldTime(UINT32 holdTime) { m_holdTime = holdTime; }
d87ddcc2
VK
246
247 static void shutdown();
248 static String getDiagInfo();
deaa4491
VK
249};
250
b549a0f8
VK
251/**
252 * NXCP encryption context
253 */
98abc9f1
VK
254class LIBNETXMS_EXPORTABLE NXCPEncryptionContext : public RefCountObject
255{
256private:
257 int m_cipher;
258 BYTE *m_sessionKey;
259 int m_keyLength;
260 BYTE m_iv[EVP_MAX_IV_LENGTH];
e4e091f0 261#ifdef _WITH_ENCRYPTION
9c3bf7f4
VK
262 MUTEX m_encryptorLock;
263#if WITH_OPENSSL
e6336a90
VK
264 EVP_CIPHER_CTX m_encryptor;
265 EVP_CIPHER_CTX m_decryptor;
9c3bf7f4
VK
266#elif WITH_COMMONCRYPTO
267 CCCryptorRef m_encryptor;
268 CCCryptorRef m_decryptor;
269#endif
e4e091f0 270#endif
98abc9f1
VK
271
272 NXCPEncryptionContext();
e6336a90 273 bool initCipher(int cipher);
98abc9f1
VK
274
275public:
b368969c 276 static NXCPEncryptionContext *create(NXCPMessage *msg, RSA *privateKey);
967893bb 277 static NXCPEncryptionContext *create(UINT32 ciphers);
98abc9f1
VK
278
279 virtual ~NXCPEncryptionContext();
280
b368969c 281 NXCP_ENCRYPTED_MESSAGE *encryptMessage(NXCP_MESSAGE *msg);
6be0a20b 282 bool decryptMessage(NXCP_ENCRYPTED_MESSAGE *msg, BYTE *decryptionBuffer);
e6336a90 283
98abc9f1
VK
284 int getCipher() { return m_cipher; }
285 BYTE *getSessionKey() { return m_sessionKey; }
286 int getKeyLength() { return m_keyLength; }
287 BYTE *getIV() { return m_iv; }
288};
289
6be0a20b
VK
290/**
291 * Message receiver result codes
292 */
293enum MessageReceiverResult
294{
295 MSGRECV_SUCCESS = 0,
296 MSGRECV_CLOSED = 1,
297 MSGRECV_TIMEOUT = 2,
298 MSGRECV_COMM_FAILURE = 3,
1bb62997
VK
299 MSGRECV_DECRYPTION_FAILURE = 4,
300 MSGRECV_PROTOCOL_ERROR = 5
6be0a20b
VK
301};
302
303/**
304 * Message receiver - abstract base class
305 */
306class LIBNETXMS_EXPORTABLE AbstractMessageReceiver
307{
308private:
309 BYTE *m_buffer;
310 BYTE *m_decryptionBuffer;
311 NXCPEncryptionContext *m_encryptionContext;
312 size_t m_initialSize;
313 size_t m_size;
314 size_t m_maxSize;
315 size_t m_dataSize;
316 size_t m_bytesToSkip;
317
1bb62997 318 NXCPMessage *getMessageFromBuffer(bool *protocolError);
6be0a20b
VK
319
320protected:
321 virtual int readBytes(BYTE *buffer, size_t size, UINT32 timeout) = 0;
322
323public:
324 AbstractMessageReceiver(size_t initialSize, size_t maxSize);
325 virtual ~AbstractMessageReceiver();
326
327 void setEncryptionContext(NXCPEncryptionContext *ctx) { m_encryptionContext = ctx; }
328
b368969c
VK
329 NXCPMessage *readMessage(UINT32 timeout, MessageReceiverResult *result);
330 NXCP_MESSAGE *getRawMessageBuffer() { return (NXCP_MESSAGE *)m_buffer; }
331
332 static const TCHAR *resultToText(MessageReceiverResult result);
6be0a20b
VK
333};
334
335/**
336 * Message receiver - socket implementation
337 */
338class LIBNETXMS_EXPORTABLE SocketMessageReceiver : public AbstractMessageReceiver
339{
340private:
341 SOCKET m_socket;
342
343protected:
344 virtual int readBytes(BYTE *buffer, size_t size, UINT32 timeout);
345
346public:
347 SocketMessageReceiver(SOCKET socket, size_t initialSize, size_t maxSize);
348 virtual ~SocketMessageReceiver();
349};
350
bf306af3
VK
351#ifdef _WITH_ENCRYPTION
352
353/**
354 * Message receiver - SSL/TLS implementation
355 */
356class LIBNETXMS_EXPORTABLE TlsMessageReceiver : public AbstractMessageReceiver
357{
358private:
359 SOCKET m_socket;
360 SSL *m_ssl;
361
362protected:
363 virtual int readBytes(BYTE *buffer, size_t size, UINT32 timeout);
364
365public:
366 TlsMessageReceiver(SOCKET socket, SSL *ssl, size_t initialSize, size_t maxSize);
367 virtual ~TlsMessageReceiver();
368};
369
370#endif /* _WITH_ENCRYPTION */
371
6be0a20b
VK
372/**
373 * Message receiver - UNIX socket/named pipe implementation
374 */
375class LIBNETXMS_EXPORTABLE PipeMessageReceiver : public AbstractMessageReceiver
376{
377private:
378 HPIPE m_pipe;
379#ifdef _WIN32
380 HANDLE m_readEvent;
381#endif
382
383protected:
384 virtual int readBytes(BYTE *buffer, size_t size, UINT32 timeout);
385
386public:
387 PipeMessageReceiver(HPIPE pipe, size_t initialSize, size_t maxSize);
388 virtual ~PipeMessageReceiver();
389};
390
503da871 391/**
d3a20572 392 * NXCP stresam compression methods
503da871 393 */
d3a20572 394enum NXCPStreamCompressionMethod
503da871 395{
d3a20572 396 NXCP_STREAM_COMPRESSION_NONE = 0,
90ed558d
VK
397 NXCP_STREAM_COMPRESSION_LZ4 = 1,
398 NXCP_STREAM_COMPRESSION_DEFLATE = 2
503da871
VK
399};
400
401/**
402 * Abstract stream compressor
403 */
404class LIBNETXMS_EXPORTABLE StreamCompressor
405{
406public:
9757ca46
VK
407 virtual ~StreamCompressor();
408
503da871
VK
409 virtual size_t compress(const BYTE *in, size_t inSize, BYTE *out, size_t maxOutSize) = 0;
410 virtual size_t decompress(const BYTE *in, size_t inSize, const BYTE **out) = 0;
411 virtual size_t compressBufferSize(size_t dataSize) = 0;
412
d3a20572 413 static StreamCompressor *create(NXCPStreamCompressionMethod method, bool compress, size_t maxBlockSize);
503da871
VK
414};
415
416/**
417 * Dummy stream compressor
418 */
419class LIBNETXMS_EXPORTABLE DummyStreamCompressor : public StreamCompressor
420{
421public:
9757ca46
VK
422 virtual ~DummyStreamCompressor();
423
503da871
VK
424 virtual size_t compress(const BYTE *in, size_t inSize, BYTE *out, size_t maxOutSize);
425 virtual size_t decompress(const BYTE *in, size_t inSize, const BYTE **out);
426 virtual size_t compressBufferSize(size_t dataSize);
427};
428
429struct __LZ4_stream_t;
430struct __LZ4_streamDecode_t;
431
432/**
433 * LZ4 stream compressor
434 */
435class LIBNETXMS_EXPORTABLE LZ4StreamCompressor : public StreamCompressor
436{
437private:
438 union
439 {
440 __LZ4_stream_t *encoder;
441 __LZ4_streamDecode_t *decoder;
442 } m_stream;
443 char *m_buffer;
444 size_t m_maxBlockSize;
445 size_t m_bufferSize;
446 size_t m_bufferPos;
447 bool m_compress;
448
449public:
450 LZ4StreamCompressor(bool compress, size_t maxBlockSize);
451 virtual ~LZ4StreamCompressor();
452
453 virtual size_t compress(const BYTE *in, size_t inSize, BYTE *out, size_t maxOutSize);
454 virtual size_t decompress(const BYTE *in, size_t inSize, const BYTE **out);
455 virtual size_t compressBufferSize(size_t dataSize);
456};
457
90ed558d
VK
458struct z_stream_s;
459
460/**
461 * Deflate stream compressor
462 */
463class LIBNETXMS_EXPORTABLE DeflateStreamCompressor : public StreamCompressor
464{
465private:
466 z_stream_s *m_stream;
467 BYTE *m_buffer;
468 size_t m_bufferSize;
469 bool m_compress;
470
471public:
472 DeflateStreamCompressor(bool compress, size_t maxBlockSize);
473 virtual ~DeflateStreamCompressor();
474
475 virtual size_t compress(const BYTE *in, size_t inSize, BYTE *out, size_t maxOutSize);
476 virtual size_t decompress(const BYTE *in, size_t inSize, const BYTE **out);
477 virtual size_t compressBufferSize(size_t dataSize);
478};
479
208d7427
VK
480#if 0
481/**
482 * NXCP message consumer interface
483 */
484class LIBNETXMS_EXPORTABLE MessageConsumer
485{
486public:
487 virtual SOCKET getSocket() = 0;
488 virtual void processMessage(NXCPMessage *msg) = 0;
489};
490
491/**
492 * Socket receiver - manages receiving NXCP messages from multiple sockets
493 */
494class LIBNETXMS_EXPORTABLE SocketReceiver
495{
496private:
497 THREAD m_thread;
498 HashMap<SOCKET, MessageConsumer> *m_consumers;
499
500 static int m_maxSocketsPerThread;
501 static ObjectArray<SocketReceiver> *m_receivers;
502
503public:
504 static void start();
505 static void shutdown();
506
507 static void addConsumer(MessageConsumer *mc);
508 static void removeConsumer(MessageConsumer *mc);
509
510 static String getDiagInfo();
511};
512#endif
513
9f2ad16c
VK
514#else /* __cplusplus */
515
b368969c 516typedef void NXCPMessage;
98abc9f1 517typedef void NXCPEncryptionContext;
9f2ad16c
VK
518
519#endif
520
da9ac8fc
VK
521typedef bool (*NXCPMessageNameResolver)(UINT16 code, TCHAR *buffer);
522
deaa4491
VK
523
524//
0d9c1b96
VK
525// Functions
526//
527
528#ifdef __cplusplus
0d9c1b96 529
b368969c
VK
530int LIBNETXMS_EXPORTABLE RecvNXCPMessage(SOCKET hSocket, NXCP_MESSAGE *pMsg,
531 NXCP_BUFFER *pBuffer, UINT32 dwMaxMsgSize,
98abc9f1 532 NXCPEncryptionContext **ppCtx,
967893bb 533 BYTE *pDecryptionBuffer, UINT32 dwTimeout);
b368969c
VK
534int LIBNETXMS_EXPORTABLE RecvNXCPMessageEx(SOCKET hSocket, NXCP_MESSAGE **msgBuffer,
535 NXCP_BUFFER *nxcpBuffer, UINT32 *bufferSize,
cc022855 536 NXCPEncryptionContext **ppCtx,
967893bb
VK
537 BYTE **decryptionBuffer, UINT32 dwTimeout,
538 UINT32 maxMsgSize);
d3a20572
VK
539NXCP_MESSAGE LIBNETXMS_EXPORTABLE *CreateRawNXCPMessage(UINT16 code, UINT32 id, UINT16 flags,
540 const void *data, size_t dataSize,
541 NXCP_MESSAGE *buffer, bool allowCompression);
967893bb 542BOOL LIBNETXMS_EXPORTABLE SendFileOverNXCP(SOCKET hSocket, UINT32 dwId, const TCHAR *pszFile,
cc022855 543 NXCPEncryptionContext *pCtx, long offset,
7b8b337e 544 void (* progressCallback)(INT64, void *), void *cbArg,
d3a20572 545 MUTEX mutex, NXCPStreamCompressionMethod compressionMethod = NXCP_STREAM_COMPRESSION_NONE);
7b8b337e 546BOOL LIBNETXMS_EXPORTABLE NXCPGetPeerProtocolVersion(SOCKET hSocket, int *pnVersion, MUTEX mutex);
cc022855 547
da9ac8fc
VK
548TCHAR LIBNETXMS_EXPORTABLE *NXCPMessageCodeName(UINT16 wCode, TCHAR *buffer);
549void LIBNETXMS_EXPORTABLE NXCPRegisterMessageNameResolver(NXCPMessageNameResolver r);
550void LIBNETXMS_EXPORTABLE NXCPUnregisterMessageNameResolver(NXCPMessageNameResolver r);
551
2df047f4 552bool LIBNETXMS_EXPORTABLE InitCryptoLib(UINT32 dwEnabledCiphers);
e5390fb5
VK
553UINT32 LIBNETXMS_EXPORTABLE NXCPGetSupportedCiphers();
554String LIBNETXMS_EXPORTABLE NXCPGetSupportedCiphersAsText();
b368969c 555NXCP_ENCRYPTED_MESSAGE LIBNETXMS_EXPORTABLE *NXCPEncryptMessage(NXCPEncryptionContext *pCtx, NXCP_MESSAGE *pMsg);
bf6fb6c3 556bool LIBNETXMS_EXPORTABLE NXCPDecryptMessage(NXCPEncryptionContext *pCtx,
6be0a20b 557 NXCP_ENCRYPTED_MESSAGE *pMsg,
e44ac467 558 BYTE *pDecryptionBuffer);
b368969c 559UINT32 LIBNETXMS_EXPORTABLE SetupEncryptionContext(NXCPMessage *pMsg,
98abc9f1 560 NXCPEncryptionContext **ppCtx,
b368969c 561 NXCPMessage **ppResponse,
4bd3d6c5 562 RSA *pPrivateKey, int nNXCPVersion);
b368969c 563void LIBNETXMS_EXPORTABLE PrepareKeyRequestMsg(NXCPMessage *pMsg, RSA *pServerKey, bool useX509Format);
3aa0061c 564RSA LIBNETXMS_EXPORTABLE *LoadRSAKeys(const TCHAR *pszKeyFile);
15cf5acc 565
bb8136f7 566#ifdef _WIN32
967893bb 567BOOL LIBNETXMS_EXPORTABLE SignMessageWithCAPI(BYTE *pMsg, UINT32 dwMsgLen, const CERT_CONTEXT *pCert,
b368969c 568 BYTE *pBuffer, size_t bufferSize, UINT32 *pdwSigLen);
bb8136f7
VK
569#endif
570
0d9c1b96
VK
571#endif
572
9f2ad16c 573#endif /* _nxcpapi_h_ */