source: protocols/jabber/jabber_util.c @ 172a73f1

Last change on this file since 172a73f1 was 172a73f1, checked in by Wilmer van der Gaast <wilmer@…>, at 2006-09-24T10:25:41Z

Updated <presence> stuff to handle changing the priority setting.

  • Property mode set to 100644
File size: 4.8 KB
Line 
1/***************************************************************************\
2*                                                                           *
3*  BitlBee - An IRC to IM gateway                                           *
4*  Jabber module - Misc. stuff                                              *
5*                                                                           *
6*  Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net>                   *
7*                                                                           *
8*  This program is free software; you can redistribute it and/or modify     *
9*  it under the terms of the GNU General Public License as published by     *
10*  the Free Software Foundation; either version 2 of the License, or        *
11*  (at your option) any later version.                                      *
12*                                                                           *
13*  This program is distributed in the hope that it will be useful,          *
14*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
15*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
16*  GNU General Public License for more details.                             *
17*                                                                           *
18*  You should have received a copy of the GNU General Public License along  *
19*  with this program; if not, write to the Free Software Foundation, Inc.,  *
20*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.              *
21*                                                                           *
22\***************************************************************************/
23
24#include "jabber.h"
25
26static int next_id = 1;
27
28char *set_eval_resprio( set_t *set, char *value )
29{
30        account_t *acc = set->data;
31        char *ret;
32       
33        if( strcmp( set->key, "priority" ) == 0 )
34                ret = set_eval_int( set, value );
35        else
36                ret = value;
37       
38        /* Only run this stuff if the account is online ATM,
39           and if the setting seems to be acceptable. */
40        if( acc->gc && ret )
41        {
42                if( strcmp( set->key, "priority" ) == 0 )
43                {
44                        /* Although set_eval functions usually are very nice
45                           and convenient, they have one disadvantage: If I
46                           would just call p_s_u() now to send the new prio
47                           setting, it would send the old setting because the
48                           set->value gets changed when the eval returns a
49                           non-NULL value.
50                           
51                           So now I can choose between implementing post-set
52                           functions next to evals, or just do this little
53                           hack: */
54                        g_free( set->value );
55                        set->value = g_strdup( ret );
56                       
57                        /* (Yes, sorry, I prefer the hack. :-P) */
58                       
59                        presence_send_update( acc->gc );
60                }
61                else
62                {
63                }
64        }
65       
66        return ret;
67}
68
69char *set_eval_tls( set_t *set, char *value )
70{
71        if( g_strcasecmp( value, "try" ) == 0 )
72                return value;
73        else
74                return set_eval_bool( set, value );
75}
76
77struct xt_node *jabber_make_packet( char *name, char *type, char *to, struct xt_node *children )
78{
79        struct xt_node *node;
80       
81        node = xt_new_node( name, NULL, children );
82       
83        if( type )
84                xt_add_attr( node, "type", type );
85        if( to )
86                xt_add_attr( node, "to", to );
87       
88        return node;
89}
90
91/* Cache a node/packet for later use. Mainly useful for IQ packets if you need
92   them when you receive the response. Use this BEFORE sending the packet so
93   it'll get an id= tag, and do NOT free() the packet after writing it! */
94void jabber_cache_packet( struct gaim_connection *gc, struct xt_node *node )
95{
96        struct jabber_data *jd = gc->proto_data;
97        char *id = g_strdup_printf( "BeeX%04x", next_id++ );
98       
99        /* FIXME: Maybe start using g_error() here if nodes still have a parent, for example? */
100       
101        xt_add_attr( node, "id", id );
102        xt_add_child( jd->node_cache, node );
103        g_free( id );
104}
105
106/* Emptying this cache is a BIG TODO! */
107struct xt_node *jabber_packet_from_cache( struct gaim_connection *gc, char *id )
108{
109        struct jabber_data *jd = gc->proto_data;
110        struct xt_node *node;
111        char *s;
112       
113        for( node = jd->node_cache->children; node; node = node->next )
114                if( ( s = xt_find_attr( node, "id" ) ) && strcmp( id, s ) == 0 )
115                        break;
116       
117        return node;
118}
119
120const struct jabber_away_state jabber_away_state_list[] =
121{
122        { "away",  "Away" },
123        { "chat",  "Free for Chat" },
124        { "dnd",   "Do not Disturb" },
125        { "xa",    "Extended Away" },
126        { "",      "Online" },
127        { "",      NULL }
128};
129
130const struct jabber_away_state *jabber_away_state_by_code( char *code )
131{
132        int i;
133       
134        for( i = 0; jabber_away_state_list[i].full_name; i ++ )
135                if( g_strcasecmp( jabber_away_state_list[i].code, code ) == 0 )
136                        return jabber_away_state_list + i;
137       
138        return NULL;
139}
140
141const struct jabber_away_state *jabber_away_state_by_name( char *name )
142{
143        int i;
144       
145        for( i = 0; jabber_away_state_list[i].full_name; i ++ )
146                if( g_strcasecmp( jabber_away_state_list[i].full_name, name ) == 0 )
147                        return jabber_away_state_list + i;
148       
149        return NULL;
150}
Note: See TracBrowser for help on using the repository browser.