diff options
-rw-r--r-- | protocols/jabber/conference.c | 29 | ||||
-rw-r--r-- | protocols/jabber/jabber.c | 9 | ||||
-rw-r--r-- | protocols/jabber/jabber.h | 3 | ||||
-rw-r--r-- | protocols/jabber/jabber_util.c | 49 | ||||
-rw-r--r-- | protocols/jabber/message.c | 3 | ||||
-rw-r--r-- | protocols/jabber/xmltree.c | 2 |
6 files changed, 82 insertions, 13 deletions
diff --git a/protocols/jabber/conference.c b/protocols/jabber/conference.c index ffc4f844..397fad85 100644 --- a/protocols/jabber/conference.c +++ b/protocols/jabber/conference.c @@ -61,6 +61,25 @@ struct groupchat *jabber_chat_join( struct im_connection *ic, char *room, char * return c; } +int jabber_chat_msg( struct groupchat *c, char *message, int flags ) +{ + struct im_connection *ic = c->ic; + struct jabber_chat *jc = c->data; + struct xt_node *node; + + node = xt_new_node( "body", message, NULL ); + node = jabber_make_packet( "message", "groupchat", jc->name, node ); + + if( !jabber_write_packet( ic, node ) ) + { + xt_free_node( node ); + return 0; + } + xt_free_node( node ); + + return 1; +} + int jabber_chat_leave( struct groupchat *c, const char *reason ) { struct im_connection *ic = c->ic; @@ -78,14 +97,6 @@ int jabber_chat_leave( struct groupchat *c, const char *reason ) } xt_free_node( node ); - /* Remove all participants from jc->buddies and clean up our data. */ - jabber_buddy_remove_bare( ic, jc->name ); - g_free( jc->name ); - g_free( jc ); - - /* And the generic stuff. */ - imcb_chat_free( c ); - return 1; } @@ -187,7 +198,7 @@ void jabber_chat_pkt_message( struct im_connection *ic, struct jabber_buddy *bud { s = strchr( bud->orig_jid, '/' ); if( s ) *s = 0; - imcb_chat_msg( chat, bud->orig_jid, body->text, 0, 0 ); + imcb_chat_msg( chat, bud->orig_jid, body->text, 0, jabber_get_timestamp( node ) ); if( s ) *s = '/'; } } diff --git a/protocols/jabber/jabber.c b/protocols/jabber/jabber.c index f9473015..6c0f6240 100644 --- a/protocols/jabber/jabber.c +++ b/protocols/jabber/jabber.c @@ -335,6 +335,12 @@ static struct groupchat *jabber_chat_join_( struct im_connection *ic, char *room return NULL; } +static void jabber_chat_msg_( struct groupchat *c, char *message, int flags ) +{ + if( c && message ) + jabber_chat_msg( c, message, flags ); +} + static void jabber_chat_leave_( struct groupchat *c ) { if( c ) @@ -405,13 +411,12 @@ void jabber_initmodule() ret->logout = jabber_logout; ret->buddy_msg = jabber_buddy_msg; ret->away_states = jabber_away_states; -// ret->get_status_string = jabber_get_status_string; ret->set_away = jabber_set_away; // ret->set_info = jabber_set_info; ret->get_info = jabber_get_info; ret->add_buddy = jabber_add_buddy; ret->remove_buddy = jabber_remove_buddy; -// ret->chat_msg = jabber_chat_msg; + ret->chat_msg = jabber_chat_msg_; // ret->chat_invite = jabber_chat_invite; ret->chat_leave = jabber_chat_leave_; ret->chat_join = jabber_chat_join_; diff --git a/protocols/jabber/jabber.h b/protocols/jabber/jabber.h index dd771910..57e24b5f 100644 --- a/protocols/jabber/jabber.h +++ b/protocols/jabber/jabber.h @@ -143,6 +143,7 @@ struct jabber_chat #define XMLNS_VERSION "jabber:iq:version" /* XEP-0092 */ #define XMLNS_TIME "jabber:iq:time" /* XEP-0090 */ #define XMLNS_VCARD "vcard-temp" /* XEP-0054 */ +#define XMLNS_DELAY "jabber:x:delay" /* XEP-0091 */ #define XMLNS_CHATSTATES "http://jabber.org/protocol/chatstates" /* 0085 */ #define XMLNS_DISCOVER "http://jabber.org/protocol/disco#info" /* 0030 */ #define XMLNS_MUC "http://jabber.org/protocol/muc" /* XEP-0045 */ @@ -191,6 +192,7 @@ struct jabber_buddy *jabber_buddy_by_jid( struct im_connection *ic, char *jid, g int jabber_buddy_remove( struct im_connection *ic, char *full_jid ); int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid ); struct groupchat *jabber_chat_by_name( struct im_connection *ic, const char *name ); +time_t jabber_get_timestamp( struct xt_node *xt ); extern const struct jabber_away_state jabber_away_state_list[]; @@ -210,6 +212,7 @@ gboolean sasl_supported( struct im_connection *ic ); /* conference.c */ struct groupchat *jabber_chat_join( struct im_connection *ic, char *room, char *nick, char *password ); +int jabber_chat_msg( struct groupchat *ic, char *message, int flags ); int jabber_chat_leave( struct groupchat *c, const char *reason ); void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bud, struct xt_node *node ); void jabber_chat_pkt_message( struct im_connection *ic, struct jabber_buddy *bud, struct xt_node *node ); diff --git a/protocols/jabber/jabber_util.c b/protocols/jabber/jabber_util.c index 86ddf7bc..091e6c7d 100644 --- a/protocols/jabber/jabber_util.c +++ b/protocols/jabber/jabber_util.c @@ -557,3 +557,52 @@ struct groupchat *jabber_chat_by_name( struct im_connection *ic, const char *nam return ret; } + +time_t jabber_get_timestamp( struct xt_node *xt ) +{ + struct tm tp, utc; + struct xt_node *c; + time_t res, tres; + char *s = NULL; + + for( c = xt->children; ( c = xt_find_node( c, "x" ) ); c = c->next ) + { + if( ( s = xt_find_attr( c, "xmlns" ) ) && strcmp( s, XMLNS_DELAY ) == 0 ) + break; + } + + if( !c || !( s = xt_find_attr( c, "stamp" ) ) ) + return 0; + + memset( &tp, 0, sizeof( tp ) ); + if( sscanf( s, "%4d%2d%2dT%2d:%2d:%2d", &tp.tm_year, &tp.tm_mon, &tp.tm_mday, + &tp.tm_hour, &tp.tm_min, &tp.tm_sec ) != 6 ) + return 0; + + tp.tm_year -= 1900; + tp.tm_mon --; + tp.tm_isdst = -1; /* GRRRRRRRRRRR */ + + res = mktime( &tp ); + /* Problem is, mktime() just gave us the GMT timestamp for the + given local time... While the given time WAS NOT local. So + we should fix this now. + + Now I could choose between messing with environment variables + (kludgy) or using timegm() (not portable)... Or doing the + following, which I actually prefer... */ + gmtime_r( &res, &utc ); + utc.tm_isdst = -1; /* Once more: GRRRRRRRRRRRRRRRRRR!!! */ + if( utc.tm_hour == tp.tm_hour && utc.tm_min == tp.tm_min ) + /* Sweet! We're in UTC right now... */ + return res; + + tres = mktime( &utc ); + res += res - tres; + + /* Yes, this is a hack. And it will go wrong around DST changes. + BUT this is more likely to be threadsafe than messing with + environment variables, and possibly more portable... */ + + return res; +} diff --git a/protocols/jabber/message.c b/protocols/jabber/message.c index 8a4ecaf4..198fc3b9 100644 --- a/protocols/jabber/message.c +++ b/protocols/jabber/message.c @@ -80,7 +80,8 @@ xt_status jabber_pkt_message( struct xt_node *node, gpointer data ) fullmsg = g_string_append( fullmsg, body->text ); if( fullmsg->len > 0 ) - imcb_buddy_msg( ic, bud ? bud->bare_jid : from, fullmsg->str, 0, 0 ); + imcb_buddy_msg( ic, bud ? bud->bare_jid : from, fullmsg->str, + 0, jabber_get_timestamp( node ) ); g_string_free( fullmsg, TRUE ); diff --git a/protocols/jabber/xmltree.c b/protocols/jabber/xmltree.c index c8bef362..9e16b939 100644 --- a/protocols/jabber/xmltree.c +++ b/protocols/jabber/xmltree.c @@ -187,7 +187,7 @@ int xt_handle( struct xt_parser *xt, struct xt_node *node, int depth ) /* If there's no parent, the handler should mention <root> as a parent. */ g_strcasecmp( xt->handlers[i].parent, "<root>" ) == 0 ) ) ) { - xt_print( node ); +// xt_print( node ); st = xt->handlers[i].func( node, xt->data ); |