Exemple #1
0
static int waprpl_send_chat(PurpleConnection * gc, int id, const char *message, PurpleMessageFlags flags)
{
	whatsapp_connection *wconn = purple_connection_get_protocol_data(gc);
	PurpleAccount *account = purple_connection_get_account(gc);
	PurpleConversation *convo = purple_find_chat(gc, id);
	PurpleChat *ch = blist_find_chat_by_convo(gc, id);
	GHashTable *hasht = purple_chat_get_components(ch);
	char *chat_id = g_hash_table_lookup(hasht, "id");
	char *plain;

	purple_markup_html_to_xhtml(message, NULL, &plain);

	char msgid[128];
	waAPI_getmsgid(wconn->waAPI, msgid);

	purple_signal_emit(purple_connection_get_prpl(gc), "whatsapp-sending-message", gc, msgid, chat_id, message);

	waAPI_sendchat(wconn->waAPI, msgid, chat_id, plain);
	g_free(plain);

	waprpl_check_output(gc);

	const char *me = purple_account_get_string(account, "nick", "");
	purple_conv_chat_write(PURPLE_CONV_CHAT(convo), me, message, PURPLE_MESSAGE_SEND, time(NULL));

	return 1;
}
Exemple #2
0
PurpleStoredImage *
purple_buddy_icons_set_account_icon(PurpleAccount *account,
                                    guchar *icon_data, size_t icon_len)
{
	PurpleStoredImage *old_img;
	PurpleStoredImage *img = NULL;
	char *old_icon;

	if (icon_data != NULL && icon_len > 0)
	{
		img = purple_buddy_icon_data_new(icon_data, icon_len, NULL);
	}

	old_icon = g_strdup(purple_account_get_string(account, "buddy_icon", NULL));
	if (img && purple_buddy_icons_is_caching())
	{
		const char *filename = purple_imgstore_get_filename(img);
		purple_account_set_string(account, "buddy_icon", filename);
		purple_account_set_int(account, "buddy_icon_timestamp", time(NULL));
		ref_filename(filename);
	}
	else
	{
		purple_account_set_string(account, "buddy_icon", NULL);
		purple_account_set_int(account, "buddy_icon_timestamp", 0);
	}
	unref_filename(old_icon);

	old_img = g_hash_table_lookup(pointer_icon_cache, account);

	if (img)
		g_hash_table_insert(pointer_icon_cache, account, img);
	else
		g_hash_table_remove(pointer_icon_cache, account);

	if (purple_account_is_connected(account))
	{
		PurpleConnection *gc;
		PurplePluginProtocolInfo *prpl_info;

		gc = purple_account_get_connection(account);
		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc));

		if (prpl_info && prpl_info->set_buddy_icon)
			prpl_info->set_buddy_icon(gc, img);
	}

	if (old_img)
		purple_imgstore_unref(old_img);
	else if (old_icon)
	{
		/* The old icon may not have been loaded into memory.  In that
		 * case, we'll need to uncache the filename.  The filenames
		 * are ref-counted, so this is safe. */
		purple_buddy_icon_data_uncache_file(old_icon);
	}
	g_free(old_icon);

	return img;
}
static VALUE set_public_alias(VALUE self, VALUE nickname)
{
  PurpleAccount *account = PURPLE_ACCOUNT(self);
  PurpleConnection *connection = NULL;
  PurplePlugin *prpl = NULL;
  const char *alias = NULL;
  void (*set_alias) (PurpleConnection *gc, const char *alias);
  
  alias = RSTRING_PTR( nickname );
  
  connection = purple_account_get_connection( account );
  
  if (!connection) {
    purple_account_set_public_alias( account, alias, NULL, NULL );
    return Qnil;
  }

  prpl = purple_connection_get_prpl( connection );
  if (!g_module_symbol( prpl->handle, "set_alias", (void *) &set_alias ) ) {
    // purple_account_set_public_alias( account, alias, NULL, NULL );
    return Qnil;
  }

  set_alias( connection, alias );
  
  return Qnil;
}
void TestPidginIm::testSendIQ(PurplePluginAction* action) {
	const char* fromName = "test@localhost/QAS";
	const char* toName = "xuewen@localhost/winxp";
	const char* protocol = "prpl-jabber";
	PurpleAccount * account = purple_accounts_find(fromName, protocol);
	if (!account) {
		purple_debug_info("TestQAS Test file", "find accout faile");
		return;
	}

	PurpleConnection * conn = purple_account_get_connection(account);
	PurplePluginProtocolInfo * prpl = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(conn));
	prpl->send_raw(conn, msg, strlen(msg));
	prpl->send_raw(conn, iq, strlen(iq));
}
/*static void
toggle_nickchange_pref(const char *name, PurplePrefType type, gconstpointer val, gpointer data)
{
	
}*/
static void nickchange_chat_rename_user
(PurpleConversation *conv, const char *old_user, const char *new_user, const char *new_alias)
{
	if (!should_hide_notice(conv, old_user, userstable)) {
		PurpleConvChat *chat = PURPLE_CONV_CHAT(conv);
		char tmp[2048];
		
		if (purple_strequal(chat->nick, purple_normalize(conv->account, old_user))) {
			// Its me!
			char *escaped = g_markup_escape_text(new_user, -1);
			g_snprintf(tmp, sizeof(tmp),
					_("You are now known as %s"), escaped);
			g_free(escaped);
		} else {
			const char *old_alias = old_user;
			const char *new_alias = new_user;
			char *escaped;
			char *escaped2;
			PurpleConnection *gc = purple_conversation_get_gc(conv);
			PurplePluginProtocolInfo *prpl_info;
			
			prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc));
			if (prpl_info && !(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) {
				PurpleBuddy *buddy;

				if ((buddy = purple_find_buddy(gc->account, old_user)) != NULL)
					old_alias = purple_buddy_get_contact_alias(buddy);
				if ((buddy = purple_find_buddy(gc->account, new_user)) != NULL)
					new_alias = purple_buddy_get_contact_alias(buddy);
			}

			escaped = g_markup_escape_text(old_alias, -1);
			escaped2 = g_markup_escape_text(new_alias, -1);
			g_snprintf(tmp, sizeof(tmp),
					_("%s is now known as %s"), escaped, escaped2);
			g_free(escaped);
			g_free(escaped2);
		}

		purple_conversation_write(conv, NULL, tmp,
				PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LINKIFY,
				time(NULL));
	}
	
	if (orig_chat_rename_user)
		return orig_chat_rename_user(conv, old_user, new_user, new_alias);
}
static void waprpl_blist_node_removed(PurpleBlistNode * node)
{
	if (!PURPLE_BLIST_NODE_IS_CHAT(node))
		return;

	PurpleChat *ch = PURPLE_CHAT(node);
	PurpleConnection *gc = purple_account_get_connection(purple_chat_get_account(ch));
	if (purple_connection_get_prpl(gc) != _whatsapp_protocol)
		return;

	char *gid = g_hash_table_lookup(purple_chat_get_components(ch), "id");
	if (gid == 0)
		return;		/* Group is not created yet... */
	whatsapp_connection *wconn = purple_connection_get_protocol_data(gc);
	waAPI_deletegroup(wconn->waAPI, gid);
	waprpl_check_output(purple_account_get_connection(purple_chat_get_account(ch)));
}
Exemple #7
0
bool Transport::canSendFile(PurpleAccount *account, const std::string &uname) {
	PurplePlugin *prpl = NULL;
	PurplePluginProtocolInfo *prpl_info = NULL;
	PurpleConnection *gc = purple_account_get_connection(account);
	if (gc)
		prpl = purple_connection_get_prpl(gc);

	if (prpl)
		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);

	if (prpl_info && prpl_info->send_file) {
		if (prpl_info->can_receive_file && prpl_info->can_receive_file(gc, uname.c_str())) {
			return true;
		}
	}
	return false;
}
Exemple #8
0
PurpleRoomlist *purple_roomlist_get_list(PurpleConnection *gc)
{
	PurplePlugin *prpl = NULL;
	PurplePluginProtocolInfo *prpl_info = NULL;

	g_return_val_if_fail(gc != NULL, NULL);
	g_return_val_if_fail(PURPLE_CONNECTION_IS_CONNECTED(gc), NULL);

	prpl = purple_connection_get_prpl(gc);

	if(prpl != NULL)
		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);

	if(prpl_info && prpl_info->roomlist_get_list)
		return prpl_info->roomlist_get_list(gc);

	return NULL;
}
Exemple #9
0
static int waprpl_send_im(PurpleConnection * gc, const char *who, const char *message, PurpleMessageFlags flags)
{
	whatsapp_connection *wconn = purple_connection_get_protocol_data(gc);
	char *plain;

	purple_markup_html_to_xhtml(message, NULL, &plain);

	char msgid[128];
	waAPI_getmsgid(wconn->waAPI, msgid);

	purple_signal_emit(purple_connection_get_prpl(gc), "whatsapp-sending-message", gc, msgid, who, message);

	waAPI_sendim(wconn->waAPI, msgid, who, plain);
	g_free(plain);

	waprpl_check_output(gc);

	return 1;
}
Exemple #10
0
gboolean
purple_media_send_dtmf(PurpleMedia *media, const gchar *session_id,
		gchar dtmf, guint8 volume, guint16 duration)
{
#ifdef USE_VV
	PurpleAccount *account = NULL;
	PurpleConnection *gc = NULL;
	PurplePlugin *prpl = NULL;
	PurplePluginProtocolInfo *prpl_info = NULL;
	PurpleMediaBackendIface *backend_iface = NULL;

	if (media)
	{
		account = purple_media_get_account(media);
		backend_iface = PURPLE_MEDIA_BACKEND_GET_INTERFACE(media->priv->backend);
	}
	if (account)
		gc = purple_account_get_connection(account);
	if (gc)
		prpl = purple_connection_get_prpl(gc);
	if (prpl)
		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);

	if (dtmf == 'a')
		dtmf = 'A';
	else if (dtmf == 'b')
		dtmf = 'B';
	else if (dtmf == 'c')
		dtmf = 'C';
	else if (dtmf == 'd')
		dtmf = 'D';

	g_return_val_if_fail(strchr("0123456789ABCD#*", dtmf), FALSE);

	if (backend_iface && backend_iface->send_dtmf
		&& backend_iface->send_dtmf(media->priv->backend,
				session_id, dtmf, volume, duration))
	{
		return TRUE;
	}
