subagent specific API moved to separate library from libnetxms
authorVictor Kirhenshtein <victor@netxms.org>
Mon, 18 May 2015 09:19:29 +0000 (12:19 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Mon, 18 May 2015 09:19:29 +0000 (12:19 +0300)
48 files changed:
configure.ac
include/nms_agent.h
netxms.sln
src/agent/Makefile.am
src/agent/core/Makefile.am
src/agent/core/nxagentd.cpp
src/agent/core/nxagentd.h
src/agent/core/policy.cpp
src/agent/core/session.cpp
src/agent/libnxagent/Makefile.am [new file with mode: 0644]
src/agent/libnxagent/bridge.cpp [new file with mode: 0644]
src/agent/libnxagent/libnxagent.h [new file with mode: 0644]
src/agent/libnxagent/libnxagent.vcproj [copied from src/libnetxms/libnetxms.vcproj with 53% similarity]
src/agent/libnxagent/main.cpp [new file with mode: 0644]
src/agent/libnxagent/tools.cpp [new file with mode: 0644]
src/agent/nxsagent/screenshot.cpp
src/agent/subagents/aix/Makefile.am
src/agent/subagents/darwin/Makefile.am
src/agent/subagents/db2/Makefile.am
src/agent/subagents/dbquery/Makefile.am
src/agent/subagents/devemu/Makefile.am
src/agent/subagents/ds18x20/Makefile.am
src/agent/subagents/ecs/Makefile.am
src/agent/subagents/filemgr/Makefile.am
src/agent/subagents/freebsd/Makefile.am
src/agent/subagents/hpux/Makefile.am
src/agent/subagents/informix/Makefile.am
src/agent/subagents/ipso/Makefile.am
src/agent/subagents/java/Makefile.am
src/agent/subagents/linux/Makefile.am
src/agent/subagents/lmsensors/Makefile.am
src/agent/subagents/logwatch/Makefile.am
src/agent/subagents/mongodb/Makefile.am
src/agent/subagents/netbsd/Makefile.am
src/agent/subagents/netsvc/Makefile.am
src/agent/subagents/odbcquery/Makefile.am
src/agent/subagents/openbsd/Makefile.am
src/agent/subagents/oracle/Makefile.am
src/agent/subagents/ping/Makefile.am
src/agent/subagents/portCheck/Makefile.am
src/agent/subagents/rpi/Makefile.am
src/agent/subagents/sms/Makefile.am
src/agent/subagents/sunos/Makefile.am
src/agent/subagents/tuxedo/Makefile.am
src/agent/subagents/ups/Makefile.am
src/libnetxms/agent.cpp [deleted file]
src/libnetxms/libnetxms.vcproj
src/libnetxms/main.cpp

index e659745..520ca55 100644 (file)
@@ -2723,7 +2723,7 @@ AC_SUBST(MONGODB_LIBS)
 #      only the first ever interface is implemented, so age can only be `0'. 
 #--------------------------------------------------------------------
 
-NETXMS_LIBRARY_VERSION=1:0:0
+NETXMS_LIBRARY_VERSION=2:0:0
 AC_SUBST(NETXMS_LIBRARY_VERSION)
 
 #--------------------------------------------------------------------
@@ -2762,6 +2762,7 @@ AC_CONFIG_FILES([
        src/agent/appagent/Makefile
        src/agent/core/Makefile
        src/agent/install/Makefile
+       src/agent/libnxagent/Makefile
        src/agent/libnxappc/Makefile
        src/agent/libnxsd/Makefile
        src/agent/subagents/Makefile
index 8dedb6c..c2af3cc 100644 (file)
 #ifndef _nms_agent_h_
 #define _nms_agent_h_
 
+#ifdef _WIN32
+#ifdef LIBNXAGENT_EXPORTS
+#define LIBNXAGENT_EXPORTABLE __declspec(dllexport)
+#else
+#define LIBNXAGENT_EXPORTABLE __declspec(dllimport)
+#endif
+#else    /* _WIN32 */
+#define LIBNXAGENT_EXPORTABLE
+#endif
+
+
 #include <nms_common.h>
 #include <nms_util.h>
 #include <nxconfig.h>
@@ -531,48 +542,50 @@ inline void ret_uint64(TCHAR *rbuf, QWORD value)
 #endif   /* _WIN32 */
 }
 
-//
-// API for subagents
-//
-BOOL LIBNETXMS_EXPORTABLE AgentGetParameterArgA(const TCHAR *param, int index, char *arg, int maxSize);
-BOOL LIBNETXMS_EXPORTABLE AgentGetParameterArgW(const TCHAR *param, int index, WCHAR *arg, int maxSize);
+/**
+ * API for subagents
+ */
+bool LIBNXAGENT_EXPORTABLE AgentGetParameterArgA(const TCHAR *param, int index, char *arg, int maxSize);
+bool LIBNXAGENT_EXPORTABLE AgentGetParameterArgW(const TCHAR *param, int index, WCHAR *arg, int maxSize);
 #ifdef UNICODE
 #define AgentGetParameterArg AgentGetParameterArgW
 #else
 #define AgentGetParameterArg AgentGetParameterArgA
 #endif
 
-void LIBNETXMS_EXPORTABLE AgentWriteLog(int logLevel, const TCHAR *format, ...)
+void LIBNXAGENT_EXPORTABLE AgentWriteLog(int logLevel, const TCHAR *format, ...)
 #if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
    __attribute__ ((format(printf, 2, 3)))
 #endif
 ;
-void LIBNETXMS_EXPORTABLE AgentWriteLog2(int logLevel, const TCHAR *format, va_list args);
-void LIBNETXMS_EXPORTABLE AgentWriteDebugLog(int level, const TCHAR *format, ...)
+void LIBNXAGENT_EXPORTABLE AgentWriteLog2(int logLevel, const TCHAR *format, va_list args);
+void LIBNXAGENT_EXPORTABLE AgentWriteDebugLog(int level, const TCHAR *format, ...)
 #if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
    __attribute__ ((format(printf, 2, 3)))
 #endif
 ;
-void LIBNETXMS_EXPORTABLE AgentWriteDebugLog2(int level, const TCHAR *format, va_list args);
-void LIBNETXMS_EXPORTABLE AgentSendTrap(UINT32 dwEvent, const TCHAR *eventName, const char *pszFormat, ...);
-void LIBNETXMS_EXPORTABLE AgentSendTrap2(UINT32 dwEvent, const TCHAR *eventName, int nCount, TCHAR **ppszArgList);
-bool LIBNETXMS_EXPORTABLE EnumerateSessions(bool (* callback)(AbstractCommSession *, void *), void *data);
-BOOL LIBNETXMS_EXPORTABLE AgentSendFileToServer(void *session, UINT32 requestId, const TCHAR *file, long offset);
-BOOL LIBNETXMS_EXPORTABLE AgentPushParameterData(const TCHAR *parameter, const TCHAR *value);
-BOOL LIBNETXMS_EXPORTABLE AgentPushParameterDataInt32(const TCHAR *parameter, LONG value);
-BOOL LIBNETXMS_EXPORTABLE AgentPushParameterDataUInt32(const TCHAR *parameter, UINT32 value);
-BOOL LIBNETXMS_EXPORTABLE AgentPushParameterDataInt64(const TCHAR *parameter, INT64 value);
-BOOL LIBNETXMS_EXPORTABLE AgentPushParameterDataUInt64(const TCHAR *parameter, QWORD value);
-BOOL LIBNETXMS_EXPORTABLE AgentPushParameterDataDouble(const TCHAR *parameter, double value);
-CONDITION LIBNETXMS_EXPORTABLE AgentGetShutdownCondition();
-bool LIBNETXMS_EXPORTABLE AgentSleepAndCheckForShutdown(UINT32 sleepTime);
-
-void LIBNETXMS_EXPORTABLE InitSubAgentAPI(void (* writeLog)(int, int, const TCHAR *),
-                                          void (* sendTrap1)(UINT32, const TCHAR *, const char *, va_list),
-                                          void (* sendTrap2)(UINT32, const TCHAR *, int, TCHAR **),
-                                                                                                               bool (* enumerateSessions)(bool (*)(AbstractCommSession *, void *), void *),
-                                          bool (* sendFile)(void *, UINT32, const TCHAR *, long),
-                                          bool (* pushData)(const TCHAR *, const TCHAR *, UINT32),
-                                          CONDITION shutdownCondition);
+void LIBNXAGENT_EXPORTABLE AgentWriteDebugLog2(int level, const TCHAR *format, va_list args);
+
+void LIBNXAGENT_EXPORTABLE AgentSendTrap(UINT32 dwEvent, const TCHAR *eventName, const char *pszFormat, ...);
+void LIBNXAGENT_EXPORTABLE AgentSendTrap2(UINT32 dwEvent, const TCHAR *eventName, int nCount, TCHAR **ppszArgList);
+
+bool LIBNXAGENT_EXPORTABLE EnumerateSessions(bool (* callback)(AbstractCommSession *, void *), void *data);
+
+bool LIBNXAGENT_EXPORTABLE AgentSendFileToServer(void *session, UINT32 requestId, const TCHAR *file, long offset);
+
+bool LIBNXAGENT_EXPORTABLE AgentPushParameterData(const TCHAR *parameter, const TCHAR *value);
+bool LIBNXAGENT_EXPORTABLE AgentPushParameterDataInt32(const TCHAR *parameter, LONG value);
+bool LIBNXAGENT_EXPORTABLE AgentPushParameterDataUInt32(const TCHAR *parameter, UINT32 value);
+bool LIBNXAGENT_EXPORTABLE AgentPushParameterDataInt64(const TCHAR *parameter, INT64 value);
+bool LIBNXAGENT_EXPORTABLE AgentPushParameterDataUInt64(const TCHAR *parameter, QWORD value);
+bool LIBNXAGENT_EXPORTABLE AgentPushParameterDataDouble(const TCHAR *parameter, double value);
+
+CONDITION LIBNXAGENT_EXPORTABLE AgentGetShutdownCondition();
+bool LIBNXAGENT_EXPORTABLE AgentSleepAndCheckForShutdown(UINT32 sleepTime);
+
+Config LIBNXAGENT_EXPORTABLE *AgentOpenRegistry();
+void LIBNXAGENT_EXPORTABLE AgentCloseRegistry(bool modified);
+
+const TCHAR LIBNXAGENT_EXPORTABLE *AgentGetDataDirectory();
 
 #endif   /* _nms_agent_h_ */
index aefa1db..f5bddde 100644 (file)
@@ -18,10 +18,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxlp", "src\libnxlp\libn
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxagentd", "src\agent\core\nxagentd.vcproj", "{57598B02-3295-4FE8-9322-94CE871CC84D}"
        ProjectSection(ProjectDependencies) = postProject
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
                {6B249E47-4BAF-4DE2-B62B-C6DD0330753F} = {6B249E47-4BAF-4DE2-B62B-C6DD0330753F}
                {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
                {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "subagents", "subagents", "{451F583D-C2DB-4414-870C-7FA0189BE7DD}"
@@ -37,52 +38,62 @@ EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winnt", "src\agent\subagents\winnt\winnt.vcproj", "{E95263B5-A248-4163-95F3-E33CA679AEB3}"
        ProjectSection(ProjectDependencies) = postProject
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winperf", "src\agent\subagents\winperf\winperf.vcproj", "{EE54BC06-6B0F-4B91-9FC6-A5BB9ECBE577}"
        ProjectSection(ProjectDependencies) = postProject
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wmi", "src\agent\subagents\wmi\wmi.vcproj", "{4E190DD5-70DA-41EC-8D05-5EE8D74F3709}"
        ProjectSection(ProjectDependencies) = postProject
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ups", "src\agent\subagents\ups\ups.vcproj", "{53A73D5F-C7E2-449E-A222-F2D78C85D514}"
        ProjectSection(ProjectDependencies) = postProject
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sms", "src\agent\subagents\sms\sms.vcproj", "{DE47D07A-C81B-4772-86D4-13389F263923}"
        ProjectSection(ProjectDependencies) = postProject
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "portcheck", "src\agent\subagents\portcheck\portcheck.vcproj", "{F66A27F0-2943-4A16-ACC7-B450314B5163}"
        ProjectSection(ProjectDependencies) = postProject
-               {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
+               {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ping", "src\agent\subagents\ping\ping.vcproj", "{C5CCF5DE-152E-40F3-AC6C-C5E54BB7C45F}"
        ProjectSection(ProjectDependencies) = postProject
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "odbcquery", "src\agent\subagents\odbcquery\odbcquery.vcproj", "{1A2D2691-D9D4-4078-BBC4-A53DAF086D0C}"
        ProjectSection(ProjectDependencies) = postProject
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "logwatch", "src\agent\subagents\logwatch\logwatch.vcproj", "{F8A8749E-E539-4A3B-A21C-2C5C86AE33EA}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {64EFC0C2-C67B-41F6-851D-F11DAB27A60B} = {64EFC0C2-C67B-41F6-851D-F11DAB27A60B}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ecs", "src\agent\subagents\ecs\ecs.vcproj", "{BBE9028E-725C-45C6-97C9-BFC443F19DB6}"
        ProjectSection(ProjectDependencies) = postProject
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
@@ -159,6 +170,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxsrv", "src\server\libn
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxcore", "src\server\core\nxcore.vcproj", "{3B172035-5EEC-45A3-8471-2C390B7ED683}"
        ProjectSection(ProjectDependencies) = postProject
+               {AB386821-B630-49F5-95C3-677B9DCE1270} = {AB386821-B630-49F5-95C3-677B9DCE1270}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
                {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {F4169894-5C48-4E11-A82E-1055F9572EEF} = {F4169894-5C48-4E11-A82E-1055F9572EEF}
                {B2988503-1921-4B9F-BBC1-5E5CF62F335E} = {B2988503-1921-4B9F-BBC1-5E5CF62F335E}
@@ -167,7 +180,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxcore", "src\server\core\n
                {64EFC0C2-C67B-41F6-851D-F11DAB27A60B} = {64EFC0C2-C67B-41F6-851D-F11DAB27A60B}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
-               {AB386821-B630-49F5-95C3-677B9DCE1270} = {AB386821-B630-49F5-95C3-677B9DCE1270}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nxsl", "nxsl", "{CE0DA89E-CF0C-452C-9C33-75A143355BDC}"
@@ -384,8 +396,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "informix", "src\db\dbdrv\in
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "informix", "src\agent\subagents\informix\informix.vcproj", "{12F5AF3E-A688-4852-A0ED-921D0E088AC4}"
        ProjectSection(ProjectDependencies) = postProject
-               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
+               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dbemu", "src\server\smsdrv\dbemu\dbemu.vcproj", "{912783D2-CF6F-4040-B564-4E2436EB0827}"
@@ -410,9 +423,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "catalyst", "src\server\driv
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "oracle", "src\agent\subagents\oracle\oracle.vcproj", "{90B762AB-B7BA-42D6-9819-C687AB3F59D0}"
        ProjectSection(ProjectDependencies) = postProject
+               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
-               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{896A7CDA-423A-460A-83E2-6ED37DAE187C}"
@@ -444,8 +458,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxsd", "src\agent\libnxs
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dbquery", "src\agent\subagents\dbquery\dbquery.vcproj", "{784D1668-124C-46D9-B985-51276FFA282A}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "appagent", "src\agent\appagent\appagent.vcproj", "{6B249E47-4BAF-4DE2-B62B-C6DD0330753F}"
@@ -502,6 +517,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "driverloader", "src\server\
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "java", "src\agent\subagents\java\java.vcproj", "{4967B29B-4272-4D7B-9CF6-8ABFF9D21348}"
        ProjectSection(ProjectDependencies) = postProject
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
@@ -531,8 +547,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libstrophe", "src\libstroph
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "netsvc", "src\agent\subagents\netsvc\netsvc.vcproj", "{17C5C5F3-3F13-47F4-8606-1EC9B5416DB2}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cisco-sb", "src\server\drivers\cisco-sb\cisco-sb.vcproj", "{6D040459-7E6D-44A5-95EE-636853A05033}"
@@ -543,6 +560,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cisco-sb", "src\server\driv
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "devemu", "src\agent\subagents\devemu\devemu.vcproj", "{BBE9028E-725C-45C6-97C9-BFC443F19DB7}"
        ProjectSection(ProjectDependencies) = postProject
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
@@ -587,12 +605,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ubnt", "src\server\drivers\
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "db2", "src\agent\subagents\db2\db2.vcproj", "{90B762AB-B7BA-42D6-9819-C787AB3F59D1}"
        ProjectSection(ProjectDependencies) = postProject
-               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
+               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "filemgr", "src\agent\subagents\filemgr\filemgr.vcproj", "{BBE9028E-725C-45C6-97C9-BFC443F19EA8}"
        ProjectSection(ProjectDependencies) = postProject
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
@@ -603,8 +623,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "src\libpng\libpng
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxsagent", "src\agent\nxsagent\nxsagent.vcproj", "{9C6790BA-385D-476D-944A-552C87018733}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {C1A5E28A-CF47-4D96-9656-3312F16E3724} = {C1A5E28A-CF47-4D96-9656-3312F16E3724}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{6FC2F162-5E91-47D7-AE00-45C595ED8C85}"
@@ -645,6 +665,7 @@ EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tuxedo", "src\agent\subagents\tuxedo\tuxedo.vcproj", "{30630D53-7B8E-45CF-BFBB-652D9206ED66}"
        ProjectSection(ProjectDependencies) = postProject
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {811F41FE-131D-491A-9184-FBE687068D34}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hpsw", "src\server\drivers\hpsw\hpsw.vcproj", "{B51F1406-AF43-4396-96C0-31176DDCA4FC}"
@@ -673,6 +694,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxgenguid", "src\tools\nxge
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxappc", "src\agent\libnxappc\libnxappc.vcproj", "{2EB4459F-6D5D-4DAE-885B-2F2132631A59}"
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxagent", "src\agent\libnxagent\libnxagent.vcproj", "{811F41FE-131D-491A-9184-FBE687068D34}"
+       ProjectSection(ProjectDependencies) = postProject
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+       EndProjectSection
+EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Win32 = Debug|Win32
@@ -1553,6 +1579,14 @@ Global
                {2EB4459F-6D5D-4DAE-885B-2F2132631A59}.Release|Win32.Build.0 = Release|Win32
                {2EB4459F-6D5D-4DAE-885B-2F2132631A59}.Release|x64.ActiveCfg = Release|x64
                {2EB4459F-6D5D-4DAE-885B-2F2132631A59}.Release|x64.Build.0 = Release|x64
+               {811F41FE-131D-491A-9184-FBE687068D34}.Debug|Win32.ActiveCfg = Debug|Win32
+               {811F41FE-131D-491A-9184-FBE687068D34}.Debug|Win32.Build.0 = Debug|Win32
+               {811F41FE-131D-491A-9184-FBE687068D34}.Debug|x64.ActiveCfg = Debug|x64
+               {811F41FE-131D-491A-9184-FBE687068D34}.Debug|x64.Build.0 = Debug|x64
+               {811F41FE-131D-491A-9184-FBE687068D34}.Release|Win32.ActiveCfg = Release|Win32
+               {811F41FE-131D-491A-9184-FBE687068D34}.Release|Win32.Build.0 = Release|Win32
+               {811F41FE-131D-491A-9184-FBE687068D34}.Release|x64.ActiveCfg = Release|x64
+               {811F41FE-131D-491A-9184-FBE687068D34}.Release|x64.Build.0 = Release|x64
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
@@ -1577,6 +1611,7 @@ Global
                {6B249E47-4BAF-4DE2-B62B-C6DD0330753F} = {8BC9D64D-347C-41BE-A506-D21C8FB72D56}
                {9C6790BA-385D-476D-944A-552C87018733} = {8BC9D64D-347C-41BE-A506-D21C8FB72D56}
                {2EB4459F-6D5D-4DAE-885B-2F2132631A59} = {8BC9D64D-347C-41BE-A506-D21C8FB72D56}
+               {811F41FE-131D-491A-9184-FBE687068D34} = {8BC9D64D-347C-41BE-A506-D21C8FB72D56}
                {E95263B5-A248-4163-95F3-E33CA679AEB3} = {451F583D-C2DB-4414-870C-7FA0189BE7DD}
                {EE54BC06-6B0F-4B91-9FC6-A5BB9ECBE577} = {451F583D-C2DB-4414-870C-7FA0189BE7DD}
                {4E190DD5-70DA-41EC-8D05-5EE8D74F3709} = {451F583D-C2DB-4414-870C-7FA0189BE7DD}
index 1f90a52..a755626 100644 (file)
@@ -8,4 +8,4 @@
 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
-SUBDIRS = appagent libnxappc libnxsd subagents core install tools
+SUBDIRS = appagent libnxagent libnxappc libnxsd subagents core install tools
index 3a8e5b0..502c082 100644 (file)
@@ -7,9 +7,9 @@ nxagentd_SOURCES = messages.c actions.cpp appagent.cpp comm.cpp config.cpp \
                    snmptrapproxy.cpp static_subagents.cpp subagent.cpp \
                    sysinfo.cpp tools.cpp trap.cpp upgrade.cpp watchdog.cpp
 if USE_INTERNAL_EXPAT
-nxagentd_LDADD = ../appagent/libappagent.la @top_srcdir@/src/db/libnxdb/libnxdb.la @top_srcdir@/src/libnetxms/libnetxms.la @top_srcdir@/src/snmp/libnxsnmp/libnxsnmp.la @top_srcdir@/src/libexpat/libexpat/libnxexpat.la @SUBAGENT_LIBS@
+nxagentd_LDADD = ../appagent/libappagent.la ../libnxagent/libnxagent.la @top_srcdir@/src/db/libnxdb/libnxdb.la @top_srcdir@/src/libnetxms/libnetxms.la @top_srcdir@/src/snmp/libnxsnmp/libnxsnmp.la @top_srcdir@/src/libexpat/libexpat/libnxexpat.la @SUBAGENT_LIBS@
 else
-nxagentd_LDADD = ../appagent/libappagent.la @top_srcdir@/src/db/libnxdb/libnxdb.la @top_srcdir@/src/libnetxms/libnetxms.la @top_srcdir@/src/snmp/libnxsnmp/libnxsnmp.la @SUBAGENT_LIBS@ 
+nxagentd_LDADD = ../appagent/libappagent.la ../libnxagent/libnxagent.la @top_srcdir@/src/db/libnxdb/libnxdb.la @top_srcdir@/src/libnetxms/libnetxms.la @top_srcdir@/src/snmp/libnxsnmp/libnxsnmp.la @SUBAGENT_LIBS@ 
 endif
 if USE_ENCRYPTION
 nxagentd_LDADD += -lssl
index f771897..3320a21 100644 (file)
@@ -76,6 +76,15 @@ extern TCHAR g_windowsServiceName[];
 extern TCHAR g_windowsServiceDisplayName[];
 #endif
 
+void LIBNXAGENT_EXPORTABLE InitSubAgentAPI(void (* writeLog)(int, int, const TCHAR *),
+                                                                                                               void (* sendTrap1)(UINT32, const TCHAR *, const char *, va_list),
+                                                                                                               void (* sendTrap2)(UINT32, const TCHAR *, int, TCHAR **),
+                                                                                                               bool (* enumerateSessions)(bool (*)(AbstractCommSession *, void *), void*),
+                                                                                                               bool (* sendFile)(void *, UINT32, const TCHAR *, long),
+                                                                                                               bool (* pushData)(const TCHAR *, const TCHAR *, UINT32),
+                                          CONDITION shutdownCondition, Config *registry,
+                                          void (* saveRegistry)(), const TCHAR *dataDirectory);
+
 /**
  * Messages generated by mc.pl (for UNIX version only)
  */
@@ -396,25 +405,6 @@ static void SaveRegistry()
        }
 }
 
-/**
- * Open registry
- */
-Config *OpenRegistry()
-{
-       s_registry->lock();
-       return s_registry;
-}
-
-/**
- * Close registry
- */
-void CloseRegistry(bool modified)
-{
-       if (modified)
-               SaveRegistry();
-       s_registry->unlock();
-}
-
 #ifdef _WIN32
 
 /**
@@ -772,7 +762,9 @@ BOOL Initialize()
 
    // Initialize API for subagents
    s_subAgentsStopCondition = ConditionCreate(TRUE);
-   InitSubAgentAPI(WriteSubAgentMsg, SendTrap, SendTrap, EnumerateSessionsBySubagent, SendFileToServer, PushData, s_subAgentsStopCondition);
+   InitSubAgentAPI(WriteSubAgentMsg, SendTrap, SendTrap, EnumerateSessionsBySubagent, 
+      SendFileToServer, PushData, s_subAgentsStopCondition, s_registry, SaveRegistry,
+      g_szDataDirectory);
    DebugPrintf(INVALID_INDEX, 1, _T("Subagent API initialized"));
 
    // Initialize cryptografy
@@ -1039,17 +1031,17 @@ BOOL Initialize()
                        StartWatchdog();
        }
 
-       //Delete file for upgrade if exists
-   Config *registry = OpenRegistry();
+       // Delete file used for upgrade if exists
+   Config *registry = AgentOpenRegistry();
    const TCHAR* szFullPath = registry->getValue(_T("/upgrade/file"));
-   if(szFullPath != NULL){
+   if(szFullPath != NULL)
+   {
       _tremove(szFullPath);
    }
    registry->deleteEntry(_T("/upgrade/file"));
-   CloseRegistry(true);
+   AgentCloseRegistry(true);
 
        delete g_config;
-
    return TRUE;
 }
 
index 4df6d6c..8c6a7ab 100644 (file)
@@ -499,9 +499,6 @@ void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, const char *pszFormat,
 void SendTrap(UINT32 dwEventCode, const TCHAR *eventName, const char *pszFormat, va_list args);
 void ForwardTrap(NXCPMessage *msg);
 
-Config *OpenRegistry();
-void CloseRegistry(bool modified);
-
 void StartPushConnector();
 bool PushData(const TCHAR *parameter, const TCHAR *value, UINT32 objectId);
 
index 25932a2..772bdad 100644 (file)
@@ -40,7 +40,7 @@ static void RegisterPolicy(CommSession *session, UINT32 type, uuid_t guid)
        _sntprintf(path, 256, POLICY_REGISTRY_PATH _T("/policy-%s/"), uuid_to_string(guid, buffer));
        tail = (int)_tcslen(path);
 
-       Config *registry = OpenRegistry();
+       Config *registry = AgentOpenRegistry();
 
        _tcscpy(&path[tail], _T("type"));
        registry->setValue(path, type);
@@ -48,7 +48,7 @@ static void RegisterPolicy(CommSession *session, UINT32 type, uuid_t guid)
        _tcscpy(&path[tail], _T("server"));
    registry->setValue(path, session->getServerAddress().toString(buffer));
 
-       CloseRegistry(true);
+       AgentCloseRegistry(true);
 }
 
 /**
@@ -59,9 +59,9 @@ static void UnregisterPolicy(uuid_t guid)
        TCHAR path[256], buffer[64];
 
        _sntprintf(path, 256, POLICY_REGISTRY_PATH _T("/policy-%s"), uuid_to_string(guid, buffer));
-       Config *registry = OpenRegistry();
+       Config *registry = AgentOpenRegistry();
        registry->deleteEntry(path);
-       CloseRegistry(true);
+       AgentCloseRegistry(true);
 }
 
 /**
@@ -73,9 +73,9 @@ static int GetPolicyType(uuid_t guid)
        int type;
 
        _sntprintf(path, 256, POLICY_REGISTRY_PATH _T("/policy-%s/type"), uuid_to_string(guid, buffer));
-       Config *registry = OpenRegistry();
+       Config *registry = AgentOpenRegistry();
        type = registry->getValueAsInt(path, -1);
-       CloseRegistry(false);
+       AgentCloseRegistry(false);
        return type;
 }
 
@@ -252,7 +252,7 @@ UINT32 UninstallPolicy(CommSession *session, NXCPMessage *request)
  */
 UINT32 GetPolicyInventory(CommSession *session, NXCPMessage *msg)
 {
-       Config *registry = OpenRegistry();
+       Config *registry = AgentOpenRegistry();
 
        ObjectArray<ConfigEntry> *list = registry->getSubEntries(_T("/policyRegistry"), NULL);
        if (list != NULL)
@@ -279,6 +279,6 @@ UINT32 GetPolicyInventory(CommSession *session, NXCPMessage *msg)
                msg->setField(VID_NUM_ELEMENTS, (UINT32)0);
        }
        
-       CloseRegistry(false);
+       AgentCloseRegistry(false);
        return RCC_SUCCESS;
 }
index c4ada49..4668922 100644 (file)
@@ -816,9 +816,9 @@ UINT32 CommSession::upgrade(NXCPMessage *pRequest)
       BuildFullPath(szPkgName, szFullPath);
 
       //Create line in registry file with upgrade file name to delete it after system start
-      Config *registry = OpenRegistry();
+      Config *registry = AgentOpenRegistry();
       registry->setValue(_T("/upgrade/file"), szFullPath);
-      CloseRegistry(true);
+      AgentCloseRegistry(true);
 
       return UpgradeAgent(szFullPath);
    }
diff --git a/src/agent/libnxagent/Makefile.am b/src/agent/libnxagent/Makefile.am
new file mode 100644 (file)
index 0000000..b206e11
--- /dev/null
@@ -0,0 +1,10 @@
+SOURCES = bridge.cpp main.cpp tools.cpp
+
+lib_LTLIBRARIES = libnxagent.la
+
+libnxagent_la_SOURCES = $(SOURCES)
+libnxagent_la_CPPFLAGS=-I@top_srcdir@/include
+libnxagent_la_LDFLAGS = -version-info $(NETXMS_LIBRARY_VERSION)
+libnxagent_la_LIBADD = ../../libnetxms/libnetxms.la
+
+EXTRA_DIST = libnxagent.h libnxagent.vcproj
diff --git a/src/agent/libnxagent/bridge.cpp b/src/agent/libnxagent/bridge.cpp
new file mode 100644 (file)
index 0000000..de742f2
--- /dev/null
@@ -0,0 +1,281 @@
+/*
+** NetXMS - Network Management System
+** Copyright (C) 2003-2015 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published
+** by the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: bridge.cpp
+**
+**/
+
+#include "libnxagent.h"
+
+/**
+ * Static data
+ */
+static void (* s_fpWriteLog)(int, int, const TCHAR *) = NULL;
+static void (* s_fpSendTrap1)(UINT32, const TCHAR *, const char *, va_list) = NULL;
+static void (* s_fpSendTrap2)(UINT32, const TCHAR *, int, TCHAR **) = NULL;
+static bool (* s_fpEnumerateSessions)(bool (*)(AbstractCommSession *, void *), void *) = NULL;
+static bool (* s_fpSendFile)(void *, UINT32, const TCHAR *, long) = NULL;
+static bool (* s_fpPushData)(const TCHAR *, const TCHAR *, UINT32) = NULL;
+static CONDITION s_agentShutdownCondition = INVALID_CONDITION_HANDLE;
+static Config *s_registry = NULL;
+static void (* s_fpSaveRegistry)() = NULL;
+static const TCHAR *s_dataDirectory = NULL;
+
+/**
+ * Initialize subagent API
+ */
+void LIBNXAGENT_EXPORTABLE InitSubAgentAPI(void (* writeLog)(int, int, const TCHAR *),
+                                                                                                               void (* sendTrap1)(UINT32, const TCHAR *, const char *, va_list),
+                                                                                                               void (* sendTrap2)(UINT32, const TCHAR *, int, TCHAR **),
+                                                                                                               bool (* enumerateSessions)(bool (*)(AbstractCommSession *, void *), void*),
+                                                                                                               bool (* sendFile)(void *, UINT32, const TCHAR *, long),
+                                                                                                               bool (* pushData)(const TCHAR *, const TCHAR *, UINT32),
+                                          CONDITION shutdownCondition, Config *registry,
+                                          void (* saveRegistry)(), const TCHAR *dataDirectory)
+{
+   s_fpWriteLog = writeLog;
+       s_fpSendTrap1 = sendTrap1;
+       s_fpSendTrap2 = sendTrap2;
+       s_fpEnumerateSessions = enumerateSessions;
+       s_fpSendFile = sendFile;
+       s_fpPushData = pushData;
+   s_agentShutdownCondition = shutdownCondition;
+   s_registry = registry;
+   s_fpSaveRegistry = saveRegistry;
+   s_dataDirectory = dataDirectory;
+}
+
+/**
+ * Write message to agent's log
+ */
+void LIBNXAGENT_EXPORTABLE AgentWriteLog(int logLevel, const TCHAR *format, ...)
+{
+   TCHAR szBuffer[4096];
+   va_list args;
+
+   if (s_fpWriteLog != NULL)
+   {
+      va_start(args, format);
+      _vsntprintf(szBuffer, 4096, format, args);
+      va_end(args);
+      s_fpWriteLog(logLevel, 0, szBuffer);
+   }
+}
+
+/**
+ * Write message to agent's log
+ */
+void LIBNXAGENT_EXPORTABLE AgentWriteLog2(int logLevel, const TCHAR *format, va_list args)
+{
+   TCHAR szBuffer[4096];
+
+   if (s_fpWriteLog != NULL)
+   {
+      _vsntprintf(szBuffer, 4096, format, args);
+      s_fpWriteLog(logLevel, 0, szBuffer);
+   }
+}
+
+/**
+ * Write debug message to agent's log
+ */
+void LIBNXAGENT_EXPORTABLE AgentWriteDebugLog(int level, const TCHAR *format, ...)
+{
+   TCHAR szBuffer[4096];
+   va_list args;
+
+   if (s_fpWriteLog != NULL)
+   {
+      va_start(args, format);
+      _vsntprintf(szBuffer, 4096, format, args);
+      va_end(args);
+      s_fpWriteLog(EVENTLOG_DEBUG_TYPE, level, szBuffer);
+   }
+}
+
+/**
+ * Write debug message to agent's log
+ */
+void LIBNXAGENT_EXPORTABLE AgentWriteDebugLog2(int level, const TCHAR *format, va_list args)
+{
+   TCHAR szBuffer[4096];
+
+   if (s_fpWriteLog != NULL)
+   {
+      _vsntprintf(szBuffer, 4096, format, args);
+      s_fpWriteLog(EVENTLOG_DEBUG_TYPE, level, szBuffer);
+   }
+}
+
+/**
+ * Send trap from agent to server
+ */
+void LIBNXAGENT_EXPORTABLE AgentSendTrap(UINT32 dwEvent, const TCHAR *eventName, const char *pszFormat, ...)
+{
+   va_list args;
+
+   if (s_fpSendTrap1 != NULL)
+   {
+      va_start(args, pszFormat);
+      s_fpSendTrap1(dwEvent, eventName, pszFormat, args);
+      va_end(args);
+   }
+}
+
+/**
+ * Send trap from agent to server
+ */
+void LIBNXAGENT_EXPORTABLE AgentSendTrap2(UINT32 dwEvent, const TCHAR *eventName, int nCount, TCHAR **ppszArgList)
+{
+   if (s_fpSendTrap2 != NULL)
+      s_fpSendTrap2(dwEvent, eventName, nCount, ppszArgList);
+}
+
+/**
+ * Goes throught all sessions and executes
+ */
+bool LIBNXAGENT_EXPORTABLE EnumerateSessions(bool (* callback)(AbstractCommSession *, void *), void *data)
+{
+   if (s_fpEnumerateSessions != NULL)
+   {
+      return s_fpEnumerateSessions(callback, data);
+   }
+   else
+      return false;
+}
+
+/**
+ * Send file to server
+ */
+bool LIBNXAGENT_EXPORTABLE AgentSendFileToServer(void *session, UINT32 requestId, const TCHAR *file, long offset)
+{
+       if ((s_fpSendFile == NULL) || (session == NULL) || (file == NULL))
+               return FALSE;
+       return s_fpSendFile(session, requestId, file, offset);
+}
+
+/**
+ * Push parameter's value
+ */
+bool LIBNXAGENT_EXPORTABLE AgentPushParameterData(const TCHAR *parameter, const TCHAR *value)
+{
+       if (s_fpPushData == NULL)
+               return FALSE;
+       return s_fpPushData(parameter, value, 0);
+}
+
+/**
+ * Push parameter's value
+ */
+bool LIBNXAGENT_EXPORTABLE AgentPushParameterDataInt32(const TCHAR *parameter, LONG value)
+{
+       TCHAR buffer[64];
+
+       _sntprintf(buffer, sizeof(buffer), _T("%d"), (int)value);
+       return AgentPushParameterData(parameter, buffer);
+}
+
+/**
+ * Push parameter's value
+ */
+bool LIBNXAGENT_EXPORTABLE AgentPushParameterDataUInt32(const TCHAR *parameter, UINT32 value)
+{
+       TCHAR buffer[64];
+
+       _sntprintf(buffer, sizeof(buffer), _T("%u"), (unsigned int)value);
+       return AgentPushParameterData(parameter, buffer);
+}
+
+/**
+ * Push parameter's value
+ */
+bool LIBNXAGENT_EXPORTABLE AgentPushParameterDataInt64(const TCHAR *parameter, INT64 value)
+{
+       TCHAR buffer[64];
+
+       _sntprintf(buffer, sizeof(buffer), INT64_FMT, value);
+       return AgentPushParameterData(parameter, buffer);
+}
+
+/**
+ * Push parameter's value
+ */
+bool LIBNXAGENT_EXPORTABLE AgentPushParameterDataUInt64(const TCHAR *parameter, QWORD value)
+{
+       TCHAR buffer[64];
+
+       _sntprintf(buffer, sizeof(buffer), UINT64_FMT, value);
+       return AgentPushParameterData(parameter, buffer);
+}
+
+/**
+ * Push parameter's value
+ */
+bool LIBNXAGENT_EXPORTABLE AgentPushParameterDataDouble(const TCHAR *parameter, double value)
+{
+       TCHAR buffer[64];
+
+       _sntprintf(buffer, sizeof(buffer), _T("%f"), value);
+       return AgentPushParameterData(parameter, buffer);
+}
+
+/**
+ * Get shutdown condition
+ */
+CONDITION LIBNXAGENT_EXPORTABLE AgentGetShutdownCondition()
+{
+   return s_agentShutdownCondition;
+}
+
+/**
+ * Sleep and check for agent shutdown
+ */
+bool LIBNXAGENT_EXPORTABLE AgentSleepAndCheckForShutdown(UINT32 sleepTime)
+{
+   return ConditionWait(s_agentShutdownCondition, sleepTime);
+}
+
+/**
+ * Open registry
+ */
+Config LIBNXAGENT_EXPORTABLE *AgentOpenRegistry()
+{
+       s_registry->lock();
+       return s_registry;
+}
+
+/**
+ * Close registry
+ */
+void LIBNXAGENT_EXPORTABLE AgentCloseRegistry(bool modified)
+{
+       if (modified)
+   {
+      if (s_fpSaveRegistry != NULL)
+                  s_fpSaveRegistry();
+   }
+       s_registry->unlock();
+}
+
+/**
+ * Get data directory
+ */
+const TCHAR LIBNXAGENT_EXPORTABLE *AgentGetDataDirectory()
+{
+   return s_dataDirectory;
+}
diff --git a/src/agent/libnxagent/libnxagent.h b/src/agent/libnxagent/libnxagent.h
new file mode 100644 (file)
index 0000000..d32239c
--- /dev/null
@@ -0,0 +1,30 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2003-2015 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: libnxagent.h
+**
+**/
+
+#ifndef _libnxagent_h_
+#define _libnxagent_h_
+
+#include <nms_common.h>
+#include <nms_util.h>
+#include <nms_agent.h>
+
+#endif
similarity index 53%
copy from src/libnetxms/libnetxms.vcproj
copy to src/agent/libnxagent/libnxagent.vcproj
index 3e88e70..3f8fe37 100644 (file)
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="windows-1251"?>
+<?xml version="1.0" encoding="Windows-1252"?>
 <VisualStudioProject
        ProjectType="Visual C++"
        Version="8.00"
-       Name="libnetxms"
-       ProjectGUID="{B1745870-F3ED-4ACB-B813-0C4F47EF0793}"
-       RootNamespace="libnetxms"
+       Name="libnxagent"
+       ProjectGUID="{811F41FE-131D-491A-9184-FBE687068D34}"
+       RootNamespace="libnxagent"
        Keyword="Win32Proj"
        >
        <Platforms>
                        <Tool
                                Name="VCCLCompilerTool"
                                Optimization="0"
-                               AdditionalIncludeDirectories="..\..\include;..\libexpat\libexpat"
-                               PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;_DEBUG;_USRDLL;LIBNETXMS_EXPORTS"
+                               AdditionalIncludeDirectories="..\..\..\include"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBNXAGENT_EXPORTS"
                                MinimalRebuild="true"
-                               ExceptionHandling="0"
                                BasicRuntimeChecks="3"
                                RuntimeLibrary="3"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
-                               Detect64BitPortabilityProblems="false"
+                               Detect64BitPortabilityProblems="true"
                                DebugInformationFormat="4"
                        />
                        <Tool
@@ -65,7 +64,6 @@
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="ws2_32.lib libeay32.lib crypt32.lib dbghelp.lib psapi.lib rpcrt4.lib iphlpapi.lib"
                                LinkIncremental="2"
                                GenerateDebugInformation="true"
                                SubSystem="2"
                        />
                </Configuration>
                <Configuration
-                       Name="Debug|x64"
-                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
-                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+                       Name="Release|Win32"
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+                       IntermediateDirectory="$(ConfigurationName)"
                        ConfigurationType="2"
                        CharacterSet="1"
+                       WholeProgramOptimization="1"
                        >
                        <Tool
                                Name="VCPreBuildEventTool"
                        />
                        <Tool
                                Name="VCMIDLTool"
-                               TargetEnvironment="3"
                        />
                        <Tool
                                Name="VCCLCompilerTool"
-                               Optimization="0"
-                               AdditionalIncludeDirectories="..\..\include;..\libexpat\libexpat"
-                               PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;_DEBUG;_USRDLL;LIBNETXMS_EXPORTS"
-                               MinimalRebuild="true"
-                               ExceptionHandling="0"
-                               BasicRuntimeChecks="3"
-                               RuntimeLibrary="3"
+                               AdditionalIncludeDirectories="..\..\..\include"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBNXAGENT_EXPORTS"
+                               RuntimeLibrary="2"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
                                Detect64BitPortabilityProblems="true"
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="ws2_32.lib libeay32.lib crypt32.lib dbghelp.lib psapi.lib rpcrt4.lib iphlpapi.lib"
-                               LinkIncremental="2"
+                               LinkIncremental="1"
                                GenerateDebugInformation="true"
                                SubSystem="2"
-                               TargetMachine="17"
+                               OptimizeReferences="2"
+                               EnableCOMDATFolding="2"
+                               TargetMachine="1"
                        />
                        <Tool
                                Name="VCALinkTool"
                        />
                </Configuration>
                <Configuration
-                       Name="Release|Win32"
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"
-                       IntermediateDirectory="$(ConfigurationName)"
+                       Name="Debug|x64"
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
                        ConfigurationType="2"
                        CharacterSet="1"
-                       WholeProgramOptimization="1"
                        >
                        <Tool
                                Name="VCPreBuildEventTool"
                        />
                        <Tool
                                Name="VCMIDLTool"
+                               TargetEnvironment="3"
                        />
                        <Tool
                                Name="VCCLCompilerTool"
-                               AdditionalIncludeDirectories="..\..\include;..\libexpat\libexpat"
-                               PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;_USRDLL;LIBNETXMS_EXPORTS;NDEBUG"
-                               ExceptionHandling="0"
-                               RuntimeLibrary="2"
+                               Optimization="0"
+                               AdditionalIncludeDirectories="..\..\..\include"
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBNXAGENT_EXPORTS"
+                               MinimalRebuild="true"
+                               BasicRuntimeChecks="3"
+                               RuntimeLibrary="3"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
-                               Detect64BitPortabilityProblems="false"
+                               Detect64BitPortabilityProblems="true"
                                DebugInformationFormat="3"
                        />
                        <Tool
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="ws2_32.lib libeay32.lib crypt32.lib dbghelp.lib psapi.lib rpcrt4.lib iphlpapi.lib"
-                               LinkIncremental="1"
+                               LinkIncremental="2"
                                GenerateDebugInformation="true"
                                SubSystem="2"
-                               OptimizeReferences="2"
-                               EnableCOMDATFolding="2"
-                               TargetMachine="1"
+                               TargetMachine="17"
                        />
                        <Tool
                                Name="VCALinkTool"
                        />
                        <Tool
                                Name="VCCLCompilerTool"
-                               AdditionalIncludeDirectories="..\..\include;..\libexpat\libexpat"
-                               PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;NDEBUG;_USRDLL;LIBNETXMS_EXPORTS"
-                               ExceptionHandling="0"
+                               AdditionalIncludeDirectories="..\..\..\include"
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBNXAGENT_EXPORTS"
                                RuntimeLibrary="2"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
                        />
                        <Tool
                                Name="VCLinkerTool"
-                               AdditionalDependencies="ws2_32.lib libeay32.lib crypt32.lib dbghelp.lib psapi.lib rpcrt4.lib iphlpapi.lib"
                                LinkIncremental="1"
                                GenerateDebugInformation="true"
                                SubSystem="2"
                        UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
                        >
                        <File
-                               RelativePath=".\agent.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\array.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\base64.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\bytestream.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\config.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\crypto.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\dir.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\dirw.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\dload.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\gen_uuid.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\geolocation.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\getopt.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\hash.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\ice.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\icmp.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\inetaddr.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\log.cpp"
+                               RelativePath=".\bridge.cpp"
                                >
                        </File>
                        <File
                                >
                        </File>
                        <File
-                               RelativePath=".\md5.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\message.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\msgrecv.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\msgwq.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\net.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\nxcp.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\pa.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\qsort.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\queue.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\rwlock.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\scandir.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\seh.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\serial.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\sha1.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\sha2.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\StackWalker.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\string.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\stringlist.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\strmap.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\strmapbase.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\strptime.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\strset.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\strtoll.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\strtoull.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\table.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\threads.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\timegm.c"
-                               >
-                       </File>
-                       <File
                                RelativePath=".\tools.cpp"
                                >
                        </File>
-                       <File
-                               RelativePath=".\tp.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\unicode.cpp"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\uuid.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\wcstoll.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\wcstoull.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\xml.cpp"
-                               >
-                       </File>
                </Filter>
                <Filter
                        Name="Header Files"
                        UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
                        >
                        <File
-                               RelativePath="..\..\include\base64.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\geolocation.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\ice.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\libnetxms.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\md5.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\netxms-regex.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\netxms-version.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\netxms_getopt.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\nms_agent.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\nms_common.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\nms_cscp.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\nms_threads.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\nms_util.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\nxconfig.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\nxcpapi.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\nxlog.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\nxqueue.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\nxstat.h"
-                               >
-                       </File>
-                       <File
-                               RelativePath="..\..\include\rwlock.h"
+                               RelativePath=".\libnxagent.h"
                                >
                        </File>
                        <File
-                               RelativePath=".\sha1.h"
+                               RelativePath="..\..\..\include\nms_agent.h"
                                >
                        </File>
                        <File
-                               RelativePath=".\sha2.h"
+                               RelativePath="..\..\..\include\nms_common.h"
                                >
                        </File>
                        <File
-                               RelativePath=".\StackWalker.h"
+                               RelativePath="..\..\..\include\nms_cscp.h"
                                >
                        </File>
                        <File
-                               RelativePath=".\strmap-internal.h"
+                               RelativePath="..\..\..\include\nms_threads.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\..\include\unicode.h"
+                               RelativePath="..\..\..\include\nms_util.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\..\include\uthash.h"
+                               RelativePath="..\..\..\include\nxconfig.h"
                                >
                        </File>
                        <File
-                               RelativePath="..\..\include\uuid.h"
+                               RelativePath="..\..\..\include\nxcpapi.h"
                                >
                        </File>
                        <File
-                               RelativePath=".\uuidP.h"
+                               RelativePath="..\..\..\include\unicode.h"
                                >
                        </File>
                </Filter>
diff --git a/src/agent/libnxagent/main.cpp b/src/agent/libnxagent/main.cpp
new file mode 100644 (file)
index 0000000..c4d50ff
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+** NetXMS - Network Management System
+** Copyright (C) 2003-2015 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published
+** by the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: main.cpp
+**
+**/
+
+#include "libnxagent.h"
+
+#ifdef _WIN32
+
+/**
+ * DLL entry point
+ */
+BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
+{
+   if (dwReason == DLL_PROCESS_ATTACH)
+      DisableThreadLibraryCalls(hInstance);
+   return TRUE;
+}
+
+#endif   /* _WIN32 */
diff --git a/src/agent/libnxagent/tools.cpp b/src/agent/libnxagent/tools.cpp
new file mode 100644 (file)
index 0000000..2566a4e
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+** NetXMS - Network Management System
+** Copyright (C) 2003-2015 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published
+** by the Free Software Foundation; either version 3 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: tools.cpp
+**
+**/
+
+#include "libnxagent.h"
+
+/**
+ * Get arguments for parameters like name(arg1,...)
+ * Returns FALSE on processing error
+ */
+static bool AgentGetParameterArgInternal(const TCHAR *param, int index, TCHAR *arg, int maxSize)
+{
+   const TCHAR *ptr1, *ptr2;
+   int state, currIndex, pos;
+   bool success = true;
+
+   arg[0] = 0;    // Default is empty string
+   ptr1 = _tcschr(param, _T('('));
+   if (ptr1 == NULL)
+      return true;  // No arguments at all
+   for(ptr2 = ptr1 + 1, currIndex = 1, state = 0, pos = 0; state != -1; ptr2++)
+   {
+      switch(state)
+      {
+         case 0:  // Normal
+            switch(*ptr2)
+            {
+               case _T(')'):
+                  if (currIndex == index)
+                     arg[pos] = 0;
+                  state = -1;    // Finish processing
+                  break;
+               case _T('"'):
+                  state = 1;     // String
+                  break;
+               case _T('\''):        // String, type 2
+                  state = 2;
+                  break;
+               case _T(','):
+                  if (currIndex == index)
+                  {
+                     arg[pos] = 0;
+                     state = -1;
+                  }
+                  else
+                  {
+                     currIndex++;
+                  }
+                  break;
+               case 0:
+                  state = -1;       // Finish processing
+                  success = false;  // Set error flag
+                  break;
+               default:
+                  if ((currIndex == index) && (pos < maxSize - 1))
+                     arg[pos++] = *ptr2;
+            }
+            break;
+         case 1:  // String in ""
+            switch(*ptr2)
+            {
+               case _T('"'):
+                  state = 0;     // Normal
+                  break;
+               case 0:
+                  state = -1;       // Finish processing
+                  success = false;  // Set error flag
+                  break;
+               default:
+                  if ((currIndex == index) && (pos < maxSize - 1))
+                     arg[pos++] = *ptr2;
+            }
+            break;
+         case 2:  // String in ''
+            switch(*ptr2)
+            {
+               case _T('\''):
+                  state = 0;     // Normal
+                  break;
+               case 0:
+                  state = -1;       // Finish processing
+                  success = false;  // Set error flag
+                  break;
+               default:
+                  if ((currIndex == index) && (pos < maxSize - 1))
+                     arg[pos++] = *ptr2;
+            }
+            break;
+      }
+   }
+
+   if (success)
+      StrStrip(arg);
+   return success;
+}
+
+/**
+ * Get arguments for parameters like name(arg1,...) as multibyte string
+ * Returns FALSE on processing error
+ */
+bool LIBNXAGENT_EXPORTABLE AgentGetParameterArgA(const TCHAR *param, int index, char *arg, int maxSize)
+{
+#ifdef UNICODE
+       WCHAR *temp = (WCHAR *)malloc(maxSize * sizeof(WCHAR));
+       bool success = AgentGetParameterArgInternal(param, index, temp, maxSize);
+       if (success)
+       {
+               WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, temp, -1, arg, maxSize, NULL, NULL);
+               arg[maxSize - 1] = 0;
+       }
+       free(temp);
+       return success;
+#else
+       return AgentGetParameterArgInternal(param, index, arg, maxSize);
+#endif
+}
+
+/**
+ * Get arguments for parameters like name(arg1,...) as UNICODE string
+ * Returns FALSE on processing error
+ */
+bool LIBNXAGENT_EXPORTABLE AgentGetParameterArgW(const TCHAR *param, int index, WCHAR *arg, int maxSize)
+{
+#ifdef UNICODE
+       return AgentGetParameterArgInternal(param, index, arg, maxSize);
+#else
+       char *temp = (char *)malloc(maxSize);
+       bool success = AgentGetParameterArgInternal(param, index, temp, maxSize);
+       if (success)
+       {
+               MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, temp, -1, arg, maxSize);
+               arg[maxSize - 1] = 0;
+       }
+       free(temp);
+       return success;
+#endif
+}
index 099c49f..2adb30a 100644 (file)
@@ -59,10 +59,6 @@ void TakeScreenshot(NXCPMessage *response)
             rcc = ERR_SUCCESS;
             response->setFieldFromFile(VID_FILE_DATA, tempFile);
          }
