static bool ClientConnect(SslHandle *ssl, const char *host) { if (SecIsValidHandle(&ssl->hContext)) { g_pSSPI->DeleteSecurityContext(&ssl->hContext); SecInvalidateHandle(&ssl->hContext); } if (MySslEmptyCache) MySslEmptyCache(); DWORD dwSSPIFlags = ISC_REQ_SEQUENCE_DETECT | ISC_REQ_REPLAY_DETECT | ISC_REQ_CONFIDENTIALITY | ISC_REQ_EXTENDED_ERROR | ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_STREAM; // Initiate a ClientHello message and generate a token. SecBuffer OutBuffers[1]; OutBuffers[0].pvBuffer = NULL; OutBuffers[0].BufferType = SECBUFFER_TOKEN; OutBuffers[0].cbBuffer = 0; SecBufferDesc OutBuffer; OutBuffer.cBuffers = _countof(OutBuffers); OutBuffer.pBuffers = OutBuffers; OutBuffer.ulVersion = SECBUFFER_VERSION; TimeStamp tsExpiry; DWORD dwSSPIOutFlags; SECURITY_STATUS scRet = g_pSSPI->InitializeSecurityContext(&hCreds, NULL, _A2T(host), dwSSPIFlags, 0, 0, NULL, 0, &ssl->hContext, &OutBuffer, &dwSSPIOutFlags, &tsExpiry); if (scRet != SEC_I_CONTINUE_NEEDED) { ReportSslError(scRet, __LINE__); return 0; } // Send response to server if there is one. if (OutBuffers[0].cbBuffer != 0 && OutBuffers[0].pvBuffer != NULL) { DWORD cbData = send(ssl->s, (char*)OutBuffers[0].pvBuffer, OutBuffers[0].cbBuffer, 0); if (cbData == SOCKET_ERROR || cbData == 0) { Netlib_Logf(NULL, "SSL failure sending connection data (%d %d)", ssl->s, WSAGetLastError()); g_pSSPI->FreeContextBuffer(OutBuffers[0].pvBuffer); return 0; } // Free output buffer. g_pSSPI->FreeContextBuffer(OutBuffers[0].pvBuffer); OutBuffers[0].pvBuffer = NULL; } return ClientHandshakeLoop(ssl, TRUE) == SEC_E_OK; }
void SmileyCategoryListType::AddAccountAsCategory(PROTOACCOUNT *acc, const CMString &defaultFile) { if (Proto_IsAccountEnabled(acc) && acc->szProtoName && IsSmileyProto(acc->szModuleName)) { CMString displayName(acc->tszAccountName ? acc->tszAccountName : _A2T(acc->szModuleName)); CMString PhysProtoName, paths; DBVARIANT dbv; if (db_get_ts(NULL, acc->szModuleName, "AM_BaseProto", &dbv) == 0) { PhysProtoName = _T("AllProto"); PhysProtoName += dbv.ptszVal; db_free(&dbv); } if (!PhysProtoName.IsEmpty()) paths = g_SmileyCategories.GetSmileyCategory(PhysProtoName) ? g_SmileyCategories.GetSmileyCategory(PhysProtoName)->GetFilename() : _T(""); if (paths.IsEmpty()) { const char *packnam = acc->szProtoName; if (mir_strcmp(packnam, "JABBER") == 0) packnam = "JGMail"; else if (strstr(packnam, "SIP") != NULL) packnam = "MSN"; char path[MAX_PATH]; mir_snprintf(path, "Smileys\\nova\\%s.msl", packnam); paths = _A2T(path); CMString patha; pathToAbsolute(paths, patha); if (_taccess(patha.c_str(), 0) != 0) paths = defaultFile; } CMString tname(_A2T(acc->szModuleName)); AddCategory(tname, displayName, acc->bIsVirtual ? smcVirtualProto : smcProto, paths); } }
void __cdecl SessionStateChange(mwSession* session, mwSessionState state, gpointer info) { CSametimeProto* proto = (CSametimeProto*)mwSession_getProperty(session, "PROTO_STRUCT_PTR"); proto->debugLog(_T("SessionStateChange() state=[%d]"), state); switch (state) { case mwSession_STARTING: break; case mwSession_HANDSHAKE: break; case mwSession_HANDSHAKE_ACK: break; case mwSession_STARTED: proto->SessionStarted(); break; case mwSession_STOPPING: if ((int)info) {// & ERR_FAILURE) { proto->showPopup((int)info); } proto->SessionStopping(); break; case mwSession_STOPPED: break; case mwSession_LOGIN_REDIR: proto->debugLog(_T("SessionStateChange() mwSession_LOGIN_REDIR info=[%s]"), _A2T((char*)info)); //options.server_name = str((char*)info); strcpy(proto->options.server_name, (char*)info); proto->LogOut(); proto->LogIn(proto->login_status, proto->m_hNetlibUser); break; case mwSession_LOGIN_CONT: break; case mwSession_LOGIN: break; case mwSession_LOGIN_ACK: break; case mwSession_UNKNOWN: break; } }
int CMsnProto::MSN_ChatInit(GCThreadData *info, const char *pszID, const char *pszTopic) { char *szNet, *szEmail; _tcsncpy(info->mChatID, _A2T(pszID), _countof(info->mChatID)); parseWLID(NEWSTR_ALLOCA(pszID), &szNet, &szEmail, NULL); info->netId = atoi(szNet); strncpy(info->szEmail, szEmail, sizeof(info->szEmail)); TCHAR szName[512]; InterlockedIncrement(&m_chatID); if (*pszTopic) _tcsncpy(szName, _A2T(pszTopic), _countof(szName)); else mir_sntprintf(szName, _T("%s %s%d"), m_tszUserName, TranslateT("Chat #"), m_chatID); GCSESSION gcw = { sizeof(gcw) }; gcw.iType = GCW_CHATROOM; gcw.pszModule = m_szModuleName; gcw.ptszName = szName; gcw.ptszID = info->mChatID; CallServiceSync(MS_GC_NEWSESSION, 0, (LPARAM)&gcw); GCDEST gcd = { m_szModuleName, info->mChatID, GC_EVENT_ADDGROUP }; GCEVENT gce = { sizeof(gce), &gcd }; for (int j = 0; j < _countof(m_ptszRoles); j++) { gce.ptszStatus = m_ptszRoles[j]; CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); } gcd.iType = GC_EVENT_CONTROL; CallServiceSync(MS_GC_EVENT, SESSION_INITDONE, (LPARAM)&gce); CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, (LPARAM)&gce); CallServiceSync(MS_GC_EVENT, WINDOW_VISIBLE, (LPARAM)&gce); mir_free((TCHAR*)gce.ptszUID); return 0; }
static void GetProtocolStrings(CMString& buffer) { PROTOACCOUNT **accList; int accCount; int i, j; Proto_EnumAccounts(&accCount, &accList); int protoCount; PROTOCOLDESCRIPTOR **protoList; Proto_EnumProtocols(&protoCount, &protoList); int protoCountMy = 0; char** protoListMy = (char**)alloca((protoCount + accCount) * sizeof(char*)); for (i = 0; i < protoCount; i++) { if (protoList[i]->type != PROTOTYPE_PROTOCOL) continue; protoListMy[protoCountMy++] = protoList[i]->szName; } for (j = 0; j < accCount; j++) { for (i = 0; i < protoCountMy; i++) if (!mir_strcmp(protoListMy[i], accList[j]->szProtoName)) break; if (i == protoCountMy) protoListMy[protoCountMy++] = accList[j]->szProtoName; } ProtoCount *protos = (ProtoCount*)alloca(sizeof(ProtoCount) * protoCountMy); memset(protos, 0, sizeof(ProtoCount) * protoCountMy); for (j = 0; j < accCount; j++) for (i = 0; i < protoCountMy; i++) if (!mir_strcmp(protoListMy[i], accList[j]->szProtoName)) { protos[i].nloaded = accList[j]->bDynDisabled != 0; if (Proto_IsAccountEnabled(accList[j])) ++protos[i].countse; else ++protos[i].countsd; break; } for (i = 0; i < protoCountMy; i++) buffer.AppendFormat(TEXT("%-24s %d - Enabled %d - Disabled %sLoaded\r\n"), (TCHAR*)_A2T(protoListMy[i]), protos[i].countse, protos[i].countsd, protos[i].nloaded ? _T("Not ") : _T("")); }
void CSametimeProto::showPopup(guint32 code) { struct mwReturnCodeDesc *rcDesc = mwGetReturnCodeDesc(code); SametimePopupEnum flag = (rcDesc->type == mwReturnCodeError ? SAMETIME_POPUP_ERROR : SAMETIME_POPUP_INFO); TCHAR buff[512]; mir_sntprintf(buff, TranslateT("%s\n\nSametime error %S\n%s"), TranslateTS(_A2T(rcDesc->name)), rcDesc->codeString, TranslateTS(_A2T(rcDesc->description))); showPopup(buff, flag); debugLog(buff); g_free(rcDesc->codeString); g_free(rcDesc->name); g_free(rcDesc->description); g_free(rcDesc); }
void SmileyCategoryListType::AddContactTransportAsCategory(MCONTACT hContact, const CMString &defaultFile) { char *proto = GetContactProto(hContact); if (proto == NULL) return; DBVARIANT dbv; if (!db_get_ts(hContact, proto, "Transport", &dbv)) { if (dbv.ptszVal[0] == '\0') { db_free(&dbv); return; } char *trsp = mir_strdup(_T2A(dbv.ptszVal)); _strlwr(trsp); const char *packname = NULL; if (strstr(trsp, "msn") != NULL) packname = "msn"; else if (strstr(trsp, "icq") != NULL) packname = "icq"; else if (strstr(trsp, "yahoo") != NULL) packname = "yahoo"; else if (strstr(trsp, "aim") != NULL) packname = "aim"; else if (strstr(trsp, "lcs") != NULL) packname = "msn"; mir_free(trsp); CMString displayName = dbv.ptszVal; if (packname != NULL) { char path[MAX_PATH]; mir_snprintf(path, "Smileys\\nova\\%s.msl", packname); CMString paths = _A2T(path), patha; pathToAbsolute(paths, patha); if (_taccess(patha.c_str(), 0) != 0) paths = defaultFile; AddCategory(displayName, displayName, smcTransportProto, paths); } else AddCategory(displayName, displayName, smcTransportProto, defaultFile); db_free(&dbv); } }
/* void *p should always be a struct of type update_avatar */ void TwitterProto::UpdateAvatarWorker(void *p) { if(p == 0) return; std::auto_ptr<update_avatar> data( static_cast<update_avatar*>(p)); DBVARIANT dbv = {0}; // db_get_s returns 0 when it suceeds, so if this suceeds it will return 0, or false. // therefore if it returns 1, or true, we want to return as there is no such user. // as a side effect, dbv now has the username in it i think if(db_get_ts(data->hContact,m_szModuleName,TWITTER_KEY_UN,&dbv)) return; std::string ext = data->url.substr(data->url.rfind('.')); // finds the filetype of the avatar std::tstring filename = GetAvatarFolder() + _T('\\') + dbv.ptszVal + (TCHAR*)_A2T(ext.c_str()); // local filename and path db_free(&dbv); PROTO_AVATAR_INFORMATIONT ai = {sizeof(ai)}; ai.hContact = data->hContact; ai.format = ProtoGetAvatarFormat(filename.c_str()); if (ai.format == PA_FORMAT_UNKNOWN) { debugLogA( _T("***** Update avatar: Terminated for this contact, extension format unknown for %s"), data->url.c_str()); return; // lets just ignore unknown formats... if not it crashes miranda. should probably speak to borkra about this. } _tcsncpy(ai.filename,filename.c_str(),MAX_PATH); // puts the local file name in the avatar struct, to a max of 260 chars (as of now) debugLogA( _T("***** Updating avatar: %s"), data->url.c_str()); WaitForSingleObjectEx(avatar_lock_,INFINITE,true); if(CallService(MS_SYSTEM_TERMINATED,0,0)) // if miranda is shutting down... { debugLogA( _T("***** Terminating avatar update early: %s"),data->url.c_str()); return; } if(save_url(hAvatarNetlib_,data->url,filename)) { db_set_s(data->hContact,m_szModuleName,TWITTER_KEY_AV_URL,data->url.c_str()); ProtoBroadcastAck(data->hContact,ACKTYPE_AVATAR,ACKRESULT_SUCCESS,&ai,0); } else ProtoBroadcastAck(data->hContact,ACKTYPE_AVATAR,ACKRESULT_FAILED, &ai,0); ReleaseMutex(avatar_lock_); debugLogA( _T("***** Done avatar: %s"),data->url.c_str()); }
int ShowPopup(HANDLE hContact, SESSION_INFO *si, HICON hIcon, char* pszProtoName, TCHAR* pszRoomName, COLORREF crBkg, const TCHAR* fmt, ...) { POPUPDATAT pd = { 0 }; va_list marker; static TCHAR szBuf[4 * 1024]; if (!fmt || lstrlen(fmt) == 0 || lstrlen(fmt) > 2000) return 0; va_start(marker, fmt); mir_vsntprintf(szBuf, SIZEOF(szBuf), fmt, marker); va_end(marker); pd.lchContact = hContact; if (hIcon) pd.lchIcon = hIcon; else pd.lchIcon = LoadIconEx(IDI_CHANMGR, "window", 0, 0); PROTOACCOUNT *pa = ProtoGetAccount(pszProtoName); mir_sntprintf(pd.lptzContactName, MAX_CONTACTNAME - 1, _T("%s - %s"), (pa == NULL) ? _A2T(pszProtoName) : pa->tszAccountName, pcli->pfnGetContactDisplayName(hContact, 0)); lstrcpyn(pd.lptzText, TranslateTS(szBuf), MAX_SECONDLINE); pd.iSeconds = g_Settings.iPopupTimeout; if (g_Settings.iPopupStyle == 2) { pd.colorBack = 0; pd.colorText = 0; } else if (g_Settings.iPopupStyle == 3) { pd.colorBack = g_Settings.crPUBkgColour; pd.colorText = g_Settings.crPUTextColour; } else { pd.colorBack = g_Settings.crLogBackground; pd.colorText = crBkg; } pd.PluginWindowProc = PopupDlgProc; pd.PluginData = si; return PUAddPopupT(&pd); }
std::wstring& MirandaUtils::getDisplayName() { if (displayName.size()>0){ //displayName is now inited return displayName; } displayName.append(L"Miranda NG v."); char mirandaVersion[128]; CallService(MS_SYSTEM_GETVERSIONTEXT, (WPARAM)SIZEOF(mirandaVersion), (LPARAM)mirandaVersion); displayName.append(_A2T(mirandaVersion)); displayName.append(L" ("); displayName.append(getProfileName()); displayName.append(L")"); return displayName; }
int ShowPopup(MCONTACT hContact, SESSION_INFO *si, HICON hIcon, char *pszProtoName, TCHAR*, COLORREF crBkg, const TCHAR *fmt, ...) { static TCHAR szBuf[4 * 1024]; if (!fmt || fmt[0] == 0 || mir_tstrlen(fmt) > 2000) return 0; va_list marker; va_start(marker, fmt); mir_vsntprintf(szBuf, 4096, fmt, marker); va_end(marker); POPUPDATAT pd = { 0 }; pd.lchContact = hContact; if (hIcon) pd.lchIcon = hIcon; else pd.lchIcon = LoadIconEx("window", FALSE); PROTOACCOUNT *pa = Proto_GetAccount(pszProtoName); mir_sntprintf(pd.lptzContactName, _T("%s - %s"), (pa == NULL) ? _A2T(pszProtoName) : pa->tszAccountName, cli.pfnGetContactDisplayName(hContact, 0)); mir_tstrncpy(pd.lptzText, TranslateTS(szBuf), _countof(pd.lptzText)); pd.iSeconds = g_Settings->iPopupTimeout; if (g_Settings->iPopupStyle == 2) { pd.colorBack = 0; pd.colorText = 0; } else if (g_Settings->iPopupStyle == 3) { pd.colorBack = g_Settings->crPUBkgColour; pd.colorText = g_Settings->crPUTextColour; } else { pd.colorBack = g_Settings->crLogBackground; pd.colorText = crBkg; } pd.PluginWindowProc = PopupDlgProc; pd.PluginData = si; return PUAddPopupT(&pd); }
void DBDataManage(MCONTACT hContact, WORD Mode, WPARAM wParam, LPARAM) { LIST<char> arSettings(10); // get all the settings and stored them in a temporary list DBCONTACTENUMSETTINGS dbces; dbces.lParam = (LPARAM)&arSettings; dbces.pfnEnumProc = GetWeatherDataFromDB; dbces.szModule = WEATHERCONDITION; CallService(MS_DB_CONTACT_ENUMSETTINGS, hContact, (LPARAM)&dbces); // begin deleting settings for (int i = arSettings.getCount() - 1; i >= 0; i--) { char *szSetting = arSettings[i]; DBVARIANT dbv; if (!db_get_ts(hContact, WEATHERCONDITION, szSetting, &dbv)) { switch (Mode) { case WDBM_REMOVE: db_unset(hContact, WEATHERCONDITION, szSetting); break; case WDBM_DETAILDISPLAY: // skip the "WeatherInfo" variable if (!mir_strcmp(szSetting, "WeatherInfo") || !mir_strcmp(szSetting, "Ignore") || szSetting[0] == '#') continue; HWND hList = GetDlgItem((HWND)wParam, IDC_DATALIST); LV_ITEM lvi = { 0 }; lvi.mask = LVIF_TEXT | LVIF_PARAM; lvi.lParam = i; lvi.pszText = TranslateTS(_A2T(szSetting)); lvi.iItem = ListView_InsertItem(hList, &lvi); lvi.pszText = dbv.ptszVal; ListView_SetItemText(hList, lvi.iItem, 1, dbv.ptszVal); break; } db_free(&dbv); } mir_free(szSetting); } }
/** * name: ProtoIcon * class: CPsTreeItem * desc: check if current tree item name is a protocol name and return its icon if so * params: none * return: nothing **/ HICON CPsTreeItem::ProtoIcon() { PROTOACCOUNT **pa; int ProtoCount; if (!CallService(MS_PROTO_ENUMACCOUNTS, (WPARAM)&ProtoCount, (LPARAM)&pa)) { if (_pszName) { for (int i = 0; i < ProtoCount; i++) { if (!mir_tcsnicmp(pa[i]->tszAccountName, _A2T(_pszName), mir_tstrlen(pa[i]->tszAccountName))) { CHAR szIconID[MAX_PATH]; mir_snprintf(szIconID, SIZEOF(szIconID), "core_status_%s1", pa[i]->szModuleName); HICON hIco = Skin_GetIcon(szIconID); if (!hIco) hIco = (HICON)CallProtoService(pa[i]->szModuleName, PS_LOADICON, PLI_PROTOCOL, NULL); return hIco; } } } } return NULL; }
/** * name: ProtoIcon * class: CPsTreeItem * desc: check if current tree item name is a protocol name and return its icon if so * params: none * return: nothing **/ HICON CPsTreeItem::ProtoIcon() { if (!_pszName) return NULL; PROTOACCOUNT **pa; int ProtoCount; Proto_EnumAccounts(&ProtoCount, &pa); for (int i = 0; i < ProtoCount; i++) { if (!mir_tstrncmpi(pa[i]->tszAccountName, _A2T(_pszName), mir_tstrlen(pa[i]->tszAccountName))) { CHAR szIconID[MAX_PATH]; mir_snprintf(szIconID, "core_status_%s1", pa[i]->szModuleName); HICON hIco = IcoLib_GetIcon(szIconID); if (!hIco) hIco = (HICON)CallProtoService(pa[i]->szModuleName, PS_LOADICON, PLI_PROTOCOL, NULL); return hIco; } } return NULL; }
void LoadBassLibrary(TCHAR CurrBassPath[MAX_PATH]) { hBass = LoadLibrary(CurrBassPath); if (hBass != NULL) { newBass = (BASS_SetConfig(BASS_CONFIG_DEV_DEFAULT, TRUE) != 0); // will use new "Default" device DBVARIANT dbv = { 0 }; BASS_DEVICEINFO info; if (!db_get_ts(NULL, ModuleName, OPT_OUTDEVICE, &dbv)) for (int i = 1; BASS_GetDeviceInfo(i, &info); i++) if (!mir_tstrcmp(dbv.ptszVal, _A2T(info.name))) device = i; db_free(&dbv); sndLimSnd = db_get_b(NULL, ModuleName, OPT_MAXCHAN, MAXCHAN); if (sndLimSnd > MAXCHAN) sndLimSnd = MAXCHAN; TimeWrd1 = db_get_w(NULL, ModuleName, OPT_TIME1, 0); TimeWrd2 = db_get_w(NULL, ModuleName, OPT_TIME2, 0); QuietTime = db_get_b(NULL, ModuleName, OPT_QUIETTIME, 0); EnPreview = db_get_b(NULL, ModuleName, OPT_PREVIEW, 0); StatMask = db_get_w(NULL, ModuleName, OPT_STATUS, 0x3ff); BASS_Init(device, 44100, 0, pcli->hwndContactList, NULL); Volume = db_get_b(NULL, ModuleName, OPT_VOLUME, 33); BASS_SetConfig(BASS_CONFIG_GVOL_STREAM, Volume * 100); hPlaySound = HookEvent(ME_SKIN_PLAYINGSOUND, OnPlaySnd); CreateFrame(); } else { FreeLibrary(hBass); hBass = NULL; } }
static int OnContactSettingChanged(WPARAM hContact, LPARAM lParam) { if (hContact == NULL) return 0; DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam; if (cws && cws->szSetting && !mir_strcmp(cws->szSetting, "MirVer")) { switch (cws->value.type) { case DBVT_UTF8: ApplyFingerprintImage(hContact, ptrT(mir_utf8decodeT(cws->value.pszVal))); break; case DBVT_ASCIIZ: ApplyFingerprintImage(hContact, _A2T(cws->value.pszVal)); break; case DBVT_WCHAR: ApplyFingerprintImage(hContact, cws->value.pwszVal); break; default: ApplyFingerprintImage(hContact, NULL); } } return 0; }
static MCONTACT convertContact(MCONTACT hContact) { // Check what protocol this contact belongs to char szProto[100]; if (myGetS(hContact, "Protocol", "p", szProto)) return INVALID_CONTACT_ID; // Protocol installed? if (!IsProtocolLoaded(szProto)) return INVALID_CONTACT_ID; // Is contact in database? char* pszUniqueSetting = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); // Skip protocols with no unique id setting (some non IM protocols return NULL) MCONTACT hDst = INVALID_CONTACT_ID; if (pszUniqueSetting && (INT_PTR)pszUniqueSetting != CALLSERVICE_NOTFOUND) { DBVARIANT dbv; if (!myGet(hContact, szProto, pszUniqueSetting, &dbv)) { switch (dbv.type) { case DBVT_DWORD: hDst = HContactFromNumericID(szProto, pszUniqueSetting, dbv.dVal); break; case DBVT_ASCIIZ: hDst = HContactFromID(szProto, pszUniqueSetting, _A2T(dbv.pszVal)); break; case DBVT_WCHAR: hDst = HContactFromID(szProto, pszUniqueSetting, dbv.ptszVal); break; } srcDb->FreeVariant(&dbv); } } return hDst; }
static INT_PTR SetMyAvatar(WPARAM wParam, LPARAM lParam) { return avSetMyAvatar((char*)wParam, _A2T((const char*)lParam)); }
void __cdecl CYahooProto::get_status_thread(void *param) { int l; DBVARIANT dbv; char *gm = NULL, *sm = NULL, *fm; MCONTACT hContact = (MCONTACT)param; Sleep(150); /* Check Yahoo Games Message */ if (!getString(hContact, "YGMsg", &dbv)) { gm = strdup(dbv.pszVal); db_free(&dbv); } if (!db_get_s(hContact, "CList", "StatusMsg", &dbv)) { if (lstrlenA(dbv.pszVal) >= 1) sm = strdup(dbv.pszVal); db_free(&dbv); } else { int status = getWord(hContact, "YStatus", (WORD)YAHOO_STATUS_OFFLINE); sm = yahoo_status_code(yahoo_status(status)); if (sm) sm = strdup(sm); /* we need this to go global FREE later */ } l = 0; if (gm) l += lstrlenA(gm) + 3; l += lstrlenA(sm) + 1; fm = (char *)malloc(l); fm[0] = '\0'; if (gm && lstrlenA(gm) > 0) { /* BAH YAHOO SUCKS! WHAT A PAIN! find first carriage return add status message then add the rest */ char *c = strchr(gm, '\r'); if (c != NULL) { lstrcpynA(fm, gm, c - gm + 1); fm[c - gm + 1] = '\0'; } else lstrcpyA(fm, gm); if (sm) { lstrcatA(fm, ": "); lstrcatA(fm, sm); } if (c != NULL) lstrcatA(fm, c); } else if (sm) { lstrcatA(fm, sm); } FREE(sm); ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, (HANDLE)1, (LPARAM)(TCHAR*)_A2T(fm)); }
int __cdecl CYahooProto::SetStatus(int iNewStatus) { LOG(("[SetStatus] New status %S", pcli->pfnGetStatusModeDescription(iNewStatus, 0))); if (iNewStatus == ID_STATUS_OFFLINE) { logout(); } else if (!m_bLoggedIn) { DBVARIANT dbv; int err = 0; char errmsg[80]; if (m_iStatus == ID_STATUS_CONNECTING) return 0; YAHOO_utils_logversion(); /* * Load Yahoo ID from the database. */ if (!getString(YAHOO_LOGINID, &dbv)) { if (lstrlenA(dbv.pszVal) > 0) lstrcpynA(m_yahoo_id, dbv.pszVal, 255); else err++; db_free(&dbv); } else { ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_BADUSERID); err++; } if (err) lstrcpynA(errmsg, Translate("Please enter your Yahoo ID in Options/Network/Yahoo"), 80); else { if (!getString(YAHOO_PASSWORD, &dbv)) { if (lstrlenA(dbv.pszVal) > 0) lstrcpynA(m_password, dbv.pszVal, 255); else err++; db_free(&dbv); } else { ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_WRONGPASSWORD); err++; } if (err) lstrcpynA(errmsg, Translate("Please enter your Yahoo password in Options/Network/Yahoo"), 80); } if (err != 0) { BroadcastStatus(ID_STATUS_OFFLINE); ShowError(TranslateT("Yahoo Login Error"), _A2T(errmsg)); return 0; } if (iNewStatus == ID_STATUS_OFFLINE) iNewStatus = ID_STATUS_ONLINE; FREE(m_pw_token); // No Token yet. if (!getString(YAHOO_PWTOKEN, &dbv)) { if (lstrlenA(dbv.pszVal) > 0) m_pw_token = strdup(dbv.pszVal); db_free(&dbv); } m_startStatus = iNewStatus; //reset the unread email count. We'll get a new packet since we are connecting. m_unreadMessages = 0; BroadcastStatus(ID_STATUS_CONNECTING); iNewStatus = (iNewStatus == ID_STATUS_INVISIBLE) ? YAHOO_STATUS_INVISIBLE : YAHOO_STATUS_AVAILABLE; ForkThread(&CYahooProto::server_main, (void *)iNewStatus); } else if (iNewStatus == ID_STATUS_INVISIBLE) { /* other normal away statuses are set via setaway */ BroadcastStatus(iNewStatus); set_status(m_iStatus, NULL, (m_iStatus != ID_STATUS_ONLINE) ? 1 : 0); } else { /* clear out our message just in case, STUPID AA! */ FREE(m_startMsg); /* now tell miranda that we are Online, don't tell Yahoo server yet though! */ BroadcastStatus(iNewStatus); } return 0; }
void __cdecl CJabberProto::FileServerThread(filetransfer *ft) { debugLogA("Thread started: type=file_send"); ThreadData info(this, NULL); ft->type = FT_OOB; NETLIBBIND nlb = { 0 }; nlb.cbSize = sizeof(NETLIBBIND); nlb.pfnNewConnectionV2 = JabberFileServerConnection; nlb.pExtra = this; nlb.wPort = 0; // Use user-specified incoming port ranges, if available info.s = (HANDLE)CallService(MS_NETLIB_BINDPORT, (WPARAM)m_hNetlibUser, (LPARAM)&nlb); if (info.s == NULL) { debugLogA("Cannot allocate port to bind for file server thread, thread ended."); ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0); delete ft; return; } ft->s = info.s; debugLogA("ft->s = %d", info.s); HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); ft->hFileEvent = hEvent; TCHAR szPort[20]; mir_sntprintf(szPort, _countof(szPort), _T("%d"), nlb.wPort); JABBER_LIST_ITEM *item = ListAdd(LIST_FILE, szPort); item->ft = ft; TCHAR *ptszResource = ListGetBestClientResourceNamePtr(ft->jid); if (ptszResource != NULL) { ft->state = FT_CONNECTING; for (int i = 0; i < ft->std.totalFiles && ft->state != FT_ERROR && ft->state != FT_DENIED; i++) { ft->std.currentFileNumber = i; ft->state = FT_CONNECTING; if (ft->httpPath) mir_free(ft->httpPath); ft->httpPath = NULL; TCHAR *p; if ((p = _tcschr(ft->std.ptszFiles[i], '\\')) != NULL) p++; else p = ft->std.ptszFiles[i]; ptrA pFileName(mir_urlEncode(T2Utf(p))); if (pFileName != NULL) { ft->szId = JabberId2string(SerialNext()); ptrA myAddr; if (m_options.BsDirect && m_options.BsDirectManual) myAddr = getStringA("BsDirectAddr"); if (myAddr == NULL) myAddr = (char*)CallService(MS_NETLIB_ADDRESSTOSTRING, 1, nlb.dwExternalIP); char szAddr[256]; mir_snprintf(szAddr, _countof(szAddr), "http://%s:%d/%s", myAddr, nlb.wPort, pFileName); size_t len = mir_tstrlen(ptszResource) + mir_tstrlen(ft->jid) + 2; TCHAR *fulljid = (TCHAR *)alloca(sizeof(TCHAR) * len); mir_sntprintf(fulljid, len, _T("%s/%s"), ft->jid, ptszResource); XmlNodeIq iq(_T("set"), ft->szId, fulljid); HXML query = iq << XQUERY(JABBER_FEAT_OOB); query << XCHILD(_T("url"), _A2T(szAddr)); query << XCHILD(_T("desc"), ft->szDescription); m_ThreadInfo->send(iq); debugLogA("Waiting for the file to be sent..."); WaitForSingleObject(hEvent, INFINITE); } debugLogA("File sent, advancing to the next file..."); ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_NEXTFILE, ft, 0); } CloseHandle(hEvent); ft->hFileEvent = NULL; debugLogA("Finish all files"); } ft->s = NULL; debugLogA("ft->s is NULL"); ListRemove(LIST_FILE, szPort); switch (ft->state) { case FT_DONE: debugLogA("Finish successfully"); ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_SUCCESS, ft, 0); break; case FT_DENIED: ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_DENIED, ft, 0); break; default: // FT_ERROR: debugLogA("Finish with errors"); ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_FAILED, ft, 0); break; } debugLogA("Thread ended: type=file_send"); delete ft; }
void TSendContactsData::ShowErrorDlg(HWND hwndDlg, char* szMsg, bool bAllowRetry) { ShowWindow(hwndDlg, SW_SHOWNORMAL); EnableWindow(hwndDlg, FALSE); if (!hError) { hError = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_MSGSENDERROR), hwndDlg, ErrorDlgProc, (LPARAM)(LPTSTR)_A2T(szMsg)); if (!bAllowRetry) EnableDlgItem(hError, IDOK, FALSE); // do not allow again - fatal, could not be better } }
void IEView::navigate(const char *url) { pWebBrowser->Navigate(_A2T(url), NULL, NULL, NULL, NULL); }
void CMsnProto::MSN_ChatStart(ezxml_t xmli) { if (!mir_strcmp(xmli->txt, "thread")) return; // If Chat ID already exists, don'T create a new one const char *pszID = ezxml_txt(ezxml_child(xmli, "id")); GCThreadData* info = MSN_GetThreadByChatId(_A2T(pszID)); if (info == NULL) { info = new GCThreadData; { mir_cslock lck(m_csThreads); m_arGCThreads.insert(info); } MSN_ChatInit(info, pszID, ezxml_txt(ezxml_get(xmli, "properties", 0, "topic", -1))); MSN_StartStopTyping(info, false); } else { GCDEST gcd = { m_szModuleName, info->mChatID, GC_EVENT_CONTROL }; GCEVENT gce = { sizeof(gce), &gcd }; CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, (LPARAM)&gce); } const char *pszCreator = ezxml_txt(ezxml_get(xmli, "properties", 0, "creator", -1)); for (ezxml_t memb = ezxml_get(xmli, "members", 0, "member", -1); memb != NULL; memb = ezxml_next(memb)) { const char *mri = ezxml_txt(ezxml_child(memb, "mri")); const char *role = ezxml_txt(ezxml_child(memb, "role")); GCUserItem *gcu = NULL; for (int j = 0; j < info->mJoinedContacts.getCount(); j++) { if (!mir_strcmp(info->mJoinedContacts[j]->WLID, mri)) { gcu = info->mJoinedContacts[j]; break; } } if (!gcu) { gcu = new GCUserItem; info->mJoinedContacts.insert(gcu); strncpy(gcu->WLID, mri, sizeof(gcu->WLID)); } mir_tstrcpy(gcu->role, _A2T(role)); if (pszCreator && !mir_strcmp(mri, pszCreator)) info->mCreator = gcu; char* szEmail, *szNet; parseWLID(NEWSTR_ALLOCA(mri), &szNet, &szEmail, NULL); if (!mir_strcmpi(szEmail, GetMyUsername(atoi(szNet)))) info->mMe = gcu; gcu->btag = 1; } // Remove contacts not on list (not tagged) for (int j = 0; j < info->mJoinedContacts.getCount(); j++) { if (!info->mJoinedContacts[j]->btag) { info->mJoinedContacts.remove(j); j--; } else info->mJoinedContacts[j]->btag = 0; } }
static INT_PTR CALLBACK JabberChangePasswordDlgProc( HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam ) { CJabberProto* ppro = (CJabberProto*)GetWindowLongPtr( hwndDlg, GWLP_USERDATA ); switch ( msg ) { case WM_INITDIALOG: ppro = (CJabberProto*)lParam; SetWindowLongPtr( hwndDlg, GWLP_USERDATA, ( LONG_PTR )lParam ); WindowSetIcon( hwndDlg, ppro, "key" ); TranslateDialogDefault( hwndDlg ); if ( ppro->m_bJabberOnline && ppro->m_ThreadInfo!=NULL ) { TCHAR text[1024]; mir_sntprintf( text, SIZEOF( text ), _T("%s %s@") _T(TCHAR_STR_PARAM), TranslateT( "Set New Password for" ), ppro->m_ThreadInfo->username, ppro->m_ThreadInfo->server ); SetWindowText( hwndDlg, text ); } return TRUE; case WM_COMMAND: switch ( LOWORD( wParam )) { case IDOK: if ( ppro->m_bJabberOnline && ppro->m_ThreadInfo!=NULL ) { TCHAR newPasswd[512], text[512]; GetDlgItemText( hwndDlg, IDC_NEWPASSWD, newPasswd, SIZEOF( newPasswd )); GetDlgItemText( hwndDlg, IDC_NEWPASSWD2, text, SIZEOF( text )); if ( _tcscmp( newPasswd, text )) { MessageBox( hwndDlg, TranslateT( "New password does not match." ), TranslateT( "Change Password" ), MB_OK|MB_ICONSTOP|MB_SETFOREGROUND ); break; } GetDlgItemText( hwndDlg, IDC_OLDPASSWD, text, SIZEOF( text )); if ( _tcscmp( text, ppro->m_ThreadInfo->password )) { MessageBox( hwndDlg, TranslateT( "Current password is incorrect." ), TranslateT( "Change Password" ), MB_OK|MB_ICONSTOP|MB_SETFOREGROUND ); break; } _tcsncpy( ppro->m_ThreadInfo->newPassword, newPasswd, SIZEOF( ppro->m_ThreadInfo->newPassword )); int iqId = ppro->SerialNext(); ppro->IqAdd( iqId, IQ_PROC_NONE, &CJabberProto::OnIqResultSetPassword ); XmlNodeIq iq( _T("set"), iqId, _A2T(ppro->m_ThreadInfo->server)); HXML q = iq << XQUERY( _T(JABBER_FEAT_REGISTER)); q << XCHILD( _T("username"), ppro->m_ThreadInfo->username ); q << XCHILD( _T("password"), newPasswd ); ppro->m_ThreadInfo->send( iq ); } DestroyWindow( hwndDlg ); break; case IDCANCEL: DestroyWindow( hwndDlg ); break; } break; case WM_CLOSE: DestroyWindow( hwndDlg ); break; case WM_DESTROY: ppro->m_hwndJabberChangePassword = NULL; WindowFreeIcon( hwndDlg ); break; } return FALSE; }
static void FindFilterStrings(int enableKeywordFiltering, int current, HWND hWndParent, const OptionsPageData *page) { TCHAR pluginName[MAX_PATH]; HWND hWnd = 0; if (enableKeywordFiltering) { if (current) hWnd = page->hwnd; else { hWnd = CreateDialogIndirectParamA(page->hInst, page->pTemplate, hWndParent, page->dlgProc, page->dwInitParam); //create the options dialog page so we can parse it ShowWindow(hWnd, SW_HIDE); //make sure it's hidden } } DWORD key = GetPluginPageHash(page); //get the plugin page hash char *temp = GetPluginNameByInstance(page->hInst); GetDialogStrings(enableKeywordFiltering, key, GetPluginName(page->hInst, pluginName, SIZEOF(pluginName)), hWnd, page->ptszGroup, page->ptszTitle, page->ptszTab, _A2T(temp)); if (enableKeywordFiltering && !current) DestroyWindow(hWnd); //destroy the page, we're done with it }
BOOL CJabberProto::OnIqRequestAvatar(HXML, CJabberIqInfo *pInfo) { if (!m_options.EnableAvatars) return TRUE; int pictureType = m_options.AvatarType; if (pictureType == PA_FORMAT_UNKNOWN) return TRUE; TCHAR *szMimeType; switch (pictureType) { case PA_FORMAT_JPEG: szMimeType = _T("image/jpeg"); break; case PA_FORMAT_GIF: szMimeType = _T("image/gif"); break; case PA_FORMAT_PNG: szMimeType = _T("image/png"); break; case PA_FORMAT_BMP: szMimeType = _T("image/bmp"); break; default: return TRUE; } TCHAR szFileName[MAX_PATH]; GetAvatarFileName(NULL, szFileName, _countof(szFileName)); FILE* in = _tfopen(szFileName, _T("rb")); if (in == NULL) return TRUE; long bytes = _filelength(_fileno(in)); ptrA buffer((char*)mir_alloc(bytes * 4 / 3 + bytes + 1000)); if (buffer == NULL) { fclose(in); return TRUE; } fread(buffer, bytes, 1, in); fclose(in); ptrA str(mir_base64_encode((PBYTE)(char*)buffer, bytes)); m_ThreadInfo->send(XmlNodeIq(_T("result"), pInfo) << XQUERY(JABBER_FEAT_AVATAR) << XCHILD(_T("query"), _A2T(str)) << XATTR(_T("mimetype"), szMimeType)); return TRUE; }
INT_PTR srvVariablesHandler(WPARAM, LPARAM lParam) { ARGUMENTSINFO *ai = (ARGUMENTSINFO*)lParam; ai->flags = AIF_DONTPARSE; TCString Result; if (!mir_tstrcmp(ai->targv[0], VAR_AWAYSINCE_TIME)) { GetTimeFormat(LOCALE_USER_DEFAULT, 0, g_ProtoStates[VarParseData.szProto].AwaySince, (ai->argc > 1 && *ai->targv[1]) ? ai->targv[1] : _T("H:mm"), Result.GetBuffer(256), 256); Result.ReleaseBuffer(); } else if (!mir_tstrcmp(ai->targv[0], VAR_AWAYSINCE_DATE)) { GetDateFormat(LOCALE_USER_DEFAULT, 0, g_ProtoStates[VarParseData.szProto].AwaySince, (ai->argc > 1 && *ai->targv[1]) ? ai->targv[1] : NULL, Result.GetBuffer(256), 256); Result.ReleaseBuffer(); } else if (!mir_tstrcmp(ai->targv[0], VAR_STATDESC)) { Result = (VarParseData.Flags & VPF_XSTATUS) ? STR_XSTATUSDESC : pcli->pfnGetStatusModeDescription(g_ProtoStates[VarParseData.szProto].Status, 0); } else if (!mir_tstrcmp(ai->targv[0], VAR_MYNICK)) { if (g_MoreOptPage.GetDBValueCopy(IDC_MOREOPTDLG_MYNICKPERPROTO) && VarParseData.szProto) Result = db_get_s(NULL, VarParseData.szProto, "Nick", (TCHAR*)NULL); if (Result == NULL) Result = pcli->pfnGetContactDisplayName(NULL, 0); if (Result == NULL) Result = TranslateT("Stranger"); } else if (!mir_tstrcmp(ai->targv[0], VAR_REQUESTCOUNT)) { mir_sntprintf(Result.GetBuffer(16), 16, _T("%d"), db_get_w(ai->fi->hContact, MOD_NAME, DB_REQUESTCOUNT, 0)); Result.ReleaseBuffer(); } else if (!mir_tstrcmp(ai->targv[0], VAR_MESSAGENUM)) { mir_sntprintf(Result.GetBuffer(16), 16, _T("%d"), db_get_w(ai->fi->hContact, MOD_NAME, DB_MESSAGECOUNT, 0)); Result.ReleaseBuffer(); } else if (!mir_tstrcmp(ai->targv[0], VAR_TIMEPASSED)) { ULARGE_INTEGER ul_AwaySince, ul_Now; SYSTEMTIME st; GetLocalTime(&st); SystemTimeToFileTime(&st, (LPFILETIME)&ul_Now); SystemTimeToFileTime(g_ProtoStates[VarParseData.szProto].AwaySince, (LPFILETIME)&ul_AwaySince); ul_Now.QuadPart -= ul_AwaySince.QuadPart; ul_Now.QuadPart /= 10000000; // now it's in seconds Result.GetBuffer(256); if (ul_Now.LowPart >= 7200) // more than 2 hours mir_sntprintf(Result, 256, TranslateT("%d hours"), ul_Now.LowPart / 3600); else if (ul_Now.LowPart >= 120) // more than 2 minutes mir_sntprintf(Result, 256, TranslateT("%d minutes"), ul_Now.LowPart / 60); else mir_sntprintf(Result, 256, TranslateT("%d seconds"), ul_Now.LowPart); Result.ReleaseBuffer(); } else if (!mir_tstrcmp(ai->targv[0], VAR_PREDEFINEDMESSAGE)) { ai->flags = 0; // reset AIF_DONTPARSE flag if (ai->argc != 2) return NULL; COptPage MsgTreeData(g_MsgTreePage); COptItem_TreeCtrl *TreeCtrl = (COptItem_TreeCtrl*)MsgTreeData.Find(IDV_MSGTREE); TreeCtrl->DBToMem(CString(MOD_NAME)); for (int i = 0; i < TreeCtrl->Value.GetSize(); i++) { if (!(TreeCtrl->Value[i].Flags & TIF_GROUP) && !mir_tstrcmpi(TreeCtrl->Value[i].Title, ai->targv[1])) { Result = TreeCtrl->Value[i].User_Str1; break; } } if (Result == NULL) // if we didn't find a message with specified title return NULL; // return it now, as later we change NULL to "" } else if (!mir_tstrcmp(ai->targv[0], VAR_PROTOCOL)) { if (VarParseData.szProto) { CString AnsiResult; CallProtoService(VarParseData.szProto, PS_GETNAME, 256, (LPARAM)AnsiResult.GetBuffer(256)); AnsiResult.ReleaseBuffer(); Result = _A2T(AnsiResult); } if (Result == NULL) // if we didn't find a message with specified title return NULL; // return it now, as later we change NULL to "" } TCHAR *szResult = (TCHAR*)malloc((Result.GetLen() + 1) * sizeof(TCHAR)); if (!szResult) return NULL; mir_tstrcpy(szResult, (Result != NULL) ? Result : _T("")); return (INT_PTR)szResult; }
INT_PTR TTBSetOptions(WPARAM wParam, LPARAM lParam) { mir_cslock lck(csButtonsHook); TopButtonInt *b = idtopos(HIWORD(wParam)); if (b == NULL) return -1; switch (LOWORD(wParam)) { case TTBO_FLAGS: { if (b->dwFlags == lParam) return 0; DWORD retval = b->CheckFlags(lParam); if (retval & TTBBF_PUSHED) b->SetBitmap(); if (retval & TTBBF_VISIBLE) { ArrangeButtons(); b->SaveSettings(0, 0); } return 1; } case TTBO_TIPNAME: if (lParam == 0) return -1; replaceStrT(b->ptszTooltip, TranslateTS(_A2T((LPCSTR)lParam))); SendMessage(b->hwnd, BUTTONADDTOOLTIP, (WPARAM)b->ptszTooltip, BATF_UNICODE); return 1; case TTBO_ALLDATA: if (lParam) { TTBButton *lpTTB = (TTBButton*)lParam; DWORD retval = b->CheckFlags(lpTTB->dwFlags); bool changed = false; if (b->hIconUp != lpTTB->hIconUp) { b->hIconUp = lpTTB->hIconUp; changed = true; } if (b->hIconDn != lpTTB->hIconDn) { b->hIconDn = lpTTB->hIconDn; changed = true; } if (changed) b->SetBitmap(); if (retval & TTBBF_VISIBLE) { ArrangeButtons(); b->SaveSettings(0, 0); } if (b->dwFlags & TTBBF_ISLBUTTON) replaceStrT(b->ptszProgram, lpTTB->program); else replaceStr(b->pszService, lpTTB->pszService); b->lParamUp = lpTTB->lParamUp; b->wParamUp = lpTTB->wParamUp; b->lParamDown = lpTTB->lParamDown; b->wParamDown = lpTTB->wParamDown; return 1; } else return 0; default: return -1; } }
bool WhatsAppProto::Register(int state, const string &cc, const string &number, const string &code, string &ret) { string idx; DBVARIANT dbv; if (WASocketConnection::hNetlibUser == NULL) { NotifyEvent(m_tszUserName, TranslateT("Network connection error."), NULL, WHATSAPP_EVENT_CLIENT); return false; } if (!getString(WHATSAPP_KEY_IDX, &dbv)) { idx = dbv.pszVal; db_free(&dbv); } if (idx.empty()) { std::stringstream tm; tm << time(NULL); BYTE idxBuf[16]; utils::md5string(tm.str(), idxBuf); idx = std::string((const char*)idxBuf, 16); setString(WHATSAPP_KEY_IDX, idx.c_str()); } CMStringA url = WARegister::RequestCodeUrl(cc + number, code); if (url.IsEmpty()) return false; NETLIBHTTPREQUEST nlhr = { sizeof(NETLIBHTTPREQUEST) }; nlhr.requestType = REQUEST_POST; nlhr.szUrl = url.GetBuffer(); nlhr.headers = s_registerHeaders; nlhr.headersCount = _countof(s_registerHeaders); nlhr.flags = NLHRF_HTTP11 | NLHRF_GENERATEHOST | NLHRF_REMOVEHOST | NLHRF_SSL; NETLIBHTTPREQUEST* pnlhr = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)WASocketConnection::hNetlibUser, (LPARAM)&nlhr); const TCHAR *ptszTitle = TranslateT("Registration"); if (pnlhr == NULL) { NotifyEvent(ptszTitle, TranslateT("Registration failed. Invalid server response."), NULL, WHATSAPP_EVENT_CLIENT); return false; } debugLogA("Server response: %s", pnlhr->pData); JSONNode resp = JSONNode::parse(pnlhr->pData); if (!resp) { NotifyEvent(ptszTitle, TranslateT("Registration failed. Invalid server response."), NULL, WHATSAPP_EVENT_CLIENT); return false; } // Status = fail std::string status = resp["status"].as_string(); if (status == "fail") { std::string reason = resp["reason"].as_string(); if (reason == "stale") NotifyEvent(ptszTitle, TranslateT("Registration failed due to stale code. Please request a new code"), NULL, WHATSAPP_EVENT_CLIENT); else { CMString tmp(FORMAT, TranslateT("Registration failed. Reason: %s"), _A2T(reason.c_str())); NotifyEvent(ptszTitle, tmp, NULL, WHATSAPP_EVENT_CLIENT); } const JSONNode &tmpVal = resp["retry_after"]; if (tmpVal) { CMString tmp(FORMAT, TranslateT("Please try again in %i seconds"), tmpVal.as_int()); NotifyEvent(ptszTitle, tmp, NULL, WHATSAPP_EVENT_OTHER); } return false; } // Request code if (state == REG_STATE_REQ_CODE) { std::string pw = resp["pw"].as_string(); if (!pw.empty()) ret = pw; else if (status == "sent") NotifyEvent(ptszTitle, TranslateT("Registration code has been sent to your phone."), NULL, WHATSAPP_EVENT_OTHER); return true; } // Register if (state == REG_STATE_REG_CODE) { std::string pw = resp["pw"].as_string(); if (!pw.empty()) { ret = pw; return true; } NotifyEvent(ptszTitle, TranslateT("Registration failed."), NULL, WHATSAPP_EVENT_CLIENT); } return false; }