diff options
| author | Wilmer van der Gaast <wilmer@gaast.net> | 2006-10-02 19:46:57 +0200 | 
|---|---|---|
| committer | Wilmer van der Gaast <wilmer@gaast.net> | 2006-10-02 19:46:57 +0200 | 
| commit | 995913b4be70be6e07b8aa7661ac639e5fc0d6e7 (patch) | |
| tree | 6af35350d96cfee47a57790eb9561638fb49ad7b /protocols | |
| parent | 501b4e06244dbd333ee207ceade37592482e0fe7 (diff) | |
Added some error handling for the (not very complete yet) privacy list code.
Diffstat (limited to 'protocols')
| -rw-r--r-- | protocols/jabber/iq.c | 53 | ||||
| -rw-r--r-- | protocols/jabber/jabber.c | 19 | ||||
| -rw-r--r-- | protocols/jabber/jabber.h | 2 | 
3 files changed, 65 insertions, 9 deletions
| diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c index 0411d4ad..b77ee9ff 100644 --- a/protocols/jabber/iq.c +++ b/protocols/jabber/iq.c @@ -147,6 +147,7 @@ xt_status jabber_pkt_iq( struct xt_node *node, gpointer data )  	else if( strcmp( type, "result" ) == 0 && orig )  	{  		struct xt_node *c; +		  		if( !( jd->flags & JFLAG_AUTHENTICATED ) &&  		    ( c = xt_find_node( orig->children, "query" ) ) &&  		    ( c = xt_find_node( c->children, "username" ) ) && @@ -198,6 +199,7 @@ xt_status jabber_pkt_iq( struct xt_node *node, gpointer data )  	else if( strcmp( type, "error" ) == 0 )  	{  		if( !( jd->flags & JFLAG_AUTHENTICATED ) && +		      orig &&  		    ( c = xt_find_node( orig->children, "query" ) ) &&  		    ( c = xt_find_node( c->children, "username" ) ) &&  		    c->text_len ) @@ -206,11 +208,32 @@ xt_status jabber_pkt_iq( struct xt_node *node, gpointer data )  			signoff( gc );  			return XT_ABORT;  		} -		else if( orig && -		         ( c = xt_find_node( orig->children, "query" ) ) && -		         ( c = xt_find_node( c->children, "active" ) ) ) +		else if( ( xmlns && strcmp( xmlns, "jabber:iq:privacy" ) == 0 ) || +		         ( orig && +		           ( c = xt_find_node( orig->children, "query" ) ) && +		           ( s = xt_find_attr( c, "xmlns" ) ) && +		           strcmp( s, "jabber:iq:privacy" ) == 0 ) )  		{ -			serv_got_crap( gc, "Error while activating privacy list, maybe it doesn't exist" ); +			/* All errors related to privacy lists. */ +			if( ( c = xt_find_node( node->children, "error" ) ) == NULL ) +			{ +				hide_login_progress_error( gc, "Received malformed error packet" ); +				signoff( gc ); +				return XT_ABORT; +			} +			 +			if( xt_find_node( c->children, "item-not-found" ) ) +			{ +				serv_got_crap( gc, "Error while activating privacy list, maybe it doesn't exist" ); +				/* Should I do anything else here? */ +			} +			else if( xt_find_node( c->children, "feature-not-implemented" ) ) +			{ +				jd->flags |= JFLAG_PRIVACY_BROKEN; +				/* Probably there's no need to inform the user. +				   We can do that if the user ever tries to use +				   the block/allow commands. */ +			}  		}  	} @@ -326,9 +349,9 @@ int jabber_get_privacy( struct gaim_connection *gc )  	xt_add_attr( node, "xmlns", "jabber:iq:privacy" );  	node = jabber_make_packet( "iq", "get", NULL, node ); +	jabber_cache_packet( gc, node );  	st = jabber_write_packet( gc, node ); -	xt_free_node( node );  	return st;  } @@ -346,3 +369,23 @@ int jabber_set_privacy( struct gaim_connection *gc, char *name )  	return jabber_write_packet( gc, node );  } + +char *set_eval_privacy_list( set_t *set, char *value ) +{ +	account_t *acc = set->data; +	struct jabber_data *jd = acc->gc->proto_data; +	 +	if( jd->flags & JFLAG_PRIVACY_BROKEN ) +	{ +		serv_got_crap( acc->gc, "Privacy lists not supported by this server" ); +		return NULL; +	} +	 +	/* If we're on-line, return NULL and let the server decide if the +	   chosen list is valid. If we're off-line, just accept it and we'll +	   see later (when we connect). */ +	if( acc->gc ) +		jabber_set_privacy( acc->gc, value ); +	 +	return acc->gc ? NULL : value; +} diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index 8ec6b70c..39d93d16 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -41,8 +41,7 @@ static void jabber_acc_init( account_t *acc )  	s = set_add( &acc->set, "priority", "0", set_eval_priority, acc ); -	s = set_add( &acc->set, "privacy_list", NULL, NULL, acc ); -	/* TODO: Add evaluator. */ +	s = set_add( &acc->set, "privacy_list", NULL, set_eval_privacy_list, acc );  	s = set_add( &acc->set, "resource", "BitlBee", NULL, acc );  	s->flags |= ACC_SET_OFFLINE_ONLY; @@ -231,12 +230,24 @@ static void jabber_keepalive( struct gaim_connection *gc )  static void jabber_add_permit( struct gaim_connection *gc, char *who )  { -	presence_send_request( gc, who, "subscribed" ); +	struct jabber_data *jd = gc->proto_data; +	 +	if( jd->flags & JFLAG_PRIVACY_BROKEN ) +	{ +		serv_got_crap( gc, "Privacy lists not supported by this server" ); +		return; +	}  }  static void jabber_rem_permit( struct gaim_connection *gc, char *who )  { -	presence_send_request( gc, who, "unsubscribed" ); +	struct jabber_data *jd = gc->proto_data; +	 +	if( jd->flags & JFLAG_PRIVACY_BROKEN ) +	{ +		serv_got_crap( gc, "Privacy lists not supported by this server" ); +		return; +	}  }  /* XMPP doesn't have both a block- and and allow-list, so these two functions diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index 1ee02d3e..2c7cadd1 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -36,6 +36,7 @@ typedef enum  	JFLAG_STREAM_RESTART = 4,	/* Set when we want to restart the stream (after SASL or TLS). */  	JFLAG_WAIT_SESSION = 8,		/* Set if we sent a <session> tag and need a reply before we continue. */  	JFLAG_WAIT_BIND = 16,		/* ... for <bind> tag. */ +	JFLAG_PRIVACY_BROKEN = 32,	/* Or just not supported, actually. */  } jabber_flags_t;  struct jabber_data @@ -82,6 +83,7 @@ int jabber_add_to_roster( struct gaim_connection *gc, char *handle, char *name )  int jabber_remove_from_roster( struct gaim_connection *gc, char *handle );  int jabber_get_privacy( struct gaim_connection *gc );  int jabber_set_privacy( struct gaim_connection *gc, char *name ); +char *set_eval_privacy_list( set_t *set, char *value );  /* message.c */  xt_status jabber_pkt_message( struct xt_node *node, gpointer data ); | 