-         else
-         {
-            AgentWriteDebugLog(4, _T("Cannot save bitmap as PNG"));
-         }
          DeleteObject(bitmap);
          DeleteFile(tempFile);
       }
index c486d1c..9b8c92a 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = aix.la
 aix_la_SOURCES = cpu.cpp disk.cpp iostat.cpp main.cpp net.cpp proc.cpp system.cpp
 aix_la_CPPFLAGS=-I@top_srcdir@/include
 aix_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-aix_la_LIBADD = -lperfstat ../../../libnetxms/libnetxms.la
+aix_la_LIBADD = -lperfstat ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la
 
 EXTRA_DIST = aix_subagent.h
 
index 7046472..215c8ed 100644 (file)
@@ -20,7 +20,7 @@ pkglib_LTLIBRARIES=darwin.la
 darwin_la_SOURCES=darwin.cpp net.cpp system.cpp disk.cpp cpu.cpp
 darwin_la_CPPFLAGS=-I@top_srcdir@/include
 darwin_la_LDFLAGS=-module -avoid-version -export-symbols ../subagent.sym
-darwin_la_LIBADD=../../../libnetxms/libnetxms.la
+darwin_la_LIBADD=../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la
 
 EXTRA_DIST=cpu.h darwin.h disk.h net.h system.h
 
