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