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