initial version of new C++ client library; nxpush converted to new library
authorVictor Kirhenshtein <victor@netxms.org>
Wed, 3 Dec 2014 22:33:43 +0000 (00:33 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Wed, 3 Dec 2014 22:33:43 +0000 (00:33 +0200)
33 files changed:
include/Makefile.am
include/nxclapi.h
include/nxcldefs.h [new file with mode: 0644]
include/nxclient.h [new file with mode: 0644]
include/nxcpapi.h
include/nxlexer_styles.h [deleted file]
include/nxsm_ext.h [deleted file]
netxms.sln
src/agent/core/nxagentd.h
src/agent/subagents/filemgr/filemgr.cpp
src/agent/subagents/filemgr/filemgr.h
src/agent/subagents/filemgr/filemgr.vcproj
src/agent/subagents/portCheck/main.cpp
src/agent/tools/nxapush/nxapush.cpp
src/client/libnxclient/dc.cpp [new file with mode: 0644]
src/client/libnxclient/libnxclient.h [copied from src/libnetxms/libnetxms.h with 74% similarity]
src/client/libnxclient/libnxclient.vcproj [copied from src/agent/subagents/filemgr/filemgr.vcproj with 79% similarity]
src/client/libnxclient/main.cpp [new file with mode: 0644]
src/client/libnxclient/session.cpp [new file with mode: 0644]
src/client/nxpush/nxpush.cpp
src/libnetxms/crypto.cpp
src/libnetxms/libnetxms.h
src/server/core/objtools.cpp
src/server/core/session.cpp
src/server/include/nxsrvapi.h
src/server/libnxsrv/libnxsrv.vcproj
src/server/libnxsrv/main.cpp
src/server/smsdrv/dbemu/dbemu.h
src/server/tools/nxaction/nxaction.cpp
src/server/tools/nxap/nxap.cpp
src/server/tools/nxdbmgr/upgrade.cpp
src/server/tools/nxget/nxget.cpp
src/server/tools/nxupload/nxupload.cpp

index 106fa4f..755770b 100644 (file)
@@ -31,11 +31,12 @@ include_HEADERS = \
        nms_threads.h \
        nms_util.h \
        nxclapi.h \
+       nxcldefs.h \
+       nxclient.h \
        nxconfig.h \
        nxcpapi.h \
        nxdbapi.h \
        nxevent.h \
-       nxlexer_styles.h \
        nxlog.h \
        nxlpapi.h \
        nxmbapi.h \
@@ -43,7 +44,6 @@ include_HEADERS = \
        nxsdapi.h \
        nxsl_classes.h \
        nxsl.h \
-       nxsm_ext.h \
        nxsnmp.h \
        nxstat.h \
        nxtools.h \
index c7c0bf3..7681f9c 100644 (file)
@@ -24,6 +24,8 @@
 #ifndef _nxclapi_h_
 #define _nxclapi_h_
 
+//#error DEPRECATED
+
 #ifdef LIBNXCL_CONSTANTS_ONLY
 
 #ifndef LIBNXCL_NO_DECLARATIONS
diff --git a/include/nxcldefs.h b/include/nxcldefs.h
new file mode 100644 (file)
index 0000000..9ee79d2
--- /dev/null
@@ -0,0 +1,1057 @@
+/*
+** NetXMS - Network Management System
+** Common defines for client library and server
+** Copyright (C) 2003-2014 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: nxcldefs.h
+**
+**/
+
+#ifndef _nxcldefs_h_
+#define _nxcldefs_h_
+
+#include <nxlog.h>
+
+/**
+ * Some constants
+ */
+#define MAX_COMMUNITY_LENGTH     128
+#define MAX_OID_LENGTH           1024
+#define MAX_EVENT_MSG_LENGTH     2000
+#define MAX_EVENT_NAME           64
+#define MAX_USERTAG_LENGTH       64
+#define MAX_SESSION_NAME         256
+#define MAX_USER_NAME            64
+#define MAX_USER_FULLNAME        128
+#define MAX_USER_DESCR           256
+#define MAX_ITEM_NAME            1024
+#define MAX_STRING_VALUE         256
+#define MAX_VARIABLE_NAME        256
+#define MAX_AGENT_VERSION_LEN    64
+#define MAX_PLATFORM_NAME_LEN    64
+#define MAX_PACKAGE_NAME_LEN     64
+#define GROUP_EVERYONE           ((UINT32)0x80000000)
+#define INVALID_UID              ((UINT32)0xFFFFFFFF)
+#define OBJECT_STATUS_COUNT      9
+#define MAX_RCPT_ADDR_LEN        256
+#define MAX_EMAIL_SUBJECT_LEN    256
+#define MAC_ADDR_LENGTH          6
+#define CURRENT_USER             ((UINT32)0xFFFFFFFF)
+#define MAX_DCI_DATA_RECORDS     200000
+#define MAX_POLICY_CONFIG_NAME   64
+
+/**
+ * NetXMS agent authentication methods
+ */
+#define AUTH_NONE             0
+#define AUTH_PLAINTEXT        1
+#define AUTH_MD5_HASH         2
+#define AUTH_SHA1_HASH        3
+
+/**
+ * Client-server authentication types
+ */
+#define NETXMS_AUTH_TYPE_PASSWORD       0
+#define NETXMS_AUTH_TYPE_CERTIFICATE    1
+#define NETXMS_AUTH_TYPE_SSO_TICKET     2
+
+/**
+ * Client type
+ */
+#define CLIENT_TYPE_DESKTOP      0
+#define CLIENT_TYPE_WEB          1
+#define CLIENT_TYPE_MOBILE       2
+#define CLIENT_TYPE_TABLET       3
+#define CLIENT_TYPE_APPLICATION  4
+
+/**
+ * Forced poll types
+ */
+#define POLL_STATUS           1
+#define POLL_CONFIGURATION    2
+#define POLL_INTERFACE_NAMES  3
+#define POLL_TOPOLOGY         4
+
+/**
+ * Object types
+ */
+#define OBJECT_GENERIC              0
+#define OBJECT_SUBNET               1
+#define OBJECT_NODE                 2
+#define OBJECT_INTERFACE            3
+#define OBJECT_NETWORK              4
+#define OBJECT_CONTAINER            5
+#define OBJECT_ZONE                 6
+#define OBJECT_SERVICEROOT          7
+#define OBJECT_TEMPLATE             8
+#define OBJECT_TEMPLATEGROUP        9
+#define OBJECT_TEMPLATEROOT         10
+#define OBJECT_NETWORKSERVICE       11
+#define OBJECT_VPNCONNECTOR         12
+#define OBJECT_CONDITION            13
+#define OBJECT_CLUSTER                       14
+#define OBJECT_POLICYGROUP          15
+#define OBJECT_POLICYROOT           16
+#define OBJECT_AGENTPOLICY          17
+#define OBJECT_AGENTPOLICY_CONFIG   18
+#define OBJECT_NETWORKMAPROOT       19
+#define OBJECT_NETWORKMAPGROUP      20
+#define OBJECT_NETWORKMAP           21
+#define OBJECT_DASHBOARDROOT        22
+#define OBJECT_DASHBOARD            23
+#define OBJECT_BUSINESSSERVICEROOT  27
+#define OBJECT_BUSINESSSERVICE      28
+#define OBJECT_NODELINK             29
+#define OBJECT_SLMCHECK             30
+#define OBJECT_MOBILEDEVICE         31
+#define OBJECT_RACK                 32
+#define OBJECT_ACCESSPOINT          33
+
+/** Base value for custom object classes */
+#define OBJECT_CUSTOM               10000
+
+/**
+ * Object's status
+ */
+#define STATUS_NORMAL         0
+#define STATUS_WARNING        1
+#define STATUS_MINOR          2
+#define STATUS_MAJOR          3
+#define STATUS_CRITICAL       4
+#define STATUS_UNKNOWN        5
+#define STATUS_UNMANAGED      6
+#define STATUS_DISABLED       7
+#define STATUS_TESTING        8
+
+/**
+ * Event and alarm severity
+ */
+#define SEVERITY_NORMAL       0
+#define SEVERITY_WARNING      1
+#define SEVERITY_MINOR        2
+#define SEVERITY_MAJOR        3
+#define SEVERITY_CRITICAL     4
+#define SEVERITY_FROM_EVENT   5
+#define SEVERITY_TERMINATE    6
+#define SEVERITY_RESOLVE      7
+
+/**
+ * Alarm states
+ */
+#define ALARM_STATE_OUTSTANDING  0x00
+#define ALARM_STATE_ACKNOWLEDGED 0x01
+#define ALARM_STATE_RESOLVED     0x02
+#define ALARM_STATE_TERMINATED   0x03
+#define ALARM_STATE_MASK         0x0F          /* mask for selecting alarm state */
+#define ALARM_STATE_STICKY       0x10          /* bit flag indicating sticky state */
+
+/**
+ * Alarm state in help desk system
+ */
+#define ALARM_HELPDESK_IGNORED   0
+#define ALARM_HELPDESK_OPEN      1
+#define ALARM_HELPDESK_CLOSED    2
+
+/**
+ * Node flags
+ */
+#define NF_SYSTEM_FLAGS           0x003FFF7F
+#define NF_USER_FLAGS             0xFFC00080
+
+#define NF_IS_SNMP                0x00000001
+#define NF_IS_NATIVE_AGENT        0x00000002
+#define NF_IS_BRIDGE              0x00000004
+#define NF_IS_ROUTER              0x00000008
+#define NF_IS_LOCAL_MGMT          0x00000010
+#define NF_IS_PRINTER             0x00000020
+#define NF_IS_OSPF                0x00000040
+#define NF_REMOTE_AGENT           0x00000080
+#define NF_IS_CPSNMP              0x00000100  /* CheckPoint SNMP agent on port 260 */
+#define NF_IS_CDP                 0x00000200
+#define NF_IS_NDP                 0x00000400  /* Supports Nortel (Synoptics/Bay Networks) topology discovery */
+#define NF_IS_SONMP               0x00000400  /* SONMP is an old name for NDP */
+#define NF_IS_LLDP                0x00000800 /* Supports Link Layer Discovery Protocol */
+#define NF_IS_VRRP                0x00001000  /* VRRP support */
+#define NF_HAS_VLANS              0x00002000  /* VLAN information available */
+#define NF_IS_8021X               0x00004000  /* 802.1x support enabled on node */
+#define NF_IS_STP                 0x00008000  /* Spanning Tree (IEEE 802.1d) enabled on node */
+#define NF_HAS_ENTITY_MIB         0x00010000  /* Supports ENTITY-MIB */
+#define NF_HAS_IFXTABLE           0x00020000  /* Supports ifXTable */
+#define NF_HAS_AGENT_IFXCOUNTERS  0x00040000  /* Agent supports 64-bit interface counters */
+#define NF_HAS_WINPDH             0x00080000  /* Node supports Windows PDH parameters */
+#define NF_IS_WIFI_CONTROLLER     0x00100000  /* Node is wireless network controller */
+#define NF_IS_SMCLP               0x00200000  /* Node supports SMCLP protocol */
+#define NF_DISABLE_DISCOVERY_POLL 0x00400000
+#define NF_DISABLE_TOPOLOGY_POLL  0x00800000
+#define NF_DISABLE_SNMP           0x01000000
+#define NF_DISABLE_NXCP           0x02000000
+#define NF_DISABLE_ICMP           0x04000000
+#define NF_FORCE_ENCRYPTION       0x08000000
+#define NF_DISABLE_STATUS_POLL    0x10000000
+#define NF_DISABLE_CONF_POLL      0x20000000
+#define NF_DISABLE_ROUTE_POLL     0x40000000
+#define NF_DISABLE_DATA_COLLECT   0x80000000
+
+/**
+ * Template flags
+ */
+#define TF_AUTO_APPLY            0x00000001
+#define TF_AUTO_REMOVE           0x00000002
+
+/**
+ * Container flags
+ */
+#define CF_AUTO_BIND             0x00000001
+#define CF_AUTO_UNBIND           0x00000002
+
+/**
+ * Interface flags
+ */
+#define IF_SYNTHETIC_MASK        0x00000001
+#define IF_PHYSICAL_PORT         0x00000002
+#define IF_EXCLUDE_FROM_TOPOLOGY 0x00000004
+#define IF_LOOPBACK              0x00000008
+#define IF_CREATED_MANUALLY      0x00000010
+#define IF_PEER_REFLECTION       0x00000020  /* topology information obtained by reflection */
+#define IF_EXPECTED_STATE_MASK   0x30000000    /* 2-bit field holding expected interface state */
+#define IF_USER_FLAGS_MASK       (IF_EXCLUDE_FROM_TOPOLOGY)    /* flags that can be changed by user */
+
+/**
+ * Expected interface states
+ */
+#define IF_EXPECTED_STATE_UP     0
+#define IF_EXPECTED_STATE_DOWN   1
+#define IF_EXPECTED_STATE_IGNORE 2
+
+/**
+ * Interface administrative states
+ */
+#define IF_ADMIN_STATE_UNKNOWN   0
+#define IF_ADMIN_STATE_UP        1
+#define IF_ADMIN_STATE_DOWN      2
+#define IF_ADMIN_STATE_TESTING   3
+
+/**
+ * Interface operational states
+ */
+#define IF_OPER_STATE_UNKNOWN    0
+#define IF_OPER_STATE_UP         1
+#define IF_OPER_STATE_DOWN       2
+#define IF_OPER_STATE_TESTING    3
+
+/**
+ * Node ifXTable usage mode
+ */
+#define IFXTABLE_DEFAULT                       0
+#define IFXTABLE_ENABLED                       1
+#define IFXTABLE_DISABLED                      2
+
+/**
+ * Status calculation and propagation algorithms
+ */
+#define SA_CALCULATE_DEFAULT              0
+#define SA_CALCULATE_MOST_CRITICAL        1
+#define SA_CALCULATE_SINGLE_THRESHOLD     2
+#define SA_CALCULATE_MULTIPLE_THRESHOLDS  3
+
+#define SA_PROPAGATE_DEFAULT              0
+#define SA_PROPAGATE_UNCHANGED            1
+#define SA_PROPAGATE_FIXED                2
+#define SA_PROPAGATE_RELATIVE             3
+#define SA_PROPAGATE_TRANSLATED           4
+
+/**
+ * Network map types
+ */
+#define MAP_TYPE_CUSTOM          0
+#define MAP_TYPE_LAYER2_TOPOLOGY 1
+#define MAP_TYPE_IP_TOPOLOGY     2
+
+/**
+ * Components that can be locked by management pack installer
+ */
+#define NXMP_LC_EVENTDB    0
+#define NXMP_LC_EPP        1
+#define NXMP_LC_TRAPCFG    2
+
+/**
+ * Network service types
+ */
+enum
+{
+       NETSRV_CUSTOM,
+       NETSRV_SSH,
+       NETSRV_POP3,
+       NETSRV_SMTP,
+       NETSRV_FTP,
+       NETSRV_HTTP,
+       NETSRV_HTTPS,
+       NETSRV_TELNET
+};
+
+/**
+ * Address list types
+ */
+#define ADDR_LIST_DISCOVERY_TARGETS    1
+#define ADDR_LIST_DISCOVERY_FILTER     2
+
+/**
+ * Discovery filter flags
+ */
+#define DFF_ALLOW_AGENT                0x0001
+#define DFF_ALLOW_SNMP                 0x0002
+#define DFF_ONLY_RANGE                 0x0004
+
+/**
+ * Connection point types
+ */
+#define CP_TYPE_INDIRECT      0
+#define CP_TYPE_DIRECT        1
+#define CP_TYPE_WIRELESS      2
+
+/**
+ * Events
+ */
+#define NXC_EVENT_CONNECTION_BROKEN    1
+#define NXC_EVENT_NEW_ELOG_RECORD      2
+#define NXC_EVENT_USER_DB_CHANGED      3
+#define NXC_EVENT_OBJECT_CHANGED       4
+#define NXC_EVENT_NOTIFICATION         5
+#define NXC_EVENT_DEPLOYMENT_STATUS    6
+#define NXC_EVENT_NEW_SYSLOG_RECORD    7
+#define NXC_EVENT_NEW_SNMP_TRAP        8
+#define NXC_EVENT_SITUATION_UPDATE     9
+#define NXC_EVENT_JOB_CHANGE           10
+
+/**
+ * Session states (used both by client library and server)
+ */
+enum SessionState
+{
+   STATE_DISCONNECTED    = 0,
+   STATE_CONNECTING      = 1,
+   STATE_CONNECTED       = 2,
+   STATE_AUTHENTICATED   = 3
+};
+
+/**
+ * Notification codes
+ */
+#define NX_NOTIFY_SHUTDOWN                   1
+#define NX_NOTIFY_EVENTDB_CHANGED            2
+#define NX_NOTIFY_ALARM_DELETED              3
+#define NX_NOTIFY_NEW_ALARM                  4
+#define NX_NOTIFY_ALARM_CHANGED              5
+#define NX_NOTIFY_ACTION_CREATED             6
+#define NX_NOTIFY_ACTION_MODIFIED            7
+#define NX_NOTIFY_ACTION_DELETED             8
+#define NX_NOTIFY_OBJTOOLS_CHANGED           9
+#define NX_NOTIFY_DBCONN_STATUS              10
+#define NX_NOTIFY_ALARM_TERMINATED           11
+#define NX_NOTIFY_GRAPHS_CHANGED             12
+#define NX_NOTIFY_ETMPL_CHANGED              13
+#define NX_NOTIFY_ETMPL_DELETED              14
+#define NX_NOTIFY_OBJTOOL_DELETED            15
+#define NX_NOTIFY_TRAPCFG_CREATED            16
+#define NX_NOTIFY_TRAPCFG_MODIFIED           17
+#define NX_NOTIFY_TRAPCFG_DELETED            18
+#define NX_NOTIFY_MAPTBL_CHANGED             19
+#define NX_NOTIFY_MAPTBL_DELETED             20
+#define NX_NOTIFY_DCISUMTBL_CHANGED          21
+#define NX_NOTIFY_DCISUMTBL_DELETED          22
+#define NX_NOTIFY_CERTIFICATE_CHANGED        23
+#define NX_NOTIFY_ALARM_STATUS_FLOW_CHANGED  24
+#define NX_NOTIFY_FILE_LIST_CHANGED          25
+#define NX_NOTIFY_FILE_MONITORING_FAILED     26
+#define NX_NOTIFY_SESSION_KILLED             27
+
+/**
+ * Request completion codes
+ */
+#define RCC_SUCCESS                  ((UINT32)0)
+#define RCC_COMPONENT_LOCKED         ((UINT32)1)
+#define RCC_ACCESS_DENIED            ((UINT32)2)
+#define RCC_INVALID_REQUEST          ((UINT32)3)
+#define RCC_TIMEOUT                  ((UINT32)4)
+#define RCC_OUT_OF_STATE_REQUEST     ((UINT32)5)
+#define RCC_DB_FAILURE               ((UINT32)6)
+#define RCC_INVALID_OBJECT_ID        ((UINT32)7)
+#define RCC_ALREADY_EXIST            ((UINT32)8)
+#define RCC_COMM_FAILURE             ((UINT32)9)
+#define RCC_SYSTEM_FAILURE           ((UINT32)10)
+#define RCC_INVALID_USER_ID          ((UINT32)11)
+#define RCC_INVALID_ARGUMENT         ((UINT32)12)
+#define RCC_DUPLICATE_DCI            ((UINT32)13)
+#define RCC_INVALID_DCI_ID           ((UINT32)14)
+#define RCC_OUT_OF_MEMORY            ((UINT32)15)
+#define RCC_IO_ERROR                 ((UINT32)16)
+#define RCC_INCOMPATIBLE_OPERATION   ((UINT32)17)
+#define RCC_OBJECT_CREATION_FAILED   ((UINT32)18)
+#define RCC_OBJECT_LOOP              ((UINT32)19)
+#define RCC_INVALID_OBJECT_NAME      ((UINT32)20)
+#define RCC_INVALID_ALARM_ID         ((UINT32)21)
+#define RCC_INVALID_ACTION_ID        ((UINT32)22)
+#define RCC_OPERATION_IN_PROGRESS    ((UINT32)23)
+#define RCC_DCI_COPY_ERRORS          ((UINT32)24)
+#define RCC_INVALID_EVENT_CODE       ((UINT32)25)
+#define RCC_NO_WOL_INTERFACES        ((UINT32)26)
+#define RCC_NO_MAC_ADDRESS           ((UINT32)27)
+#define RCC_NOT_IMPLEMENTED          ((UINT32)28)
+#define RCC_INVALID_TRAP_ID          ((UINT32)29)
+#define RCC_DCI_NOT_SUPPORTED        ((UINT32)30)
+#define RCC_VERSION_MISMATCH         ((UINT32)31)
+#define RCC_NPI_PARSE_ERROR          ((UINT32)32)
+#define RCC_DUPLICATE_PACKAGE        ((UINT32)33)
+#define RCC_PACKAGE_FILE_EXIST       ((UINT32)34)
+#define RCC_RESOURCE_BUSY            ((UINT32)35)
+#define RCC_INVALID_PACKAGE_ID       ((UINT32)36)
+#define RCC_INVALID_IP_ADDR          ((UINT32)37)
+#define RCC_ACTION_IN_USE            ((UINT32)38)
+#define RCC_VARIABLE_NOT_FOUND       ((UINT32)39)
+#define RCC_BAD_PROTOCOL             ((UINT32)40)
+#define RCC_ADDRESS_IN_USE           ((UINT32)41)
+#define RCC_NO_CIPHERS               ((UINT32)42)
+#define RCC_INVALID_PUBLIC_KEY       ((UINT32)43)
+#define RCC_INVALID_SESSION_KEY      ((UINT32)44)
+#define RCC_NO_ENCRYPTION_SUPPORT    ((UINT32)45)
+#define RCC_INTERNAL_ERROR           ((UINT32)46)
+#define RCC_EXEC_FAILED              ((UINT32)47)
+#define RCC_INVALID_TOOL_ID          ((UINT32)48)
+#define RCC_SNMP_ERROR               ((UINT32)49)
+#define RCC_BAD_REGEXP               ((UINT32)50)
+#define RCC_UNKNOWN_PARAMETER        ((UINT32)51)
+#define RCC_FILE_IO_ERROR            ((UINT32)52)
+#define RCC_CORRUPTED_MIB_FILE       ((UINT32)53)
+#define RCC_TRANSFER_IN_PROGRESS     ((UINT32)54)
+#define RCC_INVALID_JOB_ID           ((UINT32)55)
+#define RCC_INVALID_SCRIPT_ID        ((UINT32)56)
+#define RCC_INVALID_SCRIPT_NAME      ((UINT32)57)
+#define RCC_UNKNOWN_MAP_NAME         ((UINT32)58)
+#define RCC_INVALID_MAP_ID           ((UINT32)59)
+#define RCC_ACCOUNT_DISABLED         ((UINT32)60)
+#define RCC_NO_GRACE_LOGINS          ((UINT32)61)
+#define RCC_CONNECTION_BROKEN        ((UINT32)62)
+#define RCC_INVALID_CONFIG_ID        ((UINT32)63)
+#define RCC_DB_CONNECTION_LOST       ((UINT32)64)
+#define RCC_ALARM_OPEN_IN_HELPDESK   ((UINT32)65)
+#define RCC_ALARM_NOT_OUTSTANDING    ((UINT32)66)
+#define RCC_NOT_PUSH_DCI             ((UINT32)67)
+#define RCC_CONFIG_PARSE_ERROR       ((UINT32)68)
+#define RCC_CONFIG_VALIDATION_ERROR  ((UINT32)69)
+#define RCC_INVALID_GRAPH_ID         ((UINT32)70)
+#define RCC_LOCAL_CRYPTO_ERROR          ((UINT32)71)
+#define RCC_UNSUPPORTED_AUTH_TYPE       ((UINT32)72)
+#define RCC_BAD_CERTIFICATE                     ((UINT32)73)
+#define RCC_INVALID_CERT_ID          ((UINT32)74)
+#define RCC_SNMP_FAILURE             ((UINT32)75)
+#define RCC_NO_L2_TOPOLOGY_SUPPORT      ((UINT32)76)
+#define RCC_INVALID_SITUATION_ID     ((UINT32)77)
+#define RCC_INSTANCE_NOT_FOUND       ((UINT32)78)
+#define RCC_INVALID_EVENT_ID         ((UINT32)79)
+#define RCC_AGENT_ERROR              ((UINT32)80)
+#define RCC_UNKNOWN_VARIABLE         ((UINT32)81)
+#define RCC_RESOURCE_NOT_AVAILABLE   ((UINT32)82)
+#define RCC_JOB_CANCEL_FAILED        ((UINT32)83)
+#define RCC_INVALID_POLICY_ID        ((UINT32)84)
+#define RCC_UNKNOWN_LOG_NAME         ((UINT32)85)
+#define RCC_INVALID_LOG_HANDLE       ((UINT32)86)
+#define RCC_WEAK_PASSWORD            ((UINT32)87)
+#define RCC_REUSED_PASSWORD          ((UINT32)88)
+#define RCC_INVALID_SESSION_HANDLE   ((UINT32)89)
+#define RCC_CLUSTER_MEMBER_ALREADY   ((UINT32)90)
+#define RCC_JOB_HOLD_FAILED          ((UINT32)91)
+#define RCC_JOB_UNHOLD_FAILED        ((UINT32)92)
+#define RCC_ZONE_ID_ALREADY_IN_USE   ((UINT32)93)
+#define RCC_INVALID_ZONE_ID          ((UINT32)94)
+#define RCC_ZONE_NOT_EMPTY           ((UINT32)95)
+#define RCC_NO_COMPONENT_DATA        ((UINT32)96)
+#define RCC_INVALID_ALARM_NOTE_ID    ((UINT32)97)
+#define RCC_ENCRYPTION_ERROR         ((UINT32)98)
+#define RCC_INVALID_MAPPING_TABLE_ID ((UINT32)99)
+#define RCC_NO_SOFTWARE_PACKAGE_DATA ((UINT32)100)
+#define RCC_INVALID_SUMMARY_TABLE_ID ((UINT32)101)
+#define RCC_USER_LOGGED_IN           ((UINT32)102)
+#define RCC_XML_PARSE_ERROR          ((UINT32)103)
+#define RCC_HIGH_QUERY_COST          ((UINT32)104)
+#define RCC_LICENSE_VIOLATION        ((UINT32)105)
+#define RCC_CLIENT_LICENSE_EXCEEDED  ((UINT32)106)
+#define RCC_OBJECT_ALREADY_EXISTS    ((UINT32)107)
+#define RCC_NO_HDLINK                ((UINT32)108)
+#define RCC_HDLINK_COMM_FAILURE      ((UINT32)109)
+#define RCC_HDLINK_ACCESS_DENIED     ((UINT32)110)
+#define RCC_HDLINK_INTERNAL_ERROR    ((UINT32)111)
+#define RCC_NO_LDAP_CONNECTION       ((UINT32)112)
+#define RCC_NO_ROUTING_TABLE         ((UINT32)113)
+#define RCC_NO_FDB                   ((UINT32)114)
+#define RCC_NO_LOCATION_HISTORY      ((UINT32)115)
+#define RCC_OBJECT_IN_USE            ((UINT32)116)
+#define RCC_NXSL_COMPILATION_ERROR   ((UINT32)117)
+#define RCC_NXSL_EXECUTION_ERROR     ((UINT32)118)
+
+/**
+ * Mask bits for NXCModifyEventTemplate()
+ */
+#define EM_SEVERITY        ((UINT32)0x01)
+#define EM_FLAGS           ((UINT32)0x02)
+#define EM_NAME            ((UINT32)0x04)
+#define EM_MESSAGE         ((UINT32)0x08)
+#define EM_DESCRIPTION     ((UINT32)0x10)
+#define EM_ALL             ((UINT32)0x1F)
+
+/**
+ * Mask bits (flags) for NXCModifyObject()
+ */
+#define OBJ_UPDATE_NAME             ((QWORD)_ULL(0x0000000001))
+#define OBJ_UPDATE_AGENT_PORT       ((QWORD)_ULL(0x0000000002))
+#define OBJ_UPDATE_AGENT_AUTH       ((QWORD)_ULL(0x0000000004))
+#define OBJ_UPDATE_AGENT_SECRET     ((QWORD)_ULL(0x0000000008))
+#define OBJ_UPDATE_SNMP_VERSION     ((QWORD)_ULL(0x0000000010))
+#define OBJ_UPDATE_SNMP_AUTH        ((QWORD)_ULL(0x0000000020))
+#define OBJ_UPDATE_ACL              ((QWORD)_ULL(0x0000000040))
+#define OBJ_UPDATE_GEOLOCATION      ((QWORD)_ULL(0x0000000080))
+#define OBJ_UPDATE_SYNC_NETS        ((QWORD)_ULL(0x0000000100))
+#define OBJ_UPDATE_SERVICE_TYPE     ((QWORD)_ULL(0x0000000200))
+#define OBJ_UPDATE_IP_PROTO         ((QWORD)_ULL(0x0000000400))
+#define OBJ_UPDATE_IP_PORT          ((QWORD)_ULL(0x0000000800))
+#define OBJ_UPDATE_CHECK_REQUEST    ((QWORD)_ULL(0x0000001000))
+#define OBJ_UPDATE_CHECK_RESPONSE   ((QWORD)_ULL(0x0000002000))
+#define OBJ_UPDATE_POLLER_NODE      ((QWORD)_ULL(0x0000004000))
+#define OBJ_UPDATE_IP_ADDR          ((QWORD)_ULL(0x0000008000))
+#define OBJ_UPDATE_PEER_GATEWAY     ((QWORD)_ULL(0x0000010000))
+#define OBJ_UPDATE_NETWORK_LIST     ((QWORD)_ULL(0x0000020000))
+#define OBJ_UPDATE_STATUS_ALG       ((QWORD)_ULL(0x0000040000))
+#define OBJ_UPDATE_PROXY_NODE       ((QWORD)_ULL(0x0000080000))
+#define OBJ_UPDATE_FLAGS            ((QWORD)_ULL(0x0000100000))
+#define OBJ_UPDATE_ACT_EVENT        ((QWORD)_ULL(0x0000200000))
+#define OBJ_UPDATE_DEACT_EVENT      ((QWORD)_ULL(0x0000400000))
+#define OBJ_UPDATE_SOURCE_OBJECT    ((QWORD)_ULL(0x0000800000))
+#define OBJ_UPDATE_ACTIVE_STATUS    ((QWORD)_ULL(0x0001000000))
+#define OBJ_UPDATE_INACTIVE_STATUS  ((QWORD)_ULL(0x0002000000))
+#define OBJ_UPDATE_DCI_LIST         ((QWORD)_ULL(0x0004000000))
+#define OBJ_UPDATE_SCRIPT           ((QWORD)_ULL(0x0008000000))
+#define OBJ_UPDATE_CLUSTER_TYPE                ((QWORD)_ULL(0x0010000000))
+#define OBJ_UPDATE_RESOURCES                   ((QWORD)_ULL(0x0020000000))
+#define OBJ_UPDATE_SNMP_PROXY                  ((QWORD)_ULL(0x0040000000))
+#define OBJ_UPDATE_REQUIRED_POLLS   ((QWORD)_ULL(0x0080000000))
+#define OBJ_UPDATE_TRUSTED_NODES    ((QWORD)_ULL(0x0100000000))
+#define OBJ_UPDATE_CUSTOM_ATTRS     ((QWORD)_ULL(0x0200000000))
+#define OBJ_UPDATE_USE_IFXTABLE     ((QWORD)_ULL(0x0400000000))
+#define OBJ_UPDATE_AUTOBIND         ((QWORD)_ULL(0x1000000000))
+#define OBJ_UPDATE_SNMP_PORT        ((QWORD)_ULL(0x2000000000))
+#define OBJ_UPDATE_PRIMARY_NAME     ((QWORD)_ULL(0x4000000000))
+
+/**
+ * Global user rights
+ */
+#ifndef NETXMS_CUSTOM_USER_RIGHTS
+
+#define SYSTEM_ACCESS_MANAGE_USERS        _ULL(0x00000001)
+#define SYSTEM_ACCESS_SERVER_CONFIG       _ULL(0x00000002)
+#define SYSTEM_ACCESS_CONFIGURE_TRAPS     _ULL(0x00000004)
+#define SYSTEM_ACCESS_MANAGE_SESSIONS     _ULL(0x00000008)
+#define SYSTEM_ACCESS_VIEW_EVENT_DB       _ULL(0x00000010)
+#define SYSTEM_ACCESS_EDIT_EVENT_DB       _ULL(0x00000020)
+#define SYSTEM_ACCESS_EPP                 _ULL(0x00000040)
+#define SYSTEM_ACCESS_MANAGE_ACTIONS      _ULL(0x00000080)
+#define SYSTEM_ACCESS_DELETE_ALARMS       _ULL(0x00000100)
+#define SYSTEM_ACCESS_MANAGE_PACKAGES     _ULL(0x00000200)
+#define SYSTEM_ACCESS_VIEW_EVENT_LOG      _ULL(0x00000400)
+#define SYSTEM_ACCESS_MANAGE_TOOLS        _ULL(0x00000800)
+#define SYSTEM_ACCESS_MANAGE_SCRIPTS      _ULL(0x00001000)
+#define SYSTEM_ACCESS_VIEW_TRAP_LOG       _ULL(0x00002000)
+#define SYSTEM_ACCESS_VIEW_AUDIT_LOG      _ULL(0x00004000)
+#define SYSTEM_ACCESS_MANAGE_AGENT_CFG    _ULL(0x00008000)
+#define SYSTEM_ACCESS_MANAGE_SITUATIONS   _ULL(0x00010000)
+#define SYSTEM_ACCESS_SEND_SMS            _ULL(0x00020000)
+#define SYSTEM_ACCESS_MOBILE_DEVICE_LOGIN _ULL(0x00040000)
+#define SYSTEM_ACCESS_REGISTER_AGENTS     _ULL(0x00080000)
+#define SYSTEM_ACCESS_READ_FILES          _ULL(0x00100000)
+#define SYSTEM_ACCESS_SERVER_CONSOLE      _ULL(0x00200000)
+#define SYSTEM_ACCESS_MANAGE_FILES        _ULL(0x00400000)
+#define SYSTEM_ACCESS_MANAGE_MAPPING_TBLS _ULL(0x00800000)
+#define SYSTEM_ACCESS_MANAGE_SUMMARY_TBLS _ULL(0x01000000)
+#define SYSTEM_ACCESS_REPORTING_SERVER    _ULL(0x02000000)
+#define SYSTEM_ACCESS_XMPP_COMMANDS       _ULL(0x04000000)
+#define SYSTEM_ACCESS_MANAGE_IMAGE_LIB    _ULL(0x08000000)
+#define SYSTEM_ACCESS_UNLINK_ISSUES       _ULL(0x10000000)
+#define SYSTEM_ACCESS_VIEW_SYSLOG         _ULL(0x20000000)
+
+#define SYSTEM_ACCESS_FULL                _ULL(0x3FFFFFFF)
+
+#endif /* NETXMS_CUSTOM_USER_RIGHTS */
+
+/**
+ * Object access rights
+ */
+#define OBJECT_ACCESS_READ          0x00000001
+#define OBJECT_ACCESS_MODIFY        0x00000002
+#define OBJECT_ACCESS_CREATE        0x00000004
+#define OBJECT_ACCESS_DELETE        0x00000008
+#define OBJECT_ACCESS_READ_ALARMS   0x00000010
+#define OBJECT_ACCESS_ACL           0x00000020
+#define OBJECT_ACCESS_UPDATE_ALARMS 0x00000040
+#define OBJECT_ACCESS_SEND_EVENTS   0x00000080
+#define OBJECT_ACCESS_CONTROL       0x00000100
+#define OBJECT_ACCESS_TERM_ALARMS   0x00000200
+#define OBJECT_ACCESS_PUSH_DATA     0x00000400
+#define OBJECT_ACCESS_CREATE_ISSUE  0x00000800
+#define OBJECT_ACCESS_DOWNLOAD      0x00001000
+#define OBJECT_ACCESS_UPLOAD        0x00002000
+#define OBJECT_ACCESS_MANAGE_FILES  0x00004000
+
+/**
+ * Object sync flags
+ */
+#define OBJECT_SYNC_SEND_UPDATES    0x0001
+#define OBJECT_SYNC_DUAL_CONFIRM    0x0002
+
+/**
+ * User/group flags
+ */
+#define UF_MODIFIED                 0x0001
+#define UF_DELETED                  0x0002
+#define UF_DISABLED                 0x0004
+#define UF_CHANGE_PASSWORD          0x0008
+#define UF_CANNOT_CHANGE_PASSWORD   0x0010
+#define UF_INTRUDER_LOCKOUT         0x0020
+#define UF_PASSWORD_NEVER_EXPIRES   0x0040
+#define UF_LDAP_USER                0x0080
+#define UF_SYNC_EXCEPTION           0x0100
+
+/**
+ * Fields for NXCModifyUserEx
+ */
+#define USER_MODIFY_LOGIN_NAME         0x00000001
+#define USER_MODIFY_DESCRIPTION        0x00000002
+#define USER_MODIFY_FULL_NAME          0x00000004
+#define USER_MODIFY_FLAGS              0x00000008
+#define USER_MODIFY_ACCESS_RIGHTS      0x00000010
+#define USER_MODIFY_MEMBERS            0x00000020
+#define USER_MODIFY_CERT_MAPPING       0x00000040
+#define USER_MODIFY_AUTH_METHOD        0x00000080
+#define USER_MODIFY_PASSWD_LENGTH      0x00000100
+#define USER_MODIFY_TEMP_DISABLE       0x00000200
+#define USER_MODIFY_CUSTOM_ATTRIBUTES  0x00000400
+#define USER_MODIFY_XMPP_ID            0x00000800
+#define USER_MODIFY_GROUP_MEMBERSHIP   0x00001000
+
+/**
+ * User certificate mapping methods
+ */
+#define USER_MAP_CERT_BY_SUBJECT    0
+#define USER_MAP_CERT_BY_PUBKEY     1
+#define USER_MAP_CERT_BY_CN         2
+
+/**
+ * User database change notification types
+ */
+#define USER_DB_CREATE              0
+#define USER_DB_DELETE              1
+#define USER_DB_MODIFY              2
+
+/**
+ * Situation change notification types
+ */
+#define SITUATION_CREATE            1
+#define SITUATION_DELETE            2
+#define SITUATION_UPDATE            3
+#define SITUATION_INSTANCE_UPDATE   4
+#define SITUATION_INSTANCE_DELETE   5
+
+/**
+ * Data collection object types
+ */
+#define DCO_TYPE_GENERIC   0
+#define DCO_TYPE_ITEM      1
+#define DCO_TYPE_TABLE     2
+
+/**
+ * DCI flags
+ */
+#define DCF_ADVANCED_SCHEDULE       ((UINT16)0x0001)
+#define DCF_ALL_THRESHOLDS          ((UINT16)0x0002)
+#define DCF_RAW_VALUE_OCTET_STRING  ((UINT16)0x0004)
+#define DCF_SHOW_ON_OBJECT_TOOLTIP  ((UINT16)0x0008)
+#define DCF_AGGREGATE_FUNCTION_MASK ((UINT16)0x0070)
+#define DCF_AGGREGATE_ON_CLUSTER    ((UINT16)0x0080)
+#define DCF_TRANSFORM_AGGREGATED    ((UINT16)0x0100)
+#define DCF_NO_STORAGE              ((UINT16)0x0200)
+#define DCF_CALCULATE_NODE_STATUSS  ((UINT16)0x0400)
+
+/**
+ * Get cluster aggregation function from DCI flags
+ */
+#define DCF_GET_AGGREGATION_FUNCTION(flags) (((flags) & DCF_AGGREGATE_FUNCTION_MASK) >> 4)
+#define DCF_SET_AGGREGATION_FUNCTION(flags,func) (((flags) & ~DCF_AGGREGATE_FUNCTION_MASK) | (((func) & 0x07) << 4))
+
+/**
+ * DCTable column flags
+ */
+#define TCF_DATA_TYPE_MASK          ((UINT16)0x000F)
+#define TCF_AGGREGATE_FUNCTION_MASK ((UINT16)0x0070)
+#define TCF_INSTANCE_COLUMN         ((UINT16)0x0100)
+#define TCF_INSTANCE_LABEL_COLUMN   ((UINT16)0x0200)
+
+/**
+ * Get cluster aggregation function from column flags
+ */
+#define TCF_GET_AGGREGATION_FUNCTION(flags) (((flags) & TCF_AGGREGATE_FUNCTION_MASK) >> 4)
+#define TCF_SET_AGGREGATION_FUNCTION(flags,func) (((flags) & ~DCF_AGGREGATE_FUNCTION_MASK) | (((func) & 0x07) << 4))
+
+/**
+ * Get data type from column flags
+ */
+#define TCF_GET_DATA_TYPE(flags) ((flags) & TCF_DATA_TYPE_MASK)
+#define TCF_SET_DATA_TYPE(flags,dt) (((flags) & ~TCF_DATA_TYPE_MASK) | ((dt) & 0x0F))
+
+/**
+ * Aggregation functions
+ */
+#define DCF_FUNCTION_SUM 0
+#define DCF_FUNCTION_AVG 1
+#define DCF_FUNCTION_MIN 2
+#define DCF_FUNCTION_MAX 3
+
+/**
+ * SNMP raw types
+ */
+#define SNMP_RAWTYPE_NONE           0
+#define SNMP_RAWTYPE_INT32          1
+#define SNMP_RAWTYPE_UINT32         2
+#define SNMP_RAWTYPE_INT64          3
+#define SNMP_RAWTYPE_UINT64         4
+#define SNMP_RAWTYPE_DOUBLE         5
+#define SNMP_RAWTYPE_IP_ADDR        6
+#define SNMP_RAWTYPE_MAC_ADDR       7
+
+/**
+ * Data sources
+ */
+#define DS_INTERNAL           0
+#define DS_NATIVE_AGENT       1
+#define DS_SNMP_AGENT         2
+#define DS_CHECKPOINT_AGENT   3
+#define DS_PUSH_AGENT         4
+#define DS_WINPERF            5
+#define DS_SMCLP              6
+#define DS_SCRIPT             7
+
+/**
+ * Item status
+ */
+#define ITEM_STATUS_ACTIVE          0
+#define ITEM_STATUS_DISABLED        1
+#define ITEM_STATUS_NOT_SUPPORTED   2
+
+/**
+ * Delta calculation methods for DCIs
+ */
+#define DCM_ORIGINAL_VALUE       0
+#define DCM_SIMPLE               1
+#define DCM_AVERAGE_PER_SECOND   2
+#define DCM_AVERAGE_PER_MINUTE   3
+
+/**
+ * Threshold functions
+ */
+#define F_LAST       0
+#define F_AVERAGE    1
+#define F_DEVIATION  2
+#define F_DIFF       3
+#define F_ERROR      4
+#define F_SUM        5
+#define F_SCRIPT     6
+
+/**
+ * DCI aggregation functions
+ */
+enum AggregationFunction
+{
+   DCI_AGG_LAST = 0,
+   DCI_AGG_MIN = 1,
+   DCI_AGG_MAX = 2,
+   DCI_AGG_AVG = 3,
+   DCI_AGG_SUM = 4
+};
+
+/**
+ * Threshold operations
+ */
+#define OP_LE        0
+#define OP_LE_EQ     1
+#define OP_EQ        2
+#define OP_GT_EQ     3
+#define OP_GT        4
+#define OP_NE        5
+#define OP_LIKE      6
+#define OP_NOTLIKE   7
+
+/**
+ * DCI base units
+ */
+#define DCI_BASEUNITS_OTHER             0
+#define DCI_BASEUNITS_CUSTOM            1
+#define DCI_BASEUNITS_BYTES             2
+#define DCI_BASEUNITS_BITS              3
+#define DCI_BASEUNITS_SECONDS           4
+#define DCI_BASEUNITS_PERCENTS          5
+#define DCI_BASEUNITS_BITS_PER_SECOND   6
+#define DCI_BASEUNITS_BYTES_PER_SECOND  7
+
+/**
+ * DCI instance discovery methods
+ */
+#define IDM_NONE                        0
+#define IDM_AGENT_LIST                  1
+#define IDM_AGENT_TABLE                 2
+#define IDM_SNMP_WALK_VALUES            3
+#define IDM_SNMP_WALK_OIDS              4
+
+/**
+ * Event policy rule flags
+ */
+#define RF_STOP_PROCESSING       0x0001
+#define RF_NEGATED_SOURCE        0x0002
+#define RF_NEGATED_EVENTS        0x0004
+#define RF_GENERATE_ALARM        0x0008
+#define RF_DISABLED              0x0010
+#define RF_TERMINATE_BY_REGEXP   0x0020
+#define RF_SEVERITY_INFO         0x0100
+#define RF_SEVERITY_WARNING      0x0200
+#define RF_SEVERITY_MINOR        0x0400
+#define RF_SEVERITY_MAJOR        0x0800
+#define RF_SEVERITY_CRITICAL     0x1000
+
+/**
+ * Action types
+ */
+#define ACTION_EXEC           0
+#define ACTION_REMOTE         1
+#define ACTION_SEND_EMAIL     2
+#define ACTION_SEND_SMS       3
+#define ACTION_FORWARD_EVENT  4
+#define ACTION_NXSL_SCRIPT    5
+#define ACTION_XMPP_MESSAGE   6
+
+/**
+ * Network map types
+ */
+#define NETMAP_USER_DEFINED   0
+#define NETMAP_IP_TOPOLOGY    1
+#define NETMAP_L2_TOPOLOGY    2
+
+/**
+ * Network map flags
+ */
+#define MF_SHOW_STATUS_ICON      0x00000001
+#define MF_SHOW_STATUS_FRAME     0x00000002
+#define MF_SHOW_STATUS_BKGND     0x00000004
+#define MF_SHOW_END_NODES        0x00000008
+#define MF_CALCULATE_STATUS      0x00000010
+
+/**
+ * Network map layouts
+ */
+#define MAP_LAYOUT_MANUAL        0x7FFF
+#define MAP_LAYOUT_SPRING        0
+#define MAP_LAYOUT_RADIAL        1
+#define MAP_LAYOUT_HTREE         2
+#define MAP_LAYOUT_VTREE                  3
+#define MAP_LAYOUT_SPARSE_VTREE  4
+
+
+//
+// Deployment manager status codes
+//
+
+#define DEPLOYMENT_STATUS_PENDING      0
+#define DEPLOYMENT_STATUS_TRANSFER     1
+#define DEPLOYMENT_STATUS_INSTALLATION 2
+#define DEPLOYMENT_STATUS_COMPLETED    3
+#define DEPLOYMENT_STATUS_FAILED       4
+#define DEPLOYMENT_STATUS_INITIALIZE   5
+#define DEPLOYMENT_STATUS_FINISHED     255
+
+/**
+ * Session subscription codes (data channels)
+ */
+#define NXC_CHANNEL_EVENTS       0x00000001
+#define NXC_CHANNEL_SYSLOG       0x00000002
+#define NXC_CHANNEL_ALARMS       0x00000004
+#define NXC_CHANNEL_OBJECTS      0x00000008
+#define NXC_CHANNEL_SNMP_TRAPS   0x00000010
+#define NXC_CHANNEL_AUDIT_LOG    0x00000020
+#define NXC_CHANNEL_SITUATIONS   0x00000040
+
+
+//
+// Node creation flags
+//
+
+#define NXC_NCF_DISABLE_ICMP     0x0001
+#define NXC_NCF_DISABLE_NXCP     0x0002
+#define NXC_NCF_DISABLE_SNMP     0x0004
+#define NXC_NCF_CREATE_UNMANAGED 0x0008
+
+
+//
+// Server components
+//
+
+#define SRV_COMPONENT_DISCOVERY_MGR    1
+
+
+//
+// Configuration import flags
+//
+
+#define CFG_IMPORT_REPLACE_EVENT_BY_CODE   0x0001
+#define CFG_IMPORT_REPLACE_EVENT_BY_NAME   0x0002
+
+
+//
+// Graph access flags
+//
+
+#define NXGRAPH_ACCESS_READ            0x01
+#define NXGRAPH_ACCESS_WRITE           0x02
+
+
+//
+// Cluster types
+//
+
+#define CLUSTER_TYPE_GENERIC                   0
+
+
+//
+// SNMP trap flags
+//
+
+#define TRAP_VARBIND_FORCE_TEXT     0x0001
+
+/**
+ * IP network
+ */
+typedef struct
+{
+   UINT32 dwAddr;
+   UINT32 dwMask;
+} IP_NETWORK;
+
+/**
+ * Agent's parameter information
+ */
+typedef struct
+{
+   TCHAR szName[MAX_PARAM_NAME];
+   TCHAR szDescription[MAX_DB_STRING];
+   int iDataType;
+} NXC_AGENT_PARAM;
+
+/**
+ * Server action definition structure
+ */
+typedef struct
+{
+   UINT32 dwId;
+   int iType;
+   BOOL bIsDisabled;
+   TCHAR szName[MAX_OBJECT_NAME];
+   TCHAR szRcptAddr[MAX_RCPT_ADDR_LEN];
+   TCHAR szEmailSubject[MAX_EMAIL_SUBJECT_LEN];
+   TCHAR *pszData;
+} NXC_ACTION;
+
+/**
+ * Alarm structure
+ */
+typedef struct
+{
+   QWORD qwSourceEventId;  // Originating event ID
+   UINT32 dwAlarmId;        // Unique alarm ID
+   UINT32 dwCreationTime;   // Alarm creation time in UNIX time format
+   UINT32 dwLastChangeTime; // Alarm's last change time in UNIX time format
+   UINT32 dwSourceObject;   // Source object ID
+   UINT32 dwSourceEventCode;// Originating event code
+   BYTE nCurrentSeverity;  // Alarm's current severity
+   BYTE nOriginalSeverity; // Alarm's original severity
+   BYTE nState;            // Current state
+   BYTE nHelpDeskState;    // State of alarm in helpdesk system
+   UINT32 dwAckByUser;      // ID of user who was acknowledged this alarm (0 for system)
+       UINT32 dwResolvedByUser; // ID of user who was resolved this alarm (0 for system)
+   UINT32 dwTermByUser;     // ID of user who was terminated this alarm (0 for system)
+   UINT32 dwRepeatCount;
+       UINT32 dwTimeout;
+       UINT32 dwTimeoutEvent;
+   TCHAR szMessage[MAX_EVENT_MSG_LENGTH];
+   TCHAR szKey[MAX_DB_STRING];
+   TCHAR szHelpDeskRef[MAX_HELPDESK_REF_LEN];
+   void *pUserData;        // Can be freely used by client application
+       UINT32 noteCount;        // Number of notes added to alarm
+   UINT32 ackTimeout;  // Sticky acknowledgment end time. If acknowladgmant without timeout put 0
+} NXC_ALARM;
+
+/**
+ * Trap parameter mapping entry
+ */
+typedef struct
+{
+   UINT32 *pdwObjectId;     // Trap OID
+   UINT32 dwOidLen;         // Trap OID length (if highest bit is set, then it's a position)
+       UINT32 dwFlags;
+   TCHAR szDescription[MAX_DB_STRING];
+} NXC_OID_MAP;
+
+/**
+ * Trap configuration entry
+ */
+typedef struct
+{
+   UINT32 dwId;             // Entry ID
+   UINT32 *pdwObjectId;     // Trap OID
+   UINT32 dwOidLen;         // Trap OID length
+   UINT32 dwEventCode;      // Event code
+   UINT32 dwNumMaps;        // Number of parameter mappings
+   NXC_OID_MAP *pMaps;
+   TCHAR szDescription[MAX_DB_STRING];
+       TCHAR szUserTag[MAX_USERTAG_LENGTH];
+} NXC_TRAP_CFG_ENTRY;
+
+/**
+ * Condition's input DCI definition
+ */
+typedef struct
+{
+   UINT32 id;
+   UINT32 nodeId;
+   int function;    // Average, last, diff
+   int polls;       // Number of polls used for average
+} INPUT_DCI;
+
+/**
+ * Cluster resource
+ */
+typedef struct
+{
+       UINT32 dwId;
+       TCHAR szName[MAX_DB_STRING];
+       UINT32 dwIpAddr;
+       UINT32 dwCurrOwner;
+} CLUSTER_RESOURCE;
+
+#endif   /* _nxcldefs_h_ */
diff --git a/include/nxclient.h b/include/nxclient.h
new file mode 100644 (file)
index 0000000..dabd4b6
--- /dev/null
@@ -0,0 +1,212 @@
+/*
+** NetXMS - Network Management System
+** Client Library API
+** Copyright (C) 2003-2014 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: nxclient.h
+**
+**/
+
+#ifndef _nxclient_h_
+#define _nxclient_h_
+
+#include <nms_common.h>
+#include <nms_util.h>
+#include <nxevent.h>
+#include <nxcpapi.h>
+#include <nxtools.h>
+#include <nxlog.h>
+#include <uuid.h>
+#include <nxcldefs.h>
+
+#ifdef _WIN32
+#ifdef LIBNXCLIENT_EXPORTS
+#define LIBNXCLIENT_EXPORTABLE __declspec(dllexport)
+#else
+#define LIBNXCLIENT_EXPORTABLE __declspec(dllimport)
+#endif
+#else    /* _WIN32 */
+#define LIBNXCLIENT_EXPORTABLE
+#endif
+
+#define MAX_TZ_LEN         32
+
+/**
+ * NXCSession::connect flags
+ */
+#define NXCF_DEFAULT                                              0
+#define NXCF_ENCRYPT                                              0x0001
+#define NXCF_EXACT_VERSION_MATCH                  0x0002
+#define NXCF_USE_CERTIFICATE                      0x0004
+#define NXCF_IGNORE_PROTOCOL_VERSION   0x0008
+
+/**
+ * Standard controller names
+ */
+#define CONTROLLER_ALARMS           _T("ALARMS")
+#define CONTROLLER_DATA_COLLECTION  _T("DATACOLL")
+#define CONTROLLER_EVENTS           _T("EVENTS")
+#define CONTROLLER_OBJECTS          _T("OBJECTS")
+
+/**
+ * DCI push data
+ */
+struct NXCPushData
+{
+   UINT32 dciId;          // DCI ID or 0 if name is used
+   TCHAR *dciName;
+   UINT32 nodeId;      // Node ID or 0 if name is used
+   TCHAR *nodeName;
+   TCHAR *value;
+};
+
+/**
+ * Debug callback
+ */
+typedef void (* NXC_DEBUG_CALLBACK)(const TCHAR *msg);
+
+class NXCSession;
+
+/**
+ * Abstract controller class
+ */
+class LIBNXCLIENT_EXPORTABLE Controller
+{
+protected:
+   NXCSession *m_session;
+
+public:
+   Controller(NXCSession *session) { m_session = session; }
+};
+
+/**
+ * Alarm controller
+ */
+class LIBNXCLIENT_EXPORTABLE AlarmController : public Controller
+{
+public:
+   AlarmController(NXCSession *session) : Controller(session) { }
+
+   UINT32 acknowledge(UINT32 alarmId, bool sticky = false);
+   UINT32 resolve(UINT32 alarmId);
+   UINT32 terminate(UINT32 alarmId);
+   ObjectArray<NXC_ALARM> *get();
+};
+
+/**
+ * Data collection controller
+ */
+class LIBNXCLIENT_EXPORTABLE DataCollectionController : public Controller
+{
+public:
+   DataCollectionController(NXCSession *session) : Controller(session) { }
+
+   UINT32 pushData(ObjectArray<NXCPushData> *data, UINT32 *failedIndex = NULL);
+};
+
+/**
+ * Event controller
+ */
+class LIBNXCLIENT_EXPORTABLE EventController : public Controller
+{
+public:
+   EventController(NXCSession *session) : Controller(session) { }
+};
+
+/**
+ * Object controller
+ */
+class LIBNXCLIENT_EXPORTABLE ObjectController : public Controller
+{
+public:
+   ObjectController(NXCSession *session) : Controller(session) { }
+
+   UINT32 manage(UINT32 objectId);
+   UINT32 unmanage(UINT32 objectId);
+};
+
+/**
+ * Session
+ */
+class LIBNXCLIENT_EXPORTABLE NXCSession
+{
+private:
+   THREAD m_receiverThread;
+
+   static THREAD_RESULT THREAD_CALL receiverThreadStarter(void *arg);
+   void receiverThread();
+
+protected:
+   // communications
+   bool m_connected;
+   bool m_disconnected;
+   VolatileCounter m_msgId;
+   SOCKET m_hSocket;
+   MsgWaitQueue *m_msgWaitQueue;
+   NXCPEncryptionContext *m_encryptionContext;
+   UINT32 m_commandTimeout;
+
+   // server information
+   BYTE m_serverId[8];
+   TCHAR m_serverVersion[64];
+   TCHAR m_serverTimeZone[MAX_TZ_LEN];
+   UINT32 m_userId;
+   UINT64 m_systemRights;
+   bool m_passwordChangeNeeded;
+
+   // data
+   MUTEX m_dataLock;
+   MUTEX m_msgSendLock;
+   StringObjectMap<Controller> *m_controllers;
+
+   void onNotify(NXCPMessage *msg);
+
+public:
+   NXCSession();
+   virtual ~NXCSession();
+
+   UINT32 connect(const TCHAR *host, const TCHAR *login, const TCHAR *password, UINT32 flags = NXCF_DEFAULT, const TCHAR *clientInfo = NULL);
+   void disconnect();
+
+   UINT32 createMessageId() { return InterlockedIncrement(&m_msgId); }
+   bool sendMessage(NXCPMessage *msg);
+   NXCPMessage *waitForMessage(UINT16 code, UINT32 id, UINT32 timeout = 0);
+   UINT32 waitForRCC(UINT32 id, UINT32 timeout = 0);
+
+   void setCommandTimeout(UINT32 timeout) { m_commandTimeout = timeout; }
+   UINT32 getCommandTimeout() { return m_commandTimeout; }
+
+   const TCHAR *getServerVersion() { return m_serverVersion; }
+   const TCHAR *getServerTimeZone() { return m_serverTimeZone; }
+   UINT32 getUserId() { return m_userId; }
+   UINT64 getSystemRights() { return m_systemRights; }
+   bool isPasswordChangeNeeded() { return m_passwordChangeNeeded; }
+
+   Controller *getController(const TCHAR *name);
+};
+
+/**
+ * Functions
+ */
+UINT32 LIBNXCLIENT_EXPORTABLE NXCGetVersion();
+const TCHAR LIBNXCLIENT_EXPORTABLE *NXCGetErrorText(UINT32 rcc);
+
+bool LIBNXCLIENT_EXPORTABLE NXCInitialize();
+void LIBNXCLIENT_EXPORTABLE NXCShutdown();
+void LIBNXCLIENT_EXPORTABLE NXCSetDebugCallback(NXC_DEBUG_CALLBACK cb);
+
+#endif   /* _nxclient_h_ */
index 06d350a..2d3318c 100644 (file)
@@ -24,8 +24,8 @@
 #ifndef _nxcpapi_h_
 #define _nxcpapi_h_
 
-#include <nms_threads.h>
 #include <nms_util.h>
+#include <nms_threads.h>
 
 #ifdef _WIN32
 #include <wincrypt.h>
@@ -363,10 +363,10 @@ BOOL LIBNETXMS_EXPORTABLE SendFileOverNXCP(SOCKET hSocket, UINT32 dwId, const TC
                                                                                                                 MUTEX mutex);
 BOOL LIBNETXMS_EXPORTABLE NXCPGetPeerProtocolVersion(SOCKET hSocket, int *pnVersion, MUTEX mutex);
 
-BOOL LIBNETXMS_EXPORTABLE InitCryptoLib(UINT32 dwEnabledCiphers, void (*debugCallback)(int, const TCHAR *, va_list args));
+bool LIBNETXMS_EXPORTABLE InitCryptoLib(UINT32 dwEnabledCiphers, void (*debugCallback)(int, const TCHAR *, va_list args));
 UINT32 LIBNETXMS_EXPORTABLE CSCPGetSupportedCiphers();
 NXCP_ENCRYPTED_MESSAGE LIBNETXMS_EXPORTABLE *NXCPEncryptMessage(NXCPEncryptionContext *pCtx, NXCP_MESSAGE *pMsg);
-BOOL LIBNETXMS_EXPORTABLE NXCPDecryptMessage(NXCPEncryptionContext *pCtx,
+bool LIBNETXMS_EXPORTABLE NXCPDecryptMessage(NXCPEncryptionContext *pCtx,
                                              NXCP_ENCRYPTED_MESSAGE *pMsg,
                                              BYTE *pDecryptionBuffer);
 UINT32 LIBNETXMS_EXPORTABLE SetupEncryptionContext(NXCPMessage *pMsg,
diff --git a/include/nxlexer_styles.h b/include/nxlexer_styles.h
deleted file mode 100644 (file)
index 2eacfa7..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/* 
-** NetXMS - Network Management System
-** Windows UI Library
-** Copyright (C) 2006 Victor Kirhenshtein
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-**
-** $module: nxlexer_styles.h
-**
-**/
-
-#ifndef _nxlexer_styles_h_
-#define _nxlexer_styles_h_
-
-
-//
-// Default lexer styles
-//
-
-#define NX_STYLE_DEFAULT      0
-#define NX_STYLE_COMMENT      1
-#define NX_STYLE_KEYWORD      2
-#define NX_STYLE_STRING       3
-#define NX_STYLE_CONSTANT     4
-#define NX_STYLE_ERROR        5
-#define NX_STYLE_SYMBOL       6
-#define NX_STYLE_SECTION      7
-#define NX_STYLE_ML_COMMENT   8
-#define NX_STYLE_TIMESTAMP    9
-#define NX_STYLE_POLL_INFO    10
-#define NX_STYLE_POLL_WARNING 11
-#define NX_STYLE_POLL_ERROR   12
-#define NX_STYLE_HIDDEN       13
-
-
-#endif
diff --git a/include/nxsm_ext.h b/include/nxsm_ext.h
deleted file mode 100644 (file)
index c683c54..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/* $Id$ */
-/* 
-** NetXMS - Network Management System
-** Session Manager
-** Copyright (C) 2005 Alex Kirhenshtein
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-**
-**/
-
-#ifndef __NXSM_EXT__H__
-#define __NXSM_EXT__H__
-
-enum
-{
-       CMD_NXSM_LOGIN,
-       CMD_NXSM_CHECK_SESSION,
-       CMD_NXSM_LOGOUT,
-
-       CMD_NXSM_GET_OBJECTS,
-       CMD_NXSM_GET_ALARMS,
-       CMD_NXSM_ALARM_ACK,
-
-       CMD_NXSM_STATUS,
-
-       CMD_NXSM_GET_OBJECT_INFO,
-
-       CMD_NXSM_LAST
-};
-
-enum
-{
-       VID_NXSM_LOGIN,
-       VID_NXSM_PASSWORD,
-       VID_NXSM_SID,
-       VID_NXSM_DATA_SIZE,
-
-       VID_NXSM_DATA = 128 // SHOULD BE LAST IN ENUM!
-};
-
-
-typedef struct t_NXSM_ALARM
-{
-       DWORD dwAlarmId;
-       DWORD dwTimeStamp;
-       WORD wSeverity;
-       TCHAR szSourceObject[MAX_OBJECT_NAME];
-       TCHAR szMessage[MAX_DB_STRING];
-} NXSM_ALARM;
-
-typedef struct t_W_NXSM_ALARM
-{
-       int count;
-       NXSM_ALARM *data;
-} W_NXSM_ALARM;
-
-typedef struct
-{
-       DWORD dwNumAlarms;
-       DWORD dwNumAlarmsNormal;
-       DWORD dwNumAlarmsWarning;
-       DWORD dwNumAlarmsMinor;
-       DWORD dwNumAlarmsMajor;
-       DWORD dwNumAlarmsCritical;
-       DWORD dwNumObjects;
-       DWORD dwNumNodes;
-       DWORD dwNumDCI;
-       DWORD dwNumClientSessions;
-       DWORD dwServerUptime;
-       DWORD dwServerProcessVMSize;
-       DWORD dwServerProcessWorkSet;
-       TCHAR szServerVersion[MAX_DB_STRING];
-} NXSM_SERVER_STATS;
-
-
-typedef struct t_NXSM_OBJECT
-{
-       DWORD dwId;
-       TCHAR szName[MAX_DB_STRING];
-       DWORD dwClass;
-       DWORD dwNumChilds;
-       DWORD dwStatus;
-} NXSM_OBJECT;
-
-typedef struct t_W_NXSM_OBJECT
-{
-       int count;
-       NXSM_OBJECT *data;
-} W_NXSM_OBJECT;
-
-#endif // __NXSM_EXT__H__
-
-//////////////////////////////////////////////////////////////////////////////
-/*
-
-$Log: not supported by cvs2svn $
-Revision 1.4  2006/01/09 07:40:35  alk
-alarms weight distr. graph added to overview page
-
-Revision 1.3  2005/12/21 22:42:00  alk
-+ get server stats
-
-Revision 1.2  2005/12/21 03:05:40  alk
-1) nxsmcl added to configure
-2) Makefile.PL+autoconf -- looks like it works, but...
-3) building on linux
-
-Revision 1.1  2005/12/20 23:14:07  alk
-nxsm_ext.h moved to global includes
-
-Revision 1.4  2005/12/15 00:01:50  alk
-session manager(and sm client) can handle login/logout/alarms list/alarm ack
-
-Revision 1.3  2005/12/12 00:37:05  alk
-initial version of web interface
-*NOT WORKING*
-if anyone can comment this, i would be happy:
-c:\work\nms\include\nms_threads.h(65) : error C2054: expected '(' to follow 'inline'
-
-Revision 1.2  2005/09/27 01:13:03  alk
-license text block added
-
-
-*/
index afdc746..a8cd898 100644 (file)
@@ -115,8 +115,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxevent", "src\client\nxeve
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxpush", "src\client\nxpush\nxpush.vcproj", "{B8671BF7-94E1-4615-A8C2-F5C78DB8C515}"
        ProjectSection(ProjectDependencies) = postProject
+               {B2C8E7C8-E047-46E8-ADDB-0BB819F72288} = {B2C8E7C8-E047-46E8-ADDB-0BB819F72288}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
-               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxsms", "src\client\nxsms\nxsms.vcproj", "{B0A70A32-A8F0-4071-8044-FDA3C834A5C5}"
@@ -657,6 +657,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hpsw", "src\server\drivers\
                {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
        EndProjectSection
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxclient", "src\client\libnxclient\libnxclient.vcproj", "{B2C8E7C8-E047-46E8-ADDB-0BB819F72288}"
+       ProjectSection(ProjectDependencies) = postProject
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+       EndProjectSection
+EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Win32 = Debug|Win32
@@ -1513,6 +1518,14 @@ Global
                {B51F1406-AF43-4396-96C0-31176DDCA4FC}.Release|Win32.Build.0 = Release|Win32
                {B51F1406-AF43-4396-96C0-31176DDCA4FC}.Release|x64.ActiveCfg = Release|x64
                {B51F1406-AF43-4396-96C0-31176DDCA4FC}.Release|x64.Build.0 = Release|x64
+               {B2C8E7C8-E047-46E8-ADDB-0BB819F72288}.Debug|Win32.ActiveCfg = Debug|Win32
+               {B2C8E7C8-E047-46E8-ADDB-0BB819F72288}.Debug|Win32.Build.0 = Debug|Win32
+               {B2C8E7C8-E047-46E8-ADDB-0BB819F72288}.Debug|x64.ActiveCfg = Debug|x64
+               {B2C8E7C8-E047-46E8-ADDB-0BB819F72288}.Debug|x64.Build.0 = Debug|x64
+               {B2C8E7C8-E047-46E8-ADDB-0BB819F72288}.Release|Win32.ActiveCfg = Release|Win32
+               {B2C8E7C8-E047-46E8-ADDB-0BB819F72288}.Release|Win32.Build.0 = Release|Win32
+               {B2C8E7C8-E047-46E8-ADDB-0BB819F72288}.Release|x64.ActiveCfg = Release|x64
+               {B2C8E7C8-E047-46E8-ADDB-0BB819F72288}.Release|x64.Build.0 = Release|x64
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
@@ -1570,6 +1583,7 @@ Global
                {9F722C62-78FD-4D8C-A7C7-2815B09F1943} = {268BC97D-BFC6-4BD7-BF78-E6AC1D8BA37E}
                {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {E431F5D5-AAD8-4315-928A-23F86969DB35}
                {39BF23C9-D903-4C20-8E88-19533A745625} = {E431F5D5-AAD8-4315-928A-23F86969DB35}
+               {B2C8E7C8-E047-46E8-ADDB-0BB819F72288} = {E431F5D5-AAD8-4315-928A-23F86969DB35}
                {F9FFAAE9-D669-451E-B9EF-18BC8AD37FAB} = {39BF23C9-D903-4C20-8E88-19533A745625}
                {C7A460E8-12A8-4FC7-9F59-C9C5CE17ED20} = {39BF23C9-D903-4C20-8E88-19533A745625}
                {B8671BF7-94E1-4615-A8C2-F5C78DB8C515} = {39BF23C9-D903-4C20-8E88-19533A745625}
index 916e2ef..678feed 100644 (file)
 #include <nms_util.h>
 #include <nms_threads.h>
 #include <nms_agent.h>
-#include <nms_cscp.h>
-#include <stdio.h>
-#include <stdarg.h>
+#include <nxcpapi.h>
 #include <nxqueue.h>
 #include <nxlog.h>
+#include <nxcldefs.h>
 #include "messages.h"
 #include "nxsnmp.h"
 
-#define LIBNXCL_NO_DECLARATIONS
-#include <nxclapi.h>
-
 #ifdef _NETWARE
 #undef SEVERITY_CRITICAL
 #endif
index cea0229..c0648bb 100644 (file)
@@ -336,7 +336,7 @@ static void GetFolderContent(TCHAR *folder, NXCPMessage *msg, bool rootFolder)
    }
    else
    {
-      msg->setField(VID_RCC, RCC_IO_ERROR);
+      msg->setField(VID_RCC, ERR_IO_FAILURE);
    }
 }
 
@@ -583,7 +583,7 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
          response->setId(request->getId());
          if (directory == NULL)
          {
-            response->setField(VID_RCC, RCC_IO_ERROR);
+            response->setField(VID_RCC, ERR_IO_FAILURE);
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): File name should be set."));
             return TRUE;
          }
@@ -597,7 +597,7 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
          else
          {
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Access denied"));
-            response->setField(VID_RCC, RCC_ACCESS_DENIED);
+            response->setField(VID_RCC, ERR_ACCESS_DENIED);
          }
          return TRUE;
       }
@@ -608,7 +608,7 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
          response->setId(request->getId());
          if(file == NULL)
          {
-            response->setField(VID_RCC, RCC_IO_ERROR);
+            response->setField(VID_RCC, ERR_IO_FAILURE);
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): File name should be set."));
             return TRUE;
          }
