- Timestamp:
- 2006-10-10T12:05:42Z (18 years ago)
- Branches:
- master
- Children:
- 8eb10c9
- Parents:
- 6a1128d
- Location:
- protocols/jabber
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/jabber.c
r6a1128d ra21a8ac 44 44 s = set_add( &acc->set, "resource", "BitlBee", NULL, acc ); 45 45 s->flags |= ACC_SET_OFFLINE_ONLY; 46 47 s = set_add( &acc->set, "resource_select", "priority", NULL, acc ); 46 48 47 49 s = set_add( &acc->set, "server", NULL, set_eval_account, acc ); … … 137 139 static int jabber_send_im( struct gaim_connection *gc, char *who, char *message, int len, int away ) 138 140 { 141 struct jabber_data *jd = gc->proto_data; 142 struct jabber_buddy *bud; 139 143 struct xt_node *node; 140 144 int st; 141 145 142 /* 143 event = xt_new_node( "active", NULL, NULL ); 144 xt_add_attr( event, "xlmns", "http://jabber.org/protocol/chatstates" ); 145 146 event = xt_new_node( "x", NULL, xt_new_node( "composing", NULL, NULL ) ); 147 xt_add_attr( event, "xmlns", "jabber:x:event" ); 148 */ 146 bud = jabber_buddy_by_jid( gc, who ); 149 147 150 148 node = xt_new_node( "body", message, NULL ); 151 node = jabber_make_packet( "message", "chat", who, node ); 149 node = jabber_make_packet( "message", "chat", bud->full_jid, node ); 150 151 if( ( jd->flags & JFLAG_WANT_TYPING ) && 152 ( ( bud->flags & JBFLAG_DOES_JEP85 ) || 153 !( bud->flags & JBFLAG_PROBED_JEP85 ) ) ) 154 { 155 struct xt_node *act; 156 157 /* If the user likes typing notification and if we don't know 158 (and didn't probe before) if this resource supports JEP85, 159 include a probe in this packet now. */ 160 act = xt_new_node( "active", NULL, NULL ); 161 xt_add_attr( act, "xmlns", "http://jabber.org/protocol/chatstates" ); 162 xt_add_child( node, act ); 163 164 /* Just make sure we do this only once. */ 165 bud->flags |= JBFLAG_PROBED_JEP85; 166 } 167 152 168 st = jabber_write_packet( gc, node ); 153 169 xt_free_node( node ); … … 227 243 is in the cache for about a minute (which should be enough AFAIK). */ 228 244 jabber_cache_clean( gc ); 245 } 246 247 static int jabber_send_typing( struct gaim_connection *gc, char *who, int typing ) 248 { 249 struct jabber_data *jd = gc->proto_data; 250 struct jabber_buddy *bud; 251 252 /* Enable typing notification related code from now. */ 253 jd->flags |= JFLAG_WANT_TYPING; 254 255 bud = jabber_buddy_by_jid( gc, who ); 256 if( bud->flags & JBFLAG_DOES_JEP85 ) 257 { 258 /* We're only allowed to send this stuff if we know the other 259 side supports it. */ 260 261 struct xt_node *node; 262 char *type; 263 int st; 264 265 if( typing == 0 ) 266 type = "active"; 267 else if( typing == 2 ) 268 type = "paused"; 269 else /* if( typing == 1 ) */ 270 type = "composing"; 271 272 node = xt_new_node( type, NULL, NULL ); 273 xt_add_attr( node, "xmlns", "http://jabber.org/protocol/chatstates" ); 274 node = jabber_make_packet( "message", "chat", bud->full_jid, node ); 275 276 st = jabber_write_packet( gc, node ); 277 xt_free_node( node ); 278 279 return st; 280 } 281 282 return 1; 229 283 } 230 284 … … 250 304 // ret->chat_open = jabber_chat_open; 251 305 ret->keepalive = jabber_keepalive; 252 //ret->send_typing = jabber_send_typing;306 ret->send_typing = jabber_send_typing; 253 307 ret->handle_cmp = g_strcasecmp; 254 308 -
protocols/jabber/jabber.h
r6a1128d ra21a8ac 32 32 typedef enum 33 33 { 34 JFLAG_STREAM_STARTED = 1, /* Set when we detected the beginning of the stream and want to do auth. */ 34 JFLAG_STREAM_STARTED = 1, /* Set when we detected the beginning of the stream 35 and want to do auth. */ 35 36 JFLAG_AUTHENTICATED = 2, /* Set when we're successfully authenticatd. */ 36 JFLAG_STREAM_RESTART = 4, /* Set when we want to restart the stream (after SASL or TLS). */ 37 JFLAG_WAIT_SESSION = 8, /* Set if we sent a <session> tag and need a reply before we continue. */ 37 JFLAG_STREAM_RESTART = 4, /* Set when we want to restart the stream (after 38 SASL or TLS). */ 39 JFLAG_WAIT_SESSION = 8, /* Set if we sent a <session> tag and need a reply 40 before we continue. */ 38 41 JFLAG_WAIT_BIND = 16, /* ... for <bind> tag. */ 42 JFLAG_WANT_TYPING = 32, /* Set if we ever sent a typing notification, this 43 activates all JEP-85 related code. */ 39 44 } jabber_flags_t; 45 46 typedef enum 47 { 48 JBFLAG_PROBED_JEP85 = 1, /* Set this when we sent our probe packet to make 49 sure it gets sent only once. */ 50 JBFLAG_DOES_JEP85 = 2, /* Set this when the resource seems to support 51 JEP85 (typing notification shite). */ 52 } jabber_buddy_flag_t; 40 53 41 54 struct jabber_data … … 81 94 { 82 95 char *handle; 96 char *full_jid; 83 97 char *resource; 84 98 -
protocols/jabber/jabber_util.c
r6a1128d ra21a8ac 247 247 248 248 *s = '/'; 249 new->resource = g_strdup( s + 1 ); 249 new->full_jid = g_strdup( full_jid ); 250 new->resource = strchr( new->full_jid, '/' ) + 1; 250 251 251 252 return new; … … 268 269 else 269 270 { 270 /* TODO: Add selection. */ 271 return g_hash_table_lookup( jd->buddies, jid ); 271 struct jabber_buddy *best_prio, *best_time; 272 char *set; 273 274 best_prio = best_time = bud = g_hash_table_lookup( jd->buddies, jid ); 275 for( ; bud; bud = bud->next ) 276 { 277 if( bud->priority > best_prio->priority ) 278 best_prio = bud; 279 if( bud->last_act > best_time->last_act ) 280 best_time = bud; 281 } 282 283 if( ( set = set_getstr( &gc->acc->set, "resource_select" ) ) == NULL ) 284 return NULL; 285 else if( strcmp( set, "activity" ) == 0 ) 286 return best_time; 287 else /* if( strcmp( set, "priority" ) == 0 ) */ 288 return best_prio; 272 289 } 273 290 … … 295 312 g_hash_table_remove( jd->buddies, bud->handle ); 296 313 g_free( bud->handle ); 297 g_free( bud-> resource);314 g_free( bud->full_jid ); 298 315 g_free( bud->away_message ); 299 316 g_free( bud ); … … 314 331 g_hash_table_replace( jd->buddies, bi->handle, bi->next ); 315 332 316 g_free( bi-> resource);333 g_free( bi->full_jid ); 317 334 g_free( bi->away_message ); 318 335 g_free( bi ); -
protocols/jabber/message.c
r6a1128d ra21a8ac 29 29 char *from = xt_find_attr( node, "from" ); 30 30 char *type = xt_find_attr( node, "type" ); 31 struct xt_node * msg= xt_find_node( node->children, "body" );31 struct xt_node *body = xt_find_node( node->children, "body" ); 32 32 33 if( !type || !msg)33 if( !type ) 34 34 return XT_HANDLED; /* Grmbl... FIXME */ 35 35 36 36 if( strcmp( type, "chat" ) == 0 ) 37 37 { 38 char *s;38 struct jabber_buddy *bud = NULL; 39 39 40 s = strchr( from, '/' ); 41 if( s ) 42 *s = 0; 40 if( strchr( from, '/' ) == NULL ) 41 { 42 /* It just shouldn't happen. */ 43 hide_login_progress( gc, "Received message packet from bare JID" ); 44 signoff( gc ); 45 return XT_ABORT; 46 } 43 47 44 serv_got_im( gc, from, msg->text, 0, 0, 0 ); 48 bud = jabber_buddy_by_jid( gc, from ); 49 bud->last_act = time( NULL ); 45 50 46 if( s ) 47 *s = '/'; 51 if( body ) /* Could be just a typing notification. */ 52 serv_got_im( gc, bud->handle, body->text, 0, 0, 0 ); 53 54 if( xt_find_node( node->children, "composing" ) ) 55 { 56 bud->flags |= JBFLAG_DOES_JEP85; 57 serv_got_typing( gc, bud->handle, 0, 1 ); 58 } 59 else if( xt_find_node( node->children, "active" ) ) 60 { 61 bud->flags |= JBFLAG_DOES_JEP85; 62 } 48 63 } 49 64 else 50 65 { 51 printf( "Received MSG from %s: %s\n", from, msg ? msg->text : "<null>");66 printf( "Received MSG from %s:\n", from ); 52 67 xt_print( node ); 53 68 } -
protocols/jabber/presence.c
r6a1128d ra21a8ac 30 30 char *type = xt_find_attr( node, "type" ); /* NULL should mean the person is online. */ 31 31 struct xt_node *c; 32 struct jabber_buddy *bud; 32 33 33 34 if( !from ) … … 36 37 if( type == NULL ) 37 38 { 38 struct jabber_buddy *bud; 39 if( strchr( from, '/' ) == NULL ) 40 { 41 char *s = xt_to_string( node ); 42 serv_got_crap( gc, "WARNING: Ignoring presence tag with bare JID: %s\n", s ); 43 g_free( s ); 44 } 39 45 40 46 if( !( bud = jabber_buddy_by_jid( gc, from ) ) ) … … 52 58 bud->away_state = (void*) jabber_away_state_by_code( c->text ); 53 59 else 60 { 54 61 bud->away_state = NULL; 62 /* Let's only set last_act if there's *no* away state, 63 since it could be some auto-away thingy. */ 64 bud->last_act = time( NULL ); 65 } 55 66 56 67 if( ( c = xt_find_node( node->children, "priority" ) ) && c->text_len > 0 ) … … 59 70 bud->priority = 0; 60 71 61 serv_got_update( gc, bud->handle, 1, 0, 0, 0, 0, 0 ); 72 serv_got_update( gc, bud->handle, 1, 0, 0, 0, 73 bud->away_state ? UC_UNAVAILABLE : 0, 0 ); 62 74 } 63 75 else if( strcmp( type, "unavailable" ) == 0 ) … … 65 77 char *s; 66 78 79 if( ( s = strchr( from, '/' ) ) == NULL ) 80 { 81 char *s = xt_to_string( node ); 82 serv_got_crap( gc, "WARNING: Ignoring presence tag with bare JID: %s\n", s ); 83 g_free( s ); 84 } 85 67 86 jabber_buddy_remove( gc, from ); 68 69 if( ( s = strchr( from, '/' ) ) ) 70 *s = 0; 87 *s = 0; 71 88 72 89 /* Only count this as offline if there's no other resource
Note: See TracChangeset
for help on using the changeset viewer.