malformed software package entries not added to package list during configuration...
[public/netxms.git] / src / server / core / swpkg.cpp
CommitLineData
caa04e26
VK
1/*
2** NetXMS - Network Management System
3e050a0b 3** Copyright (C) 2003-2017 Victor Kirhenshtein
caa04e26
VK
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 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 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: swpkg.cpp
20**
21**/
22
23#include "nxcore.h"
24
25/**
26 * Extract value from source table cell
27 */
28#define EXTRACT_VALUE(name, field) \
29 { \
30 if (!_tcsicmp(table->getColumnName(i), _T(name))) \
31 { \
32 const TCHAR *value = table->getAsString(row, i); \
3e050a0b 33 pkg->field = _tcsdup_ex(value); \
caa04e26
VK
34 continue; \
35 } \
36 }
37
3e050a0b
VK
38/**
39 * Create from agent table
40 *
41 * @param table table received from agent
42 * @param row row number in a table
43 * @return new object on success, NULL on parse error
44 */
45SoftwarePackage *SoftwarePackage::createFromTableRow(const Table *table, int row)
46{
47 SoftwarePackage *pkg = new SoftwarePackage();
48 for(int i = 0; i < table->getNumColumns(); i++)
49 {
50 EXTRACT_VALUE("NAME", m_name);
51 EXTRACT_VALUE("VERSION", m_version);
52 EXTRACT_VALUE("VENDOR", m_vendor);
53 EXTRACT_VALUE("URL", m_url);
54 EXTRACT_VALUE("DESCRIPTION", m_description);
55
56 if (!_tcsicmp(table->getColumnName(i), _T("DATE")))
57 pkg->m_date = (time_t)table->getAsInt(row, i);
58 }
59
60 if (pkg->m_name == NULL)
61 {
62 delete pkg;
63 return NULL;
64 }
65 return pkg;
66}
67
caa04e26
VK
68/**
69 * Constructor
70 *
71 * @param table table received from agent
72 * @param row row number in a table
73 */
3e050a0b 74SoftwarePackage::SoftwarePackage()
caa04e26
VK
75{
76 m_name = NULL;
77 m_version = NULL;
78 m_vendor = NULL;
79 m_date = 0;
80 m_url = NULL;
81 m_description = NULL;
caa04e26
VK
82}
83
84/**
85 * Destructor
86 */
87SoftwarePackage::~SoftwarePackage()
88{
3e050a0b
VK
89 free(m_name);
90 free(m_version);
91 free(m_vendor);
92 free(m_url);
93 free(m_description);
caa04e26
VK
94}
95
96/**
97 * Fill NXCP message with package data
98 */
1d7917d5 99void SoftwarePackage::fillMessage(NXCPMessage *msg, UINT32 baseId) const
caa04e26 100{
967893bb 101 UINT32 varId = baseId;
b368969c
VK
102 msg->setField(varId++, CHECK_NULL_EX(m_name));
103 msg->setField(varId++, CHECK_NULL_EX(m_version));
104 msg->setField(varId++, CHECK_NULL_EX(m_vendor));
105 msg->setField(varId++, (UINT32)m_date);
106 msg->setField(varId++, CHECK_NULL_EX(m_url));
107 msg->setField(varId++, CHECK_NULL_EX(m_description));
caa04e26 108}