Exemplo n.º 1
0
static void nullprpl_chat_invite(PurpleConnection *gc, int id,
                                 const char *message, const char *who) {
  const char *username = purple_account_get_username(purple_connection_get_account(gc));
  PurpleChatConversation *chat = purple_conversations_find_chat(gc, id);
  const char *room = purple_conversation_get_name(PURPLE_CONVERSATION(chat));
  PurpleAccount *to_acct = purple_accounts_find(who, NULLPRPL_ID);

  purple_debug_info("nullprpl", "%s is inviting %s to join chat room %s\n",
                    username, who, room);

  if (to_acct) {
    PurpleChatConversation *to_conv = purple_conversations_find_chat(purple_account_get_connection(to_acct), id);
    if (to_conv) {
      char *tmp = g_strdup_printf("%s is already in chat room %s.", who, room);
      purple_debug_info("nullprpl",
                        "%s is already in chat room %s; "
                        "ignoring invitation from %s\n",
                        who, room, username);
      purple_notify_info(gc, _("Chat invitation"), _("Chat invitation"), tmp,
                         purple_request_cpar_from_conversation(PURPLE_CONVERSATION(to_conv)));
      g_free(tmp);
    } else {
      GHashTable *components;
      components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
      g_hash_table_replace(components, "room", g_strdup(room));
      g_hash_table_replace(components, "invited_by", g_strdup(username));
      purple_serv_got_chat_invite(purple_account_get_connection(to_acct), room, username, message, components);
    }
  }
}
Exemplo n.º 2
0
void yahoo_process_chat_addinvite(PurpleConnection *gc, struct yahoo_packet *pkt)
{
	PurpleAccount *account;
	GSList *l;
	char *room = NULL;
	char *msg = NULL;
	char *who = NULL;

	account = purple_connection_get_account(gc);

	for (l = pkt->hash; l; l = l->next) {
		struct yahoo_pair *pair = l->data;

		switch (pair->key) {
		case 104:
			g_free(room);
			room = yahoo_string_decode(gc, pair->value, TRUE);
			break;
		case 129: /* room id? */
			break;
		case 126: /* ??? */
			break;
		case 117:
			g_free(msg);
			msg = yahoo_string_decode(gc, pair->value, FALSE);
			break;
		case 119:
			if (g_utf8_validate(pair->value, -1, NULL)) {
				who = pair->value;
			} else {
				purple_debug_warning("yahoo", "yahoo_process_chat_addinvite "
						"got non-UTF-8 string for key %d\n", pair->key);
			}
			break;
		case 118: /* us */
			break;
		}
	}

	if (room && who) {
		GHashTable *components;

		if (!purple_account_privacy_check(account, who) ||
				(purple_account_get_bool(account, "ignore_invites", FALSE)))
		{
			purple_debug_info("yahoo", "Invite to room %s from %s has been dropped.\n", room, who);
			g_free(room);
			g_free(msg);
			return;
		}

		components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
		g_hash_table_replace(components, g_strdup("room"), g_strdup(room));
		purple_serv_got_chat_invite(gc, room, who, msg, components);
	}

	g_free(room);
	g_free(msg);
}
Exemplo n.º 3
0
void yahoo_process_conference_invite(PurpleConnection *gc, struct yahoo_packet *pkt)
{
	PurpleAccount *account;
	GSList *l;
	char *room = NULL;
	char *who = NULL;
	char *msg = NULL;
	GString *members = NULL;
	GHashTable *components;

	if ( (pkt->status == 2) || (pkt->status == 11) )
		return; /* Status is 11 when we are being notified about invitation being sent to someone else */

	account = purple_connection_get_account(gc);

	for (l = pkt->hash; l; l = l->next) {
		struct yahoo_pair *pair = l->data;
		if (pair->key == 57)
		{
			room = yahoo_string_decode(gc, pair->value, FALSE);
			if (yahoo_find_conference(gc, room) != NULL)
			{
				/* Looks like we got invited to an already open conference. */
				/* Laters: Should we accept this conference rather than ignoring the invitation ? */
				purple_debug_info("yahoo","Ignoring invitation for an already existing chat, room:%s\n",room);
				g_free(room);
				return;
			}
		}
	}

	members = g_string_sized_new(512);

	for (l = pkt->hash; l; l = l->next) {
		struct yahoo_pair *pair = l->data;

		switch (pair->key) {
		case 1: /* us, but we already know who we are */
			break;
		case 57:
			g_free(room);
			room = yahoo_string_decode(gc, pair->value, FALSE);
			break;
		case 50: /* inviter */
			if (g_utf8_validate(pair->value, -1, NULL)) {
				who = pair->value;
				g_string_append_printf(members, "%s\n", who);
			} else {
				purple_debug_warning("yahoo", "yahoo_process_conference_invite "
						"got non-UTF-8 string for key %d\n", pair->key);
			}
			break;
		case 51: /* This user is being invited to the conference. Comes with status = 11, so we wont reach here */
			break;
		case 52: /* Invited users. Assuming us invited, since we got this packet */
			break; /* break needed, or else we add the users to the conference before they accept the invitation */
		case 53: /* members who have already joined the conference */
			if (g_utf8_validate(pair->value, -1, NULL)) {
				g_string_append_printf(members, "%s\n", pair->value);
			} else {
				purple_debug_warning("yahoo", "yahoo_process_conference_invite "
						"got non-UTF-8 string for key %d\n", pair->key);
			}
			break;
		case 58:
			g_free(msg);
			msg = yahoo_string_decode(gc, pair->value, FALSE);
			break;
		case 13: /* ? */
			break;
		}
	}

	if (!room) {
		g_string_free(members, TRUE);
		g_free(msg);
		return;
	}

	if (!purple_account_privacy_check(account, who) ||
			(purple_account_get_bool(account, "ignore_invites", FALSE)))
	{
		purple_debug_info("yahoo",
		    "Invite to conference %s from %s has been dropped.\n", room, who);
		g_free(room);
		g_free(msg);
		g_string_free(members, TRUE);
		return;
	}

	components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
	g_hash_table_replace(components, g_strdup("room"), room);
	if (msg)
		g_hash_table_replace(components, g_strdup("topic"), msg);
	g_hash_table_replace(components, g_strdup("type"), g_strdup("Conference"));
	g_hash_table_replace(components, g_strdup("members"), g_string_free(members, FALSE));
	purple_serv_got_chat_invite(gc, room, who, msg, components);

}