diff options
Diffstat (limited to 'src/namestore/gnunet-namestore-gtk_edit.c')
-rw-r--r-- | src/namestore/gnunet-namestore-gtk_edit.c | 1965 |
1 files changed, 8 insertions, 1957 deletions
diff --git a/src/namestore/gnunet-namestore-gtk_edit.c b/src/namestore/gnunet-namestore-gtk_edit.c index 7fe0d27b..790f591b 100644 --- a/src/namestore/gnunet-namestore-gtk_edit.c +++ b/src/namestore/gnunet-namestore-gtk_edit.c | |||
@@ -20,78 +20,24 @@ | |||
20 | /** | 20 | /** |
21 | * @file src/namestore/gnunet-namestore-gtk_edit.c | 21 | * @file src/namestore/gnunet-namestore-gtk_edit.c |
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
23 | * @brief editing dialogs for GNS records | 23 | * @brief common functions for editing dialogs for GNS records |
24 | */ | 24 | */ |
25 | #include "gnunet-namestore-gtk_edit.h" | 25 | #include "gnunet_gtk.h" |
26 | #include <gnunet/gnunet_gns_service.h> | 26 | #include <gnunet/gnunet_gns_service.h> |
27 | 27 | #include "gnunet_gtk_namestore_plugin.h" | |
28 | |||
29 | /** | ||
30 | * Disable 'save' button, dialog state is not acceptable. | ||
31 | * | ||
32 | * @param edc dialog to modify | ||
33 | */ | ||
34 | static void | ||
35 | edit_dialog_disable_save (struct EditDialogContext *edc) | ||
36 | { | ||
37 | gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (edc->builder, | ||
38 | "edit_dialog_save_button")), | ||
39 | FALSE); | ||
40 | } | ||
41 | |||
42 | |||
43 | /** | ||
44 | * Enable 'save' button, dialog state is acceptable. | ||
45 | * | ||
46 | * @param edc dialog to modify | ||
47 | */ | ||
48 | static void | ||
49 | edit_dialog_enable_save (struct EditDialogContext *edc) | ||
50 | { | ||
51 | gtk_widget_set_sensitive (GTK_WIDGET (gtk_builder_get_object (edc->builder, | ||
52 | "edit_dialog_save_button")), | ||
53 | TRUE); | ||
54 | } | ||
55 | |||
56 | |||
57 | /** | ||
58 | * Check that the common elements of the edit dialog are valid; | ||
59 | * if so, call 'edit_dialog_enable_save', otherwise 'edit_dialog_disable_save'. | ||
60 | * | ||
61 | * @param edc edit dialog to check | ||
62 | */ | ||
63 | static void | ||
64 | edit_dialog_check_save (struct EditDialogContext *edc) | ||
65 | { | ||
66 | GtkEditable *entry; | ||
67 | const gchar *name; | ||
68 | |||
69 | /* check name */ | ||
70 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
71 | "edit_dialog_name_entry")); | ||
72 | name = gtk_editable_get_chars (entry, 0, -1); | ||
73 | if ( (GNUNET_SYSERR == GNUNET_DNSPARSER_check_label (name)) && | ||
74 | (0 != strcmp (name, GNUNET_GNS_MASTERZONE_STR)) ) | ||
75 | { | ||
76 | edit_dialog_disable_save (edc); | ||
77 | return; | ||
78 | } | ||
79 | /* any other checks should go here */ | ||
80 | edit_dialog_enable_save (edc); | ||
81 | } | ||
82 | 28 | ||
83 | 29 | ||
84 | /** | 30 | /** |
85 | * The 'relative' expiration time radiobutton was toggled (on or off). | 31 | * The 'relative' expiration time radiobutton was toggled (on or off). |
86 | * | 32 | * |
87 | * @param button the button | 33 | * @param button the button |
88 | * @param user_data the 'struct EditDialogContext' of the dialog | 34 | * @param user_data the '' of the dialog |
89 | */ | 35 | */ |
90 | void | 36 | void |
91 | GNS_edit_dialog_expiration_relative_radiobutton_toggled_cb (GtkToggleButton *button, | 37 | GNS_edit_dialog_expiration_relative_radiobutton_toggled_cb (GtkToggleButton *button, |
92 | gpointer user_data) | 38 | gpointer user_data) |
93 | { | 39 | { |
94 | struct EditDialogContext *edc = user_data; | 40 | struct GNUNET_GTK_NAMESTORE_PluginEnvironment *edc = user_data; |
95 | 41 | ||
96 | if (gtk_toggle_button_get_active (button)) | 42 | if (gtk_toggle_button_get_active (button)) |
97 | gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (edc->builder, | 43 | gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (edc->builder, |
@@ -106,7 +52,7 @@ GNS_edit_dialog_expiration_relative_radiobutton_toggled_cb (GtkToggleButton *but | |||
106 | * The 'forever' expiration time radiobutton was toggled (on or off). | 52 | * The 'forever' expiration time radiobutton was toggled (on or off). |
107 | * | 53 | * |
108 | * @param button the button | 54 | * @param button the button |
109 | * @param user_data the 'struct EditDialogContext' of the dialog | 55 | * @param user_data the '' of the dialog |
110 | */ | 56 | */ |
111 | void | 57 | void |
112 | GNS_edit_dialog_expiration_forever_radiobutton_toggled_cb (GtkToggleButton *button, | 58 | GNS_edit_dialog_expiration_forever_radiobutton_toggled_cb (GtkToggleButton *button, |
@@ -120,13 +66,13 @@ GNS_edit_dialog_expiration_forever_radiobutton_toggled_cb (GtkToggleButton *butt | |||
120 | * The 'absolute' expiration time radiobutton was toggled (on or off). | 66 | * The 'absolute' expiration time radiobutton was toggled (on or off). |
121 | * | 67 | * |
122 | * @param button the button | 68 | * @param button the button |
123 | * @param user_data the 'struct EditDialogContext' of the dialog | 69 | * @param user_data the '' of the dialog |
124 | */ | 70 | */ |
125 | void | 71 | void |
126 | GNS_edit_dialog_expiration_absolute_radiobutton_toggled_cb (GtkToggleButton *button, | 72 | GNS_edit_dialog_expiration_absolute_radiobutton_toggled_cb (GtkToggleButton *button, |
127 | gpointer user_data) | 73 | gpointer user_data) |
128 | { | 74 | { |
129 | struct EditDialogContext *edc = user_data; | 75 | struct GNUNET_GTK_NAMESTORE_PluginEnvironment *edc = user_data; |
130 | 76 | ||
131 | if (gtk_toggle_button_get_active (button)) | 77 | if (gtk_toggle_button_get_active (button)) |
132 | { | 78 | { |
@@ -145,1900 +91,5 @@ GNS_edit_dialog_expiration_absolute_radiobutton_toggled_cb (GtkToggleButton *but | |||
145 | } | 91 | } |
146 | 92 | ||
147 | 93 | ||
148 | /** | ||
149 | * Setup the zone combobox. | ||
150 | * | ||
151 | * @param edc dialog to setup the combo box for | ||
152 | */ | ||
153 | static void | ||
154 | setup_zone (struct EditDialogContext *edc) | ||
155 | { | ||
156 | GtkTreeIter iter; | ||
157 | GtkComboBox *cb; | ||
158 | gchar *name; | ||
159 | |||
160 | cb = GTK_COMBO_BOX (gtk_builder_get_object (edc->builder, | ||
161 | "edit_dialog_zone_combobox")); | ||
162 | |||
163 | gtk_combo_box_set_model (cb, | ||
164 | GTK_TREE_MODEL (edc->zone_liststore)); | ||
165 | GNUNET_assert (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (edc->zone_liststore), | ||
166 | &iter)); | ||
167 | do { | ||
168 | gtk_tree_model_get (GTK_TREE_MODEL (edc->zone_liststore), | ||
169 | &iter, | ||
170 | ZONE_LS_NAME, &name, | ||
171 | -1); | ||
172 | if (0 == strcmp (name, | ||
173 | edc->new_zone_option)) | ||
174 | { | ||
175 | g_free (name); | ||
176 | break; | ||
177 | } | ||
178 | g_free (name); | ||
179 | } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (edc->zone_liststore), | ||
180 | &iter)); | ||
181 | gtk_combo_box_set_active_iter (cb, | ||
182 | &iter); | ||
183 | } | ||
184 | |||
185 | |||
186 | /** | ||
187 | * Initialize widgets of the edit dialog that are the same regardless of | ||
188 | * the type of the record. | ||
189 | * | ||
190 | * @param edc dialog context | ||
191 | */ | ||
192 | static void | ||
193 | edit_dialog_setup_common_elements (struct EditDialogContext *edc) | ||
194 | { | ||
195 | GtkComboBox *cb; | ||
196 | GtkListStore *ls; | ||
197 | GtkTreeIter iter; | ||
198 | struct GNUNET_TIME_Absolute at; | ||
199 | struct GNUNET_TIME_Relative rt; | ||
200 | time_t tp; | ||
201 | struct tm *ymd; | ||
202 | GtkCalendar *cal; | ||
203 | |||
204 | if (GNUNET_YES != | ||
205 | edc->old_record_in_namestore) | ||
206 | { | ||
207 | gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder, | ||
208 | "edit_dialog_delete_button"))); | ||
209 | edit_dialog_disable_save (edc); | ||
210 | } | ||
211 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
212 | "edit_dialog_name_entry")), | ||
213 | edc->name); | ||
214 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, | ||
215 | "edit_dialog_options_public_checkbutton")), | ||
216 | edc->n_public); | ||
217 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, | ||
218 | "edit_dialog_options_shadow_checkbutton")), | ||
219 | edc->n_is_shadow); | ||
220 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == edc->n_exp_time) | ||
221 | { | ||
222 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, | ||
223 | "edit_dialog_expiration_never_radiobutton")), | ||
224 | TRUE); | ||
225 | gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder, | ||
226 | "edit_dialog_expiration_absolute_calendar"))); | ||
227 | gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder, | ||
228 | "edit_dialog_expiration_absolute_hbox"))); | ||
229 | gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder, | ||
230 | "edit_dialog_expiration_relative_combobox"))); | ||
231 | } | ||
232 | if ( (edc->n_is_relative) && | ||
233 | (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != edc->n_exp_time) ) | ||
234 | { | ||
235 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, | ||
236 | "edit_dialog_expiration_relative_radiobutton")), | ||
237 | TRUE); | ||
238 | gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder, | ||
239 | "edit_dialog_expiration_absolute_calendar"))); | ||
240 | gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder, | ||
241 | "edit_dialog_expiration_absolute_hbox"))); | ||
242 | rt.rel_value_us = edc->n_exp_time; | ||
243 | } | ||
244 | else | ||
245 | { | ||
246 | /* select a sane default */ | ||
247 | rt = GNUNET_TIME_UNIT_DAYS; | ||
248 | } | ||
249 | cb = GTK_COMBO_BOX (gtk_builder_get_object (edc->builder, | ||
250 | "edit_dialog_expiration_relative_combobox")); | ||
251 | ls = GTK_LIST_STORE (gtk_combo_box_get_model (cb)); | ||
252 | gtk_list_store_insert_with_values (ls, &iter, | ||
253 | -1 /* position: append */, | ||
254 | 0, GNUNET_STRINGS_relative_time_to_string (rt, GNUNET_NO), | ||
255 | -1); | ||
256 | gtk_combo_box_set_active_iter (cb, &iter); | ||
257 | if ( (! edc->n_is_relative) && | ||
258 | (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != edc->n_exp_time) ) | ||
259 | { | ||
260 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, | ||
261 | "edit_dialog_expiration_absolute_radiobutton")), | ||
262 | TRUE); | ||
263 | |||
264 | gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (edc->builder, | ||
265 | "edit_dialog_expiration_relative_combobox"))); | ||
266 | at.abs_value_us = edc->n_exp_time; | ||
267 | } | ||
268 | else | ||
269 | { | ||
270 | /* select a sane default: right now */ | ||
271 | at = GNUNET_TIME_absolute_get (); | ||
272 | } | ||
273 | tp = (time_t) (at.abs_value_us / 1000000LL); /* convert to seconds */ | ||
274 | ymd = gmtime (&tp); | ||
275 | cal = GTK_CALENDAR (gtk_builder_get_object (edc->builder, | ||
276 | "edit_dialog_expiration_absolute_calendar")); | ||
277 | gtk_calendar_select_month (cal, | ||
278 | ymd->tm_mon, | ||
279 | ymd->tm_year + 1900); | ||
280 | gtk_calendar_mark_day (cal, | ||
281 | ymd->tm_mday); | ||
282 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
283 | "edit_dialog_expiration_absolute_hours_spinbutton")), | ||
284 | (double) ymd->tm_hour); | ||
285 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
286 | "edit_dialog_expiration_absolute_minutes_spinbutton")), | ||
287 | (double) ymd->tm_min); | ||
288 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
289 | "edit_dialog_expiration_absolute_seconds_spinbutton")), | ||
290 | (double) ymd->tm_sec); | ||
291 | setup_zone (edc); | ||
292 | } | ||
293 | |||
294 | |||
295 | /** | ||
296 | * Perform the reverse of the 'edit_dialog_setup_common_elements' function, | ||
297 | * that is, extract the values from the (common) widgets and store the | ||
298 | * values in 'edc'. | ||
299 | * | ||
300 | * @param edc edit dialog to extract data from | ||
301 | */ | ||
302 | static void | ||
303 | edit_dialog_putes_common_elements (struct EditDialogContext *edc) | ||
304 | { | ||
305 | const char *rt_s; | ||
306 | struct GNUNET_TIME_Relative rt; | ||
307 | GtkComboBox *cb; | ||
308 | GtkTreeModel *tm; | ||
309 | GtkTreeIter iter; | ||
310 | gchar *opt; | ||
311 | struct GNUNET_IDENTITY_Ego *ego; | ||
312 | |||
313 | /* is public flag */ | ||
314 | edc->n_public = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, | ||
315 | "edit_dialog_options_public_checkbutton"))); | ||
316 | /* is shadow flag */ | ||
317 | edc->n_is_shadow = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, | ||
318 | "edit_dialog_options_shadow_checkbutton"))); | ||
319 | |||
320 | /* 'forever' expiration time */ | ||
321 | if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, | ||
322 | "edit_dialog_expiration_never_radiobutton")))) | ||
323 | { | ||
324 | edc->n_exp_time = GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us; | ||
325 | edc->n_is_relative = TRUE; /* doesn't matter, but make sure it is well-defined anyway */ | ||
326 | } | ||
327 | |||
328 | /* 'relative' expiration time */ | ||
329 | if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, | ||
330 | "edit_dialog_expiration_relative_radiobutton")))) | ||
331 | { | ||
332 | cb = GTK_COMBO_BOX (gtk_builder_get_object (edc->builder, | ||
333 | "edit_dialog_expiration_relative_combobox")); | ||
334 | tm = gtk_combo_box_get_model (cb); | ||
335 | if (! gtk_combo_box_get_active_iter (cb, &iter)) | ||
336 | { | ||
337 | GNUNET_break (0); | ||
338 | return; | ||
339 | } | ||
340 | gtk_tree_model_get (tm, &iter, | ||
341 | 0, &rt_s, | ||
342 | -1); | ||
343 | GNUNET_break (GNUNET_YES == | ||
344 | GNUNET_STRINGS_fancy_time_to_relative (rt_s, | ||
345 | &rt)); | ||
346 | edc->n_exp_time = rt.rel_value_us; | ||
347 | edc->n_is_relative = TRUE; | ||
348 | } | ||
349 | |||
350 | /* 'absolute' expiration time */ | ||
351 | if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, | ||
352 | "edit_dialog_expiration_absolute_radiobutton")))) | ||
353 | { | ||
354 | guint year; | ||
355 | guint month; | ||
356 | guint day; | ||
357 | guint hour; | ||
358 | guint minute; | ||
359 | guint second; | ||
360 | char fancydate[128]; | ||
361 | struct GNUNET_TIME_Absolute atime; | ||
362 | |||
363 | gtk_calendar_get_date (GTK_CALENDAR (gtk_builder_get_object (edc->builder, | ||
364 | "edit_dialog_expiration_absolute_calendar")), | ||
365 | &year, &month, &day); | ||
366 | hour = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
367 | "edit_dialog_expiration_absolute_hours_spinbutton"))); | ||
368 | minute = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
369 | "edit_dialog_expiration_absolute_minutes_spinbutton"))); | ||
370 | second = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
371 | "edit_dialog_expiration_absolute_seconds_spinbutton"))); | ||
372 | GNUNET_snprintf (fancydate, | ||
373 | sizeof (fancydate), | ||
374 | "%u-%u-%u %u:%u:%u", | ||
375 | (unsigned int) year, | ||
376 | (unsigned int) month + 1, | ||
377 | (unsigned int) day, | ||
378 | (unsigned int) hour, | ||
379 | (unsigned int) minute, | ||
380 | (unsigned int) second); | ||
381 | GNUNET_break (GNUNET_OK == | ||
382 | GNUNET_STRINGS_fancy_time_to_absolute (fancydate, | ||
383 | &atime)); | ||
384 | edc->n_exp_time = atime.abs_value_us; | ||
385 | edc->n_is_relative = FALSE; | ||
386 | } | ||
387 | |||
388 | /* extract target zone! */ | ||
389 | cb = GTK_COMBO_BOX (gtk_builder_get_object (edc->builder, | ||
390 | "edit_dialog_zone_combobox")); | ||
391 | tm = gtk_combo_box_get_model (cb); | ||
392 | if (! gtk_combo_box_get_active_iter (cb, &iter)) | ||
393 | { | ||
394 | GNUNET_break (0); | ||
395 | } | ||
396 | else | ||
397 | { | ||
398 | gtk_tree_model_get (tm, &iter, | ||
399 | ZONE_LS_NAME, &opt, | ||
400 | ZONE_LS_EGO, &ego, | ||
401 | -1); | ||
402 | if (NULL == opt) | ||
403 | { | ||
404 | GNUNET_break (0); | ||
405 | } | ||
406 | else | ||
407 | { | ||
408 | g_free (edc->new_zone_option); | ||
409 | edc->new_zone_option = g_strdup (opt); | ||
410 | g_free (opt); | ||
411 | edc->ego = ego; | ||
412 | } | ||
413 | } | ||
414 | } | ||
415 | |||
416 | |||
417 | /** | ||
418 | * Run the edit dialog. Performs all of the common initialization | ||
419 | * steps to run an edit dialog for records. | ||
420 | * | ||
421 | * @param edc editing context | ||
422 | */ | ||
423 | static void | ||
424 | run_edit_dialog (struct EditDialogContext *edc) | ||
425 | { | ||
426 | edit_dialog_setup_common_elements (edc); | ||
427 | gtk_dialog_set_default_response (edc->dialog, | ||
428 | GTK_RESPONSE_OK); | ||
429 | gtk_window_present (GTK_WINDOW (edc->dialog)); | ||
430 | } | ||
431 | |||
432 | |||
433 | /* ************************ A records *********************** */ | ||
434 | |||
435 | /** | ||
436 | * Check validity of the value in the edit dialog for A-records. | ||
437 | * Then call the shared validity check if the result is OK. | ||
438 | * | ||
439 | * @param edc edit dialog context | ||
440 | */ | ||
441 | static void | ||
442 | edit_dialog_a_validity_check (struct EditDialogContext *edc) | ||
443 | { | ||
444 | GtkEditable *entry; | ||
445 | const gchar *preedit; | ||
446 | struct in_addr v4; | ||
447 | |||
448 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
449 | "edit_dialog_a_entry")), | ||
450 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
451 | if ( (NULL == preedit) || | ||
452 | (1 != inet_pton (AF_INET, preedit, &v4)) ) | ||
453 | { | ||
454 | edit_dialog_disable_save (edc); | ||
455 | return; | ||
456 | } | ||
457 | edit_dialog_check_save (edc); | ||
458 | } | ||
459 | |||
460 | |||
461 | /** | ||
462 | * Editing dialog was closed, get the data and call the | ||
463 | * continuation. | ||
464 | * | ||
465 | * @param dialog editing dialog | ||
466 | * @param response_id action that caused the dialog to be closed | ||
467 | * @param user_data the 'struct EditDialogContext' | ||
468 | */ | ||
469 | void | ||
470 | GNS_edit_a_dialog_response_cb (GtkDialog *dialog, | ||
471 | gint response_id, | ||
472 | gpointer user_data) | ||
473 | { | ||
474 | struct EditDialogContext *edc = user_data; | ||
475 | GtkEntry *entry; | ||
476 | const gchar *value; | ||
477 | |||
478 | if (GTK_RESPONSE_OK == response_id) | ||
479 | { | ||
480 | edit_dialog_putes_common_elements (edc); | ||
481 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
482 | "edit_dialog_a_entry")); | ||
483 | value = gtk_entry_get_text (entry); | ||
484 | g_free (edc->n_value); | ||
485 | edc->n_value = g_strdup (value); | ||
486 | } | ||
487 | gtk_widget_destroy (GTK_WIDGET (edc->dialog)); | ||
488 | g_object_unref (edc->builder); | ||
489 | edc->builder = NULL; | ||
490 | edc->cont (edc, response_id); | ||
491 | } | ||
492 | |||
493 | |||
494 | /** | ||
495 | * The user has edited the A record value. Enable/disable 'save' | ||
496 | * button depending on the validity of the value. | ||
497 | * | ||
498 | * @param entry editing widget | ||
499 | * @param user_data the 'struct EditDialogContext' of the dialog | ||
500 | */ | ||
501 | void | ||
502 | GNS_edit_dialog_a_entry_changed_cb (GtkEditable *entry, | ||
503 | gpointer user_data) | ||
504 | { | ||
505 | struct EditDialogContext *edc = user_data; | ||
506 | |||
507 | edit_dialog_a_validity_check (edc); | ||
508 | } | ||
509 | |||
510 | |||
511 | /** | ||
512 | * Run an GNS Edit dialog for an 'A' Record. | ||
513 | * | ||
514 | * @param edc editing context to use | ||
515 | */ | ||
516 | void | ||
517 | GNS_edit_dialog_a (struct EditDialogContext *edc) | ||
518 | { | ||
519 | edc->builder = GNUNET_GTK_get_new_builder ("gnunet_namestore_edit_a.glade", | ||
520 | edc); | ||
521 | if (NULL == edc->builder) | ||
522 | { | ||
523 | GNUNET_break (0); | ||
524 | edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ | ||
525 | return; | ||
526 | } | ||
527 | if (GNUNET_YES == | ||
528 | edc->old_record_in_namestore) | ||
529 | { | ||
530 | /* set A record */ | ||
531 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
532 | "edit_dialog_a_entry")), | ||
533 | edc->n_value); | ||
534 | } | ||
535 | edc->validator = &edit_dialog_a_validity_check; | ||
536 | edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder, | ||
537 | "edit_a_dialog")); | ||
538 | run_edit_dialog (edc); | ||
539 | } | ||
540 | |||
541 | |||
542 | /* ************************ AAAA records *********************** */ | ||
543 | |||
544 | /** | ||
545 | * Check validity of the value in the edit dialog for AAAA-records. | ||
546 | * Then call the shared validity check if the result is OK. | ||
547 | * | ||
548 | * @param edc edit dialog context | ||
549 | */ | ||
550 | static void | ||
551 | edit_dialog_aaaa_validity_check (struct EditDialogContext *edc) | ||
552 | { | ||
553 | GtkEditable *entry; | ||
554 | const gchar *preedit; | ||
555 | struct in6_addr v6; | ||
556 | |||
557 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
558 | "edit_dialog_aaaa_entry")), | ||
559 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
560 | if ( (NULL == preedit) || | ||
561 | (1 != inet_pton (AF_INET6, preedit, &v6)) ) | ||
562 | { | ||
563 | edit_dialog_disable_save (edc); | ||
564 | return; | ||
565 | } | ||
566 | edit_dialog_check_save (edc); | ||
567 | } | ||
568 | |||
569 | |||
570 | /** | ||
571 | * Editing dialog was closed, get the data and call the | ||
572 | * continuation. | ||
573 | * | ||
574 | * @param dialog editing dialog | ||
575 | * @param response_id action that caused the dialog to be closed | ||
576 | * @param user_data the 'struct EditDialogContext' | ||
577 | */ | ||
578 | void | ||
579 | GNS_edit_aaaa_dialog_response_cb (GtkDialog *dialog, | ||
580 | gint response_id, | ||
581 | gpointer user_data) | ||
582 | { | ||
583 | struct EditDialogContext *edc = user_data; | ||
584 | GtkEntry *entry; | ||
585 | const gchar *value; | ||
586 | |||
587 | if (GTK_RESPONSE_OK == response_id) | ||
588 | { | ||
589 | edit_dialog_putes_common_elements (edc); | ||
590 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
591 | "edit_dialog_aaaa_entry")); | ||
592 | value = gtk_entry_get_text (entry); | ||
593 | g_free (edc->n_value); | ||
594 | edc->n_value = g_strdup (value); | ||
595 | } | ||
596 | gtk_widget_destroy (GTK_WIDGET (edc->dialog)); | ||
597 | g_object_unref (edc->builder); | ||
598 | edc->builder = NULL; | ||
599 | edc->cont (edc, response_id); | ||
600 | } | ||
601 | |||
602 | |||
603 | /** | ||
604 | * The user has edited the AAAA record value. Enable/disable 'save' | ||
605 | * button depending on the validity of the value. | ||
606 | * | ||
607 | * @param entry editing widget | ||
608 | * @param user_data the 'struct EditDialogContext' of the dialog | ||
609 | */ | ||
610 | void | ||
611 | GNS_edit_dialog_aaaa_entry_changed_cb (GtkEditable *entry, | ||
612 | gpointer user_data) | ||
613 | { | ||
614 | struct EditDialogContext *edc = user_data; | ||
615 | |||
616 | edit_dialog_aaaa_validity_check (edc); | ||
617 | } | ||
618 | |||
619 | |||
620 | /** | ||
621 | * Run an GNS Edit dialog for an 'AAAA' Record. | ||
622 | * | ||
623 | * @param edc editing context to use | ||
624 | */ | ||
625 | void | ||
626 | GNS_edit_dialog_aaaa (struct EditDialogContext *edc) | ||
627 | { | ||
628 | edc->builder = GNUNET_GTK_get_new_builder ("gnunet_namestore_edit_aaaa.glade", | ||
629 | edc); | ||
630 | if (NULL == edc->builder) | ||
631 | { | ||
632 | GNUNET_break (0); | ||
633 | edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ | ||
634 | return; | ||
635 | } | ||
636 | if (GNUNET_YES == | ||
637 | edc->old_record_in_namestore) | ||
638 | { | ||
639 | /* set AAAA record */ | ||
640 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
641 | "edit_dialog_aaaa_entry")), | ||
642 | edc->n_value); | ||
643 | } | ||
644 | edc->validator = &edit_dialog_aaaa_validity_check; | ||
645 | edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder, | ||
646 | "edit_aaaa_dialog")); | ||
647 | run_edit_dialog (edc); | ||
648 | } | ||
649 | |||
650 | |||
651 | /* ************************ CNAME records *********************** */ | ||
652 | |||
653 | /** | ||
654 | * Check validity of the value in the edit dialog for AAAA-records. | ||
655 | * Then call the shared validity check if the result is OK. | ||
656 | * | ||
657 | * @param edc edit dialog context | ||
658 | */ | ||
659 | static void | ||
660 | edit_dialog_cname_validity_check (struct EditDialogContext *edc) | ||
661 | { | ||
662 | GtkEditable *entry; | ||
663 | const gchar *preedit; | ||
664 | |||
665 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
666 | "edit_dialog_cname_entry")), | ||
667 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
668 | if ( (NULL == preedit) || | ||
669 | (GNUNET_OK != GNUNET_DNSPARSER_check_name (preedit)) ) | ||
670 | { | ||
671 | edit_dialog_disable_save (edc); | ||
672 | return; | ||
673 | } | ||
674 | edit_dialog_check_save (edc); | ||
675 | } | ||
676 | |||
677 | |||
678 | /** | ||
679 | * Editing dialog was closed, get the data and call the | ||
680 | * continuation. | ||
681 | * | ||
682 | * @param dialog editing dialog | ||
683 | * @param response_id action that caused the dialog to be closed | ||
684 | * @param user_data the 'struct EditDialogContext' | ||
685 | */ | ||
686 | void | ||
687 | GNS_edit_cname_dialog_response_cb (GtkDialog *dialog, | ||
688 | gint response_id, | ||
689 | gpointer user_data) | ||
690 | { | ||
691 | struct EditDialogContext *edc = user_data; | ||
692 | GtkEntry *entry; | ||
693 | const gchar *value; | ||
694 | |||
695 | if (GTK_RESPONSE_OK == response_id) | ||
696 | { | ||
697 | edit_dialog_putes_common_elements (edc); | ||
698 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
699 | "edit_dialog_cname_entry")); | ||
700 | value = gtk_entry_get_text (entry); | ||
701 | g_free (edc->n_value); | ||
702 | edc->n_value = g_strdup (value); | ||
703 | } | ||
704 | gtk_widget_destroy (GTK_WIDGET (edc->dialog)); | ||
705 | g_object_unref (edc->builder); | ||
706 | edc->builder = NULL; | ||
707 | edc->cont (edc, response_id); | ||
708 | } | ||
709 | |||
710 | |||
711 | /** | ||
712 | * The user has edited the CNAME record value. Enable/disable 'save' | ||
713 | * button depending on the validity of the value. | ||
714 | * | ||
715 | * @param entry editing widget | ||
716 | * @param user_data the 'struct EditDialogContext' of the dialog | ||
717 | */ | ||
718 | void | ||
719 | GNS_edit_dialog_cname_entry_changed_cb (GtkEditable *entry, | ||
720 | gpointer user_data) | ||
721 | { | ||
722 | struct EditDialogContext *edc = user_data; | ||
723 | |||
724 | edit_dialog_cname_validity_check (edc); | ||
725 | } | ||
726 | |||
727 | |||
728 | /** | ||
729 | * Run an GNS Edit dialog for an 'CNAME' Record. | ||
730 | * | ||
731 | * @param edc editing context to use | ||
732 | */ | ||
733 | void | ||
734 | GNS_edit_dialog_cname (struct EditDialogContext *edc) | ||
735 | { | ||
736 | edc->builder = GNUNET_GTK_get_new_builder ("gnunet_namestore_edit_cname.glade", | ||
737 | edc); | ||
738 | if (NULL == edc->builder) | ||
739 | { | ||
740 | GNUNET_break (0); | ||
741 | edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ | ||
742 | return; | ||
743 | } | ||
744 | if (GNUNET_YES == | ||
745 | edc->old_record_in_namestore) | ||
746 | { | ||
747 | /* set CNAME record */ | ||
748 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
749 | "edit_dialog_cname_entry")), | ||
750 | edc->n_value); | ||
751 | } | ||
752 | edc->validator = &edit_dialog_cname_validity_check; | ||
753 | edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder, | ||
754 | "edit_cname_dialog")); | ||
755 | run_edit_dialog (edc); | ||
756 | } | ||
757 | |||
758 | |||
759 | /* ************************ LEHO records *********************** */ | ||
760 | |||
761 | /** | ||
762 | * Check validity of the value in the edit dialog for LEHO-records. | ||
763 | * Then call the shared validity check if the result is OK. | ||
764 | * | ||
765 | * @param edc edit dialog context | ||
766 | */ | ||
767 | static void | ||
768 | edit_dialog_leho_validity_check (struct EditDialogContext *edc) | ||
769 | { | ||
770 | GtkEditable *entry; | ||
771 | const gchar *preedit; | ||
772 | |||
773 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
774 | "edit_dialog_leho_entry")), | ||
775 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
776 | if ( (NULL == preedit) || | ||
777 | (GNUNET_OK != GNUNET_DNSPARSER_check_name (preedit)) ) | ||
778 | { | ||
779 | edit_dialog_disable_save (edc); | ||
780 | return; | ||
781 | } | ||
782 | edit_dialog_check_save (edc); | ||
783 | } | ||
784 | |||
785 | |||
786 | /** | ||
787 | * Editing dialog was closed, get the data and call the | ||
788 | * continuation. | ||
789 | * | ||
790 | * @param dialog editing dialog | ||
791 | * @param response_id action that caused the dialog to be closed | ||
792 | * @param user_data the 'struct EditDialogContext' | ||
793 | */ | ||
794 | void | ||
795 | GNS_edit_leho_dialog_response_cb (GtkDialog *dialog, | ||
796 | gint response_id, | ||
797 | gpointer user_data) | ||
798 | { | ||
799 | struct EditDialogContext *edc = user_data; | ||
800 | GtkEntry *entry; | ||
801 | const gchar *value; | ||
802 | |||
803 | if (GTK_RESPONSE_OK == response_id) | ||
804 | { | ||
805 | edit_dialog_putes_common_elements (edc); | ||
806 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
807 | "edit_dialog_leho_entry")); | ||
808 | value = gtk_entry_get_text (entry); | ||
809 | g_free (edc->n_value); | ||
810 | edc->n_value = g_strdup (value); | ||
811 | } | ||
812 | gtk_widget_destroy (GTK_WIDGET (edc->dialog)); | ||
813 | g_object_unref (edc->builder); | ||
814 | edc->builder = NULL; | ||
815 | edc->cont (edc, response_id); | ||
816 | } | ||
817 | |||
818 | |||
819 | /** | ||
820 | * The user has edited the LEHO record value. Enable/disable 'save' | ||
821 | * button depending on the validity of the value. | ||
822 | * | ||
823 | * @param entry editing widget | ||
824 | * @param user_data the 'struct EditDialogContext' of the dialog | ||
825 | */ | ||
826 | void | ||
827 | GNS_edit_dialog_leho_entry_changed_cb (GtkEditable *entry, | ||
828 | gpointer user_data) | ||
829 | { | ||
830 | struct EditDialogContext *edc = user_data; | ||
831 | |||
832 | edit_dialog_leho_validity_check (edc); | ||
833 | } | ||
834 | |||
835 | |||
836 | /** | ||
837 | * Run an GNS Edit dialog for an 'LEHO' Record. | ||
838 | * | ||
839 | * @param edc editing context to use | ||
840 | */ | ||
841 | void | ||
842 | GNS_edit_dialog_leho (struct EditDialogContext *edc) | ||
843 | { | ||
844 | edc->builder = GNUNET_GTK_get_new_builder ("gnunet_namestore_edit_leho.glade", | ||
845 | edc); | ||
846 | if (NULL == edc->builder) | ||
847 | { | ||
848 | GNUNET_break (0); | ||
849 | edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ | ||
850 | return; | ||
851 | } | ||
852 | if (GNUNET_YES == | ||
853 | edc->old_record_in_namestore) | ||
854 | { | ||
855 | /* set LEHO record */ | ||
856 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
857 | "edit_dialog_leho_entry")), | ||
858 | edc->n_value); | ||
859 | } | ||
860 | edc->validator = &edit_dialog_leho_validity_check; | ||
861 | edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder, | ||
862 | "edit_leho_dialog")); | ||
863 | run_edit_dialog (edc); | ||
864 | } | ||
865 | |||
866 | |||
867 | /* ************************ MX records *********************** */ | ||
868 | |||
869 | /** | ||
870 | * Check validity of the value in the edit dialog for MX-records. | ||
871 | * Then call the shared validity check if the result is OK. | ||
872 | * | ||
873 | * @param edc edit dialog context | ||
874 | */ | ||
875 | static void | ||
876 | edit_dialog_mx_validity_check (struct EditDialogContext *edc) | ||
877 | { | ||
878 | GtkEditable *entry; | ||
879 | const gchar *preedit; | ||
880 | |||
881 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
882 | "edit_dialog_mx_entry")), | ||
883 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
884 | if ( (NULL == preedit) || | ||
885 | (GNUNET_OK != GNUNET_DNSPARSER_check_name (preedit)) ) | ||
886 | { | ||
887 | edit_dialog_disable_save (edc); | ||
888 | return; | ||
889 | } | ||
890 | edit_dialog_check_save (edc); | ||
891 | } | ||
892 | |||
893 | |||
894 | /** | ||
895 | * Editing dialog was closed, get the data and call the | ||
896 | * continuation. | ||
897 | * | ||
898 | * @param dialog editing dialog | ||
899 | * @param response_id action that caused the dialog to be closed | ||
900 | * @param user_data the 'struct EditDialogContext' | ||
901 | */ | ||
902 | void | ||
903 | GNS_edit_mx_dialog_response_cb (GtkDialog *dialog, | ||
904 | gint response_id, | ||
905 | gpointer user_data) | ||
906 | { | ||
907 | struct EditDialogContext *edc = user_data; | ||
908 | GtkEntry *entry; | ||
909 | const gchar *value; | ||
910 | char *result; | ||
911 | unsigned int distance; | ||
912 | |||
913 | if (GTK_RESPONSE_OK == response_id) | ||
914 | { | ||
915 | edit_dialog_putes_common_elements (edc); | ||
916 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
917 | "edit_dialog_mx_entry")); | ||
918 | value = gtk_entry_get_text (entry); | ||
919 | distance = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
920 | "edit_dialog_mx_distance_spinbutton"))); | ||
921 | g_free (edc->n_value); | ||
922 | GNUNET_asprintf (&result, | ||
923 | "%hu,%s", | ||
924 | distance, | ||
925 | value); | ||
926 | edc->n_value = g_strdup (result); | ||
927 | GNUNET_free (result); | ||
928 | } | ||
929 | gtk_widget_destroy (GTK_WIDGET (edc->dialog)); | ||
930 | g_object_unref (edc->builder); | ||
931 | edc->builder = NULL; | ||
932 | edc->cont (edc, response_id); | ||
933 | } | ||
934 | |||
935 | |||
936 | /** | ||
937 | * The user has edited the MX record value. Enable/disable 'save' | ||
938 | * button depending on the validity of the value. | ||
939 | * | ||
940 | * @param entry editing widget | ||
941 | * @param user_data the 'struct EditDialogContext' of the dialog | ||
942 | */ | ||
943 | void | ||
944 | GNS_edit_dialog_mx_entry_changed_cb (GtkEditable *entry, | ||
945 | gpointer user_data) | ||
946 | { | ||
947 | struct EditDialogContext *edc = user_data; | ||
948 | |||
949 | edit_dialog_mx_validity_check (edc); | ||
950 | } | ||
951 | |||
952 | |||
953 | /** | ||
954 | * Run an GNS Edit dialog for an 'MX' Record. | ||
955 | * | ||
956 | * @param edc editing context to use | ||
957 | */ | ||
958 | void | ||
959 | GNS_edit_dialog_mx (struct EditDialogContext *edc) | ||
960 | { | ||
961 | uint16_t mx_pref; | ||
962 | char result[253 + 1]; | ||
963 | |||
964 | edc->builder = GNUNET_GTK_get_new_builder ("gnunet_namestore_edit_mx.glade", | ||
965 | edc); | ||
966 | if (NULL == edc->builder) | ||
967 | { | ||
968 | GNUNET_break (0); | ||
969 | edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ | ||
970 | return; | ||
971 | } | ||
972 | if (GNUNET_YES == | ||
973 | edc->old_record_in_namestore) | ||
974 | { | ||
975 | if (2 != SSCANF(edc->n_value, | ||
976 | "%hu,%253s", &mx_pref, result)) | ||
977 | { | ||
978 | GNUNET_break (0); | ||
979 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
980 | _("Unable to parse MX record `%s'\n"), | ||
981 | edc->n_value); | ||
982 | } | ||
983 | else | ||
984 | { | ||
985 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
986 | "edit_dialog_mx_entry")), | ||
987 | result); | ||
988 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
989 | "edit_dialog_mx_distance_spinbutton")), | ||
990 | mx_pref); | ||
991 | } | ||
992 | } | ||
993 | edc->validator = &edit_dialog_mx_validity_check; | ||
994 | edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder, | ||
995 | "edit_mx_dialog")); | ||
996 | run_edit_dialog (edc); | ||
997 | } | ||
998 | |||
999 | |||
1000 | /* ************************ GNS2DNS records *********************** */ | ||
1001 | |||
1002 | /** | ||
1003 | * Check validity of the value in the edit dialog for GNS2DNS-records. | ||
1004 | * Then call the shared validity check if the result is OK. | ||
1005 | * | ||
1006 | * @param edc edit dialog context | ||
1007 | */ | ||
1008 | static void | ||
1009 | edit_dialog_gns2dns_validity_check (struct EditDialogContext *edc) | ||
1010 | { | ||
1011 | GtkEditable *entry; | ||
1012 | const gchar *preedit; | ||
1013 | |||
1014 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
1015 | "edit_dialog_gns2dns_entry")), | ||
1016 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
1017 | if ( (NULL == preedit) || | ||
1018 | (GNUNET_OK != GNUNET_DNSPARSER_check_name (preedit)) ) | ||
1019 | { | ||
1020 | edit_dialog_disable_save (edc); | ||
1021 | return; | ||
1022 | } | ||
1023 | edit_dialog_check_save (edc); | ||
1024 | } | ||
1025 | |||
1026 | |||
1027 | /** | ||
1028 | * Editing dialog was closed, get the data and call the | ||
1029 | * continuation. | ||
1030 | * | ||
1031 | * @param dialog editing dialog | ||
1032 | * @param response_id action that caused the dialog to be closed | ||
1033 | * @param user_data the 'struct EditDialogContext' | ||
1034 | */ | ||
1035 | void | ||
1036 | GNS_edit_gns2dns_dialog_response_cb (GtkDialog *dialog, | ||
1037 | gint response_id, | ||
1038 | gpointer user_data) | ||
1039 | { | ||
1040 | struct EditDialogContext *edc = user_data; | ||
1041 | GtkEntry *entry; | ||
1042 | const gchar *value; | ||
1043 | |||
1044 | if (GTK_RESPONSE_OK == response_id) | ||
1045 | { | ||
1046 | edit_dialog_putes_common_elements (edc); | ||
1047 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1048 | "edit_dialog_gns2dns_entry")); | ||
1049 | value = gtk_entry_get_text (entry); | ||
1050 | g_free (edc->n_value); | ||
1051 | edc->n_value = g_strdup (value); | ||
1052 | } | ||
1053 | gtk_widget_destroy (GTK_WIDGET (edc->dialog)); | ||
1054 | g_object_unref (edc->builder); | ||
1055 | edc->builder = NULL; | ||
1056 | edc->cont (edc, response_id); | ||
1057 | } | ||
1058 | |||
1059 | |||
1060 | /** | ||
1061 | * The user has edited the GNS2DNS record value. Enable/disable 'save' | ||
1062 | * button depending on the validity of the value. | ||
1063 | * | ||
1064 | * @param entry editing widget | ||
1065 | * @param user_data the 'struct EditDialogContext' of the dialog | ||
1066 | */ | ||
1067 | void | ||
1068 | GNS_edit_dialog_gns2dns_entry_changed_cb (GtkEditable *entry, | ||
1069 | gpointer user_data) | ||
1070 | { | ||
1071 | struct EditDialogContext *edc = user_data; | ||
1072 | |||
1073 | edit_dialog_gns2dns_validity_check (edc); | ||
1074 | } | ||
1075 | |||
1076 | |||
1077 | /** | ||
1078 | * Run an GNS Edit dialog for a 'GNS2DNS' Record. | ||
1079 | * | ||
1080 | * @param edc editing context to use | ||
1081 | */ | ||
1082 | void | ||
1083 | GNS_edit_dialog_gns2dns (struct EditDialogContext *edc) | ||
1084 | { | ||
1085 | edc->builder = GNUNET_GTK_get_new_builder ("gnunet_namestore_edit_gns2dns.glade", | ||
1086 | edc); | ||
1087 | if (NULL == edc->builder) | ||
1088 | { | ||
1089 | GNUNET_break (0); | ||
1090 | edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ | ||
1091 | return; | ||
1092 | } | ||
1093 | if (GNUNET_YES == | ||
1094 | edc->old_record_in_namestore) | ||
1095 | { | ||
1096 | /* set NS record */ | ||
1097 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1098 | "edit_dialog_gns2dns_entry")), | ||
1099 | edc->n_value); | ||
1100 | } | ||
1101 | edc->validator = &edit_dialog_gns2dns_validity_check; | ||
1102 | edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder, | ||
1103 | "edit_gns2dns_dialog")); | ||
1104 | run_edit_dialog (edc); | ||
1105 | } | ||
1106 | |||
1107 | |||
1108 | /* ************************ PHONE records *********************** */ | ||
1109 | |||
1110 | /** | ||
1111 | * Check validity of the value in the edit dialog for PHONE-records. | ||
1112 | * Then call the shared validity check if the result is OK. | ||
1113 | * | ||
1114 | * @param edc edit dialog context | ||
1115 | */ | ||
1116 | static void | ||
1117 | edit_dialog_phone_validity_check (struct EditDialogContext *edc) | ||
1118 | { | ||
1119 | GtkEditable *entry; | ||
1120 | const gchar *preedit; | ||
1121 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | ||
1122 | |||
1123 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
1124 | "edit_dialog_phone_peer_entry")); | ||
1125 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
1126 | if ( (NULL == preedit) || | ||
1127 | (GNUNET_OK != | ||
1128 | GNUNET_CRYPTO_ecdsa_public_key_from_string (preedit, | ||
1129 | strlen (preedit), | ||
1130 | &pub)) ) | ||
1131 | { | ||
1132 | edit_dialog_disable_save (edc); | ||
1133 | return; | ||
1134 | } | ||
1135 | edit_dialog_check_save (edc); | ||
1136 | } | ||
1137 | |||
1138 | |||
1139 | /** | ||
1140 | * Editing dialog was closed, get the data and call the | ||
1141 | * continuation. | ||
1142 | * | ||
1143 | * @param dialog editing dialog | ||
1144 | * @param response_id action that caused the dialog to be closed | ||
1145 | * @param user_data the 'struct EditDialogContext' | ||
1146 | */ | ||
1147 | void | ||
1148 | GNS_edit_phone_dialog_response_cb (GtkDialog *dialog, | ||
1149 | gint response_id, | ||
1150 | gpointer user_data) | ||
1151 | { | ||
1152 | struct EditDialogContext *edc = user_data; | ||
1153 | GtkEntry *entry; | ||
1154 | GtkSpinButton *spin; | ||
1155 | const gchar *value; | ||
1156 | unsigned int line; | ||
1157 | |||
1158 | if (GTK_RESPONSE_OK == response_id) | ||
1159 | { | ||
1160 | edit_dialog_putes_common_elements (edc); | ||
1161 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1162 | "edit_dialog_phone_peer_entry")); | ||
1163 | value = gtk_entry_get_text (entry); | ||
1164 | spin = GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
1165 | "edit_dialog_phone_line_spinbutton")); | ||
1166 | line = gtk_spin_button_get_value (spin); | ||
1167 | g_free (edc->n_value); | ||
1168 | GNUNET_asprintf (&edc->n_value, | ||
1169 | "%u-%s", | ||
1170 | line, | ||
1171 | value); | ||
1172 | } | ||
1173 | gtk_widget_destroy (GTK_WIDGET (edc->dialog)); | ||
1174 | g_object_unref (edc->builder); | ||
1175 | edc->builder = NULL; | ||
1176 | edc->cont (edc, response_id); | ||
1177 | } | ||
1178 | |||
1179 | |||
1180 | /** | ||
1181 | * The user has edited the PHONE record value. Enable/disable 'save' | ||
1182 | * button depending on the validity of the value. | ||
1183 | * | ||
1184 | * @param entry editing widget | ||
1185 | * @param user_data the 'struct EditDialogContext' of the dialog | ||
1186 | */ | ||
1187 | void | ||
1188 | GNS_edit_dialog_phone_peer_entry_changed_cb (GtkEditable *entry, | ||
1189 | gpointer user_data) | ||
1190 | { | ||
1191 | struct EditDialogContext *edc = user_data; | ||
1192 | |||
1193 | edit_dialog_phone_validity_check (edc); | ||
1194 | } | ||
1195 | |||
1196 | |||
1197 | /** | ||
1198 | * Run an GNS Edit dialog for a 'PHONE' Record. | ||
1199 | * | ||
1200 | * @param edc editing context to use | ||
1201 | */ | ||
1202 | void | ||
1203 | GNS_edit_dialog_phone (struct EditDialogContext *edc) | ||
1204 | { | ||
1205 | const char *minus; | ||
1206 | unsigned int line; | ||
1207 | |||
1208 | edc->builder = GNUNET_GTK_get_new_builder ("gnunet_namestore_edit_phone.glade", | ||
1209 | edc); | ||
1210 | if (NULL == edc->builder) | ||
1211 | { | ||
1212 | GNUNET_break (0); | ||
1213 | edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ | ||
1214 | return; | ||
1215 | } | ||
1216 | if (GNUNET_YES == | ||
1217 | edc->old_record_in_namestore) | ||
1218 | { | ||
1219 | /* set PKEY record */ | ||
1220 | if (1 != (sscanf (edc->n_value, | ||
1221 | "%u-", | ||
1222 | &line))) | ||
1223 | { | ||
1224 | GNUNET_break (0); | ||
1225 | } | ||
1226 | else | ||
1227 | { | ||
1228 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
1229 | "edit_dialog_phone_line_spinbutton")), | ||
1230 | line); | ||
1231 | |||
1232 | } | ||
1233 | if (NULL == (minus = strchr (edc->n_value, '-'))) | ||
1234 | { | ||
1235 | GNUNET_break (0); | ||
1236 | } | ||
1237 | else | ||
1238 | { | ||
1239 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1240 | "edit_dialog_phone_peer_entry")), | ||
1241 | minus + 1); | ||
1242 | } | ||
1243 | } | ||
1244 | edc->validator = &edit_dialog_phone_validity_check; | ||
1245 | edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder, | ||
1246 | "edit_phone_dialog")); | ||
1247 | run_edit_dialog (edc); | ||
1248 | } | ||
1249 | |||
1250 | |||
1251 | /* ************************ PKEY records *********************** */ | ||
1252 | |||
1253 | /** | ||
1254 | * Check validity of the value in the edit dialog for PKEY-records. | ||
1255 | * Then call the shared validity check if the result is OK. | ||
1256 | * | ||
1257 | * @param edc edit dialog context | ||
1258 | */ | ||
1259 | static void | ||
1260 | edit_dialog_pkey_validity_check (struct EditDialogContext *edc) | ||
1261 | { | ||
1262 | GtkEditable *entry; | ||
1263 | const gchar *preedit; | ||
1264 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | ||
1265 | |||
1266 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
1267 | "edit_dialog_pkey_entry")), | ||
1268 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
1269 | if ( (NULL == preedit) || | ||
1270 | (GNUNET_OK != | ||
1271 | GNUNET_CRYPTO_ecdsa_public_key_from_string (preedit, | ||
1272 | strlen (preedit), | ||
1273 | &pub)) ) | ||
1274 | { | ||
1275 | edit_dialog_disable_save (edc); | ||
1276 | return; | ||
1277 | } | ||
1278 | edit_dialog_check_save (edc); | ||
1279 | } | ||
1280 | |||
1281 | |||
1282 | /** | ||
1283 | * Editing dialog was closed, get the data and call the | ||
1284 | * continuation. | ||
1285 | * | ||
1286 | * @param dialog editing dialog | ||
1287 | * @param response_id action that caused the dialog to be closed | ||
1288 | * @param user_data the 'struct EditDialogContext' | ||
1289 | */ | ||
1290 | void | ||
1291 | GNS_edit_pkey_dialog_response_cb (GtkDialog *dialog, | ||
1292 | gint response_id, | ||
1293 | gpointer user_data) | ||
1294 | { | ||
1295 | struct EditDialogContext *edc = user_data; | ||
1296 | GtkEntry *entry; | ||
1297 | const gchar *value; | ||
1298 | |||
1299 | if (GTK_RESPONSE_OK == response_id) | ||
1300 | { | ||
1301 | edit_dialog_putes_common_elements (edc); | ||
1302 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1303 | "edit_dialog_pkey_entry")); | ||
1304 | value = gtk_entry_get_text (entry); | ||
1305 | g_free (edc->n_value); | ||
1306 | edc->n_value = g_strdup (value); | ||
1307 | } | ||
1308 | gtk_widget_destroy (GTK_WIDGET (edc->dialog)); | ||
1309 | g_object_unref (edc->builder); | ||
1310 | edc->builder = NULL; | ||
1311 | edc->cont (edc, response_id); | ||
1312 | } | ||
1313 | |||
1314 | |||
1315 | /** | ||
1316 | * The user has edited the PKEY record value. Enable/disable 'save' | ||
1317 | * button depending on the validity of the value. | ||
1318 | * | ||
1319 | * @param entry editing widget | ||
1320 | * @param user_data the 'struct EditDialogContext' of the dialog | ||
1321 | */ | ||
1322 | void | ||
1323 | GNS_edit_dialog_pkey_entry_changed_cb (GtkEditable *entry, | ||
1324 | gpointer user_data) | ||
1325 | { | ||
1326 | struct EditDialogContext *edc = user_data; | ||
1327 | |||
1328 | edit_dialog_pkey_validity_check (edc); | ||
1329 | } | ||
1330 | |||
1331 | |||
1332 | /** | ||
1333 | * Run an GNS Edit dialog for an 'PKEY' Record. | ||
1334 | * | ||
1335 | * @param edc editing context to use | ||
1336 | */ | ||
1337 | void | ||
1338 | GNS_edit_dialog_pkey (struct EditDialogContext *edc) | ||
1339 | { | ||
1340 | edc->builder = GNUNET_GTK_get_new_builder ("gnunet_namestore_edit_pkey.glade", | ||
1341 | edc); | ||
1342 | if (NULL == edc->builder) | ||
1343 | { | ||
1344 | GNUNET_break (0); | ||
1345 | edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ | ||
1346 | return; | ||
1347 | } | ||
1348 | if (GNUNET_YES == | ||
1349 | edc->old_record_in_namestore) | ||
1350 | { | ||
1351 | /* set PKEY record */ | ||
1352 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1353 | "edit_dialog_pkey_entry")), | ||
1354 | edc->n_value); | ||
1355 | } | ||
1356 | edc->validator = &edit_dialog_pkey_validity_check; | ||
1357 | edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder, | ||
1358 | "edit_pkey_dialog")); | ||
1359 | run_edit_dialog (edc); | ||
1360 | } | ||
1361 | |||
1362 | |||
1363 | /* ************************ PTR records *********************** */ | ||
1364 | |||
1365 | /** | ||
1366 | * Check validity of the value in the edit dialog for PTR-records. | ||
1367 | * Then call the shared validity check if the result is OK. | ||
1368 | * | ||
1369 | * @param edc edit dialog context | ||
1370 | */ | ||
1371 | static void | ||
1372 | edit_dialog_ptr_validity_check (struct EditDialogContext *edc) | ||
1373 | { | ||
1374 | GtkEditable *entry; | ||
1375 | const gchar *preedit; | ||
1376 | |||
1377 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
1378 | "edit_dialog_ptr_entry")), | ||
1379 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
1380 | if ( (NULL == preedit) || | ||
1381 | (GNUNET_OK != GNUNET_DNSPARSER_check_name (preedit)) ) | ||
1382 | { | ||
1383 | edit_dialog_disable_save (edc); | ||
1384 | return; | ||
1385 | } | ||
1386 | edit_dialog_check_save (edc); | ||
1387 | } | ||
1388 | |||
1389 | |||
1390 | /** | ||
1391 | * Editing dialog was closed, get the data and call the | ||
1392 | * continuation. | ||
1393 | * | ||
1394 | * @param dialog editing dialog | ||
1395 | * @param response_id action that caused the dialog to be closed | ||
1396 | * @param user_data the 'struct EditDialogContext' | ||
1397 | */ | ||
1398 | void | ||
1399 | GNS_edit_ptr_dialog_response_cb (GtkDialog *dialog, | ||
1400 | gint response_id, | ||
1401 | gpointer user_data) | ||
1402 | { | ||
1403 | struct EditDialogContext *edc = user_data; | ||
1404 | GtkEntry *entry; | ||
1405 | const gchar *value; | ||
1406 | |||
1407 | if (GTK_RESPONSE_OK == response_id) | ||
1408 | { | ||
1409 | edit_dialog_putes_common_elements (edc); | ||
1410 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1411 | "edit_dialog_ptr_entry")); | ||
1412 | value = gtk_entry_get_text (entry); | ||
1413 | g_free (edc->n_value); | ||
1414 | edc->n_value = g_strdup (value); | ||
1415 | } | ||
1416 | gtk_widget_destroy (GTK_WIDGET (edc->dialog)); | ||
1417 | g_object_unref (edc->builder); | ||
1418 | edc->builder = NULL; | ||
1419 | edc->cont (edc, response_id); | ||
1420 | } | ||
1421 | |||
1422 | |||
1423 | /** | ||
1424 | * The user has edited the PTR record value. Enable/disable 'save' | ||
1425 | * button depending on the validity of the value. | ||
1426 | * | ||
1427 | * @param entry editing widget | ||
1428 | * @param user_data the 'struct EditDialogContext' of the dialog | ||
1429 | */ | ||
1430 | void | ||
1431 | GNS_edit_dialog_ptr_entry_changed_cb (GtkEditable *entry, | ||
1432 | gpointer user_data) | ||
1433 | { | ||
1434 | struct EditDialogContext *edc = user_data; | ||
1435 | |||
1436 | edit_dialog_ptr_validity_check (edc); | ||
1437 | } | ||
1438 | |||
1439 | |||
1440 | /** | ||
1441 | * Run an GNS Edit dialog for an 'PTR' Record. | ||
1442 | * | ||
1443 | * @param edc editing context to use | ||
1444 | */ | ||
1445 | void | ||
1446 | GNS_edit_dialog_ptr (struct EditDialogContext *edc) | ||
1447 | { | ||
1448 | edc->builder = GNUNET_GTK_get_new_builder ("gnunet_namestore_edit_ptr.glade", | ||
1449 | edc); | ||
1450 | if (NULL == edc->builder) | ||
1451 | { | ||
1452 | GNUNET_break (0); | ||
1453 | edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ | ||
1454 | return; | ||
1455 | } | ||
1456 | if (GNUNET_YES == | ||
1457 | edc->old_record_in_namestore) | ||
1458 | { | ||
1459 | /* set PTR record */ | ||
1460 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1461 | "edit_dialog_ptr_entry")), | ||
1462 | edc->n_value); | ||
1463 | } | ||
1464 | edc->validator = &edit_dialog_ptr_validity_check; | ||
1465 | edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder, | ||
1466 | "edit_ptr_dialog")); | ||
1467 | run_edit_dialog (edc); | ||
1468 | } | ||
1469 | |||
1470 | |||
1471 | /* ************************ SOA records *********************** */ | ||
1472 | |||
1473 | /** | ||
1474 | * Check validity of the value in the edit dialog for SOA-records. | ||
1475 | * Then call the shared validity check if the result is OK. | ||
1476 | * | ||
1477 | * @param edc edit dialog context | ||
1478 | */ | ||
1479 | static void | ||
1480 | edit_dialog_soa_validity_check (struct EditDialogContext *edc) | ||
1481 | { | ||
1482 | GtkEditable *entry; | ||
1483 | const gchar *preedit; | ||
1484 | |||
1485 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
1486 | "edit_dialog_soa_source_host_entry")), | ||
1487 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
1488 | if ( (NULL == preedit) || | ||
1489 | (GNUNET_OK != GNUNET_DNSPARSER_check_name (preedit)) ) | ||
1490 | { | ||
1491 | edit_dialog_disable_save (edc); | ||
1492 | return; | ||
1493 | } | ||
1494 | /* check for '@' in the e-mail --- required format uses "." instead! */ | ||
1495 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
1496 | "edit_dialog_soa_contact_email_entry")), | ||
1497 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
1498 | if ( (NULL == preedit) || | ||
1499 | (NULL != strstr (preedit, "@")) || | ||
1500 | (GNUNET_OK != GNUNET_DNSPARSER_check_name (preedit)) ) | ||
1501 | { | ||
1502 | /* E-mail is specified in the RFC also as a 'domain-name', hence | ||
1503 | we check above that it follows those conventions as well; the '@' | ||
1504 | is a common mistake, and while it should be illegal despite IDN, | ||
1505 | it feels better to check explicitly. */ | ||
1506 | edit_dialog_disable_save (edc); | ||
1507 | return; | ||
1508 | } | ||
1509 | edit_dialog_check_save (edc); | ||
1510 | } | ||
1511 | |||
1512 | |||
1513 | /** | ||
1514 | * Editing dialog was closed, get the data and call the | ||
1515 | * continuation. | ||
1516 | * | ||
1517 | * @param dialog editing dialog | ||
1518 | * @param response_id action that caused the dialog to be closed | ||
1519 | * @param user_data the 'struct EditDialogContext' | ||
1520 | */ | ||
1521 | void | ||
1522 | GNS_edit_soa_dialog_response_cb (GtkDialog *dialog, | ||
1523 | gint response_id, | ||
1524 | gpointer user_data) | ||
1525 | { | ||
1526 | struct EditDialogContext *edc = user_data; | ||
1527 | GtkEntry *entry; | ||
1528 | const gchar *source_host; | ||
1529 | const gchar *contact_email; | ||
1530 | unsigned int soa_serial; | ||
1531 | unsigned int soa_refresh; | ||
1532 | unsigned int soa_retry; | ||
1533 | unsigned int soa_expire; | ||
1534 | unsigned int soa_min; | ||
1535 | char *result; | ||
1536 | |||
1537 | if (GTK_RESPONSE_OK == response_id) | ||
1538 | { | ||
1539 | edit_dialog_putes_common_elements (edc); | ||
1540 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1541 | "edit_dialog_soa_source_host_entry")); | ||
1542 | source_host = gtk_entry_get_text (entry); | ||
1543 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1544 | "edit_dialog_soa_contact_email_entry")); | ||
1545 | contact_email = gtk_entry_get_text (entry); | ||
1546 | soa_serial = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
1547 | "edit_dialog_soa_serial_number_spinbutton"))); | ||
1548 | soa_refresh = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
1549 | "edit_dialog_soa_refresh_time_spinbutton"))); | ||
1550 | soa_retry = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
1551 | "edit_dialog_soa_retry_time_spinbutton"))); | ||
1552 | soa_expire = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
1553 | "edit_dialog_soa_expire_time_spinbutton"))); | ||
1554 | soa_min = gtk_spin_button_get_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
1555 | "edit_dialog_soa_minimum_ttl_spinbutton"))); | ||
1556 | GNUNET_asprintf (&result, | ||
1557 | "rname=%s mname=%s %lu,%lu,%lu,%lu,%lu", | ||
1558 | source_host, contact_email, | ||
1559 | soa_serial, | ||
1560 | soa_refresh, | ||
1561 | soa_retry, | ||
1562 | soa_expire, | ||
1563 | soa_min); | ||
1564 | edc->n_value = g_strdup (result); | ||
1565 | GNUNET_free (result); | ||
1566 | } | ||
1567 | gtk_widget_destroy (GTK_WIDGET (edc->dialog)); | ||
1568 | g_object_unref (edc->builder); | ||
1569 | edc->builder = NULL; | ||
1570 | edc->cont (edc, response_id); | ||
1571 | } | ||
1572 | |||
1573 | |||
1574 | /** | ||
1575 | * The user has edited the SOA record value. Enable/disable 'save' | ||
1576 | * button depending on the validity of the value. | ||
1577 | * | ||
1578 | * @param entry editing widget | ||
1579 | * @param user_data the 'struct EditDialogContext' of the dialog | ||
1580 | */ | ||
1581 | void | ||
1582 | GNS_edit_dialog_soa_contact_email_entry_changed_cb (GtkEditable *entry, | ||
1583 | gpointer user_data) | ||
1584 | { | ||
1585 | struct EditDialogContext *edc = user_data; | ||
1586 | |||
1587 | edit_dialog_soa_validity_check (edc); | ||
1588 | } | ||
1589 | |||
1590 | |||
1591 | /** | ||
1592 | * The user has edited the SOA record value. Enable/disable 'save' | ||
1593 | * button depending on the validity of the value. | ||
1594 | * | ||
1595 | * @param entry editing widget | ||
1596 | * @param user_data the 'struct EditDialogContext' of the dialog | ||
1597 | */ | ||
1598 | void | ||
1599 | GNS_edit_dialog_soa_source_host_entry_changed_cb (GtkEditable *entry, | ||
1600 | gpointer user_data) | ||
1601 | { | ||
1602 | struct EditDialogContext *edc = user_data; | ||
1603 | |||
1604 | edit_dialog_soa_validity_check (edc); | ||
1605 | } | ||
1606 | |||
1607 | |||
1608 | /** | ||
1609 | * Run an GNS Edit dialog for an 'SOA' Record. | ||
1610 | * | ||
1611 | * @param edc editing context to use | ||
1612 | */ | ||
1613 | void | ||
1614 | GNS_edit_dialog_soa (struct EditDialogContext *edc) | ||
1615 | { | ||
1616 | char soa_rname[253 + 1]; | ||
1617 | char soa_mname[253 + 1]; | ||
1618 | unsigned int soa_serial; | ||
1619 | unsigned int soa_refresh; | ||
1620 | unsigned int soa_retry; | ||
1621 | unsigned int soa_expire; | ||
1622 | unsigned int soa_min; | ||
1623 | |||
1624 | edc->builder = GNUNET_GTK_get_new_builder ("gnunet_namestore_edit_soa.glade", | ||
1625 | edc); | ||
1626 | if (NULL == edc->builder) | ||
1627 | { | ||
1628 | GNUNET_break (0); | ||
1629 | edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ | ||
1630 | return; | ||
1631 | } | ||
1632 | if (GNUNET_YES == | ||
1633 | edc->old_record_in_namestore) | ||
1634 | { | ||
1635 | if (7 != SSCANF (edc->n_value, | ||
1636 | "rname=%253s mname=%253s %u,%u,%u,%u,%u", | ||
1637 | soa_rname, soa_mname, | ||
1638 | &soa_serial, &soa_refresh, &soa_retry, &soa_expire, &soa_min)) | ||
1639 | { | ||
1640 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1641 | _("Unable to parse SOA record `%s'\n"), | ||
1642 | edc->n_value); | ||
1643 | } | ||
1644 | else | ||
1645 | { | ||
1646 | /* set SOA record */ | ||
1647 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1648 | "edit_dialog_soa_source_host_entry")), | ||
1649 | soa_rname); | ||
1650 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1651 | "edit_dialog_soa_contact_email_entry")), | ||
1652 | soa_mname); | ||
1653 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
1654 | "edit_dialog_soa_serial_number_spinbutton")), | ||
1655 | soa_serial); | ||
1656 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
1657 | "edit_dialog_soa_refresh_time_spinbutton")), | ||
1658 | soa_refresh); | ||
1659 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
1660 | "edit_dialog_soa_retry_time_spinbutton")), | ||
1661 | soa_retry); | ||
1662 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
1663 | "edit_dialog_soa_expire_time_spinbutton")), | ||
1664 | soa_expire); | ||
1665 | gtk_spin_button_set_value (GTK_SPIN_BUTTON (gtk_builder_get_object (edc->builder, | ||
1666 | "edit_dialog_soa_minimum_ttl_spinbutton")), | ||
1667 | soa_min); | ||
1668 | } | ||
1669 | } | ||
1670 | edc->validator = &edit_dialog_soa_validity_check; | ||
1671 | edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder, | ||
1672 | "edit_soa_dialog")); | ||
1673 | run_edit_dialog (edc); | ||
1674 | } | ||
1675 | |||
1676 | |||
1677 | /* ************************ SRV records *********************** */ | ||
1678 | /* *** Not implemented: namestore_common.c as well as here! *** */ | ||
1679 | /* ************************ SRV records *********************** */ | ||
1680 | |||
1681 | /** | ||
1682 | * Check validity of the value in the edit dialog for SRV-records. | ||
1683 | * Then call the shared validity check if the result is OK. | ||
1684 | * | ||
1685 | * @param edc edit dialog context | ||
1686 | */ | ||
1687 | static void | ||
1688 | edit_dialog_srv_validity_check (struct EditDialogContext *edc) | ||
1689 | { | ||
1690 | GtkEditable *entry; | ||
1691 | const gchar *preedit; | ||
1692 | |||
1693 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
1694 | "edit_dialog_srv_target_entry")), | ||
1695 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
1696 | if ( (NULL == preedit) || | ||
1697 | (GNUNET_OK != GNUNET_DNSPARSER_check_name (preedit)) ) | ||
1698 | { | ||
1699 | edit_dialog_disable_save (edc); | ||
1700 | return; | ||
1701 | } | ||
1702 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
1703 | "edit_dialog_name_entry")), | ||
1704 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
1705 | #if 0 | ||
1706 | /* FIXME: check service name format! */ | ||
1707 | #endif | ||
1708 | edit_dialog_check_save (edc); | ||
1709 | } | ||
1710 | |||
1711 | |||
1712 | /** | ||
1713 | * Editing dialog was closed, get the data and call the | ||
1714 | * continuation. | ||
1715 | * | ||
1716 | * @param dialog editing dialog | ||
1717 | * @param response_id action that caused the dialog to be closed | ||
1718 | * @param user_data the 'struct EditDialogContext' | ||
1719 | */ | ||
1720 | void | ||
1721 | GNS_edit_srv_dialog_response_cb (GtkDialog *dialog, | ||
1722 | gint response_id, | ||
1723 | gpointer user_data) | ||
1724 | { | ||
1725 | struct EditDialogContext *edc = user_data; | ||
1726 | |||
1727 | if (GTK_RESPONSE_OK == response_id) | ||
1728 | { | ||
1729 | edit_dialog_putes_common_elements (edc); | ||
1730 | #if 0 | ||
1731 | GtkEntry *entry; | ||
1732 | const gchar *value; | ||
1733 | |||
1734 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1735 | "edit_dialog_srv_target_entry")); | ||
1736 | /* FIXME: build srv record */ | ||
1737 | value = gtk_entry_get_text (entry); | ||
1738 | g_free (edc->n_value); | ||
1739 | edc->n_value = g_strdup (value); | ||
1740 | #endif | ||
1741 | |||
1742 | } | ||
1743 | gtk_widget_destroy (GTK_WIDGET (edc->dialog)); | ||
1744 | g_object_unref (edc->builder); | ||
1745 | edc->builder = NULL; | ||
1746 | edc->cont (edc, response_id); | ||
1747 | } | ||
1748 | |||
1749 | |||
1750 | /** | ||
1751 | * The user has edited the SRV record value. Enable/disable 'save' | ||
1752 | * button depending on the validity of the value. | ||
1753 | * | ||
1754 | * @param entry editing widget | ||
1755 | * @param user_data the 'struct EditDialogContext' of the dialog | ||
1756 | */ | ||
1757 | void | ||
1758 | GNS_edit_dialog_srv_target_entry_changed_cb (GtkEditable *entry, | ||
1759 | gpointer user_data) | ||
1760 | { | ||
1761 | struct EditDialogContext *edc = user_data; | ||
1762 | |||
1763 | edit_dialog_srv_validity_check (edc); | ||
1764 | } | ||
1765 | |||
1766 | |||
1767 | /** | ||
1768 | * Run an GNS Edit dialog for an 'SRV' Record. | ||
1769 | * | ||
1770 | * @param edc editing context to use | ||
1771 | */ | ||
1772 | void | ||
1773 | GNS_edit_dialog_srv (struct EditDialogContext *edc) | ||
1774 | { | ||
1775 | edc->builder = GNUNET_GTK_get_new_builder ("gnunet_namestore_edit_srv.glade", | ||
1776 | edc); | ||
1777 | if (NULL == edc->builder) | ||
1778 | { | ||
1779 | GNUNET_break (0); | ||
1780 | edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ | ||
1781 | return; | ||
1782 | } | ||
1783 | if (GNUNET_YES == | ||
1784 | edc->old_record_in_namestore) | ||
1785 | { | ||
1786 | #if 0 | ||
1787 | /* FIXME */ | ||
1788 | /* set SRV record */ | ||
1789 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1790 | "edit_dialog_srv_target_entry")), | ||
1791 | edc->n_value); | ||
1792 | #endif | ||
1793 | } | ||
1794 | edc->validator = &edit_dialog_srv_validity_check; | ||
1795 | edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder, | ||
1796 | "edit_srv_dialog")); | ||
1797 | run_edit_dialog (edc); | ||
1798 | } | ||
1799 | |||
1800 | |||
1801 | /* ************************ TXT records *********************** */ | ||
1802 | |||
1803 | /** | ||
1804 | * Check validity of the value in the edit dialog for TXT-records. | ||
1805 | * Then call the shared validity check if the result is OK. | ||
1806 | * | ||
1807 | * @param edc edit dialog context | ||
1808 | */ | ||
1809 | static void | ||
1810 | edit_dialog_txt_validity_check (struct EditDialogContext *edc) | ||
1811 | { | ||
1812 | edit_dialog_check_save (edc); | ||
1813 | } | ||
1814 | |||
1815 | |||
1816 | /** | ||
1817 | * Editing dialog was closed, get the data and call the | ||
1818 | * continuation. | ||
1819 | * | ||
1820 | * @param dialog editing dialog | ||
1821 | * @param response_id action that caused the dialog to be closed | ||
1822 | * @param user_data the 'struct EditDialogContext' | ||
1823 | */ | ||
1824 | void | ||
1825 | GNS_edit_txt_dialog_response_cb (GtkDialog *dialog, | ||
1826 | gint response_id, | ||
1827 | gpointer user_data) | ||
1828 | { | ||
1829 | struct EditDialogContext *edc = user_data; | ||
1830 | GtkEntry *entry; | ||
1831 | const gchar *value; | ||
1832 | |||
1833 | if (GTK_RESPONSE_OK == response_id) | ||
1834 | { | ||
1835 | edit_dialog_putes_common_elements (edc); | ||
1836 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1837 | "edit_dialog_txt_entry")); | ||
1838 | value = gtk_entry_get_text (entry); | ||
1839 | g_free (edc->n_value); | ||
1840 | edc->n_value = g_strdup (value); | ||
1841 | } | ||
1842 | gtk_widget_destroy (GTK_WIDGET (edc->dialog)); | ||
1843 | g_object_unref (edc->builder); | ||
1844 | edc->builder = NULL; | ||
1845 | edc->cont (edc, response_id); | ||
1846 | } | ||
1847 | |||
1848 | |||
1849 | /** | ||
1850 | * The user has edited the TXT record value. Enable/disable 'save' | ||
1851 | * button depending on the validity of the value. | ||
1852 | * | ||
1853 | * @param entry editing widget | ||
1854 | * @param user_data the 'struct EditDialogContext' of the dialog | ||
1855 | */ | ||
1856 | void | ||
1857 | GNS_edit_dialog_txt_entry_changed_cb (GtkEditable *entry, | ||
1858 | gpointer user_data) | ||
1859 | { | ||
1860 | struct EditDialogContext *edc = user_data; | ||
1861 | |||
1862 | edit_dialog_txt_validity_check (edc); | ||
1863 | } | ||
1864 | |||
1865 | |||
1866 | /** | ||
1867 | * Run an GNS Edit dialog for an 'TXT' Record. | ||
1868 | * | ||
1869 | * @param edc editing context to use | ||
1870 | */ | ||
1871 | void | ||
1872 | GNS_edit_dialog_txt (struct EditDialogContext *edc) | ||
1873 | { | ||
1874 | edc->builder = GNUNET_GTK_get_new_builder ("gnunet_namestore_edit_txt.glade", | ||
1875 | edc); | ||
1876 | if (NULL == edc->builder) | ||
1877 | { | ||
1878 | GNUNET_break (0); | ||
1879 | edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ | ||
1880 | return; | ||
1881 | } | ||
1882 | if (GNUNET_YES == | ||
1883 | edc->old_record_in_namestore) | ||
1884 | { | ||
1885 | /* set TXT record */ | ||
1886 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1887 | "edit_dialog_txt_entry")), | ||
1888 | edc->n_value); | ||
1889 | } | ||
1890 | edc->validator = &edit_dialog_txt_validity_check; | ||
1891 | edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder, | ||
1892 | "edit_txt_dialog")); | ||
1893 | run_edit_dialog (edc); | ||
1894 | } | ||
1895 | |||
1896 | |||
1897 | /* ************************ VPN records *********************** */ | ||
1898 | |||
1899 | /** | ||
1900 | * Check validity of the value in the edit dialog for VPN-records. | ||
1901 | * Then call the shared validity check if the result is OK. | ||
1902 | * | ||
1903 | * @param edc edit dialog context | ||
1904 | */ | ||
1905 | static void | ||
1906 | edit_dialog_vpn_validity_check (struct EditDialogContext *edc) | ||
1907 | { | ||
1908 | GtkEditable *entry; | ||
1909 | const gchar *preedit; | ||
1910 | struct GNUNET_HashCode hc; | ||
1911 | |||
1912 | entry = GTK_EDITABLE (gtk_builder_get_object (edc->builder, | ||
1913 | "edit_dialog_vpn_peer_entry")), | ||
1914 | preedit = gtk_editable_get_chars (entry, 0, -1); | ||
1915 | if ( (NULL == preedit) || | ||
1916 | (GNUNET_OK != | ||
1917 | GNUNET_CRYPTO_hash_from_string (preedit, &hc)) ) | ||
1918 | { | ||
1919 | edit_dialog_disable_save (edc); | ||
1920 | return; | ||
1921 | } | ||
1922 | edit_dialog_check_save (edc); | ||
1923 | } | ||
1924 | |||
1925 | |||
1926 | /** | ||
1927 | * Editing dialog was closed, get the data and call the | ||
1928 | * continuation. | ||
1929 | * | ||
1930 | * @param dialog editing dialog | ||
1931 | * @param response_id action that caused the dialog to be closed | ||
1932 | * @param user_data the 'struct EditDialogContext' | ||
1933 | */ | ||
1934 | void | ||
1935 | GNS_edit_vpn_dialog_response_cb (GtkDialog *dialog, | ||
1936 | gint response_id, | ||
1937 | gpointer user_data) | ||
1938 | { | ||
1939 | struct EditDialogContext *edc = user_data; | ||
1940 | GtkEntry *entry; | ||
1941 | const gchar *identifier; | ||
1942 | const gchar *peer; | ||
1943 | unsigned int proto; | ||
1944 | char *result; | ||
1945 | |||
1946 | if (GTK_RESPONSE_OK == response_id) | ||
1947 | { | ||
1948 | edit_dialog_putes_common_elements (edc); | ||
1949 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1950 | "edit_dialog_vpn_identifier_entry")); | ||
1951 | identifier = gtk_entry_get_text (entry); | ||
1952 | entry = GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
1953 | "edit_dialog_vpn_peer_entry")); | ||
1954 | peer = gtk_entry_get_text (entry); | ||
1955 | proto = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, | ||
1956 | "edit_dialog_vpn_protocol_tcp_radiobutton"))) ? IPPROTO_TCP : IPPROTO_UDP; | ||
1957 | GNUNET_asprintf (&result, | ||
1958 | "%u %s %s", | ||
1959 | proto, | ||
1960 | (const char *) peer, | ||
1961 | (const char *) identifier); | ||
1962 | g_free (edc->n_value); | ||
1963 | edc->n_value = g_strdup (result); | ||
1964 | GNUNET_free (result); | ||
1965 | } | ||
1966 | gtk_widget_destroy (GTK_WIDGET (edc->dialog)); | ||
1967 | g_object_unref (edc->builder); | ||
1968 | edc->builder = NULL; | ||
1969 | edc->cont (edc, response_id); | ||
1970 | } | ||
1971 | |||
1972 | |||
1973 | /** | ||
1974 | * The user has edited the VPN record value. Enable/disable 'save' | ||
1975 | * button depending on the validity of the value. | ||
1976 | * | ||
1977 | * @param entry editing widget | ||
1978 | * @param user_data the 'struct EditDialogContext' of the dialog | ||
1979 | */ | ||
1980 | void | ||
1981 | GNS_edit_dialog_vpn_peer_entry_changed_cb (GtkEditable *entry, | ||
1982 | gpointer user_data) | ||
1983 | { | ||
1984 | struct EditDialogContext *edc = user_data; | ||
1985 | |||
1986 | edit_dialog_vpn_validity_check (edc); | ||
1987 | } | ||
1988 | |||
1989 | |||
1990 | /** | ||
1991 | * Run an GNS Edit dialog for an 'VPN' Record. | ||
1992 | * | ||
1993 | * @param edc editing context to use | ||
1994 | */ | ||
1995 | void | ||
1996 | GNS_edit_dialog_vpn (struct EditDialogContext *edc) | ||
1997 | { | ||
1998 | char s_peer[103 + 1]; | ||
1999 | char s_serv[253 + 1]; | ||
2000 | unsigned int proto; | ||
2001 | |||
2002 | edc->builder = GNUNET_GTK_get_new_builder ("gnunet_namestore_edit_vpn.glade", | ||
2003 | edc); | ||
2004 | if (NULL == edc->builder) | ||
2005 | { | ||
2006 | GNUNET_break (0); | ||
2007 | edc->cont (edc, GTK_RESPONSE_CANCEL); /* treat as 'cancel' */ | ||
2008 | return; | ||
2009 | } | ||
2010 | if (GNUNET_YES == | ||
2011 | edc->old_record_in_namestore) | ||
2012 | { | ||
2013 | /* set VPN record */ | ||
2014 | if (3 != SSCANF (edc->n_value,"%u %103s %253s", | ||
2015 | &proto, s_peer, s_serv)) | ||
2016 | { | ||
2017 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2018 | _("Unable to parse VPN record string `%s'\n"), | ||
2019 | edc->n_value); | ||
2020 | } | ||
2021 | else | ||
2022 | { | ||
2023 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
2024 | "edit_dialog_vpn_identifier_entry")), | ||
2025 | s_serv); | ||
2026 | gtk_entry_set_text (GTK_ENTRY (gtk_builder_get_object (edc->builder, | ||
2027 | "edit_dialog_vpn_peer_entry")), | ||
2028 | s_peer); | ||
2029 | if (IPPROTO_UDP == proto) | ||
2030 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, | ||
2031 | "edit_dialog_vpn_protocol_udp_radiobutton")), TRUE); | ||
2032 | else | ||
2033 | gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gtk_builder_get_object (edc->builder, | ||
2034 | "edit_dialog_vpn_protocol_tcp_radiobutton")), TRUE); | ||
2035 | } | ||
2036 | } | ||
2037 | edc->validator = &edit_dialog_vpn_validity_check; | ||
2038 | edc->dialog = GTK_DIALOG (gtk_builder_get_object (edc->builder, | ||
2039 | "edit_vpn_dialog")); | ||
2040 | run_edit_dialog (edc); | ||
2041 | } | ||
2042 | |||
2043 | 94 | ||
2044 | /* end of gnunet-namestore-gtk_edit.c */ | 95 | /* end of gnunet-namestore-gtk_edit.c */ |