Debian Codegraph @

res/ari/internal.h

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2013, Digium, Inc.
5 *
6 * David M. Lee, II <[email protected]>
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
19 #ifndef ARI_INTERNAL_H_
20 #define ARI_INTERNAL_H_
21
22 /*! \file
23 *
24 * \brief Internal API's for res_ari.
25 * \author David M. Lee, II <[email protected]>
26 */
27
28 #include "asterisk/acl.h"
29 #include "asterisk/http.h"
30 #include "asterisk/json.h"
31 #include "asterisk/md5.h"
32 #include "asterisk/sorcery.h"
33 #include "asterisk/stringfields.h"
34 #include "asterisk/websocket_client.h"
35 #include "ari_websockets.h"
36
37
38 /*! @{ */
39
40 /*!
41 * \brief Register CLI commands for ARI.
42 *
43 * \return 0 on success.
44 * \return Non-zero on error.
45 */
46 int ari_cli_register(void);
47
48 /*!
49 * \brief Unregister CLI commands for ARI.
50 */
51 void ari_cli_unregister(void);
52
53 /*! @} */
54
55 /*! @{ */
56
57 /*! \brief Global configuration options for ARI. */
58 struct ari_conf_general {
59 SORCERY_OBJECT(details);
60 AST_DECLARE_STRING_FIELDS(
61 /*! Allowed CORS origins */
62 AST_STRING_FIELD(allowed_origins);
63 /*! Authentication realm */
64 AST_STRING_FIELD(auth_realm);
65 /*! Channel variables */
66 AST_STRING_FIELD(channelvars);
67 );
68 /*! Enabled by default, disabled if false. */
69 int enabled;
70 /*! Write timeout for websocket connections */
71 int write_timeout;
72 /*! Encoding format used during output (default compact). */
73 enum ast_json_encoding_format format;
74 };
75
76 /*! \brief Password format */
77 enum ari_user_password_format {
78 /*! \brief Plaintext password */
79 ARI_PASSWORD_FORMAT_PLAIN,
80 /*! crypt(3) password */
81 ARI_PASSWORD_FORMAT_CRYPT,
82 };
83
84 /*! \brief Per-user configuration options */
85 struct ari_conf_user {
86 SORCERY_OBJECT(details);
87 AST_DECLARE_STRING_FIELDS(
88 /*! User's password. */
89 AST_STRING_FIELD(password);
90 );
91 /*! Format for the password field */
92 enum ari_user_password_format password_format;
93 /*! If true, user cannot execute change operations */
94 int read_only;
95 /*! ACL setting */
96 struct ast_acl_list *acl;
97 };
98
99 enum ari_conf_owc_fields {
100 ARI_OWC_FIELD_NONE = 0,
101 ARI_OWC_FIELD_WEBSOCKET_CONNECTION_ID = (1 << AST_WS_CLIENT_FIELD_USER_START),
102 ARI_OWC_FIELD_APPS = (1 << (AST_WS_CLIENT_FIELD_USER_START + 1)),
103 ARI_OWC_FIELD_LOCAL_ARI_USER = (1 << (AST_WS_CLIENT_FIELD_USER_START + 2)),
104 ARI_OWC_FIELD_LOCAL_ARI_PASSWORD = (1 << (AST_WS_CLIENT_FIELD_USER_START + 3)),
105 ARI_OWC_FIELD_SUBSCRIBE_ALL = (1 << (AST_WS_CLIENT_FIELD_USER_START + 4)),
106 ARI_OWC_NEEDS_RECONNECT = AST_WS_CLIENT_NEEDS_RECONNECT
107 | ARI_OWC_FIELD_WEBSOCKET_CONNECTION_ID | ARI_OWC_FIELD_LOCAL_ARI_USER
108 | ARI_OWC_FIELD_LOCAL_ARI_PASSWORD,
109 ARI_OWC_NEEDS_REREGISTER = ARI_OWC_FIELD_APPS | ARI_OWC_FIELD_SUBSCRIBE_ALL,
110 };
111
112 struct ari_conf_outbound_websocket {
113 SORCERY_OBJECT(details);
114 AST_DECLARE_STRING_FIELDS(
115 AST_STRING_FIELD(websocket_client_id); /*!< The ID of the websocket client to use */
116 AST_STRING_FIELD(apps); /*!< Stasis apps using this connection */
117 AST_STRING_FIELD(local_ari_user);/*!< The ARI user to act as */
118 AST_STRING_FIELD(local_ari_password); /*!< The password for the ARI user */
119 );
120 int invalid; /*!< Invalid configuration */
121 int subscribe_all; /*!< Subscribe to all events */
122 struct ast_websocket_client *websocket_client; /*!< The websocket client */
123 };
124
125 /*!
126 * \brief Detect changes between two outbound websocket configurations.
127 *
128 * \param old_owc The old outbound websocket configuration.
129 * \param new_owc The new outbound websocket configuration.
130 * \return A bitmask of changed fields.
131 */
132 enum ari_conf_owc_fields ari_conf_owc_detect_changes(
133 struct ari_conf_outbound_websocket *old_owc,
134 struct ari_conf_outbound_websocket *new_owc);
135
136 /*!
137 * \brief Get the outbound websocket configuration for a Stasis app.
138 *
139 * \param app_name The application name to search for.
140 * \param ws_type An OR'd list of ari_websocket_types or ARI_WS_TYPE_ANY.
141 *
142 * \retval ARI outbound websocket configuration object.
143 * \retval NULL if not found.
144 */
145 struct ari_conf_outbound_websocket *ari_conf_get_owc_for_app(
146 const char *app_name, unsigned int ws_type);
147
148 enum ari_conf_load_flags {
149 ARI_CONF_INIT = (1 << 0), /*!< Initialize sorcery */
150 ARI_CONF_RELOAD = (1 << 1), /*!< Reload sorcery */
151 ARI_CONF_LOAD_GENERAL = (1 << 2), /*!< Load general config */
152 ARI_CONF_LOAD_USER = (1 << 3), /*!< Load user config */
153 ARI_CONF_LOAD_OWC = (1 << 4), /*!< Load outbound websocket config */
154 ARI_CONF_LOAD_ALL = ( /*!< Load all configs */
155 ARI_CONF_LOAD_GENERAL
156 | ARI_CONF_LOAD_USER
157 | ARI_CONF_LOAD_OWC),
158 };
159
160 /*!
161 * \brief (Re)load the ARI configuration
162 */
163 int ari_conf_load(enum ari_conf_load_flags flags);
164
165 /*!
166 * \brief Destroy the ARI configuration
167 */
168 void ari_conf_destroy(void);
169
170 struct ari_conf_general* ari_conf_get_general(void);
171 struct ao2_container *ari_conf_get_users(void);
172 struct ari_conf_user *ari_conf_get_user(const char *username);
173 struct ao2_container *ari_conf_get_owcs(void);
174 struct ari_conf_outbound_websocket *ari_conf_get_owc(const char *id);
175 enum ari_conf_owc_fields ari_conf_owc_get_invalid_fields(const char *id);
176 const char *ari_websocket_type_to_str(enum ast_websocket_type type);
177 int ari_sorcery_observer_add(const char *object_type,
178 const struct ast_sorcery_observer *callbacks);
179 int ari_sorcery_observer_remove(const char *object_type,
180 const struct ast_sorcery_observer *callbacks);
181
182 /*!
183 * \brief Validated a user's credentials.
184 *
185 * \param username Name of the user.
186 * \param password User's password.
187 * \return User object.
188 * \retval NULL if username or password is invalid.
189 */
190 struct ari_conf_user *ari_conf_validate_user(const char *username,
191 const char *password);
192
193 /*! @} */
194
195 #endif /* ARI_INTERNAL_H_ */