common process init function for all NetXMS processes; set correct LC_CTYPE and use...
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 11 Feb 2016 11:42:28 +0000 (13:42 +0200)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 11 Feb 2016 11:42:28 +0000 (13:42 +0200)
37 files changed:
ChangeLog
configure.ac
include/nms_util.h
src/agent/core/nxagentd.cpp
src/agent/nxsagent/main.cpp
src/agent/tools/nxappget/nxappget.cpp
src/agent/tools/nxapush/nxapush.cpp
src/client/nxalarm/nxalarm.cpp
src/client/nxevent/nxevent.cpp
src/client/nxpush/nxpush.cpp
src/client/nxsms/nxsms.cpp
src/flow_analyzer/nxflowd/nxflowd.cpp
src/libnetxms/tools.cpp
src/libnetxms/unicode.cpp
src/nxcproxy/nxcproxy.cpp
src/nxinstall/nxinstall.cpp
src/nxlptest/nxlptest.cpp
src/nxscript/nxscript.cpp
src/server/core/main.cpp
src/server/netxmsd/netxmsd.cpp
src/server/tools/driverloader/loader.cpp
src/server/tools/nxaction/nxaction.cpp
src/server/tools/nxadm/.cproject [new file with mode: 0644]
src/server/tools/nxadm/.project [new file with mode: 0644]
src/server/tools/nxadm/.settings/language.settings.xml [new file with mode: 0644]
src/server/tools/nxadm/nxadm.cpp
src/server/tools/nxap/nxap.cpp
src/server/tools/nxdbmgr/nxdbmgr.cpp
src/server/tools/nxget/nxget.cpp
src/server/tools/nxupload/nxupload.cpp
src/snmp/nxmibc/nxmibc.cpp
src/snmp/nxsnmpget/nxsnmpget.cpp
src/snmp/nxsnmpset/nxsnmpset.cpp
src/snmp/nxsnmpwalk/nxsnmpwalk.cpp
src/tools/nxdevcfg/nxdevcfg.cpp
src/tools/nxencpasswd/nxencpasswd.cpp
src/tools/nxgenguid/nxgenguid.cpp

index f96f9d4..8a35903 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,7 @@
 - GPS subagent (provides location data from NMEA compatible GPS receivers)
 - Server can update node location using GPS subagent
 - Fixed error while event alarm linking multiple times
+- NetXMS processes uses LC_CTYPE from environment for terminal I/O
 - Management console:
        - Fixed grid issues in network maps
        - Added "hide links" option on network maps
index 8ecaa15..b81522f 100644 (file)
@@ -2193,7 +2193,7 @@ AC_CHECK_FUNCS([wcslwr wcserror wcserror_r wfopen wfopen64 fputws putws])
 AC_CHECK_FUNCS([wopen wstat waccess wgetenv wrename wunlink wremove wchdir])
 AC_CHECK_FUNCS([wmkdir wrmdir wsystem wmkstemp wpopen wctime wchmod vwscanf])
 AC_CHECK_FUNCS([vswscanf vfwscanf wcscasecmp wcsncasecmp wcstombs wcsrtombs])
