gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis-gtk] branch master updated: work on pay dialog


From: gnunet
Subject: [taler-anastasis-gtk] branch master updated: work on pay dialog
Date: Thu, 11 Mar 2021 22:00:41 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository anastasis-gtk.

The following commit(s) were added to refs/heads/master by this push:
     new fb71e56  work on pay dialog
fb71e56 is described below

commit fb71e563ea1e4315ba3942579c0787bbb5cefad1
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Thu Mar 11 22:00:38 2021 +0100

    work on pay dialog
---
 contrib/anastasis_gtk_auth_add_email.glade         |   3 +-
 contrib/anastasis_gtk_auth_add_post.glade          |   2 +-
 contrib/anastasis_gtk_auth_add_sms.glade           |   3 +-
 contrib/anastasis_gtk_main_window.glade            | 238 ++++++++++++++++++++-
 src/anastasis/Makefile.am                          |   1 +
 ...stasis-gtk_handle-main-window-forward-clicked.c | 122 +++--------
 src/anastasis/anastasis-gtk_handle-method-email.c  | 152 ++++++++++++-
 src/anastasis/anastasis-gtk_handle-method-post.c   |  10 +-
 src/anastasis/anastasis-gtk_handle-method-sms.c    | 130 ++++++++++-
 9 files changed, 549 insertions(+), 112 deletions(-)

diff --git a/contrib/anastasis_gtk_auth_add_email.glade 
b/contrib/anastasis_gtk_auth_add_email.glade
index 1c83b6f..c78b154 100644
--- a/contrib/anastasis_gtk_auth_add_email.glade
+++ b/contrib/anastasis_gtk_auth_add_email.glade
@@ -5,6 +5,7 @@
   <object class="GtkDialog" id="anastasis_gtk_b_email_dialog">
     <property name="can-focus">False</property>
     <property name="type-hint">dialog</property>
+    <signal name="response" handler="anastasis_gtk_b_email_dialog_response_cb" 
swapped="no"/>
     <child internal-child="vbox">
       <object class="GtkBox">
         <property name="can-focus">False</property>
@@ -21,7 +22,6 @@
                 <property name="can-focus">True</property>
                 <property name="receives-default">True</property>
                 <property name="use-stock">True</property>
-                <signal name="clicked" 
handler="anastasis_gtk_b_email_dialog_btn_cancel_clicked_cb" swapped="no"/>
               </object>
               <packing>
                 <property name="expand">True</property>
@@ -79,6 +79,7 @@
                     <property name="visible">True</property>
                     <property name="can-focus">True</property>
                     <property name="hexpand">True</property>
+                    <property name="width-chars">36</property>
                     <property 
name="primary-icon-stock">gtk-dialog-authentication</property>
                     <property name="input-purpose">email</property>
                     <signal name="changed" 
handler="anastasis_gtk_b_email_dialog_mailaddress_entry_changed_cb" 
swapped="no"/>
diff --git a/contrib/anastasis_gtk_auth_add_post.glade 
b/contrib/anastasis_gtk_auth_add_post.glade
index 178c5aa..626071d 100644
--- a/contrib/anastasis_gtk_auth_add_post.glade
+++ b/contrib/anastasis_gtk_auth_add_post.glade
@@ -5,6 +5,7 @@
   <object class="GtkDialog" id="anastasis_gtk_b_post_dialog">
     <property name="can-focus">False</property>
     <property name="type-hint">dialog</property>
+    <signal name="response" handler="anastasis_gtk_b_post_dialog_response_cb" 
swapped="no"/>
     <child internal-child="vbox">
       <object class="GtkBox">
         <property name="can-focus">False</property>
@@ -21,7 +22,6 @@
                 <property name="can-focus">True</property>
                 <property name="receives-default">True</property>
                 <property name="use-stock">True</property>
-                <signal name="clicked" 
handler="anastasis_gtk_b_post_dialog_btn_cancel_clicked_cb" swapped="no"/>
               </object>
               <packing>
                 <property name="expand">True</property>
diff --git a/contrib/anastasis_gtk_auth_add_sms.glade 
b/contrib/anastasis_gtk_auth_add_sms.glade
index 6cfa94a..e170255 100644
--- a/contrib/anastasis_gtk_auth_add_sms.glade
+++ b/contrib/anastasis_gtk_auth_add_sms.glade
@@ -5,6 +5,7 @@
   <object class="GtkDialog" id="anastasis_gtk_b_sms_dialog">
     <property name="can-focus">False</property>
     <property name="type-hint">dialog</property>
