license changed to LGPL for libnxcl, libnxsnmp, libnxlp, libnxsl, and libnxmap
[public/netxms.git] / src / libnxcl / mib.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Client Library
4 ** Copyright (C) 2003-2010 Victor Kirhenshtein
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published by
8 ** the Free Software Foundation; either version 3 of the License, or
9 ** (at your option) any later version.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 **
20 ** File: mib.cpp
21 **
22 **/
23
24 #include "libnxcl.h"
25
26 #if defined(_WIN32) && !defined(UNDER_CE)
27 # include <io.h>
28 #endif
29
30
31 //
32 // Download MIB file from server
33 //
34
35 DWORD LIBNXCL_EXPORTABLE NXCDownloadMIBFile(NXC_SESSION hSession, const TCHAR *pszName)
36 {
37 DWORD dwRqId, dwRetCode;
38 CSCPMessage msg;
39
40 dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
41 dwRetCode = ((NXCL_Session *)hSession)->PrepareFileTransfer(pszName, dwRqId);
42 if (dwRetCode == RCC_SUCCESS)
43 {
44 msg.SetCode(CMD_GET_MIB);
45 msg.SetId(dwRqId);
46 ((NXCL_Session *)hSession)->SendMsg(&msg);
47
48 // Loading file can take time, so timeout is 300 sec. instead of default
49 dwRetCode = ((NXCL_Session *)hSession)->WaitForFileTransfer(300000);
50 }
51 return dwRetCode;
52 }
53
54
55 //
56 // Get timestamp of server's MIB file
57 //
58
59 DWORD LIBNXCL_EXPORTABLE NXCGetMIBFileTimeStamp(NXC_SESSION hSession, DWORD *pdwTimeStamp)
60 {
61 DWORD dwRqId, dwRetCode;
62 CSCPMessage msg, *pResponse;
63
64 dwRqId = ((NXCL_Session *)hSession)->CreateRqId();
65
66 msg.SetCode(CMD_GET_MIB_TIMESTAMP);
67 msg.SetId(dwRqId);
68 ((NXCL_Session *)hSession)->SendMsg(&msg);
69
70 pResponse = ((NXCL_Session *)hSession)->WaitForMessage(CMD_REQUEST_COMPLETED, dwRqId);
71 if (pResponse != NULL)
72 {
73 dwRetCode = pResponse->GetVariableLong(VID_RCC);
74 if (dwRetCode == RCC_SUCCESS)
75 *pdwTimeStamp = pResponse->GetVariableLong(VID_TIMESTAMP);
76 delete pResponse;
77 }
78 else
79 {
80 dwRetCode = RCC_TIMEOUT;
81 }
82 return dwRetCode;
83 }