uncrustify as demanded.
[oweals/gnunet.git] / src / include / gnunet_gnsrecord_plugin.h
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2012, 2013 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 /**
22  * @author Christian Grothoff
23  *
24  * @file
25  * Plugin API for GNS record types
26  *
27  * @defgroup gnsrecord-plugin  GNS Record plugin API
28  * To be implemented by applications defining new record types.
29  *
30  * @see [Documentation](https://gnunet.org/gns-plugins)
31  *
32  * @{
33  */
34 #ifndef GNUNET_GNSRECORD_PLUGIN_H
35 #define GNUNET_GNSRECORD_PLUGIN_H
36
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #if 0                           /* keep Emacsens' auto-indent happy */
41 }
42 #endif
43 #endif
44
45
46 /**
47  * Function called to convert the binary value @a data of a record of
48  * type @a type to a human-readable string.
49  *
50  * @param cls closure
51  * @param type type of the record
52  * @param data value in binary encoding
53  * @param data_size number of bytes in @a data
54  * @return NULL on error, otherwise human-readable representation of the value
55  */
56 typedef char *
57 (*GNUNET_GNSRECORD_ValueToStringFunction) (void *cls,
58                                            uint32_t type,
59                                            const void *data,
60                                            size_t data_size);
61
62
63 /**
64  * Function called to convert human-readable version of the value @a s
65  * of a record of type @a type to the respective binary
66  * representation.
67  *
68  * @param cls closure
69  * @param type type of the record
70  * @param s human-readable string
71  * @param data set to value in binary encoding (will be allocated)
72  * @param data_size set to number of bytes in @a data
73  * @return #GNUNET_OK on success
74  */
75 typedef int
76 (*GNUNET_GNSRECORD_StringToValueFunction) (void *cls,
77                                            uint32_t type,
78                                            const char *s,
79                                            void **data,
80                                            size_t *data_size);
81
82
83 /**
84  * Function called to convert a type name (i.e. "AAAA") to the
85  * corresponding number.
86  *
87  * @param cls closure
88  * @param dns_typename name to convert
89  * @return corresponding number, UINT32_MAX on error
90  */
91 typedef uint32_t
92 (*GNUNET_GNSRECORD_TypenameToNumberFunction) (void *cls,
93                                               const char *dns_typename);
94
95
96 /**
97  * Function called to convert a type number (i.e. 1) to the
98  * corresponding type string (i.e. "A")
99  *
100  * @param cls closure
101  * @param type number of a type to convert
102  * @return corresponding typestring, NULL on error
103  */
104 typedef const char *
105 (*GNUNET_GNSRECORD_NumberToTypenameFunction) (void *cls,
106                                               uint32_t type);
107
108
109 /**
110  * Each plugin is required to return a pointer to a struct of this
111  * type as the return value from its entry point.
112  */
113 struct GNUNET_GNSRECORD_PluginFunctions {
114   /**
115    * Closure for all of the callbacks.
116    */
117   void *cls;
118
119   /**
120    * Conversion to string.
121    */
122   GNUNET_GNSRECORD_ValueToStringFunction value_to_string;
123
124   /**
125    * Conversion to binary.
126    */
127   GNUNET_GNSRECORD_StringToValueFunction string_to_value;
128
129   /**
130    * Typename to number.
131    */
132   GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number;
133
134   /**
135    * Number to typename.
136    */
137   GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename;
138 };
139
140 /** @} */  /* end of group */
141
142 #if 0                           /* keep Emacsens' auto-indent happy */
143 {
144 #endif
145 #ifdef __cplusplus
146 }
147 #endif
148
149 #endif