{
scriptName[i] = 0;
StrStrip(scriptName);
- const TCHAR *temp = pObject->getCustomAttribute(scriptName);
+ TCHAR *temp = pObject->getCustomAttributeCopy(scriptName);
if (temp != NULL)
{
dwSize += (UINT32)_tcslen(temp);
pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
_tcscpy(&pText[dwPos], temp);
dwPos += (UINT32)_tcslen(temp);
+ free(temp);
}
}
break;
}
// Manual driver selection
- const TCHAR *driverName = node->getCustomAttribute(_T("snmp.driver"));
- if (driverName != NULL)
+ TCHAR driverName[64];
+ if (node->getCustomAttribute(_T("snmp.driver"), driverName, 64) != NULL)
{
NetworkDeviceDriver *driver = FindDriverByName(driverName);
if (driver != NULL)
unlockChildList();
}
+/**
+ * Set custom attribute
+ */
+void NetObj::setCustomAttribute(const TCHAR *name, const TCHAR *value)
+{
+ lockProperties();
+ const TCHAR *curr = m_customAttributes.get(name);
+ if ((curr == NULL) || _tcscmp(curr, value))
+ {
+ m_customAttributes.set(name, value);
+ setModified();
+ }
+ unlockProperties();
+}
+
+/**
+ * Set custom attribute (value is preallocated)
+ */
+void NetObj::setCustomAttributePV(const TCHAR *name, TCHAR *value)
+{
+ lockProperties();
+ const TCHAR *curr = m_customAttributes.get(name);
+ if ((curr == NULL) || _tcscmp(curr, value))
+ {
+ m_customAttributes.setPreallocated(_tcsdup(name), value);
+ setModified();
+ }
+ else
+ {
+ free(value);
+ }
+ unlockProperties();
+}
+
+/**
+ * Delete custom attribute
+ */
+void NetObj::deleteCustomAttribute(const TCHAR *name)
+{
+ lockProperties();
+ if (m_customAttributes.contains(name))
+ {
+ m_customAttributes.remove(name);
+ setModified();
+ }
+ unlockProperties();
+}
+
+/**
+ * Get custom attribute into buffer
+ */
+TCHAR *NetObj::getCustomAttribute(const TCHAR *name, TCHAR *buffer, size_t size) const
+{
+ TCHAR *result;
+ lockProperties();
+ const TCHAR *value = m_customAttributes.get(name);
+ if (value != NULL)
+ {
+ _tcslcpy(buffer, value, size);
+ result = buffer;
+ }
+ else
+ {
+ result = NULL;
+ }
+ unlockProperties();
+ return result;
+}
+
+/**
+ * Get copy of custom attribute. Returned value must be freed by caller
+ */
+TCHAR *NetObj::getCustomAttributeCopy(const TCHAR *name) const
+{
+ lockProperties();
+ const TCHAR *value = m_customAttributes.get(name);
+ TCHAR *result = _tcsdup_ex(value);
+ unlockProperties();
+ return result;
+}
+
+/**
+ * Get custom attribute as NXSL value
+ */
+NXSL_Value *NetObj::getCustomAttributeForNXSL(const TCHAR *name) const
+{
+ NXSL_Value *value = NULL;
+ lockProperties();
+ const TCHAR *av = m_customAttributes.get(name);
+ if (av != NULL)
+ value = new NXSL_Value(av);
+ unlockProperties();
+ return value;
+}
+
/**
* Get all custom attributes as NXSL hash map
*/
DbgPrintf(7, _T("Node::connectToSMCLP(%s [%d]): existing connection reset"), m_name, m_id);
}
- const TCHAR *login = getCustomAttribute(_T("iLO.login"));
- const TCHAR *password = getCustomAttribute(_T("iLO.password"));
-
- if ((login != NULL) && (password != NULL))
+ TCHAR login[64], password[64];
+ if ((getCustomAttribute(_T("iLO.login"), login, 64) != NULL) &&
+ (getCustomAttribute(_T("iLO.password"), password, 64) != NULL))
return m_smclpConnection->connect(login, password);
return false;
}
{
scriptName[i] = 0;
StrStrip(scriptName);
- const TCHAR *temp = getCustomAttribute(scriptName);
+ TCHAR *temp = getCustomAttributeCopy(scriptName);
if (temp != NULL)
{
dwSize += (UINT32)_tcslen(temp);
pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
_tcscpy(&pText[dwPos], temp);
dwPos += (UINT32)_tcslen(temp);
+ free(temp);
}
}
break;
}
else
{
- const TCHAR *attrValue = object->getCustomAttribute(attr);
- if (attrValue != NULL)
- {
- value = new NXSL_Value(attrValue);
- }
+ value = object->getCustomAttributeForNXSL(attr);
}
return value;
}
*/
static int F_GetCustomAttribute(int argc, NXSL_Value **argv, NXSL_Value **ppResult, NXSL_VM *vm)
{
- NXSL_Object *object;
- const TCHAR *value;
-
if (!argv[0]->isObject())
return NXSL_ERR_NOT_OBJECT;
if (!argv[1]->isString())
return NXSL_ERR_NOT_STRING;
- object = argv[0]->getValueAsObject();
+ NXSL_Object *object = argv[0]->getValueAsObject();
if (!object->getClass()->instanceOf(g_nxslNetObjClass.getName()))
return NXSL_ERR_BAD_CLASS;
NetObj *netxmsObject = (NetObj *)object->getData();
- value = netxmsObject->getCustomAttribute(argv[1]->getValueAsCString());
- if (value != NULL)
- {
- *ppResult = new NXSL_Value(value);
- }
- else
- {
- *ppResult = new NXSL_Value; // Return NULL if attribute not found
- }
-
+ NXSL_Value *value = netxmsObject->getCustomAttributeForNXSL(argv[1]->getValueAsCString());
+ *ppResult = (value != NULL) ? value : new NXSL_Value(); // Return NULL if attribute not found
return 0;
}
*/
static int F_SetCustomAttribute(int argc, NXSL_Value **argv, NXSL_Value **ppResult, NXSL_VM *vm)
{
- NXSL_Object *object;
- const TCHAR *value;
-
if (!argv[0]->isObject())
return NXSL_ERR_NOT_OBJECT;
if (!argv[1]->isString() || !argv[2]->isString())
return NXSL_ERR_NOT_STRING;
- object = argv[0]->getValueAsObject();
+ NXSL_Object *object = argv[0]->getValueAsObject();
if (!object->getClass()->instanceOf(g_nxslNetObjClass.getName()))
return NXSL_ERR_BAD_CLASS;
NetObj *netxmsObject = (NetObj *)object->getData();
- value = netxmsObject->getCustomAttribute(argv[1]->getValueAsCString());
- if (value != NULL)
- {
- *ppResult = new NXSL_Value(value);
- }
- else
- {
- *ppResult = new NXSL_Value; // Return NULL if attribute not found
- }
-
+ NXSL_Value *value = netxmsObject->getCustomAttributeForNXSL(argv[1]->getValueAsCString());
+ *ppResult = (value != NULL) ? value : new NXSL_Value(); // Return NULL if attribute not found
netxmsObject->setCustomAttribute(argv[1]->getValueAsCString(), argv[2]->getValueAsCString());
-
return 0;
}
void addChildNodesToList(ObjectArray<Node> *nodeList, UINT32 dwUserId);
void addChildDCTargetsToList(ObjectArray<DataCollectionTarget> *dctList, UINT32 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); setModified(); }
- void setCustomAttributePV(const TCHAR *name, TCHAR *value) { m_customAttributes.setPreallocated(_tcsdup(name), value); setModified(); }
- void deleteCustomAttribute(const TCHAR *name) { m_customAttributes.remove(name); setModified(); }
+ TCHAR *getCustomAttribute(const TCHAR *name, TCHAR *buffer, size_t size) const;
+ TCHAR *getCustomAttributeCopy(const TCHAR *name) const;
+ NXSL_Value *getCustomAttributeForNXSL(const TCHAR *name) const;
NXSL_Value *getCustomAttributesForNXSL() const;
+ void setCustomAttribute(const TCHAR *name, const TCHAR *value);
+ void setCustomAttributePV(const TCHAR *name, TCHAR *value);
+ void deleteCustomAttribute(const TCHAR *name);
virtual NXSL_Value *createNXSLObject();