NS_IMETHODIMP
nsControllerCommandTable::GetCommandState(const char *aCommandName, nsICommandParams *aParams, nsISupports *aCommandRefCon)
{
  // find the command
  nsCOMPtr<nsIControllerCommand> commandHandler;
  FindCommandHandler(aCommandName, getter_AddRefs(commandHandler));
  if (!commandHandler)
  {
#if DEBUG
    NS_WARNING("Controller command table asked to do a command that it does not handle -- ");
#endif
    return NS_OK;    // we don't handle this command
  }
  return commandHandler->GetCommandStateParams(aCommandName, aParams, aCommandRefCon);
}
NS_IMETHODIMP
nsControllerCommandTable::UpdateCommandState(const char * aCommandName, nsISupports *aCommandRefCon)
{
  // find the command
  nsCOMPtr<nsIControllerCommand> commandHandler;
  FindCommandHandler(aCommandName, getter_AddRefs(commandHandler));
  if (!commandHandler)
  {
#if DEBUG
    NS_WARNING("Controller command table asked to update the state of a command that it does not handle -- ");
#endif
    return NS_OK;    // we don't handle this command
  }

  return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsControllerCommandTable::SupportsCommand(const char * aCommandName, nsISupports *aCommandRefCon, bool *aResult)
{
  NS_ENSURE_ARG_POINTER(aResult);

  // XXX: need to check the readonly and disabled states

  *aResult = false;

  // find the command
  nsCOMPtr<nsIControllerCommand> commandHandler;
  FindCommandHandler(aCommandName, getter_AddRefs(commandHandler));

  *aResult = (commandHandler.get() != nullptr);
  return NS_OK;
}
/* boolean isCommandEnabled (in wstring command); */
NS_IMETHODIMP
nsControllerCommandTable::IsCommandEnabled(const char * aCommandName, nsISupports *aCommandRefCon, bool *aResult)
{
  NS_ENSURE_ARG_POINTER(aResult);

  *aResult = false;

  // find the command
  nsCOMPtr<nsIControllerCommand> commandHandler;
  FindCommandHandler(aCommandName, getter_AddRefs(commandHandler));
  if (!commandHandler)
  {
#if DEBUG
    NS_WARNING("Controller command table asked about a command that it does not handle -- ");
#endif
    return NS_OK;    // we don't handle this command
  }

  return commandHandler->IsCommandEnabled(aCommandName, aCommandRefCon, aResult);
}
Exemplo n.º 5
0
BOOL CCLITerminal::CommandTask(CLISESSION *pSession, BOOL bComplete, BOOL bAddHistory)
{
	CLIHANDLER	*pHandler;
	char		szCommand[256] = "";
	int			nResult, nDepts=0, nCommand;
	int			i, nIndex, argc, nParam, nPos;

	// Make New Line
	WriteStream(pSession, "\n\r");
	pSession->szCommand[pSession->nCmdLength] = '\0';

	if (pSession->nMode == CLIMODE_USER)
	{
		nCommand = atoi(pSession->szCommand);
		pSession->nCmdLength = 0;
		pSession->szCommand[0] = '\0';
		
		switch(nCommand) {
		  case 1 :
			   FirmwareDownload(pSession);
			   WriteStream(pSession, "\n\r");
			   break;
		  case 2 : 
			   pSession->nMode = CLIMODE_COMMAND;
			   DisplayPrompt(pSession);
			   return TRUE; 
		}
		DisplaySplash(pSession);
		return TRUE;
	}

	// Check Login State
	if (!pSession->bLogined)
	{
		if (pSession->bNeedUser)
		{
			if (!CheckUser(pSession))
			{
				// Display Login Error Message
				WriteStream(pSession, "Invalid User.\r\n");
			}

			// Clear Command Buffer
			pSession->nCmdLength 	= 0;
			pSession->szCommand[0]	= '\0';
			DisplayPrompt(pSession);
			return TRUE;

		}
		else if (!CheckLogin(pSession))
		{
			// Clear Command Buffer
			pSession->nCmdLength 	= 0;
			pSession->szCommand[0]	= '\0';
			pSession->bNeedUser		= TRUE;

			// Display Login Error Message
			WriteStream(pSession, "Invalid account or password.\r\n\r\n");
			strcpy(pSession->szPrompt, m_pCLIService->m_szUserPrompt);
			pSession->nLoginRetry++;
			if (pSession->nLoginRetry >= 3)
			{
				if (pSession->nType == CLITYPE_SERIAL)
					sleep(3);
				return FALSE;
			}

			DisplayPrompt(pSession);
			return TRUE;
		}

		// Clear Command Buffer
		pSession->nCmdLength 	= 0;
		pSession->szCommand[0]	= '\0';

		// Callback Login
		if (m_pCLIService->m_pConstruct &&
			m_pCLIService->m_pConstruct->pfnOnLogin)
			m_pCLIService->m_pConstruct->pfnOnLogin(pSession);

		// Login Complete
		pSession->bLogined = TRUE;
		WriteStream(pSession, "\n\r");
		strcpy(pSession->szPrompt, m_pCLIService->m_szDefaultPrompt);
		DisplayPrompt(pSession);
		return TRUE;
	}

	if (pSession->nCmdLength > 0)
	{
		// Find Command
		nResult = CLIERR_OK;
		pSession->szCommand[pSession->nCmdLength] = '\0';

		if (pSession->szCommand[0] == '!')
		{
			if (strcmp(pSession->szCommand, "!!") == 0)
			{
				strcpy(pSession->szCommand, pSession->pszHistory[pSession->nHistoryCount-1]);
				pSession->nCmdLength = strlen(pSession->szCommand);
			}
			else
			{
				nIndex = atoi(&pSession->szCommand[1]);
				if ((nIndex > 0) && (nIndex <= pSession->nHistoryCount))
				{
					strcpy(pSession->szCommand, pSession->pszHistory[nIndex-1]);
					pSession->nCmdLength = strlen(pSession->szCommand);
				}
			}
		}

		pSession->pszArgString = strdup(pSession->szCommand);
		if (bAddHistory)
			AddHistory(pSession, pSession->szCommand);

		SpliteParameter(pSession);
		pHandler = FindCommandHandler(pSession, nDepts, szCommand);
		if (pHandler != NULL)
		{
			// Execute Command
			nParam = GetParamCount(pHandler);
			argc = pSession->argc - (nDepts + 1);
			for(i=0; i<argc; i++)
				pSession->argv[i] = pSession->argv[nDepts+i+1];

			// 파라메터의 갯수가 더 많은 경우를 막을때, add apn 명령 때문에 허용하도록 변경 2007/9/5
			// if ((nParam == argc) || (pHandler->pszParam && (argc >= GetMinParamCount(pHandler)) && (argc <= nParam)))

			if ((nParam == argc) || (pHandler->pszParam && (argc >= GetMinParamCount(pHandler))))
			{
				nPos = ValidateParameter(pSession, pHandler);
				if (nPos == -1)
				{
					pSession->nCmdLength 	= 0;
					pSession->szCommand[0]	= '\0';

					if (m_pCLIService->m_pConstruct &&
						m_pCLIService->m_pConstruct->pfnOnCommand)
						m_pCLIService->m_pConstruct->pfnOnCommand(pSession, argc, pSession->argv, pHandler);

					if (pHandler->nGroup >= pSession->nGroup)
					{
						if (m_pCLIService->m_bEnableLog && pHandler->bLogFlag)
							m_pCLIService->AddLog(pSession->szUser, pSession->szCommand);

						nResult = pHandler->pfnCommand(pSession, argc, pSession->argv, (void *)pHandler);
						WriteStream(pSession, "\xd\xa");
					}
					else
					{
						WriteStream(pSession, "Permission Denied.");					
						WriteStream(pSession, "\xd\xa");
					}
				}
				else
				{
					WriteStream(pSession, "Invalid parameter : '");					
					WriteStream(pSession, pSession->argv[nPos]);					
					WriteStream(pSession, "'\xd\xa");
					WriteStream(pSession, "\xd\xa");
				}
			}
			else
			{
				WriteStream(pSession, "usage: ");
				WriteStream(pSession, szCommand);
				DisplayWideParameter(pSession, pHandler);
				DisplayAllParameter(pSession, pHandler);
				WriteStream(pSession, "\xd\xa");
			}
		}

		if (pSession->pszArgString)
			FREE(pSession->pszArgString);
		pSession->pszArgString = NULL;

		if (nResult == CLIERR_ERROR)
			return FALSE;
	}

	// Clear Command Buffer
	pSession->nCmdLength 	= 0;
	pSession->szCommand[0]	= '\0';

	// Display Prompt
	DisplayPrompt(pSession);
	return TRUE;
}