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 | |
---|
26 | static int next_id = 1; |
---|
27 | |
---|
28 | char *set_eval_resprio( set_t *set, char *value ) |
---|
29 | { |
---|
30 | account_t *acc = set->data; |
---|
31 | |
---|
32 | /* Only run this stuff if the account is online ATM. */ |
---|
33 | if( acc->gc ) |
---|
34 | { |
---|
35 | /* ... */ |
---|
36 | } |
---|
37 | |
---|
38 | if( g_strcasecmp( set->key, "priority" ) == 0 ) |
---|
39 | return set_eval_int( set, value ); |
---|
40 | else |
---|
41 | return value; |
---|
42 | } |
---|
43 | |
---|
44 | char *set_eval_tls( set_t *set, char *value ) |
---|
45 | { |
---|
46 | if( g_strcasecmp( value, "try" ) == 0 ) |
---|
47 | return value; |
---|
48 | else |
---|
49 | return set_eval_bool( set, value ); |
---|
50 | } |
---|
51 | |
---|
52 | struct xt_node *jabber_make_packet( char *name, char *type, char *to, struct xt_node *children ) |
---|
53 | { |
---|
54 | struct xt_node *node; |
---|
55 | |
---|
56 | node = xt_new_node( name, NULL, children ); |
---|
57 | |
---|
58 | if( type ) |
---|
59 | xt_add_attr( node, "type", type ); |
---|
60 | if( to ) |
---|
61 | xt_add_attr( node, "to", to ); |
---|
62 | |
---|
63 | return node; |
---|
64 | } |
---|
65 | |
---|
66 | /* Cache a node/packet for later use. Mainly useful for IQ packets if you need |
---|
67 | them when you receive the response. Use this BEFORE sending the packet so |
---|
68 | it'll get an id= tag, and do NOT free() the packet after writing it! */ |
---|
69 | void jabber_cache_packet( struct gaim_connection *gc, struct xt_node *node ) |
---|
70 | { |
---|
71 | struct jabber_data *jd = gc->proto_data; |
---|
72 | char *id = g_strdup_printf( "BeeX%04x", next_id++ ); |
---|
73 | |
---|
74 | /* FIXME: Maybe start using g_error() here if nodes still have a parent, for example? */ |
---|
75 | |
---|
76 | xt_add_attr( node, "id", id ); |
---|
77 | xt_add_child( jd->node_cache, node ); |
---|
78 | g_free( id ); |
---|
79 | } |
---|
80 | |
---|
81 | /* Emptying this cache is a BIG TODO! */ |
---|
82 | struct xt_node *jabber_packet_from_cache( struct gaim_connection *gc, char *id ) |
---|
83 | { |
---|
84 | struct jabber_data *jd = gc->proto_data; |
---|
85 | struct xt_node *node; |
---|
86 | char *s; |
---|
87 | |
---|
88 | for( node = jd->node_cache->children; node; node = node->next ) |
---|
89 | if( ( s = xt_find_attr( node, "id" ) ) && strcmp( id, s ) == 0 ) |
---|
90 | break; |
---|
91 | |
---|
92 | return node; |
---|
93 | } |
---|
94 | |
---|
95 | const 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 | |
---|
105 | const 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 | |
---|
116 | const 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 | } |
---|