Exemple #1
0
static char * _path_lookup(CppParser * cp, char const * path, int system)
{
	Cpp * cpp = cp->cpp;
	char const * filename;
	char * p;
	char * q;
	char * r;
	struct stat st;

	if(system != 0)
		return cpp_path_lookup(cpp, path, 1);
	for(; cp->subparser != NULL; cp = cp->subparser);
	for(; cp != NULL; cp = cp->parent)
	{
		filename = parser_get_filename(cp->parser);
		if((p = string_new(filename)) == NULL)
			return NULL;
		q = dirname(p);
		r = string_new_append(q, "/", path, NULL);
		string_delete(p);
		if(r == NULL)
			return NULL;
#ifdef DEBUG
		fprintf(stderr, "DEBUG: stat(\"%s\", %p)\n", r, (void *)&st);
#endif
		if(stat(r, &st) == 0)
			return r;
		error_set("%s: %s", r, strerror(errno));
		string_delete(r);
	}
	return cpp_path_lookup(cpp, path, 0);
}
Exemple #2
0
/* cpp_callback_directive */
static int _cpp_callback_directive(Parser * parser, Token * token, int c,
		void * data)
{
	CppParser * cpp = data;
	char * str;
	size_t i;

	if(cpp->directive_control != 1 || cpp->queue_code != CPP_CODE_NULL
			|| !_cpp_isword(c))
		return 1;
	DEBUG_CALLBACK();
	if((str = _cpp_parse_word(parser, c)) == NULL)
		return -1;
	for(i = 0; _cpp_directives[i] != NULL; i++)
		if(strcmp(str, _cpp_directives[i]) == 0)
			break;
	if(_cpp_directives[i] != NULL)
	{
		cpp->queue_code = CPP_CODE_META_FIRST + i;
		cpp->queue_string = NULL;
	}
	else
	{
		cpp->queue_code = CPP_CODE_META_ERROR;
		cpp->queue_string = string_new_append("Invalid directive: #",
				str, ":", NULL); /* XXX check for errors */
	}
	token_set_code(token, CPP_CODE_META_DATA);
	token_set_string(token, str);
	free(str);
	return 0;
}
Exemple #3
0
static int _init_server(OpenSSL * openssl, char const * name)
{
	String * crt;
	struct sockaddr_in sa;

	if((crt = string_new_append(SYSCONFDIR, "/AppServer/", name, ".crt"))
			== NULL)
		return -1;
	if((openssl->ssl_ctx = SSL_CTX_new(SSLv3_server_method())) == NULL
			|| SSL_CTX_set_cipher_list(openssl->ssl_ctx,
				SSL_DEFAULT_CIPHER_LIST) != 1
			|| SSL_CTX_use_certificate_file(openssl->ssl_ctx, crt,
				SSL_FILETYPE_PEM) == 0
			|| SSL_CTX_use_PrivateKey_file(openssl->ssl_ctx, crt,
				SSL_FILETYPE_PEM) == 0)
	{
		string_delete(crt);
		return -_openssl_error_ssl(1);
	}
	string_delete(crt);
	if((openssl->fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
		return -_openssl_error("socket", 1);
	sa.sin_family = AF_INET;
	sa.sin_port = htons(4242); /* XXX hard-coded */
	sa.sin_addr.s_addr = htonl(INADDR_ANY);
	if(bind(openssl->fd, (struct sockaddr *)&sa, sizeof(sa)) != 0)
		return -_openssl_error("bind", 1);
	if(listen(openssl->fd, 5) != 0)
		return -_openssl_error("listen", 1);
	event_register_io_read(openssl->helper->event, openssl->fd,
			(EventIOFunc)_openssl_callback_accept, openssl);
	return 0;
}
Exemple #4
0
static void _on_add_filename(gchar const * pathname, gpointer data)
{
	const char scheme[] = "file://";
	Favorites * favorites = data;
	GtkTreeIter iter;
	struct stat st;
	gchar * filename;
	String * path;
	gint size = 24;
	GdkPixbuf * pixbuf;

	/* XXX ignore non-directories */
	if(browser_vfs_stat(pathname, &st) != 0 || !S_ISDIR(st.st_mode))
		return;
	if((filename = g_path_get_basename(pathname)) == NULL)
		return;
	if((path = string_new_append(scheme, pathname, NULL)) == NULL)
		return;
	gtk_icon_size_lookup(GTK_ICON_SIZE_BUTTON, &size, &size);
	if((pixbuf = browser_vfs_mime_icon(favorites->mime, pathname, NULL,
					NULL, &st, size)) == NULL)
		pixbuf = favorites->folder;
#if GTK_CHECK_VERSION(2, 6, 0)
	gtk_list_store_insert_with_values(favorites->store, &iter, -1,
#else
	gtk_list_store_append(favorites->store, &iter);
	gtk_list_store_set(favorites->store, &iter,
#endif
			FC_ICON, pixbuf, FC_NAME, filename, FC_PATH, path, -1);
	string_delete(path);
	g_free(filename);
	_favorites_save(favorites);
}
Exemple #5
0
/* config_get_filename */
static char * _config_get_filename(void)
{
	String const * homedir;

	if((homedir = getenv("HOME")) == NULL)
		homedir = g_get_home_dir();
	return string_new_append(homedir, "/", PANEL_CONFIG_FILE, NULL);
}
Exemple #6
0
/* camera_get_config_filename */
static String * _camera_get_config_filename(Camera * camera, char const * name)
{
	char const * homedir;

	if((homedir = getenv("HOME")) == NULL)
		homedir = g_get_home_dir();
	return string_new_append(homedir, "/", name, NULL);
}
Exemple #7
0
/* modem_helper_config_get */
static char const * _modem_helper_config_get(Modem * modem,
		char const * variable)
{
	char const * ret;
	String * s;

	if((s = string_new_append("modem::", modem->name, NULL)) == NULL)
		return NULL;
	ret = config_get(modem->config, s, variable);
	string_delete(s);
	return ret;
}
Exemple #8
0
/* modem_helper_config_set */
static int _modem_helper_config_set(Modem * modem, char const * variable,
		char const * value)
{
	int ret;
	String * s;

	if((s = string_new_append("modem::", modem->name, NULL)) == NULL)
		return -1;
	ret = config_set(modem->config, s, variable, value);
	string_delete(s);
	return ret;
}
Exemple #9
0
static int _settings_browse_folder_access_path(char const * path,
		char const * filename, int mode)
{
	int ret;
	String * p;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(\"%s\", \"%s\", %d)\n", __func__, path,
			filename, mode);
#endif
	if((p = string_new_append(path, "/", filename, NULL)) == NULL)
		return -1;
	ret = access(p, mode);
	string_delete(p);
	return ret;
}
Exemple #10
0
/* compose_config */
static Config * _compose_config(void)
{
	Config * config;
	char const * homedir;
	String * filename;

	if((config = config_new()) == NULL)
		return NULL;
	if((homedir = getenv("HOME")) == NULL)
		homedir = g_get_home_dir();
	if((filename = string_new_append(homedir, "/" MAILER_CONFIG_FILE, NULL))
			!= NULL)
	{
		config_load(config, filename);
		string_delete(filename);
	}
	return config;
}
Exemple #11
0
/* panel_helper_config_get */
static char const * _panel_helper_config_get(Panel * panel,
		char const * section, char const * variable)
{
	char const * ret;
	String * s = NULL;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(\"%s\", \"%s\")\n", __func__, section,
			variable);
#endif
	if(section != NULL)
	{
		if((s = string_new_append("applet::", section, NULL)) == NULL)
			return NULL;
		section = s;
	}
	ret = panel_get_config(panel, section, variable);
	string_delete(s);
	return ret;
}
Exemple #12
0
static int _settings_browse_home(Settings * settings, Config * config)
{
	int ret;
	char const fallback[] = ".local/share";
	char const * path;
	char const * homedir;
	String * p;

	/* use $XDG_DATA_HOME if set and not empty */
	if((path = getenv("XDG_DATA_HOME")) != NULL && strlen(path) > 0)
		return _settings_browse_folder(settings, config, path);
	/* fallback to "$HOME/.local/share" */
	if((homedir = getenv("HOME")) == NULL)
		homedir = g_get_home_dir();
	if((p = string_new_append(homedir, "/", fallback, NULL)) == NULL)
		return -_settings_error(error_get(NULL), 1);
	ret = _settings_browse_folder(settings, config, p);
	free(p);
	return ret;
}
Exemple #13
0
/* compose_append_signature */
void compose_append_signature(Compose * compose)
{
	const char signature[] = "/.signature";
	const char prefix[] = "\n-- \n";
	char const * homedir;
	char * filename;
	gboolean res;
	gchar * buf;

	if((homedir = getenv("HOME")) == NULL)
		homedir = g_get_home_dir();
	if((filename = string_new_append(homedir, signature, NULL)) == NULL)
		return;
	res = g_file_get_contents(filename, &buf, NULL, NULL);
	string_delete(filename);
	if(res != TRUE)
		return;
	compose_append_text(compose, prefix);
	compose_append_text(compose, buf);
	g_free(buf);
}
Exemple #14
0
/* panel_helper_config_set */
static int _panel_helper_config_set(Panel * panel, char const * section,
		char const * variable, char const * value)
{
	int ret;
	String * s = NULL;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(\"%s\", \"%s\", \"%s\")\n", __func__,
			section, variable, value);
#endif
	if(section != NULL)
	{
		if((s = string_new_append("applet::", section, NULL)) == NULL)
			return -1;
		section = s;
	}
	/* FIXME save the configuration (if not in test mode) */
	ret = config_set(panel->config, section, variable, value);
	string_delete(s);
	return ret;
}
Exemple #15
0
static int _settings_browse_folder(Settings * settings, Config * config,
		char const * folder)
{
	const char ext[8] = ".desktop";
	const char section[] = "Desktop Entry";
	const char application[] = "Application";
	const int flags = GTK_ICON_LOOKUP_FORCE_SIZE;
	const gint iconsize = 48;
	GtkIconTheme * theme;
	GtkTreeModel * model;
	GtkListStore * store;
	DIR * dir;
	struct dirent * de;
	size_t len;
	String * path;
	int res;
	String const * name;
	String const * icon;
	String const * exec;
	String const * p;
	GdkPixbuf * pixbuf;
	GtkTreeIter iter;
	GError * error = NULL;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, folder);
#endif
	if((path = string_new_append(folder, "/applications", NULL)) == NULL)
		return -_settings_error(error_get(NULL), 1);
	dir = opendir(path);
	string_delete(path);
	if(dir == NULL)
		return -_settings_error(strerror(errno), 1);
	theme = gtk_icon_theme_get_default();
	model = _settings_get_model(settings);
	store = GTK_LIST_STORE(model);
	while((de = readdir(dir)) != NULL)
	{
		if((len = strlen(de->d_name)) <= sizeof(ext))
			continue;
		if(strncmp(&de->d_name[len - sizeof(ext)], ext, sizeof(ext))
				!= 0)
			continue;
		if((path = string_new_append(folder, "/applications/",
						de->d_name, NULL)) == NULL)
		{
			_settings_error(error_get(NULL), 1);
			continue;
		}
#ifdef DEBUG
		fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__, path);
#endif
		config_reset(config);
		res = config_load(config, path);
		string_delete(path);
		if(res != 0)
		{
			_settings_error(error_get(NULL), 1);
			continue;
		}
		p = config_get(config, section, "Type");
		name = config_get(config, section, "Name");
		exec = config_get(config, section, "Exec");
		if(p == NULL || name == NULL || exec == NULL
				|| strcmp(exec, PROGNAME) == 0)
			continue;
		if(strcmp(p, application) != 0)
			continue;
		if((p = config_get(config, section, "Categories")) == NULL
				|| string_find(p, "Settings") == NULL)
			continue;
		if((p = config_get(config, section, "TryExec")) != NULL
				&& _settings_browse_folder_access(path, X_OK)
				!= 0 && errno == ENOENT)
				continue;
		if((icon = config_get(config, section, "Icon")) == NULL)
			icon = GTK_STOCK_PREFERENCES;
#ifdef DEBUG
		fprintf(stderr, "DEBUG: %s() \"%s\" %s\n", __func__, name,
				icon);
#endif
		if((pixbuf = gtk_icon_theme_load_icon(theme, icon, iconsize,
						flags, &error)) == NULL)
		{
			_settings_error(error->message, 0);
			g_error_free(error);
			error = NULL;
		}
#if GTK_CHECK_VERSION(2, 6, 0)
		gtk_list_store_insert_with_values(store, &iter, -1,
#else
		gtk_list_store_append(store, &iter);
		gtk_list_store_set(store, &iter,
#endif
				SC_ICON, pixbuf, SC_NAME, name, SC_EXEC, exec,
				/* FIXME detect privileged settings */
				SC_PRIVILEGED, FALSE, -1);
	}
	closedir(dir);
	return FALSE;
}
Exemple #16
0
/* desktopicon_new_application */
DesktopIcon * desktopicon_new_application(Desktop * desktop, char const * path)
{
	DesktopIcon * desktopicon;
	Config * config;
	const char section[] = "Desktop Entry";
	char const * p;
	char const * icon;
	char * exec = NULL;
	char * tryexec = NULL;
	size_t len;
	String * buf;
	GError * error = NULL;
	GdkPixbuf * image = NULL;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(%p, \"%s\")\n", __func__, (void *)desktop,
			path);
#endif
	if((config = config_new()) == NULL || config_load(config, path) != 0)
	{
		if(config != NULL)
			config_delete(config);
		return NULL;
	}
	if((p = config_get(config, section, "Exec")) != NULL)
		exec = strdup(p);
	if((p = config_get(config, section, "TryExec")) != NULL)
		tryexec = strdup(p);
	if(exec == NULL || (p = config_get(config, section, "Name")) == NULL
			|| (icon = config_get(config, section, "Icon")) == NULL)
	{
		free(exec);
		free(tryexec);
		config_delete(config);
		return NULL;
	}
	/* image */
	if((len = strlen(icon)) > 4 && (strcmp(&icon[len - 4], ".png") == 0
				|| strcmp(&icon[len - 4], ".xpm") == 0)
			&& (buf = string_new_append(PREFIX, "/share/pixmaps/",
					icon, NULL)) != NULL)
	{
		image = gdk_pixbuf_new_from_file_at_size(buf,
				DESKTOPICON_ICON_SIZE, DESKTOPICON_ICON_SIZE,
				&error);
		string_delete(buf);
	}
	if(image == NULL)
		image = gtk_icon_theme_load_icon(desktop_get_theme(desktop),
				icon, DESKTOPICON_ICON_SIZE, 0, NULL);
	if(image == NULL)
		image = desktop_get_file(desktop);
	desktopicon = _desktopicon_new_do(desktop, image, p);
	config_delete(config); /* XXX also remove reference to the pixbuf */
	if(desktopicon == NULL)
	{
		free(exec);
		free(tryexec);
		return NULL;
	}
	desktopicon->exec = exec;
	desktopicon->tryexec = tryexec;
	desktopicon_set_confirm(desktopicon, FALSE);
	desktopicon_set_executable(desktopicon, TRUE);
	desktopicon_set_immutable(desktopicon, TRUE);
	return desktopicon;
}
Exemple #17
0
static void _on_icon_rename(gpointer data)
{
	DesktopIcon * desktopicon = data;
	GtkWidget * dialog;
	GtkSizeGroup * group;
	GtkWidget * vbox;
	GtkWidget * hbox;
	GtkWidget * widget;
	int res;
	char * p;
	char * q;
	char * r;

	dialog = gtk_dialog_new_with_buttons(_("Rename"), NULL, 0,
			GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, _("Rename"),
			GTK_RESPONSE_ACCEPT, NULL);
#if GTK_CHECK_VERSION(2, 14, 0)
	vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
#else
	vbox = GTK_DIALOG(dialog)->vbox;
#endif
	group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
	hbox = gtk_hbox_new(FALSE, 4);
	widget = gtk_label_new(_("Rename: "));
	gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
	gtk_size_group_add_widget(group, widget);
	gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
	widget = gtk_entry_new();
	gtk_editable_set_editable(GTK_EDITABLE(widget), FALSE);
	gtk_entry_set_text(GTK_ENTRY(widget), desktopicon->name);
	gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
	/* entry */
	hbox = gtk_hbox_new(FALSE, 4);
	widget = gtk_label_new(_("To: "));
	gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
	gtk_size_group_add_widget(group, widget);
	gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
	widget = gtk_entry_new();
	gtk_entry_set_text(GTK_ENTRY(widget), desktopicon->name);
	gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
	gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
	gtk_widget_show_all(vbox);
	res = gtk_dialog_run(GTK_DIALOG(dialog));
	gtk_widget_hide(dialog);
	if(res != GTK_RESPONSE_ACCEPT)
	{
		gtk_widget_destroy(dialog);
		return;
	}
	/* FIXME check errors */
	p = string_new(desktopicon->path);
	q = string_new(gtk_entry_get_text(GTK_ENTRY(widget)));
	/* FIXME convert entry from UTF-8 to filesystem's charset */
	if(q[0] == '/')
		r = string_new(q);
	else
		r = string_new_append(dirname(p), "/", q, NULL);
#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s() rename(\"%s\", \"%s\")\n", __func__,
			desktopicon->path, r);
#else
	if(rename(desktopicon->path, r) != 0)
		desktop_error(desktopicon->desktop, r, 1);
#endif
	string_delete(p);
	string_delete(q);
	string_delete(r);
	gtk_widget_destroy(dialog);
}