gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis-gtk] 01/04: implement challenge dialog handlers (WiP)


From: gnunet
Subject: [taler-anastasis-gtk] 01/04: implement challenge dialog handlers (WiP)
Date: Sat, 13 Mar 2021 19:23:30 +0100

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

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

commit 75741b4b5433993ad483f43b989588439b73f47e
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat Mar 13 16:25:04 2021 +0100

    implement challenge dialog handlers (WiP)
---
 contrib/anastasis_gtk_challenge_code.glade         |  80 +++---
 contrib/anastasis_gtk_challenge_question.glade     |  70 ++---
 m4/libtool.m4                                      |   4 +-
 po/POTFILES.in                                     |   2 +
 src/anastasis/Makefile.am                          |   2 +
 src/anastasis/anastasis-gtk_action.c               | 316 +++++++++++++++++++++
 .../anastasis-gtk_handle-challenge-code.c          |  91 ++++++
 .../anastasis-gtk_handle-challenge-question.c      |  91 ++++++
 8 files changed, 579 insertions(+), 77 deletions(-)

diff --git a/contrib/anastasis_gtk_challenge_code.glade 
b/contrib/anastasis_gtk_challenge_code.glade
index 7dff0a9..6c4981c 100644
--- a/contrib/anastasis_gtk_challenge_code.glade
+++ b/contrib/anastasis_gtk_challenge_code.glade
@@ -1,26 +1,37 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.38.2 -->
+<!-- Generated with glade 3.22.2 -->
 <interface>
   <requires lib="gtk+" version="3.0"/>
-  <object class="GtkDialog" id="anastasis_gtk_b_pin_dialog">
-    <property name="can-focus">False</property>
-    <property name="type-hint">dialog</property>
-    <signal name="response" 
handler="anastasis_gtk_b_question_dialog_response_cb" swapped="no"/>
+  <object class="GtkDialog" id="anastasis_gtk_c_code_dialog">
+    <property name="can_focus">False</property>
+    <property name="type_hint">dialog</property>
+    <signal name="response" handler="anastasis_gtk_c_code_dialog_response_cb" 
swapped="no"/>
+    <child type="titlebar">
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">Security token 
challenge</property>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget 
response="-6">anastasis_gtk_c_code_dialog_btn_cancel</action-widget>
+      <action-widget 
response="-5">anastasis_gtk_c_code_dialog_btn_ok</action-widget>
+    </action-widgets>
     <child internal-child="vbox">
       <object class="GtkBox">
-        <property name="can-focus">False</property>
+        <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <property name="spacing">2</property>
         <child internal-child="action_area">
           <object class="GtkButtonBox">
-            <property name="can-focus">False</property>
-            <property name="layout-style">end</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
             <child>
-              <object class="GtkButton" 
id="anastasis_gtk_b_question_dialog_btn_cancel">
+              <object class="GtkButton" 
id="anastasis_gtk_c_code_dialog_btn_cancel">
                 <property name="label" translatable="yes">Cancel</property>
                 <property name="visible">True</property>
-                <property name="can-focus">True</property>
-                <property name="receives-default">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
                 <signal name="clicked" 
handler="anastasis_gtk_b_question_dialog_btn_cancel_clicked_cb" swapped="no"/>
               </object>
               <packing>
@@ -30,12 +41,12 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" 
id="anastasis_gtk_b_question_dialog_btn_ok">
+              <object class="GtkButton" 
id="anastasis_gtk_c_code_dialog_btn_ok">
                 <property name="label" translatable="yes">OK</property>
                 <property name="visible">True</property>
                 <property name="sensitive">False</property>
-                <property name="can-focus">False</property>
-                <property name="receives-default">True</property>
+                <property name="can_focus">False</property>
+                <property name="receives_default">True</property>
               </object>
               <packing>
                 <property name="expand">True</property>
@@ -53,12 +64,12 @@
         <child>
           <object class="GtkBox">
             <property name="visible">True</property>
-            <property name="can-focus">False</property>
+            <property name="can_focus">False</property>
             <property name="orientation">vertical</property>
             <child>
               <object class="GtkSeparator">
                 <property name="visible">True</property>
