2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2013, Digium, Inc.
6 * Mark Michelson <mmichelson@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
22 #include "asterisk/stringfields.h"
23 /* Needed for struct ast_sockaddr */
24 #include "asterisk/netsock2.h"
25 /* Needed for linked list macros */
26 #include "asterisk/linkedlists.h"
27 /* Needed for ast_party_id */
28 #include "asterisk/channel.h"
29 /* Needed for ast_sorcery */
30 #include "asterisk/sorcery.h"
31 /* Needed for ast_dnsmgr */
32 #include "asterisk/dnsmgr.h"
33 /* Needed for ast_endpoint */
34 #include "asterisk/endpoints.h"
35 /* Needed for ast_t38_ec_modes */
36 #include "asterisk/udptl.h"
37 /* Needed for pj_sockaddr */
39 /* Needed for ast_rtp_dtls_cfg struct */
40 #include "asterisk/rtp_engine.h"
41 /* Needed for AST_VECTOR macro */
42 #include "asterisk/vector.h"
43 /* Needed for ast_sip_for_each_channel_snapshot struct */
44 #include "asterisk/stasis_channels.h"
45 #include "asterisk/stasis_endpoints.h"
47 /* Forward declarations of PJSIP stuff */
52 struct pjsip_transport;
53 struct pjsip_tpfactory;
54 struct pjsip_tls_setting;
55 struct pjsip_tpselector;
58 * \brief Structure for SIP transport information
60 struct ast_sip_transport_state {
61 /*! \brief Transport itself */
62 struct pjsip_transport *transport;
64 /*! \brief Transport factory */
65 struct pjsip_tpfactory *factory;
68 #define SIP_SORCERY_DOMAIN_ALIAS_TYPE "domain_alias"
71 * Details about a SIP domain alias
73 struct ast_sip_domain_alias {
74 /*! Sorcery object details */
75 SORCERY_OBJECT(details);
76 AST_DECLARE_STRING_FIELDS(
77 /*! Domain to be aliased to */
78 AST_STRING_FIELD(domain);
82 /*! \brief Maximum number of ciphers supported for a TLS transport */
83 #define SIP_TLS_MAX_CIPHERS 64
86 * \brief Transport to bind to
88 struct ast_sip_transport {
89 /*! Sorcery object details */
90 SORCERY_OBJECT(details);
91 AST_DECLARE_STRING_FIELDS(
92 /*! Certificate of authority list file */
93 AST_STRING_FIELD(ca_list_file);
94 /*! Public certificate file */
95 AST_STRING_FIELD(cert_file);
96 /*! Optional private key of the certificate file */
97 AST_STRING_FIELD(privkey_file);
98 /*! Password to open the private key */
99 AST_STRING_FIELD(password);
100 /*! External signaling address */
101 AST_STRING_FIELD(external_signaling_address);
102 /*! External media address */
103 AST_STRING_FIELD(external_media_address);
104 /*! Optional domain to use for messages if provided could not be found */
105 AST_STRING_FIELD(domain);
107 /*! Type of transport */
108 enum ast_transport type;
109 /*! Address and port to bind to */
111 /*! Number of simultaneous asynchronous operations */
112 unsigned int async_operations;
113 /*! Optional external port for signaling */
114 unsigned int external_signaling_port;
116 pjsip_tls_setting tls;
117 /*! Configured TLS ciphers */
118 pj_ssl_cipher ciphers[SIP_TLS_MAX_CIPHERS];
119 /*! Optional local network information, used for NAT purposes */
120 struct ast_ha *localnet;
121 /*! DNS manager for refreshing the external address */
122 struct ast_dnsmgr_entry *external_address_refresher;
123 /*! Optional external address information */
124 struct ast_sockaddr external_address;
125 /*! Transport state information */
126 struct ast_sip_transport_state *state;
127 /*! QOS DSCP TOS bits */
136 * \brief Structure for SIP nat hook information
138 struct ast_sip_nat_hook {
139 /*! Sorcery object details */
140 SORCERY_OBJECT(details);
141 /*! Callback for when a message is going outside of our local network */
142 void (*outgoing_external_message)(struct pjsip_tx_data *tdata, struct ast_sip_transport *transport);
146 * \brief Contact associated with an address of record
148 struct ast_sip_contact {
149 /*! Sorcery object details, the id is the aor name plus a random string */
150 SORCERY_OBJECT(details);
151 AST_DECLARE_STRING_FIELDS(
152 /*! Full URI of the contact */
153 AST_STRING_FIELD(uri);
154 /*! Outbound proxy to use for qualify */
155 AST_STRING_FIELD(outbound_proxy);
156 /*! Path information to place in Route headers */
157 AST_STRING_FIELD(path);
158 /*! Content of the User-Agent header in REGISTER request */
159 AST_STRING_FIELD(user_agent);
161 /*! Absolute time that this contact is no longer valid after */
162 struct timeval expiration_time;
163 /*! Frequency to send OPTIONS requests to contact. 0 is disabled. */
164 unsigned int qualify_frequency;
165 /*! If true authenticate the qualify if needed */
166 int authenticate_qualify;
169 #define CONTACT_STATUS "contact_status"
172 * \brief Status type for a contact.
174 enum ast_sip_contact_status_type {
180 * \brief A contact's status.
182 * \detail Maintains a contact's current status and round trip time
185 struct ast_sip_contact_status {
186 SORCERY_OBJECT(details);
187 /*! Current status for a contact (default - unavailable) */
188 enum ast_sip_contact_status_type status;
189 /*! The round trip start time set before sending a qualify request */
190 struct timeval rtt_start;
191 /*! The round trip time in microseconds */
196 * \brief A SIP address of record
199 /*! Sorcery object details, the id is the AOR name */
200 SORCERY_OBJECT(details);
201 AST_DECLARE_STRING_FIELDS(
202 /*! Voicemail boxes for this AOR */
203 AST_STRING_FIELD(mailboxes);
204 /*! Outbound proxy for OPTIONS requests */
205 AST_STRING_FIELD(outbound_proxy);
207 /*! Minimum expiration time */
208 unsigned int minimum_expiration;
209 /*! Maximum expiration time */
210 unsigned int maximum_expiration;
211 /*! Default contact expiration if one is not provided in the contact */
212 unsigned int default_expiration;
213 /*! Frequency to send OPTIONS requests to AOR contacts. 0 is disabled. */
214 unsigned int qualify_frequency;
215 /*! If true authenticate the qualify if needed */
216 int authenticate_qualify;
217 /*! Maximum number of external contacts, 0 to disable */
218 unsigned int max_contacts;
219 /*! Whether to remove any existing contacts not related to an incoming REGISTER when it comes in */
220 unsigned int remove_existing;
221 /*! Any permanent configured contacts */
222 struct ao2_container *permanent_contacts;
223 /*! Determines whether SIP Path headers are supported */
224 unsigned int support_path;
228 * \brief A wrapper for contact that adds the aor_id and
229 * a consistent contact id. Used by ast_sip_for_each_contact.
231 struct ast_sip_contact_wrapper {
232 /*! The id of the parent aor. */
234 /*! The id of contact in form of aor_id/contact_uri. */
236 /*! Pointer to the actual contact. */
237 struct ast_sip_contact *contact;
241 * \brief DTMF modes for SIP endpoints
243 enum ast_sip_dtmf_mode {
244 /*! No DTMF to be used */
246 /* XXX Should this be 2833 instead? */
247 /*! Use RFC 4733 events for DTMF */
248 AST_SIP_DTMF_RFC_4733,
249 /*! Use DTMF in the audio stream */
251 /*! Use SIP INFO DTMF (blech) */
256 * \brief Methods of storing SIP digest authentication credentials.
258 * Note that both methods result in MD5 digest authentication being
259 * used. The two methods simply alter how Asterisk determines the
260 * credentials for a SIP authentication
262 enum ast_sip_auth_type {
263 /*! Credentials stored as a username and password combination */
264 AST_SIP_AUTH_TYPE_USER_PASS,
265 /*! Credentials stored as an MD5 sum */
266 AST_SIP_AUTH_TYPE_MD5,
267 /*! Credentials not stored this is a fake auth */
268 AST_SIP_AUTH_TYPE_ARTIFICIAL
271 #define SIP_SORCERY_AUTH_TYPE "auth"
273 struct ast_sip_auth {
274 /* Sorcery ID of the auth is its name */
275 SORCERY_OBJECT(details);
276 AST_DECLARE_STRING_FIELDS(
277 /* Identification for these credentials */
278 AST_STRING_FIELD(realm);
279 /* Authentication username */
280 AST_STRING_FIELD(auth_user);
281 /* Authentication password */
282 AST_STRING_FIELD(auth_pass);
283 /* Authentication credentials in MD5 format (hash of user:realm:pass) */
284 AST_STRING_FIELD(md5_creds);
286 /* The time period (in seconds) that a nonce may be reused */
287 unsigned int nonce_lifetime;
288 /* Used to determine what to use when authenticating */
289 enum ast_sip_auth_type type;
292 AST_VECTOR(ast_sip_auth_vector, const char *);
295 * \brief Different methods by which incoming requests can be matched to endpoints
297 enum ast_sip_endpoint_identifier_type {
298 /*! Identify based on user name in From header */
299 AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME = (1 << 0),
302 enum ast_sip_session_refresh_method {
303 /*! Use reinvite to negotiate direct media */
304 AST_SIP_SESSION_REFRESH_METHOD_INVITE,
305 /*! Use UPDATE to negotiate direct media */
306 AST_SIP_SESSION_REFRESH_METHOD_UPDATE,
309 enum ast_sip_direct_media_glare_mitigation {
310 /*! Take no special action to mitigate reinvite glare */
311 AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_NONE,
312 /*! Do not send an initial direct media session refresh on outgoing call legs
313 * Subsequent session refreshes will be sent no matter the session direction
315 AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_OUTGOING,
316 /*! Do not send an initial direct media session refresh on incoming call legs
317 * Subsequent session refreshes will be sent no matter the session direction
319 AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_INCOMING,
322 enum ast_sip_session_media_encryption {
323 /*! Invalid media encryption configuration */
324 AST_SIP_MEDIA_TRANSPORT_INVALID = 0,
325 /*! Do not allow any encryption of session media */
326 AST_SIP_MEDIA_ENCRYPT_NONE,
327 /*! Offer SDES-encrypted session media */
328 AST_SIP_MEDIA_ENCRYPT_SDES,
329 /*! Offer encrypted session media with datagram TLS key exchange */
330 AST_SIP_MEDIA_ENCRYPT_DTLS,
333 enum ast_sip_session_redirect {
334 /*! User portion of the target URI should be used as the target in the dialplan */
335 AST_SIP_REDIRECT_USER = 0,
336 /*! Target URI should be used as the target in the dialplan */
337 AST_SIP_REDIRECT_URI_CORE,
338 /*! Target URI should be used as the target within chan_pjsip itself */
339 AST_SIP_REDIRECT_URI_PJSIP,
343 * \brief Session timers options
345 struct ast_sip_timer_options {
346 /*! Minimum session expiration period, in seconds */
348 /*! Session expiration period, in seconds */
349 unsigned int sess_expires;
353 * \brief Endpoint configuration for SIP extensions.
355 * SIP extensions, in this case refers to features
356 * indicated in Supported or Required headers.
358 struct ast_sip_endpoint_extensions {
359 /*! Enabled SIP extensions */
362 struct ast_sip_timer_options timer;
366 * \brief Endpoint configuration for unsolicited MWI
368 struct ast_sip_mwi_configuration {
369 AST_DECLARE_STRING_FIELDS(
370 /*! Configured voicemail boxes for this endpoint. Used for MWI */
371 AST_STRING_FIELD(mailboxes);
372 /*! Username to use when sending MWI NOTIFYs to this endpoint */
373 AST_STRING_FIELD(fromuser);
375 /* Should mailbox states be combined into a single notification? */
376 unsigned int aggregate;
380 * \brief Endpoint subscription configuration
382 struct ast_sip_endpoint_subscription_configuration {
383 /*! Indicates if endpoint is allowed to initiate subscriptions */
385 /*! The minimum allowed expiration for subscriptions from endpoint */
386 unsigned int minexpiry;
387 /*! Message waiting configuration */
388 struct ast_sip_mwi_configuration mwi;
392 * \brief NAT configuration options for endpoints
394 struct ast_sip_endpoint_nat_configuration {
395 /*! Whether to force using the source IP address/port for sending responses */
396 unsigned int force_rport;
397 /*! Whether to rewrite the Contact header with the source IP address/port or not */
398 unsigned int rewrite_contact;
402 * \brief Party identification options for endpoints
404 * This includes caller ID, connected line, and redirecting-related options
406 struct ast_sip_endpoint_id_configuration {
407 struct ast_party_id self;
408 /*! Do we accept identification information from this endpoint */
409 unsigned int trust_inbound;
410 /*! Do we send private identification information to this endpoint? */
411 unsigned int trust_outbound;
412 /*! Do we send P-Asserted-Identity headers to this endpoint? */
413 unsigned int send_pai;
414 /*! Do we send Remote-Party-ID headers to this endpoint? */
415 unsigned int send_rpid;
416 /*! Do we add Diversion headers to applicable outgoing requests/responses? */
417 unsigned int send_diversion;
418 /*! When performing connected line update, which method should be used */
419 enum ast_sip_session_refresh_method refresh_method;
423 * \brief Call pickup configuration options for endpoints
425 struct ast_sip_endpoint_pickup_configuration {
427 ast_group_t callgroup;
429 ast_group_t pickupgroup;
430 /*! Named call group */
431 struct ast_namedgroups *named_callgroups;
432 /*! Named pickup group */
433 struct ast_namedgroups *named_pickupgroups;
437 * \brief Configuration for one-touch INFO recording
439 struct ast_sip_info_recording_configuration {
440 AST_DECLARE_STRING_FIELDS(
441 /*! Feature to enact when one-touch recording INFO with Record: On is received */
442 AST_STRING_FIELD(onfeature);
443 /*! Feature to enact when one-touch recording INFO with Record: Off is received */
444 AST_STRING_FIELD(offfeature);
446 /*! Is one-touch recording permitted? */
447 unsigned int enabled;
451 * \brief Endpoint configuration options for INFO packages
453 struct ast_sip_endpoint_info_configuration {
454 /*! Configuration for one-touch recording */
455 struct ast_sip_info_recording_configuration recording;
459 * \brief RTP configuration for SIP endpoints
461 struct ast_sip_media_rtp_configuration {
462 AST_DECLARE_STRING_FIELDS(
463 /*! Configured RTP engine for this endpoint. */
464 AST_STRING_FIELD(engine);
466 /*! Whether IPv6 RTP is enabled or not */
468 /*! Whether symmetric RTP is enabled or not */
469 unsigned int symmetric;
470 /*! Whether ICE support is enabled or not */
471 unsigned int ice_support;
472 /*! Whether to use the "ptime" attribute received from the endpoint or not */
473 unsigned int use_ptime;
474 /*! Do we use AVPF exclusively for this endpoint? */
475 unsigned int use_avpf;
476 /*! Do we force AVP, AVPF, SAVP, or SAVPF even for DTLS media streams? */
477 unsigned int force_avp;
478 /*! Do we use the received media transport in our answer SDP */
479 unsigned int use_received_transport;
480 /*! \brief DTLS-SRTP configuration information */
481 struct ast_rtp_dtls_cfg dtls_cfg;
482 /*! Should SRTP use a 32 byte tag instead of an 80 byte tag? */
483 unsigned int srtp_tag_32;
484 /*! Do we use media encryption? what type? */
485 enum ast_sip_session_media_encryption encryption;
489 * \brief Direct media options for SIP endpoints
491 struct ast_sip_direct_media_configuration {
492 /*! Boolean indicating if direct_media is permissible */
493 unsigned int enabled;
494 /*! When using direct media, which method should be used */
495 enum ast_sip_session_refresh_method method;
496 /*! Take steps to mitigate glare for direct media */
497 enum ast_sip_direct_media_glare_mitigation glare_mitigation;
498 /*! Do not attempt direct media session refreshes if a media NAT is detected */
499 unsigned int disable_on_nat;
502 struct ast_sip_t38_configuration {
503 /*! Whether T.38 UDPTL support is enabled or not */
504 unsigned int enabled;
505 /*! Error correction setting for T.38 UDPTL */
506 enum ast_t38_ec_modes error_correction;
507 /*! Explicit T.38 max datagram value, may be 0 to indicate the remote side can be trusted */
508 unsigned int maxdatagram;
509 /*! Whether NAT Support is enabled for T.38 UDPTL sessions or not */
511 /*! Whether to use IPv6 for UDPTL or not */
516 * \brief Media configuration for SIP endpoints
518 struct ast_sip_endpoint_media_configuration {
519 AST_DECLARE_STRING_FIELDS(
520 /*! Optional media address to use in SDP */
521 AST_STRING_FIELD(address);
522 /*! SDP origin username */
523 AST_STRING_FIELD(sdpowner);
524 /*! SDP session name */
525 AST_STRING_FIELD(sdpsession);
527 /*! RTP media configuration */
528 struct ast_sip_media_rtp_configuration rtp;
529 /*! Direct media options */
530 struct ast_sip_direct_media_configuration direct_media;
531 /*! T.38 (FoIP) options */
532 struct ast_sip_t38_configuration t38;
533 /*! Configured codecs */
534 struct ast_format_cap *codecs;
535 /*! DSCP TOS bits for audio streams */
536 unsigned int tos_audio;
537 /*! Priority for audio streams */
538 unsigned int cos_audio;
539 /*! DSCP TOS bits for video streams */
540 unsigned int tos_video;
541 /*! Priority for video streams */
542 unsigned int cos_video;
546 * \brief An entity with which Asterisk communicates
548 struct ast_sip_endpoint {
549 SORCERY_OBJECT(details);
550 AST_DECLARE_STRING_FIELDS(
551 /*! Context to send incoming calls to */
552 AST_STRING_FIELD(context);
553 /*! Name of an explicit transport to use */
554 AST_STRING_FIELD(transport);
555 /*! Outbound proxy to use */
556 AST_STRING_FIELD(outbound_proxy);
557 /*! Explicit AORs to dial if none are specified */
558 AST_STRING_FIELD(aors);
559 /*! Musiconhold class to suggest that the other side use when placing on hold */
560 AST_STRING_FIELD(mohsuggest);
561 /*! Configured tone zone for this endpoint. */
562 AST_STRING_FIELD(zone);
563 /*! Configured language for this endpoint. */
564 AST_STRING_FIELD(language);
565 /*! Default username to place in From header */
566 AST_STRING_FIELD(fromuser);
567 /*! Domain to place in From header */
568 AST_STRING_FIELD(fromdomain);
569 /*! Context to route incoming MESSAGE requests to */
570 AST_STRING_FIELD(message_context);
571 /*! Accountcode to auto-set on channels */
572 AST_STRING_FIELD(accountcode);
574 /*! Configuration for extensions */
575 struct ast_sip_endpoint_extensions extensions;
576 /*! Configuration relating to media */
577 struct ast_sip_endpoint_media_configuration media;
578 /*! SUBSCRIBE/NOTIFY configuration options */
579 struct ast_sip_endpoint_subscription_configuration subscription;
580 /*! NAT configuration */
581 struct ast_sip_endpoint_nat_configuration nat;
582 /*! Party identification options */
583 struct ast_sip_endpoint_id_configuration id;
584 /*! Configuration options for INFO packages */
585 struct ast_sip_endpoint_info_configuration info;
586 /*! Call pickup configuration */
587 struct ast_sip_endpoint_pickup_configuration pickup;
588 /*! Inbound authentication credentials */
589 struct ast_sip_auth_vector inbound_auths;
590 /*! Outbound authentication credentials */
591 struct ast_sip_auth_vector outbound_auths;
592 /*! DTMF mode to use with this endpoint */
593 enum ast_sip_dtmf_mode dtmf;
594 /*! Method(s) by which the endpoint should be identified. */
595 enum ast_sip_endpoint_identifier_type ident_method;
596 /*! Boolean indicating if ringing should be sent as inband progress */
597 unsigned int inband_progress;
598 /*! Pointer to the persistent Asterisk endpoint */
599 struct ast_endpoint *persistent;
600 /*! The number of channels at which busy device state is returned */
601 unsigned int devicestate_busy_at;
602 /*! Whether fax detection is enabled or not (CNG tone detection) */
603 unsigned int faxdetect;
604 /*! Determines if transfers (using REFER) are allowed by this endpoint */
605 unsigned int allowtransfer;
606 /*! Method used when handling redirects */
607 enum ast_sip_session_redirect redirect_method;
608 /*! Variables set on channel creation */
609 struct ast_variable *channel_vars;
610 /*! Whether to place a 'user=phone' parameter into the request URI if user is a number */
611 unsigned int usereqphone;
615 * \brief Initialize an auth vector with the configured values.
617 * \param vector Vector to initialize
618 * \param auth_names Comma-separated list of names to set in the array
620 * \retval non-zero Failure
622 int ast_sip_auth_vector_init(struct ast_sip_auth_vector *vector, const char *auth_names);
625 * \brief Free contents of an auth vector.
627 * \param array Vector whose contents are to be freed
629 void ast_sip_auth_vector_destroy(struct ast_sip_auth_vector *vector);
632 * \brief Possible returns from ast_sip_check_authentication
634 enum ast_sip_check_auth_result {
635 /*! Authentication needs to be challenged */
636 AST_SIP_AUTHENTICATION_CHALLENGE,
637 /*! Authentication succeeded */
638 AST_SIP_AUTHENTICATION_SUCCESS,
639 /*! Authentication failed */
640 AST_SIP_AUTHENTICATION_FAILED,
641 /*! Authentication encountered some internal error */
642 AST_SIP_AUTHENTICATION_ERROR,
646 * \brief An interchangeable way of handling digest authentication for SIP.
648 * An authenticator is responsible for filling in the callbacks provided below. Each is called from a publicly available
649 * function in res_sip. The authenticator can use configuration or other local policy to determine whether authentication
650 * should take place and what credentials should be used when challenging and authenticating a request.
652 struct ast_sip_authenticator {
654 * \brief Check if a request requires authentication
655 * See ast_sip_requires_authentication for more details
657 int (*requires_authentication)(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
659 * \brief Check that an incoming request passes authentication.
661 * The tdata parameter is useful for adding information such as digest challenges.
663 * \param endpoint The endpoint sending the incoming request
664 * \param rdata The incoming request
665 * \param tdata Tentative outgoing request.
667 enum ast_sip_check_auth_result (*check_authentication)(struct ast_sip_endpoint *endpoint,
668 pjsip_rx_data *rdata, pjsip_tx_data *tdata);
672 * \brief an interchangeable way of responding to authentication challenges
674 * An outbound authenticator takes incoming challenges and formulates a new SIP request with
677 struct ast_sip_outbound_authenticator {
679 * \brief Create a new request with authentication credentials
681 * \param auths A vector of IDs of auth sorcery objects
682 * \param challenge The SIP response with authentication challenge(s)
683 * \param tsx The transaction in which the challenge was received
684 * \param new_request The new SIP request with challenge response(s)
685 * \retval 0 Successfully created new request
686 * \retval -1 Failed to create a new request
688 int (*create_request_with_auth)(const struct ast_sip_auth_vector *auths, struct pjsip_rx_data *challenge,
689 struct pjsip_transaction *tsx, struct pjsip_tx_data **new_request);
693 * \brief An entity responsible for identifying the source of a SIP message
695 struct ast_sip_endpoint_identifier {
697 * \brief Callback used to identify the source of a message.
698 * See ast_sip_identify_endpoint for more details
700 struct ast_sip_endpoint *(*identify_endpoint)(pjsip_rx_data *rdata);
704 * \brief Register a SIP service in Asterisk.
706 * This is more-or-less a wrapper around pjsip_endpt_register_module().
707 * Registering a service makes it so that PJSIP will call into the
708 * service at appropriate times. For more information about PJSIP module
709 * callbacks, see the PJSIP documentation. Asterisk modules that call
710 * this function will likely do so at module load time.
712 * \param module The module that is to be registered with PJSIP
716 int ast_sip_register_service(pjsip_module *module);
719 * This is the opposite of ast_sip_register_service(). Unregistering a
720 * service means that PJSIP will no longer call into the module any more.
721 * This will likely occur when an Asterisk module is unloaded.
723 * \param module The PJSIP module to unregister
725 void ast_sip_unregister_service(pjsip_module *module);
728 * \brief Register a SIP authenticator
730 * An authenticator has three main purposes:
731 * 1) Determining if authentication should be performed on an incoming request
732 * 2) Gathering credentials necessary for issuing an authentication challenge
733 * 3) Authenticating a request that has credentials
735 * Asterisk provides a default authenticator, but it may be replaced by a
736 * custom one if desired.
738 * \param auth The authenticator to register
742 int ast_sip_register_authenticator(struct ast_sip_authenticator *auth);
745 * \brief Unregister a SIP authenticator
747 * When there is no authenticator registered, requests cannot be challenged
750 * \param auth The authenticator to unregister
752 void ast_sip_unregister_authenticator(struct ast_sip_authenticator *auth);
755 * \brief Register an outbound SIP authenticator
757 * An outbound authenticator is responsible for creating responses to
758 * authentication challenges by remote endpoints.
760 * \param auth The authenticator to register
764 int ast_sip_register_outbound_authenticator(struct ast_sip_outbound_authenticator *outbound_auth);
767 * \brief Unregister an outbound SIP authenticator
769 * When there is no outbound authenticator registered, authentication challenges
770 * will be handled as any other final response would be.
772 * \param auth The authenticator to unregister
774 void ast_sip_unregister_outbound_authenticator(struct ast_sip_outbound_authenticator *auth);
777 * \brief Register a SIP endpoint identifier
779 * An endpoint identifier's purpose is to determine which endpoint a given SIP
780 * message has come from.
782 * Multiple endpoint identifiers may be registered so that if an endpoint
783 * cannot be identified by one identifier, it may be identified by another.
785 * Asterisk provides two endpoint identifiers. One identifies endpoints based
786 * on the user part of the From header URI. The other identifies endpoints based
787 * on the source IP address.
789 * If the order in which endpoint identifiers is run is important to you, then
790 * be sure to load individual endpoint identifier modules in the order you wish
791 * for them to be run in modules.conf
793 * \param identifier The SIP endpoint identifier to register
797 int ast_sip_register_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier);
800 * \brief Unregister a SIP endpoint identifier
802 * This stops an endpoint identifier from being used.
804 * \param identifier The SIP endoint identifier to unregister
806 void ast_sip_unregister_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier);
809 * \brief Allocate a new SIP endpoint
811 * This will return an endpoint with its refcount increased by one. This reference
812 * can be released using ao2_ref().
814 * \param name The name of the endpoint.
815 * \retval NULL Endpoint allocation failed
816 * \retval non-NULL The newly allocated endpoint
818 void *ast_sip_endpoint_alloc(const char *name);
821 * \brief Get a pointer to the PJSIP endpoint.
823 * This is useful when modules have specific information they need
824 * to register with the PJSIP core.
825 * \retval NULL endpoint has not been created yet.
826 * \retval non-NULL PJSIP endpoint.
828 pjsip_endpoint *ast_sip_get_pjsip_endpoint(void);
831 * \brief Get a pointer to the SIP sorcery structure.
833 * \retval NULL sorcery has not been initialized
834 * \retval non-NULL sorcery structure
836 struct ast_sorcery *ast_sip_get_sorcery(void);
839 * \brief Initialize transport support on a sorcery instance
844 int ast_sip_initialize_sorcery_transport(void);
847 * \brief Destroy transport support on a sorcery instance
852 int ast_sip_destroy_sorcery_transport(void);
855 * \brief Initialize qualify support on a sorcery instance
860 int ast_sip_initialize_sorcery_qualify(void);
863 * \brief Initialize location support on a sorcery instance
868 int ast_sip_initialize_sorcery_location(void);
871 * \brief Destroy location support on a sorcery instance
876 int ast_sip_destroy_sorcery_location(void);
879 * \brief Retrieve a named AOR
881 * \param aor_name Name of the AOR
883 * \retval NULL if not found
884 * \retval non-NULL if found
886 struct ast_sip_aor *ast_sip_location_retrieve_aor(const char *aor_name);
889 * \brief Retrieve the first bound contact for an AOR
891 * \param aor Pointer to the AOR
892 * \retval NULL if no contacts available
893 * \retval non-NULL if contacts available
895 struct ast_sip_contact *ast_sip_location_retrieve_first_aor_contact(const struct ast_sip_aor *aor);
898 * \brief Retrieve all contacts currently available for an AOR
900 * \param aor Pointer to the AOR
902 * \retval NULL if no contacts available
903 * \retval non-NULL if contacts available
905 struct ao2_container *ast_sip_location_retrieve_aor_contacts(const struct ast_sip_aor *aor);
908 * \brief Retrieve the first bound contact from a list of AORs
910 * \param aor_list A comma-separated list of AOR names
911 * \retval NULL if no contacts available
912 * \retval non-NULL if contacts available
914 struct ast_sip_contact *ast_sip_location_retrieve_contact_from_aor_list(const char *aor_list);
917 * \brief Retrieve a named contact
919 * \param contact_name Name of the contact
921 * \retval NULL if not found
922 * \retval non-NULL if found
924 struct ast_sip_contact *ast_sip_location_retrieve_contact(const char *contact_name);
927 * \brief Add a new contact to an AOR
929 * \param aor Pointer to the AOR
930 * \param uri Full contact URI
931 * \param expiration_time Optional expiration time of the contact
932 * \param path_info Path information
933 * \param user_agent User-Agent header from REGISTER request
938 int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri,
939 struct timeval expiration_time, const char *path_info, const char *user_agent);
942 * \brief Update a contact
944 * \param contact New contact object with details
949 int ast_sip_location_update_contact(struct ast_sip_contact *contact);
952 * \brief Delete a contact
954 * \param contact Contact object to delete
959 int ast_sip_location_delete_contact(struct ast_sip_contact *contact);
962 * \brief Initialize domain aliases support on a sorcery instance
967 int ast_sip_initialize_sorcery_domain_alias(void);
970 * \brief Initialize authentication support on a sorcery instance
975 int ast_sip_initialize_sorcery_auth(void);
978 * \brief Destroy authentication support on a sorcery instance
983 int ast_sip_destroy_sorcery_auth(void);
986 * \brief Callback called when an outbound request with authentication credentials is to be sent in dialog
988 * This callback will have the created request on it. The callback's purpose is to do any extra
989 * housekeeping that needs to be done as well as to send the request out.
991 * This callback is only necessary if working with a PJSIP API that sits between the application
992 * and the dialog layer.
994 * \param dlg The dialog to which the request belongs
995 * \param tdata The created request to be sent out
996 * \param user_data Data supplied with the callback
1001 typedef int (*ast_sip_dialog_outbound_auth_cb)(pjsip_dialog *dlg, pjsip_tx_data *tdata, void *user_data);
1004 * \brief Set up outbound authentication on a SIP dialog
1006 * This sets up the infrastructure so that all requests associated with a created dialog
1007 * can be re-sent with authentication credentials if the original request is challenged.
1009 * \param dlg The dialog on which requests will be authenticated
1010 * \param endpoint The endpoint whom this dialog pertains to
1011 * \param cb Callback to call to send requests with authentication
1012 * \param user_data Data to be provided to the callback when it is called
1015 * \retval -1 Failure
1017 int ast_sip_dialog_setup_outbound_authentication(pjsip_dialog *dlg, const struct ast_sip_endpoint *endpoint,
1018 ast_sip_dialog_outbound_auth_cb cb, void *user_data);
1021 * \brief Initialize the distributor module
1023 * The distributor module is responsible for taking an incoming
1024 * SIP message and placing it into the threadpool. Once in the threadpool,
1025 * the distributor will perform endpoint lookups and authentication, and
1026 * then distribute the message up the stack to any further modules.
1028 * \retval -1 Failure
1031 int ast_sip_initialize_distributor(void);
1034 * \brief Destruct the distributor module.
1036 * Unregisters pjsip modules and cleans up any allocated resources.
1038 void ast_sip_destroy_distributor(void);
1041 * \brief Retrieves a reference to the artificial auth.
1043 * \retval The artificial auth
1045 struct ast_sip_auth *ast_sip_get_artificial_auth(void);
1048 * \brief Retrieves a reference to the artificial endpoint.
1050 * \retval The artificial endpoint
1052 struct ast_sip_endpoint *ast_sip_get_artificial_endpoint(void);
1055 * \page Threading model for SIP
1057 * There are three major types of threads that SIP will have to deal with:
1058 * \li Asterisk threads
1060 * \li SIP threadpool threads (a.k.a. "servants")
1062 * \par Asterisk Threads
1064 * Asterisk threads are those that originate from outside of SIP but within
1065 * Asterisk. The most common of these threads are PBX (channel) threads and
1066 * the autoservice thread. Most interaction with these threads will be through
1067 * channel technology callbacks. Within these threads, it is fine to handle
1068 * Asterisk data from outside of SIP, but any handling of SIP data should be
1069 * left to servants, \b especially if you wish to call into PJSIP for anything.
1070 * Asterisk threads are not registered with PJLIB, so attempting to call into
1071 * PJSIP will cause an assertion to be triggered, thus causing the program to
1074 * \par PJSIP Threads
1076 * PJSIP threads are those that originate from handling of PJSIP events, such
1077 * as an incoming SIP request or response, or a transaction timeout. The role
1078 * of these threads is to process information as quickly as possible so that
1079 * the next item on the SIP socket(s) can be serviced. On incoming messages,
1080 * Asterisk automatically will push the request to a servant thread. When your
1081 * module callback is called, processing will already be in a servant. However,
1082 * for other PSJIP events, such as transaction state changes due to timer
1083 * expirations, your module will be called into from a PJSIP thread. If you
1084 * are called into from a PJSIP thread, then you should push whatever processing
1085 * is needed to a servant as soon as possible. You can discern if you are currently
1086 * in a SIP servant thread using the \ref ast_sip_thread_is_servant function.
1090 * Servants are where the bulk of SIP work should be performed. These threads
1091 * exist in order to do the work that Asterisk threads and PJSIP threads hand
1092 * off to them. Servant threads register themselves with PJLIB, meaning that
1093 * they are capable of calling PJSIP and PJLIB functions if they wish.
1097 * Tasks are handed off to servant threads using the API call \ref ast_sip_push_task.
1098 * The first parameter of this call is a serializer. If this pointer
1099 * is NULL, then the work will be handed off to whatever servant can currently handle
1100 * the task. If this pointer is non-NULL, then the task will not be executed until
1101 * previous tasks pushed with the same serializer have completed. For more information
1102 * on serializers and the benefits they provide, see \ref ast_threadpool_serializer
1106 * Do not make assumptions about individual threads based on a corresponding serializer.
1107 * In other words, just because several tasks use the same serializer when being pushed
1108 * to servants, it does not mean that the same thread is necessarily going to execute those
1109 * tasks, even though they are all guaranteed to be executed in sequence.
1113 * \brief Create a new serializer for SIP tasks
1115 * See \ref ast_threadpool_serializer for more information on serializers.
1116 * SIP creates serializers so that tasks operating on similar data will run
1119 * \retval NULL Failure
1120 * \retval non-NULL Newly-created serializer
1122 struct ast_taskprocessor *ast_sip_create_serializer(void);
1125 * \brief Set a serializer on a SIP dialog so requests and responses are automatically serialized
1127 * Passing a NULL serializer is a way to remove a serializer from a dialog.
1129 * \param dlg The SIP dialog itself
1130 * \param serializer The serializer to use
1132 void ast_sip_dialog_set_serializer(pjsip_dialog *dlg, struct ast_taskprocessor *serializer);
1135 * \brief Set an endpoint on a SIP dialog so in-dialog requests do not undergo endpoint lookup.
1137 * \param dlg The SIP dialog itself
1138 * \param endpoint The endpoint that this dialog is communicating with
1140 void ast_sip_dialog_set_endpoint(pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint);
1143 * \brief Get the endpoint associated with this dialog
1145 * This function increases the refcount of the endpoint by one. Release
1146 * the reference once you are finished with the endpoint.
1148 * \param dlg The SIP dialog from which to retrieve the endpoint
1149 * \retval NULL No endpoint associated with this dialog
1150 * \retval non-NULL The endpoint.
1152 struct ast_sip_endpoint *ast_sip_dialog_get_endpoint(pjsip_dialog *dlg);
1155 * \brief Pushes a task to SIP servants
1157 * This uses the serializer provided to determine how to push the task.
1158 * If the serializer is NULL, then the task will be pushed to the
1159 * servants directly. If the serializer is non-NULL, then the task will be
1160 * queued behind other tasks associated with the same serializer.
1162 * \param serializer The serializer to which the task belongs. Can be NULL
1163 * \param sip_task The task to execute
1164 * \param task_data The parameter to pass to the task when it executes
1166 * \retval -1 Failure
1168 int ast_sip_push_task(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);
1171 * \brief Push a task to SIP servants and wait for it to complete
1173 * Like \ref ast_sip_push_task except that it blocks until the task completes.
1175 * \warning \b Never use this function in a SIP servant thread. This can potentially
1176 * cause a deadlock. If you are in a SIP servant thread, just call your function
1179 * \param serializer The SIP serializer to which the task belongs. May be NULL.
1180 * \param sip_task The task to execute
1181 * \param task_data The parameter to pass to the task when it executes
1183 * \retval -1 Failure
1185 int ast_sip_push_task_synchronous(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);
1188 * \brief Determine if the current thread is a SIP servant thread
1190 * \retval 0 This is not a SIP servant thread
1191 * \retval 1 This is a SIP servant thread
1193 int ast_sip_thread_is_servant(void);
1196 * \brief SIP body description
1198 * This contains a type and subtype that will be added as
1199 * the "Content-Type" for the message as well as the body
1202 struct ast_sip_body {
1203 /*! Type of the body, such as "application" */
1205 /*! Subtype of the body, such as "sdp" */
1206 const char *subtype;
1207 /*! The text to go in the body */
1208 const char *body_text;
1212 * \brief General purpose method for creating a UAC dialog with an endpoint
1214 * \param endpoint A pointer to the endpoint
1215 * \param aor_name Optional name of the AOR to target, may even be an explicit SIP URI
1216 * \param request_user Optional user to place into the target URI
1218 * \retval non-NULL success
1219 * \retval NULL failure
1221 pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, const char *aor_name, const char *request_user);
1224 * \brief General purpose method for creating a UAS dialog with an endpoint
1226 * \param endpoint A pointer to the endpoint
1227 * \param rdata The request that is starting the dialog
1229 pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
1232 * \brief General purpose method for creating an rdata structure using specific information
1234 * \param rdata[out] The rdata structure that will be populated
1235 * \param packet A SIP message
1236 * \param src_name The source IP address of the message
1237 * \param src_port The source port of the message
1238 * \param transport_type The type of transport the message was received on
1239 * \param local_name The local IP address the message was received on
1240 * \param local_port The local port the message was received on
1243 * \retval -1 failure
1245 int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port, char *transport_type,
1246 const char *local_name, int local_port);
1249 * \brief General purpose method for creating a SIP request
1251 * Its typical use would be to create one-off requests such as an out of dialog
1254 * The request can either be in- or out-of-dialog. If in-dialog, the
1255 * dlg parameter MUST be present. If out-of-dialog the endpoint parameter
1256 * MUST be present. If both are present, then we will assume that the message
1257 * is to be sent in-dialog.
1259 * The uri parameter can be specified if the request should be sent to an explicit
1260 * URI rather than one configured on the endpoint.
1262 * \param method The method of the SIP request to send
1263 * \param dlg Optional. If specified, the dialog on which to request the message.
1264 * \param endpoint Optional. If specified, the request will be created out-of-dialog to the endpoint.
1265 * \param uri Optional. If specified, the request will be sent to this URI rather
1266 * than one configured for the endpoint.
1267 * \param contact The contact with which this request is associated for out-of-dialog requests.
1268 * \param[out] tdata The newly-created request
1270 * The provided contact is attached to tdata with its reference bumped, but will
1271 * not survive for the entire lifetime of tdata since the contact is cleaned up
1272 * when all supplements have completed execution.
1275 * \retval -1 Failure
1277 int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg,
1278 struct ast_sip_endpoint *endpoint, const char *uri,
1279 struct ast_sip_contact *contact, pjsip_tx_data **tdata);
1282 * \brief General purpose method for sending a SIP request
1284 * This is a companion function for \ref ast_sip_create_request. The request
1285 * created there can be passed to this function, though any request may be
1288 * This will automatically set up handling outbound authentication challenges if
1291 * \param tdata The request to send
1292 * \param dlg Optional. The dialog in which the request is sent. Otherwise it is out-of-dialog.
1293 * \param endpoint Optional. If specified, the out-of-dialog request is sent to the endpoint.
1294 * \param token Data to be passed to the callback upon receipt of out-of-dialog response.
1295 * \param callback Callback to be called upon receipt of out-of-dialog response.
1298 * \retval -1 Failure (out-of-dialog callback will not be called.)
1300 int ast_sip_send_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg,
1301 struct ast_sip_endpoint *endpoint, void *token,
1302 void (*callback)(void *token, pjsip_event *e));
1305 * \brief General purpose method for creating a SIP response
1307 * Its typical use would be to create responses for out of dialog
1310 * \param rdata The rdata from the incoming request.
1311 * \param st_code The response code to transmit.
1312 * \param contact The contact with which this request is associated.
1313 * \param[out] tdata The newly-created response
1315 * The provided contact is attached to tdata with its reference bumped, but will
1316 * not survive for the entire lifetime of tdata since the contact is cleaned up
1317 * when all supplements have completed execution.
1320 * \retval -1 Failure
1322 int ast_sip_create_response(const pjsip_rx_data *rdata, int st_code,
1323 struct ast_sip_contact *contact, pjsip_tx_data **p_tdata);
1326 * \brief Send a response to an out of dialog request
1328 * \param res_addr The response address for this response
1329 * \param tdata The response to send
1330 * \param endpoint The ast_sip_endpoint associated with this response
1333 * \retval -1 Failure
1335 int ast_sip_send_response(pjsip_response_addr *res_addr, pjsip_tx_data *tdata, struct ast_sip_endpoint *sip_endpoint);
1338 * \brief Determine if an incoming request requires authentication
1340 * This calls into the registered authenticator's requires_authentication callback
1341 * in order to determine if the request requires authentication.
1343 * If there is no registered authenticator, then authentication will be assumed
1344 * not to be required.
1346 * \param endpoint The endpoint from which the request originates
1347 * \param rdata The incoming SIP request
1348 * \retval non-zero The request requires authentication
1349 * \retval 0 The request does not require authentication
1351 int ast_sip_requires_authentication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
1354 * \brief Method to determine authentication status of an incoming request
1356 * This will call into a registered authenticator. The registered authenticator will
1357 * do what is necessary to determine whether the incoming request passes authentication.
1358 * A tentative response is passed into this function so that if, say, a digest authentication
1359 * challenge should be sent in the ensuing response, it can be added to the response.
1361 * \param endpoint The endpoint from the request was sent
1362 * \param rdata The request to potentially authenticate
1363 * \param tdata Tentative response to the request
1364 * \return The result of checking authentication.
1366 enum ast_sip_check_auth_result ast_sip_check_authentication(struct ast_sip_endpoint *endpoint,
1367 pjsip_rx_data *rdata, pjsip_tx_data *tdata);
1370 * \brief Create a response to an authentication challenge
1372 * This will call into an outbound authenticator's create_request_with_auth callback
1373 * to create a new request with authentication credentials. See the create_request_with_auth
1374 * callback in the \ref ast_sip_outbound_authenticator structure for details about
1375 * the parameters and return values.
1377 int ast_sip_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
1378 pjsip_transaction *tsx, pjsip_tx_data **new_request);
1381 * \brief Determine the endpoint that has sent a SIP message
1383 * This will call into each of the registered endpoint identifiers'
1384 * identify_endpoint() callbacks until one returns a non-NULL endpoint.
1385 * This will return an ao2 object. Its reference count will need to be
1386 * decremented when completed using the endpoint.
1388 * \param rdata The inbound SIP message to use when identifying the endpoint.
1389 * \retval NULL No matching endpoint
1390 * \retval non-NULL The matching endpoint
1392 struct ast_sip_endpoint *ast_sip_identify_endpoint(pjsip_rx_data *rdata);
1395 * \brief Set the outbound proxy for an outbound SIP message
1397 * \param tdata The message to set the outbound proxy on
1398 * \param proxy SIP uri of the proxy
1400 * \retval -1 Failure
1402 int ast_sip_set_outbound_proxy(pjsip_tx_data *tdata, const char *proxy);
1405 * \brief Add a header to an outbound SIP message
1407 * \param tdata The message to add the header to
1408 * \param name The header name
1409 * \param value The header value
1411 * \retval -1 Failure
1413 int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value);
1416 * \brief Add a body to an outbound SIP message
1418 * If this is called multiple times, the latest body will replace the current
1421 * \param tdata The message to add the body to
1422 * \param body The message body to add
1424 * \retval -1 Failure
1426 int ast_sip_add_body(pjsip_tx_data *tdata, const struct ast_sip_body *body);
1429 * \brief Add a multipart body to an outbound SIP message
1431 * This will treat each part of the input vector as part of a multipart body and
1432 * add each part to the SIP message.
1434 * \param tdata The message to add the body to
1435 * \param bodies The parts of the body to add
1437 * \retval -1 Failure
1439 int ast_sip_add_body_multipart(pjsip_tx_data *tdata, const struct ast_sip_body *bodies[], int num_bodies);
1442 * \brief Append body data to a SIP message
1444 * This acts mostly the same as ast_sip_add_body, except that rather than replacing
1445 * a body if it currently exists, it appends data to an existing body.
1447 * \param tdata The message to append the body to
1448 * \param body The string to append to the end of the current body
1450 * \retval -1 Failure
1452 int ast_sip_append_body(pjsip_tx_data *tdata, const char *body_text);
1455 * \brief Copy a pj_str_t into a standard character buffer.
1457 * pj_str_t is not NULL-terminated. Any place that expects a NULL-
1458 * terminated string needs to have the pj_str_t copied into a separate
1461 * This method copies the pj_str_t contents into the destination buffer
1462 * and NULL-terminates the buffer.
1464 * \param dest The destination buffer
1465 * \param src The pj_str_t to copy
1466 * \param size The size of the destination buffer.
1468 void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size);
1471 * \brief Get the looked-up endpoint on an out-of dialog request or response
1473 * The function may ONLY be called on out-of-dialog requests or responses. For
1474 * in-dialog requests and responses, it is required that the user of the dialog
1475 * has the looked-up endpoint stored locally.
1477 * This function should never return NULL if the message is out-of-dialog. It will
1478 * always return NULL if the message is in-dialog.
1480 * This function will increase the reference count of the returned endpoint by one.
1481 * Release your reference using the ao2_ref function when finished.
1483 * \param rdata Out-of-dialog request or response
1484 * \return The looked up endpoint
1486 struct ast_sip_endpoint *ast_pjsip_rdata_get_endpoint(pjsip_rx_data *rdata);
1489 * \brief Add 'user=phone' parameter to URI if enabled and user is a phone number.
1491 * \param endpoint The endpoint to use for configuration
1492 * \param pool The memory pool to allocate the parameter from
1493 * \param uri The URI to check for user and to add parameter to
1495 void ast_sip_add_usereqphone(const struct ast_sip_endpoint *endpoint, pj_pool_t *pool, pjsip_uri *uri);
1498 * \brief Retrieve any endpoints available to sorcery.
1500 * \retval Endpoints available to sorcery, NULL if no endpoints found.
1502 struct ao2_container *ast_sip_get_endpoints(void);
1505 * \brief Retrieve the default outbound endpoint.
1507 * \retval The default outbound endpoint, NULL if not found.
1509 struct ast_sip_endpoint *ast_sip_default_outbound_endpoint(void);
1512 * \brief Retrieve relevant SIP auth structures from sorcery
1514 * \param auths Vector of sorcery IDs of auth credentials to retrieve
1515 * \param[out] out The retrieved auths are stored here
1517 int ast_sip_retrieve_auths(const struct ast_sip_auth_vector *auths, struct ast_sip_auth **out);
1520 * \brief Clean up retrieved auth structures from memory
1522 * Call this function once you have completed operating on auths
1523 * retrieved from \ref ast_sip_retrieve_auths
1525 * \param auths An vector of auth structures to clean up
1526 * \param num_auths The number of auths in the vector
1528 void ast_sip_cleanup_auths(struct ast_sip_auth *auths[], size_t num_auths);
1531 * \brief Checks if the given content type matches type/subtype.
1533 * Compares the pjsip_media_type with the passed type and subtype and
1534 * returns the result of that comparison. The media type parameters are
1537 * \param content_type The pjsip_media_type structure to compare
1538 * \param type The media type to compare
1539 * \param subtype The media subtype to compare
1540 * \retval 0 No match
1543 int ast_sip_is_content_type(pjsip_media_type *content_type, char *type, char *subtype);
1546 * \brief Send a security event notification for when an invalid endpoint is requested
1548 * \param name Name of the endpoint requested
1549 * \param rdata Received message
1551 void ast_sip_report_invalid_endpoint(const char *name, pjsip_rx_data *rdata);
1554 * \brief Send a security event notification for when an ACL check fails
1556 * \param endpoint Pointer to the endpoint in use
1557 * \param rdata Received message
1558 * \param name Name of the ACL
1560 void ast_sip_report_failed_acl(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, const char *name);
1563 * \brief Send a security event notification for when a challenge response has failed
1565 * \param endpoint Pointer to the endpoint in use
1566 * \param rdata Received message
1568 void ast_sip_report_auth_failed_challenge_response(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
1571 * \brief Send a security event notification for when authentication succeeds
1573 * \param endpoint Pointer to the endpoint in use
1574 * \param rdata Received message
1576 void ast_sip_report_auth_success(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
1579 * \brief Send a security event notification for when an authentication challenge is sent
1581 * \param endpoint Pointer to the endpoint in use
1582 * \param rdata Received message
1583 * \param tdata Sent message
1585 void ast_sip_report_auth_challenge_sent(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pjsip_tx_data *tdata);
1588 * \brief Send a security event notification for when a request is not supported
1590 * \param endpoint Pointer to the endpoint in use
1591 * \param rdata Received message
1592 * \param req_type the type of request
1594 void ast_sip_report_req_no_support(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata,
1595 const char* req_type);
1598 * \brief Send a security event notification for when a memory limit is hit.
1600 * \param endpoint Pointer to the endpoint in use
1601 * \param rdata Received message
1603 void ast_sip_report_mem_limit(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
1605 void ast_sip_initialize_global_headers(void);
1606 void ast_sip_destroy_global_headers(void);
1608 int ast_sip_add_global_request_header(const char *name, const char *value, int replace);
1609 int ast_sip_add_global_response_header(const char *name, const char *value, int replace);
1611 int ast_sip_initialize_sorcery_global(void);
1614 * \brief Retrieves the value associated with the given key.
1616 * \param ht the hash table/dictionary to search
1617 * \param key the key to find
1619 * \retval the value associated with the key, NULL otherwise.
1621 void *ast_sip_dict_get(void *ht, const char *key);
1624 * \brief Using the dictionary stored in mod_data array at a given id,
1625 * retrieve the value associated with the given key.
1627 * \param mod_data a module data array
1628 * \param id the mod_data array index
1629 * \param key the key to find
1631 * \retval the value associated with the key, NULL otherwise.
1633 #define ast_sip_mod_data_get(mod_data, id, key) \
1634 ast_sip_dict_get(mod_data[id], key)
1637 * \brief Set the value for the given key.
1639 * Note - if the hash table does not exist one is created first, the key/value
1640 * pair is set, and the hash table returned.
1642 * \param pool the pool to allocate memory in
1643 * \param ht the hash table/dictionary in which to store the key/value pair
1644 * \param key the key to associate a value with
1645 * \param val the value to associate with a key
1647 * \retval the given, or newly created, hash table.
1649 void *ast_sip_dict_set(pj_pool_t* pool, void *ht,
1650 const char *key, void *val);
1653 * \brief Utilizing a mod_data array for a given id, set the value
1654 * associated with the given key.
1656 * For a given structure's mod_data array set the element indexed by id to
1657 * be a dictionary containing the key/val pair.
1659 * \param pool a memory allocation pool
1660 * \param mod_data a module data array
1661 * \param id the mod_data array index
1662 * \param key the key to find
1663 * \param val the value to associate with a key
1665 #define ast_sip_mod_data_set(pool, mod_data, id, key, val) \
1666 mod_data[id] = ast_sip_dict_set(pool, mod_data[id], key, val)
1669 * \brief For every contact on an AOR call the given 'on_contact' handler.
1671 * \param aor the aor containing a list of contacts to iterate
1672 * \param on_contact callback on each contact on an AOR. The object
1673 * received by the callback will be a ast_sip_contact_wrapper structure.
1674 * \param arg user data passed to handler
1675 * \retval 0 Success, non-zero on failure
1677 int ast_sip_for_each_contact(const struct ast_sip_aor *aor,
1678 ao2_callback_fn on_contact, void *arg);
1681 * \brief Handler used to convert a contact to a string.
1683 * \param object the ast_sip_aor_contact_pair containing a list of contacts to iterate and the contact
1684 * \param arg user data passed to handler
1686 * \retval 0 Success, non-zero on failure
1688 int ast_sip_contact_to_str(void *object, void *arg, int flags);
1691 * \brief For every aor in the comma separated aors string call the
1692 * given 'on_aor' handler.
1694 * \param aors a comma separated list of aors
1695 * \param on_aor callback for each aor
1696 * \param arg user data passed to handler
1697 * \retval 0 Success, non-zero on failure
1699 int ast_sip_for_each_aor(const char *aors, ao2_callback_fn on_aor, void *arg);
1702 * \brief For every auth in the array call the given 'on_auth' handler.
1704 * \param array an array of auths
1705 * \param on_auth callback for each auth
1706 * \param arg user data passed to handler
1707 * \retval 0 Success, non-zero on failure
1709 int ast_sip_for_each_auth(const struct ast_sip_auth_vector *array,
1710 ao2_callback_fn on_auth, void *arg);
1713 * \brief Converts the given auth type to a string
1715 * \param type the auth type to convert
1716 * \retval a string representative of the auth type
1718 const char *ast_sip_auth_type_to_str(enum ast_sip_auth_type type);
1721 * \brief Converts an auths array to a string of comma separated values
1723 * \param auths an auth array
1724 * \param buf the string buffer to write the object data
1725 * \retval 0 Success, non-zero on failure
1727 int ast_sip_auths_to_str(const struct ast_sip_auth_vector *auths, char **buf);
1730 * \brief AMI variable container
1732 struct ast_sip_ami {
1733 /*! Manager session */
1734 struct mansession *s;
1735 /*! Manager message */
1736 const struct message *m;
1737 /*! Manager Action ID */
1738 const char *action_id;
1739 /*! user specified argument data */
1741 /*! count of objects */
1746 * \brief Creates a string to store AMI event data in.
1748 * \param event the event to set
1749 * \param ami AMI session and message container
1750 * \retval an initialized ast_str or NULL on error.
1752 struct ast_str *ast_sip_create_ami_event(const char *event,
1753 struct ast_sip_ami *ami);
1756 * \brief An entity responsible formatting endpoint information.
1758 struct ast_sip_endpoint_formatter {
1760 * \brief Callback used to format endpoint information over AMI.
1762 int (*format_ami)(const struct ast_sip_endpoint *endpoint,
1763 struct ast_sip_ami *ami);
1764 AST_RWLIST_ENTRY(ast_sip_endpoint_formatter) next;
1768 * \brief Register an endpoint formatter.
1770 * \param obj the formatter to register
1772 * \retval -1 Failure
1774 int ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj);
1777 * \brief Unregister an endpoint formatter.
1779 * \param obj the formatter to unregister
1781 void ast_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj);
1784 * \brief Converts a sorcery object to a string of object properties.
1786 * \param obj the sorcery object to convert
1787 * \param str the string buffer to write the object data
1788 * \retval 0 Success, non-zero on failure
1790 int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf);
1793 * \brief Formats the endpoint and sends over AMI.
1795 * \param endpoint the endpoint to format and send
1796 * \param endpoint ami AMI variable container
1797 * \param count the number of formatters operated on
1798 * \retval 0 Success, otherwise non-zero on error
1800 int ast_sip_format_endpoint_ami(struct ast_sip_endpoint *endpoint,
1801 struct ast_sip_ami *ami, int *count);
1804 * \brief Format auth details for AMI.
1806 * \param auths an auth array
1807 * \param ami ami variable container
1808 * \retval 0 Success, non-zero on failure
1810 int ast_sip_format_auths_ami(const struct ast_sip_auth_vector *auths,
1811 struct ast_sip_ami *ami);
1814 * \brief Retrieve the endpoint snapshot for an endpoint
1816 * \param endpoint The endpoint whose snapshot is to be retreieved.
1817 * \retval The endpoint snapshot
1819 struct ast_endpoint_snapshot *ast_sip_get_endpoint_snapshot(
1820 const struct ast_sip_endpoint *endpoint);
1823 * \brief Retrieve the device state for an endpoint.
1825 * \param endpoint The endpoint whose state is to be retrieved.
1826 * \retval The device state.
1828 const char *ast_sip_get_device_state(const struct ast_sip_endpoint *endpoint);
1831 * \brief For every channel snapshot on an endpoint snapshot call the given
1832 * 'on_channel_snapshot' handler.
1834 * \param endpoint_snapshot snapshot of an endpoint
1835 * \param on_channel_snapshot callback for each channel snapshot
1836 * \param arg user data passed to handler
1837 * \retval 0 Success, non-zero on failure
1839 int ast_sip_for_each_channel_snapshot(const struct ast_endpoint_snapshot *endpoint_snapshot,
1840 ao2_callback_fn on_channel_snapshot,
1844 * \brief For every channel snapshot on an endpoint all the given
1845 * 'on_channel_snapshot' handler.
1847 * \param endpoint endpoint
1848 * \param on_channel_snapshot callback for each channel snapshot
1849 * \param arg user data passed to handler
1850 * \retval 0 Success, non-zero on failure
1852 int ast_sip_for_each_channel(const struct ast_sip_endpoint *endpoint,
1853 ao2_callback_fn on_channel_snapshot,
1856 enum ast_sip_supplement_priority {
1857 /*! Top priority. Supplements with this priority are those that need to run before any others */
1858 AST_SIP_SUPPLEMENT_PRIORITY_FIRST = 0,
1859 /*! Channel creation priority.
1860 * chan_pjsip creates a channel at this priority. If your supplement depends on being run before
1861 * or after channel creation, then set your priority to be lower or higher than this value.
1863 AST_SIP_SUPPLEMENT_PRIORITY_CHANNEL = 1000000,
1864 /*! Lowest priority. Supplements with this priority should be run after all other supplements */
1865 AST_SIP_SUPPLEMENT_PRIORITY_LAST = INT_MAX,
1869 * \brief A supplement to SIP message processing
1871 * These can be registered by any module in order to add
1872 * processing to incoming and outgoing SIP out of dialog
1873 * requests and responses
1875 struct ast_sip_supplement {
1876 /*! Method on which to call the callbacks. If NULL, call on all methods */
1878 /*! Priority for this supplement. Lower numbers are visited before higher numbers */
1879 enum ast_sip_supplement_priority priority;
1881 * \brief Called on incoming SIP request
1882 * This method can indicate a failure in processing in its return. If there
1883 * is a failure, it is required that this method sends a response to the request.
1884 * This method is always called from a SIP servant thread.
1887 * The following PJSIP methods will not work properly:
1888 * pjsip_rdata_get_dlg()
1889 * pjsip_rdata_get_tsx()
1890 * The reason is that the rdata passed into this function is a cloned rdata structure,
1891 * and its module data is not copied during the cloning operation.
1892 * If you need to get the dialog, you can get it via session->inv_session->dlg.
1895 * There is no guarantee that a channel will be present on the session when this is called.
1897 int (*incoming_request)(struct ast_sip_endpoint *endpoint, struct pjsip_rx_data *rdata);
1899 * \brief Called on an incoming SIP response
1900 * This method is always called from a SIP servant thread.
1903 * The following PJSIP methods will not work properly:
1904 * pjsip_rdata_get_dlg()
1905 * pjsip_rdata_get_tsx()
1906 * The reason is that the rdata passed into this function is a cloned rdata structure,
1907 * and its module data is not copied during the cloning operation.
1908 * If you need to get the dialog, you can get it via session->inv_session->dlg.
1911 * There is no guarantee that a channel will be present on the session when this is called.
1913 void (*incoming_response)(struct ast_sip_endpoint *endpoint, struct pjsip_rx_data *rdata);
1915 * \brief Called on an outgoing SIP request
1916 * This method is always called from a SIP servant thread.
1918 void (*outgoing_request)(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, struct pjsip_tx_data *tdata);
1920 * \brief Called on an outgoing SIP response
1921 * This method is always called from a SIP servant thread.
1923 void (*outgoing_response)(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, struct pjsip_tx_data *tdata);
1924 /*! Next item in the list */
1925 AST_LIST_ENTRY(ast_sip_supplement) next;
1929 * \brief Register a supplement to SIP out of dialog processing
1931 * This allows for someone to insert themselves in the processing of out
1932 * of dialog SIP requests and responses. This, for example could allow for
1933 * a module to set channel data based on headers in an incoming message.
1934 * Similarly, a module could reject an incoming request if desired.
1936 * \param supplement The supplement to register
1938 * \retval -1 Failure
1940 int ast_sip_register_supplement(struct ast_sip_supplement *supplement);
1943 * \brief Unregister a an supplement to SIP out of dialog processing
1945 * \param supplement The supplement to unregister
1947 void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement);
1950 * \brief Retrieve the system debug setting (yes|no|host).
1952 * \note returned string needs to be de-allocated by caller.
1954 * \retval the system debug setting.
1956 char *ast_sip_get_debug(void);
1958 /*! \brief Determines whether the res_pjsip module is loaded */
1959 #define CHECK_PJSIP_MODULE_LOADED() \
1961 if (!ast_module_check("res_pjsip.so") \
1962 || !ast_sip_get_pjsip_endpoint()) { \
1963 return AST_MODULE_LOAD_DECLINE; \
1968 * \brief Retrieve the system keep alive interval setting.
1970 * \retval the keep alive interval.
1972 unsigned int ast_sip_get_keep_alive_interval(void);
1974 #endif /* _RES_PJSIP_H */