Пример #1
0
// Read an INI file
LIST *ReadIni(BUF *b)
{
	LIST *o;
	// Validate arguments
	if (b == NULL)
	{
		return NULL;
	}

	o = NewListFast(NULL);

	SeekBuf(b, 0, 0);

	while (true)
	{
		char *line = CfgReadNextLine(b);

		if (line == NULL)
		{
			break;
		}

		Trim(line);

		if (IsEmptyStr(line) == false)
		{
			if (StartWith(line, "#") == false &&
				StartWith(line, "//") == false &&
				StartWith(line, ";") == false)
			{
				char *key, *value;
				UINT size = StrLen(line) + 1;

				key = ZeroMalloc(size);
				value = ZeroMalloc(size);

				if (GetKeyAndValue(line, key, size, value, size, NULL))
				{
					UINT uni_size;
					INI_ENTRY *e = ZeroMalloc(sizeof(INI_ENTRY));
					e->Key = CopyStr(key);
					e->Value = CopyStr(value);

					uni_size = CalcUtf8ToUni((BYTE *)value, StrLen(value));
					e->UnicodeValue = ZeroMalloc(uni_size);
					Utf8ToUni(e->UnicodeValue, uni_size, (BYTE *)value, StrLen(value));

					Add(o, e);
				}

				Free(key);
				Free(value);
			}
		}

		Free(line);
	}

	return o;
}
Пример #2
0
BOOL MYIniReadTools::InsertKeyAndValue( CString strTmpValue, vector<INIKEYINFO> &st ) 
{
	CString strKey;
	CString strValue;
	CString strComment;

	if(IsKeyAndValue(strTmpValue)||IsComment(strTmpValue))
	{
		GetKeyAndValue(strKey,strValue,strComment,strTmpValue);
		INIKEYINFO stInfo;
		stInfo.strKey=strKey;
		stInfo.strValue=strValue;
		stInfo.strComment=strComment;
		st.push_back(stInfo);
		return TRUE;
	}
	return FALSE;
}
Пример #3
0
void CGuiMPIJobDlg::OnRemoveBtn() 
{
    char str[CONSOLE_STR_LENGTH+1];
    int error;
    char key[100];
    char value[CONSOLE_STR_LENGTH];
    char *pszJob;
    int index;

    CString jobstr;

    UpdateData();

    if ((m_job.GetLength() < 1) || (m_sock == INVALID_SOCKET))
	return;

    index = m_job_list.GetCurSel();

    jobstr = m_job;
    jobstr.Delete(0, jobstr.Find('@')+1);
    jobstr = jobstr.Left(jobstr.Find(' '));

    strcpy(str, "dbfirst jobs");
    if (WriteString(m_sock, str) == SOCKET_ERROR)
    {
	error = WSAGetLastError();
	sprintf(value, "Error: JobsToFile, writing '%s' failed, %d\n", str, error);
	Translate_Error(error, str);
	strcat(value, str);
	MessageBox(value, "Connection Error");
	Disconnect();
	return;
    }
    if (ReadStringTimeout(m_sock, str, MPD_DEFAULT_TIMEOUT))
    {
	if (strcmp(str, "DBS_FAIL") == 0)
	{
	    //printf("no jobs on %s\n", host);
	    //WriteString(m_sock, "done");
	    //easy_closesocket(m_sock);
	    return;
	}
	if (strcmp(str, "DBS_END") == 0)
	{
	    //printf("no jobs on %s\n", host);
	    //WriteString(m_sock, "done");
	    //easy_closesocket(m_sock);
	    return;
	}
	GetKeyAndValue(str, key, value);
	pszJob = strstr(value, "@")+1;

	if (strcmp(pszJob, jobstr) == 0)
	{
	    //printf("%s : %s\n", key, value);
	    DeleteJob(m_sock, pszJob);
	    SaveKeyToDelete(key);
	}
    }
    else
    {
	//printf("Error, JobsToFile, unable to read the jobs on %s.\n", host);
	//WriteString(m_sock, "done");
	//easy_closesocket(m_sock);
	return;
    }

    while (true)
    {
	strcpy(str, "dbnext jobs");
	if (WriteString(m_sock, str) == SOCKET_ERROR)
	{
	    error = WSAGetLastError();
	    sprintf(value, "writing '%s' failed, %d\n", str, error);
	    Translate_Error(error, str);
	    strcat(value, str);
	    MessageBox(value, "Connection Error");
	    Disconnect();
	    return;
	}
	if (ReadStringTimeout(m_sock, str, MPD_DEFAULT_TIMEOUT))
	{
	    if (strcmp(str, "DBS_FAIL") == 0)
	    {
		//printf("unexpected error reading the next job\n");
		//WriteString(m_sock, "done");
		//easy_closesocket(m_sock);
		return;
	    }
	    if (strcmp(str, "DBS_END") == 0)
	    {
		break;
	    }
	    GetKeyAndValue(str, key, value);
	    pszJob = strstr(value, "@")+1;
	    if (strcmp(pszJob, jobstr) == 0)
	    {
		//printf("%s : %s\n", key, value);
		DeleteJob(m_sock, pszJob);
		SaveKeyToDelete(key);
	    }
	}
	else
	{
	    //printf("Unable to read the jobs on %s.\n", host);
	    //WriteString(m_sock, "done");
	    //easy_closesocket(m_sock);
	    return;
	}
    }

    if (s_pKeyList == NULL)
    {
	sprintf(value, "The specified job, %s, does not exist on %s\n", pszJob, m_host);
	MessageBox(value, "Note");
    }
    KeyNode *n;
    while (s_pKeyList)
    {
	n = s_pKeyList;
	s_pKeyList = s_pKeyList->next;
	DeleteKey(m_sock, n->key);
	delete n;
    }

    if (m_job_list.GetCount() > 1)
    {
	OnRefreshBtn();
	if (index == m_job_list.GetCount())
	    index--;
	m_job_list.SetCurSel(index);
	GetJobDetails();
    }
    else
    {
	OnRefreshBtn();
    }
}
Пример #4
0
void ListJobs(char *host, int port, char *altphrase)
{
    SOCKET sock;
    char str[CONSOLE_STR_LENGTH+1];
    int error;
    char key[100];
    char value[CONSOLE_STR_LENGTH];
    char localhost[100];

    if (host == NULL)
    {
	gethostname(localhost, 100);
	host = localhost;
    }

    if (ConnectToMPD(host, port, (altphrase == NULL) ? MPD_DEFAULT_PASSPHRASE : altphrase, &sock) != 0)
    {
	printf("Unable to connect to the mpd on %s\n", host);
	fflush(stdout);
	return;
    }

    printf("Jobs on %s:\n", host);
    //printf("start time : user@jobid\n");
    printf("yyyy.mm.dd<hh .mm .ss > : user@jobid : state\n");
    printf("--------------------------------------------\n");
    fflush(stdout);
    strcpy(str, "dbfirst jobs");
    if (WriteString(sock, str) == SOCKET_ERROR)
    {
	error = WSAGetLastError();
	printf("writing '%s' failed, %d\n", str, error);
	Translate_Error(error, str);
	printf("%s\n", str);
	fflush(stdout);
	easy_closesocket(sock);
	return;
    }
    if (ReadStringTimeout(sock, str, MPD_DEFAULT_TIMEOUT))
    {
	if (strcmp(str, "DBS_FAIL") == 0)
	{
	    printf("no jobs on %s\n", host);
	    fflush(stdout);
	    WriteString(sock, "done");
	    easy_closesocket(sock);
	    return;
	}
	if (strcmp(str, "DBS_END") == 0)
	{
	    printf("no jobs on %s\n", host);
	    fflush(stdout);
	    WriteString(sock, "done");
	    easy_closesocket(sock);
	    return;
	}
	GetKeyAndValue(str, key, value);
	printf("%s : %s : ", key, value);
	fflush(stdout);
	GetAndPrintState(sock, strstr(value, "@")+1);
    }
    else
    {
	printf("Unable to read the jobs on %s.\n", host);
	fflush(stdout);
	WriteString(sock, "done");
	easy_closesocket(sock);
	return;
    }

    while (true)
    {
	strcpy(str, "dbnext jobs");
	if (WriteString(sock, str) == SOCKET_ERROR)
	{
	    error = WSAGetLastError();
	    printf("writing '%s' failed, %d\n", str, error);
	    Translate_Error(error, str);
	    printf("%s\n", str);
	    fflush(stdout);
	    easy_closesocket(sock);
	    return;
	}
	if (ReadStringTimeout(sock, str, MPD_DEFAULT_TIMEOUT))
	{
	    if (strcmp(str, "DBS_FAIL") == 0)
	    {
		printf("unexpected error reading the next job\n");
		fflush(stdout);
		WriteString(sock, "done");
		easy_closesocket(sock);
		return;
	    }
	    if (strcmp(str, "DBS_END") == 0)
	    {
		break;
	    }
	    GetKeyAndValue(str, key, value);
	    printf("%s : %s : ", key, value);
	    GetAndPrintState(sock, strstr(value, "@")+1);
	}
	else
	{
	    printf("Unable to read the jobs on %s.\n", host);
	    fflush(stdout);
	    WriteString(sock, "done");
	    easy_closesocket(sock);
	    return;
	}
    }

    if (WriteString(sock, "done") == SOCKET_ERROR)
    {
	error = WSAGetLastError();
	Translate_Error(error, str);
	printf("WriteString failed: %d\n%s\n", error, str);
	fflush(stdout);
    }
    easy_closesocket(sock);
}
Пример #5
0
// Read a string table from the buffer
bool LoadTableFromBuf(BUF *b)
{
	char *tmp;
	char prefix[MAX_SIZE];
	LIST *replace_list = NULL;
	UINT i;
	// Validate arguments
	if (b == NULL)
	{
		return false;
	}

	// If the table already exists, delete it
	FreeTable();

	// Create a list
	TableList = NewList(CmpTableName);

	Zero(prefix, sizeof(prefix));

	replace_list = NewListFast(NULL);

	// Read the contents of the buffer line by line
	while (true)
	{
		TABLE *t;
		bool ok = true;

		tmp = CfgReadNextLine(b);
		if (tmp == NULL)
		{
			break;
		}

		if (tmp[0] == '$')
		{
			char key[128];
			char value[MAX_SIZE];
			if (GetKeyAndValue(tmp, key, sizeof(key), value, sizeof(value), " \t"))
			{
				if (StartWith(key, "$") && EndWith(key, "$") && StrLen(key) >= 3)
				{
					TABLE *t;
					wchar_t univalue[MAX_SIZE];
					wchar_t uniname[MAX_SIZE];

					t = ZeroMalloc(sizeof(TABLE));

					Zero(univalue, sizeof(univalue));
					Utf8ToUni(univalue, sizeof(univalue), value, StrLen(value));

					StrToUni(uniname, sizeof(uniname), key);

					t->name = (char *)CopyUniStr(uniname);
					t->unistr = CopyUniStr(univalue);

					Add(replace_list, t);

					// Found a replacement definition
					ok = false;
				}
			}
		}

		if (ok)
		{
			t = ParseTableLine(tmp, prefix, sizeof(prefix), replace_list);
			if (t != NULL)
			{
				// Register
				Insert(TableList, t);
			}
		}

		Free(tmp);
	}

	for (i = 0;i < LIST_NUM(replace_list);i++)
	{
		TABLE *t = LIST_DATA(replace_list, i);

		Free(t->name);
		Free(t->str);
		Free(t->unistr);

		Free(t);
	}

	ReleaseList(replace_list);

	return true;
}