Changeset e35d1a1 for protocols/jabber
- Timestamp:
- 2007-04-22T20:44:27Z (18 years ago)
- Branches:
- master
- Children:
- 43671b9
- Parents:
- c737ba7
- Location:
- protocols/jabber
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/Makefile
rc737ba7 re35d1a1 10 10 11 11 # [SH] Program variables 12 objects = io.o iq.o jabber.o jabber_util.o message.o presence.o sasl.o xmltree.o12 objects = conference.o io.o iq.o jabber.o jabber_util.o message.o presence.o sasl.o xmltree.o 13 13 14 14 CFLAGS += -Wall -
protocols/jabber/jabber.c
rc737ba7 re35d1a1 324 324 } 325 325 326 static struct groupchat *jabber_chat_join_( struct im_connection *ic, char *room, char *nick, char *password ) 327 { 328 if( strchr( room, '@' ) == NULL ) 329 imcb_error( ic, "Invalid room name: %s", room ); 330 else if( jabber_chat_by_name( ic, room ) ) 331 imcb_error( ic, "Already present in chat `%s'", room ); 332 else 333 return jabber_chat_join( ic, room, nick, password ); 334 335 return NULL; 336 } 337 338 static void jabber_chat_leave_( struct groupchat *c ) 339 { 340 if( c ) 341 jabber_chat_leave( c, NULL ); 342 } 343 326 344 static void jabber_keepalive( struct im_connection *ic ) 327 345 { … … 396 414 // ret->chat_msg = jabber_chat_msg; 397 415 // ret->chat_invite = jabber_chat_invite; 398 // ret->chat_leave = jabber_chat_leave;399 // ret->chat_open = jabber_chat_open;416 ret->chat_leave = jabber_chat_leave_; 417 ret->chat_join = jabber_chat_join_; 400 418 ret->keepalive = jabber_keepalive; 401 419 ret->send_typing = jabber_send_typing; -
protocols/jabber/jabber.h
rc737ba7 re35d1a1 50 50 JBFLAG_DOES_XEP85 = 2, /* Set this when the resource seems to support 51 51 XEP85 (typing notification shite). */ 52 JBFLAG_IS_CHATROOM = 4, /* It's convenient to use this JID thingy for 53 groupchat state info too. */ 52 54 } jabber_buddy_flags_t; 53 55 … … 101 103 char *resource; 102 104 105 /* Groupchat-only */ 106 char *orig_jid; 107 103 108 int priority; 104 109 struct jabber_away_state *away_state; … … 109 114 110 115 struct jabber_buddy *next; 116 }; 117 118 struct jabber_chat 119 { 120 int flags; 121 char *name; 122 struct jabber_buddy *me; 111 123 }; 112 124 … … 134 146 #define XMLNS_CHATSTATES "http://jabber.org/protocol/chatstates" /* 0085 */ 135 147 #define XMLNS_DISCOVER "http://jabber.org/protocol/disco#info" /* 0030 */ 148 #define XMLNS_MUC "http://jabber.org/protocol/muc" /* XEP-0045 */ 149 #define XMLNS_MUC_USER "http://jabber.org/protocol/muc#user"/* XEP-0045 */ 136 150 137 151 /* iq.c */ … … 164 178 const struct jabber_away_state *jabber_away_state_by_name( char *name ); 165 179 void jabber_buddy_ask( struct im_connection *ic, char *handle ); 166 char *jabber_normalize( c har *orig );180 char *jabber_normalize( const char *orig ); 167 181 168 182 typedef enum 169 183 { 170 184 GET_BUDDY_CREAT = 1, /* Try to create it, if necessary. */ 171 GET_BUDDY_EXACT = 2, /* Get an exact message (only makes sense with bare JIDs). */ 185 GET_BUDDY_EXACT = 2, /* Get an exact match (only makes sense with bare JIDs). */ 186 GET_BUDDY_FIRST = 4, /* No selection, simply get the first resource for this JID. */ 172 187 } get_buddy_flags_t; 173 188 … … 176 191 int jabber_buddy_remove( struct im_connection *ic, char *full_jid ); 177 192 int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid ); 193 struct groupchat *jabber_chat_by_name( struct im_connection *ic, const char *name ); 178 194 179 195 extern const struct jabber_away_state jabber_away_state_list[]; … … 193 209 gboolean sasl_supported( struct im_connection *ic ); 194 210 211 /* conference.c */ 212 struct groupchat *jabber_chat_join( struct im_connection *ic, char *room, char *nick, char *password ); 213 int jabber_chat_leave( struct groupchat *c, const char *reason ); 214 void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bud, struct xt_node *node ); 215 void jabber_chat_pkt_message( struct im_connection *ic, struct jabber_buddy *bud, struct xt_node *node ); 216 195 217 #endif -
protocols/jabber/jabber_util.c
rc737ba7 re35d1a1 48 48 call p_s_u() now to send the new prio setting, it would 49 49 send the old setting because the set->value gets changed 50 when theeval returns a non-NULL value.50 after the (this) eval returns a non-NULL value. 51 51 52 52 So now I can choose between implementing post-set … … 129 129 /* Cache a node/packet for later use. Mainly useful for IQ packets if you need 130 130 them when you receive the response. Use this BEFORE sending the packet so 131 it'll get a new id= tag, and do NOT free() the packet after writing it! */131 it'll get a new id= tag, and do NOT free() the packet after sending it! */ 132 132 void jabber_cache_add( struct im_connection *ic, struct xt_node *node, jabber_cache_event func ) 133 133 { … … 252 252 253 253 /* Returns a new string. Don't leak it! */ 254 char *jabber_normalize( c har *orig )254 char *jabber_normalize( const char *orig ) 255 255 { 256 256 int len, i; … … 353 353 if( ( s = strchr( jid, '/' ) ) ) 354 354 { 355 int none_found = 0; 356 355 357 *s = 0; 356 358 if( ( bud = g_hash_table_lookup( jd->buddies, jid ) ) ) … … 370 372 } 371 373 } 372 373 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && imcb_find_buddy( ic, jid ) ) 374 else 375 { 376 /* This hack is there to make sure that O_CREAT will 377 work if there's already another resouce present 378 for this JID, even if it's an unknown buddy. This 379 is done to handle conferences properly. */ 380 none_found = 1; 381 } 382 383 if( bud == NULL && ( flags & GET_BUDDY_CREAT ) && ( imcb_find_buddy( ic, jid ) || !none_found ) ) 374 384 { 375 385 *s = '/'; … … 531 541 } 532 542 } 543 544 struct groupchat *jabber_chat_by_name( struct im_connection *ic, const char *name ) 545 { 546 char *normalized = jabber_normalize( name ); 547 struct groupchat *ret; 548 struct jabber_chat *jc; 549 550 for( ret = ic->groupchats; ret; ret = ret->next ) 551 { 552 jc = ret->data; 553 if( strcmp( normalized, jc->name ) == 0 ) 554 break; 555 } 556 g_free( normalized ); 557 558 return ret; 559 } -
protocols/jabber/message.c
rc737ba7 re35d1a1 30 30 char *type = xt_find_attr( node, "type" ); 31 31 struct xt_node *body = xt_find_node( node->children, "body" ), *c; 32 struct jabber_buddy *bud = NULL; 32 33 char *s; 34 35 if( !from ) 36 return XT_HANDLED; /* Consider this packet corrupted. */ 37 38 bud = jabber_buddy_by_jid( ic, from, GET_BUDDY_EXACT ); 33 39 34 40 if( type && strcmp( type, "error" ) == 0 ) … … 36 42 /* Handle type=error packet. */ 37 43 } 38 else if( type && strcmp( type, "groupchat" ) == 0 )44 else if( type && from && strcmp( type, "groupchat" ) == 0 ) 39 45 { 40 /* TODO! */46 jabber_chat_pkt_message( ic, bud, node ); 41 47 } 42 48 else /* "chat", "normal", "headline", no-type or whatever. Should all be pretty similar. */ 43 49 { 44 struct jabber_buddy *bud = NULL;45 50 GString *fullmsg = g_string_new( "" ); 46 51 47 52 if( ( s = strchr( from, '/' ) ) ) 48 53 { 49 if( ( bud = jabber_buddy_by_jid( ic, from, GET_BUDDY_EXACT ) ))54 if( bud ) 50 55 bud->last_act = time( NULL ); 51 56 else -
protocols/jabber/presence.c
rc737ba7 re35d1a1 31 31 struct xt_node *c; 32 32 struct jabber_buddy *bud; 33 int is_chat = 0; 33 34 char *s; 34 35 35 36 if( !from ) 36 37 return XT_HANDLED; 38 39 if( ( s = strchr( from, '/' ) ) ) 40 { 41 *s = 0; 42 if( jabber_chat_by_name( ic, from ) ) 43 is_chat = 1; 44 *s = '/'; 45 } 37 46 38 47 if( type == NULL ) … … 72 81 bud->priority = 0; 73 82 74 if( bud == jabber_buddy_by_jid( ic, bud->bare_jid, 0 ) ) 83 if( is_chat ) 84 jabber_chat_pkt_presence( ic, bud, node ); 85 else if( bud == jabber_buddy_by_jid( ic, bud->bare_jid, 0 ) ) 75 86 imcb_buddy_status( ic, bud->bare_jid, OPT_LOGGED_IN | is_away, 76 87 ( is_away && bud->away_state ) ? bud->away_state->full_name : NULL, … … 79 90 else if( strcmp( type, "unavailable" ) == 0 ) 80 91 { 81 if( jabber_buddy_by_jid( ic, from, GET_BUDDY_EXACT) == NULL )92 if( ( bud = jabber_buddy_by_jid( ic, from, GET_BUDDY_EXACT ) ) == NULL ) 82 93 { 83 94 if( set_getbool( &ic->irc->set, "debug" ) ) … … 86 97 } 87 98 99 /* Handle this before we delete the JID. */ 100 if( is_chat ) 101 { 102 jabber_chat_pkt_presence( ic, bud, node ); 103 } 104 88 105 jabber_buddy_remove( ic, from ); 89 106 90 if( ( s = strchr( from, '/' ) ) ) 107 if( is_chat ) 108 { 109 /* Nothing else to do for now? */ 110 } 111 else if( ( s = strchr( from, '/' ) ) ) 91 112 { 92 113 *s = 0; … … 96 117 if( jabber_buddy_by_jid( ic, from, 0 ) == NULL ) 97 118 imcb_buddy_status( ic, from, 0, NULL, NULL ); 119 /* FIXME: If this resource was not away and another resource is, 120 we should definitely send an update here. */ 98 121 99 122 *s = '/'; -
protocols/jabber/xmltree.c
rc737ba7 re35d1a1 188 188 g_strcasecmp( xt->handlers[i].parent, "<root>" ) == 0 ) ) ) 189 189 { 190 xt_print( node ); 191 190 192 st = xt->handlers[i].func( node, xt->data ); 191 193
Note: See TracChangeset
for help on using the changeset viewer.