+    <signal name="response" handler="anastasis_gtk_b_sms_dialog_response_cb" 
swapped="no"/>
     <child internal-child="vbox">
       <object class="GtkBox">
         <property name="can-focus">False</property>
@@ -22,7 +23,6 @@
                 <property name="has-focus">True</property>
                 <property name="receives-default">True</property>
                 <property name="use-stock">True</property>
-                <signal name="clicked" 
handler="anastasis_gtk_b_sms_dialog_btn_cancel_clicked_cb" swapped="no"/>
               </object>
               <packing>
                 <property name="expand">True</property>
@@ -79,6 +79,7 @@
                     <property name="visible">True</property>
                     <property name="can-focus">True</property>
                     <property name="hexpand">True</property>
+                    <property name="width-chars">24</property>
                     <property 
name="primary-icon-stock">gtk-dialog-authentication</property>
                     <property name="placeholder-text" 
translatable="yes">+41123456789</property>
                     <property name="input-purpose">phone</property>
diff --git a/contrib/anastasis_gtk_main_window.glade 
b/contrib/anastasis_gtk_main_window.glade
index 1c54373..ca4857c 100644
--- a/contrib/anastasis_gtk_main_window.glade
+++ b/contrib/anastasis_gtk_main_window.glade
@@ -75,6 +75,12 @@ Author: Christian Grothoff, Dennis Neufeld
     <property name="can-focus">False</property>
     <property name="stock">gtk-dialog-question</property>
   </object>
+  <object class="GtkListStore" id="paid_qrcodes_liststore">
+    <columns>
+      <!-- column-name qr -->
+      <column type="GdkPixbuf"/>
+    </columns>
+  </object>
   <object class="GtkTreeStore" id="policy_review_treestore">
     <columns>
       <!-- column-name policy_name -->
@@ -95,6 +101,12 @@ Author: Christian Grothoff, Dennis Neufeld
     <property name="stock">gtk-go-down</property>
     <property name="icon_size">6</property>
   </object>
+  <object class="GtkListStore" id="unpaid_qrcodes_liststore">
+    <columns>
+      <!-- column-name qr -->
+      <column type="GdkPixbuf"/>
+    </columns>
+  </object>
   <object class="GtkWindow" id="anastasis_gtk_main_window">
     <property name="can-focus">False</property>
     <property name="events">GDK_BUTTON_PRESS_MASK | 
GDK_STRUCTURE_MASK</property>
@@ -1083,12 +1095,27 @@ Author: Christian Grothoff, Dennis Neufeld
                                             <property 
name="visible">True</property>
                                             <property 
name="can-focus">False</property>
                                             <child>
-                                              <placeholder/>
+                                              <object class="GtkBox" 
id="anastasis_gtk_challenge_list_box">
+                                                <property 
name="visible">True</property>
+                                                <property 
name="can-focus">False</property>
+                                                <property 
name="margin-top">5</property>
+                                                <property 
name="margin-bottom">5</property>
+                                                <child>
+                                                  <placeholder/>
+                                                </child>
+                                              </object>
+                                              <packing>
+                                                <property 
name="expand">True</property>
+                                                <property 
name="fill">True</property>
+                                                <property 
name="padding">5</property>
+                                                <property 
name="position">0</property>
+                                              </packing>
                                             </child>
                                           </object>
                                           <packing>
-                                            <property 
name="expand">False</property>
+                                            <property 
name="expand">True</property>
                                             <property 
name="fill">True</property>
+                                            <property 
name="padding">5</property>
                                             <property 
name="position">0</property>
                                           </packing>
                                         </child>
@@ -1164,6 +1191,7 @@ Author: Christian Grothoff, Dennis Neufeld
                                                 <property 
name="can-focus">True</property>
                                                 <property 
name="primary-icon-stock">gtk-dialog-authentication</property>
                                                 <property 
name="input-purpose">password</property>
+                                                <signal name="changed" 
handler="anastasis_gtk_enter_secret_entry_changed_cb" swapped="no"/>
                                               </object>
                                               <packing>
                                                 <property 
