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