aboutsummaryrefslogtreecommitdiff
path: root/src/namestore/plugin_gtk_namestore_tlsa.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-06 14:49:26 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-06 14:49:26 +0000
commit21af94a8c53c88a908f4b69ec1d6ce1506c79060 (patch)
treefb389c5a7cfe801101653bd53d1439017fc025d5 /src/namestore/plugin_gtk_namestore_tlsa.c
parent456129b06cf2205ec4630e5926fcb5e66ad5d1d9 (diff)
downloadgnunet-gtk-21af94a8c53c88a908f4b69ec1d6ce1506c79060.tar.gz
gnunet-gtk-21af94a8c53c88a908f4b69ec1d6ce1506c79060.zip
-build srv and tlsa plugins, template for tlsa
Diffstat (limited to 'src/namestore/plugin_gtk_namestore_tlsa.c')
-rw-r--r--src/namestore/plugin_gtk_namestore_tlsa.c308
1 files changed, 308 insertions, 0 deletions
diff --git a/src/namestore/plugin_gtk_namestore_tlsa.c b/src/namestore/plugin_gtk_namestore_tlsa.c
new file mode 100644
index 00000000..a3ba28a4
--- /dev/null
+++ b/src/namestore/plugin_gtk_namestore_tlsa.c
@@ -0,0 +1,308 @@
1/*
2 * This file is part of GNUnet
3 * (C) 2009-2014 Christian Grothoff (and other contributing authors)
4 *
5 * GNUnet is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 3, or (at your
8 * option) any later version.
9 *
10 * GNUnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with GNUnet; see the file COPYING. If not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20/**
21 * @file namestore/plugin_gtk_namestore_tlsa.c
22 * @brief namestore plugin for editing TLSA records
23 * @author Christian Grothoff
24 *
25 * Please note that the code of this plugin (and its XML) is
26 * included in the BOX plugin (and Box XML) as well and thus
27 * particular care needs to be taken when changes are made
28 * to make sure names are consistent across the plugins.
29 */
30#include "gnunet_gtk.h"
31#include "gnunet_gtk_namestore_plugin.h"
32
33
34/**
35 * The user has edited the target value. Enable/disable 'save'
36 * button depending on the validity of the value.
37 *
38 * @param entry editing widget
39 * @param user_data the plugin environment
40 */
41static void
42GNS_edit_dialog_tlsa_target_entry_changed_cb (GtkEditable *entry,
43 gpointer user_data)
44{
45 struct GNUNET_GTK_NAMESTORE_PluginEnvironment *edc = user_data;
46
47 edc->check_validity (edc);
48}
49
50
51#ifndef EDP_CBC_DEF
52#define EDP_CBC_DEF
53/**
54 * The user has changed the protocol selection. Enable/disable 'save'
55 * button depending on the validity of the value.
56 *
57 * @param entry editing widget
58 * @param user_data the plugin environment
59 */
60static void
61edit_dialog_protocol_combobox_changed_cb (GtkEditable *entry,
62 gpointer user_data)
63{
64 struct GNUNET_GTK_NAMESTORE_PluginEnvironment *edc = user_data;
65
66 edc->check_validity (edc);
67}
68#endif
69
70
71/**
72 * Function that will be called to initialize the builder's
73 * widgets from the existing record (if there is one).
74 * The `n_value` is the existing value of the record as a string.
75 *
76 * @param cls the `struct GNUNET_GTK_NAMESTORE_PluginEnvironment *`
77 * @param n_value the record as a string
78 * @param builder the edit dialog's builder
79 */
80static void
81tlsa_load (void *cls,
82 gchar *n_value,
83 GtkBuilder *builder)
84{
85 unsigned int protocol;
86 GtkComboBox *cb;
87 GtkTreeIter iter;
88 unsigned int service;
89 guint service_at_iter;
90 unsigned int priority;
91 unsigned int weight;
92 unsigned int port;
93 unsigned int record_type;
94 char target_name[253 + 1];
95 GtkTreeModel *tm;
96
97 if (7 != SSCANF (n_value,
98 "%u %u %u %d %d %d %253s",
99 &protocol,
100 &service,
101 &record_type,
102 &priority,
103 &weight,
104 &port,
105 target_name))
106 {
107 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
108 _("Unable to parse (boxed) TLSA record `%s'\n"),
109 n_value);
110 return;
111 }
112
113 gtk_spin_button_set_value
114 (GTK_SPIN_BUTTON (gtk_builder_get_object (builder,
115 "edit_dialog_port_spinbutton")),
116 protocol);
117 cb = GTK_COMBO_BOX (gtk_builder_get_object (builder,
118 "edit_dialog_protocol_combobox"));
119 tm = GTK_TREE_MODEL (gtk_builder_get_object (builder,
120 "edit_dialog_protocol_liststore"));
121 if (gtk_tree_model_get_iter_first (tm,
122 &iter))
123 {
124 do
125 {
126 gtk_tree_model_get (tm,
127 &iter,
128 1, &service_at_iter,
129 -1);
130 if (service_at_iter == service)
131 {
132 gtk_combo_box_set_active_iter (cb,
133 &iter);
134 break;
135 }
136 }
137 while (gtk_tree_model_iter_next (tm,
138 &iter));
139 }
140 gtk_spin_button_set_value
141 (GTK_SPIN_BUTTON (gtk_builder_get_object (builder,
142 "edit_dialog_tlsa_priority_spinbutton")),
143 priority);
144 gtk_spin_button_set_value
145 (GTK_SPIN_BUTTON (gtk_builder_get_object (builder,
146 "edit_dialog_tlsa_weight_spinbutton")),
147 weight);
148 gtk_spin_button_set_value
149 (GTK_SPIN_BUTTON (gtk_builder_get_object (builder,
150 "edit_dialog_tlsa_value_port_spinbutton")),
151 port);
152 gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (builder,
153 "edit_dialog_tlsa_target_entry")),
154 target_name);
155}
156
157
158/**
159 * Function that will be called to retrieve the final value of the
160 * record (in string format) once the dialog is being closed.
161 *
162 * @param cls the `struct GNUNET_GTK_NAMESTORE_PluginEnvironment *`
163 * @param builder the edit dialog's builder
164 * @return record value as a string, as specified in the dialog
165 */
166static gchar *
167tlsa_store (void *cls,
168 GtkBuilder *builder)
169{
170 unsigned int protocol;
171 GtkComboBox *cb;
172 GtkTreeIter iter;
173 guint service;
174 unsigned int priority;
175 unsigned int weight;
176 unsigned int port;
177 GtkEntry *entry;
178 const gchar *target;
179 char *result;
180 GtkTreeModel *tm;
181
182 protocol = gtk_spin_button_get_value
183 (GTK_SPIN_BUTTON (gtk_builder_get_object (builder,
184 "edit_dialog_port_spinbutton")));
185 cb = GTK_COMBO_BOX (gtk_builder_get_object (builder,
186 "edit_dialog_protocol_combobox"));
187 if (! gtk_combo_box_get_active_iter (cb,
188 &iter))
189 {
190 GNUNET_break (0);
191 return NULL;
192 }
193 tm = GTK_TREE_MODEL (gtk_builder_get_object (builder,
194 "edit_dialog_protocol_liststore"));
195 gtk_tree_model_get (tm,
196 &iter,
197 1, &service,
198 -1);
199 priority = gtk_spin_button_get_value
200 (GTK_SPIN_BUTTON (gtk_builder_get_object (builder,
201 "edit_dialog_tlsa_priority_spinbutton")));
202 weight = gtk_spin_button_get_value
203 (GTK_SPIN_BUTTON (gtk_builder_get_object (builder,
204 "edit_dialog_tlsa_weight_spinbutton")));
205 port = gtk_spin_button_get_value
206 (GTK_SPIN_BUTTON (gtk_builder_get_object (builder,
207 "edit_dialog_tlsa_value_port_spinbutton")));
208 entry = GTK_ENTRY (gtk_builder_get_object (builder,
209 "edit_dialog_tlsa_target_entry"));
210 target = gtk_entry_get_text (entry);
211
212 GNUNET_asprintf (&result,
213 "%u %u %u %d %d %d %s",
214 protocol,
215 (unsigned int) service,
216 GNUNET_DNSPARSER_TYPE_TLSA,
217 priority,
218 weight,
219 port,
220 target);
221 return result;
222}
223
224
225/**
226 * Function to call to validate the state of the dialog. Should
227 * return #GNUNET_OK if the information in the dialog is valid, and
228 * #GNUNET_SYSERR if some fields contain invalid values. The
229 * function should highlight fields with invalid inputs for the
230 * user.
231 *
232 * @param cls the `struct GNUNET_GTK_NAMESTORE_PluginEnvironment *`
233 * @param builder the edit dialog's builder
234 * @return #GNUNET_OK if there is a valid record value in the dialog
235 */
236static int
237tlsa_validate (void *cls,
238 GtkBuilder *builder)
239{
240 GtkEditable *entry;
241 const gchar *preedit;
242 GtkComboBox *cb;
243 GtkTreeIter iter;
244
245 entry = GTK_EDITABLE (gtk_builder_get_object (builder,
246 "edit_dialog_tlsa_target_entry"));
247 preedit = gtk_editable_get_chars (entry, 0, -1);
248 if ( (NULL == preedit) ||
249 (GNUNET_OK != GNUNET_DNSPARSER_check_name (preedit)) )
250 return GNUNET_SYSERR;
251 cb = GTK_COMBO_BOX (gtk_builder_get_object (builder,
252 "edit_dialog_protocol_combobox"));
253 if (! gtk_combo_box_get_active_iter (cb,
254 &iter))
255 return GNUNET_SYSERR;
256 return GNUNET_OK;
257}
258
259
260/**
261 * Entry point for the plugin.
262 *
263 * @param cls the `struct GNUNET_GTK_NAMESTORE_PluginEnvironment`
264 * @return NULL on error, otherwise the plugin context
265 */
266void *
267libgnunet_plugin_gtk_namestore_tlsa_init (void *cls)
268{
269 struct GNUNET_GTK_NAMESTORE_PluginEnvironment *env = cls;
270 struct GNUNET_GTK_NAMESTORE_PluginFunctions *plugin;
271 static struct GNUNET_GTK_NAMESTORE_Symbol symbols[] = {
272 { "GNS_edit_dialog_tlsa_target_entry_changed_cb",
273 G_CALLBACK (GNS_edit_dialog_tlsa_target_entry_changed_cb) },
274 { "edit_dialog_protocol_combobox_changed_cb",
275 G_CALLBACK (edit_dialog_protocol_combobox_changed_cb) },
276 { NULL, NULL }
277 };
278
279 plugin = GNUNET_new (struct GNUNET_GTK_NAMESTORE_PluginFunctions);
280 plugin->cls = env;
281 plugin->dialog_glade_filename = "gnunet_namestore_edit_tlsa.glade";
282 plugin->dialog_widget_name = "edit_tlsa_dialog";
283 plugin->symbols = symbols;
284 plugin->load = &tlsa_load;
285 plugin->store = &tlsa_store;
286 plugin->validate = &tlsa_validate;
287 /* we will not produce a 'native' TLSA record, but one in a BOX */
288 plugin->record_type = GNUNET_GNSRECORD_TYPE_BOX;
289 return plugin;
290}
291
292
293/**
294 * Exit point from the plugin.
295 *
296 * @param cls the plugin context (as returned by "init")
297 * @return always NULL
298 */
299void *
300libgnunet_plugin_gtk_namestore_tlsa_done (void *cls)
301{
302 struct GNUNET_GTK_NAMESTORE_PluginFunctions *plugin = cls;
303
304 GNUNET_free (plugin);
305 return NULL;
306}
307
308/* end of plugin_gtk_namestore_tlsa.c */