Ejemplo n.º 1
0
static char *
default_file (void)
{
	static char *dfile = 0;

	if (!dfile)
	{
		dfile = malloc (strlen (get_xdir_fs ()) + 12);
		sprintf (dfile, "%s/xchat.conf", get_xdir_fs ());
	}
	return dfile;
}
Ejemplo n.º 2
0
Archivo: plugin.c Proyecto: n2i/xvnkb
void
plugin_auto_load (session *sess)
{
	ps = sess;
	for_files ("./plugins", "*.dll", plugin_auto_load_cb);
	for_files (get_xdir_fs (), "*.dll", plugin_auto_load_cb);
}
Ejemplo n.º 3
0
void plugin_auto_load(session *sess)
{
	ps = sess;
#ifdef WIN32
	for_files("./plugins", "*.dll", plugin_auto_load_cb);
	for_files(get_xdir_fs(), "*.dll", plugin_auto_load_cb);
#else
#if defined(__hpux)
	for_files(XCHATLIBDIR"/plugins", "*.sl", plugin_auto_load_cb);
	for_files(get_xdir_fs(), "*.sl", plugin_auto_load_cb);
#else
	for_files(XCHATLIBDIR"/plugins", "*.so", plugin_auto_load_cb);
	for_files(get_xdir_fs(), "*.so", plugin_auto_load_cb);
#endif
#endif
}
Ejemplo n.º 4
0
void
list_loadconf (char *file, GSList ** list, char *defaultconf)
{
	char filebuf[256];
	char *ibuf;
	int fh;
	struct stat st;

	snprintf (filebuf, sizeof (filebuf), "%s/%s", get_xdir_fs (), file);
	fh = open (filebuf, O_RDONLY | OFLAGS);
	if (fh == -1)
	{
		if (defaultconf)
			list_load_from_data (list, defaultconf, strlen (defaultconf));
		return;
	}
	if (fstat (fh, &st) != 0)
	{
		perror ("fstat");
		abort ();
	}

	ibuf = malloc (st.st_size);
	read (fh, ibuf, st.st_size);
	close (fh);

	list_load_from_data (list, ibuf, st.st_size);

	free (ibuf);
}
Ejemplo n.º 5
0
char *
get_xdir_utf8 (void)
{
	if (!xdir_utf)	/* never free this, keep it for program life time */
		xdir_utf = xchat_filename_to_utf8 (get_xdir_fs (), -1, 0, 0, 0);

	return xdir_utf;
}
Ejemplo n.º 6
0
static char* scrollback_get_filename(session *sess, char *buf, int max)
{
	char *net, *chan;

	net = server_get_network(sess->server, FALSE);
	if (!net)
		return nullptr;

	snprintf(buf, max, "%s/scrollback/%s/%s.txt", get_xdir_fs(), net, "");
	mkdir_p(buf);

	chan = log_create_filename(sess->channel);
	snprintf(buf, max, "%s/scrollback/%s/%s.txt", get_xdir_fs(), net, chan);
	free(chan);

	return buf;
}
Ejemplo n.º 7
0
static void
check_prefs_dir (void)
{
    char *dir = get_xdir_fs ();
    if (access (dir, F_OK) != 0)
    {
        if (mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
            fe_message (_("Cannot create ~/.gchat"), FE_MSG_ERROR);
    }
}
Ejemplo n.º 8
0
FILE *
xchat_fopen_file (const char *file, const char *mode, int xof_flags)
{
	char buf[1024];

	if (xof_flags & XOF_FULLPATH)
		return fopen (file, mode);

	snprintf (buf, sizeof (buf), "%s/%s", get_xdir_fs (), file);
	return fopen (buf, mode);
}
Ejemplo n.º 9
0
void
plugin_auto_load (session *sess)
{
	ps = sess;
#ifdef WIN32
	for_files ("./plugins", "*.dll", plugin_auto_load_cb);
	for_files (get_xdir_fs (), "*.dll", plugin_auto_load_cb);
#else
#if defined(__hpux)
	for_files (XCHATLIBDIR"/plugins", "*.sl", plugin_auto_load_cb);
	for_files (get_xdir_fs (), "*.sl", plugin_auto_load_cb);
#elif defined(FE_AQUA)
	//TODO: hide plugins into application binary
	for_files ("./plugins", "*.so", plugin_auto_load_cb);   // X-Chat Aqua
	for_files (get_xdir_fs (), "*.so", plugin_auto_load_cb);
#else
	for_files (XCHATLIBDIR"/plugins", "*.so", plugin_auto_load_cb);
	for_files (get_xdir_fs (), "*.so", plugin_auto_load_cb);
#endif
#endif
}
Ejemplo n.º 10
0
static void
check_prefs_dir (void)
{
	char *dir = get_xdir_fs ();
	static char *msg = NULL;

	if (access (dir, F_OK) != 0)
	{
#ifdef WIN32
		if (mkdir (dir) != 0)
#else
		if (mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
#endif
		{
			msg = malloc (strlen (get_xdir_fs ()) + 15);
			sprintf (msg, "Cannot create %s", get_xdir_fs ());
			fe_message (msg, FE_MSG_ERROR);
			free (msg);
		}
	}
}
Ejemplo n.º 11
0
int
xchat_open_file (char *file, int flags, int mode, int xof_flags)
{
	char buf[1024];

	if (xof_flags & XOF_FULLPATH)
		return open (file, flags | OFLAGS);

	snprintf (buf, sizeof (buf), "%s/%s", get_xdir_fs (), file);
	if (xof_flags & XOF_DOMODE)
		return open (buf, flags | OFLAGS, mode);
	else
		return open (buf, flags | OFLAGS);
}
Ejemplo n.º 12
0
static void
check_prefs_dir (void)
{
	char *dir = get_xdir_fs ();
	if (access (dir, F_OK) != 0)
	{
#ifdef WIN32
		if (mkdir (dir) != 0)
#else
		if (mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR) != 0)
#endif
			fe_message (_("Cannot create ~/.xchat2"), FE_MSG_ERROR);
	}
}
Ejemplo n.º 13
0
static void
irc_init (session *sess)
{
	static int done_init = FALSE;
	char buf[512];

	if (done_init)
		return;

	done_init = TRUE;

	plugin_add (sess, NULL, NULL, timer_plugin_init, NULL, NULL, FALSE);

#ifdef USE_PLUGIN
	if (!arg_skip_plugins)
		plugin_auto_load (sess);	/* autoload ~/.xchat *.so */
#endif

#ifdef USE_DBUS
	plugin_add (sess, NULL, NULL, dbus_plugin_init, NULL, NULL, FALSE);
#endif

	if (prefs.notify_timeout)
		notify_tag = fe_timeout_add (prefs.notify_timeout * 1000,
											  notify_checklist, 0);

	fe_timeout_add (prefs.away_timeout * 1000, away_check, 0);
	fe_timeout_add (500, xchat_misc_checks, 0);

	if (arg_url != NULL)
	{
		snprintf (buf, sizeof (buf), "server %s", arg_url);
		handle_command (sess, buf, FALSE);
		g_free (arg_url);	/* from GOption */
	}

	if (arg_command != NULL)
	{
		g_free (arg_command);
	}

	/* load -e ~/.xchat2/startup.txt */
	snprintf (buf, sizeof (buf), "%s/%s", get_xdir_fs (), "startup.txt");
	load_perform_file (sess, buf);
}
Ejemplo n.º 14
0
void
gtkutil_file_req (const char *title, void *callback, void *userdata, char *filter, char *extensions,
						int flags)
{
	struct file_req *freq;
	GtkWidget *dialog;
	GtkFileFilter *filefilter;
	extern char *get_xdir_fs (void);
	char *token;
	char *tokenbuffer;

#if 0	/* native file dialogs */
#ifdef WIN32
	if (!(flags & FRF_WRITE))
	{
		freq = malloc (sizeof (struct file_req));
		freq->th = thread_new ();
		freq->flags = 0;
		freq->multiple = (flags & FRF_MULTIPLE);
		freq->callback = callback;
		freq->userdata = userdata;
		freq->title = g_locale_from_utf8 (title, -1, 0, 0, 0);
		if (!filter)
		{
			freq->filter =	"All files\0*.*\0"
							"Executables\0*.exe\0"
							"ZIP files\0*.zip\0\0";
		}
		else
		{
			freq->filter = filter;
		}

		thread_start (freq->th, win32_thread, freq);
		fe_input_add (freq->th->pipe_fd[0], FIA_FD|FIA_READ, win32_read_thread, freq);

		return;

	}
	
	else {
		freq = malloc (sizeof (struct file_req));
		freq->th = thread_new ();
		freq->flags = 0;
		freq->multiple = (flags & FRF_MULTIPLE);
		freq->callback = callback;
		freq->userdata = userdata;
		freq->title = g_locale_from_utf8 (title, -1, 0, 0, 0);
		if (!filter)
		{
			freq->filter = "All files\0*.*\0\0";
		}
		else
		{
			freq->filter = filter;
		}

		thread_start (freq->th, win32_thread2, freq);
		fe_input_add (freq->th->pipe_fd[0], FIA_FD|FIA_READ, win32_read_thread, freq);

	return;
	}
#endif
#endif

	if (flags & FRF_WRITE)
	{
		dialog = gtk_file_chooser_dialog_new (title, NULL,
												GTK_FILE_CHOOSER_ACTION_SAVE,
												GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
												GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
												NULL);
		if (filter && filter[0])	/* filter becomes initial name when saving */
		{
			char temp[1024];
			path_part (filter, temp, sizeof (temp));
			gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), temp);
			gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), file_part (filter));
		}

		if (!(flags & FRF_NOASKOVERWRITE))
			gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
	}
	else
		dialog = gtk_file_chooser_dialog_new (title, NULL,
												GTK_FILE_CHOOSER_ACTION_OPEN,
												GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
												GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
												NULL);
	if (flags & FRF_MULTIPLE)
		gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
	if (last_dir[0])
		gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), last_dir);
	if (flags & FRF_ADDFOLDER)
		gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
														  get_xdir_fs (), NULL);
	if (flags & FRF_CHOOSEFOLDER)
	{
		gtk_file_chooser_set_action (GTK_FILE_CHOOSER (dialog), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
		gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), filter);
	}
	else
	{
		if (filter && (flags & FRF_FILTERISINITIAL))
			gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), filter);
	}

	if (flags & FRF_EXTENSIONS && extensions != NULL)
	{
		filefilter = gtk_file_filter_new ();
		tokenbuffer = g_strdup (extensions);
		token = strtok (tokenbuffer, ";");

		while (token != NULL)
		{
			gtk_file_filter_add_pattern (filefilter, token);
			token = strtok (NULL, ";");
		}

		g_free (tokenbuffer);
		gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filefilter);
	}

	freq = malloc (sizeof (struct file_req));
	freq->dialog = dialog;
	freq->flags = flags;
	freq->callback = callback;
	freq->userdata = userdata;

	g_signal_connect (G_OBJECT (dialog), "response",
							G_CALLBACK (gtkutil_file_req_response), freq);
	g_signal_connect (G_OBJECT (dialog), "destroy",
						   G_CALLBACK (gtkutil_file_req_destroy), (gpointer) freq);
	gtk_widget_show (dialog);
}
Ejemplo n.º 15
0
int
fe_args (int argc, char *argv[])
{
	GError *error = NULL;
	GOptionContext *context;

#ifdef ENABLE_NLS
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
#endif

	context = g_option_context_new (NULL);
	g_option_context_add_main_entries (context, gopt_entries, GETTEXT_PACKAGE);
	g_option_context_parse (context, &argc, &argv, &error);

	if (error)
	{
		if (error->message)
			printf ("%s\n", error->message);
		return 1;
	}

	g_option_context_free (context);

	if (arg_show_version)
	{
		printf (PACKAGE_TARNAME" "PACKAGE_VERSION"\n");
		return 0;
	}

	if (arg_show_autoload)
	{
#ifdef WIN32
		/* see the chdir() below */
		char *sl, *exe = strdup (argv[0]);
		sl = strrchr (exe, '\\');
		if (sl)
		{
			*sl = 0;
			printf ("%s\\plugins\n", exe);
		}
#else
		printf ("%s\n", HEXCHATLIBDIR"/plugins");
#endif
		return 0;
	}

	if (arg_show_config)
	{
		printf ("%s\n", get_xdir_fs ());
		return 0;
	}

	if (arg_cfgdir)	/* we want filesystem encoding */
	{
		xdir_fs = strdup (arg_cfgdir);
		if (xdir_fs[strlen (xdir_fs) - 1] == '/')
			xdir_fs[strlen (xdir_fs) - 1] = 0;
		g_free (arg_cfgdir);
	}

	return -1;
}
Ejemplo n.º 16
0
int
servlist_save (void)
{
	FILE *fp;
	char buf[256];
	ircnet *net;
	ircserver *serv;
	GSList *list;
	GSList *hlist;
#ifndef WIN32
	int first = FALSE;

	snprintf (buf, sizeof (buf), "%s/servlist_.conf", get_xdir_fs ());
	if (access (buf, F_OK) != 0)
		first = TRUE;
#endif

	fp = xchat_fopen_file ("servlist_.conf", "w", 0);
	if (!fp)
		return FALSE;

#ifndef WIN32
	if (first)
		chmod (buf, 0600);
#endif
	fprintf (fp, "v="PACKAGE_VERSION"\n\n");

	list = network_list;
	while (list)
	{
		net = list->data;

		fprintf (fp, "N=%s\n", net->name);
		if (net->nick)
			fprintf (fp, "I=%s\n", net->nick);
		if (net->nick2)
			fprintf (fp, "i=%s\n", net->nick2);
		if (net->user)
			fprintf (fp, "U=%s\n", net->user);
		if (net->real)
			fprintf (fp, "R=%s\n", net->real);
		if (net->pass)
			fprintf (fp, "P=%s\n", net->pass);
		if (net->autojoin)
			fprintf (fp, "J=%s\n", net->autojoin);
		if (net->nickserv)
			fprintf (fp, "B=%s\n", net->nickserv);
		if (net->encoding && g_ascii_strcasecmp (net->encoding, "System") &&
			 g_ascii_strcasecmp (net->encoding, "System default"))
		{
			fprintf (fp, "E=%s\n", net->encoding);
			if (!servlist_check_encoding (net->encoding))
			{
				snprintf (buf, sizeof (buf), _("Warning: \"%s\" character set is unknown. No conversion will be applied for network %s."),
							 net->encoding, net->name);
				fe_message (buf, FE_MSG_WARN);
			}
		}

		if (net->command)
			token_foreach (net->command, '\n', servlist_write_ccmd, fp);

		fprintf (fp, "F=%d\nD=%d\n", net->flags, net->selected);

		hlist = net->servlist;
		while (hlist)
		{
			serv = hlist->data;
			fprintf (fp, "S=%s\n", serv->hostname);
			hlist = hlist->next;
		}

		if (fprintf (fp, "\n") < 1)
		{
			fclose (fp);
			return FALSE;
		}

		list = list->next;
	}

	fclose (fp);
	return TRUE;
}
Ejemplo n.º 17
0
const char* xchat_get_info(xchat_plugin *ph, const char *id)
{
	session *sess;
	unsigned int hash;

	// 1234567890
	if (!strncmp(id, "event_text", 10))
	{
		char *e = (char*)id + 10;
		if (*e == ' ') e++;	// 2.8.0 only worked without a space
		return text_find_format_string(e);
	}

	hash = str_hash(id);
	// do the session independant ones first
	switch (hash)
	{
	case 0x325acab5:	// libdirfs
		return XCHATLIBDIR;

	case 0x14f51cd8: // version
		return PACKAGE_VERSION;

	case 0xdd9b1abd:	// xchatdir
		return get_xdir_utf8();

	case 0xe33f6c4a:	// xchatdirfs
		return get_xdir_fs();
	}

	sess = ph->context;
	if (!is_session(sess))
	{
		DEBUG(PrintTextf(0, "%s\txchat_get_info called without a valid context.\n", ph->name));
		return nullptr;
	}

	switch (hash)
	{
	case 0x2de2ee: // away
		if (sess->server->is_away)
			return sess->server->last_away_reason;
		return nullptr;

	case 0x2c0b7d03: // channel
		return sess->channel;

	case 0x2c0d614c: // charset
		{
			const char *locale;

			if (sess->server->encoding)
				return sess->server->encoding;

			locale = nullptr;
			g_get_charset(&locale);
			return locale;
		}

	case 0x30f5a8: // host
		return sess->server->hostname;

	case 0x1c0e99c1: // inputbox
		return fe_get_inputbox_contents(sess);

	case 0x633fb30:	// modes
		return sess->current_modes;

	case 0x6de15a2e:	// network
		return server_get_network(sess->server, FALSE);

	case 0x339763: // nick
		return sess->server->nick;

	case 0x438fdf9: // nickserv
		if (sess->server->network)
			return ((ircnet*)sess->server->network)->nickserv;
		return nullptr;

	case 0xca022f43: // server
		if (!sess->server->connected)
			return nullptr;
		return sess->server->servername;

	case 0x696cd2f: // topic
		return sess->topic;

	case 0x3419f12d: // gtkwin_ptr
		return (const char*)fe_gui_info_ptr(sess, 1);

	case 0x506d600b: // native win_ptr
		return (const char*)fe_gui_info_ptr(sess, 0);

	case 0x6d3431b5: // win_status
		switch (fe_gui_info(sess, 0))	// check window status
		{
		case 0: return "normal";
		case 1: return "active";
		case 2: return "hidden";
		}
		return nullptr;
	}

	return nullptr;
}
Ejemplo n.º 18
0
static int
xchat_pluginpref_set_str_real (xchat_plugin *pl, const char *var, const char *value, int mode) /* mode: 0 = delete, 1 = save */
{
	FILE *fpIn;
	int fhOut;
	int prevSetting;
	char confname[64];
	char confname_tmp[69];
	char buffer[512];		/* the same as in cfg_put_str */
	char buffer_tmp[512];
	char *canon;

	canon = g_strdup (pl->name);
	canonalize_key (canon);
	sprintf (confname, "plugin_%s.conf", canon);
	g_free (canon);
	sprintf (confname_tmp, "%s.new", confname);

	fhOut = xchat_open_file (confname_tmp, O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE);
	fpIn = xchat_fopen_file (confname, "r", 0);

	if (fhOut == -1)		/* unable to save, abort */
	{
		return 0;
	}
	else if (fpIn == NULL)	/* no previous config file, no parsing */
	{
		if (mode)
		{
			sprintf (buffer, "%s = %s\n", var, value);
			write (fhOut, buffer, strlen (buffer));
			close (fhOut);

			sprintf (buffer, "%s/%s", get_xdir_fs (), confname);
			sprintf (buffer_tmp, "%s/%s", get_xdir_fs (), confname_tmp);

#ifdef WIN32
			unlink (buffer);
#endif

			if (rename (buffer_tmp, buffer) == 0)
			{
				return 1;
			}
			else
			{
				return 0;
			}
		}
		else
		{
			/* mode = 0, we want to delete but the config file and thus the given setting does not exist, we're ready */
			close (fhOut);
			return 1;
		}
	}
	else	/* existing config file, preserve settings and find & replace current var value if any */
	{
		prevSetting = 0;

		while (fscanf (fpIn, " %[^\n]", &buffer) != EOF)	/* read whole lines including whitespaces */
		{
			sprintf (buffer_tmp, "%s ", var);				/* add one space, this way it works against var - var2 checks too */

			if (strncmp (buffer_tmp, buffer, strlen (var) + 1) == 0)	/* given setting already exists */
			{
				if (mode)									/* overwrite the existing matching setting if we are in save mode */
				{
					sprintf (buffer, "%s = %s\n", var, value);
				}
				else										/* erase the setting in delete mode */
				{
					strcpy (buffer, "");
				}

				prevSetting = 1;
			}
			else
			{
				strcat (buffer, "\n");						/* preserve the existing different settings */
			}

			write (fhOut, buffer, strlen (buffer));
		}

		fclose (fpIn);

		if (!prevSetting && mode)	/* var doesn't exist currently, append if we're in save mode */
		{
			sprintf (buffer, "%s = %s\n", var, value);
			write (fhOut, buffer, strlen (buffer));
		}

		close (fhOut);

		sprintf (buffer, "%s/%s", get_xdir_fs (), confname);
		sprintf (buffer_tmp, "%s/%s", get_xdir_fs (), confname_tmp);

#ifdef WIN32
		unlink (buffer);
#endif

		if (rename (buffer_tmp, buffer) == 0)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
}
Ejemplo n.º 19
0
Archivo: plugin.c Proyecto: n2i/xvnkb
const char *
xchat_get_info (xchat_plugin *ph, const char *id)
{
	session *sess;
	guint32 hash;

	/*                 1234567890 */
	if (!strncmp (id, "event_text", 10))
	{
		char *e = (char *)id + 10;
		if (*e == ' ') e++;	/* 2.8.0 only worked without a space */
		return text_find_format_string (e);
	}

	hash = str_hash (id);
	/* do the session independant ones first */
	switch (hash)
	{
	case 0x325acab5:	/* libdirfs */
		return ".";

	case 0x14f51cd8: /* version */
		return PACKAGE_VERSION;

	case 0xdd9b1abd:	/* xchatdir */
		return get_xdir_utf8 ();

	case 0xe33f6c4a:	/* xchatdirfs */
		return get_xdir_fs ();
	}

	sess = ph->context;
	if (!is_session (sess))
	{
		DEBUG(PrintTextf(0, "%s\txchat_get_info called without a valid context.\n", ph->name));
		return NULL;
	}

	switch (hash)
	{
	case 0x2de2ee: /* away */
		if (sess->server->is_away)
			return sess->server->last_away_reason;
		return NULL;

  	case 0x2c0b7d03: /* channel */
		return sess->channel;

	case 0x2c0d614c: /* charset */
		{
			const char *locale;

			if (sess->server->encoding)
				return sess->server->encoding;

			locale = NULL;
			g_get_charset (&locale);
			return locale;
		}

	case 0x30f5a8: /* host */
		return sess->server->hostname;

	case 0x1c0e99c1: /* inputbox */
		return fe_get_inputbox_contents (sess);

	case 0x633fb30:	/* modes */
		return sess->current_modes;

	case 0x6de15a2e:	/* network */
		return server_get_network (sess->server, FALSE);

	case 0x339763: /* nick */
		return sess->server->nick;

	case 0x438fdf9: /* nickserv */
		if (sess->server->network)
			return ((ircnet *)sess->server->network)->nickserv;
		return NULL;

	case 0xca022f43: /* server */
		if (!sess->server->connected)
			return NULL;
		return sess->server->servername;

	case 0x696cd2f: /* topic */
		return sess->topic;

	case 0x506d600b: /* native win_ptr */
		//return fe_gui_info_ptr (sess, 0);
		return fe_gui_info_ptr (sess, 1);

	case 0x6d3431b5: /* win_status */
		switch (fe_gui_info (sess, 0))	/* check window status */
		{
		case 0: return "normal";
		case 1: return "active";
		case 2: return "hidden";
		}
		return NULL;
	}

	return NULL;
}