refactoring of NXCP-related classes and structures
authorVictor Kirhenshtein <victor@netxms.org>
Sat, 22 Nov 2014 10:34:35 +0000 (12:34 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Sat, 22 Nov 2014 10:34:35 +0000 (12:34 +0200)
173 files changed:
include/geolocation.h
include/netxms_isc.h
include/netxms_maps.h
include/nms_agent.h
include/nms_cscp.h
include/nms_util.h
include/nxclapi.h
include/nxcpapi.h
include/nxsl_classes.h
src/agent/core/actions.cpp
src/agent/core/comm.cpp
src/agent/core/config.cpp
src/agent/core/ctrl.cpp
src/agent/core/epp.cpp
src/agent/core/extagent.cpp
src/agent/core/getparam.cpp
src/agent/core/master.cpp
src/agent/core/nxagentd.cpp
src/agent/core/nxagentd.h
src/agent/core/policy.cpp
src/agent/core/push.cpp
src/agent/core/register.cpp
src/agent/core/sa.cpp
src/agent/core/sd.cpp
src/agent/core/session.cpp
src/agent/core/snmpproxy.cpp
src/agent/core/snmptrapproxy.cpp
src/agent/core/subagent.cpp
src/agent/core/trap.cpp
src/agent/nxsagent/main.cpp
src/agent/nxsagent/nxsagent.h
src/agent/nxsagent/screenshot.cpp
src/agent/subagents/db2/db2_subagent.h
src/agent/subagents/filemgr/filemgr.cpp
src/agent/subagents/filemgr/logmonitoring.cpp
src/agent/subagents/java/main.cpp
src/agent/subagents/portCheck/main.cpp
src/agent/tools/nxapush/nxapush.cpp
src/libnetxms/crypto.cpp
src/libnetxms/geolocation.cpp
src/libnetxms/message.cpp
src/libnetxms/msgrecv.cpp
src/libnetxms/msgwq.cpp
src/libnetxms/nxcp.cpp
src/libnetxms/strmap.cpp
src/libnetxms/strset.cpp
src/libnetxms/table.cpp
src/libnxcl/actions.cpp
src/libnxcl/agentcfg.cpp
src/libnxcl/alarms.cpp
src/libnxcl/cert.cpp
src/libnxcl/comm.cpp
src/libnxcl/datacoll.cpp
src/libnxcl/epp.cpp
src/libnxcl/eventdb.cpp
src/libnxcl/events.cpp
src/libnxcl/graph.cpp
src/libnxcl/layer2.cpp
src/libnxcl/libnxcl.h
src/libnxcl/main.cpp
src/libnxcl/mib.cpp
src/libnxcl/mp.cpp
src/libnxcl/objects.cpp
src/libnxcl/objtools.cpp
src/libnxcl/package.cpp
src/libnxcl/script.cpp
src/libnxcl/server.cpp
src/libnxcl/session.cpp
src/libnxcl/situation.cpp
src/libnxcl/snmp.cpp
src/libnxcl/snmptrap.cpp
src/libnxcl/users.cpp
src/libnxmap/element.cpp
src/libnxmap/link.cpp
src/libnxmap/objlist.cpp
src/libnxsl/library.cpp
src/server/core/accesspoint.cpp
src/server/core/acl.cpp
src/server/core/actions.cpp
src/server/core/admin.cpp
src/server/core/agent.cpp
src/server/core/agent_policy.cpp
src/server/core/alarm.cpp
src/server/core/ap_config.cpp
src/server/core/audit.cpp
src/server/core/bizservice.cpp
src/server/core/cert.cpp
src/server/core/client.cpp
src/server/core/cluster.cpp
src/server/core/columnfilter.cpp
src/server/core/components.cpp
src/server/core/condition.cpp
src/server/core/container.cpp
src/server/core/dashboard.cpp
src/server/core/datacoll.cpp
src/server/core/dcitem.cpp
src/server/core/dcithreshold.cpp
src/server/core/dcobject.cpp
src/server/core/dcst.cpp
src/server/core/dctable.cpp
src/server/core/dctarget.cpp
src/server/core/dctcolumn.cpp
src/server/core/dctthreshold.cpp
src/server/core/debug.cpp
src/server/core/download_job.cpp
src/server/core/ef.cpp
src/server/core/epp.cpp
src/server/core/events.cpp
src/server/core/fdb.cpp
src/server/core/interface.cpp
src/server/core/isc.cpp
src/server/core/job.cpp
src/server/core/jobmgr.cpp
src/server/core/jobqueue.cpp
src/server/core/logfilter.cpp
src/server/core/loghandle.cpp
src/server/core/main.cpp
src/server/core/mdsession.cpp
src/server/core/mobile.cpp
src/server/core/modules.cpp
src/server/core/mt.cpp
src/server/core/netmap.cpp
src/server/core/netobj.cpp
src/server/core/netsrv.cpp
src/server/core/node.cpp
src/server/core/nodelink.cpp
src/server/core/nxslext.cpp
src/server/core/objtools.cpp
src/server/core/package.cpp
src/server/core/rack.cpp
src/server/core/reporting.cpp
src/server/core/session.cpp
src/server/core/situation.cpp
src/server/core/slmcheck.cpp
src/server/core/snmptrap.cpp
src/server/core/subnet.cpp
src/server/core/svccontainer.cpp
src/server/core/swpkg.cpp
src/server/core/syslogd.cpp
src/server/core/template.cpp
src/server/core/tools.cpp
src/server/core/tracert.cpp
src/server/core/userdb.cpp
src/server/core/userdb_objects.cpp
src/server/core/vpnconn.cpp
src/server/core/winperf.cpp
src/server/core/zone.cpp
src/server/include/netxms_mt.h
src/server/include/nms_actions.h
src/server/include/nms_alarm.h
src/server/include/nms_core.h
src/server/include/nms_dcoll.h
src/server/include/nms_events.h
src/server/include/nms_objects.h
src/server/include/nms_script.h
src/server/include/nms_topo.h
src/server/include/nms_users.h
src/server/include/nxcore_jobs.h
src/server/include/nxcore_logs.h
src/server/include/nxcore_situations.h
src/server/include/nxcore_winperf.h
src/server/include/nxmodule.h
src/server/include/nxsrvapi.h
src/server/libnxsrv/agent.cpp
src/server/libnxsrv/apinfo.cpp
src/server/libnxsrv/isc.cpp
src/server/libnxsrv/snmpproxy.cpp
src/server/libnxsrv/vlan.cpp
src/server/tools/nxadm/comm.cpp
src/server/tools/nxadm/nxadm.cpp
src/server/tools/nxadm/nxadm.h
src/snmp/libnxsnmp/libnxsnmp.h
src/snmp/libnxsnmp/mib.cpp

index 1565ea5..af0674e 100644 (file)
@@ -64,7 +64,7 @@ public:
        GeoLocation(int type, double lat, double lon, int accuracy = 0, time_t timestamp = 0);
        GeoLocation(int type, const TCHAR *lat, const TCHAR *lon, int accuracy = 0, time_t timestamp = 0);
        GeoLocation(const GeoLocation &src);
-       GeoLocation(CSCPMessage &msg);
+       GeoLocation(NXCPMessage &msg);
        ~GeoLocation();
 
        GeoLocation& operator =(const GeoLocation &src);
@@ -79,7 +79,7 @@ public:
        time_t getTimestamp() { return m_timestamp; }
    bool sameLocation(double lat, double lon, int oldAccurasy);
 
-       void fillMessage(CSCPMessage &msg);
+       void fillMessage(NXCPMessage &msg);
 };
 
 
index 0a14cb4..25afd45 100644 (file)
@@ -93,9 +93,9 @@ typedef struct
        UINT32 id;                                                              // Service ID
        const TCHAR *name;                                      // Name
        const TCHAR *enableParameter;           // Server parameter to be set to enable service
-       BOOL (*setupSession)(ISCSession *, CSCPMessage *);  // Session setup handler
+       BOOL (*setupSession)(ISCSession *, NXCPMessage *);  // Session setup handler
        void (*closeSession)(ISCSession *);          // Session close handler
-       BOOL (*processMsg)(ISCSession *, CSCPMessage *, CSCPMessage *);
+       BOOL (*processMsg)(ISCSession *, NXCPMessage *, NXCPMessage *);
 } ISC_SERVICE;
 
 
index 1ccc2f1..6b47244 100644 (file)
@@ -100,7 +100,7 @@ protected:
 public:
    nxmap_ObjList();
    nxmap_ObjList(nxmap_ObjList *src);
-   nxmap_ObjList(CSCPMessage *msg);
+   nxmap_ObjList(NXCPMessage *msg);
    ~nxmap_ObjList();
 
    void addObject(UINT32 id);
@@ -114,7 +114,7 @@ public:
    UINT32 getNumLinks() { return m_linkList->size(); }
    ObjectArray<ObjLink> *getLinks() { return m_linkList; }
 
-       void createMessage(CSCPMessage *pMsg);
+       void createMessage(NXCPMessage *pMsg);
 
        bool isLinkExist(UINT32 objectId1, UINT32 objectId2);
        bool isObjectExist(UINT32 objectId);
@@ -163,11 +163,11 @@ protected:
 public:
        NetworkMapElement(UINT32 id, UINT32 flags = 0);
        NetworkMapElement(UINT32 id, Config *config, UINT32 flags = 0);
-       NetworkMapElement(CSCPMessage *msg, UINT32 baseId);
+       NetworkMapElement(NXCPMessage *msg, UINT32 baseId);
        virtual ~NetworkMapElement();
 
        virtual void updateConfig(Config *config);
-       virtual void fillMessage(CSCPMessage *msg, UINT32 baseId);
+       virtual void fillMessage(NXCPMessage *msg, UINT32 baseId);
 
        UINT32 getId() { return m_id; }
        LONG getType() { return m_type; }
@@ -189,11 +189,11 @@ protected:
 public:
        NetworkMapObject(UINT32 id, UINT32 objectId, UINT32 flags = 0);
        NetworkMapObject(UINT32 id, Config *config, UINT32 flags = 0);
-       NetworkMapObject(CSCPMessage *msg, UINT32 baseId);
+       NetworkMapObject(NXCPMessage *msg, UINT32 baseId);
        virtual ~NetworkMapObject();
 
        virtual void updateConfig(Config *config);
-       virtual void fillMessage(CSCPMessage *msg, UINT32 baseId);
+       virtual void fillMessage(NXCPMessage *msg, UINT32 baseId);
 
        UINT32 getObjectId() { return m_objectId; }
 };
@@ -213,11 +213,11 @@ protected:
 public:
        NetworkMapDecoration(UINT32 id, LONG decorationType, UINT32 flags = 0);
        NetworkMapDecoration(UINT32 id, Config *config, UINT32 flags = 0);
-       NetworkMapDecoration(CSCPMessage *msg, UINT32 baseId);
+       NetworkMapDecoration(NXCPMessage *msg, UINT32 baseId);
        virtual ~NetworkMapDecoration();
 
        virtual void updateConfig(Config *config);
-       virtual void fillMessage(CSCPMessage *msg, UINT32 baseId);
+       virtual void fillMessage(NXCPMessage *msg, UINT32 baseId);
 
        LONG getDecorationType() { return m_decorationType; }
        UINT32 getColor() { return m_color; }
@@ -238,11 +238,11 @@ protected:
 public:
        NetworkMapDCIContainer(UINT32 id, TCHAR* objectDCIList, UINT32 flags = 0);
        NetworkMapDCIContainer(UINT32 id, Config *config, UINT32 flags = 0);
-       NetworkMapDCIContainer(CSCPMessage *msg, UINT32 baseId);
+       NetworkMapDCIContainer(NXCPMessage *msg, UINT32 baseId);
        virtual ~NetworkMapDCIContainer();
 
        virtual void updateConfig(Config *config);
-       virtual void fillMessage(CSCPMessage *msg, UINT32 baseId);
+       virtual void fillMessage(NXCPMessage *msg, UINT32 baseId);
 
        TCHAR* getObjectDCIList() { return m_xmlDCIList; }
 };
@@ -258,11 +258,11 @@ protected:
 public:
        NetworkMapDCIImage(UINT32 id, TCHAR* objectDCIList, UINT32 flags = 0);
        NetworkMapDCIImage(UINT32 id, Config *config, UINT32 flags = 0);
-       NetworkMapDCIImage(CSCPMessage *msg, UINT32 baseId);
+       NetworkMapDCIImage(NXCPMessage *msg, UINT32 baseId);
        virtual ~NetworkMapDCIImage();
 
        virtual void updateConfig(Config *config);
-       virtual void fillMessage(CSCPMessage *msg, UINT32 baseId);
+       virtual void fillMessage(NXCPMessage *msg, UINT32 baseId);
 
        TCHAR* getObjectDCIList() { return m_config; }
 };
@@ -284,10 +284,10 @@ protected:
 
 public:
        NetworkMapLink(UINT32 e1, UINT32 e2, int type);
-       NetworkMapLink(CSCPMessage *msg, UINT32 baseId);
+       NetworkMapLink(NXCPMessage *msg, UINT32 baseId);
        virtual ~NetworkMapLink();
 
-       void fillMessage(CSCPMessage *msg, UINT32 baseId);
+       void fillMessage(NXCPMessage *msg, UINT32 baseId);
 
        UINT32 getElement1() { return m_element1; }
        UINT32 getElement2() { return m_element2; }
index e85d286..ed033a2 100644 (file)
@@ -365,8 +365,8 @@ public:
    virtual bool isControlServer() = 0;
    virtual const InetAddress& getServerAddress() = 0;
 
-   virtual void sendMessage(CSCPMessage *pMsg) = 0;
-   virtual void sendRawMessage(CSCP_MESSAGE *pMsg) = 0;
+   virtual void sendMessage(NXCPMessage *pMsg) = 0;
+   virtual void sendRawMessage(NXCP_MESSAGE *pMsg) = 0;
        virtual bool sendFile(UINT32 requestId, const TCHAR *file, long offset) = 0;
    virtual UINT32 openFile(TCHAR* nameOfFile, UINT32 requestId) = 0;
 };
@@ -428,7 +428,7 @@ typedef struct
 
 #define NETXMS_SUBAGENT_INFO_MAGIC     ((UINT32)0x20110301)
 
-class CSCPMessage;
+class NXCPMessage;
 
 /**
  * Subagent initialization structure
@@ -440,7 +440,7 @@ typedef struct
    TCHAR version[32];
        BOOL (* init)(Config *);   // Called to initialize subagent. Can be NULL.
    void (* shutdown)();       // Called at subagent unload. Can be NULL.
-   BOOL (* commandHandler)(UINT32 command, CSCPMessage *request, CSCPMessage *response, AbstractCommSession *session);
+   BOOL (* commandHandler)(UINT32 command, NXCPMessage *request, NXCPMessage *response, AbstractCommSession *session);
    UINT32 numParameters;
    NETXMS_SUBAGENT_PARAM *parameters;
    UINT32 numLists;
index 613f546..64ddb14 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** NetXMS - Network Management System
-** Copyright (C) 2003-2013 Victor Kirhenshtein
+** 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
  */
 typedef struct
 {
-   UINT32 fieldId;      // Field identifier
-   BYTE  bType;         // Data type
-   BYTE  bPadding;      // Padding
-   WORD wInt16;
+   UINT32 fieldId;  // Field identifier
+   BYTE type;       // Data type
+   BYTE padding;    // Padding
+   WORD int16;
    union
    {
-      UINT32 dwInteger;
-      UINT64 qwInt64;
-      double dFloat;
+      INT32 int32;
+      INT64 int64;
+      UINT32 uint32;
+      UINT64 uint64;
+      double real;
       struct
       {
-         UINT32 dwLen;
-         WORD szValue[1];
+         UINT32 length;
+         WORD value[1]; // actual size depends on length value
       } string;
    } data;
-} CSCP_DF;
-
-#define df_int16  wInt16
-#define df_int32  data.dwInteger
-#define df_int64  data.qwInt64
-#define df_real   data.dFloat
+} NXCP_MESSAGE_FIELD;
+
+#define df_int16  int16
+#define df_int32  data.int32
+#define df_uint32 data.uint32
+#define df_int64  data.int64
+#define df_uint64 data.uint64
+#define df_real   data.real
 #define df_string data.string
 
 /**
@@ -107,13 +111,13 @@ typedef struct
  */
 typedef struct
 {
-   UINT16 wCode;       // Message (command) code
-   UINT16 wFlags;      // Message flags
-   UINT32 dwSize;     // Message size (including header) in bytes
-   UINT32 dwId;       // Unique message identifier
-   UINT32 dwNumVars;  // Number of variables in message
-   CSCP_DF df[1];    // Data fields
-} CSCP_MESSAGE;
+   UINT16 code;      // Message (command) code
+   UINT16 flags;     // Message flags
+   UINT32 size;      // Message size (including header) in bytes
+   UINT32 id;        // Unique message identifier
+   UINT32 numFields; // Number of fields in message
+   NXCP_MESSAGE_FIELD fields[1];    // Data fields - actual length depends on value in numFields
+} NXCP_MESSAGE;
 
 /**
  * Encrypted payload header
@@ -129,10 +133,10 @@ typedef struct
  */
 typedef struct
 {
-   WORD wCode;       // Should be CMD_ENCRYPTED_MESSAGE
-   BYTE nPadding;    // Number of bytes added to the end of message
-   BYTE nReserved;
-   UINT32 dwSize;    // Size of encrypted message (including encryption header and padding)
+   WORD code;       // Should be CMD_ENCRYPTED_MESSAGE
+   BYTE padding;    // Number of bytes added to the end of message
+   BYTE reserved;
+   UINT32 size;    // Size of encrypted message (including encryption header and padding)
    BYTE data[1];     // Encrypted payload
 } NXCP_ENCRYPTED_MESSAGE;
 
@@ -178,12 +182,12 @@ typedef struct
 /**
  * Data types
  */
-#define CSCP_DT_INT32      0
-#define CSCP_DT_STRING     1
-#define CSCP_DT_INT64      2
-#define CSCP_DT_INT16      3
-#define CSCP_DT_BINARY     4
-#define CSCP_DT_FLOAT      5
+#define NXCP_DT_INT32      0
+#define NXCP_DT_STRING     1
+#define NXCP_DT_INT64      2
+#define NXCP_DT_INT16      3
+#define NXCP_DT_BINARY     4
+#define NXCP_DT_FLOAT      5
 
 /**
  * Message flags
@@ -1181,15 +1185,11 @@ typedef struct
 
 #define VID_LOC_LIST_BASE           ((UINT32)0x10000000)
 
-//
-// Inline functions
-//
-
 #ifdef __cplusplus
 
-inline BOOL IsBinaryMsg(CSCP_MESSAGE *pMsg)
+inline BOOL IsBinaryMsg(NXCP_MESSAGE *msg)
 {
-   return ntohs(pMsg->wFlags) & MF_BINARY;
+   return ntohs(msg->flags) & MF_BINARY;
 }
 
 #endif
index de4fc10..b1588e8 100644 (file)
@@ -460,7 +460,7 @@ public:
 /**
  * NXCP message class
  */
-class CSCPMessage;
+class NXCPMessage;
 
 /**
  * String map class
@@ -484,7 +484,7 @@ public:
        UINT32 getULong(const TCHAR *key, UINT32 defaultValue);
        bool getBoolean(const TCHAR *key, bool defaultValue);
 
-   void fillMessage(CSCPMessage *msg, UINT32 sizeFieldId, UINT32 baseFieldId);
+   void fillMessage(NXCPMessage *msg, UINT32 sizeFieldId, UINT32 baseFieldId);
 };
 
 /**
@@ -546,7 +546,7 @@ struct StringSetEntry;
 /**
  * NXCP message
  */
-class CSCPMessage;
+class NXCPMessage;
 
 /**
  * String set class
@@ -574,8 +574,8 @@ public:
    void addAllPreallocated(TCHAR **strings, int count);
    void forEach(bool (*cb)(const TCHAR *, void *), void *userData);
 
-   void fillMessage(CSCPMessage *msg, UINT32 baseId, UINT32 countId);
-   void addAllFromMessage(CSCPMessage *msg, UINT32 baseId, UINT32 countId, bool clearBeforeAdd, bool toUppercase);
+   void fillMessage(NXCPMessage *msg, UINT32 baseId, UINT32 countId);
+   void addAllFromMessage(NXCPMessage *msg, UINT32 baseId, UINT32 countId, bool clearBeforeAdd, bool toUppercase);
 
    String getAll(const TCHAR *separator);
 };
@@ -608,7 +608,7 @@ public:
    }
 };
 
-class CSCPMessage;
+class NXCPMessage;
 
 /**
  * Table column definition
@@ -623,11 +623,11 @@ private:
 
 public:
    TableColumnDefinition(const TCHAR *name, const TCHAR *displayName, INT32 dataType, bool isInstance);
-   TableColumnDefinition(CSCPMessage *msg, UINT32 baseId);
+   TableColumnDefinition(NXCPMessage *msg, UINT32 baseId);
    TableColumnDefinition(TableColumnDefinition *src);
    ~TableColumnDefinition();
 
-   void fillMessage(CSCPMessage *msg, UINT32 baseId);
+   void fillMessage(NXCPMessage *msg, UINT32 baseId);
 
    const TCHAR *getName() { return m_name; }
    const TCHAR *getDisplayName() { return m_displayName; }
@@ -710,17 +710,17 @@ private:
    int m_source;
    bool m_extendedFormat;
 
-       void createFromMessage(CSCPMessage *msg);
+       void createFromMessage(NXCPMessage *msg);
        void destroy();
 
 public:
    Table();
    Table(Table *src);
-   Table(CSCPMessage *msg);
+   Table(NXCPMessage *msg);
    virtual ~Table();
 
-       int fillMessage(CSCPMessage &msg, int offset, int rowLimit);
-       void updateFromMessage(CSCPMessage *msg);
+       int fillMessage(NXCPMessage &msg, int offset, int rowLimit);
+       void updateFromMessage(NXCPMessage *msg);
 
    void addAll(Table *src);
    void copyRow(Table *src, int row);
index 31d9a8c..2c6fbb7 100644 (file)
@@ -1473,7 +1473,7 @@ typedef struct
    uuid_t guid;
    UINT32 dwId;
    UINT64 dwSystemRights;
-   WORD wFlags;
+   WORD flags;
    WORD nAuthMethod;        // Only for users
    UINT32 dwNumMembers;     // Only for groups
    UINT32 *pdwMemberList;   // Only for groups
@@ -1517,7 +1517,7 @@ typedef struct
    BYTE iDataType;
    BYTE iStatus;
    BYTE iDeltaCalculation;
-       WORD wFlags;
+       WORD flags;
    UINT32 dwNumThresholds;
    NXC_DCI_THRESHOLD *pThresholdList;
    TCHAR *pszFormula;
@@ -2039,7 +2039,7 @@ private:
    TCHAR *m_text;
 
 public:
-   AlarmComment(CSCPMessage *msg, UINT32 baseId);
+   AlarmComment(NXCPMessage *msg, UINT32 baseId);
    ~AlarmComment();
 
    UINT32 getId() { return m_id; }
@@ -2071,8 +2071,8 @@ void LIBNXCL_EXPORTABLE NXCSetDebugCallback(NXC_DEBUG_CALLBACK pFunc);
 
 /** Low-level messaging **/
 UINT32 LIBNXCL_EXPORTABLE NXCGenerateMessageId(NXC_SESSION hSession);
-BOOL LIBNXCL_EXPORTABLE NXCSendMessage(NXC_SESSION hSession, CSCPMessage *msg);
-CSCPMessage LIBNXCL_EXPORTABLE *NXCWaitForMessage(NXC_SESSION hSession, WORD wCode, UINT32 dwRqId);
+BOOL LIBNXCL_EXPORTABLE NXCSendMessage(NXC_SESSION hSession, NXCPMessage *msg);
+NXCPMessage LIBNXCL_EXPORTABLE *NXCWaitForMessage(NXC_SESSION hSession, WORD wCode, UINT32 dwRqId);
 UINT32 LIBNXCL_EXPORTABLE NXCWaitForRCC(NXC_SESSION hSession, UINT32 dwRqId);
 
 /** Session management **/
index 274b7dc..5304b91 100644 (file)
 #endif
 
 /**
- * Temporary buffer structure for RecvCSCPMessage() function
+ * Temporary buffer structure for RecvNXCPMessage() function
  */
 typedef struct
 {
-   UINT32 dwBufSize;
-   UINT32 dwBufPos;
-   char szBuffer[CSCP_TEMP_BUF_SIZE];
-} CSCP_BUFFER;
+   UINT32 bufferSize;
+   UINT32 bufferPos;
+   char buffer[CSCP_TEMP_BUF_SIZE];
+} NXCP_BUFFER;
 
 
 #ifdef __cplusplus
@@ -49,38 +49,34 @@ struct MessageField;
 /**
  * Parsed NXCP message
  */
-class LIBNETXMS_EXPORTABLE CSCPMessage
+class LIBNETXMS_EXPORTABLE NXCPMessage
 {
 private:
-   WORD m_code;
-   WORD m_flags;
+   UINT16 m_code;
+   UINT16 m_flags;
    UINT32 m_id;
    MessageField *m_fields; // Message fields
    int m_version;          // Protocol version
    BYTE *m_data;           // binary data
    size_t m_dataSize;      // binary data size
 
-   void *set(UINT32 fieldId, BYTE type, const void *value, UINT32 size = 0);
+   void *set(UINT32 fieldId, BYTE type, const void *value, size_t size = 0);
    void *get(UINT32 fieldId, BYTE requiredType, BYTE *fieldType = NULL);
-   CSCP_DF *find(UINT32 fieldId);
+   NXCP_MESSAGE_FIELD *find(UINT32 fieldId);
 
 public:
-   CSCPMessage(int nVersion = NXCP_VERSION);
-   CSCPMessage(CSCPMessage *pMsg);
-   CSCPMessage(CSCP_MESSAGE *pMsg, int nVersion = NXCP_VERSION);
-   CSCPMessage(const char *xml);
-   ~CSCPMessage();
+   NXCPMessage(int version = NXCP_VERSION);
+   NXCPMessage(NXCPMessage *msg);
+   NXCPMessage(NXCP_MESSAGE *rawMag, int version = NXCP_VERSION);
+   ~NXCPMessage();
 
-   CSCP_MESSAGE *createMessage();
-       char *createXML();
-       void processXMLToken(void *state, const char **attrs);
-       void processXMLData(void *state);
+   NXCP_MESSAGE *createMessage();
 
-   WORD GetCode() { return m_code; }
-   void SetCode(WORD code) { m_code = code; }
+   UINT16 getCode() { return m_code; }
+   void setCode(UINT16 code) { m_code = code; }
 
-   UINT32 GetId() { return m_id; }
-   void SetId(UINT32 id) { m_id = id; }
+   UINT32 getId() { return m_id; }
+   void setId(UINT32 id) { m_id = id; }
 
    bool isEndOfFile() { return (m_flags & MF_END_OF_FILE) ? true : false; }
    bool isEndOfSequence() { return (m_flags & MF_END_OF_SEQUENCE) ? true : false; }
@@ -93,51 +89,50 @@ public:
    bool isFieldExist(UINT32 fieldId) { return find(fieldId) != NULL; }
    int getFieldType(UINT32 fieldId);
 
-   void SetVariable(UINT32 fieldId, INT16 wValue) { set(fieldId, CSCP_DT_INT16, &wValue); }
-   void SetVariable(UINT32 fieldId, UINT16 wValue) { set(fieldId, CSCP_DT_INT16, &wValue); }
-   void SetVariable(UINT32 fieldId, INT32 dwValue) { set(fieldId, CSCP_DT_INT32, &dwValue); }
-   void SetVariable(UINT32 fieldId, UINT32 dwValue) { set(fieldId, CSCP_DT_INT32, &dwValue); }
-   void SetVariable(UINT32 fieldId, INT64 qwValue) { set(fieldId, CSCP_DT_INT64, &qwValue); }
-   void SetVariable(UINT32 fieldId, UINT64 qwValue) { set(fieldId, CSCP_DT_INT64, &qwValue); }
-   void SetVariable(UINT32 fieldId, double dValue) { set(fieldId, CSCP_DT_FLOAT, &dValue); }
-   void SetVariable(UINT32 fieldId, const TCHAR *value) { if (value != NULL) set(fieldId, CSCP_DT_STRING, value); }
-   void SetVariable(UINT32 fieldId, const TCHAR *value, UINT32 maxLen) { if (value != NULL) set(fieldId, CSCP_DT_STRING, value, maxLen); }
-   void SetVariable(UINT32 fieldId, BYTE *pValue, UINT32 dwSize) { set(fieldId, CSCP_DT_BINARY, pValue, dwSize); }
+   void setField(UINT32 fieldId, INT16 value) { set(fieldId, NXCP_DT_INT16, &value); }
+   void setField(UINT32 fieldId, UINT16 value) { set(fieldId, NXCP_DT_INT16, &value); }
+   void setField(UINT32 fieldId, INT32 value) { set(fieldId, NXCP_DT_INT32, &value); }
+   void setField(UINT32 fieldId, UINT32 value) { set(fieldId, NXCP_DT_INT32, &value); }
+   void setField(UINT32 fieldId, INT64 value) { set(fieldId, NXCP_DT_INT64, &value); }
+   void setField(UINT32 fieldId, UINT64 value) { set(fieldId, NXCP_DT_INT64, &value); }
+   void setField(UINT32 fieldId, double value) { set(fieldId, NXCP_DT_FLOAT, &value); }
+   void setField(UINT32 fieldId, const TCHAR *value) { if (value != NULL) set(fieldId, NXCP_DT_STRING, value); }
+   void setField(UINT32 fieldId, const TCHAR *value, UINT32 maxLen) { if (value != NULL) set(fieldId, NXCP_DT_STRING, value, maxLen); }
+   void setField(UINT32 fieldId, BYTE *value, size_t size) { set(fieldId, NXCP_DT_BINARY, value, size); }
 #ifdef UNICODE
-   void SetVariableFromMBString(UINT32 fieldId, const char *pszValue);
+   void setFieldFromMBString(UINT32 fieldId, const char *value);
 #else
-   void SetVariableFromMBString(UINT32 fieldId, const char *pszValue) { set(fieldId, CSCP_DT_STRING, pszValue); }
+   void setFieldFromMBString(UINT32 fieldId, const char *value) { set(fieldId, NXCP_DT_STRING, value); }
 #endif
-   void setField(UINT32 fieldId, time_t value) { UINT64 t = (UINT64)value; set(fieldId, CSCP_DT_INT64, &t); }
-   void setFieldInt32Array(UINT32 fieldId, UINT32 dwNumElements, const UINT32 *pdwData);
-   void setFieldInt32Array(UINT32 fieldId, IntegerArray<UINT32> *data);
+   void setFieldFromTime(UINT32 fieldId, time_t value) { UINT64 t = (UINT64)value; set(fieldId, NXCP_DT_INT64, &t); }
+   void setFieldFromInt32Array(UINT32 fieldId, UINT32 dwNumElements, const UINT32 *pdwData);
+   void setFieldFromInt32Array(UINT32 fieldId, IntegerArray<UINT32> *data);
    bool setFieldFromFile(UINT32 fieldId, const TCHAR *pszFileName);
 
    INT16 getFieldAsInt16(UINT32 fieldId);
+   UINT16 getFieldAsUInt16(UINT32 fieldId);
    INT32 getFieldAsInt32(UINT32 fieldId);
+   UINT32 getFieldAsUInt32(UINT32 fieldId);
    INT64 getFieldAsInt64(UINT32 fieldId);
+   UINT64 getFieldAsUInt64(UINT32 fieldId);
    double getFieldAsDouble(UINT32 fieldId);
    bool getFieldAsBoolean(UINT32 fieldId);
    time_t getFieldAsTime(UINT32 fieldId);
    UINT32 getFieldAsInt32Array(UINT32 fieldId, UINT32 numElements, UINT32 *buffer);
    UINT32 getFieldAsInt32Array(UINT32 fieldId, IntegerArray<UINT32> *data);
    BYTE *getBinaryFieldPtr(UINT32 fieldId, size_t *size);
+   TCHAR *getFieldAsString(UINT32 fieldId, TCHAR *buffer = NULL, size_t bufferSize = 0);
+       char *getFieldAsMBString(UINT32 fieldId, char *buffer = NULL, size_t bufferSize = 0);
+       char *getFieldAsUtf8String(UINT32 fieldId, char *buffer = NULL, size_t bufferSize = 0);
+   UINT32 getFieldAsBinary(UINT32 fieldId, BYTE *buffer, size_t bufferSize);
 
-   UINT32 GetVariableLong(UINT32 fieldId);
-   UINT64 GetVariableInt64(UINT32 fieldId);
-   UINT16 GetVariableShort(UINT32 fieldId);
-   TCHAR *GetVariableStr(UINT32 fieldId, TCHAR *szBuffer = NULL, UINT32 dwBufSize = 0);
-       char *GetVariableStrA(UINT32 fieldId, char *pszBuffer = NULL, UINT32 dwBufSize = 0);
-       char *GetVariableStrUTF8(UINT32 fieldId, char *pszBuffer = NULL, UINT32 dwBufSize = 0);
-   UINT32 GetVariableBinary(UINT32 fieldId, BYTE *pBuffer, UINT32 dwBufSize);
-
-   void deleteAllVariables();
+   void deleteAllFields();
 
    void disableEncryption() { m_flags |= MF_DONT_ENCRYPT; }
    void setEndOfSequence() { m_flags |= MF_END_OF_SEQUENCE; }
    void setReverseOrderFlag() { m_flags |= MF_REVERSE_ORDER; }
 
-   static String dump(CSCP_MESSAGE *msg, int version);
+   static String dump(NXCP_MESSAGE *msg, int version);
 };
 
 /**
@@ -145,7 +140,7 @@ public:
  */
 typedef struct
 {
-   void *msg;         // Pointer to message, either to CSCPMessage object or raw message
+   void *msg;         // Pointer to message, either to NXCPMessage object or raw message
    UINT32 id;         // Message ID
    UINT32 ttl;        // Message time-to-live in milliseconds
    UINT16 code;       // Message code
@@ -205,15 +200,15 @@ public:
    MsgWaitQueue();
    ~MsgWaitQueue();
 
-   void put(CSCPMessage *pMsg);
-   void put(CSCP_MESSAGE *pMsg);
-   CSCPMessage *waitForMessage(WORD wCode, UINT32 dwId, UINT32 dwTimeOut)
+   void put(NXCPMessage *pMsg);
+   void put(NXCP_MESSAGE *pMsg);
+   NXCPMessage *waitForMessage(WORD wCode, UINT32 dwId, UINT32 dwTimeOut)
    {
-      return (CSCPMessage *)waitForMessageInternal(0, wCode, dwId, dwTimeOut);
+      return (NXCPMessage *)waitForMessageInternal(0, wCode, dwId, dwTimeOut);
    }
-   CSCP_MESSAGE *waitForRawMessage(WORD wCode, UINT32 dwId, UINT32 dwTimeOut)
+   NXCP_MESSAGE *waitForRawMessage(WORD wCode, UINT32 dwId, UINT32 dwTimeOut)
    {
-      return (CSCP_MESSAGE *)waitForMessageInternal(1, wCode, dwId, dwTimeOut);
+      return (NXCP_MESSAGE *)waitForMessageInternal(1, wCode, dwId, dwTimeOut);
    }
 
    void clear();
@@ -240,12 +235,12 @@ private:
    bool initCipher(int cipher);
 
 public:
-       static NXCPEncryptionContext *create(CSCPMessage *msg, RSA *privateKey);
+       static NXCPEncryptionContext *create(NXCPMessage *msg, RSA *privateKey);
        static NXCPEncryptionContext *create(UINT32 ciphers);
 
        virtual ~NXCPEncryptionContext();
 
-   NXCP_ENCRYPTED_MESSAGE *encryptMessage(CSCP_MESSAGE *msg);
+   NXCP_ENCRYPTED_MESSAGE *encryptMessage(NXCP_MESSAGE *msg);
    bool decryptMessage(NXCP_ENCRYPTED_MESSAGE *msg, BYTE *decryptionBuffer);
 
        int getCipher() { return m_cipher; }
@@ -281,7 +276,7 @@ private:
    size_t m_dataSize;
    size_t m_bytesToSkip;
 
-   CSCPMessage *getMessageFromBuffer();
+   NXCPMessage *getMessageFromBuffer();
 
 protected:
    virtual int readBytes(BYTE *buffer, size_t size, UINT32 timeout) = 0;
@@ -292,8 +287,10 @@ public:
 
    void setEncryptionContext(NXCPEncryptionContext *ctx) { m_encryptionContext = ctx; }
 
-   CSCPMessage *readMessage(UINT32 timeout, MessageReceiverResult *result);
-   CSCP_MESSAGE *getRawMessageBuffer() { return (CSCP_MESSAGE *)m_buffer; }
+   NXCPMessage *readMessage(UINT32 timeout, MessageReceiverResult *result);
+   NXCP_MESSAGE *getRawMessageBuffer() { return (NXCP_MESSAGE *)m_buffer; }
+
+   static const TCHAR *resultToText(MessageReceiverResult result);
 };
 
 /**
@@ -333,7 +330,7 @@ public:
 
 #else    /* __cplusplus */
 
-typedef void CSCPMessage;
+typedef void NXCPMessage;
 typedef void NXCPEncryptionContext;
 
 #endif
@@ -345,19 +342,19 @@ typedef void NXCPEncryptionContext;
 
 #ifdef __cplusplus
 