@@ -622,13 +622,13 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
             }
             else
             {
-               response->setField(VID_RCC, RCC_IO_ERROR);
+               response->setField(VID_RCC, ERR_IO_FAILURE);
             }
          }
          else
          {
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Access denied"));
-            response->setField(VID_RCC, RCC_ACCESS_DENIED);
+            response->setField(VID_RCC, ERR_ACCESS_DENIED);
          }
          return TRUE;
       }
@@ -641,7 +641,7 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
          response->setId(request->getId());
          if (oldName == NULL && newName == NULL)
          {
-            response->setField(VID_RCC, RCC_IO_ERROR);
+            response->setField(VID_RCC, ERR_IO_FAILURE);
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): File names should be set."));
             return TRUE;
          }
@@ -656,13 +656,13 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
             }
             else
             {
-               response->setField(VID_RCC, RCC_IO_ERROR);
+               response->setField(VID_RCC, ERR_IO_FAILURE);
             }
          }
          else
          {
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Access denied"));
-            response->setField(VID_RCC, RCC_ACCESS_DENIED);
+            response->setField(VID_RCC, ERR_ACCESS_DENIED);
          }
          return TRUE;
       }
@@ -675,7 +675,7 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
          response->setId(request->getId());
          if ((oldName == NULL) && (newName == NULL))
          {
-            response->setField(VID_RCC, RCC_IO_ERROR);
+            response->setField(VID_RCC, ERR_IO_FAILURE);
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): File names should be set."));
             return TRUE;
          }
@@ -690,13 +690,13 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
             }
             else
             {
-               response->setField(VID_RCC, RCC_IO_ERROR);
+               response->setField(VID_RCC, ERR_IO_FAILURE);
             }
          }
          else
          {
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Access denied"));
-            response->setField(VID_RCC, RCC_ACCESS_DENIED);
+            response->setField(VID_RCC, ERR_ACCESS_DENIED);
          }
          return TRUE;
       }
@@ -707,7 +707,7 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
          response->setId(request->getId());
          if (name == NULL)
          {
-            response->setField(VID_RCC, RCC_IO_ERROR);
+            response->setField(VID_RCC, ERR_IO_FAILURE);
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): File name should be set."));
             return TRUE;
          }
@@ -720,7 +720,7 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
          else
          {
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Access denied"));
-            response->setField(VID_RCC, RCC_ACCESS_DENIED);
+            response->setField(VID_RCC, ERR_ACCESS_DENIED);
          }
          return TRUE;
       }
@@ -813,7 +813,7 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
          response->setId(request->getId());
          if (directory == NULL)
          {
-            response->setField(VID_RCC, RCC_IO_ERROR);
+            response->setField(VID_RCC, ERR_IO_FAILURE);
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): File name should be set."));
             return TRUE;
          }
@@ -829,13 +829,13 @@ static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *r
             else
             {
                AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Could not create directory"));
-               response->setField(VID_RCC, RCC_IO_ERROR);
+               response->setField(VID_RCC, ERR_IO_FAILURE);
             }
          }
          else
          {
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Access denied"));
-            response->setField(VID_RCC, RCC_ACCESS_DENIED);
+            response->setField(VID_RCC, ERR_ACCESS_DENIED);
          }
          return TRUE;
       }
