- Maps can be saved to server's memory (not to the database jet)
authorVictor Kirhenshtein <victor@netxms.org>
Wed, 12 Apr 2006 22:00:58 +0000 (22:00 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Wed, 12 Apr 2006 22:00:58 +0000 (22:00 +0000)
- Many small bugs fixed

26 files changed:
.gitattributes
include/netxms_maps.h
include/netxmsdb.h
include/nms_cscp.h
include/nxclapi.h
netxms.dsw
sql/Makefile.w32
sql/schema.in
src/console/win32/MapFrame.cpp
src/console/win32/MapFrame.h
src/console/win32/MapView.cpp
src/console/win32/MapView.h
src/console/win32/nxcon.clw
src/console/win32/nxcon.cpp
src/console/win32/nxcon.h
src/libnxcl/main.cpp
src/libnxcl/map.cpp
src/libnxmap/map.cpp
src/libnxmap/submap.cpp
src/server/core/Makefile.am
src/server/core/main.cpp
src/server/core/map.cpp [new file with mode: 0644]
src/server/core/nxcore.dsp
src/server/core/session.cpp
src/server/include/nms_core.h
src/server/include/nxcore_maps.h [new file with mode: 0644]

index 847604d..25bfc2e 100644 (file)
@@ -997,6 +997,7 @@ src/server/core/interface.cpp -text
 src/server/core/locks.cpp -text
 src/server/core/lpp.cpp -text
 src/server/core/main.cpp -text
+src/server/core/map.cpp -text
 src/server/core/modules.cpp -text
 src/server/core/netinfo.cpp -text
 src/server/core/netobj.cpp -text
@@ -1068,6 +1069,7 @@ src/server/include/nms_pkg.h -text
 src/server/include/nms_script.h -text
 src/server/include/nms_topo.h -text
 src/server/include/nms_users.h -text
+src/server/include/nxcore_maps.h -text
 src/server/include/nxmodule.h -text
 src/server/include/nxsrvapi.h -text
 src/server/include/rwlock.h -text
index ce6b844..8ff2658 100644 (file)
 
 
 //
+// User access rights
+//
+
+#define MAP_ACCESS_READ       0x0001
+#define MAP_ACCESS_WRITE      0x0002
+#define MAP_ACCESS_ACL        0x0004
+#define MAP_ACCESS_DELETE     0x0008
+
+
+//
 // Object-on-map structure
 //
 
@@ -77,6 +87,7 @@ struct OBJLINK
 {
    DWORD dwId1;
    DWORD dwId2;
+   LONG nType;
 };
 
 
@@ -105,7 +116,7 @@ protected:
    DWORD m_dwNumLinks;
    OBJLINK *m_pLinkList;
 
-   void CommonInit(void);
+   virtual void CommonInit(void);
 
 public:
    nxSubmap();
@@ -144,12 +155,21 @@ public:
 
 
 //
+// Callback type for submap creation
+//
+
+class nxMap;
+typedef nxSubmap * (* SUBMAP_CREATION_CALLBACK)(DWORD, nxMap *);
+
+
+//
 // Map class
 //
 
 class LIBNXMAP_EXPORTABLE nxMap
 {
 protected:
+   DWORD m_dwMapId;
    TCHAR *m_pszName;
    TCHAR *m_pszDescription;
    DWORD m_dwObjectId;
@@ -158,19 +178,22 @@ protected:
    DWORD m_dwACLSize;
    MAP_ACL_ENTRY *m_pACL;
    MUTEX m_mutex;
+   SUBMAP_CREATION_CALLBACK m_pfCreateSubmap;
 
-   void CommonInit(void);
+   virtual void CommonInit(void);
 
 public:
    nxMap();
-   nxMap(DWORD dwObjectId, TCHAR *pszName, TCHAR *pszDescription);
+   nxMap(DWORD dwMapId, DWORD dwObjectId, TCHAR *pszName, TCHAR *pszDescription);
    nxMap(CSCPMessage *pMsg);
    virtual ~nxMap();
 
    void Lock(void) { MutexLock(m_mutex, INFINITE); }
    void Unlock(void) { MutexUnlock(m_mutex); }
 
+   DWORD MapId(void) { return m_dwMapId; }
    DWORD ObjectId(void) { return m_dwObjectId; }
+   TCHAR *Name(void) { return CHECK_NULL(m_pszName); }
 
    DWORD GetSubmapCount(void) { return m_dwNumSubmaps; }
    nxSubmap *GetSubmap(DWORD dwObjectId);
index 9013c32..3769d6f 100644 (file)
@@ -23,6 +23,6 @@
 #ifndef _netxms_db_h
 #define _netxms_db_h
 
-#define DB_FORMAT_VERSION      38
+#define DB_FORMAT_VERSION      39
 
 #endif
index f390324..bb17182 100644 (file)
@@ -397,6 +397,12 @@ typedef struct
 #define CMD_TRAP_LOG_RECORDS        0x00A0
 #define CMD_START_SNMP_WALK         0x00A1
 #define CMD_SNMP_WALK_DATA          0x00A2
+#define CMD_GET_MAP_LIST            0x00A3
+#define CMD_LOAD_MAP                0x00A4
+#define CMD_SAVE_MAP                0x00A5
+#define CMD_DELETE_MAP              0x00A6
+#define CMD_RESOLVE_MAP_NAME        0x00A7
+#define CMD_SUBMAP_DATA             0x00A8
 
 
 //
@@ -618,6 +624,8 @@ typedef struct
 #define VID_SUBMAP_ATTR             ((DWORD)213)
 #define VID_NUM_LINKS               ((DWORD)214)
 #define VID_LINK_LIST               ((DWORD)215)
+#define VID_MAP_ID                  ((DWORD)216)
+#define VID_NUM_MAPS                ((DWORD)217)
 
 // Variable ranges for object's ACL
 #define VID_ACL_USER_BASE           ((DWORD)0x00001000)
@@ -704,6 +712,9 @@ typedef struct
 // Base value for SNMP walker data
 #define VID_SNMP_WALKER_DATA_BASE   ((DWORD)0x10000000)
 
+// Base value for map list
+#define VID_MAP_LIST_BASE           ((DWORD)0x10000000)
+
 
 //
 // Inline functions
index 18e44f6..a524c1c 100644 (file)
@@ -310,6 +310,8 @@ enum
 #define RCC_INVALID_LPP_ID          ((DWORD)55)
 #define RCC_INVALID_SCRIPT_ID       ((DWORD)56)
 #define RCC_INVALID_SCRIPT_NAME     ((DWORD)57)
+#define RCC_UNKNOWN_MAP_NAME        ((DWORD)58)
+#define RCC_INVALID_MAP_ID          ((DWORD)59)
 
 
 //
@@ -1292,6 +1294,19 @@ typedef struct
 
 
 //
+// Map information
+//
+
+typedef struct
+{
+   DWORD dwMapId;
+   DWORD dwObjectId;
+   DWORD dwAccess;      // Access rights to the map for current user
+   TCHAR szName[MAX_DB_STRING];
+} NXC_MAP_INFO;
+
+
+//
 // Functions
 //
 
@@ -1512,6 +1527,14 @@ DWORD LIBNXCL_EXPORTABLE NXCSnmpWalk(NXC_SESSION hSession, DWORD dwNode,
                                      TCHAR *pszRootOID, void *pUserData,
                                      void (* pfCallback)(TCHAR *, DWORD, TCHAR *, void *));
 
+DWORD LIBNXCL_EXPORTABLE NXCGetMapList(NXC_SESSION hSession, DWORD *pdwNumMaps,
+                                       NXC_MAP_INFO **ppMapList);
+DWORD LIBNXCL_EXPORTABLE NXCSaveMap(NXC_SESSION hSession, void *pMap);
+DWORD LIBNXCL_EXPORTABLE NXCLoadMap(NXC_SESSION hSession, DWORD dwMapId, void **ppMap);
+DWORD LIBNXCL_EXPORTABLE NXCDeleteMap(NXC_SESSION hSession, DWORD dwMapId);
+DWORD LIBNXCL_EXPORTABLE NXCResolveMapName(NXC_SESSION hSession, TCHAR *pszMapName,
+                                           DWORD *pdwMapId);
+
 #ifdef __cplusplus
 }
 #endif
index 8483ee1..3716591 100644 (file)
@@ -44,6 +44,9 @@ Package=<4>
     Begin Project Dependency
     Project_Dep_Name libnxcscp
     End Project Dependency
+    Begin Project Dependency
+    Project_Dep_Name libnxmap
+    End Project Dependency
 }}}
 
 ###############################################################################
@@ -359,6 +362,9 @@ Package=<4>
     Begin Project Dependency
     Project_Dep_Name libnxsl
     End Project Dependency
+    Begin Project Dependency
+    Project_Dep_Name libnxmap
+    End Project Dependency
 }}}
 
 ###############################################################################
index 82845a6..e41dea5 100644 (file)
@@ -7,7 +7,7 @@ CPP = cpp
 sql_SCRIPTS = dbinit_mysql.sql dbinit_pgsql.sql dbinit_mssql.sql dbinit_oracle.sql dbinit_sqlite.sql
 
 ROOT_FILE = dbinit.in
-SOURCE = $(ROOT_FILE) schema.in setup.in events.in images.in policy.in objtools.in scripts.in
+SOURCE = $(ROOT_FILE) schema.in setup.in events.in images.in maps.in policy.in objtools.in scripts.in
 HEADERS = ../include/netxmsdb.h ../include/nxevent.h ../include/nximage.h ../src/server/include/nms_locks.h
 COMMAND = $(CPP) -P -Wundef -D_NETXMS_DB_SCHEMA_ -I../include -I../src/server/include
 SQUEEZE = perl -e "while (<>) { if (! /^[\s\t\n]*$$/) { print; } }"
index cfe627e..958a2e7 100644 (file)
@@ -836,7 +836,7 @@ CREATE TABLE submap_object_positions
 ** Object links on submap
 */
 