#endif
	return FALSE;
}
Exemple #11
0
void BuddyListNode::ContextMenu::appendProtocolMenu(PurpleConnection *gc)
{
  PurplePluginProtocolInfo *prpl_info
    = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc));
  if (!prpl_info || !prpl_info->blist_node_menu)
    return;

  GList *ll = prpl_info->blist_node_menu(parent_node->getPurpleBlistNode());
  for (GList *l = ll; l; l = l->next) {
    PurpleMenuAction *act = reinterpret_cast<PurpleMenuAction*>(l->data);
    appendMenuAction(*this, act);
  }

  if (ll) {
    // append a separator because there has been some items
    appendSeparator();
  }

  g_list_free(ll);
}
static int account_join_chat(LuaState *L)
{
    PurpleAccount **account = ms_lua_checkclass(L, "purple.account", 1);
    const char *name         = luaL_checkstring(L, 2);

    g_return_val_if_fail(purple_account_is_connected(*account), 0);

    PurpleConnection *pc = purple_account_get_connection(*account);
    PurpleConversation *conv = purple_find_conversation_with_account(
            PURPLE_CONV_TYPE_CHAT,
            name,
            *account);

    if (conv) {
        purple_conversation_present(conv);
    }
    else {
        conv = purple_conversation_new(
                PURPLE_CONV_TYPE_CHAT,
                *account,
                name);
        purple_conv_chat_left(PURPLE_CONV_CHAT(conv));
    }

    GHashTable *hash;
    PurpleChat *chat = purple_blist_find_chat(*account, name);
    if (chat == NULL) {
        PurplePluginProtocolInfo *info = PURPLE_PLUGIN_PROTOCOL_INFO(
                purple_connection_get_prpl(pc));
        if (info->chat_info_defaults != NULL)
            hash = info->chat_info_defaults(pc, name);
    } else {
        hash = purple_chat_get_components(chat);
    }

    serv_join_chat(pc, hash);
    if (chat == NULL && hash != NULL)
        g_hash_table_destroy(hash);

    return 0;
}
Exemple #13
0
static VALUE set_personal_message( VALUE self, VALUE psm ) {
  PurplePlugin *prpl = NULL;
  PurpleAccount *account = PURPLE_ACCOUNT(self);
  void (*set_psm) (PurpleConnection *gc, const char *psm);
  PurpleConnection *gc = NULL;
  
  gc = purple_account_get_connection( account );
  
  if (!gc) {
    return;
  }

  prpl = purple_connection_get_prpl( gc );
  if (!g_module_symbol (prpl->handle, "msn_set_personal_message_cb", (void *) &set_psm)) {
    return;
  }

  set_psm( gc, (const char *) RSTRING_PTR( psm ) );
  
  return Qnil;
}
Exemple #14
0
void purple_roomlist_cancel_get_list(PurpleRoomlist *list)
{
	PurplePlugin *prpl = NULL;
	PurplePluginProtocolInfo *prpl_info = NULL;
	PurpleConnection *gc;

	g_return_if_fail(list != NULL);

	gc = purple_account_get_connection(list->account);

	g_return_if_fail(gc != NULL);

	if(gc)
		prpl = purple_connection_get_prpl(gc);

	if(prpl)
		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);

	if(prpl_info && prpl_info->roomlist_cancel)
		prpl_info->roomlist_cancel(list);
}
Exemple #15
0
static void fl_add_chat(GntWidget *button, gpointer null)
{
	char *name;
	PurpleRoomlistRoom *room = gnt_tree_get_selection_data(GNT_TREE(froomlist.tree));
	PurpleConnection *gc = purple_account_get_connection(froomlist.account);
	PurplePluginProtocolInfo *prpl_info = NULL;

	if (gc == NULL || room == NULL)
		return;

	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc));

	if(prpl_info != NULL && prpl_info->roomlist_room_serialize)
		name = prpl_info->roomlist_room_serialize(room);
	else
		name = g_strdup(purple_roomlist_room_get_name(room));

	purple_blist_request_add_chat(froomlist.account, NULL, NULL, name);

	g_free(name);
}
Exemple #16
0
PurpleWhiteboard *purple_whiteboard_create(PurpleAccount *account, const char *who, int state)
{
	PurplePluginProtocolInfo *prpl_info;
	PurpleWhiteboard *wb = g_new0(PurpleWhiteboard, 1);

	wb->account = account;
	wb->state   = state;
	wb->who     = g_strdup(who);

	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(
				purple_account_get_connection(account)));
	purple_whiteboard_set_prpl_ops(wb, prpl_info->whiteboard_prpl_ops);

	/* Start up protocol specifics */
	if(wb->prpl_ops && wb->prpl_ops->start)
		wb->prpl_ops->start(wb);

	wbList = g_list_append(wbList, wb);

	return wb;
}
Exemple #17
0
PurpleMediaCaps
purple_prpl_get_media_caps(PurpleAccount *account, const char *who)
{
#ifdef USE_VV
	PurpleConnection *gc = NULL;
	PurplePlugin *prpl = NULL;
	PurplePluginProtocolInfo *prpl_info = NULL;

	if (account)
		gc = purple_account_get_connection(account);
	if (gc)
		prpl = purple_connection_get_prpl(gc);
	if (prpl)
		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);

	if (prpl_info && PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info,
			get_media_caps)) {
		return prpl_info->get_media_caps(account, who);
	}
