diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/fs/gnunet-publish.c | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/fs/gnunet-publish.c')
-rw-r--r-- | src/fs/gnunet-publish.c | 655 |
1 files changed, 293 insertions, 362 deletions
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index 4ff1ad000..326fed3c6 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c | |||
@@ -44,7 +44,7 @@ static struct GNUNET_FS_Uri *topKeywords; | |||
44 | 44 | ||
45 | static struct GNUNET_FS_Uri *uri; | 45 | static struct GNUNET_FS_Uri *uri; |
46 | 46 | ||
47 | static struct GNUNET_FS_BlockOptions bo = { { 0LL }, 1, 365, 1 }; | 47 | static struct GNUNET_FS_BlockOptions bo = { {0LL}, 1, 365, 1 }; |
48 | 48 | ||
49 | static char *uri_string; | 49 | static char *uri_string; |
50 | 50 | ||
@@ -67,23 +67,22 @@ static int do_disable_creation_time; | |||
67 | static GNUNET_SCHEDULER_TaskIdentifier kill_task; | 67 | static GNUNET_SCHEDULER_TaskIdentifier kill_task; |
68 | 68 | ||
69 | 69 | ||
70 | static void | 70 | static void |
71 | do_stop_task (void *cls, | 71 | do_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
72 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
73 | { | 72 | { |
74 | struct GNUNET_FS_PublishContext *p; | 73 | struct GNUNET_FS_PublishContext *p; |
75 | 74 | ||
76 | if (pc != NULL) | 75 | if (pc != NULL) |
76 | { | ||
77 | p = pc; | ||
78 | pc = NULL; | ||
79 | GNUNET_FS_publish_stop (p); | ||
80 | if (NULL != meta) | ||
77 | { | 81 | { |
78 | p = pc; | 82 | GNUNET_CONTAINER_meta_data_destroy (meta); |
79 | pc = NULL; | 83 | meta = NULL; |
80 | GNUNET_FS_publish_stop (p); | ||
81 | if (NULL != meta) | ||
82 | { | ||
83 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
84 | meta = NULL; | ||
85 | } | ||
86 | } | 84 | } |
85 | } | ||
87 | } | 86 | } |
88 | 87 | ||
89 | 88 | ||
@@ -101,72 +100,66 @@ do_stop_task (void *cls, | |||
101 | * field in the GNUNET_FS_ProgressInfo struct. | 100 | * field in the GNUNET_FS_ProgressInfo struct. |
102 | */ | 101 | */ |
103 | static void * | 102 | static void * |
104 | progress_cb (void *cls, | 103 | progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *info) |
105 | const struct GNUNET_FS_ProgressInfo *info) | ||
106 | { | 104 | { |
107 | char *s; | 105 | char *s; |
108 | 106 | ||
109 | switch (info->status) | 107 | switch (info->status) |
108 | { | ||
109 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
110 | break; | ||
111 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
112 | if (verbose) | ||
110 | { | 113 | { |
111 | case GNUNET_FS_STATUS_PUBLISH_START: | 114 | s = GNUNET_STRINGS_relative_time_to_string (info->value.publish.eta); |
112 | break; | ||
113 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
114 | if (verbose) | ||
115 | { | ||
116 | s = GNUNET_STRINGS_relative_time_to_string(info->value.publish.eta); | ||
117 | fprintf (stdout, | ||
118 | _("Publishing `%s' at %llu/%llu (%s remaining)\n"), | ||
119 | info->value.publish.filename, | ||
120 | (unsigned long long) info->value.publish.completed, | ||
121 | (unsigned long long) info->value.publish.size, | ||
122 | s); | ||
123 | GNUNET_free (s); | ||
124 | } | ||
125 | break; | ||
126 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
127 | fprintf (stderr, | ||
128 | _("Error publishing: %s.\n"), | ||
129 | info->value.publish.specifics.error.message); | ||
130 | if (kill_task != GNUNET_SCHEDULER_NO_TASK) | ||
131 | { | ||
132 | GNUNET_SCHEDULER_cancel (kill_task); | ||
133 | kill_task = GNUNET_SCHEDULER_NO_TASK; | ||
134 | } | ||
135 | GNUNET_SCHEDULER_add_continuation (&do_stop_task, | ||
136 | NULL, | ||
137 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
138 | break; | ||
139 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
140 | fprintf (stdout, | 115 | fprintf (stdout, |
141 | _("Publishing `%s' done.\n"), | 116 | _("Publishing `%s' at %llu/%llu (%s remaining)\n"), |
142 | info->value.publish.filename); | 117 | info->value.publish.filename, |
143 | s = GNUNET_FS_uri_to_string (info->value.publish.specifics.completed.chk_uri); | 118 | (unsigned long long) info->value.publish.completed, |
144 | fprintf (stdout, | 119 | (unsigned long long) info->value.publish.size, s); |
145 | _("URI is `%s'.\n"), | ||
146 | s); | ||
147 | GNUNET_free (s); | 120 | GNUNET_free (s); |
148 | if (info->value.publish.pctx == NULL) | ||
149 | { | ||
150 | if (kill_task != GNUNET_SCHEDULER_NO_TASK) | ||
151 | { | ||
152 | GNUNET_SCHEDULER_cancel (kill_task); | ||
153 | kill_task = GNUNET_SCHEDULER_NO_TASK; | ||
154 | } | ||
155 | GNUNET_SCHEDULER_add_continuation (&do_stop_task, | ||
156 | NULL, | ||
157 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
158 | } | ||
159 | break; | ||
160 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
161 | GNUNET_break (NULL == pc); | ||
162 | return NULL; | ||
163 | default: | ||
164 | fprintf (stderr, | ||
165 | _("Unexpected status: %d\n"), | ||
166 | info->status); | ||
167 | return NULL; | ||
168 | } | 121 | } |
169 | return ""; /* non-null */ | 122 | break; |
123 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
124 | fprintf (stderr, | ||
125 | _("Error publishing: %s.\n"), | ||
126 | info->value.publish.specifics.error.message); | ||
127 | if (kill_task != GNUNET_SCHEDULER_NO_TASK) | ||
128 | { | ||
129 | GNUNET_SCHEDULER_cancel (kill_task); | ||
130 | kill_task = GNUNET_SCHEDULER_NO_TASK; | ||
131 | } | ||
132 | GNUNET_SCHEDULER_add_continuation (&do_stop_task, | ||
133 | NULL, | ||
134 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
135 | break; | ||
136 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
137 | fprintf (stdout, | ||
138 | _("Publishing `%s' done.\n"), info->value.publish.filename); | ||
139 | s = GNUNET_FS_uri_to_string (info->value.publish.specifics. | ||
140 | completed.chk_uri); | ||
141 | fprintf (stdout, _("URI is `%s'.\n"), s); | ||
142 | GNUNET_free (s); | ||
143 | if (info->value.publish.pctx == NULL) | ||
144 | { | ||
145 | if (kill_task != GNUNET_SCHEDULER_NO_TASK) | ||
146 | { | ||
147 | GNUNET_SCHEDULER_cancel (kill_task); | ||
148 | kill_task = GNUNET_SCHEDULER_NO_TASK; | ||
149 | } | ||
150 | GNUNET_SCHEDULER_add_continuation (&do_stop_task, | ||
151 | NULL, | ||
152 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
153 | } | ||
154 | break; | ||
155 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
156 | GNUNET_break (NULL == pc); | ||
157 | return NULL; | ||
158 | default: | ||
159 | fprintf (stderr, _("Unexpected status: %d\n"), info->status); | ||
160 | return NULL; | ||
161 | } | ||
162 | return ""; /* non-null */ | ||
170 | } | 163 | } |
171 | 164 | ||
172 | 165 | ||
@@ -185,22 +178,17 @@ progress_cb (void *cls, | |||
185 | */ | 178 | */ |
186 | static int | 179 | static int |
187 | meta_printer (void *cls, | 180 | meta_printer (void *cls, |
188 | const char *plugin_name, | 181 | const char *plugin_name, |
189 | enum EXTRACTOR_MetaType type, | 182 | enum EXTRACTOR_MetaType type, |
190 | enum EXTRACTOR_MetaFormat format, | 183 | enum EXTRACTOR_MetaFormat format, |
191 | const char *data_mime_type, | 184 | const char *data_mime_type, const char *data, size_t data_size) |
192 | const char *data, | ||
193 | size_t data_size) | ||
194 | { | 185 | { |
195 | if ( (format != EXTRACTOR_METAFORMAT_UTF8) && | 186 | if ((format != EXTRACTOR_METAFORMAT_UTF8) && |
196 | (format != EXTRACTOR_METAFORMAT_C_STRING) ) | 187 | (format != EXTRACTOR_METAFORMAT_C_STRING)) |
197 | return 0; | 188 | return 0; |
198 | if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) | 189 | if (type == EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME) |
199 | return 0; | 190 | return 0; |
200 | fprintf (stdout, | 191 | fprintf (stdout, "\t%s - %s\n", EXTRACTOR_metatype_to_string (type), data); |
201 | "\t%s - %s\n", | ||
202 | EXTRACTOR_metatype_to_string (type), | ||
203 | data); | ||
204 | return 0; | 192 | return 0; |
205 | } | 193 | } |
206 | 194 | ||
@@ -215,13 +203,9 @@ meta_printer (void *cls, | |||
215 | */ | 203 | */ |
216 | 204 | ||
217 | static int | 205 | static int |
218 | keyword_printer (void *cls, | 206 | keyword_printer (void *cls, const char *keyword, int is_mandatory) |
219 | const char *keyword, | ||
220 | int is_mandatory) | ||
221 | { | 207 | { |
222 | fprintf (stdout, | 208 | fprintf (stdout, "\t%s\n", keyword); |
223 | "\t%s\n", | ||
224 | keyword); | ||
225 | return GNUNET_OK; | 209 | return GNUNET_OK; |
226 | } | 210 | } |
227 | 211 | ||
@@ -245,13 +229,12 @@ keyword_printer (void *cls, | |||
245 | */ | 229 | */ |
246 | static int | 230 | static int |
247 | publish_inspector (void *cls, | 231 | publish_inspector (void *cls, |
248 | struct GNUNET_FS_FileInformation *fi, | 232 | struct GNUNET_FS_FileInformation *fi, |
249 | uint64_t length, | 233 | uint64_t length, |
250 | struct GNUNET_CONTAINER_MetaData *m, | 234 | struct GNUNET_CONTAINER_MetaData *m, |
251 | struct GNUNET_FS_Uri **uri, | 235 | struct GNUNET_FS_Uri **uri, |
252 | struct GNUNET_FS_BlockOptions *bo, | 236 | struct GNUNET_FS_BlockOptions *bo, |
253 | int *do_index, | 237 | int *do_index, void **client_info) |
254 | void **client_info) | ||
255 | { | 238 | { |
256 | char *fn; | 239 | char *fn; |
257 | char *fs; | 240 | char *fs; |
@@ -260,73 +243,57 @@ publish_inspector (void *cls, | |||
260 | if (cls == fi) | 243 | if (cls == fi) |
261 | return GNUNET_OK; | 244 | return GNUNET_OK; |
262 | if (NULL != topKeywords) | 245 | if (NULL != topKeywords) |
246 | { | ||
247 | if (*uri != NULL) | ||
263 | { | 248 | { |
264 | if (*uri != NULL) | 249 | new_uri = GNUNET_FS_uri_ksk_merge (topKeywords, *uri); |
265 | { | 250 | GNUNET_FS_uri_destroy (*uri); |
266 | new_uri = GNUNET_FS_uri_ksk_merge (topKeywords, | 251 | *uri = new_uri; |
267 | *uri); | 252 | GNUNET_FS_uri_destroy (topKeywords); |
268 | GNUNET_FS_uri_destroy (*uri); | ||
269 | *uri = new_uri; | ||
270 | GNUNET_FS_uri_destroy (topKeywords); | ||
271 | } | ||
272 | else | ||
273 | { | ||
274 | *uri = topKeywords; | ||
275 | } | ||
276 | topKeywords = NULL; | ||
277 | } | 253 | } |
278 | if (NULL != meta) | 254 | else |
279 | { | 255 | { |
280 | GNUNET_CONTAINER_meta_data_merge (m, meta); | 256 | *uri = topKeywords; |
281 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
282 | meta = NULL; | ||
283 | } | 257 | } |
284 | if (! do_disable_creation_time) | 258 | topKeywords = NULL; |
259 | } | ||
260 | if (NULL != meta) | ||
261 | { | ||
262 | GNUNET_CONTAINER_meta_data_merge (m, meta); | ||
263 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
264 | meta = NULL; | ||
265 | } | ||
266 | if (!do_disable_creation_time) | ||
285 | GNUNET_CONTAINER_meta_data_add_publication_date (m); | 267 | GNUNET_CONTAINER_meta_data_add_publication_date (m); |
286 | if (extract_only) | 268 | if (extract_only) |
287 | { | 269 | { |
288 | fn = GNUNET_CONTAINER_meta_data_get_by_type (m, | 270 | fn = GNUNET_CONTAINER_meta_data_get_by_type (m, |
289 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); | 271 | EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); |
290 | fs = GNUNET_STRINGS_byte_size_fancy (length); | 272 | fs = GNUNET_STRINGS_byte_size_fancy (length); |
291 | fprintf (stdout, | 273 | fprintf (stdout, _("Meta data for file `%s' (%s)\n"), fn, fs); |
292 | _("Meta data for file `%s' (%s)\n"), | 274 | GNUNET_CONTAINER_meta_data_iterate (m, &meta_printer, NULL); |
293 | fn, | 275 | fprintf (stdout, _("Keywords for file `%s' (%s)\n"), fn, fs); |
294 | fs); | 276 | GNUNET_free (fn); |
295 | GNUNET_CONTAINER_meta_data_iterate (m, | 277 | GNUNET_free (fs); |
296 | &meta_printer, | 278 | if (NULL != *uri) |
297 | NULL); | 279 | GNUNET_FS_uri_ksk_get_keywords (*uri, &keyword_printer, NULL); |
298 | fprintf (stdout, | 280 | fprintf (stdout, "\n"); |
299 | _("Keywords for file `%s' (%s)\n"), | 281 | } |
300 | fn, | ||
301 | fs); | ||
302 | GNUNET_free (fn); | ||
303 | GNUNET_free (fs); | ||
304 | if (NULL != *uri) | ||
305 | GNUNET_FS_uri_ksk_get_keywords (*uri, | ||
306 | &keyword_printer, | ||
307 | NULL); | ||
308 | fprintf (stdout, "\n"); | ||
309 | } | ||
310 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m)) | 282 | if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (m)) |
311 | GNUNET_FS_file_information_inspect (fi, | 283 | GNUNET_FS_file_information_inspect (fi, &publish_inspector, fi); |
312 | &publish_inspector, | ||
313 | fi); | ||
314 | return GNUNET_OK; | 284 | return GNUNET_OK; |
315 | } | 285 | } |
316 | 286 | ||
317 | 287 | ||
318 | static void | 288 | static void |
319 | uri_sks_continuation (void *cls, | 289 | uri_sks_continuation (void *cls, |
320 | const struct GNUNET_FS_Uri *ksk_uri, | 290 | const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) |
321 | const char *emsg) | ||
322 | { | 291 | { |
323 | if (emsg != NULL) | 292 | if (emsg != NULL) |
324 | { | 293 | { |
325 | fprintf (stderr, | 294 | fprintf (stderr, "%s\n", emsg); |
326 | "%s\n", | 295 | ret = 1; |
327 | emsg); | 296 | } |
328 | ret = 1; | ||
329 | } | ||
330 | GNUNET_FS_uri_destroy (uri); | 297 | GNUNET_FS_uri_destroy (uri); |
331 | uri = NULL; | 298 | uri = NULL; |
332 | GNUNET_FS_stop (ctx); | 299 | GNUNET_FS_stop (ctx); |
@@ -334,48 +301,40 @@ uri_sks_continuation (void *cls, | |||
334 | } | 301 | } |
335 | 302 | ||
336 | 303 | ||
337 | static void | 304 | static void |
338 | uri_ksk_continuation (void *cls, | 305 | uri_ksk_continuation (void *cls, |
339 | const struct GNUNET_FS_Uri *ksk_uri, | 306 | const struct GNUNET_FS_Uri *ksk_uri, const char *emsg) |
340 | const char *emsg) | ||
341 | { | 307 | { |
342 | struct GNUNET_FS_Namespace *ns; | 308 | struct GNUNET_FS_Namespace *ns; |
343 | 309 | ||
344 | if (emsg != NULL) | 310 | if (emsg != NULL) |
311 | { | ||
312 | fprintf (stderr, "%s\n", emsg); | ||
313 | ret = 1; | ||
314 | } | ||
315 | if (pseudonym != NULL) | ||
316 | { | ||
317 | ns = GNUNET_FS_namespace_create (ctx, pseudonym); | ||
318 | if (ns == NULL) | ||
345 | { | 319 | { |
346 | fprintf (stderr, | 320 | fprintf (stderr, _("Failed to create namespace `%s'\n"), pseudonym); |
347 | "%s\n", | ||
348 | emsg); | ||
349 | ret = 1; | 321 | ret = 1; |
350 | } | 322 | } |
351 | if (pseudonym != NULL) | 323 | else |
352 | { | 324 | { |
353 | ns = GNUNET_FS_namespace_create (ctx, | 325 | GNUNET_FS_publish_sks (ctx, |
354 | pseudonym); | 326 | ns, |
355 | if (ns == NULL) | 327 | this_id, |
356 | { | 328 | next_id, |
357 | fprintf (stderr, | 329 | meta, |
358 | _("Failed to create namespace `%s'\n"), | 330 | uri, |
359 | pseudonym); | 331 | &bo, |
360 | ret = 1; | 332 | GNUNET_FS_PUBLISH_OPTION_NONE, |
361 | } | 333 | uri_sks_continuation, NULL); |
362 | else | 334 | GNUNET_assert (GNUNET_OK == GNUNET_FS_namespace_delete (ns, GNUNET_NO)); |
363 | { | 335 | return; |
364 | GNUNET_FS_publish_sks (ctx, | ||
365 | ns, | ||
366 | this_id, | ||
367 | next_id, | ||
368 | meta, | ||
369 | uri, | ||
370 | &bo, | ||
371 | GNUNET_FS_PUBLISH_OPTION_NONE, | ||
372 | uri_sks_continuation, | ||
373 | NULL); | ||
374 | GNUNET_assert (GNUNET_OK == | ||
375 | GNUNET_FS_namespace_delete (ns, GNUNET_NO)); | ||
376 | return; | ||
377 | } | ||
378 | } | 336 | } |
337 | } | ||
379 | GNUNET_FS_uri_destroy (uri); | 338 | GNUNET_FS_uri_destroy (uri); |
380 | uri = NULL; | 339 | uri = NULL; |
381 | GNUNET_FS_stop (ctx); | 340 | GNUNET_FS_stop (ctx); |
@@ -394,8 +353,7 @@ uri_ksk_continuation (void *cls, | |||
394 | static void | 353 | static void |
395 | run (void *cls, | 354 | run (void *cls, |
396 | char *const *args, | 355 | char *const *args, |
397 | const char *cfgfile, | 356 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
398 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
399 | { | 357 | { |
400 | struct GNUNET_FS_FileInformation *fi; | 358 | struct GNUNET_FS_FileInformation *fi; |
401 | struct GNUNET_FS_Namespace *namespace; | 359 | struct GNUNET_FS_Namespace *namespace; |
@@ -404,212 +362,187 @@ run (void *cls, | |||
404 | struct stat sbuf; | 362 | struct stat sbuf; |
405 | char *ex; | 363 | char *ex; |
406 | char *emsg; | 364 | char *emsg; |
407 | 365 | ||
408 | /* check arguments */ | 366 | /* check arguments */ |
409 | if ((uri_string != NULL) && (extract_only)) | 367 | if ((uri_string != NULL) && (extract_only)) |
368 | { | ||
369 | printf (_("Cannot extract metadata from a URI!\n")); | ||
370 | ret = -1; | ||
371 | return; | ||
372 | } | ||
373 | if (((uri_string == NULL) || (extract_only)) | ||
374 | && ((args[0] == NULL) || (args[1] != NULL))) | ||
375 | { | ||
376 | printf (_("You must specify one and only one filename for insertion.\n")); | ||
377 | ret = -1; | ||
378 | return; | ||
379 | } | ||
380 | if ((uri_string != NULL) && (args[0] != NULL)) | ||
381 | { | ||
382 | printf (_("You must NOT specify an URI and a filename.\n")); | ||
383 | ret = -1; | ||
384 | return; | ||
385 | } | ||
386 | if (pseudonym != NULL) | ||
387 | { | ||
388 | if (NULL == this_id) | ||
410 | { | 389 | { |
411 | printf (_("Cannot extract metadata from a URI!\n")); | 390 | fprintf (stderr, |
391 | _("Option `%s' is required when using option `%s'.\n"), | ||
392 | "-t", "-P"); | ||
412 | ret = -1; | 393 | ret = -1; |
413 | return; | 394 | return; |
414 | } | 395 | } |
415 | if ( ( (uri_string == NULL) || (extract_only) ) | 396 | } |
416 | && ( (args[0] == NULL) || (args[1] != NULL) ) ) | 397 | else |
398 | { /* ordinary insertion checks */ | ||
399 | if (NULL != next_id) | ||
417 | { | 400 | { |
418 | printf (_ | 401 | fprintf (stderr, |
419 | ("You must specify one and only one filename for insertion.\n")); | 402 | _("Option `%s' makes no sense without option `%s'.\n"), |
403 | "-N", "-P"); | ||
420 | ret = -1; | 404 | ret = -1; |
421 | return; | 405 | return; |
422 | } | 406 | } |
423 | if ((uri_string != NULL) && (args[0] != NULL)) | 407 | if (NULL != this_id) |
424 | { | 408 | { |
425 | printf (_("You must NOT specify an URI and a filename.\n")); | 409 | fprintf (stderr, |
410 | _("Option `%s' makes no sense without option `%s'.\n"), | ||
411 | "-t", "-P"); | ||
426 | ret = -1; | 412 | ret = -1; |
427 | return; | 413 | return; |
428 | } | 414 | } |
429 | if (pseudonym != NULL) | 415 | } |
430 | { | ||
431 | if (NULL == this_id) | ||
432 | { | ||
433 | fprintf (stderr, | ||
434 | _("Option `%s' is required when using option `%s'.\n"), | ||
435 | "-t", "-P"); | ||
436 | ret = -1; | ||
437 | return; | ||
438 | } | ||
439 | } | ||
440 | else | ||
441 | { /* ordinary insertion checks */ | ||
442 | if (NULL != next_id) | ||
443 | { | ||
444 | fprintf (stderr, | ||
445 | _("Option `%s' makes no sense without option `%s'.\n"), | ||
446 | "-N", "-P"); | ||
447 | ret = -1; | ||
448 | return; | ||
449 | } | ||
450 | if (NULL != this_id) | ||
451 | { | ||
452 | fprintf (stderr, | ||
453 | _("Option `%s' makes no sense without option `%s'.\n"), | ||
454 | "-t", "-P"); | ||
455 | ret = -1; | ||
456 | return; | ||
457 | } | ||
458 | } | ||
459 | cfg = c; | 416 | cfg = c; |
460 | ctx = GNUNET_FS_start (cfg, | 417 | ctx = GNUNET_FS_start (cfg, |
461 | "gnunet-publish", | 418 | "gnunet-publish", |
462 | &progress_cb, | 419 | &progress_cb, |
463 | NULL, | 420 | NULL, GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); |
464 | GNUNET_FS_FLAGS_NONE, | ||
465 | GNUNET_FS_OPTIONS_END); | ||
466 | if (NULL == ctx) | 421 | if (NULL == ctx) |
467 | { | 422 | { |
468 | fprintf (stderr, | 423 | fprintf (stderr, _("Could not initialize `%s' subsystem.\n"), "FS"); |
469 | _("Could not initialize `%s' subsystem.\n"), | 424 | ret = 1; |
470 | "FS"); | 425 | return; |
471 | ret = 1; | 426 | } |
472 | return; | ||
473 | } | ||
474 | namespace = NULL; | 427 | namespace = NULL; |
475 | if (NULL != pseudonym) | 428 | if (NULL != pseudonym) |
429 | { | ||
430 | namespace = GNUNET_FS_namespace_create (ctx, pseudonym); | ||
431 | if (NULL == namespace) | ||
476 | { | 432 | { |
477 | namespace = GNUNET_FS_namespace_create (ctx, | 433 | fprintf (stderr, _("Could not create namespace `%s'\n"), pseudonym); |
478 | pseudonym); | 434 | GNUNET_FS_stop (ctx); |
479 | if (NULL == namespace) | 435 | ret = 1; |
480 | { | 436 | return; |
481 | fprintf (stderr, | ||
482 | _("Could not create namespace `%s'\n"), | ||
483 | pseudonym); | ||
484 | GNUNET_FS_stop (ctx); | ||
485 | ret = 1; | ||
486 | return; | ||
487 | } | ||
488 | } | 437 | } |
438 | } | ||
489 | if (NULL != uri_string) | 439 | if (NULL != uri_string) |
490 | { | 440 | { |
491 | emsg = NULL; | 441 | emsg = NULL; |
492 | uri = GNUNET_FS_uri_parse (uri_string, | 442 | uri = GNUNET_FS_uri_parse (uri_string, &emsg); |
493 | &emsg); | 443 | if (uri == NULL) |
494 | if (uri == NULL) | 444 | { |
495 | { | 445 | fprintf (stderr, _("Failed to parse URI: %s\n"), emsg); |
496 | fprintf (stderr, | 446 | GNUNET_free (emsg); |
497 | _("Failed to parse URI: %s\n"), | ||
498 | emsg); | ||
499 | GNUNET_free (emsg); | ||
500 | if (namespace != NULL) | ||
501 | GNUNET_FS_namespace_delete (namespace, GNUNET_NO); | ||
502 | GNUNET_FS_stop (ctx); | ||
503 | ret = 1; | ||
504 | return; | ||
505 | } | ||
506 | GNUNET_FS_publish_ksk (ctx, | ||
507 | topKeywords, | ||
508 | meta, | ||
509 | uri, | ||
510 | &bo, | ||
511 | GNUNET_FS_PUBLISH_OPTION_NONE, | ||
512 | &uri_ksk_continuation, | ||
513 | NULL); | ||
514 | if (namespace != NULL) | 447 | if (namespace != NULL) |
515 | GNUNET_FS_namespace_delete (namespace, GNUNET_NO); | 448 | GNUNET_FS_namespace_delete (namespace, GNUNET_NO); |
449 | GNUNET_FS_stop (ctx); | ||
450 | ret = 1; | ||
516 | return; | 451 | return; |
517 | } | 452 | } |
453 | GNUNET_FS_publish_ksk (ctx, | ||
454 | topKeywords, | ||
455 | meta, | ||
456 | uri, | ||
457 | &bo, | ||
458 | GNUNET_FS_PUBLISH_OPTION_NONE, | ||
459 | &uri_ksk_continuation, NULL); | ||
460 | if (namespace != NULL) | ||
461 | GNUNET_FS_namespace_delete (namespace, GNUNET_NO); | ||
462 | return; | ||
463 | } | ||
518 | plugins = NULL; | 464 | plugins = NULL; |
519 | if (! disable_extractor) | 465 | if (!disable_extractor) |
466 | { | ||
467 | plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); | ||
468 | if (GNUNET_OK == | ||
469 | GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", &ex)) | ||
520 | { | 470 | { |
521 | plugins = EXTRACTOR_plugin_add_defaults (EXTRACTOR_OPTION_DEFAULT_POLICY); | 471 | if (strlen (ex) > 0) |
522 | if (GNUNET_OK == | 472 | plugins = |
523 | GNUNET_CONFIGURATION_get_value_string (cfg, "FS", "EXTRACTORS", | 473 | EXTRACTOR_plugin_add_config (plugins, ex, |
524 | &ex)) | 474 | EXTRACTOR_OPTION_DEFAULT_POLICY); |
525 | { | 475 | GNUNET_free (ex); |
526 | if (strlen (ex) > 0) | ||
527 | plugins = EXTRACTOR_plugin_add_config (plugins, ex, EXTRACTOR_OPTION_DEFAULT_POLICY); | ||
528 | GNUNET_free (ex); | ||
529 | } | ||
530 | } | 476 | } |
477 | } | ||
531 | emsg = NULL; | 478 | emsg = NULL; |
532 | GNUNET_assert (NULL != args[0]); | 479 | GNUNET_assert (NULL != args[0]); |
533 | if (0 != STAT (args[0], &sbuf)) | 480 | if (0 != STAT (args[0], &sbuf)) |
534 | { | 481 | { |
535 | GNUNET_asprintf (&emsg, | 482 | GNUNET_asprintf (&emsg, _("Could not access file: %s\n"), STRERROR (errno)); |
536 | _("Could not access file: %s\n"), | 483 | fi = NULL; |
537 | STRERROR (errno)); | 484 | } |
538 | fi = NULL; | ||
539 | } | ||
540 | else if (S_ISDIR (sbuf.st_mode)) | 485 | else if (S_ISDIR (sbuf.st_mode)) |
541 | { | 486 | { |
542 | fi = GNUNET_FS_file_information_create_from_directory (ctx, | 487 | fi = GNUNET_FS_file_information_create_from_directory (ctx, |
543 | NULL, | 488 | NULL, |
544 | args[0], | 489 | args[0], |
545 | &GNUNET_FS_directory_scanner_default, | 490 | &GNUNET_FS_directory_scanner_default, |
546 | plugins, | 491 | plugins, |
547 | !do_insert, | 492 | !do_insert, |
548 | &bo, | 493 | &bo, &emsg); |
549 | &emsg); | 494 | } |
550 | } | ||
551 | else | 495 | else |
552 | { | 496 | { |
553 | if (meta == NULL) | 497 | if (meta == NULL) |
554 | meta = GNUNET_CONTAINER_meta_data_create (); | 498 | meta = GNUNET_CONTAINER_meta_data_create (); |
555 | GNUNET_FS_meta_data_extract_from_file (meta, | 499 | GNUNET_FS_meta_data_extract_from_file (meta, args[0], plugins); |
556 | args[0], | 500 | keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta); |
557 | plugins); | 501 | fi = GNUNET_FS_file_information_create_from_file (ctx, |
558 | keywords = GNUNET_FS_uri_ksk_create_from_meta_data (meta); | 502 | NULL, |
559 | fi = GNUNET_FS_file_information_create_from_file (ctx, | 503 | args[0], |
560 | NULL, | 504 | keywords, |
561 | args[0], | 505 | NULL, !do_insert, &bo); |
562 | keywords, | 506 | GNUNET_break (fi != NULL); |
563 | NULL, | 507 | GNUNET_FS_uri_destroy (keywords); |
564 | !do_insert, | 508 | } |
565 | &bo); | 509 | EXTRACTOR_plugin_remove_all (plugins); |
566 | GNUNET_break (fi != NULL); | ||
567 | GNUNET_FS_uri_destroy (keywords); | ||
568 | } | ||
569 | EXTRACTOR_plugin_remove_all (plugins); | ||
570 | if (fi == NULL) | 510 | if (fi == NULL) |
571 | { | 511 | { |
572 | fprintf (stderr, | 512 | fprintf (stderr, _("Could not publish `%s': %s\n"), args[0], emsg); |
573 | _("Could not publish `%s': %s\n"), | 513 | GNUNET_free (emsg); |
574 | args[0], | 514 | if (namespace != NULL) |
575 | emsg); | 515 | GNUNET_FS_namespace_delete (namespace, GNUNET_NO); |
576 | GNUNET_free (emsg); | 516 | GNUNET_FS_stop (ctx); |
577 | if (namespace != NULL) | 517 | ret = 1; |
578 | GNUNET_FS_namespace_delete (namespace, GNUNET_NO); | 518 | return; |
579 | GNUNET_FS_stop (ctx); | 519 | } |
580 | ret = 1; | 520 | GNUNET_FS_file_information_inspect (fi, &publish_inspector, NULL); |
581 | return; | ||
582 | } | ||
583 | GNUNET_FS_file_information_inspect (fi, | ||
584 | &publish_inspector, | ||
585 | NULL); | ||
586 | if (extract_only) | 521 | if (extract_only) |
587 | { | 522 | { |
588 | if (namespace != NULL) | 523 | if (namespace != NULL) |
589 | GNUNET_FS_namespace_delete (namespace, GNUNET_NO); | 524 | GNUNET_FS_namespace_delete (namespace, GNUNET_NO); |
590 | GNUNET_FS_file_information_destroy (fi, NULL, NULL); | 525 | GNUNET_FS_file_information_destroy (fi, NULL, NULL); |
591 | GNUNET_FS_stop (ctx); | 526 | GNUNET_FS_stop (ctx); |
592 | return; | 527 | return; |
593 | } | 528 | } |
594 | pc = GNUNET_FS_publish_start (ctx, | 529 | pc = GNUNET_FS_publish_start (ctx, |
595 | fi, | 530 | fi, |
596 | namespace, | 531 | namespace, |
597 | this_id, | 532 | this_id, |
598 | next_id, | 533 | next_id, |
599 | (do_simulate) | 534 | (do_simulate) |
600 | ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY | 535 | ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY |
601 | : GNUNET_FS_PUBLISH_OPTION_NONE); | 536 | : GNUNET_FS_PUBLISH_OPTION_NONE); |
602 | if (NULL == pc) | 537 | if (NULL == pc) |
603 | { | 538 | { |
604 | fprintf (stderr, | 539 | fprintf (stderr, _("Could not start publishing.\n")); |
605 | _("Could not start publishing.\n")); | 540 | GNUNET_FS_stop (ctx); |
606 | GNUNET_FS_stop (ctx); | 541 | ret = 1; |
607 | ret = 1; | 542 | return; |
608 | return; | 543 | } |
609 | } | ||
610 | kill_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 544 | kill_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
611 | &do_stop_task, | 545 | &do_stop_task, NULL); |
612 | NULL); | ||
613 | } | 546 | } |
614 | 547 | ||
615 | 548 | ||
@@ -634,8 +567,7 @@ main (int argc, char *const *argv) | |||
634 | ("disable adding the creation time to the metadata of the uploaded file"), | 567 | ("disable adding the creation time to the metadata of the uploaded file"), |
635 | 0, &GNUNET_GETOPT_set_one, &do_disable_creation_time}, | 568 | 0, &GNUNET_GETOPT_set_one, &do_disable_creation_time}, |
636 | {'D', "disable-extractor", NULL, | 569 | {'D', "disable-extractor", NULL, |
637 | gettext_noop | 570 | gettext_noop ("do not use libextractor to add keywords or metadata"), |
638 | ("do not use libextractor to add keywords or metadata"), | ||
639 | 0, &GNUNET_GETOPT_set_one, &disable_extractor}, | 571 | 0, &GNUNET_GETOPT_set_one, &disable_extractor}, |
640 | {'e', "extract", NULL, | 572 | {'e', "extract", NULL, |
641 | gettext_noop | 573 | gettext_noop |
@@ -651,7 +583,7 @@ main (int argc, char *const *argv) | |||
651 | 1, &GNUNET_FS_getopt_set_metadata, &meta}, | 583 | 1, &GNUNET_FS_getopt_set_metadata, &meta}, |
652 | {'n', "noindex", NULL, | 584 | {'n', "noindex", NULL, |
653 | gettext_noop ("do not index, perform full insertion (stores entire " | 585 | gettext_noop ("do not index, perform full insertion (stores entire " |
654 | "file in encrypted form in GNUnet database)"), | 586 | "file in encrypted form in GNUnet database)"), |
655 | 0, &GNUNET_GETOPT_set_one, &do_insert}, | 587 | 0, &GNUNET_GETOPT_set_one, &do_insert}, |
656 | {'N', "next", "ID", | 588 | {'N', "next", "ID", |
657 | gettext_noop | 589 | gettext_noop |
@@ -670,26 +602,25 @@ main (int argc, char *const *argv) | |||
670 | 1, &GNUNET_GETOPT_set_uint, &bo.replication_level}, | 602 | 1, &GNUNET_GETOPT_set_uint, &bo.replication_level}, |
671 | {'s', "simulate-only", NULL, | 603 | {'s', "simulate-only", NULL, |
672 | gettext_noop ("only simulate the process but do not do any " | 604 | gettext_noop ("only simulate the process but do not do any " |
673 | "actual publishing (useful to compute URIs)"), | 605 | "actual publishing (useful to compute URIs)"), |
674 | 0, &GNUNET_GETOPT_set_one, &do_simulate}, | 606 | 0, &GNUNET_GETOPT_set_one, &do_simulate}, |
675 | {'t', "this", "ID", | 607 | {'t', "this", "ID", |
676 | gettext_noop ("set the ID of this version of the publication" | 608 | gettext_noop ("set the ID of this version of the publication" |
677 | " (for namespace insertions only)"), | 609 | " (for namespace insertions only)"), |
678 | 1, &GNUNET_GETOPT_set_string, &this_id}, | 610 | 1, &GNUNET_GETOPT_set_string, &this_id}, |
679 | {'u', "uri", "URI", | 611 | {'u', "uri", "URI", |
680 | gettext_noop ("URI to be published (can be used instead of passing a " | 612 | gettext_noop ("URI to be published (can be used instead of passing a " |
681 | "file to add keywords to the file with the respective URI)"), | 613 | "file to add keywords to the file with the respective URI)"), |
682 | 1, &GNUNET_GETOPT_set_string, &uri_string}, | 614 | 1, &GNUNET_GETOPT_set_string, &uri_string}, |
683 | {'V', "verbose", NULL, | 615 | {'V', "verbose", NULL, |
684 | gettext_noop ("be verbose (print progress information)"), | 616 | gettext_noop ("be verbose (print progress information)"), |
685 | 0, &GNUNET_GETOPT_set_one, &verbose}, | 617 | 0, &GNUNET_GETOPT_set_one, &verbose}, |
686 | GNUNET_GETOPT_OPTION_END | 618 | GNUNET_GETOPT_OPTION_END |
687 | }; | 619 | }; |
688 | bo.expiration_time = GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2); | 620 | bo.expiration_time = |
621 | GNUNET_FS_year_to_time (GNUNET_FS_get_current_year () + 2); | ||
689 | return (GNUNET_OK == | 622 | return (GNUNET_OK == |
690 | GNUNET_PROGRAM_run (argc, | 623 | GNUNET_PROGRAM_run (argc, argv, "gnunet-publish [OPTIONS] FILENAME", |
691 | argv, | ||
692 | "gnunet-publish [OPTIONS] FILENAME", | ||
693 | gettext_noop | 624 | gettext_noop |
694 | ("Publish a file or directory on GNUnet"), | 625 | ("Publish a file or directory on GNUnet"), |
695 | options, &run, NULL)) ? ret : 1; | 626 | options, &run, NULL)) ? ret : 1; |