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

📄 novell.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
			break;		case NMEVT_USER_NOT_TYPING:			_evt_user_not_typing(user, event);			break;		case NMEVT_SERVER_DISCONNECT:			/* Nothing to do? */			break;		case NMEVT_INVALID_RECIPIENT:			break;		case NMEVT_UNDELIVERABLE_STATUS:			_evt_undeliverable_status(user, event);			break;		case NMEVT_CONFERENCE_INVITE_NOTIFY:			/* Someone else has been invited to join a			 * conference that we are currently a part of			 */			_evt_conference_invite_notify(user, event);			break;		case NMEVT_CONFERENCE_INVITE:			/* We have been invited to join a conference */			_evt_conference_invite(user, event);			break;		case NMEVT_CONFERENCE_JOINED:			/* Some one has joined a conference that we			 * are a part of			 */			_evt_conference_joined(user, event);			break;		case NMEVT_CONFERENCE_LEFT:			/* Someone else has left a conference that we			 * are currently a part of			 */			_evt_conference_left(user, event);			break;		default:			purple_debug(PURPLE_DEBUG_INFO, "novell",					   "_event_callback(): unhandled event, %d\n",					   nm_event_get_type(event));			break;	}}/******************************************************************************* * Prpl Ops ******************************************************************************/static voidnovell_login(PurpleAccount * account){	PurpleConnection *gc;	NMUser *user = NULL;	const char *server;	const char *name;	int port;	if (account == NULL)		return;	gc = purple_account_get_connection(account);	if (gc == NULL)		return;	server = purple_account_get_string(account, "server", NULL);	if (server == NULL || *server == '\0') {		/* TODO: Would be nice to prompt if not set!		 *  purple_request_fields(gc, _("Server Address"),...);		 */		/* ...but for now just error out with a nice message. */		purple_connection_error(gc, _("Unable to connect to server."									" Please enter the address of the server"									" you wish to connect to."));		return;	}	port = purple_account_get_int(account, "port", DEFAULT_PORT);	name = purple_account_get_username(account);	user = nm_initialize_user(name, server, port, account, _event_callback);	if (user && user->conn) {		/* save user */		gc->proto_data = user;		/* connect to the server */		purple_connection_update_progress(gc, _("Connecting"),										1, NOVELL_CONNECT_STEPS);		user->conn->use_ssl = TRUE;		user->conn->ssl_conn = g_new0(NMSSLConn, 1);		user->conn->ssl_conn->read = (nm_ssl_read_cb) purple_ssl_read;		user->conn->ssl_conn->write = (nm_ssl_write_cb) purple_ssl_write;		user->conn->ssl_conn->data = purple_ssl_connect(user->client_data,													  user->conn->addr, user->conn->port,													  novell_ssl_connected_cb, novell_ssl_connect_error, gc);		if (user->conn->ssl_conn->data == NULL) {			purple_connection_error(gc, _("Error."										" SSL support is not installed."));		}	}}static voidnovell_close(PurpleConnection * gc){	NMUser *user;	NMConn *conn;	if (gc == NULL)		return;	user = gc->proto_data;	if (user) {		conn = user->conn;		if (conn && conn->ssl_conn) {			purple_ssl_close(user->conn->ssl_conn->data);		}		nm_deinitialize_user(user);	}	gc->proto_data = NULL;}static intnovell_send_im(PurpleConnection * gc, const char *name,			   const char *message_body, PurpleMessageFlags flags){	NMUserRecord *user_record = NULL;	NMConference *conf = NULL;	NMMessage *message;	NMUser *user;	const char *dn = NULL;	char *plain;	gboolean done = TRUE, created_conf = FALSE;	NMERR_T rc = NM_OK;	if (gc == NULL || name == NULL ||		message_body == NULL || *message_body == '\0')		return 0;	user = gc->proto_data;	if (user == NULL)		return 0;	/* Create a new message */	plain = purple_unescape_html(message_body);	message = nm_create_message(plain);	g_free(plain);	/* Need to get the DN for the buddy so we can look up the convo */	dn = nm_lookup_dn(user, name);	/* Do we already know about the sender? */	user_record = nm_find_user_record(user, dn);	if (user_record) {		/* Do we already have an instantiated conference? */		conf = nm_find_conversation(user, dn);		if (conf == NULL) {			/* If not, create a blank conference */			conf = nm_create_conference(NULL);			created_conf = TRUE;			nm_conference_add_participant(conf, user_record);		}		nm_message_set_conference(message, conf);		/* Make sure conference is instantiated */		if (!nm_conference_is_instantiated(conf)) {			/* It is not, so send the createconf. We will			 * have to finish sending the message when we			 * get the response with the new conference guid.			 */			rc = nm_send_create_conference(user, conf, _createconf_resp_send_msg, message);			_check_for_disconnect(user, rc);			done = FALSE;		}	} else {		/* If we don't have details for the user, then we don't have		 * a conference yet. So create one and send the getdetails		 * to the server. We will have to finish sending the message		 * when we get the response from the server.		 */		conf = nm_create_conference(NULL);		created_conf = TRUE;		nm_message_set_conference(message, conf);		rc = nm_send_get_details(user, name, _get_details_resp_send_msg, message);		_check_for_disconnect(user, rc);		done = FALSE;	}	if (done) {		/* Did we find everything we needed? */		rc = nm_send_message(user, message, _send_message_resp_cb);		_check_for_disconnect(user, rc);		nm_release_message(message);	}	if (created_conf && conf)		nm_release_conference(conf);	return 1;}static unsigned intnovell_send_typing(PurpleConnection * gc, const char *name, PurpleTypingState state){	NMConference *conf = NULL;	NMUser *user;	const char *dn = NULL;	NMERR_T rc = NM_OK;	if (gc == NULL || name == NULL)		return 0;	user = gc->proto_data;	if (user == NULL)		return 0;	/* Need to get the DN for the buddy so we can look up the convo */	dn = nm_lookup_dn(user, name);	if (dn) {		/* Now find the conference in our list */		conf = nm_find_conversation(user, dn);		if (conf) {			rc = nm_send_typing(user, conf,								((state == PURPLE_TYPING) ? TRUE : FALSE), NULL);			_check_for_disconnect(user, rc);		}	}	return 0;}static voidnovell_convo_closed(PurpleConnection * gc, const char *who){	NMUser *user;	NMConference *conf;	const char *dn;	NMERR_T rc = NM_OK;	if (gc == NULL || who == NULL)		return;	user = gc->proto_data;	if (user && (dn = nm_lookup_dn(user, who))) {		conf = nm_find_conversation(user, dn);		if (conf) {			rc = nm_send_leave_conference(user, conf, NULL, NULL);			_check_for_disconnect(user, rc);		}	}}static voidnovell_chat_leave(PurpleConnection * gc, int id){	NMConference *conference;	NMUser *user;	PurpleConversation *chat;	GSList *cnode;	NMERR_T rc = NM_OK;	if (gc == NULL)		return;	user = gc->proto_data;	if (user == NULL)		return;	for (cnode = user->conferences; cnode != NULL; cnode = cnode->next) {		conference = cnode->data;		if (conference && (chat = nm_conference_get_data(conference))) {			if (purple_conv_chat_get_id(PURPLE_CONV_CHAT(chat)) == id) {				rc = nm_send_leave_conference(user, conference, NULL, NULL);				_check_for_disconnect(user, rc);				break;			}		}	}	serv_got_chat_left(gc, id);}static voidnovell_chat_invite(PurpleConnection *gc, int id,				   const char *message, const char *who){	NMConference *conference;	NMUser *user;	PurpleConversation *chat;	GSList *cnode;	NMERR_T rc = NM_OK;	NMUserRecord *user_record = NULL;	if (gc == NULL)		return;	user = gc->proto_data;	if (user == NULL)		return;	user_record = nm_find_user_record(user, who);	if (user_record == NULL) {		rc = nm_send_get_details(user, who, _get_details_resp_send_invite, GINT_TO_POINTER(id));		_check_for_disconnect(user, rc);		return;	}	for (cnode = user->conferences; cnode != NULL; cnode = cnode->next) {		conference = cnode->data;		if (conference && (chat = nm_conference_get_data(conference))) {			if (purple_conv_chat_get_id(PURPLE_CONV_CHAT(chat)) == id) {				rc = nm_send_conference_invite(user, conference, user_record,											   message, _sendinvite_resp_cb, NULL);				_check_for_disconnect(user, rc);				break;			}		}	}}static intnovell_chat_send(PurpleConnection * gc, int id, const char *text, PurpleMessageFlags flags){	NMConference *conference;	PurpleConversation *chat;	GSList *cnode;	NMMessage *message;	NMUser *user;	NMERR_T rc = NM_OK;	const char *name;	char *str, *plain;	if (gc == NULL || text == NULL)		return -1;	user = gc->proto_data;	if (user == NULL)		return -1;	plain = purple_unescape_html(text);	message = nm_create_message(plain);	g_free(plain);	for (cnode = user->conferences; cnode != NULL; cnode = cnode->next) {		conference = cnode->data;		if (conference && (chat = nm_conference_get_data(conference))) {			if (purple_conv_chat_get_id(PURPLE_CONV_CHAT(chat)) == id) {				nm_message_set_conference(message, conference);				/* check to see if the conference is instatiated yet */				if (!nm_conference_is_instantiated(conference)) {					nm_message_add_ref(message);					nm_send_create_conference(user, conference, _createconf_resp_send_msg, message);				} else {					rc = nm_send_message(user, message, _send_message_resp_cb);				}				nm_release_message(message);				if (!_check_for_disconnect(user, rc)) {					/* Use the account alias if it is set */					name = purple_account_get_alias(user->client_data);					if (name == NULL || *name == '\0') {						/* If there is no account alias, try full name */						name = nm_user_record_get_full_name(user->user_record);						if (name == NULL || *name == '\0') {							/* Fall back to the username that we are signed in with */							name = purple_account_get_username(user->client_data);						}					}					serv_got_chat_in(gc, id, name, 0, text, time(NULL));					return 0;				} else					return -1;			}		}	}	/* The conference was not found, must be closed */	chat = purple_find_chat(gc, id);	if (chat) {		str = g_strdup_printf(_("This conference has been closed."								" No more messages can be sent."));		purple_conversation_write(chat, NULL, str, PURPLE_MESSAGE_SYSTEM, time(NULL));		g_free(str);	}	if (message)		nm_release_message(message);	return -1;}static voidnovell_add_buddy(PurpleConnection * gc, PurpleBuddy *buddy, PurpleGroup * group){	NMFolder *folder = NULL;	NMContact *contact;	NMUser *user;	NMERR_T rc = NM_OK;	const char *alias, *gname;	if (gc == NULL || buddy == NULL || group == NULL)		return;	user = (NMUser *) gc->proto_data;	if (user == NULL)		return;	/* If we haven't synched the contact list yet, ignore	 * the add_buddy calls. Server side list is the master.	 */	if (!user->clist_synched)		return;	contact = nm_create_contact();	nm_contact_set_dn(contact, buddy->name);	/* Remove the PurpleBuddy (we will add it back after adding it	 * to the server side list). Save the alias if there is one.	 */	alias = purple_buddy_get_alias(buddy);	if (alias && strcmp(alias, buddy->name))		nm_contact_set_display_name(contact, alias);	purple_blist_remove_buddy(buddy);	buddy = NULL;	if (strcmp(group->name, NM_ROOT_FOLDER_NAME) == 0) {		gname = "";	} else {		gname = group->name;	}	folder = nm_find_folder(user, gname);	if (folder) {		/* We have everything that we need, so send the createcontact */		rc = nm_send_create_contact(user, folder, contact,									_create_contact_resp_cb, contact);	} else {		/* Need to create the folder before we can add the contact */		rc = nm_send_create_folder(user, gname,								   _create_folder_resp_add_contact, contact);	}	_check_for_disconnect(user, rc);}static voidnovell_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group){	NMContact *contact;	NMFolder *folder;	NMUser *user;	const char *dn, *gname;	NMERR_T rc = NM_OK;	if (gc == NULL || buddy == NULL || group == NULL)		return;	user = (NMUser *) gc->proto_data;	if (user && (dn = nm_lookup_dn(user, buddy->name))) {		if (strcmp(group->name, NM_ROOT_FOLDER_NAME) == 0) {			gname = "";		} else {			gname = group->name;		}		folder = nm_find_folder(user, gname);		if (folder) {			contact = nm_folder_find_contact(folder, dn);			if (contact) {				/* Remove the buddy from the contact */				nm_contact_set_data(contact, NULL);				/* Tell the server to remove the contact */				rc = nm_send_remove_contact(user, folder, contact,											_remove_contact_resp_cb, NULL);				_check_for_disconnect(user, rc);			}		}	}}static voidnovell_remove_group(PurpleConnection * gc, PurpleGroup *group){	NMUser *user;	NMERR_T rc = NM_OK;	if (gc == NULL || group == NULL)		return;

⌨️ 快捷键说明

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