// Deletes one or many oscar capabilities for a given contact void CIcqProto::ClearContactCapabilities(MCONTACT hContact, DWORD fdwCapabilities) { // Get current capability flags DWORD fdwContactCaps = getDword(hContact, DBSETTING_CAPABILITIES, 0); if (fdwContactCaps != (fdwContactCaps & ~fdwCapabilities)) { #ifdef _DEBUG NetLog_CapabilityChange(this, "Removed", fdwCapabilities & fdwContactCaps); #endif // Clear unwanted capabilities fdwContactCaps &= ~fdwCapabilities; // And write it back to disk setDword(hContact, DBSETTING_CAPABILITIES, fdwContactCaps); } }
INT_PTR __cdecl CVkProto::SvcVisitProfile(WPARAM hContact, LPARAM) { debugLogA("CVkProto::SvcVisitProfile"); LONG userID = getDword(hContact, "ID", -1); ptrT tszDomain(db_get_tsa(hContact, m_szModuleName, "domain")); CMString tszUrl("https://vk.com/"); if (tszDomain) tszUrl.Append(tszDomain); else tszUrl.AppendFormat(_T("id%i"), userID); Utils_OpenUrlT(tszUrl); return 0; }
// Sets one or many oscar capabilities for a given contact void CIcqProto::SetContactCapabilities(MCONTACT hContact, DWORD fdwCapabilities) { // Get current capability flags DWORD fdwContactCaps = getDword(hContact, DBSETTING_CAPABILITIES, 0); if (fdwContactCaps != (fdwContactCaps | fdwCapabilities)) { #ifdef _DEBUG NetLog_CapabilityChange(this, "Added", fdwCapabilities & ~fdwContactCaps); #endif // Update them fdwContactCaps |= fdwCapabilities; // And write it back to disk setDword(hContact, DBSETTING_CAPABILITIES, fdwContactCaps); } }
void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) { debugLogA("CVkProto::OnReceiveFriends %d", reply->resultCode); if (reply->resultCode != 200 || !IsOnline()) return; JSONNode jnRoot; const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot); if (!jnResponse) return; bool bCleanContacts = getBool("AutoClean"); LIST<void> arContacts(10, PtrKeySortT); for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { if (!isChatRoom(hContact)) setByte(hContact, "Auth", 1); db_unset(hContact, m_szModuleName, "ReqAuth"); SetMirVer(hContact, -1); if (bCleanContacts && !isChatRoom(hContact)) arContacts.insert((HANDLE)hContact); } const JSONNode &jnItems = jnResponse["items"]; if (jnItems) for (auto it = jnItems.begin(); it != jnItems.end(); ++it) { MCONTACT hContact = SetContactInfo((*it), true); if (hContact == NULL || hContact == INVALID_CONTACT_ID) continue; arContacts.remove((HANDLE)hContact); setByte(hContact, "Auth", 0); } if (bCleanContacts) for (int i = 0; i < arContacts.getCount(); i++) { MCONTACT hContact = (UINT_PTR)arContacts[i]; LONG userID = getDword(hContact, "ID", -1); if (userID == m_myUserId || userID == VK_FEED_USER) continue; CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact); } arContacts.destroy(); }
INT_PTR CVkProto::SvcLoadVKNews(WPARAM, LPARAM) { debugLogA("CVkProto::SvcLoadVKNews"); if (!IsOnline()) return 1; if (!m_bNewsEnabled && !m_bNotificationsEnabled) { m_bSpecialContactAlwaysEnabled = true; AddFeedSpecialUser(); } time_t tLastNewsTime = getDword("LastNewsTime", time(NULL) - 24 * 60 * 60); RetrieveUnreadNews(tLastNewsTime); return 0; }
//////////////////////////////////////////////////////////////////////////////// // Check if new user data has been filled in for specified account void GGPROTO::checknewuser(uin_t uin, const char* passwd) { char oldpasswd[128]; DBVARIANT dbv; uin_t olduin = (uin_t)getDword(GG_KEY_UIN, 0); oldpasswd[0] = '\0'; if (!getString(GG_KEY_PASSWORD, &dbv)) { if (dbv.pszVal) mir_strcpy(oldpasswd, dbv.pszVal); db_free(&dbv); } if (uin > 0 && mir_strlen(passwd) > 0 && (uin != olduin || mir_strcmp(oldpasswd, passwd))) check_first_conn = 1; }
void CYahooProto::GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, int cbLen, int type) { int tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%S"), VARST(_T("%miranda_avatarcache%")), m_szModuleName); if (_taccess(pszDest, 0)) CreateDirectoryTreeT(pszDest); if (hContact != NULL) { int ck_sum = getDword(hContact, "PictCK", 0); tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%lX"), ck_sum); } else tPathLen += mir_sntprintf(pszDest + tPathLen, cbLen - tPathLen, _T("\\%S avatar"), m_szModuleName); _tcsncpy_s((pszDest + tPathLen), (cbLen - tPathLen), (type == 1 ? _T(".swf") : _T(".png")), _TRUNCATE); }
void CVkProto::OnSendMessage(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) { int iResult = ACKRESULT_FAILED; if (pReq->pUserInfo == NULL) { debugLogA("CVkProto::OnSendMessage failed! (pUserInfo == NULL)"); return; } CVkSendMsgParam *param = (CVkSendMsgParam *)pReq->pUserInfo; debugLogA("CVkProto::OnSendMessage %d", reply->resultCode); if (reply->resultCode == 200) { JSONNode jnRoot; const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot); if (jnResponse) { UINT mid; if (jnResponse.type() != JSON_STRING) mid = jnResponse.as_int(); else if (_stscanf(jnResponse.as_mstring(), _T("%d"), &mid) != 1) mid = 0; if (param->iMsgID != -1) m_sendIds.insert((HANDLE)mid); if (mid > getDword(param->hContact, "lastmsgid")) setDword(param->hContact, "lastmsgid", mid); if (m_vkOptions.iMarkMessageReadOn >= MarkMsgReadOn::markOnReply) MarkMessagesRead(param->hContact); iResult = ACKRESULT_SUCCESS; } } if (param->pFUP) { ProtoBroadcastAck(param->hContact, ACKTYPE_FILE, iResult, (HANDLE)(param->pFUP)); if (!pReq->bNeedsRestart || m_bTerminated) delete param->pFUP; } else if (m_bServerDelivery) ProtoBroadcastAck(param->hContact, ACKTYPE_MESSAGE, iResult, (HANDLE)(param->iMsgID)); if (!pReq->bNeedsRestart || m_bTerminated) { delete param; pReq->pUserInfo = NULL; } }
void CJabberProto::RetrieveMessageArchive(MCONTACT hContact, JABBER_LIST_ITEM *pItem) { if (pItem->bHistoryRead) return; pItem->bHistoryRead = TRUE; XmlNodeIq iq( AddIQ(&CJabberProto::OnIqResultGetCollectionList, JABBER_IQ_TYPE_GET)); HXML list = iq << XCHILDNS( _T("list"), JABBER_FEAT_ARCHIVE) << XATTR(_T("with"), pItem->jid); time_t tmLast = getDword(hContact, "LastCollection", 0); if (tmLast) { TCHAR buf[40]; list << XATTR(_T("start"), time2str(tmLast, buf, SIZEOF(buf))); } m_ThreadInfo->send(iq); }
// Scans a binary buffer for oscar capabilities and adds them to the contact. // You probably want to call ClearAllContactCapabilities() first. void CIcqProto::AddCapabilitiesFromBuffer(MCONTACT hContact, BYTE *pBuffer, int nLength) { // Get current capability flags DWORD fdwContactCaps = getDword(hContact, DBSETTING_CAPABILITIES, 0); // Get capability flags from buffer DWORD fdwCapabilities = GetCapabilitiesFromBuffer(pBuffer, nLength); if (fdwContactCaps != (fdwContactCaps | fdwCapabilities)) { #ifdef _DEBUG NetLog_CapabilityChange(this, "Added", fdwCapabilities & ~fdwContactCaps); #endif // Add capability flags from buffer fdwContactCaps |= fdwCapabilities; // And write them back to database setDword(hContact, DBSETTING_CAPABILITIES, fdwContactCaps); } }
int CVkProto::OnPreBuildContactMenu(WPARAM hContact, LPARAM) { LONG userID = getDword(hContact, "ID", -1); bool bisFriend = (getBool(hContact, "Auth", true) == 0); bool bisBroadcast = !(IsEmpty(ptrT(db_get_tsa(hContact, m_szModuleName, "AudioUrl")))); Menu_ShowItem(g_hContactMenuItems[CMI_VISITPROFILE], !isChatRoom(hContact) && userID != VK_FEED_USER); Menu_ShowItem(g_hContactMenuItems[CMI_WALLPOST], !isChatRoom(hContact)); Menu_ShowItem(g_hContactMenuItems[CMI_ADDASFRIEND], !bisFriend && !isChatRoom(hContact) && userID != VK_FEED_USER); Menu_ShowItem(g_hContactMenuItems[CMI_DELETEFRIEND], bisFriend && userID != VK_FEED_USER); Menu_ShowItem(g_hContactMenuItems[CMI_BANUSER], !isChatRoom(hContact) && userID != VK_FEED_USER); Menu_ShowItem(g_hContactMenuItems[CMI_REPORTABUSE], !isChatRoom(hContact) && userID != VK_FEED_USER); Menu_ShowItem(g_hContactMenuItems[CMI_DESTROYKICKCHAT], isChatRoom(hContact) && getBool(hContact, "off")); Menu_ShowItem(g_hContactMenuItems[CMI_OPENBROADCAST], !isChatRoom(hContact) && bisBroadcast); Menu_ShowItem(g_hContactMenuItems[CMI_GETSERVERHISTORY], !isChatRoom(hContact) && userID != VK_FEED_USER); Menu_ShowItem(g_hContactMenuItems[CMI_LOADVKNEWS], userID == VK_FEED_USER); for (int i = 0; i < CHMI_COUNT; i++) Menu_ShowItem(g_hContactHistoryMenuItems[i], !isChatRoom(hContact) && userID != VK_FEED_USER); return 0; }
int CVkProto::SendMsg(MCONTACT hContact, int, const char *szMsg) { debugLogA("CVkProto::SendMsg"); if (!IsOnline()) return 0; bool bIsChat = isChatRoom(hContact); LONG iUserID = getDword(hContact, bIsChat ? "vk_chat_id" : "ID" , -1); if (iUserID == -1 || iUserID == VK_FEED_USER) { ForkThread(&CVkProto::SendMsgAck, new CVkSendMsgParam(hContact)); return 0; } int StickerId = 0; ptrA pszRetMsg(GetStickerId(szMsg, StickerId)); ULONG uMsgId = ::InterlockedIncrement(&m_msgId); AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/messages.send.json", true, bIsChat? &CVkProto::OnSendChatMsg : &CVkProto::OnSendMessage, AsyncHttpRequest::rpHigh) << INT_PARAM(bIsChat ? "chat_id" : "user_id", iUserID) << INT_PARAM("guid", ((LONG) time(NULL)) * 100 + uMsgId % 100) << VER_API; pReq->AddHeader("Content-Type", "application/x-www-form-urlencoded"); if (StickerId) pReq << INT_PARAM("sticker_id", StickerId); else pReq << CHAR_PARAM("message", szMsg); if (!bIsChat) pReq->pUserInfo = new CVkSendMsgParam(hContact, uMsgId); Push(pReq); if (!m_bServerDelivery && !bIsChat) ForkThread(&CVkProto::SendMsgAck, new CVkSendMsgParam(hContact, uMsgId)); if (!IsEmpty(pszRetMsg)) { Sleep(330); SendMsg(hContact, 0, pszRetMsg); } return uMsgId; }
int CVkProto::UserIsTyping(MCONTACT hContact, int type) { debugLogA("CVkProto::UserIsTyping"); if (PROTOTYPE_SELFTYPING_ON == type) { LONG userID = getDword(hContact, "ID", -1); if (userID == -1 || !IsOnline() || userID == VK_FEED_USER) return 1; if (m_iMarkMessageReadOn == markOnTyping) MarkMessagesRead(hContact); Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/messages.setActivity.json", true, &CVkProto::OnReceiveSmth, AsyncHttpRequest::rpLow) << INT_PARAM("user_id", userID) << CHAR_PARAM("type", "typing") << VER_API); return 0; } return 1; }
INT_PTR __cdecl CVkProto::SvcReportAbuse(WPARAM hContact, LPARAM) { debugLogA("CVkProto::SvcReportAbuse"); LONG userID = getDword(hContact, "ID", -1); if (!IsOnline() || userID == -1 || userID == VK_FEED_USER) return 1; CMString tszNick(ptrT(db_get_tsa(hContact, m_szModuleName, "Nick"))), ptszMsg(FORMAT, TranslateT("Are you sure to report abuse on %s?"), tszNick.IsEmpty() ? TranslateT("(Unknown contact)") : tszNick); if (IDNO == MessageBox(NULL, ptszMsg, TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO)) return 1; Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/users.report.json", true, &CVkProto::OnReceiveSmth) << INT_PARAM("user_id", userID) << CHAR_PARAM("type", "spam") << VER_API); return 0; }
INT_PTR __cdecl CVkProto::SvcDeleteFriend(WPARAM hContact, LPARAM flag) { debugLogA("CVkProto::SvcDeleteFriend"); LONG userID = getDword(hContact, "ID", -1); if (!IsOnline() || userID == -1 || userID == VK_FEED_USER) return 1; ptrT ptszNick(db_get_tsa(hContact, m_szModuleName, "Nick")); CMString ptszMsg; if (flag == 0) { ptszMsg.AppendFormat(TranslateT("Are you sure to delete %s from your friend list?"), IsEmpty(ptszNick) ? TranslateT("(Unknown contact)") : ptszNick); if (IDNO == MessageBox(NULL, ptszMsg, TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO)) return 1; } Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/friends.delete.json", true, &CVkProto::OnReceiveDeleteFriend) << INT_PARAM("user_id", userID) << VER_API)->pUserInfo = new CVkSendMsgParam(hContact); return 0; }
void CVkProto::RetrieveUnreadNotifications(time_t tLastNotificationsTime) { debugLogA("CVkProto::RetrieveUnreadNotifications"); if (!IsOnline()) return; time_t tLastNotificationsReqTime = getDword("LastNotificationsReqTime", time(NULL) - 24 * 60 * 60); if (time(NULL) - tLastNotificationsReqTime < 3 * 60) return; CMString code(FORMAT, _T("return{\"notifications\":API.notifications.get({\"count\": 100, \"start_time\":%d})%s"), (LONG)(tLastNotificationsTime + 1), m_bNotificationFilterInvites ? _T(",\"groupinvates\":API.groups.getInvites({\"extended\":1})};") : _T("};")); Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveUnreadNotifications) << TCHAR_PARAM("code", code) << VER_API); setDword("LastNotificationsReqTime", (DWORD)time(NULL)); }
void CJabberProto::OnIqResultGetCollectionList(HXML iqNode, CJabberIqInfo*) { const TCHAR *to = xmlGetAttrValue(iqNode, _T("to")); if (to == NULL || mir_tstrcmp( xmlGetAttrValue(iqNode, _T("type")), _T("result"))) return; HXML list = xmlGetChild(iqNode, "list"); if (!list || mir_tstrcmp( xmlGetAttrValue(list, _T("xmlns")), JABBER_FEAT_ARCHIVE)) return; MCONTACT hContact = NULL; time_t tmLast = 0; for (int nodeIdx = 1; ; nodeIdx++) { HXML itemNode = xmlGetNthChild(list, _T("chat"), nodeIdx); if (!itemNode) break; const TCHAR* start = xmlGetAttrValue(itemNode, _T("start")); const TCHAR* with = xmlGetAttrValue(itemNode, _T("with")); if (!start || !with) continue; if (hContact == NULL) { if ((hContact = HContactFromJID(with)) == NULL) continue; tmLast = getDword(hContact, "LastCollection", 0); } m_ThreadInfo->send( XmlNodeIq( AddIQ(&CJabberProto::OnIqResultGetCollection, JABBER_IQ_TYPE_GET)) << XCHILDNS( _T("retrieve"), JABBER_FEAT_ARCHIVE) << XATTR(_T("with"), with) << XATTR(_T("start"), start)); time_t tmThis = str2time(start); if ( tmThis > tmLast) { tmLast = tmThis; setDword(hContact, "LastCollection", tmLast+1); } } }
void CVkProto::GetAvatarFileName(MCONTACT hContact, TCHAR* pszDest, size_t cbLen) { int tPathLen = mir_sntprintf(pszDest, cbLen, _T("%s\\%S"), VARST(_T("%miranda_avatarcache%")), m_szModuleName); DWORD dwAttributes = GetFileAttributes(pszDest); if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) CreateDirectoryTreeT(pszDest); pszDest[ tPathLen++ ] = '\\'; const TCHAR* szFileType = _T(".jpg"); ptrT szUrl( getTStringA(hContact, "AvatarUrl")); if (szUrl) { TCHAR *p = _tcsrchr(szUrl, '.'); if (p != NULL) szFileType = p; } LONG id = getDword(hContact, "ID", -1); mir_sntprintf(pszDest + tPathLen, MAX_PATH - tPathLen, _T("%d%s"), id, szFileType); }
int CVkProto::AuthRequest(MCONTACT hContact,const TCHAR* message) { debugLogA("CVkProto::AuthRequest"); if (!IsOnline()) return 1; LONG userID = getDword(hContact, "ID", -1); if (userID == -1 || !hContact || userID == VK_FEED_USER) return 1; TCHAR msg[501] = {0}; if (message) _tcsncpy_s(msg, 500, message, _TRUNCATE); Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/friends.add.json", true, &CVkProto::OnReceiveAuthRequest) << INT_PARAM("user_id", userID) << TCHAR_PARAM("text", msg) << VER_API)->pUserInfo = new CVkSendMsgParam(hContact); return 0; }
void CVkProto::GetHistoryDlg(MCONTACT hContact, int iLastMsg) { debugLogA("CVkProto::GetHistoryDlg %d", iLastMsg); int lastmsgid = -1; switch (m_iSyncHistoryMetod) { case syncAuto: lastmsgid = getDword(hContact, "lastmsgid", -1); if (lastmsgid == -1 || !IsOnline()) { setDword(hContact, "lastmsgid", iLastMsg); return; } GetServerHistory(hContact, 0, MAXHISTORYMIDSPERONE, 0, lastmsgid); break; case sync1Days: GetServerHistoryLastNDay(hContact, 1); break; case sync3Days: GetServerHistoryLastNDay(hContact, 3); break; } }
int CSteamProto::OnPrebuildContactMenu(WPARAM wParam, LPARAM) { MCONTACT hContact = (MCONTACT)wParam; if (!hContact) return 0; if (!this->IsOnline() || lstrcmpA(GetContactProto(hContact), m_szModuleName)) return 0; //bool ctrlPressed = (GetKeyState(VK_CONTROL) & 0x8000) != 0; bool authNeeded = getBool(hContact, "Auth", 0); Menu_ShowItem(contactMenuItems[CMI_AUTH_REQUEST], authNeeded); bool isBlocked = getBool(hContact, "Block", 0); Menu_ShowItem(contactMenuItems[CMI_BLOCK], !isBlocked); DWORD gameId = getDword(hContact, "GameID", 0); Menu_ShowItem(contactMenuItems[CMI_JOIN_GAME], gameId > 0); return 0; }
void CVkProto::WallPost(MCONTACT hContact, TCHAR *ptszMsg, TCHAR *ptszUrl, bool bFriendsOnly) { debugLogA("CVkProto::WallPost"); if (!IsOnline() || (IsEmpty(ptszMsg) && IsEmpty(ptszUrl))) return; LONG userID = hContact ? m_myUserId : getDword(hContact, "ID", -1); if (userID == -1 || userID == VK_FEED_USER) return; AsyncHttpRequest *pReq = new AsyncHttpRequest(this, REQUEST_POST, "/method/wall.post.json", true, &CVkProto::OnReceiveSmth) << INT_PARAM("owner_id", userID) << INT_PARAM("friends_only", bFriendsOnly ? 1 : 0); if (!IsEmpty(ptszMsg)) pReq << TCHAR_PARAM("message", ptszMsg); if (!IsEmpty(ptszUrl)) pReq << TCHAR_PARAM("attachments", ptszUrl); Push(pReq); }
void CVkProto::RetrieveUsersInfo(bool bFreeOffline, bool bRepeat) { debugLogA("CVkProto::RetrieveUsersInfo"); if (!IsOnline()) return; CMString userIDs, code; for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { LONG userID = getDword(hContact, "ID", -1); if (userID == -1 || userID == VK_FEED_USER) continue; if (!userIDs.IsEmpty()) userIDs.AppendChar(','); userIDs.AppendFormat(_T("%i"), userID); } CMString codeformat("var userIDs=\"%s\";var _fields=\"%s\";"); if (m_bNeedSendOnline) codeformat += _T("API.account.setOnline();"); if (bFreeOffline && !m_bLoadFullCList) codeformat += CMString("var US=[];var res=[];var t=10;while(t>0){" "US=API.users.get({\"user_ids\":userIDs,\"fields\":_fields,\"name_case\":\"nom\"});" "var index=US.length;while(index>0){" "index=index-1;if(US[index].online!=0){res.push(US[index]);};};" "t=t-1;if(res.length>0)t=0;};" "return{\"freeoffline\":1,\"norepeat\":%d,\"usercount\":res.length,\"users\":res,\"requests\":API.friends.getRequests({\"extended\":0,\"need_mutual\":0,\"out\":0})};"); else codeformat += CMString("var res=API.users.get({\"user_ids\":userIDs,\"fields\":_fields,\"name_case\":\"nom\"});" "return{\"freeoffline\":0,\"norepeat\":%d,\"usercount\":res.length,\"users\":res,\"requests\":API.friends.getRequests({\"extended\":0,\"need_mutual\":0,\"out\":0})};"); code.AppendFormat(codeformat, userIDs, CMString(bFreeOffline ? "online,status" : fieldsName), (int)bRepeat); Push(new AsyncHttpRequest(this, REQUEST_POST, "/method/execute.json", true, &CVkProto::OnReceiveUserInfo) << TCHAR_PARAM("code", code) << VER_API); }
int GGPROTO::SendMsg(HANDLE hContact, int flags, const char *msg) { uin_t uin = (uin_t)getDword(hContact, GG_KEY_UIN, 0); if (!isonline() || !uin) return 0; char* msg_utf8; if (flags & PREF_UNICODE) msg_utf8 = mir_utf8encodeW((wchar_t*)&msg[ strlen( msg )+1 ] ); else if (flags & PREF_UTF) msg_utf8 = mir_strdup(msg); else msg_utf8 = mir_utf8encode(msg); if (!msg_utf8) return 0; gg_EnterCriticalSection(&sess_mutex, "SendMsg", 53, "sess_mutex", 1); int seq = gg_send_message(sess, GG_CLASS_CHAT, uin, (BYTE*)msg_utf8); gg_LeaveCriticalSection(&sess_mutex, "SendMsg", 53, 1, "sess_mutex", 1); if (!getByte(GG_KEY_MSGACK, GG_KEYDEF_MSGACK)) { // Auto-ack message without waiting for server ack GG_SEQ_ACK *ack = (GG_SEQ_ACK*)mir_alloc(sizeof(GG_SEQ_ACK)); if (ack) { ack->seq = seq; ack->hContact = hContact; #ifdef DEBUGMODE debugLogA("SendMsg(): ForkThread 16 GGPROTO::sendackthread"); #endif ForkThread(&GGPROTO::sendackthread, ack); } } mir_free(msg_utf8); return seq; }
INT_PTR __cdecl CVkProto::SvcGetAllServerHistory(WPARAM hContact, LPARAM) { debugLogA("CVkProto::SvcGetAllServerHistory"); if (!IsOnline()) return 0; LPCTSTR str = TranslateT("Are you sure to reload all messages from vk.com?\nLocal contact history will be deleted and reloaded from the server.\nIt may take a long time.\nDo you want to continue?"); if (IDNO == MessageBox(NULL, str, TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO)) return 0; LONG userID = getDword(hContact, "ID", -1); if (userID == -1 || userID == VK_FEED_USER) return 0; MEVENT hDBEvent = db_event_first(hContact); while (hDBEvent) { MEVENT hDBEventNext = db_event_next(hContact, hDBEvent); db_event_delete(hContact, hDBEvent); hDBEvent = hDBEventNext; } db_unset(hContact, m_szModuleName, "lastmsgid"); GetServerHistory(hContact, 0, MAXHISTORYMIDSPERONE, 0, 0); return 1; }
INT_PTR __cdecl CVkProto::SvcGetAllServerHistory(WPARAM, LPARAM) { debugLogA("CVkProto::SvcGetAllServerHistory start"); if (!IsOnline()) return 0; LPCTSTR str = TranslateT("Are you sure you want to reload all messages for all contacts from vk.com?\nLocal contact history will be deleted and reloaded from the server.\nIt may take a very long time and/or corrupt Miranda database.\nWe recommend check your database before reloading messages and after it (Miranda32.exe /svc:dbchecker or Miranda64.exe /svc:dbchecker).\nDo you want to continue?"); if (IDNO == MessageBox(NULL, str, TranslateT("Attention!"), MB_ICONWARNING | MB_YESNO)) return 0; for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { LONG userID = getDword(hContact, "ID", -1); if (userID == -1 || userID == VK_FEED_USER) continue; MEVENT hDBEvent = db_event_first(hContact); while (hDBEvent) { MEVENT hDBEventNext = db_event_next(hContact, hDBEvent); db_event_delete(hContact, hDBEvent); hDBEvent = hDBEventNext; } { mir_cslock lck(m_csLoadHistoryTask); m_iLoadHistoryTask++; m_bNotifyForEndLoadingHistoryAllContact = m_bNotifyForEndLoadingHistory = true; debugLogA("CVkProto::SvcGetAllServerHistory for ID=%d m_iLoadHistoryTask=%d", userID, m_iLoadHistoryTask); } db_unset(hContact, m_szModuleName, "lastmsgid"); GetServerHistory(hContact, 0, MAXHISTORYMIDSPERONE, 0, 0); } return 1; }
HANDLE CMraProto::GetAwayMsg(MCONTACT hContact) { if (!m_bLoggedIn || !hContact) return 0; TCHAR szStatusDesc[MICBLOG_STATUS_MAX + MICBLOG_STATUS_MAX + MAX_PATH], szTime[64]; DWORD dwTime; int iRet = 0; CMStringW szBlogStatus; if (mraGetStringW(hContact, DBSETTING_BLOGSTATUS, szBlogStatus)) { SYSTEMTIME tt = { 0 }; dwTime = getDword(hContact, DBSETTING_BLOGSTATUSTIME, 0); if (dwTime && MakeLocalSystemTimeFromTime32(dwTime, &tt)) mir_sntprintf(szTime, _countof(szTime), _T("%04ld.%02ld.%02ld %02ld:%02ld: "), tt.wYear, tt.wMonth, tt.wDay, tt.wHour, tt.wMinute); else szTime[0] = 0; mir_sntprintf(szStatusDesc, _countof(szStatusDesc), _T("%s%s"), szTime, szBlogStatus.c_str()); iRet = GetTickCount(); ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)iRet, (LPARAM)szStatusDesc); } return (HANDLE)iRet; }
HANDLE GGPROTO::SendFile(MCONTACT hContact, const TCHAR* szDescription, TCHAR** ppszFiles) { char *bslash, *filename; DWORD ip, ver; WORD port; uin_t myuin, uin; // Check if main dcc thread is on if (!isonline()) return ftfail(this, hContact); filename = mir_t2a(ppszFiles[0]); // Read user IP and port ip = swap32(getDword(hContact, GG_KEY_CLIENTIP, 0)); port = getWord(hContact, GG_KEY_CLIENTPORT, 0); myuin = getDword(GG_KEY_UIN, 0); uin = getDword(hContact, GG_KEY_UIN, 0); ver = getDword(hContact, GG_KEY_CLIENTVERSION, 0); // Use DCC7 if a contact is using at least version 7.6 or unknown version if ((ver & 0x00ffffff) >= 0x29 || !ver) { gg_EnterCriticalSection(&sess_mutex, "SendFile", 46, "sess_mutex", 1); struct gg_dcc7 *dcc7 = gg_dcc7_send_file(sess, uin, filename, NULL, NULL); if (!dcc7) { gg_LeaveCriticalSection(&sess_mutex, "SendFile", 46, 1, "sess_mutex", 1); debugLogA("SendFile(): Failed to send file \"%s\".", filename); mir_free(filename); return ftfail(this, hContact); } gg_LeaveCriticalSection(&sess_mutex, "SendFile", 46, 2, "sess_mutex", 1); debugLogA("SendFile(): Sending file \"%s\" to %d.", filename, uin); // Add dcc to watches list_add(&watches, dcc7, 0); // Store handle dcc7->contact = (void*)hContact; dcc7->folder = _strdup(filename); dcc7->tick = 0; // Make folder name bslash = strrchr(dcc7->folder, '\\'); if (bslash) *(bslash + 1) = 0; else *(dcc7->folder) = 0; mir_free(filename); return dcc7; } // Return if bad connection info if (!port || !uin || !myuin) { debugLogA("SendFile(): Bad contact uin or my uin. Exit."); mir_free(filename); return ftfail(this, hContact); } // Try to connect if not ask user to connect me struct gg_dcc *dcc = NULL; if ((ip && port >= 10 && !(dcc = gg_dcc_send_file(ip, port, myuin, uin))) || (port < 10 && port > 0)) { // Make fake dcc structure dcc = (gg_dcc*)malloc(sizeof(struct gg_dcc)); memset(dcc, 0, sizeof(struct gg_dcc)); // Fill up structures dcc->uin = myuin; dcc->peer_uin = uin; dcc->fd = -1; dcc->type = GG_SESSION_DCC_SEND; debugLogA("SendFile(): Requesting user to connect us and scheduling gg_dcc struct for a later use."); gg_EnterCriticalSection(&sess_mutex, "SendFile", 47, "sess_mutex", 1); gg_dcc_request(sess, uin); gg_LeaveCriticalSection(&sess_mutex, "SendFile", 47, 1, "sess_mutex", 1); list_add(&requests, dcc, 0); } // Write filename if (gg_dcc_fill_file_info(dcc, filename) == -1) { debugLogA("SendFile(): Cannot open and file fileinfo \"%s\".", filename); gg_free_dcc(dcc); mir_free(filename); return ftfail(this, hContact); } debugLogA("SendFile(): Sending file \"%s\" to %d in %s mode.", filename, uin, (dcc->fd != -1) ? "active" : "passive"); // Add dcc to watches if not passive if (dcc->fd != -1) list_add(&watches, dcc, 0); // Store handle dcc->contact = (void*)hContact; dcc->folder = _strdup(filename); dcc->tick = 0; // Make folder name bslash = strrchr(dcc->folder, '\\'); if (bslash) *(bslash + 1) = 0; else *(dcc->folder) = 0; mir_free(filename); return dcc; }
void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) { debugLogA("CVkProto::OnReceiveUserInfo %d", reply->resultCode); if (reply->resultCode != 200 || !IsOnline()) return; JSONNode jnRoot; const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot); if (!jnResponse) return; const JSONNode &jnUsers = jnResponse["users"]; if (!jnUsers) return; if (!jnResponse["norepeat"].as_bool() && jnResponse["usercount"].as_int() == 0) { RetrieveUsersInfo(true, true); return; } MCONTACT hContact; LIST<void> arContacts(10, PtrKeySortT); for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) if (!isChatRoom(hContact)) arContacts.insert((HANDLE)hContact); for (auto it = jnUsers.begin(); it != jnUsers.end(); ++it) { hContact = SetContactInfo((*it)); if (hContact) arContacts.remove((HANDLE)hContact); } if (jnResponse["freeoffline"].as_bool()) for (int i = 0; i < arContacts.getCount(); i++) { hContact = (UINT_PTR)arContacts[i]; LONG userID = getDword(hContact, "ID", -1); if (userID == m_myUserId || userID == VK_FEED_USER) continue; int iContactStatus = getWord(hContact, "Status", ID_STATUS_OFFLINE); if ((iContactStatus == ID_STATUS_ONLINE) || (iContactStatus == ID_STATUS_INVISIBLE && time(NULL) - getDword(hContact, "InvisibleTS", 0) >= m_iInvisibleInterval * 60LL)) { setWord(hContact, "Status", ID_STATUS_OFFLINE); SetMirVer(hContact, -1); db_unset(hContact, m_szModuleName, "ListeningTo"); } } arContacts.destroy(); AddFeedSpecialUser(); const JSONNode &jnRequests = jnResponse["requests"]; if (!jnRequests) return; int iCount = jnRequests["count"].as_int(); const JSONNode &jnItems = jnRequests["items"]; if (!iCount || !jnItems) return; debugLogA("CVkProto::OnReceiveUserInfo AuthRequests"); for (auto it = jnItems.begin(); it != jnItems.end(); ++it) { LONG userid = (*it).as_int(); if (userid == 0) break; hContact = FindUser(userid, true); if (!getBool(hContact, "ReqAuth")) { RetrieveUserInfo(userid); setByte(hContact, "ReqAuth", 1); ForkThread(&CVkProto::DBAddAuthRequestThread, (void *)hContact); } } }
DWORD CMraProto::MraMrimProxyConnect(HANDLE hMraMrimProxyData, HANDLE *phConnection) { DWORD dwRetErrorCode; if (hMraMrimProxyData && phConnection) { BOOL bIsHTTPSProxyUsed, bContinue; BYTE lpbBufferRcv[BUFF_SIZE_RCV_MIN_FREE]; DWORD dwBytesReceived, dwConnectReTryCount, dwCurConnectReTryCount; size_t dwRcvBuffSize = BUFF_SIZE_RCV_MIN_FREE, dwRcvBuffSizeUsed; NETLIBSELECT nls = {0}; MRA_MRIMPROXY_DATA *pmmpd = (MRA_MRIMPROXY_DATA*)hMraMrimProxyData; NETLIBOPENCONNECTION nloc = {0}; // адреса есть, значит инициаторы не мы if (pmmpd->malAddrList.dwAddrCount) { CMStringA szAddresses = MraAddrListGetToBuff(&pmmpd->malAddrList); MraProxyAck(PROXY_STATUS_OK, pmmpd->szEmail, pmmpd->dwIDRequest, pmmpd->dwDataType, pmmpd->lpszUserData, szAddresses, pmmpd->mguidSessionID); } // мы инициаторы else { pmmpd->hWaitHandle = CreateEvent(NULL, TRUE, FALSE, NULL); if (pmmpd->szEmail) if (MraProxy(pmmpd->szEmail, pmmpd->dwIDRequest, pmmpd->dwDataType, pmmpd->lpszUserData, "", pmmpd->mguidSessionID)) WaitForSingleObjectEx(pmmpd->hWaitHandle, INFINITE, FALSE); CloseHandle(pmmpd->hWaitHandle); pmmpd->hWaitHandle = NULL; } dwRetErrorCode = ERROR_NO_NETWORK; if (pmmpd->malAddrList.dwAddrCount) { pmmpd->hConnection = NULL; bIsHTTPSProxyUsed = IsHTTPSProxyUsed(m_hNetlibUser); dwConnectReTryCount = getDword("ConnectReTryCountMRIMProxy", MRA_DEFAULT_CONN_RETRY_COUNT_MRIMPROXY); nloc.cbSize = sizeof(nloc); nloc.flags = NLOCF_V2; nloc.timeout = ((MRA_TIMEOUT_DIRECT_CONN-1)/(pmmpd->malAddrList.dwAddrCount*dwConnectReTryCount));// -1 сек чтобы был запас if (nloc.timeout < MRA_TIMEOUT_CONN_MIN) nloc.timeout = MRA_TIMEOUT_CONN_MIN; if (nloc.timeout > MRA_TIMEOUT_CONN_MAX) nloc.timeout = MRA_TIMEOUT_CONN_MAX; // Set up the sockaddr structure for (size_t i = 0; i < pmmpd->malAddrList.dwAddrCount && dwRetErrorCode != NO_ERROR; i++) { // через https прокси только 443 порт if ((pmmpd->malAddrList.pMailAddress[i].dwPort == MRA_SERVER_PORT_HTTPS && bIsHTTPSProxyUsed) || bIsHTTPSProxyUsed == FALSE) { if (pmmpd->dwDataType == MRIM_PROXY_TYPE_FILES) ProtoBroadcastAck(MraHContactFromEmail(pmmpd->szEmail, FALSE, TRUE, NULL), ACKTYPE_FILE, ACKRESULT_CONNECTING, (HANDLE)pmmpd->dwIDRequest, 0); nloc.szHost = inet_ntoa((*((in_addr*)&pmmpd->malAddrList.pMailAddress[i].dwAddr))); nloc.wPort = (WORD)pmmpd->malAddrList.pMailAddress[i].dwPort; dwCurConnectReTryCount = dwConnectReTryCount; do { pmmpd->hConnection = (HANDLE)CallService(MS_NETLIB_OPENCONNECTION, (WPARAM)m_hNetlibUser, (LPARAM)&nloc); } while (--dwCurConnectReTryCount && pmmpd->hConnection == NULL); if (pmmpd->hConnection) { nls.cbSize = sizeof(nls); nls.dwTimeout = (MRA_TIMEOUT_DIRECT_CONN*1000*2); nls.hReadConns[0] = pmmpd->hConnection; bContinue = TRUE; dwRcvBuffSizeUsed = 0; if (pmmpd->dwDataType == MRIM_PROXY_TYPE_FILES) ProtoBroadcastAck(MraHContactFromEmail(pmmpd->szEmail, FALSE, TRUE, NULL), ACKTYPE_FILE, ACKRESULT_CONNECTED, (HANDLE)pmmpd->dwIDRequest, 0); MraSendPacket(nls.hReadConns[0], 0, MRIM_CS_PROXY_HELLO, &pmmpd->mguidSessionID, sizeof(MRA_GUID)); while (bContinue) { switch (CallService(MS_NETLIB_SELECT, 0, (LPARAM)&nls)) { case SOCKET_ERROR: case 0:// Time out dwRetErrorCode = GetLastError(); ShowFormattedErrorMessage(L"Disconnected, socket error", dwRetErrorCode); bContinue = FALSE; break; case 1: if (dwRcvBuffSizeUsed == BUFF_SIZE_RCV_MIN_FREE) { // bad packet bContinue = FALSE; _CrtDbgBreak(); } else { dwBytesReceived = Netlib_Recv(nls.hReadConns[0], (LPSTR)(lpbBufferRcv + dwRcvBuffSizeUsed), (int)(dwRcvBuffSize - dwRcvBuffSizeUsed), 0); if (dwBytesReceived && dwBytesReceived != SOCKET_ERROR) { // connected dwRcvBuffSizeUsed += dwBytesReceived; if (dwRcvBuffSizeUsed >= sizeof(mrim_packet_header_t)) { // packet header received if (((mrim_packet_header_t*)lpbBufferRcv)->magic == CS_MAGIC) { // packet OK if ((dwRcvBuffSizeUsed-sizeof(mrim_packet_header_t)) >= ((mrim_packet_header_t*)lpbBufferRcv)->dlen) { // full packet received, may be more than one if (((mrim_packet_header_t*)lpbBufferRcv)->msg == MRIM_CS_PROXY_HELLO_ACK) // connect OK! dwRetErrorCode = NO_ERROR; else // bad/wrong _CrtDbgBreak(); bContinue = FALSE; } else // not all packet received, continue receiving debugLogA("Not all packet received, continue receiving\n"); } else { // bad packet debugLogA("Bad packet\n"); _ASSERT(false); bContinue = FALSE; } } else // packet too small, continue receiving debugLogA("Packet to small, continue receiving\n"); } else { // disconnected dwRetErrorCode = GetLastError(); ShowFormattedErrorMessage(L"Disconnected, socket read error", dwRetErrorCode); bContinue = FALSE; } } break; }// end switch }// end while } else dwRetErrorCode = GetLastError(); }// filtered }// end for if (dwRetErrorCode != NO_ERROR) // кажется не туда подключились :) NETLIB_CLOSEHANDLE(pmmpd->hConnection); } *phConnection = pmmpd->hConnection; } else dwRetErrorCode = ERROR_INVALID_HANDLE; return dwRetErrorCode; }