Exemplo n.º 1
0
/* SYNTAX: NICK <new nick> */
static void cmd_nick(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
{
        char *nick;
	void *free_arg;

	g_return_if_fail(data != NULL);

	if (!IS_IRC_SERVER(server) || !server->connected)
		cmd_return_error(CMDERR_NOT_CONNECTED);

	if (!cmd_get_params(data, &free_arg, 1, &nick))
		return;

	server->nick_changing = TRUE;
	irc_send_cmdv(server, "NICK %s", nick);

	nick = g_strdup_printf("%s :%s", nick, nick);
	server_redirect_event(SERVER(server), nick, 5,
			      "event nick", "nickchange over", 0,
			      "event 433", "nickchange over", 1,
			      /* 437: ircnet = target unavailable,
				      dalnet = banned in channel,
				               can't change nick */
			      "event 437", "nickchange over", -1,
			      "event 432", "nickchange over", 1,
			      "event 438", "nickchange over", 1, NULL);
        g_free(nick);
	cmd_params_free(free_arg);
}
Exemplo n.º 2
0
/* SYNTAX: XMPPPASSWD -yes <old_password> <new_password> */
static void
cmd_xmpppasswd(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{
	GHashTable *optlist;
	char *old_password, *new_password, *recoded;
	LmMessage *lmsg;
	LmMessageNode *node;
	void *free_arg;

	CMD_XMPP_SERVER(server);
	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS,
	    "xmpppasswd", &optlist, &old_password, &new_password))
		return;
	if (g_hash_table_lookup(optlist, "yes") == NULL)
		cmd_param_error(CMDERR_NOT_GOOD_IDEA);
	if (strcmp(old_password, server->connrec->password) != 0)
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
	lmsg = lm_message_new_with_sub_type(XMPP_SERVER(server)->domain,
	     LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_SET);
	node = lm_message_node_add_child(lmsg->node, "query", NULL);
	lm_message_node_set_attribute(node, XMLNS, XMLNS_REGISTER);
	recoded = xmpp_recode_out(XMPP_SERVER(server)->user);
	lm_message_node_add_child(node, "username", recoded);
	g_free(recoded);
	recoded = xmpp_recode_out(new_password);
	lm_message_node_add_child(node, "password", recoded);
	g_free(recoded);
	signal_emit("xmpp send iq", 2, server, lmsg);
	lm_message_unref(lmsg);
	cmd_params_free(free_arg);
}
Exemplo n.º 3
0
/* SYNTAX: PART [<channels>] [<message>] */
static void cmd_part(const char *data, IRC_SERVER_REC *server,
		     WI_ITEM_REC *item)
{
	char *channame, *msg;
	char *recoded = NULL;
	void *free_arg;

        CMD_IRC_SERVER(server);

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST |
			    PARAM_FLAG_OPTCHAN, item, &channame, &msg))
		return;
	if (*channame == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	if (*msg == '\0') msg = (char *) settings_get_str("part_message");

        if (server->cmdcount > MAX_COMMANDS_ON_PART_UNTIL_PURGE)
		irc_server_purge_output(server, channame);

	if (*msg != '\0')
		recoded = recode_out(SERVER(server), msg, channame);
	irc_send_cmdv(server, ! recoded ? "PART %s" : "PART %s :%s",
		      channame, recoded);

	g_free(recoded);
	cmd_params_free(free_arg);
}
Exemplo n.º 4
0
static void cmd_action(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{
	CHAT_DCC_REC *dcc;
	char *target, *text;
	void *free_arg;

	g_return_if_fail(data != NULL);

	if (*data != '=') {
		/* handle only DCC actions */
		return;
	}

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
			    &target, &text))
		return;
	if (*target == '\0' || *text == '\0')
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	dcc = dcc_chat_find_id(target+1);
	if (dcc == NULL || dcc->sendbuf == NULL) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
			    IRCTXT_DCC_CHAT_NOT_FOUND, target+1);
	} else {
		if (query_find(NULL, target) == NULL)
			completion_last_message_add(target);

		signal_emit("message dcc own_action", 2, dcc, text);
	}
	cmd_params_free(free_arg);
}
Exemplo n.º 5
0
/* SYNTAX: ECHO [-current] [-window <name>] [-level <level>] <text> */
static void cmd_echo(const char *data, void *server, WI_ITEM_REC *item)
{
        WINDOW_REC *window;
	GHashTable *optlist;
	char *msg, *levelstr, *winname;
	void *free_arg;
	int level;

	g_return_if_fail(data != NULL);

	if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
			    PARAM_FLAG_GETREST, "echo", &optlist, &msg))
		return;

        levelstr = g_hash_table_lookup(optlist, "level");
	level = levelstr == NULL ? 0 :
		level2bits(g_hash_table_lookup(optlist, "level"), NULL);
	if (level == 0) level = MSGLEVEL_CRAP;

	winname = g_hash_table_lookup(optlist, "window");
	window = winname == NULL ? NULL :
		is_numeric(winname, '\0') ?
		window_find_refnum(atoi(winname)) :
		window_find_item(NULL, winname);
	if (window == NULL) window = active_win;

	printtext_window(window, level, "%s", msg);
	cmd_params_free(free_arg);
}
Exemplo n.º 6
0
/* SYNTAX: CYCLE [<channel>] [<message>] */
static void cmd_cycle(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{
	CHANNEL_REC *chanrec;
	char *channame, *msg, *joindata;
	void *free_arg;

	g_return_if_fail(data != NULL);
	if (!IS_SERVER(server) || !server->connected)
		cmd_return_error(CMDERR_NOT_CONNECTED);

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTCHAN,
			    item, &channame, &msg))
		return;
	if (*channame == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	chanrec = channel_find(server, channame);
	if (chanrec == NULL) cmd_param_error(CMDERR_CHAN_NOT_FOUND);

	joindata = chanrec->get_join_data(chanrec);
	window_bind_add(window_item_window(chanrec),
			chanrec->server->tag, chanrec->name);

	/* FIXME: kludgy kludgy... */
	signal_emit("command part", 3, data, server, item);

	if (g_slist_find(channels, chanrec) != NULL) {
		chanrec->left = TRUE;
		channel_destroy(chanrec);
	}

	server->channels_join(server, joindata, FALSE);
	g_free(joindata);

	cmd_params_free(free_arg);
}
Exemplo n.º 7
0
static void cmd_server(const char *data, SERVER_REC *server, void *item)
{
	GHashTable *optlist;
	char *addr;
	void *free_arg;

	if (*data == '\0') {
		print_servers();
		print_lookup_servers();
		print_reconnects();

		signal_stop();
		return;
	}

	if (g_strncasecmp(data, "add ", 4) == 0 ||
	    g_strncasecmp(data, "remove ", 7) == 0 ||
	    g_strcasecmp(data, "list") == 0 ||
	    g_strncasecmp(data, "list ", 5) == 0) {
		command_runsub("server", data, server, item);
		signal_stop();
		return;
	}

	if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
			    "connect", &optlist, &addr))
		return;

	if (*addr == '\0' || strcmp(addr, "+") == 0)
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
	if (*addr == '+') window_create(NULL, FALSE);

	cmd_params_free(free_arg);
}
Exemplo n.º 8
0
/* Handle incoming DCC CTCP replies */
static void dcc_ctcp_reply(char *data, IRC_SERVER_REC *server, char *sender, char *sendaddr)
{
    char *cmd, *subcmd, *args;
    void *free_arg;
    int type;
    DCC_REC *dcc;

    g_return_if_fail(data != NULL);
    g_return_if_fail(sender != NULL);

    if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST, &cmd, &subcmd, &args))
	    return;

    if (g_strcasecmp(cmd, "REJECT") == 0)
    {
        type = dcc_str2type(subcmd);
        dcc = dcc_find_item(type, sender, type == DCC_TYPE_CHAT ? NULL : args);
        if (dcc != NULL)
        {
            signal_emit("dcc closed", 1, dcc);
            dcc_destroy(dcc);
        }
    }
    else
    {
        /* unknown dcc ctcp reply */
        signal_emit("dcc unknown reply", 3, data, sender, sendaddr);
    }

    cmd_params_free(free_arg);
}
Exemplo n.º 9
0
/* SYNTAX: LOAD <module> [<submodule>] */
static void cmd_load(const char *data)
{
        char *rootmodule, *submodule;
	char **module_prefixes;
	void *free_arg;

	g_return_if_fail(data != NULL);

	if (!cmd_get_params(data, &free_arg, 2 , &rootmodule, &submodule))
		return;

	if (*rootmodule == '\0')
		cmd_load_list();
	else {
		module_prefixes = module_prefixes_get();
		if (*submodule == '\0')
			module_load(rootmodule, module_prefixes);
		else {
			module_load_sub(rootmodule, submodule,
					module_prefixes);
		}
                module_prefixes_free(module_prefixes);
	}

	cmd_params_free(free_arg);
}
Exemplo n.º 10
0
/* SYNTAX: ACTION [-<server tag>] <target> <message> */
static void cmd_action(const char *data, IRC_SERVER_REC *server)
{
	GHashTable *optlist;
	const char *target, *text;
	char *subtext;
	char **splittexts;
	int n = 0;
	void *free_arg;

        CMD_IRC_SERVER(server);

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS |
			    PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
			    "action", &optlist, &target, &text))
		return;
	if (*target == '\0' || *text == '\0')
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	server = IRC_SERVER(cmd_options_get_server("action", optlist, SERVER(server)));
	if (server == NULL || !server->connected)
		cmd_param_error(CMDERR_NOT_CONNECTED);

	splittexts = irc_server_split_action(server, target, text);
	while ((subtext = splittexts[n++])) {
		irc_server_send_action(server, target, subtext);
		signal_emit("message irc own_action", 3, server, subtext,
			    target);
	}

	g_strfreev(splittexts);
	cmd_params_free(free_arg);
}
Exemplo n.º 11
0
/* SYNTAX: TOGGLE <key> [on|off|toggle] */
static void cmd_toggle(const char *data)
{
	char *key, *value;
	void *free_arg;
	int type;

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | PARAM_FLAG_STRIP_TRAILING_WS, &key, &value))
		return;

	if (*key == '\0')
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	type = settings_get_type(key);
	if (type == SETTING_TYPE_ANY)
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SET_UNKNOWN, key);
	else if (type != SETTING_TYPE_BOOLEAN)
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SET_NOT_BOOLEAN, key);
	else {
		set_boolean(key, *value != '\0' ? value : "TOGGLE");
		set_print(settings_get_record(key));
		signal_emit("setup changed", 0);
	}

	cmd_params_free(free_arg);
}
Exemplo n.º 12
0
static void cmd_oper(const char *data, IRC_SERVER_REC *server)
{
	char *nick, *password, *format;
	void *free_arg;

	g_return_if_fail(data != NULL);
	if (!IS_IRC_SERVER(server) || !server->connected)
		cmd_return_error(CMDERR_NOT_CONNECTED);

	if (!cmd_get_params(data, &free_arg, 2, &nick, &password))
		return;
	if (*password == '\0') {
		/* password not given, ask it.
		   irc/core handles the /OPER when password is given */
		OPER_PASS_REC *rec;

		rec = g_new(OPER_PASS_REC, 1);
		rec->server = server;
		rec->nick = g_strdup(*nick != '\0' ? nick : server->nick);

		format = format_get_text(MODULE_NAME, NULL, server, NULL,
					 IRCTXT_ASK_OPER_PASS);

		keyboard_entry_redirect((SIGNAL_FUNC) cmd_oper_got_pass,
					format,
					ENTRY_REDIRECT_FLAG_HIDDEN, rec);
                g_free(format);

		signal_stop();
	}

	cmd_params_free(free_arg);
}
Exemplo n.º 13
0
/* SYNTAX: LOG OPEN [-noopen] [-autoopen] [-window] [-<server tag>]
                    [-targets <targets>] [-colors]
		    <fname> [<levels>] */
static void cmd_log_open(const char *data)
{
        SERVER_REC *server;
        GHashTable *optlist;
	char *targetarg, *fname, *levels, *servertag;
	void *free_arg;
	char window[MAX_INT_STRLEN];
	LOG_REC *log;
	int level;

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST |
			    PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_OPTIONS,
			    "log open", &optlist, &fname, &levels))
		return;
	if (*fname == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	level = level2bits(levels);
	log = log_create_rec(fname, level != 0 ? level : MSGLEVEL_ALL);

	/* -<server tag> */
	server = cmd_options_get_server("log open", optlist, NULL);
	servertag = server == NULL ? NULL : server->tag;

	if (g_hash_table_lookup(optlist, "window")) {
		/* log by window ref# */
		targetarg = g_hash_table_lookup(optlist, "targets");
		if (targetarg == NULL || !is_numeric(targetarg, '\0')) {
			ltoa(window, active_win->refnum);
			targetarg = window;
		}
		log_item_add(log, LOG_ITEM_WINDOW_REFNUM, targetarg,
			     servertag);
	} else {
		targetarg = g_hash_table_lookup(optlist, "targets");
		if (targetarg != NULL && *targetarg != '\0')
			log_add_targets(log, targetarg, servertag);
		else if (servertag != NULL)
			log_add_targets(log, "*", servertag);
	}

	if (g_hash_table_lookup(optlist, "autoopen"))
		log->autoopen = TRUE;

	if (g_hash_table_lookup(optlist, "colors") == NULL)
		log->colorizer = log_colorizer_strip;

	log_update(log);

	if (log->handle == -1 && g_hash_table_lookup(optlist, "noopen") == NULL) {
		/* start logging */
		if (log_start_logging(log)) {
			printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
				    TXT_LOG_OPENED, fname);
		} else {
			log_close(log);
		}
	}

        cmd_params_free(free_arg);
}
Exemplo n.º 14
0
/* SYNTAX: WHOWAS [<nicks> [<count>]] */
static void cmd_whowas(const char *data, IRC_SERVER_REC *server)
{
	char *nicks, *count;
	void *free_arg;
	int free_nick;

	g_return_if_fail(data != NULL);
	if (!IS_IRC_SERVER(server) || !server->connected)
		cmd_return_error(CMDERR_NOT_CONNECTED);

	if (!cmd_get_params(data, &free_arg, 2, &nicks, &count))
		return;
	if (*nicks == '\0') nicks = server->nick;

	server->whowas_found = FALSE;
	irc_send_cmdv(server, *count == '\0' ? "WHOWAS %s" :
		      "WHOWAS %s %s", nicks, count);

	nicks = get_redirect_nicklist(nicks, &free_nick);
	server_redirect_event(SERVER(server), nicks, 1,
			      "event 369", "event 369", 1,
			      "event 314", "whowas event", 1, NULL);
	if (free_nick) g_free(nicks);
	cmd_params_free(free_arg);
}
Exemplo n.º 15
0
Arquivo: perl-fe.c Projeto: Liaf/irssi
static void cmd_script_exec(const char *data)
{
        PERL_SCRIPT_REC *script;
	GHashTable *optlist;
	char *code;
	void *free_arg;

	if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
			    PARAM_FLAG_GETREST,
			    "script exec", &optlist, &code))
		return;

        if (*code == '\0')
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

        script = perl_script_load_data(code);
	if (script != NULL &&
	    g_hash_table_lookup(optlist, "permanent") == NULL) {
		/* not a permanent script, unload immediately */
                perl_script_unload(script);
	}


	cmd_params_free(free_arg);
}
Exemplo n.º 16
0
/* SYNTAX: UNLOAD <module> [<submodule>] */
static void cmd_unload(const char *data)
{
	MODULE_REC *module;
        MODULE_FILE_REC *file;
        char *rootmodule, *submodule;
	void *free_arg;

	g_return_if_fail(data != NULL);

	if (!cmd_get_params(data, &free_arg, 2 , &rootmodule, &submodule))
		return;
	if (*rootmodule == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	module = module_find(rootmodule);
	if (module != NULL) {
		if (*submodule == '\0')
			module_unload(module);
		else {
			file = module_file_find(module, submodule);
                        if (file != NULL)
				module_file_unload(file);
			else
                                module = NULL;
		}
	}

	if (module == NULL) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
                            TXT_MODULE_NOT_LOADED, rootmodule, submodule);
	}

	cmd_params_free(free_arg);
}
Exemplo n.º 17
0
Arquivo: perl-fe.c Projeto: Liaf/irssi
static void cmd_script_load(const char *data)
{
        PERL_SCRIPT_REC *script;
	char *fname, *path;
	void *free_arg;

	if (!cmd_get_params(data, &free_arg, 1, &path))
		return;

        if (*path == '\0')
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	fname = perl_script_get_path(path);
	if (fname == NULL) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
                            TXT_SCRIPT_NOT_FOUND, data);
	} else {
		script = perl_script_load_file(fname);
		if (script != NULL) {
			printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
				    TXT_SCRIPT_LOADED,
				    script->name, script->path);
		}
		g_free(fname);
	}
	cmd_params_free(free_arg);
}
Exemplo n.º 18
0
/* SYNTAX: TOPIC [-delete] [<channel>] [<topic>] */
static void cmd_topic(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
{
	GHashTable *optlist;
	char *channame, *topic;
	char *recoded = NULL;
	void *free_arg;

        CMD_IRC_SERVER(server);

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTCHAN |
			    PARAM_FLAG_OPTIONS | PARAM_FLAG_GETREST,
			    item, "topic", &optlist, &channame, &topic))
		return;

	if (*topic != '\0' || g_hash_table_lookup(optlist, "delete") != NULL)
		recoded = recode_out(SERVER(server), topic, channame);

	if (recoded == NULL)
		irc_send_cmdv(server, "TOPIC %s", channame);
	else
		irc_send_cmdv(server, "TOPIC %s :%s", channame, recoded);

	g_free(recoded);

	cmd_params_free(free_arg);
}
Exemplo n.º 19
0
/* SYNTAX: SERVER REMOVE <address> [<port>] [<network>] */
static void cmd_server_remove(const char *data)
{
    SERVER_SETUP_REC *rec;
    char *addr, *port, *chatnet;
    void *free_arg;

    if (!cmd_get_params(data, &free_arg, 3, &addr, &port, &chatnet))
        return;
    if (*addr == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

    if (*port == '\0') {
        if (*chatnet == '\0')
            rec = server_setup_find(addr, -1, NULL);
        else
            rec = server_setup_find(addr, -1, chatnet);
    }
    else
    {
        if (*chatnet == '\0')
            rec = server_setup_find(addr, atoi(port), NULL);
        else
            rec = server_setup_find(addr, atoi(port), chatnet);
    }

    if (rec == NULL)
        printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_SETUPSERVER_NOT_FOUND, addr, port);
    else {
        server_setup_remove(rec);
        printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_SETUPSERVER_REMOVED, addr, port);
    }

    cmd_params_free(free_arg);
}
Exemplo n.º 20
0
static void cmd_names(const char *data, IRC_SERVER_REC *server,
		      WI_ITEM_REC *item)
{
        GHashTable *optlist;
	char *channel;
	void *free_arg;

        CMD_IRC_SERVER(server);

	if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
			    PARAM_FLAG_GETREST | PARAM_FLAG_STRIP_TRAILING_WS,
			    "names", &optlist, &channel))
		return;

	if (g_strcmp0(channel, "*") == 0 || *channel == '\0') {
		if (!IS_IRC_CHANNEL(item))
                        cmd_param_error(CMDERR_NOT_JOINED);

		channel = IRC_CHANNEL(item)->name;
	}

	if (g_strcmp0(channel, "**") == 0) {
		/* ** displays all nicks.. */
                irc_send_cmd(server, "NAMES");
	} else {
		irc_send_cmdv(server, "NAMES %s", channel);
	}

	cmd_params_free(free_arg);
}
Exemplo n.º 21
0
static void cmd_msg(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{
	CHAT_DCC_REC *dcc;
        GHashTable *optlist;
	char *text, *target;
	void *free_arg;

	g_return_if_fail(data != NULL);

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_UNKNOWN_OPTIONS |
			    PARAM_FLAG_OPTIONS | PARAM_FLAG_GETREST, "msg",
			    &optlist, &target, &text))
		return;

	/* handle only DCC messages */
	if (strcmp(target, "*") == 0)
		dcc = item_get_dcc(item);
	else if (*target == '=')
		dcc = dcc_chat_find_id(target+1);
	else
		dcc = NULL;

	if (dcc == NULL && *target == '=') {
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
			    IRCTXT_DCC_CHAT_NOT_FOUND, target+1);
	} else if (dcc != NULL) {
		if (query_find(NULL, target) == NULL)
			completion_last_message_add(target);

		signal_emit("message dcc own", 2, dcc, text);
	}

	cmd_params_free(free_arg);
}
Exemplo n.º 22
0
/* SYNTAX: WHOWAS [<nicks> [<count> [server]]] */
static void cmd_whowas(const char *data, IRC_SERVER_REC *server)
{
	char *nicks, *rest, *nicks_redir;
	void *free_arg;
	int free_nick;

        CMD_IRC_SERVER(server);

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | PARAM_FLAG_STRIP_TRAILING_WS,
			    &nicks, &rest))
		return;
	if (*nicks == '\0') nicks = server->nick;

	nicks_redir = get_redirect_nicklist(nicks, &free_nick);
	server_redirect_event(server, "whowas", 1, nicks_redir, -1, NULL,
			      "event 301", "whowas away", /* 301 can come as a reply to /MSG, /WHOIS or /WHOWAS */
			      "event 314", "whowas event", NULL);
	if (free_nick) g_free(nicks_redir);

	server->whowas_found = FALSE;

	if (rest[0] == '\0')
		irc_send_cmdv(server, "WHOWAS %s", nicks);
	else
		irc_send_cmdv(server, "WHOWAS %s %s", nicks, rest);

	cmd_params_free(free_arg);
}
Exemplo n.º 23
0
/* SYNTAX: CLEAR [-all] [<refnum>] */
static void cmd_clear(const char *data)
{
        WINDOW_REC *window;
	GHashTable *optlist;
        char *refnum;
	void *free_arg;
        GSList *tmp;

	g_return_if_fail(data != NULL);

	if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
			    "clear", &optlist, &refnum)) return;

	if (g_hash_table_lookup(optlist, "all") != NULL) {
                /* clear all windows */
		for (tmp = windows; tmp != NULL; tmp = tmp->next) {
			WINDOW_REC *window = tmp->data;

			textbuffer_view_clear(WINDOW_GUI(window)->view);
		}
	} else if (*refnum != '\0') {
                /* clear specified window */
		window = window_find_refnum(atoi(refnum));
                if (window != NULL)
			textbuffer_view_clear(WINDOW_GUI(window)->view);
	} else {
                /* clear active window */
		textbuffer_view_clear(WINDOW_GUI(active_win)->view);
	}

	cmd_params_free(free_arg);
}
Exemplo n.º 24
0
/* SYNTAX: WAIT [-<server tag>] <milliseconds> */
static void cmd_wait(const char *data, IRC_SERVER_REC *server)
{
	GHashTable *optlist;
	char *msecs;
	void *free_arg;
	int n;

        CMD_IRC_SERVER(server);

	if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS |
			    PARAM_FLAG_UNKNOWN_OPTIONS | PARAM_FLAG_GETREST,
			    NULL, &optlist, &msecs))
		return;

	if (*msecs == '\0')
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	/* -<server tag> */
	server = IRC_SERVER(cmd_options_get_server(NULL, optlist,
						   SERVER(server)));

	n = atoi(msecs);
	if (server != NULL && n > 0) {
		g_get_current_time(&server->wait_cmd);
		server->wait_cmd.tv_sec += n/1000;
		server->wait_cmd.tv_usec += n%1000;
		if (server->wait_cmd.tv_usec >= 1000) {
			server->wait_cmd.tv_sec++;
			server->wait_cmd.tv_usec -= 1000;
		}
	}
	cmd_params_free(free_arg);
}
Exemplo n.º 25
0
/* SYNTAX: XMPPREGISTER [-ssl] [-host <server>] [-port <port>]
 *                      <jid> <password> */