name="expand">True</property>
@@ -1251,7 +1279,211 @@ Author: Christian Grothoff, Dennis Neufeld
                                     <property name="can-focus">False</property>
                                     <property name="left-padding">12</property>
                                     <child>
-                                      <placeholder/>
+                                      <object class="GtkBox">
+                                        <property 
name="visible">True</property>
+                                        <property 
name="can-focus">False</property>
+                                        <child>
+                                          <object class="GtkBox">
+                                            <property 
name="visible">True</property>
+                                            <property 
name="can-focus">False</property>
+                                            <property 
name="orientation">vertical</property>
+                                            <child>
+                                              <object class="GtkLabel">
+                                                <property 
name="visible">True</property>
+                                                <property 
name="can-focus">False</property>
+                                                <property name="label" 
translatable="yes">Unpaid:</property>
+                                              </object>
+                                              <packing>
+                                                <property 
name="expand">False</property>
+                                                <property 
name="fill">False</property>
+                                                <property 
name="padding">5</property>
+                                                <property 
name="position">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <object 
class="GtkScrolledWindow">
+                                                <property 
name="visible">True</property>
+                                                <property 
name="can-focus">True</property>
+                                                <property 
name="vscrollbar-policy">never</property>
+                                                <property 
name="shadow-type">in</property>
+                                                <child>
+                                                  <object class="GtkViewport">
+                                                    <property 
name="visible">True</property>
+                                                    <property 
name="can-focus">False</property>
+                                                    <child>
+                                                      <object 
class="GtkTreeView" id="unpaid_qr_treeview">
+                                                        <property 
name="visible">True</property>
+                                                        <property 
name="can-focus">True</property>
+                                                        <property 
name="model">unpaid_qrcodes_liststore</property>
+                                                        <property 
name="headers-visible">False</property>
+                                                        <property 
name="enable-search">False</property>
+                                                        <child 
internal-child="selection">
+                                                          <object 
class="GtkTreeSelection" id="unpaid_qr_treeselection">
+                                                            <signal 
name="changed" handler="unpaid_qr_treeselection_changed_cb" swapped="no"/>
+                                                          </object>
+                                                        </child>
+                                                        <child>
+                                                          <object 
class="GtkTreeViewColumn">
+                                                            <property 
name="sizing">autosize</property>
+                                                            <property 
name="title" translatable="yes">Unpaid</property>
+                                                            <child>
+                                                            <object 
class="GtkCellRendererPixbuf" id="unpaid_pixbuf"/>
+                                                            <attributes>
+                                                            <attribute 
name="pixbuf">0</attribute>
+                                                            </attributes>
+                                                            </child>
+                                                          </object>
+                                                        </child>
+                                                      </object>
+                                                    </child>
+                                                  </object>
+                                                </child>
+                                              </object>
+                                              <packing>
+                                                <property 
name="expand">False</property>
+                                                <property 
name="fill">True</property>
+                                                <property 
name="position">1</property>
+                                              </packing>
+                                            </child>
+                                          </object>
+                                          <packing>
+                                            <property 
name="expand">False</property>
+                                            <property 
name="fill">True</property>
+                                            <property 
name="position">0</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkBox">
+                                            <property 
name="visible">True</property>
+                                            <property 
name="can-focus">False</property>
+                                            <property 
name="orientation">vertical</property>
+                                            <child>
+                                              <object class="GtkLabel">
+                                                <property 
name="visible">True</property>
+                                                <property 
name="can-focus">False</property>
+                                                <property name="label" 
translatable="yes">Please pay with GNU Taler:</property>
+                                              </object>
+                                              <packing>
+                                                <property 
name="expand">True</property>
+                                                <property 
name="fill">True</property>
+                                                <property 
name="padding">5</property>
+                                                <property 
name="position">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <object class="GtkLabel" 
id="anastasis_gtk_pay_payto_label">
+                                                <property 
name="visible">True</property>
+                                                <property 
name="can-focus">False</property>
+                                                <property name="label" 
translatable="yes">payto://FIXME</property>
+                                                <property 
name="selectable">True</property>
+                                                <property 
name="ellipsize">end</property>
+                                                <attributes>
+                                                  <attribute name="underline" 
value="True"/>
+                                                  <attribute name="foreground" 
value="#1c1c7171d8d8"/>
+                                                </attributes>
+                                              </object>
+                                              <packing>
+                                                <property 
name="expand">True</property>
+                                                <property 
name="fill">True</property>
+                                                <property 
name="padding">5</property>
+                                                <property 
name="position">1</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <object class="GtkImage" 
id="anastasis_gtk_pay_qrcode_image">
+                                                <property 
name="width-request">400</property>
+                                                <property 
name="height-request">400</property>
+                                                <property 
name="visible">True</property>
+                                                <property 
name="sensitive">False</property>
+                                                <property 
name="can-focus">False</property>
+                                                <property 
name="stock">gtk-missing-image</property>
+                                              </object>
+                                              <packing>
+                                                <property 
name="expand">True</property>
+                                                <property 
name="fill">True</property>
+                                                <property 
name="padding">5</property>
+                                                <property 
name="position">2</property>
+                                              </packing>
+                                            </child>
+                                          </object>
+                                          <packing>
+                                            <property 
name="expand">True</property>
+                                            <property 
name="fill">True</property>
+                                            <property 
name="position">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkBox">
+                                            <property 
name="visible">True</property>
+                                            <property 
name="can-focus">False</property>
+                                            <property 
name="orientation">vertical</property>
+                                            <child>
+                                              <object class="GtkLabel">
+                                                <property 
name="visible">True</property>
+                                                <property 
name="can-focus">False</property>
+                                                <property name="label" 
translatable="yes">Paid:</property>
+                                              </object>
+                                              <packing>
+                                                <property 
name="expand">False</property>
+                                                <property 
name="fill">False</property>
+                                                <property 
name="padding">5</property>
+                                                <property 
name="position">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <object 
class="GtkScrolledWindow">
+                                                <property 
name="visible">True</property>
+                                                <property 
name="can-focus">True</property>
+                                                <property 
name="vscrollbar-policy">never</property>
+                                                <property 
name="shadow-type">in</property>
+                                                <child>
+                                                  <object class="GtkViewport">
+                                                    <property 
name="visible">True</property>
+                                                    <property 
name="can-focus">False</property>
+                                                    <child>
+                                                      <object 
class="GtkTreeView" id="paid_qr_treeview">
+                                                        <property 
name="visible">True</property>
+                                                        <property 
name="sensitive">False</property>
+                                                        <property 
name="can-focus">True</property>
+                                                        <property 
name="model">paid_qrcodes_liststore</property>
+                                                        <property 
name="headers-visible">False</property>
+                                                        <property 
name="enable-search">False</property>
+                                                        <child 
internal-child="selection">
+                                                          <object 
class="GtkTreeSelection">
+                                                            <property 
name="mode">none</property>
+                                                          </object>
+                                                        </child>
+                                                        <child>
+                                                          <object 
class="GtkTreeViewColumn" id="paid_qr_column">
+                                                            <property 
name="title" translatable="yes">Paid</property>
+                                                            <child>
+                                                            <object 
class="GtkCellRendererPixbuf" id="paid_pixbuf"/>
+                                                            <attributes>
+                                                            <attribute 
name="pixbuf">0</attribute>
+                                                            </attributes>
+                                                            </child>
+                                                          </object>
+                                                        </child>
+                                                      </object>
+                                                    </child>
+                                                  </object>
+                                                </child>
+                                              </object>
+                                              <packing>
+                                                <property 
name="expand">False</property>
+                                                <property 
name="fill">True</property>
+                                                <property 
name="padding">5</property>
+                                                <property 
name="position">1</property>
+                                              </packing>
+                                            </child>
+                                          </object>
+                                          <packing>
+                                            <property 
name="expand">False</property>
+                                            <property 
name="fill">True</property>
+                                            <property 
name="position">2</property>
+                                          </packing>
+                                        </child>
+                                      </object>
                                     </child>
                                   </object>
                                 </child>
