示例#1
0
void
fb_util_serv_got_im(PurpleConnection *gc, const gchar *who, const gchar *text,
                    PurpleMessageFlags flags, guint64 timestamp)
{
	const gchar *name;
	PurpleAccount *acct;
	PurpleIMConversation *conv;
	PurpleMessage *msg;

	if (!(flags & PURPLE_MESSAGE_SEND)) {
		purple_serv_got_im(gc, who, text, flags, timestamp);
		return;
	}

	acct = purple_connection_get_account(gc);
	conv = purple_conversations_find_im_with_account(who, acct);

	if (conv == NULL) {
		conv = purple_im_conversation_new(acct, who);
	}

	name = purple_account_get_username(acct);
	msg = purple_message_new_outgoing(name, text, flags);
	purple_message_set_time(msg, timestamp);
	purple_conversation_write_message(PURPLE_CONVERSATION(conv), msg);
}
示例#2
0
static void
bud(PurpleBuddy *who)
{
	PurpleAccount *acct = who->account;
	PurpleConversation *conv = purple_im_conversation_new(acct, who->name);

	purple_im_conversation_send(PURPLE_CONV_IM(conv), "Hello!");
}
示例#3
0
static PurpleIMConversation * ggp_message_get_conv(PurpleConnection *gc,
	uin_t uin)
{
	PurpleAccount *account = purple_connection_get_account(gc);
	PurpleIMConversation *im;
	const gchar *who = ggp_uin_to_str(uin);

	im = purple_conversations_find_im_with_account(who, account);
	if (im)
		return im;
	im = purple_im_conversation_new(account, who);
	return im;
}
示例#4
0
文件: msg.c 项目: Distrotech/pidgin
static void
datacast_inform_user(MsnSwitchBoard *swboard, const char *who,
                     const char *msg, const char *filename)
{
	char *username, *str;
	PurpleAccount *account;
	PurpleBuddy *b;
	PurpleConnection *pc;
	gboolean chat;

	account = swboard->session->account;
	pc = purple_account_get_connection(account);

	if ((b = purple_blist_find_buddy(account, who)) != NULL)
		username = g_markup_escape_text(purple_buddy_get_alias(b), -1);
	else
		username = g_markup_escape_text(who, -1);
	str = g_strdup_printf(msg, username, filename);
	g_free(username);

	swboard->flag |= MSN_SB_FLAG_IM;
	if (swboard->current_users > 1)
		chat = TRUE;
	else
		chat = FALSE;

	if (swboard->conv == NULL) {
		if (chat)
			swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_chat(
					purple_account_get_connection(account), swboard->chat_id));
		else {
			swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_im_with_account(
									who, account));
			if (swboard->conv == NULL)
				swboard->conv = PURPLE_CONVERSATION(purple_im_conversation_new(account, who));
		}
	}

	if (chat)
		purple_serv_got_chat_in(pc,
		                 purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION(swboard->conv)),
		                 who, PURPLE_MESSAGE_RECV|PURPLE_MESSAGE_SYSTEM, str,
		                 time(NULL));
	else
		purple_serv_got_im(pc, who, str, PURPLE_MESSAGE_RECV|PURPLE_MESSAGE_SYSTEM,
		            time(NULL));
	g_free(str);

}
示例#5
0
static PurpleIMConversation *
msn_session_get_im(MsnSession *session,const char *passport)
{
	PurpleAccount *account;
	PurpleIMConversation * im;

	g_return_val_if_fail(session != NULL, NULL);
	account = session->account;

	im = purple_conversations_find_im_with_account(passport, account);
	if(im == NULL){
		im = purple_im_conversation_new(account, passport);
	}
	return im;
}
示例#6
0
static gboolean xmpp_uri_handler(const char *proto, const char *user, GHashTable *params)
{
	char *acct_id = params ? g_hash_table_lookup(params, "account") : NULL;
	PurpleAccount *acct;

	if (g_ascii_strcasecmp(proto, "xmpp"))
		return FALSE;

	acct = find_acct(purple_plugin_get_id(my_protocol), acct_id);

	if (!acct)
		return FALSE;

	/* xmpp:[email protected]?message;subject=Test%20Message;body=Here%27s%20a%20test%20message */
	/* params is NULL if the URI has no '?' (or anything after it) */
	if (!params || g_hash_table_lookup_extended(params, "message", NULL, NULL)) {
		char *body = g_hash_table_lookup(params, "body");
		if (user && *user) {
			PurpleIMConversation *im =
					purple_im_conversation_new(acct, user);
			purple_conversation_present(PURPLE_CONVERSATION(im));
			if (body && *body)
				purple_conversation_send_confirm(PURPLE_CONVERSATION(im), body);
		}
	} else if (g_hash_table_lookup_extended(params, "roster", NULL, NULL)) {
		char *name = g_hash_table_lookup(params, "name");
		if (user && *user)
			purple_blist_request_add_buddy(acct, user, NULL, name);
	} else if (g_hash_table_lookup_extended(params, "join", NULL, NULL)) {
		PurpleConnection *gc = purple_account_get_connection(acct);
		if (user && *user) {
			GHashTable *params = jabber_chat_info_defaults(gc, user);
			jabber_chat_join(gc, params);
		}
		return TRUE;
	}

	return FALSE;
}
示例#7
0
static gboolean
skypeweb_uri_handler(const char *proto, const char *cmd, GHashTable *params)
{
	PurpleAccount *account;
	PurpleConnection *pc;
	
	if (!g_str_equal(proto, "skype"))
		return FALSE;
		
	/*skype uri's:
	
		skype:						//does nothing
		skype:{buddyname}			//open im with {buddyname}
		skype:{buddynames}?chat		//open multi-user chat with {buddynames}
		skype:?chat&blob={blob id}	//open public multi-user chat with the blob id of {blob id}
		skype:?chat&id={chat id}	//open multi-user chat with the id of {chat id}
		skype:{buddyname}?add		//add user to buddy list 
		skype:{buddyname}?userinfo	//get buddy's info
		
		skype:{buddynames}?call		//call {buddynames}
		skype:{buddyname}?voicemail	//send a voice mail message
		skype:{buddyname}?sendfile	//send a file
		*/
	
	account = find_acct(SKYPEWEB_PLUGIN_ID, g_hash_table_lookup(params, "account"));
	pc = purple_account_get_connection(account);
	
	if (g_hash_table_lookup(params, "chat")) {
		if (cmd && *cmd) {
			//there'll be a bunch of usernames, seperated by semi-colon
			if (strchr(cmd, ';')) {
				gchar **users = g_strsplit_set(cmd, ";", -1);
				skypeweb_initiate_chat(purple_connection_get_protocol_data(pc), users[0]);
				//TODO the other users
				g_strfreev(users);
			} else {
				PurpleIMConversation *imconv;
				imconv = purple_conversations_find_im_with_account(cmd, account);
				if (!imconv) {
					imconv = purple_im_conversation_new(account, cmd);
				}
				purple_conversation_present(PURPLE_CONVERSATION(imconv));
			}
		} else {
			//probably a public multi-user chat?
			GHashTable *chatinfo = NULL;
			if (g_hash_table_lookup(params, "id")) {
				chatinfo = skypeweb_chat_info_defaults(pc, g_hash_table_lookup(params, "id"));
			} else if (g_hash_table_lookup(params, "blob")) {
				chatinfo = skypeweb_chat_info_defaults(pc, g_hash_table_lookup(params, "blob"));
			}
			
			if (chatinfo != NULL) {
				skypeweb_join_chat(pc, chatinfo);
				g_hash_table_destroy(chatinfo);
			}
		}
	} else if (g_hash_table_lookup(params, "add")) {
		purple_blist_request_add_buddy(account, cmd, "Skype", g_hash_table_lookup(params, "displayname"));
		return TRUE;
	} else if (g_hash_table_lookup(params, "call")) {
		
	} else if (g_hash_table_lookup(params, "userinfo")) {
		skypeweb_get_info(pc, cmd);
		return TRUE;
	} else if (g_hash_table_lookup(params, "voicemail")) {
		
	} else if (g_hash_table_lookup(params, "sendfile")) {
		
	} else if (strlen(cmd)) {
		//supposed to be the same as call?
	}
	
	//we don't know how to handle this
	return FALSE;
}
示例#8
0
文件: msg.c 项目: Distrotech/pidgin
void msn_emoticon_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
{
	MsnSession *session;
	MsnSlpLink *slplink;
	MsnSwitchBoard *swboard;
	MsnObject *obj;
	char **tokens;
	char *smile, *body_str;
	const char *body, *who, *sha1;
	guint tok;
	size_t body_len;

	PurpleConversation *conv;

	session = cmdproc->servconn->session;

	if (!purple_account_get_bool(session->account, "custom_smileys", TRUE))
		return;

	swboard = cmdproc->data;
	conv = swboard->conv;

	body = msn_message_get_bin_data(msg, &body_len);
	if (!body || !body_len)
		return;
	body_str = g_strndup(body, body_len);

	/* MSN Messenger 7 may send more than one MSNObject in a single message...
	 * Maybe 10 tokens is a reasonable max value. */
	tokens = g_strsplit(body_str, "\t", 10);

	g_free(body_str);

	for (tok = 0; tok < 9; tok += 2) {
		if (tokens[tok] == NULL || tokens[tok + 1] == NULL) {
			break;
		}

		smile = tokens[tok];
		obj = msn_object_new_from_string(purple_url_decode(tokens[tok + 1]));

		if (obj == NULL)
			break;

		who = msn_object_get_creator(obj);
		sha1 = msn_object_get_sha1(obj);

		slplink = msn_session_get_slplink(session, who);
		if (slplink->swboard != swboard) {
			if (slplink->swboard != NULL)
				/*
				 * Apparently we're using a different switchboard now or
				 * something?  I don't know if this is normal, but it
				 * definitely happens.  So make sure the old switchboard
				 * doesn't still have a reference to us.
				 */
				slplink->swboard->slplinks = g_list_remove(slplink->swboard->slplinks, slplink);
			slplink->swboard = swboard;
			slplink->swboard->slplinks = g_list_prepend(slplink->swboard->slplinks, slplink);
		}

		/* If the conversation doesn't exist then this is a custom smiley
		 * used in the first message in a MSN conversation: we need to create
		 * the conversation now, otherwise the custom smiley won't be shown.
		 * This happens because every GtkIMHtml has its own smiley tree: if
		 * the conversation doesn't exist then we cannot associate the new
		 * smiley with its GtkIMHtml widget. */
		if (!conv) {
			conv = PURPLE_CONVERSATION(purple_im_conversation_new(session->account, who));
		}

		if (purple_conversation_custom_smiley_add(conv, smile, "sha1", sha1, TRUE)) {
			msn_slplink_request_object(slplink, smile, got_emoticon, NULL, obj);
		}

		msn_object_destroy(obj, FALSE);
		obj =   NULL;
		who =   NULL;
		sha1 = NULL;
	}
	g_strfreev(tokens);
}
示例#9
0
文件: peer.c 项目: Distrotech/pidgin
/**
 * Try to establish the given PeerConnection using a defined
 * sequence of steps.
 */
