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

📄 toc.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
			while ((buddy = strtok(NULL, ":")) != NULL)				purple_conv_chat_add_user(chat, buddy, NULL, PURPLE_CBFLAGS_NONE, TRUE);		else			while ((buddy = strtok(NULL, ":")) != NULL)				purple_conv_chat_remove_user(chat, buddy, NULL);	} else if (!g_ascii_strcasecmp(c, "CHAT_INVITE")) {		char *name, *who, *message;		int id;		GHashTable *components = g_hash_table_new_full(g_str_hash, g_str_equal,				g_free, g_free);		name = strtok(NULL, ":");		sscanf(strtok(NULL, ":"), "%d", &id);		who = strtok(NULL, ":");		message = strtok(NULL, ":");		g_hash_table_replace(components, g_strdup("id"), g_strdup_printf("%d", id));		serv_got_chat_invite(gc, name, who, message, components);	} else if (!g_ascii_strcasecmp(c, "CHAT_LEFT")) {		GSList *bcs = gc->buddy_chats;		PurpleConversation *b = NULL;		int id;		sscanf(strtok(NULL, ":"), "%d", &id);		while (bcs) {			b = (PurpleConversation *)bcs->data;			if (id == purple_conv_chat_get_id(PURPLE_CONV_CHAT(b)))				break;			b = NULL;			bcs = bcs->next;		}		if (!b)			return;		if (b->window) {			char error_buf[BUF_LONG];			purple_conversation_set_account(b, NULL);			g_snprintf(error_buf, sizeof error_buf, _("You have been disconnected"								  " from chat room %s."), b->name);			purple_notify_error(gc, NULL, error_buf, NULL);		} else			serv_got_chat_left(gc, id);	} else if (!g_ascii_strcasecmp(c, "GOTO_URL")) {		char *name, *url, tmp[256];		name = strtok(NULL, ":");		url = strtok(NULL, ":");		g_snprintf(tmp, sizeof(tmp), "http://%s:%d/%s", tdt->toc_ip,				purple_account_get_int(gc->account, "port", TOC_PORT),				url);		purple_url_fetch(tmp, FALSE, NULL, FALSE, toc_got_info, gc);	} else if (!g_ascii_strcasecmp(c, "DIR_STATUS")) {	} else if (!g_ascii_strcasecmp(c, "ADMIN_NICK_STATUS")) {	} else if (!g_ascii_strcasecmp(c, "ADMIN_PASSWD_STATUS")) {		purple_notify_info(gc, NULL, _("Password Change Successful"), NULL);	} else if (!g_ascii_strcasecmp(c, "PAUSE")) {		tdt->state = STATE_PAUSE;	} else if (!g_ascii_strcasecmp(c, "RVOUS_PROPOSE")) {#if 0		char *user, *uuid, *cookie;		int seq;		char *rip, *pip, *vip, *trillian = NULL;		int port;				user = strtok(NULL, ":");		uuid = strtok(NULL, ":");		cookie = strtok(NULL, ":");		sscanf(strtok(NULL, ":"), "%d", &seq);		rip = strtok(NULL, ":");		pip = strtok(NULL, ":");		vip = strtok(NULL, ":");		sscanf(strtok(NULL, ":"), "%d", &port);		if (!strcmp(uuid, FILE_SEND_UID)) {			/* they want us to get a file */			int unk[4], i;			char *messages[4], *tmp, *name;			int subtype, files, totalsize = 0;			struct ft_request *ft;			for (i = 0; i < 4; i++) {				trillian = strtok(NULL, ":");				sscanf(trillian, "%d", &unk[i]);				if (unk[i] == 10001)					break;				/* Trillian likes to send an empty token as a message, rather than				   no message at all. */				if (*(trillian + strlen(trillian) +1) != ':')					frombase64(strtok(NULL, ":"), &messages[i], NULL);			}			   			frombase64(strtok(NULL, ":"), &tmp, NULL);			subtype = tmp[1];			files = tmp[3];			totalsize |= (tmp[4] << 24) & 0xff000000;			totalsize |= (tmp[5] << 16) & 0x00ff0000;			totalsize |= (tmp[6] << 8) & 0x0000ff00;			totalsize |= (tmp[7] << 0) & 0x000000ff;			if (!totalsize) {				g_free(tmp);				for (i--; i >= 0; i--)					g_free(messages[i]);				return;			}			name = tmp + 8;			ft = g_new0(struct ft_request, 1);			ft->cookie = g_strdup(cookie);			ft->ip = g_strdup(pip);			ft->port = port;			if (i)				ft->message = g_strdup(messages[0]);			else				ft->message = NULL;			ft->filename = g_strdup(name);			ft->user = g_strdup(user);			ft->size = totalsize;			ft->files = files;			g_snprintf(ft->UID, sizeof(ft->UID), "%s", FILE_SEND_UID);			ft->gc = gc;			g_free(tmp);			for (i--; i >= 0; i--)				g_free(messages[i]);			purple_debug(PURPLE_DEBUG_MISC, "toc",					   "English translation of RVOUS_PROPOSE: %s requests "					   "Send File (i.e. send a file to you); %s:%d "					   "(verified_ip:port), %d files at total size of "					   "%d bytes.\n", user, vip, port, files, totalsize);			accept_file_dialog(ft);		} else if (!strcmp(uuid, FILE_GET_UID)) {			/* they want us to send a file */			int unk[4], i;			char *messages[4], *tmp;			struct ft_request *ft;			for (i = 0; i < 4; i++) {				sscanf(strtok(NULL, ":"), "%d", unk + i);				if (unk[i] == 10001)					break;				/* Trillian likes to send an empty token as a message, rather than				   no message at all. */				if (*(trillian + strlen(trillian) +1) != ':')					frombase64(strtok(NULL, ":"), &messages[i], NULL);			}			frombase64(strtok(NULL, ":"), &tmp, NULL);			ft = g_new0(struct ft_request, 1);			ft->cookie = g_strdup(cookie);			ft->ip = g_strdup(pip);			ft->port = port;			if (i)				ft->message = g_strdup(messages[0]);			else				ft->message = NULL;			ft->user = g_strdup(user);			g_snprintf(ft->UID, sizeof(ft->UID), "%s", FILE_GET_UID);			ft->gc = gc;			g_free(tmp);			for (i--; i >= 0; i--)				g_free(messages[i]);			accept_file_dialog(ft);		} else if (!strcmp(uuid, VOICE_UID)) {			/* oh goody. voice over ip. fun stuff. */		} else if (!strcmp(uuid, B_ICON_UID)) {			int unk[4], i;			char *messages[4];			struct buddy_icon *icon;			for (i = 0; i < 4; i++) {				sscanf(strtok(NULL, ":"), "%d", unk + i);				if (unk[i] == 10001)					break;				frombase64(strtok(NULL, ":"), &messages[i], NULL);			}			frombase64(strtok(NULL, ":"), (char **)&icon, NULL);			purple_debug(PURPLE_DEBUG_MISC, "toc",			           "received icon of length %d\n", icon->len);			g_free(icon);			for (i--; i >= 0; i--)				g_free(messages[i]);		} else if (!strcmp(uuid, IMAGE_UID)) {			/* aka Direct IM */		} else {			purple_debug(PURPLE_DEBUG_ERROR, "toc",					   "Don't know what to do with RVOUS UUID %s\n", uuid);			/* do we have to do anything here? i think it just times out */		}#endif	} else {		purple_debug(PURPLE_DEBUG_ERROR, "toc",				   "don't know what to do with %s\n", c);	}}static int toc_send_im(PurpleConnection *gc, const char *name, const char *message, PurpleMessageFlags flags){	char *buf1, *buf2;#if 1	/* This is the old, non-i18n way */	buf1 = escape_text(message);	if (strlen(buf1) + 52 > MSG_LEN) {		g_free(buf1);		return -E2BIG;	}	buf2 = g_strdup_printf("toc_send_im %s \"%s\"%s", purple_normalize(gc->account, name), buf1,						   ((flags & PURPLE_MESSAGE_AUTO_RESP) ? " auto" : ""));	g_free(buf1);#else	/* This doesn't work yet.  See the comments below for details */	buf1 = purple_strreplace(message, "\"", "\\\"");	/*	 * We still need to determine what encoding should be used and send the 	 * message in that encoding.  This should be done the same as in 	 * oscar_encoding_check() in oscar.c.  There is no encoding flag sent 	 * along with the message--the TOC to OSCAR proxy server must just 	 * use a lil' algorithm to determine what the actual encoding is.	 *	 * After that, you need to convert buf1 to that encoding, and keep track 	 * of the length of the resulting string.  Then you need to make sure 	 * that length is passed to sflap_send().	 */	if (strlen(buf1) + 52 > MSG_LEN) {		g_free(buf1);		return -E2BIG;	}	buf2 = g_strdup_printf("toc2_send_im_enc %s F U en \"%s\" %s", purple_normalize(gc->account, name), buf1, 						   ((flags & PURPLE_MESSAGE_AUTO_RESP) ? "auto" : ""));	g_free(buf1);#endif	sflap_send(gc, buf2, -1, TYPE_DATA);	g_free(buf2);	return 1;}static void toc_set_config(PurpleConnection *gc){	char *buf = g_malloc(MSG_LEN), snd[BUF_LEN * 2];	toc_build_config(gc->account, buf, MSG_LEN - strlen("toc_set_config \\{\\}"), FALSE);	g_snprintf(snd, MSG_LEN, "toc_set_config {%s}", buf);	sflap_send(gc, snd, -1, TYPE_DATA);	g_free(buf);}static void toc_get_info(PurpleConnection *gc, const char *name){	char buf[BUF_LEN * 2];	g_snprintf(buf, MSG_LEN, "toc_get_info %s", purple_normalize(gc->account, name));	sflap_send(gc, buf, -1, TYPE_DATA);}/* Should be implemented as an Account Action? */static void toc_get_dir(PurpleBlistNode *node, gpointer data){	PurpleBuddy *buddy;	PurpleConnection *gc;	char buf[BUF_LEN * 2];	g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node));	buddy = (PurpleBuddy *) node;	gc = purple_account_get_connection(buddy->account);	g_snprintf(buf, MSG_LEN, "toc_get_dir %s",			purple_normalize(buddy->account, buddy->name));	sflap_send(gc, buf, -1, TYPE_DATA);}#if 0/* Should be implemented as an Account Action */static void toc_set_dir(PurpleConnection *g, const char *first, const char *middle, const char *last,			const char *maiden, const char *city, const char *state, const char *country, int web){	char *buf3, buf2[BUF_LEN * 4], buf[BUF_LEN];	g_snprintf(buf2, sizeof(buf2), "%s:%s:%s:%s:%s:%s:%s:%s", first,		   middle, last, maiden, city, state, country, (web == 1) ? "Y" : "");	buf3 = escape_text(buf2);	g_snprintf(buf, sizeof(buf), "toc_set_dir %s", buf3);	g_free(buf3);	sflap_send(g, buf, -1, TYPE_DATA);}#endif#if 0/* Should be implemented as an Account Action */static void toc_dir_search(PurpleConnection *g, const char *first, const char *middle, const char *last,			   const char *maiden, const char *city, const char *state, const char *country, const char *email){	char buf[BUF_LONG];	g_snprintf(buf, sizeof(buf) / 2, "toc_dir_search %s:%s:%s:%s:%s:%s:%s:%s", first, middle,		   last, maiden, city, state, country, email);	purple_debug(PURPLE_DEBUG_INFO, "toc",			   "Searching for: %s,%s,%s,%s,%s,%s,%s\n",			   first, middle, last, maiden,		     city, state, country);	sflap_send(g, buf, -1, TYPE_DATA);}#endifstatic void toc_set_status(PurpleAccount *account, PurpleStatus *status){#if 0 /* do we care about TOC any more? */	char buf[BUF_LEN * 2];	if (gc->away) {		g_free(gc->away);		gc->away = NULL;	}	if (message) {		char *tmp;		gc->away = g_strdup(message);		tmp = escape_text(message);		g_snprintf(buf, MSG_LEN, "toc_set_away \"%s\"", tmp);		g_free(tmp);	} else		g_snprintf(buf, MSG_LEN, "toc_set_away \"\"");	sflap_send(g, buf, -1, TYPE_DATA);#endif}static void toc_set_info(PurpleConnection *g, const char *info){	char buf[BUF_LEN * 2], *buf2;	buf2 = escape_text(info);	g_snprintf(buf, sizeof(buf), "toc_set_info \"%s\n\"", buf2);	g_free(buf2);	sflap_send(g, buf, -1, TYPE_DATA);}static void toc_change_passwd(PurpleConnection *g, const char *orig, const char *new){	char buf[BUF_LEN * 2];	g_snprintf(buf, BUF_LONG, "toc_change_passwd %s %s", orig, new);	sflap_send(g, buf, -1, TYPE_DATA);}static voidtoc_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group){	char buf[BUF_LEN * 2];	g_snprintf(buf, sizeof(buf), "toc_add_buddy %s", purple_normalize(gc->account, buddy->name));	sflap_send(gc, buf, -1, TYPE_DATA);	toc_set_config(gc);}static void toc_add_buddies(PurpleConnection *gc, GList *buddies, GList *groups){	char buf[BUF_LEN * 2];	int n;	GList *cur;	n = g_snprintf(buf, sizeof(buf), "toc_add_buddy");	for (cur = buddies; cur != NULL; cur = cur->next) {		PurpleBuddy *buddy = cur->data;		if (strlen(purple_normalize(gc->account, buddy->name)) + n + 32 > MSG_LEN) {			sflap_send(gc, buf, -1, TYPE_DATA);			n = g_snprintf(buf, sizeof(buf), "toc_add_buddy");		}		n += g_snprintf(buf + n, sizeof(buf) - n, " %s", purple_normalize(gc->account, buddy->name));	}	sflap_send(gc, buf, -1, TYPE_DATA);}static void toc_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group){	char buf[BUF_LEN * 2];	g_snprintf(buf, sizeof(buf), "toc_remove_buddy %s", purple_normalize(gc->account, buddy->name));	sflap_send(gc, buf, -1, TYPE_DATA);	toc_set_config(gc);}static void toc_remove_buddies(PurpleConnection *gc, GList *buddies, GList *groups){	char buf[BUF_LEN * 2];	int n;	GList *cur;	n = g_snprintf(buf, sizeof(buf), "toc_remove_buddy");	for (cur = buddies; cur != NULL; cur = cur->next) {		PurpleBuddy *buddy = cur->data;		if (strlen(purple_normalize(gc->account, buddy->name)) + n + 32 > MSG_LEN) {			sflap_send(gc, buf, -1, TYPE_DATA);			n = g_snprintf(buf, sizeof(buf), "toc_remove_buddy");		}		n += g_snprintf(buf + n, sizeof(buf) - n, " %s", purple_normalize(gc->account, buddy->name));	}	sflap_send(gc, buf, -1, TYPE_DATA);	toc_set_config(gc);}static void toc_set_idle(PurpleConnection *g, int time){	char buf[BUF_LEN * 2];	g_snprintf(buf, sizeof(buf), "toc_set_idle %d", time);	sflap_send(g, buf, -1, TYPE_DATA);}static void toc_warn(PurpleConnection *g, const char *name, int anon){	char send[BUF_LEN * 2];	g_snprintf(send, 255, "toc_evil %s %s", name, ((anon) ? "anon" : "norm"));	sflap_send(g, send, -1, TYPE_DATA);}static GList *toc_chat_info(PurpleConnection *gc){	GList *m = NULL;	struct proto_chat_entry *pce;	pce = g_new0(struct proto_chat_entry, 1);	pce->label = _("_Group:");	pce->identifier = "room";	m = g_list_append(m, pce);	pce = g_new0(struct proto_chat_entry, 1);	pce->label = _("_Exchange:");	pce->identifier = "exchange";	pce->is_int = TRUE;	pce->min = 4;	pce->max = 20;	m = g_list_append(m, pce);	return m;}GHashTable *toc_chat_info_defaults(PurpleConnection *gc, const char *chat_name){	GHashTable *defaults;	defaults = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);	if (chat_name != NULL)		g_hash_table_insert(defaults, "room", g_strdup(chat_name));	return defaults;}static void toc_join_chat(PurpleConnection *g, GHashTable *data){	char buf[BUF_LONG];	char *name, *exchange;	char *id;	name = g_hash_table_lookup(data, "room");	exchange = g_hash_table_lookup(data, "exchange");	id = g_hash_table_lookup(data, "id");	if (id) {		g_snprintf(buf, 255, "toc_chat_accept %d", atoi(id));

⌨️ 快捷键说明

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