diff --git a/src/anastasis/Makefile.am b/src/anastasis/Makefile.am
index e87bf1e..7f54aa0 100644
--- a/src/anastasis/Makefile.am
+++ b/src/anastasis/Makefile.am
@@ -24,6 +24,7 @@ anastasis_gtk_SOURCES = \
   anastasis-gtk_handle-continent-unselected.c \
   anastasis-gtk_handle-country-activated.c \
   anastasis-gtk_handle-country-unselected.c \
+  anastasis-gtk_handle-core-secret-changed.c \
   anastasis-gtk_handle-identity-changed.c \
   anastasis-gtk_handle-identity-changed.h \
   anastasis-gtk_handle-secret-buttons.c \
diff --git a/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c 
b/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c
index eff0590..7da3f40 100644
--- a/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c
+++ b/src/anastasis/anastasis-gtk_handle-main-window-forward-clicked.c
@@ -98,110 +98,48 @@ AG_forward_user_attributes_collecting (void)
 static void
 forward_authentications_editing (void)
 {
-  GList *children;
-  GList *iter;
-  json_t *arguments = json_object ();
-  json_t *id_attr = json_object ();
-
-  children = gtk_container_get_children (GTK_CONTAINER (
-                                           GCG_get_main_window_object (
-                                             "anastasis_gtk_identity_vbox")));
-  for (iter = children; iter != NULL; iter = g_list_next (iter))
-  {
-    char *entry_widget;
-    char *cal_widget;
-    const char *widget = gtk_buildable_get_name (iter->data);
-
-    GNUNET_asprintf (&entry_widget,
-                     "%s_entry",
-                     widget);
-    GNUNET_asprintf (&cal_widget,
-                     "%s_cal",
-                     widget);
-
-    if (GCG_get_main_window_object (entry_widget))
-    {
-      const char *value = gtk_entry_get_text (GTK_ENTRY (
-                                                GCG_get_main_window_object (
-                                                  entry_widget)));
-      if (0 == strlen (value))
-        break;
-      if (strstr (widget, "ia_ahv"))
-        json_object_set_new (id_attr, "ahv_number", json_string (value));
-      if (strstr (widget, "ia_ssn"))
-        json_object_set_new (id_attr, "social_security_number", json_string (
-                               value));
-      if (strstr (widget, "ia_full_name"))
-        json_object_set_new (id_attr, "full_name", json_string (value));
-    }
-    if (GCG_get_main_window_object (cal_widget))
-    {
-      guint day;
-      guint month;
-      guint year;
-
-      gtk_calendar_get_date (GTK_CALENDAR (GCG_get_main_window_object (
-                                             cal_widget)),
-                             &year,
-                             &month,
-                             &day);
-      json_object_set_new (id_attr, "birth_year", json_integer (year));
-      json_object_set_new (id_attr, "birth_month", json_integer (month));
-      json_object_set_new (id_attr, "birth_day", json_integer (day));
-    }
-    GNUNET_free (entry_widget);
-    GNUNET_free (cal_widget);
-  }
-  json_object_set_new (arguments, "identity_attributes", id_attr);
-
-  if (AG_check_state (redux_state,
-                      "USER_ATTRIBUTES_COLLECTION"))
-  {
-#if FIXME
-    json_t *auth_providers = get_authentication_providers ();
-    if (NULL != auth_providers)
-      json_object_set_new (arguments,
-                           "authentication_providers",
-                           auth_providers);
-    ra = ANASTASIS_redux_action (redux_state,
-                                 "enter_user_attributes",
-                                 arguments,
-                                 &AG_action_cb,
-                                 NULL);
-#endif
-  }
-  g_list_free (children);
-
-  AG_insensitive ("anastasis_gtk_main_window_forward_button");
-
-  {
-    json_t *auth_methods = json_object_get (redux_state,
-                                            "authentication_methods");
-
-    if (json_array_size (auth_methods) > 0)
-    {
-      AG_freeze ();
-      ra = ANASTASIS_redux_action (redux_state,
-                                   "next",
-                                   NULL,
-                                   &AG_action_cb,
-                                   NULL);
-    }
-  }
+  AG_freeze ();
+  ra = ANASTASIS_redux_action (redux_state,
+                               "next",
+                               NULL,
+                               &AG_action_cb,
+                               NULL);
 }
 
 
 static void
 forward_policies_reviewing (void)
 {
-  GNUNET_break (0);
+  AG_freeze ();
+  ra = ANASTASIS_redux_action (redux_state,
+                               "next",
+                               NULL,
+                               &AG_action_cb,
+                               NULL);
 }
 
 
 static void
 forward_secret_editing (void)
 {
-  GNUNET_break (0);
+  json_t *arguments;
+  GtkEntry *entry;
+  const char *str;
+
+  entry = GTK_ENTRY (GCG_get_main_window_object (
+                       "anastasis_gtk_enter_secret_entry"));
+  str = gtk_entry_get_text (entry);
+  arguments = json_pack ("{s:o}",
+                         "secret",
+                         GNUNET_JSON_from_data (str,
+                                                strlen (str)));
+  AG_freeze ();
+  ra = ANASTASIS_redux_action (redux_state,
+                               "enter_secret",
+                               arguments,
+                               &AG_action_cb,
+                               NULL);
+  json_decref (arguments);
 }
 
 
