gnunet_gnsrecord_plugin.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2012, 2013 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  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. #ifdef __cplusplus
  32. extern "C"
  33. {
  34. #if 0 /* keep Emacsens' auto-indent happy */
  35. }
  36. #endif
  37. #endif
  38. /**
  39. * Function called to convert the binary value @a data of a record of
  40. * type @a type to a human-readable string.
  41. *
  42. * @param cls closure
  43. * @param type type of the record
  44. * @param data value in binary encoding
  45. * @param data_size number of bytes in @a data
  46. * @return NULL on error, otherwise human-readable representation of the value
  47. */
  48. typedef char *
  49. (*GNUNET_GNSRECORD_ValueToStringFunction) (void *cls,
  50. uint32_t type,
  51. const void *data,
  52. size_t data_size);
  53. /**
  54. * Function called to convert human-readable version of the value @a s
  55. * of a record of type @a type to the respective binary
  56. * representation.
  57. *
  58. * @param cls closure
  59. * @param type type of the record
  60. * @param s human-readable string
  61. * @param data set to value in binary encoding (will be allocated)
  62. * @param data_size set to number of bytes in @a data
  63. * @return #GNUNET_OK on success
  64. */
  65. typedef int
  66. (*GNUNET_GNSRECORD_StringToValueFunction) (void *cls,
  67. uint32_t type,
  68. const char *s,
  69. void **data,
  70. size_t *data_size);
  71. /**
  72. * Function called to convert a type name (i.e. "AAAA") to the
  73. * corresponding number.
  74. *
  75. * @param cls closure
  76. * @param dns_typename name to convert
  77. * @return corresponding number, UINT32_MAX on error
  78. */
  79. typedef uint32_t
  80. (*GNUNET_GNSRECORD_TypenameToNumberFunction) (void *cls,
  81. const char *dns_typename);
  82. /**
  83. * Function called to convert a type number (i.e. 1) to the
  84. * corresponding type string (i.e. "A")
  85. *
  86. * @param cls closure
  87. * @param type number of a type to convert
  88. * @return corresponding typestring, NULL on error
  89. */
  90. typedef const char *
  91. (*GNUNET_GNSRECORD_NumberToTypenameFunction) (void *cls,
  92. uint32_t type);
  93. /**
  94. * Each plugin is required to return a pointer to a struct of this
  95. * type as the return value from its entry point.
  96. */
  97. struct GNUNET_GNSRECORD_PluginFunctions
  98. {
  99. /**
  100. * Closure for all of the callbacks.
  101. */
  102. void *cls;
  103. /**
  104. * Conversion to string.
  105. */
  106. GNUNET_GNSRECORD_ValueToStringFunction value_to_string;
  107. /**
  108. * Conversion to binary.
  109. */
  110. GNUNET_GNSRECORD_StringToValueFunction string_to_value;
  111. /**
  112. * Typename to number.
  113. */
  114. GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number;
  115. /**
  116. * Number to typename.
  117. */
  118. GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename;
  119. };
  120. /** @} */ /* end of group */
  121. #if 0 /* keep Emacsens' auto-indent happy */
  122. {
  123. #endif
  124. #ifdef __cplusplus
  125. }
  126. #endif
  127. #endif