-CREATE TABLE submap_object_positions
+CREATE TABLE submap_links
 (
        map_id integer not null,
        submap_id integer not null,
index 5142a74..3f600a7 100644 (file)
@@ -42,6 +42,7 @@ BEGIN_MESSAGE_MAP(CMapFrame, CMDIChildWnd)
        ON_COMMAND(ID_MAP_FORWARD, OnMapForward)
        ON_UPDATE_COMMAND_UI(ID_MAP_FORWARD, OnUpdateMapForward)
        ON_COMMAND(ID_MAP_HOME, OnMapHome)
+       ON_COMMAND(ID_MAP_SAVE, OnMapSave)
        //}}AFX_MSG_MAP
    ON_MESSAGE(NXCM_OBJECT_CHANGE, OnObjectChange)
 END_MESSAGE_MAP()
@@ -130,12 +131,41 @@ void CMapFrame::OnSetFocus(CWnd* pOldWnd)
 
 
 //
+// Map (re)loading function
+//
+
+static DWORD LoadMap(TCHAR *pszName, nxMap **ppMap)
+{
+   DWORD dwResult, dwMapId;
+
+   dwResult = NXCResolveMapName(g_hSession, pszName, &dwMapId);
+   if (dwResult == RCC_SUCCESS)
+   {
+      dwResult = NXCLoadMap(g_hSession, dwMapId, (void **)ppMap);
+   }
+   return dwResult;
+}
+
+
+//
 // WM_COMMAND::ID_VIEW_REFRESH message handler
 //
 
 void CMapFrame::OnViewRefresh() 
 {
-   m_wndMapView.SetMap(new nxMap(1, _T("Default"), _T("Default map")));
+   DWORD dwResult;
+   nxMap *pMap;
+
+   dwResult = DoRequestArg2(LoadMap, _T("Default"), &pMap, _T("Loading map..."));
+   if (dwResult == RCC_SUCCESS)
+   {
+      m_wndMapView.SetMap(pMap);
+   }
+   else
+   {
+      theApp.ErrorBox(dwResult, _T("Cannot load map from server: %s"));
+   }
+   //m_wndMapView.SetMap(new nxMap(1, _T("Default"), _T("Default map")));
 /*   NXC_OBJECT *pObject;
    DWORD i;
    CString strFullString, strTitle;
@@ -275,3 +305,19 @@ void CMapFrame::OnObjectChange(WPARAM wParam, NXC_OBJECT *pObject)
 {
    m_wndMapView.OnObjectChange(wParam, pObject);
 }
+
+
+//
+// WM_COMMAND::ID_MAP_SAVE message handlers
+//
+
+void CMapFrame::OnMapSave() 
+{
+   DWORD dwResult;
+
+   dwResult = DoRequestArg2(NXCSaveMap, g_hSession, m_wndMapView.GetMap(), _T("Saving map..."));
+   if (dwResult != RCC_SUCCESS)
+   {
+      theApp.ErrorBox(dwResult, _T("Cannot save map on server: %s"));
+   }
+}
index 6a10cce..207d6dc 100644 (file)
@@ -60,6 +60,7 @@ protected:
        afx_msg void OnMapForward();
        afx_msg void OnUpdateMapForward(CCmdUI* pCmdUI);
        afx_msg void OnMapHome();
+       afx_msg void OnMapSave();
        //}}AFX_MSG
    afx_msg void OnObjectChange(WPARAM wParam, NXC_OBJECT *pObject);
        DECLARE_MESSAGE_MAP()
index da3d64a..b4b8131 100644 (file)
@@ -409,6 +409,7 @@ void CMapView::DoSubmapLayout()
    RECT rect;
 
    pObject = NXCFindObjectById(g_hSession, m_pSubmap->Id());
+   ASSERT(pObject != NULL);
    if (pObject != NULL)
    {
       GetClientRect(&rect);
index a642177..d310bcf 100644 (file)
@@ -155,6 +155,9 @@ protected:
        afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
+
+public:
+   nxMap *GetMap(void) { return m_pMap; }
 };
 
 /////////////////////////////////////////////////////////////////////////////
index 078618e..deb6f34 100644 (file)
@@ -16,9 +16,9 @@ Class7=CEventBrowser
 Class9=CMapView
 
 ResourceCount=138
-Resource1=IDD_OBJECT_VPNC_GENERAL (English (U.S.))
+Resource1=IDD_CREATE_VPNC (English (U.S.))
 Resource2=IDD_OBJECT_NODE_GENERAL
-Resource3=IDA_DC_EDITOR (English (U.S.))
+Resource3=IDA_AGENT_CFG_EDITOR (English (U.S.))
 Resource4=IDD_SELECT_OBJECT
 Resource5=IDD_SELECT_ACTION
 Class2=CChildView
@@ -32,9 +32,9 @@ Resource7=IDD_NEW_USER
 Class12=CObjectBrowser
 Resource8=IDD_CREATE_CONTAINER
 Class13=CObjectPropDlg
-Resource9=IDD_OBJECT_RELATIONS (English (U.S.))
-Resource10=IDD_GRAPH_PROP_SETTINGS (English (U.S.))
-Resource11=IDD_ACTION_PROPERTIES (English (U.S.))
+Resource9=IDD_OBJECT_NODE_POLL (English (U.S.))
+Resource10=IDD_DESKTOP_SAVE_AS (English (U.S.))
+Resource11=IDD_NEW_ACTION (English (U.S.))
 Resource12=IDR_CTRLPANEL (English (U.S.))
 Resource13=IDR_EVENTS (English (U.S.))
 Resource14=IDR_MAPFRAME (English (U.S.))
@@ -42,17 +42,17 @@ Resource15=IDR_OBJECTS (English (U.S.))
 Resource16=IDD_DUMMY (English (U.S.))
 Class14=CEventEditor
 Class15=CEditEventDlg
-Resource17=IDD_SELECT_INTERNAL_ITEM (English (U.S.))
+Resource17=IDD_EDIT_TRAP_ARG (English (U.S.))
 Class16=CDebugFrame
-Resource18=IDD_EDIT_IP_SUBNET (English (U.S.))
+Resource18=IDD_OBJECT_VPNC_GENERAL (English (U.S.))
 Resource19=IDD_OBJECT_PROPERTIES (English (U.S.))
 Resource20=IDD_SELECT_EVENT
 Class17=CObjectPreview
-Resource21=IDA_OBJECT_TOOLS_EDITOR (English (U.S.))
+Resource21=IDA_DC_EDITOR (English (U.S.))
 Class18=CToolBox
 Class19=CObjectInfoBox
 Class20=CObjectSearchBox
-Resource22=IDD_SET_PASSWORD (English (U.S.))
+Resource22=IDD_GROUP_PROPERTIES (English (U.S.))
 Class21=CEditBox
 Class22=COPGeneral
 Class23=CNodePropsGeneral
@@ -61,14 +61,14 @@ Class24=CObjectPropCaps
 Class25=CObjectPropSheet
 Resource24=IDA_MDI_DEFAULT
 Class26=CRequestProcessingDlg
-Resource25=IDD_EDIT_TRAP_ARG (English (U.S.))
+Resource25=IDD_EDIT_TRAP (English (U.S.))
 Resource26=IDD_PROGRESS (English (U.S.))
 Resource27=IDD_EDIT_RULE_ALARM
-Resource28=IDD_OBJECT_NETSRV_GENERAL (English (U.S.))
+Resource28=IDD_CREATE_NETSRV (English (U.S.))
 Class27=CObjectPropsGeneral
-Resource29=IDD_DCI_COLLECTION (English (U.S.))
+Resource29=IDD_SET_PASSWORD (English (U.S.))
 Class28=CObjectPropsSecurity
-Resource30=IDD_SELECT_USER (English (U.S.))
+Resource30=IDD_OBJECT_SECURITY (English (U.S.))
 Resource31=IDD_SELECT_USER
 Resource32=IDD_OBJECT_SECURITY
 Class29=CUserSelectDlg
@@ -79,36 +79,36 @@ Class31=CNewUserDlg
 Resource35=IDD_THRESHOLD
 Resource36=IDA_EPP
 Class32=CUserPropDlg
-Resource37=IDD_ABOUTBOX (English (U.S.))
+Resource37=IDA_SCRIPT_MANAGER (English (U.S.))
 Resource38=IDD_ABOUTBOX
 Class33=CGroupPropDlg
 Resource39=IDD_CP_GENERAL
 Resource40=IDA_TRAP_EDITOR
 Resource41=IDM_VIEW_SPECIFIC
-Resource42=IDD_EDIT_RULE_COMMENT (English (U.S.))
+Resource42=IDD_SELECT_OBJECT (English (U.S.))
 Class34=CPasswordChangeDlg
 Class35=CNodeSummary
 Class36=CNetSummaryFrame
 Class37=CDataCollectionEditor
-Resource43=IDA_SERVER_CFG_EDITOR (English (U.S.))
+Resource43=IDA_LAST_VALUES (English (U.S.))
 Class38=CDCIPropPage
-Resource44=IDA_GRAPH (English (U.S.))
+Resource44=IDA_TRAP_EDITOR (English (U.S.))
 Class39=CDCIDataView
-Resource45=IDD_SELECT_OBJECT (English (U.S.))
+Resource45=IDD_MIB_BROWSER (English (U.S.))
 Class40=CGraph
 Class41=CGraphFrame
 Class42=CDCIThresholdsPage
-Resource46=IDD_SELECT_ACTION (English (U.S.))
-Resource47=IDD_EDIT_EVENT (English (U.S.))
+Resource46=IDD_ACTION_PROPERTIES (English (U.S.))
+Resource47=IDD_ABOUTBOX (English (U.S.))
 Resource48=IDM_CONTEXT
 Class43=CThresholdDlg
-Resource49=IDA_PACKAGE_MGR (English (U.S.))
+Resource49=IDA_GRAPH (English (U.S.))
 Resource50=IDD_EDIT_TRAP_ARG
 Class44=CMIBBrowserDlg
 Class45=CEventPolicyEditor
 Class46=CRuleList
 Class47=CRuleHeader
-Resource51=IDA_OBJECT_BROWSER (English (U.S.))
+Resource51=IDA_MDI_DEFAULT (English (U.S.))
 Resource52=IDD_CREATE_NODE
 Class48=CObjectSelDlg
 Resource53=IDD_OBJECT_CAPS
@@ -117,22 +117,22 @@ Class49=CRuleCommentDlg
 Resource55=IDD_DCI_COLLECTION
 Class50=CEventSelDlg
 Resource56=IDD_DATA_QUERY
-Resource57=IDD_DCI_THRESHOLDS (English (U.S.))
+Resource57=IDD_DCI_COLLECTION (English (U.S.))
 Resource58=IDD_CREATE_TG
-Resource59=IDD_EDIT_RULE_SEVERITY (English (U.S.))
-Resource60=IDA_TRAP_EDITOR (English (U.S.))
+Resource59=IDD_OBJECT_PRESENTATION (English (U.S.))
+Resource60=IDA_ACTION_EDITOR (English (U.S.))
 Class51=CObjectPropsPresentation
-Resource61=IDD_CHANGE_IP (English (U.S.))
+Resource61=IDD_OBJTOOL_OPTIONS (English (U.S.))
 Resource62=IDD_EDIT_RULE_COMMENT
 Class52=CRuleSeverityDlg
 Resource63=IDD_ACTION_PROPERTIES
 Class53=CRuleAlarmDlg
 Class54=CAlarmBrowser
-Resource64=IDA_SCRIPT_MANAGER (English (U.S.))
+Resource64=IDA_OBJECT_TOOLS_EDITOR (English (U.S.))
 Resource65=IDD_DCI_TRANSFORM
-Resource66=IDD_OBJECT_NODE_GENERAL (English (U.S.))
-Resource67=IDD_EDIT_VARIABLE (English (U.S.))
-Resource68=IDD_SAVE_AGENT_CFG (English (U.S.))
+Resource66=IDD_EDIT_EVENT (English (U.S.))
+Resource67=IDD_DCI_DATA_EXPORT (English (U.S.))
+Resource68=IDD_EDIT_IP_SUBNET (English (U.S.))
 Class55=CConsolePropsGeneral
 Class56=CActionEditor
 Resource69=IDA_ACTION_EDITOR
@@ -143,18 +143,18 @@ Class58=CEditActionDlg
 Resource72=IDA_NETMAP
 Class59=CActionSelDlg
 Resource73=IDD_MIB_BROWSER
-Resource74=IDD_OBJTOOL_COLUMNS
-Resource75=IDD_SELECT_AGENT_PARAM (English (U.S.))
+Resource74=IDD_REMOVE_TEMPLATE
+Resource75=IDD_SELECT_INTERNAL_ITEM (English (U.S.))
 Resource76=IDD_USER_PROPERTIES
 Class60=CCreateObjectDlg
 Class61=CCreateContainerDlg
 Resource77=IDR_MAINFRAME
 Class62=CCreateNodeDlg
-Resource78=IDD_DCI_TRANSFORM (English (U.S.))
+Resource78=IDD_CREATE_NODE (English (U.S.))
 Resource79=IDT_MAP (English (U.S.))
-Resource80=IDD_NEW_USER (English (U.S.))
+Resource80=IDD_SELECT_USER (English (U.S.))
 Class63=CDCITransformPage
-Resource81=IDA_AGENT_CFG_EDITOR (English (U.S.))
+Resource81=IDA_SERVER_CFG_EDITOR (English (U.S.))
 Class64=CPollNodeDlg
 Resource82=IDD_POLL_NODE (English (U.S.))
 Class65=CNodePoller
@@ -171,7 +171,7 @@ Resource89=IDA_ALARM_BROWSER
 Class69=CDataQueryDlg
 Resource90=IDD_EDIT_RULE_SEVERITY
 Class70=CTrapEditDlg
-Resource91=IDD_OBJECT_CAPS (English (U.S.))
+Resource91=IDD_OBJECT_NODE_GENERAL (English (U.S.))
 Class71=CTrapParamDlg
 Resource92=IDD_EDIT_EVENT
 Resource93=IDD_CREATE_TEMPLATE
@@ -179,91 +179,91 @@ Class72=CGraphPropDlg
 Class73=CColorSelector
 Class74=CPackageMgr
 Resource94=IDD_GROUP_PROPERTIES
-Resource95=IDD_CREATE_CONTAINER (English (U.S.))
-Resource96=IDD_CREATE_NETSRV (English (U.S.))
-Resource97=IDD_NEW_OBJECT_TOOL (English (U.S.))
-Resource98=IDD_USER_PROPERTIES (English (U.S.))
-Resource99=IDA_NETMAP (English (U.S.))
-Resource100=IDD_REQUEST_PROCESSING (English (U.S.))
-Resource101=IDD_EDIT_RULE_ALARM (English (U.S.))
-Resource102=IDD_LASTVAL_PROP (English (U.S.))
-Resource103=IDD_CREATE_VPNC (English (U.S.))
-Resource104=IDD_SELECT_EVENT (English (U.S.))
-Resource105=IDD_GRAPH_PROP_DATA (English (U.S.))
-Resource106=IDA_EPP (English (U.S.))
-Resource107=IDD_DCI_SCHEDULE (English (U.S.))
+Resource95=IDD_SELECT_ACTION (English (U.S.))
+Resource96=IDD_INPUT_BOX (English (U.S.))
+Resource97=IDD_OBJTOOL_GENERAL (English (U.S.))
+Resource98=IDD_NEW_USER (English (U.S.))
+Resource99=IDA_ALARM_BROWSER (English (U.S.))
+Resource100=IDD_OBJECT_CAPS (English (U.S.))
+Resource101=IDD_EDIT_RULE_SEVERITY (English (U.S.))
+Resource102=IDD_GRAPH_PROP_DATA (English (U.S.))
+Resource103=IDD_EDIT_VARIABLE (English (U.S.))
+Resource104=IDD_EDIT_RULE_COMMENT (English (U.S.))
+Resource105=IDD_GRAPH_PROP_SETTINGS (English (U.S.))
+Resource106=IDA_OBJECT_BROWSER (English (U.S.))
+Resource107=IDD_SAVE_AGENT_CFG (English (U.S.))
 Class75=CInternalItemSelDlg
-Resource108=IDD_CREATE_TG (English (U.S.))
+Resource108=IDD_DCI_TRANSFORM (English (U.S.))
 Class76=CAgentParamSelDlg
-Resource109=IDD_INPUT_BOX (English (U.S.))
+Resource109=IDD_SELECT_AGENT_PARAM (English (U.S.))
 Class77=CInputBox
-Resource110=IDD_DATA_QUERY (English (U.S.))
+Resource110=IDD_CREATE_TEMPLATE (English (U.S.))
 Class78=CCreateNetSrvDlg
-Resource111=IDD_EDIT_TRAP (English (U.S.))
+Resource111=IDD_DATA_QUERY (English (U.S.))
 Class79=CNetSrvPropsGeneral
 Resource112=IDD_LOGIN (English (U.S.))
 Class80=CNodePropsPolling
 Class81=CDeploymentView
 Class82=CLastValuesView
 Class83=CValueList
-Resource113=IDD_OBJECT_GENERAL (English (U.S.))
+Resource113=IDD_REQUEST_PROCESSING (English (U.S.))
 Class84=CObjectPropsRelations
-Resource114=IDD_CP_GENERAL (English (U.S.))
+Resource114=IDD_EDIT_RULE_ALARM (English (U.S.))
 Class85=CSaveDesktopDlg
-Resource115=IDD_OBJECT_PRESENTATION (English (U.S.))
+Resource115=IDD_SELECT_EVENT (English (U.S.))
 Class86=CGraphSettingsPage
-Resource116=IDD_MIB_BROWSER (English (U.S.))
+Resource116=IDD_THRESHOLD (English (U.S.))
 Class87=CGraphDataPage
-Resource117=IDM_VIEW_SPECIFIC (English (U.S.))
+Resource117=IDM_CONTEXT (English (U.S.))
 Class88=CRemoveTemplateDlg
-Resource118=IDD_OBJECT_STATUS (English (U.S.))
+Resource118=IDD_DCI_SCHEDULE (English (U.S.))
 Class89=CAddrChangeDlg
-Resource119=IDA_ALARM_BROWSER (English (U.S.))
+Resource119=IDA_EPP (English (U.S.))
 Class90=CLastValuesPropDlg
 Class91=CAgentCfgEditor
-Resource120=IDA_ACTION_EDITOR (English (U.S.))
+Resource120=IDA_EVENT_EDITOR (English (U.S.))
 Class92=CDataExportDlg
 Class93=CServerCfgEditor
-Resource121=IDD_DESKTOP_SAVE_AS (English (U.S.))
-Resource122=IDA_EVENT_EDITOR (English (U.S.))
+Resource121=IDD_OBJECT_RELATIONS (English (U.S.))
+Resource122=IDA_NETMAP (English (U.S.))
 Class94=CEditVariableDlg
-Resource123=IDD_OBJECT_SECURITY (English (U.S.))
+Resource123=IDD_OBJECT_GENERAL (English (U.S.))
 Class95=CCreateVPNConnDlg
-Resource124=IDA_MDI_DEFAULT (English (U.S.))
+Resource124=IDR_MAINFRAME (English (U.S.))
 Class96=CVPNCPropsGeneral
-Resource125=IDD_DCI_DATA_EXPORT (English (U.S.))
+Resource125=IDD_LASTVAL_PROP (English (U.S.))
 Class97=CEditSubnetDlg
-Resource126=IDA_LAST_VALUES (English (U.S.))
-Resource127=IDD_OBJTOOL_OPTIONS (English (U.S.))
+Resource126=IDA_PACKAGE_MGR (English (U.S.))
+Resource127=IDD_NEW_OBJECT_TOOL (English (U.S.))
 Class98=CModifiedAgentCfgDlg
 Class99=CSimpleSplitter
 Class100=CAdvSplitter
-Resource128=IDD_CREATE_NODE (English (U.S.))
+Resource128=IDD_CREATE_CONTAINER (English (U.S.))
 Class101=CTableView
 Class102=CWaitView
 Class103=CWebBrowser
 Class104=CSyslogBrowser
 Class105=CLPPList
-Resource129=IDD_GROUP_PROPERTIES (English (U.S.))
+Resource129=IDD_USER_PROPERTIES (English (U.S.))
 Class106=CDCISchedulePage
-Resource130=IDD_CREATE_TEMPLATE (English (U.S.))
+Resource130=IDD_CREATE_TG (English (U.S.))
 Class107=CObjectPropsStatus
 Class108=CObjectToolsEditor
-Resource131=IDR_MAINFRAME (English (U.S.))
-Resource132=IDD_REMOVE_TEMPLATE
+Resource131=IDD_OBJTOOL_COLUMNS
+Resource132=IDD_CHANGE_IP (English (U.S.))
 Class109=CObjToolPropGeneral
-Resource133=IDD_OBJTOOL_GENERAL (English (U.S.))
+Resource133=IDD_OBJECT_STATUS (English (U.S.))
 Class110=CObjToolPropColumns
-Resource134=IDD_THRESHOLD (English (U.S.))
+Resource134=IDD_DCI_THRESHOLDS (English (U.S.))
 Class111=CNewObjectToolDlg
 Class112=CObjToolPropOptions
 Class113=CScriptManager
 Class114=CScriptView
-Resource135=IDM_CONTEXT (English (U.S.))
+Resource135=IDM_VIEW_SPECIFIC (English (U.S.))
 Class115=CTrapLogBrowser
 Class116=CViewEditor
-Resource136=IDD_NEW_ACTION (English (U.S.))
-Resource137=IDD_OBJECT_NODE_POLL (English (U.S.))
+Resource136=IDD_CP_GENERAL (English (U.S.))
+Resource137=IDD_OBJECT_NETSRV_GENERAL (English (U.S.))
 Class117=CSNMPWalkDlg
 Class118=CMapToolbox
 Class119=CMapControlBox
index 07a1fcd..47cadc8 100644 (file)
@@ -549,26 +549,36 @@ void CConsoleApp::OnViewCreate(DWORD dwView, CMDIChildWnd *pWnd, DWORD dwArg)
 {
    DWORD i;
 
-   switch(dwView)
+   if (dwView == IDR_DC_EDITOR)
    {
-      case IDR_DC_EDITOR:
-         // Register new DC editor
-         for(i = 0; i < MAX_DC_EDITORS; i++)
-            if (m_openDCEditors[i].pWnd == NULL)
-            {
-               m_openDCEditors[i].pWnd = pWnd;
-               m_openDCEditors[i].dwNodeId = dwArg;
-               break;
-            }
-         break;
-      default:
-         if (dwView < MAX_VIEW_ID)
+      // Register new DC editor
+      for(i = 0; i < MAX_DC_EDITORS; i++)
+         if (m_openDCEditors[i].pWnd == NULL)
          {
-            m_viewState[dwView].bActive = TRUE;
-            m_viewState[dwView].pWnd = pWnd;
-            m_viewState[dwView].hWnd = pWnd->m_hWnd;
+            m_openDCEditors[i].pWnd = pWnd;
+            m_openDCEditors[i].dwNodeId = dwArg;
+            break;
          }
-         break;
+   }
+   else
+   {
+      // Regitesr view
+      if (dwView < MAX_VIEW_ID)
+      {
+         m_viewState[dwView].bActive = TRUE;
+         m_viewState[dwView].pWnd = pWnd;
+         m_viewState[dwView].hWnd = pWnd->m_hWnd;
+      }
+
+      // Some view-specific processing
+      switch(dwView)
+      {
+         case VIEW_DEBUG:
+            NXCSetDebugCallback(ClientDebugCallback);
+            break;
+         default:
+            break;
+      }
    }
 }
 
@@ -581,26 +591,36 @@ void CConsoleApp::OnViewDestroy(DWORD dwView, CMDIChildWnd *pWnd, DWORD dwArg)
 {
    DWORD i;
 
-   switch(dwView)
+   if (dwView == IDR_DC_EDITOR)
    {
-      case IDR_DC_EDITOR:
-         // Unregister DC editor
-         for(i = 0; i < MAX_DC_EDITORS; i++)
-            if (m_openDCEditors[i].pWnd == pWnd)
-            {
-               m_openDCEditors[i].pWnd = NULL;
-               m_openDCEditors[i].dwNodeId = 0;
-               break;
-            }
-         break;
-      default:
-         if (dwView < MAX_VIEW_ID)
+      // Unregister DC editor
+      for(i = 0; i < MAX_DC_EDITORS; i++)
+         if (m_openDCEditors[i].pWnd == pWnd)
          {
-            m_viewState[dwView].bActive = FALSE;
-            m_viewState[dwView].pWnd = NULL;
-            m_viewState[dwView].hWnd = NULL;
+            m_openDCEditors[i].pWnd = NULL;
+            m_openDCEditors[i].dwNodeId = 0;
+            break;
          }
-         break;
+   }
+   else
+   {
+      // Unregister view
+      if (dwView < MAX_VIEW_ID)
+      {
+         m_viewState[dwView].bActive = FALSE;
+         m_viewState[dwView].pWnd = NULL;
+         m_viewState[dwView].hWnd = NULL;
+      }
+
+      // Some view-specific processing
+      switch(dwView)
+      {
+         case VIEW_DEBUG:
+            NXCSetDebugCallback(NULL);
+            break;
+         default:
+            break;
+      }
    }
 }
 
index 012e4bf..8f0fab8 100644 (file)
@@ -266,7 +266,7 @@ public:
    void DebugCallback(char *pszMsg)
    {
       if (m_viewState[VIEW_DEBUG].bActive)
-         ((CDebugFrame *)m_viewState[VIEW_ALARMS].pWnd)->AddMessage(pszMsg);
+         ((CDebugFrame *)m_viewState[VIEW_DEBUG].pWnd)->AddMessage(pszMsg);
    }
    CAlarmBrowser *GetAlarmBrowser(void) { return m_viewState[VIEW_ALARMS].bActive ? (CAlarmBrowser *)m_viewState[VIEW_ALARMS].pWnd : NULL; }
 };
index 8cb5e6e..39da629 100644 (file)
@@ -222,9 +222,14 @@ const TCHAR LIBNXCL_EXPORTABLE *NXCGetErrorText(DWORD dwError)
       _T("Parameter is not supported by agent"),
       _T("File I/O operation failed"),
       _T("MIB file is corrupted"),
-      _T("File transfer operation already in progress")
+      _T("File transfer operation already in progress"),
+      _T("Invalid log processing policy ID"),
+      _T("Invalid script ID"),
+      _T("Invalid script name"),
+      _T("Unknown map name"),
+      _T("Invalid map ID")
    };
-   return ((dwError >= 0) && (dwError <= RCC_TRANSFER_IN_PROGRESS)) ? pszErrorText[dwError] : _T("Unknown error code");
+   return ((dwError >= 0) && (dwError <= RCC_INVALID_MAP_ID)) ? pszErrorText[dwError] : _T("No text message for this error");
 }
 
 
index 98d7233..ec568d5 100644 (file)
 **/
 
 #include "libnxcl.h"
+#include <netxms_maps.h>
+
+
+//
+// Get map list
+//
+
+DWORD LIBNXCL_EXPORTABLE NXCGetMapList(NXC_SESSION hSession, DWORD *pdwNumMaps,
+                                       NXC_MAP_INFO **ppMapList)
+{
+   CSCPMessage msg, *pResponse;
+   DWORD i, dwRqId, dwResult, dwId;
+
+   dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
+
+   msg.SetCode(CMD_GET_MAP_LIST);
+   msg.SetId(dwRqId);
+   ((NXCL_Session *)hSession)->SendMsg(&msg);
+
+   pResponse = ((NXCL_Session *)hSession)->WaitForMessage(CMD_REQUEST_COMPLETED, dwRqId);
+   if (pResponse != NULL)
+   {
+      dwResult = pResponse->GetVariableLong(VID_RCC);
+      if (dwResult == RCC_SUCCESS)
+      {
+         *pdwNumMaps = pResponse->GetVariableLong(VID_NUM_MAPS);
+         *ppMapList = (NXC_MAP_INFO *)malloc(sizeof(NXC_MAP_INFO) * (*pdwNumMaps));
+         for(i = 0, dwId = VID_MAP_LIST_BASE; i < *pdwNumMaps; i++)
+         {
+            (*ppMapList)[i].dwMapId = pResponse->GetVariableLong(dwId++);
+            (*ppMapList)[i].dwObjectId = pResponse->GetVariableLong(dwId++);
+            (*ppMapList)[i].dwAccess = pResponse->GetVariableLong(dwId++);
+            pResponse->GetVariableStr(dwId++, (*ppMapList)[i].szName, MAX_DB_STRING);
+            dwId += 6;  // Reserved ids for future use
+         }
+      }
+      delete pResponse;
+   }
+   else
+   {
+      dwResult = RCC_TIMEOUT;
+   }
+   return dwResult;
+}
+
+
+//
+// Save map
+//
+
+DWORD LIBNXCL_EXPORTABLE NXCSaveMap(NXC_SESSION hSession, void *pMap)
+{
+   nxSubmap *pSubmap;
+   CSCPMessage msg;
+   DWORD i, dwRqId, dwResult;
+
+   dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
+   ((nxMap *)pMap)->Lock();
+
+   msg.SetCode(CMD_SAVE_MAP);
+   msg.SetId(dwRqId);
+   ((nxMap *)pMap)->CreateMessage(&msg);
+   ((NXCL_Session *)hSession)->SendMsg(&msg);
+
+   // Wait for initial confirmation
+   dwResult = ((NXCL_Session *)hSession)->WaitForRCC(dwRqId);
+
+   // If OK, send all submaps to server
+   if (dwResult == RCC_SUCCESS)
+   {
+      msg.SetCode(CMD_SUBMAP_DATA);
+      for(i = 0; i < ((nxMap *)pMap)->GetSubmapCount(); i++)
+      {
+         msg.DeleteAllVariables();
+         pSubmap = ((nxMap *)pMap)->GetSubmapByIndex(i);
+         if (pSubmap != NULL)
+            pSubmap->CreateMessage(&msg);
+         if (i == ((nxMap *)pMap)->GetSubmapCount() - 1)
+            msg.SetEndOfSequence();
+         ((NXCL_Session *)hSession)->SendMsg(&msg);
+      }
+
+      // Wait for second confirmation
+      dwResult = ((NXCL_Session *)hSession)->WaitForRCC(dwRqId);
+   }
+
+   ((nxMap *)pMap)->Unlock();
+   return dwResult;
+}
+
+
+//
+// Load map
+//
+
+DWORD LIBNXCL_EXPORTABLE NXCLoadMap(NXC_SESSION hSession, DWORD dwMapId, void **ppMap)
+{
+   nxMap *pMap;
+   nxSubmap *pSubmap;
+   CSCPMessage msg, *pResponse;
+   DWORD dwRqId, dwResult, dwId;
+
+   dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
+
+   msg.SetCode(CMD_LOAD_MAP);
+   msg.SetId(dwRqId);
+   msg.SetVariable(VID_MAP_ID, dwMapId);
+   ((NXCL_Session *)hSession)->SendMsg(&msg);
+
+   pResponse = ((NXCL_Session *)hSession)->WaitForMessage(CMD_REQUEST_COMPLETED, dwRqId);
+   if (pResponse != NULL)
+   {
+      dwResult = pResponse->GetVariableLong(VID_RCC);
+      if (dwResult == RCC_SUCCESS)
+      {
+         pMap = new nxMap(pResponse);
+         if (pResponse->GetVariableLong(VID_NUM_SUBMAPS) > 0)
+         {
+            do
+            {
+               delete pResponse;
+               pResponse = ((NXCL_Session *)hSession)->WaitForMessage(CMD_SUBMAP_DATA, dwRqId);
+               if (pResponse != NULL)
+               {
+                  dwResult = pResponse->GetVariableLong(VID_RCC);
+                  if (dwResult == RCC_SUCCESS)
+                  {
+                     dwId = pResponse->GetVariableLong(VID_OBJECT_ID);
+                     pSubmap = pMap->GetSubmap(dwId);
+                     pSubmap->ModifyFromMessage(pResponse);
+                  }
+               }
+               else
+               {
+                  dwResult = RCC_TIMEOUT;
+                  break;
+               }
+            } while((dwResult == RCC_SUCCESS) && (!pResponse->IsEndOfSequence()));
+            if (dwResult == RCC_SUCCESS)
+            {
+               *ppMap = pMap;
+            }
+            else
+            {
+               delete pMap;
+            }
+         }
+         else
+         {
+            *ppMap = pMap;
+         }
+      }
+      delete pResponse;
+   }
+   else
+   {
+      dwResult = RCC_TIMEOUT;
+   }
+   return dwResult;
+}
+
+
+//
+// Delete map
+//
+
+DWORD LIBNXCL_EXPORTABLE NXCDeleteMap(NXC_SESSION hSession, DWORD dwMapId)
+{
+   CSCPMessage msg;
+   DWORD dwRqId;
+
+   dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
+
+   msg.SetCode(CMD_DELETE_MAP);
+   msg.SetId(dwRqId);
+   msg.SetVariable(VID_MAP_ID, dwMapId);
+   ((NXCL_Session *)hSession)->SendMsg(&msg);
+
+   return ((NXCL_Session *)hSession)->WaitForRCC(dwRqId);
+}
+
+
+//
+// Resolve map name to id
+//
+
+DWORD LIBNXCL_EXPORTABLE NXCResolveMapName(NXC_SESSION hSession, TCHAR *pszMapName,
+                                           DWORD *pdwMapId)
+{
+   CSCPMessage msg, *pResponse;
+   DWORD dwRqId, dwResult;
+
+   dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
+
+   msg.SetCode(CMD_RESOLVE_MAP_NAME);
+   msg.SetId(dwRqId);
+   msg.SetVariable(VID_NAME, pszMapName);
+   ((NXCL_Session *)hSession)->SendMsg(&msg);
+
+   pResponse = ((NXCL_Session *)hSession)->WaitForMessage(CMD_REQUEST_COMPLETED, dwRqId);
+   if (pResponse != NULL)
+   {
+      dwResult = pResponse->GetVariableLong(VID_RCC);
+      if (dwResult == RCC_SUCCESS)
+      {
+         *pdwMapId = pResponse->GetVariableLong(VID_MAP_ID);
+      }
+      delete pResponse;
+   }
+   else
+   {
+      dwResult = RCC_TIMEOUT;
+   }
+   return dwResult;
+}
index 58af37a..e86eb9f 100644 (file)
 
 
 //
+// Default submap creation function
+//
+
+static nxSubmap *CreateSubmap(DWORD dwObjectId, nxMap *pMap)
+{
+   return new nxSubmap(dwObjectId);
+}
+
+
+//
 // Default map object constructor
 //
 
@@ -38,9 +48,10 @@ nxMap::nxMap()
 // Constructor for new map object
 //
 
-nxMap::nxMap(DWORD dwObjectId, TCHAR *pszName, TCHAR *pszDescription)
+nxMap::nxMap(DWORD dwMapId, DWORD dwObjectId, TCHAR *pszName, TCHAR *pszDescription)
 {
    CommonInit();
+   m_dwMapId = dwMapId;
    m_dwObjectId = dwObjectId;
    m_pszName = _tcsdup(pszName);
    m_pszDescription = _tcsdup(pszDescription);
@@ -64,6 +75,7 @@ nxMap::nxMap(CSCPMessage *pMsg)
 
 void nxMap::CommonInit(void)
 {
+   m_dwMapId = 0;
    m_pszName = NULL;
    m_pszDescription = NULL;
    m_dwObjectId = 0;
@@ -72,6 +84,7 @@ void nxMap::CommonInit(void)
    m_dwACLSize = 0;
    m_pACL = NULL;
    m_mutex = MutexCreate();
+   m_pfCreateSubmap = CreateSubmap;
 }
 
 
@@ -116,7 +129,7 @@ nxSubmap *nxMap::GetSubmap(DWORD dwObjectId)
    if (i == m_dwNumSubmaps)
    {
       // Create new submap
-      pSubmap = new nxSubmap(dwObjectId);
+      pSubmap = m_pfCreateSubmap(dwObjectId, this);
       m_dwNumSubmaps++;
       m_ppSubmaps = (nxSubmap **)realloc(m_ppSubmaps, sizeof(nxSubmap *) * m_dwNumSubmaps);
       m_ppSubmaps[i] = pSubmap;
@@ -171,6 +184,7 @@ void nxMap::CreateMessage(CSCPMessage *pMsg)
    for(i = 0; i < m_dwNumSubmaps; i++)
       pdwSubmapList[i] = m_ppSubmaps[i]->Id();
    
+   pMsg->SetVariable(VID_MAP_ID, m_dwMapId);
    pMsg->SetVariable(VID_NAME, m_pszName);
    pMsg->SetVariable(VID_DESCRIPTION, m_pszDescription);
    pMsg->SetVariable(VID_OBJECT_ID, m_dwObjectId);
@@ -193,6 +207,8 @@ void nxMap::ModifyFromMessage(CSCPMessage *pMsg)
    DWORD i, j, dwNumSubmaps, *pdwTemp;
 
    // Update simple attributes
+   m_dwMapId = pMsg->GetVariableLong(VID_MAP_ID);
+   m_dwObjectId = pMsg->GetVariableLong(VID_OBJECT_ID);
    safe_free(m_pszName);
    m_pszName = pMsg->GetVariableStr(VID_NAME);
    safe_free(m_pszDescription);
index 295c090..121b695 100644 (file)
@@ -138,6 +138,7 @@ void nxSubmap::ModifyFromMessage(CSCPMessage *pMsg)
    m_dwNumObjects = pMsg->GetVariableLong(VID_NUM_OBJECTS);
    if (m_dwNumObjects > 0)
    {
+      m_pObjectList = (MAP_OBJECT *)realloc(m_pObjectList, sizeof(MAP_OBJECT) * m_dwNumObjects);
       pdwList = (DWORD *)malloc(sizeof(DWORD) * m_dwNumObjects * 3);
       pMsg->GetVariableInt32Array(VID_OBJECT_LIST, m_dwNumObjects * 3, pdwList);
       for(i = 0, j = 0; i < m_dwNumObjects; i++)
@@ -148,10 +149,15 @@ void nxSubmap::ModifyFromMessage(CSCPMessage *pMsg)
       }
       free(pdwList);
    }
+   else
+   {
+      safe_free_and_null(m_pObjectList);
+   }
 
    m_dwNumLinks = pMsg->GetVariableLong(VID_NUM_LINKS);
    if (m_dwNumLinks > 0)
    {
+      m_pLinkList = (OBJLINK *)realloc(m_pLinkList, sizeof(OBJLINK) * m_dwNumLinks);
       pdwList = (DWORD *)malloc(sizeof(DWORD) * m_dwNumLinks * 2);
       pMsg->GetVariableInt32Array(VID_LINK_LIST, m_dwNumLinks * 2, pdwList);
       for(i = 0, j = 0; i < m_dwNumLinks; i++)
@@ -161,6 +167,10 @@ void nxSubmap::ModifyFromMessage(CSCPMessage *pMsg)
       }
       free(pdwList);
    }
+   else
+   {
+      safe_free_and_null(m_pLinkList);
+   }
 }
 
 
index a9ed1a7..6d7f6d2 100644 (file)
@@ -8,13 +8,13 @@ libnxcore_la_SOURCES = acl.cpp agent.cpp actions.cpp admin.cpp alarm.cpp client.
                        dbwrite.cpp dcitem.cpp dcithreshold.cpp dcivalue.cpp \
                        debug.cpp email.cpp entirenet.cpp epp.cpp events.cpp \
                        evproc.cpp hk.cpp id.cpp image.cpp interface.cpp \
-                       locks.cpp lpp.cpp main.cpp modules.cpp netinfo.cpp \
-                       netobj.cpp netsrv.cpp node.cpp nortel.cpp np.cpp \
-                       objects.cpp objtools.cpp package.cpp poll.cpp \
+                       locks.cpp lpp.cpp main.cpp map.cpp modules.cpp \
+                       netinfo.cpp netobj.cpp netsrv.cpp node.cpp nortel.cpp \
+                       np.cpp objects.cpp objtools.cpp package.cpp poll.cpp \
                        rootobj.cpp script.cpp session.cpp sms.cpp snmp.cpp \
-                       snmptrap.cpp subnet.cpp syncer.cpp syslogd.cpp template.cpp \
-                       tools.cpp tracert.cpp uniroot.cpp users.cpp vpnconn.cpp \
-                       watchdog.cpp zone.cpp
+                       snmptrap.cpp subnet.cpp syncer.cpp syslogd.cpp \
+                       template.cpp tools.cpp tracert.cpp uniroot.cpp \
+                       users.cpp vpnconn.cpp watchdog.cpp zone.cpp
 libnxcore_la_LDFLAGS = -version-info $(LIBNXCORE_LIBRARY_VERSION)
 
 EXTRA_DIST = \
index 234bbe3..d6e89fb 100644 (file)
@@ -75,6 +75,8 @@ DWORD g_dwDBSyntax = DB_SYNTAX_GENERIC;
 QWORD g_qwServerId;
 RSA *g_pServerKey = NULL;
 time_t g_tServerStartTime = 0;
+DWORD g_dwLockTimeout = 60000;   // Default timeout for acquiring mutex
+
 
 //
 // Static data
@@ -194,6 +196,7 @@ static void LoadGlobalConfig()
       g_dwFlags |= AF_ENABLE_MULTIPLE_DB_CONN;
    ConfigReadStr("DataDirectory", g_szDataDir, MAX_PATH, DEFAULT_DATA_DIR);
    g_dwPingSize = ConfigReadInt("IcmpPingSize", 46);
+   g_dwLockTimeout = ConfigReadInt("LockTimeout", 60000);
 }
 
 
