/********************************************************************\ * BitlBee -- An IRC to other IM-networks gateway * * * * Copyright 2002-2010 Wilmer van der Gaast and others * \********************************************************************/ /* IRC commands */ /* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License with the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #define BITLBEE_CORE #include "bitlbee.h" #include "ipc.h" static void irc_cmd_pass( irc_t *irc, char **cmd ) { if( irc->status & USTATUS_LOGGED_IN ) { char *send_cmd[] = { "identify", cmd[1], NULL }; /* We're already logged in, this client seems to send the PASS command last. (Possibly it won't send it at all if it turns out we don't require it, which will break this feature.) Try to identify using the given password. */ return root_command( irc, send_cmd ); } /* Handling in pre-logged-in state, first see if this server is password-protected: */ else if( global.conf->auth_pass && ( strncmp( global.conf->auth_pass, "md5:", 4 ) == 0 ? md5_verify_password( cmd[1], global.conf->auth_pass + 4 ) == 0 : strcmp( cmd[1], global.conf->auth_pass ) == 0 ) ) { irc->status |= USTATUS_AUTHORIZED; irc_check_login( irc ); } else if( global.conf->auth_pass ) { irc_send_num( irc, 464, ":Incorrect password" ); } else { /* Remember the password and try to identify after USER/NICK. */ irc_setpass( irc, cmd[1] ); irc_check_login( irc ); } } static void irc_cmd_user( irc_t *irc, char **cmd ) { irc->user->user = g_strdup( cmd[1] ); irc->user->fullname = g_strdup( cmd[4] ); irc_check_login( irc ); } static void irc_cmd_nick( irc_t *irc, char **cmd ) { irc_user_t *iu; if( ( iu = irc_user_by_name( irc, cmd[1] ) ) && iu != irc->user ) { irc_send_num( irc, 433, "%s :This nick is already in use", cmd[1] ); } else if( !nick_ok( cmd[1] ) ) { /* [SH] Invalid characters. */ irc_send_num( irc, 432, "%s :This nick contains invalid characters", cmd[1] ); } else if( irc->status & USTATUS_LOGGED_IN ) { if( irc->status & USTATUS_IDENTIFIED ) { irc_setpass( irc, NULL ); irc->status &= ~USTATUS_IDENTIFIED; irc_umode_set( irc, "-R", 1 ); irc_usermsg( irc, "Changing nicks resets your identify status. " "Re-identify or register a new account if you want " "your configuration to be saved. See \x02help " "nick_changes\x02." ); } irc_user_set_nick( irc->user, cmd[1] ); } else { g_free( irc->user->nick ); irc->user->nick = g_strdup( cmd[1] ); irc_check_login( irc ); } } static void irc_cmd_quit( irc_t *irc, char **cmd ) { if( cmd[1] && *cmd[1] ) irc_abort( irc, 0, "Quit: %s", cmd[1] ); else irc_abort( irc, 0, "Leaving..." ); } static void irc_cmd_ping( irc_t *irc, char **cmd ) { irc_write( irc, ":%s PONG %s :%s", irc->root->host, irc->root->host, cmd[1]?cmd[1]:irc->root->host ); } static void irc_cmd_pong( irc_t *irc, char **cmd ) { /* We could check the value we get back from the user, but in fact we don't care, we're just happy s/he's still alive. */ irc->last_pong = gettime(); irc->pinging = 0; } static void irc_cmd_join( irc_t *irc, char **cmd ) { char *comma, *s = cmd[1]; while( s ) { irc_channel_t *ic; if( ( comma = strchr( s, ',' ) ) ) *comma = '\0'; if( ( ic = irc_channel_by_name( irc, s ) ) == NULL ) ic = irc_channel_new( irc, s ); if( ic == NULL ) { irc_send_num( irc, 479, "%s :Invalid channel name", s ); goto next; } if( ic->flags & IRC_CHANNEL_JOINED ) /* Dude, you're already there... RFC doesn't have any reply for that though? */ goto next; if( ic->f->join && !ic->f->join( ic ) ) /* The story is: FALSE either means the handler showed an error message, or is doing some work before the join should be confirmed. (In the latter case, the caller should take care of that confirmation.) TRUE means all's good, let the user join the channel right away. */ goto next; irc_channel_add_user( ic, irc->user ); next: if( comma ) { s = comma + 1; *comma = ','; } else break; } } static void irc_cmd_names( irc_t *irc, char **cmd ) { irc_channel_t *ic; if( cmd[1] && ( ic = irc_channel_by_name( irc, cmd[1] ) ) ) irc_send_names( ic ); /* With no args, we should show /names of all chans. Make the code below work well if necessary. else { GSList *l; for( l = irc->channels; l; l = l->next ) irc_send_names( l->data ); } */ } static void irc_cmd_part( irc_t *irc, char **cmd ) { irc_channel_t *ic; if( ( ic = irc_channel_by_name( irc, cmd[1] ) ) == NULL ) { irc_send_num( irc, 403, "%s :No such channel", cmd[1] ); } else if( irc_channel_del_user( ic, irc->user, FALSE, cmd[2] ) ) { if( ic->f->part ) ic->f->part( ic, NULL ); } else { irc_send_num( irc, 442, "%s :You're not on that channel", cmd[1] ); } } static void irc_cmd_whois( irc_t *irc, char **cmd ) { char *nick = cmd[1]; irc_user_t *iu = irc_user_by_name( irc, nick ); if( iu ) irc_send_whois( iu ); else irc_send_num( irc, 401, "%s :Nick does not exist", nick ); } static void irc_cmd_whowas( irc_t *irc, char **cmd ) { /* For some reason irssi tries a whowas when whois fails. We can ignore this, but then the user never gets a "user not found" message from irssi which is a bit annoying. So just respond with not-found and irssi users will get better error messages */ irc_send_num( irc, 406, "%s :Nick does not exist", cmd[1] ); irc_send_num( irc, 369, "%s :End of WHOWAS", cmd[1] ); } static void irc_cmd_motd( irc_t *irc, char **cmd ) { irc_send_motd( irc ); } static void irc_cmd_mode( irc_t *irc, char **cmd ) { if( irc_channel_name_ok( cmd[1] ) ) { irc_channel_t *ic; if( ( ic = irc_channel_by_name( irc, cmd[1] ) ) == NULL ) irc_send_num( irc, 403, "%s :No such channel", cmd[1] ); else if( cmd[2] ) { if( *cmd[2] == '+' || *cmd[2] == '-' ) irc_send_num( irc, 477, "%s :Can't change channel modes", cmd[1] ); else if( *cmd[2] == 'b' ) irc_send_num( irc, 368, "%s :No bans possible", cmd[1] ); } else irc_send_num( irc, 324, "%s +%s", cmd[1], ic->mode ); } else { if( nick_cmp( cmd[1], irc->user->nick ) == 0 ) { if( cmd[2] ) irc_umode_set( irc, cmd[2], 0 ); else irc_send_num( irc, 221, "+%s", irc->umode ); } else irc_send_num( irc, 502, ":Don't touch their modes" ); } } static void irc_cmd_who( irc_t *irc, char **cmd ) { char *channel = cmd[1]; irc_channel_t *ic; if( !channel || *channel == '0' || *channel == '*' || !*channel ) irc_send_who( irc, irc->users, "**" ); else if( ( ic = irc_channel_by_name( irc, channel ) ) ) irc_send_who( irc, ic->users, channel ); else irc_send_num( irc, 403, "%s :No such channel", channel ); } static void irc_cmd_privmsg( irc_t *irc, char **cmd ) { irc_channel_t *ic; irc_user_t *iu; if( !cmd[2] ) { irc_send_num( irc, 412, ":No text to send" ); return; } /* Don't treat CTCP actions as real CTCPs, just convert them right now. */ if( g_strncasecmp( cmd[2], "\001ACTION", 7 ) == 0 ) { cmd[2] += 4; memcpy( cmd[2], "/me", 3 ); if( cmd[2][strlen(cmd[2])-1] == '\001' ) cmd[2][strlen(cmd[2])-1] = '\0'; } if( irc_channel_name_ok( cmd[1] ) && ( ic = irc_channel_by_name( irc, cmd[1] ) ) ) { if( ic->f->privmsg ) ic->f->privmsg( ic, cmd[2] ); } else if( ( iu = irc_user_by_name( irc, cmd[1] ) ) ) { if( cmd[2][0] == '\001' ) { char **ctcp; if( iu->f->ctcp == NULL ) return; if( cmd[2][strlen(cmd[2])-1] == '\001' ) cmd[2][strlen(cmd[2])-1] = '\0'; ctcp = split_command_parts( cmd[2] + 1 ); iu->f->ctcp( iu, ctcp ); } else if( iu->f->privmsg ) { iu->last_channel = NULL; iu->f->privmsg( iu, cmd[2] );
<?xml version='1.0'?>
<!--
	Convert DocBook documentation to help.txt file used by bitlbee
	(C) 2004 Jelmer Vernooij
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	version="1.1">

	<xsl:output method="text" encoding="utf-8" standalone="yes"/>
	<xsl:strip-space elements="*"/>

	<xsl:template match="text()">
		<xsl:if test="starts-with(.,' ') and preceding-sibling::* and
			not(preceding-sibling::*[1]/node()[1][self::text() and contains(concat(.,'^$%'),' ^$%')])">
			<xsl:text> </xsl:text>
		</xsl:if>
	
		<xsl:value-of select="normalize-space(.)"/>
		<xsl:if test="contains(concat(.,'^$%'),' ^$%') and following-sibling::* and
			not(following-sibling::*[1]/node()[1][self::text() and starts-with(.,' ')])">
			<xsl:text> </xsl:text>
		</xsl:if>
	</xsl:template>

	<xsl:template match="para">
		<xsl:apply-templates/><xsl:text>&#10;</xsl:text>
		<xsl:if test="$extraparanewline = '1'">
			<xsl:text>&#10;</xsl:text>
		</xsl:if>
	</xsl:template>

	<xsl:template name="subject">
		<xsl:param name="id"/>
		<xsl:message><xsl:text>Processing: </xsl:text><xsl:value-of select="$id"/></xsl:message>