Asterisk - The Open Source Telephony Project GIT-master-c7a8271
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
ari_websockets.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 <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
19#ifndef ARI_WEBSOCKETS_H_
20#define ARI_WEBSOCKETS_H_
21
22/*! \file
23 *
24 * \brief Internal API's for websockets.
25 * \author David M. Lee, II <dlee@digium.com>
26 */
27
28#include "asterisk/http.h"
29#include "asterisk/json.h"
30#include "asterisk/vector.h"
32
34
35/* Forward-declare websocket structs. This avoids including http_websocket.h,
36 * which causes optional_api stuff to happen, which makes optional_api more
37 * difficult to debug. */
38
39struct ast_websocket;
40
41/*
42 * Since we create a "stasis-<appname>" dialplan context for each
43 * stasis app, we need to make sure that the total length will be
44 * <= AST_MAX_CONTEXT
45 */
46#define STASIS_CONTEXT_PREFIX "stasis-"
47#define STASIS_CONTEXT_PREFIX_LEN (sizeof(STASIS_CONTEXT_PREFIX) - 1)
48#define ARI_MAX_APP_NAME_LEN (AST_MAX_CONTEXT - STASIS_CONTEXT_PREFIX_LEN)
49
51 enum ast_websocket_type type; /*!< The type of websocket session. */
52 struct ast_websocket *ast_ws_session; /*!< The parent websocket session. */
53 int (*validator)(struct ast_json *); /*!< The message validator. */
54 struct ast_vector_string websocket_apps; /*!< List of Stasis apps registered to
55 the websocket session. */
56 int subscribe_all; /*!< Flag indicating if all events are subscribed to. */
57 AST_VECTOR(, struct ast_json *) message_queue; /*!< Container for holding delayed messages. */
58 char *app_name; /*!< The name of the Stasis application. */
59 char *remote_addr; /*!< The remote address. */
60 struct ari_conf_outbound_websocket *owc; /*!< The outbound websocket configuration. */
61 pthread_t thread; /*!< The thread that handles the websocket. */
62 char *channel_id; /*!< The channel id for per-call websocket. */
63 char *channel_name; /*!< The channel name for per-call websocket. */
64 int stasis_end_sent; /*!< Flag indicating if the StasisEnd message was sent. */
65 int connected; /*!< Flag indicating if the websocket is connected. */
66 int closing; /*!< Flag indicating if the session is closing. */
67 char session_id[]; /*!< The id for the websocket session. */
68};
69
77
78/*!
79 * \internal
80 * \brief Send a JSON event to a websocket.
81 *
82 * \param ari_ws_session ARI websocket session
83 * \param app_name Application name
84 * \param message JSON message
85 * \param debug_app Debug flag for application
86 */
88 const char *app_name, struct ast_json *message, int debug_app);
89
90/*!
91 * \internal
92 * \brief Process an ARI REST over Websocket request
93 *
94 * \param ari_ws_session ARI websocket session
95 * \param remote_addr Remote address for log messages
96 * \param upgrade_headers HTTP headers from the upgrade request
97 * \param app_name Application name
98 * \param msg JSON Request message
99 * \retval 0 on success, -1 on failure
100 */
102 const char *remote_addr, struct ast_variable *upgrade_headers,
103 const char *app_name, struct ast_json *msg);
104
105/*!
106 * \brief Wrapper for invoking the websocket code for an incoming connection.
107 *
108 * \param ws_server WebSocket server to invoke.
109 * \param ser HTTP session.
110 * \param uri Requested URI.
111 * \param method Requested HTTP method.
112 * \param get_params Parsed query parameters.
113 * \param headers Parsed HTTP headers.
114 */
116 const char *uri, enum ast_http_method method,
117 struct ast_variable *get_params,
118 struct ast_variable *headers);
119
122
123#endif /* ARI_WEBSOCKETS_H_ */
int ari_outbound_websocket_start(struct ari_conf_outbound_websocket *owc)
struct ari_ws_session * ari_websocket_get_session(const char *session_id)
void ari_websocket_shutdown_all(void)
int ari_websocket_process_request(struct ari_ws_session *ast_ws_session, const char *remote_addr, struct ast_variable *upgrade_headers, const char *app_name, struct ast_json *msg)
int ari_websocket_load_module(int is_enabled)
struct ari_ws_session * ari_websocket_get_session_by_app(const char *app_name)
void ari_websocket_send_event(struct ari_ws_session *ari_ws_session, const char *app_name, struct ast_json *message, int debug_app)
Callback handler for Stasis application messages.
void ari_websocket_shutdown(struct ari_ws_session *session)
const char * ari_websocket_type_to_str(enum ast_websocket_type type)
int ari_websocket_unload_module(void)
void ari_handle_websocket(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 * ari_websocket_get_sessions(void)
static struct ast_mansession session
static const char type[]
Definition: chan_ooh323.c:109
Support for Private Asterisk HTTP Servers.
ast_http_method
HTTP Request methods known by Asterisk.
Definition: http.h:58
ast_websocket_type
WebSocket connection/configuration types.
Asterisk JSON abstraction layer.
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
static int is_enabled(void)
Helper function to check if module is enabled.
Definition: res_ari.c:96
const char * method
Definition: res_pjsip.c:1279
Generic container type.
pthread_t thread
struct ast_vector_string websocket_apps
struct ari_conf_outbound_websocket * owc
enum ast_websocket_type type
struct ari_ws_session::@424 message_queue
struct ast_websocket * ast_ws_session
int(* validator)(struct ast_json *)
Abstract JSON element (object, array, string, int, ...).
describes a server instance
Definition: tcptls.h:151
Structure for variables, used for configurations and for channel variables.
String vector definitions.
Definition: vector.h:55
Structure definition for session.
Vector container support.
#define AST_VECTOR(name, type)
Define a vector structure.
Definition: vector.h:44