@@ -407,6 +410,7 @@ BOOL NXCORE_EXPORTABLE Initialize(void)
    ObjectsInit();
    if (!LoadObjects())
       return FALSE;
+   LoadMaps();
    DbgPrintf(AF_DEBUG_MISC, "Objects loaded and initialized");
 
    // Initialize and load event actions
diff --git a/src/server/core/map.cpp b/src/server/core/map.cpp
new file mode 100644 (file)
index 0000000..30f1178
--- /dev/null
@@ -0,0 +1,316 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2003, 2004, 2005, 2006 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: map.cpp
+**
+**/
+
+#include "nxcore.h"
+
+
+//
+// Static data
+//
+
+static DWORD m_dwNumMaps = 0;
+static nxMapSrv **m_ppMapList = NULL;
+static MUTEX m_mutexMapList = INVALID_MUTEX_HANDLE;
+
+
+//
+// Submap creation function for ...Srv classes
+//
+
+static nxSubmap *CreateSubmapSrv(DWORD dwObjectId, nxMap *pMap)
+{
+   return new nxSubmapSrv(dwObjectId, pMap->MapId());
+}
+
+
+//
+// Constructor for creating submap object from database
+// Expected field order:
+//     submap_id,attributes
+//
+
+nxSubmapSrv::nxSubmapSrv(DB_RESULT hData, int nRow, DWORD dwMapId)
+{
+   DB_RESULT hResult;
+   DWORD i;
+   TCHAR szQuery[1024];
+
+   CommonInit();
+   m_dwMapId = dwMapId;
+   m_dwId = DBGetFieldULong(hData, nRow, 0);
+   m_dwAttr = DBGetFieldULong(hData, nRow, 1);
+   
+   // Load object positions
+   _sntprintf(szQuery, 1024, _T("SELECT object_id,x,y FROM submap_object_positions WHERE map_id=%d AND submap_id=%d"),
+              m_dwMapId, m_dwId);
+   hResult = DBSelect(g_hCoreDB, szQuery);
+   if (hResult != NULL)
+   {
+      m_dwNumObjects = DBGetNumRows(hResult);
+      if (m_dwNumObjects > 0)
+      {
+         m_pObjectList = (MAP_OBJECT *)malloc(sizeof(MAP_OBJECT) * m_dwNumObjects);
+         for(i = 0; i < m_dwNumObjects; i++)
+         {
+            m_pObjectList[i].dwId = DBGetFieldULong(hResult, i, 0);
+            m_pObjectList[i].x = DBGetFieldLong(hResult, i, 1);
+            m_pObjectList[i].y = DBGetFieldLong(hResult, i, 2);
+            m_pObjectList[i].dwState = 0;
+         }
+      }
+      DBFreeResult(hResult);
+   }
+
+   // Load links between objects
+   _sntprintf(szQuery, 1024, _T("SELECT object_id1,object_id2,link_type FROM submap_links WHERE map_id=%d AND submap_id=%d"),
+              m_dwMapId, m_dwId);
+   hResult = DBSelect(g_hCoreDB, szQuery);
+   if (hResult != NULL)
+   {
+      m_dwNumLinks = DBGetNumRows(hResult);
+      if (m_dwNumLinks > 0)
+      {
+         m_pLinkList = (OBJLINK *)malloc(sizeof(OBJLINK) * m_dwNumLinks);
+         for(i = 0; i < m_dwNumLinks; i++)
+         {
+            m_pLinkList[i].dwId1 = DBGetFieldULong(hResult, i, 0);
+            m_pLinkList[i].dwId2 = DBGetFieldULong(hResult, i, 1);
+            m_pLinkList[i].nType = DBGetFieldLong(hResult, i, 2);
+         }
+      }
+      DBFreeResult(hResult);
+   }
+}
+
+
+//
+// Constructor for new empty nxSubmapSrv object
+//
+
+nxSubmapSrv::nxSubmapSrv(DWORD dwObjectId, DWORD dwMapId)
+            :nxSubmap(dwObjectId)
+{
+   m_dwMapId = dwMapId;
+}
+
+
+//
+// Constructor for creaing map object from database
+// Expected field order:
+//     map_id,map_name,description,root_object_id
+//
+
+nxMapSrv::nxMapSrv(DB_RESULT hData, int nRow)
+{
+   DB_RESULT hResult;
+   DWORD i;
+   TCHAR szQuery[1024];
+
+   CommonInit();
+   m_dwMapId = DBGetFieldULong(hData, nRow, 0);
+   m_pszName = _tcsdup(DBGetField(hData, nRow, 1));
+   m_pszDescription = _tcsdup(DBGetField(hData, nRow, 2));
+   m_dwObjectId = DBGetFieldULong(hData, nRow, 3);
+
+   // Load ACL
+   _sntprintf(szQuery, 1024, _T("SELECT user_id,access_rights FROM map_access_lists WHERE map_id=%d"), m_dwMapId);
+   hResult = DBSelect(g_hCoreDB, szQuery);
+   if (hResult != NULL)
+   {
+      m_dwACLSize = DBGetNumRows(hResult);
+      if (m_dwACLSize > 0)
+      {
+         m_pACL = (MAP_ACL_ENTRY *)malloc(sizeof(MAP_ACL_ENTRY) * m_dwACLSize);
+         for(i = 0; i < m_dwACLSize; i++)
+         {
+            m_pACL[i].dwUserId = DBGetFieldULong(hResult, i, 0);
+            m_pACL[i].dwAccess = DBGetFieldULong(hResult, i, 1);
+         }
+      }
+      DBFreeResult(hResult);
+   }
+
+   // Load submaps
+   _sntprintf(szQuery, 1024, _T("SELECT submap_id,attributes FROM submaps WHERE map_id=%d"), m_dwMapId);
+   hResult = DBSelect(g_hCoreDB, szQuery);
+   if (hResult != NULL)
+   {
+      m_dwNumSubmaps = DBGetNumRows(hResult);
+      if (m_dwNumSubmaps > 0)
+      {
+         m_ppSubmaps = (nxSubmap **)malloc(sizeof(nxSubmap *) * m_dwNumSubmaps);
+         for(i = 0; i < m_dwNumSubmaps; i++)
+            m_ppSubmaps[i] = new nxSubmapSrv(hResult, i, m_dwMapId);
+      }
+      DBFreeResult(hResult);
+   }
+}
+
+
+//
+// Common initialization for nxMapSrv constructors
+//
+
+void nxMapSrv::CommonInit(void)
+{
+   nxMap::CommonInit();
+   m_nRefCount = 0;
+   m_pfCreateSubmap = CreateSubmapSrv;
+}
+
+
+//
+// Check user's access level
+//
+
+BOOL nxMapSrv::CheckUserRights(DWORD dwUserId, DWORD dwDesiredAccess)
+{
+   DWORD i, dwRights;
+   BOOL bRet = FALSE, bFound = FALSE;
+
+   if (dwUserId == 0)
+      return TRUE;   // Superuser always has all rights
+
+   Lock();
+
+   // Check direct user assignment first
+   for(i = 0; i < m_dwACLSize; i++)
+   {
+      if (m_pACL[i].dwUserId == dwUserId)
+      {
+         bRet = ((m_pACL[i].dwAccess & dwDesiredAccess) == dwDesiredAccess)? TRUE : FALSE;
+         bFound = TRUE;
+         break;
+      }
+   }
+
+   // Check rights assignment through the group
+   if (!bFound)
+   {
+      dwRights = 0;
+      for(i = 0; i < m_dwACLSize; i++)
+      {
+         if (m_pACL[i].dwUserId & GROUP_FLAG)
+         {
+            if (CheckUserMembership(dwUserId, m_pACL[i].dwUserId))
+            {
+               dwRights |= m_pACL[i].dwAccess;
+            }
+         }
+      }
+      bRet = ((dwRights & dwDesiredAccess) == dwDesiredAccess)? TRUE : FALSE;
+   }
+
+   Unlock();
+   return bRet;
+}
+
+
+//
+// Load all maps on startup
+//
+
+void LoadMaps(void)
+{
+   DB_RESULT hResult;
+   DWORD i;
+
+   hResult = DBSelect(g_hCoreDB, "SELECT map_id,map_name,description,root_object_id FROM maps");
+   if (hResult != NULL)
+   {
+      m_dwNumMaps = DBGetNumRows(hResult);
+      if (m_dwNumMaps > 0)
+      {
+         m_ppMapList = (nxMapSrv **)malloc(sizeof(nxMapSrv *) * m_dwNumMaps);
+         for(i = 0; i < m_dwNumMaps; i++)
+            m_ppMapList[i] = new nxMapSrv(hResult, i);
+      }
+      DBFreeResult(hResult);
+   }
+   m_mutexMapList = MutexCreate();
+}
+
+
+//
+// Resolve map name to ID
+// Will return RCC_SUCCESS on success or appropriate RCC on failure
+//
+
+DWORD GetMapIdFromName(TCHAR *pszName, DWORD *pdwMapId)
+{
+   DWORD i, dwResult = RCC_INTERNAL_ERROR;
+
+   if (MutexLock(m_mutexMapList, g_dwLockTimeout))
+   {
+      for(i = 0; i < m_dwNumMaps; i++)
+      {
+         if (!_tcsicmp(pszName, m_ppMapList[i]->Name()))
+         {
+            *pdwMapId = m_ppMapList[i]->MapId();
+            dwResult = RCC_SUCCESS;
+            break;
+         }
+
+         // Map with given name not found
+         *pdwMapId = 0;
+         dwResult = RCC_UNKNOWN_MAP_NAME;
+      }
+      MutexUnlock(m_mutexMapList);
+   }
+   return dwResult;
+}
+
+
+//
+// Lock access to maps
+//
+
+BOOL LockMaps(void)
+{
+   return MutexLock(m_mutexMapList, g_dwLockTimeout);
+}
+
+
+//
+// Unlock access to maps
+//
+
+void UnlockMaps(void)
+{
+   MutexUnlock(m_mutexMapList);
+}
+
+
+//
+// Find map by ID (assuming that map list already locked)
+//
+
+nxMapSrv *FindMapByID(DWORD dwMapId)
+{
+   DWORD i;
+
+   for(i = 0; i < m_dwNumMaps; i++)
+      if (m_ppMapList[i]->MapId() == dwMapId)
+         return m_ppMapList[i];
+   return NULL;
+}
+
index 6e841f9..880ea03 100644 (file)
@@ -55,7 +55,7 @@ BSC32=bscmake.exe
 # ADD BSC32 /nologo
 LINK32=link.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libnetxms.lib libnxcscp.lib libnxsrv.lib libnxsnmp.lib iphlpapi.lib libeay32.lib minidump.lib version.lib psapi.lib libnxsl.lib /nologo /dll /machine:I386 /libpath:"..\..\libnetxms\Release" /libpath:"..\..\libnxcscp\Release" /libpath:"..\..\libnxsnmp\Release" /libpath:"..\libnxsrv\Release" /libpath:"..\..\libnxsl\Release"
