aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-02 20:09:10 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-02 20:09:10 +0000
commit84a6a4b4466a0920b8ff7e0c59ee139d13f7a3d3 (patch)
tree7066aeef467346f05a4e2cf9cfd74a035d2b6194 /src
parentc063d2964498620ed0cb9772637067c5c285fb3f (diff)
downloadgnunet-gtk-84a6a4b4466a0920b8ff7e0c59ee139d13f7a3d3.tar.gz
gnunet-gtk-84a6a4b4466a0920b8ff7e0c59ee139d13f7a3d3.zip
adding logic to import caller ID into our address book
Diffstat (limited to 'src')
-rw-r--r--src/conversation/Makefile.am1
-rw-r--r--src/conversation/gnunet-conversation-gtk_import.c96
-rw-r--r--src/conversation/gnunet-conversation-gtk_import.h9
-rw-r--r--src/conversation/gnunet-conversation-gtk_phone.c23
-rw-r--r--src/conversation/gnunet-conversation-gtk_use_current.c233
5 files changed, 317 insertions, 45 deletions
diff --git a/src/conversation/Makefile.am b/src/conversation/Makefile.am
index 35a1fb1f..abcc8e2f 100644
--- a/src/conversation/Makefile.am
+++ b/src/conversation/Makefile.am
@@ -24,6 +24,7 @@ gnunet_conversation_gtk_SOURCES = \
24 gnunet-conversation-gtk_import.h \ 24 gnunet-conversation-gtk_import.h \
25 gnunet-conversation-gtk_log.c \ 25 gnunet-conversation-gtk_log.c \
26 gnunet-conversation-gtk_log.h \ 26 gnunet-conversation-gtk_log.h \
27 gnunet-conversation-gtk_use_current.c \
27 gnunet-conversation-gtk_phone.c \ 28 gnunet-conversation-gtk_phone.c \
28 gnunet-conversation-gtk_phone.h \ 29 gnunet-conversation-gtk_phone.h \
29 gnunet-conversation-gtk_visibility.c \ 30 gnunet-conversation-gtk_visibility.c \
diff --git a/src/conversation/gnunet-conversation-gtk_import.c b/src/conversation/gnunet-conversation-gtk_import.c
index 0d78445b..855c6c1a 100644
--- a/src/conversation/gnunet-conversation-gtk_import.c
+++ b/src/conversation/gnunet-conversation-gtk_import.c
@@ -29,6 +29,8 @@
29#include "gnunet-conversation-gtk_contacts.h" 29#include "gnunet-conversation-gtk_contacts.h"
30#include "gnunet-conversation-gtk_egos.h" 30#include "gnunet-conversation-gtk_egos.h"
31#include "gnunet-conversation-gtk_import.h" 31#include "gnunet-conversation-gtk_import.h"
32#include "gnunet-conversation-gtk_zones.h"
33
32 34
33/** 35/**
34 * Handle to the namestore. 36 * Handle to the namestore.
@@ -81,6 +83,16 @@ static struct GNUNET_GNSRECORD_Data my_rd;
81 */ 83 */
82static char *my_rd_data; 84static char *my_rd_data;
83 85
86/**
87 * When does our phone record expire?
88 */
89static struct GNUNET_TIME_Relative expiration_time;
90
91/**
92 * Is our phone record private?
93 */
94static int private_record;
95
84 96
85/** 97/**
86 * Continuation called to notify client about result of the 98 * Continuation called to notify client about result of the
@@ -115,9 +127,12 @@ GSC_add_contact (const gchar *name,
115 const gchar *address) 127 const gchar *address)
116{ 128{
117 struct GNUNET_GNSRECORD_Data rd; 129 struct GNUNET_GNSRECORD_Data rd;
118 struct GNUNET_CRYPTO_EcdsaPublicKey pkey; 130 struct GNUNET_CRYPTO_EcdsaPublicKey rvalue;
131 const void *value;
119 struct GNUNET_IDENTITY_Ego *ego; 132 struct GNUNET_IDENTITY_Ego *ego;
120 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_pkey; 133 size_t value_size;
134 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zkey;
135 uint32_t type;
121 136
122 if (NULL != add_contact_qe) 137 if (NULL != add_contact_qe)
123 { 138 {
@@ -126,32 +141,35 @@ GSC_add_contact (const gchar *name,
126 return; 141 return;
127 } 142 }
128 143
129 // FIXME: what should really be the preferred address format here? 144 /* if we got a .zkey address, we create a PKEY record,
130 // (CNAME? PKEY? PHONE?) 145 otherwise a CNAME record */
131 if (GNUNET_OK != 146 if (GNUNET_OK ==
132 GNUNET_CRYPTO_ecdsa_public_key_from_string (address, 147 GNUNET_GNSRECORD_zkey_to_pkey (address,
133 strlen (address), 148 &rvalue))
134 &pkey))
135 { 149 {
136 GCG_log (_("Adding contact failed: %s\n"), 150 type = GNUNET_GNSRECORD_TYPE_PKEY;
137 _("invalid address")); 151 value = &rvalue;
138 return; 152 value_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey);
139 } 153 }
140 rd.data = &pkey; 154 else
141 rd.data_size = sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); 155 {
142 rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; 156 type = GNUNET_DNSPARSER_TYPE_CNAME;
157 value = address;
158 value_size = strlen (address) + 1;
159 }
160 rd.data = value;
161 rd.data_size = value_size;
162 rd.record_type = type;
143 rd.flags 163 rd.flags
144 = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION 164 = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION
145 | GNUNET_GNSRECORD_RF_PRIVATE; 165 | GNUNET_GNSRECORD_RF_PRIVATE;
146 rd.expiration_time 166 rd.expiration_time
147 = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; 167 = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
148 ego = GCG_EGOS_get_selected_ego (); 168 ego = GCG_ZONES_get_selected_zone ();
149 zone_pkey = GNUNET_IDENTITY_ego_get_private_key (ego); 169 zkey = GNUNET_IDENTITY_ego_get_private_key (ego);
150 /* FIXME: we should check if the 'name' already exists,
151 and not do this if it does... */
152 add_contact_qe 170 add_contact_qe
153 = GNUNET_NAMESTORE_records_store (ns, 171 = GNUNET_NAMESTORE_records_store (ns,
154 zone_pkey, 172 zkey,
155 name, 173 name,
156 1, &rd, 174 1, &rd,
157 &add_contact_continuation, NULL); 175 &add_contact_continuation, NULL);
@@ -170,8 +188,8 @@ GSC_add_contact (const gchar *name,
170 */ 188 */
171static void 189static void
172add_phone_continuation (void *cls, 190add_phone_continuation (void *cls,
173 int32_t success, 191 int32_t success,
174 const char *emsg) 192 const char *emsg)
175{ 193{
176 add_phone_qe = NULL; 194 add_phone_qe = NULL;
177 if (GNUNET_SYSERR == success) 195 if (GNUNET_SYSERR == success)
@@ -256,6 +274,11 @@ GSC_add_phone (const gchar *label,
256 GNUNET_free_non_null (my_rd_data); 274 GNUNET_free_non_null (my_rd_data);
257 phone_label = GNUNET_strdup (label); 275 phone_label = GNUNET_strdup (label);
258 my_rd = *rd; 276 my_rd = *rd;
277 my_rd.expiration_time = expiration_time.rel_value_us;
278 my_rd.flags |= GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
279 if (GNUNET_YES == private_record)
280 my_rd.flags |= GNUNET_GNSRECORD_RF_PRIVATE;
281
259 my_rd.data = my_rd_data = GNUNET_malloc (rd->data_size); 282 my_rd.data = my_rd_data = GNUNET_malloc (rd->data_size);
260 memcpy (my_rd_data, rd->data, rd->data_size); 283 memcpy (my_rd_data, rd->data, rd->data_size);
261 add_waiting = GNUNET_YES; 284 add_waiting = GNUNET_YES;
@@ -367,13 +390,42 @@ GSC_remove_phone ()
367} 390}
368 391
369 392
393
394/**
395 * Obtain namestore handle.
396 *
397 * @return handle to the namestore.
398 */
399struct GNUNET_NAMESTORE_Handle *
400GCG_IMPORT_get_namestore ()
401{
402 return ns;
403}
404
405
370/** 406/**
371 * Initialize the import subsystem. 407 * Initialize the import subsystem.
372 */ 408 */
373void 409void
374GCG_IMPORT_init () 410GCG_IMPORT_init ()
375{ 411{
376 ns = GNUNET_NAMESTORE_connect (GCG_get_configuration ()); 412 const struct GNUNET_CONFIGURATION_Handle *cfg;
413
414 cfg = GCG_get_configuration ();
415 ns = GNUNET_NAMESTORE_connect (cfg);
416 private_record = GNUNET_CONFIGURATION_get_value_yesno (cfg,
417 "CONVERSATION",
418 "RECORD_IS_PRIVATE");
419 if (GNUNET_OK !=
420 GNUNET_CONFIGURATION_get_value_time (cfg,
421 "CONVERSATION",
422 "RECORD_EXPIRATION",
423 &expiration_time))
424 {
425 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
426 "CONVERSATION",
427 "RECORD_EXPIRATION");
428 }
377} 429}
378 430
379 431
diff --git a/src/conversation/gnunet-conversation-gtk_import.h b/src/conversation/gnunet-conversation-gtk_import.h
index 000fa4e9..6d0bf997 100644
--- a/src/conversation/gnunet-conversation-gtk_import.h
+++ b/src/conversation/gnunet-conversation-gtk_import.h
@@ -59,6 +59,15 @@ GSC_remove_phone (void);
59 59
60 60
61/** 61/**
62 * Obtain namestore handle.
63 *
64 * @return handle to the namestore.
65 */
66struct GNUNET_NAMESTORE_Handle *
67GCG_IMPORT_get_namestore (void);
68
69
70/**
62 * Initialize the import subsystem. 71 * Initialize the import subsystem.
63 */ 72 */
64void 73void
diff --git a/src/conversation/gnunet-conversation-gtk_phone.c b/src/conversation/gnunet-conversation-gtk_phone.c
index 74d49805..af3930ee 100644
--- a/src/conversation/gnunet-conversation-gtk_phone.c
+++ b/src/conversation/gnunet-conversation-gtk_phone.c
@@ -1099,29 +1099,6 @@ GNUNET_CONVERSATION_GTK_on_reject_clicked (GtkButton *button,
1099 1099
1100 1100
1101/** 1101/**
1102 * User clicked the '> contact' button to move the selected
1103 * caller's information into our address book.
1104 *
1105 * @param button the button
1106 * @param user_data builder (unused)
1107 */
1108void
1109gnunet_conversation_gtk_use_current_button_clicked (GtkButton *button,
1110 gpointer *user_data)
1111{
1112 GNUNET_break (0); // FIXME: implement!
1113 // need to determine desired label for the contact!
1114 // => prompt user!?
1115#if 0
1116 const gchar *target;
1117
1118 target = gtk_entry_get_text (address_entry);
1119 GSC_add_contact (label, address);
1120#endif
1121}
1122
1123
1124/**
1125 * The "resume" button was clicked. Resume a call! 1102 * The "resume" button was clicked. Resume a call!
1126 * 1103 *
1127 * @param button the button 1104 * @param button the button
diff --git a/src/conversation/gnunet-conversation-gtk_use_current.c b/src/conversation/gnunet-conversation-gtk_use_current.c
new file mode 100644
index 00000000..fa4f1279
--- /dev/null
+++ b/src/conversation/gnunet-conversation-gtk_use_current.c
@@ -0,0 +1,233 @@
1/*
2 This file is part of GNUnet.
3 (C) 2014 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file src/conversation/gnunet-conversation-gtk_use_current.c
23 * @brief logic to import caller ID into address book
24 * @author Christian Grothoff
25 */
26#include "gnunet-conversation-gtk.h"
27#include "gnunet-conversation-gtk_egos.h"
28#include "gnunet-conversation-gtk_history.h"
29#include "gnunet-conversation-gtk_import.h"
30#include "gnunet-conversation-gtk_log.h"
31#include "gnunet-conversation-gtk_phone.h"
32#include "gnunet-conversation-gtk_zones.h"
33
34
35/**
36 * Queue entry for the 'check exists' operation.
37 */
38static struct GNUNET_NAMESTORE_QueueEntry *qe;
39
40
41/**
42 * Process a record that was stored in the namestore.
43 *
44 * @param cls closure, NULL
45 * @param zone private key of the zone; NULL on disconnect
46 * @param label label of the records; NULL on disconnect
47 * @param rd_count number of entries in @a rd array, 0 if label was deleted
48 * @param rd array of records with data to store
49 */
50static void
51handle_existing_records (void *cls,
52 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
53 const char *label,
54 unsigned int rd_count,
55 const struct GNUNET_GNSRECORD_Data *rd)
56{
57 GtkBuilder *builder = GTK_BUILDER (cls);
58 GtkWidget *b_add;
59
60 qe = NULL;
61 if (0 != rd_count)
62 {
63 GCG_log (_("Label `%s' in use\n"),
64 label);
65 return;
66 }
67 b_add = GTK_WIDGET (gtk_builder_get_object
68 (builder,
69 "gnunet_conversation_gtk_enter_label_dialog_add_button"));
70 gtk_widget_set_sensitive (b_add, TRUE);
71}
72
73
74/**
75 * The user has edited the label; check if the new label
76 * is valid and available and update the sensitivity of
77 * the "add" button.
78 *
79 * @param editable the entry that changed
80 * @param user_data our builder
81 */
82void
83gnunet_conversation_gtk_enter_label_entry_changed_cb (GtkEditable *editable,
84 gpointer user_data)
85{
86 GtkBuilder *builder = GTK_BUILDER (user_data);
87 GtkEntry *label_entry;
88 const gchar *label;
89 GtkWidget *b_add;
90 struct GNUNET_IDENTITY_Ego *ego;
91 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey;
92
93 if (NULL != qe)
94 {
95 GNUNET_NAMESTORE_cancel (qe);
96 qe = NULL;
97 }
98 label_entry = GTK_ENTRY (gtk_builder_get_object
99 (builder,
100 ("gnunet_conversation_gtk_enter_label_entry")));
101 label = gtk_entry_get_text (label_entry);
102 b_add = GTK_WIDGET (gtk_builder_get_object
103 (builder,
104 "gnunet_conversation_gtk_enter_label_dialog_add_button"));
105 gtk_widget_set_sensitive (b_add, FALSE);
106 if (GNUNET_OK !=
107 GNUNET_DNSPARSER_check_label (label))
108 {
109 GCG_log (_("Invalid label `%s'\n"),
110 label);
111 return;
112 }
113 ego = GCG_ZONES_get_selected_zone ();
114 pkey = GNUNET_IDENTITY_ego_get_private_key (ego);
115 qe = GNUNET_NAMESTORE_records_lookup (GCG_IMPORT_get_namestore (),
116 pkey,
117 label,
118 &handle_existing_records,
119 builder);
120}
121
122
123/**
124 * The user has clicked the "add" button, close the dialog and
125 * complete the "add contact" operation.
126 *
127 * @param button the button
128 * @param user_data our builder
129 */
130void
131gnunet_conversation_gtk_enter_label_dialog_add_button_clicked_cb (GtkButton *button,
132 gpointer *user_data)
133{
134 GtkBuilder *builder = GTK_BUILDER (user_data);
135 GtkWidget *dialog;
136 const gchar *target;
137 const gchar *label;
138 GtkEntry *address_entry;
139 GtkEntry *label_entry;
140
141 address_entry = GTK_ENTRY (GCG_get_main_window_object
142 ("gnunet_conversation_gtk_address_entry"));
143 target = gtk_entry_get_text (address_entry);
144 label_entry = GTK_ENTRY (gtk_builder_get_object
145 (builder,
146 ("gnunet_conversation_gtk_enter_label_entry")));
147 label = gtk_entry_get_text (label_entry);
148 GSC_add_contact (label, target);
149 dialog = GTK_WIDGET (gtk_builder_get_object
150 (builder,
151 "gnunet_conversation_gtk_enter_label_window"));
152 gtk_widget_destroy (GTK_WIDGET (dialog));
153 g_object_unref (G_OBJECT (builder));
154}
155
156
157/**
158 * The user has clicked the "cancel" button, close the dialog and
159 * abort the "add contact" operation.
160 *
161 * @param button the button
162 * @param user_data our builder
163 */
164void
165gnunet_conversation_gtk_enter_label_dialog_cancel_button_clicked_cb (GtkButton *button,
166 gpointer *user_data)
167{
168 GtkBuilder *builder = GTK_BUILDER (user_data);
169 GtkWidget *dialog;
170
171 dialog = GTK_WIDGET (gtk_builder_get_object
172 (builder,
173 "gnunet_conversation_gtk_enter_label_window"));
174 gtk_widget_destroy (GTK_WIDGET (dialog));
175 g_object_unref (G_OBJECT (builder));
176}
177
178
179/**
180 * User closed the window of the enter label dialog.
181 *
182 * @param widget the window
183 * @param event the deletion event
184 * @param user_data the 'GtkBuilder' of the URI dialog
185 * @return FALSE (allow destruction)
186 */
187gboolean
188gnunet_conversation_gtk_enter_label_window_delete_event_cb (GtkWidget *widget,
189 GdkEvent *event,
190 gpointer user_data)
191{
192 GtkBuilder *builder = GTK_BUILDER (user_data);
193
194 g_object_unref (G_OBJECT (builder));
195 return FALSE;
196}
197
198
199/**
200 * User clicked the '> contact' button to move the selected
201 * caller's information into our address book.
202 *
203 * @param button the button
204 * @param user_data main loop context (unused)
205 */
206void
207gnunet_conversation_gtk_use_current_button_clicked (GtkButton *button,
208 gpointer *user_data)
209{
210 GtkBuilder *builder;
211 GtkWidget *dialog;
212 GtkWidget *toplevel;
213
214 builder =
215 GNUNET_GTK_get_new_builder ("gnunet_conversation_gtk_enter_label.glade",
216 NULL);
217 if (NULL == builder)
218 {
219 GNUNET_break (0);
220 return;
221 }
222 dialog = GTK_WIDGET (gtk_builder_get_object
223 (builder,
224 "gnunet_conversation_gtk_enter_label_window"));
225 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
226 if (GTK_IS_WINDOW (toplevel))
227 gtk_window_set_transient_for (GTK_WINDOW (dialog),
228 GTK_WINDOW (toplevel));
229 gtk_widget_show (dialog);
230}
231
232
233/* end of gnunet-conversation-gtk_use_current.c */