diff --git a/src/anastasis/anastasis-gtk_handle-method-email.c 
b/src/anastasis/anastasis-gtk_handle-method-email.c
index 423af4a..693b824 100644
--- a/src/anastasis/anastasis-gtk_handle-method-email.c
+++ b/src/anastasis/anastasis-gtk_handle-method-email.c
@@ -31,6 +31,124 @@
 #include <jansson.h>
 
 
+/**
+ * Return obfuscated variant of an e-mail address.
+ *
+ * @param email input address
+ * @return obfuscated version, NULL on errors
+ */
+static char *
+mask_email (const char *email)
+{
+  char *at;
+  char *tld;
+  size_t nlen;
+  char *result;
+
+  result = GNUNET_strdup (email);
+  at = strchr (result, '@');
+  if (NULL == at)
+  {
+    GNUNET_break (0);
+    GNUNET_free (result);
+    return NULL;
+  }
+  tld = strrchr (result, '.');
+  if (NULL == tld)
+  {
+    GNUNET_break (0);
+    GNUNET_free (result);
+    return NULL;
+  }
+  if ( (ssize_t) (at - tld) > 0)
+  {
+    GNUNET_break (0);
+    GNUNET_free (result);
+    return NULL;
+  }
+  nlen = at - result;
+  switch (nlen)
+  {
+  case 0:
+    GNUNET_break (0);
+    GNUNET_free (result);
+    return NULL;
+  case 1:
+    result[0] = '?';
+    break;
+  case 2:
+  case 3:
+    result[0] = '?';
+    result[1] = '?';
+    break;
+  default:
+    for (unsigned int i = 1; i<nlen - 2; i++)
+      result[i] = '?';
+    break;
+  }
+  nlen = tld - at;
+  switch (nlen)
+  {
+  case 1:
+    GNUNET_break (0);
+    GNUNET_free (result);
+    return NULL;
+  case 2:
+    at[1] = '?';
+    break;
+  case 3:
+    at[1] = '?';
+    at[2] = '?';
+    break;
+  case 4:
+    at[2] = '?';
+    at[3] = '?';
+    break;
+  default:
+    for (unsigned int i = 2; i<nlen - 2; i++)
+      at[i] = '?';
+    break;
+  }
+
+  /* shorten multiple consecutive "?" to "*" */
+  {
+    bool star = false;
+    bool qmark = false;
+    size_t woff = 0;
+
+    for (unsigned int i = 0; i<strlen (result); i++)
+    {
+      result[woff++] = result[i];
+      if ('?' == result[i])
+      {
+        if (star)
+        {
+          /* more than two "??" in a row */
+          woff--;
+          continue;
+        }
+        if (qmark)
+        {
+          /* two "??", combine to "*" */
+          result[--woff - 1] = '*';
+          star = true;
+          continue;
+        }
+        /* first qmark */
+        qmark = true;
+      }
+      else
+      {
+        star = false;
+        qmark = false;
+      }
+    }
+    result[woff] = '\0';
+  }
+  return result;
+}
+
+
 /**
  * Function called from the security-email dialog upon completion.
  *
@@ -47,6 +165,8 @@ anastasis_gtk_b_email_dialog_response_cb (GtkDialog *dialog,
   GtkEntry *q;
   const char *qs;
   json_t *args;
+  char *ins;
+  char *pe;
 
   if (GTK_RESPONSE_OK != response_id)
   {
@@ -57,7 +177,11 @@ anastasis_gtk_b_email_dialog_response_cb (GtkDialog *dialog,
   q = GTK_ENTRY (gtk_builder_get_object (builder,
                                          
"anastasis_gtk_b_email_dialog_mailaddress_entry"));
   qs = gtk_entry_get_text (q);
-  // FIXME: produce mangled email address for instructions!
+  pe = mask_email (qs);
+  GNUNET_asprintf (&ins,
+                   "PIN sent to e-mail at %s",
+                   pe);
+  GNUNET_free (pe);
   args = json_pack ("{ s:{s:s, s:o, s:s}}",
                     "authentication_method",
                     "type",
@@ -66,7 +190,8 @@ anastasis_gtk_b_email_dialog_response_cb (GtkDialog *dialog,
                     GNUNET_JSON_from_data (qs,
                                            strlen (qs)),
                     "instructions",
-                    qs);
+                    ins);
+  GNUNET_free (ins);
   gtk_widget_destroy (GTK_WIDGET (dialog));
   g_object_unref (G_OBJECT (builder));
   AG_freeze ();
@@ -85,19 +210,32 @@ anastasis_gtk_b_email_dialog_mailaddress_entry_changed_cb 
(GtkEntry *entry,
 {
   GtkBuilder *builder = GTK_BUILDER (user_data);
   GtkEntry *q;
-  GtkEntry *a;
   const char *qs;
-  const char *as;
+  regex_t regex;
+  int regex_result;
+  const char *regexp = "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}";
 
+  regex_result = regcomp (&regex,
+                          regexp,
+                          REG_EXTENDED);
+  if (0 < regex_result)
+  {
+    GNUNET_break (0);
+    return;
+  }
   q = GTK_ENTRY (gtk_builder_get_object (builder,
                                          
"anastasis_gtk_b_email_dialog_mailaddress_entry"));
   qs = gtk_entry_get_text (q);
-  // FIXME: validate e-mail address more here!
+  regex_result = regexec (&regex,
+                          qs,
+                          0,
+                          NULL,
+                          0);
+  regfree (&regex);
   gtk_widget_set_sensitive (
     GTK_WIDGET (gtk_builder_get_object (builder,
                                         
"anastasis_gtk_b_email_dialog_btn_ok")),
-    ( (NULL != qs) &&
-      (0 < strlen (qs)) ));
+    0 == regex_result);
 }
 
 
diff --git a/src/anastasis/anastasis-gtk_handle-method-post.c 
b/src/anastasis/anastasis-gtk_handle-method-post.c
index 4469eae..50b0996 100644
--- a/src/anastasis/anastasis-gtk_handle-method-post.c
+++ b/src/anastasis/anastasis-gtk_handle-method-post.c
@@ -45,7 +45,13 @@ gt (GtkBuilder *b,
   GtkEntry *q;
 
   q = GTK_ENTRY (gtk_builder_get_object (b,
-                                         
"anastasis_gtk_b_post_dialog_post_entry"));
+                                         widget_name));
+  if (NULL == q)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Could not find GtkEntry widget `%s'\n",
+                widget_name);
+  }
   return gtk_entry_get_text (q);
 }
 
@@ -73,7 +79,7 @@ anastasis_gtk_b_post_dialog_response_cb (GtkDialog *dialog,
     return;
   }
   GNUNET_asprintf (&ins,
-                   "PIN sent to address in %s\n",
+                   "PIN sent to address in %s",
                    gt (builder,
                        "anastasis_gtk_b_post_dialog_postcode_entry"));
   args = json_pack ("{ s:{s:s, s:{s:s,s:s,s:s,s:s,s:s}, s:s}}",
diff --git a/src/anastasis/anastasis-gtk_handle-method-sms.c 
b/src/anastasis/anastasis-gtk_handle-method-sms.c
index 310e89f..3c203a5 100644
--- a/src/anastasis/anastasis-gtk_handle-method-sms.c
+++ b/src/anastasis/anastasis-gtk_handle-method-sms.c
@@ -31,6 +31,104 @@
 #include <jansson.h>
 
 
+/**
+ * Return obfuscated variant of a phone number.
+ *
+ * @param number input address
+ * @return obfuscated version, NULL on errors
+ */
+static char *
+mask_number (const char *number)
+{
+  char *at;
+  size_t nlen;
+  char *result;
+
+  result = GNUNET_strdup (number);
+  at = strchr (result, '+');
+  if ( (NULL != at) &&
+       (result != at) )
+  {
+    GNUNET_break (0);
+    GNUNET_free (result);
+    return NULL;
+  }
+  nlen = strlen (number);
+  if (NULL != at)
+  {
+    if (strlen (at) < 3)
+    {
+      GNUNET_break (0);
+      GNUNET_free (result);
+      return NULL;
+    }
+    at += 3;
+    nlen -= 3;
+  }
+  else
+  {
+    at = result;
+  }
+  switch (nlen)
+  {
+  case 0:
+    GNUNET_break (0);
+    GNUNET_free (result);
+    return NULL;
+  case 1:
+    at[0] = '?';
+    break;
+  case 2:
+  case 3:
+  case 4:
+    at[0] = '?';
+    at[1] = '?';
+    break;
+  default:
+    for (unsigned int i = 1; i<nlen - 3; i++)
+      at[i] = '?';
+    break;
+  }
+
+  /* shorten multiple consecutive "?" to "*" */
+  {
+    bool star = false;
+    bool qmark = false;
+    size_t woff = 0;
+
+    for (unsigned int i = 0; i<strlen (result); i++)
+    {
+      result[woff++] = result[i];
+      if ('?' == result[i])
+      {
+        if (star)
+        {
+          /* more than two "??" in a row */
+          woff--;
+          continue;
+        }
+        if (qmark)
+        {
+          /* two "??", combine to "*" */
+          result[--woff - 1] = '*';
+          star = true;
+          continue;
+        }
+        /* first qmark */
+        qmark = true;
+      }
+      else
+      {
+        star = false;
+        qmark = false;
+      }
+    }
+    result[woff] = '\0';
+  }
+  return result;
+}
+
+
 /**
  * Function called from the security-sms dialog upon completion.
  *
@@ -47,6 +145,8 @@ anastasis_gtk_b_sms_dialog_response_cb (GtkDialog *dialog,
   GtkEntry *q;
   const char *qs;
   json_t *args;
+  char *mn;
+  char *ins;
 
   if (GTK_RESPONSE_OK != response_id)
   {
@@ -57,7 +157,11 @@ anastasis_gtk_b_sms_dialog_response_cb (GtkDialog *dialog,
   q = GTK_ENTRY (gtk_builder_get_object (builder,
                                          
"anastasis_gtk_b_sms_dialog_phonenumber_entry"));
   qs = gtk_entry_get_text (q);
-  // FIXME: produce mangled phone number for instructions!
+  mn = mask_number (qs);
+  GNUNET_asprintf (&ins,
+                   "SMS-TAN sent to phone at %s",
+                   mn);
+  GNUNET_free (mn);
   args = json_pack ("{ s:{s:s, s:o, s:s}}",
                     "authentication_method",
                     "type",
@@ -66,7 +170,8 @@ anastasis_gtk_b_sms_dialog_response_cb (GtkDialog *dialog,
                     GNUNET_JSON_from_data (qs,
                                            strlen (qs)),
                     "instructions",
-                    qs);
+                    ins);
+  GNUNET_free (ins);
   gtk_widget_destroy (GTK_WIDGET (dialog));
   g_object_unref (G_OBJECT (builder));
   AG_freeze ();
@@ -86,16 +191,31 @@ anastasis_gtk_b_sms_dialog_phonenumber_entry_changed_cb 
(GtkEntry *entry,
   GtkBuilder *builder = GTK_BUILDER (user_data);
   GtkEntry *q;
   const char *qs;
+  regex_t regex;
+  int regex_result;
+  const char *regexp = "^\\+?[0-9]+$";
 
+  regex_result = regcomp (&regex,
+                          regexp,
+                          REG_EXTENDED);
+  if (0 < regex_result)
+  {
+    GNUNET_break (0);
+    return;
+  }
   q = GTK_ENTRY (gtk_builder_get_object (builder,
                                          
"anastasis_gtk_b_sms_dialog_phonenumber_entry"));
   qs = gtk_entry_get_text (q);
-  // FIXME: validate phone number more here!
+  regex_result = regexec (&regex,
+                          qs,
+                          0,
+                          NULL,
+                          0);
+  regfree (&regex);
   gtk_widget_set_sensitive (
     GTK_WIDGET (gtk_builder_get_object (builder,
                                         "anastasis_gtk_b_sms_dialog_btn_ok")),
-    ( (NULL != qs) &&
-      (0 < strlen (qs)) ));
+    0 == regex_result);
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]