index 4e38c04..9badf1c 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = db2.la
 db2_la_SOURCES     = db2_subagent.cpp db2dci.cpp
 db2_la_CPPFLAGS    = -I@top_srcdir@/include
 db2_la_LDFLAGS     = -module -avoid-version -export-symbols ../subagent.sym
-db2_la_LIBADD      = ../../../libnetxms/libnetxms.la ../../../db/libnxdb/libnxdb.la
+db2_la_LIBADD      = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la ../../../db/libnxdb/libnxdb.la
 
 EXTRA_DIST         = db2_subagent.h db2dci.h db2.vcproj
 
index ad46c8b..ce3a5ef 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = dbquery.la
 dbquery_la_SOURCES = conn.cpp dbquery.cpp direct.cpp poll.cpp
 dbquery_la_CPPFLAGS = -I@top_srcdir@/include
 dbquery_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-dbquery_la_LIBADD = ../../../libnetxms/libnetxms.la ../../../db/libnxdb/libnxdb.la
+dbquery_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la ../../../db/libnxdb/libnxdb.la
 
 EXTRA_DIST = dbquery.vcproj dbquery.h
 
index 77896f9..3d86933 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = devemu.la
 devemu_la_SOURCES = devemu.cpp
 devemu_la_CPPFLAGS=-I@top_srcdir@/include
 devemu_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-devemu_la_LIBADD = ../../../libnetxms/libnetxms.la
