Changeset e8c8d00


Ignore:
Timestamp:
2010-03-17T15:15:19Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
60e4df3
Parents:
1c3008a (diff), f9928cb (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 mainline.

Files:
37 edited

Legend:

Unmodified
Added
Removed
  • Makefile

    r1c3008a re8c8d00  
    4949
    5050clean: $(subdirs)
    51         rm -f *.o $(OUTFILE) core utils/bitlbeed encode decode
     51        rm -f *.o $(OUTFILE) core utils/bitlbeed
    5252        $(MAKE) -C tests clean
    5353
     
    124124endif
    125125
    126 encode: crypting.c
    127         $(CC) crypting.c lib/md5.c $(CFLAGS) -o encode -DCRYPTING_MAIN $(CFLAGS) $(EFLAGS) $(LFLAGS)
    128 
    129 decode: encode
    130         cp encode decode
    131 
    132126ctags:
    133127        ctags `find . -name "*.c"` `find . -name "*.h"`
  • account.c

    r1c3008a re8c8d00  
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
    4   * Copyright 2002-2004 Wilmer van der Gaast and others                *
     4  * Copyright 2002-2010 Wilmer van der Gaast and others                *
    55  \********************************************************************/
    66
     
    5555        s = set_add( &a->set, "auto_reconnect", "true", set_eval_bool, a );
    5656       
     57        s = set_add( &a->set, "nick_source", "handle", NULL, a );
     58       
    5759        s = set_add( &a->set, "password", NULL, set_eval_account, a );
    5860        s->flags |= ACC_SET_NOSAVE | SET_NULL_OK;
     
    6971                prpl->init( a );
    7072       
    71         return( a );
     73        s = set_add( &a->set, "away", NULL, set_eval_account, a );
     74        s->flags |= SET_NULL_OK;
     75       
     76        if( a->flags & ACC_FLAG_STATUS_MESSAGE )
     77        {
     78                s = set_add( &a->set, "status", NULL, set_eval_account, a );
     79                s->flags |= SET_NULL_OK;
     80        }
     81       
     82        return a;
    7283}
    7384
     
    121132               
    122133                acc->auto_connect = bool2int( value );
     134                return value;
     135        }
     136        else if( strcmp( set->key, "away" ) == 0 ||
     137                 strcmp( set->key, "status" ) == 0 )
     138        {
     139                if( acc->ic && acc->ic->flags & OPT_LOGGED_IN )
     140                {
     141                        /* If we're currently on-line, set the var now already
     142                           (bit of a hack) and send an update. */
     143                        g_free( set->value );
     144                        set->value = g_strdup( value );
     145                       
     146                        imc_away_send_update( acc->ic );
     147                }
     148               
    123149                return value;
    124150        }
     
    267293        p->max = 86400;
    268294       
    269         /* Format: /[0-9]+([*+][0-9]+(<[0-9+]))/ */
     295        /* Format: /[0-9]+([*+][0-9]+(<[0-9+])?)?/ */
    270296        while( *value && isdigit( *value ) )
    271297                p->start = p->start * 10 + *value++ - '0';
  • account.h

    r1c3008a re8c8d00  
    3737        int auto_reconnect_delay;
    3838        int reconnect;
     39        int flags;
    3940       
    4041        set_t *set;
     
    5657int account_reconnect_delay( account_t *a );
    5758
    58 #define ACC_SET_NOSAVE          0x01
    59 #define ACC_SET_OFFLINE_ONLY    0x02
    60 #define ACC_SET_ONLINE_ONLY     0x04
     59typedef enum
     60{
     61        ACC_SET_NOSAVE = 0x01,          /* Don't save this setting (i.e. stored elsewhere). */
     62        ACC_SET_OFFLINE_ONLY = 0x02,    /* Allow changes only if the acct is offline. */
     63        ACC_SET_ONLINE_ONLY = 0x04,     /* Allow changes only if the acct is online. */
     64} account_set_flag_t;
     65
     66typedef enum
     67{
     68        ACC_FLAG_AWAY_MESSAGE = 0x01,   /* Supports away messages instead of just states. */
     69        ACC_FLAG_STATUS_MESSAGE = 0x02, /* Supports status messages (without being away). */
     70} account_flag_t;
    6171
    6272#endif
  • bitlbee.c

    r1c3008a re8c8d00  
    109109                chdir( "/" );
    110110               
    111                 /* Sometimes std* are already closed (for example when we're in a RESTARTed
    112                    BitlBee process. So let's only close TTY-fds. */
    113                 if( isatty( 0 ) ) close( 0 );
    114                 if( isatty( 1 ) ) close( 1 );
    115                 if( isatty( 2 ) ) close( 2 );
     111                if( getenv( "_BITLBEE_RESTART_STATE" ) == NULL )
     112                        for( i = 0; i < 3; i ++ )
     113                                if( close( i ) == 0 )
     114                                {
     115                                        /* Keep something bogus on those fd's just in case. */
     116                                        open( "/dev/null", O_WRONLY );
     117                                }
    116118        }
    117119#endif
  • bitlbee.conf

    r1c3008a re8c8d00  
    5555##
    5656## Password the user should enter when logging into a closed BitlBee server.
    57 ## You can also have an MD5-encrypted password here. Format: "md5:", followed
    58 ## by a hash as generated for the <user password=""> attribute in a BitlBee
    59 ## XML file (for now there's no easier way to generate the hash).
     57## You can also have a BitlBee-style MD5 hash here. Format: "md5:", followed
     58## by a hash as generated by "bitlbee -x hash <password>".
    6059##
    6160# AuthPassword = ItllBeBitlBee   ## Heh.. Our slogan. ;-)
     
    121120## Proxy = socks5://socksproxy.localnet.com
    122121
     122## Protocols offered by bitlbee
     123##
     124## As recompiling may be quite unpractical for some people, this option
     125## allows to remove the support of protocol, even if compiled in. If
     126## nothing is given, there are no restrictions.
     127##
     128## Protocols = jabber yahoo
     129
    123130
    124131[defaults]
  • bitlbee.h

    r1c3008a re8c8d00  
    2727#define _BITLBEE_H
    2828
     29#ifndef _GNU_SOURCE
    2930#define _GNU_SOURCE /* Stupid GNU :-P */
     31#endif
    3032
    3133/* Depend on Windows 2000 for now since we need getaddrinfo() */
     
    3335
    3436#define PACKAGE "BitlBee"
    35 #define BITLBEE_VERSION "1.2.4"
     37#define BITLBEE_VERSION "1.2.5"
    3638#define VERSION BITLBEE_VERSION
    3739
  • conf.c

    r1c3008a re8c8d00  
    6666        conf->ft_max_kbps = G_MAXUINT;
    6767        conf->ft_listen = NULL;
     68        conf->protocols = NULL;
    6869        proxytype = 0;
    6970       
     
    130131                {
    131132                        printf( "Usage: bitlbee [-D/-F [-i <interface>] [-p <port>] [-n] [-v]] [-I]\n"
    132                                 "               [-c <file>] [-d <dir>] [-h]\n"
     133                                "               [-c <file>] [-d <dir>] [-x] [-h]\n"
    133134                                "\n"
    134135                                "An IRC-to-other-chat-networks gateway\n"
     
    146147                                "  -c  Load alternative configuration file\n"
    147148                                "  -d  Specify alternative user configuration directory\n"
     149                                "  -x  Command-line interface to password encryption/hashing\n"
    148150                                "  -h  Show this help page.\n" );
    149151                        return NULL;
     
    333335                                conf->ft_listen = g_strdup( ini->value );
    334336                        }
     337                        else if( g_strcasecmp( ini->key, "protocols" ) == 0 )
     338                        {
     339                                g_strfreev( conf->protocols );
     340                                conf->protocols = g_strsplit_set( ini->value, " \t,;", -1 );
     341                        }
    335342                        else
    336343                        {
  • conf.h

    r1c3008a re8c8d00  
    5353        int ft_max_kbps;
    5454        char *ft_listen;
     55        char **protocols;
    5556} conf_t;
    5657
  • configure

    r1c3008a re8c8d00  
    156156
    157157echo CFLAGS=$CFLAGS >> Makefile.settings
    158 echo CFLAGS+=-I`pwd` -I`pwd`/lib -I`pwd`/protocols -I. >> Makefile.settings
     158echo CFLAGS+=-I`pwd` -iquote`pwd`/lib -iquote`pwd`/protocols -I. >> Makefile.settings
    159159
    160160echo CFLAGS+=-DHAVE_CONFIG_H >> Makefile.settings
     
    360360       
    361361        ## Yes, you, at the console! How can you authenticate if you don't have any SSL!?
    362         if [ "$msn" = "1" ]; then
     362        if [ "$msn" = "1" -o "$yahoo" = "1" ]; then
    363363                echo
    364                 echo 'Real SSL support is necessary for MSN authentication, will build without'
    365                 echo 'MSN protocol support.'
     364                echo 'WARNING: The MSN and Yahoo! modules will not work without SSL. Disabling.'
    366365                msn=0
     366                yahoo=0
    367367        fi
    368368       
     
    444444fi
    445445
     446if [ ! -e doc/user-guide/help.txt ] && ! type xmlto > /dev/null 2> /dev/null; then
     447        echo
     448        echo 'WARNING: Building from an unreleased source tree without prebuilt helpfile.'
     449        echo 'Install xmlto if you want online help to work.'
     450fi
     451
    446452echo
    447453if [ -z "$BITLBEE_VERSION" -a -d .bzr ] && type bzr > /dev/null 2> /dev/null; then
     
    529535;;
    530536Darwin )
     537        echo 'STRIP=\# skip strip' >> Makefile.settings
    531538;;
    532539IRIX )
  • crypting.c

    r1c3008a re8c8d00  
    132132        return (rv);
    133133}
    134 
    135 #ifdef CRYPTING_MAIN
    136 
    137 /* A little main() function for people who want a stand-alone program to
    138    encode/decode BitlCrypted files. */
    139 
    140 int main( int argc, char *argv[] )
    141 {
    142         char *hash, *action, line[256];
    143         char* (*func)( char *, const char * );
    144        
    145         if( argc < 2 )
    146         {
    147                 fprintf( stderr, "Usage: %s <password>\n\n"
    148                                  "Reads from stdin, writes to stdout.\n"
    149                                  "Call as \"encode\" to encode, \"decode\" to decode.\n", argv[0] );
    150                 return( 1 );
    151         }
    152        
    153         hash = hashpass( argv[1] );
    154         action = argv[0] + strlen( argv[0] ) - strlen( "encode" );
    155        
    156         if( strcmp( action, "encode" ) == 0 )
    157         {
    158                 fwrite( hash, 32, 1, stdout );
    159                 func = obfucrypt;
    160         }
    161         else if( strcmp( action, "decode" ) == 0 )
    162         {
    163                 char hash2[32];
    164                
    165                 fread( hash2, 32, 1, stdin );
    166                 if( memcmp( hash, hash2, 32 ) != 0 )
    167                 {
    168                         fprintf( stderr, "Passwords don't match. Can't decode.\n" );
    169                         return( 1 );
    170                 }
    171                 func = deobfucrypt;
    172         }
    173         else
    174         {
    175                 return( main( 0, NULL ) );
    176         }
    177        
    178         while( fscanf( stdin, "%[^\n]255s", line ) > 0 )
    179         {
    180                 char *out;
    181                
    182                 /* Flush the newline */
    183                 fgetc( stdin );
    184                
    185                 out = func( line, argv[1] );
    186                 printf( "%s\n", out );
    187                 g_free( out );
    188         }
    189        
    190         return( 0 );
    191 }
    192 
    193 #endif
  • doc/CHANGES

    r1c3008a re8c8d00  
    33
    44http://bugs.bitlbee.org/bitlbee/timeline?daysback=90&changeset=on
     5
     6Version 1.2.5:
     7- Many bug fixes, including a fix for MSN login issues, Jabber login timing
     8  issues, Yahoo! crashes at login time with huge contact lists,
     9- Avoid linking in a static version of libresolv now that glibc has all
     10  relevant functions available in the dynamic version.
     11- Improved away state code and added the ability to set (non-away) status
     12  messages using "set status" (also possible per account) and see them in
     13  blist and /whois output.
     14- Added a post-1.2 equivalent of encode/decode to quickly encrypt/decrypt
     15  passwords in a way that BitlBee can read them.
     16- Allow using the full name for generating nicknames, instead of just the
     17  handle. This is especially useful when using the Facebook XMPP server.
     18- Auto reconnect is now enabled by default since all protocols can properly
     19  detect cases where auto reconnect should be avoided (i.e. concurrent
     20  logins).
     21- Changed the default resource_select setting which should reduce message
     22  routing issues on Jabber (i.e. messages going someone's phone instead of
     23  the main client).
     24
     25Fixed 17 Mar 2010
    526
    627Version 1.2.4:
  • doc/user-guide/commands.xml

    r1c3008a re8c8d00  
    436436        </bitlbee-setting>
    437437
     438        <bitlbee-setting name="away" type="string" scope="both">
     439                <description>
     440                        <para>
     441                                To mark yourself as away, it is recommended to just use <emphasis>/away</emphasis>, like on normal IRC networks. If you want to mark yourself as away on only one IM network, you can use this per-account setting.
     442                        </para>
     443
     444                        <para>
     445                                You can set it to any value and BitlBee will try to map it to the most appropriate away state for every open IM connection, or set it as a free-form away message where possible.
     446                        </para>
     447
     448                        <para>
     449                                Any per-account away setting will override globally set away states. To un-set the setting, use <emphasis>set -del away</emphasis>.
     450                        </para>
     451                </description>
     452        </bitlbee-setting>
     453
    438454        <bitlbee-setting name="away_devoice" type="boolean" scope="global">
    439455                <default>true</default>
     
    592608        </bitlbee-setting>
    593609
     610        <bitlbee-setting name="nick_source" type="string" scope="account">
     611                <default>handle</default>
     612                <possible-values>handle, full_name, first_name</possible-values>
     613
     614                <description>
     615                        <para>
     616                                By default, BitlBee generates a nickname for every contact by taking its handle and chopping off everything after the @. In some cases, this gives very inconvenient nicknames. The Facebook XMPP server is a good example, as all Facebook XMPP handles are numeric.
     617                        </para>
     618
     619                        <para>
     620                                With this setting set to <emphasis>full_name</emphasis>, the person's full name is used to generate a nickname. Or if you don't like long nicknames, set this setting to <emphasis>first_name</emphasis> instead and only the first word will be used. Note that the full name can be full of non-ASCII characters which will be stripped off.
     621                        </para>
     622                </description>
     623        </bitlbee-setting>
     624
    594625        <bitlbee-setting name="ops" type="string" scope="global">
    595626                <default>both</default>
     
    685716
    686717        <bitlbee-setting name="resource_select" type="string" scope="account">
    687                 <default>priority</default>
     718                <default>activity</default>
    688719                <possible-values>priority, activity</possible-values>
    689720
     
    743774                        <para>
    744775                                Currently only available for Jabber connections. Set this to true if the server accepts SSL connections.
     776                        </para>
     777                </description>
     778        </bitlbee-setting>
     779
     780        <bitlbee-setting name="status" type="string" scope="both">
     781                <description>
     782                        <para>
     783                                Certain protocols (like Jabber/XMPP) support status messages, similar to away messages. They can be used to indicate things like your location or activity, without showing up as away/busy.
     784                        </para>
     785
     786                        <para>
     787                                This setting can be used to set such a message. It will be available as a per-account setting for protocols that support it, and also as a global setting (which will then automatically be used for all protocols that support it).
     788                        </para>
     789
     790                        <para>
     791                                Away states set using <emphasis>/away</emphasis> or the <emphasis>away</emphasis> setting will override this setting. To un-set the setting, use <emphasis>set -del status</emphasis>.
    745792                        </para>
    746793                </description>
  • doc/user-guide/misc.xml

    r1c3008a re8c8d00  
    8686
    8787<para>
    88 As you might've expected, you can just use the <emphasis>/away</emphasis> command in your IRC client to set an away-state. BitlBee supports most away-states supported by the protocols.
     88To mark yourself as away, you can just use the <emphasis>/away</emphasis> command in your IRC client. BitlBee supports most away-states supported by the protocols.
    8989</para>
    9090
    9191<para>
    92 Not all away states are supported by all protocols, and some protocols have different names for them. BitlBee will try to pick the best available alias from this list for every connection:
     92Away states have different names accross different protocols. BitlBee will try to pick the best available option for every connection:
    9393</para>
    9494
    9595<simplelist>
    96         <member>Away from computer, Away, Extended away</member>
    97         <member>NA, N/A, Not available</member>
    98         <member>Busy, Do not disturb, DND, Occupied</member>
    99         <member>Be right back, BRB</member>
    100         <member>On the phone, Phone, On phone</member>
    101         <member>Out to lunch, Lunch, Food</member>
     96        <member>Away</member>
     97        <member>NA</member>
     98        <member>Busy, DND</member>
     99        <member>BRB</member>
     100        <member>Phone</member>
     101        <member>Lunch, Food</member>
    102102        <member>Invisible, Hidden</member>
    103103</simplelist>
    104104
    105105<para>
    106 So <emphasis>/away Food</emphasis> will set your state to "Out to lunch" on your MSN connection, and for most other connections the default, "Away" or "Away from computer" will be chosen.
     106So <emphasis>/away Food</emphasis> will set your state to "Out to lunch" on your MSN connection, and for most other connections the default, "Away" will be chosen.
    107107</para>
    108108
     
    111111</para>
    112112
     113<para>
     114If you want to set an away state for only one of your connections, you can use the per-account <emphasis>away</emphasis> setting. See <emphasis>help set away</emphasis>.
     115</para>
     116
    113117</sect1>
    114118
  • irc.c

    r1c3008a re8c8d00  
    7979}
    8080
     81static char *set_eval_away_status( set_t *set, char *value )
     82{
     83        irc_t *irc = set->data;
     84        account_t *a;
     85       
     86        g_free( set->value );
     87        set->value = g_strdup( value );
     88       
     89        for( a = irc->accounts; a; a = a->next )
     90        {
     91                struct im_connection *ic = a->ic;
     92               
     93                if( ic && ic->flags & OPT_LOGGED_IN )
     94                        imc_away_send_update( ic );
     95        }
     96       
     97        return value;
     98}
     99
    81100irc_t *irc_new( int fd )
    82101{
     
    144163        irc_connection_list = g_slist_append( irc_connection_list, irc );
    145164       
     165        s = set_add( &irc->set, "away", NULL,  set_eval_away_status, irc );
     166        s->flags |= SET_NULL_OK;
    146167        s = set_add( &irc->set, "away_devoice", "true",  set_eval_away_devoice, irc );
    147168        s = set_add( &irc->set, "auto_connect", "true", set_eval_bool, irc );
    148         s = set_add( &irc->set, "auto_reconnect", "false", set_eval_bool, irc );
     169        s = set_add( &irc->set, "auto_reconnect", "true", set_eval_bool, irc );
    149170        s = set_add( &irc->set, "auto_reconnect_delay", "5*3<900", set_eval_account_reconnect_delay, irc );
    150171        s = set_add( &irc->set, "buddy_sendbuffer", "false", set_eval_bool, irc );
     
    164185        s = set_add( &irc->set, "save_on_quit", "true", set_eval_bool, irc );
    165186        s = set_add( &irc->set, "simulate_netsplit", "true", set_eval_bool, irc );
     187        s = set_add( &irc->set, "status", NULL,  set_eval_away_status, irc );
     188        s->flags |= SET_NULL_OK;
    166189        s = set_add( &irc->set, "strip_html", "true", NULL, irc );
    167190        s = set_add( &irc->set, "to_char", ": ", set_eval_to_char, irc );
  • irc_commands.c

    r1c3008a re8c8d00  
    448448        user_t *u = user_find( irc, irc->nick );
    449449        char *away = cmd[1];
    450         account_t *a;
    451450       
    452451        if( !u ) return;
     
    475474        }
    476475       
    477         for( a = irc->accounts; a; a = a->next )
    478         {
    479                 struct im_connection *ic = a->ic;
    480                
    481                 if( ic && ic->flags & OPT_LOGGED_IN )
    482                         imc_set_away( ic, u->away );
    483         }
     476        set_setstr( &irc->set, "away", u->away );
    484477}
    485478
     
    504497                else if( u->away )
    505498                        irc_reply( irc, 301, "%s :%s", u->nick, u->away );
     499                if( u->status_msg )
     500                        irc_reply( irc, 333, "%s :Status: %s", u->nick, u->status_msg );
    506501               
    507502                irc_reply( irc, 318, "%s :End of /WHOIS list", nick );
  • lib/misc.c

    r1c3008a re8c8d00  
    3434#include "nogaim.h"
    3535#include "base64.h"
     36#include "md5.h"
    3637#include <stdio.h>
    3738#include <stdlib.h>
     
    8990        { "gt",     ">" },
    9091        { "amp",    "&" },
     92        { "apos",   "'" },
    9193        { "quot",   "\"" },
    9294        { "aacute", "á" },
     
    522524
    523525/* Word wrapping. Yes, I know this isn't UTF-8 clean. I'm willing to take the risk. */
    524 char *word_wrap( char *msg, int line_len )
     526char *word_wrap( const char *msg, int line_len )
    525527{
    526528        GString *ret = g_string_sized_new( strlen( msg ) + 16 );
  • lib/misc.h

    r1c3008a re8c8d00  
    6262G_MODULE_EXPORT struct ns_srv_reply *srv_lookup( char *service, char *protocol, char *domain );
    6363
    64 G_MODULE_EXPORT char *word_wrap( char *msg, int line_len );
     64G_MODULE_EXPORT char *word_wrap( const char *msg, int line_len );
    6565
    6666G_MODULE_EXPORT gboolean ssl_sockerr_again( void *ssl );
  • protocols/jabber/io.c

    r1c3008a re8c8d00  
    375375       
    376376        if( ( c = xt_find_node( node->children, "bind" ) ) )
    377         {
    378                 reply = xt_new_node( "bind", NULL, xt_new_node( "resource", set_getstr( &ic->acc->set, "resource" ), NULL ) );
    379                 xt_add_attr( reply, "xmlns", XMLNS_BIND );
    380                 reply = jabber_make_packet( "iq", "set", NULL, reply );
    381                 jabber_cache_add( ic, reply, jabber_pkt_bind_sess );
    382                
    383                 if( !jabber_write_packet( ic, reply ) )
    384                         return XT_ABORT;
    385                
    386                 jd->flags |= JFLAG_WAIT_BIND;
    387         }
     377                jd->flags |= JFLAG_WANT_BIND;
    388378       
    389379        if( ( c = xt_find_node( node->children, "session" ) ) )
    390         {
    391                 reply = xt_new_node( "session", NULL, NULL );
    392                 xt_add_attr( reply, "xmlns", XMLNS_SESSION );
    393                 reply = jabber_make_packet( "iq", "set", NULL, reply );
    394                 jabber_cache_add( ic, reply, jabber_pkt_bind_sess );
    395                
    396                 if( !jabber_write_packet( ic, reply ) )
    397                         return XT_ABORT;
    398                
    399                 jd->flags |= JFLAG_WAIT_SESSION;
    400         }
    401        
    402         /* This flag is already set if we authenticated via SASL, so now
    403            we can resume the session in the new stream, if we don't have
    404            to bind/initialize the session. */
    405         if( jd->flags & JFLAG_AUTHENTICATED && ( jd->flags & ( JFLAG_WAIT_BIND | JFLAG_WAIT_SESSION ) ) == 0 )
    406         {
    407                 if( !jabber_get_roster( ic ) )
    408                         return XT_ABORT;
    409         }
     380                jd->flags |= JFLAG_WANT_SESSION;
     381       
     382        if( jd->flags & JFLAG_AUTHENTICATED )
     383                return jabber_pkt_bind_sess( ic, NULL, NULL );
    410384       
    411385        return XT_HANDLED;
     
    441415        imcb_log( ic, "Converting stream to TLS" );
    442416       
     417        jd->flags |= JFLAG_STARTTLS_DONE;
    443418        jd->ssl = ssl_starttls( jd->fd, jabber_connected_ssl, ic );
    444419       
     
    531506                jd->r_inpa = b_input_add( jd->fd, GAIM_INPUT_READ, jabber_read_callback, ic );
    532507       
    533         greet = g_strdup_printf( "<?xml version='1.0' ?>"
    534                                  "<stream:stream to=\"%s\" xmlns=\"jabber:client\" "
    535                                   "xmlns:stream=\"http://etherx.jabber.org/streams\" version=\"1.0\">", jd->server );
     508        greet = g_strdup_printf( "%s<stream:stream to=\"%s\" xmlns=\"jabber:client\" "
     509                                  "xmlns:stream=\"http://etherx.jabber.org/streams\" version=\"1.0\">",
     510                                  ( jd->flags & JFLAG_STARTTLS_DONE ) ? "" : "<?xml version='1.0' ?>",
     511                                  jd->server );
    536512       
    537513        st = jabber_write( ic, greet, strlen( greet ) );
  • protocols/jabber/iq.c

    r1c3008a re8c8d00  
    310310{
    311311        struct jabber_data *jd = ic->proto_data;
    312         struct xt_node *c;
     312        struct xt_node *c, *reply = NULL;
    313313        char *s;
    314314       
    315         if( ( c = xt_find_node( node->children, "bind" ) ) )
     315        if( node && ( c = xt_find_node( node->children, "bind" ) ) )
    316316        {
    317317                c = xt_find_node( c->children, "jid" );
     
    319319                    strcmp( s + 1, set_getstr( &ic->acc->set, "resource" ) ) != 0 )
    320320                        imcb_log( ic, "Server changed session resource string to `%s'", s + 1 );
    321                
    322                 jd->flags &= ~JFLAG_WAIT_BIND;
    323         }
    324         else
    325         {
    326                 jd->flags &= ~JFLAG_WAIT_SESSION;
    327         }
    328        
    329         if( ( jd->flags & ( JFLAG_WAIT_BIND | JFLAG_WAIT_SESSION ) ) == 0 )
     321        }
     322       
     323        if( jd->flags & JFLAG_WANT_BIND )
     324        {
     325                reply = xt_new_node( "bind", NULL, xt_new_node( "resource", set_getstr( &ic->acc->set, "resource" ), NULL ) );
     326                xt_add_attr( reply, "xmlns", XMLNS_BIND );
     327                jd->flags &= ~JFLAG_WANT_BIND;
     328        }
     329        else if( jd->flags & JFLAG_WANT_SESSION )
     330        {
     331                reply = xt_new_node( "session", NULL, NULL );
     332                xt_add_attr( reply, "xmlns", XMLNS_SESSION );
     333                jd->flags &= ~JFLAG_WANT_SESSION;
     334        }
     335       
     336        if( reply != NULL )
     337        {
     338                reply = jabber_make_packet( "iq", "set", NULL, reply );
     339                jabber_cache_add( ic, reply, jabber_pkt_bind_sess );
     340               
     341                if( !jabber_write_packet( ic, reply ) )
     342                        return XT_ABORT;
     343        }
     344        else if( ( jd->flags & ( JFLAG_WANT_BIND | JFLAG_WANT_SESSION ) ) == 0 )
    330345        {
    331346                if( !jabber_get_roster( ic ) )
  • protocols/jabber/jabber.c

    r1c3008a re8c8d00  
    6969        s->flags |= ACC_SET_OFFLINE_ONLY;
    7070       
    71         s = set_add( &acc->set, "resource_select", "priority", NULL, acc );
     71        s = set_add( &acc->set, "resource_select", "activity", NULL, acc );
    7272       
    7373        s = set_add( &acc->set, "server", NULL, set_eval_account, acc );
     
    8282        s = set_add( &acc->set, "xmlconsole", "false", set_eval_bool, acc );
    8383        s->flags |= ACC_SET_OFFLINE_ONLY;
     84       
     85        acc->flags |= ACC_FLAG_AWAY_MESSAGE | ACC_FLAG_STATUS_MESSAGE;
    8486}
    8587
     
    378380        while( bud )
    379381        {
    380                 imcb_log( ic, "Buddy %s (%d) information:\nAway state: %s\nAway message: %s",
    381                                    bud->full_jid, bud->priority,
    382                                    bud->away_state ? bud->away_state->full_name : "(none)",
    383                                    bud->away_message ? : "(none)" );
     382                imcb_log( ic, "Buddy %s (%d) information:", bud->full_jid, bud->priority );
     383                if( bud->away_state )
     384                        imcb_log( ic, "Away state: %s", bud->away_state->full_name );
     385                imcb_log( ic, "Status message: %s", bud->away_message ? : "(none)" );
     386               
    384387                bud = bud->next;
    385388        }
     
    391394{
    392395        struct jabber_data *jd = ic->proto_data;
    393         struct jabber_away_state *state;
    394        
    395         /* Save all this info. We need it, for example, when changing the priority setting. */
    396         state = (void *) jabber_away_state_by_name( state_txt );
    397         jd->away_state = state ? state : (void *) jabber_away_state_list; /* Fall back to "Away" if necessary. */
     396       
     397        /* state_txt == NULL -> Not away.
     398           Unknown state -> fall back to the first defined away state. */
     399        jd->away_state = state_txt ? jabber_away_state_by_name( state_txt )
     400                         ? : jabber_away_state_list : NULL;
     401       
    398402        g_free( jd->away_message );
    399403        jd->away_message = ( message && *message ) ? g_strdup( message ) : NULL;
  • protocols/jabber/jabber.h

    r1c3008a re8c8d00  
    4040        JFLAG_STREAM_RESTART = 4,       /* Set when we want to restart the stream (after
    4141                                           SASL or TLS). */
    42         JFLAG_WAIT_SESSION = 8,         /* Set if we sent a <session> tag and need a reply
     42        JFLAG_WANT_SESSION = 8,         /* Set if the server wants a <session/> tag
    4343                                           before we continue. */
    44         JFLAG_WAIT_BIND = 16,           /* ... for <bind> tag. */
     44        JFLAG_WANT_BIND = 16,           /* ... for <bind> tag. */
    4545        JFLAG_WANT_TYPING = 32,         /* Set if we ever sent a typing notification, this
    4646                                           activates all XEP-85 related code. */
    4747        JFLAG_XMLCONSOLE = 64,          /* If the user added an xmlconsole buddy. */
     48        JFLAG_STARTTLS_DONE = 128,      /* If a plaintext session was converted to TLS. */
    4849} jabber_flags_t;
    4950
     
    9293        /* After changing one of these two (or the priority setting), call
    9394           presence_send_update() to inform the server about the changes. */
    94         struct jabber_away_state *away_state;
     95        const struct jabber_away_state *away_state;
    9596        char *away_message;
    9697       
  • protocols/jabber/jabber_util.c

    r1c3008a re8c8d00  
    232232{
    233233        { "away",  "Away" },
    234         { "chat",  "Free for Chat" },
     234        { "chat",  "Free for Chat" },   /* WTF actually uses this? */
    235235        { "dnd",   "Do not Disturb" },
    236236        { "xa",    "Extended Away" },
    237         { "",      "Online" },
    238237        { "",      NULL }
    239238};
     
    242241{
    243242        int i;
     243       
     244        if( code == NULL )
     245                return NULL;
    244246       
    245247        for( i = 0; jabber_away_state_list[i].full_name; i ++ )
     
    253255{
    254256        int i;
     257       
     258        if( name == NULL )
     259                return NULL;
    255260       
    256261        for( i = 0; jabber_away_state_list[i].full_name; i ++ )
  • protocols/jabber/presence.c

    r1c3008a re8c8d00  
    190190                int is_away = 0;
    191191
    192                 if( send_presence->away_state && !( *send_presence->away_state->code == 0 ||
    193                     strcmp( send_presence->away_state->code, "chat" ) == 0 ) )
     192                if( send_presence->away_state &&
     193                    strcmp( send_presence->away_state->code, "chat" ) != 0 )
    194194                        is_away = OPT_AWAY;
    195195
    196196                imcb_buddy_status( ic, send_presence->bare_jid, OPT_LOGGED_IN | is_away,
    197                                    ( is_away && send_presence->away_state ) ?
    198                                    send_presence->away_state->full_name : NULL,
     197                                   is_away ? send_presence->away_state->full_name : NULL,
    199198                                   send_presence->away_message );
    200199        }
     
    209208        struct jabber_data *jd = ic->proto_data;
    210209        struct xt_node *node, *cap;
    211         char *show = jd->away_state->code;
    212         char *status = jd->away_message;
    213210        struct groupchat *c;
    214211        int st;
     
    216213        node = jabber_make_packet( "presence", NULL, NULL, NULL );
    217214        xt_add_child( node, xt_new_node( "priority", set_getstr( &ic->acc->set, "priority" ), NULL ) );
    218         if( show && *show )
    219                 xt_add_child( node, xt_new_node( "show", show, NULL ) );
    220         if( status )
    221                 xt_add_child( node, xt_new_node( "status", status, NULL ) );
     215        if( jd->away_state )
     216                xt_add_child( node, xt_new_node( "show", jd->away_state->code, NULL ) );
     217        if( jd->away_message )
     218                xt_add_child( node, xt_new_node( "status", jd->away_message, NULL ) );
    222219       
    223220        /* This makes the packet slightly bigger, but clients interested in
  • protocols/msn/msn.c

    r1c3008a re8c8d00  
    2626#include "nogaim.h"
    2727#include "msn.h"
     28
     29int msn_chat_id;
     30GSList *msn_connections;
     31GSList *msn_switchboards;
    2832
    2933static char *msn_set_display_name( set_t *set, char *value );
     
    143147       
    144148        if( l == NULL )
    145                 for( i = 0; msn_away_state_list[i].number > -1; i ++ )
    146                         l = g_list_append( l, (void*) msn_away_state_list[i].name );
     149                for( i = 0; *msn_away_state_list[i].code; i ++ )
     150                        if( *msn_away_state_list[i].name )
     151                                l = g_list_append( l, (void*) msn_away_state_list[i].name );
    147152       
    148153        return l;
     
    153158        char buf[1024];
    154159        struct msn_data *md = ic->proto_data;
    155         const struct msn_away_state *st;
    156        
    157         if( strcmp( state, GAIM_AWAY_CUSTOM ) == 0 )
    158                 st = msn_away_state_by_name( "Away" );
     160       
     161        if( state )
     162                md->away_state = msn_away_state_by_name( state ) ? :
     163                                 msn_away_state_list + 1;
    159164        else
    160                 st = msn_away_state_by_name( state );
    161        
    162         if( !st ) st = msn_away_state_list;
    163         md->away_state = st;
    164        
    165         g_snprintf( buf, sizeof( buf ), "CHG %d %s\r\n", ++md->trId, st->code );
     165                md->away_state = msn_away_state_list;
     166       
     167        g_snprintf( buf, sizeof( buf ), "CHG %d %s\r\n", ++md->trId, md->away_state->code );
    166168        msn_write( ic, buf, strlen( buf ) );
    167169}
  • protocols/msn/msn.h

    r1c3008a re8c8d00  
    9898struct msn_away_state
    9999{
    100         int number;
    101100        char code[4];
    102101        char name[16];
     
    137136#define STATUS_SB_CHAT_SPARE    8       /* Same, but also for groupchats (not used yet). */
    138137
    139 int msn_chat_id;
     138extern int msn_chat_id;
    140139extern const struct msn_away_state msn_away_state_list[];
    141140extern const struct msn_status_code msn_status_code_list[];
     
    146145   connection), the callback should check whether it's still listed here
    147146   before doing *anything* else. */
    148 GSList *msn_connections;
    149 GSList *msn_switchboards;
     147extern GSList *msn_connections;
     148extern GSList *msn_switchboards;
    150149
    151150/* ns.c */
  • protocols/msn/msn_util.c

    r1c3008a re8c8d00  
    171171               
    172172                /* End of headers? */
    173                 if( strncmp( text + i - 2, "\n\n", 2 ) == 0 ||
    174                     strncmp( text + i - 4, "\r\n\r\n", 4 ) == 0 ||
    175                     strncmp( text + i - 2, "\r\r", 2 ) == 0 )
     173                if( ( i >= 4 && strncmp( text + i - 4, "\r\n\r\n", 4 ) == 0 ) ||
     174                    ( i >= 2 && ( strncmp( text + i - 2, "\n\n", 2 ) == 0 ||   
     175                                  strncmp( text + i - 2, "\r\r", 2 ) == 0 ) ) )
    176176                {
    177177                        break;
     
    374374        *list = NULL;
    375375       
    376         imcb_log( ic, ret->str );
     376        imcb_log( ic, "%s", ret->str );
    377377        g_string_free( ret, TRUE );
    378378}
  • protocols/msn/ns.c

    r1c3008a re8c8d00  
    229229                        }
    230230                }
    231                 else if( num_parts == 7 && strcmp( cmd[2], "OK" ) == 0 )
     231                else if( num_parts >= 7 && strcmp( cmd[2], "OK" ) == 0 )
    232232                {
    233233                        set_t *s;
    234234                       
    235                         http_decode( cmd[4] );
    236                        
    237                         strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) );
    238                         ic->displayname[sizeof(ic->displayname)-1] = 0;
    239                        
    240                         if( ( s = set_find( &ic->acc->set, "display_name" ) ) )
    241                         {
    242                                 g_free( s->value );
    243                                 s->value = g_strdup( cmd[4] );
     235                        if( num_parts == 7 )
     236                        {
     237                                http_decode( cmd[4] );
     238                               
     239                                strncpy( ic->displayname, cmd[4], sizeof( ic->displayname ) );
     240                                ic->displayname[sizeof(ic->displayname)-1] = 0;
     241                               
     242                                if( ( s = set_find( &ic->acc->set, "display_name" ) ) )
     243                                {
     244                                        g_free( s->value );
     245                                        s->value = g_strdup( cmd[4] );
     246                                }
     247                        }
     248                        else
     249                        {
     250                                imcb_log( ic, "Warning: Friendly name in server response was corrupted" );
    244251                        }
    245252                       
     
    420427                {
    421428                        /* FIXME: Warn/Bomb about unknown away state? */
    422                         st = msn_away_state_list;
    423                 }
    424                
    425                 imcb_buddy_status( ic, cmd[3], OPT_LOGGED_IN |
    426                                    ( st->number ? OPT_AWAY : 0 ), st->name, NULL );
     429                        st = msn_away_state_list + 1;
     430                }
     431               
     432                imcb_buddy_status( ic, cmd[3], OPT_LOGGED_IN |
     433                                   ( st != msn_away_state_list ? OPT_AWAY : 0 ),
     434                                   st->name, NULL );
    427435        }
    428436        else if( strcmp( cmd[0], "FLN" ) == 0 )
     
    449457                {
    450458                        /* FIXME: Warn/Bomb about unknown away state? */
    451                         st = msn_away_state_list;
    452                 }
    453                
    454                 imcb_buddy_status( ic, cmd[2], OPT_LOGGED_IN |
    455                                    ( st->number ? OPT_AWAY : 0 ), st->name, NULL );
     459                        st = msn_away_state_list + 1;
     460                }
     461               
     462                imcb_buddy_status( ic, cmd[2], OPT_LOGGED_IN |
     463                                   ( st != msn_away_state_list ? OPT_AWAY : 0 ),
     464                                   st->name, NULL );
    456465        }
    457466        else if( strcmp( cmd[0], "RNG" ) == 0 )
     
    663672                                }
    664673                               
    665                                 if( arg1 ) g_free( arg1 );
    666                                 if( mtype ) g_free( mtype );
     674                                g_free( arg1 );
     675                                g_free( mtype );
    667676                        }
    668677                        else if( g_strncasecmp( ct, "text/x-msmsgsprofile", 20 ) == 0 )
     
    672681                        else if( g_strncasecmp( ct, "text/x-msmsgsinitialemailnotification", 37 ) == 0 )
    673682                        {
    674                                 char *inbox = msn_findheader( body, "Inbox-Unread:", blen );
    675                                 char *folders = msn_findheader( body, "Folders-Unread:", blen );
    676                                
    677                                 if( inbox && folders && set_getbool( &ic->acc->set, "mail_notifications" ) )
     683                                if( set_getbool( &ic->acc->set, "mail_notifications" ) )
    678684                                {
    679                                         imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders );
     685                                        char *inbox = msn_findheader( body, "Inbox-Unread:", blen );
     686                                        char *folders = msn_findheader( body, "Folders-Unread:", blen );
     687
     688                                        if( inbox && folders )
     689                                                imcb_log( ic, "INBOX contains %s new messages, plus %s messages in other folders.", inbox, folders );
     690                                       
     691                                        g_free( inbox );
     692                                        g_free( folders );
    680693                                }
    681                                
    682                                 g_free( inbox );
    683                                 g_free( folders );
    684694                        }
    685695                        else if( g_strncasecmp( ct, "text/x-msmsgsemailnotification", 30 ) == 0 )
    686696                        {
    687                                 char *from = msn_findheader( body, "From-Addr:", blen );
    688                                 char *fromname = msn_findheader( body, "From:", blen );
    689                                
    690                                 if( from && fromname && set_getbool( &ic->acc->set, "mail_notifications" ) )
     697                                if( set_getbool( &ic->acc->set, "mail_notifications" ) )
    691698                                {
    692                                         imcb_log( ic, "Received an e-mail message from %s <%s>.", fromname, from );
     699                                        char *from = msn_findheader( body, "From-Addr:", blen );
     700                                        char *fromname = msn_findheader( body, "From:", blen );
     701                                       
     702                                        if( from && fromname )
     703                                                imcb_log( ic, "Received an e-mail message from %s <%s>.", fromname, from );
     704
     705                                        g_free( from );
     706                                        g_free( fromname );
    693707                                }
    694708                        }
  • protocols/msn/tables.c

    r1c3008a re8c8d00  
    2929const struct msn_away_state msn_away_state_list[] =
    3030{
    31         {  0, "NLN", "Available" },
    32         {  1, "BSY", "Busy" },
    33         {  3, "IDL", "Idle" },
    34         {  5, "BRB", "Be Right Back" },
    35         {  7, "AWY", "Away" },
    36         {  9, "PHN", "On the Phone" },
    37         { 11, "LUN", "Out to Lunch" },
    38         { 13, "HDN", "Hidden" },
    39         { -1, "",    "" }
     31        { "NLN", "" },
     32        { "AWY", "Away" },
     33        { "BSY", "Busy" },
     34        { "IDL", "Idle" },
     35        { "BRB", "Be Right Back" },
     36        { "PHN", "On the Phone" },
     37        { "LUN", "Out to Lunch" },
     38        { "HDN", "Hidden" },
     39        { "",    "" }
    4040};
    41 
    42 const struct msn_away_state *msn_away_state_by_number( int number )
    43 {
    44         int i;
    45        
    46         for( i = 0; msn_away_state_list[i].number > -1; i ++ )
    47                 if( msn_away_state_list[i].number == number )
    48                         return( msn_away_state_list + i );
    49        
    50         return( NULL );
    51 }
    5241
    5342const struct msn_away_state *msn_away_state_by_code( char *code )
     
    5544        int i;
    5645       
    57         for( i = 0; msn_away_state_list[i].number > -1; i ++ )
     46        for( i = 0; *msn_away_state_list[i].code; i ++ )
    5847                if( g_strcasecmp( msn_away_state_list[i].code, code ) == 0 )
    5948                        return( msn_away_state_list + i );
    6049       
    61         return( NULL );
     50        return NULL;
    6251}
    6352
     
    6655        int i;
    6756       
    68         for( i = 0; msn_away_state_list[i].number > -1; i ++ )
     57        for( i = 0; *msn_away_state_list[i].code; i ++ )
    6958                if( g_strcasecmp( msn_away_state_list[i].name, name ) == 0 )
    7059                        return( msn_away_state_list + i );
    7160       
    72         return( NULL );
     61        return NULL;
    7362}
    7463
  • protocols/nogaim.c

    r1c3008a re8c8d00  
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
    4   * Copyright 2002-2006 Wilmer van der Gaast and others                *
     4  * Copyright 2002-2010 Wilmer van der Gaast and others                *
    55  \********************************************************************/
    66
     
    9898void register_protocol (struct prpl *p)
    9999{
    100         protocols = g_list_append(protocols, p);
     100        int i;
     101        gboolean refused = global.conf->protocols != NULL;
     102 
     103        for (i = 0; global.conf->protocols && global.conf->protocols[i]; i++)
     104        {
     105                if (g_strcasecmp(p->name, global.conf->protocols[i]) == 0)
     106                        refused = FALSE;
     107        }
     108
     109        if (refused)
     110                log_message(LOGLVL_WARNING, "Protocol %s disabled\n", p->name);
     111        else
     112                protocols = g_list_append(protocols, p);
    101113}
    102114
     
    268280        ic->flags |= OPT_LOGGED_IN;
    269281       
    270         /* Also necessary when we're not away, at least for some of the
    271            protocols. */
    272         imc_set_away( ic, u->away );
     282        /* Necessary to send initial presence status, even if we're not away. */
     283        imc_away_send_update( ic );
    273284       
    274285        /* Apparently we're connected successfully, so reset the
     
    372383/* list.c */
    373384
    374 void imcb_add_buddy( struct im_connection *ic, char *handle, char *group )
     385void imcb_add_buddy( struct im_connection *ic, const char *handle, const char *group )
    375386{
    376387        user_t *u;
     
    446457}
    447458
    448 void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname )
     459void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *realname )
    449460{
    450461        user_t *u = user_findhandle( ic, handle );
     462        char *set;
    451463       
    452464        if( !u || !realname ) return;
     
    461473                        imcb_log( ic, "User `%s' changed name to `%s'", u->nick, u->realname );
    462474        }
    463 }
    464 
    465 void imcb_remove_buddy( struct im_connection *ic, char *handle, char *group )
     475       
     476        set = set_getstr( &ic->acc->set, "nick_source" );
     477        if( strcmp( set, "handle" ) != 0 )
     478        {
     479                char *name = g_strdup( realname );
     480               
     481                if( strcmp( set, "first_name" ) == 0 )
     482                {
     483                        int i;
     484                        for( i = 0; name[i] && !isspace( name[i] ); i ++ ) {}
     485                        name[i] = '\0';
     486                }
     487               
     488                imcb_buddy_nick_hint( ic, handle, name );
     489               
     490                g_free( name );
     491        }
     492}
     493
     494void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *group )
    466495{
    467496        user_t *u;
     
    473502/* Mainly meant for ICQ (and now also for Jabber conferences) to allow IM
    474503   modules to suggest a nickname for a handle. */
    475 void imcb_buddy_nick_hint( struct im_connection *ic, char *handle, char *nick )
     504void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const char *nick )
    476505{
    477506        user_t *u = user_findhandle( ic, handle );
     
    618647        oo = u->online;
    619648       
    620         if( u->away )
    621         {
    622                 g_free( u->away );
    623                 u->away = NULL;
    624         }
     649        g_free( u->away );
     650        g_free( u->status_msg );
     651        u->away = u->status_msg = NULL;
    625652       
    626653        if( ( flags & OPT_LOGGED_IN ) && !u->online )
     
    660687                }
    661688        }
    662         /* else waste_any_state_information_for_now(); */
     689        else
     690        {
     691                u->status_msg = g_strdup( message );
     692        }
    663693       
    664694        /* LISPy... */
     
    685715}
    686716
    687 void imcb_buddy_msg( struct im_connection *ic, char *handle, char *msg, uint32_t flags, time_t sent_at )
     717void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at )
    688718{
    689719        irc_t *irc = ic->irc;
     
    818848}
    819849
    820 void imcb_chat_msg( struct groupchat *c, char *who, char *msg, uint32_t flags, time_t sent_at )
     850void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t flags, time_t sent_at )
    821851{
    822852        struct im_connection *ic = c->ic;
     
    890920/* buddy_chat.c */
    891921
    892 void imcb_chat_add_buddy( struct groupchat *b, char *handle )
     922void imcb_chat_add_buddy( struct groupchat *b, const char *handle )
    893923{
    894924        user_t *u = user_findhandle( b->ic, handle );
     
    925955
    926956/* This function is one BIG hack... :-( EREWRITE */
    927 void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason )
     957void imcb_chat_remove_buddy( struct groupchat *b, const char *handle, const char *reason )
    928958{
    929959        user_t *u;
     
    10701100}
    10711101
    1072 static char *imc_away_alias_find( GList *gcm, char *away );
    1073 
    1074 int imc_set_away( struct im_connection *ic, char *away )
    1075 {
    1076         GList *m, *ms;
    1077         char *s;
    1078        
    1079         if( !away ) away = "";
    1080         ms = m = ic->acc->prpl->away_states( ic );
    1081        
    1082         while( m )
    1083         {
    1084                 if( *away )
    1085                 {
    1086                         if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 )
    1087                                 break;
    1088                 }
    1089                 else
    1090                 {
    1091                         if( g_strcasecmp( m->data, "Available" ) == 0 )
    1092                                 break;
    1093                         if( g_strcasecmp( m->data, "Online" ) == 0 )
    1094                                 break;
    1095                 }
    1096                 m = m->next;
    1097         }
    1098        
    1099         if( m )
    1100         {
    1101                 ic->acc->prpl->set_away( ic, m->data, *away ? away : NULL );
    1102         }
    1103         else
    1104         {
    1105                 s = imc_away_alias_find( ms, away );
    1106                 if( s )
    1107                 {
    1108                         ic->acc->prpl->set_away( ic, s, away );
    1109                         if( set_getbool( &ic->irc->set, "debug" ) )
    1110                                 imcb_log( ic, "Setting away state to %s", s );
    1111                 }
    1112                 else
    1113                         ic->acc->prpl->set_away( ic, GAIM_AWAY_CUSTOM, away );
    1114         }
    1115        
    1116         return( 1 );
     1102static char *imc_away_state_find( GList *gcm, char *away, char **message );
     1103
     1104int imc_away_send_update( struct im_connection *ic )
     1105{
     1106        char *away, *msg = NULL;
     1107       
     1108        away = set_getstr( &ic->acc->set, "away" ) ?
     1109             : set_getstr( &ic->irc->set, "away" );
     1110        if( away && *away )
     1111        {
     1112                GList *m = ic->acc->prpl->away_states( ic );
     1113                msg = ic->acc->flags & ACC_FLAG_AWAY_MESSAGE ? away : NULL;
     1114                away = imc_away_state_find( m, away, &msg ) ? : m->data;
     1115        }
     1116        else if( ic->acc->flags & ACC_FLAG_STATUS_MESSAGE )
     1117        {
     1118                away = NULL;
     1119                msg = set_getstr( &ic->acc->set, "status" ) ?
     1120                    : set_getstr( &ic->irc->set, "status" );
     1121        }
     1122       
     1123        ic->acc->prpl->set_away( ic, away, msg );
     1124       
     1125        return 1;
    11171126}
    11181127
     
    11291138};
    11301139
    1131 static char *imc_away_alias_find( GList *gcm, char *away )
     1140static char *imc_away_state_find( GList *gcm, char *away, char **message )
    11321141{
    11331142        GList *m;
    11341143        int i, j;
    11351144       
     1145        for( m = gcm; m; m = m->next )
     1146                if( g_strncasecmp( m->data, away, strlen( m->data ) ) == 0 )
     1147                {
     1148                        /* At least the Yahoo! module works better if message
     1149                           contains no data unless it adds something to what
     1150                           we have in state already. */
     1151                        if( strlen( m->data ) == strlen( away ) )
     1152                                *message = NULL;
     1153                       
     1154                        return m->data;
     1155                }
     1156       
    11361157        for( i = 0; *imc_away_alias_list[i]; i ++ )
    11371158        {
     1159                int keep_message;
     1160               
    11381161                for( j = 0; imc_away_alias_list[i][j]; j ++ )
    11391162                        if( g_strncasecmp( away, imc_away_alias_list[i][j], strlen( imc_away_alias_list[i][j] ) ) == 0 )
     1163                        {
     1164                                keep_message = strlen( away ) != strlen( imc_away_alias_list[i][j] );
    11401165                                break;
     1166                        }
    11411167               
    11421168                if( !imc_away_alias_list[i][j] )        /* If we reach the end, this row */
     
    11461172                for( j = 0; imc_away_alias_list[i][j]; j ++ )
    11471173                {
    1148                         m = gcm;
    1149                         while( m )
    1150                         {
     1174                        for( m = gcm; m; m = m->next )
    11511175                                if( g_strcasecmp( imc_away_alias_list[i][j], m->data ) == 0 )
    1152                                         return( imc_away_alias_list[i][j] );
    1153                                 m = m->next;
    1154                         }
    1155                 }
    1156         }
    1157        
    1158         return( NULL );
     1176                                {
     1177                                        if( !keep_message )
     1178                                                *message = NULL;
     1179                                       
     1180                                        return imc_away_alias_list[i][j];
     1181                                }
     1182                }
     1183               
     1184                /* No need to look further, apparently this state doesn't
     1185                   have any good alias for this protocol. */
     1186                break;
     1187        }
     1188       
     1189        return NULL;
    11591190}
    11601191
  • protocols/nogaim.h

    r1c3008a re8c8d00  
    5151
    5252#define WEBSITE "http://www.bitlbee.org/"
    53 #define GAIM_AWAY_CUSTOM "Custom"
    5453
    5554/* Sharing flags between all kinds of things. I just hope I won't hit any
     
    220219       
    221220        /* You can tell what away states your protocol supports, so that
    222          * BitlBee will try to map the IRC away reasons to them, or use
    223          * GAIM_AWAY_CUSTOM when calling skype_set_away(). */
     221         * BitlBee will try to map the IRC away reasons to them. If your
     222         * protocol doesn't have any, just return one generic "Away". */
    224223        GList *(* away_states)(struct im_connection *ic);
    225224       
     
    281280 * user, usually after a login, or if the user added a buddy and the IM
    282281 * server confirms that the add was successful. Don't forget to do this! */
    283 G_MODULE_EXPORT void imcb_add_buddy( struct im_connection *ic, char *handle, char *group );
    284 G_MODULE_EXPORT void imcb_remove_buddy( struct im_connection *ic, char *handle, char *group );
     282G_MODULE_EXPORT void imcb_add_buddy( struct im_connection *ic, const char *handle, const char *group );
     283G_MODULE_EXPORT void imcb_remove_buddy( struct im_connection *ic, const char *handle, char *group );
    285284G_MODULE_EXPORT struct buddy *imcb_find_buddy( struct im_connection *ic, char *handle );
    286 G_MODULE_EXPORT void imcb_rename_buddy( struct im_connection *ic, char *handle, char *realname );
    287 G_MODULE_EXPORT void imcb_buddy_nick_hint( struct im_connection *ic, char *handle, char *nick );
     285G_MODULE_EXPORT void imcb_rename_buddy( struct im_connection *ic, const char *handle, const char *realname );
     286G_MODULE_EXPORT void imcb_buddy_nick_hint( struct im_connection *ic, const char *handle, const char *nick );
    288287
    289288/* Buddy activity */
     
    295294/* Not implemented yet! */ G_MODULE_EXPORT void imcb_buddy_times( struct im_connection *ic, const char *handle, time_t login, time_t idle );
    296295/* Call when a handle says something. 'flags' and 'sent_at may be just 0. */
    297 G_MODULE_EXPORT void imcb_buddy_msg( struct im_connection *ic, char *handle, char *msg, uint32_t flags, time_t sent_at );
     296G_MODULE_EXPORT void imcb_buddy_msg( struct im_connection *ic, const char *handle, char *msg, uint32_t flags, time_t sent_at );
    298297G_MODULE_EXPORT void imcb_buddy_typing( struct im_connection *ic, char *handle, uint32_t flags );
    299298G_MODULE_EXPORT void imcb_clean_handle( struct im_connection *ic, char *handle );
     
    308307 *   user, too. */
    309308G_MODULE_EXPORT struct groupchat *imcb_chat_new( struct im_connection *ic, const char *handle );
    310 G_MODULE_EXPORT void imcb_chat_add_buddy( struct groupchat *b, char *handle );
     309G_MODULE_EXPORT void imcb_chat_add_buddy( struct groupchat *b, const char *handle );
    311310/* To remove a handle from a group chat. Reason can be NULL. */
    312 G_MODULE_EXPORT void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason );
     311G_MODULE_EXPORT void imcb_chat_remove_buddy( struct groupchat *b, const char *handle, const char *reason );
    313312/* To tell BitlBee 'who' said 'msg' in 'c'. 'flags' and 'sent_at' can be 0. */
    314 G_MODULE_EXPORT void imcb_chat_msg( struct groupchat *c, char *who, char *msg, uint32_t flags, time_t sent_at );
     313G_MODULE_EXPORT void imcb_chat_msg( struct groupchat *c, const char *who, char *msg, uint32_t flags, time_t sent_at );
    315314/* System messages specific to a groupchat, so they can be displayed in the right context. */
    316315G_MODULE_EXPORT void imcb_chat_log( struct groupchat *c, char *format, ... ) G_GNUC_PRINTF( 2, 3 );
     
    320319
    321320/* Actions, or whatever. */
    322 int imc_set_away( struct im_connection *ic, char *away );
     321int imc_away_send_update( struct im_connection *ic );
    323322int imc_buddy_msg( struct im_connection *ic, char *handle, char *msg, int flags );
    324323int imc_chat_msg( struct groupchat *c, char *msg, int flags );
  • protocols/oscar/oscar.c

    r1c3008a re8c8d00  
    380380                s->flags |= ACC_SET_OFFLINE_ONLY;
    381381        }
     382       
     383        acc->flags |= ACC_FLAG_AWAY_MESSAGE;
    382384}
    383385
     
    19521954static void oscar_set_away_aim(struct im_connection *ic, struct oscar_data *od, const char *state, const char *message)
    19531955{
     1956        if (state == NULL)
     1957                state = "";
    19541958
    19551959        if (!g_strcasecmp(state, _("Visible"))) {
     
    19591963                aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_INVISIBLE);
    19601964                return;
    1961         } /* else... */
     1965        } else if (message == NULL) {
     1966                message = state;
     1967        }
    19621968
    19631969        if (od->rights.maxawaymsglen == 0)
     
    20022008        }
    20032009
    2004         if (!g_strcasecmp(state, "Online")) {
     2010        if (state == NULL) {
    20052011                aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_NORMAL);
    20062012        } else if (!g_strcasecmp(state, "Away")) {
     
    20272033                aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_INVISIBLE);
    20282034                ic->away = g_strdup(msg);
    2029         } else if (!g_strcasecmp(state, GAIM_AWAY_CUSTOM)) {
     2035        } else {
    20302036                if (no_message) {
    20312037                        aim_setextstatus(od->sess, od->conn, AIM_ICQ_STATE_NORMAL);
     
    22762282{
    22772283        struct oscar_data *od = ic->proto_data;
    2278         GList *m = NULL;
    2279 
    2280         if (!od->icq)
    2281                 return g_list_append(m, GAIM_AWAY_CUSTOM);
    2282 
    2283         m = g_list_append(m, "Online");
    2284         m = g_list_append(m, "Away");
    2285         m = g_list_append(m, "Do Not Disturb");
    2286         m = g_list_append(m, "Not Available");
    2287         m = g_list_append(m, "Occupied");
    2288         m = g_list_append(m, "Free For Chat");
    2289         m = g_list_append(m, "Invisible");
    2290 
    2291         return m;
     2284
     2285        if (od->icq) {
     2286                static GList *m = NULL;
     2287                m = g_list_append(m, "Away");
     2288                m = g_list_append(m, "Do Not Disturb");
     2289                m = g_list_append(m, "Not Available");
     2290                m = g_list_append(m, "Occupied");
     2291                m = g_list_append(m, "Free For Chat");
     2292                m = g_list_append(m, "Invisible");
     2293                return m;
     2294        } else {
     2295                static GList *m = NULL;
     2296                m = g_list_append(m, "Away");
     2297                return m;
     2298        }
    22922299}
    22932300
  • protocols/yahoo/libyahoo2.c

    r1c3008a re8c8d00  
    855855}
    856856
    857 static YList * bud_str2list(char *rawlist)
    858 {
    859         YList * l = NULL;
    860 
    861         char **lines;
    862         char **split;
    863         char **buddies;
    864         char **tmp, **bud;
    865 
    866         lines = y_strsplit(rawlist, "\n", -1);
    867         for (tmp = lines; *tmp; tmp++) {
    868                 struct yahoo_buddy *newbud;
    869 
    870                 split = y_strsplit(*tmp, ":", 2);
    871                 if (!split)
    872                         continue;
    873                 if (!split[0] || !split[1]) {
    874                         y_strfreev(split);
    875                         continue;
    876                 }
    877                 buddies = y_strsplit(split[1], ",", -1);
    878 
    879                 for (bud = buddies; bud && *bud; bud++) {
    880                         newbud = y_new0(struct yahoo_buddy, 1);
    881                         newbud->id = strdup(*bud);
    882                         newbud->group = strdup(split[0]);
    883 
    884                         if(y_list_find_custom(l, newbud, is_same_bud)) {
    885                                 FREE(newbud->id);
    886                                 FREE(newbud->group);
    887                                 FREE(newbud);
    888                                 continue;
    889                         }
    890 
    891                         newbud->real_name = NULL;
    892 
    893                         l = y_list_append(l, newbud);
    894 
    895                         NOTICE(("Added buddy %s to group %s", newbud->id, newbud->group));
    896                 }
    897 
    898                 y_strfreev(buddies);
    899                 y_strfreev(split);
    900         }
    901         y_strfreev(lines);
    902 
    903         return l;
    904 }
    905 
    906857static char * getcookie(char *rawcookie)
    907858{
     
    13601311}
    13611312
    1362 
    1363 static void yahoo_process_status(struct yahoo_input_data *yid, struct yahoo_packet *pkt)
     1313static void yahoo_process_status(struct yahoo_input_data *yid,
     1314        struct yahoo_packet *pkt)
    13641315{
    13651316        YList *l;
    13661317        struct yahoo_data *yd = yid->yd;
    13671318
    1368         struct user
    1369         {
    1370                 char *name;     /* 7    name */
    1371                 int   state;    /* 10   state */
    1372                 int   flags;    /* 13   flags, bit 0 = pager, bit 1 = chat, bit 2 = game */
    1373                 int   mobile;   /* 60   mobile */
    1374                 char *msg;      /* 19   custom status message */
    1375                 int   away;     /* 47   away (or invisible)*/
    1376                 int   buddy_session;    /* 11   state */
    1377                 int   f17;      /* 17   in chat? then what about flags? */
    1378                 int   idle;     /* 137  seconds idle */
    1379                 int   f138;     /* 138  state */
    1380                 char *f184;     /* 184  state */
    1381                 int   f192;     /* 192  state */
    1382                 int   f10001;   /* 10001        state */
    1383                 int   f10002;   /* 10002        state */
    1384                 int   f198;     /* 198  state */
    1385                 char *f197;     /* 197  state */
    1386                 char *f205;     /* 205  state */
    1387                 int   f213;     /* 213  state */
    1388         } *u;
     1319        struct yahoo_process_status_entry *u;
    13891320
    13901321        YList *users = 0;
    1391        
     1322
    13921323        if (pkt->service == YAHOO_SERVICE_LOGOFF && pkt->status == -1) {
    1393                 YAHOO_CALLBACK(ext_yahoo_login_response)(yd->client_id, YAHOO_LOGIN_DUPL, NULL);
    1394                 return;
    1395         }
     1324                YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id,
     1325                        YAHOO_LOGIN_DUPL, NULL);
     1326                return;
     1327        }
     1328
     1329        /* Status updates may be spread accross multiple packets and not
     1330           even on buddy boundaries, so keeping some state is important.
     1331           So, continue where we left off, and only add a user entry to
     1332           the list once it's complete (301-315 End buddy). */
     1333        u = yd->half_user;
    13961334
    13971335        for (l = pkt->hash; l; l = l->next) {
     
    13991337
    14001338                switch (pair->key) {
    1401                 case 0: /* we won't actually do anything with this */
     1339                case 300:       /* Begin buddy */
     1340                        if (!strcmp(pair->value, "315") && !u) {
     1341                                u = yd->half_user = y_new0(struct yahoo_process_status_entry, 1);
     1342                        }
     1343                        break;
     1344                case 301:       /* End buddy */
     1345                        if (!strcmp(pair->value, "315") && u) {
     1346                                /* Sometimes user info comes in an odd format with no
     1347                                   "begin buddy" but *with* an "end buddy". Don't add
     1348                                   it twice. */
     1349                                if (!y_list_find(users, u))
     1350                                        users = y_list_prepend(users, u);
     1351                                u = yd->half_user = NULL;
     1352                        }
     1353                        break;
     1354                case 0: /* we won't actually do anything with this */
    14021355                        NOTICE(("key %d:%s", pair->key, pair->value));
    14031356                        break;
    1404                 case 1: /* we don't get the full buddy list here. */
     1357                case 1: /* we don't get the full buddy list here. */
    14051358                        if (!yd->logged_in) {
    1406                                 yd->logged_in = TRUE;
    1407                                 if(yd->current_status < 0)
     1359                                yd->logged_in = 1;
     1360                                if (yd->current_status < 0)
    14081361                                        yd->current_status = yd->initial_status;
    1409                                 YAHOO_CALLBACK(ext_yahoo_login_response)(yd->client_id, YAHOO_LOGIN_OK, NULL);
     1362                                YAHOO_CALLBACK(ext_yahoo_login_response) (yd->
     1363                                        client_id, YAHOO_LOGIN_OK, NULL);
    14101364                        }
    14111365                        break;
    1412                 case 8: /* how many online buddies we have */
     1366                case 8: /* how many online buddies we have */
    14131367                        NOTICE(("key %d:%s", pair->key, pair->value));
    14141368                        break;
    1415                 case 7: /* the current buddy */
    1416                         u = y_new0(struct user, 1);
     1369                case 7: /* the current buddy */
     1370                        if (!u) {
     1371                                /* This will only happen in case of a single level message */
     1372                                u = y_new0(struct yahoo_process_status_entry, 1);
     1373                                users = y_list_prepend(users, u);
     1374                        }
    14171375                        u->name = pair->value;
    1418                         users = y_list_prepend(users, u);
    1419                         break;
    1420                 case 10: /* state */
    1421                         ((struct user*)users->data)->state = strtol(pair->value, NULL, 10);
    1422                         break;
    1423                 case 19: /* custom status message */
    1424                         ((struct user*)users->data)->msg = pair->value;
    1425                         break;
    1426                 case 47: /* is it an away message or not */
    1427                         ((struct user*)users->data)->away = atoi(pair->value);
    1428                         break;
    1429                 case 137: /* seconds idle */
    1430                         ((struct user*)users->data)->idle = atoi(pair->value);
    1431                         break;
    1432                 case 11: /* this is the buddy's session id */
    1433                         ((struct user*)users->data)->buddy_session = atoi(pair->value);
    1434                         break;
    1435                 case 17: /* in chat? */
    1436                         ((struct user*)users->data)->f17 = atoi(pair->value);
    1437                         break;
    1438                 case 13: /* bitmask, bit 0 = pager, bit 1 = chat, bit 2 = game */
    1439                         ((struct user*)users->data)->flags = atoi(pair->value);
    1440                         break;
    1441                 case 60: /* SMS -> 1 MOBILE USER */
     1376                        break;
     1377                case 10:        /* state */
     1378                        u->state = strtol(pair->value, NULL, 10);
     1379                        break;
     1380                case 19:        /* custom status message */
     1381                        u->msg = pair->value;
     1382                        break;
     1383                case 47:        /* is it an away message or not. Not applicable for YMSG16 anymore */
     1384                        u->away = atoi(pair->value);
     1385                        break;
     1386                case 137:       /* seconds idle */
     1387                        u->idle = atoi(pair->value);
     1388                        break;
     1389                case 11:        /* this is the buddy's session id */
     1390                        u->buddy_session = atoi(pair->value);
     1391                        break;
     1392                case 17:        /* in chat? */
     1393                        u->f17 = atoi(pair->value);
     1394                        break;
     1395                case 13:        /* bitmask, bit 0 = pager, bit 1 = chat, bit 2 = game */
     1396                        u->flags = atoi(pair->value);
     1397                        break;
     1398                case 60:        /* SMS -> 1 MOBILE USER */
    14421399                        /* sometimes going offline makes this 2, but invisible never sends it */
    1443                         ((struct user*)users->data)->mobile = atoi(pair->value);
     1400                        u->mobile = atoi(pair->value);
    14441401                        break;
    14451402                case 138:
    1446                         ((struct user*)users->data)->f138 = atoi(pair->value);
     1403                        u->f138 = atoi(pair->value);
    14471404                        break;
    14481405                case 184:
    1449                         ((struct user*)users->data)->f184 = pair->value;
     1406                        u->f184 = pair->value;
    14501407                        break;
    14511408                case 192:
    1452                         ((struct user*)users->data)->f192 = atoi(pair->value);
     1409                        u->f192 = atoi(pair->value);
    14531410                        break;
    14541411                case 10001:
    1455                         ((struct user*)users->data)->f10001 = atoi(pair->value);
     1412                        u->f10001 = atoi(pair->value);
    14561413                        break;
    14571414                case 10002:
    1458                         ((struct user*)users->data)->f10002 = atoi(pair->value);
     1415                        u->f10002 = atoi(pair->value);
    14591416                        break;
    14601417                case 198:
    1461                         ((struct user*)users->data)->f198 = atoi(pair->value);
     1418                        u->f198 = atoi(pair->value);
    14621419                        break;
    14631420                case 197:
    1464                         ((struct user*)users->data)->f197 = pair->value;
     1421                        u->f197 = pair->value;
    14651422                        break;
    14661423                case 205:
    1467                         ((struct user*)users->data)->f205 = pair->value;
     1424                        u->f205 = pair->value;
    14681425                        break;
    14691426                case 213:
    1470                         ((struct user*)users->data)->f213 = atoi(pair->value);
    1471                         break;
    1472                 case 16: /* Custom error message */
    1473                         YAHOO_CALLBACK(ext_yahoo_error)(yd->client_id, pair->value, 0, E_CUSTOM);
     1427                        u->f213 = atoi(pair->value);
     1428                        break;
     1429                case 16:        /* Custom error message */
     1430                        YAHOO_CALLBACK(ext_yahoo_error) (yd->client_id,
     1431                                pair->value, 0, E_CUSTOM);
    14741432                        break;
    14751433                default:
    1476                         WARNING(("unknown status key %d:%s", pair->key, pair->value));
    1477                         break;
    1478                 }
    1479         }
    1480        
     1434                        WARNING(("unknown status key %d:%s", pair->key,
     1435                                        pair->value));
     1436                        break;
     1437                }
     1438        }
     1439
    14811440        while (users) {
    14821441                YList *t = users;
    1483                 struct user *u = users->data;
     1442                struct yahoo_process_status_entry *u = users->data;
    14841443
    14851444                if (u->name != NULL) {
    1486                         if (pkt->service == YAHOO_SERVICE_LOGOFF) { /* || u->flags == 0) { Not in YMSG16 */
    1487                                 YAHOO_CALLBACK(ext_yahoo_status_changed)(yd->client_id, u->name, YAHOO_STATUS_OFFLINE, NULL, 1, 0, 0);
     1445                        if (pkt->service ==
     1446                                YAHOO_SERVICE_LOGOFF
     1447                                /*|| u->flags == 0 No flags for YMSG16 */ ) {
     1448                                YAHOO_CALLBACK(ext_yahoo_status_changed) (yd->
     1449                                        client_id, u->name,
     1450                                        YAHOO_STATUS_OFFLINE, NULL, 1, 0, 0);
    14881451                        } else {
    14891452                                /* Key 47 always seems to be 1 for YMSG16 */
    1490                                 if(!u->state)
     1453                                if (!u->state)
    14911454                                        u->away = 0;
    14921455                                else
    14931456                                        u->away = 1;
    14941457
    1495                                 YAHOO_CALLBACK(ext_yahoo_status_changed)(yd->client_id, u->name, u->state, u->msg, u->away, u->idle, u->mobile);
     1458                                YAHOO_CALLBACK(ext_yahoo_status_changed) (yd->
     1459                                        client_id, u->name, u->state, u->msg,
     1460                                        u->away, u->idle, u->mobile);
    14961461                        }
    14971462                }
     
    15031468}
    15041469
    1505 static void yahoo_process_buddy_list(struct yahoo_input_data *yid, struct yahoo_packet *pkt)
     1470static void yahoo_process_buddy_list(struct yahoo_input_data *yid,
     1471        struct yahoo_packet *pkt)
    15061472{
    15071473        struct yahoo_data *yd = yid->yd;
     
    15151481                struct yahoo_pair *pair = l->data;
    15161482
    1517                 switch(pair->key) {
     1483                switch (pair->key) {
    15181484                case 300:
    15191485                case 301:
    15201486                case 302:
     1487                        break;  /* Separators. Our logic does not need them */
    15211488                case 303:
    1522                         if ( 315 == atoi(pair->value) )
     1489                        if (318 == atoi(pair->value))
    15231490                                last_packet = 1;
    15241491                        break;
    15251492                case 65:
    1526                         g_free(cur_group);
    15271493                        cur_group = strdup(pair->value);
    15281494                        break;
     
    15301496                        newbud = y_new0(struct yahoo_buddy, 1);
    15311497                        newbud->id = strdup(pair->value);
    1532                         if(cur_group)
     1498                        if (cur_group)
    15331499                                newbud->group = strdup(cur_group);
    1534                         else {
    1535                                 struct yahoo_buddy *lastbud = (struct yahoo_buddy *)y_list_nth(
    1536                                                                 yd->buddies, y_list_length(yd->buddies)-1)->data;
     1500                        else if (yd->buddies) {
     1501                                struct yahoo_buddy *lastbud =
     1502                                        (struct yahoo_buddy *)y_list_nth(yd->
     1503                                        buddies,
     1504                                        y_list_length(yd->buddies) - 1)->data;
    15371505                                newbud->group = strdup(lastbud->group);
    1538                         }
     1506                        } else
     1507                                newbud->group = strdup("Buddies");
    15391508
    15401509                        yd->buddies = y_list_append(yd->buddies, newbud);
     
    15431512                }
    15441513        }
    1545        
    1546         g_free(cur_group);
    15471514
    15481515        /* we could be getting multiple packets here */
    1549         if (last_packet)
    1550                 return;
    1551 
    1552         YAHOO_CALLBACK(ext_yahoo_got_buddies)(yd->client_id, yd->buddies);
    1553 
    1554         /*** We login at the very end of the packet communication */
     1516        if (pkt->hash && !last_packet)
     1517                return;
     1518
     1519        YAHOO_CALLBACK(ext_yahoo_got_buddies) (yd->client_id, yd->buddies);
     1520
     1521        /* Logged in */
    15551522        if (!yd->logged_in) {
    1556                 yd->logged_in = TRUE;
    1557                 if(yd->current_status < 0)
     1523                yd->logged_in = 1;
     1524                if (yd->current_status < 0)
    15581525                        yd->current_status = yd->initial_status;
    1559                 YAHOO_CALLBACK(ext_yahoo_login_response)(yd->client_id, YAHOO_LOGIN_OK, NULL);
    1560         }
    1561 }
    1562 
    1563 static void yahoo_process_list(struct yahoo_input_data *yid, struct yahoo_packet *pkt)
     1526                YAHOO_CALLBACK(ext_yahoo_login_response) (yd->client_id,
     1527                        YAHOO_LOGIN_OK, NULL);
     1528
     1529                /*
     1530                yahoo_set_away(yd->client_id, yd->initial_status, NULL,
     1531                        (yd->initial_status == YAHOO_STATUS_AVAILABLE) ? 0 : 1);
     1532
     1533                yahoo_get_yab(yd->client_id);
     1534                */
     1535        }
     1536
     1537}
     1538
     1539static void yahoo_process_list(struct yahoo_input_data *yid,
     1540        struct yahoo_packet *pkt)
    15641541{
    15651542        struct yahoo_data *yd = yid->yd;
    15661543        YList *l;
    15671544
    1568         if (!yd->logged_in) {
    1569                 yd->logged_in = TRUE;
    1570                 if(yd->current_status < 0)
    1571                         yd->current_status = yd->initial_status;
    1572                 YAHOO_CALLBACK(ext_yahoo_login_response)(yd->client_id, YAHOO_LOGIN_OK, NULL);
    1573         }
    1574 
     1545        /* we could be getting multiple packets here */
    15751546        for (l = pkt->hash; l; l = l->next) {
    15761547                struct yahoo_pair *pair = l->data;
    15771548
    1578                 switch(pair->key) {
    1579                 case 87: /* buddies */
    1580                         if(!yd->rawbuddylist)
    1581                                 yd->rawbuddylist = strdup(pair->value);
    1582                         else {
    1583                                 yd->rawbuddylist = y_string_append(yd->rawbuddylist, pair->value);
     1549                switch (pair->key) {
     1550                case 89:        /* identities */
     1551                        {
     1552                                char **identities =
     1553                                        y_strsplit(pair->value, ",", -1);
     1554                                int i;
     1555                                for (i = 0; identities[i]; i++)
     1556                                        yd->identities =
     1557                                                y_list_append(yd->identities,
     1558                                                strdup(identities[i]));
     1559                                y_strfreev(identities);
    15841560                        }
    1585                         break;
    1586 
    1587                 case 88: /* ignore list */
    1588                         if(!yd->ignorelist)
    1589                                 yd->ignorelist = strdup("Ignore:");
    1590                         yd->ignorelist = y_string_append(yd->ignorelist, pair->value);
    1591                         break;
    1592 
    1593                 case 89: /* identities */
    1594                         {
    1595                         char **identities = y_strsplit(pair->value, ",", -1);
    1596                         int i;
    1597                         for(i=0; identities[i]; i++)
    1598                                 yd->identities = y_list_append(yd->identities,
    1599                                                 strdup(identities[i]));
    1600                         y_strfreev(identities);
    1601                         }
    1602                         YAHOO_CALLBACK(ext_yahoo_got_identities)(yd->client_id, yd->identities);
    1603                         break;
    1604                 case 59: /* cookies */
    1605                         if(yd->ignorelist) {
    1606                                 yd->ignore = bud_str2list(yd->ignorelist);
    1607                                 FREE(yd->ignorelist);
    1608                                 YAHOO_CALLBACK(ext_yahoo_got_ignore)(yd->client_id, yd->ignore);
    1609                         }
    1610                         if(yd->rawbuddylist) {
    1611                                 yd->buddies = bud_str2list(yd->rawbuddylist);
    1612                                 FREE(yd->rawbuddylist);
    1613                                 YAHOO_CALLBACK(ext_yahoo_got_buddies)(yd->client_id, yd->buddies);
    1614                         }
    1615 
    1616                         if(pair->value[0]=='Y') {
     1561                        YAHOO_CALLBACK(ext_yahoo_got_identities) (yd->client_id,
     1562                                yd->identities);
     1563                        break;
     1564                case 59:        /* cookies */
     1565                        if (pair->value[0] == 'Y') {
    16171566                                FREE(yd->cookie_y);
    16181567                                FREE(yd->login_cookie);
     
    16211570                                yd->login_cookie = getlcookie(yd->cookie_y);
    16221571
    1623                         } else if(pair->value[0]=='T') {
     1572                        } else if (pair->value[0] == 'T') {
    16241573                                FREE(yd->cookie_t);
    16251574                                yd->cookie_t = getcookie(pair->value);
    16261575
    1627                         } else if(pair->value[0]=='C') {
     1576                        } else if (pair->value[0] == 'C') {
    16281577                                FREE(yd->cookie_c);
    16291578                                yd->cookie_c = getcookie(pair->value);
    1630                         } 
    1631 
    1632                         if(yd->cookie_y && yd->cookie_t)
    1633                                 YAHOO_CALLBACK(ext_yahoo_got_cookies)(yd->client_id);
    1634 
    1635                         break;
    1636                 case 3: /* my id */
    1637                 case 90: /* 1 */
    1638                 case 100: /* 0 */
    1639                 case 101: /* NULL */
    1640                 case 102: /* NULL */
    1641                 case 93: /* 86400/1440 */
    1642                         break;
    1643                 }
    1644         }
     1579                        }
     1580
     1581                        break;
     1582                case 3: /* my id */
     1583                case 90:        /* 1 */
     1584                case 100:       /* 0 */
     1585                case 101:       /* NULL */
     1586                case 102:       /* NULL */
     1587                case 93:        /* 86400/1440 */
     1588                        break;
     1589                }
     1590        }
     1591
     1592        if (yd->cookie_y && yd->cookie_t)       /* We don't get cookie_c anymore */
     1593                YAHOO_CALLBACK(ext_yahoo_got_cookies) (yd->client_id);
    16451594}
    16461595
     
    23932342{
    23942343        struct yahoo_https_auth_data *had = req->data;
    2395         struct yahoo_input_data *yid = had->yid;
    2396         struct yahoo_data *yd = yid->yd;
     2344        struct yahoo_input_data *yid;
     2345        struct yahoo_data *yd;
    23972346        int st;
     2347       
     2348        if (y_list_find(inputs, had->yid) == NULL)
     2349                return;
     2350       
     2351        yid = had->yid;
     2352        yd = yid->yd;
    23982353       
    23992354        if (req->status_code != 200) {
     
    24362391{
    24372392        struct yahoo_https_auth_data *had = req->data;
    2438         struct yahoo_input_data *yid = had->yid;
    2439         struct yahoo_data *yd = yid->yd;
     2393        struct yahoo_input_data *yid;
     2394        struct yahoo_data *yd;
    24402395        struct yahoo_packet *pack;
    2441         char *crumb;
     2396        char *crumb = NULL;
    24422397        int st;
     2398       
     2399        if (y_list_find(inputs, had->yid) == NULL)
     2400                return;
     2401       
     2402        yid = had->yid;
     2403        yd = yid->yd;
    24432404       
    24442405        md5_byte_t result[16];
     
    40804041
    40814042        yd = yid->yd;
    4082 
    40834043        old_status = yd->current_status;
    4084 
    4085         if (msg && strncmp(msg,"Invisible",9)) {
    4086                 yd->current_status = YAHOO_STATUS_CUSTOM;
    4087         } else {
    4088                 yd->current_status = state;
    4089         }
     4044        yd->current_status = state;
    40904045
    40914046        /* Thank you libpurple :) */
     
    41024057        snprintf(s, sizeof(s), "%d", yd->current_status);
    41034058        yahoo_packet_hash(pkt, 10, s);
    4104          
    4105         if (yd->current_status == YAHOO_STATUS_CUSTOM) {
    4106                 yahoo_packet_hash(pkt, 19, msg);
    4107         } else {
    4108                 yahoo_packet_hash(pkt, 19, "");
    4109         }
    4110        
     4059        yahoo_packet_hash(pkt, 19, msg && state == YAHOO_STATUS_CUSTOM ? msg : "");
    41114060        yahoo_packet_hash(pkt, 47, (away == 2)? "2": (away) ?"1":"0");
    4112 
    41134061        yahoo_send_packet(yid, pkt, 0);
    41144062        yahoo_packet_free(pkt);
  • protocols/yahoo/yahoo.c

    r1c3008a re8c8d00  
    130130{
    131131        set_add( &acc->set, "mail_notifications", "false", set_eval_bool, acc );
     132       
     133        acc->flags |= ACC_FLAG_AWAY_MESSAGE | ACC_FLAG_STATUS_MESSAGE;
    132134}
    133135
     
    197199{
    198200        struct byahoo_data *yd = (struct byahoo_data *) ic->proto_data;
    199         char *away;
    200        
    201         away = NULL;
    202        
    203         if( state && msg && g_strcasecmp( state, msg ) != 0 )
    204         {
    205                 yd->current_status = YAHOO_STATUS_CUSTOM;
    206                 away = "";
    207         }
    208         else if( state )
    209         {
    210                 /* Set msg to NULL since (if it isn't NULL already) it's equal
    211                    to state. msg must be empty if we want to use an existing
    212                    away state. */
    213                 msg = NULL;
    214                
    215                 away = "";
    216                 if( g_strcasecmp( state, "Available" ) == 0 )
    217                 {
    218                         yd->current_status = YAHOO_STATUS_AVAILABLE;
    219                         away = NULL;
    220                 }
    221                 else if( g_strcasecmp( state, "Be Right Back" ) == 0 )
     201       
     202        if( state && msg == NULL )
     203        {
     204                /* Use these states only if msg doesn't contain additional
     205                   info since away messages are only supported with CUSTOM. */
     206                if( g_strcasecmp( state, "Be Right Back" ) == 0 )
    222207                        yd->current_status = YAHOO_STATUS_BRB;
    223208                else if( g_strcasecmp( state, "Busy" ) == 0 )
     
    239224                else if( g_strcasecmp( state, "Invisible" ) == 0 )
    240225                        yd->current_status = YAHOO_STATUS_INVISIBLE;
    241                 else if( g_strcasecmp( state, GAIM_AWAY_CUSTOM ) == 0 )
    242                 {
    243                         yd->current_status = YAHOO_STATUS_AVAILABLE;
    244                        
    245                         away = NULL;
    246                 }
    247         }
     226                else
     227                        yd->current_status = YAHOO_STATUS_CUSTOM;
     228        }
     229        else if( msg )
     230                yd->current_status = YAHOO_STATUS_CUSTOM;
    248231        else
    249232                yd->current_status = YAHOO_STATUS_AVAILABLE;
    250233       
    251         yahoo_set_away( yd->y2_id, yd->current_status, msg, away != NULL ? 2 : 0 );
     234        yahoo_set_away( yd->y2_id, yd->current_status, msg, state ? 2 : 0 );
    252235}
    253236
     
    258241        if( m == NULL )
    259242        {
    260                 m = g_list_append( m, "Available" );
    261243                m = g_list_append( m, "Be Right Back" );
    262244                m = g_list_append( m, "Busy" );
     
    269251                m = g_list_append( m, "Stepped Out" );
    270252                m = g_list_append( m, "Invisible" );
    271                 m = g_list_append( m, GAIM_AWAY_CUSTOM );
    272253        }
    273254       
  • protocols/yahoo/yahoo2_types.h

    r1c3008a re8c8d00  
    196196
    197197        void  *server_settings;
     198       
     199        struct yahoo_process_status_entry *half_user;
    198200};
    199201
     
    261263};
    262264
     265struct yahoo_process_status_entry {
     266        char *name;     /* 7      name */
     267        int state;      /* 10     state */
     268        int flags;      /* 13     flags, bit 0 = pager, bit 1 = chat, bit 2 = game */
     269        int mobile;     /* 60     mobile */
     270        char *msg;      /* 19     custom status message */
     271        int away;       /* 47     away (or invisible) */
     272        int buddy_session; /* 11  state */
     273        int f17;        /* 17     in chat? then what about flags? */
     274        int idle;       /* 137    seconds idle */
     275        int f138;       /* 138    state */
     276        char *f184;     /* 184    state */
     277        int f192;       /* 192    state */
     278        int f10001;     /* 10001  state */
     279        int f10002;     /* 10002  state */
     280        int f198;       /* 198    state */
     281        char *f197;     /* 197    state */
     282        char *f205;     /* 205    state */
     283        int f213;       /* 213    state */
     284};
     285
    263286#ifdef __cplusplus
    264287}
  • root_commands.c

    r1c3008a re8c8d00  
    143143        storage_status_t status = storage_load( irc, cmd[1] );
    144144        char *account_on[] = { "account", "on", NULL };
     145       
     146        if( strchr( irc->umode, 'R' ) != NULL )
     147        {
     148                irc_usermsg( irc, "You're already logged in." );
     149                return;
     150        }
    145151       
    146152        switch (status) {
     
    908914                online = 1;
    909915        else
    910                 online =  away = 1;
     916                online = away = 1;
    911917       
    912918        if( strchr( irc->umode, 'b' ) != NULL )
     
    921927                if( online == 1 )
    922928                {
     929                        char st[256] = "Online";
     930                       
     931                        if( u->status_msg )
     932                                g_snprintf( st, sizeof( st ) - 1, "Online (%s)", u->status_msg );
     933                       
    923934                        g_snprintf( s, sizeof( s ) - 1, "%s@%s %s(%s)", u->user, u->host, u->ic->acc->prpl->name, u->ic->acc->user );
    924                         irc_usermsg( irc, format, u->nick, s, "Online" );
     935                        irc_usermsg( irc, format, u->nick, s, st );
    925936                }
    926937               
     
    11151126                irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "chat", cmd[1] );
    11161127        }
    1117 
    1118 
    1119 
    1120 #if 0
    1121         account_t *a;
    1122         struct im_connection *ic;
    1123         char *chat, *channel, *nick = NULL, *password = NULL;
    1124         struct groupchat *c;
    1125        
    1126         if( !( a = account_get( irc, cmd[1] ) ) )
    1127         {
    1128                 irc_usermsg( irc, "Invalid account" );
    1129                 return;
    1130         }
    1131         else if( !( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) )
    1132         {
    1133                 irc_usermsg( irc, "That account is not on-line" );
    1134                 return;
    1135         }
    1136         else if( a->prpl->chat_join == NULL )
    1137         {
    1138                 irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
    1139                 return;
    1140         }
    1141         ic = a->ic;
    1142        
    1143         chat = cmd[2];
    1144         if( cmd[3] )
    1145         {
    1146                 if( strchr( CTYPES, cmd[3][0] ) == NULL )
    1147                         channel = g_strdup_printf( "&%s", cmd[3] );
    1148                 else
    1149                         channel = g_strdup( cmd[3] );
    1150         }
    1151         else
    1152         {
    1153                 char *s;
    1154                
    1155                 channel = g_strdup_printf( "&%s", chat );
    1156                 if( ( s = strchr( channel, '@' ) ) )
    1157                         *s = 0;
    1158         }
    1159         if( cmd[3] && cmd[4] )
    1160                 nick = cmd[4];
    1161         else
    1162                 nick = irc->nick;
    1163         if( cmd[3] && cmd[4] && cmd[5] )
    1164                 password = cmd[5];
    1165        
    1166         if( !nick_ok( channel + 1 ) )
    1167         {
    1168                 irc_usermsg( irc, "Invalid channel name: %s", channel );
    1169                 g_free( channel );
    1170                 return;
    1171         }
    1172         else if( g_strcasecmp( channel, irc->channel ) == 0 || irc_chat_by_channel( irc, channel ) )
    1173         {
    1174                 irc_usermsg( irc, "Channel already exists: %s", channel );
    1175                 g_free( channel );
    1176                 return;
    1177         }
    1178        
    1179         if( ( c = a->prpl->chat_join( ic, chat, nick, password ) ) )
    1180         {
    1181                 g_free( c->channel );
    1182                 c->channel = channel;
    1183         }
    1184         else
    1185         {
    1186                 irc_usermsg( irc, "Tried to join chat, not sure if this was successful" );
    1187                 g_free( channel );
    1188         }
    1189 #endif
    11901128}
    11911129
  • unix.c

    r1c3008a re8c8d00  
    2525
    2626#include "bitlbee.h"
     27
     28#include "arc.h"
     29#include "base64.h"
    2730#include "commands.h"
    28 #include "crypting.h"
    2931#include "protocols/nogaim.h"
    3032#include "help.h"
    3133#include "ipc.h"
     34#include "md5.h"
     35#include "misc.h"
    3236#include <signal.h>
    3337#include <unistd.h>
     
    4044static void sighandler( int signal );
    4145
     46static int crypt_main( int argc, char *argv[] );
     47
    4248int main( int argc, char *argv[] )
    4349{
     
    4551        char *old_cwd = NULL;
    4652        struct sigaction sig, old;
     53       
     54        if( argc > 1 && strcmp( argv[1], "-x" ) == 0 )
     55                return crypt_main( argc, argv );
    4756       
    4857        log_init();
     
    159168}
    160169
     170static int crypt_main( int argc, char *argv[] )
     171{
     172        int pass_len;
     173        unsigned char *pass_cr, *pass_cl;
     174       
     175        if( argc < 4 || ( strcmp( argv[2], "hash" ) != 0 &&
     176                          strcmp( argv[2], "unhash" ) != 0 && argc < 5 ) )
     177        {
     178                printf( "Supported:\n"
     179                        "  %s -x enc <key> <cleartext password>\n"
     180                        "  %s -x dec <key> <encrypted password>\n"
     181                        "  %s -x hash <cleartext password>\n"
     182                        "  %s -x unhash <hashed password>\n"
     183                        "  %s -x chkhash <hashed password> <cleartext password>\n",
     184                        argv[0], argv[0], argv[0], argv[0], argv[0] );
     185        }
     186        else if( strcmp( argv[2], "enc" ) == 0 )
     187        {
     188                pass_len = arc_encode( argv[4], strlen( argv[4] ), (unsigned char**) &pass_cr, argv[3], 12 );
     189                printf( "%s\n", base64_encode( pass_cr, pass_len ) );
     190        }
     191        else if( strcmp( argv[2], "dec" ) == 0 )
     192        {
     193                pass_len = base64_decode( argv[4], (unsigned char**) &pass_cr );
     194                arc_decode( pass_cr, pass_len, (char**) &pass_cl, argv[3] );
     195                printf( "%s\n", pass_cl );
     196        }
     197        else if( strcmp( argv[2], "hash" ) == 0 )
     198        {
     199                md5_byte_t pass_md5[21];
     200                md5_state_t md5_state;
     201               
     202                random_bytes( pass_md5 + 16, 5 );
     203                md5_init( &md5_state );
     204                md5_append( &md5_state, (md5_byte_t*) argv[3], strlen( argv[3] ) );
     205                md5_append( &md5_state, pass_md5 + 16, 5 ); /* Add the salt. */
     206                md5_finish( &md5_state, pass_md5 );
     207               
     208                printf( "%s\n", base64_encode( pass_md5, 21 ) );
     209        }
     210        else if( strcmp( argv[2], "unhash" ) == 0 )
     211        {
     212                printf( "Hash %s submitted to a massive Beowulf cluster of\n"
     213                        "overclocked 486s. Expect your answer next year somewhere around this time. :-)\n", argv[3] );
     214        }
     215        else if( strcmp( argv[2], "chkhash" ) == 0 )
     216        {
     217                char *hash = strncmp( argv[3], "md5:", 4 ) == 0 ? argv[3] + 4 : argv[3];
     218                int st = md5_verify_password( argv[4], hash );
     219               
     220                printf( "Hash %s given password.\n", st == 0 ? "matches" : "does not match" );
     221               
     222                return st;
     223        }
     224       
     225        return 0;
     226}
     227
    161228static void sighandler( int signal )
    162229{
     
    214281        return( (double) time->tv_sec + (double) time->tv_usec / 1000000 );
    215282}
    216 
    217 
  • user.h

    r1c3008a re8c8d00  
    3434       
    3535        char *away;
     36        char *status_msg; /* Non-IRC extension, but nice on IM. */
    3637       
    3738        char is_private;
Note: See TracChangeset for help on using the changeset viewer.