- SMS DB emulator, initial submission, not tested, it doesnt link
authorAlex Kalimulin <alex@netxms.org>
Mon, 26 Sep 2011 22:52:50 +0000 (22:52 +0000)
committerAlex Kalimulin <alex@netxms.org>
Mon, 26 Sep 2011 22:52:50 +0000 (22:52 +0000)
.gitattributes
netxms.sln
src/server/smsdrv/dbemu/dbemu.h [new file with mode: 0644]
src/server/smsdrv/dbemu/dbemu.vcproj [new file with mode: 0644]
src/server/smsdrv/dbemu/main.cpp [new file with mode: 0644]

index 89390f1..65aace2 100644 (file)
@@ -1595,6 +1595,7 @@ src/server/libnxsrv/ndd.cpp -text
 src/server/libnxsrv/snmp.cpp -text
 src/server/libnxsrv/vlan.cpp -text
 src/server/netxmsd/netxmsd.vcproj -text
+src/server/smsdrv/dbemu/dbemu.vcproj -text
 src/server/smsdrv/generic/generic.vcproj -text
 src/server/smsdrv/generic/pdumode.cpp -text
 src/server/smsdrv/nxagent/nxagent.vcproj -text
index fcc9fc6..b1d77a1 100644 (file)
@@ -502,6 +502,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "informix", "src\agent\subag
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dbemu", "src\server\smsdrv\dbemu\dbemu.vcproj", "{912783D2-CF6F-4040-B564-4E2436EB0827}"
+       ProjectSection(ProjectDependencies) = postProject
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
+               {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
+       EndProjectSection
+EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Pocket PC 2003 (ARMV4) = Debug|Pocket PC 2003 (ARMV4)
@@ -826,16 +834,14 @@ Global
                {CB89D905-C8BE-4027-B2D8-F96C245E9160}.Release|Win32.Build.0 = Release|Win32
                {CB89D905-C8BE-4027-B2D8-F96C245E9160}.Release|x64.ActiveCfg = Release|x64
                {CB89D905-C8BE-4027-B2D8-F96C245E9160}.Release|x64.Build.0 = Release|x64
-               {3B172035-5EEC-45A3-8471-2C390B7ED683}.Debug|Pocket PC 2003 (ARMV4).ActiveCfg = Debug|x64
+               {3B172035-5EEC-45A3-8471-2C390B7ED683}.Debug|Pocket PC 2003 (ARMV4).ActiveCfg = Debug|Win32
                {3B172035-5EEC-45A3-8471-2C390B7ED683}.Debug|Win32.ActiveCfg = Debug|Win32
                {3B172035-5EEC-45A3-8471-2C390B7ED683}.Debug|Win32.Build.0 = Debug|Win32
-               {3B172035-5EEC-45A3-8471-2C390B7ED683}.Debug|x64.ActiveCfg = Debug|x64
-               {3B172035-5EEC-45A3-8471-2C390B7ED683}.Debug|x64.Build.0 = Debug|x64
-               {3B172035-5EEC-45A3-8471-2C390B7ED683}.Release|Pocket PC 2003 (ARMV4).ActiveCfg = Release|x64
+               {3B172035-5EEC-45A3-8471-2C390B7ED683}.Debug|x64.ActiveCfg = Debug|Win32
+               {3B172035-5EEC-45A3-8471-2C390B7ED683}.Release|Pocket PC 2003 (ARMV4).ActiveCfg = Release|Win32
                {3B172035-5EEC-45A3-8471-2C390B7ED683}.Release|Win32.ActiveCfg = Release|Win32
                {3B172035-5EEC-45A3-8471-2C390B7ED683}.Release|Win32.Build.0 = Release|Win32
-               {3B172035-5EEC-45A3-8471-2C390B7ED683}.Release|x64.ActiveCfg = Release|x64
-               {3B172035-5EEC-45A3-8471-2C390B7ED683}.Release|x64.Build.0 = Release|x64
+               {3B172035-5EEC-45A3-8471-2C390B7ED683}.Release|x64.ActiveCfg = Release|Win32
                {B2988503-1921-4B9F-BBC1-5E5CF62F335E}.Debug|Pocket PC 2003 (ARMV4).ActiveCfg = Debug|x64
                {B2988503-1921-4B9F-BBC1-5E5CF62F335E}.Debug|Win32.ActiveCfg = Debug|Win32
                {B2988503-1921-4B9F-BBC1-5E5CF62F335E}.Debug|Win32.Build.0 = Debug|Win32
@@ -1334,6 +1340,14 @@ Global
                {12F5AF3E-A688-4852-A0ED-921D0E088AC4}.Release|Win32.Build.0 = Release|Win32
                {12F5AF3E-A688-4852-A0ED-921D0E088AC4}.Release|x64.ActiveCfg = Release|x64
                {12F5AF3E-A688-4852-A0ED-921D0E088AC4}.Release|x64.Build.0 = Release|x64
+               {912783D2-CF6F-4040-B564-4E2436EB0827}.Debug|Pocket PC 2003 (ARMV4).ActiveCfg = Debug|Win32
+               {912783D2-CF6F-4040-B564-4E2436EB0827}.Debug|Win32.ActiveCfg = Debug|Win32
+               {912783D2-CF6F-4040-B564-4E2436EB0827}.Debug|Win32.Build.0 = Debug|Win32
+               {912783D2-CF6F-4040-B564-4E2436EB0827}.Debug|x64.ActiveCfg = Debug|Win32
+               {912783D2-CF6F-4040-B564-4E2436EB0827}.Release|Pocket PC 2003 (ARMV4).ActiveCfg = Release|Win32
+               {912783D2-CF6F-4040-B564-4E2436EB0827}.Release|Win32.ActiveCfg = Release|Win32
+               {912783D2-CF6F-4040-B564-4E2436EB0827}.Release|Win32.Build.0 = Release|Win32
+               {912783D2-CF6F-4040-B564-4E2436EB0827}.Release|x64.ActiveCfg = Release|Win32
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
@@ -1405,6 +1419,7 @@ Global
                {41A5009F-4467-4D89-A171-5A919FEFE16E} = {5818CCA9-B585-44B8-B29E-98B1DC278A3C}
                {C317231C-B984-4423-ACF2-C19DE8B6AA3F} = {5818CCA9-B585-44B8-B29E-98B1DC278A3C}
                {7D0A15A1-7F6E-480D-9926-13BB6DAA0E10} = {5818CCA9-B585-44B8-B29E-98B1DC278A3C}
+               {912783D2-CF6F-4040-B564-4E2436EB0827} = {5818CCA9-B585-44B8-B29E-98B1DC278A3C}
                {BECC966D-AFC8-48F6-97B1-2FE92062D7B4} = {69EC5B74-D466-422E-B8D1-1386B0421D54}
                {23F22F68-D562-4E80-8267-9F1DD9398357} = {69EC5B74-D466-422E-B8D1-1386B0421D54}
                {169A4446-A035-4CF7-8377-3C517ADF0C50} = {69EC5B74-D466-422E-B8D1-1386B0421D54}
diff --git a/src/server/smsdrv/dbemu/dbemu.h b/src/server/smsdrv/dbemu/dbemu.h
new file mode 100644 (file)
index 0000000..27de961
--- /dev/null
@@ -0,0 +1,42 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2011 NetXMS Team
+**
+** 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: dbemu.h
+**
+**/
+
+#ifndef __DBEMU_H__
+#define __DBEMU_H__
+
+#include <nms_common.h>
+#include <nxsrvapi.h>
+#include <nxdbapi.h>
+#include <nms_util.h>
+
+#ifdef _WIN32
+#define EXPORT __declspec(dllexport)
+#else
+#define EXPORT
+#endif
+
+#define MAX_DBPARAM_LEN                (31)
+#define MAX_STR                                (256)
+#define MAX_SQL                                (1024)
+#define MYNAMESTR                      (_T("SMSDBEmu"))
+
+#endif
\ No newline at end of file
diff --git a/src/server/smsdrv/dbemu/dbemu.vcproj b/src/server/smsdrv/dbemu/dbemu.vcproj
new file mode 100644 (file)
index 0000000..fa35884
--- /dev/null
@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="windows-1251"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="8,00"\r
+       Name="dbemu"\r
+       ProjectGUID="{912783D2-CF6F-4040-B564-4E2436EB0827}"\r
+       RootNamespace="dbemu"\r
+       Keyword="Win32Proj"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="2"\r
+                       CharacterSet="2"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories="..\..\..\..\include;..\..\include"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;DBEMU_EXPORTS"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="4"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               OutputFile="$(OutDir)\$(ProjectName).sms"\r
+                               LinkIncremental="2"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="2"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="2"\r
+                       CharacterSet="2"\r
+                       WholeProgramOptimization="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               AdditionalIncludeDirectories="..\..\..\..\include;..\..\include"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DBEMU_EXPORTS"\r
+                               RuntimeLibrary="2"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               OutputFile="$(OutDir)\$(ProjectName).sms"\r
+                               LinkIncremental="1"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="2"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
+                       >\r
+                       <File\r
+                               RelativePath=".\main.cpp"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"\r
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
+                       >\r
+                       <File\r
+                               RelativePath=".\dbemu.h"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Resource Files"\r
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"\r
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"\r
+                       >\r
+               </Filter>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
diff --git a/src/server/smsdrv/dbemu/main.cpp b/src/server/smsdrv/dbemu/main.cpp
new file mode 100644 (file)
index 0000000..1e95fb5
--- /dev/null
@@ -0,0 +1,137 @@
+/* 
+** NetXMS - Network Management System
+** SMS driver emulator for databases
+** Copyright (C) 2011 NetXMS Team
+**
+** 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 "dbemu.h"
+
+static TCHAR dbDriver[MAX_STR];
+static TCHAR dbName[MAX_DBPARAM_LEN];
+static TCHAR dbUsername[MAX_DBPARAM_LEN];
+static TCHAR dbPassword[MAX_DBPARAM_LEN];
+static TCHAR dbServer[MAX_DBPARAM_LEN];
+static TCHAR dbSchema[MAX_DBPARAM_LEN];
+static TCHAR sqlTemplate[MAX_STR];
+
+TCHAR *configFile;
+DB_HANDLE dbh;
+
+extern "C" BOOL EXPORT SMSDriverInit(const TCHAR *pszInitArgs)
+{
+       BOOL bRet = false;
+       NX_CFG_TEMPLATE configTemplate[] = 
+       {
+               { _T("DBDriver"),                       CT_STRING,      0, 0, MAX_DBPARAM_LEN, 0,       dbDriver },     
+               { _T("DBName"),                         CT_STRING,      0, 0, MAX_DBPARAM_LEN, 0,       dbName },       
+               { _T("DBLogin"),                        CT_STRING,      0, 0, MAX_DBPARAM_LEN, 0,       dbUsername },   
+               { _T("DBPassword"),                     CT_STRING,      0, 0, MAX_DBPARAM_LEN, 0,       dbPassword },
+               { _T("DBServer"),                       CT_STRING,      0, 0, MAX_DBPARAM_LEN, 0,       dbServer },     
+               { _T("DBSchema"),                       CT_STRING,      0, 0, MAX_DBPARAM_LEN, 0,       dbSchema },     
+               { _T("SqlTemplate"),            CT_STRING,      0, 0, MAX_DBPARAM_LEN, 0,       sqlTemplate },  
+               { _T(""), CT_END_OF_LIST, 0, 0, 0, 0, NULL }
+       };
+
+       if (pszInitArgs == NULL || *pszInitArgs == 0)
+       {
+#ifdef _WIN32
+               configFile = _tcsdup(_T("\\smsdbemu.conf"));
+#else
+               configFile = _tcsdup(_T("/etc/smsdbemu.conf"));
+#endif
+       }
+       else
+       {
+               configFile = _tcsdup(pszInitArgs);
+       }
+
+       Config *config = new Config();
+       if (config->loadIniConfig(configFile, _T("SMSDbEmu")) && config->parseTemplate(_T("SMSDbEmu"), configTemplate))
+       {
+               if (!DBInit(0, 0))
+               {
+                       DbgPrintf(1, _T("%s: Unable to initialize database library"), MYNAMESTR);
+                       goto finish;
+               }
+
+               DB_DRIVER driver = DBLoadDriver(dbDriver, NULL, TRUE, NULL, NULL);
+               if (driver == NULL)
+               {
+                       DbgPrintf(1, _T("%s: Unable to load and initialize database driver \"%s\""), MYNAMESTR, dbDriver);
+                       goto finish;
+               }
+
+               TCHAR errorText[DBDRV_MAX_ERROR_TEXT];
+               dbh = DBConnect(driver, dbServer, dbName, dbUsername, dbPassword, dbSchema, errorText);
+               if (dbh == NULL)
+               {
+                       DbgPrintf(1, _T("%s: Unable to connect to database %s@%s as %s: %s"), MYNAMESTR, dbName, dbServer, dbUsername, errorText);
+                       DBUnloadDriver(driver);
+                       goto finish;
+               }       
+               bRet = true;
+       }
+
+finish:
+       return bRet;
+}
+
+extern "C" BOOL EXPORT SMSDriverSend(const TCHAR *pszPhoneNumber, const TCHAR *pszText)
+{
+       BOOL bRet = false;
+       TCHAR *realText = EscapeStringForXML(pszText, -1);
+
+       DB_STATEMENT dbs = DBPrepare(dbh, sqlTemplate);
+       if (dbs != NULL)
+       {
+               DBBind(dbs, 1, DB_SQLTYPE_VARCHAR, pszPhoneNumber, DB_BIND_STATIC);
+               DBBind(dbs, 2, DB_SQLTYPE_VARCHAR, realText, DB_BIND_STATIC);
+               if (!(bRet = DBExecute(dbs)))
+                       DbgPrintf(1, _T("%s: Cannot execute"), MYNAMESTR);
+               else
+                       DbgPrintf(9, _T("%s: sent sms '%s' to %s"), MYNAMESTR, realText, pszPhoneNumber);
+               DBFreeStatement(dbs);
+       }
+
+       return bRet;
+}
+
+
+extern "C" void EXPORT SMSDriverUnload()
+{
+       DBDisconnect(dbh);
+}
+
+
+//
+// DLL Entry point
+//
+
+#ifdef _WIN32
+
+BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
+{
+       if (dwReason == DLL_PROCESS_ATTACH)
+               DisableThreadLibraryCalls(hInstance);
+       return TRUE;
+}
+
+#endif
+