fixed compilation warnings; minor refactoring
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 16 Jun 2016 06:51:19 +0000 (09:51 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 16 Jun 2016 06:51:19 +0000 (09:51 +0300)
17 files changed:
src/agent/core/nxagentd.cpp
src/agent/subagents/gps/main.cpp
src/server/core/actions.cpp
src/server/core/ap_jobs.cpp
src/server/core/download_job.cpp
src/server/core/epp.cpp
src/server/core/events.cpp
src/server/core/job.cpp
src/server/core/ldap.cpp
src/server/core/nxcore.vcproj
src/server/core/upload_job.cpp
src/server/core/userdb.cpp
src/server/include/nxcore_jobs.h
src/server/tools/nxdbmgr/check.cpp
src/snmp/libnxsnmp/transport.cpp
src/snmp/libnxsnmp/variable.cpp
tests/test-libnetxms/test-libnetxms.vcproj

index 182d2db..f3dfe51 100644 (file)
@@ -663,7 +663,6 @@ static void ParseServerList(TCHAR *serverList, bool isControl, bool isMaster)
 BOOL Initialize()
 {
    TCHAR *pItem, *pEnd;
-       TCHAR regPath[MAX_PATH];
 
    if (s_debugLevel == (UINT32)NXCONFIG_UNINITIALIZED_VALUE)
       s_debugLevel = 0;
index dbb98b8..90fd002 100644 (file)
@@ -337,7 +337,7 @@ static LONG H_LocationInfo(const TCHAR *param, const TCHAR *arg, TCHAR *value, A
          ret_double(value, s_nmeaInfo.VDOP);
          break;
       case 'X': // speed
-         ret_int(value, s_nmeaInfo.speed);
+         ret_double(value, s_nmeaInfo.speed);
          break;
       default:
          rc = SYSINFO_RC_UNSUPPORTED;
index c1c906b..3a454e7 100644 (file)
@@ -287,20 +287,17 @@ static void RunCommand(void *arg)
 /**
  * Forward event to other server
  */
-static BOOL ForwardEvent(const TCHAR *server, Event *event)
+static bool ForwardEvent(const TCHAR *server, Event *event)
 {
-       ISC *isc;
-       UINT32 i, addr, rcc;
-
-       addr = ResolveHostName(server);
-       if (addr == INADDR_NONE)
+   InetAddress addr = InetAddress::resolveHostName(server);
+       if (!addr.isValidUnicast())
        {
-               DbgPrintf(2, _T("ForwardEvent: unable to resolve host name %s"), server);
+               nxlog_debug(2, _T("ForwardEvent: host name %s is invalid or cannot be resolved"), server);
                return FALSE;
        }
 
-       isc = new ISC(addr);
-       rcc = isc->connect(ISC_SERVICE_EVENT_FORWARDER);
+       ISC *isc = new ISC(addr);
+       UINT32 rcc = isc->connect(ISC_SERVICE_EVENT_FORWARDER);
        if (rcc == ISC_ERR_SUCCESS)
        {
                NXCPMessage msg;
@@ -320,7 +317,7 @@ static BOOL ForwardEvent(const TCHAR *server, Event *event)
                        if (event->getUserTag() != NULL)
                                msg.setField(VID_USER_TAG, event->getUserTag());
                        msg.setField(VID_NUM_ARGS, (WORD)event->getParametersCount());
-                       for(i = 0; i < event->getParametersCount(); i++)
+                       for(int i = 0; i < event->getParametersCount(); i++)
                                msg.setField(VID_EVENT_ARG_BASE + i, event->getParameter(i));
 
                        if (isc->sendMessage(&msg))
@@ -361,7 +358,7 @@ static BOOL ExecuteActionScript(const TCHAR *scriptName, Event *event)
                // Pass event's parameters as arguments
                NXSL_Value **ppValueList = (NXSL_Value **)malloc(sizeof(NXSL_Value *) * event->getParametersCount());
                memset(ppValueList, 0, sizeof(NXSL_Value *) * event->getParametersCount());
-               for(UINT32 i = 0; i < event->getParametersCount(); i++)
+               for(int i = 0; i < event->getParametersCount(); i++)
                        ppValueList[i] = new NXSL_Value(event->getParameter(i));
 
                if (vm->run(event->getParametersCount(), ppValueList))
index 51ac505..2c8a8a0 100644 (file)
@@ -153,7 +153,7 @@ ServerJobResult PolicyDeploymentJob::run()
    if(success == JOB_RESULT_FAILED && m_retryCount-- > 0)
    {
       TCHAR description[256];
-      _sntprintf(description, 256, _T("Policy deploy failed. Wainting %d minutes to restart job."), getNextJobExecutionTime()/60);
+      _sntprintf(description, 256, _T("Policy deploy failed. Wainting %d minutes to restart job."), getRetryDelay() / 60);
       setDescription(description);
       success = JOB_RESULT_RESCHEDULE;
    }
@@ -177,7 +177,7 @@ const String PolicyDeploymentJob::serializeParameters()
  */
 void PolicyDeploymentJob::rescheduleExecution()
 {
-   AddOneTimeScheduledTask(_T("Policy.Deploy"), time(NULL) + getNextJobExecutionTime(), serializeParameters(), 0, getRemoteNode(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
+   AddOneTimeScheduledTask(_T("Policy.Deploy"), time(NULL) + getRetryDelay(), serializeParameters(), 0, getRemoteNode(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
 }
 
 
@@ -307,7 +307,7 @@ ServerJobResult PolicyUninstallJob::run()
    if(success == JOB_RESULT_FAILED && m_retryCount-- > 0)
    {
       TCHAR description[256];
-      _sntprintf(description, 256, _T("Policy uninstall failed. Wainting %d minutes to restart job."), getNextJobExecutionTime()/60);
+      _sntprintf(description, 256, _T("Policy uninstall failed. Wainting %d minutes to restart job."), getRetryDelay() / 60);
       setDescription(description);
       success = JOB_RESULT_RESCHEDULE;
    }
@@ -332,5 +332,5 @@ const String PolicyUninstallJob::serializeParameters()
  */
 void PolicyUninstallJob::rescheduleExecution()
 {
-   AddOneTimeScheduledTask(_T("Policy.Uninstall"), time(NULL) + getNextJobExecutionTime(), serializeParameters(), 0, getRemoteNode(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
+   AddOneTimeScheduledTask(_T("Policy.Uninstall"), time(NULL) + getRetryDelay(), serializeParameters(), 0, getRemoteNode(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
 }
index 90618a7..85f1e24 100644 (file)
@@ -60,7 +60,7 @@ FileDownloadJob::FileDownloadJob(Node *node, const TCHAR *remoteFile, UINT32 max
 /**
  * Returns localFileName
  */
-TCHAR* FileDownloadJob::getLocalFileName()
+const TCHAR *FileDownloadJob::getLocalFileName()
 {
    return m_localFile;
 }
index f891ba7..5599067 100644 (file)
@@ -387,30 +387,26 @@ bool EPRule::matchSeverity(UINT32 dwSeverity)
  */
 bool EPRule::matchScript(Event *pEvent)
 {
-   NXSL_Value **ppValueList, *pValue;
-   NXSL_VariableSystem *pLocals, *pGlobals = NULL;
    bool bRet = true;
-   UINT32 i;
-       NetObj *pObject;
 
    if (m_pScript == NULL)
       return true;
 
    // Pass event's parameters as arguments and
    // other information as variables
-   ppValueList = (NXSL_Value **)malloc(sizeof(NXSL_Value *) * pEvent->getParametersCount());
+   NXSL_Value **ppValueList = (NXSL_Value **)malloc(sizeof(NXSL_Value *) * pEvent->getParametersCount());
    memset(ppValueList, 0, sizeof(NXSL_Value *) * pEvent->getParametersCount());
-   for(i = 0; i < pEvent->getParametersCount(); i++)
+   for(int i = 0; i < pEvent->getParametersCount(); i++)
       ppValueList[i] = new NXSL_Value(pEvent->getParameter(i));
 
-   pLocals = new NXSL_VariableSystem;
+   NXSL_VariableSystem *pLocals = new NXSL_VariableSystem;
    pLocals->create(_T("EVENT_CODE"), new NXSL_Value(pEvent->getCode()));
    pLocals->create(_T("SEVERITY"), new NXSL_Value(pEvent->getSeverity()));
    pLocals->create(_T("SEVERITY_TEXT"), new NXSL_Value(GetStatusAsText(pEvent->getSeverity(), true)));
    pLocals->create(_T("OBJECT_ID"), new NXSL_Value(pEvent->getSourceId()));
    pLocals->create(_T("EVENT_TEXT"), new NXSL_Value((TCHAR *)pEvent->getMessage()));
    pLocals->create(_T("USER_TAG"), new NXSL_Value((TCHAR *)pEvent->getUserTag()));
-       pObject = FindObjectById(pEvent->getSourceId());
+       NetObj *pObject = FindObjectById(pEvent->getSourceId());
        if (pObject != NULL)
        {
                if (pObject->getObjectClass() == OBJECT_NODE)
@@ -420,17 +416,16 @@ bool EPRule::matchScript(Event *pEvent)
        m_pScript->setGlobalVariable(_T("CUSTOM_MESSAGE"), new NXSL_Value);
 
    // Run script
-   if (m_pScript->run(pEvent->getParametersCount(), ppValueList, pLocals, &pGlobals))
+   NXSL_VariableSystem *globals = NULL;
+   if (m_pScript->run(pEvent->getParametersCount(), ppValueList, pLocals, &globals))
    {
-      pValue = m_pScript->getResult();
-      if (pValue != NULL)
+      NXSL_Value *value = m_pScript->getResult();
+      if (value != NULL)
       {
-         bRet = pValue->getValueAsInt32() ? true : false;
+         bRet = value->getValueAsInt32() ? true : false;
          if (bRet)
          {
-               NXSL_Variable *var;
-
-               var = pGlobals->find(_T("CUSTOM_MESSAGE"));
+               NXSL_Variable *var = globals->find(_T("CUSTOM_MESSAGE"));
                if (var != NULL)
                {
                        // Update custom message in event
@@ -444,7 +439,7 @@ bool EPRule::matchScript(Event *pEvent)
       nxlog_write(MSG_EPRULE_SCRIPT_EXECUTION_ERROR, EVENTLOG_ERROR_TYPE, "ds", m_id + 1, m_pScript->getErrorText());
    }
    free(ppValueList);
-   delete pGlobals;
+   delete globals;
 
    return bRet;
 }
index 0e12438..52f68d6 100644 (file)
@@ -1226,7 +1226,6 @@ EventTemplate *FindEventTemplateByCode(UINT32 eventCode)
 EventTemplate *FindEventTemplateByName(const TCHAR *name)
 {
    EventTemplate *result = NULL;
-   UINT32 i;
 
    RWLockReadLock(m_rwlockTemplateAccess, INFINITE);
    Iterator<EventTemplate> *it = m_eventTemplates.iterator();
index e60c728..ca269e3 100644 (file)
@@ -396,13 +396,11 @@ void ServerJob::rescheduleExecution()
 {
 }
 
-
-
 /**
- * Returns next job execution interval in minutes
- * Each next execution time will be twce bigger than the previous one
+ * Returns delay before retry in seconds
+ * Each next interval will be twice as bigger as previous one
  */
-int ServerJob::getNextJobExecutionTime()
+int ServerJob::getRetryDelay()
 {
-   return pow(2.0f, (4 - m_retryCount)) * JOB_RESCHEDULE_OFSET;
+   return (int)(pow(2.0f, (4 - m_retryCount)) * JOB_RESCHEDULE_OFSET);
 }
index da62522..ae86f81 100644 (file)
@@ -661,16 +661,17 @@ TCHAR *LDAPConnection::getIdAttrValue(LDAPMessage *entry, const char *attr)
    BYTE tmp[1024];
    memset(tmp, 0, 1024);
    berval **values = ldap_get_values_lenA(m_ldapConn, entry, (char *)attr);   // cast needed for Windows LDAP library
+   int count = (int)ldap_count_values_len(values);
    int i,pos;
-   for(i = 0, pos = 0; i < ldap_count_values_len(values); i++)
+   for(i = 0, pos = 0; i < count; i++)
    {
-      if(pos+values[i]->bv_len > 1024)
+      if (pos + values[i]->bv_len > 1024)
          break;
       memcpy(tmp+pos,values[i]->bv_val,values[i]->bv_len);
       pos += values[i]->bv_len;
    }
    ldap_value_free_len(values);
-   if(i == 0)
+   if (i == 0)
       return _tcsdup(_T(""));
 
    CalculateSHA256Hash(tmp, pos, hash);
index 8733c54..f6e15c8 100644 (file)
                                RelativePath=".\ap_jobs.cpp"
                                >
                        </File>
+                       <File
+                               RelativePath=".\ap_logparser.cpp"
+                               >
+                       </File>
                        <File
                                RelativePath=".\audit.cpp"
                                >
                                RelativePath=".\maint.cpp"
                                >
                        </File>
+                       <File
+                               RelativePath=".\market.cpp"
+                               >
+                       </File>
                        <File
                                RelativePath=".\mdconn.cpp"
                                >
index d211d36..5ecd0c8 100644 (file)
@@ -191,7 +191,7 @@ ServerJobResult FileUploadJob::run()
    if(success == JOB_RESULT_FAILED && m_retryCount-- > 0)
    {
       TCHAR description[256];
-      _sntprintf(description, 256, _T("File upload failed. Wainting %d minutes to restart job."), getNextJobExecutionTime()/60);
+      _sntprintf(description, 256, _T("File upload failed. Wainting %d minutes to restart job."), getRetryDelay() / 60);
       setDescription(description);
       success = JOB_RESULT_RESCHEDULE;
    }
@@ -233,10 +233,9 @@ const String FileUploadJob::serializeParameters()
 }
 
 /**
- * Schedules execution in 10 minutes
+ * Schedules repeated execution
  */
 void FileUploadJob::rescheduleExecution()
 {
-   AddOneTimeScheduledTask(_T("Policy.Uninstall"), time(NULL) + getNextJobExecutionTime(), serializeParameters(), 0, getRemoteNode(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
+   AddOneTimeScheduledTask(_T("Policy.Uninstall"), time(NULL) + getRetryDelay(), serializeParameters(), 0, getRemoteNode(), SYSTEM_ACCESS_FULL, SCHEDULED_TASK_SYSTEM);//TODO: change to correct user
 }
-
index 8777f7e..1ea8c49 100644 (file)
@@ -263,8 +263,6 @@ BOOL LoadUsers()
  */
 void SaveUsers(DB_HANDLE hdb)
 {
-   int i;
-
    // Save users
    RWLockWriteLock(s_userDatabaseLock, INFINITE);
    Iterator<UserDatabaseObject> *it = s_userDatabase.iterator();
@@ -299,7 +297,6 @@ UINT32 AuthenticateUser(const TCHAR *login, const TCHAR *password, UINT32 dwSigL
                         BYTE *pChallenge, UINT32 *pdwId, UINT64 *pdwSystemRights,
                                                           bool *pbChangePasswd, bool *pbIntruderLockout, bool *closeOtherSessions, bool ssoAuth)
 {
-   int i, j;
    UINT32 dwResult = RCC_ACCESS_DENIED;
    BOOL bPasswordValid = FALSE;
 
@@ -949,8 +946,6 @@ void DumpUsers(CONSOLE_CTX pCtx)
  */
 UINT32 NXCORE_EXPORTABLE DeleteUserDatabaseObject(UINT32 id, bool alreadyLocked)
 {
-   int i, j;
-
    DeleteUserFromAllObjects(id);
 
    if (!alreadyLocked)
@@ -1022,10 +1017,9 @@ UINT32 NXCORE_EXPORTABLE CreateNewUser(const TCHAR *name, bool isGroup, UINT32 *
  */
 UINT32 NXCORE_EXPORTABLE ModifyUserDatabaseObject(NXCPMessage *msg)
 {
-   UINT32 id, fields, dwResult = RCC_INVALID_USER_ID;
-       int i;
+   UINT32 dwResult = RCC_INVALID_USER_ID;
 
-       id = msg->getFieldAsUInt32(VID_USER_ID);
+       UINT32 id = msg->getFieldAsUInt32(VID_USER_ID);
 
    RWLockWriteLock(s_userDatabaseLock, INFINITE);
 
@@ -1034,7 +1028,7 @@ UINT32 NXCORE_EXPORTABLE ModifyUserDatabaseObject(NXCPMessage *msg)
    {
       TCHAR name[MAX_USER_NAME];
 
-      fields = msg->getFieldAsUInt32(VID_FIELDS);
+      UINT32 fields = msg->getFieldAsUInt32(VID_FIELDS);
       if (fields & USER_MODIFY_LOGIN_NAME)
       {
          msg->getFieldAsString(VID_USER_NAME, name, MAX_USER_NAME);
index 1931b77..7a73f0f 100644 (file)
@@ -92,14 +92,16 @@ protected:
        virtual ServerJobResult run();
        virtual bool onCancel();
        virtual const TCHAR *getAdditionalInfo();
+       virtual const String serializeParameters();
 
        void notifyClients(bool isStatusChange);
        void changeStatus(ServerJobStatus newStatus);
        void markProgress(int pctCompleted);
        void setFailureMessage(const TCHAR *msg);
-
        void setDescription(const TCHAR *description);
 
+       int getRetryDelay();
+
 public:
        ServerJob(const TCHAR *type, const TCHAR *description, UINT32 node, UINT32 userId, bool createOnHold, int retryCount = -1);
        ServerJob(const TCHAR* params, UINT32 node, UINT32 userId);
@@ -131,9 +133,8 @@ public:
        void setOwningQueue(ServerJobQueue *queue);
 
        void fillMessage(NXCPMessage *msg);
-       virtual const String serializeParameters();
+
        virtual void rescheduleExecution();
-       int getNextJobExecutionTime();
 };
 
 /**
@@ -193,7 +194,9 @@ protected:
 
        virtual ServerJobResult run();
        virtual const TCHAR *getAdditionalInfo();
-       static void uploadCallback(INT64 size, void *arg);
+       virtual const String serializeParameters();
+
+   static void uploadCallback(INT64 size, void *arg);
 
 public:
        static void init();
@@ -202,7 +205,6 @@ public:
        FileUploadJob(TCHAR* params, UINT32 node, UINT32 userId);
        virtual ~FileUploadJob();
 
-       virtual const String serializeParameters();
        virtual void rescheduleExecution();
        void setLocalFileFullPath();
 };
@@ -232,20 +234,20 @@ protected:
 
        static void progressCallback(size_t size, void *arg);
        static void fileResendCallback(NXCP_MESSAGE *msg, void *arg);
+       static TCHAR *buildServerFileName(UINT32 nodeId, const TCHAR *remoteFile, TCHAR *buffer, size_t bufferSize);
 
 public:
        FileDownloadJob(Node *node, const TCHAR *remoteName, UINT32 maxFileSize, bool follow, ClientSession *session, UINT32 requestId);
        virtual ~FileDownloadJob();
 
-       static TCHAR *buildServerFileName(UINT32 nodeId, const TCHAR *remoteFile, TCHAR *buffer, size_t bufferSize);
-       TCHAR *getLocalFileName();
+       const TCHAR *getLocalFileName();
 };
 
+class AgentPolicy;
+
 /**
  * Agent policy deployment job
  */
-class AgentPolicy;
-
 class PolicyDeploymentJob : public ServerJob
 {
 protected:
@@ -253,17 +255,16 @@ protected:
        AgentPolicy *m_policy;
 
        virtual ServerJobResult run();
+       virtual const String serializeParameters();
 
 public:
        PolicyDeploymentJob(Node *node, AgentPolicy *policy, UINT32 userId);
    PolicyDeploymentJob(const TCHAR* params, UINT32 node, UINT32 userId);
        virtual ~PolicyDeploymentJob();
 
-       virtual const String serializeParameters();
        virtual void rescheduleExecution();
 };
 
-
 /**
  * Agent policy uninstall job
  */
@@ -274,13 +275,13 @@ protected:
        AgentPolicy *m_policy;
 
        virtual ServerJobResult run();
+       virtual const String serializeParameters();
 
 public:
        PolicyUninstallJob(Node *node, AgentPolicy *policy, UINT32 userId);
    PolicyUninstallJob(const TCHAR* params, UINT32 node, UINT32 userId);
        virtual ~PolicyUninstallJob();
 
-       virtual const String serializeParameters();
        virtual void rescheduleExecution();
 };
 
index 82332b6..14755ba 100644 (file)
@@ -200,8 +200,7 @@ static void CheckZones()
 {
    DB_RESULT hResult, hResult2;
    DWORD i, dwNumObjects, dwId;
-   TCHAR szQuery[1024], szName[MAX_OBJECT_NAME];
-   BOOL bIsDeleted;
+   TCHAR szQuery[1024];
 
    StartStage(_T("Checking zone objects..."));
    hResult = SQLSelect(_T("SELECT id FROM zones"));
index b1497b0..dc9fd0c 100644 (file)
@@ -212,7 +212,7 @@ retry_wait:
                }
                else  // message ID do not match
                {
-                  INT32 elapsedTime = (INT32)(GetCurrentTimeMs() - startTime);
+                  UINT32 elapsedTime = (UINT32)(GetCurrentTimeMs() - startTime);
                   if (elapsedTime < remainingWaitTime)
                   {
                      remainingWaitTime -= elapsedTime;
@@ -226,7 +226,7 @@ retry_wait:
                if ((*response)->getRequestId() == request->getRequestId())
                   break;
 
-               INT32 elapsedTime = (INT32)(GetCurrentTimeMs() - startTime);
+               UINT32 elapsedTime = (UINT32)(GetCurrentTimeMs() - startTime);
                if (elapsedTime < remainingWaitTime)
                {
                   remainingWaitTime -= elapsedTime;
index 39e093f..2a311b5 100644 (file)
@@ -322,7 +322,7 @@ TCHAR *SNMP_Variable::getValueAsPrintableString(TCHAR *buffer, size_t bufferSize
          if (!conversionNeeded)
          {
 #ifdef UNICODE
-            if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (char *)m_value, (int)length, buffer, (int)bufferSize) < length)
+            if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (char *)m_value, (int)length, buffer, (int)bufferSize) < (int)length)
             {
                if (convertToHexAllowed)
                {
index c31e2d0..1e37242 100644 (file)
@@ -50,7 +50,7 @@
                                RuntimeLibrary="3"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
-                               Detect64BitPortabilityProblems="true"
+                               Detect64BitPortabilityProblems="false"
                                DebugInformationFormat="4"
                        />
                        <Tool
                                RuntimeLibrary="2"
                                UsePrecompiledHeader="0"
                                WarningLevel="3"
-                               Detect64BitPortabilityProblems="true"
+                               Detect64BitPortabilityProblems="false"
                                DebugInformationFormat="3"
                        />
                        <Tool