gnunet_rest_lib.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2010-2015 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 Martin Schanzenbach
  18. *
  19. * @file
  20. * API for helper library to parse/create REST
  21. *
  22. * @defgroup rest REST library
  23. * Helper library to parse/create REST
  24. * @{
  25. */
  26. #ifndef GNUNET_REST_LIB_H
  27. #define GNUNET_REST_LIB_H
  28. #include "gnunet_util_lib.h"
  29. #include <microhttpd.h>
  30. #define GNUNET_REST_HANDLER_END { NULL, NULL, NULL }
  31. struct GNUNET_REST_RequestHandle
  32. {
  33. /**
  34. * Map of url parameters
  35. */
  36. struct GNUNET_CONTAINER_MultiHashMap *url_param_map;
  37. /**
  38. * Map of headers
  39. */
  40. struct GNUNET_CONTAINER_MultiHashMap *header_param_map;
  41. /**
  42. * The HTTP method as MHD value (see microhttpd.h)
  43. */
  44. const char *method;
  45. /**
  46. * The url as string
  47. */
  48. const char *url;
  49. /**
  50. * The POST data
  51. */
  52. const char *data;
  53. /**
  54. * The POST data size
  55. */
  56. size_t data_size;
  57. };
  58. struct GNUNET_REST_RequestHandlerError
  59. {
  60. int error_code;
  61. char*error_text;
  62. };
  63. struct GNUNET_REST_RequestHandler
  64. {
  65. /**
  66. * Http method to handle
  67. */
  68. const char *method;
  69. /**
  70. * Namespace to handle
  71. */
  72. const char *namespace;
  73. /**
  74. * callback handler
  75. */
  76. void (*proc) (struct GNUNET_REST_RequestHandle *handle,
  77. const char *url,
  78. void *cls);
  79. };
  80. /**
  81. * Iterator called on obtained result for a REST result.
  82. *
  83. * @param cls closure
  84. * @param resp the response
  85. * @param status status code (HTTP)
  86. */
  87. typedef void (*GNUNET_REST_ResultProcessor) (void *cls,
  88. struct MHD_Response *resp,
  89. int status);
  90. /**
  91. * Check if namespace is in URL.
  92. *
  93. * @param url URL to check
  94. * @param namespace namespace to check against
  95. * @return GNUNET_YES if namespace matches
  96. */
  97. int
  98. GNUNET_REST_namespace_match (const char *url, const char *namespace);
  99. /**
  100. * Create REST MHD response
  101. *
  102. * @param data result
  103. * @return MHD response
  104. */
  105. struct MHD_Response*
  106. GNUNET_REST_create_response (const char *data);
  107. int
  108. GNUNET_REST_handle_request (struct GNUNET_REST_RequestHandle *conn,
  109. const struct GNUNET_REST_RequestHandler *handlers,
  110. struct GNUNET_REST_RequestHandlerError *err,
  111. void *cls);
  112. #endif
  113. /** @} */ /* end of group */