#endif
	return PURPLE_MEDIA_CAPS_NONE;
}
Exemple #18
0
static void
reset_account_list(PurpleAccount *account)
{
	GList *list;
	GntComboBox *accounts = GNT_COMBO_BOX(froomlist.accounts);
	gnt_combo_box_remove_all(accounts);
	for (list = purple_connections_get_all(); list; list = list->next) {
		PurplePluginProtocolInfo *prpl_info = NULL;
		PurpleConnection *gc = list->data;

		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc));
		if (PURPLE_CONNECTION_IS_CONNECTED(gc) &&
		        prpl_info->roomlist_get_list != NULL) {
			PurpleAccount *account = purple_connection_get_account(gc);
			char *text = g_strdup_printf("%s (%s)",
					purple_account_get_username(account),
					purple_account_get_protocol_name(account));
			gnt_combo_box_add_data(accounts, account, text);
			g_free(text);
		}
	}
}
Exemple #19
0
void purple_roomlist_expand_category(PurpleRoomlist *list, PurpleRoomlistRoom *category)
{
	PurplePlugin *prpl = NULL;
	PurplePluginProtocolInfo *prpl_info = NULL;
	PurpleConnection *gc;

	g_return_if_fail(list != NULL);
	g_return_if_fail(category != NULL);
	g_return_if_fail(category->type & PURPLE_ROOMLIST_ROOMTYPE_CATEGORY);

	gc = purple_account_get_connection(list->account);
	g_return_if_fail(gc != NULL);

	if(gc)
		prpl = purple_connection_get_prpl(gc);

	if(prpl)
		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);

	if(prpl_info && prpl_info->roomlist_expand_category)
		prpl_info->roomlist_expand_category(list, category);
}
Exemple #20
0
//-----------------------------------------------------------------------------
//VOXOX CHANGE CJC ADD SKYPE CALL SUPPORT
//TODO: THIS SHOULD NOT BE HERE
bool PurpleIMChat::callSkypeContactCbk(void * dataIn)
{
	Mutex::ScopedLock lock(PurpleIMChat::_mutex);

	PurpleIMChatCallbackData* cbData = (PurpleIMChatCallbackData*) dataIn;

	PurpleIMChat*  imChat		= cbData->getPurpleIMChat();
	IMContactSet*  imContactSet = cbData->getIMContactSet();
	PurpleAccount* gAccount		= getPurpleAccount( imChat->getIMAccount() );

	PurplePluginProtocolInfo* prpl_info = NULL;
	PurpleConnection*		  gc		= purple_account_get_connection(gAccount);
	PurplePlugin*			  prpl		= NULL;

	IMContactSet::const_iterator it;


	if (imContactSet->size() == 1)
	{
		it = imContactSet->begin();
		std::string contactId = (*it).getContactId();
		
		if (gc != NULL)
			prpl = purple_connection_get_prpl(gc);      

		if (prpl != NULL)
			prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);

		if (prpl_info != NULL && prpl_info->set_info != NULL)
			 prpl_info->set_info(NULL,contactId.c_str());
	}
	
	timeoutRemove( cbData );
	delete cbData;

	return TRUE;
}
Exemple #21
0
gboolean
purple_prpl_initiate_media(PurpleAccount *account,
			   const char *who,
			   PurpleMediaSessionType type)
{
#ifdef USE_VV
	PurpleConnection *gc = NULL;
	PurplePlugin *prpl = NULL;
	PurplePluginProtocolInfo *prpl_info = NULL;

	if (account)
		gc = purple_account_get_connection(account);
	if (gc)
		prpl = purple_connection_get_prpl(gc);
	if (prpl)
		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);

	if (prpl_info && PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, initiate_media)) {
		/* should check that the protocol supports this media type here? */
		return prpl_info->initiate_media(account, who, type);
	} else
