Ejemplo n.º 1
0
INT_PTR CIrcProto::DoEvent(int iEvent, const TCHAR* pszWindow, const TCHAR* pszNick, 
			const TCHAR* pszText, const TCHAR* pszStatus, const TCHAR* pszUserInfo, 
			DWORD_PTR dwItemData, bool bAddToLog, bool bIsMe, time_t timestamp)
{						   
	GCDEST gcd = {0};
	GCEVENT gce = {0};
	CMString sID;
	CMString sText = _T("");

	if ( iEvent == GC_EVENT_INFORMATION && bIsMe && !bEcho )
		return false;

	if ( pszText ) {
		if (iEvent != GC_EVENT_SENDMESSAGE)
			sText = DoColorCodes(pszText, FALSE, TRUE);
		else
			sText = pszText;
	}

	if ( pszWindow ) {
		if ( lstrcmpi( pszWindow, SERVERWINDOW))
			sID = pszWindow + (CMString)_T(" - ") + m_info.sNetwork;
		else
			sID = pszWindow;
		gcd.ptszID = (TCHAR*)sID.c_str();
	}
	else gcd.ptszID = NULL;

	gcd.pszModule = m_szModuleName;
	gcd.iType = iEvent;

	gce.cbSize = sizeof(GCEVENT);
	gce.pDest = &gcd;
	gce.ptszStatus = pszStatus;
	gce.dwFlags = GC_TCHAR + ((bAddToLog) ? GCEF_ADDTOLOG : 0);
	gce.ptszNick = pszNick;
	gce.ptszUID = pszNick;
	if (iEvent == GC_EVENT_TOPIC)
	  gce.ptszUserInfo = pszUserInfo;
	else
	  gce.ptszUserInfo = m_showAddresses ? pszUserInfo : NULL;

	if ( !sText.IsEmpty() )
		gce.ptszText = sText.c_str();

	gce.dwItemData = dwItemData;
	if(timestamp == 1)
		gce.time = time(NULL);
	else
		gce.time = timestamp;
	gce.bIsMe = bIsMe;
	return CallChatEvent((WPARAM)0, (LPARAM)&gce);
}
Ejemplo n.º 2
0
CMString& __stdcall ReplaceString ( CMString& text, const TCHAR* replaceme, const TCHAR* newword)
{
	if ( !text.IsEmpty() && replaceme != NULL) {
		int i = 0;
		while (( i = text.Find(replaceme, i)) != -1 ) {
			text.Delete(i,lstrlen(replaceme));
			text.Insert(i, newword);
			i = i + lstrlen(newword);
	}	}

	return text;
}
Ejemplo n.º 3
0
void SmileyCategoryListType::SaveSettings(void)
{
	CMString catstr;
	for (int i = 0; i < m_SmileyCategories.getCount(); i++) {
		m_SmileyCategories[i].SaveSettings();
		if (m_SmileyCategories[i].IsCustom()) {
			if (!catstr.IsEmpty()) catstr += '#';
			catstr += m_SmileyCategories[i].GetName();
		}
	}
	opt.WriteCustomCategories(catstr);
}
Ejemplo n.º 4
0
void CVkProto::RetrieveStatusMusic(const CMString &StatusMsg)
{
	debugLogA("CVkProto::RetrieveStatusMusic");
	if (!IsOnline() || m_iStatus == ID_STATUS_INVISIBLE || m_vkOptions.iMusicSendMetod == MusicSendMetod::sendNone)
		return;

	CMString code;
	CMString tszOldStatusMsg(db_get_tsa(0, m_szModuleName, "OldStatusMsg"));
	if (StatusMsg.IsEmpty()) {
		if (m_vkOptions.iMusicSendMetod == MusicSendMetod::sendBroadcastOnly)
			code = "API.audio.setBroadcast();return null;";
		else {
			CMString codeformat("API.status.set({text:\"%s\"});return null;");
			code.AppendFormat(codeformat, tszOldStatusMsg);
		}
		m_bSetBroadcast = false;
	}
	else {
		if (m_vkOptions.iMusicSendMetod == MusicSendMetod::sendBroadcastOnly) {
			CMString codeformat("var StatusMsg=\"%s\";var CntLmt=100;var OldMsg=API.status.get();"
				"var Tracks=API.audio.search({\"q\":StatusMsg,\"count\":CntLmt,\"search_own\":1});"
				"var Cnt=Tracks.count;if(Cnt>CntLmt){Cnt=CntLmt;}"
				"if(Cnt==0){API.audio.setBroadcast();}"
				"else{var i=0;var j=0;var Track=\" \";"
				"while(i<Cnt){Track=Tracks.items[i].artist+\" - \"+Tracks.items[i].title;if(Track==StatusMsg){j=i;}i=i+1;}"
				"Track=Tracks.items[j].owner_id+\"_\"+Tracks.items[j].id;API.audio.setBroadcast({\"audio\":Track});"
				"};return OldMsg;");
			code.AppendFormat(codeformat, StatusMsg);
		}
		else if (m_vkOptions.iMusicSendMetod == MusicSendMetod::sendStatusOnly) {
			CMString codeformat("var StatusMsg=\"&#9835; %s\";var OldMsg=API.status.get();"
				"API.status.set({\"text\":StatusMsg});"
				"return OldMsg;");
			code.AppendFormat(codeformat, StatusMsg);
		}
		else if (m_vkOptions.iMusicSendMetod == MusicSendMetod::sendBroadcastAndStatus) {
			CMString codeformat("var StatusMsg=\"%s\";var CntLmt=100;var Track=\" \";var OldMsg=API.status.get();"
				"var Tracks=API.audio.search({\"q\":StatusMsg,\"count\":CntLmt,\"search_own\":1});"
				"var Cnt=Tracks.count;if(Cnt>CntLmt){Cnt=CntLmt;}"
				"if(Cnt==0){Track=\"&#9835; \"+StatusMsg;API.status.set({\"text\":Track});}"
				"else{var i=0;var j=-1;"
				"while(i<Cnt){Track=Tracks.items[i].artist+\" - \"+Tracks.items[i].title;if(Track==StatusMsg){j=i;}i=i+1;}"
				"if(j==-1){Track=\"&#9835; \"+StatusMsg;API.status.set({\"text\":Track});}else{"
				"Track=Tracks.items[j].owner_id+\"_\"+Tracks.items[j].id;};API.audio.setBroadcast({\"audio\":Track});"
				"};return OldMsg;");
			code.AppendFormat(codeformat, StatusMsg);
		}
		m_bSetBroadcast = true;
	}
	Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveStatus)
		<< TCHAR_PARAM("code", code));
}
Ejemplo n.º 5
0
CVKNewsItem* CVkProto::GetVkNotificationsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers)
{
    debugLogA("CVkProto::GetVkNotificationsItem");
    if (!jnItem)
        return NULL;

    CMString tszType(jnItem["type"].as_mstring());
    VKObjType vkFeedbackType = vkNull, vkParentType = vkNull;
    CMString tszNotificationTranslate = SpanVKNotificationType(tszType, vkFeedbackType, vkParentType);

    const JSONNode &jnFeedback = jnItem["feedback"];
    const JSONNode &jnParent = jnItem["parent"];

    if (!jnFeedback || !jnParent)
        return NULL;

    CVkUserInfo *vkUser = NULL;
    CMString tszFeedback = GetVkFeedback(jnFeedback, vkFeedbackType, vkUsers, vkUser);
    CVKNewsItem* vkNotification = GetVkParent(jnParent, vkParentType);

    if (!vkNotification)
        return NULL;

    if (vkNotification && !tszFeedback.IsEmpty()) {
        CMString tszNotificaton;
        tszNotificaton.AppendFormat(tszFeedback, tszNotificationTranslate, vkNotification->tszText);
        vkNotification->tszText = tszNotificaton;

        tszFeedback = RemoveBBC(tszFeedback);
        int idx = tszFeedback.Find(_T(" %s %s"));

        vkNotification->tszPopupTitle.AppendFormat(_T("%s %s"), tszFeedback.Mid(0, idx), tszNotificationTranslate);
        if (tszFeedback.GetLength() > idx + 7) {
            if (!vkNotification->tszPopupText.IsEmpty())
                vkNotification->tszPopupText += _T("\n>> ");
            vkNotification->tszPopupText += tszFeedback.Mid(idx + 7, tszFeedback.GetLength() - idx - 7);
        }

        vkNotification->tszType = tszType;
        vkNotification->tDate = jnItem["date"].as_int();
        vkNotification->vkFeedbackType = vkFeedbackType;
        vkNotification->vkParentType = vkParentType;
        vkNotification->vkUser = vkUser;
        return vkNotification;
    }

    delete vkNotification;
    return NULL;
}
Ejemplo n.º 6
0
CMString CVkProto::GetVkFeedback(const JSONNode &jnFeedback, VKObjType vkFeedbackType, OBJLIST<CVkUserInfo> &vkUsers, CVkUserInfo *vkUser)
{
	debugLogA("CVkProto::GetVkFeedback");
	CMString tszRes;
	if (!jnFeedback || !vkFeedbackType)
		return tszRes;

	CMString tszFormat;
	LONG iUserId = 0;

	if (vkFeedbackType == vkComment) {
		iUserId = jnFeedback["from_id"].as_int();
		tszFormat = _T("%s %%s %%s\n%s");		
	}
	else if (vkFeedbackType == vkPost) {		
		iUserId = jnFeedback["owner_id "].as_int();
		tszFormat = _T("%s %%s %%s\n%s");		
	}
	else if (vkFeedbackType == VKObjType::vkUsers || vkFeedbackType == vkCopy) {
		const JSONNode &jnUsers = jnFeedback["items"];
		
		CMString tszUsers;
		for (auto it = jnUsers.begin(); it != jnUsers.end(); ++it) {
			const JSONNode &jnUserItem = (*it);
			if (!jnUserItem["from_id"])
				continue;
			iUserId = jnUserItem["from_id"].as_int();			
			vkUser = GetVkUserInfo(iUserId, vkUsers);
			if (!tszUsers.IsEmpty())
				tszUsers += _T(", ");
			tszUsers += SetBBCString(vkUser->m_tszUserNick, m_iBBCForNews, vkbbcUrl, vkUser->m_tszLink);
		}
		tszRes.AppendFormat(_T("%s %%s %%s"), tszUsers);
		vkUser = NULL;
		iUserId = 0;
	}

	if (iUserId) {
		vkUser = GetVkUserInfo(iUserId, vkUsers);
		CMString tszText(jnFeedback["text"].as_mstring());
		tszText.Replace(_T("%"), _T("%%"));
		tszRes.AppendFormat(tszFormat, SetBBCString(vkUser->m_tszUserNick, m_iBBCForNews, vkbbcUrl, vkUser->m_tszLink), ClearFormatNick(tszText));
	}

	return tszRes;
}
Ejemplo n.º 7
0
void CVkProto::AddFeedEvent(CMString& tszBody, time_t tTime)
{
	if (tszBody.IsEmpty()) {
		debugLogA("CVkProto::AddFeedEvent %d", tTime);
		return;
	}
	
	MCONTACT hContact = FindUser(VK_FEED_USER, true);
	T2Utf pszBody(tszBody);

	PROTORECVEVENT recv = { 0 };
	recv.timestamp = tTime;
	recv.szMessage = pszBody;
	recv.lParam = 0;
	recv.pCustomData = NULL;
	recv.cbCustomDataSize = 0;
	ProtoChainRecvMsg(hContact, &recv);
}
Ejemplo n.º 8
0
void CSkypeProto::UpdateProfileBirthday(const JSONNode &root, MCONTACT hContact)
{
	CMString birthday = root["birthday"].as_mstring();
	if (!birthday.IsEmpty() && birthday != "null")
	{
		int d, m, y;
		_stscanf(birthday.GetBuffer(), _T("%d-%d-%d"), &y, &m, &d);
		setWord(hContact, "BirthYear", y);
		setByte(hContact, "BirthDay", d);
		setByte(hContact, "BirthMonth", m);
	}
	else
	{
		delSetting(hContact, "BirthYear");
		delSetting(hContact, "BirthDay");
		delSetting(hContact, "BirthMonth");
	}
}
Ejemplo n.º 9
0
void CJabberProto::UpdateMirVer(MCONTACT hContact, pResourceStatus &resource)
{
	CMString tszMirVer;
	FormatMirVer(resource, tszMirVer);
	if (!tszMirVer.IsEmpty())
		setTString(hContact, "MirVer", tszMirVer);

	ptrT jid( getTStringA(hContact, "jid"));
	if (jid == NULL)
		return;

	TCHAR szFullJid[JABBER_MAX_JID_LEN];
	if (resource->m_tszResourceName && !_tcschr(jid, '/'))
		mir_sntprintf(szFullJid, SIZEOF(szFullJid), _T("%s/%s"), jid, resource->m_tszResourceName);
	else
		lstrcpyn(szFullJid, jid, SIZEOF(szFullJid));
	setTString(hContact, DBSETTING_DISPLAY_UID, szFullJid);
}
Ejemplo n.º 10
0
void CVkProto::SetAvatarUrl(MCONTACT hContact, CMString &tszUrl)
{
	CMString oldUrl(getTStringA(hContact, "AvatarUrl"));

	if (tszUrl == oldUrl)
		return;

	if (tszUrl.IsEmpty()) {
		delSetting(hContact, "AvatarUrl");
		ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, NULL);
	}
	else {
		setTString(hContact, "AvatarUrl", tszUrl);
		setByte(hContact,"NeedNewAvatar", 1);
		PROTO_AVATAR_INFORMATION ai = { 0 };
		ai.hContact = hContact;
		GetAvatarFileName(ai.hContact, ai.filename, _countof(ai.filename));
		ai.format = ProtoGetAvatarFormat(ai.filename);
		ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, (HANDLE)&ai);
	}
}
Ejemplo n.º 11
0
CVKNewsItem* CVkProto::GetVkNotificationsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers)
{
	debugLogA("CVkProto::GetVkNotificationsItem");
	if (!jnItem)
		return NULL;

	CMString tszType(jnItem["type"].as_mstring());
	VKObjType vkFeedbackType = vkNull, vkParentType = vkNull;
	CMString tszNotificationTranslate = SpanVKNotificationType(tszType, vkFeedbackType, vkParentType);
		
	const JSONNode &jnFeedback = jnItem["feedback"];
	const JSONNode &jnParent = jnItem["parent"];
	
	if (!jnFeedback || !jnParent)
		return NULL;

	CVkUserInfo *vkUser = NULL;
	CMString tszFeedback = GetVkFeedback(jnFeedback, vkFeedbackType, vkUsers, vkUser);
	CVKNewsItem* vkNotification = GetVkParent(jnParent, vkParentType);

	if (!vkNotification)
		return NULL;
	
	if (vkNotification && !tszFeedback.IsEmpty()) {
		CMString tszNotificaton;
		tszNotificaton.AppendFormat(tszFeedback, tszNotificationTranslate, vkNotification->tszText);
		vkNotification->tszText = tszNotificaton;
		vkNotification->tszType = tszType;
		vkNotification->tDate = jnItem["date"].as_int();
		vkNotification->vkFeedbackType = vkFeedbackType;
		vkNotification->vkParentType = vkParentType;
		vkNotification->vkUser = vkUser;
		return vkNotification;
	}
	
	delete vkNotification;
	return NULL;
}
Ejemplo n.º 12
0
bool SmileyPackType::LoadSmileyFileMSL(CMString &tbuf, bool onlyInfo, CMString &modpath)
{
	CMString pathstr, packstr;
	{
		_TPattern *pathsplit = _TPattern::compile(_T("(.*\\\\)(.*)\\.|$"));
		_TMatcher *m0 = pathsplit->createTMatcher(modpath);
		m0->findFirstMatch();
		pathstr = m0->getGroup(1);
		packstr = m0->getGroup(2);
		delete m0;
		delete pathsplit;
	}
	{
		_TPattern *otherf = _TPattern::compile(
			_T("^\\s*(Name|Author|Date|Version|ButtonSmiley)\\s*=\\s*\"(.*)\""),
			_TPattern::MULTILINE_MATCHING);

		_TMatcher *m0 = otherf->createTMatcher(tbuf);
		while (m0->findNextMatch()) {
			if (m0->getGroup(1) == _T("Name")) m_Name = m0->getGroup(2);
			if (m0->getGroup(1) == _T("Author")) m_Author = m0->getGroup(2);
			if (m0->getGroup(1) == _T("Date")) m_Date = m0->getGroup(2);
			if (m0->getGroup(1) == _T("Version")) m_Version = m0->getGroup(2);
			if (m0->getGroup(1) == _T("ButtonSmiley")) m_ButtonSmiley = m0->getGroup(2);
		}
		delete m0;
		delete otherf;
	}

	if (!onlyInfo) {
		selec.x = selec.y = win.x = win.y = 0;
		{
			_TPattern *pat = _TPattern::compile(
				_T("^\\s*(Selection|Window)Size\\s*=\\s*(\\d+)\\s*,\\s*(\\d+)"),
				_TPattern::MULTILINE_MATCHING);
			_TMatcher *m0 = pat->createTMatcher(tbuf);
			while (m0->findNextMatch()) {
				POINT tpt;
				tpt.x = _ttol(m0->getGroup(2).c_str());
				tpt.y = _ttol(m0->getGroup(3).c_str());

				if (m0->getGroup(1) == _T("Selection"))
					selec = tpt;
				else if (m0->getGroup(1) == _T("Window"))
					win = tpt;
			}
			delete m0;
			delete pat;
		}

		_TPattern *smiley = _TPattern::compile(
			_T("^\\s*Smiley(\\*)?\\s*=")	// Is Hidden
			_T("(?:\\s*\"(.*)\")")			// Smiley file name
			_T("(?:[\\s,]+(\\-?\\d+))")		// Icon resource id
			_T("(?:[\\s,]+(R|S)?\"(.*?)\")")	// Trigger text
			_T("(?:[\\s,]+\"(.*?)\")?")		// Tooltip or insert text
			_T("(?:[\\s,]+\"(.*?)\")?"),		// Tooltip text
			_TPattern::MULTILINE_MATCHING);

		SmileyVectorType hiddenSmileys;
		unsigned smnum = 0;
		{
			_TMatcher *m0 = smiley->createTMatcher(tbuf);
			while (m0->findNextMatch()) {
				CMString resname = m0->getGroup(2);
				if (resname.Find(_T("http://")) != -1) {
					if (GetSmileyFile(resname, packstr))
						continue;
				}
				else if (!resname.IsEmpty())
					resname.Insert(0, pathstr);

				SmileyType *dat = new SmileyType;

				const int iconIndex = _ttol(m0->getGroup(3).c_str());

				dat->SetHidden(m0->getStartingIndex(1) >= 0);
				if (m0->getStartingIndex(4) >= 0) {
					dat->SetRegEx(m0->getGroup(4) == _T("R"));
					dat->SetService(m0->getGroup(4) == _T("S"));
				}
				dat->m_TriggerText = m0->getGroup(5);
				if (dat->IsRegEx()) {
					if (m0->getStartingIndex(6) >= 0)
						ReplaceAllSpecials(m0->getGroup(6), dat->m_InsertText);

					if (m0->getStartingIndex(7) >= 0)
						ReplaceAllSpecials(m0->getGroup(7), dat->m_ToolText);
					else
						dat->m_ToolText = dat->m_InsertText;
				}
				else {
					if (m0->getStartingIndex(6) >= 0)
						ReplaceAllSpecials(m0->getGroup(6), dat->m_ToolText);
					else
						ReplaceAllSpecials(dat->m_TriggerText, dat->m_ToolText);
				}

				bool noerr;
				if (resname.IsEmpty()) {
					dat->SetHidden(true);
					dat->SetText(true);
					noerr = true;
				}
				else noerr = dat->LoadFromResource(resname, iconIndex);

				if (dat->IsHidden())
					hiddenSmileys.insert(dat);
				else
					m_SmileyList.insert(dat);

				if (!noerr) {
					static const TCHAR errmsg[] = LPGENT("Smiley #%u in file %s for smiley pack %s not found.");
					TCHAR msgtxt[1024];
					mir_sntprintf(msgtxt, TranslateTS(errmsg), smnum, resname.c_str(), modpath.c_str());
					CallService(MS_NETLIB_LOG, (WPARAM)hNetlibUser, _T2A(msgtxt));
					errorFound = true;
				}
				smnum++;
			}
			delete smiley;
			delete m0;
		}

		m_VisibleCount = m_SmileyList.getCount();

		m_SmileyList.splice(hiddenSmileys);

		AddTriggersToSmileyLookup();
	}

	return true;
}
Ejemplo n.º 13
0
bool SmileyPackType::LoadSmileyFile(const CMString& filename, const CMString& packname, bool onlyInfo, bool noerr)
{
	Clear();

	if (filename.IsEmpty()) {
		m_Name = _T("Nothing loaded");
		return false;
	}

	CMString modpath;
	pathToAbsolute(filename, modpath);

	// Load xep file
	int fh = _topen(modpath.c_str(), _O_BINARY | _O_RDONLY);
	if (fh == -1) {
		if (!noerr) {
			static const TCHAR errmsg[] = LPGENT("Smiley pack %s for category \"%s\" not found.\nSelect correct smiley pack in the Options -> Customize -> Smileys.");
			TCHAR msgtxt[1024];
			mir_sntprintf(msgtxt, TranslateTS(errmsg), modpath.c_str(), packname);
			ReportError(msgtxt);
		}

		m_Name = _T("Nothing loaded");
		return false;
	}

	m_Filename = filename;

	// Find file size
	const long flen = _filelength(fh);

	// Allocate file buffer
	char* buf = new char[flen + sizeof(wchar_t)];

	// Read xep file in
	int len = _read(fh, buf, flen);
	*(wchar_t*)(buf + len) = 0;

	// Close file
	_close(fh);

	CMString tbuf;

	if (len > 2 && *(wchar_t*)buf == 0xfeff)
		tbuf = W2T_SM((wchar_t*)buf + 1);
	else if (len > 3 && buf[0] == '\xef' && buf[1] == '\xbb' && buf[2] == '\xbf')
		tbuf = W2T_SM(A2W_SM(buf + 3, CP_UTF8));
	else
		tbuf = A2T_SM(buf);

	delete[] buf;

	bool res;
	if (filename.Find(_T(".xep")) == -1)
		res = LoadSmileyFileMSL(tbuf, onlyInfo, modpath);
	else
		res = LoadSmileyFileXEP(tbuf, onlyInfo, modpath);

	if (errorFound)
		ReportError(TranslateT("There were problems loading smiley pack (it should be corrected).\nSee network log for details."));

	return res;
}
Ejemplo n.º 14
0
void CVkProto::OnReciveUpload(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_FILE_NOT_UPLOADED);
		return;
	}

	JSONNode jnRoot;
	CheckJsonResponse(pReq, reply, jnRoot);

	if (pReq->m_iErrorCode) {
		SendFileFiled(fup, pReq->m_iErrorCode);
		return;
	}

	if ((!jnRoot["server"] || !jnRoot["hash"]) && !jnRoot["file"]) {
		SendFileFiled(fup, VKERR_INVALID_PARAMETERS);
		return;
	}

	CMString server(jnRoot["server"].as_mstring());
	CMString hash(jnRoot["hash"].as_mstring());
	CMString upload;

	AsyncHttpRequest *pUploadReq;

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

	switch (fup->GetType()) {
	case CVkFileUploadParam::typeImg:
		upload = jnRoot["photo"].as_mstring();
		if (upload == _T("[]")) {
			SendFileFiled(fup, VKERR_INVALID_PARAMETERS);
			return;
		}
		pUploadReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/photos.saveMessagesPhoto.json", true, &CVkProto::OnReciveUploadFile)
			<< TCHAR_PARAM("server", server)
			<< TCHAR_PARAM("photo", upload)
			<< TCHAR_PARAM("hash", hash)
			<< VER_API;
		break;
	case CVkFileUploadParam::typeAudio:
		upload = jnRoot["audio"].as_mstring();
		if (upload == _T("[]")) {
			SendFileFiled(fup, VKERR_INVALID_PARAMETERS);
			return;
		}
		pUploadReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/audio.save.json", true, &CVkProto::OnReciveUploadFile)
			<< TCHAR_PARAM("server", server)
			<< TCHAR_PARAM("audio", upload)
			<< TCHAR_PARAM("hash", hash)
			<< VER_API;
		break;
	case CVkFileUploadParam::typeDoc:
		upload = jnRoot["file"].as_mstring();
		if (upload.IsEmpty()) {
			SendFileFiled(fup, VKERR_INVALID_PARAMETERS);
			return;
		}
		pUploadReq = new AsyncHttpRequest(this, REQUEST_GET, "/method/docs.save.json", true, &CVkProto::OnReciveUploadFile)
			<< CHAR_PARAM("title", fup->fileName())
			<< TCHAR_PARAM("file", upload)	
			<< VER_API;
		break;
	default:
		SendFileFiled(fup, VKERR_FTYPE_NOT_SUPPORTED);
		return;
	}

	pUploadReq->pUserInfo = pReq->pUserInfo;
	Push(pUploadReq);
}
Ejemplo n.º 15
0
int CSkypeProto::OnGroupChatEventHook(WPARAM, LPARAM lParam)
{
	GCHOOK *gch = (GCHOOK*)lParam;
	if (!gch)
	{
		return 1;
	}
	else if (mir_strcmp(gch->pDest->pszModule, m_szModuleName) != 0)
	{
		return 0;
	}

	ptrA chat_id(mir_t2a(gch->pDest->ptszID));

	switch (gch->pDest->iType)
	{
	case GC_USER_MESSAGE:
	{
		OnSendChatMessage(gch->pDest->ptszID, gch->ptszText);
		break;
	}

	case GC_USER_PRIVMESS:
	{
		MCONTACT hContact = FindContact(_T2A(gch->ptszUID));
		if (hContact == NULL)
		{
			hContact = AddContact(_T2A(gch->ptszUID), true);
			setWord(hContact, "Status", ID_STATUS_ONLINE);
			db_set_b(hContact, "CList", "Hidden", 1);
			setTString(hContact, "Nick", gch->ptszUID);
			db_set_dw(hContact, "Ignore", "Mask1", 0);
		}
		CallService(MS_MSG_SENDMESSAGET, hContact, 0);
		break;
	}

	case GC_USER_LOGMENU:
	{
		switch (gch->dwData)
		{
		case 10: {
			CSkypeInviteDlg dlg(this);
			if(!dlg.DoModal())
			{
				break;
			}
			MCONTACT hContact = dlg.m_hContact;
			if (hContact != NULL)
			{
				ptrA username(db_get_sa(hContact, m_szModuleName, SKYPE_SETTINGS_ID));
				SendRequest(new InviteUserToChatRequest(m_szRegToken, chat_id, username, "User", m_szServer));
			}
			break;
		}
		case 20:
			OnLeaveChatRoom(FindChatRoom(chat_id), NULL);
			break;
		case 30:
			CMString newTopic = ChangeTopicForm();
			if (!newTopic.IsEmpty())
				SendRequest(new SetChatPropertiesRequest(m_szRegToken, chat_id, "topic", ptrA(mir_utf8encodeT(newTopic.GetBuffer())), m_szServer));
			break;
		}
		break;
	}

	case GC_USER_NICKLISTMENU:
	{
		ptrA user_id;
		if (gch->dwData == 10 || gch->dwData == 30 || gch->dwData == 40)
		{
			user_id = mir_t2a_cp(gch->ptszUID, CP_UTF8);
		}

		switch (gch->dwData)
		{
		case 10:
			SendRequest(new KickUserRequest(m_szRegToken, chat_id, user_id, m_szServer));
			break;
		case 30:
			SendRequest(new InviteUserToChatRequest(m_szRegToken, chat_id, user_id, "Admin", m_szServer));
			break;
		case 40:
			SendRequest(new InviteUserToChatRequest(m_szRegToken, chat_id, user_id, "User", m_szServer));
			break;
		}

		break;

	}
	}
	return 0;
}
Ejemplo n.º 16
0
void CMSocketC::Connect(const CMString& sHost, UINT16 nPort)
{
    //网络接入连接检查
    CMNetConnMgr& mgr = CMNetConnMgr::Instance();

    if (mgr.CurrentType() == CMNetConnMgr::NONE)
    {
        //未接入,开始接入
        m_cTimer.SetTimerID(1); //使用TimerID来记重复次数
        m_cTimer.Set(3*1000);   //3秒检查
        m_sHost = sHost;
        m_nPort = nPort;
        m_cTimer.Start();
        return;
    }

    if (m_status != NOTCONNECTED)
    {//当前已有连接
//       if (m_sHost == sHost && m_nPort == nPort)
//        {
//            //新连接于原始连接相同,重用
//            if (m_status == CONNECTED)
//            {//取消现有操作
//				CM_ERR("CMSocketC::Connect connect reserved");
//                m_status = CONNECTED;
//                m_pNotify->OnConnect(MER_OK);
//                return;
//            }
//            CM_ERR("CMSocketC::Connect cancel!");
//            Cancel();
			
//       }
       // else
        {
            //关闭连接
            Close();
        }
    }

    CMString sTmp;
    if (!CMUrl::IsIP(sHost))
    {
        CM_LOGP(CM_LOGL_DEBUG, "CMSocketC::Connect HostNameToIP %s", (const CHAR*)(CMString)sHost);        
        sTmp = mgr.HostNameToIP(sHost);
        if (sTmp.IsEmpty())
        {
            CM_ERRP("Host %s can't to addr", (const CHAR*)(CMString)sHost);
            m_pNotify->OnConnect(MERN_WRONG_PARAM);
            return;
        }
    }
    else
    {
        sTmp = sHost;
    }
    TInetAddr addr;
    TBuf<20> buf;
    buf = (const UINT16*)((const WCHAR*)(sTmp));
    addr.SetPort(nPort);
    INT32 nErr = addr.Input(buf);
    if (nErr != KErrNone)
    {
        m_pNotify->OnConnect(MERN_WRONG_PARAM);
        return;
    }
    
    CM_LOGP(CM_LOGL_DEBUG, "CMSocketC::Connect Open start ip %s, port %d", (const CHAR*)sTmp, nPort);
    nErr = m_sk.Open(mgr.SocketServer(), KAfInet, KSockStream, KProtocolInetTcp
//#if !defined(__WINSCW__)
            , mgr.Connection());
//#else
//            );
//#endif
    
    if (nErr != KErrNone && nErr != KErrAlreadyExists)
    {
        m_pNotify->OnConnect(MERN_INITIALIZE);
        return;            
    }
    
//    iStatus = KErrNone;
    m_sk.Connect(addr, iStatus);
    m_status = CONNECTING;
    m_sHost = sHost;
    m_nPort = nPort;
    m_cTimer.Stop();
    m_cTimer.Set(60 * 1000); //超时默认60秒
    m_cTimer.Start();
    SetActive();
    return;
}
Ejemplo n.º 17
0
void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
	debugLogA("CVkProto::OnReceiveFriends %d", reply->resultCode);
	if (reply->resultCode != 200)
		return;

	JSONROOT pRoot;
	JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot), *pInfo;
	if (pResponse == NULL)
		return;

	bool bCleanContacts = getByte("AutoClean", 0) != 0;
	LIST<void> arContacts(10, PtrKeySortT);
	if (bCleanContacts)
		for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
			if (!isChatRoom(hContact))
				arContacts.insert((HANDLE)hContact);

	for (int i = 0; (pInfo = json_at(pResponse, i)) != NULL; i++) {
		ptrT szValue(json_as_string(json_get(pInfo, "uid")));
		if (szValue == NULL)
			continue;

		CMString tszNick;
		MCONTACT hContact = FindUser(_ttoi(szValue), true);
		arContacts.remove((HANDLE)hContact);
		szValue = json_as_string(json_get(pInfo, "first_name"));
		if (szValue) {
			setTString(hContact, "FirstName", szValue);

			tszNick.Append(szValue);
			tszNick.AppendChar(' ');
		}

		if (szValue = json_as_string(json_get(pInfo, "last_name"))) {
			setTString(hContact, "LastName", szValue);
			tszNick.Append(szValue);
		}

		if (!tszNick.IsEmpty())
			setTString(hContact, "Nick", tszNick);

		szValue = json_as_string(json_get(pInfo, "photo_medium"));
		SetAvatarUrl(hContact, szValue);

		setWord(hContact, "Status", (json_as_int(json_get(pInfo, "online")) == 0) ? ID_STATUS_OFFLINE : ID_STATUS_ONLINE);

		int iValue = json_as_int(json_get(pInfo, "sex"));
		if (iValue)
			setByte(hContact, "Gender", (iValue == 2) ? 'M' : 'F');

		if ((iValue = json_as_int(json_get(pInfo, "timezone"))) != 0)
			setByte(hContact, "Timezone", iValue * -2);

		szValue = json_as_string(json_get(pInfo, "mobile_phone"));
		if (szValue && *szValue)
			setTString(hContact, "Cellular", szValue);
		szValue = json_as_string(json_get(pInfo, "home_phone"));
		if (szValue && *szValue)
			setTString(hContact, "Phone", szValue);
	}

	if (bCleanContacts)
		for (int i = 0; i < arContacts.getCount(); i++)
			CallService(MS_DB_CONTACT_DELETE, (WPARAM)arContacts[i], 0);
}
Ejemplo n.º 18
0
void CMHttpSNotify::OnResponse(UINT32 nCode, const CMHTTPRspHeader* pRespHeader)
{
    UINT32 nRet = MER_OK;
    if (nCode == MER_OK)
    {
        ASSERT(pRespHeader != NULL);

        UINT32 httpRet = pRespHeader->GetHttpReturn();

        if (httpRet == 200 || httpRet == 206)
        {
            CMString sVal;

            //判断是否wap网关的无聊返回,如果是则继续请求一次
            if (pRespHeader->GetValue(HH_CTYPE, sVal))
            {
                if (sVal.Find(L"text/vnd.wap.wml") >= 0)
                {
                    m_pHttpC->Request();
                    return;
                }
            }            

            sVal.Empty();
            pRespHeader->GetValue(HH_CRANGE, sVal);

            sVal.Trim();

            CMHTTPRspHeader header;
            header.SetRet(200, CMString("OK"));
            header.AddValue(HH_CTYPE, L"application/x-shockwave-flash");

            if (!sVal.IsEmpty())
            {
                INT32 nPos1 = sVal.Find(L" ");
                INT32 nPos2 = sVal.Find(L"-");
                INT32 nPos3 = sVal.Find(L"/");
                if (nPos1 <= 0 || nPos2 <= 0 || nPos3 <= 0)
                {
                    CM_ERRP("CMHttpSNotify::OnResponse wrong content-range %s", (const CHAR*)sVal);
                    goto err;
                }

                m_nStart= _mwtoi((const WCHAR*)sVal.Mid(nPos1 + 1, nPos2 - nPos1 - 1));
                m_nEnd = _mwtoi((const WCHAR*)sVal.Mid(nPos2 + 1, nPos3 - nPos2 - 1));
                m_nSize = m_nEnd - m_nStart + 1;

                if (m_nTotalSize == 0)
                {
                    //对于第一次http返回,需要返回结果给socket
                    m_nTotalSize = _mwtoi((const WCHAR*)sVal.Mid(nPos3 + 1));
                    CMString sSendSize;
                    sSendSize.Format(L"%d", m_nTotalSize);
                    header.AddValue(HH_CLENGTH, sSendSize);
                    CMString sHeader = header.ToString();

                    CM_LOGP(CM_LOGL_INFO, "%s", (const CHAR*)sHeader);

                    m_pSocketC->Send((INT8*)(const CHAR*)sHeader, sHeader.GetLength());
                }
                else
                {
                    ASSERT(m_nTotalSize == _mwtoi((const WCHAR*)sVal.Mid(nPos3 + 1)));
                    ASSERT(m_nStatus == 2);
                    ASSERT(m_nEnd - m_nStart < REQ_SIZE);

                    UINT32 nLen = m_nSize;
                    if (m_nSize > BUF_SIZE)
                    {
                        nLen = BUF_SIZE;
                    }
                    m_pHttpC->Read(m_pBuf, nLen);
                }
            }
            else
            {
                if (!pRespHeader->GetValue(HH_CLENGTH, sVal))
                {
                    CM_ERR("CMHttpSNotify::OnResponse no content-length");
                    goto err;
                }

                m_nTotalSize = 0;  //此值无效
                m_nSize = _mwtoi(sVal);

                //获取响应头成功,返回结果到Socket处
                CMString sSendSize;
                sSendSize.Format(L"%d", m_nSize);
                header.AddValue(HH_CLENGTH, sSendSize);
                CMString sHeader = header.ToString();

                CM_LOGP(CM_LOGL_INFO, "%s", (const CHAR*)sHeader);

                m_pSocketC->Send((INT8*)(const CHAR*)sHeader, sHeader.GetLength());
            }
           
            return;
        }
        else
        {
            CM_ERRP("CMHttpSNotify::OnResponse http ret %d error", httpRet);
            nRet = httpRet;
        }
    }
    else
    {
        CM_ERRP("CMHttpSNotify::OnResponse ret %d error", nCode);
        nRet = nCode;
    }

err:
    //未成功获取信息,清理,等待下次获取
    //if (m_pBuf)
    //{
    //    delete m_pBuf;
    //    m_pBuf = NULL;
    //}

    m_bInService = FALSE;

    //if (nCode == MERN_TIMEOUT)
    //{
    //    m_pSocketC->Close();
    //}
    //else
    //{
        char response[] = "HTTP/1.1 404 NOT FOUND\r\n\r\n";
        m_nSize = 0;
        m_pSocketC->Send((INT8*)response, strlen(response));
    //}

    //重置http
    m_pHttpC->Cancel();
}
Ejemplo n.º 19
0
void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
	debugLogA("CVkProto::OnReceiveMessages %d", reply->resultCode);
	if (reply->resultCode != 200)
		return;

	JSONNode jnRoot;
	const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
	if (!jnResponse)
		return;
	if (!jnResponse["Msgs"])
		return;

	CMStringA mids;
	int numMessages = jnResponse["Msgs"]["count"].as_int();
	const JSONNode &jnMsgs = jnResponse["Msgs"]["items"];
	const JSONNode &jnFUsers = jnResponse["fwd_users"];

	debugLogA("CVkProto::OnReceiveMessages numMessages = %d", numMessages);

	for (auto it = jnMsgs.begin(); it != jnMsgs.end(); ++it) {
		const JSONNode &jnMsg = (*it);
		if (!jnMsg) {
			debugLogA("CVkProto::OnReceiveMessages pMsg == NULL");
			break;
		}

		UINT mid = jnMsg["id"].as_int();
		CMString tszBody(jnMsg["body"].as_mstring());
		int datetime = jnMsg["date"].as_int();
		int isOut = jnMsg["out"].as_int();
		int isRead = jnMsg["read_state"].as_int();
		int uid = jnMsg["user_id"].as_int();

		const JSONNode &jnFwdMessages = jnMsg["fwd_messages"];
		if (jnFwdMessages) {
			CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, jnFUsers, m_vkOptions.BBCForAttachments());
			if (!tszBody.IsEmpty())
				tszFwdMessages = _T("\n") + tszFwdMessages;
			tszBody +=  tszFwdMessages;
		}

		CMString tszAttachmentDescr;
		const JSONNode &jnAttachments = jnMsg["attachments"];
		if (jnAttachments) {
			tszAttachmentDescr = GetAttachmentDescr(jnAttachments, m_vkOptions.BBCForAttachments());
			if (!tszBody.IsEmpty())
				tszBody += _T("\n");
			tszBody += tszAttachmentDescr;
		}

		MCONTACT hContact = NULL;
		int chat_id = jnMsg["chat_id"].as_int();
		if (chat_id == 0)
			hContact = FindUser(uid, true);

		char szMid[40];
		_itoa(mid, szMid, 10);
		if (m_vkOptions.iMarkMessageReadOn == MarkMsgReadOn::markOnReceive || chat_id != 0) {
			if (!mids.IsEmpty())
				mids.AppendChar(',');
			mids.Append(szMid);
		}

		if (chat_id != 0) {
			debugLogA("CVkProto::OnReceiveMessages chat_id != 0");
			CMString action_chat = jnMsg["action"].as_mstring();
			int action_mid = _ttoi(jnMsg["action_mid"].as_mstring());
			if ((action_chat == "chat_kick_user") && (action_mid == m_myUserId))
				KickFromChat(chat_id, uid, jnMsg, jnFUsers);
			else {
				MCONTACT chatContact = FindChat(chat_id);
				if (chatContact && getBool(chatContact, "kicked", true))
					db_unset(chatContact, m_szModuleName, "kicked");
				AppendChatMessage(chat_id, jnMsg, jnFUsers, false);
			}
			continue;
		}

		PROTORECVEVENT recv = { 0 };
		bool bUseServerReadFlag = m_vkOptions.bSyncReadMessageStatusFromServer ? true : !m_vkOptions.bMesAsUnread;
		if (isRead && bUseServerReadFlag)
			recv.flags |= PREF_CREATEREAD;
		if (isOut)
			recv.flags |= PREF_SENT;
		else if (m_vkOptions.bUserForceInvisibleOnActivity && time(NULL) - datetime < 60 * m_vkOptions.iInvisibleInterval)
			SetInvisible(hContact);

		T2Utf pszBody(tszBody);
		recv.timestamp = m_vkOptions.bUseLocalTime ? time(NULL) : datetime;
		recv.szMessage = pszBody;
		recv.lParam = isOut;
		recv.pCustomData = szMid;
		recv.cbCustomDataSize = (int)mir_strlen(szMid);
		Sleep(100);

		debugLogA("CVkProto::OnReceiveMessages mid = %d, datetime = %d, isOut = %d, isRead = %d, uid = %d", mid, datetime, isOut, isRead, uid);

		if (!CheckMid(m_sendIds, mid)) {
			debugLogA("CVkProto::OnReceiveMessages ProtoChainRecvMsg");
			ProtoChainRecvMsg(hContact, &recv);
			if (mid > getDword(hContact, "lastmsgid", -1))
				setDword(hContact, "lastmsgid", mid);
			if (!isOut)
				m_incIds.insert((HANDLE)mid);
		}
		else if (m_vkOptions.bLoadSentAttachments && !tszAttachmentDescr.IsEmpty() && isOut) {
			T2Utf pszAttach(tszAttachmentDescr);
			recv.timestamp = time(NULL); // only local time
			recv.szMessage = pszAttach;
			ProtoChainRecvMsg(hContact, &recv);
		}
	}

	if (!mids.IsEmpty())
		MarkMessagesRead(mids);
}
Ejemplo n.º 20
0
void CMHttpSNotify::OnRecv(UINT32 nCode, INT32 nLen)
{
    if (nCode == MER_OK)
    {
        //是不是请求头
        INT32 nTmp = nLen;
        if (!m_cReqHeader.Parse(m_pHeadBuf, nTmp))
        {
            m_nHeadPos += nLen;
            if (nTmp == -1 && m_nHeadPos < REQ_HEAD_MAX_LEN)
            {
                //可能头还没收全,继续收
                CM_LOGP(CM_LOGL_DEBUG, "CMHttpSNotify::OnRecv header part %d",  nLen);
                m_pSocketC->Recv(m_pHeadBuf + m_nHeadPos , REQ_HEAD_MAX_LEN - m_nHeadPos);
                return;
            }
            CM_LOGP(CM_LOGL_DEBUG, "CMHttpSNotify::OnRecv header failed is %s", (const CHAR*)CMString((const CHAR*)m_pHeadBuf, nLen));
            return;
        }

        CMString sRange;
        m_cReqHeader.GetValue(HH_RANGER, sRange);

        //是外部请求,构造CMHttp请求
        m_rUrl = m_pHttpS->ToRemote(m_cReqHeader.GetUrl());
        if (!m_rUrl.Url().IsEmpty())
        {
            CMHTTPReqHeader header;
            header.CreateDefault();

            if (sRange.IsEmpty())
            {
				if(CMNetConnMgr::Instance().CurrentType() == CMNetConnMgr::CMWAP)
	            {
    	            sRange.Format(L"bytes = 0-%d", REQ_SIZE - 1);
                    header.AddValue(HH_RANGER, sRange);
	            }
	            else
                {
                    //请求没有指定range,不发送此参数	
                }
            }
            else
            {
                //暂时此流程不支持
                ASSERT(FALSE);
             //   if(CMGlobal::TheOne().NetConnMgr().CurrentType() == CMNetConnMgr::CMWAP)
	            //{
             //       //如果请求包含range信息,对于跨CMWAP网关也需要处理
             //       UINT32 nStart = 0;
             //       UINT32 nEnd = 0;

             //       INT32 nPos1 = sRange.Find(L"-");
             //       if (nPos1 > 0)
             //       {
             //           INT32 nPos2 = sRange.Find(L"=");
             //           nStart= _mwtoi((const WCHAR*)sRange.Mid(nPos2 + 2, nPos1 - nPos2 - 2));
             //           INT32 nLen = sRange.GetLength();
             //           if (nLen > nPos1 + 1)
             //           {
             //               nEnd = _mwtoi((const WCHAR*)sRange.Mid(nPos2 + 1, nLen - 1));
             //           }
             //       }

             //       if (nEnd != 0)
             //       {
             //           m_nSendSize = nEnd - nStart + 1;
             //       }
             //       else
             //       {
             //           m_nSendSize = m_pFile->GetLength() - nStart;
             //           nEnd = nStart + m_nSendSize - 1;
             //       }
             //   }
             //   else
             //       header.AddValue(HH_RANGER, sRange);
            }

            header.SetUrl(m_rUrl);
            m_pHttpC->Request(header);
            m_nStatus = 1;
            return;
        }

        //是本地文件请求,构造发送信息
        //const CMString* pFile = m_pHttpS->GetFile(m_cReqHeader.GetUrl());
        //if (pFile)
        //{
        //    if (!m_pFile)
        //    {
        //        m_pFile = new CMFile();
        //    }
        //    if (!m_pFile->Open(*pFile, CMFile::OPEN_R_EXIST, CMFile::SHARE_R))
        //    {
        //        //打开失败
        //        CM_ERRP("CMHttpSNotify::OnRecv Open file  %s not exist", (const CHAR*)CMString(*pFile));
        //        return;
        //    }

        //    UINT32 nStart = 0;
        //    UINT32 nEnd = 0;
        //    if (!sRange.IsEmpty())
        //    {
        //        INT32 nPos1 = sRange.Find(L"-");
        //        if (nPos1 > 0)
        //        {
        //            INT32 nPos2 = sRange.Find(L"=");
        //            nStart= _mwtoi((const WCHAR*)sRange.Mid(nPos2 + 2, nPos1 - nPos2 - 2));
        //            INT32 nLen = sRange.GetLength();
        //            if (nLen > nPos1 + 1)
        //            {
        //                nEnd = _mwtoi((const WCHAR*)sRange.Mid(nPos2 + 1, nLen - 1));
        //            }
        //        }
        //    }

        //    if (nStart != 0)
        //        m_pFile->Seek(nStart);
        //    if (nEnd != 0)
        //    {
        //        m_nSendSize = nEnd - nStart + 1;
        //    }
        //    else
        //    {
        //        m_nSendSize = m_pFile->GetLength() - nStart;
        //        nEnd = nStart + m_nSendSize - 1;
        //    }

        //    //获取成功,返回响应头结果到Socket处
        //    CMHTTPRspHeader resp;
        //    resp.SetRet(200, CMString("OK"));
        //    if (!sRange.IsEmpty())
        //    {
        //        //如果有range,就要返回range,  bytes 0-2668566/2668567
        //        CMString sSendRange;
        //        sSendRange.Format(L"bytes %d-%d/%d", nStart, nEnd, m_nSendSize);
        //        resp.AddValue(HH_CRANGE, sSendRange);
        //    }
        //    else
        //    {
        //        //否则返回content-lengthW
        //        CMString sSendSize;
        //        sSendSize.Format(L"%d", m_nSendSize);
        //        resp.AddValue(HH_CLENGTH, sSendSize);
        //    }
        //    resp.AddValue(HH_CTYPE, L"application/x-shockwave-flash");
        //    CMString sHeader = resp.ToString();
        //    CM_LOGP(CM_LOGL_DEBUG, "%s", (const CHAR*)sHeader);

        //    m_pSocketC->Send((const INT8*)(const CHAR*)sHeader, sHeader.GetLength());

        //    m_nStatus = 3;
        //    return;
        //}
    }
    else
    {
        CM_ERRP("CMHttpSNotify::OnRecv ret %d error", nCode);
    }
err:
    //未成功获取信息,清理,等待下次获取

    m_bInService = FALSE;
    m_nSize = 0;

    if (nCode == MERN_TIMEOUT)
    {
        m_pSocketC->Close();
    }
    else
    {
        char response[] = "HTTP/1.1 404 NOT FOUND\r\n\r\n";
        m_pSocketC->Send((INT8*)response, strlen(response));
    }

    //重置http
    m_pHttpC->Cancel();

}
Ejemplo n.º 21
0
INT_PTR __cdecl CIrcProto::Scripting_GetIrcData(WPARAM, LPARAM lparam)
{
	if (m_scriptingEnabled && lparam) {
		CMStringA sString = (char*)lparam, sRequest;
		CMString sOutput, sChannel;

		int i = sString.Find("|");
		if (i != -1) {
			sRequest = sString.Mid(0, i);
			TCHAR* p = mir_a2t(sString.Mid(i + 1));
			sChannel = p;
			mir_free(p);
		}
		else sRequest = sString;

		sRequest.MakeLower();

		if (sRequest == "ownnick" && IsConnected())
			sOutput = m_info.sNick;

		else if (sRequest == "network" && IsConnected())
			sOutput = m_info.sNetwork;

		else if (sRequest == "primarynick")
			sOutput = m_nick;

		else if (sRequest == "secondarynick")
			sOutput = m_alternativeNick;

		else if (sRequest == "myip")
			return (INT_PTR)mir_strdup(m_manualHost ? m_mySpecifiedHostIP :
			(m_IPFromServer) ? m_myHost : m_myLocalHost);

		else if (sRequest == "usercount" && !sChannel.IsEmpty()) {
			CMString S = MakeWndID(sChannel.c_str());
			GC_INFO gci = { 0 };
			gci.Flags = GCF_BYID | GCF_COUNT;
			gci.pszModule = m_szModuleName;
			gci.pszID = S.c_str();
			if (!CallServiceSync(MS_GC_GETINFO, 0, (LPARAM)&gci)) {
				TCHAR szTemp[40];
				mir_sntprintf(szTemp, _T("%u"), gci.iCount);
				sOutput = szTemp;
			}
		}
		else if (sRequest == "userlist" && !sChannel.IsEmpty()) {
			CMString S = MakeWndID(sChannel.c_str());
			GC_INFO gci = { 0 };
			gci.Flags = GCF_BYID | GCF_USERS;
			gci.pszModule = m_szModuleName;
			gci.pszID = S.c_str();
			if (!CallServiceSync(MS_GC_GETINFO, 0, (LPARAM)&gci))
				return (INT_PTR)mir_strdup(gci.pszUsers);
		}
		else if (sRequest == "channellist") {
			CMString S = _T("");
			int n = CallServiceSync(MS_GC_GETSESSIONCOUNT, 0, (LPARAM)m_szModuleName);
			if (n >= 0) {
				int j = 0;
				while (j < n) {
					GC_INFO gci = { 0 };
					gci.Flags = GCF_BYINDEX | GCF_ID;
					gci.pszModule = m_szModuleName;
					gci.iItem = j;
					if (!CallServiceSync(MS_GC_GETINFO, 0, (LPARAM)&gci)) {
						if (mir_tstrcmpi(gci.pszID, SERVERWINDOW)) {
							CMString S1 = gci.pszID;
							int k = S1.Find(_T(" "));
							if (k != -1)
								S1 = S1.Mid(0, k);
							S += S1 + _T(" ");
						}
					}
					j++;
				}
			}

			if (!S.IsEmpty())
				sOutput = (TCHAR*)S.c_str();
		}
		// send it to mbot
		if (!sOutput.IsEmpty())
			return (INT_PTR)mir_t2a(sOutput.c_str());
	}
	return 0;
}
Ejemplo n.º 22
0
TCHAR* fnTrayIconMakeTooltip(const TCHAR *szPrefix, const char *szProto)
{
	initcheck NULL;

	mir_cslock lck(trayLockCS);
	TCHAR *szSeparator = _T("\n");

	if (szProto == NULL) {
		if (accounts.getCount() == 0)
			return NULL;

		if (accounts.getCount() == 1)
			return cli.pfnTrayIconMakeTooltip(szPrefix, accounts[0]->szModuleName);

		CMString tszTip;

		if (szPrefix && szPrefix[0]) {
			if (!db_get_b(NULL, "CList", "AlwaysStatus", SETTING_ALWAYSSTATUS_DEFAULT)) {
				_tcsncpy_s(cli.szTip, MAX_TIP_SIZE, szPrefix, _TRUNCATE);
				return cli.szTip;
			}
			tszTip.Append(szPrefix);
		}

		for (int t = 0; t < accounts.getCount(); t++) {
			int i = cli.pfnGetAccountIndexByPos(t);
			if (i == -1)
				continue;

			PROTOACCOUNT *pa = accounts[i];
			if (!cli.pfnGetProtocolVisibility(pa->szModuleName))
				continue;

			TCHAR *szStatus = cli.pfnGetStatusModeDescription(CallProtoServiceInt(NULL, pa->szModuleName, PS_GETSTATUS, 0, 0), 0);
			if (!szStatus)
				continue;

			if (!tszTip.IsEmpty())
				tszTip.AppendChar('\n');
			if (mToolTipTrayTips) {
				tszTip.AppendFormat(_T("<b>%-12.12s</b>\t%s"), pa->tszAccountName, szStatus);

				ptrT ProtoXStatus(sttGetXStatus(pa->szModuleName));
				if (ProtoXStatus != NULL) {
					if (!tszTip.IsEmpty())
						tszTip.AppendChar('\n');
					tszTip.AppendFormat(_T("%-24.24s\n"), ProtoXStatus);
				}
			}
			else tszTip.AppendFormat(_T("%s %s"), pa->tszAccountName, szStatus);
		}

		_tcsncpy_s(cli.szTip, MAX_TIP_SIZE, tszTip, _TRUNCATE);
	}
	else {
		PROTOACCOUNT *pa = Proto_GetAccount(szProto);
		if (pa != NULL) {
			ptrT ProtoXStatus(sttGetXStatus(szProto));
			TCHAR *szStatus = cli.pfnGetStatusModeDescription(CallProtoServiceInt(NULL, szProto, PS_GETSTATUS, 0, 0), 0);
			if (szPrefix && szPrefix[0]) {
				if (db_get_b(NULL, "CList", "AlwaysStatus", SETTING_ALWAYSSTATUS_DEFAULT)) {
					if (mToolTipTrayTips) {
						if (ProtoXStatus != NULL)
							mir_sntprintf(cli.szTip, MAX_TIP_SIZE, _T("%s%s<b>%-12.12s</b>\t%s%s%-24.24s"), szPrefix, szSeparator, pa->tszAccountName, szStatus, szSeparator, ProtoXStatus);
						else
							mir_sntprintf(cli.szTip, MAX_TIP_SIZE, _T("%s%s<b>%-12.12s</b>\t%s"), szPrefix, szSeparator, pa->tszAccountName, szStatus);
					}
					else mir_sntprintf(cli.szTip, MAX_TIP_SIZE, _T("%s%s%s %s"), szPrefix, szSeparator, pa->tszAccountName, szStatus);
				}
				else mir_tstrncpy(cli.szTip, szPrefix, MAX_TIP_SIZE);
			}
			else {
				if (mToolTipTrayTips) {
					if (ProtoXStatus != NULL)
						mir_sntprintf(cli.szTip, MAX_TIP_SIZE, _T("<b>%-12.12s</b>\t%s\n%-24.24s"), pa->tszAccountName, szStatus, ProtoXStatus);
					else
						mir_sntprintf(cli.szTip, MAX_TIP_SIZE, _T("<b>%-12.12s</b>\t%s"), pa->tszAccountName, szStatus);
				}
				else mir_sntprintf(cli.szTip, MAX_TIP_SIZE, _T("%s %s"), pa->tszAccountName, szStatus);
			}
		}
	}

	return cli.szTip;
}