AdminClient.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef AdminClient_H
  16. #define AdminClient_H
  17. #include "benc/String.h"
  18. #include "benc/Dict.h"
  19. #include "memory/Allocator.h"
  20. #include "util/log/Log.h"
  21. #include "util/events/EventBase.h"
  22. #include "util/platform/Sockaddr.h"
  23. enum AdminClient_Error
  24. {
  25. /** Success. */
  26. AdminClient_Error_NONE = 0,
  27. /** Response was longer than max message size. */
  28. AdminClient_Error_OVERLONG_RESPONSE,
  29. /** Error on recv(), causes result.errno to be set. */
  30. AdminClient_Error_ERROR_READING_FROM_SOCKET,
  31. /** No data on socket. */
  32. AdminClient_Error_SOCKET_NOT_READY,
  33. /** Failed to deserialize response. */
  34. AdminClient_Error_DESERIALIZATION_FAILED,
  35. /** Failed to serialize request. */
  36. AdminClient_Error_SERIALIZATION_FAILED,
  37. /** Timeout waiting for response. */
  38. AdminClient_Error_TIMEOUT,
  39. /** Requested cookie and response did not contain cookie. */
  40. AdminClient_Error_NO_COOKIE,
  41. };
  42. /** The biggest message that can be sent or received. */
  43. #define AdminClient_MAX_MESSAGE_SIZE 1023
  44. /** The amount of message padding. */
  45. #define AdminClient_Result_PADDING_SIZE (sizeof(struct Sockaddr_storage))
  46. struct AdminClient_Result
  47. {
  48. /** The error type of AdminClient_Error_NONE if there was no error. */
  49. enum AdminClient_Error err;
  50. /** Space to put the address of the node which the response is being sent to. */
  51. uint8_t padding[AdminClient_Result_PADDING_SIZE];
  52. /**
  53. * When the request is made, this will hold the request bytes,
  54. * after it will hold the response bytes. If there is an error
  55. * during the sending of the request, it will still have the request bytes.
  56. * 1 byte extra to alow for a null terminator.
  57. */
  58. uint8_t messageBytes[AdminClient_MAX_MESSAGE_SIZE + 1];
  59. /** The deserialized response. */
  60. Dict* responseDict;
  61. };
  62. struct AdminClient
  63. {
  64. /** How long to wait for a response from the cjdns node. */
  65. uint32_t millisecondsToWait;
  66. };
  67. char* AdminClient_errorString(enum AdminClient_Error err);
  68. struct AdminClient_Result* AdminClient_rpcCall(String* function,
  69. Dict* args,
  70. struct AdminClient* client,
  71. struct Allocator* requestAlloc);
  72. struct AdminClient* AdminClient_new(struct Sockaddr* addr,
  73. String* adminPassword,
  74. struct EventBase* eventBase,
  75. struct Log* logger,
  76. struct Allocator* alloc);
  77. #endif