mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-17 15:29:05 +00:00
Merge the pimp_my_sip branch into trunk.
The pimp_my_sip branch is being merged at this point because it offers basic functionality, and from an API standpoint, things are complete. SIP work is *not* feature-complete; however, with the completion of the SUBSCRIBE/NOTIFY API, all APIs (except a PUBLISH API) have been created, and thus it is possible for developers to attempt to create new SIP work. API documentation can be found in the doxygen in the code, but usability documentation is still lacking. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@386540 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -294,7 +294,7 @@
|
||||
/* Define if your system has the GLOB_NOMAGIC headers. */
|
||||
#undef HAVE_GLOB_NOMAGIC
|
||||
|
||||
/* Define if your system has the GMIME libraries. */
|
||||
/* Define to 1 if you have the GMime library. */
|
||||
#undef HAVE_GMIME
|
||||
|
||||
/* Define to indicate the GSM library */
|
||||
@@ -306,7 +306,7 @@
|
||||
/* Define to indicate that gsm.h has no prefix for its location */
|
||||
#undef HAVE_GSM_HEADER
|
||||
|
||||
/* Define if your system has the GTK2 libraries. */
|
||||
/* Define to 1 if you have the gtk2 library. */
|
||||
#undef HAVE_GTK2
|
||||
|
||||
/* Define to 1 if you have the Hoard Memory Allocator library. */
|
||||
@@ -324,7 +324,7 @@
|
||||
/* Define to 1 if you have the Iksemel Jabber library. */
|
||||
#undef HAVE_IKSEMEL
|
||||
|
||||
/* Define if your system has the ILBC libraries. */
|
||||
/* Define to 1 if you have the System iLBC library. */
|
||||
#undef HAVE_ILBC
|
||||
|
||||
/* Define if your system has the UW IMAP Toolkit c-client library. */
|
||||
@@ -376,7 +376,7 @@
|
||||
/* Define to 1 if you have the OpenLDAP library. */
|
||||
#undef HAVE_LDAP
|
||||
|
||||
/* Define if your system has the LIBEDIT libraries. */
|
||||
/* Define to 1 if you have the NetBSD Editline library library. */
|
||||
#undef HAVE_LIBEDIT
|
||||
|
||||
/* Define to 1 if you have the <libintl.h> header file. */
|
||||
@@ -551,7 +551,7 @@
|
||||
/* Define to indicate presence of the pg_encoding_to_char API. */
|
||||
#undef HAVE_PGSQL_pg_encoding_to_char
|
||||
|
||||
/* Define if your system has the PJPROJECT libraries. */
|
||||
/* Define to 1 if you have the PJPROJECT library. */
|
||||
#undef HAVE_PJPROJECT
|
||||
|
||||
/* Define to 1 if your system defines IP_PKTINFO. */
|
||||
@@ -854,19 +854,19 @@
|
||||
/* Define to 1 if you have the `strtoq' function. */
|
||||
#undef HAVE_STRTOQ
|
||||
|
||||
/* Define to 1 if `ifr_ifru.ifru_hwaddr' is a member of `struct ifreq'. */
|
||||
/* Define to 1 if `ifr_ifru.ifru_hwaddr' is member of `struct ifreq'. */
|
||||
#undef HAVE_STRUCT_IFREQ_IFR_IFRU_IFRU_HWADDR
|
||||
|
||||
/* Define to 1 if `uid' is a member of `struct sockpeercred'. */
|
||||
/* Define to 1 if `uid' is member of `struct sockpeercred'. */
|
||||
#undef HAVE_STRUCT_SOCKPEERCRED_UID
|
||||
|
||||
/* Define to 1 if `st_blksize' is a member of `struct stat'. */
|
||||
/* Define to 1 if `st_blksize' is member of `struct stat'. */
|
||||
#undef HAVE_STRUCT_STAT_ST_BLKSIZE
|
||||
|
||||
/* Define to 1 if `cr_uid' is a member of `struct ucred'. */
|
||||
/* Define to 1 if `cr_uid' is member of `struct ucred'. */
|
||||
#undef HAVE_STRUCT_UCRED_CR_UID
|
||||
|
||||
/* Define to 1 if `uid' is a member of `struct ucred'. */
|
||||
/* Define to 1 if `uid' is member of `struct ucred'. */
|
||||
#undef HAVE_STRUCT_UCRED_UID
|
||||
|
||||
/* Define to 1 if you have the mISDN Supplemental Services library. */
|
||||
@@ -1144,12 +1144,12 @@
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#undef PACKAGE_TARNAME
|
||||
|
||||
/* Define to the home page for this package. */
|
||||
#undef PACKAGE_URL
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#undef PACKAGE_VERSION
|
||||
|
||||
/* Define to 1 if the C compiler supports function prototypes. */
|
||||
#undef PROTOTYPES
|
||||
|
||||
/* Define to necessary symbol if this constant uses a non-standard name on
|
||||
your system. */
|
||||
#undef PTHREAD_CREATE_JOINABLE
|
||||
@@ -1169,6 +1169,11 @@
|
||||
/* Define to the type of arg 5 for `select'. */
|
||||
#undef SELECT_TYPE_ARG5
|
||||
|
||||
/* Define to 1 if the `setvbuf' function takes the buffering type as its
|
||||
second argument and the buffer pointer as the third, as on System V before
|
||||
release 3. */
|
||||
#undef SETVBUF_REVERSED
|
||||
|
||||
/* The size of `char *', as computed by sizeof. */
|
||||
#undef SIZEOF_CHAR_P
|
||||
|
||||
@@ -1204,39 +1209,24 @@
|
||||
/* Define to a type of the same size as fd_set.fds_bits[[0]] */
|
||||
#undef TYPEOF_FD_SET_FDS_BITS
|
||||
|
||||
/* Enable extensions on AIX 3, Interix. */
|
||||
/* Define to 1 if on AIX 3.
|
||||
System headers sometimes define this.
|
||||
We just want to avoid a redefinition error message. */
|
||||
#ifndef _ALL_SOURCE
|
||||
# undef _ALL_SOURCE
|
||||
#endif
|
||||
/* Enable GNU extensions on systems that have them. */
|
||||
#ifndef _GNU_SOURCE
|
||||
# undef _GNU_SOURCE
|
||||
#endif
|
||||
/* Enable threading extensions on Solaris. */
|
||||
#ifndef _POSIX_PTHREAD_SEMANTICS
|
||||
# undef _POSIX_PTHREAD_SEMANTICS
|
||||
#endif
|
||||
/* Enable extensions on HP NonStop. */
|
||||
#ifndef _TANDEM_SOURCE
|
||||
# undef _TANDEM_SOURCE
|
||||
#endif
|
||||
/* Enable general extensions on Solaris. */
|
||||
#ifndef __EXTENSIONS__
|
||||
# undef __EXTENSIONS__
|
||||
#endif
|
||||
|
||||
|
||||
/* Define to 1 if running on Darwin. */
|
||||
#undef _DARWIN_UNLIMITED_SELECT
|
||||
|
||||
/* Enable large inode numbers on Mac OS X 10.5. */
|
||||
#ifndef _DARWIN_USE_64_BIT_INODE
|
||||
# define _DARWIN_USE_64_BIT_INODE 1
|
||||
#endif
|
||||
|
||||
/* Number of bits in a file offset, on hosts where this is settable. */
|
||||
#undef _FILE_OFFSET_BITS
|
||||
|
||||
/* Enable GNU extensions on systems that have them. */
|
||||
#ifndef _GNU_SOURCE
|
||||
# undef _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
|
||||
#undef _LARGEFILE_SOURCE
|
||||
|
||||
@@ -1253,6 +1243,20 @@
|
||||
/* Define to 1 if you need to in order for `stat' and other things to work. */
|
||||
#undef _POSIX_SOURCE
|
||||
|
||||
/* Enable extensions on Solaris. */
|
||||
#ifndef __EXTENSIONS__
|
||||
# undef __EXTENSIONS__
|
||||
#endif
|
||||
#ifndef _POSIX_PTHREAD_SEMANTICS
|
||||
# undef _POSIX_PTHREAD_SEMANTICS
|
||||
#endif
|
||||
#ifndef _TANDEM_SOURCE
|
||||
# undef _TANDEM_SOURCE
|
||||
#endif
|
||||
|
||||
/* Define like PROTOTYPES; this can be used by system headers. */
|
||||
#undef __PROTOTYPES
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
#undef const
|
||||
|
||||
|
||||
1092
include/asterisk/res_sip.h
Normal file
1092
include/asterisk/res_sip.h
Normal file
File diff suppressed because it is too large
Load Diff
346
include/asterisk/res_sip_pubsub.h
Normal file
346
include/asterisk/res_sip_pubsub.h
Normal file
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2013, Digium, Inc.
|
||||
*
|
||||
* Mark Michelson <mmichelson@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 _RES_SIP_PUBSUB_H
|
||||
#define _RES_SIP_PUBSUB_H
|
||||
|
||||
#include "asterisk/linkedlists.h"
|
||||
|
||||
/* Forward declarations */
|
||||
struct pjsip_rx_data;
|
||||
struct pjsip_tx_data;
|
||||
struct pjsip_evsub;
|
||||
struct ast_sip_endpoint;
|
||||
struct ast_datastore;
|
||||
struct ast_datastore_info;
|
||||
|
||||
/*!
|
||||
* \brief Opaque structure representing an RFC 3265 SIP subscription
|
||||
*/
|
||||
struct ast_sip_subscription;
|
||||
|
||||
/*!
|
||||
* \brief Role for the subscription that is being created
|
||||
*/
|
||||
enum ast_sip_subscription_role {
|
||||
/* Sending SUBSCRIBEs, receiving NOTIFYs */
|
||||
AST_SIP_SUBSCRIBER,
|
||||
/* Sending NOTIFYs, receiving SUBSCRIBEs */
|
||||
AST_SIP_NOTIFIER,
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Data for responses to SUBSCRIBEs and NOTIFIEs
|
||||
*
|
||||
* Some of PJSIP's evsub callbacks expect us to provide them
|
||||
* with data so that they can craft a response rather than have
|
||||
* us create our own response.
|
||||
*
|
||||
* Filling in the structure is optional, since the framework
|
||||
* will automatically respond with a 200 OK response if we do
|
||||
* not provide it with any additional data.
|
||||
*/
|
||||
struct ast_sip_subscription_response_data {
|
||||
/*! Status code of the response */
|
||||
int status_code;
|
||||
/*! Optional status text */
|
||||
const char *status_text;
|
||||
/*! Optional additional headers to add to the response */
|
||||
struct ast_variable *headers;
|
||||
/*! Optional body to add to the response */
|
||||
struct ast_sip_body *body;
|
||||
};
|
||||
|
||||
#define AST_SIP_MAX_ACCEPT 32
|
||||
|
||||
struct ast_sip_subscription_handler {
|
||||
/*! The name of the event this handler deals with */
|
||||
const char *event_name;
|
||||
/*! The types of body this handler accepts */
|
||||
const char *accept[AST_SIP_MAX_ACCEPT];
|
||||
|
||||
/*!
|
||||
* \brief Called when a subscription is to be destroyed
|
||||
*
|
||||
* This is a subscriber and notifier callback.
|
||||
*
|
||||
* The handler is not expected to send any sort of requests or responses
|
||||
* during this callback. The handler MUST, however, begin the destruction
|
||||
* process for the subscription during this callback.
|
||||
*/
|
||||
void (*subscription_shutdown)(struct ast_sip_subscription *subscription);
|
||||
|
||||
/*!
|
||||
* \brief Called when a SUBSCRIBE arrives in order to create a new subscription
|
||||
*
|
||||
* This is a notifier callback.
|
||||
*
|
||||
* If the notifier wishes to accept the subscription, then it can create
|
||||
* a new ast_sip_subscription to do so.
|
||||
*
|
||||
* If the notifier chooses to create a new subscription, then it must accept
|
||||
* the incoming subscription using pjsip_evsub_accept() and it must also
|
||||
* send an initial NOTIFY with the current subscription state.
|
||||
*
|
||||
* \param endpoint The endpoint from which we received the SUBSCRIBE
|
||||
* \param rdata The SUBSCRIBE request
|
||||
* \retval NULL The SUBSCRIBE has not been accepted
|
||||
* \retval non-NULL The newly-created subscription
|
||||
*/
|
||||
struct ast_sip_subscription *(*new_subscribe)(struct ast_sip_endpoint *endpoint,
|
||||
pjsip_rx_data *rdata);
|
||||
|
||||
/*!
|
||||
* \brief Called when an endpoint renews a subscription.
|
||||
*
|
||||
* This is a notifier callback.
|
||||
*
|
||||
* Because of the way that the PJSIP evsub framework works, it will automatically
|
||||
* send a response to the SUBSCRIBE. However, the subscription handler must send
|
||||
* a NOTIFY with the current subscription state when this callback is called.
|
||||
*
|
||||
* The response_data that is passed into this callback is used to craft what should
|
||||
* be in the response to the incoming SUBSCRIBE. It is initialized with a 200 status
|
||||
* code and all other parameters are empty.
|
||||
*
|
||||
* \param sub The subscription that is being renewed
|
||||
* \param rdata The SUBSCRIBE request in question
|
||||
* \param[out] response_data Data pertaining to the SIP response that should be
|
||||
* sent to the SUBSCRIBE
|
||||
*/
|
||||
void (*resubscribe)(struct ast_sip_subscription *sub,
|
||||
pjsip_rx_data *rdata, struct ast_sip_subscription_response_data *response_data);
|
||||
|
||||
/*!
|
||||
* \brief Called when a subscription times out.
|
||||
*
|
||||
* This is a notifier callback
|
||||
*
|
||||
* This indicates that the subscription has timed out. The subscription handler is
|
||||
* expected to send a NOTIFY that terminates the subscription.
|
||||
*
|
||||
* \param sub The subscription that has timed out
|
||||
*/
|
||||
void (*subscription_timeout)(struct ast_sip_subscription *sub);
|
||||
|
||||
/*!
|
||||
* \brief Called when a subscription is terminated via a SUBSCRIBE or NOTIFY request
|
||||
*
|
||||
* This is a notifier and subscriber callback.
|
||||
*
|
||||
* The PJSIP subscription framework will automatically send the response to the
|
||||
* request. If a notifier receives this callback, then the subscription handler
|
||||
* is expected to send a final NOTIFY to terminate the subscription.
|
||||
*
|
||||
* \param sub The subscription being terminated
|
||||
* \param rdata The request that terminated the subscription
|
||||
*/
|
||||
void (*subscription_terminated)(struct ast_sip_subscription *sub, pjsip_rx_data *rdata);
|
||||
|
||||
/*!
|
||||
* \brief Called when a subscription handler's outbound NOTIFY receives a response
|
||||
*
|
||||
* This is a notifier callback.
|
||||
*
|
||||
* \param sub The subscription
|
||||
* \param rdata The NOTIFY response
|
||||
*/
|
||||
void (*notify_response)(struct ast_sip_subscription *sub, pjsip_rx_data *rdata);
|
||||
|
||||
/*!
|
||||
* \brief Called when a subscription handler receives an inbound NOTIFY
|
||||
*
|
||||
* This is a subscriber callback.
|
||||
*
|
||||
* Because of the way that the PJSIP evsub framework works, it will automatically
|
||||
* send a response to the NOTIFY. By default this will be a 200 OK response, but
|
||||
* this callback can change details of the response by returning response data
|
||||
* to use.
|
||||
*
|
||||
* The response_data that is passed into this callback is used to craft what should
|
||||
* be in the response to the incoming SUBSCRIBE. It is initialized with a 200 status
|
||||
* code and all other parameters are empty.
|
||||
*
|
||||
* \param sub The subscription
|
||||
* \param rdata The NOTIFY request
|
||||
* \param[out] response_data Data pertaining to the SIP response that should be
|
||||
* sent to the SUBSCRIBE
|
||||
*/
|
||||
void (*notify_request)(struct ast_sip_subscription *sub,
|
||||
pjsip_rx_data *rdata, struct ast_sip_subscription_response_data *response_data);
|
||||
|
||||
/*!
|
||||
* \brief Called when it is time for a subscriber to resubscribe
|
||||
*
|
||||
* This is a subscriber callback.
|
||||
*
|
||||
* The subscriber can reresh the subscription using the pjsip_evsub_initiate()
|
||||
* function.
|
||||
*
|
||||
* \param sub The subscription to refresh
|
||||
* \retval 0 Success
|
||||
* \retval non-zero Failure
|
||||
*/
|
||||
int (*refresh_subscription)(struct ast_sip_subscription *sub);
|
||||
AST_LIST_ENTRY(ast_sip_subscription_handler) next;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Create a new ast_sip_subscription structure
|
||||
*
|
||||
* In most cases the pubsub core will create a general purpose subscription
|
||||
* within PJSIP. However, PJSIP provides enhanced support for the following
|
||||
* event packages:
|
||||
*
|
||||
* presence
|
||||
* message-summary
|
||||
*
|
||||
* If either of these events are handled by the subscription handler, then
|
||||
* the special-purpose event subscriptions will be created within PJSIP,
|
||||
* and it will be expected that your subscription handler make use of the
|
||||
* special PJSIP APIs.
|
||||
*
|
||||
* \param handler The subsription handler for this subscription
|
||||
* \param role Whether we are acting as subscriber or notifier for this subscription
|
||||
* \param endpoint The endpoint involved in this subscription
|
||||
* \param rdata If acting as a notifier, the SUBSCRIBE request that triggered subscription creation
|
||||
*/
|
||||
struct ast_sip_subscription *ast_sip_create_subscription(const struct ast_sip_subscription_handler *handler,
|
||||
enum ast_sip_subscription_role role, struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Get the endpoint that is associated with this subscription
|
||||
*
|
||||
* This function will increase the reference count of the endpoint. Be sure to
|
||||
* release the reference to it when you are finished with the endpoint.
|
||||
*
|
||||
* \retval NULL Could not get endpoint
|
||||
* \retval non-NULL The endpoint
|
||||
*/
|
||||
struct ast_sip_endpoint *ast_sip_subscription_get_endpoint(struct ast_sip_subscription *sub);
|
||||
|
||||
/*!
|
||||
* \brief Get the serializer for the subscription
|
||||
*
|
||||
* Tasks that originate outside of a SIP servant thread should get the serializer
|
||||
* and push the task to the serializer.
|
||||
*
|
||||
* \param sub The subscription
|
||||
* \retval NULL Failure
|
||||
* \retval non-NULL The subscription's serializer
|
||||
*/
|
||||
struct ast_taskprocessor *ast_sip_subscription_get_serializer(struct ast_sip_subscription *sub);
|
||||
|
||||
/*!
|
||||
* \brief Get the underlying PJSIP evsub structure
|
||||
*
|
||||
* This is useful when wishing to call PJSIP's API calls in order to
|
||||
* create SUBSCRIBEs, NOTIFIES, etc. as well as get subscription state
|
||||
*
|
||||
* This function, as well as all methods called on the pjsip_evsub should
|
||||
* be done in a SIP servant thread.
|
||||
*
|
||||
* \param sub The subscription
|
||||
* \retval NULL Failure
|
||||
* \retval non-NULL The underlying pjsip_evsub
|
||||
*/
|
||||
pjsip_evsub *ast_sip_subscription_get_evsub(struct ast_sip_subscription *sub);
|
||||
|
||||
/*!
|
||||
* \brief Send a request created via a PJSIP evsub method
|
||||
*
|
||||
* Callers of this function should take care to do so within a SIP servant
|
||||
* thread.
|
||||
*
|
||||
* \param sub The subscription on which to send the request
|
||||
* \param tdata The request to send
|
||||
* \retval 0 Success
|
||||
* \retval non-zero Failure
|
||||
*/
|
||||
int ast_sip_subscription_send_request(struct ast_sip_subscription *sub, pjsip_tx_data *tdata);
|
||||
|
||||
/*!
|
||||
* \brief Alternative for ast_datastore_alloc()
|
||||
*
|
||||
* There are two major differences between this and ast_datastore_alloc()
|
||||
* 1) This allocates a refcounted object
|
||||
* 2) This will fill in a uid if one is not provided
|
||||
*
|
||||
* DO NOT call ast_datastore_free() on a datastore allocated in this
|
||||
* way since that function will attempt to free the datastore rather
|
||||
* than play nicely with its refcount.
|
||||
*
|
||||
* \param info Callbacks for datastore
|
||||
* \param uid Identifier for datastore
|
||||
* \retval NULL Failed to allocate datastore
|
||||
* \retval non-NULL Newly allocated datastore
|
||||
*/
|
||||
struct ast_datastore *ast_sip_subscription_alloc_datastore(const struct ast_datastore_info *info, const char *uid);
|
||||
|
||||
/*!
|
||||
* \brief Add a datastore to a SIP subscription
|
||||
*
|
||||
* Note that SIP uses reference counted datastores. The datastore passed into this function
|
||||
* must have been allocated using ao2_alloc() or there will be serious problems.
|
||||
*
|
||||
* \param subscription The ssubscription to add the datastore to
|
||||
* \param datastore The datastore to be added to the subscription
|
||||
* \retval 0 Success
|
||||
* \retval -1 Failure
|
||||
*/
|
||||
int ast_sip_subscription_add_datastore(struct ast_sip_subscription *subscription, struct ast_datastore *datastore);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve a subscription datastore
|
||||
*
|
||||
* The datastore retrieved will have its reference count incremented. When the caller is done
|
||||
* with the datastore, the reference counted needs to be decremented using ao2_ref().
|
||||
*
|
||||
* \param subscription The subscription from which to retrieve the datastore
|
||||
* \param name The name of the datastore to retrieve
|
||||
* \retval NULL Failed to find the specified datastore
|
||||
* \retval non-NULL The specified datastore
|
||||
*/
|
||||
struct ast_datastore *ast_sip_subscription_get_datastore(struct ast_sip_subscription *subscription, const char *name);
|
||||
|
||||
/*!
|
||||
* \brief Remove a subscription datastore from the subscription
|
||||
*
|
||||
* This operation may cause the datastore's free() callback to be called if the reference
|
||||
* count reaches zero.
|
||||
*
|
||||
* \param subscription The subscription to remove the datastore from
|
||||
* \param name The name of the datastore to remove
|
||||
*/
|
||||
void ast_sip_subscription_remove_datastore(struct ast_sip_subscription *subscription, const char *name);
|
||||
|
||||
/*!
|
||||
* \brief Register a subscription handler
|
||||
*
|
||||
* \retval 0 Handler was registered successfully
|
||||
* \retval non-zero Handler was not registered successfully
|
||||
*/
|
||||
int ast_sip_register_subscription_handler(struct ast_sip_subscription_handler *handler);
|
||||
|
||||
/*!
|
||||
* \brief Unregister a subscription handler
|
||||
*/
|
||||
void ast_sip_unregister_subscription_handler(struct ast_sip_subscription_handler *handler);
|
||||
|
||||
#endif /* RES_SIP_PUBSUB_H */
|
||||
468
include/asterisk/res_sip_session.h
Normal file
468
include/asterisk/res_sip_session.h
Normal file
@@ -0,0 +1,468 @@
|
||||
/*
|
||||
* Asterisk -- An open source telephony toolkit.
|
||||
*
|
||||
* Copyright (C) 2013, Digium, Inc.
|
||||
*
|
||||
* Mark Michelson <mmichelson@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 _RES_SIP_SESSION_H
|
||||
#define _RES_SIP_SESSION_H
|
||||
|
||||
/* Needed for pj_timer_entry definition */
|
||||
#include "pjlib.h"
|
||||
#include "asterisk/linkedlists.h"
|
||||
/* Needed for AST_MAX_EXTENSION constant */
|
||||
#include "asterisk/channel.h"
|
||||
/* Needed for ast_sockaddr struct */
|
||||
#include "asterisk/netsock.h"
|
||||
|
||||
/* Forward declarations */
|
||||
struct ast_sip_endpoint;
|
||||
struct ast_sip_transport;
|
||||
struct pjsip_inv_session;
|
||||
struct ast_channel;
|
||||
struct ast_datastore;
|
||||
struct ast_datastore_info;
|
||||
struct ao2_container;
|
||||
struct pjsip_tx_data;
|
||||
struct pjsip_rx_data;
|
||||
struct ast_party_id;
|
||||
struct pjmedia_sdp_media;
|
||||
struct pjmedia_sdp_session;
|
||||
struct ast_rtp_instance;
|
||||
|
||||
struct ast_sip_session_sdp_handler;
|
||||
|
||||
/*!
|
||||
* \brief A structure containing SIP session media information
|
||||
*/
|
||||
struct ast_sip_session_media {
|
||||
/*! \brief RTP instance itself */
|
||||
struct ast_rtp_instance *rtp;
|
||||
/*! \brief Direct media address */
|
||||
struct ast_sockaddr direct_media_addr;
|
||||
/*! \brief SDP handler that setup the RTP */
|
||||
struct ast_sip_session_sdp_handler *handler;
|
||||
/*! \brief Stream is on hold */
|
||||
unsigned int held:1;
|
||||
/*! \brief Stream type this session media handles */
|
||||
char stream_type[1];
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Opaque structure representing a request that could not be sent
|
||||
* due to an outstanding INVITE transaction
|
||||
*/
|
||||
struct ast_sip_session_delayed_request;
|
||||
|
||||
/*!
|
||||
* \brief A structure describing a SIP session
|
||||
*
|
||||
* For the sake of brevity, a "SIP session" in Asterisk is referring to
|
||||
* a dialog initiated by an INVITE. While "session" is typically interpreted
|
||||
* to refer to the negotiated media within a SIP dialog, we have opted
|
||||
* to use the term "SIP session" to refer to the INVITE dialog itself.
|
||||
*/
|
||||
struct ast_sip_session {
|
||||
/* Dialplan extension where incoming call is destined */
|
||||
char exten[AST_MAX_EXTENSION];
|
||||
/* The endpoint with which Asterisk is communicating */
|
||||
struct ast_sip_endpoint *endpoint;
|
||||
/* The PJSIP details of the session, which includes the dialog */
|
||||
struct pjsip_inv_session *inv_session;
|
||||
/* The Asterisk channel associated with the session */
|
||||
struct ast_channel *channel;
|
||||
/* Registered session supplements */
|
||||
AST_LIST_HEAD(, ast_sip_session_supplement) supplements;
|
||||
/* Datastores added to the session by supplements to the session */
|
||||
struct ao2_container *datastores;
|
||||
/* Media streams */
|
||||
struct ao2_container *media;
|
||||
/* Serializer for tasks relating to this SIP session */
|
||||
struct ast_taskprocessor *serializer;
|
||||
/* Requests that could not be sent due to current inv_session state */
|
||||
AST_LIST_HEAD_NOLOCK(, ast_sip_session_delayed_request) delayed_requests;
|
||||
/* When we need to reschedule a reinvite, we use this structure to do it */
|
||||
pj_timer_entry rescheduled_reinvite;
|
||||
/* Format capabilities pertaining to direct media */
|
||||
struct ast_format_cap *direct_media_cap;
|
||||
/* Identity of endpoint this session deals with */
|
||||
struct ast_party_id id;
|
||||
/* Requested capabilities */
|
||||
struct ast_format_cap *req_caps;
|
||||
};
|
||||
|
||||
typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);
|
||||
typedef int (*ast_sip_session_response_cb)(struct ast_sip_session *session, pjsip_rx_data *rdata);
|
||||
|
||||
enum ast_sip_session_supplement_priority {
|
||||
/*! Top priority. Supplements with this priority are those that need to run before any others */
|
||||
AST_SIP_SESSION_SUPPLEMENT_PRIORITY_FIRST = 0,
|
||||
/*! Channel creation priority.
|
||||
* chan_gulp creates a channel at this priority. If your supplement depends on being run before
|
||||
* or after channel creation, then set your priority to be lower or higher than this value.
|
||||
*/
|
||||
AST_SIP_SESSION_SUPPLEMENT_PRIORITY_CHANNEL = 1000000,
|
||||
/*! Lowest priority. Supplements with this priority should be run after all other supplements */
|
||||
AST_SIP_SESSION_SUPPLEMENT_PRIORITY_LAST = INT_MAX,
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief A supplement to SIP message processing
|
||||
*
|
||||
* These can be registered by any module in order to add
|
||||
* processing to incoming and outgoing SIP requests and responses
|
||||
*/
|
||||
struct ast_sip_session_supplement {
|
||||
/*! Method on which to call the callbacks. If NULL, call on all methods */
|
||||
const char *method;
|
||||
/*! Priority for this supplement. Lower numbers are visited before higher numbers */
|
||||
enum ast_sip_session_supplement_priority priority;
|
||||
/*!
|
||||
* \brief Notification that the session has begun
|
||||
* This method will always be called from a SIP servant thread.
|
||||
*/
|
||||
void (*session_begin)(struct ast_sip_session *session);
|
||||
/*!
|
||||
* \brief Notification that the session has ended
|
||||
*
|
||||
* This method may or may not be called from a SIP servant thread. Do
|
||||
* not make assumptions about being able to call PJSIP methods from within
|
||||
* this method.
|
||||
*/
|
||||
void (*session_end)(struct ast_sip_session *session);
|
||||
/*!
|
||||
* \brief Notification that the session is being destroyed
|
||||
*/
|
||||
void (*session_destroy)(struct ast_sip_session *session);
|
||||
/*!
|
||||
* \brief Called on incoming SIP request
|
||||
* This method can indicate a failure in processing in its return. If there
|
||||
* is a failure, it is required that this method sends a response to the request.
|
||||
* This method is always called from a SIP servant thread.
|
||||
*
|
||||
* \note
|
||||
* The following PJSIP methods will not work properly:
|
||||
* pjsip_rdata_get_dlg()
|
||||
* pjsip_rdata_get_tsx()
|
||||
* The reason is that the rdata passed into this function is a cloned rdata structure,
|
||||
* and its module data is not copied during the cloning operation.
|
||||
* If you need to get the dialog, you can get it via session->inv_session->dlg.
|
||||
*/
|
||||
int (*incoming_request)(struct ast_sip_session *session, struct pjsip_rx_data *rdata);
|
||||
/*!
|
||||
* \brief Called on an incoming SIP response
|
||||
* This method is always called from a SIP servant thread.
|
||||
*
|
||||
* \note
|
||||
* The following PJSIP methods will not work properly:
|
||||
* pjsip_rdata_get_dlg()
|
||||
* pjsip_rdata_get_tsx()
|
||||
* The reason is that the rdata passed into this function is a cloned rdata structure,
|
||||
* and its module data is not copied during the cloning operation.
|
||||
* If you need to get the dialog, you can get it via session->inv_session->dlg.
|
||||
*/
|
||||
void (*incoming_response)(struct ast_sip_session *session, struct pjsip_rx_data *rdata);
|
||||
/*!
|
||||
* \brief Called on an outgoing SIP request
|
||||
* This method is always called from a SIP servant thread.
|
||||
*/
|
||||
void (*outgoing_request)(struct ast_sip_session *session, struct pjsip_tx_data *tdata);
|
||||
/*!
|
||||
* \brief Called on an outgoing SIP response
|
||||
* This method is always called from a SIP servant thread.
|
||||
*/
|
||||
void (*outgoing_response)(struct ast_sip_session *session, struct pjsip_tx_data *tdata);
|
||||
/*! Next item in the list */
|
||||
AST_LIST_ENTRY(ast_sip_session_supplement) next;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief A handler for SDPs in SIP sessions
|
||||
*
|
||||
* An SDP handler is registered by a module that is interested in being the
|
||||
* responsible party for specific types of SDP streams.
|
||||
*/
|
||||
struct ast_sip_session_sdp_handler {
|
||||
/*! An identifier for this handler */
|
||||
const char *id;
|
||||
/*!
|
||||
* \brief Set session details based on a stream in an incoming SDP offer or answer
|
||||
* \param session The session for which the media is being negotiated
|
||||
* \param session_media The media to be setup for this session
|
||||
* \param sdp The entire SDP. Useful for getting "global" information, such as connections or attributes
|
||||
* \param stream The stream on which to operate
|
||||
* \retval 0 The stream was not handled by this handler. If there are other registered handlers for this stream type, they will be called.
|
||||
* \retval <0 There was an error encountered. No further operation will take place and the current negotiation will be abandoned.
|
||||
* \retval >0 The stream was handled by this handler. No further handler of this stream type will be called.
|
||||
*/
|
||||
int (*negotiate_incoming_sdp_stream)(struct ast_sip_session *session, struct ast_sip_session_media *session_media, const struct pjmedia_sdp_session *sdp, const struct pjmedia_sdp_media *stream);
|
||||
/*!
|
||||
* \brief Create an SDP media stream and add it to the outgoing SDP offer or answer
|
||||
* \param session The session for which media is being added
|
||||
* \param session_media The media to be setup for this session
|
||||
* \param stream The stream on which to operate
|
||||
* \retval 0 The stream was not handled by this handler. If there are other registered handlers for this stream type, they will be called.
|
||||
* \retval <0 There was an error encountered. No further operation will take place and the current negotiation will be abandoned.
|
||||
* \retval >0 The stream was handled by this handler. No further handler of this stream type will be called.
|
||||
*/
|
||||
int (*handle_incoming_sdp_stream)(struct ast_sip_session *session, struct ast_sip_session_media *session_media, const struct pjmedia_sdp_session *sdp, struct pjmedia_sdp_media *stream);
|
||||
/*!
|
||||
* \brief Create an SDP media stream and add it to the outgoing SDP offer or answer
|
||||
* \param session The session for which media is being added
|
||||
* \param session_media The media to be setup for this session
|
||||
* \param sdp The entire SDP as currently built
|
||||
* \retval 0 This handler has no stream to add. If there are other registered handlers for this stream type, they will be called.
|
||||
* \retval <0 There was an error encountered. No further operation will take place and the current SDP negotiation will be abandoned.
|
||||
* \retval >0 The handler has a stream to be added to the SDP. No further handler of this stream type will be called.
|
||||
*/
|
||||
int (*create_outgoing_sdp_stream)(struct ast_sip_session *session, struct ast_sip_session_media *session_media, struct pjmedia_sdp_session *sdp);
|
||||
/*!
|
||||
* \brief Update media stream with external address if applicable
|
||||
* \param tdata The outgoing message itself
|
||||
* \param stream The stream on which to operate
|
||||
* \param transport The transport the SDP is going out on
|
||||
*/
|
||||
void (*change_outgoing_sdp_stream_media_address)(struct pjsip_tx_data *tdata, struct pjmedia_sdp_media *stream, struct ast_sip_transport *transport);
|
||||
/*!
|
||||
* \brief Apply a negotiated SDP media stream
|
||||
* \param session The session for which media is being applied
|
||||
* \param session_media The media to be setup for this session
|
||||
* \param local The entire local negotiated SDP
|
||||
* \param local_stream The local stream which to apply
|
||||
* \param remote The entire remote negotiated SDP
|
||||
* \param remote_stream The remote stream which to apply
|
||||
* \retval 0 The stream was not applied by this handler. If there are other registered handlers for this stream type, they will be called.
|
||||
* \retval <0 There was an error encountered. No further operation will take place and the current application will be abandoned.
|
||||
* \retval >0 The stream was handled by this handler. No further handler of this stream type will be called.
|
||||
*/
|
||||
int (*apply_negotiated_sdp_stream)(struct ast_sip_session *session, struct ast_sip_session_media *session_media, const struct pjmedia_sdp_session *local, const struct pjmedia_sdp_media *local_stream,
|
||||
const struct pjmedia_sdp_session *remote, const struct pjmedia_sdp_media *remote_stream);
|
||||
/*!
|
||||
* \brief Destroy a session_media created by this handler
|
||||
* \param session The session for which media is being destroyed
|
||||
* \param session_media The media to destroy
|
||||
*/
|
||||
void (*stream_destroy)(struct ast_sip_session_media *session_media);
|
||||
/*! Next item in the list. */
|
||||
AST_LIST_ENTRY(ast_sip_session_sdp_handler) next;
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Allocate a new SIP session
|
||||
*
|
||||
* This will take care of allocating the datastores container on the session as well
|
||||
* as placing all registered supplements onto the session.
|
||||
*
|
||||
* The endpoint that is passed in will have its reference count increased by one since
|
||||
* the session will be keeping a reference to the endpoint. The session will relinquish
|
||||
* this reference when the session is destroyed.
|
||||
*
|
||||
* \param endpoint The endpoint that this session communicates with
|
||||
* \param inv_session The PJSIP INVITE session data
|
||||
*/
|
||||
struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint, pjsip_inv_session *inv);
|
||||
|
||||
/*!
|
||||
* \brief Create a new outgoing SIP session
|
||||
*
|
||||
* The endpoint that is passed in will have its reference count increased by one since
|
||||
* the session will be keeping a reference to the endpoint. The session will relinquish
|
||||
* this reference when the session is destroyed.
|
||||
*
|
||||
* \param endpoint The endpoint that this session uses for settings
|
||||
* \param location Optional name of the location to call, be it named location or explicit URI
|
||||
* \param request_user Optional request user to place in the request URI if permitted
|
||||
* \param req_caps The requested capabilities
|
||||
*/
|
||||
struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint *endpoint, const char *location, const char *request_user, struct ast_format_cap *req_caps);
|
||||
|
||||
/*!
|
||||
* \brief Register an SDP handler
|
||||
*
|
||||
* An SDP handler is responsible for parsing incoming SDP streams and ensuring that
|
||||
* Asterisk can cope with the contents. Similarly, the SDP handler will be
|
||||
* responsible for constructing outgoing SDP streams.
|
||||
*
|
||||
* Multiple handlers for the same stream type may be registered. They will be
|
||||
* visited in the order they were registered. Handlers will be visited for each
|
||||
* stream type until one claims to have handled the stream.
|
||||
*
|
||||
* \param handler The SDP handler to register
|
||||
* \param stream_type The type of media stream for which to call the handler
|
||||
* \retval 0 Success
|
||||
* \retval -1 Failure
|
||||
*/
|
||||
int ast_sip_session_register_sdp_handler(struct ast_sip_session_sdp_handler *handler, const char *stream_type);
|
||||
|
||||
/*!
|
||||
* \brief Unregister an SDP handler
|
||||
*
|
||||
* \param handler The SDP handler to unregister
|
||||
* \param stream_type Stream type for which the SDP handler was registered
|
||||
*/
|
||||
void ast_sip_session_unregister_sdp_handler(struct ast_sip_session_sdp_handler *handler, const char *stream_type);
|
||||
|
||||
/*!
|
||||
* \brief Register a supplement to SIP session processing
|
||||
*
|
||||
* This allows for someone to insert themselves in the processing of SIP
|
||||
* requests and responses. This, for example could allow for a module to
|
||||
* set channel data based on headers in an incoming message. Similarly,
|
||||
* a module could reject an incoming request if desired.
|
||||
*
|
||||
* \param supplement The supplement to register
|
||||
* \retval 0 Success
|
||||
* \retval -1 Failure
|
||||
*/
|
||||
int ast_sip_session_register_supplement(struct ast_sip_session_supplement *supplement);
|
||||
|
||||
/*!
|
||||
* \brief Unregister a an supplement to SIP session processing
|
||||
*
|
||||
* \param supplement The supplement to unregister
|
||||
*/
|
||||
void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement);
|
||||
|
||||
/*!
|
||||
* \brief Alternative for ast_datastore_alloc()
|
||||
*
|
||||
* There are two major differences between this and ast_datastore_alloc()
|
||||
* 1) This allocates a refcounted object
|
||||
* 2) This will fill in a uid if one is not provided
|
||||
*
|
||||
* DO NOT call ast_datastore_free() on a datastore allocated in this
|
||||
* way since that function will attempt to free the datastore rather
|
||||
* than play nicely with its refcount.
|
||||
*
|
||||
* \param info Callbacks for datastore
|
||||
* \param uid Identifier for datastore
|
||||
* \retval NULL Failed to allocate datastore
|
||||
* \retval non-NULL Newly allocated datastore
|
||||
*/
|
||||
struct ast_datastore *ast_sip_session_alloc_datastore(const struct ast_datastore_info *info, const char *uid);
|
||||
|
||||
/*!
|
||||
* \brief Add a datastore to a SIP session
|
||||
*
|
||||
* Note that SIP uses reference counted datastores. The datastore passed into this function
|
||||
* must have been allocated using ao2_alloc() or there will be serious problems.
|
||||
*
|
||||
* \param session The session to add the datastore to
|
||||
* \param datastore The datastore to be added to the session
|
||||
* \retval 0 Success
|
||||
* \retval -1 Failure
|
||||
*/
|
||||
int ast_sip_session_add_datastore(struct ast_sip_session *session, struct ast_datastore *datastore);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve a session datastore
|
||||
*
|
||||
* The datastore retrieved will have its reference count incremented. When the caller is done
|
||||
* with the datastore, the reference counted needs to be decremented using ao2_ref().
|
||||
*
|
||||
* \param session The session from which to retrieve the datastore
|
||||
* \param name The name of the datastore to retrieve
|
||||
* \retval NULL Failed to find the specified datastore
|
||||
* \retval non-NULL The specified datastore
|
||||
*/
|
||||
struct ast_datastore *ast_sip_session_get_datastore(struct ast_sip_session *session, const char *name);
|
||||
|
||||
/*!
|
||||
* \brief Remove a session datastore from the session
|
||||
*
|
||||
* This operation may cause the datastore's free() callback to be called if the reference
|
||||
* count reaches zero.
|
||||
*
|
||||
* \param session The session to remove the datastore from
|
||||
* \param name The name of the datastore to remove
|
||||
*/
|
||||
void ast_sip_session_remove_datastore(struct ast_sip_session *session, const char *name);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve identifying information from an incoming request
|
||||
*
|
||||
* This will retrieve identifying information and place it in the
|
||||
* id parameter. The caller of the function can then apply this to
|
||||
* caller ID, connected line, or whatever else may be proper.
|
||||
*
|
||||
* \param rdata The incoming request or response
|
||||
* \param[out] id The collected identity information
|
||||
* \retval 0 Successfully found identifying information
|
||||
* \retval -1 Identifying information could not be found
|
||||
*/
|
||||
int ast_sip_session_get_identity(struct pjsip_rx_data *rdata, struct ast_party_id *id);
|
||||
|
||||
/*!
|
||||
* \brief Send a reinvite or UPDATE on a session
|
||||
*
|
||||
* This method will inspect the session in order to construct an appropriate
|
||||
* session refresh request. As with any outgoing request in res_sip_session,
|
||||
* this will call into registered supplements in case they wish to add anything.
|
||||
*
|
||||
* Note: The on_request_creation callback may or may not be called in the same
|
||||
* thread where this function is called. Request creation may need to be delayed
|
||||
* due to the current INVITE transaction state.
|
||||
*
|
||||
* \param session The session on which the reinvite will be sent
|
||||
* \param on_request_creation Callback called when request is created
|
||||
* \param on_response Callback called when response for request is received
|
||||
* \param method The method that should be used when constructing the session refresh
|
||||
* \param generate_new_sdp Boolean to indicate if a new SDP should be created
|
||||
* \retval 0 Successfully sent refresh
|
||||
* \retval -1 Failure to send refresh
|
||||
*/
|
||||
int ast_sip_session_refresh(struct ast_sip_session *session,
|
||||
ast_sip_session_request_creation_cb on_request_creation,
|
||||
ast_sip_session_response_cb on_response,
|
||||
enum ast_sip_session_refresh_method method,
|
||||
int generate_new_sdp);
|
||||
|
||||
/*!
|
||||
* \brief Send a SIP response
|
||||
*
|
||||
* This will send the SIP response specified in tdata and
|
||||
* call into any registered supplements' outgoing_response callback.
|
||||
*
|
||||
* \param session The session on which to send the response.
|
||||
* \param tdata The response to send
|
||||
*/
|
||||
void ast_sip_session_send_response(struct ast_sip_session *session, pjsip_tx_data *tdata);
|
||||
|
||||
/*!
|
||||
* \brief Send a SIP request
|
||||
*
|
||||
* This will send the SIP request specified in tdata and
|
||||
* call into any registered supplements' outgoing_request callback.
|
||||
*
|
||||
* \param session The session to which to send the request
|
||||
* \param tdata The request to send
|
||||
*/
|
||||
void ast_sip_session_send_request(struct ast_sip_session *session, pjsip_tx_data *tdata);
|
||||
|
||||
/*!
|
||||
* \brief Send a SIP request and get called back when a response is received
|
||||
*
|
||||
* This will send the request out exactly the same as ast_sip_send_request() does.
|
||||
* The difference is that when a response arrives, the specified callback will be
|
||||
* called into
|
||||
*
|
||||
* \param session The session on which to send the request
|
||||
* \param tdata The request to send
|
||||
* \param on_response Callback to be called when a response is received
|
||||
*/
|
||||
void ast_sip_session_send_request_with_cb(struct ast_sip_session *session, pjsip_tx_data *tdata,
|
||||
ast_sip_session_response_cb on_response);
|
||||
|
||||
#endif /* _RES_SIP_SESSION_H */
|
||||
@@ -157,10 +157,15 @@ typedef struct ast_variable *(*sorcery_transform_handler)(struct ast_variable *s
|
||||
/*!
|
||||
* \brief A callback function for when an object set is successfully applied to an object
|
||||
*
|
||||
* \note On a failure return, the state of the object is left undefined. It is a bad
|
||||
* idea to try to use this object.
|
||||
*
|
||||
* \param sorcery Sorcery structure in use
|
||||
* \param obj The object itself
|
||||
* \retval 0 Success
|
||||
* \retval non-zero Failure
|
||||
*/
|
||||
typedef void (*sorcery_apply_handler)(const struct ast_sorcery *sorcery, void *obj);
|
||||
typedef int (*sorcery_apply_handler)(const struct ast_sorcery *sorcery, void *obj);
|
||||
|
||||
/*!
|
||||
* \brief A callback function for copying the contents of one object to another
|
||||
|
||||
@@ -108,6 +108,20 @@ struct ast_threadpool_options {
|
||||
* maximum size.
|
||||
*/
|
||||
int max_size;
|
||||
/*!
|
||||
* \brief Function to call when a thread starts
|
||||
*
|
||||
* This is useful if there is something common that all threads
|
||||
* in a threadpool need to do when they start.
|
||||
*/
|
||||
void (*thread_start)(void);
|
||||
/*!
|
||||
* \brief Function to call when a thread ends
|
||||
*
|
||||
* This is useful if there is common cleanup to execute when
|
||||
* a thread completes
|
||||
*/
|
||||
void (*thread_end)(void);
|
||||
};
|
||||
|
||||
/*!
|
||||
|
||||
Reference in New Issue
Block a user