diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2006-05-23 09:45:14 +0200 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2006-05-23 09:45:14 +0200 | 
| commit | 226fce105c1189bde1aa321b494494d49b463e90 (patch) | |
| tree | c0064ebc75d0b100d91ac53a8bfcc6f503dcbafa /protocols/nogaim.c | |
| parent | 73cf7fd5f066d3c0720f58af840affa3e61bad12 (diff) | |
Some changes for im_api. (bim_* functions)
Diffstat (limited to 'protocols/nogaim.c')
| -rw-r--r-- | protocols/nogaim.c | 197 | 
1 files changed, 102 insertions, 95 deletions
| diff --git a/protocols/nogaim.c b/protocols/nogaim.c index 568afe33..a9b27e92 100644 --- a/protocols/nogaim.c +++ b/protocols/nogaim.c @@ -37,19 +37,6 @@  #include "nogaim.h"  #include <ctype.h> -static char *proto_away_alias[8][5] = -{ -	{ "Away from computer", "Away", "Extended away", NULL }, -	{ "NA", "N/A", "Not available", NULL }, -	{ "Busy", "Do not disturb", "DND", "Occupied", NULL }, -	{ "Be right back", "BRB", NULL }, -	{ "On the phone", "Phone", "On phone", NULL }, -	{ "Out to lunch", "Lunch", "Food", NULL }, -	{ "Invisible", "Hidden" }, -	{ NULL } -}; -static char *proto_away_alias_find( GList *gcm, char *away ); -  static int remove_chat_buddy_silent( struct conversation *b, char *handle );  GSList *connections; @@ -157,83 +144,6 @@ void nogaim_init()  GSList *get_connections() { return connections; } -int proto_away( struct gaim_connection *gc, char *away ) -{ -	GList *m, *ms; -	char *s; -	 -	if( !away ) away = ""; -	ms = m = gc->prpl->away_states( gc ); -	 -	while( m ) -	{ -		if( *away ) -		{ -			if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) -				break; -		} -		else -		{ -			if( g_strcasecmp( m->data, "Available" ) == 0 ) -				break; -			if( g_strcasecmp( m->data, "Online" ) == 0 ) -				break; -		} -		m = m->next; -	} -	 -	if( m ) -	{ -		gc->prpl->set_away( gc, m->data, *away ? away : NULL ); -	} -	else -	{ -		s = proto_away_alias_find( ms, away ); -		if( s ) -		{ -			gc->prpl->set_away( gc, s, away ); -			if( set_getint( gc->irc, "debug" ) ) -				serv_got_crap( gc, "Setting away state to %s", s ); -		} -		else -			gc->prpl->set_away( gc, GAIM_AWAY_CUSTOM, away ); -	} -	 -	g_list_free( ms ); -	 -	return( 1 ); -} - -static char *proto_away_alias_find( GList *gcm, char *away ) -{ -	GList *m; -	int i, j; -	 -	for( i = 0; *proto_away_alias[i]; i ++ ) -	{ -		for( j = 0; proto_away_alias[i][j]; j ++ ) -			if( g_strncasecmp( away, proto_away_alias[i][j], strlen( proto_away_alias[i][j] ) ) == 0 ) -				break; -		 -		if( !proto_away_alias[i][j] )	/* If we reach the end, this row */ -			continue;		/* is not what we want. Next!    */ -		 -		/* Now find an entry in this row which exists in gcm */ -		for( j = 0; proto_away_alias[i][j]; j ++ ) -		{ -			m = gcm; -			while( m ) -			{ -				if( g_strcasecmp( proto_away_alias[i][j], m->data ) == 0 ) -					return( proto_away_alias[i][j] ); -				m = m->next; -			} -		} -	} -	 -	return( NULL ); -} -  /* multi.c */  struct gaim_connection *new_gaim_conn( struct aim_user *user ) @@ -358,7 +268,7 @@ void account_online( struct gaim_connection *gc )  	/* Also necessary when we're not away, at least for some of the  	   protocols. */ -	proto_away( gc, u->away ); +	bim_set_away( gc, u->away );  }  gboolean auto_reconnect( gpointer data ) @@ -1030,24 +940,30 @@ char *set_eval_away_devoice( irc_t *irc, set_t *set, char *value )  	return( set_eval_bool( irc, set, value ) );  } -int serv_send_im( irc_t *irc, user_t *u, char *msg, int flags ) + + + +/* The plan is to not allow straight calls to prpl functions anymore, but do +   them all from some wrappers. We'll start to define some down here: */ + +int bim_buddy_msg( struct gaim_connection *gc, char *handle, char *msg, int flags )  {  	char *buf = NULL;  	int st; -	if( ( u->gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) ) +	if( ( gc->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) )  	{  		buf = escape_html( msg );  		msg = buf;  	} -	st = ((struct gaim_connection *)u->gc)->prpl->send_im( u->gc, u->handle, msg, strlen( msg ), flags ); +	st = gc->prpl->send_im( gc, handle, msg, strlen( msg ), flags );  	g_free( buf );  	return st;  } -int serv_send_chat( irc_t *irc, struct gaim_connection *gc, int id, char *msg ) +int bim_chat_msg( struct gaim_connection *gc, int id, char *msg )  {  	char *buf = NULL;  	int st; @@ -1063,3 +979,94 @@ int serv_send_chat( irc_t *irc, struct gaim_connection *gc, int id, char *msg )  	return st;  } + +static char *bim_away_alias_find( GList *gcm, char *away ); + +int bim_set_away( struct gaim_connection *gc, char *away ) +{ +	GList *m, *ms; +	char *s; +	 +	if( !away ) away = ""; +	ms = m = gc->prpl->away_states( gc ); +	 +	while( m ) +	{ +		if( *away ) +		{ +			if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 ) +				break; +		} +		else +		{ +			if( g_strcasecmp( m->data, "Available" ) == 0 ) +				break; +			if( g_strcasecmp( m->data, "Online" ) == 0 ) +				break; +		} +		m = m->next; +	} +	 +	if( m ) +	{ +		gc->prpl->set_away( gc, m->data, *away ? away : NULL ); +	} +	else +	{ +		s = bim_away_alias_find( ms, away ); +		if( s ) +		{ +			gc->prpl->set_away( gc, s, away ); +			if( set_getint( gc->irc, "debug" ) ) +				serv_got_crap( gc, "Setting away state to %s", s ); +		} +		else +			gc->prpl->set_away( gc, GAIM_AWAY_CUSTOM, away ); +	} +	 +	g_list_free( ms ); +	 +	return( 1 ); +} + +static char *bim_away_alias_list[8][5] = +{ +	{ "Away from computer", "Away", "Extended away", NULL }, +	{ "NA", "N/A", "Not available", NULL }, +	{ "Busy", "Do not disturb", "DND", "Occupied", NULL }, +	{ "Be right back", "BRB", NULL }, +	{ "On the phone", "Phone", "On phone", NULL }, +	{ "Out to lunch", "Lunch", "Food", NULL }, +	{ "Invisible", "Hidden" }, +	{ NULL } +}; + +static char *bim_away_alias_find( GList *gcm, char *away ) +{ +	GList *m; +	int i, j; +	 +	for( i = 0; *bim_away_alias_list[i]; i ++ ) +	{ +		for( j = 0; bim_away_alias_list[i][j]; j ++ ) +			if( g_strncasecmp( away, bim_away_alias_list[i][j], strlen( bim_away_alias_list[i][j] ) ) == 0 ) +				break; +		 +		if( !bim_away_alias_list[i][j] )	/* If we reach the end, this row */ +			continue;			/* is not what we want. Next!    */ +		 +		/* Now find an entry in this row which exists in gcm */ +		for( j = 0; bim_away_alias_list[i][j]; j ++ ) +		{ +			m = gcm; +			while( m ) +			{ +				if( g_strcasecmp( bim_away_alias_list[i][j], m->data ) == 0 ) +					return( bim_away_alias_list[i][j] ); +				m = m->next; +			} +		} +	} +	 +	return( NULL ); +} | 
