gnunet-android

GNUnet for Android
Log | Files | Refs | README

gnunet_gnsrecord_plugin.h (4554B)


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