+devemu_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la
 
 EXTRA_DIST = devemu.vcproj
 
index 9ceff8e..d08ce9c 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = ds18x20.la
 ds18x20_la_SOURCES = ds18x20.cpp
 ds18x20_la_CPPFLAGS=-I@top_srcdir@/include
 ds18x20_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-ds18x20_la_LIBADD = ../../../libnetxms/libnetxms.la
+ds18x20_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la
 
 EXTRA_DIST = ds18x20.h
 
index 650bf57..a19c254 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = ecs.la
 ecs_la_SOURCES = ecs.cpp
 ecs_la_CPPFLAGS=-I@top_srcdir@/include
 ecs_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-ecs_la_LIBADD = ../../../libnetxms/libnetxms.la
+ecs_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la
 
 EXTRA_DIST = ecs.vcproj
 
index 1aba111..1627f22 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = filemgr.la
 filemgr_la_SOURCES = filemgr.cpp logmonitoring.cpp
 filemgr_la_CPPFLAGS=-I@top_srcdir@/include
 filemgr_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-filemgr_la_LIBADD = ../../../libnetxms/libnetxms.la
+filemgr_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la
 
 EXTRA_DIST = filemgr.vcproj filemgr.h
 
index d3e0763..f8872df 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = freebsd.la
 freebsd_la_SOURCES = disk.cpp freebsd.cpp net.cpp proc.cpp system.cpp 
 freebsd_la_CPPFLAGS=-I@top_srcdir@/include
 freebsd_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-freebsd_la_LIBADD = ../../../libnetxms/libnetxms.la -lkvm
