fixed some warnings
[public/netxms.git] / src / server / libnxsrv / apinfo.cpp
CommitLineData
4cd1e46b
AK
1/*
2** NetXMS - Network Management System
3** Copyright (C) 2003-2013 Victor Kirhenshtein
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU Lesser General Public License as published by
7** the Free Software Foundation; either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU Lesser General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** File: apinfo.cpp
20**
21**/
22
23#include "libnxsrv.h"
24
25
26//
27// Constructor
28//
29
b368969c 30AgentPolicyInfo::AgentPolicyInfo(NXCPMessage *msg)
4cd1e46b 31{
b368969c 32 m_size = msg->getFieldAsUInt32(VID_NUM_ELEMENTS);
4cd1e46b
AK
33 if (m_size > 0)
34 {
35 m_guidList = (BYTE *)malloc(UUID_LENGTH * m_size);
36 m_typeList = (int *)malloc(sizeof(int) * m_size);
37 m_serverList = (TCHAR **)malloc(sizeof(TCHAR *) * m_size);
38
39 UINT32 varId = VID_ELEMENT_LIST_BASE;
40 for(int i = 0; i < m_size; i++, varId += 7)
41 {
b368969c
VK
42 msg->getFieldAsBinary(varId++, &m_guidList[i * UUID_LENGTH], UUID_LENGTH);
43 m_typeList[i] = (int)msg->getFieldAsUInt16(varId++);
44 m_serverList[i] = msg->getFieldAsString(varId++);
4cd1e46b
AK
45 }
46 }
47 else
48 {
49 m_guidList = NULL;
50 m_typeList = NULL;
51 m_serverList = NULL;
52 }
53}
54
55
56//
57// Destructor
58//
59
60AgentPolicyInfo::~AgentPolicyInfo()
61{
62 for(int i = 0; i < m_size; i++)
63 safe_free(m_serverList[i]);
64 safe_free(m_serverList);
65 safe_free(m_typeList);
66 safe_free(m_guidList);
67}
68
69
70//
71// Get GUID
72//
73
74bool AgentPolicyInfo::getGuid(int index, uuid_t guid)
75{
76 if ((index >= 0) && (index < m_size))
77 {
78 memcpy(guid, &m_guidList[index * UUID_LENGTH], UUID_LENGTH);
79 return true;
80 }
81 else
82 {
83 return false;
84 }
85}