diff options
Diffstat (limited to 'src/namestore/plugin_gtk_namestore_vpn.c')
-rw-r--r-- | src/namestore/plugin_gtk_namestore_vpn.c | 77 |
1 files changed, 73 insertions, 4 deletions
diff --git a/src/namestore/plugin_gtk_namestore_vpn.c b/src/namestore/plugin_gtk_namestore_vpn.c index 622c69e5..7b106fb5 100644 --- a/src/namestore/plugin_gtk_namestore_vpn.c +++ b/src/namestore/plugin_gtk_namestore_vpn.c | |||
@@ -28,6 +28,23 @@ | |||
28 | 28 | ||
29 | 29 | ||
30 | /** | 30 | /** |
31 | * The user has edited the VPN record value. Enable/disable 'save' | ||
32 | * button depending on the validity of the value. | ||
33 | * | ||
34 | * @param entry editing widget | ||
35 | * @param user_data the plugin environment | ||
36 | */ | ||
37 | void | ||
38 | GNS_edit_dialog_vpn_peer_entry_changed_cb (GtkEditable *entry, | ||
39 | gpointer user_data) | ||
40 | { | ||
41 | struct GNUNET_GTK_NAMESTORE_PluginEnvironment *env = user_data; | ||
42 | |||
43 | env->check_validity (env->cls); | ||
44 | } | ||
45 | |||
46 | |||
47 | /** | ||
31 | * Function that will be called to initialize the builder's | 48 | * Function that will be called to initialize the builder's |
32 | * widgets from the existing record (if there is one). | 49 | * widgets from the existing record (if there is one). |
33 | * The `n_value` is the existing value of the record as a string. | 50 | * The `n_value` is the existing value of the record as a string. |
@@ -41,7 +58,31 @@ vpn_load (void *cls, | |||
41 | gchar *n_value, | 58 | gchar *n_value, |
42 | GtkBuilder *builder) | 59 | GtkBuilder *builder) |
43 | { | 60 | { |
44 | GNUNET_break (0); | 61 | char s_peer[103 + 1]; |
62 | char s_serv[253 + 1]; | ||
63 | unsigned int proto; | ||
64 | |||
65 | if (3 != SSCANF (n_value, | ||
66 | "%u %103s %253s", | ||
67 | &proto, s_peer, s_serv)) | ||
68 | { | ||
69 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
70 | _("Unable to parse VPN record string `%s'\n"), | ||
71 | n_value); | ||
72 | return; | ||
73 | } | ||
74 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (builder, | ||
75 | "edit_dialog_vpn_identifier_entry")), | ||
76 | s_serv); | ||
77 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (builder, | ||
78 | "edit_dialog_vpn_peer_entry")), | ||
79 | s_peer); | ||
80 | if (IPPROTO_UDP == proto) | ||
81 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, | ||
82 | "edit_dialog_vpn_protocol_udp_radiobutton")), TRUE); | ||
83 | else | ||
84 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, | ||
85 | "edit_dialog_vpn_protocol_tcp_radiobutton")), TRUE); | ||
45 | } | 86 | } |
46 | 87 | ||
47 | 88 | ||
@@ -57,8 +98,26 @@ static gchar * | |||
57 | vpn_store (void *cls, | 98 | vpn_store (void *cls, |
58 | GtkBuilder *builder) | 99 | GtkBuilder *builder) |
59 | { | 100 | { |
60 | GNUNET_break (0); | 101 | GtkEntry *entry; |
61 | return NULL; | 102 | const gchar *identifier; |
103 | const gchar *peer; | ||
104 | unsigned int proto; | ||
105 | char *result; | ||
106 | |||
107 | entry = GTK_ENTRY (gtk_builder_get_object (builder, | ||
108 | "edit_dialog_vpn_identifier_entry")); | ||
109 | identifier = gtk_entry_get_text (entry); | ||
110 | entry = GTK_ENTRY (gtk_builder_get_object (builder, | ||
111 | "edit_dialog_vpn_peer_entry")); | ||
112 | peer = gtk_entry_get_text (entry); | ||
113 | proto = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (builder, | ||
114 | "edit_dialog_vpn_protocol_tcp_radiobutton"))) ? IPPROTO_TCP : IPPROTO_UDP; | ||
115 | GNUNET_asprintf (&result, | ||
116 | "%u %s %s", | ||
117 | proto, | ||
118 | (const char *) peer, | ||
119 | (const char *) identifier); | ||
120 | return result; | ||
62 | } | 121 | } |
63 | 122 | ||
64 | 123 | ||
@@ -77,7 +136,17 @@ static int | |||
77 | vpn_validate (void *cls, | 136 | vpn_validate (void *cls, |
78 | GtkBuilder *builder) | 137 | GtkBuilder *builder) |
79 | { | 138 | { |
80 | GNUNET_break (0); | 139 | GtkEditable *entry; |
140 | const gchar *preedit; | ||
141 | struct GNUNET_HashCode hc; | ||
142 | |||
143 | entry = GTK_EDITABLE (gtk_builder_get_object (builder, | ||
144 | "edit_dialog_vpn_peer_entry")), | ||
145 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
146 | if ( (NULL == preedit) || | ||
147 | (GNUNET_OK != | ||
148 | GNUNET_CRYPTO_hash_from_string (preedit, &hc)) ) | ||
149 | return GNUNET_SYSERR; | ||
81 | return GNUNET_OK; | 150 | return GNUNET_OK; |
82 | } | 151 | } |
83 | 152 | ||