[SVN-NetXMS] revision 3312

From: NetXMS.org SVN Server <svn_at_DOMAIN_REMOVED>
Date: Tue, 17 Jun 2008 16:59:55 +0300

* { font-family: Consolas, Lucida Console, Courier New; font-size: 100%; }
h1 { font-size: 150%; }
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 100%; width: 100%; }
.highlight span { width: 100%; display:-moz-inline-stack; display:inline-block; zoom:1; *display:inline; }
body { background: #ffffff; }
body .c { color: #999988; font-style: italic } /* Comment */
body .err { color: #a61717; background-color: #e3d2d2 } /* Error */
body .k { font-weight: bold } /* Keyword */
body .o { font-weight: bold } /* Operator */
body .cm { color: #999988; font-style: italic } /* Comment.Multiline */
body .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
body .c1 { color: #999988; font-style: italic } /* Comment.Single */
body .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
body .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
body .ge { font-style: italic } /* Generic.Emph */
body .gr { color: #aa0000 } /* Generic.Error */
body .gh { color: #999999 } /* Generic.Heading */
body .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
body .go { color: #888888 } /* Generic.Output */
body .gp { color: #555555 } /* Generic.Prompt */
body .gs { font-weight: bold } /* Generic.Strong */
body .gu { color: #aaaaaa } /* Generic.Subheading */
body .gt { color: #aa0000 } /* Generic.Traceback */
body .kc { font-weight: bold } /* Keyword.Constant */
body .kd { font-weight: bold } /* Keyword.Declaration */
body .kp { font-weight: bold } /* Keyword.Pseudo */
body .kr { font-weight: bold } /* Keyword.Reserved */
body .kt { color: #445588; font-weight: bold } /* Keyword.Type */
body .m { color: #009999 } /* Literal.Number */
body .s { color: #bb8844 } /* Literal.String */
body .na { color: #008080 } /* Name.Attribute */
body .nb { color: #999999 } /* Name.Builtin */
body .nc { color: #445588; font-weight: bold } /* Name.Class */
body .no { color: #008080 } /* Name.Constant */
body .ni { color: #800080 } /* Name.Entity */
body .ne { color: #990000; font-weight: bold } /* Name.Exception */
body .nf { color: #990000; font-weight: bold } /* Name.Function */
body .nn { color: #555555 } /* Name.Namespace */
body .nt { color: #000080 } /* Name.Tag */
body .nv { color: #008080 } /* Name.Variable */
body .ow { font-weight: bold } /* Operator.Word */
body .w { color: #bbbbbb } /* Text.Whitespace */
body .mf { color: #009999 } /* Literal.Number.Float */
body .mh { color: #009999 } /* Literal.Number.Hex */
body .mi { color: #009999 } /* Literal.Number.Integer */
body .mo { color: #009999 } /* Literal.Number.Oct */
body .sb { color: #bb8844 } /* Literal.String.Backtick */
body .sc { color: #bb8844 } /* Literal.String.Char */
body .sd { color: #bb8844 } /* Literal.String.Doc */
body .s2 { color: #bb8844 } /* Literal.String.Double */
body .se { color: #bb8844 } /* Literal.String.Escape */
body .sh { color: #bb8844 } /* Literal.String.Heredoc */
body .si { color: #bb8844 } /* Literal.String.Interpol */
body .sx { color: #bb8844 } /* Literal.String.Other */
body .sr { color: #808000 } /* Literal.String.Regex */
body .s1 { color: #bb8844 } /* Literal.String.Single */
body .ss { color: #bb8844 } /* Literal.String.Symbol */
body .bp { color: #999999 } /* Name.Builtin.Pseudo */
body .vc { color: #008080 } /* Name.Variable.Class */
body .vg { color: #008080 } /* Name.Variable.Global */
body .vi { color: #008080 } /* Name.Variable.Instance */
body .il { color: #009999 } /* Literal.Number.Integer.Long */

Info

Revision:3312
Author:victor

Date:2008-06-17 16:59:55 +0300 (Tue, 17 Jun 2008)

Comment:added support of custom object attributes

Changes
U trunk/ChangeLog
U trunk/include/nms_cscp.h
U trunk/include/nxclapi.h
U trunk/src/server/core/netobj.cpp
U trunk/src/server/include/nms_objects.h

Diff
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-06-17 12:31:53 UTC (rev 3311)
+++ trunk/ChangeLog 2008-06-17 13:59:55 UTC (rev 3312)
@@ -6,6 +6,7 @@
 - Scripts in event processing policy now has access to node properties
   via $node variable and to event properties via $event variable
 - Implemented XML encoding for NXCP messages
+- Added support of custom object attributes
 - Fixed issues: #196, #201, #220, #221
 
 

Modified: trunk/include/nms_cscp.h
===================================================================
--- trunk/include/nms_cscp.h 2008-06-17 12:31:53 UTC (rev 3311)
+++ trunk/include/nms_cscp.h 2008-06-17 13:59:55 UTC (rev 3312)
@@ -774,6 +774,7 @@
 #define VID_NUM_TRUSTED_NODES ((DWORD)306)
 #define VID_TRUSTED_NODES ((DWORD)307)
 #define VID_TIMEZONE ((DWORD)308)
+#define VID_NUM_CUSTOM_ATTRIBUTES ((DWORD)309)
 
 // Variable ranges for object&#39;s ACL
 #define VID_ACL_USER_BASE ((DWORD)0x00001000)
@@ -813,6 +814,9 @@
 #define VID_CHILD_ID_BASE ((DWORD)0x80000000)
 #define VID_CHILD_ID_LAST ((DWORD)0xFFFFFFFE)
 
+// Base value for custom attributes
+#define VID_CUSTOM_ATTRIBUTES_BASE ((DWORD)0x70000000)
+
 // Base value for cluster resource list
 #define VID_RESOURCE_LIST_BASE ((DWORD)0x20000000)
 

Modified: trunk/include/nxclapi.h
===================================================================
--- trunk/include/nxclapi.h 2008-06-17 12:31:53 UTC (rev 3311)
+++ trunk/include/nxclapi.h 2008-06-17 13:59:55 UTC (rev 3312)
@@ -457,6 +457,7 @@
 #define OBJ_UPDATE_SNMP_PROXY ((QWORD)_ULL(0x0040000000))
 #define OBJ_UPDATE_REQUIRED_POLLS ((QWORD)_ULL(0x0080000000))
 #define OBJ_UPDATE_TRUSTED_NODES ((QWORD)_ULL(0x0100000000))
+#define OBJ_UPDATE_CUSTOM_ATTRS ((QWORD)_ULL(0x0200000000))
 
 
 //
@@ -1065,6 +1066,11 @@
    TCHAR *pszComments;
         DWORD dwNumTrustedNodes;
         DWORD *pdwTrustedNodes;
+#ifdef __cplusplus
+ StringMap *pCustomAttrs;
+#else
+ void *pCustomAttrs;
+#endif
    union
    {
       struct __nxc_object_iface iface;
@@ -1137,6 +1143,11 @@
         WORD wRequiredPollCount;
         DWORD dwNumTrustedNodes;
         DWORD *pdwTrustedNodes;
+#ifdef __cplusplus
+ StringMap *pCustomAttrs;
+#else
+ void *pCustomAttrs;
+#endif
 } NXC_OBJECT_UPDATE;
 
 

Modified: trunk/src/server/core/netobj.cpp
===================================================================
--- trunk/src/server/core/netobj.cpp 2008-06-17 12:31:53 UTC (rev 3311)
+++ trunk/src/server/core/netobj.cpp 2008-06-17 13:59:55 UTC (rev 3312)
@@ -123,6 +123,8 @@
    QueueSQLRequest(szQuery);
    sprintf(szQuery, &quot;DELETE FROM object_properties WHERE object_id=%d&quot;, m_dwId);
    QueueSQLRequest(szQuery);
+ sprintf(szQuery, &quot;DELETE FROM object_custom_attributes WHERE object_id=%d&quot;, m_dwId);
+ QueueSQLRequest(szQuery);
    return TRUE;
 }
 
@@ -171,9 +173,42 @@
       DBFreeResult(hResult);
    }
 
+ // Load custom attributes
         if (bResult)
+ {
+ _sntprintf(szQuery, 1024, _T(&quot;SELECT attr_name,attr_value FROM object_custom_attributes WHERE object_id=%d&quot;), m_dwId);
+ hResult = DBSelect(g_hCoreDB, szQuery);
+ if (hResult != NULL)
+ {
+ int i, count;
+ TCHAR *name, *value;
+
+ count = DBGetNumRows(hResult);
+ for(i = 0; i &lt; count; i++)
+ {
+ name = DBGetField(hResult, i, 0, NULL, 0);
+ if (name != NULL)
+ {
+ DecodeSQLString(name);
+ value = DBGetField(hResult, i, 1, NULL, 0);
+ if (value != NULL)
+ {
+ DecodeSQLString(value);
+ m_customAttributes.SetPreallocated(name, value);
+ }
+ }
+ }
+ DBFreeResult(hResult);
+ }
+ else
+ {
+ bResult = FALSE;
+ }
+ }
+
+ if (bResult)
                 bResult = LoadTrustedNodes();
-
+
    return bResult;
 }
 
@@ -235,6 +270,30 @@
       DBFreeResult(hResult);
       bResult = DBQuery(hdb, szQuery);
    }
+
+ // Save custom attributes
+ if (bResult)
+ {
+ _sntprintf(szQuery, 512, _T(&quot;DELETE FROM object_custom_attributes WHERE object_id=%d&quot;), m_dwId);
+ bResult = DBQuery(hdb, szQuery);
+ if (bResult)
+ {
+ TCHAR *escName, *escValue;
+
+ for(i = 0; i &lt; m_customAttributes.Size(); i++)
+ {
+ escName = EncodeSQLString(m_customAttributes.GetKeyByIndex(i));
+ escValue = EncodeSQLString(m_customAttributes.GetValueByIndex(i));
+ _sntprintf(szQuery, 16384, _T(&quot;INSERT INTO object_custom_attributes (object_id,attr_name,attr_value) VALUES (%d,&#39;%s&#39;,&#39;%s&#39;)&quot;),
+ m_dwId, escName, escValue);
+ free(escName);
+ free(escValue);
+ bResult = DBQuery(hdb, szQuery);
+ if (!bResult)
+ break;
+ }
+ }
+ }
 
         if (bResult)
                 bResult = SaveTrustedNodes(hdb);
@@ -708,6 +767,14 @@
         pMsg-&gt;SetVariable(VID_NUM_TRUSTED_NODES, m_dwNumTrustedNodes);
         if (m_dwNumTrustedNodes &gt; 0)
                 pMsg-&gt;SetVariableToInt32Array(VID_TRUSTED_NODES, m_dwNumTrustedNodes, m_pdwTrustedNodes);
+
+ pMsg-&gt;SetVariable(VID_NUM_CUSTOM_ATTRIBUTES, m_customAttributes.Size());
+ for(i = 0, dwId = VID_CUSTOM_ATTRIBUTES_BASE; i &lt; m_customAttributes.Size(); i++)
+ {
+ pMsg-&gt;SetVariable(dwId++, m_customAttributes.GetKeyByIndex(i));
+ pMsg-&gt;SetVariable(dwId++, m_customAttributes.GetValueByIndex(i));
+ }
+
    m_pAccessList-&gt;CreateMessage(pMsg);
 }
 
@@ -802,7 +869,24 @@
                 m_pdwTrustedNodes = (DWORD *)realloc(m_pdwTrustedNodes, sizeof(DWORD) * m_dwNumTrustedNodes);
                 pRequest-&gt;GetVariableInt32Array(VID_TRUSTED_NODES, m_dwNumTrustedNodes, m_pdwTrustedNodes);
    }
+
+ // Change custom attributes
+ if (pRequest-&gt;IsVariableExist(VID_NUM_CUSTOM_ATTRIBUTES))
+ {
+ DWORD i, dwId, dwNumElements;
+ TCHAR *name, *value;
 
+ dwNumElements = pRequest-&gt;GetVariableLong(VID_NUM_CUSTOM_ATTRIBUTES);
+ m_customAttributes.Clear();
+ for(i = 0, dwId = VID_CUSTOM_ATTRIBUTES_BASE; i &lt; dwNumElements; i++)
+ {
+ name = pRequest-&gt;GetVariableStr(dwId++);
+ value = pRequest-&gt;GetVariableStr(dwId++);
+ if ((name != NULL) &amp;&amp; (value != NULL))
+ m_customAttributes.SetPreallocated(name, value);
+ }
+ }
+
    Modify();
    UnlockData();
 

Modified: trunk/src/server/include/nms_objects.h
===================================================================
--- trunk/src/server/include/nms_objects.h 2008-06-17 12:31:53 UTC (rev 3311)
+++ trunk/src/server/include/nms_objects.h 2008-06-17 13:59:55 UTC (rev 3312)
@@ -54,6 +54,7 @@
 //
 
 #define MAX_INTERFACES 4096
+#define MAX_ATTR_NAME_LEN 128
 #define INVALID_INDEX 0xFFFFFFFF
 
 
@@ -200,6 +201,8 @@
 
         DWORD m_dwNumTrustedNodes; // Trusted nodes
         DWORD *m_pdwTrustedNodes;
+
+ StringMap m_customAttributes;
 
    void LockData(void) { MutexLock(m_mutexData, INFINITE); }
    void UnlockData(void) { MutexUnlock(m_mutexData); }
@@ -298,6 +301,11 @@
    void DropUserAccess(DWORD dwUserId);
 
    void AddChildNodesToList(DWORD *pdwNumNodes, Node ***pppNodeList, DWORD dwUserId);
+
+ const TCHAR *GetCustomAttribute(const TCHAR *name) { return m_customAttributes.Get(name); }
+ void SetCustomAttribute(const TCHAR *name, const TCHAR *value) { m_customAttributes.Set(name, value); }
+ void SetCustomAttributePV(const TCHAR *name, TCHAR *value) { m_customAttributes.SetPreallocated(_tcsdup(name), value); }
+ void DeleteCustomAttribute(const TCHAR *name) { m_customAttributes.Delete(name); }
 
    // Debug methods
    const char *ParentList(char *szBuffer);
Received on Tue Jun 17 2008 - 16:59:55 EEST

This archive was generated by hypermail 2.2.0 : Tue Jun 17 2008 - 16:56:16 EEST