AsyncHttpRequest::AsyncHttpRequest(CVkProto *ppro, int iRequestType, LPCSTR _url, bool bSecure, VK_REQUEST_HANDLER pFunc, RequestPriority rpPriority) { cbSize = sizeof(NETLIBHTTPREQUEST); m_bApiReq = true; bIsMainConn = false; bExpUrlEncode = ppro->m_bUseNonStandardUrlEncode; AddHeader("Connection", "keep-alive"); AddHeader("Accept-Encoding", "booo"); flags = VK_NODUMPHEADERS | NLHRF_DUMPASTEXT | NLHRF_HTTP11 | NLHRF_REDIRECT; if (bSecure) flags |= NLHRF_SSL; if (*_url == '/') { // relative url leads to a site m_szUrl = ((bSecure) ? "https://" : "http://") + CMStringA("api.vk.com"); m_szUrl += _url; bIsMainConn = true; } else m_szUrl = _url; if (bSecure) this << CHAR_PARAM("access_token", ppro->m_szAccessToken); requestType = iRequestType; m_pFunc = pFunc; pUserInfo = NULL; m_iRetry = MAX_RETRIES; m_iErrorCode = 0; bNeedsRestart = false; m_reqNum = ::InterlockedIncrement(&m_reqCount); m_priority = rpPriority; }
void CMsnProto::MsnInvokeMyURL(bool ismail, const char* url) { char* hippy = NULL; if (!url) url = ismail ? "http://mail.live.com?rru=inbox" : "http://profile.live.com"; const char *postdata = ismail ? postdataM : postdataS; char passport[256]; if (db_get_static(NULL, m_szModuleName, "MsnPassportHost", passport, 256)) strcpy(passport, "https://login.live.com/"); char *p = strchr(passport, '/'); if (p && p[1] == '/') p = strchr(p + 2, '/'); if (p) *p = 0; CMStringA post = HotmailLogin(CMStringA().Format(postdata, (unsigned)time(NULL), ptrA(mir_urlEncode(url)))); if (!post.IsEmpty()) { CMStringA hippy(passport); hippy.AppendFormat("/ppsecure/sha1auth.srf?lc=%d&token=%s", itoa(langpref, passport, 10), ptrA(mir_urlEncode(post))); debugLogA("Starting URL: '%s'", hippy); CallService(MS_UTILS_OPENURL, 1, (LPARAM)hippy.GetString()); } }
// 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()); }
HANDLE CMraProto::SearchByEmail(const TCHAR *email) { if (m_bLoggedIn && email) return MraWPRequestByEMail(NULL, ACKTYPE_SEARCH, CMStringA(email)); return NULL; }
INT_PTR CMsnProto::MsnSendHotmail(WPARAM hContact, LPARAM) { char szEmail[MSN_MAX_EMAIL_LEN]; if (MSN_IsMeByContact(hContact, szEmail)) MsnGotoInbox(0, 0); else if (msnLoggedIn) MsnInvokeMyURL(true, CMStringA().Format("http://mail.live.com?rru=compose?to=%s", ptrA(mir_urlEncode(szEmail)))); return 0; }
INT_PTR CMraProto::MraSendSMS(WPARAM wParam, LPARAM lParam) { if (!m_bLoggedIn || !wParam || !lParam) return 0; ptrW lpwszMessageXMLEncoded( mir_utf8decodeW((LPSTR)lParam)); if (lpwszMessageXMLEncoded) { CMStringW decoded = DecodeXML( CMStringW(lpwszMessageXMLEncoded)); if (decoded.GetLength()) MraSMSW(NULL, CMStringA((LPSTR)wParam), decoded); } return 0; }
int CMraProto::Authorize(MEVENT hDBEvent) { if (!m_bLoggedIn) return 1; DBEVENTINFO dbei = { sizeof(dbei) }; if ((dbei.cbBlob = db_event_getBlobSize(hDBEvent)) == -1) return 1; dbei.pBlob = (PBYTE)alloca(dbei.cbBlob); if (db_event_get(hDBEvent, &dbei)) return 1; if (dbei.eventType != EVENTTYPE_AUTHREQUEST) return 1; if (mir_strcmp(dbei.szModule, m_szModuleName)) return 1; LPSTR lpszNick = (LPSTR)(dbei.pBlob + sizeof(DWORD) * 2); LPSTR lpszFirstName = lpszNick + mir_strlen(lpszNick) + 1; LPSTR lpszLastName = lpszFirstName + mir_strlen(lpszFirstName) + 1; MraAuthorize(CMStringA(lpszLastName + mir_strlen(lpszLastName) + 1)); return 0; }
int CVkProto::PollServer() { debugLogA("CVkProto::PollServer"); NETLIBHTTPREQUEST req = { sizeof(req) }; req.requestType = REQUEST_GET; req.szUrl = NEWSTR_ALLOCA(CMStringA().Format("http://%s?act=a_check&key=%s&ts=%s&wait=25&access_token=%s", m_pollingServer, m_pollingKey, m_pollingTs, m_szAccessToken)); req.flags = VK_NODUMPHEADERS | NLHRF_PERSISTENT; req.timeout = 30000; req.nlc = m_pollingConn; NETLIBHTTPREQUEST *reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)&req); if (reply == NULL) { m_pollingConn = NULL; return 0; } int retVal = 0; if (reply->resultCode == 200) { JSONROOT pRoot(reply->pData); JSONNODE *pFailed = json_get(pRoot, "failed"); if (pFailed != NULL && json_as_int(pFailed) == 2) { RetrievePollingInfo(); retVal = -1; debugLogA("Polling key expired, restarting polling thread"); } else if (CheckJsonResult(NULL, reply, pRoot)) { m_pollingTs = mir_t2a(ptrT(json_as_string(json_get(pRoot, "ts")))); JSONNODE *pUpdates = json_get(pRoot, "updates"); if (pUpdates != NULL) PollUpdates(pUpdates); retVal = 1; } } m_pollingConn = reply->nlc; CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply); return retVal; }
INT_PTR CIcqProto::OpenWebProfile(WPARAM hContact, LPARAM) { Utils_OpenUrl(CMStringA(FORMAT, "http://www.icq.com/people/%d", getContactUin(hContact))); return 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; }
MIR_APP_DLL(void) ProtoLogA(struct PROTO_INTERFACE *pThis, LPCSTR szFormat, va_list args) { char buf[4096]; int res = _vsnprintf(buf, _countof(buf), szFormat, args); CallService(MS_NETLIB_LOG, (WPARAM)(pThis ? pThis->m_hNetlibUser : NULL), (LPARAM)((res != -1) ? buf : CMStringA().FormatV(szFormat, args))); }