Changes in / [ba3a8a5:ced1e17]


Ignore:
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • Makefile

    rba3a8a5 rced1e17  
    1010
    1111# Program variables
    12 objects = account.o bitlbee.o crypting.o help.o ipc.o irc.o irc_commands.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS) user.o
     12objects = account.o bitlbee.o chat.o crypting.o help.o ipc.o irc.o irc_commands.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS) user.o
    1313headers = account.h bitlbee.h commands.h conf.h config.h crypting.h help.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h user.h lib/events.h lib/http_client.h lib/ini.h lib/md5.h lib/misc.h lib/proxy.h lib/sha1.h lib/ssl_client.h lib/url.h protocols/nogaim.h
    1414subdirs = lib protocols
  • account.c

    rba3a8a5 rced1e17  
    190190{
    191191        account_t *a, *l = NULL;
     192        struct chat *c, *nc;
    192193       
    193194        if( acc->ic )
     
    202203                        else
    203204                                irc->accounts = a->next;
     205                       
     206                        for( c = irc->chatrooms; c; c = nc )
     207                        {
     208                                nc = c->next;
     209                                if( acc == c->acc )
     210                                        chat_del( irc, c );
     211                        }
    204212                       
    205213                        while( a->set )
  • bitlbee.h

    rba3a8a5 rced1e17  
    129129#include "account.h"
    130130#include "nick.h"
     131#include "chat.h"
    131132#include "conf.h"
    132133#include "log.h"
  • doc/user-guide/commands.xml

    rba3a8a5 rced1e17  
    125125                        <description>
    126126                                <para>
    127                                         This command gives you a list of all the accounts known by BitlBee, including the numbers you'll need for most account commands.
     127                                        This command gives you a list of all the accounts known by BitlBee.
    128128                                </para>
    129129                        </description>
     
    138138                        <description>
    139139                                <para>
    140                                         This account can be used to change various settings for IM accounts. For all protocols, this command can be used to change the handle or the password BitlBee uses to log in and if it should be logged in automatically. Some protocols have additional settings. You can see the settings available for a connection by typing <emphasis>account set &lt;account id&gt;</emphasis>.
     140                                        This command can be used to change various settings for IM accounts. For all protocols, this command can be used to change the handle or the password BitlBee uses to log in and if it should be logged in automatically. Some protocols have additional settings. You can see the settings available for a connection by typing <emphasis>account set &lt;account id&gt;</emphasis>.
    141141                                </para>
    142142                               
    143143                                <para>
    144                                         For more infomation about a setting, see <emphasis>help set &lt;setting&gt;</emphasis>. For details about the syntax of this command, see <emphasis>help set</emphasis>.
     144                                        For more infomation about a setting, see <emphasis>help set &lt;setting&gt;</emphasis>.
    145145                                </para>
    146146                               
    147147                                <para>
    148148                                        The account ID can be a number (see <emphasis>account list</emphasis>), the protocol name or (part of) the screenname, as long as it matches only one connection.
     149                                </para>
     150                        </description>
     151                </bitlbee-command>
     152        </bitlbee-command>
     153
     154        <bitlbee-command name="chat">
     155                <short-description>Chatroom list maintenance</short-description>
     156                <syntax>chat &lt;action&gt; [&lt;arguments&gt;]</syntax>
     157
     158                <description>
     159
     160                        <para>
     161                                Available actions: add, del, list, with and set. See <emphasis>help chat &lt;action&gt;</emphasis> for more information.
     162                        </para>
     163
     164                </description>
     165
     166                <bitlbee-command name="add">
     167                        <syntax>chat add &lt;account&gt; &lt;room&gt; [&lt;channel&gt;]</syntax>
     168
     169                        <description>
     170                                <para>
     171                                        Add a chatroom to the list of chatrooms you're interested in. BitlBee needs this list to map room names to a proper IRC channel name.
     172                                </para>
     173
     174                                <para>
     175                                        After adding a room to your list, you can simply use the IRC /join command to enter the room. Also, you can tell BitlBee to automatically join the room when you log in. (See <emphasis>chat set</emphasis>)
     176                                </para>
     177                        </description>
     178
     179                </bitlbee-command>
     180
     181                <bitlbee-command name="del">
     182                        <syntax>chat del &lt;chat id&gt;</syntax>
     183
     184                        <description>
     185                                <para>
     186                                        This commands deletes an chatroom from your list.
     187                                </para>
     188
     189                                <para>
     190                                        The room ID can be a number (see <emphasis>chat list</emphasis>), or (part of) the name of the room/channel.
     191                                </para>
     192                        </description>
     193                </bitlbee-command>
     194
     195                <bitlbee-command name="list">
     196                        <syntax>chat list</syntax>
     197
     198                        <description>
     199                                <para>
     200                                        This command gives you a list of all the chatrooms known by BitlBee.
     201                                </para>
     202                        </description>
     203                </bitlbee-command>
     204
     205                <bitlbee-command name="with">
     206                        <syntax>chat with &lt;nickname&gt;</syntax>
     207
     208                        <description>
     209                                <para>
     210                                        While most <emphasis>chat</emphasis> subcommands are about named chatrooms, this command can be used to open an unnamed groupchat with one or more persons. This command is what <emphasis>/join #nickname</emphasis> used to do in older BitlBee versions.
     211                                </para>
     212                        </description>
     213                </bitlbee-command>
     214
     215                <bitlbee-command name="set">
     216                        <syntax>chat set &lt;chat id&gt;</syntax>
     217                        <syntax>chat set &lt;chat id&gt;/&lt;setting&gt;</syntax>
     218                        <syntax>chat set &lt;chat id&gt;/&lt;setting&gt; &lt;value&gt;</syntax>
     219                        <syntax>chat set -del &lt;chat id&gt;/&lt;setting&gt;</syntax>
     220
     221                        <description>
     222                                <para>
     223                                        This command can be used to change various settings for chatrooms.
     224                                </para>
     225                               
     226                                <para>
     227                                        For more infomation about a setting, see <emphasis>help set &lt;setting&gt;</emphasis>.
     228                                </para>
     229                               
     230                                <para>
     231                                        The room ID can be a number (see <emphasis>chat list</emphasis>), or (part of) the name of the room/channel.
    149232                                </para>
    150233                        </description>
     
    303386        </bitlbee-setting>
    304387
     388        <bitlbee-setting name="auto_join" type="boolean" scope="chat">
     389                <default>false</default>
     390
     391                <description>
     392                        <para>
     393                                With this option enabled, BitlBee will automatically join this chatroom when you log in.
     394                        </para>
     395                </description>
     396        </bitlbee-setting>
     397
    305398        <bitlbee-setting name="auto_reconnect" type="boolean" scope="both">
    306399                <default>false</default>
     
    486579        </bitlbee-setting>
    487580
     581        <bitlbee-setting name="nick" type="string" scope="chat">
     582
     583                <description>
     584                        <para>
     585                                You can use this option to set your nickname in a chatroom. You won't see this nickname yourself, but other people in the room will. By default, BitlBee will use your username as the chatroom nickname.
     586                        </para>
     587                </description>
     588        </bitlbee-setting>
     589
    488590        <bitlbee-setting name="ops" type="string" scope="global">
    489591                <default>both</default>
     
    854956
    855957        </bitlbee-command>
    856 
    857         <bitlbee-command name="join_chat">
    858                 <short-description>Join a named groupchat/conference room</short-description>
    859                 <syntax>join_chat &lt;connection&gt; &lt;room name&gt; [&lt;channel name&gt;] [&lt;room nickname&gt;] [&lt;password&gt;]</syntax>
    860 
    861                 <description>
    862                         <para>
    863                                 On most IM-networks groupchats can be started using the /join command. (<emphasis>/join #foo</emphasis> to start a chatroom with you and <emphasis>foo</emphasis>) This doesn't work with names groupchats though (which exist on Jabber networks and AIM, for example), instead you can use this command.
    864                         </para>
    865 
    866                         <para>
    867                                 The first two arguments are required. <emphasis>room name</emphasis> is the name of the chatroom on the IM-network. <emphasis>channel name</emphasis> is the IRC channel name BitlBee should map this to. <emphasis>room nickname</emphasis> is the nickname you want to have in this channel. If you don't give these options, BitlBee will do the right guesses.
    868                         </para>
    869 
    870                         <para>
    871                                 The following command will join you to the chatroom called <emphasis>bitlbee@conference.bitlbee.org</emphasis>. The channel will be called <emphasis>&amp;bitlbee-help</emphasis> because <emphasis>&amp;bitlbee</emphasis> will already be in use. Your nickname will be <emphasis>help-me</emphasis>.
    872                         </para>
    873                 </description>
    874 
    875                 <ircexample>
    876                         <ircline nick="wilmer">join_chat jabber bitlbee@conference.bitlbee.org &amp;bitlbee-help help-me</ircline>
    877                 </ircexample>
    878 
    879         </bitlbee-command>
    880958</chapter>
  • doc/user-guide/misc.xml

    rba3a8a5 rced1e17  
    6969
    7070<para>
    71 If you want to start a groupchat with the person <emphasis>lisa_msn</emphasis> in it, just join the channel <emphasis>#lisa_msn</emphasis>. BitlBee will refuse to join you to the channel with that name, but it will create a new virtual channel with root, you and lisa_msn in it.
     71To open a groupchat, use the <emphasis>chat with</emphasis> command. For example,  to start a groupchat with the person <emphasis>lisa_msn</emphasis> in it, just type <emphasis>chat with lisa_msn</emphasis>. BitlBee will create a new virtual channel with root, you and lisa_msn in it.
    7272</para>
    7373
    7474<para>
    75 Of course a channel with only two people isn't really exciting yet. So the next step is to invite some other people to the channel. For this, you can use the <emphasis>/invite</emphasis> command of your IRC client. Please do keep in mind that all the people have to be on the same network and contact list! You can't invite Yahoo! buddies into an MSN groupchat.
     75Then, just use the ordinary IRC <emphasis>/invite</emphasis> command to invite more people. Please do keep in mind that all the people have to be on the same network and contact list! You can't invite Yahoo! buddies into an MSN groupchat.
    7676</para>
    7777
    7878<para>
    79 Some protocols (like Jabber) also support named groupchats. BitlBee now supports these too. You can use the <emphasis>join_chat</emphasis> command to join them. See <emphasis>help join_chat</emphasis> for more information.
     79Some protocols (like Jabber) also support named groupchats. BitlBee now supports these too. You can use the <emphasis>chat add</emphasis> command to join them. See <emphasis>help chat_add</emphasis> for more information.
    8080</para>
    8181
  • irc.c

    rba3a8a5 rced1e17  
    781781        irc_reply( irc,   3, ":%s", IRCD_INFO );
    782782        irc_reply( irc,   4, "%s %s %s %s", irc->myhost, BITLBEE_VERSION, UMODES UMODES_PRIV, CMODES );
    783         irc_reply( irc,   5, "PREFIX=(ov)@+ CHANTYPES=#& CHANMODES=,,,%s NICKLEN=%d NETWORK=BitlBee CASEMAPPING=rfc1459 MAXTARGETS=1 WATCH=128 :are supported by this server", CMODES, MAX_NICK_LENGTH - 1 );
     783        irc_reply( irc,   5, "PREFIX=(ov)@+ CHANTYPES=%s CHANMODES=,,,%s NICKLEN=%d NETWORK=BitlBee "
     784                             "CASEMAPPING=rfc1459 MAXTARGETS=1 WATCH=128 :are supported by this server",
     785                             CTYPES, CMODES, MAX_NICK_LENGTH - 1 );
    784786        irc_motd( irc );
    785787        irc->umode[0] = '\0';
     
    10221024        user_t *u = NULL;
    10231025       
    1024         if( *nick == '#' || *nick == '&' )
     1026        if( strchr( CTYPES, *nick ) )
    10251027        {
    10261028                if( !( c = irc_chat_by_channel( irc, nick ) ) )
  • irc.h

    rba3a8a5 rced1e17  
    3838#define CMODE "t"
    3939#define UMODE "s"
     40#define CTYPES "&#"
    4041
    4142typedef enum
     
    4748        USTATUS_SHUTDOWN = 8
    4849} irc_status_t;
    49 
    50 typedef struct channel
    51 {
    52         char *name;
    53 } channel_t;
    5450
    5551typedef struct irc
     
    8783        struct query *queries;
    8884        struct account *accounts;
     85        struct chat *chatrooms;
    8986       
    9087        struct __USER *users;
     
    10097
    10198#include "user.h"
    102 // #include "nick.h"
    10399
    104100extern GSList *irc_connection_list;
  • irc_commands.c

    rba3a8a5 rced1e17  
    125125static void irc_cmd_mode( irc_t *irc, char **cmd )
    126126{
    127         if( *cmd[1] == '#' || *cmd[1] == '&' )
     127        if( strchr( CTYPES, *cmd[1] ) )
    128128        {
    129129                if( cmd[2] )
     
    193193        else if( cmd[1] )
    194194        {
    195                 if( ( cmd[1][0] == '#' || cmd[1][0] == '&' ) && cmd[1][1] )
    196                 {
    197                         user_t *u = user_find( irc, cmd[1] + 1 );
    198                        
    199                         if( u && u->ic && u->ic->acc->prpl->chat_with )
    200                         {
    201                                 irc_reply( irc, 403, "%s :Initializing groupchat in a different channel", cmd[1] );
    202                                
    203                                 if( !u->ic->acc->prpl->chat_with( u->ic, u->handle ) )
    204                                 {
    205                                         irc_usermsg( irc, "Could not open a groupchat with %s.", u->nick );
    206                                 }
    207                         }
    208                         else if( u )
    209                         {
    210                                 irc_reply( irc, 403, "%s :Groupchats are not possible with %s", cmd[1], cmd[1]+1 );
    211                         }
    212                         else
    213                         {
    214                                 irc_reply( irc, 403, "%s :No such nick", cmd[1] );
    215                         }
     195                struct chat *c;
     196                user_t *u;
     197               
     198                if( strchr( CTYPES, cmd[1][0] ) == NULL || cmd[1][1] == 0 )
     199                {
     200                        irc_reply( irc, 403, "%s :No such channel", cmd[1] );
     201                        return;
     202                }
     203               
     204                if( ( c = chat_bychannel( irc, cmd[1] ) ) )
     205                {
     206                        chat_join( irc, c );
    216207                }
    217208                else
  • protocols/nogaim.c

    rba3a8a5 rced1e17  
    249249void imcb_connected( struct im_connection *ic )
    250250{
     251        irc_t *irc = ic->irc;
     252        struct chat *c;
    251253        user_t *u;
    252254       
     
    271273           exponential backoff timer. */
    272274        ic->acc->auto_reconnect_delay = 0;
     275       
     276        for( c = irc->chatrooms; c; c = c->next )
     277        {
     278                if( c->acc != ic->acc )
     279                        continue;
     280               
     281                if( set_getbool( &c->set, "auto_join" ) )
     282                        chat_join( irc, c );
     283        }
    273284}
    274285
  • root_commands.c

    rba3a8a5 rced1e17  
    7878}
    7979
     80#define MIN_ARGS( x, y... )                                                    \
     81        do                                                                     \
     82        {                                                                      \
     83                int blaat;                                                     \
     84                for( blaat = 0; blaat <= x; blaat ++ )                         \
     85                        if( cmd[blaat] == NULL )                               \
     86                        {                                                      \
     87                                irc_usermsg( irc, "Not enough parameters given (need %d).", x ); \
     88                                return y;                                      \
     89                        }                                                      \
     90        } while( 0 )
     91
    8092void root_command( irc_t *irc, char *cmd[] )
    8193{       
     
    88100                if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 )
    89101                {
    90                         if( !cmd[commands[i].required_parameters] )
    91                         {
    92                                 irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters );
    93                                 return;
    94                         }
     102                        MIN_ARGS( commands[i].required_parameters );
     103                       
    95104                        commands[i].execute( irc, cmd );
    96105                        return;
     
    250259}
    251260
     261typedef set_t** (*cmd_set_findhead)( irc_t*, char* );
     262
     263static int cmd_set_real( irc_t *irc, char **cmd, cmd_set_findhead findhead )
     264{
     265        char *set_full = NULL, *set_name = NULL, *tmp;
     266        set_t **head;
     267       
     268        if( cmd[1] && g_strncasecmp( cmd[1], "-del", 4 ) == 0 )
     269        {
     270                MIN_ARGS( 2, 0 );
     271                set_full = cmd[2];
     272        }
     273        else
     274                set_full = cmd[1];
     275       
     276        if( findhead == NULL )
     277        {
     278                set_name = set_full;
     279               
     280                head = &irc->set;
     281        }
     282        else
     283        {
     284                char *id;
     285               
     286                if( ( tmp = strchr( set_full, '/' ) ) )
     287                {
     288                        id = g_strndup( set_full, ( tmp - set_full ) );
     289                        set_name = tmp + 1;
     290                }
     291                else
     292                {
     293                        id = g_strdup( set_full );
     294                }
     295               
     296                if( ( head = findhead( irc, id ) ) == NULL )
     297                {
     298                        g_free( id );
     299                        irc_usermsg( irc, "Could not find setting." );
     300                        return 0;
     301                }
     302                g_free( id );
     303        }
     304       
     305        if( cmd[1] && cmd[2] && set_name )
     306        {
     307                set_t *s = set_find( head, set_name );
     308                int st;
     309               
     310                /*
     311                FIXME: Make these work again. Probably a gross hack.
     312               
     313                if( a->ic && s && s->flags & ACC_SET_OFFLINE_ONLY )
     314                {
     315                        irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" );
     316                        return 0;
     317                }
     318                else if( !a->ic && s && s->flags & ACC_SET_ONLINE_ONLY )
     319                {
     320                        irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" );
     321                        return 0;
     322                }
     323                */
     324               
     325                if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 )
     326                        st = set_reset( head, set_name );
     327                else
     328                        st = set_setstr( head, set_name, cmd[2] );
     329               
     330                if( set_getstr( head, set_name ) == NULL )
     331                {
     332                        if( st )
     333                                irc_usermsg( irc, "Setting changed successfully" );
     334                        else
     335                                irc_usermsg( irc, "Failed to change setting" );
     336                }
     337                else
     338                {
     339                        cmd_showset( irc, head, set_name );
     340                }
     341        }
     342        else if( set_name )
     343        {
     344                cmd_showset( irc, head, set_name );
     345        }
     346        else
     347        {
     348                set_t *s = *head;
     349                while( s )
     350                {
     351                        cmd_showset( irc, &s, s->key );
     352                        s = s->next;
     353                }
     354        }
     355       
     356        return 1;
     357}
     358
     359static set_t **cmd_account_set_findhead( irc_t *irc, char *id )
     360{
     361        account_t *a;
     362       
     363        if( ( a = account_get( irc, id ) ) )
     364                return &a->set;
     365        else
     366                return NULL;
     367}
     368
    252369static void cmd_account( irc_t *irc, char **cmd )
    253370{
     
    264381                struct prpl *prpl;
    265382               
    266                 if( cmd[2] == NULL || cmd[3] == NULL || cmd[4] == NULL )
    267                 {
    268                         irc_usermsg( irc, "Not enough parameters" );
    269                         return;
    270                 }
    271                
    272                 prpl = find_protocol(cmd[2]);
     383                MIN_ARGS( 4 );
     384               
     385                prpl = find_protocol( cmd[2] );
    273386               
    274387                if( prpl == NULL )
     
    290403        else if( g_strcasecmp( cmd[1], "del" ) == 0 )
    291404        {
    292                 if( !cmd[2] )
    293                 {
    294                         irc_usermsg( irc, "Not enough parameters given (need %d)", 2 );
    295                 }
    296                 else if( !( a = account_get( irc, cmd[2] ) ) )
     405                MIN_ARGS( 2 );
     406
     407                if( !( a = account_get( irc, cmd[2] ) ) )
    297408                {
    298409                        irc_usermsg( irc, "Invalid account" );
     
    422533        else if( g_strcasecmp( cmd[1], "set" ) == 0 )
    423534        {
    424                 char *acc_handle, *set_name = NULL, *tmp;
    425                
    426                 if( !cmd[2] )
    427                 {
    428                         irc_usermsg( irc, "Not enough parameters given (need %d)", 2 );
    429                         return;
    430                 }
    431                
    432                 if( g_strncasecmp( cmd[2], "-del", 4 ) == 0 )
    433                         acc_handle = g_strdup( cmd[3] );
    434                 else
    435                         acc_handle = g_strdup( cmd[2] );
    436                
    437                 if( !acc_handle )
    438                 {
    439                         irc_usermsg( irc, "Not enough parameters given (need %d)", 3 );
    440                         return;
    441                 }
    442                
    443                 if( ( tmp = strchr( acc_handle, '/' ) ) )
    444                 {
    445                         *tmp = 0;
    446                         set_name = tmp + 1;
    447                 }
    448                
    449                 if( ( a = account_get( irc, acc_handle ) ) == NULL )
    450                 {
    451                         g_free( acc_handle );
    452                         irc_usermsg( irc, "Invalid account" );
    453                         return;
    454                 }
    455                
    456                 if( cmd[3] && set_name )
    457                 {
    458                         set_t *s = set_find( &a->set, set_name );
    459                         int st;
    460                        
    461                         if( a->ic && s && s->flags & ACC_SET_OFFLINE_ONLY )
    462                         {
    463                                 g_free( acc_handle );
    464                                 irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "off" );
    465                                 return;
    466                         }
    467                         else if( !a->ic && s && s->flags & ACC_SET_ONLINE_ONLY )
    468                         {
    469                                 g_free( acc_handle );
    470                                 irc_usermsg( irc, "This setting can only be changed when the account is %s-line", "on" );
    471                                 return;
    472                         }
    473                        
    474                         if( g_strncasecmp( cmd[2], "-del", 4 ) == 0 )
    475                                 st = set_reset( &a->set, set_name );
    476                         else
    477                                 st = set_setstr( &a->set, set_name, cmd[3] );
    478                        
    479                         if( set_getstr( &a->set, set_name ) == NULL )
    480                         {
    481                                 if( st )
    482                                         irc_usermsg( irc, "Setting changed successfully" );
    483                                 else
    484                                         irc_usermsg( irc, "Failed to change setting" );
    485                         }
    486                         else
    487                         {
    488                                 cmd_showset( irc, &a->set, set_name );
    489                         }
    490                 }
    491                 else if( set_name )
    492                 {
    493                         cmd_showset( irc, &a->set, set_name );
    494                 }
    495                 else
    496                 {
    497                         set_t *s = a->set;
    498                         while( s )
    499                         {
    500                                 cmd_showset( irc, &s, s->key );
    501                                 s = s->next;
    502                         }
    503                 }
    504                
    505                 g_free( acc_handle );
    506         }
    507         else
    508         {
    509                 irc_usermsg( irc, "Unknown command: account %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[1] );
     535                MIN_ARGS( 2 );
     536               
     537                cmd_set_real( irc, cmd + 1, cmd_account_set_findhead );
     538        }
     539        else
     540        {
     541                irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "account", cmd[1] );
    510542        }
    511543}
     
    837869static void cmd_set( irc_t *irc, char **cmd )
    838870{
    839         char *set_name = cmd[1];
    840        
    841         if( cmd[1] && cmd[2] )
    842         {
    843                 int st;
    844                
    845                 if( g_strncasecmp( cmd[1], "-del", 4 ) == 0 )
    846                 {
    847                         st = set_reset( &irc->set, cmd[2] );
    848                         set_name = cmd[2];
    849                 }
    850                 else
    851                 {
    852                         st = set_setstr( &irc->set, cmd[1], cmd[2] );
    853                 }
    854                
    855                 /* Normally we just show the variable's new/unchanged
    856                    value as feedback to the user, but this has always
    857                    caused confusion when changing the password. Give
    858                    other feedback instead: */
    859                 if( set_getstr( &irc->set, set_name ) == NULL )
    860                 {
    861                         if( st )
    862                                 irc_usermsg( irc, "Setting changed successfully" );
    863                         else
    864                                 irc_usermsg( irc, "Failed to change setting" );
    865                 }
    866                 else
    867                 {
    868                         cmd_showset( irc, &irc->set, set_name );
    869                 }
    870         }
    871         else if( set_name )
    872         {
    873                 cmd_showset( irc, &irc->set, set_name );
    874 
    875                 if( strchr( set_name, '/' ) )
    876                         irc_usermsg( irc, "Warning: / found in setting name, you're probably looking for the `account set' command." );
    877         }
    878         else
    879         {
    880                 set_t *s = irc->set;
    881                 while( s )
    882                 {
    883                         cmd_showset( irc, &s, s->key );
    884                         s = s->next;
    885                 }
    886         }
     871        cmd_set_real( irc, cmd, NULL );
    887872}
    888873
     
    1007992static void cmd_join_chat( irc_t *irc, char **cmd )
    1008993{
     994        irc_usermsg( irc, "This command is now obsolete. "
     995                          "Please try the `chat' command instead." );
     996}
     997
     998static set_t **cmd_chat_set_findhead( irc_t *irc, char *id )
     999{
     1000        struct chat *c;
     1001       
     1002        if( ( c = chat_get( irc, id ) ) )
     1003                return &c->set;
     1004        else
     1005                return NULL;
     1006}
     1007
     1008static void cmd_chat( irc_t *irc, char **cmd )
     1009{
     1010        account_t *acc;
     1011        struct chat *c;
     1012       
     1013        if( g_strcasecmp( cmd[1], "add" ) == 0 )
     1014        {
     1015                char *channel, *s;
     1016               
     1017                MIN_ARGS( 3 );
     1018               
     1019                if( !( acc = account_get( irc, cmd[2] ) ) )
     1020                {
     1021                        irc_usermsg( irc, "Invalid account" );
     1022                        return;
     1023                }
     1024               
     1025                if( cmd[4] == NULL )
     1026                {
     1027                        channel = g_strdup( cmd[3] );
     1028                        if( ( s = strchr( channel, '@' ) ) )
     1029                                *s = 0;
     1030                }
     1031                else
     1032                {
     1033                        channel = g_strdup( cmd[4] );
     1034                }
     1035               
     1036                if( strchr( CTYPES, channel[0] ) == NULL )
     1037                {
     1038                        s = g_strdup_printf( "%c%s", CTYPES[0], channel );
     1039                        g_free( channel );
     1040                        channel = s;
     1041                }
     1042               
     1043                if( ( c = chat_add( irc, acc, cmd[3], channel ) ) )
     1044                        irc_usermsg( irc, "Chatroom added successfully." );
     1045                else
     1046                        irc_usermsg( irc, "Could not add chatroom." );
     1047               
     1048                g_free( channel );
     1049        }
     1050        else if( g_strcasecmp( cmd[1], "list" ) == 0 )
     1051        {
     1052                int i = 0;
     1053               
     1054                if( strchr( irc->umode, 'b' ) )
     1055                        irc_usermsg( irc, "Chatroom list:" );
     1056               
     1057                for( c = irc->chatrooms; c; c = c->next )
     1058                {
     1059                        irc_usermsg( irc, "%2d. %s(%s) %s, %s", i, c->acc->prpl->name,
     1060                                          c->acc->user, c->handle, c->channel );
     1061                       
     1062                        i ++;
     1063                }
     1064                irc_usermsg( irc, "End of chatroom list" );
     1065        }
     1066        else if( g_strcasecmp( cmd[1], "set" ) == 0 )
     1067        {
     1068                cmd_set_real( irc, cmd + 1, cmd_chat_set_findhead );
     1069        }
     1070        else if( g_strcasecmp( cmd[1], "del" ) == 0 )
     1071        {
     1072                MIN_ARGS( 2 );
     1073               
     1074                if( ( c = chat_get( irc, cmd[2] ) ) )
     1075                {
     1076                        chat_del( irc, c );
     1077                }
     1078                else
     1079                {
     1080                        irc_usermsg( irc, "Could not remove chat." );
     1081                }
     1082        }
     1083        else if( g_strcasecmp( cmd[1], "with" ) == 0 )
     1084        {
     1085                user_t *u;
     1086               
     1087                MIN_ARGS( 2 );
     1088               
     1089                if( ( u = user_find( irc, cmd[2] ) ) && u->ic && u->ic->acc->prpl->chat_with )
     1090                {
     1091                        if( !u->ic->acc->prpl->chat_with( u->ic, u->handle ) )
     1092                        {
     1093                                irc_usermsg( irc, "(Possible) failure while trying to open "
     1094                                                  "a groupchat with %s.", u->nick );
     1095                        }
     1096                }
     1097                else
     1098                {
     1099                        irc_usermsg( irc, "Can't open a groupchat with %s.", cmd[2] );
     1100                }
     1101        }
     1102        else
     1103        {
     1104                irc_usermsg( irc, "Unknown command: %s %s. Please use \x02help commands\x02 to get a list of available commands.", "chat", cmd[1] );
     1105        }
     1106
     1107
     1108
     1109#if 0
    10091110        account_t *a;
    10101111        struct im_connection *ic;
     
    10321133        if( cmd[3] )
    10331134        {
    1034                 if( cmd[3][0] != '#' && cmd[3][0] != '&' )
     1135                if( strchr( CTYPES, cmd[3][0] ) == NULL )
    10351136                        channel = g_strdup_printf( "&%s", cmd[3] );
    10361137                else
     
    10751176                g_free( channel );
    10761177        }
     1178#endif
    10771179}
    10781180
     
    10971199        { "qlist",          0, cmd_qlist,          0 },
    10981200        { "join_chat",      2, cmd_join_chat,      0 },
     1201        { "chat",           1, cmd_chat,           0 },
    10991202        { NULL }
    11001203};
  • storage_xml.c

    rba3a8a5 rced1e17  
    5454        char *current_setting;
    5555        account_t *current_account;
     56        struct chat *current_chat;
     57        set_t **current_set_head;
    5658        char *given_nick;
    5759        char *given_pass;
     
    172174               
    173175                if( ( setting = xml_attr( attr_names, attr_values, "name" ) ) )
     176                {
     177                        if( xd->current_chat != NULL )
     178                                xd->current_set_head = &xd->current_chat->set;
     179                        else if( xd->current_account != NULL )
     180                                xd->current_set_head = &xd->current_account->set;
     181                        else
     182                                xd->current_set_head = &xd->irc->set;
     183                       
    174184                        xd->current_setting = g_strdup( setting );
     185                }
    175186                else
    176187                        g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
     
    194205                }
    195206        }
     207        else if( g_strcasecmp( element_name, "chat" ) == 0 )
     208        {
     209                char *handle, *channel;
     210               
     211                handle = xml_attr( attr_names, attr_values, "handle" );
     212                channel = xml_attr( attr_names, attr_values, "channel" );
     213               
     214                if( xd->current_account && handle && channel )
     215                {
     216                        xd->current_chat = chat_add( xd->irc, xd->current_account, handle, channel );
     217                }
     218                else
     219                {
     220                        g_set_error( error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
     221                                     "Missing attributes for %s element", element_name );
     222                }
     223        }
    196224        else
    197225        {
     
    214242                xd->current_account = NULL;
    215243        }
     244        else if( g_strcasecmp( element_name, "chat" ) == 0 )
     245        {
     246                xd->current_chat = NULL;
     247        }
    216248}
    217249
     
    220252        char text[text_len+1];
    221253        struct xml_parsedata *xd = data;
    222         irc_t *irc = xd->irc;
    223254       
    224255        strncpy( text, text_orig, text_len );
     
    233264        else if( g_strcasecmp( g_markup_parse_context_get_element( ctx ), "setting" ) == 0 && xd->current_setting )
    234265        {
    235                 set_setstr( xd->current_account ? &xd->current_account->set : &irc->set,
    236                             xd->current_setting, (char*) text );
     266                set_setstr( xd->current_set_head, xd->current_setting, (char*) text );
    237267                g_free( xd->current_setting );
    238268                xd->current_setting = NULL;
     
    397427       
    398428        for( set = irc->set; set; set = set->next )
    399                 if( set->value && set->def )
     429                if( set->value )
    400430                        if( !xml_printf( fd, 1, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
    401431                                goto write_error;
     
    406436                char *pass_b64;
    407437                int pass_len;
     438                struct chat *c;
    408439               
    409440                pass_len = arc_encode( acc->pass, strlen( acc->pass ), (unsigned char**) &pass_cr, irc->password, 12 );
     
    424455               
    425456                for( set = acc->set; set; set = set->next )
    426                         if( set->value && set->def && !( set->flags & ACC_SET_NOSAVE ) )
     457                        if( set->value && !( set->flags & ACC_SET_NOSAVE ) )
    427458                                if( !xml_printf( fd, 2, "<setting name=\"%s\">%s</setting>\n", set->key, set->value ) )
    428459                                        goto write_error;
     
    438469                        goto write_error;
    439470               
     471                for( c = irc->chatrooms; c; c = c->next )
     472                {
     473                        if( c->acc != acc )
     474                                continue;
     475                       
     476                        if( !xml_printf( fd, 2, "<chat handle=\"%s\" channel=\"%s\" type=\"%s\">\n",
     477                                                c->handle, c->channel, "room" ) )
     478                                goto write_error;
     479                       
     480                        for( set = c->set; set; set = set->next )
     481                                if( set->value && !( set->flags & ACC_SET_NOSAVE ) )
     482                                        if( !xml_printf( fd, 3, "<setting name=\"%s\">%s</setting>\n",
     483                                                                set->key, set->value ) )
     484                                                goto write_error;
     485
     486                        if( !xml_printf( fd, 2, "</chat>\n" ) )
     487                                goto write_error;
     488                }
     489               
    440490                if( !xml_printf( fd, 1, "</account>\n" ) )
    441491                        goto write_error;
Note: See TracChangeset for help on using the changeset viewer.