Beispiel #1
0
// Adds new contact
DWORD CMraProto::MraAddContact(MCONTACT hContact, DWORD dwContactFlag, DWORD dwGroupID, const CMStringA &szEmail, const CMStringW &wszCustomName, const CMStringA *szPhones, const CMString* wszAuthMessage)
{
	if (szEmail.GetLength() <= 4 && !(dwContactFlag & CONTACT_FLAG_GROUP))
		return 0;

	dwContactFlag |= CONTACT_FLAG_UNICODE_NAME;
	if (dwGroupID == -1)
		dwGroupID = 0;

	OutBuffer buf;
	buf.SetUL(dwContactFlag);
	buf.SetUL(dwGroupID);
	buf.SetLPSLowerCase(szEmail);
	buf.SetLPSW(wszCustomName);
	buf.SetLPS((szPhones == NULL) ? "" : *szPhones);

	// pack auth message
	OutBuffer buf2;
	buf2.SetUL(2);
	buf2.SetLPSW(_T(""));//***deb possible nick here
	buf2.SetLPSW((wszAuthMessage == NULL) ? _T("") : *wszAuthMessage);
	buf.SetLPS(CMStringA(ptrA(mir_base64_encode(buf2.Data(), (int)buf2.Len()))));

	buf.SetUL(0);

	return MraSendQueueCMD(hSendQueueHandle, 0, hContact, ACKTYPE_ADDED, NULL, 0, MRIM_CS_ADD_CONTACT, buf.Data(), buf.Len());
}
Beispiel #2
0
// Отправка SMS
DWORD CMraProto::MraSMSW(MCONTACT hContact, const CMStringA &lpszPhone, const CMStringW &lpwszMessage)
{
	CMStringA szPhoneLocal = "+" + CopyNumber(lpszPhone);

	OutBuffer buf;
	buf.SetUL(0);
	buf.SetLPS(szPhoneLocal);
	buf.SetLPSW(lpwszMessage);

	/* Save phone number for ack notify after send. */
	LPBYTE lpbData = (LPBYTE)mir_calloc(lpszPhone.GetLength() + sizeof(size_t));
	if (NULL == lpbData)
		return (0);
	memcpy(lpbData, lpszPhone, lpszPhone.GetLength());
	return MraSendQueueCMD(hSendQueueHandle, 0, hContact, ICQACKTYPE_SMS, lpbData, lpszPhone.GetLength(), MRIM_CS_SMS, buf.Data(), buf.Len());
}
Beispiel #3
0
int luaM_print(lua_State *L)
{
	CMStringA data;
	int nargs = lua_gettop(L);
	for (int i = 1; i <= nargs; ++i)
	{
		switch (lua_type(L, i))
		{
		case LUA_TNIL:
			data.AppendFormat("%s   ", "nil");
			break;
		case LUA_TBOOLEAN:
			data.AppendFormat("%s   ", lua_toboolean(L, i) ? "true" : "false");
			break;
		case LUA_TNUMBER:
		case LUA_TSTRING:
			data.AppendFormat("%s   ", lua_tostring(L, i));
			break;
		case LUA_TTABLE:
			data.AppendFormat("%s   ", "table");
			break;
		default:
			data.AppendFormat("0x%p   ", lua_topointer(L, i));
			break;
		}
	}
	data.Delete(data.GetLength() - 3, 3);

	CallService(MS_NETLIB_LOG, (WPARAM)hNetlib, (LPARAM)data.GetBuffer());

	return 0;
}
Beispiel #4
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;
}
Beispiel #5
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;
}
Beispiel #6
0
// autorize a user & add him to a roster
DWORD CMraProto::MraAuthorize(const CMStringA& szEmail)
{
	if (szEmail.GetLength() <= 4)
		return 0;

	OutBuffer buf;
	buf.SetLPSLowerCase(szEmail);
	return MraSendCMD(MRIM_CS_AUTHORIZE, buf.Data(), buf.Len());
}
Beispiel #7
0
DWORD CMraProto::MraMessageRecv(const CMStringA &szFrom, DWORD dwMsgID)
{
	if (szFrom.GetLength() <= 4)
		return 0;

	OutBuffer buf;
	buf.SetLPSLowerCase(szFrom);
	buf.SetUL(dwMsgID);
	return MraSendCMD(MRIM_CS_MESSAGE_RECV, buf.Data(), buf.Len());
}
Beispiel #8
0
// Ответ на отправку файлов
DWORD CMraProto::MraFileTransferAck(DWORD dwStatus, const CMStringA &szEmail, DWORD dwIDRequest, const CMStringA &szDescription)
{
	if (szEmail.GetLength() <= 4)
		return 0;

	OutBuffer buf;
	buf.SetUL(dwStatus);
	buf.SetLPSLowerCase(szEmail);
	buf.SetUL(dwIDRequest);
	buf.SetLPS(szDescription);
	return MraSendCMD(MRIM_CS_FILE_TRANSFER_ACK, buf.Data(), buf.Len());
}
Beispiel #9
0
// Отправка файлов
DWORD CMraProto::MraFileTransfer(const CMStringA &szEmail, DWORD dwIDRequest, DWORD dwFilesTotalSize, const CMStringW &wszFiles, const CMStringA &szAddresses)
{
	if (szEmail.GetLength() <= 4)
		return 0;

	CMStringA szFiles = wszFiles;

	OutBuffer buf;
	buf.SetLPSLowerCase(szEmail);
	buf.SetUL(dwIDRequest);
	buf.SetUL(dwFilesTotalSize);
	buf.SetUL(sizeof(DWORD) * 5 + szFiles.GetLength() + wszFiles.GetLength()*sizeof(WCHAR) + szAddresses.GetLength());

	buf.SetLPS(szFiles);
	buf.SetUL(sizeof(DWORD) * 2 + wszFiles.GetLength()*sizeof(WCHAR));

	buf.SetUL(1);
	buf.SetLPSW(wszFiles);

	buf.SetLPS(szAddresses);
	return MraSendCMD(MRIM_CS_FILE_TRANSFER, buf.Data(), buf.Len());
}
Beispiel #10
0
// Отправка файлов
DWORD CMraProto::MraGame(const CMStringA &szEmail, DWORD dwGameSessionID, DWORD dwGameMsg, DWORD dwGameMsgID, const CMStringA &szData)
{
	if (szEmail.GetLength() <= 4)
		return 0;

	OutBuffer buf;
	buf.SetLPSLowerCase(szEmail);
	buf.SetUL(dwGameSessionID);
	buf.SetUL(dwGameMsg);
	buf.SetUL(dwGameMsgID);
	buf.SetUL(_time32(NULL));
	buf.SetLPS(szData);
	return MraSendCMD(MRIM_CS_GAME, buf.Data(), buf.Len());
}
Beispiel #11
0
// Авторизация
DWORD CMraProto::MraLogin2W(const CMStringA &szLogin, const CMStringA &szPassword, DWORD dwStatus, const CMStringA &szStatusUri, CMStringW &wszStatusTitle, CMStringW &wszStatusDesc, DWORD dwFutureFlags, CMStringA &szUserAgentFormatted, CMStringA &szUserAgent)
{
	if (wszStatusTitle.GetLength() > STATUS_TITLE_MAX)     wszStatusTitle.Truncate(STATUS_TITLE_MAX);
	if (wszStatusDesc.GetLength() > STATUS_DESC_MAX)       wszStatusDesc.Truncate(STATUS_DESC_MAX);
	if (szUserAgentFormatted.GetLength() > USER_AGENT_MAX) szUserAgentFormatted.Truncate(USER_AGENT_MAX);
	if (szUserAgent.GetLength() > MAX_CLIENT_DESCRIPTION)  szUserAgent.Truncate(MAX_CLIENT_DESCRIPTION);

	OutBuffer buf;
	buf.SetLPS(szLogin);
	buf.SetLPS(szPassword);
	buf.SetUL(dwStatus);
	buf.SetLPS(szStatusUri);
	buf.SetLPSW(wszStatusTitle);
	buf.SetLPSW(wszStatusDesc);
	buf.SetUL(dwFutureFlags);
	buf.SetLPS(szUserAgentFormatted);
	buf.SetLPS("ru");
	buf.SetLPS("");
	buf.SetLPS("");
	buf.SetLPS(szUserAgent);// LPS client description /max 256

	return MraSendCMD(MRIM_CS_LOGIN2, buf.Data(), buf.Len());
}
Beispiel #12
0
// Соединение с прокси
DWORD CMraProto::MraProxy(const CMStringA &szEmail, DWORD dwIDRequest, DWORD dwDataType, const CMStringA &lpszData, const CMStringA &szAddresses, MRA_GUID mguidSessionID)
{
	if (szEmail.GetLength() <= 4)
		return 0;

	OutBuffer buf;
	buf.SetLPSLowerCase(szEmail);
	buf.SetUL(dwIDRequest);
	buf.SetUL(dwDataType);
	buf.SetLPS(lpszData);
	buf.SetLPS(szAddresses);
	buf.SetGUID(mguidSessionID);
	return MraSendCMD(MRIM_CS_PROXY, buf.Data(), buf.Len());
}
Beispiel #13
0
// Поиск контакта по EMail
HANDLE CMraProto::MraWPRequestByEMail(MCONTACT hContact, DWORD dwAckType, CMStringA &szEmail)
{
	if (szEmail.GetLength() <= 4)
		return 0;

	int iStart = 0;
	CMStringA szUser = szEmail.Tokenize("@", iStart);
	CMStringA szDomain = szEmail.Tokenize("@", iStart);

	DWORD dwRequestFlags = 0;
	SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_USER);
	SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DOMAIN);
	return MraWPRequestW(hContact, dwAckType, dwRequestFlags, szUser, szDomain, _T(""), _T(""), _T(""), 0, 0, 0, 0, 0, 0, 0, 0, 0);
}
Beispiel #14
0
// Send confirmation
DWORD CMraProto::MraMessageAsk(DWORD dwMsgID, DWORD dwFlags, const CMStringA &szEmail, const CMStringW &lpwszMessage, const CMStringW &lpwszMessageRTF)
{
	if (szEmail.GetLength() <= 4 || lpwszMessage.IsEmpty())
		return 0;

	OutBuffer buf;
	buf.SetUL(dwMsgID);//UL msg_id
	buf.SetUL(dwFlags);//UL flags
	buf.SetLPSLowerCase(szEmail);// LPS from e-mail ANSI
	buf.SetLPSW(lpwszMessage);// LPS message UNICODE
	if (dwFlags & MESSAGE_FLAG_RTF)
		buf.SetLPSW(lpwszMessageRTF);// LPS	//rtf-formatted message ( >= 1.1)	- MESSAGE_FLAG_RTF

	return MraSendCMD(MRIM_CS_MESSAGE_ACK, buf.Data(), buf.Len());
}
Beispiel #15
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;
}
Beispiel #16
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;
}
Beispiel #17
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;
}
Beispiel #18
0
// add prefix to sent messages
int OnDatabaseEventPreAdd(WPARAM hContact, LPARAM lParam)
{
	if (!options.prefix_messages || !lParam)
		return 0;

	DBEVENTINFO *dbei = (DBEVENTINFO *)lParam;
	if ((dbei->eventType != EVENTTYPE_MESSAGE) || !(dbei->flags & DBEF_SENT) || (dbei->flags & DBEF_OTR_PREFIXED))
		return 0;

	if (dbei->cbBlob == 0 || dbei->pBlob == 0)
		return 0; // just to be safe

	const char *proto = GetContactProto(hContact);
	if (!proto)
		return 0;
	if (db_get_b(hContact, proto, "ChatRoom", 0) == 1)
		return 0;

	if (mir_strcmp(proto, META_PROTO) == 0) {
		hContact = db_mc_getMostOnline(hContact);
		if (!hContact)
			return 0;
		proto = GetContactProto(hContact);
		if (!proto)
			return 0;
	}

	ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact);	
	bool encrypted = otr_context_get_trust(context) != TRUST_NOT_PRIVATE;
	if (!encrypted)
		return 0;
	
	DBEVENTINFO my_dbei = *dbei; // copy the other event

	char *msg = (char*)dbei->pBlob;
	int msgLen = (int)strlen(msg);

	int prefixlen = (int)strnlen(options.prefix, 64);
	if (strncmp(msg, options.prefix, prefixlen) == 0)
		return 0;

	// check for additional data presence
	int datalen = dbei->cbBlob - msgLen;
	if (datalen < 0)
		datalen = 0;

	CMStringA buf;
	buf.Append(options.prefix, prefixlen);
	buf.Append(msg);
	// append additional data
	if (datalen) {
		buf.AppendChar(0);
		buf.Append(msg + msgLen + 1, datalen);
	}
	
	my_dbei.pBlob = (BYTE*)buf.GetBuffer();
	my_dbei.cbBlob = (int)buf.GetLength();
	my_dbei.flags |= DBEF_OTR_PREFIXED;
	db_event_add(hContact, &my_dbei);
	
	// stop original event from being added
	return 1;
}
Beispiel #19
0
void CAimProto::aim_connection_clientlogin(void)
{
	pass_ptrA password(getStringA(AIM_KEY_PW));
	replaceStr(m_username, ptrA(getStringA(AIM_KEY_SN)));

	CMStringA buf;
	buf.Format("devId=%s&f=xml&pwd=%s&s=%s", AIM_DEFAULT_CLIENT_KEY, ptrA(mir_urlEncode(password)), ptrA(mir_urlEncode(m_username)));

	NETLIBHTTPHEADER headers[] = {
		{ "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8" }
	};

	NETLIBHTTPREQUEST req = { 0 };
	req.cbSize = sizeof(req);
	req.flags = NLHRF_SSL;
	req.requestType = REQUEST_POST;
	req.szUrl = AIM_LOGIN_URL;
	req.headers = headers;
	req.headersCount = _countof(headers);
	req.pData = buf.GetBuffer();
	req.dataLength = buf.GetLength();

	NLHR_PTR resp(CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)&req));
	if (!resp || !resp->dataLength) {
		broadcast_status(ID_STATUS_OFFLINE);
		return;
	}

	time_t hosttime;
	CMStringA token, secret;
	if (!parse_clientlogin_response(resp, headers, token, secret, hosttime)) {
		//TODO: handle error
		broadcast_status(ID_STATUS_OFFLINE);
		mir_free(headers[0].szValue);
		return;
	}

	bool encryption = !getByte(AIM_KEY_DSSL, 0);
	CMStringA url;
	fill_session_url(url, token, secret, hosttime, password, encryption);

	// reuse NETLIBHTTPREQUEST
	req.requestType = REQUEST_GET;
	req.pData = NULL;
	req.flags |= NLHRF_MANUALHOST;
	req.dataLength = 0;
	req.headersCount = 1;
	req.szUrl = url.GetBuffer();
	{
		NETLIBHTTPHEADER headers2[] = {
			{ "Host", "api.oscar.aol.com" },
		};
		req.headers = headers2;

		resp = CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)&req);
	}

	if (!resp || !resp->dataLength) {
		// TODO: handle error
		broadcast_status(ID_STATUS_OFFLINE);
		return;
	}

	CMStringA bos_host, cookie, tls_cert_name; //TODO: find efficient buf size
	unsigned short bos_port = 0;
	if (!parse_start_socar_session_response(resp->pData, bos_host, bos_port, cookie, tls_cert_name, encryption)) {
		// TODO: handle error
		broadcast_status(ID_STATUS_OFFLINE);
		return;
	}

	m_hServerConn = aim_connect(bos_host, bos_port, (tls_cert_name[0] && encryption) ? true : false, bos_host);
	if (!m_hServerConn) {
		// TODO: handle error
		broadcast_status(ID_STATUS_OFFLINE);
		return;
	}

	replaceStr(COOKIE, cookie);
	COOKIE_LENGTH = (int)mir_strlen(cookie);

	ForkThread(&CAimProto::aim_protocol_negotiation, 0);
}
Beispiel #20
0
void fill_session_url(CMStringA &buf, CMStringA &token, CMStringA &secret, time_t &hosttime, const char *password, bool encryption)
{
	/*
		AIM_SESSION_URL?query_string?sig_sha256=signature
		*/

	CMStringA query_string;
	query_string.Format("a=%s&distId=%s&f=xml&k=%s&ts=%llu&useTLS=%d", token, AIM_DEFAULT_DISTID, AIM_DEFAULT_CLIENT_KEY, hosttime, (int)encryption);

	BYTE session_key[MIR_SHA256_HASH_SIZE], signature[MIR_SHA256_HASH_SIZE];
	mir_hmac_sha256(session_key, (BYTE*)password, mir_strlen(password), (BYTE*)secret.GetString(), secret.GetLength());

	ptrA szKey(mir_base64_encode(session_key, sizeof(session_key)));
	generate_signature(signature, "GET", AIM_SESSION_URL, query_string, szKey);

	ptrA szEncoded(mir_base64_encode(signature, sizeof(signature)));
	buf.Format("%s?%s&sig_sha256=%s", AIM_SESSION_URL, query_string, (char*)szEncoded);
}
Beispiel #21
0
void CVkProto::OnReciveUploadServer(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
	CVkFileUploadParam *fup = (CVkFileUploadParam *)pReq->pUserInfo;
	if (!IsOnline()) {
		SendFileFiled(fup, VKERR_OFFLINE);
		return;
	}

	debugLogA("CVkProto::OnReciveUploadServer %d", reply->resultCode);
	if (reply->resultCode != 200) {
		SendFileFiled(fup, VKERR_INVALID_SERVER);
		return;
	}

	JSONNode jnRoot;
	const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
	if (!jnResponse || pReq->m_iErrorCode) {
		SendFileFiled(fup, pReq->m_iErrorCode);
		return;
	}

	CMStringA uri(jnResponse["upload_url"].as_mstring());
	if (uri.IsEmpty()) {
		SendFileFiled(fup, VKERR_INVALID_URL);
		return;
	}
	
	FILE *pFile = _tfopen(fup->FileName, _T("rb"));
	if (pFile == NULL) {
		SendFileFiled(fup, VKERR_ERR_OPEN_FILE);
		return;
	}

	fseek(pFile, 0, SEEK_END);
	long iFileLen = ftell(pFile); //FileSize
	if (iFileLen < 1) {
		fclose(pFile);
		SendFileFiled(fup, VKERR_ERR_READ_FILE);
		return;
	}
	fseek(pFile, 0, SEEK_SET);

	ProtoBroadcastAck(fup->hContact, ACKTYPE_FILE, ACKRESULT_CONNECTING, (HANDLE)fup);

	AsyncHttpRequest *pUploadReq = new AsyncHttpRequest(this, REQUEST_POST, uri, false, &CVkProto::OnReciveUpload);
	pUploadReq->m_bApiReq = false;
	pUploadReq->m_szParam = "";
	CMStringA boundary, header;
	CMStringA NamePart = fup->atrName();
	CMStringA FNamePart = fup->fileName();
	// Boundary
	int iboundary;
	Utils_GetRandom(&iboundary, sizeof(iboundary));
	boundary.AppendFormat("Miranda%dNG%d", iboundary, time(NULL));
	// Header
	header.AppendFormat("multipart/form-data; boundary=%s", boundary);
	pUploadReq->AddHeader("Content-Type", header);
	// Content-Disposition {
	CMStringA DataBegin = "--";
	DataBegin += boundary;
	DataBegin += "\r\n";
	DataBegin += "Content-Disposition: form-data; name=\"";
	DataBegin += NamePart;
	DataBegin += "\"; filename=\"";
	DataBegin += FNamePart;
	DataBegin += "\";\r\n\r\n";
	// } Content-Disposition
	CMStringA DataEnd = "\r\n--";
	DataEnd += boundary;
	DataEnd += "--\r\n";
	// Body size
	long dataLength = iFileLen + DataBegin.GetLength() + DataEnd.GetLength();
	// Body {
	char* pData = (char *)mir_alloc(dataLength);
	memcpy(pData, (void *)DataBegin.GetBuffer(), DataBegin.GetLength());
	pUploadReq->pData = pData;

	pData += DataBegin.GetLength();
	long lBytes = (long)fread(pData, 1, iFileLen, pFile);
	fclose(pFile);

	if (lBytes != iFileLen) {
		SendFileFiled(fup, VKERR_ERR_READ_FILE);
		mir_free(pUploadReq->pData);
		delete pUploadReq;
		return;
	}

	pData += iFileLen;
	memcpy(pData, (void *)DataEnd.GetBuffer(), DataEnd.GetLength());
	// } Body

	pUploadReq->dataLength = (int)dataLength;
	pUploadReq->pUserInfo = pReq->pUserInfo;
	Push(pUploadReq);
}
Beispiel #22
0
HWND GGPROTO::SearchAdvanced(HWND hwndDlg)
{
	// Check if connected
	if (!isonline())
		return 0;

	gg_pubdir50_t req = gg_pubdir50_new(GG_PUBDIR50_SEARCH);
	if (!req)
	{
#ifdef DEBUGMODE
		debugLogA("SearchAdvanced(): ForkThread 14 GGPROTO::searchthread");
#endif
		ForkThread(&GGPROTO::searchthread, NULL);
		return (HWND)1;
	}

	CMStringA szQuery;

	// Fetch search data
	TCHAR text[64];
	GetDlgItemText(hwndDlg, IDC_FIRSTNAME, text, _countof(text));
	if (mir_tstrlen(text))
	{
		T2Utf firstName_utf8(text);
		gg_pubdir50_add(req, GG_PUBDIR50_FIRSTNAME, firstName_utf8);
		szQuery.Append(firstName_utf8);
	}
	/* 1 */ szQuery.AppendChar('.');

	GetDlgItemText(hwndDlg, IDC_LASTNAME, text, _countof(text));
	if (mir_tstrlen(text))
	{
		T2Utf lastName_utf8(text);
		gg_pubdir50_add(req, GG_PUBDIR50_LASTNAME, lastName_utf8);
		szQuery.Append(lastName_utf8);
	}
	/* 2 */ szQuery.AppendChar('.');

	GetDlgItemText(hwndDlg, IDC_NICKNAME, text, _countof(text));
	if (mir_tstrlen(text))
	{
		T2Utf nickName_utf8(text);
		gg_pubdir50_add(req, GG_PUBDIR50_NICKNAME, nickName_utf8);
		szQuery.Append(nickName_utf8);
	}
	/* 3 */ szQuery.AppendChar('.');

	GetDlgItemText(hwndDlg, IDC_CITY, text, _countof(text));
	if (mir_tstrlen(text))
	{
		T2Utf city_utf8(text);
		gg_pubdir50_add(req, GG_PUBDIR50_CITY, city_utf8);
		szQuery.Append(city_utf8);
	}
	/* 4 */ szQuery.AppendChar('.');

	GetDlgItemText(hwndDlg, IDC_AGEFROM, text, _countof(text));
	if (mir_tstrlen(text))
	{
		int yearTo = _tstoi(text);
		int yearFrom;
		time_t t = time(NULL);
		struct tm *lt = localtime(&t);
		int ay = lt->tm_year + 1900;
		char age[16];

		GetDlgItemTextA(hwndDlg, IDC_AGETO, age, _countof(age));
		yearFrom = atoi(age);

		// Count & fix ranges
		if (!yearTo)
			yearTo = ay;
		else
			yearTo = ay - yearTo;
		if (!yearFrom)
			yearFrom = 0;
		else
			yearFrom = ay - yearFrom;
		mir_sntprintf(text, _T("%d %d"), yearFrom, yearTo);

		T2Utf age_utf8(text);
		gg_pubdir50_add(req, GG_PUBDIR50_BIRTHYEAR, age_utf8);
		szQuery.Append(age_utf8);
	}
	/* 5 */ szQuery.AppendChar('.');

	switch(SendDlgItemMessage(hwndDlg, IDC_GENDER, CB_GETCURSEL, 0, 0))
	{
		case 1:
			gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_FEMALE);
			szQuery.Append(GG_PUBDIR50_GENDER_MALE);
			break;
		case 2:
			gg_pubdir50_add(req, GG_PUBDIR50_GENDER, GG_PUBDIR50_GENDER_MALE);
			szQuery.Append(GG_PUBDIR50_GENDER_FEMALE);
			break;
	}
	/* 6 */ szQuery.AppendChar('.');

	if (IsDlgButtonChecked(hwndDlg, IDC_ONLYCONNECTED))
	{
		gg_pubdir50_add(req, GG_PUBDIR50_ACTIVE, GG_PUBDIR50_ACTIVE_TRUE);
		szQuery.Append(GG_PUBDIR50_ACTIVE_TRUE);
	}
	/* 7 */ szQuery.AppendChar('.');

	// No data entered
	if (szQuery.GetLength() <= 7 || (szQuery.GetLength() == 8 && IsDlgButtonChecked(hwndDlg, IDC_ONLYCONNECTED)))
		return 0;

	// Count crc & check if the data was equal if yes do same search with shift
	unsigned long crc = crc_get(szQuery.GetBuffer());

	if (crc == last_crc && next_uin)
		gg_pubdir50_add(req, GG_PUBDIR50_START, ditoa(next_uin));
	else
		last_crc = crc;

	gg_pubdir50_seq_set(req, GG_SEQ_SEARCH);

	if (isonline())
	{
		gg_EnterCriticalSection(&sess_mutex, "SearchAdvanced", 52, "sess_mutex", 1);
		if (!gg_pubdir50(sess, req))
		{
			gg_LeaveCriticalSection(&sess_mutex, "SearchAdvanced", 52, 1, "sess_mutex", 1);
#ifdef DEBUGMODE
			debugLogA("SearchAdvanced(): ForkThread 15 GGPROTO::searchthread");
#endif
			ForkThread(&GGPROTO::searchthread, NULL);
			return (HWND)1;
		}
		gg_LeaveCriticalSection(&sess_mutex, "SearchAdvanced", 52, 2, "sess_mutex", 1);
	}
	debugLogA("SearchAdvanced(): Seq %d.", req->seq);
	gg_pubdir50_free(req);

	return (HWND)1;
}
Beispiel #23
0
DWORD CMraProto::MraMessage(BOOL bAddToQueue, MCONTACT hContact, DWORD dwAckType, DWORD dwFlags, const CMStringA &szEmail, const CMStringW &lpwszMessage, LPBYTE lpbMultiChatData, size_t dwMultiChatDataSize)
{
	debugLogA("Sending message: flags %08x, to '%S', message '%S'\n", dwFlags, szEmail, lpwszMessage);

	DWORD dwRet = 0;
	LPSTR lpszMessageConverted = (LPSTR)lpwszMessage.GetString();
	LPSTR lpszMessageRTF = NULL;
	size_t dwMessageConvertedSize = lpwszMessage.GetLength()*sizeof(WCHAR), dwMessageRTFSize = 0;

	if (MraIsMessageFlashAnimation(lpwszMessage))
		dwFlags |= MESSAGE_FLAG_FLASH;

	// pack auth message
	if (dwFlags & MESSAGE_FLAG_AUTHORIZE) {
		OutBuffer buf;
		buf.SetUL(2);
		buf.SetLPSW(_T(""));//***deb possible nick here
		buf.SetLPSW(lpwszMessage);
		lpszMessageConverted = mir_base64_encode(buf.Data(), (int)buf.Len());
		dwMessageConvertedSize = mir_strlen(lpszMessageConverted);
	}
	// messages with Flash
	else if (dwFlags & MESSAGE_FLAG_FLASH) {
		dwFlags |= MESSAGE_FLAG_RTF;

		CMStringA lpszBuf(mir_u2a(lpwszMessage));

		OutBuffer buf;
		buf.SetUL(4);
		buf.SetLPS(lpszBuf);// сообщение что у собеседника плохая версия :)
		buf.SetUL(4);
		buf.SetUL(getDword("RTFBackgroundColour", MRA_DEFAULT_RTF_BACKGROUND_COLOUR));
		buf.SetLPS(lpszBuf);// сам мульт ANSI
		buf.SetLPSW(lpwszMessage);// сам мульт UNICODE

		DWORD dwBufSize = DWORD(buf.Len() + 128);
		lpszBuf.Truncate(dwBufSize);
		if (compress2((LPBYTE)(LPCSTR)lpszBuf, &dwBufSize, buf.Data(), (int)buf.Len(), Z_BEST_COMPRESSION) == Z_OK) {
			lpszMessageRTF = mir_base64_encode((LPBYTE)(LPCSTR)lpszBuf, dwBufSize);
			dwMessageRTFSize = mir_strlen(lpszMessageRTF);
		}
	}
	// standart message
	else if ((dwFlags & (MESSAGE_FLAG_CONTACT | MESSAGE_FLAG_NOTIFY | MESSAGE_FLAG_SMS)) == 0) {
		// Only if message is simple text message or RTF or ALARM
		if (dwFlags & MESSAGE_FLAG_RTF) { // add RFT part
			CMStringA lpbRTFData; lpbRTFData.Truncate(lpwszMessage.GetLength() * 16 + 4096);
			if (!MraConvertToRTFW(lpwszMessage, lpbRTFData)) {
				DWORD dwBackColour = getDword("RTFBackgroundColour", MRA_DEFAULT_RTF_BACKGROUND_COLOUR);

				OutBuffer buf;
				buf.SetUL(2);
				buf.SetLPS(lpbRTFData);
				buf.SetUL(4);
				buf.SetUL(dwBackColour);

				DWORD dwRTFDataSize = lpbRTFData.GetLength();
				if (compress2((LPBYTE)(LPCSTR)lpbRTFData, &dwRTFDataSize, buf.Data(), (int)buf.Len(), Z_BEST_COMPRESSION) == Z_OK) {
					lpszMessageRTF = mir_base64_encode((LPBYTE)(LPCSTR)lpbRTFData, dwRTFDataSize);
					dwMessageRTFSize = mir_strlen(lpszMessageRTF);
				}
			}
		}
	}

	if (lpszMessageRTF == NULL || dwMessageRTFSize == 0) dwFlags &= ~(MESSAGE_FLAG_RTF | MESSAGE_FLAG_FLASH);
	if (lpbMultiChatData == NULL || dwMultiChatDataSize == 0) dwFlags &= ~MESSAGE_FLAG_MULTICHAT;

	OutBuffer buf;
	buf.SetUL(dwFlags);
	buf.SetLPSLowerCase(szEmail);
	buf.SetLPS(CMStringA(lpszMessageConverted, (int)dwMessageConvertedSize));
	buf.SetLPS(lpszMessageRTF);
	if (dwFlags & MESSAGE_FLAG_MULTICHAT)
		buf.SetLPS(CMStringA((LPSTR)lpbMultiChatData, (int)dwMultiChatDataSize));

	if (bAddToQueue)
		dwRet = MraSendQueueCMD(hSendQueueHandle, 0, hContact, dwAckType, NULL, 0, MRIM_CS_MESSAGE, buf.Data(), buf.Len());
	else
		dwRet = MraSendCMD(MRIM_CS_MESSAGE, buf.Data(), buf.Len());

	return dwRet;
}
Beispiel #24
0
	void SetLPSLowerCase(const CMStringA &str)
	{
		SetUL(str.GetLength());
		BuffToLowerCase((LPSTR)Allocate(str.GetLength()), str, str.GetLength());
	}
Beispiel #25
0
	void SetLPS(const CMStringA &str)
	{
		SetUL(str.GetLength());
		memcpy(Allocate(str.GetLength()), str, str.GetLength());
	}