+freebsd_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la -lkvm
 
 EXTRA_DIST = disk.h net.h system.h
 
index 99f65df..878f21c 100644 (file)
@@ -19,7 +19,7 @@ SUBAGENT = hpux
 pkglib_LTLIBRARIES = hpux.la
 hpux_la_SOURCES = disk.cpp iostat.cpp main.cpp net.cpp proc.cpp system.cpp
 hpux_la_CPPFLAGS = -I@top_srcdir@/include -D_PSTAT64
-hpux_la_LIBADD = ../../../libnetxms/libnetxms.la -lnm
+hpux_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la -lnm
 hpux_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
 
 EXTRA_DIST = disk.h hpux.h net.h system.h
index 2ce33bb..5e4486f 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = informix.la
 informix_la_SOURCES = main.cpp
 informix_la_CPPFLAGS=-I@top_srcdir@/include
 informix_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-informix_la_LIBADD = ../../../libnetxms/libnetxms.la ../../../db/libnxdb/libnxdb.la
+informix_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la ../../../db/libnxdb/libnxdb.la
 
 EXTRA_DIST = informix.vcproj informix_subagent.h
 
index 96d0ec2..5bf497e 100644 (file)
@@ -2,5 +2,6 @@ lib_LTLIBRARIES = libnsm_ipso.la
 libnsm_ipso_la_SOURCES = disk.cpp ipso.cpp net.cpp system.cpp
 libnsm_ipso_CPPFLAGS=-I@top_srcdir@/include
 libnsm_ipso_la_LDFLAGS = -lkvm
