aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2022-12-04 23:26:25 +0900
committerMartin Schanzenbach <schanzen@gnunet.org>2022-12-04 23:26:25 +0900
commit395bc9345a005a55e29a7882fdcc82f35c06d2e5 (patch)
treeb111592f9f57025a19ddafe11877f6038263ae7f /src/include
parent3f0d91045d29435feef723f09f9ff75c80296d3d (diff)
downloadgnunet-395bc9345a005a55e29a7882fdcc82f35c06d2e5.tar.gz
gnunet-395bc9345a005a55e29a7882fdcc82f35c06d2e5.zip
Large refactor in order to restore some sanity with respect to private defines used in headers
Diffstat (limited to 'src/include')
-rw-r--r--src/include/gnunet_bio_lib.h49
-rw-r--r--src/include/gnunet_config.h.in3
-rw-r--r--src/include/gnunet_container_lib.h389
-rw-r--r--src/include/gnunet_extractor_compat.h149
-rw-r--r--src/include/gnunet_fs_service.h393
-rw-r--r--src/include/gnunet_mysql_compat.h63
-rw-r--r--src/include/gnunet_util_lib.h37
7 files changed, 614 insertions, 469 deletions
diff --git a/src/include/gnunet_bio_lib.h b/src/include/gnunet_bio_lib.h
index e165b9d90..6d42f554c 100644
--- a/src/include/gnunet_bio_lib.h
+++ b/src/include/gnunet_bio_lib.h
@@ -125,19 +125,6 @@ GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
125 size_t max_length); 125 size_t max_length);
126 126
127 127
128/**
129 * Read a metadata container.
130 *
131 * @param h handle to an open file
132 * @param what describes what is being read (for error message creation)
133 * @param result the buffer to store a pointer to the (allocated) metadata
134 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
135 */
136int
137GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
138 const char *what,
139 struct GNUNET_CONTAINER_MetaData **result);
140
141 128
142/** 129/**
143 * Read a float. 130 * Read a float.
@@ -294,19 +281,6 @@ GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h,
294 const char *s); 281 const char *s);
295 282
296 283
297/**
298 * Write a metadata container.
299 *
300 * @param h the IO handle to write to
301 * @param what what is being written (for error message creation)
302 * @param m metadata to write
303 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
304 */
305int
306GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
307 const char *what,
308 const struct GNUNET_CONTAINER_MetaData *m);
309
310 284
311/** 285/**
312 * Write a float. 286 * Write a float.
@@ -453,17 +427,6 @@ GNUNET_BIO_read_spec_string (const char *what,
453 size_t max_length); 427 size_t max_length);
454 428
455 429
456/**
457 * Create the specification to read a metadata container.
458 *
459 * @param what describes what is being read (for error message creation)
460 * @param result the buffer to store a pointer to the (allocated) metadata
461 * @return the read spec
462 */
463struct GNUNET_BIO_ReadSpec
464GNUNET_BIO_read_spec_meta_data (const char *what,
465 struct GNUNET_CONTAINER_MetaData **result);
466
467 430
468/** 431/**
469 * Create the specification to read an (u)int32_t. 432 * Create the specification to read an (u)int32_t.
@@ -610,18 +573,6 @@ GNUNET_BIO_write_spec_string (const char *what,
610 573
611 574
612/** 575/**
613 * Create the specification to write a metadata container.
614 *
615 * @param what what is being written (for error message creation)
616 * @param m metadata to write
617 * @return the write spec
618 */
619struct GNUNET_BIO_WriteSpec
620GNUNET_BIO_write_spec_meta_data (const char *what,
621 const struct GNUNET_CONTAINER_MetaData *m);
622
623
624/**
625 * Create the specification to write an (u)int32_t. 576 * Create the specification to write an (u)int32_t.
626 * 577 *
627 * @param what describes what is being written (for error message creation) 578 * @param what describes what is being written (for error message creation)
diff --git a/src/include/gnunet_config.h.in b/src/include/gnunet_config.h.in
index 5b0d69a03..ce7c5a894 100644
--- a/src/include/gnunet_config.h.in
+++ b/src/include/gnunet_config.h.in
@@ -48,7 +48,4 @@
48/* Set to 1 if GnuTLS has DANE support */ 48/* Set to 1 if GnuTLS has DANE support */
49#define GNUNET_CURL_GNUTLS @curl_gnutls@ 49#define GNUNET_CURL_GNUTLS @curl_gnutls@
50 50
51/* Set to 1 is we have the byteswap header */
52#define GNUNET_HAVE_BYTESWAP_H @have_byteswap@
53
54#endif 51#endif
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index 55774a209..1d39f813b 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -48,8 +48,6 @@
48 * 48 *
49 * @see [Documentation](https://gnunet.org/mdll-api) 49 * @see [Documentation](https://gnunet.org/mdll-api)
50 * 50 *
51 * @defgroup metadata Metadata
52 * GNU libextractor key-value pairs
53 * 51 *
54 * @} 52 * @}
55 */ 53 */
@@ -102,114 +100,6 @@ char *
102GNUNET_decompress (const char *input, size_t input_size, size_t output_size); 100GNUNET_decompress (const char *input, size_t input_size, size_t output_size);
103 101
104 102
105#if HAVE_EXTRACTOR_H
106
107#include <extractor.h>
108
109#else
110
111/* definitions from extractor.h we need for the build */
112
113/**
114 * Enumeration defining various sources of keywords. See also
115 * http://dublincore.org/documents/1998/09/dces/
116 */
117enum EXTRACTOR_MetaType
118{
119 EXTRACTOR_METATYPE_RESERVED = 0,
120 EXTRACTOR_METATYPE_MIMETYPE = 1,
121 EXTRACTOR_METATYPE_FILENAME = 2,
122 EXTRACTOR_METATYPE_COMMENT = 3,
123 EXTRACTOR_METATYPE_TITLE = 4,
124 EXTRACTOR_METATYPE_BOOK_TITLE = 5,
125 EXTRACTOR_METATYPE_JOURNAL_NAME = 8,
126 EXTRACTOR_METATYPE_AUTHOR_NAME = 13,
127 EXTRACTOR_METATYPE_PUBLICATION_DATE = 24,
128 EXTRACTOR_METATYPE_URL = 29,
129 EXTRACTOR_METATYPE_URI = 30,
130 EXTRACTOR_METATYPE_ISRC = 31,
131 EXTRACTOR_METATYPE_UNKNOWN = 45,
132 EXTRACTOR_METATYPE_DESCRIPTION = 46,
133 EXTRACTOR_METATYPE_KEYWORDS = 49,
134 EXTRACTOR_METATYPE_SUBJECT = 52,
135 EXTRACTOR_METATYPE_PACKAGE_NAME = 69,
136 EXTRACTOR_METATYPE_THUMBNAIL = 114,
137 EXTRACTOR_METATYPE_ALBUM = 129,
138 EXTRACTOR_METATYPE_ARTIST = 130,
139 EXTRACTOR_METATYPE_ORIGINAL_TITLE = 162,
140 EXTRACTOR_METATYPE_GNUNET_FULL_DATA = 174,
141 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME = 180,
142};
143
144/**
145 * Format in which the extracted meta data is presented.
146 */
147enum EXTRACTOR_MetaFormat
148{
149 /**
150 * Format is unknown.
151 */
152 EXTRACTOR_METAFORMAT_UNKNOWN = 0,
153
154 /**
155 * 0-terminated, UTF-8 encoded string. "data_len"
156 * is strlen(data)+1.
157 */
158 EXTRACTOR_METAFORMAT_UTF8 = 1,
159
160 /**
161 * Some kind of binary format, see given Mime type.
162 */
163 EXTRACTOR_METAFORMAT_BINARY = 2,
164
165 /**
166 * 0-terminated string. The specific encoding is unknown.
167 * "data_len" is strlen (data)+1.
168 */
169 EXTRACTOR_METAFORMAT_C_STRING = 3
170};
171
172
173/**
174 * Type of a function that libextractor calls for each
175 * meta data item found.
176 *
177 * @param cls closure (user-defined)
178 * @param plugin_name name of the plugin that produced this value;
179 * special values can be used (e.g. '&lt;zlib&gt;' for zlib being
180 * used in the main libextractor library and yielding
181 * meta data).
182 * @param type libextractor-type describing the meta data
183 * @param format basic format information about @a data
184 * @param data_mime_type mime-type of @a data (not of the original file);
185 * can be NULL (if mime-type is not known)
186 * @param data actual meta-data found
187 * @param data_len number of bytes in @a data
188 * @return 0 to continue extracting, 1 to abort
189 */
190typedef int (*EXTRACTOR_MetaDataProcessor) (void *cls,
191 const char *plugin_name,
192 enum EXTRACTOR_MetaType type,
193 enum EXTRACTOR_MetaFormat format,
194 const char *data_mime_type,
195 const char *data,
196 size_t data_len);
197
198#endif
199
200#ifndef EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
201/* hack for LE < 0.6.3 */
202#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME 180
203#endif
204
205#ifdef __cplusplus
206extern "C" {
207#if 0 /* keep Emacsens' auto-indent happy */
208}
209#endif
210#endif
211
212
213/* ******************* bloomfilter ***************** */ 103/* ******************* bloomfilter ***************** */
214 104
215/** 105/**
@@ -435,285 +325,6 @@ GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
435 unsigned int k); 325 unsigned int k);
436 326
437 327
438/* ****************** metadata ******************* */
439
440/**
441 * @ingroup metadata
442 * Meta data to associate with a file, directory or namespace.
443 */
444struct GNUNET_CONTAINER_MetaData;
445
446
447/**
448 * @ingroup metadata
449 * Create a fresh meta data container.
450 *
451 * @return empty meta-data container
452 */
453struct GNUNET_CONTAINER_MetaData *
454GNUNET_CONTAINER_meta_data_create (void);
455
456
457/**
458 * @ingroup metadata
459 * Duplicate a MetaData token.
460 *
461 * @param md what to duplicate
462 * @return duplicate meta-data container
463 */
464struct GNUNET_CONTAINER_MetaData *
465GNUNET_CONTAINER_meta_data_duplicate (
466 const struct GNUNET_CONTAINER_MetaData *md);
467
468
469/**
470 * @ingroup metadata
471 * Free meta data.
472 *
473 * @param md what to free
474 */
475void
476GNUNET_CONTAINER_meta_data_destroy (struct GNUNET_CONTAINER_MetaData *md);
477
478
479/**
480 * @ingroup metadata
481 * Test if two MDs are equal. We consider them equal if
482 * the meta types, formats and content match (we do not
483 * include the mime types and plugins names in this
484 * consideration).
485 *
486 * @param md1 first value to check
487 * @param md2 other value to check
488 * @return #GNUNET_YES if they are equal
489 */
490int
491GNUNET_CONTAINER_meta_data_test_equal (
492 const struct GNUNET_CONTAINER_MetaData *md1,
493 const struct GNUNET_CONTAINER_MetaData *md2);
494
495
496/**
497 * @ingroup metadata
498 * Extend metadata.
499 *
500 * @param md metadata to extend
501 * @param plugin_name name of the plugin that produced this value;
502 * special values can be used (e.g. '&lt;zlib&gt;' for zlib being
503 * used in the main libextractor library and yielding
504 * meta data).
505 * @param type libextractor-type describing the meta data
506 * @param format basic format information about data
507 * @param data_mime_type mime-type of data (not of the original file);
508 * can be NULL (if mime-type is not known)
509 * @param data actual meta-data found
510 * @param data_size number of bytes in data
511 * @return #GNUNET_OK on success, #GNUNET_SYSERR if this entry already exists
512 * data_mime_type and plugin_name are not considered for "exists" checks
513 */
514int
515GNUNET_CONTAINER_meta_data_insert (struct GNUNET_CONTAINER_MetaData *md,
516 const char *plugin_name,
517 enum EXTRACTOR_MetaType type,
518 enum EXTRACTOR_MetaFormat format,
519 const char *data_mime_type,
520 const char *data,
521 size_t data_size);
522
523
524/**
525 * @ingroup metadata
526 * Extend metadata. Merges the meta data from the second argument
527 * into the first, discarding duplicate key-value pairs.
528 *
529 * @param md metadata to extend
530 * @param in metadata to merge
531 */
532void
533GNUNET_CONTAINER_meta_data_merge (struct GNUNET_CONTAINER_MetaData *md,
534 const struct GNUNET_CONTAINER_MetaData *in);
535
536
537/**
538 * @ingroup metadata
539 * Remove an item.
540 *
541 * @param md metadata to manipulate
542 * @param type type of the item to remove
543 * @param data specific value to remove, NULL to remove all
544 * entries of the given type
545 * @param data_size number of bytes in data
546 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the item does not exist in md
547 */
548int
549GNUNET_CONTAINER_meta_data_delete (struct GNUNET_CONTAINER_MetaData *md,
550 enum EXTRACTOR_MetaType type,
551 const char *data,
552 size_t data_size);
553
554
555/**
556 * @ingroup metadata
557 * Remove all items in the container.
558 *
559 * @param md metadata to manipulate
560 */
561void
562GNUNET_CONTAINER_meta_data_clear (struct GNUNET_CONTAINER_MetaData *md);
563
564
565/**
566 * @ingroup metadata
567 * Add the current time as the publication date
568 * to the meta-data.
569 *
570 * @param md metadata to modify
571 */
572void
573GNUNET_CONTAINER_meta_data_add_publication_date (
574 struct GNUNET_CONTAINER_MetaData *md);
575
576
577/**
578 * @ingroup metadata
579 * Iterate over MD entries.
580 *
581 * @param md metadata to inspect
582 * @param iter function to call on each entry, return 0 to continue to iterate
583 * and 1 to abort iteration in this function (GNU libextractor API!)
584 * @param iter_cls closure for @a iter
585 * @return number of entries
586 */
587int
588GNUNET_CONTAINER_meta_data_iterate (const struct GNUNET_CONTAINER_MetaData *md,
589 EXTRACTOR_MetaDataProcessor iter,
590 void *iter_cls);
591
592
593/**
594 * @ingroup metadata
595 * Get the first MD entry of the given type. Caller
596 * is responsible for freeing the return value.
597 * Also, only meta data items that are strings (0-terminated)
598 * are returned by this function.
599 *
600 * @param md metadata to inspect
601 * @param type type to look for
602 * @return NULL if no entry was found
603 */
604char *
605GNUNET_CONTAINER_meta_data_get_by_type (
606 const struct GNUNET_CONTAINER_MetaData *md,
607 enum EXTRACTOR_MetaType type);
608
609
610/**
611 * @ingroup metadata
612 * Get the first matching MD entry of the given types. Caller is
613 * responsible for freeing the return value. Also, only meta data
614 * items that are strings (0-terminated) are returned by this
615 * function.
616 *
617 * @param md metadata to inspect
618 * @param ... -1-terminated list of types
619 * @return NULL if we do not have any such entry,
620 * otherwise client is responsible for freeing the value!
621 */
622char *
623GNUNET_CONTAINER_meta_data_get_first_by_types (
624 const struct GNUNET_CONTAINER_MetaData *md,
625 ...);
626
627/**
628 * @ingroup metadata
629 * Get a thumbnail from the meta-data (if present). Only matches meta
630 * data with mime type "image" and binary format.
631 *
632 * @param md metadata to inspect
633 * @param thumb will be set to the thumbnail data. Must be
634 * freed by the caller!
635 * @return number of bytes in thumbnail, 0 if not available
636 */
637size_t
638GNUNET_CONTAINER_meta_data_get_thumbnail (
639 const struct GNUNET_CONTAINER_MetaData *md,
640 unsigned char **thumb);
641
642
643/**
644 * @ingroup metadata
645 * Options for metadata serialization.
646 */
647enum GNUNET_CONTAINER_MetaDataSerializationOptions
648{
649 /**
650 * @ingroup metadata
651 * Serialize all of the data.
652 */
653 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL = 0,
654
655 /**
656 * @ingroup metadata
657 * If not enough space is available, it is acceptable
658 * to only serialize some of the metadata.
659 */
660 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART = 1,
661
662 /**
663 * @ingroup metadata
664 * Speed is of the essence, do not allow compression.
665 */
666 GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS = 2
667};
668
669
670/**
671 * @ingroup metadata
672 * Serialize meta-data to target.
673 *
674 * @param md metadata to serialize
675 * @param target where to write the serialized metadata;
676 * *target can be NULL, in which case memory is allocated
677 * @param max maximum number of bytes available
678 * @param opt is it ok to just write SOME of the
679 * meta-data to match the size constraint,
680 * possibly discarding some data?
681 * @return number of bytes written on success,
682 * -1 on error (typically: not enough
683 * space)
684 */
685ssize_t
686GNUNET_CONTAINER_meta_data_serialize (
687 const struct GNUNET_CONTAINER_MetaData *md,
688 char **target,
689 size_t max,
690 enum GNUNET_CONTAINER_MetaDataSerializationOptions opt);
691
692
693/**
694 * @ingroup metadata
695 * Get the size of the full meta-data in serialized form.
696 *
697 * @param md metadata to inspect
698 * @return number of bytes needed for serialization, -1 on error
699 */
700ssize_t
701GNUNET_CONTAINER_meta_data_get_serialized_size (
702 const struct GNUNET_CONTAINER_MetaData *md);
703
704
705/**
706 * @ingroup metadata
707 * Deserialize meta-data. Initializes md.
708 *
709 * @param input serialized meta-data.
710 * @param size number of bytes available
711 * @return MD on success, NULL on error (e.g.
712 * bad format)
713 */
714struct GNUNET_CONTAINER_MetaData *
715GNUNET_CONTAINER_meta_data_deserialize (const char *input, size_t size);
716
717 328
718/* ******************************* HashMap **************************** */ 329/* ******************************* HashMap **************************** */
719 330
diff --git a/src/include/gnunet_extractor_compat.h b/src/include/gnunet_extractor_compat.h
new file mode 100644
index 000000000..d69525c9d
--- /dev/null
+++ b/src/include/gnunet_extractor_compat.h
@@ -0,0 +1,149 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 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 */
20/**
21 * @author Martin Schanzenbach
22 *
23 * @file
24 * libextractor compatibility insanity helper header
25 *
26 * @{
27 */
28#ifndef GNUNET_EXTRACTOR_COMPAT_H
29#define GNUNET_EXTRACTOR_COMPAT_H
30
31
32#ifdef __cplusplus
33extern "C"
34{
35#if 0 /* keep Emacsens' auto-indent happy */
36}
37#endif
38#endif
39
40#if HAVE_EXTRACTOR_H
41
42#include <extractor.h>
43
44#else
45
46/* definitions from extractor.h we need for the build */
47
48/**
49 * Enumeration defining various sources of keywords. See also
50 * http://dublincore.org/documents/1998/09/dces/
51 */
52enum EXTRACTOR_MetaType
53{
54 EXTRACTOR_METATYPE_RESERVED = 0,
55 EXTRACTOR_METATYPE_MIMETYPE = 1,
56 EXTRACTOR_METATYPE_FILENAME = 2,
57 EXTRACTOR_METATYPE_COMMENT = 3,
58 EXTRACTOR_METATYPE_TITLE = 4,
59 EXTRACTOR_METATYPE_BOOK_TITLE = 5,
60 EXTRACTOR_METATYPE_JOURNAL_NAME = 8,
61 EXTRACTOR_METATYPE_AUTHOR_NAME = 13,
62 EXTRACTOR_METATYPE_PUBLICATION_DATE = 24,
63 EXTRACTOR_METATYPE_URL = 29,
64 EXTRACTOR_METATYPE_URI = 30,
65 EXTRACTOR_METATYPE_ISRC = 31,
66 EXTRACTOR_METATYPE_UNKNOWN = 45,
67 EXTRACTOR_METATYPE_DESCRIPTION = 46,
68 EXTRACTOR_METATYPE_KEYWORDS = 49,
69 EXTRACTOR_METATYPE_SUBJECT = 52,
70 EXTRACTOR_METATYPE_PACKAGE_NAME = 69,
71 EXTRACTOR_METATYPE_THUMBNAIL = 114,
72 EXTRACTOR_METATYPE_ALBUM = 129,
73 EXTRACTOR_METATYPE_ARTIST = 130,
74 EXTRACTOR_METATYPE_ORIGINAL_TITLE = 162,
75 EXTRACTOR_METATYPE_GNUNET_FULL_DATA = 174,
76 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME = 180,
77};
78
79/**
80 * Format in which the extracted meta data is presented.
81 */
82enum EXTRACTOR_MetaFormat
83{
84 /**
85 * Format is unknown.
86 */
87 EXTRACTOR_METAFORMAT_UNKNOWN = 0,
88
89 /**
90 * 0-terminated, UTF-8 encoded string. "data_len"
91 * is strlen(data)+1.
92 */
93 EXTRACTOR_METAFORMAT_UTF8 = 1,
94
95 /**
96 * Some kind of binary format, see given Mime type.
97 */
98 EXTRACTOR_METAFORMAT_BINARY = 2,
99
100 /**
101 * 0-terminated string. The specific encoding is unknown.
102 * "data_len" is strlen (data)+1.
103 */
104 EXTRACTOR_METAFORMAT_C_STRING = 3
105};
106
107
108/**
109 * Type of a function that libextractor calls for each
110 * meta data item found.
111 *
112 * @param cls closure (user-defined)
113 * @param plugin_name name of the plugin that produced this value;
114 * special values can be used (e.g. '&lt;zlib&gt;' for zlib being
115 * used in the main libextractor library and yielding
116 * meta data).
117 * @param type libextractor-type describing the meta data
118 * @param format basic format information about @a data
119 * @param data_mime_type mime-type of @a data (not of the original file);
120 * can be NULL (if mime-type is not known)
121 * @param data actual meta-data found
122 * @param data_len number of bytes in @a data
123 * @return 0 to continue extracting, 1 to abort
124 */
125typedef int (*EXTRACTOR_MetaDataProcessor) (void *cls,
126 const char *plugin_name,
127 enum EXTRACTOR_MetaType type,
128 enum EXTRACTOR_MetaFormat format,
129 const char *data_mime_type,
130 const char *data,
131 size_t data_len);
132
133#endif
134
135#ifndef EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME
136/* hack for LE < 0.6.3 */
137#define EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME 180
138#endif
139
140#if 0 /* keep Emacsens' auto-indent happy */
141{
142#endif
143#ifdef __cplusplus
144}
145#endif
146
147#endif
148
149/** @} */ /* end of group */
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index 6b46f1553..53ca6a9ec 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -37,6 +37,7 @@
37#define GNUNET_FS_LIB_H 37#define GNUNET_FS_LIB_H
38 38
39 39
40#include "gnunet_common.h"
40#include "gnunet_util_lib.h" 41#include "gnunet_util_lib.h"
41 42
42#ifdef __cplusplus 43#ifdef __cplusplus
@@ -92,6 +93,12 @@ extern "C"
92 */ 93 */
93struct GNUNET_FS_Uri; 94struct GNUNET_FS_Uri;
94 95
96/**
97 * @ingroup metadata
98 * Meta data to associate with a file, directory or namespace.
99 */
100struct GNUNET_FS_MetaData;
101
95 102
96/** 103/**
97 * Iterator over keywords 104 * Iterator over keywords
@@ -436,7 +443,7 @@ GNUNET_FS_uri_test_loc (const struct GNUNET_FS_Uri *uri);
436 * @return NULL on error, otherwise a KSK URI 443 * @return NULL on error, otherwise a KSK URI
437 */ 444 */
438struct GNUNET_FS_Uri * 445struct GNUNET_FS_Uri *
439GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData 446GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_FS_MetaData
440 *md); 447 *md);
441 448
442 449
@@ -472,7 +479,7 @@ GNUNET_FS_GETOPT_METADATA (char shortName,
472 const char *name, 479 const char *name,
473 const char *argumentHelp, 480 const char *argumentHelp,
474 const char *description, 481 const char *description,
475 struct GNUNET_CONTAINER_MetaData **meta); 482 struct GNUNET_FS_MetaData **meta);
476 483
477/** 484/**
478 * Command-line option parser function that allows the user to specify 485 * Command-line option parser function that allows the user to specify
@@ -481,7 +488,7 @@ GNUNET_FS_GETOPT_METADATA (char shortName,
481 * the metadata must be passed as the "scls" argument. 488 * the metadata must be passed as the "scls" argument.
482 * 489 *
483 * @param ctx command line processor context 490 * @param ctx command line processor context
484 * @param scls must be of type `struct GNUNET_CONTAINER_MetaData **` 491 * @param scls must be of type `struct GNUNET_FS_MetaData **`
485 * @param option name of the option (typically 'k') 492 * @param option name of the option (typically 'k')
486 * @param value command line argument given 493 * @param value command line argument given
487 * @return #GNUNET_OK on success 494 * @return #GNUNET_OK on success
@@ -1099,7 +1106,7 @@ struct GNUNET_FS_ProgressInfo
1099 /** 1106 /**
1100 * Known metadata for the download. 1107 * Known metadata for the download.
1101 */ 1108 */
1102 const struct GNUNET_CONTAINER_MetaData *meta; 1109 const struct GNUNET_FS_MetaData *meta;
1103 } start; 1110 } start;
1104 1111
1105 /** 1112 /**
@@ -1111,7 +1118,7 @@ struct GNUNET_FS_ProgressInfo
1111 /** 1118 /**
1112 * Known metadata for the download. 1119 * Known metadata for the download.
1113 */ 1120 */
1114 const struct GNUNET_CONTAINER_MetaData *meta; 1121 const struct GNUNET_FS_MetaData *meta;
1115 1122
1116 /** 1123 /**
1117 * Error message, NULL if we have not encountered any error yet. 1124 * Error message, NULL if we have not encountered any error yet.
@@ -1196,7 +1203,7 @@ struct GNUNET_FS_ProgressInfo
1196 /** 1203 /**
1197 * Metadata for the search result. 1204 * Metadata for the search result.
1198 */ 1205 */
1199 const struct GNUNET_CONTAINER_MetaData *meta; 1206 const struct GNUNET_FS_MetaData *meta;
1200 1207
1201 /** 1208 /**
1202 * URI for the search result. 1209 * URI for the search result.
@@ -1224,7 +1231,7 @@ struct GNUNET_FS_ProgressInfo
1224 /** 1231 /**
1225 * Metadata for the search result. 1232 * Metadata for the search result.
1226 */ 1233 */
1227 const struct GNUNET_CONTAINER_MetaData *meta; 1234 const struct GNUNET_FS_MetaData *meta;
1228 1235
1229 /** 1236 /**
1230 * URI for the search result. 1237 * URI for the search result.
@@ -1271,7 +1278,7 @@ struct GNUNET_FS_ProgressInfo
1271 /** 1278 /**
1272 * Metadata for the search result. 1279 * Metadata for the search result.
1273 */ 1280 */
1274 const struct GNUNET_CONTAINER_MetaData *meta; 1281 const struct GNUNET_FS_MetaData *meta;
1275 1282
1276 /** 1283 /**
1277 * URI for the search result. 1284 * URI for the search result.
@@ -1323,7 +1330,7 @@ struct GNUNET_FS_ProgressInfo
1323 /** 1330 /**
1324 * Metadata for the search result. 1331 * Metadata for the search result.
1325 */ 1332 */
1326 const struct GNUNET_CONTAINER_MetaData *meta; 1333 const struct GNUNET_FS_MetaData *meta;
1327 1334
1328 /** 1335 /**
1329 * URI for the search result. 1336 * URI for the search result.
@@ -1351,7 +1358,7 @@ struct GNUNET_FS_ProgressInfo
1351 /** 1358 /**
1352 * Metadata for the search result. 1359 * Metadata for the search result.
1353 */ 1360 */
1354 const struct GNUNET_CONTAINER_MetaData *meta; 1361 const struct GNUNET_FS_MetaData *meta;
1355 1362
1356 /** 1363 /**
1357 * URI for the search result. 1364 * URI for the search result.
@@ -1406,7 +1413,7 @@ struct GNUNET_FS_ProgressInfo
1406 /** 1413 /**
1407 * Metadata for the namespace. 1414 * Metadata for the namespace.
1408 */ 1415 */
1409 const struct GNUNET_CONTAINER_MetaData *meta; 1416 const struct GNUNET_FS_MetaData *meta;
1410 1417
1411 /** 1418 /**
1412 * Public key of the namespace. 1419 * Public key of the namespace.
@@ -1706,7 +1713,7 @@ typedef int
1706(*GNUNET_FS_FileInformationProcessor) (void *cls, 1713(*GNUNET_FS_FileInformationProcessor) (void *cls,
1707 struct GNUNET_FS_FileInformation *fi, 1714 struct GNUNET_FS_FileInformation *fi,
1708 uint64_t length, 1715 uint64_t length,
1709 struct GNUNET_CONTAINER_MetaData *meta, 1716 struct GNUNET_FS_MetaData *meta,
1710 struct GNUNET_FS_Uri **uri, 1717 struct GNUNET_FS_Uri **uri,
1711 struct GNUNET_FS_BlockOptions *bo, 1718 struct GNUNET_FS_BlockOptions *bo,
1712 int *do_index, 1719 int *do_index,
@@ -1771,7 +1778,7 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
1771 const struct 1778 const struct
1772 GNUNET_FS_Uri *keywords, 1779 GNUNET_FS_Uri *keywords,
1773 const struct 1780 const struct
1774 GNUNET_CONTAINER_MetaData *meta, 1781 GNUNET_FS_MetaData *meta,
1775 int do_index, 1782 int do_index,
1776 const struct 1783 const struct
1777 GNUNET_FS_BlockOptions *bo); 1784 GNUNET_FS_BlockOptions *bo);
@@ -1801,7 +1808,7 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
1801 const struct 1808 const struct
1802 GNUNET_FS_Uri *keywords, 1809 GNUNET_FS_Uri *keywords,
1803 const struct 1810 const struct
1804 GNUNET_CONTAINER_MetaData *meta, 1811 GNUNET_FS_MetaData *meta,
1805 int do_index, 1812 int do_index,
1806 const struct 1813 const struct
1807 GNUNET_FS_BlockOptions *bo); 1814 GNUNET_FS_BlockOptions *bo);
@@ -1860,7 +1867,7 @@ GNUNET_FS_file_information_create_from_reader (struct GNUNET_FS_Handle *h,
1860 const struct GNUNET_FS_Uri 1867 const struct GNUNET_FS_Uri
1861 *keywords, 1868 *keywords,
1862 const struct 1869 const struct
1863 GNUNET_CONTAINER_MetaData *meta, 1870 GNUNET_FS_MetaData *meta,
1864 int do_index, 1871 int do_index,
1865 const struct 1872 const struct
1866 GNUNET_FS_BlockOptions *bo); 1873 GNUNET_FS_BlockOptions *bo);
@@ -1884,7 +1891,7 @@ GNUNET_FS_file_information_create_empty_directory (struct GNUNET_FS_Handle *h,
1884 const struct GNUNET_FS_Uri 1891 const struct GNUNET_FS_Uri
1885 *keywords, 1892 *keywords,
1886 const struct 1893 const struct
1887 GNUNET_CONTAINER_MetaData 1894 GNUNET_FS_MetaData
1888 *meta, 1895 *meta,
1889 const struct 1896 const struct
1890 GNUNET_FS_BlockOptions *bo, 1897 GNUNET_FS_BlockOptions *bo,
@@ -2043,7 +2050,7 @@ struct GNUNET_FS_PublishKskContext;
2043struct GNUNET_FS_PublishKskContext * 2050struct GNUNET_FS_PublishKskContext *
2044GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h, 2051GNUNET_FS_publish_ksk (struct GNUNET_FS_Handle *h,
2045 const struct GNUNET_FS_Uri *ksk_uri, 2052 const struct GNUNET_FS_Uri *ksk_uri,
2046 const struct GNUNET_CONTAINER_MetaData *meta, 2053 const struct GNUNET_FS_MetaData *meta,
2047 const struct GNUNET_FS_Uri *uri, 2054 const struct GNUNET_FS_Uri *uri,
2048 const struct GNUNET_FS_BlockOptions *bo, 2055 const struct GNUNET_FS_BlockOptions *bo,
2049 enum GNUNET_FS_PublishOptions options, 2056 enum GNUNET_FS_PublishOptions options,
@@ -2085,7 +2092,7 @@ GNUNET_FS_publish_sks (struct GNUNET_FS_Handle *h,
2085 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, 2092 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
2086 const char *identifier, 2093 const char *identifier,
2087 const char *update, 2094 const char *update,
2088 const struct GNUNET_CONTAINER_MetaData *meta, 2095 const struct GNUNET_FS_MetaData *meta,
2089 const struct GNUNET_FS_Uri *uri, 2096 const struct GNUNET_FS_Uri *uri,
2090 const struct GNUNET_FS_BlockOptions *bo, 2097 const struct GNUNET_FS_BlockOptions *bo,
2091 enum GNUNET_FS_PublishOptions options, 2098 enum GNUNET_FS_PublishOptions options,
@@ -2181,7 +2188,7 @@ typedef void (*GNUNET_FS_IdentifierProcessor) (void *cls,
2181 const struct 2188 const struct
2182 GNUNET_FS_Uri *last_uri, 2189 GNUNET_FS_Uri *last_uri,
2183 const struct 2190 const struct
2184 GNUNET_CONTAINER_MetaData * 2191 GNUNET_FS_MetaData *
2185 last_meta, 2192 last_meta,
2186 const char *next_id); 2193 const char *next_id);
2187 2194
@@ -2291,7 +2298,7 @@ GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2291struct GNUNET_FS_SearchResult * 2298struct GNUNET_FS_SearchResult *
2292GNUNET_FS_probe (struct GNUNET_FS_Handle *h, 2299GNUNET_FS_probe (struct GNUNET_FS_Handle *h,
2293 const struct GNUNET_FS_Uri *uri, 2300 const struct GNUNET_FS_Uri *uri,
2294 const struct GNUNET_CONTAINER_MetaData *meta, 2301 const struct GNUNET_FS_MetaData *meta,
2295 void *client_info, 2302 void *client_info,
2296 uint32_t anonymity); 2303 uint32_t anonymity);
2297 2304
@@ -2379,7 +2386,7 @@ enum GNUNET_FS_DownloadOptions
2379struct GNUNET_FS_DownloadContext * 2386struct GNUNET_FS_DownloadContext *
2380GNUNET_FS_download_start (struct GNUNET_FS_Handle *h, 2387GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
2381 const struct GNUNET_FS_Uri *uri, 2388 const struct GNUNET_FS_Uri *uri,
2382 const struct GNUNET_CONTAINER_MetaData *meta, 2389 const struct GNUNET_FS_MetaData *meta,
2383 const char *filename, const char *tempname, 2390 const char *filename, const char *tempname,
2384 uint64_t offset, uint64_t length, uint32_t anonymity, 2391 uint64_t offset, uint64_t length, uint32_t anonymity,
2385 enum GNUNET_FS_DownloadOptions options, void *cctx, 2392 enum GNUNET_FS_DownloadOptions options, void *cctx,
@@ -2473,7 +2480,7 @@ GNUNET_FS_download_resume (struct GNUNET_FS_DownloadContext *dc);
2473 * we have no mime-type information (treat as #GNUNET_NO) 2480 * we have no mime-type information (treat as #GNUNET_NO)
2474 */ 2481 */
2475int 2482int
2476GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData 2483GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_FS_MetaData
2477 *md); 2484 *md);
2478 2485
2479 2486
@@ -2484,7 +2491,7 @@ GNUNET_FS_meta_data_test_for_directory (const struct GNUNET_CONTAINER_MetaData
2484 * @param md metadata to add mimetype to 2491 * @param md metadata to add mimetype to
2485 */ 2492 */
2486void 2493void
2487GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md); 2494GNUNET_FS_meta_data_make_directory (struct GNUNET_FS_MetaData *md);
2488 2495
2489 2496
2490/** 2497/**
@@ -2495,7 +2502,7 @@ GNUNET_FS_meta_data_make_directory (struct GNUNET_CONTAINER_MetaData *md);
2495 */ 2502 */
2496char * 2503char *
2497GNUNET_FS_meta_data_suggest_filename (const struct 2504GNUNET_FS_meta_data_suggest_filename (const struct
2498 GNUNET_CONTAINER_MetaData *md); 2505 GNUNET_FS_MetaData *md);
2499 2506
2500 2507
2501/** 2508/**
@@ -2518,7 +2525,7 @@ typedef void (*GNUNET_FS_DirectoryEntryProcessor) (void *cls,
2518 const struct GNUNET_FS_Uri * 2525 const struct GNUNET_FS_Uri *
2519 uri, 2526 uri,
2520 const struct 2527 const struct
2521 GNUNET_CONTAINER_MetaData * 2528 GNUNET_FS_MetaData *
2522 meta, size_t length, 2529 meta, size_t length,
2523 const void *data); 2530 const void *data);
2524 2531
@@ -2561,7 +2568,7 @@ struct GNUNET_FS_DirectoryBuilder;
2561 * @param mdir metadata for the directory 2568 * @param mdir metadata for the directory
2562 */ 2569 */
2563struct GNUNET_FS_DirectoryBuilder * 2570struct GNUNET_FS_DirectoryBuilder *
2564GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData 2571GNUNET_FS_directory_builder_create (const struct GNUNET_FS_MetaData
2565 *mdir); 2572 *mdir);
2566 2573
2567 2574
@@ -2578,7 +2585,7 @@ GNUNET_FS_directory_builder_create (const struct GNUNET_CONTAINER_MetaData
2578void 2585void
2579GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld, 2586GNUNET_FS_directory_builder_add (struct GNUNET_FS_DirectoryBuilder *bld,
2580 const struct GNUNET_FS_Uri *uri, 2587 const struct GNUNET_FS_Uri *uri,
2581 const struct GNUNET_CONTAINER_MetaData *md, 2588 const struct GNUNET_FS_MetaData *md,
2582 const void *data); 2589 const void *data);
2583 2590
2584 2591
@@ -2693,7 +2700,7 @@ struct GNUNET_FS_ShareTreeItem
2693 /** 2700 /**
2694 * Metadata for this file or directory 2701 * Metadata for this file or directory
2695 */ 2702 */
2696 struct GNUNET_CONTAINER_MetaData *meta; 2703 struct GNUNET_FS_MetaData *meta;
2697 2704
2698 /** 2705 /**
2699 * Keywords for this file or directory (derived from metadata). 2706 * Keywords for this file or directory (derived from metadata).
@@ -2782,6 +2789,336 @@ GNUNET_FS_share_tree_trim (struct GNUNET_FS_ShareTreeItem *toplevel);
2782void 2789void
2783GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel); 2790GNUNET_FS_share_tree_free (struct GNUNET_FS_ShareTreeItem *toplevel);
2784 2791
2792/**
2793 * Meta data processing
2794 * @defgroup metadata Metadata
2795 * GNU libextractor key-value pairs
2796 */
2797
2798
2799/* ****************** metadata ******************* */
2800
2801
2802/**
2803 * @ingroup metadata
2804 * Create a fresh meta data container.
2805 *
2806 * @return empty meta-data container
2807 */
2808struct GNUNET_FS_MetaData *
2809GNUNET_FS_meta_data_create (void);
2810
2811
2812/**
2813 * @ingroup metadata
2814 * Duplicate a MetaData token.
2815 *
2816 * @param md what to duplicate
2817 * @return duplicate meta-data container
2818 */
2819struct GNUNET_FS_MetaData *
2820GNUNET_FS_meta_data_duplicate (
2821 const struct GNUNET_FS_MetaData *md);
2822
2823
2824/**
2825 * @ingroup metadata
2826 * Free meta data.
2827 *
2828 * @param md what to free
2829 */
2830void
2831GNUNET_FS_meta_data_destroy (struct GNUNET_FS_MetaData *md);
2832
2833
2834/**
2835 * @ingroup metadata
2836 * Test if two MDs are equal. We consider them equal if
2837 * the meta types, formats and content match (we do not
2838 * include the mime types and plugins names in this
2839 * consideration).
2840 *
2841 * @param md1 first value to check
2842 * @param md2 other value to check
2843 * @return #GNUNET_YES if they are equal
2844 */
2845int
2846GNUNET_FS_meta_data_test_equal (
2847 const struct GNUNET_FS_MetaData *md1,
2848 const struct GNUNET_FS_MetaData *md2);
2849
2850
2851/**
2852 * @ingroup metadata
2853 * Extend metadata.
2854 *
2855 * @param md metadata to extend
2856 * @param plugin_name name of the plugin that produced this value;
2857 * special values can be used (e.g. '&lt;zlib&gt;' for zlib being
2858 * used in the main libextractor library and yielding
2859 * meta data).
2860 * @param type libextractor-type describing the meta data
2861 * @param format basic format information about data
2862 * @param data_mime_type mime-type of data (not of the original file);
2863 * can be NULL (if mime-type is not known)
2864 * @param data actual meta-data found
2865 * @param data_size number of bytes in data
2866 * @return #GNUNET_OK on success, #GNUNET_SYSERR if this entry already exists
2867 * data_mime_type and plugin_name are not considered for "exists" checks
2868 */
2869int
2870GNUNET_FS_meta_data_insert (struct GNUNET_FS_MetaData *md,
2871 const char *plugin_name,
2872 enum EXTRACTOR_MetaType type,
2873 enum EXTRACTOR_MetaFormat format,
2874 const char *data_mime_type,
2875 const char *data,
2876 size_t data_size);
2877
2878
2879/**
2880 * @ingroup metadata
2881 * Extend metadata. Merges the meta data from the second argument
2882 * into the first, discarding duplicate key-value pairs.
2883 *
2884 * @param md metadata to extend
2885 * @param in metadata to merge
2886 */
2887void
2888GNUNET_FS_meta_data_merge (struct GNUNET_FS_MetaData *md,
2889 const struct GNUNET_FS_MetaData *in);
2890
2891
2892/**
2893 * @ingroup metadata
2894 * Remove an item.
2895 *
2896 * @param md metadata to manipulate
2897 * @param type type of the item to remove
2898 * @param data specific value to remove, NULL to remove all
2899 * entries of the given type
2900 * @param data_size number of bytes in data
2901 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the item does not exist in md
2902 */
2903int
2904GNUNET_FS_meta_data_delete (struct GNUNET_FS_MetaData *md,
2905 enum EXTRACTOR_MetaType type,
2906 const char *data,
2907 size_t data_size);
2908
2909
2910/**
2911 * @ingroup metadata
2912 * Remove all items in the container.
2913 *
2914 * @param md metadata to manipulate
2915 */
2916void
2917GNUNET_FS_meta_data_clear (struct GNUNET_FS_MetaData *md);
2918
2919
2920/**
2921 * @ingroup metadata
2922 * Add the current time as the publication date
2923 * to the meta-data.
2924 *
2925 * @param md metadata to modify
2926 */
2927void
2928GNUNET_FS_meta_data_add_publication_date (
2929 struct GNUNET_FS_MetaData *md);
2930
2931
2932/**
2933 * @ingroup metadata
2934 * Iterate over MD entries.
2935 *
2936 * @param md metadata to inspect
2937 * @param iter function to call on each entry, return 0 to continue to iterate
2938 * and 1 to abort iteration in this function (GNU libextractor API!)
2939 * @param iter_cls closure for @a iter
2940 * @return number of entries
2941 */
2942int
2943GNUNET_FS_meta_data_iterate (const struct GNUNET_FS_MetaData *md,
2944 EXTRACTOR_MetaDataProcessor iter,
2945 void *iter_cls);
2946
2947
2948/**
2949 * @ingroup metadata
2950 * Get the first MD entry of the given type. Caller
2951 * is responsible for freeing the return value.
2952 * Also, only meta data items that are strings (0-terminated)
2953 * are returned by this function.
2954 *
2955 * @param md metadata to inspect
2956 * @param type type to look for
2957 * @return NULL if no entry was found
2958 */
2959char *
2960GNUNET_FS_meta_data_get_by_type (
2961 const struct GNUNET_FS_MetaData *md,
2962 enum EXTRACTOR_MetaType type);
2963
2964
2965/**
2966 * @ingroup metadata
2967 * Get the first matching MD entry of the given types. Caller is
2968 * responsible for freeing the return value. Also, only meta data
2969 * items that are strings (0-terminated) are returned by this
2970 * function.
2971 *
2972 * @param md metadata to inspect
2973 * @param ... -1-terminated list of types
2974 * @return NULL if we do not have any such entry,
2975 * otherwise client is responsible for freeing the value!
2976 */
2977char *
2978GNUNET_FS_meta_data_get_first_by_types (
2979 const struct GNUNET_FS_MetaData *md,
2980 ...);
2981
2982/**
2983 * @ingroup metadata
2984 * Get a thumbnail from the meta-data (if present). Only matches meta
2985 * data with mime type "image" and binary format.
2986 *
2987 * @param md metadata to inspect
2988 * @param thumb will be set to the thumbnail data. Must be
2989 * freed by the caller!
2990 * @return number of bytes in thumbnail, 0 if not available
2991 */
2992size_t
2993GNUNET_FS_meta_data_get_thumbnail (
2994 const struct GNUNET_FS_MetaData *md,
2995 unsigned char **thumb);
2996
2997
2998/**
2999 * @ingroup metadata
3000 * Options for metadata serialization.
3001 */
3002enum GNUNET_FS_MetaDataSerializationOptions
3003{
3004 /**
3005 * @ingroup metadata
3006 * Serialize all of the data.
3007 */
3008 GNUNET_FS_META_DATA_SERIALIZE_FULL = 0,
3009
3010 /**
3011 * @ingroup metadata
3012 * If not enough space is available, it is acceptable
3013 * to only serialize some of the metadata.
3014 */
3015 GNUNET_FS_META_DATA_SERIALIZE_PART = 1,
3016
3017 /**
3018 * @ingroup metadata
3019 * Speed is of the essence, do not allow compression.
3020 */
3021 GNUNET_FS_META_DATA_SERIALIZE_NO_COMPRESS = 2
3022};
3023
3024
3025/**
3026 * @ingroup metadata
3027 * Serialize meta-data to target.
3028 *
3029 * @param md metadata to serialize
3030 * @param target where to write the serialized metadata;
3031 * *target can be NULL, in which case memory is allocated
3032 * @param max maximum number of bytes available
3033 * @param opt is it ok to just write SOME of the
3034 * meta-data to match the size constraint,
3035 * possibly discarding some data?
3036 * @return number of bytes written on success,
3037 * -1 on error (typically: not enough
3038 * space)
3039 */
3040ssize_t
3041GNUNET_FS_meta_data_serialize (
3042 const struct GNUNET_FS_MetaData *md,
3043 char **target,
3044 size_t max,
3045 enum GNUNET_FS_MetaDataSerializationOptions opt);
3046
3047
3048/**
3049 * @ingroup metadata
3050 * Get the size of the full meta-data in serialized form.
3051 *
3052 * @param md metadata to inspect
3053 * @return number of bytes needed for serialization, -1 on error
3054 */
3055ssize_t
3056GNUNET_FS_meta_data_get_serialized_size (
3057 const struct GNUNET_FS_MetaData *md);
3058
3059
3060/**
3061 * @ingroup metadata
3062 * Deserialize meta-data. Initializes md.
3063 *
3064 * @param input serialized meta-data.
3065 * @param size number of bytes available
3066 * @return MD on success, NULL on error (e.g.
3067 * bad format)
3068 */
3069struct GNUNET_FS_MetaData *
3070GNUNET_FS_meta_data_deserialize (const char *input, size_t size);
3071
3072/**
3073 * Write a metadata container.
3074 *
3075 * @param h the IO handle to write to
3076 * @param what what is being written (for error message creation)
3077 * @param m metadata to write
3078 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
3079 */
3080enum GNUNET_GenericReturnValue
3081GNUNET_FS_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
3082 const char *what,
3083 const struct GNUNET_FS_MetaData *m);
3084
3085/**
3086 * Create the specification to read a metadata container.
3087 *
3088 * @param what describes what is being read (for error message creation)
3089 * @param result the buffer to store a pointer to the (allocated) metadata
3090 * @return the read spec
3091 */
3092struct GNUNET_BIO_ReadSpec
3093GNUNET_FS_read_spec_meta_data (const char *what,
3094 struct GNUNET_FS_MetaData **result);
3095
3096
3097
3098/**
3099 * Create the specification to write a metadata container.
3100 *
3101 * @param what what is being written (for error message creation)
3102 * @param m metadata to write
3103 * @return the write spec
3104 */
3105struct GNUNET_BIO_WriteSpec
3106GNUNET_FS_write_spec_meta_data (const char *what,
3107 const struct GNUNET_FS_MetaData *m);
3108
3109/**
3110 * Read a metadata container.
3111 *
3112 * @param h handle to an open file
3113 * @param what describes what is being read (for error message creation)
3114 * @param result the buffer to store a pointer to the (allocated) metadata
3115 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
3116 */
3117enum GNUNET_GenericReturnValue
3118GNUNET_FS_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
3119 const char *what,
3120 struct GNUNET_FS_MetaData **result);
3121
2785 3122
2786#if 0 /* keep Emacsens' auto-indent happy */ 3123#if 0 /* keep Emacsens' auto-indent happy */
2787{ 3124{
diff --git a/src/include/gnunet_mysql_compat.h b/src/include/gnunet_mysql_compat.h
new file mode 100644
index 000000000..bb1e8de8a
--- /dev/null
+++ b/src/include/gnunet_mysql_compat.h
@@ -0,0 +1,63 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 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 */
20/**
21 * @author Martin Schanzenbach
22 *
23 * @file
24 * MySQL/MariaDB compatibility insanity helper header
25 *
26 * @defgroup mysql MySQL library
27 * Helper library to access a MySQL database.
28 * @{
29 */
30#ifndef GNUNET_MYSQL_COMPAT_H
31#define GNUNET_MYSQL_COMPAT_H
32
33
34#include <mysql/mysql.h>
35
36#ifdef __cplusplus
37extern "C"
38{
39#if 0 /* keep Emacsens' auto-indent happy */
40}
41#endif
42#endif
43
44#ifndef LIBMARIADB
45#if MYSQL_VERSION_ID < 80000
46#define MYSQL_BOOL bool;
47#else
48#define MYSQL_BOOL my_bool; //MySQL < 8 wants this
49#endif
50#else
51#define MYSQL_BOOL my_bool //MariaDB still uses my_bool
52#endif
53
54#if 0 /* keep Emacsens' auto-indent happy */
55{
56#endif
57#ifdef __cplusplus
58}
59#endif
60
61#endif
62
63/** @} */ /* end of group */
diff --git a/src/include/gnunet_util_lib.h b/src/include/gnunet_util_lib.h
index 52fa5c373..337552a0c 100644
--- a/src/include/gnunet_util_lib.h
+++ b/src/include/gnunet_util_lib.h
@@ -92,6 +92,43 @@ extern "C"
92#include "gnunet_child_management_lib.h" 92#include "gnunet_child_management_lib.h"
93#include "gnunet_error_codes.h" 93#include "gnunet_error_codes.h"
94 94
95/**
96 * Try to compress the given block of data using libz. Only returns
97 * the compressed block if compression worked and the new block is
98 * actually smaller. Decompress using #GNUNET_decompress().
99 *
100 * @param data block to compress; if compression
101 * resulted in a smaller block, the first
102 * bytes of data are updated to the compressed
103 * data
104 * @param old_size number of bytes in data
105 * @param[out] result set to the compressed data, if compression worked
106 * @param[out] new_size set to size of result, if compression worked
107 * @return #GNUNET_YES if compression reduce the size,
108 * #GNUNET_NO if compression did not help
109 */
110int
111GNUNET_try_compression (const char *data,
112 size_t old_size,
113 char **result,
114 size_t *new_size);
115
116/**
117 * Decompress input, return the decompressed data as output. Dual to
118 * #GNUNET_try_compression(). Caller must set @a output_size to the
119 * number of bytes that were originally compressed.
120 *
121 * @param input compressed data
122 * @param input_size number of bytes in input
123 * @param output_size expected size of the output
124 * @return NULL on error, buffer of @a output_size decompressed bytes otherwise
125 */
126char *
127GNUNET_decompress (const char *input,
128 size_t input_size,
129 size_t output_size);
130
131
95#if 0 /* keep Emacsens' auto-indent happy */ 132#if 0 /* keep Emacsens' auto-indent happy */
96{ 133{
97#endif 134#endif