Add support for SIP over WebSocket.

This allows SIP traffic to be exchanged over a WebSocket connection which is useful for rtcweb.

Review: https://reviewboard.asterisk.org/r/2008


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370072 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Joshua Colp
2012-07-16 12:35:04 +00:00
parent f9c3585d73
commit e938737570
8 changed files with 263 additions and 139 deletions

View File

@@ -176,105 +176,12 @@ struct ast_sockaddr *ast_websocket_remote_address(struct ast_websocket *session)
*/
int ast_websocket_is_secure(struct ast_websocket *session);
#endif /* _ASTERISK_HTTP_WEBSOCKET_H */
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2012, Digium, Inc.
*
* Joshua Colp <jcolp@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
#ifndef _ASTERISK_HTTP_WEBSOCKET_H
#define _ASTERISK_HTTP_WEBSOCKET_H
#include "asterisk/module.h"
/*!
* \file http_websocket.h
* \brief Support for WebSocket connections within the Asterisk HTTP server.
*
* \author Joshua Colp <jcolp@digium.com>
* \brief Set the socket of a WebSocket session to be non-blocking.
*
* \retval 0 on success
* \retval -1 on failure
*/
int ast_websocket_set_nonblock(struct ast_websocket *session);
/*! \brief WebSocket operation codes */
enum ast_websocket_opcode {
AST_WEBSOCKET_OPCODE_TEXT = 0x1, /*!< Text frame */
AST_WEBSOCKET_OPCODE_BINARY = 0x2, /*!< Binary frame */
AST_WEBSOCKET_OPCODE_PING = 0x9, /*!< Request that the other side respond with a pong */
AST_WEBSOCKET_OPCODE_PONG = 0xA, /*!< Response to a ping */
AST_WEBSOCKET_OPCODE_CLOSE = 0x8, /*!< Connection is being closed */
AST_WEBSOCKET_OPCODE_CONTINUATION = 0x0, /*!< Continuation of a previous frame */
};
/*!
* \brief Callback for when a new connection for a sub-protocol is established
*
* \param f Pointer to the file instance for the session
* \param fd File descriptor for the session
* \param remote_address The address of the remote party
*
* \note Once called the ownership of the session is transferred to the sub-protocol handler. It
* is responsible for closing and cleaning up.
*
*/
typedef void (*ast_websocket_callback)(FILE *f, int fd, struct ast_sockaddr *remote_address);
/*!
* \brief Add a sub-protocol handler to the server
*
* \param name Name of the sub-protocol to register
* \param callback Callback called when a new connection requesting the sub-protocol is established
*
* \retval 0 success
* \retval -1 if sub-protocol handler could not be registered
*/
int ast_websocket_add_protocol(char *name, ast_websocket_callback callback);
/*!
* \brief Remove a sub-protocol handler from the server
*
* \param name Name of the sub-protocol to unregister
* \param callback Callback that was previously registered with the sub-protocol
*
* \retval 0 success
* \retval -1 if sub-protocol was not found or if callback did not match
*/
int ast_websocket_remove_protocol(char *name, ast_websocket_callback callback);
/*!
* \brief Read a WebSocket frame and handle it
*
* \param f Pointer to the file stream, used to respond to certain frames
* \param buf Pointer to the buffer containing the frame
* \param buflen Size of the buffer
* \param payload_len Pointer to a uint64_t which will be populated with the length of the payload if present
* \param opcode Pointer to an int which will be populated with the opcode of the frame
*
* \retval NULL if no payload is present
* \retval non-NULL if payload is present, returned pointer points to beginning of payload
*/
char *ast_websocket_read(FILE *f, char *buf, size_t buflen, uint64_t *payload_len, int *opcode);
/*!
* \brief Construct and transmit a WebSocket frame
*
* \param f Pointer to the file stream which the frame will be sent on
* \param opcode WebSocket operation code to place in the frame
* \param payload Optional pointer to a payload to add to the frame
* \param actual_length Length of the payload (0 if no payload)
*/
void ast_websocket_write(FILE *f, int op_code, char *payload, uint64_t actual_length);
#endif /* _ASTERISK_HTTP_WEBSOCKET_H */
#endif