⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 novell.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * novell.c * * Copyright (c) 2004 Novell, Inc. All Rights Reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA	02111-1307	USA * */#include "internal.h"#include "accountopt.h"#include "debug.h"#include "prpl.h"#include "server.h"#include "nmuser.h"#include "notify.h"#include "util.h"#include "sslconn.h"#include "request.h"#include "network.h"#include "privacy.h"#include "status.h"#include "version.h"#define DEFAULT_PORT			8300#define NOVELL_CONNECT_STEPS	4#define NM_ROOT_FOLDER_NAME "GroupWise Messenger"#define NOVELL_STATUS_TYPE_AVAILABLE "available"#define NOVELL_STATUS_TYPE_AWAY "away"#define NOVELL_STATUS_TYPE_BUSY "busy"#define NOVELL_STATUS_TYPE_OFFLINE "offline"#define NOVELL_STATUS_TYPE_IDLE "idle"#define NOVELL_STATUS_TYPE_APPEAR_OFFLINE "appearoffline"static PurplePlugin *my_protocol = NULL;static gboolean_is_disconnect_error(NMERR_T err);static gboolean_check_for_disconnect(NMUser * user, NMERR_T err);static void_send_message(NMUser * user, NMMessage * message);static void_update_buddy_status(NMUser *user, PurpleBuddy * buddy, int status, int gmt);static void_remove_purple_buddies(NMUser * user);static void_add_contacts_to_purple_blist(NMUser * user, NMFolder * folder);static void_add_purple_buddies(NMUser * user);static void_sync_contact_list(NMUser *user);static void_sync_privacy_lists(NMUser *user);static void_show_info(PurpleConnection * gc, NMUserRecord * user_record);const char *_get_conference_name(int id);/******************************************************************************* * Response callbacks *******************************************************************************//* Handle login response */static void_login_resp_cb(NMUser * user, NMERR_T ret_code,			   gpointer resp_data, gpointer user_data){	PurpleConnection *gc;	const char *alias;	NMERR_T rc;	if (user == NULL)		return;	gc = purple_account_get_connection(user->client_data);	if (gc == NULL)		return;	if (ret_code == NM_OK) {		/* Set alias for user if not set (use Full Name) */		alias = purple_account_get_alias(user->client_data);		if (alias == NULL || *alias == '\0') {			alias = nm_user_record_get_full_name(user->user_record);			if (alias)				purple_account_set_alias(user->client_data, alias);		}		/* Tell Purple that we are connected */		purple_connection_set_state(gc, PURPLE_CONNECTED);		_sync_contact_list(user);		rc = nm_send_set_status(user, NM_STATUS_AVAILABLE, NULL, NULL, NULL,								NULL);		_check_for_disconnect(user, rc);	} else {		char *err = g_strdup_printf(_("Login failed (%s)."),					    nm_error_to_string (ret_code));		/* Don't attempt to auto-reconnect if our password		 * was invalid.		 */		if (ret_code == NMERR_AUTHENTICATION_FAILED ||			ret_code == NMERR_CREDENTIALS_MISSING ||			ret_code == NMERR_PASSWORD_INVALID) {			gc->wants_to_die = TRUE;		}		purple_connection_error(gc, err);		g_free(err);	}}/* Handle getstatus response*/static void_get_status_resp_cb(NMUser * user, NMERR_T ret_code,					gpointer resp_data, gpointer user_data){	PurpleBuddy *buddy;	GSList *buddies;	GSList *bnode;	NMUserRecord *user_record = (NMUserRecord *) resp_data;	int status;	if (user == NULL || user_record == NULL)		return;	if (ret_code == NM_OK) {		/* Find all Purple buddies and update their statuses */		const char *name = nm_user_record_get_display_id(user_record);		if (name) {			buddies = purple_find_buddies((PurpleAccount *) user->client_data, name);			for (bnode = buddies; bnode; bnode = bnode->next) {				buddy = (PurpleBuddy *) bnode->data;				if (buddy) {					status = nm_user_record_get_status(user_record);					_update_buddy_status(user, buddy, status, time(0));				}			}			g_slist_free(buddies);		}	} else {		purple_debug(PURPLE_DEBUG_INFO, "novell",				   "_get_status_resp_cb(): rc = 0x%X\n", ret_code);	}}/* Show an error if the rename failed */static void_rename_contact_resp_cb(NMUser * user, NMERR_T ret_code,						gpointer resp_data, gpointer user_data){	if (ret_code != NM_OK) {		purple_debug(PURPLE_DEBUG_INFO, "novell",				   "_rename_contact_resp_cb(): rc = 0x%X\n", ret_code);	}}/* Handle the getdetails response and send the message */static void_get_details_resp_send_msg(NMUser * user, NMERR_T ret_code,						   gpointer resp_data, gpointer user_data){	PurpleConversation *gconv;	PurpleConnection *gc;	NMUserRecord *user_record = NULL;	NMContact *cntct = NULL;	NMConference *conf;	NMMessage *msg = user_data;	const char *dn = NULL;	const char *name;	if (user == NULL || msg == NULL)		return;	if (ret_code == NM_OK) {		user_record = (NMUserRecord *) resp_data;		if (user_record) {			/* Set the title for the conversation */			/* XXX - Should this be PURPLE_CONV_TYPE_IM? */			gconv =	purple_find_conversation_with_account(PURPLE_CONV_TYPE_ANY,														nm_user_record_get_display_id(user_record),														(PurpleAccount *) user->client_data);			if (gconv) {				dn = nm_user_record_get_dn(user_record);				if (dn) {					cntct = nm_find_contact(user, dn);				}				if (cntct) {					purple_conversation_set_title(gconv,												nm_contact_get_display_name(cntct));				} else {					/* Not in the contact list, try to user full name */					name = (char *) nm_user_record_get_full_name(user_record);					if (name)						purple_conversation_set_title(gconv, name);				}			}			/* Add the user record to particpant list */			conf = nm_message_get_conference(msg);			if (conf) {				nm_conference_add_participant(conf, user_record);				_send_message(user, msg);			}		}	} else {		gc = purple_account_get_connection(user->client_data);		if (gc != NULL) {			char *err = g_strdup_printf(_("Unable to send message."										  " Could not get details for user (%s)."),						    nm_error_to_string (ret_code));			purple_notify_error(gc, NULL, err, NULL);			g_free(err);		}		if (msg)			nm_release_message(msg);	}}/* Set up the new PurpleBuddy based on the response from getdetails */static void_get_details_resp_setup_buddy(NMUser * user, NMERR_T ret_code,							  gpointer resp_data, gpointer user_data){	NMUserRecord *user_record;	NMContact *contact;	PurpleBuddy *buddy;	const char *alias;	NMERR_T rc = NM_OK;	if (user == NULL || resp_data == NULL || user_data == NULL)		return;	contact = user_data;	if (ret_code == NM_OK) {		user_record = resp_data;		buddy = nm_contact_get_data(contact);		nm_contact_set_user_record(contact, user_record);		/* Set the display id */		purple_blist_rename_buddy(buddy,								nm_user_record_get_display_id(user_record));		alias = purple_buddy_get_alias(buddy);		if (alias == NULL || *alias == '\0' || (strcmp(alias, buddy->name) == 0)) {			purple_blist_alias_buddy(buddy,								   nm_user_record_get_full_name(user_record));			/* Tell the server about the new display name */			rc = nm_send_rename_contact(user, contact,										nm_user_record_get_full_name(user_record),										NULL, NULL);			_check_for_disconnect(user, rc);		}		/* Get initial status for the buddy */		rc = nm_send_get_status(user, resp_data, _get_status_resp_cb, NULL);		_check_for_disconnect(user, rc);/*		nm_release_contact(contact);*/	}	if (contact)		nm_release_contact(contact);}/* Add the new contact into the PurpleBuddy list */static void_create_contact_resp_cb(NMUser * user, NMERR_T ret_code,						gpointer resp_data, gpointer user_data){	NMContact *tmp_contact = (NMContact *) user_data;	NMContact *new_contact = NULL;	NMFolder *folder = NULL;	PurpleGroup *group;	PurpleBuddy *buddy;	const char *folder_name = NULL;	NMERR_T rc = NM_OK;	if (user == NULL)		return;	if (ret_code == NM_OK) {		new_contact = (NMContact *) resp_data;		if (new_contact == NULL || tmp_contact == NULL)			return;		/* Get the userid and folder name for the new contact */		folder = nm_find_folder_by_id(user,									  nm_contact_get_parent_id(new_contact));		if (folder) {			folder_name = nm_folder_get_name(folder);		}		if (folder_name == NULL || *folder_name == '\0')			folder_name = NM_ROOT_FOLDER_NAME;		/* Re-add the buddy now that we got the okay from the server */		if (folder_name && (group = purple_find_group(folder_name))) {			const char *alias = nm_contact_get_display_name(tmp_contact);			const char *display_id = nm_contact_get_display_id(new_contact);			if (display_id == NULL)				display_id = nm_contact_get_dn(new_contact);			if (alias && strcmp(alias, display_id)) {				/* The user requested an alias, tell the server about it. */				rc = nm_send_rename_contact(user, new_contact, alias,											_rename_contact_resp_cb, NULL);				_check_for_disconnect(user, rc);			} else {				alias = "";			}			/* Add it to the purple buddy list if it is not there */			buddy = purple_find_buddy_in_group(user->client_data, display_id, group);			if (buddy == NULL) {				buddy = purple_buddy_new(user->client_data, display_id, alias);				purple_blist_add_buddy(buddy, NULL, group, NULL);			}			/* Save the new buddy as part of the contact object */			nm_contact_set_data(new_contact, (gpointer) buddy);			/* We need details for the user before we can setup the			 * new Purple buddy. We always call this because the			 * 'createcontact' response fields do not always contain			 * everything that we need.			 */			nm_contact_add_ref(new_contact);			rc = nm_send_get_details(user, nm_contact_get_dn(new_contact),									 _get_details_resp_setup_buddy, new_contact);			_check_for_disconnect(user, rc);		}	} else {		PurpleConnection *gc = purple_account_get_connection(user->client_data);		const char *name = nm_contact_get_dn(tmp_contact);		char *err;		err =			g_strdup_printf(_("Unable to add %s to your buddy list (%s)."),					name, nm_error_to_string (ret_code));		purple_notify_error(gc, NULL, err, NULL);		g_free(err);	}	if (tmp_contact)		nm_release_contact(tmp_contact);}/* Show an error if we failed to send the message */static void_send_message_resp_cb(NMUser * user, NMERR_T ret_code,					  gpointer resp_data, gpointer user_data){	PurpleConnection *gc;	char *err = NULL;	if (user == NULL)		return;	if (ret_code != NM_OK) {		gc = purple_account_get_connection(user->client_data);		/* TODO: Improve this! message to who or for what conference? */		err = g_strdup_printf(_("Unable to send message (%s)."),				      nm_error_to_string (ret_code));		purple_notify_error(gc, NULL, err, NULL);		g_free(err);	}}/* Show an error if the remove failed */static void_remove_contact_resp_cb(NMUser * user, NMERR_T ret_code,						gpointer resp_data, gpointer user_data){	if (ret_code != NM_OK) {		/* TODO: Display an error? */		purple_debug(PURPLE_DEBUG_INFO, "novell",				   "_remove_contact_resp_cb(): rc = 0x%x\n", ret_code);	}}/* Show an error if the remove failed */static void_remove_folder_resp_cb(NMUser * user, NMERR_T ret_code,					   gpointer resp_data, gpointer user_data){	if (ret_code != NM_OK) {		/* TODO: Display an error? */		purple_debug(PURPLE_DEBUG_INFO, "novell",				   "_remove_folder_resp_cb(): rc = 0x%x\n", ret_code);	}}/* Show an error if the move failed */static void_move_contact_resp_cb(NMUser * user, NMERR_T ret_code,					  gpointer resp_data, gpointer user_data){	if (ret_code != NM_OK) {		/* TODO: Display an error? */		purple_debug(PURPLE_DEBUG_INFO, "novell",				   "_move_contact_resp_cb(): rc = 0x%x\n", ret_code);	}}/* Show an error if the rename failed */static void_rename_folder_resp_cb(NMUser * user, NMERR_T ret_code,					   gpointer resp_data, gpointer user_data){	if (ret_code != NM_OK) {		/* TODO: Display an error? */		purple_debug(PURPLE_DEBUG_INFO, "novell",				   "_rename_folder_resp_cb(): rc = 0x%x\n", ret_code);	}}static void_sendinvite_resp_cb(NMUser *user, NMERR_T ret_code,					gpointer resp_data, gpointer user_data){	char *err;	PurpleConnection *gc;	if (user == NULL)		return;	if (ret_code != NM_OK) {		gc = purple_account_get_connection(user->client_data);		err = g_strdup_printf(_("Unable to invite user (%s)."), nm_error_to_string(ret_code));		purple_notify_error(gc, NULL, err, NULL);		g_free(err);		purple_debug(PURPLE_DEBUG_INFO, "novell",				   "_sendinvite_resp_cb(): rc = 0x%x\n", ret_code);	}}/* If the createconf was successful attempt to send the message, * otherwise display an error message to the user. */static void_createconf_resp_send_msg(NMUser * user, NMERR_T ret_code,						  gpointer resp_data, gpointer user_data){	NMConference *conf;	NMMessage *msg = user_data;	if (user == NULL || msg == NULL)		return;	if (ret_code == NM_OK) {		_send_message(user, msg);	} else {		if ((conf = nm_message_get_conference(msg))) {			PurpleConnection *gc = purple_account_get_connection(user->client_data);			const char *name = NULL;			char *err;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -