void mwResolve_handler_details_callback(mwServiceResolve* srvc, guint32 id, guint32 code, GList* results, gpointer data) { CSametimeProto* proto = getProtoFromMwServiceResolve(srvc); MYPROTOSEARCHRESULT mpsr; memset(&mpsr, 0, sizeof(mpsr)); mpsr.cbSize = sizeof(mpsr); mpsr.nick.a = mpsr.name; if (code == mwResolveCode_SUCCESS) { GList *ri = results, *mri; for (; ri; ri = ri->next) { mri = ((mwResolveResult *)ri->data)->matches; for (; mri; mri = mri->next) { MCONTACT hContact = proto->FindContactByUserId(((mwResolveMatch*)mri->data)->id); if (hContact) { char* name = ((mwResolveMatch*)mri->data)->name; if (name && mir_strlen(name)) { db_set_utf(hContact, proto->m_szModuleName, "Name", name); db_set_utf(hContact, proto->m_szModuleName, "Nick", name); db_set_utf(hContact, "CList", "MyHandle", name); } } } } } }
int ChangeInfoData::SaveSettingsToDb(HWND hwndDlg) { int ret = 1; for (int i = 0; i < settingCount; i++) { if (!settingData[i].changed) continue; if (!(setting[i].displayType & LIF_ZEROISVALID) && settingData[i].value==0) { ppro->delSetting(setting[i].szDbSetting); continue; } switch(setting[i].dbType) { case DBVT_ASCIIZ: if (setting[i].displayType & LIF_PASSWORD) { int nSettingLen = strlennull((char*)settingData[i].value); if (nSettingLen > 8 || nSettingLen < 1) { MessageBox(hwndDlg, TranslateT("The ICQ server does not support passwords longer than 8 characters. Please use a shorter password."), TranslateT("Change ICQ Details"), MB_OK); ret=0; break; } PwConfirmDlgParam param = { ppro, (char*)settingData[i].value }; if (IDOK != DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_PWCONFIRM), hwndDlg, PwConfirmDlgProc, (LPARAM)¶m)) { ret = 0; break; } strcpy(ppro->m_szPassword, (char*)settingData[i].value); } else { if (*(char*)settingData[i].value) db_set_utf(NULL, ppro->m_szModuleName, setting[i].szDbSetting, (char*)settingData[i].value); else ppro->delSetting(setting[i].szDbSetting); } break; case DBVT_UTF8: if (*(char*)settingData[i].value) db_set_utf(NULL, ppro->m_szModuleName, setting[i].szDbSetting, (char*)settingData[i].value); else ppro->delSetting(setting[i].szDbSetting); break; case DBVT_WORD: ppro->setWord(setting[i].szDbSetting, (WORD)settingData[i].value); break; case DBVT_BYTE: ppro->setByte(setting[i].szDbSetting, (BYTE)settingData[i].value); break; } } return ret; }
void CDropbox::RequestAccountInfo(void *p) { CDropbox *self = (CDropbox*)p; MCONTACT hContact = self->GetDefaultContact(); ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); GetCurrentAccountRequest request(token); NLHR_PTR response(request.Send(self->hNetlibConnection)); HandleJsonResponseError(response); JSONNode root = JSONNode::parse(response->pData); if (root.empty()) return; JSONNode referral_link = root.at("referral_link"); if (!referral_link.empty()) db_set_s(hContact, MODULE, "Homepage", referral_link.as_string().c_str()); JSONNode email = root.at("email"); if (!email.empty()) db_set_s(hContact, MODULE, "e-mail", email.as_string().c_str()); JSONNode name = root.at("name"); if (!name.empty()) { db_set_utf(hContact, MODULE, "FirstName", name.at("given_name").as_string().c_str()); db_set_utf(hContact, MODULE, "LastName", name.at("surname").as_string().c_str()); } JSONNode country = root.at("country"); if (!country.empty()) { std::string isocode = country.as_string(); if (isocode.empty()) db_unset(hContact, MODULE, "Country"); else { char *szCountry = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode.c_str(), 0); db_set_s(hContact, MODULE, "Country", szCountry); } } /*JSONNode quota_info = root.at("quota_info"); if (!quota_info.empty()) { ULONG lTotalQuota = quota_info.at("quota").as_int(); ULONG lNormalQuota = quota_info.at("normal").as_int(); ULONG lSharedQuota = quota_info.at("shared").as_int(); db_set_dw(hContact, MODULE, "SharedQuota", lSharedQuota); db_set_dw(hContact, MODULE, "NormalQuota", lNormalQuota); db_set_dw(hContact, MODULE, "TotalQuota", lTotalQuota); db_set_s(hContact, "CList", "StatusMsg", CMStringA(FORMAT, Translate("Free %ld of %ld MB"), (lTotalQuota - lNormalQuota) / (1024 * 1024), lTotalQuota / (1024 * 1024))); }*/ }
/** * name: toDB * class: CExImContactBase * desc: searches the database for a contact representing the one * identified by this class or creates a new one if it was not found * param: hMetaContact - a meta contact to add this contact to * return: handle of the contact if successful **/ HANDLE CExImContactBase::toDB() { // create new contact if none exists if (_hContact == INVALID_HANDLE_VALUE && _pszProto && _pszUIDKey && _dbvUID.type != DBVT_DELETED) { PROTOACCOUNT* pszAccount = 0; if (NULL == (pszAccount = ProtoGetAccount( _pszProto ))) { //account does not exist _hContact = INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE; } if (!IsAccountEnabled(pszAccount)) { ; } // create new contact _hContact = DB::Contact::Add(); if (!_hContact) { _hContact = INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE; } // Add the protocol to the new contact if (CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)_hContact, (LPARAM)_pszProto)) { DB::Contact::Delete(_hContact); _hContact = INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE; } // write uid to protocol module if (db_set(_hContact, _pszProto, _pszUIDKey, &_dbvUID)) { DB::Contact::Delete(_hContact); _hContact = INVALID_HANDLE_VALUE; return INVALID_HANDLE_VALUE; } // write nick and display name if (_pszNick) db_set_utf(_hContact, _pszProto, SET_CONTACT_NICK, _pszNick); if (_pszDisp) db_set_utf(_hContact, MOD_CLIST, SET_CONTACT_MYHANDLE, _pszDisp); // add group if (_pszGroup) { ptrT ptszGroup( mir_utf8decodeT(_pszGroup)); db_set_ts(_hContact, MOD_CLIST, "Group", ptszGroup); if ( Clist_GroupExists(ptszGroup) == NULL) { HANDLE hGroup = Clist_CreateGroup(NULL, NULL); if (hGroup) { // renaming twice is stupid but the only way to avoid error dialog telling shit like // a group with that name does exist CallService(MS_CLIST_GROUPRENAME, (WPARAM)hGroup, (LPARAM)ptszGroup); } } } } return _hContact; }
/** * name: SaveState * class: CPsTree * desc: saves the current tree to database * param: none * return: nothing **/ void CPsTree::SaveState() { CPsTreeItem *pti = CurrentItem(); if (_hWndTree && (_dwFlags & (PSTVF_LABEL_CHANGED|PSTVF_POS_CHANGED|PSTVF_STATE_CHANGED))) { SHORT i; int iItem = 0; // save all visible items WORD numErrors = SaveItemsState(TREE_ROOTITEM, TVGN_ROOT, iItem); // save all invisible items of the current subtree for (i = 0; i < _numItems; i++) { if (!_pItems[i]->Hti()) { LPSTR pszGroup; if (!IsIndexValid(_pItems[i]->Parent()) || !(pszGroup = _pItems[_pItems[i]->Parent()]->Name())) pszGroup = TREE_ROOTITEM; numErrors += _pItems[i]->DBSaveItemState(pszGroup, iItem++, DBTVIS_INVISIBLE, _dwFlags); } } // remove changed flags RemoveFlags(PSTVF_STATE_CHANGED|PSTVF_LABEL_CHANGED|PSTVF_POS_CHANGED); } // save current selected item if (pti) db_set_utf(NULL, MODNAME, SET_LASTITEM, pti->Name()); else db_unset(NULL, MODNAME, SET_LASTITEM); }
MCONTACT TwitterProto::AddToClientList(const char *name, const char *status) { // First, check if this contact exists MCONTACT hContact = UsernameToHContact(name); if (hContact) return hContact; if (in_chat_) AddChatContact(name); // If not, make a new contact! hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); if (hContact) { if (Proto_AddToContact(hContact, m_szModuleName) == 0) { setString(hContact, TWITTER_KEY_UN, name); setWord(hContact, "Status", ID_STATUS_ONLINE); db_set_utf(hContact, "CList", "StatusMsg", status); std::string url = profile_base_url(twit_.get_base_url()) + http::url_encode(name); setString(hContact, "Homepage", url.c_str()); DBVARIANT dbv; if (!getTString(TWITTER_KEY_GROUP, &dbv)) { db_set_ts(hContact, "CList", "Group", dbv.ptszVal); db_free(&dbv); } return hContact; } CallService(MS_DB_CONTACT_DELETE, hContact, 0); } return 0; }
void CSametimeProto::SaveOptions() { db_set_utf(0, m_szModuleName, "ServerName", options.server_name); db_set_utf(0, m_szModuleName, "stid", options.id); //db_set_s(0, m_szModuleName, "Nick", options.id); db_set_utf(0, m_szModuleName, "Password", options.pword); db_set_dw(0, m_szModuleName, "ServerPort", options.port); db_set_b(0, m_szModuleName, "GetServerContacts", options.get_server_contacts ? 1 : 0); db_set_dw(0, m_szModuleName, "ClientID", options.client_id); db_set_dw(0, m_szModuleName, "ClientVersionMajor", options.client_versionMajor); db_set_dw(0, m_szModuleName, "ClientVersionMinor", options.client_versionMinor); db_set_b(0, m_szModuleName, "ErrorDisplay", options.err_method); db_set_b(0, m_szModuleName, "AutoAddContacts", options.add_contacts ? 1 : 0); db_set_b(0, m_szModuleName, "EncryptSession", options.encrypt_session ? 1 : 0); db_set_b(0, m_szModuleName, "IdleAsAway", options.idle_as_away ? 1 : 0); }
void RenameModule(HANDLE hContact, const char* pszOldName, const char* pszNewName) { SettingsList settingsList; DBCONTACTENUMSETTINGS dbces = {0}; dbces.szModule = pszOldName; dbces.lParam = (LPARAM)&settingsList; dbces.pfnEnumProc = EnumSettingsProc2; int nResult = ::CallService(MS_DB_CONTACT_ENUMSETTINGS, (WPARAM)hContact, (LPARAM)&dbces); if (nResult != -1) { DBVARIANT dbv; for(unsigned i=0; i<settingsList.size(); i++) { const char* pszSetting = settingsList[i]; if (!GetSetting(hContact, pszOldName, pszSetting, &dbv)) { switch (dbv.type) { case DBVT_BYTE: db_set_b(hContact, pszNewName, pszSetting, dbv.bVal); break; case DBVT_WORD: db_set_w(hContact, pszNewName, pszSetting, dbv.wVal); break; case DBVT_DWORD: db_set_dw(hContact, pszNewName, pszSetting, dbv.dVal); break; case DBVT_ASCIIZ: db_set_s(hContact, pszNewName, pszSetting, dbv.pszVal); break; case DBVT_UTF8: db_set_utf(hContact, pszNewName, pszSetting, dbv.pszVal); break; default: assert(0); break; } db_unset(hContact, pszOldName, pszSetting); db_free(&dbv); } free((char*)settingsList[i]); } } }
void SaveOptions() { db_set_w(0, MODULENAME, "DefaultPolicy", options.default_policy); db_set_w(0, MODULENAME, "ErrorDisplay", (int)options.err_method); db_set_b(0, MODULENAME, "PrefixMessages", options.prefix_messages ? 1 : 0); db_set_b(0, MODULENAME, "MsgInline", options.msg_inline ? 1 : 0); db_set_b(0, MODULENAME, "MsgPopup", options.msg_popup ? 1 : 0); db_set_b(0, MODULENAME, "NoHistory", options.delete_history ? 1 : 0); db_set_b(0, MODULENAME, "NoSystemHistory", options.delete_systeminfo ? 1 : 0); db_set_b(0, MODULENAME, "AutoShowVerify", options.autoshow_verify ? 1 : 0); db_set_utf(0, MODULENAME, "Prefix", options.prefix); db_set_b(0, MODULENAME, "EndOffline", options.end_offline ? 1 : 0); db_set_b(0, MODULENAME, "EndWindowClose", options.end_window_close ? 1 : 0); }
void renameModule(char* oldName, char* newName, HANDLE hContact) { DBVARIANT dbv; ModuleSettingLL settinglist; ModSetLinkLinkItem *setting; if (!EnumSettings(hContact, oldName, &settinglist)) { msg(Translate("Error Loading Setting List"), modFullname); return; } setting = settinglist.first; while (setting) { if (!GetSetting(hContact, oldName, setting->name, &dbv)) { switch (dbv.type) { case DBVT_BYTE: db_set_b(hContact, newName, setting->name, dbv.bVal); break; case DBVT_WORD: db_set_w(hContact, newName, setting->name, dbv.wVal); break; case DBVT_DWORD: db_set_dw(hContact, newName, setting->name, dbv.dVal); break; case DBVT_ASCIIZ: db_set_s(hContact, newName, setting->name, dbv.pszVal); break; case DBVT_UTF8: db_set_utf(hContact, newName, setting->name, dbv.pszVal); break; case DBVT_BLOB: db_set_blob(hContact, newName, setting->name, dbv.pbVal, dbv.cpbVal); break; } db_unset(hContact, oldName, setting->name); } db_free(&dbv); setting = (ModSetLinkLinkItem *)setting->next; } FreeModuleSettingLL(&settinglist); }
INT_PTR Meta_Convert(WPARAM wParam, LPARAM lParam) { DBVARIANT dbv; char *group = 0; // Get some information about the selected contact. if ( !db_get_utf((HANDLE)wParam, "CList", "Group", &dbv)) { group = _strdup(dbv.pszVal); db_free(&dbv); } // Create a new metacontact HANDLE hMetaContact = (HANDLE)CallService(MS_DB_CONTACT_ADD,0,0); if (hMetaContact) { db_set_dw(hMetaContact, META_PROTO, META_ID,nextMetaID); db_set_dw(hMetaContact, META_PROTO, "NumContacts",0); db_set_dw(NULL, META_PROTO, "NextMetaID", ++nextMetaID); // Add the MetaContact protocol to the new meta contact CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hMetaContact, (LPARAM)META_PROTO); if (group) db_set_utf(hMetaContact, "CList", "Group", group); // Assign the contact to the MetaContact just created (and make default). if ( !Meta_Assign((HANDLE)wParam, hMetaContact, TRUE)) { MessageBox(0, TranslateT("There was a problem in assigning the contact to the MetaContact"), TranslateT("Error"), MB_ICONEXCLAMATION); CallService(MS_DB_CONTACT_DELETE, (WPARAM)hMetaContact, 0); return 0; } // hide the contact if clist groups disabled (shouldn't create one anyway since menus disabled) if ( !Meta_IsEnabled()) db_set_b(hMetaContact, "CList", "Hidden", 1); } free(group); return (INT_PTR)hMetaContact; }
/** * name: DBSaveItemState * class: CPsTreeItem * desc: saves the current treeitem to database * param: pszGroup - name of the parent item * iItemPosition - iterated index to remember the order of the tree * iState - expanded|collapsed|invisible * dwFlags - tells what to save * return: handle to new (moved) treeitem if successful or NULL otherwise **/ WORD CPsTreeItem::DBSaveItemState(LPCSTR pszGroup, int iItemPosition, UINT iState, DWORD dwFlags) { WORD numErrors = 0; // save group if ((dwFlags & PSTVF_GROUPS) && (dwFlags & PSTVF_POS_CHANGED)) numErrors += db_set_utf(NULL, MODNAME, PropertyKey(SET_ITEM_GROUP), (LPSTR)pszGroup); // save label if ((dwFlags & PSTVF_LABEL_CHANGED) && (_dwFlags & PSTVF_LABEL_CHANGED)) numErrors += db_set_ts(NULL, MODNAME, GlobalPropertyKey(SET_ITEM_LABEL), Label()); // save position if ((dwFlags & PSTVF_POS_CHANGED) && !(dwFlags & PSTVF_SORTTREE)) numErrors += db_set_b(NULL, MODNAME, PropertyKey(SET_ITEM_POS), iItemPosition); // save state if (dwFlags & PSTVF_STATE_CHANGED) numErrors += db_set_b(NULL, MODNAME, PropertyKey(SET_ITEM_STATE), _hItem ? ((iState & TVIS_EXPANDED) ? DBTVIS_EXPANDED : DBTVIS_NORMAL) : DBTVIS_INVISIBLE); RemoveFlags(PSTVF_STATE_CHANGED|PSTVF_LABEL_CHANGED|PSTVF_POS_CHANGED); return numErrors; }
void copyModule(char* module, MCONTACT hContactFrom, MCONTACT hContactTo) { ModuleSettingLL msll; EnumSettings(hContactFrom, module, &msll); ModSetLinkLinkItem *setting = msll.first; while (setting) { DBVARIANT dbv; if (!GetSetting(hContactFrom, module, setting->name, &dbv)) { switch (dbv.type) { case DBVT_BYTE: db_set_b(hContactTo, module, setting->name, dbv.bVal); break; case DBVT_WORD: db_set_w(hContactTo, module, setting->name, dbv.wVal); break; case DBVT_DWORD: db_set_dw(hContactTo, module, setting->name, dbv.dVal); break; case DBVT_ASCIIZ: db_set_s(hContactTo, module, setting->name, dbv.pszVal); break; case DBVT_UTF8: db_set_utf(hContactTo, module, setting->name, dbv.pszVal); break; case DBVT_BLOB: db_set_blob(hContactTo, module, setting->name, dbv.pbVal, dbv.cpbVal); break; } } db_free(&dbv); setting = setting->next; } FreeModuleSettingLL(&msll); }
void CIcqProto::handleXtrazNotifyResponse(DWORD dwUin, MCONTACT hContact, WORD wCookie, char* szMsg, int nMsgLen) { char *szMem, *szRes, *szEnd; int nResLen; #ifdef _DEBUG debugLogA("Received Xtraz Notify Response"); #endif szRes = strstrnull(szMsg, "<RES>"); szEnd = strstrnull(szMsg, "</RES>"); if (szRes && szEnd) { // valid response char *szNode, *szWork; szRes += 5; nResLen = szEnd - szRes; szMem = szRes = DemangleXml(szRes, nResLen); #ifdef _DEBUG debugLogA("Response: %s", szRes); #endif ProtoBroadcastAck(hContact, ICQACKTYPE_XTRAZNOTIFY_RESPONSE, ACKRESULT_SUCCESS, (HANDLE)wCookie, (LPARAM)szRes); NextVal: szNode = strstrnull(szRes, "<val srv_id="); if (szNode) szEnd = strstrnull(szNode, ">"); else szEnd = NULL; if (szNode && szEnd) { *(szEnd - 1) = '\0'; szNode += 13; //one more than the length of the string to skip ' or " too szWork = szEnd + 1; if (!stricmpnull(szNode, "cAwaySrv")) { int bChanged = FALSE; *szEnd = ' '; szNode = strstrnull(szWork, "<index>"); szEnd = strstrnull(szWork, "</index>"); if (szNode && szEnd) { szNode += 7; *szEnd = '\0'; if (atoi(szNode) != getContactXStatus(hContact)) { // this is strange - but go on debugLogA("Warning: XStatusIds do not match!"); } *szEnd = ' '; } szNode = strstrnull(szWork, "<title>"); szEnd = strstrnull(szWork, "</title>"); if (szNode && szEnd) { // we got XStatus title, save it char *szXName, *szOldXName; szNode += 7; *szEnd = '\0'; szXName = DemangleXml(szNode, strlennull(szNode)); // check if the name changed szOldXName = getSettingStringUtf(hContact, DBSETTING_XSTATUS_NAME, NULL); if (strcmpnull(szOldXName, szXName)) bChanged = TRUE; SAFE_FREE(&szOldXName); db_set_utf(hContact, m_szModuleName, DBSETTING_XSTATUS_NAME, szXName); SAFE_FREE(&szXName); *szEnd = ' '; } szNode = strstrnull(szWork, "<desc>"); szEnd = strstrnull(szWork, "</desc>"); if (szNode && szEnd) { // we got XStatus mode msg, save it char *szXMsg, *szOldXMsg; szNode += 6; *szEnd = '\0'; szXMsg = DemangleXml(szNode, strlennull(szNode)); // check if the decription changed szOldXMsg = getSettingStringUtf(hContact, DBSETTING_XSTATUS_NAME, NULL); if (strcmpnull(szOldXMsg, szXMsg)) bChanged = TRUE; SAFE_FREE(&szOldXMsg); db_set_utf(hContact, m_szModuleName, DBSETTING_XSTATUS_MSG, szXMsg); SAFE_FREE(&szXMsg); } ProtoBroadcastAck(hContact, ICQACKTYPE_XSTATUS_RESPONSE, ACKRESULT_SUCCESS, (HANDLE)wCookie, 0); } else { char *szSrvEnd = strstrnull(szEnd, "</srv>"); if (szSrvEnd && strstrnull(szSrvEnd, "<val srv_id=")) { // check all values ! szRes = szSrvEnd + 6; // after first value goto NextVal; } // no next val, we were unable to handle packet, write error debugLogA("Error: Unknown serverId \"%s\" in Xtraz response", szNode); } } else debugLogA("Error: Missing serverId in Xtraz response"); SAFE_FREE(&szMem); } else debugLogA("Error: Invalid Xtraz Notify response"); }
void CIcqProto::handleServUINSettings(int nPort, serverthread_info *info) { setUserInfo(); /* SNAC 3,4: Tell server who's on our list (deprecated) */ /* SNAC 3,15: Try to add unauthorised contacts to temporary list */ sendEntireListServ(ICQ_BUDDY_FAMILY, ICQ_USER_ADDTOTEMPLIST, BUL_ALLCONTACTS); if (m_iDesiredStatus == ID_STATUS_INVISIBLE) { /* Tell server who's on our visible list (deprecated) */ if (!m_bSsiEnabled) sendEntireListServ(ICQ_BOS_FAMILY, ICQ_CLI_ADDVISIBLE, BUL_VISIBLE); else updateServVisibilityCode(3); } if (m_iDesiredStatus != ID_STATUS_INVISIBLE) { /* Tell server who's on our invisible list (deprecated) */ if (!m_bSsiEnabled) sendEntireListServ(ICQ_BOS_FAMILY, ICQ_CLI_ADDINVISIBLE, BUL_INVISIBLE); else updateServVisibilityCode(4); } // SNAC 1,1E: Set status icq_packet packet; { DWORD dwDirectCookie = rand() ^ (rand() << 16); // Get status WORD wStatus = MirandaStatusToIcq(m_iDesiredStatus); // Get status note & mood char *szStatusNote = PrepareStatusNote(m_iDesiredStatus); BYTE bXStatus = getContactXStatus(NULL); char szMoodData[32]; // prepare mood id if (m_bMoodsEnabled && bXStatus && moodXStatus[bXStatus - 1] != -1) mir_snprintf(szMoodData, "icqmood%d", moodXStatus[bXStatus - 1]); else szMoodData[0] = '\0'; //! Tricky code, this ensures that the status note will be saved to the directory SetStatusNote(szStatusNote, m_bGatewayMode ? 5000 : 2500, TRUE); size_t wStatusNoteLen = mir_strlen(szStatusNote); size_t wStatusMoodLen = mir_strlen(szMoodData); size_t wSessionDataLen = (wStatusNoteLen ? wStatusNoteLen + 4 : 0) + 4 + wStatusMoodLen + 4; serverPacketInit(&packet, 71 + (wSessionDataLen ? wSessionDataLen + 4 : 0)); packFNACHeader(&packet, ICQ_SERVICE_FAMILY, ICQ_CLIENT_SET_STATUS); packDWord(&packet, 0x00060004); // TLV 6: Status mode and security flags packWord(&packet, GetMyStatusFlags()); // Status flags packWord(&packet, wStatus); // Status packTLVWord(&packet, 0x0008, 0x0A06); // TLV 8: Independent Status Messages packDWord(&packet, 0x000c0025); // TLV C: Direct connection info packDWord(&packet, getDword("RealIP", 0)); packDWord(&packet, nPort); packByte(&packet, DC_TYPE); // TCP/FLAG firewall settings packWord(&packet, ICQ_VERSION); packDWord(&packet, dwDirectCookie); // DC Cookie packDWord(&packet, WEBFRONTPORT); // Web front port packDWord(&packet, CLIENTFEATURES); // Client features packDWord(&packet, 0x7fffffff); // Abused timestamp packDWord(&packet, ICQ_PLUG_VERSION); // Abused timestamp if (ServiceExists("SecureIM/IsContactSecured")) packDWord(&packet, 0x5AFEC0DE); // SecureIM Abuse else packDWord(&packet, 0x00000000); // Timestamp packWord(&packet, 0x0000); // Unknown packTLVWord(&packet, 0x001F, 0x0000); if (wSessionDataLen) { // Pack session data packWord(&packet, 0x1D); // TLV 1D packWord(&packet, WORD(wSessionDataLen)); // TLV length packWord(&packet, 0x02); // Item Type if (wStatusNoteLen) { packWord(&packet, 0x400 | WORD(wStatusNoteLen + 4)); // Flags + Item Length packWord(&packet, WORD(wStatusNoteLen)); // Text Length packBuffer(&packet, (LPBYTE)szStatusNote, wStatusNoteLen); packWord(&packet, 0); // Encoding not specified (utf-8 is default) } else packWord(&packet, 0); // Flags + Item Length packWord(&packet, 0x0E); // Item Type packWord(&packet, WORD(wStatusMoodLen)); // Flags + Item Length if (wStatusMoodLen) packBuffer(&packet, (LPBYTE)szMoodData, wStatusMoodLen); // Mood // Save current status note & mood db_set_utf(NULL, m_szModuleName, DBSETTING_STATUS_NOTE, szStatusNote); setString(DBSETTING_STATUS_MOOD, szMoodData); } // Release memory SAFE_FREE(&szStatusNote); sendServPacket(&packet); } /* SNAC 1,11 */ serverPacketInit(&packet, 14); packFNACHeader(&packet, ICQ_SERVICE_FAMILY, ICQ_CLIENT_SET_IDLE); packDWord(&packet, 0x00000000); sendServPacket(&packet); m_bIdleAllow = 0; // Change status SetCurrentStatus(m_iDesiredStatus); // Finish Login sequence serverPacketInit(&packet, 98); packFNACHeader(&packet, ICQ_SERVICE_FAMILY, ICQ_CLIENT_READY); packDWord(&packet, 0x00220001); // imitate ICQ 6 behaviour packDWord(&packet, 0x0110164f); packDWord(&packet, 0x00010004); packDWord(&packet, 0x0110164f); packDWord(&packet, 0x00130004); packDWord(&packet, 0x0110164f); packDWord(&packet, 0x00020001); packDWord(&packet, 0x0110164f); packDWord(&packet, 0x00030001); packDWord(&packet, 0x0110164f); packDWord(&packet, 0x00150001); packDWord(&packet, 0x0110164f); packDWord(&packet, 0x00040001); packDWord(&packet, 0x0110164f); packDWord(&packet, 0x00060001); packDWord(&packet, 0x0110164f); packDWord(&packet, 0x00090001); packDWord(&packet, 0x0110164f); packDWord(&packet, 0x000A0001); packDWord(&packet, 0x0110164f); packDWord(&packet, 0x000B0001); packDWord(&packet, 0x0110164f); sendServPacket(&packet); debugLogA(" *** Yeehah, login sequence complete"); // login sequence is complete enter logged-in mode info->bLoggedIn = true; m_bConnectionLost = false; // enable auto info-update routine icq_EnableUserLookup(true); if (!info->isMigrating) { // Get Offline Messages Reqeust cookie_offline_messages *ack = (cookie_offline_messages*)SAFE_MALLOC(sizeof(cookie_offline_messages)); if (ack) { DWORD dwCookie = AllocateCookie(CKT_OFFLINEMESSAGE, ICQ_MSG_CLI_REQ_OFFLINE, 0, ack); serverPacketInit(&packet, 10); packFNACHeader(&packet, ICQ_MSG_FAMILY, ICQ_MSG_CLI_REQ_OFFLINE, 0, dwCookie); sendServPacket(&packet); } else icq_LogMessage(LOG_WARNING, LPGEN("Failed to request offline messages. They may be received next time you log in.")); // Update our information from the server sendOwnerInfoRequest(); // Request info updates on all contacts icq_RescanInfoUpdate(); // Start sending Keep-Alive packets StartKeepAlive(info); if (m_bAvatarsEnabled) { // Send SNAC 1,4 - request avatar family 0x10 connection icq_requestnewfamily(ICQ_AVATAR_FAMILY, &CIcqProto::StartAvatarThread); m_avatarsConnectionPending = TRUE; debugLogA("Requesting Avatar family entry point."); } // Set last xstatus updateServerCustomStatus(TRUE); } info->isMigrating = false; if (m_bAimEnabled) { char **szAwayMsg = NULL; mir_cslock l(m_modeMsgsMutex); szAwayMsg = MirandaStatusToAwayMsg(m_iStatus); if (szAwayMsg) icq_sendSetAimAwayMsgServ(*szAwayMsg); } }
static void ProcessIniFile(TCHAR* szIniPath, char *szSafeSections, char *szUnsafeSections, int secur, bool secFN) { FILE *fp = _tfopen(szIniPath, _T("rt")); if (fp == NULL) return; bool warnThisSection = false; char szSection[128]; szSection[0] = 0; while (!feof(fp)) { char szLine[2048]; if (fgets(szLine, sizeof(szLine), fp) == NULL) break; LBL_NewLine: size_t lineLength = mir_strlen(szLine); while (lineLength && (BYTE)(szLine[lineLength - 1]) <= ' ') szLine[--lineLength] = '\0'; if (szLine[0] == ';' || szLine[0] <= ' ') continue; if (szLine[0] == '[') { char *szEnd = strchr(szLine + 1, ']'); if (szEnd == NULL) continue; if (szLine[1] == '!') szSection[0] = '\0'; else { mir_strncpy(szSection, szLine + 1, min(sizeof(szSection), (int)(szEnd - szLine))); switch (secur) { case 0: warnThisSection = false; break; case 1: warnThisSection = !IsInSpaceSeparatedList(szSection, szSafeSections); break; case 2: warnThisSection = IsInSpaceSeparatedList(szSection, szUnsafeSections); break; default: warnThisSection = true; break; } if (secFN) warnThisSection = 0; } if (szLine[1] == '?') { DBCONTACTENUMSETTINGS dbces; dbces.pfnEnumProc = SettingsEnumProc; mir_strncpy(szSection, szLine+2, min(sizeof(szSection), (int)(szEnd-szLine-1))); dbces.szModule = szSection; dbces.ofsSettings = 0; CallService(MS_DB_CONTACT_ENUMSETTINGS, 0, (LPARAM)&dbces); while (setting_items) { SettingsList *next = setting_items->next; db_unset(NULL, szSection, setting_items->name); mir_free(setting_items->name); mir_free(setting_items); setting_items = next; } } continue; } if (szSection[0] == '\0') continue; char *szValue = strchr(szLine, '='); if (szValue == NULL) continue; char szName[128]; mir_strncpy(szName, szLine, min(sizeof(szName), (int)(szValue-szLine+1))); szValue++; { warnSettingChangeInfo_t warnInfo; warnInfo.szIniPath = szIniPath; warnInfo.szName = szName; warnInfo.szSafeSections = szSafeSections; warnInfo.szSection = szSection; warnInfo.szUnsafeSections = szUnsafeSections; warnInfo.szValue = szValue; warnInfo.warnNoMore = 0; warnInfo.cancel = 0; if (warnThisSection && IDNO == DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_WARNINICHANGE), NULL, WarnIniChangeDlgProc, (LPARAM)&warnInfo)) continue; if (warnInfo.cancel) break; if (warnInfo.warnNoMore) warnThisSection = 0; } switch (szValue[0]) { case 'b': case 'B': db_set_b(NULL, szSection, szName, (BYTE)strtol(szValue+1, NULL, 0)); break; case 'w': case 'W': db_set_w(NULL, szSection, szName, (WORD)strtol(szValue+1, NULL, 0)); break; case 'd': case 'D': db_set_dw(NULL, szSection, szName, (DWORD)strtoul(szValue+1, NULL, 0)); break; case 'l': case 'L': case '-': if (szValue[1] == '*') { LIST<char> arSettings(1); ESFDParam param = { &arSettings, szName }; DBCONTACTENUMSETTINGS dbep = {}; dbep.pfnEnumProc = EnumSettingsForDeletion; dbep.szModule = szSection; dbep.lParam = (LPARAM)¶m; CallService(MS_DB_CONTACT_ENUMSETTINGS, NULL, LPARAM(&dbep)); while (arSettings.getCount()) { db_unset(NULL, szSection, arSettings[0]); mir_free(arSettings[0]); arSettings.remove(0); } } db_unset(NULL, szSection, szName); break; case 'e': case 'E': ConvertBackslashes(szValue+1, Langpack_GetDefaultCodePage()); case 's': case 'S': db_set_s(NULL, szSection, szName, szValue+1); break; case 'g': case 'G': for (char *pstr = szValue + 1; *pstr; pstr++) { if (*pstr == '\\') { switch (pstr[1]) { case 'n': *pstr = '\n'; break; case 't': *pstr = '\t'; break; case 'r': *pstr = '\r'; break; default: *pstr = pstr[1]; break; } memmove(pstr + 1, pstr + 2, mir_strlen(pstr + 2) + 1); } } case 'u': case 'U': db_set_utf(NULL, szSection, szName, szValue + 1); break; case 'm': case 'M': { CMStringA memo(szValue + 1); memo.Append("\r\n"); while (fgets(szLine, sizeof(szLine), fp) != NULL) { switch (szLine[0]) { case 0: case '\r': case '\n': case ' ': case '\t': break; default: db_set_utf(NULL, szSection, szName, memo); goto LBL_NewLine; } memo.Append(rtrim(szLine + 1)); memo.Append("\r\n"); } db_set_utf(NULL, szSection, szName, memo); } break; case 'n': case 'h': case 'N': case 'H': { int len; char *pszValue, *pszEnd; PBYTE buf = (PBYTE)mir_alloc(mir_strlen(szValue + 1)); for (len = 0, pszValue = szValue + 1;; len++) { buf[len] = (BYTE)strtol(pszValue, &pszEnd, 0x10); if (pszValue == pszEnd) break; pszValue = pszEnd; } db_set_blob(NULL, szSection, szName, buf, len); mir_free(buf); } break; default: TCHAR buf[250]; mir_sntprintf(buf, TranslateT("Invalid setting type for '%s'. The first character of every value must be b, w, d, l, s, e, u, g, h or n."), _A2T(szName)); MessageBox(NULL, buf, TranslateT("Install database settings"), MB_ICONWARNING | MB_OK); break; } } fclose(fp); }
MCONTACT CSametimeProto::AddContact(mwSametimeUser* user, bool temporary) { debugLog(_T("CSametimeProto::AddContact() start")); const char* id = mwSametimeUser_getUser(user); const char* name = mwSametimeUser_getShortName(user); const char* nick = mwSametimeUser_getAlias(user); //const char* nick = mwSametimeUser_getShortName(user); mwSametimeUserType type = mwSametimeUser_getType(user); MCONTACT hContact = FindContactByUserId(id); bool new_contact = false; if (!hContact) { hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0); if (!hContact) { debugLog(_T("AddContact(): Failed to create Sametime contact")); return NULL; ///TODO error handling } if (Proto_AddToContact(hContact, m_szModuleName) != 0) { CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0); debugLog(_T("AddContact(): Failed to register Sametime contact")); return NULL; ///TODO error handling } new_contact = true; } else if (!temporary) { db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Hidden"); } // add to miranda if (new_contact) db_set_utf(hContact, m_szModuleName, "stid", id); if (name && mir_strlen(name)) db_set_utf(hContact, m_szModuleName, "Name", name); if (nick && mir_strlen(nick)) { db_set_utf(hContact, m_szModuleName, "Nick", nick); } else if (name && mir_strlen(name)) { db_set_utf(hContact, m_szModuleName, "Nick", name); } else { db_set_utf(hContact, m_szModuleName, "Nick", id); } db_set_b(hContact, m_szModuleName, "type", (BYTE)type); if (new_contact) { //add to our awareness list mwAwareIdBlock id_block; if (GetAwareIdFromContact(hContact, &id_block)) { GList* gl = g_list_prepend(NULL, &id_block); mwAwareList_addAware(aware_list, gl); g_list_free(gl); free(id_block.user); } } if (temporary) { db_set_b(hContact, "CList", "NotOnList", 1); db_set_b(hContact, "CList", "Hidden", 1); } else { db_unset(hContact, "CList", "NotOnList"); db_unset(hContact, "CList", "Hidden"); } return hContact; }
void mwAwareList_on_aware(mwAwareList* list, mwAwareSnapshot* aware) { CSametimeProto* proto = getProtoFromMwAwareList(list);; MCONTACT hContact = proto->FindContactByUserId(aware->id.user); char* group = 0; DBVARIANT dbv; // update self - necessary for some servers if (aware->online && !db_get_utf(0, proto->m_szModuleName, "stid", &dbv) && mir_strcmp(aware->id.user, dbv.pszVal) == 0) { int new_status = ID_STATUS_OFFLINE; switch (aware->status.status) { case mwStatus_ACTIVE: new_status = ID_STATUS_ONLINE; break; case mwStatus_AWAY: new_status = ID_STATUS_AWAY; break; case mwStatus_IDLE: new_status = ID_STATUS_IDLE; break; case mwStatus_BUSY: new_status = ID_STATUS_DND; break; case mwStatus_IN_MEETING: // link 'in meeting' Sametime status new_status = ID_STATUS_OCCUPIED; // with 'Occupied' MIR_NG status break; } if (new_status != ID_STATUS_IDLE) //SetSessionStatus(new_status); proto->UpdateSelfStatus(); db_free(&dbv); } if (hContact && !db_get_utf(hContact, "CList", "Group", &dbv)) { group = _strdup(dbv.pszVal); db_free(&dbv); } if (aware->group && (!group || mir_strcmp(aware->group, group) || !hContact)) { // dynamic group member we're not already aware of // resolve server alias to user id via resolver mwSametimeList* user_list = mwSametimeList_new(); mwSametimeGroup* stgroup = mwSametimeGroup_new(user_list, mwSametimeGroup_DYNAMIC, aware->group); char buff[256]; mir_snprintf(buff, "GA_%s", aware->group); if (!db_get_utf(0, proto->szProtoGroups, buff, &dbv)) { mwSametimeGroup_setAlias(stgroup, dbv.pszVal); db_free(&dbv); } GList* query = g_list_prepend(0, aware->id.user); mwServiceResolve_resolve(proto->service_resolve, query, mwResolveFlag_USERS, mwResolve_handler_dyngroup_callback, (gpointer)stgroup, 0); g_list_free(query); } else if (hContact) { if (aware->online) { int new_status = ID_STATUS_OFFLINE; switch (aware->status.status) { case mwStatus_ACTIVE: new_status = ID_STATUS_ONLINE; db_set_dw(hContact, proto->m_szModuleName, "IdleTS", 0); db_set_w(hContact, proto->m_szModuleName, "Status", new_status); break; case mwStatus_AWAY: new_status = ID_STATUS_AWAY; db_set_dw(hContact, proto->m_szModuleName, "IdleTS", 0); db_set_w(hContact, proto->m_szModuleName, "Status", new_status); break; case mwStatus_IDLE: if (proto->options.idle_as_away) { new_status = ID_STATUS_AWAY; db_set_w(hContact, proto->m_szModuleName, "Status", new_status); } db_set_dw(hContact, proto->m_szModuleName, "IdleTS", (DWORD)time(0)); break; case mwStatus_BUSY: new_status = ID_STATUS_DND; db_set_w(hContact, proto->m_szModuleName, "Status", new_status); db_set_dw(hContact, proto->m_szModuleName, "IdleTS", 0); break; case mwStatus_IN_MEETING: // link 'in meeting' Sametime status to 'Occipied' MIR_NG status new_status = ID_STATUS_OCCUPIED; db_set_w(hContact, proto->m_szModuleName, "Status", new_status); db_set_dw(hContact, proto->m_szModuleName, "IdleTS", 0); break; } } else db_set_w(hContact, proto->m_szModuleName, "Status", ID_STATUS_OFFLINE); if (proto->service_aware) { const char* desc = mwServiceAware_getText(proto->service_aware, &aware->id); if (desc) //db_set_utf(hContact, m_szModuleName, "StatusMsg", desc); db_set_utf(hContact, "CList", "StatusMsg", desc); else //db_set_utf(hContact, m_szModuleName, "StatusMsg", ""); //db_unset(hContact, m_szModuleName, "StatusMsg"); db_unset(hContact, "CList", "StatusMsg"); } } if (group) free(group); }
void CSametimeProto::SetContactGroup(MCONTACT hContact, const char* name) { db_set_utf(hContact, "CList", "Group", name); }
void CSametimeProto::ImportContactsFromList(mwSametimeList* user_list, bool temporary) { debugLog(_T("CSametimeProto::ImportContactsFromList() start")); // add contacts mwSametimeGroup* stgroup; mwSametimeUser* stuser; GList *gl, *gtl, *ul, *utl; const char* group_name; const char* group_alias; mwSametimeGroupType group_type; bool group_open; gl = gtl = mwSametimeList_getGroups(user_list); for (; gl; gl = gl->next) { char buff[256]; stgroup = (mwSametimeGroup*)gl->data; group_name = mwSametimeGroup_getName(stgroup); group_alias = mwSametimeGroup_getAlias(stgroup); if (!group_alias) group_alias = group_name; group_type = mwSametimeGroup_getType(stgroup); group_open = (mwSametimeGroup_isOpen(stgroup) != 0); mir_snprintf(buff, "GN_%s", group_alias); db_set_utf(0, szProtoGroups, buff, group_name); mir_snprintf(buff, "GT_%s", group_alias); db_set_b(0, szProtoGroups, buff, (BYTE)group_type); mir_snprintf(buff, "GO_%s", group_alias); db_set_b(0, szProtoGroups, buff, (BYTE)(group_open ? 1 : 0)); // inverse mapping mir_snprintf(buff, "GA_%s", group_name); db_set_utf(0, szProtoGroups, buff, group_alias); AddGroup(group_alias, group_open); if (group_type == mwSametimeGroup_DYNAMIC) { mwAwareIdBlock id_block; id_block.type = mwAware_GROUP; id_block.user = (char*)group_name; id_block.community = 0; GList* gl = g_list_prepend(NULL, &id_block); mwAwareList_addAware(aware_list, gl); g_list_free(gl); } ul = utl = mwSametimeGroup_getUsers(stgroup); for (; ul; ul = ul->next) { stuser = (mwSametimeUser*)ul->data; MCONTACT hContact = AddContact(stuser, temporary); if (hContact && group_alias && mir_strcmp(group_alias, Translate("None")) != 0 && mir_strcmp(group_alias, "MetaContacts Hidden Group") != 0) { SetContactGroup(hContact, group_alias); // mark contact as belonging to dynamic group } } g_list_free(utl); } g_list_free(gtl); }
int Meta_SettingChanged(WPARAM hContact, LPARAM lParam) { DBCONTACTWRITESETTING *dcws = (DBCONTACTWRITESETTING *)lParam; char buffer[512]; // the only global options we're interested in if (hContact == 0) return 0; DBCachedContact *cc = currDb->m_cache->GetCachedContact(hContact); if (cc == NULL || !cc->IsSub()) return 0; DBCachedContact *ccMeta = currDb->m_cache->GetCachedContact(cc->parentID); if (ccMeta == NULL || !ccMeta->IsMeta()) return 0; // This contact is attached to a MetaContact. int contact_number = Meta_GetContactNumber(ccMeta, hContact); if (contact_number == -1) return 0; // exit - db corruption if (!strcmp(dcws->szSetting, "IP")) { if (dcws->value.type == DBVT_DWORD) db_set_dw(ccMeta->contactID, META_PROTO, "IP", dcws->value.dVal); else db_unset(ccMeta->contactID, META_PROTO, "IP"); } else if (!strcmp(dcws->szSetting, "RealIP")) { if (dcws->value.type == DBVT_DWORD) db_set_dw(ccMeta->contactID, META_PROTO, "RealIP", dcws->value.dVal); else db_unset(ccMeta->contactID, META_PROTO, "RealIP"); } else if (!strcmp(dcws->szSetting, "ListeningTo")) { switch (dcws->value.type) { case DBVT_ASCIIZ: db_set_s(ccMeta->contactID, META_PROTO, "ListeningTo", dcws->value.pszVal); break; case DBVT_UTF8: db_set_utf(ccMeta->contactID, META_PROTO, "ListeningTo", dcws->value.pszVal); break; case DBVT_WCHAR: db_set_ws(ccMeta->contactID, META_PROTO, "ListeningTo", dcws->value.pwszVal); break; case DBVT_DELETED: db_unset(ccMeta->contactID, META_PROTO, "ListeningTo"); break; } } else if (!strcmp(dcws->szSetting, "Nick") && dcws->value.type != DBVT_DELETED) { // subcontact nick has changed - update metacontact mir_snprintf(buffer, SIZEOF(buffer), "Nick%d", contact_number); db_set(ccMeta->contactID, META_PROTO, buffer, &dcws->value); ptrT tszMyhandle(db_get_tsa(hContact, "CList", "MyHandle")); if (tszMyhandle == NULL) { mir_snprintf(buffer, SIZEOF(buffer), "CListName%d", contact_number); db_set(ccMeta->contactID, META_PROTO, buffer, &dcws->value); } // copy nick to metacontact, if it's the most online MCONTACT hMostOnline = Meta_GetMostOnline(ccMeta); Meta_CopyContactNick(ccMeta, hMostOnline); } else if (!strcmp(dcws->szSetting, "IdleTS")) { if (dcws->value.type == DBVT_DWORD) db_set_dw(ccMeta->contactID, META_PROTO, "IdleTS", dcws->value.dVal); else if (dcws->value.type == DBVT_DELETED) db_set_dw(ccMeta->contactID, META_PROTO, "IdleTS", 0); } else if (!strcmp(dcws->szSetting, "LogonTS")) { if (dcws->value.type == DBVT_DWORD) db_set_dw(ccMeta->contactID, META_PROTO, "LogonTS", dcws->value.dVal); else if (dcws->value.type == DBVT_DELETED) db_set_dw(ccMeta->contactID, META_PROTO, "LogonTS", 0); } else if (!strcmp(dcws->szModule, "CList") && !strcmp(dcws->szSetting, "MyHandle")) { if (dcws->value.type == DBVT_DELETED) { char *proto = GetContactProto(hContact); mir_snprintf(buffer, SIZEOF(buffer), "CListName%d", contact_number); DBVARIANT dbv; if (proto && !db_get_ts(hContact, proto, "Nick", &dbv)) { db_set_ts(ccMeta->contactID, META_PROTO, buffer, dbv.ptszVal); db_free(&dbv); } else db_unset(ccMeta->contactID, META_PROTO, buffer); } else { // subcontact clist displayname has changed - update metacontact mir_snprintf(buffer, SIZEOF(buffer), "CListName%d", contact_number); db_set(ccMeta->contactID, META_PROTO, buffer, &dcws->value); } // copy nick to metacontact, if it's the most online Meta_CopyContactNick(ccMeta, Meta_GetMostOnline(ccMeta)); } // subcontact changing status else if (!strcmp(dcws->szSetting, "Status") && dcws->value.type != DBVT_DELETED) { // update subcontact status setting mir_snprintf(buffer, SIZEOF(buffer), "Status%d", contact_number); db_set_w(ccMeta->contactID, META_PROTO, buffer, dcws->value.wVal); mir_snprintf(buffer, SIZEOF(buffer), "StatusString%d", contact_number); db_set_ts(ccMeta->contactID, META_PROTO, buffer, cli.pfnGetStatusModeDescription(dcws->value.wVal, 0)); // set status to that of most online contact MCONTACT hMostOnline = Meta_GetMostOnline(ccMeta); if (hMostOnline != db_mc_getDefault(ccMeta->contactID)) db_mc_notifyDefChange(ccMeta->contactID, hMostOnline); Meta_CopyContactNick(ccMeta, hMostOnline); Meta_FixStatus(ccMeta); // most online contact with avatar support might have changed - update avatar hMostOnline = Meta_GetMostOnlineSupporting(ccMeta, PFLAGNUM_4, PF4_AVATARS); if (hMostOnline) { PROTO_AVATAR_INFORMATIONT AI = { sizeof(AI) }; AI.hContact = ccMeta->contactID; AI.format = PA_FORMAT_UNKNOWN; _tcscpy(AI.filename, _T("X")); if (CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS) db_set_ts(ccMeta->contactID, "ContactPhoto", "File", AI.filename); } } return 0; }
void TwitterProto::UpdateStatuses(bool pre_read, bool popups, bool tweetToMsg) { try { ScopedLock s(twitter_lock_); twitter::status_list updates = twit_.get_statuses(200,since_id_); s.Unlock(); if(!updates.empty()) { since_id_ = std::max(since_id_, updates[0].status.id); } for(twitter::status_list::reverse_iterator i=updates.rbegin(); i!=updates.rend(); ++i) { if(!pre_read && in_chat_) UpdateChat(*i); if(i->username == twit_.get_username()) continue; HANDLE hContact = AddToClientList(i->username.c_str(),""); UpdateAvatar(hContact,i->profile_image_url); // as UpdateFriends() doesn't work at the moment, i'm going to update the avatars here // i think we maybe should just do that DBEF_READ line instead of stopping ALL this code. have to test. if (tweetToMsg) { DBEVENTINFO dbei = {sizeof(dbei)}; dbei.pBlob = (BYTE*)(i->status.text.c_str()); dbei.cbBlob = (int)i->status.text.size()+1; dbei.eventType = TWITTER_DB_EVENT_TYPE_TWEET; dbei.flags = DBEF_UTF | DBEF_READ; dbei.timestamp = static_cast<DWORD>(i->status.time); dbei.szModule = m_szModuleName; db_event_add(hContact, &dbei); } db_set_utf(hContact,"CList","StatusMsg",i->status.text.c_str()); if(!pre_read && popups) ShowContactPopup(hContact,i->status.text); } db_pod_set(0,m_szModuleName,TWITTER_KEY_SINCEID,since_id_); disconnectionCount = 0; debugLogA( _T("***** Status messages updated")); } catch(const bad_response &) { ++disconnectionCount; debugLogA( _T("***** UpdateStatuses - Bad response from server, this has happened %d time(s)"), disconnectionCount); if (disconnectionCount > 2) { debugLogA( _T("***** UpdateStatuses - Too many bad responses from the server, signing off")); SetStatus(ID_STATUS_OFFLINE); } } catch(const std::exception &e) { ShowPopup( (std::string("While updating status messages, an error occurred: ") +e.what()).c_str()); debugLogA( _T("***** Error updating status messages: %s"), e.what()); } }
void CIcqProto::parseStatusNote(DWORD dwUin, char *szUid, MCONTACT hContact, oscar_tlv_chain *pChain) { DWORD dwStatusNoteTS = time(NULL); BYTE *pStatusNoteTS, *pStatusNote; WORD wStatusNoteTSLen, wStatusNoteLen; BYTE bStatusNoteFlags; if (unpackSessionDataItem(pChain, 0x0D, &pStatusNoteTS, &wStatusNoteTSLen, NULL) && wStatusNoteTSLen == sizeof(DWORD)) unpackDWord(&pStatusNoteTS, &dwStatusNoteTS); // Get Status Note session item if (unpackSessionDataItem(pChain, 0x02, &pStatusNote, &wStatusNoteLen, &bStatusNoteFlags)) { char *szStatusNote = NULL; if ((bStatusNoteFlags & 4) == 4 && wStatusNoteLen >= 4) { BYTE *buf = pStatusNote; WORD buflen = wStatusNoteLen - 2; WORD wTextLen; unpackWord(&buf, &wTextLen); if (wTextLen > buflen) wTextLen = buflen; if (wTextLen > 0) { szStatusNote = (char*)_alloca(wStatusNoteLen + 1); unpackString(&buf, szStatusNote, wTextLen); szStatusNote[wTextLen] = '\0'; buflen -= wTextLen; WORD wEncodingType = 0; char *szEncoding = NULL; if (buflen >= 2) unpackWord(&buf, &wEncodingType); if (wEncodingType == 1 && buflen > 6) { // Encoding specified buf += 2; buflen -= 2; unpackWord(&buf, &wTextLen); if (wTextLen > buflen) wTextLen = buflen; szEncoding = (char*)_alloca(wTextLen + 1); unpackString(&buf, szEncoding, wTextLen); szEncoding[wTextLen] = '\0'; } else if (UTF8_IsValid(szStatusNote)) szEncoding = "utf-8"; szStatusNote = ApplyEncoding(szStatusNote, szEncoding); } } // Check if the status note was changed if (dwStatusNoteTS > getDword(hContact, DBSETTING_STATUS_NOTE_TIME, 0)) { DBVARIANT dbv = {DBVT_DELETED}; if (mir_strlen(szStatusNote) || (!getString(hContact, DBSETTING_STATUS_NOTE, &dbv) && (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_UTF8) && mir_strlen(dbv.pszVal))) debugLogA("%s changed status note to \"%s\"", strUID(dwUin, szUid), szStatusNote ? szStatusNote : ""); db_free(&dbv); if (szStatusNote) db_set_utf(hContact, m_szModuleName, DBSETTING_STATUS_NOTE, szStatusNote); else delSetting(hContact, DBSETTING_STATUS_NOTE); setDword(hContact, DBSETTING_STATUS_NOTE_TIME, dwStatusNoteTS); if (getContactXStatus(hContact) != 0 || !CheckContactCapabilities(hContact, CAPF_STATUS_MESSAGES)) { setStatusMsgVar(hContact, szStatusNote, false); TCHAR *tszNote = mir_utf8decodeT(szStatusNote); ProtoBroadcastAck(hContact, ACKTYPE_AWAYMSG, ACKRESULT_SUCCESS, NULL, (LPARAM)tszNote); mir_free(tszNote); } } SAFE_FREE(&szStatusNote); } else if (getContactStatus(hContact) == ID_STATUS_OFFLINE) { setStatusMsgVar(hContact, NULL, false); delSetting(hContact, DBSETTING_STATUS_NOTE); setDword(hContact, DBSETTING_STATUS_NOTE_TIME, dwStatusNoteTS); } }
void CIcqProto::handleUserOnline(BYTE *buf, size_t wLen, serverthread_info*) { DWORD dwPort = 0; DWORD dwRealIP = 0; DWORD dwUIN; uid_str szUID; DWORD dwDirectConnCookie = 0; DWORD dwWebPort = 0; DWORD dwFT1 = 0, dwFT2 = 0, dwFT3 = 0; const char *szClient = NULL; BYTE bClientId = 0; WORD wVersion = 0; WORD wTLVCount; WORD wWarningLevel; WORD wStatusFlags; WORD wStatus = 0, wOldStatus = 0; BYTE nTCPFlag = 0; char szStrBuf[MAX_PATH]; // Unpack the sender's user ID if (!unpackUID(&buf, &wLen, &dwUIN, &szUID)) return; // Syntax check if (wLen < 4) return; // Warning level? unpackWord(&buf, &wWarningLevel); wLen -= 2; // TLV count unpackWord(&buf, &wTLVCount); wLen -= 2; // Ignore status notification if the user is not already on our list MCONTACT hContact = HContactFromUID(dwUIN, szUID, NULL); if (hContact == INVALID_CONTACT_ID) { debugLogA("Ignoring user online (%s)", strUID(dwUIN, szUID)); return; } // Read user info TLVs oscar_tlv_chain *pChain; oscar_tlv *pTLV; // Syntax check if (wLen < 4) return; // Get chain if (!(pChain = readIntoTLVChain(&buf, wLen, wTLVCount))) return; // Get Class word WORD wClass = pChain->getWord(0x01, 1); int nIsICQ = wClass & CLASS_ICQ; if (dwUIN) { // Get DC info TLV pTLV = pChain->getTLV(0x0C, 1); if (pTLV && (pTLV->wLen >= 15)) { BYTE *pBuffer = pTLV->pData; nIsICQ = TRUE; unpackDWord(&pBuffer, &dwRealIP); unpackDWord(&pBuffer, &dwPort); unpackByte(&pBuffer, &nTCPFlag); unpackWord(&pBuffer, &wVersion); unpackDWord(&pBuffer, &dwDirectConnCookie); unpackDWord(&pBuffer, &dwWebPort); // Web front port pBuffer += 4; // Client features // Get faked time signatures, used to identify clients if (pTLV->wLen >= 0x23) { unpackDWord(&pBuffer, &dwFT1); unpackDWord(&pBuffer, &dwFT2); unpackDWord(&pBuffer, &dwFT3); } } // Get Status info TLV pTLV = pChain->getTLV(0x06, 1); if (pTLV && (pTLV->wLen >= 4)) { BYTE *pBuffer = pTLV->pData; unpackWord(&pBuffer, &wStatusFlags); unpackWord(&pBuffer, &wStatus); } else if (!nIsICQ) { // Connected thru AIM client, guess by user class if (wClass & CLASS_AWAY) wStatus = ID_STATUS_AWAY; else if (wClass & CLASS_WIRELESS) wStatus = ID_STATUS_ONTHEPHONE; else wStatus = ID_STATUS_ONLINE; wStatusFlags = 0; } else { // Huh? No status TLV? Lets guess then... wStatusFlags = 0; wStatus = ICQ_STATUS_ONLINE; } } else { nIsICQ = FALSE; if (wClass & CLASS_AWAY) wStatus = ID_STATUS_AWAY; else if (wClass & CLASS_WIRELESS) wStatus = ID_STATUS_ONTHEPHONE; else wStatus = ID_STATUS_ONLINE; wStatusFlags = 0; } debugLogA("Flags are %x", wStatusFlags); debugLogA("Status is %x", wStatus); // Get IP TLV DWORD dwIP = pChain->getDWord(0x0A, 1); // Get Online Since TLV DWORD dwOnlineSince = pChain->getDWord(0x03, 1); // Get Away Since TLV DWORD dwAwaySince = pChain->getDWord(0x29, 1); // Get Member Since TLV DWORD dwMemberSince = pChain->getDWord(0x05, 1); // Get Idle timer TLV WORD wIdleTimer = pChain->getWord(0x04, 1); time_t tIdleTS = 0; if (wIdleTimer) { time(&tIdleTS); tIdleTS -= (wIdleTimer*60); } if (wIdleTimer) debugLogA("Idle timer is %u.", wIdleTimer); debugLogA("Online since %s", time2text(dwOnlineSince)); if (dwAwaySince) debugLogA("Status was set on %s", time2text(dwAwaySince)); // Check client capabilities if (hContact != NULL) { wOldStatus = getContactStatus(hContact); // Collect all Capability info from TLV chain BYTE *capBuf = NULL; WORD capLen = 0; // Get Location Capability Info TLVs oscar_tlv *pFullTLV = pChain->getTLV(0x0D, 1); oscar_tlv *pShortTLV = pChain->getTLV(0x19, 1); if (pFullTLV && (pFullTLV->wLen >= BINARY_CAP_SIZE)) capLen += pFullTLV->wLen; if (pShortTLV && (pShortTLV->wLen >= 2)) capLen += (pShortTLV->wLen * 8); capBuf = (BYTE*)_alloca(capLen + BINARY_CAP_SIZE); if (capLen) { BYTE *pCapability = capBuf; capLen = 0; // we need to recount that if (pFullTLV && (pFullTLV->wLen >= BINARY_CAP_SIZE)) { // copy classic Capabilities BYTE *cData = pFullTLV->pData; int cLen = pFullTLV->wLen; while (cLen) { // be impervious to duplicates (AOL sends them sometimes) if (!capLen || !MatchCapability(capBuf, capLen, (capstr*)cData, BINARY_CAP_SIZE)) { // not present, add memcpy(pCapability, cData, BINARY_CAP_SIZE); capLen += BINARY_CAP_SIZE; pCapability += BINARY_CAP_SIZE; } cData += BINARY_CAP_SIZE; cLen -= BINARY_CAP_SIZE; } } if (pShortTLV && (pShortTLV->wLen >= 2)) { // copy short Capabilities capstr tmp; BYTE *cData = pShortTLV->pData; int cLen = pShortTLV->wLen; memcpy(tmp, capShortCaps, BINARY_CAP_SIZE); while (cLen) { // be impervious to duplicates (AOL sends them sometimes) tmp[2] = cData[0]; tmp[3] = cData[1]; if (!capLen || !MatchCapability(capBuf, capLen, &tmp, BINARY_CAP_SIZE)) { // not present, add memcpy(pCapability, tmp, BINARY_CAP_SIZE); capLen += BINARY_CAP_SIZE; pCapability += BINARY_CAP_SIZE; } cData += 2; cLen -= 2; } } debugLogA("Detected %d capability items.", capLen / BINARY_CAP_SIZE); } if (capLen) { // Update the contact's capabilies if present in packet SetCapabilitiesFromBuffer(hContact, capBuf, capLen, wOldStatus == ID_STATUS_OFFLINE); char *szCurrentClient = wOldStatus == ID_STATUS_OFFLINE ? NULL : getSettingStringUtf(hContact, "MirVer", NULL); szClient = detectUserClient(hContact, nIsICQ, wClass, dwOnlineSince, szCurrentClient, wVersion, dwFT1, dwFT2, dwFT3, dwDirectConnCookie, dwWebPort, capBuf, capLen, &bClientId, szStrBuf); // Check if the client changed, if not do not change if (szCurrentClient && !strcmpnull(szCurrentClient, szClient)) szClient = (const char*)-1; SAFE_FREE(&szCurrentClient); } else if (wOldStatus == ID_STATUS_OFFLINE) { // Remove the contact's capabilities if coming from offline ClearAllContactCapabilities(hContact); // no capability debugLogA("No capability info TLVs"); szClient = detectUserClient(hContact, nIsICQ, wClass, dwOnlineSince, NULL, wVersion, dwFT1, dwFT2, dwFT3, dwDirectConnCookie, dwWebPort, NULL, capLen, &bClientId, szStrBuf); } else // Capabilities not present in update packet, do not touch szClient = (const char*)-1; // we don't want to client be overwritten // handle Xtraz status char *moodData = NULL; WORD moodSize = 0; unpackSessionDataItem(pChain, 0x0E, (BYTE**)&moodData, &moodSize, NULL); if (capLen || wOldStatus == ID_STATUS_OFFLINE) handleXStatusCaps(dwUIN, szUID, hContact, capBuf, capLen, moodData, moodSize); else handleXStatusCaps(dwUIN, szUID, hContact, NULL, 0, moodData, moodSize); // Determine support for extended status messages if (pChain->getWord(0x08, 1) == 0x0A06) SetContactCapabilities(hContact, CAPF_STATUS_MESSAGES); else if (wOldStatus == ID_STATUS_OFFLINE) ClearContactCapabilities(hContact, CAPF_STATUS_MESSAGES); if (wOldStatus == ID_STATUS_OFFLINE) { if (CheckContactCapabilities(hContact, CAPF_SRV_RELAY)) debugLogA("Supports advanced messages"); else debugLogA("Does NOT support advanced messages"); } if (!nIsICQ) { // AIM clients does not advertise these, but do support them SetContactCapabilities(hContact, CAPF_UTF | CAPF_TYPING); // Server relayed messages are only supported by ICQ clients ClearContactCapabilities(hContact, CAPF_SRV_RELAY); if (dwUIN && wOldStatus == ID_STATUS_OFFLINE) debugLogA("Logged in with AIM client"); } if (nIsICQ && wVersion < 8) { ClearContactCapabilities(hContact, CAPF_SRV_RELAY); if (wOldStatus == ID_STATUS_OFFLINE) debugLogA("Forcing simple messages due to compability issues"); } // Process Avatar Hash pTLV = pChain->getTLV(0x1D, 1); if (pTLV) handleAvatarContactHash(dwUIN, szUID, hContact, pTLV->pData, pTLV->wLen); else handleAvatarContactHash(dwUIN, szUID, hContact, NULL, 0); // Process Status Note parseStatusNote(dwUIN, szUID, hContact, pChain); } // Free TLV chain disposeChain(&pChain); // Save contacts details in database if (hContact != NULL) { setDword(hContact, "LogonTS", dwOnlineSince); setDword(hContact, "AwayTS", dwAwaySince); setDword(hContact, "IdleTS", tIdleTS); if (dwMemberSince) setDword(hContact, "MemberTS", dwMemberSince); if (nIsICQ) { // on AIM these are not used setDword(hContact, "DirectCookie", dwDirectConnCookie); setByte(hContact, "DCType", (BYTE)nTCPFlag); setWord(hContact, "UserPort", (WORD)(dwPort & 0xffff)); setWord(hContact, "Version", wVersion); } else { delSetting(hContact, "DirectCookie"); delSetting(hContact, "DCType"); delSetting(hContact, "UserPort"); delSetting(hContact, "Version"); } // if no detection, set uknown if (!szClient) szClient = (nIsICQ ? "Unknown" : "Unknown AIM"); if (szClient != (char*)-1) { db_set_utf(hContact, m_szModuleName, "MirVer", szClient); setByte(hContact, "ClientID", bClientId); } if (wOldStatus == ID_STATUS_OFFLINE) { setDword(hContact, "IP", dwIP); setDword(hContact, "RealIP", dwRealIP); } else { // if not first notification only write significant information if (dwIP) setDword(hContact, "IP", dwIP); if (dwRealIP) setDword(hContact, "RealIP", dwRealIP); } setWord(hContact, "Status", (WORD)IcqStatusToMiranda(wStatus)); // Update info? if (dwUIN) { // check if the local copy of user details is up-to-date if (IsMetaInfoChanged(hContact)) icq_QueueUser(hContact); } } LPCTSTR ptszStatus = pcli->pfnGetStatusModeDescription(IcqStatusToMiranda(wStatus), 0); if (wOldStatus != IcqStatusToMiranda(wStatus)) { // And a small log notice... if status was changed if (nIsICQ) debugLogA("%u changed status to %S (v%d).", dwUIN, ptszStatus, wVersion); else debugLogA("%s changed status to %S.", strUID(dwUIN, szUID), ptszStatus); } if (szClient == cliSpamBot) { if (getByte("KillSpambots", DEFAULT_KILLSPAM_ENABLED) && db_get_b(hContact, "CList", "NotOnList", 0)) { // kill spammer icq_DequeueUser(dwUIN); icq_sendRemoveContact(dwUIN, NULL); AddToSpammerList(dwUIN); if (getByte("PopupsSpamEnabled", DEFAULT_SPAM_POPUPS_ENABLED)) ShowPopupMsg(hContact, LPGEN("Spambot Detected"), LPGEN("Contact deleted & further events blocked."), POPTYPE_SPAM); CallService(MS_DB_CONTACT_DELETE, hContact, 0); debugLogA("Contact %u deleted", dwUIN); } } }
int replaceModule(HWND hwnd, HANDLE hContact, const char *module, const char *find, const char *replace, int mode) { ModuleSettingLL msll; ModSetLinkLinkItem *setting; char *myreplace = NULL; char *newModule; int count = 0; if (mode & RW_FULL) newModule = (char*)replace; else { myreplace = multiReplace(module, find, replace, mode & RW_CASE); newModule = myreplace; } if (newModule[0] == 0) { ItemFound(hwnd, hContact, module, NULL, NULL, FW_MODULE | FW_DELETED); deleteModule((char*)module, hContact, 1); replaceTreeItem(GetDlgItem(hwnd2mainWindow, IDC_MODULES), hContact, module, NULL); mir_free(myreplace); return 1; } if (!IsModuleEmpty(hContact, newModule)) return 0; if (EnumSettings(hContact, (char*)module, &msll)) { setting = msll.first; while (setting) { DBVARIANT dbv; if (!GetSetting(hContact, module, setting->name, &dbv)) { switch (dbv.type) { case DBVT_BYTE: db_set_b(hContact, newModule, setting->name, dbv.bVal); break; case DBVT_WORD: db_set_w(hContact, newModule, setting->name, dbv.wVal); break; case DBVT_DWORD: db_set_dw(hContact, newModule, setting->name, dbv.dVal); break; case DBVT_ASCIIZ: db_set_s(hContact, newModule, setting->name, dbv.pszVal); break; case DBVT_UTF8: db_set_utf(hContact, newModule, setting->name, dbv.pszVal); break; case DBVT_BLOB: db_set_blob(hContact, newModule, setting->name, dbv.pbVal, dbv.cpbVal); break; } db_free(&dbv); db_unset(hContact, module, setting->name); } setting = setting->next; } FreeModuleSettingLL(&msll); replaceTreeItem(GetDlgItem(hwnd2mainWindow, IDC_MODULES), hContact, module, newModule); ItemFound(hwnd, hContact, newModule, NULL, NULL, FW_MODULE | FW_REPLACED); count++; } mir_free(myreplace); return count; }
void CMsnProto::setStringUtf(MCONTACT hContact, const char* name, const char* value) { db_set_utf(hContact, m_szModuleName, name, value); }