Exemplo n.º 1
0
void
palette_save (void)
{
	int i, j, fh;
	char prefname[256];

	fh = xchat_open_file ("colors.conf", O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE);
	if (fh != -1)
	{
		/* mIRC colors 0-31 are here */
		for (i = 0; i < 32; i++)
		{
			snprintf (prefname, sizeof prefname, "color_%d", i);
			cfg_put_color (fh, colors[i].red, colors[i].green, colors[i].blue, prefname);
		}

		/* our special colors are mapped at 256+ */
		for (i = 256, j = 32; j < MAX_COL+1; i++, j++)
		{
			snprintf (prefname, sizeof prefname, "color_%d", i);
			cfg_put_color (fh, colors[j].red, colors[j].green, colors[j].blue, prefname);
		}

		close (fh);
	}
}
Exemplo n.º 2
0
void
notify_save (void)
{
	int fh;
	struct notify *notify;
	GSList *list = notify_list;

	fh = xchat_open_file ("notify.conf", O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE);
	if (fh != -1)
	{
		while (list)
		{
			notify = (struct notify *) list->data;
			write (fh, notify->name, strlen (notify->name));
			if (notify->networks)
			{
				write (fh, " ", 1);
				write (fh, notify->networks, strlen (notify->networks));
			}
			write (fh, "\n", 1);
			list = list->next;
		}
		close (fh);
	}
}
Exemplo n.º 3
0
void
notify_load (void)
{
	int fh;
	char buf[256];
	char *sep;

	fh = xchat_open_file ("notify.conf", O_RDONLY, 0, 0);
	if (fh != -1)
	{
		while (waitline (fh, buf, sizeof buf, FALSE) != -1)
		{
			if (buf[0] != '#' && buf[0] != 0)
			{
				sep = strchr (buf, ' ');
				if (sep)
				{
					sep[0] = 0;
					notify_adduser (buf, sep + 1);					
				}
				else
					notify_adduser (buf, NULL);
			}
		}
		close (fh);
	}
}
Exemplo n.º 4
0
int
xchat_pluginpref_get_str (xchat_plugin *pl, const char *var, char *dest)
{
	int fh;
	int l;
	char confname[64];
	char *canon;
	char *cfg;
	struct stat st;

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

	/* partly borrowed from palette.c */
	fh = xchat_open_file (confname, O_RDONLY, 0, 0);

	if (fh == -1)
	{
		return 0;
	}

	fstat (fh, &st);
	cfg = malloc (st.st_size + 1);

	if (!cfg)
	{
		close (fh);
		return 0;
	}

	cfg[0] = '\0';
	l = read (fh, cfg, st.st_size);

	if (l >= 0)
	{
		cfg[l] = '\0';
	}

	if (!cfg_get_str (cfg, var, dest, 512)) /* dest_len is the same as buffer size in set */
	{
		free (cfg);
		close (fh);
		return 0;
	}

	free (cfg);
	close (fh);
	return 1;
}
Exemplo n.º 5
0
Arquivo: fkeys.c Projeto: n2i/xvnkb
static void
key_load_defaults ()
{
		/* This is the default config */
#define defcfg \
		"C\nPrior\nChange Page\nD1:-1\nD2:Relative\n\n"\
		"C\nNext\nChange Page\nD1:1\nD2:Relative\n\n"\
		"A\n9\nChange Page\nD1:9\nD2!\n\n"\
		"A\n8\nChange Page\nD1:8\nD2!\n\n"\
		"A\n7\nChange Page\nD1:7\nD2!\n\n"\
		"A\n6\nChange Page\nD1:6\nD2!\n\n"\
		"A\n5\nChange Page\nD1:5\nD2!\n\n"\
		"A\n4\nChange Page\nD1:4\nD2!\n\n"\
		"A\n3\nChange Page\nD1:3\nD2!\n\n"\
		"A\n2\nChange Page\nD1:2\nD2!\n\n"\
		"A\n1\nChange Page\nD1:1\nD2!\n\n"\
		"C\no\nInsert in Buffer\nD1:\nD2!\n\n"\
		"C\nb\nInsert in Buffer\nD1:\nD2!\n\n"\
		"C\nk\nInsert in Buffer\nD1:\nD2!\n\n"\
		"S\nNext\nChange Selected Nick\nD1!\nD2!\n\n"\
		"S\nPrior\nChange Selected Nick\nD1:Up\nD2!\n\n"\
		"None\nNext\nScroll Page\nD1:Down\nD2!\n\n"\
		"None\nPrior\nScroll Page\nD1:Up\nD2!\n\n"\
		"S\nDown\nScroll Page\nD1:+1\nD2!\n\n"\
		"S\nUp\nScroll Page\nD1:-1\nD2!\n\n"\
		"None\nDown\nNext Command\nD1!\nD2!\n\n"\
		"None\nUp\nLast Command\nD1!\nD2!\n\n"\
		"None\nTab\nComplete nick/command\nD1!\nD2!\n\n"\
		"None\nspace\nCheck For Replace\nD1!\nD2!\n\n"\
		"None\nReturn\nCheck For Replace\nD1!\nD2!\n\n"\
		"None\nKP_Enter\nCheck For Replace\nD1!\nD2!\n\n"\
		"C\nTab\nComplete nick/command\nD1:Up\nD2!\n\n"\
		"A\nLeft\nMove front tab left\nD1!\nD2!\n\n"\
		"A\nRight\nMove front tab right\nD1!\nD2!\n\n"\
		"CS\nPrior\nMove tab family left\nD1!\nD2!\n\n"\
		"CS\nNext\nMove tab family right\nD1!\nD2!\n\n"\
		"None\nF9\nRun Command\nD1:/GUI MENU TOGGLE\nD2!\n\n"
	int fd;

	fd = xchat_open_file ("keybindings.conf", O_CREAT | O_TRUNC | O_WRONLY, 0x180, XOF_DOMODE);
	if (fd < 0)
		/* ???!!! */
		return;

	write (fd, defcfg, strlen (defcfg));
	close (fd);
}
Exemplo n.º 6
0
static void
rawlog_save (server *serv, char *file)
{
	int fh = -1;

	if (file)
	{
		if (serv->gui->rawlog_window)
			fh = xchat_open_file (file, O_TRUNC | O_WRONLY | O_CREAT,
										 0600, XOF_DOMODE | XOF_FULLPATH);
		if (fh != -1)
		{
			gtk_xtext_save (GTK_XTEXT (serv->gui->rawlog_textlist), fh);
			close (fh);
		}
	}
}
Exemplo n.º 7
0
static void
chanlist_filereq_done (server *serv, char *file)
{
	time_t t = time (0);
	int fh, users;
	char *chan, *topic;
	char buf[1024];
	GtkTreeModel *model = GET_MODEL (serv);
	GtkTreeIter iter;

	if (!file)
		return;

	fh = xchat_open_file (file, O_TRUNC | O_WRONLY | O_CREAT, 0600,
								 XOF_DOMODE | XOF_FULLPATH);
	if (fh == -1)
		return;

	snprintf (buf, sizeof buf, "XChat Channel List: %s - %s\n",
				 serv->servername, ctime (&t));
	write (fh, buf, strlen (buf));

	if (gtk_tree_model_get_iter_first (model, &iter))
	{
		do
		{
			gtk_tree_model_get (model, &iter,
									  COL_CHANNEL, &chan,
									  COL_USERS, &users,
									  COL_TOPIC, &topic, -1);
			snprintf (buf, sizeof buf, "%-16s %-5d%s\n", chan, users, topic);
			g_free (chan);
			g_free (topic);
			write (fh, buf, strlen (buf));
		}
		while (gtk_tree_model_iter_next (model, &iter));
	}

	close (fh);
}
Exemplo n.º 8
0
void
palette_load (void)
{
	int i, j, l, fh, res;
	char prefname[256];
	struct stat st;
	char *cfg;
	int red, green, blue;
	int upgrade = FALSE;

	fh = xchat_open_file ("colors.conf", O_RDONLY, 0, 0);
	if (fh == -1)
	{
		fh = xchat_open_file ("palette.conf", O_RDONLY, 0, 0);
		upgrade = TRUE;
	}

	if (fh != -1)
	{
		fstat (fh, &st);
		cfg = malloc (st.st_size + 1);
		if (cfg)
		{
			cfg[0] = '\0';
			l = read (fh, cfg, st.st_size);
			if (l >= 0)
				cfg[l] = '\0';

			if (!upgrade)
			{
				/* mIRC colors 0-31 are here */
				for (i = 0; i < 32; i++)
				{
					snprintf (prefname, sizeof prefname, "color_%d", i);
					cfg_get_color (cfg, prefname, &red, &green, &blue);
					colors[i].red = red;
					colors[i].green = green;
					colors[i].blue = blue;
				}

				/* our special colors are mapped at 256+ */
				for (i = 256, j = 32; j < MAX_COL+1; i++, j++)
				{
					snprintf (prefname, sizeof prefname, "color_%d", i);
					cfg_get_color (cfg, prefname, &red, &green, &blue);
					colors[j].red = red;
					colors[j].green = green;
					colors[j].blue = blue;
				}

			} else
			{
				/* loading 2.0.x palette.conf */
				for (i = 0; i < MAX_COL+1; i++)
				{
					snprintf (prefname, sizeof prefname, "color_%d_red", i);
					red = cfg_get_int (cfg, prefname);

					snprintf (prefname, sizeof prefname, "color_%d_grn", i);
					green = cfg_get_int (cfg, prefname);

					snprintf (prefname, sizeof prefname, "color_%d_blu", i);
					blue = cfg_get_int_with_result (cfg, prefname, &res);

					if (res)
					{
						colors[remap[i]].red = red;
						colors[remap[i]].green = green;
						colors[remap[i]].blue = blue;
					}
				}

				/* copy 0-15 to 16-31 */
				for (i = 0; i < 16; i++)
				{
					colors[i+16].red = colors[i].red;
					colors[i+16].green = colors[i].green;
					colors[i+16].blue = colors[i].blue;
				}
			}
			free (cfg);
		}
		close (fh);
	}
}
Exemplo n.º 9
0
Arquivo: fkeys.c Projeto: n2i/xvnkb
static int
key_load_kbs (char *filename)
{
	char *buf, *ibuf;
	struct stat st;
	struct key_binding *kb = NULL, *last = NULL;
	int fd, len, pnt = 0, state = 0, n;

	if (filename == NULL)
		fd = xchat_open_file ("keybindings.conf", O_RDONLY, 0, 0);
	else
		fd = xchat_open_file (filename, O_RDONLY, 0, XOF_FULLPATH);
	if (fd < 0)
		return 1;
	if (fstat (fd, &st) != 0)
		return 1;
	ibuf = malloc (st.st_size);
	read (fd, ibuf, st.st_size);
	close (fd);

	while (buf_get_line (ibuf, &buf, &pnt, st.st_size))
	{
		if (buf[0] == '#')
			continue;
		if (strlen (buf) == 0)
			continue;

		switch (state)
		{
		case KBSTATE_MOD:
			kb = (struct key_binding *) malloc (sizeof (struct key_binding));
			if (key_load_kbs_helper_mod (buf, &kb->mod))
				goto corrupt_file;
			state = KBSTATE_KEY;
			continue;
		case KBSTATE_KEY:
			/* First strip off the fluff */
			while (buf[0] == ' ' || buf[0] == '\t')
				buf++;
			len = strlen (buf);
			while (buf[len] == ' ' || buf[len] == '\t')
			{
				buf[len] = 0;
				len--;
			}

			n = gdk_keyval_from_name (buf);
			if (n == 0)
			{
				/* Unknown keyname, abort */
				if (last)
					last->next = NULL;
				free (ibuf);
				ibuf = malloc (1024);
				snprintf (ibuf, 1024,
							 _("Unknown keyname %s in key bindings config file\nLoad aborted, please fix %s/keybindings.conf\n"),
							 buf, get_xdir_utf8 ());
				fe_message (ibuf, FE_MSG_ERROR);
				free (ibuf);
				return 2;
			}
			kb->keyname = gdk_keyval_name (n);
			kb->keyval = n;

			state = KBSTATE_ACT;
			continue;
		case KBSTATE_ACT:
			/* First strip off the fluff */
			while (buf[0] == ' ' || buf[0] == '\t')
				buf++;
			len = strlen (buf);
			while (buf[len] == ' ' || buf[len] == '\t')
			{
				buf[len] = 0;
				len--;
			}

			for (n = 0; n < KEY_MAX_ACTIONS + 1; n++)
			{
				if (strcmp (key_actions[n].name, buf) == 0)
				{
					kb->action = n;
					break;
				}
			}

			if (n == KEY_MAX_ACTIONS + 1)
			{
				if (last)
					last->next = NULL;
				free (ibuf);
				ibuf = malloc (1024);
				snprintf (ibuf, 1024,
							 _("Unknown action %s in key bindings config file\nLoad aborted, Please fix %s/keybindings\n"),
							 buf, get_xdir_utf8 ());
				fe_message (ibuf, FE_MSG_ERROR);
				free (ibuf);
				return 3;
			}
			state = KBSTATE_DT1;
			continue;
		case KBSTATE_DT1:
		case KBSTATE_DT2:
			if (state == KBSTATE_DT1)
				kb->data1 = kb->data2 = NULL;

			while (buf[0] == ' ' || buf[0] == '\t')
				buf++;

			if (buf[0] != 'D')
			{
				free (ibuf);
				ibuf = malloc (1024);
				snprintf (ibuf, 1024,
							 _("Expecting Data line (beginning Dx{:|!}) but got:\n%s\n\nLoad aborted, Please fix %s/keybindings\n"),
							 buf, get_xdir_utf8 ());
				fe_message (ibuf, FE_MSG_ERROR);
				free (ibuf);
				return 4;
			}
			switch (buf[1])
			{
			case '1':
				if (state != KBSTATE_DT1)
					goto corrupt_file;
				break;
			case '2':
				if (state != KBSTATE_DT2)
					goto corrupt_file;
				break;
			default:
				goto corrupt_file;
			}

			if (buf[2] == ':')
			{
				len = strlen (buf);
				/* Add one for the NULL, subtract 3 for the "Dx:" */
				len++;
				len -= 3;
				if (state == KBSTATE_DT1)
				{
					kb->data1 = malloc (len);
					memcpy (kb->data1, &buf[3], len);
				} else
				{
					kb->data2 = malloc (len);
					memcpy (kb->data2, &buf[3], len);
				}
			} else if (buf[2] == '!')
			{
				if (state == KBSTATE_DT1)
					kb->data1 = NULL;
				else
					kb->data2 = NULL;
			}
			if (state == KBSTATE_DT1)
			{
				state = KBSTATE_DT2;
				continue;
			} else
			{
				if (last)
					last->next = kb;
				else
					keys_root = kb;
				last = kb;

				state = KBSTATE_MOD;
			}

			continue;
		}
	}
	if (last)
		last->next = NULL;
	free (ibuf);
	return 0;

 corrupt_file:
	/*if (getenv ("XCHAT_DEBUG"))
		abort ();*/
	snprintf (ibuf, 1024,
						_("Key bindings config file is corrupt, load aborted\n"
								 "Please fix %s/keybindings.conf\n"),
						 get_xdir_utf8 ());
	fe_message (ibuf, FE_MSG_ERROR);
	free (ibuf);
	return 5;
}
Exemplo n.º 10
0
Arquivo: fkeys.c Projeto: n2i/xvnkb
static void
key_save_kbs (char *fn)
{
	int fd, i;
	char buf[512];
	struct key_binding *kb;

	if (!fn)
		fd = xchat_open_file ("keybindings.conf", O_CREAT | O_TRUNC | O_WRONLY,
									 0x180, XOF_DOMODE);
	else
		fd = xchat_open_file (fn, O_CREAT | O_TRUNC | O_WRONLY,
									 0x180, XOF_DOMODE | XOF_FULLPATH);
	if (fd < 0)
	{
		fe_message (_("Error opening keys config file\n"), FE_MSG_ERROR);
		return;
	}
	write (fd, buf,
			 snprintf (buf, 510, "# ZChat key bindings config file\n\n"));

	kb = keys_root;
	i = 0;

	while (kb)
	{
		if (kb->keyval == -1 || kb->keyname == NULL || kb->action < 0)
		{
			kb = kb->next;
			continue;
		}
		i = 0;
		if (kb->mod & STATE_CTRL)
		{
			i++;
			write (fd, "C", 1);
		}
		if (kb->mod & STATE_ALT)
		{
			i++;
			write (fd, "A", 1);
		}
		if (kb->mod & STATE_SHIFT)
		{
			i++;
			write (fd, "S", 1);
		}
		if (i == 0)
			write (fd, "None\n", 5);
		else
			write (fd, "\n", 1);

		write (fd, buf, snprintf (buf, 510, "%s\n%s\n", kb->keyname,
										  key_actions[kb->action].name));
		if (kb->data1 && kb->data1[0])
			write (fd, buf, snprintf (buf, 510, "D1:%s\n", kb->data1));
		else
			write (fd, "D1!\n", 4);

		if (kb->data2 && kb->data2[0])
			write (fd, buf, snprintf (buf, 510, "D2:%s\n", kb->data2));
		else
			write (fd, "D2!\n", 4);

		write (fd, "\n", 1);

		kb = kb->next;
	}

	close (fd);
}
Exemplo n.º 11
0
static void
editlist_gui_save (GtkWidget * igad)
{
	int fh, i = 0;
	char buf[512];
	char *a, *b;

	fh = xchat_open_file (editlist_file, O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE);
	if (fh != -1)
	{
		while (1)
		{
			if (!gtk_clist_get_text (GTK_CLIST (editlist_gui_list), i, 0, &a))
				break;
			gtk_clist_get_text (GTK_CLIST (editlist_gui_list), i, 1, &b);
			snprintf (buf, sizeof (buf), "NAME %s\nCMD %s\n\n", a, b);
			write (fh, buf, strlen (buf));
			i++;
		}
		close (fh);
		gtk_widget_destroy (editlist_gui_window);
		if (editlist_list == replace_list)
		{
			list_free (&replace_list);
			list_loadconf (editlist_file, &replace_list, 0);
		} else if (editlist_list == popup_list)
		{
			list_free (&popup_list);
			list_loadconf (editlist_file, &popup_list, 0);
		} else if (editlist_list == button_list)
		{
			GSList *list = sess_list;
			struct session *sess;
			list_free (&button_list);
			list_loadconf (editlist_file, &button_list, 0);
			while (list)
			{
				sess = (struct session *) list->data;
				fe_buttons_update (sess);
				list = list->next;
			}
		} else if (editlist_list == dlgbutton_list)
		{
			GSList *list = sess_list;
			struct session *sess;
			list_free (&dlgbutton_list);
			list_loadconf (editlist_file, &dlgbutton_list, 0);
			while (list)
			{
				sess = (struct session *) list->data;
				fe_dlgbuttons_update (sess);
				list = list->next;
			}
		} else if (editlist_list == ctcp_list)
		{
			list_free (&ctcp_list);
			list_loadconf (editlist_file, &ctcp_list, 0);
		} else if (editlist_list == command_list)
		{
			list_free (&command_list);
			list_loadconf (editlist_file, &command_list, 0);
		} else if (editlist_list == usermenu_list)
		{
			list_free (&usermenu_list);
			list_loadconf (editlist_file, &usermenu_list, 0);
			usermenu_update ();
		} else
		{
			list_free (&urlhandler_list);
			list_loadconf (editlist_file, &urlhandler_list, 0);
		}
	}
}
Exemplo n.º 12
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;
		}
	}
}