Changeset 5e202b0


Ignore:
Timestamp:
2006-09-23T16:18:24Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
172a73f1
Parents:
d8e0484
Message:

Implemented a list of away states, using this for a better set_away(), and
got rid of the double <presence> tag sent because of presence_announce().

Location:
protocols
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/iq.c

    rd8e0484 r5e202b0  
    107107                }
    108108               
    109                 presence_announce( gc );
     109                account_online( gc );
    110110        }
    111111        else if( strcmp( type, "result" ) == 0 && orig )
  • protocols/jabber/jabber.c

    rd8e0484 r5e202b0  
    111111        xt_free( jd->xt );
    112112       
     113        g_free( jd->away_message );
    113114        g_free( jd->username );
    114115        g_free( jd );
     
    128129}
    129130
    130 /* TODO: For away state handling, implement some list like the one for MSN. */
    131131static GList *jabber_away_states( struct gaim_connection *gc )
    132132{
    133         GList *l = NULL;
     133        static GList *l = NULL;
     134        int i;
    134135       
    135         l = g_list_append( l, (void*) "Online" );
    136         l = g_list_append( l, (void*) "Away" );
    137         l = g_list_append( l, (void*) "Extended Away" );
    138         l = g_list_append( l, (void*) "Do Not Disturb" );
     136        if( l == NULL )
     137                for( i = 0; jabber_away_state_list[i].full_name; i ++ )
     138                        l = g_list_append( l, (void*) jabber_away_state_list[i].full_name );
    139139       
    140         return( l );
     140        return l;
    141141}
    142142
    143 static void jabber_set_away( struct gaim_connection *gc, char *state, char *message )
     143static void jabber_set_away( struct gaim_connection *gc, char *state_txt, char *message )
    144144{
    145         /* For now let's just always set state to "away" and send the message, if available. */
    146         presence_send( gc, NULL, g_strcasecmp( state, "Online" ) == 0 ? NULL : "away", message );
     145        struct jabber_data *jd = gc->proto_data;
     146        struct jabber_away_state *state;
     147       
     148        /* Save all this info. We need it, for example, when changing the priority setting. */
     149        state = (void *) jabber_away_state_by_name( state_txt );
     150        jd->away_state = state ? state : (void *) jabber_away_state_list; /* Fall back to "Away" if necessary. */
     151        g_free( jd->away_message );
     152        jd->away_message = ( message && *message ) ? g_strdup( message ) : NULL;
     153       
     154        presence_send( gc, NULL, jd->away_state->code, jd->away_message );
    147155}
    148156
  • protocols/jabber/jabber.h

    rd8e0484 r5e202b0  
    3939} jabber_flags_t;
    4040
    41 /* iq.c */
    42 xt_status jabber_pkt_iq( struct xt_node *node, gpointer data );
    43 int jabber_start_iq_auth( struct gaim_connection *gc );
    44 int jabber_get_roster( struct gaim_connection *gc );
    45 
    46 xt_status jabber_pkt_message( struct xt_node *node, gpointer data );
    47 
    48 /* presence.c */
    49 xt_status jabber_pkt_presence( struct xt_node *node, gpointer data );
    50 int presence_announce( struct gaim_connection *gc );
    51 int presence_send( struct gaim_connection *gc, char *to, char *show, char *status );
    52 
    53 /* jabber_util.c */
    54 char *set_eval_resprio( set_t *set, char *value );
    55 char *set_eval_tls( set_t *set, char *value );
    56 struct xt_node *jabber_make_packet( char *name, char *type, char *to, struct xt_node *children );
    57 void jabber_cache_packet( struct gaim_connection *gc, struct xt_node *node );
    58 struct xt_node *jabber_packet_from_cache( struct gaim_connection *gc, char *id );
    59 
    60 /* io.c */
    61 int jabber_write_packet( struct gaim_connection *gc, struct xt_node *node );
    62 int jabber_write( struct gaim_connection *gc, char *buf, int len );
    63 gboolean jabber_connected_plain( gpointer data, gint source, b_input_condition cond );
    64 gboolean jabber_start_stream( struct gaim_connection *gc );
    65 void jabber_end_stream( struct gaim_connection *gc );
    66 
    67 /* sasl.c */
    68 xt_status sasl_pkt_mechanisms( struct xt_node *node, gpointer data );
    69 xt_status sasl_pkt_challenge( struct xt_node *node, gpointer data );
    70 xt_status sasl_pkt_result( struct xt_node *node, gpointer data );
    71 gboolean sasl_supported( struct gaim_connection *gc );
    72 
    7341struct jabber_data
    7442{
     
    8654        char *username;         /* USERNAME@server */
    8755        char *server;           /* username@SERVER -=> server/domain, not hostname */
     56        struct jabber_away_state *away_state;
     57        char *away_message;
    8858       
    8959        struct xt_node *node_cache;
    9060};
    9161
     62struct jabber_away_state
     63{
     64        char code[5];
     65        char *full_name;
     66};
     67
     68/* iq.c */
     69xt_status jabber_pkt_iq( struct xt_node *node, gpointer data );
     70int jabber_start_iq_auth( struct gaim_connection *gc );
     71int jabber_get_roster( struct gaim_connection *gc );
     72
     73xt_status jabber_pkt_message( struct xt_node *node, gpointer data );
     74
     75/* presence.c */
     76xt_status jabber_pkt_presence( struct xt_node *node, gpointer data );
     77int presence_send( struct gaim_connection *gc, char *to, char *show, char *status );
     78
     79/* jabber_util.c */
     80char *set_eval_resprio( set_t *set, char *value );
     81char *set_eval_tls( set_t *set, char *value );
     82struct xt_node *jabber_make_packet( char *name, char *type, char *to, struct xt_node *children );
     83void jabber_cache_packet( struct gaim_connection *gc, struct xt_node *node );
     84struct xt_node *jabber_packet_from_cache( struct gaim_connection *gc, char *id );
     85const struct jabber_away_state *jabber_away_state_by_code( char *code );
     86const struct jabber_away_state *jabber_away_state_by_name( char *name );
     87
     88extern const struct jabber_away_state jabber_away_state_list[];
     89
     90/* io.c */
     91int jabber_write_packet( struct gaim_connection *gc, struct xt_node *node );
     92int jabber_write( struct gaim_connection *gc, char *buf, int len );
     93gboolean jabber_connected_plain( gpointer data, gint source, b_input_condition cond );
     94gboolean jabber_start_stream( struct gaim_connection *gc );
     95void jabber_end_stream( struct gaim_connection *gc );
     96
     97/* sasl.c */
     98xt_status sasl_pkt_mechanisms( struct xt_node *node, gpointer data );
     99xt_status sasl_pkt_challenge( struct xt_node *node, gpointer data );
     100xt_status sasl_pkt_result( struct xt_node *node, gpointer data );
     101gboolean sasl_supported( struct gaim_connection *gc );
     102
    92103#endif
  • protocols/jabber/jabber_util.c

    rd8e0484 r5e202b0  
    9292        return node;
    9393}
     94
     95const struct jabber_away_state jabber_away_state_list[] =
     96{
     97        { "away",  "Away" },
     98        { "chat",  "Free for Chat" },
     99        { "dnd",   "Do not Disturb" },
     100        { "xa",    "Extended Away" },
     101        { "",      "Online" },
     102        { "",      NULL }
     103};
     104
     105const struct jabber_away_state *jabber_away_state_by_code( char *code )
     106{
     107        int i;
     108       
     109        for( i = 0; jabber_away_state_list[i].full_name; i ++ )
     110                if( g_strcasecmp( jabber_away_state_list[i].code, code ) == 0 )
     111                        return jabber_away_state_list + i;
     112       
     113        return NULL;
     114}
     115
     116const struct jabber_away_state *jabber_away_state_by_name( char *name )
     117{
     118        int i;
     119       
     120        for( i = 0; jabber_away_state_list[i].full_name; i ++ )
     121                if( g_strcasecmp( jabber_away_state_list[i].full_name, name ) == 0 )
     122                        return jabber_away_state_list + i;
     123       
     124        return NULL;
     125}
  • protocols/jabber/presence.c

    rd8e0484 r5e202b0  
    5454}
    5555
    56 /* Send the <presence/> tag that finalizes the whole login process, from here
    57    we'll actually show up as online to our buddies. */
    58 int presence_announce( struct gaim_connection *gc )
    59 {
    60         struct xt_node *node;
    61         int st;
    62        
    63         node = jabber_make_packet( "presence", NULL, NULL, NULL );
    64        
    65         st = jabber_write_packet( gc, node );
    66        
    67         if( st )
    68                 account_online( gc );
    69        
    70         xt_free_node( node );
    71         return st;
    72 }
    73 
    7456int presence_send( struct gaim_connection *gc, char *to, char *show, char *status )
    7557{
     
    7860       
    7961        node = jabber_make_packet( "presence", NULL, to, NULL );
    80         if( show )
     62        if( show && *show )
    8163                xt_add_child( node, xt_new_node( "show", show, NULL ) );
    8264        if( status )
  • protocols/msn/msn.c

    rd8e0484 r5e202b0  
    183183static GList *msn_away_states( struct gaim_connection *gc )
    184184{
    185         GList *l = NULL;
     185        static GList *l = NULL;
    186186        int i;
    187187       
    188         for( i = 0; msn_away_state_list[i].number > -1; i ++ )
    189                 l = g_list_append( l, (void*) msn_away_state_list[i].name );
    190        
    191         return( l );
     188        if( l == NULL )
     189                for( i = 0; msn_away_state_list[i].number > -1; i ++ )
     190                        l = g_list_append( l, (void*) msn_away_state_list[i].name );
     191       
     192        return l;
    192193}
    193194
  • protocols/nogaim.c

    rd8e0484 r5e202b0  
    10191019        }
    10201020       
    1021         g_list_free( ms );
    1022        
    10231021        return( 1 );
    10241022}
Note: See TracChangeset for help on using the changeset viewer.