Changeset 0ac1a375 for protocols/purple


Ignore:
Timestamp:
2009-11-25T00:19:45Z (10 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
e5d8d21
Parents:
45a19e5
Message:

Added enough code to handle one class of queries (action-based), enough
to make the "Please accept this SSL certificate" question work.

Need to extend the BitlBee API a bit to *really* support this well though
(yes/no is not enough).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/purple/purple.c

    r45a19e5 r0ac1a375  
    2424#include "bitlbee.h"
    2525
     26#include <stdarg.h>
     27
    2628#include <glib.h>
    2729#include <purple.h>
    2830
    2931GSList *purple_connections;
     32
     33/* This makes me VERY sad... :-( But some libpurple callbacks come in without
     34   any context so this is the only way to get that. Don't want to support
     35   libpurple in daemon mode anyway. */
     36static irc_t *local_irc;
    3037
    3138static struct im_connection *purple_ic_by_pa( PurpleAccount *pa )
     
    134141{
    135142        struct im_connection *ic = imcb_new( acc );
    136         static void *irc_check = NULL;
    137143        PurpleAccount *pa;
    138144       
    139         if( irc_check != NULL && irc_check != acc->irc )
    140         {
    141                 irc_usermsg( acc->irc, "Daemon mode detected. Do *not* try to use libpurple in daemon mode! Please use inetd or ForkDaemon mode instead." );
     145        if( local_irc != NULL && local_irc != acc->irc )
     146        {
     147                irc_usermsg( acc->irc, "Daemon mode detected. Do *not* try to use libpurple in daemon mode! "
     148                                       "Please use inetd or ForkDaemon mode instead." );
    142149                return;
    143150        }
    144         irc_check = acc->irc;
     151        local_irc = acc->irc;
    145152       
    146153        /* For now this is needed in the _connected() handlers if using
     
    407414};
    408415
     416struct prplcb_request_action_data
     417{
     418        void *user_data, *bee_data;
     419        PurpleRequestActionCb yes, no;
     420        int yes_i, no_i;
     421};
     422
     423static void prplcb_request_action_yes( void *data )
     424{
     425        struct prplcb_request_action_data *pqad = data;
     426       
     427        pqad->yes( pqad->user_data, pqad->yes_i );
     428        g_free( pqad );
     429}
     430
     431static void prplcb_request_action_no( void *data )
     432{
     433        struct prplcb_request_action_data *pqad = data;
     434       
     435        pqad->no( pqad->user_data, pqad->no_i );
     436        g_free( pqad );
     437}
     438
     439static void *prplcb_request_action( const char *title, const char *primary, const char *secondary,
     440                                    int default_action, PurpleAccount *account, const char *who,
     441                                    PurpleConversation *conv, void *user_data, size_t action_count,
     442                                    va_list actions )
     443{
     444        struct prplcb_request_action_data *pqad;
     445        int i;
     446        char *q;
     447       
     448        pqad = g_new0( struct prplcb_request_action_data, 1 );
     449       
     450        for( i = 0; i < action_count; i ++ )
     451        {
     452                char *caption;
     453                void *fn;
     454               
     455                caption = va_arg( actions, char* );
     456                fn = va_arg( actions, void* );
     457               
     458                if( strcmp( caption, "Accept" ) == 0 )
     459                {
     460                        pqad->yes = fn;
     461                        pqad->yes_i = i;
     462                }
     463                else if( strcmp( caption, "Reject" ) == 0 )
     464                {
     465                        pqad->no = fn;
     466                        pqad->no_i = i;
     467                }
     468        }
     469       
     470        pqad->user_data = user_data;
     471       
     472        q = g_strdup_printf( "Request: %s\n\n%s\n\n%s", title, primary, secondary );
     473        pqad->bee_data = query_add( local_irc, purple_ic_by_pa( account ), q,
     474                prplcb_request_action_yes, prplcb_request_action_no, pqad );
     475       
     476        g_free( q );
     477}
     478
     479static PurpleRequestUiOps bee_request_uiops =
     480{
     481        NULL,
     482        NULL,
     483        prplcb_request_action,
     484        NULL,
     485        NULL,
     486        NULL,
     487        NULL,
     488};
     489
    409490static void prplcb_debug_print( PurpleDebugLevel level, const char *category, const char *arg_s )
    410491{
     
    446527        purple_connections_set_ui_ops( &bee_conn_uiops );
    447528        purple_conversations_set_ui_ops( &bee_conv_uiops );
     529        purple_request_set_ui_ops( &bee_request_uiops );
    448530        //purple_debug_set_ui_ops( &bee_debug_uiops );
    449531}
Note: See TracChangeset for help on using the changeset viewer.