Example #1
0
static void event_topic_info(IRC_SERVER_REC *server, const char *data)
{
    const char *channel;
    char *params, *timestr, *bynick, *byhost, *topictime;

    g_return_if_fail(data != NULL);

    params = event_get_params(data, 4, NULL, &channel,
                              &bynick, &topictime);

    timestr = my_asctime((time_t) atol(topictime));

    byhost = strchr(bynick, '!');
    if (byhost != NULL)
        *byhost++ = '\0';

    channel = get_visible_target(server, channel);
    printformat(server, channel, MSGLEVEL_CRAP, IRCTXT_TOPIC_INFO,
                bynick, timestr, byhost == NULL ? "" : byhost);
    g_free(timestr);
    g_free(params);
}
Example #2
0
static void dcc_connected(CHAT_DCC_REC *dcc)
{
	char *sender;

        if (!IS_DCC_CHAT(dcc)) return;

	sender = g_strconcat("=", dcc->id, NULL);
	printformat(dcc->server, NULL, MSGLEVEL_DCC,
		    IRCTXT_DCC_CHAT_CONNECTED,
		    dcc->id, dcc->addrstr, dcc->port);

	if (query_find(NULL, sender) == NULL) {
		int level = settings_get_level("autocreate_query_level");
		int autocreate_dccquery = (level & MSGLEVEL_DCCMSGS) != 0;

		if (!autocreate_dccquery)
			completion_last_message_add(sender);
		else
			irc_query_create(dcc->servertag, sender, TRUE);
	}
	g_free(sender);
}
Example #3
0
static SERVER_SETUP_REC *create_server_setup(GHashTable *optlist)
{
	CHAT_PROTOCOL_REC *rec;
        SERVER_SETUP_REC *server;
        char *chatnet;

	rec = chat_protocol_find_net(optlist);
	if (rec == NULL)
                rec = chat_protocol_get_default();
	else {
		chatnet = g_hash_table_lookup(optlist, rec->chatnet);
		if (chatnet_find(chatnet) == NULL) {
			printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
				    TXT_UNKNOWN_CHATNET, chatnet);
			return NULL;
		}
	}

        server = rec->create_server_setup();
        server->chat_type = rec->id;
	return server;
}
Example #4
0
static void set_print_pattern(const char *pattern)
{
	GSList *sets, *tmp;
	const char *last_section;

	last_section = "";
	sets = settings_get_sorted();
	for (tmp = sets; tmp != NULL; tmp = tmp->next) {
		SETTINGS_REC *rec = tmp->data;

		if (stristr(rec->key, pattern) == NULL)
			continue;
		if (g_strcmp0(last_section, rec->section) != 0) {
			/* print section */
			printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
				    TXT_SET_TITLE, rec->section);
			last_section = rec->section;
		}
		set_print(rec);
	}
	g_slist_free(sets);
}
Example #5
0
static void set_print(SETTINGS_REC *rec)
{
	const char *value;
	char value_int[MAX_INT_STRLEN];

	switch (rec->type) {
	case SETTING_TYPE_BOOLEAN:
		value = settings_get_bool(rec->key) ? "ON" : "OFF";
		break;
	case SETTING_TYPE_INT:
		ltoa(value_int, settings_get_int(rec->key));
		value = value_int;
		break;
	case SETTING_TYPE_STRING:
		value = settings_get_str(rec->key);
		break;
	default:
		value = "";
	}
	printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_SET_ITEM,
		    rec->key, value);
}
Example #6
0
static void theme_save(THEME_REC *theme, int save_all)
{
	CONFIG_REC *config;
	THEME_SAVE_REC data;
	char *path;
	int ok;

	config = config_open(theme->path, -1);
        if (config != NULL)
                config_parse(config);
        else {
                if (g_strcasecmp(theme->name, "default") == 0) {
                        config = config_open(NULL, -1);
                        config_parse_data(config, default_theme, "internal");
                        config_change_file_name(config, theme->path, 0660);
                } else {
                        config = config_open(theme->path, 0660);
                        if (config == NULL)
                                return;
                        config_parse(config);
                }
        }

	data.config = config;
        data.save_all = save_all;
	g_hash_table_foreach(theme->modules, (GHFunc) module_save, &data);

        /* always save the theme to ~/.irssi/ */
	path = g_strdup_printf("%s/%s", get_irssi_dir(),
			       g_basename(theme->path));
	ok = config_write(config, path, 0660) == 0;

	printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
		    ok ? TXT_THEME_SAVED : TXT_THEME_SAVE_FAILED,
		    path, config_last_error(config));

	g_free(path);
	config_close(config);
}
Example #7
0
/* SYNTAX: UNIGNORE <id>|<mask> */
static void cmd_unignore(const char *data)
{
	IGNORE_REC *rec;
	GSList *tmp;
        char *mask;
	void *free_arg;

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

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

	if (is_numeric(mask, ' ')) {
		/* with index number */
		tmp = g_slist_nth(ignores, atoi(mask)-1);
		rec = tmp == NULL ? NULL : tmp->data;
	} else {
		/* with mask */
		const char *chans[2] = { "*", NULL };

		if (active_win->active_server != NULL &&
		    server_ischannel(active_win->active_server, mask)) {
			chans[0] = mask;
			mask = NULL;
		}
		rec = ignore_find("*", mask, (char **) chans);
	}

	if (rec != NULL) {
		rec->level = 0;
		ignore_update_rec(rec);
	} else {
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
			    TXT_IGNORE_NOT_FOUND, mask);
	}
	cmd_params_free(free_arg);
}
Example #8
0
static void event_whois_channels(IRC_SERVER_REC *server, const char *data)
{
	char *params, *nick, *chans, *recoded;

	g_return_if_fail(data != NULL);

	params = event_get_params(data, 3, NULL, &nick, &chans);

	/* sure - we COULD print the channel names as-is, but since the
	   colors, bolds, etc. are mostly just to fool people, I think we
	   should show the channel names as they REALLY are so they could
	   even be joined without any extra tricks. */
	chans = show_lowascii(chans);
	if (settings_get_bool("whois_hide_safe_channel_id"))
		hide_safe_channel_id(server, chans);
	recoded = recode_in(SERVER(server), chans, nick);
	printformat(server, nick, MSGLEVEL_CRAP,
		    IRCTXT_WHOIS_CHANNELS, nick, recoded);
	g_free(chans);

	g_free(params);
	g_free(recoded);
}
Example #9
0
static void ctcp_default_reply(IRC_SERVER_REC *server, const char *data,
			       const char *nick, const char *addr,
			       const char *target)
{
	const char *ctcpdata;
	char *ctcp, *ptr;

	g_return_if_fail(data != NULL);

	ctcp = g_strdup(data);
	ptr = strchr(ctcp, ' ');
	if (ptr == NULL)
		ctcpdata = "";
	else {
		*ptr = '\0';
		ctcpdata = ptr+1;
	}

	printformat(server, ischannel(*target) ? target : nick, MSGLEVEL_CTCPS,
		    ischannel(*target) ? IRCTXT_CTCP_REPLY_CHANNEL :
		    IRCTXT_CTCP_REPLY, ctcp, nick, ctcpdata, target);
	g_free(ctcp);
}
Example #10
0
static void event_who(IRC_SERVER_REC *server, const char *data)
{
    char *params, *nick, *channel, *user, *host, *stat, *realname, *hops;
    char *serv, *recoded;

    g_return_if_fail(data != NULL);

    params = event_get_params(data, 8, NULL, &channel, &user,
                              &host, &serv, &nick, &stat, &realname);

    /* split hops/realname */
    hops = realname;
    while (*realname != '\0' && *realname != ' ') realname++;
    if (*realname == ' ')
        *realname++ = '\0';

    recoded = recode_in(SERVER(server), realname, nick);
    printformat(server, NULL, MSGLEVEL_CRAP, IRCTXT_WHO,
                channel, nick, stat, hops, user, host, recoded, serv);

    g_free(params);
    g_free(recoded);
}
Example #11
0
static void event_away(IRC_SERVER_REC *server, const char *data)
{
    char *params, *nick, *awaymsg, *recoded;

    g_return_if_fail(data != NULL);

    params = event_get_params(data, 3, NULL, &nick, &awaymsg);
    recoded = recode_in(SERVER(server), awaymsg, nick);
    if (!settings_get_bool("show_away_once") ||
            last_away_nick == NULL || g_strcasecmp(last_away_nick, nick) != 0 ||
            last_away_msg == NULL || g_strcasecmp(last_away_msg, awaymsg) != 0) {
        /* don't show the same away message
           from the same nick all the time */
        g_free_not_null(last_away_nick);
        g_free_not_null(last_away_msg);
        last_away_nick = g_strdup(nick);
        last_away_msg = g_strdup(awaymsg);

        printformat(server, nick, MSGLEVEL_CRAP,
                    IRCTXT_NICK_AWAY, nick, recoded);
    }
    g_free(params);
    g_free(recoded);
}
Example #12
0
static void sig_message_own_action(IRC_SERVER_REC *server, const char *msg,
                                   const char *target)
{
	void *item;
	const char *oldtarget;
        char *freemsg = NULL;

	oldtarget = target;
	target = fe_channel_skip_prefix(IRC_SERVER(server), target);
	if (server_ischannel(SERVER(server), target))
		item = irc_channel_find(server, target);
	else
		item = irc_query_find(server, target);

	if (settings_get_bool("emphasis"))
		msg = freemsg = expand_emphasis(item, msg);

	printformat(server, target,
		    MSGLEVEL_ACTIONS | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT |
		    (server_ischannel(SERVER(server), target) ? MSGLEVEL_PUBLIC : MSGLEVEL_MSGS),
		    item != NULL && oldtarget == target ? IRCTXT_OWN_ACTION : IRCTXT_OWN_ACTION_TARGET,
		    server->nick, msg, oldtarget);
        g_free_not_null(freemsg);
}
Example #13
0
void glog_func(const char *log_domain, GLogLevelFlags log_level,
	       const char *message)
{
	const char *reason;

	switch (log_level) {
	case G_LOG_LEVEL_WARNING:
                reason = "warning";
                break;
	case G_LOG_LEVEL_CRITICAL:
                reason = "critical";
		break;
	default:
		reason = "error";
                break;
	}

	if (windows == NULL)
		fprintf(stderr, "GLib %s: %s\n", reason, message);
	else {
		printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
			    TXT_GLIB_ERROR, reason, message);
	}
}
Example #14
0
/* SYNTAX: CHANNEL ADD [-auto | -noauto] [-bots <masks>] [-botcmd <command>]
                       <channel> <chatnet> [<password>] */
