1ad489ce06742fd602216ce00972cb4cd3a58f74
[public/netxms.git] / src / server / libnxsrv / apinfo.cpp
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 * Constructor
27 */
28 AgentPolicyInfo::AgentPolicyInfo(NXCPMessage *msg)
29 {
30 m_size = msg->getFieldAsUInt32(VID_NUM_ELEMENTS);
31 if (m_size > 0)
32 {
33 m_guidList = (BYTE *)malloc(UUID_LENGTH * m_size);
34 m_typeList = (int *)malloc(sizeof(int) * m_size);
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);
38
39 UINT32 varId = VID_ELEMENT_LIST_BASE;
40 for(int i = 0; i < m_size; i++, varId += 5)
41 {
42 msg->getFieldAsBinary(varId++, &m_guidList[i * UUID_LENGTH], UUID_LENGTH);
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++);
47 }
48 }
49 else
50 {
51 m_guidList = NULL;
52 m_typeList = NULL;
53 m_serverInfoList = NULL;
54 m_serverIdList = NULL;
55 m_version = NULL;
56 }
57 }
58
59 /**
60 * Destructor
61 */
62 AgentPolicyInfo::~AgentPolicyInfo()
63 {
64 for(int i = 0; i < m_size; i++)
65 free(m_serverInfoList[i]);
66 free(m_serverIdList);
67 free(m_typeList);
68 free(m_guidList);
69 free(m_version);
70 }
71
72 /**
73 * Get GUID
74 */
75 uuid AgentPolicyInfo::getGuid(int index)
76 {
77 if ((index >= 0) && (index < m_size))
78 {
79 return uuid(&m_guidList[index * UUID_LENGTH]);
80 }
81 else
82 {
83 return uuid::NULL_UUID;
84 }
85 }