internal.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * David M. Lee, II <dlee@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. #ifndef ARI_INTERNAL_H_
  19. #define ARI_INTERNAL_H_
  20. /*! \file
  21. *
  22. * \brief Internal API's for res_ari.
  23. * \author David M. Lee, II <dlee@digium.com>
  24. */
  25. #include "asterisk/http.h"
  26. #include "asterisk/json.h"
  27. #include "asterisk/stringfields.h"
  28. /*! @{ */
  29. /*!
  30. * \brief Register CLI commands for ARI.
  31. *
  32. * \return 0 on success.
  33. * \return Non-zero on error.
  34. */
  35. int ast_ari_cli_register(void);
  36. /*!
  37. * \brief Unregister CLI commands for ARI.
  38. */
  39. void ast_ari_cli_unregister(void);
  40. /*! @} */
  41. /*! @{ */
  42. struct ast_ari_conf_general;
  43. /*! \brief All configuration options for ARI. */
  44. struct ast_ari_conf {
  45. /*! The general section configuration options. */
  46. struct ast_ari_conf_general *general;
  47. /*! Configured users */
  48. struct ao2_container *users;
  49. };
  50. /*! Max length for auth_realm field */
  51. #define ARI_AUTH_REALM_LEN 80
  52. /*! \brief Global configuration options for ARI. */
  53. struct ast_ari_conf_general {
  54. /*! Enabled by default, disabled if false. */
  55. int enabled;
  56. /*! Write timeout for websocket connections */
  57. int write_timeout;
  58. /*! Encoding format used during output (default compact). */
  59. enum ast_json_encoding_format format;
  60. /*! Authentication realm */
  61. char auth_realm[ARI_AUTH_REALM_LEN];
  62. AST_DECLARE_STRING_FIELDS(
  63. AST_STRING_FIELD(allowed_origins);
  64. );
  65. };
  66. /*! \brief Password format */
  67. enum ast_ari_password_format {
  68. /*! \brief Plaintext password */
  69. ARI_PASSWORD_FORMAT_PLAIN,
  70. /*! crypt(3) password */
  71. ARI_PASSWORD_FORMAT_CRYPT,
  72. };
  73. /*!
  74. * \brief User's password mx length.
  75. *
  76. * If 256 seems like a lot, a crypt SHA-512 has over 106 characters.
  77. */
  78. #define ARI_PASSWORD_LEN 256
  79. /*! \brief Per-user configuration options */
  80. struct ast_ari_conf_user {
  81. /*! Username for authentication */
  82. char *username;
  83. /*! User's password. */
  84. char password[ARI_PASSWORD_LEN];
  85. /*! Format for the password field */
  86. enum ast_ari_password_format password_format;
  87. /*! If true, user cannot execute change operations */
  88. int read_only;
  89. };
  90. /*!
  91. * \brief Initialize the ARI configuration
  92. */
  93. int ast_ari_config_init(void);
  94. /*!
  95. * \brief Reload the ARI configuration
  96. */
  97. int ast_ari_config_reload(void);
  98. /*!
  99. * \brief Destroy the ARI configuration
  100. */
  101. void ast_ari_config_destroy(void);
  102. /*!
  103. * \brief Get the current ARI configuration.
  104. *
  105. * This is an immutable object, so don't modify it. It is AO2 managed, so
  106. * ao2_cleanup() when you're done with it.
  107. *
  108. * \return ARI configuration object.
  109. * \return \c NULL on error.
  110. */
  111. struct ast_ari_conf *ast_ari_config_get(void);
  112. /*!
  113. * \brief Validated a user's credentials.
  114. *
  115. * \param username Name of the user.
  116. * \param password User's password.
  117. * \return User object.
  118. * \return \c NULL if username or password is invalid.
  119. */
  120. struct ast_ari_conf_user *ast_ari_config_validate_user(const char *username,
  121. const char *password);
  122. /*! @} */
  123. /* Forward-declare websocket structs. This avoids including http_websocket.h,
  124. * which causes optional_api stuff to happen, which makes optional_api more
  125. * difficult to debug. */
  126. struct ast_websocket_server;
  127. /*!
  128. * \brief Wrapper for invoking the websocket code for an incoming connection.
  129. *
  130. * \param ws_server WebSocket server to invoke.
  131. * \param ser HTTP session.
  132. * \param uri Requested URI.
  133. * \param method Requested HTTP method.
  134. * \param get_params Parsed query parameters.
  135. * \param headers Parsed HTTP headers.
  136. */
  137. void ari_handle_websocket(struct ast_websocket_server *ws_server,
  138. struct ast_tcptls_session_instance *ser, const char *uri,
  139. enum ast_http_method method, struct ast_variable *get_params,
  140. struct ast_variable *headers);
  141. #endif /* ARI_INTERNAL_H_ */