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

📄 nmevent.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * nmevent.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 <glib.h>#include <string.h>#include <time.h>#include "nmevent.h"#include "nmfield.h"#include "nmconn.h"#include "nmuserrecord.h"#include "nmrtf.h"#define MAX_UINT32 0xFFFFFFFFstruct _NMEvent{	/* Event type */	int type;	/* The DN of the event source */	char *source;	/* Timestamp of the event */	guint32 gmt;	/* Conference to associate with the event */	NMConference *conference;	/* User record to associate with the event */	NMUserRecord *user_record;	/* Text associated with the event */	char *text;	/* Reference count for event structure */	int ref_count;};/* Handle getdetails response and set the new user record into the event */static void_got_user_for_event(NMUser * user, NMERR_T ret_val,					gpointer resp_data, gpointer user_data){	NMUserRecord *user_record;	NMEvent *event;	nm_event_cb cb;	if (user == NULL)		return;	user_record = resp_data;	event = user_data;	if (ret_val == NM_OK) {		if (event && user_record) {			/* Add the user record to the event structure			 * and make the callback.			 */			nm_event_set_user_record(event, user_record);			if ((cb = nm_user_get_event_callback(user))) {				cb(user, event);			}		}	} else {		/* Cleanup resp_data */	}	/* Clean up */	if (event)		nm_release_event(event);}/* Handle getdetails response, set the new user record into the event * and add the user record as a participant in the conference */static void_got_user_for_conference(NMUser * user, NMERR_T ret_val,						 gpointer resp_data, gpointer user_data){	NMUserRecord *user_record = resp_data;	NMEvent *event = user_data;	NMConference *conference;	nm_event_cb cb;	if (user == NULL)		return;	if (event && user_record) {		conference = nm_event_get_conference(event);		if (conference) {			/* Add source of event as recip of the conference */			nm_conference_add_participant(conference, user_record);			/* Add the user record to the event structure			 * and make the callback.			 */			nm_event_set_user_record(event, user_record);			if ((cb = nm_user_get_event_callback(user))) {				cb(user, event);			}		}	}	if (event)		nm_release_event(event);}/* Read the receive message event, set up the event object, and * get details for the event source if we don't have them yet. */static NMERR_Thandle_receive_message(NMUser * user, NMEvent * event, gboolean autoreply){	NMConference *conference;	NMUserRecord *user_record;	NMConn *conn;	NMERR_T rc = NM_OK;	guint32 size = 0, flags = 0;	char *msg = NULL;	char *nortf = NULL;	char *guid = NULL;	conn = nm_user_get_conn(user);	/* Read the conference guid */	rc = nm_read_uint32(conn, &size);	if (size == MAX_UINT32)	return NMERR_PROTOCOL;	if (rc == NM_OK) {		guid = g_new0(char, size + 1);		rc = nm_read_all(conn, guid, size);	}	/* Read the conference flags */	if (rc == NM_OK) {		rc = nm_read_uint32(conn, &flags);	}	/* Read the message text */	if (rc == NM_OK) {		rc = nm_read_uint32(conn, &size);		if (size == MAX_UINT32)	return NMERR_PROTOCOL;		if (rc == NM_OK) {			msg = g_new0(char, size + 1);			rc = nm_read_all(conn, msg, size);			purple_debug(PURPLE_DEBUG_INFO, "novell", "Message is %s\n", msg);			/* Auto replies are not in RTF format! */			if (!autoreply) {				NMRtfContext *ctx;				ctx = nm_rtf_init();				nortf = nm_rtf_strip_formatting(ctx, msg);				nm_rtf_deinit(ctx);				purple_debug(PURPLE_DEBUG_INFO, "novell",						   "Message without RTF is %s\n", nortf);				/* Store the event data */				nm_event_set_text(event, nortf);			} else {				/* Store the event data */				nm_event_set_text(event, msg);			}		}	}	/* Check to see if we already know about the conference */	conference = nm_conference_list_find(user, guid);	if (conference) {		nm_conference_set_flags(conference, flags);		nm_event_set_conference(event, conference);		/* Add a reference to the user record in our event object */		user_record = nm_find_user_record(user, nm_event_get_source(event));		if (user_record) {			nm_event_set_user_record(event, user_record);		}	} else {		/* This is a new conference, so create one and add it to our list */		conference = nm_create_conference(guid);		nm_conference_set_flags(conference, flags);		/* Add a reference to the conference in the event */		nm_event_set_conference(event, conference);		/* Add new conference to the conference list */		nm_conference_list_add(user, conference);		/* Check to see if we have details for the event source yet */		user_record = nm_find_user_record(user, nm_event_get_source(event));		if (user_record) {			/* We do so add the user record as a recipient of the conference */			nm_conference_add_participant(conference, user_record);			/* Add a reference to the user record in our event object */			nm_event_set_user_record(event, user_record);		} else {			/* Need to go to the server to get details for the user */			rc = nm_send_get_details(user, nm_event_get_source(event),									 _got_user_for_conference, event);			if (rc == NM_OK)				rc = -1;		/* Not done processing the event yet! */		}		nm_release_conference(conference);	}	if (msg)		g_free(msg);	if (nortf)		g_free(nortf);	if (guid)		g_free(guid);	return rc;}/* Read the invite event, set up the event object, and * get details for the event source if we don't have them yet. */static NMERR_Thandle_conference_invite(NMUser * user, NMEvent * event){	NMERR_T rc = NM_OK;	guint32 size = 0;	char *guid = NULL;	char *msg = NULL;	NMConn *conn;	NMUserRecord *user_record;	conn = nm_user_get_conn(user);	/* Read the conference guid */	rc = nm_read_uint32(conn, &size);	if (size == MAX_UINT32)	return NMERR_PROTOCOL;	if (rc == NM_OK) {		guid = g_new0(char, size + 1);		rc = nm_read_all(conn, guid, size);	}	/* Read the the message */	if (rc == NM_OK) {		rc = nm_read_uint32(conn, &size);		if (size == MAX_UINT32)	return NMERR_PROTOCOL;		if (rc == NM_OK) {			msg = g_new0(char, size + 1);			rc = nm_read_all(conn, msg, size);		}	}	/* Store the event data */	if (rc == NM_OK) {		NMConference *conference;		nm_event_set_text(event, msg);		conference = nm_conference_list_find(user, guid);		if (conference == NULL) {			conference = nm_create_conference(guid);			/* Add new conference to the list and the event */			nm_conference_list_add(user, conference);			nm_event_set_conference(event, conference);			/* Check to see if we have details for the event source yet */			user_record = nm_find_user_record(user, nm_event_get_source(event));			if (user_record) {				/* Add a reference to the user record in our event object */				nm_event_set_user_record(event, user_record);			} else {				/* Need to go to the server to get details for the user */				rc = nm_send_get_details(user, nm_event_get_source(event),										 _got_user_for_event, event);				if (rc == NM_OK)					rc = -1;	/* Not done processing the event yet! */			}			nm_release_conference(conference);		}	}	if (msg)		g_free(msg);	if (guid)		g_free(guid);	return rc;}/* Read the invite notify event, set up the event object, and * get details for the event source if we don't have them yet. */static NMERR_Thandle_conference_invite_notify(NMUser * user, NMEvent * event){	NMERR_T rc = NM_OK;	guint32 size = 0;	char *guid = NULL;	NMConn *conn;	NMConference *conference;	NMUserRecord *user_record;	conn = nm_user_get_conn(user);	/* Read the conference guid */	rc = nm_read_uint32(conn, &size);	if (size == MAX_UINT32)	return NMERR_PROTOCOL;	if (rc == NM_OK) {		guid = g_new0(char, size + 1);		rc = nm_read_all(conn, guid, size);	}	conference = nm_conference_list_find(user, guid);	if (conference) {		nm_event_set_conference(event, conference);		/* Check to see if we have details for the event source yet */		user_record = nm_find_user_record(user, nm_event_get_source(event));		if (user_record) {			/* Add a reference to the user record in our event object */			nm_event_set_user_record(event, user_record);		} else {			/* Need to go to the server to get details for the user */			rc = nm_send_get_details(user, nm_event_get_source(event),									 _got_user_for_event, event);			if (rc == NM_OK)				rc = -1;		/* Not done processing the event yet! */		}	} else {		rc = NMERR_CONFERENCE_NOT_FOUND;	}	if (guid)		g_free(guid);	return rc;}/* Read the conference reject event and set up the event object */static NMERR_Thandle_conference_reject(NMUser * user, NMEvent * event){	NMERR_T rc = NM_OK;	guint32 size = 0;	char *guid = NULL;	NMConn *conn;	NMConference *conference;	conn = nm_user_get_conn(user);	/* Read the conference guid */	rc = nm_read_uint32(conn, &size);	if (size == MAX_UINT32)	return NMERR_PROTOCOL;	if (rc == NM_OK) {		guid = g_new0(char, size + 1);		rc = nm_read_all(conn, guid, size);	}	if (rc == NM_OK) {		conference = nm_conference_list_find(user, guid);		if (conference) {			nm_event_set_conference(event, conference);		} else {			rc = NMERR_CONFERENCE_NOT_FOUND;		}	}	if (guid)		g_free(guid);	return rc;}/* Read the conference left event, set up the event object, and * remove the conference from the list if there are no more * participants */static NMERR_Thandle_conference_left(NMUser * user, NMEvent * event){	NMERR_T rc = NM_OK;	guint32 size = 0, flags = 0;	char *guid = NULL;	NMConference *conference;	NMConn *conn;	conn = nm_user_get_conn(user);	/* Read the conference guid */	rc = nm_read_uint32(conn, &size);	if (size == MAX_UINT32)	return NMERR_PROTOCOL;	if (rc == NM_OK) {		guid = g_new0(char, size + 1);		rc = nm_read_all(conn, guid, size);	}	/* Read the conference flags */	if (rc == NM_OK) {		rc = nm_read_uint32(conn, &flags);	}	if (rc == NM_OK) {		conference = nm_conference_list_find(user, guid);		if (conference) {			nm_event_set_conference(event, conference);			nm_conference_set_flags(conference, flags);			nm_conference_remove_participant(conference, nm_event_get_source(event));			if (nm_conference_get_participant_count(conference) == 0) {				nm_conference_list_remove(user, conference);			}		} else {			rc = NMERR_CONFERENCE_NOT_FOUND;		}	}	if (guid)

⌨️ 快捷键说明

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