Fixed problem with file sheduled file upload. Fixed some memory leaks Fixes #1187
[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
de4af576
VK
25/**
26 * Constructor
27 */
b368969c 28AgentPolicyInfo::AgentPolicyInfo(NXCPMessage *msg)
4cd1e46b 29{
b368969c 30 m_size = msg->getFieldAsUInt32(VID_NUM_ELEMENTS);
4cd1e46b
AK
31 if (m_size > 0)
32 {
33 m_guidList = (BYTE *)malloc(UUID_LENGTH * m_size);
34 m_typeList = (int *)malloc(sizeof(int) * m_size);
7f6ecb6d
TD
35 m_serverIdList = (UINT64*)malloc(sizeof(UINT64) * m_size);
36 m_serverInfoList = (TCHAR **)malloc(sizeof(TCHAR *) * m_size);
37 m_version = (int *)malloc(sizeof(int) * m_size);
4cd1e46b
AK
38
39 UINT32 varId = VID_ELEMENT_LIST_BASE;
7f6ecb6d 40 for(int i = 0; i < m_size; i++, varId += 5)
4cd1e46b 41 {
b368969c 42 msg->getFieldAsBinary(varId++, &m_guidList[i * UUID_LENGTH], UUID_LENGTH);
7f6ecb6d
TD
43 m_typeList[i] = (int)msg->getFieldAsUInt32(varId++);
44 m_serverInfoList[i] = msg->getFieldAsString(varId++);
45 m_serverIdList[i] = msg->getFieldAsUInt64(varId++);
46 m_version[i] = (int)msg->getFieldAsUInt32(varId++);
4cd1e46b
AK
47 }
48 }
49 else
50 {
51 m_guidList = NULL;
52 m_typeList = NULL;
7f6ecb6d
TD
53 m_serverInfoList = NULL;
54 m_serverIdList = NULL;
55 m_version = NULL;
4cd1e46b
AK
56 }
57}
58
de4af576
VK
59/**
60 * Destructor
61 */
4cd1e46b
AK
62AgentPolicyInfo::~AgentPolicyInfo()
63{
7f6ecb6d
TD
64 for(int i = 0; i < m_size; i++)
65 free(m_serverInfoList[i]);
c9b9393b 66 free(m_serverInfoList);
7f6ecb6d
TD
67 free(m_serverIdList);
68 free(m_typeList);
69 free(m_guidList);
70 free(m_version);
4cd1e46b
AK
71}
72
de4af576
VK
73/**
74 * Get GUID
75 */
76uuid AgentPolicyInfo::getGuid(int index)
4cd1e46b
AK
77{
78 if ((index >= 0) && (index < m_size))
79 {
de4af576 80 return uuid(&m_guidList[index * UUID_LENGTH]);
4cd1e46b
AK
81 }
82 else
83 {
de4af576 84 return uuid::NULL_UUID;
4cd1e46b
AK
85 }
86}