+libnsm_ipso_la_LIBADD = ../../libnxagent/libnxagent.la 
 
 EXTRA_DIST = ipso.h
index acbad18..7d90b24 100644 (file)
@@ -6,7 +6,7 @@ java_la_SOURCES = Action.cpp ConfigHelper.cpp ListParameter.cpp main.cpp \
                   SubAgent.cpp TableColumn.cpp TableParameter.cpp
 java_la_CPPFLAGS=-I@top_srcdir@/include
 java_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-java_la_LIBADD = ../../../libnetxms/libnetxms.la
+java_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la
 
 EXTRA_DIST = \
        java.vcproj \
index 9f5c5f9..ae22bdf 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = linux.la
 linux_la_SOURCES = cpu.cpp disk.cpp drbd.cpp hddinfo.cpp iostat.cpp linux.cpp net.cpp packages.cpp proc.cpp system.cpp
 linux_la_CPPFLAGS=-I@top_srcdir@/include
 linux_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-linux_la_LIBADD = ../../../libnetxms/libnetxms.la
+linux_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la
 
 EXTRA_DIST = linux_subagent.h
 
index df7673e..7e6953a 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = lmsensors.la
 lmsensors_la_SOURCES = main.cpp
 lmsensors_la_CPPFLAGS=-I@top_srcdir@/include
 lmsensors_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-lmsensors_la_LIBADD = ../../../libnetxms/libnetxms.la -lsensors
+lmsensors_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la -lsensors
 
 if !STATIC_BUILD
 install-exec-hook:
index a9e6ccf..9d00e45 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = logwatch.la
 logwatch_la_SOURCES = logwatch.cpp
 logwatch_la_CPPFLAGS=-I@top_srcdir@/include
 logwatch_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-logwatch_la_LIBADD = @top_srcdir@/src/libnetxms/libnetxms.la @top_srcdir@/src/libnxlp/libnxlp.la
+logwatch_la_LIBADD = ../../libnxagent/libnxagent.la @top_srcdir@/src/libnetxms/libnetxms.la @top_srcdir@/src/libnxlp/libnxlp.la
 
 EXTRA_DIST = logwatch.h logwatch.vcproj
 
index e5cfc89..0efe31e 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = mongodb.la
 mongodb_la_SOURCES = db.cpp main.cpp
 mongodb_la_CPPFLAGS=-I@top_srcdir@/include @MONGODB_CPPFLAGS@
 mongodb_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym @MONGODB_LDFLAGS@
-mongodb_la_LIBADD = ../../../libnetxms/libnetxms.la @MONGODB_LIBS@
+mongodb_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la @MONGODB_LIBS@
 
 EXTRA_DIST = mongodb_subagent.h
 
index 257c957..a55d458 100644 (file)
@@ -16,7 +16,7 @@ pkglib_LTLIBRARIES = netbsd.la
 netbsd_la_SOURCES = netbsd.cpp system.cpp disk.cpp net.cpp proc.cpp proc2.cpp
 netbsd_la_CPPFLAGS=-I@top_srcdir@/include
 netbsd_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-netbsd_la_LIBADD = ../../../libnetxms/libnetxms.la -lkvm
+netbsd_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la -lkvm
 
 EXTRA_DIST = disk.h net.h system.h
 
index e3057bb..0e3269c 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = netsvc.la
 netsvc_la_SOURCES = main.cpp
 netsvc_la_CPPFLAGS=-I@top_srcdir@/include
 netsvc_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-netsvc_la_LIBADD = ../../../libnetxms/libnetxms.la -lcurl
+netsvc_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la -lcurl
 
 EXTRA_DIST = netsvc.h netsvc.vcproj
 
index ccdb6f6..9c5b853 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = odbcquery.la
 odbcquery_la_SOURCES = odbcquery.cpp odbcsapi.cpp
 odbcquery_la_CPPFLAGS=-I@top_srcdir@/include
 odbcquery_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-odbcquery_la_LIBADD = ../../../libnetxms/libnetxms.la @ODBC_LIBS@
+odbcquery_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la @ODBC_LIBS@
 
 EXTRA_DIST = odbcquery.vcproj odbcquery.h
 
index 8afeec5..311ade5 100644 (file)
@@ -16,7 +16,7 @@ pkglib_LTLIBRARIES = openbsd.la
 openbsd_la_SOURCES = openbsd.cpp system.cpp disk.cpp net.cpp
 openbsd_la_CPPFLAGS=-I@top_srcdir@/include
 openbsd_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-openbsd_la_LIBADD = ../../../libnetxms/libnetxms.la -lkvm
+openbsd_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la -lkvm
 
 EXTRA_DIST = disk.h net.h system.h
 
index 7011348..b49257e 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = oracle.la
 oracle_la_SOURCES = db.cpp main.cpp
 oracle_la_CPPFLAGS=-I@top_srcdir@/include
 oracle_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-oracle_la_LIBADD = ../../../libnetxms/libnetxms.la ../../../db/libnxdb/libnxdb.la
+oracle_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la ../../../db/libnxdb/libnxdb.la
 if USE_INTERNAL_LIBTRE
 oracle_la_LIBADD += ../../../libtre/libnxtre.la
 endif
index 8a18e1b..c63a4f7 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = ping.la
 ping_la_SOURCES = ping.cpp
 ping_la_CPPFLAGS=-I@top_srcdir@/include
 ping_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-ping_la_LIBADD = ../../../libnetxms/libnetxms.la
+ping_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la
 
 EXTRA_DIST = ping.h ping.vcproj
 
index f849619..c619a0f 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = portcheck.la
 portcheck_la_SOURCES = custom.cpp http.cpp main.cpp net.cpp pop3.cpp smtp.cpp ssh.cpp telnet.cpp
 portcheck_la_CPPFLAGS=-I@top_srcdir@/include
 portcheck_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-portcheck_la_LIBADD = ../../../libnetxms/libnetxms.la
+portcheck_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la
 if USE_INTERNAL_LIBTRE
 portcheck_la_LIBADD += @top_srcdir@/src/libtre/libnxtre.la
 endif
index 18bfd59..1c6f4bc 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = rpi.la
 rpi_la_SOURCES = htsensor.cpp rpi.cpp
 rpi_la_CPPFLAGS=-I@top_srcdir@/include
 rpi_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-rpi_la_LIBADD = ../../../libnetxms/libnetxms.la -lbcm2835
+rpi_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la -lbcm2835
 
 if !STATIC_BUILD
 install-exec-hook:
index 5ba1827..9dfda49 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = sms.la
 sms_la_SOURCES = main.cpp pdumode.cpp sender.cpp
 sms_la_CPPFLAGS=-I@top_srcdir@/include
 sms_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-sms_la_LIBADD = ../../../libnetxms/libnetxms.la
+sms_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la
 
 EXTRA_DIST = sms.h sms.vcproj
 
index 66459aa..df0c0e8 100644 (file)
@@ -20,7 +20,7 @@ pkglib_LTLIBRARIES = sunos.la
 sunos_la_SOURCES = cpu.cpp disk.cpp iostat.cpp mac_dlpi.cpp main.cpp net.cpp process.cpp system.cpp
 sunos_la_CPPFLAGS=-I@top_srcdir@/include
 sunos_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-sunos_la_LIBADD = ../../../libnetxms/libnetxms.la
+sunos_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la
 
 EXTRA_DIST = sunos_subagent.h
 
index f920d3c..e2fedc4 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = tuxedo.la
 tuxedo_la_SOURCES = clients.cpp domain.cpp machines.cpp main.cpp queues.cpp servers.cpp services.cpp
 tuxedo_la_CPPFLAGS=-I@top_srcdir@/include @TUXEDO_CPPFLAGS@
 tuxedo_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym @TUXEDO_LDFLAGS@
-tuxedo_la_LIBADD = ../../../libnetxms/libnetxms.la -ltux -lfml32 @TUXEDO_LIBS@
+tuxedo_la_LIBADD = ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la -ltux -lfml32 @TUXEDO_LIBS@
 
 EXTRA_DIST = tuxedo.vcproj tuxedo_subagent.h
 
index 8804b07..0784d5a 100644 (file)
@@ -4,7 +4,7 @@ pkglib_LTLIBRARIES = ups.la
 ups_la_SOURCES = apc.cpp bcmxcp.cpp main.cpp megatec.cpp metasys.cpp microdowell.cpp serial.cpp ups.cpp 
 ups_la_CPPFLAGS=-I@top_srcdir@/include
 ups_la_LDFLAGS = -module -avoid-version -export-symbols ../subagent.sym
-ups_la_LIBADD= ../../../libnetxms/libnetxms.la
+ups_la_LIBADD= ../../libnxagent/libnxagent.la ../../../libnetxms/libnetxms.la
 
 EXTRA_DIST = ups.h ups.vcproj usb.cpp
 
