Changeset b308cf9 for protocols/nogaim.c


Ignore:
Timestamp:
2010-06-05T23:21:02Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
1fdb0a4
Parents:
3ab1d31 (diff), e774815 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging libpurple branch into killerbee. It's fairly usable already, and
Debian packaging is now properly separated. This also picks up a load of
stuff from mainline it seems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/nogaim.c

    r3ab1d31 rb308cf9  
    3939
    4040static int remove_chat_buddy_silent( struct groupchat *b, const char *handle );
     41static char *format_timestamp( irc_t *irc, time_t msg_ts );
    4142
    4243GSList *connections;
     
    116117{
    117118        GList *gl;
    118         for (gl = protocols; gl; gl = gl->next)
     119       
     120        for( gl = protocols; gl; gl = gl->next )
    119121        {
    120122                struct prpl *proto = gl->data;
    121                 if(!g_strcasecmp(proto->name, name))
     123               
     124                if( g_strcasecmp( proto->name, name ) == 0 )
    122125                        return proto;
    123126        }
     127       
    124128        return NULL;
    125129}
     
    132136        extern void byahoo_initmodule();
    133137        extern void jabber_initmodule();
     138        extern void twitter_initmodule();
     139        extern void purple_initmodule();
    134140
    135141#ifdef WITH_MSN
     
    147153#ifdef WITH_JABBER
    148154        jabber_initmodule();
     155#endif
     156
     157#ifdef WITH_TWITTER
     158        twitter_initmodule();
     159#endif
     160       
     161#ifdef WITH_PURPLE
     162        purple_initmodule();
    149163#endif
    150164
     
    651665        u->away = u->status_msg = NULL;
    652666       
    653         if( ( flags & OPT_LOGGED_IN ) && !u->online )
    654         {
     667        if( set_getbool( &ic->irc->set, "show_offline" ) && !u->online )
     668        {
     669                /* always set users as online */
    655670                irc_spawn( ic->irc, u );
    656671                u->online = 1;
     672                if( !( flags & OPT_LOGGED_IN ) )
     673                {
     674                        /* set away message if user isn't really online */
     675                        u->away = g_strdup( "User is offline" );
     676                }
     677        }
     678        else if( ( flags & OPT_LOGGED_IN ) && !u->online )
     679        {
     680                irc_spawn( ic->irc, u );
     681                u->online = 1;
    657682        }
    658683        else if( !( flags & OPT_LOGGED_IN ) && u->online )
     
    660685                struct groupchat *c;
    661686               
    662                 irc_kill( ic->irc, u );
    663                 u->online = 0;
    664                
    665                 /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */
    666                 for( c = ic->groupchats; c; c = c->next )
    667                         remove_chat_buddy_silent( c, handle );
    668         }
    669        
     687                if( set_getbool( &ic->irc->set, "show_offline" ) )
     688                {
     689                        /* keep offline users in channel and set away message to "offline" */
     690                        u->away = g_strdup( "User is offline" );
     691
     692                        /* Keep showing him/her in the control channel but not in groupchats. */
     693                        for( c = ic->groupchats; c; c = c->next )
     694                        {
     695                                if( remove_chat_buddy_silent( c, handle ) && c->joined )
     696                                        irc_part( c->ic->irc, u, c->channel );
     697                        }
     698                }
     699                else
     700                {
     701                        /* kill offline users */
     702                        irc_kill( ic->irc, u );
     703                        u->online = 0;
     704
     705                        /* Remove him/her from the groupchats to prevent PART messages after he/she QUIT already */
     706                        for( c = ic->groupchats; c; c = c->next )
     707                                remove_chat_buddy_silent( c, handle );
     708                }
     709        }
     710
    670711        if( flags & OPT_AWAY )
    671712        {
     
    692733        }
    693734       
    694         /* LISPy... */
    695         if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) &&         /* Don't do a thing when user doesn't want it */
    696             ( u->online ) &&                                            /* Don't touch offline people */
    697             ( ( ( u->online != oo ) && !u->away ) ||                    /* Voice joining people */
    698               ( ( u->online == oo ) && ( oa == !u->away ) ) ) )         /* (De)voice people changing state */
     735        /* early if-clause for show_offline even if there is some redundant code here because this isn't LISP but C ;) */
     736        if( set_getbool( &ic->irc->set, "show_offline" ) && set_getbool( &ic->irc->set, "away_devoice" ) )
    699737        {
    700738                char *from;
     
    709747                                                            ic->irc->myhost );
    710748                }
    711                 irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel,
    712                                                           u->away?'-':'+', u->nick );
    713                 g_free( from );
     749
     750                /* if we use show_offline, we op online users, voice away users, and devoice/deop offline users */
     751                if( flags & OPT_LOGGED_IN )
     752                {
     753                        /* user is "online" (either really online or away) */
     754                        irc_write( ic->irc, ":%s MODE %s %cv%co %s %s", from, ic->irc->channel,
     755                                                                  u->away?'+':'-', u->away?'-':'+', u->nick, u->nick );
     756                }
     757                else
     758                {
     759                        /* user is offline */
     760                        irc_write( ic->irc, ":%s MODE %s -vo %s %s", from, ic->irc->channel, u->nick, u->nick );
     761                }
     762        }
     763        else
     764        {
     765                /* LISPy... */
     766                if( ( set_getbool( &ic->irc->set, "away_devoice" ) ) &&         /* Don't do a thing when user doesn't want it */
     767                    ( u->online ) &&                                            /* Don't touch offline people */
     768                    ( ( ( u->online != oo ) && !u->away ) ||                    /* Voice joining people */
     769                      ( ( u->online == oo ) && ( oa == !u->away ) ) ) )         /* (De)voice people changing state */
     770                {
     771                        char *from;
     772
     773                        if( set_getbool( &ic->irc->set, "simulate_netsplit" ) )
     774                        {
     775                                from = g_strdup( ic->irc->myhost );
     776                        }
     777                        else
     778                        {
     779                                from = g_strdup_printf( "%s!%s@%s", ic->irc->mynick, ic->irc->mynick,
     780                                                                    ic->irc->myhost );
     781                        }
     782                        irc_write( ic->irc, ":%s MODE %s %cv %s", from, ic->irc->channel,
     783                                                                  u->away?'-':'+', u->nick );
     784                        g_free( from );
     785                }
    714786        }
    715787}
     
    718790{
    719791        irc_t *irc = ic->irc;
    720         char *wrapped;
     792        char *wrapped, *ts = NULL;
    721793        user_t *u;
    722794       
     
    760832            ( ( ic->flags & OPT_DOES_HTML ) && set_getbool( &ic->irc->set, "strip_html" ) ) )
    761833                strip_html( msg );
    762 
     834       
     835        if( set_getbool( &ic->irc->set, "display_timestamps" ) &&
     836            ( ts = format_timestamp( irc, sent_at ) ) )
     837        {
     838                char *new = g_strconcat( ts, msg, NULL );
     839                g_free( ts );
     840                ts = msg = new;
     841        }
     842       
    763843        wrapped = word_wrap( msg, 425 );
    764844        irc_msgfrom( irc, u->nick, wrapped );
    765845        g_free( wrapped );
     846        g_free( ts );
    766847}
    767848
     
    805886       
    806887        return c;
     888}
     889
     890void imcb_chat_name_hint( struct groupchat *c, const char *name )
     891{
     892        if( !c->joined )
     893        {
     894                struct im_connection *ic = c->ic;
     895                char stripped[MAX_NICK_LENGTH+1], *full_name;
     896               
     897                strncpy( stripped, name, MAX_NICK_LENGTH );
     898                stripped[MAX_NICK_LENGTH] = '\0';
     899                nick_strip( stripped );
     900                if( set_getbool( &ic->irc->set, "lcnicks" ) )
     901                        nick_lc( stripped );
     902               
     903                full_name = g_strdup_printf( "&%s", stripped );
     904               
     905                if( stripped[0] &&
     906                    nick_cmp( stripped, ic->irc->channel + 1 ) != 0 &&
     907                    irc_chat_by_channel( ic->irc, full_name ) == NULL )
     908                {
     909                        g_free( c->channel );
     910                        c->channel = full_name;
     911                }
     912                else
     913                {
     914                        g_free( full_name );
     915                }
     916        }
    807917}
    808918
     
    867977        if( c && u )
    868978        {
    869                 irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, "", wrapped );
     979                char *ts = NULL;
     980                if( set_getbool( &ic->irc->set, "display_timestamps" ) )
     981                        ts = format_timestamp( ic->irc, sent_at );
     982                irc_privmsg( ic->irc, u, "PRIVMSG", c->channel, ts ? : "", wrapped );
     983                g_free( ts );
    870984        }
    871985        else
     
    10611175}
    10621176
    1063 
    1064 
     1177char *set_eval_timezone( set_t *set, char *value )
     1178{
     1179        char *s;
     1180       
     1181        if( strcmp( value, "local" ) == 0 ||
     1182            strcmp( value, "gmt" ) == 0 || strcmp( value, "utc" ) == 0 )
     1183                return value;
     1184       
     1185        /* Otherwise: +/- at the beginning optional, then one or more numbers,
     1186           possibly followed by a colon and more numbers. Don't bother bound-
     1187           checking them since users are free to shoot themselves in the foot. */
     1188        s = value;
     1189        if( *s == '+' || *s == '-' )
     1190                s ++;
     1191       
     1192        /* \d+ */
     1193        if( !isdigit( *s ) )
     1194                return SET_INVALID;
     1195        while( *s && isdigit( *s ) ) s ++;
     1196       
     1197        /* EOS? */
     1198        if( *s == '\0' )
     1199                return value;
     1200       
     1201        /* Otherwise, colon */
     1202        if( *s != ':' )
     1203                return SET_INVALID;
     1204        s ++;
     1205       
     1206        /* \d+ */
     1207        if( !isdigit( *s ) )
     1208                return SET_INVALID;
     1209        while( *s && isdigit( *s ) ) s ++;
     1210       
     1211        /* EOS */
     1212        return *s == '\0' ? value : SET_INVALID;
     1213}
     1214
     1215static char *format_timestamp( irc_t *irc, time_t msg_ts )
     1216{
     1217        time_t now_ts = time( NULL );
     1218        struct tm now, msg;
     1219        char *set;
     1220       
     1221        /* If the timestamp is <= 0 or less than a minute ago, discard it as
     1222           it doesn't seem to add to much useful info and/or might be noise. */
     1223        if( msg_ts <= 0 || msg_ts > now_ts - 60 )
     1224                return NULL;
     1225       
     1226        set = set_getstr( &irc->set, "timezone" );
     1227        if( strcmp( set, "local" ) == 0 )
     1228        {
     1229                localtime_r( &now_ts, &now );
     1230                localtime_r( &msg_ts, &msg );
     1231        }
     1232        else
     1233        {
     1234                int hr, min = 0, sign = 60;
     1235               
     1236                if( set[0] == '-' )
     1237                {
     1238                        sign *= -1;
     1239                        set ++;
     1240                }
     1241                else if( set[0] == '+' )
     1242                {
     1243                        set ++;
     1244                }
     1245               
     1246                if( sscanf( set, "%d:%d", &hr, &min ) >= 1 )
     1247                {
     1248                        msg_ts += sign * ( hr * 60 + min );
     1249                        now_ts += sign * ( hr * 60 + min );
     1250                }
     1251               
     1252                gmtime_r( &now_ts, &now );
     1253                gmtime_r( &msg_ts, &msg );
     1254        }
     1255       
     1256        if( msg.tm_year == now.tm_year && msg.tm_yday == now.tm_yday )
     1257                return g_strdup_printf( "\x02[\x02\x02\x02%02d:%02d:%02d\x02]\x02 ",
     1258                                        msg.tm_hour, msg.tm_min, msg.tm_sec );
     1259        else
     1260                return g_strdup_printf( "\x02[\x02\x02\x02%04d-%02d-%02d "
     1261                                        "%02d:%02d:%02d\x02]\x02 ",
     1262                                        msg.tm_year + 1900, msg.tm_mon + 1, msg.tm_mday,
     1263                                        msg.tm_hour, msg.tm_min, msg.tm_sec );
     1264}
    10651265
    10661266/* The plan is to not allow straight calls to prpl functions anymore, but do
     
    11051305{
    11061306        char *away, *msg = NULL;
     1307       
     1308        if( ic->acc->prpl->away_states == NULL ||
     1309            ic->acc->prpl->set_away == NULL )
     1310                return 0;
    11071311       
    11081312        away = set_getstr( &ic->acc->set, "away" ) ?
Note: See TracChangeset for help on using the changeset viewer.