aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2007-04-22 19:58:44 -0700
committerWilmer van der Gaast <wilmer@gaast.net>2007-04-22 19:58:44 -0700
commit0e7ab64dfb66192a875c37322ca6f8a364ec5bc8 (patch)
tree93e010a079632973a1e101ad0b85e4af67923643
parent43671b964b636520a54e343542c5958b30e9f589 (diff)
Got rid of one HORRIBLE stupidity called chat_by_channel(), which still
used the GLOBAL IM connections list, allowing user A to interfere with user B's groupchats if running in daemon mode. I can't believe this was still there...
-rw-r--r--irc.c22
-rw-r--r--irc.h1
-rw-r--r--irc_commands.c6
-rw-r--r--protocols/jabber/conference.c4
-rw-r--r--protocols/nogaim.c18
-rw-r--r--protocols/nogaim.h1
-rw-r--r--root_commands.c15
7 files changed, 39 insertions, 28 deletions
diff --git a/irc.c b/irc.c
index e953bfad..eec0ce11 100644
--- a/irc.c
+++ b/irc.c
@@ -657,7 +657,7 @@ void irc_names( irc_t *irc, char *channel )
strcat( namelist, " " );
}
}
- else if( ( c = chat_by_channel( channel ) ) )
+ else if( ( c = irc_chat_by_channel( irc, channel ) ) )
{
GList *l;
@@ -810,7 +810,7 @@ void irc_topic( irc_t *irc, char *channel )
}
else
{
- struct groupchat *c = chat_by_channel( channel );
+ struct groupchat *c = irc_chat_by_channel( irc, channel );
if( c )
irc_reply( irc, 332, "%s :BitlBee groupchat: \"%s\". Please keep in mind that root-commands won't work here. Have fun!", channel, c->title );
@@ -948,7 +948,7 @@ int irc_send( irc_t *irc, char *nick, char *s, int flags )
if( *nick == '#' || *nick == '&' )
{
- if( !( c = chat_by_channel( nick ) ) )
+ if( !( c = irc_chat_by_channel( irc, nick ) ) )
{
irc_reply( irc, 403, "%s :Channel does not exist", nick );
return( 0 );
@@ -1214,3 +1214,19 @@ static gboolean irc_userping( gpointer _irc, gint fd, b_input_condition cond )
return TRUE;
}
+
+struct groupchat *irc_chat_by_channel( irc_t *irc, char *channel )
+{
+ struct groupchat *c;
+ account_t *a;
+
+ /* This finds the connection which has a conversation which belongs to this channel */
+ for( a = irc->accounts; a; a = a->next )
+ {
+ for( c = a->ic->groupchats; c && g_strcasecmp( c->channel, channel ) != 0; c = c->next );
+ if( c )
+ return c;
+ }
+
+ return NULL;
+}
diff --git a/irc.h b/irc.h
index 5b770180..8be3579e 100644
--- a/irc.h
+++ b/irc.h
@@ -139,5 +139,6 @@ int irc_msgfrom( irc_t *irc, char *nick, char *msg );
int irc_noticefrom( irc_t *irc, char *nick, char *msg );
void buddy_send_handler( irc_t *irc, user_t *u, char *msg, int flags );
+struct groupchat *irc_chat_by_channel( irc_t *irc, char *channel );
#endif
diff --git a/irc_commands.c b/irc_commands.c
index 8d841aaa..266d9732 100644
--- a/irc_commands.c
+++ b/irc_commands.c
@@ -143,7 +143,7 @@ static void irc_cmd_part( irc_t *irc, char **cmd )
irc_part( irc, u, irc->channel );
irc_join( irc, u, irc->channel );
}
- else if( ( c = chat_by_channel( cmd[1] ) ) )
+ else if( ( c = irc_chat_by_channel( irc, cmd[1] ) ) )
{
user_t *u = user_find( irc, irc->nick );
@@ -200,7 +200,7 @@ static void irc_cmd_join( irc_t *irc, char **cmd )
static void irc_cmd_invite( irc_t *irc, char **cmd )
{
char *nick = cmd[1], *channel = cmd[2];
- struct groupchat *c = chat_by_channel( channel );
+ struct groupchat *c = irc_chat_by_channel( irc, channel );
user_t *u = user_find( irc, nick );
if( u && c && ( u->ic == c->ic ) )
@@ -286,7 +286,7 @@ static void irc_cmd_who( irc_t *irc, char **cmd )
irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->away ? 'G' : 'H', u->realname );
u = u->next;
}
- else if( ( c = chat_by_channel( channel ) ) )
+ else if( ( c = irc_chat_by_channel( irc, channel ) ) )
for( l = c->in_room; l; l = l->next )
{
if( ( u = user_findhandle( c->ic, l->data ) ) )
diff --git a/protocols/jabber/conference.c b/protocols/jabber/conference.c
index 397fad85..c16236b3 100644
--- a/protocols/jabber/conference.c
+++ b/protocols/jabber/conference.c
@@ -101,7 +101,7 @@ int jabber_chat_leave( struct groupchat *c, const char *reason )
}
/* Not really the same syntax as the normal pkt_ functions, but this isn't
- called by the xmltree parser exactly and this way I can add some extra
+ called by the xmltree parser directly and this way I can add some extra
parameters so we won't have to repeat too many things done by the caller
already. */
void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bud, struct xt_node *node )
@@ -150,7 +150,7 @@ void jabber_chat_pkt_presence( struct im_connection *ic, struct jabber_buddy *bu
imcb_chat_add_buddy( chat, bud->orig_jid );
if( s ) *s = '/';
}
- else if( type ) /* This only gets called if type=="unavailable" */
+ else if( type ) /* This only gets called if type is NULL or "unavailable" */
{
/* Won't handle this for now. */
if( bud->orig_jid == NULL )
diff --git a/protocols/nogaim.c b/protocols/nogaim.c
index f3dbb0b8..5b1c4346 100644
--- a/protocols/nogaim.c
+++ b/protocols/nogaim.c
@@ -855,24 +855,6 @@ static int remove_chat_buddy_silent( struct groupchat *b, char *handle )
/* Misc. BitlBee stuff which shouldn't really be here */
-struct groupchat *chat_by_channel( char *channel )
-{
- struct im_connection *ic;
- struct groupchat *c;
- GSList *l;
-
- /* This finds the connection which has a conversation which belongs to this channel */
- for( l = connections; l; l = l->next )
- {
- ic = l->data;
- for( c = ic->groupchats; c && g_strcasecmp( c->channel, channel ) != 0; c = c->next );
- if( c )
- return c;
- }
-
- return NULL;
-}
-
char *set_eval_away_devoice( set_t *set, char *value )
{
irc_t *irc = set->data;
diff --git a/protocols/nogaim.h b/protocols/nogaim.h
index b26cf73e..4eb5cea1 100644
--- a/protocols/nogaim.h
+++ b/protocols/nogaim.h
@@ -206,7 +206,6 @@ G_MODULE_EXPORT void imcb_chat_add_buddy( struct groupchat *b, char *handle );
G_MODULE_EXPORT void imcb_chat_remove_buddy( struct groupchat *b, char *handle, char *reason );
G_MODULE_EXPORT void imcb_chat_msg( struct groupchat *c, char *who, char *msg, u_int32_t flags, time_t sent_at );
G_MODULE_EXPORT void imcb_chat_free( struct groupchat *c );
-struct groupchat *chat_by_channel( char *channel );
/* Actions, or whatever. */
int imc_set_away( struct im_connection *ic, char *away );
diff --git a/root_commands.c b/root_commands.c
index 2b57fb4f..9965c2e8 100644
--- a/root_commands.c
+++ b/root_commands.c
@@ -917,7 +917,7 @@ static void cmd_join_chat( irc_t *irc, char **cmd )
{
char *s;
- channel = g_strdup( chat );
+ channel = g_strdup_printf( "&%s", chat );
if( ( s = strchr( channel, '@' ) ) )
*s = 0;
}
@@ -928,6 +928,19 @@ static void cmd_join_chat( irc_t *irc, char **cmd )
if( cmd[3] && cmd[4] && cmd[5] )
password = cmd[5];
+ if( channel[0] != '#' && channel[0] != '&' )
+ {
+ irc_usermsg( irc, "Invalid channel name: %s", channel );
+ g_free( channel );
+ return;
+ }
+ else if( g_strcasecmp( channel, irc->channel ) == 0 || irc_chat_by_channel( irc, channel ) )
+ {
+ irc_usermsg( irc, "Channel already exists: %s", channel );
+ g_free( channel );
+ return;
+ }
+
if( ( c = a->prpl->chat_join( ic, chat, nick, password ) ) )
{
g_free( c->channel );