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