header
[oweals/gnunet.git] / src / include / gnunet_gnsrecord_plugin.h
1 /*
2      This file is part of GNUnet
3      (C) 2012, 2013 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file include/gnunet_gnsrecord_plugin.h
23  * @brief plugin API for GNS record types
24  * @author Christian Grothoff
25  * @defgroup gnsrecordplugin API to be implemented by applications defining new GNS record types
26  * @{ */
27 #ifndef GNUNET_GNSRECORD_PLUGIN_H
28 #define GNUNET_GNSRECORD_PLUGIN_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38
39 /**
40  * Function called to convert the binary value @a data of a record of
41  * type @a type to a human-readable string.
42  *
43  * @param cls closure
44  * @param type type of the record
45  * @param data value in binary encoding
46  * @param data_size number of bytes in @a data
47  * @return NULL on error, otherwise human-readable representation of the value
48  */
49 typedef char * (*GNUNET_GNSRECORD_ValueToStringFunction) (void *cls,
50                                                           uint32_t type,
51                                                           const void *data,
52                                                           size_t data_size);
53
54
55 /**
56  * Function called to convert human-readable version of the value @a s
57  * of a record of type @a type to the respective binary
58  * representation.
59  *
60  * @param cls closure
61  * @param type type of the record
62  * @param s human-readable string
63  * @param data set to value in binary encoding (will be allocated)
64  * @param data_size set to number of bytes in @a data
65  * @return #GNUNET_OK on success
66  */
67 typedef int (*GNUNET_GNSRECORD_StringToValueFunction) (void *cls,
68                                                        uint32_t type,
69                                                        const char *s,
70                                                        void **data,
71                                                        size_t *data_size);
72
73
74 /**
75  * Function called to convert a type name (i.e. "AAAA") to the
76  * corresponding number.
77  *
78  * @param cls closure
79  * @param dns_typename name to convert
80  * @return corresponding number, UINT32_MAX on error
81  */
82 typedef uint32_t (*GNUNET_GNSRECORD_TypenameToNumberFunction) (void *cls,
83                                                                const char *dns_typename);
84
85
86 /**
87  * Function called to convert a type number (i.e. 1) to the
88  * corresponding type string (i.e. "A")
89  *
90  * @param cls closure
91  * @param type number of a type to convert
92  * @return corresponding typestring, NULL on error
93  */
94 typedef const char * (*GNUNET_GNSRECORD_NumberToTypenameFunction) (void *cls,
95                                                                    uint32_t type);
96
97
98 /**
99  * Each plugin is required to return a pointer to a struct of this
100  * type as the return value from its entry point.
101  */
102 struct GNUNET_GNSRECORD_PluginFunctions
103 {
104
105   /**
106    * Closure for all of the callbacks.
107    */
108   void *cls;
109
110   /**
111    * Conversion to string.
112    */
113   GNUNET_GNSRECORD_ValueToStringFunction value_to_string;
114
115   /**
116    * Conversion to binary.
117    */
118   GNUNET_GNSRECORD_StringToValueFunction string_to_value;
119
120   /**
121    * Typename to number.
122    */
123   GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number;
124
125   /**
126    * Number to typename.
127    */
128   GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename;
129
130 };
131
132
133 /** @} */ /* end of group gnsrecordplugin */
134
135 #if 0                           /* keep Emacsens' auto-indent happy */
136 {
137 #endif
138 #ifdef __cplusplus
139 }
140 #endif
141
142 #endif