Re-request Authorization with libpurple?

michaelcbrook at msn.com michaelcbrook at msn.com
Wed Aug 12 11:47:38 EDT 2009


On Wed, 2009-08-12 at 07:56 -0700, Paul Aurich wrote:
> And michaelcbrook at msn.com spoke on 08/12/2009 01:11 AM, saying:
> > On Wed, 2009-08-12 at 00:52 -0700, Paul Aurich wrote:
> >> On Aug 12, 2009, at 00:39, michaelcbrook at msn.com wrote:
> >>> Thinking this was another casting issue, I tried casting the type for
> >>> the callback to PurpleCallback, since that looks like the correct type
> >>> in libpurple's source code, but I still get the same error that  
> >>> there's
> >>> too many arguments:
> >>>
> >>> ((PurpleCallback)menu_action->callback)((PurpleBlistNode *)buddy);
> >>
> >> It doesn't look like it's documented anywhere, but the function  
> >> prototype that you want to be matching is:
> >> 	void callback(PurpleBlistNode*, gpointer cb_data)
> >>
> >> See, for example, gtkutils.c:menu_action_cb:
> >> 	static void
> >> 	menu_action_cb(GtkMenuItem *item, gpointer object)
> >> 	{
> >> 	    gpointer data;
> >> 	    void (*callback)(gpointer, gpointer);
> >>
> >> 	    callback = g_object_get_data(G_OBJECT(item), "purplecallback");
> >> 	    data = g_object_get_data(G_OBJECT(item), "purplecallbackdata");
> >>
> >> 	    if (callback)
> >> 	        callback(object, data);
> >> 	}
> >>
> >> (in your case, you'd have (PurpleBlistNode*)buddy and menu_action->data)
> >>
> >> ~Paul
> >>
> >>
> > I think I get what you're saying, I gave the callback function a second
> > argument for menu_action->data, but the compiler still says that I have
> > too many arguments...why is it telling me this?
> > 
> > Here's my callback at the moment:
> > menu_action->callback(((PurpleBlistNode *)buddy), menu_action->data);
> 
> You need to cast the callback (which is stored as a PurpleCallback, which
> is just a generic type) to void (*callback)(gpointer, gointer) (like the
> code above is doing -- although it retrieves the callback from a gobject)
> 
> > 
> > -Michael
> > 
> 
> ~Paul
> 
Ahh I got it working now.  Thanks so much!  I really appreciate it.
Here's my working code now for anyone who's interested...

gboolean re_request_buddy(gpointer data)
{

PurpleBuddy *buddy = data;

  if (buddy!=NULL)
  {

  printf("Re-requesting authorization for %s (%s)...\n",
purple_buddy_get_name(buddy),
purple_account_get_protocol_id(purple_buddy_get_account(buddy)));

  PurplePluginProtocolInfo *prpl_info =
PURPLE_PLUGIN_PROTOCOL_INFO(purple_account_get_connection(purple_buddy_get_account(buddy))->prpl);

    if (prpl_info && prpl_info->blist_node_menu)
    {

    GList *menu = prpl_info->blist_node_menu((PurpleBlistNode *)buddy);

      while (menu)
      {

      PurpleMenuAction *menu_action = menu->data;

        if (g_str_equal(menu_action->label, "Re-request Authorization"))
        {

        printf("Found re-request menu option...\n");

        gpointer data;

        void (*callback)(gpointer, gpointer);
        callback = (void *)menu_action->callback;
        data = menu_action->data;

          if (callback)
          {
          callback(((PurpleBlistNode *)buddy), data);
          printf("Re-requested authorization\n");
          }

        }

      /* Destroy the data in the linked list */
      purple_menu_action_free(menu_action);
      /* Remove this node from the list */
      menu = g_list_delete_link(menu, menu);

      }

    }
    else
    {
    printf("Re-request authorization failed because the buddy's menu
does not exist for %s (%s)\n", purple_buddy_get_name(buddy),
purple_account_get_protocol_id(purple_buddy_get_account(buddy)));
    }

  }
  else
  {
  printf("Re-request authorization failed because buddy does not exist
\n");
  }

}

-Michael




More information about the Support mailing list