+# ADD LINK32 minidump.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libnetxms.lib libnxcscp.lib libnxsrv.lib libnxsnmp.lib iphlpapi.lib libeay32.lib version.lib psapi.lib libnxsl.lib libnxmap.lib /nologo /dll /machine:I386 /libpath:"..\..\libnetxms\Release" /libpath:"..\..\libnxcscp\Release" /libpath:"..\..\libnxsnmp\Release" /libpath:"..\libnxsrv\Release" /libpath:"..\..\libnxsl\Release" /libpath:"..\..\libnxmap\Release"
 # Begin Special Build Tool
 SOURCE="$(InputPath)"
 PostBuild_Desc=Copy files
@@ -86,7 +86,7 @@ BSC32=bscmake.exe
 # ADD BSC32 /nologo
 LINK32=link.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libnetxms.lib libnxcscp.lib libnxsrv.lib libnxsnmp.lib iphlpapi.lib libeay32.lib minidump.lib version.lib psapi.lib libnxsl.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"..\..\libnetxms\Debug" /libpath:"..\..\libnxcscp\Debug" /libpath:"..\..\libnxsnmp\Debug" /libpath:"..\libnxsrv\Debug" /libpath:"..\..\libnxsl\Debug"
+# ADD LINK32 minidump.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libnetxms.lib libnxcscp.lib libnxsrv.lib libnxsnmp.lib iphlpapi.lib libeay32.lib version.lib psapi.lib libnxsl.lib libnxmap.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"..\..\libnetxms\Debug" /libpath:"..\..\libnxcscp\Debug" /libpath:"..\..\libnxsnmp\Debug" /libpath:"..\libnxsrv\Debug" /libpath:"..\..\libnxsl\Debug" /libpath:"..\..\libnxmap\Debug"
 # Begin Special Build Tool
 SOURCE="$(InputPath)"
 PostBuild_Desc=Copy files
