aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-gtk_advertise-pseudonym.c
blob: 388aa22b5de4b352286e2a64fb1ed0b8a899daad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
     This file is part of GNUnet
     (C) 2005-2013 Christian Grothoff (and other contributing authors)

     GNUnet is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published
     by the Free Software Foundation; either version 3, or (at your
     option) any later version.

     GNUnet is distributed in the hope that it will be useful, but
     WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     General Public License for more details.

     You should have received a copy of the GNU General Public License
     along with GNUnet; see the file COPYING.  If not, write to the
     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.
*/

/**
 * @file src/fs/gnunet-fs-gtk_advertise-pseudonym.c
 * @author Christian Grothoff
 * @brief allow the user to select a pseudonym to advertise and
 *        then run the advertising dialog (using the edit-publish 
 *        dialog functions) and finally do the advertising
 */
#include "gnunet-fs-gtk_common.h"
#include "gnunet-fs-gtk.h"
#include "gnunet-fs-gtk_publish-edit-dialog.h"
#include "gnunet-fs-gtk_advertise-pseudonym.h"


/**
 * Columns in the select pseudonym model.
 */
enum FS_SelectPseudonymModelColumns
  {
    /**
     * A gchararray
     */
    FS_SELECT_PSEUDONYM_NAMESPACE_MC_NAME = 0,

    /**
     * A gpointer
     */
    FS_SELECT_PSEUDONYM_NAMESPACE_MC_HANDLE = 1,
  };


/* *************************** handlers run on closing of the dialog ********************** */


/**
 * Closure for 'advertise_namespace' and the callback from the editing dialog.
 */
struct NamespaceAdvertisementContext
{
  /**
   * Handle to the namespace to advertise.
   */
  struct GNUNET_CRYPTO_EccPrivateKey ns;

  /**
   * Root of the namespace is stored here temporarily.
   */
  const char *root;

  /**
   * File information structure (fake) which we use to run the 'edit' dialog.
   */
  struct GNUNET_FS_FileInformation *fip;
};


/**
 * Actually perform the advertising with the information collected.
 *
 * @param cls closure, a 'struct NamespaceAdvertisementContext *'
 * @param fi the entry in the publish-structure
 * @param length length of the file or directory
 * @param meta metadata for the file or directory (can be modified)
 * @param uri pointer to the keywords that will be used for this entry (can be modified)
 * @param bo block options (can be modified)
 * @param do_index should we index (can be modified)
 * @param client_info pointer to client context set upon creation (can be modified)
 * @return GNUNET_OK to continue, GNUNET_NO to remove
 *         this entry from the directory, GNUNET_SYSERR
 *         to abort the iteration
 */
static int
advertise_namespace (void *cls, 
		     struct GNUNET_FS_FileInformation *fi,
                     uint64_t length, struct GNUNET_CONTAINER_MetaData *meta,
                     struct GNUNET_FS_Uri **uri,
                     struct GNUNET_FS_BlockOptions *bo, int *do_index,
                     void **client_info)
{
  struct NamespaceAdvertisementContext *nds = cls;
  struct GNUNET_FS_Uri *sks_uri;
  struct GNUNET_CRYPTO_EccPublicKey pub;

  GNUNET_CRYPTO_ecc_key_get_public (&nds->ns, &pub);
  sks_uri = GNUNET_FS_uri_sks_create (&pub, nds->root);
  GNUNET_FS_publish_ksk (GNUNET_FS_GTK_get_fs_handle (),
			 *uri, meta, sks_uri,
			 bo, GNUNET_FS_PUBLISH_OPTION_NONE, 
			 NULL, NULL);
  GNUNET_FS_uri_destroy (sks_uri);
  return GNUNET_SYSERR;
}


/**
 * Callback invoked from the editing dialog upon completion of the
 * meta data editing for the advertisement.
 *
 * @param cls the 'struct NamespaceAdvertisementContext'
 * @param ret return value from the dialog
 * @param root namespace root to use
 */
static void
adv_pseudonym_edit_publish_dialog_cb (gpointer cls, 
				      gint ret,
                                      const char *root)
{
  struct NamespaceAdvertisementContext *nds = cls;

  if (ret == GTK_RESPONSE_OK)
  {
    nds->root = root;
    GNUNET_FS_file_information_inspect (nds->fip, &advertise_namespace, nds);
    nds->root = NULL;
  }
  GNUNET_FS_file_information_destroy (nds->fip, NULL, NULL);
  GNUNET_free (nds);
}


/**
 * Call the publication editor dialog in namespace advertising mode,
 * and publish the namespace when it's OK'ed.
 *
 * @param ns namespace to advertise
 * @param transient_for parent window for the dialog
 */
void
GNUNET_FS_GTK_advertise_namespace (const struct GNUNET_CRYPTO_EccPrivateKey *ns, 
				   GtkWindow *transient_for)
{
  struct NamespaceAdvertisementContext *nds;
  struct GNUNET_FS_BlockOptions bo;
  struct GNUNET_CONTAINER_MetaData *meta;

  nds = GNUNET_new (struct NamespaceAdvertisementContext);
  nds->ns = *ns;
  memset (&bo, 0, sizeof (struct GNUNET_FS_BlockOptions));
  bo.expiration_time = GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2);
  bo.anonymity_level = 1;
  bo.content_priority = 1000;
  /* create fake file information to run the 'edit' dialog with */
  meta = GNUNET_CONTAINER_meta_data_create ();
  nds->fip =
      GNUNET_FS_file_information_create_empty_directory (NULL, NULL, NULL, meta,
                                                         &bo, NULL);
  GNUNET_CONTAINER_meta_data_destroy (meta);
  GNUNET_FS_GTK_edit_publish_dialog (transient_for,
				     nds->fip,
				     GNUNET_YES,
                                     &adv_pseudonym_edit_publish_dialog_cb,
                                     nds);
}


/* end of gnunet-fs-gtk_advertise-pseudonym.c */