Changeset 6bbb939 for protocols


Ignore:
Timestamp:
2007-04-16T04:01:13Z (17 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
cfc8d58
Parents:
84b045d
Message:

Split serv_got_update() into imcb_buddy_(status|times). (Well, the second
one isn't implemented yet, but I'll do that later.) At last I got rid of
the hack called get_status_string(). And now Yahoo seems to mess up away
messages...

Location:
protocols
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • protocols/jabber/iq.c

    r84b045d r6bbb939  
    388388                                   just try to handle this as well as we can. */
    389389                                jabber_buddy_remove_bare( ic, jid );
    390                                 serv_got_update( ic, jid, 0, 0, 0, 0, 0, 0 );
     390                                imcb_buddy_status( ic, jid, 0, NULL, NULL );
    391391                                /* FIXME! */
    392392                        }
  • protocols/jabber/presence.c

    r84b045d r6bbb939  
    3838        if( type == NULL )
    3939        {
     40                int is_away = 0;
     41               
    4042                if( !( bud = jabber_buddy_by_jid( ic, from, GET_BUDDY_EXACT | GET_BUDDY_CREAT ) ) )
    4143                {
     
    5254               
    5355                if( ( c = xt_find_node( node->children, "show" ) ) && c->text_len > 0 )
     56                {
    5457                        bud->away_state = (void*) jabber_away_state_by_code( c->text );
     58                        if( strcmp( c->text, "chat" ) != 0 )
     59                                is_away = OPT_AWAY;
     60                }
    5561                else
    5662                {
     
    6672                        bud->priority = 0;
    6773               
    68                 serv_got_update( ic, bud->bare_jid, 1, 0, 0, 0,
    69                                  bud->away_state ? UC_UNAVAILABLE : 0, 0 );
     74                /* FIXME: What to send if there are other resources??? */
     75                imcb_buddy_status( ic, bud->bare_jid, OPT_LOGGED_IN | is_away,
     76                                   bud->away_state->full_name, bud->away_message );
    7077        }
    7178        else if( strcmp( type, "unavailable" ) == 0 )
     
    8794                           available anymore. */
    8895                        if( jabber_buddy_by_jid( ic, from, 0 ) == NULL )
    89                                 serv_got_update( ic, from, 0, 0, 0, 0, 0, 0 );
     96                                imcb_buddy_status( ic, from, 0, NULL, NULL );
    9097                       
    9198                        *s = '/';
     
    93100                else
    94101                {
    95                         serv_got_update( ic, from, 0, 0, 0, 0, 0, 0 );
     102                        imcb_buddy_status( ic, from, 0, NULL, NULL );
    96103                }
    97104        }
  • protocols/msn/msn.c

    r84b045d r6bbb939  
    192192}
    193193
    194 static char *msn_get_status_string( struct im_connection *ic, int number )
    195 {
    196         const struct msn_away_state *st = msn_away_state_by_number( number );
    197        
    198         if( st )
    199                 return( (char*) st->name );
    200         else
    201                 return( "" );
    202 }
    203 
    204194static void msn_set_away( struct im_connection *ic, char *state, char *message )
    205195{
     
    399389        ret->send_im = msn_send_im;
    400390        ret->away_states = msn_away_states;
    401         ret->get_status_string = msn_get_status_string;
    402391        ret->set_away = msn_set_away;
    403392        ret->get_info = msn_get_info;
  • protocols/msn/ns.c

    r84b045d r6bbb939  
    400400                }
    401401               
    402                 serv_got_update( ic, cmd[3], 1, 0, 0, 0, st->number, 0 );
     402                imcb_buddy_status( ic, cmd[3], OPT_LOGGED_IN |
     403                                   ( st->number ? OPT_AWAY : 0 ), st->name, NULL );
    403404        }
    404405        else if( strcmp( cmd[0], "FLN" ) == 0 )
    405406        {
    406407                if( cmd[1] )
    407                         serv_got_update( ic, cmd[1], 0, 0, 0, 0, 0, 0 );
     408                        imcb_buddy_status( ic, cmd[1], 0, NULL, NULL );
    408409        }
    409410        else if( strcmp( cmd[0], "NLN" ) == 0 )
     
    428429                }
    429430               
    430                 serv_got_update( ic, cmd[2], 1, 0, 0, 0, st->number, 0 );
     431                imcb_buddy_status( ic, cmd[2], OPT_LOGGED_IN |
     432                                   ( st->number ? OPT_AWAY : 0 ), st->name, NULL );
    431433        }
    432434        else if( strcmp( cmd[0], "RNG" ) == 0 )
  • protocols/nogaim.c

    r84b045d r6bbb939  
    187187
    188188        if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
    189             ( ( ic->flags & OPT_CONN_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
     189            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
    190190                strip_html( text );
    191191       
     
    494494/* server.c */                   
    495495
    496 void serv_got_update( struct im_connection *ic, char *handle, int loggedin, int evil, time_t signon, time_t idle, int type, guint caps )
     496void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message )
    497497{
    498498        user_t *u;
    499499        int oa, oo;
    500500       
    501         u = user_findhandle( ic, handle );
     501        u = user_findhandle( ic, (char*) handle );
    502502       
    503503        if( !u )
     
    505505                if( g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "add" ) == 0 )
    506506                {
    507                         add_buddy( ic, NULL, handle, NULL );
    508                         u = user_findhandle( ic, handle );
     507                        add_buddy( ic, NULL, (char*) handle, NULL );
     508                        u = user_findhandle( ic, (char*) handle );
    509509                }
    510510                else
     
    512512                        if( set_getbool( &ic->irc->set, "debug" ) || g_strcasecmp( set_getstr( &ic->irc->set, "handle_unknown" ), "ignore" ) != 0 )
    513513                        {
    514                                 imcb_log( ic, "serv_got_update() for handle %s:", handle );
    515                                 imcb_log( ic, "loggedin = %d, type = %d", loggedin, type );
     514                                imcb_log( ic, "imcb_buddy_status() for unknown handle %s:", handle );
     515                                imcb_log( ic, "flags = %d, state = %s, message = %s", flags,
     516                                          state ? state : "NULL", message ? message : "NULL" );
    516517                        }
    517518                       
    518519                        return;
    519520                }
    520                 /* Why did we have this here....
    521                 return; */
    522521        }
    523522       
     
    531530        }
    532531       
    533         if( loggedin && !u->online )
     532        if( ( flags & OPT_LOGGED_IN ) && !u->online )
    534533        {
    535534                irc_spawn( ic->irc, u );
    536535                u->online = 1;
    537536        }
    538         else if( !loggedin && u->online )
     537        else if( !( flags & OPT_LOGGED_IN ) && u->online )
    539538        {
    540539                struct groupchat *c;
     
    545544                /* Remove him/her from the conversations to prevent PART messages after he/she QUIT already */
    546545                for( c = ic->conversations; c; c = c->next )
    547                         remove_chat_buddy_silent( c, handle );
    548         }
    549        
    550         if( ( type & UC_UNAVAILABLE ) && ( strcmp( ic->acc->prpl->name, "oscar" ) == 0 || strcmp( ic->acc->prpl->name, "icq" ) == 0 ) )
    551         {
    552                 u->away = g_strdup( "Away" );
    553         }
    554         else if( ( type & UC_UNAVAILABLE ) && ic->acc->prpl->get_status_string )
    555         {
    556                 u->away = g_strdup( ic->acc->prpl->get_status_string( ic, type ) );
    557         }
    558         else
    559                 u->away = NULL;
     546                        remove_chat_buddy_silent( c, (char*) handle );
     547        }
     548       
     549        if( flags & OPT_AWAY )
     550        {
     551                if( state && message )
     552                {
     553                        u->away = g_strdup_printf( "%s (%s)", state, message );
     554                }
     555                else if( state )
     556                {
     557                        u->away = g_strdup( state );
     558                }
     559                else if( message )
     560                {
     561                        u->away = g_strdup( message );
     562                }
     563                else
     564                {
     565                        u->away = g_strdup( "Away" );
     566                }
     567        }
     568        /* else waste_any_state_information_for_now(); */
    560569       
    561570        /* LISPy... */
     
    612621       
    613622        if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
    614             ( ( ic->flags & OPT_CONN_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
     623            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
    615624                strip_html( msg );
    616625
     
    718727       
    719728        if( ( g_strcasecmp( set_getstr( &ic->irc->set, "strip_html" ), "always" ) == 0 ) ||
    720             ( ( ic->flags & OPT_CONN_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
     729            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
    721730                strip_html( msg );
    722731       
     
    925934        int st;
    926935       
    927         if( ( ic->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) )
     936        if( ( ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) )
    928937        {
    929938                buf = escape_html( msg );
     
    941950        char *buf = NULL;
    942951       
    943         if( ( c->ic->flags & OPT_CONN_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) )
     952        if( ( c->ic->flags & OPT_DOES_HTML ) && ( g_strncasecmp( msg, "<html>", 6 ) != 0 ) )
    944953        {
    945954                buf = escape_html( msg );
  • protocols/nogaim.h

    r84b045d r6bbb939  
    66
    77/*
    8  * nogaim
     8 * nogaim, soon to be known as im_api. Not a separate product (unless
     9 * someone would be interested in such a thing), just a new name.
    910 *
    1011 * Gaim without gaim - for BitlBee
     
    1516 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
    1617 *                          (and possibly other members of the Gaim team)
    17  * Copyright 2002-2004 Wilmer van der Gaast <wilmer@gaast.net>
     18 * Copyright 2002-2007 Wilmer van der Gaast <wilmer@gaast.net>
    1819 */
    1920
     
    4445#include "sha.h"
    4546
    46 
    4747#define BUF_LEN MSG_LEN
    4848#define BUF_LONG ( BUF_LEN * 2 )
     
    5454
    5555#define WEBSITE "http://www.bitlbee.org/"
    56 #define IM_FLAG_AWAY 0x0020
    5756#define GAIM_AWAY_CUSTOM "Custom"
    5857
    59 #define OPT_CONN_HTML   0x00000001
    60 #define OPT_LOGGED_IN   0x00010000
    61 #define OPT_LOGGING_OUT 0x00020000
     58/* Sharing flags between buddies and connections. Or planning to, at least... */
     59#define OPT_LOGGED_IN   0x00000001
     60#define OPT_LOGGING_OUT 0x00000002
     61#define OPT_AWAY        0x00000004
     62#define OPT_DOES_HTML   0x00000010
    6263
    6364/* ok. now the fun begins. first we create a connection structure */
     
    6566{
    6667        account_t *acc;
    67         guint32 flags;
     68        u_int32_t flags;
    6869       
    6970        /* each connection then can have its own protocol-specific data */
     
    164165             (* chat_join)      (struct im_connection *, char *chat, char *nick, char *password);
    165166       
    166         /* DIE! */
    167         char *(* get_status_string) (struct im_connection *ic, int stat);
    168        
    169167        GList *(* away_states)(struct im_connection *ic);
    170168       
     
    201199G_MODULE_EXPORT void serv_got_chat_left( struct groupchat *c );
    202200struct groupchat *chat_by_channel( char *channel );
    203 struct groupchat *chat_by_id( int id );
    204201
    205202/* Buddy management */
     
    209206
    210207/* Buddy activity */
    211 G_MODULE_EXPORT void serv_got_update( struct im_connection *ic, char *handle, int loggedin, int evil, time_t signon, time_t idle, int type, guint caps );
     208G_MODULE_EXPORT void imcb_buddy_status( struct im_connection *ic, const char *handle, int flags, const char *state, const char *message );
     209/* Not implemented yet! */ G_MODULE_EXPORT void imcb_buddy_times( struct im_connection *ic, const char *handle, time_t login, time_t idle );
    212210G_MODULE_EXPORT void serv_got_im( struct im_connection *ic, char *handle, char *msg, guint32 flags, time_t mtime, gint len );
    213211G_MODULE_EXPORT void serv_got_typing( struct im_connection *ic, char *handle, int timeout, int type );
  • protocols/oscar/oscar.c

    r84b045d r6bbb939  
    365365                   Let's hope nothing will break. ;-) */
    366366        } else {
    367                 ic->flags |= OPT_CONN_HTML;
     367                ic->flags |= OPT_DOES_HTML;
    368368        }
    369369
     
    968968        aim_userinfo_t *info;
    969969        time_t time_idle = 0, signon = 0;
    970         int type = 0;
    971         int caps = 0;
    972         char *tmp;
     970        int flags = OPT_LOGGED_IN;
     971        char *tmp, *state_string = NULL;
    973972
    974973        va_list ap;
     
    977976        va_end(ap);
    978977
    979         if (info->present & AIM_USERINFO_PRESENT_CAPABILITIES)
    980                 caps = info->capabilities;
    981         if (info->flags & AIM_FLAG_ACTIVEBUDDY)
    982                 type |= UC_AB;
    983 
    984978        if ((!od->icq) && (info->present & AIM_USERINFO_PRESENT_FLAGS)) {
    985                 if (info->flags & AIM_FLAG_UNCONFIRMED)
    986                         type |= UC_UNCONFIRMED;
    987                 if (info->flags & AIM_FLAG_ADMINISTRATOR)
    988                         type |= UC_ADMIN;
    989                 if (info->flags & AIM_FLAG_AOL)
    990                         type |= UC_AOL;
    991                 if (info->flags & AIM_FLAG_FREE)
    992                         type |= UC_NORMAL;
    993979                if (info->flags & AIM_FLAG_AWAY)
    994                         type |= UC_UNAVAILABLE;
    995                 if (info->flags & AIM_FLAG_WIRELESS)
    996                         type |= UC_WIRELESS;
    997         }
     980                        flags |= OPT_AWAY;
     981        }
     982       
    998983        if (info->present & AIM_USERINFO_PRESENT_ICQEXTSTATUS) {
    999                 type = (info->icqinfo.status << 7);
    1000984                if (!(info->icqinfo.status & AIM_ICQ_STATE_CHAT) &&
    1001985                      (info->icqinfo.status != AIM_ICQ_STATE_NORMAL)) {
    1002                         type |= UC_UNAVAILABLE;
     986                        flags |= OPT_AWAY;
    1003987                }
    1004         }
    1005 
    1006         if (caps & AIM_CAPS_ICQ)
    1007                 caps ^= AIM_CAPS_ICQ;
     988               
     989                if( info->icqinfo.status & AIM_ICQ_STATE_DND )
     990                        state_string = "Do Not Disturb";
     991                else if( info->icqinfo.status & AIM_ICQ_STATE_OUT )
     992                        state_string = "Not Available";
     993                else if( info->icqinfo.status & AIM_ICQ_STATE_BUSY )
     994                        state_string = "Occupied";
     995                else if( info->icqinfo.status & AIM_ICQ_STATE_INVISIBLE )
     996                        state_string = "Invisible";
     997        }
    1008998
    1009999        if (info->present & AIM_USERINFO_PRESENT_IDLE) {
     
    10201010        g_free(tmp);
    10211011
    1022         serv_got_update(ic, info->sn, 1, info->warnlevel/10, signon,
    1023                         time_idle, type, caps);
     1012        imcb_buddy_status(ic, info->sn, flags, state_string, NULL);
     1013        /* imcb_buddy_times(ic, info->sn, signon, time_idle); */
    10241014
    10251015        return 1;
     
    10351025        va_end(ap);
    10361026
    1037         serv_got_update(ic, info->sn, 0, 0, 0, 0, 0, 0);
     1027        imcb_buddy_status(ic, info->sn, 0, NULL, NULL );
    10381028
    10391029        return 1;
     
    10461036       
    10471037        if (args->icbmflags & AIM_IMFLAGS_AWAY)
    1048                 flags |= IM_FLAG_AWAY;
     1038                flags |= OPT_AWAY;
    10491039       
    10501040        if ((args->icbmflags & AIM_IMFLAGS_UNICODE) || (args->icbmflags & AIM_IMFLAGS_ISO_8859_1)) {
     
    18211811        struct oscar_data *odata = (struct oscar_data *)ic->proto_data;
    18221812        int ret = 0, len = strlen(message);
    1823         if (imflags & IM_FLAG_AWAY) {
     1813        if (imflags & OPT_AWAY) {
    18241814                ret = aim_send_im(odata->sess, name, AIM_IMFLAGS_AWAY, message);
    18251815        } else {
     
    24452435}
    24462436
    2447 static char *oscar_get_status_string( struct im_connection *ic, int number )
    2448 {
    2449         struct oscar_data *od = ic->proto_data;
    2450        
    2451         if( ! number & UC_UNAVAILABLE )
    2452         {
    2453                 return( NULL );
    2454         }
    2455         else if( od->icq )
    2456         {
    2457                 number >>= 7;
    2458                 if( number & AIM_ICQ_STATE_DND )
    2459                         return( "Do Not Disturb" );
    2460                 else if( number & AIM_ICQ_STATE_OUT )
    2461                         return( "Not Available" );
    2462                 else if( number & AIM_ICQ_STATE_BUSY )
    2463                         return( "Occupied" );
    2464                 else if( number & AIM_ICQ_STATE_INVISIBLE )
    2465                         return( "Invisible" );
    2466                 else
    2467                         return( "Away" );
    2468         }
    2469         else
    2470         {
    2471                 return( "Away" );
    2472         }
    2473 }
    2474 
    24752437int oscar_send_typing(struct im_connection *ic, char * who, int typing)
    24762438{
     
    26332595        ret->rem_deny = oscar_rem_deny;
    26342596        ret->set_permit_deny = oscar_set_permit_deny;
    2635         ret->get_status_string = oscar_get_status_string;
    26362597        ret->send_typing = oscar_send_typing;
    26372598       
  • protocols/yahoo/yahoo.c

    r84b045d r6bbb939  
    293293}
    294294
    295 static char *byahoo_get_status_string( struct im_connection *ic, int stat )
    296 {
    297         enum yahoo_status a = stat >> 1;
    298        
    299         switch (a)
    300         {
    301         case YAHOO_STATUS_BRB:
    302                 return "Be Right Back";
    303         case YAHOO_STATUS_BUSY:
    304                 return "Busy";
    305         case YAHOO_STATUS_NOTATHOME:
    306                 return "Not At Home";
    307         case YAHOO_STATUS_NOTATDESK:
    308                 return "Not At Desk";
    309         case YAHOO_STATUS_NOTINOFFICE:
    310                 return "Not In Office";
    311         case YAHOO_STATUS_ONPHONE:
    312                 return "On Phone";
    313         case YAHOO_STATUS_ONVACATION:
    314                 return "On Vacation";
    315         case YAHOO_STATUS_OUTTOLUNCH:
    316                 return "Out To Lunch";
    317         case YAHOO_STATUS_STEPPEDOUT:
    318                 return "Stepped Out";
    319         case YAHOO_STATUS_INVISIBLE:
    320                 return "Invisible";
    321         case YAHOO_STATUS_CUSTOM:
    322                 return "Away";
    323         case YAHOO_STATUS_IDLE:
    324                 return "Idle";
    325         case YAHOO_STATUS_OFFLINE:
    326                 return "Offline";
    327         case YAHOO_STATUS_NOTIFY:
    328                 return "Notify";
    329         default:
    330                 return "Away";
    331         }
    332 }
    333 
    334295static void byahoo_chat_send( struct groupchat *c, char *message, int flags )
    335296{
     
    393354        ret->add_buddy = byahoo_add_buddy;
    394355        ret->remove_buddy = byahoo_remove_buddy;
    395         ret->get_status_string = byahoo_get_status_string;
    396356        ret->send_typing = byahoo_send_typing;
    397357       
     
    586546{
    587547        struct im_connection *ic = byahoo_get_ic_by_id( id );
    588        
    589         serv_got_update( ic, who, stat != YAHOO_STATUS_OFFLINE, 0, 0,
    590                          ( stat == YAHOO_STATUS_IDLE ) ? away : 0,
    591                          ( stat != YAHOO_STATUS_AVAILABLE ) | ( stat << 1 ), 0 );
     548        char *state_string = NULL;
     549        int flags = OPT_LOGGED_IN;
     550       
     551        if( away )
     552                flags |= OPT_AWAY;
     553       
     554        switch (stat)
     555        {
     556        case YAHOO_STATUS_BRB:
     557                state_string = "Be Right Back";
     558                break;
     559        case YAHOO_STATUS_BUSY:
     560                state_string = "Busy";
     561                break;
     562        case YAHOO_STATUS_NOTATHOME:
     563                state_string = "Not At Home";
     564                break;
     565        case YAHOO_STATUS_NOTATDESK:
     566                state_string = "Not At Desk";
     567                break;
     568        case YAHOO_STATUS_NOTINOFFICE:
     569                state_string = "Not In Office";
     570                break;
     571        case YAHOO_STATUS_ONPHONE:
     572                state_string = "On Phone";
     573                break;
     574        case YAHOO_STATUS_ONVACATION:
     575                state_string = "On Vacation";
     576                break;
     577        case YAHOO_STATUS_OUTTOLUNCH:
     578                state_string = "Out To Lunch";
     579                break;
     580        case YAHOO_STATUS_STEPPEDOUT:
     581                state_string = "Stepped Out";
     582                break;
     583        case YAHOO_STATUS_INVISIBLE:
     584                state_string = "Invisible";
     585                break;
     586        case YAHOO_STATUS_CUSTOM:
     587                state_string = "Away";
     588                break;
     589        case YAHOO_STATUS_IDLE:
     590                state_string = "Idle";
     591                break;
     592        case YAHOO_STATUS_OFFLINE:
     593                state_string = "Offline";
     594                flags = 0;
     595                break;
     596        case YAHOO_STATUS_NOTIFY:
     597                state_string = "Notify";
     598                break;
     599        }
     600       
     601        imcb_buddy_status( ic, who, flags, state_string, msg );
     602       
     603        /* Not implemented yet...
     604        if( stat == YAHOO_STATUS_IDLE )
     605                imcb_buddy_times( ic, who, 0, away );
     606        */
    592607}
    593608
Note: See TracChangeset for help on using the changeset viewer.