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

📄 novell.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	os_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);	GetVersionEx(&os_info);	GetSystemInfo(&sys_info);	if (os_info.dwPlatformId == VER_PLATFORM_WIN32_NT)  {		switch (os_info.dwMajorVersion) {			case 3:			case 4:				sysname = "Windows NT";				break;			case 5:				switch (os_info.dwMinorVersion) {					case 0:						sysname = "Windows 2000";						break;					case 1:						sysname = "Windows XP";						break;					case 2:						sysname = "Windows Server 2003";						break;					default:						sysname = "Windows";						break;				}				break;			default:				sysname = "Windows";				break;		}	}	else if (os_info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {		switch (os_info.dwMinorVersion) {			case 0:				sysname = "Windows 95";				break;			case 10:				sysname = "Windows 98";				break;			case 90:				sysname = "Windows ME";				break;			default:				sysname = "Windows";				break;		}	} else {		sysname = "Windows";	}	return g_strdup_printf("Purple/%s (%s; %ld.%ld)", VERSION, sysname,						   os_info.dwMajorVersion, os_info.dwMinorVersion);#endif}static gboolean_is_disconnect_error(NMERR_T err){	return (err == NMERR_TCP_WRITE ||			err == NMERR_TCP_READ || err == NMERR_PROTOCOL);}static gboolean_check_for_disconnect(NMUser * user, NMERR_T err){	PurpleConnection *gc = purple_account_get_connection(user->client_data);	if (_is_disconnect_error(err)) {		purple_connection_error(gc, _("Error communicating with server."									" Closing connection."));		return TRUE;	}	return FALSE;}/* Check to see if the conference is instantiated, if so send the message. * If not send the create conference -- the response handler for the createconf * will call this function again. */static void_send_message(NMUser * user, NMMessage * message){	NMConference *conf;	NMERR_T rc = NM_OK;	conf = nm_message_get_conference(message);	if (conf) {		/* We have a conference make sure that the		   server knows about it already. */		if (nm_conference_is_instantiated(conf)) {			/* We have everything that we need...finally! */			rc = nm_send_message(user, message, _send_message_resp_cb);			_check_for_disconnect(user, rc);			nm_release_message(message);		} else {			rc = nm_send_create_conference(user, conf, _createconf_resp_send_msg, message);			_check_for_disconnect(user, rc);		}	}}/* * Update the status of the given buddy in the Purple buddy list */static void_update_buddy_status(NMUser *user, PurpleBuddy * buddy, int novellstatus, int gmt){	PurpleAccount *account;	const char *status_id;	const char *text = NULL;	const char *dn;	int idle = 0;	gboolean loggedin = TRUE;	account = buddy->account;	switch (novellstatus) {		case NM_STATUS_AVAILABLE:			status_id = NOVELL_STATUS_TYPE_AVAILABLE;			break;		case NM_STATUS_AWAY:			status_id = NOVELL_STATUS_TYPE_AWAY;			break;		case NM_STATUS_BUSY:			status_id = NOVELL_STATUS_TYPE_BUSY;			break;		case NM_STATUS_OFFLINE:			status_id = NOVELL_STATUS_TYPE_OFFLINE;			loggedin = FALSE;			break;		case NM_STATUS_AWAY_IDLE:			status_id = NOVELL_STATUS_TYPE_AWAY;			idle = gmt;			break;		default:			status_id = NOVELL_STATUS_TYPE_OFFLINE;			loggedin = FALSE;			break;	}	/* Get status text for the user */	dn = nm_lookup_dn(user, buddy->name);	if (dn) {		NMUserRecord *user_record = nm_find_user_record(user, dn);		if (user_record) {			text = nm_user_record_get_status_text(user_record);		}	}	purple_prpl_got_user_status(account, buddy->name, status_id,							  "message", text, NULL);	purple_prpl_got_user_idle(account, buddy->name,							(novellstatus == NM_STATUS_AWAY_IDLE), idle);}/* Iterate through the cached Purple buddy list and remove buddies * that are not in the server side list. */static void_remove_purple_buddies(NMUser *user){	PurpleBlistNode *gnode;	PurpleBlistNode *cnode;	PurpleBlistNode *bnode;	PurpleGroup *group;	PurpleBuddy *buddy;	PurpleBuddyList *blist;	GSList *rem_list = NULL;	GSList *l;	NMFolder *folder = NULL;	const char *gname = NULL;	if ((blist = purple_get_blist())) {		for (gnode = blist->root; gnode; gnode = gnode->next) {			if (!PURPLE_BLIST_NODE_IS_GROUP(gnode))				continue;			group = (PurpleGroup *) gnode;			for (cnode = gnode->child; cnode; cnode = cnode->next) {				if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode))					continue;				for (bnode = cnode->child; bnode; bnode = bnode->next) {					if (!PURPLE_BLIST_NODE_IS_BUDDY(bnode))						continue;					buddy = (PurpleBuddy *) bnode;					if (buddy->account == user->client_data) {						gname = group->name;						if (strcmp(group->name, NM_ROOT_FOLDER_NAME) == 0)							gname = "";						folder = nm_find_folder(user, gname);						if (folder == NULL ||							!nm_folder_find_contact_by_display_id(folder, buddy->name)) {							rem_list = g_slist_append(rem_list, buddy);						}					}				}			}		}		if (rem_list) {			for (l = rem_list; l; l = l->next) {				purple_blist_remove_buddy(l->data);			}			g_slist_free(rem_list);		}	}}/* Add all of the contacts in the given folder to the Purple buddy list */static void_add_contacts_to_purple_blist(NMUser * user, NMFolder * folder){	NMUserRecord *user_record = NULL;	NMContact *contact = NULL;	PurpleBuddy *buddy = NULL;	PurpleGroup *group;	NMERR_T cnt = 0, i;	const char *text = NULL;	const char *name = NULL;	const char *fname = NULL;	int status = 0;	/* If this is the root folder give it a name. Purple does not have the concept of	 * a root folder.	 */	fname = nm_folder_get_name(folder);	if (fname == NULL || *fname == '\0') {		fname = NM_ROOT_FOLDER_NAME;	}	/* Does the Purple group exist already? */	group = purple_find_group(fname);	if (group == NULL) {		group = purple_group_new(fname);		purple_blist_add_group(group, NULL);	}	/* Get each contact for this folder */	cnt = nm_folder_get_contact_count(folder);	for (i = 0; i < cnt; i++) {		contact = nm_folder_get_contact(folder, i);		if (contact) {			name = nm_contact_get_display_id(contact);			if (name) {				buddy = purple_find_buddy_in_group(user->client_data, name, group);				if (buddy == NULL) {					/* Add it to the purple buddy list */					buddy = purple_buddy_new(user->client_data,										   name,										   nm_contact_get_display_name(contact));					purple_blist_add_buddy(buddy, NULL, group, NULL);				}				/* Set the initial status for the buddy */				user_record = nm_contact_get_user_record(contact);				if (user_record) {					status = nm_user_record_get_status(user_record);					text = nm_user_record_get_status_text(user_record);				}				_update_buddy_status(user, buddy, status, time(0));				/* Save the new buddy as part of the contact object */				nm_contact_set_data(contact, (gpointer) buddy);			}		} else {			/* NULL contact. This should not happen, but			 * let's break out of the loop.			 */			break;		}	}}/* Add all of the server side contacts to the Purple buddy list. */static void_add_purple_buddies(NMUser * user){	int cnt = 0, i;	NMFolder *root_folder = NULL;	NMFolder *folder = NULL;	root_folder = nm_get_root_folder(user);	if (root_folder) {		/* Add sub-folders and contacts to sub-folders...		 * iterate throught the sub-folders in reverse order		 * because Purple adds the folders to the front -- so we		 * want to add the first folder last		 */		cnt = nm_folder_get_subfolder_count(root_folder);		for (i = cnt-1; i >= 0; i--) {			folder = nm_folder_get_subfolder(root_folder, i);			if (folder) {				_add_contacts_to_purple_blist(user, folder);			}		}		/* Add contacts for the root folder */		_add_contacts_to_purple_blist(user, root_folder);	}}static void_sync_contact_list(NMUser *user){	/* Remove all buddies from the local list that are	 * not in the server side list and add all buddies	 * from the server side list that are not in	 * the local list	 */	_remove_purple_buddies(user);	_add_purple_buddies(user);	user->clist_synched = TRUE;}static void_sync_privacy_lists(NMUser *user){	GSList *node = NULL, *rem_list = NULL;	PurpleConnection *gc;	const char *name, *dn;	NMUserRecord *user_record;	if (user == NULL)		return;	gc = purple_account_get_connection(user->client_data);	if (gc == NULL)		return;	/* Set the Purple privacy setting */	if (user->default_deny) {		if (user->allow_list == NULL) {			gc->account->perm_deny = PURPLE_PRIVACY_DENY_ALL;		} else {			gc->account->perm_deny = PURPLE_PRIVACY_ALLOW_USERS;		}	} else {		if (user->deny_list == NULL) {			gc->account->perm_deny = PURPLE_PRIVACY_ALLOW_ALL;		} else {			gc->account->perm_deny = PURPLE_PRIVACY_DENY_USERS;		}	}	/* Add stuff */	for (node = user->allow_list; node; node = node->next) {		user_record = nm_find_user_record(user, (char *)node->data);		if (user_record)			name = nm_user_record_get_display_id(user_record);		else			name =(char *)node->data;		if (!g_slist_find_custom(gc->account->permit,								 name, (GCompareFunc)purple_utf8_strcasecmp)) {			purple_privacy_permit_add(gc->account, name , TRUE);		}	}	for (node = user->deny_list; node; node = node->next) {		user_record = nm_find_user_record(user, (char *)node->data);		if (user_record)			name = nm_user_record_get_display_id(user_record);		else			name =(char *)node->data;		if (!g_slist_find_custom(gc->account->deny,								 name, (GCompareFunc)purple_utf8_strcasecmp)) {			purple_privacy_deny_add(gc->account, name, TRUE);		}	}	/*  Remove stuff */	for (node = gc->account->permit; node; node = node->next) {		dn = nm_lookup_dn(user, (char *)node->data);		if (dn != NULL &&			!g_slist_find_custom(user->allow_list,								 dn, (GCompareFunc)purple_utf8_strcasecmp)) {			rem_list = g_slist_append(rem_list, node->data);		}	}	if (rem_list) {		for (node = rem_list; node; node = node->next) {			purple_privacy_permit_remove(gc->account, (char *)node->data, TRUE);		}		g_free(rem_list);		rem_list = NULL;	}	for (node = gc->account->deny; node; node = node->next) {		dn = nm_lookup_dn(user, (char *)node->data);		if (dn != NULL &&			!g_slist_find_custom(user->deny_list,								 dn, (GCompareFunc)purple_utf8_strcasecmp)) {			rem_list = g_slist_append(rem_list, node->data);		}	}	if (rem_list) {		for (node = rem_list; node; node = node->next) {			purple_privacy_deny_remove(gc->account, (char *)node->data, TRUE);		}		g_slist_free(rem_list);	}} /* Map known property tags to user-friendly strings */static const char *_map_property_tag(const char *tag){	if (tag == NULL) return NULL;	if (strcmp(tag, "telephoneNumber") == 0)		return _("Telephone Number");	else if (strcmp(tag, "L") == 0)		return _("Location");	else if (strcmp(tag, "OU") == 0)		return _("Department");	else if (strcmp(tag, "personalTitle") == 0)		return _("Personal Title");	else if (strcmp(tag, "Title") == 0)		return _("Title");	else if (strcmp(tag, "mailstop") == 0)		return _("Mailstop");	else if (strcmp(tag, "Internet EMail Address") == 0)		return _("E-Mail Address");	else		return tag;}/* Display a dialog box showing the properties for the given user record */static void_show_info(PurpleConnection * gc, NMUserRecord * user_record){	PurpleNotifyUserInfo *user_info =	purple_notify_user_info_new();	int count, i;	NMProperty *property;	const char *tag, *value;	tag = _("User ID");	value = nm_user_record_get_userid(user_record);	if (value) {		purple_notify_user_info_add_pair(user_info, tag, value);	}/*	tag = _("DN");	value = nm_user_record_get_dn(user_record);	if (value) {		purple_notify_user_info_add_pair(user_info, tag, value);	}*/	tag = _("Full name");	value = nm_user_record_get_full_name(user_record);	if (value) {		purple_notify_user_info_add_pair(user_info, tag, value);	}	count = nm_user_record_get_property_count(user_record);	for (i = 0; i < count; i++) {		property = nm_user_record_get_property(user_record, i);		if (property) {			tag = _map_property_tag(nm_property_get_tag(property));			value = nm_property_get_value(property);			if (tag && value) {				purple_notify_user_info_add_pair(user_info, tag, value);			}			nm_release_property(property);		}	}	purple_notify_userinfo(gc, nm_user_record_get_userid(user_record), 						 user_info, NULL, NULL);	purple_notify_user_info_destroy(user_info);}/* Send a join conference, the first item in the parms list is the * NMUser object and the second item is the conference to join. * This callback is passed to purple_request_action when we ask the * user if they want to join the conference. */static void_join_conference_cb(GSList * parms){	NMUser *user;	NMConference *conference;	NMERR_T rc = NM_OK;	if (parms == NULL || g_slist_length(parms) != 2)		return;	user = g_slist_nth_data(parms, 0);	conference = g_slist_nth_data(parms, 1);	if (user && conference) {		rc = nm_send_join_conference(user, conference,									 _join_conf_resp_cb, conference);		_check_for_disconnect(user, rc);	}	g_slist_free(parms);}/* Send a reject conference, the first item in the parms list is the * NMUser object and the second item is the conference to reject. * This callback is passed to purple_request_action when we ask the * user if they want to joing the conference. */static void_reject_conference_cb(GSList * parms)

⌨️ 快捷键说明

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