diff --git a/src/libnetxms/agent.cpp b/src/libnetxms/agent.cpp
deleted file mode 100644 (file)
index 20844d6..0000000
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
-** NetXMS - Network Management System
-** NetXMS Foundation Library
-** Copyright (C) 2003-2013 Victor Kirhenshtein
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU Lesser General Public License as published
-** by the Free Software Foundation; either version 3 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU Lesser General Public License
-** along with this program; if not, write to the Free Software
-** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-**
-** File: agent.cpp
-**
-**/
-
-#include "libnetxms.h"
-#include <nms_agent.h>
-
-/**
- * Static data
- */
-static void (* s_fpWriteLog)(int, int, const TCHAR *) = NULL;
-static void (* s_fpSendTrap1)(UINT32, const TCHAR *, const char *, va_list) = NULL;
-static void (* s_fpSendTrap2)(UINT32, const TCHAR *, int, TCHAR **) = NULL;
-static bool (* s_fpEnumerateSessions)(bool (*)(AbstractCommSession *, void *), void *) = NULL;
-static bool (* s_fpSendFile)(void *, UINT32, const TCHAR *, long) = NULL;
-static bool (* s_fpPushData)(const TCHAR *, const TCHAR *, UINT32) = NULL;
-static CONDITION s_agentShutdownCondition = INVALID_CONDITION_HANDLE;
-
-/**
- * Initialize subagent API
- */
-void LIBNETXMS_EXPORTABLE InitSubAgentAPI(void (* writeLog)(int, int, const TCHAR *),
-                                                                                                               void (* sendTrap1)(UINT32, const TCHAR *, const char *, va_list),
-                                                                                                               void (* sendTrap2)(UINT32, const TCHAR *, int, TCHAR **),
-                                                                                                               bool (* enumerateSessions)(bool (*)(AbstractCommSession *, void *), void*),
-                                                                                                               bool (* sendFile)(void *, UINT32, const TCHAR *, long),
-                                                                                                               bool (* pushData)(const TCHAR *, const TCHAR *, UINT32),
-                                          CONDITION shutdownCondition)
-{
-   s_fpWriteLog = writeLog;
-       s_fpSendTrap1 = sendTrap1;
-       s_fpSendTrap2 = sendTrap2;
-       s_fpEnumerateSessions = enumerateSessions;
-       s_fpSendFile = sendFile;
-       s_fpPushData = pushData;
-   s_agentShutdownCondition = shutdownCondition;
-}
-
-/**
- * Write message to agent's log
- */
-void LIBNETXMS_EXPORTABLE AgentWriteLog(int logLevel, const TCHAR *format, ...)
-{
-   TCHAR szBuffer[4096];
-   va_list args;
-
-   if (s_fpWriteLog != NULL)
-   {
-      va_start(args, format);
-      _vsntprintf(szBuffer, 4096, format, args);
-      va_end(args);
-      s_fpWriteLog(logLevel, 0, szBuffer);
-   }
-}
-
-void LIBNETXMS_EXPORTABLE AgentWriteLog2(int logLevel, const TCHAR *format, va_list args)
-{
-   TCHAR szBuffer[4096];
-
-   if (s_fpWriteLog != NULL)
-   {
-      _vsntprintf(szBuffer, 4096, format, args);
-      s_fpWriteLog(logLevel, 0, szBuffer);
-   }
-}
-
-void LIBNETXMS_EXPORTABLE AgentWriteDebugLog(int level, const TCHAR *format, ...)
-{
-   TCHAR szBuffer[4096];
-   va_list args;
-
-   if (s_fpWriteLog != NULL)
-   {
-      va_start(args, format);
-      _vsntprintf(szBuffer, 4096, format, args);
-      va_end(args);
-      s_fpWriteLog(EVENTLOG_DEBUG_TYPE, level, szBuffer);
-   }
-}
-
-void LIBNETXMS_EXPORTABLE AgentWriteDebugLog2(int level, const TCHAR *format, va_list args)
-{
-   TCHAR szBuffer[4096];
-
-   if (s_fpWriteLog != NULL)
-   {
-      _vsntprintf(szBuffer, 4096, format, args);
-      s_fpWriteLog(EVENTLOG_DEBUG_TYPE, level, szBuffer);
-   }
-}
-
-/**
- * Send trap from agent to server
- */
-void LIBNETXMS_EXPORTABLE AgentSendTrap(UINT32 dwEvent, const TCHAR *eventName, const char *pszFormat, ...)
-{
-   va_list args;
-
-   if (s_fpSendTrap1 != NULL)
-   {
-      va_start(args, pszFormat);
-      s_fpSendTrap1(dwEvent, eventName, pszFormat, args);
-      va_end(args);
-   }
-}
-
-/**
- * Send trap from agent to server
- */
-void LIBNETXMS_EXPORTABLE AgentSendTrap2(UINT32 dwEvent, const TCHAR *eventName, int nCount, TCHAR **ppszArgList)
-{
-   if (s_fpSendTrap2 != NULL)
-      s_fpSendTrap2(dwEvent, eventName, nCount, ppszArgList);
-}
-
-/**
- * Goes throught all sessions and executes
- */
-bool LIBNETXMS_EXPORTABLE EnumerateSessions(bool (* callback)(AbstractCommSession *, void *), void *data)
-{
-   if (s_fpEnumerateSessions != NULL)
-   {
-      return s_fpEnumerateSessions(callback, data);
-   }
-   else
-      return false;
-}
-
-/**
- * Get arguments for parameters like name(arg1,...)
- * Returns FALSE on processing error
- */
-static BOOL AgentGetParameterArgInternal(const TCHAR *param, int index, TCHAR *arg, int maxSize)
-{
-   const TCHAR *ptr1, *ptr2;
-   int state, currIndex, pos;
-   BOOL bResult = TRUE;
-
-   arg[0] = 0;    // Default is empty string
-   ptr1 = _tcschr(param, _T('('));
-   if (ptr1 == NULL)
-      return TRUE;  // No arguments at all
-   for(ptr2 = ptr1 + 1, currIndex = 1, state = 0, pos = 0; state != -1; ptr2++)
-   {
-      switch(state)
-      {
-         case 0:  // Normal
-            switch(*ptr2)
-            {
-               case _T(')'):
-                  if (currIndex == index)
-                     arg[pos] = 0;
-                  state = -1;    // Finish processing
-                  break;
-               case _T('"'):
-                  state = 1;     // String
-                  break;
-               case _T('\''):        // String, type 2
-                  state = 2;
-                  break;
-               case _T(','):
-                  if (currIndex == index)
-                  {
-                     arg[pos] = 0;
-                     state = -1;
-                  }
-                  else
-                  {
-                     currIndex++;
-                  }
-                  break;
-               case 0:
-                  state = -1;       // Finish processing
-                  bResult = FALSE;  // Set error flag
-                  break;
-               default:
-                  if ((currIndex == index) && (pos < maxSize - 1))
-                     arg[pos++] = *ptr2;
-            }
-            break;
-         case 1:  // String in ""
-            switch(*ptr2)
-            {
-               case _T('"'):
-                  state = 0;     // Normal
-                  break;
-               case 0:
-                  state = -1;    // Finish processing
-                  bResult = FALSE;  // Set error flag
-                  break;
-               default:
-                  if ((currIndex == index) && (pos < maxSize - 1))
-                     arg[pos++] = *ptr2;
-            }
-            break;
-         case 2:  // String in ''
-            switch(*ptr2)
-            {
-               case _T('\''):
-                  state = 0;     // Normal
-                  break;
-               case 0:
-                  state = -1;    // Finish processing
-                  bResult = FALSE;  // Set error flag
-                  break;
-               default:
-                  if ((currIndex == index) && (pos < maxSize - 1))
-                     arg[pos++] = *ptr2;
-            }
-            break;
-      }
-   }
-
-   if (bResult)
-      StrStrip(arg);
-   return bResult;
-}
-
-BOOL LIBNETXMS_EXPORTABLE AgentGetParameterArgA(const TCHAR *param, int index, char *arg, int maxSize)
-{
-#ifdef UNICODE
-       WCHAR *temp = (WCHAR *)malloc(maxSize * sizeof(WCHAR));
-       BOOL success = AgentGetParameterArgInternal(param, index, temp, maxSize);
-       if (success)
-       {
-               WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, temp, -1, arg, maxSize, NULL, NULL);
-               arg[maxSize - 1] = 0;
-       }
-       free(temp);
-       return success;
-#else
-       return AgentGetParameterArgInternal(param, index, arg, maxSize);
-#endif
-}
-
-BOOL LIBNETXMS_EXPORTABLE AgentGetParameterArgW(const TCHAR *param, int index, WCHAR *arg, int maxSize)
-{
-#ifdef UNICODE
-       return AgentGetParameterArgInternal(param, index, arg, maxSize);
-#else
-       char *temp = (char *)malloc(maxSize);
-       BOOL success = AgentGetParameterArgInternal(param, index, temp, maxSize);
-       if (success)
-       {
-               MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, temp, -1, arg, maxSize);
-               arg[maxSize - 1] = 0;
-       }
-       free(temp);
-       return success;
-#endif
-}
-
-/**
- * Send file to server
- */
-BOOL LIBNETXMS_EXPORTABLE AgentSendFileToServer(void *session, UINT32 requestId, const TCHAR *file, long offset)
-{
-       if ((s_fpSendFile == NULL) || (session == NULL) || (file == NULL))
-               return FALSE;
-       return s_fpSendFile(session, requestId, file, offset);
-}
-
-/**
- * Push parameter's value
- */
-BOOL LIBNETXMS_EXPORTABLE AgentPushParameterData(const TCHAR *parameter, const TCHAR *value)
-{
-       if (s_fpPushData == NULL)
-               return FALSE;
-       return s_fpPushData(parameter, value, 0);
-}
-
-BOOL LIBNETXMS_EXPORTABLE AgentPushParameterDataInt32(const TCHAR *parameter, LONG value)
-{
-       TCHAR buffer[64];
-
-       _sntprintf(buffer, sizeof(buffer), _T("%d"), (int)value);
-       return AgentPushParameterData(parameter, buffer);
-}
-
-BOOL LIBNETXMS_EXPORTABLE AgentPushParameterDataUInt32(const TCHAR *parameter, UINT32 value)
-{
-       TCHAR buffer[64];
-
-       _sntprintf(buffer, sizeof(buffer), _T("%u"), (unsigned int)value);
-       return AgentPushParameterData(parameter, buffer);
-}
-
-BOOL LIBNETXMS_EXPORTABLE AgentPushParameterDataInt64(const TCHAR *parameter, INT64 value)
-{
-       TCHAR buffer[64];
-
-       _sntprintf(buffer, sizeof(buffer), INT64_FMT, value);
-       return AgentPushParameterData(parameter, buffer);
-}
-
-BOOL LIBNETXMS_EXPORTABLE AgentPushParameterDataUInt64(const TCHAR *parameter, QWORD value)
-{
-       TCHAR buffer[64];
-
-       _sntprintf(buffer, sizeof(buffer), UINT64_FMT, value);
-       return AgentPushParameterData(parameter, buffer);
-}
-
-BOOL LIBNETXMS_EXPORTABLE AgentPushParameterDataDouble(const TCHAR *parameter, double value)
-{
-       TCHAR buffer[64];
-
-       _sntprintf(buffer, sizeof(buffer), _T("%f"), value);
-       return AgentPushParameterData(parameter, buffer);
-}
-
-/**
- * Get shutdown condition
- */
-CONDITION LIBNETXMS_EXPORTABLE AgentGetShutdownCondition()
-{
-   return s_agentShutdownCondition;
-}
-
-/**
- * Sleep and check for agent shutdown
- */
-bool LIBNETXMS_EXPORTABLE AgentSleepAndCheckForShutdown(UINT32 sleepTime)
-{
-   return ConditionWait(s_agentShutdownCondition, sleepTime);
-}
index 3e88e70..6481887 100644 (file)
                        UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
                        >
                        <File
-                               RelativePath=".\agent.cpp"
-                               >
-                       </File>
-                       <File
                                RelativePath=".\array.cpp"
                                >
                        </File>
index c5d5ac0..7bfbcef 100644 (file)
@@ -123,14 +123,11 @@ void LIBNETXMS_EXPORTABLE __wcsupr(WCHAR *in)
 
 #endif
 
-
-//
-// DLL entry point
-//
-
 #ifdef _WIN32
 
-#ifndef UNDER_CE // FIXME
+/**
+ * DLL entry point
+ */
 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
 {
    if (dwReason == DLL_PROCESS_ATTACH)
@@ -140,25 +137,5 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
        }
    return TRUE;
 }
-#endif // UNDER_CE
 
 #endif   /* _WIN32 */
-
-
-//
-// NetWare library entry point
-//
-
-#ifdef _NETWARE
-
-int _init(void)
-{
-   return 0;
-}
-
-int _fini(void)
-{
-   return 0;
-}
-
-#endif