void CVkProto::ExecuteRequest(AsyncHttpRequest *pReq) { CMStringA str; do { pReq->bNeedsRestart = false; pReq->szUrl = pReq->m_szUrl.GetBuffer(); if (!pReq->m_szParam.IsEmpty()) { if (pReq->requestType == REQUEST_GET) { str.Format("%s?%s", pReq->m_szUrl, pReq->m_szParam); pReq->szUrl = str.GetBuffer(); } else { pReq->pData = mir_strdup(pReq->m_szParam); pReq->dataLength = pReq->m_szParam.GetLength(); } } if (pReq->m_bApiReq) { pReq->flags |= NLHRF_PERSISTENT; pReq->nlc = m_hAPIConnection; } debugLogA("CVkProto::ExecuteRequest \n====\n%s\n====\n", pReq->szUrl); NETLIBHTTPREQUEST *reply = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)m_hNetlibUser, (LPARAM)pReq); if (reply != NULL) { if (pReq->m_pFunc != NULL) (this->*(pReq->m_pFunc))(reply, pReq); // may be set pReq->bNeedsRestart if (pReq->m_bApiReq) m_hAPIConnection = reply->nlc; CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)reply); } else if (pReq->bIsMainConn) { if (IsStatusConnecting(m_iStatus)) ConnectionFailed(LOGINERR_NONETWORK); else if (pReq->m_iRetry && !m_bTerminated) { pReq->bNeedsRestart = true; Sleep(1000); //Pause for fix err pReq->m_iRetry--; debugLogA("CVkProto::ExecuteRequest restarting (retry = %d)", MAX_RETRIES - pReq->m_iRetry); } else { debugLogA("CVkProto::ExecuteRequest ShutdownSession"); ShutdownSession(); } } debugLogA("CVkProto::ExecuteRequest pReq->bNeedsRestart = %d", (int)pReq->bNeedsRestart); if (!reply && pReq->m_bApiReq) m_hAPIConnection = NULL; } while (pReq->bNeedsRestart && !m_bTerminated); delete pReq; }
void WriteSetting(MCONTACT hContact, char* module1, char* setting1, char* module2, char* setting2) { CMStringA newString; char text[MAX_STRING_LENGTH]; int error = 0, status = GetLCStatus(0, 0); if (db_get_static(hContact, module1, setting1, text, _countof(text))) { switch (stringReplacer(text, newString, hContact)) { case ERROR_NO_LINE_AFTER_VAR_F: newString.Format(Translate("%s - ERROR: no line specified or line not found (in %s)"), text, setting1); error = 1; break; case ERROR_LINE_NOT_READ: newString.Format(Translate("%s - ERROR: file couldn't be opened (in %s)"), text, setting1); error = 1; break; case ERROR_NO_FILE: newString.Format(Translate("%s - ERROR: no file specified in settings (in %s)"), text, setting1); error = 1; break; default: error = 0; break; } // strip the tab and new lines from all except the tooltip if (!error && mir_strcmp(setting1, "ToolTip")) newString.TrimRight(); db_set_s(hContact, module2, setting2, newString); } else db_set_s(hContact, module2, setting2, ""); if (!error) { if ((status == ID_STATUS_ONLINE) || (status == ID_STATUS_AWAY) || (status == db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE)) || db_get_b(hContact, MODNAME, "AlwaysVisible", 0)) db_set_w(hContact, MODNAME, "Status", (WORD)db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE)); else db_set_w(hContact, MODNAME, "Status", ID_STATUS_OFFLINE); } else db_set_w(hContact, MODNAME, "Status", ID_STATUS_OFFLINE); }
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); }
INT_PTR CALLBACK TestWindowDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM) { switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwnd); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_HELPMSG: CreateDialog(g_hInst, MAKEINTRESOURCE(IDD_HELP), 0, HelpWindowDlgProc); break; case IDCANCEL: DestroyWindow(hwnd); break; case IDC_STRING: if (HIWORD(wParam) == EN_CHANGE) { char tmp[MAX_STRING_LENGTH]; int i = 0, j; if (GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING))) { GetDlgItemTextA(hwnd, IDC_STRING, tmp, _countof(tmp)); if (tmp[mir_strlen(tmp) - 1] == '(') { for (i = 0; i < VARS; i++) { if (!mir_strcmp(braceList[i].var, &tmp[mir_strlen(tmp) - mir_strlen(braceList[i].var)])) { for (j = 0; j < MAX_BRACES; j++) { if (!braceOrder[j]) { braceOrder[j] = i; EnableWindow(GetDlgItem(hwnd, braceList[i].idCtrl), 1); if (j) EnableWindow(GetDlgItem(hwnd, braceList[braceOrder[j - 1]].idCtrl), 0); break; } } break; } } } else if (tmp[mir_strlen(tmp) - 1] == ')') { for (j = 0; j < MAX_BRACES; j++) { if (!braceOrder[j]) { EnableWindow(GetDlgItem(hwnd, braceList[braceOrder[j - 1]].idCtrl), 0); if (j > 1) EnableWindow(GetDlgItem(hwnd, braceList[braceOrder[j - 2]].idCtrl), 1); braceOrder[j - 1] = 0; break; } } } } else { for (j = 0; j < MAX_BRACES; j++) { if (!braceOrder[j]) break; EnableWindow(GetDlgItem(hwnd, braceList[braceOrder[j]].idCtrl), 0); } } } break; case IDOK: CMStringA replacedString; char str2replace[MAX_STRING_LENGTH]; int error; if (GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING))) { GetDlgItemTextA(hwnd, IDC_STRING, str2replace, _countof(str2replace)); switch (stringReplacer(str2replace, replacedString, NULL)) { case ERROR_NO_LINE_AFTER_VAR_F: replacedString.Format("ERROR: no %s", "%line or %wholeline or %lastline after %fn"); error = 1; break; case ERROR_LINE_NOT_READ: replacedString.Format("ERROR: file couldnt be opened "); error = 1; break; case ERROR_NO_FILE: replacedString.Format("ERROR: no file specified in settings"); error = 1; break; default: error = 0; } SetDlgItemTextA(hwnd, IDC_ANSWER, replacedString); } } break; } return FALSE; }
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); }
INT_PTR CALLBACK MraSelectEMailDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM lParam) { MraSelectEMailDlgData *dat = (MraSelectEMailDlgData*)GetWindowLongPtr(hWndDlg, GWLP_USERDATA); switch (message) { case WM_INITDIALOG: TranslateDialogDefault(hWndDlg); dat = (MraSelectEMailDlgData*)lParam; { BOOL bMRAOnly; SetWindowLongPtr(hWndDlg, GWLP_USERDATA, (LONG_PTR)lParam); HWND hWndList = GetDlgItem(hWndDlg, IDC_LIST_EMAILS); switch (dat->dwType) { case MRA_SELECT_EMAIL_TYPE_SEND_POSTCARD: bMRAOnly = FALSE; break; case MRA_SELECT_EMAIL_TYPE_VIEW_ALBUM: case MRA_SELECT_EMAIL_TYPE_READ_BLOG: bMRAOnly = TRUE; break; default: bMRAOnly = FALSE; break; } LPSTR lpszProto = dat->hContact ? GetContactProto(dat->hContact) : dat->ppro->m_szModuleName; AddContactEMailToListParam(dat->hContact, bMRAOnly, lpszProto, "e-mail", hWndList); AddContactEMailToListParam(dat->hContact, bMRAOnly, "UserInfo", "e-mail", hWndList); AddContactEMailToListParam(dat->hContact, bMRAOnly, "UserInfo", "Mye-mail", hWndList); AddContactEMailToListParam(dat->hContact, bMRAOnly, "UserInfo", "Companye-mail", hWndList); AddContactEMailToListParam(dat->hContact, bMRAOnly, "UserInfo", "MyCompanye-mail", hWndList); } return TRUE; case WM_CLOSE: DestroyWindow(hWndDlg); break; case WM_DESTROY: SetWindowLongPtr(hWndDlg, GWLP_USERDATA, 0); mir_free(dat); EndDialog(hWndDlg, NO_ERROR); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_LIST_EMAILS: if (HIWORD(wParam) == LBN_DBLCLK) SendMessage(hWndDlg, WM_COMMAND, MAKEWPARAM(IDOK, BN_CLICKED), (LPARAM)GetDlgItem(hWndDlg, IDOK)); break; case IDOK: { CMStringA szEmail; WCHAR wszBuff[MAX_PATH]; SendDlgItemMessage(hWndDlg, IDC_LIST_EMAILS, LB_GETTEXT, SendDlgItemMessage(hWndDlg, IDC_LIST_EMAILS, LB_GETCURSEL, 0, 0), (LPARAM)wszBuff); szEmail = wszBuff; szEmail.MakeLower(); switch (dat->dwType) { case MRA_SELECT_EMAIL_TYPE_SEND_POSTCARD: { CMStringA szUrl; szUrl.Format("http://cards.mail.ru/event.html?rcptname=%s&rcptemail=%s", pcli->pfnGetContactDisplayName(dat->hContact, 0), szEmail); dat->ppro->MraMPopSessionQueueAddUrl(dat->ppro->hMPopSessionQueue, szUrl); } break; case MRA_SELECT_EMAIL_TYPE_VIEW_ALBUM: dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_FOTO_URL, szEmail); break; case MRA_SELECT_EMAIL_TYPE_READ_BLOG: dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_BLOGS_URL, szEmail); break; case MRA_SELECT_EMAIL_TYPE_VIEW_VIDEO: dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_VIDEO_URL, szEmail); break; case MRA_SELECT_EMAIL_TYPE_ANSWERS: dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_ANSWERS_URL, szEmail); break; case MRA_SELECT_EMAIL_TYPE_WORLD: dat->ppro->MraMPopSessionQueueAddUrlAndEMail(dat->ppro->hMPopSessionQueue, MRA_WORLD_URL, szEmail); break; } } //break; case IDCANCEL: DestroyWindow(hWndDlg); break; default: break; } break; default: break; } return FALSE; }
INT_PTR CSkypeProto::GetEventText(WPARAM, LPARAM lParam) { DBEVENTGETTEXT *pEvent = (DBEVENTGETTEXT *)lParam; CMStringA szText; BOOL bUseBB = db_get_b(NULL, pEvent->dbei->szModule, "UseBBCodes", 1); switch (pEvent->dbei->eventType) { case SKYPE_DB_EVENT_TYPE_EDITED_MESSAGE: { JSONNode jMsg = JSONNode::parse((char*)pEvent->dbei->pBlob); if (jMsg) { JSONNode &jOriginalMsg = jMsg["original_message"]; szText.AppendFormat(bUseBB ? Translate("[b]Original message:[/b]\n%s\n") : Translate("Original message:\n%s\n"), mir_utf8decodeA(jOriginalMsg["text"].as_string().c_str())); JSONNode &jEdits = jMsg["edits"]; for (auto it = jEdits.begin(); it != jEdits.end(); ++it) { const JSONNode &jEdit = *it; time_t time = jEdit["time"].as_int(); char szTime[MAX_PATH]; strftime(szTime, sizeof(szTime), "%X %x", localtime(&time)); szText.AppendFormat(bUseBB ? Translate("[b]Edited at %s:[/b]\n%s\n") : Translate("Edited at %s:\n%s\n"), szTime, mir_utf8decodeA(jEdit["text"].as_string().c_str())); } } else { szText = INVALID_DATA; } break; } case SKYPE_DB_EVENT_TYPE_CALL_INFO: { HXML xml = xmlParseString(ptrT(mir_utf8decodeT((char*)pEvent->dbei->pBlob)), 0, _T("partlist")); if (xml != NULL) { ptrA type(mir_t2a(xmlGetAttrValue(xml, _T("type")))); bool bType = (!mir_strcmpi(type, "started")) ? 1 : 0; time_t callDuration = 0; for (int i = 0; i < xmlGetChildCount(xml); i++) { HXML xmlPart = xmlGetNthChild(xml, _T("part"), i); if (xmlPart != NULL) { HXML xmlDuration = xmlGetChildByPath(xmlPart, _T("duration"), 0); if (xmlDuration != NULL) { callDuration = _ttol(xmlGetText(xmlDuration)); xmlDestroyNode(xmlDuration); xmlDestroyNode(xmlPart); break; } xmlDestroyNode(xmlPart); } } if (bType) { szText = Translate("Call"); } else { if (callDuration == 0) { szText = Translate("Call missed"); } else { char szTime[100]; strftime(szTime, sizeof(szTime), "%X", gmtime(&callDuration)); szText.Format(Translate("Call ended (%s)"), szTime); } } xmlDestroyNode(xml); } else { szText = INVALID_DATA; } break; } case SKYPE_DB_EVENT_TYPE_FILETRANSFER_INFO: { HXML xml = xmlParseString(ptrT(mir_utf8decodeT((char*)pEvent->dbei->pBlob)), 0, _T("files")); if (xml != NULL) { for (int i = 0; i < xmlGetChildCount(xml); i++) { LONGLONG fileSize = 0; HXML xmlNode = xmlGetNthChild(xml, _T("file"), i); if (xmlNode != NULL) { fileSize = _ttol(xmlGetAttrValue(xmlNode, _T("size"))); char *fileName = _T2A(xmlGetText(xmlNode)); if (fileName != NULL) { szText.AppendFormat(Translate("File transfer:\n\tFile name: %s \n\tSize: %lld bytes \n"), fileName, fileSize); } xmlDestroyNode(xmlNode); } } xmlDestroyNode(xml); } else { szText = INVALID_DATA; } break; } case SKYPE_DB_EVENT_TYPE_MOJI: case SKYPE_DB_EVENT_TYPE_URIOBJ: { HXML xml = xmlParseString(ptrT(mir_utf8decodeT((char*)pEvent->dbei->pBlob)), 0, _T("URIObject")); if (xml != NULL) { szText.Append(_T2A(xmlGetText(xml))); HXML xmlA = xmlGetChildByPath(xml, _T("a"), 0); if (xmlA != NULL) { szText += _T2A(xmlGetAttrValue(xmlA, _T("href"))); xmlDestroyNode(xmlA); } xmlDestroyNode(xml); } else { szText = INVALID_DATA; } break; } case SKYPE_DB_EVENT_TYPE_INCOMING_CALL: { szText = Translate("Incoming call"); break; } case SKYPE_DB_EVENT_TYPE_UNKNOWN: { szText.Format(Translate("Unknown event, please send this text for developer: \"%s\""), mir_utf8decodeA((char*)pEvent->dbei->pBlob)); break; } default: { szText = ptrA(mir_utf8decodeA((char*)pEvent->dbei->pBlob)); } } switch(pEvent->datatype) { case DBVT_TCHAR: { return (INT_PTR)mir_a2t(szText); } case DBVT_ASCIIZ: { return (INT_PTR)szText.Detach(); } case DBVT_UTF8: { return (INT_PTR)mir_utf8encode(szText); } default: { return NULL; } } }
// Поиск контакта HANDLE CMraProto::MraWPRequestW(MCONTACT hContact, DWORD dwAckType, DWORD dwRequestFlags, const CMStringA &szUser, const CMStringA &szDomain, const CMStringW &wszNickName, const CMStringW &wszFirstName, const CMStringW &wszLastName, DWORD dwSex, DWORD dwDate1, DWORD dwDate2, DWORD dwCityID, DWORD dwZodiak, DWORD dwBirthdayMonth, DWORD dwBirthdayDay, DWORD dwCountryID, DWORD dwOnline) { OutBuffer buf; CMStringA tmp; if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_USER)) { buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_USER); buf.SetLPSLowerCase(szUser); } if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DOMAIN)) { buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_DOMAIN); buf.SetLPSLowerCase(szDomain); } if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_NICKNAME)) { buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_NICKNAME); buf.SetLPSW(wszNickName); } if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_FIRSTNAME)) { buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_FIRSTNAME); buf.SetLPSW(wszFirstName); } if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_LASTNAME)) { buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_LASTNAME); buf.SetLPSW(wszLastName); } if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_SEX)) { tmp.Format("%lu", dwSex); buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_SEX); buf.SetLPS(tmp); } if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DATE1)) { tmp.Format("%lu", dwDate1); buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_DATE1); buf.SetLPS(tmp); } if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DATE2)) { tmp.Format("%lu", dwDate2); buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_DATE2); buf.SetLPS(tmp); } if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_CITY_ID)) { tmp.Format("%lu", dwCityID); buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_CITY_ID); buf.SetLPS(tmp); } if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_ZODIAC)) { tmp.Format("%lu", dwZodiak); buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_ZODIAC); buf.SetLPS(tmp); } if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY_MONTH)) { tmp.Format("%lu", dwBirthdayMonth); buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY_MONTH); buf.SetLPS(tmp); } if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY_DAY)) { tmp.Format("%lu", dwBirthdayDay); buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY_DAY); buf.SetLPS(tmp); } if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_COUNTRY_ID)) { tmp.Format("%lu", dwCountryID); buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_COUNTRY_ID); buf.SetLPS(tmp); } if (GetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_ONLINE)) { tmp.Format("%lu", dwOnline); buf.SetUL(MRIM_CS_WP_REQUEST_PARAM_ONLINE); buf.SetLPS(tmp); } return (HANDLE)MraSendQueueCMD(hSendQueueHandle, dwRequestFlags, hContact, dwAckType, NULL, 0, MRIM_CS_WP_REQUEST, buf.Data(), buf.Len()); }