Exemplo n.º 1
0
// do load("A") A is DBVar name
void checkStringForLoad(MCONTACT hContact, CMStringA &str)
{
	if (!strstr(str, "load(\"")) return;
	char *A, *copyOfStr = NEWSTR_ALLOCA(str.c_str());
	unsigned int i, j = 0, s = str.GetLength();
	CMStringA tmp;
	for (i = 0; i < s; i++) {
		if (!strncmp(str.c_str()+i, "load(\"", mir_strlen("load(\""))) {
			i += (int)mir_strlen("load(\"");
			A = strtok(&copyOfStr[i], "\")");
			j = A - &copyOfStr[i] + (int)mir_strlen(A) + 1;
			if (A) {
				DBVARIANT dbv;
				if (!db_get_s(hContact, MODNAME, A, &dbv)) {
					tmp.Append(dbv.pszVal);
					db_free(&dbv);
				}
			}
			else tmp.Append(str.c_str()+i, j);
			i += j;
		}
		else tmp.AppendChar(copyOfStr[i]);
	}
	str = tmp;
}
Exemplo n.º 2
0
// do the compare("A","B","X","Y")
void checkStringForcompare(CMStringA &str)
{
	if (!strstr(str, "compare(\"")) return;
	char *A, *B, *X, *Y, *copyOfStr = NEWSTR_ALLOCA(str.c_str());
	CMStringA tmp;
	unsigned int i, j = 0, s = str.GetLength();
	for (i = 0; i < s; i++) {
		if (!strncmp(str.c_str()+i, "compare(\"", mir_strlen("compare(\""))) {
			i += (int)mir_strlen("compare(\"");
			A = strtok(&copyOfStr[i], "\",\"");
			B = strtok(NULL, "\",\"");
			X = strtok(NULL, "\",\"");
			Y = strtok(NULL, ",\")");
			j = Y - &copyOfStr[i] + (int)mir_strlen(Y) + 1;
			if (A && B && X && Y) {
				if (!mir_strcmp(A, B))
					tmp.Append(X);
				else
					tmp.Append(Y);
			}
			else tmp.Append(str.c_str()+i, j);
			i += j;
		}
		else tmp.AppendChar(copyOfStr[i]);
	}
	str = tmp;
}
Exemplo n.º 3
0
INT_PTR __cdecl CIrcProto::Scripting_InsertRawOut( WPARAM, LPARAM lParam )
{
	char* pszRaw = (char*)lParam;
	if (m_scriptingEnabled && pszRaw && IsConnected()) {
		CMStringA S = pszRaw;
		S.Replace("%", "%%%%");
		NLSendNoScript((const unsigned char *)S.c_str(), (int)mir_strlen(S.c_str()));
		return 0;
	}

	return 1;
}
Exemplo n.º 4
0
INT_PTR CMraProto::MraChatSessionInvite(HANDLE hContactChatSession, const CMStringA &lpszEMailInMultiChat, DWORD dwTime)
{
	if (!hContactChatSession)
		return 1;

	CMStringW wszBuff;
	wszBuff.Format(L"[%s]: %s", _A2T(lpszEMailInMultiChat.c_str()), TranslateT("invite sender"));
	return MraChatSessionEventSendByHandle(hContactChatSession, GC_EVENT_ACTION, GCEF_ADDTOLOG, lpszEMailInMultiChat, NULL, wszBuff, 0, dwTime);
}
Exemplo n.º 5
0
// do saveN("A","B","C","D") A is module, B is setting, c is value, D is type 0/b 1/w 2/d 3/s
void checkStringForSaveN(CMStringA &str)
{
	if (!strstr(str, "saveN(\"")) return;
	char *A, *B, *C, *D, *copyOfStr = NEWSTR_ALLOCA(str.c_str());
	unsigned int i, j = 0, s = str.GetLength();
	CMStringA tmp;
	for (i = 0; i < s; i++) {
		if (!strncmp(str.c_str()+i, "saveN(\"", mir_strlen("saveN(\""))) {
			i += (int)mir_strlen("saveN(\"");
			A = strtok(&copyOfStr[i], "\",\"");
			B = strtok(NULL, ",\"");
			C = strtok(NULL, ",\"");
			D = strtok(NULL, ",\")");
			j = D - &copyOfStr[i] + (int)mir_strlen(D) + 1;
			if (A && B && C && D) {
				switch (D[0]) {
				case '0':
				case 'b':
					db_set_b(NULL, A, B, (BYTE)atoi(C));
					break;
				case '1':
				case 'w':
					db_set_w(NULL, A, B, (WORD)atoi(C));
					break;
				case '2':
				case 'd':
					db_set_dw(NULL, A, B, (DWORD)atoi(C));
					break;
				case '3':
				case 's':
					db_set_s(NULL, A, B, C);
					break;
				}
			}
			else tmp.Append(str.c_str()+i, j);
			i += j;
		}
		else tmp.AppendChar(copyOfStr[i]);
	}
	str = tmp;
}
Exemplo n.º 6
0
// do loadN("A","B") A is module, B is setting
void checkStringForLoadN(CMStringA &str)
{
	if (!strstr(str, "loadN(\"")) return;
	char *copyOfStr = NEWSTR_ALLOCA(str.c_str()), temp[32];
	unsigned int i, j = 0, s = str.GetLength();
	CMStringA tmp;
	for (i = 0; i < s; i++) {
		if (!strncmp(str.c_str()+i, "loadN(\"", mir_strlen("loadN(\""))) {
			i += (int)mir_strlen("loadN(\"");
			char *A = strtok(&copyOfStr[i], "\",\"");
			char *B = strtok(NULL, ",\")");
			if (A && B) {
				j = B - &copyOfStr[i] + (int)mir_strlen(B) + 1;
				DBVARIANT dbv;
				if (!db_get(NULL, A, B, &dbv)) {
					switch (dbv.type) {
					case DBVT_BYTE:
						tmp.Append(_itoa(dbv.bVal, temp, 10));
						break;
					case DBVT_WORD:
						tmp.Append(_itoa(dbv.wVal, temp, 10));
						break;
					case DBVT_DWORD:
						tmp.Append(_itoa(dbv.dVal, temp, 10));
						break;
					case DBVT_ASCIIZ:
						tmp.Append(dbv.pszVal);
						break;
					}
					db_free(&dbv);
				}
			}
			else tmp.Append(str.c_str()+i, i);
			i += j;
		}
		else tmp.AppendChar(copyOfStr[i]);
	}
	str = tmp;
}
Exemplo n.º 7
0
// do save("A","B") A is DBVar name, B is value
void checkStringForSave(MCONTACT hContact, CMStringA &str)
{
	if (!strstr(str, "save(\"")) return;
	char *A, *B, *copyOfStr = NEWSTR_ALLOCA(str.c_str());
	unsigned int i, j = 0, s = str.GetLength();
	CMStringA tmp;
	for (i = 0; i < s; i++) {
		if (!strncmp(str.c_str()+i, "save(\"", mir_strlen("save(\""))) {
			i += (int)mir_strlen("save(\"");
			A = strtok(&copyOfStr[i], "\",\"");
			B = strtok(NULL, ",\")");
			j = B - &copyOfStr[i] + (int)mir_strlen(B) + 1;
			if (A && B)
				db_set_s(hContact, MODNAME, A, B);

			else tmp.Append(str.c_str()+i, j);
			i += j;
		}
		else tmp.AppendChar(copyOfStr[i]);
	}
	str = tmp;
}
Exemplo n.º 8
0
DWORD MraAvatarsHttpTransaction(HANDLE hConnection, DWORD dwRequestType, LPCSTR lpszUser, LPCSTR lpszDomain, LPCSTR lpszHost, DWORD dwReqObj, BOOL bUseKeepAliveConn, DWORD *pdwResultCode, BOOL *pbKeepAlive, DWORD *pdwFormat, size_t *pdwAvatarSize, INTERNET_TIME *pitLastModifiedTime)
{
	if (pdwResultCode)      *pdwResultCode = 0;
	if (pbKeepAlive)        *pbKeepAlive = FALSE;
	if (pdwFormat)          *pdwFormat = PA_FORMAT_UNKNOWN;
	if (pdwAvatarSize)      *pdwAvatarSize = 0;
	if (pitLastModifiedTime) memset(pitLastModifiedTime, 0, sizeof(INTERNET_TIME));

	if (!hConnection)
		return ERROR_INVALID_HANDLE;

	LPSTR lpszReqObj;

	switch (dwReqObj) {
		case MAHTRO_AVT:          lpszReqObj = "_avatar"; break;
		case MAHTRO_AVTMRIM:      lpszReqObj = "_mrimavatar"; break;
		case MAHTRO_AVTSMALL:     lpszReqObj = "_avatarsmall"; break;
		case MAHTRO_AVTSMALLMRIM: lpszReqObj = "_mrimavatarsmall"; break;
		default:                  lpszReqObj = ""; break;
	}

	char szBuff[4096];
	DWORD dwBuffSize = mir_snprintf(szBuff, SIZEOF(szBuff), "http://%s/%s/%s/%s", lpszHost, lpszDomain, lpszUser, lpszReqObj);
	CMStringA szSelfVersionString = MraGetSelfVersionString();

	NETLIBHTTPHEADER nlbhHeaders[8] = { 0 };
	nlbhHeaders[0].szName = "User-Agent";		nlbhHeaders[0].szValue = (LPSTR)szSelfVersionString.c_str();
	nlbhHeaders[1].szName = "Accept-Encoding";	nlbhHeaders[1].szValue = "deflate";
	nlbhHeaders[2].szName = "Pragma";		nlbhHeaders[2].szValue = "no-cache";
	nlbhHeaders[3].szName = "Connection";		nlbhHeaders[3].szValue = (bUseKeepAliveConn) ? "keep-alive" : "close";

	NETLIBHTTPREQUEST nlhr = { 0 };
	nlhr.cbSize = sizeof(nlhr);
	nlhr.requestType = dwRequestType;
	nlhr.flags = (NLHRF_GENERATEHOST | NLHRF_SMARTREMOVEHOST | NLHRF_SMARTAUTHHEADER);
	nlhr.szUrl = szBuff;
	nlhr.headers = (NETLIBHTTPHEADER*)&nlbhHeaders;
	nlhr.headersCount = 4;

	DWORD dwSent = CallService(MS_NETLIB_SENDHTTPREQUEST, (WPARAM)hConnection, (LPARAM)&nlhr);
	if (dwSent == SOCKET_ERROR || !dwSent)
		return GetLastError();

	NETLIBHTTPREQUEST *pnlhr = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_RECVHTTPHEADERS, (WPARAM)hConnection, 0);
	if (!pnlhr)
		return GetLastError();

	for (int i = 0; i < pnlhr->headersCount; i++) {
		if (!_strnicmp(pnlhr->headers[i].szName, "Connection", 10)) {
			if (pbKeepAlive)
				*pbKeepAlive = !_strnicmp(pnlhr->headers[i].szValue, "keep-alive", 10);
		}
		else if (!_strnicmp(pnlhr->headers[i].szName, "Content-Type", 12)) {
			if (pdwFormat) {
				for (DWORD j = 0; j < PA_FORMAT_MAX; j++) {
					if (!_stricmp(pnlhr->headers[i].szValue, lpcszContentType[j])) {
						*pdwFormat = j;
						break;
					}
				}
			}
		}
		else if (!_strnicmp(pnlhr->headers[i].szName, "Content-Length", 14)) {
			if (pdwAvatarSize)
				*pdwAvatarSize = atol(pnlhr->headers[i].szValue);
		}
		else if (!_strnicmp(pnlhr->headers[i].szName, "Last-Modified", 13)) {
			if (pitLastModifiedTime)
				InternetTimeGetTime(pnlhr->headers[i].szValue, *pitLastModifiedTime);
		}
	}

	if (pdwResultCode)
		*pdwResultCode = pnlhr->resultCode;
	CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)pnlhr);
	return 0;
}