/********************************************************************\ * BitlBee -- An IRC to other IM-networks gateway * * * * Copyright 2002-2004 Wilmer van der Gaast and others * \********************************************************************/ /* User manager (root) 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 "commands.h" #include "crypting.h" #include "bitlbee.h" #include "help.h" #include void root_command_string( irc_t *irc, user_t *u, char *command, int flags ) { char *cmd[IRC_MAX_ARGS]; char *s; int k; char q = 0; memset( cmd, 0, sizeof( cmd ) ); cmd[0] = command; k = 1; for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ ) if( *s == ' ' && !q ) { *s = 0; while( *++s == ' ' ); if( *s == '"' || *s == '\'' ) { q = *s; s ++; } if( *s ) { cmd[k++] = s; s --; } else { break; } } else if( *s == '\\' && ( ( !q && s[1] ) || ( q && q == s[1] ) ) ) { char *cpy; for( cpy = s; *cpy; cpy ++ ) cpy[0] = cpy[1]; } else if( *s == q ) { q = *s = 0; } cmd[k] = NULL; root_command( irc, cmd ); } void root_command( irc_t *irc, char *cmd[] ) { int i; if( !cmd[0] ) return; for( i = 0; commands[i].command; i++ ) if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 ) { if( !cmd[commands[i].required_parameters] ) { irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters ); return; } commands[i].execute( irc, cmd ); return; } irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] ); } static void cmd_help( irc_t *irc, char **cmd ) { char param[80]; int i; char *s; memset( param, 0, sizeof(param) ); for ( i = 1; (cmd[i] != NULL && ( strlen(param) < (sizeof(param)-1) ) ); i++ ) { if ( i != 1 ) // prepend space except for the first parameter strcat(param, " "); strncat( param, cmd[i], sizeof(param) - strlen(param) - 1 ); } s = help_get( &(global.help), param ); if( !s ) s = help_get( &(global.help), "" ); if( s ) { irc_usermsg( irc, "%s", s ); g_free( s ); } else { irc_usermsg( irc, "Error opening helpfile." ); } } static void cmd_account( irc_t *irc, char **cmd ); static void cmd_identify( irc_t *irc, char **cmd ) { storage_status_t status = storage_load( irc->nick, cmd[1], irc ); char *account_on[] = { "account", "on", NULL }; switch (status) { case STORAGE_INVALID_PASSWORD: irc_usermsg( irc, "Incorrect password" ); break; case STORAGE_NO_SUCH_USER: irc_usermsg( irc, "The nick is (probably) not registered" ); break; case STORAGE_OK: irc_usermsg( irc, "Password accepted, settings and accounts loaded" ); irc_umode_set( irc, "+R", 1 ); if( set_getbool( &irc->set, "auto_connect" ) ) cmd_account( irc, account_on ); break; case STORAGE_OTHER_ERROR: default: irc_usermsg( irc, "Unknown error while loading configuration" ); break; } } static void cmd_register( irc_t *irc, char **cmd ) { if( global.conf->authmode == AUTHMODE_REGISTERED ) { irc_usermsg( irc, "This server does not allow registering new accounts" ); return; } irc_setpass( irc, cmd[1] ); switch( storage_save( irc, FALSE )) { case STORAGE_ALREADY_EXISTS: irc_usermsg( irc, "Nick is already registered" ); break; case STORAGE_OK: irc_usermsg( irc, "Account successfully created" ); irc->status |= USTATUS_IDENTIFIED; irc_umode_set( irc, "+R", 1 ); break; default: irc_usermsg( irc, "Error registering" ); break; } } static void cmd_drop( irc_t *irc, char **cmd ) { storage_status_t status; status = storage_remove (irc->nick, cmd[1]); switch (status) { case STORAGE_NO_SUCH_USER: irc_usermsg( irc, "That account does not exist" ); break; case STORAGE_INVALID_PASSWORD: irc_usermsg( irc, "Password invalid" ); break; case STORAGE_OK: irc_setpass( irc, NULL ); irc->status &= ~USTATUS_IDENTIFIED; irc_umode_set( irc, "-R", 1 ); irc_usermsg( irc, "Account `%s' removed", irc->nick ); break; default: irc_usermsg( irc, "Error: `%d'", status ); break; } } static void cmd_account( irc_t *irc, char **cmd ) { account_t *a; if( global.conf->authmode == AUTHMODE_REGISTERED && !( irc->status & USTATUS_IDENTIFIED ) ) { irc_usermsg( irc, "This server only accepts registered users" ); return; } if( g_strcasecmp( cmd[1], "add" ) == 0 ) { struct prpl *prpl; if( cmd[2] == NULL || cmd[3] == NULL || cmd[4] == NULL ) { irc_usermsg( irc, "Not enough parameters" ); return; } prpl = find_protocol(cmd[2]); if( prpl == NULL ) { irc_usermsg( irc, "Unknown protocol" ); return; } a = account_add( irc, prpl, cmd[3], cmd[4] ); if( cmd[5] ) { irc_usermsg( irc, "Warning: Passing a servername/other flags to `account add' " "is now deprecated. Use `account set' instead." ); set_setstr( &a->set, "server", cmd[5] ); } irc_usermsg( irc, "Account successfully added" ); } else if( g_strcasecmp( cmd[1], "del" ) == 0 ) { if( !cmd[2] ) { irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); } else if( !( a = account_get( irc, cmd[2] ) ) ) { irc_usermsg( irc, "Invalid account" ); } else if( a->ic ) { irc_usermsg( irc, "Account is still logged in, can't delete" ); } else { account_del( irc, a ); irc_usermsg( irc, "Account deleted" ); } } else if( g_strcasecmp( cmd[1], "list" ) == 0 ) { int i = 0; if( strchr( irc->umode, 'b' ) ) irc_usermsg( irc, "Account list:" ); for( a = irc->accounts; a; a = a->next ) { char *con; if( a->ic && ( a->ic->flags & OPT_LOGGED_IN ) ) con = " (connected)"; else if( a->ic ) con = " (connecting)"; else if( a->reconnect ) con = " (awaiting reconnect)"; else con = ""; irc_usermsg( irc, "%2d. %s, %s%s", i, a->prpl->name, a->user, con ); i ++; } irc_usermsg( irc, "End of account list" ); } else if( g_strcasecmp( cmd[1], "on" ) == 0 ) { if( cmd[2] ) { if( ( a = account_get( irc, cmd[2] ) ) ) { if( a->ic ) { irc_usermsg( irc, "Account already online" ); return; } else { account_on( irc, a ); } } else { irc_usermsg( irc, "Invalid account" ); return; } } else { if ( irc->accounts ) { irc_usermsg( irc, "Trying to get all accounts connected..." ); for( a = irc->accounts; a; a = a->next ) if( !a->ic && a->auto_connect ) account_on( irc, a ); } else { irc_usermsg( irc, "No accounts known. Use `account add' to add one." ); } } } else if( g_strcasecmp( cmd[1], "off" ) == 0 ) { if( !cmd[2] ) { irc_usermsg( irc, "Deactivating all active (re)connections..." ); for( a = irc->accounts; a; a = a->next ) { if( a->ic ) account_off( irc, a ); else if( a->reconnect ) cancel_auto_reconnect( a ); } } else if( ( a = account_get( irc, cmd[2] ) ) ) { if( a->ic ) { account_off( irc, a ); } else if( a->reconnect ) { cancel_auto_reconnect( a ); irc_usermsg( irc, "Reconnect cancelled" ); } else { irc_usermsg( irc, "Account already offline" ); return; } } else { irc_usermsg( irc, "Invalid account" ); return; } } else if( g_strcasecmp( cmd[1], "set" ) == 0 ) { char *acc_handle, *set_name = NULL, *tmp; if( !cmd[2] ) { irc_usermsg( irc, "Not enough parameters given (need %d)", 2 ); return; } if( g_strncasecmp( cmd[2], "-del", 4 ) == 0 ) acc_handle = g_strdup( cmd[3] ); else acc_handle = g_strdup( cmd[2] ); if( ( tmp = strchr( acc_handle, '/' ) ) ) { *tmp = 0; set_name = tmp + 1; } if( ( a = account_get( irc, acc_handle ) ) == NULL ) { g_free( acc_handle ); irc_usermsg( irc, "Invalid account" ); return; } if( cmd[3] && set_name ) { set_t *s = set_find( &a->set, set_name ); if( a->ic && s && s->
  /********************************************************************\
  * BitlBee -- An IRC to other IM-networks gateway                     *
  *                                                                    *
  * Copyright 2002-2004 Wilmer van der Gaast and others                *
  \********************************************************************/

/* MSN module - Some tables with useful data                            */

/*
  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
*/

#include "nogaim.h"
#include "msn.h"

const struct msn_away_state msn_away_state_list[] =
{
	{  0, "NLN", "Available" },
	{  1, "BSY", "Busy" },
	{  3, "IDL", "Idle" },
	{  5, "BRB", "Be Right Back" },
	{  7, "AWY", "Away" },
	{  9, "PHN", "On the Phone" },
	{ 11, "LUN", "Out to Lunch" },
	{ 13, "HDN", "Hidden" },
	{ -1, "",    "" }
};

const struct msn_away_state *msn_away_state_by_number( int number )
{
	int i;
	
	for( i = 0; msn_away_state_list[i].number > -1; i ++ )
		if( msn_away_state_list[i].number == number )
			return( msn_away_state_list + i );
	
	return( NULL );
}

const struct msn_away_state *msn_away_state_by_code( char *code )
{
	int i;
	
	for( i = 0; msn_away_state_list[i].number > -1; i ++ )