Changeset - 9d50d5870ede
[Not reviewed]
Merge
0 1 0
Jan Kaluza - 12 years ago 2013-01-29 09:43:34
hanzz.k@gmail.com
Merge pull request #23 from vitalyster/vcard_fields

libpurple backend: handle Display name vcard field
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/main.cpp
Show inline comments
 
@@ -912,385 +912,385 @@ static void conv_write_im(PurpleConversation *conv, const char *who, const char
 

	
 

	
 
	// Escape HTML characters.
 
	char *newline = purple_strdup_withhtml_wrapped(msg);
 
	char *strip, *xhtml;
 
	purple_markup_html_to_xhtml_wrapped(newline, &xhtml, &strip);
 
// 	xhtml_linkified = spectrum_markup_linkify(xhtml);
 
	std::string message_(strip);
 

	
 
	std::string xhtml_(xhtml);
 
	g_free(newline);
 
	g_free(xhtml);
 
// 	g_free(xhtml_linkified);
 
	g_free(strip);
 

	
 
	// AIM and XMPP adds <body>...</body> here...
 
	if (xhtml_.find("<body>") == 0) {
 
		xhtml_ = xhtml_.substr(6);
 
		if (xhtml_.find("</body>") != std::string::npos) {
 
			xhtml_ = xhtml_.substr(0, xhtml_.find("</body>"));
 
		}
 
	}
 

	
 
	if (xhtml_ == message_) {
 
		xhtml_ = "";
 
	}
 

	
 
	std::string timestamp;
 
	if (mtime && (unsigned long) time(NULL)-10 > (unsigned long) mtime/* && (unsigned long) time(NULL) - 31536000 < (unsigned long) mtime*/) {
 
		char buf[80];
 
		strftime(buf, sizeof(buf), "%Y%m%dT%H%M%S", gmtime(&mtime));
 
		timestamp = buf;
 
	}
 

	
 
// 	LOG4CXX_INFO(logger, "Received message body='" << message_ << "' xhtml='" << xhtml_ << "'");
 

	
 
	if (purple_conversation_get_type_wrapped(conv) == PURPLE_CONV_TYPE_IM) {
 
		std::string w = purple_normalize_wrapped(account, who);
 
		size_t pos = w.find("/");
 
		if (pos != std::string::npos)
 
			w.erase((int) pos, w.length() - (int) pos);
 
		np->handleMessage(np->m_accounts[account], w, message_, "", xhtml_, timestamp);
 
	}
 
	else {
 
		LOG4CXX_INFO(logger, "Received message body='" << message_ << "' name='" << purple_conversation_get_name_wrapped(conv) << "' " << who);
 
		np->handleMessage(np->m_accounts[account], purple_conversation_get_name_wrapped(conv), message_, who, xhtml_, timestamp);
 
	}
 
}
 

	
 
static void conv_chat_add_users(PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals) {
 
	PurpleAccount *account = purple_conversation_get_account_wrapped(conv);
 

	
 
	GList *l = cbuddies;
 
	while (l != NULL) {
 
		PurpleConvChatBuddy *cb = (PurpleConvChatBuddy *)l->data;
 
		std::string name(cb->name);
 
		int flags = GPOINTER_TO_INT(cb->flags);
 
		if (flags & PURPLE_CBFLAGS_OP || flags & PURPLE_CBFLAGS_HALFOP) {
 
// 			item->addAttribute("affiliation", "admin");
 
// 			item->addAttribute("role", "moderator");
 
			flags = 1;
 
		}
 
		else if (flags & PURPLE_CBFLAGS_FOUNDER) {
 
// 			item->addAttribute("affiliation", "owner");
 
// 			item->addAttribute("role", "moderator");
 
			flags = 1;
 
		}
 
		else {
 
			flags = 0;
 
// 			item->addAttribute("affiliation", "member");
 
// 			item->addAttribute("role", "participant");
 
		}
 

	
 
		np->handleParticipantChanged(np->m_accounts[account], name, purple_conversation_get_name_wrapped(conv), (int) flags, pbnetwork::STATUS_ONLINE);
 

	
 
		l = l->next;
 
	}
 
}
 

	
 