-AC_CHECK_FUNCS([itow _itow wcsftime])
+AC_CHECK_FUNCS([mbstowcs mbsrtowcs itow _itow wcsftime])
 
 AC_CHECK_DECLS([putws],,,[
 #if HAVE_WCHAR_H
index 831d4e6..311d6e5 100644 (file)
@@ -213,8 +213,10 @@ inline TCHAR *_tcsdup_ex(const TCHAR *s)
 extern "C" {
 #endif
 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromMBString(const char *pszString);
+WCHAR LIBNETXMS_EXPORTABLE *WideStringFromMBStringSysLocale(const char *pszString);
 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromUTF8String(const char *pszString);
 char LIBNETXMS_EXPORTABLE *MBStringFromWideString(const WCHAR *pwszString);
+char LIBNETXMS_EXPORTABLE *MBStringFromWideStringSysLocale(const WCHAR *pwszString);
 char LIBNETXMS_EXPORTABLE *UTF8StringFromWideString(const WCHAR *pwszString);
 #ifdef __cplusplus
 }
@@ -1460,6 +1462,8 @@ extern "C"
 {
 #endif
 
+void LIBNETXMS_EXPORTABLE InitNetXMSProcess();
+
 #if !defined(_WIN32) && !defined(_NETWARE)
 #if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
 void LIBNETXMS_EXPORTABLE __wcsupr(WCHAR *in);
index 0e85e0d..356567f 100644 (file)
@@ -1319,9 +1319,7 @@ int main(int argc, char *argv[])
        int uid = 0, gid = 0;
 #endif
 
-#ifdef _WIN32
-       SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
-#endif
+   InitNetXMSProcess();
 
 #if defined(__sun) || defined(_AIX) || defined(__hpux)
    signal(SIGPIPE, SIG_IGN);
@@ -1331,20 +1329,6 @@ int main(int argc, char *argv[])
    signal(SIGUSR2, SIG_IGN);
 #endif
 
-   InitThreadLibrary();
-
-#ifdef NETXMS_MEMORY_DEBUG
-       InitMemoryDebugger();
-#endif
-
-   // Set locale to C. It shouldn't be needed, according to
-   // documentation, but I've seen the cases when agent formats
-   // floating point numbers by sprintf inserting comma in place
-   // of a dot, as set by system's regional settings.
-#if HAVE_SETLOCALE
-   setlocale(LC_NUMERIC, "C");
-#endif
-
    // Check for alternate config file location
 #ifdef _WIN32
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\NetXMS\\Agent"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
index f69f170..da61a08 100644 (file)
@@ -322,6 +322,8 @@ static HWND GetConsoleHWND()
  */
 int main(int argc, char *argv[])
 {
+   InitNetXMSProcess();
+
    bool hideConsole = false;
 
    int ch;
index e52d7ae..bd44f5d 100644 (file)
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
        int ret = 0;
        int c;
 
-       InitThreadLibrary();
+       InitNetXMSProcess();
 
        opterr = 0;
 #if HAVE_DECL_GETOPT_LONG
index 43cbc4b..accd86a 100644 (file)
@@ -1,7 +1,7 @@
 /* 
 ** nxapush - command line tool used to push DCI values to NetXMS server
 **           via local NetXMS agent
-** Copyright (C) 2006-2014 Raden Solutions
+** Copyright (C) 2006-2016 Raden Solutions
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -255,7 +255,7 @@ int main(int argc, char *argv[])
        int ret = 0;
        int c;
 
-       InitThreadLibrary();
+       InitNetXMSProcess();
 
        opterr = 0;
 #if HAVE_DECL_GETOPT_LONG
index 1493bf9..9046233 100644 (file)
@@ -86,6 +86,8 @@ int main(int argc, char *argv[])
    int timeout = 3, ackTimeout = 0;
        int ch;
 
+   InitNetXMSProcess();
+
    // Parse command line
    opterr = 1;
    while((ch = getopt(argc, argv, CMDLINE_OPTIONS)) != -1)
index 415196e..c884bb8 100644 (file)
@@ -106,6 +106,8 @@ int main(int argc, char *argv[])
    int ch, rcc = RCC_INVALID_ARGUMENT;
    BOOL bStart = TRUE, bEncrypt = FALSE;
 
+   InitNetXMSProcess();
+
    // Parse command line
    opterr = 1;
    while((ch = getopt(argc, argv, CMDLINE_OPTIONS)) != -1)
index b61e7fe..5018555 100644 (file)
@@ -446,7 +446,7 @@ int main(int argc, char *argv[])
        int ret = 0;
        int c;
 
-       InitThreadLibrary();
+       InitNetXMSProcess();
 
        opterr = 0;
 #if HAVE_DECL_GETOPT_LONG
index ccf473d..546e424 100644 (file)
@@ -47,6 +47,8 @@ int main(int argc, char *argv[])
        DWORD rcc, timeout = 3;
        int ch;
 
+   InitNetXMSProcess();
+
    // Parse command line
    opterr = 1;
    while((ch = getopt(argc, argv, CMDLINE_OPTIONS)) != -1)
index 0f473db..696e254 100644 (file)
@@ -278,7 +278,7 @@ int main(int argc, char *argv[])
        TCHAR moduleName[MAX_PATH];
 #endif
 
-   InitThreadLibrary();
+   InitNetXMSProcess();
 
        // Parse command line
        opterr = 1;
index 304580a..8e9f15b 100644 (file)
 #include <malloc.h>
 #endif
 
+#if HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
 #ifdef _WIN32
 # ifndef __GNUC__
 #  define EPOCHFILETIME (116444736000000000i64)
 #endif
 
 /**
+ * Common initialization for any NetXMS process
+ */
+void LIBNETXMS_EXPORTABLE InitNetXMSProcess()
+{
+   InitThreadLibrary();
+
+   // Set locale to C. It shouldn't be needed, according to
+   // documentation, but I've seen the cases when agent formats
+   // floating point numbers by sprintf inserting comma in place
+   // of a dot, as set by system's regional settings.
+#if HAVE_SETLOCALE
+   setlocale(LC_NUMERIC, "C");
+#if defined(UNICODE) && !defined(_WIN32)
+   const char *locale = getenv("LC_CTYPE");
+   if (locale == NULL)
+      locale = getenv("LC_ALL");
+   if (locale == NULL)
+      locale = getenv("LANG");
+   if (locale != NULL)
+      setlocale(LC_CTYPE, locale);
+#endif
+#endif
+
+#ifdef NETXMS_MEMORY_DEBUG
+   InitMemoryDebugger();
+#endif
+
+#ifdef _WIN32
+   SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
+#endif
+}
+
+/**
  * Calculate number of bits in netmask (in host byte order)
  */
 int LIBNETXMS_EXPORTABLE BitsInMask(UINT32 dwMask)
@@ -2178,7 +2215,7 @@ void LIBNETXMS_EXPORTABLE WriteToTerminal(const TCHAR *text)
 #if HAVE_FPUTWS
        fputws(text, stdout);
 #else
-       char *mbtext = MBStringFromWideString(text);
+       char *mbtext = MBStringFromWideStringSysLocale(text);
        fputs(mbtext, stdout);
        free(mbtext);
 #endif
index e2084d6..603f696 100644 (file)
@@ -1,6 +1,6 @@
 /*
  ** NetXMS - Network Management System
- ** Copyright (C) 2003-2014 RAden Solutions
+ ** Copyright (C) 2003-2016 Raden Solutions
  **
  ** 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
@@ -388,6 +388,28 @@ UINT32 LIBNETXMS_EXPORTABLE inet_addr_w(const WCHAR *pszAddr)
 }
 
 /**
+ * Convert multibyte string to wide string using current LC_CTYPE setting and
+ * allocating wide string dynamically
+ */
+WCHAR LIBNETXMS_EXPORTABLE *WideStringFromMBStringSysLocale(const char *pszString)
+{
+#ifdef _WIN32
+   return WideStringFromMBString(pszString);
+#else
+   if (pszString == NULL)
+      return NULL;
+   int nLen = (int)strlen(pszString) + 1;
+   WCHAR *pwszOut = (WCHAR *) malloc(nLen * sizeof(WCHAR));
+#if HAVE_MBSTOWCS
+   mbstowcs(pwszOut, pszString, nLen);
+#else
+   MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pszString, -1, pwszOut, nLen);
+#endif
+   return pwszOut;
+#endif
+}
+
+/**
  * Convert multibyte string to wide string using current codepage and
  * allocating wide string dynamically
  */
@@ -429,6 +451,28 @@ char LIBNETXMS_EXPORTABLE *MBStringFromWideString(const WCHAR *pwszString)
 }
 
 /**
+ * Convert wide string to multibyte string using current LC_CTYPE setting and
+ * allocating multibyte string dynamically
+ */
+char LIBNETXMS_EXPORTABLE *MBStringFromWideStringSysLocale(const WCHAR *pwszString)
+{
+#ifdef _WIN32
+   return MBStringFromWideString(pwszString);
+#else
+   if (pwszString == NULL)
+      return NULL;
+   int nLen = (int)wcslen(pwszString) + 1;
+   char *pszOut = (char *)malloc(nLen);
+#if HAVE_WCSTOMBS
+   wcstombs(pszOut, pwszString, nLen);
+#else
+   WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, pwszString, -1, pszOut, nLen, NULL, NULL);
+#endif
+   return pszOut;
+#endif
+}
+
+/**
  * Convert wide string to UTF8 string allocating UTF8 string dynamically
  */
 char LIBNETXMS_EXPORTABLE *UTF8StringFromWideString(const WCHAR *pwszString)
index f0f48eb..bd5bd1d 100644 (file)
@@ -315,9 +315,7 @@ int main(int argc, char *argv[])
    TCHAR *pszEnv;
 #endif
 
-#ifdef _WIN32
-       SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
-#endif
+   InitNetXMSProcess();
 
 #if defined(__sun) || defined(_AIX) || defined(__hpux)
    signal(SIGPIPE, SIG_IGN);
@@ -328,12 +326,6 @@ int main(int argc, char *argv[])
    signal(SIGUSR2, SIG_IGN);
 #endif
 
-   InitThreadLibrary();
-
-#ifdef NETXMS_MEMORY_DEBUG
-       InitMemoryDebugger();
-#endif
-   
    // Check for alternate config file location
 #ifdef _WIN32
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\NetXMS\\ClientProxy"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
index 865524a..c23f0a9 100644 (file)
@@ -42,6 +42,8 @@ int main(int argc, char *argv[])
    int i, ch;
    bool dump = false, printResult = false, quiet = false;
 
+   InitNetXMSProcess();
+
    // Parse command line
    opterr = 1;
        while((ch = getopt(argc, argv, "drt:q")) != -1)
index 9729383..276dce4 100644 (file)
@@ -85,6 +85,8 @@ int main(int argc, char *argv[])
        TCHAR *inputFile = NULL;
        LogParser *parser;
 
+   InitNetXMSProcess();
+
    // Parse command line
    opterr = 1;
        while((ch = getopt(argc, argv, "f:hit:v")) != -1)
index 0475b19..f11949c 100644 (file)
@@ -64,6 +64,8 @@ int main(int argc, char *argv[])
    bool dump = false, printResult = false, compileOnly = false, binary = false;
    int runCount = 1;
 
+   InitNetXMSProcess();
+
    func.m_iNumArgs = 0;
    func.m_pfHandler = F_new;
    _tcscpy(func.m_name, _T("new"));
index 81b5b2a..d55f6f8 100644 (file)
@@ -2143,7 +2143,11 @@ THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL Main(void *pArg)
                           if (ptr != NULL)
                           {
 #ifdef UNICODE
+#if HAVE_MBSTOWCS
+                             mbstowcs(wcCommand, ptr, 255);
+#else
                                   MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, ptr, -1, wcCommand, 256);
+#endif
                                   wcCommand[255] = 0;
                                   StrStrip(wcCommand);
                                   if (wcCommand[0] != 0)
index 71c06a2..a418da5 100644 (file)
@@ -1,7 +1,7 @@
 /* 
 ** NetXMS - Network Management System
 ** Server startup module
-** Copyright (C) 2003-2015 Raden Solutions
+** Copyright (C) 2003-2016 Raden Solutions
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 
 #include "netxmsd.h"
 
-#if HAVE_LOCALE_H
-#include <locale.h>
-#endif
-
 #if HAVE_GETOPT_H
 #include <getopt.h>
 #endif
@@ -329,12 +325,7 @@ static BOOL ParseCommandLine(int argc, char *argv[])
  */
 int main(int argc, char* argv[])
 {
-#ifdef _WIN32
-   HKEY hKey;
-   DWORD dwSize;
-#else
-   FILE *fp;
-#endif
+   InitNetXMSProcess();
 
 #ifndef _WIN32
    signal(SIGPIPE, SIG_IGN);
@@ -344,25 +335,12 @@ int main(int argc, char* argv[])
    signal(SIGUSR2, SIG_IGN);
 #endif
 
-   InitThreadLibrary();
-
-#ifdef NETXMS_MEMORY_DEBUG
-   InitMemoryDebugger();
-#endif
-
-   // Set locale to C. It shouldn't be needed, according to
-   // documentation, but I've seen the cases when agent formats
-   // floating point numbers by sprintf inserting comma in place
-   // of a dot, as set by system's regional settings.
-#if HAVE_SETLOCALE
-   setlocale(LC_NUMERIC, "C");
-#endif
-
    // Check for alternate config file location
 #ifdef _WIN32
+   HKEY hKey;
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\NetXMS\\Server"), 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS)
    {
-      dwSize = MAX_PATH * sizeof(TCHAR);
+      DWORD dwSize = MAX_PATH * sizeof(TCHAR);
       RegQueryValueEx(hKey, _T("ConfigFile"), NULL, NULL, (BYTE *)g_szConfigFile, &dwSize);
       RegCloseKey(hKey);
    }
@@ -448,7 +426,7 @@ int main(int argc, char* argv[])
    }
 
    // Write PID file
-   fp = _tfopen(g_szPIDFile, _T("w"));
+   FILE *fp = _tfopen(g_szPIDFile, _T("w"));
    if (fp != NULL)
    {
       _ftprintf(fp, _T("%d"), getpid());
index ca2079a..623a5b1 100644 (file)
@@ -211,6 +211,8 @@ int main(int argc, char *argv[])
    int snmpPort = 161;
    const char *community = "public";
 
+   InitNetXMSProcess();
+
    // Parse command line
    opterr = 1;
    int ch;
index 12858ef..d090121 100644 (file)
@@ -60,7 +60,7 @@ int main(int argc, char *argv[])
    TCHAR szKeyFile[MAX_PATH];
    RSA *pServerKey = NULL;
 
-   InitThreadLibrary();
+   InitNetXMSProcess();
 
    GetNetXMSDirectory(nxDirData, szKeyFile);
    _tcscat(szKeyFile, DFILE_KEYS);
diff --git a/src/server/tools/nxadm/.cproject b/src/server/tools/nxadm/.cproject
new file mode 100644 (file)
index 0000000..d8a88b9
--- /dev/null
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
+       <storageModule moduleId="org.eclipse.cdt.core.settings">
+               <cconfiguration id="cdt.managedbuild.toolchain.gnu.base.388951568">
+                       <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.388951568" moduleId="org.eclipse.cdt.core.settings" name="Default">
+                               <externalSettings/>
+                               <extensions>
+                                       <extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
+                                       <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
+                               </extensions>
+                       </storageModule>
+                       <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+                               <configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.base.388951568" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
+                                       <folderInfo id="cdt.managedbuild.toolchain.gnu.base.388951568.613702561" name="/" resourcePath="">
+                                               <toolChain id="cdt.managedbuild.toolchain.gnu.base.837443512" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.base">
+                                                       <targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.base.1709404275" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
+                                                       <builder id="cdt.managedbuild.target.gnu.builder.base.1313376028" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.archiver.base.1378619410" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.519759521" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
+                                                               <option id="gnu.cpp.compiler.option.include.paths.1200920526" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}/src/server/include&quot;"/>
+                                                               </option>
+                                                               <option id="gnu.cpp.compiler.option.preprocessor.def.156451159" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" valueType="definedSymbols">
+                                                                       <listOptionValue builtIn="false" value="_THREAD_SAFE"/>
+                                                                       <listOptionValue builtIn="false" value="TRE_WCHAR=1"/>
+                                                                       <listOptionValue builtIn="false" value="UNICODE"/>
+                                                                       <listOptionValue builtIn="false" value="_GNU_SOURCE"/>
+                                                               </option>
+                                                               <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.2051298310" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
+                                                       </tool>
+                                                       <tool id="cdt.managedbuild.tool.gnu.c.compiler.base.998957044" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
+                                                               <option id="gnu.c.compiler.option.include.paths.1131635407" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}/src/server/include&quot;"/>
+                                                               </option>
+                                                               <option id="gnu.c.compiler.option.preprocessor.def.symbols.322363942" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" valueType="definedSymbols">
+                                                                       <listOptionValue builtIn="false" value="_THREAD_SAFE"/>
+                                                                       <listOptionValue builtIn="false" value="TRE_WCHAR=1"/>
+                                                                       <listOptionValue builtIn="false" value="UNICODE"/>
+                                                                       <listOptionValue builtIn="false" value="_GNU_SOURCE"/>
+                                                               </option>
+                                                               <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1972328149" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
+                                                       </tool>
+                                                       <tool id="cdt.managedbuild.tool.gnu.c.linker.base.471860298" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
+                                                       <tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.1347961517" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
+                                                               <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1741844255" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
+                                                                       <additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
+                                                                       <additionalInput kind="additionalinput" paths="$(LIBS)"/>
+                                                               </inputType>
+                                                       </tool>
+                                                       <tool id="cdt.managedbuild.tool.gnu.assembler.base.1538965285" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
+                                                               <option id="gnu.both.asm.option.include.paths.1935992019" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath">
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}/include&quot;"/>
+                                                                       <listOptionValue builtIn="false" value="&quot;${NETXMS_BASE}/src/server/include&quot;"/>
+                                                               </option>
+                                                               <inputType id="cdt.managedbuild.tool.gnu.assembler.input.1457393705" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
+                                                       </tool>
+                                               </toolChain>
+                                       </folderInfo>
+                               </configuration>
+                       </storageModule>
+                       <storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
+               </cconfiguration>
+       </storageModule>
+       <storageModule moduleId="cdtBuildSystem" version="4.0.0">
+               <project id="nxadm.null.115316220" name="nxadm"/>
+       </storageModule>
+       <storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
+       <storageModule moduleId="scannerConfiguration">
+               <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+               <scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.388951568;cdt.managedbuild.toolchain.gnu.base.388951568.613702561;cdt.managedbuild.tool.gnu.c.compiler.base.998957044;cdt.managedbuild.tool.gnu.c.compiler.input.1972328149">
+                       <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+               </scannerConfigBuildInfo>
+               <scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.388951568;cdt.managedbuild.toolchain.gnu.base.388951568.613702561;cdt.managedbuild.tool.gnu.cpp.compiler.base.519759521;cdt.managedbuild.tool.gnu.cpp.compiler.input.2051298310">
+                       <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
+               </scannerConfigBuildInfo>
+       </storageModule>
+</cproject>
diff --git a/src/server/tools/nxadm/.project b/src/server/tools/nxadm/.project
new file mode 100644 (file)
index 0000000..1850d26
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>nxadm</name>
+       <comment></comment>
+       <projects>
+               <project>libnetxms</project>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
+                       <triggers>clean,full,incremental,</triggers>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
+                       <triggers>full,incremental,</triggers>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.cdt.core.cnature</nature>
+               <nature>org.eclipse.cdt.core.ccnature</nature>
+               <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
+               <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
+       </natures>
+       <filteredResources>
+               <filter>
+                       <id>1455188580433</id>
+                       <name></name>
+                       <type>6</type>
+                       <matcher>
+                               <id>org.eclipse.ui.ide.multiFilter</id>
+                               <arguments>1.0-name-matches-false-false-*.o</arguments>
+                       </matcher>
+               </filter>
+               <filter>
+                       <id>1455188580440</id>
+                       <name></name>
+                       <type>6</type>
+                       <matcher>
+                               <id>org.eclipse.ui.ide.multiFilter</id>
+                               <arguments>1.0-name-matches-false-false-*.lo</arguments>
+                       </matcher>
+               </filter>
+       </filteredResources>
+</projectDescription>
diff --git a/src/server/tools/nxadm/.settings/language.settings.xml b/src/server/tools/nxadm/.settings/language.settings.xml
new file mode 100644 (file)
index 0000000..a5a2c5d
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<project>
+       <configuration id="cdt.managedbuild.toolchain.gnu.base.388951568" name="Default">
+               <extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
+                       <provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
+                       <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
+                       <provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
+                       <provider-reference id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" ref="shared-provider"/>
+                       <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
+               </extension>
+       </configuration>
+</project>
index adda0c8..5ff3a9f 100644 (file)
@@ -1,7 +1,7 @@
 /* 
 ** NetXMS - Network Management System
 ** Local administration tool
-** Copyright (C) 2003-2015 Victor Kirhenshtein
+** Copyright (C) 2003-2016 Victor Kirhenshtein
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -23,7 +23,7 @@
 
 #include "nxadm.h"
 
-#if !defined(_WIN32) && HAVE_READLINE_READLINE_H && HAVE_READLINE
+#if !defined(_WIN32) && HAVE_READLINE_READLINE_H && HAVE_READLINE && !defined(UNICODE)
 #include <readline/readline.h>
 #include <readline/history.h>
 #define USE_READLINE 1
  */
 static void Help()
 {
-   printf("NetXMS Administartor Tool  Version " NETXMS_VERSION_STRING_A "\n"
-          "Copyright (c) 2004, 2005, 2006, 2007 Victor Kirhenshtein\n\n"
-          "Usage: nxadm -c <command>\n"
-          "       nxadm -i\n"
-          "       nxadm -h\n\n"
-          "Options:\n"
-          "   -c  Execute given command and disconnect\n"
-          "   -i  Go to interactive mode\n"
-          "   -h  Dispaly help and exit\n\n");
+   _tprintf(_T("NetXMS Server Administration Tool  Version ") NETXMS_VERSION_STRING _T("\n")
+            _T("Copyright (c) 2004-2016 Raden Solutions\n\n")
+            _T("Usage: nxadm -c <command>\n")
+            _T("       nxadm -i\n")
+            _T("       nxadm -h\n\n")
+            _T("Options:\n")
+            _T("   -c  Execute given command at server debug console and disconnect\n")
+            _T("   -i  Connect to server debug console in interactive mode\n")
+            _T("   -h  Display help and exit\n\n"));
 }
 
 /**
  * Execute command
  */
