From 735b30ad71110c2a51404cb8686bbe3cf14b630c Mon Sep 17 00:00:00 2001 From: Mark Michelson Date: Tue, 30 Jul 2013 18:14:50 +0000 Subject: The large GULP->PJSIP renaming effort. The general gist is to have a clear boundary between old SIP stuff and new SIP stuff by having the word "SIP" for old stuff and "PJSIP" for new stuff. Here's a brief rundown of the changes: * The word "Gulp" in dialstrings, functions, and CLI commands is now "PJSIP" * chan_gulp.c is now chan_pjsip.c * Function names in chan_gulp.c that were "gulp_*" are now "chan_pjsip_*" * All files that were "res_sip*" are now "res_pjsip*" * The "res_sip" directory is now "res_pjsip" * Files in the "res_pjsip" directory that began with "sip_*" are now "pjsip_*" * The configuration file is now "pjsip.conf" instead of "res_sip.conf" * The module info for all PJSIP-related files now uses "PJSIP" instead of "SIP" * CLI and AMI commands created by Asterisk's PJSIP modules now have "pjsip" as the starting word instead of "sip" git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@395764 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- include/asterisk/res_pjsip.h | 1502 ++++++++++++++++++++++++++++++ include/asterisk/res_pjsip_exten_state.h | 94 ++ include/asterisk/res_pjsip_pubsub.h | 516 ++++++++++ include/asterisk/res_pjsip_session.h | 561 +++++++++++ include/asterisk/res_sip.h | 1502 ------------------------------ include/asterisk/res_sip_exten_state.h | 94 -- include/asterisk/res_sip_pubsub.h | 516 ---------- include/asterisk/res_sip_session.h | 561 ----------- 8 files changed, 2673 insertions(+), 2673 deletions(-) create mode 100644 include/asterisk/res_pjsip.h create mode 100644 include/asterisk/res_pjsip_exten_state.h create mode 100644 include/asterisk/res_pjsip_pubsub.h create mode 100644 include/asterisk/res_pjsip_session.h delete mode 100644 include/asterisk/res_sip.h delete mode 100644 include/asterisk/res_sip_exten_state.h delete mode 100644 include/asterisk/res_sip_pubsub.h delete mode 100644 include/asterisk/res_sip_session.h (limited to 'include') diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h new file mode 100644 index 000000000..23d1a641e --- /dev/null +++ b/include/asterisk/res_pjsip.h @@ -0,0 +1,1502 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2013, Digium, Inc. + * + * Mark Michelson + * + * 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_H +#define _RES_SIP_H + +#include "asterisk/stringfields.h" +/* Needed for struct ast_sockaddr */ +#include "asterisk/netsock2.h" +/* Needed for linked list macros */ +#include "asterisk/linkedlists.h" +/* Needed for ast_party_id */ +#include "asterisk/channel.h" +/* Needed for ast_sorcery */ +#include "asterisk/sorcery.h" +/* Needed for ast_dnsmgr */ +#include "asterisk/dnsmgr.h" +/* Needed for ast_endpoint */ +#include "asterisk/endpoints.h" +/* Needed for ast_t38_ec_modes */ +#include "asterisk/udptl.h" +/* Needed for pj_sockaddr */ +#include +/* Needed for ast_rtp_dtls_cfg struct */ +#include "asterisk/rtp_engine.h" + +/* Forward declarations of PJSIP stuff */ +struct pjsip_rx_data; +struct pjsip_module; +struct pjsip_tx_data; +struct pjsip_dialog; +struct pjsip_transport; +struct pjsip_tpfactory; +struct pjsip_tls_setting; +struct pjsip_tpselector; + +/*! + * \brief Structure for SIP transport information + */ +struct ast_sip_transport_state { + /*! \brief Transport itself */ + struct pjsip_transport *transport; + + /*! \brief Transport factory */ + struct pjsip_tpfactory *factory; +}; + +#define SIP_SORCERY_DOMAIN_ALIAS_TYPE "domain_alias" + +/*! + * Details about a SIP domain alias + */ +struct ast_sip_domain_alias { + /*! Sorcery object details */ + SORCERY_OBJECT(details); + AST_DECLARE_STRING_FIELDS( + /*! Domain to be aliased to */ + AST_STRING_FIELD(domain); + ); +}; + +/*! \brief Maximum number of ciphers supported for a TLS transport */ +#define SIP_TLS_MAX_CIPHERS 64 + +/* + * \brief Transport to bind to + */ +struct ast_sip_transport { + /*! Sorcery object details */ + SORCERY_OBJECT(details); + AST_DECLARE_STRING_FIELDS( + /*! Certificate of authority list file */ + AST_STRING_FIELD(ca_list_file); + /*! Public certificate file */ + AST_STRING_FIELD(cert_file); + /*! Optional private key of the certificate file */ + AST_STRING_FIELD(privkey_file); + /*! Password to open the private key */ + AST_STRING_FIELD(password); + /*! External signaling address */ + AST_STRING_FIELD(external_signaling_address); + /*! External media address */ + AST_STRING_FIELD(external_media_address); + /*! Optional domain to use for messages if provided could not be found */ + AST_STRING_FIELD(domain); + ); + /*! Type of transport */ + enum ast_transport type; + /*! Address and port to bind to */ + pj_sockaddr host; + /*! Number of simultaneous asynchronous operations */ + unsigned int async_operations; + /*! Optional external port for signaling */ + unsigned int external_signaling_port; + /*! TLS settings */ + pjsip_tls_setting tls; + /*! Configured TLS ciphers */ + pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS]; + /*! Optional local network information, used for NAT purposes */ + struct ast_ha *localnet; + /*! DNS manager for refreshing the external address */ + struct ast_dnsmgr_entry *external_address_refresher; + /*! Optional external address information */ + struct ast_sockaddr external_address; + /*! Transport state information */ + struct ast_sip_transport_state *state; + /*! QOS DSCP TOS bits */ + unsigned int tos; + /*! QOS COS value */ + unsigned int cos; +}; + +/*! + * \brief Structure for SIP nat hook information + */ +struct ast_sip_nat_hook { + /*! Sorcery object details */ + SORCERY_OBJECT(details); + /*! Callback for when a message is going outside of our local network */ + void (*outgoing_external_message)(struct pjsip_tx_data *tdata, struct ast_sip_transport *transport); +}; + +/*! + * \brief Contact associated with an address of record + */ +struct ast_sip_contact { + /*! Sorcery object details, the id is the aor name plus a random string */ + SORCERY_OBJECT(details); + AST_DECLARE_STRING_FIELDS( + /*! Full URI of the contact */ + AST_STRING_FIELD(uri); + ); + /*! Absolute time that this contact is no longer valid after */ + struct timeval expiration_time; + /*! Frequency to send OPTIONS requests to contact. 0 is disabled. */ + unsigned int qualify_frequency; + /*! If true authenticate the qualify if needed */ + int authenticate_qualify; +}; + +#define CONTACT_STATUS "contact_status" + +/*! + * \brief Status type for a contact. + */ +enum ast_sip_contact_status_type { + UNAVAILABLE, + AVAILABLE +}; + +/*! + * \brief A contact's status. + * + * \detail Maintains a contact's current status and round trip time + * if available. + */ +struct ast_sip_contact_status { + SORCERY_OBJECT(details); + /*! Current status for a contact (default - unavailable) */ + enum ast_sip_contact_status_type status; + /*! The round trip start time set before sending a qualify request */ + struct timeval rtt_start; + /*! The round trip time in microseconds */ + int64_t rtt; +}; + +/*! + * \brief A transport to be used for messages to a contact + */ +struct ast_sip_contact_transport { + AST_DECLARE_STRING_FIELDS( + /*! Full URI of the contact */ + AST_STRING_FIELD(uri); + ); + pjsip_transport *transport; +}; + +/*! + * \brief A SIP address of record + */ +struct ast_sip_aor { + /*! Sorcery object details, the id is the AOR name */ + SORCERY_OBJECT(details); + AST_DECLARE_STRING_FIELDS( + /*! Voicemail boxes for this AOR */ + AST_STRING_FIELD(mailboxes); + ); + /*! Minimum expiration time */ + unsigned int minimum_expiration; + /*! Maximum expiration time */ + unsigned int maximum_expiration; + /*! Default contact expiration if one is not provided in the contact */ + unsigned int default_expiration; + /*! Frequency to send OPTIONS requests to AOR contacts. 0 is disabled. */ + unsigned int qualify_frequency; + /*! If true authenticate the qualify if needed */ + int authenticate_qualify; + /*! Maximum number of external contacts, 0 to disable */ + unsigned int max_contacts; + /*! Whether to remove any existing contacts not related to an incoming REGISTER when it comes in */ + unsigned int remove_existing; + /*! Any permanent configured contacts */ + struct ao2_container *permanent_contacts; +}; + +/*! + * \brief DTMF modes for SIP endpoints + */ +enum ast_sip_dtmf_mode { + /*! No DTMF to be used */ + AST_SIP_DTMF_NONE, + /* XXX Should this be 2833 instead? */ + /*! Use RFC 4733 events for DTMF */ + AST_SIP_DTMF_RFC_4733, + /*! Use DTMF in the audio stream */ + AST_SIP_DTMF_INBAND, + /*! Use SIP INFO DTMF (blech) */ + AST_SIP_DTMF_INFO, +}; + +/*! + * \brief Methods of storing SIP digest authentication credentials. + * + * Note that both methods result in MD5 digest authentication being + * used. The two methods simply alter how Asterisk determines the + * credentials for a SIP authentication + */ +enum ast_sip_auth_type { + /*! Credentials stored as a username and password combination */ + AST_SIP_AUTH_TYPE_USER_PASS, + /*! Credentials stored as an MD5 sum */ + AST_SIP_AUTH_TYPE_MD5, + /*! Credentials not stored this is a fake auth */ + AST_SIP_AUTH_TYPE_ARTIFICIAL +}; + +#define SIP_SORCERY_AUTH_TYPE "auth" + +struct ast_sip_auth { + /* Sorcery ID of the auth is its name */ + SORCERY_OBJECT(details); + AST_DECLARE_STRING_FIELDS( + /* Identification for these credentials */ + AST_STRING_FIELD(realm); + /* Authentication username */ + AST_STRING_FIELD(auth_user); + /* Authentication password */ + AST_STRING_FIELD(auth_pass); + /* Authentication credentials in MD5 format (hash of user:realm:pass) */ + AST_STRING_FIELD(md5_creds); + ); + /* The time period (in seconds) that a nonce may be reused */ + unsigned int nonce_lifetime; + /* Used to determine what to use when authenticating */ + enum ast_sip_auth_type type; +}; + +struct ast_sip_auth_array { + /*! Array of Sorcery IDs of auth sections */ + const char **names; + /*! Number of credentials in the array */ + unsigned int num; +}; + +/*! + * \brief Different methods by which incoming requests can be matched to endpoints + */ +enum ast_sip_endpoint_identifier_type { + /*! Identify based on user name in From header */ + AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME = (1 << 0), +}; + +enum ast_sip_session_refresh_method { + /*! Use reinvite to negotiate direct media */ + AST_SIP_SESSION_REFRESH_METHOD_INVITE, + /*! Use UPDATE to negotiate direct media */ + AST_SIP_SESSION_REFRESH_METHOD_UPDATE, +}; + +enum ast_sip_direct_media_glare_mitigation { + /*! Take no special action to mitigate reinvite glare */ + AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_NONE, + /*! Do not send an initial direct media session refresh on outgoing call legs + * Subsequent session refreshes will be sent no matter the session direction + */ + AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_OUTGOING, + /*! Do not send an initial direct media session refresh on incoming call legs + * Subsequent session refreshes will be sent no matter the session direction + */ + AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_INCOMING, +}; + +enum ast_sip_session_media_encryption { + /*! Invalid media encryption configuration */ + AST_SIP_MEDIA_TRANSPORT_INVALID = 0, + /*! Do not allow any encryption of session media */ + AST_SIP_MEDIA_ENCRYPT_NONE, + /*! Offer SDES-encrypted session media */ + AST_SIP_MEDIA_ENCRYPT_SDES, + /*! Offer encrypted session media with datagram TLS key exchange */ + AST_SIP_MEDIA_ENCRYPT_DTLS, +}; + +/*! + * \brief Session timers options + */ +struct ast_sip_timer_options { + /*! Minimum session expiration period, in seconds */ + unsigned int min_se; + /*! Session expiration period, in seconds */ + unsigned int sess_expires; +}; + +/*! + * \brief Endpoint configuration for SIP extensions. + * + * SIP extensions, in this case refers to features + * indicated in Supported or Required headers. + */ +struct ast_sip_endpoint_extensions { + /*! Enabled SIP extensions */ + unsigned int flags; + /*! Timer options */ + struct ast_sip_timer_options timer; +}; + +/*! + * \brief Endpoint configuration for unsolicited MWI + */ +struct ast_sip_mwi_configuration { + AST_DECLARE_STRING_FIELDS( + /*! Configured voicemail boxes for this endpoint. Used for MWI */ + AST_STRING_FIELD(mailboxes); + /*! Username to use when sending MWI NOTIFYs to this endpoint */ + AST_STRING_FIELD(fromuser); + ); + /* Should mailbox states be combined into a single notification? */ + unsigned int aggregate; +}; + +/*! + * \brief Endpoint subscription configuration + */ +struct ast_sip_endpoint_subscription_configuration { + /*! Indicates if endpoint is allowed to initiate subscriptions */ + unsigned int allow; + /*! The minimum allowed expiration for subscriptions from endpoint */ + unsigned int minexpiry; + /*! Message waiting configuration */ + struct ast_sip_mwi_configuration mwi; +}; + +/*! + * \brief NAT configuration options for endpoints + */ +struct ast_sip_endpoint_nat_configuration { + /*! Whether to force using the source IP address/port for sending responses */ + unsigned int force_rport; + /*! Whether to rewrite the Contact header with the source IP address/port or not */ + unsigned int rewrite_contact; +}; + +/*! + * \brief Party identification options for endpoints + * + * This includes caller ID, connected line, and redirecting-related options + */ +struct ast_sip_endpoint_id_configuration { + struct ast_party_id self; + /*! Do we accept identification information from this endpoint */ + unsigned int trust_inbound; + /*! Do we send private identification information to this endpoint? */ + unsigned int trust_outbound; + /*! Do we send P-Asserted-Identity headers to this endpoint? */ + unsigned int send_pai; + /*! Do we send Remote-Party-ID headers to this endpoint? */ + unsigned int send_rpid; + /*! Do we add Diversion headers to applicable outgoing requests/responses? */ + unsigned int send_diversion; + /*! When performing connected line update, which method should be used */ + enum ast_sip_session_refresh_method refresh_method; +}; + +/*! + * \brief Call pickup configuration options for endpoints + */ +struct ast_sip_endpoint_pickup_configuration { + /*! Call group */ + ast_group_t callgroup; + /*! Pickup group */ + ast_group_t pickupgroup; + /*! Named call group */ + struct ast_namedgroups *named_callgroups; + /*! Named pickup group */ + struct ast_namedgroups *named_pickupgroups; +}; + +/*! + * \brief Configuration for one-touch INFO recording + */ +struct ast_sip_info_recording_configuration { + AST_DECLARE_STRING_FIELDS( + /*! Feature to enact when one-touch recording INFO with Record: On is received */ + AST_STRING_FIELD(onfeature); + /*! Feature to enact when one-touch recording INFO with Record: Off is received */ + AST_STRING_FIELD(offfeature); + ); + /*! Is one-touch recording permitted? */ + unsigned int enabled; +}; + +/*! + * \brief Endpoint configuration options for INFO packages + */ +struct ast_sip_endpoint_info_configuration { + /*! Configuration for one-touch recording */ + struct ast_sip_info_recording_configuration recording; +}; + +/*! + * \brief RTP configuration for SIP endpoints + */ +struct ast_sip_media_rtp_configuration { + AST_DECLARE_STRING_FIELDS( + /*! Configured RTP engine for this endpoint. */ + AST_STRING_FIELD(engine); + ); + /*! Whether IPv6 RTP is enabled or not */ + unsigned int ipv6; + /*! Whether symmetric RTP is enabled or not */ + unsigned int symmetric; + /*! Whether ICE support is enabled or not */ + unsigned int ice_support; + /*! Whether to use the "ptime" attribute received from the endpoint or not */ + unsigned int use_ptime; + /*! Do we use AVPF exclusively for this endpoint? */ + unsigned int use_avpf; + /*! \brief DTLS-SRTP configuration information */ + struct ast_rtp_dtls_cfg dtls_cfg; + /*! Should SRTP use a 32 byte tag instead of an 80 byte tag? */ + unsigned int srtp_tag_32; + /*! Do we use media encryption? what type? */ + enum ast_sip_session_media_encryption encryption; +}; + +/*! + * \brief Direct media options for SIP endpoints + */ +struct ast_sip_direct_media_configuration { + /*! Boolean indicating if direct_media is permissible */ + unsigned int enabled; + /*! When using direct media, which method should be used */ + enum ast_sip_session_refresh_method method; + /*! Take steps to mitigate glare for direct media */ + enum ast_sip_direct_media_glare_mitigation glare_mitigation; + /*! Do not attempt direct media session refreshes if a media NAT is detected */ + unsigned int disable_on_nat; +}; + +struct ast_sip_t38_configuration { + /*! Whether T.38 UDPTL support is enabled or not */ + unsigned int enabled; + /*! Error correction setting for T.38 UDPTL */ + enum ast_t38_ec_modes error_correction; + /*! Explicit T.38 max datagram value, may be 0 to indicate the remote side can be trusted */ + unsigned int maxdatagram; + /*! Whether NAT Support is enabled for T.38 UDPTL sessions or not */ + unsigned int nat; + /*! Whether to use IPv6 for UDPTL or not */ + unsigned int ipv6; +}; + +/*! + * \brief Media configuration for SIP endpoints + */ +struct ast_sip_endpoint_media_configuration { + AST_DECLARE_STRING_FIELDS( + /*! Optional external media address to use in SDP */ + AST_STRING_FIELD(external_address); + /*! SDP origin username */ + AST_STRING_FIELD(sdpowner); + /*! SDP session name */ + AST_STRING_FIELD(sdpsession); + ); + /*! RTP media configuration */ + struct ast_sip_media_rtp_configuration rtp; + /*! Direct media options */ + struct ast_sip_direct_media_configuration direct_media; + /*! T.38 (FoIP) options */ + struct ast_sip_t38_configuration t38; + /*! Codec preferences */ + struct ast_codec_pref prefs; + /*! Configured codecs */ + struct ast_format_cap *codecs; + /*! DSCP TOS bits for audio streams */ + unsigned int tos_audio; + /*! Priority for audio streams */ + unsigned int cos_audio; + /*! DSCP TOS bits for video streams */ + unsigned int tos_video; + /*! Priority for video streams */ + unsigned int cos_video; +}; + +/*! + * \brief An entity with which Asterisk communicates + */ +struct ast_sip_endpoint { + SORCERY_OBJECT(details); + AST_DECLARE_STRING_FIELDS( + /*! Context to send incoming calls to */ + AST_STRING_FIELD(context); + /*! Name of an explicit transport to use */ + AST_STRING_FIELD(transport); + /*! Outbound proxy to use */ + AST_STRING_FIELD(outbound_proxy); + /*! Explicit AORs to dial if none are specified */ + AST_STRING_FIELD(aors); + /*! Musiconhold class to suggest that the other side use when placing on hold */ + AST_STRING_FIELD(mohsuggest); + /*! Configured tone zone for this endpoint. */ + AST_STRING_FIELD(zone); + /*! Configured language for this endpoint. */ + AST_STRING_FIELD(language); + /*! Default username to place in From header */ + AST_STRING_FIELD(fromuser); + /*! Domain to place in From header */ + AST_STRING_FIELD(fromdomain); + ); + /*! Configuration for extensions */ + struct ast_sip_endpoint_extensions extensions; + /*! Configuration relating to media */ + struct ast_sip_endpoint_media_configuration media; + /*! SUBSCRIBE/NOTIFY configuration options */ + struct ast_sip_endpoint_subscription_configuration subscription; + /*! NAT configuration */ + struct ast_sip_endpoint_nat_configuration nat; + /*! Party identification options */ + struct ast_sip_endpoint_id_configuration id; + /*! Configuration options for INFO packages */ + struct ast_sip_endpoint_info_configuration info; + /*! Call pickup configuration */ + struct ast_sip_endpoint_pickup_configuration pickup; + /*! Inbound authentication credentials */ + struct ast_sip_auth_array inbound_auths; + /*! Outbound authentication credentials */ + struct ast_sip_auth_array outbound_auths; + /*! DTMF mode to use with this endpoint */ + enum ast_sip_dtmf_mode dtmf; + /*! Method(s) by which the endpoint should be identified. */ + enum ast_sip_endpoint_identifier_type ident_method; + /*! Boolean indicating if ringing should be sent as inband progress */ + unsigned int inband_progress; + /*! Pointer to the persistent Asterisk endpoint */ + struct ast_endpoint *persistent; + /*! The number of channels at which busy device state is returned */ + unsigned int devicestate_busy_at; + /*! Whether fax detection is enabled or not (CNG tone detection) */ + unsigned int faxdetect; + /*! Determines if transfers (using REFER) are allowed by this endpoint */ + unsigned int allowtransfer; +}; + +/*! + * \brief Initialize an auth array with the configured values. + * + * \param array Array to initialize + * \param auth_names Comma-separated list of names to set in the array + * \retval 0 Success + * \retval non-zero Failure + */ +int ast_sip_auth_array_init(struct ast_sip_auth_array *array, const char *auth_names); + +/*! + * \brief Free contents of an auth array. + * + * \param array Array whose contents are to be freed + */ +void ast_sip_auth_array_destroy(struct ast_sip_auth_array *array); + +/*! + * \brief Possible returns from ast_sip_check_authentication + */ +enum ast_sip_check_auth_result { + /*! Authentication needs to be challenged */ + AST_SIP_AUTHENTICATION_CHALLENGE, + /*! Authentication succeeded */ + AST_SIP_AUTHENTICATION_SUCCESS, + /*! Authentication failed */ + AST_SIP_AUTHENTICATION_FAILED, + /*! Authentication encountered some internal error */ + AST_SIP_AUTHENTICATION_ERROR, +}; + +/*! + * \brief An interchangeable way of handling digest authentication for SIP. + * + * An authenticator is responsible for filling in the callbacks provided below. Each is called from a publicly available + * function in res_sip. The authenticator can use configuration or other local policy to determine whether authentication + * should take place and what credentials should be used when challenging and authenticating a request. + */ +struct ast_sip_authenticator { + /*! + * \brief Check if a request requires authentication + * See ast_sip_requires_authentication for more details + */ + int (*requires_authentication)(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata); + /*! + * \brief Check that an incoming request passes authentication. + * + * The tdata parameter is useful for adding information such as digest challenges. + * + * \param endpoint The endpoint sending the incoming request + * \param rdata The incoming request + * \param tdata Tentative outgoing request. + */ + enum ast_sip_check_auth_result (*check_authentication)(struct ast_sip_endpoint *endpoint, + pjsip_rx_data *rdata, pjsip_tx_data *tdata); +}; + +/*! + * \brief an interchangeable way of responding to authentication challenges + * + * An outbound authenticator takes incoming challenges and formulates a new SIP request with + * credentials. + */ +struct ast_sip_outbound_authenticator { + /*! + * \brief Create a new request with authentication credentials + * + * \param auths An array of IDs of auth sorcery objects + * \param challenge The SIP response with authentication challenge(s) + * \param tsx The transaction in which the challenge was received + * \param new_request The new SIP request with challenge response(s) + * \retval 0 Successfully created new request + * \retval -1 Failed to create a new request + */ + int (*create_request_with_auth)(const struct ast_sip_auth_array *auths, struct pjsip_rx_data *challenge, + struct pjsip_transaction *tsx, struct pjsip_tx_data **new_request); +}; + +/*! + * \brief An entity responsible for identifying the source of a SIP message + */ +struct ast_sip_endpoint_identifier { + /*! + * \brief Callback used to identify the source of a message. + * See ast_sip_identify_endpoint for more details + */ + struct ast_sip_endpoint *(*identify_endpoint)(pjsip_rx_data *rdata); +}; + +#define SIP_SORCERY_SECURITY_TYPE "security" + +/*! + * \brief SIP security details and configuration. + */ +struct ast_sip_security { + SORCERY_OBJECT(details); + struct ast_acl_list *acl; + struct ast_acl_list *contact_acl; +}; + +/*! + * \brief Register a SIP service in Asterisk. + * + * This is more-or-less a wrapper around pjsip_endpt_register_module(). + * Registering a service makes it so that PJSIP will call into the + * service at appropriate times. For more information about PJSIP module + * callbacks, see the PJSIP documentation. Asterisk modules that call + * this function will likely do so at module load time. + * + * \param module The module that is to be registered with PJSIP + * \retval 0 Success + * \retval -1 Failure + */ +int ast_sip_register_service(pjsip_module *module); + +/*! + * This is the opposite of ast_sip_register_service(). Unregistering a + * service means that PJSIP will no longer call into the module any more. + * This will likely occur when an Asterisk module is unloaded. + * + * \param module The PJSIP module to unregister + */ +void ast_sip_unregister_service(pjsip_module *module); + +/*! + * \brief Register a SIP authenticator + * + * An authenticator has three main purposes: + * 1) Determining if authentication should be performed on an incoming request + * 2) Gathering credentials necessary for issuing an authentication challenge + * 3) Authenticating a request that has credentials + * + * Asterisk provides a default authenticator, but it may be replaced by a + * custom one if desired. + * + * \param auth The authenticator to register + * \retval 0 Success + * \retval -1 Failure + */ +int ast_sip_register_authenticator(struct ast_sip_authenticator *auth); + +/*! + * \brief Unregister a SIP authenticator + * + * When there is no authenticator registered, requests cannot be challenged + * or authenticated. + * + * \param auth The authenticator to unregister + */ +void ast_sip_unregister_authenticator(struct ast_sip_authenticator *auth); + + /*! + * \brief Register an outbound SIP authenticator + * + * An outbound authenticator is responsible for creating responses to + * authentication challenges by remote endpoints. + * + * \param auth The authenticator to register + * \retval 0 Success + * \retval -1 Failure + */ +int ast_sip_register_outbound_authenticator(struct ast_sip_outbound_authenticator *outbound_auth); + +/*! + * \brief Unregister an outbound SIP authenticator + * + * When there is no outbound authenticator registered, authentication challenges + * will be handled as any other final response would be. + * + * \param auth The authenticator to unregister + */ +void ast_sip_unregister_outbound_authenticator(struct ast_sip_outbound_authenticator *auth); + +/*! + * \brief Register a SIP endpoint identifier + * + * An endpoint identifier's purpose is to determine which endpoint a given SIP + * message has come from. + * + * Multiple endpoint identifiers may be registered so that if an endpoint + * cannot be identified by one identifier, it may be identified by another. + * + * Asterisk provides two endpoint identifiers. One identifies endpoints based + * on the user part of the From header URI. The other identifies endpoints based + * on the source IP address. + * + * If the order in which endpoint identifiers is run is important to you, then + * be sure to load individual endpoint identifier modules in the order you wish + * for them to be run in modules.conf + * + * \param identifier The SIP endpoint identifier to register + * \retval 0 Success + * \retval -1 Failure + */ +int ast_sip_register_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier); + +/*! + * \brief Unregister a SIP endpoint identifier + * + * This stops an endpoint identifier from being used. + * + * \param identifier The SIP endoint identifier to unregister + */ +void ast_sip_unregister_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier); + +/*! + * \brief Allocate a new SIP endpoint + * + * This will return an endpoint with its refcount increased by one. This reference + * can be released using ao2_ref(). + * + * \param name The name of the endpoint. + * \retval NULL Endpoint allocation failed + * \retval non-NULL The newly allocated endpoint + */ +void *ast_sip_endpoint_alloc(const char *name); + +/*! + * \brief Get a pointer to the PJSIP endpoint. + * + * This is useful when modules have specific information they need + * to register with the PJSIP core. + * \retval NULL endpoint has not been created yet. + * \retval non-NULL PJSIP endpoint. + */ +pjsip_endpoint *ast_sip_get_pjsip_endpoint(void); + +/*! + * \brief Get a pointer to the SIP sorcery structure. + * + * \retval NULL sorcery has not been initialized + * \retval non-NULL sorcery structure + */ +struct ast_sorcery *ast_sip_get_sorcery(void); + +/*! + * \brief Initialize transport support on a sorcery instance + * + * \param sorcery The sorcery instance + * + * \retval -1 failure + * \retval 0 success + */ +int ast_sip_initialize_sorcery_transport(struct ast_sorcery *sorcery); + +/*! + * \brief Initialize qualify support on a sorcery instance + * + * \param sorcery The sorcery instance + * + * \retval -1 failure + * \retval 0 success + */ +int ast_sip_initialize_sorcery_qualify(struct ast_sorcery *sorcery); + +/*! + * \brief Initialize location support on a sorcery instance + * + * \param sorcery The sorcery instance + * + * \retval -1 failure + * \retval 0 success + */ +int ast_sip_initialize_sorcery_location(struct ast_sorcery *sorcery); + +/*! + * \brief Retrieve a named AOR + * + * \param aor_name Name of the AOR + * + * \retval NULL if not found + * \retval non-NULL if found + */ +struct ast_sip_aor *ast_sip_location_retrieve_aor(const char *aor_name); + +/*! + * \brief Retrieve the first bound contact for an AOR + * + * \param aor Pointer to the AOR + * \retval NULL if no contacts available + * \retval non-NULL if contacts available + */ +struct ast_sip_contact *ast_sip_location_retrieve_first_aor_contact(const struct ast_sip_aor *aor); + +/*! + * \brief Retrieve all contacts currently available for an AOR + * + * \param aor Pointer to the AOR + * + * \retval NULL if no contacts available + * \retval non-NULL if contacts available + */ +struct ao2_container *ast_sip_location_retrieve_aor_contacts(const struct ast_sip_aor *aor); + +/*! + * \brief Retrieve the first bound contact from a list of AORs + * + * \param aor_list A comma-separated list of AOR names + * \retval NULL if no contacts available + * \retval non-NULL if contacts available + */ +struct ast_sip_contact *ast_sip_location_retrieve_contact_from_aor_list(const char *aor_list); + +/*! + * \brief Retrieve a named contact + * + * \param contact_name Name of the contact + * + * \retval NULL if not found + * \retval non-NULL if found + */ +struct ast_sip_contact *ast_sip_location_retrieve_contact(const char *contact_name); + +/*! + * \brief Add a transport for a contact to use + */ + +void ast_sip_location_add_contact_transport(struct ast_sip_contact_transport *ct); + +/*! + * \brief Delete a transport for a contact that went away + */ +void ast_sip_location_delete_contact_transport(struct ast_sip_contact_transport *ct); + +/*! + * \brief Retrieve a contact_transport, by URI + * + * \param contact_uri URI of the contact + * + * \retval NULL if not found + * \retval non-NULL if found + */ +struct ast_sip_contact_transport *ast_sip_location_retrieve_contact_transport_by_uri(const char *contact_uri); + +/*! + * \brief Retrieve a contact_transport, by transport + * + * \param transport transport the contact uses + * + * \retval NULL if not found + * \retval non-NULL if found + */ +struct ast_sip_contact_transport *ast_sip_location_retrieve_contact_transport_by_transport(pjsip_transport *transport); + +/*! + * \brief Add a new contact to an AOR + * + * \param aor Pointer to the AOR + * \param uri Full contact URI + * \param expiration_time Optional expiration time of the contact + * + * \retval -1 failure + * \retval 0 success + */ +int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time); + +/*! + * \brief Update a contact + * + * \param contact New contact object with details + * + * \retval -1 failure + * \retval 0 success + */ +int ast_sip_location_update_contact(struct ast_sip_contact *contact); + +/*! +* \brief Delete a contact +* +* \param contact Contact object to delete +* +* \retval -1 failure +* \retval 0 success +*/ +int ast_sip_location_delete_contact(struct ast_sip_contact *contact); + +/*! + * \brief Initialize domain aliases support on a sorcery instance + * + * \param sorcery The sorcery instance + * + * \retval -1 failure + * \retval 0 success + */ +int ast_sip_initialize_sorcery_domain_alias(struct ast_sorcery *sorcery); + +/*! + * \brief Initialize authentication support on a sorcery instance + * + * \param sorcery The sorcery instance + * + * \retval -1 failure + * \retval 0 success + */ +int ast_sip_initialize_sorcery_auth(struct ast_sorcery *sorcery); + +/*! + * \brief Initialize security support on a sorcery instance + * + * \param sorcery The sorcery instance + * + * \retval -1 failure + * \retval 0 success + */ +int ast_sip_initialize_sorcery_security(struct ast_sorcery *sorcery); + +/*! + * \brief Callback called when an outbound request with authentication credentials is to be sent in dialog + * + * This callback will have the created request on it. The callback's purpose is to do any extra + * housekeeping that needs to be done as well as to send the request out. + * + * This callback is only necessary if working with a PJSIP API that sits between the application + * and the dialog layer. + * + * \param dlg The dialog to which the request belongs + * \param tdata The created request to be sent out + * \param user_data Data supplied with the callback + * + * \retval 0 Success + * \retval -1 Failure + */ +typedef int (*ast_sip_dialog_outbound_auth_cb)(pjsip_dialog *dlg, pjsip_tx_data *tdata, void *user_data); + +/*! + * \brief Set up outbound authentication on a SIP dialog + * + * This sets up the infrastructure so that all requests associated with a created dialog + * can be re-sent with authentication credentials if the original request is challenged. + * + * \param dlg The dialog on which requests will be authenticated + * \param endpoint The endpoint whom this dialog pertains to + * \param cb Callback to call to send requests with authentication + * \param user_data Data to be provided to the callback when it is called + * + * \retval 0 Success + * \retval -1 Failure + */ +int ast_sip_dialog_setup_outbound_authentication(pjsip_dialog *dlg, const struct ast_sip_endpoint *endpoint, + ast_sip_dialog_outbound_auth_cb cb, void *user_data); + +/*! + * \brief Initialize the distributor module + * + * The distributor module is responsible for taking an incoming + * SIP message and placing it into the threadpool. Once in the threadpool, + * the distributor will perform endpoint lookups and authentication, and + * then distribute the message up the stack to any further modules. + * + * \retval -1 Failure + * \retval 0 Success + */ +int ast_sip_initialize_distributor(void); + +/*! + * \brief Destruct the distributor module. + * + * Unregisters pjsip modules and cleans up any allocated resources. + */ +void ast_sip_destroy_distributor(void); + +/*! + * \brief Retrieves a reference to the artificial auth. + * + * \retval The artificial auth + */ +struct ast_sip_auth *ast_sip_get_artificial_auth(void); + +/*! + * \brief Retrieves a reference to the artificial endpoint. + * + * \retval The artificial endpoint + */ +struct ast_sip_endpoint *ast_sip_get_artificial_endpoint(void); + +/*! + * \page Threading model for SIP + * + * There are three major types of threads that SIP will have to deal with: + * \li Asterisk threads + * \li PJSIP threads + * \li SIP threadpool threads (a.k.a. "servants") + * + * \par Asterisk Threads + * + * Asterisk threads are those that originate from outside of SIP but within + * Asterisk. The most common of these threads are PBX (channel) threads and + * the autoservice thread. Most interaction with these threads will be through + * channel technology callbacks. Within these threads, it is fine to handle + * Asterisk data from outside of SIP, but any handling of SIP data should be + * left to servants, \b especially if you wish to call into PJSIP for anything. + * Asterisk threads are not registered with PJLIB, so attempting to call into + * PJSIP will cause an assertion to be triggered, thus causing the program to + * crash. + * + * \par PJSIP Threads + * + * PJSIP threads are those that originate from handling of PJSIP events, such + * as an incoming SIP request or response, or a transaction timeout. The role + * of these threads is to process information as quickly as possible so that + * the next item on the SIP socket(s) can be serviced. On incoming messages, + * Asterisk automatically will push the request to a servant thread. When your + * module callback is called, processing will already be in a servant. However, + * for other PSJIP events, such as transaction state changes due to timer + * expirations, your module will be called into from a PJSIP thread. If you + * are called into from a PJSIP thread, then you should push whatever processing + * is needed to a servant as soon as possible. You can discern if you are currently + * in a SIP servant thread using the \ref ast_sip_thread_is_servant function. + * + * \par Servants + * + * Servants are where the bulk of SIP work should be performed. These threads + * exist in order to do the work that Asterisk threads and PJSIP threads hand + * off to them. Servant threads register themselves with PJLIB, meaning that + * they are capable of calling PJSIP and PJLIB functions if they wish. + * + * \par Serializer + * + * Tasks are handed off to servant threads using the API call \ref ast_sip_push_task. + * The first parameter of this call is a serializer. If this pointer + * is NULL, then the work will be handed off to whatever servant can currently handle + * the task. If this pointer is non-NULL, then the task will not be executed until + * previous tasks pushed with the same serializer have completed. For more information + * on serializers and the benefits they provide, see \ref ast_threadpool_serializer + * + * \note + * + * Do not make assumptions about individual threads based on a corresponding serializer. + * In other words, just because several tasks use the same serializer when being pushed + * to servants, it does not mean that the same thread is necessarily going to execute those + * tasks, even though they are all guaranteed to be executed in sequence. + */ + +/*! + * \brief Create a new serializer for SIP tasks + * + * See \ref ast_threadpool_serializer for more information on serializers. + * SIP creates serializers so that tasks operating on similar data will run + * in sequence. + * + * \retval NULL Failure + * \retval non-NULL Newly-created serializer + */ +struct ast_taskprocessor *ast_sip_create_serializer(void); + +/*! + * \brief Set a serializer on a SIP dialog so requests and responses are automatically serialized + * + * Passing a NULL serializer is a way to remove a serializer from a dialog. + * + * \param dlg The SIP dialog itself + * \param serializer The serializer to use + */ +void ast_sip_dialog_set_serializer(pjsip_dialog *dlg, struct ast_taskprocessor *serializer); + +/*! + * \brief Set an endpoint on a SIP dialog so in-dialog requests do not undergo endpoint lookup. + * + * \param dlg The SIP dialog itself + * \param endpoint The endpoint that this dialog is communicating with + */ +void ast_sip_dialog_set_endpoint(pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint); + +/*! + * \brief Get the endpoint associated with this dialog + * + * This function increases the refcount of the endpoint by one. Release + * the reference once you are finished with the endpoint. + * + * \param dlg The SIP dialog from which to retrieve the endpoint + * \retval NULL No endpoint associated with this dialog + * \retval non-NULL The endpoint. + */ +struct ast_sip_endpoint *ast_sip_dialog_get_endpoint(pjsip_dialog *dlg); + +/*! + * \brief Pushes a task to SIP servants + * + * This uses the serializer provided to determine how to push the task. + * If the serializer is NULL, then the task will be pushed to the + * servants directly. If the serializer is non-NULL, then the task will be + * queued behind other tasks associated with the same serializer. + * + * \param serializer The serializer to which the task belongs. Can be NULL + * \param sip_task The task to execute + * \param task_data The parameter to pass to the task when it executes + * \retval 0 Success + * \retval -1 Failure + */ +int ast_sip_push_task(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data); + +/*! + * \brief Push a task to SIP servants and wait for it to complete + * + * Like \ref ast_sip_push_task except that it blocks until the task completes. + * + * \warning \b Never use this function in a SIP servant thread. This can potentially + * cause a deadlock. If you are in a SIP servant thread, just call your function + * in-line. + * + * \param serializer The SIP serializer to which the task belongs. May be NULL. + * \param sip_task The task to execute + * \param task_data The parameter to pass to the task when it executes + * \retval 0 Success + * \retval -1 Failure + */ +int ast_sip_push_task_synchronous(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data); + +/*! + * \brief Determine if the current thread is a SIP servant thread + * + * \retval 0 This is not a SIP servant thread + * \retval 1 This is a SIP servant thread + */ +int ast_sip_thread_is_servant(void); + +/*! + * \brief SIP body description + * + * This contains a type and subtype that will be added as + * the "Content-Type" for the message as well as the body + * text. + */ +struct ast_sip_body { + /*! Type of the body, such as "application" */ + const char *type; + /*! Subtype of the body, such as "sdp" */ + const char *subtype; + /*! The text to go in the body */ + const char *body_text; +}; + +/*! + * \brief General purpose method for creating a dialog with an endpoint + * + * \param endpoint A pointer to the endpoint + * \param aor_name Optional name of the AOR to target, may even be an explicit SIP URI + * \param request_user Optional user to place into the target URI + * + * \retval non-NULL success + * \retval NULL failure + */ + pjsip_dialog *ast_sip_create_dialog(const struct ast_sip_endpoint *endpoint, const char *aor_name, const char *request_user); + +/*! + * \brief General purpose method for creating a SIP request + * + * Its typical use would be to create one-off requests such as an out of dialog + * SIP MESSAGE. + * + * The request can either be in- or out-of-dialog. If in-dialog, the + * dlg parameter MUST be present. If out-of-dialog the endpoint parameter + * MUST be present. If both are present, then we will assume that the message + * is to be sent in-dialog. + * + * The uri parameter can be specified if the request should be sent to an explicit + * URI rather than one configured on the endpoint. + * + * \param method The method of the SIP request to send + * \param dlg Optional. If specified, the dialog on which to request the message. + * \param endpoint Optional. If specified, the request will be created out-of-dialog + * to the endpoint. + * \param uri Optional. If specified, the request will be sent to this URI rather + * this value. + * than one configured for the endpoint. + * \param[out] tdata The newly-created request + * \retval 0 Success + * \retval -1 Failure + */ +int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg, + struct ast_sip_endpoint *endpoint, const char *uri, + pjsip_tx_data **tdata); + +/*! + * \brief General purpose method for sending a SIP request + * + * This is a companion function for \ref ast_sip_create_request. The request + * created there can be passed to this function, though any request may be + * passed in. + * + * This will automatically set up handling outbound authentication challenges if + * they arrive. + * + * \param tdata The request to send + * \param dlg Optional. If specified, the dialog on which the request should be sent + * \param endpoint Optional. If specified, the request is sent out-of-dialog to the endpoint. + * \retval 0 Success + * \retval -1 Failure + */ +int ast_sip_send_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint); + +/*! + * \brief Determine if an incoming request requires authentication + * + * This calls into the registered authenticator's requires_authentication callback + * in order to determine if the request requires authentication. + * + * If there is no registered authenticator, then authentication will be assumed + * not to be required. + * + * \param endpoint The endpoint from which the request originates + * \param rdata The incoming SIP request + * \retval non-zero The request requires authentication + * \retval 0 The request does not require authentication + */ +int ast_sip_requires_authentication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata); + +/*! + * \brief Method to determine authentication status of an incoming request + * + * This will call into a registered authenticator. The registered authenticator will + * do what is necessary to determine whether the incoming request passes authentication. + * A tentative response is passed into this function so that if, say, a digest authentication + * challenge should be sent in the ensuing response, it can be added to the response. + * + * \param endpoint The endpoint from the request was sent + * \param rdata The request to potentially authenticate + * \param tdata Tentative response to the request + * \return The result of checking authentication. + */ +enum ast_sip_check_auth_result ast_sip_check_authentication(struct ast_sip_endpoint *endpoint, + pjsip_rx_data *rdata, pjsip_tx_data *tdata); + +/*! + * \brief Create a response to an authentication challenge + * + * This will call into an outbound authenticator's create_request_with_auth callback + * to create a new request with authentication credentials. See the create_request_with_auth + * callback in the \ref ast_sip_outbound_authenticator structure for details about + * the parameters and return values. + */ +int ast_sip_create_request_with_auth(const struct ast_sip_auth_array *auths, pjsip_rx_data *challenge, + pjsip_transaction *tsx, pjsip_tx_data **new_request); + +/*! + * \brief Determine the endpoint that has sent a SIP message + * + * This will call into each of the registered endpoint identifiers' + * identify_endpoint() callbacks until one returns a non-NULL endpoint. + * This will return an ao2 object. Its reference count will need to be + * decremented when completed using the endpoint. + * + * \param rdata The inbound SIP message to use when identifying the endpoint. + * \retval NULL No matching endpoint + * \retval non-NULL The matching endpoint + */ +struct ast_sip_endpoint *ast_sip_identify_endpoint(pjsip_rx_data *rdata); + +/*! + * \brief Add a header to an outbound SIP message + * + * \param tdata The message to add the header to + * \param name The header name + * \param value The header value + * \retval 0 Success + * \retval -1 Failure + */ +int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value); + +/*! + * \brief Add a body to an outbound SIP message + * + * If this is called multiple times, the latest body will replace the current + * body. + * + * \param tdata The message to add the body to + * \param body The message body to add + * \retval 0 Success + * \retval -1 Failure + */ +int ast_sip_add_body(pjsip_tx_data *tdata, const struct ast_sip_body *body); + +/*! + * \brief Add a multipart body to an outbound SIP message + * + * This will treat each part of the input array as part of a multipart body and + * add each part to the SIP message. + * + * \param tdata The message to add the body to + * \param bodies The parts of the body to add + * \retval 0 Success + * \retval -1 Failure + */ +int ast_sip_add_body_multipart(pjsip_tx_data *tdata, const struct ast_sip_body *bodies[], int num_bodies); + +/*! + * \brief Append body data to a SIP message + * + * This acts mostly the same as ast_sip_add_body, except that rather than replacing + * a body if it currently exists, it appends data to an existing body. + * + * \param tdata The message to append the body to + * \param body The string to append to the end of the current body + * \retval 0 Success + * \retval -1 Failure + */ +int ast_sip_append_body(pjsip_tx_data *tdata, const char *body_text); + +/*! + * \brief Copy a pj_str_t into a standard character buffer. + * + * pj_str_t is not NULL-terminated. Any place that expects a NULL- + * terminated string needs to have the pj_str_t copied into a separate + * buffer. + * + * This method copies the pj_str_t contents into the destination buffer + * and NULL-terminates the buffer. + * + * \param dest The destination buffer + * \param src The pj_str_t to copy + * \param size The size of the destination buffer. + */ +void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size); + +/*! + * \brief Get the looked-up endpoint on an out-of dialog request or response + * + * The function may ONLY be called on out-of-dialog requests or responses. For + * in-dialog requests and responses, it is required that the user of the dialog + * has the looked-up endpoint stored locally. + * + * This function should never return NULL if the message is out-of-dialog. It will + * always return NULL if the message is in-dialog. + * + * This function will increase the reference count of the returned endpoint by one. + * Release your reference using the ao2_ref function when finished. + * + * \param rdata Out-of-dialog request or response + * \return The looked up endpoint + */ +struct ast_sip_endpoint *ast_pjsip_rdata_get_endpoint(pjsip_rx_data *rdata); + +/*! + * \brief Retrieve any endpoints available to sorcery. + * + * \retval Endpoints available to sorcery, NULL if no endpoints found. + */ +struct ao2_container *ast_sip_get_endpoints(void); + +/*! + * \brief Retrieve relevant SIP auth structures from sorcery + * + * \param auths Array of sorcery IDs of auth credentials to retrieve + * \param[out] out The retrieved auths are stored here + */ +int ast_sip_retrieve_auths(const struct ast_sip_auth_array *auths, struct ast_sip_auth **out); + +/*! + * \brief Clean up retrieved auth structures from memory + * + * Call this function once you have completed operating on auths + * retrieved from \ref ast_sip_retrieve_auths + * + * \param auths An array of auth structures to clean up + * \param num_auths The number of auths in the array + */ +void ast_sip_cleanup_auths(struct ast_sip_auth *auths[], size_t num_auths); + +/*! + * \brief Checks if the given content type matches type/subtype. + * + * Compares the pjsip_media_type with the passed type and subtype and + * returns the result of that comparison. The media type parameters are + * ignored. + * + * \param content_type The pjsip_media_type structure to compare + * \param type The media type to compare + * \param subtype The media subtype to compare + * \retval 0 No match + * \retval -1 Match + */ +int ast_sip_is_content_type(pjsip_media_type *content_type, char *type, char *subtype); + +/*! + * \brief Send a security event notification for when an invalid endpoint is requested + * + * \param name Name of the endpoint requested + * \param rdata Received message + */ +void ast_sip_report_invalid_endpoint(const char *name, pjsip_rx_data *rdata); + +/*! + * \brief Send a security event notification for when an ACL check fails + * + * \param endpoint Pointer to the endpoint in use + * \param rdata Received message + * \param name Name of the ACL + */ +void ast_sip_report_failed_acl(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, const char *name); + +/*! + * \brief Send a security event notification for when a challenge response has failed + * + * \param endpoint Pointer to the endpoint in use + * \param rdata Received message + */ +void ast_sip_report_auth_failed_challenge_response(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata); + +/*! + * \brief Send a security event notification for when authentication succeeds + * + * \param endpoint Pointer to the endpoint in use + * \param rdata Received message + */ +void ast_sip_report_auth_success(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata); + +/*! + * \brief Send a security event notification for when an authentication challenge is sent + * + * \param endpoint Pointer to the endpoint in use + * \param rdata Received message + * \param tdata Sent message + */ +void ast_sip_report_auth_challenge_sent(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pjsip_tx_data *tdata); + +void ast_sip_initialize_global_headers(void); +void ast_sip_destroy_global_headers(void); + +int ast_sip_add_global_request_header(const char *name, const char *value, int replace); +int ast_sip_add_global_response_header(const char *name, const char *value, int replace); + +int ast_sip_initialize_sorcery_global(struct ast_sorcery *sorcery); + +#endif /* _RES_SIP_H */ diff --git a/include/asterisk/res_pjsip_exten_state.h b/include/asterisk/res_pjsip_exten_state.h new file mode 100644 index 000000000..62662f930 --- /dev/null +++ b/include/asterisk/res_pjsip_exten_state.h @@ -0,0 +1,94 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2013, Digium, Inc. + * + * Kevin Harwell + * + * 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_EXTEN_STATE_H +#define _RES_SIP_EXTEN_STATE_H + +#include "asterisk/stringfields.h" +#include "asterisk/linkedlists.h" + +#include "asterisk/pbx.h" +#include "asterisk/presencestate.h" + + +/*! + * \brief Contains information pertaining to extension/device state changes. + */ +struct ast_sip_exten_state_data { + /*! The extension of the current state change */ + const char *exten; + /*! The extension state of the change */ + enum ast_extension_states exten_state; + /*! The presence state of the change */ + enum ast_presence_state presence_state; + /*! Current device state information */ + struct ao2_container *device_state_info; +}; + +/*! + * \brief Extension state provider. + */ +struct ast_sip_exten_state_provider { + /*! The name of the event this provider registers for */ + const char *event_name; + /*! Type of the body, ex: "application" */ + const char *type; + /*! Subtype of the body, ex: "pidf+xml" */ + const char *subtype; + /*! Type/Subtype together - ex: application/pidf+xml */ + const char *body_type; + /*! Subscription handler to be used and associated with provider */ + struct ast_sip_subscription_handler *handler; + + /*! + * \brief Create the body text of a NOTIFY request. + * + * Implementors use this to create body information within the given + * ast_str. That information is then added to the NOTIFY request. + * + * \param data Current extension state changes + * \param local URI of the dialog's local party, e.g. 'from' + * \param remote URI of the dialog's remote party, e.g. 'to' + * \param body_text Out parameter used to populate the NOTIFY msg body + * \retval 0 Successfully created the body's text + * \retval -1 Failed to create the body's text + */ + int (*create_body)(struct ast_sip_exten_state_data *data, const char *local, + const char *remote, struct ast_str **body_text); + + /*! Next item in the list */ + AST_LIST_ENTRY(ast_sip_exten_state_provider) next; +}; + +/*! + * \brief Registers an extension state provider. + * + * \param obj An extension state provider + * \retval 0 Successfully registered the extension state provider + * \retval -1 Failed to register the extension state provider + */ +int ast_sip_register_exten_state_provider(struct ast_sip_exten_state_provider *obj); + +/*! + * \brief Unregisters an extension state provider. + * + * \param obj An extension state provider + */ +void ast_sip_unregister_exten_state_provider(struct ast_sip_exten_state_provider *obj); + +#endif diff --git a/include/asterisk/res_pjsip_pubsub.h b/include/asterisk/res_pjsip_pubsub.h new file mode 100644 index 000000000..e74f23bf5 --- /dev/null +++ b/include/asterisk/res_pjsip_pubsub.h @@ -0,0 +1,516 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2013, Digium, Inc. + * + * Mark Michelson + * + * 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 a publication + */ +struct ast_sip_publication; + +/*! + * \brief Callbacks that publication handlers will define + */ +struct ast_sip_publish_handler { + /*! \brief The name of the event this handler deals with */ + const char *event_name; + + /*! \brief Publications */ + struct ao2_container *publications; + + /*! + * \brief Called when a PUBLISH to establish a new publication arrives. + * + * \param endpoint The endpoint from whom the PUBLISH arrived + * \param rdata The PUBLISH request + * \retval NULL PUBLISH was not accepted + * \retval non-NULL New publication + * + * \note The callback is expected to send a response for the PUBLISH in success cases. + */ + struct ast_sip_publication *(*new_publication)(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata); + + /*! + * \brief Called when a PUBLISH for an existing publication arrives. + * + * This PUBLISH may be intending to change state or it may be simply renewing + * the publication since the publication is nearing expiration. The callback + * is expected to send a response to the PUBLISH. + * + * \param pub The publication on which the PUBLISH arrived + * \param rdata The PUBLISH request + * \retval 0 Publication was accepted + * \retval non-zero Publication was denied + * + * \note The callback is expected to send a response for the PUBLISH. + */ + int (*publish_refresh)(struct ast_sip_publication *pub, pjsip_rx_data *rdata); + + /*! + * \brief Called when a publication has reached its expiration. + */ + void (*publish_expire)(struct ast_sip_publication *pub); + + /*! + * \brief Called when a PUBLISH arrives to terminate a publication. + * + * \param pub The publication that is terminating + * \param rdata The PUBLISH request terminating the publication + * + * \note The callback is expected to send a response for the PUBLISH. + */ + void (*publish_termination)(struct ast_sip_publication *pub, pjsip_rx_data *rdata); + + AST_LIST_ENTRY(ast_sip_publish_handler) next; +}; + +/*! + * \brief Create a new publication + * + * Publication handlers should call this when a PUBLISH arrives to establish a new publication. + * + * \param endpoint The endpoint from whom the PUBLISHes arrive + * \param rdata The PUBLISH that established the publication + * \retval NULL Failed to create a publication + * \retval non-NULL The newly-created publication + */ +struct ast_sip_publication *ast_sip_create_publication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata); + +/*! + * \brief Given a publication, get the associated endpoint + * + * \param pub The publication + * \retval NULL Failure + * \retval non-NULL The associated endpoint + */ +struct ast_sip_endpoint *ast_sip_publication_get_endpoint(struct ast_sip_publication *pub); + +/*! + * \brief Create a response to an inbound PUBLISH + * + * The created response must be sent using ast_sip_publication_send_response + * + * \param pub The publication + * \param status code The status code to place in the response + * \param rdata The request to which the response is being made + * \param[out] tdata The created response + */ +int ast_sip_publication_create_response(struct ast_sip_publication *pub, int status_code, pjsip_rx_data *rdata, + pjsip_tx_data **tdata); + +/*! + * \brief Send a response for an inbound PUBLISH + * + * \param pub The publication + * \param rdata The request to which the response was made + * \param tdata The response to the request + */ +pj_status_t ast_sip_publication_send_response(struct ast_sip_publication *pub, pjsip_rx_data *rdata, + pjsip_tx_data *tdata); + +/*! + * \brief Register a publish handler + * + * \retval 0 Handler was registered successfully + * \retval non-zero Handler was not registered successfully + */ +int ast_sip_register_publish_handler(struct ast_sip_publish_handler *handler); + +/*! + * \brief Unregister a publish handler + */ +void ast_sip_unregister_publish_handler(struct ast_sip_publish_handler *handler); + +/*! + * \brief Add a datastore to a SIP publication + * + * 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 publication The publication to add the datastore to + * \param datastore The datastore to be added to the subscription + * \retval 0 Success + * \retval -1 Failure + */ +int ast_sip_publication_add_datastore(struct ast_sip_publication *publication, struct ast_datastore *datastore); + +/*! + * \brief Retrieve a publication 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 publication The publication 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_publication_get_datastore(struct ast_sip_publication *publication, const char *name); + +/*! + * \brief Remove a publication datastore from the publication + * + * This operation may cause the datastore's free() callback to be called if the reference + * count reaches zero. + * + * \param publication The publication to remove the datastore from + * \param name The name of the datastore to remove + */ +void ast_sip_publication_remove_datastore(struct ast_sip_publication *publication, const char *name); + +/*! + * \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 Get the underlying PJSIP dialog structure + * + * Call this function when information needs to be retrieved from the + * underlying pjsip dialog. + * + * 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_dialog + */ +pjsip_dialog *ast_sip_subscription_get_dlg(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 */ diff --git a/include/asterisk/res_pjsip_session.h b/include/asterisk/res_pjsip_session.h new file mode 100644 index 000000000..4c5ac5534 --- /dev/null +++ b/include/asterisk/res_pjsip_session.h @@ -0,0 +1,561 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2013, Digium, Inc. + * + * Mark Michelson + * + * 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" +/* Needed for ast_sdp_srtp struct */ +#include "asterisk/sdp_srtp.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_dsp; +struct ast_udptl; + +/*! \brief T.38 states for a session */ +enum ast_sip_session_t38state { + T38_DISABLED = 0, /*!< Not enabled */ + T38_LOCAL_REINVITE, /*!< Offered from local - REINVITE */ + T38_PEER_REINVITE, /*!< Offered from peer - REINVITE */ + T38_ENABLED, /*!< Negotiated (enabled) */ + T38_REJECTED, /*!< Refused */ +}; + +struct ast_sip_session_sdp_handler; + +/*! + * \brief A structure containing SIP session media information + */ +struct ast_sip_session_media { + union { + /*! \brief RTP instance itself */ + struct ast_rtp_instance *rtp; + /*! \brief UDPTL instance itself */ + struct ast_udptl *udptl; + }; + /*! \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 Holds SRTP information */ + struct ast_sdp_srtp *srtp; + /*! \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; + /* When we need to forcefully end the session */ + pj_timer_entry scheduled_termination; + /* Identity of endpoint this session deals with */ + struct ast_party_id id; + /* Requested capabilities */ + struct ast_format_cap *req_caps; + /* Codecs overriden by dialplan on an outgoing request */ + struct ast_codec_pref override_prefs; + /* Optional DSP, used only for inband DTMF detection if configured */ + struct ast_dsp *dsp; + /* Whether the termination of the session should be deferred */ + unsigned int defer_terminate:1; + /* Deferred incoming re-invite */ + pjsip_rx_data *deferred_reinvite; + /* Current T.38 state */ + enum ast_sip_session_t38state t38state; +}; + +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); +typedef int (*ast_sip_session_sdp_creation_cb)(struct ast_sip_session *session, pjmedia_sdp_session *sdp); + +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 Determine whether a stream requires that the re-invite be deferred. + * If a stream can not be immediately negotiated the re-invite can be deferred and + * resumed at a later time. It is up to the handler which caused deferral to occur + * to resume it. + * \param session The session for which the media is being re-invited + * \param session_media The media being reinvited + * \param sdp The entire SDP. + * \retval 0 The stream was unhandled or does not need the re-invite to be deferred. + * \retval 1 Re-invite should be deferred and will be resumed later. No further operations will take place. + * \note This is optional, if not implemented the stream is assumed to not be deferred. + */ + int (*defer_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 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 A structure which contains a channel implementation and session + */ +struct ast_sip_channel_pvt { + /*! \brief Pointer to channel specific implementation information, must be ao2 object */ + void *pvt; + /*! \brief Pointer to session */ + struct ast_sip_session *session; +}; + +/*! + * \brief Allocate a new SIP channel pvt structure + * + * \param pvt Pointer to channel specific implementation + * \param session Pointer to SIP session + * + * \retval non-NULL success + * \retval NULL failure + */ +struct ast_sip_channel_pvt *ast_sip_channel_pvt_alloc(void *pvt, struct ast_sip_session *session); + +/*! + * \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 Defer local termination of a session until remote side terminates, or an amount of time passes + * + * \param session The session to defer termination on + */ +void ast_sip_session_defer_termination(struct ast_sip_session *session); + +/*! + * \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 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_sdp_creation Callback called when SDP 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_sdp_creation_cb on_sdp_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 Creates an INVITE request. + * + * \param session Starting session for the INVITE + * \param tdata The created request. + */ +int ast_sip_session_create_invite(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); + +/*! + * \brief Retrieves a session from a dialog + * + * \param dlg The dialog to retrieve the session from + * + * \retval non-NULL if session exists + * \retval NULL if no session + * + * \note The reference count of the session is increased when returned + * + * \note This function *must* be called with the dialog locked + */ +struct ast_sip_session *ast_sip_dialog_get_session(pjsip_dialog *dlg); + +/*! + * \brief Resumes processing of a deferred incoming re-invite + * + * \param session The session which has a pending incoming re-invite + * + * \note When resuming a re-invite it is given to the pjsip stack as if it + * had just been received from a transport, this means that the deferral + * callback will be called again. + */ +void ast_sip_session_resume_reinvite(struct ast_sip_session *session); + +#endif /* _RES_SIP_SESSION_H */ diff --git a/include/asterisk/res_sip.h b/include/asterisk/res_sip.h deleted file mode 100644 index 23d1a641e..000000000 --- a/include/asterisk/res_sip.h +++ /dev/null @@ -1,1502 +0,0 @@ -/* - * Asterisk -- An open source telephony toolkit. - * - * Copyright (C) 2013, Digium, Inc. - * - * Mark Michelson - * - * 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_H -#define _RES_SIP_H - -#include "asterisk/stringfields.h" -/* Needed for struct ast_sockaddr */ -#include "asterisk/netsock2.h" -/* Needed for linked list macros */ -#include "asterisk/linkedlists.h" -/* Needed for ast_party_id */ -#include "asterisk/channel.h" -/* Needed for ast_sorcery */ -#include "asterisk/sorcery.h" -/* Needed for ast_dnsmgr */ -#include "asterisk/dnsmgr.h" -/* Needed for ast_endpoint */ -#include "asterisk/endpoints.h" -/* Needed for ast_t38_ec_modes */ -#include "asterisk/udptl.h" -/* Needed for pj_sockaddr */ -#include -/* Needed for ast_rtp_dtls_cfg struct */ -#include "asterisk/rtp_engine.h" - -/* Forward declarations of PJSIP stuff */ -struct pjsip_rx_data; -struct pjsip_module; -struct pjsip_tx_data; -struct pjsip_dialog; -struct pjsip_transport; -struct pjsip_tpfactory; -struct pjsip_tls_setting; -struct pjsip_tpselector; - -/*! - * \brief Structure for SIP transport information - */ -struct ast_sip_transport_state { - /*! \brief Transport itself */ - struct pjsip_transport *transport; - - /*! \brief Transport factory */ - struct pjsip_tpfactory *factory; -}; - -#define SIP_SORCERY_DOMAIN_ALIAS_TYPE "domain_alias" - -/*! - * Details about a SIP domain alias - */ -struct ast_sip_domain_alias { - /*! Sorcery object details */ - SORCERY_OBJECT(details); - AST_DECLARE_STRING_FIELDS( - /*! Domain to be aliased to */ - AST_STRING_FIELD(domain); - ); -}; - -/*! \brief Maximum number of ciphers supported for a TLS transport */ -#define SIP_TLS_MAX_CIPHERS 64 - -/* - * \brief Transport to bind to - */ -struct ast_sip_transport { - /*! Sorcery object details */ - SORCERY_OBJECT(details); - AST_DECLARE_STRING_FIELDS( - /*! Certificate of authority list file */ - AST_STRING_FIELD(ca_list_file); - /*! Public certificate file */ - AST_STRING_FIELD(cert_file); - /*! Optional private key of the certificate file */ - AST_STRING_FIELD(privkey_file); - /*! Password to open the private key */ - AST_STRING_FIELD(password); - /*! External signaling address */ - AST_STRING_FIELD(external_signaling_address); - /*! External media address */ - AST_STRING_FIELD(external_media_address); - /*! Optional domain to use for messages if provided could not be found */ - AST_STRING_FIELD(domain); - ); - /*! Type of transport */ - enum ast_transport type; - /*! Address and port to bind to */ - pj_sockaddr host; - /*! Number of simultaneous asynchronous operations */ - unsigned int async_operations; - /*! Optional external port for signaling */ - unsigned int external_signaling_port; - /*! TLS settings */ - pjsip_tls_setting tls; - /*! Configured TLS ciphers */ - pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS]; - /*! Optional local network information, used for NAT purposes */ - struct ast_ha *localnet; - /*! DNS manager for refreshing the external address */ - struct ast_dnsmgr_entry *external_address_refresher; - /*! Optional external address information */ - struct ast_sockaddr external_address; - /*! Transport state information */ - struct ast_sip_transport_state *state; - /*! QOS DSCP TOS bits */ - unsigned int tos; - /*! QOS COS value */ - unsigned int cos; -}; - -/*! - * \brief Structure for SIP nat hook information - */ -struct ast_sip_nat_hook { - /*! Sorcery object details */ - SORCERY_OBJECT(details); - /*! Callback for when a message is going outside of our local network */ - void (*outgoing_external_message)(struct pjsip_tx_data *tdata, struct ast_sip_transport *transport); -}; - -/*! - * \brief Contact associated with an address of record - */ -struct ast_sip_contact { - /*! Sorcery object details, the id is the aor name plus a random string */ - SORCERY_OBJECT(details); - AST_DECLARE_STRING_FIELDS( - /*! Full URI of the contact */ - AST_STRING_FIELD(uri); - ); - /*! Absolute time that this contact is no longer valid after */ - struct timeval expiration_time; - /*! Frequency to send OPTIONS requests to contact. 0 is disabled. */ - unsigned int qualify_frequency; - /*! If true authenticate the qualify if needed */ - int authenticate_qualify; -}; - -#define CONTACT_STATUS "contact_status" - -/*! - * \brief Status type for a contact. - */ -enum ast_sip_contact_status_type { - UNAVAILABLE, - AVAILABLE -}; - -/*! - * \brief A contact's status. - * - * \detail Maintains a contact's current status and round trip time - * if available. - */ -struct ast_sip_contact_status { - SORCERY_OBJECT(details); - /*! Current status for a contact (default - unavailable) */ - enum ast_sip_contact_status_type status; - /*! The round trip start time set before sending a qualify request */ - struct timeval rtt_start; - /*! The round trip time in microseconds */ - int64_t rtt; -}; - -/*! - * \brief A transport to be used for messages to a contact - */ -struct ast_sip_contact_transport { - AST_DECLARE_STRING_FIELDS( - /*! Full URI of the contact */ - AST_STRING_FIELD(uri); - ); - pjsip_transport *transport; -}; - -/*! - * \brief A SIP address of record - */ -struct ast_sip_aor { - /*! Sorcery object details, the id is the AOR name */ - SORCERY_OBJECT(details); - AST_DECLARE_STRING_FIELDS( - /*! Voicemail boxes for this AOR */ - AST_STRING_FIELD(mailboxes); - ); - /*! Minimum expiration time */ - unsigned int minimum_expiration; - /*! Maximum expiration time */ - unsigned int maximum_expiration; - /*! Default contact expiration if one is not provided in the contact */ - unsigned int default_expiration; - /*! Frequency to send OPTIONS requests to AOR contacts. 0 is disabled. */ - unsigned int qualify_frequency; - /*! If true authenticate the qualify if needed */ - int authenticate_qualify; - /*! Maximum number of external contacts, 0 to disable */ - unsigned int max_contacts; - /*! Whether to remove any existing contacts not related to an incoming REGISTER when it comes in */ - unsigned int remove_existing; - /*! Any permanent configured contacts */ - struct ao2_container *permanent_contacts; -}; - -/*! - * \brief DTMF modes for SIP endpoints - */ -enum ast_sip_dtmf_mode { - /*! No DTMF to be used */ - AST_SIP_DTMF_NONE, - /* XXX Should this be 2833 instead? */ - /*! Use RFC 4733 events for DTMF */ - AST_SIP_DTMF_RFC_4733, - /*! Use DTMF in the audio stream */ - AST_SIP_DTMF_INBAND, - /*! Use SIP INFO DTMF (blech) */ - AST_SIP_DTMF_INFO, -}; - -/*! - * \brief Methods of storing SIP digest authentication credentials. - * - * Note that both methods result in MD5 digest authentication being - * used. The two methods simply alter how Asterisk determines the - * credentials for a SIP authentication - */ -enum ast_sip_auth_type { - /*! Credentials stored as a username and password combination */ - AST_SIP_AUTH_TYPE_USER_PASS, - /*! Credentials stored as an MD5 sum */ - AST_SIP_AUTH_TYPE_MD5, - /*! Credentials not stored this is a fake auth */ - AST_SIP_AUTH_TYPE_ARTIFICIAL -}; - -#define SIP_SORCERY_AUTH_TYPE "auth" - -struct ast_sip_auth { - /* Sorcery ID of the auth is its name */ - SORCERY_OBJECT(details); - AST_DECLARE_STRING_FIELDS( - /* Identification for these credentials */ - AST_STRING_FIELD(realm); - /* Authentication username */ - AST_STRING_FIELD(auth_user); - /* Authentication password */ - AST_STRING_FIELD(auth_pass); - /* Authentication credentials in MD5 format (hash of user:realm:pass) */ - AST_STRING_FIELD(md5_creds); - ); - /* The time period (in seconds) that a nonce may be reused */ - unsigned int nonce_lifetime; - /* Used to determine what to use when authenticating */ - enum ast_sip_auth_type type; -}; - -struct ast_sip_auth_array { - /*! Array of Sorcery IDs of auth sections */ - const char **names; - /*! Number of credentials in the array */ - unsigned int num; -}; - -/*! - * \brief Different methods by which incoming requests can be matched to endpoints - */ -enum ast_sip_endpoint_identifier_type { - /*! Identify based on user name in From header */ - AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME = (1 << 0), -}; - -enum ast_sip_session_refresh_method { - /*! Use reinvite to negotiate direct media */ - AST_SIP_SESSION_REFRESH_METHOD_INVITE, - /*! Use UPDATE to negotiate direct media */ - AST_SIP_SESSION_REFRESH_METHOD_UPDATE, -}; - -enum ast_sip_direct_media_glare_mitigation { - /*! Take no special action to mitigate reinvite glare */ - AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_NONE, - /*! Do not send an initial direct media session refresh on outgoing call legs - * Subsequent session refreshes will be sent no matter the session direction - */ - AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_OUTGOING, - /*! Do not send an initial direct media session refresh on incoming call legs - * Subsequent session refreshes will be sent no matter the session direction - */ - AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_INCOMING, -}; - -enum ast_sip_session_media_encryption { - /*! Invalid media encryption configuration */ - AST_SIP_MEDIA_TRANSPORT_INVALID = 0, - /*! Do not allow any encryption of session media */ - AST_SIP_MEDIA_ENCRYPT_NONE, - /*! Offer SDES-encrypted session media */ - AST_SIP_MEDIA_ENCRYPT_SDES, - /*! Offer encrypted session media with datagram TLS key exchange */ - AST_SIP_MEDIA_ENCRYPT_DTLS, -}; - -/*! - * \brief Session timers options - */ -struct ast_sip_timer_options { - /*! Minimum session expiration period, in seconds */ - unsigned int min_se; - /*! Session expiration period, in seconds */ - unsigned int sess_expires; -}; - -/*! - * \brief Endpoint configuration for SIP extensions. - * - * SIP extensions, in this case refers to features - * indicated in Supported or Required headers. - */ -struct ast_sip_endpoint_extensions { - /*! Enabled SIP extensions */ - unsigned int flags; - /*! Timer options */ - struct ast_sip_timer_options timer; -}; - -/*! - * \brief Endpoint configuration for unsolicited MWI - */ -struct ast_sip_mwi_configuration { - AST_DECLARE_STRING_FIELDS( - /*! Configured voicemail boxes for this endpoint. Used for MWI */ - AST_STRING_FIELD(mailboxes); - /*! Username to use when sending MWI NOTIFYs to this endpoint */ - AST_STRING_FIELD(fromuser); - ); - /* Should mailbox states be combined into a single notification? */ - unsigned int aggregate; -}; - -/*! - * \brief Endpoint subscription configuration - */ -struct ast_sip_endpoint_subscription_configuration { - /*! Indicates if endpoint is allowed to initiate subscriptions */ - unsigned int allow; - /*! The minimum allowed expiration for subscriptions from endpoint */ - unsigned int minexpiry; - /*! Message waiting configuration */ - struct ast_sip_mwi_configuration mwi; -}; - -/*! - * \brief NAT configuration options for endpoints - */ -struct ast_sip_endpoint_nat_configuration { - /*! Whether to force using the source IP address/port for sending responses */ - unsigned int force_rport; - /*! Whether to rewrite the Contact header with the source IP address/port or not */ - unsigned int rewrite_contact; -}; - -/*! - * \brief Party identification options for endpoints - * - * This includes caller ID, connected line, and redirecting-related options - */ -struct ast_sip_endpoint_id_configuration { - struct ast_party_id self; - /*! Do we accept identification information from this endpoint */ - unsigned int trust_inbound; - /*! Do we send private identification information to this endpoint? */ - unsigned int trust_outbound; - /*! Do we send P-Asserted-Identity headers to this endpoint? */ - unsigned int send_pai; - /*! Do we send Remote-Party-ID headers to this endpoint? */ - unsigned int send_rpid; - /*! Do we add Diversion headers to applicable outgoing requests/responses? */ - unsigned int send_diversion; - /*! When performing connected line update, which method should be used */ - enum ast_sip_session_refresh_method refresh_method; -}; - -/*! - * \brief Call pickup configuration options for endpoints - */ -struct ast_sip_endpoint_pickup_configuration { - /*! Call group */ - ast_group_t callgroup; - /*! Pickup group */ - ast_group_t pickupgroup; - /*! Named call group */ - struct ast_namedgroups *named_callgroups; - /*! Named pickup group */ - struct ast_namedgroups *named_pickupgroups; -}; - -/*! - * \brief Configuration for one-touch INFO recording - */ -struct ast_sip_info_recording_configuration { - AST_DECLARE_STRING_FIELDS( - /*! Feature to enact when one-touch recording INFO with Record: On is received */ - AST_STRING_FIELD(onfeature); - /*! Feature to enact when one-touch recording INFO with Record: Off is received */ - AST_STRING_FIELD(offfeature); - ); - /*! Is one-touch recording permitted? */ - unsigned int enabled; -}; - -/*! - * \brief Endpoint configuration options for INFO packages - */ -struct ast_sip_endpoint_info_configuration { - /*! Configuration for one-touch recording */ - struct ast_sip_info_recording_configuration recording; -}; - -/*! - * \brief RTP configuration for SIP endpoints - */ -struct ast_sip_media_rtp_configuration { - AST_DECLARE_STRING_FIELDS( - /*! Configured RTP engine for this endpoint. */ - AST_STRING_FIELD(engine); - ); - /*! Whether IPv6 RTP is enabled or not */ - unsigned int ipv6; - /*! Whether symmetric RTP is enabled or not */ - unsigned int symmetric; - /*! Whether ICE support is enabled or not */ - unsigned int ice_support; - /*! Whether to use the "ptime" attribute received from the endpoint or not */ - unsigned int use_ptime; - /*! Do we use AVPF exclusively for this endpoint? */ - unsigned int use_avpf; - /*! \brief DTLS-SRTP configuration information */ - struct ast_rtp_dtls_cfg dtls_cfg; - /*! Should SRTP use a 32 byte tag instead of an 80 byte tag? */ - unsigned int srtp_tag_32; - /*! Do we use media encryption? what type? */ - enum ast_sip_session_media_encryption encryption; -}; - -/*! - * \brief Direct media options for SIP endpoints - */ -struct ast_sip_direct_media_configuration { - /*! Boolean indicating if direct_media is permissible */ - unsigned int enabled; - /*! When using direct media, which method should be used */ - enum ast_sip_session_refresh_method method; - /*! Take steps to mitigate glare for direct media */ - enum ast_sip_direct_media_glare_mitigation glare_mitigation; - /*! Do not attempt direct media session refreshes if a media NAT is detected */ - unsigned int disable_on_nat; -}; - -struct ast_sip_t38_configuration { - /*! Whether T.38 UDPTL support is enabled or not */ - unsigned int enabled; - /*! Error correction setting for T.38 UDPTL */ - enum ast_t38_ec_modes error_correction; - /*! Explicit T.38 max datagram value, may be 0 to indicate the remote side can be trusted */ - unsigned int maxdatagram; - /*! Whether NAT Support is enabled for T.38 UDPTL sessions or not */ - unsigned int nat; - /*! Whether to use IPv6 for UDPTL or not */ - unsigned int ipv6; -}; - -/*! - * \brief Media configuration for SIP endpoints - */ -struct ast_sip_endpoint_media_configuration { - AST_DECLARE_STRING_FIELDS( - /*! Optional external media address to use in SDP */ - AST_STRING_FIELD(external_address); - /*! SDP origin username */ - AST_STRING_FIELD(sdpowner); - /*! SDP session name */ - AST_STRING_FIELD(sdpsession); - ); - /*! RTP media configuration */ - struct ast_sip_media_rtp_configuration rtp; - /*! Direct media options */ - struct ast_sip_direct_media_configuration direct_media; - /*! T.38 (FoIP) options */ - struct ast_sip_t38_configuration t38; - /*! Codec preferences */ - struct ast_codec_pref prefs; - /*! Configured codecs */ - struct ast_format_cap *codecs; - /*! DSCP TOS bits for audio streams */ - unsigned int tos_audio; - /*! Priority for audio streams */ - unsigned int cos_audio; - /*! DSCP TOS bits for video streams */ - unsigned int tos_video; - /*! Priority for video streams */ - unsigned int cos_video; -}; - -/*! - * \brief An entity with which Asterisk communicates - */ -struct ast_sip_endpoint { - SORCERY_OBJECT(details); - AST_DECLARE_STRING_FIELDS( - /*! Context to send incoming calls to */ - AST_STRING_FIELD(context); - /*! Name of an explicit transport to use */ - AST_STRING_FIELD(transport); - /*! Outbound proxy to use */ - AST_STRING_FIELD(outbound_proxy); - /*! Explicit AORs to dial if none are specified */ - AST_STRING_FIELD(aors); - /*! Musiconhold class to suggest that the other side use when placing on hold */ - AST_STRING_FIELD(mohsuggest); - /*! Configured tone zone for this endpoint. */ - AST_STRING_FIELD(zone); - /*! Configured language for this endpoint. */ - AST_STRING_FIELD(language); - /*! Default username to place in From header */ - AST_STRING_FIELD(fromuser); - /*! Domain to place in From header */ - AST_STRING_FIELD(fromdomain); - ); - /*! Configuration for extensions */ - struct ast_sip_endpoint_extensions extensions; - /*! Configuration relating to media */ - struct ast_sip_endpoint_media_configuration media; - /*! SUBSCRIBE/NOTIFY configuration options */ - struct ast_sip_endpoint_subscription_configuration subscription; - /*! NAT configuration */ - struct ast_sip_endpoint_nat_configuration nat; - /*! Party identification options */ - struct ast_sip_endpoint_id_configuration id; - /*! Configuration options for INFO packages */ - struct ast_sip_endpoint_info_configuration info; - /*! Call pickup configuration */ - struct ast_sip_endpoint_pickup_configuration pickup; - /*! Inbound authentication credentials */ - struct ast_sip_auth_array inbound_auths; - /*! Outbound authentication credentials */ - struct ast_sip_auth_array outbound_auths; - /*! DTMF mode to use with this endpoint */ - enum ast_sip_dtmf_mode dtmf; - /*! Method(s) by which the endpoint should be identified. */ - enum ast_sip_endpoint_identifier_type ident_method; - /*! Boolean indicating if ringing should be sent as inband progress */ - unsigned int inband_progress; - /*! Pointer to the persistent Asterisk endpoint */ - struct ast_endpoint *persistent; - /*! The number of channels at which busy device state is returned */ - unsigned int devicestate_busy_at; - /*! Whether fax detection is enabled or not (CNG tone detection) */ - unsigned int faxdetect; - /*! Determines if transfers (using REFER) are allowed by this endpoint */ - unsigned int allowtransfer; -}; - -/*! - * \brief Initialize an auth array with the configured values. - * - * \param array Array to initialize - * \param auth_names Comma-separated list of names to set in the array - * \retval 0 Success - * \retval non-zero Failure - */ -int ast_sip_auth_array_init(struct ast_sip_auth_array *array, const char *auth_names); - -/*! - * \brief Free contents of an auth array. - * - * \param array Array whose contents are to be freed - */ -void ast_sip_auth_array_destroy(struct ast_sip_auth_array *array); - -/*! - * \brief Possible returns from ast_sip_check_authentication - */ -enum ast_sip_check_auth_result { - /*! Authentication needs to be challenged */ - AST_SIP_AUTHENTICATION_CHALLENGE, - /*! Authentication succeeded */ - AST_SIP_AUTHENTICATION_SUCCESS, - /*! Authentication failed */ - AST_SIP_AUTHENTICATION_FAILED, - /*! Authentication encountered some internal error */ - AST_SIP_AUTHENTICATION_ERROR, -}; - -/*! - * \brief An interchangeable way of handling digest authentication for SIP. - * - * An authenticator is responsible for filling in the callbacks provided below. Each is called from a publicly available - * function in res_sip. The authenticator can use configuration or other local policy to determine whether authentication - * should take place and what credentials should be used when challenging and authenticating a request. - */ -struct ast_sip_authenticator { - /*! - * \brief Check if a request requires authentication - * See ast_sip_requires_authentication for more details - */ - int (*requires_authentication)(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata); - /*! - * \brief Check that an incoming request passes authentication. - * - * The tdata parameter is useful for adding information such as digest challenges. - * - * \param endpoint The endpoint sending the incoming request - * \param rdata The incoming request - * \param tdata Tentative outgoing request. - */ - enum ast_sip_check_auth_result (*check_authentication)(struct ast_sip_endpoint *endpoint, - pjsip_rx_data *rdata, pjsip_tx_data *tdata); -}; - -/*! - * \brief an interchangeable way of responding to authentication challenges - * - * An outbound authenticator takes incoming challenges and formulates a new SIP request with - * credentials. - */ -struct ast_sip_outbound_authenticator { - /*! - * \brief Create a new request with authentication credentials - * - * \param auths An array of IDs of auth sorcery objects - * \param challenge The SIP response with authentication challenge(s) - * \param tsx The transaction in which the challenge was received - * \param new_request The new SIP request with challenge response(s) - * \retval 0 Successfully created new request - * \retval -1 Failed to create a new request - */ - int (*create_request_with_auth)(const struct ast_sip_auth_array *auths, struct pjsip_rx_data *challenge, - struct pjsip_transaction *tsx, struct pjsip_tx_data **new_request); -}; - -/*! - * \brief An entity responsible for identifying the source of a SIP message - */ -struct ast_sip_endpoint_identifier { - /*! - * \brief Callback used to identify the source of a message. - * See ast_sip_identify_endpoint for more details - */ - struct ast_sip_endpoint *(*identify_endpoint)(pjsip_rx_data *rdata); -}; - -#define SIP_SORCERY_SECURITY_TYPE "security" - -/*! - * \brief SIP security details and configuration. - */ -struct ast_sip_security { - SORCERY_OBJECT(details); - struct ast_acl_list *acl; - struct ast_acl_list *contact_acl; -}; - -/*! - * \brief Register a SIP service in Asterisk. - * - * This is more-or-less a wrapper around pjsip_endpt_register_module(). - * Registering a service makes it so that PJSIP will call into the - * service at appropriate times. For more information about PJSIP module - * callbacks, see the PJSIP documentation. Asterisk modules that call - * this function will likely do so at module load time. - * - * \param module The module that is to be registered with PJSIP - * \retval 0 Success - * \retval -1 Failure - */ -int ast_sip_register_service(pjsip_module *module); - -/*! - * This is the opposite of ast_sip_register_service(). Unregistering a - * service means that PJSIP will no longer call into the module any more. - * This will likely occur when an Asterisk module is unloaded. - * - * \param module The PJSIP module to unregister - */ -void ast_sip_unregister_service(pjsip_module *module); - -/*! - * \brief Register a SIP authenticator - * - * An authenticator has three main purposes: - * 1) Determining if authentication should be performed on an incoming request - * 2) Gathering credentials necessary for issuing an authentication challenge - * 3) Authenticating a request that has credentials - * - * Asterisk provides a default authenticator, but it may be replaced by a - * custom one if desired. - * - * \param auth The authenticator to register - * \retval 0 Success - * \retval -1 Failure - */ -int ast_sip_register_authenticator(struct ast_sip_authenticator *auth); - -/*! - * \brief Unregister a SIP authenticator - * - * When there is no authenticator registered, requests cannot be challenged - * or authenticated. - * - * \param auth The authenticator to unregister - */ -void ast_sip_unregister_authenticator(struct ast_sip_authenticator *auth); - - /*! - * \brief Register an outbound SIP authenticator - * - * An outbound authenticator is responsible for creating responses to - * authentication challenges by remote endpoints. - * - * \param auth The authenticator to register - * \retval 0 Success - * \retval -1 Failure - */ -int ast_sip_register_outbound_authenticator(struct ast_sip_outbound_authenticator *outbound_auth); - -/*! - * \brief Unregister an outbound SIP authenticator - * - * When there is no outbound authenticator registered, authentication challenges - * will be handled as any other final response would be. - * - * \param auth The authenticator to unregister - */ -void ast_sip_unregister_outbound_authenticator(struct ast_sip_outbound_authenticator *auth); - -/*! - * \brief Register a SIP endpoint identifier - * - * An endpoint identifier's purpose is to determine which endpoint a given SIP - * message has come from. - * - * Multiple endpoint identifiers may be registered so that if an endpoint - * cannot be identified by one identifier, it may be identified by another. - * - * Asterisk provides two endpoint identifiers. One identifies endpoints based - * on the user part of the From header URI. The other identifies endpoints based - * on the source IP address. - * - * If the order in which endpoint identifiers is run is important to you, then - * be sure to load individual endpoint identifier modules in the order you wish - * for them to be run in modules.conf - * - * \param identifier The SIP endpoint identifier to register - * \retval 0 Success - * \retval -1 Failure - */ -int ast_sip_register_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier); - -/*! - * \brief Unregister a SIP endpoint identifier - * - * This stops an endpoint identifier from being used. - * - * \param identifier The SIP endoint identifier to unregister - */ -void ast_sip_unregister_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier); - -/*! - * \brief Allocate a new SIP endpoint - * - * This will return an endpoint with its refcount increased by one. This reference - * can be released using ao2_ref(). - * - * \param name The name of the endpoint. - * \retval NULL Endpoint allocation failed - * \retval non-NULL The newly allocated endpoint - */ -void *ast_sip_endpoint_alloc(const char *name); - -/*! - * \brief Get a pointer to the PJSIP endpoint. - * - * This is useful when modules have specific information they need - * to register with the PJSIP core. - * \retval NULL endpoint has not been created yet. - * \retval non-NULL PJSIP endpoint. - */ -pjsip_endpoint *ast_sip_get_pjsip_endpoint(void); - -/*! - * \brief Get a pointer to the SIP sorcery structure. - * - * \retval NULL sorcery has not been initialized - * \retval non-NULL sorcery structure - */ -struct ast_sorcery *ast_sip_get_sorcery(void); - -/*! - * \brief Initialize transport support on a sorcery instance - * - * \param sorcery The sorcery instance - * - * \retval -1 failure - * \retval 0 success - */ -int ast_sip_initialize_sorcery_transport(struct ast_sorcery *sorcery); - -/*! - * \brief Initialize qualify support on a sorcery instance - * - * \param sorcery The sorcery instance - * - * \retval -1 failure - * \retval 0 success - */ -int ast_sip_initialize_sorcery_qualify(struct ast_sorcery *sorcery); - -/*! - * \brief Initialize location support on a sorcery instance - * - * \param sorcery The sorcery instance - * - * \retval -1 failure - * \retval 0 success - */ -int ast_sip_initialize_sorcery_location(struct ast_sorcery *sorcery); - -/*! - * \brief Retrieve a named AOR - * - * \param aor_name Name of the AOR - * - * \retval NULL if not found - * \retval non-NULL if found - */ -struct ast_sip_aor *ast_sip_location_retrieve_aor(const char *aor_name); - -/*! - * \brief Retrieve the first bound contact for an AOR - * - * \param aor Pointer to the AOR - * \retval NULL if no contacts available - * \retval non-NULL if contacts available - */ -struct ast_sip_contact *ast_sip_location_retrieve_first_aor_contact(const struct ast_sip_aor *aor); - -/*! - * \brief Retrieve all contacts currently available for an AOR - * - * \param aor Pointer to the AOR - * - * \retval NULL if no contacts available - * \retval non-NULL if contacts available - */ -struct ao2_container *ast_sip_location_retrieve_aor_contacts(const struct ast_sip_aor *aor); - -/*! - * \brief Retrieve the first bound contact from a list of AORs - * - * \param aor_list A comma-separated list of AOR names - * \retval NULL if no contacts available - * \retval non-NULL if contacts available - */ -struct ast_sip_contact *ast_sip_location_retrieve_contact_from_aor_list(const char *aor_list); - -/*! - * \brief Retrieve a named contact - * - * \param contact_name Name of the contact - * - * \retval NULL if not found - * \retval non-NULL if found - */ -struct ast_sip_contact *ast_sip_location_retrieve_contact(const char *contact_name); - -/*! - * \brief Add a transport for a contact to use - */ - -void ast_sip_location_add_contact_transport(struct ast_sip_contact_transport *ct); - -/*! - * \brief Delete a transport for a contact that went away - */ -void ast_sip_location_delete_contact_transport(struct ast_sip_contact_transport *ct); - -/*! - * \brief Retrieve a contact_transport, by URI - * - * \param contact_uri URI of the contact - * - * \retval NULL if not found - * \retval non-NULL if found - */ -struct ast_sip_contact_transport *ast_sip_location_retrieve_contact_transport_by_uri(const char *contact_uri); - -/*! - * \brief Retrieve a contact_transport, by transport - * - * \param transport transport the contact uses - * - * \retval NULL if not found - * \retval non-NULL if found - */ -struct ast_sip_contact_transport *ast_sip_location_retrieve_contact_transport_by_transport(pjsip_transport *transport); - -/*! - * \brief Add a new contact to an AOR - * - * \param aor Pointer to the AOR - * \param uri Full contact URI - * \param expiration_time Optional expiration time of the contact - * - * \retval -1 failure - * \retval 0 success - */ -int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time); - -/*! - * \brief Update a contact - * - * \param contact New contact object with details - * - * \retval -1 failure - * \retval 0 success - */ -int ast_sip_location_update_contact(struct ast_sip_contact *contact); - -/*! -* \brief Delete a contact -* -* \param contact Contact object to delete -* -* \retval -1 failure -* \retval 0 success -*/ -int ast_sip_location_delete_contact(struct ast_sip_contact *contact); - -/*! - * \brief Initialize domain aliases support on a sorcery instance - * - * \param sorcery The sorcery instance - * - * \retval -1 failure - * \retval 0 success - */ -int ast_sip_initialize_sorcery_domain_alias(struct ast_sorcery *sorcery); - -/*! - * \brief Initialize authentication support on a sorcery instance - * - * \param sorcery The sorcery instance - * - * \retval -1 failure - * \retval 0 success - */ -int ast_sip_initialize_sorcery_auth(struct ast_sorcery *sorcery); - -/*! - * \brief Initialize security support on a sorcery instance - * - * \param sorcery The sorcery instance - * - * \retval -1 failure - * \retval 0 success - */ -int ast_sip_initialize_sorcery_security(struct ast_sorcery *sorcery); - -/*! - * \brief Callback called when an outbound request with authentication credentials is to be sent in dialog - * - * This callback will have the created request on it. The callback's purpose is to do any extra - * housekeeping that needs to be done as well as to send the request out. - * - * This callback is only necessary if working with a PJSIP API that sits between the application - * and the dialog layer. - * - * \param dlg The dialog to which the request belongs - * \param tdata The created request to be sent out - * \param user_data Data supplied with the callback - * - * \retval 0 Success - * \retval -1 Failure - */ -typedef int (*ast_sip_dialog_outbound_auth_cb)(pjsip_dialog *dlg, pjsip_tx_data *tdata, void *user_data); - -/*! - * \brief Set up outbound authentication on a SIP dialog - * - * This sets up the infrastructure so that all requests associated with a created dialog - * can be re-sent with authentication credentials if the original request is challenged. - * - * \param dlg The dialog on which requests will be authenticated - * \param endpoint The endpoint whom this dialog pertains to - * \param cb Callback to call to send requests with authentication - * \param user_data Data to be provided to the callback when it is called - * - * \retval 0 Success - * \retval -1 Failure - */ -int ast_sip_dialog_setup_outbound_authentication(pjsip_dialog *dlg, const struct ast_sip_endpoint *endpoint, - ast_sip_dialog_outbound_auth_cb cb, void *user_data); - -/*! - * \brief Initialize the distributor module - * - * The distributor module is responsible for taking an incoming - * SIP message and placing it into the threadpool. Once in the threadpool, - * the distributor will perform endpoint lookups and authentication, and - * then distribute the message up the stack to any further modules. - * - * \retval -1 Failure - * \retval 0 Success - */ -int ast_sip_initialize_distributor(void); - -/*! - * \brief Destruct the distributor module. - * - * Unregisters pjsip modules and cleans up any allocated resources. - */ -void ast_sip_destroy_distributor(void); - -/*! - * \brief Retrieves a reference to the artificial auth. - * - * \retval The artificial auth - */ -struct ast_sip_auth *ast_sip_get_artificial_auth(void); - -/*! - * \brief Retrieves a reference to the artificial endpoint. - * - * \retval The artificial endpoint - */ -struct ast_sip_endpoint *ast_sip_get_artificial_endpoint(void); - -/*! - * \page Threading model for SIP - * - * There are three major types of threads that SIP will have to deal with: - * \li Asterisk threads - * \li PJSIP threads - * \li SIP threadpool threads (a.k.a. "servants") - * - * \par Asterisk Threads - * - * Asterisk threads are those that originate from outside of SIP but within - * Asterisk. The most common of these threads are PBX (channel) threads and - * the autoservice thread. Most interaction with these threads will be through - * channel technology callbacks. Within these threads, it is fine to handle - * Asterisk data from outside of SIP, but any handling of SIP data should be - * left to servants, \b especially if you wish to call into PJSIP for anything. - * Asterisk threads are not registered with PJLIB, so attempting to call into - * PJSIP will cause an assertion to be triggered, thus causing the program to - * crash. - * - * \par PJSIP Threads - * - * PJSIP threads are those that originate from handling of PJSIP events, such - * as an incoming SIP request or response, or a transaction timeout. The role - * of these threads is to process information as quickly as possible so that - * the next item on the SIP socket(s) can be serviced. On incoming messages, - * Asterisk automatically will push the request to a servant thread. When your - * module callback is called, processing will already be in a servant. However, - * for other PSJIP events, such as transaction state changes due to timer - * expirations, your module will be called into from a PJSIP thread. If you - * are called into from a PJSIP thread, then you should push whatever processing - * is needed to a servant as soon as possible. You can discern if you are currently - * in a SIP servant thread using the \ref ast_sip_thread_is_servant function. - * - * \par Servants - * - * Servants are where the bulk of SIP work should be performed. These threads - * exist in order to do the work that Asterisk threads and PJSIP threads hand - * off to them. Servant threads register themselves with PJLIB, meaning that - * they are capable of calling PJSIP and PJLIB functions if they wish. - * - * \par Serializer - * - * Tasks are handed off to servant threads using the API call \ref ast_sip_push_task. - * The first parameter of this call is a serializer. If this pointer - * is NULL, then the work will be handed off to whatever servant can currently handle - * the task. If this pointer is non-NULL, then the task will not be executed until - * previous tasks pushed with the same serializer have completed. For more information - * on serializers and the benefits they provide, see \ref ast_threadpool_serializer - * - * \note - * - * Do not make assumptions about individual threads based on a corresponding serializer. - * In other words, just because several tasks use the same serializer when being pushed - * to servants, it does not mean that the same thread is necessarily going to execute those - * tasks, even though they are all guaranteed to be executed in sequence. - */ - -/*! - * \brief Create a new serializer for SIP tasks - * - * See \ref ast_threadpool_serializer for more information on serializers. - * SIP creates serializers so that tasks operating on similar data will run - * in sequence. - * - * \retval NULL Failure - * \retval non-NULL Newly-created serializer - */ -struct ast_taskprocessor *ast_sip_create_serializer(void); - -/*! - * \brief Set a serializer on a SIP dialog so requests and responses are automatically serialized - * - * Passing a NULL serializer is a way to remove a serializer from a dialog. - * - * \param dlg The SIP dialog itself - * \param serializer The serializer to use - */ -void ast_sip_dialog_set_serializer(pjsip_dialog *dlg, struct ast_taskprocessor *serializer); - -/*! - * \brief Set an endpoint on a SIP dialog so in-dialog requests do not undergo endpoint lookup. - * - * \param dlg The SIP dialog itself - * \param endpoint The endpoint that this dialog is communicating with - */ -void ast_sip_dialog_set_endpoint(pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint); - -/*! - * \brief Get the endpoint associated with this dialog - * - * This function increases the refcount of the endpoint by one. Release - * the reference once you are finished with the endpoint. - * - * \param dlg The SIP dialog from which to retrieve the endpoint - * \retval NULL No endpoint associated with this dialog - * \retval non-NULL The endpoint. - */ -struct ast_sip_endpoint *ast_sip_dialog_get_endpoint(pjsip_dialog *dlg); - -/*! - * \brief Pushes a task to SIP servants - * - * This uses the serializer provided to determine how to push the task. - * If the serializer is NULL, then the task will be pushed to the - * servants directly. If the serializer is non-NULL, then the task will be - * queued behind other tasks associated with the same serializer. - * - * \param serializer The serializer to which the task belongs. Can be NULL - * \param sip_task The task to execute - * \param task_data The parameter to pass to the task when it executes - * \retval 0 Success - * \retval -1 Failure - */ -int ast_sip_push_task(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data); - -/*! - * \brief Push a task to SIP servants and wait for it to complete - * - * Like \ref ast_sip_push_task except that it blocks until the task completes. - * - * \warning \b Never use this function in a SIP servant thread. This can potentially - * cause a deadlock. If you are in a SIP servant thread, just call your function - * in-line. - * - * \param serializer The SIP serializer to which the task belongs. May be NULL. - * \param sip_task The task to execute - * \param task_data The parameter to pass to the task when it executes - * \retval 0 Success - * \retval -1 Failure - */ -int ast_sip_push_task_synchronous(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data); - -/*! - * \brief Determine if the current thread is a SIP servant thread - * - * \retval 0 This is not a SIP servant thread - * \retval 1 This is a SIP servant thread - */ -int ast_sip_thread_is_servant(void); - -/*! - * \brief SIP body description - * - * This contains a type and subtype that will be added as - * the "Content-Type" for the message as well as the body - * text. - */ -struct ast_sip_body { - /*! Type of the body, such as "application" */ - const char *type; - /*! Subtype of the body, such as "sdp" */ - const char *subtype; - /*! The text to go in the body */ - const char *body_text; -}; - -/*! - * \brief General purpose method for creating a dialog with an endpoint - * - * \param endpoint A pointer to the endpoint - * \param aor_name Optional name of the AOR to target, may even be an explicit SIP URI - * \param request_user Optional user to place into the target URI - * - * \retval non-NULL success - * \retval NULL failure - */ - pjsip_dialog *ast_sip_create_dialog(const struct ast_sip_endpoint *endpoint, const char *aor_name, const char *request_user); - -/*! - * \brief General purpose method for creating a SIP request - * - * Its typical use would be to create one-off requests such as an out of dialog - * SIP MESSAGE. - * - * The request can either be in- or out-of-dialog. If in-dialog, the - * dlg parameter MUST be present. If out-of-dialog the endpoint parameter - * MUST be present. If both are present, then we will assume that the message - * is to be sent in-dialog. - * - * The uri parameter can be specified if the request should be sent to an explicit - * URI rather than one configured on the endpoint. - * - * \param method The method of the SIP request to send - * \param dlg Optional. If specified, the dialog on which to request the message. - * \param endpoint Optional. If specified, the request will be created out-of-dialog - * to the endpoint. - * \param uri Optional. If specified, the request will be sent to this URI rather - * this value. - * than one configured for the endpoint. - * \param[out] tdata The newly-created request - * \retval 0 Success - * \retval -1 Failure - */ -int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg, - struct ast_sip_endpoint *endpoint, const char *uri, - pjsip_tx_data **tdata); - -/*! - * \brief General purpose method for sending a SIP request - * - * This is a companion function for \ref ast_sip_create_request. The request - * created there can be passed to this function, though any request may be - * passed in. - * - * This will automatically set up handling outbound authentication challenges if - * they arrive. - * - * \param tdata The request to send - * \param dlg Optional. If specified, the dialog on which the request should be sent - * \param endpoint Optional. If specified, the request is sent out-of-dialog to the endpoint. - * \retval 0 Success - * \retval -1 Failure - */ -int ast_sip_send_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint); - -/*! - * \brief Determine if an incoming request requires authentication - * - * This calls into the registered authenticator's requires_authentication callback - * in order to determine if the request requires authentication. - * - * If there is no registered authenticator, then authentication will be assumed - * not to be required. - * - * \param endpoint The endpoint from which the request originates - * \param rdata The incoming SIP request - * \retval non-zero The request requires authentication - * \retval 0 The request does not require authentication - */ -int ast_sip_requires_authentication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata); - -/*! - * \brief Method to determine authentication status of an incoming request - * - * This will call into a registered authenticator. The registered authenticator will - * do what is necessary to determine whether the incoming request passes authentication. - * A tentative response is passed into this function so that if, say, a digest authentication - * challenge should be sent in the ensuing response, it can be added to the response. - * - * \param endpoint The endpoint from the request was sent - * \param rdata The request to potentially authenticate - * \param tdata Tentative response to the request - * \return The result of checking authentication. - */ -enum ast_sip_check_auth_result ast_sip_check_authentication(struct ast_sip_endpoint *endpoint, - pjsip_rx_data *rdata, pjsip_tx_data *tdata); - -/*! - * \brief Create a response to an authentication challenge - * - * This will call into an outbound authenticator's create_request_with_auth callback - * to create a new request with authentication credentials. See the create_request_with_auth - * callback in the \ref ast_sip_outbound_authenticator structure for details about - * the parameters and return values. - */ -int ast_sip_create_request_with_auth(const struct ast_sip_auth_array *auths, pjsip_rx_data *challenge, - pjsip_transaction *tsx, pjsip_tx_data **new_request); - -/*! - * \brief Determine the endpoint that has sent a SIP message - * - * This will call into each of the registered endpoint identifiers' - * identify_endpoint() callbacks until one returns a non-NULL endpoint. - * This will return an ao2 object. Its reference count will need to be - * decremented when completed using the endpoint. - * - * \param rdata The inbound SIP message to use when identifying the endpoint. - * \retval NULL No matching endpoint - * \retval non-NULL The matching endpoint - */ -struct ast_sip_endpoint *ast_sip_identify_endpoint(pjsip_rx_data *rdata); - -/*! - * \brief Add a header to an outbound SIP message - * - * \param tdata The message to add the header to - * \param name The header name - * \param value The header value - * \retval 0 Success - * \retval -1 Failure - */ -int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value); - -/*! - * \brief Add a body to an outbound SIP message - * - * If this is called multiple times, the latest body will replace the current - * body. - * - * \param tdata The message to add the body to - * \param body The message body to add - * \retval 0 Success - * \retval -1 Failure - */ -int ast_sip_add_body(pjsip_tx_data *tdata, const struct ast_sip_body *body); - -/*! - * \brief Add a multipart body to an outbound SIP message - * - * This will treat each part of the input array as part of a multipart body and - * add each part to the SIP message. - * - * \param tdata The message to add the body to - * \param bodies The parts of the body to add - * \retval 0 Success - * \retval -1 Failure - */ -int ast_sip_add_body_multipart(pjsip_tx_data *tdata, const struct ast_sip_body *bodies[], int num_bodies); - -/*! - * \brief Append body data to a SIP message - * - * This acts mostly the same as ast_sip_add_body, except that rather than replacing - * a body if it currently exists, it appends data to an existing body. - * - * \param tdata The message to append the body to - * \param body The string to append to the end of the current body - * \retval 0 Success - * \retval -1 Failure - */ -int ast_sip_append_body(pjsip_tx_data *tdata, const char *body_text); - -/*! - * \brief Copy a pj_str_t into a standard character buffer. - * - * pj_str_t is not NULL-terminated. Any place that expects a NULL- - * terminated string needs to have the pj_str_t copied into a separate - * buffer. - * - * This method copies the pj_str_t contents into the destination buffer - * and NULL-terminates the buffer. - * - * \param dest The destination buffer - * \param src The pj_str_t to copy - * \param size The size of the destination buffer. - */ -void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size); - -/*! - * \brief Get the looked-up endpoint on an out-of dialog request or response - * - * The function may ONLY be called on out-of-dialog requests or responses. For - * in-dialog requests and responses, it is required that the user of the dialog - * has the looked-up endpoint stored locally. - * - * This function should never return NULL if the message is out-of-dialog. It will - * always return NULL if the message is in-dialog. - * - * This function will increase the reference count of the returned endpoint by one. - * Release your reference using the ao2_ref function when finished. - * - * \param rdata Out-of-dialog request or response - * \return The looked up endpoint - */ -struct ast_sip_endpoint *ast_pjsip_rdata_get_endpoint(pjsip_rx_data *rdata); - -/*! - * \brief Retrieve any endpoints available to sorcery. - * - * \retval Endpoints available to sorcery, NULL if no endpoints found. - */ -struct ao2_container *ast_sip_get_endpoints(void); - -/*! - * \brief Retrieve relevant SIP auth structures from sorcery - * - * \param auths Array of sorcery IDs of auth credentials to retrieve - * \param[out] out The retrieved auths are stored here - */ -int ast_sip_retrieve_auths(const struct ast_sip_auth_array *auths, struct ast_sip_auth **out); - -/*! - * \brief Clean up retrieved auth structures from memory - * - * Call this function once you have completed operating on auths - * retrieved from \ref ast_sip_retrieve_auths - * - * \param auths An array of auth structures to clean up - * \param num_auths The number of auths in the array - */ -void ast_sip_cleanup_auths(struct ast_sip_auth *auths[], size_t num_auths); - -/*! - * \brief Checks if the given content type matches type/subtype. - * - * Compares the pjsip_media_type with the passed type and subtype and - * returns the result of that comparison. The media type parameters are - * ignored. - * - * \param content_type The pjsip_media_type structure to compare - * \param type The media type to compare - * \param subtype The media subtype to compare - * \retval 0 No match - * \retval -1 Match - */ -int ast_sip_is_content_type(pjsip_media_type *content_type, char *type, char *subtype); - -/*! - * \brief Send a security event notification for when an invalid endpoint is requested - * - * \param name Name of the endpoint requested - * \param rdata Received message - */ -void ast_sip_report_invalid_endpoint(const char *name, pjsip_rx_data *rdata); - -/*! - * \brief Send a security event notification for when an ACL check fails - * - * \param endpoint Pointer to the endpoint in use - * \param rdata Received message - * \param name Name of the ACL - */ -void ast_sip_report_failed_acl(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, const char *name); - -/*! - * \brief Send a security event notification for when a challenge response has failed - * - * \param endpoint Pointer to the endpoint in use - * \param rdata Received message - */ -void ast_sip_report_auth_failed_challenge_response(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata); - -/*! - * \brief Send a security event notification for when authentication succeeds - * - * \param endpoint Pointer to the endpoint in use - * \param rdata Received message - */ -void ast_sip_report_auth_success(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata); - -/*! - * \brief Send a security event notification for when an authentication challenge is sent - * - * \param endpoint Pointer to the endpoint in use - * \param rdata Received message - * \param tdata Sent message - */ -void ast_sip_report_auth_challenge_sent(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pjsip_tx_data *tdata); - -void ast_sip_initialize_global_headers(void); -void ast_sip_destroy_global_headers(void); - -int ast_sip_add_global_request_header(const char *name, const char *value, int replace); -int ast_sip_add_global_response_header(const char *name, const char *value, int replace); - -int ast_sip_initialize_sorcery_global(struct ast_sorcery *sorcery); - -#endif /* _RES_SIP_H */ diff --git a/include/asterisk/res_sip_exten_state.h b/include/asterisk/res_sip_exten_state.h deleted file mode 100644 index 62662f930..000000000 --- a/include/asterisk/res_sip_exten_state.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Asterisk -- An open source telephony toolkit. - * - * Copyright (C) 2013, Digium, Inc. - * - * Kevin Harwell - * - * 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_EXTEN_STATE_H -#define _RES_SIP_EXTEN_STATE_H - -#include "asterisk/stringfields.h" -#include "asterisk/linkedlists.h" - -#include "asterisk/pbx.h" -#include "asterisk/presencestate.h" - - -/*! - * \brief Contains information pertaining to extension/device state changes. - */ -struct ast_sip_exten_state_data { - /*! The extension of the current state change */ - const char *exten; - /*! The extension state of the change */ - enum ast_extension_states exten_state; - /*! The presence state of the change */ - enum ast_presence_state presence_state; - /*! Current device state information */ - struct ao2_container *device_state_info; -}; - -/*! - * \brief Extension state provider. - */ -struct ast_sip_exten_state_provider { - /*! The name of the event this provider registers for */ - const char *event_name; - /*! Type of the body, ex: "application" */ - const char *type; - /*! Subtype of the body, ex: "pidf+xml" */ - const char *subtype; - /*! Type/Subtype together - ex: application/pidf+xml */ - const char *body_type; - /*! Subscription handler to be used and associated with provider */ - struct ast_sip_subscription_handler *handler; - - /*! - * \brief Create the body text of a NOTIFY request. - * - * Implementors use this to create body information within the given - * ast_str. That information is then added to the NOTIFY request. - * - * \param data Current extension state changes - * \param local URI of the dialog's local party, e.g. 'from' - * \param remote URI of the dialog's remote party, e.g. 'to' - * \param body_text Out parameter used to populate the NOTIFY msg body - * \retval 0 Successfully created the body's text - * \retval -1 Failed to create the body's text - */ - int (*create_body)(struct ast_sip_exten_state_data *data, const char *local, - const char *remote, struct ast_str **body_text); - - /*! Next item in the list */ - AST_LIST_ENTRY(ast_sip_exten_state_provider) next; -}; - -/*! - * \brief Registers an extension state provider. - * - * \param obj An extension state provider - * \retval 0 Successfully registered the extension state provider - * \retval -1 Failed to register the extension state provider - */ -int ast_sip_register_exten_state_provider(struct ast_sip_exten_state_provider *obj); - -/*! - * \brief Unregisters an extension state provider. - * - * \param obj An extension state provider - */ -void ast_sip_unregister_exten_state_provider(struct ast_sip_exten_state_provider *obj); - -#endif diff --git a/include/asterisk/res_sip_pubsub.h b/include/asterisk/res_sip_pubsub.h deleted file mode 100644 index e74f23bf5..000000000 --- a/include/asterisk/res_sip_pubsub.h +++ /dev/null @@ -1,516 +0,0 @@ -/* - * Asterisk -- An open source telephony toolkit. - * - * Copyright (C) 2013, Digium, Inc. - * - * Mark Michelson - * - * 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 a publication - */ -struct ast_sip_publication; - -/*! - * \brief Callbacks that publication handlers will define - */ -struct ast_sip_publish_handler { - /*! \brief The name of the event this handler deals with */ - const char *event_name; - - /*! \brief Publications */ - struct ao2_container *publications; - - /*! - * \brief Called when a PUBLISH to establish a new publication arrives. - * - * \param endpoint The endpoint from whom the PUBLISH arrived - * \param rdata The PUBLISH request - * \retval NULL PUBLISH was not accepted - * \retval non-NULL New publication - * - * \note The callback is expected to send a response for the PUBLISH in success cases. - */ - struct ast_sip_publication *(*new_publication)(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata); - - /*! - * \brief Called when a PUBLISH for an existing publication arrives. - * - * This PUBLISH may be intending to change state or it may be simply renewing - * the publication since the publication is nearing expiration. The callback - * is expected to send a response to the PUBLISH. - * - * \param pub The publication on which the PUBLISH arrived - * \param rdata The PUBLISH request - * \retval 0 Publication was accepted - * \retval non-zero Publication was denied - * - * \note The callback is expected to send a response for the PUBLISH. - */ - int (*publish_refresh)(struct ast_sip_publication *pub, pjsip_rx_data *rdata); - - /*! - * \brief Called when a publication has reached its expiration. - */ - void (*publish_expire)(struct ast_sip_publication *pub); - - /*! - * \brief Called when a PUBLISH arrives to terminate a publication. - * - * \param pub The publication that is terminating - * \param rdata The PUBLISH request terminating the publication - * - * \note The callback is expected to send a response for the PUBLISH. - */ - void (*publish_termination)(struct ast_sip_publication *pub, pjsip_rx_data *rdata); - - AST_LIST_ENTRY(ast_sip_publish_handler) next; -}; - -/*! - * \brief Create a new publication - * - * Publication handlers should call this when a PUBLISH arrives to establish a new publication. - * - * \param endpoint The endpoint from whom the PUBLISHes arrive - * \param rdata The PUBLISH that established the publication - * \retval NULL Failed to create a publication - * \retval non-NULL The newly-created publication - */ -struct ast_sip_publication *ast_sip_create_publication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata); - -/*! - * \brief Given a publication, get the associated endpoint - * - * \param pub The publication - * \retval NULL Failure - * \retval non-NULL The associated endpoint - */ -struct ast_sip_endpoint *ast_sip_publication_get_endpoint(struct ast_sip_publication *pub); - -/*! - * \brief Create a response to an inbound PUBLISH - * - * The created response must be sent using ast_sip_publication_send_response - * - * \param pub The publication - * \param status code The status code to place in the response - * \param rdata The request to which the response is being made - * \param[out] tdata The created response - */ -int ast_sip_publication_create_response(struct ast_sip_publication *pub, int status_code, pjsip_rx_data *rdata, - pjsip_tx_data **tdata); - -/*! - * \brief Send a response for an inbound PUBLISH - * - * \param pub The publication - * \param rdata The request to which the response was made - * \param tdata The response to the request - */ -pj_status_t ast_sip_publication_send_response(struct ast_sip_publication *pub, pjsip_rx_data *rdata, - pjsip_tx_data *tdata); - -/*! - * \brief Register a publish handler - * - * \retval 0 Handler was registered successfully - * \retval non-zero Handler was not registered successfully - */ -int ast_sip_register_publish_handler(struct ast_sip_publish_handler *handler); - -/*! - * \brief Unregister a publish handler - */ -void ast_sip_unregister_publish_handler(struct ast_sip_publish_handler *handler); - -/*! - * \brief Add a datastore to a SIP publication - * - * 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 publication The publication to add the datastore to - * \param datastore The datastore to be added to the subscription - * \retval 0 Success - * \retval -1 Failure - */ -int ast_sip_publication_add_datastore(struct ast_sip_publication *publication, struct ast_datastore *datastore); - -/*! - * \brief Retrieve a publication 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 publication The publication 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_publication_get_datastore(struct ast_sip_publication *publication, const char *name); - -/*! - * \brief Remove a publication datastore from the publication - * - * This operation may cause the datastore's free() callback to be called if the reference - * count reaches zero. - * - * \param publication The publication to remove the datastore from - * \param name The name of the datastore to remove - */ -void ast_sip_publication_remove_datastore(struct ast_sip_publication *publication, const char *name); - -/*! - * \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 Get the underlying PJSIP dialog structure - * - * Call this function when information needs to be retrieved from the - * underlying pjsip dialog. - * - * 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_dialog - */ -pjsip_dialog *ast_sip_subscription_get_dlg(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 */ diff --git a/include/asterisk/res_sip_session.h b/include/asterisk/res_sip_session.h deleted file mode 100644 index 4c5ac5534..000000000 --- a/include/asterisk/res_sip_session.h +++ /dev/null @@ -1,561 +0,0 @@ -/* - * Asterisk -- An open source telephony toolkit. - * - * Copyright (C) 2013, Digium, Inc. - * - * Mark Michelson - * - * 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" -/* Needed for ast_sdp_srtp struct */ -#include "asterisk/sdp_srtp.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_dsp; -struct ast_udptl; - -/*! \brief T.38 states for a session */ -enum ast_sip_session_t38state { - T38_DISABLED = 0, /*!< Not enabled */ - T38_LOCAL_REINVITE, /*!< Offered from local - REINVITE */ - T38_PEER_REINVITE, /*!< Offered from peer - REINVITE */ - T38_ENABLED, /*!< Negotiated (enabled) */ - T38_REJECTED, /*!< Refused */ -}; - -struct ast_sip_session_sdp_handler; - -/*! - * \brief A structure containing SIP session media information - */ -struct ast_sip_session_media { - union { - /*! \brief RTP instance itself */ - struct ast_rtp_instance *rtp; - /*! \brief UDPTL instance itself */ - struct ast_udptl *udptl; - }; - /*! \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 Holds SRTP information */ - struct ast_sdp_srtp *srtp; - /*! \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; - /* When we need to forcefully end the session */ - pj_timer_entry scheduled_termination; - /* Identity of endpoint this session deals with */ - struct ast_party_id id; - /* Requested capabilities */ - struct ast_format_cap *req_caps; - /* Codecs overriden by dialplan on an outgoing request */ - struct ast_codec_pref override_prefs; - /* Optional DSP, used only for inband DTMF detection if configured */ - struct ast_dsp *dsp; - /* Whether the termination of the session should be deferred */ - unsigned int defer_terminate:1; - /* Deferred incoming re-invite */ - pjsip_rx_data *deferred_reinvite; - /* Current T.38 state */ - enum ast_sip_session_t38state t38state; -}; - -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); -typedef int (*ast_sip_session_sdp_creation_cb)(struct ast_sip_session *session, pjmedia_sdp_session *sdp); - -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 Determine whether a stream requires that the re-invite be deferred. - * If a stream can not be immediately negotiated the re-invite can be deferred and - * resumed at a later time. It is up to the handler which caused deferral to occur - * to resume it. - * \param session The session for which the media is being re-invited - * \param session_media The media being reinvited - * \param sdp The entire SDP. - * \retval 0 The stream was unhandled or does not need the re-invite to be deferred. - * \retval 1 Re-invite should be deferred and will be resumed later. No further operations will take place. - * \note This is optional, if not implemented the stream is assumed to not be deferred. - */ - int (*defer_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 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 A structure which contains a channel implementation and session - */ -struct ast_sip_channel_pvt { - /*! \brief Pointer to channel specific implementation information, must be ao2 object */ - void *pvt; - /*! \brief Pointer to session */ - struct ast_sip_session *session; -}; - -/*! - * \brief Allocate a new SIP channel pvt structure - * - * \param pvt Pointer to channel specific implementation - * \param session Pointer to SIP session - * - * \retval non-NULL success - * \retval NULL failure - */ -struct ast_sip_channel_pvt *ast_sip_channel_pvt_alloc(void *pvt, struct ast_sip_session *session); - -/*! - * \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 Defer local termination of a session until remote side terminates, or an amount of time passes - * - * \param session The session to defer termination on - */ -void ast_sip_session_defer_termination(struct ast_sip_session *session); - -/*! - * \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 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_sdp_creation Callback called when SDP 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_sdp_creation_cb on_sdp_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 Creates an INVITE request. - * - * \param session Starting session for the INVITE - * \param tdata The created request. - */ -int ast_sip_session_create_invite(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); - -/*! - * \brief Retrieves a session from a dialog - * - * \param dlg The dialog to retrieve the session from - * - * \retval non-NULL if session exists - * \retval NULL if no session - * - * \note The reference count of the session is increased when returned - * - * \note This function *must* be called with the dialog locked - */ -struct ast_sip_session *ast_sip_dialog_get_session(pjsip_dialog *dlg); - -/*! - * \brief Resumes processing of a deferred incoming re-invite - * - * \param session The session which has a pending incoming re-invite - * - * \note When resuming a re-invite it is given to the pjsip stack as if it - * had just been received from a transport, this means that the deferral - * callback will be called again. - */ -void ast_sip_session_resume_reinvite(struct ast_sip_session *session); - -#endif /* _RES_SIP_SESSION_H */ -- cgit v1.2.3