Asterisk - The Open Source Telephony Project  18.5.0
internal.h
Go to the documentation of this file.
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/http.h"
29 #include "asterisk/json.h"
30 #include "asterisk/stringfields.h"
31 
32 /*! @{ */
33 
34 /*!
35  * \brief Register CLI commands for ARI.
36  *
37  * \return 0 on success.
38  * \return Non-zero on error.
39  */
40 int ast_ari_cli_register(void);
41 
42 /*!
43  * \brief Unregister CLI commands for ARI.
44  */
45 void ast_ari_cli_unregister(void);
46 
47 /*! @} */
48 
49 /*! @{ */
50 
52 
53 /*! \brief All configuration options for ARI. */
54 struct ast_ari_conf {
55  /*! The general section configuration options. */
57  /*! Configured users */
59 };
60 
61 /*! Max length for auth_realm field */
62 #define ARI_AUTH_REALM_LEN 80
63 
64 /*! \brief Global configuration options for ARI. */
66  /*! Enabled by default, disabled if false. */
67  int enabled;
68  /*! Write timeout for websocket connections */
70  /*! Encoding format used during output (default compact). */
72  /*! Authentication realm */
73  char auth_realm[ARI_AUTH_REALM_LEN];
74 
76  AST_STRING_FIELD(allowed_origins);
77  );
78 };
79 
80 /*! \brief Password format */
82  /*! \brief Plaintext password */
84  /*! crypt(3) password */
86 };
87 
88 /*!
89  * \brief User's password mx length.
90  *
91  * If 256 seems like a lot, a crypt SHA-512 has over 106 characters.
92  */
93 #define ARI_PASSWORD_LEN 256
94 
95 /*! \brief Per-user configuration options */
97  /*! Username for authentication */
98  char *username;
99  /*! User's password. */
101  /*! Format for the password field */
102  enum ast_ari_password_format password_format;
103  /*! If true, user cannot execute change operations */
105 };
106 
107 /*!
108  * \brief Initialize the ARI configuration
109  */
110 int ast_ari_config_init(void);
111 
112 /*!
113  * \brief Reload the ARI configuration
114  */
115 int ast_ari_config_reload(void);
116 
117 /*!
118  * \brief Destroy the ARI configuration
119  */
120 void ast_ari_config_destroy(void);
121 
122 /*!
123  * \brief Get the current ARI configuration.
124  *
125  * This is an immutable object, so don't modify it. It is AO2 managed, so
126  * ao2_cleanup() when you're done with it.
127  *
128  * \return ARI configuration object.
129  * \return \c NULL on error.
130  */
131 struct ast_ari_conf *ast_ari_config_get(void);
132 
133 /*!
134  * \brief Validated a user's credentials.
135  *
136  * \param username Name of the user.
137  * \param password User's password.
138  * \return User object.
139  * \return \c NULL if username or password is invalid.
140  */
142  const char *password);
143 
144 /*! @} */
145 
146 /* Forward-declare websocket structs. This avoids including http_websocket.h,
147  * which causes optional_api stuff to happen, which makes optional_api more
148  * difficult to debug. */
149 
150 struct ast_websocket_server;
151 
152 /*!
153  * \brief Wrapper for invoking the websocket code for an incoming connection.
154  *
155  * \param ws_server WebSocket server to invoke.
156  * \param ser HTTP session.
157  * \param uri Requested URI.
158  * \param method Requested HTTP method.
159  * \param get_params Parsed query parameters.
160  * \param headers Parsed HTTP headers.
161  */
162 void ari_handle_websocket(struct ast_websocket_server *ws_server,
163  struct ast_tcptls_session_instance *ser, const char *uri,
164  enum ast_http_method method, struct ast_variable *get_params,
165  struct ast_variable *headers);
166 
167 #endif /* ARI_INTERNAL_H_ */
ast_ari_password_format
Password format.
Definition: internal.h:81
struct ast_ari_conf_user * ast_ari_config_validate_user(const char *username, const char *password)
Validated a user&#39;s credentials.
Structure for a WebSocket server.
struct ast_ari_conf_general * general
Definition: internal.h:56
All configuration options for ARI.
Definition: internal.h:54
int ast_ari_config_reload(void)
Reload the ARI configuration.
Structure for variables, used for configurations and for channel variables.
#define ARI_PASSWORD_LEN
User&#39;s password mx length.
Definition: internal.h:93
char * username
Definition: internal.h:98
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
Definition: stringfields.h:337
Plaintext password.
Definition: internal.h:83
void ast_ari_cli_unregister(void)
Unregister CLI commands for ARI.
Definition: res/ari/cli.c:438
static struct ast_str * password
Definition: cdr_mysql.c:77
Support for Private Asterisk HTTP Servers.
Global configuration options for ARI.
Definition: internal.h:65
Asterisk JSON abstraction layer.
#define ARI_AUTH_REALM_LEN
Definition: internal.h:62
#define AST_STRING_FIELD(name)
Declare a string field.
Definition: stringfields.h:299
void ast_ari_config_destroy(void)
Destroy the ARI configuration.
const char * method
Definition: res_pjsip.c:4335
describes a server instance
Definition: tcptls.h:149
Per-user configuration options.
Definition: internal.h:96
int ast_ari_cli_register(void)
Register CLI commands for ARI.
Definition: res/ari/cli.c:434
struct ast_ari_conf * ast_ari_config_get(void)
Get the current ARI configuration.
Generic container type.
ast_http_method
HTTP Request methods known by Asterisk.
Definition: http.h:56
int ast_ari_config_init(void)
Initialize the ARI configuration.
static snd_pcm_format_t format
Definition: chan_alsa.c:102
void ari_handle_websocket(struct ast_websocket_server *ws_server, struct ast_tcptls_session_instance *ser, const char *uri, enum ast_http_method method, struct ast_variable *get_params, struct ast_variable *headers)
Wrapper for invoking the websocket code for an incoming connection.
struct ao2_container * users
Definition: internal.h:58
ast_json_encoding_format
Encoding format type.
Definition: json.h:745