@@ -119,7 +119,7 @@ BSC32=bscmake.exe
 # ADD BSC32 /nologo
 LINK32=link.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libnetxms.lib libnxcscp.lib libnxsrv.lib libnxsnmp.lib iphlpapi.lib libeay32.lib minidump.lib version.lib psapi.lib libnxsl.lib /nologo /dll /machine:I386 /libpath:"..\..\libnetxms\Release" /libpath:"..\..\libnxcscp\Release" /libpath:"..\..\libnxsnmp\Release" /libpath:"..\libnxsrv\Release" /libpath:"..\..\libnxsl\Release"
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libnetxms.lib libnxcscp.lib libnxsrv.lib libnxsnmp.lib iphlpapi.lib libeay32.lib version.lib psapi.lib libnxsl.lib bufferoverflowU.lib dbghelp.lib /nologo /dll /machine:I386 /libpath:"..\..\libnetxms\Release64" /libpath:"..\..\libnxcscp\Release64" /libpath:"..\..\libnxsnmp\Release64" /libpath:"..\libnxsrv\Release64" /libpath:"..\..\libnxsl\Release64" /machine:AMD64
+# ADD LINK32 bufferoverflowU.lib dbghelp.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libnetxms.lib libnxcscp.lib libnxsrv.lib libnxsnmp.lib iphlpapi.lib libeay32.lib version.lib psapi.lib libnxsl.lib libnxmap.lib /nologo /dll /machine:I386 /libpath:"..\..\libnetxms\Release64" /libpath:"..\..\libnxcscp\Release64" /libpath:"..\..\libnxsnmp\Release64" /libpath:"..\libnxsrv\Release64" /libpath:"..\..\libnxsl\Release64" /libpath:"..\..\libnxmap\Release64" /machine:AMD64
 # SUBTRACT LINK32 /pdb:none
 # Begin Special Build Tool
 SOURCE="$(InputPath)"