#endif
	return FALSE;
}
static void
notify_test_jabber_send_cb(PurplePluginAction *action)
{
       xmlnode* message;
       xmlnode* body;
       message = xmlnode_new("message");
       xmlnode_set_attrib(message, "from", "xuewen@localhost/develop");
       xmlnode_set_attrib(message, "to", "test@localhost");
       xmlnode_set_attrib(message, "type", "chat");

       body = xmlnode_new_child(message, "body");
       const char* body_data = "this is a test stanza";
       body->data = (char*)body_data;
       body->data_sz = strlen(body_data);

       // get a connection and emit it
       GList* connections = purple_connections_get_all();
       GList* connection = g_list_first(connections);
       PurpleConnection * gc_xuewen = 0;
       while(connection) {
               PurpleConnection * gc = (PurpleConnection*) connection->data;
               if (strcmp(gc->display_name, "test@localhost/QAS") == 0)
                       gc_xuewen = gc;
               connection = g_list_next(connection);
       }
/*
       const gchar* id = purple_plugin_get_id(gc_xuewen->prpl);
       if (strcmp(id, prpl-jabber) == 0) {

       }
*/
       PurplePlugin* plugin = purple_connection_get_prpl(gc_xuewen);
       PurplePluginProtocolInfo* info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
       info->send_raw(gc_xuewen, msg, strlen(msg));
       //serv_send_im(gc_xuewen, "test@localhost", "this is a test", PURPLE_MESSAGE_SEND);
}
static void waprpl_blist_node_added(PurpleBlistNode * node)
{
	if (!PURPLE_BLIST_NODE_IS_CHAT(node))
		return;

	PurpleChat *ch = PURPLE_CHAT(node);
	PurpleConnection *gc = purple_account_get_connection(purple_chat_get_account(ch));
	if (purple_connection_get_prpl(gc) != _whatsapp_protocol)
		return;

	whatsapp_connection *wconn = purple_connection_get_protocol_data(gc);
	GHashTable *hasht = purple_chat_get_components(ch);
	const char *groupname = g_hash_table_lookup(hasht, "subject");
	const char *gid = g_hash_table_lookup(hasht, "id");
	if (gid != 0)
		return;		/* Already created */
	purple_debug_info(WHATSAPP_ID, "Creating group %s\n", groupname);

	waAPI_creategroup(wconn->waAPI, groupname);
	waprpl_check_output(purple_account_get_connection(purple_chat_get_account(ch)));

	/* Remove it, it will get added at the moment the chat list gets refreshed */
	purple_blist_remove_chat(ch);
}
Exemple #24
0
void jabber_presence_parse(JabberStream *js, xmlnode *packet)
{
	const char *type;
	JabberBuddyResource *jbr = NULL;
	gboolean signal_return, ret;
	JabberPresence presence;
	xmlnode *child;

	memset(&presence, 0, sizeof(presence));
	/* defaults */
	presence.state = JABBER_BUDDY_STATE_UNKNOWN;
	presence.sent = time(NULL);
	/* interesting values */
	presence.from = xmlnode_get_attrib(packet, "from");
	presence.to   = xmlnode_get_attrib(packet, "to");
	type = xmlnode_get_attrib(packet, "type");
	presence.type = str_to_presence_type(type);

	presence.jb = jabber_buddy_find(js, presence.from, TRUE);
	g_return_if_fail(presence.jb != NULL);

	presence.jid_from = jabber_id_new(presence.from);
	if (presence.jid_from == NULL) {
		purple_debug_error("jabber", "Ignoring presence with malformed 'from' "
		                   "JID: %s\n", presence.from);
		return;
	}

	signal_return = GPOINTER_TO_INT(purple_signal_emit_return_1(purple_connection_get_prpl(js->gc),
			"jabber-receiving-presence", js->gc, type, presence.from, packet));
	if (signal_return) {
		goto out;
	}

	if (presence.jid_from->node)
		presence.chat = jabber_chat_find(js, presence.jid_from->node,
		                                 presence.jid_from->domain);
	if(presence.jb->error_msg) {
		g_free(presence.jb->error_msg);
		presence.jb->error_msg = NULL;
	}

	if (presence.type == JABBER_PRESENCE_AVAILABLE) {
		presence.state = JABBER_BUDDY_STATE_ONLINE;
	} else if (presence.type == JABBER_PRESENCE_ERROR) {
		/* TODO: Is this handled properly?  Should it be treated as per-jbr? */
		char *msg = jabber_parse_error(js, packet, NULL);
		presence.state = JABBER_BUDDY_STATE_ERROR;
		presence.jb->error_msg = msg ? msg : g_strdup(_("Unknown Error in presence"));
	} else if (presence.type == JABBER_PRESENCE_SUBSCRIBE) {
		/* TODO: Move to handle_subscribe() (so nick is extracted by the
		 * PresenceHandler */
		struct _jabber_add_permit *jap = g_new0(struct _jabber_add_permit, 1);
		gboolean onlist = FALSE;
		PurpleAccount *account;
		PurpleBuddy *buddy;
		xmlnode *nick;

		account = purple_connection_get_account(js->gc);
		buddy = purple_find_buddy(account, presence.from);
		nick = xmlnode_get_child_with_namespace(packet, "nick", "http://jabber.org/protocol/nick");
		if (nick)
			presence.nickname = xmlnode_get_data(nick);

		if (buddy) {
			if ((presence.jb->subscription & (JABBER_SUB_TO | JABBER_SUB_PENDING)))
				onlist = TRUE;
		}

		jap->gc = js->gc;
		jap->who = g_strdup(presence.from);
		jap->js = js;

		purple_account_request_authorization(account, presence.from, NULL, presence.nickname,
				NULL, onlist, authorize_add_cb, deny_add_cb, jap);

		goto out;
	} else if (presence.type == JABBER_PRESENCE_SUBSCRIBED) {
Exemple #25
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);
}
Exemple #26
0
void BuddyList::add_chat_ok_cb(PurpleRequestFields *fields)
{
  PurpleAccount *account = purple_request_fields_get_account(fields, "account");
  const char *name = purple_request_fields_get_string(fields, "name");
  const char *alias = purple_request_fields_get_string(fields, "alias");
  int selected = purple_request_fields_get_choice(fields, "group");
  GList *list = purple_request_field_choice_get_labels(
      purple_request_fields_get_field(fields, "group"));
  const char *group
    = reinterpret_cast<const char*>(g_list_nth_data(list, selected));
  bool autojoin = purple_request_fields_get_bool(fields, "autojoin");

  bool err = false;
  if (!account) {
    LOG->Message(_("No account specified."));
    err = true;
  }
  else if (!purple_account_is_connected(account)) {
    LOG->Message(_("Selected account is not connected."));
    err = true;
  }
  else {
    PurpleConnection *gc = purple_account_get_connection(account);
    PurplePluginProtocolInfo *info = PURPLE_PLUGIN_PROTOCOL_INFO(
        purple_connection_get_prpl(gc));
    if (!info->join_chat) {
      LOG->Message(_("This protocol does not support chat rooms."));
      account = NULL;
      err = true;
    }
  }
  if (!name || !name[0]) {
    LOG->Message(_("No buddy name specified."));
    err = true;
  }
  if (!group || !group[0]) {
    LOG->Message(_("No group name specified."));
    err = true;
  }
  if (err) {
    purple_blist_request_add_chat(account, purple_find_group(group), alias, name);
    return;
  }

  PurpleConnection *gc = purple_account_get_connection(account);
  PurplePluginProtocolInfo *info = PURPLE_PLUGIN_PROTOCOL_INFO(
      purple_connection_get_prpl(gc));
  GHashTable *hash = NULL;
  if (info->chat_info_defaults)
    hash = info->chat_info_defaults(gc, name);

  PurpleChat *chat = purple_chat_new(account, name, hash);

  if (chat) {
    PurpleGroup* g = purple_find_group(group);
    if (!g) {
      g = purple_group_new(group);
      purple_blist_add_group(g, NULL);
    }
    purple_blist_add_chat(chat, g, NULL);
    if (alias && alias[0])
      purple_blist_alias_chat(chat, alias);
    purple_blist_node_set_bool(reinterpret_cast<PurpleBlistNode*>(chat),
        PACKAGE_NAME "-autojoin", autojoin);
  }
}
Exemple #27
0
static void waprpl_process_incoming_events(PurpleConnection * gc)
{
	whatsapp_connection *wconn = purple_connection_get_protocol_data(gc);
	PurpleAccount *acc = purple_connection_get_account(gc);

	int err;
	do {
		char * reason;
		err = waAPI_geterror(wconn->waAPI, &reason);
		if (err != 0) {
			PurpleConnectionError errcode = PURPLE_CONNECTION_ERROR_OTHER_ERROR;
			if (err == 1)
				errcode = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED;
			purple_connection_error_reason(gc, errcode, reason);
			g_free(reason);
		}
	} while (err != 0);

	switch (waAPI_loginstatus(wconn->waAPI)) {
	case 0:
		purple_connection_update_progress(gc, "Connecting", 0, 4);
		break;
	case 1:
		purple_connection_update_progress(gc, "Sending authorization", 1, 4);
		break;
	case 2:
		purple_connection_update_progress(gc, "Awaiting response", 2, 4);
		break;
	case 3:
		if (!wconn->connected) {
			purple_connection_update_progress(gc, "Connection established", 3, 4);
			purple_connection_set_state(gc, PURPLE_CONNECTED);

			PurpleAccount *account = purple_connection_get_account(gc);
			PurpleStatus *status = purple_account_get_active_status(account);

			waprpl_insert_contacts(gc);
			waprpl_set_status(account, status);

			wconn->connected = 1;
		}
		break;
	default:
		break;
	};
	
	/* Groups update */
	if (waAPI_getgroupsupdated(wconn->waAPI)) {
		purple_debug_info(WHATSAPP_ID, "Receiving update information from my groups\n");

		/* Delete/update the chats that are in our list */
		PurpleBlistNode *node;

		for (node = purple_blist_get_root(); node; node = purple_blist_node_next(node, FALSE)) {
			if (!PURPLE_BLIST_NODE_IS_CHAT(node))
				continue;

			PurpleChat *ch = PURPLE_CHAT(node);
			if (purple_chat_get_account(ch) != acc)
				continue;

			GHashTable *hasht = purple_chat_get_components(ch);
			char *grid = g_hash_table_lookup(hasht, "id");
			char *glist = waAPI_getgroups(wconn->waAPI);
			gchar **gplist = g_strsplit(glist, ",", 0);

			if (str_array_find(gplist, grid) >= 0) {
				/* The group is in the system, update the fields */
				char *sub, *own;
				waAPI_getgroupinfo(wconn->waAPI, grid, &sub, &own, 0);
				g_hash_table_replace(hasht, g_strdup("subject"), sub);
				g_hash_table_replace(hasht, g_strdup("owner"), own);
				purple_blist_alias_chat(ch, sub);
			} else {
				/* The group was deleted */
				PurpleChat *del = (PurpleChat *) node;
				node = purple_blist_node_next(node, FALSE);
				purple_blist_remove_chat(del);
			}

			g_strfreev(gplist);
			g_free(glist);
		}

		/* Add new groups */
		char *glist = waAPI_getgroups(wconn->waAPI);
		gchar **gplist = g_strsplit(glist, ",", 0);
		gchar **p;

		for (p = gplist; *p; p++) {
			gchar *gpid = *p;
			PurpleChat *ch = blist_find_chat_by_id(gc, gpid);
			if (!ch)
				ch = create_chat_group(gpid, wconn, acc);
			
			/* Now update the open conversation that may exist */
			char *id = g_hash_table_lookup(purple_chat_get_components(ch), "id");
			int prplid = chatid_to_convo(id);
			PurpleConversation *conv = purple_find_chat(gc, prplid);
			char *subject, *owner, *part;
			if (conv && waAPI_getgroupinfo(wconn->waAPI, id, &subject, &owner, &part)) {
				conv_add_participants(conv, part, owner);
			}
		}

		g_strfreev(gplist);
		g_free(glist);
	}

	t_message m;
	while (waAPI_querymsg(wconn->waAPI, &m)) {
		switch (m.type) {
		case 0:
			purple_debug_info(WHATSAPP_ID, "Got chat message from %s: %s\n", m.who, m.message);
			conv_add_message(gc, m.who, m.message, m.author, m.t);
			break;
		case 1: {
			purple_debug_info(WHATSAPP_ID, "Got image from %s: %s\n", m.who, m.message);
			int imgid = purple_imgstore_add_with_id(g_memdup(m.image, m.imagelen), m.imagelen, NULL);
			char *msg = g_strdup_printf("<a href=\"%s\"><img id=\"%u\"></a><br/><a href=\"%s\">%s</a>",
				m.url, imgid, m.url, m.url);
			conv_add_message(gc, m.who, msg, m.author, m.t);
			g_free(msg);
			} break;
		case 2: {
			purple_debug_info(WHATSAPP_ID, "Got geomessage from: %s Coordinates (%f %f)\n", 
				m.who, (float)m.lat, (float)m.lng);
			char * lat = dbl2str(m.lat);
			char * lng = dbl2str(m.lng);
			char *msg = g_strdup_printf("<a href=\"http://openstreetmap.org/?lat=%s&lon=%s&zoom=20\">"
				"http://openstreetmap.org/?lat=%s&lon=%s&zoom=20</a>", 
				lat, lng, lat, lng);
			conv_add_message(gc, m.who, msg, m.author, m.t);
			g_free(msg); g_free(lng); g_free(lat);
			} break;
		case 3: {
			purple_debug_info(WHATSAPP_ID, "Got chat sound from %s: %s\n", m.who, m.url);
			char *msg = g_strdup_printf("<a href=\"%s\">%s</a>", m.url, m.url);
			conv_add_message(gc, m.who, msg, m.author, m.t);
			g_free(msg);
			} break;
		case 4: {
			purple_debug_info(WHATSAPP_ID, "Got chat video from %s: %s\n", m.who, m.url);
			char *msg = g_strdup_printf("<a href=\"%s\">%s</a>", m.url, m.url);
			conv_add_message(gc, m.who, msg, m.author, m.t);
			g_free(msg);
			} break;
		case 5: {
			purple_debug_info(WHATSAPP_ID, "Got phone call from %s\n", m.who);
			conv_add_message(gc, m.who, "[Trying to voice-call you]", m.author, m.t);
			} break;
		default:
			purple_debug_info(WHATSAPP_ID, "Got an unrecognized message!\n");
			break;
		};
		g_free(m.who); g_free(m.author); g_free(m.message);
	}

	while (1) {
		int typer;
		char msgid[128];
		if (!waAPI_queryreceivedmsg(wconn->waAPI, msgid, &typer))
			break;

		purple_debug_info(WHATSAPP_ID, "Received message %s type: %d\n", msgid, typer);
		purple_signal_emit(purple_connection_get_prpl(gc), "whatsapp-message-received", gc, msgid, typer);
	}

	/* Status changes, typing notices and profile pictures. */
	query_status(gc);
	query_typing(gc);
	query_icon(gc);
}
Exemple #28
0
void jabber_iq_parse(JabberStream *js, PurpleXmlNode *packet)
{
	JabberIqCallbackData *jcd;
	PurpleXmlNode *child, *error, *x;
	const char *xmlns;
	const char *iq_type, *id, *from;
	JabberIqType type = JABBER_IQ_NONE;
	gboolean signal_return;
	JabberID *from_id;

	from = purple_xmlnode_get_attrib(packet, "from");
	id = purple_xmlnode_get_attrib(packet, "id");
	iq_type = purple_xmlnode_get_attrib(packet, "type");

	/*
	 * Ensure the 'from' attribute is valid. No point in handling a stanza
	 * of which we don't understand where it came from.
	 */
	from_id = jabber_id_new(from);

	if (from && !from_id) {
		purple_debug_error("jabber", "Received an iq with an invalid from: %s\n", from);
		return;
	}

	/*
	 * child will be either the first tag child or NULL if there is no child.
	 * Historically, we used just the 'query' subchild, but newer XEPs use
	 * differently named children. Grabbing the first child is (for the time
	 * being) sufficient.
	 */
	for (child = packet->child; child; child = child->next) {
		if (child->type == PURPLE_XMLNODE_TYPE_TAG)
			break;
	}

	if (iq_type) {
		if (!strcmp(iq_type, "get"))
			type = JABBER_IQ_GET;
		else if (!strcmp(iq_type, "set"))
			type = JABBER_IQ_SET;
		else if (!strcmp(iq_type, "result"))
			type = JABBER_IQ_RESULT;
		else if (!strcmp(iq_type, "error"))
			type = JABBER_IQ_ERROR;
	}

	if (type == JABBER_IQ_NONE) {
		purple_debug_error("jabber", "IQ with invalid type ('%s') - ignoring.\n",
						   iq_type ? iq_type : "(null)");
		jabber_id_free(from_id);
		return;
	}

	/* All IQs must have an ID, so send an error for a set/get that doesn't */
	if(!id || !*id) {

		if(type == JABBER_IQ_SET || type == JABBER_IQ_GET) {
			JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR);

			purple_xmlnode_free(iq->node);
			iq->node = purple_xmlnode_copy(packet);
			if (from) {
				purple_xmlnode_set_attrib(iq->node, "to", from);
				purple_xmlnode_remove_attrib(iq->node, "from");
			}

			purple_xmlnode_set_attrib(iq->node, "type", "error");
			/* This id is clearly not useful, but we must put something there for a valid stanza */
			iq->id = jabber_get_next_id(js);
			purple_xmlnode_set_attrib(iq->node, "id", iq->id);
			error = purple_xmlnode_new_child(iq->node, "error");
			purple_xmlnode_set_attrib(error, "type", "modify");
			x = purple_xmlnode_new_child(error, "bad-request");
			purple_xmlnode_set_namespace(x, NS_XMPP_STANZAS);

			jabber_iq_send(iq);
		} else
			purple_debug_error("jabber", "IQ of type '%s' missing id - ignoring.\n",
			                   iq_type);

		jabber_id_free(from_id);
		return;
	}

	signal_return = GPOINTER_TO_INT(purple_signal_emit_return_1(purple_connection_get_prpl(js->gc),
			"jabber-receiving-iq", js->gc, iq_type, id, from, packet));
	if (signal_return) {
		jabber_id_free(from_id);
		return;
	}

	/* First, lets see if a special callback got registered */
	if(type == JABBER_IQ_RESULT || type == JABBER_IQ_ERROR) {
		jcd = g_hash_table_lookup(js->iq_callbacks, id);
		if (jcd) {
			if (does_reply_from_match_request_to(js, jcd->to, from_id)) {
				jcd->callback(js, from, type, id, packet, jcd->data);
				jabber_iq_remove_callback_by_id(js, id);
				jabber_id_free(from_id);
				return;
			} else {
				char *expected_to;

				if (jcd->to) {
					expected_to = jabber_id_get_full_jid(jcd->to);
				} else {
					expected_to = jabber_id_get_bare_jid(js->user);
				}

				purple_debug_error("jabber", "Got a result iq with id %s from %s instead of expected %s!\n", id, from ? from : "(null)", expected_to);

				g_free(expected_to);
			}
		}
	}

	/*
	 * Apparently not, so let's see if we have a pre-defined handler
	 * or if an outside plugin is interested.
	 */
	if(child && (xmlns = purple_xmlnode_get_namespace(child))) {
		char *key = g_strdup_printf("%s %s", child->name, xmlns);
		JabberIqHandler *jih = g_hash_table_lookup(iq_handlers, key);
		int signal_ref = GPOINTER_TO_INT(g_hash_table_lookup(signal_iq_handlers, key));
		g_free(key);

		if (signal_ref > 0) {
			signal_return = GPOINTER_TO_INT(purple_signal_emit_return_1(purple_connection_get_prpl(js->gc), "jabber-watched-iq",
					js->gc, iq_type, id, from, child));
			if (signal_return) {
				jabber_id_free(from_id);
				return;
			}
		}

		if(jih) {
			jih(js, from, type, id, child);
			jabber_id_free(from_id);
			return;
		}
	}

	purple_debug_misc("jabber", "Unhandled IQ with id %s\n", id);

	/* If we get here, send the default error reply mandated by XMPP-CORE */
	if(type == JABBER_IQ_SET || type == JABBER_IQ_GET) {
		JabberIq *iq = jabber_iq_new(js, JABBER_IQ_ERROR);

		purple_xmlnode_free(iq->node);
		iq->node = purple_xmlnode_copy(packet);
		if (from) {
			purple_xmlnode_set_attrib(iq->node, "to", from);
			purple_xmlnode_remove_attrib(iq->node, "from");
		}

		purple_xmlnode_set_attrib(iq->node, "type", "error");
		error = purple_xmlnode_new_child(iq->node, "error");
		purple_xmlnode_set_attrib(error, "type", "cancel");
		purple_xmlnode_set_attrib(error, "code", "501");
		x = purple_xmlnode_new_child(error, "feature-not-implemented");
		purple_xmlnode_set_namespace(x, NS_XMPP_STANZAS);

		jabber_iq_send(iq);
	}

	jabber_id_free(from_id);
}
/**
 * \fn xmlnode_received_cb
 * \brief Reacts to requests and receipts
 */
