1 | /***************************************************************************\ |
---|
2 | * * |
---|
3 | * BitlBee - An IRC to IM gateway * |
---|
4 | * Jabber module - Main file * |
---|
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 <glib.h> |
---|
25 | #include <string.h> |
---|
26 | #include <unistd.h> |
---|
27 | #include <ctype.h> |
---|
28 | #include <stdio.h> |
---|
29 | |
---|
30 | #include "ssl_client.h" |
---|
31 | #include "xmltree.h" |
---|
32 | #include "bitlbee.h" |
---|
33 | #include "jabber.h" |
---|
34 | #include "md5.h" |
---|
35 | |
---|
36 | GSList *jabber_connections; |
---|
37 | |
---|
38 | /* First enty is the default */ |
---|
39 | static const int jabber_port_list[] = { |
---|
40 | 5222, |
---|
41 | 5223, |
---|
42 | 5220, |
---|
43 | 5221, |
---|
44 | 5224, |
---|
45 | 5225, |
---|
46 | 5226, |
---|
47 | 5227, |
---|
48 | 5228, |
---|
49 | 5229, |
---|
50 | 80, |
---|
51 | 443, |
---|
52 | 0 |
---|
53 | }; |
---|
54 | |
---|
55 | static void jabber_init( account_t *acc ) |
---|
56 | { |
---|
57 | set_t *s; |
---|
58 | char str[16]; |
---|
59 | |
---|
60 | s = set_add( &acc->set, "activity_timeout", "600", set_eval_int, acc ); |
---|
61 | |
---|
62 | s = set_add( &acc->set, "oauth", "false", set_eval_bool, acc ); |
---|
63 | |
---|
64 | g_snprintf( str, sizeof( str ), "%d", jabber_port_list[0] ); |
---|
65 | s = set_add( &acc->set, "port", str, set_eval_int, acc ); |
---|
66 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
67 | |
---|
68 | s = set_add( &acc->set, "priority", "0", set_eval_priority, acc ); |
---|
69 | |
---|
70 | s = set_add( &acc->set, "proxy", "<local>;<auto>", NULL, acc ); |
---|
71 | |
---|
72 | s = set_add( &acc->set, "resource", "BitlBee", NULL, acc ); |
---|
73 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
74 | |
---|
75 | s = set_add( &acc->set, "resource_select", "activity", NULL, acc ); |
---|
76 | |
---|
77 | s = set_add( &acc->set, "server", NULL, set_eval_account, acc ); |
---|
78 | s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY | SET_NULL_OK; |
---|
79 | |
---|
80 | s = set_add( &acc->set, "ssl", "false", set_eval_bool, acc ); |
---|
81 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
82 | |
---|
83 | s = set_add( &acc->set, "tls", "try", set_eval_tls, acc ); |
---|
84 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
85 | |
---|
86 | s = set_add( &acc->set, "user_agent", "BitlBee", NULL, acc ); |
---|
87 | |
---|
88 | s = set_add( &acc->set, "xmlconsole", "false", set_eval_bool, acc ); |
---|
89 | s->flags |= ACC_SET_OFFLINE_ONLY; |
---|
90 | |
---|
91 | acc->flags |= ACC_FLAG_AWAY_MESSAGE | ACC_FLAG_STATUS_MESSAGE; |
---|
92 | } |
---|
93 | |
---|
94 | static void jabber_generate_id_hash( struct jabber_data *jd ); |
---|
95 | |
---|
96 | static void jabber_login( account_t *acc ) |
---|
97 | { |
---|
98 | struct im_connection *ic = imcb_new( acc ); |
---|
99 | struct jabber_data *jd = g_new0( struct jabber_data, 1 ); |
---|
100 | struct ns_srv_reply **srvl = NULL, *srv = NULL; |
---|
101 | char *connect_to, *s; |
---|
102 | int i; |
---|
103 | |
---|
104 | /* For now this is needed in the _connected() handlers if using |
---|
105 | GLib event handling, to make sure we're not handling events |
---|
106 | on dead connections. */ |
---|
107 | jabber_connections = g_slist_prepend( jabber_connections, ic ); |
---|
108 | |
---|
109 | jd->ic = ic; |
---|
110 | ic->proto_data = jd; |
---|
111 | |
---|
112 | jd->username = g_strdup( acc->user ); |
---|
113 | jd->server = strchr( jd->username, '@' ); |
---|
114 | |
---|
115 | jd->fd = jd->r_inpa = jd->w_inpa = -1; |
---|
116 | |
---|
117 | if( jd->server == NULL ) |
---|
118 | { |
---|
119 | imcb_error( ic, "Incomplete account name (format it like <username@jabberserver.name>)" ); |
---|
120 | imc_logout( ic, FALSE ); |
---|
121 | return; |
---|
122 | } |
---|
123 | |
---|
124 | /* So don't think of free()ing jd->server.. :-) */ |
---|
125 | *jd->server = 0; |
---|
126 | jd->server ++; |
---|
127 | |
---|
128 | if( ( s = strchr( jd->server, '/' ) ) ) |
---|
129 | { |
---|
130 | *s = 0; |
---|
131 | set_setstr( &acc->set, "resource", s + 1 ); |
---|
132 | |
---|
133 | /* Also remove the /resource from the original variable so we |
---|
134 | won't have to do this again every time. */ |
---|
135 | s = strchr( acc->user, '/' ); |
---|
136 | *s = 0; |
---|
137 | } |
---|
138 | |
---|
139 | jd->node_cache = g_hash_table_new_full( g_str_hash, g_str_equal, NULL, jabber_cache_entry_free ); |
---|
140 | jd->buddies = g_hash_table_new( g_str_hash, g_str_equal ); |
---|
141 | |
---|
142 | /* Figure out the hostname to connect to. */ |
---|
143 | if( acc->server && *acc->server ) |
---|
144 | connect_to = acc->server; |
---|
145 | else if( ( srvl = srv_lookup( "xmpp-client", "tcp", jd->server ) ) || |
---|
146 | ( srvl = srv_lookup( "jabber-client", "tcp", jd->server ) ) ) |
---|
147 | { |
---|
148 | /* Find the lowest-priority one. These usually come |
---|
149 | back in random/shuffled order. Not looking at |
---|
150 | weights etc for now. */ |
---|
151 | srv = *srvl; |
---|
152 | for( i = 1; srvl[i]; i ++ ) |
---|
153 | if( srvl[i]->prio < srv->prio ) |
---|
154 | srv = srvl[i]; |
---|
155 | |
---|
156 | connect_to = srv->name; |
---|
157 | } |
---|
158 | else |
---|
159 | connect_to = jd->server; |
---|
160 | |
---|
161 | imcb_log( ic, "Connecting" ); |
---|
162 | |
---|
163 | for( i = 0; jabber_port_list[i] > 0; i ++ ) |
---|
164 | if( set_getint( &acc->set, "port" ) == jabber_port_list[i] ) |
---|
165 | break; |
---|
166 | |
---|
167 | if( jabber_port_list[i] == 0 ) |
---|
168 | { |
---|
169 | imcb_log( ic, "Illegal port number" ); |
---|
170 | imc_logout( ic, FALSE ); |
---|
171 | return; |
---|
172 | } |
---|
173 | |
---|
174 | /* For non-SSL connections we can try to use the port # from the SRV |
---|
175 | reply, but let's not do that when using SSL, SSL usually runs on |
---|
176 | non-standard ports... */ |
---|
177 | if( set_getbool( &acc->set, "ssl" ) ) |
---|
178 | { |
---|
179 | jd->ssl = ssl_connect( connect_to, set_getint( &acc->set, "port" ), jabber_connected_ssl, ic ); |
---|
180 | jd->fd = jd->ssl ? ssl_getfd( jd->ssl ) : -1; |
---|
181 | } |
---|
182 | else |
---|
183 | { |
---|
184 | jd->fd = proxy_connect( connect_to, srv ? srv->port : set_getint( &acc->set, "port" ), jabber_connected_plain, ic ); |
---|
185 | } |
---|
186 | srv_free( srvl ); |
---|
187 | |
---|
188 | if( jd->fd == -1 ) |
---|
189 | { |
---|
190 | imcb_error( ic, "Could not connect to server" ); |
---|
191 | imc_logout( ic, TRUE ); |
---|
192 | |
---|
193 | return; |
---|
194 | } |
---|
195 | |
---|
196 | if( set_getbool( &acc->set, "xmlconsole" ) ) |
---|
197 | { |
---|
198 | jd->flags |= JFLAG_XMLCONSOLE; |
---|
199 | /* Shouldn't really do this at this stage already, maybe. But |
---|
200 | I think this shouldn't break anything. */ |
---|
201 | imcb_add_buddy( ic, JABBER_XMLCONSOLE_HANDLE, NULL ); |
---|
202 | } |
---|
203 | |
---|
204 | jabber_generate_id_hash( jd ); |
---|
205 | } |
---|
206 | |
---|
207 | /* This generates an unfinished md5_state_t variable. Every time we generate |
---|
208 | an ID, we finish the state by adding a sequence number and take the hash. */ |
---|
209 | static void jabber_generate_id_hash( struct jabber_data *jd ) |
---|
210 | { |
---|
211 | md5_byte_t binbuf[4]; |
---|
212 | char *s; |
---|
213 | |
---|
214 | md5_init( &jd->cached_id_prefix ); |
---|
215 | md5_append( &jd->cached_id_prefix, (unsigned char *) jd->username, strlen( jd->username ) ); |
---|
216 | md5_append( &jd->cached_id_prefix, (unsigned char *) jd->server, strlen( jd->server ) ); |
---|
217 | s = set_getstr( &jd->ic->acc->set, "resource" ); |
---|
218 | md5_append( &jd->cached_id_prefix, (unsigned char *) s, strlen( s ) ); |
---|
219 | random_bytes( binbuf, 4 ); |
---|
220 | md5_append( &jd->cached_id_prefix, binbuf, 4 ); |
---|
221 | } |
---|
222 | |
---|
223 | static void jabber_logout( struct im_connection *ic ) |
---|
224 | { |
---|
225 | struct jabber_data *jd = ic->proto_data; |
---|
226 | |
---|
227 | while( jd->filetransfers ) |
---|
228 | imcb_file_canceled( ic, ( ( struct jabber_transfer *) jd->filetransfers->data )->ft, "Logging out" ); |
---|
229 | |
---|
230 | while( jd->streamhosts ) |
---|
231 | { |
---|
232 | jabber_streamhost_t *sh = jd->streamhosts->data; |
---|
233 | jd->streamhosts = g_slist_remove( jd->streamhosts, sh ); |
---|
234 | g_free( sh->jid ); |
---|
235 | g_free( sh->host ); |
---|
236 | g_free( sh ); |
---|
237 | } |
---|
238 | |
---|
239 | if( jd->fd >= 0 ) |
---|
240 | jabber_end_stream( ic ); |
---|
241 | |
---|
242 | while( ic->groupchats ) |
---|
243 | jabber_chat_free( ic->groupchats->data ); |
---|
244 | |
---|
245 | if( jd->r_inpa >= 0 ) |
---|
246 | b_event_remove( jd->r_inpa ); |
---|
247 | if( jd->w_inpa >= 0 ) |
---|
248 | b_event_remove( jd->w_inpa ); |
---|
249 | |
---|
250 | if( jd->ssl ) |
---|
251 | ssl_disconnect( jd->ssl ); |
---|
252 | if( jd->fd >= 0 ) |
---|
253 | closesocket( jd->fd ); |
---|
254 | |
---|
255 | if( jd->tx_len ) |
---|
256 | g_free( jd->txq ); |
---|
257 | |
---|
258 | if( jd->node_cache ) |
---|
259 | g_hash_table_destroy( jd->node_cache ); |
---|
260 | |
---|
261 | jabber_buddy_remove_all( ic ); |
---|
262 | |
---|
263 | xt_free( jd->xt ); |
---|
264 | |
---|
265 | g_free( jd->away_message ); |
---|
266 | g_free( jd->username ); |
---|
267 | g_free( jd ); |
---|
268 | |
---|
269 | jabber_connections = g_slist_remove( jabber_connections, ic ); |
---|
270 | } |
---|
271 | |
---|
272 | static int jabber_buddy_msg( struct im_connection *ic, char *who, char *message, int flags ) |
---|
273 | { |
---|
274 | struct jabber_data *jd = ic->proto_data; |
---|
275 | struct jabber_buddy *bud; |
---|
276 | struct xt_node *node; |
---|
277 | char *s; |
---|
278 | int st; |
---|
279 | |
---|
280 | if( g_strcasecmp( who, JABBER_XMLCONSOLE_HANDLE ) == 0 ) |
---|
281 | return jabber_write( ic, message, strlen( message ) ); |
---|
282 | |
---|
283 | if( ( s = strchr( who, '=' ) ) && jabber_chat_by_jid( ic, s + 1 ) ) |
---|
284 | bud = jabber_buddy_by_ext_jid( ic, who, 0 ); |
---|
285 | else |
---|
286 | bud = jabber_buddy_by_jid( ic, who, GET_BUDDY_BARE_OK ); |
---|
287 | |
---|
288 | node = xt_new_node( "body", message, NULL ); |
---|
289 | node = jabber_make_packet( "message", "chat", bud ? bud->full_jid : who, node ); |
---|
290 | |
---|
291 | if( bud && ( jd->flags & JFLAG_WANT_TYPING ) && |
---|
292 | ( ( bud->flags & JBFLAG_DOES_XEP85 ) || |
---|
293 | !( bud->flags & JBFLAG_PROBED_XEP85 ) ) ) |
---|
294 | { |
---|
295 | struct xt_node *act; |
---|
296 | |
---|
297 | /* If the user likes typing notification and if we don't know |
---|
298 | (and didn't probe before) if this resource supports XEP85, |
---|
299 | include a probe in this packet now. Also, if we know this |
---|
300 | buddy does support XEP85, we have to send this <active/> |
---|
301 | tag to tell that the user stopped typing (well, that's what |
---|
302 | we guess when s/he pressed Enter...). */ |
---|
303 | act = xt_new_node( "active", NULL, NULL ); |
---|
304 | xt_add_attr( act, "xmlns", XMLNS_CHATSTATES ); |
---|
305 | xt_add_child( node, act ); |
---|
306 | |
---|
307 | /* Just make sure we do this only once. */ |
---|
308 | bud->flags |= JBFLAG_PROBED_XEP85; |
---|
309 | } |
---|
310 | |
---|
311 | st = jabber_write_packet( ic, node ); |
---|
312 | xt_free_node( node ); |
---|
313 | |
---|
314 | return st; |
---|
315 | } |
---|
316 | |
---|
317 | static GList *jabber_away_states( struct im_connection *ic ) |
---|
318 | { |
---|
319 | static GList *l = NULL; |
---|
320 | int i; |
---|
321 | |
---|
322 | if( l == NULL ) |
---|
323 | for( i = 0; jabber_away_state_list[i].full_name; i ++ ) |
---|
324 | l = g_list_append( l, (void*) jabber_away_state_list[i].full_name ); |
---|
325 | |
---|
326 | return l; |
---|
327 | } |
---|
328 | |
---|
329 | static void jabber_get_info( struct im_connection *ic, char *who ) |
---|
330 | { |
---|
331 | struct jabber_buddy *bud; |
---|
332 | |
---|
333 | bud = jabber_buddy_by_jid( ic, who, GET_BUDDY_FIRST ); |
---|
334 | |
---|
335 | while( bud ) |
---|
336 | { |
---|
337 | imcb_log( ic, "Buddy %s (%d) information:", bud->full_jid, bud->priority ); |
---|
338 | if( bud->away_state ) |
---|
339 | imcb_log( ic, "Away state: %s", bud->away_state->full_name ); |
---|
340 | imcb_log( ic, "Status message: %s", bud->away_message ? bud->away_message : "(none)" ); |
---|
341 | |
---|
342 | bud = bud->next; |
---|
343 | } |
---|
344 | |
---|
345 | jabber_get_vcard( ic, bud ? bud->full_jid : who ); |
---|
346 | } |
---|
347 | |
---|
348 | static void jabber_set_away( struct im_connection *ic, char *state_txt, char *message ) |
---|
349 | { |
---|
350 | struct jabber_data *jd = ic->proto_data; |
---|
351 | |
---|
352 | /* state_txt == NULL -> Not away. |
---|
353 | Unknown state -> fall back to the first defined away state. */ |
---|
354 | if( state_txt == NULL ) |
---|
355 | jd->away_state = NULL; |
---|
356 | else if( ( jd->away_state = jabber_away_state_by_name( state_txt ) ) == NULL ) |
---|
357 | jd->away_state = jabber_away_state_list; |
---|
358 | |
---|
359 | g_free( jd->away_message ); |
---|
360 | jd->away_message = ( message && *message ) ? g_strdup( message ) : NULL; |
---|
361 | |
---|
362 | presence_send_update( ic ); |
---|
363 | } |
---|
364 | |
---|
365 | static void jabber_add_buddy( struct im_connection *ic, char *who, char *group ) |
---|
366 | { |
---|
367 | struct jabber_data *jd = ic->proto_data; |
---|
368 | |
---|
369 | if( g_strcasecmp( who, JABBER_XMLCONSOLE_HANDLE ) == 0 ) |
---|
370 | { |
---|
371 | jd->flags |= JFLAG_XMLCONSOLE; |
---|
372 | imcb_add_buddy( ic, JABBER_XMLCONSOLE_HANDLE, NULL ); |
---|
373 | return; |
---|
374 | } |
---|
375 | |
---|
376 | if( jabber_add_to_roster( ic, who, NULL, group ) ) |
---|
377 | presence_send_request( ic, who, "subscribe" ); |
---|
378 | } |
---|
379 | |
---|
380 | static void jabber_remove_buddy( struct im_connection *ic, char *who, char *group ) |
---|
381 | { |
---|
382 | struct jabber_data *jd = ic->proto_data; |
---|
383 | |
---|
384 | if( g_strcasecmp( who, JABBER_XMLCONSOLE_HANDLE ) == 0 ) |
---|
385 | { |
---|
386 | jd->flags &= ~JFLAG_XMLCONSOLE; |
---|
387 | /* Not necessary for now. And for now the code isn't too |
---|
388 | happy if the buddy is completely gone right after calling |
---|
389 | this function already. |
---|
390 | imcb_remove_buddy( ic, JABBER_XMLCONSOLE_HANDLE, NULL ); |
---|
391 | */ |
---|
392 | return; |
---|
393 | } |
---|
394 | |
---|
395 | /* We should always do this part. Clean up our administration a little bit. */ |
---|
396 | jabber_buddy_remove_bare( ic, who ); |
---|
397 | |
---|
398 | if( jabber_remove_from_roster( ic, who ) ) |
---|
399 | presence_send_request( ic, who, "unsubscribe" ); |
---|
400 | } |
---|
401 | |
---|
402 | static struct groupchat *jabber_chat_join_( struct im_connection *ic, const char *room, const char *nick, const char *password, set_t **sets ) |
---|
403 | { |
---|
404 | if( strchr( room, '@' ) == NULL ) |
---|
405 | imcb_error( ic, "Invalid room name: %s", room ); |
---|
406 | else if( jabber_chat_by_jid( ic, room ) ) |
---|
407 | imcb_error( ic, "Already present in chat `%s'", room ); |
---|
408 | else |
---|
409 | return jabber_chat_join( ic, room, nick, set_getstr( sets, "password" ) ); |
---|
410 | |
---|
411 | return NULL; |
---|
412 | } |
---|
413 | |
---|
414 | static void jabber_chat_msg_( struct groupchat *c, char *message, int flags ) |
---|
415 | { |
---|
416 | if( c && message ) |
---|
417 | jabber_chat_msg( c, message, flags ); |
---|
418 | } |
---|
419 | |
---|
420 | static void jabber_chat_topic_( struct groupchat *c, char *topic ) |
---|
421 | { |
---|
422 | if( c && topic ) |
---|
423 | jabber_chat_topic( c, topic ); |
---|
424 | } |
---|
425 | |
---|
426 | static void jabber_chat_leave_( struct groupchat *c ) |
---|
427 | { |
---|
428 | if( c ) |
---|
429 | jabber_chat_leave( c, NULL ); |
---|
430 | } |
---|
431 | |
---|
432 | static void jabber_chat_invite_( struct groupchat *c, char *who, char *msg ) |
---|
433 | { |
---|
434 | struct jabber_chat *jc = c->data; |
---|
435 | gchar *msg_alt = NULL; |
---|
436 | |
---|
437 | if( msg == NULL ) |
---|
438 | msg_alt = g_strdup_printf( "%s invited you to %s", c->ic->acc->user, jc->name ); |
---|
439 | |
---|
440 | if( c && who ) |
---|
441 | jabber_chat_invite( c, who, msg ? msg : msg_alt ); |
---|
442 | |
---|
443 | g_free( msg_alt ); |
---|
444 | } |
---|
445 | |
---|
446 | static void jabber_keepalive( struct im_connection *ic ) |
---|
447 | { |
---|
448 | /* Just any whitespace character is enough as a keepalive for XMPP sessions. */ |
---|
449 | if( !jabber_write( ic, "\n", 1 ) ) |
---|
450 | return; |
---|
451 | |
---|
452 | /* This runs the garbage collection every minute, which means every packet |
---|
453 | is in the cache for about a minute (which should be enough AFAIK). */ |
---|
454 | jabber_cache_clean( ic ); |
---|
455 | } |
---|
456 | |
---|
457 | static int jabber_send_typing( struct im_connection *ic, char *who, int typing ) |
---|
458 | { |
---|
459 | struct jabber_data *jd = ic->proto_data; |
---|
460 | struct jabber_buddy *bud; |
---|
461 | |
---|
462 | /* Enable typing notification related code from now. */ |
---|
463 | jd->flags |= JFLAG_WANT_TYPING; |
---|
464 | |
---|
465 | if( ( bud = jabber_buddy_by_jid( ic, who, 0 ) ) == NULL ) |
---|
466 | { |
---|
467 | /* Sending typing notifications to unknown buddies is |
---|
468 | unsupported for now. Shouldn't be a problem, I think. */ |
---|
469 | return 0; |
---|
470 | } |
---|
471 | |
---|
472 | if( bud->flags & JBFLAG_DOES_XEP85 ) |
---|
473 | { |
---|
474 | /* We're only allowed to send this stuff if we know the other |
---|
475 | side supports it. */ |
---|
476 | |
---|
477 | struct xt_node *node; |
---|
478 | char *type; |
---|
479 | int st; |
---|
480 | |
---|
481 | if( typing & OPT_TYPING ) |
---|
482 | type = "composing"; |
---|
483 | else if( typing & OPT_THINKING ) |
---|
484 | type = "paused"; |
---|
485 | else |
---|
486 | type = "active"; |
---|
487 | |
---|
488 | node = xt_new_node( type, NULL, NULL ); |
---|
489 | xt_add_attr( node, "xmlns", XMLNS_CHATSTATES ); |
---|
490 | node = jabber_make_packet( "message", "chat", bud->full_jid, node ); |
---|
491 | |
---|
492 | st = jabber_write_packet( ic, node ); |
---|
493 | xt_free_node( node ); |
---|
494 | |
---|
495 | return st; |
---|
496 | } |
---|
497 | |
---|
498 | return 1; |
---|
499 | } |
---|
500 | |
---|
501 | void jabber_chat_add_settings( account_t *acc, set_t **head ) |
---|
502 | { |
---|
503 | /* Meh. Stupid room passwords. Not trying to obfuscate/hide |
---|
504 | them from the user for now. */ |
---|
505 | set_add( head, "password", NULL, NULL, NULL ); |
---|
506 | } |
---|
507 | |
---|
508 | void jabber_chat_free_settings( account_t *acc, set_t **head ) |
---|
509 | { |
---|
510 | set_del( head, "password" ); |
---|
511 | } |
---|
512 | |
---|
513 | GList *jabber_buddy_action_list( bee_user_t *bu ) |
---|
514 | { |
---|
515 | static GList *ret = NULL; |
---|
516 | |
---|
517 | if( ret == NULL ) |
---|
518 | { |
---|
519 | static const struct buddy_action ba[2] = { |
---|
520 | { "VERSION", "Get client (version) information" }, |
---|
521 | }; |
---|
522 | |
---|
523 | ret = g_list_prepend( ret, (void*) ba + 0 ); |
---|
524 | } |
---|
525 | |
---|
526 | return ret; |
---|
527 | } |
---|
528 | |
---|
529 | void *jabber_buddy_action( struct bee_user *bu, const char *action, char * const args[], void *data ) |
---|
530 | { |
---|
531 | if( g_strcasecmp( action, "VERSION" ) == 0 ) |
---|
532 | { |
---|
533 | struct jabber_buddy *bud; |
---|
534 | |
---|
535 | if( ( bud = jabber_buddy_by_ext_jid( bu->ic, bu->handle, 0 ) ) == NULL ) |
---|
536 | bud = jabber_buddy_by_jid( bu->ic, bu->handle, GET_BUDDY_FIRST ); |
---|
537 | for( ; bud; bud = bud->next ) |
---|
538 | jabber_iq_version_send( bu->ic, bud, data ); |
---|
539 | } |
---|
540 | |
---|
541 | return NULL; |
---|
542 | } |
---|
543 | |
---|
544 | void jabber_initmodule() |
---|
545 | { |
---|
546 | struct prpl *ret = g_new0( struct prpl, 1 ); |
---|
547 | |
---|
548 | ret->name = "jabber"; |
---|
549 | ret->mms = 0; /* no limit */ |
---|
550 | ret->login = jabber_login; |
---|
551 | ret->init = jabber_init; |
---|
552 | ret->logout = jabber_logout; |
---|
553 | ret->buddy_msg = jabber_buddy_msg; |
---|
554 | ret->away_states = jabber_away_states; |
---|
555 | ret->set_away = jabber_set_away; |
---|
556 | // ret->set_info = jabber_set_info; |
---|
557 | ret->get_info = jabber_get_info; |
---|
558 | ret->add_buddy = jabber_add_buddy; |
---|
559 | ret->remove_buddy = jabber_remove_buddy; |
---|
560 | ret->chat_msg = jabber_chat_msg_; |
---|
561 | ret->chat_topic = jabber_chat_topic_; |
---|
562 | ret->chat_invite = jabber_chat_invite_; |
---|
563 | ret->chat_leave = jabber_chat_leave_; |
---|
564 | ret->chat_join = jabber_chat_join_; |
---|
565 | ret->chat_add_settings = jabber_chat_add_settings; |
---|
566 | ret->chat_free_settings = jabber_chat_free_settings; |
---|
567 | ret->keepalive = jabber_keepalive; |
---|
568 | ret->send_typing = jabber_send_typing; |
---|
569 | ret->handle_cmp = g_strcasecmp; |
---|
570 | ret->transfer_request = jabber_si_transfer_request; |
---|
571 | ret->buddy_action_list = jabber_buddy_action_list; |
---|
572 | ret->buddy_action = jabber_buddy_action; |
---|
573 | |
---|
574 | register_protocol( ret ); |
---|
575 | } |
---|