index 6394c84..bf0d52d 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <nms_common.h>
 #include <nms_agent.h>
-#include <nxclapi.h>
+#include <nxcpapi.h>
 #include <nxstat.h>
 
 
index c31eab1..a8689d3 100644 (file)
                        UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
                        >
                        <File
+                               RelativePath=".\filemgr.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\..\..\include\nms_agent.h"
                                >
                        </File>
index 833d03f..315e810 100644 (file)
@@ -1,10 +1,9 @@
 /* $Id$ */
 
-#define LIBNXCL_NO_DECLARATIONS
-
 #include <nms_common.h>
 #include <nms_agent.h>
-#include <nxclapi.h>
+#include <nxcldefs.h>
+#include <nxcpapi.h>
 
 #ifdef _WITH_ENCRYPTION
 #include <openssl/ssl.h>
index 6ee247a..4ad96e1 100644 (file)
@@ -22,7 +22,7 @@
 #include <nms_common.h>
 #include <nms_agent.h>
 #include <nms_util.h>
-#include <nxclapi.h>
+#include <nxcpapi.h>
 
 #if HAVE_GETOPT_H
 #include <getopt.h>
diff --git a/src/client/libnxclient/dc.cpp b/src/client/libnxclient/dc.cpp
new file mode 100644 (file)
index 0000000..06790d0
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+** NetXMS - Network Management System
+** Client Library
+** Copyright (C) 2003-2014 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: dc.cpp
+**
+**/
+
+#include "libnxclient.h"
+
+/**
+ * Push data
+ */
+UINT32 DataCollectionController::pushData(ObjectArray<NXCPushData> *data, UINT32 *failedIndex)
+{
+   NXCPMessage msg;
+   msg.setCode(CMD_PUSH_DCI_DATA);
+   msg.setId(m_session->createMessageId());
+   msg.setField(VID_NUM_ITEMS, (INT32)data->size());
+
+   UINT32 id = VID_PUSH_DCI_DATA_BASE;
+   for(int i = 0; i < data->size(); i++)
+   {
+      NXCPushData *d = data->get(i);
+      msg.setField(id++, d->nodeId);
+      if (d->nodeId == 0)
+      {
+         msg.setField(id++, d->nodeName);
+      }
+
+      msg.setField(id++, d->dciId);
+      if (d->dciId == 0)
+      {
+         msg.setField(id++, d->dciName);
+      }
+
+      msg.setField(id++, d->value);
+   }
+
+   m_session->sendMessage(&msg);
+
+   UINT32 rcc;
+   NXCPMessage *response = m_session->waitForMessage(CMD_REQUEST_COMPLETED, msg.getId());
+   if (response != NULL)
+   {
+      rcc = response->getFieldAsUInt32(VID_RCC);
+      if (rcc != RCC_SUCCESS)
+      {
+         if (failedIndex != NULL)
+            *failedIndex = response->getFieldAsUInt32(VID_FAILED_DCI_INDEX);
+      }
+      delete response;
+   }
+   else
+   {
+      rcc = RCC_TIMEOUT;
+      if (failedIndex != NULL)
+         *failedIndex = 0;
+   }
+   return rcc;
+}
similarity index 74%
copy from src/libnetxms/libnetxms.h
copy to src/client/libnxclient/libnxclient.h
index d828955..b42448c 100644 (file)
@@ -1,7 +1,7 @@
-/* 
+/*
 ** NetXMS - Network Management System
-** Utility Library
-** Copyright (C) 2003-2010 Victor Kirhenshtein
+** Client Library
+** Copyright (C) 2003-2014 Victor Kirhenshtein
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 **
-** File: libnetxms.h
+** File: libnxclient.h
 **
 **/
 