-                <property name="can-focus">False</property>
+                <property name="can_focus">False</property>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -69,11 +80,11 @@
             <child>
               <object class="GtkBox">
                 <property name="visible">True</property>
-                <property name="can-focus">False</property>
+                <property name="can_focus">False</property>
                 <child>
                   <object class="GtkLabel">
                     <property name="visible">True</property>
-                    <property name="can-focus">False</property>
+                    <property name="can_focus">False</property>
                     <property name="label" translatable="yes">A challenge code 
has been send to:</property>
                   </object>
                   <packing>
@@ -86,7 +97,7 @@
                 <child>
                   <object class="GtkLabel" id="challenge_instructions_label">
                     <property name="visible">True</property>
-                    <property name="can-focus">False</property>
+                    <property name="can_focus">False</property>
                     <property name="label" translatable="yes">SET DYNAMICALLY 
BY PROGRAM</property>
                   </object>
                   <packing>
@@ -106,7 +117,7 @@
             <child>
               <object class="GtkSeparator">
                 <property name="visible">True</property>
-                <property name="can-focus">False</property>
+                <property name="can_focus">False</property>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -124,11 +135,11 @@
         <child>
           <object class="GtkBox">
             <property name="visible">True</property>
-            <property name="can-focus">False</property>
+            <property name="can_focus">False</property>
             <child>
               <object class="GtkLabel">
                 <property name="visible">True</property>
-                <property name="can-focus">False</property>
+                <property name="can_focus">False</property>
                 <property name="label" translatable="yes">Enter 
code:</property>
               </object>
               <packing>
@@ -139,13 +150,13 @@
               </packing>
             </child>
             <child>
-              <object class="GtkEntry" id="anastasis_gtk_c_pin_entry">
+              <object class="GtkEntry" id="anastasis_gtk_c_code_entry">
                 <property name="visible">True</property>
-                <property name="can-focus">True</property>
+                <property name="can_focus">True</property>
                 <property name="hexpand">True</property>
-                <property name="width-chars">60</property>
-                <property 
name="primary-icon-stock">gtk-dialog-authentication</property>
-                <signal name="changed" 
handler="anastasis_gtk_b_question_dialog_answer_entry_changed_cb" swapped="no"/>
+                <property name="width_chars">60</property>
+                <property 
name="primary_icon_stock">gtk-dialog-authentication</property>
+                <signal name="changed" 
handler="anastasis_gtk_c_code_dialog_answer_entry_changed_cb" swapped="no"/>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -165,19 +176,8 @@
       </object>
     </child>
     <action-widgets>
-      <action-widget 
response="-6">anastasis_gtk_b_question_dialog_btn_cancel</action-widget>
-      <action-widget 
response="-5">anastasis_gtk_b_question_dialog_btn_ok</action-widget>
-    </action-widgets>
-    <child type="titlebar">
-      <object class="GtkLabel">
-        <property name="visible">True</property>
-        <property name="can-focus">False</property>
-        <property name="label" translatable="yes">Security token 
challenge</property>
-      </object>
-    </child>
-    <action-widgets>
-      <action-widget 
response="-6">anastasis_gtk_b_question_dialog_btn_cancel</action-widget>
-      <action-widget 
response="-5">anastasis_gtk_b_question_dialog_btn_ok</action-widget>
+      <action-widget 
response="-6">anastasis_gtk_c_code_dialog_btn_cancel</action-widget>
+      <action-widget 
response="-5">anastasis_gtk_c_code_dialog_btn_ok</action-widget>
     </action-widgets>
   </object>
 </interface>
diff --git a/contrib/anastasis_gtk_challenge_question.glade 
b/contrib/anastasis_gtk_challenge_question.glade
index 11c0356..d36e862 100644
--- a/contrib/anastasis_gtk_challenge_question.glade
+++ b/contrib/anastasis_gtk_challenge_question.glade
@@ -1,26 +1,37 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.38.2 -->
+<!-- Generated with glade 3.22.2 -->
 <interface>
   <requires lib="gtk+" version="3.0"/>
   <object class="GtkDialog" id="anastasis_gtk_c_question_dialog">