static void conv_chat_remove_users(PurpleConversation *conv, GList *users) {
 
	PurpleAccount *account = purple_conversation_get_account_wrapped(conv);
 

	
 
	GList *l = users;
 
	while (l != NULL) {
 
		std::string name((char *) l->data);
 
		np->handleParticipantChanged(np->m_accounts[account], name, purple_conversation_get_name_wrapped(conv), 0, pbnetwork::STATUS_NONE);
 

	
 
		l = l->next;
 
	}
 
}
 

	
 
static PurpleConversationUiOps conversation_ui_ops =
 
{
 
	NULL,
 
	NULL,
 
	conv_write_im,//conv_write_chat,                              /* write_chat           */
 
	conv_write_im,             /* write_im             */
 
	NULL,//conv_write_conv,           /* write_conv           */
 
	conv_chat_add_users,       /* chat_add_users       */
 
	NULL,//conv_chat_rename_user,     /* chat_rename_user     */
 
	conv_chat_remove_users,    /* chat_remove_users    */
 
	NULL,//pidgin_conv_chat_update_user,     /* chat_update_user     */
 
	NULL,//pidgin_conv_present_conversation, /* present              */
 
	NULL,//pidgin_conv_has_focus,            /* has_focus            */
 
	NULL,//pidgin_conv_custom_smiley_add,    /* custom_smiley_add    */
 
	NULL,//pidgin_conv_custom_smiley_write,  /* custom_smiley_write  */
 
	NULL,//pidgin_conv_custom_smiley_close,  /* custom_smiley_close  */
 
	NULL,//pidgin_conv_send_confirm,         /* send_confirm         */
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL
 
};
 

	
 
struct Dis {
 
	std::string name;
 
	std::string protocol;
 
};
 

	
 
static gboolean disconnectMe(void *data) {
 
	Dis *d = (Dis *) data;
 
	PurpleAccount *account = purple_accounts_find_wrapped(d->name.c_str(), d->protocol.c_str());
 
	delete d;
 

	
 
	if (account) {
 
		np->handleLogoutRequest(np->m_accounts[account], purple_account_get_username_wrapped(account));
 
	}
 
	return FALSE;
 
}
 

	
 
static gboolean pingTimeout(void *data) {
 
	np->checkPing();
 
	return TRUE;
 
}
 

	
 
static void connection_report_disconnect(PurpleConnection *gc, PurpleConnectionError reason, const char *text){
 
	PurpleAccount *account = purple_connection_get_account_wrapped(gc);
 
	np->handleDisconnected(np->m_accounts[account], (int) reason, text ? text : "");
 
// 	Dis *d = new Dis;
 
// 	d->name = purple_account_get_username_wrapped(account);
 
// 	d->protocol = purple_account_get_protocol_id_wrapped(account);
 
// 	purple_timeout_add_seconds_wrapped(10, disconnectMe, d);
 
}
 

	
 
static PurpleConnectionUiOps conn_ui_ops =
 
{
 
	NULL,
 
	NULL,
 
	NULL,//connection_disconnected,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL,
 
	connection_report_disconnect,
 
	NULL,
 
	NULL,
 
	NULL
 
};
 

	
 
