aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent456129b06cf2205ec4630e5926fcb5e66ad5d1d9 (diff)
downloadgnunet-gtk-21af94a8c53c88a908f4b69ec1d6ce1506c79060.tar.gz
gnunet-gtk-21af94a8c53c88a908f4b69ec1d6ce1506c79060.zip
-build srv and tlsa plugins, template for tlsa
Diffstat (limited to 'src')
-rw-r--r--src/namestore/Makefile.am38
-rw-r--r--src/namestore/plugin_gtk_namestore_box.c10
-rw-r--r--src/namestore/plugin_gtk_namestore_tlsa.c308
3 files changed, 334 insertions, 22 deletions
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index c582bc68..cd329e0e 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -49,11 +49,11 @@ plugin_LTLIBRARIES = \
49 libgnunet_plugin_gtk_namestore_pkey.la \ 49 libgnunet_plugin_gtk_namestore_pkey.la \
50 libgnunet_plugin_gtk_namestore_ptr.la \ 50 libgnunet_plugin_gtk_namestore_ptr.la \
51 libgnunet_plugin_gtk_namestore_soa.la \ 51 libgnunet_plugin_gtk_namestore_soa.la \
52 libgnunet_plugin_gtk_namestore_srv.la \
53 libgnunet_plugin_gtk_namestore_tlsa.la \
52 libgnunet_plugin_gtk_namestore_txt.la \ 54 libgnunet_plugin_gtk_namestore_txt.la \
53 libgnunet_plugin_gtk_namestore_vpn.la 55 libgnunet_plugin_gtk_namestore_vpn.la
54 56
55# libgnunet_plugin_gtk_namestore_srv.la
56
57 57
58libgnunet_plugin_gtk_namestore_a_la_SOURCES = \ 58libgnunet_plugin_gtk_namestore_a_la_SOURCES = \
59 plugin_gtk_namestore_a.c 59 plugin_gtk_namestore_a.c
@@ -194,17 +194,29 @@ libgnunet_plugin_gtk_namestore_soa_la_LIBADD = \
194libgnunet_plugin_gtk_namestore_soa_la_LDFLAGS = \ 194libgnunet_plugin_gtk_namestore_soa_la_LDFLAGS = \
195 $(GN_PLUGIN_LDFLAGS) 195 $(GN_PLUGIN_LDFLAGS)
196 196
197#libgnunet_plugin_gtk_namestore_srv_la_SOURCES = \ 197libgnunet_plugin_gtk_namestore_srv_la_SOURCES = \
198# plugin_gtk_namestore_srv.c 198 plugin_gtk_namestore_srv.c
199#libgnunet_plugin_gtk_namestore_srv_la_CFLAGS = \ 199libgnunet_plugin_gtk_namestore_srv_la_CFLAGS = \
200# @GTK_CFLAGS@ \ 200 @GTK_CFLAGS@ \
201# @GNUNET_CFLAGS@ \ 201 @GNUNET_CFLAGS@ \
202# @GLADE_CFLAGS@ 202 @GLADE_CFLAGS@
203#libgnunet_plugin_gtk_namestore_srv_la_LIBADD = \ 203libgnunet_plugin_gtk_namestore_srv_la_LIBADD = \
204# @GNUNET_LIBS@ \ 204 @GNUNET_LIBS@ \
205# -lgnunetutil 205 -lgnunetutil
206#libgnunet_plugin_gtk_namestore_srv_la_LDFLAGS = \ 206libgnunet_plugin_gtk_namestore_srv_la_LDFLAGS = \
207# $(GN_PLUGIN_LDFLAGS) 207 $(GN_PLUGIN_LDFLAGS)
208
209libgnunet_plugin_gtk_namestore_tlsa_la_SOURCES = \
210 plugin_gtk_namestore_tlsa.c
211libgnunet_plugin_gtk_namestore_tlsa_la_CFLAGS = \
212 @GTK_CFLAGS@ \
213 @GNUNET_CFLAGS@ \
214 @GLADE_CFLAGS@
215libgnunet_plugin_gtk_namestore_tlsa_la_LIBADD = \
216 @GNUNET_LIBS@ \
217 -lgnunetutil
218libgnunet_plugin_gtk_namestore_tlsa_la_LDFLAGS = \
219 $(GN_PLUGIN_LDFLAGS)
208 220
209libgnunet_plugin_gtk_namestore_txt_la_SOURCES = \ 221libgnunet_plugin_gtk_namestore_txt_la_SOURCES = \
210 plugin_gtk_namestore_txt.c 222 plugin_gtk_namestore_txt.c
diff --git a/src/namestore/plugin_gtk_namestore_box.c b/src/namestore/plugin_gtk_namestore_box.c
index f973c325..20c0efbd 100644
--- a/src/namestore/plugin_gtk_namestore_box.c
+++ b/src/namestore/plugin_gtk_namestore_box.c
@@ -56,6 +56,7 @@ edit_dialog_protocol_combobox_changed_cb (GtkEditable *entry,
56 56
57/* We simply include the code for boxed plugins directly here */ 57/* We simply include the code for boxed plugins directly here */
58#include "plugin_gtk_namestore_srv.c" 58#include "plugin_gtk_namestore_srv.c"
59#include "plugin_gtk_namestore_tlsa.c"
59 60
60 61
61/** 62/**
@@ -122,12 +123,9 @@ box_load (void *cls,
122 case GNUNET_DNSPARSER_TYPE_TLSA: 123 case GNUNET_DNSPARSER_TYPE_TLSA:
123 gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (builder, 124 gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (builder,
124 "edit_dialog_tlsa_frame"))); 125 "edit_dialog_tlsa_frame")));
125#if 0
126 /* FIXME: not implemented */
127 tlsa_load (bc->env, 126 tlsa_load (bc->env,
128 n_value, 127 n_value,
129 builder); 128 builder);
130#endif
131 break; 129 break;
132 default: 130 default:
133 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 131 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -158,11 +156,8 @@ box_store (void *cls,
158 return srv_store (bc->env, 156 return srv_store (bc->env,
159 builder); 157 builder);
160 case GNUNET_DNSPARSER_TYPE_TLSA: 158 case GNUNET_DNSPARSER_TYPE_TLSA:
161#if 0
162 /* FIXME: not implemented */
163 return tlsa_store (bc->env, 159 return tlsa_store (bc->env,
164 builder); 160 builder);
165#endif
166 default: 161 default:
167 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 162 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
168 _("Boxed record type %u not supported\n"), 163 _("Boxed record type %u not supported\n"),
@@ -195,11 +190,8 @@ box_validate (void *cls,
195 return srv_validate (bc->env, 190 return srv_validate (bc->env,
196 builder); 191 builder);
197 case GNUNET_DNSPARSER_TYPE_TLSA: 192 case GNUNET_DNSPARSER_TYPE_TLSA:
198#if 0
199 /* FIXME: not implemented */
200 return tlsa_validate (bc->env, 193 return tlsa_validate (bc->env,
201 builder); 194 builder);
202#endif
203 default: 195 default:
204 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
205 _("Boxed record type %u not supported\n"), 197 _("Boxed record type %u not supported\n"),
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 */