Changeset 43671b9


Ignore:
Timestamp:
2007-04-22T23:39:37Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
0e7ab64
Parents:
e35d1a1
Message:

You can send messages too now. But it's still very kludgy and doesn't work
with anonymous rooms (ie about 95% of all available Jabber chatrooms?).

Location:
protocols/jabber
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/conference.c

    re35d1a1 r43671b9  
    6262}
    6363
    64 int jabber_chat_leave( struct groupchat *c, const char *reason )
     64int jabber_chat_msg( struct groupchat *c, char *message, int flags )
    6565{
    6666        struct im_connection *ic = c->ic;
     
    6868        struct xt_node *node;
    6969       
     70        node = xt_new_node( "body", message, NULL );
     71        node = jabber_make_packet( "message", "groupchat", jc->name, node );
     72       
     73        if( !jabber_write_packet( ic, node ) )
     74        {
     75                xt_free_node( node );
     76                return 0;
     77        }
     78        xt_free_node( node );
     79       
     80        return 1;
     81}
     82
     83int jabber_chat_leave( struct groupchat *c, const char *reason )
     84{
     85        struct im_connection *ic = c->ic;
     86        struct jabber_chat *jc = c->data;
     87        struct xt_node *node;
     88       
    7089        node = xt_new_node( "x", NULL, NULL );
    7190        xt_add_attr( node, "xmlns", XMLNS_MUC );
     
    7897        }
    7998        xt_free_node( node );
    80        
    81         /* Remove all participants from jc->buddies and clean up our data. */
    82         jabber_buddy_remove_bare( ic, jc->name );
    83         g_free( jc->name );
    84         g_free( jc );
    85        
    86         /* And the generic stuff. */
    87         imcb_chat_free( c );
    8899       
    89100        return 1;
     
    188199                s = strchr( bud->orig_jid, '/' );
    189200                if( s ) *s = 0;
    190                 imcb_chat_msg( chat, bud->orig_jid, body->text, 0, 0 );
     201                imcb_chat_msg( chat, bud->orig_jid, body->text, 0, jabber_get_timestamp( node ) );
    191202                if( s ) *s = '/';
    192203        }
  • protocols/jabber/jabber.c

    re35d1a1 r43671b9  
    336336}
    337337
     338static void jabber_chat_msg_( struct groupchat *c, char *message, int flags )
     339{
     340        if( c && message )
     341                jabber_chat_msg( c, message, flags );
     342}
     343
    338344static void jabber_chat_leave_( struct groupchat *c )
    339345{
     
    406412        ret->buddy_msg = jabber_buddy_msg;
    407413        ret->away_states = jabber_away_states;
    408 //      ret->get_status_string = jabber_get_status_string;
    409414        ret->set_away = jabber_set_away;
    410415//      ret->set_info = jabber_set_info;
     
    412417        ret->add_buddy = jabber_add_buddy;
    413418        ret->remove_buddy = jabber_remove_buddy;
    414 //      ret->chat_msg = jabber_chat_msg;
     419        ret->chat_msg = jabber_chat_msg_;
    415420//      ret->chat_invite = jabber_chat_invite;
    416421        ret->chat_leave = jabber_chat_leave_;
  • protocols/jabber/jabber.h

    re35d1a1 r43671b9  
    144144#define XMLNS_TIME         "jabber:iq:time"                     /* XEP-0090 */
    145145#define XMLNS_VCARD        "vcard-temp"                         /* XEP-0054 */
     146#define XMLNS_DELAY        "jabber:x:delay"                     /* XEP-0091 */
    146147#define XMLNS_CHATSTATES   "http://jabber.org/protocol/chatstates"  /* 0085 */
    147148#define XMLNS_DISCOVER     "http://jabber.org/protocol/disco#info"  /* 0030 */
     
    192193int jabber_buddy_remove_bare( struct im_connection *ic, char *bare_jid );
    193194struct groupchat *jabber_chat_by_name( struct im_connection *ic, const char *name );
     195time_t jabber_get_timestamp( struct xt_node *xt );
    194196
    195197extern const struct jabber_away_state jabber_away_state_list[];
     
    211213/* conference.c */
    212214struct groupchat *jabber_chat_join( struct im_connection *ic, char *room, char *nick, char *password );
     215int jabber_chat_msg( struct groupchat *ic, char *message, int flags );
    213216int jabber_chat_leave( struct groupchat *c, const char *reason );
    214217void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bud, struct xt_node *node );
  • protocols/jabber/jabber_util.c

    re35d1a1 r43671b9  
    558558        return ret;
    559559}
     560
     561time_t jabber_get_timestamp( struct xt_node *xt )
     562{
     563        struct tm tp, utc;
     564        struct xt_node *c;
     565        time_t res, tres;
     566        char *s = NULL;
     567       
     568        for( c = xt->children; ( c = xt_find_node( c, "x" ) ); c = c->next )
     569        {
     570                if( ( s = xt_find_attr( c, "xmlns" ) ) && strcmp( s, XMLNS_DELAY ) == 0 )
     571                        break;
     572        }
     573       
     574        if( !c || !( s = xt_find_attr( c, "stamp" ) ) )
     575                return 0;
     576       
     577        memset( &tp, 0, sizeof( tp ) );
     578        if( sscanf( s, "%4d%2d%2dT%2d:%2d:%2d", &tp.tm_year, &tp.tm_mon, &tp.tm_mday,
     579                                                &tp.tm_hour, &tp.tm_min, &tp.tm_sec ) != 6 )
     580                return 0;
     581       
     582        tp.tm_year -= 1900;
     583        tp.tm_mon --;
     584        tp.tm_isdst = -1; /* GRRRRRRRRRRR */
     585       
     586        res = mktime( &tp );
     587        /* Problem is, mktime() just gave us the GMT timestamp for the
     588           given local time... While the given time WAS NOT local. So
     589           we should fix this now.
     590       
     591           Now I could choose between messing with environment variables
     592           (kludgy) or using timegm() (not portable)... Or doing the
     593           following, which I actually prefer... */
     594        gmtime_r( &res, &utc );
     595        utc.tm_isdst = -1; /* Once more: GRRRRRRRRRRRRRRRRRR!!! */
     596        if( utc.tm_hour == tp.tm_hour && utc.tm_min == tp.tm_min )
     597                /* Sweet! We're in UTC right now... */
     598                return res;
     599       
     600        tres = mktime( &utc );
     601        res += res - tres;
     602       
     603        /* Yes, this is a hack. And it will go wrong around DST changes.
     604           BUT this is more likely to be threadsafe than messing with
     605           environment variables, and possibly more portable... */
     606       
     607        return res;
     608}
  • protocols/jabber/message.c

    re35d1a1 r43671b9  
    8181               
    8282                if( fullmsg->len > 0 )
    83                         imcb_buddy_msg( ic, bud ? bud->bare_jid : from, fullmsg->str, 0, 0 );
     83                        imcb_buddy_msg( ic, bud ? bud->bare_jid : from, fullmsg->str,
     84                                        0, jabber_get_timestamp( node ) );
    8485               
    8586                g_string_free( fullmsg, TRUE );
  • protocols/jabber/xmltree.c

    re35d1a1 r43671b9  
    188188                                               g_strcasecmp( xt->handlers[i].parent, "<root>" ) == 0 ) ) )
    189189                        {
    190                                 xt_print( node );
     190//                              xt_print( node );
    191191                               
    192192                                st = xt->handlers[i].func( node, xt->data );
Note: See TracChangeset for help on using the changeset viewer.