diff options
-rw-r--r-- | protocols/nogaim.c | 61 | ||||
-rw-r--r-- | protocols/nogaim.h | 13 | ||||
-rw-r--r-- | user.c | 2 | ||||
-rw-r--r-- | user.h | 2 |
4 files changed, 63 insertions, 15 deletions
diff --git a/protocols/nogaim.c b/protocols/nogaim.c index fd445324..710b7645 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -505,33 +505,70 @@ void imcb_buddy_nick_hint( struct im_connection *ic, char *handle, char *nick ) } } -/* prpl.c */ -struct show_got_added_data +struct imcb_ask_cb_data { struct im_connection *ic; char *handle; }; -void show_got_added_no( void *data ) +static void imcb_ask_auth_cb_no( void *data ) { - g_free( ((struct show_got_added_data*)data)->handle ); + struct imcb_ask_cb_data *cbd = data; + + cbd->ic->acc->prpl->auth_deny( cbd->ic, cbd->handle ); + + g_free( cbd->handle ); + g_free( cbd ); +} + +static void imcb_ask_auth_cb_yes( void *data ) +{ + struct imcb_ask_cb_data *cbd = data; + + cbd->ic->acc->prpl->auth_allow( cbd->ic, cbd->handle ); + + g_free( cbd->handle ); + g_free( cbd ); +} + +void imcb_ask_auth( struct im_connection *ic, const char *handle, const char *realname ) +{ + struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 ); + char *s, *realname_ = NULL; + + if( realname != NULL ) + realname_ = g_strdup_printf( " (%s)", realname ); + + s = g_strdup_printf( "The user %s%s wants to add you to his/her buddy list.", + handle, realname_ ?: "" ); + + g_free( realname_ ); + + data->ic = ic; + data->handle = g_strdup( handle ); + query_add( ic->irc, ic, s, imcb_ask_auth_cb_yes, imcb_ask_auth_cb_no, data ); +} + + +static void imcb_ask_add_cb_no( void *data ) +{ + g_free( ((struct imcb_ask_cb_data*)data)->handle ); g_free( data ); } -void show_got_added_yes( void *data ) +static void imcb_ask_add_cb_yes( void *data ) { - struct show_got_added_data *sga = data; + struct imcb_ask_cb_data *cbd = data; - sga->ic->acc->prpl->add_buddy( sga->ic, sga->handle, NULL ); - /* imcb_add_buddy( sga->ic, NULL, sga->handle, sga->handle ); */ + cbd->ic->acc->prpl->add_buddy( cbd->ic, cbd->handle, NULL ); - return show_got_added_no( data ); + return imcb_ask_add_cb_no( data ); } -void imcb_ask_add( struct im_connection *ic, char *handle, const char *realname ) +void imcb_ask_add( struct im_connection *ic, const char *handle, const char *realname ) { - struct show_got_added_data *data = g_new0( struct show_got_added_data, 1 ); + struct imcb_ask_cb_data *data = g_new0( struct imcb_ask_cb_data, 1 ); char *s; /* TODO: Make a setting for this! */ @@ -542,7 +579,7 @@ void imcb_ask_add( struct im_connection *ic, char *handle, const char *realname data->ic = ic; data->handle = g_strdup( handle ); - query_add( ic->irc, ic, s, show_got_added_yes, show_got_added_no, data ); + query_add( ic->irc, ic, s, imcb_ask_add_cb_yes, imcb_ask_add_cb_no, data ); } diff --git a/protocols/nogaim.h b/protocols/nogaim.h index ddfff07e..1e5df503 100644 --- a/protocols/nogaim.h +++ b/protocols/nogaim.h @@ -223,6 +223,10 @@ struct prpl { /* Mainly for AOL, since they think "Bung hole" == "Bu ngho le". *sigh* * - Most protocols will just want to set this to g_strcasecmp().*/ int (* handle_cmp) (const char *who1, const char *who2); + + /* Implement these callbacks if you want to use imcb_ask_auth() */ + void (* auth_allow) (struct im_connection *, const char *who); + void (* auth_deny) (struct im_connection *, const char *who); }; /* im_api core stuff. */ @@ -251,13 +255,20 @@ G_MODULE_EXPORT void imc_logout( struct im_connection *ic, int allow_reconnect ) G_MODULE_EXPORT void imcb_log( struct im_connection *ic, char *format, ... ) G_GNUC_PRINTF( 2, 3 ); /* To tell the user an error, ie. before logging out when an error occurs. */ G_MODULE_EXPORT void imcb_error( struct im_connection *ic, char *format, ... ) G_GNUC_PRINTF( 2, 3 ); + /* To ask a your about something. * - 'msg' is the question. * - 'data' can be your custom struct - it will be passed to the callbacks. * - 'doit' or 'dont' will be called depending of the answer of the user. */ G_MODULE_EXPORT void imcb_ask( struct im_connection *ic, char *msg, void *data, query_callback doit, query_callback dont ); -G_MODULE_EXPORT void imcb_ask_add( struct im_connection *ic, char *handle, const char *realname ); + +/* Two common questions you may want to ask: + * - X added you to his contact list, allow? + * - X is not in your contact list, want to add? + */ +G_MODULE_EXPORT void imcb_ask_auth( struct im_connection *ic, const char *handle, const char *realname ); +G_MODULE_EXPORT void imcb_ask_add( struct im_connection *ic, const char *handle, const char *realname ); /* Buddy management */ /* This function should be called for each handle which are visible to the @@ -140,7 +140,7 @@ user_t *user_find( irc_t *irc, char *nick ) return( NULL ); } -user_t *user_findhandle( struct im_connection *ic, char *handle ) +user_t *user_findhandle( struct im_connection *ic, const char *handle ) { user_t *u; char *nick; @@ -55,7 +55,7 @@ typedef struct __USER user_t *user_add( struct irc *irc, char *nick ); int user_del( irc_t *irc, char *nick ); G_MODULE_EXPORT user_t *user_find( irc_t *irc, char *nick ); -G_MODULE_EXPORT user_t *user_findhandle( struct im_connection *ic, char *handle ); +G_MODULE_EXPORT user_t *user_findhandle( struct im_connection *ic, const char *handle ); void user_rename( irc_t *irc, char *oldnick, char *newnick ); #endif /* __USER_H__ */ |