static void cmd_channel_add(const char *data)
{
	GHashTable *optlist;
	CHANNEL_SETUP_REC *rec;
	char *botarg, *botcmdarg, *chatnet, *channel, *password;
	void *free_arg;

	if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
			    "channel add", &optlist, &channel, &chatnet, &password))
		return;

	botarg = g_hash_table_lookup(optlist, "bots");
	botcmdarg = g_hash_table_lookup(optlist, "botcmd");

	if (*chatnet == '\0' || *channel == '\0')
		cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
	rec = channels_setup_find(channel, chatnet);
	if (rec == NULL) {
		rec = g_new0(CHANNEL_SETUP_REC, 1);
		rec->name = g_strdup(channel);
		rec->chatnet = g_strdup(chatnet);
	} else {
		if (g_hash_table_lookup(optlist, "bots")) g_free_and_null(rec->botmasks);
		if (g_hash_table_lookup(optlist, "botcmd")) g_free_and_null(rec->autosendcmd);
		if (*password != '\0') g_free_and_null(rec->password);
	}
	if (g_hash_table_lookup(optlist, "auto")) rec->autojoin = TRUE;
	if (g_hash_table_lookup(optlist, "noauto")) rec->autojoin = FALSE;
	if (botarg != NULL && *botarg != '\0') rec->botmasks = g_strdup(botarg);
	if (botcmdarg != NULL && *botcmdarg != '\0') rec->autosendcmd = g_strdup(botcmdarg);
	if (*password != '\0' && strcmp(password, "-") != 0) rec->password = g_strdup(password);
	channels_setup_create(rec);
	printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_CHANSETUP_ADDED, channel, chatnet);

	cmd_params_free(free_arg);
}
Example #15
0
static void sig_module_loaded(MODULE_REC *module, MODULE_FILE_REC *file)
{
    printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
                TXT_MODULE_LOADED, module->name, file->name);
}
Example #16
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 |
			    PARAM_FLAG_STRIP_TRAILING_WS, "log open", &optlist, 
			    &fname, &levels))
		return;
	if (*fname == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	level = level2bits(levels, NULL);
	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);
}
Example #17
0
static void sig_log_create_failed(LOG_REC *log)
{
	printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
		    TXT_LOG_CREATE_FAILED,
		    log->real_fname, g_strerror(errno));
}
Example #18
0
static void sig_log_locked(LOG_REC *log)
{
	printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
		    TXT_LOG_LOCKED, log->real_fname);
}
Example #19
0
static void cmd_ignore(const char *data)
{
	/* /IGNORE [-regexp | -word] [-pattern <pattern>] [-except]
	           [-replies] [-channels <channel>] <mask> <levels>
	   OR

           /IGNORE [-regexp | -word] [-pattern <pattern>] [-except] [-replies]
	           <channels> <levels> */
        GHashTable *optlist;
	IGNORE_REC *rec;
	char *patternarg, *chanarg, *mask, *levels, *key;
	char **channels;
	void *free_arg;
	int new_ignore;

	if (*data == '\0') {
		cmd_ignore_show();
		return;
	}

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS | PARAM_FLAG_GETREST,
			    "ignore", &optlist, &mask, &levels))
		return;

	patternarg = g_hash_table_lookup(optlist, "pattern");
        chanarg = g_hash_table_lookup(optlist, "channels");

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

	if (ischannel(*mask)) {
		chanarg = mask;
		mask = "";
	}
	channels = (chanarg == NULL || *chanarg == '\0') ? NULL :
		g_strsplit(replace_chars(chanarg, ',', ' '), " ", -1);

	rec = ignore_find(NULL, mask, channels);
	new_ignore = rec == NULL;

	if (rec == NULL) {
		rec = g_new0(IGNORE_REC, 1);

		rec->mask = *mask == '\0' ? NULL : g_strdup(mask);
		rec->channels = channels;
	} else {
                g_free_and_null(rec->pattern);
		g_strfreev(channels);
	}

	if (g_hash_table_lookup(optlist, "except") != NULL) {
                rec->except_level = combine_level(rec->except_level, levels);
	} else {
		ignore_split_levels(levels, &rec->level, &rec->except_level);
	}

	rec->pattern = (patternarg == NULL || *patternarg == '\0') ?
		NULL : g_strdup(patternarg);
	rec->regexp = g_hash_table_lookup(optlist, "regexp") != NULL;
	rec->fullword = g_hash_table_lookup(optlist, "word") != NULL;
	rec->replies = g_hash_table_lookup(optlist, "replies") != NULL;

	if (rec->level == 0 && rec->except_level == 0) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_UNIGNORED,
			    rec->mask == NULL ? "" : rec->mask);
	} else {
		key = ignore_get_key(rec);
		levels = ignore_get_levels(rec->level, rec->except_level);
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_IGNORED, key, levels);
		g_free(key);
		g_free(levels);
	}

	if (new_ignore)
		ignore_add_rec(rec);
	else
		ignore_update_rec(rec);

	cmd_params_free(free_arg);
}
Example #20
0
static void cmd_ignore(const char *data)
{
	/* /IGNORE [-regexp | -word] [-pattern <pattern>] [-except]
	           [-channels <channel>] <mask> <levels>
	   OR

           /IGNORE [-regexp | -word] [-pattern <pattern>] [-except]
	           <channels> <levels> */
	char *params, *args, *patternarg, *chanarg, *mask, *levels, *key;
	char **channels;
	IGNORE_REC *rec;
	int new_ignore;

	if (*data == '\0') {
		cmd_ignore_show();
		return;
	}

	args = "pattern channels";
	params = cmd_get_params(data, 5 | PARAM_FLAG_MULTIARGS | PARAM_FLAG_GETREST,
				&args, &patternarg, &chanarg, &mask, &levels);
	if (*levels == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);

	if (ischannel(*mask)) {
		chanarg = mask;
		mask = "";
	}
	channels = *chanarg == '\0' ? NULL :
		g_strsplit(replace_chars(chanarg, ',', ' '), " ", -1);

	rec = ignore_find(NULL, mask, channels);
	new_ignore = rec == NULL;

	if (rec == NULL) {
		rec = g_new0(IGNORE_REC, 1);

		rec->mask = *mask == '\0' ? NULL : g_strdup(mask);
		rec->channels = channels;
	} else {
                g_free_and_null(rec->pattern);
		g_strfreev(channels);
	}

	if (stristr(args, "-except") != NULL) {
                rec->except_level = combine_level(rec->except_level, levels);
	} else {
		ignore_split_levels(levels, &rec->level, &rec->except_level);
	}

	rec->pattern = *patternarg == '\0' ? NULL : g_strdup(patternarg);
	rec->regexp = stristr(args, "-regexp") != NULL;
	rec->fullword = stristr(args, "-word") != NULL;
	rec->replies = stristr(args, "-replies") != NULL;

	if (rec->level == 0 && rec->except_level == 0) {
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_UNIGNORED,
			    rec->mask == NULL ? "" : rec->mask);
	} else {
		key = ignore_get_key(rec);
		levels = ignore_get_levels(rec->level, rec->except_level);
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, IRCTXT_IGNORED, key, levels);
		g_free(key);
		g_free(levels);
	}

	if (new_ignore)
		ignore_add_rec(rec);
	else
		ignore_update_rec(rec);

	g_free(params);
}
Example #21
0
static void sig_sasl_failure(IRC_SERVER_REC *server, const char *reason)
{
	printformat(server, NULL, MSGLEVEL_CRAP, IRCTXT_SASL_ERROR, reason);
}
Example #22
0
static void event_unaway(IRC_SERVER_REC *server, const char *data)
{
	printformat(server, NULL, MSGLEVEL_CRAP, IRCTXT_UNAWAY);
}
Example #23
0
static void sig_message_quit(SERVER_REC *server, const char *nick,
			     const char *address, const char *reason)
{
	WINDOW_REC *window;
	GString *chans;
	GSList *tmp, *windows;
	char *print_channel;
	int once, count, level = MSGLEVEL_QUITS;

	if (ignore_check_plus(server, nick, address, NULL, reason, &level, TRUE))
		return;

	print_channel = NULL;
	once = settings_get_bool("show_quit_once");

	count = 0; windows = NULL;
	chans = g_string_new(NULL);
	for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
		CHANNEL_REC *rec;
		level = MSGLEVEL_QUITS;
		rec = tmp->data;

		if (!nicklist_find(rec, nick))
			continue;

		if (ignore_check_plus(server, nick, address, rec->visible_name,
				      reason, &level, TRUE)) {
			count++;
			continue;
		}

		if (print_channel == NULL ||
		    active_win->active == (WI_ITEM_REC *) rec)
			print_channel = rec->visible_name;

		if (once)
			g_string_append_printf(chans, "%s,", rec->visible_name);
		else {
			window = window_item_window((WI_ITEM_REC *) rec);
			if (g_slist_find(windows, window) == NULL) {
				windows = g_slist_append(windows, window);
				printformat(server, rec->visible_name,
					    level,
					    TXT_QUIT, nick, address, reason,
					    rec->visible_name);
			}
		}
		count++;
	}
	g_slist_free(windows);

	if (!once) {
		/* check if you had query with the nick and
		   display the quit there too */
		QUERY_REC *query = query_find(server, nick);
		if (query != NULL) {
			printformat(server, nick, level,
				    TXT_QUIT, nick, address, reason, "");
		}
	}

	if (once || count == 0) {
		if (chans->len > 0)
			g_string_truncate(chans, chans->len-1);
		printformat(server, print_channel, MSGLEVEL_QUITS,
			    count <= 1 ? TXT_QUIT : TXT_QUIT_ONCE,
			    nick, address, reason, chans->str);
	}
	g_string_free(chans, TRUE);
}
Example #24
0
static void cmd_server_add(const char *data)
{
        GHashTable *optlist;
	SERVER_SETUP_REC *rec;
	char *addr, *portstr, *password, *value, *chatnet;
	void *free_arg;
	int port;

	if (!cmd_get_params(data, &free_arg, 3 | PARAM_FLAG_OPTIONS,
			    "server add", &optlist, &addr, &portstr, &password))
		return;

	if (*addr == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
	port = *portstr == '\0' ? DEFAULT_SERVER_ADD_PORT : atoi(portstr);

	chatnet = g_hash_table_lookup(optlist, "network");

	rec = server_setup_find(addr, port, chatnet);

	if (rec == NULL) {
		rec = create_server_setup(optlist);
		if (rec == NULL) {
			cmd_params_free(free_arg);
			return;
		}
		rec->address = g_strdup(addr);
		rec->port = port;
	} else {
		value = g_hash_table_lookup(optlist, "port");
		if (value != NULL && *value != '\0') rec->port = atoi(value);

		if (*password != '\0') g_free_and_null(rec->password);
		if (g_hash_table_lookup(optlist, "host")) {
			g_free_and_null(rec->own_host);
			rec->own_ip4 = rec->own_ip6 = NULL;
		}
	}

	if (g_hash_table_lookup(optlist, "6"))
		rec->family = AF_INET6;
        else if (g_hash_table_lookup(optlist, "4"))
		rec->family = AF_INET;

	if (g_hash_table_lookup(optlist, "ssl"))
		rec->use_ssl = TRUE;

	value = g_hash_table_lookup(optlist, "ssl_cert");
	if (value != NULL && *value != '\0')
		rec->ssl_cert = g_strdup(value);

	value = g_hash_table_lookup(optlist, "ssl_pkey");
	if (value != NULL && *value != '\0')
		rec->ssl_pkey = g_strdup(value);

	if (g_hash_table_lookup(optlist, "ssl_verify"))
		rec->ssl_verify = TRUE;

	value = g_hash_table_lookup(optlist, "ssl_cafile");
	if (value != NULL && *value != '\0')
		rec->ssl_cafile = g_strdup(value);

	value = g_hash_table_lookup(optlist, "ssl_capath");
	if (value != NULL && *value != '\0')
		rec->ssl_capath = g_strdup(value);

	if ((rec->ssl_cafile != NULL && rec->ssl_cafile[0] != '\0')
	||  (rec->ssl_capath != NULL && rec->ssl_capath[0] != '\0'))
		rec->ssl_verify = TRUE;

	if ((rec->ssl_cert != NULL && rec->ssl_cert[0] != '\0') || rec->ssl_verify == TRUE)
		rec->use_ssl = TRUE;

	if (g_hash_table_lookup(optlist, "auto")) rec->autoconnect = TRUE;
	if (g_hash_table_lookup(optlist, "noauto")) rec->autoconnect = FALSE;
	if (g_hash_table_lookup(optlist, "proxy")) rec->no_proxy = FALSE;
	if (g_hash_table_lookup(optlist, "noproxy")) rec->no_proxy = TRUE;

	if (*password != '\0' && strcmp(password, "-") != 0) rec->password = g_strdup(password);
	value = g_hash_table_lookup(optlist, "host");
	if (value != NULL && *value != '\0') {
		rec->own_host = g_strdup(value);
		rec->own_ip4 = rec->own_ip6 = NULL;
	}

	signal_emit("server add fill", 2, rec, optlist);

	server_setup_add(rec);
	printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
		    TXT_SETUPSERVER_ADDED, addr, port);

	cmd_params_free(free_arg);
}
Example #25
0
static void show_lastlog(const char *searchtext, GHashTable *optlist,
			 int start, int count, FILE *fhandle)
{
	WINDOW_REC *window;
        LINE_REC *startline;
	GList *list, *tmp;
	GString *line;
        char *str;
	int level, before, after, len, date = FALSE;

        level = cmd_options_get_level("lastlog", optlist);
	if (level == -1) return; /* error in options */
        if (level == 0) level = MSGLEVEL_ALL;

	if (g_hash_table_lookup(optlist, "clear") != NULL) {
		textbuffer_view_remove_lines_by_level(WINDOW_GUI(active_win)->view, MSGLEVEL_LASTLOG);
		if (*searchtext == '\0')
                        return;
	}

        /* which window's lastlog to look at? */
        window = active_win;
        str = g_hash_table_lookup(optlist, "window");
	if (str != NULL) {
		window = is_numeric(str, '\0') ?
			window_find_refnum(atoi(str)) :
			window_find_item(NULL, str);
		if (window == NULL) {
			printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
                                    TXT_REFNUM_NOT_FOUND, str);
			return;
		}
	}

	if (g_hash_table_lookup(optlist, "new") != NULL)
		startline = textbuffer_view_get_bookmark(WINDOW_GUI(window)->view, "lastlog_last_check");
	else if (g_hash_table_lookup(optlist, "away") != NULL)
		startline = textbuffer_view_get_bookmark(WINDOW_GUI(window)->view, "lastlog_last_away");
	else
		startline = NULL;

	if (startline == NULL)
                startline = textbuffer_view_get_lines(WINDOW_GUI(window)->view);

	str = g_hash_table_lookup(optlist, "#");
	if (str != NULL) {
		before = after = atoi(str);
	} else {
		str = g_hash_table_lookup(optlist, "before");
		before = str == NULL ? 0 : *str != '\0' ?
			atoi(str) : DEFAULT_LASTLOG_BEFORE;

		str = g_hash_table_lookup(optlist, "after");
		if (str == NULL) str = g_hash_table_lookup(optlist, "a");
		after = str == NULL ? 0 : *str != '\0' ?
			atoi(str) : DEFAULT_LASTLOG_AFTER;
	}

	if (g_hash_table_lookup(optlist, "date") != NULL)
		date = TRUE;

	list = textbuffer_find_text(WINDOW_GUI(window)->view->buffer, startline,
				    level, MSGLEVEL_LASTLOG,
				    searchtext, before, after,
				    g_hash_table_lookup(optlist, "regexp") != NULL,
				    g_hash_table_lookup(optlist, "word") != NULL,
				    g_hash_table_lookup(optlist, "case") != NULL);

        len = g_list_length(list);
	if (count <= 0)
		tmp = list;
	else {
		int pos = len-count-start;
		if (pos < 0) pos = 0;

		tmp = pos > len ? NULL : g_list_nth(list, pos);
		len = g_list_length(tmp);
	}

	if (g_hash_table_lookup(optlist, "count") != NULL) {
		printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
				   TXT_LASTLOG_COUNT, len);
		g_list_free(list);
		return;
	}

	if (len > MAX_LINES_WITHOUT_FORCE && fhandle == NULL &&
	    g_hash_table_lookup(optlist, "force") == NULL) {
		printformat_window(active_win,
				   MSGLEVEL_CLIENTNOTICE|MSGLEVEL_LASTLOG,
				   TXT_LASTLOG_TOO_LONG, len);
		g_list_free(list);
		return;
	}

	if (fhandle == NULL && g_hash_table_lookup(optlist, "-") == NULL)
		printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_START);

	line = g_string_new(NULL);
        while (tmp != NULL && (count < 0 || count > 0)) {
		LINE_REC *rec = tmp->data;

		if (rec == NULL) {
			if (tmp->next == NULL)
                                break;
			if (fhandle != NULL) {
				fwrite("--\n", 3, 1, fhandle);
			} else {
				printformat_window(active_win,
						   MSGLEVEL_LASTLOG,
						   TXT_LASTLOG_SEPARATOR);
			}
                        tmp = tmp->next;
			continue;
		}

                /* get the line text */
		textbuffer_line2text(rec, fhandle == NULL, line);
		if (!settings_get_bool("timestamps")) {
			struct tm *tm = localtime(&rec->info.time);
                        char timestamp[10];

			g_snprintf(timestamp, sizeof(timestamp),
				   "%02d:%02d ",
				   tm->tm_hour, tm->tm_min);
                        g_string_prepend(line, timestamp);
		}

		if (date == TRUE)
			prepend_date(window, rec, line);

                /* write to file/window */
		if (fhandle != NULL) {
			fwrite(line->str, line->len, 1, fhandle);
			fputc('\n', fhandle);
		} else {
			printtext_window(active_win, MSGLEVEL_LASTLOG,
					 "%s", line->str);
		}

		count--;
		tmp = tmp->next;
	}
        g_string_free(line, TRUE);

	if (fhandle == NULL && g_hash_table_lookup(optlist, "-") == NULL)
		printformat(NULL, NULL, MSGLEVEL_LASTLOG, TXT_LASTLOG_END);

	textbuffer_view_set_bookmark_bottom(WINDOW_GUI(window)->view,
					    "lastlog_last_check");

	g_list_free(list);
}
Example #26
0
static void sig_message_public(SERVER_REC *server, const char *msg,
			       const char *nick, const char *address,
			       const char *target, NICK_REC *nickrec)
{
	CHANNEL_REC *chanrec;
	const char *nickmode, *printnick;
	int for_me, print_channel, level;
	char *color, *freemsg = NULL;

	/* NOTE: this may return NULL if some channel is just closed with
	   /WINDOW CLOSE and server still sends the few last messages */
	chanrec = channel_find(server, target);
	if (nickrec == NULL && chanrec != NULL)
                nickrec = nicklist_find(chanrec, nick);

	for_me = !settings_get_bool("hilight_nick_matches") ? FALSE :
		nick_match_msg(chanrec, msg, server->nick);
	color = for_me ? NULL :
		hilight_match_nick(server, target, nick, address, MSGLEVEL_PUBLIC, msg);

	print_channel = chanrec == NULL ||
		!window_item_is_active((WI_ITEM_REC *) chanrec);
	if (!print_channel && settings_get_bool("print_active_channel") &&
	    window_item_window((WI_ITEM_REC *) chanrec)->items->next != NULL)
		print_channel = TRUE;

	level = MSGLEVEL_PUBLIC;
	if (for_me || color != NULL)
		level |= MSGLEVEL_HILIGHT;

	if (settings_get_bool("emphasis"))
		msg = freemsg = expand_emphasis((WI_ITEM_REC *) chanrec, msg);

	/* get nick mode & nick what to print the msg with
	   (in case there's multiple identical nicks) */
	nickmode = channel_get_nickmode_rec(nickrec);
	printnick = nickrec == NULL ? nick :
		g_hash_table_lookup(printnicks, nickrec);
	if (printnick == NULL)
		printnick = nick;

	if (!print_channel) {
		/* message to active channel in window */
		if (color != NULL) {
			/* highlighted nick */
			printformat(server, target, level,
				    TXT_PUBMSG_HILIGHT,
				    color, printnick, msg, nickmode);
		} else {
			printformat(server, target, level,
				    for_me ? TXT_PUBMSG_ME : TXT_PUBMSG,
				    printnick, msg, nickmode);
		}
	} else {
		/* message to not existing/active channel */
		if (color != NULL) {
			/* highlighted nick */
			printformat(server, target, level,
				    TXT_PUBMSG_HILIGHT_CHANNEL,
				    color, printnick, target, msg, nickmode);
		} else {
			printformat(server, target, level,
				    for_me ? TXT_PUBMSG_ME_CHANNEL :
				    TXT_PUBMSG_CHANNEL,
				    printnick, target, msg, nickmode);
		}
	}

        g_free_not_null(freemsg);
	g_free_not_null(color);
}
Example #27
0
static void sig_server_looking(SERVER_REC *server)
{
	g_return_if_fail(server != NULL);

	printformat(server, NULL, MSGLEVEL_CLIENTNOTICE, TXT_LOOKING_UP, server->connrec->address);
}
Example #28
0
static void sig_message_join(SERVER_REC *server, const char *channel,
			     const char *nick, const char *address)
{
	printformat(server, channel, MSGLEVEL_JOINS,
		    TXT_JOIN, nick, address, channel);
}
Example #29
0
/* NOTE: -network replaces the old -ircnet flag. */
static void cmd_ignore(const char *data)
{
	GHashTable *optlist;
	IGNORE_REC *rec;
	char *patternarg, *chanarg, *mask, *levels, *timestr, *servertag;
	char **channels;
	void *free_arg;
	int new_ignore, msecs, level, flags;

	if (*data == '\0') {
		cmd_ignore_show();
		return;
	}

	if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS | 
			    PARAM_FLAG_GETREST | PARAM_FLAG_STRIP_TRAILING_WS,
			    "ignore", &optlist, &mask, &levels))
		return;

	patternarg = g_hash_table_lookup(optlist, "pattern");
        chanarg = g_hash_table_lookup(optlist, "channels");
	servertag = g_hash_table_lookup(optlist, "network");
	/* Allow -ircnet for backwards compatibility */
	if (!servertag)
		servertag = g_hash_table_lookup(optlist, "ircnet");

	if (*mask == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
        if (*levels == '\0') levels = "ALL";
	level = level2bits(levels, NULL);

	msecs = 0;
	timestr = g_hash_table_lookup(optlist, "time");
	if (timestr != NULL) {
		if (!parse_time_interval(timestr, &msecs))
			cmd_param_error(CMDERR_INVALID_TIME);
	}

	if (active_win->active_server != NULL &&
	    server_ischannel(active_win->active_server, mask)) {
		chanarg = mask;
		mask = NULL;
	}
	channels = (chanarg == NULL || *chanarg == '\0') ? NULL :
		g_strsplit(chanarg, ",", -1);

	flags = IGNORE_FIND_PATTERN;
	if (level & MSGLEVEL_NO_ACT)
		flags |= IGNORE_FIND_NOACT;
	if (level & MSGLEVEL_HIDDEN)
		flags |= IGNORE_FIND_HIDDEN;

	rec = ignore_find_full(servertag, mask, patternarg, channels, flags);
	new_ignore = rec == NULL;

	if (rec == NULL) {
		rec = g_new0(IGNORE_REC, 1);

		rec->mask = mask == NULL || *mask == '\0' ||
			g_strcmp0(mask, "*") == 0 ? NULL : g_strdup(mask);
		rec->channels = channels;
	} else {
                g_free_and_null(rec->pattern);
		g_strfreev(channels);
	}

	rec->level = combine_level(rec->level, levels);

	if (rec->level == MSGLEVEL_NO_ACT) {
		/* If only NO_ACT was specified add all levels; it makes no
		 * sense on its own. */
		rec->level |= MSGLEVEL_ALL;
	}

	if (rec->level == MSGLEVEL_HIDDEN) {
		/* If only HIDDEN was specified add all levels; it makes no
		 * sense on its own. */
		rec->level |= MSGLEVEL_ALL;
	}

	if (new_ignore && rec->level == 0) {
		/* tried to unignore levels from nonexisting ignore */
		printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
			    TXT_IGNORE_NOT_FOUND, rec->mask);
		g_free(rec->mask);
		g_strfreev(rec->channels);
		g_free(rec);
		cmd_params_free(free_arg);
                return;
	}
	rec->servertag = (servertag == NULL || *servertag == '\0') ?
		NULL : g_strdup(servertag);
	rec->pattern = (patternarg == NULL || *patternarg == '\0') ?
		NULL : g_strdup(patternarg);
	rec->exception = g_hash_table_lookup(optlist, "except") != NULL;
	rec->regexp = g_hash_table_lookup(optlist, "regexp") != NULL;
	rec->fullword = g_hash_table_lookup(optlist, "full") != NULL;
	rec->replies = g_hash_table_lookup(optlist, "replies") != NULL;
	if (msecs != 0)
		rec->unignore_time = time(NULL)+msecs/1000;

	if (new_ignore)
		ignore_add_rec(rec);
	else
		ignore_update_rec(rec);

	cmd_params_free(free_arg);
}
Example #30
0
static void sig_sasl_success(IRC_SERVER_REC *server)
{
	printformat(server, NULL, MSGLEVEL_CRAP, IRCTXT_SASL_SUCCESS);
}