void
peer_connection_trynext(PeerConnection *conn)
{
	PurpleAccount *account;

	account = purple_connection_get_account(conn->od->gc);

	/*
	 * Close any remnants of a previous failed connection attempt.
	 */
	peer_connection_close(conn);

	/*
	 * 1. Attempt to connect to the remote user using their verifiedip and clientip.
	 *    We try these at the same time and use whichever succeeds first, so we don't
	 *    have to wait for a timeout.
	 */
	if (!(conn->flags & PEER_CONNECTION_FLAG_TRIED_DIRECT) &&
		(conn->verifiedip != NULL) && (conn->port != 0) && (!conn->use_proxy))
	{
		conn->flags |= PEER_CONNECTION_FLAG_TRIED_DIRECT;

		if (conn->type == OSCAR_CAPABILITY_DIRECTIM)
		{
			gchar *tmp;
			PurpleIMConversation *im;
			tmp = g_strdup_printf(_("Attempting to connect to %s:%hu."),
					conn->verifiedip, conn->port);
			im = purple_im_conversation_new(account, conn->bn);
			purple_conversation_write(PURPLE_CONVERSATION(im), NULL, tmp,
					PURPLE_MESSAGE_SYSTEM, time(NULL));
			g_free(tmp);
		}

		conn->verified_connect_data = purple_proxy_connect(NULL, account,
				conn->verifiedip, conn->port,
				peer_connection_verified_established_cb, conn);

		if ((conn->verifiedip == NULL) ||
			strcmp(conn->verifiedip, conn->clientip))
		{
			conn->client_connect_data = purple_proxy_connect(NULL, account,
					conn->clientip, conn->port,
					peer_connection_client_established_cb, conn);
		}

		if ((conn->verified_connect_data != NULL) ||
			(conn->client_connect_data != NULL))
		{
			/* Connecting... */
			conn->connect_timeout_timer = purple_timeout_add_seconds(5,
					peer_connection_tooktoolong, conn);
			return;
		}
	}

	/*
	 * 2. Attempt to have the remote user connect to us (using both
	 *    our verifiedip and our clientip).
	 */
	if (!(conn->flags & PEER_CONNECTION_FLAG_TRIED_INCOMING) &&
		(!conn->use_proxy))
	{
		conn->flags |= PEER_CONNECTION_FLAG_TRIED_INCOMING;

		/*
		 * Remote user is connecting to us, so we'll need to verify
		 * that the user who connected is our friend.
		 */
		conn->flags |= PEER_CONNECTION_FLAG_IS_INCOMING;

		conn->listen_data = purple_network_listen_range(5190, 5290, AF_UNSPEC, SOCK_STREAM, TRUE,
				peer_connection_establish_listener_cb, conn);
		if (conn->listen_data != NULL)
		{
			/* Opening listener socket... */
			return;
		}
	}

	/*
	 * 3. Attempt to have both users connect to an intermediate proxy
	 *    server.
	 */
	if (!(conn->flags & PEER_CONNECTION_FLAG_TRIED_PROXY))
	{
		conn->flags |= PEER_CONNECTION_FLAG_TRIED_PROXY;

		/*
		 * If we initiate the proxy connection, then the remote user
		 * could be anyone, so we need to verify that the user who
		 * connected is our friend.
		 */
		if (!conn->use_proxy)
			conn->flags |= PEER_CONNECTION_FLAG_IS_INCOMING;

		if (conn->type == OSCAR_CAPABILITY_DIRECTIM)
		{
			gchar *tmp;
			PurpleIMConversation *im;
			tmp = g_strdup(_("Attempting to connect via proxy server."));
			im = purple_im_conversation_new(account, conn->bn);
			purple_conversation_write(PURPLE_CONVERSATION(im), NULL, tmp,
					PURPLE_MESSAGE_SYSTEM, time(NULL));
			g_free(tmp);
		}

		conn->verified_connect_data = purple_proxy_connect(NULL, account,
				(conn->proxyip != NULL)
					? conn->proxyip
					: (conn->od->icq ? ICQ_PEER_PROXY_SERVER : AIM_PEER_PROXY_SERVER),
				PEER_PROXY_PORT,
				peer_proxy_connection_established_cb, conn);
		if (conn->verified_connect_data != NULL)
		{
			/* Connecting... */
			return;
		}
	}

	/* Give up! */
	peer_connection_destroy(conn, OSCAR_DISCONNECT_COULD_NOT_CONNECT, NULL);
}
示例#10
0
文件: peer.c 项目: Distrotech/pidgin
/**
 * We've just opened a listener socket, so we send the remote
 * user an ICBM and ask them to connect to us.
 */
static void
peer_connection_establish_listener_cb(int listenerfd, gpointer data)
{
	PeerConnection *conn;
	OscarData *od;
	PurpleConnection *gc;
	PurpleAccount *account;
	PurpleIMConversation *im;
	char *tmp;
	FlapConnection *bos_conn;
	const char *listener_ip;
	const guchar *ip_atoi;
	unsigned short listener_port;

	conn = data;
	conn->listen_data = NULL;

	if (listenerfd < 0)
	{
		/* Could not open listener socket */
		peer_connection_trynext(conn);
		return;
	}

	od = conn->od;
	gc = od->gc;
	account = purple_connection_get_account(gc);
	conn->listenerfd = listenerfd;

	/* Watch for new connections on our listener socket */
	conn->watcher_incoming = purple_input_add(conn->listenerfd,
			PURPLE_INPUT_READ, peer_connection_listen_cb, conn);

	/* Send the "please connect to me!" ICBM */
	bos_conn = flap_connection_findbygroup(od, SNAC_FAMILY_ICBM);
	if (bos_conn == NULL)
	{
		/* Not good */
		peer_connection_trynext(conn);
		return;
	}

	if (bos_conn->gsc)
		listener_ip = purple_network_get_my_ip(bos_conn->gsc->fd);
	else
		listener_ip = purple_network_get_my_ip(bos_conn->fd);

	ip_atoi = peer_ip_atoi(listener_ip);
	if (ip_atoi == NULL) {
		/* Could not convert IP to 4 byte array--weird, but this does
		   happen for some users (#4829, Adium #15839).  Maybe they're
		   connecting with IPv6...?  Maybe through a proxy? */
		purple_debug_error("oscar", "Can't ask peer to connect to us "
				"because peer_ip_atoi(%s) returned NULL. "
				"fd=%d. is_ssl=%d\n",
				listener_ip ? listener_ip : "(null)",
				bos_conn->gsc ? bos_conn->gsc->fd : bos_conn->fd,
				bos_conn->gsc ? 1 : 0);
		peer_connection_trynext(conn);
		return;
	}

	listener_port = purple_network_get_port_from_fd(conn->listenerfd);

	if (conn->type == OSCAR_CAPABILITY_DIRECTIM)
	{
		aim_im_sendch2_odc_requestdirect(od,
				conn->cookie, conn->bn, ip_atoi,
				listener_port, ++conn->lastrequestnumber);

		/* Print a message to a local conversation window */
		im = purple_im_conversation_new(account, conn->bn);
		tmp = g_strdup_printf(_("Asking %s to connect to us at %s:%hu for "
				"Direct IM."), conn->bn, listener_ip, listener_port);
		purple_conversation_write(PURPLE_CONVERSATION(im), NULL, tmp,
				PURPLE_MESSAGE_SYSTEM, time(NULL));
		g_free(tmp);
	}
	else if (conn->type == OSCAR_CAPABILITY_SENDFILE)
	{
		aim_im_sendch2_sendfile_requestdirect(od,
				conn->cookie, conn->bn,
				ip_atoi,
				listener_port, ++conn->lastrequestnumber,
				(const gchar *)conn->xferdata.name,
				conn->xferdata.size, conn->xferdata.totfiles);
	}
}
示例#11
0
static void ggp_pubdir_search_results_im(PurpleConnection *gc, GList *row,
	gpointer _form)
{
	purple_conversation_present(PURPLE_CONVERSATION(purple_im_conversation_new(
		purple_connection_get_account(gc), g_list_nth_data(row, 0))));
}
示例#12
0
void IMInvoker::send(void *userdata, const std::string event) {
	// we are in the thread that manages all of libpurple
	EventContext* ctx = (EventContext*)userdata;

	if (!ctx)
		return;

	if (!ctx->instance || !ctx->instance->_account) {
		ctx->instance->returnErrorExecution("No account available");
		delete(ctx);
		return;
	}

	if (iequals(ctx->sendReq.name, "im.send")) {
		std::string receiver;
		Event::getParam(ctx->sendReq.params, "receiver", receiver);

		Data data;
		Event::getParam(ctx->sendReq.params, "data", data);

#if LIBPURPLE_VERSION_MAJOR >= 3
		PurpleIMConversation* conv = purple_im_conversation_new(ctx->instance->_account, receiver.c_str());
		if (ctx->sendReq.content.length() > 0)
			purple_conversation_send(PURPLE_CONVERSATION(conv), ctx->sendReq.content.c_str());
#else
		PurpleConversation* conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, ctx->instance->_account, receiver.c_str());
		if (ctx->sendReq.content.length() > 0)
			purple_conv_im_send(purple_conversation_get_im_data(conv), ctx->sendReq.content.c_str());
#endif

#if 0
		if (data.binary) {
			PurpleConnection *gc = purple_account_get_connection(ctx->instance->_account);
			PurplePlugin *prpl;
			PurplePluginProtocolInfo *prpl_info;


			if (gc) {
				prpl = purple_connection_get_prpl(gc);
				prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);

//					if (prpl_info && prpl_info->new_xfer) {
//						PurpleXfer* xfer = (prpl_info->new_xfer)(purple_account_get_connection(ctx->instance->_account), receiver.c_str());
//						purple_xfer_set_local_filename(xfer, "/Users/sradomski/Documents/W3C Standards.pdf");
//						purple_xfer_set_filename(xfer, "asdfadsf.pdf");
//						purple_xfer_request(xfer);
//						purple_xfer_request_accepted(xfer, "/Users/sradomski/Documents/W3C Standards.pdf");
//					}

				//Set the filename
//					purple_xfer_set_local_filename(xfer, [[fileTransfer localFilename] UTF8String]);
//					purple_xfer_set_filename(xfer, [[[fileTransfer localFilename] lastPathComponent] UTF8String]);
//					xfer->ui_data
//					purple_xfer_request(xfer);

				serv_send_file(gc, "sradomski@localhost", "/Users/sradomski/Documents/W3C Standards.pdf");
//					if (prpl_info->send_file && (prpl_info->can_receive_file && prpl_info->can_receive_file(gc, receiver.c_str()))) {
//						prpl_info->send_file(gc, receiver.c_str(), "/Users/sradomski/Documents/W3C Standards.pdf");
//					}
//						prpl_info->send_raw(gc, data.binary->data, data.binary->size);
			}

		}
#endif
	} else if (iequals(ctx->sendReq.name, "im.buddy.add")) {
		std::string buddyName;
		Event::getParam(ctx->sendReq.params, "name", buddyName);

		std::string reqMsg;
		Event::getParam(ctx->sendReq.params, "msg", reqMsg);

		PurpleBuddy* buddy = purple_buddy_new(ctx->instance->_account, buddyName.c_str(), NULL);
		purple_blist_add_buddy(buddy, NULL, NULL, NULL);
#if LIBPURPLE_VERSION_MAJOR >= 3
		purple_account_add_buddy(ctx->instance->_account, buddy, reqMsg.c_str());
#else
		purple_account_add_buddy(ctx->instance->_account, buddy);
#endif

	} else if (iequals(ctx->sendReq.name, "im.buddy.remove")) {
		std::string buddyName;
		Event::getParam(ctx->sendReq.params, "name", buddyName);

#if LIBPURPLE_VERSION_MAJOR >= 3
		PurpleBuddy* buddy = purple_blist_find_buddy(ctx->instance->_account, buddyName.c_str());
		if (PURPLE_IS_BUDDY(buddy)) {
			purple_account_remove_buddy(ctx->instance->_account, buddy, purple_buddy_get_group(buddy));
			purple_blist_remove_buddy(buddy);
		}
#else
		PurpleBuddy* buddy = purple_find_buddy(ctx->instance->_account, buddyName.c_str());
		purple_account_remove_buddy(ctx->instance->_account, buddy, purple_buddy_get_group(buddy));
		purple_blist_remove_buddy(buddy);

#endif
	}

	delete(ctx);
}
示例#13
0
static void
send_online_buddy_cb (PurpleBlistNode *cnode, gpointer data)
{
	PurplePlugin *plugin = (PurplePlugin *)data;
	PurpleConnection *gc;
   GSList *blist;
   PurpleBlistNode *gnode, *node;
   PurpleBuddy *b, *buddy;
   PurpleGroup *g, *check_group;
   const char *name, *gname, *receiver;
   int count = 0;
   PurpleAccount *account;
	PurpleIMConversation *im;
	gchar *buddylist = NULL;
	int total, flag = 0, counter = 0;
	gchar *group_info;

   const gchar *groupname = purple_group_get_name(data);
	purple_debug_info("send-option", "The group selected is: %s", groupname);

   buddy = (PurpleBuddy *)cnode;
	purple_debug_info("send-option", "Inside send_online_buddy_cb");
	receiver = purple_buddy_get_name(buddy); 
	purple_debug_info("send-option", "Receiver name: %s", receiver);
	account = purple_buddy_get_account(buddy);
	gc = purple_account_get_connection(account);

	im = purple_conversations_find_im_with_account(receiver, purple_connection_get_account(gc));
       if(im)
	      purple_debug_info("send-option", "Yayy, IM!");
       else
         purple_debug_info("send-option", "Boo! No IM :(");
	if (im == NULL)
      im = purple_im_conversation_new(purple_connection_get_account(gc), receiver);

   for(gnode = purple_blist_get_buddy_list()->root;
       gnode != NULL;
       gnode = gnode->next)
   {
	    if (PURPLE_IS_GROUP(gnode)) {
         g = (PurpleGroup*)gnode; 
		 /*fishy. It says g may be uninitiliazed here. What can I initilalie g to in the else, to get rid of the warning*/  	
         if (g != data)
			   continue;
			else
            break;
       }
	}

   gname = purple_group_get_name(g);
	total = purple_counting_node_get_online_count(PURPLE_COUNTING_NODE(g));;
   purple_debug_info("send-option", "%s (%d): \n",gname, total);
   group_info = g_strdup_printf("%s (%d):\n",gname, total);
	buddylist = g_strconcat(group_info, "\t","\t", NULL);
			 
   for (blist = purple_blist_get_buddies(); 
	  	  blist != NULL;
		  blist = blist->next)
   {
       node = blist->data;

       if (PURPLE_IS_BUDDY(node)) {
		 b = (PurpleBuddy*)node;
       name = purple_buddy_get_alias(b);                  
       check_group = purple_buddy_get_group(b);
                  
       if (data == check_group && PURPLE_BUDDY_IS_ONLINE(b)) {
          ++count;
			 ++counter;

	       if (flag == 1 && counter != total) {
             buddylist = g_strconcat(name, ",\t", NULL);
             flag = 0;
          } else if (flag == 1 && counter == total) {
             buddylist = g_strconcat(name, ".\t", NULL);
				 purple_debug_info(NULL, "%s", buddylist);	
             purple_conversation_send(PURPLE_CONVERSATION(im), buddylist); 
				 buddylist = NULL;
				 count = 0;
			 } else{
				 if (count <= 20 && counter != total) {
				  buddylist = g_strconcat(buddylist, name, ",\t", NULL);	/*fishy cant insert newline*/	
				 } else {
					if (counter == total)
						 buddylist = g_strconcat(buddylist, name, ".\t", NULL);
					else
                   buddylist = g_strconcat(buddylist, name, ",\t", NULL);
						 
                   purple_debug_info(NULL, "%s", buddylist);	
                   purple_conversation_send(PURPLE_CONVERSATION(im), buddylist); 
						 buddylist = NULL;
						 count = 0;
						 flag = 1;
             }
	       }
          }
	    }
	}
   purple_debug_info("send-option", "The counter is (%d): \n",counter);
   
   purple_notify_message (plugin, PURPLE_NOTIFY_MSG_INFO,
		    "Send online buddies", "Successfully sent your online buddies :)", NULL, NULL,
		     NULL, NULL);
	
	g_free(buddylist);
}
示例#14
0
static void
send_group_list_cb (PurpleBlistNode *cnode, gpointer data)
{
	PurplePlugin *plugin = (PurplePlugin *)data;
	PurpleBuddy *buddy;
	const char *receiver, *gname = NULL;
	PurpleAccount *account;
	PurpleIMConversation *im;
	PurpleConnection *gc;
	PurpleBlistNode *gnode;
	PurpleGroup *g;
	gchar *grouptotal, *grouplist = NULL;
	int count = 0, counter = 0, flag = 0, total = 0;

	buddy = (PurpleBuddy *)cnode;
	purple_debug_info("send-option", "Inside send_group_list_cb");
	receiver = purple_buddy_get_name(buddy); 
	purple_debug_info("send-option", "Receiver name: %s", receiver);
	account = purple_buddy_get_account(buddy);
	gc = purple_account_get_connection(account);

	im = purple_conversations_find_im_with_account(receiver, purple_connection_get_account(gc));
       if(im)
	      purple_debug_info("send-option", "Yayy, IM!");
       else
         purple_debug_info("send-option", "Boo! No IM :(");
	if (im == NULL)
      im = purple_im_conversation_new(purple_connection_get_account(gc), receiver);

	for(gnode = purple_blist_get_buddy_list()->root;
       gnode != NULL;
       gnode = gnode->next)
   {
	    if (PURPLE_IS_GROUP(gnode)) {
          ++total;
			 grouptotal = g_strdup_printf("Groups (%d):\n", total);
			 grouplist = g_strconcat(grouptotal, gname, ",\t", NULL);
       }
	}

	for(gnode = purple_blist_get_buddy_list()->root;
       gnode != NULL;
       gnode = gnode->next)
   {
	    if (PURPLE_IS_GROUP(gnode)) {
         g = (PurpleGroup*)gnode;
			gname = purple_group_get_name(g);
			purple_debug_info("send-option", " Group checked: %s \n",gname);
			++count;
			++counter;

	       if (flag == 1 && counter != total) {
             grouplist = g_strconcat(gname, ",\t", NULL);
             flag = 0;
          } else if (flag == 1 && counter == total) {
             grouplist = g_strconcat(gname, ".\t", NULL);
				 purple_debug_info(NULL, "%s", grouplist);	
             purple_conversation_send(PURPLE_CONVERSATION(im), grouplist); 
				 grouplist = NULL;
				 count = 0;
			 } else{
				 if (count <= 20 && counter != total) {
				  grouplist = g_strconcat(grouplist, gname, ",\t", NULL);	/*fishy cant insert newline*/	
				 } else {
					if (counter == total)
						 grouplist = g_strconcat(grouplist, gname, ".\t", NULL);
					else
                   grouplist = g_strconcat(grouplist, gname, ",\t", NULL);
						 
                   purple_debug_info(NULL, "%s", grouplist);	
                   purple_conversation_send(PURPLE_CONVERSATION(im), grouplist); 
						 grouplist = NULL;
						 count = 0;
						 flag = 1;
             }
	       }
          
		 }
	}
   purple_notify_message (plugin, PURPLE_NOTIFY_MSG_INFO,
		    "Send group list", "Successfully sent your group list :)", NULL, NULL,
		     NULL, NULL);
	
	g_free(grouplist);	
}