-int LIBNETXMS_EXPORTABLE RecvNXCPMessage(SOCKET hSocket, CSCP_MESSAGE *pMsg,
-                                         CSCP_BUFFER *pBuffer, UINT32 dwMaxMsgSize,
+int LIBNETXMS_EXPORTABLE RecvNXCPMessage(SOCKET hSocket, NXCP_MESSAGE *pMsg,
+                                         NXCP_BUFFER *pBuffer, UINT32 dwMaxMsgSize,
                                          NXCPEncryptionContext **ppCtx,
                                          BYTE *pDecryptionBuffer, UINT32 dwTimeout);
-int LIBNETXMS_EXPORTABLE RecvNXCPMessageEx(SOCKET hSocket, CSCP_MESSAGE **msgBuffer,
-                                           CSCP_BUFFER *nxcpBuffer, UINT32 *bufferSize,
+int LIBNETXMS_EXPORTABLE RecvNXCPMessageEx(SOCKET hSocket, NXCP_MESSAGE **msgBuffer,
+                                           NXCP_BUFFER *nxcpBuffer, UINT32 *bufferSize,
                                            NXCPEncryptionContext **ppCtx,
                                            BYTE **decryptionBuffer, UINT32 dwTimeout,
                                                                                                                 UINT32 maxMsgSize);
-CSCP_MESSAGE LIBNETXMS_EXPORTABLE *CreateRawNXCPMessage(WORD wCode, UINT32 dwId, WORD wFlags,
+NXCP_MESSAGE LIBNETXMS_EXPORTABLE *CreateRawNXCPMessage(WORD wCode, UINT32 dwId, WORD flags,
                                                         UINT32 dwDataSize, void *pData,
-                                                        CSCP_MESSAGE *pBuffer);
-TCHAR LIBNETXMS_EXPORTABLE *NXCPMessageCodeName(WORD wCode, TCHAR *pszBuffer);
+                                                        NXCP_MESSAGE *pBuffer);
+TCHAR LIBNETXMS_EXPORTABLE *NXCPMessageCodeName(WORD wCode, TCHAR *buffer);
 BOOL LIBNETXMS_EXPORTABLE SendFileOverNXCP(SOCKET hSocket, UINT32 dwId, const TCHAR *pszFile,
                                            NXCPEncryptionContext *pCtx, long offset,
                                                                                                                 void (* progressCallback)(INT64, void *), void *cbArg,
@@ -366,20 +363,20 @@ BOOL LIBNETXMS_EXPORTABLE NXCPGetPeerProtocolVersion(SOCKET hSocket, int *pnVers
 
 BOOL LIBNETXMS_EXPORTABLE InitCryptoLib(UINT32 dwEnabledCiphers, void (*debugCallback)(int, const TCHAR *, va_list args));
 UINT32 LIBNETXMS_EXPORTABLE CSCPGetSupportedCiphers();
-NXCP_ENCRYPTED_MESSAGE LIBNETXMS_EXPORTABLE *CSCPEncryptMessage(NXCPEncryptionContext *pCtx, CSCP_MESSAGE *pMsg);
-BOOL LIBNETXMS_EXPORTABLE CSCPDecryptMessage(NXCPEncryptionContext *pCtx,
+NXCP_ENCRYPTED_MESSAGE LIBNETXMS_EXPORTABLE *NXCPEncryptMessage(NXCPEncryptionContext *pCtx, NXCP_MESSAGE *pMsg);
+BOOL LIBNETXMS_EXPORTABLE NXCPDecryptMessage(NXCPEncryptionContext *pCtx,
                                              NXCP_ENCRYPTED_MESSAGE *pMsg,
                                              BYTE *pDecryptionBuffer);
-UINT32 LIBNETXMS_EXPORTABLE SetupEncryptionContext(CSCPMessage *pMsg,
+UINT32 LIBNETXMS_EXPORTABLE SetupEncryptionContext(NXCPMessage *pMsg,
                                                   NXCPEncryptionContext **ppCtx,
-                                                  CSCPMessage **ppResponse,
+                                                  NXCPMessage **ppResponse,
                                                   RSA *pPrivateKey, int nNXCPVersion);
-void LIBNETXMS_EXPORTABLE PrepareKeyRequestMsg(CSCPMessage *pMsg, RSA *pServerKey, bool useX509Format);
+void LIBNETXMS_EXPORTABLE PrepareKeyRequestMsg(NXCPMessage *pMsg, RSA *pServerKey, bool useX509Format);
 RSA LIBNETXMS_EXPORTABLE *LoadRSAKeys(const TCHAR *pszKeyFile);
 
 #ifdef _WIN32
 BOOL LIBNETXMS_EXPORTABLE SignMessageWithCAPI(BYTE *pMsg, UINT32 dwMsgLen, const CERT_CONTEXT *pCert,
-                                                                                                         BYTE *pBuffer, UINT32 dwBufSize, UINT32 *pdwSigLen);
+                                                                                                         BYTE *pBuffer, size_t bufferSize, UINT32 *pdwSigLen);
 #endif
 
 #endif
index c11cdb8..e7dcd6d 100644 (file)
@@ -526,7 +526,7 @@ public:
    NXSL_Program *findScript(const TCHAR *name);
    NXSL_VM *createVM(const TCHAR *name, NXSL_Environment *env);
 
-   void fillMessage(CSCPMessage *pMsg);
+   void fillMessage(NXCPMessage *pMsg);
 };
 
 /**
index d163f8c..39933fe 100644 (file)
@@ -174,14 +174,14 @@ static THREAD_RESULT THREAD_CALL ActionExecutionThread(void *arg)
 {
    ActionExecutorData *data = (ActionExecutorData *)arg;
    
-   CSCPMessage msg;
-   msg.SetCode(CMD_REQUEST_COMPLETED);
-   msg.SetId(data->m_requestId);
-   msg.SetVariable(VID_RCC, ERR_SUCCESS);
+   NXCPMessage msg;
+   msg.setCode(CMD_REQUEST_COMPLETED);
+   msg.setId(data->m_requestId);
+   msg.setField(VID_RCC, ERR_SUCCESS);
    data->m_session->sendMessage(&msg);
 
-   msg.SetCode(CMD_COMMAND_OUTPUT);
-   msg.deleteAllVariables();
+   msg.setCode(CMD_COMMAND_OUTPUT);
+   msg.deleteAllFields();
 
    FILE *pipe = _tpopen(data->m_cmdLine, _T("r"));
    if (pipe != NULL)
@@ -194,9 +194,9 @@ static THREAD_RESULT THREAD_CALL ActionExecutionThread(void *arg)
          if (ret == NULL)
             break;
          
-         msg.SetVariable(VID_MESSAGE, line);
+         msg.setField(VID_MESSAGE, line);
          data->m_session->sendMessage(&msg);
-         msg.deleteAllVariables();
+         msg.deleteAllFields();
       }
       pclose(pipe);
    }
@@ -206,7 +206,7 @@ static THREAD_RESULT THREAD_CALL ActionExecutionThread(void *arg)
 
       TCHAR buffer[1024];
       _sntprintf(buffer, 1024, _T("Failed to execute command %s"), data->m_cmdLine);
-      msg.SetVariable(VID_MESSAGE, buffer);
+      msg.setField(VID_MESSAGE, buffer);
    }
 
    msg.setEndOfSequence();
index aaf15e6..dbb4edb 100644 (file)
@@ -37,7 +37,7 @@ MUTEX g_hSessionListAccess;
  * Static data
  */
 static MUTEX m_mutexWatchdogActive = INVALID_MUTEX_HANDLE;
-static VolatileCounter s_messageId = (VolatileCounter)time(NULL);
+static VolatileCounter s_messageId = (INT32)time(NULL);
 
 /**
  * Generate new message ID
index d377c26..c063f3a 100644 (file)
@@ -59,9 +59,9 @@ BOOL DownloadConfig(TCHAR *pszServer)
    struct sockaddr_in sa;
    BOOL bRet = FALSE;
    TCHAR szBuffer[MAX_RESULT_LENGTH], *pszConfig;
-   CSCPMessage msg, *pResponse;
-   CSCP_MESSAGE *pRawMsg;
-   CSCP_BUFFER *pBuffer;
+   NXCPMessage msg, *pResponse;
+   NXCP_MESSAGE *pRawMsg;
+   NXCP_BUFFER *pBuffer;
    NXCPEncryptionContext *pDummyCtx = NULL;
    int nLen;
 
@@ -93,35 +93,35 @@ BOOL DownloadConfig(TCHAR *pszServer)
       if (connect(hSocket, (struct sockaddr *)&sa, sizeof(sa)) != -1)
       {
          // Prepare request
-         msg.SetCode(CMD_GET_MY_CONFIG);
-         msg.SetId(1);
+         msg.setCode(CMD_GET_MY_CONFIG);
+         msg.setId(1);
          if (H_PlatformName(NULL, NULL, szBuffer) != SYSINFO_RC_SUCCESS)
             _tcscpy(szBuffer, _T("error"));
-         msg.SetVariable(VID_PLATFORM_NAME, szBuffer);
-         msg.SetVariable(VID_VERSION_MAJOR, (WORD)NETXMS_VERSION_MAJOR);
-         msg.SetVariable(VID_VERSION_MINOR, (WORD)NETXMS_VERSION_MINOR);
-         msg.SetVariable(VID_VERSION_RELEASE, (WORD)NETXMS_VERSION_BUILD);
-         msg.SetVariable(VID_VERSION, NETXMS_VERSION_STRING);
+         msg.setField(VID_PLATFORM_NAME, szBuffer);
+         msg.setField(VID_VERSION_MAJOR, (WORD)NETXMS_VERSION_MAJOR);
+         msg.setField(VID_VERSION_MINOR, (WORD)NETXMS_VERSION_MINOR);
+         msg.setField(VID_VERSION_RELEASE, (WORD)NETXMS_VERSION_BUILD);
+         msg.setField(VID_VERSION, NETXMS_VERSION_STRING);
 
          // Send request
          pRawMsg = msg.createMessage();
-         nLen = ntohl(pRawMsg->dwSize);
+         nLen = ntohl(pRawMsg->size);
          if (SendEx(hSocket, pRawMsg, nLen, 0, NULL) == nLen)
          {
-            pRawMsg = (CSCP_MESSAGE *)realloc(pRawMsg, MAX_MSG_SIZE);
-            pBuffer = (CSCP_BUFFER *)malloc(sizeof(CSCP_BUFFER));
+            pRawMsg = (NXCP_MESSAGE *)realloc(pRawMsg, MAX_MSG_SIZE);
+            pBuffer = (NXCP_BUFFER *)malloc(sizeof(NXCP_BUFFER));
             RecvNXCPMessage(0, NULL, pBuffer, 0, NULL, NULL, 0);
 
             nLen = RecvNXCPMessage(hSocket, pRawMsg, pBuffer, MAX_MSG_SIZE,
                                    &pDummyCtx, NULL, 30000);
             if (nLen >= 16)
             {
-               pResponse = new CSCPMessage(pRawMsg);
-               if ((pResponse->GetCode() == CMD_REQUEST_COMPLETED) &&
-                   (pResponse->GetId() == 1) &&
-                   (pResponse->GetVariableLong(VID_RCC) == 0))
+               pResponse = new NXCPMessage(pRawMsg);
+               if ((pResponse->getCode() == CMD_REQUEST_COMPLETED) &&
+                   (pResponse->getId() == 1) &&
+                   (pResponse->getFieldAsUInt32(VID_RCC) == 0))
                {
-                  pszConfig = pResponse->GetVariableStr(VID_CONFIG_FILE);
+                  pszConfig = pResponse->getFieldAsString(VID_CONFIG_FILE);
                   if (pszConfig != NULL)
                   {
                      bRet = SaveConfig(pszConfig);
index f8f6051..1fc252c 100644 (file)
@@ -34,11 +34,11 @@ static void ProcessControlRequest(HPIPE hPipe)
        while(true)
        {
       MessageReceiverResult result;
-               CSCPMessage *msg = receiver.readMessage(5000, &result);
+               NXCPMessage *msg = receiver.readMessage(5000, &result);
                if (msg == NULL)
                        break;
-               AgentWriteDebugLog(6, _T("ProcessControlRequest: received message %s"), NXCPMessageCodeName(msg->GetCode(), buffer));
-               if (msg->GetCode() == CMD_SHUTDOWN)
+               AgentWriteDebugLog(6, _T("ProcessControlRequest: received message %s"), NXCPMessageCodeName(msg->getCode(), buffer));
+               if (msg->getCode() == CMD_SHUTDOWN)
                {
          ShutdownExtSubagents();
                }
@@ -235,7 +235,7 @@ void StartControlConnector()
 /**
  * Send control message
  */
-bool SendControlMessage(CSCPMessage *msg)
+bool SendControlMessage(NXCPMessage *msg)
 {
 #ifdef _WIN32
    HANDLE hPipe = NULL;
@@ -274,16 +274,16 @@ reconnect:
 #endif
 
    bool success = false;
-       CSCP_MESSAGE *rawMsg = msg->createMessage();
+       NXCP_MESSAGE *rawMsg = msg->createMessage();
 #ifdef _WIN32
        DWORD bytes;
-       if (!WriteFile(hPipe, rawMsg, ntohl(rawMsg->dwSize), &bytes, NULL))
+       if (!WriteFile(hPipe, rawMsg, ntohl(rawMsg->size), &bytes, NULL))
                goto cleanup;
-       if (bytes != ntohl(rawMsg->dwSize))
+       if (bytes != ntohl(rawMsg->size))
                goto cleanup;
 #else
-       int bytes = SendEx(hPipe, rawMsg, ntohl(rawMsg->dwSize), 0, NULL); 
-       if (bytes != (int)ntohl(rawMsg->dwSize))
+       int bytes = SendEx(hPipe, rawMsg, ntohl(rawMsg->size), 0, NULL); 
+       if (bytes != (int)ntohl(rawMsg->size))
                goto cleanup;
 #endif
    success = true;
index e9005d1..da10e1b 100644 (file)
@@ -46,7 +46,7 @@ public:
        int getPollInterval() { return m_pollInterval; }
        void poll();
        LONG getValue(const TCHAR *name, TCHAR *buffer);
-       void listParameters(CSCPMessage *msg, UINT32 *baseId, UINT32 *count);
+       void listParameters(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
        void listParameters(StringList *list);
 };
 
@@ -149,7 +149,7 @@ void ParamProvider::poll()
  */
 struct ParameterListCallbackData
 {
-   CSCPMessage *msg;
+   NXCPMessage *msg;
    UINT32 id;
    UINT32 count;
 };
@@ -159,9 +159,9 @@ struct ParameterListCallbackData
  */
 static bool ParameterListCallback(const TCHAR *key, const void *value, void *data)
 {
-       ((ParameterListCallbackData *)data)->msg->SetVariable(((ParameterListCallbackData *)data)->id++, key);
-       ((ParameterListCallbackData *)data)->msg->SetVariable(((ParameterListCallbackData *)data)->id++, _T(""));
-       ((ParameterListCallbackData *)data)->msg->SetVariable(((ParameterListCallbackData *)data)->id++, (WORD)DCI_DT_STRING);
+       ((ParameterListCallbackData *)data)->msg->setField(((ParameterListCallbackData *)data)->id++, key);
+       ((ParameterListCallbackData *)data)->msg->setField(((ParameterListCallbackData *)data)->id++, _T(""));
+       ((ParameterListCallbackData *)data)->msg->setField(((ParameterListCallbackData *)data)->id++, (WORD)DCI_DT_STRING);
        ((ParameterListCallbackData *)data)->count++;
    return true;
 }
@@ -169,7 +169,7 @@ static bool ParameterListCallback(const TCHAR *key, const void *value, void *dat
 /**
  * List available parameters
  */
-void ParamProvider::listParameters(CSCPMessage *msg, UINT32 *baseId, UINT32 *count)
+void ParamProvider::listParameters(NXCPMessage *msg, UINT32 *baseId, UINT32 *count)
 {
    ParameterListCallbackData data;
    data.msg = msg;
@@ -290,7 +290,7 @@ LONG GetParameterValueFromExtProvider(const TCHAR *name, TCHAR *buffer)
 /**
  * Add parameters from external providers to NXCP message
  */
-void ListParametersFromExtProviders(CSCPMessage *msg, UINT32 *baseId, UINT32 *count)
+void ListParametersFromExtProviders(NXCPMessage *msg, UINT32 *baseId, UINT32 *count)
 {
        for(int i = 0; i < s_providers.size(); i++)
        {
index a5e68e3..0b4bd85 100644 (file)
@@ -54,12 +54,12 @@ ExternalSubagent::~ExternalSubagent()
 /*
  * Send message to external subagent
  */
-bool ExternalSubagent::sendMessage(CSCPMessage *msg)
+bool ExternalSubagent::sendMessage(NXCPMessage *msg)
 {
        TCHAR buffer[256];
-       AgentWriteDebugLog(6, _T("ExternalSubagent::sendMessage(%s): sending message %s"), m_name, NXCPMessageCodeName(msg->GetCode(), buffer));
+       AgentWriteDebugLog(6, _T("ExternalSubagent::sendMessage(%s): sending message %s"), m_name, NXCPMessageCodeName(msg->getCode(), buffer));
 
-       CSCP_MESSAGE *rawMsg = msg->createMessage();
+       NXCP_MESSAGE *rawMsg = msg->createMessage();
        MutexLock(m_mutexPipeWrite);
    bool success = SendMessageToPipe(m_pipe, rawMsg);
        MutexUnlock(m_mutexPipeWrite);
@@ -70,7 +70,7 @@ bool ExternalSubagent::sendMessage(CSCPMessage *msg)
 /**
  * Wait for specific message to arrive
  */
-CSCPMessage *ExternalSubagent::waitForMessage(WORD code, UINT32 id)
+NXCPMessage *ExternalSubagent::waitForMessage(WORD code, UINT32 id)
 {
        return m_msgQueue->waitForMessage(code, id, 5000);      // 5 sec timeout
 }
@@ -90,14 +90,14 @@ void ExternalSubagent::connect(HPIPE hPipe)
        while(true)
        {
       MessageReceiverResult result;
-      CSCPMessage *msg = receiver.readMessage(INFINITE, &result);
+      NXCPMessage *msg = receiver.readMessage(INFINITE, &result);
                if (msg == NULL)
       {
-               AgentWriteDebugLog(6, _T("ExternalSubagent(%s): receiver failure (%d)"), m_name, result);
+         AgentWriteDebugLog(6, _T("ExternalSubagent(%s): receiver failure (%s)"), m_name, AbstractMessageReceiver::resultToText(result));
                        break;
       }
-               AgentWriteDebugLog(6, _T("ExternalSubagent(%s): received message %s"), m_name, NXCPMessageCodeName(msg->GetCode(), buffer));
-      switch(msg->GetCode())
+               AgentWriteDebugLog(6, _T("ExternalSubagent(%s): received message %s"), m_name, NXCPMessageCodeName(msg->getCode(), buffer));
+      switch(msg->getCode())
       {
          case CMD_PUSH_DCI_DATA:
             MutexLock(g_hSessionListAccess);
@@ -130,9 +130,9 @@ void ExternalSubagent::connect(HPIPE hPipe)
  */
 void ExternalSubagent::shutdown()
 {
-       CSCPMessage msg;
-       msg.SetCode(CMD_SHUTDOWN);
-       msg.SetId(m_requestId++);
+       NXCPMessage msg;
+       msg.setCode(CMD_SHUTDOWN);
+       msg.setId(m_requestId++);
        sendMessage(&msg);
 }
 
@@ -141,26 +141,26 @@ void ExternalSubagent::shutdown()
  */
 NETXMS_SUBAGENT_PARAM *ExternalSubagent::getSupportedParameters(UINT32 *count)
 {
-       CSCPMessage msg;
+       NXCPMessage msg;
        NETXMS_SUBAGENT_PARAM *result = NULL;
 
-       msg.SetCode(CMD_GET_PARAMETER_LIST);
-       msg.SetId(m_requestId++);
+       msg.setCode(CMD_GET_PARAMETER_LIST);
+       msg.setId(m_requestId++);
        if (sendMessage(&msg))
        {
-               CSCPMessage *response = waitForMessage(CMD_REQUEST_COMPLETED, msg.GetId());
+               NXCPMessage *response = waitForMessage(CMD_REQUEST_COMPLETED, msg.getId());
                if (response != NULL)
                {
-                       if (response->GetVariableLong(VID_RCC) == ERR_SUCCESS)
+                       if (response->getFieldAsUInt32(VID_RCC) == ERR_SUCCESS)
                        {
-                               *count = response->GetVariableLong(VID_NUM_PARAMETERS);
+                               *count = response->getFieldAsUInt32(VID_NUM_PARAMETERS);
                                result = (NETXMS_SUBAGENT_PARAM *)malloc(*count * sizeof(NETXMS_SUBAGENT_PARAM));
                                UINT32 varId = VID_PARAM_LIST_BASE;
                                for(UINT32 i = 0; i < *count; i++)
                                {
-                                       response->GetVariableStr(varId++, result[i].name, MAX_PARAM_NAME);
-                                       response->GetVariableStr(varId++, result[i].description, MAX_DB_STRING);
-                                       result[i].dataType = (int)response->GetVariableShort(varId++);
+                                       response->getFieldAsString(varId++, result[i].name, MAX_PARAM_NAME);
+                                       response->getFieldAsString(varId++, result[i].description, MAX_DB_STRING);
+                                       result[i].dataType = (int)response->getFieldAsUInt16(varId++);
                                }
                        }
                        delete response;
@@ -174,24 +174,24 @@ NETXMS_SUBAGENT_PARAM *ExternalSubagent::getSupportedParameters(UINT32 *count)
  */
 NETXMS_SUBAGENT_LIST *ExternalSubagent::getSupportedLists(UINT32 *count)
 {
-       CSCPMessage msg;
+       NXCPMessage msg;
        NETXMS_SUBAGENT_LIST *result = NULL;
 
-       msg.SetCode(CMD_GET_ENUM_LIST);
-       msg.SetId(m_requestId++);
+       msg.setCode(CMD_GET_ENUM_LIST);
+       msg.setId(m_requestId++);
        if (sendMessage(&msg))
        {
-               CSCPMessage *response = waitForMessage(CMD_REQUEST_COMPLETED, msg.GetId());
+               NXCPMessage *response = waitForMessage(CMD_REQUEST_COMPLETED, msg.getId());
                if (response != NULL)
                {
-                       if (response->GetVariableLong(VID_RCC) == ERR_SUCCESS)
+                       if (response->getFieldAsUInt32(VID_RCC) == ERR_SUCCESS)
                        {
-                               *count = response->GetVariableLong(VID_NUM_ENUMS);
+                               *count = response->getFieldAsUInt32(VID_NUM_ENUMS);
                                result = (NETXMS_SUBAGENT_LIST *)malloc(*count * sizeof(NETXMS_SUBAGENT_LIST));
                                UINT32 varId = VID_ENUM_LIST_BASE;
                                for(UINT32 i = 0; i < *count; i++)
                                {
-                                       response->GetVariableStr(varId++, result[i].name, MAX_PARAM_NAME);
+                                       response->getFieldAsString(varId++, result[i].name, MAX_PARAM_NAME);
                                }
                        }
                        delete response;
@@ -205,26 +205,26 @@ NETXMS_SUBAGENT_LIST *ExternalSubagent::getSupportedLists(UINT32 *count)
  */
 NETXMS_SUBAGENT_TABLE *ExternalSubagent::getSupportedTables(UINT32 *count)
 {
-       CSCPMessage msg;
+       NXCPMessage msg;
        NETXMS_SUBAGENT_TABLE *result = NULL;
 
-       msg.SetCode(CMD_GET_TABLE_LIST);
-       msg.SetId(m_requestId++);
+       msg.setCode(CMD_GET_TABLE_LIST);
+       msg.setId(m_requestId++);
        if (sendMessage(&msg))
        {
-               CSCPMessage *response = waitForMessage(CMD_REQUEST_COMPLETED, msg.GetId());
+               NXCPMessage *response = waitForMessage(CMD_REQUEST_COMPLETED, msg.getId());
                if (response != NULL)
                {
-                       if (response->GetVariableLong(VID_RCC) == ERR_SUCCESS)
+                       if (response->getFieldAsUInt32(VID_RCC) == ERR_SUCCESS)
                        {
-                               *count = response->GetVariableLong(VID_NUM_TABLES);
+                               *count = response->getFieldAsUInt32(VID_NUM_TABLES);
                                result = (NETXMS_SUBAGENT_TABLE *)malloc(*count * sizeof(NETXMS_SUBAGENT_TABLE));
                                UINT32 varId = VID_TABLE_LIST_BASE;
                                for(UINT32 i = 0; i < *count; i++)
                                {
-                                       response->GetVariableStr(varId++, result[i].name, MAX_PARAM_NAME);
-                                       response->GetVariableStr(varId++, result[i].instanceColumns, MAX_COLUMN_NAME * MAX_INSTANCE_COLUMNS);
-                                       response->GetVariableStr(varId++, result[i].description, MAX_DB_STRING);
+                                       response->getFieldAsString(varId++, result[i].name, MAX_PARAM_NAME);
+                                       response->getFieldAsString(varId++, result[i].instanceColumns, MAX_COLUMN_NAME * MAX_INSTANCE_COLUMNS);
+                                       response->getFieldAsString(varId++, result[i].description, MAX_DB_STRING);
                                }
                        }
                        delete response;
@@ -236,7 +236,7 @@ NETXMS_SUBAGENT_TABLE *ExternalSubagent::getSupportedTables(UINT32 *count)
 /**
  * List supported parameters
  */
-void ExternalSubagent::listParameters(CSCPMessage *msg, UINT32 *baseId, UINT32 *count)
+void ExternalSubagent::listParameters(NXCPMessage *msg, UINT32 *baseId, UINT32 *count)
 {
        UINT32 paramCount = 0;
        NETXMS_SUBAGENT_PARAM *list = getSupportedParameters(&paramCount);
@@ -246,9 +246,9 @@ void ExternalSubagent::listParameters(CSCPMessage *msg, UINT32 *baseId, UINT32 *
 
                for(UINT32 i = 0; i < paramCount; i++)
                {
-                       msg->SetVariable(id++, list[i].name);
-                       msg->SetVariable(id++, list[i].description);
-                       msg->SetVariable(id++, (WORD)list[i].dataType);
+                       msg->setField(id++, list[i].name);
+                       msg->setField(id++, list[i].description);
+                       msg->setField(id++, (WORD)list[i].dataType);
                }
                *baseId = id;
                *count += paramCount;
@@ -274,7 +274,7 @@ void ExternalSubagent::listParameters(StringList *list)
 /**
  * List supported lists
  */
-void ExternalSubagent::listLists(CSCPMessage *msg, UINT32 *baseId, UINT32 *count)
+void ExternalSubagent::listLists(NXCPMessage *msg, UINT32 *baseId, UINT32 *count)
 {
        UINT32 paramCount = 0;
        NETXMS_SUBAGENT_LIST *list = getSupportedLists(&paramCount);
@@ -284,7 +284,7 @@ void ExternalSubagent::listLists(CSCPMessage *msg, UINT32 *baseId, UINT32 *count
 
                for(UINT32 i = 0; i < paramCount; i++)
                {
-                       msg->SetVariable(id++, list[i].name);
+                       msg->setField(id++, list[i].name);
                }
                *baseId = id;
                *count += paramCount;
@@ -310,7 +310,7 @@ void ExternalSubagent::listLists(StringList *list)
 /**
  * List supported tables
  */
-void ExternalSubagent::listTables(CSCPMessage *msg, UINT32 *baseId, UINT32 *count)
+void ExternalSubagent::listTables(NXCPMessage *msg, UINT32 *baseId, UINT32 *count)
 {
        UINT32 paramCount = 0;
        NETXMS_SUBAGENT_TABLE *list = getSupportedTables(&paramCount);
@@ -320,9 +320,9 @@ void ExternalSubagent::listTables(CSCPMessage *msg, UINT32 *baseId, UINT32 *coun
 
                for(UINT32 i = 0; i < paramCount; i++)
                {
-                       msg->SetVariable(id++, list[i].name);
-                       msg->SetVariable(id++, list[i].instanceColumns);
-                       msg->SetVariable(id++, list[i].description);
+                       msg->setField(id++, list[i].name);
+                       msg->setField(id++, list[i].instanceColumns);
+                       msg->setField(id++, list[i].description);
                }
                *baseId = id;
                *count += paramCount;
@@ -350,20 +350,20 @@ void ExternalSubagent::listTables(StringList *list)
  */
 UINT32 ExternalSubagent::getParameter(const TCHAR *name, TCHAR *buffer)
 {
-       CSCPMessage msg;
+       NXCPMessage msg;
        UINT32 rcc;
 
-       msg.SetCode(CMD_GET_PARAMETER);
-       msg.SetId(m_requestId++);
-       msg.SetVariable(VID_PARAMETER, name);
+       msg.setCode(CMD_GET_PARAMETER);
+       msg.setId(m_requestId++);
+       msg.setField(VID_PARAMETER, name);
        if (sendMessage(&msg))
        {
-               CSCPMessage *response = waitForMessage(CMD_REQUEST_COMPLETED, msg.GetId());
+               NXCPMessage *response = waitForMessage(CMD_REQUEST_COMPLETED, msg.getId());
                if (response != NULL)
                {
-                       rcc = response->GetVariableLong(VID_RCC);
+                       rcc = response->getFieldAsUInt32(VID_RCC);
                        if (rcc == ERR_SUCCESS)
-                               response->GetVariableStr(VID_VALUE, buffer, MAX_RESULT_LENGTH);
+                               response->getFieldAsString(VID_VALUE, buffer, MAX_RESULT_LENGTH);
                        delete response;
                }
                else
@@ -383,18 +383,18 @@ UINT32 ExternalSubagent::getParameter(const TCHAR *name, TCHAR *buffer)
  */
 UINT32 ExternalSubagent::getTable(const TCHAR *name, Table *value)
 {
-       CSCPMessage msg;
+       NXCPMessage msg;
        UINT32 rcc;
 
-       msg.SetCode(CMD_GET_TABLE);
-       msg.SetId(m_requestId++);
-       msg.SetVariable(VID_PARAMETER, name);
+       msg.setCode(CMD_GET_TABLE);
+       msg.setId(m_requestId++);
+       msg.setField(VID_PARAMETER, name);
        if (sendMessage(&msg))
        {
-               CSCPMessage *response = waitForMessage(CMD_REQUEST_COMPLETED, msg.GetId());
+               NXCPMessage *response = waitForMessage(CMD_REQUEST_COMPLETED, msg.getId());
                if (response != NULL)
                {
-                       rcc = response->GetVariableLong(VID_RCC);
+                       rcc = response->getFieldAsUInt32(VID_RCC);
                        if (rcc == ERR_SUCCESS)
                                value->updateFromMessage(response);
                        delete response;
@@ -416,23 +416,23 @@ UINT32 ExternalSubagent::getTable(const TCHAR *name, Table *value)
  */
 UINT32 ExternalSubagent::getList(const TCHAR *name, StringList *value)
 {
-       CSCPMessage msg;
+       NXCPMessage msg;
        UINT32 rcc;
 
-       msg.SetCode(CMD_GET_LIST);
-       msg.SetId(m_requestId++);
-       msg.SetVariable(VID_PARAMETER, name);
+       msg.setCode(CMD_GET_LIST);
+       msg.setId(m_requestId++);
+       msg.setField(VID_PARAMETER, name);
        if (sendMessage(&msg))
        {
-               CSCPMessage *response = waitForMessage(CMD_REQUEST_COMPLETED, msg.GetId());
+               NXCPMessage *response = waitForMessage(CMD_REQUEST_COMPLETED, msg.getId());
                if (response != NULL)
                {
-                       rcc = response->GetVariableLong(VID_RCC);
+                       rcc = response->getFieldAsUInt32(VID_RCC);
                        if (rcc == ERR_SUCCESS)
                        {
-            UINT32 count = response->GetVariableLong(VID_NUM_STRINGS);
+            UINT32 count = response->getFieldAsUInt32(VID_NUM_STRINGS);
             for(UINT32 i = 0; i < count; i++)
-                                       value->addPreallocated(response->GetVariableStr(VID_ENUM_VALUE_BASE + i));
+                                       value->addPreallocated(response->getFieldAsString(VID_ENUM_VALUE_BASE + i));
                        }
                        delete response;
                }
@@ -635,7 +635,7 @@ cleanup:
 /*
  * Send message to external subagent
  */
-bool SendMessageToPipe(HPIPE hPipe, CSCP_MESSAGE *msg)
+bool SendMessageToPipe(HPIPE hPipe, NXCP_MESSAGE *msg)
 {
        bool success = false;
 
@@ -644,16 +644,16 @@ bool SendMessageToPipe(HPIPE hPipe, CSCP_MESSAGE *msg)
       return false;
 
        DWORD bytes = 0;
-   if (WriteFile(hPipe, msg, ntohl(msg->dwSize), &bytes, NULL))
+   if (WriteFile(hPipe, msg, ntohl(msg->size), &bytes, NULL))
        {
-               success = (bytes == ntohl(msg->dwSize));
+               success = (bytes == ntohl(msg->size));
        }
 #else
    if (hPipe == -1)
       return false;
 
-       int bytes = SendEx(hPipe, msg, ntohl(msg->dwSize), 0, NULL); 
-       success = (bytes == ntohl(msg->dwSize));
+       int bytes = SendEx(hPipe, msg, ntohl(msg->size), 0, NULL); 
+       success = (bytes == ntohl(msg->size));
 #endif
        return success;
 }
@@ -687,7 +687,7 @@ bool AddExternalSubagent(const TCHAR *config)
 /**
  * Add parameters from external providers to NXCP message
  */
-void ListParametersFromExtSubagents(CSCPMessage *msg, UINT32 *baseId, UINT32 *count)
+void ListParametersFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count)
 {
        for(int i = 0; i < s_subagents.size(); i++)
        {
@@ -715,7 +715,7 @@ void ListParametersFromExtSubagents(StringList *list)
 /**
  * Add lists from external providers to NXCP message
  */
-void ListListsFromExtSubagents(CSCPMessage *msg, UINT32 *baseId, UINT32 *count)
+void ListListsFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count)
 {
        for(int i = 0; i < s_subagents.size(); i++)
        {
@@ -743,7 +743,7 @@ void ListListsFromExtSubagents(StringList *list)
 /**
  * Add tables from external providers to NXCP message
  */
-void ListTablesFromExtSubagents(CSCPMessage *msg, UINT32 *baseId, UINT32 *count)
+void ListTablesFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count)
 {
        for(int i = 0; i < s_subagents.size(); i++)
        {
index b1d24a0..7faf5b9 100644 (file)
@@ -684,7 +684,7 @@ UINT32 GetTableValue(UINT32 dwSessionId, TCHAR *pszParam, Table *pValue)
 /**
  * Put complete list of supported parameters into NXCP message
  */
-void GetParameterList(CSCPMessage *pMsg)
+void GetParameterList(NXCPMessage *pMsg)
 {
    int i;
    UINT32 dwId, count;
@@ -694,40 +694,40 @@ void GetParameterList(CSCPMessage *pMsg)
    {
                if (m_pParamList[i].dataType != DCI_DT_DEPRECATED)
                {
-                       pMsg->SetVariable(dwId++, m_pParamList[i].name);
-                       pMsg->SetVariable(dwId++, m_pParamList[i].description);
-                       pMsg->SetVariable(dwId++, (WORD)m_pParamList[i].dataType);
+                       pMsg->setField(dwId++, m_pParamList[i].name);
+                       pMsg->setField(dwId++, m_pParamList[i].description);
+                       pMsg->setField(dwId++, (WORD)m_pParamList[i].dataType);
                        count++;
                }
    }
        ListParametersFromExtProviders(pMsg, &dwId, &count);
        ListParametersFromExtSubagents(pMsg, &dwId, &count);
-   pMsg->SetVariable(VID_NUM_PARAMETERS, count);
+   pMsg->setField(VID_NUM_PARAMETERS, count);
 
        // Push parameters
-   pMsg->SetVariable(VID_NUM_PUSH_PARAMETERS, (UINT32)m_iNumPushParams);
+   pMsg->setField(VID_NUM_PUSH_PARAMETERS, (UINT32)m_iNumPushParams);
    for(i = 0, dwId = VID_PUSHPARAM_LIST_BASE; i < m_iNumPushParams; i++)
    {
-      pMsg->SetVariable(dwId++, m_pPushParamList[i].name);
-      pMsg->SetVariable(dwId++, m_pPushParamList[i].description);
-      pMsg->SetVariable(dwId++, (WORD)m_pPushParamList[i].dataType);
+      pMsg->setField(dwId++, m_pPushParamList[i].name);
+      pMsg->setField(dwId++, m_pPushParamList[i].description);
+      pMsg->setField(dwId++, (WORD)m_pPushParamList[i].dataType);
    }
 
        // Lists
-   pMsg->SetVariable(VID_NUM_ENUMS, (UINT32)m_iNumEnums);
+   pMsg->setField(VID_NUM_ENUMS, (UINT32)m_iNumEnums);
    for(i = 0, dwId = VID_ENUM_LIST_BASE; i < m_iNumEnums; i++)
    {
-      pMsg->SetVariable(dwId++, m_pEnumList[i].name);
+      pMsg->setField(dwId++, m_pEnumList[i].name);
    }
        ListListsFromExtSubagents(pMsg, &dwId, &count);
 
        // Tables
-   pMsg->SetVariable(VID_NUM_TABLES, (UINT32)m_iNumTables);
+   pMsg->setField(VID_NUM_TABLES, (UINT32)m_iNumTables);
    for(i = 0, dwId = VID_TABLE_LIST_BASE; i < m_iNumTables; i++)
    {
-      pMsg->SetVariable(dwId++, m_pTableList[i].name);
-               pMsg->SetVariable(dwId++, m_pTableList[i].instanceColumns);
-               pMsg->SetVariable(dwId++, m_pTableList[i].description);
+      pMsg->setField(dwId++, m_pTableList[i].name);
+               pMsg->setField(dwId++, m_pTableList[i].instanceColumns);
+               pMsg->setField(dwId++, m_pTableList[i].description);
    }
        ListTablesFromExtSubagents(pMsg, &dwId, &count);
 }
@@ -735,17 +735,17 @@ void GetParameterList(CSCPMessage *pMsg)
 /**
  * Put list of supported tables into NXCP message
  */
-void GetTableList(CSCPMessage *pMsg)
+void GetTableList(NXCPMessage *pMsg)
 {
    int i;
    UINT32 dwId, count;
 
-   pMsg->SetVariable(VID_NUM_TABLES, (UINT32)m_iNumTables);
+   pMsg->setField(VID_NUM_TABLES, (UINT32)m_iNumTables);
    for(i = 0, dwId = VID_TABLE_LIST_BASE; i < m_iNumTables; i++)
    {
-      pMsg->SetVariable(dwId++, m_pTableList[i].name);
-               pMsg->SetVariable(dwId++, m_pTableList[i].instanceColumns);
-               pMsg->SetVariable(dwId++, m_pTableList[i].description);
+      pMsg->setField(dwId++, m_pTableList[i].name);
+               pMsg->setField(dwId++, m_pTableList[i].instanceColumns);
+               pMsg->setField(dwId++, m_pTableList[i].description);
    }
        ListTablesFromExtSubagents(pMsg, &dwId, &count);
 }
@@ -753,15 +753,15 @@ void GetTableList(CSCPMessage *pMsg)
 /**
  * Put list of supported lists (enums) into NXCP message
  */
-void GetEnumList(CSCPMessage *pMsg)
+void GetEnumList(NXCPMessage *pMsg)
 {
    int i;
    UINT32 dwId, count;
 
-   pMsg->SetVariable(VID_NUM_ENUMS, (UINT32)m_iNumEnums);
+   pMsg->setField(VID_NUM_ENUMS, (UINT32)m_iNumEnums);
    for(i = 0, dwId = VID_ENUM_LIST_BASE; i < m_iNumEnums; i++)
    {
-      pMsg->SetVariable(dwId++, m_pEnumList[i].name);
+      pMsg->setField(dwId++, m_pEnumList[i].name);
    }
        ListListsFromExtSubagents(pMsg, &dwId, &count);
 }
index ba8700e..cde3bc5 100644 (file)
 /**
  * Handler for CMD_GET_PARAMETER command
  */
-static void H_GetParameter(CSCPMessage *pRequest, CSCPMessage *pMsg)
+static void H_GetParameter(NXCPMessage *pRequest, NXCPMessage *pMsg)
 {
    TCHAR name[MAX_PARAM_NAME], value[MAX_RESULT_LENGTH];
    UINT32 dwErrorCode;
 
-   pRequest->GetVariableStr(VID_PARAMETER, name, MAX_PARAM_NAME);
+   pRequest->getFieldAsString(VID_PARAMETER, name, MAX_PARAM_NAME);
    dwErrorCode = GetParameterValue(0, name, value);
-   pMsg->SetVariable(VID_RCC, dwErrorCode);
+   pMsg->setField(VID_RCC, dwErrorCode);
    if (dwErrorCode == ERR_SUCCESS)
-      pMsg->SetVariable(VID_VALUE, value);
+      pMsg->setField(VID_VALUE, value);
 }
 
 /**
  * Handler for CMD_GET_TABLE command
  */
-static void H_GetTable(CSCPMessage *pRequest, CSCPMessage *pMsg)
+static void H_GetTable(NXCPMessage *pRequest, NXCPMessage *pMsg)
 {
    TCHAR name[MAX_PARAM_NAME];
        Table value;
    UINT32 dwErrorCode;
 
-   pRequest->GetVariableStr(VID_PARAMETER, name, MAX_PARAM_NAME);
+   pRequest->getFieldAsString(VID_PARAMETER, name, MAX_PARAM_NAME);
    dwErrorCode = GetTableValue(0, name, &value);
-   pMsg->SetVariable(VID_RCC, dwErrorCode);
+   pMsg->setField(VID_RCC, dwErrorCode);
    if (dwErrorCode == ERR_SUCCESS)
                value.fillMessage(*pMsg, 0, -1);
 }
@@ -56,20 +56,20 @@ static void H_GetTable(CSCPMessage *pRequest, CSCPMessage *pMsg)
 /**
  * Handler for CMD_GET_LIST command
  */
-static void H_GetList(CSCPMessage *pRequest, CSCPMessage *pMsg)
+static void H_GetList(NXCPMessage *pRequest, NXCPMessage *pMsg)
 {
    TCHAR name[MAX_PARAM_NAME];
        StringList value;
    UINT32 dwErrorCode;
 
-   pRequest->GetVariableStr(VID_PARAMETER, name, MAX_PARAM_NAME);
+   pRequest->getFieldAsString(VID_PARAMETER, name, MAX_PARAM_NAME);
    dwErrorCode = GetListValue(0, name, &value);
-   pMsg->SetVariable(VID_RCC, dwErrorCode);
+   pMsg->setField(VID_RCC, dwErrorCode);
    if (dwErrorCode == ERR_SUCCESS)
    {
-               pMsg->SetVariable(VID_NUM_STRINGS, (UINT32)value.size());
+               pMsg->setField(VID_NUM_STRINGS, (UINT32)value.size());
                for(int i = 0; i < value.size(); i++)
-                       pMsg->SetVariable(VID_ENUM_VALUE_BASE + i, value.get(i));
+                       pMsg->setField(VID_ENUM_VALUE_BASE + i, value.get(i));
    }
 }
 
@@ -126,17 +126,20 @@ THREAD_RESULT THREAD_CALL MasterAgentListener(void *arg)
                        while(!(g_dwFlags & AF_SHUTDOWN))
                        {
             MessageReceiverResult result;
-                               CSCPMessage *msg = receiver.readMessage(INFINITE, &result);
+                               NXCPMessage *msg = receiver.readMessage(INFINITE, &result);
                                if ((msg == NULL) || (g_dwFlags & AF_SHUTDOWN))
+            {
+               AgentWriteDebugLog(6, _T("MasterAgentListener: receiver failure (%s)"), AbstractMessageReceiver::resultToText(result));
                                        break;
+            }
 
             TCHAR buffer[256];
-                               AgentWriteDebugLog(6, _T("Received message %s from master agent"), NXCPMessageCodeName(msg->GetCode(), buffer));
+                               AgentWriteDebugLog(6, _T("Received message %s from master agent"), NXCPMessageCodeName(msg->getCode(), buffer));
                                
-                               CSCPMessage response;
-                               response.SetCode(CMD_REQUEST_COMPLETED);
-                               response.SetId(msg->GetId());
-                               switch(msg->GetCode())
+                               NXCPMessage response;
+                               response.setCode(CMD_REQUEST_COMPLETED);
+                               response.setId(msg->getId());
+                               switch(msg->getCode())
                                {
                                        case CMD_GET_PARAMETER:
                                                H_GetParameter(msg, &response);
@@ -148,15 +151,15 @@ THREAD_RESULT THREAD_CALL MasterAgentListener(void *arg)
                                                H_GetList(msg, &response);
                                                break;
                                        case CMD_GET_PARAMETER_LIST:
-                                               response.SetVariable(VID_RCC, ERR_SUCCESS);
+                                               response.setField(VID_RCC, ERR_SUCCESS);
                                                GetParameterList(&response);
                                                break;
                                        case CMD_GET_ENUM_LIST:
-                                               response.SetVariable(VID_RCC, ERR_SUCCESS);
+                                               response.setField(VID_RCC, ERR_SUCCESS);
                                                GetEnumList(&response);
                                                break;
                                        case CMD_GET_TABLE_LIST:
-                                               response.SetVariable(VID_RCC, ERR_SUCCESS);
+                                               response.setField(VID_RCC, ERR_SUCCESS);
                                                GetTableList(&response);
                                                break;
                case CMD_SHUTDOWN:
@@ -165,13 +168,13 @@ THREAD_RESULT THREAD_CALL MasterAgentListener(void *arg)
                   exit(0);
                   break;
                                        default:
-                                               response.SetVariable(VID_RCC, ERR_UNKNOWN_COMMAND);
+                                               response.setField(VID_RCC, ERR_UNKNOWN_COMMAND);
                                                break;
                                }
                                delete msg;
 
                                // Send response to pipe
-                               CSCP_MESSAGE *rawMsg = response.createMessage();
+                               NXCP_MESSAGE *rawMsg = response.createMessage();
             bool sendSuccess = SendMessageToPipe(s_pipe, rawMsg);
             free(rawMsg);
             if (!sendSuccess)
@@ -206,9 +209,9 @@ THREAD_RESULT THREAD_CALL MasterAgentListener(void *arg)
 /**
  * Send message to master agent
  */
-bool SendMessageToMasterAgent(CSCPMessage *msg)
+bool SendMessageToMasterAgent(NXCPMessage *msg)
 {
-   CSCP_MESSAGE *rawMsg = msg->createMessage();
+   NXCP_MESSAGE *rawMsg = msg->createMessage();
    bool success = SendRawMessageToMasterAgent(rawMsg);
    free(rawMsg);
    return success;
@@ -217,7 +220,7 @@ bool SendMessageToMasterAgent(CSCPMessage *msg)
 /**
  * Send raw message to master agent
  */
-bool SendRawMessageToMasterAgent(CSCP_MESSAGE *msg)
+bool SendRawMessageToMasterAgent(NXCP_MESSAGE *msg)
 {
        MutexLock(s_mutexPipeWrite);
    bool success = SendMessageToPipe(s_pipe, msg);
index fb6c44c..3b4476f 100644 (file)
@@ -1211,8 +1211,8 @@ static void InitConfig()
  */
 static void InitiateExtSubagentShutdown()
 {
-   CSCPMessage msg;
-   msg.SetCode(CMD_SHUTDOWN);
+   NXCPMessage msg;
+   msg.setCode(CMD_SHUTDOWN);
    if (SendControlMessage(&msg))
       _tprintf(_T("Control message sent successfully to master agent\n"));
    else
index bd1112d..fd93374 100644 (file)
@@ -234,8 +234,8 @@ private:
        UINT32 m_requestId;
        MUTEX m_mutexPipeWrite;
 
-       bool sendMessage(CSCPMessage *msg);
-       CSCPMessage *waitForMessage(WORD code, UINT32 id);
+       bool sendMessage(NXCPMessage *msg);
+       NXCPMessage *waitForMessage(WORD code, UINT32 id);
        UINT32 waitForRCC(UINT32 id);
        NETXMS_SUBAGENT_PARAM *getSupportedParameters(UINT32 *count);
        NETXMS_SUBAGENT_LIST *getSupportedLists(UINT32 *count);
@@ -254,11 +254,11 @@ public:
        UINT32 getParameter(const TCHAR *name, TCHAR *buffer);
        UINT32 getTable(const TCHAR *name, Table *value);
        UINT32 getList(const TCHAR *name, StringList *value);
-       void listParameters(CSCPMessage *msg, UINT32 *baseId, UINT32 *count);
+       void listParameters(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
        void listParameters(StringList *list);
-       void listLists(CSCPMessage *msg, UINT32 *baseId, UINT32 *count);
+       void listLists(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
        void listLists(StringList *list);
-       void listTables(CSCPMessage *msg, UINT32 *baseId, UINT32 *count);
+       void listTables(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
        void listTables(StringList *list);
    void shutdown();
 };
@@ -298,7 +298,7 @@ private:
    SOCKET m_hSocket;
    Queue *m_pSendQueue;
    Queue *m_pMessageQueue;
-   CSCP_BUFFER *m_pMsgBuffer;
+   NXCP_BUFFER *m_pMsgBuffer;
    THREAD m_hWriteThread;
    THREAD m_hProcessingThread;
    THREAD m_hProxyReadThread;
@@ -316,19 +316,19 @@ private:
    SOCKET m_hProxySocket;     // Socket for proxy connection
        MUTEX m_socketWriteMutex;
 
-       BOOL sendRawMessage(CSCP_MESSAGE *pMsg, NXCPEncryptionContext *pCtx);
-   void authenticate(CSCPMessage *pRequest, CSCPMessage *pMsg);
-   void getConfig(CSCPMessage *pMsg);
-   void updateConfig(CSCPMessage *pRequest, CSCPMessage *pMsg);
-   void getParameter(CSCPMessage *pRequest, CSCPMessage *pMsg);
-   void getList(CSCPMessage *pRequest, CSCPMessage *pMsg);
-   void getTable(CSCPMessage *pRequest, CSCPMessage *pMsg);
-   void action(CSCPMessage *pRequest, CSCPMessage *pMsg);
-   void recvFile(CSCPMessage *pRequest, CSCPMessage *pMsg);
-   void getLocalFile(CSCPMessage *pRequest, CSCPMessage *pMsg);
-   void cancelFileMonitoring(CSCPMessage *pRequest, CSCPMessage *pMsg);
-   UINT32 upgrade(CSCPMessage *pRequest);
-   UINT32 setupProxyConnection(CSCPMessage *pRequest);
+       BOOL sendRawMessage(NXCP_MESSAGE *pMsg, NXCPEncryptionContext *pCtx);
+   void authenticate(NXCPMessage *pRequest, NXCPMessage *pMsg);
+   void getConfig(NXCPMessage *pMsg);
+   void updateConfig(NXCPMessage *pRequest, NXCPMessage *pMsg);
+   void getParameter(NXCPMessage *pRequest, NXCPMessage *pMsg);
+   void getList(NXCPMessage *pRequest, NXCPMessage *pMsg);
+   void getTable(NXCPMessage *pRequest, NXCPMessage *pMsg);
+   void action(NXCPMessage *pRequest, NXCPMessage *pMsg);
+   void recvFile(NXCPMessage *pRequest, NXCPMessage *pMsg);
+   void getLocalFile(NXCPMessage *pRequest, NXCPMessage *pMsg);
+   void cancelFileMonitoring(NXCPMessage *pRequest, NXCPMessage *pMsg);
+   UINT32 upgrade(NXCPMessage *pRequest);
+   UINT32 setupProxyConnection(NXCPMessage *pRequest);
 
    void readThread();
    void writeThread();
@@ -347,8 +347,8 @@ public:
    void run();
    void disconnect();
 
-   virtual void sendMessage(CSCPMessage *pMsg) { m_pSendQueue->Put(pMsg->createMessage()); }
-   virtual void sendRawMessage(CSCP_MESSAGE *pMsg) { m_pSendQueue->Put(nx_memdup(pMsg, ntohl(pMsg->dwSize))); }
+   virtual void sendMessage(NXCPMessage *pMsg) { m_pSendQueue->Put(pMsg->createMessage()); }
+   virtual void sendRawMessage(NXCP_MESSAGE *pMsg) { m_pSendQueue->Put(nx_memdup(pMsg, ntohl(pMsg->size))); }
        virtual bool sendFile(UINT32 requestId, const TCHAR *file, long offset);
 
        virtual const InetAddress& getServerAddress() { return m_serverAddr; }
@@ -376,7 +376,7 @@ private:
    UINT32 m_id;
    SOCKET m_socket;
    MUTEX m_mutex;
-   CSCP_BUFFER m_msgBuffer;
+   NXCP_BUFFER m_msgBuffer;
    MsgWaitQueue m_msgQueue;
    UINT32 m_sessionId;
    TCHAR *m_sessionName;
@@ -385,7 +385,7 @@ private:
    VolatileCounter m_requestId;
 
    void readThread();
-   bool sendMessage(CSCPMessage *msg);
+   bool sendMessage(NXCPMessage *msg);
    UINT32 nextRequestId() { return InterlockedIncrement(&m_requestId); }
 
    static THREAD_RESULT THREAD_CALL readThreadStarter(void *);
@@ -404,7 +404,7 @@ public:
    const TCHAR *getUserName() { return CHECK_NULL(m_userName); }
 
    bool testConnection();
-   void takeScreenshot(CSCPMessage *msg);
+   void takeScreenshot(NXCPMessage *msg);
 };
 
 /**
@@ -454,15 +454,15 @@ BOOL AddExternalParameter(TCHAR *pszCfgLine, BOOL bShellExec, BOOL bIsList);
 UINT32 GetParameterValue(UINT32 dwSessionId, TCHAR *pszParam, TCHAR *pszValue);
 UINT32 GetListValue(UINT32 dwSessionId, TCHAR *pszParam, StringList *pValue);
 UINT32 GetTableValue(UINT32 dwSessionId, TCHAR *pszParam, Table *pValue);
-void GetParameterList(CSCPMessage *pMsg);
-void GetEnumList(CSCPMessage *pMsg);
-void GetTableList(CSCPMessage *pMsg);
+void GetParameterList(NXCPMessage *pMsg);
+void GetEnumList(NXCPMessage *pMsg);
+void GetTableList(NXCPMessage *pMsg);
 BOOL LoadSubAgent(TCHAR *szModuleName);
 void UnloadAllSubAgents();
 BOOL InitSubAgent(HMODULE hModule, const TCHAR *pszModuleName,
                   BOOL (* SubAgentInit)(NETXMS_SUBAGENT_INFO **, Config *),
                   const TCHAR *pszEntryPoint);
-BOOL ProcessCmdBySubAgent(UINT32 dwCommand, CSCPMessage *pRequest, CSCPMessage *pResponse, AbstractCommSession *session);
+BOOL ProcessCmdBySubAgent(UINT32 dwCommand, NXCPMessage *pRequest, NXCPMessage *pResponse, AbstractCommSession *session);
 BOOL AddAction(const TCHAR *pszName, int iType, const TCHAR *pArg,
                LONG (*fpHandler)(const TCHAR *, StringList *, const TCHAR *),
                const TCHAR *pszSubAgent, const TCHAR *pszDescription);
@@ -475,22 +475,22 @@ UINT32 ExecuteShellCommand(TCHAR *pszCommand, StringList *pArgs);
 void StartParamProvidersPoller();
 bool AddParametersProvider(const TCHAR *line);
 LONG GetParameterValueFromExtProvider(const TCHAR *name, TCHAR *buffer);
-void ListParametersFromExtProviders(CSCPMessage *msg, UINT32 *baseId, UINT32 *count);
+void ListParametersFromExtProviders(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
 void ListParametersFromExtProviders(StringList *list);
 
 bool AddExternalSubagent(const TCHAR *config);
 UINT32 GetParameterValueFromExtSubagent(const TCHAR *name, TCHAR *buffer);
 UINT32 GetTableValueFromExtSubagent(const TCHAR *name, Table *value);
 UINT32 GetListValueFromExtSubagent(const TCHAR *name, StringList *value);
-void ListParametersFromExtSubagents(CSCPMessage *msg, UINT32 *baseId, UINT32 *count);
+void ListParametersFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
 void ListParametersFromExtSubagents(StringList *list);
-void ListListsFromExtSubagents(CSCPMessage *msg, UINT32 *baseId, UINT32 *count);
+void ListListsFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
 void ListListsFromExtSubagents(StringList *list);
-void ListTablesFromExtSubagents(CSCPMessage *msg, UINT32 *baseId, UINT32 *count);
+void ListTablesFromExtSubagents(NXCPMessage *msg, UINT32 *baseId, UINT32 *count);
 void ListTablesFromExtSubagents(StringList *list);
-bool SendMessageToPipe(HPIPE hPipe, CSCP_MESSAGE *msg);
-bool SendMessageToMasterAgent(CSCPMessage *msg);
-bool SendRawMessageToMasterAgent(CSCP_MESSAGE *msg);
+bool SendMessageToPipe(HPIPE hPipe, NXCP_MESSAGE *msg);
+bool SendMessageToMasterAgent(NXCPMessage *msg);
+bool SendRawMessageToMasterAgent(NXCP_MESSAGE *msg);
 void ShutdownExtSubagents();
 
 void RegisterApplicationAgent(const TCHAR *name);
@@ -503,7 +503,7 @@ UINT32 UpgradeAgent(TCHAR *pszPkgFile);
 void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, int iNumArgs, TCHAR **ppArgList);
 void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, const char *pszFormat, ...);
 void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, const char *pszFormat, va_list args);
-void ForwardTrap(CSCPMessage *msg);
+void ForwardTrap(NXCPMessage *msg);
 
 Config *OpenRegistry();
 void CloseRegistry(bool modified);
@@ -514,7 +514,7 @@ bool PushData(const TCHAR *parameter, const TCHAR *value, UINT32 objectId);
 void StartStorageDiscoveryConnector();
 
 void StartControlConnector();
-bool SendControlMessage(CSCPMessage *msg);
+bool SendControlMessage(NXCPMessage *msg);
 
 void StartSessionAgentConnector();
 SessionAgentConnector *AcquireSessionAgentConnector(const TCHAR *sessionName);
index c33ca4b..25932a2 100644 (file)
@@ -82,7 +82,7 @@ static int GetPolicyType(uuid_t guid)
 /**
  * Deploy configuration file
  */
-static UINT32 DeployConfig(UINT32 session, uuid_t guid, CSCPMessage *msg)
+static UINT32 DeployConfig(UINT32 session, uuid_t guid, NXCPMessage *msg)
 {
        TCHAR path[MAX_PATH], name[64], tail;
        int fh;
@@ -96,11 +96,11 @@ static UINT32 DeployConfig(UINT32 session, uuid_t guid, CSCPMessage *msg)
        fh = _topen(path, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, S_IRUSR | S_IWUSR);
        if (fh != -1)
        {
-               UINT32 size = msg->GetVariableBinary(VID_CONFIG_FILE_DATA, NULL, 0);
+               UINT32 size = msg->getFieldAsBinary(VID_CONFIG_FILE_DATA, NULL, 0);
                BYTE *data = (BYTE *)malloc(size);
                if (data != NULL)
                {
-                       msg->GetVariableBinary(VID_CONFIG_FILE_DATA, data, size);
+                       msg->getFieldAsBinary(VID_CONFIG_FILE_DATA, data, size);
                        if (write(fh, data, size) == size)
                        {
                      DebugPrintf(session, 3, _T("Configuration file %s saved successfully"), path);
@@ -130,7 +130,7 @@ static UINT32 DeployConfig(UINT32 session, uuid_t guid, CSCPMessage *msg)
 /**
  * Deploy log parser policy
  */
-static UINT32 DeployLogParser(UINT32 session, uuid_t guid, CSCPMessage *msg)
+static UINT32 DeployLogParser(UINT32 session, uuid_t guid, NXCPMessage *msg)
 {
        return ERR_NOT_IMPLEMENTED;
 }
@@ -138,13 +138,13 @@ static UINT32 DeployLogParser(UINT32 session, uuid_t guid, CSCPMessage *msg)
 /**
  * Deploy policy on agent
  */
-UINT32 DeployPolicy(CommSession *session, CSCPMessage *request)
+UINT32 DeployPolicy(CommSession *session, NXCPMessage *request)
 {
        UINT32 type, rcc;
        uuid_t guid;
 
-       type = request->GetVariableShort(VID_POLICY_TYPE);
-       request->GetVariableBinary(VID_GUID, guid, UUID_LENGTH);
+       type = request->getFieldAsUInt16(VID_POLICY_TYPE);
+       request->getFieldAsBinary(VID_GUID, guid, UUID_LENGTH);
 
        switch(type)
        {
@@ -169,7 +169,7 @@ UINT32 DeployPolicy(CommSession *session, CSCPMessage *request)
 /**
  * Remove configuration file
  */
-static UINT32 RemoveConfig(UINT32 session, uuid_t guid,  CSCPMessage *msg)
+static UINT32 RemoveConfig(UINT32 session, uuid_t guid,  NXCPMessage *msg)
 {
        TCHAR path[MAX_PATH], name[64], tail;
        UINT32 rcc;
@@ -193,7 +193,7 @@ static UINT32 RemoveConfig(UINT32 session, uuid_t guid,  CSCPMessage *msg)
 /**
  * Remove log parser file
  */
-static UINT32 RemoveLogParser(UINT32 session, uuid_t guid,  CSCPMessage *msg)
+static UINT32 RemoveLogParser(UINT32 session, uuid_t guid,  NXCPMessage *msg)
 {
        TCHAR path[MAX_PATH], name[64], tail;
        UINT32 rcc;
@@ -217,14 +217,14 @@ static UINT32 RemoveLogParser(UINT32 session, uuid_t guid,  CSCPMessage *msg)
 /**
  * Uninstall policy from agent
  */
-UINT32 UninstallPolicy(CommSession *session, CSCPMessage *request)
+UINT32 UninstallPolicy(CommSession *session, NXCPMessage *request)
 {
        UINT32 rcc;
        int type;
        uuid_t guid;
        TCHAR buffer[64];
 
-       request->GetVariableBinary(VID_GUID, guid, UUID_LENGTH);
+       request->getFieldAsBinary(VID_GUID, guid, UUID_LENGTH);
        type = GetPolicyType(guid);
 
        switch(type)
@@ -250,14 +250,14 @@ UINT32 UninstallPolicy(CommSession *session, CSCPMessage *request)
 /**
  * Get policy inventory
  */
-UINT32 GetPolicyInventory(CommSession *session, CSCPMessage *msg)
+UINT32 GetPolicyInventory(CommSession *session, NXCPMessage *msg)
 {
        Config *registry = OpenRegistry();
 
        ObjectArray<ConfigEntry> *list = registry->getSubEntries(_T("/policyRegistry"), NULL);
        if (list != NULL)
        {
-               msg->SetVariable(VID_NUM_ELEMENTS, (UINT32)list->size());
+               msg->setField(VID_NUM_ELEMENTS, (UINT32)list->size());
                UINT32 varId = VID_ELEMENT_LIST_BASE;
                for(int i = 0; i < list->size(); i++, varId += 7)
                {
@@ -267,16 +267,16 @@ UINT32 GetPolicyInventory(CommSession *session, CSCPMessage *msg)
                        if (MatchString(_T("policy-*"), e->getName(), TRUE))
                        {
                                uuid_parse(&(e->getName()[7]), guid);
-                               msg->SetVariable(varId++, guid, UUID_LENGTH);
-                               msg->SetVariable(varId++, (WORD)e->getSubEntryValueAsInt(_T("type")));
-                               msg->SetVariable(varId++, e->getSubEntryValue(_T("server")));
+                               msg->setField(varId++, guid, UUID_LENGTH);
+                               msg->setField(varId++, (WORD)e->getSubEntryValueAsInt(_T("type")));
+                               msg->setField(varId++, e->getSubEntryValue(_T("server")));
                        }
                }
                delete list;
        }
        else
        {
-               msg->SetVariable(VID_NUM_ELEMENTS, (UINT32)0);
+               msg->setField(VID_NUM_ELEMENTS, (UINT32)0);
        }
        
        CloseRegistry(false);
index f5c7dbd..540ec22 100644 (file)
@@ -32,16 +32,16 @@ static QWORD s_requestId = (QWORD)time(NULL) << 32;
  */
 bool PushData(const TCHAR *parameter, const TCHAR *value, UINT32 objectId)
 {
-       CSCPMessage msg;
+       NXCPMessage msg;
        bool success = false;
 
        AgentWriteDebugLog(6, _T("PushData: \"%s\" = \"%s\""), parameter, value);
 
-       msg.SetCode(CMD_PUSH_DCI_DATA);
-       msg.SetVariable(VID_NAME, parameter);
-       msg.SetVariable(VID_VALUE, value);
-   msg.SetVariable(VID_OBJECT_ID, objectId);
-   msg.SetVariable(VID_REQUEST_ID, s_requestId++); 
+       msg.setCode(CMD_PUSH_DCI_DATA);
+       msg.setField(VID_NAME, parameter);
+       msg.setField(VID_VALUE, value);
+   msg.setField(VID_OBJECT_ID, objectId);
+   msg.setField(VID_REQUEST_ID, s_requestId++); 
 
    if (g_dwFlags & AF_SUBAGENT_LOADER)
    {
@@ -74,20 +74,20 @@ static void ProcessPushRequest(HPIPE hPipe)
        while(true)
        {
       MessageReceiverResult result;
-               CSCPMessage *msg = receiver.readMessage(5000, &result);
+               NXCPMessage *msg = receiver.readMessage(5000, &result);
                if (msg == NULL)
                        break;
-               AgentWriteDebugLog(6, _T("ProcessPushRequest: received message %s"), NXCPMessageCodeName(msg->GetCode(), buffer));
-               if (msg->GetCode() == CMD_PUSH_DCI_DATA)
+               AgentWriteDebugLog(6, _T("ProcessPushRequest: received message %s"), NXCPMessageCodeName(msg->getCode(), buffer));
+               if (msg->getCode() == CMD_PUSH_DCI_DATA)
                {
-         UINT32 objectId = msg->GetVariableLong(VID_OBJECT_ID);
-                       UINT32 count = msg->GetVariableLong(VID_NUM_ITEMS);
+         UINT32 objectId = msg->getFieldAsUInt32(VID_OBJECT_ID);
+                       UINT32 count = msg->getFieldAsUInt32(VID_NUM_ITEMS);
                        UINT32 varId = VID_PUSH_DCI_DATA_BASE;
                        for(DWORD i = 0; i < count; i++)
                        {
                                TCHAR name[MAX_PARAM_NAME], value[MAX_RESULT_LENGTH];
-                               msg->GetVariableStr(varId++, name, MAX_PARAM_NAME);
-                               msg->GetVariableStr(varId++, value, MAX_RESULT_LENGTH);
+                               msg->getFieldAsString(varId++, name, MAX_PARAM_NAME);
+                               msg->getFieldAsString(varId++, value, MAX_RESULT_LENGTH);
                                PushData(name, value, objectId);
                        }
                }
index 507d129..1d72801 100644 (file)
@@ -42,9 +42,9 @@ BOOL RegisterOnServer(const TCHAR *pszServer)
    struct sockaddr_in sa;
    BOOL bRet = FALSE;
    TCHAR szBuffer[MAX_RESULT_LENGTH];
-   CSCPMessage msg, *pResponse;
-   CSCP_MESSAGE *pRawMsg;
-   CSCP_BUFFER *pBuffer;
+   NXCPMessage msg, *pResponse;
+   NXCP_MESSAGE *pRawMsg;
+   NXCP_BUFFER *pBuffer;
    NXCPEncryptionContext *pDummyCtx = NULL;
    int nLen;
 
@@ -66,32 +66,32 @@ BOOL RegisterOnServer(const TCHAR *pszServer)
       if (connect(hSocket, (struct sockaddr *)&sa, sizeof(sa)) != -1)
       {
          // Prepare request
-         msg.SetCode(CMD_REGISTER_AGENT);
-         msg.SetId(2);
+         msg.setCode(CMD_REGISTER_AGENT);
+         msg.setId(2);
          if (H_PlatformName(NULL, NULL, szBuffer) != SYSINFO_RC_SUCCESS)
             _tcscpy(szBuffer, _T("error"));
-         msg.SetVariable(VID_PLATFORM_NAME, szBuffer);
-         msg.SetVariable(VID_VERSION_MAJOR, (WORD)NETXMS_VERSION_MAJOR);
-         msg.SetVariable(VID_VERSION_MINOR, (WORD)NETXMS_VERSION_MINOR);
-         msg.SetVariable(VID_VERSION_RELEASE, (WORD)NETXMS_VERSION_BUILD);
+         msg.setField(VID_PLATFORM_NAME, szBuffer);
+         msg.setField(VID_VERSION_MAJOR, (WORD)NETXMS_VERSION_MAJOR);
+         msg.setField(VID_VERSION_MINOR, (WORD)NETXMS_VERSION_MINOR);
+         msg.setField(VID_VERSION_RELEASE, (WORD)NETXMS_VERSION_BUILD);
 
          // Send request
          pRawMsg = msg.createMessage();
-         nLen = ntohl(pRawMsg->dwSize);
+         nLen = ntohl(pRawMsg->size);
          if (SendEx(hSocket, pRawMsg, nLen, 0, NULL) == nLen)
          {
-            pRawMsg = (CSCP_MESSAGE *)realloc(pRawMsg, MAX_MSG_SIZE);
-            pBuffer = (CSCP_BUFFER *)malloc(sizeof(CSCP_BUFFER));
+            pRawMsg = (NXCP_MESSAGE *)realloc(pRawMsg, MAX_MSG_SIZE);
+            pBuffer = (NXCP_BUFFER *)malloc(sizeof(NXCP_BUFFER));
             RecvNXCPMessage(0, NULL, pBuffer, 0, NULL, NULL, 0);
 
             nLen = RecvNXCPMessage(hSocket, pRawMsg, pBuffer, MAX_MSG_SIZE,
                                    &pDummyCtx, NULL, 30000);
             if (nLen >= 16)
             {
-               pResponse = new CSCPMessage(pRawMsg);
-               if ((pResponse->GetCode() == CMD_REQUEST_COMPLETED) &&
-                   (pResponse->GetId() == 2) &&
-                   (pResponse->GetVariableLong(VID_RCC) == 0))
+               pResponse = new NXCPMessage(pRawMsg);
+               if ((pResponse->getCode() == CMD_REQUEST_COMPLETED) &&
+                   (pResponse->getId() == 2) &&
+                   (pResponse->getFieldAsUInt32(VID_RCC) == 0))
                {
                   bRet = TRUE;
                }
index 319a167..2f8d3b2 100644 (file)
@@ -115,10 +115,10 @@ void SessionAgentConnector::disconnect()
 /**
  * Send message
  */
-bool SessionAgentConnector::sendMessage(CSCPMessage *msg)
+bool SessionAgentConnector::sendMessage(NXCPMessage *msg)
 {
-   CSCP_MESSAGE *rawMsg = msg->createMessage();
-   bool success = (SendEx(m_socket, rawMsg, ntohl(rawMsg->dwSize), 0, m_mutex) == ntohl(rawMsg->dwSize));
+   NXCP_MESSAGE *rawMsg = msg->createMessage();
+   bool success = (SendEx(m_socket, rawMsg, ntohl(rawMsg->size), 0, m_mutex) == ntohl(rawMsg->size));
    free(rawMsg);
    return success;
 }
@@ -131,7 +131,7 @@ void SessionAgentConnector::readThread()
    NXCPEncryptionContext *dummyCtx = NULL;
    RecvNXCPMessage(0, NULL, &m_msgBuffer, 0, NULL, NULL, 0);
    UINT32 rawMsgSize = 65536;
-   CSCP_MESSAGE *rawMsg = (CSCP_MESSAGE *)malloc(rawMsgSize);
+   NXCP_MESSAGE *rawMsg = (NXCP_MESSAGE *)malloc(rawMsgSize);
    while(1)
    {
       int err = RecvNXCPMessageEx(m_socket, &rawMsg, &m_msgBuffer, &rawMsgSize, &dummyCtx, NULL, 300000, 4 * 1024 * 1024);
@@ -154,33 +154,33 @@ void SessionAgentConnector::readThread()
       }
 
       // Check that actual received packet size is equal to encoded in packet
-      if ((int)ntohl(rawMsg->dwSize) != err)
+      if ((int)ntohl(rawMsg->size) != err)
       {
-         DebugPrintf(INVALID_INDEX, 5, _T("Session agent connector %d: actual message size doesn't match wSize value (%d,%d)"), m_id, err, ntohl(rawMsg->dwSize));
+         DebugPrintf(INVALID_INDEX, 5, _T("Session agent connector %d: actual message size doesn't match wSize value (%d,%d)"), m_id, err, ntohl(rawMsg->size));
          continue;   // Bad packet, wait for next
       }
 
       if (g_debugLevel >= 8)
       {
-         String msgDump = CSCPMessage::dump(rawMsg, NXCP_VERSION);
+         String msgDump = NXCPMessage::dump(rawMsg, NXCP_VERSION);
          DebugPrintf(INVALID_INDEX, 8, _T("SA-%d: Message dump:\n%s"), m_id, (const TCHAR *)msgDump);
       }
 
-      UINT16 flags = ntohs(rawMsg->wFlags);
+      UINT16 flags = ntohs(rawMsg->flags);
       if (!(flags & MF_BINARY))
       {
          // Create message object from raw message
-         CSCPMessage *msg = new CSCPMessage(rawMsg);
-         if (msg->GetCode() == CMD_LOGIN)
+         NXCPMessage *msg = new NXCPMessage(rawMsg);
+         if (msg->getCode() == CMD_LOGIN)
          {
-            m_sessionId = msg->GetVariableLong(VID_SESSION_ID);
+            m_sessionId = msg->getFieldAsUInt32(VID_SESSION_ID);
             m_sessionState = msg->getFieldAsInt16(VID_SESSION_STATE);
 
             safe_free(m_sessionName);
-            m_sessionName = msg->GetVariableStr(VID_NAME);
+            m_sessionName = msg->getFieldAsString(VID_NAME);
 
             safe_free(m_userName);
-            m_userName = msg->GetVariableStr(VID_USER_NAME);
+            m_userName = msg->getFieldAsString(VID_USER_NAME);
 
             delete msg;
             DebugPrintf(INVALID_INDEX, 5, _T("Session agent connector %d: login as %s@%s [%d]"), m_id, getUserName(), getSessionName(), m_sessionId);
@@ -201,14 +201,14 @@ void SessionAgentConnector::readThread()
  */
 bool SessionAgentConnector::testConnection()
 {
-   CSCPMessage msg;
+   NXCPMessage msg;
 
-   msg.SetCode(CMD_KEEPALIVE);
-   msg.SetId(nextRequestId());
+   msg.setCode(CMD_KEEPALIVE);
+   msg.setId(nextRequestId());
    if (!sendMessage(&msg))
       return false;
 
-   CSCPMessage *response = m_msgQueue.waitForMessage(CMD_REQUEST_COMPLETED, msg.GetId(), 5000);
+   NXCPMessage *response = m_msgQueue.waitForMessage(CMD_REQUEST_COMPLETED, msg.getId(), 5000);
    if (response == NULL)
       return false;
 
@@ -219,37 +219,37 @@ bool SessionAgentConnector::testConnection()
 /**
  * Take screenshot via session agent
  */
-void SessionAgentConnector::takeScreenshot(CSCPMessage *masterResponse)
+void SessionAgentConnector::takeScreenshot(NXCPMessage *masterResponse)
 {
-   CSCPMessage msg;
+   NXCPMessage msg;
 
-   msg.SetCode(CMD_TAKE_SCREENSHOT);
-   msg.SetId(nextRequestId());
+   msg.setCode(CMD_TAKE_SCREENSHOT);
+   msg.setId(nextRequestId());
    if (!sendMessage(&msg))
    {
-      masterResponse->SetVariable(VID_RCC, ERR_CONNECTION_BROKEN);
+      masterResponse->setField(VID_RCC, ERR_CONNECTION_BROKEN);
       return;
    }
 
-   CSCPMessage *response = m_msgQueue.waitForMessage(CMD_REQUEST_COMPLETED, msg.GetId(), 5000);
+   NXCPMessage *response = m_msgQueue.waitForMessage(CMD_REQUEST_COMPLETED, msg.getId(), 5000);
    if (response == NULL)
    {
-      masterResponse->SetVariable(VID_RCC, ERR_REQUEST_TIMEOUT);
+      masterResponse->setField(VID_RCC, ERR_REQUEST_TIMEOUT);
       return;
    }
 
-   UINT32 rcc = response->GetVariableLong(VID_RCC);
+   UINT32 rcc = response->getFieldAsUInt32(VID_RCC);
    if (rcc == ERR_SUCCESS)
    {
-      masterResponse->SetVariable(VID_RCC, ERR_SUCCESS);
+      masterResponse->setField(VID_RCC, ERR_SUCCESS);
       size_t imageSize;
       BYTE *image = response->getBinaryFieldPtr(VID_FILE_DATA, &imageSize);
       if (image != NULL)
-         masterResponse->SetVariable(VID_FILE_DATA, image, (UINT32)imageSize);
+         masterResponse->setField(VID_FILE_DATA, image, (UINT32)imageSize);
    }
    else
    {
-      masterResponse->SetVariable(VID_RCC, rcc);
+      masterResponse->setField(VID_RCC, rcc);
    }
 
    delete response;
index 616f578..519ec22 100644 (file)
@@ -35,10 +35,10 @@ static void ProcessStorageDiscoveryRequest(HPIPE hPipe)
        while(true)
        {
       MessageReceiverResult result;
-               CSCPMessage *msg = receiver.readMessage(INFINITE, &result);
+               NXCPMessage *msg = receiver.readMessage(INFINITE, &result);
                if (msg == NULL)
                        break;
-               AgentWriteDebugLog(6, _T("ProcessStorageDiscoveryRequest: received message %s"), NXCPMessageCodeName(msg->GetCode(), buffer));
+               AgentWriteDebugLog(6, _T("ProcessStorageDiscoveryRequest: received message %s"), NXCPMessageCodeName(msg->getCode(), buffer));
                delete msg;
        }
        AgentWriteDebugLog(5, _T("ProcessStorageDiscoveryRequest: connection closed"));
index 936ba68..a97c311 100644 (file)
  * Externals
  */
 void UnregisterSession(UINT32 dwIndex);
-void ProxySNMPRequest(CSCPMessage *pRequest, CSCPMessage *pResponse);
-UINT32 DeployPolicy(CommSession *session, CSCPMessage *request);
-UINT32 UninstallPolicy(CommSession *session, CSCPMessage *request);
-UINT32 GetPolicyInventory(CommSession *session, CSCPMessage *msg);
+void ProxySNMPRequest(NXCPMessage *pRequest, NXCPMessage *pResponse);
+UINT32 DeployPolicy(CommSession *session, NXCPMessage *request);
+UINT32 UninstallPolicy(CommSession *session, NXCPMessage *request);
+UINT32 GetPolicyInventory(CommSession *session, NXCPMessage *msg);
 
 /**
  * Constants
@@ -93,7 +93,7 @@ CommSession::CommSession(SOCKET hSocket, const InetAddress &serverAddr, bool mas
    m_hSocket = hSocket;
    m_hProxySocket = -1;
    m_dwIndex = INVALID_INDEX;
-   m_pMsgBuffer = (CSCP_BUFFER *)malloc(sizeof(CSCP_BUFFER));
+   m_pMsgBuffer = (NXCP_BUFFER *)malloc(sizeof(NXCP_BUFFER));
    m_hWriteThread = INVALID_THREAD_HANDLE;
    m_hProcessingThread = INVALID_THREAD_HANDLE;
    m_serverAddr = serverAddr;
@@ -153,17 +153,17 @@ void CommSession::disconnect()
  */
 void CommSession::readThread()
 {
-   CSCP_MESSAGE *pRawMsg;
-   CSCPMessage *pMsg;
+   NXCP_MESSAGE *pRawMsg;
+   NXCPMessage *pMsg;
    BYTE *pDecryptionBuffer = NULL;
    int iErr;
    TCHAR szBuffer[256];  //
-   WORD wFlags;
+   WORD flags;
 
    // Initialize raw message receiving function
    RecvNXCPMessage(0, NULL, m_pMsgBuffer, 0, NULL, NULL, 0);
 
-   pRawMsg = (CSCP_MESSAGE *)malloc(RAW_MSG_SIZE);
+   pRawMsg = (NXCP_MESSAGE *)malloc(RAW_MSG_SIZE);
 #ifdef _WITH_ENCRYPTION
    pDecryptionBuffer = (BYTE *)malloc(RAW_MSG_SIZE);
 #endif
@@ -197,9 +197,9 @@ void CommSession::readThread()
       }
 
       // Check that actual received packet size is equal to encoded in packet
-      if ((int)ntohl(pRawMsg->dwSize) != iErr)
+      if ((int)ntohl(pRawMsg->size) != iErr)
       {
-         DebugPrintf(m_dwIndex, 5, _T("Actual message size doesn't match wSize value (%d,%d)"), iErr, ntohl(pRawMsg->dwSize));
+         DebugPrintf(m_dwIndex, 5, _T("Actual message size doesn't match wSize value (%d,%d)"), iErr, ntohl(pRawMsg->size));
          continue;   // Bad packet, wait for next
       }
 
@@ -208,7 +208,7 @@ void CommSession::readThread()
 
       if (g_debugLevel >= 8)
       {
-         String msgDump = CSCPMessage::dump(pRawMsg, NXCP_VERSION);
+         String msgDump = NXCPMessage::dump(pRawMsg, NXCP_VERSION);
          DebugPrintf(m_dwIndex, 8, _T("Message dump:\n%s"), (const TCHAR *)msgDump);
       }
 
@@ -219,79 +219,79 @@ void CommSession::readThread()
       }
       else
       {
-         wFlags = ntohs(pRawMsg->wFlags);
-         if (wFlags & MF_BINARY)
+         flags = ntohs(pRawMsg->flags);
+         if (flags & MF_BINARY)
          {
             // Convert message header to host format
-            pRawMsg->dwId = ntohl(pRawMsg->dwId);
-            pRawMsg->wCode = ntohs(pRawMsg->wCode);
-            pRawMsg->dwNumVars = ntohl(pRawMsg->dwNumVars);
-            DebugPrintf(m_dwIndex, 6, _T("Received raw message %s"), NXCPMessageCodeName(pRawMsg->wCode, szBuffer));
+            pRawMsg->id = ntohl(pRawMsg->id);
+            pRawMsg->code = ntohs(pRawMsg->code);
+            pRawMsg->numFields = ntohl(pRawMsg->numFields);
+            DebugPrintf(m_dwIndex, 6, _T("Received raw message %s"), NXCPMessageCodeName(pRawMsg->code, szBuffer));
 
-            if (pRawMsg->wCode == CMD_FILE_DATA)
+            if (pRawMsg->code == CMD_FILE_DATA)
             {
-               if ((m_hCurrFile != -1) && (m_dwFileRqId == pRawMsg->dwId))
+               if ((m_hCurrFile != -1) && (m_dwFileRqId == pRawMsg->id))
                {
-                  if (write(m_hCurrFile, pRawMsg->df, pRawMsg->dwNumVars) == (int)pRawMsg->dwNumVars)
+                  if (write(m_hCurrFile, pRawMsg->fields, pRawMsg->numFields) == (int)pRawMsg->numFields)
                   {
-                     if (wFlags & MF_END_OF_FILE)
+                     if (flags & MF_END_OF_FILE)
                      {
-                        CSCPMessage msg;
+                        NXCPMessage msg;
 
                         close(m_hCurrFile);
                         m_hCurrFile = -1;
 
-                        msg.SetCode(CMD_REQUEST_COMPLETED);
-                        msg.SetId(pRawMsg->dwId);
-                        msg.SetVariable(VID_RCC, ERR_SUCCESS);
+                        msg.setCode(CMD_REQUEST_COMPLETED);
+                        msg.setId(pRawMsg->id);
+                        msg.setField(VID_RCC, ERR_SUCCESS);
                         sendMessage(&msg);
                      }
                   }
                   else
                   {
                      // I/O error
-                     CSCPMessage msg;
+                     NXCPMessage msg;
 
                      close(m_hCurrFile);
                      m_hCurrFile = -1;
 
-                     msg.SetCode(CMD_REQUEST_COMPLETED);
-                     msg.SetId(pRawMsg->dwId);
-                     msg.SetVariable(VID_RCC, ERR_IO_FAILURE);
+                     msg.setCode(CMD_REQUEST_COMPLETED);
+                     msg.setId(pRawMsg->id);
+                     msg.setField(VID_RCC, ERR_IO_FAILURE);
                      sendMessage(&msg);
                   }
                }
             }
          }
-         else if (wFlags & MF_CONTROL)
+         else if (flags & MF_CONTROL)
          {
             // Convert message header to host format
-            pRawMsg->dwId = ntohl(pRawMsg->dwId);
-            pRawMsg->wCode = ntohs(pRawMsg->wCode);
-            pRawMsg->dwNumVars = ntohl(pRawMsg->dwNumVars);
-            DebugPrintf(m_dwIndex, 6, _T("Received control message %s"), NXCPMessageCodeName(pRawMsg->wCode, szBuffer));
+            pRawMsg->id = ntohl(pRawMsg->id);
+            pRawMsg->code = ntohs(pRawMsg->code);
+            pRawMsg->numFields = ntohl(pRawMsg->numFields);
+            DebugPrintf(m_dwIndex, 6, _T("Received control message %s"), NXCPMessageCodeName(pRawMsg->code, szBuffer));
 
-            if (pRawMsg->wCode == CMD_GET_NXCP_CAPS)
+            if (pRawMsg->code == CMD_GET_NXCP_CAPS)
             {
-               CSCP_MESSAGE *pMsg = (CSCP_MESSAGE *)malloc(NXCP_HEADER_SIZE);
-               pMsg->dwId = htonl(pRawMsg->dwId);
-               pMsg->wCode = htons((WORD)CMD_NXCP_CAPS);
-               pMsg->wFlags = htons(MF_CONTROL);
-               pMsg->dwNumVars = htonl(NXCP_VERSION << 24);
-               pMsg->dwSize = htonl(NXCP_HEADER_SIZE);
+               NXCP_MESSAGE *pMsg = (NXCP_MESSAGE *)malloc(NXCP_HEADER_SIZE);
+               pMsg->id = htonl(pRawMsg->id);
+               pMsg->code = htons((WORD)CMD_NXCP_CAPS);
+               pMsg->flags = htons(MF_CONTROL);
+               pMsg->numFields = htonl(NXCP_VERSION << 24);
+               pMsg->size = htonl(NXCP_HEADER_SIZE);
                sendRawMessage(pMsg, m_pCtx);
             }
          }
          else
          {
             // Create message object from raw message
-            pMsg = new CSCPMessage(pRawMsg);
-            if (pMsg->GetCode() == CMD_REQUEST_SESSION_KEY)
+            pMsg = new NXCPMessage(pRawMsg);
+            if (pMsg->getCode() == CMD_REQUEST_SESSION_KEY)
             {
-               DebugPrintf(m_dwIndex, 6, _T("Received message %s"), NXCPMessageCodeName(pMsg->GetCode(), szBuffer));
+               DebugPrintf(m_dwIndex, 6, _T("Received message %s"), NXCPMessageCodeName(pMsg->getCode(), szBuffer));
                if (m_pCtx == NULL)
                {
-                  CSCPMessage *pResponse;
+                  NXCPMessage *pResponse;
 
                   SetupEncryptionContext(pMsg, &m_pCtx, &pResponse, NULL, NXCP_VERSION);
                   sendMessage(pResponse);
@@ -331,18 +331,18 @@ void CommSession::readThread()
 /**
  * Send prepared raw message over the network and destroy it
  */
-BOOL CommSession::sendRawMessage(CSCP_MESSAGE *pMsg, NXCPEncryptionContext *pCtx)
+BOOL CommSession::sendRawMessage(NXCP_MESSAGE *pMsg, NXCPEncryptionContext *pCtx)
 {
    BOOL bResult = TRUE;
    TCHAR szBuffer[128];
 
-   DebugPrintf(m_dwIndex, 6, _T("Sending message %s (size %d)"), NXCPMessageCodeName(ntohs(pMsg->wCode), szBuffer), ntohl(pMsg->dwSize));
+   DebugPrintf(m_dwIndex, 6, _T("Sending message %s (size %d)"), NXCPMessageCodeName(ntohs(pMsg->code), szBuffer), ntohl(pMsg->size));
    if ((pCtx != NULL) && (pCtx != PROXY_ENCRYPTION_CTX))
    {
-      NXCP_ENCRYPTED_MESSAGE *enMsg = CSCPEncryptMessage(pCtx, pMsg);
+      NXCP_ENCRYPTED_MESSAGE *enMsg = pCtx->encryptMessage(pMsg);
       if (enMsg != NULL)
       {
-         if (SendEx(m_hSocket, (const char *)enMsg, ntohl(enMsg->dwSize), 0, m_socketWriteMutex) <= 0)
+         if (SendEx(m_hSocket, (const char *)enMsg, ntohl(enMsg->size), 0, m_socketWriteMutex) <= 0)
          {
             bResult = FALSE;
          }
@@ -351,13 +351,13 @@ BOOL CommSession::sendRawMessage(CSCP_MESSAGE *pMsg, NXCPEncryptionContext *pCtx
    }
    else
    {
-      if (SendEx(m_hSocket, (const char *)pMsg, ntohl(pMsg->dwSize), 0, m_socketWriteMutex) <= 0)
+      if (SendEx(m_hSocket, (const char *)pMsg, ntohl(pMsg->size), 0, m_socketWriteMutex) <= 0)
       {
          bResult = FALSE;
       }
    }
        if (!bResult)
-          DebugPrintf(m_dwIndex, 6, _T("CommSession::SendRawMessage() for %s (size %d) failed"), NXCPMessageCodeName(ntohs(pMsg->wCode), szBuffer), ntohl(pMsg->dwSize));
+          DebugPrintf(m_dwIndex, 6, _T("CommSession::SendRawMessage() for %s (size %d) failed"), NXCPMessageCodeName(ntohs(pMsg->code), szBuffer), ntohl(pMsg->size));
    free(pMsg);
    return bResult;
 }
@@ -367,11 +367,11 @@ BOOL CommSession::sendRawMessage(CSCP_MESSAGE *pMsg, NXCPEncryptionContext *pCtx
  */
 void CommSession::writeThread()
 {
-   CSCP_MESSAGE *pMsg;
+   NXCP_MESSAGE *pMsg;
 
    while(1)
    {
-      pMsg = (CSCP_MESSAGE *)m_pSendQueue->GetOrBlock();
+      pMsg = (NXCP_MESSAGE *)m_pSendQueue->GetOrBlock();
       if (pMsg == INVALID_POINTER_VALUE)    // Session termination indicator
          break;
 
@@ -386,33 +386,33 @@ void CommSession::writeThread()
  */
 void CommSession::processingThread()
 {
-   CSCPMessage *pMsg;
+   NXCPMessage *pMsg;
    TCHAR szBuffer[128];
-   CSCPMessage msg;
+   NXCPMessage msg;
    UINT32 dwCommand, dwRet;
 
    while(1)
    {
-      pMsg = (CSCPMessage *)m_pMessageQueue->GetOrBlock();
+      pMsg = (NXCPMessage *)m_pMessageQueue->GetOrBlock();
       if (pMsg == INVALID_POINTER_VALUE)    // Session termination indicator
          break;
-      dwCommand = pMsg->GetCode();
+      dwCommand = pMsg->getCode();
       DebugPrintf(m_dwIndex, 6, _T("Received message %s"), NXCPMessageCodeName((WORD)dwCommand, szBuffer));
 
       // Prepare response message
-      msg.SetCode(CMD_REQUEST_COMPLETED);
-      msg.SetId(pMsg->GetId());
+      msg.setCode(CMD_REQUEST_COMPLETED);
+      msg.setId(pMsg->getId());
 
       // Check if authentication required
       if ((!m_authenticated) && (dwCommand != CMD_AUTHENTICATE))
       {
                        DebugPrintf(m_dwIndex, 6, _T("Authentication required"));
-         msg.SetVariable(VID_RCC, ERR_AUTH_REQUIRED);
+         msg.setField(VID_RCC, ERR_AUTH_REQUIRED);
       }
       else if ((g_dwFlags & AF_REQUIRE_ENCRYPTION) && (m_pCtx == NULL))
       {
                        DebugPrintf(m_dwIndex, 6, _T("Encryption required"));
-         msg.SetVariable(VID_RCC, ERR_ENCRYPTION_REQUIRED);
+         msg.setField(VID_RCC, ERR_ENCRYPTION_REQUIRED);
       }
       else
       {
@@ -431,7 +431,7 @@ void CommSession::processingThread()
                getTable(pMsg, &msg);
                break;
             case CMD_KEEPALIVE:
-               msg.SetVariable(VID_RCC, ERR_SUCCESS);
+               msg.setField(VID_RCC, ERR_SUCCESS);
                break;
             case CMD_ACTION:
                action(pMsg, &msg);
@@ -440,18 +440,18 @@ void CommSession::processingThread()
                recvFile(pMsg, &msg);
                break;
             case CMD_UPGRADE_AGENT:
-               msg.SetVariable(VID_RCC, upgrade(pMsg));
+               msg.setField(VID_RCC, upgrade(pMsg));
                break;
             case CMD_GET_PARAMETER_LIST:
-               msg.SetVariable(VID_RCC, ERR_SUCCESS);
+               msg.setField(VID_RCC, ERR_SUCCESS);
                GetParameterList(&msg);
                break;
             case CMD_GET_ENUM_LIST:
-               msg.SetVariable(VID_RCC, ERR_SUCCESS);
+               msg.setField(VID_RCC, ERR_SUCCESS);
                GetEnumList(&msg);
                break;
             case CMD_GET_TABLE_LIST:
-               msg.SetVariable(VID_RCC, ERR_SUCCESS);
+               msg.setField(VID_RCC, ERR_SUCCESS);
                GetTableList(&msg);
                break;
             case CMD_GET_AGENT_CONFIG:
@@ -467,17 +467,17 @@ void CommSession::processingThread()
                // by SetupProxyConnection() in case of success.
                if (dwRet == ERR_SUCCESS)
                   goto stop_processing;
-               msg.SetVariable(VID_RCC, dwRet);
+               msg.setField(VID_RCC, dwRet);
                break;
             case CMD_ENABLE_AGENT_TRAPS:
                if (m_masterServer)
                {
                   m_acceptTraps = true;
-                  msg.SetVariable(VID_RCC, ERR_SUCCESS);
+                  msg.setField(VID_RCC, ERR_SUCCESS);
                }
                else
                {
-                  msg.SetVariable(VID_RCC, ERR_ACCESS_DENIED);
+                  msg.setField(VID_RCC, ERR_ACCESS_DENIED);
                }
                break;
                                case CMD_SNMP_REQUEST:
@@ -487,44 +487,44 @@ void CommSession::processingThread()
                                        }
                                        else
                                        {
-                  msg.SetVariable(VID_RCC, ERR_ACCESS_DENIED);
+                  msg.setField(VID_RCC, ERR_ACCESS_DENIED);
                                        }
                                        break;
                                case CMD_DEPLOY_AGENT_POLICY:
                                        if (m_masterServer)
                                        {
-                                               msg.SetVariable(VID_RCC, DeployPolicy(this, pMsg));
+                                               msg.setField(VID_RCC, DeployPolicy(this, pMsg));
                                        }
                                        else
                                        {
-                  msg.SetVariable(VID_RCC, ERR_ACCESS_DENIED);
+                  msg.setField(VID_RCC, ERR_ACCESS_DENIED);
                                        }
                                        break;
                                case CMD_UNINSTALL_AGENT_POLICY:
                                        if (m_masterServer)
                                        {
-                                               msg.SetVariable(VID_RCC, UninstallPolicy(this, pMsg));
+                                               msg.setField(VID_RCC, UninstallPolicy(this, pMsg));
                                        }
                                        else
                                        {
-                  msg.SetVariable(VID_RCC, ERR_ACCESS_DENIED);
+                  msg.setField(VID_RCC, ERR_ACCESS_DENIED);
                                        }
                                        break;
                                case CMD_GET_POLICY_INVENTORY:
                                        if (m_masterServer)
                                        {
-                                               msg.SetVariable(VID_RCC, GetPolicyInventory(this, &msg));
+                                               msg.setField(VID_RCC, GetPolicyInventory(this, &msg));
                                        }
                                        else
                                        {
-                  msg.SetVariable(VID_RCC, ERR_ACCESS_DENIED);
+                  msg.setField(VID_RCC, ERR_ACCESS_DENIED);
                                        }
                                        break;
             case CMD_TAKE_SCREENSHOT:
                                        if (m_controlServer)
                                        {
                   TCHAR sessionName[256];
-                  pMsg->GetVariableStr(VID_NAME, sessionName, 256);
+                  pMsg->getFieldAsString(VID_NAME, sessionName, 256);
                   DebugPrintf(m_dwIndex, 6, _T("Take snapshot from session \"%s\""), sessionName);
                   SessionAgentConnector *conn = AcquireSessionAgentConnector(sessionName);
                   if (conn != NULL)
@@ -535,18 +535,18 @@ void CommSession::processingThread()
                   }
                   else
                   {
-                     msg.SetVariable(VID_RCC, ERR_NO_SESSION_AGENT);
+                     msg.setField(VID_RCC, ERR_NO_SESSION_AGENT);
                   }
                                        }
                                        else
                                        {
-                  msg.SetVariable(VID_RCC, ERR_ACCESS_DENIED);
+                  msg.setField(VID_RCC, ERR_ACCESS_DENIED);
                                        }
                                        break;
             default:
                // Attempt to process unknown command by subagents
                if (!ProcessCmdBySubAgent(dwCommand, pMsg, &msg, this))
-                  msg.SetVariable(VID_RCC, ERR_UNKNOWN_COMMAND);
+                  msg.setField(VID_RCC, ERR_UNKNOWN_COMMAND);
                break;
          }
       }
@@ -554,7 +554,7 @@ void CommSession::processingThread()
 
       // Send response
       sendMessage(&msg);
-      msg.deleteAllVariables();
+      msg.deleteAllFields();
    }
 
 stop_processing:
@@ -564,12 +564,12 @@ stop_processing:
 /**
  * Authenticate peer
  */
-void CommSession::authenticate(CSCPMessage *pRequest, CSCPMessage *pMsg)
+void CommSession::authenticate(NXCPMessage *pRequest, NXCPMessage *pMsg)
 {
    if (m_authenticated)
    {
       // Already authenticated
-      pMsg->SetVariable(VID_RCC, (g_dwFlags & AF_REQUIRE_AUTH) ? ERR_ALREADY_AUTHENTICATED : ERR_AUTH_NOT_REQUIRED);
+      pMsg->setField(VID_RCC, (g_dwFlags & AF_REQUIRE_AUTH) ? ERR_ALREADY_AUTHENTICATED : ERR_AUTH_NOT_REQUIRED);
    }
    else
    {
@@ -577,24 +577,24 @@ void CommSession::authenticate(CSCPMessage *pRequest, CSCPMessage *pMsg)
       BYTE hash[32];
       WORD wAuthMethod;
 
-      wAuthMethod = pRequest->GetVariableShort(VID_AUTH_METHOD);
+      wAuthMethod = pRequest->getFieldAsUInt16(VID_AUTH_METHOD);
       switch(wAuthMethod)
       {
          case AUTH_PLAINTEXT:
-            pRequest->GetVariableStr(VID_SHARED_SECRET, szSecret, MAX_SECRET_LENGTH);
+            pRequest->getFieldAsString(VID_SHARED_SECRET, szSecret, MAX_SECRET_LENGTH);
             if (!_tcscmp(szSecret, g_szSharedSecret))
             {
                m_authenticated = true;
-               pMsg->SetVariable(VID_RCC, ERR_SUCCESS);
+               pMsg->setField(VID_RCC, ERR_SUCCESS);
             }
             else
             {
                nxlog_write(MSG_AUTH_FAILED, EVENTLOG_WARNING_TYPE, "Is", &m_serverAddr, "PLAIN");
-               pMsg->SetVariable(VID_RCC, ERR_AUTH_FAILED);
+               pMsg->setField(VID_RCC, ERR_AUTH_FAILED);
             }
             break;
          case AUTH_MD5_HASH:
-            pRequest->GetVariableBinary(VID_SHARED_SECRET, (BYTE *)szSecret, MD5_DIGEST_SIZE);
+            pRequest->getFieldAsBinary(VID_SHARED_SECRET, (BYTE *)szSecret, MD5_DIGEST_SIZE);
 #ifdef UNICODE
                                {
                                        char sharedSecret[256];
@@ -608,16 +608,16 @@ void CommSession::authenticate(CSCPMessage *pRequest, CSCPMessage *pMsg)
             if (!memcmp(szSecret, hash, MD5_DIGEST_SIZE))
             {
                m_authenticated = true;
-               pMsg->SetVariable(VID_RCC, ERR_SUCCESS);
+               pMsg->setField(VID_RCC, ERR_SUCCESS);
             }
             else
             {
                nxlog_write(MSG_AUTH_FAILED, EVENTLOG_WARNING_TYPE, "Is", &m_serverAddr, _T("MD5"));
-               pMsg->SetVariable(VID_RCC, ERR_AUTH_FAILED);
+               pMsg->setField(VID_RCC, ERR_AUTH_FAILED);
             }
             break;
          case AUTH_SHA1_HASH:
-            pRequest->GetVariableBinary(VID_SHARED_SECRET, (BYTE *)szSecret, SHA1_DIGEST_SIZE);
+            pRequest->getFieldAsBinary(VID_SHARED_SECRET, (BYTE *)szSecret, SHA1_DIGEST_SIZE);
 #ifdef UNICODE
                                {
                                        char sharedSecret[256];
@@ -631,16 +631,16 @@ void CommSession::authenticate(CSCPMessage *pRequest, CSCPMessage *pMsg)
             if (!memcmp(szSecret, hash, SHA1_DIGEST_SIZE))
             {
                m_authenticated = true;
-               pMsg->SetVariable(VID_RCC, ERR_SUCCESS);
+               pMsg->setField(VID_RCC, ERR_SUCCESS);
             }
             else
             {
                nxlog_write(MSG_AUTH_FAILED, EVENTLOG_WARNING_TYPE, "Is", &m_serverAddr, _T("SHA1"));
-               pMsg->SetVariable(VID_RCC, ERR_AUTH_FAILED);
+               pMsg->setField(VID_RCC, ERR_AUTH_FAILED);
             }
             break;
          default:
-            pMsg->SetVariable(VID_RCC, ERR_NOT_IMPLEMENTED);
+            pMsg->setField(VID_RCC, ERR_NOT_IMPLEMENTED);
             break;
       }
    }
@@ -649,50 +649,50 @@ void CommSession::authenticate(CSCPMessage *pRequest, CSCPMessage *pMsg)
 /**
  * Get parameter's value
  */
-void CommSession::getParameter(CSCPMessage *pRequest, CSCPMessage *pMsg)
+void CommSession::getParameter(NXCPMessage *pRequest, NXCPMessage *pMsg)
 {
    TCHAR szParameter[MAX_PARAM_NAME], szValue[MAX_RESULT_LENGTH];
    UINT32 dwErrorCode;
 
-   pRequest->GetVariableStr(VID_PARAMETER, szParameter, MAX_PARAM_NAME);
+   pRequest->getFieldAsString(VID_PARAMETER, szParameter, MAX_PARAM_NAME);
    dwErrorCode = GetParameterValue(m_dwIndex, szParameter, szValue);
-   pMsg->SetVariable(VID_RCC, dwErrorCode);
+   pMsg->setField(VID_RCC, dwErrorCode);
    if (dwErrorCode == ERR_SUCCESS)
-      pMsg->SetVariable(VID_VALUE, szValue);
+      pMsg->setField(VID_VALUE, szValue);
 }
 
 /**
  * Get list of values
  */
-void CommSession::getList(CSCPMessage *pRequest, CSCPMessage *pMsg)
+void CommSession::getList(NXCPMessage *pRequest, NXCPMessage *pMsg)
 {
    TCHAR szParameter[MAX_PARAM_NAME];    //
 
-   pRequest->GetVariableStr(VID_PARAMETER, szParameter, MAX_PARAM_NAME);
+   pRequest->getFieldAsString(VID_PARAMETER, szParameter, MAX_PARAM_NAME);
 
    StringList value;
    UINT32 dwErrorCode = GetListValue(m_dwIndex, szParameter, &value);
-   pMsg->SetVariable(VID_RCC, dwErrorCode);
+   pMsg->setField(VID_RCC, dwErrorCode);
    if (dwErrorCode == ERR_SUCCESS)
    {
-               pMsg->SetVariable(VID_NUM_STRINGS, (UINT32)value.size());
+               pMsg->setField(VID_NUM_STRINGS, (UINT32)value.size());
                for(int i = 0; i < value.size(); i++)
-                       pMsg->SetVariable(VID_ENUM_VALUE_BASE + i, value.get(i));
+                       pMsg->setField(VID_ENUM_VALUE_BASE + i, value.get(i));
    }
 }
 
 /**
  * Get table
  */
-void CommSession::getTable(CSCPMessage *pRequest, CSCPMessage *pMsg)
+void CommSession::getTable(NXCPMessage *pRequest, NXCPMessage *pMsg)
 {
    TCHAR szParameter[MAX_PARAM_NAME];
 
-   pRequest->GetVariableStr(VID_PARAMETER, szParameter, MAX_PARAM_NAME);
+   pRequest->getFieldAsString(VID_PARAMETER, szParameter, MAX_PARAM_NAME);
 
    Table value;
    UINT32 dwErrorCode = GetTableValue(m_dwIndex, szParameter, &value);
-   pMsg->SetVariable(VID_RCC, dwErrorCode);
+   pMsg->setField(VID_RCC, dwErrorCode);
    if (dwErrorCode == ERR_SUCCESS)
    {
                value.fillMessage(*pMsg, 0, -1);        // no row limit
@@ -702,58 +702,58 @@ void CommSession::getTable(CSCPMessage *pRequest, CSCPMessage *pMsg)
 /**
  * Perform action on request
  */
-void CommSession::action(CSCPMessage *pRequest, CSCPMessage *pMsg)
+void CommSession::action(NXCPMessage *pRequest, NXCPMessage *pMsg)
 {
    if ((g_dwFlags & AF_ENABLE_ACTIONS) && m_controlServer)
    {
       // Get action name and arguments
       TCHAR action[MAX_PARAM_NAME];
-      pRequest->GetVariableStr(VID_ACTION_NAME, action, MAX_PARAM_NAME);
+      pRequest->getFieldAsString(VID_ACTION_NAME, action, MAX_PARAM_NAME);
 
       int numArgs = pRequest->getFieldAsInt32(VID_NUM_ARGS);
       StringList *args = new StringList;
       for(int i = 0; i < numArgs; i++)
-                       args->addPreallocated(pRequest->GetVariableStr(VID_ACTION_ARG_BASE + i));
+                       args->addPreallocated(pRequest->getFieldAsString(VID_ACTION_ARG_BASE + i));
 
       // Execute action
       if (pRequest->getFieldAsBoolean(VID_RECEIVE_OUTPUT))
       {
-         UINT32 rcc = ExecActionWithOutput(this, pRequest->GetId(), action, args);
-         pMsg->SetVariable(VID_RCC, rcc);
+         UINT32 rcc = ExecActionWithOutput(this, pRequest->getId(), action, args);
+         pMsg->setField(VID_RCC, rcc);
       }
       else
       {
          UINT32 rcc = ExecAction(action, args);
-         pMsg->SetVariable(VID_RCC, rcc);
+         pMsg->setField(VID_RCC, rcc);
          delete args;
       }
    }
    else
    {
-      pMsg->SetVariable(VID_RCC, ERR_ACCESS_DENIED);
+      pMsg->setField(VID_RCC, ERR_ACCESS_DENIED);
    }
 }
 
 /**
  * Prepare for receiving file
  */
-void CommSession::recvFile(CSCPMessage *pRequest, CSCPMessage *pMsg)
+void CommSession::recvFile(NXCPMessage *pRequest, NXCPMessage *pMsg)
 {
        TCHAR szFileName[MAX_PATH], szFullPath[MAX_PATH];
 
        if (m_masterServer)
        {
                szFileName[0] = 0;
-               pRequest->GetVariableStr(VID_FILE_NAME, szFileName, MAX_PATH);
+               pRequest->getFieldAsString(VID_FILE_NAME, szFileName, MAX_PATH);
                DebugPrintf(m_dwIndex, 5, _T("CommSession::recvFile(): Preparing for receiving file \"%s\""), szFileName);
       BuildFullPath(szFileName, szFullPath);
 
                // Check if for some reason we have already opened file
-      pMsg->SetVariable(VID_RCC, openFile(szFullPath, pRequest->GetId()));
+      pMsg->setField(VID_RCC, openFile(szFullPath, pRequest->getId()));
        }
        else
        {
-               pMsg->SetVariable(VID_RCC, ERR_ACCESS_DENIED);
+               pMsg->setField(VID_RCC, ERR_ACCESS_DENIED);
        }
 }
 
@@ -800,14 +800,14 @@ bool CommSession::sendFile(UINT32 requestId, const TCHAR *file, long offset)
 /**
  * Upgrade agent from package in the file store
  */
-UINT32 CommSession::upgrade(CSCPMessage *pRequest)
+UINT32 CommSession::upgrade(NXCPMessage *pRequest)
 {
    if (m_masterServer)
    {
       TCHAR szPkgName[MAX_PATH], szFullPath[MAX_PATH];
 
       szPkgName[0] = 0;
-      pRequest->GetVariableStr(VID_FILE_NAME, szPkgName, MAX_PATH);
+      pRequest->getFieldAsString(VID_FILE_NAME, szPkgName, MAX_PATH);
       BuildFullPath(szPkgName, szFullPath);
 
       //Create line in registry file with upgrade file name to delete it after system start
@@ -826,75 +826,75 @@ UINT32 CommSession::upgrade(CSCPMessage *pRequest)
 /**
  * Get agent's configuration file
  */
-void CommSession::getConfig(CSCPMessage *pMsg)
+void CommSession::getConfig(NXCPMessage *pMsg)
 {
    if (m_masterServer)
    {
-      pMsg->SetVariable(VID_RCC,
+      pMsg->setField(VID_RCC,
          pMsg->setFieldFromFile(VID_CONFIG_FILE, g_szConfigFile) ? ERR_SUCCESS : ERR_IO_FAILURE);
    }
    else
    {
-      pMsg->SetVariable(VID_RCC, ERR_ACCESS_DENIED);
+      pMsg->setField(VID_RCC, ERR_ACCESS_DENIED);
    }
 }
 
 /**
  * Update agent's configuration file
  */
-void CommSession::updateConfig(CSCPMessage *pRequest, CSCPMessage *pMsg)
+void CommSession::updateConfig(NXCPMessage *pRequest, NXCPMessage *pMsg)
 {
    if (m_masterServer)
    {
       BYTE *pConfig;
       int hFile;
-      UINT32 dwSize;
+      UINT32 size;
 
       if (pRequest->isFieldExist(VID_CONFIG_FILE))
       {
-         dwSize = pRequest->GetVariableBinary(VID_CONFIG_FILE, NULL, 0);
-         pConfig = (BYTE *)malloc(dwSize);
-         pRequest->GetVariableBinary(VID_CONFIG_FILE, pConfig, dwSize);
+         size = pRequest->getFieldAsBinary(VID_CONFIG_FILE, NULL, 0);
+         pConfig = (BYTE *)malloc(size);
+         pRequest->getFieldAsBinary(VID_CONFIG_FILE, pConfig, size);
          hFile = _topen(g_szConfigFile, O_CREAT | O_TRUNC | O_WRONLY, 0644);
          if (hFile != -1)
          {
-            if (dwSize > 0)
+            if (size > 0)
             {
-               for(UINT32 i = 0; i < dwSize - 1; i++)
+               for(UINT32 i = 0; i < size - 1; i++)
                   if (pConfig[i] == 0x0D)
                   {
-                     dwSize--;
-                     memmove(&pConfig[i], &pConfig[i + 1], dwSize - i);
+                     size--;
+                     memmove(&pConfig[i], &pConfig[i + 1], size - i);
                                                        i--;
                   }
             }
-            write(hFile, pConfig, dwSize);
+            write(hFile, pConfig, size);
             close(hFile);
-            pMsg->SetVariable(VID_RCC, ERR_SUCCESS);
+            pMsg->setField(VID_RCC, ERR_SUCCESS);
          }
          else
          {
                                DebugPrintf(m_dwIndex, 2, _T("CommSession::updateConfig(): Error opening file \"%s\" for writing (%s)"),
                         g_szConfigFile, _tcserror(errno));
-            pMsg->SetVariable(VID_RCC, ERR_FILE_OPEN_ERROR);
+            pMsg->setField(VID_RCC, ERR_FILE_OPEN_ERROR);
          }
          free(pConfig);
       }
       else
       {
-         pMsg->SetVariable(VID_RCC, ERR_MALFORMED_COMMAND);
+         pMsg->setField(VID_RCC, ERR_MALFORMED_COMMAND);
       }
    }
    else
    {
-      pMsg->SetVariable(VID_RCC, ERR_ACCESS_DENIED);
+      pMsg->setField(VID_RCC, ERR_ACCESS_DENIED);
    }
 }
 
 /**
  * Setup proxy connection
  */
-UINT32 CommSession::setupProxyConnection(CSCPMessage *pRequest)
+UINT32 CommSession::setupProxyConnection(NXCPMessage *pRequest)
 {
    UINT32 dwResult, dwAddr;
    WORD wPort;
@@ -904,8 +904,8 @@ UINT32 CommSession::setupProxyConnection(CSCPMessage *pRequest)
 
    if (m_masterServer && (g_dwFlags & AF_ENABLE_PROXY))
    {
-      dwAddr = pRequest->GetVariableLong(VID_IP_ADDRESS);
-      wPort = pRequest->GetVariableShort(VID_AGENT_PORT);
+      dwAddr = pRequest->getFieldAsUInt32(VID_IP_ADDRESS);
+      wPort = pRequest->getFieldAsUInt16(VID_AGENT_PORT);
       m_hProxySocket = socket(AF_INET, SOCK_STREAM, 0);
       if (m_hProxySocket != INVALID_SOCKET)
       {
@@ -916,8 +916,8 @@ UINT32 CommSession::setupProxyConnection(CSCPMessage *pRequest)
          sa.sin_port = htons(wPort);
          if (connect(m_hProxySocket, (struct sockaddr *)&sa, sizeof(sa)) != -1)
          {
-            CSCPMessage msg;
-            CSCP_MESSAGE *pRawMsg;
+            NXCPMessage msg;
+            NXCP_MESSAGE *pRawMsg;
 
             // Stop writing thread
             m_pSendQueue->Put(INVALID_POINTER_VALUE);
@@ -937,9 +937,9 @@ UINT32 CommSession::setupProxyConnection(CSCPMessage *pRequest)
             // We cannot use sendMessage() and writing thread, because
             // encryption context already overriden, and writing thread
             // already stopped
-            msg.SetCode(CMD_REQUEST_COMPLETED);
-            msg.SetId(pRequest->GetId());
-            msg.SetVariable(VID_RCC, RCC_SUCCESS);
+            msg.setCode(CMD_REQUEST_COMPLETED);
+            msg.setId(pRequest->getId());
+            msg.setField(VID_RCC, RCC_SUCCESS);
             pRawMsg = msg.createMessage();
             sendRawMessage(pRawMsg, pSavedCtx);
                                if (pSavedCtx != NULL)
index 05d5c02..0f10c37 100644 (file)
@@ -87,7 +87,7 @@ static BOOL ReadPDU(SOCKET hSocket, BYTE *pdu, UINT32 *pdwSize)
 /**
  * Send SNMP request to target, receive response, and send it to server
  */
-void ProxySNMPRequest(CSCPMessage *pRequest, CSCPMessage *pResponse)
+void ProxySNMPRequest(NXCPMessage *pRequest, NXCPMessage *pResponse)
 {
        BYTE *pduIn, *pduOut;
        UINT32 dwSizeIn, dwSizeOut;
@@ -95,21 +95,21 @@ void ProxySNMPRequest(CSCPMessage *pRequest, CSCPMessage *pResponse)
        int nRetries;
        struct sockaddr_in addr;
 
-       dwSizeIn = pRequest->GetVariableLong(VID_PDU_SIZE);
+       dwSizeIn = pRequest->getFieldAsUInt32(VID_PDU_SIZE);
        if (dwSizeIn > 0)
        {
                pduIn = (BYTE *)malloc(dwSizeIn);
                if (pduIn != NULL)
                {
-                       pRequest->GetVariableBinary(VID_PDU, pduIn, dwSizeIn);
+                       pRequest->getFieldAsBinary(VID_PDU, pduIn, dwSizeIn);
 
                        hSocket = socket(AF_INET, SOCK_DGRAM, 0);
                        if (hSocket != INVALID_SOCKET)
                        {
                                memset(&addr, 0, sizeof(struct sockaddr_in));
                                addr.sin_family = AF_INET;
-                               addr.sin_addr.s_addr = htonl(pRequest->GetVariableLong(VID_IP_ADDRESS));
-                               addr.sin_port = htons(pRequest->GetVariableShort(VID_PORT));
+                               addr.sin_addr.s_addr = htonl(pRequest->getFieldAsUInt32(VID_IP_ADDRESS));
+                               addr.sin_port = htons(pRequest->getFieldAsUInt16(VID_PORT));
                                if (connect(hSocket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) != -1)
                                {
                                        pduOut = (BYTE *)malloc(SNMP_BUFFER_SIZE);
@@ -121,39 +121,39 @@ void ProxySNMPRequest(CSCPMessage *pRequest, CSCPMessage *pResponse)
                                                        {
                                                                if (ReadPDU(hSocket, pduOut, &dwSizeOut))
                                                                {
-                                                                       pResponse->SetVariable(VID_PDU_SIZE, dwSizeOut);
-                                                                       pResponse->SetVariable(VID_PDU, pduOut, dwSizeOut);
+                                                                       pResponse->setField(VID_PDU_SIZE, dwSizeOut);
+                                                                       pResponse->setField(VID_PDU, pduOut, dwSizeOut);
                                                                        break;
                                                                }
                                                        }
                                                }
                                                free(pduOut);
-                                               pResponse->SetVariable(VID_RCC, (nRetries == 3) ? ERR_REQUEST_TIMEOUT : ERR_SUCCESS);
+                                               pResponse->setField(VID_RCC, (nRetries == 3) ? ERR_REQUEST_TIMEOUT : ERR_SUCCESS);
                                        }
                                        else
                                        {
-                                               pResponse->SetVariable(VID_RCC, ERR_OUT_OF_RESOURCES);
+                                               pResponse->setField(VID_RCC, ERR_OUT_OF_RESOURCES);
                                        }
                                }
                                else
                                {
-                                       pResponse->SetVariable(VID_RCC, ERR_SOCKET_ERROR);
+                                       pResponse->setField(VID_RCC, ERR_SOCKET_ERROR);
                                }
                                closesocket(hSocket);
                        }
                        else
                        {
-                               pResponse->SetVariable(VID_RCC, ERR_SOCKET_ERROR);
+                               pResponse->setField(VID_RCC, ERR_SOCKET_ERROR);
                        }
                        free(pduIn);
                }
                else
                {
-                       pResponse->SetVariable(VID_RCC, ERR_OUT_OF_RESOURCES);
+                       pResponse->setField(VID_RCC, ERR_OUT_OF_RESOURCES);
                }
        }
        else
        {
-               pResponse->SetVariable(VID_RCC, ERR_MALFORMED_COMMAND);
+               pResponse->setField(VID_RCC, ERR_MALFORMED_COMMAND);
        }
 }
index d886a40..89f0a94 100644 (file)
@@ -169,13 +169,13 @@ THREAD_RESULT THREAD_CALL SNMPTrapSender(void *pArg)
       DebugPrintf(INVALID_INDEX, 1, _T("Got trap from queue"));
       bool sent = false;
 
-      CSCPMessage *msg = new CSCPMessage();
-      msg->SetCode(CMD_SNMP_TRAP);
-      msg->SetId(GenerateMessageId());
-      msg->SetVariable(VID_IP_ADDRESS, pdu->ipAddr);
-      msg->SetVariable(VID_PORT, pdu->port);
-      msg->SetVariable(VID_PDU_SIZE, pdu->lenght);
-      msg->SetVariable(VID_PDU, pdu->rawMessage, pdu->lenght);
+      NXCPMessage *msg = new NXCPMessage();
+      msg->setCode(CMD_SNMP_TRAP);
+      msg->setId(GenerateMessageId());
+      msg->setField(VID_IP_ADDRESS, pdu->ipAddr);
+      msg->setField(VID_PORT, pdu->port);
+      msg->setField(VID_PDU_SIZE, pdu->lenght);
+      msg->setField(VID_PDU, pdu->rawMessage, pdu->lenght);
 
       if (g_dwFlags & AF_SUBAGENT_LOADER)
       {
@@ -184,7 +184,7 @@ THREAD_RESULT THREAD_CALL SNMPTrapSender(void *pArg)
       else
       {
          MutexLock(g_hSessionListAccess);
-         for(int i = 0; i < g_dwMaxSessions; i++)
+         for(UINT32 i = 0; i < g_dwMaxSessions; i++)
          {
             if (g_pSessionList[i] != NULL)
             {
index 49ba4ea..92c2f25 100644 (file)
@@ -321,7 +321,7 @@ LONG H_IsSubagentLoaded(const TCHAR *pszCmd, const TCHAR *pArg, TCHAR *pValue)
 /**
  * Process unknown command by subagents
  */
-BOOL ProcessCmdBySubAgent(UINT32 dwCommand, CSCPMessage *pRequest, CSCPMessage *pResponse, AbstractCommSession *session)
+BOOL ProcessCmdBySubAgent(UINT32 dwCommand, NXCPMessage *pRequest, NXCPMessage *pResponse, AbstractCommSession *session)
 {
    BOOL bResult = FALSE;
    UINT32 i;
index eab0112..f0ea2c6 100644 (file)
@@ -37,7 +37,7 @@ static time_t s_lastTrapTime = 0;
  */
 THREAD_RESULT THREAD_CALL TrapSender(void *pArg)
 {
-   CSCP_MESSAGE *pMsg;
+   NXCP_MESSAGE *pMsg;
    UINT32 i;
    bool trapSent;
 
@@ -45,7 +45,7 @@ THREAD_RESULT THREAD_CALL TrapSender(void *pArg)
        s_trapId = (QWORD)time(NULL) << 32;
    while(1)
    {
-      pMsg = (CSCP_MESSAGE *)s_trapQueue->GetOrBlock();
+      pMsg = (NXCP_MESSAGE *)s_trapQueue->GetOrBlock();
       if (pMsg == INVALID_POINTER_VALUE)
          break;
 
@@ -99,7 +99,7 @@ void ShutdownTrapSender()
 void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, int iNumArgs, TCHAR **ppArgList)
 {
    int i;
-   CSCPMessage msg;
+   NXCPMessage msg;
 
        DebugPrintf(INVALID_INDEX, 5, _T("SendTrap(): event_code=%d, event_name=%s, num_args=%d, arg[0]=\"%s\" arg[1]=\"%s\" arg[2]=\"%s\""),
                    dwEventCode, CHECK_NULL(eventName), iNumArgs, 
@@ -107,15 +107,15 @@ void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, int iNumArgs, TCHAR **
                                        (iNumArgs > 1) ? ppArgList[1] : _T("(null)"),
                                        (iNumArgs > 2) ? ppArgList[2] : _T("(null)"));
 
-   msg.SetCode(CMD_TRAP);
-   msg.SetId(0);
-       msg.SetVariable(VID_TRAP_ID, s_trapId++);
-   msg.SetVariable(VID_EVENT_CODE, dwEventCode);
+   msg.setCode(CMD_TRAP);
+   msg.setId(0);
+       msg.setField(VID_TRAP_ID, s_trapId++);
+   msg.setField(VID_EVENT_CODE, dwEventCode);
        if (eventName != NULL)
-               msg.SetVariable(VID_EVENT_NAME, eventName);
-   msg.SetVariable(VID_NUM_ARGS, (WORD)iNumArgs);
+               msg.setField(VID_EVENT_NAME, eventName);
+   msg.setField(VID_NUM_ARGS, (WORD)iNumArgs);
    for(i = 0; i < iNumArgs; i++)
-      msg.SetVariable(VID_EVENT_ARG_BASE + i, ppArgList[i]);
+      msg.setField(VID_EVENT_ARG_BASE + i, ppArgList[i]);
    if (s_trapQueue != NULL)
        {
                s_genTrapCount++;
@@ -209,9 +209,9 @@ void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, const char *pszFormat,
 /**
  * Forward trap from external subagent to server
  */
-void ForwardTrap(CSCPMessage *msg)
+void ForwardTrap(NXCPMessage *msg)
 {
-       msg->SetVariable(VID_TRAP_ID, s_trapId++);
+       msg->setField(VID_TRAP_ID, s_trapId++);
    if (s_trapQueue != NULL)
        {
                s_genTrapCount++;
index 50e04a8..f69f170 100644 (file)
@@ -44,7 +44,7 @@ static MUTEX s_socketLock = MutexCreate();
 /**
  * Protocol buffer
  */
-static CSCP_BUFFER s_msgBuffer;
+static NXCP_BUFFER s_msgBuffer;
 
 /**
  * Connect to master agent
@@ -81,13 +81,13 @@ static bool ConnectToMasterAgent()
 /**
  * Send message to master agent
  */
-static bool SendMsg(CSCPMessage *msg)
+static bool SendMsg(NXCPMessage *msg)
 {
    if (s_socket == INVALID_SOCKET)
       return false;
 
-   CSCP_MESSAGE *rawMsg = msg->createMessage();
-   bool success = (SendEx(s_socket, rawMsg, ntohl(rawMsg->dwSize), 0, s_socketLock) == ntohl(rawMsg->dwSize));
+   NXCP_MESSAGE *rawMsg = msg->createMessage();
+   bool success = (SendEx(s_socket, rawMsg, ntohl(rawMsg->size), 0, s_socketLock) == ntohl(rawMsg->size));
    free(rawMsg);
    return success;
 }
@@ -97,12 +97,12 @@ static bool SendMsg(CSCPMessage *msg)
  */
 static void Login()
 {
-   CSCPMessage msg;
-   msg.SetCode(CMD_LOGIN);
+   NXCPMessage msg;
+   msg.setCode(CMD_LOGIN);
 
    DWORD sid;
    ProcessIdToSessionId(GetCurrentProcessId(), &sid);
-   msg.SetVariable(VID_SESSION_ID, (UINT32)sid);
+   msg.setField(VID_SESSION_ID, (UINT32)sid);
 
    DWORD size;
    WTS_CONNECTSTATE_CLASS *state;
@@ -127,20 +127,20 @@ static void Login()
       WTSFreeMemory(state);
    }
 
-   msg.SetVariable(VID_SESSION_STATE, sessionState);
+   msg.setField(VID_SESSION_STATE, sessionState);
 
    TCHAR *sessionName;
    if (WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, sid, WTSWinStationName, &sessionName, &size))
    {
       if (*sessionName != 0)
       {
-         msg.SetVariable(VID_NAME, sessionName);
+         msg.setField(VID_NAME, sessionName);
       }
       else
       {
          TCHAR buffer[256];
          _sntprintf(buffer, 256, _T("%s-%d"), (sessionState == USER_SESSION_DISCONNECTED) ? _T("Disconnected") : ((sessionState == USER_SESSION_IDLE) ? _T("Idle") : _T("Session")), sid);
-         msg.SetVariable(VID_NAME, buffer);
+         msg.setField(VID_NAME, buffer);
       }
       WTSFreeMemory(sessionName);
    }
@@ -149,7 +149,7 @@ static void Login()
    size = 256;
    if (GetUserName(userName, &size))
    {
-      msg.SetVariable(VID_USER_NAME, userName);
+      msg.setField(VID_USER_NAME, userName);
    }
 
    SendMsg(&msg);
@@ -158,23 +158,23 @@ static void Login()
 /**
  * Process request from master agent
  */
-static void ProcessRequest(CSCPMessage *request)
+static void ProcessRequest(NXCPMessage *request)
 {
-   CSCPMessage msg;
+   NXCPMessage msg;
 
-   msg.SetCode(CMD_REQUEST_COMPLETED);
-   msg.SetId(request->GetId());
+   msg.setCode(CMD_REQUEST_COMPLETED);
+   msg.setId(request->getId());
 
-   switch(request->GetCode())
+   switch(request->getCode())
    {
       case CMD_KEEPALIVE:
-         msg.SetVariable(VID_RCC, ERR_SUCCESS);
+         msg.setField(VID_RCC, ERR_SUCCESS);
          break;
       case CMD_TAKE_SCREENSHOT:
          TakeScreenshot(&msg);
          break;
       default:
-         msg.SetVariable(VID_RCC, ERR_UNKNOWN_COMMAND);
+         msg.setField(VID_RCC, ERR_UNKNOWN_COMMAND);
          break;
    }
 
@@ -189,7 +189,7 @@ static void ProcessMessages()
    NXCPEncryptionContext *dummyCtx = NULL;
    RecvNXCPMessage(0, NULL, &s_msgBuffer, 0, NULL, NULL, 0);
    UINT32 rawMsgSize = 65536;
-   CSCP_MESSAGE *rawMsg = (CSCP_MESSAGE *)malloc(rawMsgSize);
+   NXCP_MESSAGE *rawMsg = (NXCP_MESSAGE *)malloc(rawMsgSize);
    while(1)
    {
       int err = RecvNXCPMessageEx(s_socket, &rawMsg, &s_msgBuffer, &rawMsgSize, &dummyCtx, NULL, 900000, 4 * 1024 * 1024);
@@ -212,18 +212,18 @@ static void ProcessMessages()
       }
 
       // Check that actual received packet size is equal to encoded in packet
-      if ((int)ntohl(rawMsg->dwSize) != err)
+      if ((int)ntohl(rawMsg->size) != err)
       {
-         _tprintf(_T("Actual message size doesn't match wSize value (%d,%d)"), err, ntohl(rawMsg->dwSize));
+         _tprintf(_T("Actual message size doesn't match wSize value (%d,%d)"), err, ntohl(rawMsg->size));
          continue;   // Bad packet, wait for next
       }
 
-      UINT16 flags = ntohs(rawMsg->wFlags);
+      UINT16 flags = ntohs(rawMsg->flags);
       if (!(flags & MF_BINARY))
       {
-         CSCPMessage *msg = new CSCPMessage(rawMsg);
+         NXCPMessage *msg = new NXCPMessage(rawMsg);
          TCHAR msgCodeName[256];
-         _tprintf(_T("Received message %s\n"), NXCPMessageCodeName(msg->GetCode(), msgCodeName));
+         _tprintf(_T("Received message %s\n"), NXCPMessageCodeName(msg->getCode(), msgCodeName));
          ProcessRequest(msg);
          delete msg;
       }
index 59f8bc2..49c0231 100644 (file)
@@ -33,7 +33,7 @@
 #include <nxcpapi.h>
 #include <wtsapi32.h>
 
-void TakeScreenshot(CSCPMessage *response);
+void TakeScreenshot(NXCPMessage *response);
 bool SaveBitmapToPng(HBITMAP hBitmap, const TCHAR *fileName);
 
 #endif
index b6c2f01..099c49f 100644 (file)
@@ -25,7 +25,7 @@
 /**
  * Take screenshot
  */
-void TakeScreenshot(CSCPMessage *response)
+void TakeScreenshot(NXCPMessage *response)
 {
    UINT32 rcc = ERR_INTERNAL_ERROR;
 
@@ -69,5 +69,5 @@ void TakeScreenshot(CSCPMessage *response)
       DeleteDC(dc);
    }
    
-   response->SetVariable(VID_RCC, rcc);
+   response->setField(VID_RCC, rcc);
 }
index 0a431d1..dc08f84 100644 (file)
@@ -72,7 +72,7 @@ typedef struct
 
 static BOOL DB2Init(Config* config);
 static void DB2Shutdown();
-static BOOL DB2CommandHandler(UINT32 dwCommand, CSCPMessage* pRequest, CSCPMessage* pResponse, void* session);
+static BOOL DB2CommandHandler(UINT32 dwCommand, NXCPMessage* pRequest, NXCPMessage* pResponse, void* session);
 
 static THREAD_RESULT THREAD_CALL RunMonitorThread(void* info);
 static BOOL PerformQueries(const PTHREAD_INFO);
index d7010e9..c770166 100644 (file)
@@ -216,11 +216,11 @@ static BOOL CheckFullPath(TCHAR *folder, bool withHomeDir)
 /**
  * Puts in response list of containing files
  */
-static void GetFolderContent(TCHAR *folder, CSCPMessage *msg, bool rootFolder)
+static void GetFolderContent(TCHAR *folder, NXCPMessage *msg, bool rootFolder)
 {
    NX_STAT_STRUCT st;
 
-   msg->SetVariable(VID_RCC, ERR_SUCCESS);
+   msg->setField(VID_RCC, ERR_SUCCESS);
    UINT32 count = 0;
    UINT32 varId = VID_INSTANCE_LIST_BASE;
 
@@ -233,9 +233,9 @@ static void GetFolderContent(TCHAR *folder, CSCPMessage *msg, bool rootFolder)
 
          if (CALL_STAT(g_rootFileManagerFolders->get(i), &st) == 0)
          {
-            msg->SetVariable(varId++, g_rootFileManagerFolders->get(i));
-            msg->SetVariable(varId++, (QWORD)st.st_size);
-            msg->SetVariable(varId++, (QWORD)st.st_mtime);
+            msg->setField(varId++, g_rootFileManagerFolders->get(i));
+            msg->setField(varId++, (QWORD)st.st_size);
+            msg->setField(varId++, (QWORD)st.st_mtime);
             UINT32 type = 0;
 #ifndef _WIN32
             if(S_ISLNK(st.st_mode))
@@ -251,10 +251,10 @@ static void GetFolderContent(TCHAR *folder, CSCPMessage *msg, bool rootFolder)
 #endif
             type |= S_ISREG(st.st_mode) ? REGULAR_FILE : 0;
             type |= S_ISDIR(st.st_mode) ? DIRECTORY : 0;
-            msg->SetVariable(varId++, type);
+            msg->setField(varId++, type);
             TCHAR fullName[MAX_PATH];
             _tcscpy(fullName, g_rootFileManagerFolders->get(i));
-            msg->SetVariable(varId++, fullName);
+            msg->setField(varId++, fullName);
 
             varId += 5;
             count++;
@@ -264,7 +264,7 @@ static void GetFolderContent(TCHAR *folder, CSCPMessage *msg, bool rootFolder)
             AgentWriteDebugLog(3, _T("FILEMGR: GetFolderContent: Not possible to get folder %s"), g_rootFileManagerFolders->get(i));
          }
       }
-      msg->SetVariable(VID_INSTANCE_COUNT, count);
+      msg->setField(VID_INSTANCE_COUNT, count);
       return;
    }
 
@@ -289,9 +289,9 @@ static void GetFolderContent(TCHAR *folder, CSCPMessage *msg, bool rootFolder)
 
          if (CALL_STAT(fullName, &st) == 0)
          {
-            msg->SetVariable(varId++, d->d_name);
-            msg->SetVariable(varId++, (QWORD)st.st_size);
-            msg->SetVariable(varId++, (QWORD)st.st_mtime);
+            msg->setField(varId++, d->d_name);
+            msg->setField(varId++, (QWORD)st.st_size);
+            msg->setField(varId++, (QWORD)st.st_mtime);
             UINT32 type = 0;
 #ifndef _WIN32
             if(S_ISLNK(st.st_mode))
@@ -307,9 +307,9 @@ static void GetFolderContent(TCHAR *folder, CSCPMessage *msg, bool rootFolder)
 #endif
             type |= S_ISREG(st.st_mode) ? REGULAR_FILE : 0;
             type |= S_ISDIR(st.st_mode) ? DIRECTORY : 0;
-            msg->SetVariable(varId++, type);
+            msg->setField(varId++, type);
             ConvertPathToNetwork(fullName);
-            msg->SetVariable(varId++, fullName);
+            msg->setField(varId++, fullName);
 
             /*
             S_IFMT     0170000   bit mask for the file type bit fields
@@ -331,12 +331,12 @@ static void GetFolderContent(TCHAR *folder, CSCPMessage *msg, bool rootFolder)
              AgentWriteDebugLog(6, _T("FILEMGR: GetFolderContent: Not possible to get folder %s"), fullName);
          }
       }
-      msg->SetVariable(VID_INSTANCE_COUNT, count);
+      msg->setField(VID_INSTANCE_COUNT, count);
       _tclosedir(dir);
    }
    else
    {
-      msg->SetVariable(VID_RCC, RCC_IO_ERROR);
+      msg->setField(VID_RCC, RCC_IO_ERROR);
    }
 }
 
@@ -572,24 +572,24 @@ static BOOL CreateFolder(const TCHAR *directory)
 /**
  * Process commands like get files in folder, delete file/folder, copy file/folder, move file/folder
  */
-static BOOL ProcessCommands(UINT32 command, CSCPMessage *request, CSCPMessage *response, AbstractCommSession *session)
+static BOOL ProcessCommands(UINT32 command, NXCPMessage *request, NXCPMessage *response, AbstractCommSession *session)
 {
    switch(command)
    {
       case CMD_GET_FOLDER_CONTENT:
       {
          TCHAR directory[MAX_PATH];
-         request->GetVariableStr(VID_FILE_NAME, directory, MAX_PATH);
-         response->SetId(request->GetId());
+         request->getFieldAsString(VID_FILE_NAME, directory, MAX_PATH);
+         response->setId(request->getId());
          if (directory == NULL)
          {
-            response->SetVariable(VID_RCC, RCC_IO_ERROR);
+            response->setField(VID_RCC, RCC_IO_ERROR);
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): File name should be set."));
             return TRUE;
          }
          ConvertPathToHost(directory);
 
-         bool rootFolder = request->GetVariableShort(VID_ROOT) ? 1 : 0;
+         bool rootFolder = request->getFieldAsUInt16(VID_ROOT) ? 1 : 0;
          if (CheckFullPath(directory, rootFolder) && session->isMasterServer())
          {
             GetFolderContent(directory, response, rootFolder);
@@ -597,18 +597,18 @@ static BOOL ProcessCommands(UINT32 command, CSCPMessage *request, CSCPMessage *r
          else
          {
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Access denied"));
-            response->SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+            response->setField(VID_RCC, RCC_ACCESS_DENIED);
          }
          return TRUE;
       }
       case CMD_FILEMGR_DELETE_FILE:
       {
          TCHAR file[MAX_PATH];
-         request->GetVariableStr(VID_FILE_NAME, file, MAX_PATH);
-         response->SetId(request->GetId());
+         request->getFieldAsString(VID_FILE_NAME, file, MAX_PATH);
+         response->setId(request->getId());
          if(file == NULL)
          {
-            response->SetVariable(VID_RCC, RCC_IO_ERROR);
+            response->setField(VID_RCC, RCC_IO_ERROR);
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): File name should be set."));
             return TRUE;
          }
@@ -618,30 +618,30 @@ static BOOL ProcessCommands(UINT32 command, CSCPMessage *request, CSCPMessage *r
          {
             if (Delete(file))
             {
-               response->SetVariable(VID_RCC, ERR_SUCCESS);
+               response->setField(VID_RCC, ERR_SUCCESS);
             }
             else
             {
-               response->SetVariable(VID_RCC, RCC_IO_ERROR);
+               response->setField(VID_RCC, RCC_IO_ERROR);
             }
          }
          else
          {
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Access denied"));
-            response->SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+            response->setField(VID_RCC, RCC_ACCESS_DENIED);
          }
          return TRUE;
       }
       case CMD_FILEMGR_RENAME_FILE:
       {
          TCHAR oldName[MAX_PATH];
-         request->GetVariableStr(VID_FILE_NAME, oldName, MAX_PATH);
+         request->getFieldAsString(VID_FILE_NAME, oldName, MAX_PATH);
          TCHAR newName[MAX_PATH];
-         request->GetVariableStr(VID_NEW_FILE_NAME, newName, MAX_PATH);
-         response->SetId(request->GetId());
+         request->getFieldAsString(VID_NEW_FILE_NAME, newName, MAX_PATH);
+         response->setId(request->getId());
          if (oldName == NULL && newName == NULL)
          {
-            response->SetVariable(VID_RCC, RCC_IO_ERROR);
+            response->setField(VID_RCC, RCC_IO_ERROR);
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): File names should be set."));
             return TRUE;
          }
@@ -652,30 +652,30 @@ static BOOL ProcessCommands(UINT32 command, CSCPMessage *request, CSCPMessage *r
          {
             if (Rename(oldName, newName))
             {
-               response->SetVariable(VID_RCC, ERR_SUCCESS);
+               response->setField(VID_RCC, ERR_SUCCESS);
             }
             else
             {
-               response->SetVariable(VID_RCC, RCC_IO_ERROR);
+               response->setField(VID_RCC, RCC_IO_ERROR);
             }
          }
          else
          {
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Access denied"));
-            response->SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+            response->setField(VID_RCC, RCC_ACCESS_DENIED);
          }
          return TRUE;
       }
       case CMD_FILEMGR_MOVE_FILE:
       {
          TCHAR oldName[MAX_PATH];
-         request->GetVariableStr(VID_FILE_NAME, oldName, MAX_PATH);
+         request->getFieldAsString(VID_FILE_NAME, oldName, MAX_PATH);
          TCHAR newName[MAX_PATH];
-         request->GetVariableStr(VID_NEW_FILE_NAME, newName, MAX_PATH);
-         response->SetId(request->GetId());
-         if(oldName == NULL && newName == NULL)
+         request->getFieldAsString(VID_NEW_FILE_NAME, newName, MAX_PATH);
+         response->setId(request->getId());
+         if ((oldName == NULL) && (newName == NULL))
          {
-            response->SetVariable(VID_RCC, RCC_IO_ERROR);
+            response->setField(VID_RCC, RCC_IO_ERROR);
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): File names should be set."));
             return TRUE;
          }
@@ -686,28 +686,28 @@ static BOOL ProcessCommands(UINT32 command, CSCPMessage *request, CSCPMessage *r
          {
             if(MoveFile(oldName, newName))
             {
-               response->SetVariable(VID_RCC, ERR_SUCCESS);
+               response->setField(VID_RCC, ERR_SUCCESS);
             }
             else
             {
-               response->SetVariable(VID_RCC, RCC_IO_ERROR);
+               response->setField(VID_RCC, RCC_IO_ERROR);
             }
          }
          else
          {
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Access denied"));
-            response->SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+            response->setField(VID_RCC, RCC_ACCESS_DENIED);
          }
          return TRUE;
       }
       case CMD_FILEMGR_UPLOAD:
       {
          TCHAR name[MAX_PATH];
-         request->GetVariableStr(VID_FILE_NAME, name, MAX_PATH);
-         response->SetId(request->GetId());
+         request->getFieldAsString(VID_FILE_NAME, name, MAX_PATH);
+         response->setId(request->getId());
          if (name == NULL)
          {
-            response->SetVariable(VID_RCC, RCC_IO_ERROR);
+            response->setField(VID_RCC, RCC_IO_ERROR);
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): File name should be set."));
             return TRUE;
          }
@@ -715,21 +715,21 @@ static BOOL ProcessCommands(UINT32 command, CSCPMessage *request, CSCPMessage *r
 
          if (CheckFullPath(name, false) && session->isMasterServer())
          {
-            response->SetVariable(VID_RCC, session->openFile(name, request->GetId()));
+            response->setField(VID_RCC, session->openFile(name, request->getId()));
          }
          else
          {
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Access denied"));
-            response->SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+            response->setField(VID_RCC, RCC_ACCESS_DENIED);
          }
          return TRUE;
       }
       case CMD_GET_FILE_DETAILS:
       {
          TCHAR fileName[MAX_PATH];
-         request->GetVariableStr(VID_FILE_NAME, fileName, MAX_PATH);
+         request->getFieldAsString(VID_FILE_NAME, fileName, MAX_PATH);
          ExpandFileName(fileName, fileName, MAX_PATH, false);
-         response->SetId(request->GetId());
+         response->setId(request->getId());
 
        if (session->isMasterServer() && CheckFullPath(fileName, false))
          {
@@ -738,104 +738,104 @@ static BOOL ProcessCommands(UINT32 command, CSCPMessage *request, CSCPMessage *r
             //prepare file name
             if (CALL_STAT(fileName, &fs) == 0)
             {
-               response->SetVariable(VID_FILE_SIZE, (UINT64)fs.st_size);
-               response->SetVariable(VID_MODIFY_TIME, (UINT64)fs.st_mtime);
-               response->SetVariable(VID_RCC, ERR_SUCCESS);
+               response->setField(VID_FILE_SIZE, (UINT64)fs.st_size);
+               response->setField(VID_MODIFY_TIME, (UINT64)fs.st_mtime);
+               response->setField(VID_RCC, ERR_SUCCESS);
             }
             else
             {
-               response->SetVariable(VID_RCC, ERR_FILE_STAT_FAILED);
+               response->setField(VID_RCC, ERR_FILE_STAT_FAILED);
             }
          }
          else
          {
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Access denied"));
-            response->SetVariable(VID_RCC, ERR_ACCESS_DENIED);
+            response->setField(VID_RCC, ERR_ACCESS_DENIED);
          }
          return TRUE;
       }
       case CMD_GET_AGENT_FILE:
       {
-         response->SetId(request->GetId());
+         response->setId(request->getId());
          TCHAR fileName[MAX_PATH];
-         request->GetVariableStr(VID_FILE_NAME, fileName, MAX_PATH);
+         request->getFieldAsString(VID_FILE_NAME, fileName, MAX_PATH);
          ExpandFileName(fileName, fileName, MAX_PATH, false);
 
          if (session->isMasterServer() && CheckFullPath(fileName, false))
          {
             TCHAR *fileNameCode = (TCHAR*)malloc(MAX_PATH * sizeof(TCHAR));
-            request->GetVariableStr(VID_NAME, fileNameCode, MAX_PATH);
+            request->getFieldAsString(VID_NAME, fileNameCode, MAX_PATH);
 
             MessageData *data = new MessageData();
             data->fileName = _tcsdup(fileName);
             data->fileNameCode = fileNameCode;
-            data->follow = request->GetVariableShort(VID_FILE_FOLLOW) ? true : false;
-            data->id = request->GetId();
-            data->offset = request->GetVariableLong(VID_FILE_OFFSET);
+            data->follow = request->getFieldAsUInt16(VID_FILE_FOLLOW) ? true : false;
+            data->id = request->getId();
+            data->offset = request->getFieldAsUInt32(VID_FILE_OFFSET);
             data->session = session;
 
             ThreadCreateEx(SendFile, 0, data);
 
-            response->SetVariable(VID_RCC, ERR_SUCCESS);
+            response->setField(VID_RCC, ERR_SUCCESS);
          }
          else
          {
-            response->SetVariable(VID_RCC, ERR_ACCESS_DENIED);
+            response->setField(VID_RCC, ERR_ACCESS_DENIED);
          }
          return TRUE;
       }
       case CMD_CANCEL_FILE_MONITORING:
       {
-         response->SetId(request->GetId());
+         response->setId(request->getId());
          if (session->isMasterServer())
          {
             TCHAR fileName[MAX_PATH];
-            request->GetVariableStr(VID_FILE_NAME, fileName, MAX_PATH);
+            request->getFieldAsString(VID_FILE_NAME, fileName, MAX_PATH);
             if(g_monitorFileList.removeMonitoringFile(fileName))
             {
-               response->SetVariable(VID_RCC, ERR_SUCCESS);
+               response->setField(VID_RCC, ERR_SUCCESS);
             }
             else
             {
-               response->SetVariable(VID_RCC, ERR_BAD_ARGUMENTS);
+               response->setField(VID_RCC, ERR_BAD_ARGUMENTS);
             }
          }
          else
          {
-            response->SetVariable(VID_RCC, ERR_ACCESS_DENIED);
+            response->setField(VID_RCC, ERR_ACCESS_DENIED);
          }
          return TRUE;
       }
       case CMD_FILEMGR_CREATE_FOLDER:
       {
          TCHAR directory[MAX_PATH];
-         request->GetVariableStr(VID_FILE_NAME, directory, MAX_PATH);
-         response->SetId(request->GetId());
+         request->getFieldAsString(VID_FILE_NAME, directory, MAX_PATH);
+         response->setId(request->getId());
          if (directory == NULL)
          {
-            response->SetVariable(VID_RCC, RCC_IO_ERROR);
+            response->setField(VID_RCC, RCC_IO_ERROR);
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): File name should be set."));
             return TRUE;
          }
          ConvertPathToHost(directory);
 
-         bool rootFolder = request->GetVariableShort(VID_ROOT) ? 1 : 0;
+         bool rootFolder = request->getFieldAsUInt16(VID_ROOT) ? 1 : 0;
          if (CheckFullPath(directory, false) && session->isMasterServer())
          {
             if(CreateFolder(directory))
             {
-               response->SetVariable(VID_RCC, ERR_SUCCESS);
+               response->setField(VID_RCC, ERR_SUCCESS);
             }
             else
             {
                AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Could not create directory"));
-               response->SetVariable(VID_RCC, RCC_IO_ERROR);
+               response->setField(VID_RCC, RCC_IO_ERROR);
             }
          }
          else
          {
             AgentWriteDebugLog(6, _T("FILEMGR: ProcessCommands(): Access denied"));
-            response->SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+            response->setField(VID_RCC, RCC_ACCESS_DENIED);
          }
          return TRUE;
       }
index 9858287..44c0a1b 100644 (file)
@@ -126,7 +126,7 @@ void MonitoredFileList::Unlock()
 struct SendMessageData
 {
    InetAddress ip;
-   CSCPMessage *pMsg;
+   NXCPMessage *pMsg;
 };
 
 /**
@@ -151,7 +151,7 @@ THREAD_RESULT THREAD_CALL SendFileUpdatesOverNXCP(void *args)
    int hFile, threadSleepTime = 1;
    BYTE* readBytes = NULL;
    BOOL bResult = FALSE;
-   CSCPMessage *pMsg;
+   NXCPMessage *pMsg;
    UINT32 readSize;
 
    bool follow = true;
@@ -182,10 +182,10 @@ THREAD_RESULT THREAD_CALL SendFileUpdatesOverNXCP(void *args)
                readSize = MAX_MSG_SIZE - headerSize;
                newOffset = flData->getOffset() + readSize;
             }
-            pMsg = new CSCPMessage();
-            pMsg->SetCode(CMD_FILE_MONITORING);
-            pMsg->SetId(0);
-            pMsg->SetVariable(VID_FILE_NAME, flData->getFileId(), MAX_PATH);
+            pMsg = new NXCPMessage();
+            pMsg->setCode(CMD_FILE_MONITORING);
+            pMsg->setId(0);
+            pMsg->setField(VID_FILE_NAME, flData->getFileId(), MAX_PATH);
 
             lseek(hFile, flData->getOffset(), SEEK_SET);
             readBytes = (BYTE*)malloc(readSize);
@@ -193,10 +193,10 @@ THREAD_RESULT THREAD_CALL SendFileUpdatesOverNXCP(void *args)
             AgentWriteDebugLog(6, _T("SendFileUpdatesOverNXCP: %d bytes will be sent."), readSize);
 #ifdef UNICODE
             TCHAR *text = WideStringFromMBString((char *)readBytes);
-            pMsg->SetVariable(VID_FILE_DATA, text, readSize);
+            pMsg->setField(VID_FILE_DATA, text, readSize);
             free(text);
 #else
-            pMsg->SetVariable(VID_FILE_DATA, (char *)readBytes, readSize);
+            pMsg->setField(VID_FILE_DATA, (char *)readBytes, readSize);
 #endif
             flData->setOffset(newOffset);
 
index f0f7e53..8b0cb9b 100644 (file)
@@ -78,7 +78,7 @@ static NETXMS_SUBAGENT_INFO g_subAgentInfo =
    NETXMS_VERSION_STRING,
    SubAgentInit,
    SubAgentShutdown,
-   NULL,                         // BOOL (*commandhandler)(UINT32 dwCommand, CSCPMessage *pRequest, CSCPMessage *pResponse, void *session)
+   NULL,                         // BOOL (*commandhandler)(UINT32 dwCommand, NXCPMessage *pRequest, NXCPMessage *pResponse, void *session)
    0,                            // numParamaters
    NULL,                         // parameters
    0,                            // numLists
index 3b74c17..833d03f 100644 (file)
@@ -30,7 +30,7 @@ char g_szFailedDir[1024] = "";
 /**
  * Command handler
  */
-BOOL CommandHandler(UINT32 dwCommand, CSCPMessage *pRequest, CSCPMessage *pResponse, AbstractCommSession *session)
+BOOL CommandHandler(UINT32 dwCommand, NXCPMessage *pRequest, NXCPMessage *pResponse, AbstractCommSession *session)
 {
        BOOL bHandled = TRUE;
        WORD wType, wPort;
@@ -44,11 +44,11 @@ BOOL CommandHandler(UINT32 dwCommand, CSCPMessage *pRequest, CSCPMessage *pRespo
                return FALSE;
        }
 
-       wType = pRequest->GetVariableShort(VID_SERVICE_TYPE);
-       wPort = pRequest->GetVariableShort(VID_IP_PORT);
-       dwAddress = pRequest->GetVariableLong(VID_IP_ADDRESS);
-       pRequest->GetVariableStrA(VID_SERVICE_REQUEST, szRequest, sizeof(szRequest));
-       pRequest->GetVariableStrA(VID_SERVICE_RESPONSE, szResponse, sizeof(szResponse));
+       wType = pRequest->getFieldAsUInt16(VID_SERVICE_TYPE);
+       wPort = pRequest->getFieldAsUInt16(VID_IP_PORT);
+       dwAddress = pRequest->getFieldAsUInt32(VID_IP_ADDRESS);
+       pRequest->getFieldAsMBString(VID_SERVICE_REQUEST, szRequest, sizeof(szRequest));
+       pRequest->getFieldAsMBString(VID_SERVICE_RESPONSE, szResponse, sizeof(szResponse));
 
    INT64 start = GetCurrentTimeMs();
 
@@ -57,20 +57,20 @@ BOOL CommandHandler(UINT32 dwCommand, CSCPMessage *pRequest, CSCPMessage *pRespo
                case NETSRV_CUSTOM:
                        // unsupported for now
                        nRet = CheckCustom(NULL, dwAddress, wPort, 0);
-                       pResponse->SetVariable(VID_RCC, ERR_SUCCESS);
-                       pResponse->SetVariable(VID_SERVICE_STATUS, (UINT32)nRet);
+                       pResponse->setField(VID_RCC, ERR_SUCCESS);
+                       pResponse->setField(VID_SERVICE_STATUS, (UINT32)nRet);
                        break;
                case NETSRV_SSH:
                        nRet = CheckSSH(NULL, dwAddress, wPort, NULL, NULL, 0);
 
-                       pResponse->SetVariable(VID_RCC, ERR_SUCCESS);
-                       pResponse->SetVariable(VID_SERVICE_STATUS, (UINT32)nRet);
+                       pResponse->setField(VID_RCC, ERR_SUCCESS);
+                       pResponse->setField(VID_SERVICE_STATUS, (UINT32)nRet);
                        break;
                case NETSRV_TELNET:
                        nRet = CheckTelnet(NULL, dwAddress, wPort, NULL, NULL, 0);
 
-                       pResponse->SetVariable(VID_RCC, ERR_SUCCESS);
-                       pResponse->SetVariable(VID_SERVICE_STATUS, (UINT32)nRet);
+                       pResponse->setField(VID_RCC, ERR_SUCCESS);
+                       pResponse->setField(VID_SERVICE_STATUS, (UINT32)nRet);
                        break;
                case NETSRV_POP3:
                        {
@@ -88,8 +88,8 @@ BOOL CommandHandler(UINT32 dwCommand, CSCPMessage *pRequest, CSCPMessage *pRespo
 
                                }
 
-                               pResponse->SetVariable(VID_RCC, ERR_SUCCESS);
-                               pResponse->SetVariable(VID_SERVICE_STATUS, (UINT32)nRet);
+                               pResponse->setField(VID_RCC, ERR_SUCCESS);
+                               pResponse->setField(VID_SERVICE_STATUS, (UINT32)nRet);
                        }
                        break;
                case NETSRV_SMTP:
@@ -98,12 +98,12 @@ BOOL CommandHandler(UINT32 dwCommand, CSCPMessage *pRequest, CSCPMessage *pRespo
                        if (szRequest[0] != 0)
                        {
                                nRet = CheckSMTP(NULL, dwAddress, wPort, szRequest, 0);
-                               pResponse->SetVariable(VID_RCC, ERR_SUCCESS);
-                               pResponse->SetVariable(VID_SERVICE_STATUS, (UINT32)nRet);
+                               pResponse->setField(VID_RCC, ERR_SUCCESS);
+                               pResponse->setField(VID_SERVICE_STATUS, (UINT32)nRet);
                        }
 
-                       pResponse->SetVariable(VID_RCC, ERR_SUCCESS);
-                       pResponse->SetVariable(VID_SERVICE_STATUS, (UINT32)nRet);
+                       pResponse->setField(VID_RCC, ERR_SUCCESS);
+                       pResponse->setField(VID_SERVICE_STATUS, (UINT32)nRet);
                        break;
                case NETSRV_FTP:
                        bHandled = FALSE;
@@ -133,8 +133,8 @@ BOOL CommandHandler(UINT32 dwCommand, CSCPMessage *pRequest, CSCPMessage *pRespo
                }
                                }
 
-                               pResponse->SetVariable(VID_RCC, ERR_SUCCESS);
-                               pResponse->SetVariable(VID_SERVICE_STATUS, (UINT32)nRet);
+                               pResponse->setField(VID_RCC, ERR_SUCCESS);
+                               pResponse->setField(VID_SERVICE_STATUS, (UINT32)nRet);
                        }
                        break;
                default:
@@ -145,7 +145,7 @@ BOOL CommandHandler(UINT32 dwCommand, CSCPMessage *pRequest, CSCPMessage *pRespo
    if (bHandled)
    {
       INT64 elapsed = GetCurrentTimeMs() - start;
-      pResponse->SetVariable(VID_RESPONSE_TIME, (INT32)elapsed);
+      pResponse->setField(VID_RESPONSE_TIME, (INT32)elapsed);
    }
        return bHandled;
 }
index 2432bff..6ee247a 100644 (file)
@@ -338,22 +338,22 @@ static BOOL Send()
 {
        BOOL success = FALSE;
 
-       CSCPMessage msg;
-       msg.SetCode(CMD_PUSH_DCI_DATA);
-   msg.SetVariable(VID_OBJECT_ID, optObjectId);
+       NXCPMessage msg;
+       msg.setCode(CMD_PUSH_DCI_DATA);
+   msg.setField(VID_OBJECT_ID, optObjectId);
    s_data->fillMessage(&msg, VID_NUM_ITEMS, VID_PUSH_DCI_DATA_BASE);
 
        // Send response to pipe
-       CSCP_MESSAGE *rawMsg = msg.createMessage();
+       NXCP_MESSAGE *rawMsg = msg.createMessage();
 #ifdef _WIN32
        DWORD bytes;
-       if (!WriteFile(s_hPipe, rawMsg, ntohl(rawMsg->dwSize), &bytes, NULL))
+       if (!WriteFile(s_hPipe, rawMsg, ntohl(rawMsg->size), &bytes, NULL))
                goto cleanup;
-       if (bytes != ntohl(rawMsg->dwSize))
+       if (bytes != ntohl(rawMsg->size))
                goto cleanup;
 #else
-       int bytes = SendEx(s_hPipe, rawMsg, ntohl(rawMsg->dwSize), 0, NULL); 
-       if (bytes != (int)ntohl(rawMsg->dwSize))
+       int bytes = SendEx(s_hPipe, rawMsg, ntohl(rawMsg->size), 0, NULL); 
+       if (bytes != (int)ntohl(rawMsg->size))
                goto cleanup;
 #endif
 
index 5623482..a36867b 100644 (file)
@@ -1,7 +1,7 @@
 /* 
 ** NetXMS - Network Management System
 ** NetXMS Foundation Library
-** Copyright (C) 2003-2013 Victor Kirhenshtein
+** 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
@@ -209,17 +209,17 @@ UINT32 LIBNETXMS_EXPORTABLE CSCPGetSupportedCiphers()
 /**
  * Encrypt message
  */
-NXCP_ENCRYPTED_MESSAGE LIBNETXMS_EXPORTABLE *CSCPEncryptMessage(NXCPEncryptionContext *pCtx, CSCP_MESSAGE *pMsg)
+NXCP_ENCRYPTED_MESSAGE LIBNETXMS_EXPORTABLE *NXCPEncryptMessage(NXCPEncryptionContext *pCtx, NXCP_MESSAGE *msg)
 {
-   return (pCtx != NULL) ? pCtx->encryptMessage(pMsg) : NULL;
+   return (pCtx != NULL) ? pCtx->encryptMessage(msg) : NULL;
 }
 
 /**
  * Decrypt message
  */
-BOOL LIBNETXMS_EXPORTABLE CSCPDecryptMessage(NXCPEncryptionContext *pCtx, NXCP_ENCRYPTED_MESSAGE *pMsg, BYTE *pDecryptionBuffer)
+BOOL LIBNETXMS_EXPORTABLE NXCPDecryptMessage(NXCPEncryptionContext *pCtx, NXCP_ENCRYPTED_MESSAGE *msg, BYTE *pDecryptionBuffer)
 {
-   return (pCtx != NULL) ? pCtx->decryptMessage(pMsg, pDecryptionBuffer) : FALSE;
+   return (pCtx != NULL) ? pCtx->decryptMessage(msg, pDecryptionBuffer) : FALSE;
 }
 
 /**
@@ -228,28 +228,28 @@ BOOL LIBNETXMS_EXPORTABLE CSCPDecryptMessage(NXCPEncryptionContext *pCtx, NXCP_E
  * by message code. Initiator should provide it's private key,
  * and responder should provide pointer to response message.
  */
-UINT32 LIBNETXMS_EXPORTABLE SetupEncryptionContext(CSCPMessage *pMsg, 
+UINT32 LIBNETXMS_EXPORTABLE SetupEncryptionContext(NXCPMessage *msg, 
                                                   NXCPEncryptionContext **ppCtx,
-                                                  CSCPMessage **ppResponse,
+                                                  NXCPMessage **ppResponse,
                                                   RSA *pPrivateKey, int nNXCPVersion)
 {
    UINT32 dwResult = RCC_NOT_IMPLEMENTED;
 
        *ppCtx = NULL;
 #ifdef _WITH_ENCRYPTION
-   if (pMsg->GetCode() == CMD_REQUEST_SESSION_KEY)
+   if (msg->getCode() == CMD_REQUEST_SESSION_KEY)
    {
       UINT32 dwCiphers;
 
-      *ppResponse = new CSCPMessage(nNXCPVersion);
-      (*ppResponse)->SetCode(CMD_SESSION_KEY);
-      (*ppResponse)->SetId(pMsg->GetId());
+      *ppResponse = new NXCPMessage(nNXCPVersion);
+      (*ppResponse)->setCode(CMD_SESSION_KEY);
+      (*ppResponse)->setId(msg->getId());
       (*ppResponse)->disableEncryption();
 
-      dwCiphers = pMsg->GetVariableLong(VID_SUPPORTED_ENCRYPTION) & m_dwSupportedCiphers;
+      dwCiphers = msg->getFieldAsUInt32(VID_SUPPORTED_ENCRYPTION) & m_dwSupportedCiphers;
       if (dwCiphers == 0)
       {
-         (*ppResponse)->SetVariable(VID_RCC, RCC_NO_CIPHERS);
+         (*ppResponse)->setField(VID_RCC, RCC_NO_CIPHERS);
          dwResult = RCC_NO_CIPHERS;
       }
       else
@@ -260,41 +260,41 @@ UINT32 LIBNETXMS_EXPORTABLE SetupEncryptionContext(CSCPMessage *pMsg,
                        *ppCtx = NXCPEncryptionContext::create(dwCiphers);
 
          // Encrypt key
-         int size = pMsg->GetVariableBinary(VID_PUBLIC_KEY, ucKeyBuffer, KEY_BUFFER_SIZE);
+         int size = msg->getFieldAsBinary(VID_PUBLIC_KEY, ucKeyBuffer, KEY_BUFFER_SIZE);
          pBufPos = ucKeyBuffer;
          pServerKey = d2i_RSAPublicKey(NULL, (OPENSSL_CONST BYTE **)&pBufPos, size);
          if (pServerKey != NULL)
          {
-            (*ppResponse)->SetVariable(VID_RCC, RCC_SUCCESS);
+            (*ppResponse)->setField(VID_RCC, RCC_SUCCESS);
             
             size = RSA_public_encrypt((*ppCtx)->getKeyLength(), (*ppCtx)->getSessionKey(), ucKeyBuffer, pServerKey, RSA_PKCS1_OAEP_PADDING);
-            (*ppResponse)->SetVariable(VID_SESSION_KEY, ucKeyBuffer, (UINT32)size);
-            (*ppResponse)->SetVariable(VID_KEY_LENGTH, (WORD)(*ppCtx)->getKeyLength());
+            (*ppResponse)->setField(VID_SESSION_KEY, ucKeyBuffer, (UINT32)size);
+            (*ppResponse)->setField(VID_KEY_LENGTH, (WORD)(*ppCtx)->getKeyLength());
             
             int ivLength = EVP_CIPHER_iv_length(s_ciphers[(*ppCtx)->getCipher()]());
             if ((ivLength <= 0) || (ivLength > EVP_MAX_IV_LENGTH))
                ivLength = EVP_MAX_IV_LENGTH;
             size = RSA_public_encrypt(ivLength, (*ppCtx)->getIV(), ucKeyBuffer, pServerKey, RSA_PKCS1_OAEP_PADDING);
-            (*ppResponse)->SetVariable(VID_SESSION_IV, ucKeyBuffer, (UINT32)size);
-            (*ppResponse)->SetVariable(VID_IV_LENGTH, (WORD)ivLength);
+            (*ppResponse)->setField(VID_SESSION_IV, ucKeyBuffer, (UINT32)size);
+            (*ppResponse)->setField(VID_IV_LENGTH, (WORD)ivLength);
 
-            (*ppResponse)->SetVariable(VID_CIPHER, (WORD)(*ppCtx)->getCipher());
+            (*ppResponse)->setField(VID_CIPHER, (WORD)(*ppCtx)->getCipher());
             RSA_free(pServerKey);
             dwResult = RCC_SUCCESS;
          }
          else
          {
-            (*ppResponse)->SetVariable(VID_RCC, RCC_INVALID_PUBLIC_KEY);
+            (*ppResponse)->setField(VID_RCC, RCC_INVALID_PUBLIC_KEY);
             dwResult = RCC_INVALID_PUBLIC_KEY;
          }
       }
    }
-   else if (pMsg->GetCode() == CMD_SESSION_KEY)
+   else if (msg->getCode() == CMD_SESSION_KEY)
    {
-      dwResult = pMsg->GetVariableLong(VID_RCC);
+      dwResult = msg->getFieldAsUInt32(VID_RCC);
       if (dwResult == RCC_SUCCESS)
       {
-                       *ppCtx = NXCPEncryptionContext::create(pMsg, pPrivateKey);
+                       *ppCtx = NXCPEncryptionContext::create(msg, pPrivateKey);
                        if (*ppCtx == NULL)
                        {
                                dwResult = RCC_INVALID_SESSION_KEY;
@@ -308,13 +308,13 @@ UINT32 LIBNETXMS_EXPORTABLE SetupEncryptionContext(CSCPMessage *pMsg,
       *ppCtx = NULL;
    }
 #else
-   if (pMsg->GetCode() == CMD_REQUEST_SESSION_KEY)
+   if (msg->getCode() == CMD_REQUEST_SESSION_KEY)
    {
-      *ppResponse = new CSCPMessage(nNXCPVersion);
+      *ppResponse = new NXCPMessage(nNXCPVersion);
       (*ppResponse)->SetCode(CMD_SESSION_KEY);
-      (*ppResponse)->SetId(pMsg->GetId());
+      (*ppResponse)->SetId(msg->getId());
       (*ppResponse)->disableEncryption();
-      (*ppResponse)->SetVariable(VID_RCC, dwResult);
+      (*ppResponse)->setField(VID_RCC, dwResult);
    }
 #endif
 
@@ -324,14 +324,14 @@ UINT32 LIBNETXMS_EXPORTABLE SetupEncryptionContext(CSCPMessage *pMsg,
 /**
  * Prepare session key request message
  */
-void LIBNETXMS_EXPORTABLE PrepareKeyRequestMsg(CSCPMessage *pMsg, RSA *pServerKey, bool useX509Format)
+void LIBNETXMS_EXPORTABLE PrepareKeyRequestMsg(NXCPMessage *msg, RSA *pServerKey, bool useX509Format)
 {
 #ifdef _WITH_ENCRYPTION
    int iLen;
    BYTE *pKeyBuffer, *pBufPos;
 
-   pMsg->SetCode(CMD_REQUEST_SESSION_KEY);
-   pMsg->SetVariable(VID_SUPPORTED_ENCRYPTION, m_dwSupportedCiphers);
+   msg->setCode(CMD_REQUEST_SESSION_KEY);
+   msg->setField(VID_SUPPORTED_ENCRYPTION, m_dwSupportedCiphers);
 
        if (useX509Format)
        {
@@ -347,7 +347,7 @@ void LIBNETXMS_EXPORTABLE PrepareKeyRequestMsg(CSCPMessage *pMsg, RSA *pServerKe
                pBufPos = pKeyBuffer;
                i2d_RSAPublicKey(pServerKey, &pBufPos);
        }
-       pMsg->SetVariable(VID_PUBLIC_KEY, pKeyBuffer, iLen);
+       msg->setField(VID_PUBLIC_KEY, pKeyBuffer, iLen);
    free(pKeyBuffer);
 #endif
 }
@@ -406,7 +406,7 @@ RSA LIBNETXMS_EXPORTABLE *LoadRSAKeys(const TCHAR *pszKeyFile)
 /**
  * Create signature for message using certificate (MS CAPI version)
  * Paraeters:
- *    pMsg and dwMsgLen - message to sign and it's length
+ *    msg and dwMsgLen - message to sign and it's length
  *    pCert - certificate
  *    pBuffer - output buffer
  *    dwBufSize - buffer size
@@ -414,7 +414,7 @@ RSA LIBNETXMS_EXPORTABLE *LoadRSAKeys(const TCHAR *pszKeyFile)
  */
 #ifdef _WIN32
 
-BOOL LIBNETXMS_EXPORTABLE SignMessageWithCAPI(BYTE *pMsg, UINT32 dwMsgLen, const CERT_CONTEXT *pCert,
+BOOL LIBNETXMS_EXPORTABLE SignMessageWithCAPI(BYTE *msg, UINT32 dwMsgLen, const CERT_CONTEXT *pCert,
                                                                                                          BYTE *pBuffer, UINT32 dwBufSize, UINT32 *pdwSigLen)
 {
        BOOL bFreeProv, bRet = FALSE;
@@ -427,7 +427,7 @@ BOOL LIBNETXMS_EXPORTABLE SignMessageWithCAPI(BYTE *pMsg, UINT32 dwMsgLen, const
        {
                if (CryptCreateHash(hProv, CALG_SHA1, NULL, 0, &hHash))
                {
-                       if (CryptHashData(hHash, pMsg, dwMsgLen, 0))
+                       if (CryptHashData(hHash, msg, dwMsgLen, 0))
                        {
                                dwLen = dwBufSize;
                                pTemp = (BYTE *)malloc(dwBufSize);;
@@ -525,7 +525,7 @@ NXCPEncryptionContext::~NXCPEncryptionContext()
 /**
  * Create encryption context from CMD_SESSION_KEY NXCP message
  */
-NXCPEncryptionContext *NXCPEncryptionContext::create(CSCPMessage *msg, RSA *privateKey)
+NXCPEncryptionContext *NXCPEncryptionContext::create(NXCPMessage *msg, RSA *privateKey)
 {
 #ifdef _WITH_ENCRYPTION
    BYTE ucKeyBuffer[KEY_BUFFER_SIZE], ucSessionKey[KEY_BUFFER_SIZE];
@@ -533,25 +533,25 @@ NXCPEncryptionContext *NXCPEncryptionContext::create(CSCPMessage *msg, RSA *priv
    int nSize, nIVLen;
        NXCPEncryptionContext *ctx = new NXCPEncryptionContext;
 
-   int cipher = (int)msg->GetVariableShort(VID_CIPHER);
+   int cipher = (int)msg->getFieldAsUInt16(VID_CIPHER);
    if (ctx->initCipher(cipher))
    {
-      if (ctx->m_keyLength == (int)msg->GetVariableShort(VID_KEY_LENGTH))
+      if (ctx->m_keyLength == (int)msg->getFieldAsUInt16(VID_KEY_LENGTH))
       {
          ctx->m_sessionKey = (BYTE *)malloc(ctx->m_keyLength);
 
          // Decrypt session key
-         dwKeySize = msg->GetVariableBinary(VID_SESSION_KEY, ucKeyBuffer, KEY_BUFFER_SIZE);
+         dwKeySize = msg->getFieldAsBinary(VID_SESSION_KEY, ucKeyBuffer, KEY_BUFFER_SIZE);
          nSize = RSA_private_decrypt(dwKeySize, ucKeyBuffer, ucSessionKey, privateKey, RSA_PKCS1_OAEP_PADDING);
          if (nSize == ctx->m_keyLength)
          {
             memcpy(ctx->m_sessionKey, ucSessionKey, nSize);
 
             // Decrypt session IV
-            nIVLen = msg->GetVariableShort(VID_IV_LENGTH);
+            nIVLen = msg->getFieldAsUInt16(VID_IV_LENGTH);
             if (nIVLen == 0)  // Versions prior to 0.2.13 don't send IV length, assume 16
                nIVLen = 16;
-            dwKeySize = msg->GetVariableBinary(VID_SESSION_IV, ucKeyBuffer, KEY_BUFFER_SIZE);
+            dwKeySize = msg->getFieldAsBinary(VID_SESSION_IV, ucKeyBuffer, KEY_BUFFER_SIZE);
             nSize = RSA_private_decrypt(dwKeySize, ucKeyBuffer, ucSessionKey, privateKey, RSA_PKCS1_OAEP_PADDING);
             if ((nSize == nIVLen) &&
                 (nIVLen <= EVP_CIPHER_iv_length(s_ciphers[ctx->m_cipher]())))
@@ -572,7 +572,7 @@ NXCPEncryptionContext *NXCPEncryptionContext::create(CSCPMessage *msg, RSA *priv
       }
       else
       {
-         CryptoDbgPrintf(6, _T("NXCPEncryptionContext::create: key length mismatch (remote: %d local: %d)"), (int)msg->GetVariableShort(VID_KEY_LENGTH), ctx->m_keyLength);
+         CryptoDbgPrintf(6, _T("NXCPEncryptionContext::create: key length mismatch (remote: %d local: %d)"), (int)msg->getFieldAsUInt16(VID_KEY_LENGTH), ctx->m_keyLength);
          delete_and_null(ctx);
       }
    }
@@ -699,10 +699,10 @@ NXCPEncryptionContext *NXCPEncryptionContext::create(UINT32 ciphers)
 /**
  * Encrypt message
  */
-NXCP_ENCRYPTED_MESSAGE *NXCPEncryptionContext::encryptMessage(CSCP_MESSAGE *msg)
+NXCP_ENCRYPTED_MESSAGE *NXCPEncryptionContext::encryptMessage(NXCP_MESSAGE *msg)
 {
-   if (msg->wFlags & s_noEncryptionFlag)
-      return (NXCP_ENCRYPTED_MESSAGE *)nx_memdup(msg, ntohl(msg->dwSize));
+   if (msg->flags & s_noEncryptionFlag)
+      return (NXCP_ENCRYPTED_MESSAGE *)nx_memdup(msg, ntohl(msg->size));
 
 #ifdef _WITH_ENCRYPTION
    MutexLock(m_encryptorLock);
@@ -713,11 +713,11 @@ NXCP_ENCRYPTED_MESSAGE *NXCPEncryptionContext::encryptMessage(CSCP_MESSAGE *msg)
       return NULL;
    }
 
-   UINT32 msgSize = ntohl(msg->dwSize);
+   UINT32 msgSize = ntohl(msg->size);
    NXCP_ENCRYPTED_MESSAGE *emsg = 
       (NXCP_ENCRYPTED_MESSAGE *)malloc(msgSize + NXCP_ENCRYPTION_HEADER_SIZE + EVP_CIPHER_block_size(EVP_CIPHER_CTX_cipher(&m_encryptor)) + 8);
-   emsg->wCode = htons(CMD_ENCRYPTED_MESSAGE);
-   emsg->nReserved = 0;
+   emsg->code = htons(CMD_ENCRYPTED_MESSAGE);
+   emsg->reserved = 0;
 
    NXCP_ENCRYPTED_PAYLOAD_HEADER header;
    header.dwChecksum = htonl(CalculateCRC32((BYTE *)msg, msgSize, 0));
@@ -726,7 +726,7 @@ NXCP_ENCRYPTED_MESSAGE *NXCPEncryptionContext::encryptMessage(CSCP_MESSAGE *msg)
    int dataSize;
    EVP_EncryptUpdate(&m_encryptor, emsg->data, &dataSize, (BYTE *)&header, NXCP_EH_ENCRYPTED_BYTES);
    msgSize = dataSize;
-   EVP_EncryptUpdate(&m_encryptor, emsg->data + msgSize, &dataSize, (BYTE *)msg, ntohl(msg->dwSize));
+   EVP_EncryptUpdate(&m_encryptor, emsg->data + msgSize, &dataSize, (BYTE *)msg, ntohl(msg->size));
    msgSize += dataSize;
    EVP_EncryptFinal_ex(&m_encryptor, emsg->data + msgSize, &dataSize);
    msgSize += dataSize + NXCP_EH_UNENCRYPTED_BYTES;
@@ -735,14 +735,14 @@ NXCP_ENCRYPTED_MESSAGE *NXCPEncryptionContext::encryptMessage(CSCP_MESSAGE *msg)
 
    if (msgSize % 8 != 0)
    {
-      emsg->nPadding = (BYTE)(8 - (msgSize % 8));
-      msgSize += emsg->nPadding;
+      emsg->padding = (BYTE)(8 - (msgSize % 8));
+      msgSize += emsg->padding;
    }
    else
    {
-      emsg->nPadding = 0;
+      emsg->padding = 0;
    }
-   emsg->dwSize = htonl(msgSize);
+   emsg->size = htonl(msgSize);
 
    return emsg;
 #else    /* _WITH_ENCRYPTION */
@@ -759,15 +759,15 @@ bool NXCPEncryptionContext::decryptMessage(NXCP_ENCRYPTED_MESSAGE *msg, BYTE *de
    if (!EVP_DecryptInit_ex(&m_decryptor, NULL, NULL, m_sessionKey, m_iv))
       return false;
 
-   msg->dwSize = ntohl(msg->dwSize);
+   msg->size = ntohl(msg->size);
    int dataSize;
    EVP_DecryptUpdate(&m_decryptor, decryptionBuffer, &dataSize, msg->data,
-                     msg->dwSize - NXCP_EH_UNENCRYPTED_BYTES - msg->nPadding);
+                     msg->size - NXCP_EH_UNENCRYPTED_BYTES - msg->padding);
    EVP_DecryptFinal(&m_decryptor, decryptionBuffer + dataSize, &dataSize);
 
-   CSCP_MESSAGE *clearMsg = (CSCP_MESSAGE *)(decryptionBuffer + NXCP_EH_ENCRYPTED_BYTES);
-   UINT32 msgSize = ntohl(clearMsg->dwSize);
-   if (msgSize > msg->dwSize)
+   NXCP_MESSAGE *clearMsg = (NXCP_MESSAGE *)(decryptionBuffer + NXCP_EH_ENCRYPTED_BYTES);
+   UINT32 msgSize = ntohl(clearMsg->size);
+   if (msgSize > msg->size)
       return false;  // Message decrypted incorrectly, because it can't be larger than encrypted
    UINT32 crc32 = CalculateCRC32((BYTE *)clearMsg, msgSize, 0);
    if (crc32 != ntohl(((NXCP_ENCRYPTED_PAYLOAD_HEADER *)decryptionBuffer)->dwChecksum))
index fb070c8..5f48636 100644 (file)
@@ -95,36 +95,36 @@ GeoLocation::GeoLocation(const GeoLocation &src)
 /**
  * Create geolocation object from data in NXCP message
  */
-GeoLocation::GeoLocation(CSCPMessage &msg)
+GeoLocation::GeoLocation(NXCPMessage &msg)
 {
-       m_type = (int)msg.GetVariableShort(VID_GEOLOCATION_TYPE);
+       m_type = (int)msg.getFieldAsUInt16(VID_GEOLOCATION_TYPE);
 
-   if (msg.getFieldType(VID_LATITUDE) == CSCP_DT_INT32)
+   if (msg.getFieldType(VID_LATITUDE) == NXCP_DT_INT32)
           m_lat = (double)msg.getFieldAsInt32(VID_LATITUDE) / 1000000;
    else
           m_lat = msg.getFieldAsDouble(VID_LATITUDE);
 
-   if (msg.getFieldType(VID_LONGITUDE) == CSCP_DT_INT32)
+   if (msg.getFieldType(VID_LONGITUDE) == NXCP_DT_INT32)
           m_lon = (double)msg.getFieldAsInt32(VID_LONGITUDE) / 1000000;
    else
        m_lon = msg.getFieldAsDouble(VID_LONGITUDE);
 
-       m_accuracy = (int)msg.GetVariableShort(VID_ACCURACY);
+       m_accuracy = (int)msg.getFieldAsUInt16(VID_ACCURACY);
 
    m_timestamp = 0;
    int ft = msg.getFieldType(VID_GEOLOCATION_TIMESTAMP);
-   if (ft == CSCP_DT_INT64)
+   if (ft == NXCP_DT_INT64)
    {
-      m_timestamp = (time_t)msg.GetVariableInt64(VID_GEOLOCATION_TIMESTAMP);
+      m_timestamp = (time_t)msg.getFieldAsUInt64(VID_GEOLOCATION_TIMESTAMP);
    }
-   else if (ft == CSCP_DT_INT32)
+   else if (ft == NXCP_DT_INT32)
    {
-      m_timestamp = (time_t)msg.GetVariableLong(VID_GEOLOCATION_TIMESTAMP);
+      m_timestamp = (time_t)msg.getFieldAsUInt32(VID_GEOLOCATION_TIMESTAMP);
    }
-   else if (ft == CSCP_DT_STRING)
+   else if (ft == NXCP_DT_STRING)
    {
       char ts[256];
-      msg.GetVariableStrA(VID_GEOLOCATION_TIMESTAMP, ts, 256);
+      msg.getFieldAsMBString(VID_GEOLOCATION_TIMESTAMP, ts, 256);
 
       struct tm timeBuff;
       if (strptime(ts, "%Y/%m/%d %H:%M:%S", &timeBuff) != NULL)
@@ -167,13 +167,13 @@ GeoLocation& GeoLocation::operator =(const GeoLocation &src)
 /**
  * Fill NXCP message
  */
-void GeoLocation::fillMessage(CSCPMessage &msg)
+void GeoLocation::fillMessage(NXCPMessage &msg)
 {
-       msg.SetVariable(VID_GEOLOCATION_TYPE, (WORD)m_type);
-       msg.SetVariable(VID_LATITUDE, m_lat);
-       msg.SetVariable(VID_LONGITUDE, m_lon);
-       msg.SetVariable(VID_ACCURACY, (WORD)m_accuracy);
-       msg.SetVariable(VID_GEOLOCATION_TIMESTAMP, (QWORD)m_timestamp);
+       msg.setField(VID_GEOLOCATION_TYPE, (WORD)m_type);
+       msg.setField(VID_LATITUDE, m_lat);
+       msg.setField(VID_LONGITUDE, m_lon);
+       msg.setField(VID_ACCURACY, (WORD)m_accuracy);
+       msg.setField(VID_GEOLOCATION_TIMESTAMP, (QWORD)m_timestamp);
 }
 
 /**
index 2e809d3..0af4c7c 100644 (file)
 **
 **/
 #include "libnetxms.h"
-#include <expat.h>
 #include <uthash.h>
 
 /**
- * XML parser state codes for creating CSCPMessage object from XML
- */
-enum ParserStates
-{
-   XML_STATE_INIT = -1,
-   XML_STATE_END = -2,
-   XML_STATE_ERROR = -255,
-   XML_STATE_NXCP = 0,
-   XML_STATE_MESSAGE = 1,
-   XML_STATE_VARIABLE = 2,
-   XML_STATE_VALUE = 3
-};
-
-/**
- * XML parser state data
- */
-typedef struct
-{
-       CSCPMessage *msg;
-       int state;
-       int valueLen;
-       char *value;
-       int varType;
-       UINT32 varId;
-} XML_PARSER_STATE;
-
-/**
  * Calculate field size
  */
-static size_t CalculateFieldSize(CSCP_DF *field, bool networkByteOrder)
+static size_t CalculateFieldSize(NXCP_MESSAGE_FIELD *field, bool networkByteOrder)
 {
    size_t nSize;
 
-   switch(field->bType)
+   switch(field->type)
    {
-      case CSCP_DT_INT32:
+      case NXCP_DT_INT32:
          nSize = 12;
          break;
-      case CSCP_DT_INT64:
-      case CSCP_DT_FLOAT:
+      case NXCP_DT_INT64:
+      case NXCP_DT_FLOAT:
          nSize = 16;
          break;
-      case CSCP_DT_INT16:
+      case NXCP_DT_INT16:
          nSize = 8;
          break;
-      case CSCP_DT_STRING:
-      case CSCP_DT_BINARY:
+      case NXCP_DT_STRING:
+      case NXCP_DT_BINARY:
          if (networkByteOrder)
-            nSize = ntohl(field->df_string.dwLen) + 12;
+            nSize = ntohl(field->df_string.length) + 12;
          else
-            nSize = field->df_string.dwLen + 12;
+            nSize = field->df_string.length + 12;
          break;
       default:
          nSize = 8;
@@ -92,7 +64,7 @@ struct MessageField
    UT_hash_handle hh;
    UINT32 id;
    size_t size;
-   CSCP_DF data;
+   NXCP_MESSAGE_FIELD data;
 };
 
 /**
@@ -100,16 +72,16 @@ struct MessageField
  */
 inline MessageField *CreateMessageField(size_t fieldSize)
 {
-   size_t entrySize = sizeof(MessageField) - sizeof(CSCP_DF) + fieldSize;
+   size_t entrySize = sizeof(MessageField) - sizeof(NXCP_MESSAGE_FIELD) + fieldSize;
    MessageField *entry = (MessageField *)calloc(1, entrySize);
    entry->size = entrySize;
    return entry;
 }
 
 /**
- * Default constructor for CSCPMessage class
+ * Default constructor for NXCPMessage class
  */
-CSCPMessage::CSCPMessage(int version)
+NXCPMessage::NXCPMessage(int version)
 {
    m_code = 0;
    m_id = 0;
@@ -123,23 +95,23 @@ CSCPMessage::CSCPMessage(int version)
 /**
  * Create a copy of prepared CSCP message
  */
-CSCPMessage::CSCPMessage(CSCPMessage *pMsg)
+NXCPMessage::NXCPMessage(NXCPMessage *msg)
 {
-   m_code = pMsg->m_code;
-   m_id = pMsg->m_id;
-   m_flags = pMsg->m_flags;
-   m_version = pMsg->m_version;
+   m_code = msg->m_code;
+   m_id = msg->m_id;
+   m_flags = msg->m_flags;
+   m_version = msg->m_version;
    m_fields = NULL;
-   m_dataSize = pMsg->m_dataSize;
+   m_dataSize = msg->m_dataSize;
 
    if (m_flags & MF_BINARY)
    {
-      m_data = (BYTE *)nx_memdup(pMsg->m_data, m_dataSize);
+      m_data = (BYTE *)nx_memdup(msg->m_data, m_dataSize);
    }
    else
    {
       MessageField *entry, *tmp;
-      HASH_ITER(hh, pMsg->m_fields, entry, tmp)
+      HASH_ITER(hh, msg->m_fields, entry, tmp)
       {
          MessageField *f = (MessageField *)nx_memdup(entry, entry->size);
          HASH_ADD_INT(m_fields, id, f);
@@ -148,46 +120,46 @@ CSCPMessage::CSCPMessage(CSCPMessage *pMsg)
 }
 
 /**
- * Create CSCPMessage object from received message
+ * Create NXCPMessage object from received message
  */
-CSCPMessage::CSCPMessage(CSCP_MESSAGE *pMsg, int version)
+NXCPMessage::NXCPMessage(NXCP_MESSAGE *msg, int version)
 {
    UINT32 i;
 
-   m_flags = ntohs(pMsg->wFlags);
-   m_code = ntohs(pMsg->wCode);
-   m_id = ntohl(pMsg->dwId);
+   m_flags = ntohs(msg->flags);
+   m_code = ntohs(msg->code);
+   m_id = ntohl(msg->id);
    m_version = version;
    m_fields = NULL;
 
    // Parse data fields
    if (m_flags & MF_BINARY)
    {
-      m_dataSize = (size_t)ntohl(pMsg->dwNumVars);
-      m_data = (BYTE *)nx_memdup(pMsg->df, m_dataSize);
+      m_dataSize = (size_t)ntohl(msg->numFields);
+      m_data = (BYTE *)nx_memdup(msg->fields, m_dataSize);
    }
    else
    {
       m_data = NULL;
       m_dataSize = 0;
 
-      int fieldCount = (int)ntohl(pMsg->dwNumVars);
-      size_t dwSize = ntohl(pMsg->dwSize);
+      int fieldCount = (int)ntohl(msg->numFields);
+      size_t size = (size_t)ntohl(msg->size);
       size_t pos = NXCP_HEADER_SIZE;
       for(int f = 0; f < fieldCount; f++)
       {
-         CSCP_DF *field = (CSCP_DF *)(((BYTE *)pMsg) + pos);
+         NXCP_MESSAGE_FIELD *field = (NXCP_MESSAGE_FIELD *)(((BYTE *)msg) + pos);
 
          // Validate position inside message
-         if (pos > dwSize - 8)
+         if (pos > size - 8)
             break;
-         if ((pos > dwSize - 12) && 
-             ((field->bType == CSCP_DT_STRING) || (field->bType == CSCP_DT_BINARY)))
+         if ((pos > size - 12) && 
+             ((field->type == NXCP_DT_STRING) || (field->type == NXCP_DT_BINARY)))
             break;
 
          // Calculate and validate variable size
          size_t fieldSize = CalculateFieldSize(field, true);
-         if (pos + fieldSize > dwSize)
+         if (pos + fieldSize > size)
             break;
 
          // Create new entry
@@ -197,29 +169,29 @@ CSCPMessage::CSCPMessage(CSCP_MESSAGE *pMsg, int version)
 
          // Convert values to host format
          entry->data.fieldId = ntohl(entry->data.fieldId);
-         switch(field->bType)
+         switch(field->type)
          {
-            case CSCP_DT_INT32:
+            case NXCP_DT_INT32:
                entry->data.df_int32 = ntohl(entry->data.df_int32);
                break;
-            case CSCP_DT_INT64:
+            case NXCP_DT_INT64:
                entry->data.df_int64 = ntohq(entry->data.df_int64);
                break;
-            case CSCP_DT_INT16:
+            case NXCP_DT_INT16:
                entry->data.df_int16 = ntohs(entry->data.df_int16);
                break;
-            case CSCP_DT_FLOAT:
+            case NXCP_DT_FLOAT:
                entry->data.df_real = ntohd(entry->data.df_real);
                break;
-            case CSCP_DT_STRING:
+            case NXCP_DT_STRING:
 #if !(WORDS_BIGENDIAN)
-               entry->data.df_string.dwLen = ntohl(entry->data.df_string.dwLen);
-               for(i = 0; i < entry->data.df_string.dwLen / 2; i++)
-                  entry->data.df_string.szValue[i] = ntohs(entry->data.df_string.szValue[i]);
+               entry->data.df_string.length = ntohl(entry->data.df_string.length);
+               for(i = 0; i < entry->data.df_string.length / 2; i++)
+                  entry->data.df_string.value[i] = ntohs(entry->data.df_string.value[i]);
 #endif
                break;
-            case CSCP_DT_BINARY:
-               entry->data.df_string.dwLen = ntohl(entry->data.df_string.dwLen);
+            case NXCP_DT_BINARY:
+               entry->data.df_string.length = ntohl(entry->data.df_string.length);
                break;
          }
 
@@ -236,197 +208,18 @@ CSCPMessage::CSCPMessage(CSCP_MESSAGE *pMsg, int version)
 }
 
 /**
- * Create CSCPMessage object from XML document
+ * Destructor for NXCPMessage
  */
-static void StartElement(void *userData, const char *name, const char **attrs)
-{
-       if (!strcmp(name, "nxcp"))
-       {
-               ((XML_PARSER_STATE *)userData)->state = XML_STATE_NXCP;
-       }
-       else if (!strcmp(name, "message"))
-       {
-               ((XML_PARSER_STATE *)userData)->state = XML_STATE_MESSAGE;
-       }
-       else if (!strcmp(name, "variable"))
-       {
-               ((XML_PARSER_STATE *)userData)->state = XML_STATE_VARIABLE;
-       }
-       else if (!strcmp(name, "value"))
-       {
-               ((XML_PARSER_STATE *)userData)->valueLen = 1;
-               ((XML_PARSER_STATE *)userData)->value = NULL;
-               ((XML_PARSER_STATE *)userData)->state = XML_STATE_VALUE;
-       }
-       else
-       {
-               ((XML_PARSER_STATE *)userData)->state = XML_STATE_ERROR;
-       }
-       if (((XML_PARSER_STATE *)userData)->state != XML_STATE_ERROR)
-               ((XML_PARSER_STATE *)userData)->msg->processXMLToken(userData, attrs);
-}
-
-static void EndElement(void *userData, const char *name)
-{
-       if (!strcmp(name, "nxcp"))
-       {
-               ((XML_PARSER_STATE *)userData)->state = XML_STATE_END;
-       }
-       else if (!strcmp(name, "message"))
-       {
-               ((XML_PARSER_STATE *)userData)->state = XML_STATE_NXCP;
-       }
-       else if (!strcmp(name, "variable"))
-       {
-               ((XML_PARSER_STATE *)userData)->state = XML_STATE_MESSAGE;
-       }
-       else if (!strcmp(name, "value"))
-       {
-               ((XML_PARSER_STATE *)userData)->msg->processXMLData(userData);
-               safe_free(((XML_PARSER_STATE *)userData)->value);
-               ((XML_PARSER_STATE *)userData)->state = XML_STATE_VARIABLE;
-       }
-}
-
-static void CharData(void *userData, const XML_Char *s, int len)
-{
-       XML_PARSER_STATE *ps = (XML_PARSER_STATE *)userData;
-
-       if (ps->state != XML_STATE_VALUE)
-               return;
-
-       ps->value = (char *)realloc(ps->value, ps->valueLen + len);
-       memcpy(&ps->value[ps->valueLen - 1], s, len);
-       ps->valueLen += len;
-       ps->value[ps->valueLen - 1] = 0;
-}
-
-CSCPMessage::CSCPMessage(const char *xml)
-{
-       XML_Parser parser = XML_ParserCreate(NULL);
-       XML_PARSER_STATE state;
-
-       // Default values
-   m_code = 0;
-   m_id = 0;
-   m_fields = NULL;
-   m_flags = 0;
-   m_version = NXCP_VERSION;
-   m_data = NULL;
-   m_dataSize = 0;
-
-       // Parse XML
-       state.msg = this;
-       state.state = -1;
-       XML_SetUserData(parser, &state);
-       XML_SetElementHandler(parser, StartElement, EndElement);
-       XML_SetCharacterDataHandler(parser, CharData);
-       if (XML_Parse(parser, xml, (int)strlen(xml), TRUE) == XML_STATUS_ERROR)
-       {
-/*fprintf(stderr,
-        "%s at line %d\n",
-        XML_ErrorString(XML_GetErrorCode(parser)),
-        XML_GetCurrentLineNumber(parser));*/
-       }
-       XML_ParserFree(parser);
-}
-
-void CSCPMessage::processXMLToken(void *state, const char **attrs)
+NXCPMessage::~NXCPMessage()
 {
-       XML_PARSER_STATE *ps = (XML_PARSER_STATE *)state;
-       const char *type;
-       static const char *types[] = { "int32", "string", "int64", "int16", "binary", "float", NULL };
-
-       switch(ps->state)
-       {
-               case XML_STATE_NXCP:
-                       m_version = XMLGetAttrInt(attrs, "version", m_version);
-                       break;
-               case XML_STATE_MESSAGE:
-                       m_id = XMLGetAttrUINT32(attrs, "id", m_id);
-                       m_code = (WORD)XMLGetAttrUINT32(attrs, "code", m_code);
-                       break;
-               case XML_STATE_VARIABLE:
-                       ps->varId = XMLGetAttrUINT32(attrs, "id", 0);
-                       type = XMLGetAttr(attrs, "type");
-                       if (type != NULL)
-                       {
-                               int i;
-
-                               for(i = 0; types[i] != NULL; i++)
-                                       if (!stricmp(types[i], type))
-                                       {
-                                               ps->varType = i;
-                                               break;
-                                       }
-                       }
-                       break;
-               default:
-                       break;
-       }
-}
-
-void CSCPMessage::processXMLData(void *state)
-{
-       XML_PARSER_STATE *ps = (XML_PARSER_STATE *)state;
-       char *binData;
-       size_t binLen;
-#ifdef UNICODE
-       WCHAR *temp;
-#endif
-
-       if (ps->value == NULL)
-               return;
-
-       switch(ps->varType)
-       {
-               case CSCP_DT_INT32:
-                       SetVariable(ps->varId, (UINT32)strtoul(ps->value, NULL, 0));
-                       break;
-               case CSCP_DT_INT16:
-                       SetVariable(ps->varId, (WORD)strtoul(ps->value, NULL, 0));
-                       break;
-               case CSCP_DT_INT64:
-                       SetVariable(ps->varId, (UINT64)strtoull(ps->value, NULL, 0));
-                       break;
-               case CSCP_DT_FLOAT:
-                       SetVariable(ps->varId, strtod(ps->value, NULL));
-                       break;
-               case CSCP_DT_STRING:
-#ifdef UNICODE
-                       temp = WideStringFromUTF8String(ps->value);
-                       SetVariable(ps->varId, temp);
-                       free(temp);
-#else
-                       SetVariable(ps->varId, ps->value);
-#endif
-                       break;
-               case CSCP_DT_BINARY:
-                       if (base64_decode_alloc(ps->value, ps->valueLen, &binData, &binLen))
-                       {
-                               if (binData != NULL)
-                               {
-                                       SetVariable(ps->varId, (BYTE *)binData, (UINT32)binLen);
-                                       free(binData);
-                               }
-                       }
-                       break;
-       }
-}
-
-/**
- * Destructor for CSCPMessage
- */
-CSCPMessage::~CSCPMessage()
-{
-   deleteAllVariables();
+   deleteAllFields();
    safe_free(m_data);
 }
 
 /**
  * Find field by ID
  */
-CSCP_DF *CSCPMessage::find(UINT32 fieldId)
+NXCP_MESSAGE_FIELD *NXCPMessage::find(UINT32 fieldId)
 {
    MessageField *entry;
    HASH_FIND_INT(m_fields, &fieldId, entry);
@@ -435,75 +228,75 @@ CSCP_DF *CSCPMessage::find(UINT32 fieldId)
 
 /**
  * set variable
- * Argument dwSize (data size) contains data length in bytes for DT_BINARY type
+ * Argument size (data size) contains data length in bytes for DT_BINARY type
  * and maximum number of characters for DT_STRING type (0 means no limit)
  */
-void *CSCPMessage::set(UINT32 fieldId, BYTE bType, const void *pValue, UINT32 dwSize)
+void *NXCPMessage::set(UINT32 fieldId, BYTE type, const void *value, size_t size)
 {
    if (m_flags & MF_BINARY)
       return NULL;
 
-   UINT32 dwLength;
+   size_t length;
 #if defined(UNICODE_UCS2) && defined(UNICODE)
-#define __buffer pValue
+#define __buffer value
 #else
    UCS2CHAR *__buffer;
 #endif
 
    // Create entry
    MessageField *entry;
-   switch(bType)
+   switch(type)
    {
-      case CSCP_DT_INT32:
+      case NXCP_DT_INT32:
          entry = CreateMessageField(12);
-         entry->data.df_int32 = *((const UINT32 *)pValue);
+         entry->data.df_int32 = *((const UINT32 *)value);
          break;
-      case CSCP_DT_INT16:
+      case NXCP_DT_INT16:
          entry = CreateMessageField(8);
-         entry->data.df_int16 = *((const WORD *)pValue);
+         entry->data.df_int16 = *((const WORD *)value);
          break;
-      case CSCP_DT_INT64:
+      case NXCP_DT_INT64:
          entry = CreateMessageField(16);
-         entry->data.df_int64 = *((const UINT64 *)pValue);
+         entry->data.df_int64 = *((const UINT64 *)value);
          break;
-      case CSCP_DT_FLOAT:
+      case NXCP_DT_FLOAT:
          entry = CreateMessageField(16);
-         entry->data.df_real = *((const double *)pValue);
+         entry->data.df_real = *((const double *)value);
          break;
-      case CSCP_DT_STRING:
+      case NXCP_DT_STRING:
 #ifdef UNICODE         
-         dwLength = (UINT32)_tcslen((const TCHAR *)pValue);
-                       if ((dwSize > 0) && (dwLength > dwSize))
-                               dwLength = dwSize;
+         length = _tcslen((const TCHAR *)value);
+                       if ((size > 0) && (length > size))
+                               length = size;
 #ifndef UNICODE_UCS2 /* assume UNICODE_UCS4 */
-         __buffer = (UCS2CHAR *)malloc(dwLength * 2 + 2);
-         ucs4_to_ucs2((WCHAR *)pValue, dwLength, __buffer, dwLength + 1);
+         __buffer = (UCS2CHAR *)malloc(length * 2 + 2);
+         ucs4_to_ucs2((WCHAR *)value, length, __buffer, length + 1);
 #endif         
 #else          /* not UNICODE */
-                       __buffer = UCS2StringFromMBString((const char *)pValue);
-                       dwLength = (UINT32)ucs2_strlen(__buffer);
-                       if ((dwSize > 0) && (dwLength > dwSize))
-                               dwLength = dwSize;
+                       __buffer = UCS2StringFromMBString((const char *)value);
+                       length = (UINT32)ucs2_strlen(__buffer);
+                       if ((size > 0) && (length > size))
+                               length = size;
 #endif
-         entry = CreateMessageField(12 + dwLength * 2);
-         entry->data.df_string.dwLen = dwLength * 2;
-         memcpy(entry->data.df_string.szValue, __buffer, entry->data.df_string.dwLen);
+         entry = CreateMessageField(12 + length * 2);
+         entry->data.df_string.length = (UINT32)(length * 2);
+         memcpy(entry->data.df_string.value, __buffer, entry->data.df_string.length);
 #if !defined(UNICODE_UCS2) || !defined(UNICODE)
          free(__buffer);
 #endif
          break;
-      case CSCP_DT_BINARY:
-         entry = CreateMessageField(12 + dwSize);
-         entry->data.df_string.dwLen = dwSize;
-         if ((entry->data.df_string.dwLen > 0) && (pValue != NULL))
-            memcpy(entry->data.df_string.szValue, pValue, entry->data.df_string.dwLen);
+      case NXCP_DT_BINARY:
+         entry = CreateMessageField(12 + size);
+         entry->data.df_string.length = (UINT32)size;
+         if ((entry->data.df_string.length > 0) && (value != NULL))
+            memcpy(entry->data.df_string.value, value, entry->data.df_string.length);
          break;
       default:
          return NULL;  // Invalid data type, unable to handle
    }
    entry->id = fieldId;
    entry->data.fieldId = fieldId;
-   entry->data.bType = bType;
+   entry->data.type = type;
 
    // add or replace field
    MessageField *curr;
@@ -515,26 +308,26 @@ void *CSCPMessage::set(UINT32 fieldId, BYTE bType, const void *pValue, UINT32 dw
    }
    HASH_ADD_INT(m_fields, id, entry);
 
-   return (bType == CSCP_DT_INT16) ? ((void *)((BYTE *)&entry->data + 6)) : ((void *)((BYTE *)&entry->data + 8));
+   return (type == NXCP_DT_INT16) ? ((void *)((BYTE *)&entry->data + 6)) : ((void *)((BYTE *)&entry->data + 8));
 #undef __buffer
 }
 
 /**
  * get field value
  */
-void *CSCPMessage::get(UINT32 fieldId, BYTE requiredType, BYTE *fieldType)
+void *NXCPMessage::get(UINT32 fieldId, BYTE requiredType, BYTE *fieldType)
 {
-   CSCP_DF *field = find(fieldId);
+   NXCP_MESSAGE_FIELD *field = find(fieldId);
    if (field == NULL)
       return NULL;      // No such field
 
    // Check data type
-   if ((requiredType != 0xFF) && (field->bType != requiredType))
+   if ((requiredType != 0xFF) && (field->type != requiredType))
       return NULL;
 
    if (fieldType != NULL)
-      *fieldType = field->bType;
-   return (field->bType == CSCP_DT_INT16) ?
+      *fieldType = field->type;
+   return (field->type == NXCP_DT_INT16) ?
            ((void *)((BYTE *)field + 6)) : 
            ((void *)((BYTE *)field + 8));
 }
@@ -542,7 +335,7 @@ void *CSCPMessage::get(UINT32 fieldId, BYTE requiredType, BYTE *fieldType)
 /**
  * get 16 bit field as boolean
  */
-bool CSCPMessage::getFieldAsBoolean(UINT32 fieldId)
+bool NXCPMessage::getFieldAsBoolean(UINT32 fieldId)
 {
    BYTE type;
    void *value = (void *)get(fieldId, 0xFF, &type);
@@ -551,11 +344,11 @@ bool CSCPMessage::getFieldAsBoolean(UINT32 fieldId)
 
    switch(type)
    {
-      case CSCP_DT_INT16:
+      case NXCP_DT_INT16:
          return *((UINT16 *)value) ? true : false;
-      case CSCP_DT_INT32:
+      case NXCP_DT_INT32:
          return *((UINT32 *)value) ? true : false;
-      case CSCP_DT_INT64:
+      case NXCP_DT_INT64:
          return *((UINT64 *)value) ? true : false;
       default:
          return false;
@@ -567,79 +360,79 @@ bool CSCPMessage::getFieldAsBoolean(UINT32 fieldId)
  *
  * @return field type or -1 if field with given ID does not exist
  */
-int CSCPMessage::getFieldType(UINT32 fieldId)
+int NXCPMessage::getFieldType(UINT32 fieldId)
 {
-   CSCP_DF *field = find(fieldId);
-   return (field != NULL) ? (int)field->bType : -1;
+   NXCP_MESSAGE_FIELD *field = find(fieldId);
+   return (field != NULL) ? (int)field->type : -1;
 }
 
 /**
  * get signed integer field
  */
-INT32 CSCPMessage::getFieldAsInt32(UINT32 fieldId)
+INT32 NXCPMessage::getFieldAsInt32(UINT32 fieldId)
 {
-   char *value = (char *)get(fieldId, CSCP_DT_INT32);
+   char *value = (char *)get(fieldId, NXCP_DT_INT32);
    return (value != NULL) ? *((INT32 *)value) : 0;
 }
 
 /**
  * get unsigned integer field
  */
-UINT32 CSCPMessage::GetVariableLong(UINT32 fieldId)
+UINT32 NXCPMessage::getFieldAsUInt32(UINT32 fieldId)
 {
-   void *value = get(fieldId, CSCP_DT_INT32);
+   void *value = get(fieldId, NXCP_DT_INT32);
    return (value != NULL) ? *((UINT32 *)value) : 0;
 }
 
 /**
  * get signed 16-bit integer field
  */
-INT16 CSCPMessage::getFieldAsInt16(UINT32 fieldId)
+INT16 NXCPMessage::getFieldAsInt16(UINT32 fieldId)
 {
-   void *value = get(fieldId, CSCP_DT_INT16);
+   void *value = get(fieldId, NXCP_DT_INT16);
    return (value != NULL) ? *((INT16 *)value) : 0;
 }
 
 /**
  * get unsigned 16-bit integer variable
  */
-UINT16 CSCPMessage::GetVariableShort(UINT32 fieldId)
+UINT16 NXCPMessage::getFieldAsUInt16(UINT32 fieldId)
 {
-   void *pValue = get(fieldId, CSCP_DT_INT16);
-   return pValue ? *((WORD *)pValue) : 0;
+   void *value = get(fieldId, NXCP_DT_INT16);
+   return value ? *((WORD *)value) : 0;
 }
 
 /**
  * get signed 64-bit integer field
  */
-INT64 CSCPMessage::getFieldAsInt64(UINT32 fieldId)
+INT64 NXCPMessage::getFieldAsInt64(UINT32 fieldId)
 {
-   void *value = get(fieldId, CSCP_DT_INT64);
+   void *value = get(fieldId, NXCP_DT_INT64);
    return (value != NULL) ? *((INT64 *)value) : 0;
 }
 
 /**
  * get unsigned 64-bit integer field
  */
-UINT64 CSCPMessage::GetVariableInt64(UINT32 fieldId)
+UINT64 NXCPMessage::getFieldAsUInt64(UINT32 fieldId)
 {
-   void *pValue = get(fieldId, CSCP_DT_INT64);
-   return pValue ? *((UINT64 *)pValue) : 0;
+   void *value = get(fieldId, NXCP_DT_INT64);
+   return value ? *((UINT64 *)value) : 0;
 }
 
 /**
  * get 64-bit floating point variable
  */
-double CSCPMessage::getFieldAsDouble(UINT32 fieldId)
+double NXCPMessage::getFieldAsDouble(UINT32 fieldId)
 {
-   void *value = get(fieldId, CSCP_DT_FLOAT);
+   void *value = get(fieldId, NXCP_DT_FLOAT);
    return (value != NULL) ? *((double *)value) : 0;
 }
 
 /**
  * get time_t field
  */
-time_t CSCPMessage::getFieldAsTime(UINT32 fieldId)
+time_t NXCPMessage::getFieldAsTime(UINT32 fieldId)
 {
    BYTE type;
    void *value = (void *)get(fieldId, 0xFF, &type);
@@ -648,9 +441,9 @@ time_t CSCPMessage::getFieldAsTime(UINT32 fieldId)
 
    switch(type)
    {
-      case CSCP_DT_INT32:
+      case NXCP_DT_INT32:
          return (time_t)(*((UINT32 *)value));
-      case CSCP_DT_INT64:
+      case NXCP_DT_INT64:
          return (time_t)(*((UINT64 *)value));
       default:
          return false;
@@ -662,50 +455,47 @@ time_t CSCPMessage::getFieldAsTime(UINT32 fieldId)
  * If szBuffer is NULL, memory block of required size will be allocated
  * for result; if szBuffer is not NULL, entire result or part of it will
  * be placed to szBuffer and pointer to szBuffer will be returned.
- * Note: dwBufSize is buffer size in characters, not bytes!
+ * Note: bufferSize is buffer size in characters, not bytes!
  */
-TCHAR *CSCPMessage::GetVariableStr(UINT32 fieldId, TCHAR *pszBuffer, UINT32 dwBufSize)
+TCHAR *NXCPMessage::getFieldAsString(UINT32 fieldId, TCHAR *buffer, size_t bufferSize)
 {
-   void *pValue;
-   TCHAR *str = NULL;
-   UINT32 dwLen;
-
-   if ((pszBuffer != NULL) && (dwBufSize == 0))
+   if ((buffer != NULL) && (bufferSize == 0))
       return NULL;   // non-sense combination
 
-   pValue = get(fieldId, CSCP_DT_STRING);
-   if (pValue != NULL)
+   TCHAR *str = NULL;
+   void *value = get(fieldId, NXCP_DT_STRING);
+   if (value != NULL)
    {
-      if (pszBuffer == NULL)
+      if (buffer == NULL)
       {
 #if defined(UNICODE) && defined(UNICODE_UCS4)
-         str = (TCHAR *)malloc(*((UINT32 *)pValue) * 2 + 4);
+         str = (TCHAR *)malloc(*((UINT32 *)value) * 2 + 4);
 #elif defined(UNICODE) && defined(UNICODE_UCS2)
-         str = (TCHAR *)malloc(*((UINT32 *)pValue) + 2);
+         str = (TCHAR *)malloc(*((UINT32 *)value) + 2);
 #else
-         str = (TCHAR *)malloc(*((UINT32 *)pValue) / 2 + 1);
+         str = (TCHAR *)malloc(*((UINT32 *)value) / 2 + 1);
 #endif
       }
       else
       {
-         str = pszBuffer;
+         str = buffer;
       }
 
-      dwLen = (pszBuffer == NULL) ? (*((UINT32 *)pValue) / 2) : min(*((UINT32 *)pValue) / 2, dwBufSize - 1);
+      size_t length = (buffer == NULL) ? (*((UINT32 *)value) / 2) : min(*((UINT32 *)value) / 2, bufferSize - 1);
 #if defined(UNICODE) && defined(UNICODE_UCS4)
-               ucs2_to_ucs4((UCS2CHAR *)((BYTE *)pValue + 4), dwLen, str, dwLen + 1);
+               ucs2_to_ucs4((UCS2CHAR *)((BYTE *)value + 4), length, str, length + 1);
 #elif defined(UNICODE) && defined(UNICODE_UCS2)
-      memcpy(str, (BYTE *)pValue + 4, dwLen * 2);
+      memcpy(str, (BYTE *)value + 4, length * 2);
 #else
-               ucs2_to_mb((UCS2CHAR *)((BYTE *)pValue + 4), dwLen, str, dwLen + 1);
+               ucs2_to_mb((UCS2CHAR *)((BYTE *)value + 4), length, str, length + 1);
 #endif
-      str[dwLen] = 0;
+      str[length] = 0;
    }
    else
    {
-      if (pszBuffer != NULL)
+      if (buffer != NULL)
       {
-         str = pszBuffer;
+         str = buffer;
          str[0] = 0;
       }
    }
@@ -717,36 +507,33 @@ TCHAR *CSCPMessage::GetVariableStr(UINT32 fieldId, TCHAR *pszBuffer, UINT32 dwBu
 /**
  * get variable as multibyte string
  */
-char *CSCPMessage::GetVariableStrA(UINT32 fieldId, char *pszBuffer, UINT32 dwBufSize)
+char *NXCPMessage::getFieldAsMBString(UINT32 fieldId, char *buffer, size_t bufferSize)
 {
-   void *pValue;
-   char *str = NULL;
-   UINT32 dwLen;
-
-   if ((pszBuffer != NULL) && (dwBufSize == 0))
+   if ((buffer != NULL) && (bufferSize == 0))
       return NULL;   // non-sense combination
 
-   pValue = get(fieldId, CSCP_DT_STRING);
-   if (pValue != NULL)
+   char *str = NULL;
+   void *value = get(fieldId, NXCP_DT_STRING);
+   if (value != NULL)
    {
-      if (pszBuffer == NULL)
+      if (buffer == NULL)
       {
-         str = (char *)malloc(*((UINT32 *)pValue) / 2 + 1);
+         str = (char *)malloc(*((UINT32 *)value) / 2 + 1);
       }
       else
       {
-         str = pszBuffer;
+         str = buffer;
       }
 
-      dwLen = (pszBuffer == NULL) ? (*((UINT32 *)pValue) / 2) : min(*((UINT32 *)pValue) / 2, dwBufSize - 1);
-               ucs2_to_mb((UCS2CHAR *)((BYTE *)pValue + 4), dwLen, str, dwLen + 1);
-      str[dwLen] = 0;
+      size_t length = (buffer == NULL) ? (*((UINT32 *)value) / 2) : min(*((UINT32 *)value) / 2, bufferSize - 1);
+               ucs2_to_mb((UCS2CHAR *)((BYTE *)value + 4), (int)length, str, (int)length + 1);
+      str[length] = 0;
    }
    else
    {
-      if (pszBuffer != NULL)
+      if (buffer != NULL)
       {
-         str = pszBuffer;
+         str = buffer;
          str[0] = 0;
       }
    }
@@ -758,9 +545,9 @@ char *CSCPMessage::GetVariableStrA(UINT32 fieldId, char *pszBuffer, UINT32 dwBuf
 /**
  * get field as multibyte string
  */
-char *CSCPMessage::GetVariableStrA(UINT32 fieldId, char *pszBuffer, UINT32 dwBufSize)
+char *NXCPMessage::getFieldAsMBString(UINT32 fieldId, char *buffer, size_t bufferSize)
 {
-       return GetVariableStr(fieldId, pszBuffer, dwBufSize);
+       return getFieldAsString(fieldId, buffer, bufferSize);
 }
 
 #endif
@@ -768,44 +555,41 @@ char *CSCPMessage::GetVariableStrA(UINT32 fieldId, char *pszBuffer, UINT32 dwBuf
 /**
  * get field as UTF-8 string
  */
-char *CSCPMessage::GetVariableStrUTF8(UINT32 fieldId, char *pszBuffer, UINT32 dwBufSize)
+char *NXCPMessage::getFieldAsUtf8String(UINT32 fieldId, char *buffer, size_t bufferSize)
 {
-   void *pValue;
-   char *str = NULL;
-   UINT32 dwLen, dwOutSize;
-       int cc;
-
-   if ((pszBuffer != NULL) && (dwBufSize == 0))
+   if ((buffer != NULL) && (bufferSize == 0))
       return NULL;   // non-sense combination
 
-   pValue = get(fieldId, CSCP_DT_STRING);
-   if (pValue != NULL)
+   char *str = NULL;
+   void *value = get(fieldId, NXCP_DT_STRING);
+   if (value != NULL)
    {
-      if (pszBuffer == NULL)
+      int outSize;
+      if (buffer == NULL)
       {
                        // Assume worst case scenario - 3 bytes per character
-                       dwOutSize = *((UINT32 *)pValue) + *((UINT32 *)pValue) / 2 + 1;
-         str = (char *)malloc(dwOutSize);
+                       outSize = (int)(*((UINT32 *)value) + *((UINT32 *)value) / 2 + 1);
+         str = (char *)malloc(outSize);
       }
       else
       {
-                       dwOutSize = dwBufSize;
-         str = pszBuffer;
+                       outSize = (int)bufferSize;
+         str = buffer;
       }
 
-      dwLen = *((UINT32 *)pValue) / 2;
+      size_t length = *((UINT32 *)value) / 2;
 #ifdef UNICODE_UCS2
-               cc = WideCharToMultiByte(CP_UTF8, 0, (WCHAR *)((BYTE *)pValue + 4), dwLen, str, dwOutSize - 1, NULL, NULL);
+               int cc = WideCharToMultiByte(CP_UTF8, 0, (WCHAR *)((BYTE *)value + 4), (int)length, str, outSize - 1, NULL, NULL);
 #else
-               cc = ucs2_to_utf8((UCS2CHAR *)((BYTE *)pValue + 4), dwLen, str, dwOutSize - 1);
+               int cc = ucs2_to_utf8((UCS2CHAR *)((BYTE *)value + 4), (int)length, str, outSize - 1);
 #endif
       str[cc] = 0;
    }
    else
    {
-      if (pszBuffer != NULL)
+      if (buffer != NULL)
       {
-         str = pszBuffer;
+         str = buffer;
          str[0] = 0;
       }
    }
@@ -814,19 +598,19 @@ char *CSCPMessage::GetVariableStrUTF8(UINT32 fieldId, char *pszBuffer, UINT32 dw
 
 /**
  * get binary (byte array) field
- * Result will be placed to the buffer provided (no more than dwBufSize bytes,
+ * Result will be placed to the buffer provided (no more than bufferSize bytes,
  * and actual size of data will be returned
  * If pBuffer is NULL, just actual data length is returned
  */
-UINT32 CSCPMessage::GetVariableBinary(UINT32 fieldId, BYTE *pBuffer, UINT32 dwBufSize)
+UINT32 NXCPMessage::getFieldAsBinary(UINT32 fieldId, BYTE *pBuffer, size_t bufferSize)
 {
    UINT32 size;
-   void *value = get(fieldId, CSCP_DT_BINARY);
+   void *value = get(fieldId, NXCP_DT_BINARY);
    if (value != NULL)
    {
       size = *((UINT32 *)value);
       if (pBuffer != NULL)
-         memcpy(pBuffer, (BYTE *)value + 4, min(dwBufSize, size));
+         memcpy(pBuffer, (BYTE *)value + 4, min(bufferSize, size));
    }
    else
    {
@@ -840,10 +624,10 @@ UINT32 CSCPMessage::GetVariableBinary(UINT32 fieldId, BYTE *pBuffer, UINT32 dwBu
  * Returns pointer to internal buffer or NULL if field not found
  * Data length set in size parameter.
  */
-BYTE *CSCPMessage::getBinaryFieldPtr(UINT32 fieldId, size_t *size)
+BYTE *NXCPMessage::getBinaryFieldPtr(UINT32 fieldId, size_t *size)
 {
    BYTE *data;
-   void *value = get(fieldId, CSCP_DT_BINARY);
+   void *value = get(fieldId, NXCP_DT_BINARY);
    if (value != NULL)
    {
       *size = (size_t)(*((UINT32 *)value));
@@ -860,7 +644,7 @@ BYTE *CSCPMessage::getBinaryFieldPtr(UINT32 fieldId, size_t *size)
 /**
  * Build protocol message ready to be send over the wire
  */
-CSCP_MESSAGE *CSCPMessage::createMessage()
+NXCP_MESSAGE *NXCPMessage::createMessage()
 {
    // Calculate message size
    size_t size = NXCP_HEADER_SIZE;
@@ -892,22 +676,22 @@ CSCP_MESSAGE *CSCPMessage::createMessage()
    }
 
    // Create message
-   CSCP_MESSAGE *pMsg = (CSCP_MESSAGE *)malloc(size);
-   memset(pMsg, 0, size);
-   pMsg->wCode = htons(m_code);
-   pMsg->wFlags = htons(m_flags);
-   pMsg->dwSize = htonl((UINT32)size);
-   pMsg->dwId = htonl(m_id);
-   pMsg->dwNumVars = htonl(fieldCount);
+   NXCP_MESSAGE *msg = (NXCP_MESSAGE *)malloc(size);
+   memset(msg, 0, size);
+   msg->code = htons(m_code);
+   msg->flags = htons(m_flags);
+   msg->size = htonl((UINT32)size);
+   msg->id = htonl(m_id);
+   msg->numFields = htonl(fieldCount);
 
    // Fill data fields
    if (m_flags & MF_BINARY)
    {
-      memcpy(pMsg->df, m_data, m_dataSize);
+      memcpy(msg->fields, m_data, m_dataSize);
    }
    else
    {
-      CSCP_DF *field = (CSCP_DF *)((char *)pMsg + NXCP_HEADER_SIZE);
+      NXCP_MESSAGE_FIELD *field = (NXCP_MESSAGE_FIELD *)((char *)msg + NXCP_HEADER_SIZE);
       MessageField *entry, *tmp;
       HASH_ITER(hh, m_fields, entry, tmp)
       {
@@ -916,47 +700,47 @@ CSCP_MESSAGE *CSCPMessage::createMessage()
 
          // Convert numeric values to network format
          field->fieldId = htonl(field->fieldId);
-         switch(field->bType)
+         switch(field->type)
          {
-            case CSCP_DT_INT32:
+            case NXCP_DT_INT32:
                field->df_int32 = htonl(field->df_int32);
                break;
-            case CSCP_DT_INT64:
+            case NXCP_DT_INT64:
                field->df_int64 = htonq(field->df_int64);
                break;
-            case CSCP_DT_INT16:
+            case NXCP_DT_INT16:
                field->df_int16 = htons(field->df_int16);
                break;
-            case CSCP_DT_FLOAT:
+            case NXCP_DT_FLOAT:
                field->df_real = htond(field->df_real);
                break;
-            case CSCP_DT_STRING:
+            case NXCP_DT_STRING:
 #if !(WORDS_BIGENDIAN)
                {
-                  for(UINT32 i = 0; i < field->df_string.dwLen / 2; i++)
-                     field->df_string.szValue[i] = htons(field->df_string.szValue[i]);
-                  field->df_string.dwLen = htonl(field->df_string.dwLen);
+                  for(UINT32 i = 0; i < field->df_string.length / 2; i++)
+                     field->df_string.value[i] = htons(field->df_string.value[i]);
+                  field->df_string.length = htonl(field->df_string.length);
                }
 #endif
                break;
-            case CSCP_DT_BINARY:
-               field->df_string.dwLen = htonl(field->df_string.dwLen);
+            case NXCP_DT_BINARY:
+               field->df_string.length = htonl(field->df_string.length);
                break;
          }
 
          if (m_version >= 2)
-            field = (CSCP_DF *)((char *)field + fieldSize + ((8 - (fieldSize % 8)) & 7));
+            field = (NXCP_MESSAGE_FIELD *)((char *)field + fieldSize + ((8 - (fieldSize % 8)) & 7));
          else
-            field = (CSCP_DF *)((char *)field + fieldSize);
+            field = (NXCP_MESSAGE_FIELD *)((char *)field + fieldSize);
       }
    }
-   return pMsg;
+   return msg;
 }
 
 /**
  * Delete all variables
  */
-void CSCPMessage::deleteAllVariables()
+void NXCPMessage::deleteAllFields()
 {
    MessageField *entry, *tmp;
    HASH_ITER(hh, m_fields, entry, tmp)
@@ -971,10 +755,10 @@ void CSCPMessage::deleteAllVariables()
 /**
  * set variable from multibyte string
  */
-void CSCPMessage::SetVariableFromMBString(UINT32 fieldId, const char *pszValue)
+void NXCPMessage::setFieldFromMBString(UINT32 fieldId, const char *value)
 {
-       WCHAR *wcValue = WideStringFromMBString(pszValue);
-       set(fieldId, CSCP_DT_STRING, wcValue);
+       WCHAR *wcValue = WideStringFromMBString(value);
+       set(fieldId, NXCP_DT_STRING, wcValue);
        free(wcValue);
 }
 
@@ -983,9 +767,9 @@ void CSCPMessage::SetVariableFromMBString(UINT32 fieldId, const char *pszValue)
 /**
  * set binary field to an array of UINT32s
  */
-void CSCPMessage::setFieldInt32Array(UINT32 fieldId, UINT32 dwNumElements, const UINT32 *pdwData)
+void NXCPMessage::setFieldFromInt32Array(UINT32 fieldId, UINT32 dwNumElements, const UINT32 *pdwData)
 {
-   UINT32 *pdwBuffer = (UINT32 *)set(fieldId, CSCP_DT_BINARY, pdwData, dwNumElements * sizeof(UINT32));
+   UINT32 *pdwBuffer = (UINT32 *)set(fieldId, NXCP_DT_BINARY, pdwData, dwNumElements * sizeof(UINT32));
    if (pdwBuffer != NULL)
    {
       pdwBuffer++;   // First UINT32 is a length field
@@ -997,9 +781,9 @@ void CSCPMessage::setFieldInt32Array(UINT32 fieldId, UINT32 dwNumElements, const
 /**
  * set binary field to an array of UINT32s
  */
-void CSCPMessage::setFieldInt32Array(UINT32 fieldId, IntegerArray<UINT32> *data)
+void NXCPMessage::setFieldFromInt32Array(UINT32 fieldId, IntegerArray<UINT32> *data)
 {
-   UINT32 *pdwBuffer = (UINT32 *)set(fieldId, CSCP_DT_BINARY, data->getBuffer(), data->size() * sizeof(UINT32));
+   UINT32 *pdwBuffer = (UINT32 *)set(fieldId, NXCP_DT_BINARY, data->getBuffer(), data->size() * sizeof(UINT32));
    if (pdwBuffer != NULL)
    {
       pdwBuffer++;   // First UINT32 is a length field
@@ -1011,9 +795,9 @@ void CSCPMessage::setFieldInt32Array(UINT32 fieldId, IntegerArray<UINT32> *data)
 /**
  * get binary field as an array of 32 bit unsigned integers
  */
-UINT32 CSCPMessage::getFieldAsInt32Array(UINT32 fieldId, UINT32 numElements, UINT32 *buffer)
+UINT32 NXCPMessage::getFieldAsInt32Array(UINT32 fieldId, UINT32 numElements, UINT32 *buffer)
 {
-   UINT32 size = GetVariableBinary(fieldId, (BYTE *)buffer, numElements * sizeof(UINT32));
+   UINT32 size = getFieldAsBinary(fieldId, (BYTE *)buffer, numElements * sizeof(UINT32));
    size /= sizeof(UINT32);   // Convert bytes to elements
    for(UINT32 i = 0; i < size; i++)
       buffer[i] = ntohl(buffer[i]);
@@ -1023,11 +807,11 @@ UINT32 CSCPMessage::getFieldAsInt32Array(UINT32 fieldId, UINT32 numElements, UIN
 /**
  * get binary field as an array of 32 bit unsigned integers
  */
-UINT32 CSCPMessage::getFieldAsInt32Array(UINT32 fieldId, IntegerArray<UINT32> *data)
+UINT32 NXCPMessage::getFieldAsInt32Array(UINT32 fieldId, IntegerArray<UINT32> *data)
 {
    data->clear();
 
-   UINT32 *value = (UINT32 *)get(fieldId, CSCP_DT_BINARY);
+   UINT32 *value = (UINT32 *)get(fieldId, NXCP_DT_BINARY);
    if (value != NULL)
    {
       UINT32 size = *value;
@@ -1044,21 +828,21 @@ UINT32 CSCPMessage::getFieldAsInt32Array(UINT32 fieldId, IntegerArray<UINT32> *d
 /**
  * set binary field from file
  */
-bool CSCPMessage::setFieldFromFile(UINT32 fieldId, const TCHAR *pszFileName)
+bool NXCPMessage::setFieldFromFile(UINT32 fieldId, const TCHAR *pszFileName)
 {
    FILE *pFile;
    BYTE *pBuffer;
-   UINT32 dwSize;
+   UINT32 size;
    bool bResult = false;
 
-   dwSize = (UINT32)FileSize(pszFileName);
+   size = (UINT32)FileSize(pszFileName);
    pFile = _tfopen(pszFileName, _T("rb"));
    if (pFile != NULL)
    {
-      pBuffer = (BYTE *)set(fieldId, CSCP_DT_BINARY, NULL, dwSize);
+      pBuffer = (BYTE *)set(fieldId, NXCP_DT_BINARY, NULL, size);
       if (pBuffer != NULL)
       {
-         if (fread(pBuffer + sizeof(UINT32), 1, dwSize, pFile) == dwSize)
+         if (fread(pBuffer + sizeof(UINT32), 1, size, pFile) == size)
             bResult = true;
       }
       fclose(pFile);
@@ -1067,95 +851,6 @@ bool CSCPMessage::setFieldFromFile(UINT32 fieldId, const TCHAR *pszFileName)
 }
 
 /**
- * Create XML document
- */
-char *CSCPMessage::createXML()
-{
-       String xml;
-       char *out, *bdata;
-       size_t blen;
-       TCHAR *tempStr;
-#if !defined(UNICODE) || defined(UNICODE_UCS4)
-       int bytes;
-#endif
-       static const TCHAR *dtString[] = { _T("int32"), _T("string"), _T("int64"), _T("int16"), _T("binary"), _T("float") };
-
-       xml.addFormattedString(_T("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<nxcp version=\"%d\">\r\n   <message code=\"%d\" id=\"%d\">\r\n"), m_version, m_code, m_id);
-   MessageField *entry, *tmp;
-   HASH_ITER(hh, m_fields, entry, tmp)
-       {
-               xml.addFormattedString(_T("      <variable id=\"%d\" type=\"%s\">\r\n         <value>"),
-                                      entry->data.fieldId, dtString[entry->data.bType]);
-               switch(entry->data.bType)
-               {
-                       case CSCP_DT_INT32:
-                               xml.addFormattedString(_T("%d"), entry->data.data.dwInteger);
-                               break;
-                       case CSCP_DT_INT16:
-                               xml.addFormattedString(_T("%d"), entry->data.wInt16);
-                               break;
-                       case CSCP_DT_INT64:
-                               xml.addFormattedString(INT64_FMT, entry->data.data.qwInt64);
-                               break;
-                       case CSCP_DT_STRING:
-#ifdef UNICODE
-#ifdef UNICODE_UCS2
-                               xml.addDynamicString(EscapeStringForXML((TCHAR *)entry->data.data.string.szValue, entry->data.data.string.dwLen / 2));
-#else
-                               tempStr = (WCHAR *)malloc(entry->data.data.string.dwLen * 2);
-                               bytes = ucs2_to_ucs4(entry->data.data.string.szValue, entry->data.data.string.dwLen / 2, tempStr, entry->data.data.string.dwLen / 2);
-                               xml.addDynamicString(EscapeStringForXML(tempStr, bytes));
-                               free(tempStr);
-#endif
-#else          /* not UNICODE */
-#ifdef UNICODE_UCS2
-                               bytes = WideCharToMultiByte(CP_UTF8, 0, (UCS2CHAR *)entry->data.data.string.szValue,
-                                                           entry->data.data.string.dwLen / 2, NULL, 0, NULL, NULL);
-                               tempStr = (char *)malloc(bytes + 1);
-                               bytes = WideCharToMultiByte(CP_UTF8, 0, (UCS2CHAR *)entry->data.data.string.szValue,
-                                                           entry->data.data.string.dwLen / 2, tempStr, bytes + 1, NULL, NULL);
-                               xml.addDynamicString(EscapeStringForXML(tempStr, bytes));
-                               free(tempStr);
-#else
-                               tempStr = (char *)malloc(entry->data.data.string.dwLen);
-                               bytes = ucs2_to_utf8(entry->data.data.string.szValue, entry->data.data.string.dwLen / 2, tempStr, entry->data.data.string.dwLen);
-                               xml.addDynamicString(EscapeStringForXML(tempStr, bytes));
-                               free(tempStr);
-#endif
-#endif /* UNICODE */
-                               break;
-                       case CSCP_DT_BINARY:
-                               blen = base64_encode_alloc((char *)entry->data.data.string.szValue,
-                                                          entry->data.data.string.dwLen, &bdata);
-                               if ((blen != 0) && (bdata != NULL))
-                               {
-#ifdef UNICODE
-                                       tempStr = (WCHAR *)malloc((blen + 1) * sizeof(WCHAR));
-                                       MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, bdata, (int)blen, tempStr, (int)blen);
-                                       tempStr[blen] = 0;
-                                       xml.addDynamicString(tempStr);
-#else
-                                       xml.addString(bdata, (UINT32)blen);
-#endif
-                               }
-                               safe_free(bdata);
-                               break;
-                       default:
-                               break;
-               }
-               xml += _T("</value>\r\n      </variable>\r\n");
-       }
-       xml += _T("   </message>\r\n</nxcp>\r\n");
-
-#ifdef UNICODE
-       out = UTF8StringFromWideString(xml);
-#else
-       out = strdup(xml);
-#endif
-       return out;
-}
-
-/**
  * Get string from field
  */
 static TCHAR *GetStringFromField(void *df)
@@ -1182,22 +877,22 @@ static TCHAR *GetStringFromField(void *df)
 /**
  * Dump NXCP message
  */
-String CSCPMessage::dump(CSCP_MESSAGE *pMsg, int version)
+String NXCPMessage::dump(NXCP_MESSAGE *msg, int version)
 {
    String out;
    int i;
    TCHAR *str, buffer[128];
 
-   WORD flags = ntohs(pMsg->wFlags);
-   WORD code = ntohs(pMsg->wCode);
-   UINT32 id = ntohl(pMsg->dwId);
-   UINT32 size = ntohl(pMsg->dwSize);
-   int numFields = (int)ntohl(pMsg->dwNumVars);
+   WORD flags = ntohs(msg->flags);
+   WORD code = ntohs(msg->code);
+   UINT32 id = ntohl(msg->id);
+   UINT32 size = ntohl(msg->size);
+   int numFields = (int)ntohl(msg->numFields);
 
    // Dump raw message
    for(i = 0; i < (int)size; i += 16)
    {
-      BinToStr(((BYTE *)pMsg) + i, min(16, size - i), buffer); 
+      BinToStr(((BYTE *)msg) + i, min(16, size - i), buffer); 
       out.addFormattedString(_T("  ** %s\n"), buffer);
    }
 
@@ -1214,7 +909,7 @@ String CSCPMessage::dump(CSCP_MESSAGE *pMsg, int version)
    size_t pos = NXCP_HEADER_SIZE;
    for(int f = 0; f < numFields; f++)
    {
-      CSCP_DF *field = (CSCP_DF *)(((BYTE *)pMsg) + pos);
+      NXCP_MESSAGE_FIELD *field = (NXCP_MESSAGE_FIELD *)(((BYTE *)msg) + pos);
 
       // Validate position inside message
       if (pos > size - 8)
@@ -1223,9 +918,9 @@ String CSCPMessage::dump(CSCP_MESSAGE *pMsg, int version)
          break;
       }
       if ((pos > size - 12) && 
-          ((field->bType == CSCP_DT_STRING) || (field->bType == CSCP_DT_BINARY)))
+          ((field->type == NXCP_DT_STRING) || (field->type == NXCP_DT_BINARY)))
       {
-         out.addFormattedString(_T("  ** message format error (pos > size - 8 and field type %d)\n"), (int)field->bType);
+         out.addFormattedString(_T("  ** message format error (pos > size - 8 and field type %d)\n"), (int)field->type);
          break;
       }
 
@@ -1238,45 +933,45 @@ String CSCPMessage::dump(CSCP_MESSAGE *pMsg, int version)
       }
 
       // Create new entry
-      CSCP_DF *convertedField = (CSCP_DF *)malloc(fieldSize);
+      NXCP_MESSAGE_FIELD *convertedField = (NXCP_MESSAGE_FIELD *)malloc(fieldSize);
       memcpy(convertedField, field, fieldSize);
 
       // Convert numeric values to host format
       convertedField->fieldId = ntohl(convertedField->fieldId);
-      switch(field->bType)
+      switch(field->type)
       {
-         case CSCP_DT_INT32:
+         case NXCP_DT_INT32:
             convertedField->df_int32 = ntohl(convertedField->df_int32);
             out.addFormattedString(_T("  ** [%6d] INT32  %d\n"), (int)convertedField->fieldId, convertedField->df_int32);
             break;
-         case CSCP_DT_INT64:
+         case NXCP_DT_INT64:
             convertedField->df_int64 = ntohq(convertedField->df_int64);
             out.addFormattedString(_T("  ** [%6d] INT64  ") INT64_FMT _T("\n"), (int)convertedField->fieldId, convertedField->df_int64);
             break;
-         case CSCP_DT_INT16:
+         case NXCP_DT_INT16:
             convertedField->df_int16 = ntohs(convertedField->df_int16);
             out.addFormattedString(_T("  ** [%6d] INT16  %d\n"), (int)convertedField->fieldId, (int)convertedField->df_int16);
             break;
-         case CSCP_DT_FLOAT:
+         case NXCP_DT_FLOAT:
             convertedField->df_real = ntohd(convertedField->df_real);
             out.addFormattedString(_T("  ** [%6d] FLOAT  %f\n"), (int)convertedField->fieldId, convertedField->df_real);
             break;
-         case CSCP_DT_STRING:
+         case NXCP_DT_STRING:
 #if !(WORDS_BIGENDIAN)
-            convertedField->df_string.dwLen = ntohl(convertedField->df_string.dwLen);
-            for(i = 0; i < (int)convertedField->df_string.dwLen / 2; i++)
-               convertedField->df_string.szValue[i] = ntohs(convertedField->df_string.szValue[i]);
+            convertedField->df_string.length = ntohl(convertedField->df_string.length);
+            for(i = 0; i < (int)convertedField->df_string.length / 2; i++)
+               convertedField->df_string.value[i] = ntohs(convertedField->df_string.value[i]);
 #endif
             str = GetStringFromField((BYTE *)convertedField + 8);
             out.addFormattedString(_T("  ** [%6d] STRING \"%s\"\n"), (int)convertedField->fieldId, str);
             free(str);
             break;
-         case CSCP_DT_BINARY:
-            convertedField->df_string.dwLen = ntohl(convertedField->df_string.dwLen);
-            out.addFormattedString(_T("  ** [%6d] BINARY len=%d\n"), (int)convertedField->fieldId, (int)convertedField->df_string.dwLen);
+         case NXCP_DT_BINARY:
+            convertedField->df_string.length = ntohl(convertedField->df_string.length);
+            out.addFormattedString(_T("  ** [%6d] BINARY len=%d\n"), (int)convertedField->fieldId, (int)convertedField->df_string.length);
             break;
          default:
-            out.addFormattedString(_T("  ** [%6d] unknown type %d\n"), (int)convertedField->fieldId, (int)field->bType);
+            out.addFormattedString(_T("  ** [%6d] unknown type %d\n"), (int)convertedField->fieldId, (int)field->type);
             break;
       }
       free(convertedField);
index 7959fd6..67afe19 100644 (file)
@@ -50,16 +50,16 @@ AbstractMessageReceiver::~AbstractMessageReceiver()
 /**
  * Get message from buffer
  */
-CSCPMessage *AbstractMessageReceiver::getMessageFromBuffer()
+NXCPMessage *AbstractMessageReceiver::getMessageFromBuffer()
 {
-   CSCPMessage *msg = NULL;
+   NXCPMessage *msg = NULL;
 
    if (m_dataSize >= NXCP_HEADER_SIZE)
    {
-      size_t msgSize = (size_t)ntohl(((CSCP_MESSAGE *)m_buffer)->dwSize);
+      size_t msgSize = (size_t)ntohl(((NXCP_MESSAGE *)m_buffer)->size);
       if (msgSize <= m_dataSize)
       {
-         if (ntohs(((CSCP_MESSAGE *)m_buffer)->wCode) == CMD_ENCRYPTED_MESSAGE)
+         if (ntohs(((NXCP_MESSAGE *)m_buffer)->code) == CMD_ENCRYPTED_MESSAGE)
          {
             if ((m_encryptionContext != NULL) && (m_encryptionContext != PROXY_ENCRYPTION_CTX))
             {
@@ -67,13 +67,13 @@ CSCPMessage *AbstractMessageReceiver::getMessageFromBuffer()
                   m_decryptionBuffer = (BYTE *)malloc(m_size);
                if (m_encryptionContext->decryptMessage((NXCP_ENCRYPTED_MESSAGE *)m_buffer, m_decryptionBuffer))
                {
-                  msg = new CSCPMessage((CSCP_MESSAGE *)m_buffer);
+                  msg = new NXCPMessage((NXCP_MESSAGE *)m_buffer);
                }
             }
          }
          else
          {
-            msg = new CSCPMessage((CSCP_MESSAGE *)m_buffer);
+            msg = new NXCPMessage((NXCP_MESSAGE *)m_buffer);
          }
          m_dataSize -= msgSize;
          if (m_dataSize > 0)
@@ -103,9 +103,9 @@ CSCPMessage *AbstractMessageReceiver::getMessageFromBuffer()
 /**
  * Read message from communication channel
  */
-CSCPMessage *AbstractMessageReceiver::readMessage(UINT32 timeout, MessageReceiverResult *result)
+NXCPMessage *AbstractMessageReceiver::readMessage(UINT32 timeout, MessageReceiverResult *result)
 {
-   CSCPMessage *msg;
+   NXCPMessage *msg;
    while(true)
    {
       msg = getMessageFromBuffer();
@@ -142,6 +142,21 @@ CSCPMessage *AbstractMessageReceiver::readMessage(UINT32 timeout, MessageReceive
 }
 
 /**
+ * Convert result to text
+ */
+const TCHAR *AbstractMessageReceiver::resultToText(MessageReceiverResult result)
+{
+   static TCHAR *text[] = { 
+      _T("MSGRECV_SUCCESS"), 
+      _T("MSGRECV_CLOSED"), 
+      _T("MSGRECV_TIMEOUT"), 
+      _T("MSGRECV_COMM_FAILURE"), 
+      _T("MSGRECV_DECRYPTION_FAILURE") 
+   };
+   return ((result >= MSGRECV_SUCCESS) && (result <= MSGRECV_DECRYPTION_FAILURE)) ? text[result] : _T("UNKNOWN");
+}
+
+/**
  * Socket message receiver constructor
  */
 SocketMessageReceiver::SocketMessageReceiver(SOCKET socket, size_t initialSize, size_t maxSize) : AbstractMessageReceiver(initialSize, maxSize)
index 500cdec..15a7a5b 100644 (file)
@@ -99,7 +99,7 @@ void MsgWaitQueue::clear()
       }
       else
       {
-         delete (CSCPMessage *)(m_elements[i].msg);
+         delete (NXCPMessage *)(m_elements[i].msg);
       }
    }
    m_size = 0;
@@ -111,7 +111,7 @@ void MsgWaitQueue::clear()
 /**
  * Put message into queue
  */
-void MsgWaitQueue::put(CSCPMessage *pMsg)
+void MsgWaitQueue::put(NXCPMessage *pMsg)
 {
    lock();
 
@@ -128,9 +128,9 @@ void MsgWaitQueue::put(CSCPMessage *pMsg)
       for(pos = 0; m_elements[pos].msg != NULL; pos++);
    }
        
-   m_elements[pos].code = pMsg->GetCode();
+   m_elements[pos].code = pMsg->getCode();
    m_elements[pos].isBinary = 0;
-   m_elements[pos].id = pMsg->GetId();
+   m_elements[pos].id = pMsg->getId();
    m_elements[pos].ttl = m_holdTime;
    m_elements[pos].msg = pMsg;
    m_size++;
@@ -149,7 +149,7 @@ void MsgWaitQueue::put(CSCPMessage *pMsg)
 /**
  * Put raw message into queue
  */
-void MsgWaitQueue::put(CSCP_MESSAGE *pMsg)
+void MsgWaitQueue::put(NXCP_MESSAGE *pMsg)
 {
    lock();
 
@@ -166,9 +166,9 @@ void MsgWaitQueue::put(CSCP_MESSAGE *pMsg)
       for(pos = 0; m_elements[pos].msg != NULL; pos++);
    }
 
-   m_elements[pos].code = pMsg->wCode;
+   m_elements[pos].code = pMsg->code;
    m_elements[pos].isBinary = 1;
-   m_elements[pos].id = pMsg->dwId;
+   m_elements[pos].id = pMsg->id;
    m_elements[pos].ttl = m_holdTime;
    m_elements[pos].msg = pMsg;
    m_size++;
@@ -305,7 +305,7 @@ void MsgWaitQueue::housekeeperThread()
             }
             else
             {
-               delete (CSCPMessage *)(m_elements[i].msg);
+               delete (NXCPMessage *)(m_elements[i].msg);
             }
             m_elements[i].msg = NULL;
             m_size--;
index 6529d8f..aff33e3 100644 (file)
@@ -32,7 +32,7 @@
 /**
  * Get symbolic name for message code
  */
-TCHAR LIBNETXMS_EXPORTABLE *NXCPMessageCodeName(WORD wCode, TCHAR *pszBuffer)
+TCHAR LIBNETXMS_EXPORTABLE *NXCPMessageCodeName(WORD code, TCHAR *pszBuffer)
 {
    static const TCHAR *pszMsgNames[] =
    {
@@ -344,10 +344,10 @@ TCHAR LIBNETXMS_EXPORTABLE *NXCPMessageCodeName(WORD wCode, TCHAR *pszBuffer)
       _T("CMD_QUERY_ADHOC_SUMMARY_TABLE")
    };
 
-   if ((wCode >= CMD_LOGIN) && (wCode <= CMD_QUERY_ADHOC_SUMMARY_TABLE))
-      _tcscpy(pszBuffer, pszMsgNames[wCode - CMD_LOGIN]);
+   if ((code >= CMD_LOGIN) && (code <= CMD_QUERY_ADHOC_SUMMARY_TABLE))
+      _tcscpy(pszBuffer, pszMsgNames[code - CMD_LOGIN]);
    else
-      _sntprintf(pszBuffer, 64, _T("CMD_0x%04X"), wCode);
+      _sntprintf(pszBuffer, 64, _T("CMD_0x%04X"), code);
    return pszBuffer;
 }
 
@@ -363,8 +363,8 @@ TCHAR LIBNETXMS_EXPORTABLE *NXCPMessageCodeName(WORD wCode, TCHAR *pszBuffer)
  *   2 Message decryption failed
  *   3 Receive timeout
  */
-int LIBNETXMS_EXPORTABLE RecvNXCPMessageEx(SOCKET hSocket, CSCP_MESSAGE **msgBuffer,
-                                           CSCP_BUFFER *nxcpBuffer, UINT32 *bufferSize,
+int LIBNETXMS_EXPORTABLE RecvNXCPMessageEx(SOCKET hSocket, NXCP_MESSAGE **msgBuffer,
+                                           NXCP_BUFFER *nxcpBuffer, UINT32 *bufferSize,
                                            NXCPEncryptionContext **ppCtx,
                                            BYTE **decryptionBuffer, UINT32 dwTimeout,
                                                                                                                 UINT32 maxMsgSize)
@@ -376,94 +376,94 @@ int LIBNETXMS_EXPORTABLE RecvNXCPMessageEx(SOCKET hSocket, CSCP_MESSAGE **msgBuf
    // Initialize buffer if requested
    if (msgBuffer == NULL)
    {
-      nxcpBuffer->dwBufSize = 0;
-      nxcpBuffer->dwBufPos = 0;
+      nxcpBuffer->bufferSize = 0;
+      nxcpBuffer->bufferPos = 0;
       return 0;
    }
 
    // Check if we have something in buffer
-   if (nxcpBuffer->dwBufSize > 0)
+   if (nxcpBuffer->bufferSize > 0)
    {
       // Handle the case when entire message header have not been read into the buffer
-      if (nxcpBuffer->dwBufSize < NXCP_HEADER_SIZE)
+      if (nxcpBuffer->bufferSize < NXCP_HEADER_SIZE)
       {
          // Most likely we are at the buffer end, so move content
          // to the beginning
-         memmove(nxcpBuffer->szBuffer, &nxcpBuffer->szBuffer[nxcpBuffer->dwBufPos], nxcpBuffer->dwBufSize);
-         nxcpBuffer->dwBufPos = 0;
+         memmove(nxcpBuffer->buffer, &nxcpBuffer->buffer[nxcpBuffer->bufferPos], nxcpBuffer->bufferSize);
+         nxcpBuffer->bufferPos = 0;
 
          // Receive new portion of data from the network
          // and append it to existing data in buffer
-                       iErr = RecvEx(hSocket, &nxcpBuffer->szBuffer[nxcpBuffer->dwBufSize],
-                       CSCP_TEMP_BUF_SIZE - nxcpBuffer->dwBufSize, 0, dwTimeout);
+                       iErr = RecvEx(hSocket, &nxcpBuffer->buffer[nxcpBuffer->bufferSize],
+                       CSCP_TEMP_BUF_SIZE - nxcpBuffer->bufferSize, 0, dwTimeout);
          if (iErr <= 0)
             return (iErr == -2) ? 3 : iErr;
-         nxcpBuffer->dwBufSize += (UINT32)iErr;
+         nxcpBuffer->bufferSize += (UINT32)iErr;
       }
 
       // Get message size from message header and copy available
       // message bytes from buffer
-      dwMsgSize = ntohl(((CSCP_MESSAGE *)(&nxcpBuffer->szBuffer[nxcpBuffer->dwBufPos]))->dwSize);
+      dwMsgSize = ntohl(((NXCP_MESSAGE *)(&nxcpBuffer->buffer[nxcpBuffer->bufferPos]))->size);
       if (dwMsgSize > *bufferSize)
       {
                        if ((*bufferSize >= maxMsgSize) || (dwMsgSize > maxMsgSize))
                        {
                                bSkipMsg = TRUE;  // Message is too large, will skip it
-                               memcpy(*msgBuffer, &nxcpBuffer->szBuffer[nxcpBuffer->dwBufPos], NXCP_HEADER_SIZE);
+                               memcpy(*msgBuffer, &nxcpBuffer->buffer[nxcpBuffer->bufferPos], NXCP_HEADER_SIZE);
                        }
                        else
                        {
                                // Increase buffer
                                *bufferSize = dwMsgSize;
-                               *msgBuffer = (CSCP_MESSAGE *)realloc(*msgBuffer, *bufferSize);
+                               *msgBuffer = (NXCP_MESSAGE *)realloc(*msgBuffer, *bufferSize);
                                if (decryptionBuffer != NULL)
                                        *decryptionBuffer = (BYTE *)realloc(*decryptionBuffer, *bufferSize);
                        }
       }
-      dwBytesRead = min(dwMsgSize, nxcpBuffer->dwBufSize);
+      dwBytesRead = min(dwMsgSize, nxcpBuffer->bufferSize);
       if (!bSkipMsg)
-         memcpy(*msgBuffer, &nxcpBuffer->szBuffer[nxcpBuffer->dwBufPos], dwBytesRead);
-      nxcpBuffer->dwBufSize -= dwBytesRead;
-      nxcpBuffer->dwBufPos = (nxcpBuffer->dwBufSize > 0) ? (nxcpBuffer->dwBufPos + dwBytesRead) : 0;
+         memcpy(*msgBuffer, &nxcpBuffer->buffer[nxcpBuffer->bufferPos], dwBytesRead);
+      nxcpBuffer->bufferSize -= dwBytesRead;
+      nxcpBuffer->bufferPos = (nxcpBuffer->bufferSize > 0) ? (nxcpBuffer->bufferPos + dwBytesRead) : 0;
       if (dwBytesRead == dwMsgSize)
          goto decrypt_message;
    }
 
    // Receive rest of message from the network
        // Buffer is empty now
-       nxcpBuffer->dwBufSize = 0;
-       nxcpBuffer->dwBufPos = 0;
+       nxcpBuffer->bufferSize = 0;
+       nxcpBuffer->bufferPos = 0;
    do
    {
-               iErr = RecvEx(hSocket, &nxcpBuffer->szBuffer[nxcpBuffer->dwBufSize],
-                             CSCP_TEMP_BUF_SIZE - nxcpBuffer->dwBufSize, 0, dwTimeout);
+               iErr = RecvEx(hSocket, &nxcpBuffer->buffer[nxcpBuffer->bufferSize],
+                             CSCP_TEMP_BUF_SIZE - nxcpBuffer->bufferSize, 0, dwTimeout);
       if (iErr <= 0)
          return (iErr == -2) ? 3 : iErr;
 
                if (dwBytesRead == 0) // New message?
       {
-                       if ((iErr + nxcpBuffer->dwBufSize) < NXCP_HEADER_SIZE)
+                       if ((iErr + nxcpBuffer->bufferSize) < NXCP_HEADER_SIZE)
                        {
                                // Header not received completely
-                               nxcpBuffer->dwBufSize += iErr;
+                               nxcpBuffer->bufferSize += iErr;
                                continue;
                        }
-                       iErr += nxcpBuffer->dwBufSize;
-                       nxcpBuffer->dwBufSize = 0;
+                       iErr += nxcpBuffer->bufferSize;
+                       nxcpBuffer->bufferSize = 0;
 
-         dwMsgSize = ntohl(((CSCP_MESSAGE *)(nxcpBuffer->szBuffer))->dwSize);
+         dwMsgSize = ntohl(((NXCP_MESSAGE *)(nxcpBuffer->buffer))->size);
          if (dwMsgSize > *bufferSize)
          {
                                if ((*bufferSize >= maxMsgSize) || (dwMsgSize > maxMsgSize))
                                {
                                        bSkipMsg = TRUE;  // Message is too large, will skip it
-                   memcpy(*msgBuffer, nxcpBuffer->szBuffer, NXCP_HEADER_SIZE);
+                   memcpy(*msgBuffer, nxcpBuffer->buffer, NXCP_HEADER_SIZE);
                                }
                                else
                                {
                                        // Increase buffer
                                        *bufferSize = dwMsgSize;
-                                       *msgBuffer = (CSCP_MESSAGE *)realloc(*msgBuffer, *bufferSize);
+                                       *msgBuffer = (NXCP_MESSAGE *)realloc(*msgBuffer, *bufferSize);
                                        if (decryptionBuffer != NULL)
                                                *decryptionBuffer = (BYTE *)realloc(*decryptionBuffer, *bufferSize);
                                }
@@ -471,7 +471,7 @@ int LIBNETXMS_EXPORTABLE RecvNXCPMessageEx(SOCKET hSocket, CSCP_MESSAGE **msgBuf
       }
       dwBytesToCopy = min((UINT32)iErr, dwMsgSize - dwBytesRead);
       if (!bSkipMsg)
-         memcpy(((char *)(*msgBuffer)) + dwBytesRead, nxcpBuffer->szBuffer, dwBytesToCopy);
+         memcpy(((char *)(*msgBuffer)) + dwBytesRead, nxcpBuffer->buffer, dwBytesToCopy);
       dwBytesRead += dwBytesToCopy;
    }
        while((dwBytesRead < dwMsgSize) || (dwBytesRead < NXCP_HEADER_SIZE));
@@ -479,19 +479,19 @@ int LIBNETXMS_EXPORTABLE RecvNXCPMessageEx(SOCKET hSocket, CSCP_MESSAGE **msgBuf
    // Check if we have something left in buffer
    if (dwBytesToCopy < (UINT32)iErr)
    {
-      nxcpBuffer->dwBufPos = dwBytesToCopy;
-      nxcpBuffer->dwBufSize = (UINT32)iErr - dwBytesToCopy;
+      nxcpBuffer->bufferPos = dwBytesToCopy;
+      nxcpBuffer->bufferSize = (UINT32)iErr - dwBytesToCopy;
    }
 
    // Check for encrypted message
 decrypt_message:
-   if ((!bSkipMsg) && (ntohs((*msgBuffer)->wCode) == CMD_ENCRYPTED_MESSAGE))
+   if ((!bSkipMsg) && (ntohs((*msgBuffer)->code) == CMD_ENCRYPTED_MESSAGE))
    {
       if ((*ppCtx != NULL) && (*ppCtx != PROXY_ENCRYPTION_CTX))
       {
-         if (CSCPDecryptMessage(*ppCtx, (NXCP_ENCRYPTED_MESSAGE *)(*msgBuffer), *decryptionBuffer))
+         if ((*ppCtx)->decryptMessage((NXCP_ENCRYPTED_MESSAGE *)(*msgBuffer), *decryptionBuffer))
          {
-            dwMsgSize = ntohl((*msgBuffer)->dwSize);
+            dwMsgSize = ntohl((*msgBuffer)->size);
          }
          else
          {
@@ -508,12 +508,12 @@ decrypt_message:
    return bSkipMsg ? 1 : (int)dwMsgSize;
 }
 
-int LIBNETXMS_EXPORTABLE RecvNXCPMessage(SOCKET hSocket, CSCP_MESSAGE *msgBuffer,
-                                         CSCP_BUFFER *nxcpBuffer, UINT32 bufferSize,
+int LIBNETXMS_EXPORTABLE RecvNXCPMessage(SOCKET hSocket, NXCP_MESSAGE *msgBuffer,
+                                         NXCP_BUFFER *nxcpBuffer, UINT32 bufferSize,
                                          NXCPEncryptionContext **ppCtx,
                                          BYTE *decryptionBuffer, UINT32 dwTimeout)
 {
-       CSCP_MESSAGE *mb = msgBuffer;
+       NXCP_MESSAGE *mb = msgBuffer;
        UINT32 bs = bufferSize;
        BYTE *db = decryptionBuffer;
        return RecvNXCPMessageEx(hSocket, (msgBuffer != NULL) ? &mb : NULL, nxcpBuffer, &bs, ppCtx,
@@ -525,27 +525,27 @@ int LIBNETXMS_EXPORTABLE RecvNXCPMessage(SOCKET hSocket, CSCP_MESSAGE *msgBuffer
  * If pBuffer is NULL, new buffer is allocated with malloc()
  * Buffer should be of dwDataSize + NXCP_HEADER_SIZE + 8 bytes.
  */
-CSCP_MESSAGE LIBNETXMS_EXPORTABLE *CreateRawNXCPMessage(WORD wCode, UINT32 dwId, WORD wFlags,
+NXCP_MESSAGE LIBNETXMS_EXPORTABLE *CreateRawNXCPMessage(WORD code, UINT32 id, WORD flags,
                                                         UINT32 dwDataSize, void *pData,
-                                                        CSCP_MESSAGE *pBuffer)
+                                                        NXCP_MESSAGE *pBuffer)
 {
-   CSCP_MESSAGE *pMsg;
+   NXCP_MESSAGE *pMsg;
    UINT32 dwPadding;
 
    if (pBuffer == NULL)
-      pMsg = (CSCP_MESSAGE *)malloc(dwDataSize + NXCP_HEADER_SIZE + 8);
+      pMsg = (NXCP_MESSAGE *)malloc(dwDataSize + NXCP_HEADER_SIZE + 8);
    else
       pMsg = pBuffer;
 
    // Message should be aligned to 8 bytes boundary
    dwPadding = (8 - ((dwDataSize + NXCP_HEADER_SIZE) % 8)) & 7;
 
-   pMsg->wCode = htons(wCode);
-   pMsg->wFlags = htons(MF_BINARY | wFlags);
-   pMsg->dwId = htonl(dwId);
-   pMsg->dwSize = htonl(dwDataSize + NXCP_HEADER_SIZE + dwPadding);
-   pMsg->dwNumVars = htonl(dwDataSize);   // dwNumVars contains actual data size for binary message
-   memcpy(pMsg->df, pData, dwDataSize);
+   pMsg->code = htons(code);
+   pMsg->flags = htons(MF_BINARY | flags);
+   pMsg->id = htonl(id);
+   pMsg->size = htonl(dwDataSize + NXCP_HEADER_SIZE + dwPadding);
+   pMsg->numFields = htonl(dwDataSize);   // numFields contains actual data size for binary message
+   memcpy(pMsg->fields, pData, dwDataSize);
 
    return pMsg;
 }
@@ -553,7 +553,7 @@ CSCP_MESSAGE LIBNETXMS_EXPORTABLE *CreateRawNXCPMessage(WORD wCode, UINT32 dwId,
 /**
  * Send file over CSCP
  */
-BOOL LIBNETXMS_EXPORTABLE SendFileOverNXCP(SOCKET hSocket, UINT32 dwId, const TCHAR *pszFile,
+BOOL LIBNETXMS_EXPORTABLE SendFileOverNXCP(SOCKET hSocket, UINT32 id, const TCHAR *pszFile,
                                            NXCPEncryptionContext *pCtx, long offset,
                                                                                                                 void (* progressCallback)(INT64, void *), void *cbArg,
                                                                                                                 MUTEX mutex)
@@ -562,7 +562,7 @@ BOOL LIBNETXMS_EXPORTABLE SendFileOverNXCP(SOCKET hSocket, UINT32 dwId, const TC
        INT64 bytesTransferred = 0;
    UINT32 dwPadding;
    BOOL bResult = FALSE;
-   CSCP_MESSAGE *pMsg;
+   NXCP_MESSAGE *pMsg;
    NXCP_ENCRYPTED_MESSAGE *pEnMsg;
 
    hFile = _topen(pszFile, O_RDONLY | O_BINARY);
@@ -578,31 +578,31 @@ BOOL LIBNETXMS_EXPORTABLE SendFileOverNXCP(SOCKET hSocket, UINT32 dwId, const TC
                if (lseek(hFile, offset, (offset < 0) ? SEEK_END : SEEK_SET) != -1)
                {
                        // Allocate message and prepare it's header
-                       pMsg = (CSCP_MESSAGE *)malloc(FILE_BUFFER_SIZE + NXCP_HEADER_SIZE + 8);
-