MCONTACT CSkypeProto::AddToList(int, PROTOSEARCHRESULT *psr) { debugLogA(__FUNCTION__); if (psr->id.a == NULL) return NULL; MCONTACT hContact; if (psr->flags & PSR_UNICODE) hContact = AddContact(mir_utf8encodeT(psr->id.t)); else hContact = AddContact(psr->id.a); return hContact; }
void Jabber::LoggedIn() { LOG("Jabber", liDebug, "Jabber::LoggedIn()"); Progress("Jabber Login", "Jabber: Logged in!", 1.00); BMessage msg(IM::MESSAGE); msg.AddInt32("im_what", IM::STATUS_SET); msg.AddString("protocol", kProtocolName); msg.AddString("status", ONLINE_TEXT); fServerMsgr.SendMessage( &msg ); fFullLogged=true; LOG("Jabber", liDebug, "Starting fLaterBuddyList"); while (fLaterBuddyList->size() != 0) { BString id = *(fLaterBuddyList->begin()); fLaterBuddyList->pop_front(); // removes first item JabberContact* contact=getContact(id.String()); if(!contact) { AddContact(id.String(),id.String(),""); BuddyStatusChanged(id.String(),OFFLINE_TEXT); } } LOG("Jabber", liDebug, "Ending fLaterBuddyList"); }
MCONTACT CSametimeProto::AddSearchedUser(MYPROTOSEARCHRESULT* mpsr, bool temporary) { MCONTACT hContact = 0; debugLog(_T("CSametimeProto::AddSearchedUser() start")); mwSametimeList* user_list = mwSametimeList_new(); mwSametimeGroup* stgroup = 0; if (mpsr->group) { stgroup = mwSametimeGroup_new(user_list, mwSametimeGroup_DYNAMIC, mpsr->stid); mwSametimeGroup_setAlias(stgroup, mpsr->name); ImportContactsFromList(user_list, temporary); } else { stgroup = mwSametimeGroup_new(user_list, mwSametimeGroup_NORMAL, Translate("None")); mwIdBlock uid; uid.user = mpsr->stid; uid.community = 0; mwSametimeUser *stuser = mwSametimeUser_new(stgroup, mwSametimeUser_NORMAL, &uid); mwSametimeUser_setShortName(stuser, mpsr->name); hContact = AddContact(stuser, temporary); mwSametimeList_free(mwSametimeGroup_getList(stgroup)); } return hContact; }
//[{"username":"******", "firstname" : "Echo \/ Sound Test Service", "lastname" : null, "avatarUrl" : null, "mood" : null, "richMood" : null, "displayname" : null, "country" : null, "city" : null},...] void CSkypeProto::LoadContactsInfo(const NETLIBHTTPREQUEST *response) { if (response == NULL) return; JSONNode root = JSONNode::parse(response->pData); if (!root) return; const JSONNode &items = root.as_array(); for (size_t i = 0; i < items.size(); i++) { const JSONNode &item = items.at(i); if (!item) break; std::string skypename = item["username"].as_string(); MCONTACT hContact = AddContact(skypename.c_str()); if (hContact) { UpdateProfileCountry(item, hContact); UpdateProfileCity(item, hContact); UpdateProfileStatusMessage(item, hContact); } } }
MCONTACT CSteamProto::AddToList(int, PROTOSEARCHRESULT* psr) { MCONTACT hContact = NULL; ptrA steamId(mir_u2a(psr->id.t)); if (psr->cbSize == sizeof(PROTOSEARCHRESULT)) { if (!FindContact(steamId)) { //hContact = AddContact(steamId, true); //ForkThread(&CSteamProto::UpdateContactsThread, (void*)mir_strdup(steamId)); ptrA token(getStringA("TokenSecret")); PushRequest( new GetUserSummariesRequest(token, steamId), &CSteamProto::OnGotUserSummaries); } } else if (psr->cbSize == sizeof(STEAM_SEARCH_RESULT)) { STEAM_SEARCH_RESULT *ssr = (STEAM_SEARCH_RESULT*)psr; hContact = AddContact(steamId, true); UpdateContact(hContact, ssr->data); } return hContact; }
void mwIm_conversation_opened(mwConversation *conv) { mwIdBlock *idb = mwConversation_getTarget(conv); HANDLE hContact = FindContactByUserId(idb->user); if(!hContact) { mwSametimeList *user_list = mwSametimeList_new(); mwSametimeGroup *stgroup = mwSametimeGroup_new(user_list, mwSametimeGroup_NORMAL, Translate("None")); mwSametimeUser *stuser = mwSametimeUser_new(stgroup, mwSametimeUser_NORMAL, idb); AddContact(stuser, (options.add_contacts ? false : true)); GetMoreDetails(idb->user); } ContactMessageQueue::iterator i; EnterCriticalSection(&q_cs); if((i = contact_message_queue.find(hContact)) != contact_message_queue.end()) { while(i->second.size()) { mwConversation_send(conv, mwImSend_PLAIN, (gconstpointer)i->second.front().c_str()); i->second.pop(); } contact_message_queue.erase(i); } LeaveCriticalSection(&q_cs); // gives linker error 'unresolved external symbol' :( So instead we will either add ciphers to the session or not (see session.cpp) //mwConversation_setEncrypted(conv, options.encrypt_session); }
void AddCustomerWindow::on_addContactButton_clicked() { contactDialog = new AddCustomerAddContact(this, contacts, phones, emails); connect(contactDialog, SIGNAL(CloseAndAdd()), this, SLOT(AddContact())); contactDialog->exec(); }
void on_okbutton3_clicked (GtkButton *button, gpointer user_data) { GtkEntry* dd = (GtkEntry*)lookup_widget(add_diag1, "entry3"); char *s = gtk_entry_get_text((GtkEntry*)dd); if(strcmp(s,"")!=0) AddContact(s); }
//************************************************************************ // removes a contact from the list //************************************************************************ void CContactList::RemoveContact(HANDLE hContact) { CListContainer<CContactListEntry*,CContactListGroup*> *pGroup = NULL; ///tstring strGroup = GetContactGroupPath(hContact); CListEntry<CContactListEntry*,CContactListGroup*> *pContactEntry = FindContact(hContact); if(!pContactEntry) { return; } if( !CConfig::GetBoolSetting(CLIST_USEGROUPS)){ if(pContactEntry->GetType() == ITEM) RemoveItem(((CListItem<CContactListEntry*,CContactListGroup*>*)pContactEntry)->GetItemData()); else RemoveGroup(((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry)->GetGroupData()); } else { pGroup = (CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry->GetParent(); ASSERT(pGroup != NULL); CContactListEntry *pEntry = GetContactData(pContactEntry); if(!pEntry) { return; } // Update the contacts group if it has one if(pGroup->GetType() != ROOT) { if(!CAppletManager::IsSubContact(hContact) && pEntry->iStatus != ID_STATUS_OFFLINE) ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,-1); if(!CAppletManager::IsSubContact(hContact) && pEntry->iMessages > 0) ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,0,-pEntry->iMessages); } if(pContactEntry->GetType() == ITEM) pGroup->RemoveItem(((CListItem<CContactListEntry*,CContactListGroup*>*)pContactEntry)->GetItemData()); else { pGroup->RemoveGroup(((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry)->GetGroupData()); // Reenumerate all subcontacts (maybe MetaContacts was disabled int numContacts = CallService(MS_MC_GETNUMCONTACTS,(WPARAM)hContact,0); HANDLE hSubContact = NULL; for(int i=0;i<numContacts;i++) { hSubContact = (HANDLE *) CallService(MS_MC_GETSUBCONTACT,(WPARAM)hContact, (LPARAM)i); if(!FindContact(hSubContact)) { AddContact(hSubContact); } } } CListContainer<CContactListEntry*,CContactListGroup*> *pParent = (CListContainer<CContactListEntry*,CContactListGroup*>*)pGroup->GetParent(); while(pParent != NULL && pGroup->IsEmpty() && !pGroup->GetGroupData()->hMetaContact) { pParent->RemoveGroup(pGroup->GetGroupData()); pGroup = pParent; pParent = (CListContainer<CContactListEntry*,CContactListGroup*>*)pGroup->GetParent(); } } }
void NetworkContact::AddConnect(time_t t, uint32_t bytes_sent, uint32_t bytes_received) { AddContact(t); daten_t d = static_cast<daten_t>(t); if (bytes_sent > 0) { ncr_.ncr.lastcontactsent = d; ncr_.ncr.bytes_waiting = 0; ncr_.ncr.bytes_sent += bytes_sent; } ncr_.ncr.bytes_received += bytes_received; }
HANDLE CDatabase::FindOrAddContact(const wchar_t* uri, const wchar_t* nick, bool temporary) const { MTLASSERT(uri); HANDLE hContact = FindContact(uri); if(!hContact) hContact = AddContact(uri, nick, temporary); MTLASSERT(hContact); return hContact; }
Babel::Babel(QWidget *parent) : QMainWindow(parent), dial(new Dial) { ui.setupUi(this); ui.ButtonLogin->setEnabled(false); QObject::connect(ui.actionQuit, SIGNAL(triggered()), qApp, SLOT(quit())); QObject::connect(ui.InputLogin, SIGNAL(textChanged(QString)), this, SLOT(check_config())); QObject::connect(ui.InputIp, SIGNAL(textChanged(QString)), this, SLOT(check_config())); QObject::connect(ui.InputPort, SIGNAL(textChanged(QString)), this, SLOT(check_config())); QObject::connect(ui.ButtonLogin, SIGNAL(clicked()), this, SLOT(login())); QObject::connect(ui.AddButton, SIGNAL(clicked()), this, SLOT(AddContact())); QObject::connect(ui.CallButton, SIGNAL(clicked()), this, SLOT(CallContact())); QObject::connect(ui.ListAll, SIGNAL(itemSelectionChanged()), this, SLOT(UnselectListContact())); QObject::connect(ui.ListContact, SIGNAL(itemSelectionChanged()), this, SLOT(UnselectListAll())); }
//************************************************************************ // called when a contacts hidden flag has changed //************************************************************************ void CContactList::OnContactHiddenChanged(MCONTACT hContact, bool bHidden) { CListEntry<CContactListEntry*,CContactListGroup*> *pContactEntry = FindContact(hContact); if(!pContactEntry && !bHidden) { AddContact(hContact); return; } else if(!pContactEntry) return; if(!IsVisible(GetContactData(pContactEntry))) RemoveContact(hContact); }
//************************************************************************ // called when the contacts message count has changed //************************************************************************ void CContactList::OnMessageCountChanged(MCONTACT hContact) { CListEntry<CContactListEntry *,CContactListGroup*> *pContactEntry = FindContact(hContact); if(!pContactEntry) { AddContact(hContact); return; } UpdateMessageCounter(pContactEntry); if(!IsVisible(GetContactData(pContactEntry))) RemoveContact(hContact); ((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry->GetParent())->sort(CContactList::CompareEntries); }
//************************************************************************ // called when a contacts status has changed //************************************************************************ void CContactList::OnStatusChange(MCONTACT hContact,int iStatus) { // find the entry in the list CListEntry<CContactListEntry *,CContactListGroup*> *pContactEntry = FindContact(hContact); if(!pContactEntry) { AddContact(hContact); return; } CContactListEntry *pItemData = GetContactData(pContactEntry); if(!pItemData) { return; } // get the old status int iOldStatus = pItemData->iStatus; // Update the list entry TCHAR *szStatus = pcli->pfnGetStatusModeDescription(iStatus, 0); if(szStatus != NULL) pItemData->strStatus =toTstring(szStatus); pItemData->iStatus = iStatus; // update the contacts group CListContainer<CContactListEntry*,CContactListGroup*>* pGroup = ((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry->GetParent()); if(pGroup->GetType() != ROOT) { if(!db_mc_isSub(hContact) && iStatus == ID_STATUS_OFFLINE && iOldStatus != ID_STATUS_OFFLINE) ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,-1); else if(!db_mc_isSub(hContact) && iStatus != ID_STATUS_OFFLINE && iOldStatus == ID_STATUS_OFFLINE) ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,1); } // check if the entry is still visible if(!IsVisible(pItemData)) { RemoveContact(hContact); return; } // sort the list pGroup->sort(CContactList::CompareEntries); }
//************************************************************************ // called when a contacts status has changed //************************************************************************ void CContactList::OnStatusChange(HANDLE hContact,int iStatus) { // find the entry in the list CListEntry<CContactListEntry *,CContactListGroup*> *pContactEntry = FindContact(hContact); if(!pContactEntry) { AddContact(hContact); return; } CContactListEntry *pItemData = GetContactData(pContactEntry); if(!pItemData) { return; } // get the old status int iOldStatus = pItemData->iStatus; // Update the list entry char *szStatus = (char *) CallService(MS_CLIST_GETSTATUSMODEDESCRIPTION, iStatus, 0); if(szStatus != NULL) pItemData->strStatus =toTstring(szStatus); pItemData->iStatus = iStatus; // update the contacts group CListContainer<CContactListEntry*,CContactListGroup*>* pGroup = ((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry->GetParent()); if(pGroup->GetType() != ROOT) { if(!CAppletManager::IsSubContact(hContact) && iStatus == ID_STATUS_OFFLINE && iOldStatus != ID_STATUS_OFFLINE) ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,-1); else if(!CAppletManager::IsSubContact(hContact) && iStatus != ID_STATUS_OFFLINE && iOldStatus == ID_STATUS_OFFLINE) ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,1); } // check if the entry is still visible if(!IsVisible(pItemData)) { RemoveContact(hContact); return; } // sort the list pGroup->sort(CContactList::CompareEntries); }
void CSkypeProto::OnTrouterEvent(const JSONNode &body, const JSONNode &) { //std::string displayname = body["displayName"].as_string(); //std::string cuid = body["callerId"].as_string(); std::string uid = body["conversationId"].as_string(); std::string gp = body["gp"].as_string(); int evt = body["evt"].as_int(); switch (evt) { case 100: //incoming call { std::string callId = body["convoCallId"].as_string(); if (!uid.empty()) { MCONTACT hContact = AddContact(uid.c_str(), true); MEVENT hEvent = AddDbEvent(SKYPE_DB_EVENT_TYPE_INCOMING_CALL, hContact, time(NULL), DBEF_READ, gp.c_str(), callId.c_str()); SkinPlaySound("skype_inc_call"); CLISTEVENT cle = { sizeof(cle) }; cle.flags |= CLEF_TCHAR; cle.hContact = hContact; cle.hDbEvent = hEvent; cle.lParam = SKYPE_DB_EVENT_TYPE_INCOMING_CALL; cle.hIcon = IcoLib_GetIconByHandle(GetIconHandle("inc_call")); CMStringA service(FORMAT, "%s/IncomingCallCLE", GetContactProto(hContact)); cle.pszService = service.GetBuffer(); CMString tooltip(FORMAT, TranslateT("Incoming call from %s"), pcli->pfnGetContactDisplayName(hContact, 0)); cle.ptszTooltip = tooltip.GetBuffer(); CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle); ShowNotification(pcli->pfnGetContactDisplayName(hContact, 0), TranslateT("Incoming call"), hContact, SKYPE_DB_EVENT_TYPE_INCOMING_CALL); } } break; case 104: //call canceled: callerId=""; conversationId=NULL; callId=call id // std::string callId = body["callId"].as_string(); SkinPlaySound("skype_call_canceled"); break; } }
//************************************************************************ // called when a contact has been added //************************************************************************ void CContactList::OnContactAdded(MCONTACT hContact) { // Update the list AddContact(hContact); // increase the membercount of the new group, and check if it needs to be created tstring strGroup = GetContactGroupPath(hContact); if(!strGroup.empty()) { CContactListGroup *pGroup = GetGroupObjectByPath(strGroup); if(!pGroup) pGroup = CreateGroupObjectByPath(strGroup); if(!db_mc_isSub(hContact)) ChangeGroupObjectCounters(strGroup,1); } }
void CSametimeProto::ClearInviteQueue() { debugLog(_T("CSametimeProto::ClearInviteQueue() start")); if (!my_conference) return; mwIdBlock idb; idb.community = 0; while(invite_queue.size()) { idb.user = (char *)invite_queue.front().c_str(); MCONTACT hContact = FindContactByUserId(idb.user); if (!hContact) { mwSametimeList* user_list = mwSametimeList_new(); char* utfs = mir_utf8encodeT(TranslateT("None")); mwSametimeGroup* stgroup = mwSametimeGroup_new(user_list, mwSametimeGroup_NORMAL, utfs); mwSametimeUser* stuser = mwSametimeUser_new(stgroup, mwSametimeUser_NORMAL, &idb); hContact = AddContact(stuser, (options.add_contacts ? false : true)); mwSametimeList_free(user_list); mir_free(utfs); } bool found = false; GList *members, *mem; members = mem = mwConference_getMembers(my_conference); for (;mem;mem=mem->next) { if (my_login_info && strcmp(idb.user, ((mwLoginInfo *)mem->data)->user_id) == 0) { found = true; break; } } g_list_free(members); if (!found) { char* temp = mir_utf8encodeT(TranslateT("Please join this meeting.")); mwConference_invite(my_conference, &idb, temp); mir_free(temp); } invite_queue.pop(); } }
void CSkypeProto::LoadContactsAuth(const NETLIBHTTPREQUEST *response) { if (response == NULL) return; JSONNode root = JSONNode::parse(response->pData); if (!root) return; const JSONNode &items = root.as_array(); for (size_t i = 0; i < items.size(); i++) { const JSONNode &item = items.at(i); if (!item) break; std::string skypename = item["sender"].as_string(); std::string reason = item["greeting"].as_string(); time_t eventTime = IsoToUnixTime(item["event_time_iso"].as_string().c_str()); MCONTACT hContact = AddContact(skypename.c_str()); if (hContact) { time_t lastEventTime = db_get_dw(hContact, m_szModuleName, "LastAuthRequestTime", 0); if (lastEventTime < eventTime) { db_set_dw(hContact, m_szModuleName, "LastAuthRequestTime", eventTime); delSetting(hContact, "Auth"); DB_AUTH_BLOB blob(hContact, NULL, NULL, NULL, skypename.c_str(), reason.c_str()); PROTORECVEVENT pre = { 0 }; pre.timestamp = time(NULL); pre.lParam = blob.size(); pre.szMessage = blob; ProtoChainRecv(hContact, PSR_AUTH, 0, (LPARAM)&pre); } } } }
MCONTACT CSkypeProto::AddToListByEvent(int, int, MEVENT hDbEvent) { debugLogA(__FUNCTION__); DBEVENTINFO dbei = { sizeof(dbei) }; if ((dbei.cbBlob = db_event_getBlobSize(hDbEvent)) == (DWORD)(-1)) return NULL; if ((dbei.pBlob = (PBYTE)alloca(dbei.cbBlob)) == NULL) return NULL; if (db_event_get(hDbEvent, &dbei)) return NULL; if (mir_strcmp(dbei.szModule, m_szModuleName)) return NULL; if (dbei.eventType != EVENTTYPE_AUTHREQUEST) return NULL; DB_AUTH_BLOB blob(dbei.pBlob); MCONTACT hContact = AddContact(ptrA(blob.get_id())); return hContact; }
//************************************************************************ // refreshes the list //************************************************************************ void CContactList::RefreshList() { if((db_get_b(NULL,"MetaContacts","Enabled",1) != 0) != m_bUseMetaContacts || CConfig::GetBoolSetting(CLIST_USEGROUPS) != m_bUseGroups) { InitializeGroupObjects(); Clear(); } m_bUseGroups = CConfig::GetBoolSetting(CLIST_USEGROUPS); m_bUseMetaContacts = db_get_b(NULL,"MetaContacts","Enabled",1) != 0; CListEntry<CContactListEntry*,CContactListGroup*> *pContactEntry = NULL; MCONTACT hContact = db_find_first(); while(hContact != NULL) { pContactEntry = FindContact(hContact); if(!pContactEntry) AddContact(hContact); else if(pContactEntry && !IsVisible(GetContactData(pContactEntry))) RemoveContact(hContact); hContact = db_find_next(hContact); } }
int RoutingTable::AddContact(const Contact &new_contact) { short int index = KBucketIndex(new_contact.node_id()); KBucketExitCode exitcode = FAIL; if (index < 0) return 3; exitcode = k_buckets_[index]->AddContact(new_contact); switch (exitcode) { case SUCCEED: return 0; case FULL: if (K_ > 2 && !k_buckets_[index]->KeyInRange(holder_id_)) { if (index == brother_bucket_of_holder_) { if (ForceKAcceptNewPeer(new_contact) != 0) { return 2; } else { return 0; } } return 2; } SplitKbucket(index); return AddContact(new_contact); case FAIL: default: return -2; } }
int CSkypeProto::OnGroupChatEventHook(WPARAM, LPARAM lParam) { GCHOOK *gch = (GCHOOK*)lParam; if (!gch) { return 1; } else if (mir_strcmp(gch->pDest->pszModule, m_szModuleName) != 0) { return 0; } ptrA chat_id(mir_t2a(gch->pDest->ptszID)); switch (gch->pDest->iType) { case GC_USER_MESSAGE: { OnSendChatMessage(gch->pDest->ptszID, gch->ptszText); break; } case GC_USER_PRIVMESS: { MCONTACT hContact = FindContact(_T2A(gch->ptszUID)); if (hContact == NULL) { hContact = AddContact(_T2A(gch->ptszUID), true); setWord(hContact, "Status", ID_STATUS_ONLINE); db_set_b(hContact, "CList", "Hidden", 1); setTString(hContact, "Nick", gch->ptszUID); db_set_dw(hContact, "Ignore", "Mask1", 0); } CallService(MS_MSG_SENDMESSAGET, hContact, 0); break; } case GC_USER_LOGMENU: { switch (gch->dwData) { case 10: { CSkypeInviteDlg dlg(this); if(!dlg.DoModal()) { break; } MCONTACT hContact = dlg.m_hContact; if (hContact != NULL) { ptrA username(db_get_sa(hContact, m_szModuleName, SKYPE_SETTINGS_ID)); SendRequest(new InviteUserToChatRequest(m_szRegToken, chat_id, username, "User", m_szServer)); } break; } case 20: OnLeaveChatRoom(FindChatRoom(chat_id), NULL); break; case 30: CMString newTopic = ChangeTopicForm(); if (!newTopic.IsEmpty()) SendRequest(new SetChatPropertiesRequest(m_szRegToken, chat_id, "topic", ptrA(mir_utf8encodeT(newTopic.GetBuffer())), m_szServer)); break; } break; } case GC_USER_NICKLISTMENU: { ptrA user_id; if (gch->dwData == 10 || gch->dwData == 30 || gch->dwData == 40) { user_id = mir_t2a_cp(gch->ptszUID, CP_UTF8); } switch (gch->dwData) { case 10: SendRequest(new KickUserRequest(m_szRegToken, chat_id, user_id, m_szServer)); break; case 30: SendRequest(new InviteUserToChatRequest(m_szRegToken, chat_id, user_id, "Admin", m_szServer)); break; case 40: SendRequest(new InviteUserToChatRequest(m_szRegToken, chat_id, user_id, "User", m_szServer)); break; } break; } } return 0; }
static MCONTACT ImportContact(MCONTACT hSrc) { MCONTACT hDst; TCHAR id[ 40 ], *pszUniqueID; char szProto[100]; // Check what protocol this contact belongs to if (myGetS(hSrc, "Protocol", "p", szProto)) { AddMessage(LPGENT("Skipping contact with no protocol")); return NULL; } if (!IsProtocolLoaded(szProto)) { AddMessage(LPGENT("Skipping contact, %S not installed."), szProto); return NULL; } // Skip protocols with no unique id setting (some non IM protocols return NULL) char* pszUniqueSetting = (char*)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); if (!pszUniqueSetting || (INT_PTR)pszUniqueSetting == CALLSERVICE_NOTFOUND) { AddMessage(LPGENT("Skipping non-IM contact (%S)"), szProto); return NULL; } DBVARIANT dbv; if (myGet(hSrc, szProto, pszUniqueSetting, &dbv)) { AddMessage(LPGENT("Skipping %S contact, ID not found"), szProto); return NULL; } // Does the contact already exist? switch (dbv.type) { case DBVT_DWORD: pszUniqueID = _ltot(dbv.dVal, id, 10); hDst = HContactFromNumericID(szProto, pszUniqueSetting, dbv.dVal); break; case DBVT_ASCIIZ: pszUniqueID = NEWTSTR_ALLOCA(_A2T(dbv.pszVal)); hDst = HContactFromID(szProto, pszUniqueSetting, pszUniqueID); break; case DBVT_WCHAR: pszUniqueID = NEWTSTR_ALLOCA(dbv.ptszVal); hDst = HContactFromID(szProto, pszUniqueSetting, pszUniqueID); break; } if (hDst != INVALID_CONTACT_ID) { AddMessage(LPGENT("Skipping duplicate %S contact %s"), szProto, pszUniqueID); srcDb->FreeVariant(&dbv); return NULL; } TCHAR *tszGroup = myGetWs(hSrc, "CList", "Group"), *tszNick = myGetWs(hSrc, "CList", "MyHandle"); if (tszNick == NULL) tszNick = myGetWs(hSrc, szProto, "Nick"); hDst = AddContact(hdlgProgress, szProto, pszUniqueSetting, &dbv, pszUniqueID, tszNick, tszGroup); mir_free(tszGroup), mir_free(tszNick); if (hDst != INVALID_CONTACT_ID) { // Hidden? if (!myGet(hSrc, "CList", "Hidden", &dbv)) { mySet(hDst, "CList", "Hidden", &dbv); srcDb->FreeVariant(&dbv); } // Ignore settings if (!myGet(hSrc, "Ignore", "Mask1", &dbv)) { mySet(hDst, "Ignore", "Mask1", &dbv); srcDb->FreeVariant(&dbv); } // Apparent mode if (!myGet(hSrc, szProto, "ApparentMode", &dbv)) { mySet(hDst, szProto, "ApparentMode", &dbv); srcDb->FreeVariant(&dbv); } // Nick if (!myGet(hSrc, szProto, "Nick", &dbv)) { mySet(hDst, szProto, "Nick", &dbv); srcDb->FreeVariant(&dbv); } // Myhandle if (!myGet(hSrc, szProto, "MyHandle", &dbv)) { mySet(hDst, szProto, "MyHandle", &dbv); srcDb->FreeVariant(&dbv); } // First name if (!myGet(hSrc, szProto, "FirstName", &dbv)) { mySet(hDst, szProto, "FirstName", &dbv); srcDb->FreeVariant(&dbv); } // Last name if (!myGet(hSrc, szProto, "LastName", &dbv)) { mySet(hDst, szProto, "LastName", &dbv); srcDb->FreeVariant(&dbv); } // About if (!myGet(hSrc, szProto, "About", &dbv)) { mySet(hDst, szProto, "About", &dbv); srcDb->FreeVariant(&dbv); } } else AddMessage(LPGENT("Unknown error while adding %S contact %s"), szProto, pszUniqueID); return hDst; }
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); }
void CSkypeProto::LoadContactList(const NETLIBHTTPREQUEST *response) { if (response == NULL) return; JSONNode root = JSONNode::parse(response->pData); if (!root) return; LIST<char> skypenames(1); bool loadAll = getBool("LoadAllContacts", false); const JSONNode &items = root["contacts"].as_array(); for (size_t i = 0; i < items.size(); i++) { const JSONNode &item = items.at(i); if (!item) break; const JSONNode &name = item["name"]; const JSONNode &phones = item["phones"]; std::string skypename = item["id"].as_string(); CMString display_name = item["display_name"].as_mstring(); CMString first_name = name["first"].as_mstring(); CMString last_name = name["surname"].as_mstring(); CMString avatar_url = item["avatar_url"].as_mstring(); std::string type = item["type"].as_string(); if (type == "skype" || loadAll) { MCONTACT hContact = AddContact(skypename.c_str()); if (hContact) { if (item["authorized"].as_bool()) { delSetting(hContact, "Auth"); delSetting(hContact, "Grant"); } else setByte(hContact, "Grant", 1); if (item["blocked"].as_bool()) { db_set_dw(hContact, "Ignore", "Mask1", 127); db_set_b(hContact, "CList", "Hidden", 1); setByte(hContact, "IsBlocked", 1); } else { if (db_get_b(hContact, m_szModuleName, "IsBlocked", 0)) { db_set_dw(hContact, "Ignore", "Mask1", 0); db_set_b(hContact, "CList", "Hidden", 0); setByte(hContact, "IsBlocked", 0); } } setString(hContact, "Type", type.c_str()); if (display_name) setTString(hContact, "Nick", display_name); if (first_name) setTString(hContact, "FirstName", first_name); if (last_name) setTString(hContact, "LastName", last_name); SetAvatarUrl(hContact, avatar_url); ReloadAvatarInfo(hContact); for (size_t j = 0; j < phones.size(); j++) { const JSONNode &phone = phones.at(j); if (!phone) break; CMString number = phone["number"].as_mstring(); switch (phone["type"].as_int()) { case 0: setTString(hContact, "Phone", number); break; case 2: setTString(hContact, "Cellular", number); break; } } if (type == "skype") skypenames.insert(mir_strdup(skypename.c_str())); } } } if (skypenames.getCount() > 0) { int i = 0; do { LIST<char> users(1); for (; i < skypenames.getCount() && users.getCount() <= 50; i++) users.insert(skypenames[i]); PushRequest(new GetContactsInfoRequest(li, users), &CSkypeProto::LoadContactsInfo); } while(i < skypenames.getCount()); FreeList(skypenames); skypenames.destroy(); } PushRequest(new GetContactsAuthRequest(li), &CSkypeProto::LoadContactsAuth); }
status_t Jabber::Process( BMessage * msg ) { switch ( msg->what ) { case IM::MESSAGE: { int32 im_what = 0; msg->FindInt32("im_what", &im_what ); switch ( im_what ) { case IM::SET_STATUS: { const char *status = msg->FindString("status"); LOG(kProtocolName, liMedium, "Set status to %s", status); if (strcmp(status, OFFLINE_TEXT) == 0) { SetStatus(S_OFFLINE,OFFLINE_TEXT); //do the log-out? } else if (strcmp(status, AWAY_TEXT) == 0) { if(IsAuthorized()){ //const char *away_msg; BString away_msg; if(msg->FindString("away_msg",&away_msg) == B_OK) { // quick and dirty way to use advanced away status: // add 'DND: ' for Do not Disturb // or 'XA: ' for Extended Away if(away_msg.Compare("DND: ",4) == 0) SetStatus(S_DND,away_msg); else if(away_msg.Compare("XA: ",4) == 0) SetStatus(S_XA,away_msg); else SetStatus(S_AWAY,away_msg); } else SetStatus(S_AWAY,AWAY_TEXT); SetAway(true); } } else if (strcmp(status, ONLINE_TEXT) == 0) { if(!IsAuthorized()) { if(fUsername == "") Error("Empty Username!",NULL); if(fServer == "") Error("Empty Server!",NULL); if(fPassword == "") Error("Empty Password!",NULL); Progress("Jabber Login", "Jabber: Connecting..", 0.0); } SetStatus(S_ONLINE,ONLINE_TEXT); //do the login! if(IsAuthorized()) SetAway(false); } else { Error("Invalid",NULL); LOG(kProtocolName, liHigh, "Invalid status when setting status: '%s'", status); } } break; case IM::SEND_MESSAGE: { const char * buddy=msg->FindString("id"); const char * sms=msg->FindString("message"); JabberMessage jm; jm.SetTo(buddy); jm.SetFrom(GetJid()); jm.SetBody(sms); TimeStamp(jm); //not the right place.. see Jabber::Message JabberContact *contact=getContact(buddy); //tmp: new mess id! BString messid("imkit_"); messid << idsms; idsms++; if(contact) jm.SetID(messid); SendMessage(jm); MessageSent(buddy,sms); } break; case IM::REGISTER_CONTACTS: { //debugger("REGISTER"); type_code garbage; int32 count = 0; msg->GetInfo("id", &garbage, &count); if (count > 0 ) { for ( int i=0; msg->FindString("id",i); i++ ) { const char * id = msg->FindString("id",i); JabberContact* contact=getContact(id); if(contact) BuddyStatusChanged(contact); else { //Are we on-line? // send auth req? if(fFullLogged) { AddContact(id,id,""); BuddyStatusChanged(id,OFFLINE_TEXT); } else { // we add to a temp list. // when logged in we will register the new buddy.. fLaterBuddyList->push_back(BString(id)); } } }; } else return B_ERROR; } break; case IM::UNREGISTER_CONTACTS: { const char * buddy=NULL; for ( int i=0; msg->FindString("id", i, &buddy) == B_OK; i++ ) { LOG(kProtocolName, liDebug, "Unregister Contact: '%s'", buddy); if(!fFullLogged) BuddyStatusChanged(buddy,OFFLINE_TEXT); else { LOG(kProtocolName, liDebug, "Unregister Contact DOING IT"); JabberContact* contact=getContact(buddy); if(contact) RemoveContact(contact); } } } break; case IM::USER_STARTED_TYPING: { const char * id=NULL; if( msg->FindString("id", &id) == B_OK ) { JabberContact* contact=getContact(id); if(contact) StartComposingMessage(contact); } } break; case IM::USER_STOPPED_TYPING: { const char * id=NULL; if( msg->FindString("id", &id) == B_OK ) { JabberContact* contact=getContact(id); if(contact && (contact->GetLastMessageID().ICompare("")!=0)){ StopComposingMessage(contact); contact->SetLastMessageID(""); } } } break; case IM::GET_CONTACT_INFO: //debugger("Get Contact Info! ;)"); SendContactInfo(msg->FindString("id")); break; case IM::SEND_AUTH_ACK: { if(!IsAuthorized()) return B_ERROR; const char * id = msg->FindString("id"); int32 button = msg->FindInt32("which"); if (button == 0) { //Authorization granted AcceptSubscription(id); BMessage im_msg(IM::MESSAGE); im_msg.AddInt32("im_what", IM::CONTACT_AUTHORIZED); im_msg.AddString("protocol", kProtocolName); im_msg.AddString("id", id); im_msg.AddString("message", ""); fServerMsgr.SendMessage(&im_msg); //now we want to see you! ;) AddContact(id,id,""); } else { //Authorization rejected Error("Authorization rejected!",id); } } break; default: // we don't handle this im_what code msg->PrintToStream(); return B_ERROR; } } break; default: // we don't handle this what code return B_ERROR; } return B_OK; }
//************************************************************************ // adds a contact to the list //************************************************************************ void CContactList::AddContact(MCONTACT hContact) { CListContainer<CContactListEntry*,CContactListGroup*> *pGroup = NULL; tstring strName = CAppletManager::GetContactDisplayname(hContact); char *szProto = GetContactProto(hContact); tstring strGroup = GetContactGroupPath(hContact); // ignore contacts without a valid protocoll if(szProto == NULL) return; int iStatus = db_get_w(hContact,szProto,"Status",ID_STATUS_OFFLINE); TCHAR *szStatus = pcli->pfnGetStatusModeDescription(iStatus, 0); CContactListEntry *psContact = new CContactListEntry(); psContact->strName = strName; psContact->iMessages = 0; psContact->hHandle = hContact; psContact->iStatus = iStatus; if(szStatus != NULL) psContact->strStatus =toTstring(szStatus); psContact->strProto = toTstring(szProto); // check wether the contact should be listed if(!IsVisible(psContact)) { delete psContact; return; } // Don't add metacontacts as contacts if(!mir_strcmpi(szProto,"MetaContacts")) { if(!CConfig::GetBoolSetting(CLIST_USEGROUPS)) strGroup = _T(""); strGroup += (strGroup.empty()?_T(""):_T("\\"))+psContact->strName; pGroup = GetGroupByString(strGroup); if(pGroup == NULL) pGroup = AddGroupByString(strGroup); pGroup->GetGroupData()->hMetaContact = hContact; pGroup->GetGroupData()->pContactListEntry = psContact; pGroup = (CListContainer<CContactListEntry*,CContactListGroup*>*)pGroup->GetParent(); if(pGroup->GetType() != ROOT && iStatus != ID_STATUS_OFFLINE) ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,1); pGroup->sort(CContactList::CompareEntries); // check that all subcontacts exist int numContacts = db_mc_getSubCount(hContact); MCONTACT hSubContact = NULL; for(int i=0;i<numContacts;i++) { hSubContact = db_mc_getSub(hContact, i); RemoveContact(hSubContact); AddContact(hSubContact); } return; } else if(db_mc_isSub(hContact)) { MCONTACT hMetaContact = db_mc_getMeta(hContact); // check that the metacontact exists if(!FindContact(hMetaContact)) AddContact(hMetaContact); } CListItem<CContactListEntry*,CContactListGroup*> *pItem = NULL; if((!db_mc_isSub(hContact) && !CConfig::GetBoolSetting(CLIST_USEGROUPS)) || strGroup.empty()) { pItem = AddItem(psContact); ((CListContainer<CContactListEntry*,CContactListGroup*>*)this)->sort(CContactList::CompareEntries); } else { pGroup = GetGroupByString(strGroup); if(pGroup == NULL) { pGroup = AddGroupByString(strGroup); } pItem = pGroup->AddItem(psContact); if(!db_mc_isSub(hContact) && iStatus != ID_STATUS_OFFLINE) ChangeGroupObjectCounters(pGroup->GetGroupData()->strPath,0,1); pGroup->sort(CContactList::CompareEntries); } UpdateMessageCounter((CListEntry<CContactListEntry*,CContactListGroup*>*)pItem); }
//************************************************************************ // called when a contacts group has changed //************************************************************************ void CContactList::OnContactGroupChanged(MCONTACT hContact,tstring strGroup) { bool bMetaContact = false; strGroup = GetContactGroupPath(hContact); // Decrease the membercount of the old group CListEntry<CContactListEntry *,CContactListGroup*> *pContactEntry = FindContact(hContact); CContactListGroup *pOldGroup = NULL; // If the contactentry was not found, try adding the contact (metacontacts fix) if(!pContactEntry) { return; } if(pContactEntry->GetType() == CONTAINER) bMetaContact = true; CListContainer<CContactListEntry*,CContactListGroup*>* pContainer = ((CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry->GetParent()); // Update the contacts group if it has one if(pContainer->GetType() != ROOT) { pOldGroup = pContainer->GetGroupData(); if(!db_mc_isSub(hContact)) ChangeGroupObjectCounters(pOldGroup->strPath,-1); } // increase the membercount of the new group, and check if it needs to be created if(!strGroup.empty()) { CContactListGroup *pGroup = GetGroupObjectByPath(strGroup); if(!pGroup) pGroup = CreateGroupObjectByPath(strGroup); if(!db_mc_isSub(hContact)) ChangeGroupObjectCounters(strGroup,1); } // move subcontacts if(pContactEntry->GetType() == CONTAINER) { CListContainer<CContactListEntry*,CContactListGroup*> *pGroup = (CListContainer<CContactListEntry*,CContactListGroup*>*)pContactEntry; CListContainer<CContactListEntry*,CContactListGroup*>::iterator iter = pGroup->begin(); while(!pGroup->empty()) { iter = pGroup->begin(); if((*iter)->GetType() == ITEM) OnContactGroupChanged(GetContactData(*iter)->hHandle,_T("")); Sleep(1); } } // update the list RemoveContact(hContact); AddContact(hContact); if(bMetaContact) { tstring strName = CAppletManager::GetContactDisplayname(hContact); tstring strPath = _T(""); if(pOldGroup) strPath += pOldGroup->strPath; strPath += (strPath.empty()?_T(""):_T("\\")) + strName; DeleteGroupObjectByPath(strPath); } // check if the old group ( if it exists ) needs to be deleted if(pOldGroup && !pOldGroup->hMetaContact && pOldGroup->iMembers <= 0 && pOldGroup->iGroups <= 0) DeleteGroupObjectByPath(pOldGroup->strPath); }