@@ -153,7 +153,7 @@ BSC32=bscmake.exe
 # ADD BSC32 /nologo
 LINK32=link.exe
 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libnetxms.lib libnxcscp.lib libnxsrv.lib libnxsnmp.lib iphlpapi.lib libeay32.lib minidump.lib version.lib psapi.lib libnxsl.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"..\..\libnetxms\Debug" /libpath:"..\..\libnxcscp\Debug" /libpath:"..\..\libnxsnmp\Debug" /libpath:"..\libnxsrv\Debug" /libpath:"..\..\libnxsl\Debug"
-# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libnetxms.lib libnxcscp.lib libnxsrv.lib libnxsnmp.lib iphlpapi.lib libeay32.lib version.lib psapi.lib libnxsl.lib bufferoverflowU.lib dbghelp.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"..\..\libnetxms\Debug64" /libpath:"..\..\libnxcscp\Debug64" /libpath:"..\..\libnxsnmp\Debug64" /libpath:"..\libnxsrv\Debug64" /libpath:"..\..\libnxsl\Debug64" /machine:AMD64
+# ADD LINK32 bufferoverflowU.lib dbghelp.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib libnetxms.lib libnxcscp.lib libnxsrv.lib libnxsnmp.lib iphlpapi.lib libeay32.lib version.lib psapi.lib libnxsl.lib libnxmap.lib /nologo /dll /debug /machine:I386 /pdbtype:sept /libpath:"..\..\libnetxms\Debug64" /libpath:"..\..\libnxcscp\Debug64" /libpath:"..\..\libnxsnmp\Debug64" /libpath:"..\libnxsrv\Debug64" /libpath:"..\..\libnxsl\Debug64" /libpath:"..\..\libnxmap\Debug64" /machine:AMD64
 # SUBTRACT LINK32 /pdb:none
 # Begin Special Build Tool
 SOURCE="$(InputPath)"