-static BOOL ExecCommand(char *pszCmd)
+static bool ExecCommand(const TCHAR *command)
 {
-   NXCPMessage msg, *pResponse;
-   BOOL bConnClosed = FALSE;
-   WORD wCode;
-   TCHAR *pszText;
+   bool connClosed = false;
 
+   NXCPMessage msg;
    msg.setCode(CMD_ADM_REQUEST);
    msg.setId(g_dwRqId++);
-#ifdef UNICODE
-   WCHAR *wcmd = WideStringFromMBString(pszCmd);
-   msg.setField(VID_COMMAND, wcmd);
-   free(wcmd);
-#else
-   msg.setField(VID_COMMAND, pszCmd);
-#endif
+   msg.setField(VID_COMMAND, command);
    SendMsg(&msg);
 
-   while(1)
+   while(true)
    {
-      pResponse = RecvMsg();
-      if (pResponse == NULL)
+      NXCPMessage *response = RecvMsg();
+      if (response == NULL)
       {
-         printf("Connection closed\n");
-         bConnClosed = TRUE;
+         _tprintf(_T("Connection closed\n"));
+         connClosed = true;
          break;
       }
 
-      wCode = pResponse->getCode();
-      switch(wCode)
+      UINT16 code = response->getCode();
+      if(code == CMD_ADM_MESSAGE)
       {
-         case CMD_ADM_MESSAGE:
-            pszText = pResponse->getFieldAsString(VID_MESSAGE);
-            if (pszText != NULL)
-            {
-#if defined(_WIN32) || !defined(UNICODE)
-               WriteToTerminal(pszText);
-#else
-              char *mbText = MBStringFromWideString(pszText);
-              fputs(mbText, stdout);
-              free(mbText);
-#endif
-               free(pszText);
-            }
-            break;
-         default:
-            break;
+         TCHAR *text = response->getFieldAsString(VID_MESSAGE);
+         if (text != NULL)
+         {
+            WriteToTerminal(text);
+         }
       }
-      delete pResponse;
-      if (wCode == CMD_REQUEST_COMPLETED)
+      delete response;
+      if (code == CMD_REQUEST_COMPLETED)
          break;
    }
 
-   return bConnClosed;
+   return connClosed;
 }
 
 /**
@@ -111,8 +92,8 @@ static void Shell()
 {
    char *ptr;
 
-   printf("\nNetXMS Server Remote Console V" NETXMS_VERSION_STRING_A " Ready\n"
-          "Enter \"help\" for command list\n\n");
+   _tprintf(_T("\nNetXMS Server Remote Console V") NETXMS_VERSION_STRING _T(" Ready\n")
+            _T("Enter \"help\" for command list\n\n"));
 
 #if USE_READLINE
    // Initialize readline library if we use it
@@ -124,11 +105,7 @@ static void Shell()
 #if USE_READLINE
       ptr = readline("\x1b[33mnetxmsd:\x1b[0m ");
 #else
-#ifdef _WIN32
       WriteToTerminal(_T("\x1b[33mnetxmsd:\x1b[0m "));
-#else
-      fputs("\x1b[33mnetxmsd:\x1b[0m ", stdout);
-#endif
       fflush(stdout);
       char szCommand[256];
       if (fgets(szCommand, 255, stdin) == NULL)
@@ -141,10 +118,24 @@ static void Shell()
 
       if (ptr != NULL)
       {
-         StrStripA(ptr);
+#ifdef UNICODE
+         WCHAR wcCommand[256];
+#if HAVE_MBSTOWCS
+         mbstowcs(wcCommand, ptr, 255);
+#else
+         MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, ptr, -1, wcCommand, 256);
+#endif
+         wcCommand[255] = 0;
+         StrStrip(wcCommand);
+         if (wcCommand[0] != 0)
+         {
+            if (ExecCommand(wcCommand))
+#else
+         StrStrip(ptr);
          if (*ptr != 0)
          {
             if (ExecCommand(ptr))
+#endif
                break;
 #if USE_READLINE
             add_history(ptr);
@@ -156,7 +147,7 @@ static void Shell()
       }
       else
       {
-         printf("\n");
+         _tprintf(_T("\n"));
       }
    }
 
@@ -172,11 +163,12 @@ int main(int argc, char *argv[])
 {
    int iError, ch;
    BOOL bStart = TRUE, bCmdLineOK = FALSE;
-   char *pszCmd;
+   TCHAR *command = NULL;
+
+   InitNetXMSProcess();
 
 #ifdef _WIN32
    WSADATA wsaData;
-
    WSAStartup(0x0002, &wsaData);
 #endif
 
@@ -193,11 +185,15 @@ int main(int argc, char *argv[])
                bStart = FALSE;
                break;
             case 'c':
-               pszCmd = optarg;
+#ifdef UNICODE
+               command = WideStringFromMBStringSysLocale(optarg);
+#else
+               command = optarg;
+#endif
                bCmdLineOK = TRUE;
                break;
             case 'i':
-               pszCmd = NULL;
+               command = NULL;
                bCmdLineOK = TRUE;
                break;
             case '?':
@@ -213,13 +209,13 @@ int main(int argc, char *argv[])
       {
          if (Connect())
          {
-            if (pszCmd == NULL)
+            if (command == NULL)
             {
                Shell();
             }
             else
             {
-               ExecCommand(pszCmd);
+               ExecCommand(command);
             }
             Disconnect();
             iError = 0;
@@ -240,5 +236,8 @@ int main(int argc, char *argv[])
       Help();
       iError = 1;
    }
+#ifdef UNICODE
+   free(command);
+#endif
    return iError;
 }
index 7643a57..c59ff69 100644 (file)
@@ -96,7 +96,7 @@ int main(int argc, char *argv[])
    RSA *pServerKey = NULL;
        uuid_t guid;
 
-   InitThreadLibrary();
+   InitNetXMSProcess();
 
    GetNetXMSDirectory(nxDirData, szKeyFile);
    _tcscat(szKeyFile, DFILE_KEYS);
index e6948d8..1794825 100644 (file)
@@ -553,7 +553,7 @@ int main(int argc, char *argv[])
    bool replaceValue = true;
    int ch;
 
-   InitThreadLibrary();
+   InitNetXMSProcess();
 
    TCHAR configFile[MAX_PATH] = _T("");
 
index 1454597..3a93b81 100644 (file)
@@ -280,7 +280,7 @@ int main(int argc, char *argv[])
        WCHAR *wcValue;
 #endif
 
-   InitThreadLibrary();
+   InitNetXMSProcess();
 #ifdef _WIN32
        SetExceptionHandler(SEHDefaultConsoleHandler, NULL, NULL, _T("nxget"), 0, FALSE, FALSE);
 #endif
index 0d7f024..fc219b0 100644 (file)
@@ -135,7 +135,7 @@ int main(int argc, char *argv[])
    RSA *pServerKey = NULL;
    NXCPCompressionMethod compression = NXCP_COMPRESSION_NONE;
 
-   InitThreadLibrary();
+   InitNetXMSProcess();
 
    GetNetXMSDirectory(nxDirData, szKeyFile);
    _tcscat(szKeyFile, DFILE_KEYS);
index 61154dd..9747ecc 100644 (file)
@@ -169,8 +169,10 @@ int main(int argc, char *argv[])
    DWORD dwFlags = 0, dwRet;
    int i, ch, rc = 0;
 
+   InitNetXMSProcess();
+
    _tprintf(_T("NetXMS MIB Compiler  Version ") NETXMS_VERSION_STRING _T("\n")
-            _T("Copyright (c) 2005-2013 Victor Kirhenshtein\n\n"));
+            _T("Copyright (c) 2005-2016 Raden Solutions\n\n"));
 
    // Parse command line
    opterr = 1;
index 5d56ab8..c60a3da 100644 (file)
@@ -150,6 +150,8 @@ int main(int argc, char *argv[])
    char *eptr;
    BOOL bStart = TRUE;
 
+   InitNetXMSProcess();
+
    // Parse command line
    opterr = 1;
        while((ch = getopt(argc, argv, "a:A:c:e:E:hp:u:v:w:")) != -1)
index 89bcc03..03c2e57 100644 (file)
@@ -129,6 +129,8 @@ int main(int argc, char *argv[])
    char *eptr;
    BOOL bStart = TRUE;
 
+   InitNetXMSProcess();
+
    // Parse command line
    opterr = 1;
        while((ch = getopt(argc, argv, "a:A:c:e:E:hp:t:u:v:w:")) != -1)
index 3757537..2ade0df 100644 (file)
@@ -177,6 +177,8 @@ int main(int argc, char *argv[])
    char *eptr;
    BOOL bStart = TRUE;
 
+   InitNetXMSProcess();
+
    // Parse command line
    opterr = 1;
        while((ch = getopt(argc, argv, "a:A:c:e:E:hn:p:u:v:w:")) != -1)
index 8ddf700..50d3287 100644 (file)
@@ -129,6 +129,8 @@ int main(int argc, char *argv[])
 #endif
        int ch;
 
+   InitNetXMSProcess();
+
        if (argc < 2)
        {
                ShowHelp();
index f0a69d7..0a30eeb 100644 (file)
@@ -35,6 +35,8 @@ int main(int argc, char *argv[])
    bool isAgentSecret = false;
    bool decrypt = false;
 
+   InitNetXMSProcess();
+
    // Parse command line
    opterr = 1;
    while((ch = getopt(argc, argv, "hK:vaz")) != -1)
index 8886c8d..1cb1cb0 100644 (file)
@@ -30,6 +30,8 @@ int main(int argc, char *argv[])
 {
        int ch;
 
+   InitNetXMSProcess();
+
    // Parse command line
    opterr = 1;
    while((ch = getopt(argc, argv, "hK:va")) != -1)