Changeset fa295e36 for protocols


Ignore:
Timestamp:
2009-10-10T13:39:51Z (15 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
ba16895
Parents:
e59b4f6
Message:

Added imcb_ask_auth() instead of reimplementing authorization requests
in every protocol module.

Location:
protocols
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    re59b4f6 rfa295e36  
    506506}
    507507
    508 /* prpl.c */
    509 
    510 struct show_got_added_data
     508
     509struct imcb_ask_cb_data
    511510{
    512511        struct im_connection *ic;
     
    514513};
    515514
    516 void show_got_added_no( void *data )
    517 {
    518         g_free( ((struct show_got_added_data*)data)->handle );
     515static void imcb_ask_auth_cb_no( void *data )
     516{
     517        struct imcb_ask_cb_data *cbd = data;
     518       
     519        cbd->ic->acc->prpl->auth_deny( cbd->ic, cbd->handle );
     520       
     521        g_free( cbd->handle );
     522        g_free( cbd );
     523}
     524
     525static void imcb_ask_auth_cb_yes( void *data )
     526{
     527        struct imcb_ask_cb_data *cbd = data;
     528       
     529        cbd->ic->acc->prpl->auth_allow( cbd->ic, cbd->handle );
     530       
     531        g_free( cbd->handle );
     532        g_free( cbd );
     533}
     534
     535void imcb_ask_auth( struct im_connection *ic, const char *handle, const char *realname )
     536{
     537        struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 );
     538        char *s, *realname_ = NULL;
     539       
     540        if( realname != NULL )
     541                realname_ = g_strdup_printf( " (%s)", realname );
     542       
     543        s = g_strdup_printf( "The user %s%s wants to add you to his/her buddy list.",
     544                             handle, realname_ ?: "" );
     545       
     546        g_free( realname_ );
     547       
     548        data->ic = ic;
     549        data->handle = g_strdup( handle );
     550        query_add( ic->irc, ic, s, imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, data );
     551}
     552
     553
     554static void imcb_ask_add_cb_no( void *data )
     555{
     556        g_free( ((struct imcb_ask_cb_data*)data)->handle );
    519557        g_free( data );
    520558}
    521559
    522 void show_got_added_yes( void *data )
    523 {
    524         struct show_got_added_data *sga = data;
    525        
    526         sga->ic->acc->prpl->add_buddy( sga->ic, sga->handle, NULL );
    527         /* imcb_add_buddy( sga->ic, NULL, sga->handle, sga->handle ); */
    528        
    529         return show_got_added_no( data );
    530 }
    531 
    532 void imcb_ask_add( struct im_connection *ic, char *handle, const char *realname )
    533 {
    534         struct show_got_added_data *data = g_new0( struct show_got_added_data, 1 );
     560static void imcb_ask_add_cb_yes( void *data )
     561{
     562        struct imcb_ask_cb_data *cbd = data;
     563       
     564        cbd->ic->acc->prpl->add_buddy( cbd->ic, cbd->handle, NULL );
     565       
     566        return imcb_ask_add_cb_no( data );
     567}
     568
     569void imcb_ask_add( struct im_connection *ic, const char *handle, const char *realname )
     570{
     571        struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 );
    535572        char *s;
    536573       
     
    543580        data->ic = ic;
    544581        data->handle = g_strdup( handle );
    545         query_add( ic->irc, ic, s, show_got_added_yes, show_got_added_no, data );
     582        query_add( ic->irc, ic, s, imcb_ask_add_cb_yes, imcb_ask_add_cb_no, data );
    546583}
    547584
  • protocols/nogaim.h

    re59b4f6 rfa295e36  
    224224         * - Most protocols will just want to set this to g_strcasecmp().*/
    225225        int (* handle_cmp) (const char *who1, const char *who2);
     226
     227        /* Implement these callbacks if you want to use imcb_ask_auth() */
     228        void (* auth_allow)     (struct im_connection *, const char *who);
     229        void (* auth_deny)      (struct im_connection *, const char *who);
    226230};
    227231
     
    252256/* To tell the user an error, ie. before logging out when an error occurs. */
    253257G_MODULE_EXPORT void imcb_error( struct im_connection *ic, char *format, ... ) G_GNUC_PRINTF( 2, 3 );
     258
    254259/* To ask a your about something.
    255260 * - 'msg' is the question.
     
    258263 */
    259264G_MODULE_EXPORT void imcb_ask( struct im_connection *ic, char *msg, void *data, query_callback doit, query_callback dont );
    260 G_MODULE_EXPORT void imcb_ask_add( struct im_connection *ic, char *handle, const char *realname );
     265
     266/* Two common questions you may want to ask:
     267 * - X added you to his contact list, allow?
     268 * - X is not in your contact list, want to add?
     269 */
     270G_MODULE_EXPORT void imcb_ask_auth( struct im_connection *ic, const char *handle, const char *realname );
     271G_MODULE_EXPORT void imcb_ask_add( struct im_connection *ic, const char *handle, const char *realname );
    261272
    262273/* Buddy management */
Note: See TracChangeset for help on using the changeset viewer.