@@ -282,6 +282,10 @@ SOURCE=.\main.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\map.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\modules.cpp
 # End Source File
 # Begin Source File
@@ -494,6 +498,10 @@ SOURCE=.\nxcore.h
 # End Source File
 # Begin Source File
 
+SOURCE=..\include\nxcore_maps.h
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\..\include\nxcscpapi.h
 # End Source File
 # Begin Source File
index 2e490b5..dcd1844 100644 (file)
@@ -927,6 +927,18 @@ void ClientSession::ProcessingThread(void)
          case CMD_START_SNMP_WALK:
             StartSnmpWalk(pMsg);
             break;
+         case CMD_RESOLVE_MAP_NAME:
+            ResolveMapName(pMsg);
+            break;
+         case CMD_SAVE_MAP:
+            SaveMap(pMsg);
+            break;
+         case CMD_SUBMAP_DATA:
+            ProcessSubmapData(pMsg);
+            break;
+         case CMD_LOAD_MAP:
+            LoadMap(pMsg);
+            break;
          default:
             // Pass message to loaded modules
             for(i = 0; i < g_dwNumModules; i++)
@@ -6431,3 +6443,165 @@ void ClientSession::StartSnmpWalk(CSCPMessage *pRequest)
    }
    SendMessage(&msg);
 }
