GNUnet 0.22.0
gnunet-search.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009, 2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
29#include "platform.h"
30#include <ctype.h>
31#include <inttypes.h>
32#include <limits.h>
33
34#include "gnunet_fs_service.h"
35
36
37#define GNUNET_SEARCH_log(kind, ...) \
38 GNUNET_log_from (kind, "gnunet-search", __VA_ARGS__)
39
40
41/* The default settings that we use for the printed output */
42
43#define DEFAULT_DIR_FORMAT "#%n:\ngnunet-download -o \"%f\" -R %u\n\n"
44#define HELP_DEFAULT_DIR_FORMAT "#%n:\\ngnunet-download -o \"%f\" -R %u\\n\\n"
45#define DEFAULT_FILE_FORMAT "#%n:\ngnunet-download -o \"%f\" %u\n\n"
46#define HELP_DEFAULT_FILE_FORMAT "#%n:\\ngnunet-download -o \"%f\" %u\\n\\n"
47#define VERB_DEFAULT_DIR_FORMAT DEFAULT_DIR_FORMAT "%a\n"
48#define VERB_DEFAULT_FILE_FORMAT DEFAULT_FILE_FORMAT "%a\n"
49
50#if HAVE_LIBEXTRACTOR
51#define DEFAULT_META_FORMAT " %t: %p\n"
52#define HELP_DEFAULT_META_FORMAT " %t: %p\\n"
53#define HELP_EXTRACTOR_TEXTADD ", %t"
54#else
55#define DEFAULT_META_FORMAT " MetaType #%i: %p\n"
56#define HELP_DEFAULT_META_FORMAT " MetaType #%i: %p\\n"
57#define HELP_EXTRACTOR_TEXTADD ""
58#endif
59
60#define GENERIC_DIRECTORY_NAME "collection"
61#define GENERIC_FILE_NAME "no-name"
62#define GENERIC_FILE_MIMETYPE "application/octet-stream"
63
64
66{
70};
71
72
74{
75 unsigned int counter;
76 unsigned int flags;
77 int type;
78};
79
80
81static int ret;
82
83static const struct GNUNET_CONFIGURATION_Handle *cfg;
84
85static struct GNUNET_FS_Handle *ctx;
86
88
89static char *output_filename;
90
91static char *format_string;
92
93static char *dir_format_string;
94
95static char *meta_format_string;
96
98
99static unsigned int anonymity = 1;
100
105
106static unsigned int results_limit;
107
108static unsigned int results;
109
110static unsigned int verbose;
111
112static int bookmark_only;
113
114static int local_only;
115
116static int silent_mode;
117
119
120static int stop_searching;
121
122
134static const char *
135print_escape_sequence (const char *const esc)
136{
137 unsigned int probe;
138 const char *cursor = esc + 1;
139 char tmp;
140 switch (*cursor)
141 {
142 /* Trivia */
143 case '\\': putchar ('\\'); return cursor + 1;
144 case 'a': putchar ('\a'); return cursor + 1;
145 case 'b': putchar ('\b'); return cursor + 1;
146 case 'e': putchar ('\x1B'); return cursor + 1;
147 case 'f': putchar ('\f'); return cursor + 1;
148 case 'n': putchar ('\n'); return cursor + 1;
149 case 'r': putchar ('\r'); return cursor + 1;
150 case 't': putchar ('\t'); return cursor + 1;
151 case 'v': putchar ('\v'); return cursor + 1;
152
153 /* Possibly hexadecimal code point */
154 case 'x':
155 probe = 0;
156 while (probe < 256 && isxdigit ((tmp = *++cursor)))
157 probe = (probe << 4) + tmp - (tmp > 96 ? 87 : tmp > 64 ? 55 : 48);
158 goto maybe_codepoint;
159
160 /* Possibly octal code point */
161 case '0': case '1': case '2': case '3':
162 case '4': case '5': case '6': case '7':
163 probe = *cursor++ - 48;
164 do probe = (probe << 3) + *cursor++ - 48;
165 while (probe < 256 && cursor < esc + 4 && *cursor > 47 && *cursor < 56);
166 goto maybe_codepoint;
167
168 /* Boredom */
169 case '\0': putchar ('\\'); return cursor;
170 default: printf ("\\%c", *cursor); return cursor + 1;
171 }
172
173 maybe_codepoint:
174 if (probe < 256)
175 putchar (probe);
176 else
177 fwrite (esc, 1, cursor - esc, stdout);
178 return cursor;
179}
180
181
199static int
200item_printer (void *const cls,
201 const char *const plugin_name,
202 const enum EXTRACTOR_MetaType type,
203 const enum EXTRACTOR_MetaFormat format,
204 const char *const data_mime_type,
205 const char *const data,
206 const size_t data_size)
207{
208 const char *cursor;
209 const char *next_spec;
210 const char *next_esc;
211#define info ((struct GNUNET_SEARCH_MetadataPrinterInfo *) cls)
212 if ((format != EXTRACTOR_METAFORMAT_UTF8 &&
213 format != EXTRACTOR_METAFORMAT_C_STRING) ||
215 return 0;
216 info->counter++;
217 if ((info->flags & METADATA_PRINTER_FLAG_HAVE_TYPE) && type != info->type)
218 return 0;
219
220 cursor = meta_format_string;
221 next_spec = strchr (cursor, '%');
222 next_esc = strchr (cursor, '\\');
223
224 parse_format:
225
226 /* If an escape sequence exists before the next format specifier... */
227 if (next_esc && (! next_spec || next_esc < next_spec))
228 {
229 if (next_esc > cursor)
230 fwrite (cursor, 1, next_esc - cursor, stdout);
231
232 cursor = print_escape_sequence (next_esc);
233 next_esc = strchr (cursor, '\\');
234 goto parse_format;
235 }
236
237 /* If a format specifier exists before the next escape sequence... */
238 if (next_spec && (! next_esc || next_spec < next_esc))
239 {
240 if (next_spec > cursor)
241 fwrite (cursor, 1, next_spec - cursor, stdout);
242
243 switch (*++next_spec)
244 {
245 case '%': putchar ('%'); break;
246 case 'i': printf ("%d", type); break;
247 case 'l': printf ("%lu", (long unsigned int) data_size); break;
248 case 'n': printf ("%u", info->counter); break;
249 case 'p': printf ("%s", data); break;
250#if HAVE_LIBEXTRACTOR
251 case 't':
252 printf ("%s",
254 EXTRACTOR_metatype_to_string (type)));
255 break;
256#endif
257 case 'w': printf ("%s", plugin_name); break;
258 case '\0': putchar ('%'); return 0;
259 default: printf ("%%%c", *next_spec); break;
260 }
261 cursor = next_spec + 1;
262 next_spec = strchr (cursor, '%');
263 goto parse_format;
264 }
265
266 if (*cursor)
267 printf ("%s", cursor);
268
269 return info->flags & METADATA_PRINTER_FLAG_ONE_RUN;
270#undef info
271}
272
273
285static void
286print_search_result (const char *const filename,
287 const struct GNUNET_FS_Uri *const uri,
288 const struct GNUNET_FS_MetaData *const metadata,
289 const unsigned int resultnum,
290 const int is_directory)
291{
292
293 const char *cursor = GNUNET_YES == is_directory ?
296
297 const char *next_spec = strchr (cursor, '%');
298 const char *next_esc = strchr (cursor, '\\');
299 char *placeholder;
301
302 parse_format:
303 /* If an escape sequence exists before the next format specifier... */
304 if (next_esc && (! next_spec || next_esc < next_spec))
305 {
306 if (next_esc > cursor)
307 fwrite (cursor, 1, next_esc - cursor, stdout);
308
309 cursor = print_escape_sequence (next_esc);
310 next_esc = strchr (cursor, '\\');
311 goto parse_format;
312 }
313
314 /* If a format specifier exists before the next escape sequence... */
315 if (next_spec && (! next_esc || next_spec < next_esc))
316 {
317 if (next_spec > cursor)
318 fwrite (cursor, 1, next_spec - cursor, stdout);
319
320 switch (*++next_spec)
321 {
322 /* All metadata fields */
323 case 'a':
325
326 iterate_meta:
327 info.counter = 0;
329 break;
330 /* File's name */
331 case 'f':
332 if (GNUNET_YES == is_directory)
333 {
334 printf ("%s%s", filename, GNUNET_FS_DIRECTORY_EXT);
335 break;
336 }
337 printf ("%s", filename);
338 break;
339 /* Only the first metadata field */
340 case 'j':
342 goto iterate_meta;
343 /* File name's length */
344 case 'l':
345 printf ("%lu",
346 (long unsigned int) (GNUNET_YES == is_directory ?
347 strlen (filename)
348 + (sizeof(GNUNET_FS_DIRECTORY_EXT) - 1)
349 :
350 strlen (filename)));
351 break;
352 /* File's mime type */
353 case 'm':
354 if (GNUNET_YES == is_directory)
355 {
356 printf ("%s", GNUNET_FS_DIRECTORY_MIME);
357 break;
358 }
359 placeholder = GNUNET_FS_meta_data_get_by_type (
360 metadata,
361 EXTRACTOR_METATYPE_MIMETYPE);
362 printf ("%s", placeholder ? placeholder : GENERIC_FILE_MIMETYPE);
363 GNUNET_free (placeholder);
364 break;
365 /* Result number */
366 case 'n': printf ("%u", resultnum); break;
367 /* File's size */
368 case 's':
369 printf ("%" PRIu64, GNUNET_FS_uri_chk_get_file_size (uri));
370 break;
371 /* File's URI */
372 case 'u':
373 placeholder = GNUNET_FS_uri_to_string (uri);
374 printf ("%s", placeholder);
375 GNUNET_free (placeholder);
376 break;
377
378 /* We can add as many cases as we want here... */
379
380 /* Handle `%123#a` and `%123#j` (e.g. `%5#j` is a book title) */
381 case '0': case '1': case '2': case '3': case '4':
382 case '5': case '6': case '7': case '8': case '9':
383 cursor = next_spec;
384 info.type = *cursor - 48;
385 while (isdigit (*++cursor) && info.type < (INT_MAX - *cursor + 48) / 10)
386 info.type = info.type * 10 + *cursor - 48;
387 if (info.type == 0 || *cursor != '#')
388 goto not_a_specifier;
389 switch (*++cursor)
390 {
391 /* All metadata fields of type `info.type` */
392 case 'a':
393 next_spec = cursor;
395 goto iterate_meta;
396
397 /* Only the first metadata field of type `info.type` */
398 case 'j':
399 next_spec = cursor;
402 goto iterate_meta;
403 }
404 goto not_a_specifier;
405
406 /* All other cases */
407 case '%': putchar ('%'); break;
408 case '\0': putchar ('%'); return;
409
410 not_a_specifier:
411 default: printf ("%%%c", *next_spec); break;
412 }
413 cursor = next_spec + 1;
414 next_spec = strchr (cursor, '%');
415 goto parse_format;
416 }
417
418 if (*cursor)
419 printf ("%s", cursor);
420}
421
422
423static void
424clean_task (void *const cls)
425{
426 size_t dsize;
427 void *ddata;
428
430 ctx = NULL;
431 if (output_filename == NULL)
432 return;
433 if (GNUNET_OK !=
434 GNUNET_FS_directory_builder_finish (db, &dsize, &ddata))
435 {
436 GNUNET_break (0);
438 return;
439 }
441 if (GNUNET_OK !=
443 ddata,
444 dsize,
447 {
449 _ ("Failed to write directory with search results to "
450 "`%s'\n"),
452 }
453 GNUNET_free (ddata);
455}
456
457
471static void *
472progress_cb (void *const cls,
473 const struct GNUNET_FS_ProgressInfo *const info)
474{
475 static unsigned int cnt;
476 int is_directory;
477 char *filename;
478
479 switch (info->status)
480 {
482 break;
483
485 if (stop_searching)
486 break;
487
488 if (db != NULL)
490 db,
491 info->value.search.specifics.result.uri,
492 info->value.search.specifics.result.meta,
493 NULL);
494
495 if (silent_mode)
496 break;
497
498 cnt++;
500 info->value.search.specifics.result.meta,
503 info->value.search.specifics.result.meta);
504 if (NULL != filename)
505 {
506 while ((filename[0] != '\0') && ('/' == filename[strlen (filename) - 1]))
507 filename[strlen (filename) - 1] = '\0';
509 }
512 : is_directory ?
514 :
516 info->value.search.specifics.result.uri,
517 info->value.search.specifics.result.meta,
518 cnt,
519 is_directory);
520 fflush (stdout);
522 results++;
523 if ((results_limit > 0) && (results >= results_limit))
524 {
526 /* otherwise the function might keep printing results for a while... */
528 }
529 break;
530
533 /* ignore */
534 break;
535
538 _ ("Error searching: %s.\n"),
539 info->value.search.specifics.error.message);
541 break;
542
545 break;
546
547 default:
549 _ ("Unexpected status: %d\n"),
550 info->status);
551 break;
552 }
553 return NULL;
554}
555
556
557static void
558shutdown_task (void *const cls)
559{
560 if (sc != NULL)
561 {
563 sc = NULL;
564 }
565}
566
567
568static void
569timeout_task (void *const cls)
570{
571 tt = NULL;
574}
575
576
585static void
586run (void *const cls,
587 char *const *const args,
588 const char *const cfgfile,
589 const struct GNUNET_CONFIGURATION_Handle *const cfgarg)
590{
591 struct GNUNET_FS_Uri *uri;
592 unsigned int argc;
594
596 {
597 fprintf (stderr,
598 _ ("Conflicting options --bookmark-only and --silent.\n"));
599 ret = 1;
600 return;
601 }
603 {
604 fprintf (stderr,
605 _ ("Conflicting options --bookmark-only and --output.\n"));
606 ret = 1;
607 return;
608 }
610 {
611 fprintf (stderr, _ ("An output file is mandatory for silent mode.\n"));
612 ret = 1;
613 return;
614 }
615 if (NULL == dir_format_string)
619 if (NULL == format_string)
622 if (NULL == meta_format_string)
624 argc = 0;
625 while (NULL != args[argc])
626 argc++;
627 uri = GNUNET_FS_uri_ksk_create_from_args (argc, (const char **) args);
628 if (NULL == uri)
629 {
630 fprintf (stderr,
631 "%s",
632 _ ("Could not create keyword URI from arguments.\n"));
633 ret = 1;
634 return;
635 }
637 {
638 fprintf (stderr,
639 "%s",
640 _ ("Invalid URI. Valid URIs for searching are keyword query "
641 "URIs\n(\"gnunet://fs/ksk/...\") and namespace content URIs "
642 "(\"gnunet://fs/sks/...\").\n"));
644 ret = 1;
645 return;
646 }
647 if (bookmark_only)
648 {
649 char *bmstr = GNUNET_FS_uri_to_string (uri);
650 printf ("%s\n", bmstr);
651 GNUNET_free (bmstr);
653 ret = 0;
654 return;
655 }
656 cfg = cfgarg;
658 "gnunet-search",
660 NULL,
663 if (NULL == ctx)
664 {
665 fprintf (stderr, _ ("Could not initialize the `%s` subsystem.\n"), "FS");
667 ret = 1;
668 return;
669 }
670 if (output_filename != NULL)
673 if (local_only)
677 if (NULL == sc)
678 {
679 fprintf (stderr, "%s", _ ("Could not start searching.\n"));
681 ret = 1;
682 return;
683 }
684 if (0 != timeout.rel_value_us)
687}
688
689
697int
698main (int argc, char *const *argv)
699{
702 'a',
703 "anonymity",
704 "LEVEL",
705 gettext_noop ("set the desired LEVEL of receiver-anonymity (default: "
706 "1)"),
707 &anonymity),
709 'b',
710 "bookmark-only",
711 gettext_noop ("do not search, print only the URI that points to this "
712 "search"),
715 'F',
716 "dir-printf",
717 "FORMAT",
718 gettext_noop ("write search results for directories according to "
719 "FORMAT; accepted placeholders are: %a, %f, %j, %l, %m, "
720 "%n, %s; defaults to the value of --printf when omitted "
721 "or to `" HELP_DEFAULT_DIR_FORMAT "` if --printf is "
722 "omitted too"),
725 'f',
726 "printf",
727 "FORMAT",
728 gettext_noop ("write search results according to FORMAT; accepted "
729 "placeholders are: %a, %f, %j, %l, %m, %n, %s; defaults "
730 "to `" HELP_DEFAULT_FILE_FORMAT "` when omitted"),
733 'i',
734 "iter-printf",
735 "FORMAT",
736 gettext_noop ("when the %a or %j placeholders appear in --printf or "
737 "--dir-printf, list each metadata property according to "
738 "FORMAT; accepted placeholders are: %i, %l, %n, %p"
739 HELP_EXTRACTOR_TEXTADD ", %w; defaults to `"
740 HELP_DEFAULT_META_FORMAT "` when omitted"),
743 "results",
744 "VALUE",
745 gettext_noop ("automatically terminate search "
746 "after VALUE results are found"),
749 'n',
750 "no-network",
751 gettext_noop ("only search the local peer (no P2P network search)"),
752 &local_only),
754 'o',
755 "output",
756 "FILENAME",
757 gettext_noop ("create a GNUnet directory with search results at "
758 "FILENAME (e.g. `gnunet-search --output=commons"
759 GNUNET_FS_DIRECTORY_EXT " commons`)"),
762 's',
763 "silent",
764 gettext_noop ("silent mode (requires the --output argument)"),
765 &silent_mode),
767 't',
768 "timeout",
769 "DELAY",
770 gettext_noop ("automatically terminate search after DELAY; the value "
771 "given must be a number followed by a space and a time "
772 "unit, for example \"500 ms\"; without a unit it defaults "
773 "to microseconds - 1000000 = 1 second; if 0 or omitted "
774 "it means to wait for CTRL-C"),
775 &timeout),
777 'V',
778 "verbose",
779 gettext_noop ("be verbose (append \"%a\\n\" to the default --printf and "
780 "--dir-printf arguments - ignored when these are provided "
781 "by the user)"),
782 &verbose),
784
785 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
786 return 12;
787
788 if (GNUNET_SYSERR ==
789 GNUNET_PROGRAM_run (argc,
790 argv,
791 "gnunet-search [OPTIONS] KEYWORD1 KEYWORD2 ...",
792 gettext_noop ("Search for files that have been "
793 "published on GNUnet\n"),
794 options,
795 &run,
796 NULL))
797 ret = 1;
798
799 GNUNET_free_nz ((void *) argv);
800 return ret;
801}
802
803
804/* end of gnunet-search.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define INT_MAX
#define gettext_noop(String)
Definition: gettext.h:74
#define dgettext(Domainname, Msgid)
Definition: gettext.h:51
static char * plugin_name
Name of our plugin.
static char * data
The data to insert into the dht.
static char * filename
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
#define VERB_DEFAULT_DIR_FORMAT
Definition: gnunet-search.c:47
#define info
static char * output_filename
Definition: gnunet-search.c:89
#define DEFAULT_META_FORMAT
Definition: gnunet-search.c:55
static unsigned int verbose
#define HELP_DEFAULT_FILE_FORMAT
Definition: gnunet-search.c:46
#define DEFAULT_DIR_FORMAT
Definition: gnunet-search.c:43
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:87
#define HELP_DEFAULT_DIR_FORMAT
Definition: gnunet-search.c:44
static void timeout_task(void *const cls)
static char * dir_format_string
Definition: gnunet-search.c:93
#define HELP_DEFAULT_META_FORMAT
Definition: gnunet-search.c:56
static void shutdown_task(void *const cls)
static unsigned int anonymity
Definition: gnunet-search.c:99
#define GENERIC_FILE_NAME
Definition: gnunet-search.c:61
static void run(void *const cls, char *const *const args, const char *const cfgfile, const struct GNUNET_CONFIGURATION_Handle *const cfgarg)
Main function that will be run by the scheduler.
static void clean_task(void *const cls)
static int silent_mode
#define GNUNET_SEARCH_log(kind,...)
Definition: gnunet-search.c:37
static const struct GNUNET_CONFIGURATION_Handle * cfg
Definition: gnunet-search.c:83
static int bookmark_only
static char * meta_format_string
Definition: gnunet-search.c:95
static int ret
Definition: gnunet-search.c:81
static struct GNUNET_SCHEDULER_Task * tt
static unsigned int results
static struct GNUNET_FS_Handle * ctx
Definition: gnunet-search.c:85
GNUNET_SEARCH_MetadataPrinterFlags
Definition: gnunet-search.c:66
@ METADATA_PRINTER_FLAG_HAVE_TYPE
Definition: gnunet-search.c:69
@ METADATA_PRINTER_FLAG_NONE
Definition: gnunet-search.c:67
@ METADATA_PRINTER_FLAG_ONE_RUN
Definition: gnunet-search.c:68
#define GENERIC_FILE_MIMETYPE
Definition: gnunet-search.c:62
static const char * print_escape_sequence(const char *const esc)
Print the escape sequence at the beginning of a string.
static struct GNUNET_TIME_Relative timeout
Timeout for the search, 0 means to wait for CTRL-C.
static int stop_searching
#define DEFAULT_FILE_FORMAT
Definition: gnunet-search.c:45
#define HELP_EXTRACTOR_TEXTADD
Definition: gnunet-search.c:57
static int local_only
static unsigned int results_limit
int main(int argc, char *const *argv)
The main function to search GNUnet.
#define GENERIC_DIRECTORY_NAME
Definition: gnunet-search.c:60
static void * progress_cb(void *const cls, const struct GNUNET_FS_ProgressInfo *const info)
Called by FS client to give information about the progress of an operation.
static char * format_string
Definition: gnunet-search.c:91
#define VERB_DEFAULT_FILE_FORMAT
Definition: gnunet-search.c:48
static int item_printer(void *const cls, const char *const plugin_name, const enum EXTRACTOR_MetaType type, const enum EXTRACTOR_MetaFormat format, const char *const data_mime_type, const char *const data, const size_t data_size)
Type of a function that libextractor calls for each meta data item found.
static void print_search_result(const char *const filename, const struct GNUNET_FS_Uri *const uri, const struct GNUNET_FS_MetaData *const metadata, const unsigned int resultnum, const int is_directory)
Print a search result according to the current formats.
static struct GNUNET_FS_DirectoryBuilder * db
Definition: gnunet-search.c:97
API for file sharing via GNUnet.
void GNUNET_DISK_filename_canonicalize(char *fn)
Removes special characters as ':' from a filename.
Definition: disk.c:1192
enum GNUNET_GenericReturnValue GNUNET_DISK_fn_write(const char *fn, const void *buf, size_t buf_size, enum GNUNET_DISK_AccessPermissions mode)
Write a buffer to a file atomically.
Definition: disk.c:726
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1088
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
GNUNET_FS_SearchOptions
Options for searching.
int GNUNET_FS_directory_builder_finish(struct GNUNET_FS_DirectoryBuilder *bld, size_t *rsize, void **rdata)
Finish building the directory.
Definition: fs_directory.c:578
uint64_t GNUNET_FS_uri_chk_get_file_size(const struct GNUNET_FS_Uri *uri)
What is the size of the file that this URI refers to?
Definition: fs_uri.c:1360
int GNUNET_FS_uri_test_ksk(const struct GNUNET_FS_Uri *uri)
Is this a keyword URI?
Definition: fs_uri.c:1324
#define GNUNET_FS_DIRECTORY_MIME
char * GNUNET_FS_uri_to_string(const struct GNUNET_FS_Uri *uri)
Convert a URI to a UTF-8 String.
Definition: fs_uri.c:2034
struct GNUNET_FS_Handle * GNUNET_FS_start(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *client_name, GNUNET_FS_ProgressCallback upcb, void *upcb_cls, enum GNUNET_FS_Flags flags,...)
Setup a connection to the file-sharing service.
Definition: fs_api.c:3254
struct GNUNET_FS_Uri * GNUNET_FS_uri_ksk_create_from_args(unsigned int argc, const char **argv)
Create an FS URI from a user-supplied command line of keywords.
Definition: fs_uri.c:1144
void GNUNET_FS_search_stop(struct GNUNET_FS_SearchContext *sc)
Stop search for content.
Definition: fs_search.c:1766
void GNUNET_FS_uri_destroy(struct GNUNET_FS_Uri *uri)
Free URI.
Definition: fs_uri.c:677
int GNUNET_FS_uri_test_sks(const struct GNUNET_FS_Uri *uri)
Is this a namespace URI?
Definition: fs_uri.c:1271
struct GNUNET_FS_DirectoryBuilder * GNUNET_FS_directory_builder_create(const struct GNUNET_FS_MetaData *mdir)
Create a directory builder.
Definition: fs_directory.c:366
int GNUNET_FS_meta_data_test_for_directory(const struct GNUNET_FS_MetaData *md)
Does the meta-data claim that this is a directory? Checks if the mime-type is that of a GNUnet direct...
Definition: fs_directory.c:55
#define GNUNET_FS_DIRECTORY_EXT
void GNUNET_FS_stop(struct GNUNET_FS_Handle *h)
Close our connection with the file-sharing service.
Definition: fs_api.c:3320
struct GNUNET_FS_SearchContext * GNUNET_FS_search_start(struct GNUNET_FS_Handle *h, const struct GNUNET_FS_Uri *uri, uint32_t anonymity, enum GNUNET_FS_SearchOptions options, void *cctx)
Start search for content.
Definition: fs_search.c:1607
void GNUNET_FS_directory_builder_add(struct GNUNET_FS_DirectoryBuilder *bld, const struct GNUNET_FS_Uri *uri, const struct GNUNET_FS_MetaData *md, const void *data)
Add an entry to a directory.
Definition: fs_directory.c:392
@ GNUNET_FS_FLAGS_NONE
No special flags set.
@ GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY
Only search the local host, do not search remote systems (no P2P)
@ GNUNET_FS_SEARCH_OPTION_NONE
No options (use defaults for everything).
@ GNUNET_FS_OPTIONS_END
Last option in the VARARG list.
@ GNUNET_FS_STATUS_SEARCH_UPDATE
We have additional data about the quality or availability of a search result.
@ GNUNET_FS_STATUS_SEARCH_ERROR
Signals a problem with this search.
@ GNUNET_FS_STATUS_SEARCH_RESULT_STOPPED
Event generated for each search result when the respective search is stopped.
@ GNUNET_FS_STATUS_SEARCH_RESULT
This search has yielded a result.
@ GNUNET_FS_STATUS_SEARCH_START
First event generated when a client requests a search to begin or when a namespace result automatical...
@ GNUNET_FS_STATUS_SEARCH_STOPPED
Last message from a search; this signals that there will be no further events associated with this se...
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_increment_uint(char shortName, const char *name, const char *description, unsigned int *val)
Increment val each time the option flag is given by one.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_relative_time(char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Relative *val)
Allow user to specify a struct GNUNET_TIME_Relative (using human-readable "fancy" time).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_free_nz(ptr)
Wrapper around free.
int GNUNET_FS_meta_data_iterate(const struct GNUNET_FS_MetaData *md, EXTRACTOR_MetaDataProcessor iter, void *iter_cls)
Iterate over MD entries.
Definition: meta_data.c:418
char * GNUNET_FS_meta_data_get_by_type(const struct GNUNET_FS_MetaData *md, enum EXTRACTOR_MetaType type)
Get the first MD entry of the given type.
Definition: meta_data.c:438
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:566
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1338
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1303
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1276
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1230
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
#define LIBEXTRACTOR_GETTEXT_DOMAIN
Definition: platform.h:179
Internal state of a directory builder.
Definition: fs_directory.c:342
Master context for most FS operations.
Definition: fs_api.h:1070
Meta data to associate with a file, directory or namespace.
Definition: meta_data.c:92
Argument given to the progress callback with information about what is going on.
Handle for controlling a search.
Definition: fs_api.h:1511
A Universal Resource Identifier (URI), opaque.
Definition: fs_api.h:167
Definition of a command line option.
Entry in list of pending tasks.
Definition: scheduler.c:135
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.