aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--protocols/jabber/iq.c2
-rw-r--r--protocols/jabber/jabber.c28
-rw-r--r--protocols/jabber/jabber.h51
-rw-r--r--protocols/jabber/jabber_util.c32
-rw-r--r--protocols/jabber/presence.c20
-rw-r--r--protocols/msn/msn.c9
-rw-r--r--protocols/nogaim.c2
7 files changed, 88 insertions, 56 deletions
diff --git a/protocols/jabber/iq.c b/protocols/jabber/iq.c
index fbb4a38b..5c108379 100644
--- a/protocols/jabber/iq.c
+++ b/protocols/jabber/iq.c
@@ -106,7 +106,7 @@ xt_status jabber_pkt_iq( struct xt_node *node, gpointer data )
node = node->next;
}
- presence_announce( gc );
+ account_online( gc );
}
else if( strcmp( type, "result" ) == 0 && orig )
{
diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c
index c8525db5..b3199cde 100644
--- a/protocols/jabber/jabber.c
+++ b/protocols/jabber/jabber.c
@@ -110,6 +110,7 @@ static void jabber_close( struct gaim_connection *gc )
xt_free_node( jd->node_cache );
xt_free( jd->xt );
+ g_free( jd->away_message );
g_free( jd->username );
g_free( jd );
}
@@ -127,23 +128,30 @@ static int jabber_send_im( struct gaim_connection *gc, char *who, char *message,
return st;
}
-/* TODO: For away state handling, implement some list like the one for MSN. */
static GList *jabber_away_states( struct gaim_connection *gc )
{
- GList *l = NULL;
+ static GList *l = NULL;
+ int i;
- l = g_list_append( l, (void*) "Online" );
- l = g_list_append( l, (void*) "Away" );
- l = g_list_append( l, (void*) "Extended Away" );
- l = g_list_append( l, (void*) "Do Not Disturb" );
+ if( l == NULL )
+ for( i = 0; jabber_away_state_list[i].full_name; i ++ )
+ l = g_list_append( l, (void*) jabber_away_state_list[i].full_name );
- return( l );
+ return l;
}
-static void jabber_set_away( struct gaim_connection *gc, char *state, char *message )
+static void jabber_set_away( struct gaim_connection *gc, char *state_txt, char *message )
{
- /* For now let's just always set state to "away" and send the message, if available. */
- presence_send( gc, NULL, g_strcasecmp( state, "Online" ) == 0 ? NULL : "away", message );
+ struct jabber_data *jd = gc->proto_data;
+ struct jabber_away_state *state;
+
+ /* Save all this info. We need it, for example, when changing the priority setting. */
+ state = (void *) jabber_away_state_by_name( state_txt );
+ jd->away_state = state ? state : (void *) jabber_away_state_list; /* Fall back to "Away" if necessary. */
+ g_free( jd->away_message );
+ jd->away_message = ( message && *message ) ? g_strdup( message ) : NULL;
+
+ presence_send( gc, NULL, jd->away_state->code, jd->away_message );
}
static void jabber_keepalive( struct gaim_connection *gc )
diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h
index c2d3867e..29cf6a84 100644
--- a/protocols/jabber/jabber.h
+++ b/protocols/jabber/jabber.h
@@ -38,6 +38,33 @@ typedef enum
JFLAG_WAIT_BIND = 16, /* ... for <bind> tag. */
} jabber_flags_t;
+struct jabber_data
+{
+ struct gaim_connection *gc;
+
+ int fd;
+ void *ssl;
+ char *txq;
+ int tx_len;
+ int r_inpa, w_inpa;
+
+ struct xt_parser *xt;
+ jabber_flags_t flags;
+
+ char *username; /* USERNAME@server */
+ char *server; /* username@SERVER -=> server/domain, not hostname */
+ struct jabber_away_state *away_state;
+ char *away_message;
+
+ struct xt_node *node_cache;
+};
+
+struct jabber_away_state
+{
+ char code[5];
+ char *full_name;
+};
+
/* iq.c */
xt_status jabber_pkt_iq( struct xt_node *node, gpointer data );
int jabber_start_iq_auth( struct gaim_connection *gc );
@@ -47,7 +74,6 @@ xt_status jabber_pkt_message( struct xt_node *node, gpointer data );
/* presence.c */
xt_status jabber_pkt_presence( struct xt_node *node, gpointer data );
-int presence_announce( struct gaim_connection *gc );
int presence_send( struct gaim_connection *gc, char *to, char *show, char *status );
/* jabber_util.c */
@@ -56,6 +82,10 @@ char *set_eval_tls( set_t *set, char *value );
struct xt_node *jabber_make_packet( char *name, char *type, char *to, struct xt_node *children );
void jabber_cache_packet( struct gaim_connection *gc, struct xt_node *node );
struct xt_node *jabber_packet_from_cache( struct gaim_connection *gc, char *id );
+const struct jabber_away_state *jabber_away_state_by_code( char *code );
+const struct jabber_away_state *jabber_away_state_by_name( char *name );
+
+extern const struct jabber_away_state jabber_away_state_list[];
/* io.c */
int jabber_write_packet( struct gaim_connection *gc, struct xt_node *node );
@@ -70,23 +100,4 @@ xt_status sasl_pkt_challenge( struct xt_node *node, gpointer data );
xt_status sasl_pkt_result( struct xt_node *node, gpointer data );
gboolean sasl_supported( struct gaim_connection *gc );
-struct jabber_data
-{
- struct gaim_connection *gc;
-
- int fd;
- void *ssl;
- char *txq;
- int tx_len;
- int r_inpa, w_inpa;
-
- struct xt_parser *xt;
- jabber_flags_t flags;
-
- char *username; /* USERNAME@server */
- char *server; /* username@SERVER -=> server/domain, not hostname */
-
- struct xt_node *node_cache;
-};
-
#endif
diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c
index 88b9e55d..21df5126 100644
--- a/protocols/jabber/jabber_util.c
+++ b/protocols/jabber/jabber_util.c
@@ -91,3 +91,35 @@ struct xt_node *jabber_packet_from_cache( struct gaim_connection *gc, char *id )
return node;
}
+
+const struct jabber_away_state jabber_away_state_list[] =
+{
+ { "away", "Away" },
+ { "chat", "Free for Chat" },
+ { "dnd", "Do not Disturb" },
+ { "xa", "Extended Away" },
+ { "", "Online" },
+ { "", NULL }
+};
+
+const struct jabber_away_state *jabber_away_state_by_code( char *code )
+{
+ int i;
+
+ for( i = 0; jabber_away_state_list[i].full_name; i ++ )
+ if( g_strcasecmp( jabber_away_state_list[i].code, code ) == 0 )
+ return jabber_away_state_list + i;
+
+ return NULL;
+}
+
+const struct jabber_away_state *jabber_away_state_by_name( char *name )
+{
+ int i;
+
+ for( i = 0; jabber_away_state_list[i].full_name; i ++ )
+ if( g_strcasecmp( jabber_away_state_list[i].full_name, name ) == 0 )
+ return jabber_away_state_list + i;
+
+ return NULL;
+}
diff --git a/protocols/jabber/presence.c b/protocols/jabber/presence.c
index 75e8786c..18ce969b 100644
--- a/protocols/jabber/presence.c
+++ b/protocols/jabber/presence.c
@@ -53,31 +53,13 @@ xt_status jabber_pkt_presence( struct xt_node *node, gpointer data )
return XT_HANDLED;
}
-/* Send the <presence/> tag that finalizes the whole login process, from here
- we'll actually show up as online to our buddies. */
-int presence_announce( struct gaim_connection *gc )
-{
- struct xt_node *node;
- int st;
-
- node = jabber_make_packet( "presence", NULL, NULL, NULL );
-
- st = jabber_write_packet( gc, node );
-
- if( st )
- account_online( gc );
-
- xt_free_node( node );
- return st;
-}
-
int presence_send( struct gaim_connection *gc, char *to, char *show, char *status )
{
struct xt_node *node;
int st;
node = jabber_make_packet( "presence", NULL, to, NULL );
- if( show )
+ if( show && *show )
xt_add_child( node, xt_new_node( "show", show, NULL ) );
if( status )
xt_add_child( node, xt_new_node( "status", status, NULL ) );
diff --git a/protocols/msn/msn.c b/protocols/msn/msn.c
index 01b011c7..d36d861f 100644
--- a/protocols/msn/msn.c
+++ b/protocols/msn/msn.c
@@ -182,13 +182,14 @@ static int msn_send_im( struct gaim_connection *gc, char *who, char *message, in
static GList *msn_away_states( struct gaim_connection *gc )
{
- GList *l = NULL;
+ static GList *l = NULL;
int i;
- for( i = 0; msn_away_state_list[i].number > -1; i ++ )
- l = g_list_append( l, (void*) msn_away_state_list[i].name );
+ if( l == NULL )
+ for( i = 0; msn_away_state_list[i].number > -1; i ++ )
+ l = g_list_append( l, (void*) msn_away_state_list[i].name );
- return( l );
+ return l;
}
static char *msn_get_status_string( struct gaim_connection *gc, int number )
diff --git a/protocols/nogaim.c b/protocols/nogaim.c
index ec87ccd5..36461b32 100644
--- a/protocols/nogaim.c
+++ b/protocols/nogaim.c
@@ -1018,8 +1018,6 @@ int bim_set_away( struct gaim_connection *gc, char *away )
gc->acc->prpl->set_away( gc, GAIM_AWAY_CUSTOM, away );
}
- g_list_free( ms );
-
return( 1 );
}