+
+
+//
+// Resolve map name to ID
+//
+
+void ClientSession::ResolveMapName(CSCPMessage *pRequest)
+{
+   CSCPMessage msg;
+   TCHAR szName[MAX_DB_STRING];
+   DWORD dwMapId;
+
+   msg.SetCode(CMD_REQUEST_COMPLETED);
+   msg.SetId(pRequest->GetId());
+
+   pRequest->GetVariableStr(VID_NAME, szName, MAX_DB_STRING);
+   msg.SetVariable(VID_RCC, GetMapIdFromName(szName, &dwMapId));
+   msg.SetVariable(VID_MAP_ID, dwMapId);
+
+   SendMessage(&msg);
+}
+
+
+//
+// Save map
+//
+
+void ClientSession::SaveMap(CSCPMessage *pRequest)
+{
+   CSCPMessage msg;
+   DWORD dwMapId;
+
+   msg.SetCode(CMD_REQUEST_COMPLETED);
+   msg.SetId(pRequest->GetId());
+
+   if (!(m_dwFlags & CSF_RECEIVING_MAP_DATA))
+   {
+      dwMapId = pRequest->GetVariableLong(VID_MAP_ID);
+      LockMaps();
+      m_pActiveMap = FindMapByID(dwMapId);
+      if (m_pActiveMap != NULL)
+      {
+         if (m_pActiveMap->CheckUserRights(m_dwUserId, MAP_ACCESS_WRITE))
+         {
+            m_pActiveMap->IncRefCount();
+            m_pActiveMap->Lock();
+            m_pActiveMap->ModifyFromMessage(pRequest);
+            m_pActiveMap->Unlock();
+            msg.SetVariable(VID_RCC, RCC_SUCCESS);
+            m_dwFlags |= CSF_RECEIVING_MAP_DATA;
+            m_dwMapSaveRqId = pRequest->GetId();
+         }
+         else
+         {
+            msg.SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+         }
+      }
+      else
+      {
+         msg.SetVariable(VID_RCC, RCC_INVALID_MAP_ID);
+      }
+      UnlockMaps();
+   }
+   else
+   {
+      msg.SetVariable(VID_RCC, RCC_OPERATION_IN_PROGRESS);
+   }
+
+   SendMessage(&msg);
+}
+
+
+//
+// Process incoming submap data
+//
+
+void ClientSession::ProcessSubmapData(CSCPMessage *pRequest)
+{
+   CSCPMessage msg;
+   DWORD dwId;
+   nxSubmapSrv *pSubmap;
+   BOOL bSend = FALSE;
+
+   msg.SetCode(CMD_REQUEST_COMPLETED);
+   msg.SetId(pRequest->GetId());
+
+   if ((m_dwFlags & CSF_RECEIVING_MAP_DATA) &&
+       (m_dwMapSaveRqId == pRequest->GetId()))
+   {
+      dwId = pRequest->GetVariableLong(VID_OBJECT_ID);
+      pSubmap = (nxSubmapSrv *)m_pActiveMap->GetSubmap(dwId);
+      if (pSubmap != NULL)
+      {
+         pSubmap->ModifyFromMessage(pRequest);
+      }
+      if (pRequest->IsEndOfSequence())
+      {
+         m_pActiveMap->DecRefCount();
+         m_dwFlags &= ~CSF_RECEIVING_MAP_DATA;
+         msg.SetVariable(VID_RCC, RCC_SUCCESS);
+         bSend = TRUE;
+      }
+   }
+   else
+   {
+      msg.SetVariable(VID_RCC, RCC_OUT_OF_STATE_REQUEST);
+      bSend = TRUE;
+   }
+
+   if (bSend)
+      SendMessage(&msg);
+}
+
+
+//
+// Load map
+//
+
+void ClientSession::LoadMap(CSCPMessage *pRequest)
+{
+   CSCPMessage msg;
+   DWORD i, dwMapId;
+   nxMapSrv *pMap;
+   nxSubmap *pSubmap;
+
+   msg.SetCode(CMD_REQUEST_COMPLETED);
+   msg.SetId(pRequest->GetId());
+
+   dwMapId = pRequest->GetVariableLong(VID_MAP_ID);
+   LockMaps();
+   pMap = FindMapByID(dwMapId);
+   if (pMap != NULL)
+   {
+      if (pMap->CheckUserRights(m_dwUserId, MAP_ACCESS_READ))
+      {
+         msg.SetVariable(VID_RCC, RCC_SUCCESS);
+         pMap->CreateMessage(&msg);
+
+         for(i = 0; i < pMap->GetSubmapCount(); i++)
+         {
+            SendMessage(&msg);
+            msg.SetCode(CMD_SUBMAP_DATA);
+            msg.DeleteAllVariables();
+            pSubmap = pMap->GetSubmapByIndex(i);
+            if (pSubmap != NULL)
+               pSubmap->CreateMessage(&msg);
+         }
+         msg.SetEndOfSequence();
+      }
+      else
+      {
+         msg.SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+      }
+   }
+   else
+   {
+      msg.SetVariable(VID_RCC, RCC_INVALID_MAP_ID);
+   }
+   UnlockMaps();
+
+   SendMessage(&msg);
+}
index 2615e48..b8737d3 100644 (file)
@@ -101,6 +101,7 @@ typedef __console_ctx * CONSOLE_CTX;
 #include "nms_pkg.h"
 #include "nms_topo.h"
 #include "nms_script.h"
+#include "nxcore_maps.h"
 
 
 //
@@ -205,6 +206,7 @@ typedef void * HSNMPSESSION;
 #define CSF_TRAP_CFG_LOCKED      ((DWORD)0x0040)
 #define CSF_AUTHENTICATED        ((DWORD)0x0080)
 #define CSF_OBJECT_TOOLS_LOCKED  ((DWORD)0x0100)
+#define CSF_RECEIVING_MAP_DATA   ((DWORD)0x0200)
 
 
 //
@@ -354,6 +356,8 @@ private:
    DWORD m_dwEncryptionResult;
    CONDITION m_condEncryptionSetup;
    DWORD m_dwActiveChannels;     // Active data channels
+   DWORD m_dwMapSaveRqId;        // ID of currently active map saving request
+   nxMapSrv *m_pActiveMap;       // Map currenly being saved
 
    static THREAD_RESULT THREAD_CALL ReadThreadStarter(void *);
    static THREAD_RESULT THREAD_CALL WriteThreadStarter(void *);
@@ -466,6 +470,10 @@ private:
    void KillSession(CSCPMessage *pRequest);
    void SendTrapLog(CSCPMessage *pRequest);
    void StartSnmpWalk(CSCPMessage *pRequest);
+   void ResolveMapName(CSCPMessage *pRequest);
+   void SaveMap(CSCPMessage *pRequest);
+   void ProcessSubmapData(CSCPMessage *pRequest);
+   void LoadMap(CSCPMessage *pRequest);
 
 public:
    ClientSession(SOCKET hSocket, DWORD dwHostAddr);
@@ -647,6 +655,7 @@ extern QWORD g_qwServerId;
 extern RSA *g_pServerKey;
 extern DWORD g_dwPingSize;
 extern time_t g_tServerStartTime;
+extern DWORD g_dwLockTimeout;
 
 extern DB_HANDLE g_hCoreDB;
 extern Queue *g_pLazyRequestQueue;
diff --git a/src/server/include/nxcore_maps.h b/src/server/include/nxcore_maps.h
new file mode 100644 (file)
index 0000000..257a469
--- /dev/null
@@ -0,0 +1,80 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2003, 2004, 2005, 2006 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: nxcore_maps.h
+**
+**/
+
+#ifndef _nxcore_maps_h_
+#define _nxcore_maps_h_
+
+#include <netxms_maps.h>
+
+
+//
+// Server-side submap class
+//
+
+class nxSubmapSrv : public nxSubmap
+{
+protected:
+   DWORD m_dwMapId;     // ID of parent map
+
+public:
+   nxSubmapSrv(DB_RESULT hResult, int nRow, DWORD dwMapId);
+   nxSubmapSrv(DWORD dwObjectId, DWORD dwMapId);
+
+   DWORD SaveToDB(void);
+};
+
+
+//
+// Server-side map class
+//
+
+class nxMapSrv : public nxMap
+{
+protected:
+   int m_nRefCount;
+
+   virtual void CommonInit(void);
+
+public:
+   nxMapSrv(DB_RESULT hResult, int nRow);
+
+   DWORD SaveToDB(void);
+   BOOL CheckUserRights(DWORD dwUserId, DWORD dwDesiredAccess);
+
+   void IncRefCount(void) { Lock(); m_nRefCount++; Unlock(); }
+   void DecRefCount(void) { Lock(); if (m_nRefCount > 0) m_nRefCount--; Unlock(); }
+   int GetRefCount(void) { int nRef; Lock(); nRef = m_nRefCount; Unlock(); return nRef; }
+};
+
+
+//
+// Functions
+//
+
+void LoadMaps(void);
+DWORD GetMapIdFromName(TCHAR *pszName, DWORD *pdwMapId);
+BOOL LockMaps(void);
+void UnlockMaps(void);
+nxMapSrv *FindMapByID(DWORD dwMapId);
+
+
+#endif   /* _nxcore_maps_h_ */