⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mpdconsole.cpp

📁 MPICH是MPI的重要研究,提供了一系列的接口函数,为并行计算的实现提供了编程环境.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	{	    LaunchStateStruct *pLS = GetLaunchStruct(atoi(&p->pszIn[16]));	    if (pLS != NULL)	    {		if (pLS->bMPIFinalized)		{		    dbg_printf("sending mpifinalized launchid(%d)\n", atoi(&p->pszIn[16]));		    strcpy(pszStr, "yes");		}		else		{		    dbg_printf("sending not mpifinalized launchid(%d)\n", atoi(&p->pszIn[16]));		    strcpy(pszStr, "no");		}		ContextWriteString(p, pszStr);	    }	    else	    {		ContextWriteString(p, "FAIL");	    }	}	else if (strnicmp(p->pszIn, "setMPIFinalized ", 16) == 0)	{	    if (SaveMPIFinalized(atoi(&p->pszIn[16])))		ContextWriteString(p, "SUCCESS");	    else		ContextWriteString(p, "FAIL");	}	else if (strnicmp(p->pszIn, "setdbgoutput ", 13) == 0)	{	    if (SetDbgRedirection(&p->pszIn[13]))	    {		SYSTEMTIME s;		GetSystemTime(&s);		dbg_printf("[%d.%d.%d %dh:%dm:%ds] starting redirection to log file.\n", s.wYear, s.wMonth, s.wDay, s.wHour, s.wMinute, s.wSecond);		WriteMPDRegistry("RedirectToLogfile", "yes");		WriteMPDRegistry("LogFile", &p->pszIn[13]);		ContextWriteString(p, "SUCCESS");	    }	    else	    {		WriteMPDRegistry("RedirectToLogfile", "no");		ContextWriteString(p, "FAIL");	    }	}	else if (strnicmp(p->pszIn, "canceldbgoutput", 15) == 0)	{	    SYSTEMTIME s;	    GetSystemTime(&s);	    dbg_printf("[%d.%d.%d %dh:%dm:%ds] stopping redirection to log file.\n", s.wYear, s.wMonth, s.wDay, s.wHour, s.wMinute, s.wSecond);	    CancelDbgRedirection();	    WriteMPDRegistry("RedirectToLogfile", "no");	    ContextWriteString(p, "SUCCESS");	}	else if (strnicmp(p->pszIn, "geterror ", 9) == 0)	{	    LaunchStateStruct *pLS = GetLaunchStruct(atoi(&p->pszIn[9]));	    if (pLS != NULL)		ContextWriteString(p, pLS->pszError);	    else		ContextWriteString(p, "invalid launch id");	}	else if (strnicmp(p->pszIn, "freeprocess ", 12) == 0)	{	    if (RemoveStateStruct(GetLaunchStruct(atoi(&p->pszIn[12]))))		ContextWriteString(p, "SUCCESS");	    else		ContextWriteString(p, "FAIL");	}	else if (strnicmp(p->pszIn, "kill ", 5) == 0)	{	    char pszTemp1[MAX_HOST_LENGTH], pszTemp2[10];	    if (GetStringOpt(p->pszIn, "host", pszTemp1) && GetStringOpt(p->pszIn, "pid", pszTemp2))	    {		strncat(p->pszIn, " src=", MAX_CMD_LENGTH - 1 - strlen(p->pszIn));		strncat(p->pszIn, g_pszHost, MAX_CMD_LENGTH - 1 - strlen(p->pszIn));		ContextWriteString(g_pRightContext, p->pszIn);	    }	    else	    {		LaunchStateStruct *pLS = GetLaunchStruct(atoi(&p->pszIn[5]));		if (pLS != NULL)		{		    _snprintf(pszStr, MAX_CMD_LENGTH, "kill src=%s host=%s pid=%d", g_pszHost, pLS->pszHost, pLS->nPid);		    ContextWriteString(g_pRightContext, pszStr);		}		else		{		    // kill does not return a value, so it cannot return an error either		    //EnqueueWrite(p, "invalid launch id", MPD_WRITING_RESULT);		}	    }	}	else if (strnicmp(p->pszIn, "setmpduser ", 11) == 0)	{	    if (g_bMPDUserCapable)	    {		char pszAccount[100];		char pszPassword[300];		if (GetStringOpt(&p->pszIn[11], "a", pszAccount))		{		    if (GetStringOpt(&p->pszIn[11], "p", pszPassword))		    {			DecodePassword(pszPassword);			if (mpdSetupCryptoClient())			{			    if (mpdSavePasswordToRegistry(pszAccount, pszPassword, true))			    {				//WriteMPDRegistry("UseMPDUser", "yes");				strcpy(g_pszMPDUserAccount, pszAccount);				strcpy(g_pszMPDUserPassword, pszPassword);				strcpy(pszStr, "SUCCESS");			    }			    else			    {				_snprintf(pszStr, MAX_CMD_LENGTH, "FAIL - %s", mpdCryptGetLastErrorString());			    }			}			else			{			    _snprintf(pszStr, MAX_CMD_LENGTH, "FAIL - %s", mpdCryptGetLastErrorString());			}		    }		    else		    {			_snprintf(pszStr, MAX_CMD_LENGTH, "FAIL - password not specified");		    }		}		else		{		    _snprintf(pszStr, MAX_CMD_LENGTH, "FAIL - account not specified");		}	    }	    else	    {		_snprintf(pszStr, MAX_CMD_LENGTH, "FAIL - command not enabled");	    }	    ContextWriteString(p, pszStr);	}	else if (stricmp(p->pszIn, "clrmpduser") == 0)	{	    if (g_bMPDUserCapable)	    {		if (mpdDeletePasswordRegistryEntry())		{		    g_bUseMPDUser = false;		    WriteMPDRegistry("UseMPDUser", "no");		    strcpy(pszStr, "SUCCESS");		}		else		{		    _snprintf(pszStr, MAX_CMD_LENGTH, "FAIL - %s", mpdCryptGetLastErrorString());		}	    }	    else	    {		_snprintf(pszStr, MAX_CMD_LENGTH, "FAIL - command not enabled");	    }	    ContextWriteString(p, pszStr);	}	else if (stricmp(p->pszIn, "enablempduser") == 0)	{	    if (g_bMPDUserCapable)	    {		//char pszAccount[100], pszPassword[100];		//if (ReadMPDRegistry("mpdAccount", pszAccount, false))		if (mpdReadPasswordFromRegistry(g_pszMPDUserAccount, g_pszMPDUserPassword))		{		    g_bUseMPDUser = true;		    WriteMPDRegistry("UseMPDUser", "yes");		    strcpy(pszStr, "SUCCESS");		}		else		{		    strcpy(pszStr, "FAIL - mpdsetuser must be called to set an account before enablempduser can be called.\n");		}	    }	    else	    {		_snprintf(pszStr, MAX_CMD_LENGTH, "FAIL - command not enabled");	    }	    ContextWriteString(p, pszStr);	}	else if (stricmp(p->pszIn, "disablempduser") == 0)	{	    if (g_bMPDUserCapable)	    {		g_bUseMPDUser = false;		WriteMPDRegistry("UseMPDUser", "no");		ContextWriteString(p, "SUCCESS");	    }	    else	    {		ContextWriteString(p, "FAIL - command not enabled");	    }	}	else if (strnicmp(p->pszIn, "stat ", 5) == 0)	{    	    char pszHost[MAX_HOST_LENGTH];	    if (!GetStringOpt(p->pszIn, "host", pszHost))	    {		strncat(p->pszIn, " host=", MAX_CMD_LENGTH - 1 - strlen(p->pszIn));		strncat(p->pszIn, g_pszHost, MAX_CMD_LENGTH - 1 - strlen(p->pszIn));	    }	    _snprintf(pszStr, MAX_CMD_LENGTH, "stat src=%s sock=%d %s", g_pszHost, p->sock, &p->pszIn[5]);	    ContextWriteString(g_pRightContext, pszStr);	}	else if (strnicmp(p->pszIn, "validate ", 9) == 0)	{	    char pszAccount[100], pszPassword[300], pszCache[10];	    bool bUseCache = true;	    int error;	    _snprintf(pszStr, MAX_CMD_LENGTH, "FAIL - invalid arguments");	    if (GetStringOpt(&p->pszIn[9], "a", pszAccount))	    {		if (GetStringOpt(&p->pszIn[9], "p", pszPassword))		{		    DecodePassword(pszPassword);		    if (GetStringOpt(&p->pszIn[9], "c", pszCache))		    {			if (stricmp(pszCache, "no") == 0)			    bUseCache = false;		    }		    if (ValidateUser(pszAccount, pszPassword, bUseCache, &error))		    {			_snprintf(pszStr, MAX_CMD_LENGTH, "SUCCESS");		    }		    else		    {			Translate_Error(error, pszStr, "FAIL - ");		    }		}	    }	    ContextWriteString(p, pszStr);	}	else if (strnicmp(p->pszIn, "freecached", 10) == 0)	{	    char pszHost[MAX_HOST_LENGTH];	    if (!GetStringOpt(p->pszIn, "host", pszHost))		strcpy(pszHost, g_pszHost);	    _snprintf(pszStr, MAX_CMD_LENGTH, "freecached src=%s sock=%d host=%s", g_pszHost, p->sock, pszHost);	    ContextWriteString(g_pRightContext, pszStr);	}	else if (stricmp(p->pszIn, "killall") == 0)	{	    _snprintf(pszStr, MAX_CMD_LENGTH, "killall src=%s", g_pszHost);	    ContextWriteString(g_pRightContext, pszStr);	}	else if (stricmp(p->pszIn, "hosts") == 0)	{	    _snprintf(pszStr, MAX_CMD_LENGTH, "hosts src=%s sock=%d result=%s", g_pszHost, p->sock, g_pszHost);	    ContextWriteString(g_pRightContext, pszStr);	}	else if (strnicmp(p->pszIn, "next ", 5) == 0)	{	    int n = atoi(&p->pszIn[5]);	    if ((n > 0) || (n < 16384))	    {		n--;		ContextWriteString(p, g_pszHost);		if (n > 0)		{		    _snprintf(pszStr, MAX_CMD_LENGTH, "next src=%s sock=%d n=%d", g_pszHost, p->sock, n);		    ContextWriteString(g_pRightContext, pszStr);		}	    }	    else	    {		ContextWriteString(p, "Error: invalid number of hosts requested");	    }	}	else if (strnicmp(p->pszIn, "barrier ", 8) == 0)	{	    char pszName[100], pszCount[10];	    if (GetStringOpt(p->pszIn, "name", pszName))	    {		if (GetStringOpt(p->pszIn, "count", pszCount))		{		    SetBarrier(pszName, atoi(pszCount), p->sock);		    _snprintf(pszStr, MAX_CMD_LENGTH, "barrier src=%s name=%s count=%s", g_pszHost, pszName, pszCount);		    ContextWriteString(g_pRightContext, pszStr);		}		else		    ContextWriteString(p, "Error: invalid barrier command, no count specified");	    }	    else		ContextWriteString(p, "Error: invalid barrier command, no name specified");	}	else if (stricmp(p->pszIn, "ps") == 0)	{	    _snprintf(pszStr, MAX_CMD_LENGTH, "ps src=%s sock=%d result=", g_pszHost, p->sock);	    ConcatenateProcessesToString(pszStr);	    ContextWriteString(g_pRightContext, pszStr);	}	else if (stricmp(p->pszIn, "extract") == 0)	{	    if (!Extract(true))	    {		err_printf("Extract failed\n");	    }	    p->nLLState = MPD_READING_CMD;	}	else if (stricmp(p->pszIn, "done") == 0)	{	    p->bDeleteMe = true;	    p->nState = MPD_INVALID;	}	else if (stricmp(p->pszIn, "set nodes") == 0)	{	    _snprintf(pszStr, MAX_CMD_LENGTH, "lefthost src=%s host=%s", g_pszHost, g_pszHost);	    ContextWriteString(g_pRightContext, pszStr);	}	else if (strnicmp(p->pszIn, "set ", 4) == 0)	{	    char pszKey[100], *pszValue;	    int nLength;	    pszValue = strstr(p->pszIn, "=");	    if (pszValue != NULL)	    {		nLength = pszValue - &p->pszIn[4];		memcpy(pszKey, &p->pszIn[4], nLength);		pszKey[nLength] = '\0';		pszValue++;		_snprintf(pszStr, MAX_CMD_LENGTH, "set src=%s key=%s value=%s", g_pszHost, pszKey, pszValue);		ContextWriteString(g_pRightContext, pszStr);	    }	}	else if (strnicmp(p->pszIn, "lset ", 5) == 0)	{	    char pszKey[100], *pszValue;	    int nLength;	    pszValue = strstr(p->pszIn, "=");	    if (pszValue != NULL)	    {		nLength = pszValue - &p->pszIn[5];		memcpy(pszKey, &p->pszIn[5], nLength);		pszKey[nLength] = '\0';		pszValue++;		WriteMPDRegistry(pszKey, pszValue);	    }	}	else if (strnicmp(p->pszIn, "lget ", 5) == 0)	{	    pszStr[0] = '\0';	    ReadMPDRegistry(&p->pszIn[5], pszStr);	    ContextWriteString(p, pszStr);	}	else if (strnicmp(p->pszIn, "ldelete ", 8) == 0)	{	    DeleteMPDRegistry(&p->pszIn[8]);	}	else if (strnicmp(p->pszIn, "insert ", 7) == 0)	{	    if (!InsertIntoRing(&p->pszIn[7]))	    {		_snprintf(pszStr, MAX_CMD_LENGTH, "%s failed\n", p->pszIn);		ContextWriteString(p, pszStr);	    }	    else	    {		p->nLLState = MPD_READING_CMD;	    }	}	else if (stricmp(p->pszIn, "shutdown") == 0)	{	    ServiceStop();	}	else if (stricmp(p->pszIn, "exitall") == 0)	{	    g_bExitAllRoot = true;	    ContextWriteString(g_pRightContext, "exitall");	}	else if (stricmp(p->pszIn, "version") == 0)	{	    GetMPDVersion(pszStr, MAX_CMD_LENGTH);	    ContextWriteString(p, pszStr);	}	else if (stricmp(p->pszIn, "mpich version") == 0)	{	    GetMPICHVersion(pszStr, MAX_CMD_LENGTH);	    ContextWriteString(p, pszStr);	}	else if (stricmp(p->pszIn, "config") == 0)	{	    pszStr[0] = '\0';	    MPDRegistryToString(pszStr, MAX_CMD_LENGTH);	    ContextWriteString(p, pszStr);	}	else if (stricmp(p->pszIn, "print") == 0)	{	    int nSent;	    char *buf, *pBuf;	    int size;	    FILE *fout = tmpfile();	    	    PrintState(fout);	    size = ftell(fout);	    //dbg_printf("print command wrote %d bytes to tmp file\n", size);	    fseek( fout, 0L, SEEK_SET );	    buf = new char[size+1];	    pBuf = buf;	    WaitForSingleObject(p->hMutex, INFINITE);	    while (size)	    {		nSent = fread(pBuf, 1, size, fout);		if (nSent == size)		{		    pBuf[size] = '\0';		    easy_send(p->sock, pBuf, size+1);		}		else		    easy_send(p->sock, pBuf, nSent);		size = size - nSent;		pBuf = pBuf + nSent;	    }	    ReleaseMutex(p->hMutex);	    delete buf;	    fclose(fout);	}	else if (strnicmp(p->pszIn, "createforwarder ", 16) == 0)	{	    _snprintf(pszStr, MAX_CMD_LENGTH, "createforwarder src=%s sock=%d %s", g_pszHost, p->sock, &p->pszIn[16]);	    ContextWriteString(g_pRightContext, pszStr);	}	else if (strnicmp(p->pszIn, "stopforwarder ", 14) == 0)	{	    char pszHost[100];	    if (GetStringOpt(p->pszIn, "host", pszHost))	    {		char *token = strtok(pszHost, ":");		if (token != NULL)		{		    token = strtok(NULL, "\n");		    if (token != NULL)		    {			int nPort = atoi(token);			if (nPort > 0)			{			    _snprintf(&p->pszIn[14], MAX_CMD_LENGTH - 14, "host=%s port=%d", pszHost, nPort);			}		    }		}	    }	    else	    {		if (GetStringOpt(p->pszIn, "port", pszHost))		{		    strncat(p->pszIn, " host=", MAX_CMD_LENGTH - 1 - strlen(p->pszIn));		    strncat(p->pszIn, g_pszHost, MAX_CMD_LENGTH - 1 - strlen(p->pszIn));		}		else		{		    if (strstr(p->pszIn, ":") != NULL)		    {			strncpy(pszHost, &p->pszIn[14], 100);			pszHost[99] = '\0';			char *token = strtok(pszHost, ":");			if (token != NULL)			{			    token = strtok(NULL, "\n");			    if (token != NULL)			    {				int nPort = atoi(token);				if (nPort > 0)				{				    _snprintf(&p->pszIn[14], MAX_CMD_LENGTH - 14, "host=%s port=%d", pszHost, nPort);				}			    }			}		    }		    else		    {			int nPort = atoi(&p->pszIn[14]);			if (nPort > 0)			{			    _snprintf(&p->pszIn[14], MAX_CMD_LENGTH - 14, "host=%s port=%d", g_pszHost, nPort);			}		    }		}	    }	    _snprintf(pszStr, MAX_CMD_LENGTH, "stopforwarder src=%s sock=%d %s", g_pszHost, p->sock, &p->pszIn[14]);	    ContextWriteString(g_pRightContext, pszStr);	}	else if (stricmp(p->pszIn, "forwarders") == 0)	{	    _snprintf(pszStr, MAX_CMD_LENGTH, "forwarders src=%s sock=%d result=", g_pszHost, p->sock);	    ConcatenateForwardersToString(pszStr);	    ContextWriteString(g_pRightContext, pszStr);	}	else if (stricmp(p->pszIn, "killforwarders") == 0)	{	    _snprintf(pszStr, MAX_CMD_LENGTH, "killforwarders src=%s", g_pszHost);	    ContextWriteString(g_pRightContext, pszStr);	}	else if (strnicmp(p->pszIn, "createtmpfile ", 14) == 0)	{	    _snprintf(pszStr, MAX_CMD_LENGTH, "createtmpfile src=%s sock=%d %s", g_pszHost, p->sock, &p->pszIn[14]);	    ContextWriteString(g_pRightContext, pszStr);	}	else if (strnicmp(p->pszIn, "deletetmpfile ", 14) == 0)	{	    _snprintf(pszStr, MAX_CMD_LENGTH, "deletetmpfile src=%s sock=%d %s", g_pszHost, p->sock, &p->pszIn[14]);	    ContextWriteString(g_pRightContext, pszStr);	}	else if (strnicmp(p->pszIn, "mpich1readint ", 14) == 0)	{	    _snprintf(pszStr, MAX_CMD_LENGTH, "mpich1readint src=%s sock=%d %s", g_pszHost, p->sock, &p->pszIn[14]);	    ContextWriteString(g_pRightContext, pszStr);	}	else if (strnicmp(p->pszIn, "putfile ", 8) == 0)	{	    HANDLE hUser;	    hUser = ParseBecomeUser(p, &p->pszIn[8], false);	    if (hUser != (HANDLE)-1)	    {		ConsoleGetFile(p->sock, &p->pszIn[8]);		LoseTheUser(hUser);	    }	}	else if (strnicmp(p->pszIn, "getfile ", 8) == 0)	{	    HANDLE hUser;	    hUser = ParseBecomeUser(p, &p->pszIn[8], true);	    if (hUser != (HANDLE)-1)	    {		ConsolePutFile(p->sock, &p->pszIn[8]);		LoseTheUser(hUser);	    }	}	else if (strnicmp(p->pszIn, "getdir ", 7) == 0)	{	    HANDLE hUser;	    hUser = ParseBecomeUser(p, &p->pszIn[7], false);	    if (hUser != (HANDLE)-1)	    {		GetDirectoryFiles(p->sock, &p->pszIn[7]);		LoseTheUser(hUser);	    }	}	else if (strnicmp(p->pszIn, "fileinit ", 9) == 0)	{	    if (GetStringOpt(p->pszIn, "account", p->pszFileAccount) && 		GetStringOpt(p->pszIn, "password", p->pszFilePassword))	    {		DecodePassword(p->pszFilePassword);		p->bFileInitCalled = true;	    }	}	else if (strnicmp(p->pszIn, "update ", 7) == 0)	{	    UpdateMPD(&p->pszIn[7]);	}	else if (strnicmp(p->pszIn, "updatempich ", 12) == 0)	{	    UpdateMPICH(&p->pszIn[12]);	    ContextWriteString(p, "SUCCESS");	}	else if (strnicmp(p->pszIn, "updatempichd ", 13) == 0)	{	    UpdateMPICHd(&p->pszIn[13]);	    ContextWriteString(p, "SUCCESS");	}	else if (stricmp(p->pszIn, "restart") == 0)	{	    ContextWriteString(p, "Restarting mpd...");	    RestartMPD();	}	else	{	    err_printf("console socket read unknown command: '%s'\n", p->pszIn);	    p->nLLState = MPD_READING_CMD;	}	break;    default:	err_printf("unexpected read in console state %d, '%s'\n", p->nLLState, p->pszIn);	p->nLLState = MPD_READING_CMD;	break;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -