Asterisk - The Open Source Telephony Project GIT-master-3dee037
res_pjsip.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2013, Digium, Inc.
5 *
6 * Mark Michelson <mmichelson@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19#ifndef _RES_PJSIP_H
20#define _RES_PJSIP_H
21
22#include <pjsip.h>
23/* Needed for SUBSCRIBE, NOTIFY, and PUBLISH method definitions */
24#include <pjsip_simple.h>
25#include <pjsip/sip_transaction.h>
26#include <pj/timer.h>
27/* Needed for pj_sockaddr */
28#include <pjlib.h>
29
31/* Needed for struct ast_sockaddr */
32#include "asterisk/netsock2.h"
33/* Needed for linked list macros */
35/* Needed for ast_party_id */
36#include "asterisk/channel.h"
37/* Needed for ast_sorcery */
38#include "asterisk/sorcery.h"
39/* Needed for ast_dnsmgr */
40#include "asterisk/dnsmgr.h"
41/* Needed for ast_endpoint */
42#include "asterisk/endpoints.h"
43/* Needed for ast_t38_ec_modes */
44#include "asterisk/udptl.h"
45/* Needed for ast_rtp_dtls_cfg struct */
46#include "asterisk/rtp_engine.h"
47/* Needed for AST_VECTOR macro */
48#include "asterisk/vector.h"
49/* Needed for ast_sip_for_each_channel_snapshot struct */
52#include "asterisk/stream.h"
53
54#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
55/* Needed for knowing if the cert or priv key files changed */
56#include <sys/stat.h>
57#endif
58
59#define PJSIP_MINVERSION(m,n,p) (((m << 24) | (n << 16) | (p << 8)) >= PJ_VERSION_NUM)
60
61#ifndef PJSIP_EXPIRES_NOT_SPECIFIED
62/*
63 * Added in pjproject 2.10.0. However define here if someone compiles against a
64 * version of pjproject < 2.10.0.
65 *
66 * Usually defined in pjsip/include/pjsip/sip_msg.h (included as part of <pjsip.h>)
67 */
68#define PJSIP_EXPIRES_NOT_SPECIFIED ((pj_uint32_t)-1)
69#endif
70
71#define PJSTR_PRINTF_SPEC "%.*s"
72#define PJSTR_PRINTF_VAR(_v) ((int)(_v).slen), ((_v).ptr)
73
74#define AST_SIP_AUTH_MAX_REALM_LENGTH 255 /* From the auth/realm realtime column size */
75
76/* ":12345" */
77#define COLON_PORT_STRLEN 6
78/*
79 * "<ipaddr>:<port>"
80 * PJ_INET6_ADDRSTRLEN includes the NULL terminator
81 */
82#define IP6ADDR_COLON_PORT_BUFLEN (PJ_INET6_ADDRSTRLEN + COLON_PORT_STRLEN)
83
84/*!
85 * \brief Fill a buffer with a pjsip transport's remote ip address and port
86 *
87 * \param _transport The pjsip_transport to use
88 * \param _dest The destination buffer of at least IP6ADDR_COLON_PORT_BUFLEN bytes
89 */
90#define AST_SIP_MAKE_REMOTE_IPADDR_PORT_STR(_transport, _dest) \
91 pj_sockaddr_print(&_transport->key.rem_addr, _dest, sizeof(_dest), 1);
92
93/* Forward declarations of PJSIP stuff */
94struct pjsip_rx_data;
95struct pjsip_module;
96struct pjsip_tx_data;
97struct pjsip_dialog;
98struct pjsip_transport;
99struct pjsip_tpfactory;
100struct pjsip_tls_setting;
101struct pjsip_tpselector;
102
103/*! \brief Maximum number of ciphers supported for a TLS transport */
104#define SIP_TLS_MAX_CIPHERS 64
105
106/*! Maximum number of challenges before assuming that we are in a loop */
107#define MAX_RX_CHALLENGES 10
108
110
111static const pj_str_t AST_PJ_STR_EMPTY = { "", 0 };
112
113/*!
114 * \brief Structure for SIP transport information
115 */
117 /*! \brief Transport itself */
118 struct pjsip_transport *transport;
119 /*! \brief Transport factory */
120 struct pjsip_tpfactory *factory;
121 /*!
122 * Transport id
123 * \since 13.8.0
124 */
125 char *id;
126 /*!
127 * Transport type
128 * \since 13.8.0
129 */
131 /*!
132 * Address and port to bind to
133 * \since 13.8.0
134 */
135 pj_sockaddr host;
136 /*!
137 * TLS settings
138 * \since 13.8.0
139 */
140 pjsip_tls_setting tls;
141 /*!
142 * Configured TLS ciphers
143 * \since 13.8.0
144 */
146 /*!
147 * Optional local network information, used for NAT purposes.
148 * "deny" (set) means that it's in the local network. Use the
149 * ast_sip_transport_is_nonlocal and ast_sip_transport_is_local
150 * macro's.
151 * \since 13.8.0
152 */
154 /*!
155 * DNS manager for refreshing the external signaling address
156 * \since 13.8.0
157 */
159 /*!
160 * Optional external signaling address information
161 * \since 13.8.0
162 */
164 /*!
165 * DNS manager for refreshing the external media address
166 * \since 13.18.0
167 */
169 /*!
170 * Optional external signaling address information
171 * \since 13.18.0
172 */
174 /*!
175 * Set when this transport is a flow of signaling to a target
176 * \since 17.0.0
177 */
178 int flow;
179 /*!
180 * The P-Preferred-Identity to use on traffic using this transport
181 * \since 17.0.0
182 */
184 /*!
185 * The Service Routes to use on traffic using this transport
186 * \since 17.0.0
187 */
189 /*!
190 * Disregard RFC5922 7.2, and allow wildcard certs (TLS only)
191 */
193 /*!
194 * If true, fail if server certificate cannot verify (TLS only)
195 */
197#ifdef HAVE_PJSIP_TLS_TRANSPORT_RESTART
198 /*!
199 * The stats information for the certificate file, if configured
200 */
201 struct stat cert_file_stat;
202 /*!
203 * The stats information for the private key file, if configured
204 */
205 struct stat privkey_file_stat;
206#endif
207};
208
209#define ast_sip_transport_is_nonlocal(transport_state, addr) \
210 (!transport_state->localnet || ast_apply_ha(transport_state->localnet, addr) == AST_SENSE_ALLOW)
211
212#define ast_sip_transport_is_local(transport_state, addr) \
213 (transport_state->localnet && ast_apply_ha(transport_state->localnet, addr) != AST_SENSE_ALLOW)
214
215/*!
216 * \brief Transport to bind to
217 */
219 /*! Sorcery object details */
222 /*! Certificate of authority list file */
224 /*! Certificate of authority list path */
226 /*! Public certificate file */
228 /*! Optional private key of the certificate file */
230 /*! Password to open the private key */
232 /*! External signaling address */
234 /*! External media address */
236 /*! Optional domain to use for messages if provided could not be found */
238 );
239 /*! Type of transport */
241 /*!
242 * \deprecated Moved to ast_sip_transport_state
243 * \version 13.8.0 deprecated
244 * Address and port to bind to
245 */
246 pj_sockaddr host;
247 /*! Number of simultaneous asynchronous operations */
248 unsigned int async_operations;
249 /*! Optional external port for signaling */
251 /*!
252 * \deprecated Moved to ast_sip_transport_state
253 * \version 13.7.1 deprecated
254 * TLS settings
255 */
256 pjsip_tls_setting tls;
257 /*!
258 * \deprecated Moved to ast_sip_transport_state
259 * \version 13.7.1 deprecated
260 * Configured TLS ciphers
261 */
263 /*!
264 * \deprecated Moved to ast_sip_transport_state
265 * \version 13.7.1 deprecated
266 * Optional local network information, used for NAT purposes
267 */
269 /*!
270 * \deprecated Moved to ast_sip_transport_state
271 * \version 13.7.1 deprecated
272 * DNS manager for refreshing the external address
273 */
275 /*!
276 * \deprecated Moved to ast_sip_transport_state
277 * \version 13.7.1 deprecated
278 * Optional external address information
279 */
281 /*!
282 * \deprecated
283 * \version 13.7.1 deprecated
284 * Transport state information
285 */
287 /*! QOS DSCP TOS bits */
288 unsigned int tos;
289 /*! QOS COS value */
290 unsigned int cos;
291 /*! Write timeout */
293 /*! Allow reload */
295 /*! Automatically send requests out the same transport requests have come in on */
297 /*! This is a flow to another target */
298 int flow;
299 /*! Enable TCP keepalive */
301 /*! Time in seconds the connection needs to remain idle before TCP starts sending keepalive probes */
303 /*! The time in seconds between individual keepalive probes */
305 /*! The maximum number of keepalive probes TCP should send before dropping the connection */
307};
308
309#define SIP_SORCERY_DOMAIN_ALIAS_TYPE "domain_alias"
310
311/*!
312 * Details about a SIP domain alias
313 */
315 /*! Sorcery object details */
318 /*! Domain to be aliased to */
320 );
321};
322
323/*!
324 * \brief Structure for SIP nat hook information
325 */
327 /*! Sorcery object details */
329 /*! Callback for when a message is going outside of our local network */
330 void (*outgoing_external_message)(struct pjsip_tx_data *tdata, struct ast_sip_transport *transport);
331};
332
333/*! \brief Structure which contains information about a transport */
335 /*! \brief Type of transport */
337 /*! \brief Potential pointer to the transport itself, if UDP */
338 pjsip_transport *transport;
339 /*! \brief Potential pointer to the transport factory itself, if TCP/TLS */
340 pjsip_tpfactory *factory;
341 /*! \brief Local address for transport */
343 /*! \brief Local port for transport */
345};
346
347/*!
348 * \brief The kind of security negotiation
349 */
351 /*! No security mechanism negotiation */
353 /*! Use mediasec security mechanism negotiation */
355 /* Add RFC 3329 (sec-agree) mechanism negotiation in the future */
356};
357
358/*!
359 * \brief The security mechanism type
360 */
363 /* Use msrp-tls as security mechanism */
365 /* Use sdes-srtp as security mechanism */
367 /* Use dtls-srtp as security mechanism */
369 /* Add RFC 3329 (sec-agree) mechanisms like tle, digest, ipsec-ike in the future */
370};
371
372/*!
373 * \brief Structure representing a security mechanism as defined in RFC 3329
374 */
376 /* Used to determine which security mechanism to use. */
378 /* The preference of this security mechanism. The higher the value, the more preferred. */
379 float qvalue;
380 /* Optional mechanism parameters. */
382};
383
385
386/*!
387 * \brief Contact associated with an address of record
388 */
390 /*! Sorcery object details, the id is the aor name plus a random string */
393 /*! Full URI of the contact */
395 /*! Outbound proxy to use for qualify */
397 /*! Path information to place in Route headers */
399 /*! Content of the User-Agent header in REGISTER request */
401 /*! The name of the aor this contact belongs to */
403 /*! Asterisk Server name */
405 /*! IP-address of the Via header in REGISTER request */
407 /*! Content of the Call-ID header in REGISTER request */
409 /*! The name of the endpoint that added the contact */
411 );
412 /*! Absolute time that this contact is no longer valid after */
413 struct timeval expiration_time;
414 /*! Frequency to send OPTIONS requests to contact. 0 is disabled. */
415 unsigned int qualify_frequency;
416 /*! If true authenticate the qualify challenge response if needed */
418 /*! Qualify timeout. 0 is diabled. */
420 /*! Endpoint that added the contact, only available in observers */
422 /*! Port of the Via header in REGISTER request */
424 /*! If true delete the contact on Asterisk restart/boot */
426 /*! If true only authenticate if OPTIONS response is 2XX */
428};
429
430/*!
431 * \brief Status type for a contact.
432 */
434 /*! Frequency > 0, but no response from remote uri */
436 /*! Frequency > 0, and got response from remote uri */
438 /*! Default last status, and when a contact status object is not found */
440 /*! Frequency == 0, has a contact, but don't know status (non-qualified) */
443};
444
445/*!
446 * \brief A contact's status.
447 *
448 * Maintains a contact's current status and round trip time if available.
449 */
452 /*! The original contact's URI */
454 /*! The name of the aor this contact_status belongs to */
456 );
457 /*! The round trip time in microseconds */
458 int64_t rtt;
459 /*!
460 * The security mechanism list of the contact (RFC 3329).
461 * Stores the values of Security-Server headers in 401/421/494 responses to an
462 * in-dialog request or successful outbound registration which will be used to
463 * set the Security-Verify headers of all subsequent requests to the contact.
464 */
466 /*! Current status for a contact (default - unavailable) */
468 /*! Last status for a contact (default - unavailable) */
470 /*! Name of the contact */
471 char name[0];
472};
473
474/*!
475 * \brief A SIP address of record
476 */
478 /*! Sorcery object details, the id is the AOR name */
481 /*! Voicemail boxes for this AOR */
483 /*! Outbound proxy for OPTIONS requests */
485 );
486 /*! Minimum expiration time */
487 unsigned int minimum_expiration;
488 /*! Maximum expiration time */
489 unsigned int maximum_expiration;
490 /*! Default contact expiration if one is not provided in the contact */
491 unsigned int default_expiration;
492 /*! Frequency to send OPTIONS requests to AOR contacts. 0 is disabled. */
493 unsigned int qualify_frequency;
494 /*! If true authenticate the qualify challenge response if needed */
496 /*! Maximum number of external contacts, 0 to disable */
497 unsigned int max_contacts;
498 /*! Whether to remove any existing contacts not related to an incoming REGISTER when it comes in */
499 unsigned int remove_existing;
500 /*! Any permanent configured contacts */
502 /*! Determines whether SIP Path headers are supported */
503 unsigned int support_path;
504 /*! Qualify timeout. 0 is diabled. */
506 /*! Voicemail extension to set in Message-Account */
508 /*! Whether to remove unavailable contacts over max_contacts at all or first if remove_existing is enabled */
509 unsigned int remove_unavailable;
510 /*! If true only authenticate if OPTIONS response is 2XX */
512};
513
514/*!
515 * \brief A wrapper for contact that adds the aor_id and
516 * a consistent contact id. Used by ast_sip_for_each_contact.
517 */
519 /*! The id of the parent aor. */
520 char *aor_id;
521 /*! The id of contact in form of aor_id/contact_uri. */
523 /*! Pointer to the actual contact. */
525};
526
527/*!
528 * \brief 100rel modes for SIP endpoints
529 */
531 /*! Do not support 100rel. (no) */
533 /*! As UAC, indicate 100rel support in Supported header. (yes) */
535 /*! As UAS, send 1xx responses reliably, if the UAC indicated its support. Otherwise same as AST_SIP_100REL_SUPPORTED. (peer_supported) */
537 /*! Require the use of 100rel. (required) */
539};
540
541/*!
542 * \brief DTMF modes for SIP endpoints
543 */
545 /*! No DTMF to be used */
547 /* XXX Should this be 2833 instead? */
548 /*! Use RFC 4733 events for DTMF */
550 /*! Use DTMF in the audio stream */
552 /*! Use SIP INFO DTMF (blech) */
554 /*! Use SIP 4733 if supported by the other side or INBAND if not */
556 /*! Use SIP 4733 if supported by the other side or INFO DTMF (blech) if not */
558};
559
560/*!
561 * \brief Methods of storing SIP digest authentication credentials.
562 *
563 * Note that both methods result in MD5 digest authentication being
564 * used. The two methods simply alter how Asterisk determines the
565 * credentials for a SIP authentication
566 */
568 /*! Credentials stored as a username and password combination */
570 /*! Credentials stored as an MD5 sum */
572 /*! Google Oauth */
574 /*! Credentials not stored this is a fake auth */
577
578#define SIP_SORCERY_AUTH_TYPE "auth"
579
581 /*! Sorcery ID of the auth is its name */
584 /*! Identification for these credentials */
586 /*! Authentication username */
588 /*! Authentication password */
590 /*! Authentication credentials in MD5 format (hash of user:realm:pass) */
592 /*! Refresh token to use for OAuth authentication */
594 /*! Client ID to use for OAuth authentication */
596 /*! Secret to use for OAuth authentication */
598 );
599 /*! The time period (in seconds) that a nonce may be reused */
600 unsigned int nonce_lifetime;
601 /*! Used to determine what to use when authenticating */
603};
604
606
607/*!
608 * \brief Different methods by which incoming requests can be matched to endpoints
609 */
611 /*! Identify based on user name in From header */
613 /*! Identify based on user name in Auth header first, then From header */
615 /*! Identify based on source IP address */
617 /*! Identify based on arbitrary headers */
619 /*! Identify based on request uri */
621};
623
625 /*! Use reinvite to negotiate direct media */
627 /*! Use UPDATE to negotiate direct media */
629};
630
632 /*! Take no special action to mitigate reinvite glare */
634 /*! Do not send an initial direct media session refresh on outgoing call legs
635 * Subsequent session refreshes will be sent no matter the session direction
636 */
638 /*! Do not send an initial direct media session refresh on incoming call legs
639 * Subsequent session refreshes will be sent no matter the session direction
640 */
642};
643
645 /*! Invalid media encryption configuration */
647 /*! Do not allow any encryption of session media */
649 /*! Offer SDES-encrypted session media */
651 /*! Offer encrypted session media with datagram TLS key exchange */
653};
654
656 /*! User portion of the target URI should be used as the target in the dialplan */
658 /*! Target URI should be used as the target in the dialplan */
660 /*! Target URI should be used as the target within chan_pjsip itself */
662};
663
664/*!
665 * \brief Incoming/Outgoing call offer/answer joint codec preference.
666 *
667 * The default is INTERSECT ALL LOCAL.
668 */
670 /*! Two bits for merge */
671 /*! Intersection of local and remote */
673 /*! Union of local and remote */
675
676 /*! Two bits for filter */
677 /*! No filter */
679 /*! Only the first */
681
682 /*! Two bits for preference and sort */
683 /*! Prefer, and order by local values */
685 /*! Prefer, and order by remote values */
687};
688
689/*!
690 * \brief Returns true if the preference is set in the parameter
691 * \since 18.0.0
692 *
693 * \param __param A ast_flags struct with one or more of enum ast_sip_call_codec_pref set
694 * \param __codec_pref The last component of one of the enum values
695 * \retval 1 if the enum value is set
696 * \retval 0 if not
697 */
698#define ast_sip_call_codec_pref_test(__param, __codec_pref) (!!(ast_test_flag( &__param, AST_SIP_CALL_CODEC_PREF_ ## __codec_pref )))
699
700/*!
701 * \brief Session timers options
702 */
704 /*! Minimum session expiration period, in seconds */
705 unsigned int min_se;
706 /*! Session expiration period, in seconds */
707 unsigned int sess_expires;
708};
709
710/*!
711 * \brief Endpoint configuration for SIP extensions.
712 *
713 * SIP extensions, in this case refers to features
714 * indicated in Supported or Required headers.
715 */
717 /*! Enabled SIP extensions */
718 unsigned int flags;
719 /*! Timer options */
721};
722
723/*!
724 * \brief Endpoint configuration for unsolicited MWI
725 */
728 /*! Configured voicemail boxes for this endpoint. Used for MWI */
730 /*! Username to use when sending MWI NOTIFYs to this endpoint */
732 );
733 /*! Should mailbox states be combined into a single notification? */
734 unsigned int aggregate;
735 /*! Should a subscribe replace unsolicited notifies? */
737 /*! Voicemail extension to set in Message-Account */
739};
740
741/*!
742 * \brief Endpoint subscription configuration
743 */
745 /*! Indicates if endpoint is allowed to initiate subscriptions */
746 unsigned int allow;
747 /*! The minimum allowed expiration for subscriptions from endpoint */
748 unsigned int minexpiry;
749 /*! Message waiting configuration */
751 /*! Context for SUBSCRIBE requests */
753};
754
755/*!
756 * \brief NAT configuration options for endpoints
757 */
759 /*! Whether to force using the source IP address/port for sending responses */
760 unsigned int force_rport;
761 /*! Whether to rewrite the Contact header with the source IP address/port or not */
762 unsigned int rewrite_contact;
763};
764
765/*!
766 * \brief Party identification options for endpoints
767 *
768 * This includes caller ID, connected line, and redirecting-related options
769 */
772 /*! Do we accept identification information from this endpoint */
773 unsigned int trust_inbound;
774 /*! Do we send private identification information to this endpoint? */
775 unsigned int trust_outbound;
776 /*! Do we send P-Asserted-Identity headers to this endpoint? */
777 unsigned int send_pai;
778 /*! Do we send Remote-Party-ID headers to this endpoint? */
779 unsigned int send_rpid;
780 /*! Do we send messages for connected line updates for unanswered incoming calls immediately to this endpoint? */
781 unsigned int rpid_immediate;
782 /*! Do we add Diversion headers to applicable outgoing requests/responses? */
783 unsigned int send_diversion;
784 /*! Do we accept connected line updates from this endpoint? */
786 /*! Do we send connected line updates to this endpoint? */
788 /*! When performing connected line update, which method should be used */
790 /*! Do we add History-Info headers to applicable outgoing requests/responses? */
791 unsigned int send_history_info;
792};
793
794/*!
795 * \brief Call pickup configuration options for endpoints
796 */
798 /*! Call group */
800 /*! Pickup group */
802 /*! Named call group */
803 struct ast_namedgroups *named_callgroups;
804 /*! Named pickup group */
805 struct ast_namedgroups *named_pickupgroups;
806};
807
808/*!
809 * \brief Configuration for one-touch INFO recording
810 */
813 /*! Feature to enact when one-touch recording INFO with Record: On is received */
815 /*! Feature to enact when one-touch recording INFO with Record: Off is received */
817 );
818 /*! Is one-touch recording permitted? */
819 unsigned int enabled;
820};
821
822/*!
823 * \brief Endpoint configuration options for INFO packages
824 */
826 /*! Configuration for one-touch recording */
828};
829
830/*!
831 * \brief RTP configuration for SIP endpoints
832 */
835 /*! Configured RTP engine for this endpoint. */
837 );
838 /*! Whether IPv6 RTP is enabled or not */
839 unsigned int ipv6;
840 /*! Whether symmetric RTP is enabled or not */
841 unsigned int symmetric;
842 /*! Whether ICE support is enabled or not */
843 unsigned int ice_support;
844 /*! Whether to use the "ptime" attribute received from the endpoint or not */
845 unsigned int use_ptime;
846 /*! Do we use AVPF exclusively for this endpoint? */
847 unsigned int use_avpf;
848 /*! Do we force AVP, AVPF, SAVP, or SAVPF even for DTLS media streams? */
849 unsigned int force_avp;
850 /*! Do we use the received media transport in our answer SDP */
852 /*! \brief DTLS-SRTP configuration information */
854 /*! Should SRTP use a 32 byte tag instead of an 80 byte tag? */
855 unsigned int srtp_tag_32;
856 /*! Do we use media encryption? what type? */
858 /*! Do we want to optimistically support encryption if possible? */
860 /*! Number of seconds between RTP keepalive packets */
861 unsigned int keepalive;
862 /*! Number of seconds before terminating channel due to lack of RTP (when not on hold) */
863 unsigned int timeout;
864 /*! Number of seconds before terminating channel due to lack of RTP (when on hold) */
865 unsigned int timeout_hold;
866 /*! Follow forked media with a different To tag */
868 /*! Accept updated SDPs on non-100rel 18X and 2XX responses with the same To tag */
870};
871
872/*!
873 * \brief Direct media options for SIP endpoints
874 */
876 /*! Boolean indicating if direct_media is permissible */
877 unsigned int enabled;
878 /*! When using direct media, which method should be used */
880 /*! Take steps to mitigate glare for direct media */
882 /*! Do not attempt direct media session refreshes if a media NAT is detected */
883 unsigned int disable_on_nat;
884};
885
887 /*! Whether T.38 UDPTL support is enabled or not */
888 unsigned int enabled;
889 /*! Error correction setting for T.38 UDPTL */
891 /*! Explicit T.38 max datagram value, may be 0 to indicate the remote side can be trusted */
892 unsigned int maxdatagram;
893 /*! Whether NAT Support is enabled for T.38 UDPTL sessions or not */
894 unsigned int nat;
895 /*! Whether to use IPv6 for UDPTL or not */
896 unsigned int ipv6;
897 /*! Bind the UDPTL instance to the media_address */
899};
900
901/*!
902 * \brief Media configuration for SIP endpoints
903 */
906 /*! Optional media address to use in SDP */
908 /*! SDP origin username */
910 /*! SDP session name */
912 );
913 /*! RTP media configuration */
915 /*! Direct media options */
917 /*! T.38 (FoIP) options */
919 /*! Configured codecs */
921 /*! Capabilities in topology form */
923 /*! DSCP TOS bits for audio streams */
924 unsigned int tos_audio;
925 /*! Priority for audio streams */
926 unsigned int cos_audio;
927 /*! DSCP TOS bits for video streams */
928 unsigned int tos_video;
929 /*! Priority for video streams */
930 unsigned int cos_video;
931 /*! Is g.726 packed in a non standard way */
932 unsigned int g726_non_standard;
933 /*! Bind the RTP instance to the media_address */
935 /*! Use RTCP-MUX */
936 unsigned int rtcp_mux;
937 /*! Maximum number of audio streams to offer/accept */
938 unsigned int max_audio_streams;
939 /*! Maximum number of video streams to offer/accept */
940 unsigned int max_video_streams;
941 /*! Use BUNDLE */
942 unsigned int bundle;
943 /*! Enable webrtc settings and defaults */
944 unsigned int webrtc;
945 /*! Codec preference for an incoming offer */
947 /*! Codec preference for an outgoing offer */
949 /*! Codec negotiation prefs for incoming offers */
951 /*! Codec negotiation prefs for outgoing offers */
953 /*! Codec negotiation prefs for incoming answers */
955 /*! Codec negotiation prefs for outgoing answers */
957};
958
959/*!
960 * \brief An entity with which Asterisk communicates
961 */
965 /*! Context to send incoming calls to */
967 /*! Name of an explicit transport to use */
969 /*! Outbound proxy to use */
971 /*! Explicit AORs to dial if none are specified */
973 /*! Musiconhold class to suggest that the other side use when placing on hold */
975 /*! Configured tone zone for this endpoint. */
977 /*! Configured language for this endpoint. */
979 /*! Default username to place in From header */
981 /*! Domain to place in From header */
983 /*! Context to route incoming MESSAGE requests to */
985 /*! Accountcode to auto-set on channels */
987 /*! If set, we'll push incoming MWI NOTIFYs to stasis using this mailbox */
989 /*! STIR/SHAKEN profile to use */
991 );
992 /*! Configuration for extensions */
994 /*! Configuration relating to media */
996 /*! SUBSCRIBE/NOTIFY configuration options */
998 /*! NAT configuration */
1000 /*! Party identification options */
1002 /*! Configuration options for INFO packages */
1004 /*! Call pickup configuration */
1006 /*! Inbound authentication credentials */
1008 /*! Outbound authentication credentials */
1010 /*! DTMF mode to use with this endpoint */
1012 /*! Method(s) by which the endpoint should be identified. */
1014 /*! Order of the method(s) by which the endpoint should be identified. */
1016 /*! Boolean indicating if ringing should be sent as inband progress */
1017 unsigned int inband_progress;
1018 /*! Pointer to the persistent Asterisk endpoint */
1020 /*! The number of channels at which busy device state is returned */
1022 /*! Whether fax detection is enabled or not (CNG tone detection) */
1023 unsigned int faxdetect;
1024 /*! Determines if transfers (using REFER) are allowed by this endpoint */
1025 unsigned int allowtransfer;
1026 /*! Method used when handling redirects */
1028 /*! Variables set on channel creation */
1030 /*! Whether to place a 'user=phone' parameter into the request URI if user is a number */
1031 unsigned int usereqphone;
1032 /*! Whether to pass through hold and unhold using re-invites with recvonly and sendrecv */
1033 unsigned int moh_passthrough;
1034 /*! Access control list */
1036 /*! Restrict what IPs are allowed in the Contact header (for registration) */
1038 /*! The number of seconds into call to disable fax detection. (0 = disabled) */
1039 unsigned int faxdetect_timeout;
1040 /*! Override the user on the outgoing Contact header with this value. */
1042 /*! Whether to response SDP offer with single most preferred codec. */
1044 /*! Do we allow an asymmetric RTP codec? */
1046 /*! Do we allow overlap dialling? */
1047 unsigned int allow_overlap;
1048 /*! Whether to notifies all the progress details on blind transfer */
1050 /*! Whether to notifies dialog-info 'early' on INUSE && RINGING state */
1052 /*! Suppress Q.850 Reason headers on this endpoint */
1054 /*! Ignore 183 if no SDP is present */
1056 /*! Type of security negotiation to use (RFC 3329). */
1058 /*! Client security mechanisms (RFC 3329). */
1060 /*! Set which STIR/SHAKEN behaviors we want on this endpoint */
1061 unsigned int stir_shaken;
1062 /*! Should we authenticate OPTIONS requests per RFC 3261? */
1064 /*! The name of the geoloc profile to apply when Asterisk receives a call from this endpoint */
1065 AST_STRING_FIELD_EXTENDED(geoloc_incoming_call_profile);
1066 /*! The name of the geoloc profile to apply when Asterisk sends a call to this endpoint */
1067 AST_STRING_FIELD_EXTENDED(geoloc_outgoing_call_profile);
1068 /*! The context to use for overlap dialing, if different from the endpoint's context */
1070 /*! 100rel mode to use with this endpoint */
1072 /*! Send Advice-of-Charge messages */
1073 unsigned int send_aoc;
1074 /*! Tenant ID for the endpoint */
1076 /*! Ignore remote hold requests */
1078};
1079
1080/*! URI parameter for symmetric transport */
1081#define AST_SIP_X_AST_TXP "x-ast-txp"
1082#define AST_SIP_X_AST_TXP_LEN 9
1083
1084/*! Common media types used throughout res_pjsip and pjproject */
1085extern pjsip_media_type pjsip_media_type_application_json;
1087extern pjsip_media_type pjsip_media_type_application_pidf_xml;
1088extern pjsip_media_type pjsip_media_type_application_xpidf_xml;
1089extern pjsip_media_type pjsip_media_type_application_cpim_xpidf_xml;
1090extern pjsip_media_type pjsip_media_type_application_rlmi_xml;
1092extern pjsip_media_type pjsip_media_type_application_sdp;
1093extern pjsip_media_type pjsip_media_type_multipart_alternative;
1094extern pjsip_media_type pjsip_media_type_multipart_mixed;
1095extern pjsip_media_type pjsip_media_type_multipart_related;
1096extern pjsip_media_type pjsip_media_type_text_plain;
1097
1098/*!
1099 * \brief Compare pjsip media types
1100 *
1101 * \param a the first media type
1102 * \param b the second media type
1103 * \retval 1 Media types are equal
1104 * \retval 0 Media types are not equal
1105 */
1106int ast_sip_are_media_types_equal(pjsip_media_type *a, pjsip_media_type *b);
1107
1108/*!
1109 * \brief Check if a media type is in a list of others
1110 *
1111 * \param a pjsip_media_type to search for
1112 * \param ... one or more pointers to pjsip_media_types the last of which must be "SENTINEL"
1113 * \retval 1 Media types are equal
1114 * \retval 0 Media types are not equal
1115 */
1116int ast_sip_is_media_type_in(pjsip_media_type *a, ...) attribute_sentinel;
1117
1118/*!
1119 * \brief Add security headers to transmission data
1120 *
1121 * \param security_mechanisms Vector of security mechanisms.
1122 * \param header_name The header name under which to add the security mechanisms.
1123 * One of Security-Client, Security-Server, Security-Verify.
1124 * \param add_qval If zero, don't add the q-value to the header.
1125 * \param tdata The transmission data.
1126 * \retval 0 Success
1127 * \retval non-zero Failure
1128 */
1130 const char *header_name, int add_qval, pjsip_tx_data *tdata);
1131
1132/*!
1133 * \brief Append to security mechanism vector from SIP header
1134 *
1135 * \param hdr The header of the security mechanisms.
1136 * \param security_mechanisms Vector of security mechanisms to append to.
1137 * Header name must be one of Security-Client, Security-Server, Security-Verify.
1138 */
1139void ast_sip_header_to_security_mechanism(const pjsip_generic_string_hdr *hdr,
1140 struct ast_sip_security_mechanism_vector *security_mechanisms);
1141
1142/*!
1143 * \brief Initialize security mechanism vector from string of security mechanisms.
1144 *
1145 * \param security_mechanism Pointer to vector of security mechanisms to initialize.
1146 * \param value String of security mechanisms as defined in RFC 3329.
1147 * \retval 0 Success
1148 * \retval non-zero Failure
1149 */
1150int ast_sip_security_mechanism_vector_init(struct ast_sip_security_mechanism_vector *security_mechanism, const char *value);
1151
1152/*!
1153 * \brief Removes all headers of a specific name and value from a pjsip_msg.
1154 *
1155 * \param msg PJSIP message from which to remove headers.
1156 * \param hdr_name Name of the header to remove.
1157 * \param value Optional string value of the header to remove.
1158 * If NULL, remove all headers of given hdr_name.
1159 */
1160void ast_sip_remove_headers_by_name_and_value(pjsip_msg *msg, const pj_str_t *hdr_name, const char* value);
1161
1162/*!
1163 * \brief Duplicate a security mechanism.
1164 *
1165 * \param dst Security mechanism to duplicate to.
1166 * \param src Security mechanism to duplicate.
1167 */
1169 const struct ast_sip_security_mechanism_vector *src);
1170
1171/*!
1172 * \brief Free contents of a security mechanism vector.
1173 *
1174 * \param security_mechanisms Vector whose contents are to be freed
1175 */
1177
1178/*!
1179 * \brief Allocate a security mechanism from a string.
1180 *
1181 * \param security_mechanism Pointer-pointer to the security mechanism to allocate.
1182 * \param value The security mechanism string as defined in RFC 3329 (section 2.2)
1183 * in the form <mechanism_name>;q=<q_value>;<mechanism_parameters>
1184 * \retval 0 Success
1185 * \retval non-zero Failure
1186 */
1187int ast_sip_str_to_security_mechanism(struct ast_sip_security_mechanism **security_mechanism, const char *value);
1188
1189/*!
1190 * \brief Writes the security mechanisms of an endpoint into a buffer as a string and returns the buffer.
1191 *
1192 * \note The buffer must be freed by the caller.
1193 *
1194 * \param endpoint Pointer to endpoint.
1195 * \param add_qvalue If non-zero, the q-value is printed as well
1196 * \param buf The buffer to write the string into
1197 * \retval 0 Success
1198 * \retval non-zero Failure
1199 */
1200int ast_sip_security_mechanisms_to_str(const struct ast_sip_security_mechanism_vector *security_mechanisms, int add_qvalue, char **buf);
1201
1202/*!
1203 * \brief Set the security negotiation based on a given string.
1204 *
1205 * \param security_negotiation Security negotiation enum to set.
1206 * \param val String that represents a security_negotiation value.
1207 * \retval 0 Success
1208 * \retval non-zero Failure
1209 */
1210int ast_sip_set_security_negotiation(enum ast_sip_security_negotiation *security_negotiation, const char *val);
1211
1212/*!
1213 * \brief Initialize an auth vector with the configured values.
1214 *
1215 * \param vector Vector to initialize
1216 * \param auth_names Comma-separated list of names to set in the array
1217 * \retval 0 Success
1218 * \retval non-zero Failure
1219 */
1220int ast_sip_auth_vector_init(struct ast_sip_auth_vector *vector, const char *auth_names);
1221
1222/*!
1223 * \brief Free contents of an auth vector.
1224 *
1225 * \param vector Vector whose contents are to be freed
1226 */
1228
1229/*!
1230 * \brief Possible returns from ast_sip_check_authentication
1231 */
1233 /*! Authentication needs to be challenged */
1235 /*! Authentication succeeded */
1237 /*! Authentication failed */
1239 /*! Authentication encountered some internal error */
1241};
1242
1243/*!
1244 * \brief An interchangeable way of handling digest authentication for SIP.
1245 *
1246 * An authenticator is responsible for filling in the callbacks provided below. Each is called from a publicly available
1247 * function in res_sip. The authenticator can use configuration or other local policy to determine whether authentication
1248 * should take place and what credentials should be used when challenging and authenticating a request.
1249 */
1251 /*!
1252 * \brief Check if a request requires authentication
1253 * See ast_sip_requires_authentication for more details
1254 */
1255 int (*requires_authentication)(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
1256 /*!
1257 * \brief Check that an incoming request passes authentication.
1258 *
1259 * The tdata parameter is useful for adding information such as digest challenges.
1260 *
1261 * \param endpoint The endpoint sending the incoming request
1262 * \param rdata The incoming request
1263 * \param tdata Tentative outgoing request.
1264 */
1266 pjsip_rx_data *rdata, pjsip_tx_data *tdata);
1267};
1268
1269/*!
1270 * \brief an interchangeable way of responding to authentication challenges
1271 *
1272 * An outbound authenticator takes incoming challenges and formulates a new SIP request with
1273 * credentials.
1274 */
1276 /*!
1277 * \brief Create a new request with authentication credentials
1278 *
1279 * \param auths A vector of IDs of auth sorcery objects
1280 * \param challenge The SIP response with authentication challenge(s)
1281 * \param old_request The request that received the auth challenge(s)
1282 * \param new_request The new SIP request with challenge response(s)
1283 * \retval 0 Successfully created new request
1284 * \retval -1 Failed to create a new request
1285 */
1286 int (*create_request_with_auth)(const struct ast_sip_auth_vector *auths, struct pjsip_rx_data *challenge,
1287 struct pjsip_tx_data *old_request, struct pjsip_tx_data **new_request);
1288};
1289
1290/*!
1291 * \brief An entity responsible for identifying the source of a SIP message
1292 */
1294 /*!
1295 * \brief Callback used to identify the source of a message.
1296 * See ast_sip_identify_endpoint for more details
1297 */
1298 struct ast_sip_endpoint *(*identify_endpoint)(pjsip_rx_data *rdata);
1299};
1300
1301/*!
1302 * \brief Contact retrieval filtering flags
1303 */
1305 /*! \brief Default filter flags */
1307
1308 /*! \brief Return only reachable or unknown contacts */
1310};
1311
1312/*!
1313 * \brief Adds a Date header to the tdata, formatted like:
1314 * Date: Wed, 01 Jan 2021 14:53:01 GMT
1315 * \since 16.19.0
1316 *
1317 * \note There is no checking done to see if the header already exists
1318 * before adding it. It's up to the caller of this function to determine
1319 * if that needs to be done or not.
1320 */
1321void ast_sip_add_date_header(pjsip_tx_data *tdata);
1322
1323/*!
1324 * \brief Register a SIP service in Asterisk.
1325 *
1326 * This is more-or-less a wrapper around pjsip_endpt_register_module().
1327 * Registering a service makes it so that PJSIP will call into the
1328 * service at appropriate times. For more information about PJSIP module
1329 * callbacks, see the PJSIP documentation. Asterisk modules that call
1330 * this function will likely do so at module load time.
1331 *
1332 * \param module The module that is to be registered with PJSIP
1333 * \retval 0 Success
1334 * \retval -1 Failure
1335 */
1336int ast_sip_register_service(pjsip_module *module);
1337
1338/*!
1339 * This is the opposite of ast_sip_register_service(). Unregistering a
1340 * service means that PJSIP will no longer call into the module any more.
1341 * This will likely occur when an Asterisk module is unloaded.
1342 *
1343 * \param module The PJSIP module to unregister
1344 */
1345void ast_sip_unregister_service(pjsip_module *module);
1346
1347/*!
1348 * \brief Register a SIP authenticator
1349 *
1350 * An authenticator has three main purposes:
1351 * 1) Determining if authentication should be performed on an incoming request
1352 * 2) Gathering credentials necessary for issuing an authentication challenge
1353 * 3) Authenticating a request that has credentials
1354 *
1355 * Asterisk provides a default authenticator, but it may be replaced by a
1356 * custom one if desired.
1357 *
1358 * \param auth The authenticator to register
1359 * \retval 0 Success
1360 * \retval -1 Failure
1361 */
1363
1364/*!
1365 * \brief Unregister a SIP authenticator
1366 *
1367 * When there is no authenticator registered, requests cannot be challenged
1368 * or authenticated.
1369 *
1370 * \param auth The authenticator to unregister
1371 */
1373
1374 /*!
1375 * \brief Register an outbound SIP authenticator
1376 *
1377 * An outbound authenticator is responsible for creating responses to
1378 * authentication challenges by remote endpoints.
1379 *
1380 * \param outbound_auth The authenticator to register
1381 * \retval 0 Success
1382 * \retval -1 Failure
1383 */
1385
1386/*!
1387 * \brief Unregister an outbound SIP authenticator
1388 *
1389 * When there is no outbound authenticator registered, authentication challenges
1390 * will be handled as any other final response would be.
1391 *
1392 * \param auth The authenticator to unregister
1393 */
1395
1396/*!
1397 * \brief Register a SIP endpoint identifier with a name.
1398 *
1399 * An endpoint identifier's purpose is to determine which endpoint a given SIP
1400 * message has come from.
1401 *
1402 * Multiple endpoint identifiers may be registered so that if an endpoint
1403 * cannot be identified by one identifier, it may be identified by another.
1404 *
1405 * \param identifier The SIP endpoint identifier to register
1406 * \param name The name of the endpoint identifier
1407 * \retval 0 Success
1408 * \retval -1 Failure
1409 */
1411 const char *name);
1412
1413/*!
1414 * \brief Register a SIP endpoint identifier
1415 *
1416 * An endpoint identifier's purpose is to determine which endpoint a given SIP
1417 * message has come from.
1418 *
1419 * Multiple endpoint identifiers may be registered so that if an endpoint
1420 * cannot be identified by one identifier, it may be identified by another.
1421 *
1422 * Asterisk provides two endpoint identifiers. One identifies endpoints based
1423 * on the user part of the From header URI. The other identifies endpoints based
1424 * on the source IP address.
1425 *
1426 * If the order in which endpoint identifiers is run is important to you, then
1427 * be sure to load individual endpoint identifier modules in the order you wish
1428 * for them to be run in modules.conf
1429 *
1430 * \note endpoint identifiers registered using this method (no name specified)
1431 * are placed at the front of the endpoint identifiers list ahead of any
1432 * named identifiers.
1433 *
1434 * \param identifier The SIP endpoint identifier to register
1435 * \retval 0 Success
1436 * \retval -1 Failure
1437 */
1439
1440/*!
1441 * \brief Unregister a SIP endpoint identifier
1442 *
1443 * This stops an endpoint identifier from being used.
1444 *
1445 * \param identifier The SIP endoint identifier to unregister
1446 */
1448
1449/*!
1450 * \brief Allocate a new SIP endpoint
1451 *
1452 * This will return an endpoint with its refcount increased by one. This reference
1453 * can be released using ao2_ref().
1454 *
1455 * \param name The name of the endpoint.
1456 * \retval NULL Endpoint allocation failed
1457 * \retval non-NULL The newly allocated endpoint
1458 */
1459void *ast_sip_endpoint_alloc(const char *name);
1460
1461/*!
1462 * \brief Change state of a persistent endpoint.
1463 *
1464 * \param endpoint_name The SIP endpoint name to change state.
1465 * \param state The new state
1466 * \retval 0 Success
1467 * \retval -1 Endpoint not found
1468 */
1469int ast_sip_persistent_endpoint_update_state(const char *endpoint_name, enum ast_endpoint_state state);
1470
1471/*!
1472 * \brief Publish the change of state for a contact.
1473 *
1474 * \param endpoint_name The SIP endpoint name.
1475 * \param contact_status The contact status.
1476 */
1477void ast_sip_persistent_endpoint_publish_contact_state(const char *endpoint_name, const struct ast_sip_contact_status *contact_status);
1478
1479/*!
1480 * \brief Retrieve the current status for a contact.
1481 *
1482 * \param contact The contact.
1483 *
1484 * \retval non-NULL Success
1485 * \retval NULL Status information not found
1486 *
1487 * \note The returned contact status object is immutable.
1488 */
1490
1491/*!
1492 * \brief Get a pointer to the PJSIP endpoint.
1493 *
1494 * This is useful when modules have specific information they need
1495 * to register with the PJSIP core.
1496 * \retval NULL endpoint has not been created yet.
1497 * \retval non-NULL PJSIP endpoint.
1498 */
1499pjsip_endpoint *ast_sip_get_pjsip_endpoint(void);
1500
1501/*!
1502 * \brief Get a pointer to the SIP sorcery structure.
1503 *
1504 * \retval NULL sorcery has not been initialized
1505 * \retval non-NULL sorcery structure
1506 */
1507struct ast_sorcery *ast_sip_get_sorcery(void);
1508
1509/*!
1510 * \brief Retrieve a named AOR
1511 *
1512 * \param aor_name Name of the AOR
1513 *
1514 * \retval NULL if not found
1515 * \retval non-NULL if found
1516 */
1517struct ast_sip_aor *ast_sip_location_retrieve_aor(const char *aor_name);
1518
1519/*!
1520 * \brief Retrieve the first bound contact for an AOR
1521 *
1522 * \param aor Pointer to the AOR
1523 * \retval NULL if no contacts available
1524 * \retval non-NULL if contacts available
1525 */
1527
1528/*!
1529 * \brief Retrieve the first bound contact for an AOR and filter based on flags
1530 * \since 13.16.0
1531 *
1532 * \param aor Pointer to the AOR
1533 * \param flags Filtering flags
1534 * \retval NULL if no contacts available
1535 * \retval non-NULL if contacts available
1536 */
1538 unsigned int flags);
1539
1540/*!
1541 * \brief Retrieve all contacts currently available for an AOR
1542 *
1543 * \param aor Pointer to the AOR
1544 *
1545 * \retval NULL if no contacts available
1546 * \retval non-NULL if contacts available
1547 *
1548 * \warning
1549 * Since this function prunes expired contacts before returning, it holds a named write
1550 * lock on the aor. If you already hold the lock, call ast_sip_location_retrieve_aor_contacts_nolock instead.
1551 */
1553
1554/*!
1555 * \brief Retrieve all contacts currently available for an AOR and filter based on flags
1556 * \since 13.16.0
1557 *
1558 * \param aor Pointer to the AOR
1559 * \param flags Filtering flags
1560 *
1561 * \retval NULL if no contacts available
1562 * \retval non-NULL if contacts available
1563 *
1564 * \warning
1565 * Since this function prunes expired contacts before returning, it holds a named write
1566 * lock on the aor. If you already hold the lock, call ast_sip_location_retrieve_aor_contacts_nolock instead.
1567 */
1569 unsigned int flags);
1570
1571/*!
1572 * \brief Retrieve all contacts currently available for an AOR without locking the AOR
1573 * \since 13.9.0
1574 *
1575 * \param aor Pointer to the AOR
1576 *
1577 * \retval NULL if no contacts available
1578 * \retval non-NULL if contacts available
1579 *
1580 * \warning
1581 * This function should only be called if you already hold a named write lock on the aor.
1582 */
1584
1585/*!
1586 * \brief Retrieve all contacts currently available for an AOR without locking the AOR and filter based on flags
1587 * \since 13.16.0
1588 *
1589 * \param aor Pointer to the AOR
1590 * \param flags Filtering flags
1591 *
1592 * \retval NULL if no contacts available
1593 * \retval non-NULL if contacts available
1594 *
1595 * \warning
1596 * This function should only be called if you already hold a named write lock on the aor.
1597 */
1599 unsigned int flags);
1600
1601/*!
1602 * \brief Retrieve the first bound contact from a list of AORs
1603 *
1604 * \param aor_list A comma-separated list of AOR names
1605 * \retval NULL if no contacts available
1606 * \retval non-NULL if contacts available
1607 */
1609
1610/*!
1611 * \brief Retrieve all contacts from a list of AORs
1612 *
1613 * \param aor_list A comma-separated list of AOR names
1614 * \retval NULL if no contacts available
1615 * \retval non-NULL container (which must be freed) if contacts available
1616 */
1618
1619/*!
1620 * \brief Retrieve the first bound contact AND the AOR chosen from a list of AORs
1621 *
1622 * \param aor_list A comma-separated list of AOR names
1623 * \param aor The chosen AOR
1624 * \param contact The chosen contact
1625 */
1626 void ast_sip_location_retrieve_contact_and_aor_from_list(const char *aor_list, struct ast_sip_aor **aor,
1627 struct ast_sip_contact **contact);
1628
1629/*!
1630 * \brief Retrieve the first bound contact AND the AOR chosen from a list of AORs and filter based on flags
1631 * \since 13.16.0
1632 *
1633 * \param aor_list A comma-separated list of AOR names
1634 * \param flags Filtering flags
1635 * \param aor The chosen AOR
1636 * \param contact The chosen contact
1637 */
1638void ast_sip_location_retrieve_contact_and_aor_from_list_filtered(const char *aor_list, unsigned int flags,
1639 struct ast_sip_aor **aor, struct ast_sip_contact **contact);
1640
1641/*!
1642 * \brief Retrieve a named contact
1643 *
1644 * \param contact_name Name of the contact
1645 *
1646 * \retval NULL if not found
1647 * \retval non-NULL if found
1648 */
1649struct ast_sip_contact *ast_sip_location_retrieve_contact(const char *contact_name);
1650
1651/*!
1652 * \brief Add a new contact to an AOR
1653 *
1654 * \param aor Pointer to the AOR
1655 * \param uri Full contact URI
1656 * \param expiration_time Optional expiration time of the contact
1657 * \param path_info Path information
1658 * \param user_agent User-Agent header from REGISTER request
1659 * \param via_addr
1660 * \param via_port
1661 * \param call_id
1662 * \param endpoint The endpoint that resulted in the contact being added
1663 *
1664 * \retval -1 failure
1665 * \retval 0 success
1666 *
1667 * \warning
1668 * This function holds a named write lock on the aor. If you already hold the lock
1669 * you should call ast_sip_location_add_contact_nolock instead.
1670 */
1671int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri,
1672 struct timeval expiration_time, const char *path_info, const char *user_agent,
1673 const char *via_addr, int via_port, const char *call_id,
1674 struct ast_sip_endpoint *endpoint);
1675
1676/*!
1677 * \brief Add a new contact to an AOR without locking the AOR
1678 * \since 13.9.0
1679 *
1680 * \param aor Pointer to the AOR
1681 * \param uri Full contact URI
1682 * \param expiration_time Optional expiration time of the contact
1683 * \param path_info Path information
1684 * \param user_agent User-Agent header from REGISTER request
1685 * \param via_addr
1686 * \param via_port
1687 * \param call_id
1688 * \param endpoint The endpoint that resulted in the contact being added
1689 *
1690 * \retval -1 failure
1691 * \retval 0 success
1692 *
1693 * \warning
1694 * This function should only be called if you already hold a named write lock on the aor.
1695 */
1697 struct timeval expiration_time, const char *path_info, const char *user_agent,
1698 const char *via_addr, int via_port, const char *call_id,
1699 struct ast_sip_endpoint *endpoint);
1700
1701/*!
1702 * \brief Create a new contact for an AOR without locking the AOR
1703 * \since 13.18.0
1704 *
1705 * \param aor Pointer to the AOR
1706 * \param uri Full contact URI
1707 * \param expiration_time Optional expiration time of the contact
1708 * \param path_info Path information
1709 * \param user_agent User-Agent header from REGISTER request
1710 * \param via_addr
1711 * \param via_port
1712 * \param call_id
1713 * \param prune_on_boot Non-zero if the contact cannot survive a restart/boot.
1714 * \param endpoint The endpoint that resulted in the contact being added
1715 *
1716 * \return The created contact or NULL on failure.
1717 *
1718 * \warning
1719 * This function should only be called if you already hold a named write lock on the aor.
1720 */
1722 const char *uri, struct timeval expiration_time, const char *path_info,
1723 const char *user_agent, const char *via_addr, int via_port, const char *call_id,
1725
1726/*!
1727 * \brief Update a contact
1728 *
1729 * \param contact New contact object with details
1730 *
1731 * \retval -1 failure
1732 * \retval 0 success
1733 */
1735
1736/*!
1737* \brief Delete a contact
1738*
1739* \param contact Contact object to delete
1740*
1741* \retval -1 failure
1742* \retval 0 success
1743*/
1745
1746/*!
1747 * \brief Prune the prune_on_boot contacts
1748 * \since 13.18.0
1749 */
1751
1752/*!
1753 * \brief Callback called when an outbound request with authentication credentials is to be sent in dialog
1754 *
1755 * This callback will have the created request on it. The callback's purpose is to do any extra
1756 * housekeeping that needs to be done as well as to send the request out.
1757 *
1758 * This callback is only necessary if working with a PJSIP API that sits between the application
1759 * and the dialog layer.
1760 *
1761 * \param dlg The dialog to which the request belongs
1762 * \param tdata The created request to be sent out
1763 * \param user_data Data supplied with the callback
1764 *
1765 * \retval 0 Success
1766 * \retval -1 Failure
1767 */
1768typedef int (*ast_sip_dialog_outbound_auth_cb)(pjsip_dialog *dlg, pjsip_tx_data *tdata, void *user_data);
1769
1770/*!
1771 * \brief Set up outbound authentication on a SIP dialog
1772 *
1773 * This sets up the infrastructure so that all requests associated with a created dialog
1774 * can be re-sent with authentication credentials if the original request is challenged.
1775 *
1776 * \param dlg The dialog on which requests will be authenticated
1777 * \param endpoint The endpoint whom this dialog pertains to
1778 * \param cb Callback to call to send requests with authentication
1779 * \param user_data Data to be provided to the callback when it is called
1780 *
1781 * \retval 0 Success
1782 * \retval -1 Failure
1783 */
1785 ast_sip_dialog_outbound_auth_cb cb, void *user_data);
1786
1787/*!
1788 * \brief Retrieves a reference to the artificial auth.
1789 *
1790 * \retval The artificial auth
1791 */
1793
1794/*!
1795 * \brief Retrieves a reference to the artificial endpoint.
1796 *
1797 * \retval The artificial endpoint
1798 */
1800
1801/*! \defgroup pjsip_threading PJSIP Threading Model
1802 * @{
1803 * \page PJSIP PJSIP Threading Model
1804 *
1805 * There are three major types of threads that SIP will have to deal with:
1806 * \li Asterisk threads
1807 * \li PJSIP threads
1808 * \li SIP threadpool threads (a.k.a. "servants")
1809 *
1810 * \par Asterisk Threads
1811 *
1812 * Asterisk threads are those that originate from outside of SIP but within
1813 * Asterisk. The most common of these threads are PBX (channel) threads and
1814 * the autoservice thread. Most interaction with these threads will be through
1815 * channel technology callbacks. Within these threads, it is fine to handle
1816 * Asterisk data from outside of SIP, but any handling of SIP data should be
1817 * left to servants, \b especially if you wish to call into PJSIP for anything.
1818 * Asterisk threads are not registered with PJLIB, so attempting to call into
1819 * PJSIP will cause an assertion to be triggered, thus causing the program to
1820 * crash.
1821 *
1822 * \par PJSIP Threads
1823 *
1824 * PJSIP threads are those that originate from handling of PJSIP events, such
1825 * as an incoming SIP request or response, or a transaction timeout. The role
1826 * of these threads is to process information as quickly as possible so that
1827 * the next item on the SIP socket(s) can be serviced. On incoming messages,
1828 * Asterisk automatically will push the request to a servant thread. When your
1829 * module callback is called, processing will already be in a servant. However,
1830 * for other PJSIP events, such as transaction state changes due to timer
1831 * expirations, your module will be called into from a PJSIP thread. If you
1832 * are called into from a PJSIP thread, then you should push whatever processing
1833 * is needed to a servant as soon as possible. You can discern if you are currently
1834 * in a SIP servant thread using the \ref ast_sip_thread_is_servant function.
1835 *
1836 * \par Servants
1837 *
1838 * Servants are where the bulk of SIP work should be performed. These threads
1839 * exist in order to do the work that Asterisk threads and PJSIP threads hand
1840 * off to them. Servant threads register themselves with PJLIB, meaning that
1841 * they are capable of calling PJSIP and PJLIB functions if they wish.
1842 *
1843 * \par Serializer
1844 *
1845 * Tasks are handed off to servant threads using the API call \ref ast_sip_push_task.
1846 * The first parameter of this call is a serializer. If this pointer
1847 * is NULL, then the work will be handed off to whatever servant can currently handle
1848 * the task. If this pointer is non-NULL, then the task will not be executed until
1849 * previous tasks pushed with the same serializer have completed. For more information
1850 * on serializers and the benefits they provide, see \ref ast_threadpool_serializer
1851 *
1852 * \par Scheduler
1853 *
1854 * Some situations require that a task run periodically or at a future time. Normally
1855 * the ast_sched functionality would be used but ast_sched only uses 1 thread for all
1856 * tasks and that thread isn't registered with PJLIB and therefore can't do any PJSIP
1857 * related work.
1858 *
1859 * ast_sip_sched uses ast_sched only as a scheduled queue. When a task is ready to run,
1860 * it's pushed to a Serializer to be invoked asynchronously by a Servant. This ensures
1861 * that the task is executed in a PJLIB registered thread and allows the ast_sched thread
1862 * to immediately continue processing the queue. The Serializer used by ast_sip_sched
1863 * is one of your choosing or a random one from the res_pjsip pool if you don't choose one.
1864 *
1865 * \note
1866 *
1867 * Do not make assumptions about individual threads based on a corresponding serializer.
1868 * In other words, just because several tasks use the same serializer when being pushed
1869 * to servants, it does not mean that the same thread is necessarily going to execute those
1870 * tasks, even though they are all guaranteed to be executed in sequence.
1871 */
1872
1873typedef int (*ast_sip_task)(void *user_data);
1874
1875/*!
1876 * \brief Create a new serializer for SIP tasks
1877 * \since 13.8.0
1878 *
1879 * See \ref ast_threadpool_serializer for more information on serializers.
1880 * SIP creates serializers so that tasks operating on similar data will run
1881 * in sequence.
1882 *
1883 * \param name Name of the serializer. (must be unique)
1884 *
1885 * \retval NULL Failure
1886 * \retval non-NULL Newly-created serializer
1887 */
1889
1891
1892/*!
1893 * \brief Create a new serializer for SIP tasks
1894 * \since 13.8.0
1895 *
1896 * See \ref ast_threadpool_serializer for more information on serializers.
1897 * SIP creates serializers so that tasks operating on similar data will run
1898 * in sequence.
1899 *
1900 * \param name Name of the serializer. (must be unique)
1901 * \param shutdown_group Group shutdown controller. (NULL if no group association)
1902 *
1903 * \retval NULL Failure
1904 * \retval non-NULL Newly-created serializer
1905 */
1907
1908/*!
1909 * \brief Determine the distributor serializer for the SIP message.
1910 * \since 13.10.0
1911 *
1912 * \param rdata The incoming message.
1913 *
1914 * \retval Calculated distributor serializer on success.
1915 * \retval NULL on error.
1916 */
1917struct ast_taskprocessor *ast_sip_get_distributor_serializer(pjsip_rx_data *rdata);
1918
1919/*!
1920 * \brief Set a serializer on a SIP dialog so requests and responses are automatically serialized
1921 *
1922 * Passing a NULL serializer is a way to remove a serializer from a dialog.
1923 *
1924 * \param dlg The SIP dialog itself
1925 * \param serializer The serializer to use
1926 */
1927void ast_sip_dialog_set_serializer(pjsip_dialog *dlg, struct ast_taskprocessor *serializer);
1928
1929/*!
1930 * \brief Set an endpoint on a SIP dialog so in-dialog requests do not undergo endpoint lookup.
1931 *
1932 * \param dlg The SIP dialog itself
1933 * \param endpoint The endpoint that this dialog is communicating with
1934 */
1935void ast_sip_dialog_set_endpoint(pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint);
1936
1937/*!
1938 * \brief Get the endpoint associated with this dialog
1939 *
1940 * This function increases the refcount of the endpoint by one. Release
1941 * the reference once you are finished with the endpoint.
1942 *
1943 * \param dlg The SIP dialog from which to retrieve the endpoint
1944 * \retval NULL No endpoint associated with this dialog
1945 * \retval non-NULL The endpoint.
1946 */
1947struct ast_sip_endpoint *ast_sip_dialog_get_endpoint(pjsip_dialog *dlg);
1948
1949/*!
1950 * \brief Pushes a task to SIP servants
1951 *
1952 * This uses the serializer provided to determine how to push the task.
1953 * If the serializer is NULL, then the task will be pushed to the
1954 * servants directly. If the serializer is non-NULL, then the task will be
1955 * queued behind other tasks associated with the same serializer.
1956 *
1957 * \param serializer The serializer to which the task belongs. Can be NULL
1958 * \param sip_task The task to execute
1959 * \param task_data The parameter to pass to the task when it executes
1960 * \retval 0 Success
1961 * \retval -1 Failure
1962 */
1963int ast_sip_push_task(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);
1964
1965/*!
1966 * \brief Push a task to SIP servants and wait for it to complete.
1967 *
1968 * Like \ref ast_sip_push_task except that it blocks until the task
1969 * completes. If the current thread is a SIP servant thread then the
1970 * task executes immediately. Otherwise, the specified serializer
1971 * executes the task and the current thread waits for it to complete.
1972 *
1973 * \note PJPROJECT callbacks tend to have locks already held when
1974 * called.
1975 *
1976 * \warning \b Never hold locks that may be acquired by a SIP servant
1977 * thread when calling this function. Doing so may cause a deadlock
1978 * if all SIP servant threads are blocked waiting to acquire the lock
1979 * while the thread holding the lock is waiting for a free SIP servant
1980 * thread.
1981 *
1982 * \warning \b Use of this function in an ao2 destructor callback is a
1983 * bad idea. You don't have control over which thread executes the
1984 * destructor. Attempting to shift execution to another thread with
1985 * this function is likely to cause deadlock.
1986 *
1987 * \param serializer The SIP serializer to execute the task if the
1988 * current thread is not a SIP servant. NULL if any of the default
1989 * serializers can be used.
1990 * \param sip_task The task to execute
1991 * \param task_data The parameter to pass to the task when it executes
1992 *
1993 * \note The sip_task() return value may need to be distinguished from
1994 * the failure to push the task.
1995 *
1996 * \return sip_task() return value on success.
1997 * \retval -1 Failure to push the task.
1998 */
1999int ast_sip_push_task_wait_servant(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);
2000
2001/*!
2002 * \brief Push a task to SIP servants and wait for it to complete.
2003 * \deprecated Replaced with ast_sip_push_task_wait_servant().
2004 */
2005int ast_sip_push_task_synchronous(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);
2006
2007/*!
2008 * \brief Push a task to the serializer and wait for it to complete.
2009 *
2010 * Like \ref ast_sip_push_task except that it blocks until the task is
2011 * completed by the specified serializer. If the specified serializer
2012 * is the current thread then the task executes immediately.
2013 *
2014 * \note PJPROJECT callbacks tend to have locks already held when
2015 * called.
2016 *
2017 * \warning \b Never hold locks that may be acquired by a SIP servant
2018 * thread when calling this function. Doing so may cause a deadlock
2019 * if all SIP servant threads are blocked waiting to acquire the lock
2020 * while the thread holding the lock is waiting for a free SIP servant
2021 * thread for the serializer to execute in.
2022 *
2023 * \warning \b Never hold locks that may be acquired by the serializer
2024 * when calling this function. Doing so will cause a deadlock.
2025 *
2026 * \warning \b Never use this function in the pjsip monitor thread (It
2027 * is a SIP servant thread). This is likely to cause a deadlock.
2028 *
2029 * \warning \b Use of this function in an ao2 destructor callback is a
2030 * bad idea. You don't have control over which thread executes the
2031 * destructor. Attempting to shift execution to another thread with
2032 * this function is likely to cause deadlock.
2033 *
2034 * \param serializer The SIP serializer to execute the task. NULL if
2035 * any of the default serializers can be used.
2036 * \param sip_task The task to execute
2037 * \param task_data The parameter to pass to the task when it executes
2038 *
2039 * \note It is generally better to call
2040 * ast_sip_push_task_wait_servant() if you pass NULL for the
2041 * serializer parameter.
2042 *
2043 * \note The sip_task() return value may need to be distinguished from
2044 * the failure to push the task.
2045 *
2046 * \return sip_task() return value on success.
2047 * \retval -1 Failure to push the task.
2048 */
2049int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data);
2050
2051/*!
2052 * \brief Determine if the current thread is a SIP servant thread
2053 *
2054 * \retval 0 This is not a SIP servant thread
2055 * \retval 1 This is a SIP servant thread
2056 */
2058
2059/*!
2060 * \brief Task flags for the res_pjsip scheduler
2061 *
2062 * The default is AST_SIP_SCHED_TASK_FIXED
2063 * | AST_SIP_SCHED_TASK_DATA_NOT_AO2
2064 * | AST_SIP_SCHED_TASK_DATA_NO_CLEANUP
2065 * | AST_SIP_SCHED_TASK_PERIODIC
2066 */
2068 /*!
2069 * The defaults
2070 */
2072
2073 /*!
2074 * Run at a fixed interval.
2075 * Stop scheduling if the callback returns <= 0.
2076 * Any other value is ignored.
2077 */
2079 /*!
2080 * Run at a variable interval.
2081 * Stop scheduling if the callback returns <= 0.
2082 * Any other return value is used as the new interval.
2083 */
2085
2086 /*!
2087 * Run just once.
2088 * Return values are ignored.
2089 */
2091
2092 /*!
2093 * The task data is not an AO2 object.
2094 */
2096 /*!
2097 * The task data is an AO2 object.
2098 * A reference count will be held by the scheduler until
2099 * after the task has run for the final time (if ever).
2100 */
2102
2103 /*!
2104 * Don't take any cleanup action on the data
2105 */
2107 /*!
2108 * If AST_SIP_SCHED_TASK_DATA_AO2 is set, decrement the reference count
2109 * otherwise call ast_free on it.
2110 */
2112
2113 /*!
2114 * \brief The task is scheduled at multiples of interval
2115 * \see Interval
2116 */
2118 /*!
2119 * \brief The next invocation of the task is at last finish + interval
2120 * \see Interval
2121 */
2123 /*!
2124 * \brief The scheduled task's events are tracked in the debug log.
2125 * \details
2126 * Schedule events such as scheduling, running, rescheduling, canceling,
2127 * and destroying are logged about the task.
2128 */
2130};
2131
2132/*!
2133 * \brief Scheduler task data structure
2134 */
2135struct ast_sip_sched_task;
2136
2137/*!
2138 * \brief Schedule a task to run in the res_pjsip thread pool
2139 * \since 13.9.0
2140 *
2141 * \param serializer The serializer to use. If NULL, don't use a serializer (see note below)
2142 * \param interval The invocation interval in milliseconds (see note below)
2143 * \param sip_task The task to invoke
2144 * \param name An optional name to associate with the task
2145 * \param task_data Optional data to pass to the task
2146 * \param flags One of enum ast_sip_scheduler_task_type
2147 *
2148 * \returns Pointer to \ref ast_sip_sched_task ao2 object which must be dereferenced when done.
2149 *
2150 * \par Serialization
2151 *
2152 * Specifying a serializer guarantees serialized execution but NOT specifying a serializer
2153 * may still result in tasks being effectively serialized if the thread pool is busy.
2154 * The point of the serializer BTW is not to prevent parallel executions of the SAME task.
2155 * That happens automatically (see below). It's to prevent the task from running at the same
2156 * time as other work using the same serializer, whether or not it's being run by the scheduler.
2157 *
2158 * \par Interval
2159 *
2160 * The interval is used to calculate the next time the task should run. There are two models.
2161 *
2162 * \ref AST_SIP_SCHED_TASK_PERIODIC specifies that the invocations of the task occur at the
2163 * specific interval. That is, every \p interval milliseconds, regardless of how long the task
2164 * takes. If the task takes longer than \p interval, it will be scheduled at the next available
2165 * multiple of \p interval. For example: If the task has an interval of 60 seconds and the task
2166 * takes 70 seconds, the next invocation will happen at 120 seconds.
2167 *
2168 * \ref AST_SIP_SCHED_TASK_DELAY specifies that the next invocation of the task should start
2169 * at \p interval milliseconds after the current invocation has finished.
2170 *
2171 */
2173 int interval, ast_sip_task sip_task, const char *name, void *task_data,
2175
2176/*!
2177 * \brief Cancels the next invocation of a task
2178 * \since 13.9.0
2179 *
2180 * \param schtd The task structure pointer
2181 * \retval 0 Success
2182 * \retval -1 Failure
2183 * \note Only cancels future invocations not the currently running invocation.
2184 */
2186
2187/*!
2188 * \brief Cancels the next invocation of a task by name
2189 * \since 13.9.0
2190 *
2191 * \param name The task name
2192 * \retval 0 Success
2193 * \retval -1 Failure
2194 * \note Only cancels future invocations not the currently running invocation.
2195 */
2197
2198/*!
2199 * \brief Gets the last start and end times of the task
2200 * \since 13.9.0
2201 *
2202 * \param schtd The task structure pointer
2203 * \param[out] when_queued Pointer to a timeval structure to contain the time when queued
2204 * \param[out] last_start Pointer to a timeval structure to contain the time when last started
2205 * \param[out] last_end Pointer to a timeval structure to contain the time when last ended
2206 * \retval 0 Success
2207 * \retval -1 Failure
2208 * \note Any of the pointers can be NULL if you don't need them.
2209 */
2211 struct timeval *when_queued, struct timeval *last_start, struct timeval *last_end);
2212
2213/*!
2214 * \brief Gets the queued, last start, last_end, time left, interval, next run
2215 * \since 16.15.0
2216 * \since 18.1.0
2217 *
2218 * \param schtd The task structure pointer
2219 * \param[out] when_queued Pointer to a timeval structure to contain the time when queued
2220 * \param[out] last_start Pointer to a timeval structure to contain the time when last started
2221 * \param[out] last_end Pointer to a timeval structure to contain the time when last ended
2222 * \param[out] interval Pointer to an int to contain the interval in ms
2223 * \param[out] time_left Pointer to an int to contain the ms left to the next run
2224 * \param[out] next_start Pointer to a timeval structure to contain the next run time
2225 * \retval 0 Success
2226 * \retval -1 Failure
2227 * \note Any of the pointers can be NULL if you don't need them.
2228 */
2230 struct timeval *when_queued, struct timeval *last_start, struct timeval *last_end,
2231 int *interval, int *time_left, struct timeval *next_start);
2232
2233/*!
2234 * \brief Gets the last start and end times of the task by name
2235 * \since 13.9.0
2236 *
2237 * \param name The task name
2238 * \param[out] when_queued Pointer to a timeval structure to contain the time when queued
2239 * \param[out] last_start Pointer to a timeval structure to contain the time when last started
2240 * \param[out] last_end Pointer to a timeval structure to contain the time when last ended
2241 * \retval 0 Success
2242 * \retval -1 Failure
2243 * \note Any of the pointers can be NULL if you don't need them.
2244 */
2246 struct timeval *when_queued, struct timeval *last_start, struct timeval *last_end);
2247
2248/*!
2249 * \brief Gets the queued, last start, last_end, time left, interval, next run by task name
2250 * \since 16.15.0
2251 * \since 18.1.0
2252 *
2253 * \param name The task name
2254 * \param[out] when_queued Pointer to a timeval structure to contain the time when queued
2255 * \param[out] last_start Pointer to a timeval structure to contain the time when last started
2256 * \param[out] last_end Pointer to a timeval structure to contain the time when last ended
2257 * \param[out] interval Pointer to an int to contain the interval in ms
2258 * \param[out] time_left Pointer to an int to contain the ms left to the next run
2259 * \param[out] next_start Pointer to a timeval structure to contain the next run time
2260 * \retval 0 Success
2261 * \retval -1 Failure
2262 * \note Any of the pointers can be NULL if you don't need them.
2263 */
2265 struct timeval *when_queued, struct timeval *last_start, struct timeval *last_end,
2266 int *interval, int *time_left, struct timeval *next_start);
2267
2268/*!
2269 * \brief Gets the number of milliseconds until the next invocation
2270 * \since 13.9.0
2271 *
2272 * \param schtd The task structure pointer
2273 * \return The number of milliseconds until the next invocation or -1 if the task isn't scheduled
2274 */
2276
2277/*!
2278 * \brief Gets the number of milliseconds until the next invocation
2279 * \since 13.9.0
2280 *
2281 * \param name The task name
2282 * \return The number of milliseconds until the next invocation or -1 if the task isn't scheduled
2283 */
2285
2286/*!
2287 * \brief Checks if the task is currently running
2288 * \since 13.9.0
2289 *
2290 * \param schtd The task structure pointer
2291 * \retval 0 not running
2292 * \retval 1 running
2293 */
2295
2296/*!
2297 * \brief Checks if the task is currently running
2298 * \since 13.9.0
2299 *
2300 * \param name The task name
2301 * \retval 0 not running or not found
2302 * \retval 1 running
2303 */
2305
2306/*!
2307 * \brief Gets the task name
2308 * \since 13.9.0
2309 *
2310 * \param schtd The task structure pointer
2311 * \param name, maxlen
2312 * \retval 0 success
2313 * \retval 1 failure
2314 */
2315int ast_sip_sched_task_get_name(struct ast_sip_sched_task *schtd, char *name, size_t maxlen);
2316
2317/*!
2318 * @}
2319 */
2320
2321/*!
2322 * \brief SIP body description
2323 *
2324 * This contains a type and subtype that will be added as
2325 * the "Content-Type" for the message as well as the body
2326 * text.
2327 */
2329 /*! Type of the body, such as "application" */
2330 const char *type;
2331 /*! Subtype of the body, such as "sdp" */
2332 const char *subtype;
2333 /*! The text to go in the body */
2334 const char *body_text;
2335};
2336
2337/*!
2338 * \brief General purpose method for creating a UAC dialog with an endpoint
2339 *
2340 * \param endpoint A pointer to the endpoint
2341 * \param aor_name Optional name of the AOR to target, may even be an explicit SIP URI
2342 * \param request_user Optional user to place into the target URI
2343 *
2344 * \retval non-NULL success
2345 * \retval NULL failure
2346 */
2347pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, const char *aor_name, const char *request_user);
2348
2349/*!
2350 * \brief General purpose method for creating a UAS dialog with an endpoint
2351 *
2352 * \deprecated This function is unsafe (due to the returned object not being locked nor
2353 * having its reference incremented) and should no longer be used. Instead
2354 * use ast_sip_create_dialog_uas_locked so a properly locked and referenced
2355 * object is returned.
2356 *
2357 * \param endpoint A pointer to the endpoint
2358 * \param rdata The request that is starting the dialog
2359 * \param[out] status On failure, the reason for failure in creating the dialog
2360 */
2361pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pj_status_t *status);
2362
2363/*!
2364 * \brief General purpose method for creating a UAS dialog with an endpoint
2365 *
2366 * This function creates and returns a locked, and referenced counted pjsip
2367 * dialog object. The caller is thus responsible for freeing the allocated
2368 * memory, decrementing the reference, and releasing the lock when done with
2369 * the returned object.
2370 *
2371 * \note The safest way to unlock the object, and decrement its reference is by
2372 * calling pjsip_dlg_dec_lock. Alternatively, pjsip_dlg_dec_session can be
2373 * used to decrement the reference only.
2374 *
2375 * The dialog is returned locked and with a reference in order to ensure that the
2376 * dialog object, and any of its associated objects (e.g. transaction) are not
2377 * untimely destroyed. For instance, that could happen when a transport error
2378 * occurs.
2379 *
2380 * As long as the caller maintains a reference to the dialog there should be no
2381 * worry that it might unknowingly be destroyed. However, once the caller unlocks
2382 * the dialog there is a danger that some of the dialog's internal objects could
2383 * be lost and/or compromised. For example, when the aforementioned transport error
2384 * occurs the dialog's associated transaction gets destroyed (see pjsip_dlg_on_tsx_state
2385 * in sip_dialog.c, and mod_inv_on_tsx_state in sip_inv.c).
2386 *
2387 * In this case and before using the dialog again the caller should re-lock the
2388 * dialog, check to make sure the dialog is still established, and the transaction
2389 * still exists and has not been destroyed.
2390 *
2391 * \param endpoint A pointer to the endpoint
2392 * \param rdata The request that is starting the dialog
2393 * \param[out] status On failure, the reason for failure in creating the dialog
2394 *
2395 * \retval A locked, and reference counted pjsip_dialog object.
2396 * \retval NULL on failure
2397 */
2398pjsip_dialog *ast_sip_create_dialog_uas_locked(const struct ast_sip_endpoint *endpoint,
2399 pjsip_rx_data *rdata, pj_status_t *status);
2400
2401/*!
2402 * \brief General purpose method for creating an rdata structure using specific information
2403 * \since 13.15.0
2404 *
2405 * \param[out] rdata The rdata structure that will be populated
2406 * \param packet A SIP message
2407 * \param src_name The source IP address of the message
2408 * \param src_port The source port of the message
2409 * \param transport_type The type of transport the message was received on
2410 * \param local_name The local IP address the message was received on
2411 * \param local_port The local port the message was received on
2412 * \param contact_uri The contact URI of the message
2413 *
2414 * \retval 0 success
2415 * \retval -1 failure
2416 */
2417int ast_sip_create_rdata_with_contact(pjsip_rx_data *rdata, char *packet,
2418 const char *src_name, int src_port, char *transport_type, const char *local_name,
2419 int local_port, const char *contact_uri);
2420
2421/*!
2422 * \brief General purpose method for creating an rdata structure using specific information
2423 *
2424 * \param[out] rdata The rdata structure that will be populated
2425 * \param packet A SIP message
2426 * \param src_name The source IP address of the message
2427 * \param src_port The source port of the message
2428 * \param transport_type The type of transport the message was received on
2429 * \param local_name The local IP address the message was received on
2430 * \param local_port The local port the message was received on
2431 *
2432 * \retval 0 success
2433 * \retval -1 failure
2434 */
2435int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name,
2436 int src_port, char *transport_type, const char *local_name, int local_port);
2437
2438/*!
2439 * \brief General purpose method for creating a SIP request
2440 *
2441 * Its typical use would be to create one-off requests such as an out of dialog
2442 * SIP MESSAGE.
2443 *
2444 * The request can either be in- or out-of-dialog. If in-dialog, the
2445 * dlg parameter MUST be present. If out-of-dialog the endpoint parameter
2446 * MUST be present. If both are present, then we will assume that the message
2447 * is to be sent in-dialog.
2448 *
2449 * The uri parameter can be specified if the request should be sent to an explicit
2450 * URI rather than one configured on the endpoint.
2451 *
2452 * \param method The method of the SIP request to send
2453 * \param dlg Optional. If specified, the dialog on which to request the message.
2454 * \param endpoint Optional. If specified, the request will be created out-of-dialog to the endpoint.
2455 * \param uri Optional. If specified, the request will be sent to this URI rather
2456 * than one configured for the endpoint.
2457 * \param contact The contact with which this request is associated for out-of-dialog requests.
2458 * \param[out] tdata The newly-created request
2459 *
2460 * The provided contact is attached to tdata with its reference bumped, but will
2461 * not survive for the entire lifetime of tdata since the contact is cleaned up
2462 * when all supplements have completed execution.
2463 *
2464 * \retval 0 Success
2465 * \retval -1 Failure
2466 */
2467int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg,
2468 struct ast_sip_endpoint *endpoint, const char *uri,
2469 struct ast_sip_contact *contact, pjsip_tx_data **tdata);
2470
2471/*!
2472 * \brief General purpose method for sending a SIP request
2473 *
2474 * This is a companion function for \ref ast_sip_create_request. The request
2475 * created there can be passed to this function, though any request may be
2476 * passed in.
2477 *
2478 * This will automatically set up handling outbound authentication challenges if
2479 * they arrive.
2480 *
2481 * \param tdata The request to send
2482 * \param dlg Optional. The dialog in which the request is sent. Otherwise it is out-of-dialog.
2483 * \param endpoint Optional. If specified, the out-of-dialog request is sent to the endpoint.
2484 * \param token Data to be passed to the callback upon receipt of out-of-dialog response.
2485 * \param callback Callback to be called upon receipt of out-of-dialog response.
2486 *
2487 * \retval 0 Success
2488 * \retval -1 Failure (out-of-dialog callback will not be called.)
2489 */
2490int ast_sip_send_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg,
2491 struct ast_sip_endpoint *endpoint, void *token,
2492 void (*callback)(void *token, pjsip_event *e));
2493
2494/*!
2495 * \brief General purpose method for sending an Out-Of-Dialog SIP request
2496 *
2497 * This is a companion function for \ref ast_sip_create_request. The request
2498 * created there can be passed to this function, though any request may be
2499 * passed in.
2500 *
2501 * This will automatically set up handling outbound authentication challenges if
2502 * they arrive.
2503 *
2504 * \param tdata The request to send
2505 * \param endpoint Optional. If specified, the out-of-dialog request is sent to the endpoint.
2506 * \param timeout If non-zero, after the timeout the transaction will be terminated
2507 * and the callback will be called with the PJSIP_EVENT_TIMER type.
2508 * \param token Data to be passed to the callback upon receipt of out-of-dialog response.
2509 * \param callback Callback to be called upon receipt of out-of-dialog response.
2510 *
2511 * \retval 0 Success
2512 * \retval -1 Failure (out-of-dialog callback will not be called.)
2513 *
2514 * \note Timeout processing:
2515 * There are 2 timers associated with this request, PJSIP timer_b which is
2516 * set globally in the "system" section of pjsip.conf, and the timeout specified
2517 * on this call. The timer that expires first (before normal completion) will
2518 * cause the callback to be run with e->body.tsx_state.type = PJSIP_EVENT_TIMER.
2519 * The timer that expires second is simply ignored and the callback is not run again.
2520 */
2521int ast_sip_send_out_of_dialog_request(pjsip_tx_data *tdata,
2522 struct ast_sip_endpoint *endpoint, int timeout, void *token,
2523 void (*callback)(void *token, pjsip_event *e));
2524
2525/*!
2526 * \brief General purpose method for creating a SIP response
2527 *
2528 * Its typical use would be to create responses for out of dialog
2529 * requests.
2530 *
2531 * \param rdata The rdata from the incoming request.
2532 * \param st_code The response code to transmit.
2533 * \param contact The contact with which this request is associated.
2534 * \param[out] p_tdata The newly-created response
2535 *
2536 * The provided contact is attached to tdata with its reference bumped, but will
2537 * not survive for the entire lifetime of tdata since the contact is cleaned up
2538 * when all supplements have completed execution.
2539 *
2540 * \retval 0 Success
2541 * \retval -1 Failure
2542 */
2543int ast_sip_create_response(const pjsip_rx_data *rdata, int st_code,
2544 struct ast_sip_contact *contact, pjsip_tx_data **p_tdata);
2545
2546/*!
2547 * \brief Send a response to an out of dialog request
2548 *
2549 * Use this function sparingly, since this does not create a transaction
2550 * within PJSIP. This means that if the request is retransmitted, it is
2551 * your responsibility to detect this and not process the same request
2552 * twice, and to send the same response for each retransmission.
2553 *
2554 * \param res_addr The response address for this response
2555 * \param tdata The response to send
2556 * \param sip_endpoint The ast_sip_endpoint associated with this response
2557 *
2558 * \retval 0 Success
2559 * \retval -1 Failure
2560 */
2561int ast_sip_send_response(pjsip_response_addr *res_addr, pjsip_tx_data *tdata, struct ast_sip_endpoint *sip_endpoint);
2562
2563/*!
2564 * \brief Send a stateful response to an out of dialog request
2565 *
2566 * This creates a transaction within PJSIP, meaning that if the request
2567 * that we are responding to is retransmitted, we will not attempt to
2568 * re-handle the request.
2569 *
2570 * \param rdata The request that is being responded to
2571 * \param tdata The response to send
2572 * \param sip_endpoint The ast_sip_endpoint associated with this response
2573 *
2574 * \since 13.4.0
2575 *
2576 * \retval 0 Success
2577 * \retval -1 Failure
2578 */
2579int ast_sip_send_stateful_response(pjsip_rx_data *rdata, pjsip_tx_data *tdata, struct ast_sip_endpoint *sip_endpoint);
2580
2581/*!
2582 * \brief Determine if an incoming request requires authentication
2583 *
2584 * This calls into the registered authenticator's requires_authentication callback
2585 * in order to determine if the request requires authentication.
2586 *
2587 * If there is no registered authenticator, then authentication will be assumed
2588 * not to be required.
2589 *
2590 * \param endpoint The endpoint from which the request originates
2591 * \param rdata The incoming SIP request
2592 * \retval non-zero The request requires authentication
2593 * \retval 0 The request does not require authentication
2594 */
2595int ast_sip_requires_authentication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
2596
2597/*!
2598 * \brief Method to determine authentication status of an incoming request
2599 *
2600 * This will call into a registered authenticator. The registered authenticator will
2601 * do what is necessary to determine whether the incoming request passes authentication.
2602 * A tentative response is passed into this function so that if, say, a digest authentication
2603 * challenge should be sent in the ensuing response, it can be added to the response.
2604 *
2605 * \param endpoint The endpoint from the request was sent
2606 * \param rdata The request to potentially authenticate
2607 * \param tdata Tentative response to the request
2608 * \return The result of checking authentication.
2609 */
2611 pjsip_rx_data *rdata, pjsip_tx_data *tdata);
2612
2613/*!
2614 * \brief Create a response to an authentication challenge
2615 *
2616 * This will call into an outbound authenticator's create_request_with_auth callback
2617 * to create a new request with authentication credentials. See the create_request_with_auth
2618 * callback in the \ref ast_sip_outbound_authenticator structure for details about
2619 * the parameters and return values.
2620 */
2621int ast_sip_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
2622 pjsip_tx_data *tdata, pjsip_tx_data **new_request);
2623
2624/*!
2625 * \brief Determine the endpoint that has sent a SIP message
2626 *
2627 * This will call into each of the registered endpoint identifiers'
2628 * identify_endpoint() callbacks until one returns a non-NULL endpoint.
2629 * This will return an ao2 object. Its reference count will need to be
2630 * decremented when completed using the endpoint.
2631 *
2632 * \param rdata The inbound SIP message to use when identifying the endpoint.
2633 * \retval NULL No matching endpoint
2634 * \retval non-NULL The matching endpoint
2635 */
2636struct ast_sip_endpoint *ast_sip_identify_endpoint(pjsip_rx_data *rdata);
2637
2638/*!
2639 * \brief Get a specific header value from rdata
2640 *
2641 * \note The returned value does not need to be freed since it's from the rdata pool
2642 *
2643 * \param rdata The rdata
2644 * \param str The header to find
2645 *
2646 * \retval NULL on failure
2647 * \retval The header value on success
2648 */
2649char *ast_sip_rdata_get_header_value(pjsip_rx_data *rdata, const pj_str_t str);
2650
2651/*!
2652 * \brief Set the outbound proxy for an outbound SIP message
2653 *
2654 * \param tdata The message to set the outbound proxy on
2655 * \param proxy SIP uri of the proxy
2656 * \retval 0 Success
2657 * \retval -1 Failure
2658 */
2659int ast_sip_set_outbound_proxy(pjsip_tx_data *tdata, const char *proxy);
2660
2661/*!
2662 * \brief Add a header to an outbound SIP message
2663 *
2664 * \param tdata The message to add the header to
2665 * \param name The header name
2666 * \param value The header value
2667 * \retval 0 Success
2668 * \retval -1 Failure
2669 */
2670int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value);
2671
2672/*!
2673 * \brief Add a header to an outbound SIP message, returning a pointer to the header
2674 *
2675 * \param tdata The message to add the header to
2676 * \param name The header name
2677 * \param value The header value
2678 * \return The pjsip_generic_string_hdr * added.
2679 */
2680pjsip_generic_string_hdr *ast_sip_add_header2(pjsip_tx_data *tdata,
2681 const char *name, const char *value);
2682
2683/*!
2684 * \brief Add a body to an outbound SIP message
2685 *
2686 * If this is called multiple times, the latest body will replace the current
2687 * body.
2688 *
2689 * \param tdata The message to add the body to
2690 * \param body The message body to add
2691 * \retval 0 Success
2692 * \retval -1 Failure
2693 */
2694int ast_sip_add_body(pjsip_tx_data *tdata, const struct ast_sip_body *body);
2695
2696/*!
2697 * \brief Add a multipart body to an outbound SIP message
2698 *
2699 * This will treat each part of the input vector as part of a multipart body and
2700 * add each part to the SIP message.
2701 *
2702 * \param tdata The message to add the body to
2703 * \param bodies The message bodies to add
2704 * \param num_bodies The parts of the body to add
2705 * \retval 0 Success
2706 * \retval -1 Failure
2707 */
2708int ast_sip_add_body_multipart(pjsip_tx_data *tdata, const struct ast_sip_body *bodies[], int num_bodies);
2709
2710/*!
2711 * \brief Append body data to a SIP message
2712 *
2713 * This acts mostly the same as ast_sip_add_body, except that rather than replacing
2714 * a body if it currently exists, it appends data to an existing body.
2715 *
2716 * \param tdata The message to append the body to
2717 * \param body_text The string to append to the end of the current body
2718 * \retval 0 Success
2719 * \retval -1 Failure
2720 */
2721int ast_sip_append_body(pjsip_tx_data *tdata, const char *body_text);
2722
2723/*!
2724 * \brief Copy a pj_str_t into a standard character buffer.
2725 *
2726 * pj_str_t is not NULL-terminated. Any place that expects a NULL-
2727 * terminated string needs to have the pj_str_t copied into a separate
2728 * buffer.
2729 *
2730 * This method copies the pj_str_t contents into the destination buffer
2731 * and NULL-terminates the buffer.
2732 *
2733 * \param dest The destination buffer
2734 * \param src The pj_str_t to copy
2735 * \param size The size of the destination buffer.
2736 */
2737void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size);
2738
2739/*!
2740 * \brief Create and copy a pj_str_t into a standard character buffer.
2741 *
2742 * pj_str_t is not NULL-terminated. Any place that expects a NULL-
2743 * terminated string needs to have the pj_str_t copied into a separate
2744 * buffer.
2745 *
2746 * Copies the pj_str_t contents into a newly allocated buffer pointed to
2747 * by dest. NULL-terminates the buffer.
2748 *
2749 * \note Caller is responsible for freeing the allocated memory.
2750 *
2751 * \param[out] dest The destination buffer
2752 * \param src The pj_str_t to copy
2753 * \return Number of characters copied or negative value on error
2754 */
2755int ast_copy_pj_str2(char **dest, const pj_str_t *src);
2756
2757/*!
2758 * \brief Get the looked-up endpoint on an out-of dialog request or response
2759 *
2760 * The function may ONLY be called on out-of-dialog requests or responses. For
2761 * in-dialog requests and responses, it is required that the user of the dialog
2762 * has the looked-up endpoint stored locally.
2763 *
2764 * This function should never return NULL if the message is out-of-dialog. It will
2765 * always return NULL if the message is in-dialog.
2766 *
2767 * This function will increase the reference count of the returned endpoint by one.
2768 * Release your reference using the ao2_ref function when finished.
2769 *
2770 * \param rdata Out-of-dialog request or response
2771 * \return The looked up endpoint
2772 */
2773struct ast_sip_endpoint *ast_pjsip_rdata_get_endpoint(pjsip_rx_data *rdata);
2774
2775/*!
2776 * \brief Add 'user=phone' parameter to URI if enabled and user is a phone number.
2777 *
2778 * \param endpoint The endpoint to use for configuration
2779 * \param pool The memory pool to allocate the parameter from
2780 * \param uri The URI to check for user and to add parameter to
2781 */
2782void ast_sip_add_usereqphone(const struct ast_sip_endpoint *endpoint, pj_pool_t *pool, pjsip_uri *uri);
2783
2784/*!
2785 * \brief Retrieve any endpoints available to sorcery.
2786 *
2787 * \retval Endpoints available to sorcery, NULL if no endpoints found.
2788 */
2790
2791/*!
2792 * \brief Retrieve the default outbound endpoint.
2793 *
2794 * \retval The default outbound endpoint, NULL if not found.
2795 */
2797
2798/*!
2799 * \brief Retrieve relevant SIP auth structures from sorcery
2800 *
2801 * \param auths Vector of sorcery IDs of auth credentials to retrieve
2802 * \param[out] out The retrieved auths are stored here
2803 */
2804int ast_sip_retrieve_auths(const struct ast_sip_auth_vector *auths, struct ast_sip_auth **out);
2805
2806/*!
2807 * \brief Clean up retrieved auth structures from memory
2808 *
2809 * Call this function once you have completed operating on auths
2810 * retrieved from \ref ast_sip_retrieve_auths
2811 *
2812 * \param auths An array of auth object pointers to clean up
2813 * \param num_auths The number of auths in the array
2814 */
2815void ast_sip_cleanup_auths(struct ast_sip_auth *auths[], size_t num_auths);
2816
2818/*!
2819 * \brief Retrieve relevant SIP auth structures from sorcery as a vector
2820 *
2821 * \param auth_ids Vector of sorcery IDs of auth credentials to retrieve
2822 * \param[out] auth_objects A pointer ast_sip_auth_objects_vector to hold the objects
2823 *
2824 * \retval 0 Success
2825 * \retval -1 Number of auth objects found is less than the number of names supplied.
2826 *
2827 * \warning The number of auth objects retrieved may be less than the
2828 * number of auth ids supplied if auth objects couldn't be found for
2829 * some of them.
2830 *
2831 * \note Since the ref count on all auth objects returned has been
2832 * bumped, you must call ast_sip_cleanup_auth_objects_vector() to decrement
2833 * the ref count on all of the auth objects in the vector,
2834 * then call AST_VECTOR_FREE() on the vector itself.
2835 *
2836 */
2837int ast_sip_retrieve_auths_vector(const struct ast_sip_auth_vector *auth_ids,
2838 struct ast_sip_auth_objects_vector *auth_objects);
2839
2840/*!
2841 * \brief Clean up retrieved auth objects in vector
2842 *
2843 * Call this function once you have completed operating on auths
2844 * retrieved from \ref ast_sip_retrieve_auths_vector. All
2845 * auth objects will have their reference counts decremented and
2846 * the vector size will be reset to 0. You must still call
2847 * AST_VECTOR_FREE() on the vector itself.
2848 *
2849 * \param auth_objects A vector of auth structures to clean up
2850 */
2851#define ast_sip_cleanup_auth_objects_vector(auth_objects) AST_VECTOR_RESET(auth_objects, ao2_cleanup)
2852
2853/*!
2854 * \brief Checks if the given content type matches type/subtype.
2855 *
2856 * Compares the pjsip_media_type with the passed type and subtype and
2857 * returns the result of that comparison. The media type parameters are
2858 * ignored.
2859 *
2860 * \param content_type The pjsip_media_type structure to compare
2861 * \param type The media type to compare
2862 * \param subtype The media subtype to compare
2863 * \retval 0 No match
2864 * \retval -1 Match
2865 */
2866int ast_sip_is_content_type(pjsip_media_type *content_type, char *type, char *subtype);
2867
2868/*!
2869 * \brief Send a security event notification for when an invalid endpoint is requested
2870 *
2871 * \param name Name of the endpoint requested
2872 * \param rdata Received message
2873 */
2874void ast_sip_report_invalid_endpoint(const char *name, pjsip_rx_data *rdata);
2875
2876/*!
2877 * \brief Send a security event notification for when an ACL check fails
2878 *
2879 * \param endpoint Pointer to the endpoint in use
2880 * \param rdata Received message
2881 * \param name Name of the ACL
2882 */
2883void ast_sip_report_failed_acl(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, const char *name);
2884
2885/*!
2886 * \brief Send a security event notification for when a challenge response has failed
2887 *
2888 * \param endpoint Pointer to the endpoint in use
2889 * \param rdata Received message
2890 */
2891void ast_sip_report_auth_failed_challenge_response(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
2892
2893/*!
2894 * \brief Send a security event notification for when authentication succeeds
2895 *
2896 * \param endpoint Pointer to the endpoint in use
2897 * \param rdata Received message
2898 */
2899void ast_sip_report_auth_success(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
2900
2901/*!
2902 * \brief Send a security event notification for when an authentication challenge is sent
2903 *
2904 * \param endpoint Pointer to the endpoint in use
2905 * \param rdata Received message
2906 * \param tdata Sent message
2907 */
2908void ast_sip_report_auth_challenge_sent(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pjsip_tx_data *tdata);
2909
2910/*!
2911 * \brief Send a security event notification for when a request is not supported
2912 *
2913 * \param endpoint Pointer to the endpoint in use
2914 * \param rdata Received message
2915 * \param req_type the type of request
2916 */
2917void ast_sip_report_req_no_support(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata,
2918 const char* req_type);
2919
2920/*!
2921 * \brief Send a security event notification for when a memory limit is hit.
2922 *
2923 * \param endpoint Pointer to the endpoint in use
2924 * \param rdata Received message
2925 */
2926void ast_sip_report_mem_limit(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata);
2927
2928int ast_sip_add_global_request_header(const char *name, const char *value, int replace);
2929int ast_sip_add_global_response_header(const char *name, const char *value, int replace);
2930
2931/*!
2932 * \brief Retrieves the value associated with the given key.
2933 *
2934 * \param ht the hash table/dictionary to search
2935 * \param key the key to find
2936 *
2937 * \retval the value associated with the key, NULL otherwise.
2938 */
2939void *ast_sip_dict_get(void *ht, const char *key);
2940
2941/*!
2942 * \brief Using the dictionary stored in mod_data array at a given id,
2943 * retrieve the value associated with the given key.
2944 *
2945 * \param mod_data a module data array
2946 * \param id the mod_data array index
2947 * \param key the key to find
2948 *
2949 * \retval the value associated with the key, NULL otherwise.
2950 */
2951#define ast_sip_mod_data_get(mod_data, id, key) \
2952 ast_sip_dict_get(mod_data[id], key)
2953
2954/*!
2955 * \brief Set the value for the given key.
2956 *
2957 * Note - if the hash table does not exist one is created first, the key/value
2958 * pair is set, and the hash table returned.
2959 *
2960 * \param pool the pool to allocate memory in
2961 * \param ht the hash table/dictionary in which to store the key/value pair
2962 * \param key the key to associate a value with
2963 * \param val the value to associate with a key
2964 *
2965 * \retval the given, or newly created, hash table.
2966 */
2967void *ast_sip_dict_set(pj_pool_t* pool, void *ht,
2968 const char *key, void *val);
2969
2970/*!
2971 * \brief Utilizing a mod_data array for a given id, set the value
2972 * associated with the given key.
2973 *
2974 * For a given structure's mod_data array set the element indexed by id to
2975 * be a dictionary containing the key/val pair.
2976 *
2977 * \param pool a memory allocation pool
2978 * \param mod_data a module data array
2979 * \param id the mod_data array index
2980 * \param key the key to find
2981 * \param val the value to associate with a key
2982 */
2983#define ast_sip_mod_data_set(pool, mod_data, id, key, val) \
2984 mod_data[id] = ast_sip_dict_set(pool, mod_data[id], key, val)
2985
2986/*!
2987 * \brief For every contact on an AOR call the given 'on_contact' handler.
2988 *
2989 * \param aor the aor containing a list of contacts to iterate
2990 * \param on_contact callback on each contact on an AOR. The object
2991 * received by the callback will be a ast_sip_contact_wrapper structure.
2992 * \param arg user data passed to handler
2993 * \retval 0 Success, non-zero on failure
2994 */
2995int ast_sip_for_each_contact(const struct ast_sip_aor *aor,
2996 ao2_callback_fn on_contact, void *arg);
2997
2998/*!
2999 * \brief Handler used to convert a contact to a string.
3000 *
3001 * \param object the ast_sip_aor_contact_pair containing a list of contacts to iterate and the contact
3002 * \param arg user data passed to handler
3003 * \param flags
3004 * \retval 0 Success, non-zero on failure
3005 */
3006int ast_sip_contact_to_str(void *object, void *arg, int flags);
3007
3008/*!
3009 * \brief For every aor in the comma separated aors string call the
3010 * given 'on_aor' handler.
3011 *
3012 * \param aors a comma separated list of aors
3013 * \param on_aor callback for each aor
3014 * \param arg user data passed to handler
3015 * \retval 0 Success, non-zero on failure
3016 */
3017int ast_sip_for_each_aor(const char *aors, ao2_callback_fn on_aor, void *arg);
3018
3019/*!
3020 * \brief For every auth in the array call the given 'on_auth' handler.
3021 *
3022 * \param array an array of auths
3023 * \param on_auth callback for each auth
3024 * \param arg user data passed to handler
3025 * \retval 0 Success, non-zero on failure
3026 */
3028 ao2_callback_fn on_auth, void *arg);
3029
3030/*!
3031 * \brief Converts the given auth type to a string
3032 *
3033 * \param type the auth type to convert
3034 * \retval a string representative of the auth type
3035 */
3037
3038/*!
3039 * \brief Converts an auths array to a string of comma separated values
3040 *
3041 * \param auths an auth array
3042 * \param buf the string buffer to write the object data
3043 * \retval 0 Success, non-zero on failure
3044 */
3045int ast_sip_auths_to_str(const struct ast_sip_auth_vector *auths, char **buf);
3046
3047/*!
3048 * \brief AMI variable container
3049 */
3051 /*! Manager session */
3052 struct mansession *s;
3053 /*! Manager message */
3054 const struct message *m;
3055 /*! Manager Action ID */
3056 const char *action_id;
3057 /*! user specified argument data */
3058 void *arg;
3059 /*! count of objects */
3061};
3062
3063/*!
3064 * \brief Creates a string to store AMI event data in.
3065 *
3066 * \param event the event to set
3067 * \param ami AMI session and message container
3068 * \retval an initialized ast_str or NULL on error.
3069 */
3070struct ast_str *ast_sip_create_ami_event(const char *event,
3071 struct ast_sip_ami *ami);
3072
3073/*!
3074 * \brief An entity responsible formatting endpoint information.
3075 */
3077 /*!
3078 * \brief Callback used to format endpoint information over AMI.
3079 */
3080 int (*format_ami)(const struct ast_sip_endpoint *endpoint,
3081 struct ast_sip_ami *ami);
3083};
3084
3085/*!
3086 * \brief Register an endpoint formatter.
3087 *
3088 * \param obj the formatter to register
3089 */
3091
3092/*!
3093 * \brief Unregister an endpoint formatter.
3094 *
3095 * \param obj the formatter to unregister
3096 */
3098
3099/*!
3100 * \brief Converts a sorcery object to a string of object properties.
3101 *
3102 * \param obj the sorcery object to convert
3103 * \param buf the string buffer to write the object data
3104 * \retval 0 Success, non-zero on failure
3105 */
3106int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf);
3107
3108/*!
3109 * \brief Formats the endpoint and sends over AMI.
3110 *
3111 * \param endpoint the endpoint to format and send
3112 * \param ami AMI variable container
3113 * \param count the number of formatters operated on
3114 * \retval 0 Success, otherwise non-zero on error
3115 */
3117 struct ast_sip_ami *ami, int *count);
3118
3119/*!
3120 * \brief Formats the contact and sends over AMI.
3121 *
3122 * \param obj a pointer an ast_sip_contact_wrapper structure
3123 * \param arg a pointer to an ast_sip_ami structure
3124 * \param flags ignored
3125 * \retval 0 Success, otherwise non-zero on error
3126 */
3127int ast_sip_format_contact_ami(void *obj, void *arg, int flags);
3128
3129/*!
3130 * \brief Format auth details for AMI.
3131 *
3132 * \param auths an auth array
3133 * \param ami ami variable container
3134 * \retval 0 Success, non-zero on failure
3135 */
3136int ast_sip_format_auths_ami(const struct ast_sip_auth_vector *auths,
3137 struct ast_sip_ami *ami);
3138
3139/*!
3140 * \brief Retrieve the endpoint snapshot for an endpoint
3141 *
3142 * \param endpoint The endpoint whose snapshot is to be retrieved.
3143 * \retval The endpoint snapshot
3144 */
3146 const struct ast_sip_endpoint *endpoint);
3147
3148/*!
3149 * \brief Retrieve the device state for an endpoint.
3150 *
3151 * \param endpoint The endpoint whose state is to be retrieved.
3152 * \retval The device state.
3153 */
3154const char *ast_sip_get_device_state(const struct ast_sip_endpoint *endpoint);
3155
3156/*!
3157 * \brief For every channel snapshot on an endpoint snapshot call the given
3158 * 'on_channel_snapshot' handler.
3159 *
3160 * \param endpoint_snapshot snapshot of an endpoint
3161 * \param on_channel_snapshot callback for each channel snapshot
3162 * \param arg user data passed to handler
3163 * \retval 0 Success, non-zero on failure
3164 */
3165int ast_sip_for_each_channel_snapshot(const struct ast_endpoint_snapshot *endpoint_snapshot,
3166 ao2_callback_fn on_channel_snapshot,
3167 void *arg);
3168
3169/*!
3170 * \brief For every channel snapshot on an endpoint all the given
3171 * 'on_channel_snapshot' handler.
3172 *
3173 * \param endpoint endpoint
3174 * \param on_channel_snapshot callback for each channel snapshot
3175 * \param arg user data passed to handler
3176 * \retval 0 Success, non-zero on failure
3177 */
3178int ast_sip_for_each_channel(const struct ast_sip_endpoint *endpoint,
3179 ao2_callback_fn on_channel_snapshot,
3180 void *arg);
3181
3183 /*! Top priority. Supplements with this priority are those that need to run before any others */
3185 /*! Channel creation priority.
3186 * chan_pjsip creates a channel at this priority. If your supplement depends on being run before
3187 * or after channel creation, then set your priority to be lower or higher than this value.
3188 */
3190 /*! Lowest priority. Supplements with this priority should be run after all other supplements */
3192};
3193
3194/*!
3195 * \brief A supplement to SIP message processing
3196 *
3197 * These can be registered by any module in order to add
3198 * processing to incoming and outgoing SIP out of dialog
3199 * requests and responses
3200 */
3202 /*! Method on which to call the callbacks. If NULL, call on all methods */
3203 const char *method;
3204 /*! Priority for this supplement. Lower numbers are visited before higher numbers */
3206 /*!
3207 * \brief Called on incoming SIP request
3208 * This method can indicate a failure in processing in its return. If there
3209 * is a failure, it is required that this method sends a response to the request.
3210 * This method is always called from a SIP servant thread.
3211 *
3212 * \note
3213 * The following PJSIP methods will not work properly:
3214 * pjsip_rdata_get_dlg()
3215 * pjsip_rdata_get_tsx()
3216 * The reason is that the rdata passed into this function is a cloned rdata structure,
3217 * and its module data is not copied during the cloning operation.
3218 * If you need to get the dialog, you can get it via session->inv_session->dlg.
3219 *
3220 * \note
3221 * There is no guarantee that a channel will be present on the session when this is called.
3222 */
3223 int (*incoming_request)(struct ast_sip_endpoint *endpoint, struct pjsip_rx_data *rdata);
3224 /*!
3225 * \brief Called on an incoming SIP response
3226 * This method is always called from a SIP servant thread.
3227 *
3228 * \note
3229 * The following PJSIP methods will not work properly:
3230 * pjsip_rdata_get_dlg()
3231 * pjsip_rdata_get_tsx()
3232 * The reason is that the rdata passed into this function is a cloned rdata structure,
3233 * and its module data is not copied during the cloning operation.
3234 * If you need to get the dialog, you can get it via session->inv_session->dlg.
3235 *
3236 * \note
3237 * There is no guarantee that a channel will be present on the session when this is called.
3238 */
3239 void (*incoming_response)(struct ast_sip_endpoint *endpoint, struct pjsip_rx_data *rdata);
3240 /*!
3241 * \brief Called on an outgoing SIP request
3242 * This method is always called from a SIP servant thread.
3243 */
3244 void (*outgoing_request)(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, struct pjsip_tx_data *tdata);
3245 /*!
3246 * \brief Called on an outgoing SIP response
3247 * This method is always called from a SIP servant thread.
3248 */
3249 void (*outgoing_response)(struct ast_sip_endpoint *endpoint, struct ast_sip_contact *contact, struct pjsip_tx_data *tdata);
3250 /*! Next item in the list */
3252};
3253
3254/*!
3255 * \brief Register a supplement to SIP out of dialog processing
3256 *
3257 * This allows for someone to insert themselves in the processing of out
3258 * of dialog SIP requests and responses. This, for example could allow for
3259 * a module to set channel data based on headers in an incoming message.
3260 * Similarly, a module could reject an incoming request if desired.
3261 *
3262 * \param supplement The supplement to register
3263 */
3264void ast_sip_register_supplement(struct ast_sip_supplement *supplement);
3265
3266/*!
3267 * \brief Unregister a an supplement to SIP out of dialog processing
3268 *
3269 * \param supplement The supplement to unregister
3270 */
3271void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement);
3272
3273/*!
3274 * \brief Retrieve the global MWI taskprocessor high water alert trigger level.
3275 *
3276 * \since 13.12.0
3277 *
3278 * \retval the system MWI taskprocessor high water alert trigger level
3279 */
3280unsigned int ast_sip_get_mwi_tps_queue_high(void);
3281
3282/*!
3283 * \brief Retrieve the global MWI taskprocessor low water clear alert level.
3284 *
3285 * \since 13.12.0
3286 *
3287 * \retval the system MWI taskprocessor low water clear alert level
3288 */
3290
3291/*!
3292 * \brief Retrieve the global setting 'disable sending unsolicited mwi on startup'.
3293 * \since 13.12.0
3294 *
3295 * \retval non zero if disable.
3296 */
3298
3299/*!
3300 * \brief Retrieve the global setting 'allow_sending_180_after_183'.
3301 *
3302 * \retval non zero if disable.
3303 */
3305
3306/*!
3307 * \brief Retrieve the global setting 'use_callerid_contact'.
3308 * \since 13.24.0
3309 *
3310 * \retval non zero if CALLERID(num) is to be used as the default username in the contact
3311 */
3312unsigned int ast_sip_get_use_callerid_contact(void);
3313
3314/*!
3315 * \brief Retrieve the global setting 'norefersub'.
3316 *
3317 * \retval non zero if norefersub is to be sent in "Supported" Headers
3318 */
3319unsigned int ast_sip_get_norefersub(void);
3320
3321/*!
3322 * \brief Retrieve the global setting 'ignore_uri_user_options'.
3323 * \since 13.12.0
3324 *
3325 * \retval non zero if ignore the user field options.
3326 */
3327unsigned int ast_sip_get_ignore_uri_user_options(void);
3328
3329/*!
3330 * \brief Retrieve the global setting 'send_contact_status_on_update_registration'.
3331 * \since 16.2.0
3332 *
3333 * \retval non zero if need to send AMI ContactStatus event when a contact is updated.
3334 */
3336
3337
3338/*!
3339 * \brief Truncate the URI user field options string if enabled.
3340 * \since 13.12.0
3341 *
3342 * \param str URI user field string to truncate if enabled
3343 *
3344 * \details
3345 * We need to be able to handle URI's looking like
3346 * "sip:1235557890;phone-context=national@x.x.x.x;user=phone"
3347 *
3348 * Where the URI user field is:
3349 * "1235557890;phone-context=national"
3350 *
3351 * When truncated the string will become:
3352 * "1235557890"
3353 */
3354#define AST_SIP_USER_OPTIONS_TRUNCATE_CHECK(str) \
3355 do { \
3356 char *__semi = strchr((str), ';'); \
3357 if (__semi && ast_sip_get_ignore_uri_user_options()) { \
3358 *__semi = '\0'; \
3359 } \
3360 } while (0)
3361
3362/*!
3363 * \brief Retrieve the system debug setting (yes|no|host).
3364 *
3365 * \note returned string needs to be de-allocated by caller.
3366 *
3367 * \retval the system debug setting.
3368 */
3369char *ast_sip_get_debug(void);
3370
3371/*!
3372 * \brief Retrieve the global regcontext setting.
3373 *
3374 * \since 13.8.0
3375 *
3376 * \note returned string needs to be de-allocated by caller.
3377 *
3378 * \retval the global regcontext setting
3379 */
3380char *ast_sip_get_regcontext(void);
3381
3382/*!
3383 * \brief Retrieve the global endpoint_identifier_order setting.
3384 *
3385 * Specifies the order by which endpoint identifiers should be regarded.
3386 *
3387 * \retval the global endpoint_identifier_order value
3388 */
3390
3391/*!
3392 * \brief Retrieve the default voicemail extension.
3393 * \since 13.9.0
3394 *
3395 * \note returned string needs to be de-allocated by caller.
3396 *
3397 * \retval the default voicemail extension
3398 */
3400
3401/*!
3402 * \brief Retrieve the global default realm.
3403 *
3404 * This is the value placed in outbound challenges' realm if there
3405 * is no better option (such as an auth-configured realm).
3406 *
3407 * \param[out] realm The default realm
3408 * \param size The buffer size of realm
3409 */
3410void ast_sip_get_default_realm(char *realm, size_t size);
3411
3412/*!
3413 * \brief Retrieve the global default from user.
3414 *
3415 * This is the value placed in outbound requests' From header if there
3416 * is no better option (such as an endpoint-configured from_user or
3417 * caller ID number).
3418 *
3419 * \param[out] from_user The default from user
3420 * \param size The buffer size of from_user
3421 */
3422void ast_sip_get_default_from_user(char *from_user, size_t size);
3423
3424/*!
3425 * \brief Retrieve the system keep alive interval setting.
3426 *
3427 * \retval the keep alive interval.
3428 */
3429unsigned int ast_sip_get_keep_alive_interval(void);
3430
3431/*!
3432 * \brief Retrieve the system contact expiration check interval setting.
3433 *
3434 * \retval the contact expiration check interval.
3435 */
3437
3438/*!
3439 * \brief Retrieve the system setting 'disable multi domain'.
3440 * \since 13.9.0
3441 *
3442 * \retval non zero if disable multi domain.
3443 */
3444unsigned int ast_sip_get_disable_multi_domain(void);
3445
3446/*!
3447 * \brief Retrieve the system max initial qualify time.
3448 *
3449 * \retval the maximum initial qualify time.
3450 */
3451unsigned int ast_sip_get_max_initial_qualify_time(void);
3452
3453/*!
3454 * \brief translate ast_sip_contact_status_type to character string.
3455 *
3456 * \retval the character string equivalent.
3457 */
3458
3461
3462/*!
3463 * \brief Set a request to use the next value in the list of resolved addresses.
3464 *
3465 * \param tdata the tx data from the original request
3466 * \retval 0 No more addresses to try
3467 * \retval 1 The request was successfully re-intialized
3468 */
3469int ast_sip_failover_request(pjsip_tx_data *tdata);
3470
3471/*!
3472 * \brief Retrieve the local host address in IP form
3473 *
3474 * \param af The address family to retrieve
3475 * \param addr A place to store the local host address
3476 *
3477 * \retval 0 success
3478 * \retval -1 failure
3479 *
3480 * \since 13.6.0
3481 */
3482int ast_sip_get_host_ip(int af, pj_sockaddr *addr);
3483
3484/*!
3485 * \brief Retrieve the local host address in string form
3486 *
3487 * \param af The address family to retrieve
3488 *
3489 * \retval non-NULL success
3490 * \retval NULL failure
3491 *
3492 * \since 13.6.0
3493 *
3494 * \note An empty string may be returned if the address family is valid but no local address exists
3495 */
3496const char *ast_sip_get_host_ip_string(int af);
3497
3498/*!
3499 * \brief Return the size of the SIP threadpool's task queue
3500 * \since 13.7.0
3501 */
3503
3504/*!
3505 * \brief Retrieve the SIP threadpool object
3506 */
3508
3509/*!
3510 * \brief Retrieve transport state
3511 * \since 13.7.1
3512 *
3513 * \param transport_id
3514 * \retval transport_state
3515 *
3516 * \note ao2_cleanup(...) or ao2_ref(..., -1) must be called on the returned object
3517 */
3518struct ast_sip_transport_state *ast_sip_get_transport_state(const char *transport_id);
3519
3520/*!
3521 * \brief Return the SIP URI of the Contact header
3522 *
3523 * \param tdata
3524 * \retval Pointer to SIP URI of Contact
3525 * \retval NULL if Contact header not found or not a SIP(S) URI
3526 *
3527 * \note Do not free the returned object.
3528 */
3529pjsip_sip_uri *ast_sip_get_contact_sip_uri(pjsip_tx_data *tdata);
3530
3531/*!
3532 * \brief Returns the transport state currently in use based on request transport details
3533 *
3534 * \param details
3535 * \retval transport_state
3536 *
3537 * \note ao2_cleanup(...) or ao2_ref(..., -1) must be called on the returned object
3538 */
3540
3541/*!
3542 * \brief Sets request transport details based on tdata
3543 *
3544 * \param details pre-allocated request transport details to set
3545 * \param tdata
3546 * \param use_ipv6 if non-zero, ipv6 transports will be considered
3547 * \retval 0 success
3548 * \retval -1 failure
3549 */
3550int ast_sip_set_request_transport_details(struct ast_sip_request_transport_details *details, pjsip_tx_data *tdata, int use_ipv6);
3551
3552/*!
3553 * \brief Replace domain and port of SIP URI to point to (external) signaling address of this Asterisk instance
3554 *
3555 * \param uri
3556 * \param tdata
3557 *
3558 * \retval 0 success
3559 * \retval -1 failure
3560 *
3561 * \note Uses domain and port in Contact header if it exists, otherwise the local URI of the dialog is used if the
3562 * message is sent within the context of a dialog. Further, NAT settings are considered - i.e. if the target
3563 * is not in the localnet, the external_signaling_address and port are used.
3564 */
3565int ast_sip_rewrite_uri_to_local(pjsip_sip_uri *uri, pjsip_tx_data *tdata);
3566
3567/*!
3568 * \brief Retrieves all transport states
3569 * \since 13.7.1
3570 *
3571 * \retval ao2_container
3572 *
3573 * \note ao2_cleanup(...) or ao2_ref(..., -1) must be called on the returned object
3574 */
3576
3577/*!
3578 * \brief Sets pjsip_tpselector from ast_sip_transport
3579 * \since 13.8.0
3580 *
3581 * \param transport The transport to be used
3582 * \param selector The selector to be populated
3583 * \retval 0 success
3584 * \retval -1 failure
3585 *
3586 * \note The transport selector must be unreffed using ast_sip_tpselector_unref
3587 */
3588int ast_sip_set_tpselector_from_transport(const struct ast_sip_transport *transport, pjsip_tpselector *selector);
3589
3590/*!
3591 * \brief Sets pjsip_tpselector from ast_sip_transport
3592 * \since 13.8.0
3593 *
3594 * \param transport_name The name of the transport to be used
3595 * \param selector The selector to be populated
3596 * \retval 0 success
3597 * \retval -1 failure
3598 *
3599 * \note The transport selector must be unreffed using ast_sip_tpselector_unref
3600 */
3601int ast_sip_set_tpselector_from_transport_name(const char *transport_name, pjsip_tpselector *selector);
3602
3603/*!
3604 * \brief Unreference a pjsip_tpselector
3605 * \since 17.0.0
3606 *
3607 * \param selector The selector to be unreffed
3608 */
3609void ast_sip_tpselector_unref(pjsip_tpselector *selector);
3610
3611/*!
3612 * \brief Sets the PJSIP transport on a child transport
3613 * \since 17.0.0
3614 *
3615 * \param transport_name The name of the transport to be updated
3616 * \param transport The PJSIP transport
3617 * \retval 0 success
3618 * \retval -1 failure
3619 */
3620int ast_sip_transport_state_set_transport(const char *transport_name, pjsip_transport *transport);
3621
3622/*!
3623 * \brief Sets the P-Preferred-Identity on a child transport
3624 * \since 17.0.0
3625 *
3626 * \param transport_name The name of the transport to be set on
3627 * \param identity The P-Preferred-Identity to use on requests on this transport
3628 * \retval 0 success
3629 * \retval -1 failure
3630 */
3631int ast_sip_transport_state_set_preferred_identity(const char *transport_name, const char *identity);
3632
3633/*!
3634 * \brief Sets the service routes on a child transport
3635 * \since 17.0.0
3636 *
3637 * \param transport_name The name of the transport to be set on
3638 * \param service_routes A vector of service routes
3639 * \retval 0 success
3640 * \retval -1 failure
3641 *
3642 * \note This assumes ownership of the service routes in both success and failure scenarios
3643 */
3644int ast_sip_transport_state_set_service_routes(const char *transport_name, struct ast_sip_service_route_vector *service_routes);
3645
3646/*!
3647 * \brief Apply the configuration for a transport to an outgoing message
3648 * \since 17.0.0
3649 *
3650 * \param transport_name The name of the transport to apply configuration from
3651 * \param tdata The SIP message
3652 */
3653void ast_sip_message_apply_transport(const char *transport_name, pjsip_tx_data *tdata);
3654
3655/*!
3656 * \brief Allocate a vector of service routes
3657 * \since 17.0.0
3658 *
3659 * \retval non-NULL success
3660 * \retval NULL failure
3661 */
3663
3664/*!
3665 * \brief Destroy a vector of service routes
3666 * \since 17.0.0
3667 *
3668 * \param service_routes A vector of service routes
3669 */
3671
3672/*!
3673 * \brief Set the ID for a connected line update
3674 *
3675 * \retval -1 on failure, 0 on success
3676 */
3677int ast_sip_set_id_connected_line(struct pjsip_rx_data *rdata, struct ast_party_id *id);
3678
3679/*!
3680 * \brief Set the ID from an INVITE
3681 *
3682 * \param rdata
3683 * \param id ID structure to fill
3684 * \param default_id Default ID structure with data to use (for non-trusted endpoints)
3685 * \param trust_inbound Whether or not the endpoint is trusted (controls whether PAI or RPID can be used)
3686 *
3687 * \retval -1 on failure, 0 on success
3688 */
3689int ast_sip_set_id_from_invite(struct pjsip_rx_data *rdata, struct ast_party_id *id, struct ast_party_id *default_id, int trust_inbound);
3690
3691/*!
3692 * \brief Set name and number information on an identity header.
3693 *
3694 * \param pool Memory pool to use for string duplication
3695 * \param id_hdr A From, P-Asserted-Identity, or Remote-Party-ID header to modify
3696 * \param id The identity information to apply to the header
3697 */
3698void ast_sip_modify_id_header(pj_pool_t *pool, pjsip_fromto_hdr *id_hdr,
3699 const struct ast_party_id *id);
3700
3701/*!
3702 * \brief Retrieves an endpoint and URI from the "to" string.
3703 *
3704 * This URI is used as the Request URI.
3705 *
3706 * Expects the given 'to' to be in one of the following formats:
3707 * Why we allow so many is a mystery.
3708 *
3709 * Basic:
3710 *
3711 * endpoint : We'll get URI from the default aor/contact
3712 * endpoint/aor : We'll get the URI from the specific aor/contact
3713 * endpoint@domain : We toss the domain part and just use the endpoint
3714 *
3715 * These all use the endpoint and specified URI:
3716 * \verbatim
3717 endpoint/<sip[s]:host>
3718 endpoint/<sip[s]:user@host>
3719 endpoint/"Bob" <sip[s]:host>
3720 endpoint/"Bob" <sip[s]:user@host>
3721 endpoint/sip[s]:host
3722 endpoint/sip[s]:user@host
3723 endpoint/host
3724 endpoint/user@host
3725 \endverbatim
3726 *
3727 * These all use the default endpoint and specified URI:
3728 * \verbatim
3729 <sip[s]:host>
3730 <sip[s]:user@host>
3731 "Bob" <sip[s]:host>
3732 "Bob" <sip[s]:user@host>
3733 sip[s]:host
3734 sip[s]:user@host
3735 \endverbatim
3736 *
3737 * These use the default endpoint and specified host:
3738 * \verbatim
3739 host
3740 user@host
3741 \endverbatim
3742 *
3743 * This form is similar to a dialstring:
3744 * \verbatim
3745 PJSIP/user@endpoint
3746 \endverbatim
3747 *
3748 * In this case, the user will be added to the endpoint contact's URI.
3749 * If the contact URI already has a user, it will be replaced.
3750 *
3751 * The ones that have the sip[s] scheme are the easiest to parse.
3752 * The rest all have some issue.
3753 *
3754 * endpoint vs host : We have to test for endpoint first
3755 * endpoint/aor vs endpoint/host : We have to test for aor first
3756 * What if there's an aor with the same
3757 * name as the host?
3758 * endpoint@domain vs user@host : We have to test for endpoint first.
3759 * What if there's an endpoint with the
3760 * same name as the user?
3761 *
3762 * \param to 'To' field with possible endpoint
3763 * \param get_default_outbound If nonzero, try to retrieve the default
3764 * outbound endpoint if no endpoint was found.
3765 * Otherwise, return NULL if no endpoint was found.
3766 * \param uri Pointer to a char* which will be set to the URI.
3767 * Always must be ast_free'd by the caller - even if the return value is NULL!
3768 *
3769 * \note The logic below could probably be condensed but then it wouldn't be
3770 * as clear.
3771 */
3772struct ast_sip_endpoint *ast_sip_get_endpoint(const char *to, int get_default_outbound, char **uri);
3773
3774/*!
3775 * \brief Replace the To URI in the tdata with the supplied one
3776 *
3777 * \param tdata the outbound message data structure
3778 * \param to URI to replace the To URI with. Must be a valid SIP URI.
3779 *
3780 * \retval 0: success, -1: failure
3781 */
3782int ast_sip_update_to_uri(pjsip_tx_data *tdata, const char *to);
3783
3784/*!
3785 * \brief Overwrite fields in the outbound 'From' header
3786 *
3787 * The outbound 'From' header is created/added in ast_sip_create_request with
3788 * default data. If available that data may be info specified in the 'from_user'
3789 * and 'from_domain' options found on the endpoint. That information will be
3790 * overwritten with data in the given 'from' parameter.
3791 *
3792 * \param tdata the outbound message data structure
3793 * \param from info to copy into the header.
3794 * Can be either a SIP URI, or in the format user[@domain]
3795 *
3796 * \retval 0: success, -1: failure
3797 */
3798int ast_sip_update_from(pjsip_tx_data *tdata, char *from);
3799
3800/*!
3801 * \brief Retrieve the unidentified request security event thresholds
3802 * \since 13.8.0
3803 *
3804 * \param count The maximum number of unidentified requests per source ip to accumulate before emitting a security event
3805 * \param period The period in seconds over which to accumulate unidentified requests
3806 * \param prune_interval The interval in seconds at which expired entries will be pruned
3807 */
3808void ast_sip_get_unidentified_request_thresholds(unsigned int *count, unsigned int *period,
3809 unsigned int *prune_interval);
3810
3811/*!
3812 * \brief Get the transport name from an endpoint or request uri
3813 * \since 13.15.0
3814 *
3815 * \param endpoint
3816 * \param sip_uri
3817 * \param buf Buffer to receive transport name
3818 * \param buf_len Buffer length
3819 *
3820 * \retval 0 Success
3821 * \retval -1 Failure
3822 *
3823 * \note
3824 * If endpoint->transport is not NULL, it is returned in buf.
3825 * Otherwise if sip_uri has an 'x-ast-txp' parameter AND the sip_uri host is
3826 * an ip4 or ip6 address, its value is returned,
3827 */
3828int ast_sip_get_transport_name(const struct ast_sip_endpoint *endpoint,
3829 pjsip_sip_uri *sip_uri, char *buf, size_t buf_len);
3830
3831/*!
3832 * \brief Sets pjsip_tpselector from an endpoint or uri
3833 * \since 13.15.0
3834 *
3835 * \param endpoint If endpoint->transport is set, it's used
3836 * \param sip_uri If sip_uri contains a x-ast-txp parameter, it's used
3837 * \param selector The selector to be populated
3838 *
3839 * \retval 0 success
3840 * \retval -1 failure
3841 */
3843 pjsip_sip_uri *sip_uri, pjsip_tpselector *selector);
3844
3845/*!
3846 * \brief Set the transport on a dialog
3847 * \since 13.15.0
3848 *
3849 * \param endpoint
3850 * \param dlg
3851 * \param selector (optional)
3852 *
3853 * \note
3854 * This API calls ast_sip_get_transport_name(endpoint, dlg->target) and if the result is
3855 * non-NULL, calls pjsip_dlg_set_transport. If 'selector' is non-NULL, it is updated with
3856 * the selector used.
3857 *
3858 * \note
3859 * It is the responsibility of the caller to unref the passed in selector if one is provided.
3860 */
3861int ast_sip_dlg_set_transport(const struct ast_sip_endpoint *endpoint, pjsip_dialog *dlg,
3862 pjsip_tpselector *selector);
3863
3864/*!
3865 * \brief Convert the DTMF mode enum value into a string
3866 * \since 13.18.0
3867 *
3868 * \param dtmf the dtmf mode
3869 * \param buf Buffer to receive dtmf mode string
3870 * \param buf_len Buffer length
3871 *
3872 * \retval 0 Success
3873 * \retval -1 Failure
3874 *
3875 */
3877 char *buf, size_t buf_len);
3878
3879/*!
3880 * \brief Convert the DTMF mode name into an enum
3881 * \since 13.18.0
3882 *
3883 * \param dtmf_mode dtmf mode as a string
3884 *
3885 * \retval >= 0 The enum value
3886 * \retval -1 Failure
3887 *
3888 */
3889int ast_sip_str_to_dtmf(const char *dtmf_mode);
3890
3891/*!
3892 * \brief Convert the call codec preference flags to a string
3893 * \since 18.0.0
3894 *
3895 * \param pref the call codec preference setting
3896 *
3897 * \returns a constant string with either the setting value or 'unknown'
3898 * \note Don't try to free the string!
3899 *
3900 */
3901const char *ast_sip_call_codec_pref_to_str(struct ast_flags pref);
3902
3903/*!
3904 * \brief Convert a call codec preference string to preference flags
3905 * \since 18.0.0
3906 *
3907 * \param pref A pointer to an ast_flags structure to receive the preference flags
3908 * \param pref_str The call codec preference setting string
3909 * \param is_outgoing Is for outgoing calls?
3910 *
3911 * \retval 0 The string was parsed successfully
3912 * \retval -1 The string option was invalid
3913 */
3914int ast_sip_call_codec_str_to_pref(struct ast_flags *pref, const char *pref_str, int is_outgoing);
3915
3916/*!
3917 * \brief Transport shutdown monitor callback.
3918 * \since 13.18.0
3919 *
3920 * \param data User data to know what to do when transport shuts down.
3921 *
3922 * \note The callback does not need to care that data is an ao2 object.
3923 */
3924typedef void (*ast_transport_monitor_shutdown_cb)(void *data);
3925
3926/*!
3927 * \brief Transport shutdown monitor data matcher
3928 * \since 13.20.0
3929 *
3930 * \param a User data to compare.
3931 * \param b User data to compare.
3932 *
3933 * \retval 1 The data objects match
3934 * \retval 0 The data objects don't match
3935 */
3936typedef int (*ast_transport_monitor_data_matcher)(void *a, void *b);
3937
3939 /*! \brief Successfully registered the transport monitor */
3941 /*! \brief Replaced the already existing transport monitor with new one. */
3943 /*!
3944 * \brief Transport not found to monitor.
3945 * \note Transport is either already shutdown or is not reliable.
3946 */
3948 /*! \brief Error while registering transport monitor. */
3950};
3951
3952/*!
3953 * \brief Register a reliable transport shutdown monitor callback.
3954 * \deprecated Replaced with ast_sip_transport_monitor_register_key().
3955 * \since 13.20.0
3956 *
3957 * \param transport Transport to monitor for shutdown.
3958 * \param cb Who to call when transport is shutdown.
3959 * \param ao2_data Data to pass with the callback.
3960 *
3961 * \note The data object passed will have its reference count automatically
3962 * incremented by this call and automatically decremented after the callback
3963 * runs or when the callback is unregistered.
3964 *
3965 * There is no checking for duplicate registrations.
3966 *
3967 * \return enum ast_transport_monitor_reg
3968 */
3970 ast_transport_monitor_shutdown_cb cb, void *ao2_data);
3971
3972/*!
3973 * \brief Register a reliable transport shutdown monitor callback.
3974 *
3975 * \param transport_key Key for the transport to monitor for shutdown.
3976 * Create the key with AST_SIP_MAKE_REMOTE_IPADDR_PORT_STR.
3977 * \param cb Who to call when transport is shutdown.
3978 * \param ao2_data Data to pass with the callback.
3979 *
3980 * \note The data object passed will have its reference count automatically
3981 * incremented by this call and automatically decremented after the callback
3982 * runs or when the callback is unregistered.
3983 *
3984 * There is no checking for duplicate registrations.
3985 *
3986 * \return enum ast_transport_monitor_reg
3987 */
3989 const char *transport_key, ast_transport_monitor_shutdown_cb cb,
3990 void *ao2_data);
3991
3992/*!
3993 * \brief Register a reliable transport shutdown monitor callback replacing any duplicate.
3994 * \deprecated Replaced with ast_sip_transport_monitor_register_replace_key().
3995 * \since 13.26.0
3996 * \since 16.3.0
3997 *
3998 * \param transport Transport to monitor for shutdown.
3999 * \param cb Who to call when transport is shutdown.
4000 * \param ao2_data Data to pass with the callback.
4001 * \param matches Matcher function that returns true if data matches a previously
4002 * registered data object
4003 *
4004 * \note The data object passed will have its reference count automatically
4005 * incremented by this call and automatically decremented after the callback
4006 * runs or when the callback is unregistered.
4007 *
4008 * This function checks for duplicates, and overwrites/replaces the old monitor
4009 * with the given one.
4010 *
4011 * \return enum ast_transport_monitor_reg
4012 */
4015
4016/*!
4017 * \brief Register a reliable transport shutdown monitor callback replacing any duplicate.
4018 *
4019 * \param transport_key Key for the transport to monitor for shutdown.
4020 * Create the key with AST_SIP_MAKE_REMOTE_IPADDR_PORT_STR.
4021 * \param cb Who to call when transport is shutdown.
4022 * \param ao2_data Data to pass with the callback.
4023 * \param matches Matcher function that returns true if data matches a previously
4024 * registered data object
4025 *
4026 * \note The data object passed will have its reference count automatically
4027 * incremented by this call and automatically decremented after the callback
4028 * runs or when the callback is unregistered.
4029 *
4030 * This function checks for duplicates, and overwrites/replaces the old monitor
4031 * with the given one.
4032 *
4033 * \return enum ast_transport_monitor_reg
4034 */
4036 const char *transport_key, ast_transport_monitor_shutdown_cb cb,
4037 void *ao2_data, ast_transport_monitor_data_matcher matches);
4038
4039/*!
4040 * \brief Unregister a reliable transport shutdown monitor
4041 * \deprecated Replaced with ast_sip_transport_monitor_unregister_key().
4042 * \since 13.20.0
4043 *
4044 * \param transport Transport to monitor for shutdown.
4045 * \param cb The callback that was used for the original register.
4046 * \param data Data to pass to the matcher. May be NULL and does NOT need to be an ao2 object.
4047 * If NULL, all monitors with the provided callback are unregistered.
4048 * \param matches Matcher function that returns true if data matches the previously
4049 * registered data object. If NULL, a simple pointer comparison is done.
4050 *
4051 * \note The data object passed into the original register will have its reference count
4052 * automatically decremented.
4053 */
4056
4057/*!
4058 * \brief Unregister a reliable transport shutdown monitor
4059 *
4060 * \param transport_key Key for the transport to monitor for shutdown.
4061 * Create the key with AST_SIP_MAKE_REMOTE_IPADDR_PORT_STR.
4062 * \param cb The callback that was used for the original register.
4063 * \param data Data to pass to the matcher. May be NULL and does NOT need to be an ao2 object.
4064 * If NULL, all monitors with the provided callback are unregistered.
4065 * \param matches Matcher function that returns true if data matches the previously
4066 * registered data object. If NULL, a simple pointer comparison is done.
4067 *
4068 * \note The data object passed into the original register will have its reference count
4069 * automatically decremented.
4070 */
4071void ast_sip_transport_monitor_unregister_key(const char *transport_key,
4073
4074/*!
4075 * \brief Unregister a transport shutdown monitor from all reliable transports
4076 * \since 13.20.0
4077 *
4078 * \param cb The callback that was used for the original register.
4079 * \param data Data to pass to the matcher. May be NULL and does NOT need to be an ao2 object.
4080 * If NULL, all monitors with the provided callback are unregistered.
4081 * \param matches Matcher function that returns true if ao2_data matches the previously
4082 * registered data object. If NULL, a simple pointer comparison is done.
4083 *
4084 * \note The data object passed into the original register will have its reference count
4085 * automatically decremented.
4086 */
4088 void *data, ast_transport_monitor_data_matcher matches);
4089
4090/*! Transport state notification registration element. */
4092 /*! PJPROJECT transport state notification callback */
4093 pjsip_tp_state_callback cb;
4095};
4096
4097/*!
4098 * \brief Register a transport state notification callback element.
4099 * \since 13.18.0
4100 *
4101 * \param element What we are registering.
4102 */
4104
4105/*!
4106 * \brief Unregister a transport state notification callback element.
4107 * \since 13.18.0
4108 *
4109 * \param element What we are unregistering.
4110 */
4112
4113/*!
4114 * \brief Check whether a pjsip_uri is SIP/SIPS or not
4115 * \since 16.28.0
4116 *
4117 * \param uri The pjsip_uri to check
4118 *
4119 * \retval 1 if true
4120 * \retval 0 if false
4121 */
4122int ast_sip_is_uri_sip_sips(pjsip_uri *uri);
4123
4124/*!
4125 * \brief Check whether a pjsip_uri is allowed or not
4126 * \since 16.28.0
4127 *
4128 * \param uri The pjsip_uri to check
4129 *
4130 * \retval 1 if allowed
4131 * \retval 0 if not allowed
4132 */
4133int ast_sip_is_allowed_uri(pjsip_uri *uri);
4134
4135/*!
4136 * \brief Get the user portion of the pjsip_uri
4137 * \since 16.28.0
4138 *
4139 * \param uri The pjsip_uri to get the user from
4140 *
4141 * \note This function will check what kind of URI it receives and return
4142 * the user based off of that
4143 *
4144 * \return User string or empty string if not present
4145 */
4146const pj_str_t *ast_sip_pjsip_uri_get_username(pjsip_uri *uri);
4147
4148/*!
4149 * \brief Get the host portion of the pjsip_uri
4150 * \since 16.28.0
4151 *
4152 * \param uri The pjsip_uri to get the host from
4153 *
4154 * \note This function will check what kind of URI it receives and return
4155 * the host based off of that
4156 *
4157 * \return Host string or empty string if not present
4158 */
4159const pj_str_t *ast_sip_pjsip_uri_get_hostname(pjsip_uri *uri);
4160
4161/*!
4162 * \brief Find an 'other' SIP/SIPS URI parameter by name
4163 * \since 16.28.0
4164 *
4165 * A convenience function to find a named parameter from a SIP/SIPS URI. This
4166 * function will not find the following standard SIP/SIPS URI parameters which
4167 * are stored separately by PJSIP:
4168 *
4169 * \li `user`
4170 * \li `method`
4171 * \li `transport`
4172 * \li `ttl`
4173 * \li `lr`
4174 * \li `maddr`
4175 *
4176 * \param uri The pjsip_uri to get the parameter from
4177 * \param param_str The name of the parameter to find
4178 *
4179 * \note This function will check what kind of URI it receives and return
4180 * the parameter based off of that
4181 *
4182 * \return Find parameter or NULL if not present
4183 */
4184struct pjsip_param *ast_sip_pjsip_uri_get_other_param(pjsip_uri *uri, const pj_str_t *param_str);
4185
4186/*!
4187 * \brief Retrieve the system setting 'all_codecs_on_empty_reinvite'.
4188 *
4189 * \retval non zero if we should return all codecs on empty re-INVITE
4190 */
4192
4193
4194/*!
4195 * \brief Convert SIP hangup causes to Asterisk hangup causes
4196 *
4197 * \param cause SIP cause
4198 *
4199 * \retval matched cause code from causes.h
4200 */
4201const int ast_sip_hangup_sip2cause(int cause);
4202
4203/*!
4204 * \brief Convert name to SIP response code
4205 *
4206 * \param name SIP response code name matching one of the
4207 * enum names defined in "enum pjsip_status_code"
4208 * defined in sip_msg.h. May be specified with or
4209 * without the PJSIP_SC_ prefix.
4210 *
4211 * \retval SIP response code
4212 * \retval -1 if matching code not found
4213 */
4214int ast_sip_str2rc(const char *name);
4215
4216#endif /* _RES_PJSIP_H */
jack_status_t status
Definition: app_jack.c:146
const char * str
Definition: app_jack.c:147
int() ao2_callback_fn(void *obj, void *arg, int flags)
Type of a generic callback function.
Definition: astobj2.h:1226
static const char type[]
Definition: chan_ooh323.c:109
General Asterisk PBX channel definitions.
unsigned long long ast_group_t
Definition: channel.h:215
#define AST_MAX_CONTEXT
Definition: channel.h:135
#define attribute_sentinel
Definition: compiler.h:65
Background DNS update manager.
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
Endpoint abstractions.
ast_endpoint_state
Valid states for an endpoint.
Definition: endpoints.h:51
char * address
Definition: f2c.h:59
static const char name[]
Definition: format_mp3.c:68
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:888
static int array(struct ast_channel *chan, const char *cmd, char *var, const char *value)
struct ast_sip_endpoint * ast_sip_dialog_get_endpoint(pjsip_dialog *dlg)
Get the endpoint associated with this dialog.
int(* ast_sip_task)(void *user_data)
Definition: res_pjsip.h:1873
int ast_sip_sched_task_get_times2(struct ast_sip_sched_task *schtd, struct timeval *when_queued, struct timeval *last_start, struct timeval *last_end, int *interval, int *time_left, struct timeval *next_start)
Gets the queued, last start, last_end, time left, interval, next run.
struct ast_taskprocessor * ast_sip_get_distributor_serializer(pjsip_rx_data *rdata)
Determine the distributor serializer for the SIP message.
ast_sip_scheduler_task_flags
Task flags for the res_pjsip scheduler.
Definition: res_pjsip.h:2067
int ast_sip_sched_task_cancel_by_name(const char *name)
Cancels the next invocation of a task by name.
int ast_sip_push_task(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Pushes a task to SIP servants.
Definition: res_pjsip.c:2099
struct ast_taskprocessor * ast_sip_create_serializer(const char *name)
Create a new serializer for SIP tasks.
Definition: res_pjsip.c:2094
struct ast_taskprocessor * ast_sip_create_serializer_group(const char *name, struct ast_serializer_shutdown_group *shutdown_group)
Create a new serializer for SIP tasks.
Definition: res_pjsip.c:2089
struct ast_sip_sched_task * ast_sip_schedule_task(struct ast_taskprocessor *serializer, int interval, ast_sip_task sip_task, const char *name, void *task_data, enum ast_sip_scheduler_task_flags flags)
Schedule a task to run in the res_pjsip thread pool.
void ast_sip_dialog_set_endpoint(pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint)
Set an endpoint on a SIP dialog so in-dialog requests do not undergo endpoint lookup.
int ast_sip_sched_task_cancel(struct ast_sip_sched_task *schtd)
Cancels the next invocation of a task.
int ast_sip_sched_is_task_running(struct ast_sip_sched_task *schtd)
Checks if the task is currently running.
int ast_sip_thread_is_servant(void)
Determine if the current thread is a SIP servant thread.
Definition: res_pjsip.c:2310
int ast_sip_sched_task_get_name(struct ast_sip_sched_task *schtd, char *name, size_t maxlen)
Gets the task name.
int ast_sip_sched_task_get_next_run(struct ast_sip_sched_task *schtd)
Gets the number of milliseconds until the next invocation.
void ast_sip_dialog_set_serializer(pjsip_dialog *dlg, struct ast_taskprocessor *serializer)
Set a serializer on a SIP dialog so requests and responses are automatically serialized.
int ast_sip_push_task_synchronous(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to SIP servants and wait for it to complete.
Definition: res_pjsip.c:2174
int ast_sip_sched_task_get_times(struct ast_sip_sched_task *schtd, struct timeval *when_queued, struct timeval *last_start, struct timeval *last_end)
Gets the last start and end times of the task.
int ast_sip_push_task_wait_servant(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to SIP servants and wait for it to complete.
Definition: res_pjsip.c:2165
int ast_sip_sched_task_get_next_run_by_name(const char *name)
Gets the number of milliseconds until the next invocation.
int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to the serializer and wait for it to complete.
Definition: res_pjsip.c:2179
int ast_sip_sched_is_task_running_by_name(const char *name)
Checks if the task is currently running.
int ast_sip_sched_task_get_times_by_name2(const char *name, struct timeval *when_queued, struct timeval *last_start, struct timeval *last_end, int *interval, int *time_left, struct timeval *next_start)
Gets the queued, last start, last_end, time left, interval, next run by task name.
int ast_sip_sched_task_get_times_by_name(const char *name, struct timeval *when_queued, struct timeval *last_start, struct timeval *last_end)
Gets the last start and end times of the task by name.
@ AST_SIP_SCHED_TASK_ONESHOT
Definition: res_pjsip.h:2090
@ AST_SIP_SCHED_TASK_DELAY
The next invocation of the task is at last finish + interval.
Definition: res_pjsip.h:2122
@ AST_SIP_SCHED_TASK_TRACK
The scheduled task's events are tracked in the debug log.
Definition: res_pjsip.h:2129
@ AST_SIP_SCHED_TASK_DATA_NOT_AO2
Definition: res_pjsip.h:2095
@ AST_SIP_SCHED_TASK_DEFAULTS
Definition: res_pjsip.h:2071
@ AST_SIP_SCHED_TASK_FIXED
Definition: res_pjsip.h:2078
@ AST_SIP_SCHED_TASK_PERIODIC
The task is scheduled at multiples of interval.
Definition: res_pjsip.h:2117
@ AST_SIP_SCHED_TASK_DATA_AO2
Definition: res_pjsip.h:2101
@ AST_SIP_SCHED_TASK_DATA_FREE
Definition: res_pjsip.h:2111
@ AST_SIP_SCHED_TASK_DATA_NO_CLEANUP
Definition: res_pjsip.h:2106
@ AST_SIP_SCHED_TASK_VARIABLE
Definition: res_pjsip.h:2084
A set of macros to manage forward-linked lists.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:410
#define AST_RWLIST_ENTRY
Definition: linkedlists.h:415
Network socket handling.
ast_transport
Definition: netsock2.h:59
static struct ast_serializer_shutdown_group * shutdown_group
Shutdown group for options serializers.
const char * method
Definition: res_pjsip.c:1279
ast_sip_security_mechanism_type
The security mechanism type.
Definition: res_pjsip.h:361
@ AST_SIP_SECURITY_MECH_DTLS_SRTP
Definition: res_pjsip.h:368
@ AST_SIP_SECURITY_MECH_SDES_SRTP
Definition: res_pjsip.h:366
@ AST_SIP_SECURITY_MECH_MSRP_TLS
Definition: res_pjsip.h:364
@ AST_SIP_SECURITY_MECH_NONE
Definition: res_pjsip.h:362
struct ast_sip_auth * ast_sip_get_artificial_auth(void)
Retrieves a reference to the artificial auth.
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)
Set up outbound authentication on a SIP dialog.
void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement)
Unregister a an supplement to SIP out of dialog processing.
Definition: res_pjsip.c:1476
struct ast_sip_endpoint * ast_sip_get_endpoint(const char *to, int get_default_outbound, char **uri)
Retrieves an endpoint and URI from the "to" string.
Definition: res_pjsip.c:3249
void ast_sip_add_usereqphone(const struct ast_sip_endpoint *endpoint, pj_pool_t *pool, pjsip_uri *uri)
Add 'user=phone' parameter to URI if enabled and user is a phone number.
Definition: res_pjsip.c:930
unsigned int ast_sip_get_norefersub(void)
Retrieve the global setting 'norefersub'.
struct pjsip_param * ast_sip_pjsip_uri_get_other_param(pjsip_uri *uri, const pj_str_t *param_str)
Find an 'other' SIP/SIPS URI parameter by name.
Definition: res_pjsip.c:3511
const pj_str_t * ast_sip_pjsip_uri_get_username(pjsip_uri *uri)
Get the user portion of the pjsip_uri.
Definition: res_pjsip.c:3477
void ast_sip_header_to_security_mechanism(const pjsip_generic_string_hdr *hdr, struct ast_sip_security_mechanism_vector *security_mechanisms)
Append to security mechanism vector from SIP header.
unsigned int ast_sip_get_max_initial_qualify_time(void)
Retrieve the system max initial qualify time.
unsigned int ast_sip_get_keep_alive_interval(void)
Retrieve the system keep alive interval setting.
void ast_sip_persistent_endpoint_publish_contact_state(const char *endpoint_name, const struct ast_sip_contact_status *contact_status)
Publish the change of state for a contact.
int ast_sip_set_security_negotiation(enum ast_sip_security_negotiation *security_negotiation, const char *val)
Set the security negotiation based on a given string.
void ast_sip_unregister_service(pjsip_module *module)
Definition: res_pjsip.c:133
unsigned int ast_sip_get_allow_sending_180_after_183(void)
Retrieve the global setting 'allow_sending_180_after_183'.
ast_sip_endpoint_identifier_type
Different methods by which incoming requests can be matched to endpoints.
Definition: res_pjsip.h:610
@ AST_SIP_ENDPOINT_IDENTIFY_BY_HEADER
Definition: res_pjsip.h:618
@ AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME
Definition: res_pjsip.h:612
@ AST_SIP_ENDPOINT_IDENTIFY_BY_REQUEST_URI
Definition: res_pjsip.h:620
@ AST_SIP_ENDPOINT_IDENTIFY_BY_IP
Definition: res_pjsip.h:616
@ AST_SIP_ENDPOINT_IDENTIFY_BY_AUTH_USERNAME
Definition: res_pjsip.h:614
const char * ast_sip_get_host_ip_string(int af)
Retrieve the local host address in string form.
Definition: res_pjsip.c:2493
char * ast_sip_get_endpoint_identifier_order(void)
Retrieve the global endpoint_identifier_order setting.
int(* ast_transport_monitor_data_matcher)(void *a, void *b)
Transport shutdown monitor data matcher.
Definition: res_pjsip.h:3936
void ast_sip_security_mechanisms_vector_copy(struct ast_sip_security_mechanism_vector *dst, const struct ast_sip_security_mechanism_vector *src)
Duplicate a security mechanism.
pjsip_media_type pjsip_media_type_application_media_control_xml
Definition: res_pjsip.c:3910
int ast_sip_call_codec_str_to_pref(struct ast_flags *pref, const char *pref_str, int is_outgoing)
Convert a call codec preference string to preference flags.
Definition: res_pjsip.c:2577
int ast_sip_transport_state_set_transport(const char *transport_name, pjsip_transport *transport)
Sets the PJSIP transport on a child transport.
char * ast_sip_rdata_get_header_value(pjsip_rx_data *rdata, const pj_str_t str)
Get a specific header value from rdata.
Definition: res_pjsip.c:345
pjsip_dialog * ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pj_status_t *status)
General purpose method for creating a UAS dialog with an endpoint.
Definition: res_pjsip.c:1176
struct ast_sip_contact * ast_sip_location_retrieve_contact_from_aor_list(const char *aor_list)
Retrieve the first bound contact from a list of AORs.
Definition: location.c:304
int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time, const char *path_info, const char *user_agent, const char *via_addr, int via_port, const char *call_id, struct ast_sip_endpoint *endpoint)
Add a new contact to an AOR.
Definition: location.c:430
void ast_sip_location_retrieve_contact_and_aor_from_list(const char *aor_list, struct ast_sip_aor **aor, struct ast_sip_contact **contact)
Retrieve the first bound contact AND the AOR chosen from a list of AORs.
Definition: location.c:266
struct ast_sip_endpoint * ast_sip_get_artificial_endpoint(void)
Retrieves a reference to the artificial endpoint.
pjsip_media_type pjsip_media_type_application_json
Definition: res_pjsip.c:3909
int ast_sip_requires_authentication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
Determine if an incoming request requires authentication.
Definition: res_pjsip.c:163
void ast_sip_report_mem_limit(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
Send a security event notification for when a memory limit is hit.
int ast_sip_send_response(pjsip_response_addr *res_addr, pjsip_tx_data *tdata, struct ast_sip_endpoint *sip_endpoint)
Send a response to an out of dialog request.
Definition: res_pjsip.c:2396
pjsip_generic_string_hdr * ast_sip_add_header2(pjsip_tx_data *tdata, const char *name, const char *value)
Add a header to an outbound SIP message, returning a pointer to the header.
Definition: res_pjsip.c:2023
void ast_sip_report_req_no_support(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, const char *req_type)
Send a security event notification for when a request is not supported.
struct ao2_container * ast_sip_get_endpoints(void)
Retrieve any endpoints available to sorcery.
int ast_copy_pj_str2(char **dest, const pj_str_t *src)
Create and copy a pj_str_t into a standard character buffer.
Definition: res_pjsip.c:2208
int ast_sip_get_host_ip(int af, pj_sockaddr *addr)
Retrieve the local host address in IP form.
Definition: res_pjsip.c:2480
int ast_sip_for_each_auth(const struct ast_sip_auth_vector *array, ao2_callback_fn on_auth, void *arg)
For every auth in the array call the given 'on_auth' handler.
Definition: config_auth.c:135
void ast_sip_report_auth_success(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
Send a security event notification for when authentication succeeds.
struct ao2_container * ast_sip_get_transport_states(void)
Retrieves all transport states.
ast_sip_session_redirect
Definition: res_pjsip.h:655
@ AST_SIP_REDIRECT_URI_CORE
Definition: res_pjsip.h:659
@ AST_SIP_REDIRECT_URI_PJSIP
Definition: res_pjsip.h:661
@ AST_SIP_REDIRECT_USER
Definition: res_pjsip.h:657
int ast_sip_create_response(const pjsip_rx_data *rdata, int st_code, struct ast_sip_contact *contact, pjsip_tx_data **p_tdata)
General purpose method for creating a SIP response.
Definition: res_pjsip.c:2468
int ast_sip_register_service(pjsip_module *module)
Register a SIP service in Asterisk.
Definition: res_pjsip.c:117
void * ast_sip_endpoint_alloc(const char *name)
Allocate a new SIP endpoint.
struct ast_sip_aor * ast_sip_location_retrieve_aor(const char *aor_name)
Retrieve a named AOR.
Definition: location.c:147
int ast_sip_is_allowed_uri(pjsip_uri *uri)
Check whether a pjsip_uri is allowed or not.
Definition: res_pjsip.c:3472
pjsip_dialog * ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint, const char *aor_name, const char *request_user)
General purpose method for creating a UAC dialog with an endpoint.
Definition: res_pjsip.c:964
int ast_sip_for_each_channel_snapshot(const struct ast_endpoint_snapshot *endpoint_snapshot, ao2_callback_fn on_channel_snapshot, void *arg)
For every channel snapshot on an endpoint snapshot call the given 'on_channel_snapshot' handler.
struct ao2_container * ast_sip_location_retrieve_aor_contacts_nolock_filtered(const struct ast_sip_aor *aor, unsigned int flags)
Retrieve all contacts currently available for an AOR without locking the AOR and filter based on flag...
Definition: location.c:219
void ast_sip_transport_state_register(struct ast_sip_tpmgr_state_callback *element)
Register a transport state notification callback element.
void ast_sip_cleanup_auths(struct ast_sip_auth *auths[], size_t num_auths)
Clean up retrieved auth structures from memory.
int ast_sip_for_each_contact(const struct ast_sip_aor *aor, ao2_callback_fn on_contact, void *arg)
For every contact on an AOR call the given 'on_contact' handler.
Definition: location.c:723
const int ast_sip_hangup_sip2cause(int cause)
Convert SIP hangup causes to Asterisk hangup causes.
Definition: res_pjsip.c:3531
enum ast_transport_monitor_reg ast_sip_transport_monitor_register_key(const char *transport_key, ast_transport_monitor_shutdown_cb cb, void *ao2_data)
Register a reliable transport shutdown monitor callback.
int ast_sip_rewrite_uri_to_local(pjsip_sip_uri *uri, pjsip_tx_data *tdata)
Replace domain and port of SIP URI to point to (external) signaling address of this Asterisk instance...
Definition: res_pjsip.c:605
int ast_sip_format_auths_ami(const struct ast_sip_auth_vector *auths, struct ast_sip_ami *ami)
Format auth details for AMI.
Definition: config_auth.c:195
int ast_sip_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge, pjsip_tx_data *tdata, pjsip_tx_data **new_request)
Create a response to an authentication challenge.
Definition: res_pjsip.c:214
int ast_sip_for_each_aor(const char *aors, ao2_callback_fn on_aor, void *arg)
For every aor in the comma separated aors string call the given 'on_aor' handler.
Definition: location.c:688
struct ast_sip_contact * ast_sip_location_retrieve_first_aor_contact_filtered(const struct ast_sip_aor *aor, unsigned int flags)
Retrieve the first bound contact for an AOR and filter based on flags.
Definition: location.c:199
int ast_sip_set_id_connected_line(struct pjsip_rx_data *rdata, struct ast_party_id *id)
Set the ID for a connected line update.
Definition: res_pjsip.c:2822
pjsip_media_type pjsip_media_type_application_sdp
Definition: res_pjsip.c:3916
ast_sip_session_media_encryption
Definition: res_pjsip.h:644
@ AST_SIP_MEDIA_ENCRYPT_SDES
Definition: res_pjsip.h:650
@ AST_SIP_MEDIA_TRANSPORT_INVALID
Definition: res_pjsip.h:646
@ AST_SIP_MEDIA_ENCRYPT_NONE
Definition: res_pjsip.h:648
@ AST_SIP_MEDIA_ENCRYPT_DTLS
Definition: res_pjsip.h:652
void ast_sip_register_supplement(struct ast_sip_supplement *supplement)
Register a supplement to SIP out of dialog processing.
Definition: res_pjsip.c:1456
void ast_sip_add_date_header(pjsip_tx_data *tdata)
Adds a Date header to the tdata, formatted like: Date: Wed, 01 Jan 2021 14:53:01 GMT.
Definition: res_pjsip.c:90
pjsip_media_type pjsip_media_type_text_plain
Definition: res_pjsip.c:3920
void ast_sip_report_auth_challenge_sent(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pjsip_tx_data *tdata)
Send a security event notification for when an authentication challenge is sent.
void ast_sip_message_apply_transport(const char *transport_name, pjsip_tx_data *tdata)
Apply the configuration for a transport to an outgoing message.
void ast_sip_unregister_outbound_authenticator(struct ast_sip_outbound_authenticator *auth)
Unregister an outbound SIP authenticator.
Definition: res_pjsip.c:203
int ast_sip_set_id_from_invite(struct pjsip_rx_data *rdata, struct ast_party_id *id, struct ast_party_id *default_id, int trust_inbound)
Set the ID from an INVITE.
Definition: res_pjsip.c:2827
enum ast_transport_monitor_reg ast_sip_transport_monitor_register_replace(pjsip_transport *transport, ast_transport_monitor_shutdown_cb cb, void *ao2_data, ast_transport_monitor_data_matcher matches)
Register a reliable transport shutdown monitor callback replacing any duplicate.
pjsip_media_type pjsip_media_type_application_pidf_xml
Definition: res_pjsip.c:3911
void ast_sip_transport_monitor_unregister(pjsip_transport *transport, ast_transport_monitor_shutdown_cb cb, void *data, ast_transport_monitor_data_matcher matches)
Unregister a reliable transport shutdown monitor.
int ast_sip_auths_to_str(const struct ast_sip_auth_vector *auths, char **buf)
Converts an auths array to a string of comma separated values.
int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port, char *transport_type, const char *local_name, int local_port)
General purpose method for creating an rdata structure using specific information.
Definition: res_pjsip.c:1266
enum ast_sip_check_auth_result ast_sip_check_authentication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pjsip_tx_data *tdata)
Method to determine authentication status of an incoming request.
Definition: res_pjsip.c:179
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition: res_pjsip.c:520
int ast_sip_register_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier)
Register a SIP endpoint identifier.
Definition: res_pjsip.c:310
struct ast_endpoint_snapshot * ast_sip_get_endpoint_snapshot(const struct ast_sip_endpoint *endpoint)
Retrieve the endpoint snapshot for an endpoint.
void * ast_sip_dict_get(void *ht, const char *key)
Retrieves the value associated with the given key.
Definition: res_pjsip.c:2327
unsigned int ast_sip_get_send_contact_status_on_update_registration(void)
Retrieve the global setting 'send_contact_status_on_update_registration'.
int ast_sip_update_from(pjsip_tx_data *tdata, char *from)
Overwrite fields in the outbound 'From' header.
Definition: res_pjsip.c:3383
ast_sip_supplement_priority
Definition: res_pjsip.h:3182
@ AST_SIP_SUPPLEMENT_PRIORITY_CHANNEL
Definition: res_pjsip.h:3189
@ AST_SIP_SUPPLEMENT_PRIORITY_FIRST
Definition: res_pjsip.h:3184
@ AST_SIP_SUPPLEMENT_PRIORITY_LAST
Definition: res_pjsip.h:3191
int ast_sip_format_endpoint_ami(struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami, int *count)
Formats the endpoint and sends over AMI.
Definition: res_pjsip.c:501
int ast_sip_dtmf_to_str(const enum ast_sip_dtmf_mode dtmf, char *buf, size_t buf_len)
Convert the DTMF mode enum value into a string.
Definition: res_pjsip.c:2504
int ast_sip_str2rc(const char *name)
Convert name to SIP response code.
Definition: res_pjsip.c:3714
int ast_sip_set_tpselector_from_transport(const struct ast_sip_transport *transport, pjsip_tpselector *selector)
Sets pjsip_tpselector from ast_sip_transport.
Definition: res_pjsip.c:843
int ast_sip_retrieve_auths(const struct ast_sip_auth_vector *auths, struct ast_sip_auth **out)
Retrieve relevant SIP auth structures from sorcery.
struct ast_sip_endpoint * ast_pjsip_rdata_get_endpoint(pjsip_rx_data *rdata)
Get the looked-up endpoint on an out-of dialog request or response.
int ast_sip_is_uri_sip_sips(pjsip_uri *uri)
Check whether a pjsip_uri is SIP/SIPS or not.
Definition: res_pjsip.c:3467
int ast_sip_set_tpselector_from_ep_or_uri(const struct ast_sip_endpoint *endpoint, pjsip_sip_uri *sip_uri, pjsip_tpselector *selector)
Sets pjsip_tpselector from an endpoint or uri.
Definition: res_pjsip.c:911
void ast_sip_service_route_vector_destroy(struct ast_sip_service_route_vector *service_routes)
Destroy a vector of service routes.
void ast_sip_unregister_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier)
Unregister a SIP endpoint identifier.
Definition: res_pjsip.c:315
const char * ast_sip_get_contact_short_status_label(const enum ast_sip_contact_status_type status)
void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size)
Copy a pj_str_t into a standard character buffer.
Definition: res_pjsip.c:2201
void ast_sip_security_mechanisms_vector_destroy(struct ast_sip_security_mechanism_vector *security_mechanisms)
Free contents of a security mechanism vector.
void ast_sip_transport_monitor_unregister_all(ast_transport_monitor_shutdown_cb cb, void *data, ast_transport_monitor_data_matcher matches)
Unregister a transport shutdown monitor from all reliable transports.
const char * ast_sip_call_codec_pref_to_str(struct ast_flags pref)
Convert the call codec preference flags to a string.
Definition: res_pjsip.c:2554
struct ast_sip_endpoint * ast_sip_identify_endpoint(pjsip_rx_data *rdata)
Determine the endpoint that has sent a SIP message.
Definition: res_pjsip.c:330
int ast_sip_send_out_of_dialog_request(pjsip_tx_data *tdata, struct ast_sip_endpoint *endpoint, int timeout, void *token, void(*callback)(void *token, pjsip_event *e))
General purpose method for sending an Out-Of-Dialog SIP request.
Definition: res_pjsip.c:1938
pjsip_dialog * ast_sip_create_dialog_uas_locked(const struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pj_status_t *status)
General purpose method for creating a UAS dialog with an endpoint.
Definition: res_pjsip.c:1192
pjsip_media_type pjsip_media_type_application_simple_message_summary
Definition: res_pjsip.c:3915
struct ast_sip_transport_state * ast_sip_find_transport_state_in_use(struct ast_sip_request_transport_details *details)
Returns the transport state currently in use based on request transport details.
Definition: res_pjsip.c:595
int ast_sip_format_contact_ami(void *obj, void *arg, int flags)
Formats the contact and sends over AMI.
#define SIP_TLS_MAX_CIPHERS
Maximum number of ciphers supported for a TLS transport.
Definition: res_pjsip.h:104
int ast_sip_dlg_set_transport(const struct ast_sip_endpoint *endpoint, pjsip_dialog *dlg, pjsip_tpselector *selector)
Set the transport on a dialog.
Definition: res_pjsip.c:727
int ast_sip_is_media_type_in(pjsip_media_type *a,...) attribute_sentinel
Check if a media type is in a list of others.
Definition: res_pjsip.c:2228
enum ast_transport_monitor_reg ast_sip_transport_monitor_register_replace_key(const char *transport_key, ast_transport_monitor_shutdown_cb cb, void *ao2_data, ast_transport_monitor_data_matcher matches)
Register a reliable transport shutdown monitor callback replacing any duplicate.
unsigned int ast_sip_get_use_callerid_contact(void)
Retrieve the global setting 'use_callerid_contact'.
char * ast_sip_get_default_voicemail_extension(void)
Retrieve the default voicemail extension.
ast_sip_contact_filter
Contact retrieval filtering flags.
Definition: res_pjsip.h:1304
@ AST_SIP_CONTACT_FILTER_REACHABLE
Return only reachable or unknown contacts.
Definition: res_pjsip.h:1309
@ AST_SIP_CONTACT_FILTER_DEFAULT
Default filter flags.
Definition: res_pjsip.h:1306
void ast_sip_unregister_authenticator(struct ast_sip_authenticator *auth)
Unregister a SIP authenticator.
Definition: res_pjsip.c:152
unsigned int ast_sip_get_contact_expiration_check_interval(void)
Retrieve the system contact expiration check interval setting.
int ast_sip_persistent_endpoint_update_state(const char *endpoint_name, enum ast_endpoint_state state)
Change state of a persistent endpoint.
int ast_sip_send_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint, void *token, void(*callback)(void *token, pjsip_event *e))
General purpose method for sending a SIP request.
Definition: res_pjsip.c:1979
const char * ast_sip_get_device_state(const struct ast_sip_endpoint *endpoint)
Retrieve the device state for an endpoint.
long ast_sip_threadpool_queue_size(void)
Return the size of the SIP threadpool's task queue.
Definition: res_pjsip.c:3457
struct ast_sip_endpoint * ast_sip_default_outbound_endpoint(void)
Retrieve the default outbound endpoint.
int ast_sip_set_request_transport_details(struct ast_sip_request_transport_details *details, pjsip_tx_data *tdata, int use_ipv6)
Sets request transport details based on tdata.
Definition: res_pjsip.c:648
void ast_sip_report_invalid_endpoint(const char *name, pjsip_rx_data *rdata)
Send a security event notification for when an invalid endpoint is requested.
int ast_sip_register_outbound_authenticator(struct ast_sip_outbound_authenticator *outbound_auth)
Register an outbound SIP authenticator.
Definition: res_pjsip.c:191
void ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Register an endpoint formatter.
Definition: res_pjsip.c:481
int ast_sip_add_global_request_header(const char *name, const char *value, int replace)
int ast_sip_add_body(pjsip_tx_data *tdata, const struct ast_sip_body *body)
Add a body to an outbound SIP message.
Definition: res_pjsip.c:2052
int ast_sip_security_mechanisms_to_str(const struct ast_sip_security_mechanism_vector *security_mechanisms, int add_qvalue, char **buf)
Writes the security mechanisms of an endpoint into a buffer as a string and returns the buffer.
void * ast_sip_dict_set(pj_pool_t *pool, void *ht, const char *key, void *val)
Set the value for the given key.
Definition: res_pjsip.c:2338
int ast_sip_are_media_types_equal(pjsip_media_type *a, pjsip_media_type *b)
Compare pjsip media types.
Definition: res_pjsip.c:2219
void ast_sip_tpselector_unref(pjsip_tpselector *selector)
Unreference a pjsip_tpselector.
Definition: res_pjsip.c:923
void ast_sip_get_default_realm(char *realm, size_t size)
Retrieve the global default realm.
struct ao2_container * ast_sip_location_retrieve_aor_contacts_nolock(const struct ast_sip_aor *aor)
Retrieve all contacts currently available for an AOR without locking the AOR.
Definition: location.c:214
int ast_sip_get_transport_name(const struct ast_sip_endpoint *endpoint, pjsip_sip_uri *sip_uri, char *buf, size_t buf_len)
Get the transport name from an endpoint or request uri.
Definition: res_pjsip.c:698
unsigned int ast_sip_get_disable_multi_domain(void)
Retrieve the system setting 'disable multi domain'.
void ast_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Unregister an endpoint formatter.
Definition: res_pjsip.c:487
int ast_sip_retrieve_auths_vector(const struct ast_sip_auth_vector *auth_ids, struct ast_sip_auth_objects_vector *auth_objects)
Retrieve relevant SIP auth structures from sorcery as a vector.
ast_sip_dtmf_mode
DTMF modes for SIP endpoints.
Definition: res_pjsip.h:544
@ AST_SIP_DTMF_NONE
Definition: res_pjsip.h:546
@ AST_SIP_DTMF_AUTO_INFO
Definition: res_pjsip.h:557
@ AST_SIP_DTMF_AUTO
Definition: res_pjsip.h:555
@ AST_SIP_DTMF_INBAND
Definition: res_pjsip.h:551
@ AST_SIP_DTMF_INFO
Definition: res_pjsip.h:553
@ AST_SIP_DTMF_RFC_4733
Definition: res_pjsip.h:549
unsigned int ast_sip_get_ignore_uri_user_options(void)
Retrieve the global setting 'ignore_uri_user_options'.
int ast_sip_register_authenticator(struct ast_sip_authenticator *auth)
Register a SIP authenticator.
Definition: res_pjsip.c:140
static const pj_str_t AST_PJ_STR_EMPTY
Definition: res_pjsip.h:111
struct ast_sip_service_route_vector * ast_sip_service_route_vector_alloc(void)
Allocate a vector of service routes.
struct ast_sip_contact * ast_sip_location_retrieve_contact(const char *contact_name)
Retrieve a named contact.
Definition: location.c:350
enum ast_transport_monitor_reg ast_sip_transport_monitor_register(pjsip_transport *transport, ast_transport_monitor_shutdown_cb cb, void *ao2_data)
Register a reliable transport shutdown monitor callback.
int ast_sip_str_to_security_mechanism(struct ast_sip_security_mechanism **security_mechanism, const char *value)
Allocate a security mechanism from a string.
int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf)
Converts a sorcery object to a string of object properties.
void ast_sip_transport_state_unregister(struct ast_sip_tpmgr_state_callback *element)
Unregister a transport state notification callback element.
int ast_sip_add_body_multipart(pjsip_tx_data *tdata, const struct ast_sip_body *bodies[], int num_bodies)
Add a multipart body to an outbound SIP message.
Definition: res_pjsip.c:2059
ast_sip_auth_type
Methods of storing SIP digest authentication credentials.
Definition: res_pjsip.h:567
@ AST_SIP_AUTH_TYPE_GOOGLE_OAUTH
Definition: res_pjsip.h:573
@ AST_SIP_AUTH_TYPE_ARTIFICIAL
Definition: res_pjsip.h:575
@ AST_SIP_AUTH_TYPE_MD5
Definition: res_pjsip.h:571
@ AST_SIP_AUTH_TYPE_USER_PASS
Definition: res_pjsip.h:569
pjsip_media_type pjsip_media_type_application_rlmi_xml
Definition: res_pjsip.c:3914
ast_transport_monitor_reg
Definition: res_pjsip.h:3938
@ AST_TRANSPORT_MONITOR_REG_NOT_FOUND
Transport not found to monitor.
Definition: res_pjsip.h:3947
@ AST_TRANSPORT_MONITOR_REG_REPLACED
Replaced the already existing transport monitor with new one.
Definition: res_pjsip.h:3942
@ AST_TRANSPORT_MONITOR_REG_FAILED
Error while registering transport monitor.
Definition: res_pjsip.h:3949
@ AST_TRANSPORT_MONITOR_REG_SUCCESS
Successfully registered the transport monitor.
Definition: res_pjsip.h:3940
void(* ast_transport_monitor_shutdown_cb)(void *data)
Transport shutdown monitor callback.
Definition: res_pjsip.h:3924
int ast_sip_add_global_response_header(const char *name, const char *value, int replace)
struct ao2_container * ast_sip_location_retrieve_contacts_from_aor_list(const char *aor_list)
Retrieve all contacts from a list of AORs.
Definition: location.c:335
int ast_sip_update_to_uri(pjsip_tx_data *tdata, const char *to)
Replace the To URI in the tdata with the supplied one.
Definition: res_pjsip.c:3323
pjsip_media_type pjsip_media_type_multipart_mixed
Definition: res_pjsip.c:3918
void ast_sip_report_auth_failed_challenge_response(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
Send a security event notification for when a challenge response has failed.
void ast_sip_remove_headers_by_name_and_value(pjsip_msg *msg, const pj_str_t *hdr_name, const char *value)
Removes all headers of a specific name and value from a pjsip_msg.
pjsip_media_type pjsip_media_type_application_xpidf_xml
Definition: res_pjsip.c:3912
void ast_sip_location_retrieve_contact_and_aor_from_list_filtered(const char *aor_list, unsigned int flags, struct ast_sip_aor **aor, struct ast_sip_contact **contact)
Retrieve the first bound contact AND the AOR chosen from a list of AORs and filter based on flags.
Definition: location.c:272
int ast_sip_set_outbound_proxy(pjsip_tx_data *tdata, const char *proxy)
Set the outbound proxy for an outbound SIP message.
Definition: res_pjsip.c:1992
struct ast_sip_transport_state * ast_sip_get_transport_state(const char *transport_id)
Retrieve transport state.
unsigned int ast_sip_get_mwi_disable_initial_unsolicited(void)
Retrieve the global setting 'disable sending unsolicited mwi on startup'.
void ast_sip_auth_vector_destroy(struct ast_sip_auth_vector *vector)
Free contents of an auth vector.
struct ast_threadpool * ast_sip_threadpool(void)
Retrieve the SIP threadpool object.
Definition: res_pjsip.c:3462
int ast_sip_register_endpoint_identifier_with_name(struct ast_sip_endpoint_identifier *identifier, const char *name)
Register a SIP endpoint identifier with a name.
Definition: res_pjsip.c:233
pjsip_media_type pjsip_media_type_multipart_alternative
Definition: res_pjsip.c:3917
ast_sip_security_negotiation
The kind of security negotiation.
Definition: res_pjsip.h:350
@ AST_SIP_SECURITY_NEG_MEDIASEC
Definition: res_pjsip.h:354
@ AST_SIP_SECURITY_NEG_NONE
Definition: res_pjsip.h:352
int ast_sip_set_tpselector_from_transport_name(const char *transport_name, pjsip_tpselector *selector)
Sets pjsip_tpselector from ast_sip_transport.
Definition: res_pjsip.c:893
int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg, struct ast_sip_endpoint *endpoint, const char *uri, struct ast_sip_contact *contact, pjsip_tx_data **tdata)
General purpose method for creating a SIP request.
Definition: res_pjsip.c:1435
struct ast_str * ast_sip_create_ami_event(const char *event, struct ast_sip_ami *ami)
Creates a string to store AMI event data in.
int ast_sip_get_mwi_tps_queue_low(void)
Retrieve the global MWI taskprocessor low water clear alert level.
struct ast_sip_contact * ast_sip_location_create_contact(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time, const char *path_info, const char *user_agent, const char *via_addr, int via_port, const char *call_id, int prune_on_boot, struct ast_sip_endpoint *endpoint)
Create a new contact for an AOR without locking the AOR.
Definition: location.c:355
int ast_sip_str_to_dtmf(const char *dtmf_mode)
Convert the DTMF mode name into an enum.
Definition: res_pjsip.c:2533
int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value)
Add a header to an outbound SIP message.
Definition: res_pjsip.c:2008
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
const pj_str_t * ast_sip_pjsip_uri_get_hostname(pjsip_uri *uri)
Get the host portion of the pjsip_uri.
Definition: res_pjsip.c:3496
char * ast_sip_get_regcontext(void)
Retrieve the global regcontext setting.
ast_sip_check_auth_result
Possible returns from ast_sip_check_authentication.
Definition: res_pjsip.h:1232
@ AST_SIP_AUTHENTICATION_CHALLENGE
Definition: res_pjsip.h:1234
@ AST_SIP_AUTHENTICATION_ERROR
Definition: res_pjsip.h:1240
@ AST_SIP_AUTHENTICATION_SUCCESS
Definition: res_pjsip.h:1236
@ AST_SIP_AUTHENTICATION_FAILED
Definition: res_pjsip.h:1238
ast_sip_call_codec_pref
Incoming/Outgoing call offer/answer joint codec preference.
Definition: res_pjsip.h:669
@ AST_SIP_CALL_CODEC_PREF_ALL
Definition: res_pjsip.h:678
@ AST_SIP_CALL_CODEC_PREF_LOCAL
Definition: res_pjsip.h:684
@ AST_SIP_CALL_CODEC_PREF_REMOTE
Definition: res_pjsip.h:686
@ AST_SIP_CALL_CODEC_PREF_UNION
Definition: res_pjsip.h:674
@ AST_SIP_CALL_CODEC_PREF_FIRST
Definition: res_pjsip.h:680
@ AST_SIP_CALL_CODEC_PREF_INTERSECT
Definition: res_pjsip.h:672
const char * ast_sip_auth_type_to_str(enum ast_sip_auth_type type)
Converts the given auth type to a string.
Definition: config_auth.c:80
struct ast_sip_contact_status * ast_sip_get_contact_status(const struct ast_sip_contact *contact)
Retrieve the current status for a contact.
int(* ast_sip_dialog_outbound_auth_cb)(pjsip_dialog *dlg, pjsip_tx_data *tdata, void *user_data)
Callback called when an outbound request with authentication credentials is to be sent in dialog.
Definition: res_pjsip.h:1768
int ast_sip_security_mechanism_vector_init(struct ast_sip_security_mechanism_vector *security_mechanism, const char *value)
Initialize security mechanism vector from string of security mechanisms.
int ast_sip_location_update_contact(struct ast_sip_contact *contact)
Update a contact.
Definition: location.c:446
const char * ast_sip_get_contact_status_label(const enum ast_sip_contact_status_type status)
translate ast_sip_contact_status_type to character string.
int ast_sip_send_stateful_response(pjsip_rx_data *rdata, pjsip_tx_data *tdata, struct ast_sip_endpoint *sip_endpoint)
Send a stateful response to an out of dialog request.
Definition: res_pjsip.c:2424
int ast_sip_for_each_channel(const struct ast_sip_endpoint *endpoint, ao2_callback_fn on_channel_snapshot, void *arg)
For every channel snapshot on an endpoint all the given 'on_channel_snapshot' handler.
int ast_sip_auth_vector_init(struct ast_sip_auth_vector *vector, const char *auth_names)
Initialize an auth vector with the configured values.
ast_sip_contact_status_type
Status type for a contact.
Definition: res_pjsip.h:433
@ AVAILABLE
Definition: res_pjsip.h:437
@ UNAVAILABLE
Definition: res_pjsip.h:435
@ REMOVED
Definition: res_pjsip.h:442
@ UNKNOWN
Definition: res_pjsip.h:439
@ CREATED
Definition: res_pjsip.h:441
void ast_sip_get_default_from_user(char *from_user, size_t size)
Retrieve the global default from user.
unsigned int ast_sip_get_mwi_tps_queue_high(void)
Retrieve the global MWI taskprocessor high water alert trigger level.
int ast_sip_is_content_type(pjsip_media_type *content_type, char *type, char *subtype)
Checks if the given content type matches type/subtype.
Definition: res_pjsip.c:2248
void ast_sip_transport_monitor_unregister_key(const char *transport_key, ast_transport_monitor_shutdown_cb cb, void *data, ast_transport_monitor_data_matcher matches)
Unregister a reliable transport shutdown monitor.
int ast_sip_append_body(pjsip_tx_data *tdata, const char *body_text)
Append body data to a SIP message.
Definition: res_pjsip.c:2075
int ast_sip_add_security_headers(struct ast_sip_security_mechanism_vector *security_mechanisms, const char *header_name, int add_qval, pjsip_tx_data *tdata)
Add security headers to transmission data.
int ast_sip_contact_to_str(void *object, void *arg, int flags)
Handler used to convert a contact to a string.
Definition: location.c:771
struct ast_sip_contact * ast_sip_location_retrieve_first_aor_contact(const struct ast_sip_aor *aor)
Retrieve the first bound contact for an AOR.
Definition: location.c:194
int ast_sip_transport_state_set_preferred_identity(const char *transport_name, const char *identity)
Sets the P-Preferred-Identity on a child transport.
unsigned int ast_sip_get_all_codecs_on_empty_reinvite(void)
Retrieve the system setting 'all_codecs_on_empty_reinvite'.
void ast_sip_location_prune_boot_contacts(void)
Prune the prune_on_boot contacts.
Definition: location.c:470
ast_sip_100rel_mode
100rel modes for SIP endpoints
Definition: res_pjsip.h:530
@ AST_SIP_100REL_PEER_SUPPORTED
Definition: res_pjsip.h:536
@ AST_SIP_100REL_UNSUPPORTED
Definition: res_pjsip.h:532
@ AST_SIP_100REL_SUPPORTED
Definition: res_pjsip.h:534
@ AST_SIP_100REL_REQUIRED
Definition: res_pjsip.h:538
struct ao2_container * ast_sip_location_retrieve_aor_contacts(const struct ast_sip_aor *aor)
Retrieve all contacts currently available for an AOR.
Definition: location.c:247
ast_sip_direct_media_glare_mitigation
Definition: res_pjsip.h:631
@ AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_NONE
Definition: res_pjsip.h:633
@ AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_INCOMING
Definition: res_pjsip.h:641
@ AST_SIP_DIRECT_MEDIA_GLARE_MITIGATION_OUTGOING
Definition: res_pjsip.h:637
pjsip_media_type pjsip_media_type_application_cpim_xpidf_xml
Definition: res_pjsip.c:3913
struct ao2_container * ast_sip_location_retrieve_aor_contacts_filtered(const struct ast_sip_aor *aor, unsigned int flags)
Retrieve all contacts currently available for an AOR and filter based on flags.
Definition: location.c:252
pjsip_sip_uri * ast_sip_get_contact_sip_uri(pjsip_tx_data *tdata)
Return the SIP URI of the Contact header.
Definition: res_pjsip.c:564
int ast_sip_location_delete_contact(struct ast_sip_contact *contact)
Delete a contact.
Definition: location.c:451
int ast_sip_create_rdata_with_contact(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port, char *transport_type, const char *local_name, int local_port, const char *contact_uri)
General purpose method for creating an rdata structure using specific information.
Definition: res_pjsip.c:1214
pjsip_media_type pjsip_media_type_multipart_related
Definition: res_pjsip.c:3919
int ast_sip_failover_request(pjsip_tx_data *tdata)
Set a request to use the next value in the list of resolved addresses.
Definition: res_pjsip.c:1816
void ast_sip_report_failed_acl(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, const char *name)
Send a security event notification for when an ACL check fails.
int ast_sip_location_add_contact_nolock(struct ast_sip_aor *aor, const char *uri, struct timeval expiration_time, const char *path_info, const char *user_agent, const char *via_addr, int via_port, const char *call_id, struct ast_sip_endpoint *endpoint)
Add a new contact to an AOR without locking the AOR.
Definition: location.c:417
int ast_sip_transport_state_set_service_routes(const char *transport_name, struct ast_sip_service_route_vector *service_routes)
Sets the service routes on a child transport.
ast_sip_session_refresh_method
Definition: res_pjsip.h:624
@ AST_SIP_SESSION_REFRESH_METHOD_UPDATE
Definition: res_pjsip.h:628
@ AST_SIP_SESSION_REFRESH_METHOD_INVITE
Definition: res_pjsip.h:626
void ast_sip_get_unidentified_request_thresholds(unsigned int *count, unsigned int *period, unsigned int *prune_interval)
Retrieve the unidentified request security event thresholds.
char * ast_sip_get_debug(void)
Retrieve the system debug setting (yes|no|host).
void ast_sip_modify_id_header(pj_pool_t *pool, pjsip_fromto_hdr *id_hdr, const struct ast_party_id *id)
Set name and number information on an identity header.
Definition: res_pjsip.c:2850
static void challenge(const char *realm, pjsip_tx_data *tdata, const pjsip_rx_data *rdata, int is_stale)
astobj2 callback for adding digest challenges to responses
Pluggable RTP Architecture.
Sorcery Data Access Layer API.
Endpoint abstractions.
Media Stream API.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
Definition: stringfields.h:341
#define AST_STRING_FIELD(name)
Declare a string field.
Definition: stringfields.h:303
Generic container type.
Wrapper for an ast_acl linked list.
Definition: acl.h:76
Definition: dnsmgr.c:66
A snapshot of an endpoint's state.
Structure used to handle boolean flags.
Definition: utils.h:199
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
internal representation of ACL entries In principle user applications would have no need for this,...
Definition: acl.h:51
Information needed to identify an endpoint in a call.
Definition: channel.h:340
DTLS configuration structure.
Definition: rtp_engine.h:605
AMI variable container.
Definition: res_pjsip.h:3050
const char * action_id
Definition: res_pjsip.h:3056
struct mansession * s
Definition: res_pjsip.h:3052
void * arg
Definition: res_pjsip.h:3058
const struct message * m
Definition: res_pjsip.h:3054
A SIP address of record.
Definition: res_pjsip.h:477
SORCERY_OBJECT(details)
unsigned int minimum_expiration
Definition: res_pjsip.h:487
unsigned int remove_existing
Definition: res_pjsip.h:499
double qualify_timeout
Definition: res_pjsip.h:505
char * voicemail_extension
Definition: res_pjsip.h:507
unsigned int max_contacts
Definition: res_pjsip.h:497
int qualify_2xx_only
Definition: res_pjsip.h:511
unsigned int support_path
Definition: res_pjsip.h:503
struct ao2_container * permanent_contacts
Definition: res_pjsip.h:501
unsigned int remove_unavailable
Definition: res_pjsip.h:509
const ast_string_field outbound_proxy
Definition: res_pjsip.h:485
unsigned int maximum_expiration
Definition: res_pjsip.h:489
const ast_string_field mailboxes
Definition: res_pjsip.h:485
unsigned int default_expiration
Definition: res_pjsip.h:491
int authenticate_qualify
Definition: res_pjsip.h:495
unsigned int qualify_frequency
Definition: res_pjsip.h:493
SORCERY_OBJECT(details)
const ast_string_field oauth_clientid
Definition: res_pjsip.h:598
const ast_string_field oauth_secret
Definition: res_pjsip.h:598
const ast_string_field md5_creds
Definition: res_pjsip.h:598
const ast_string_field realm
Definition: res_pjsip.h:598
unsigned int nonce_lifetime
Definition: res_pjsip.h:600
const ast_string_field auth_user
Definition: res_pjsip.h:598
const ast_string_field refresh_token
Definition: res_pjsip.h:598
const ast_string_field auth_pass
Definition: res_pjsip.h:598
enum ast_sip_auth_type type
Definition: res_pjsip.h:602
An interchangeable way of handling digest authentication for SIP.
Definition: res_pjsip.h:1250
enum ast_sip_check_auth_result(* check_authentication)(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pjsip_tx_data *tdata)
Check that an incoming request passes authentication.
Definition: res_pjsip.h:1265
int(* requires_authentication)(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
Check if a request requires authentication See ast_sip_requires_authentication for more details.
Definition: res_pjsip.h:1255
SIP body description.
Definition: res_pjsip.h:2328
const char * type
Definition: res_pjsip.h:2330
const char * body_text
Definition: res_pjsip.h:2334
const char * subtype
Definition: res_pjsip.h:2332
A contact's status.
Definition: res_pjsip.h:450
const ast_string_field uri
Definition: res_pjsip.h:456
enum ast_sip_contact_status_type status
Definition: res_pjsip.h:467
enum ast_sip_contact_status_type last_status
Definition: res_pjsip.h:469
const ast_string_field aor
Definition: res_pjsip.h:456
struct ast_sip_security_mechanism_vector security_mechanisms
Definition: res_pjsip.h:465
A wrapper for contact that adds the aor_id and a consistent contact id. Used by ast_sip_for_each_cont...
Definition: res_pjsip.h:518
struct ast_sip_contact * contact
Definition: res_pjsip.h:524
Contact associated with an address of record.
Definition: res_pjsip.h:389
SORCERY_OBJECT(details)
const ast_string_field uri
Definition: res_pjsip.h:411
double qualify_timeout
Definition: res_pjsip.h:419
struct ast_sip_endpoint * endpoint
Definition: res_pjsip.h:421
const ast_string_field via_addr
Definition: res_pjsip.h:411
int qualify_2xx_only
Definition: res_pjsip.h:427
const ast_string_field call_id
Definition: res_pjsip.h:411
const ast_string_field aor
Definition: res_pjsip.h:411
const ast_string_field outbound_proxy
Definition: res_pjsip.h:411
struct timeval expiration_time
Definition: res_pjsip.h:413
const ast_string_field path
Definition: res_pjsip.h:411
const ast_string_field endpoint_name
Definition: res_pjsip.h:411
int authenticate_qualify
Definition: res_pjsip.h:417
const ast_string_field reg_server
Definition: res_pjsip.h:411
const ast_string_field user_agent
Definition: res_pjsip.h:411
unsigned int qualify_frequency
Definition: res_pjsip.h:415
Direct media options for SIP endpoints.
Definition: res_pjsip.h:875
enum ast_sip_direct_media_glare_mitigation glare_mitigation
Definition: res_pjsip.h:881
enum ast_sip_session_refresh_method method
Definition: res_pjsip.h:879
const ast_string_field domain
Definition: res_pjsip.h:320
Endpoint configuration for SIP extensions.
Definition: res_pjsip.h:716
struct ast_sip_timer_options timer
Definition: res_pjsip.h:720
An entity responsible formatting endpoint information.
Definition: res_pjsip.h:3076
int(* format_ami)(const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami)
Callback used to format endpoint information over AMI.
Definition: res_pjsip.h:3080
Party identification options for endpoints.
Definition: res_pjsip.h:770
struct ast_party_id self
Definition: res_pjsip