[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r29987 - gnunet-gtk/src/setup
From: |
gnunet |
Subject: |
[GNUnet-SVN] r29987 - gnunet-gtk/src/setup |
Date: |
Tue, 8 Oct 2013 14:48:07 +0200 |
Author: grothoff
Date: 2013-10-08 14:48:06 +0200 (Tue, 08 Oct 2013)
New Revision: 29987
Added:
gnunet-gtk/src/setup/gnunet-setup-exit-services.c
Removed:
gnunet-gtk/src/setup/gnunet-setup-dns-exit.c
Modified:
gnunet-gtk/src/setup/gnunet-setup.h
Log:
-towards fixing #2796
Deleted: gnunet-gtk/src/setup/gnunet-setup-dns-exit.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-dns-exit.c 2013-10-08 12:19:42 UTC
(rev 29986)
+++ gnunet-gtk/src/setup/gnunet-setup-dns-exit.c 2013-10-08 12:48:06 UTC
(rev 29987)
@@ -1,749 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file src/setup/gnunet-setup-dns-exit.c
- * @brief code for the dialog to configure GNS-EXIT records
- * @author Christian Grothoff
- */
-#include "gnunet-setup.h"
-#include <gnunet/gnunet_util_lib.h>
-#include <gdk/gdkkeysyms.h>
-
-
-/**
- * Check if the section represents a DNS entry and then update the
- * GtkListStore accordingly.
- *
- * @param cls the list store to modify
- * @param section name of the section
- */
-static void
-add_dns_entry_to_list_store (void *cls, const char *section)
-{
- GtkListStore *ls = cls;
- GtkTreeIter iter;
- char *sld;
- char *hostname;
- char *hostport;
- char *redirect;
- char *cpy;
- gboolean udp;
-
- if (NULL == section)
- {
- gtk_list_store_insert_with_values (ls, &iter, G_MAXINT,
- GNUNET_GTK_SETUP_GNS_MC_HOSTNAME, "",
- GNUNET_GTK_SETUP_GNS_MC_SOURCEPORT,
- (guint) 80,
- GNUNET_GTK_SETUP_GNS_MC_TARGETPORT,
- (guint) 8080,
- GNUNET_GTK_SETUP_GNS_MC_HOSTNAME,
- "localhost4",
- GNUNET_GTK_SETUP_GNS_MC_ISUDP, "tcp",
- -1);
- return;
- }
-
- if ((8 > strlen (section)) ||
- (0 != strcmp (".gnunet.", section + ((strlen (section) - 8)))))
- return;
- sld = GNUNET_strdup (section);
- sld[strlen (section) - 8] = '\0';
- udp = FALSE;
- do
- {
- if (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg, section,
- (TRUE ==
- udp) ? "UDP_REDIRECTS" :
- "TCP_REDIRECTS", &cpy))
- {
- for (redirect = strtok (cpy, " "); redirect != NULL;
- redirect = strtok (NULL, " "))
- {
- if (NULL == (hostname = strstr (redirect, ":")))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Option `%s' is not formatted correctly!\n"),
redirect);
- continue;
- }
- hostname[0] = '\0';
- hostname++;
- if (NULL == (hostport = strstr (hostname, ":")))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Option `%s' is not formatted correctly!\n"),
redirect);
- continue;
- }
- hostport[0] = '\0';
- hostport++;
-
- int local_port = atoi (redirect);
-
- if (!((local_port > 0) && (local_port < 65536)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("`%s' is not a valid port number!\n"), redirect);
- continue;
- }
- int host_port = atoi (hostport);
-
- if (!((host_port > 0) && (host_port < 65536)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("`%s' is not a valid port number!\n"), hostport);
- continue;
- }
- gtk_list_store_insert_with_values (ls, &iter, 0,
- GNUNET_GTK_SETUP_GNS_MC_HOSTNAME,
- sld,
- GNUNET_GTK_SETUP_GNS_MC_SOURCEPORT,
- (guint) local_port,
- GNUNET_GTK_SETUP_GNS_MC_TARGETPORT,
- (guint) host_port,
-
GNUNET_GTK_SETUP_GNS_MC_TARGETHOSTNAME,
- hostname,
- GNUNET_GTK_SETUP_GNS_MC_ISUDP,
- (TRUE == udp) ? "udp" : "tcp", -1);
- }
- GNUNET_free (cpy);
- }
- udp = !udp;
- }
- while (udp != FALSE);
- GNUNET_free (sld);
-}
-
-
-/**
- * Initialize the GtkListModel with the VPN's DNS service specification.
- *
- * @param cls NULL
- * @param section section with the value (NULL)
- * @param option option name (NULL)
- * @param value value as a string (NULL)
- * @param widget widget to initialize (the GtkTreeView)
- * @param cfg configuration handle
- * @return GNUNET_OK on success, GNUNET_SYSERR if there was a problem
- */
-static int
-load_vpn_dns_configuration (const void *cls, const char *section,
- const char *option, const char *value,
- GObject * widget,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- GtkTreeView *tv;
- GtkListStore *ls;
-
- tv = GTK_TREE_VIEW (widget);
- if (tv == NULL)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- ls = GTK_LIST_STORE (gtk_tree_view_get_model (tv));
- GNUNET_CONFIGURATION_iterate_sections (cfg, &add_dns_entry_to_list_store,
ls);
- /* finally, add empty entry */
- add_dns_entry_to_list_store (ls, NULL);
- return GNUNET_OK;
-}
-
-
-/**
- * Records we use to build DNS information lists.
- */
-struct DnsInfo
-{
- struct DnsInfo *next;
- char *section;
- char *altnames;
- char *tcpred;
- char *udpred;
- unsigned long long ttl;
-};
-
-
-/**
- * Function called for each section in the configuration.
- * Gather existing ttl, section names and altnames.
- *
- * @param cls 'struct DnsInfo**' to create
- * @param section name of a section in the configuration
- */
-static void
-collect_dns_sections (void *cls, const char *section)
-{
- struct DnsInfo **base = cls;
- struct DnsInfo *pos;
-
- if ((8 > strlen (section)) ||
- (0 != strcmp (".gnunet.", section + ((strlen (section) - 8)))))
- return;
- pos = GNUNET_malloc (sizeof (struct DnsInfo));
- pos->section = GNUNET_strdup (section);
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg, section, "TTL", &pos->ttl))
- pos->ttl = 3600000;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg, section, "ALTERNATIVE_NAMES",
- &pos->altnames))
- pos->altnames = NULL;
- pos->tcpred = GNUNET_strdup ("");
- pos->udpred = GNUNET_strdup ("");
- pos->next = *base;
- *base = pos;
-}
-
-
-/**
- * Function called for each section in the configuration.
- * Removes those ending in '.gnunet.'.
- *
- * @param cls unused
- * @param section name of a section in the configuration
- */
-static void
-remove_dns_sections (void *cls, const char *section)
-{
- if ((8 > strlen (section)) ||
- (0 != strcmp (".gnunet.", section + ((strlen (section) - 8)))))
- return;
- GNUNET_CONFIGURATION_remove_section (cfg, section);
-}
-
-
-/**
- * Given the list store and the data in it, update the
- * configuration file accordingly.
- *
- * @param tm model to use
- */
-static void
-update_vpn_dns_configuration (GtkTreeModel * tm)
-{
- GtkTreeIter iter;
- gchar *hostname;
- guint srcport;
- guint targetport;
- gchar *targethost;
- gchar *tcpudp;
- char *tmp;
- struct DnsInfo *head;
- struct DnsInfo *pos;
-
- head = NULL;
- GNUNET_CONFIGURATION_iterate_sections (cfg, &collect_dns_sections, &head);
- if (TRUE == gtk_tree_model_get_iter_first (tm, &iter))
- do
- {
- gtk_tree_model_get (tm, &iter,
- GNUNET_GTK_SETUP_GNS_MC_HOSTNAME, &hostname,
- GNUNET_GTK_SETUP_GNS_MC_SOURCEPORT, &srcport,
- GNUNET_GTK_SETUP_GNS_MC_TARGETPORT, &targetport,
- GNUNET_GTK_SETUP_GNS_MC_TARGETHOSTNAME, &targethost,
- GNUNET_GTK_SETUP_GNS_MC_ISUDP, &tcpudp,
- -1);
- if (0 != strlen (hostname))
- {
- pos = head;
- GNUNET_asprintf (&tmp, "%s.gnunet.", hostname);
- while ((NULL != pos) && (0 != strcasecmp (tmp, pos->section)))
- pos = pos->next;
- if (pos == NULL)
- {
- pos = GNUNET_malloc (sizeof (struct DnsInfo));
- pos->section = tmp;
- pos->ttl = 3600000;
- pos->altnames = NULL;
- pos->tcpred = GNUNET_strdup ("");
- pos->udpred = GNUNET_strdup ("");
- pos->next = head;
- head = pos;
- }
- else
- {
- GNUNET_free (tmp);
- }
- GNUNET_asprintf (&tmp, "%u:%s:%u %s", srcport, targethost, targetport,
- (0 ==
- strcasecmp ("tcp",
- tcpudp)) ? pos->tcpred : pos->udpred);
- if (0 == strcasecmp ("tcp", tcpudp))
- {
- GNUNET_free (pos->tcpred);
- pos->tcpred = tmp;
- }
- else
- {
- GNUNET_free (pos->udpred);
- pos->udpred = tmp;
- }
- }
- g_free (tcpudp);
- g_free (hostname);
- g_free (targethost);
- }
- while (TRUE == gtk_tree_model_iter_next (tm, &iter));
- GNUNET_CONFIGURATION_iterate_sections (cfg, &remove_dns_sections, NULL);
- while (NULL != head)
- {
- pos = head;
- head = pos->next;
- if (pos->altnames != NULL)
- GNUNET_CONFIGURATION_set_value_string (cfg, pos->section,
- "ALTERNATIVE_NAMES",
- pos->altnames);
- if (strlen (pos->udpred) > 0)
- GNUNET_CONFIGURATION_set_value_string (cfg, pos->section,
"UDP_REDIRECTS",
- pos->udpred);
- if (strlen (pos->tcpred) > 0)
- GNUNET_CONFIGURATION_set_value_string (cfg, pos->section,
"TCP_REDIRECTS",
- pos->tcpred);
- if ((strlen (pos->udpred) > 0) || (strlen (pos->tcpred) > 0))
- GNUNET_CONFIGURATION_set_value_number (cfg, pos->section, "TTL",
- pos->ttl);
- GNUNET_free_non_null (pos->altnames);
- GNUNET_free (pos->tcpred);
- GNUNET_free (pos->udpred);
- GNUNET_free (pos->section);
- GNUNET_free (pos);
- }
-}
-
-
-/**
- * The user has edited the DNS name of a service we're offering.
- * Update the GtkTreeModel (at the given path) and update the
- * respective service entry in the configuration file. Finally,
- * if the edited path is for a "fresh" entry, create another empty
- * one at the bottom. If the hostname was set to empty, remove
- * the entire entry from the configuration and the model.
- *
- * @param renderer GtkCellRendererText that changed
- * @param path GtkTreePath identifying where in the Model the change is
- * @param new_text the new text that was stored in the line
- * @param user_data NULL
- */
-static void
-save_vpn_dns_service_dnsname (GtkCellRendererText * renderer, gchar * path,
- gchar * new_text, gpointer user_data)
-{
- GtkTreeModel *tm;
- GtkListStore *ls;
- GtkTreeIter iter;
- gchar *old;
-
- tm = GTK_TREE_MODEL (GNUNET_SETUP_get_object ("GNUNET_setup_gns_liststore"));
- if (NULL == tm)
- {
- GNUNET_break (0);
- return;
- }
- ls = GTK_LIST_STORE (tm);
- if (NULL == ls)
- {
- GNUNET_break (0);
- return;
- }
- if (TRUE != gtk_tree_model_get_iter_from_string (tm, &iter, path))
- {
- GNUNET_break (0);
- return;
- }
- gtk_tree_model_get (tm, &iter, GNUNET_GTK_SETUP_GNS_MC_HOSTNAME, &old, -1);
- if ((0 != strlen (old)) && (0 == strlen (new_text)))
- {
- /* deletion */
- gtk_list_store_remove (ls, &iter);
- g_free (old);
- /* update configuration */
- update_vpn_dns_configuration (tm);
- return;
- }
- /* update model */
- gtk_list_store_set (ls, &iter,
- GNUNET_GTK_SETUP_GNS_MC_HOSTNAME, new_text, -1);
- /* update configuration */
- update_vpn_dns_configuration (tm);
- if ((0 == strlen (old)) && (0 != strlen (new_text)))
- {
- /* need another empty entry at the end for future expansion */
- add_dns_entry_to_list_store (GTK_LIST_STORE (tm), NULL);
- }
- g_free (old);
-}
-
-
-/**
- * Initialize the GtkListModel with the VPN's DNS service specification.
- *
- * @param cls NULL
- * @param section section with the value (NULL)
- * @param option option name (NULL)
- * @param widget widget to initialize (the GtkTreeView)
- * @param cfg configuration handle
- * @return GNUNET_OK on success, GNUNET_SYSERR if there was a problem
- */
-static int
-gns_name_install_edited_handler (const void *cls,
- const char *section,
- const char *option,
- GObject * widget,
- struct
- GNUNET_CONFIGURATION_Handle
- *cfg)
-{
- static int once;
- GtkCellRendererText *rt;
-
- rt = GTK_CELL_RENDERER_TEXT (widget);
- if (NULL == rt)
- return GNUNET_SYSERR;
- if (0 != once++)
- return GNUNET_OK;
- g_signal_connect (rt, "edited", G_CALLBACK (&save_vpn_dns_service_dnsname),
- NULL);
- return GNUNET_OK;
-}
-
-
-/**
- * The user has edited the DNS name of a service we're offering.
- * Update the GtkTreeModel (at the given path) and update the
- * respective service entry in the configuration file. Finally,
- * if the edited path is for a "fresh" entry, create another empty
- * one at the bottom. If the hostname was set to empty, remove
- * the entire entry from the configuration and the model.
- *
- * @param renderer GtkCellRendererText that changed
- * @param path GtkTreePath identifying where in the Model the change is
- * @param new_text the new text that was stored in the line
- * @param user_data NULL
- */
-static void
-save_vpn_dns_service_tcpudp (GtkCellRendererText * renderer, gchar * path,
- gchar * new_text, gpointer user_data)
-{
- GtkTreeModel *tm;
- GtkListStore *ls;
- GtkTreeIter iter;
-
- if ((0 != strcasecmp ("tcp", new_text)) &&
- (0 != strcasecmp ("udp", new_text)))
- {
- /* FIXME: warn... */
- return;
- }
- tm = GTK_TREE_MODEL (GNUNET_SETUP_get_object ("GNUNET_setup_gns_liststore"));
- if (NULL == tm)
- {
- GNUNET_break (0);
- return;
- }
- ls = GTK_LIST_STORE (tm);
- if (NULL == ls)
- {
- GNUNET_break (0);
- return;
- }
- if (TRUE != gtk_tree_model_get_iter_from_string (tm, &iter, path))
- {
- GNUNET_break (0);
- return;
- }
- /* update model */
- gtk_list_store_set (ls, &iter, GNUNET_GTK_SETUP_GNS_MC_ISUDP, new_text, -1);
- /* update configuration */
- update_vpn_dns_configuration (tm);
-}
-
-
-/**
- * Initialize the GtkListModel with the VPN's DNS service specification.
- *
- * @param cls NULL
- * @param section section with the value (NULL)
- * @param option option name (NULL)
- * @param widget widget to initialize (the GtkTreeView)
- * @param cfg configuration handle
- * @return GNUNET_OK on success, GNUNET_SYSERR if there was a problem
- */
-static int
-gns_type_install_edited_handler (const void *cls,
- const char *section,
- const char *option,
- GObject * widget,
- struct
- GNUNET_CONFIGURATION_Handle
*cfg)
-{
- static int once;
- GtkCellRendererText *rt;
-
- rt = GTK_CELL_RENDERER_TEXT (widget);
- if (NULL == rt)
- return GNUNET_SYSERR;
- if (0 != once++)
- return GNUNET_OK;
- g_signal_connect (rt, "edited", G_CALLBACK (&save_vpn_dns_service_tcpudp),
- NULL);
- return GNUNET_OK;
-}
-
-
-/**
- * The user has edited the DNS name of a service we're offering.
- * Update the GtkTreeModel (at the given path) and update the
- * respective service entry in the configuration file. Finally,
- * if the edited path is for a "fresh" entry, create another empty
- * one at the bottom. If the hostname was set to empty, remove
- * the entire entry from the configuration and the model.
- *
- * @param renderer GtkCellRendererText that changed
- * @param path GtkTreePath identifying where in the Model the change is
- * @param new_text the new text that was stored in the line
- * @param user_data NULL
- */
-static void
-save_vpn_dns_service_sourceport (GtkCellRendererText * renderer, gchar * path,
- gchar * new_text, gpointer user_data)
-{
- GtkTreeModel *tm;
- GtkListStore *ls;
- GtkTreeIter iter;
- int port;
-
- port = atoi (new_text);
- if ((port < 1) || (port > UINT16_MAX))
- {
- /* invalid port, FIXME: warn */
- return;
- }
- tm = GTK_TREE_MODEL (GNUNET_SETUP_get_object ("GNUNET_setup_gns_liststore"));
- if (NULL == tm)
- {
- GNUNET_break (0);
- return;
- }
- ls = GTK_LIST_STORE (tm);
- if (NULL == ls)
- {
- GNUNET_break (0);
- return;
- }
- if (TRUE != gtk_tree_model_get_iter_from_string (tm, &iter, path))
- {
- GNUNET_break (0);
- return;
- }
- /* update model */
- gtk_list_store_set (ls, &iter,
- GNUNET_GTK_SETUP_GNS_MC_SOURCEPORT, (guint) port, -1);
- /* update configuration */
- update_vpn_dns_configuration (tm);
-}
-
-
-/**
- * Initialize the GtkListModel with the VPN's DNS service specification.
- *
- * @param cls NULL
- * @param section section with the value (NULL)
- * @param option option name (NULL)
- * @param widget widget to initialize (the GtkTreeView)
- * @param cfg configuration handle
- * @return GNUNET_OK on success, GNUNET_SYSERR if there was a problem
- */
-static int
-gns_ttl_install_edited_handler (const void *cls,
- const char *section,
- const char *option,
- GObject * widget,
- struct
- GNUNET_CONFIGURATION_Handle
- *cfg)
-{
- static int once;
- GtkCellRendererText *rt;
-
- rt = GTK_CELL_RENDERER_TEXT (widget);
- if (NULL == rt)
- return GNUNET_SYSERR;
- if (0 != once++)
- return GNUNET_OK;
- g_signal_connect (rt, "edited", G_CALLBACK
(&save_vpn_dns_service_sourceport),
- NULL);
- return GNUNET_OK;
-}
-
-
-/**
- * The user has edited the DNS name of a service we're offering.
- * Update the GtkTreeModel (at the given path) and update the
- * respective service entry in the configuration file. Finally,
- * if the edited path is for a "fresh" entry, create another empty
- * one at the bottom. If the hostname was set to empty, remove
- * the entire entry from the configuration and the model.
- *
- * @param renderer GtkCellRendererText that changed
- * @param path GtkTreePath identifying where in the Model the change is
- * @param new_text the new text that was stored in the line
- * @param user_data NULL
- */
-static void
-save_vpn_dns_service_targethostname (GtkCellRendererText * renderer,
- gchar * path, gchar * new_text,
- gpointer user_data)
-{
- GtkTreeModel *tm;
- GtkListStore *ls;
- GtkTreeIter iter;
-
- tm = GTK_TREE_MODEL (GNUNET_SETUP_get_object ("GNUNET_setup_gns_liststore"));
- if (NULL == tm)
- {
- GNUNET_break (0);
- return;
- }
- ls = GTK_LIST_STORE (tm);
- if (NULL == ls)
- {
- GNUNET_break (0);
- return;
- }
- if (TRUE != gtk_tree_model_get_iter_from_string (tm, &iter, path))
- {
- GNUNET_break (0);
- return;
- }
- /* update model */
- gtk_list_store_set (ls, &iter,
- GNUNET_GTK_SETUP_GNS_MC_TARGETHOSTNAME, new_text, -1);
- /* update configuration */
- update_vpn_dns_configuration (tm);
-}
-
-
-/**
- * Initialize the GtkListModel with the VPN's DNS service specification.
- *
- * @param cls NULL
- * @param section section with the value (NULL)
- * @param option option name (NULL)
- * @param widget widget to initialize (the GtkTreeView)
- * @param cfg configuration handle
- * @return GNUNET_OK on success, GNUNET_SYSERR if there was a problem
- */
-static int
-gns_value_install_edited_handler (const void *cls,
- const char *section,
- const char *option,
- GObject * widget,
- struct
- GNUNET_CONFIGURATION_Handle
- *cfg)
-{
- static int once;
- GtkCellRendererText *rt;
-
- rt = GTK_CELL_RENDERER_TEXT (widget);
- if (NULL == rt)
- return GNUNET_SYSERR;
- if (0 != once++)
- return GNUNET_OK;
- g_signal_connect (rt, "edited",
- G_CALLBACK (&save_vpn_dns_service_targethostname), NULL);
- return GNUNET_OK;
-}
-
-
-#if 0
- {
- "GNUNET_setup_gns_treeview",
- NULL,
- NULL,
- NULL,
- gettext_noop
- ("Specification of .gnunet TLD"),
- "https://gnunet.org/configuration-dns",
- &load_vpn_dns_configuration,
- NULL, NULL,
- NULL, NULL,
- NULL},
-
- {
- "GNUNET_setup_gns_name_cellrenderertext",
- "editing-started",
- NULL,
- NULL,
- NULL,
- "https://gnunet.org/configuration-dns",
- NULL,
- &gns_name_install_edited_handler,
- NULL,
- NULL,
- NULL,
- NULL},
-
- {
- "GNUNET_setup_gns_type_cellrenderertext",
- "editing-started",
- NULL,
- NULL,
- NULL,
- "https://gnunet.org/configuration-dns",
- NULL,
- &gns_type_install_edited_handler,
- NULL,
- NULL,
- NULL,
- NULL},
-
- {
- "GNUNET_setup_gns_ttl_cellrenderertext",
- "editing-started",
- NULL,
- NULL,
- NULL,
- "https://gnunet.org/configuration-dns",
- NULL,
- &gns_ttl_install_edited_handler,
- NULL,
- NULL,
- NULL,
- NULL},
-
- {
- "GNUNET_setup_gns_value_cellrenderertext",
- "editing-started",
- NULL,
- NULL,
- NULL,
- "https://gnunet.org/configuration-dns",
- NULL,
- &gns_value_install_edited_handler,
- NULL,
- NULL,
- NULL,
- NULL},
-
-#endif
-
-/* end of gnunet-setup-dns-exit.c */
Added: gnunet-gtk/src/setup/gnunet-setup-exit-services.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-exit-services.c
(rev 0)
+++ gnunet-gtk/src/setup/gnunet-setup-exit-services.c 2013-10-08 12:48:06 UTC
(rev 29987)
@@ -0,0 +1,762 @@
+/*
+ This file is part of GNUnet.
+ (C) 2013 Christian Grothoff (and other contributing authors)
+
+ GNUnet is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNUnet; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file src/setup/gnunet-setup-exit-services.c
+ * @brief code for the dialog to configure EXIT records
+ * @author Christian Grothoff
+ */
+#include "gnunet-setup.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gdk/gdkkeysyms.h>
+
+
+/**
+ * Columns in the hosted service model.
+ */
+enum ServiceModelColumns
+{
+ /**
+ * A gchararray
+ */
+ SERVICE_MC_HOSTNAME = 0,
+
+ /**
+ * A gboolean
+ */
+ SERVICE_MC_ISUDP = 1
+
+ /**
+ * A guint
+ */
+ SERVICE_MC_VISIBLE_PORT = 2,
+
+ /**
+ * Destination adddress, a gchararray
+ */
+ SERVICE_MC_DESTINATION_ADDRESS = 3
+
+};
+
+
+/**
+ * Check if the section represents a hosted service and then update
+ * the GtkListStore accordingly.
+ *
+ * @param cls the list store to modify
+ * @param section name of the section
+ */
+static void
+add_dns_entry_to_list_store (void *cls,
+ const char *section)
+{
+ GtkListStore *ls = cls;
+ GtkTreeIter iter;
+ char *sld;
+ char *destination;
+ char *redirect;
+ char *cpy;
+ gboolean udp;
+
+ if (NULL == section)
+ {
+ gtk_list_store_insert_with_values (ls, &iter, G_MAXINT,
+ SERVICE_MC_HOSTNAME, "",
+ SERVICE_MC_ISUDP, FALSE,
+ SERVICE_MC_VISIBLE_PORT, (guint) 80,
+ SERVICE_MC_DESTINATION_ADDRESS,
"127.0.0.1:8080",
+ -1);
+ return;
+ }
+
+ if ((8 > strlen (section)) ||
+ (0 != strcmp (".gnunet.", section + ((strlen (section) - 8)))))
+ return;
+ sld = GNUNET_strdup (section);
+ sld[strlen (section) - 8] = '\0';
+ udp = FALSE;
+ do
+ {
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, section,
+ (udp)
+ ? "UDP_REDIRECTS"
+ : "TCP_REDIRECTS",
+ &cpy))
+ {
+ for (redirect = strtok (cpy, " "); NULL != redirect;
+ redirect = strtok (NULL, " "))
+ {
+ if (NULL == (hostname = strstr (redirect, ":")))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("Option `%s' is not formatted correctly!\n"),
redirect);
+ continue;
+ }
+ hostname[0] = '\0';
+ hostname++;
+
+ guint local_port = atoi (redirect);
+ if (!((local_port > 0) && (local_port < 65536)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ _("`%s' is not a valid port number!\n"), redirect);
+ continue;
+ }
+ gtk_list_store_insert_with_values (ls, &iter, 0,
+ SERVICE_MC_HOSTNAME, sld,
+ SERVICE_MC_ISUDP, udp,
+ SERVICE_MC_VISIBLE_PORT, local_port,
+ SERVICE_MC_DESTINATION_ADDRESS,
hostname,
+ -1);
+ }
+ GNUNET_free (cpy);
+ }
+ udp = !udp;
+ }
+ while (udp);
+ GNUNET_free (sld);
+}
+
+
+/**
+ * Initialize the GtkListModel with the hosted service specification.
+ *
+ * @param cls NULL
+ * @param section section with the value (NULL)
+ * @param option option name (NULL)
+ * @param value value as a string (NULL)
+ * @param widget widget to initialize (the GtkTreeView)
+ * @param cfg configuration handle
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if there was a problem
+ */
+static int
+load_hosted_service_configuration (const void *cls,
+ const char *section,
+ const char *option,
+ const char *value,
+ GObject * widget,
+ const struct GNUNET_CONFIGURATION_Handle
*cfg)
+{
+ GtkTreeView *tv;
+ GtkListStore *ls;
+
+ tv = GTK_TREE_VIEW (widget);
+ if (NULL == tv)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ ls = GTK_LIST_STORE (gtk_tree_view_get_model (tv));
+ GNUNET_CONFIGURATION_iterate_sections (cfg,
+ &add_dns_entry_to_list_store,
+ ls);
+ /* finally, add empty entry */
+ add_dns_entry_to_list_store (ls, NULL);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Records we use to build DNS information lists.
+ */
+struct DnsInfo
+{
+ /**
+ * We keep these in a singly-linked list.
+ */
+ struct DnsInfo *next;
+
+ /**
+ * Name of the section in the configuration (must end in ".gnunet.").
+ */
+ char *section;
+
+ /**
+ * String describing all TCP redirects.
+ */
+ char *tcpred;
+
+ /**
+ * String describing all UDP redirects.
+ */
+ char *udpred;
+
+};
+
+
+/**
+ * Function called for each section in the configuration.
+ * Gather existing ttl, section names and altnames.
+ *
+ * @param cls 'struct DnsInfo**' to create
+ * @param section name of a section in the configuration
+ */
+static void
+collect_dns_sections (void *cls,
+ const char *section)
+{
+ struct DnsInfo **base = cls;
+ struct DnsInfo *pos;
+
+ if ((8 > strlen (section)) ||
+ (0 != strcmp (".gnunet.",
+ section + ((strlen (section) - 8)))))
+ return;
+ pos = GNUNET_new (struct DnsInfo);
+ pos->section = GNUNET_strdup (section);
+ pos->tcpred = GNUNET_strdup ("");
+ pos->udpred = GNUNET_strdup ("");
+ pos->next = *base;
+ *base = pos;
+}
+
+
+/**
+ * Function called for each section in the configuration.
+ * Removes those ending in '.gnunet.'.
+ *
+ * @param cls unused
+ * @param section name of a section in the configuration
+ */
+static void
+remove_dns_sections (void *cls,
+ const char *section)
+{
+ if ((8 > strlen (section)) ||
+ (0 != strcmp (".gnunet.", section + ((strlen (section) - 8)))))
+ return;
+ GNUNET_CONFIGURATION_remove_section (cfg, section);
+}
+
+
+/**
+ * Given the list store and the data in it, update the
+ * configuration file accordingly.
+ *
+ * @param tm model to use
+ */
+static void
+update_vpn_dns_configuration (GtkTreeModel * tm)
+{
+ GtkTreeIter iter;
+ gchar *name;
+ guint srcport;
+ gchar *targetaddress;
+ gboolea is_udp;
+ char *tmp;
+ struct DnsInfo *head;
+ struct DnsInfo *pos;
+
+ head = NULL;
+ GNUNET_CONFIGURATION_iterate_sections (cfg,
+ &collect_dns_sections,
+ &head);
+ if (gtk_tree_model_get_iter_first (tm, &iter))
+ do
+ {
+ gtk_tree_model_get (tm, &iter,
+ SERVICE_MC_HOSTNAME, &name,
+ SERVICE_MC_ISUDP, &is_udp,
+ SERVICE_MC_VISIBLE_PORT, &srcport,
+ SERVICE_MC_DESTINATION_ADDRESS, &targetaddress,
+ -1);
+ if (0 != strlen (name))
+ {
+ pos = head;
+ GNUNET_asprintf (&tmp, "%s.gnunet.", name);
+ while ((NULL != pos) && (0 != strcasecmp (tmp, pos->section)))
+ pos = pos->next;
+ if (NULL == pos)
+ {
+ pos = GNUNET_new (struct DnsInfo);
+ pos->section = tmp;
+ pos->tcpred = GNUNET_strdup ("");
+ pos->udpred = GNUNET_strdup ("");
+ pos->next = head;
+ head = pos;
+ }
+ else
+ {
+ GNUNET_free (tmp);
+ }
+ GNUNET_asprintf (&tmp,
+ "%u:%s %s",
+ srcport,
+ targetaddress,
+ (is_udp)
+ ? pos->udpred
+ : pos->tcpred);
+ if (is_udp)
+ {
+ GNUNET_free (pos->udpred);
+ pos->udpred = tmp;
+ }
+ else
+ {
+ GNUNET_free (pos->tcpred);
+ pos->tcpred = tmp;
+ }
+ }
+ g_free (name);
+ g_free (targetaddress);
+ }
+ while (TRUE == gtk_tree_model_iter_next (tm, &iter));
+ GNUNET_CONFIGURATION_iterate_sections (cfg,
+ &remove_dns_sections,
+ NULL);
+ while (NULL != head)
+ {
+ pos = head;
+ head = pos->next;
+ if (strlen (pos->udpred) > 0)
+ GNUNET_CONFIGURATION_set_value_string (cfg, pos->section,
+ "UDP_REDIRECTS",
+ pos->udpred);
+ if (strlen (pos->tcpred) > 0)
+ GNUNET_CONFIGURATION_set_value_string (cfg, pos->section,
+ "TCP_REDIRECTS",
+ pos->tcpred);
+ GNUNET_free (pos->tcpred);
+ GNUNET_free (pos->udpred);
+ GNUNET_free (pos->section);
+ GNUNET_free (pos);
+ }
+}
+
+
+/**
+ * The user has edited the DNS name of a service we're offering.
+ * Update the GtkTreeModel (at the given path) and update the
+ * respective service entry in the configuration file. Finally,
+ * if the edited path is for a "fresh" entry, create another empty
+ * one at the bottom. If the hostname was set to empty, remove
+ * the entire entry from the configuration and the model.
+ *
+ * @param renderer GtkCellRendererText that changed
+ * @param path GtkTreePath identifying where in the Model the change is
+ * @param new_text the new text that was stored in the line
+ * @param user_data NULL
+ */
+static void
+save_vpn_dns_service_dnsname (GtkCellRendererText * renderer,
+ gchar * path,
+ gchar * new_text,
+ gpointer user_data)
+{
+ GtkTreeModel *tm;
+ GtkListStore *ls;
+ GtkTreeIter iter;
+ gchar *old;
+
+ tm = GTK_TREE_MODEL (GNUNET_SETUP_get_object ("GNUNET_setup_gns_liststore"));
+ if (NULL == tm)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ ls = GTK_LIST_STORE (tm);
+ if (NULL == ls)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (TRUE != gtk_tree_model_get_iter_from_string (tm, &iter, path))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ gtk_tree_model_get (tm, &iter, SERVICE_MC_HOSTNAME, &old, -1);
+ if ((0 != strlen (old)) && (0 == strlen (new_text)))
+ {
+ /* deletion */
+ gtk_list_store_remove (ls, &iter);
+ g_free (old);
+ /* update configuration */
+ update_vpn_dns_configuration (tm);
+ return;
+ }
+ /* update model */
+ gtk_list_store_set (ls, &iter,
+ SERVICE_MC_HOSTNAME, new_text, -1);
+ /* update configuration */
+ update_vpn_dns_configuration (tm);
+ if ((0 == strlen (old)) && (0 != strlen (new_text)))
+ {
+ /* need another empty entry at the end for future expansion */
+ add_dns_entry_to_list_store (GTK_LIST_STORE (tm), NULL);
+ }
+ g_free (old);
+}
+
+
+/**
+ * Initialize the GtkListModel with the VPN's DNS service specification.
+ *
+ * @param cls NULL
+ * @param section section with the value (NULL)
+ * @param option option name (NULL)
+ * @param widget widget to initialize (the GtkTreeView)
+ * @param cfg configuration handle
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if there was a problem
+ */
+static int
+gns_name_install_edited_handler (const void *cls,
+ const char *section,
+ const char *option,
+ GObject * widget,
+ struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ static int once;
+ GtkCellRendererText *rt;
+
+ rt = GTK_CELL_RENDERER_TEXT (widget);
+ if (NULL == rt)
+ return GNUNET_SYSERR;
+ if (0 != once++)
+ return GNUNET_OK;
+ g_signal_connect (rt, "edited",
+ G_CALLBACK (&save_vpn_dns_service_dnsname),
+ NULL);
+ return GNUNET_OK;
+}
+
+
+/**
+ * The user has edited the DNS name of a service we're offering.
+ * Update the GtkTreeModel (at the given path) and update the
+ * respective service entry in the configuration file. Finally,
+ * if the edited path is for a "fresh" entry, create another empty
+ * one at the bottom. If the hostname was set to empty, remove
+ * the entire entry from the configuration and the model.
+ *
+ * @param renderer GtkCellRendererText that changed
+ * @param path GtkTreePath identifying where in the Model the change is
+ * @param new_text the new text that was stored in the line
+ * @param user_data NULL
+ */
+static void
+save_vpn_dns_service_tcpudp (GtkCellRendererText * renderer,
+ gchar * path,
+ gchar * new_text,
+ gpointer user_data)
+{
+ GtkTreeModel *tm;
+ GtkListStore *ls;
+ GtkTreeIter iter;
+
+ if ((0 != strcasecmp ("tcp", new_text)) &&
+ (0 != strcasecmp ("udp", new_text)))
+ {
+ /* FIXME: warn... */
+ return;
+ }
+ tm = GTK_TREE_MODEL (GNUNET_SETUP_get_object ("GNUNET_setup_gns_liststore"));
+ if (NULL == tm)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ ls = GTK_LIST_STORE (tm);
+ if (NULL == ls)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (TRUE != gtk_tree_model_get_iter_from_string (tm, &iter, path))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ /* update model */
+ gtk_list_store_set (ls, &iter, SERVICE_MC_ISUDP, new_text, -1);
+ /* update configuration */
+ update_vpn_dns_configuration (tm);
+}
+
+
+/**
+ * Initialize the GtkListModel with the VPN's DNS service specification.
+ *
+ * @param cls NULL
+ * @param section section with the value (NULL)
+ * @param option option name (NULL)
+ * @param widget widget to initialize (the GtkTreeView)
+ * @param cfg configuration handle
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if there was a problem
+ */
+static int
+gns_type_install_edited_handler (const void *cls,
+ const char *section,
+ const char *option,
+ GObject * widget,
+ struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ static int once;
+ GtkCellRendererText *rt;
+
+ rt = GTK_CELL_RENDERER_TEXT (widget);
+ if (NULL == rt)
+ return GNUNET_SYSERR;
+ if (0 != once++)
+ return GNUNET_OK;
+ g_signal_connect (rt, "edited", G_CALLBACK (&save_vpn_dns_service_tcpudp),
+ NULL);
+ return GNUNET_OK;
+}
+
+
+/**
+ * The user has edited the DNS name of a service we're offering.
+ * Update the GtkTreeModel (at the given path) and update the
+ * respective service entry in the configuration file. Finally,
+ * if the edited path is for a "fresh" entry, create another empty
+ * one at the bottom. If the hostname was set to empty, remove
+ * the entire entry from the configuration and the model.
+ *
+ * @param renderer GtkCellRendererText that changed
+ * @param path GtkTreePath identifying where in the Model the change is
+ * @param new_text the new text that was stored in the line
+ * @param user_data NULL
+ */
+static void
+save_vpn_dns_service_sourceport (GtkCellRendererText * renderer,
+ gchar * path,
+ gchar * new_text,
+ gpointer user_data)
+{
+ GtkTreeModel *tm;
+ GtkListStore *ls;
+ GtkTreeIter iter;
+ int port;
+
+ port = atoi (new_text);
+ if ((port < 1) || (port > UINT16_MAX))
+ {
+ /* invalid port, FIXME: warn */
+ return;
+ }
+ tm = GTK_TREE_MODEL (GNUNET_SETUP_get_object ("GNUNET_setup_gns_liststore"));
+ if (NULL == tm)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ ls = GTK_LIST_STORE (tm);
+ if (NULL == ls)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (TRUE != gtk_tree_model_get_iter_from_string (tm, &iter, path))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ /* update model */
+ gtk_list_store_set (ls, &iter,
+ SERVICE_MC_SOURCEPORT, (guint) port, -1);
+ /* update configuration */
+ update_vpn_dns_configuration (tm);
+}
+
+
+/**
+ * Initialize the GtkListModel with the VPN's DNS service specification.
+ *
+ * @param cls NULL
+ * @param section section with the value (NULL)
+ * @param option option name (NULL)
+ * @param widget widget to initialize (the GtkTreeView)
+ * @param cfg configuration handle
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if there was a problem
+ */
+static int
+gns_ttl_install_edited_handler (const void *cls,
+ const char *section,
+ const char *option,
+ GObject * widget,
+ struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ static int once;
+ GtkCellRendererText *rt;
+
+ rt = GTK_CELL_RENDERER_TEXT (widget);
+ if (NULL == rt)
+ return GNUNET_SYSERR;
+ if (0 != once++)
+ return GNUNET_OK;
+ g_signal_connect (rt, "edited", G_CALLBACK
(&save_vpn_dns_service_sourceport),
+ NULL);
+ return GNUNET_OK;
+}
+
+
+/**
+ * The user has edited the DNS name of a service we're offering.
+ * Update the GtkTreeModel (at the given path) and update the
+ * respective service entry in the configuration file. Finally,
+ * if the edited path is for a "fresh" entry, create another empty
+ * one at the bottom. If the hostname was set to empty, remove
+ * the entire entry from the configuration and the model.
+ *
+ * @param renderer GtkCellRendererText that changed
+ * @param path GtkTreePath identifying where in the Model the change is
+ * @param new_text the new text that was stored in the line
+ * @param user_data NULL
+ */
+static void
+save_vpn_dns_service_targethostname (GtkCellRendererText * renderer,
+ gchar * path, gchar * new_text,
+ gpointer user_data)
+{
+ GtkTreeModel *tm;
+ GtkListStore *ls;
+ GtkTreeIter iter;
+
+ tm = GTK_TREE_MODEL (GNUNET_SETUP_get_object ("GNUNET_setup_gns_liststore"));
+ if (NULL == tm)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ ls = GTK_LIST_STORE (tm);
+ if (NULL == ls)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ if (TRUE != gtk_tree_model_get_iter_from_string (tm, &iter, path))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ /* update model */
+ gtk_list_store_set (ls, &iter,
+ SERVICE_MC_TARGETHOSTNAME, new_text, -1);
+ /* update configuration */
+ update_vpn_dns_configuration (tm);
+}
+
+
+/**
+ * Initialize the GtkListModel with the VPN's DNS service specification.
+ *
+ * @param cls NULL
+ * @param section section with the value (NULL)
+ * @param option option name (NULL)
+ * @param widget widget to initialize (the GtkTreeView)
+ * @param cfg configuration handle
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if there was a problem
+ */
+static int
+gns_value_install_edited_handler (const void *cls,
+ const char *section,
+ const char *option,
+ GObject * widget,
+ struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ static int once;
+ GtkCellRendererText *rt;
+
+ rt = GTK_CELL_RENDERER_TEXT (widget);
+ if (NULL == rt)
+ return GNUNET_SYSERR;
+ if (0 != once++)
+ return GNUNET_OK;
+ g_signal_connect (rt, "edited",
+ G_CALLBACK (&save_vpn_dns_service_targethostname), NULL);
+ return GNUNET_OK;
+}
+
+
+#if 0
+ {
+ "GNUNET_setup_gns_treeview",
+ NULL,
+ NULL,
+ NULL,
+ gettext_noop
+ ("Specification of .gnunet TLD"),
+ "https://gnunet.org/configuration-dns",
+ &load_vpn_dns_configuration,
+ NULL, NULL,
+ NULL, NULL,
+ NULL},
+
+ {
+ "GNUNET_setup_gns_name_cellrenderertext",
+ "editing-started",
+ NULL,
+ NULL,
+ NULL,
+ "https://gnunet.org/configuration-dns",
+ NULL,
+ &gns_name_install_edited_handler,
+ NULL,
+ NULL,
+ NULL,
+ NULL},
+
+ {
+ "GNUNET_setup_gns_type_cellrenderertext",
+ "editing-started",
+ NULL,
+ NULL,
+ NULL,
+ "https://gnunet.org/configuration-dns",
+ NULL,
+ &gns_type_install_edited_handler,
+ NULL,
+ NULL,
+ NULL,
+ NULL},
+
+ {
+ "GNUNET_setup_gns_ttl_cellrenderertext",
+ "editing-started",
+ NULL,
+ NULL,
+ NULL,
+ "https://gnunet.org/configuration-dns",
+ NULL,
+ &gns_ttl_install_edited_handler,
+ NULL,
+ NULL,
+ NULL,
+ NULL},
+
+ {
+ "GNUNET_setup_gns_value_cellrenderertext",
+ "editing-started",
+ NULL,
+ NULL,
+ NULL,
+ "https://gnunet.org/configuration-dns",
+ NULL,
+ &gns_value_install_edited_handler,
+ NULL,
+ NULL,
+ NULL,
+ NULL},
+
+#endif
+
+/* end of gnunet-setup-dns-exit.c */
Modified: gnunet-gtk/src/setup/gnunet-setup.h
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup.h 2013-10-08 12:19:42 UTC (rev 29986)
+++ gnunet-gtk/src/setup/gnunet-setup.h 2013-10-08 12:48:06 UTC (rev 29987)
@@ -51,38 +51,6 @@
/**
- * Columns in the hostlist url setup model.
- */
-enum GNUNET_GTK_SETUP_GnsModelColumns
- {
- /**
- * A gchararray
- */
- GNUNET_GTK_SETUP_GNS_MC_HOSTNAME = 0,
-
- /**
- * A guint
- */
- GNUNET_GTK_SETUP_GNS_MC_SOURCEPORT = 1,
-
- /**
- * A guint
- */
- GNUNET_GTK_SETUP_GNS_MC_TARGETPORT = 2,
-
- /**
- * A gchararray
- */
- GNUNET_GTK_SETUP_GNS_MC_TARGETHOSTNAME = 3,
-
- /**
- * A gchararray
- */
- GNUNET_GTK_SETUP_GNS_MC_ISUDP = 4,
- };
-
-
-/**
* Get an object from the main window.
*
* @param name name of the object
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r29987 - gnunet-gtk/src/setup,
gnunet <=