Exemple #1
0
static void init_configfile(void)
{
	struct stat statbuf;
	char *str;

	if (stat(get_irssi_dir(), &statbuf) != 0) {
		/* ~/.irssi not found, create it. */
		if (g_mkdir_with_parents(get_irssi_dir(), 0700) != 0) {
			g_error("Couldn't create %s directory: %s",
			        get_irssi_dir(), g_strerror(errno));
		}
	} else if (!S_ISDIR(statbuf.st_mode)) {
		g_error("%s is not a directory.\n"
			"You should remove it with command: rm %s",
			get_irssi_dir(), get_irssi_dir());
	}

	mainconfig = parse_configfile(NULL);
	config_last_modifycounter = mainconfig->modifycounter;

	/* any errors? */
	if (config_last_error(mainconfig) != NULL) {
		str = g_strdup_printf("Ignored errors in configuration file:\n%s",
				      config_last_error(mainconfig));
		signal_emit("gui dialog", 2, "error", str);
                g_free(str);
	}

	signal(SIGTERM, sig_term);
}
Exemple #2
0
/* SYNTAX: UPGRADE [<irssi binary path>] */
static void cmd_upgrade(const char *data)
{
	CONFIG_REC *session;
	char *session_file, *str;
	char *binary;

	if (*data == '\0')
		data = irssi_binary;

	if ((binary = g_find_program_in_path(data)) == NULL)
		cmd_return_error(CMDERR_PROGRAM_NOT_FOUND);

	/* save the session */
        session_file = g_strdup_printf("%s/session", get_irssi_dir());
	session = config_open(session_file, 0600);
        unlink(session_file);

	signal_emit("session save", 1, session);
        config_write(session, NULL, -1);
        config_close(session);

	/* data may contain some other program as well, like
	   /UPGRADE /usr/bin/screen irssi */
	str = g_strdup_printf("%s --noconnect --session=%s --home=%s --config=%s",
			      binary, session_file, get_irssi_dir(), get_irssi_config());
	g_free(binary);
	g_free(session_file);
        session_args = g_strsplit(str, " ", -1);
        g_free(str);

	signal_emit("gui exit", 0);
}
Exemple #3
0
void themes_reload(void)
{
	GSList *refs;
	char *fname;

	/* increase every theme's refcount, and destroy them. this way if
	   we want to use the theme before it's reloaded we don't crash. */
	refs = NULL;
	while (themes != NULL) {
		THEME_REC *theme = themes->data;

		refs = g_slist_prepend(refs, theme);

		theme->refcount++;
		theme_destroy(theme);
	}

	/* first there's default theme.. */
	current_theme = theme_load("default");
	if (current_theme == NULL) {
		fname = g_strdup_printf("%s/default.theme", get_irssi_dir());
		current_theme = theme_create(fname, "default");
		current_theme->default_color = -1;
                theme_read(current_theme, NULL);
		g_free(fname);
	}

        window_themes_update();
	change_theme(settings_get_str("theme"), FALSE);

	while (refs != NULL) {
		theme_unref(refs->data);
		refs = g_slist_remove(refs, refs->data);
	}
}
Exemple #4
0
static GModule *module_open(const char *name, int *found)
{
	struct stat statbuf;
	GModule *module;
	char *path, *str;

	if (g_path_is_absolute(name) || *name == '~' ||
	    (*name == '.' && name[1] == G_DIR_SEPARATOR))
		path = g_strdup(name);
	else {
		/* first try from home dir */
		str = g_strdup_printf("%s/modules", get_irssi_dir());
    
		path = g_module_build_path(str, name);
		g_free(str);

		if (stat(path, &statbuf) == 0) {
			module = g_module_open(path, (GModuleFlags) 0);
			g_free(path);
			*found = TRUE;
			return module;
		}

		/* module not found from home dir, try global module dir */
		g_free(path);
    // MacIrssi, /usr/local/lib/foo isn't good on OSX
		path = g_module_build_path("Contents/Resources", name);
	}

	*found = stat(path, &statbuf) == 0;
	module = g_module_open(path, (GModuleFlags) 0);
	g_free(path);
	return module;
}
Exemple #5
0
static void check_oldcrap(void)
{
        FILE *f;
	char *path, str[256];
        int found;

        /* check that default.theme is up-to-date */
	path = g_strdup_printf("%s/default.theme", get_irssi_dir());
	f = fopen(path, "r+");
	if (f == NULL) {
		g_free(path);
                return;
	}
        found = FALSE;
	while (!found && fgets(str, sizeof(str), f) != NULL)
                found = strstr(str, "abstracts = ") != NULL;
	fclose(f);

	if (found) {
		g_free(path);
		return;
	}

	printf("\nYou seem to have old default.theme in "IRSSI_DIR_SHORT"/ directory.\n");
        printf("Themeing system has changed a bit since last irssi release,\n");
        printf("you should either delete your old default.theme or manually\n");
        printf("merge it with the new default.theme.\n\n");
	printf("Do you want to delete the old theme now? (Y/n)\n");

	str[0] = '\0';
	fgets(str, sizeof(str), stdin);
	if (i_toupper(str[0]) == 'Y' || str[0] == '\n' || str[0] == '\0')
                remove(path);
	g_free(path);
}
Exemple #6
0
static void autorun_startup(void)
{
	char *path;
	GIOChannel *handle;
	GString *buf;
	gsize tpos;

	/* open ~/.irssi/startup and run all commands in it */
	path = g_strdup_printf("%s/startup", get_irssi_dir());
	handle = g_io_channel_new_file(path, "r", NULL);
	g_free(path);
	if (handle == NULL) {
		/* file not found */
		return;
	}

	g_io_channel_set_encoding(handle, NULL, NULL);
	buf = g_string_sized_new(512);
	while (g_io_channel_read_line_string(handle, buf, &tpos, NULL) == G_IO_STATUS_NORMAL) {
		buf->str[tpos] = '\0';
		if (buf->str[0] != '#') {
			eval_special_string(buf->str, "",
					    active_win->active_server,
					    active_win->active);
		}
	}
	g_string_free(buf, TRUE);

	g_io_channel_unref(handle);
}
Exemple #7
0
static void perl_scripts_autorun(void)
{
	DIR *dirp;
	struct dirent *dp;
	struct stat statbuf;
	char *path, *fname;

        /* run *.pl scripts from ~/.irssi/scripts/autorun/ */
	path = g_strdup_printf("%s/scripts/autorun", get_irssi_dir());
	dirp = opendir(path);
	if (dirp == NULL) {
		g_free(path);
		return;
	}

	while ((dp = readdir(dirp)) != NULL) {
		if (!IS_PERL_SCRIPT(dp->d_name))
			continue;

		fname = g_strdup_printf("%s/%s", path, dp->d_name);
		if (stat(fname, &statbuf) == 0 && !S_ISDIR(statbuf.st_mode))
			perl_script_load_file(fname);
		g_free(fname);
	}
	closedir(dirp);
	g_free(path);
}
Exemple #8
0
/* Returns full path for the script */
char *perl_script_get_path(const char *name)
{
	struct stat statbuf;
	char *file, *path;

	if (g_path_is_absolute(name) || (name[0] == '~' && name[1] == '/')) {
		/* full path specified */
                return convert_home(name);
	}

	/* add .pl suffix if it's missing */
	file = IS_PERL_SCRIPT(name) ? g_strdup(name) :
		g_strdup_printf("%s.pl", name);

	/* check from ~/.irssi/scripts/ */
	path = g_strdup_printf("%s/scripts/%s", get_irssi_dir(), file);
	if (stat(path, &statbuf) != 0) {
		/* check from SCRIPTDIR */
		g_free(path);
		path = g_strdup_printf(SCRIPTDIR"/%s", file);
		if (stat(path, &statbuf) != 0) {
			g_free(path);
			path = NULL;
		}
	}
	g_free(file);
	return path;
}
Exemple #9
0
static void check_files(void)
{
	struct stat statbuf;

	if (stat(get_irssi_dir(), &statbuf) != 0) {
		/* ~/.irssi doesn't exist, first time running irssi */
		display_firsttimer = TRUE;
	}
}
Exemple #10
0
THEME_REC *theme_load(const char *setname)
{
	THEME_REC *theme, *oldtheme;
	struct stat statbuf;
	char *fname, *name, *p;

        name = g_strdup(setname);
	p = strrchr(name, '.');
	if (p != NULL && strcmp(p, ".theme") == 0) {
		/* remove the trailing .theme */
                *p = '\0';
	}

	theme = theme_find(name);

	/* check home dir */
	fname = g_strdup_printf("%s/%s.theme", get_irssi_dir(), name);
	if (stat(fname, &statbuf) != 0) {
		/* check global config dir */
		g_free(fname);
		fname = g_strdup_printf(THEMESDIR"/%s.theme", name);
		if (stat(fname, &statbuf) != 0) {
			/* theme not found */
			g_free(fname);
			g_free(name);
			return theme; /* use the one in memory if possible */
		}
	}

	if (theme != NULL && theme->last_modify == statbuf.st_mtime) {
		/* theme not modified, use the one already in memory */
		g_free(fname);
		g_free(name);
		return theme;
	}

        oldtheme = theme;
	theme = theme_create(fname, name);
	theme->last_modify = statbuf.st_mtime;
	if (!theme_read(theme, theme->path, NULL)) {
                /* error reading .theme file */
		theme_destroy(theme);
		theme = NULL;
	}

	if (oldtheme != NULL && theme != NULL) {
		theme_destroy(oldtheme);
		window_themes_update();
	}

	g_free(fname);
	g_free(name);
	return theme;
}
Exemple #11
0
static void sig_complete_load(GList **list, WINDOW_REC *window,
			      const char *word, const char *line,
			      int *want_space)
{
        char *user_dir;

	if (*line != '\0')
		return;

	/* completing filename parameter for /SCRIPT LOAD */
	user_dir = g_strdup_printf("%s/scripts", get_irssi_dir());
	*list = filename_complete(word, user_dir);
	*list = g_list_concat(*list, filename_complete(word, SCRIPTDIR));
        g_free(user_dir);

	if (*list != NULL) {
		*want_space = FALSE;
		signal_stop();
	}
}
Exemple #12
0
static void botuser_config_read(void)
{
	CONFIG_NODE *node;
	GSList *tmp;
	char *fname;

	/* Read users from ~/.irssi/users */
	fname = g_strdup_printf("%s/users", get_irssi_dir());
	userconfig = config_open(fname, 0600);
	g_free(fname);

	if (userconfig == NULL)
		return; /* access denied?! */

	config_parse(userconfig);

	node = config_node_traverse(userconfig, "users", FALSE);
	tmp = node == NULL ? NULL : node->value;
	for (; tmp != NULL; tmp = tmp->next)
		botuser_config_read_user(tmp->data);
}
Exemple #13
0
int pyloader_init(void)
{
    char *pyhome;

    g_return_val_if_fail(script_paths == NULL, 0);
    g_return_val_if_fail(script_modules == NULL, 0);

    script_modules = PyList_New(0);
    if (!script_modules)
        return 0;
    
    /* Add script location to the load path */
    pyhome = g_strdup_printf("%s/scripts", get_irssi_dir());
    pyloader_add_script_path(pyhome);
    g_free(pyhome);
   
    /* typically /usr/local/share/irssi/scripts */
    pyloader_add_script_path(SCRIPTDIR);
   
    return 1;
}
Exemple #14
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_ascii_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);
}