source: chat.c @ e7bc722

Last change on this file since e7bc722 was e7bc722, checked in by Wilmer van der Gaast <wilmer@…>, at 2008-08-31T00:04:53Z

Integrated cmd_set() and the "account set" into one fully unreadable
cmd_set_real() function and using this to get a proper "chat set" command.

  • Property mode set to 100644
File size: 3.2 KB
Line 
1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2008 Wilmer van der Gaast and others                *
5  \********************************************************************/
6
7/* Keep track of chatrooms the user is interested in                    */
8
9/*
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License with
21  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
22  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23  Suite 330, Boston, MA  02111-1307  USA
24*/
25
26#include "bitlbee.h"
27
28struct chat *chat_add( irc_t *irc, account_t *acc, char *handle, char *channel )
29{
30        struct chat *c, *l;
31        set_t *s;
32       
33        if( !chat_chanok( channel ) )
34                return NULL;
35       
36        for( c = irc->chatrooms; c; c = c->next )
37        {
38                if( chat_chancmp( channel, c->channel ) == 0 )
39                        return NULL;
40               
41                if( acc == c->acc && g_strcasecmp( handle, c->handle ) == 0 )
42                        return NULL;
43               
44                l = c;
45        }
46       
47        if( irc->chatrooms == NULL )
48                irc->chatrooms = c = g_new0( struct chat, 1 );
49        else
50                l->next = c = g_new0( struct chat, 1 );
51       
52        c->acc = acc;
53        c->handle = g_strdup( handle );
54        c->channel = g_strdup( channel );
55       
56        s = set_add( &c->set, "auto_join", "false", set_eval_bool, c );
57        s = set_add( &c->set, "auto_rejoin", "false", set_eval_bool, c );
58        s = set_add( &c->set, "nick", NULL, NULL, c );
59        s->flags |= SET_NULL_OK;
60       
61        return c;
62}
63
64struct chat *chat_byhandle( irc_t *irc, account_t *acc, char *handle )
65{
66        struct chat *c;
67       
68        for( c = irc->chatrooms; c; c = c->next )
69        {
70                if( acc == c->acc && g_strcasecmp( handle, c->handle ) == 0 )
71                        break;
72        }
73       
74        return c;
75}
76
77struct chat *chat_bychannel( irc_t *irc, char *channel )
78{
79        struct chat *c;
80       
81        for( c = irc->chatrooms; c; c = c->next )
82        {
83                if( chat_chancmp( channel, c->channel ) == 0 )
84                        break;
85        }
86       
87        return c;
88}
89
90struct chat *chat_get( irc_t *irc, char *id )
91{
92        struct chat *c, *ret = NULL;
93        int nr;
94       
95        if( sscanf( id, "%d", &nr ) == 1 && nr < 1000 )
96        {
97                for( c = irc->chatrooms; c; c = c->next )
98                        if( ( nr-- ) == 0 )
99                                return c;
100               
101                return NULL;
102        }
103       
104        for( c = irc->chatrooms; c; c = c->next )
105        {
106                if( strstr( c->handle, id ) )
107                {
108                        if( !ret )
109                                ret = c;
110                        else
111                                return NULL;
112                }
113                else if( strstr( c->channel, id ) )
114                {
115                        if( !ret )
116                                ret = c;
117                        else
118                                return NULL;
119                }
120        }
121       
122        return ret;
123}
124
125int chat_chancmp( char *a, char *b )
126{
127        if( !chat_chanok( a ) || !chat_chanok( b ) )
128                return 0;
129       
130        if( a[0] == b[0] )
131                return nick_cmp( a + 1, b + 1 );
132        else
133                return -1;
134}
135
136int chat_chanok( char *a )
137{
138        if( strchr( "&#", a[0] ) != NULL )
139                return nick_ok( a + 1 );
140        else
141                return 0;
142}
Note: See TracBrowser for help on using the repository browser.