-    <property name="can-focus">False</property>
-    <property name="type-hint">dialog</property>
-    <signal name="response" 
handler="anastasis_gtk_b_question_dialog_response_cb" swapped="no"/>
+    <property name="can_focus">False</property>
+    <property name="type_hint">dialog</property>
+    <signal name="response" 
handler="anastasis_gtk_c_question_dialog_response_cb" swapped="no"/>
+    <child type="titlebar">
+      <object class="GtkLabel">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes">Solve secuity question 
challenge</property>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget 
response="-6">anastasis_gtk_b_question_dialog_btn_cancel</action-widget>
+      <action-widget 
response="-5">anastasis_gtk_c_question_dialog_btn_ok</action-widget>
+    </action-widgets>
     <child internal-child="vbox">
       <object class="GtkBox">
-        <property name="can-focus">False</property>
+        <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <property name="spacing">2</property>
         <child internal-child="action_area">
           <object class="GtkButtonBox">
-            <property name="can-focus">False</property>
-            <property name="layout-style">end</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
             <child>
               <object class="GtkButton" 
id="anastasis_gtk_b_question_dialog_btn_cancel">
                 <property name="label" translatable="yes">Cancel</property>
                 <property name="visible">True</property>
-                <property name="can-focus">True</property>
-                <property name="receives-default">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
                 <signal name="clicked" 
handler="anastasis_gtk_b_question_dialog_btn_cancel_clicked_cb" swapped="no"/>
               </object>
               <packing>
@@ -30,12 +41,12 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" 
id="anastasis_gtk_b_question_dialog_btn_ok">
+              <object class="GtkButton" 
id="anastasis_gtk_c_question_dialog_btn_ok">
                 <property name="label" translatable="yes">OK</property>
                 <property name="visible">True</property>
                 <property name="sensitive">False</property>
-                <property name="can-focus">False</property>
-                <property name="receives-default">True</property>
+                <property name="can_focus">False</property>
+                <property name="receives_default">True</property>
               </object>
               <packing>
                 <property name="expand">True</property>
@@ -53,12 +64,12 @@
         <child>
           <object class="GtkBox">
             <property name="visible">True</property>
-            <property name="can-focus">False</property>
+            <property name="can_focus">False</property>
             <property name="orientation">vertical</property>
             <child>
               <object class="GtkSeparator">
                 <property name="visible">True</property>
-                <property name="can-focus">False</property>
+                <property name="can_focus">False</property>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -69,11 +80,11 @@
             <child>
               <object class="GtkBox">
                 <property name="visible">True</property>
-                <property name="can-focus">False</property>
+                <property name="can_focus">False</property>
                 <child>
                   <object class="GtkLabel">
                     <property name="visible">True</property>
-                    <property name="can-focus">False</property>
+                    <property name="can_focus">False</property>
                     <property name="label" translatable="yes">Security 
question:</property>
                   </object>
                   <packing>
@@ -86,7 +97,7 @@
                 <child>
                   <object class="GtkLabel" id="security_question_label">
                     <property name="visible">True</property>
-                    <property name="can-focus">False</property>
+                    <property name="can_focus">False</property>
                     <property name="label" translatable="yes">SET DYNAMICALLY 
BY PROGRAM</property>
                   </object>
                   <packing>
@@ -106,7 +117,7 @@
             <child>
               <object class="GtkSeparator">
                 <property name="visible">True</property>
-                <property name="can-focus">False</property>
+                <property name="can_focus">False</property>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -124,11 +135,11 @@
         <child>
           <object class="GtkBox">
             <property name="visible">True</property>
-            <property name="can-focus">False</property>
+            <property name="can_focus">False</property>
             <child>
               <object class="GtkLabel">
                 <property name="visible">True</property>
-                <property name="can-focus">False</property>
+                <property name="can_focus">False</property>
                 <property name="label" translatable="yes">Answer:</property>
               </object>
               <packing>
