Most of the server code made UNICODe compatible (does not compile yet!!!)
authorVictor Kirhenshtein <victor@netxms.org>
Mon, 13 Dec 2010 08:02:15 +0000 (08:02 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Mon, 13 Dec 2010 08:02:15 +0000 (08:02 +0000)
91 files changed:
.gitattributes
doc/internal/db_driver_api.txt [new file with mode: 0644]
include/dbdrv.h
include/nms_common.h
include/nms_util.h
include/nxcpapi.h
include/nxdbapi.h
include/unicode.h
netxms.sln
src/db/dbdrv/pgsql/pgsql.cpp
src/db/libnxdb/drivers.cpp
src/db/libnxdb/libnxdb.h
src/db/libnxdb/session.cpp
src/libnetxms/message.cpp
src/libnetxms/tools.cpp
src/libnetxms/unicode.cpp
src/libnxmap/libnxmapw.vcproj
src/server/core/acl.cpp
src/server/core/actions.cpp
src/server/core/admin.cpp
src/server/core/agent.cpp
src/server/core/agent_policy.cpp
src/server/core/alarm.cpp
src/server/core/audit.cpp
src/server/core/cert.cpp
src/server/core/client.cpp
src/server/core/cluster.cpp
src/server/core/condition.cpp
src/server/core/config.cpp
src/server/core/container.cpp
src/server/core/datacoll.cpp
src/server/core/dbwrite.cpp
src/server/core/dcitem.cpp
src/server/core/dcithreshold.cpp
src/server/core/dcivalue.cpp
src/server/core/debug.cpp
src/server/core/email.cpp
src/server/core/entirenet.cpp
src/server/core/epp.cpp
src/server/core/events.cpp
src/server/core/evproc.cpp
src/server/core/hk.cpp
src/server/core/id.cpp
src/server/core/interface.cpp
src/server/core/isc.cpp
src/server/core/layer2.cpp
src/server/core/locks.cpp
src/server/core/logs.cpp
src/server/core/main.cpp
src/server/core/map.cpp
src/server/core/netinfo.cpp
src/server/core/netmap.cpp
src/server/core/netobj.cpp
src/server/core/netsrv.cpp
src/server/core/node.cpp
src/server/core/np.cpp
src/server/core/nxcore.vcproj
src/server/core/nxsl_classes.cpp
src/server/core/nxslext.cpp
src/server/core/objects.cpp
src/server/core/objtools.cpp
src/server/core/package.cpp
src/server/core/poll.cpp
src/server/core/radius.cpp
src/server/core/rootobj.cpp
src/server/core/script.cpp
src/server/core/session.cpp
src/server/core/situation.cpp
src/server/core/sms.cpp
src/server/core/snmp.cpp
src/server/core/snmptrap.cpp
src/server/core/subnet.cpp
src/server/core/syncer.cpp
src/server/core/syslogd.cpp
src/server/core/template.cpp
src/server/core/tools.cpp
src/server/core/uniroot.cpp
src/server/core/userdb.cpp
src/server/core/userdb_objects.cpp
src/server/core/vpnconn.cpp
src/server/core/watchdog.cpp
src/server/core/zone.cpp
src/server/include/nms_actions.h
src/server/include/nms_alarm.h
src/server/include/nms_core.h
src/server/include/nms_dcoll.h
src/server/include/nms_events.h
src/server/include/nms_locks.h
src/server/include/nms_objects.h
src/server/tools/nxdbmgr/nxdbmgr.cpp
src/server/tools/nxdbmgr/reindex.cpp

index 01cd484..389beb8 100644 (file)
@@ -8,6 +8,7 @@ contrib/startup/debian/nxhttpd.in -text
 doc/RadenSolutions.xml -text
 doc/comparison_netxms_nnm.doc -text
 doc/internal/build.w64 -text
+doc/internal/db_driver_api.txt -text
 doc/internal/dci_perftab.txt -text
 doc/internal/netxms_architecture.vsd -text
 doc/manuals/client_library.doc -text
diff --git a/doc/internal/db_driver_api.txt b/doc/internal/db_driver_api.txt
new file mode 100644 (file)
index 0000000..2881308
--- /dev/null
@@ -0,0 +1,46 @@
+BOOL DrvInit(const char *);\r
+\r
+DBDRV_CONNECTION DrvConnect(const char *, const char *, const char *, const char *);\r
+\r
+void DrvDisconnect(DBDRV_CONNECTION);\r
+\r
+DWORD DrvQuery(DBDRV_CONNECTION, const WCHAR *, WCHAR *);\r
+\r
+DBDRV_RESULT DrvSelect(DBDRV_CONNECTION, const WCHAR *, DWORD *, WCHAR *);\r
+\r
+DBDRV_ASYNC_RESULT DrvAsyncSelect(DBDRV_CONNECTION, const WCHAR *, DWORD *, WCHAR *);\r
+\r
+BOOL DrvFetch(DBDRV_ASYNC_RESULT);\r
+\r
+LONG DrvGetFieldLength(DBDRV_RESULT, int, int);\r
+\r
+LONG DrvGetFieldLengthAsync(DBDRV_RESULT, int);\r
+\r
+WCHAR* DrvGetField(DBDRV_RESULT, int, int, WCHAR *, int);\r
+\r
+WCHAR* DrvGetFieldAsync(DBDRV_ASYNC_RESULT, int, WCHAR *, int);\r
+\r
+int DrvGetNumRows(DBDRV_RESULT);\r
+\r
+int DrvGetColumnCount(DBDRV_RESULT);\r
+\r
+const char* DrvGetColumnName(DBDRV_RESULT, int);\r
+\r
+int DrvGetColumnCountAsync(DBDRV_ASYNC_RESULT);\r
+\r
+const char* DrvGetColumnNameAsync(DBDRV_ASYNC_RESULT, int);\r
+\r
+void DrvFreeResult(DBDRV_RESULT);\r
+\r
+void DrvFreeAsyncResult(DBDRV_ASYNC_RESULT);\r
+\r
+DWORD DrvBegin(DBDRV_CONNECTION);\r
+\r
+DWORD DrvCommit(DBDRV_CONNECTION);\r
+\r
+DWORD DrvRollback(DBDRV_CONNECTION);\r
+\r
+void DrvUnload(void);\r
+\r
+WCHAR *DrvPrepareStringW(const WCHAR *);\r
+char *DrvPrepareStringA(const char *);\r
index c085420..f1817c5 100644 (file)
@@ -30,7 +30,7 @@
 // API version
 //
 
-#define DBDRV_API_VERSION           8
+#define DBDRV_API_VERSION           9
 
 
 //
index d591b77..f4ef43d 100644 (file)
@@ -278,7 +278,7 @@ typedef unsigned __int64 uint64_t;
 #define malloc(n)       HeapAlloc(GetProcessHeap(), 0, n)
 #define realloc(p, n)   (((p) == NULL) ? HeapAlloc(GetProcessHeap(), 0, n) : HeapReAlloc(GetProcessHeap(), 0, p, n))
 #define free(p)         HeapFree(GetProcessHeap(), 0, p)
-#define strdup(s)       nx_strdup(s)
+#define _tcsdup(s)       nx__tcsdup(s)
 #define wcsdup(s)       nx_wcsdup(s)
 
 #undef _tcsdup
@@ -891,7 +891,7 @@ typedef struct tagICMPHDR
 
 
 //
-// Define stricmp() for non-windows
+// Define _tcsicmp() for non-windows
 //
 
 #ifndef _WIN32
index 0f76804..9633d92 100644 (file)
 
 
 //
-// strdup() replacement
+// _tcsdup() replacement
 //
 
 #if defined(_WIN32) && defined(USE_WIN32_HEAP)
 #ifdef __cplusplus
 extern "C" {
 #endif
-char LIBNETXMS_EXPORTABLE *nx_strdup(const char *src);
+char LIBNETXMS_EXPORTABLE *nx__tcsdup(const char *src);
 WCHAR LIBNETXMS_EXPORTABLE *nx_wcsdup(const WCHAR *src);
 #ifdef __cplusplus
 }
@@ -539,10 +539,17 @@ extern "C"
    void LIBNETXMS_EXPORTABLE Trim(TCHAR *str);
    BOOL LIBNETXMS_EXPORTABLE MatchString(const TCHAR *pattern, const TCHAR *string, BOOL matchCase);
        BOOL LIBNETXMS_EXPORTABLE RegexpMatch(const TCHAR *pszStr, const TCHAR *pszExpr, BOOL bMatchCase);
-   TCHAR LIBNETXMS_EXPORTABLE *ExtractWord(TCHAR *line, TCHAR *buffer);
+   const TCHAR LIBNETXMS_EXPORTABLE *ExtractWord(const TCHAR *line, TCHAR *buffer);
        TCHAR LIBNETXMS_EXPORTABLE **SplitString(const TCHAR *source, TCHAR sep, int *numStrings);
    int LIBNETXMS_EXPORTABLE NumChars(const TCHAR *pszStr, int ch);
-       void LIBNETXMS_EXPORTABLE RemoveTrailingCRLF(TCHAR *str);
+       void LIBNETXMS_EXPORTABLE RemoveTrailingCRLFA(char *str);
+       void LIBNETXMS_EXPORTABLE RemoveTrailingCRLFW(WCHAR *str);
+#ifdef UNICODE
+#define RemoveTrailingCRLF RemoveTrailingCRLFW
+#else
+#define RemoveTrailingCRLF RemoveTrailingCRLFA
+#endif
+
 #ifdef __cplusplus
    BOOL LIBNETXMS_EXPORTABLE IsValidObjectName(const TCHAR *pszName, BOOL bExtendedChars = FALSE);
 #endif
@@ -633,7 +640,7 @@ extern "C"
        UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strncpy(UCS2CHAR *pDst, const UCS2CHAR *pSrc, int nDstLen);
 #endif
 #if !defined(UNICODE_UCS2) || !HAVE_WCSDUP
-       UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strdup(const UCS2CHAR *pStr);
+       UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2__tcsdup(const UCS2CHAR *pStr);
 #endif
 
 #ifndef UNICODE
index d4ec641..05046cb 100644 (file)
@@ -92,6 +92,11 @@ public:
    void SetVariable(DWORD dwVarId, double dValue) { Set(dwVarId, CSCP_DT_FLOAT, &dValue); }
    void SetVariable(DWORD dwVarId, const TCHAR *pszValue) { Set(dwVarId, CSCP_DT_STRING, pszValue); }
    void SetVariable(DWORD dwVarId, BYTE *pValue, DWORD dwSize) { Set(dwVarId, CSCP_DT_BINARY, pValue, dwSize); }
+#ifdef UNICODE
+   void SetVariableFromMBString(DWORD dwVarId, const char *pszValue);
+#else
+   void SetVariableFromMBString(DWORD dwVarId, const char *pszValue) { Set(dwVarId, CSCP_DT_STRING, pszValue); }
+#endif
    void SetVariableToInt32Array(DWORD dwVarId, DWORD dwNumElements, DWORD *pdwData);
    BOOL SetVariableFromFile(DWORD dwVarId, const TCHAR *pszFileName);
 
@@ -101,6 +106,8 @@ public:
    LONG GetVariableShortAsInt32(DWORD dwVarId);
    double GetVariableDouble(DWORD dwVarId);
    TCHAR *GetVariableStr(DWORD dwVarId, TCHAR *szBuffer = NULL, DWORD dwBufSize = 0);
+       char *GetVariableStrA(DWORD dwVarId, char *pszBuffer = NULL, DWORD dwBufSize = 0);
+       char *GetVariableStrUTF8(DWORD dwVarId, char *pszBuffer = NULL, DWORD dwBufSize = 0);
    DWORD GetVariableBinary(DWORD dwVarId, BYTE *pBuffer, DWORD dwBufSize);
    DWORD GetVariableInt32Array(DWORD dwVarId, DWORD dwNumElements, DWORD *pdwBuffer);
 
index 35484f2..9d8e222 100644 (file)
@@ -92,7 +92,7 @@ typedef db_async_result_t * DB_ASYNC_RESULT;
 \r
 bool LIBNXDB_EXPORTABLE DBInit(DWORD logMsgCode, DWORD sqlErrorMsgCode);\r
 DB_DRIVER LIBNXDB_EXPORTABLE DBLoadDriver(const TCHAR *module, const TCHAR *initParameters,\r
-                                                                                                               bool dumpSQL, void (* fpEventHandler)(DWORD, const TCHAR *, const TCHAR *, void *),\r
+                                                                                                               bool dumpSQL, void (* fpEventHandler)(DWORD, const WCHAR *, const WCHAR *, void *),\r
                                                                                                                void *userArg);\r
 void LIBNXDB_EXPORTABLE DBUnloadDriver(DB_DRIVER driver);\r
 \r
@@ -112,6 +112,8 @@ int LIBNXDB_EXPORTABLE DBGetColumnCountAsync(DB_ASYNC_RESULT hResult);
 BOOL LIBNXDB_EXPORTABLE DBGetColumnNameAsync(DB_ASYNC_RESULT hResult, int column, TCHAR *buffer, int bufSize);\r
 TCHAR LIBNXDB_EXPORTABLE *DBGetField(DB_RESULT hResult, int iRow, int iColumn,\r
                                       TCHAR *pszBuffer, int nBufLen);\r
+char LIBNXDB_EXPORTABLE *DBGetFieldA(DB_RESULT hResult, int iRow, int iColumn,\r
+                                      char *pszBuffer, int nBufLen);\r
 LONG LIBNXDB_EXPORTABLE DBGetFieldLong(DB_RESULT hResult, int iRow, int iColumn);\r
 DWORD LIBNXDB_EXPORTABLE DBGetFieldULong(DB_RESULT hResult, int iRow, int iColumn);\r
 INT64 LIBNXDB_EXPORTABLE DBGetFieldInt64(DB_RESULT hResult, int iRow, int iColumn);\r
@@ -140,6 +142,11 @@ int LIBNXDB_EXPORTABLE DBGetSchemaVersion(DB_HANDLE conn);
 int LIBNXDB_EXPORTABLE DBGetSyntax(DB_HANDLE conn);\r
 \r
 String LIBNXDB_EXPORTABLE DBPrepareString(DB_HANDLE conn, const TCHAR *str, int maxSize = -1);\r
+#ifdef UNICODE\r
+String LIBNXDB_EXPORTABLE DBPrepareStringA(DB_HANDLE conn, const char *str, int maxSize = -1);\r
+#else\r
+#define DBPrepareStringA DBPrepareString\r
+#endif\r
 TCHAR LIBNXDB_EXPORTABLE *EncodeSQLString(const TCHAR *pszIn);\r
 void LIBNXDB_EXPORTABLE DecodeSQLString(TCHAR *pszStr);\r
 \r
index 677e1d9..84d7937 100644 (file)
@@ -51,6 +51,9 @@
 // Windows always use UCS-2
 #define UNICODE_UCS2                           1
 
+#define ICONV_DEFAULT_CODEPAGE_A    "ACP"
+#define ICONV_DEFAULT_CODEPAGE_W    L"ACP"
+
 #ifdef UNICODE
 
 #define _tcstoll  wcstoll
 
 #define _ERR_error_tstring             ERR_error_string_W
 
-#else
+#define ICONV_DEFAULT_CODEPAGE      ICONV_DEFAULT_CODEPAGE_W
+
+#else  /* !UNICODE */
 
 #define _tcstoll  strtoll
 #define _tcstoull strtoull
 
 #define _ERR_error_tstring             ERR_error_string
 
-#endif
+#define ICONV_DEFAULT_CODEPAGE      ICONV_DEFAULT_CODEPAGE_A
 
-#define ICONV_DEFAULT_CODEPAGE "ACP"
+#endif /* UNICODE */
 
 #define ucs2_strlen    wcslen
 #define ucs2_strdup    wcsdup
index 5eda895..8e9a02b 100644 (file)
@@ -5,27 +5,27 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libexpat", "src\libexpat\li
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnetxms", "src\libnetxms\libnetxms.vcproj", "{B1745870-F3ED-4ACB-B813-0C4F47EF0793}"
        ProjectSection(ProjectDependencies) = postProject
-               {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
                {6A88EF62-C4F2-4295-A833-549DAE4DF5ED} = {6A88EF62-C4F2-4295-A833-549DAE4DF5ED}
+               {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnetxmsw", "src\libnetxms\libnetxmsw.vcproj", "{AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}"
        ProjectSection(ProjectDependencies) = postProject
-               {6A88EF62-C4F2-4295-A833-549DAE4DF5ED} = {6A88EF62-C4F2-4295-A833-549DAE4DF5ED}
                {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
+               {6A88EF62-C4F2-4295-A833-549DAE4DF5ED} = {6A88EF62-C4F2-4295-A833-549DAE4DF5ED}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxlp", "src\libnxlp\libnxlp.vcproj", "{64EFC0C2-C67B-41F6-851D-F11DAB27A60B}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
-               {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
                {6A88EF62-C4F2-4295-A833-549DAE4DF5ED} = {6A88EF62-C4F2-4295-A833-549DAE4DF5ED}
+               {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 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}
                {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
+               {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}"
@@ -65,8 +65,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sms", "src\agent\subagents\
 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}
+               {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}"
@@ -81,8 +81,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "odbcquery", "src\agent\suba
 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}
+               {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}"
@@ -104,124 +104,124 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxmapw", "src\libnxmap\l
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxcl", "src\libnxcl\libnxcl.vcproj", "{3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}"
        ProjectSection(ProjectDependencies) = postProject
-               {AB386821-B630-49F5-95C3-677B9DCE1270} = {AB386821-B630-49F5-95C3-677B9DCE1270}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {AB386821-B630-49F5-95C3-677B9DCE1270} = {AB386821-B630-49F5-95C3-677B9DCE1270}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxclw", "src\libnxcl\libnxclw.vcproj", "{3CB9B8C6-E6BF-4002-A61A-7A21FEADB532}"
        ProjectSection(ProjectDependencies) = postProject
-               {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
                {0A5E80F3-485D-40C8-BE1E-9D7EE744DB8B} = {0A5E80F3-485D-40C8-BE1E-9D7EE744DB8B}
+               {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{39BF23C9-D903-4C20-8E88-19533A745625}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxalarm", "src\client\nxalarm\nxalarm.vcproj", "{F9FFAAE9-D669-451E-B9EF-18BC8AD37FAB}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxevent", "src\client\nxevent\nxevent.vcproj", "{C7A460E8-12A8-4FC7-9F59-C9C5CE17ED20}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxpush", "src\client\nxpush\nxpush.vcproj", "{B8671BF7-94E1-4615-A8C2-F5C78DB8C515}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxsms", "src\client\nxsms\nxsms.vcproj", "{B0A70A32-A8F0-4071-8044-FDA3C834A5C5}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxsnmp", "src\snmp\libnxsnmp\libnxsnmp.vcproj", "{7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {E7410EB4-3355-4C83-8E05-D2877581CDA1} = {E7410EB4-3355-4C83-8E05-D2877581CDA1}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxzlib", "src\zlib\nxzlib.vcproj", "{E7410EB4-3355-4C83-8E05-D2877581CDA1}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxsnmpget", "src\snmp\nxsnmpget\nxsnmpget.vcproj", "{0A4CE471-020A-42C6-91C0-DFEFA7E815E0}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxsnmpw", "src\snmp\libnxsnmp\libnxsnmpw.vcproj", "{7DC90EE4-E31C-4F12-8F1E-81F10E9099FC}"
        ProjectSection(ProjectDependencies) = postProject
-               {E7410EB4-3355-4C83-8E05-D2877581CDA1} = {E7410EB4-3355-4C83-8E05-D2877581CDA1}
                {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
+               {E7410EB4-3355-4C83-8E05-D2877581CDA1} = {E7410EB4-3355-4C83-8E05-D2877581CDA1}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxsnmpset", "src\snmp\nxsnmpset\nxsnmpset.vcproj", "{9EA98E79-EB7D-4F6C-8105-AC7B231ABB10}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxsnmpwalk", "src\snmp\nxsnmpwalk\nxsnmpwalk.vcproj", "{5FA3AADC-3AD7-4B17-A581-D5E02DE17727}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxmibc", "src\snmp\nxmibc\nxmibc.vcproj", "{9F722C62-78FD-4D8C-A7C7-2815B09F1943}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxsrv", "src\server\libnxsrv\libnxsrv.vcproj", "{CB89D905-C8BE-4027-B2D8-F96C245E9160}"
        ProjectSection(ProjectDependencies) = postProject
-               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FC} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FC}
                {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
+               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FC} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FC}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxcore", "src\server\core\nxcore.vcproj", "{3B172035-5EEC-45A3-8471-2C390B7ED683}"
        ProjectSection(ProjectDependencies) = postProject
-               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
-               {B2988503-1921-4B9F-BBC1-5E5CF62F335E} = {B2988503-1921-4B9F-BBC1-5E5CF62F335E}
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
-               {AB386821-B630-49F5-95C3-677B9DCE1270} = {AB386821-B630-49F5-95C3-677B9DCE1270}
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FC} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FC}
+               {0A5E80F3-485D-40C8-BE1E-9D7EE744DB8B} = {0A5E80F3-485D-40C8-BE1E-9D7EE744DB8B}
+               {96EF0643-89FD-47CD-B82E-9F7D1DAF35EC} = {96EF0643-89FD-47CD-B82E-9F7D1DAF35EC}
+               {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
                {64EFC0C2-C67B-41F6-851D-F11DAB27A60B} = {64EFC0C2-C67B-41F6-851D-F11DAB27A60B}
-               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
+               {B2988503-1921-4B9F-BBC1-5E5CF62F335E} = {B2988503-1921-4B9F-BBC1-5E5CF62F335E}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nxsl", "nxsl", "{CE0DA89E-CF0C-452C-9C33-75A143355BDC}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxsl", "src\libnxsl\libnxsl.vcproj", "{B2988503-1921-4B9F-BBC1-5E5CF62F335E}"
        ProjectSection(ProjectDependencies) = postProject
-               {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
                {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
+               {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxscript", "src\nxscript\nxscript.vcproj", "{BA263F92-D5A9-4F26-9606-5A1C1495FEA5}"
        ProjectSection(ProjectDependencies) = postProject
-               {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
                {B2988503-1921-4B9F-BBC1-5E5CF62F335E} = {B2988503-1921-4B9F-BBC1-5E5CF62F335E}
+               {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "netxmsd", "src\server\netxmsd\netxmsd.vcproj", "{E417A0C4-41F1-4F87-8C33-8526ECB1F8AF}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
-               {3B172035-5EEC-45A3-8471-2C390B7ED683} = {3B172035-5EEC-45A3-8471-2C390B7ED683}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {3B172035-5EEC-45A3-8471-2C390B7ED683} = {3B172035-5EEC-45A3-8471-2C390B7ED683}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{64482674-7B36-4A14-A612-247333174315}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxaction", "src\server\tools\nxaction\nxaction.vcproj", "{BF5CE6BA-C84A-4448-B1B7-1B355AC77D12}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxadm", "src\server\tools\nxadm\nxadm.vcproj", "{67E35735-2115-45FF-9E93-EE67AF5C9C2C}"
@@ -231,31 +231,31 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxadm", "src\server\tools\n
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxget", "src\server\tools\nxget\nxget.vcproj", "{1AC3C8D1-E309-4327-9E17-0E4CE0FC68CF}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxupload", "src\server\tools\nxupload\nxupload.vcproj", "{DA863269-ED58-4910-AA6A-2572A3EE745D}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxdbmgr", "src\server\tools\nxdbmgr\nxdbmgr.vcproj", "{4940613E-A11C-4259-95C8-8D23217EE60E}"
        ProjectSection(ProjectDependencies) = postProject
-               {96EF0643-89FD-47CD-B82E-9F7D1DAF35EC} = {96EF0643-89FD-47CD-B82E-9F7D1DAF35EC}
-               {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
-               {87CAA25D-991E-45E1-BB69-337D45121F19} = {87CAA25D-991E-45E1-BB69-337D45121F19}
                {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
+               {87CAA25D-991E-45E1-BB69-337D45121F19} = {87CAA25D-991E-45E1-BB69-337D45121F19}
+               {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
+               {96EF0643-89FD-47CD-B82E-9F7D1DAF35EC} = {96EF0643-89FD-47CD-B82E-9F7D1DAF35EC}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "webui", "webui", "{7C6B32C4-53F9-4378-903E-1DA05748376B}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxhttpd", "src\webui\nxhttpd\nxhttpd.vcproj", "{AC0CB89C-E27A-43FA-A049-1FF4B2FE2121}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
-               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
                {F5287CFB-0894-4169-B5B5-1AEE4F2FF585} = {F5287CFB-0894-4169-B5B5-1AEE4F2FF585}
+               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libpng", "src\webui\libgd\libpng\libpng.vcproj", "{E9F4A68D-4BF2-45AD-BDD6-210AFF857661}"
@@ -271,67 +271,67 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "smsdrv", "smsdrv", "{5818CC
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "generic", "src\server\smsdrv\generic\generic.vcproj", "{41A5009F-4467-4D89-A171-5A919FEFE16E}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxagent", "src\server\smsdrv\nxagent\nxagent.vcproj", "{C317231C-B984-4423-ACF2-C19DE8B6AA3F}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libgd", "src\webui\libgd\gd\libgd.vcproj", "{F5287CFB-0894-4169-B5B5-1AEE4F2FF585}"
        ProjectSection(ProjectDependencies) = postProject
-               {55B7161B-683F-4E7A-96F6-277A1681D6C5} = {55B7161B-683F-4E7A-96F6-277A1681D6C5}
-               {E9F4A68D-4BF2-45AD-BDD6-210AFF857661} = {E9F4A68D-4BF2-45AD-BDD6-210AFF857661}
-               {E7410EB4-3355-4C83-8E05-D2877581CDA1} = {E7410EB4-3355-4C83-8E05-D2877581CDA1}
                {0D98A1CD-48E0-4F11-9151-B53497E1F7DA} = {0D98A1CD-48E0-4F11-9151-B53497E1F7DA}
+               {E7410EB4-3355-4C83-8E05-D2877581CDA1} = {E7410EB4-3355-4C83-8E05-D2877581CDA1}
+               {E9F4A68D-4BF2-45AD-BDD6-210AFF857661} = {E9F4A68D-4BF2-45AD-BDD6-210AFF857661}
+               {55B7161B-683F-4E7A-96F6-277A1681D6C5} = {55B7161B-683F-4E7A-96F6-277A1681D6C5}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "windows", "windows", "{69EC5B74-D466-422E-B8D1-1386B0421D54}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxlexer", "src\client\nxlexer\nxlexer.vcproj", "{F0FAC738-1BC6-46A5-A54A-8D7F2219302D}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {8E5A517B-93AB-4EA8-BB53-AE6346756343} = {8E5A517B-93AB-4EA8-BB53-AE6346756343}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scilexer", "src\client\scilexer\scilexer.vcproj", "{8E5A517B-93AB-4EA8-BB53-AE6346756343}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxuilib", "src\client\windows\nxuilib\nxuilib.vcproj", "{BECC966D-AFC8-48F6-97B1-2FE92062D7B4}"
        ProjectSection(ProjectDependencies) = postProject
-               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532}
                {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
+               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxav", "src\client\windows\nxav\nxav.vcproj", "{23F22F68-D562-4E80-8267-9F1DD9398357}"
        ProjectSection(ProjectDependencies) = postProject
-               {BECC966D-AFC8-48F6-97B1-2FE92062D7B4} = {BECC966D-AFC8-48F6-97B1-2FE92062D7B4}
-               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532}
                {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
+               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532}
+               {BECC966D-AFC8-48F6-97B1-2FE92062D7B4} = {BECC966D-AFC8-48F6-97B1-2FE92062D7B4}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxnotify", "src\client\windows\nxnotify\nxnotify.vcproj", "{169A4446-A035-4CF7-8377-3C517ADF0C50}"
        ProjectSection(ProjectDependencies) = postProject
-               {BECC966D-AFC8-48F6-97B1-2FE92062D7B4} = {BECC966D-AFC8-48F6-97B1-2FE92062D7B4}
-               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532}
                {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
+               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532}
+               {BECC966D-AFC8-48F6-97B1-2FE92062D7B4} = {BECC966D-AFC8-48F6-97B1-2FE92062D7B4}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxcon", "src\client\windows\nxcon\nxcon.vcproj", "{956DD617-0939-4B25-B8D0-E10AA645064E}"
        ProjectSection(ProjectDependencies) = postProject
-               {BECC966D-AFC8-48F6-97B1-2FE92062D7B4} = {BECC966D-AFC8-48F6-97B1-2FE92062D7B4}
-               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532}
-               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FC} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FC}
-               {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
                {0A5E80F3-485D-40C8-BE1E-9D7EE744DB8B} = {0A5E80F3-485D-40C8-BE1E-9D7EE744DB8B}
+               {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA} = {AEB182ED-7F5C-4F5A-BCE1-9A38E98579BA}
+               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FC} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FC}
+               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB532}
+               {BECC966D-AFC8-48F6-97B1-2FE92062D7B4} = {BECC966D-AFC8-48F6-97B1-2FE92062D7B4}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxlptest", "src\nxlptest\nxlptest.vcproj", "{1EA79FC6-F395-43DF-9E3C-2030CA05ED1D}"
        ProjectSection(ProjectDependencies) = postProject
-               {64EFC0C2-C67B-41F6-851D-F11DAB27A60B} = {64EFC0C2-C67B-41F6-851D-F11DAB27A60B}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {64EFC0C2-C67B-41F6-851D-F11DAB27A60B} = {64EFC0C2-C67B-41F6-851D-F11DAB27A60B}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxsqlite", "src\sqlite\nxsqlite.vcproj", "{87CAA25D-991E-45E1-BB69-337D45121F19}"
@@ -382,14 +382,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pgsql", "src\db\dbdrv\pgsql
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sqlite", "src\db\dbdrv\sqlite\sqlite.vcproj", "{AA18FD4D-7B01-4932-BA04-B0F54F001F66}"
        ProjectSection(ProjectDependencies) = postProject
-               {87CAA25D-991E-45E1-BB69-337D45121F19} = {87CAA25D-991E-45E1-BB69-337D45121F19}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {87CAA25D-991E-45E1-BB69-337D45121F19} = {87CAA25D-991E-45E1-BB69-337D45121F19}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxconfig", "src\server\tools\nxconfig\nxconfig.vcproj", "{A76CCCF5-D70B-4307-B84C-219289CEAA6D}"
        ProjectSection(ProjectDependencies) = postProject
-               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxcptest", "src\tools\nxcptest\nxcptest.vcproj", "{418E47B0-3E78-4820-A101-CA9C4439F9AB}"
@@ -406,9 +406,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libipfix", "src\flow_analyz
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxflowd", "src\flow_analyzer\nxflowd\nxflowd.vcproj", "{D7F709ED-7483-49F0-8B17-ABB705606FEA}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
-               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
                {2DEF303B-5FEF-4F5E-87C4-FB7895058F59} = {2DEF303B-5FEF-4F5E-87C4-FB7895058F59}
+               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "db2", "src\db\dbdrv\db2\db2.vcproj", "{297D9A45-B928-4470-91B5-0E07A20C2405}"
@@ -418,8 +418,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "db2", "src\db\dbdrv\db2\db2
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxap", "src\server\tools\nxap\nxap.vcproj", "{36749C31-C8C6-4DD2-A11C-E41ED86927C7}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtre", "src\libtre\libtre.vcproj", "{406AE5C7-343D-4C88-B8F3-84E46255B830}"
index fb3a308..f7112d5 100644 (file)
@@ -1,7 +1,6 @@
-/* $Id$ */
 /* 
 ** PostgreSQL Database Driver
-** Copyright (C) 2003 - 2008 Victor Kirhenshtein and Alex Kirhenshtein
+** Copyright (C) 2003 - 2010 Victor Kirhenshtein and Alex 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
@@ -40,64 +39,119 @@ extern "C" const char EXPORT *drvName = "PGSQL";
 // Prepare string for using in SQL query - enclose in quotes and escape as needed
 //
 
-extern "C" TCHAR EXPORT *DrvPrepareString(const TCHAR *str)
+extern "C" WCHAR EXPORT *DrvPrepareStringW(const WCHAR *str)
 {
-       int len = (int)_tcslen(str) + 3;   // + two quotes and \0 at the end
+       int len = (int)wcslen(str) + 3;   // + two quotes and \0 at the end
        int bufferSize = len + 128;
-       TCHAR *out = (TCHAR *)malloc(bufferSize * sizeof(TCHAR));
-       out[0] = _T('\'');
+       WCHAR *out = (WCHAR *)malloc(bufferSize * sizeof(WCHAR));
+       out[0] = L'\'';
 
-       const TCHAR *src = str;
+       const WCHAR *src = str;
        int outPos;
        for(outPos = 1; *src != NULL; src++)
        {
-#ifdef UNICODE
                long chval = *src;
-#else
+               if (chval < 32)
+               {
+                       WCHAR buffer[8];
+
+                       snwprintf(buffer, 8, L"\\%03o", chval);
+                       len += 4;
+                       if (len >= bufferSize)
+                       {
+                               bufferSize += 128;
+                               out = (WCHAR *)realloc(out, bufferSize * sizeof(WCHAR));
+                       }
+                       memcpy(&out[outPos], buffer, 4 * sizeof(WCHAR));
+                       outPos += 4;
+               }
+               else if (*src == L'\'')
+               {
+                       len++;
+                       if (len >= bufferSize)
+                       {
+                               bufferSize += 128;
+                               out = (WCHAR *)realloc(out, bufferSize * sizeof(WCHAR));
+                       }
+                       out[outPos++] = L'\'';
+                       out[outPos++] = L'\'';
+               }
+               else if (*src == L'\\')
+               {
+                       len++;
+                       if (len >= bufferSize)
+                       {
+                               bufferSize += 128;
+                               out = (WCHAR *)realloc(out, bufferSize * sizeof(WCHAR));
+                       }
+                       out[outPos++] = L'\\';
+                       out[outPos++] = L'\\';
+               }
+               else
+               {
+                       out[outPos++] = *src;
+               }
+       }
+       out[outPos++] = L'\'';
+       out[outPos++] = 0;
+
+       return out;
+}
+
+extern "C" char EXPORT *DrvPrepareStringA(const char *str)
+{
+       int len = (int)_tcslen(str) + 3;   // + two quotes and \0 at the end
+       int bufferSize = len + 128;
+       char *out = (char *)malloc(bufferSize);
+       out[0] = '\'';
+
+       const char *src = str;
+       int outPos;
+       for(outPos = 1; *src != NULL; src++)
+       {
                long chval = (long)(*((unsigned char *)src));
-#endif
                if (chval < 32)
                {
                        TCHAR buffer[8];
 
-                       _sntprintf(buffer, 8, _T("\\%03o"), chval);
+                       snprintf(buffer, 8, "\\%03o", chval);
                        len += 4;
                        if (len >= bufferSize)
                        {
                                bufferSize += 128;
-                               out = (TCHAR *)realloc(out, bufferSize * sizeof(TCHAR));
+                               out = (char *)realloc(out, bufferSize);
                        }
-                       memcpy(&out[outPos], buffer, 4 * sizeof(TCHAR));
+                       memcpy(&out[outPos], buffer, 4);
                        outPos += 4;
                }
-               else if (*src == _T('\''))
+               else if (*src == '\'')
                {
                        len++;
                        if (len >= bufferSize)
                        {
                                bufferSize += 128;
-                               out = (TCHAR *)realloc(out, bufferSize * sizeof(TCHAR));
+                               out = (char *)realloc(out, bufferSize);
                        }
-                       out[outPos++] = _T('\'');
-                       out[outPos++] = _T('\'');
+                       out[outPos++] = '\'';
+                       out[outPos++] = '\'';
                }
-               else if (*src == _T('\\'))
+               else if (*src == '\\')
                {
                        len++;
                        if (len >= bufferSize)
                        {
                                bufferSize += 128;
-                               out = (TCHAR *)realloc(out, bufferSize * sizeof(TCHAR));
+                               out = (char *)realloc(out, bufferSize);
                        }
-                       out[outPos++] = _T('\\');
-                       out[outPos++] = _T('\\');
+                       out[outPos++] = '\\';
+                       out[outPos++] = '\\';
                }
                else
                {
                        out[outPos++] = *src;
                }
        }
-       out[outPos++] = _T('\'');
+       out[outPos++] = '\'';
        out[outPos++] = 0;
 
        return out;
@@ -108,7 +162,7 @@ extern "C" TCHAR EXPORT *DrvPrepareString(const TCHAR *str)
 // Initialize driver
 //
 
-extern "C" BOOL EXPORT DrvInit(const TCHAR *cmdLine)
+extern "C" BOOL EXPORT DrvInit(const char *cmdLine)
 {
        return TRUE;
 }
@@ -191,7 +245,7 @@ extern "C" void EXPORT DrvDisconnect(DBDRV_CONNECTION pConn)
 // Perform non-SELECT query
 //
 
-static BOOL UnsafeDrvQuery(PG_CONN *pConn, char *szQuery, TCHAR *errorText)
+static BOOL UnsafeDrvQuery(PG_CONN *pConn, char *szQuery, WCHAR *errorText)
 {
        PGresult        *pResult;
 
@@ -200,7 +254,7 @@ static BOOL UnsafeDrvQuery(PG_CONN *pConn, char *szQuery, TCHAR *errorText)
        if (pResult == NULL)
        {
                if (errorText != NULL)
-                       nx_strncpy(errorText, _T("Internal error (pResult is NULL in UnsafeDrvQuery)"), DBDRV_MAX_ERROR_TEXT);
+                       wcsncpy(errorText, L"Internal error (pResult is NULL in UnsafeDrvQuery)", DBDRV_MAX_ERROR_TEXT);
                return FALSE;
        }
 
@@ -208,8 +262,9 @@ static BOOL UnsafeDrvQuery(PG_CONN *pConn, char *szQuery, TCHAR *errorText)
        {
                if (errorText != NULL)
                {
-                       nx_strncpy(errorText, PQerrorMessage(pConn->pHandle), DBDRV_MAX_ERROR_TEXT);
-                       RemoveTrailingCRLF(errorText);
+                       MultiByteToWideChar(CP_UTF8, 0, PQerrorMessage(pConn->pHandle), -1, errorText, DBDRV_MAX_ERROR_TEXT);
+                       errorText[DBDRV_MAX_ERROR_TEXT - 1] = 0;
+                       RemoveTrailingCRLFW(errorText);
                }
                PQclear(pResult);
                return FALSE;
@@ -221,7 +276,7 @@ static BOOL UnsafeDrvQuery(PG_CONN *pConn, char *szQuery, TCHAR *errorText)
    return TRUE;
 }
 
-extern "C" DWORD EXPORT DrvQuery(PG_CONN *pConn, WCHAR *pwszQuery, TCHAR *errorText)
+extern "C" DWORD EXPORT DrvQuery(PG_CONN *pConn, WCHAR *pwszQuery, WCHAR *errorText)
 {
        DWORD dwRet = DBERR_INVALID_HANDLE;
    char *pszQueryUTF8;
@@ -250,7 +305,7 @@ extern "C" DWORD EXPORT DrvQuery(PG_CONN *pConn, WCHAR *pwszQuery, TCHAR *errorT
 // Perform SELECT query
 //
 
-static DBDRV_RESULT UnsafeDrvSelect(PG_CONN *pConn, char *szQuery, TCHAR *errorText)
+static DBDRV_RESULT UnsafeDrvSelect(PG_CONN *pConn, char *szQuery, WCHAR *errorText)
 {
        PGresult        *pResult;
 
@@ -259,7 +314,7 @@ static DBDRV_RESULT UnsafeDrvSelect(PG_CONN *pConn, char *szQuery, TCHAR *errorT
        if (pResult == NULL)
        {
                if (errorText != NULL)
-                       nx_strncpy(errorText, _T("Internal error (pResult is NULL in UnsafeDrvSelect)"), DBDRV_MAX_ERROR_TEXT);
+                       wcsncpy(errorText, L"Internal error (pResult is NULL in UnsafeDrvSelect)", DBDRV_MAX_ERROR_TEXT);
                return NULL;
        }
 
@@ -269,8 +324,9 @@ static DBDRV_RESULT UnsafeDrvSelect(PG_CONN *pConn, char *szQuery, TCHAR *errorT
                
                if (errorText != NULL)
                {
-                       nx_strncpy(errorText, PQerrorMessage(pConn->pHandle), DBDRV_MAX_ERROR_TEXT);
-                       RemoveTrailingCRLF(errorText);
+                       MultiByteToWideChar(CP_UTF8, 0, PQerrorMessage(pConn->pHandle), -1, errorText, DBDRV_MAX_ERROR_TEXT);
+                       errorText[DBDRV_MAX_ERROR_TEXT - 1] = 0;
+                       RemoveTrailingCRLFW(errorText);
                }
                PQclear(pResult);
                return NULL;
@@ -281,7 +337,7 @@ static DBDRV_RESULT UnsafeDrvSelect(PG_CONN *pConn, char *szQuery, TCHAR *errorT
    return (DBDRV_RESULT)pResult;
 }
 
-extern "C" DBDRV_RESULT EXPORT DrvSelect(PG_CONN *pConn, WCHAR *pwszQuery, DWORD *pdwError, TCHAR *errorText)
+extern "C" DBDRV_RESULT EXPORT DrvSelect(PG_CONN *pConn, WCHAR *pwszQuery, DWORD *pdwError, WCHAR *errorText)
 {
        DBDRV_RESULT pResult;
    char *pszQueryUTF8;
@@ -390,8 +446,7 @@ extern "C" void EXPORT DrvFreeResult(DBDRV_RESULT pResult)
 // Perform asynchronous SELECT query
 //
 
-extern "C" DBDRV_ASYNC_RESULT EXPORT DrvAsyncSelect(PG_CONN *pConn, WCHAR *pwszQuery,
-                                                 DWORD *pdwError, TCHAR *errorText)
+extern "C" DBDRV_ASYNC_RESULT EXPORT DrvAsyncSelect(PG_CONN *pConn, WCHAR *pwszQuery, DWORD *pdwError, WCHAR *errorText)
 {
        BOOL bSuccess = FALSE;
    char *pszReq, *pszQueryUTF8;
index 8dc634f..142f6c2 100644 (file)
@@ -83,11 +83,11 @@ bool LIBNXDB_EXPORTABLE DBInit(DWORD logMsgCode, DWORD sqlErrorMsgCode)
 //\r
 \r
 DB_DRIVER LIBNXDB_EXPORTABLE DBLoadDriver(const TCHAR *module, const TCHAR *initParameters,\r
-                                                                                                               bool dumpSQL, void (* fpEventHandler)(DWORD, const TCHAR *, const TCHAR *, void *),\r
+                                                                                                               bool dumpSQL, void (* fpEventHandler)(DWORD, const WCHAR *, const WCHAR *, void *),\r
                                                                                                                void *userArg)\r
 {\r
    static DWORD dwVersionZero = 0;\r
-   BOOL (* fpDrvInit)(const TCHAR *);\r
+   BOOL (* fpDrvInit)(const char *);\r
    DWORD *pdwAPIVersion;\r
    TCHAR szErrorText[256];\r
        const char *driverName;\r
@@ -162,12 +162,12 @@ DB_DRIVER LIBNXDB_EXPORTABLE DBLoadDriver(const TCHAR *module, const TCHAR *init
        }\r
 \r
    // Import symbols\r
-   fpDrvInit = (BOOL (*)(const TCHAR *))DLGetSymbolAddrEx(driver->m_handle, _T("DrvInit"));\r
+   fpDrvInit = (BOOL (*)(const char *))DLGetSymbolAddrEx(driver->m_handle, _T("DrvInit"));\r
    driver->m_fpDrvConnect = (DBDRV_CONNECTION (*)(const char *, const char *, const char *, const char *))DLGetSymbolAddrEx(driver->m_handle, _T("DrvConnect"));\r
    driver->m_fpDrvDisconnect = (void (*)(DBDRV_CONNECTION))DLGetSymbolAddrEx(driver->m_handle, _T("DrvDisconnect"));\r
-   driver->m_fpDrvQuery = (DWORD (*)(DBDRV_CONNECTION, const WCHAR *, TCHAR *))DLGetSymbolAddrEx(driver->m_handle, _T("DrvQuery"));\r
-   driver->m_fpDrvSelect = (DBDRV_RESULT (*)(DBDRV_CONNECTION, const WCHAR *, DWORD *, TCHAR *))DLGetSymbolAddrEx(driver->m_handle, _T("DrvSelect"));\r
-   driver->m_fpDrvAsyncSelect = (DBDRV_ASYNC_RESULT (*)(DBDRV_CONNECTION, const WCHAR *, DWORD *, TCHAR *))DLGetSymbolAddrEx(driver->m_handle, _T("DrvAsyncSelect"));\r
+   driver->m_fpDrvQuery = (DWORD (*)(DBDRV_CONNECTION, const WCHAR *, WCHAR *))DLGetSymbolAddrEx(driver->m_handle, _T("DrvQuery"));\r
+   driver->m_fpDrvSelect = (DBDRV_RESULT (*)(DBDRV_CONNECTION, const WCHAR *, DWORD *, WCHAR *))DLGetSymbolAddrEx(driver->m_handle, _T("DrvSelect"));\r
+   driver->m_fpDrvAsyncSelect = (DBDRV_ASYNC_RESULT (*)(DBDRV_CONNECTION, const WCHAR *, DWORD *, WCHAR *))DLGetSymbolAddrEx(driver->m_handle, _T("DrvAsyncSelect"));\r
    driver->m_fpDrvFetch = (BOOL (*)(DBDRV_ASYNC_RESULT))DLGetSymbolAddrEx(driver->m_handle, _T("DrvFetch"));\r
    driver->m_fpDrvGetFieldLength = (LONG (*)(DBDRV_RESULT, int, int))DLGetSymbolAddrEx(driver->m_handle, _T("DrvGetFieldLength"));\r
    driver->m_fpDrvGetFieldLengthAsync = (LONG (*)(DBDRV_RESULT, int))DLGetSymbolAddrEx(driver->m_handle, _T("DrvGetFieldLengthAsync"));\r
@@ -184,7 +184,8 @@ DB_DRIVER LIBNXDB_EXPORTABLE DBLoadDriver(const TCHAR *module, const TCHAR *init
    driver->m_fpDrvCommit = (DWORD (*)(DBDRV_CONNECTION))DLGetSymbolAddrEx(driver->m_handle, _T("DrvCommit"));\r
    driver->m_fpDrvRollback = (DWORD (*)(DBDRV_CONNECTION))DLGetSymbolAddrEx(driver->m_handle, _T("DrvRollback"));\r
    driver->m_fpDrvUnload = (void (*)(void))DLGetSymbolAddrEx(driver->m_handle, _T("DrvUnload"));\r
-   driver->m_fpDrvPrepareString = (TCHAR* (*)(const TCHAR *))DLGetSymbolAddrEx(driver->m_handle, _T("DrvPrepareString"));\r
+   driver->m_fpDrvPrepareStringA = (char* (*)(const char *))DLGetSymbolAddrEx(driver->m_handle, _T("DrvPrepareStringA"));\r
+   driver->m_fpDrvPrepareStringW = (WCHAR* (*)(const WCHAR *))DLGetSymbolAddrEx(driver->m_handle, _T("DrvPrepareStringW"));\r
    if ((fpDrvInit == NULL) || (driver->m_fpDrvConnect == NULL) || (driver->m_fpDrvDisconnect == NULL) ||\r
        (driver->m_fpDrvQuery == NULL) || (driver->m_fpDrvSelect == NULL) || (driver->m_fpDrvGetField == NULL) ||\r
        (driver->m_fpDrvGetNumRows == NULL) || (driver->m_fpDrvFreeResult == NULL) || \r
@@ -194,7 +195,7 @@ DB_DRIVER LIBNXDB_EXPORTABLE DBLoadDriver(const TCHAR *module, const TCHAR *init
                 (driver->m_fpDrvGetColumnCount == NULL) || (driver->m_fpDrvGetColumnName == NULL) ||\r
                 (driver->m_fpDrvGetColumnCountAsync == NULL) || (driver->m_fpDrvGetColumnNameAsync == NULL) ||\r
        (driver->m_fpDrvGetFieldLength == NULL) || (driver->m_fpDrvGetFieldLengthAsync == NULL) ||\r
-                (driver->m_fpDrvPrepareString == NULL))\r
+                (driver->m_fpDrvPrepareStringA == NULL) || (driver->m_fpDrvPrepareStringW == NULL))\r
    {\r
       if (s_writeLog)\r
          __DBWriteLog(EVENTLOG_ERROR_TYPE, _T("Unable to find all required entry points in database driver \"%s\""), module);\r
@@ -202,7 +203,14 @@ DB_DRIVER LIBNXDB_EXPORTABLE DBLoadDriver(const TCHAR *module, const TCHAR *init
    }\r
 \r
    // Initialize driver\r
+#ifdef UNICODE\r
+       char mbInitParameters[1024];\r
+       WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, initParameters, -1, mbInitParameters, 1024, NULL, NULL);\r
+       mbInitParameters[1023] = 0;\r
+   if (!fpDrvInit(mbInitParameters))\r
+#else\r
    if (!fpDrvInit(initParameters))\r
+#endif\r
    {\r
       if (s_writeLog)\r
          __DBWriteLog(EVENTLOG_ERROR_TYPE, _T("Database driver \"%s\" initialization failed"), module);\r
index f954eb7..a74f6f2 100644 (file)
@@ -52,9 +52,9 @@ struct db_driver_t
        void *m_userArg;\r
        DBDRV_CONNECTION (* m_fpDrvConnect)(const char *, const char *, const char *, const char *);\r
        void (* m_fpDrvDisconnect)(DBDRV_CONNECTION);\r
-       DWORD (* m_fpDrvQuery)(DBDRV_CONNECTION, const WCHAR *, TCHAR *);\r
-       DBDRV_RESULT (* m_fpDrvSelect)(DBDRV_CONNECTION, const WCHAR *, DWORD *, TCHAR *);\r
-       DBDRV_ASYNC_RESULT (* m_fpDrvAsyncSelect)(DBDRV_CONNECTION, const WCHAR *, DWORD *, TCHAR *);\r
+       DWORD (* m_fpDrvQuery)(DBDRV_CONNECTION, const WCHAR *, WCHAR *);\r
+       DBDRV_RESULT (* m_fpDrvSelect)(DBDRV_CONNECTION, const WCHAR *, DWORD *, WCHAR *);\r
+       DBDRV_ASYNC_RESULT (* m_fpDrvAsyncSelect)(DBDRV_CONNECTION, const WCHAR *, DWORD *, WCHAR *);\r
        BOOL (* m_fpDrvFetch)(DBDRV_ASYNC_RESULT);\r
        LONG (* m_fpDrvGetFieldLength)(DBDRV_RESULT, int, int);\r
        LONG (* m_fpDrvGetFieldLengthAsync)(DBDRV_RESULT, int);\r
@@ -66,13 +66,14 @@ struct db_driver_t
        DWORD (* m_fpDrvBegin)(DBDRV_CONNECTION);\r
        DWORD (* m_fpDrvCommit)(DBDRV_CONNECTION);\r
        DWORD (* m_fpDrvRollback)(DBDRV_CONNECTION);\r
-       void (* m_fpDrvUnload)(void);\r
-       void (* m_fpEventHandler)(DWORD, const TCHAR *, const TCHAR *, void *);\r
+       void (* m_fpDrvUnload)();\r
+       void (* m_fpEventHandler)(DWORD, const WCHAR *, const WCHAR *, void *);\r
        int (* m_fpDrvGetColumnCount)(DBDRV_RESULT);\r
        const char* (* m_fpDrvGetColumnName)(DBDRV_RESULT, int);\r
        int (* m_fpDrvGetColumnCountAsync)(DBDRV_ASYNC_RESULT);\r
        const char* (* m_fpDrvGetColumnNameAsync)(DBDRV_ASYNC_RESULT, int);\r
-       TCHAR* (* m_fpDrvPrepareString)(const TCHAR *);\r
+       WCHAR* (* m_fpDrvPrepareStringW)(const WCHAR *);\r
+       char* (* m_fpDrvPrepareStringA)(const char *);\r
 };\r
 \r
 \r
index 0f32ab0..fc88aa4 100644 (file)
@@ -152,25 +152,23 @@ BOOL LIBNXDB_EXPORTABLE DBQueryEx(DB_HANDLE hConn, const TCHAR *szQuery, TCHAR *
    INT64 ms;\r
 #ifdef UNICODE\r
 #define pwszQuery szQuery\r
+#define wcErrorText errorText\r
 #else\r
    WCHAR *pwszQuery = WideStringFromMBString(szQuery);\r
+       WCHAR wcErrorText[DBDRV_MAX_ERROR_TEXT] = L"";\r
 #endif\r
 \r
    MutexLock(hConn->m_mutexTransLock, INFINITE);\r
    if (hConn->m_driver->m_dumpSql)\r
       ms = GetCurrentTimeMs();\r
 \r
-   dwResult = hConn->m_driver->m_fpDrvQuery(hConn->m_connection, pwszQuery, errorText);\r
+   dwResult = hConn->m_driver->m_fpDrvQuery(hConn->m_connection, pwszQuery, wcErrorText);\r
    if (dwResult == DBERR_CONNECTION_LOST)\r
    {\r
       DBReconnect(hConn);\r
-      dwResult = hConn->m_driver->m_fpDrvQuery(hConn->m_connection, pwszQuery, errorText);\r
+      dwResult = hConn->m_driver->m_fpDrvQuery(hConn->m_connection, pwszQuery, wcErrorText);\r
    }\r
 \r
-#ifndef UNICODE\r
-   free(pwszQuery);\r
-#endif\r
-   \r
    if (hConn->m_driver->m_dumpSql)\r
    {\r
       ms = GetCurrentTimeMs() - ms;\r
@@ -178,15 +176,27 @@ BOOL LIBNXDB_EXPORTABLE DBQueryEx(DB_HANDLE hConn, const TCHAR *szQuery, TCHAR *
    }\r
    \r
    MutexUnlock(hConn->m_mutexTransLock);\r
+\r
+#ifndef UNICODE\r
+       WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, wcErrorText, -1, errorText, DBDRV_MAX_ERROR_TEXT, NULL, NULL);\r
+       errorText[DBDRV_MAX_ERROR_TEXT - 1] = 0;\r
+#endif\r
+\r
    if (dwResult != DBERR_SUCCESS)\r
        {       \r
                if (hConn->m_driver->m_logSqlErrors)\r
                        nxlog_write(g_sqlErrorMsgCode, EVENTLOG_ERROR_TYPE, "ss", szQuery, errorText);\r
                if (hConn->m_driver->m_fpEventHandler != NULL)\r
-                       hConn->m_driver->m_fpEventHandler(DBEVENT_QUERY_FAILED, szQuery, errorText, hConn->m_driver->m_userArg);\r
+                       hConn->m_driver->m_fpEventHandler(DBEVENT_QUERY_FAILED, pwszQuery, wcErrorText, hConn->m_driver->m_userArg);\r
        }\r
+\r
+#ifndef UNICODE\r
+   free(pwszQuery);\r
+#endif\r
+   \r
    return dwResult == DBERR_SUCCESS;\r
 #undef pwszQuery\r
+#undef wcErrorText\r
 }\r
 \r
 BOOL LIBNXDB_EXPORTABLE DBQuery(DB_HANDLE hConn, const TCHAR *query)\r
@@ -209,38 +219,46 @@ DB_RESULT LIBNXDB_EXPORTABLE DBSelectEx(DB_HANDLE hConn, const TCHAR *szQuery, T
    INT64 ms;\r
 #ifdef UNICODE\r
 #define pwszQuery szQuery\r
+#define wcErrorText errorText\r
 #else\r
    WCHAR *pwszQuery = WideStringFromMBString(szQuery);\r
+       WCHAR wcErrorText[DBDRV_MAX_ERROR_TEXT] = L"";\r
 #endif\r
    \r
    MutexLock(hConn->m_mutexTransLock, INFINITE);\r
    if (hConn->m_driver->m_dumpSql)\r
       ms = GetCurrentTimeMs();\r
-   hResult = hConn->m_driver->m_fpDrvSelect(hConn->m_connection, pwszQuery, &dwError, errorText);\r
+   hResult = hConn->m_driver->m_fpDrvSelect(hConn->m_connection, pwszQuery, &dwError, wcErrorText);\r
    if ((hResult == NULL) && (dwError == DBERR_CONNECTION_LOST))\r
    {\r
       DBReconnect(hConn);\r
-      hResult = hConn->m_driver->m_fpDrvSelect(hConn->m_connection, pwszQuery, &dwError, errorText);\r
+      hResult = hConn->m_driver->m_fpDrvSelect(hConn->m_connection, pwszQuery, &dwError, wcErrorText);\r
    }\r
 \r
-#ifndef UNICODE\r
-   free(pwszQuery);\r
-#endif\r
-   \r
    if (hConn->m_driver->m_dumpSql)\r
    {\r
       ms = GetCurrentTimeMs() - ms;\r
       __DBDbgPrintf(9, _T("%s sync query: \"%s\" [%d ms]"), (hResult != NULL) ? _T("Successful") : _T("Failed"), szQuery, (DWORD)ms);\r
    }\r
    MutexUnlock(hConn->m_mutexTransLock);\r
-   if (hResult == NULL)\r
+\r
+#ifndef UNICODE\r
+       WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, wcErrorText, -1, errorText, DBDRV_MAX_ERROR_TEXT, NULL, NULL);\r
+       errorText[DBDRV_MAX_ERROR_TEXT - 1] = 0;\r
+#endif\r
+\r
+       if (hResult == NULL)\r
        {\r
                if (hConn->m_driver->m_logSqlErrors)\r
                        nxlog_write(g_sqlErrorMsgCode, EVENTLOG_ERROR_TYPE, "ss", szQuery, errorText);\r
                if (hConn->m_driver->m_fpEventHandler != NULL)\r
-                       hConn->m_driver->m_fpEventHandler(DBEVENT_QUERY_FAILED, szQuery, errorText, hConn->m_driver->m_userArg);\r
+                       hConn->m_driver->m_fpEventHandler(DBEVENT_QUERY_FAILED, pwszQuery, wcErrorText, hConn->m_driver->m_userArg);\r
        }\r
 \r
+#ifndef UNICODE\r
+   free(pwszQuery);\r
+#endif\r
+   \r
        if (hResult != NULL)\r
        {\r
                result = (DB_RESULT)malloc(sizeof(db_result_t));\r
@@ -328,8 +346,7 @@ BOOL LIBNXDB_EXPORTABLE DBGetColumnNameAsync(DB_ASYNC_RESULT hResult, int column
 // Get field's value\r
 //\r
 \r
-TCHAR LIBNXDB_EXPORTABLE *DBGetField(DB_RESULT hResult, int iRow, int iColumn,\r
-                                      TCHAR *pszBuffer, int nBufLen)\r
+TCHAR LIBNXDB_EXPORTABLE *DBGetField(DB_RESULT hResult, int iRow, int iColumn, TCHAR *pszBuffer, int nBufLen)\r
 {\r
 #ifdef UNICODE\r
    if (pszBuffer != NULL)\r
@@ -355,6 +372,12 @@ TCHAR LIBNXDB_EXPORTABLE *DBGetField(DB_RESULT hResult, int iRow, int iColumn,
       return pszTemp;\r
    }\r
 #else\r
+       return DBGetFieldA(hResult, iRow, iColumn, pszBuffer, nBufLen);\r
+#endif\r
+}\r
+\r
+char LIBNXDB_EXPORTABLE *DBGetFieldA(DB_RESULT hResult, int iRow, int iColumn, char *pszBuffer, int nBufLen)\r
+{\r
    WCHAR *pwszData, *pwszBuffer;\r
    char *pszRet;\r
    int nLen;\r
@@ -391,8 +414,7 @@ TCHAR LIBNXDB_EXPORTABLE *DBGetField(DB_RESULT hResult, int iRow, int iColumn,
          {\r
             nLen = (int)wcslen(pwszData) + 1;\r
             pszRet = (char *)malloc(nLen);\r
-            WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR,\r
-                                pwszData, -1, pszRet, nLen, NULL, NULL);\r
+            WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, pwszData, -1, pszRet, nLen, NULL, NULL);\r
          }\r
          else\r
          {\r
@@ -402,7 +424,6 @@ TCHAR LIBNXDB_EXPORTABLE *DBGetField(DB_RESULT hResult, int iRow, int iColumn,
       }\r
    }\r
    return pszRet;\r
-#endif\r
 }\r
 \r
 \r
@@ -599,24 +620,22 @@ DB_ASYNC_RESULT LIBNXDB_EXPORTABLE DBAsyncSelectEx(DB_HANDLE hConn, const TCHAR
    INT64 ms;\r
 #ifdef UNICODE\r
 #define pwszQuery szQuery\r
+#define wcErrorText errorText\r
 #else\r
    WCHAR *pwszQuery = WideStringFromMBString(szQuery);\r
+       WCHAR wcErrorText[DBDRV_MAX_ERROR_TEXT] = L"";\r
 #endif\r
    \r
    MutexLock(hConn->m_mutexTransLock, INFINITE);\r
        if (hConn->m_driver->m_dumpSql)\r
       ms = GetCurrentTimeMs();\r
-   hResult = hConn->m_driver->m_fpDrvAsyncSelect(hConn->m_connection, pwszQuery, &dwError, errorText);\r
+   hResult = hConn->m_driver->m_fpDrvAsyncSelect(hConn->m_connection, pwszQuery, &dwError, wcErrorText);\r
    if ((hResult == NULL) && (dwError == DBERR_CONNECTION_LOST))\r
    {\r
       DBReconnect(hConn);\r
-      hResult = hConn->m_driver->m_fpDrvAsyncSelect(hConn->m_connection, pwszQuery, &dwError, errorText);\r
+      hResult = hConn->m_driver->m_fpDrvAsyncSelect(hConn->m_connection, pwszQuery, &dwError, wcErrorText);\r
    }\r
 \r
-#ifndef UNICODE\r
-   free(pwszQuery);\r
-#endif\r
-   \r
    if (hConn->m_driver->m_dumpSql)\r
    {\r
       ms = GetCurrentTimeMs() - ms;\r
@@ -625,12 +644,22 @@ DB_ASYNC_RESULT LIBNXDB_EXPORTABLE DBAsyncSelectEx(DB_HANDLE hConn, const TCHAR
    if (hResult == NULL)\r
    {\r
       MutexUnlock(hConn->m_mutexTransLock);\r
+\r
+#ifndef UNICODE\r
+               WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, wcErrorText, -1, errorText, DBDRV_MAX_ERROR_TEXT, NULL, NULL);\r
+               errorText[DBDRV_MAX_ERROR_TEXT - 1] = 0;\r
+#endif\r
+\r
                if (hConn->m_driver->m_logSqlErrors)\r
         nxlog_write(g_sqlErrorMsgCode, EVENTLOG_ERROR_TYPE, "ss", szQuery, errorText);\r
                if (hConn->m_driver->m_fpEventHandler != NULL)\r
-                       hConn->m_driver->m_fpEventHandler(DBEVENT_QUERY_FAILED, szQuery, errorText, hConn->m_driver->m_userArg);\r
+                       hConn->m_driver->m_fpEventHandler(DBEVENT_QUERY_FAILED, pwszQuery, wcErrorText, hConn->m_driver->m_userArg);\r
    }\r
 \r
+#ifndef UNICODE\r
+   free(pwszQuery);\r
+#endif\r
+   \r
        if (hResult != NULL)\r
        {\r
                result = (DB_ASYNC_RESULT)malloc(sizeof(db_async_result_t));\r
@@ -935,16 +964,36 @@ String LIBNXDB_EXPORTABLE DBPrepareString(DB_HANDLE conn, const TCHAR *str, int
        {\r
                TCHAR *temp = (TCHAR *)malloc((maxSize + 1) * sizeof(TCHAR));\r
                nx_strncpy(temp, str, maxSize + 1);\r
-               out.setBuffer(conn->m_driver->m_fpDrvPrepareString(temp));\r
+#ifdef UNICODE\r
+               out.setBuffer(conn->m_driver->m_fpDrvPrepareStringW(temp));\r
+#else\r
+               out.setBuffer(conn->m_driver->m_fpDrvPrepareStringA(temp));\r
+#endif\r
                free(temp);\r
        }\r
        else    \r
        {\r
-               out.setBuffer(conn->m_driver->m_fpDrvPrepareString(CHECK_NULL_EX(str)));\r
+#ifdef UNICODE\r
+               out.setBuffer(conn->m_driver->m_fpDrvPrepareStringW(CHECK_NULL_EX(str)));\r
+#else\r
+               out.setBuffer(conn->m_driver->m_fpDrvPrepareStringA(CHECK_NULL_EX(str)));\r
+#endif\r
        }\r
        return out;\r
 }\r
 \r
+#ifdef UNICODE\r
+\r
+String LIBNXDB_EXPORTABLE DBPrepareStringA(DB_HANDLE conn, const char *str, int maxSize)\r
+{\r
+       WCHAR *wcs = WideStringFromMBString(str);\r
+       String s = DBPrepareString(conn, wcs, maxSize);\r
+       free(wcs);\r
+       return s;\r
+}\r
+\r
+#endif\r
+\r
 \r
 //\r
 // Characters to be escaped before writing to SQL\r
index 3848f76..14d11e0 100644 (file)
@@ -634,6 +634,107 @@ TCHAR *CSCPMessage::GetVariableStr(DWORD dwVarId, TCHAR *pszBuffer, DWORD dwBufS
 
 
 //
+// Get variable as multibyte string
+//
+
+#ifdef UNICODE
+
+char *CSCPMessage::GetVariableStrA(DWORD dwVarId, char *pszBuffer, DWORD dwBufSize)
+{
+   void *pValue;
+   char *pStr = NULL;
+   DWORD dwLen;
+
+   if ((pszBuffer != NULL) && (dwBufSize == 0))
+      return NULL;   // non-sense combination
+
+   pValue = Get(dwVarId, CSCP_DT_STRING);
+   if (pValue != NULL)
+   {
+      if (pszBuffer == NULL)
+      {
+         pStr = (char *)malloc(*((DWORD *)pValue) / 2 + 1);
+      }
+      else
+      {
+         pStr = pszBuffer;
+      }
+
+      dwLen = (pszBuffer == NULL) ? (*((DWORD *)pValue) / 2) : min(*((DWORD *)pValue) / 2, dwBufSize - 1);
+               ucs2_to_mb((UCS2CHAR *)((BYTE *)pValue + 4), dwLen, pStr, dwLen + 1);
+      pStr[dwLen] = 0;
+   }
+   else
+   {
+      if (pszBuffer != NULL)
+      {
+         pStr = pszBuffer;
+         pStr[0] = 0;
+      }
+   }
+   return pStr;
+}
+
+#else
+
+char *CSCPMessage::GetVariableStrA(DWORD dwVarId, char *pszBuffer, DWORD dwBufSize)
+{
+       return GetVariableStr(dwVarId, pszBuffer, dwBufSize);
+}
+
+#endif
+
+
+//
+// Get variable as UTF-8 string
+//
+
+char *CSCPMessage::GetVariableStrUTF8(DWORD dwVarId, char *pszBuffer, DWORD dwBufSize)
+{
+   void *pValue;
+   char *pStr = NULL;
+   DWORD dwLen, dwOutSize;
+       int cc;
+
+   if ((pszBuffer != NULL) && (dwBufSize == 0))
+      return NULL;   // non-sense combination
+
+   pValue = Get(dwVarId, CSCP_DT_STRING);
+   if (pValue != NULL)
+   {
+      if (pszBuffer == NULL)
+      {
+                       // Assume worst case scenario - 3 bytes per character
+                       dwOutSize = *((DWORD *)pValue) + *((DWORD *)pValue) / 2 + 1;
+         pStr = (char *)malloc(dwOutSize);
+      }
+      else
+      {
+                       dwOutSize = dwBufSize;
+         pStr = pszBuffer;
+      }
+
+      dwLen = *((DWORD *)pValue) / 2;
+#ifdef UNICODE_UCS2
+               cc = WideCharToMultiByte(CP_UTF8, 0, (WCHAR *)((BYTE *)pValue + 4), dwLen, pStr, dwOutSize - 1, NULL, NULL);
+#else
+               cc = ucs2_to_utf8((UCS2CHAR *)((BYTE *)pValue + 4), dwLen, pStr, dwOutSize - 1);
+#endif
+      pStr[cc] = 0;
+   }
+   else
+   {
+      if (pszBuffer != NULL)
+      {
+         pStr = pszBuffer;
+         pStr[0] = 0;
+      }
+   }
+   return pStr;
+}
+
+
+//
 // Get binary (byte array) variable
 // Result will be placed to the buffer provided (no more than dwBufSize bytes,
 // and actual size of data will be returned
@@ -664,7 +765,7 @@ DWORD CSCPMessage::GetVariableBinary(DWORD dwVarId, BYTE *pBuffer, DWORD dwBufSi
 // Build protocol message ready to be send over the wire
 //
 
-CSCP_MESSAGE *CSCPMessage::CreateMessage(void)
+CSCP_MESSAGE *CSCPMessage::CreateMessage()
 {
    DWORD dwSize;
    int iVarSize;
@@ -744,7 +845,7 @@ CSCP_MESSAGE *CSCPMessage::CreateMessage(void)
 // Delete all variables
 //
 
-void CSCPMessage::DeleteAllVariables(void)
+void CSCPMessage::DeleteAllVariables()
 {
    if (m_ppVarList != NULL)
    {
@@ -761,6 +862,22 @@ void CSCPMessage::DeleteAllVariables(void)
 
 
 //
+// Set variable from multibyte string
+//
+
+#ifdef UNICODE
+
+void CSCPMessage::SetVariableFromMBString(DWORD dwVarId, const char *pszValue)
+{
+       WCHAR *wcValue = WideStringFromMBString(pszValue);
+       Set(dwVarId, CSCP_DT_STRING, wcValue);
+       free(wcValue);
+}
+
+#endif
+
+
+//
 // Set binary variable to an array of DWORDs
 //
 
index a9c6b88..5135066 100644 (file)
@@ -288,12 +288,12 @@ void LIBNETXMS_EXPORTABLE Trim(TCHAR *str)
 // Remove trailing CR/LF or LF from string
 //
 
-void LIBNETXMS_EXPORTABLE RemoveTrailingCRLF(TCHAR *str)
+void LIBNETXMS_EXPORTABLE RemoveTrailingCRLFA(char *str)
 {
        if (*str == 0)
                return;
 
-       TCHAR *p = str + _tcslen(str) - 1;
+       char *p = str + strlen(str) - 1;
        if (*p == '\n')
                p--;
        if (*p == '\r')
@@ -301,6 +301,19 @@ void LIBNETXMS_EXPORTABLE RemoveTrailingCRLF(TCHAR *str)
        *(p + 1) = 0;
 }
 
+void LIBNETXMS_EXPORTABLE RemoveTrailingCRLFW(WCHAR *str)
+{
+       if (*str == 0)
+               return;
+
+       WCHAR *p = str + wcslen(str) - 1;
+       if (*p == L'\n')
+               p--;
+       if (*p == L'\r')
+               p--;
+       *(p + 1) = 0;
+}
+
 
 //
 // Get current time in milliseconds
@@ -338,9 +351,10 @@ INT64 LIBNETXMS_EXPORTABLE GetCurrentTimeMs(void)
 // of line reached.
 //
 
-TCHAR LIBNETXMS_EXPORTABLE *ExtractWord(TCHAR *line, TCHAR *buffer)
+const TCHAR LIBNETXMS_EXPORTABLE *ExtractWord(const TCHAR *line, TCHAR *buffer)
 {
-   TCHAR *ptr,*bptr;
+   const TCHAR *ptr;
+       TCHAR *bptr;
 
    for(ptr=line;(*ptr==_T(' '))||(*ptr==_T('\t'));ptr++);  // Skip initial spaces
    // Copy word to buffer
index f81d71e..55485cd 100644 (file)
@@ -27,7 +27,7 @@
 // Static data
 //
 
-static char m_cpDefault[MAX_CODEPAGE_LEN] = ICONV_DEFAULT_CODEPAGE;
+static char m_cpDefault[MAX_CODEPAGE_LEN] = ICONV_DEFAULT_CODEPAGE_A;
 
 
 #ifndef _WIN32
index 682fc3d..2068025 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath=".\link.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath=".\main.cpp"\r
                                >\r
                        </File>\r
index 6044093..79e8f77 100644 (file)
@@ -1,6 +1,6 @@
 /* 
 ** NetXMS - Network Management System
-** Copyright (C) 2003, 2004 Victor Kirhenshtein
+** Copyright (C) 2003-2010 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
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 **
-** $module: acl.cpp
+** File: acl.cpp
 **
 **/
 
@@ -176,7 +176,7 @@ void AccessList::CreateMessage(CSCPMessage *pMsg)
 // Delete all elements
 //
 
-void AccessList::DeleteAll(void)
+void AccessList::DeleteAll()
 {
    Lock();
    m_dwNumElements = 0;
index 9e564e3..81d4c18 100644 (file)
@@ -68,15 +68,15 @@ static void DestroyActionList(void)
 // Load actions list from database
 //
 
-static BOOL LoadActions(void)
+static BOOL LoadActions()
 {
    DB_RESULT hResult;
    BOOL bResult = FALSE;
    DWORD i;
 
-   hResult = DBSelect(g_hCoreDB, "SELECT action_id,action_name,action_type,"
-                                 "is_disabled,rcpt_addr,email_subject,action_data "
-                                 "FROM actions ORDER BY action_id");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT action_id,action_name,action_type,")
+                                 _T("is_disabled,rcpt_addr,email_subject,action_data ")
+                                 _T("FROM actions ORDER BY action_id"));
    if (hResult != NULL)
    {
       DestroyActionList();
@@ -114,7 +114,7 @@ static BOOL LoadActions(void)
 // Initialize action-related stuff
 //
 
-BOOL InitActions(void)
+BOOL InitActions()
 {
    BOOL bSuccess = FALSE;
 
@@ -147,7 +147,7 @@ static void SaveActionToDB(NXC_ACTION *pAction)
    TCHAR *pszEscRcpt, *pszEscSubj, *pszEscData, szQuery[4096];
 
    // Check if action with given ID already exist in database
-   sprintf(szQuery, "SELECT action_id FROM actions WHERE action_id=%d", pAction->dwId);
+   _sntprintf(szQuery, 4096, _T("SELECT action_id FROM actions WHERE action_id=%d"), pAction->dwId);
    hResult = DBSelect(g_hCoreDB, szQuery);
    if (hResult != NULL)
    {
@@ -158,17 +158,19 @@ static void SaveActionToDB(NXC_ACTION *pAction)
    // Prepare and execute INSERT or UPDATE query
    pszEscRcpt = EncodeSQLString(pAction->szRcptAddr);
    pszEscSubj = EncodeSQLString(pAction->szEmailSubject);
-   pszEscData = EncodeSQLString(pAction->pszData == NULL ? "" : pAction->pszData);
+   pszEscData = EncodeSQLString(CHECK_NULL_EX(pAction->pszData));
    if (bExist)
-      sprintf(szQuery, "UPDATE actions SET action_name='%s',action_type=%d,is_disabled=%d,"
-                       "rcpt_addr='%s',email_subject='%s',action_data='%s'"
-                       "WHERE action_id=%d",
+      _sntprintf(szQuery, 4096, 
+                          _T("UPDATE actions SET action_name='%s',action_type=%d,is_disabled=%d,")
+                 _T("rcpt_addr='%s',email_subject='%s',action_data='%s'")
+                 _T("WHERE action_id=%d"),
               pAction->szName, pAction->iType, pAction->bIsDisabled,
               pszEscRcpt, pszEscSubj, pszEscData, pAction->dwId);
    else
-      sprintf(szQuery, "INSERT INTO actions (action_id,action_name,action_type,"
-                       "is_disabled,rcpt_addr,email_subject,action_data) VALUES"
-                       " (%d,'%s',%d,%d,'%s','%s','%s')",
+      _sntprintf(szQuery, 4096,
+                          _T("INSERT INTO actions (action_id,action_name,action_type,")
+                 _T("is_disabled,rcpt_addr,email_subject,action_data) VALUES")
+                 _T(" (%d,'%s',%d,%d,'%s','%s','%s')"),
               pAction->dwId,pAction->szName, pAction->iType, pAction->bIsDisabled,
               pszEscRcpt, pszEscSubj, pszEscData);
    DBQuery(g_hCoreDB, szQuery);
@@ -365,32 +367,31 @@ BOOL ExecuteAction(DWORD dwActionId, Event *pEvent, TCHAR *pszAlarmMsg)
    {
       if (pAction->bIsDisabled)
       {
-         DbgPrintf(3, "*actions* Action %d (%s) is disabled and will not be executed",
+         DbgPrintf(3, _T("*actions* Action %d (%s) is disabled and will not be executed"),
                    dwActionId, pAction->szName);
          bSuccess = TRUE;
       }
       else
       {
-         char *pszExpandedData, *pszExpandedSubject, *pszExpandedRcpt, *curr, *next;
+         TCHAR *pszExpandedData, *pszExpandedSubject, *pszExpandedRcpt, *curr, *next;
 
          pszExpandedData = pEvent->expandText(CHECK_NULL_EX(pAction->pszData), pszAlarmMsg);
          pszExpandedRcpt = pEvent->expandText(pAction->szRcptAddr, pszAlarmMsg);
          switch(pAction->iType)
          {
             case ACTION_EXEC:
-               DbgPrintf(3, "*actions* Executing command \"%s\"", pszExpandedData);
+               DbgPrintf(3, _T("*actions* Executing command \"%s\""), pszExpandedData);
                //bSuccess = ExecCommand(pszExpandedData);
-                                       ThreadCreate(RunCommandThread, 0, strdup(pszExpandedData));
+                                       ThreadCreate(RunCommandThread, 0, _tcsdup(pszExpandedData));
                                        bSuccess = TRUE;
                break;
             case ACTION_SEND_EMAIL:
-               DbgPrintf(3, "*actions* Sending mail to %s: \"%s\"", 
-                         pszExpandedRcpt, pszExpandedData);
+               DbgPrintf(3, _T("*actions* Sending mail to %s: \"%s\""), pszExpandedRcpt, pszExpandedData);
                pszExpandedSubject = pEvent->expandText(pAction->szEmailSubject, pszAlarmMsg);
                                        curr = pszExpandedRcpt;
                                        do
                                        {
-                                               next = strchr(curr, ';');
+                                               next = _tcschr(curr, _T(';'));
                                                if (next != NULL)
                                                        *next = 0;
                                                StrStrip(curr);
@@ -401,12 +402,11 @@ BOOL ExecuteAction(DWORD dwActionId, Event *pEvent, TCHAR *pszAlarmMsg)
                bSuccess = TRUE;
                break;
             case ACTION_SEND_SMS:
-               DbgPrintf(3, "*actions* Sending SMS to %s: \"%s\"", 
-                         pszExpandedRcpt, pszExpandedData);
+               DbgPrintf(3, _T("*actions* Sending SMS to %s: \"%s\""), pszExpandedRcpt, pszExpandedData);
                                        curr = pszExpandedRcpt;
                                        do
                                        {
-                                               next = strchr(curr, ';');
+                                               next = _tcschr(curr, _T(';'));
                                                if (next != NULL)
                                                        *next = 0;
                                                StrStrip(curr);
@@ -416,12 +416,11 @@ BOOL ExecuteAction(DWORD dwActionId, Event *pEvent, TCHAR *pszAlarmMsg)
                bSuccess = TRUE;
                break;
             case ACTION_REMOTE:
-               DbgPrintf(3, "*actions* Executing on \"%s\": \"%s\"",
-                         pszExpandedRcpt, pszExpandedData);
+               DbgPrintf(3, _T("*actions* Executing on \"%s\": \"%s\""), pszExpandedRcpt, pszExpandedData);
                bSuccess = ExecuteRemoteAction(pszExpandedRcpt, pszExpandedData);
                break;
                                case ACTION_FORWARD_EVENT:
-               DbgPrintf(3, "*actions* Forwarding event to \"%s\"", pszExpandedRcpt);
+               DbgPrintf(3, _T("*actions* Forwarding event to \"%s\""), pszExpandedRcpt);
                bSuccess = ForwardEvent(pszExpandedRcpt, pEvent);
                                        break;
             default:
@@ -440,7 +439,7 @@ BOOL ExecuteAction(DWORD dwActionId, Event *pEvent, TCHAR *pszAlarmMsg)
 // Create new action
 //
 
-DWORD CreateNewAction(char *pszName, DWORD *pdwId)
+DWORD CreateNewAction(const TCHAR *pszName, DWORD *pdwId)
 {
    DWORD i, dwResult = RCC_SUCCESS;
 
@@ -448,7 +447,7 @@ DWORD CreateNewAction(char *pszName, DWORD *pdwId)
 
    // Check for duplicate name
    for(i = 0; i < m_dwNumActions; i++)
-      if (!stricmp(m_pActionList[i].szName, pszName))
+      if (!_tcsicmp(m_pActionList[i].szName, pszName))
       {
          dwResult = RCC_ALREADY_EXIST;
          break;
@@ -487,7 +486,7 @@ DWORD CreateNewAction(char *pszName, DWORD *pdwId)
 DWORD DeleteActionFromDB(DWORD dwActionId)
 {
    DWORD i, dwResult = RCC_INVALID_ACTION_ID;
-   char szQuery[256];
+   TCHAR szQuery[256];
 
    RWLockWriteLock(m_rwlockActionListAccess, INFINITE);
 
@@ -500,7 +499,7 @@ DWORD DeleteActionFromDB(DWORD dwActionId)
          m_dwNumActions--;
          safe_free(m_pActionList[i].pszData);
          memmove(&m_pActionList[i], &m_pActionList[i + 1], sizeof(NXC_ACTION) * (m_dwNumActions - i));
-         sprintf(szQuery, "DELETE FROM actions WHERE action_id=%d", dwActionId);
+         _sntprintf(szQuery, 256, _T("DELETE FROM actions WHERE action_id=%d"), dwActionId);
          DBQuery(g_hCoreDB, szQuery);
 
          dwResult = RCC_SUCCESS;
index 1b261f0..0a85e59 100644 (file)
@@ -1,8 +1,6 @@
-/* $Id$ */
-
 /* 
 ** NetXMS - Network Management System
-** Copyright (C) 2003, 2004 Victor Kirhenshtein
+** Copyright (C) 2003-2010 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
@@ -18,7 +16,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 **
-** $module: admin.cpp
+** File: admin.cpp
 **
 **/
 
@@ -112,7 +110,7 @@ THREAD_RESULT THREAD_CALL LocalAdminListener(void *pArg)
    // Create socket
    if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    {
-      nxlog_write(MSG_SOCKET_FAILED, EVENTLOG_ERROR_TYPE, "s", "LocalAdminListener");
+      nxlog_write(MSG_SOCKET_FAILED, EVENTLOG_ERROR_TYPE, "s", _T("LocalAdminListener"));
       return THREAD_OK;
    }
 
@@ -128,7 +126,7 @@ THREAD_RESULT THREAD_CALL LocalAdminListener(void *pArg)
    // Bind socket
    if (bind(sock, (struct sockaddr *)&servAddr, sizeof(struct sockaddr_in)) != 0)
    {
-      nxlog_write(MSG_BIND_ERROR, EVENTLOG_ERROR_TYPE, "dse", LOCAL_ADMIN_PORT, "LocalAdminListener", WSAGetLastError());
+      nxlog_write(MSG_BIND_ERROR, EVENTLOG_ERROR_TYPE, "dse", LOCAL_ADMIN_PORT, _T("LocalAdminListener"), WSAGetLastError());
       closesocket(sock);
       /* TODO: we should initiate shutdown from here */
       return THREAD_OK;
index 4b57532..fa4b91d 100644 (file)
@@ -42,7 +42,7 @@ void AgentConnectionEx::onTrap(CSCPMessage *pMsg)
    int i, iNumArgs;
    Node *pNode;
    TCHAR *pszArgList[32], szBuffer[32];
-   TCHAR szFormat[] = "ssssssssssssssssssssssssssssssss";
+   char szFormat[] = "ssssssssssssssssssssssssssssssss";
 
    DbgPrintf(3, _T("Received trap message from agent at %s"), IpToStr(getIpAddr(), szBuffer));
    pNode = FindNodeByIP(getIpAddr());
index e62bcf2..782a6ff 100644 (file)
@@ -163,7 +163,7 @@ BOOL AgentPolicy::CreateFromDB(DWORD dwId)
 
        if (!LoadCommonProperties())
    {
-      DbgPrintf(2, "Cannot load common properties for agent policy object %d", dwId);
+      DbgPrintf(2, _T("Cannot load common properties for agent policy object %d"), dwId);
       return FALSE;
    }
 
index b9968b5..19d536c 100644 (file)
@@ -105,13 +105,13 @@ BOOL AlarmManager::Init()
    DWORD i;
 
    // Load unacknowledged alarms into memory
-   hResult = DBSelect(g_hCoreDB, "SELECT alarm_id,source_object_id,"
-                                 "source_event_code,source_event_id,message,"
-                                 "original_severity,current_severity,"
-                                 "alarm_key,creation_time,last_change_time,"
-                                 "hd_state,hd_ref,ack_by,repeat_count,"
-                                 "alarm_state,timeout,timeout_event "
-                                 "FROM alarms WHERE alarm_state<2");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT alarm_id,source_object_id,")
+                                 _T("source_event_code,source_event_id,message,")
+                                 _T("original_severity,current_severity,")
+                                 _T("alarm_key,creation_time,last_change_time,")
+                                 _T("hd_state,hd_ref,ack_by,repeat_count,")
+                                 _T("alarm_state,timeout,timeout_event ")
+                                 _T("FROM alarms WHERE alarm_state<2"));
    if (hResult == NULL)
       return FALSE;
 
@@ -227,11 +227,12 @@ void AlarmManager::NewAlarm(TCHAR *pszMsg, TCHAR *pszKey, int nState,
       }
 
       // Save alarm to database
-      sprintf(szQuery, "INSERT INTO alarms (alarm_id,creation_time,last_change_time,"
-                       "source_object_id,source_event_code,message,original_severity,"
-                       "current_severity,alarm_key,alarm_state,ack_by,hd_state,"
-                       "hd_ref,repeat_count,term_by,timeout,timeout_event,source_event_id) VALUES "
-                       "(%d,%d,%d,%d,%d,%s,%d,%d,%s,%d,%d,%d,%s,%d,%d,%d,%d," UINT64_FMT ")",
+      _sntprintf(szQuery, 2048, 
+                               _T("INSERT INTO alarms (alarm_id,creation_time,last_change_time,")
+                 _T("source_object_id,source_event_code,message,original_severity,")
+                 _T("current_severity,alarm_key,alarm_state,ack_by,hd_state,")
+                 _T("hd_ref,repeat_count,term_by,timeout,timeout_event,source_event_id) VALUES ")
+                 _T("(%d,%d,%d,%d,%d,%s,%d,%d,%s,%d,%d,%d,%s,%d,%d,%d,%d,") UINT64_FMT _T(")"),
               alarm.dwAlarmId, alarm.dwCreationTime, alarm.dwLastChangeTime,
                                  alarm.dwSourceObject, alarm.dwSourceEventCode,
                                  (const TCHAR *)DBPrepareString(g_hCoreDB, alarm.szMessage),
@@ -336,7 +337,7 @@ DWORD AlarmManager::TerminateById(DWORD dwAlarmId, DWORD dwUserId)
 // Terminate all alarms with given key
 //
 
-void AlarmManager::TerminateByKey(char *pszKey, bool useRegexp)
+void AlarmManager::TerminateByKey(const TCHAR *pszKey, bool useRegexp)
 {
    DWORD i, j, dwNumObjects, *pdwObjectList, dwCurrTime;
 
@@ -385,7 +386,7 @@ void AlarmManager::TerminateByKey(char *pszKey, bool useRegexp)
 void AlarmManager::DeleteAlarm(DWORD dwAlarmId)
 {
    DWORD i, dwObject;
-   char szQuery[256];
+   TCHAR szQuery[256];
 
    // Delete alarm from in-memory list
    Lock();
@@ -401,8 +402,7 @@ void AlarmManager::DeleteAlarm(DWORD dwAlarmId)
    Unlock();
 
    // Delete from database
-   sprintf(szQuery, "DELETE FROM alarms WHERE alarm_id=%d", dwAlarmId);
-   //DBQuery(g_hCoreDB, szQuery);
+   _sntprintf(szQuery, 256, _T("DELETE FROM alarms WHERE alarm_id=%d"), dwAlarmId);
    QueueSQLRequest(szQuery);
 
    UpdateObjectStatus(dwObject);
@@ -415,7 +415,7 @@ void AlarmManager::DeleteAlarm(DWORD dwAlarmId)
 
 void AlarmManager::UpdateAlarmInDB(NXC_ALARM *pAlarm)
 {
-   char szQuery[2048];
+   TCHAR szQuery[2048];
 
    _sntprintf(szQuery, 2048, _T("UPDATE alarms SET alarm_state=%d,ack_by=%d,term_by=%d,")
                              _T("last_change_time=%d,current_severity=%d,repeat_count=%d,")
@@ -511,7 +511,7 @@ void AlarmManager::SendAlarmsToClient(DWORD dwRqId, BOOL bIncludeAck, ClientSess
 NetObj *AlarmManager::GetAlarmSourceObject(DWORD dwAlarmId)
 {
    DWORD i, dwObjectId = 0;
-   char szQuery[256];
+   TCHAR szQuery[256];
    DB_RESULT hResult;
 
    // First, look at our in-memory list
@@ -527,7 +527,7 @@ NetObj *AlarmManager::GetAlarmSourceObject(DWORD dwAlarmId)
    // If not found, search database
    if (i == m_dwNumAlarms)
    {
-      sprintf(szQuery, "SELECT source_object_id FROM alarms WHERE alarm_id=%d", dwAlarmId);
+      _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("SELECT source_object_id FROM alarms WHERE alarm_id=%d"), dwAlarmId);
       hResult = DBSelect(g_hCoreDB, szQuery);
       if (hResult != NULL)
       {
index 204594d..c1b1d6c 100644 (file)
@@ -53,8 +53,15 @@ static void SendSyslogRecord(const TCHAR *text)
        time_t ts = time(NULL);
        struct tm *now = localtime(&ts);
 
+#ifdef UNICODE
+       char *mbText = MBStringFromWideString(text);
+       snprintf(message, 1025, "<%d>%s %2d %02d:%02d:%02d %s %s %s", (m_auditFacility << 3) + m_auditSeverity, month[now->tm_mon],
+                now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec, m_localHostName, m_auditTag, mbText);
+       free(mbText);
+#else
        snprintf(message, 1025, "<%d>%s %2d %02d:%02d:%02d %s %s %s", (m_auditFacility << 3) + m_auditSeverity, month[now->tm_mon],
                 now->tm_mday, now->tm_hour, now->tm_min, now->tm_sec, m_localHostName, m_auditTag, text);
+#endif
        message[1024] = 0;
 
    SOCKET hSocket = socket(AF_INET, SOCK_DGRAM, 0);
@@ -99,7 +106,7 @@ void InitAuditLog()
                m_auditServerPort = htons((WORD)ConfigReadInt(_T("ExternalAuditPort"), 514));
                m_auditFacility = ConfigReadInt(_T("ExternalAuditFacility"), 13);  // default is log audit facility
                m_auditSeverity = ConfigReadInt(_T("ExternalAuditSeverity"), SYSLOG_SEVERITY_NOTICE);
-               ConfigReadStr(_T("ExternalAuditTag"), m_auditTag, MAX_SYSLOG_TAG_LEN, _T("netxmsd-audit"));
+               ConfigReadStrA(_T("ExternalAuditTag"), m_auditTag, MAX_SYSLOG_TAG_LEN, "netxmsd-audit");
 
                // Get local host name
 #ifdef _WIN32
index 2469d43..d675112 100644 (file)
@@ -106,13 +106,22 @@ BOOL ValidateUserCertificate(X509 *pCert, const TCHAR *pszLogin, BYTE *pChalleng
        BYTE hash[SHA1_DIGEST_SIZE];
        BOOL bValid = FALSE;
 
-       DbgPrintf(3, _T("Validating certificate \"%s\" for user %s"), CHECK_NULL(pCert->name), pszLogin);
+#ifdef UNICODE
+       WCHAR *certSubject = WideStringFromMBString(CHECK_NULL_A(pCert->name));
+#else
+#define certSubject (CHECK_NULL(pCert->name))
+#endif
+
+       DbgPrintf(3, _T("Validating certificate \"%s\" for user %s"), certSubject, pszLogin);
        MutexLock(m_mutexStoreAccess, INFINITE);
 
        if (m_pTrustedCertStore == NULL)
        {
                DbgPrintf(3, _T("Cannot validate user certificate because certificate store is not initialized"));
                MutexUnlock(m_mutexStoreAccess);
+#ifdef UNICODE
+               free(certSubject);
+#endif
                return FALSE;
        }
 
@@ -127,7 +136,7 @@ BOOL ValidateUserCertificate(X509 *pCert, const TCHAR *pszLogin, BYTE *pChalleng
                                bValid = RSA_verify(NID_sha1, hash, SHA1_DIGEST_SIZE, pSignature, dwSigLen, pKey->pkey.rsa);
                                break;
                        default:
-                               DbgPrintf(3, _T("Unknown key type %d in certificate \"%s\" for user %s"), pKey->type, CHECK_NULL(pCert->name), pszLogin);
+                               DbgPrintf(3, _T("Unknown key type %d in certificate \"%s\" for user %s"), pKey->type, certSubject, pszLogin);
                                break;
                }
        }
@@ -144,13 +153,13 @@ BOOL ValidateUserCertificate(X509 *pCert, const TCHAR *pszLogin, BYTE *pChalleng
                        bValid = X509_verify_cert(pStore);
                        X509_STORE_CTX_free(pStore);
                        DbgPrintf(3, _T("Certificate \"%s\" for user %s - validation %s"),
-                                 CHECK_NULL(pCert->name), pszLogin, bValid ? _T("successful") : _T("failed"));
+                                 certSubject, pszLogin, bValid ? _T("successful") : _T("failed"));
                }
                else
                {
-                       char szBuffer[256];
+                       TCHAR szBuffer[256];
 
-                       DbgPrintf(3, _T("X509_STORE_CTX_new() failed: %s"), ERR_error_string(ERR_get_error(), szBuffer));
+                       DbgPrintf(3, _T("X509_STORE_CTX_new() failed: %s"), _ERR_error_tstring(ERR_get_error(), szBuffer));
                        bValid = FALSE;
                }
        }
@@ -161,7 +170,7 @@ BOOL ValidateUserCertificate(X509 *pCert, const TCHAR *pszLogin, BYTE *pChalleng
                switch(nMappingMethod)
                {
                        case USER_MAP_CERT_BY_SUBJECT:
-                               bValid = !_tcsicmp(CHECK_NULL(pCert->name), CHECK_NULL_EX(pszMappingData));
+                               bValid = !_tcsicmp(certSubject, CHECK_NULL_EX(pszMappingData));
                                break;
                        case USER_MAP_CERT_BY_PUBKEY:
                                bValid = CheckPublicKey(pKey, CHECK_NULL_EX(pszMappingData));
@@ -174,7 +183,13 @@ BOOL ValidateUserCertificate(X509 *pCert, const TCHAR *pszLogin, BYTE *pChalleng
        }
 
        MutexUnlock(m_mutexStoreAccess);
+
+#ifdef UNICODE
+       free(certSubject);
+#endif
+
        return bValid;
+#undef certSubject
 }
 
 
@@ -200,7 +215,7 @@ void ReloadCertificates()
        m_pTrustedCertStore = X509_STORE_new();
        if (m_pTrustedCertStore != NULL)
        {
-               _stprintf(szBuffer, _T("SELECT cert_data,subject FROM certificates WHERE cert_type=%d"), CERT_TYPE_TRUSTED_CA);
+               _sntprintf(szBuffer, 256, _T("SELECT cert_data,subject FROM certificates WHERE cert_type=%d"), CERT_TYPE_TRUSTED_CA);
                hResult = DBSelect(g_hCoreDB, szBuffer);
                if (hResult != NULL)
                {
index e726a7c..9b20eb1 100644 (file)
@@ -1,6 +1,6 @@
 /* 
 ** NetXMS - Network Management System
-** Copyright (C) 2003, 2004, 2005, 2006, 2007 Victor Kirhenshtein
+** Copyright (C) 2003-2010 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
@@ -84,7 +84,7 @@ static THREAD_RESULT THREAD_CALL ClientKeepAliveThread(void *)
    CSCPMessage msg;
 
    // Read configuration
-   iSleepTime = ConfigReadInt("KeepAliveInterval", 60);
+   iSleepTime = ConfigReadInt(_T("KeepAliveInterval"), 60);
 
    // Prepare keepalive message
    msg.SetCode(CMD_KEEPALIVE);
@@ -123,12 +123,12 @@ THREAD_RESULT THREAD_CALL ClientListener(void *)
    ClientSession *pSession;
 
    // Read configuration
-   wListenPort = (WORD)ConfigReadInt("ClientListenerPort", SERVER_LISTEN_PORT);
+   wListenPort = (WORD)ConfigReadInt(_T("ClientListenerPort"), SERVER_LISTEN_PORT);
 
    // Create socket
    if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    {
-      nxlog_write(MSG_SOCKET_FAILED, EVENTLOG_ERROR_TYPE, "s", "ClientListener");
+      nxlog_write(MSG_SOCKET_FAILED, EVENTLOG_ERROR_TYPE, "s", _T("ClientListener"));
       return THREAD_OK;
    }
 
@@ -147,7 +147,7 @@ THREAD_RESULT THREAD_CALL ClientListener(void *)
    // Bind socket
    if (bind(sock, (struct sockaddr *)&servAddr, sizeof(struct sockaddr_in)) != 0)
    {
-      nxlog_write(MSG_BIND_ERROR, EVENTLOG_ERROR_TYPE, "dse", wListenPort, "ClientListener", WSAGetLastError());
+      nxlog_write(MSG_BIND_ERROR, EVENTLOG_ERROR_TYPE, "dse", wListenPort, _T("ClientListener"), WSAGetLastError());
       closesocket(sock);
       /* TODO: we should initiate shutdown procedure here */
       return THREAD_OK;
@@ -215,12 +215,12 @@ void DumpSessions(CONSOLE_CTX pCtx)
    static const TCHAR *pszStateName[] = { _T("init"), _T("idle"), _T("processing") };
    static const TCHAR *pszCipherName[] = { _T("NONE"), _T("AES-256"), _T("BLOWFISH"), _T("IDEA"), _T("3DES") };
 
-   ConsolePrintf(pCtx, "ID  STATE                    CIPHER   USER [CLIENT]\n");
+   ConsolePrintf(pCtx, _T("ID  STATE                    CIPHER   USER [CLIENT]\n"));
    RWLockReadLock(m_rwlockSessionListAccess, INFINITE);
    for(i = 0, iCount = 0; i < MAX_CLIENT_SESSIONS; i++)
       if (m_pSessionList[i] != NULL)
       {
-         ConsolePrintf(pCtx, "%-3d %-24s %-8s %s [%s]\n", i, 
+         ConsolePrintf(pCtx, _T("%-3d %-24s %-8s %s [%s]\n"), i, 
                        (m_pSessionList[i]->getState() != SESSION_STATE_PROCESSING) ?
                          pszStateName[m_pSessionList[i]->getState()] :
                          NXCPMessageCodeName(m_pSessionList[i]->getCurrentCmd(), szBuffer),
@@ -230,7 +230,7 @@ void DumpSessions(CONSOLE_CTX pCtx)
          iCount++;
       }
    RWLockUnlock(m_rwlockSessionListAccess);
-   ConsolePrintf(pCtx, "\n%d active session%s\n\n", iCount, iCount == 1 ? "" : "s");
+   ConsolePrintf(pCtx, _T("\n%d active session%s\n\n"), iCount, iCount == 1 ? "" : "s");
 }
 
 
index caea03f..35d3507 100644 (file)
@@ -85,7 +85,7 @@ BOOL Cluster::CreateFromDB(DWORD dwId)
 
    if (!LoadCommonProperties())
    {
-      DbgPrintf(2, "Cannot load common properties for cluster object %d", dwId);
+      DbgPrintf(2, _T("Cannot load common properties for cluster object %d"), dwId);
       return FALSE;
    }
 
@@ -99,7 +99,7 @@ BOOL Cluster::CreateFromDB(DWORD dwId)
    if (!m_bIsDeleted)
    {
                // Load member nodes
-               _stprintf(szQuery, _T("SELECT node_id FROM cluster_members WHERE cluster_id=%d"), m_dwId);
+               _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("SELECT node_id FROM cluster_members WHERE cluster_id=%d"), m_dwId);
                hResult = DBSelect(g_hCoreDB, szQuery);
                if (hResult != NULL)
                {
@@ -135,7 +135,7 @@ BOOL Cluster::CreateFromDB(DWORD dwId)
                // Load sync net list
                if (bResult)
                {
-                       _stprintf(szQuery, _T("SELECT subnet_addr,subnet_mask FROM cluster_sync_subnets WHERE cluster_id=%d"), m_dwId);
+                       _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("SELECT subnet_addr,subnet_mask FROM cluster_sync_subnets WHERE cluster_id=%d"), m_dwId);
                        hResult = DBSelect(g_hCoreDB, szQuery);
                        if (hResult != NULL)
                        {
@@ -160,7 +160,7 @@ BOOL Cluster::CreateFromDB(DWORD dwId)
                // Load resources
                if (bResult)
                {
-                       _stprintf(szQuery, _T("SELECT resource_id,resource_name,ip_addr,current_owner FROM cluster_resources WHERE cluster_id=%d"), m_dwId);
+                       _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("SELECT resource_id,resource_name,ip_addr,current_owner FROM cluster_resources WHERE cluster_id=%d"), m_dwId);
                        hResult = DBSelect(g_hCoreDB, szQuery);
                        if (hResult != NULL)
                        {
@@ -211,7 +211,7 @@ BOOL Cluster::SaveToDB(DB_HANDLE hdb)
    SaveCommonProperties(hdb);
 
    // Check for object's existence in database
-   _stprintf(szQuery, _T("SELECT id FROM clusters WHERE id=%d"), m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("SELECT id FROM clusters WHERE id=%d"), m_dwId);
    hResult = DBSelect(hdb, szQuery);
    if (hResult != 0)
    {
@@ -240,14 +240,14 @@ BOOL Cluster::SaveToDB(DB_HANDLE hdb)
                // Save cluster members list
                if (DBBegin(hdb))
                {
-                       _stprintf(szQuery, _T("DELETE FROM cluster_members WHERE cluster_id=%d"), m_dwId);
+                       _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM cluster_members WHERE cluster_id=%d"), m_dwId);
                        DBQuery(hdb, szQuery);
                        LockChildList(FALSE);
                        for(i = 0; i < m_dwChildCount; i++)
                        {
                                if (m_pChildList[i]->Type() == OBJECT_NODE)
                                {
-                                       _stprintf(szQuery, _T("INSERT INTO cluster_members (cluster_id,node_id) VALUES (%d,%d)"),
+                                       _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("INSERT INTO cluster_members (cluster_id,node_id) VALUES (%d,%d)"),
                                                                 m_dwId, m_pChildList[i]->Id());
                                        bResult = DBQuery(hdb, szQuery);
                                        if (!bResult)
@@ -270,11 +270,11 @@ BOOL Cluster::SaveToDB(DB_HANDLE hdb)
                {
                        if (DBBegin(hdb))
                        {
-                               _stprintf(szQuery, _T("DELETE FROM cluster_sync_subnets WHERE cluster_id=%d"), m_dwId);
+                               _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM cluster_sync_subnets WHERE cluster_id=%d"), m_dwId);
                                DBQuery(hdb, szQuery);
                                for(i = 0; i < m_dwNumSyncNets; i++)
                                {
-                                       _stprintf(szQuery, _T("INSERT INTO cluster_sync_subnets (cluster_id,subnet_addr,subnet_mask) VALUES (%d,'%s','%s')"),
+                                       _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("INSERT INTO cluster_sync_subnets (cluster_id,subnet_addr,subnet_mask) VALUES (%d,'%s','%s')"),
                                                                 m_dwId, IpToStr(m_pSyncNetList[i].dwAddr, szIpAddr),
                                                                 IpToStr(m_pSyncNetList[i].dwMask, szNetMask));
                                        bResult = DBQuery(hdb, szQuery);
@@ -297,12 +297,12 @@ BOOL Cluster::SaveToDB(DB_HANDLE hdb)
                {
                        if (DBBegin(hdb))
                        {
-                               _stprintf(szQuery, _T("DELETE FROM cluster_resources WHERE cluster_id=%d"), m_dwId);
+                               _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM cluster_resources WHERE cluster_id=%d"), m_dwId);
                                DBQuery(hdb, szQuery);
                                for(i = 0; i < m_dwNumResources; i++)
                                {
                                        pszEscName = EncodeSQLString(m_pResourceList[i].szName);
-                                       _stprintf(szQuery, _T("INSERT INTO cluster_resources (cluster_id,resource_id,resource_name,ip_addr,current_owner) VALUES (%d,%d,'%s','%s',%d)"),
+                                       _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("INSERT INTO cluster_resources (cluster_id,resource_id,resource_name,ip_addr,current_owner) VALUES (%d,%d,'%s','%s',%d)"),
                                                                 m_dwId, m_pResourceList[i].dwId, pszEscName,
                                                                 IpToStr(m_pResourceList[i].dwIpAddr, szIpAddr),
                                                                 m_pResourceList[i].dwCurrOwner);
@@ -347,11 +347,11 @@ BOOL Cluster::DeleteFromDB(void)
    bSuccess = Template::DeleteFromDB();
    if (bSuccess)
    {
-      _stprintf(szQuery, _T("DELETE FROM clusters WHERE id=%d"), m_dwId);
+      _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM clusters WHERE id=%d"), m_dwId);
       QueueSQLRequest(szQuery);
-      _stprintf(szQuery, _T("DELETE FROM cluster_members WHERE cluster_id=%d"), m_dwId);
+      _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM cluster_members WHERE cluster_id=%d"), m_dwId);
       QueueSQLRequest(szQuery);
-      _stprintf(szQuery, _T("DELETE FROM cluster_sync_subnets WHERE cluster_id=%d"), m_dwId);
+      _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM cluster_sync_subnets WHERE cluster_id=%d"), m_dwId);
       QueueSQLRequest(szQuery);
    }
    return bSuccess;
index 5e379bd..baf84b5 100644 (file)
@@ -169,10 +169,11 @@ BOOL Condition::SaveToDB(DB_HANDLE hdb)
    SaveCommonProperties(hdb);
 
    pszEscScript = EncodeSQLString(CHECK_NULL_EX(m_pszScript));
-   pszQuery = (TCHAR *)malloc(sizeof(TCHAR) * (_tcslen(pszEscScript) + 1024));
+       size_t qlen = _tcslen(pszEscScript) + 1024;
+   pszQuery = (TCHAR *)malloc(sizeof(TCHAR) * qlen);
 
    // Check for object's existence in database
-   _stprintf(pszQuery, _T("SELECT id FROM conditions WHERE id=%d"), m_dwId);
+   _sntprintf(pszQuery, qlen, _T("SELECT id FROM conditions WHERE id=%d"), m_dwId);
    hResult = DBSelect(hdb, pszQuery);
    if (hResult != NULL)
    {
@@ -184,7 +185,8 @@ BOOL Condition::SaveToDB(DB_HANDLE hdb)
    // Form and execute INSERT or UPDATE query
    if (bNewObject)
    {
-      _stprintf(pszQuery, _T("INSERT INTO conditions (id,activation_event,")
+      _sntprintf(pszQuery, qlen, 
+                                        _T("INSERT INTO conditions (id,activation_event,")
                           _T("deactivation_event,source_object,active_status,")
                           _T("inactive_status,script) VALUES (%d,%d,%d,%d,%d,%d,'%s')"),
                 m_dwId, m_dwActivationEventCode, m_dwDeactivationEventCode,
@@ -192,7 +194,8 @@ BOOL Condition::SaveToDB(DB_HANDLE hdb)
    }
    else
    {
-      _stprintf(pszQuery, _T("UPDATE conditions SET activation_event=%d,")
+      _sntprintf(pszQuery, qlen,
+                                        _T("UPDATE conditions SET activation_event=%d,")
                           _T("deactivation_event=%d,source_object=%d,active_status=%d,")
                           _T("inactive_status=%d,script='%s' WHERE id=%d"),
                 m_dwActivationEventCode, m_dwDeactivationEventCode, m_dwSourceObject,
@@ -202,12 +205,12 @@ BOOL Condition::SaveToDB(DB_HANDLE hdb)
    DBQuery(hdb, pszQuery);
 
    // Save DCI mapping
-   _stprintf(pszQuery, _T("DELETE FROM cond_dci_map WHERE condition_id=%d"), m_dwId);
+   _sntprintf(pszQuery, qlen, _T("DELETE FROM cond_dci_map WHERE condition_id=%d"), m_dwId);
    DBQuery(hdb, pszQuery);
    for(i = 0; i < m_dwDCICount; i++)
    {
-      _stprintf(pszQuery, _T("INSERT INTO cond_dci_map (condition_id,sequence_number,dci_id,node_id,")
-                          _T("dci_func,num_polls) VALUES (%d,%d,%d,%d,%d,%d)"),
+      _sntprintf(pszQuery, qlen, _T("INSERT INTO cond_dci_map (condition_id,sequence_number,dci_id,node_id,")
+                                 _T("dci_func,num_polls) VALUES (%d,%d,%d,%d,%d,%d)"),
                 m_dwId, i, m_pDCIList[i].dwId, m_pDCIList[i].dwNodeId,
                 m_pDCIList[i].nFunction, m_pDCIList[i].nPolls);
       DBQuery(hdb, pszQuery);
index ec06bbf..d74f047 100644 (file)
@@ -52,24 +52,24 @@ TCHAR g_szDbName[MAX_DB_NAME] = _T("netxms_db");
 static TCHAR s_encryptedDbPassword[MAX_DB_STRING] = _T("");
 static NX_CFG_TEMPLATE m_cfgTemplate[] =
 {
-   { "CodePage", CT_STRING, 0, 0, 256, 0, g_szCodePage },
-   { "CreateCrashDumps", CT_BOOLEAN, 0, 0, AF_CATCH_EXCEPTIONS, 0, &g_dwFlags },
-   { "DataDirectory", CT_STRING, 0, 0, MAX_PATH, 0, g_szDataDir },
-   { "DBDriver", CT_STRING, 0, 0, MAX_PATH, 0, g_szDbDriver },
-   { "DBDrvParams", CT_STRING, 0, 0, MAX_PATH, 0, g_szDbDrvParams },
-   { "DBEncryptedPassword", CT_STRING, 0, 0, MAX_DB_STRING, 0, s_encryptedDbPassword },
-   { "DBLogin", CT_STRING, 0, 0, MAX_DB_LOGIN, 0, g_szDbLogin },
-   { "DBName", CT_STRING, 0, 0, MAX_DB_NAME, 0, g_szDbName },
-   { "DBPassword", CT_STRING, 0, 0, MAX_DB_PASSWORD, 0, g_szDbPassword },
-   { "DBServer", CT_STRING, 0, 0, MAX_PATH, 0, g_szDbServer },
-   { "DumpDirectory", CT_STRING, 0, 0, MAX_PATH, 0, g_szDumpDir },
-   { "FullCrashDumps", CT_BOOLEAN, 0, 0, AF_WRITE_FULL_DUMP, 0, &g_dwFlags },
-   { "ListenAddress", CT_STRING, 0, 0, MAX_PATH, 0, g_szListenAddress },
-   { "LogFailedSQLQueries", CT_BOOLEAN, 0, 0, AF_LOG_SQL_ERRORS, 0, &g_dwFlags },
-   { "LogFile", CT_STRING, 0, 0, MAX_PATH, 0, g_szLogFile },
-   { "Module", CT_STRING_LIST, '\n', 0, 0, 0, &g_pszModLoadList },
-   { "ProcessAffinityMask", CT_LONG, 0, 0, 0, 0, &g_processAffinityMask },
-   { "", CT_END_OF_LIST, 0, 0, 0, 0, NULL }
+   { _T("CodePage"), CT_STRING, 0, 0, 256, 0, g_szCodePage },
+   { _T("CreateCrashDumps"), CT_BOOLEAN, 0, 0, AF_CATCH_EXCEPTIONS, 0, &g_dwFlags },
+   { _T("DataDirectory"), CT_STRING, 0, 0, MAX_PATH, 0, g_szDataDir },
+   { _T("DBDriver"), CT_STRING, 0, 0, MAX_PATH, 0, g_szDbDriver },
+   { _T("DBDrvParams"), CT_STRING, 0, 0, MAX_PATH, 0, g_szDbDrvParams },
+   { _T("DBEncryptedPassword"), CT_STRING, 0, 0, MAX_DB_STRING, 0, s_encryptedDbPassword },
+   { _T("DBLogin"), CT_STRING, 0, 0, MAX_DB_LOGIN, 0, g_szDbLogin },
+   { _T("DBName"), CT_STRING, 0, 0, MAX_DB_NAME, 0, g_szDbName },
+   { _T("DBPassword"), CT_STRING, 0, 0, MAX_DB_PASSWORD, 0, g_szDbPassword },
+   { _T("DBServer"), CT_STRING, 0, 0, MAX_PATH, 0, g_szDbServer },
+   { _T("DumpDirectory"), CT_STRING, 0, 0, MAX_PATH, 0, g_szDumpDir },
+   { _T("FullCrashDumps"), CT_BOOLEAN, 0, 0, AF_WRITE_FULL_DUMP, 0, &g_dwFlags },
+   { _T("ListenAddress"), CT_STRING, 0, 0, MAX_PATH, 0, g_szListenAddress },
+   { _T("LogFailedSQLQueries"), CT_BOOLEAN, 0, 0, AF_LOG_SQL_ERRORS, 0, &g_dwFlags },
+   { _T("LogFile"), CT_STRING, 0, 0, MAX_PATH, 0, g_szLogFile },
+   { _T("Module"), CT_STRING_LIST, '\n', 0, 0, 0, &g_pszModLoadList },
+   { _T("ProcessAffinityMask"), CT_LONG, 0, 0, 0, 0, &g_processAffinityMask },
+   { _T(""), CT_END_OF_LIST, 0, 0, 0, 0, NULL }
 };
 
 BOOL NXCORE_EXPORTABLE LoadConfig()
@@ -80,29 +80,29 @@ BOOL NXCORE_EXPORTABLE LoadConfig()
 #if !defined(_WIN32) && !defined(_NETWARE)
        if (!_tcscmp(g_szConfigFile, _T("{search}")))
        {
-               if (access(PREFIX "/etc/netxmsd.conf", 4) == 0)
+               if (access(PREFIX _T("/etc/netxmsd.conf"), 4) == 0)
                {
-                       _tcscpy(g_szConfigFile, PREFIX "/etc/netxmsd.conf");
+                       _tcscpy(g_szConfigFile, PREFIX _T("/etc/netxmsd.conf"));
                }
-               else if (access("/usr/etc/netxmsd.conf", 4) == 0)
+               else if (access(_T("/usr/etc/netxmsd.conf"), 4) == 0)
                {
-                       _tcscpy(g_szConfigFile, "/usr/etc/netxmsd.conf");
+                       _tcscpy(g_szConfigFile, _T("/usr/etc/netxmsd.conf"));
                }
                else
                {
-                       _tcscpy(g_szConfigFile, "/etc/netxmsd.conf");
+                       _tcscpy(g_szConfigFile, _T("/etc/netxmsd.conf"));
                }
        }
 #endif
 
    if (IsStandalone())
-      printf("Using configuration file \"%s\"\n", g_szConfigFile);
+      _tprintf(_T("Using configuration file \"%s\"\n"), g_szConfigFile);
 
        config = new Config();
        if (config->loadConfig(g_szConfigFile, _T("server")) && config->parseTemplate(_T("server"), m_cfgTemplate))
    {
-      if ((!stricmp(g_szLogFile,"{EventLog}")) ||
-          (!stricmp(g_szLogFile,"{syslog}")))
+      if ((!_tcsicmp(g_szLogFile, _T("{EventLog}"))) ||
+          (!_tcsicmp(g_szLogFile, _T("{syslog}"))))
       {
          g_dwFlags |= AF_USE_SYSLOG;
       }
@@ -200,6 +200,32 @@ BOOL NXCORE_EXPORTABLE ConfigReadStr(const TCHAR *szVar, TCHAR *szBuffer, int iB
 
 
 //
+// Read multibyte string from configuration table
+//
+
+#ifdef UNICODE
+
+BOOL NXCORE_EXPORTABLE ConfigReadStrA(const WCHAR *szVar, char *szBuffer, int iBufSize, const char *szDefault)
+{
+       WCHAR *wcBuffer = (WCHAR *)malloc(iBufSize * sizeof(WCHAR));
+   BOOL rc = ConfigReadStr(szVar, wcBuffer, iBufSize, _T(""));
+       if (rc)
+       {
+               WideCharToMultiByte(CP_ACP, WC_DEFAULTCHAR | WC_COMPOSITECHECK, wcBuffer, -1, szBuffer, iBufSize, NULL, NULL);
+       }
+       else
+       {
+               strncpy(szBuffer, szDefault, iBufSize);
+       }
+       szBuffer[iBufSize - 1] = 0;
+       free(wcBuffer);
+       return rc;
+}
+
+#endif
+
+
+//
 // Read integer value from configuration table
 //
 
@@ -243,7 +269,7 @@ BOOL NXCORE_EXPORTABLE ConfigReadByteArray(const TCHAR *pszVar, int *pnArray, in
    if (ConfigReadStr(pszVar, szBuffer, 256, _T("")))
    {
       StrToBin(szBuffer, (BYTE *)pbBytes, 128);
-      nLen = (int)strlen(szBuffer) / 2;
+      nLen = (int)_tcslen(szBuffer) / 2;
       for(i = 0; (i < nSize) && (i < nLen); i++)
          pnArray[i] = pbBytes[i];
       for(; i < nSize; i++)
@@ -313,7 +339,7 @@ BOOL NXCORE_EXPORTABLE ConfigWriteInt(const TCHAR *szVar, int iValue, BOOL bCrea
 {
    TCHAR szBuffer[64];
 
-   _stprintf(szBuffer, _T("%d"), iValue);
+   _sntprintf(szBuffer, 64, _T("%d"), iValue);
    return ConfigWriteStr(szVar, szBuffer, bCreate, isVisible, needRestart);
 }
 
@@ -326,7 +352,7 @@ BOOL NXCORE_EXPORTABLE ConfigWriteULong(const TCHAR *szVar, DWORD dwValue, BOOL
 {
    TCHAR szBuffer[64];
 
-   _stprintf(szBuffer, _T("%u"), dwValue);
+   _sntprintf(szBuffer, 64, _T("%u"), dwValue);
    return ConfigWriteStr(szVar, szBuffer, bCreate, isVisible, needRestart);
 }
 
@@ -341,7 +367,7 @@ BOOL NXCORE_EXPORTABLE ConfigWriteByteArray(const TCHAR *pszVar, int *pnArray, i
    int i, j;
 
    for(i = 0, j = 0; (i < nSize) && (i < 127); i++, j += 2)
-      _stprintf(&szBuffer[j], _T("%02X"), (char)((pnArray[i] > 127) ? 127 : ((pnArray[i] < -127) ? -127 : pnArray[i])));
+      _sntprintf(&szBuffer[j], 256 - j, _T("%02X"), (char)((pnArray[i] > 127) ? 127 : ((pnArray[i] < -127) ? -127 : pnArray[i])));
    return ConfigWriteStr(pszVar, szBuffer, bCreate, isVisible, needRestart);
 }
 
index 09174e2..745f59c 100644 (file)
@@ -1,7 +1,6 @@
-/* $Id$ */
 /* 
 ** NetXMS - Network Management System
-** Copyright (C) 2003, 2004, 2005, 2006 Victor Kirhenshtein
+** Copyright (C) 2003-2010 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
@@ -55,7 +54,7 @@ Container::Container()
 
 
 //
-// "Normal" container class constructor
+// _T("Normal") container class constructor
 //
 
 Container::Container(TCHAR *pszName, DWORD dwCategory)
@@ -89,7 +88,7 @@ Container::~Container()
 
 BOOL Container::CreateFromDB(DWORD dwId)
 {
-   char szQuery[256];
+   TCHAR szQuery[256];
    DB_RESULT hResult;
    DWORD i;
 
@@ -98,7 +97,7 @@ BOOL Container::CreateFromDB(DWORD dwId)
    if (!LoadCommonProperties())
       return FALSE;
 
-   sprintf(szQuery, "SELECT category,enable_auto_bind,auto_bind_filter FROM containers WHERE id=%d", dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("SELECT category,enable_auto_bind,auto_bind_filter FROM containers WHERE id=%d"), dwId);
    hResult = DBSelect(g_hCoreDB, szQuery);
    if (hResult == NULL)
       return FALSE;     // Query failed
@@ -133,7 +132,7 @@ BOOL Container::CreateFromDB(DWORD dwId)
    // Load child list for later linkage
    if (!m_bIsDeleted)
    {
-      sprintf(szQuery, "SELECT object_id FROM container_members WHERE container_id=%d", m_dwId);
+      _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("SELECT object_id FROM container_members WHERE container_id=%d"), m_dwId);
       hResult = DBSelect(g_hCoreDB, szQuery);
       if (hResult != NULL)
       {
@@ -158,7 +157,7 @@ BOOL Container::CreateFromDB(DWORD dwId)
 
 BOOL Container::SaveToDB(DB_HANDLE hdb)
 {
-   char szQuery[1024], *pszDynQuery, *pszEscScript;
+   TCHAR szQuery[1024], *pszDynQuery, *pszEscScript;
    DB_RESULT hResult;
    DWORD i, len;
    BOOL bNewObject = TRUE;
@@ -169,7 +168,7 @@ BOOL Container::SaveToDB(DB_HANDLE hdb)
    SaveCommonProperties(hdb);
 
    // Check for object's existence in database
-   sprintf(szQuery, "SELECT id FROM containers WHERE id=%d", m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("SELECT id FROM containers WHERE id=%d"), m_dwId);
    hResult = DBSelect(hdb, szQuery);
    if (hResult != NULL)
    {
@@ -183,22 +182,22 @@ BOOL Container::SaveToDB(DB_HANDLE hdb)
        len = (DWORD)_tcslen(pszEscScript) + 256;
        pszDynQuery = (TCHAR *)malloc(sizeof(TCHAR) * len);
    if (bNewObject)
-      sprintf(pszDynQuery, "INSERT INTO containers (id,category,object_class,enable_auto_bind,auto_bind_filter) VALUES (%d,%d,%d,%d,'%s')",
-              m_dwId, m_dwCategory, Type(), (m_bindFilterSource != NULL) ? 1 : 0, pszEscScript);
+      _sntprintf(pszDynQuery, len, _T("INSERT INTO containers (id,category,object_class,enable_auto_bind,auto_bind_filter) VALUES (%d,%d,%d,%d,'%s')"),
+                 m_dwId, m_dwCategory, Type(), (m_bindFilterSource != NULL) ? 1 : 0, pszEscScript);
    else
-      sprintf(pszDynQuery, "UPDATE containers SET category=%d,object_class=%d,enable_auto_bind=%d,auto_bind_filter='%s' WHERE id=%d",
-              m_dwCategory, Type(), (m_bindFilterSource != NULL) ? 1 : 0, pszEscScript, m_dwId);
+      _sntprintf(pszDynQuery, len, _T("UPDATE containers SET category=%d,object_class=%d,enable_auto_bind=%d,auto_bind_filter='%s' WHERE id=%d"),
+                 m_dwCategory, Type(), (m_bindFilterSource != NULL) ? 1 : 0, pszEscScript, m_dwId);
        free(pszEscScript);
    DBQuery(hdb, pszDynQuery);
        free(pszDynQuery);
 
    // Update members list
-   sprintf(szQuery, "DELETE FROM container_members WHERE container_id=%d", m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM container_members WHERE container_id=%d"), m_dwId);
    DBQuery(hdb, szQuery);
    LockChildList(FALSE);
    for(i = 0; i < m_dwChildCount; i++)
    {
-      sprintf(szQuery, "INSERT INTO container_members (container_id,object_id) VALUES (%d,%d)", m_dwId, m_pChildList[i]->Id());
+      _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("INSERT INTO container_members (container_id,object_id) VALUES (%d,%d)"), m_dwId, m_pChildList[i]->Id());
       DBQuery(hdb, szQuery);
    }
    UnlockChildList();
@@ -220,15 +219,15 @@ BOOL Container::SaveToDB(DB_HANDLE hdb)
 
 BOOL Container::DeleteFromDB(void)
 {
-   char szQuery[256];
+   TCHAR szQuery[256];
    BOOL bSuccess;
 
    bSuccess = NetObj::DeleteFromDB();
    if (bSuccess)
    {
-      sprintf(szQuery, "DELETE FROM containers WHERE id=%d", m_dwId);
+      _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM containers WHERE id=%d"), m_dwId);
       QueueSQLRequest(szQuery);
-      sprintf(szQuery, "DELETE FROM container_members WHERE container_id=%d", m_dwId);
+      _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM container_members WHERE container_id=%d"), m_dwId);
       QueueSQLRequest(szQuery);
    }
    return bSuccess;
@@ -361,8 +360,7 @@ BOOL Container::IsSuitableForNode(Node *node)
                        TCHAR buffer[1024];
 
                        _sntprintf(buffer, 1024, _T("Container::%s::%d"), m_szName, m_dwId);
-                       PostEvent(EVENT_SCRIPT_ERROR, g_dwMgmtNode, _T("ssd"), buffer,
-                                                m_bindFilter->getErrorText(), m_dwId);
+                       PostEvent(EVENT_SCRIPT_ERROR, g_dwMgmtNode, "ssd", buffer, m_bindFilter->getErrorText(), m_dwId);
                        nxlog_write(MSG_CONTAINER_SCRIPT_EXECUTION_ERROR, EVENTLOG_WARNING_TYPE, "dss", m_dwId, m_szName, m_bindFilter->getErrorText());
                }
        }
index 4b3a199..5f15812 100644 (file)
@@ -60,9 +60,9 @@ static THREAD_RESULT THREAD_CALL DataCollector(void *pArg)
    Node *pNode;
    DWORD dwError;
    time_t currTime;
-   char *pBuffer;
+   TCHAR *pBuffer;
 
-   pBuffer = (char *)malloc(MAX_LINE_SIZE);
+   pBuffer = (TCHAR *)malloc(MAX_LINE_SIZE * sizeof(TCHAR));
 
    while(!ShutdownInProgress())
    {
@@ -95,7 +95,7 @@ static THREAD_RESULT THREAD_CALL DataCollector(void *pArg)
                                }
                                else
                                {
-               // Change item's status to "not supported"
+               // Change item's status to _T("not supported")
                pItem->setStatus(ITEM_STATUS_NOT_SUPPORTED, true);
 
                                        if (pNode != NULL)
@@ -163,7 +163,7 @@ static THREAD_RESULT THREAD_CALL DataCollector(void *pArg)
       else     /* pNode == NULL */
       {
                        Template *n = pItem->getRelatedNode();
-         DbgPrintf(3, "*** DataCollector: Attempt to collect information for non-existing node (DCI=%d \"%s\" node=%d proxy=%d)",
+         DbgPrintf(3, _T("*** DataCollector: Attempt to collect information for non-existing node (DCI=%d \"%s\" node=%d proxy=%d)"),
                                  pItem->getId(), pItem->getName(), (n != NULL) ? n->Id() : -1, pItem->getProxyNode());
       }
 
@@ -173,7 +173,7 @@ static THREAD_RESULT THREAD_CALL DataCollector(void *pArg)
    }
 
    free(pBuffer);
-   DbgPrintf(1, "Data collector thread terminated");
+   DbgPrintf(1, _T("Data collector thread terminated"));
    return THREAD_OK;
 }
 
@@ -189,7 +189,7 @@ static THREAD_RESULT THREAD_CALL ItemPoller(void *pArg)
    DWORD dwTimingHistory[60 / ITEM_POLLING_INTERVAL];
    INT64 qwStart;
 
-   dwWatchdogId = WatchdogAddThread("Item Poller", 20);
+   dwWatchdogId = WatchdogAddThread(_T("Item Poller"), 20);
    memset(dwTimingHistory, 0, sizeof(DWORD) * (60 / ITEM_POLLING_INTERVAL));
 
    while(!ShutdownInProgress())
@@ -225,7 +225,7 @@ static THREAD_RESULT THREAD_CALL ItemPoller(void *pArg)
          dwSum += dwTimingHistory[i];
       g_dwAvgDCIQueuingTime = dwSum / (60 / ITEM_POLLING_INTERVAL);
    }
-   DbgPrintf(1, "Item poller thread terminated");
+   DbgPrintf(1, _T("Item poller thread terminated"));
    return THREAD_OK;
 }
 
@@ -292,7 +292,7 @@ BOOL InitDataCollector(void)
    g_pItemQueue = new Queue(4096, 256);
 
    // Start data collection threads
-   iNumCollectors = ConfigReadInt("NumberOfDataCollectors", 10);
+   iNumCollectors = ConfigReadInt(_T("NumberOfDataCollectors"), 10);
    for(i = 0; i < iNumCollectors; i++)
       ThreadCreate(DataCollector, 0, NULL);
 
index cd72c21..c4e315b 100644 (file)
@@ -1,6 +1,6 @@
 /* 
 ** NetXMS - Network Management System
-** Copyright (C) 2003-2009 Victor Kirhenshtein
+** Copyright (C) 2003-2010 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
@@ -106,7 +106,7 @@ void StartDBWriter()
 
    if (g_dwFlags & AF_ENABLE_MULTIPLE_DB_CONN)
    {
-      m_iNumWriters = ConfigReadInt("NumberOfDatabaseWriters", 1);
+      m_iNumWriters = ConfigReadInt(_T("NumberOfDatabaseWriters"), 1);
       if (m_iNumWriters < 1)
          m_iNumWriters = 1;
       if (m_iNumWriters > MAX_DB_WRITERS)
index 335015c..5c88e45 100644 (file)
@@ -157,10 +157,10 @@ static int F_FindDCIByDescription(int argc, NXSL_Value **argv, NXSL_Value **ppRe
 
 static NXSL_ExtFunction m_nxslDCIFunctions[] =
 {
-   { "FindDCIByName", F_FindDCIByName, 2 },
-   { "FindDCIByDescription", F_FindDCIByDescription, 2 },
-   { "GetDCIObject", F_GetDCIObject, 2 },
-   { "GetDCIValue", F_GetDCIValue, 2 }
+   { _T("FindDCIByName"), F_FindDCIByName, 2 },
+   { _T("FindDCIByDescription"), F_FindDCIByDescription, 2 },
+   { _T("GetDCIObject"), F_GetDCIObject, 2 },
+   { _T("GetDCIValue"), F_GetDCIValue, 2 }
 };
 
 void RegisterDCIFunctions(NXSL_Environment *pEnv)
@@ -395,7 +395,7 @@ DCItem::DCItem(DWORD dwId, const TCHAR *szName, int iSource, int iDataType,
    if (pszDescription != NULL)
       nx_strncpy(m_szDescription, pszDescription, MAX_DB_STRING);
    else
-      strcpy(m_szDescription, m_szName);
+      _tcscpy(m_szDescription, m_szName);
    m_szInstance[0] = 0;
        nx_strncpy(m_systemTag, CHECK_NULL_EX(systemTag), MAX_DB_STRING);
    m_source = iSource;
@@ -580,14 +580,15 @@ void DCItem::clearCache()
 BOOL DCItem::loadThresholdsFromDB()
 {
    DWORD i;
-   char szQuery[256];
+   TCHAR szQuery[256];
    DB_RESULT hResult;
    BOOL bResult = FALSE;
 
-   sprintf(szQuery, "SELECT threshold_id,fire_value,rearm_value,check_function,"
-                    "check_operation,parameter_1,parameter_2,event_code,current_state,"
-                    "rearm_event_code,repeat_interval FROM thresholds WHERE item_id=%d "
-                    "ORDER BY sequence_number", m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR),
+                  _T("SELECT threshold_id,fire_value,rearm_value,check_function,")
+              _T("check_operation,parameter_1,parameter_2,event_code,current_state,")
+              _T("rearm_event_code,repeat_interval FROM thresholds WHERE item_id=%d ")
+              _T("ORDER BY sequence_number"), m_dwId);
    hResult = DBSelect(g_hCoreDB, szQuery);
    if (hResult != NULL)
    {
@@ -767,7 +768,7 @@ void DCItem::checkThresholds(ItemValue &value)
          case THRESHOLD_REACHED:
             PostEvent(m_ppThresholdList[i]->getEventCode(), m_pNode->Id(), "ssssisd", m_szName,
                       m_szDescription, m_ppThresholdList[i]->getStringValue(), 
-                      (const char *)checkValue, m_dwId, m_szInstance, 0);
+                      (const TCHAR *)checkValue, m_dwId, m_szInstance, 0);
                                m_ppThresholdList[i]->setLastEventTimestamp();
             if (!m_processAllThresholds)
                i = m_dwNumThresholds;  // Stop processing
@@ -788,7 +789,7 @@ void DCItem::checkThresholds(ItemValue &value)
                                        {
                                                PostEvent(m_ppThresholdList[i]->getEventCode(), m_pNode->Id(), "ssssisd", m_szName,
                                                                         m_szDescription, m_ppThresholdList[i]->getStringValue(), 
-                                                                        (const char *)checkValue, m_dwId, m_szInstance, 1);
+                                                                        (const TCHAR *)checkValue, m_dwId, m_szInstance, 1);
                                                m_ppThresholdList[i]->setLastEventTimestamp();
                                        }
 
@@ -855,15 +856,15 @@ void DCItem::createMessage(CSCPMessage *pMsg)
 
 void DCItem::deleteFromDB()
 {
-   char szQuery[256];
+   TCHAR szQuery[256];
 
-   sprintf(szQuery, "DELETE FROM items WHERE item_id=%d", m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM items WHERE item_id=%d"), m_dwId);
    QueueSQLRequest(szQuery);
-   sprintf(szQuery, "DELETE FROM idata_%d WHERE item_id=%d", m_pNode->Id(), m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM idata_%d WHERE item_id=%d"), m_pNode->Id(), m_dwId);
    QueueSQLRequest(szQuery);
-   sprintf(szQuery, "DELETE FROM thresholds WHERE item_id=%d", m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM thresholds WHERE item_id=%d"), m_dwId);
    QueueSQLRequest(szQuery);
-   sprintf(szQuery, "DELETE FROM dci_schedules WHERE item_id=%d", m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM dci_schedules WHERE item_id=%d"), m_dwId);
    QueueSQLRequest(szQuery);
 }
 
@@ -1158,10 +1159,10 @@ void DCItem::transform(ItemValue &value, time_t nElapsedTime)
                value = ((double)value - (double)m_prevRawValue) / (double)nElapsedTime;
                break;
             case DCI_DT_STRING:
-               // I don't see any meaning in "average delta per second (minute)" for string
+               // I don't see any meaning in _T("average delta per second (minute)") for string
                // values, so result will be 0 if there are no difference between
                // current and previous values, and 1 otherwise
-               value = (LONG)((strcmp((const TCHAR *)value, (const TCHAR *)m_prevRawValue) == 0) ? 0 : 1);
+               value = (LONG)((_tcscmp((const TCHAR *)value, (const TCHAR *)m_prevRawValue) == 0) ? 0 : 1);
                break;
             default:
                // Delta calculation is not supported for other types
@@ -1177,7 +1178,7 @@ void DCItem::transform(ItemValue &value, time_t nElapsedTime)
       NXSL_Value *pValue;
       NXSL_ServerEnv *pEnv;
 
-      pValue = new NXSL_Value((char *)((const char *)value));
+      pValue = new NXSL_Value((const TCHAR *)value);
       pEnv = new NXSL_ServerEnv;
       m_pScript->setGlobalVariable(_T("$node"), new NXSL_Value(new NXSL_Object(&g_nxslNodeClass, m_pNode)));
        
@@ -1217,7 +1218,7 @@ void DCItem::transform(ItemValue &value, time_t nElapsedTime)
 
          _sntprintf(szBuffer, 1024, _T("DCI::%s::%d"),
                     (m_pNode != NULL) ? m_pNode->Name() : _T("(null)"), m_dwId);
-         PostEvent(EVENT_SCRIPT_ERROR, g_dwMgmtNode, _T("ssd"), szBuffer,
+         PostEvent(EVENT_SCRIPT_ERROR, g_dwMgmtNode, "ssd", szBuffer,
                    m_pScript->getErrorText(), m_dwId);
       }
    }
@@ -1327,31 +1328,31 @@ void DCItem::updateCacheSize(DWORD dwCondId)
       if (m_pNode != NULL)
       {
          DB_ASYNC_RESULT hResult;
-         char szBuffer[MAX_DB_STRING];
+         TCHAR szBuffer[MAX_DB_STRING];
          BOOL bHasData;
 
          switch(g_nDBSyntax)
          {
             case DB_SYNTAX_MSSQL:
-               sprintf(szBuffer, "SELECT TOP %d idata_value,idata_timestamp FROM idata_%d "
-                                 "WHERE item_id=%d ORDER BY idata_timestamp DESC",
+               _sntprintf(szBuffer, MAX_DB_STRING, _T("SELECT TOP %d idata_value,idata_timestamp FROM idata_%d ")
+                                 _T("WHERE item_id=%d ORDER BY idata_timestamp DESC"),
                        dwRequiredSize, m_pNode->Id(), m_dwId);
                break;
             case DB_SYNTAX_ORACLE:
-               sprintf(szBuffer, "SELECT idata_value,idata_timestamp FROM idata_%d "
-                                 "WHERE item_id=%d AND ROWNUM <= %d ORDER BY idata_timestamp DESC",
+               _sntprintf(szBuffer, MAX_DB_STRING, _T("SELECT idata_value,idata_timestamp FROM idata_%d ")
+                                 _T("WHERE item_id=%d AND ROWNUM <= %d ORDER BY idata_timestamp DESC"),
                        m_pNode->Id(), m_dwId, dwRequiredSize);
                break;
             case DB_SYNTAX_MYSQL:
             case DB_SYNTAX_PGSQL:
             case DB_SYNTAX_SQLITE:
-               sprintf(szBuffer, "SELECT idata_value,idata_timestamp FROM idata_%d "
-                                 "WHERE item_id=%d ORDER BY idata_timestamp DESC LIMIT %d",
+               _sntprintf(szBuffer, MAX_DB_STRING, _T("SELECT idata_value,idata_timestamp FROM idata_%d ")
+                                 _T("WHERE item_id=%d ORDER BY idata_timestamp DESC LIMIT %d"),
                        m_pNode->Id(), m_dwId, dwRequiredSize);
                break;
             default:
-               sprintf(szBuffer, "SELECT idata_value,idata_timestamp FROM idata_%d "
-                                 "WHERE item_id=%d ORDER BY idata_timestamp DESC",
+               _sntprintf(szBuffer, MAX_DB_STRING, _T("SELECT idata_value,idata_timestamp FROM idata_%d ")
+                                 _T("WHERE item_id=%d ORDER BY idata_timestamp DESC"),
                        m_pNode->Id(), m_dwId);
                break;
          }
@@ -1564,7 +1565,7 @@ static BOOL MatchScheduleElement(TCHAR *pszPattern, int nValue)
    {
       *ptr = 0;
       ptr++;
-      nStep = atoi(ptr);
+      nStep = _tcstol(ptr, NULL, 10);
    }
    else
    {
@@ -1584,13 +1585,13 @@ static BOOL MatchScheduleElement(TCHAR *pszPattern, int nValue)
                return FALSE;  // Form like 1-2-3 is invalid
             bRange = TRUE;
             *ptr = 0;
-            nPrev = atoi(curr);
+            nPrev = _tcstol(curr, NULL, 10);
             break;
          case 0:
             bRun = FALSE;
          case ',':
             *ptr = 0;
-            nCurr = atoi(curr);
+            nCurr = _tcstol(curr, NULL, 10);
             if (bRange)
             {
                if ((nValue >= nPrev) && (nValue <= nCurr))
@@ -1619,7 +1620,8 @@ check_step:
 
 static BOOL MatchSchedule(struct tm *pCurrTime, TCHAR *pszSchedule)
 {
-   TCHAR *pszCurr, szValue[256];
+   const TCHAR *pszCurr;
+       TCHAR szValue[256];
 
    // Minute
    pszCurr = ExtractWord(pszSchedule, szValue);
@@ -2063,19 +2065,19 @@ void DCItem::expandMacros(const TCHAR *src, TCHAR *dst, size_t dstLen)
                                        NXSL_Value *result = script->getResult();
                                        if (result != NULL)
                                                temp += CHECK_NULL_EX(result->getValueAsCString());
-                        DbgPrintf(4, "DCItem::expandMacros(%d,\"%s\"): Script %s executed successfully", m_dwId, src, &macro[7]);
+                        DbgPrintf(4, _T("DCItem::expandMacros(%d,\"%s\"): Script %s executed successfully"), m_dwId, src, &macro[7]);
                                }
                                else
                                {
-                        DbgPrintf(4, "DCItem::expandMacros(%d,\"%s\"): Script %s execution error: %s",
+                        DbgPrintf(4, _T("DCItem::expandMacros(%d,\"%s\"): Script %s execution error: %s"),
                                                  m_dwId, src, &macro[7], script->getErrorText());
-                                       PostEvent(EVENT_SCRIPT_ERROR, g_dwMgmtNode, _T("ssd"), &macro[7],
+                                       PostEvent(EVENT_SCRIPT_ERROR, g_dwMgmtNode, "ssd", &macro[7],
                                                                 script->getErrorText(), m_dwId);
                                }
                        }
                        else
                        {
-                DbgPrintf(4, "DCItem::expandMacros(%d,\"%s\"): Cannot find script %s", m_dwId, src, &macro[7]);
+                DbgPrintf(4, _T("DCItem::expandMacros(%d,\"%s\"): Cannot find script %s"), m_dwId, src, &macro[7]);
                        }
              g_pScriptLibrary->unlock();
                }
index 56e7e0b..a07b683 100644 (file)
@@ -177,7 +177,7 @@ BOOL Threshold::saveToDB(DB_HANDLE hdb, DWORD dwIndex)
    BOOL bNewObject = TRUE;
 
    // Check for object's existence in database
-   _stprintf(szQuery, _T("SELECT threshold_id FROM thresholds WHERE threshold_id=%d"), m_id);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("SELECT threshold_id FROM thresholds WHERE threshold_id=%d"), m_id);
    hResult = DBSelect(hdb, szQuery);
    if (hResult != 0)
    {
@@ -189,18 +189,20 @@ BOOL Threshold::saveToDB(DB_HANDLE hdb, DWORD dwIndex)
    // Prepare and execute query
    pszEscValue = EncodeSQLString(m_value.String());
    if (bNewObject)
-      sprintf(szQuery, "INSERT INTO thresholds (threshold_id,item_id,fire_value,rearm_value,"
-                       "check_function,check_operation,parameter_1,parameter_2,event_code,"
-                       "sequence_number,current_state,rearm_event_code,repeat_interval) VALUES "
-                       "(%d,%d,'%s','#00',%d,%d,%d,%d,%d,%d,%d,%d,%d)", 
+      _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), 
+                             _T("INSERT INTO thresholds (threshold_id,item_id,fire_value,rearm_value,")
+                    _T("check_function,check_operation,parameter_1,parameter_2,event_code,")
+                    _T("sequence_number,current_state,rearm_event_code,repeat_interval) VALUES ")
+                    _T("(%d,%d,'%s','#00',%d,%d,%d,%d,%d,%d,%d,%d,%d)"), 
               m_id, m_itemId, pszEscValue, m_function, m_operation, m_param1,
               m_param2, m_eventCode, dwIndex, m_isReached, m_rearmEventCode,
                                  m_repeatInterval);
    else
-      sprintf(szQuery, "UPDATE thresholds SET item_id=%d,fire_value='%s',check_function=%d,"
-                       "check_operation=%d,parameter_1=%d,parameter_2=%d,event_code=%d,"
-                       "sequence_number=%d,current_state=%d,"
-                       "rearm_event_code=%d,repeat_interval=%d WHERE threshold_id=%d",
+      _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), 
+                             _T("UPDATE thresholds SET item_id=%d,fire_value='%s',check_function=%d,")
+                    _T("check_operation=%d,parameter_1=%d,parameter_2=%d,event_code=%d,")
+                    _T("sequence_number=%d,current_state=%d,")
+                    _T("rearm_event_code=%d,repeat_interval=%d WHERE threshold_id=%d"),
               m_itemId, pszEscValue, m_function, m_operation, m_param1,
               m_param2, m_eventCode, dwIndex, m_isReached,
               m_rearmEventCode, m_repeatInterval, m_id);
@@ -316,7 +318,7 @@ int Threshold::check(ItemValue &value, ItemValue **ppPrevValues, ItemValue &fval
                   bMatch = ((double)fvalue == (double)m_value);
                   break;
                case DCI_DT_STRING:
-                  bMatch = !strcmp(fvalue.String(), m_value.String());
+                  bMatch = !_tcscmp(fvalue.String(), m_value.String());
                   break;
             }
             break;
@@ -379,7 +381,7 @@ int Threshold::check(ItemValue &value, ItemValue **ppPrevValues, ItemValue &fval
                   bMatch = ((double)fvalue != (double)m_value);
                   break;
                case DCI_DT_STRING:
-                  bMatch = strcmp(fvalue.String(), m_value.String());
+                  bMatch = _tcscmp(fvalue.String(), m_value.String());
                   break;
             }
             break;
@@ -651,7 +653,7 @@ BOOL Threshold::compare(Threshold *pThr)
          bMatch = ((double)pThr->m_value == (double)m_value);
          break;
       case DCI_DT_STRING:
-         bMatch = !strcmp(pThr->m_value.String(), m_value.String());
+         bMatch = !_tcscmp(pThr->m_value.String(), m_value.String());
          break;
       default:
          bMatch = TRUE;
index 52c6c97..02bffef 100644 (file)
@@ -47,11 +47,11 @@ ItemValue::ItemValue()
 ItemValue::ItemValue(const TCHAR *pszValue, DWORD dwTimeStamp)
 {
    nx_strncpy(m_szString, pszValue, MAX_DB_STRING);
-   m_iInt32 = strtol(m_szString, NULL, 0);
-   m_iInt64 = strtoll(m_szString, NULL, 0);
-   m_dwInt32 = strtoul(m_szString, NULL, 0);
-   m_qwInt64 = strtoull(m_szString, NULL, 0);
-   m_dFloat = strtod(m_szString, NULL);
+   m_iInt32 = _tcstol(m_szString, NULL, 0);
+   m_iInt64 = _tcstoll(m_szString, NULL, 0);
+   m_dwInt32 = _tcstoul(m_szString, NULL, 0);
+   m_qwInt64 = _tcstoull(m_szString, NULL, 0);
+   m_dFloat = _tcstod(m_szString, NULL);
 
    if (dwTimeStamp == 0)
       m_dwTimeStamp = (DWORD)time(NULL);
@@ -103,18 +103,18 @@ const ItemValue& ItemValue::operator=(const ItemValue &src)
 const ItemValue& ItemValue::operator=(const TCHAR *pszStr)
 {
    nx_strncpy(m_szString, pszStr, MAX_DB_STRING);
-   m_iInt32 = strtol(m_szString, NULL, 0);
-   m_iInt64 = strtoll(m_szString, NULL, 0);
-   m_dwInt32 = strtoul(m_szString, NULL, 0);
-   m_qwInt64 = strtoull(m_szString, NULL, 0);
-   m_dFloat = strtod(m_szString, NULL);
+   m_iInt32 = _tcstol(m_szString, NULL, 0);
+   m_iInt64 = _tcstoll(m_szString, NULL, 0);
+   m_dwInt32 = _tcstoul(m_szString, NULL, 0);
+   m_qwInt64 = _tcstoull(m_szString, NULL, 0);
+   m_dFloat = _tcstod(m_szString, NULL);
    return *this;
 }
 
 const ItemValue& ItemValue::operator=(double dFloat)
 {
    m_dFloat = dFloat;
-   sprintf(m_szString, "%f", m_dFloat);
+   _sntprintf(m_szString, MAX_DB_STRING, _T("%f"), m_dFloat);
    m_iInt32 = (LONG)m_dFloat;
    m_iInt64 = (INT64)m_dFloat;
    m_dwInt32 = (DWORD)m_dFloat;
@@ -125,7 +125,7 @@ const ItemValue& ItemValue::operator=(double dFloat)
 const ItemValue& ItemValue::operator=(LONG iInt32)
 {
    m_iInt32 = iInt32;
-   sprintf(m_szString, "%d", m_iInt32);
+   _sntprintf(m_szString, MAX_DB_STRING, _T("%d"), m_iInt32);
    m_dFloat = (double)m_iInt32;
    m_iInt64 = (INT64)m_iInt32;
    m_dwInt32 = (DWORD)m_iInt32;
@@ -136,7 +136,7 @@ const ItemValue& ItemValue::operator=(LONG iInt32)
 const ItemValue& ItemValue::operator=(INT64 iInt64)
 {
    m_iInt64 = iInt64;
-   sprintf(m_szString, INT64_FMT, m_iInt64);
+   _sntprintf(m_szString, MAX_DB_STRING, INT64_FMT, m_iInt64);
    m_dFloat = (double)m_iInt64;
    m_iInt32 = (LONG)m_iInt64;
    m_dwInt32 = (DWORD)m_iInt64;
@@ -147,7 +147,7 @@ const ItemValue& ItemValue::operator=(INT64 iInt64)
 const ItemValue& ItemValue::operator=(DWORD dwInt32)
 {
    m_dwInt32 = dwInt32;
-   sprintf(m_szString, "%u", m_dwInt32);
+   _sntprintf(m_szString, MAX_DB_STRING, _T("%u"), m_dwInt32);
    m_dFloat = (double)m_dwInt32;
    m_iInt32 = (LONG)m_dwInt32;
    m_iInt64 = (INT64)m_dwInt32;
@@ -158,7 +158,7 @@ const ItemValue& ItemValue::operator=(DWORD dwInt32)
 const ItemValue& ItemValue::operator=(QWORD qwInt64)
 {
    m_qwInt64 = qwInt64;
-   sprintf(m_szString, UINT64_FMT, m_qwInt64);
+   _sntprintf(m_szString, MAX_DB_STRING, UINT64_FMT, m_qwInt64);
    m_dFloat = (double)((INT64)m_qwInt64);
    m_iInt32 = (LONG)m_qwInt64;
    m_iInt64 = (INT64)m_qwInt64;
index 23d730b..d572c5d 100644 (file)
@@ -77,14 +77,14 @@ void DbgTestRWLock(RWLOCK hLock, const TCHAR *szName, CONSOLE_CTX pCtx)
 // Print message to console, either local or remote
 //
 
-void ConsolePrintf(CONSOLE_CTX pCtx, const char *pszFormat, ...)
+void ConsolePrintf(CONSOLE_CTX pCtx, const TCHAR *pszFormat, ...)
 {
    va_list args;
 
    va_start(args, pszFormat);
    if (pCtx->hSocket == -1)
    {
-      vprintf(pszFormat, args);
+      _vtprintf(pszFormat, args);
    }
    else
    {
@@ -115,9 +115,9 @@ void ShowServerStats(CONSOLE_CTX pCtx)
       dwNumItems += ((Node *)g_pNodeIndexByAddr[i].pObject)->getItemCount();
    RWLockUnlock(g_rwlockNodeIndex);
 
-   ConsolePrintf(pCtx, "Total number of objects:     %d\n"
-                       "Number of monitored nodes:   %d\n"
-                       "Number of collectable DCIs:  %d\n\n",
+   ConsolePrintf(pCtx, _T("Total number of objects:     %d\n")
+                       _T("Number of monitored nodes:   %d\n")
+                       _T("Number of collectable DCIs:  %d\n\n"),
                  g_dwIdIndexSize, g_dwNodeAddrIndexSize, dwNumItems);
 }
 
@@ -126,10 +126,10 @@ void ShowServerStats(CONSOLE_CTX pCtx)
 // Show queue stats
 //
 
-void ShowQueueStats(CONSOLE_CTX pCtx, Queue *pQueue, const char *pszName)
+void ShowQueueStats(CONSOLE_CTX pCtx, Queue *pQueue, const TCHAR *pszName)
 {
    if (pQueue != NULL)
-      ConsolePrintf(pCtx, "%-32s : %d\n", pszName, pQueue->Size());
+      ConsolePrintf(pCtx, _T("%-32s : %d\n"), pszName, pQueue->Size());
 }
 
 
@@ -141,27 +141,28 @@ void ShowQueueStats(CONSOLE_CTX pCtx, Queue *pQueue, const char *pszName)
 
 void DumpProcess(CONSOLE_CTX pCtx)
 {
-       STARTUPINFO si;
+       STARTUPINFOA si;
        PROCESS_INFORMATION pi;
-       char cmdLine[64], buffer[256];
+       char cmdLine[64];
 
-       ConsolePrintf(pCtx, "Dumping process to disk...\n");
+       ConsolePrintf(pCtx, _T("Dumping process to disk...\n"));
 
        sprintf(cmdLine, "netxmsd.exe --dump %d", GetCurrentProcessId());
        memset(&si, 0, sizeof(STARTUPINFO));
        si.cb = sizeof(STARTUPINFO);
-       if (CreateProcess(NULL, cmdLine, NULL, NULL, FALSE,
-                         (g_dwFlags & AF_DAEMON) ? CREATE_NO_WINDOW : 0, NULL, NULL, &si, &pi))
+       if (CreateProcessA(NULL, cmdLine, NULL, NULL, FALSE,
+                          (g_dwFlags & AF_DAEMON) ? CREATE_NO_WINDOW : 0, NULL, NULL, &si, &pi))
        {
                WaitForSingleObject(pi.hProcess, INFINITE);
                CloseHandle(pi.hThread);
                CloseHandle(pi.hProcess);
                
-               ConsolePrintf(pCtx, "Done.\n");
+               ConsolePrintf(pCtx, _T("Done.\n"));
        }
        else
        {
-               ConsolePrintf(pCtx, "Dump error: CreateProcess() failed (%s)\n", GetSystemErrorText(GetLastError(), buffer, 256));
+               TCHAR buffer[256];
+               ConsolePrintf(pCtx, _T("Dump error: CreateProcess() failed (%s)\n"), GetSystemErrorText(GetLastError(), buffer, 256));
        }
 }
 
index a00776a..c5e0ff0 100644 (file)
@@ -1,6 +1,6 @@
 /* 
 ** NetXMS - Network Management System
-** Copyright (C) 2003 Victor Kirhenshtein
+** Copyright (C) 2003-2010 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
@@ -72,7 +72,7 @@ typedef struct
 // Static data
 //
 
-static char m_szSmtpServer[MAX_PATH] = "localhost";
+static TCHAR m_szSmtpServer[MAX_PATH] = _T("localhost");
 static WORD m_wSmtpPort = 25;
 static char m_szFromAddr[MAX_PATH] = "netxms@localhost";
 static char m_szFromName[MAX_PATH] = "NetXMS Server";
@@ -154,7 +154,6 @@ static int GetSMTPResponse(SOCKET hSocket, char *pszBuffer, int *pnBufPos)
 static DWORD SendMail(char *pszRcpt, char *pszSubject, char *pszText)
 {
    SOCKET hSocket;
-   struct hostent *hs;
    struct sockaddr_in sa;
    char szBuffer[SMTP_BUFFER_SIZE];
    int iResp, iState = STATE_INITIAL, nBufPos = 0;
@@ -162,7 +161,7 @@ static DWORD SendMail(char *pszRcpt, char *pszSubject, char *pszText)
        char szEncoding[128];
 
        // get mail encoding from DB
-       ConfigReadStr("MailEncoding", szEncoding, sizeof(szEncoding), "iso-8859-1");
+       ConfigReadStrA(_T("MailEncoding"), szEncoding, sizeof(szEncoding) / sizeof(TCHAR), "iso-8859-1");
 
    // Fill in address structure
    memset(&sa, 0, sizeof(sa));
@@ -170,16 +169,7 @@ static DWORD SendMail(char *pszRcpt, char *pszSubject, char *pszText)
    sa.sin_port = htons(m_wSmtpPort);
 
    // Resolve hostname
-   hs = gethostbyname(m_szSmtpServer);
-   if (hs != NULL)
-   {
-      memcpy(&sa.sin_addr.s_addr, hs->h_addr, sizeof(DWORD));
-   }
-   else
-   {
-      sa.sin_addr.s_addr = inet_addr(m_szSmtpServer);
-   }
-
+       sa.sin_addr.s_addr = ResolveHostName(m_szSmtpServer);
    if ((sa.sin_addr.s_addr == INADDR_ANY) || (sa.sin_addr.s_addr == INADDR_NONE))
       return SMTP_ERR_BAD_SERVER_NAME;
 
@@ -361,12 +351,12 @@ static THREAD_RESULT THREAD_CALL MailerThread(void *pArg)
 {
    MAIL_ENVELOPE *pEnvelope;
    DWORD dwResult;
-   static const char *m_szErrorText[] =
+   static const TCHAR *m_szErrorText[] =
    {
-      "Sent successfully",
-      "Unable to resolve SMTP server name",
-      "Communication failure",
-      "SMTP conversation failure"
+      _T("Sent successfully"),
+      _T("Unable to resolve SMTP server name"),
+      _T("Communication failure"),
+      _T("SMTP conversation failure")
    };
 
    while(1)
@@ -375,10 +365,10 @@ static THREAD_RESULT THREAD_CALL MailerThread(void *pArg)
       if (pEnvelope == INVALID_POINTER_VALUE)
          break;
 
-      ConfigReadStr("SMTPServer", m_szSmtpServer, MAX_PATH, "localhost");
-      ConfigReadStr("SMTPFromAddr", m_szFromAddr, MAX_PATH, "netxms@localhost");
-      ConfigReadStr("SMTPFromName", m_szFromName, MAX_PATH, "NetXMS Server");
-      m_wSmtpPort = (WORD)ConfigReadInt("SMTPPort", 25);
+      ConfigReadStr(_T("SMTPServer"), m_szSmtpServer, MAX_PATH, _T("localhost"));
+      ConfigReadStrA(_T("SMTPFromAddr"), m_szFromAddr, MAX_PATH, "netxms@localhost");
+      ConfigReadStrA(_T("SMTPFromName"), m_szFromName, MAX_PATH, "NetXMS Server");
+      m_wSmtpPort = (WORD)ConfigReadInt(_T("SMTPPort"), 25);
 
       dwResult = SendMail(pEnvelope->szRcptAddr, pEnvelope->szSubject, pEnvelope->pszText);
       if (dwResult != SMTP_ERR_SUCCESS)
@@ -436,14 +426,22 @@ void ShutdownMailer(void)
 // Post e-mail to queue
 //
 
-void NXCORE_EXPORTABLE PostMail(char *pszRcpt, char *pszSubject, char *pszText)
+void NXCORE_EXPORTABLE PostMail(const TCHAR *pszRcpt, const TCHAR *pszSubject, const TCHAR *pszText)
 {
    MAIL_ENVELOPE *pEnvelope;
 
    pEnvelope = (MAIL_ENVELOPE *)malloc(sizeof(MAIL_ENVELOPE));
+#ifdef UNICODE
+       WideCharToMultiByte(CP_ACP, WC_DEFAULTCHAR | WC_COMPOSITECHECK, pszRcpt, -1, pEnvelope->szRcptAddr, MAX_RCPT_ADDR_LEN, NULL, NULL);
+       pEnvelope->szRcptAddr[MAX_RCPT_ADDR_LEN - 1] = 0;
+       WideCharToMultiByte(CP_ACP, WC_DEFAULTCHAR | WC_COMPOSITECHECK, pszSubject, -1, pEnvelope->szSubject, MAX_EMAIL_SUBJECT_LEN, NULL, NULL);
+       pEnvelope->szSubject[MAX_EMAIL_SUBJECT_LEN - 1] = 0;
+       pEnvelope->pszText = MBStringFromWideString(pszText);
+#else
    nx_strncpy(pEnvelope->szRcptAddr, pszRcpt, MAX_RCPT_ADDR_LEN);
    nx_strncpy(pEnvelope->szSubject, pszSubject, MAX_EMAIL_SUBJECT_LEN);
-   pEnvelope->pszText = strdup(pszText);
+   pEnvelope->pszText = _tcsdup(pszText);
+#endif
        pEnvelope->nRetryCount = ConfigReadInt(_T("SMTPRetryCount"), 1);
    m_pMailerQueue->Put(pEnvelope);
 }
index 1d8bd8f..b0531a9 100644 (file)
@@ -31,7 +31,7 @@ Network::Network()
         :NetObj()
 {
    m_dwId = BUILTIN_OID_NETWORK;
-   strcpy(m_szName, "Entire Network");
+   _tcscpy(m_szName, _T("Entire Network"));
 }
 
 
index abf6625..c8db5ea 100644 (file)
@@ -433,12 +433,12 @@ void EPRule::GenerateAlarm(Event *pEvent)
 BOOL EPRule::LoadFromDB()
 {
    DB_RESULT hResult;
-   char szQuery[256], name[MAX_DB_STRING], value[MAX_DB_STRING];
+   TCHAR szQuery[256], name[MAX_DB_STRING], value[MAX_DB_STRING];
    BOOL bSuccess = TRUE;
    DWORD i, count;
    
    // Load rule's sources
-   sprintf(szQuery, "SELECT object_id FROM policy_source_list WHERE rule_id=%d", m_dwId);
+   _sntprintf(szQuery, 256, _T("SELECT object_id FROM policy_source_list WHERE rule_id=%d"), m_dwId);
    hResult = DBSelect(g_hCoreDB, szQuery);
    if (hResult != NULL)
    {
@@ -454,7 +454,7 @@ BOOL EPRule::LoadFromDB()
    }
 
    // Load rule's events
-   sprintf(szQuery, "SELECT event_code FROM policy_event_list WHERE rule_id=%d", m_dwId);
+   _sntprintf(szQuery, 256, _T("SELECT event_code FROM policy_event_list WHERE rule_id=%d"), m_dwId);
    hResult = DBSelect(g_hCoreDB, szQuery);
    if (hResult != NULL)
    {
@@ -470,7 +470,7 @@ BOOL EPRule::LoadFromDB()
    }
 
    // Load rule's actions
-   sprintf(szQuery, "SELECT action_id FROM policy_action_list WHERE rule_id=%d", m_dwId);
+   _sntprintf(szQuery, 256, _T("SELECT action_id FROM policy_action_list WHERE rule_id=%d"), m_dwId);
    hResult = DBSelect(g_hCoreDB, szQuery);
    if (hResult != NULL)
    {
@@ -486,7 +486,7 @@ BOOL EPRule::LoadFromDB()
    }
    
    // Load situation attributes
-   sprintf(szQuery, "SELECT attr_name,attr_value FROM policy_situation_attr_list WHERE rule_id=%d", m_dwId);
+   _sntprintf(szQuery, 256, _T("SELECT attr_name,attr_value FROM policy_situation_attr_list WHERE rule_id=%d"), m_dwId);
    hResult = DBSelect(g_hCoreDB, szQuery);
    if (hResult != NULL)
    {
@@ -519,10 +519,10 @@ void EPRule::SaveToDB()
    TCHAR *pszComment, *pszEscKey, *pszEscMessage,
              *pszEscScript, *pszQuery, *pszEscSituationInstance,
                        *pszEscName, *pszEscValue;
-   DWORD i;
+   DWORD i, len;
 
-   pszQuery = (TCHAR *)malloc((_tcslen(CHECK_NULL(m_pszComment)) +
-                               _tcslen(CHECK_NULL(m_pszScript)) + 4096) * sizeof(TCHAR));
+       len = (DWORD)(_tcslen(CHECK_NULL(m_pszComment)) + _tcslen(CHECK_NULL(m_pszScript)) + 4096);
+   pszQuery = (TCHAR *)malloc(len * sizeof(TCHAR));
 
    // General attributes
    pszComment = EncodeSQLString(m_pszComment);
@@ -530,7 +530,7 @@ void EPRule::SaveToDB()
    pszEscMessage = EncodeSQLString(m_szAlarmMessage);
    pszEscScript = EncodeSQLString(m_pszScript);
        pszEscSituationInstance = EncodeSQLString(m_szSituationInstance);
-   _stprintf(pszQuery, _T("INSERT INTO event_policy (rule_id,flags,comments,alarm_message,")
+   _sntprintf(pszQuery, len, _T("INSERT INTO event_policy (rule_id,flags,comments,alarm_message,")
                        _T("alarm_severity,alarm_key,script,alarm_timeout,alarm_timeout_event,")
                                                          _T("situation_id,situation_instance) ")
                        _T("VALUES (%d,%d,'%s','%s',%d,'%s','%s',%d,%d,%d,'%s')"),
@@ -547,7 +547,7 @@ void EPRule::SaveToDB()
    // Actions
    for(i = 0; i < m_dwNumActions; i++)
    {
-      _stprintf(pszQuery, _T("INSERT INTO policy_action_list (rule_id,action_id) VALUES (%d,%d)"),
+      _sntprintf(pszQuery, len, _T("INSERT INTO policy_action_list (rule_id,action_id) VALUES (%d,%d)"),
                 m_dwId, m_pdwActionList[i]);
       DBQuery(g_hCoreDB, pszQuery);
    }
@@ -555,7 +555,7 @@ void EPRule::SaveToDB()
    // Events
    for(i = 0; i < m_dwNumEvents; i++)
    {
-      _stprintf(pszQuery, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"),
+      _sntprintf(pszQuery, len, _T("INSERT INTO policy_event_list (rule_id,event_code) VALUES (%d,%d)"),
                 m_dwId, m_pdwEventList[i]);
       DBQuery(g_hCoreDB, pszQuery);
    }
@@ -563,7 +563,7 @@ void EPRule::SaveToDB()
    // Sources
    for(i = 0; i < m_dwNumSources; i++)
    {
-      _stprintf(pszQuery, _T("INSERT INTO policy_source_list (rule_id,object_id) VALUES (%d,%d)"),
+      _sntprintf(pszQuery, len, _T("INSERT INTO policy_source_list (rule_id,object_id) VALUES (%d,%d)"),
                 m_dwId, m_pdwSourceList[i]);
       DBQuery(g_hCoreDB, pszQuery);
    }
@@ -573,7 +573,7 @@ void EPRule::SaveToDB()
        {
                pszEscName = EncodeSQLString(m_situationAttrList.getKeyByIndex(i));
                pszEscValue = EncodeSQLString(m_situationAttrList.getValueByIndex(i));
-      _stprintf(pszQuery, _T("INSERT INTO policy_situation_attr_list (rule_id,situation_id,attr_name,attr_value) VALUES (%d,%d,'%s','%s')"),
+      _sntprintf(pszQuery, len, _T("INSERT INTO policy_situation_attr_list (rule_id,situation_id,attr_name,attr_value) VALUES (%d,%d,'%s','%s')"),
                 m_dwId, m_dwSituationId, pszEscName, pszEscValue);
                free(pszEscName);
                free(pszEscValue);
index 1b6185d..b176ee1 100644 (file)
@@ -29,8 +29,8 @@
 
 Queue *g_pEventQueue = NULL;
 EventPolicy *g_pEventPolicy = NULL;
-const char *g_szStatusText[] = { "NORMAL", "WARNING", "MINOR", "MAJOR", "CRITICAL", "UNKNOWN", "UNMANAGED", "DISABLED", "TESTING" };
-const char *g_szStatusTextSmall[] = { "Normal", "Warning", "Minor", "Major", "Critical", "Unknown", "Unmanaged", "Disabled", "Testing" };
+const TCHAR *g_szStatusText[] = { _T("NORMAL"), _T("WARNING"), _T("MINOR"), _T("MAJOR"), _T("CRITICAL"), _T("UNKNOWN"), _T("UNMANAGED"), _T("DISABLED"), _T("TESTING") };
+const TCHAR *g_szStatusTextSmall[] = { _T("Normal"), _T("Warning"), _T("Minor"), _T("Major"), _T("Critical"), _T("Unknown"), _T("Unmanaged"), _T("Disabled"), _T("Testing") };
 
 
 //
@@ -89,35 +89,35 @@ Event::Event(EVENT_TEMPLATE *pTemplate, DWORD dwSourceId, const TCHAR *pszUserTa
       DWORD i;
 
       m_dwNumParameters = (DWORD)strlen(szFormat);
-      m_ppszParameters = (char **)malloc(sizeof(char *) * m_dwNumParameters);
+      m_ppszParameters = (TCHAR **)malloc(sizeof(TCHAR *) * m_dwNumParameters);
 
       for(i = 0; i < m_dwNumParameters; i++)
       {
          switch(szFormat[i])
          {
             case 's':
-               m_ppszParameters[i] = strdup(va_arg(args, char *));
+               m_ppszParameters[i] = _tcsdup(va_arg(args, TCHAR *));
                break;
             case 'd':
-               m_ppszParameters[i] = (char *)malloc(16);
-               sprintf(m_ppszParameters[i], "%d", va_arg(args, LONG));
+               m_ppszParameters[i] = (TCHAR *)malloc(16 * sizeof(TCHAR));
+               _sntprintf(m_ppszParameters[i], 16, _T("%d"), va_arg(args, LONG));
                break;
             case 'D':
-               m_ppszParameters[i] = (char *)malloc(32);
-               sprintf(m_ppszParameters[i], INT64_FMT, va_arg(args, INT64));
+               m_ppszParameters[i] = (TCHAR *)malloc(32 * sizeof(TCHAR));
+               _sntprintf(m_ppszParameters[i], 32, INT64_FMT, va_arg(args, INT64));
                break;
             case 'x':
             case 'i':
-               m_ppszParameters[i] = (char *)malloc(16);
-               sprintf(m_ppszParameters[i], "0x%08X", va_arg(args, DWORD));
+               m_ppszParameters[i] = (TCHAR *)malloc(16 * sizeof(TCHAR));
+               _sntprintf(m_ppszParameters[i], 16, _T("0x%08X"), va_arg(args, DWORD));
                break;
             case 'a':
-               m_ppszParameters[i] = (char *)malloc(16);
+               m_ppszParameters[i] = (TCHAR *)malloc(16 * sizeof(TCHAR));
                IpToStr(va_arg(args, DWORD), m_ppszParameters[i]);
                break;
             default:
-               m_ppszParameters[i] = (char *)malloc(64);
-               sprintf(m_ppszParameters[i], "BAD FORMAT \"%c\" [value = 0x%08X]", szFormat[i], va_arg(args, DWORD));
+               m_ppszParameters[i] = (TCHAR *)malloc(64 * sizeof(TCHAR));
+               _sntprintf(m_ppszParameters[i], 64, _T("BAD FORMAT \"%c\" [value = 0x%08X]"), szFormat[i], va_arg(args, DWORD));
                break;
          }
       }
@@ -211,71 +211,71 @@ TCHAR *Event::expandText(const TCHAR *pszTemplate, const TCHAR *pszAlarmMsg)
                   break;
                case 'n':   // Name of event source
                   dwSize += (DWORD)_tcslen(pObject->Name());
-                  pText = (char *)realloc(pText, dwSize);
-                  strcpy(&pText[dwPos], pObject->Name());
+                  pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
+                  _tcscpy(&pText[dwPos], pObject->Name());
                   dwPos += (DWORD)_tcslen(pObject->Name());
                   break;
                case 'a':   // IP address of event source
                   dwSize += 16;
-                  pText = (char *)realloc(pText, dwSize);
+                  pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
                   IpToStr(pObject->IpAddr(), &pText[dwPos]);
                   dwPos = (DWORD)_tcslen(pText);
                   break;
                case 'i':   // Source object identifier
                   dwSize += 10;
-                  pText = (char *)realloc(pText, dwSize);
-                  sprintf(&pText[dwPos], "0x%08X", m_dwSource);
+                  pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
+                  _sntprintf(&pText[dwPos], 11, _T("0x%08X"), m_dwSource);
                   dwPos = (DWORD)_tcslen(pText);
                   break;
                case 't':   // Event's timestamp
                   dwSize += 32;
-                  pText = (char *)realloc(pText, dwSize);
+                  pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
                   lt = localtime(&m_tTimeStamp);
-                  strftime(&pText[dwPos], 32, "%d-%b-%Y %H:%M:%S", lt);
+                  _tcsftime(&pText[dwPos], 32, _T("%d-%b-%Y %H:%M:%S"), lt);
                   dwPos = (DWORD)_tcslen(pText);
                   break;
                case 'T':   // Event's timestamp as number of seconds since epoch
                   dwSize += 16;
-                  pText = (char *)realloc(pText, dwSize);
-                  sprintf(&pText[dwPos], "%lu", m_tTimeStamp);
+                  pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
+                  _sntprintf(&pText[dwPos], 16, _T("%lu"), m_tTimeStamp);
                   dwPos = (DWORD)_tcslen(pText);
                   break;
                case 'c':   // Event code
                   dwSize += 16;
-                  pText = (char *)realloc(pText, dwSize);
-                  sprintf(&pText[dwPos], "%u", m_dwCode);
+                  pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
+                  _sntprintf(&pText[dwPos], 16, _T("%u"), m_dwCode);
                   dwPos = (DWORD)_tcslen(pText);
                   break;
                case 'N':   // Event name
                   dwSize += (DWORD)_tcslen(m_szName);
-                  pText = (char *)realloc(pText, dwSize);
-                  strcpy(&pText[dwPos], m_szName);
+                  pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
+                  _tcscpy(&pText[dwPos], m_szName);
                   dwPos += (DWORD)_tcslen(m_szName);
                   break;
                case 's':   // Severity code
                   dwSize += 3;
-                  pText = (char *)realloc(pText, dwSize);
-                  sprintf(&pText[dwPos], "%d", (int)m_dwSeverity);
+                  pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
+                  _sntprintf(&pText[dwPos], 4, _T("%d"), (int)m_dwSeverity);
                   dwPos = (DWORD)_tcslen(pText);
                   break;
                case 'S':   // Severity text
                   dwSize += (DWORD)_tcslen(g_szStatusTextSmall[m_dwSeverity]);
-                  pText = (char *)realloc(pText, dwSize);
-                  strcpy(&pText[dwPos], g_szStatusTextSmall[m_dwSeverity]);
+                  pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
+                  _tcscpy(&pText[dwPos], g_szStatusTextSmall[m_dwSeverity]);
                   dwPos += (DWORD)_tcslen(g_szStatusTextSmall[m_dwSeverity]);
                   break;
                case 'v':   // NetXMS server version
                   dwSize += (DWORD)_tcslen(NETXMS_VERSION_STRING);
-                  pText = (char *)realloc(pText, dwSize);
-                  strcpy(&pText[dwPos], NETXMS_VERSION_STRING);
+                  pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
+                  _tcscpy(&pText[dwPos], NETXMS_VERSION_STRING);
                   dwPos += (DWORD)_tcslen(NETXMS_VERSION_STRING);
                   break;
                case 'm':
                   if (m_pszMessageText != NULL)
                   {
                      dwSize += (DWORD)_tcslen(m_pszMessageText);
-                     pText = (char *)realloc(pText, dwSize);
-                     strcpy(&pText[dwPos], m_pszMessageText);
+                         pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
+                     _tcscpy(&pText[dwPos], m_pszMessageText);
                      dwPos += (DWORD)_tcslen(m_pszMessageText);
                   }
                   break;
@@ -283,8 +283,8 @@ TCHAR *Event::expandText(const TCHAR *pszTemplate, const TCHAR *pszAlarmMsg)
                   if (m_pszCustomMessage != NULL)
                   {
                      dwSize += (DWORD)_tcslen(m_pszCustomMessage);
-                     pText = (char *)realloc(pText, dwSize);
-                     strcpy(&pText[dwPos], m_pszCustomMessage);
+                         pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
+                     _tcscpy(&pText[dwPos], m_pszCustomMessage);
                      dwPos += (DWORD)_tcslen(m_pszCustomMessage);
                   }
                   break;
@@ -292,8 +292,8 @@ TCHAR *Event::expandText(const TCHAR *pszTemplate, const TCHAR *pszAlarmMsg)
                   if (pszAlarmMsg != NULL)
                   {
                      dwSize += (DWORD)_tcslen(pszAlarmMsg);
-                     pText = (char *)realloc(pText, dwSize);
-                     strcpy(&pText[dwPos], pszAlarmMsg);
+                         pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
+                     _tcscpy(&pText[dwPos], pszAlarmMsg);
                      dwPos += (DWORD)_tcslen(pszAlarmMsg);
                   }
                   break;
@@ -301,8 +301,8 @@ TCHAR *Event::expandText(const TCHAR *pszTemplate, const TCHAR *pszAlarmMsg)
                   if (m_pszUserTag != NULL)
                   {
                      dwSize += (DWORD)_tcslen(m_pszUserTag);
-                     pText = (char *)realloc(pText, dwSize);
-                     strcpy(&pText[dwPos], m_pszUserTag);
+                         pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
+                     _tcscpy(&pText[dwPos], m_pszUserTag);
                      dwPos += (DWORD)_tcslen(m_pszUserTag);
                   }
                   break;
@@ -327,13 +327,13 @@ TCHAR *Event::expandText(const TCHAR *pszTemplate, const TCHAR *pszAlarmMsg)
                   {
                      szBuffer[1] = 0;
                   }
-                  dwParam = atol(szBuffer);
+                  dwParam = _tcstoul(szBuffer, NULL, 10);
                   if ((dwParam > 0) && (dwParam <= m_dwNumParameters))
                   {
                      dwParam--;
                      dwSize += (DWORD)_tcslen(m_ppszParameters[dwParam]);
-                     pText = (char *)realloc(pText, dwSize);
-                     strcpy(&pText[dwPos], m_ppszParameters[dwParam]);
+                         pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
+                     _tcscpy(&pText[dwPos], m_ppszParameters[dwParam]);
                      dwPos += (DWORD)_tcslen(m_ppszParameters[dwParam]);
                   }
                   break;
@@ -374,25 +374,25 @@ TCHAR *Event::expandText(const TCHAR *pszTemplate, const TCHAR *pszAlarmMsg)
                                                                                if (temp != NULL)
                                                                                {
                                                                                        dwSize += (DWORD)_tcslen(temp);
-                                                                                       pText = (char *)realloc(pText, dwSize);
+                                                                                       pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
                                                                                        _tcscpy(&pText[dwPos], temp);
                                                                                        dwPos += (DWORD)_tcslen(temp);
-                                                                                       DbgPrintf(4, "Event::ExpandText(%d, \"%s\"): Script %s executed successfully",
+                                                                                       DbgPrintf(4, _T("Event::ExpandText(%d, \"%s\"): Script %s executed successfully"),
                                                                                                                 m_dwCode, pszTemplate, scriptName);
                                                                                }
                                                                        }
                                                                }
                                                                else
                                                                {
-                                                                       DbgPrintf(4, "Event::ExpandText(%d, \"%s\"): Script %s execution error: %s",
+                                                                       DbgPrintf(4, _T("Event::ExpandText(%d, \"%s\"): Script %s execution error: %s"),
                                                                                                 m_dwCode, pszTemplate, scriptName, script->getErrorText());
-                                                                       PostEvent(EVENT_SCRIPT_ERROR, g_dwMgmtNode, _T("ssd"), scriptName,
+                                                                       PostEvent(EVENT_SCRIPT_ERROR, g_dwMgmtNode, "ssd", scriptName,
                                                                                                 script->getErrorText(), 0);
                                                                }
                                                        }
                                                        else
                                                        {
-                                                               DbgPrintf(4, "Event::ExpandText(%d, \"%s\"): Cannot find script %s", m_dwCode, pszTemplate, scriptName);
+                                                               DbgPrintf(4, _T("Event::ExpandText(%d, \"%s\"): Cannot find script %s"), m_dwCode, pszTemplate, scriptName);
                                                        }
                                                        g_pScriptLibrary->unlock();
                                                }
@@ -414,7 +414,7 @@ TCHAR *Event::expandText(const TCHAR *pszTemplate, const TCHAR *pszAlarmMsg)
                                                        if (temp != NULL)
                                                        {
                                                                dwSize += (DWORD)_tcslen(temp);
-                                                               pText = (char *)realloc(pText, dwSize);
+                                                               pText = (TCHAR *)realloc(pText, dwSize * sizeof(TCHAR));
                                                                _tcscpy(&pText[dwPos], temp);
                                                                dwPos += (DWORD)_tcslen(temp);
                                                        }
@@ -482,13 +482,13 @@ void Event::prepareMessage(CSCPMessage *pMsg)
 // Load event configuration from database
 //
 
-static BOOL LoadEvents(void)
+static BOOL LoadEvents()
 {
    DB_RESULT hResult;
    DWORD i;
    BOOL bSuccess = FALSE;
 
-   hResult = DBSelect(g_hCoreDB, "SELECT event_code,severity,flags,message,description,event_name FROM event_cfg ORDER BY event_code");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT event_code,severity,flags,message,description,event_name FROM event_cfg ORDER BY event_code"));
    if (hResult != NULL)
    {
       m_dwNumTemplates = DBGetNumRows(hResult);
index 055d885..1287cd5 100644 (file)
@@ -60,7 +60,7 @@ static THREAD_RESULT THREAD_CALL EventStormDetector(void *arg)
        if (!ConfigReadInt(_T("EnableEventStormDetection"), 0))
        {
                // Event storm detection is off
-          DbgPrintf(1, "Event storm detector thread stopped because event storm detection is off");
+          DbgPrintf(1, _T("Event storm detector thread stopped because event storm detection is off"));
                return THREAD_OK;
        }
 
@@ -79,7 +79,7 @@ static THREAD_RESULT THREAD_CALL EventStormDetector(void *arg)
                        if (actualDuration >= duration)
                        {
                                g_dwFlags |= AF_EVENT_STORM_DETECTED;
-                               DbgPrintf(2, "Event storm detected: threshold=" INT64_FMT " eventsPerSecond=" INT64_FMT, eventsPerSecond, numEvents);
+                               DbgPrintf(2, _T("Event storm detected: threshold=") INT64_FMT _T(" eventsPerSecond=") INT64_FMT, eventsPerSecond, numEvents);
                                PostEvent(EVENT_EVENT_STORM_DETECTED, g_dwMgmtNode, "DdD", numEvents, duration, eventsPerSecond);
                        }
                }
@@ -87,11 +87,11 @@ static THREAD_RESULT THREAD_CALL EventStormDetector(void *arg)
                {
                        actualDuration = 0;
                        g_dwFlags &= ~AF_EVENT_STORM_DETECTED;
-                  DbgPrintf(2, "Event storm condition cleared");
+                  DbgPrintf(2, _T("Event storm condition cleared"));
                        PostEvent(EVENT_EVENT_STORM_ENDED, g_dwMgmtNode, "DdD", numEvents, duration, eventsPerSecond);
                }
        }
-   DbgPrintf(1, "Event storm detector thread stopped");
+   DbgPrintf(1, _T("Event storm detector thread stopped"));
        return THREAD_OK;
 }
 
@@ -132,11 +132,11 @@ THREAD_RESULT THREAD_CALL EventProcessor(void *arg)
                // possible event recursion in case of severe DB failure
                if ((pEvent->getFlags() & EF_LOG) && (pEvent->getCode() != EVENT_DB_QUERY_FAILED))
       {
-         char szQuery[8192];
+         TCHAR szQuery[8192];
 
-         snprintf(szQuery, 8192, "INSERT INTO event_log (event_id,event_code,event_timestamp,"
-                                 "event_source,event_severity,event_message,root_event_id,user_tag) "
-                                 "VALUES (" INT64_FMT ",%d," TIME_T_FMT ",%d,%d,%s," INT64_FMT ",%s)"
+         snprintf(szQuery, 8192, _T("INSERT INTO event_log (event_id,event_code,event_timestamp,")
+                                 _T("event_source,event_severity,event_message,root_event_id,user_tag) ")
+                                 _T("VALUES (") INT64_FMT _T(",%d,") TIME_T_FMT _T(",%d,%d,%s,") INT64_FMT _T(",%s)")
                   pEvent->getId(), pEvent->getCode(), pEvent->getTimeStamp(),
                   pEvent->getSourceId(), pEvent->getSeverity(),
                                                (const TCHAR *)DBPrepareString(g_hCoreDB, pEvent->getMessage(), EVENTLOG_MAX_MESSAGE_SIZE),
@@ -155,7 +155,7 @@ THREAD_RESULT THREAD_CALL EventProcessor(void *arg)
             pObject = g_pEntireNet;
          DbgPrintf(5, _T("EVENT %d (F:0x%04X S:%d%s) FROM %s: %s"), pEvent->getCode(), 
                    pEvent->getFlags(), pEvent->getSeverity(),
-                   (pEvent->getRootId() == 0) ? "" : " CORRELATED",
+                   (pEvent->getRootId() == 0) ? _T("") : _T(" CORRELATED"),
                    pObject->Name(), pEvent->getMessage());
       }
 
@@ -170,6 +170,6 @@ THREAD_RESULT THREAD_CALL EventProcessor(void *arg)
    }
 
        ThreadJoin(m_threadStormDetector);
-   DbgPrintf(1, "Event processing thread stopped");
+   DbgPrintf(1, _T("Event processing thread stopped"));
    return THREAD_OK;
 }
index c3293d6..1eef46d 100644 (file)
@@ -38,11 +38,11 @@ static void CleanDeletedObjects(void)
 {
    DB_RESULT hResult;
 
-   hResult = DBSelect(m_hdb, "SELECT object_id FROM deleted_objects");
+   hResult = DBSelect(m_hdb, _T("SELECT object_id FROM deleted_objects"));
    if (hResult != NULL)
    {
       DB_ASYNC_RESULT hAsyncResult;
-      char szQuery[256];
+      TCHAR szQuery[256];
       int i, iNumRows;
       DWORD dwObjectId;
 
@@ -52,16 +52,16 @@ static void CleanDeletedObjects(void)
          dwObjectId = DBGetFieldULong(hResult, i, 0);
 
          // Check if there are references to this object in event log
-         sprintf(szQuery, "SELECT event_source FROM event_log WHERE event_source=%d", dwObjectId);
+         _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("SELECT event_source FROM event_log WHERE event_source=%d"), dwObjectId);
          hAsyncResult = DBAsyncSelect(m_hdb, szQuery);
          if (hAsyncResult != NULL)
          {
             if (!DBFetch(hAsyncResult))
             {
                // No records with that source ID, so we can purge this object
-               sprintf(szQuery, "DELETE FROM deleted_objects WHERE object_id=%d", dwObjectId);
+               _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM deleted_objects WHERE object_id=%d"), dwObjectId);
                QueueSQLRequest(szQuery);
-               DbgPrintf(4, "*HK* Deleted object with id %d was purged", dwObjectId);
+               DbgPrintf(4, _T("*HK* Deleted object with id %d was purged"), dwObjectId);
             }
             DBFreeAsyncResult(m_hdb, hAsyncResult);
          }
@@ -102,8 +102,8 @@ static void DeleteEmptySubnets(void)
 
 static void PGSQLMaintenance(void)
 {
-   if (!ConfigReadInt("DisableVacuum", 0))
-      DBQuery(m_hdb, "VACUUM ANALYZE");
+   if (!ConfigReadInt(_T("DisableVacuum"), 0))
+      DBQuery(m_hdb, _T("VACUUM ANALYZE"));
 }
 
 
@@ -114,7 +114,7 @@ static void PGSQLMaintenance(void)
 THREAD_RESULT THREAD_CALL HouseKeeper(void *pArg)
 {
    time_t currTime;
-   char szQuery[256];
+   TCHAR szQuery[256];
    DWORD i, dwRetentionTime, dwInterval;
 
    // Establish separate connection to database if needed
@@ -133,7 +133,7 @@ THREAD_RESULT THREAD_CALL HouseKeeper(void *pArg)
    }
 
    // Load configuration
-   dwInterval = ConfigReadULong("HouseKeepingInterval", 3600);
+   dwInterval = ConfigReadULong(_T("HouseKeepingInterval"), 3600);
 
    // Housekeeping loop
    while(!ShutdownInProgress())
@@ -143,29 +143,29 @@ THREAD_RESULT THREAD_CALL HouseKeeper(void *pArg)
          break;      // Shutdown has arrived
 
       // Remove outdated event log records
-      dwRetentionTime = ConfigReadULong("EventLogRetentionTime", 90);
+      dwRetentionTime = ConfigReadULong(_T("EventLogRetentionTime"), 90);
       if (dwRetentionTime > 0)
       {
                        dwRetentionTime *= 86400;       // Convert days to seconds
-         sprintf(szQuery, "DELETE FROM event_log WHERE event_timestamp<%ld", currTime - dwRetentionTime);
+         _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM event_log WHERE event_timestamp<%ld"), currTime - dwRetentionTime);
          DBQuery(m_hdb, szQuery);
       }
 
       // Remove outdated syslog records
-      dwRetentionTime = ConfigReadULong("SyslogRetentionTime", 90);
+      dwRetentionTime = ConfigReadULong(_T("SyslogRetentionTime"), 90);
       if (dwRetentionTime > 0)
       {
                        dwRetentionTime *= 86400;       // Convert days to seconds
-         sprintf(szQuery, "DELETE FROM syslog WHERE msg_timestamp<%ld", currTime - dwRetentionTime);
+         _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM syslog WHERE msg_timestamp<%ld"), currTime - dwRetentionTime);
          DBQuery(m_hdb, szQuery);
       }
 
       // Remove outdated audit log records
-      dwRetentionTime = ConfigReadULong("AuditLogRetentionTime", 90);
+      dwRetentionTime = ConfigReadULong(_T("AuditLogRetentionTime"), 90);
       if (dwRetentionTime > 0)
       {
                        dwRetentionTime *= 86400;       // Convert days to seconds
-         sprintf(szQuery, "DELETE FROM audit_log WHERE timestamp<%ld", currTime - dwRetentionTime);
+         _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM audit_log WHERE timestamp<%ld"), currTime - dwRetentionTime);
          DBQuery(m_hdb, szQuery);
       }
 
@@ -192,6 +192,6 @@ THREAD_RESULT THREAD_CALL HouseKeeper(void *pArg)
    {
       DBDisconnect(m_hdb);
    }
-   DbgPrintf(1, "Housekeeper thread terminated");
+   DbgPrintf(1, _T("Housekeeper thread terminated"));
    return THREAD_OK;
 }
index a390cb9..4f8dfbc 100644 (file)
@@ -48,30 +48,30 @@ static DWORD m_dwIdLimits[NUMBER_OF_GROUPS] = { 0xFFFFFFFE, 0xFFFFFFFE, 0x7FFFFF
                                                                                                                                0xFFFFFFFE, 0xFFFFFFFE
                                               };
 static QWORD m_qwFreeEventId = 1;
-static const char *m_pszGroupNames[NUMBER_OF_GROUPS] =
+static const TCHAR *m_pszGroupNames[NUMBER_OF_GROUPS] =
 {
-   "Network Objects",
-   "Container Categories",
-   "Events",
-   "Data Collection Items",
-   "SNMP Trap",
-   "--Images",
-   "Actions",
-   "Event Groups",
-   "Data Collection Thresholds",
-   "Users",
-   "User Groups",
-   "Alarms",
-   "Alarm Notes",
-   "Packages",
-   "--Log Processing Policies",
-   "Object Tools",
-   "Scripts",
-   "Agent Configs",
-       "Graphs",
-       "Certificates",
-       "Situations",
-       "Maps"
+   _T("Network Objects"),
+   _T("Container Categories"),
+   _T("Events"),
+   _T("Data Collection Items"),
+   _T("SNMP Trap"),
+   _T("--Images"),
+   _T("Actions"),
+   _T("Event Groups"),
+   _T("Data Collection Thresholds"),
+   _T("Users"),
+   _T("User Groups"),
+   _T("Alarms"),
+   _T("Alarm Notes"),
+   _T("Packages"),
+   _T("--Log Processing Policies"),
+   _T("Object Tools"),
+   _T("Scripts"),
+   _T("Agent Configs"),
+       _T("Graphs"),
+       _T("Certificates"),
+       _T("Situations"),
+       _T("Maps")
 };
 
 
@@ -86,7 +86,7 @@ BOOL InitIdTable(void)
    m_mutexTableAccess = MutexCreate();
 
    // Get first available network object ID
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM nodes");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM nodes"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -94,7 +94,7 @@ BOOL InitIdTable(void)
                                                    DBGetFieldULong(hResult, 0, 0) + 1);
       DBFreeResult(hResult);
    }
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM subnets");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM subnets"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -102,7 +102,7 @@ BOOL InitIdTable(void)
                                                    DBGetFieldULong(hResult, 0, 0) + 1);
       DBFreeResult(hResult);
    }
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM interfaces");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM interfaces"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -110,7 +110,7 @@ BOOL InitIdTable(void)
                                                    DBGetFieldULong(hResult, 0, 0) + 1);
       DBFreeResult(hResult);
    }
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM containers");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM containers"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -118,7 +118,7 @@ BOOL InitIdTable(void)
                                                    DBGetFieldULong(hResult, 0, 0) + 1);
       DBFreeResult(hResult);
    }
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM templates");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM templates"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -126,7 +126,7 @@ BOOL InitIdTable(void)
                                                    DBGetFieldULong(hResult, 0, 0) + 1);
       DBFreeResult(hResult);
    }
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM network_services");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM network_services"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -134,7 +134,7 @@ BOOL InitIdTable(void)
                                                    DBGetFieldULong(hResult, 0, 0) + 1);
       DBFreeResult(hResult);
    }
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM conditions");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM conditions"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -142,7 +142,7 @@ BOOL InitIdTable(void)
                                                    DBGetFieldULong(hResult, 0, 0) + 1);
       DBFreeResult(hResult);
    }
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM clusters");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM clusters"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -150,7 +150,7 @@ BOOL InitIdTable(void)
                                                    DBGetFieldULong(hResult, 0, 0) + 1);
       DBFreeResult(hResult);
    }
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM ap_common");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM ap_common"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -158,7 +158,7 @@ BOOL InitIdTable(void)
                                                    DBGetFieldULong(hResult, 0, 0) + 1);
       DBFreeResult(hResult);
    }
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM network_maps");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM network_maps"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -166,7 +166,7 @@ BOOL InitIdTable(void)
                                                    DBGetFieldULong(hResult, 0, 0) + 1);
       DBFreeResult(hResult);
    }
-   hResult = DBSelect(g_hCoreDB, "SELECT max(object_id) FROM deleted_objects");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(object_id) FROM deleted_objects"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -176,7 +176,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available container category id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(category) FROM container_categories");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(category) FROM container_categories"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -185,7 +185,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available event code
-   hResult = DBSelect(g_hCoreDB, "SELECT max(event_code) FROM event_cfg");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(event_code) FROM event_cfg"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -194,7 +194,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available data collection item id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(item_id) FROM items");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(item_id) FROM items"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -203,7 +203,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available SNMP trap configuration record id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(trap_id) FROM snmp_trap_cfg");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(trap_id) FROM snmp_trap_cfg"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -212,7 +212,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available action id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(action_id) FROM actions");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(action_id) FROM actions"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -221,7 +221,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available event group id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM event_groups");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM event_groups"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -230,7 +230,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available threshold id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(threshold_id) FROM thresholds");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(threshold_id) FROM thresholds"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -240,7 +240,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available user id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM users");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM users"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -250,7 +250,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available user group id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM user_groups");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM user_groups"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -260,7 +260,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available alarm id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(alarm_id) FROM alarms");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(alarm_id) FROM alarms"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -270,7 +270,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available alarm note id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(note_id) FROM alarm_notes");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(note_id) FROM alarm_notes"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -280,7 +280,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available event identifier
-   hResult = DBSelect(g_hCoreDB, "SELECT max(event_id) FROM event_log");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(event_id) FROM event_log"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -289,7 +289,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available package id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(pkg_id) FROM agent_pkg");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(pkg_id) FROM agent_pkg"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -299,7 +299,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available object tool id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(tool_id) FROM object_tools");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(tool_id) FROM object_tools"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -309,7 +309,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available script id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(script_id) FROM script_library");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(script_id) FROM script_library"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -319,7 +319,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available agent config id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(config_id) FROM agent_configs");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(config_id) FROM agent_configs"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -329,7 +329,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available graph id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(graph_id) FROM graphs");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(graph_id) FROM graphs"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -339,7 +339,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available certificate id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(cert_id) FROM certificates");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(cert_id) FROM certificates"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -349,7 +349,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available situation id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM situations");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM situations"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -359,7 +359,7 @@ BOOL InitIdTable(void)
    }
 
    // Get first available map id
-   hResult = DBSelect(g_hCoreDB, "SELECT max(map_id) FROM maps");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(map_id) FROM maps"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -367,7 +367,7 @@ BOOL InitIdTable(void)
                                         DBGetFieldULong(hResult, 0, 0) + 1);
       DBFreeResult(hResult);
    }
-   hResult = DBSelect(g_hCoreDB, "SELECT max(id) FROM web_maps");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT max(id) FROM web_maps"));
    if (hResult != NULL)
    {
       if (DBGetNumRows(hResult) > 0)
@@ -391,7 +391,7 @@ DWORD CreateUniqueId(int iGroup)
    MutexLock(m_mutexTableAccess, INFINITE);
    if (m_dwFreeIdTable[iGroup] == m_dwIdLimits[iGroup])
    {
-      dwId = 0;   // ID zero means "no unique ID available"
+      dwId = 0;   // ID zero means _T("no unique ID available")
       nxlog_write(MSG_NO_UNIQUE_ID, EVENTLOG_ERROR_TYPE, "s", m_pszGroupNames[iGroup]);
    }
    else
index 67d267f..79756aa 100644 (file)
@@ -48,7 +48,7 @@ Interface::Interface()
 Interface::Interface(DWORD dwAddr, DWORD dwNetMask, BOOL bSyntheticMask)
           : NetObj()
 {
-   strcpy(m_szName, "unknown");
+   _tcscpy(m_szName, _T("unknown"));
    m_dwIpAddr = dwAddr;
    m_dwIpNetMask = dwNetMask;
    m_dwIfIndex = 1;
@@ -67,7 +67,7 @@ Interface::Interface(DWORD dwAddr, DWORD dwNetMask, BOOL bSyntheticMask)
 // Constructor for normal interface object
 //
 
-Interface::Interface(const char *szName, DWORD dwIndex, DWORD dwAddr, DWORD dwNetMask, DWORD dwType)
+Interface::Interface(const TCHAR *szName, DWORD dwIndex, DWORD dwAddr, DWORD dwNetMask, DWORD dwType)
           : NetObj()
 {
    nx_strncpy(m_szName, szName, MAX_OBJECT_NAME);
@@ -111,8 +111,8 @@ BOOL Interface::CreateFromDB(DWORD dwId)
    if (!LoadCommonProperties())
       return FALSE;
 
-   _sntprintf(szQuery, 256, _T("SELECT ip_addr,ip_netmask,if_type,if_index,node_id,"
-                               "mac_addr,synthetic_mask,required_polls FROM interfaces WHERE id=%d"), dwId);
+   _sntprintf(szQuery, 256, _T("SELECT ip_addr,ip_netmask,if_type,if_index,node_id,")
+                            _T("mac_addr,synthetic_mask,required_polls FROM interfaces WHERE id=%d"), dwId);
    hResult = DBSelect(g_hCoreDB, szQuery);
    if (hResult == NULL)
       return FALSE;     // Query failed
@@ -168,7 +168,7 @@ BOOL Interface::CreateFromDB(DWORD dwId)
 
 BOOL Interface::SaveToDB(DB_HANDLE hdb)
 {
-   char szQuery[1024], szMacStr[16], szIpAddr[16], szNetMask[16];
+   TCHAR szQuery[1024], szMacStr[16], szIpAddr[16], szNetMask[16];
    BOOL bNewObject = TRUE;
    Node *pNode;
    DWORD dwNodeId;
@@ -234,7 +234,7 @@ BOOL Interface::SaveToDB(DB_HANDLE hdb)
 
 BOOL Interface::DeleteFromDB(void)
 {
-   char szQuery[128];
+   TCHAR szQuery[128];
    BOOL bSuccess;
 
    bSuccess = NetObj::DeleteFromDB();
@@ -353,9 +353,9 @@ void Interface::StatusPoll(ClientSession *pSession, DWORD dwRqId,
        }
 
        int requiredPolls = (m_iRequiredPollCount > 0) ? m_iRequiredPollCount : g_nRequiredPolls;
-       SendPollerMsg(dwRqId, "      Interface is %s for %d poll%s (%d poll%s required for status change)\r\n",
-                     g_szStatusText[newStatus], m_iPollCount, (m_iPollCount == 1) ? "" : "s",
-                     requiredPolls, (requiredPolls == 1) ? "" : "s");
+       SendPollerMsg(dwRqId, _T("      Interface is %s for %d poll%s (%d poll%s required for status change)\r\n"),
+                     g_szStatusText[newStatus], m_iPollCount, (m_iPollCount == 1) ? _T("") : _T("s"),
+                     requiredPolls, (requiredPolls == 1) ? _T("") : _T("s"));
        DbgPrintf(7, _T("Interface::StatusPoll(%d,%s): newStatus=%d oldStatus=%d pollCount=%d requiredPolls=%d"),
                  m_dwId, m_szName, newStatus, oldStatus, m_iPollCount, requiredPolls);
 
@@ -377,7 +377,7 @@ void Interface::StatusPoll(ClientSession *pSession, DWORD dwRqId,
                DbgPrintf(7, _T("Interface::StatusPoll(%d,%s): status changed from %d to %d"), m_dwId, m_szName, m_iStatus, newStatus);
                m_iStatus = newStatus;
                m_iPendingStatus = -1;  // Invalidate pending status
-               SendPollerMsg(dwRqId, "      Interface status changed to %s\r\n", g_szStatusText[m_iStatus]);
+               SendPollerMsg(dwRqId, _T("      Interface status changed to %s\r\n"), g_szStatusText[m_iStatus]);
                PostEventEx(pEventQueue, 
                                                statusToEvent[m_iStatus],
                                                pNode->Id(), "dsaad", m_dwId, m_szName, m_dwIpAddr, m_dwIpNetMask,
index dc9986f..d817af1 100644 (file)
@@ -234,7 +234,7 @@ THREAD_RESULT THREAD_CALL ISCListener(void *pArg)
    // Bind socket\r
    if (bind(sock, (struct sockaddr *)&servAddr, sizeof(struct sockaddr_in)) != 0)\r
    {\r
-      nxlog_write(MSG_BIND_ERROR, EVENTLOG_ERROR_TYPE, "dse", NETXMS_ISC_PORT, "ISCListener", WSAGetLastError());\r
+      nxlog_write(MSG_BIND_ERROR, EVENTLOG_ERROR_TYPE, "dse", NETXMS_ISC_PORT, _T("ISCListener"), WSAGetLastError());\r
       closesocket(sock);\r
       /* TODO: we should initiate shutdown from here */\r
       return THREAD_OK;\r
index 7ac9bec..9fb9787 100644 (file)
@@ -68,10 +68,10 @@ static DWORD SONMPTopoHandler(DWORD dwVersion, SNMP_Variable *pVar, SNMP_Transpo
 
        // Get interface
    pRqPDU = new SNMP_PDU(SNMP_GET_REQUEST, SnmpNewRequestId(), dwVersion);
-   _tcscpy(szOid, ".1.3.6.1.4.1.45.1.6.13.2.1.1.1");   // Slot
+   _tcscpy(szOid, _T(".1.3.6.1.4.1.45.1.6.13.2.1.1.1"));       // Slot
    _tcscat(szOid, szSuffix);
        pRqPDU->bindVariable(new SNMP_Variable(szOid));
-   _tcscpy(szOid, ".1.3.6.1.4.1.45.1.6.13.2.1.1.2");   // Port
+   _tcscpy(szOid, _T(".1.3.6.1.4.1.45.1.6.13.2.1.1.2"));       // Port
    _tcscat(szOid, szSuffix);
        pRqPDU->bindVariable(new SNMP_Variable(szOid));
    dwResult = pTransport->doRequest(pRqPDU, &pRespPDU, g_dwSNMPTimeout, 3);
@@ -79,8 +79,8 @@ static DWORD SONMPTopoHandler(DWORD dwVersion, SNMP_Variable *pVar, SNMP_Transpo
 
    if (dwResult == SNMP_ERR_SUCCESS)
    {
-               _stprintf(szIfName, _T("%d/%d"), pRespPDU->getVariable(0)->GetValueAsUInt(),
-                         pRespPDU->getVariable(1)->GetValueAsUInt());
+               _sntprintf(szIfName, MAX_CONNECTOR_NAME, _T("%d/%d"), pRespPDU->getVariable(0)->GetValueAsUInt(),
+                          pRespPDU->getVariable(1)->GetValueAsUInt());
                ((PeerList *)pArg)->Add(ntohl(pVar->GetValueAsUInt()), szIfName);
       delete pRespPDU;
        }
@@ -106,7 +106,7 @@ static DWORD CDPTopoHandler(DWORD dwVersion, SNMP_Variable *pVar, SNMP_Transport
 
        // Get interface
    pRqPDU = new SNMP_PDU(SNMP_GET_REQUEST, SnmpNewRequestId(), dwVersion);
-   _tcscpy(szOid, ".1.3.6.1.4.1.9.9.23.1.2.1.1.7");    // Remote port name
+   _tcscpy(szOid, _T(".1.3.6.1.4.1.9.9.23.1.2.1.1.7"));        // Remote port name
    _tcscat(szOid, szSuffix);
        pRqPDU->bindVariable(new SNMP_Variable(szOid));
    dwResult = pTransport->doRequest(pRqPDU, &pRespPDU, g_dwSNMPTimeout, 3);
@@ -114,7 +114,7 @@ static DWORD CDPTopoHandler(DWORD dwVersion, SNMP_Variable *pVar, SNMP_Transport
 
    if (dwResult == SNMP_ERR_SUCCESS)
    {
-               ((PeerList *)pArg)->Add(ntohl(inet_addr(pVar->GetValueAsIPAddr(szIpAddr))),
+               ((PeerList *)pArg)->Add(ntohl(_t_inet_addr(pVar->GetValueAsIPAddr(szIpAddr))),
                                        pRespPDU->getVariable(0)->GetValueAsString(szIfName, MAX_CONNECTOR_NAME));
       delete pRespPDU;
        }
@@ -137,12 +137,12 @@ DWORD BuildL2Topology(nxmap_ObjList &topology, Node *pRoot, Node *pParent, int n
        pList = new PeerList;
        if (pRoot->getFlags() & NF_IS_SONMP)
        {
-               if (pRoot->CallSnmpEnumerate(".1.3.6.1.4.1.45.1.6.13.2.1.1.3", SONMPTopoHandler, pList) != SNMP_ERR_SUCCESS)
+               if (pRoot->CallSnmpEnumerate(_T(".1.3.6.1.4.1.45.1.6.13.2.1.1.3"), SONMPTopoHandler, pList) != SNMP_ERR_SUCCESS)
                        goto cleanup;
        }
        else if (pRoot->getFlags() & NF_IS_CDP)
        {
-               if (pRoot->CallSnmpEnumerate(".1.3.6.1.4.1.9.9.23.1.2.1.1.4", CDPTopoHandler, pList) != SNMP_ERR_SUCCESS)
+               if (pRoot->CallSnmpEnumerate(_T(".1.3.6.1.4.1.9.9.23.1.2.1.1.4"), CDPTopoHandler, pList) != SNMP_ERR_SUCCESS)
                        goto cleanup;
        }
 
index ece1d1d..9951db3 100644 (file)
@@ -65,32 +65,32 @@ static LOCK_INFO m_locks[NUMBER_OF_LOCKS] =
 // Will return FALSE if someone already locked database
 //
 
-BOOL InitLocks(DWORD *pdwIpAddr, char *pszInfo)
+BOOL InitLocks(DWORD *pdwIpAddr, TCHAR *pszInfo)
 {
    BOOL bSuccess = FALSE;
-   char szBuffer[256];
+   TCHAR szBuffer[256];
 
    *pdwIpAddr = UNLOCKED;
    pszInfo[0] = 0;
 
    // Check current database lock status
-   ConfigReadStr("DBLockStatus", szBuffer, 256, "ERROR");
-   if (!strcmp(szBuffer, "UNLOCKED"))
+   ConfigReadStr(_T("DBLockStatus"), szBuffer, 256, _T("ERROR"));
+   if (!_tcscmp(szBuffer, _T("UNLOCKED")))
    {
       IpToStr(GetLocalIpAddr(), szBuffer);
-      ConfigWriteStr("DBLockStatus", szBuffer, FALSE);
+      ConfigWriteStr(_T("DBLockStatus"), szBuffer, FALSE);
       GetSysInfoStr(szBuffer, sizeof(szBuffer));
-      ConfigWriteStr("DBLockInfo", szBuffer, TRUE);
-      ConfigWriteULong("DBLockPID", GetCurrentProcessId(), TRUE);
+      ConfigWriteStr(_T("DBLockInfo"), szBuffer, TRUE);
+      ConfigWriteULong(_T("DBLockPID"), GetCurrentProcessId(), TRUE);
       m_hMutexLockerAccess = MutexCreate();
       bSuccess = TRUE;
    }
    else
    {
-      if (strcmp(szBuffer, "ERROR"))
+      if (_tcscmp(szBuffer, _T("ERROR")))
       {
-         *pdwIpAddr = ntohl(inet_addr(szBuffer));
-         ConfigReadStr("DBLockInfo", pszInfo, 256, "<error>");
+         *pdwIpAddr = ntohl(_t_inet_addr(szBuffer));
+         ConfigReadStr(_T("DBLockInfo"), pszInfo, 256, _T("<error>"));
       }
    }
 
@@ -102,11 +102,11 @@ BOOL InitLocks(DWORD *pdwIpAddr, char *pszInfo)
 // Unlock database
 //
 
-void NXCORE_EXPORTABLE UnlockDB(void)
+void NXCORE_EXPORTABLE UnlockDB()
 {
-   ConfigWriteStr("DBLockStatus", "UNLOCKED", FALSE);
-   ConfigWriteStr("DBLockInfo", "", FALSE);
-   ConfigWriteULong("DBLockPID", 0, FALSE);
+   ConfigWriteStr(_T("DBLockStatus"), _T("UNLOCKED"), FALSE);
+   ConfigWriteStr(_T("DBLockInfo"), _T(""), FALSE);
+   ConfigWriteULong(_T("DBLockPID"), 0, FALSE);
 }
 
 
@@ -117,10 +117,10 @@ void NXCORE_EXPORTABLE UnlockDB(void)
 // field, and pszCurrentOwnerInfo will be filled with the value of  owner_info field.
 //
 
-BOOL LockComponent(DWORD dwId, DWORD dwLockBy, const char *pszOwnerInfo, 
-                   DWORD *pdwCurrentOwner, char *pszCurrentOwnerInfo)
+BOOL LockComponent(DWORD dwId, DWORD dwLockBy, const TCHAR *pszOwnerInfo, 
+                   DWORD *pdwCurrentOwner, TCHAR *pszCurrentOwnerInfo)
 {
-   char szBuffer[256];
+   TCHAR szBuffer[256];
    BOOL bSuccess = FALSE;
    DWORD dwTemp;
 
@@ -132,27 +132,27 @@ BOOL LockComponent(DWORD dwId, DWORD dwLockBy, const char *pszOwnerInfo,
    if (dwId >= NUMBER_OF_LOCKS)
    {
       *pdwCurrentOwner = UNLOCKED;
-      strcpy(pszCurrentOwnerInfo, "Unknown component");
+      _tcscpy(pszCurrentOwnerInfo, _T("Unknown component"));
       return FALSE;
    }
 
-   DbgPrintf(5, "*Locks* Attempting to lock component \"%s\" by %d (%s)",
-             m_locks[dwId].pszName, dwLockBy, pszOwnerInfo != NULL ? pszOwnerInfo : "NULL");
+   DbgPrintf(5, _T("*Locks* Attempting to lock component \"%s\" by %d (%s)"),
+             m_locks[dwId].pszName, dwLockBy, pszOwnerInfo != NULL ? pszOwnerInfo : _T("NULL"));
    MutexLock(m_hMutexLockerAccess, INFINITE);
    if (m_locks[dwId].dwLockStatus == UNLOCKED)
    {
       m_locks[dwId].dwLockStatus = dwLockBy;
       nx_strncpy(m_locks[dwId].szOwnerInfo, pszOwnerInfo, MAX_OWNER_INFO);
       bSuccess = TRUE;
-      DbgPrintf(5, "*Locks* Component \"%s\" successfully locked by %d (%s)",
-                m_locks[dwId].pszName, dwLockBy, pszOwnerInfo != NULL ? pszOwnerInfo : "NULL");
+      DbgPrintf(5, _T("*Locks* Component \"%s\" successfully locked by %d (%s)"),
+                m_locks[dwId].pszName, dwLockBy, pszOwnerInfo != NULL ? pszOwnerInfo : _T("NULL"));
    }
    else
    {
       *pdwCurrentOwner = m_locks[dwId].dwLockStatus;
-      strcpy(pszCurrentOwnerInfo, m_locks[dwId].szOwnerInfo);
-      DbgPrintf(5, "*Locks* Component \"%s\" cannot be locked by %d (%s) - already locked by \"%s\"",
-                m_locks[dwId].pszName, dwLockBy, pszOwnerInfo != NULL ? pszOwnerInfo : "NULL",
+      _tcscpy(pszCurrentOwnerInfo, m_locks[dwId].szOwnerInfo);
+      DbgPrintf(5, _T("*Locks* Component \"%s\" cannot be locked by %d (%s) - already locked by \"%s\""),
+                m_locks[dwId].pszName, dwLockBy, pszOwnerInfo != NULL ? pszOwnerInfo : _T("NULL"),
                 m_locks[dwId].szOwnerInfo);
    }
    MutexUnlock(m_hMutexLockerAccess);
@@ -170,7 +170,7 @@ void UnlockComponent(DWORD dwId)
    m_locks[dwId].dwLockStatus = UNLOCKED;
    m_locks[dwId].szOwnerInfo[0] = 0;
    MutexUnlock(m_hMutexLockerAccess);
-   DbgPrintf(5, "*Locks* Component \"%s\" unlocked", m_locks[dwId].pszName);
+   DbgPrintf(5, _T("*Locks* Component \"%s\" unlocked"), m_locks[dwId].pszName);
 }
 
 
@@ -190,5 +190,5 @@ void RemoveAllSessionLocks(DWORD dwSessionId)
          m_locks[i].szOwnerInfo[0] = 0;
       }
    MutexUnlock(m_hMutexLockerAccess);
-   DbgPrintf(5, "*Locks* All locks for session %d removed", dwSessionId);
+   DbgPrintf(5, _T("*Locks* All locks for session %d removed"), dwSessionId);
 }
index 515b708..a037bfc 100644 (file)
@@ -1,6 +1,6 @@
 /* 
 ** NetXMS - Network Management System
-** Copyright (C) 2003-2009 Victor Kirhenshtein
+** Copyright (C) 2003-2010 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
@@ -31,22 +31,22 @@ static NXCORE_LOG s_logs[] =
 {
        { _T("AuditLog"), _T("audit_log"), SYSTEM_ACCESS_VIEW_AUDIT_LOG,
                {
-                       { "record_id", "Record ID", LC_INTEGER },
-                       { "timestamp", "Timestamp", LC_TIMESTAMP },
-                       { "subsystem", "Subsystem", LC_TEXT },
-                       { "user_id", "User", LC_USER_ID },
-                       { "workstation", "Workstation", LC_TEXT },
-                       { "message", "Message", LC_TEXT },
+                       { _T("record_id"), _T("Record ID"), LC_INTEGER },
+                       { _T("timestamp"), _T("Timestamp"), LC_TIMESTAMP },
+                       { _T("subsystem"), _T("Subsystem"), LC_TEXT },
+                       { _T("user_id"), _T("User"), LC_USER_ID },
+                       { _T("workstation"), _T("Workstation"), LC_TEXT },
+                       { _T("message"), _T("Message"), LC_TEXT },
                        { NULL, NULL, 0 }
                }
        },
        { _T("EventLog"), _T("event_log"), SYSTEM_ACCESS_VIEW_EVENT_LOG,
                {
-                       { "event_timestamp", "Time", LC_TIMESTAMP },
-                       { "event_source", "Source", LC_OBJECT_ID },
-                       { "event_code", "Event", LC_EVENT_CODE },
-                       { "event_severity", "Severity", LC_SEVERITY },
-                       { "event_message", "Message", LC_TEXT },
+                       { _T("event_timestamp"), _T("Time"), LC_TIMESTAMP },
+                       { _T("event_source"), _T("Source"), LC_OBJECT_ID },
+                       { _T("event_code"), _T("Event"), LC_EVENT_CODE },
+                       { _T("event_severity"), _T("Severity"), LC_SEVERITY },
+                       { _T("event_message"), _T("Message"), LC_TEXT },
                        { NULL, NULL, 0 }
                }
        },
index e6a2380..b0cd2b4 100644 (file)
@@ -106,7 +106,7 @@ TCHAR NXCORE_EXPORTABLE g_szDumpDir[MAX_PATH] = DEFAULT_DUMP_DIR;
 TCHAR g_szCodePage[256] = ICONV_DEFAULT_CODEPAGE;
 TCHAR NXCORE_EXPORTABLE g_szListenAddress[MAX_PATH] = _T("0.0.0.0");
 #ifndef _WIN32
-char NXCORE_EXPORTABLE g_szPIDFile[MAX_PATH] = "/var/run/netxmsd.pid";
+char NXCORE_EXPORTABLE g_szPIDFile[MAX_PATH] = _T("/var/run/netxmsd.pid");
 #endif
 DB_HANDLE g_hCoreDB = 0;
 DWORD g_dwDiscoveryPollingInterval;
@@ -173,25 +173,25 @@ void NXCORE_EXPORTABLE ShutdownDB()
 // Check data directory for existence
 //
 
-static BOOL CheckDataDir(void)
+static BOOL CheckDataDir()
 {
-       char szBuffer[MAX_PATH];
+       TCHAR szBuffer[MAX_PATH];
 
-       if (chdir(g_szDataDir) == -1)
+       if (_tchdir(g_szDataDir) == -1)
        {
                nxlog_write(MSG_INVALID_DATA_DIR, EVENTLOG_ERROR_TYPE, "s", g_szDataDir);
                return FALSE;
        }
 
 #ifdef _WIN32
-#define MKDIR(name) _mkdir(name)
+#define MKDIR(name) _tmkdir(name)
 #else
-#define MKDIR(name) mkdir(name, 0700)
+#define MKDIR(name) _tmkdir(name, 0700)
 #endif
 
        // Create directory for mib files if it doesn't exist
-       strcpy(szBuffer, g_szDataDir);
-       strcat(szBuffer, DDIR_MIBS);
+       _tcscpy(szBuffer, g_szDataDir);
+       _tcscat(szBuffer, DDIR_MIBS);
        if (MKDIR(szBuffer) == -1)
                if (errno != EEXIST)
                {
@@ -200,8 +200,8 @@ static BOOL CheckDataDir(void)
                }
 
        // Create directory for package files if it doesn't exist
-       strcpy(szBuffer, g_szDataDir);
-       strcat(szBuffer, DDIR_PACKAGES);
+       _tcscpy(szBuffer, g_szDataDir);
+       _tcscat(szBuffer, DDIR_PACKAGES);
        if (MKDIR(szBuffer) == -1)
                if (errno != EEXIST)
                {
@@ -210,8 +210,8 @@ static BOOL CheckDataDir(void)
                }
 
        // Create directory for map background images if it doesn't exist
-       strcpy(szBuffer, g_szDataDir);
-       strcat(szBuffer, DDIR_BACKGROUNDS);
+       _tcscpy(szBuffer, g_szDataDir);
+       _tcscat(szBuffer, DDIR_BACKGROUNDS);
        if (MKDIR(szBuffer) == -1)
                if (errno != EEXIST)
                {
@@ -231,18 +231,18 @@ static BOOL CheckDataDir(void)
 
 static void LoadGlobalConfig()
 {
-       g_dwDiscoveryPollingInterval = ConfigReadInt("DiscoveryPollingInterval", 900);
-       g_dwStatusPollingInterval = ConfigReadInt("StatusPollingInterval", 60);
-       g_dwConfigurationPollingInterval = ConfigReadInt("ConfigurationPollingInterval", 3600);
-       g_dwRoutingTableUpdateInterval = ConfigReadInt("RoutingTableUpdateInterval", 300);
-       g_dwConditionPollingInterval = ConfigReadInt("ConditionPollingInterval", 60);
-       if (ConfigReadInt("DeleteEmptySubnets", 1))
+       g_dwDiscoveryPollingInterval = ConfigReadInt(_T("DiscoveryPollingInterval"), 900);
+       g_dwStatusPollingInterval = ConfigReadInt(_T("StatusPollingInterval"), 60);
+       g_dwConfigurationPollingInterval = ConfigReadInt(_T("ConfigurationPollingInterval"), 3600);
+       g_dwRoutingTableUpdateInterval = ConfigReadInt(_T("RoutingTableUpdateInterval"), 300);
+       g_dwConditionPollingInterval = ConfigReadInt(_T("ConditionPollingInterval"), 60);
+       if (ConfigReadInt(_T("DeleteEmptySubnets"), 1))
                g_dwFlags |= AF_DELETE_EMPTY_SUBNETS;
-       if (ConfigReadInt("EnableSNMPTraps", 1))
+       if (ConfigReadInt(_T("EnableSNMPTraps"), 1))
                g_dwFlags |= AF_ENABLE_SNMP_TRAPD;
-       if (ConfigReadInt("EnableZoning", 0))
+       if (ConfigReadInt(_T("EnableZoning"), 0))
                g_dwFlags |= AF_ENABLE_ZONING;
-       if (ConfigReadInt("EnableMultipleDBConnections", 1))
+       if (ConfigReadInt(_T("EnableMultipleDBConnections"), 1))
        {
                // SQLite has troubles with multiple connections to the same database
                // from different threads, and it does not speed up database access
@@ -256,22 +256,22 @@ static void LoadGlobalConfig()
                        DbgPrintf(1, _T("Configuration parameter EnableMultipleDBConnections ignored because database engine is SQLite"));
                }
        }
-       if (ConfigReadInt("RunNetworkDiscovery", 0))
+       if (ConfigReadInt(_T("RunNetworkDiscovery"), 0))
                g_dwFlags |= AF_ENABLE_NETWORK_DISCOVERY;
-       if (ConfigReadInt("ActiveNetworkDiscovery", 0))
+       if (ConfigReadInt(_T("ActiveNetworkDiscovery"), 0))
                g_dwFlags |= AF_ACTIVE_NETWORK_DISCOVERY;
-       if (ConfigReadInt("ResolveNodeNames", 1))
+       if (ConfigReadInt(_T("ResolveNodeNames"), 1))
                g_dwFlags |= AF_RESOLVE_NODE_NAMES;
-       if (ConfigReadInt("SyncNodeNamesWithDNS", 0))
+       if (ConfigReadInt(_T("SyncNodeNamesWithDNS"), 0))
                g_dwFlags |= AF_SYNC_NODE_NAMES_WITH_DNS;
-       if (ConfigReadInt("InternalCA", 0))
+       if (ConfigReadInt(_T("InternalCA"), 0))
                g_dwFlags |= AF_INTERNAL_CA;
-       if (ConfigReadInt("CheckTrustedNodes", 1))
+       if (ConfigReadInt(_T("CheckTrustedNodes"), 1))
                g_dwFlags |= AF_CHECK_TRUSTED_NODES;
        
        if (g_szDataDir[0] == 0)
        {
-               ConfigReadStr("DataDirectory", g_szDataDir, MAX_PATH, DEFAULT_DATA_DIR);
+               ConfigReadStr(_T("DataDirectory"), g_szDataDir, MAX_PATH, DEFAULT_DATA_DIR);
                DbgPrintf(1, _T("Data directory set to %s from server configuration variable"), g_szDataDir);
        }
        else
@@ -279,12 +279,12 @@ static void LoadGlobalConfig()
                DbgPrintf(1, _T("Using data directory %s"), g_szDataDir);
        }
 
-       g_dwPingSize = ConfigReadInt("IcmpPingSize", 46);
-       g_dwLockTimeout = ConfigReadInt("LockTimeout", 60000);
-       g_dwSNMPTimeout = ConfigReadInt("SNMPRequestTimeout", 2000);
-       g_dwAgentCommandTimeout = ConfigReadInt("AgentCommandTimeout", 2000);
-       g_dwThresholdRepeatInterval = ConfigReadInt("ThresholdRepeatInterval", 0);
-       g_nRequiredPolls = ConfigReadInt("PollCountForStatusChange", 1);
+       g_dwPingSize = ConfigReadInt(_T("IcmpPingSize"), 46);
+       g_dwLockTimeout = ConfigReadInt(_T("LockTimeout"), 60000);
+       g_dwSNMPTimeout = ConfigReadInt(_T("SNMPRequestTimeout"), 2000);
+       g_dwAgentCommandTimeout = ConfigReadInt(_T("AgentCommandTimeout"), 2000);
+       g_dwThresholdRepeatInterval = ConfigReadInt(_T("ThresholdRepeatInterval"), 0);
+       g_nRequiredPolls = ConfigReadInt(_T("PollCountForStatusChange"), 1);
 }
 
 
@@ -295,26 +295,26 @@ static void LoadGlobalConfig()
 static BOOL InitCryptografy()
 {
 #ifdef _WITH_ENCRYPTION
-       char szKeyFile[MAX_PATH];
+       TCHAR szKeyFile[MAX_PATH];
        BOOL bResult = FALSE;
        int fd, iPolicy;
        DWORD dwLen;
        BYTE *pBufPos, *pKeyBuffer, hash[SHA1_DIGEST_SIZE];
 
-       if (!InitCryptoLib(ConfigReadULong("AllowedCiphers", 15)))
+       if (!InitCryptoLib(ConfigReadULong(_T("AllowedCiphers"), 15)))
                return FALSE;
 
-       strcpy(szKeyFile, g_szDataDir);
-       strcat(szKeyFile, DFILE_KEYS);
-       fd = open(szKeyFile, O_RDONLY | O_BINARY);
+       _tcscpy(szKeyFile, g_szDataDir);
+       _tcscat(szKeyFile, DFILE_KEYS);
+       fd = _topen(szKeyFile, O_RDONLY | O_BINARY);
        g_pServerKey = LoadRSAKeys(szKeyFile);
        if (g_pServerKey == NULL)
        {
-               DbgPrintf(1, "Generating RSA key pair...");
+               DbgPrintf(1, _T("Generating RSA key pair..."));
                g_pServerKey = RSA_generate_key(NETXMS_RSA_KEYLEN, 17, NULL, 0);
                if (g_pServerKey != NULL)
                {
-                       fd = open(szKeyFile, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, 0600);
+                       fd = _topen(szKeyFile, O_WRONLY | O_BINARY | O_CREAT | O_TRUNC, 0600);
                        if (fd != -1)
                        {
                                dwLen = i2d_RSAPublicKey(g_pServerKey, NULL);
@@ -341,7 +341,7 @@ static BOOL InitCryptografy()
                bResult = TRUE;
        }
 
-       iPolicy = ConfigReadInt("DefaultEncryptionPolicy", 1);
+       iPolicy = ConfigReadInt(_T("DefaultEncryptionPolicy"), 1);
        if ((iPolicy < 0) || (iPolicy > 3))
                iPolicy = 1;
        SetAgentDEP(iPolicy);
@@ -390,7 +390,7 @@ static BOOL IsNetxmsdProcess(DWORD dwPID)
 // Database event handler
 //
 
-static void DBEventHandler(DWORD dwEvent, const TCHAR *pszArg1, const TCHAR *pszArg2, void *userArg)
+static void DBEventHandler(DWORD dwEvent, const WCHAR *pszArg1, const WCHAR *pszArg2, void *userArg)
 {
        if (!(g_dwFlags & AF_SERVER_INITIALIZED))
                return;     // Don't try to do anything if server is not ready yet
@@ -424,7 +424,7 @@ BOOL NXCORE_EXPORTABLE Initialize()
 {
        int i, iDBVersion;
        DWORD dwAddr;
-       char szInfo[256];
+       TCHAR szInfo[256];
 
        g_tServerStartTime = time(NULL);
        srand((unsigned int)g_tServerStartTime);
@@ -442,7 +442,7 @@ BOOL NXCORE_EXPORTABLE Initialize()
 #ifndef _WIN32
        if (SetDefaultCodepage(g_szCodePage))
        {
-               DbgPrintf(1, "Code page set to %s", g_szCodePage);
+               DbgPrintf(1, _T("Code page set to %s"), g_szCodePage);
        }
        else
        {
@@ -497,7 +497,7 @@ BOOL NXCORE_EXPORTABLE Initialize()
                nxlog_write(MSG_DB_CONNFAIL, EVENTLOG_ERROR_TYPE, NULL);
                return FALSE;
        }
-       DbgPrintf(1, "Successfully connected to database %s@%s", g_szDbName, g_szDbServer);
+       DbgPrintf(1, _T("Successfully connected to database %s@%s"), g_szDbName, g_szDbServer);
 
        // Check database version
        iDBVersion = DBGetSchemaVersion(g_hCoreDB);
@@ -507,16 +507,16 @@ BOOL NXCORE_EXPORTABLE Initialize()
                return FALSE;
        }
 
-       int baseSize = ConfigReadInt("ConnectionPoolBaseSize", 5);
-       int maxSize = ConfigReadInt("ConnectionPoolMaxSize", 20);
-       int cooldownTime = ConfigReadInt("ConnectionPoolCooldownTime", 300);
+       int baseSize = ConfigReadInt(_T("ConnectionPoolBaseSize"), 5);
+       int maxSize = ConfigReadInt(_T("ConnectionPoolMaxSize"), 20);
+       int cooldownTime = ConfigReadInt(_T("ConnectionPoolCooldownTime"), 300);
        DBConnectionPoolStartup(g_dbDriver, g_szDbServer, g_szDbName, g_szDbLogin, g_szDbPassword, baseSize, maxSize, cooldownTime);
 
        // Read database syntax
        g_nDBSyntax = DBGetSyntax(g_hCoreDB);
 
        // Read server ID
-       ConfigReadStr("ServerID", szInfo, 256, "");
+       ConfigReadStr(_T("ServerID"), szInfo, 256, _T(""));
        StrStrip(szInfo);
        if (szInfo[0] != 0)
        {
@@ -527,7 +527,7 @@ BOOL NXCORE_EXPORTABLE Initialize()
                // Generate new ID
                g_qwServerId = (((QWORD)time(NULL)) << 32) | rand();
                BinToStr((BYTE *)&g_qwServerId, sizeof(QWORD), szInfo);
-               ConfigWriteStr("ServerID", szInfo, TRUE);
+               ConfigWriteStr(_T("ServerID"), szInfo, TRUE);
        }
 
        // Initialize locks
@@ -545,7 +545,7 @@ retry_db_lock:
                        {
                                DWORD dwPID;
 
-                               dwPID = ConfigReadULong("DBLockPID", 0);
+                               dwPID = ConfigReadULong(_T("DBLockPID"), 0);
                                if (!IsNetxmsdProcess(dwPID) || (dwPID == GetCurrentProcessId()))
                                {
                                        UnlockDB();
@@ -561,7 +561,7 @@ retry_db_lock:
 
        // Load global configuration parameters
        LoadGlobalConfig();
-       DbgPrintf(1, "Global configuration loaded");
+       DbgPrintf(1, _T("Global configuration loaded"));
 
        // Check data directory
        if (!CheckDataDir())
@@ -586,7 +586,7 @@ retry_db_lock:
        // Setup unique identifiers table
        if (!InitIdTable())
                return FALSE;
-       DbgPrintf(2, "ID table created");
+       DbgPrintf(2, _T("ID table created"));
 
        // Load and compile scripts
        LoadScripts();
@@ -602,7 +602,7 @@ retry_db_lock:
                nxlog_write(MSG_ERROR_LOADING_USERS, EVENTLOG_ERROR_TYPE, NULL);
                return FALSE;
        }
-       DbgPrintf(2, "User accounts loaded");
+       DbgPrintf(2, _T("User accounts loaded"));
 
        // Initialize audit
        InitAuditLog();
@@ -612,12 +612,12 @@ retry_db_lock:
        if (!LoadObjects())
                return FALSE;
        LoadMaps();
-       DbgPrintf(1, "Objects loaded and initialized");
+       DbgPrintf(1, _T("Objects loaded and initialized"));
        
        // Initialize situations
        if (!SituationsInit())
                return FALSE;
-       DbgPrintf(1, "Situations loaded and initialized");
+       DbgPrintf(1, _T("Situations loaded and initialized"));
 
        // Initialize and load event actions
        if (!InitActions())
@@ -664,18 +664,18 @@ retry_db_lock:
 
        // Start SNMP trapper
        InitTraps();
-       if (ConfigReadInt("EnableSNMPTraps", 1))
+       if (ConfigReadInt(_T("EnableSNMPTraps"), 1))
                ThreadCreate(SNMPTrapReceiver, 0, NULL);
 
        // Start built-in syslog daemon
-       if (ConfigReadInt("EnableSyslogDaemon", 0))
+       if (ConfigReadInt(_T("EnableSyslogDaemon"), 0))
                m_thSyslogDaemon = ThreadCreateEx(SyslogDaemon, 0, NULL);
 
-       // Start database "lazy" write thread
+       // Start database _T("lazy") write thread
        StartDBWriter();
 
        // Start local administartive interface listener if required
-       if (ConfigReadInt("EnableAdminInterface", 1))
+       if (ConfigReadInt(_T("EnableAdminInterface"), 1))
                ThreadCreate(LocalAdminListener, 0, NULL);
 
        // Load modules
@@ -685,14 +685,14 @@ retry_db_lock:
        ThreadCreate(BeaconPoller, 0, NULL);
 
        // Start inter-server communication listener
-       if (ConfigReadInt("EnableISCListener", 0))
+       if (ConfigReadInt(_T("EnableISCListener"), 0))
                ThreadCreate(ISCListener, 0, NULL);
 
        // Allow clients to connect
        ThreadCreate(ClientListener, 0, NULL);
 
        g_dwFlags |= AF_SERVER_INITIALIZED;
-       DbgPrintf(1, "Server initialization completed");
+       DbgPrintf(1, _T("Server initialization completed"));
        return TRUE;
 }
 
@@ -721,7 +721,7 @@ void NXCORE_EXPORTABLE Shutdown()
 
        // Stop event processor(s)
        g_pEventQueue->Clear();
-       dwNumThreads = ConfigReadInt("NumberOfEventProcessors", 1);
+       dwNumThreads = ConfigReadInt(_T("NumberOfEventProcessors"), 1);
        for(i = 0; i < dwNumThreads; i++)
                g_pEventQueue->Put(INVALID_POINTER_VALUE);
 
@@ -729,7 +729,7 @@ void NXCORE_EXPORTABLE Shutdown()
        ShutdownSMSSender();
 
        ThreadSleep(1);     // Give other threads a chance to terminate in a safe way
-       DbgPrintf(2, "All threads was notified, continue with shutdown");
+       DbgPrintf(2, _T("All threads was notified, continue with shutdown"));
 
        // Wait for critical threads
        ThreadJoin(m_thHouseKeeper);
@@ -738,11 +738,11 @@ void NXCORE_EXPORTABLE Shutdown()
        ThreadJoin(m_thSyslogDaemon);
 
        SaveObjects(g_hCoreDB);
-       DbgPrintf(2, "All objects saved to database");
+       DbgPrintf(2, _T("All objects saved to database"));
        SaveUsers(g_hCoreDB);
-       DbgPrintf(2, "All users saved to database");
+       DbgPrintf(2, _T("All users saved to database"));
        StopDBWriter();
-       DbgPrintf(1, "Database writer stopped");
+       DbgPrintf(1, _T("Database writer stopped"));
 
        CleanupUsers();
 
@@ -756,11 +756,11 @@ void NXCORE_EXPORTABLE Shutdown()
        DBConnectionPoolShutdown();
 
        DBUnloadDriver(g_dbDriver);
-       DbgPrintf(1, "Database driver unloaded");
+       DbgPrintf(1, _T("Database driver unloaded"));
 
        CleanupActions();
        ShutdownEventSubsystem();
-       DbgPrintf(1, "Event processing stopped");
+       DbgPrintf(1, _T("Event processing stopped"));
 
        // Delete all objects
        //for(i = 0; i < g_dwIdIndexSize; i++)
@@ -795,16 +795,16 @@ void NXCORE_EXPORTABLE FastShutdown(void)
        ConditionSet(m_condShutdown);
 
        SaveObjects(g_hCoreDB);
-       DbgPrintf(2, "All objects saved to database");
+       DbgPrintf(2, _T("All objects saved to database"));
        SaveUsers(g_hCoreDB);
-       DbgPrintf(2, "All users saved to database");
+       DbgPrintf(2, _T("All users saved to database"));
 
        // Remove database lock first, because we have a chance to loose DB connection
        UnlockDB();
 
        // Stop database writers
        StopDBWriter();
-       DbgPrintf(1, "Database writer stopped");
+       DbgPrintf(1, _T("Database writer stopped"));
 
        nxlog_close();
 }
@@ -814,12 +814,12 @@ void NXCORE_EXPORTABLE FastShutdown(void)
 // Compare given string to command template with abbreviation possibility
 //
 
-static BOOL IsCommand(const char *pszTemplate, char *pszString, int iMinChars)
+static BOOL IsCommand(const TCHAR *pszTemplate, TCHAR *pszString, int iMinChars)
 {
        int i;
 
        // Convert given string to uppercase
-       strupr(pszString);
+       _tcsupr(pszString);
 
        for(i = 0; pszString[i] != 0; i++)
                if (pszString[i] != pszTemplate[i])
@@ -834,15 +834,14 @@ static BOOL IsCommand(const char *pszTemplate, char *pszString, int iMinChars)
 // Dump index
 //
 
-static void DumpIndex(CONSOLE_CTX pCtx, RWLOCK hLock, INDEX *pIndex, DWORD dwSize,
-               BOOL bIndexByIp)
+static void DumpIndex(CONSOLE_CTX pCtx, RWLOCK hLock, INDEX *pIndex, DWORD dwSize, BOOL bIndexByIp)
 {
        DWORD i;
-       char szIpAddr[16];
+       TCHAR szIpAddr[16];
 
        if (!RWLockReadLock(hLock, 5000))
        {
-               ConsolePrintf(pCtx, "ERROR: unable to obtain index lock in 5 seconds\n");
+               ConsolePrintf(pCtx, _T("ERROR: unable to obtain index lock in 5 seconds\n"));
                return;
        }
 
@@ -850,13 +849,13 @@ static void DumpIndex(CONSOLE_CTX pCtx, RWLOCK hLock, INDEX *pIndex, DWORD dwSiz
        {
                if (bIndexByIp)
                {
-                       ConsolePrintf(pCtx, "%08X [%-15s] %p %s\n", pIndex[i].dwKey,
+                       ConsolePrintf(pCtx, _T("%08X [%-15s] %p %s\n"), pIndex[i].dwKey,
                                        IpToStr(pIndex[i].dwKey, szIpAddr),
                                        pIndex[i].pObject, ((NetObj *)pIndex[i].pObject)->Name());
                }
                else
                {
-                       ConsolePrintf(pCtx, "%08X %p %s\n", pIndex[i].dwKey, pIndex[i].pObject,
+                       ConsolePrintf(pCtx, _T("%08X %p %s\n"), pIndex[i].dwKey, pIndex[i].pObject,
                                        ((NetObj *)pIndex[i].pObject)->Name());
                }
        }
@@ -867,95 +866,95 @@ static void DumpIndex(CONSOLE_CTX pCtx, RWLOCK hLock, INDEX *pIndex, DWORD dwSiz
 
 //
 // Process command entered from command line in standalone mode
-// Return TRUE if command was "down"
+// Return TRUE if command was _T("down")
 //
 
-int ProcessConsoleCommand(char *pszCmdLine, CONSOLE_CTX pCtx)
+int ProcessConsoleCommand(const TCHAR *pszCmdLine, CONSOLE_CTX pCtx)
 {
-       char *pArg;
-       char szBuffer[256];
+       const TCHAR *pArg;
+       TCHAR szBuffer[256];
        int nExitCode = CMD_EXIT_CONTINUE;
 
        // Get command
        pArg = ExtractWord(pszCmdLine, szBuffer);
 
-       if (IsCommand("DEBUG", szBuffer, 2))
+       if (IsCommand(_T("DEBUG"), szBuffer, 2))
        {
                // Get argument
                pArg = ExtractWord(pArg, szBuffer);
 
-               if (IsCommand("ON", szBuffer, 2))
+               if (IsCommand(_T("ON"), szBuffer, 2))
                {
                        g_nDebugLevel = 8;
-                       ConsolePrintf(pCtx, "Debug mode turned on\n");
+                       ConsolePrintf(pCtx, _T("Debug mode turned on\n"));
                }
-               else if (IsCommand("OFF", szBuffer, 2))
+               else if (IsCommand(_T("OFF"), szBuffer, 2))
                {
                        g_nDebugLevel = 0;
-                       ConsolePrintf(pCtx, "Debug mode turned off\n");
+                       ConsolePrintf(pCtx, _T("Debug mode turned off\n"));
                }
                else
                {
                        if (szBuffer[0] == 0)
-                               ConsolePrintf(pCtx, "ERROR: Missing argument\n\n");
+                               ConsolePrintf(pCtx, _T("ERROR: Missing argument\n\n"));
                        else
-                               ConsolePrintf(pCtx, "ERROR: Invalid DEBUG argument\n\n");
+                               ConsolePrintf(pCtx, _T("ERROR: Invalid DEBUG argument\n\n"));
                }
        }
-       else if (IsCommand("DOWN", szBuffer, 4))
+       else if (IsCommand(_T("DOWN"), szBuffer, 4))
        {
-               ConsolePrintf(pCtx, "Proceeding with server shutdown...\n");
+               ConsolePrintf(pCtx, _T("Proceeding with server shutdown...\n"));
                nExitCode = CMD_EXIT_SHUTDOWN;
        }
-       else if (IsCommand("DUMP", szBuffer, 4))
+       else if (IsCommand(_T("DUMP"), szBuffer, 4))
        {
                DumpProcess(pCtx);
        }
-       else if (IsCommand("RAISE", szBuffer, 5))
+       else if (IsCommand(_T("RAISE"), szBuffer, 5))
        {
                // Get argument
                pArg = ExtractWord(pArg, szBuffer);
 
-               if (IsCommand("ACCESS", szBuffer, 6))
+               if (IsCommand(_T("ACCESS"), szBuffer, 6))
                {
-                       ConsolePrintf(pCtx, "Raising exception...\n");
+                       ConsolePrintf(pCtx, _T("Raising exception...\n"));
                        char *p = NULL;
                        *p = 0;
                }
-               else if (IsCommand("BREAKPOINT", szBuffer, 5))
+               else if (IsCommand(_T("BREAKPOINT"), szBuffer, 5))
                {
 #ifdef _WIN32
-                       ConsolePrintf(pCtx, "Raising exception...\n");
+                       ConsolePrintf(pCtx, _T("Raising exception...\n"));
                        RaiseException(EXCEPTION_BREAKPOINT, 0, 0, NULL);
 #else
-                       ConsolePrintf(pCtx, "ERROR: Not supported on current platform\n");
+                       ConsolePrintf(pCtx, _T("ERROR: Not supported on current platform\n"));
 #endif
                }
                else
                {
-                       ConsolePrintf(pCtx, "Invalid exception name; possible names are:\nACCESS BREAKPOINT\n");
+                       ConsolePrintf(pCtx, _T("Invalid exception name; possible names are:\nACCESS BREAKPOINT\n"));
                }
        }
-       else if (IsCommand("EXIT", szBuffer, 4))
+       else if (IsCommand(_T("EXIT"), szBuffer, 4))
        {
                if (pCtx->hSocket != -1)
                {
-                       ConsolePrintf(pCtx, "Closing session...\n");
+                       ConsolePrintf(pCtx, _T("Closing session...\n"));
                        nExitCode = CMD_EXIT_CLOSE_SESSION;
                }
                else
                {
-                       ConsolePrintf(pCtx, "Cannot exit from local server console\n");
+                       ConsolePrintf(pCtx, _T("Cannot exit from local server console\n"));
                }
        }
-       else if (IsCommand("SHOW", szBuffer, 2))
+       else if (IsCommand(_T("SHOW"), szBuffer, 2))
        {
                // Get argument
                pArg = ExtractWord(pArg, szBuffer);
 
-               if (IsCommand("FLAGS", szBuffer, 1))
+               if (IsCommand(_T("FLAGS"), szBuffer, 1))
                {
-                       ConsolePrintf(pCtx, "Flags: 0x%08X\n", g_dwFlags);
+                       ConsolePrintf(pCtx, _T("Flags: 0x%08X\n"), g_dwFlags);
                        ConsolePrintf(pCtx, SHOW_FLAG_VALUE(AF_DAEMON));
                        ConsolePrintf(pCtx, SHOW_FLAG_VALUE(AF_USE_SYSLOG));
                        ConsolePrintf(pCtx, SHOW_FLAG_VALUE(AF_ENABLE_NETWORK_DISCOVERY));
@@ -977,32 +976,32 @@ int ProcessConsoleCommand(char *pszCmdLine, CONSOLE_CTX pCtx)
                        ConsolePrintf(pCtx, SHOW_FLAG_VALUE(AF_EVENT_STORM_DETECTED));
                        ConsolePrintf(pCtx, SHOW_FLAG_VALUE(AF_SERVER_INITIALIZED));
                        ConsolePrintf(pCtx, SHOW_FLAG_VALUE(AF_SHUTDOWN));
-                       ConsolePrintf(pCtx, "\n");
+                       ConsolePrintf(pCtx, _T("\n"));
                }
-               else if (IsCommand("INDEX", szBuffer, 1))
+               else if (IsCommand(_T("INDEX"), szBuffer, 1))
                {
                        // Get argument
                        pArg = ExtractWord(pArg, szBuffer);
 
-                       if (IsCommand("CONDITION", szBuffer, 1))
+                       if (IsCommand(_T("CONDITION"), szBuffer, 1))
                        {
                                DumpIndex(pCtx, g_rwlockConditionIndex, g_pConditionIndex, g_dwConditionIndexSize, FALSE);
                        }
-                       else if (IsCommand("ID", szBuffer, 2))
+                       else if (IsCommand(_T("ID"), szBuffer, 2))
                        {
                                DumpIndex(pCtx, g_rwlockIdIndex, g_pIndexById, g_dwIdIndexSize, FALSE);
                        }
-                       else if (IsCommand("INTERFACE", szBuffer, 2))
+                       else if (IsCommand(_T("INTERFACE"), szBuffer, 2))
                        {
                                DumpIndex(pCtx, g_rwlockInterfaceIndex, g_pInterfaceIndexByAddr,
                                                g_dwInterfaceAddrIndexSize, TRUE);
                        }
-                       else if (IsCommand("NODE", szBuffer, 1))
+                       else if (IsCommand(_T("NODE"), szBuffer, 1))
                        {
                                DumpIndex(pCtx, g_rwlockNodeIndex, g_pNodeIndexByAddr,
                                                g_dwNodeAddrIndexSize, TRUE);
                        }
-                       else if (IsCommand("SUBNET", szBuffer, 1))
+                       else if (IsCommand(_T("SUBNET"), szBuffer, 1))
                        {
                                DumpIndex(pCtx, g_rwlockSubnetIndex, g_pSubnetIndexByAddr,
                                                g_dwSubnetAddrIndexSize, TRUE);
@@ -1010,57 +1009,57 @@ int ProcessConsoleCommand(char *pszCmdLine, CONSOLE_CTX pCtx)
                        else
                        {
                                if (szBuffer[0] == 0)
-                                       ConsolePrintf(pCtx, "ERROR: Missing index name\n"
-                                                       "Valid names are: CONDITION, ID, INTERFACE, NODE, SUBNET\n\n");
+                                       ConsolePrintf(pCtx, _T("ERROR: Missing index name\n")
+                                                       _T("Valid names are: CONDITION, ID, INTERFACE, NODE, SUBNET\n\n"));
                                else
-                                       ConsolePrintf(pCtx, "ERROR: Invalid index name\n\n");
+                                       ConsolePrintf(pCtx, _T("ERROR: Invalid index name\n\n"));
                        }
                }
-               else if (IsCommand("MEMORY", szBuffer, 2))
+               else if (IsCommand(_T("MEMORY"), szBuffer, 2))
                {
 #ifdef NETXMS_MEMORY_DEBUG
                        PrintMemoryBlocks();
 #else
-                       ConsolePrintf(pCtx, "ERROR: Server was compiled without memory debugger\n\n");
+                       ConsolePrintf(pCtx, _T("ERROR: Server was compiled without memory debugger\n\n"));
 #endif
                }
-               else if (IsCommand("MUTEX", szBuffer, 2))
+               else if (IsCommand(_T("MUTEX"), szBuffer, 2))
                {
-                       ConsolePrintf(pCtx, "Mutex status:\n");
-                       DbgTestRWLock(g_rwlockIdIndex, "g_hMutexIdIndex", pCtx);
-                       DbgTestRWLock(g_rwlockNodeIndex, "g_hMutexNodeIndex", pCtx);
-                       DbgTestRWLock(g_rwlockSubnetIndex, "g_hMutexSubnetIndex", pCtx);
-                       DbgTestRWLock(g_rwlockInterfaceIndex, "g_hMutexInterfaceIndex", pCtx);
-                       ConsolePrintf(pCtx, "\n");
+                       ConsolePrintf(pCtx, _T("Mutex status:\n"));
+                       DbgTestRWLock(g_rwlockIdIndex, _T("g_hMutexIdIndex"), pCtx);
+                       DbgTestRWLock(g_rwlockNodeIndex, _T("g_hMutexNodeIndex"), pCtx);
+                       DbgTestRWLock(g_rwlockSubnetIndex, _T("g_hMutexSubnetIndex"), pCtx);
+                       DbgTestRWLock(g_rwlockInterfaceIndex, _T("g_hMutexInterfaceIndex"), pCtx);
+                       ConsolePrintf(pCtx, _T("\n"));
                }
-               else if (IsCommand("OBJECTS", szBuffer, 1))
+               else if (IsCommand(_T("OBJECTS"), szBuffer, 1))
                {
                        DumpObjects(pCtx);
                }
-               else if (IsCommand("POLLERS", szBuffer, 1))
+               else if (IsCommand(_T("POLLERS"), szBuffer, 1))
                {
                        ShowPollerState(pCtx);
                }
-               else if (IsCommand("QUEUES", szBuffer, 1))
+               else if (IsCommand(_T("QUEUES"), szBuffer, 1))
                {
-                       ShowQueueStats(pCtx, &g_conditionPollerQueue, "Condition poller");
-                       ShowQueueStats(pCtx, &g_configPollQueue, "Configuration poller");
-                       ShowQueueStats(pCtx, g_pItemQueue, "Data collector");
-                       ShowQueueStats(pCtx, g_pLazyRequestQueue, "Database writer");
-                       ShowQueueStats(pCtx, g_pEventQueue, "Event processor");
-                       ShowQueueStats(pCtx, &g_discoveryPollQueue, "Network discovery poller");
-                       ShowQueueStats(pCtx, &g_nodePollerQueue, "Node poller");
-                       ShowQueueStats(pCtx, &g_routePollQueue, "Routing table poller");
-                       ShowQueueStats(pCtx, &g_statusPollQueue, "Status poller");
-                       ConsolePrintf(pCtx, "\n");
+                       ShowQueueStats(pCtx, &g_conditionPollerQueue, _T("Condition poller"));
+                       ShowQueueStats(pCtx, &g_configPollQueue, _T("Configuration poller"));
+                       ShowQueueStats(pCtx, g_pItemQueue, _T("Data collector"));
+                       ShowQueueStats(pCtx, g_pLazyRequestQueue, _T("Database writer"));
+                       ShowQueueStats(pCtx, g_pEventQueue, _T("Event processor"));
+                       ShowQueueStats(pCtx, &g_discoveryPollQueue, _T("Network discovery poller"));
+                       ShowQueueStats(pCtx, &g_nodePollerQueue, _T("Node poller"));
+                       ShowQueueStats(pCtx, &g_routePollQueue, _T("Routing table poller"));
+                       ShowQueueStats(pCtx, &g_statusPollQueue, _T("Status poller"));
+                       ConsolePrintf(pCtx, _T("\n"));
                }
-               else if (IsCommand("ROUTING-TABLE", szBuffer, 1))
+               else if (IsCommand(_T("ROUTING-TABLE"), szBuffer, 1))
                {
                        DWORD dwNode;
                        NetObj *pObject;
 
                        pArg = ExtractWord(pArg, szBuffer);
-                       dwNode = strtoul(szBuffer, NULL, 0);
+                       dwNode = _tcstoul(szBuffer, NULL, 0);
                        if (dwNode != 0)
                        {
                                pObject = FindObjectById(dwNode);
@@ -1069,96 +1068,96 @@ int ProcessConsoleCommand(char *pszCmdLine, CONSOLE_CTX pCtx)
                                        if (pObject->Type() == OBJECT_NODE)
                                        {
                                                ROUTING_TABLE *pRT;
-                                               char szIpAddr[16];
+                                               TCHAR szIpAddr[16];
                                                int i;
 
-                                               ConsolePrintf(pCtx, "Routing table for node %s:\n\n", pObject->Name());
+                                               ConsolePrintf(pCtx, _T("Routing table for node %s:\n\n"), pObject->Name());
                                                pRT = ((Node *)pObject)->getCachedRoutingTable();
                                                if (pRT != NULL)
                                                {
                                                        for(i = 0; i < pRT->iNumEntries; i++)
                                                        {
-                                                               sprintf(szBuffer, "%s/%d", IpToStr(pRT->pRoutes[i].dwDestAddr, szIpAddr),
-                                                                               BitsInMask(pRT->pRoutes[i].dwDestMask));
-                                                               ConsolePrintf(pCtx, "%-18s %-15s %-6d %d\n", szBuffer,
-                                                                               IpToStr(pRT->pRoutes[i].dwNextHop, szIpAddr),
-                                                                               pRT->pRoutes[i].dwIfIndex, pRT->pRoutes[i].dwRouteType);
+                                                               _sntprintf(szBuffer, 256, _T("%s/%d"), IpToStr(pRT->pRoutes[i].dwDestAddr, szIpAddr),
+                                                                                    BitsInMask(pRT->pRoutes[i].dwDestMask));
+                                                               ConsolePrintf(pCtx, _T("%-18s %-15s %-6d %d\n"), szBuffer,
+                                                                                       IpToStr(pRT->pRoutes[i].dwNextHop, szIpAddr),
+                                                                                       pRT->pRoutes[i].dwIfIndex, pRT->pRoutes[i].dwRouteType);
                                                        }
-                                                       ConsolePrintf(pCtx, "\n");
+                                                       ConsolePrintf(pCtx, _T("\n"));
                                                }
                                                else
                                                {
-                                                       ConsolePrintf(pCtx, "Node doesn't have cached routing table\n\n");
+                                                       ConsolePrintf(pCtx, _T("Node doesn't have cached routing table\n\n"));
                                                }
                                        }
                                        else
                                        {
-                                               ConsolePrintf(pCtx, "ERROR: Object is not a node\n\n");
+                                               ConsolePrintf(pCtx, _T("ERROR: Object is not a node\n\n"));
                                        }
                                }
                                else
                                {
-                                       ConsolePrintf(pCtx, "ERROR: Object with ID %d does not exist\n\n", dwNode);
+                                       ConsolePrintf(pCtx, _T("ERROR: Object with ID %d does not exist\n\n"), dwNode);
                                }
                        }
                        else
                        {
-                               ConsolePrintf(pCtx, "ERROR: Invalid or missing node ID\n\n");
+                               ConsolePrintf(pCtx, _T("ERROR: Invalid or missing node ID\n\n"));
                        }
                }
-               else if (IsCommand("SESSIONS", szBuffer, 2))
+               else if (IsCommand(_T("SESSIONS"), szBuffer, 2))
                {
                        DumpSessions(pCtx);
                }
-               else if (IsCommand("STATS", szBuffer, 2))
+               else if (IsCommand(_T("STATS"), szBuffer, 2))
                {
                        ShowServerStats(pCtx);
                }
-               else if (IsCommand("USERS", szBuffer, 1))
+               else if (IsCommand(_T("USERS"), szBuffer, 1))
                {
                        DumpUsers(pCtx);
                }
-               else if (IsCommand("WATCHDOG", szBuffer, 1))
+               else if (IsCommand(_T("WATCHDOG"), szBuffer, 1))
                {
                        WatchdogPrintStatus(pCtx);
-                       ConsolePrintf(pCtx, "\n");
+                       ConsolePrintf(pCtx, _T("\n"));
                }
                else
                {
                        if (szBuffer[0] == 0)
-                               ConsolePrintf(pCtx, "ERROR: Missing subcommand\n\n");
+                               ConsolePrintf(pCtx, _T("ERROR: Missing subcommand\n\n"));
                        else
-                               ConsolePrintf(pCtx, "ERROR: Invalid SHOW subcommand\n\n");
+                               ConsolePrintf(pCtx, _T("ERROR: Invalid SHOW subcommand\n\n"));
                }
        }
-       else if (IsCommand("TRACE", szBuffer, 1))
+       else if (IsCommand(_T("TRACE"), szBuffer, 1))
        {
                DWORD dwNode1, dwNode2;
                NetObj *pObject1, *pObject2;
                NETWORK_PATH_TRACE *pTrace;
-               char szNextHop[16];
+               TCHAR szNextHop[16];
                int i;
 
                // Get arguments
                pArg = ExtractWord(pArg, szBuffer);
-               dwNode1 = strtoul(szBuffer, NULL, 0);
+               dwNode1 = _tcstoul(szBuffer, NULL, 0);
 
                pArg = ExtractWord(pArg, szBuffer);
-               dwNode2 = strtoul(szBuffer, NULL, 0);
+               dwNode2 = _tcstoul(szBuffer, NULL, 0);
 
                if ((dwNode1 != 0) && (dwNode2 != 0))
                {
                        pObject1 = FindObjectById(dwNode1);
                        if (pObject1 == NULL)
                        {
-                               ConsolePrintf(pCtx, "ERROR: Object with ID %d does not exist\n\n", dwNode1);
+                               ConsolePrintf(pCtx, _T("ERROR: Object with ID %d does not exist\n\n"), dwNode1);
                        }
                        else
                        {
                                pObject2 = FindObjectById(dwNode2);
                                if (pObject2 == NULL)
                                {
-                                       ConsolePrintf(pCtx, "ERROR: Object with ID %d does not exist\n\n", dwNode2);
+                                       ConsolePrintf(pCtx, _T("ERROR: Object with ID %d does not exist\n\n"), dwNode2);
                                }
                                else
                                {
@@ -1168,61 +1167,61 @@ int ProcessConsoleCommand(char *pszCmdLine, CONSOLE_CTX pCtx)
                                                pTrace = TraceRoute((Node *)pObject1, (Node *)pObject2);
                                                if (pTrace != NULL)
                                                {
-                                                       ConsolePrintf(pCtx, "Trace from %s to %s (%d hops):\n",
+                                                       ConsolePrintf(pCtx, _T("Trace from %s to %s (%d hops):\n"),
                                                                        pObject1->Name(), pObject2->Name(), pTrace->iNumHops);
                                                        for(i = 0; i < pTrace->iNumHops; i++)
-                                                               ConsolePrintf(pCtx, "[%d] %s %s %s %d\n",
+                                                               ConsolePrintf(pCtx, _T("[%d] %s %s %s %d\n"),
                                                                                pTrace->pHopList[i].pObject->Id(),
                                                                                pTrace->pHopList[i].pObject->Name(),
                                                                                IpToStr(pTrace->pHopList[i].dwNextHop, szNextHop),
-                                                                               pTrace->pHopList[i].bIsVPN ? "VPN Connector ID:" : "Interface Index: ",
+                                                                               pTrace->pHopList[i].bIsVPN ? _T("VPN Connector ID:") : _T("Interface Index: "),
                                                                                pTrace->pHopList[i].dwIfIndex);
                                                        DestroyTraceData(pTrace);
-                                                       ConsolePrintf(pCtx, "\n");
+                                                       ConsolePrintf(pCtx, _T("\n"));
                                                }
                                                else
                                                {
-                                                       ConsolePrintf(pCtx, "ERROR: Call to TraceRoute() failed\n\n");
+                                                       ConsolePrintf(pCtx, _T("ERROR: Call to TraceRoute() failed\n\n"));
                                                }
                                        }
                                        else
                                        {
-                                               ConsolePrintf(pCtx, "ERROR: Object is not a node\n\n");
+                                               ConsolePrintf(pCtx, _T("ERROR: Object is not a node\n\n"));
                                        }
                                }
                        }
                }
                else
                {
-                       ConsolePrintf(pCtx, "ERROR: Invalid or missing node id(s)\n\n");
+                       ConsolePrintf(pCtx, _T("ERROR: Invalid or missing node id(s)\n\n"));
                }
        }
-       else if (IsCommand("HELP", szBuffer, 2) || IsCommand("?", szBuffer, 1))
+       else if (IsCommand(_T("HELP"), szBuffer, 2) || IsCommand(_T("?"), szBuffer, 1))
        {
-               ConsolePrintf(pCtx, "Valid commands are:\n"
-                               "   debug [on|off]            - Turn debug mode on or off\n"
-                               "   down                      - Down NetXMS server\n"
-                               "   exit                      - Exit from remote session\n"
-                               "   help                      - Display this help\n"
-                               "   raise <exception>         - Raise exception\n"
-                               "   show flags                - Show internal server flags\n"
-                               "   show index <index>        - Show internal index\n"
-                               "   show mutex                - Display mutex status\n"
-                               "   show objects              - Dump network objects to screen\n"
-                               "   show pollers              - Show poller threads state information\n"
-                               "   show queues               - Show internal queues statistics\n"
-                               "   show routing-table <node> - Show cached routing table for node\n"
-                               "   show sessions             - Show active client sessions\n"
-                               "   show stats                - Show server statistics\n"
-                               "   show users                - Show users\n"
-                               "   show watchdog             - Display watchdog information\n"
-                               "   trace <node1> <node2>     - Show network path trace between two nodes\n"
-                               "\nAlmost all commands can be abbreviated to 2 or 3 characters\n"
-                               "\n");
+               ConsolePrintf(pCtx, _T("Valid commands are:\n")
+                               _T("   debug [on|off]            - Turn debug mode on or off\n")
+                               _T("   down                      - Down NetXMS server\n")
+                               _T("   exit                      - Exit from remote session\n")
+                               _T("   help                      - Display this help\n")
+                               _T("   raise <exception>         - Raise exception\n")
+                               _T("   show flags                - Show internal server flags\n")
+                               _T("   show index <index>        - Show internal index\n")
+                               _T("   show mutex                - Display mutex status\n")
+                               _T("   show objects              - Dump network objects to screen\n")
+                               _T("   show pollers              - Show poller threads state information\n")
+                               _T("   show queues               - Show internal queues statistics\n")
+                               _T("   show routing-table <node> - Show cached routing table for node\n")
+                               _T("   show sessions             - Show active client sessions\n")
+                               _T("   show stats                - Show server statistics\n")
+                               _T("   show users                - Show users\n")
+                               _T("   show watchdog             - Display watchdog information\n")
+                               _T("   trace <node1> <node2>     - Show network path trace between two nodes\n")
+                               _T("\nAlmost all commands can be abbreviated to 2 or 3 characters\n")
+                               _T("\n"));
        }
        else
        {
-               ConsolePrintf(pCtx, "UNKNOWN COMMAND\n\n");
+               ConsolePrintf(pCtx, _T("UNKNOWN COMMAND\n\n"));
        }
 
        return nExitCode;
@@ -1324,12 +1323,15 @@ THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL Main(void *pArg)
        {
                char *ptr, szCommand[256];
                struct __console_ctx ctx;
+#ifdef UNICODE
+               WCHAR wcCommand[256];
+#endif
 
                ctx.hSocket = -1;
                ctx.pMsg = NULL;
-               printf("\nNetXMS Server V" NETXMS_VERSION_STRING " Ready\n"
-                               "Enter \"help\" for command list or \"down\" for server shutdown\n"
-                               "System Console\n\n");
+               _tprintf(_T("\nNetXMS Server V") NETXMS_VERSION_STRING _T(" Ready\n")
+                                  _T("Enter \"help\" for command list or \"down\" for server shutdown\n")
+                                  _T("System Console\n\n"));
 
 #if USE_READLINE
                // Initialize readline library if we use it
@@ -1353,10 +1355,19 @@ THREAD_RESULT NXCORE_EXPORTABLE THREAD_CALL Main(void *pArg)
 
                        if (ptr != NULL)
                        {
+#ifdef UNICODE
+                               MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, ptr, -1, wcCommand, 256);
+                               wcCommand[255] = 0;
+                               StrStrip(wcCommand);
+                               if (wcCommand[0] != 0)
+                               {
+                                       if (ProcessConsoleCommand(wcCommand, &ctx) == CMD_EXIT_SHUTDOWN)
+#else
                                StrStrip(ptr);
                                if (*ptr != 0)
                                {
                                        if (ProcessConsoleCommand(ptr, &ctx) == CMD_EXIT_SHUTDOWN)
+#endif
                                                break;
 #if USE_READLINE
                                        add_history(ptr);
index 19eeb86..e9eea41 100644 (file)
@@ -489,7 +489,7 @@ void LoadMaps(void)
    DB_RESULT hResult;
    DWORD i;
 
-   hResult = DBSelect(g_hCoreDB, "SELECT map_id,map_name,description,root_object_id FROM maps");
+   hResult = DBSelect(g_hCoreDB, _T("SELECT map_id,map_name,description,root_object_id FROM maps"));
    if (hResult != NULL)
    {
       m_dwNumMaps = DBGetNumRows(hResult);
index 67cbd9d..4eaef64 100644 (file)
@@ -60,7 +60,7 @@ void InitLocalNetInfo(void)
 #ifdef _WIN32
    HMODULE hModule;
 
-   hModule = LoadLibrary("NETMAN.DLL");
+   hModule = LoadLibrary(_T("NETMAN.DLL"));
    if (hModule != NULL)
    {
       imp_HrLanConnectionNameFromGuidOrPath = 
@@ -68,7 +68,7 @@ void InitLocalNetInfo(void)
    }
 #elif HAVE_SYS_UTSNAME_H
    struct utsname un;
-   char szName[MAX_PATH], szErrorText[256];
+   TCHAR szName[MAX_PATH], szErrorText[256];
    int i;
 
    if (uname(&un) != -1)
@@ -76,8 +76,8 @@ void InitLocalNetInfo(void)
       // Convert system name to lowercase
       for(i = 0; un.sysname[i] != 0; i++)
          un.sysname[i] = tolower(un.sysname[i]);
-      if (!strcmp(un.sysname, "hp-ux"))
-         strcpy(un.sysname, "hpux");
+      if (!_tcscmp(un.sysname, "hp-ux"))
+         _tcscpy(un.sysname, "hpux");
       snprintf(szName, MAX_PATH, LIBDIR "/libnsm_%s" SHL_SUFFIX, un.sysname);
 
       m_hSubAgent = DLOpen(szName, szErrorText);
@@ -113,13 +113,13 @@ void InitLocalNetInfo(void)
 // Convert string representation of MAC address to binary form
 //
 
-void StrToMac(char *pszStr, BYTE *pBuffer)
+void StrToMac(const TCHAR *pszStr, BYTE *pBuffer)
 {
    DWORD byte1, byte2, byte3, byte4, byte5, byte6;
 
    memset(pBuffer, 6, 0);
-   if (sscanf(pszStr, "%x:%x:%x:%x:%x:%x", &byte1, &byte2, &byte3, 
-              &byte4, &byte5, &byte6) == 6)
+   if (_stscanf(pszStr, _T("%x:%x:%x:%x:%x:%x"), &byte1, &byte2, &byte3, 
+                &byte4, &byte5, &byte6) == 6)
    {
       pBuffer[0] = (BYTE)byte1;
       pBuffer[1] = (BYTE)byte2;
@@ -135,7 +135,7 @@ void StrToMac(char *pszStr, BYTE *pBuffer)
 // Get local ARP cache
 //
 
-static ARP_CACHE *SysGetLocalArpCache(void)
+static ARP_CACHE *SysGetLocalArpCache()
 {
    ARP_CACHE *pArpCache = NULL;
 
@@ -235,15 +235,15 @@ static ARP_CACHE *SysGetLocalArpCache(void)
 // Get local interface list (built-in system dependent code)
 //
 
-static INTERFACE_LIST *SysGetLocalIfList(void)
+static INTERFACE_LIST *SysGetLocalIfList()
 {
    INTERFACE_LIST *pIfList = NULL;
 
 #ifdef _WIN32
    DWORD dwSize;
    IP_ADAPTER_INFO *pBuffer, *pInfo;
-   char szAdapterName[MAX_OBJECT_NAME];
-   char szMacAddr[MAX_ADAPTER_ADDRESS_LENGTH * 2 + 1];
+   TCHAR szAdapterName[MAX_OBJECT_NAME];
+   TCHAR szMacAddr[MAX_ADAPTER_ADDRESS_LENGTH * 2 + 1];
    IP_ADDR_STRING *pAddr;
 
    if (GetAdaptersInfo(NULL, &dwSize) != ERROR_BUFFER_OVERFLOW)
@@ -272,19 +272,33 @@ static INTERFACE_LIST *SysGetLocalIfList(void)
             dwSize = 256;
             if (imp_HrLanConnectionNameFromGuidOrPath(NULL, wGUID, wName, &dwSize) == 0)
             {
+#ifdef UNICODE
+                                       nx_strncpy(szAdapterName, wName, MAX_OBJECT_NAME);
+#else
                WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, 
                                    wName, dwSize, szAdapterName, MAX_OBJECT_NAME, NULL, NULL);
                szAdapterName[MAX_OBJECT_NAME - 1] = 0;
+#endif
             }
             else
             {
+#ifdef UNICODE
+                                       MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pInfo->AdapterName, -1, szAdapterName, MAX_OBJECT_NAME);
+               szAdapterName[MAX_OBJECT_NAME - 1] = 0;
+#else
                nx_strncpy(szAdapterName, pInfo->AdapterName, MAX_OBJECT_NAME);
+#endif
             }
          }
          else
          {
             // We don't have a GUID resolving function, use GUID as name
+#ifdef UNICODE
+                               MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pInfo->AdapterName, -1, szAdapterName, MAX_OBJECT_NAME);
+            szAdapterName[MAX_OBJECT_NAME - 1] = 0;
+#else
             nx_strncpy(szAdapterName, pInfo->AdapterName, MAX_OBJECT_NAME);
+#endif
          }
 
          BinToStr(pInfo->Address, pInfo->AddressLength, szMacAddr);
@@ -297,8 +311,8 @@ static INTERFACE_LIST *SysGetLocalIfList(void)
             nx_strncpy(pIfList->pInterfaces[pIfList->iNumEntries].szName, szAdapterName, MAX_OBJECT_NAME);
             memcpy(pIfList->pInterfaces[pIfList->iNumEntries].bMacAddr, pInfo->Address, MAC_ADDR_LENGTH);
             pIfList->pInterfaces[pIfList->iNumEntries].dwIndex = pInfo->Index;
-            pIfList->pInterfaces[pIfList->iNumEntries].dwIpAddr = ntohl(_t_inet_addr(pAddr->IpAddress.String));
-            pIfList->pInterfaces[pIfList->iNumEntries].dwIpNetMask = ntohl(_t_inet_addr(pAddr->IpMask.String));
+            pIfList->pInterfaces[pIfList->iNumEntries].dwIpAddr = ntohl(inet_addr(pAddr->IpAddress.String));
+            pIfList->pInterfaces[pIfList->iNumEntries].dwIpNetMask = ntohl(inet_addr(pAddr->IpMask.String));
             pIfList->pInterfaces[pIfList->iNumEntries].dwType = pInfo->Type;
             pIfList->pInterfaces[pIfList->iNumEntries].iNumSecondary = 0;
             pIfList->iNumEntries++;
index 52bdf75..5365c35 100644 (file)
@@ -193,7 +193,7 @@ BOOL NetworkMap::CreateFromDB(DWORD dwId)
 
        if (!LoadCommonProperties())
    {
-      DbgPrintf(2, "Cannot load common properties for network map object %d", dwId);
+      DbgPrintf(2, _T("Cannot load common properties for network map object %d"), dwId);
       return FALSE;
    }
 
@@ -230,7 +230,13 @@ BOOL NetworkMap::CreateFromDB(DWORD dwId)
                                        TCHAR *data = DBGetField(hResult, i, 2, NULL, 0);
                                        if (data != NULL)
                                        {
-                                               config->loadXmlConfigFromMemory(data, (int)strlen(data), _T("<database>"), _T("element"));
+#ifdef UNICODE
+                                               char *utf8data = UTF8StringFromWideString(data);
+                                               config->loadXmlConfigFromMemory(utf8data, (int)strlen(utf8data), _T("<database>"), "element");
+                                               free(utf8data);
+#else
+                                               config->loadXmlConfigFromMemory(data, (int)strlen(data), _T("<database>"), "element");
+#endif
                                                free(data);
                                                switch(DBGetFieldLong(hResult, i, 1))
                                                {
index ed57275..dc35975 100644 (file)
@@ -113,14 +113,14 @@ BOOL NetObj::SaveToDB(DB_HANDLE hdb)
 
 BOOL NetObj::DeleteFromDB()
 {
-   char szQuery[256];
+   TCHAR szQuery[256];
 
    // Delete ACL
-   sprintf(szQuery, "DELETE FROM acl WHERE object_id=%d", m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM acl WHERE object_id=%d"), m_dwId);
    QueueSQLRequest(szQuery);
-   sprintf(szQuery, "DELETE FROM object_properties WHERE object_id=%d", m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM object_properties WHERE object_id=%d"), m_dwId);
    QueueSQLRequest(szQuery);
-   sprintf(szQuery, "DELETE FROM object_custom_attributes WHERE object_id=%d", m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("DELETE FROM object_custom_attributes WHERE object_id=%d"), m_dwId);
    QueueSQLRequest(szQuery);
    return TRUE;
 }
@@ -678,12 +678,12 @@ void NetObj::CalculateCompoundStatus(BOOL bForcedRecalc)
 
 BOOL NetObj::LoadACLFromDB(void)
 {
-   char szQuery[256];
+   TCHAR szQuery[256];
    DB_RESULT hResult;
    BOOL bSuccess = FALSE;
 
    // Load access list
-   sprintf(szQuery, "SELECT user_id,access_rights FROM acl WHERE object_id=%d", m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), "SELECT user_id,access_rights FROM acl WHERE object_id=%d", m_dwId);
    hResult = DBSelect(g_hCoreDB, szQuery);
    if (hResult != NULL)
    {
@@ -718,9 +718,9 @@ struct SAVE_PARAM
 
 static void EnumerationHandler(DWORD dwUserId, DWORD dwAccessRights, void *pArg)
 {
-   char szQuery[256];
+   TCHAR szQuery[256];
 
-   sprintf(szQuery, "INSERT INTO acl (object_id,user_id,access_rights) VALUES (%d,%d,%d)",
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), "INSERT INTO acl (object_id,user_id,access_rights) VALUES (%d,%d,%d)",
            ((SAVE_PARAM *)pArg)->dwObjectId, dwUserId, dwAccessRights);
    DBQuery(((SAVE_PARAM *)pArg)->hdb, szQuery);
 }
@@ -732,13 +732,13 @@ static void EnumerationHandler(DWORD dwUserId, DWORD dwAccessRights, void *pArg)
 
 BOOL NetObj::SaveACLToDB(DB_HANDLE hdb)
 {
-   char szQuery[256];
+   TCHAR szQuery[256];
    BOOL bSuccess = FALSE;
    SAVE_PARAM sp;
 
    // Save access list
    LockACL();
-   sprintf(szQuery, "DELETE FROM acl WHERE object_id=%d", m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), "DELETE FROM acl WHERE object_id=%d", m_dwId);
    if (DBQuery(hdb, szQuery))
    {
       sp.dwObjectId = m_dwId;
index 1c7ff9f..1504317 100644 (file)
@@ -93,7 +93,7 @@ BOOL NetworkService::SaveToDB(DB_HANDLE hdb)
    SaveCommonProperties(hdb);
 
    // Check for object's existence in database
-   _stprintf(szQuery, _T("SELECT id FROM network_services WHERE id=%d"), m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("SELECT id FROM network_services WHERE id=%d"), m_dwId);
    hResult = DBSelect(hdb, szQuery);
    if (hResult != NULL)
    {
@@ -186,8 +186,7 @@ BOOL NetworkService::CreateFromDB(DWORD dwId)
          pObject = FindObjectById(dwHostNodeId);
          if (pObject == NULL)
          {
-            nxlog_write(MSG_INVALID_NODE_ID_EX, EVENTLOG_ERROR_TYPE, "dds",
-                        dwId, dwHostNodeId, "network service");
+            nxlog_write(MSG_INVALID_NODE_ID_EX, EVENTLOG_ERROR_TYPE, "dds", dwId, dwHostNodeId, _T("network service"));
          }
          else if (pObject->Type() != OBJECT_NODE)
          {
@@ -208,7 +207,7 @@ BOOL NetworkService::CreateFromDB(DWORD dwId)
             if (pObject == NULL)
             {
                nxlog_write(MSG_INVALID_NODE_ID_EX, EVENTLOG_ERROR_TYPE,
-                        "dds", dwId, m_dwPollerNode, "network service");
+                        "dds", dwId, m_dwPollerNode, _T("network service"));
                bResult = FALSE;
             }
             else if (pObject->Type() != OBJECT_NODE)
@@ -431,7 +430,7 @@ void NetworkService::StatusPoll(ClientSession *pSession, DWORD dwRqId,
                {
                        m_iStatus = newStatus;
                        m_iPendingStatus = -1;  // Invalidate pending status
-                       SendPollerMsg(dwRqId, "      Service status changed to %s\r\n", g_szStatusTextSmall[m_iStatus]);
+                       SendPollerMsg(dwRqId, _T("      Service status changed to %s\r\n"), g_szStatusTextSmall[m_iStatus]);
                        PostEventEx(pEventQueue, m_iStatus == STATUS_NORMAL ? EVENT_SERVICE_UP : 
                                                        (m_iStatus == STATUS_CRITICAL ? EVENT_SERVICE_DOWN : EVENT_SERVICE_UNKNOWN),
                                                        m_pHostNode->Id(), "sdd", m_szName, m_dwId, m_iServiceType);
@@ -440,7 +439,7 @@ void NetworkService::StatusPoll(ClientSession *pSession, DWORD dwRqId,
                        UnlockData();
                }
    }
-   SendPollerMsg(dwRqId, "   Finished status poll on network service %s\r\n", m_szName);
+   SendPollerMsg(dwRqId, _T("   Finished status poll on network service %s\r\n"), m_szName);
 }
 
 
index 7bd53d0..b249df1 100644 (file)
@@ -41,9 +41,8 @@ Node::Node()
    m_iStatusPollType = POLL_ICMP_PING;
    m_snmpVersion = SNMP_VERSION_1;
    m_wSNMPPort = SNMP_DEFAULT_PORT;
-       TCHAR community[MAX_COMMUNITY_LENGTH];
-   ConfigReadStr("DefaultCommunityString", community,
-                 MAX_COMMUNITY_LENGTH, "public");
+       char community[MAX_COMMUNITY_LENGTH];
+   ConfigReadStrA(_T("DefaultCommunityString"), community, MAX_COMMUNITY_LENGTH, "public");
        m_snmpSecurity = new SNMP_SecurityContext(c