Hey,
There are some issues with importing .pcf files. First, we're trying to
parse them with GKeyFile which is a bit different from pcf files: The
character for comments is '#' (instead of ';'), section names and key
names are case sensitive (instead of ... well, case insensitive).
The .pcf file also has a format !key which means 'key' and it's not
changeable by user instead of literal !key key.
So here's a patch to implement a simple parser for pcf files.
Additionally, this patch makes the importer use same rules as the UI for
required keys (for example, there's no reason a .pcf file must contain
key 'NTDomain'). As a bonus, it also fixes a memory leak (loaded routes
were never freed).
Tambet
Index: properties/Makefile.am
===
RCS file: /cvs/gnome/NetworkManager/vpn-daemons/vpnc/properties/Makefile.am,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 Makefile.am
--- properties/Makefile.am 27 Sep 2006 15:10:31 - 1.1.2.2
+++ properties/Makefile.am 25 Oct 2006 13:31:54 -
@@ -3,6 +3,8 @@
lib_LTLIBRARIES = libnm-vpnc-properties.la
libnm_vpnc_properties_la_SOURCES = \
+pcf-file.c \
+pcf-file.h \
nm-vpnc.c
gladedir = $(datadir)/gnome-vpn-properties/vpnc
Index: properties/nm-vpnc.c
===
RCS file: /cvs/gnome/NetworkManager/vpn-daemons/vpnc/properties/nm-vpnc.c,v
retrieving revision 1.5.2.2
diff -u -r1.5.2.2 nm-vpnc.c
--- properties/nm-vpnc.c 27 Sep 2006 15:10:32 - 1.5.2.2
+++ properties/nm-vpnc.c 25 Oct 2006 13:31:54 -
@@ -32,6 +32,7 @@
#define NM_VPN_API_SUBJECT_TO_CHANGE
#include nm-vpn-ui-interface.h
+#include pcf-file.h
typedef struct _NetworkManagerVpnUIImpl NetworkManagerVpnUIImpl;
@@ -478,95 +479,85 @@
static gboolean
import_from_file (NetworkManagerVpnUIImpl *impl, const char *path)
{
- char *basename;
- GKeyFile *keyfile;
- gboolean file_is_good;
-
- /*printf (path='%s'\n, path);*/
-
- file_is_good = FALSE;
- basename = g_path_get_basename (path);
-
- keyfile = g_key_file_new ();
- if (g_key_file_load_from_file (keyfile, path, 0, NULL)) {
- char *connectionname = NULL;
- char *gateway = NULL;
- char *groupname = NULL;
- char *username = NULL;
- char *domain = NULL;
- char *tunneling_mode = NULL;
- char *routes = NULL;
- gboolean should_expand;
-
- if ((connectionname = g_key_file_get_string (keyfile, main, Description, NULL)) == NULL)
- goto error;
- if ((gateway = g_key_file_get_string (keyfile, main, Host, NULL)) == NULL)
- goto error;
- if ((groupname = g_key_file_get_string (keyfile, main, GroupName, NULL)) == NULL)
- goto error;
- if ((username = g_key_file_get_string (keyfile, main, Username, NULL)) == NULL)
- goto error;
- if ((domain = g_key_file_get_string (keyfile, main, NTDomain, NULL)) == NULL)
- goto error;
- if ((tunneling_mode = g_key_file_get_string (keyfile, main, TunnelingMode, NULL)) == NULL)
- goto error;
-
- /* may not exist */
- if ((routes = g_key_file_get_string (keyfile, main, X-NM-Routes, NULL)) == NULL)
- routes = g_strdup ();
-
- /* sanity check data */
- if (! (strlen (gateway) 0
- strlen (groupname) 0))
- goto error;
-
- gtk_entry_set_text (impl-w_connection_name, connectionname);
- gtk_entry_set_text (impl-w_gateway, gateway);
- gtk_entry_set_text (impl-w_group_name, groupname);
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl-w_use_alternate_username), strlen (username) 0);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl-w_use_routes), strlen (routes) 0);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (impl-w_use_domain), strlen (domain) 0);
- gtk_entry_set_text (impl-w_username, username);
- gtk_entry_set_text (impl-w_routes, routes);
- gtk_entry_set_text (impl-w_domain, domain);
- gtk_widget_set_sensitive (GTK_WIDGET (impl-w_username), strlen (username) 0);
- gtk_widget_set_sensitive (GTK_WIDGET (impl-w_routes), strlen (routes) 0);
- gtk_widget_set_sensitive (GTK_WIDGET (impl-w_domain), strlen (username) 0);
+ GHashTable *pcf;
+ const char *buf;
+ gboolean have_value;
+ char *basename = NULL;
+ gboolean expand = FALSE;
+ gboolean success = FALSE;
+
+ pcf = pcf_file_load (path);
+ if (pcf == NULL)
+ return FALSE;
+
+ /* Connection name */
+ if ((buf = pcf_file_lookup_value (pcf, main, Description)) == NULL || strlen (buf) 1)
+ goto error;
+ gtk_entry_set_text (impl-w_connection_name, buf);
+
+ /* Gateway */
+ if ((buf = pcf_file_lookup_value (pcf, main, Host)) == NULL || strlen (buf) 1)
+ goto error;
+ gtk_entry_set_text (impl-w_gateway, buf);
+
+ /* Group name */
+ if ((buf = pcf_file_lookup_value (pcf, main, GroupName)) == NULL || strlen (buf) 1)
+ goto error;
+ gtk_entry_set_text (impl-w_group_name, buf);
+
+ /* Optional settings */
+
+ if ((buf = pcf_file_lookup_value (pcf, main, UserName)))
+ gtk_entry_set_text (impl-w_username, buf);
+ have_value = buf == NULL ? FALSE : strlen (buf) 0;
+ expand |=