Example #1
0
INT_PTR CSametimeProto::onMenuCreateChat(WPARAM wParam, LPARAM lParam)
{
	MCONTACT hContact = (MCONTACT)wParam;
	debugLog(_T("CSametimeProto::onMenuCreateChat() hContact=[%x]"), hContact);
	mwAwareIdBlock id_block;
	mwIdBlock idb;
	if (my_login_info && GetAwareIdFromContact(hContact, &id_block)) {
		TCHAR title[512];
		TCHAR* ts = mir_utf8decodeT(my_login_info->user_name);
		mir_sntprintf(title, SIZEOF(title), TranslateT("%s's conference"), ts);
		mir_free(ts);

		idb.user = id_block.user;
		idb.community = id_block.community;

		invite_queue.push(idb.user);

		if (!my_conference) {
			debugLog(_T("CSametimeProto::onMenuCreateChat() mwConference_open"));
			char* utfs;
			my_conference = mwConference_new(service_conference, utfs = mir_utf8encodeT(title));
			mwConference_open(my_conference);
			mir_free(utfs);
		} else {
			debugLog(_T("CSametimeProto::onMenuCreateChat() ClearInviteQueue"));
			ClearInviteQueue();
		}

		free(id_block.user);
	}

	return 0;
}
Example #2
0
HANDLE SendMessageToUserW(HANDLE hContact, wchar_t *msg) {
	mwIdBlock idb;
	mwAwareIdBlock id_block;

	char text[MAX_MESSAGE_SIZE];

	WideCharToMultiByte(CP_UTF8, 0, msg, -1, text, MAX_MESSAGE_SIZE * sizeof(char), 0, 0);

	if(GetAwareIdFromContact(hContact, &id_block)) {
		idb.user = id_block.user;
		idb.community = id_block.community;

		mwConversation *conv = mwServiceIm_getConversation(service_im, &idb);
		if(conv) {
			if(!mwConversation_isOpen(conv)) {
				EnterCriticalSection(&q_cs);
				contact_message_queue[hContact].push(text);
				LeaveCriticalSection(&q_cs);

				mwConversation_open(conv);
			} else
				mwConversation_send(conv, mwImSend_PLAIN, (gconstpointer)text);

			free(id_block.user);
			return (HANDLE)conv;
		}

		free(id_block.user);
	}

	return 0;
}
Example #3
0
void CloseIm(HANDLE hContact) {
	mwIdBlock idb;
	mwAwareIdBlock id_block;

	if(GetAwareIdFromContact(hContact, &id_block)) {
		idb.user = id_block.user;
		idb.community = id_block.community;

		mwConversation *conv = mwServiceIm_getConversation(service_im, &idb);
		if(conv) {
			if(mwConversation_isOpen(conv))
				mwConversation_close(conv, 0);
		}
		free(id_block.user);
	}
}
Example #4
0
void CSametimeProto::UserListCreate()
{
	debugLog(_T("CSametimeProto::UserListCreate() start"));
	mwServiceAware_unsetAttribute(service_aware, mwAttribute_SPEAKERS);
	mwServiceAware_unsetAttribute(service_aware, mwAttribute_MICROPHONE);
	mwServiceAware_unsetAttribute(service_aware, mwAttribute_VIDEO_CAMERA);
	mwServiceAware_setAttributeBoolean(service_aware, mwAttribute_AV_PREFS_SET, TRUE);
	mwServiceAware_setAttributeBoolean(service_aware, mwAttribute_FILE_TRANSFER, TRUE);

	aware_list = mwAwareList_new(service_aware, &mwAwareList_handler);

	// add all contacts

	DBVARIANT dbv;
	mwAwareIdBlock id_block;
	GList *gl = 0;

	for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
		if (db_get_b(hContact, m_szModuleName, "ChatRoom", 0) == 0 /*&&  proto && !mir_strcmp( PROTO, proto)*/) {
			if (!db_get_utf(hContact, m_szModuleName, "stid", &dbv)) {
				if (dbv.pszVal) {
					if (GetAwareIdFromContact(hContact, &id_block)) {
						// add user to aware list
						gl = g_list_prepend(0, &id_block);
						mwAwareList_addAware(aware_list, gl);
						free(id_block.user);
						g_list_free(gl);
					}
				}
				db_free(&dbv);
			}
		}
	}

	// add self - might be necessary for some servers
	if (!db_get_utf(0, m_szModuleName, "stid", &dbv)) {
		id_block.type = mwAware_USER;
		id_block.user = dbv.pszVal;
		id_block.community = 0;

		gl = g_list_prepend(0, &id_block);
		mwAwareList_addAware(aware_list, gl);
		g_list_free(gl);

		db_free(&dbv);
	}
}
Example #5
0
void SendTyping(HANDLE hContact, bool typing) {
	mwIdBlock idb;
	mwAwareIdBlock id_block;

	if(GetAwareIdFromContact(hContact, &id_block)) {
		idb.user = id_block.user;
		idb.community = id_block.community;

		mwConversation *conv = mwServiceIm_getConversation(service_im, &idb);
		if(conv) {
			if(mwConversation_isOpen(conv))
				mwConversation_send(conv, mwImSend_TYPING, (gconstpointer)GUINT_TO_POINTER(typing ? 1 : 0));
		}

		free(id_block.user);
	}
}
Example #6
0
int CSametimeProto::ContactDeleted(MCONTACT hContact)
{
	mwAwareIdBlock id_block;

	if (db_get_b(hContact, m_szModuleName, "ChatRoom", 0))
		return 0;

	debugLog(_T("CSametimeProto::ContactDeleted()"));

	if (GetAwareIdFromContact(hContact, &id_block)) {
		GList* gl = g_list_prepend(NULL, &id_block);
		mwAwareList_removeAware(aware_list, gl);
		g_list_free(gl);
		free(id_block.user);
	}

	return 0;
}
Example #7
0
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;
}
Example #8
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);
		}
	}
}
Example #9
0
HANDLE CSametimeProto::SendFilesToUser(MCONTACT hContact, TCHAR** files, const TCHAR* ptszDesc)
{
	debugLog(_T("CSametimeProto::SendFilesToUser() start"));

	mwAwareIdBlock id_block;
	if (GetAwareIdFromContact(hContact, &id_block)) {
		mwIdBlock idb;
		idb.user = id_block.user;
		idb.community = id_block.community;

		FileTransferClientData *ftcd, *prev_ftcd = 0, *first_ftcd = 0;
		mwFileTransfer *ft, *first_ft = 0;

		for (int i = 0; files[i]; i++) {
			HANDLE hFile = CreateFile(files[i], GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
			if (hFile != INVALID_HANDLE_VALUE) {
				DWORD filesize = GetFileSize(hFile, 0);

				TCHAR *fn = _tcsrchr(files[i], '\\');
				if (fn)
					fn++;
				else
					fn = files[i];

				ft = mwFileTransfer_new(service_files, &idb, T2Utf(ptszDesc), T2Utf(fn), filesize);

				ftcd = new FileTransferClientData;
				memset(ftcd, 0, sizeof(FileTransferClientData));

				ftcd->ft = ft;
				ftcd->hContact = hContact;

				ftcd->next = 0;
				if (prev_ftcd) {
					prev_ftcd->next = ftcd; // link into list

					// each node contains a pointer to the first - it will contain infor linke the count etc
					ftcd->first = prev_ftcd->first;
				}
				else ftcd->first = ftcd;

				if (!first_ft) first_ft = ft;

				ftcd->sending = true;
				ftcd->hFile = hFile;
				ftcd->hFt = (HANDLE)first_ft;

				ftcd->save_path = 0;
				ftcd->buffer = new char[FILE_BUFF_SIZE];

				ftcd->ft_number = ftcd->first->ft_count;
				ftcd->first->ft_count++;
				ftcd->sizeToHere = ftcd->first->totalSize;
				ftcd->first->totalSize += filesize;

				mwFileTransfer_setClientData(ft, (gpointer)ftcd, 0);

				prev_ftcd = ftcd;
			}
		}

		free(id_block.user);

		if (first_ft) {
			mwFileTransfer_offer(first_ft);
			return (HANDLE)first_ft;
		}
	}

	return 0;
}