-#ifndef _libnetxms_h_
-#define _libnetxms_h_
+#ifndef _libnxclient_h_
+#define _libnxclient_h_
 
 #include <nms_common.h>
 #include <nms_util.h>
+#include <nms_threads.h>
 #include <nxcpapi.h>
+#include <nxclient.h>
 
-#define LIBNXCL_NO_DECLARATIONS
-#include <nxclapi.h>
+void DebugPrintf(const TCHAR *format, ...);
 
-#define MAX_CODEPAGE_LEN               64
-
-
-//
-// Functions
-//
-
-void SEHInit(void);
-
-
-#endif   /* _libnetxms_h_ */
+#endif   /* _libnxclient_h_ */
similarity index 79%
copy from src/agent/subagents/filemgr/filemgr.vcproj
copy to src/client/libnxclient/libnxclient.vcproj
index c31eab1..33d06a1 100644 (file)
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="windows-1251"?>
+<?xml version="1.0" encoding="Windows-1252"?>
 <VisualStudioProject
        ProjectType="Visual C++"
        Version="8.00"
-       Name="filemgr"
-       ProjectGUID="{BBE9028E-725C-45C6-97C9-BFC443F19EA8}"
-       RootNamespace="filemgr"
+       Name="libnxclient"
+       ProjectGUID="{B2C8E7C8-E047-46E8-ADDB-0BB819F72288}"
+       RootNamespace="libnxclient"
        Keyword="Win32Proj"
        >
        <Platforms>
                        <Tool
                                Name="VCCLCompilerTool"
                                Optimization="0"
