示例#1
0
void hlloader_handler_recv(SALoader_Interface* pSALoader, Handler_List_t *pHandlerList, char* topic, susiaccess_packet_body_t *pkt, void *pRev1, void* pRev2)
{
	Handler_Loader_Interface* handler = NULL;
	char* pReqInfoPayload = NULL;
	
	if(!pSALoader)
		return;

	pReqInfoPayload = pkg_parser_packet_print(pkt);

	if(pSALoader->Loader_FindHandler_API)
	{
		/*Support V3.1 Version */
		handler = pSALoader->Loader_FindHandler_API(pHandlerList, pkt->handlerName);
	}
	if(handler != NULL)
	{
		if( handler->Handler_Recv_API )
			handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
	}

	/*Support V3.0 or Older Version */
	else{
		int reqID = pkt->requestID;
		if(pSALoader)
		{
			/*Support V3.0 Version */
			handler = pSALoader->Loader_FindHandlerByReqID_API(pHandlerList, reqID);
		}
		if(handler != NULL)
		{
			if( handler->Handler_Recv_API )
				handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
		}
		/*Support Older Version */
		else if(reqID == cagent_request_device_monitoring)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "device_monitoring");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "device_monitoring" );
			}
		}
		else if(reqID == cagent_request_power_onoff)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "power_onoff");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "power_onoff" );
			}
		}
		else if(reqID == cagent_request_remote_kvm)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "remote_kvm");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "remote_kvm" );
			}
		}
		else if(reqID == cagent_request_protection)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "protection");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "protection" );
			}
		}
		else if(reqID == cagent_request_recovery)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "recovery");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "recovery" );
			}
		}
		else if(reqID == cagent_request_software_monitoring)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "software_monitoring");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "software_monitoring" );
			}
		}
		else if(reqID == cagent_request_global)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "general");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "global" );
			}
		}
		else if(reqID == cagent_request_terminal)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "terminal");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "terminal" );
			}
		}
		else if(reqID == cagent_request_screenshot)
		{
			if(pSALoader)
			{
				handler = pSALoader->Loader_FindHandler_API(pHandlerList, "screenshot");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(pSALoader->LogHandle, Warning, "Cannot find handler: %s", "screenshot" );
			}
		}
	}
	free(pReqInfoPayload);
}
示例#2
0
void SAManager_RecvInternalCommandReq(char* topic, susiaccess_packet_body_t *pkt, void *pRev1, void* pRev2)
{
	Handler_Loader_Interface* handler = NULL;
	PJSON ReqInfoJSON = NULL;
	char* pReqInfoPayload = NULL;
	ReqInfoJSON = SAParser_CreateAgentPacketToJSON(pkt);
	pReqInfoPayload = SAParser_PrintUnformatted(ReqInfoJSON);
	SAParser_Free(ReqInfoJSON);

	if(g_SALoader)
	{
		/*Support V3.1 Version */
		handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, pkt->handlerName);
	}
	if(handler != NULL)
	{
		//SAManagerLog(g_samanagerlogger, Normal, "Handler find by name: %s", pkt->handlerName );
		if( handler->Handler_Recv_API )
			handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
	}
	/*Support V3.0 or Older Version */
	else{
		int reqID = pkt->requestID;
		if(g_SALoader)
		{
			/*Support V3.0 Version */
			handler = g_SALoader->Loader_FindHandlerByReqID_API(&g_handlerList, reqID);
		}
		if(handler != NULL)
		{
			//SAManagerLog(g_samanagerlogger, Normal, "Handler find by ID: %d", reqID );
			if( handler->Handler_Recv_API )
				handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
		}
		/*Support Older Version */
		else if(reqID == cagent_request_device_monitoring)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "device_monitoring");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "device_monitoring" );
			}
		}
		else if(reqID == cagent_request_power_onoff)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "power_onoff");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "power_onoff" );
			}
		}
		else if(reqID == cagent_request_remote_kvm)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "remote_kvm");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "remote_kvm" );
			}
		}
		else if(reqID == cagent_request_protection)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "protection");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "protection" );
			}
		}
		else if(reqID == cagent_request_recovery)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "recovery");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "recovery" );
			}
		}
		else if(reqID == cagent_request_software_monitoring)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "software_monitoring");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "software_monitoring" );
			}
		}
		else if(reqID == cagent_request_global)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "general");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "global" );
			}
		}
		else if(reqID == cagent_request_terminal)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "terminal");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "terminal" );
			}
		}
		else if(reqID == cagent_request_screenshot)
		{
			if(g_SALoader)
			{
				handler = g_SALoader->Loader_FindHandler_API(&g_handlerList, "screenshot");
			}
			if(handler != NULL)
			{
				if( handler->Handler_Recv_API )
					handler->Handler_Recv_API(topic, pReqInfoPayload, strlen(pReqInfoPayload), pRev1, pRev2);
			}
			else
			{
				SAManagerLog(g_samanagerlogger, Warning, "Cannot find handler: %s", "screenshot" );
			}
		}
	}
	free(pReqInfoPayload);
}