intermediate commit - more UNICODE-related errors fixed
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 14 Dec 2010 22:42:57 +0000 (22:42 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 14 Dec 2010 22:42:57 +0000 (22:42 +0000)
14 files changed:
doc/internal/db_format_change.txt
include/netxmsdb.h
include/nxsnmp.h
src/libnetxms/unicode.cpp
src/server/core/datacoll.cpp
src/server/core/evproc.cpp
src/server/core/netobj.cpp
src/server/core/netsrv.cpp
src/server/core/session.cpp
src/server/core/situation.cpp
src/server/core/snmp.cpp
src/server/core/snmptrap.cpp
src/server/include/nms_objects.h
src/server/tools/nxdbmgr/upgrade.cpp

index 9c2629f..9d7ed25 100644 (file)
@@ -1,4 +1,11 @@
 ***************
+* 217 ==> 218 *
+***************
+
+- All text columns in table "snmp_communities" converted from # encoded format
+
+
+***************
 * 216 ==> 217 *
 ***************
 
index 5ab9186..1db37b1 100644 (file)
@@ -23,6 +23,6 @@
 #ifndef _netxmsdb_h
 #define _netxmsdb_h
 
-#define DB_FORMAT_VERSION   217
+#define DB_FORMAT_VERSION   218
 
 #endif
index 40b0ea4..0a804db 100644 (file)
@@ -404,10 +404,10 @@ public:
    DWORD GetValueLength(void) { return m_dwValueLength; }
    const BYTE *GetValue(void) { return m_pValue; }
 
-   DWORD GetValueAsUInt(void);
-   LONG GetValueAsInt(void);
+   DWORD GetValueAsUInt();
+   LONG GetValueAsInt();
    TCHAR *GetValueAsString(TCHAR *pszBuffer, DWORD dwBufferSize);
-   SNMP_ObjectId *GetValueAsObjectId(void);
+   SNMP_ObjectId *GetValueAsObjectId();
    TCHAR *GetValueAsMACAddr(TCHAR *pszBuffer);
    TCHAR *GetValueAsIPAddr(TCHAR *pszBuffer);
 
index 55485cd..dcb9019 100644 (file)
@@ -1070,30 +1070,85 @@ int LIBNETXMS_EXPORTABLE nx_swprintf(WCHAR *buffer, size_t size, const WCHAR *fo
 static WCHAR *ReplaceFormatSpecs(const WCHAR *oldFormat)
 {
        WCHAR *fmt, *p;
+       int state = 0;
+       bool hmod;
 
        fmt = wcsdup(oldFormat);
        for(p = fmt; *p != 0; p++)
        {
-               if ((*p == _T('%')) && (*(p + 1) != 0))
+               switch(state)
                {
-                       p++;
-                       switch(*p)
-                       {
-                               case _T('s'):
-                                       *p = _T('S');
-                                       break;
-                               case _T('S'):
-                                       *p = _T('s');
-                                       break;
-                               case _T('c'):
-                                       *p = _T('C');
-                                       break;
-                               case _T('C'):
-                                       *p = _T('c');
-                                       break;
-                               default:
-                                       break;
-                       }
+                       case 0: // Normal text
+                               if (*p == L'%')
+                               {
+                                       state = 1;
+                                       hmod = false;
+                               }
+                               break;
+                       case 1: // Format start
+                               switch(*p)
+                               {
+                                       case L's':
+                                               if (hmod)
+                                               {
+                                                       memmove(p - 1, p, wcslen(p - 1) * sizeof(TCHAR));
+                                               }
+                                               else
+                                               {
+                                                       *p = L'S';
+                                               }
+                                               state = 0;
+                                               break;
+                                       case L'S':
+                                               *p = L's';
+                                               state = 0;
+                                               break;
+                                       case L'c':
+                                               if (hmod)
+                                               {
+                                                       memmove(p - 1, p, wcslen(p - 1) * sizeof(TCHAR));
+                                               }
+                                               else
+                                               {
+                                                       *p = L'C';
+                                               }
+                                               state = 0;
+                                               break;
+                                       case L'C':
+                                               *p = L'c';
+                                               state = 0;
+                                               break;
+                                       case L'.':      // All this characters could be part of format specifier        
+                                       case L'*':      // and has no interest for us
+                                       case L'+':
+                                       case L'-':
+                                       case L' ':
+                                       case L'#':
+                                       case L'0':
+                                       case L'1':
+                                       case L'2':
+                                       case L'3':
+                                       case L'4':
+                                       case L'5':
+                                       case L'6':
+                                       case L'7':
+                                       case L'8':
+                                       case L'9':
+                                       case L'l':
+                                       case L'L':
+                                       case L'F':
+                                       case L'N':
+                                       case L'w':
+                                               break;
+                                       case L'h':      // check for %hs
+                                               hmod = true;
+                                               break;
+                                       default:                // All other cahacters means end of format
+                                               state = 0;
+                                               break;
+
+                               }
+                               break;
                }
        }
        return fmt;
index 5f15812..4241961 100644 (file)
@@ -284,7 +284,7 @@ static THREAD_RESULT THREAD_CALL StatCollector(void *pArg)
 // Initialize data collection subsystem
 //
 
-BOOL InitDataCollector(void)
+BOOL InitDataCollector()
 {
    int i, iNumCollectors;
 
index 1287cd5..893d320 100644 (file)
@@ -134,9 +134,9 @@ THREAD_RESULT THREAD_CALL EventProcessor(void *arg)
       {
          TCHAR szQuery[8192];
 
-         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)"), 
+         _sntprintf(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),
index dc35975..f5a7d79 100644 (file)
@@ -440,7 +440,7 @@ void NetObj::Delete(BOOL bIndexLocked)
 {
    DWORD i;
 
-   DbgPrintf(4, "Deleting object %d [%s]", m_dwId, m_szName);
+   DbgPrintf(4, _T("Deleting object %d [%s]"), m_dwId, m_szName);
 
        // Prevent object change propagation util it marked as deleted
        // (to prevent object re-appearance in GUI if client hides object
@@ -452,7 +452,7 @@ void NetObj::Delete(BOOL bIndexLocked)
    PrepareForDeletion();
 
    // Remove references to this object from parent objects
-   DbgPrintf(5, "NetObj::Delete(): clearing parent list for object %d", m_dwId);
+   DbgPrintf(5, _T("NetObj::Delete(): clearing parent list for object %d"), m_dwId);
    LockParentList(TRUE);
    for(i = 0; i < m_dwParentCount; i++)
    {
@@ -465,7 +465,7 @@ void NetObj::Delete(BOOL bIndexLocked)
    UnlockParentList();
 
    // Delete references to this object from child objects
-   DbgPrintf(5, "NetObj::Delete(): clearing child list for object %d", m_dwId);
+   DbgPrintf(5, _T("NetObj::Delete(): clearing child list for object %d"), m_dwId);
    LockChildList(TRUE);
    for(i = 0; i < m_dwChildCount; i++)
    {
@@ -484,11 +484,11 @@ void NetObj::Delete(BOOL bIndexLocked)
    Modify();
    UnlockData();
 
-   DbgPrintf(5, "NetObj::Delete(): deleting object %d from indexes", m_dwId);
+   DbgPrintf(5, _T("NetObj::Delete(): deleting object %d from indexes"), m_dwId);
    NetObjDeleteFromIndexes(this);
 
    // Notify all other objects about object deletion
-   DbgPrintf(5, "NetObj::Delete(): calling OnObjectDelete(%d)", m_dwId);
+   DbgPrintf(5, _T("NetObj::Delete(): calling OnObjectDelete(%d)"), m_dwId);
    if (!bIndexLocked)
       RWLockReadLock(g_rwlockIdIndex, INFINITE);
    for(i = 0; i < g_dwIdIndexSize; i++)
@@ -499,7 +499,7 @@ void NetObj::Delete(BOOL bIndexLocked)
    if (!bIndexLocked)
       RWLockUnlock(g_rwlockIdIndex);
 
-   DbgPrintf(4, "Object %d successfully deleted", m_dwId);
+   DbgPrintf(4, _T("Object %d successfully deleted"), m_dwId);
 }
 
 
@@ -516,7 +516,7 @@ void NetObj::OnObjectDelete(DWORD dwObjectId)
 // Print childs IDs
 //
 
-const char *NetObj::ChildList(char *szBuffer)
+const char *NetObj::ChildList(TCHAR *szBuffer)
 {
    DWORD i;
    char *pBuf = szBuffer;
@@ -525,7 +525,7 @@ const char *NetObj::ChildList(char *szBuffer)
    LockChildList(FALSE);
    for(i = 0, pBuf = szBuffer; i < m_dwChildCount; i++)
    {
-      sprintf(pBuf, "%d ", m_pChildList[i]->Id());
+      _sntprintf(pBuf, 10, _T("%d "), m_pChildList[i]->Id());
       while(*pBuf)
          pBuf++;
    }
@@ -540,7 +540,7 @@ const char *NetObj::ChildList(char *szBuffer)
 // Print parents IDs
 //
 
-const char *NetObj::ParentList(char *szBuffer)
+const char *NetObj::ParentList(TCHAR *szBuffer)
 {
    DWORD i;
    char *pBuf = szBuffer;
@@ -549,7 +549,7 @@ const char *NetObj::ParentList(char *szBuffer)
    LockParentList(FALSE);
    for(i = 0; i < m_dwParentCount; i++)
    {
-      sprintf(pBuf, "%d ", m_pParentList[i]->Id());
+      _sntprintf(pBuf, 10, _T("%d "), m_pParentList[i]->Id());
       while(*pBuf)
          pBuf++;
    }
@@ -683,7 +683,7 @@ BOOL NetObj::LoadACLFromDB(void)
    BOOL bSuccess = FALSE;
 
    // Load access list
-   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), "SELECT user_id,access_rights FROM acl WHERE object_id=%d", m_dwId);
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("SELECT user_id,access_rights FROM acl WHERE object_id=%d"), m_dwId);
    hResult = DBSelect(g_hCoreDB, szQuery);
    if (hResult != NULL)
    {
@@ -720,7 +720,7 @@ static void EnumerationHandler(DWORD dwUserId, DWORD dwAccessRights, void *pArg)
 {
    TCHAR szQuery[256];
 
-   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), "INSERT INTO acl (object_id,user_id,access_rights) VALUES (%d,%d,%d)",
+   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), _T("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);
 }
@@ -738,7 +738,7 @@ BOOL NetObj::SaveACLToDB(DB_HANDLE hdb)
 
    // Save access list
    LockACL();
-   _sntprintf(szQuery, sizeof(szQuery) / sizeof(TCHAR), "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);
    if (DBQuery(hdb, szQuery))
    {
       sp.dwObjectId = m_dwId;
index 1504317..f6af0bb 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
@@ -108,10 +108,10 @@ BOOL NetworkService::SaveToDB(DB_HANDLE hdb)
    if (bNewObject)
    {
       _sntprintf(szQuery, 16384, _T("INSERT INTO network_services (id,node_id,"
-                                    "service_type,ip_bind_addr,ip_proto,ip_port,"
-                                    "check_request,check_responce,poller_node_id,"
-                                                                                               "required_polls) VALUES "
-                                    "(%d,%d,%d,'%s',%d,%d,'%s','%s',%d,%d)"),
+                                    _T("service_type,ip_bind_addr,ip_proto,ip_port,")
+                                    _T("check_request,check_responce,poller_node_id,")
+                                                                                               _T("required_polls) VALUES ")
+                                    _T("(%d,%d,%d,'%s',%d,%d,'%s','%s',%d,%d)")),
                  m_dwId, m_pHostNode->Id(), m_iServiceType,
                  IpToStr(m_dwIpAddr, szIpAddr), m_wProto, m_wPort, pszEscRequest,
                  pszEscResponse, m_dwPollerNode, m_iRequiredPollCount);
@@ -119,10 +119,10 @@ BOOL NetworkService::SaveToDB(DB_HANDLE hdb)
    else
    {
       _sntprintf(szQuery, 16384, _T("UPDATE network_services SET node_id=%d,"
-                                    "service_type=%d,ip_bind_addr='%s',"
-                                    "ip_proto=%d,ip_port=%d,check_request='%s',"
-                                    "check_responce='%s',poller_node_id=%d,"
-                                                                                               "required_polls=%d WHERE id=%d"),
+                                    _T("service_type=%d,ip_bind_addr='%s',")
+                                    _T("ip_proto=%d,ip_port=%d,check_request='%s',")
+                                    _T("check_responce='%s',poller_node_id=%d,")
+                                                                                               _T("required_polls=%d WHERE id=%d")),
                  m_pHostNode->Id(), m_iServiceType,
                  IpToStr(m_dwIpAddr, szIpAddr), m_wProto, m_wPort, pszEscRequest,
                  pszEscResponse, m_dwPollerNode, m_iRequiredPollCount, m_dwId);
@@ -159,8 +159,8 @@ BOOL NetworkService::CreateFromDB(DWORD dwId)
       return FALSE;
 
    _sntprintf(szQuery, 256, _T("SELECT node_id,service_type,"
-                               "ip_bind_addr,ip_proto,ip_port,check_request,check_responce,"
-                               "poller_node_id,required_polls FROM network_services WHERE id=%d"), dwId);
+                               _T("ip_bind_addr,ip_proto,ip_port,check_request,check_responce,")
+                               _T("poller_node_id,required_polls FROM network_services WHERE id=%d")), dwId);
    hResult = DBSelect(g_hCoreDB, szQuery);
    if (hResult == NULL)
       return FALSE;     // Query failed
@@ -367,8 +367,8 @@ void NetworkService::StatusPoll(ClientSession *pSession, DWORD dwRqId,
       return;     // Service without host node, which is VERY strange
    }
 
-   SendPollerMsg(dwRqId, "   Starting status poll on network service %s\r\n"
-                         "      Current status is %s\r\n",
+   SendPollerMsg(dwRqId, _T("   Starting status poll on network service %s\r\n")
+                         _T("      Current status is %s\r\n"),
                  m_szName, g_szStatusTextSmall[m_iStatus]);
 
    if (m_dwPollerNode != 0)
@@ -389,7 +389,7 @@ void NetworkService::StatusPoll(ClientSession *pSession, DWORD dwRqId,
       TCHAR szBuffer[16];
       DWORD dwStatus;
 
-      SendPollerMsg(dwRqId, "      Polling service from node %s [%s]\r\n",
+      SendPollerMsg(dwRqId, _T("      Polling service from node %s [%s]\r\n"),
                     pNode->Name(), IpToStr(pNode->IpAddr(), szBuffer));
       if (pNode->CheckNetworkService(&dwStatus, 
                                      (m_dwIpAddr == 0) ? m_pHostNode->IpAddr() : m_dwIpAddr,
@@ -397,11 +397,11 @@ void NetworkService::StatusPoll(ClientSession *pSession, DWORD dwRqId,
                                      m_pszRequest, m_pszResponse) == ERR_SUCCESS)
       {
          newStatus = (dwStatus == 0) ? STATUS_NORMAL : STATUS_CRITICAL;
-         SendPollerMsg(dwRqId, "      Agent reports service status [%d]\r\n", dwStatus);
+         SendPollerMsg(dwRqId, _T("      Agent reports service status [%d]\r\n"), dwStatus);
       }
       else
       {
-         SendPollerMsg(dwRqId, "      Unable to check service status due to agent or communication error\r\n");
+         SendPollerMsg(dwRqId, _T("      Unable to check service status due to agent or communication error\r\n"));
          newStatus = STATUS_UNKNOWN;
       }
 
@@ -410,7 +410,7 @@ void NetworkService::StatusPoll(ClientSession *pSession, DWORD dwRqId,
    }
    else
    {
-      SendPollerMsg(dwRqId, "      Unable to find node object for poll\r\n");
+      SendPollerMsg(dwRqId, _T("      Unable to find node object for poll\r\n"));
       newStatus = STATUS_UNKNOWN;
    }
 
index 7e0365f..c8dc5bc 100644 (file)
@@ -9384,7 +9384,6 @@ void ClientSession::SendCommunityList(DWORD dwRqId)
                        for(i = 0, id = VID_STRING_LIST_BASE; i < count; i++)
                        {
                                DBGetField(hResult, i, 0, buffer, 256);
-                               DecodeSQLString(buffer);
                                msg.SetVariable(id++, buffer);
                        }
                        DBFreeResult(hResult);
@@ -9411,7 +9410,7 @@ void ClientSession::SendCommunityList(DWORD dwRqId)
 void ClientSession::UpdateCommunityList(CSCPMessage *pRequest)
 {
    CSCPMessage msg;
-       TCHAR value[256], *escValue, query[1024];
+       TCHAR value[256], query[1024];
        int i, count;
        DWORD id;
 
@@ -9427,9 +9426,8 @@ void ClientSession::UpdateCommunityList(CSCPMessage *pRequest)
                        for(i = 0, id = VID_STRING_LIST_BASE; i < count; i++)
                        {
                                pRequest->GetVariableStr(id++, value, 256);
-                               escValue = EncodeSQLString(value);
-                               _sntprintf(query, 1024, _T("INSERT INTO snmp_communities (id,community) VALUES(%d,'%s')"), i + 1, escValue);
-                               free(escValue);
+                               String escValue = DBPrepareString(g_hCoreDB, value);
+                               _sntprintf(query, 1024, _T("INSERT INTO snmp_communities (id,community) VALUES(%d,%s)"), i + 1, (const TCHAR *)escValue);
                                if (!DBQuery(g_hCoreDB, query))
                                        break;
                        }
index 8dfb247..dddd2c2 100644 (file)
@@ -175,12 +175,14 @@ void Situation::SaveToDatabase()
 {
        DB_RESULT result;
        TCHAR *query, *escName, *escComments;
+       size_t qlen;
        BOOL isUpdate;
        
        escName = EncodeSQLString(CHECK_NULL_EX(m_name));
        escComments = EncodeSQLString(CHECK_NULL_EX(m_comments));
-       query = (TCHAR *)malloc((_tcslen(escName) + _tcslen(escComments) + 256) * sizeof(TCHAR));
-       _stprintf(query, _T("SELECT id FROM situations WHERE id=%d"), m_id);
+       qlen = _tcslen(escName) + _tcslen(escComments) + 256;
+       query = (TCHAR *)malloc(qlen * sizeof(TCHAR));
+       _sntprintf(query, qlen, _T("SELECT id FROM situations WHERE id=%d"), m_id);
        result = DBSelect(g_hCoreDB, query);
        if (result != NULL)
        {
@@ -192,11 +194,11 @@ void Situation::SaveToDatabase()
                isUpdate = FALSE;
        }
        if (isUpdate)
-               _stprintf(query, _T("UPDATE situations SET name='%s',comments='%s' WHERE id=%d"),
-                         escName, escComments, m_id);
+               _sntprintf(query, qlen, _T("UPDATE situations SET name='%s',comments='%s' WHERE id=%d"),
+                          escName, escComments, m_id);
        else
-               _stprintf(query, _T("INSERT INTO situations (id,name,comments) VALUES (%d,'%s','%s')"),
-                         m_id, escName, escComments);
+               _sntprintf(query, qlen, _T("INSERT INTO situations (id,name,comments) VALUES (%d,'%s','%s')"),
+                          m_id, escName, escComments);
        free(escName);
        free(escComments);
        DBQuery(g_hCoreDB, query);
index 3a0eb08..b1a2431 100644 (file)
@@ -108,7 +108,7 @@ DWORD OidToType(TCHAR *pszOid, DWORD *pdwFlags)
 //
 
 DWORD SnmpGet(DWORD dwVersion, SNMP_Transport *pTransport,
-              const char *szOidStr, const DWORD *oidBinary, DWORD dwOidLen, void *pValue,
+              const TCHAR *szOidStr, const DWORD *oidBinary, DWORD dwOidLen, void *pValue,
               DWORD dwBufferSize, BOOL bVerbose, BOOL bStringResult)
 {
    SNMP_PDU *pRqPDU, *pRespPDU;
@@ -211,7 +211,7 @@ DWORD SnmpGet(DWORD dwVersion, SNMP_Transport *pTransport,
 // Enumerate multiple values by walking throgh MIB, starting at given root
 //
 
-DWORD SnmpEnumerate(DWORD dwVersion, SNMP_Transport *pTransport, const char *szRootOid,
+DWORD SnmpEnumerate(DWORD dwVersion, SNMP_Transport *pTransport, const TCHAR *szRootOid,
                     DWORD (* pHandler)(DWORD, SNMP_Variable *, SNMP_Transport *, void *),
                     void *pUserArg, BOOL bVerbose)
 {
@@ -353,11 +353,11 @@ static DWORD HandlerIpAddr(DWORD dwVersion, SNMP_Variable *pVar,
                      sizeof(INTERFACE_INFO) * ((INTERFACE_LIST *)pArg)->iNumEntries);
                memcpy(&(((INTERFACE_LIST *)pArg)->pInterfaces[((INTERFACE_LIST *)pArg)->iNumEntries - 1]), 
                       &(((INTERFACE_LIST *)pArg)->pInterfaces[i]), sizeof(INTERFACE_INFO));
-               if (strlen(((INTERFACE_LIST *)pArg)->pInterfaces[i].szName) < MAX_OBJECT_NAME - 6)
+               if (_tcslen(((INTERFACE_LIST *)pArg)->pInterfaces[i].szName) < MAX_OBJECT_NAME - 6)
                {
                   TCHAR szBuffer[8];
 
-                  sprintf(szBuffer,_T(":%d"), ((INTERFACE_LIST *)pArg)->pInterfaces[i].iNumSecondary++);
+                  _sntprintf(szBuffer, 8, _T(":%d"), ((INTERFACE_LIST *)pArg)->pInterfaces[i].iNumSecondary++);
                   _tcscat(((INTERFACE_LIST *)pArg)->pInterfaces[((INTERFACE_LIST *)pArg)->iNumEntries - 1].szName, szBuffer);
                }
                i = ((INTERFACE_LIST *)pArg)->iNumEntries - 1;
@@ -417,7 +417,7 @@ INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwVersion, SNMP_Transport *pTransport
          // Get interface alias if needed
          if (useAliases > 0)
          {
-                     sprintf(szOid, _T(".1.3.6.1.2.1.31.1.1.1.18.%d"), pIfList->pInterfaces[i].dwIndex);
+                     _sntprintf(szOid, 128, _T(".1.3.6.1.2.1.31.1.1.1.18.%d"), pIfList->pInterfaces[i].dwIndex);
                      if (SnmpGet(dwVersion, pTransport, szOid, NULL, 0,
                                   pIfList->pInterfaces[i].szName, MAX_DB_STRING,
                                   FALSE, FALSE) != SNMP_ERR_SUCCESS)
@@ -431,12 +431,12 @@ INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwVersion, SNMP_Transport *pTransport
          }
 
                        // Try to get interface name from ifXTable, if unsuccessful or disabled, use ifTable
-         sprintf(szOid, _T(".1.3.6.1.2.1.31.1.1.1.1.%d"), pIfList->pInterfaces[i].dwIndex);
+         _sntprintf(szOid, 128, _T(".1.3.6.1.2.1.31.1.1.1.1.%d"), pIfList->pInterfaces[i].dwIndex);
          if (!useIfXTable ||
                                 (SnmpGet(dwVersion, pTransport, szOid, NULL, 0,
                       szBuffer, 256, FALSE, FALSE) != SNMP_ERR_SUCCESS))
          {
-                     sprintf(szOid, _T(".1.3.6.1.2.1.2.2.1.2.%d"), pIfList->pInterfaces[i].dwIndex);
+                     _sntprintf(szOid, 128, _T(".1.3.6.1.2.1.2.2.1.2.%d"), pIfList->pInterfaces[i].dwIndex);
                      if (SnmpGet(dwVersion, pTransport, szOid, NULL, 0,
                                  szBuffer, 256, FALSE, FALSE) != SNMP_ERR_SUCCESS)
                         break;
@@ -485,7 +485,7 @@ INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwVersion, SNMP_Transport *pTransport
          }
 
          // Interface type
-         sprintf(szOid, _T(".1.3.6.1.2.1.2.2.1.3.%d"), pIfList->pInterfaces[i].dwIndex);
+         _sntprintf(szOid, 128, _T(".1.3.6.1.2.1.2.2.1.3.%d"), pIfList->pInterfaces[i].dwIndex);
          if (SnmpGet(dwVersion, pTransport, szOid, NULL, 0,
                       &pIfList->pInterfaces[i].dwType, sizeof(DWORD),
                       FALSE, FALSE) != SNMP_ERR_SUCCESS)
@@ -494,7 +494,7 @@ INTERFACE_LIST *SnmpGetInterfaceList(DWORD dwVersion, SNMP_Transport *pTransport
                        }
 
          // MAC address
-         sprintf(szOid, _T(".1.3.6.1.2.1.2.2.1.6.%d"), pIfList->pInterfaces[i].dwIndex);
+         _sntprintf(szOid, 128, _T(".1.3.6.1.2.1.2.2.1.6.%d"), pIfList->pInterfaces[i].dwIndex);
          memset(szBuffer, 0, MAC_ADDR_LENGTH);
          if (SnmpGet(dwVersion, pTransport, szOid, NULL, 0,
                       szBuffer, 256, FALSE, TRUE) == SNMP_ERR_SUCCESS)
@@ -729,7 +729,7 @@ static SNMP_SecurityContext *SnmpCheckV3CommSettings(SNMP_Transport *pTransport,
        // Check original SNMP V3 settings, if set
        if ((originalContext != NULL) && (originalContext->getSecurityModel() == SNMP_SECURITY_MODEL_USM))
        {
-               DbgPrintf(5, _T("SnmpCheckV3CommSettings: trying %s/%d:%d"), originalContext->getUser(),
+               DbgPrintf(5, _T("SnmpCheckV3CommSettings: trying %hs/%d:%d"), originalContext->getUser(),
                          originalContext->getAuthMethod(), originalContext->getPrivMethod());
                pTransport->setSecurityContext(new SNMP_SecurityContext(originalContext));
                if (SnmpGet(SNMP_VERSION_3, pTransport, _T(".1.3.6.1.2.1.1.2.0"), NULL,
@@ -744,19 +744,19 @@ static SNMP_SecurityContext *SnmpCheckV3CommSettings(SNMP_Transport *pTransport,
        DB_RESULT hResult = DBSelect(g_hCoreDB, _T("SELECT user_name,auth_method,priv_method,auth_password,priv_password FROM usm_credentials"));
        if (hResult != NULL)
        {
-               TCHAR name[MAX_DB_STRING], authPasswd[MAX_DB_STRING], privPasswd[MAX_DB_STRING];
+               char name[MAX_DB_STRING], authPasswd[MAX_DB_STRING], privPasswd[MAX_DB_STRING];
                SNMP_SecurityContext *ctx;
                int i, count = DBGetNumRows(hResult);
 
                for(i = 0; i < count; i++)
                {
-                       DBGetField(hResult, i, 0, name, MAX_DB_STRING);
-                       DBGetField(hResult, i, 3, authPasswd, MAX_DB_STRING);
-                       DBGetField(hResult, i, 4, privPasswd, MAX_DB_STRING);
+                       DBGetFieldA(hResult, i, 0, name, MAX_DB_STRING);
+                       DBGetFieldA(hResult, i, 3, authPasswd, MAX_DB_STRING);
+                       DBGetFieldA(hResult, i, 4, privPasswd, MAX_DB_STRING);
                        ctx = new SNMP_SecurityContext(name, authPasswd, privPasswd,
                                                       DBGetFieldLong(hResult, i, 1), DBGetFieldLong(hResult, i, 2));
                        pTransport->setSecurityContext(ctx);
-                       DbgPrintf(5, _T("SnmpCheckV3CommSettings: trying %s/%d:%d"), ctx->getUser(), ctx->getAuthMethod(), ctx->getPrivMethod());
+                       DbgPrintf(5, _T("SnmpCheckV3CommSettings: trying %hs/%d:%d"), ctx->getUser(), ctx->getAuthMethod(), ctx->getPrivMethod());
                        if (SnmpGet(SNMP_VERSION_3, pTransport, _T(".1.3.6.1.2.1.1.2.0"), NULL,
                                                        0, buffer, 1024, FALSE, FALSE) == SNMP_ERR_SUCCESS)
                        {
@@ -788,7 +788,8 @@ static SNMP_SecurityContext *SnmpCheckV3CommSettings(SNMP_Transport *pTransport,
 SNMP_SecurityContext *SnmpCheckCommSettings(SNMP_Transport *pTransport, int *version, SNMP_SecurityContext *originalContext)
 {
        int i, count, snmpVer = SNMP_VERSION_2C;
-       char defCommunity[MAX_COMMUNITY_LENGTH], buffer[1024], temp[256];
+       TCHAR buffer[1024];
+       char defCommunity[MAX_COMMUNITY_LENGTH];
        DB_RESULT hResult;
 
        // Check for V3 USM
@@ -799,13 +800,13 @@ SNMP_SecurityContext *SnmpCheckCommSettings(SNMP_Transport *pTransport, int *ver
                return securityContext;
        }
 
-       ConfigReadStr(_T("DefaultCommunityString"), defCommunity, MAX_COMMUNITY_LENGTH, _T("public"));
+       ConfigReadStrA(_T("DefaultCommunityString"), defCommunity, MAX_COMMUNITY_LENGTH, "public");
 
 restart_check:
        // Check current community first
        if ((originalContext != NULL) && (originalContext->getSecurityModel() != SNMP_SECURITY_MODEL_USM))
        {
-               DbgPrintf(5, _T("SnmpCheckCommSettings: trying version %d community '%s'"), snmpVer, originalContext->getCommunity());
+               DbgPrintf(5, _T("SnmpCheckCommSettings: trying version %d community '%hs'"), snmpVer, originalContext->getCommunity());
                pTransport->setSecurityContext(new SNMP_SecurityContext(originalContext));
                if (SnmpGet(snmpVer, pTransport, _T(".1.3.6.1.2.1.1.2.0"), NULL,
                                                0, buffer, 1024, FALSE, FALSE) == SNMP_ERR_SUCCESS)
@@ -829,15 +830,15 @@ restart_check:
        hResult = DBSelect(g_hCoreDB, _T("SELECT community FROM snmp_communities"));
        if (hResult != NULL)
        {
+               char temp[256];
+
                count = DBGetNumRows(hResult);
                for(i = 0; i < count; i++)
                {
-                       DBGetField(hResult, i, 0, temp, 256);
-                       DecodeSQLString(temp);
-                       DbgPrintf(5, _T("SnmpCheckCommSettings: trying version %d community '%s'"), snmpVer, temp);
+                       DBGetFieldA(hResult, i, 0, temp, 256);
+                       DbgPrintf(5, _T("SnmpCheckCommSettings: trying version %d community '%hs'"), snmpVer, temp);
                        pTransport->setSecurityContext(new SNMP_SecurityContext(temp));
-                       if (SnmpGet(snmpVer, pTransport, _T(".1.3.6.1.2.1.1.2.0"), NULL,
-                                                       0, buffer, 1024, FALSE, FALSE) == SNMP_ERR_SUCCESS)
+                       if (SnmpGet(snmpVer, pTransport, _T(".1.3.6.1.2.1.1.2.0"), NULL, 0, buffer, 1024, FALSE, FALSE) == SNMP_ERR_SUCCESS)
                        {
                                *version = snmpVer;
                                break;
index e644636..66b9dbf 100644 (file)
@@ -619,7 +619,7 @@ static BOOL SaveParameterMapping(NXC_TRAP_CFG_ENTRY *pTrap)
          }
          else
          {
-            _stprintf(szOID, _T("POS:%d"), pTrap->pMaps[i].dwOidLen & 0x7FFFFFFF);
+            _sntprintf(szOID, 1024, _T("POS:%d"), pTrap->pMaps[i].dwOidLen & 0x7FFFFFFF);
          }
          pszEscDescr = EncodeSQLString(pTrap->pMaps[i].szDescription);
          _sntprintf(szQuery, 1024, _T("INSERT INTO snmp_trap_pmap (trap_id,parameter,")
index fa7a5e9..134ea6e 100644 (file)
@@ -318,9 +318,9 @@ public:
    void DeleteCustomAttribute(const TCHAR *name) { m_customAttributes.remove(name); Modify(); }
 
    // Debug methods
-   const char *ParentList(char *szBuffer);
-   const char *ChildList(char *szBuffer);
-   const char *TimeStampAsText(void) { return ctime((time_t *)&m_dwTimeStamp); }
+   const char *ParentList(TCHAR *szBuffer);
+   const char *ChildList(TCHAR *szBuffer);
+   const char *TimeStampAsText() { return ctime((time_t *)&m_dwTimeStamp); }
 };
 
 
index 694c072..a52a2e1 100644 (file)
@@ -249,6 +249,20 @@ static BOOL SetColumnNullable(const TCHAR *table, const TCHAR *column, const TCH
 
 
 //
+// Upgrade from V217 to V218
+//
+
+static BOOL H_UpgradeFromV217(int currVersion, int newVersion)
+{
+       CHK_EXEC(SetColumnNullable(_T("snmp_communities"), _T("community"), _T("varchar(255)")));
+       CHK_EXEC(ConvertStrings(_T("snmp_communities"), _T("id"), _T("community")));
+
+       CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='218' WHERE var_name='SchemaVersion'")));
+   return TRUE;
+}
+
+
+//
 // Upgrade from V216 to V217
 //
 
@@ -4973,6 +4987,7 @@ static struct
        { 214, 215, H_UpgradeFromV214 },
        { 215, 216, H_UpgradeFromV215 },
        { 216, 217, H_UpgradeFromV216 },
+       { 217, 218, H_UpgradeFromV217 },
    { 0, NULL }
 };