Ejemplo n.º 1
0
static void KVMGetConnectParams(kvm_vnc_server_start_params * pVNCStartServerParams)
{
	if(!IsKVMGetConnectParamsThreadRunning)
	{
		if(!g_pkvmVNCServerStartParms)
			g_pkvmVNCServerStartParms = malloc(sizeof(kvm_vnc_server_start_params));
		memset(g_pkvmVNCServerStartParms, 0, sizeof(kvm_vnc_server_start_params));
		memcpy(g_pkvmVNCServerStartParms, pVNCStartServerParams,  sizeof(kvm_vnc_server_start_params));

		KillX11Vnc();

		/*if(X11vncPid > 0)
		{
			int wPid = 0;
			kill(X11vncPid, SIGKILL);
			wPid = waitpid(X11vncPid,NULL, WNOHANG);
			//if(wPid == X11vncPid) X11vncPid = 0;
			X11vncPid = 0;
		}*/
		IsKVMGetConnectParamsThreadRunning = TRUE;
		if (app_os_thread_create(&KVMGetConnectParamsThreadHandle, KVMGetConnectParamsThreadStart, g_pkvmVNCServerStartParms) != 0)
		{
			printf("KVMGetConnectParamsThreadStart failed!\n");
			IsKVMGetConnectParamsThreadRunning = FALSE;
		}
		else
		{
			printf("KVMGetConnectParamsThreadStart ok!\n");
		}
	}
}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------
// Global functions define:
//-----------------------------------------------------------------------------
void ProtectAction()
{
	handler_context_t *pProtectHandlerContext = (handler_context_t *)&g_HandlerContex;
	if(IsExpired())
	{
#ifndef _WIN32
		//DeleteLicense();
#endif
		SendReplyMsg_Prtt("Expired", prtt_expire, prtt_protect_rep);	
	}
	else
	{
		if(app_os_is_file_exist(InstallPath))
		{
			if(!pProtectHandlerContext->isProtectActionRunning)
			{
				CAGENT_THREAD_HANDLE protectActionThreadHandle;
				pProtectHandlerContext->isProtectActionRunning = TRUE;
				if (app_os_thread_create(&protectActionThreadHandle, ProtectActionThreadStart, pProtectHandlerContext) != 0)
				{
					ProtectLog(g_loghandle, Warning, " %s> Start protect action thread failed!", strPluginName);
					pProtectHandlerContext->isProtectActionRunning = FALSE;
				}
			}
			else
			{
				SendReplyMsg_Prtt("ProtectActionRunning", prtt_busy, prtt_protect_rep);			
			}
		}
	}
}
Ejemplo n.º 3
0
int FtpDownload(HFTPDL hFtpDl, char * remoteUrl, char * localFile)
{
	CURLcode rc = CURLE_OK;
	if(hFtpDl == NULL || localFile == NULL || remoteUrl == NULL) return -1;
	{
		PFTPDLCONTEXT pFTPDLContext = (PFTPDLCONTEXT)hFtpDl;
		CURL *curl = (CURL *)pFTPDLContext->hCurl;
		int tmpLen = 0;
		if(curl == NULL) return -1;
		tmpLen = strlen(remoteUrl) + 1;
		pFTPDLContext->remoteUrl = (char *)malloc(tmpLen);
		memset(pFTPDLContext->remoteUrl, 0, tmpLen);
		strcpy(pFTPDLContext->remoteUrl, remoteUrl);
		tmpLen = strlen(localFile) + 1;
		pFTPDLContext->localFile = (char *)malloc(tmpLen);
		memset(pFTPDLContext->localFile, 0, tmpLen);
		strcpy(pFTPDLContext->localFile, localFile);
		{
			struct FtpFile ftpfile = {pFTPDLContext->localFile, NULL};
			curl_easy_setopt(curl, CURLOPT_URL, pFTPDLContext->remoteUrl);
			curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, FtpDwlWriteCallback);
			curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
			//curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
			pFTPDLContext->dlInfoGetThreadRunning = 1;

			app_os_thread_create(&pFTPDLContext->dlInfoGetThreadHanle , FtpDLInfoGetThreadStart, pFTPDLContext);

			if(!pFTPDLContext->dlInfoGetThreadHanle)
			{
				pFTPDLContext->dlInfoGetThreadRunning = 0;
			}
			pFTPDLContext->dlStatus = FTP_DSC_START;
			rc= curl_easy_perform(curl);
			if(rc != CURLE_OK && !(rc == CURLE_OPERATION_TIMEDOUT && pFTPDLContext->dlPersent == 100))
			{
				char * tmpStr = NULL;
				pFTPDLContext->dlStatus = FTP_DSC_ERROR;
				tmpStr = (char *)curl_easy_strerror(rc);
				if(tmpStr && strlen(tmpStr))
				{
					memset(pFTPDLContext->dlLastError, 0, sizeof(pFTPDLContext->dlLastError));
					strcpy(pFTPDLContext->dlLastError, tmpStr);
				}
			}
			else
			{
				rc = CURLE_OK;
			}
			if(ftpfile.stream) fclose(ftpfile.stream); 
		}
	}
	return rc;
}
Ejemplo n.º 4
0
/* **************************************************************************************
 *  Function Name: Handler_Start
 *  Description: Start Running
 *  Input :  None
 *  Output: None
 *  Return:  0  : Success Init Handler
 *              -1 : Fail Init Handler
 * ***************************************************************************************/