-                               AdditionalIncludeDirectories="..\..\..\..\include"
-                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;FILEMGR_EXPORTS"
+                               AdditionalIncludeDirectories="..\..\..\include"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBNXCLIENT_EXPORTS"
                                MinimalRebuild="true"
                                BasicRuntimeChecks="3"
                                RuntimeLibrary="3"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
-                               Detect64BitPortabilityProblems="false"
+                               Detect64BitPortabilityProblems="true"
                                DebugInformationFormat="4"
                        />
                        <Tool
@@ -65,7 +65,6 @@
                        <Tool
                                Name="VCLinkerTool"
                                AdditionalDependencies="ws2_32.lib"
-                               OutputFile="$(OutDir)\$(ProjectName).nsm"
                                LinkIncremental="2"
                                GenerateDebugInformation="true"
                                SubSystem="2"
                        />
                </Configuration>
                <Configuration
-                       Name="Debug|x64"
-                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
-                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+                       Name="Release|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
                        ConfigurationType="2"
                        CharacterSet="1"
+                       WholeProgramOptimization="1"
                        >
                        <Tool
                                Name="VCPreBuildEventTool"
                        />
                        <Tool
                                Name="VCMIDLTool"
-                               TargetEnvironment="3"
                        />
                        <Tool
                                Name="VCCLCompilerTool"
-                               Optimization="0"
-                               AdditionalIncludeDirectories="..\..\..\..\include"
-                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;FILEMGR_EXPORTS"
-                               MinimalRebuild="true"
-                               BasicRuntimeChecks="3"
-                               RuntimeLibrary="3"
+                               AdditionalIncludeDirectories="..\..\..\include"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBNXCLIENT_EXPORTS"
+                               RuntimeLibrary="2"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
                                Detect64BitPortabilityProblems="true"
                        <Tool
                                Name="VCLinkerTool"
                                AdditionalDependencies="ws2_32.lib"
-                               OutputFile="$(OutDir)\$(ProjectName).nsm"
-                               LinkIncremental="2"
+                               LinkIncremental="1"
                                GenerateDebugInformation="true"
                                SubSystem="2"
-                               TargetMachine="17"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               TargetMachine="1"
                        />
                        <Tool
                                Name="VCALinkTool"
                        />
                </Configuration>
                <Configuration
-                       Name="Release|Win32"
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-                       IntermediateDirectory="$(ConfigurationName)"
+                       Name="Debug|x64"
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
                        ConfigurationType="2"
                        CharacterSet="1"
-                       WholeProgramOptimization="1"
                        >
                        <Tool
                                Name="VCPreBuildEventTool"
                        />
                        <Tool
                                Name="VCMIDLTool"
+                               TargetEnvironment="3"
                        />
                        <Tool
                                Name="VCCLCompilerTool"
-                               AdditionalIncludeDirectories="..\..\..\..\include"
-                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;FILEMGR_EXPORTS"
-                               RuntimeLibrary="2"
+                               Optimization="0"
+                               AdditionalIncludeDirectories="..\..\..\include"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBNXCLIENT_EXPORTS"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
-                               Detect64BitPortabilityProblems="false"
+                               Detect64BitPortabilityProblems="true"
                                DebugInformationFormat="3"
                        />
                        <Tool
                        <Tool
                                Name="VCLinkerTool"
                                AdditionalDependencies="ws2_32.lib"
-                               OutputFile="$(OutDir)\$(ProjectName).nsm"
-                               LinkIncremental="1"
+                               LinkIncremental="2"
                                GenerateDebugInformation="true"
                                SubSystem="2"
-                               OptimizeReferences="2"
-                               EnableCOMDATFolding="2"
-                               TargetMachine="1"
+                               TargetMachine="17"
                        />
                        <Tool
                                Name="VCALinkTool"
                        />
                        <Tool
                                Name="VCCLCompilerTool"
-                               AdditionalIncludeDirectories="..\..\..\..\include"
-                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;FILEMGR_EXPORTS"
+                               AdditionalIncludeDirectories="..\..\..\include"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBNXCLIENT_EXPORTS"
                                RuntimeLibrary="2"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
                        <Tool
                                Name="VCLinkerTool"
                                AdditionalDependencies="ws2_32.lib"
-                               OutputFile="$(OutDir)\$(ProjectName).nsm"
                                LinkIncremental="1"
                                GenerateDebugInformation="true"
                                SubSystem="2"
                        UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
                        >
                        <File
-                               RelativePath=".\filemgr.cpp"
+                               RelativePath=".\dc.cpp"
                                >
                        </File>
                        <File
-                               RelativePath=".\logmonitoring.cpp"
+                               RelativePath=".\main.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\session.cpp"
                                >
                        </File>
                </Filter>
                        UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
                        >
                        <File
-                               RelativePath="..\..\..\..\include\nms_agent.h"
+                               RelativePath=".\libnxclient.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\..\include\netxms-regex.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\..\include\netxms-version.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\..\include\netxms_maps.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\..\include\nms_common.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\..\include\nms_cscp.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\..\include\nms_threads.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\..\include\nms_util.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\..\..\..\include\nms_common.h"
+                               RelativePath="..\..\..\include\nxcldefs.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\..\..\..\include\nms_threads.h"
+                               RelativePath="..\..\..\include\nxclient.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\..\..\..\include\nms_util.h"
+                               RelativePath="..\..\..\include\nxcpapi.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\..\..\..\include\nxlog.h"
+                               RelativePath="..\..\..\include\nxlog.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\..\..\..\include\unicode.h"
+                               RelativePath="..\..\..\include\unicode.h"
                                >
                        </File>
                </Filter>