@@ -141,10 +152,10 @@
             <child>
               <object class="GtkEntry" 
id="anastasis_gtk_c_question_dialog_answer_entry">
                 <property name="visible">True</property>
-                <property name="can-focus">True</property>
+                <property name="can_focus">True</property>
                 <property name="hexpand">True</property>
-                <property name="width-chars">60</property>
-                <property 
name="primary-icon-stock">gtk-dialog-authentication</property>
+                <property name="width_chars">60</property>
+                <property 
name="primary_icon_stock">gtk-dialog-authentication</property>
                 <signal name="changed" 
handler="anastasis_gtk_b_question_dialog_answer_entry_changed_cb" swapped="no"/>
               </object>
               <packing>
@@ -166,18 +177,7 @@
     </child>
     <action-widgets>
       <action-widget 
response="-6">anastasis_gtk_b_question_dialog_btn_cancel</action-widget>
-      <action-widget 
response="-5">anastasis_gtk_b_question_dialog_btn_ok</action-widget>
-    </action-widgets>
-    <child type="titlebar">
-      <object class="GtkLabel">
-        <property name="visible">True</property>
-        <property name="can-focus">False</property>
-        <property name="label" translatable="yes">Solve secuity question 
challenge</property>
-      </object>
-    </child>
-    <action-widgets>
-      <action-widget 
response="-6">anastasis_gtk_b_question_dialog_btn_cancel</action-widget>
-      <action-widget 
response="-5">anastasis_gtk_b_question_dialog_btn_ok</action-widget>
+      <action-widget 
response="-5">anastasis_gtk_c_question_dialog_btn_ok</action-widget>
     </action-widgets>
   </object>
 </interface>
diff --git a/m4/libtool.m4 b/m4/libtool.m4
index c4c0294..a6d21ae 100644
--- a/m4/libtool.m4
+++ b/m4/libtool.m4
@@ -1071,11 +1071,11 @@ _LT_EOF
       # to the OS version, if on x86, and 10.4, the deployment
       # target defaults to 10.4. Don't you love it?
       case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
-       10.0,*86*-darwin8*|10.0,*-darwin[[912]]*)
+       10.0,*86*-darwin8*|10.0,*-darwin[[91]]*)
          _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;;
        10.[[012]][[,.]]*)
          _lt_dar_allow_undefined='$wl-flat_namespace $wl-undefined 
${wl}suppress' ;;
-       10.*|11.*)
+       10.*)
          _lt_dar_allow_undefined='$wl-undefined ${wl}dynamic_lookup' ;;
       esac
     ;;
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 63e5aae..5ce1bf1 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -30,6 +30,8 @@ contrib/anastasis_gtk_auth_add_post.glade
 contrib/anastasis_gtk_auth_add_question.glade
 contrib/anastasis_gtk_auth_add_sms.glade
 contrib/anastasis_gtk_auth_add_video.glade
+contrib/anastasis_gtk_challenge_code.glade
+contrib/anastasis_gtk_challenge_question.glade
 contrib/anastasis_gtk_edit_providers.glade
 contrib/anastasis_gtk_main_window.glade
 contrib/anastasis_gtk_open_file_dialog.glade
diff --git a/src/anastasis/Makefile.am b/src/anastasis/Makefile.am
index b738dd3..6942eb9 100644
--- a/src/anastasis/Makefile.am
+++ b/src/anastasis/Makefile.am
@@ -20,6 +20,8 @@ anastasis_gtk_SOURCES = \
   anastasis-gtk_handle-auth-delete-button-clicked.c \
   anastasis-gtk_handle-auth-edit-provider-clicked.c \
   anastasis-gtk_handle-backup-button-clicked.c \
+  anastasis-gtk_handle-challenge-code.c \
+  anastasis-gtk_handle-challenge-question.c \
   anastasis-gtk_handle-continent-activated.c \
   anastasis-gtk_handle-continent-unselected.c \
   anastasis-gtk_handle-country-activated.c \