static void *notify_user_info(PurpleConnection *gc, const char *who, PurpleNotifyUserInfo *user_info) {
 
	PurpleAccount *account = purple_connection_get_account_wrapped(gc);
 
	std::string name(purple_normalize_wrapped(account, who));
 
	std::transform(name.begin(), name.end(), name.begin(), ::tolower);
 

	
 
	size_t pos = name.find("/");
 
	if (pos != std::string::npos)
 
		name.erase((int) pos, name.length() - (int) pos);
 

	
 
	
 
	GList *vcardEntries = purple_notify_user_info_get_entries_wrapped(user_info);
 
	PurpleNotifyUserInfoEntry *vcardEntry;
 
	std::string firstName;
 
	std::string lastName;
 
	std::string fullName;
 
	std::string nickname;
 
	std::string header;
 
	std::string label;
 
	std::string photo;
 

	
 
	while (vcardEntries) {
 
		vcardEntry = (PurpleNotifyUserInfoEntry *)(vcardEntries->data);
 
		if (purple_notify_user_info_entry_get_label_wrapped(vcardEntry) && purple_notify_user_info_entry_get_value_wrapped(vcardEntry)){
 
			label = purple_notify_user_info_entry_get_label_wrapped(vcardEntry);
 
			if (label == "Given Name" || label == "First Name") {
 
				firstName = purple_notify_user_info_entry_get_value_wrapped(vcardEntry);
 
			}
 
			else if (label == "Family Name" || label == "Last Name") {
 
				lastName = purple_notify_user_info_entry_get_value_wrapped(vcardEntry);
 
			}
 
			else if (label=="Nickname" || label == "Nick") {
 
				nickname = purple_notify_user_info_entry_get_value_wrapped(vcardEntry);
 
			}
 
			else if (label=="Full Name") {
 
			else if (label=="Full Name" || label == "Display name") {
 
				fullName = purple_notify_user_info_entry_get_value_wrapped(vcardEntry);
 
			}
 
			else {
 
				LOG4CXX_WARN(logger, "Unhandled VCard Label '" << purple_notify_user_info_entry_get_label_wrapped(vcardEntry) << "' " << purple_notify_user_info_entry_get_value_wrapped(vcardEntry));
 
			}
 
		}
 
		vcardEntries = vcardEntries->next;
 
	}
 

	
 
	if ((!firstName.empty() || !lastName.empty()) && fullName.empty())
 
		fullName = firstName + " " + lastName;
 

	
 
	if (nickname.empty() && !fullName.empty()) {
 
		nickname = fullName;
 
	}
 

	
 
	bool ownInfo = name == purple_account_get_username_wrapped(account);
 

	
 
	if (ownInfo) {
 
		const gchar *displayname = purple_connection_get_display_name_wrapped(gc);
 
#if PURPLE_MAJOR_VERSION >= 2 && PURPLE_MINOR_VERSION >= 7
 
		if (!displayname) {
 
			displayname = purple_account_get_name_for_display_wrapped(account);
 
		}
 
#endif
 

	
 
		if (displayname && nickname.empty()) {
 
			nickname = displayname;
 
		}
 

	
 
		// avatar
 
		PurpleStoredImage *avatar = purple_buddy_icons_find_account_icon_wrapped(account);
 
		if (avatar) {
 
			const gchar * data = (const gchar *) purple_imgstore_get_data_wrapped(avatar);
 
			size_t len = purple_imgstore_get_size_wrapped(avatar);
 
			if (len < 300000 && data) {
 
				photo = std::string(data, len);
 
			}
 
			purple_imgstore_unref_wrapped(avatar);
 
		}
 
	}
 

	
 
	PurpleBuddy *buddy = purple_find_buddy_wrapped(purple_connection_get_account_wrapped(gc), who);
 
	if (buddy && photo.size() == 0) {
 
		gsize len;
 
		PurpleBuddyIcon *icon = NULL;
 
		icon = purple_buddy_icons_find_wrapped(purple_connection_get_account_wrapped(gc), name.c_str());
 
		if (icon) {
 
			if (true) {
 
				gchar *data;
 
				gchar *path = purple_buddy_icon_get_full_path_wrapped(icon);
 
				if (path) {
 
					if (g_file_get_contents(path, &data, &len, NULL)) {
 
						photo = std::string(data, len);
 
						g_free(data);
 
					}
 
					g_free(path);
 
				}
 
			}
 
			else {
 
				const gchar * data = (gchar*)purple_buddy_icon_get_data_wrapped(icon, &len);
 
				if (len < 300000 && data) {
 
					photo = std::string(data, len);
 
				}
 
			}
 
			purple_buddy_icon_unref_wrapped(icon);
 
		}
 
	}
 

	
 
	np->handleVCard(np->m_accounts[account], np->m_vcards[np->m_accounts[account] + name], name, fullName, nickname, photo);
 
	np->m_vcards.erase(np->m_accounts[account] + name);
 

	
 
	return NULL;
 
}
 

	
 
static PurpleNotifyUiOps notifyUiOps =
 
{
 
		NULL,
 
		NULL,
 
		NULL,
 
		NULL,
 
		NULL,
 
		NULL,
 
		notify_user_info,
 
		NULL,
 
		NULL,
 
		NULL,
 
		NULL,
 
		NULL,
 
		NULL
 
};
 

	
 
static PurpleRequestUiOps requestUiOps =
 
{
 
	requestInput,
 
	NULL,
 
	requestAction,
 
	NULL,
 
	NULL,
 
	NULL, //requestClose,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL
 
};
 

	
 
static void * accountRequestAuth(PurpleAccount *account, const char *remote_user, const char *id, const char *alias, const char *message, gboolean on_list, PurpleAccountRequestAuthorizationCb authorize_cb, PurpleAccountRequestAuthorizationCb deny_cb, void *user_data) {
 
	authRequest *req = new authRequest;
 
	req->authorize_cb = authorize_cb;
 
	req->deny_cb = deny_cb;
 
	req->user_data = user_data;
 
	req->account = account;
 
	req->who = remote_user;
 
	req->mainJID = np->m_accounts[account];
 
	np->m_authRequests[req->mainJID + req->who] = req;
 

	
 
	np->handleAuthorization(req->mainJID, req->who);
 

	
 
	return req;
 
}
 

	
 
static void accountRequestClose(void *data){
 
	authRequest *req = (authRequest *) data;
 
	np->m_authRequests.erase(req->mainJID + req->who);
 
}
 

	
 

	
 
static PurpleAccountUiOps accountUiOps =
 
{
 
	NULL,
 
	NULL,
 
	NULL,
 
	accountRequestAuth,
 
	accountRequestClose,
 
	NULL,
 
	NULL,
 
	NULL,
 
	NULL
 
};
 

	
 
static void XferCreated(PurpleXfer *xfer) {
 
	if (!xfer) {
 
		return;
 
	}
 

	
 
// 	PurpleAccount *account = purple_xfer_get_account_wrapped(xfer);
 
// 	np->handleFTStart(np->m_accounts[account], xfer->who, xfer, "", xhtml_);
 
}
 

	
 
static void XferDestroyed(PurpleXfer *xfer) {
 
	std::remove(np->m_waitingXfers.begin(), np->m_waitingXfers.end(), xfer);
 
	FTData *ftdata = (FTData *) xfer->ui_data;
 
	if (ftdata && ftdata->timer) {
 
		purple_timeout_remove_wrapped(ftdata->timer);
 
	}
 
	if (ftdata) {
 
		np->m_xfers.erase(ftdata->id);
 
	}
 
}
 

	
 
static void xferCanceled(PurpleXfer *xfer) {
 
	PurpleAccount *account = purple_xfer_get_account_wrapped(xfer);
 
	std::string filename(xfer ? purple_xfer_get_filename_wrapped(xfer) : "");
 
	std::string w = xfer->who;
 
	size_t pos = w.find("/");
 
	if (pos != std::string::npos)
 
		w.erase((int) pos, w.length() - (int) pos);
 

	
 
	FTData *ftdata = (FTData *) xfer->ui_data;
 

	
 
	np->handleFTFinish(np->m_accounts[account], w, filename, purple_xfer_get_size_wrapped(xfer), ftdata ? ftdata->id : 0);
 
	std::remove(np->m_waitingXfers.begin(), np->m_waitingXfers.end(), xfer);
 
	if (ftdata && ftdata->timer) {
 
		purple_timeout_remove_wrapped(ftdata->timer);
 
	}
 
	purple_xfer_unref_wrapped(xfer);
 
}
 

	
 
static void fileSendStart(PurpleXfer *xfer) {
 
// 	FiletransferRepeater *repeater = (FiletransferRepeater *) xfer->ui_data;
 
// 	repeater->fileSendStart();
 
}
 

	
 
static void fileRecvStart(PurpleXfer *xfer) {
 
// 	FiletransferRepeater *repeater = (FiletransferRepeater *) xfer->ui_data;
 
// 	repeater->fileRecvStart();
 
	FTData *ftData = (FTData *) xfer->ui_data;
 
	if (ftData->timer == 0) {
 
		ftData->timer = purple_timeout_add_wrapped(1, ft_ui_ready, xfer);
 
	}
 
}
0 comments (0 inline, 0 general)