diff --git a/src/client/libnxclient/main.cpp b/src/client/libnxclient/main.cpp
new file mode 100644 (file)
index 0000000..50a8114
--- /dev/null
@@ -0,0 +1,234 @@
+/*
+** NetXMS - Network Management System
+** Client Library
+** Copyright (C) 2003-2014 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: main.cpp
+**
+**/
+
+#include "libnxclient.h"
+
+/**
+ * Debug callback
+ */
+static NXC_DEBUG_CALLBACK s_debugCallback = NULL;
+
+/**
+ * Print debug messages
+ */
+void DebugPrintf(const TCHAR *format, ...)
+{
+   if (s_debugCallback == NULL)
+      return;
+
+   va_list args;
+   TCHAR buffer[4096];
+
+   va_start(args, format);
+   _vsntprintf(buffer, 4096, format, args);
+   va_end(args);
+   s_debugCallback(buffer);
+}
+
+/**
+ * Debug callback for crypto lib
+ */
+static void CryptoLibDebugCallback(int level, const TCHAR *format, va_list args)
+{
+   if (s_debugCallback == NULL)
+      return;
+
+   TCHAR buffer[4096];
+   _vsntprintf(buffer, 4096, format, args);
+   s_debugCallback(buffer);
+}
+
+/**
+ * Initialization function
+ */
+bool LIBNXCLIENT_EXPORTABLE NXCInitialize()
+{
+   return InitCryptoLib(0xFFFF, CryptoLibDebugCallback);
+}
+
+/**
+ * Shutdown function
+ */
+void LIBNXCLIENT_EXPORTABLE NXCShutdown()
+{
+}
+
+/**
+ * Get library version
+ */
+UINT32 LIBNXCLIENT_EXPORTABLE NXCGetVersion()
+{
+   return (NETXMS_VERSION_MAJOR << 24) | (NETXMS_VERSION_MINOR << 16) | NETXMS_VERSION_BUILD;
+}
+
+/**
+ * Set callback for debug messages
+ */
+void LIBNXCLIENT_EXPORTABLE NXCSetDebugCallback(NXC_DEBUG_CALLBACK cb)
+{
+   s_debugCallback = cb;
+}
+
+/**
+ * Get text for error
+ */
+const TCHAR LIBNXCLIENT_EXPORTABLE *NXCGetErrorText(UINT32 error)
+{
+   static const TCHAR *errorText[] =
+   {
+      _T("Request completed successfully"),
+      _T("Component locked"),
+      _T("Access denied"),
+      _T("Invalid request"),
+      _T("Request timed out"),
+      _T("Request is out of state"),
+      _T("Database failure"),
+      _T("Invalid object ID"),
+      _T("Object already exist"),
+      _T("Communication failure"),
+      _T("System failure"),
+      _T("Invalid user ID"),
+      _T("Invalid argument"),
+      _T("Duplicate DCI"),
+      _T("Invalid DCI ID"),
+      _T("Out of memory"),
+      _T("Input/Output error"),
+      _T("Incompatible operation"),
+      _T("Object creation failed"),
+      _T("Loop in object relationship detected"),
+      _T("Invalid object name"),
+      _T("Invalid alarm ID"),
+      _T("Invalid action ID"),
+      _T("Operation in progress"),
+      _T("Copy operation failed for one or more DCI(s)"),
+      _T("Invalid or unknown event code"),
+      _T("No interfaces suitable for sending magic packet"),
+      _T("No MAC address on interface"),
+      _T("Command not implemented"),
+      _T("Invalid trap configuration record ID"),
+      _T("Requested data collection item is not supported by agent"),
+      _T("Client and server versions mismatch"),
+      _T("Error parsing package information file"),
+      _T("Package with specified properties already installed on server"),
+      _T("Package file already exist on server"),
+      _T("Server resource busy"),
+      _T("Invalid package ID"),
+      _T("Invalid IP address"),
+      _T("Action is used in event processing policy"),
+      _T("Variable not found"),
+      _T("Server uses incompatible version of communication protocol"),
+      _T("Address already in use"),
+      _T("Unable to select cipher"),
+      _T("Invalid public key"),
+      _T("Invalid session key"),
+      _T("Encryption is not supported by peer"),
+      _T("Server internal error"),
+      _T("Execution of external command failed"),
+      _T("Invalid object tool ID"),
+      _T("SNMP protocol error"),
+      _T("Incorrect regular expression"),
+      _T("Parameter is not supported by agent"),
+      _T("File I/O operation failed"),
+      _T("MIB file is corrupted"),
+      _T("File transfer operation already in progress"),
+      _T("Invalid job ID"),
+      _T("Invalid script ID"),
+      _T("Invalid script name"),
+      _T("Unknown map name"),
+      _T("Invalid map ID"),
+      _T("Account disabled"),
+      _T("No more grace logins"),
+      _T("Server connection broken"),
+      _T("Invalid agent configuration ID"),
+      _T("Server has lost connection with backend database"),
+      _T("Alarm is still open in helpdesk system"),
+      _T("Alarm is not in \"outstanding\" state"),
+      _T("DCI data source is not a push agent"),
+      _T("Error parsing configuration import file"),
+      _T("Configuration cannot be imported because of validation errors"),
+               _T("Invalid graph ID"),
+               _T("Local cryptographic provider failure"),
+               _T("Unsupported authentication type"),
+               _T("Bad certificate"),
+               _T("Invalid certificate ID"),
+               _T("SNMP failure"),
+               _T("Node has no support for layer 2 topology discovery"),
+               _T("Invalid situation ID"),
+               _T("Named instance not found"),
+               _T("Invalid event ID"),
+               _T("Operation cannot be completed due to agent error"),
+               _T("Unknown variable"),
+               _T("Requested resource not available"),
+               _T("Job cannot be cancelled"),
+               _T("Invalid policy ID"),
+               _T("Unknown log name"),
+               _T("Invalid log handle"),
+               _T("New password is too weak"),
+               _T("Password was used before"),
+               _T("Invalid session handle"),
+               _T("Node already is a member of a cluster"),
+               _T("Job cannot be hold"),
+               _T("Job cannot be unhold"),
+               _T("Zone ID is already in use"),
+               _T("Invalid zone ID"),
+               _T("Cannot delete non-empty zone object"),
+               _T("No physical component data"),
+               _T("Invalid alarm note ID"),
+               _T("Encryption error"),
+               _T("Invalid mapping table ID"),
+      _T("No software package data"),
+               _T("Invalid DCI summary table ID"),
+      _T("User is logged in"),
+      _T("Error parsing XML"),
+      _T("SQL query cost is too high"),
+      _T("License violation"),
+      _T("Number of client licenses exceeded"),
+      _T("Object already exist"),
+      _T("No helpdesk link"),
+      _T("Helpdesk link communication failure"),
+      _T("Helpdesk link access denied"),
+      _T("Helpdesk link internal error"),
+      _T("LDAP connection error"),
+      _T("Routing table unavailable"),
+      _T("Switch forwarding database unavailable"),
+      _T("Location history not available"),
+      _T("Object is in use and cannot be deleted"),
+      _T("Script compilation error"),
+      _T("Script execution error")
+   };
+       return (error <= RCC_NXSL_EXECUTION_ERROR) ? errorText[error] : _T("No text message for this error");
+}
+
+#if defined(_WIN32) && !defined(UNDER_CE)
+
+/**
+ * DLL entry point
+ */
+BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
+{
+   if (dwReason == DLL_PROCESS_ATTACH)
+      DisableThreadLibraryCalls(hInstance);
+   return TRUE;
+}
+
+#endif   /* _WIN32 */
diff --git a/src/client/libnxclient/session.cpp b/src/client/libnxclient/session.cpp
new file mode 100644 (file)
index 0000000..3f778ec
--- /dev/null
@@ -0,0 +1,429 @@
+/*
+** NetXMS - Network Management System
+** Client Library
+** Copyright (C) 2003-2014 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: session.cpp
+**
+**/
+
+#include "libnxclient.h"
+
+/**
+ * Max NXCP message size
+ */
+#define MAX_MSG_SIZE    4194304
+
+/**
+ * Constructor
+ */
+NXCSession::NXCSession()
+{
+   m_controllers = new StringObjectMap<Controller>(true);
+   m_msgId = 0;
+   m_dataLock = MutexCreate();
+   m_msgSendLock = MutexCreate();
+   m_connected = false;
+   m_disconnected = false;
+   m_hSocket = INVALID_SOCKET;
+   m_msgWaitQueue = NULL;
+   m_encryptionContext = NULL;
+   m_receiverThread = INVALID_THREAD_HANDLE;
+   m_serverVersion[0] = 0;
+   m_serverTimeZone[0] = 0;
+   m_userId = 0;
+   m_systemRights = 0;
+   m_commandTimeout = 60000;  // 60 seconds
+}
+
+/**
+ * Destructor
+ */
+NXCSession::~NXCSession()
+{
+   disconnect();
+   delete m_controllers;
+   MutexDestroy(m_dataLock);
+   MutexDestroy(m_msgSendLock);
+}
+
+/**
+ * Get controller
+ */
+Controller *NXCSession::getController(const TCHAR *name)
+{
+   MutexLock(m_dataLock);
+   Controller *c = m_controllers->get(name);
+   if (c == NULL)
+   {
+      if (!_tcsicmp(name, CONTROLLER_ALARMS))
+         c = new AlarmController(this);
+      else if (!_tcsicmp(name, CONTROLLER_DATA_COLLECTION))
+         c = new DataCollectionController(this);
+      else if (!_tcsicmp(name, CONTROLLER_EVENTS))
+         c = new EventController(this);
+      else if (!_tcsicmp(name, CONTROLLER_OBJECTS))
+         c = new ObjectController(this);
+
+      if (c != NULL)
+         m_controllers->set(name, c);
+   }
+   MutexUnlock(m_dataLock);
+   return c;
+}
+
+/**
+ * Disconnect
+ */
+void NXCSession::disconnect()
+{
+   if (!m_connected || m_disconnected)
+      return;
+
+   // Close socket
+   if (m_hSocket != INVALID_SOCKET)
+   {
+      shutdown(m_hSocket, SHUT_RDWR);
+      closesocket(m_hSocket);
+   }
+
+   if (m_receiverThread != INVALID_THREAD_HANDLE)
+      ThreadJoin(m_receiverThread);
+
+   // Clear message wait queue
+   delete m_msgWaitQueue;
+
+   m_connected = false;
+   m_disconnected = true;
+}
+
+/**
+ * Connect to server
+ */
+UINT32 NXCSession::connect(const TCHAR *host, const TCHAR *login, const TCHAR *password, UINT32 flags, const TCHAR *clientInfo)
+{
+   if (m_connected || m_disconnected)
+      return RCC_OUT_OF_STATE_REQUEST;
+
+   TCHAR hostname[128];
+   nx_strncpy(hostname, host, 128);
+   Trim(hostname);
+
+   // Check if server given in form host:port
+   // If IPv6 address is given, it must be enclosed in [] if port is also specified
+   WORD port = SERVER_LISTEN_PORT_FOR_CLIENTS;
+   TCHAR *p = _tcsrchr(hostname, _T(':'));
+   if ((p != NULL) && (p != hostname) &&
+       (((hostname[0] != _T('[')) && (NumChars(hostname, _T(':') == 1)) || (*(p - 1) == _T(']')))))
+   {
+      *p = 0;
+      p++;
+      TCHAR *eptr;
+      int n = _tcstol(p, &eptr, 10);
+      if ((*eptr != 0) || (n < 1) || (n > 65535))
+         return RCC_INVALID_ARGUMENT;
+      port = (WORD)n;
+   }
+   DebugPrintf(_T("NXCSession::connect: host=\"%s\" port=%d"), hostname, (int)port);
+
+   InetAddress addr = InetAddress::resolveHostName(hostname);
+   if (!addr.isValid())
+      return RCC_COMM_FAILURE;
+
+   struct sockaddr *sa;
+   int saLen;
+
+   struct sockaddr_in sa4;
+#ifdef WITH_IPV6
+   struct sockaddr_in6 sa6;
+#endif
+   if (addr.getFamily() == AF_INET)
+   {
+      saLen = sizeof(sa4);
+      memset(&sa4, 0, saLen);
+      sa = (struct sockaddr *)&sa4;
+      sa4.sin_family = AF_INET;
+      sa4.sin_addr.s_addr = htonl(addr.getAddressV4());
+      sa4.sin_port = htons(port);
+   }
+   else
+   {
+#ifdef WITH_IPV6
+      saLen = sizeof(sa6);
+      memset(&sa6, 0, saLen);
+      sa = (struct sockaddr *)&sa6;
+      sa6.sin6_family = AF_INET6;
+      memcpy(&sa6.sin6_addr, addr.getAddressV6(), 16);
+      sa6.sin6_port = ntohs(port);
+#else
+      return RCC_NOT_IMPLEMENTED;
+#endif
+   }
+
+   m_hSocket = socket(addr.getFamily(), SOCK_STREAM, 0);
+   if (m_hSocket == INVALID_SOCKET)
+      return RCC_COMM_FAILURE;
+
+   if (::connect(m_hSocket, sa, saLen) != 0)
+   {
+      closesocket(m_hSocket);
+      m_hSocket = INVALID_SOCKET;
+      return RCC_COMM_FAILURE;
+   }
+
+   m_connected = true;
+   m_msgWaitQueue = new MsgWaitQueue();
+   m_receiverThread = ThreadCreateEx(receiverThreadStarter, 0, this);
+   
+   UINT32 rcc = RCC_COMM_FAILURE;
+
+   // Query server information
+   NXCPMessage msg;
+   msg.setId(createMessageId());
+   msg.setCode(CMD_GET_SERVER_INFO);
+   if (sendMessage(&msg))
+   {
+      NXCPMessage *response = waitForMessage(CMD_REQUEST_COMPLETED, msg.getId());
+      if (response != NULL)
+      {
+         rcc = response->getFieldAsUInt32(VID_RCC);
+         if (rcc == RCC_SUCCESS)
+         {
+            response->getFieldAsBinary(VID_SERVER_ID, m_serverId, 8);
+            response->getFieldAsString(VID_SERVER_VERSION, m_serverVersion, 64);
+                               response->getFieldAsString(VID_TIMEZONE, m_serverTimeZone, MAX_TZ_LEN);
+
+            if (flags & NXCF_EXACT_VERSION_MATCH)
+            {
+               if (_tcsncmp(m_serverVersion, NETXMS_VERSION_STRING, 64))
+                  rcc = RCC_VERSION_MISMATCH;
+            }
+                               if (!(flags & NXCF_IGNORE_PROTOCOL_VERSION))
+                               {
+                                       if (response->getFieldAsUInt32(VID_PROTOCOL_VERSION) != CLIENT_PROTOCOL_VERSION)
+                                               rcc = RCC_BAD_PROTOCOL;
+                               }
+         }
+         delete response;
+      }
+      else
+      {
+         rcc = RCC_TIMEOUT;
+      }
+   }
+
+   // Request encryption if needed
+   if ((rcc == RCC_SUCCESS) && (flags & NXCF_ENCRYPT))
+   {
+      msg.deleteAllFields();
+      msg.setId(createMessageId());
+      msg.setCode(CMD_REQUEST_ENCRYPTION);
+      if (sendMessage(&msg))
+      {
+         rcc = waitForRCC(msg.getId());
+      }
+      else
+      {
+         rcc = RCC_COMM_FAILURE;
+      }
+   }
+
+   if (rcc == RCC_SUCCESS)
+   {
+      msg.deleteAllFields();
+      msg.setId(createMessageId());
+      msg.setCode(CMD_LOGIN);
+      msg.setField(VID_LOGIN_NAME, login);
+          if (flags & NXCF_USE_CERTIFICATE)
+          {
+         /* TODO: implement certificate auth */
+                       msg.setField(VID_AUTH_TYPE, (UINT16)NETXMS_AUTH_TYPE_CERTIFICATE);
+          }
+          else
+          {
+                  msg.setField(VID_PASSWORD, password);
+                  msg.setField(VID_AUTH_TYPE, (UINT16)NETXMS_AUTH_TYPE_PASSWORD);
+          }
+      msg.setField(VID_CLIENT_INFO, (clientInfo != NULL) ? clientInfo : _T("Unnamed Client"));
+      msg.setField(VID_LIBNXCL_VERSION, NETXMS_VERSION_STRING);
+      
+      TCHAR buffer[64];
+      GetOSVersionString(buffer, 64);
+      msg.setField(VID_OS_INFO, buffer);
+
+      if (sendMessage(&msg))
+      {
+         NXCPMessage *response = waitForMessage(CMD_LOGIN_RESP, msg.getId());
+         if (response != NULL)
+         {
+            rcc = response->getFieldAsUInt32(VID_RCC);
+            if (rcc == RCC_SUCCESS)
+            {
+               m_userId = response->getFieldAsUInt32(VID_USER_ID);
+               m_systemRights = response->getFieldAsUInt64(VID_USER_SYS_RIGHTS);
+               m_passwordChangeNeeded = response->getFieldAsBoolean(VID_CHANGE_PASSWD_FLAG);
+            }
+            delete response;
+         }
+         else
+         {
+            rcc = RCC_TIMEOUT;
+         }
+      }
+      else
+      {
+         rcc = RCC_COMM_FAILURE;
+      }
+   }
+
+   m_connected = true;
+   if (rcc != RCC_SUCCESS)
+      disconnect();
+
+   return rcc;
+}
+
+/**
+ * Send message
+ */
+bool NXCSession::sendMessage(NXCPMessage *msg)
+{
+   if (!m_connected)
+      return false;
+
+   TCHAR buffer[128];
+   DebugPrintf(_T("NXCSession::sendMessage(\"%s\", id:%d)"), NXCPMessageCodeName(msg->getCode(), buffer), msg->getId());
+
+   bool result;
+   NXCP_MESSAGE *rawMsg = msg->createMessage();
+       MutexLock(m_msgSendLock);
+   if (m_encryptionContext != NULL)
+   {
+      NXCP_ENCRYPTED_MESSAGE *emsg = m_encryptionContext->encryptMessage(rawMsg);
+      if (emsg != NULL)
+      {
+         result = (SendEx(m_hSocket, (char *)emsg, ntohl(emsg->size), 0, NULL) == (int)ntohl(emsg->size));
+         free(emsg);
+      }
+      else
+      {
+         result = FALSE;
+      }
+   }
+   else
+   {
+      result = (SendEx(m_hSocket, (char *)rawMsg, ntohl(rawMsg->size), 0, NULL) == (int)ntohl(rawMsg->size));
+   }
+       MutexUnlock(m_msgSendLock);
+   free(rawMsg);
+   return result;
+}
+
+/**
+ * Wait for message
+ */
+NXCPMessage *NXCSession::waitForMessage(UINT16 code, UINT32 id, UINT32 timeout)
+{
+   if (!m_connected)
+      return NULL;
+
+   return m_msgWaitQueue->waitForMessage(code, id, (timeout == 0) ? m_commandTimeout : timeout);
+}
+
+/**
+ * Wait for CMD_REQUEST_COMPLETED message and return RCC
+ */
+UINT32 NXCSession::waitForRCC(UINT32 id, UINT32 timeout)
+{
+   NXCPMessage *response = waitForMessage(CMD_REQUEST_COMPLETED, id, timeout);
+   if (response == NULL)
+      return RCC_TIMEOUT;
+
+   UINT32 rcc = response->getFieldAsUInt32(VID_RCC);
+   delete response;
+   return rcc;
+}
+
+/**
+ * Starter for receiver thread
+ */
+THREAD_RESULT THREAD_CALL NXCSession::receiverThreadStarter(void *arg)
+{
+   ((NXCSession *)arg)->receiverThread();
+   return THREAD_OK;
+}
+
+/**
+ * Receiver thread
+ */
+void NXCSession::receiverThread()
+{
+   SocketMessageReceiver receiver(m_hSocket, 4096, MAX_MSG_SIZE);
+   while(true)
+   {
+      MessageReceiverResult result;
+      NXCPMessage *msg = receiver.readMessage(900000, &result);
+
+      // Check for decryption error
+      if (result == MSGRECV_DECRYPTION_FAILURE)
+      {
+         DebugPrintf(_T("NXCSession::receiverThread: Unable to decrypt received message"));
+         continue;
+      }
+
+      // Receive error
+      if (msg == NULL)
+      {
+         DebugPrintf(_T("NXCSession::receiverThread: message receiving error (%s)"), AbstractMessageReceiver::resultToText(result));
+         break;
+      }
+
+      TCHAR buffer[128];
+      DebugPrintf(_T("NXCSession::receiveMessage(\"%s\", id:%d)"), NXCPMessageCodeName(msg->getCode(), buffer), msg->getId());
+
+      switch(msg->getCode())
+      {
+         case CMD_REQUEST_SESSION_KEY:
+            if (m_encryptionContext == NULL)
+            {
+               NXCPMessage *response;
+               MutexLock(m_dataLock);
+               SetupEncryptionContext(msg, &m_encryptionContext, &response, NULL, NXCP_VERSION);
+               receiver.setEncryptionContext(m_encryptionContext);
+               MutexUnlock(m_dataLock);
+               sendMessage(response);
+               delete response;
+            }
+            break;
+         case CMD_NOTIFY:
+            onNotify(msg);
+            break;
+         default:
+            m_msgWaitQueue->put(msg);
+            msg = NULL;    // prevent destruction
+            break;
+      }
+      delete msg;
+   }
+}
+
+/**
+ * Notification message handler
+ */
+void NXCSession::onNotify(NXCPMessage *msg)
+{
+}
index ff75594..41fdf43 100644 (file)
@@ -21,7 +21,7 @@
 #include <nms_common.h>
 #include <nms_agent.h>
 #include <nms_util.h>
-#include <nxclapi.h>
+#include <nxclient.h>
 
 #if HAVE_GETOPT_H
 #include <getopt.h>
 // Global variables
 //
 
-NXC_SESSION hSession = NULL;
-NXC_DCI_PUSH_DATA *queue = NULL;
-int queueSize = 0;
+NXCSession *session = NULL;
+DataCollectionController *controller = NULL;
+ObjectArray<NXCPushData> queue(16, 16, true);
 
 
 //
 // Forward declarations
 //
 
-BOOL AddValuePair(char *name, char *value);
-BOOL AddValue(char *pair);
-BOOL Startup(void);
-BOOL Send(void);
-BOOL Teardown(void);
+static BOOL AddValuePair(char *name, char *value);
+static BOOL AddValue(char *pair);
+static BOOL Startup();
+static BOOL Send();
+static BOOL Teardown();
 
 
 //
@@ -264,7 +264,7 @@ int main(int argc, char *argv[])
                }
        }
 
-       if (queueSize > 0)
+       if (queue.size() > 0)
        {
                if (Startup())
                {
@@ -290,7 +290,7 @@ int main(int argc, char *argv[])
 /**
  * Values parser - clean string and split by '='
  */
-BOOL AddValue(char *pair)
+static BOOL AddValue(char *pair)
 {
        BOOL ret = FALSE;
        char *p = pair;
@@ -321,12 +321,10 @@ BOOL AddValue(char *pair)
        return ret;
 }
 
-
-//
-// Split IDs, cleanup and add to the send queue
-//
-
-BOOL AddValuePair(char *name, char *value)
+/**
+ * Split IDs, cleanup and add to the send queue
+ */
+static BOOL AddValuePair(char *name, char *value)
 {
        BOOL ret = TRUE;
        UINT32 dciId = 0;
@@ -356,52 +354,49 @@ BOOL AddValuePair(char *name, char *value)
                                dciId, nodeName, dciName, value);
                }
 
-               NXC_DCI_PUSH_DATA *p = (NXC_DCI_PUSH_DATA *)realloc(
-                       queue, sizeof(NXC_DCI_PUSH_DATA) * (queueSize + 1));
+      NXCPushData *p = new NXCPushData();
                if (p != NULL)
                {
-                       queue = p;
-                       p[queueSize].dwId = dciId;
-                       p[queueSize].dwNodeId = nodeId;
+                       p->dciId = dciId;
+                       p->nodeId = nodeId;
                        if (dciId > 0)
                        {
-                               p[queueSize].pszName = NULL;
+                               p->dciName = NULL;
                        }
                        else
                        {
 #ifdef UNICODE
-                               p[queueSize].pszName = WideStringFromMBString(dciName);
+                               p->dciName = WideStringFromMBString(dciName);
 #else
-                               p[queueSize].pszName = strdup(dciName);
+                               p->dciName = strdup(dciName);
 #endif
                        }
 
                        if (nodeId > 0)
                        {
-                               p[queueSize].pszNodeName = NULL;
+                               p->nodeName = NULL;
                        }
                        else
                        {
 #ifdef UNICODE
-                               p[queueSize].pszNodeName = WideStringFromMBString(nodeName);
+                               p->nodeName= WideStringFromMBString(nodeName);
 #else
-                               p[queueSize].pszNodeName = strdup(nodeName);
+                               p->nodeName = strdup(nodeName);
 #endif
                        }
 
 #ifdef UNICODE
-                       p[queueSize].pszValue = WideStringFromMBString(value);
+                       p->value = WideStringFromMBString(value);
 #else
-                       p[queueSize].pszValue = strdup(value);
+                       p->value = strdup(value);
 #endif
-
-                       queueSize++;
+         queue.add(p);
                }
                else
                {
                        if (optVerbose > 0)
                        {
-                               _tprintf(_T("realloc failed!: %s\n"), _tcserror(errno));
+                               _tprintf(_T("new failed!: %s\n"), _tcserror(errno));
                        }
                }
        }
