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