aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/fs/gnunet-fs-gtk_common.c44
-rw-r--r--src/fs/gnunet-fs-gtk_common.h2
-rw-r--r--src/identity/Makefile.am2
-rw-r--r--src/identity/gnunet-identity-gtk.c11
-rw-r--r--src/identity/gnunet-identity-gtk.h40
-rw-r--r--src/identity/gnunet-identity-gtk_advertise.c198
-rw-r--r--src/identity/gnunet-identity-gtk_advertise.h8
7 files changed, 286 insertions, 19 deletions
diff --git a/src/fs/gnunet-fs-gtk_common.c b/src/fs/gnunet-fs-gtk_common.c
index f0746883..288a334b 100644
--- a/src/fs/gnunet-fs-gtk_common.c
+++ b/src/fs/gnunet-fs-gtk_common.c
@@ -28,6 +28,7 @@
28#include "gnunet-fs-gtk.h" 28#include "gnunet-fs-gtk.h"
29#include "gnunet-fs-gtk_event-handler.h" 29#include "gnunet-fs-gtk_event-handler.h"
30 30
31
31/** 32/**
32 * Converts metadata specified by @a data of size @a data_len 33 * Converts metadata specified by @a data of size @a data_len
33 * and saved in format @a format to UTF-8 encoded string. 34 * and saved in format @a format to UTF-8 encoded string.
@@ -196,13 +197,13 @@ GNUNET_FS_GTK_get_thumbnail_from_meta_data (const struct
196 197
197 198
198/** 199/**
199 * mmap the given file and run the GNUNET_FS_directory_list_contents 200 * mmap the given file and run the #GNUNET_FS_directory_list_contents
200 * function on it. 201 * function on it.
201 * 202 *
202 * @param filename name with the directory 203 * @param filename name with the directory
203 * @param dep function to call on each entry 204 * @param dep function to call on each entry
204 * @param dep_cls closure for 'dep' 205 * @param dep_cls closure for @a dep
205 * @return GNUNET_OK on success 206 * @return #GNUNET_OK on success
206 */ 207 */
207int 208int
208GNUNET_FS_GTK_mmap_and_scan (const char *filename, 209GNUNET_FS_GTK_mmap_and_scan (const char *filename,
@@ -260,13 +261,13 @@ GNUNET_FS_GTK_mmap_and_scan (const char *filename,
260 * the respective meta data. 261 * the respective meta data.
261 * 262 *
262 * @param meta meta data to inspect 263 * @param meta meta data to inspect
263 * @param is_a_dup is set to GNUNET_YES if the result is a dup, and there was 264 * @param is_a_dup is set to #GNUNET_YES if the result is a dup, and there was
264 * no description to be found. GNUNET_NO otherwise. 265 * no description to be found. #GNUNET_NO otherwise.
265 * @return description of the result in utf-8, never NULL 266 * @return description of the result in utf-8, never NULL
266 */ 267 */
267char * 268char *
268GNUNET_FS_GTK_get_description_from_metadata ( 269GNUNET_FS_GTK_get_description_from_metadata (const struct GNUNET_CONTAINER_MetaData *meta,
269 const struct GNUNET_CONTAINER_MetaData *meta, int *is_a_dup) 270 int *is_a_dup)
270{ 271{
271 char *desc; 272 char *desc;
272 char *utf8_desc; 273 char *utf8_desc;
@@ -438,10 +439,11 @@ GNUNET_FS_GTK_handle_uri (const struct GNUNET_FS_Uri *uri,
438 * 439 *
439 * @param rr row reference 440 * @param rr row reference
440 * @param iter pointer to an iter structure to fill 441 * @param iter pointer to an iter structure to fill
441 * @return GNUNET_OK if iter was filled, GNUNET_SYSERR otherwise 442 * @return #GNUNET_OK if iter was filled, #GNUNET_SYSERR otherwise
442 */ 443 */
443int 444int
444GNUNET_GTK_get_iter_from_reference (GtkTreeRowReference *rr, GtkTreeIter *iter) 445GNUNET_GTK_get_iter_from_reference (GtkTreeRowReference *rr,
446 GtkTreeIter *iter)
445{ 447{
446 int result = GNUNET_SYSERR; 448 int result = GNUNET_SYSERR;
447 if (rr != NULL) 449 if (rr != NULL)
@@ -464,6 +466,7 @@ GNUNET_GTK_get_iter_from_reference (GtkTreeRowReference *rr, GtkTreeIter *iter)
464 return result; 466 return result;
465} 467}
466 468
469
467/** 470/**
468 * Creates a GtkTreeRowReference from a GtkTreeIter. 471 * Creates a GtkTreeRowReference from a GtkTreeIter.
469 * 472 *
@@ -487,8 +490,29 @@ GNUNET_GTK_get_reference_from_iter (GtkTreeModel *model, GtkTreeIter *iter)
487 return result; 490 return result;
488} 491}
489 492
493
494/**
495 * Fills "next_iter" with iterator for an item that comes next in the tree
496 * after "iter".
497 * Next item is, in order of precedence:
498 * 1) First child of "iter", if "iter" has children and "allow_children"
499 * is enabled.
500 * 2) Next sibling of "iter", unless "iter" is the last sibling.
501 * If none of those are present, function recursively checks parents of
502 * "iter" until it finds next item or runs out of parents.
503 *
504 * @param model a model to reference
505 * @param iter an iter that points to current row in the model
506 * @param allow_children whether child of "iter" is considered to be next.
507 * @param next_iter will be filled with the next row in the model on success
508 * @return TRUE if next_iter is set to a valid iter,
509 * FALSE if ran out of parents
510 */
490gboolean 511gboolean
491GNUNET_GTK_tree_model_get_next_flat_iter (GtkTreeModel *model, GtkTreeIter *iter, gboolean allow_children, GtkTreeIter *next_iter) 512GNUNET_GTK_tree_model_get_next_flat_iter (GtkTreeModel *model,
513 GtkTreeIter *iter,
514 gboolean allow_children,
515 GtkTreeIter *next_iter)
492{ 516{
493 GtkTreeIter current_iter = *iter; 517 GtkTreeIter current_iter = *iter;
494 while (TRUE) 518 while (TRUE)
diff --git a/src/fs/gnunet-fs-gtk_common.h b/src/fs/gnunet-fs-gtk_common.h
index 53990378..96fcbc30 100644
--- a/src/fs/gnunet-fs-gtk_common.h
+++ b/src/fs/gnunet-fs-gtk_common.h
@@ -73,7 +73,7 @@ GNUNET_FS_GTK_get_expiration_time (GtkSpinButton * spin);
73 * @param filename name with the directory 73 * @param filename name with the directory
74 * @param dep function to call on each entry 74 * @param dep function to call on each entry
75 * @param dep_cls closure for @a dep 75 * @param dep_cls closure for @a dep
76 * @return GNUNET_OK on success 76 * @return #GNUNET_OK on success
77 */ 77 */
78int 78int
79GNUNET_FS_GTK_mmap_and_scan (const char *filename, 79GNUNET_FS_GTK_mmap_and_scan (const char *filename,
diff --git a/src/identity/Makefile.am b/src/identity/Makefile.am
index bb5acc31..119908fb 100644
--- a/src/identity/Makefile.am
+++ b/src/identity/Makefile.am
@@ -10,7 +10,7 @@ INCLUDES = \
10bin_PROGRAMS = gnunet-identity-gtk 10bin_PROGRAMS = gnunet-identity-gtk
11 11
12gnunet_identity_gtk_SOURCES = \ 12gnunet_identity_gtk_SOURCES = \
13 gnunet-identity-gtk.c \ 13 gnunet-identity-gtk.c gnunet-identity-gtk.h \
14 gnunet-identity-gtk_about.c \ 14 gnunet-identity-gtk_about.c \
15 gnunet-identity-gtk_advertise.c gnunet-identity-gtk_advertise.h 15 gnunet-identity-gtk_advertise.c gnunet-identity-gtk_advertise.h
16gnunet_identity_gtk_LDADD = \ 16gnunet_identity_gtk_LDADD = \
diff --git a/src/identity/gnunet-identity-gtk.c b/src/identity/gnunet-identity-gtk.c
index 897ca96b..c950feb6 100644
--- a/src/identity/gnunet-identity-gtk.c
+++ b/src/identity/gnunet-identity-gtk.c
@@ -108,10 +108,12 @@ static struct OperationContext *oc_tail;
108 108
109 109
110/** 110/**
111 * Get cfg. 111 * Get our configuration.
112 *
113 * @return configuration handle
112 */ 114 */
113static const struct GNUNET_CONFIGURATION_Handle * 115const struct GNUNET_CONFIGURATION_Handle *
114get_configuration () 116GIG_get_configuration ()
115{ 117{
116 return GNUNET_GTK_main_loop_get_configuration (ml); 118 return GNUNET_GTK_main_loop_get_configuration (ml);
117} 119}
@@ -384,6 +386,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
384{ 386{
385 struct OperationContext *oc; 387 struct OperationContext *oc;
386 388
389 GIG_advertise_shutdown_ ();
387 while (NULL != (oc = oc_head)) 390 while (NULL != (oc = oc_head))
388 { 391 {
389 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 392 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -527,7 +530,7 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
527 gtk_widget_show (main_window); 530 gtk_widget_show (main_window);
528 gtk_window_present (GTK_WINDOW (main_window)); 531 gtk_window_present (GTK_WINDOW (main_window));
529 } 532 }
530 identity = GNUNET_IDENTITY_connect (get_configuration (), 533 identity = GNUNET_IDENTITY_connect (GIG_get_configuration (),
531 &add_ego, 534 &add_ego,
532 NULL); 535 NULL);
533 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 536 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
diff --git a/src/identity/gnunet-identity-gtk.h b/src/identity/gnunet-identity-gtk.h
new file mode 100644
index 00000000..c3d30b7b
--- /dev/null
+++ b/src/identity/gnunet-identity-gtk.h
@@ -0,0 +1,40 @@
1/*
2 This file is part of GNUnet
3 (C) 2013 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/identity/gnunet-identity-gtk.h
23 * @author Christian Grothoff
24 */
25#include <gnunet/gnunet_util_lib.h>
26
27
28#ifndef GNUNET_IDENTITY_GTK_H
29#define GNUNET_IDENTITY_GTK_H
30
31/**
32 * Get our configuration.
33 *
34 * @return configuration handle
35 */
36const struct GNUNET_CONFIGURATION_Handle *
37GIG_get_configuration (void);
38
39
40#endif
diff --git a/src/identity/gnunet-identity-gtk_advertise.c b/src/identity/gnunet-identity-gtk_advertise.c
index 07ab09fd..63bba35e 100644
--- a/src/identity/gnunet-identity-gtk_advertise.c
+++ b/src/identity/gnunet-identity-gtk_advertise.c
@@ -24,6 +24,7 @@
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "gnunet-identity-gtk_advertise.h" 26#include "gnunet-identity-gtk_advertise.h"
27#include "gnunet-identity-gtk.h"
27#include <gnunet/gnunet_fs_service.h> 28#include <gnunet/gnunet_fs_service.h>
28 29
29 30
@@ -148,6 +149,120 @@ struct AdvertiseContext
148}; 149};
149 150
150 151
152/**
153 * Context for the publishing operation.
154 */
155struct PublishContext
156{
157
158 /**
159 * Kept in a DLL.
160 */
161 struct PublishContext *next;
162
163 /**
164 * Kept in a DLL.
165 */
166 struct PublishContext *prev;
167
168 /**
169 * Handle to FS subsystem.
170 */
171 struct GNUNET_FS_Handle *fs;
172
173 /**
174 * Handle to the publish operation.
175 */
176 struct GNUNET_FS_PublishKskContext *pub;
177
178};
179
180
181/**
182 * Kept in a DLL.
183 */
184static struct PublishContext *pc_head;
185
186/**
187 * Kept in a DLL.
188 */
189static struct PublishContext *pc_tail;
190
191
192/**
193 * Shutdown advertisement subsystem, this process is terminating.
194 */
195void
196GIG_advertise_shutdown_ ()
197{
198 struct PublishContext *pc;
199
200 while (NULL != (pc = pc_head))
201 {
202 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
203 _("Aborting advertising operation due to shutdown.\n"));
204 GNUNET_CONTAINER_DLL_remove (pc_head,
205 pc_tail,
206 pc);
207 GNUNET_FS_publish_ksk_cancel (pc->pub);
208 GNUNET_FS_stop (pc->fs);
209 GNUNET_free (pc);
210 }
211}
212
213
214/**
215 * Function called once we published the advertisement.
216 *
217 * @param cls closure with the `struct PublishContext`
218 * @param uri URI under which the block is now available, NULL on error
219 * @param emsg error message, NULL on success
220 */
221static void
222publish_continuation (void *cls,
223 const struct GNUNET_FS_Uri *uri,
224 const char *emsg)
225{
226 struct PublishContext *pc = cls;
227
228 pc->pub = NULL;
229 if (NULL == uri)
230 {
231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
232 _("Failed to advertise ego: %s\n"),
233 emsg);
234 /* FIXME: might want to output to GUI... */
235 }
236 GNUNET_FS_stop (pc->fs);
237 GNUNET_CONTAINER_DLL_remove (pc_head,
238 pc_tail,
239 pc);
240 GNUNET_free (pc);
241}
242
243
244/**
245 * Notification of FS to a client about the progress of an
246 * operation. Callbacks of this type will be used for uploads,
247 * downloads and searches. Some of the arguments depend a bit
248 * in their meaning on the context in which the callback is used.
249 *
250 * @param cls closure
251 * @param info details about the event, specifying the event type
252 * and various bits about the event
253 * @return client-context (for the next progress call
254 * for this operation; should be set to NULL for
255 * SUSPEND and STOPPED events). The value returned
256 * will be passed to future callbacks in the respective
257 * field in the `struct GNUNET_FS_ProgressInfo`.
258 */
259static void *
260progress_cb (void *cls,
261 const struct GNUNET_FS_ProgressInfo *info)
262{
263 return NULL;
264}
265
151 266
152/** 267/**
153 * The user terminated the dialog. Perform the appropriate action. 268 * The user terminated the dialog. Perform the appropriate action.
@@ -162,12 +277,89 @@ GNUNET_GTK_identity_advertise_dialog_response_cb (GtkDialog *dialog,
162 gpointer user_data) 277 gpointer user_data)
163{ 278{
164 struct AdvertiseContext *ac = user_data; 279 struct AdvertiseContext *ac = user_data;
165 280 struct GNUNET_FS_Uri *ksk_uri;
166 if (GTK_RESPONSE_OK == response_id) 281 struct GNUNET_FS_Uri *uri;
282 gchar *keyword;
283 struct GNUNET_CONTAINER_MetaData *meta;
284 guint ntype;
285 gchar *value;
286 GtkTreeIter iter;
287 struct GNUNET_FS_BlockOptions bo;
288 struct GNUNET_CRYPTO_EccPublicKey pk;
289 struct PublishContext *pc;
290
291 if (GTK_RESPONSE_OK != response_id)
292 goto cleanup;
293 ksk_uri = NULL;
294 if (! gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ac->keywords), &iter))
295 {
296 GNUNET_break (0);
297 goto cleanup;
298 }
299 do
300 {
301 gtk_tree_model_get (GTK_TREE_MODEL (ac->keywords), &iter,
302 KEYWORDS_MC_KEYWORD, &keyword,
303 -1);
304 if (NULL == ksk_uri)
305 ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, (const char **) &keyword);
306 else
307 GNUNET_FS_uri_ksk_add_keyword (ksk_uri, keyword, GNUNET_NO);
308 g_free (keyword);
309 }
310 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ac->keywords), &iter));
311
312 meta = GNUNET_CONTAINER_meta_data_create ();
313 if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ac->metadata),
314 &iter))
315 {
316 do
167 { 317 {
168 GNUNET_break (0); // FIXME: not implemented 318 gtk_tree_model_get (GTK_TREE_MODEL (ac->metadata), &iter,
319 METADATA_MC_TYPE_AS_ENUM, &ntype,
320 METADATA_MC_VALUE, &value,
321 -1);
322 if (ntype > 0)
323 {
324 GNUNET_CONTAINER_meta_data_insert (meta, "<user>",
325 ntype,
326 EXTRACTOR_METAFORMAT_UTF8,
327 "text/plain", value,
328 strlen (value) + 1);
329 }
330 g_free (value);
169 } 331 }
332 while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ac->metadata), &iter));
333 }
170 334
335 bo.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS; /* FIXME: allow user to specify */
336 bo.anonymity_level = 1; /* FIXME: allow user to specify */
337 bo.content_priority = 1000; /* FIXME: allow user to specify */
338 bo.replication_level = 5;
339 GNUNET_CRYPTO_ecc_key_get_public (&ac->priv,
340 &pk);
341 uri = GNUNET_FS_uri_sks_create (&pk,
342 "root"); /* FIXME: allow user to specify! */
343
344 pc = GNUNET_new (struct PublishContext);
345 pc->fs = GNUNET_FS_start (GIG_get_configuration (),
346 "gnunet-identity-gtk",
347 &progress_cb, pc,
348 GNUNET_FS_FLAGS_NONE,
349 GNUNET_FS_OPTIONS_END);
350 pc->pub = GNUNET_FS_publish_ksk (pc->fs,
351 ksk_uri,
352 meta,
353 uri,
354 &bo,
355 GNUNET_FS_PUBLISH_OPTION_NONE,
356 &publish_continuation, pc);
357 GNUNET_CONTAINER_DLL_insert (pc_head,
358 pc_tail,
359 pc);
360 GNUNET_FS_uri_destroy (uri);
361 GNUNET_CONTAINER_meta_data_destroy (meta);
362 cleanup:
171 gtk_widget_destroy (ac->dialog); 363 gtk_widget_destroy (ac->dialog);
172 g_object_unref (G_OBJECT (ac->builder)); 364 g_object_unref (G_OBJECT (ac->builder));
173 GNUNET_free (ac); 365 GNUNET_free (ac);
diff --git a/src/identity/gnunet-identity-gtk_advertise.h b/src/identity/gnunet-identity-gtk_advertise.h
index c5230b88..27c9b936 100644
--- a/src/identity/gnunet-identity-gtk_advertise.h
+++ b/src/identity/gnunet-identity-gtk_advertise.h
@@ -29,6 +29,14 @@
29 29
30#include "gnunet_gtk.h" 30#include "gnunet_gtk.h"
31 31
32
33/**
34 * Shutdown advertisement subsystem, this process is terminating.
35 */
36void
37GIG_advertise_shutdown_ ();
38
39
32/** 40/**
33 * Run the dialog for advertising a namespace. 41 * Run the dialog for advertising a namespace.
34 * 42 *