@@ -409,18 +404,18 @@ BOOL AddValuePair(char *name, char *value)
        return ret;
 }
 
-//
-// Callback function for debug messages from client library
-//
-static void DebugCallback(TCHAR *pMsg)
+/**
+ * Callback function for debug messages from client library
+ */
+static void DebugCallback(const TCHAR *pMsg)
 {
        _tprintf(_T("NXCL: %s\n"), pMsg);
 }
 
-//
-// Initialize client library and connect to the server
-//
-BOOL Startup()
+/**
+ * Initialize client library and connect to the server
+ */
+static BOOL Startup()
 {
        BOOL ret = FALSE;
        UINT32 dwResult;
@@ -468,9 +463,9 @@ BOOL Startup()
 #define _PASSWD optPassword
 #endif
 
-               dwResult = NXCConnect(optEncrypt ? NXCF_ENCRYPT : 0, _HOST, _USER, _PASSWD,
-                                     0, NULL, NULL, &hSession,
-                                     _T("nxpush/") NETXMS_VERSION_STRING, NULL);
+      session = new NXCSession();
+      dwResult = session->connect(_HOST, _USER, _PASSWD, optEncrypt ? NXCF_ENCRYPT : 0, _T("nxpush/") NETXMS_VERSION_STRING);
+
 #ifdef UNICODE
                free(wHost);
                free(wUser);
@@ -485,7 +480,7 @@ BOOL Startup()
                }
                else
                {
-                       NXCSetCommandTimeout(hSession, 5 * 1000);
+         session->setCommandTimeout(5 * 1000);
                        ret = TRUE;
                }
        }
@@ -493,10 +488,10 @@ BOOL Startup()
        return ret;
 }
 
-//
-// Send all DCIs
-//
-BOOL Send()
+/**
+ * Send all DCIs
+ */
+static BOOL Send()
 {
        BOOL ret = TRUE;
        UINT32 errIdx;
@@ -506,18 +501,18 @@ BOOL Send()
 
        if (optBatchSize == 0)
        {
-               optBatchSize = queueSize;
+               optBatchSize = queue.size();
        }
 
-       batches = queueSize / optBatchSize;
-       if (queueSize % optBatchSize != 0)
+       batches = queue.size() / optBatchSize;
+       if (queue.size() % optBatchSize != 0)
        {
                batches++;
        }
 
        for (i = 0; i < batches; i++)
        {
-               size = min(optBatchSize, queueSize - (optBatchSize * i));
+               size = min(optBatchSize, queue.size() - (optBatchSize * i));
 
                if (optVerbose > 1)
                {
@@ -528,18 +523,18 @@ BOOL Send()
                {
                        for (int j = 0; j < size; j++)
                        {
-                               NXC_DCI_PUSH_DATA *rec = &queue[(optBatchSize * i) + j];
+            NXCPushData *rec = queue.get(optBatchSize * i + j);
                                _tprintf(_T("Record #%d: \"%s\" for %d(%s):%d(%s)\n"),
                                        (optBatchSize * i) + j + 1,
-                                       rec->pszValue,
-                                       rec->dwNodeId,
-                                       rec->pszNodeName != NULL ? rec->pszNodeName : _T("n/a"),
-                                       rec->dwId,
-                                       rec->pszName != NULL ? rec->pszName : _T("n/a"));
+                                       rec->value,
+                                       rec->nodeId,
+                                       rec->nodeName != NULL ? rec->nodeName : _T("n/a"),
+                                       rec->dciId,
+                                       rec->dciName != NULL ? rec->dciName : _T("n/a"));
                        }
                }
 
-               UINT32 dwResult = NXCPushDCIData(hSession, size, &queue[optBatchSize * i], &errIdx);
+      UINT32 dwResult = ((DataCollectionController *)(session->getController(CONTROLLER_DATA_COLLECTION)))->pushData(&queue, &errIdx);
                if (dwResult != RCC_SUCCESS)
                {
                        if (optVerbose > 0)
@@ -565,27 +560,22 @@ BOOL Send()
        return ret;
 }
 
-//
-// Disconnect and cleanup
-//
-BOOL Teardown()
+/**
+ * Disconnect and cleanup
+ */
+static BOOL Teardown()
 {
-       if (hSession != NULL)
+       if (session != NULL)
        {
-               NXCDisconnect(hSession);
+      delete session;
        }
 
-       if (queue != NULL)
+       for(int i = 0; i < queue.size(); i++)
        {
-               for (int i = 0; i < queueSize; i++)
-               {
-                       if (queue[i].pszName != NULL) free(queue[i].pszName);
-                       if (queue[i].pszNodeName != NULL) free(queue[i].pszNodeName);
-                       if (queue[i].pszValue != NULL) free(queue[i].pszValue);
-               }
-               free(queue);
-               queue = NULL;
-               queueSize = 0;
+      NXCPushData *d = queue.get(i);
+               safe_free(d->dciName);
+               safe_free(d->nodeName);
+               safe_free(d->value);
        }
 
        return TRUE;
index a36867b..59610cf 100644 (file)
@@ -145,7 +145,7 @@ static void CryptoDbgPrintf(int level, const TCHAR *format, ...)
 /**
  * Initialize OpenSSL library
  */
-BOOL LIBNETXMS_EXPORTABLE InitCryptoLib(UINT32 dwEnabledCiphers, void (*debugCallback)(int, const TCHAR *, va_list args))
+bool LIBNETXMS_EXPORTABLE InitCryptoLib(UINT32 dwEnabledCiphers, void (*debugCallback)(int, const TCHAR *, va_list args))
 {
    s_debugCallback = debugCallback;
    s_noEncryptionFlag = htons(MF_DONT_ENCRYPT);
@@ -195,7 +195,7 @@ BOOL LIBNETXMS_EXPORTABLE InitCryptoLib(UINT32 dwEnabledCiphers, void (*debugCal
 #else
    CryptoDbgPrintf(1, _T("Crypto library will not be initialized because libnetxms was built without encryption support"));
 #endif   /* _WITH_ENCRYPTION */
-   return TRUE;
+   return true;
 }
 
 /**
@@ -217,9 +217,9 @@ NXCP_ENCRYPTED_MESSAGE LIBNETXMS_EXPORTABLE *NXCPEncryptMessage(NXCPEncryptionCo
 /**
  * Decrypt message
  */
-BOOL LIBNETXMS_EXPORTABLE NXCPDecryptMessage(NXCPEncryptionContext *pCtx, NXCP_ENCRYPTED_MESSAGE *msg, BYTE *pDecryptionBuffer)
+bool LIBNETXMS_EXPORTABLE NXCPDecryptMessage(NXCPEncryptionContext *pCtx, NXCP_ENCRYPTED_MESSAGE *msg, BYTE *pDecryptionBuffer)
 {
-   return (pCtx != NULL) ? pCtx->decryptMessage(msg, pDecryptionBuffer) : FALSE;
+   return (pCtx != NULL) ? pCtx->decryptMessage(msg, pDecryptionBuffer) : false;
 }
 
 /**
index d828955..6bfcf08 100644 (file)
@@ -27,9 +27,7 @@
 #include <nms_common.h>
 #include <nms_util.h>
 #include <nxcpapi.h>
-
-#define LIBNXCL_NO_DECLARATIONS
-#include <nxclapi.h>
+#include <nxcldefs.h>
 
 #define MAX_CODEPAGE_LEN               64
 
index 294ec22..f5cdf58 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "nxcore.h"
 #include <netxms-regex.h>
+#include <nxtools.h>
 
 /**
  * Tool startup info
index ad0229b..2a3d553 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "nxcore.h"
 #include <netxms_mt.h>
+#include <nxtools.h>
 
 #ifdef _WIN32
 #include <psapi.h>
@@ -395,7 +396,7 @@ void ClientSession::readThread()
       // Check for decryption error
       if (result == MSGRECV_DECRYPTION_FAILURE)
       {
-         debugPrintf(4, _T("Unable to decrypt received message"));
+         debugPrintf(4, _T("readThread: Unable to decrypt received message"));
          continue;
       }
 
@@ -10843,16 +10844,15 @@ void ClientSession::cancelFileMonitoring(NXCPMessage *request)
             if (response != NULL)
             {
                rcc = response->getFieldAsUInt32(VID_RCC);
-               if(rcc == RCC_SUCCESS)
+               if (rcc == ERR_SUCCESS)
                {
                   msg.setField(VID_RCC, rcc);
                   debugPrintf(6, _T("File monitoring cancelled successfully"));
                }
                else
                {
-                  msg.setField(VID_RCC, RCC_INTERNAL_ERROR);
-
-                  debugPrintf(6, _T("Error on agent: %d"), rcc);
+                  msg.setField(VID_RCC, AgentErrorToRCC(rcc));
+                  debugPrintf(6, _T("Error on agent: %d (%s)"), rcc, AgentErrorCodeToText(rcc));
                }
             }
             else
@@ -13214,7 +13214,7 @@ void ClientSession::getEffectiveRights(NXCPMessage *request)
 void ClientSession::fileManagerControl(NXCPMessage *request)
 {
    NXCPMessage msg, *response = NULL, *responseMessage;
-       UINT32 rcc;
+       UINT32 rcc = RCC_INTERNAL_ERROR;
    responseMessage = &msg;
 
    msg.setCode(CMD_REQUEST_COMPLETED);
@@ -13241,7 +13241,7 @@ void ClientSession::fileManagerControl(NXCPMessage *request)
                if (response != NULL)
                {
                   rcc = response->getFieldAsUInt32(VID_RCC);
-                  if(rcc == RCC_SUCCESS)
+                  if (rcc == ERR_SUCCESS)
                   {
                      response->setId(msg.getId());
                      response->setCode(CMD_REQUEST_COMPLETED);
@@ -13286,8 +13286,9 @@ void ClientSession::fileManagerControl(NXCPMessage *request)
                   }
                   else
                   {
-                     msg.setField(VID_RCC, rcc); // TODO: add transofrmation script
-                     debugPrintf(6, _T("ClientSession::getAgentFolderContent: Error on agent: %d"), rcc);
+                     debugPrintf(6, _T("ClientSession::getAgentFolderContent: Error on agent: %d (%s)"), rcc, AgentErrorCodeToText(rcc));
+                     rcc = AgentErrorToRCC(rcc);
+                     msg.setField(VID_RCC, rcc);
                   }
                }
                else
@@ -13317,7 +13318,7 @@ void ClientSession::fileManagerControl(NXCPMessage *request)
                msg.setField(VID_RCC, RCC_INVALID_OBJECT_ID);
        }
 
-       if(rcc == RCC_ACCESS_DENIED)
+       if (rcc == RCC_ACCESS_DENIED)
        {
       switch(request->getCode())
       {
index 653790c..dc3fd68 100644 (file)
 #define LIBNXSRV_EXPORTABLE
 #endif
 
-#ifndef LIBNXCL_NO_DECLARATIONS
-#define LIBNXCL_NO_DECLARATIONS 1
-#endif
-#include <nxclapi.h>
 #include <nxcpapi.h>
+#include <nms_util.h>
 #include <nms_agent.h>
 #include <nxsnmp.h>
 #include <netxms_isc.h>
+#include <nxcldefs.h>
 
 #ifdef INCLUDE_LIBNXSRV_MESSAGES
 #include "../libnxsrv/messages.h"
@@ -632,7 +630,8 @@ public:
 void LIBNXSRV_EXPORTABLE DestroyArpCache(ARP_CACHE *pArpCache);
 void LIBNXSRV_EXPORTABLE DestroyRoutingTable(ROUTING_TABLE *pRT);
 void LIBNXSRV_EXPORTABLE SortRoutingTable(ROUTING_TABLE *pRT);
-const TCHAR LIBNXSRV_EXPORTABLE *AgentErrorCodeToText(int iError);
+const TCHAR LIBNXSRV_EXPORTABLE *AgentErrorCodeToText(UINT32 err);
+UINT32 LIBNXSRV_EXPORTABLE AgentErrorToRCC(UINT32 err);
 
 void LIBNXSRV_EXPORTABLE WriteLogOther(WORD wType, const TCHAR *format, ...)
 #if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
index 1ab9c5b..cb80a5a 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath="..\..\..\include\nxcpapi.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\..\include\nxsnmp.h"
                                >
                        </File>
index 077cf00..c637983 100644 (file)
@@ -77,17 +77,36 @@ static struct
 /**
  * Resolve agent's error code to text
  */
-const TCHAR LIBNXSRV_EXPORTABLE *AgentErrorCodeToText(int iError)
+const TCHAR LIBNXSRV_EXPORTABLE *AgentErrorCodeToText(UINT32 err)
 {
    int i;
 
    for(i = 0; m_agentErrors[i].pszText != NULL; i++)
-      if (iError == m_agentErrors[i].iCode)
+      if (err == (UINT32)m_agentErrors[i].iCode)
          return m_agentErrors[i].pszText;
    return _T("Unknown error code");
 }
 
 /**
+ * Convert agent error code to client RCC
+ */
+UINT32 LIBNXSRV_EXPORTABLE AgentErrorToRCC(UINT32 err)
+{
+   switch(err)
+   {
+      case ERR_ACCESS_DENIED:
+         return RCC_ACCESS_DENIED;
+      case ERR_IO_FAILURE:
+         return RCC_IO_ERROR;
+      case ERR_ALREADY_AUTHENTICATED:
+      case ERR_AUTH_FAILED:
+      case ERR_AUTH_NOT_REQUIRED:
+         return RCC_COMM_FAILURE;
+   }
+   return RCC_AGENT_ERROR;
+}
+
+/**
  * Destroy ARP cache created by discovery functions
  */
 void LIBNXSRV_EXPORTABLE DestroyArpCache(ARP_CACHE *pArpCache)
index 27de961..a1d1730 100644 (file)
@@ -26,7 +26,6 @@
 #include <nms_common.h>
 #include <nxsrvapi.h>
 #include <nxdbapi.h>
-#include <nms_util.h>
 
 #ifdef _WIN32
 #define EXPORT __declspec(dllexport)
index b2b2168..d65d0a2 100644 (file)
@@ -24,7 +24,6 @@
 #include <nms_common.h>
 #include <nms_agent.h>
 #include <nms_util.h>
-#include <nxclapi.h>
 #include <nxsrvapi.h>
 
 #ifndef _WIN32
index 07ee29a..45ff97e 100644 (file)
@@ -1,6 +1,6 @@
 /* 
 ** nxap - command line tool used to manage agent policies
-** Copyright (C) 2010 Victor Kirhenshtein
+** Copyright (C) 2010-2014 Victor Kirhenshtein
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -23,7 +23,6 @@
 #include <nms_common.h>
 #include <nms_agent.h>
 #include <nms_util.h>
-#include <nxclapi.h>
 #include <nxsrvapi.h>
 
 #ifndef _WIN32
index ca14466..4ea7fd3 100644 (file)
@@ -21,6 +21,7 @@
 **/
 
 #include "nxdbmgr.h"
+#include <nxevent.h>
 
 /**
  * Externals
index 3a0121e..de3a77c 100644 (file)
@@ -23,7 +23,7 @@
 #include <nms_common.h>
 #include <nms_agent.h>
 #include <nms_util.h>
-#include <nxclapi.h>
+#include <nxcpapi.h>
 #include <nxsrvapi.h>
 
 #ifndef _WIN32
index 74ed393..a12e9cc 100644 (file)
@@ -1,6 +1,6 @@
 /* 
 ** nxupload - command line tool used to upload files to NetXMS agent
-** Copyright (C) 2004 Victor Kirhenshtein
+** Copyright (C) 2004-2014 Victor Kirhenshtein
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 **
-** $module: nxupload.cpp
+** File: nxupload.cpp
 **
 **/
 
 #include <nms_common.h>
 #include <nms_agent.h>
 #include <nms_util.h>
-#include <nxclapi.h>
 #include <nxsrvapi.h>
 
 #ifndef _WIN32