static void
xmlnode_received_cb(PurpleConnection *gc, xmlnode **packet, gpointer null)
{
	if(*packet != NULL)
	{
		if(strcmp((*packet)->name, "message") == 0)
		{
			#ifdef DEBUG
			printf("got message\n");
			#endif

			xmlnode* nodeRequest = xmlnode_get_child (*packet, "request");

			const char* strFrom	= xmlnode_get_attrib(*packet , "from");

			//Answer to an request and verify namespace
			if(nodeRequest)
			{
				#ifdef DEBUG
				printf("got request\n");
				#endif

				const char* strId 	= xmlnode_get_attrib(*packet , "id");

				const char* strNS = xmlnode_get_namespace(nodeRequest);

				if(strcmp(strNS, "urn:xmpp:receipts") == 0)
				{
					xmlnode *message = xmlnode_new("message");
					xmlnode_set_attrib(message, "to", strFrom);
					
					xmlnode *received = xmlnode_new_child(message, "received");
					xmlnode_set_namespace(received, "urn:xmpp:receipts");
					
					xmlnode_set_attrib(received, "id", strId);

					purple_signal_emit(purple_connection_get_prpl(gc), "jabber-sending-xmlnode", gc, &message);
					
					if (message != NULL)
						xmlnode_free(message);
				}
			}
			//Find incoming receipt and call the display-function
			xmlnode* nodeReceived = xmlnode_get_child (*packet, "received");
			if(nodeReceived)
			{
				#ifdef DEBUG
				printf("got received\n");
				#endif

				const char* strNS 	= xmlnode_get_namespace(nodeReceived);
				const char* strId 	= xmlnode_get_attrib(nodeReceived , "id");

				if (strcmp(strNS, "urn:xmpp:receipts") == 0)
				{
					display_message_receipt(strId);
				}
			}
		}
	}
}