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; }
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 CSametimeProto::ExportContactsToServer() { mwSametimeList* user_list; mwStorageUnit* unit; mwPutBuffer* buff; mwOpaque* op; debugLog(_T("CSametimeProto::ExportContactsToServer() start")); if (MW_SERVICE_IS_DEAD(service_storage)) { debugLog(_T("CSametimeProto::ExportContactsToServer() Failed")); showPopup(TranslateT("Failed to upload contacts - storage service unavailable."), SAMETIME_POPUP_ERROR); return; } user_list = mwSametimeList_new(); ExportContactsToList(user_list); buff = mwPutBuffer_new(); mwSametimeList_put(buff, user_list); mwSametimeList_free(user_list); /* put the buffer contents into a storage unit */ unit = mwStorageUnit_new(mwStore_AWARE_LIST); op = mwStorageUnit_asOpaque(unit); mwPutBuffer_finalize(op, buff); /* save the storage unit to the service */ mwServiceStorage_save(service_storage, unit, NULL, NULL, NULL); }
void load_users_callback(mwServiceStorage* srvc, guint32 result, mwStorageUnit *item, gpointer data) { CSametimeProto* proto = getProtoFromMwServiceStorage(srvc); if (mwStorageUnit_getKey(item) == mwStore_AWARE_LIST) { mwGetBuffer *buff = mwGetBuffer_wrap(mwStorageUnit_asOpaque(item)); if (mwGetBuffer_remaining(buff)) { mwSametimeList* user_list = mwSametimeList_new(); mwSametimeList_get(buff, user_list); proto->ImportContactsFromList(user_list, false); mwSametimeList_free(user_list); } } }
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 MeanwhileSession::handleStorageLoad(struct mwServiceStorage * /* srvc */, guint32 result, struct mwStorageUnit *item, gpointer /* data */) { HERE; if (result != ERR_SUCCESS) { mwDebug() << "contact list load returned " << result << endl; return; } struct mwGetBuffer *buf = mwGetBuffer_wrap(mwStorageUnit_asOpaque(item)); struct mwSametimeList *list = mwSametimeList_new(); mwSametimeList_get(buf, list); GList *gl, *glf, *cl, *clf; Kopete::ContactList *contactlist = Kopete::ContactList::self(); for (glf = gl = mwSametimeList_getGroups(list); gl; gl = gl->next) { struct mwSametimeGroup *stgroup = (struct mwSametimeGroup *)gl->data; Kopete::Group *group = contactlist->findGroup(mwSametimeGroup_getName(stgroup)); group->setPluginData(account->protocol(), "alias", mwSametimeGroup_getAlias(stgroup)); for (clf = cl = mwSametimeGroup_getUsers(stgroup); cl; cl = cl->next) { struct mwSametimeUser *stuser = (struct mwSametimeUser *)cl->data; MeanwhileContact *contact = static_cast<MeanwhileContact *> (account->contacts().value(mwSametimeUser_getUser(stuser))); if (contact != 0L) continue; account->addContact(mwSametimeUser_getUser(stuser), mwSametimeUser_getAlias(stuser), group, Kopete::Account::ChangeKABC); } g_list_free(clf); } g_list_free(glf); mwSametimeList_free(list); }
/** triggered when someone joins the conference */ void mwServiceConf_on_peer_joined(mwConference* conf, mwLoginInfo *user) { CSametimeProto* proto = getProtoFromMwConference(conf); proto->debugLog(_T("mwServiceConf_on_peer_joined() start")); MCONTACT hContact = proto->FindContactByUserId(user->user_id); if (!hContact) { mwIdBlock idb; idb.user = ((mwLoginInfo *)user)->user_id; idb.community = 0; 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 = proto->AddContact(stuser, (proto->options.add_contacts ? false : true)); mwSametimeList_free(user_list); mir_free(utfs); } ptrT tszConfId(mir_utf8decodeT(mwConference_getName(conf))); ptrT tszUserName(mir_utf8decodeT(user->user_name)); ptrT tszUserId(mir_utf8decodeT(user->login_id)); // add user GCDEST gcd = { proto->m_szModuleName }; gcd.ptszID = tszConfId; gcd.iType = GC_EVENT_JOIN; GCEVENT gce = { sizeof(gce), &gcd }; gce.dwFlags = GCEF_ADDTOLOG; gce.ptszNick = tszUserName; gce.ptszUID = tszUserId; gce.ptszStatus = _T("Normal"); gce.time = (DWORD)time(0); CallServiceSync(MS_GC_EVENT, 0, (LPARAM) &gce); mir_free(tszUserName); mir_free(tszUserId); mir_free(tszConfId); }
/** an incoming file transfer has been offered */ void mwFileTransfer_offered(mwFileTransfer* ft) { CSametimeProto* proto = getProtoFromMwFileTransfer(ft); proto->debugLog(_T("mwFileTransfer_offered() start")); const mwIdBlock* idb = mwFileTransfer_getUser(ft); MCONTACT hContact = proto->FindContactByUserId(idb->user); proto->debugLog(_T("Sametime mwFileTransfer_offered hContact=[%x]"), hContact); if (!hContact) { mwSametimeList* user_list = mwSametimeList_new(); mwSametimeGroup* stgroup = mwSametimeGroup_new(user_list, mwSametimeGroup_NORMAL, Translate("None")); mwSametimeUser* stuser = mwSametimeUser_new(stgroup, mwSametimeUser_NORMAL, (mwIdBlock*)idb); hContact = proto->AddContact(stuser, (proto->options.add_contacts ? false : true)); } proto->ProtoBroadcastAck(hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, (HANDLE)ft, 0); TCHAR* filenameT = mir_utf8decodeT(mwFileTransfer_getFileName(ft)); const char* message = mwFileTransfer_getMessage(ft); TCHAR descriptionT[512]; if (message) { TCHAR* messageT = mir_utf8decodeT(message); mir_sntprintf(descriptionT, _T("%s - %s"), filenameT, messageT); mir_free(messageT); } else _tcsncpy_s(descriptionT, filenameT, _TRUNCATE); PROTORECVFILET pre = {0}; pre.dwFlags = PRFF_TCHAR; pre.fileCount = 1; pre.timestamp = time(NULL); pre.descr.t = descriptionT; pre.files.t = &filenameT; pre.lParam = (LPARAM)ft; ProtoChainRecvFile(hContact, &pre); mir_free(filenameT); }
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 MeanwhileSession::syncContactsToServer() { HERE; struct mwSametimeList *list = mwSametimeList_new(); /* set up a fallback group for top-level contacts */ struct mwSametimeGroup *topstgroup = mwSametimeGroup_new(list, mwSametimeGroup_DYNAMIC, "People"); mwSametimeGroup_setOpen(topstgroup, true); const QHash<QString, Kopete::Contact *> contacts = account->contacts(); // Q3DictIterator<Kopete::Contact> it(account->contacts()); for(QHash<QString, Kopete::Contact *>::const_iterator it = contacts.constBegin(); it != contacts.constEnd(); ++it ) { MeanwhileContact *contact = static_cast<MeanwhileContact *>(it.value()); /* Find the group that the metacontact is in */ Kopete::MetaContact *mc = contact->metaContact(); if (!mc) continue; Kopete::Group *contactgroup = mc->groups().value(0); if (!contactgroup) continue; if (contactgroup->type() == Kopete::Group::Temporary) continue; struct mwSametimeGroup *stgroup; if (contactgroup->type() == Kopete::Group::TopLevel) { stgroup = topstgroup; } else { /* find (or create) a matching sametime list group */ stgroup = mwSametimeList_findGroup(list, contactgroup->displayName().toUtf8().constData()); if (!stgroup) { stgroup = mwSametimeGroup_new(list, mwSametimeGroup_DYNAMIC, contactgroup->displayName().toUtf8().constData()); } mwSametimeGroup_setOpen(stgroup, contactgroup->isExpanded()); mwSametimeGroup_setAlias(stgroup, contactgroup->pluginData(account->protocol(), "alias").toUtf8().constData()); } QByteArray tmpMeanwhileId = contact->meanwhileId().toUtf8(); /* now add the user (by IDBlock) */ struct mwIdBlock id = { (gchar*)tmpMeanwhileId.constData(), 0 }; struct mwSametimeUser *stuser = mwSametimeUser_new(stgroup, mwSametimeUser_NORMAL, &id); mwSametimeUser_setAlias(stuser, mc->displayName().toUtf8().constData()); } /* store! */ struct mwPutBuffer *buf = mwPutBuffer_new(); struct mwStorageUnit *unit = mwStorageUnit_new(mwStore_AWARE_LIST); struct mwOpaque *opaque = mwStorageUnit_asOpaque(unit); mwSametimeList_put(buf, list); mwPutBuffer_finalize(opaque, buf); mwServiceStorage_save(storageService, unit, NULL, NULL, NULL); mwSametimeList_free(list); }