Esempio n. 1
0
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;
}
Esempio n. 2
0
void CSametimeProto::ExportContactsToList(mwSametimeList* user_list)
{
	debugLog(_T("CSametimeProto::ExportContactsToList() start"));
	mwSametimeGroup* stgroup = 0;
	char* group_name;
	char* group_alias;
	mwSametimeGroupType group_type;
	bool group_open;

	mwSametimeUser* stuser;
	char* user_alias;
	char* user_shortName;
	mwSametimeUserType user_type;
	DBVARIANT dbv, dbv2;
	char buff[256];
	mwAwareIdBlock id_block;
	mwIdBlock uid;

	GList* gl = 0;
	for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
		if (!db_get_utf(hContact, m_szModuleName, "stid", &dbv)) {
			if (dbv.pszVal) {
				if (GetAwareIdFromContact(hContact, &id_block)) {
					if (!db_get_utf(hContact, "CList", "Group", &dbv2)) {
						group_alias = _strdup(dbv2.pszVal);
						db_free(&dbv2);
					}
					else
						group_alias = _strdup(Translate("None"));

					if (group_alias) {
						mir_snprintf(buff, "GT_%s", group_alias);
						group_type = (mwSametimeGroupType)db_get_b(0, szProtoGroups, buff, (BYTE)mwSametimeGroup_NORMAL);
						// apparently we don't want to upload contacts in dynamic groups - see gaim sametime plugin comments
						if (group_type == mwSametimeGroup_DYNAMIC) {
							db_free(&dbv);
							free(id_block.user);
							free(group_alias);
							hContact = db_find_next(hContact, m_szModuleName);
							continue;
						}

						mir_snprintf(buff, "GN_%s", group_alias);
						if (!db_get_utf(0, szProtoGroups, buff, &dbv2)) {
							group_name = _strdup(dbv2.pszVal);
							db_free(&dbv2);
						}
						else
							group_name = _strdup(group_alias);

						//group_open = (db_get_b(0, szProtoGroups, buff, 0) == 1);

						ptrT ptszGroup(mir_utf8decodeT(group_alias));
						HANDLE hGroup = Clist_GroupExists(ptszGroup);
						if (hGroup) {
							int expanded;
							CallService(MS_CLIST_GROUPGETNAME, (WPARAM)hGroup, (LPARAM)&expanded);
							group_open = (expanded != 0);
						}
						else {
							mir_snprintf(buff, "GO_%s", group_alias);
							group_open = (db_get_b(0, szProtoGroups, buff, 0) == 1);
						}

						stgroup = 0;
						stgroup = mwSametimeList_findGroup(user_list, group_name);
						if (!stgroup) {
							if (group_name) stgroup = mwSametimeGroup_new(user_list, group_type, group_name);
							mwSametimeGroup_setAlias(stgroup, group_alias);
							mwSametimeGroup_setOpen(stgroup, group_open);
						}

						free(group_name);
						free(group_alias);

						if (!db_get_utf(hContact, m_szModuleName, "Name", &dbv2)) {
							user_shortName = _strdup(dbv2.pszVal);
							db_free(&dbv2);
						}
						else
							user_shortName = 0;

						if (!db_get_utf(hContact, "CList", "MyHandle", &dbv2)) {
							user_alias = _strdup(dbv2.pszVal);
							db_free(&dbv2);
						}
						else
							user_alias = 0;

						user_type = (mwSametimeUserType)db_get_b(hContact, m_szModuleName, "type", (BYTE)mwSametimeUser_NORMAL);

						uid.user = id_block.user;
						uid.community = id_block.community;

						stuser = mwSametimeUser_new(stgroup, user_type, &uid);
						if (user_shortName) {
							mwSametimeUser_setShortName(stuser, user_shortName);
							free(user_shortName);
						}
						if (user_alias) {
							mwSametimeUser_setAlias(stuser, user_alias);
							free(user_alias);
						}
					}

					free(id_block.user);
				}
			}
			db_free(&dbv);
		}
	}
}
Esempio n. 3
0
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);
}