diff --git a/src/anastasis/anastasis-gtk_action.c 
b/src/anastasis/anastasis-gtk_action.c
index 77cd4ec..1cea7d7 100644
--- a/src/anastasis/anastasis-gtk_action.c
+++ b/src/anastasis/anastasis-gtk_action.c
@@ -1176,6 +1176,316 @@ action_backup_finished (void)
 }
 
 
+/**
+ * The user clicked one of the challenge buttons,
+ * select the challenge.
+ *
+ * @param button the button that was clicked
+ * @param user_data a `json *` with the challenge
+ */
+static void
+challenge_button_clicked_cb (GtkButton *button,
+                             gpointer user_data)
+{
+  json_t *challenge = user_data;
+  json_t *uuid = json_object_get (challenge,
+                                  "uuid");
+  json_t *args = json_pack ("{s:O}",
+                                   "uuid",
+                                   uuid);
+
+  GNUNET_assert (NULL != uuid);
+  GNUNET_assert (NULL != args);
+  AG_freeze ();
+  ra = ANASTASIS_redux_action (redux_state,
+                               "select_challenge",
+                               args,
+                               &AG_action_cb,
+                               NULL);
+  json_decref (args);
+}
+
+
+/**
+ * Removes @a child from the container in @a user_data.
+ *
+ * @param child a child to remove
+ * @param user_data a `GtkContainer` to remove child from
+ */
+static void
+remove_child (GtkWidget *child,
+              gpointer user_data)
+{
+  GtkContainer *c = user_data;
+
+  gtk_container_remove (c,
+                        child);
+}
+
+
+static void
+action_challenge_selecting (void)
+{
+  json_t *challenges;
+  size_t index;
+  json_t *challenge;
+  GtkBox *box;
+  
+  AG_hide_all_frames ();
+  AG_show ("anastasis_gtk_challenge_frame");
+  challenges = json_object_get (redux_state,
+                                "challenges");
+  box = GTK_BOX (GCG_get_main_window_object (
+                                             
"anastasis_gtk_open_challenge_box"));
+  gtk_container_foreach (GTK_CONTAINER (box),
+                         &remove_child,
+                         box);
+  json_array_foreach (challenges, index, challenge)
+  {
+    GtkButton *b;
+    const char *instructions;
+    struct TALER_Amount cost;
+    struct GNUNET_JSON_Specification spec[] = {
+      GNUNET_JSON_spec_string ("instructions",
+                               &instructions),
+      TALER_JSON_spec_amount ("cost",
+                               &cost),
+      GNUNET_JSON_spec_end ()
+    };
+ 
+    if (GNUNET_OK !=
+        GNUNET_JSON_parse (challenge,
+                           spec,
+                           NULL, NULL))
+    {
+      GNUNET_break (0);
+      continue;
+    }
+    {
+    char *ins_str;
+
+    GNUNET_asprintf (&ins_str,
+                     "#%u: %s",
+                     (unsigned int) index,
+                     instructions);
+    b = gtk_button_new_with_label (ins_str);
+    GNUNET_free (ins_str);
+  }
+    {
+          char *cost_str;
+
+    GNUNET_asprintf (&cost_str,
+                     _("Price: %s"),
+                     TALER_amount2s (&cost));
+    gtk_widget_set_tooltip_text (GTK_WIDGET (b),
+                                 cost_str);
+    GNUNET_free (cost_str);
+    }
+    g_object_connect (G_OBJECT (b),
+                      "signal::clicked",
+                      &challenge_button_clicked_cb,
+                      challenge,
+                      NULL);
+    gtk_container_add (GTK_CONTAINER (box),
+                       GTK_WIDGET (b));
+    
+  }
+  AG_show ("anastasis_gtk_main_control_vbox");
+  AG_show ("anastasis_gtk_main_window_save_as_button");
+  AG_hide ("anastasis_gtk_main_window_quit_button");
+  AG_hide ("anastasis_gtk_main_window_prev_button");
+  AG_hide ("anastasis_gtk_main_window_forward_button");
+}
+
+
+static void
+action_challenge_paying (void)
+{
+  json_t *pprs;
+  size_t index;
+  json_t *ppr;
+
+  // FIXME: json parser is wrong here!
+  AG_hide_all_frames ();
+  pprs = json_object_get (redux_state,
+                          "challenge_payment_requests");
+  json_array_foreach (pprs, index, ppr)
+  {
+    const char *provider;
+    const char *payto;
+    struct GNUNET_JSON_Specification spec[] = {
+      GNUNET_JSON_spec_string ("provider",
+                               &provider),
+      GNUNET_JSON_spec_string ("payto",
+                               &payto),
+      GNUNET_JSON_spec_end ()
+    };
+    GdkPixbuf *pb;
+
+    if (GNUNET_OK !=
+        GNUNET_JSON_parse (ppr,
+                           spec,
+                           NULL, NULL))
+    {
+      GNUNET_break (0);
+      continue;
+    }
+    pb = setup_qrcode ("anastasis_gtk_pay_qrcode_image",
+                       payto);
+    if (NULL == pb)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  _ ("Failed to initialize QR-code pixbuf for `%s'\n"),
+                  payto);
+      continue;
+    }
+
+    if (0 == index)
+    {
+      GtkImage *image;
+      json_t *args;
+
+      image = GTK_IMAGE (GCG_get_main_window_object (
+                           "anastasis_gtk_pay_qrcode_image"));
+      gtk_image_set_from_pixbuf (image,
+                                 pb);
+      GNUNET_assert (NULL == ra);
+      args = json_pack ("{s:s}",
+                        "payto_uri",
+                        payto);
+      ra = ANASTASIS_redux_action (redux_state,
+                                   "await_payment",
+                                   args,
+                                   &AG_action_cb,
+                                   NULL);
+      json_decref (args);
+    }
+    g_object_unref (pb);
+  }
+  AG_show ("anastasis_gtk_pay_frame");
+  AG_show ("anastasis_gtk_pay_image");
+  AG_show ("anastasis_gtk_main_control_vbox");
+  AG_hide ("anastasis_gtk_main_window_unpaid_box"); // FIXME: name!?
+  AG_sensitive ("anastasis_gtk_main_window_prev_button");
+  AG_show ("anastasis_gtk_main_window_prev_button");
+  AG_hide ("anastasis_gtk_main_window_forward_button");
+}
+
+
+/**
+ * Open dialog to allow user to answer security question.
+ *
+ * @param details details about the challenge
+ * @return the dialog object, or NULL on error
+ */
+static GtkDialog *
+diag_question (const json_t *details)
+{
+  GtkBuilder *builder;
+  GtkDialog *ad;
+  GtkLabel *label;
+  const char *instructions;
+
+  builder = GNUNET_GTK_get_new_builder 
("anastasis_gtk_challenge_question.glade",
+                                        NULL);
+  if (NULL == builder)
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
+  ad = GTK_DIALOG (gtk_builder_get_object (builder,
+                                           "anastasis_gtk_c_question_dialog"));
+  label = GTK_LABEL (gtk_builder_get_object (builder,
+                                             "XXX"));
+  instructions = json_string_value (json_object_get (details,
+                                                     "instructions"));
+  gtk_label_set_text (label,
+                      instructions);
+  return ad;
+}
+
+
+static GtkDialog *
+diag_code (const json_t *details)
+{
+  GtkBuilder *builder;
+  GtkDialog *ad;
+  GtkLabel *label;
+  const char *instructions;
+
+  builder = GNUNET_GTK_get_new_builder ("anastasis_gtk_challenge_code.glade",
+                                        NULL);
+  if (NULL == builder)
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
+  ad = GTK_DIALOG (gtk_builder_get_object (builder,
+                                           "anastasis_gtk_c_code_dialog"));
+  label = GTK_LABEL (gtk_builder_get_object (builder,
+                                             "XXX"));
+  instructions = json_string_value (json_object_get (details,
+                                                     "instructions"));
+  gtk_label_set_text (label,
+                      instructions);
+  return ad;
+}
+
+
+static void
+action_challenge_solving (void)
+{
+  static struct
+  {
+    const char *type;
+    GtkDialog *(*ctor)(const json_t *details);
+  } type_map [] = {
+    { .type = "question",
+      .ctor = &diag_question },
+    { .type = "sms",
+      .ctor = &diag_code },
+    { .type = "post",
+      .ctor = &diag_code },
+    { .type = "email",
+      .ctor = &diag_code },
+    { .type = NULL,
+      .ctor = NULL }
+  };
+  const char *type;
+  GtkDialog *diag;
+  json_t *challenge = NULL; // FIXME...
+
+  type = json_string_value (json_object_get (challenge,
+                                             "type"));
+  if (NULL == type)
+  {
+    GNUNET_break (0);
+    return;
+  }
+  /* create dialog based on challenge type */
+  for (unsigned int i = 0; NULL != type_map[i].type; i++)
+  {
+    if (0 != strcmp (type_map[i].type,
+                     type))
+      continue;
+    diag = type_map[i].ctor (challenge);
+    break;
+  }
+  /* show dialog */
+  {
+    GtkWidget *toplevel;
+    GtkBox *box;
+    
+    box = GTK_BOX (GCG_get_main_window_object (
+                                             
"anastasis_gtk_open_challenge_box"));
+    toplevel = gtk_widget_get_toplevel (GTK_WIDGET (box));
+    gtk_window_set_transient_for (GTK_WINDOW (diag),
+                                  GTK_WINDOW (toplevel));
+    gtk_window_present (GTK_WINDOW (diag));
+  }
+}
+
+
 static void
 action_recovery_finished (void)
 {
@@ -1232,6 +1542,12 @@ AG_action_cb (void *cls,
       .action = &action_policies_paying },
     { .state = "BACKUP_FINISHED",
       .action = &action_backup_finished },
+    { .state = "CHALLENGE_SELECTING",
+      .action = &action_challenge_selecting },
+    { .state = "CHALLENGE_PAYING",
+      .action = &action_challenge_paying },
+    { .state = "CHALLENGE_SOLVING",
+      .action = &action_challenge_solving },
     { .state = "RECOVERY_FINISHED",
       .action = &action_recovery_finished },
     { .state = NULL,
diff --git a/src/anastasis/anastasis-gtk_handle-challenge-code.c 
b/src/anastasis/anastasis-gtk_handle-challenge-code.c
new file mode 100644
index 0000000..1628c60
--- /dev/null
+++ b/src/anastasis/anastasis-gtk_handle-challenge-code.c
@@ -0,0 +1,91 @@
+/*
+     This file is part of anastasis-gtk.
+     Copyright (C) 2021 Anastasis SARL
+
+     Anastasis 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.
+
+     Anastasis 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 Anastasis; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @file src/anastasis/anastasis-gtk_handle-challenge-code.c
+ * @brief Handle dialogs for code returned to challenge address (Email, SMS, 
POST)
+ * @author Christian Grothoff
+ */
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_util_lib.h>
+#include "anastasis-gtk_action.h"
+#include "anastasis-gtk_helper.h"
+#include "anastasis-gtk_handle-identity-changed.h"
+#include <jansson.h>
+
+
+/**
+ * Function called from the secure question challenge dialog upon completion.
+ *
+ * @param dialog the pseudonym selection dialog
+ * @param response_id response code from the dialog
+ * @param user_data the builder of the dialog
+ */
+void
+anastasis_gtk_c_code_dialog_response_cb (GtkDialog *dialog,
+                                         gint response_id,
+                                         gpointer user_data)
+{  
+  GtkBuilder *builder = GTK_BUILDER (user_data);
+  GtkEntry *q;
+  const char *qs;
+  json_t *args;
+
+  if (GTK_RESPONSE_OK != response_id)
+  {
+    gtk_widget_destroy (GTK_WIDGET (dialog));
+    g_object_unref (G_OBJECT (builder));
+    return;
+  }
+  q = GTK_ENTRY (gtk_builder_get_object (builder,
+                                         "anastasis_gtk_c_code_entry"));
+  qs = gtk_entry_get_text (q);
+  args = json_pack ("{s:s}",
+                    "solution",
+                    qs);
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+  g_object_unref (G_OBJECT (builder));
+  AG_freeze ();
+  ra = ANASTASIS_redux_action (redux_state,
+                               "solve_challenge",
+                               args,
+                               &AG_action_cb,
+                               NULL);
+  json_decref (args);
+}
+
+
+void
+anastasis_gtk_c_code_dialog_answer_entry_changed_cb (GtkEntry *entry,
+                                                     gpointer user_data)
+{
+  GtkBuilder *builder = GTK_BUILDER (user_data);
+  GtkEntry *a;
+  const char *as;
+
+  a = GTK_ENTRY (gtk_builder_get_object (builder,
+                                         "anastasis_gtk_c_code_entry"));
+  as = gtk_entry_get_text (a);
+  gtk_widget_set_sensitive (
+                            GTK_WIDGET (gtk_builder_get_object (builder,
+                                                                
"anastasis_gtk_c_code_dialog_btn_ok")),
+                            (NULL != as) &&
+                            (0 < strlen (as)));
+}
diff --git a/src/anastasis/anastasis-gtk_handle-challenge-question.c 
b/src/anastasis/anastasis-gtk_handle-challenge-question.c
new file mode 100644
index 0000000..a62bdc4
--- /dev/null
+++ b/src/anastasis/anastasis-gtk_handle-challenge-question.c
@@ -0,0 +1,91 @@
+/*
+     This file is part of anastasis-gtk.
+     Copyright (C) 2021 Anastasis SARL
+
+     Anastasis 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.
+
+     Anastasis 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 Anastasis; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @file src/anastasis/anastasis-gtk_handle-challenge-question.c
+ * @brief Handle dialogs for secure question
+ * @author Christian Grothoff
+ */
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_util_lib.h>
+#include "anastasis-gtk_action.h"
+#include "anastasis-gtk_helper.h"
+#include "anastasis-gtk_handle-identity-changed.h"
+#include <jansson.h>
+
+
+/**
+ * Function called from the secure question challenge dialog upon completion.
+ *
+ * @param dialog the pseudonym selection dialog
+ * @param response_id response code from the dialog
+ * @param user_data the builder of the dialog
+ */
+void
+anastasis_gtk_c_question_dialog_response_cb (GtkDialog *dialog,
+                                             gint response_id,
+                                             gpointer user_data)
+{
+  GtkBuilder *builder = GTK_BUILDER (user_data);
+  GtkEntry *q;
+  const char *qs;
+  json_t *args;
+
+  if (GTK_RESPONSE_OK != response_id)
+  {
+    gtk_widget_destroy (GTK_WIDGET (dialog));
+    g_object_unref (G_OBJECT (builder));
+    return;
+  }
+  q = GTK_ENTRY (gtk_builder_get_object (builder,
+                                         
"anastasis_gtk_c_question_dialog_answer_entry"));
+  qs = gtk_entry_get_text (q);
+  args = json_pack ("{s:s}",
+                    "solution",
+                    qs);
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+  g_object_unref (G_OBJECT (builder));
+  AG_freeze ();
+  ra = ANASTASIS_redux_action (redux_state,
+                               "solve_challenge",
+                               args,
+                               &AG_action_cb,
+                               NULL);
+  json_decref (args);
+}
+
+
+void
+anastasis_gtk_c_question_dialog_answer_entry_changed_cb (GtkEntry *entry,
+                                                         gpointer user_data)
+{
+  GtkBuilder *builder = GTK_BUILDER (user_data);
+  GtkEntry *a;
+  const char *as;
+
+  a = GTK_ENTRY (gtk_builder_get_object (builder,
+                                         
"anastasis_gtk_c_question_dialog_answer_entry"));
+  as = gtk_entry_get_text (a);  
+  gtk_widget_set_sensitive (
+                            GTK_WIDGET (gtk_builder_get_object (builder,
+                                                                
"anastasis_gtk_c_question_dialog_btn_ok")),
+                            (NULL != as) &&
+                            (0 < strlen (as)));
+}

-- 
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]