configuration parameter TopologyPollingInterval added to DB
[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
eae56922
VK
352/**
353 * Message receiver - comm channel implementation
354 */
355class LIBNETXMS_EXPORTABLE CommChannelMessageReceiver : public AbstractMessageReceiver
356{
357private:
358 AbstractCommChannel *m_channel;
359
360protected:
361 virtual int readBytes(BYTE *buffer, size_t size, UINT32 timeout);
362
363public:
364 CommChannelMessageReceiver(AbstractCommChannel *channel, size_t initialSize, size_t maxSize);
365 virtual ~CommChannelMessageReceiver();
366};
367
bf306af3
VK
368#ifdef _WITH_ENCRYPTION
369
370/**
371 * Message receiver - SSL/TLS implementation
372 */
373class LIBNETXMS_EXPORTABLE TlsMessageReceiver : public AbstractMessageReceiver
374{
375private:
376 SOCKET m_socket;
377 SSL *m_ssl;
cce82c3a 378 MUTEX m_mutex;
bf306af3
VK
379
380protected:
381 virtual int readBytes(BYTE *buffer, size_t size, UINT32 timeout);
382
383public:
cce82c3a 384 TlsMessageReceiver(SOCKET socket, SSL *ssl, MUTEX mutex, size_t initialSize, size_t maxSize);
bf306af3
VK
385 virtual ~TlsMessageReceiver();
386};
387
388#endif /* _WITH_ENCRYPTION */
389
6be0a20b
VK
390/**
391 * Message receiver - UNIX socket/named pipe implementation
392 */
393class LIBNETXMS_EXPORTABLE PipeMessageReceiver : public AbstractMessageReceiver
394{
395private:
396 HPIPE m_pipe;
397#ifdef _WIN32
398 HANDLE m_readEvent;
399#endif
400
401protected:
402 virtual int readBytes(BYTE *buffer, size_t size, UINT32 timeout);
403
404public:
405 PipeMessageReceiver(HPIPE pipe, size_t initialSize, size_t maxSize);
406 virtual ~PipeMessageReceiver();
407};
408
503da871 409/**
d3a20572 410 * NXCP stresam compression methods
503da871 411 */
d3a20572 412enum NXCPStreamCompressionMethod
503da871 413{
d3a20572 414 NXCP_STREAM_COMPRESSION_NONE = 0,
90ed558d
VK
415 NXCP_STREAM_COMPRESSION_LZ4 = 1,
416 NXCP_STREAM_COMPRESSION_DEFLATE = 2
503da871
VK
417};
418
419/**
420 * Abstract stream compressor
421 */
422class LIBNETXMS_EXPORTABLE StreamCompressor
423{
424public:
9757ca46
VK
425 virtual ~StreamCompressor();
426
503da871
VK
427 virtual size_t compress(const BYTE *in, size_t inSize, BYTE *out, size_t maxOutSize) = 0;
428 virtual size_t decompress(const BYTE *in, size_t inSize, const BYTE **out) = 0;
429 virtual size_t compressBufferSize(size_t dataSize) = 0;
430
d3a20572 431 static StreamCompressor *create(NXCPStreamCompressionMethod method, bool compress, size_t maxBlockSize);
503da871
VK
432};
433
434/**
435 * Dummy stream compressor
436 */
437class LIBNETXMS_EXPORTABLE DummyStreamCompressor : public StreamCompressor
438{
439public:
9757ca46
VK
440 virtual ~DummyStreamCompressor();
441
503da871
VK
442 virtual size_t compress(const BYTE *in, size_t inSize, BYTE *out, size_t maxOutSize);
443 virtual size_t decompress(const BYTE *in, size_t inSize, const BYTE **out);
444 virtual size_t compressBufferSize(size_t dataSize);
445};
446
447struct __LZ4_stream_t;
448struct __LZ4_streamDecode_t;
449
450/**
451 * LZ4 stream compressor
452 */
453class LIBNETXMS_EXPORTABLE LZ4StreamCompressor : public StreamCompressor
454{
455private:
456 union
457 {
458 __LZ4_stream_t *encoder;
459 __LZ4_streamDecode_t *decoder;
460 } m_stream;
461 char *m_buffer;
462 size_t m_maxBlockSize;
463 size_t m_bufferSize;
464 size_t m_bufferPos;
465 bool m_compress;
466
467public:
468 LZ4StreamCompressor(bool compress, size_t maxBlockSize);
469 virtual ~LZ4StreamCompressor();
470
471 virtual size_t compress(const BYTE *in, size_t inSize, BYTE *out, size_t maxOutSize);
472 virtual size_t decompress(const BYTE *in, size_t inSize, const BYTE **out);
473 virtual size_t compressBufferSize(size_t dataSize);
474};
475
90ed558d
VK
476struct z_stream_s;
477
478/**
479 * Deflate stream compressor
480 */
481class LIBNETXMS_EXPORTABLE DeflateStreamCompressor : public StreamCompressor
482{
483private:
484 z_stream_s *m_stream;
485 BYTE *m_buffer;
486 size_t m_bufferSize;
487 bool m_compress;
488
489public:
490 DeflateStreamCompressor(bool compress, size_t maxBlockSize);
491 virtual ~DeflateStreamCompressor();
492
493 virtual size_t compress(const BYTE *in, size_t inSize, BYTE *out, size_t maxOutSize);
494 virtual size_t decompress(const BYTE *in, size_t inSize, const BYTE **out);
495 virtual size_t compressBufferSize(size_t dataSize);
496};
497
208d7427
VK
498#if 0
499/**
500 * NXCP message consumer interface
501 */
502class LIBNETXMS_EXPORTABLE MessageConsumer
503{
504public:
505 virtual SOCKET getSocket() = 0;
506 virtual void processMessage(NXCPMessage *msg) = 0;
507};
508
509/**
510 * Socket receiver - manages receiving NXCP messages from multiple sockets
511 */
512class LIBNETXMS_EXPORTABLE SocketReceiver
513{
514private:
515 THREAD m_thread;
516 HashMap<SOCKET, MessageConsumer> *m_consumers;
517
518 static int m_maxSocketsPerThread;
519 static ObjectArray<SocketReceiver> *m_receivers;
520
521public:
522 static void start();
523 static void shutdown();
524
525 static void addConsumer(MessageConsumer *mc);
526 static void removeConsumer(MessageConsumer *mc);
527
528 static String getDiagInfo();
529};
530#endif
531
9f2ad16c
VK
532#else /* __cplusplus */
533
b368969c 534typedef void NXCPMessage;
98abc9f1 535typedef void NXCPEncryptionContext;
9f2ad16c
VK
536
537#endif
538
da9ac8fc
VK
539typedef bool (*NXCPMessageNameResolver)(UINT16 code, TCHAR *buffer);
540
deaa4491
VK
541
542//
0d9c1b96
VK
543// Functions
544//
545
546#ifdef __cplusplus
0d9c1b96 547
b368969c
VK
548int LIBNETXMS_EXPORTABLE RecvNXCPMessage(SOCKET hSocket, NXCP_MESSAGE *pMsg,
549 NXCP_BUFFER *pBuffer, UINT32 dwMaxMsgSize,
98abc9f1 550 NXCPEncryptionContext **ppCtx,
967893bb 551 BYTE *pDecryptionBuffer, UINT32 dwTimeout);
e3ff8ad1
VK
552int LIBNETXMS_EXPORTABLE RecvNXCPMessage(AbstractCommChannel *channel, NXCP_MESSAGE *pMsg,
553 NXCP_BUFFER *pBuffer, UINT32 dwMaxMsgSize,
554 NXCPEncryptionContext **ppCtx,
555 BYTE *pDecryptionBuffer, UINT32 dwTimeout);
b368969c
VK
556int LIBNETXMS_EXPORTABLE RecvNXCPMessageEx(SOCKET hSocket, NXCP_MESSAGE **msgBuffer,
557 NXCP_BUFFER *nxcpBuffer, UINT32 *bufferSize,
cc022855 558 NXCPEncryptionContext **ppCtx,
967893bb
VK
559 BYTE **decryptionBuffer, UINT32 dwTimeout,
560 UINT32 maxMsgSize);
e3ff8ad1
VK
561int LIBNETXMS_EXPORTABLE RecvNXCPMessageEx(AbstractCommChannel *channel, NXCP_MESSAGE **msgBuffer,
562 NXCP_BUFFER *nxcpBuffer, UINT32 *bufferSize,
563 NXCPEncryptionContext **ppCtx,
564 BYTE **decryptionBuffer, UINT32 dwTimeout,
565 UINT32 maxMsgSize);
d3a20572
VK
566NXCP_MESSAGE LIBNETXMS_EXPORTABLE *CreateRawNXCPMessage(UINT16 code, UINT32 id, UINT16 flags,
567 const void *data, size_t dataSize,
568 NXCP_MESSAGE *buffer, bool allowCompression);
eae56922 569bool LIBNETXMS_EXPORTABLE SendFileOverNXCP(SOCKET hSocket, UINT32 dwId, const TCHAR *pszFile,
cc022855 570 NXCPEncryptionContext *pCtx, long offset,
7b8b337e 571 void (* progressCallback)(INT64, void *), void *cbArg,
d3a20572 572 MUTEX mutex, NXCPStreamCompressionMethod compressionMethod = NXCP_STREAM_COMPRESSION_NONE);
eae56922
VK
573bool LIBNETXMS_EXPORTABLE SendFileOverNXCP(AbstractCommChannel *channel, UINT32 dwId, const TCHAR *pszFile,
574 NXCPEncryptionContext *pCtx, long offset,
575 void (* progressCallback)(INT64, void *), void *cbArg,
576 MUTEX mutex, NXCPStreamCompressionMethod compressionMethod = NXCP_STREAM_COMPRESSION_NONE);
e3ff8ad1
VK
577bool LIBNETXMS_EXPORTABLE NXCPGetPeerProtocolVersion(SOCKET s, int *pnVersion, MUTEX mutex);
578bool LIBNETXMS_EXPORTABLE NXCPGetPeerProtocolVersion(AbstractCommChannel *channel, int *pnVersion, MUTEX mutex);
cc022855 579
da9ac8fc
VK
580TCHAR LIBNETXMS_EXPORTABLE *NXCPMessageCodeName(UINT16 wCode, TCHAR *buffer);
581void LIBNETXMS_EXPORTABLE NXCPRegisterMessageNameResolver(NXCPMessageNameResolver r);
582void LIBNETXMS_EXPORTABLE NXCPUnregisterMessageNameResolver(NXCPMessageNameResolver r);
583
2df047f4 584bool LIBNETXMS_EXPORTABLE InitCryptoLib(UINT32 dwEnabledCiphers);
e5390fb5
VK
585UINT32 LIBNETXMS_EXPORTABLE NXCPGetSupportedCiphers();
586String LIBNETXMS_EXPORTABLE NXCPGetSupportedCiphersAsText();
b368969c 587NXCP_ENCRYPTED_MESSAGE LIBNETXMS_EXPORTABLE *NXCPEncryptMessage(NXCPEncryptionContext *pCtx, NXCP_MESSAGE *pMsg);
bf6fb6c3 588bool LIBNETXMS_EXPORTABLE NXCPDecryptMessage(NXCPEncryptionContext *pCtx,
6be0a20b 589 NXCP_ENCRYPTED_MESSAGE *pMsg,
e44ac467 590 BYTE *pDecryptionBuffer);
b368969c 591UINT32 LIBNETXMS_EXPORTABLE SetupEncryptionContext(NXCPMessage *pMsg,
98abc9f1 592 NXCPEncryptionContext **ppCtx,
b368969c 593 NXCPMessage **ppResponse,
4bd3d6c5 594 RSA *pPrivateKey, int nNXCPVersion);
b368969c 595void LIBNETXMS_EXPORTABLE PrepareKeyRequestMsg(NXCPMessage *pMsg, RSA *pServerKey, bool useX509Format);
3aa0061c 596RSA LIBNETXMS_EXPORTABLE *LoadRSAKeys(const TCHAR *pszKeyFile);
cce82c3a
VK
597RSA LIBNETXMS_EXPORTABLE *RSAKeyFromData(const BYTE *data, size_t size, bool withPrivate);
598void LIBNETXMS_EXPORTABLE RSAFree(RSA *key);
15cf5acc 599
bb8136f7 600#ifdef _WIN32
967893bb 601BOOL LIBNETXMS_EXPORTABLE SignMessageWithCAPI(BYTE *pMsg, UINT32 dwMsgLen, const CERT_CONTEXT *pCert,
b368969c 602 BYTE *pBuffer, size_t bufferSize, UINT32 *pdwSigLen);
bb8136f7
VK
603#endif
604
0d9c1b96
VK
605#endif
606
9f2ad16c 607#endif /* _nxcpapi_h_ */