static void
cmd_xmppregister(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{
	GHashTable *optlist;
	char *str, *jid, *password, *address;
	void *free_arg;
	struct register_data *rd;

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS,
	    "xmppconnect", &optlist, &jid, &password))
		return;
	if (*jid == '\0' || *password == '\0' || !xmpp_have_domain(jid))
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
	rd = g_new0(struct register_data, 1);
	rd->username = xmpp_extract_user(jid);
	rd->domain = xmpp_extract_domain(jid);
	rd->password = g_strdup(password);
	address = g_hash_table_lookup(optlist, "host");
	if (address == NULL || *address == '\0')
		address = rd->domain;
	rd->address = g_strdup(address);
	rd->port = (str = g_hash_table_lookup(optlist, "port")) ? atoi(str) : 0;
	rd->use_ssl = g_hash_table_lookup(optlist, "ssl") != NULL;
	signal_emit("xmpp registration started", 2, rd->username, rd->domain);
	start_registration(rd);
	cmd_params_free(free_arg);
}
Exemplo n.º 26
0
/* SYNTAX: NOTICE <targets> <message> */
static void cmd_notice(const char *data, IRC_SERVER_REC *server,
		       WI_ITEM_REC *item)
{
	const char *target, *msg;
	char *recoded;
	void *free_arg;

        CMD_IRC_SERVER(server);

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST,
			    &target, &msg))
		return;
	if (g_strcmp0(target, "*") == 0)
		target = item == NULL ? NULL : window_item_get_target(item);
	if (target == NULL || *target == '\0' || *msg == '\0')
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	recoded = recode_out(SERVER(server), msg, target);
	g_string_printf(tmpstr, "NOTICE %s :%s", target, recoded);
	g_free(recoded);

	irc_send_cmd_split(server, tmpstr->str, 2, server->max_msgs_in_cmd);

	cmd_params_free(free_arg);
}
Exemplo n.º 27
0
/* SYNTAX: NCTCP <targets> <ctcp command> [<ctcp data>] */
static void cmd_nctcp(const char *data, IRC_SERVER_REC *server,
		      WI_ITEM_REC *item)
{
	const char *target;
	char *ctcpcmd, *ctcpdata, *recoded;
	void *free_arg;

        CMD_IRC_SERVER(server);

	if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_GETREST,
			    &target, &ctcpcmd, &ctcpdata))
		return;
	if (strcmp(target, "*") == 0)
		target = item == NULL ? NULL : window_item_get_target(item);
	if (*target == '\0' || *ctcpcmd == '\0')
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	g_strup(ctcpcmd);
	recoded = recode_out(SERVER(server), ctcpdata, target);
	g_string_sprintf(tmpstr, "NOTICE %s :\001%s %s\001", target, ctcpcmd, recoded);
	g_free(recoded);

	irc_send_cmd_split(server, tmpstr->str, 2, server->max_msgs_in_cmd);

	cmd_params_free(free_arg);
}
Exemplo n.º 28
0
/* SYNTAX: SAVE [<file>] */
static void cmd_save(const char *data)
{
        GHashTable *optlist;
	char *format, *fname;
        void *free_arg;

	if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
			    "save", &optlist, &fname))
		return;

	if (*fname == '\0')
		fname = mainconfig->fname;

	if (!irssi_config_is_changed(fname))
		settings_save_fe(fname);
	else {
                /* config file modified outside irssi */
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
			    TXT_CONFIG_MODIFIED, fname);

		format = format_get_text(MODULE_NAME, NULL, NULL, NULL,
					 TXT_OVERWRITE_CONFIG);
		keyboard_entry_redirect((SIGNAL_FUNC) settings_save_confirm,
					format, 0, g_strdup(fname));
		g_free(format);
	}

	cmd_params_free(free_arg);
}
Exemplo n.º 29
0
/* SYNTAX: WHO [<nicks> | <channels> | **] */
static void cmd_who(const char *data, IRC_SERVER_REC *server,
		    WI_ITEM_REC *item)
{
	char *channel, *rest;
	void *free_arg;

        CMD_IRC_SERVER(server);

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &channel, &rest))
		return;

	if (strcmp(channel, "*") == 0 || *channel == '\0') {
		if (!IS_IRC_CHANNEL(item))
                        cmd_param_error(CMDERR_NOT_JOINED);

		channel = IRC_CHANNEL(item)->name;
	}
	if (strcmp(channel, "**") == 0) {
		/* ** displays all nicks.. */
		*channel = '\0';
	}

	irc_send_cmdv(server, *rest == '\0' ? "WHO %s" : "WHO %s %s",
		      channel, rest);
	cmd_params_free(free_arg);
}
Exemplo n.º 30
0
/* SYNTAX: WHO <nicks>|<channels>|** */
static void cmd_who(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item)
{
	char *channel, *rest;
	void *free_arg;

	g_return_if_fail(data != NULL);
	if (!IS_IRC_SERVER(server) || !server->connected)
		cmd_return_error(CMDERR_NOT_CONNECTED);

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &channel, &rest))
		return;

	if (strcmp(channel, "*") == 0 || *channel == '\0') {
		if (!IS_IRC_CHANNEL(item))
                        cmd_param_error(CMDERR_NOT_JOINED);

		channel = item->name;
	}
	if (strcmp(channel, "**") == 0) {
		/* ** displays all nicks.. */
		*channel = '\0';
	}

	irc_send_cmdv(server, *rest == '\0' ? "WHO %s" : "WHO %s %s",
		      channel, rest);
	cmd_params_free(free_arg);

	/* add default redirection */
	server_redirect_default((SERVER_REC *) server, "bogus command who");
}