int HANDLER_API Handler_Start( void )
{
	printf("> %s Handler_Start\r\n", strPluginName);
	
	if (app_os_thread_create(&g_HandlerContex.threadHandler, SampleHandlerThreadStart, &g_HandlerContex) != 0)
	{
		g_HandlerContex.isThreadRunning = false;
		printf("> start handler thread failed!\r\n");	
		return handler_fail;
    }
	g_HandlerContex.isThreadRunning = true;
	g_status = handler_status_start;
	time(&g_monitortime);
	return handler_success;
}
Ejemplo n.º 5
0
static void KVMGetConnectParams(kvm_vnc_server_start_params * pVNCStartServerParams)
{
	if(!IsKVMGetConnectParamsThreadRunning)
	{
		IsKVMGetConnectParamsThreadRunning = TRUE;
		if(!g_pkvmVNCServerStartParms)
			g_pkvmVNCServerStartParms = malloc(sizeof(kvm_vnc_server_start_params));
		memset(g_pkvmVNCServerStartParms, 0, sizeof(kvm_vnc_server_start_params));
		memcpy(g_pkvmVNCServerStartParms, pVNCStartServerParams,  sizeof(kvm_vnc_server_start_params));

		if (app_os_thread_create(&KVMGetConnectParamsThreadHandle, KVMGetConnectParamsThreadStart, g_pkvmVNCServerStartParms) != 0)
		{
			IsKVMGetConnectParamsThreadRunning = FALSE;
		}
	}
}
Ejemplo n.º 6
0
void CreateASZ(char * aszParams)
{
	recovery_handler_context_t *pRecoveryHandlerContext = (recovery_handler_context_t *)&RecoveryHandlerContext;
	char createASZMsg[BUFSIZ] = {0};
	char aszParamsStr[BUFSIZ] = {0};
	char * word[16] = {NULL};
	if(NULL == aszParams) return;
	strcpy(aszParamsStr, aszParams);
	if(strstr(aszParamsStr, ","))
	{
		char *buf = aszParamsStr;
		int i = 0, j = 0;
		while((word[i] = strtok( buf, ",")) != NULL)
		{
			i++;
			buf=NULL;
		}
		for(j = 0; j <= i; j++)
		{
			TrimStr(word[i]);
		}
	}
	if(!pRecoveryHandlerContext->isCreateASZRunning)
	{
		pRecoveryHandlerContext->isCreateASZRunning = TRUE;
		if (app_os_thread_create(&pRecoveryHandlerContext->acrCreateASZThreadHandle, CreateASZThreadStart, word) != 0)
		{
			RecoveryLog(g_loghandle, Normal, "%s()[%d]###Start create ASZ thread failed!\n",__FUNCTION__, __LINE__ );
			sprintf(createASZMsg, "%s,%s",  "ASZInfo", "Create ASZ thread failed!");			
			SendReplyMsg_Rcvy(createASZMsg, asz_threadFail, rcvy_create_asz_rep);
			pRecoveryHandlerContext->isCreateASZRunning = FALSE;
		}
		else
		{
			sprintf(createASZMsg, "%s,%s",  "ASZInfo", "Creating ASZ...");
			SendReplyMsg_Rcvy(createASZMsg, asz_creating, rcvy_create_asz_rep);
		}
	}
}
Ejemplo n.º 7
0
//-----------------------------------------------------------------------------
// Global functions define:
//-----------------------------------------------------------------------------
void DoBackup()
{
    recovery_handler_context_t * pRecoveryHandlerContext = (recovery_handler_context_t *)&RecoveryHandlerContext;
    char backupMsg[512] = { 0 };
    char aszExitStatus[16] = { 0 };
    BOOL isReady = FALSE;
    IsBackuping = FALSE;

#ifndef _is_linux
    CheckASZStatus();
    GetASZExistRecord(aszExitStatus);
    if(!_stricmp(aszExitStatus, "True"))
        isReady = TRUE;
#else
    LONGLONG backupNeedSpace = GetBackupNeedSpace();
    if(app_os_is_file_exist(backupFolder) && \
            (backupNeedSpace != -1) && \
            (GetFolderAvailSpace(backupFolder) > backupNeedSpace))
        isReady = TRUE;
#endif /* _is_linux */

    if (isReady)
    {
        if (!pRecoveryHandlerContext->isAcrBackupRunning)
        {
            pRecoveryHandlerContext->isAcrBackupRunning = TRUE;
            if (app_os_thread_create(&pRecoveryHandlerContext->acrBackupThreadHandle, AcrBackupThreadStart, pRecoveryHandlerContext) != 0)
            {
                RecoveryLog(g_loghandle, Normal, "%s()[%d]###Start recovery backup thread failed!\n", __FUNCTION__, __LINE__);
                pRecoveryHandlerContext->isAcrBackupRunning = FALSE;
            }
            else
            {
                IsBackuping = TRUE;
            }
        }
        else
        {
            char * str = "AcrBackupRunning";
            SendReplyMsg_Rcvy(str, bkp_busy, rcvy_backup_rep);
        }
    }
#ifndef _is_linux
    else
    {
        LONGLONG minSizeMB = 0, maxSizeMB = 0;
        app_os_GetMinAndMaxSpaceMB(&minSizeMB, &maxSizeMB);
        if(maxSizeMB >= minSizeMB)
        {
            sprintf(backupMsg, "ASZ not exist! ASZSize: %lld,%lld", minSizeMB, maxSizeMB);
            SendReplyMsg_Rcvy(backupMsg, bkp_noASZ, rcvy_backup_rep);
        }
        else
        {
            sprintf(backupMsg, "%s", "ASZSizeNotEnough");
            SendReplyMsg_Rcvy(backupMsg, bkp_sizeLack, rcvy_backup_rep);
        }
    }
#else
    else
    {
        if (app_os_is_file_exist(backupFolder))
Ejemplo n.º 8
0
void SAMANAGER_API SAManager_Initialize(susiaccess_agent_conf_body_t * config, susiaccess_agent_profile_body_t * profile, void * loghandle)
{
	char workdir[MAX_PATH] = {0};
	Handler_Loader_Interface GlobalPlugin;
	g_samanagerlogger = loghandle;
	
	memset(&g_statethreadctx, 0, sizeof(struct state_ctx));
	g_statethreadctx.msgqueue = malloc(sizeof( struct statequeue));
	if(g_statethreadctx.msgqueue)
	{	
		if(!queue_init(g_statethreadctx.msgqueue, 1000))
		{
			free(g_statethreadctx.msgqueue);
			g_statethreadctx.msgqueue = NULL;
		}
		g_statethreadctx.isThreadRunning = true;
		if (app_os_thread_create(&g_statethreadctx.threadHandler, StateQueueThread, &g_statethreadctx) != 0)
		{
			g_statethreadctx.isThreadRunning = false;
			queue_uninit(g_statethreadctx.msgqueue);
			free(g_statethreadctx.msgqueue);
			g_statethreadctx.msgqueue = NULL;
		}
	}

	if(strlen(profile->workdir)>0)
		strcpy(workdir, profile->workdir);
	else
		app_os_get_module_path(workdir);

	memset(&g_handlerList, 0, sizeof(Handler_List_t));
	/*Load Handler Loader*/	
	if(dl_IsExistSALoaderLib(profile->workdir))
	{
		g_SALoader = malloc(sizeof(SALoader_Interface));
		memset(g_SALoader, 0, sizeof(SALoader_Interface));
		if(dl_LoadSALoaderLib(profile->workdir, g_SALoader))
		{
			printf("HandlerLoader loaded\r\n");
			if(g_SALoader->Loader_Initialize_API)
				g_SALoader->Loader_Initialize_API(workdir, config, profile, loghandle);
			if(g_SALoader->Loader_SetFuncCB_API)
			{
				Callback_Functions_t functions;
				memset(&functions, 0, sizeof(Callback_Functions_t));
				functions.sendcbf = SAManager_SendMessage;
				functions.sendcustcbf = SAManager_SendCustMessage;
				functions.subscribecustcbf = SAManager_SubscribeCustTopic;
				functions.sendreportcbf = SAManager_SendAutoReport;
				functions.sendcapabilitycbf = SAManager_SendCapability;
				functions.sendevnetcbf = SAManager_SendEventNotify;
				functions.connectservercbf = SAManager_ConnectServer;
				functions.disconnectcbf = SAManager_Disconnect;
				g_SALoader->Loader_SetFuncCB_API(&functions);
			}
			//if(g_SALoader->Loader_SetSendCB_API)
			//	g_SALoader->Loader_SetSendCB_API(SAManager_SendMessage);
			//if(g_SALoader->Loader_SetCustSendCB_API)
			//	g_SALoader->Loader_SetCustSendCB_API(SAManager_SendCustMessage);
			//if(g_SALoader->Loader_SetAutoReportCB_API)
			//	g_SALoader->Loader_SetAutoReportCB_API(SAManager_SendAutoReport);
			//if(g_SALoader->Loader_SetCustSubscribeCB_API)
			//	g_SALoader->Loader_SetCustSubscribeCB_API(SAManager_SubscribeCustTopic);
		}
		else
		{
			char *err = dl_GetLoadError();
			SAManagerLog(g_samanagerlogger, Warning, "Load HandlerLoader failed!\r\n  %s!!", err);
			free(err);
		}
	}
	else
	{
		char *err = dl_GetLoadError();
		SAManagerLog(g_samanagerlogger, Warning, "Cannot find HandlerLoader!\r\n  %s!!", err);
		free(err);
	}

	memset(&GlobalPlugin, 0, sizeof(Handler_Loader_Interface));
	if(dl_IsExistSAGeneralLib(profile->workdir))
	{
		g_SAGeneral = malloc(sizeof(SAGeneral_Interface));
		memset(g_SAGeneral, 0, sizeof(SAGeneral_Interface));
		if(dl_LoadSAGeneralLib(profile->workdir, g_SAGeneral))
		{
			
			printf("GeneralHandler loaded\r\n");
			if(g_SALoader)
			{
				if(g_SALoader->Loader_GetBasicHandlerLoaderInterface_API)
					g_SALoader->Loader_GetBasicHandlerLoaderInterface_API(&GlobalPlugin);
			}
			strcpy(GlobalPlugin.Name, "general");
			strncpy(GlobalPlugin.pHandlerInfo->ServerIP,  config->serverIP, strlen(config->serverIP)+1);
			GlobalPlugin.pHandlerInfo->ServerPort = atol(config->serverPort);
			GlobalPlugin.type = core_handler;
			if(g_SAGeneral->General_Initialize_API)
			{
				GlobalPlugin.Handler_Init_API = (HANDLER_INITLIZE)g_SAGeneral->General_Initialize_API;
				g_SAGeneral->General_Initialize_API(GlobalPlugin.pHandlerInfo);
			}

			if(g_SAGeneral->General_HandleRecv_API)
				GlobalPlugin.Handler_Recv_API = (HANDLER_RECV)g_SAGeneral->General_HandleRecv_API;

			if(g_SAGeneral->General_Start_API)
				GlobalPlugin.Handler_Start_API = (HANDLER_START)g_SAGeneral->General_Start_API;

			if(g_SAGeneral->General_Stop_API)
				GlobalPlugin.Handler_Stop_API = (HANDLER_STOP)g_SAGeneral->General_Stop_API;

			if(g_SAGeneral->General_OnStatusChanges_API)
				GlobalPlugin.Handler_OnStatusChange_API = (HANDLER_ONSTATUSCAHNGE)g_SAGeneral->General_OnStatusChanges_API;


			GlobalPlugin.Workable = true;
		}
		else
		{
			char *err = dl_GetLoadError();
			SAManagerLog(g_samanagerlogger, Warning, "Load GeneralHandler failed!\r\n  %s!!", err);
			free(err);
		}
	}
	else
	{
		char *err = dl_GetLoadError();
		SAManagerLog(g_samanagerlogger, Warning, "Cannot find GeneralHandler!\r\n  %s!!", err);
		free(err);
	}

	if(g_SALoader)
	{
		if(g_SAGeneral)
		{
			if(g_SAGeneral->General_SetPluginHandlers_API)
				g_SAGeneral->General_SetPluginHandlers_API(&g_handlerList);
			if(g_SALoader->Loader_AddHandler_API)
				g_SALoader->Loader_AddHandler_API(&g_handlerList, &GlobalPlugin);
		}
		g_SALoader->Loader_LoadAllHandler_API(&g_handlerList, workdir);
		g_SALoader->Loader_StartAllHandler_API(&g_handlerList);
//#ifdef WIN32
		keepalive_initialize(&g_handlerList, g_samanagerlogger);
//#endif
	}
}