Asterisk - The Open Source Telephony Project  18.5.0
res_pjsip.c
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 <[email protected]>
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 #include "asterisk.h"
20 
21 #include <pjsip.h>
22 /* Needed for SUBSCRIBE, NOTIFY, and PUBLISH method definitions */
23 #include <pjsip_simple.h>
24 #include <pjsip/sip_transaction.h>
25 #include <pj/timer.h>
26 #include <pjlib.h>
27 #include <pjmedia/errno.h>
28 
29 #include "asterisk/res_pjsip.h"
31 #include "asterisk/linkedlists.h"
32 #include "asterisk/logger.h"
33 #include "asterisk/lock.h"
34 #include "asterisk/utils.h"
35 #include "asterisk/astobj2.h"
36 #include "asterisk/module.h"
37 #include "asterisk/serializer.h"
38 #include "asterisk/threadpool.h"
39 #include "asterisk/taskprocessor.h"
40 #include "asterisk/uuid.h"
41 #include "asterisk/sorcery.h"
42 #include "asterisk/file.h"
43 #include "asterisk/cli.h"
44 #include "asterisk/res_pjsip_cli.h"
45 #include "asterisk/test.h"
47 #include "asterisk/res_pjproject.h"
48 
49 /*** MODULEINFO
50  <depend>pjproject</depend>
51  <depend>res_pjproject</depend>
52  <depend>res_sorcery_config</depend>
53  <depend>res_sorcery_memory</depend>
54  <depend>res_sorcery_astdb</depend>
55  <use type="module">res_statsd</use>
56  <support_level>core</support_level>
57  ***/
58 
59 /*** DOCUMENTATION
60  <configInfo name="res_pjsip" language="en_US">
61  <synopsis>SIP Resource using PJProject</synopsis>
62  <configFile name="pjsip.conf">
63  <configObject name="endpoint">
64  <synopsis>Endpoint</synopsis>
65  <description><para>
66  The <emphasis>Endpoint</emphasis> is the primary configuration object.
67  It contains the core SIP related options only, endpoints are <emphasis>NOT</emphasis>
68  dialable entries of their own. Communication with another SIP device is
69  accomplished via Addresses of Record (AoRs) which have one or more
70  contacts associated with them. Endpoints <emphasis>NOT</emphasis> configured to
71  use a <literal>transport</literal> will default to first transport found
72  in <filename>pjsip.conf</filename> that matches its type.
73  </para>
74  <para>Example: An Endpoint has been configured with no transport.
75  When it comes time to call an AoR, PJSIP will find the
76  first transport that matches the type. A SIP URI of <literal>sip:[email protected][11::33]</literal>
77  will use the first IPv6 transport and try to send the request.
78  </para>
79  <para>If the anonymous endpoint identifier is in use an endpoint with the name
80  "[email protected]" will be searched for as a last resort. If this is not found
81  it will fall back to searching for "anonymous". If neither endpoints are found
82  the anonymous endpoint identifier will not return an endpoint and anonymous
83  calling will not be possible.
84  </para>
85  </description>
86  <configOption name="100rel" default="yes">
87  <synopsis>Allow support for RFC3262 provisional ACK tags</synopsis>
88  <description>
89  <enumlist>
90  <enum name="no" />
91  <enum name="required" />
92  <enum name="yes" />
93  </enumlist>
94  </description>
95  </configOption>
96  <configOption name="aggregate_mwi" default="yes">
97  <synopsis>Condense MWI notifications into a single NOTIFY.</synopsis>
98  <description><para>When enabled, <replaceable>aggregate_mwi</replaceable> condenses message
99  waiting notifications from multiple mailboxes into a single NOTIFY. If it is disabled,
100  individual NOTIFYs are sent for each mailbox.</para></description>
101  </configOption>
102  <configOption name="allow">
103  <synopsis>Media Codec(s) to allow</synopsis>
104  </configOption>
105  <configOption name="codec_prefs_incoming_offer">
106  <synopsis>Codec negotiation prefs for incoming offers.</synopsis>
107  <description>
108  <para>
109  This is a string that describes how the codecs
110  specified on an incoming SDP offer (pending) are reconciled with the codecs specified
111  on an endpoint (configured) before being sent to the Asterisk core.
112  The string actually specifies 4 <literal>name:value</literal> pair parameters
113  separated by commas. Whitespace is ignored and they may be specified in any order.
114  Note that this option is reserved for future functionality.
115 
116  </para>
117  <para>
118  Parameters:
119  </para>
120  <enumlist>
121  <enum name="prefer: &lt; pending | configured &gt;">
122  <para>
123  </para>
124  <enumlist>
125  <enum name="pending"><para>The codec list from the caller. (default)</para></enum>
126  <enum name="configured"><para>The codec list from the endpoint.</para></enum>
127  </enumlist>
128  </enum>
129  <enum name="operation : &lt; intersect | only_preferred | only_nonpreferred &gt;">
130  <para>
131  </para>
132  <enumlist>
133  <enum name="intersect"><para>Only common codecs with the preferred codecs first. (default)</para></enum>
134  <enum name="only_preferred"><para>Use only the preferred codecs.</para></enum>
135  <enum name="only_nonpreferred"><para>Use only the non-preferred codecs.</para></enum>
136  </enumlist>
137  </enum>
138  <enum name="keep : &lt; all | first &gt;">
139  <para>
140  </para>
141  <enumlist>
142  <enum name="all"><para>After the operation, keep all codecs. (default)</para></enum>
143  <enum name="first"><para>After the operation, keep only the first codec.</para></enum>
144  </enumlist>
145  </enum>
146  <enum name="transcode : &lt; allow | prevent &gt;">
147  <para>
148  </para>
149  <enumlist>
150  <enum name="allow"><para>Allow transcoding. (default)</para></enum>
151  <enum name="prevent"><para>Prevent transcoding.</para></enum>
152  </enumlist>
153  </enum>
154  </enumlist>
155  <para>
156  </para>
157  <example>
158  codec_prefs_incoming_offer = prefer: pending, operation: intersect, keep: all, transcode: allow
159  </example>
160  <para>
161  Prefer the codecs coming from the caller. Use only the ones that are common.
162  keeping the order of the preferred list. Keep all codecs in the result. Allow transcoding.
163  </para>
164  </description>
165  </configOption>
166  <configOption name="codec_prefs_outgoing_offer">
167  <synopsis>Codec negotiation prefs for outgoing offers.</synopsis>
168  <description>
169  <para>
170  This is a string that describes how the codecs specified in the topology that
171  comes from the Asterisk core (pending) are reconciled with the codecs specified on an
172  endpoint (configured) when sending an SDP offer.
173  The string actually specifies 4 <literal>name:value</literal> pair parameters
174  separated by commas. Whitespace is ignored and they may be specified in any order.
175  Note that this option is reserved for future functionality.
176 
177  </para>
178  <para>
179  Parameters:
180  </para>
181  <enumlist>
182  <enum name="prefer: &lt; pending | configured &gt;">
183  <para>
184  </para>
185  <enumlist>
186  <enum name="pending"><para>The codec list from the core. (default)</para></enum>
187  <enum name="configured"><para>The codec list from the endpoint.</para></enum>
188  </enumlist>
189  </enum>
190  <enum name="operation : &lt; union | intersect | only_preferred | only_nonpreferred &gt;">
191  <para>
192  </para>
193  <enumlist>
194  <enum name="union"><para>Merge the lists with the preferred codecs first. (default)</para></enum>
195  <enum name="intersect"><para>Only common codecs with the preferred codecs first. (default)</para></enum>
196  <enum name="only_preferred"><para>Use only the preferred codecs.</para></enum>
197  <enum name="only_nonpreferred"><para>Use only the non-preferred codecs.</para></enum>
198  </enumlist>
199  </enum>
200  <enum name="keep : &lt; all | first &gt;">
201  <para>
202  </para>
203  <enumlist>
204  <enum name="all"><para>After the operation, keep all codecs. (default)</para></enum>
205  <enum name="first"><para>After the operation, keep only the first codec.</para></enum>
206  </enumlist>
207  </enum>
208  <enum name="transcode : &lt; allow | prevent &gt;">
209  <para>
210  </para>
211  <enumlist>
212  <enum name="allow"><para>Allow transcoding. (default)</para></enum>
213  <enum name="prevent"><para>Prevent transcoding.</para></enum>
214  </enumlist>
215  </enum>
216  </enumlist>
217  <para>
218  </para>
219  <example>
220  codec_prefs_outgoing_offer = prefer: configured, operation: union, keep: first, transcode: prevent
221  </example>
222  <para>
223  Prefer the codecs coming from the endpoint. Merge them with the codecs from the core
224  keeping the order of the preferred list. Keep only the first one. No transcoding allowed.
225  </para>
226  </description>
227  </configOption>
228  <configOption name="codec_prefs_incoming_answer">
229  <synopsis>Codec negotiation prefs for incoming answers.</synopsis>
230  <description>
231  <para>
232  This is a string that describes how the codecs specified in an incoming SDP answer
233  (pending) are reconciled with the codecs specified on an endpoint (configured)
234  when receiving an SDP answer.
235  The string actually specifies 4 <literal>name:value</literal> pair parameters
236  separated by commas. Whitespace is ignored and they may be specified in any order.
237  Note that this option is reserved for future functionality.
238 
239  </para>
240  <para>
241  Parameters:
242  </para>
243  <enumlist>
244  <enum name="prefer: &lt; pending | configured &gt;">
245  <para>
246  </para>
247  <enumlist>
248  <enum name="pending"><para>The codec list in the received SDP answer. (default)</para></enum>
249  <enum name="configured"><para>The codec list from the endpoint.</para></enum>
250  </enumlist>
251  </enum>
252  <enum name="operation : &lt; union | intersect | only_preferred | only_nonpreferred &gt;">
253  <para>
254  </para>
255  <enumlist>
256  <enum name="union"><para>Merge the lists with the preferred codecs first.</para></enum>
257  <enum name="intersect"><para>Only common codecs with the preferred codecs first. (default)</para></enum>
258  <enum name="only_preferred"><para>Use only the preferred codecs.</para></enum>
259  <enum name="only_nonpreferred"><para>Use only the non-preferred codecs.</para></enum>
260  </enumlist>
261  </enum>
262  <enum name="keep : &lt; all | first &gt;">
263  <para>
264  </para>
265  <enumlist>
266  <enum name="all"><para>After the operation, keep all codecs. (default)</para></enum>
267  <enum name="first"><para>After the operation, keep only the first codec.</para></enum>
268  </enumlist>
269  </enum>
270  <enum name="transcode : &lt; allow | prevent &gt;">
271  <para>
272  The transcode parameter is ignored when processing answers.
273  </para>
274  </enum>
275  </enumlist>
276  <para>
277  </para>
278  <example>
279  codec_prefs_incoming_answer = keep: first
280  </example>
281  <para>
282  Use the defaults but keep oinly the first codec.
283  </para>
284  </description>
285  </configOption>
286  <configOption name="codec_prefs_outgoing_answer">
287  <synopsis>Codec negotiation prefs for outgoing answers.</synopsis>
288  <description>
289  <para>
290  This is a string that describes how the codecs that come from the core (pending)
291  are reconciled with the codecs specified on an endpoint (configured)
292  when sending an SDP answer.
293  The string actually specifies 4 <literal>name:value</literal> pair parameters
294  separated by commas. Whitespace is ignored and they may be specified in any order.
295  Note that this option is reserved for future functionality.
296 
297  </para>
298  <para>
299  Parameters:
300  </para>
301  <enumlist>
302  <enum name="prefer: &lt; pending | configured &gt;">
303  <para>
304  </para>
305  <enumlist>
306  <enum name="pending"><para>The codec list that came from the core. (default)</para></enum>
307  <enum name="configured"><para>The codec list from the endpoint.</para></enum>
308  </enumlist>
309  </enum>
310  <enum name="operation : &lt; union | intersect | only_preferred | only_nonpreferred &gt;">
311  <para>
312  </para>
313  <enumlist>
314  <enum name="union"><para>Merge the lists with the preferred codecs first.</para></enum>
315  <enum name="intersect"><para>Only common codecs with the preferred codecs first. (default)</para></enum>
316  <enum name="only_preferred"><para>Use only the preferred codecs.</para></enum>
317  <enum name="only_nonpreferred"><para>Use only the non-preferred codecs.</para></enum>
318  </enumlist>
319  </enum>
320  <enum name="keep : &lt; all | first &gt;">
321  <para>
322  </para>
323  <enumlist>
324  <enum name="all"><para>After the operation, keep all codecs. (default)</para></enum>
325  <enum name="first"><para>After the operation, keep only the first codec.</para></enum>
326  </enumlist>
327  </enum>
328  <enum name="transcode : &lt; allow | prevent &gt;">
329  <para>
330  The transcode parameter is ignored when processing answers.
331  </para>
332  </enum>
333  </enumlist>
334  <para>
335  </para>
336  <example>
337  codec_prefs_incoming_answer = keep: first
338  </example>
339  <para>
340  Use the defaults but keep oinly the first codec.
341  </para>
342  </description>
343  </configOption>
344  <configOption name="allow_overlap" default="yes">
345  <synopsis>Enable RFC3578 overlap dialing support.</synopsis>
346  </configOption>
347  <configOption name="aors">
348  <synopsis>AoR(s) to be used with the endpoint</synopsis>
349  <description><para>
350  List of comma separated AoRs that the endpoint should be associated with.
351  </para></description>
352  </configOption>
353  <configOption name="auth">
354  <synopsis>Authentication Object(s) associated with the endpoint</synopsis>
355  <description><para>
356  This is a comma-delimited list of <replaceable>auth</replaceable> sections defined
357  in <filename>pjsip.conf</filename> to be used to verify inbound connection attempts.
358  </para><para>
359  Endpoints without an authentication object
360  configured will allow connections without verification.</para>
361  <note><para>
362  Using the same auth section for inbound and outbound
363  authentication is not recommended. There is a difference in
364  meaning for an empty realm setting between inbound and outbound
365  authentication uses. See the auth realm description for details.
366  </para></note>
367  </description>
368  </configOption>
369  <configOption name="callerid">
370  <synopsis>CallerID information for the endpoint</synopsis>
371  <description><para>
372  Must be in the format <literal>Name &lt;Number&gt;</literal>,
373  or only <literal>&lt;Number&gt;</literal>.
374  </para></description>
375  </configOption>
376  <configOption name="callerid_privacy">
377  <synopsis>Default privacy level</synopsis>
378  <description>
379  <enumlist>
380  <enum name="allowed_not_screened" />
381  <enum name="allowed_passed_screen" />
382  <enum name="allowed_failed_screen" />
383  <enum name="allowed" />
384  <enum name="prohib_not_screened" />
385  <enum name="prohib_passed_screen" />
386  <enum name="prohib_failed_screen" />
387  <enum name="prohib" />
388  <enum name="unavailable" />
389  </enumlist>
390  </description>
391  </configOption>
392  <configOption name="callerid_tag">
393  <synopsis>Internal id_tag for the endpoint</synopsis>
394  </configOption>
395  <configOption name="context">
396  <synopsis>Dialplan context for inbound sessions</synopsis>
397  </configOption>
398  <configOption name="direct_media_glare_mitigation" default="none">
399  <synopsis>Mitigation of direct media (re)INVITE glare</synopsis>
400  <description>
401  <para>
402  This setting attempts to avoid creating INVITE glare scenarios
403  by disabling direct media reINVITEs in one direction thereby allowing
404  designated servers (according to this option) to initiate direct
405  media reINVITEs without contention and significantly reducing call
406  setup time.
407  </para>
408  <para>
409  A more detailed description of how this option functions can be found on
410  the Asterisk wiki https://wiki.asterisk.org/wiki/display/AST/SIP+Direct+Media+Reinvite+Glare+Avoidance
411  </para>
412  <enumlist>
413  <enum name="none" />
414  <enum name="outgoing" />
415  <enum name="incoming" />
416  </enumlist>
417  </description>
418  </configOption>
419  <configOption name="direct_media_method" default="invite">
420  <synopsis>Direct Media method type</synopsis>
421  <description>
422  <para>Method for setting up Direct Media between endpoints.</para>
423  <enumlist>
424  <enum name="invite" />
425  <enum name="reinvite">
426  <para>Alias for the <literal>invite</literal> value.</para>
427  </enum>
428  <enum name="update" />
429  </enumlist>
430  </description>
431  </configOption>
432  <configOption name="trust_connected_line">
433  <synopsis>Accept Connected Line updates from this endpoint</synopsis>
434  </configOption>
435  <configOption name="send_connected_line">
436  <synopsis>Send Connected Line updates to this endpoint</synopsis>
437  </configOption>
438  <configOption name="connected_line_method" default="invite">
439  <synopsis>Connected line method type</synopsis>
440  <description>
441  <para>Method used when updating connected line information.</para>
442  <enumlist>
443  <enum name="invite">
444  <para>When set to <literal>invite</literal>, check the remote's Allow header and
445  if UPDATE is allowed, send UPDATE instead of INVITE to avoid SDP
446  renegotiation. If UPDATE is not Allowed, send INVITE.</para>
447  </enum>
448  <enum name="reinvite">
449  <para>Alias for the <literal>invite</literal> value.</para>
450  </enum>
451  <enum name="update">
452  <para>If set to <literal>update</literal>, send UPDATE regardless of what the remote
453  Allows. </para>
454  </enum>
455  </enumlist>
456  </description>
457  </configOption>
458  <configOption name="direct_media" default="yes">
459  <synopsis>Determines whether media may flow directly between endpoints.</synopsis>
460  </configOption>
461  <configOption name="disable_direct_media_on_nat" default="no">
462  <synopsis>Disable direct media session refreshes when NAT obstructs the media session</synopsis>
463  </configOption>
464  <configOption name="disallow">
465  <synopsis>Media Codec(s) to disallow</synopsis>
466  </configOption>
467  <configOption name="dtmf_mode" default="rfc4733">
468  <synopsis>DTMF mode</synopsis>
469  <description>
470  <para>This setting allows to choose the DTMF mode for endpoint communication.</para>
471  <enumlist>
472  <enum name="rfc4733">
473  <para>DTMF is sent out of band of the main audio stream. This
474  supercedes the older <emphasis>RFC-2833</emphasis> used within
475  the older <literal>chan_sip</literal>.</para>
476  </enum>
477  <enum name="inband">
478  <para>DTMF is sent as part of audio stream.</para>
479  </enum>
480  <enum name="info">
481  <para>DTMF is sent as SIP INFO packets.</para>
482  </enum>
483  <enum name="auto">
484  <para>DTMF is sent as RFC 4733 if the other side supports it or as INBAND if not.</para>
485  </enum>
486  <enum name="auto_info">
487  <para>DTMF is sent as RFC 4733 if the other side supports it or as SIP INFO if not.</para>
488  </enum>
489  </enumlist>
490  </description>
491  </configOption>
492  <configOption name="media_address">
493  <synopsis>IP address used in SDP for media handling</synopsis>
494  <description><para>
495  At the time of SDP creation, the IP address defined here will be used as
496  the media address for individual streams in the SDP.
497  </para>
498  <note><para>
499  Be aware that the <literal>external_media_address</literal> option, set in Transport
500  configuration, can also affect the final media address used in the SDP.
501  </para></note>
502  </description>
503  </configOption>
504  <configOption name="bind_rtp_to_media_address">
505  <synopsis>Bind the RTP instance to the media_address</synopsis>
506  <description><para>
507  If media_address is specified, this option causes the RTP instance to be bound to the
508  specified ip address which causes the packets to be sent from that address.
509  </para>
510  </description>
511  </configOption>
512  <configOption name="force_rport" default="yes">
513  <synopsis>Force use of return port</synopsis>
514  </configOption>
515  <configOption name="ice_support" default="no">
516  <synopsis>Enable the ICE mechanism to help traverse NAT</synopsis>
517  </configOption>
518  <configOption name="identify_by">
519  <synopsis>Way(s) for the endpoint to be identified</synopsis>
520  <description>
521  <para>Endpoints and AORs can be identified in multiple ways. This
522  option is a comma separated list of methods the endpoint can be
523  identified.
524  </para>
525  <note><para>
526  This option controls both how an endpoint is matched for incoming
527  traffic and also how an AOR is determined if a registration
528  occurs. You must list at least one method that also matches for
529  AORs or the registration will fail.
530  </para></note>
531  <enumlist>
532  <enum name="username">
533  <para>Matches the endpoint or AOR ID based on the username
534  and domain in the From header (or To header for AORs). If
535  an exact match on both username and domain/realm fails, the
536  match is retried with just the username.
537  </para>
538  </enum>
539  <enum name="auth_username">
540  <para>Matches the endpoint or AOR ID based on the username
541  and realm in the Authentication header. If an exact match
542  on both username and domain/realm fails, the match is
543  retried with just the username.
544  </para>
545  <note><para>This method of identification has some security
546  considerations because an Authentication header is not
547  present on the first message of a dialog when digest
548  authentication is used. The client can't generate it until
549  the server sends the challenge in a 401 response. Since
550  Asterisk normally sends a security event when an incoming
551  request can't be matched to an endpoint, using this method
552  requires that the security event be deferred until a request
553  is received with the Authentication header and only
554  generated if the username doesn't result in a match. This
555  may result in a delay before an attack is recognized. You
556  can control how many unmatched requests are received from
557  a single ip address before a security event is generated
558  using the <literal>unidentified_request</literal>
559  parameters in the "global" configuration object.
560  </para></note>
561  </enum>
562  <enum name="ip">
563  <para>Matches the endpoint based on the source IP address.
564  </para>
565  <para>This method of identification is not configured here
566  but simply allowed by this configuration option. See the
567  documentation for the <literal>identify</literal>
568  configuration section for more details on this method of
569  endpoint identification.
570  </para>
571  </enum>
572  <enum name="header">
573  <para>Matches the endpoint based on a configured SIP header
574  value.
575  </para>
576  <para>This method of identification is not configured here
577  but simply allowed by this configuration option. See the
578  documentation for the <literal>identify</literal>
579  configuration section for more details on this method of
580  endpoint identification.
581  </para>
582  </enum>
583  </enumlist>
584  </description>
585  </configOption>
586  <configOption name="redirect_method">
587  <synopsis>How redirects received from an endpoint are handled</synopsis>
588  <description><para>
589  When a redirect is received from an endpoint there are multiple ways it can be handled.
590  If this option is set to <literal>user</literal> the user portion of the redirect target
591  is treated as an extension within the dialplan and dialed using a Local channel. If this option
592  is set to <literal>uri_core</literal> the target URI is returned to the dialing application
593  which dials it using the PJSIP channel driver and endpoint originally used. If this option is
594  set to <literal>uri_pjsip</literal> the redirect occurs within chan_pjsip itself and is not exposed
595  to the core at all. The <literal>uri_pjsip</literal> option has the benefit of being more efficient
596  and also supporting multiple potential redirect targets. The con is that since redirection occurs
597  within chan_pjsip redirecting information is not forwarded and redirection can not be
598  prevented.
599  </para>
600  <enumlist>
601  <enum name="user" />
602  <enum name="uri_core" />
603  <enum name="uri_pjsip" />
604  </enumlist>
605  </description>
606  </configOption>
607  <configOption name="mailboxes">
608  <synopsis>NOTIFY the endpoint when state changes for any of the specified mailboxes</synopsis>
609  <description><para>
610  Asterisk will send unsolicited MWI NOTIFY messages to the endpoint when state
611  changes happen for any of the specified mailboxes. More than one mailbox can be
612  specified with a comma-delimited string. app_voicemail mailboxes must be specified
613  as [email protected]; for example: [email protected] For mailboxes provided by
614  external sources, such as through the res_mwi_external module, you must specify
615  strings supported by the external system.
616  </para><para>
617  For endpoints that SUBSCRIBE for MWI, use the <literal>mailboxes</literal> option in your AOR
618  configuration.
619  </para></description>
620  </configOption>
621  <configOption name="mwi_subscribe_replaces_unsolicited">
622  <synopsis>An MWI subscribe will replace sending unsolicited NOTIFYs</synopsis>
623  </configOption>
624  <configOption name="voicemail_extension">
625  <synopsis>The voicemail extension to send in the NOTIFY Message-Account header</synopsis>
626  </configOption>
627  <configOption name="moh_suggest" default="default">
628  <synopsis>Default Music On Hold class</synopsis>
629  </configOption>
630  <configOption name="outbound_auth">
631  <synopsis>Authentication object(s) used for outbound requests</synopsis>
632  <description><para>
633  This is a comma-delimited list of <replaceable>auth</replaceable>
634  sections defined in <filename>pjsip.conf</filename> used to respond
635  to outbound connection authentication challenges.</para>
636  <note><para>
637  Using the same auth section for inbound and outbound
638  authentication is not recommended. There is a difference in
639  meaning for an empty realm setting between inbound and outbound
640  authentication uses. See the auth realm description for details.
641  </para></note>
642  </description>
643  </configOption>
644  <configOption name="outbound_proxy">
645  <synopsis>Full SIP URI of the outbound proxy used to send requests</synopsis>
646  </configOption>
647  <configOption name="rewrite_contact">
648  <synopsis>Allow Contact header to be rewritten with the source IP address-port</synopsis>
649  <description><para>
650  On inbound SIP messages from this endpoint, the Contact header or an
651  appropriate Record-Route header will be changed to have the source IP
652  address and port. This option does not affect outbound messages sent to
653  this endpoint. This option helps servers communicate with endpoints
654  that are behind NATs. This option also helps reuse reliable transport
655  connections such as TCP and TLS.
656  </para></description>
657  </configOption>
658  <configOption name="rtp_ipv6" default="no">
659  <synopsis>Allow use of IPv6 for RTP traffic</synopsis>
660  </configOption>
661  <configOption name="rtp_symmetric" default="no">
662  <synopsis>Enforce that RTP must be symmetric</synopsis>
663  </configOption>
664  <configOption name="send_diversion" default="yes">
665  <synopsis>Send the Diversion header, conveying the diversion
666  information to the called user agent</synopsis>
667  </configOption>
668  <configOption name="send_history_info" default="no">
669  <synopsis>Send the History-Info header, conveying the diversion
670  information to the called and calling user agents</synopsis>
671  </configOption>
672  <configOption name="send_pai" default="no">
673  <synopsis>Send the P-Asserted-Identity header</synopsis>
674  </configOption>
675  <configOption name="send_rpid" default="no">
676  <synopsis>Send the Remote-Party-ID header</synopsis>
677  </configOption>
678  <configOption name="rpid_immediate" default="no">
679  <synopsis>Immediately send connected line updates on unanswered incoming calls.</synopsis>
680  <description>
681  <para>When enabled, immediately send <emphasis>180 Ringing</emphasis>
682  or <emphasis>183 Progress</emphasis> response messages to the
683  caller if the connected line information is updated before
684  the call is answered. This can send a <emphasis>180 Ringing</emphasis>
685  response before the call has even reached the far end. The
686  caller can start hearing ringback before the far end even gets
687  the call. Many phones tend to grab the first connected line
688  information and refuse to update the display if it changes. The
689  first information is not likely to be correct if the call
690  goes to an endpoint not under the control of this Asterisk
691  box.</para>
692  <para>When disabled, a connected line update must wait for
693  another reason to send a message with the connected line
694  information to the caller before the call is answered. You can
695  trigger the sending of the information by using an appropriate
696  dialplan application such as <emphasis>Ringing</emphasis>.</para>
697  </description>
698  </configOption>
699  <configOption name="timers_min_se" default="90">
700  <synopsis>Minimum session timers expiration period</synopsis>
701  <description><para>
702  Minimum session timer expiration period. Time in seconds.
703  </para></description>
704  </configOption>
705  <configOption name="timers" default="yes">
706  <synopsis>Session timers for SIP packets</synopsis>
707  <description>
708  <enumlist>
709  <enum name="no" />
710  <enum name="yes" />
711  <enum name="required" />
712  <enum name="always" />
713  <enum name="forced"><para>Alias of always</para></enum>
714  </enumlist>
715  </description>
716  </configOption>
717  <configOption name="timers_sess_expires" default="1800">
718  <synopsis>Maximum session timer expiration period</synopsis>
719  <description><para>
720  Maximum session timer expiration period. Time in seconds.
721  </para></description>
722  </configOption>
723  <configOption name="transport">
724  <synopsis>Explicit transport configuration to use</synopsis>
725  <description>
726  <para>This will <emphasis>force</emphasis> the endpoint to use the
727  specified transport configuration to send SIP messages. You need
728  to already know what kind of transport (UDP/TCP/IPv4/etc) the
729  endpoint device will use.
730  </para>
731  <note><para>Not specifying a transport will select the first
732  configured transport in <filename>pjsip.conf</filename> which is
733  compatible with the URI we are trying to contact.
734  </para></note>
735  <warning><para>Transport configuration is not affected by reloads. In order to
736  change transports, a full Asterisk restart is required</para></warning>
737  </description>
738  </configOption>
739  <configOption name="trust_id_inbound" default="no">
740  <synopsis>Accept identification information received from this endpoint</synopsis>
741  <description><para>This option determines whether Asterisk will accept
742  identification from the endpoint from headers such as P-Asserted-Identity
743  or Remote-Party-ID header. This option applies both to calls originating from the
744  endpoint and calls originating from Asterisk. If <literal>no</literal>, the
745  configured Caller-ID from pjsip.conf will always be used as the identity for
746  the endpoint.</para></description>
747  </configOption>
748  <configOption name="trust_id_outbound" default="no">
749  <synopsis>Send private identification details to the endpoint.</synopsis>
750  <description><para>This option determines whether res_pjsip will send private
751  identification information to the endpoint. If <literal>no</literal>,
752  private Caller-ID information will not be forwarded to the endpoint.
753  "Private" in this case refers to any method of restricting identification.
754  Example: setting <replaceable>callerid_privacy</replaceable> to any
755  <literal>prohib</literal> variation.
756  Example: If <replaceable>trust_id_inbound</replaceable> is set to
757  <literal>yes</literal>, the presence of a <literal>Privacy: id</literal>
758  header in a SIP request or response would indicate the identification
759  provided in the request is private.</para></description>
760  </configOption>
761  <configOption name="type">
762  <synopsis>Must be of type 'endpoint'.</synopsis>
763  </configOption>
764  <configOption name="use_ptime" default="no">
765  <synopsis>Use Endpoint's requested packetization interval</synopsis>
766  </configOption>
767  <configOption name="use_avpf" default="no">
768  <synopsis>Determines whether res_pjsip will use and enforce usage of AVPF for this
769  endpoint.</synopsis>
770  <description><para>
771  If set to <literal>yes</literal>, res_pjsip will use the AVPF or SAVPF RTP
772  profile for all media offers on outbound calls and media updates and will
773  decline media offers not using the AVPF or SAVPF profile.
774  </para><para>
775  If set to <literal>no</literal>, res_pjsip will use the AVP or SAVP RTP
776  profile for all media offers on outbound calls and media updates, and will
777  decline media offers not using the AVP or SAVP profile.
778  </para></description>
779  </configOption>
780  <configOption name="force_avp" default="no">
781  <synopsis>Determines whether res_pjsip will use and enforce usage of AVP,
782  regardless of the RTP profile in use for this endpoint.</synopsis>
783  <description><para>
784  If set to <literal>yes</literal>, res_pjsip will use the AVP, AVPF, SAVP, or
785  SAVPF RTP profile for all media offers on outbound calls and media updates including
786  those for DTLS-SRTP streams.
787  </para><para>
788  If set to <literal>no</literal>, res_pjsip will use the respective RTP profile
789  depending on configuration.
790  </para></description>
791  </configOption>
792  <configOption name="media_use_received_transport" default="no">
793  <synopsis>Determines whether res_pjsip will use the media transport received in the
794  offer SDP in the corresponding answer SDP.</synopsis>
795  <description><para>
796  If set to <literal>yes</literal>, res_pjsip will use the received media transport.
797  </para><para>
798  If set to <literal>no</literal>, res_pjsip will use the respective RTP profile
799  depending on configuration.
800  </para></description>
801  </configOption>
802  <configOption name="media_encryption" default="no">
803  <synopsis>Determines whether res_pjsip will use and enforce usage of media encryption
804  for this endpoint.</synopsis>
805  <description>
806  <enumlist>
807  <enum name="no"><para>
808  res_pjsip will offer no encryption and allow no encryption to be setup.
809  </para></enum>
810  <enum name="sdes"><para>
811  res_pjsip will offer standard SRTP setup via in-SDP keys. Encrypted SIP
812  transport should be used in conjunction with this option to prevent
813  exposure of media encryption keys.
814  </para></enum>
815  <enum name="dtls"><para>
816  res_pjsip will offer DTLS-SRTP setup.
817  </para></enum>
818  </enumlist>
819  </description>
820  </configOption>
821  <configOption name="media_encryption_optimistic" default="no">
822  <synopsis>Determines whether encryption should be used if possible but does not terminate the
823  session if not achieved.</synopsis>
824  <description><para>
825  This option only applies if <replaceable>media_encryption</replaceable> is
826  set to <literal>sdes</literal> or <literal>dtls</literal>.
827  </para></description>
828  </configOption>
829  <configOption name="g726_non_standard" default="no">
830  <synopsis>Force g.726 to use AAL2 packing order when negotiating g.726 audio</synopsis>
831  <description><para>
832  When set to "yes" and an endpoint negotiates g.726 audio then use g.726 for AAL2
833  packing order instead of what is recommended by RFC3551. Since this essentially
834  replaces the underlying 'g726' codec with 'g726aal2' then 'g726aal2' needs to be
835  specified in the endpoint's allowed codec list.
836  </para></description>
837  </configOption>
838  <configOption name="inband_progress" default="no">
839  <synopsis>Determines whether chan_pjsip will indicate ringing using inband
840  progress.</synopsis>
841  <description><para>
842  If set to <literal>yes</literal>, chan_pjsip will send a 183 Session Progress
843  when told to indicate ringing and will immediately start sending ringing
844  as audio.
845  </para><para>
846  If set to <literal>no</literal>, chan_pjsip will send a 180 Ringing when told
847  to indicate ringing and will NOT send it as audio.
848  </para></description>
849  </configOption>
850  <configOption name="call_group">
851  <synopsis>The numeric pickup groups for a channel.</synopsis>
852  <description><para>
853  Can be set to a comma separated list of numbers or ranges between the values
854  of 0-63 (maximum of 64 groups).
855  </para></description>
856  </configOption>
857  <configOption name="pickup_group">
858  <synopsis>The numeric pickup groups that a channel can pickup.</synopsis>
859  <description><para>
860  Can be set to a comma separated list of numbers or ranges between the values
861  of 0-63 (maximum of 64 groups).
862  </para></description>
863  </configOption>
864  <configOption name="named_call_group">
865  <synopsis>The named pickup groups for a channel.</synopsis>
866  <description><para>
867  Can be set to a comma separated list of case sensitive strings limited by
868  supported line length.
869  </para></description>
870  </configOption>
871  <configOption name="named_pickup_group">
872  <synopsis>The named pickup groups that a channel can pickup.</synopsis>
873  <description><para>
874  Can be set to a comma separated list of case sensitive strings limited by
875  supported line length.
876  </para></description>
877  </configOption>
878  <configOption name="device_state_busy_at" default="0">
879  <synopsis>The number of in-use channels which will cause busy to be returned as device state</synopsis>
880  <description><para>
881  When the number of in-use channels for the endpoint matches the devicestate_busy_at setting the
882  PJSIP channel driver will return busy as the device state instead of in use.
883  </para></description>
884  </configOption>
885  <configOption name="t38_udptl" default="no">
886  <synopsis>Whether T.38 UDPTL support is enabled or not</synopsis>
887  <description><para>
888  If set to yes T.38 UDPTL support will be enabled, and T.38 negotiation requests will be accepted
889  and relayed.
890  </para></description>
891  </configOption>
892  <configOption name="t38_udptl_ec" default="none">
893  <synopsis>T.38 UDPTL error correction method</synopsis>
894  <description>
895  <enumlist>
896  <enum name="none"><para>
897  No error correction should be used.
898  </para></enum>
899  <enum name="fec"><para>
900  Forward error correction should be used.
901  </para></enum>
902  <enum name="redundancy"><para>
903  Redundancy error correction should be used.
904  </para></enum>
905  </enumlist>
906  </description>
907  </configOption>
908  <configOption name="t38_udptl_maxdatagram" default="0">
909  <synopsis>T.38 UDPTL maximum datagram size</synopsis>
910  <description><para>
911  This option can be set to override the maximum datagram of a remote endpoint for broken
912  endpoints.
913  </para></description>
914  </configOption>
915  <configOption name="fax_detect" default="no">
916  <synopsis>Whether CNG tone detection is enabled</synopsis>
917  <description><para>
918  This option can be set to send the session to the fax extension when a CNG tone is
919  detected.
920  </para></description>
921  </configOption>
922  <configOption name="fax_detect_timeout">
923  <synopsis>How long into a call before fax_detect is disabled for the call</synopsis>
924  <description><para>
925  The option determines how many seconds into a call before the
926  fax_detect option is disabled for the call. Setting the value
927  to zero disables the timeout.
928  </para></description>
929  </configOption>
930  <configOption name="t38_udptl_nat" default="no">
931  <synopsis>Whether NAT support is enabled on UDPTL sessions</synopsis>
932  <description><para>
933  When enabled the UDPTL stack will send UDPTL packets to the source address of
934  received packets.
935  </para></description>
936  </configOption>
937  <configOption name="t38_udptl_ipv6" default="no">
938  <synopsis>Whether IPv6 is used for UDPTL Sessions</synopsis>
939  <description><para>
940  When enabled the UDPTL stack will use IPv6.
941  </para></description>
942  </configOption>
943  <configOption name="tone_zone">
944  <synopsis>Set which country's indications to use for channels created for this endpoint.</synopsis>
945  </configOption>
946  <configOption name="language">
947  <synopsis>Set the default language to use for channels created for this endpoint.</synopsis>
948  </configOption>
949  <configOption name="one_touch_recording" default="no">
950  <synopsis>Determines whether one-touch recording is allowed for this endpoint.</synopsis>
951  <see-also>
952  <ref type="configOption">record_on_feature</ref>
953  <ref type="configOption">record_off_feature</ref>
954  </see-also>
955  </configOption>
956  <configOption name="record_on_feature" default="automixmon">
957  <synopsis>The feature to enact when one-touch recording is turned on.</synopsis>
958  <description>
959  <para>When an INFO request for one-touch recording arrives with a Record header set to "on", this
960  feature will be enabled for the channel. The feature designated here can be any built-in
961  or dynamic feature defined in features.conf.</para>
962  <note><para>This setting has no effect if the endpoint's one_touch_recording option is disabled</para></note>
963  </description>
964  <see-also>
965  <ref type="configOption">one_touch_recording</ref>
966  <ref type="configOption">record_off_feature</ref>
967  </see-also>
968  </configOption>
969  <configOption name="record_off_feature" default="automixmon">
970  <synopsis>The feature to enact when one-touch recording is turned off.</synopsis>
971  <description>
972  <para>When an INFO request for one-touch recording arrives with a Record header set to "off", this
973  feature will be enabled for the channel. The feature designated here can be any built-in
974  or dynamic feature defined in features.conf.</para>
975  <note><para>This setting has no effect if the endpoint's one_touch_recording option is disabled</para></note>
976  </description>
977  <see-also>
978  <ref type="configOption">one_touch_recording</ref>
979  <ref type="configOption">record_on_feature</ref>
980  </see-also>
981  </configOption>
982  <configOption name="rtp_engine" default="asterisk">
983  <synopsis>Name of the RTP engine to use for channels created for this endpoint</synopsis>
984  </configOption>
985  <configOption name="allow_transfer" default="yes">
986  <synopsis>Determines whether SIP REFER transfers are allowed for this endpoint</synopsis>
987  </configOption>
988  <configOption name="user_eq_phone" default="no">
989  <synopsis>Determines whether a user=phone parameter is placed into the request URI if the user is determined to be a phone number</synopsis>
990  </configOption>
991  <configOption name="moh_passthrough" default="no">
992  <synopsis>Determines whether hold and unhold will be passed through using re-INVITEs with recvonly and sendrecv to the remote side</synopsis>
993  </configOption>
994  <configOption name="sdp_owner" default="-">
995  <synopsis>String placed as the username portion of an SDP origin (o=) line.</synopsis>
996  </configOption>
997  <configOption name="sdp_session" default="Asterisk">
998  <synopsis>String used for the SDP session (s=) line.</synopsis>
999  </configOption>
1000  <configOption name="tos_audio">
1001  <synopsis>DSCP TOS bits for audio streams</synopsis>
1002  <description><para>
1003  See https://wiki.asterisk.org/wiki/display/AST/IP+Quality+of+Service for more information about QoS settings
1004  </para></description>
1005  </configOption>
1006  <configOption name="tos_video">
1007  <synopsis>DSCP TOS bits for video streams</synopsis>
1008  <description><para>
1009  See https://wiki.asterisk.org/wiki/display/AST/IP+Quality+of+Service for more information about QoS settings
1010  </para></description>
1011  </configOption>
1012  <configOption name="cos_audio">
1013  <synopsis>Priority for audio streams</synopsis>
1014  <description><para>
1015  See https://wiki.asterisk.org/wiki/display/AST/IP+Quality+of+Service for more information about QoS settings
1016  </para></description>
1017  </configOption>
1018  <configOption name="cos_video">
1019  <synopsis>Priority for video streams</synopsis>
1020  <description><para>
1021  See https://wiki.asterisk.org/wiki/display/AST/IP+Quality+of+Service for more information about QoS settings
1022  </para></description>
1023  </configOption>
1024  <configOption name="allow_subscribe" default="yes">
1025  <synopsis>Determines if endpoint is allowed to initiate subscriptions with Asterisk.</synopsis>
1026  </configOption>
1027  <configOption name="sub_min_expiry" default="60">
1028  <synopsis>The minimum allowed expiry time for subscriptions initiated by the endpoint.</synopsis>
1029  </configOption>
1030  <configOption name="from_user">
1031  <synopsis>Username to use in From header for requests to this endpoint.</synopsis>
1032  </configOption>
1033  <configOption name="mwi_from_user">
1034  <synopsis>Username to use in From header for unsolicited MWI NOTIFYs to this endpoint.</synopsis>
1035  </configOption>
1036  <configOption name="from_domain">
1037  <synopsis>Domain to user in From header for requests to this endpoint.</synopsis>
1038  </configOption>
1039  <configOption name="dtls_verify">
1040  <synopsis>Verify that the provided peer certificate is valid</synopsis>
1041  <description><para>
1042  This option only applies if <replaceable>media_encryption</replaceable> is
1043  set to <literal>dtls</literal>.
1044  </para><para>
1045  It can be one of the following values:
1046  </para><enumlist>
1047  <enum name="no"><para>
1048  meaning no verificaton is done.
1049  </para></enum>
1050  <enum name="fingerprint"><para>
1051  meaning to verify the remote fingerprint.
1052  </para></enum>
1053  <enum name="certificate"><para>
1054  meaning to verify the remote certificate.
1055  </para></enum>
1056  <enum name="yes"><para>
1057  meaning to verify both the remote fingerprint and certificate.
1058  </para></enum>
1059  </enumlist>
1060  </description>
1061  </configOption>
1062  <configOption name="dtls_rekey">
1063  <synopsis>Interval at which to renegotiate the TLS session and rekey the SRTP session</synopsis>
1064  <description><para>
1065  This option only applies if <replaceable>media_encryption</replaceable> is
1066  set to <literal>dtls</literal>.
1067  </para><para>
1068  If this is not set or the value provided is 0 rekeying will be disabled.
1069  </para></description>
1070  </configOption>
1071  <configOption name="dtls_auto_generate_cert" default="no">
1072  <synopsis>Whether or not to automatically generate an ephemeral X.509 certificate</synopsis>
1073  <description>
1074  <para>
1075  If enabled, Asterisk will generate an X.509 certificate for each DTLS session.
1076  This option only applies if <replaceable>media_encryption</replaceable> is set
1077  to <literal>dtls</literal>. This option will be automatically enabled if
1078  <literal>webrtc</literal> is enabled and <literal>dtls_cert_file</literal> is
1079  not specified.
1080  </para>
1081  </description>
1082  </configOption>
1083  <configOption name="dtls_cert_file">
1084  <synopsis>Path to certificate file to present to peer</synopsis>
1085  <description><para>
1086  This option only applies if <replaceable>media_encryption</replaceable> is
1087  set to <literal>dtls</literal>.
1088  </para></description>
1089  </configOption>
1090  <configOption name="dtls_private_key">
1091  <synopsis>Path to private key for certificate file</synopsis>
1092  <description><para>
1093  This option only applies if <replaceable>media_encryption</replaceable> is
1094  set to <literal>dtls</literal>.
1095  </para></description>
1096  </configOption>
1097  <configOption name="dtls_cipher">
1098  <synopsis>Cipher to use for DTLS negotiation</synopsis>
1099  <description><para>
1100  This option only applies if <replaceable>media_encryption</replaceable> is
1101  set to <literal>dtls</literal>.
1102  </para>
1103  <para>Many options for acceptable ciphers. See link for more:</para>
1104  <para>http://www.openssl.org/docs/apps/ciphers.html#CIPHER_STRINGS
1105  </para></description>
1106  </configOption>
1107  <configOption name="dtls_ca_file">
1108  <synopsis>Path to certificate authority certificate</synopsis>
1109  <description><para>
1110  This option only applies if <replaceable>media_encryption</replaceable> is
1111  set to <literal>dtls</literal>.
1112  </para></description>
1113  </configOption>
1114  <configOption name="dtls_ca_path">
1115  <synopsis>Path to a directory containing certificate authority certificates</synopsis>
1116  <description><para>
1117  This option only applies if <replaceable>media_encryption</replaceable> is
1118  set to <literal>dtls</literal>.
1119  </para></description>
1120  </configOption>
1121  <configOption name="dtls_setup">
1122  <synopsis>Whether we are willing to accept connections, connect to the other party, or both.</synopsis>
1123  <description>
1124  <para>
1125  This option only applies if <replaceable>media_encryption</replaceable> is
1126  set to <literal>dtls</literal>.
1127  </para>
1128  <enumlist>
1129  <enum name="active"><para>
1130  res_pjsip will make a connection to the peer.
1131  </para></enum>
1132  <enum name="passive"><para>
1133  res_pjsip will accept connections from the peer.
1134  </para></enum>
1135  <enum name="actpass"><para>
1136  res_pjsip will offer and accept connections from the peer.
1137  </para></enum>
1138  </enumlist>
1139  </description>
1140  </configOption>
1141  <configOption name="dtls_fingerprint">
1142  <synopsis>Type of hash to use for the DTLS fingerprint in the SDP.</synopsis>
1143  <description>
1144  <para>
1145  This option only applies if <replaceable>media_encryption</replaceable> is
1146  set to <literal>dtls</literal>.
1147  </para>
1148  <enumlist>
1149  <enum name="SHA-256"></enum>
1150  <enum name="SHA-1"></enum>
1151  </enumlist>
1152  </description>
1153  </configOption>
1154  <configOption name="srtp_tag_32">
1155  <synopsis>Determines whether 32 byte tags should be used instead of 80 byte tags.</synopsis>
1156  <description><para>
1157  This option only applies if <replaceable>media_encryption</replaceable> is
1158  set to <literal>sdes</literal> or <literal>dtls</literal>.
1159  </para></description>
1160  </configOption>
1161  <configOption name="set_var">
1162  <synopsis>Variable set on a channel involving the endpoint.</synopsis>
1163  <description><para>
1164  When a new channel is created using the endpoint set the specified
1165  variable(s) on that channel. For multiple channel variables specify
1166  multiple 'set_var'(s).
1167  </para></description>
1168  </configOption>
1169  <configOption name="message_context">
1170  <synopsis>Context to route incoming MESSAGE requests to.</synopsis>
1171  <description><para>
1172  If specified, incoming MESSAGE requests will be routed to the indicated
1173  dialplan context. If no <replaceable>message_context</replaceable> is
1174  specified, then the <replaceable>context</replaceable> setting is used.
1175  </para></description>
1176  </configOption>
1177  <configOption name="accountcode">
1178  <synopsis>An accountcode to set automatically on any channels created for this endpoint.</synopsis>
1179  <description><para>
1180  If specified, any channel created for this endpoint will automatically
1181  have this accountcode set on it.
1182  </para></description>
1183  </configOption>
1184  <configOption name="preferred_codec_only" default="no">
1185  <synopsis>Respond to a SIP invite with the single most preferred codec (DEPRECATED)</synopsis>
1186  <description><para>Respond to a SIP invite with the single most preferred codec
1187  rather than advertising all joint codec capabilities. This limits the other side's codec
1188  choice to exactly what we prefer.</para>
1189  <warning><para>This option has been deprecated in favor of
1190  <literal>incoming_call_offer_pref</literal>. Setting both options is unsupported.</para>
1191  </warning>
1192  </description>
1193  <see-also>
1194  <ref type="configOption">incoming_call_offer_pref</ref>
1195  </see-also>
1196  </configOption>
1197  <configOption name="incoming_call_offer_pref" default="local">
1198  <synopsis>Preferences for selecting codecs for an incoming call.</synopsis>
1199  <description>
1200  <para>Based on this setting, a joint list of preferred codecs between those
1201  received in an incoming SDP offer (remote), and those specified in the
1202  endpoint's "allow" parameter (local) es created and is passed to the Asterisk
1203  core. </para>
1204  <note><para>This list will consist of only those codecs found in both lists.</para></note>
1205  <enumlist>
1206  <enum name="local"><para>
1207  Include all codecs in the local list that are also in the remote list
1208  preserving the local order. (default).
1209  </para></enum>
1210  <enum name="local_first"><para>
1211  Include only the first codec in the local list that is also in the remote list.
1212  </para></enum>
1213  <enum name="remote"><para>
1214  Include all codecs in the remote list that are also in the local list
1215  preserving the remote order.
1216  </para></enum>
1217  <enum name="remote_first"><para>
1218  Include only the first codec in the remote list that is also in the local list.
1219  </para></enum>
1220  </enumlist>
1221  </description>
1222  </configOption>
1223  <configOption name="outgoing_call_offer_pref" default="remote_merge">
1224  <synopsis>Preferences for selecting codecs for an outgoing call.</synopsis>
1225  <description>
1226  <para>Based on this setting, a joint list of preferred codecs between
1227  those received from the Asterisk core (remote), and those specified in
1228  the endpoint's "allow" parameter (local) is created and is used to create
1229  the outgoing SDP offer.</para>
1230  <enumlist>
1231  <enum name="local"><para>
1232  Include all codecs in the local list that are also in the remote list
1233  preserving the local order.
1234  </para></enum>
1235  <enum name="local_merge"><para>
1236  Include all codecs in the local list preserving the local order.
1237  </para></enum>
1238  <enum name="local_first"><para>
1239  Include only the first codec in the local list.
1240  </para></enum>
1241  <enum name="remote"><para>
1242  Include all codecs in the remote list that are also in the local list
1243  preserving the remote order.
1244  </para></enum>
1245  <enum name="remote_merge"><para>
1246  Include all codecs in the local list preserving the remote order. (default)
1247  </para></enum>
1248  <enum name="remote_first"><para>
1249  Include only the first codec in the remote list that is also in the local list.
1250  </para></enum>
1251  </enumlist>
1252  </description>
1253  </configOption>
1254  <configOption name="rtp_keepalive">
1255  <synopsis>Number of seconds between RTP comfort noise keepalive packets.</synopsis>
1256  <description><para>
1257  At the specified interval, Asterisk will send an RTP comfort noise frame. This may
1258  be useful for situations where Asterisk is behind a NAT or firewall and must keep
1259  a hole open in order to allow for media to arrive at Asterisk.
1260  </para></description>
1261  </configOption>
1262  <configOption name="rtp_timeout" default="0">
1263  <synopsis>Maximum number of seconds without receiving RTP (while off hold) before terminating call.</synopsis>
1264  <description><para>
1265  This option configures the number of seconds without RTP (while off hold) before
1266  considering a channel as dead. When the number of seconds is reached the underlying
1267  channel is hung up. By default this option is set to 0, which means do not check.
1268  </para></description>
1269  </configOption>
1270  <configOption name="rtp_timeout_hold" default="0">
1271  <synopsis>Maximum number of seconds without receiving RTP (while on hold) before terminating call.</synopsis>
1272  <description><para>
1273  This option configures the number of seconds without RTP (while on hold) before
1274  considering a channel as dead. When the number of seconds is reached the underlying
1275  channel is hung up. By default this option is set to 0, which means do not check.
1276  </para></description>
1277  </configOption>
1278  <configOption name="acl">
1279  <synopsis>List of IP ACL section names in acl.conf</synopsis>
1280  <description><para>
1281  This matches sections configured in <literal>acl.conf</literal>. The value is
1282  defined as a list of comma-delimited section names.
1283  </para></description>
1284  </configOption>
1285  <configOption name="deny">
1286  <synopsis>List of IP addresses to deny access from</synopsis>
1287  <description><para>
1288  The value is a comma-delimited list of IP addresses. IP addresses may
1289  have a subnet mask appended. The subnet mask may be written in either
1290  CIDR or dotted-decimal notation. Separate the IP address and subnet
1291  mask with a slash ('/')
1292  </para></description>
1293  </configOption>
1294  <configOption name="permit">
1295  <synopsis>List of IP addresses to permit access from</synopsis>
1296  <description><para>
1297  The value is a comma-delimited list of IP addresses. IP addresses may
1298  have a subnet mask appended. The subnet mask may be written in either
1299  CIDR or dotted-decimal notation. Separate the IP address and subnet
1300  mask with a slash ('/')
1301  </para></description>
1302  </configOption>
1303  <configOption name="contact_acl">
1304  <synopsis>List of Contact ACL section names in acl.conf</synopsis>
1305  <description><para>
1306  This matches sections configured in <literal>acl.conf</literal>. The value is
1307  defined as a list of comma-delimited section names.
1308  </para></description>
1309  </configOption>
1310  <configOption name="contact_deny">
1311  <synopsis>List of Contact header addresses to deny</synopsis>
1312  <description><para>
1313  The value is a comma-delimited list of IP addresses. IP addresses may
1314  have a subnet mask appended. The subnet mask may be written in either
1315  CIDR or dotted-decimal notation. Separate the IP address and subnet
1316  mask with a slash ('/')
1317  </para></description>
1318  </configOption>
1319  <configOption name="contact_permit">
1320  <synopsis>List of Contact header addresses to permit</synopsis>
1321  <description><para>
1322  The value is a comma-delimited list of IP addresses. IP addresses may
1323  have a subnet mask appended. The subnet mask may be written in either
1324  CIDR or dotted-decimal notation. Separate the IP address and subnet
1325  mask with a slash ('/')
1326  </para></description>
1327  </configOption>
1328  <configOption name="subscribe_context">
1329  <synopsis>Context for incoming MESSAGE requests.</synopsis>
1330  <description><para>
1331  If specified, incoming SUBSCRIBE requests will be searched for the matching
1332  extension in the indicated context.
1333  If no <replaceable>subscribe_context</replaceable> is specified,
1334  then the <replaceable>context</replaceable> setting is used.
1335  </para></description>
1336  </configOption>
1337  <configOption name="contact_user" default="">
1338  <synopsis>Force the user on the outgoing Contact header to this value.</synopsis>
1339  <description><para>
1340  On outbound requests, force the user portion of the Contact header to this value.
1341  </para></description>
1342  </configOption>
1343  <configOption name="asymmetric_rtp_codec" default="no">
1344  <synopsis>Allow the sending and receiving RTP codec to differ</synopsis>
1345  <description><para>
1346  When set to "yes" the codec in use for sending will be allowed to differ from
1347  that of the received one. PJSIP will not automatically switch the sending one
1348  to the receiving one.
1349  </para></description>
1350  </configOption>
1351  <configOption name="rtcp_mux" default="no">
1352  <synopsis>Enable RFC 5761 RTCP multiplexing on the RTP port</synopsis>
1353  <description><para>
1354  With this option enabled, Asterisk will attempt to negotiate the use of the "rtcp-mux"
1355  attribute on all media streams. This will result in RTP and RTCP being sent and received
1356  on the same port. This shifts the demultiplexing logic to the application rather than
1357  the transport layer. This option is useful when interoperating with WebRTC endpoints
1358  since they mandate this option's use.
1359  </para></description>
1360  </configOption>
1361  <configOption name="refer_blind_progress" default="yes">
1362  <synopsis>Whether to notifies all the progress details on blind transfer</synopsis>
1363  <description><para>
1364  Some SIP phones (Mitel/Aastra, Snom) expect a sip/frag "200 OK"
1365  after REFER has been accepted. If set to <literal>no</literal> then asterisk
1366  will not send the progress details, but immediately will send "200 OK".
1367  </para></description>
1368  </configOption>
1369  <configOption name="notify_early_inuse_ringing" default="no">
1370  <synopsis>Whether to notifies dialog-info 'early' on InUse&amp;Ringing state</synopsis>
1371  <description><para>
1372  Control whether dialog-info subscriptions get 'early' state
1373  on Ringing when already INUSE.
1374  </para></description>
1375  </configOption>
1376  <configOption name="max_audio_streams" default="1">
1377  <synopsis>The maximum number of allowed audio streams for the endpoint</synopsis>
1378  <description><para>
1379  This option enforces a limit on the maximum simultaneous negotiated audio
1380  streams allowed for the endpoint.
1381  </para></description>
1382  </configOption>
1383  <configOption name="max_video_streams" default="1">
1384  <synopsis>The maximum number of allowed video streams for the endpoint</synopsis>
1385  <description><para>
1386  This option enforces a limit on the maximum simultaneous negotiated video
1387  streams allowed for the endpoint.
1388  </para></description>
1389  </configOption>
1390  <configOption name="bundle" default="no">
1391  <synopsis>Enable RTP bundling</synopsis>
1392  <description><para>
1393  With this option enabled, Asterisk will attempt to negotiate the use of bundle.
1394  If negotiated this will result in multiple RTP streams being carried over the same
1395  underlying transport. Note that enabling bundle will also enable the rtcp_mux option.
1396  </para></description>
1397  </configOption>
1398  <configOption name="webrtc" default="no">
1399  <synopsis>Defaults and enables some options that are relevant to WebRTC</synopsis>
1400  <description><para>
1401  When set to "yes" this also enables the following values that are needed in
1402  order for basic WebRTC support to work: rtcp_mux, use_avpf, ice_support, and
1403  use_received_transport. The following configuration settings also get defaulted
1404  as follows:</para>
1405  <para>media_encryption=dtls</para>
1406  <para>dtls_auto_generate_cert=yes (if dtls_cert_file is not set)</para>
1407  <para>dtls_verify=fingerprint</para>
1408  <para>dtls_setup=actpass</para>
1409  </description>
1410  </configOption>
1411  <configOption name="incoming_mwi_mailbox">
1412  <synopsis>Mailbox name to use when incoming MWI NOTIFYs are received</synopsis>
1413  <description><para>
1414  If an MWI NOTIFY is received <emphasis>from</emphasis> this endpoint,
1415  this mailbox will be used when notifying other modules of MWI status
1416  changes. If not set, incoming MWI NOTIFYs are ignored.
1417  </para></description>
1418  </configOption>
1419  <configOption name="follow_early_media_fork">
1420  <synopsis>Follow SDP forked media when To tag is different</synopsis>
1421  <description><para>
1422  On outgoing calls, if the UAS responds with different SDP attributes
1423  on subsequent 18X or 2XX responses (such as a port update) AND the
1424  To tag on the subsequent response is different than that on the previous
1425  one, follow it. This usually happens when the INVITE is forked to multiple
1426  UASs and more than one sends an SDP answer.
1427  </para>
1428  <note><para>
1429  This option must also be enabled in the <literal>system</literal>
1430  section for it to take effect here.
1431  </para></note>
1432  </description>
1433  </configOption>
1434  <configOption name="accept_multiple_sdp_answers" default="no">
1435  <synopsis>Accept multiple SDP answers on non-100rel responses</synopsis>
1436  <description><para>
1437  On outgoing calls, if the UAS responds with different SDP attributes
1438  on non-100rel 18X or 2XX responses (such as a port update) AND the
1439  To tag on the subsequent response is the same as that on the previous one,
1440  process the updated SDP. This can happen when the UAS needs to change ports
1441  for some reason such as using a separate port for custom ringback.
1442  </para>
1443  <note><para>
1444  This option must also be enabled in the <literal>system</literal>
1445  section for it to take effect here.
1446  </para></note>
1447  </description>
1448  </configOption>
1449  <configOption name="suppress_q850_reason_headers" default="no">
1450  <synopsis>Suppress Q.850 Reason headers for this endpoint</synopsis>
1451  <description><para>
1452  Some devices can't accept multiple Reason headers and get confused
1453  when both 'SIP' and 'Q.850' Reason headers are received. This
1454  option allows the 'Q.850' Reason header to be suppressed.</para>
1455  </description>
1456  </configOption>
1457  <configOption name="ignore_183_without_sdp" default="no">
1458  <synopsis>Do not forward 183 when it doesn't contain SDP</synopsis>
1459  <description><para>
1460  Certain SS7 internetworking scenarios can result in a 183
1461  to be generated for reasons other than early media. Forwarding
1462  this 183 can cause loss of ringback tone. This flag emulates
1463  the behavior of chan_sip and prevents these 183 responses from
1464  being forwarded.</para>
1465  </description>
1466  </configOption>
1467  <configOption name="stir_shaken" default="no">
1468  <synopsis>Enable STIR/SHAKEN support on this endpoint</synopsis>
1469  <description><para>
1470  Enable STIR/SHAKEN support on this endpoint. On incoming INVITEs,
1471  the Identity header will be checked for validity. On outgoing
1472  INVITEs, an Identity header will be added.</para>
1473  </description>
1474  </configOption>
1475  <configOption name="allow_unauthenticated_options" default="no">
1476  <synopsis>Skip authentication when receiving OPTIONS requests</synopsis>
1477  <description><para>
1478  RFC 3261 says that the response to an OPTIONS request MUST be the
1479  same had the request been an INVITE. Some UAs use OPTIONS requests
1480  like a 'ping' and the expectation is that they will return a
1481  200 OK.</para>
1482  <para>Enabling <literal>allow_unauthenticated_options</literal>
1483  will skip authentication of OPTIONS requests for the given
1484  endpoint.</para>
1485  <para>There are security implications to enabling this setting as
1486  it can allow information disclosure to occur - specifically, if
1487  enabled, an external party could enumerate and find the endpoint
1488  name by sending OPTIONS requests and examining the
1489  responses.</para>
1490  </description>
1491  </configOption>
1492  </configObject>
1493  <configObject name="auth">
1494  <synopsis>Authentication type</synopsis>
1495  <description><para>
1496  Authentication objects hold the authentication information for use
1497  by other objects such as <literal>endpoints</literal> or <literal>registrations</literal>.
1498  This also allows for multiple objects to use a single auth object. See
1499  the <literal>auth_type</literal> config option for password style choices.
1500  </para></description>
1501  <configOption name="auth_type" default="userpass">
1502  <synopsis>Authentication type</synopsis>
1503  <description><para>
1504  This option specifies which of the password style config options should be read
1505  when trying to authenticate an endpoint inbound request. If set to <literal>userpass</literal>
1506  then we'll read from the 'password' option. For <literal>md5</literal> we'll read
1507  from 'md5_cred'. If set to <literal>google_oauth</literal> then we'll read from the
1508  refresh_token/oauth_clientid/oauth_secret fields. The following values are valid:
1509  </para>
1510  <enumlist>
1511  <enum name="md5"/>
1512  <enum name="userpass"/>
1513  <enum name="google_oauth"/>
1514  </enumlist>
1515  <para>
1516  </para>
1517  <note>
1518  <para>
1519  This setting only describes whether the password is in
1520  plain text or has been pre-hashed with MD5. It doesn't describe
1521  the acceptable digest algorithms we'll accept in a received
1522  challenge.
1523  </para>
1524  </note>
1525  </description>
1526  </configOption>
1527  <configOption name="nonce_lifetime" default="32">
1528  <synopsis>Lifetime of a nonce associated with this authentication config.</synopsis>
1529  </configOption>
1530  <configOption name="md5_cred" default="">
1531  <synopsis>MD5 Hash used for authentication.</synopsis>
1532  <description><para>
1533  Only used when auth_type is <literal>md5</literal>.
1534  As an alternative to specifying a plain text password,
1535  you can hash the username, realm and password
1536  together one time and place the hash value here.
1537  The input to the hash function must be in the
1538  following format:
1539  </para>
1540  <para>
1541  </para>
1542  <para>
1543  &lt;username&gt;:&lt;realm&gt;:&lt;password&gt;
1544  </para>
1545  <para>
1546  </para>
1547  <para>
1548  For incoming authentication (asterisk is the server),
1549  the realm must match either the realm set in this object
1550  or the <variable>default_realm</variable> set in in the
1551  <replaceable>global</replaceable> object.
1552  </para>
1553  <para>
1554  </para>
1555  <para>
1556  For outgoing authentication (asterisk is the UAC),
1557  the realm must match what the server will be sending
1558  in their WWW-Authenticate header. It can't be blank
1559  unless you expect the server to be sending a blank
1560  realm in the header. You can't use pre-hashed
1561  paswords with a wildcard auth object.
1562  You can generate the hash with the following shell
1563  command:
1564  </para>
1565  <para>
1566  </para>
1567  <para>
1568  $ echo -n "myname:myrealm:mypassword" | md5sum
1569  </para>
1570  <para>
1571  </para>
1572  <para>
1573  Note the '-n'. You don't want a newline to be part
1574  of the hash.
1575  </para></description>
1576  </configOption>
1577  <configOption name="password">
1578  <synopsis>Plain text password used for authentication.</synopsis>
1579  <description><para>Only used when auth_type is <literal>userpass</literal>.</para></description>
1580  </configOption>
1581  <configOption name="refresh_token">
1582  <synopsis>OAuth 2.0 refresh token</synopsis>
1583  </configOption>
1584  <configOption name="oauth_clientid">
1585  <synopsis>OAuth 2.0 application's client id</synopsis>
1586  </configOption>
1587  <configOption name="oauth_secret">
1588  <synopsis>OAuth 2.0 application's secret</synopsis>
1589  </configOption>
1590  <configOption name="realm" default="">
1591  <synopsis>SIP realm for endpoint</synopsis>
1592  <description><para>
1593  For incoming authentication (asterisk is the UAS),
1594  this is the realm to be sent on WWW-Authenticate
1595  headers. If not specified, the <replaceable>global</replaceable>
1596  object's <variable>default_realm</variable> will be used.
1597  </para>
1598  <para>
1599  </para>
1600  <para>
1601  For outgoing authentication (asterisk is the UAS), this
1602  must either be the realm the server is expected to send,
1603  or left blank or contain a single '*' to automatically
1604  use the realm sent by the server. If you have multiple
1605  auth object for an endpoint, the realm is also used to
1606  match the auth object to the realm the server sent.
1607  </para>
1608  <para>
1609  </para>
1610  <note>
1611  <para>
1612  Using the same auth section for inbound and outbound
1613  authentication is not recommended. There is a difference in
1614  meaning for an empty realm setting between inbound and outbound
1615  authentication uses.
1616  </para>
1617  </note>
1618  <para>
1619  </para>
1620  <note>
1621  <para>
1622  If more than one auth object with the same realm or
1623  more than one wildcard auth object associated to
1624  an endpoint, we can only use the first one of
1625  each defined on the endpoint.
1626  </para>
1627  </note>
1628  </description>
1629  </configOption>
1630  <configOption name="type">
1631  <synopsis>Must be 'auth'</synopsis>
1632  </configOption>
1633  <configOption name="username">
1634  <synopsis>Username to use for account</synopsis>
1635  </configOption>
1636  </configObject>
1637  <configObject name="domain_alias">
1638  <synopsis>Domain Alias</synopsis>
1639  <description><para>
1640  Signifies that a domain is an alias. If the domain on a session is
1641  not found to match an AoR then this object is used to see if we have
1642  an alias for the AoR to which the endpoint is binding. This objects
1643  name as defined in configuration should be the domain alias and a
1644  config option is provided to specify the domain to be aliased.
1645  </para></description>
1646  <configOption name="type">
1647  <synopsis>Must be of type 'domain_alias'.</synopsis>
1648  </configOption>
1649  <configOption name="domain">
1650  <synopsis>Domain to be aliased</synopsis>
1651  </configOption>
1652  </configObject>
1653  <configObject name="transport">
1654  <synopsis>SIP Transport</synopsis>
1655  <description><para>
1656  <emphasis>Transports</emphasis>
1657  </para>
1658  <para>There are different transports and protocol derivatives
1659  supported by <literal>res_pjsip</literal>. They are in order of
1660  preference: UDP, TCP, and WebSocket (WS).</para>
1661  <note><para>Changes to transport configuration in pjsip.conf will only be
1662  effected on a complete restart of Asterisk. A module reload
1663  will not suffice.</para></note>
1664  </description>
1665  <configOption name="async_operations" default="1">
1666  <synopsis>Number of simultaneous Asynchronous Operations</synopsis>
1667  </configOption>
1668  <configOption name="bind">
1669  <synopsis>IP Address and optional port to bind to for this transport</synopsis>
1670  </configOption>
1671  <configOption name="ca_list_file">
1672  <synopsis>File containing a list of certificates to read (TLS ONLY, not WSS)</synopsis>
1673  </configOption>
1674  <configOption name="ca_list_path">
1675  <synopsis>Path to directory containing a list of certificates to read (TLS ONLY, not WSS)</synopsis>
1676  </configOption>
1677  <configOption name="cert_file">
1678  <synopsis>Certificate file for endpoint (TLS ONLY, not WSS)</synopsis>
1679  <description><para>
1680  A path to a .crt or .pem file can be provided. However, only
1681  the certificate is read from the file, not the private key.
1682  The <literal>priv_key_file</literal> option must supply a
1683  matching key file.
1684  </para></description>
1685  </configOption>
1686  <configOption name="cipher">
1687  <synopsis>Preferred cryptography cipher names (TLS ONLY, not WSS)</synopsis>
1688  <description>
1689  <para>Comma separated list of cipher names or numeric equivalents.
1690  Numeric equivalents can be either decimal or hexadecimal (0xX).
1691  </para>
1692  <para>There are many cipher names. Use the CLI command
1693  <literal>pjsip list ciphers</literal> to see a list of cipher
1694  names available for your installation. See link for more:</para>
1695  <para>http://www.openssl.org/docs/apps/ciphers.html#CIPHER_SUITE_NAMES
1696  </para>
1697  </description>
1698  </configOption>
1699  <configOption name="domain">
1700  <synopsis>Domain the transport comes from</synopsis>
1701  </configOption>
1702  <configOption name="external_media_address">
1703  <synopsis>External IP address to use in RTP handling</synopsis>
1704  <description><para>
1705  When a request or response is sent out, if the destination of the
1706  message is outside the IP network defined in the option <literal>localnet</literal>,
1707  and the media address in the SDP is within the localnet network, then the
1708  media address in the SDP will be rewritten to the value defined for
1709  <literal>external_media_address</literal>.
1710  </para></description>
1711  </configOption>
1712  <configOption name="external_signaling_address">
1713  <synopsis>External address for SIP signalling</synopsis>
1714  </configOption>
1715  <configOption name="external_signaling_port" default="0">
1716  <synopsis>External port for SIP signalling</synopsis>
1717  </configOption>
1718  <configOption name="method">
1719  <synopsis>Method of SSL transport (TLS ONLY, not WSS)</synopsis>
1720  <description>
1721  <enumlist>
1722  <enum name="default">
1723  <para>The default as defined by PJSIP. This is currently TLSv1, but may change with future releases.</para>
1724  </enum>
1725  <enum name="unspecified">
1726  <para>This option is equivalent to setting 'default'</para>
1727  </enum>
1728  <enum name="tlsv1" />
1729  <enum name="tlsv1_1" />
1730  <enum name="tlsv1_2" />
1731  <enum name="sslv2" />
1732  <enum name="sslv3" />
1733  <enum name="sslv23" />
1734  </enumlist>
1735  </description>
1736  </configOption>
1737  <configOption name="local_net">
1738  <synopsis>Network to consider local (used for NAT purposes).</synopsis>
1739  <description><para>This must be in CIDR or dotted decimal format with the IP
1740  and mask separated with a slash ('/').</para></description>
1741  </configOption>
1742  <configOption name="password">
1743  <synopsis>Password required for transport</synopsis>
1744  </configOption>
1745  <configOption name="priv_key_file">
1746  <synopsis>Private key file (TLS ONLY, not WSS)</synopsis>
1747  </configOption>
1748  <configOption name="protocol" default="udp">
1749  <synopsis>Protocol to use for SIP traffic</synopsis>
1750  <description>
1751  <enumlist>
1752  <enum name="udp" />
1753  <enum name="tcp" />
1754  <enum name="tls" />
1755  <enum name="ws" />
1756  <enum name="wss" />
1757  <enum name="flow" />
1758  </enumlist>
1759  </description>
1760  </configOption>
1761  <configOption name="require_client_cert" default="false">
1762  <synopsis>Require client certificate (TLS ONLY, not WSS)</synopsis>
1763  </configOption>
1764  <configOption name="type">
1765  <synopsis>Must be of type 'transport'.</synopsis>
1766  </configOption>
1767  <configOption name="verify_client" default="false">
1768  <synopsis>Require verification of client certificate (TLS ONLY, not WSS)</synopsis>
1769  </configOption>
1770  <configOption name="verify_server" default="false">
1771  <synopsis>Require verification of server certificate (TLS ONLY, not WSS)</synopsis>
1772  </configOption>
1773  <configOption name="tos" default="false">
1774  <synopsis>Enable TOS for the signalling sent over this transport</synopsis>
1775  <description>
1776  <para>See <literal>https://wiki.asterisk.org/wiki/display/AST/IP+Quality+of+Service</literal>
1777  for more information on this parameter.</para>
1778  <note><para>This option does not apply to the <replaceable>ws</replaceable>
1779  or the <replaceable>wss</replaceable> protocols.</para></note>
1780  </description>
1781  </configOption>
1782  <configOption name="cos" default="false">
1783  <synopsis>Enable COS for the signalling sent over this transport</synopsis>
1784  <description>
1785  <para>See <literal>https://wiki.asterisk.org/wiki/display/AST/IP+Quality+of+Service</literal>
1786  for more information on this parameter.</para>
1787  <note><para>This option does not apply to the <replaceable>ws</replaceable>
1788  or the <replaceable>wss</replaceable> protocols.</para></note>
1789  </description>
1790  </configOption>
1791  <configOption name="websocket_write_timeout">
1792  <synopsis>The timeout (in milliseconds) to set on WebSocket connections.</synopsis>
1793  <description>
1794  <para>If a websocket connection accepts input slowly, the timeout
1795  for writes to it can be increased to keep it from being disconnected.
1796  Value is in milliseconds; default is 100 ms.</para>
1797  </description>
1798  </configOption>
1799  <configOption name="allow_reload" default="no">
1800  <synopsis>Allow this transport to be reloaded.</synopsis>
1801  <description>
1802  <para>Allow this transport to be reloaded when res_pjsip is reloaded.
1803  This option defaults to "no" because reloading a transport may disrupt
1804  in-progress calls.</para>
1805  </description>
1806  </configOption>
1807  <configOption name="symmetric_transport" default="no">
1808  <synopsis>Use the same transport for outgoing requests as incoming ones.</synopsis>
1809  <description>
1810  <para>When a request from a dynamic contact
1811  comes in on a transport with this option set to 'yes',
1812  the transport name will be saved and used for subsequent
1813  outgoing requests like OPTIONS, NOTIFY and INVITE. It's
1814  saved as a contact uri parameter named 'x-ast-txp' and will
1815  display with the contact uri in CLI, AMI, and ARI output.
1816  On the outgoing request, if a transport wasn't explicitly
1817  set on the endpoint AND the request URI is not a hostname,
1818  the saved transport will be used and the 'x-ast-txp'
1819  parameter stripped from the outgoing packet.
1820  </para>
1821  </description>
1822  </configOption>
1823  </configObject>
1824  <configObject name="contact">
1825  <synopsis>A way of creating an aliased name to a SIP URI</synopsis>
1826  <description><para>
1827  Contacts are a way to hide SIP URIs from the dialplan directly.
1828  They are also used to make a group of contactable parties when
1829  in use with <literal>AoR</literal> lists.
1830  </para></description>
1831  <configOption name="type">
1832  <synopsis>Must be of type 'contact'.</synopsis>
1833  </configOption>
1834  <configOption name="uri">
1835  <synopsis>SIP URI to contact peer</synopsis>
1836  </configOption>
1837  <configOption name="expiration_time">
1838  <synopsis>Time to keep alive a contact</synopsis>
1839  <description><para>
1840  Time to keep alive a contact. String style specification.
1841  </para></description>
1842  </configOption>
1843  <configOption name="qualify_frequency" default="0">
1844  <synopsis>Interval at which to qualify a contact</synopsis>
1845  <description><para>
1846  Interval between attempts to qualify the contact for reachability.
1847  If <literal>0</literal> never qualify. Time in seconds.
1848  </para></description>
1849  </configOption>
1850  <configOption name="qualify_timeout" default="3.0">
1851  <synopsis>Timeout for qualify</synopsis>
1852  <description><para>
1853  If the contact doesn't respond to the OPTIONS request before the timeout,
1854  the contact is marked unavailable.
1855  If <literal>0</literal> no timeout. Time in fractional seconds.
1856  </para></description>
1857  </configOption>
1858  <configOption name="authenticate_qualify">
1859  <synopsis>Authenticates a qualify challenge response if needed</synopsis>
1860  <description>
1861  <para>If true and a qualify request receives a challenge response then
1862  authentication is attempted before declaring the contact available.
1863  </para>
1864  <note><para>This option does nothing as we will always complete
1865  the challenge response authentication if the qualify request is
1866  challenged.
1867  </para></note>
1868  </description>
1869  </configOption>
1870  <configOption name="outbound_proxy">
1871  <synopsis>Outbound proxy used when sending OPTIONS request</synopsis>
1872  <description><para>
1873  If set the provided URI will be used as the outbound proxy when an
1874  OPTIONS request is sent to a contact for qualify purposes.
1875  </para></description>
1876  </configOption>
1877  <configOption name="path">
1878  <synopsis>Stored Path vector for use in Route headers on outgoing requests.</synopsis>
1879  </configOption>
1880  <configOption name="user_agent">
1881  <synopsis>User-Agent header from registration.</synopsis>
1882  <description><para>
1883  The User-Agent is automatically stored based on data present in incoming SIP
1884  REGISTER requests and is not intended to be configured manually.
1885  </para></description>
1886  </configOption>
1887  <configOption name="endpoint">
1888  <synopsis>Endpoint name</synopsis>
1889  <description><para>
1890  The name of the endpoint this contact belongs to
1891  </para></description>
1892  </configOption>
1893  <configOption name="reg_server">
1894  <synopsis>Asterisk Server name</synopsis>
1895  <description><para>
1896  Asterisk Server name on which SIP endpoint registered.
1897  </para></description>
1898  </configOption>
1899  <configOption name="via_addr">
1900  <synopsis>IP-address of the last Via header from registration.</synopsis>
1901  <description><para>
1902  The last Via header should contain the address of UA which sent the request.
1903  The IP-address of the last Via header is automatically stored based on data present
1904  in incoming SIP REGISTER requests and is not intended to be configured manually.
1905  </para></description>
1906  </configOption>
1907  <configOption name="via_port">
1908  <synopsis>IP-port of the last Via header from registration.</synopsis>
1909  <description><para>
1910  The IP-port of the last Via header is automatically stored based on data present
1911  in incoming SIP REGISTER requests and is not intended to be configured manually.
1912  </para></description>
1913  </configOption>
1914  <configOption name="call_id">
1915  <synopsis>Call-ID header from registration.</synopsis>
1916  <description><para>
1917  The Call-ID header is automatically stored based on data present
1918  in incoming SIP REGISTER requests and is not intended to be configured manually.
1919  </para></description>
1920  </configOption>
1921  <configOption name="prune_on_boot">
1922  <synopsis>A contact that cannot survive a restart/boot.</synopsis>
1923  <description><para>
1924  The option is set if the incoming SIP REGISTER contact is rewritten
1925  on a reliable transport and is not intended to be configured manually.
1926  </para></description>
1927  </configOption>
1928  </configObject>
1929  <configObject name="aor">
1930  <synopsis>The configuration for a location of an endpoint</synopsis>
1931  <description><para>
1932  An AoR is what allows Asterisk to contact an endpoint via res_pjsip. If no
1933  AoRs are specified, an endpoint will not be reachable by Asterisk.
1934  Beyond that, an AoR has other uses within Asterisk, such as inbound
1935  registration.
1936  </para><para>
1937  An <literal>AoR</literal> is a way to allow dialing a group
1938  of <literal>Contacts</literal> that all use the same
1939  <literal>endpoint</literal> for calls.
1940  </para><para>
1941  This can be used as another way of grouping a list of contacts to dial
1942  rather than specifying them each directly when dialing via the dialplan.
1943  This must be used in conjunction with the <literal>PJSIP_DIAL_CONTACTS</literal>.
1944  </para><para>
1945  Registrations: For Asterisk to match an inbound registration to an endpoint,
1946  the AoR object name must match the user portion of the SIP URI in the "To:"
1947  header of the inbound SIP registration. That will usually be equivalent
1948  to the "user name" set in your hard or soft phones configuration.
1949  </para></description>
1950  <configOption name="contact">
1951  <synopsis>Permanent contacts assigned to AoR</synopsis>
1952  <description><para>
1953  Contacts specified will be called whenever referenced
1954  by <literal>chan_pjsip</literal>.
1955  </para><para>
1956  Use a separate "contact=" entry for each contact required. Contacts
1957  are specified using a SIP URI.
1958  </para></description>
1959  </configOption>
1960  <configOption name="default_expiration" default="3600">
1961  <synopsis>Default expiration time in seconds for contacts that are dynamically bound to an AoR.</synopsis>
1962  </configOption>
1963  <configOption name="mailboxes">
1964  <synopsis>Allow subscriptions for the specified mailbox(es)</synopsis>
1965  <description><para>This option applies when an external entity subscribes to an AoR
1966  for Message Waiting Indications. The mailboxes specified will be subscribed to.
1967  More than one mailbox can be specified with a comma-delimited string.
1968  app_voicemail mailboxes must be specified as [email protected];
1969  for example: [email protected] For mailboxes provided by external sources,
1970  such as through the res_mwi_external module, you must specify strings supported by
1971  the external system.
1972  </para><para>
1973  For endpoints that cannot SUBSCRIBE for MWI, you can set the <literal>mailboxes</literal> option in your
1974  endpoint configuration section to enable unsolicited MWI NOTIFYs to the endpoint.
1975  </para></description>
1976  </configOption>
1977  <configOption name="voicemail_extension">
1978  <synopsis>The voicemail extension to send in the NOTIFY Message-Account header</synopsis>
1979  </configOption>
1980  <configOption name="maximum_expiration" default="7200">
1981  <synopsis>Maximum time to keep an AoR</synopsis>
1982  <description><para>
1983  Maximum time to keep a peer with explicit expiration. Time in seconds.
1984  </para></description>
1985  </configOption>
1986  <configOption name="max_contacts" default="0">
1987  <synopsis>Maximum number of contacts that can bind to an AoR</synopsis>
1988  <description><para>
1989  Maximum number of contacts that can associate with this AoR. This value does
1990  not affect the number of contacts that can be added with the "contact" option.
1991  It only limits contacts added through external interaction, such as
1992  registration.
1993  </para>
1994  <note><para>The <replaceable>rewrite_contact</replaceable> option
1995  registers the source address as the contact address to help with
1996  NAT and reusing connection oriented transports such as TCP and
1997  TLS. Unfortunately, refreshing a registration may register a
1998  different contact address and exceed
1999  <replaceable>max_contacts</replaceable>. The
2000  <replaceable>remove_existing</replaceable> option can help by
2001  removing the soonest to expire contact(s) over
2002  <replaceable>max_contacts</replaceable> which is likely the
2003  old <replaceable>rewrite_contact</replaceable> contact source
2004  address being refreshed.
2005  </para></note>
2006  <note><para>This should be set to <literal>1</literal> and
2007  <replaceable>remove_existing</replaceable> set to <literal>yes</literal> if you
2008  wish to stick with the older <literal>chan_sip</literal> behaviour.
2009  </para></note>
2010  </description>
2011  </configOption>
2012  <configOption name="minimum_expiration" default="60">
2013  <synopsis>Minimum keep alive time for an AoR</synopsis>
2014  <description><para>
2015  Minimum time to keep a peer with an explicit expiration. Time in seconds.
2016  </para></description>
2017  </configOption>
2018  <configOption name="remove_existing" default="no">
2019  <synopsis>Determines whether new contacts replace existing ones.</synopsis>
2020  <description><para>
2021  On receiving a new registration to the AoR should it remove enough
2022  existing contacts not added or updated by the registration to
2023  satisfy <replaceable>max_contacts</replaceable>? Any removed
2024  contacts will expire the soonest.
2025  </para>
2026  <note><para>The <replaceable>rewrite_contact</replaceable> option
2027  registers the source address as the contact address to help with
2028  NAT and reusing connection oriented transports such as TCP and
2029  TLS. Unfortunately, refreshing a registration may register a
2030  different contact address and exceed
2031  <replaceable>max_contacts</replaceable>. The
2032  <replaceable>remove_existing</replaceable> option can help by
2033  removing the soonest to expire contact(s) over
2034  <replaceable>max_contacts</replaceable> which is likely the
2035  old <replaceable>rewrite_contact</replaceable> contact source
2036  address being refreshed.
2037  </para></note>
2038  <note><para>This should be set to <literal>yes</literal> and
2039  <replaceable>max_contacts</replaceable> set to <literal>1</literal> if you
2040  wish to stick with the older <literal>chan_sip</literal> behaviour.
2041  </para></note>
2042  </description>
2043  </configOption>
2044  <configOption name="type">
2045  <synopsis>Must be of type 'aor'.</synopsis>
2046  </configOption>
2047  <configOption name="qualify_frequency" default="0">
2048  <synopsis>Interval at which to qualify an AoR</synopsis>
2049  <description><para>
2050  Interval between attempts to qualify the AoR for reachability.
2051  If <literal>0</literal> never qualify. Time in seconds.
2052  </para></description>
2053  </configOption>
2054  <configOption name="qualify_timeout" default="3.0">
2055  <synopsis>Timeout for qualify</synopsis>
2056  <description><para>
2057  If the contact doesn't respond to the OPTIONS request before the timeout,
2058  the contact is marked unavailable.
2059  If <literal>0</literal> no timeout. Time in fractional seconds.
2060  </para></description>
2061  </configOption>
2062  <configOption name="authenticate_qualify">
2063  <synopsis>Authenticates a qualify challenge response if needed</synopsis>
2064  <description>
2065  <para>If true and a qualify request receives a challenge response then
2066  authentication is attempted before declaring the contact available.
2067  </para>
2068  <note><para>This option does nothing as we will always complete
2069  the challenge response authentication if the qualify request is
2070  challenged.
2071  </para></note>
2072  </description>
2073  </configOption>
2074  <configOption name="outbound_proxy">
2075  <synopsis>Outbound proxy used when sending OPTIONS request</synopsis>
2076  <description><para>
2077  If set the provided URI will be used as the outbound proxy when an
2078  OPTIONS request is sent to a contact for qualify purposes.
2079  </para></description>
2080  </configOption>
2081  <configOption name="support_path">
2082  <synopsis>Enables Path support for REGISTER requests and Route support for other requests.</synopsis>
2083  <description><para>
2084  When this option is enabled, the Path headers in register requests will be saved
2085  and its contents will be used in Route headers for outbound out-of-dialog requests
2086  and in Path headers for outbound 200 responses. Path support will also be indicated
2087  in the Supported header.
2088  </para></description>
2089  </configOption>
2090  </configObject>
2091  <configObject name="system">
2092  <synopsis>Options that apply to the SIP stack as well as other system-wide settings</synopsis>
2093  <description><para>
2094  The settings in this section are global. In addition to being global, the values will
2095  not be re-evaluated when a reload is performed. This is because the values must be set
2096  before the SIP stack is initialized. The only way to reset these values is to either
2097  restart Asterisk, or unload res_pjsip.so and then load it again.
2098  </para></description>
2099  <configOption name="timer_t1" default="500">
2100  <synopsis>Set transaction timer T1 value (milliseconds).</synopsis>
2101  <description><para>
2102  Timer T1 is the base for determining how long to wait before retransmitting
2103  requests that receive no response when using an unreliable transport (e.g. UDP).
2104  For more information on this timer, see RFC 3261, Section 17.1.1.1.
2105  </para></description>
2106  </configOption>
2107  <configOption name="timer_b" default="32000">
2108  <synopsis>Set transaction timer B value (milliseconds).</synopsis>
2109  <description><para>
2110  Timer B determines the maximum amount of time to wait after sending an INVITE
2111  request before terminating the transaction. It is recommended that this be set
2112  to 64 * Timer T1, but it may be set higher if desired. For more information on
2113  this timer, see RFC 3261, Section 17.1.1.1.
2114  </para></description>
2115  </configOption>
2116  <configOption name="compact_headers" default="no">
2117  <synopsis>Use the short forms of common SIP header names.</synopsis>
2118  </configOption>
2119  <configOption name="threadpool_initial_size" default="0">
2120  <synopsis>Initial number of threads in the res_pjsip threadpool.</synopsis>
2121  </configOption>
2122  <configOption name="threadpool_auto_increment" default="5">
2123  <synopsis>The amount by which the number of threads is incremented when necessary.</synopsis>
2124  </configOption>
2125  <configOption name="threadpool_idle_timeout" default="60">
2126  <synopsis>Number of seconds before an idle thread should be disposed of.</synopsis>
2127  </configOption>
2128  <configOption name="threadpool_max_size" default="0">
2129  <synopsis>Maximum number of threads in the res_pjsip threadpool.
2130  A value of 0 indicates no maximum.</synopsis>
2131  </configOption>
2132  <configOption name="disable_tcp_switch" default="yes">
2133  <synopsis>Disable automatic switching from UDP to TCP transports.</synopsis>
2134  <description><para>
2135  Disable automatic switching from UDP to TCP transports if outgoing
2136  request is too large. See RFC 3261 section 18.1.1.
2137  </para></description>
2138  </configOption>
2139  <configOption name="follow_early_media_fork">
2140  <synopsis>Follow SDP forked media when To tag is different</synopsis>
2141  <description><para>
2142  On outgoing calls, if the UAS responds with different SDP attributes
2143  on subsequent 18X or 2XX responses (such as a port update) AND the
2144  To tag on the subsequent response is different than that on the previous
2145  one, follow it.
2146  </para>
2147  <note><para>
2148  This option must also be enabled on endpoints that require
2149  this functionality.
2150  </para></note>
2151  </description>
2152  </configOption>
2153  <configOption name="accept_multiple_sdp_answers">
2154  <synopsis>Follow SDP forked media when To tag is the same</synopsis>
2155  <description><para>
2156  On outgoing calls, if the UAS responds with different SDP attributes
2157  on non-100rel 18X or 2XX responses (such as a port update) AND the
2158  To tag on the subsequent response is the same as that on the previous one,
2159  process the updated SDP.
2160  </para>
2161  <note><para>
2162  This option must also be enabled on endpoints that require
2163  this functionality.
2164  </para></note>
2165  </description>
2166  </configOption>
2167  <configOption name="disable_rport" default="no">
2168  <synopsis>Disable the use of rport in outgoing requests.</synopsis>
2169  <description><para>
2170  Remove "rport" parameter from the outgoing requests.
2171  </para></description>
2172  </configOption>
2173  <configOption name="type">
2174  <synopsis>Must be of type 'system' UNLESS the object name is 'system'.</synopsis>
2175  </configOption>
2176  </configObject>
2177  <configObject name="global">
2178  <synopsis>Options that apply globally to all SIP communications</synopsis>
2179  <description><para>
2180  The settings in this section are global. Unlike options in the <literal>system</literal>
2181  section, these options can be refreshed by performing a reload.
2182  </para></description>
2183  <configOption name="max_forwards" default="70">
2184  <synopsis>Value used in Max-Forwards header for SIP requests.</synopsis>
2185  </configOption>
2186  <configOption name="keep_alive_interval" default="90">
2187  <synopsis>The interval (in seconds) to send keepalives to active connection-oriented transports.</synopsis>
2188  </configOption>
2189  <configOption name="contact_expiration_check_interval" default="30">
2190  <synopsis>The interval (in seconds) to check for expired contacts.</synopsis>
2191  </configOption>
2192  <configOption name="disable_multi_domain" default="no">
2193  <synopsis>Disable Multi Domain support</synopsis>
2194  <description><para>
2195  If disabled it can improve realtime performance by reducing the number of database requests.
2196  </para></description>
2197  </configOption>
2198  <configOption name="max_initial_qualify_time" default="0">
2199  <synopsis>The maximum amount of time from startup that qualifies should be attempted on all contacts.
2200  If greater than the qualify_frequency for an aor, qualify_frequency will be used instead.</synopsis>
2201  </configOption>
2202  <configOption name="unidentified_request_period" default="5">
2203  <synopsis>The number of seconds over which to accumulate unidentified requests.</synopsis>
2204  <description><para>
2205  If <literal>unidentified_request_count</literal> unidentified requests are received
2206  during <literal>unidentified_request_period</literal>, a security event will be generated.
2207  </para></description>
2208  </configOption>
2209  <configOption name="unidentified_request_count" default="5">
2210  <synopsis>The number of unidentified requests from a single IP to allow.</synopsis>
2211  <description><para>
2212  If <literal>unidentified_request_count</literal> unidentified requests are received
2213  during <literal>unidentified_request_period</literal>, a security event will be generated.
2214  </para></description>
2215  </configOption>
2216  <configOption name="unidentified_request_prune_interval" default="30">
2217  <synopsis>The interval at which unidentified requests are older than
2218  twice the unidentified_request_period are pruned.</synopsis>
2219  </configOption>
2220  <configOption name="type">
2221  <synopsis>Must be of type 'global' UNLESS the object name is 'global'.</synopsis>
2222  </configOption>
2223  <configOption name="user_agent" default="Asterisk &lt;Asterisk Version&gt;">
2224  <synopsis>Value used in User-Agent header for SIP requests and Server header for SIP responses.</synopsis>
2225  </configOption>
2226  <configOption name="regcontext" default="">
2227  <synopsis>When set, Asterisk will dynamically create and destroy a NoOp priority 1 extension for a given
2228  peer who registers or unregisters with us.</synopsis>
2229  </configOption>
2230  <configOption name="default_outbound_endpoint" default="default_outbound_endpoint">
2231  <synopsis>Endpoint to use when sending an outbound request to a URI without a specified endpoint.</synopsis>
2232  </configOption>
2233  <configOption name="default_voicemail_extension">
2234  <synopsis>The voicemail extension to send in the NOTIFY Message-Account header if not specified on endpoint or aor</synopsis>
2235  </configOption>
2236  <configOption name="debug" default="no">
2237  <synopsis>Enable/Disable SIP debug logging. Valid options include yes, no, or
2238  a host address</synopsis>
2239  </configOption>
2240  <configOption name="endpoint_identifier_order">
2241  <synopsis>The order by which endpoint identifiers are processed and checked.
2242  Identifier names are usually derived from and can be found in the endpoint
2243  identifier module itself (res_pjsip_endpoint_identifier_*).
2244  You can use the CLI command "pjsip show identifiers" to see the
2245  identifiers currently available.</synopsis>
2246  <description>
2247  <note><para>
2248  One of the identifiers is "auth_username" which matches on the username in
2249  an Authentication header. This method has some security considerations because an
2250  Authentication header is not present on the first message of a dialog when
2251  digest authentication is used. The client can't generate it until the server
2252  sends the challenge in a 401 response. Since Asterisk normally sends a security
2253  event when an incoming request can't be matched to an endpoint, using auth_username
2254  requires that the security event be deferred until a request is received with
2255  the Authentication header and only generated if the username doesn't result in a
2256  match. This may result in a delay before an attack is recognized. You can control
2257  how many unmatched requests are received from a single ip address before a security
2258  event is generated using the unidentified_request parameters.
2259  </para></note>
2260  </description>
2261  </configOption>
2262  <configOption name="default_from_user" default="asterisk">
2263  <synopsis>When Asterisk generates an outgoing SIP request, the From header username will be
2264  set to this value if there is no better option (such as CallerID) to be
2265  used.</synopsis>
2266  </configOption>
2267  <configOption name="default_realm" default="asterisk">
2268  <synopsis>When Asterisk generates a challenge, the digest realm will be
2269  set to this value if there is no better option (such as auth/realm) to be
2270  used.</synopsis>
2271  </configOption>
2272  <configOption name="mwi_tps_queue_high" default="500">
2273  <synopsis>MWI taskprocessor high water alert trigger level.</synopsis>
2274  <description>
2275  <para>On a heavily loaded system you may need to adjust the
2276  taskprocessor queue limits. If any taskprocessor queue size
2277  reaches its high water level then pjsip will stop processing
2278  new requests until the alert is cleared. The alert clears
2279  when all alerting taskprocessor queues have dropped to their
2280  low water clear level.
2281  </para>
2282  </description>
2283  </configOption>
2284  <configOption name="mwi_tps_queue_low" default="-1">
2285  <synopsis>MWI taskprocessor low water clear alert level.</synopsis>
2286  <description>
2287  <para>On a heavily loaded system you may need to adjust the
2288  taskprocessor queue limits. If any taskprocessor queue size
2289  reaches its high water level then pjsip will stop processing
2290  new requests until the alert is cleared. The alert clears
2291  when all alerting taskprocessor queues have dropped to their
2292  low water clear level.
2293  </para>
2294  <note><para>Set to -1 for the low water level to be 90% of
2295  the high water level.</para></note>
2296  </description>
2297  </configOption>
2298  <configOption name="mwi_disable_initial_unsolicited" default="no">
2299  <synopsis>Enable/Disable sending unsolicited MWI to all endpoints on startup.</synopsis>
2300  <description>
2301  <para>When the initial unsolicited MWI notification are
2302  enabled on startup then the initial notifications
2303  get sent at startup. If you have a lot of endpoints
2304  (thousands) that use unsolicited MWI then you may
2305  want to consider disabling the initial startup
2306  notifications.
2307  </para>
2308  <para>When the initial unsolicited MWI notifications are
2309  disabled on startup then the notifications will start
2310  on the endpoint's next contact update.
2311  </para>
2312  </description>
2313  </configOption>
2314  <configOption name="ignore_uri_user_options">
2315  <synopsis>Enable/Disable ignoring SIP URI user field options.</synopsis>
2316  <description>
2317  <para>If you have this option enabled and there are semicolons
2318  in the user field of a SIP URI then the field is truncated
2319  at the first semicolon. This effectively makes the semicolon
2320  a non-usable character for PJSIP endpoint names, extensions,
2321  and AORs. This can be useful for improving compatibility with
2322  an ITSP that likes to use user options for whatever reason.
2323  </para>
2324  <example title="Sample SIP URI">
2325  sip:1235557890;[email protected];user=phone
2326  </example>
2327  <example title="Sample SIP URI user field">
2328  1235557890;phone-context=national
2329  </example>
2330  <example title="Sample SIP URI user field truncated">
2331  1235557890
2332  </example>
2333  <note><para>The caller-id and redirecting number strings
2334  obtained from incoming SIP URI user fields are always truncated
2335  at the first semicolon.</para></note>
2336  </description>
2337  </configOption>
2338  <configOption name="use_callerid_contact" default="no">
2339  <synopsis>Place caller-id information into Contact header</synopsis>
2340  <description><para>
2341  This option will cause Asterisk to place caller-id information into
2342  generated Contact headers.</para>
2343  </description>
2344  </configOption>
2345  <configOption name="send_contact_status_on_update_registration" default="no">
2346  <synopsis>Enable sending AMI ContactStatus event when a device refreshes its registration.</synopsis>
2347  </configOption>
2348  <configOption name="taskprocessor_overload_trigger">
2349  <synopsis>Trigger scope for taskprocessor overloads</synopsis>
2350  <description><para>
2351  This option specifies the trigger the distributor will use for
2352  detecting taskprocessor overloads. When it detects an overload condition,
2353  the distrubutor will stop accepting new requests until the overload is
2354  cleared.
2355  </para>
2356  <enumlist>
2357  <enum name="global"><para>(default) Any taskprocessor overload will trigger.</para></enum>
2358  <enum name="pjsip_only"><para>Only pjsip taskprocessor overloads will trigger.</para></enum>
2359  <enum name="none"><para>No overload detection will be performed.</para></enum>
2360  </enumlist>
2361  <warning><para>
2362  The "none" and "pjsip_only" options should be used
2363  with extreme caution and only to mitigate specific issues.
2364  Under certain conditions they could make things worse.
2365  </para></warning>
2366  </description>
2367  </configOption>
2368  <configOption name="norefersub" default="yes">
2369  <synopsis>Advertise support for RFC4488 REFER subscription suppression</synopsis>
2370  </configOption>
2371  </configObject>
2372  </configFile>
2373  </configInfo>
2374  <manager name="PJSIPQualify" language="en_US">
2375  <synopsis>
2376  Qualify a chan_pjsip endpoint.
2377  </synopsis>
2378  <syntax>
2379  <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
2380  <parameter name="Endpoint" required="true">
2381  <para>The endpoint you want to qualify.</para>
2382  </parameter>
2383  </syntax>
2384  <description>
2385  <para>Qualify a chan_pjsip endpoint.</para>
2386  </description>
2387  </manager>
2388  <managerEvent language="en_US" name="IdentifyDetail">
2389  <managerEventInstance class="EVENT_FLAG_COMMAND">
2390  <synopsis>Provide details about an identify section.</synopsis>
2391  <syntax>
2392  <parameter name="ObjectType">
2393  <para>The object's type. This will always be 'identify'.</para>
2394  </parameter>
2395  <parameter name="ObjectName">
2396  <para>The name of this object.</para>
2397  </parameter>
2398  <parameter name="Endpoint">
2399  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_endpoint_identifier_ip']/configFile[@name='pjsip.conf']/configObject[@name='identify']/configOption[@name='endpoint']/synopsis/node())"/></para>
2400  </parameter>
2401  <parameter name="SrvLookups">
2402  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_endpoint_identifier_ip']/configFile[@name='pjsip.conf']/configObject[@name='identify']/configOption[@name='srv_lookups']/synopsis/node())"/></para>
2403  </parameter>
2404  <parameter name="Match">
2405  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_endpoint_identifier_ip']/configFile[@name='pjsip.conf']/configObject[@name='identify']/configOption[@name='match']/synopsis/node())"/></para>
2406  </parameter>
2407  <parameter name="MatchHeader">
2408  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_endpoint_identifier_ip']/configFile[@name='pjsip.conf']/configObject[@name='identify']/configOption[@name='match_header']/synopsis/node())"/></para>
2409  </parameter>
2410  <parameter name="EndpointName">
2411  <para>The name of the endpoint associated with this information.</para>
2412  </parameter>
2413  </syntax>
2414  </managerEventInstance>
2415  </managerEvent>
2416  <managerEvent language="en_US" name="AorDetail">
2417  <managerEventInstance class="EVENT_FLAG_COMMAND">
2418  <synopsis>Provide details about an Address of Record (AoR) section.</synopsis>
2419  <syntax>
2420  <parameter name="ObjectType">
2421  <para>The object's type. This will always be 'aor'.</para>
2422  </parameter>
2423  <parameter name="ObjectName">
2424  <para>The name of this object.</para>
2425  </parameter>
2426  <parameter name="MinimumExpiration">
2427  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='minimum_expiration']/synopsis/node())"/></para>
2428  </parameter>
2429  <parameter name="MaximumExpiration">
2430  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='maximum_expiration']/synopsis/node())"/></para>
2431  </parameter>
2432  <parameter name="DefaultExpiration">
2433  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='default_expiration']/synopsis/node())"/></para>
2434  </parameter>
2435  <parameter name="QualifyFrequency">
2436  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='qualify_frequency']/synopsis/node())"/></para>
2437  </parameter>
2438  <parameter name="AuthenticateQualify">
2439  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='authenticate_qualify']/synopsis/node())"/></para>
2440  </parameter>
2441  <parameter name="MaxContacts">
2442  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='max_contacts']/synopsis/node())"/></para>
2443  </parameter>
2444  <parameter name="RemoveExisting">
2445  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='remove_existing']/synopsis/node())"/></para>
2446  </parameter>
2447  <parameter name="Mailboxes">
2448  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='mailboxes']/synopsis/node())"/></para>
2449  </parameter>
2450  <parameter name="OutboundProxy">
2451  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='outbound_proxy']/synopsis/node())"/></para>
2452  </parameter>
2453  <parameter name="SupportPath">
2454  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='support_path']/synopsis/node())"/></para>
2455  </parameter>
2456  <parameter name="TotalContacts">
2457  <para>The total number of contacts associated with this AoR.</para>
2458  </parameter>
2459  <parameter name="ContactsRegistered">
2460  <para>The number of non-permanent contacts associated with this AoR.</para>
2461  </parameter>
2462  <parameter name="EndpointName">
2463  <para>The name of the endpoint associated with this information.</para>
2464  </parameter>
2465  </syntax>
2466  </managerEventInstance>
2467  </managerEvent>
2468  <managerEvent language="en_US" name="AuthDetail">
2469  <managerEventInstance class="EVENT_FLAG_COMMAND">
2470  <synopsis>Provide details about an authentication section.</synopsis>
2471  <syntax>
2472  <parameter name="ObjectType">
2473  <para>The object's type. This will always be 'auth'.</para>
2474  </parameter>
2475  <parameter name="ObjectName">
2476  <para>The name of this object.</para>
2477  </parameter>
2478  <parameter name="Username">
2479  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='username']/synopsis/node())"/></para>
2480  </parameter>
2481  <parameter name="Password">
2482  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='username']/synopsis/node())"/></para>
2483  </parameter>
2484  <parameter name="Md5Cred">
2485  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='md5_cred']/synopsis/node())"/></para>
2486  </parameter>
2487  <parameter name="Realm">
2488  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='realm']/synopsis/node())"/></para>
2489  </parameter>
2490  <parameter name="NonceLifetime">
2491  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='nonce_lifetime']/synopsis/node())"/></para>
2492  </parameter>
2493  <parameter name="AuthType">
2494  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='auth_type']/synopsis/node())"/></para>
2495  </parameter>
2496  <parameter name="EndpointName">
2497  <para>The name of the endpoint associated with this information.</para>
2498  </parameter>
2499  </syntax>
2500  </managerEventInstance>
2501  </managerEvent>
2502  <managerEvent language="en_US" name="TransportDetail">
2503  <managerEventInstance class="EVENT_FLAG_COMMAND">
2504  <synopsis>Provide details about an authentication section.</synopsis>
2505  <syntax>
2506  <parameter name="ObjectType">
2507  <para>The object's type. This will always be 'transport'.</para>
2508  </parameter>
2509  <parameter name="ObjectName">
2510  <para>The name of this object.</para>
2511  </parameter>
2512  <parameter name="Protocol">
2513  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='protocol']/synopsis/node())"/></para>
2514  </parameter>
2515  <parameter name="Bind">
2516  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='bind']/synopsis/node())"/></para>
2517  </parameter>
2518  <parameter name="AsycOperations">
2519  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='async_operations']/synopsis/node())"/></para>
2520  </parameter>
2521  <parameter name="CaListFile">
2522  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='ca_list_file']/synopsis/node())"/></para>
2523  </parameter>
2524  <parameter name="CaListPath">
2525  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='ca_list_path']/synopsis/node())"/></para>
2526  </parameter>
2527  <parameter name="CertFile">
2528  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='cert_file']/synopsis/node())"/></para>
2529  </parameter>
2530  <parameter name="PrivKeyFile">
2531  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='priv_key_file']/synopsis/node())"/></para>
2532  </parameter>
2533  <parameter name="Password">
2534  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='password']/synopsis/node())"/></para>
2535  </parameter>
2536  <parameter name="ExternalSignalingAddress">
2537  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='external_signaling_address']/synopsis/node())"/></para>
2538  </parameter>
2539  <parameter name="ExternalSignalingPort">
2540  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='external_signaling_port']/synopsis/node())"/></para>
2541  </parameter>
2542  <parameter name="ExternalMediaAddress">
2543  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='external_media_address']/synopsis/node())"/></para>
2544  </parameter>
2545  <parameter name="Domain">
2546  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='domain']/synopsis/node())"/></para>
2547  </parameter>
2548  <parameter name="VerifyServer">
2549  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='verify_server']/synopsis/node())"/></para>
2550  </parameter>
2551  <parameter name="VerifyClient">
2552  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='verify_client']/synopsis/node())"/></para>
2553  </parameter>
2554  <parameter name="RequireClientCert">
2555  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='require_client_cert']/synopsis/node())"/></para>
2556  </parameter>
2557  <parameter name="Method">
2558  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='method']/synopsis/node())"/></para>
2559  </parameter>
2560  <parameter name="Cipher">
2561  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='cipher']/synopsis/node())"/></para>
2562  </parameter>
2563  <parameter name="LocalNet">
2564  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='local_net']/synopsis/node())"/></para>
2565  </parameter>
2566  <parameter name="Tos">
2567  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='tos']/synopsis/node())"/></para>
2568  </parameter>
2569  <parameter name="Cos">
2570  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='cos']/synopsis/node())"/></para>
2571  </parameter>
2572  <parameter name="WebsocketWriteTimeout">
2573  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='transport']/configOption[@name='websocket_write_timeout']/synopsis/node())"/></para>
2574  </parameter>
2575  <parameter name="EndpointName">
2576  <para>The name of the endpoint associated with this information.</para>
2577  </parameter>
2578  </syntax>
2579  </managerEventInstance>
2580  </managerEvent>
2581  <managerEvent language="en_US" name="EndpointDetail">
2582  <managerEventInstance class="EVENT_FLAG_COMMAND">
2583  <synopsis>Provide details about an endpoint section.</synopsis>
2584  <syntax>
2585  <parameter name="ObjectType">
2586  <para>The object's type. This will always be 'endpoint'.</para>
2587  </parameter>
2588  <parameter name="ObjectName">
2589  <para>The name of this object.</para>
2590  </parameter>
2591  <parameter name="Context">
2592  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='context']/synopsis/node())"/></para>
2593  </parameter>
2594  <parameter name="Disallow">
2595  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='disallow']/synopsis/node())"/></para>
2596  </parameter>
2597  <parameter name="Allow">
2598  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='allow']/synopsis/node())"/></para>
2599  </parameter>
2600  <parameter name="DtmfMode">
2601  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='dtmf_mode']/synopsis/node())"/></para>
2602  </parameter>
2603  <parameter name="RtpIpv6">
2604  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='rtp_ipv6']/synopsis/node())"/></para>
2605  </parameter>
2606  <parameter name="RtpSymmetric">
2607  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='rtp_symmetric']/synopsis/node())"/></para>
2608  </parameter>
2609  <parameter name="IceSupport">
2610  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='ice_support']/synopsis/node())"/></para>
2611  </parameter>
2612  <parameter name="UsePtime">
2613  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='use_ptime']/synopsis/node())"/></para>
2614  </parameter>
2615  <parameter name="ForceRport">
2616  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='force_rport']/synopsis/node())"/></para>
2617  </parameter>
2618  <parameter name="RewriteContact">
2619  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='rewrite_contact']/synopsis/node())"/></para>
2620  </parameter>
2621  <parameter name="Transport">
2622  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='transport']/synopsis/node())"/></para>
2623  </parameter>
2624  <parameter name="OutboundProxy">
2625  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='outbound_proxy']/synopsis/node())"/></para>
2626  </parameter>
2627  <parameter name="MohSuggest">
2628  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='moh_suggest']/synopsis/node())"/></para>
2629  </parameter>
2630  <parameter name="100rel">
2631  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='100rel']/synopsis/node())"/></para>
2632  </parameter>
2633  <parameter name="Timers">
2634  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='timers']/synopsis/node())"/></para>
2635  </parameter>
2636  <parameter name="TimersMinSe">
2637  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='timers_min_se']/synopsis/node())"/></para>
2638  </parameter>
2639  <parameter name="TimersSessExpires">
2640  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='timers_sess_expires']/synopsis/node())"/></para>
2641  </parameter>
2642  <parameter name="Auth">
2643  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='auth']/synopsis/node())"/></para>
2644  </parameter>
2645  <parameter name="OutboundAuth">
2646  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='outbound_auth']/synopsis/node())"/></para>
2647  </parameter>
2648  <parameter name="Aors">
2649  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='aors']/synopsis/node())"/></para>
2650  </parameter>
2651  <parameter name="MediaAddress">
2652  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='media_address']/synopsis/node())"/></para>
2653  </parameter>
2654  <parameter name="IdentifyBy">
2655  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='identify_by']/synopsis/node())"/></para>
2656  </parameter>
2657  <parameter name="DirectMedia">
2658  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='direct_media']/synopsis/node())"/></para>
2659  </parameter>
2660  <parameter name="DirectMediaMethod">
2661  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='direct_media_method']/synopsis/node())"/></para>
2662  </parameter>
2663  <parameter name="TrustConnectedLine">
2664  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='trust_connected_line']/synopsis/node())"/></para>
2665  </parameter>
2666  <parameter name="SendConnectedLine">
2667  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='send_connected_line']/synopsis/node())"/></para>
2668  </parameter>
2669  <parameter name="ConnectedLineMethod">
2670  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='connected_line_method']/synopsis/node())"/></para>
2671  </parameter>
2672  <parameter name="DirectMediaGlareMitigation">
2673  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='direct_media_glare_mitigation']/synopsis/node())"/></para>
2674  </parameter>
2675  <parameter name="DisableDirectMediaOnNat">
2676  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='disable_direct_media_on_nat']/synopsis/node())"/></para>
2677  </parameter>
2678  <parameter name="Callerid">
2679  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='callerid']/synopsis/node())"/></para>
2680  </parameter>
2681  <parameter name="CalleridPrivacy">
2682  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='callerid_privacy']/synopsis/node())"/></para>
2683  </parameter>
2684  <parameter name="CalleridTag">
2685  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='callerid_tag']/synopsis/node())"/></para>
2686  </parameter>
2687  <parameter name="TrustIdInbound">
2688  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='trust_id_inbound']/synopsis/node())"/></para>
2689  </parameter>
2690  <parameter name="TrustIdOutbound">
2691  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='trust_id_outbound']/synopsis/node())"/></para>
2692  </parameter>
2693  <parameter name="SendPai">
2694  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='send_pai']/synopsis/node())"/></para>
2695  </parameter>
2696  <parameter name="SendRpid">
2697  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='send_rpid']/synopsis/node())"/></para>
2698  </parameter>
2699  <parameter name="SendDiversion">
2700  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='send_diversion']/synopsis/node())"/></para>
2701  </parameter>
2702  <parameter name="Mailboxes">
2703  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='mailboxes']/synopsis/node())"/></para>
2704  </parameter>
2705  <parameter name="AggregateMwi">
2706  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='aggregate_mwi']/synopsis/node())"/></para>
2707  </parameter>
2708  <parameter name="MediaEncryption">
2709  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='media_encryption']/synopsis/node())"/></para>
2710  </parameter>
2711  <parameter name="MediaEncryptionOptimistic">
2712  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='media_encryption_optimistic']/synopsis/node())"/></para>
2713  </parameter>
2714  <parameter name="UseAvpf">
2715  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='use_avpf']/synopsis/node())"/></para>
2716  </parameter>
2717  <parameter name="ForceAvp">
2718  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='force_avp']/synopsis/node())"/></para>
2719  </parameter>
2720  <parameter name="MediaUseReceivedTransport">
2721  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='media_use_received_transport']/synopsis/node())"/></para>
2722  </parameter>
2723  <parameter name="OneTouchRecording">
2724  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='one_touch_recording']/synopsis/node())"/></para>
2725  </parameter>
2726  <parameter name="InbandProgress">
2727  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='inband_progress']/synopsis/node())"/></para>
2728  </parameter>
2729  <parameter name="CallGroup">
2730  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='call_group']/synopsis/node())"/></para>
2731  </parameter>
2732  <parameter name="PickupGroup">
2733  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='pickup_group']/synopsis/node())"/></para>
2734  </parameter>
2735  <parameter name="NamedCallGroup">
2736  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='named_call_group']/synopsis/node())"/></para>
2737  </parameter>
2738  <parameter name="NamedPickupGroup">
2739  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='named_pickup_group']/synopsis/node())"/></para>
2740  </parameter>
2741  <parameter name="DeviceStateBusyAt">
2742  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='device_state_busy_at']/synopsis/node())"/></para>
2743  </parameter>
2744  <parameter name="T38Udptl">
2745  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='t38_udptl']/synopsis/node())"/></para>
2746  </parameter>
2747  <parameter name="T38UdptlEc">
2748  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='t38_udptl_ec']/synopsis/node())"/></para>
2749  </parameter>
2750  <parameter name="T38UdptlMaxdatagram">
2751  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='t38_udptl_maxdatagram']/synopsis/node())"/></para>
2752  </parameter>
2753  <parameter name="FaxDetect">
2754  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='fax_detect']/synopsis/node())"/></para>
2755  </parameter>
2756  <parameter name="T38UdptlNat">
2757  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='t38_udptl_nat']/synopsis/node())"/></para>
2758  </parameter>
2759  <parameter name="T38UdptlIpv6">
2760  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='t38_udptl_ipv6']/synopsis/node())"/></para>
2761  </parameter>
2762  <parameter name="ToneZone">
2763  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='tone_zone']/synopsis/node())"/></para>
2764  </parameter>
2765  <parameter name="Language">
2766  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='language']/synopsis/node())"/></para>
2767  </parameter>
2768  <parameter name="RecordOnFeature">
2769  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='record_on_feature']/synopsis/node())"/></para>
2770  </parameter>
2771  <parameter name="RecordOffFeature">
2772  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='record_off_feature']/synopsis/node())"/></para>
2773  </parameter>
2774  <parameter name="AllowTransfer">
2775  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='allow_transfer']/synopsis/node())"/></para>
2776  </parameter>
2777  <parameter name="UserEqPhone">
2778  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='user_eq_phone']/synopsis/node())"/></para>
2779  </parameter>
2780  <parameter name="MohPassthrough">
2781  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='moh_passthrough']/synopsis/node())"/></para>
2782  </parameter>
2783  <parameter name="SdpOwner">
2784  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='sdp_owner']/synopsis/node())"/></para>
2785  </parameter>
2786  <parameter name="SdpSession">
2787  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='sdp_session']/synopsis/node())"/></para>
2788  </parameter>
2789  <parameter name="TosAudio">
2790  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='tos_audio']/synopsis/node())"/></para>
2791  </parameter>
2792  <parameter name="TosVideo">
2793  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='tos_video']/synopsis/node())"/></para>
2794  </parameter>
2795  <parameter name="CosAudio">
2796  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='cos_audio']/synopsis/node())"/></para>
2797  </parameter>
2798  <parameter name="CosVideo">
2799  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='cos_video']/synopsis/node())"/></para>
2800  </parameter>
2801  <parameter name="AllowSubscribe">
2802  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='allow_subscribe']/synopsis/node())"/></para>
2803  </parameter>
2804  <parameter name="SubMinExpiry">
2805  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='sub_min_expiry']/synopsis/node())"/></para>
2806  </parameter>
2807  <parameter name="FromUser">
2808  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='from_user']/synopsis/node())"/></para>
2809  </parameter>
2810  <parameter name="FromDomain">
2811  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='from_domain']/synopsis/node())"/></para>
2812  </parameter>
2813  <parameter name="MwiFromUser">
2814  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='mwi_from_user']/synopsis/node())"/></para>
2815  </parameter>
2816  <parameter name="RtpEngine">
2817  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='rtp_engine']/synopsis/node())"/></para>
2818  </parameter>
2819  <parameter name="DtlsVerify">
2820  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='dtls_verify']/synopsis/node())"/></para>
2821  </parameter>
2822  <parameter name="DtlsRekey">
2823  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='dtls_rekey']/synopsis/node())"/></para>
2824  </parameter>
2825  <parameter name="DtlsCertFile">
2826  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='dtls_cert_file']/synopsis/node())"/></para>
2827  </parameter>
2828  <parameter name="DtlsPrivateKey">
2829  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='dtls_private_key']/synopsis/node())"/></para>
2830  </parameter>
2831  <parameter name="DtlsCipher">
2832  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='dtls_cipher']/synopsis/node())"/></para>
2833  </parameter>
2834  <parameter name="DtlsCaFile">
2835  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='dtls_ca_file']/synopsis/node())"/></para>
2836  </parameter>
2837  <parameter name="DtlsCaPath">
2838  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='dtls_ca_path']/synopsis/node())"/></para>
2839  </parameter>
2840  <parameter name="DtlsSetup">
2841  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='dtls_setup']/synopsis/node())"/></para>
2842  </parameter>
2843  <parameter name="SrtpTag32">
2844  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='srtp_tag_32']/synopsis/node())"/></para>
2845  </parameter>
2846  <parameter name="RedirectMethod">
2847  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='redirect_method']/synopsis/node())"/></para>
2848  </parameter>
2849  <parameter name="SetVar">
2850  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='set_var']/synopsis/node())"/></para>
2851  </parameter>
2852  <parameter name="MessageContext">
2853  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='message_context']/synopsis/node())"/></para>
2854  </parameter>
2855  <parameter name="Accountcode">
2856  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='accountcode']/synopsis/node())"/></para>
2857  </parameter>
2858  <parameter name="PreferredCodecOnly">
2859  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='preferred_codec_only']/synopsis/node())"/></para>
2860  </parameter>
2861  <parameter name="DeviceState">
2862  <para>The aggregate device state for this endpoint.</para>
2863  </parameter>
2864  <parameter name="ActiveChannels">
2865  <para>The number of active channels associated with this endpoint.</para>
2866  </parameter>
2867  <parameter name="SubscribeContext">
2868  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='subscribe_context']/synopsis/node())"/></para>
2869  </parameter>
2870  <parameter name="Allowoverlap">
2871  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='endpoint']/configOption[@name='allow_overlap']/synopsis/node())"/></para>
2872  </parameter>
2873  </syntax>
2874  </managerEventInstance>
2875  </managerEvent>
2876  <managerEvent language="en_US" name="AorList">
2877  <managerEventInstance class="EVENT_FLAG_COMMAND">
2878  <synopsis>Provide details about an Address of Record (AoR) section.</synopsis>
2879  <syntax>
2880  <parameter name="ObjectType">
2881  <para>The object's type. This will always be 'aor'.</para>
2882  </parameter>
2883  <parameter name="ObjectName">
2884  <para>The name of this object.</para>
2885  </parameter>
2886  <parameter name="MinimumExpiration">
2887  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='minimum_expiration']/synopsis/node())"/></para>
2888  </parameter>
2889  <parameter name="MaximumExpiration">
2890  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='maximum_expiration']/synopsis/node())"/></para>
2891  </parameter>
2892  <parameter name="DefaultExpiration">
2893  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='default_expiration']/synopsis/node())"/></para>
2894  </parameter>
2895  <parameter name="QualifyFrequency">
2896  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='qualify_frequency']/synopsis/node())"/></para>
2897  </parameter>
2898  <parameter name="AuthenticateQualify">
2899  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='authenticate_qualify']/synopsis/node())"/></para>
2900  </parameter>
2901  <parameter name="MaxContacts">
2902  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='max_contacts']/synopsis/node())"/></para>
2903  </parameter>
2904  <parameter name="RemoveExisting">
2905  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='remove_existing']/synopsis/node())"/></para>
2906  </parameter>
2907  <parameter name="Mailboxes">
2908  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='mailboxes']/synopsis/node())"/></para>
2909  </parameter>
2910  <parameter name="OutboundProxy">
2911  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='outbound_proxy']/synopsis/node())"/></para>
2912  </parameter>
2913  <parameter name="SupportPath">
2914  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='aor']/configOption[@name='support_path']/synopsis/node())"/></para>
2915  </parameter>
2916  </syntax>
2917  </managerEventInstance>
2918  </managerEvent>
2919  <managerEvent language="en_US" name="AuthList">
2920  <managerEventInstance class="EVENT_FLAG_COMMAND">
2921  <synopsis>Provide details about an Address of Record (Auth) section.</synopsis>
2922  <syntax>
2923  <parameter name="ObjectType">
2924  <para>The object's type. This will always be 'auth'.</para>
2925  </parameter>
2926  <parameter name="ObjectName">
2927  <para>The name of this object.</para>
2928  </parameter>
2929  <parameter name="Username">
2930  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='username']/synopsis/node())"/></para>
2931  </parameter>
2932  <parameter name="Md5Cred">
2933  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='md5_cred']/synopsis/node())"/></para>
2934  </parameter>
2935  <parameter name="Realm">
2936  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='realm']/synopsis/node())"/></para>
2937  </parameter>
2938  <parameter name="AuthType">
2939  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='auth_type']/synopsis/node())"/></para>
2940  </parameter>
2941  <parameter name="Password">
2942  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='password']/synopsis/node())"/></para>
2943  </parameter>
2944  <parameter name="NonceLifetime">
2945  <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip']/configFile[@name='pjsip.conf']/configObject[@name='auth']/configOption[@name='nonce_lifetime']/synopsis/node())"/></para>
2946  </parameter>
2947  </syntax>
2948  </managerEventInstance>
2949  </managerEvent>
2950  <managerEvent language="en_US" name="ContactList">
2951  <managerEventInstance class="EVENT_FLAG_COMMAND">
2952  <synopsis>Provide details about a contact section.</synopsis>
2953  <syntax>
2954  <parameter name="ObjectType">
2955  <para>The object's type. This will always be 'contact'.</para>
2956  </parameter>
2957  <parameter name="ObjectName">
2958  <para>The name of this object.</para>
2959  </parameter>
2960  <parameter name="ViaAddr">
2961  <para>IP address of the last Via header in REGISTER request.
2962  Will only appear in the event if available.</para>
2963  </parameter>
2964  <parameter name="ViaPort">
2965  <para>Port number of the last Via header in REGISTER request.
2966  Will only appear in the event if available.</para>
2967  </parameter>
2968  <parameter name="QualifyTimeout">
2969  <para>The elapsed time in decimal seconds after which an OPTIONS
2970  message is sent before the contact is considered unavailable.</para>
2971  </parameter>
2972  <parameter name="CallId">
2973  <para>Content of the Call-ID header in REGISTER request.
2974  Will only appear in the event if available.</para>
2975  </parameter>
2976  <parameter name="RegServer">
2977  <para>Asterisk Server name.</para>
2978  </parameter>
2979  <parameter name="PruneOnBoot">
2980  <para>If true delete the contact on Asterisk restart/boot.</para>
2981  </parameter>
2982  <parameter name="Path">
2983  <para>The Path header received on the REGISTER.</para>
2984  </parameter>
2985  <parameter name="Endpoint">
2986  <para>The name of the endpoint associated with this information.</para>
2987  </parameter>
2988  <parameter name="AuthenticateQualify">
2989  <para>A boolean indicating whether a qualify should be authenticated.</para>
2990  </parameter>
2991  <parameter name="Uri">
2992  <para>This contact's URI.</para>
2993  </parameter>
2994  <parameter name="QualifyFrequency">
2995  <para>The interval in seconds at which the contact will be qualified.</para>
2996  </parameter>
2997  <parameter name="UserAgent">
2998  <para>Content of the User-Agent header in REGISTER request</para>
2999  </parameter>
3000  <parameter name="ExpirationTime">
3001  <para>Absolute time that this contact is no longer valid after</para>
3002  </parameter>
3003  <parameter name="OutboundProxy">
3004  <para>The contact's outbound proxy.</para>
3005  </parameter>
3006  <parameter name="Status">
3007  <para>This contact's status.</para>
3008  <enumlist>
3009  <enum name="Reachable"/>
3010  <enum name="Unreachable"/>
3011  <enum name="NonQualified"/>
3012  <enum name="Unknown"/>
3013  </enumlist>
3014  </parameter>
3015  <parameter name="RoundtripUsec">
3016  <para>The round trip time in microseconds.</para>
3017  </parameter>
3018  </syntax>
3019  </managerEventInstance>
3020  </managerEvent>
3021  <managerEvent language="en_US" name="ContactStatusDetail">
3022  <managerEventInstance class="EVENT_FLAG_COMMAND">
3023  <synopsis>Provide details about a contact's status.</synopsis>
3024  <syntax>
3025  <parameter name="AOR">
3026  <para>The AoR that owns this contact.</para>
3027  </parameter>
3028  <parameter name="URI">
3029  <para>This contact's URI.</para>
3030  </parameter>
3031  <parameter name="Status">
3032  <para>This contact's status.</para>
3033  <enumlist>
3034  <enum name="Reachable"/>
3035  <enum name="Unreachable"/>
3036  <enum name="NonQualified"/>
3037  <enum name="Unknown"/>
3038  </enumlist>
3039  </parameter>
3040  <parameter name="RoundtripUsec">
3041  <para>The round trip time in microseconds.</para>
3042  </parameter>
3043  <parameter name="EndpointName">
3044  <para>The name of the endpoint associated with this information.</para>
3045  </parameter>
3046  <parameter name="UserAgent">
3047  <para>Content of the User-Agent header in REGISTER request</para>
3048  </parameter>
3049  <parameter name="RegExpire">
3050  <para>Absolute time that this contact is no longer valid after</para>
3051  </parameter>
3052  <parameter name="ViaAddress">
3053  <para>IP address:port of the last Via header in REGISTER request.
3054  Will only appear in the event if available.</para>
3055  </parameter>
3056  <parameter name="CallID">
3057  <para>Content of the Call-ID header in REGISTER request.
3058  Will only appear in the event if available.</para>
3059  </parameter>
3060  <parameter name="ID">
3061  <para>The sorcery ID of the contact.</para>
3062  </parameter>
3063  <parameter name="AuthenticateQualify">
3064  <para>A boolean indicating whether a qualify should be authenticated.</para>
3065  </parameter>
3066  <parameter name="OutboundProxy">
3067  <para>The contact's outbound proxy.</para>
3068  </parameter>
3069  <parameter name="Path">
3070  <para>The Path header received on the REGISTER.</para>
3071  </parameter>
3072  <parameter name="QualifyFrequency">
3073  <para>The interval in seconds at which the contact will be qualified.</para>
3074  </parameter>
3075  <parameter name="QualifyTimeout">
3076  <para>The elapsed time in decimal seconds after which an OPTIONS
3077  message is sent before the contact is considered unavailable.</para>
3078  </parameter>
3079  </syntax>
3080  </managerEventInstance>
3081  </managerEvent>
3082  <managerEvent language="en_US" name="EndpointList">
3083  <managerEventInstance class="EVENT_FLAG_COMMAND">
3084  <synopsis>Provide details about a contact's status.</synopsis>
3085  <syntax>
3086  <parameter name="ObjectType">
3087  <para>The object's type. This will always be 'endpoint'.</para>
3088  </parameter>
3089  <parameter name="ObjectName">
3090  <para>The name of this object.</para>
3091  </parameter>
3092  <parameter name="Transport">
3093  <para>The transport configurations associated with this endpoint.</para>
3094  </parameter>
3095  <parameter name="Aor">
3096  <para>The aor configurations associated with this endpoint.</para>
3097  </parameter>
3098  <parameter name="Auths">
3099  <para>The inbound authentication configurations associated with this endpoint.</para>
3100  </parameter>
3101  <parameter name="OutboundAuths">
3102  <para>The outbound authentication configurations associated with this endpoint.</para>
3103  </parameter>
3104  <parameter name="DeviceState">
3105  <para>The aggregate device state for this endpoint.</para>
3106  </parameter>
3107  <parameter name="ActiveChannels">
3108  <para>The number of active channels associated with this endpoint.</para>
3109  </parameter>
3110  </syntax>
3111  </managerEventInstance>
3112  </managerEvent>
3113  <manager name="PJSIPShowEndpoints" language="en_US">
3114  <synopsis>
3115  Lists PJSIP endpoints.
3116  </synopsis>
3117  <syntax />
3118  <description>
3119  <para>
3120  Provides a listing of all endpoints. For each endpoint an <literal>EndpointList</literal> event
3121  is raised that contains relevant attributes and status information. Once all
3122  endpoints have been listed an <literal>EndpointListComplete</literal> event is issued.
3123  </para>
3124  </description>
3125  <responses>
3126  <list-elements>
3127  <xi:include xpointer="xpointer(/docs/managerEvent[@name='EndpointList'])" />
3128  </list-elements>
3129  <managerEvent language="en_US" name="EndpointListComplete">
3130  <managerEventInstance class="EVENT_FLAG_COMMAND">
3131  <synopsis>Provide final information about an endpoint list.</synopsis>
3132  <syntax>
3133  <parameter name="EventList"/>
3134  <parameter name="ListItems"/>
3135  </syntax>
3136  </managerEventInstance>
3137  </managerEvent>
3138  </responses>
3139  </manager>
3140  <manager name="PJSIPShowEndpoint" language="en_US">
3141  <synopsis>
3142  Detail listing of an endpoint and its objects.
3143  </synopsis>
3144  <syntax>
3145  <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
3146  <parameter name="Endpoint" required="true">
3147  <para>The endpoint to list.</para>
3148  </parameter>
3149  </syntax>
3150  <description>
3151  <para>
3152  Provides a detailed listing of options for a given endpoint. Events are issued
3153  showing the configuration and status of the endpoint and associated objects. These
3154  events include <literal>EndpointDetail</literal>, <literal>AorDetail</literal>,
3155  <literal>AuthDetail</literal>, <literal>TransportDetail</literal>, and
3156  <literal>IdentifyDetail</literal>. Some events may be listed multiple times if multiple objects are
3157  associated (for instance AoRs). Once all detail events have been raised a final
3158  <literal>EndpointDetailComplete</literal> event is issued.
3159  </para>
3160  </description>
3161  <responses>
3162  <list-elements>
3163  <xi:include xpointer="xpointer(/docs/managerEvent[@name='EndpointDetail'])" />
3164  <xi:include xpointer="xpointer(/docs/managerEvent[@name='IdentifyDetail'])" />
3165  <xi:include xpointer="xpointer(/docs/managerEvent[@name='ContactStatusDetail'])" />
3166  <xi:include xpointer="xpointer(/docs/managerEvent[@name='AuthDetail'])" />
3167  <xi:include xpointer="xpointer(/docs/managerEvent[@name='TransportDetail'])" />
3168  <xi:include xpointer="xpointer(/docs/managerEvent[@name='AorDetail'])" />
3169  </list-elements>
3170  <managerEvent language="en_US" name="EndpointDetailComplete">
3171  <managerEventInstance class="EVENT_FLAG_COMMAND">
3172  <synopsis>Provide final information about endpoint details.</synopsis>
3173  <syntax>
3174  <parameter name="EventList"/>
3175  <parameter name="ListItems"/>
3176  </syntax>
3177  </managerEventInstance>
3178  </managerEvent>
3179  </responses>
3180  </manager>
3181  <manager name="PJSIPShowAors" language="en_US">
3182  <synopsis>
3183  Lists PJSIP AORs.
3184  </synopsis>
3185  <syntax />
3186  <description>
3187  <para>
3188  Provides a listing of all AORs. For each AOR an <literal>AorList</literal> event
3189  is raised that contains relevant attributes and status information. Once all
3190  aors have been listed an <literal>AorListComplete</literal> event is issued.
3191  </para>
3192  </description>
3193  <responses>
3194  <list-elements>
3195  <xi:include xpointer="xpointer(/docs/managerEvent[@name='AorList'])" />
3196  </list-elements>
3197  <managerEvent language="en_US" name="AorListComplete">
3198  <managerEventInstance class="EVENT_FLAG_COMMAND">
3199  <synopsis>Provide final information about an aor list.</synopsis>
3200  <syntax>
3201  <parameter name="EventList"/>
3202  <parameter name="ListItems"/>
3203  </syntax>
3204  </managerEventInstance>
3205  </managerEvent>
3206  </responses>
3207  </manager>
3208  <manager name="PJSIPShowAuths" language="en_US">
3209  <synopsis>
3210  Lists PJSIP Auths.
3211  </synopsis>
3212  <syntax />
3213  <description>
3214  <para>Provides a listing of all Auths. For each Auth an <literal>AuthList</literal> event
3215  is raised that contains relevant attributes and status information. Once all
3216  auths have been listed an <literal>AuthListComplete</literal> event is issued.
3217  </para>
3218  </description>
3219  <responses>
3220  <list-elements>
3221  <xi:include xpointer="xpointer(/docs/managerEvent[@name='AuthList'])" />
3222  </list-elements>
3223  <managerEvent language="en_US" name="AuthListComplete">
3224  <managerEventInstance class="EVENT_FLAG_COMMAND">
3225  <synopsis>Provide final information about an auth list.</synopsis>
3226  <syntax>
3227  <parameter name="EventList"/>
3228  <parameter name="ListItems"/>
3229  </syntax>
3230  </managerEventInstance>
3231  </managerEvent>
3232  </responses>
3233  </manager>
3234  <manager name="PJSIPShowContacts" language="en_US">
3235  <synopsis>
3236  Lists PJSIP Contacts.
3237  </synopsis>
3238  <syntax />
3239  <description>
3240  <para>Provides a listing of all Contacts. For each Contact a <literal>ContactList</literal>
3241  event is raised that contains relevant attributes and status information.
3242  Once all contacts have been listed a <literal>ContactListComplete</literal> event
3243  is issued.
3244  </para>
3245  </description>
3246  <responses>
3247  <list-elements>
3248  <xi:include xpointer="xpointer(/docs/managerEvent[@name='ContactList'])" />
3249  </list-elements>
3250  <managerEvent language="en_US" name="ContactListComplete">
3251  <managerEventInstance class="EVENT_FLAG_COMMAND">
3252  <synopsis>Provide final information about a contact list.</synopsis>
3253  <syntax>
3254  <parameter name="EventList"/>
3255  <parameter name="ListItems"/>
3256  </syntax>
3257  </managerEventInstance>
3258  </managerEvent>
3259  </responses>
3260  </manager>
3261 
3262  ***/
3263 
3264 #define MOD_DATA_CONTACT "contact"
3265 
3266 /*! Number of serializers in pool if one not supplied. */
3267 #define SERIALIZER_POOL_SIZE 8
3268 
3269 /*! Pool of serializers to use if not supplied. */
3271 
3272 static pjsip_endpoint *ast_pjsip_endpoint;
3273 
3275 
3276 /*! Local host address for IPv4 */
3277 static pj_sockaddr host_ip_ipv4;
3278 
3279 /*! Local host address for IPv4 (string form) */
3280 static char host_ip_ipv4_string[PJ_INET6_ADDRSTRLEN];
3281 
3282 /*! Local host address for IPv6 */
3283 static pj_sockaddr host_ip_ipv6;
3284 
3285 /*! Local host address for IPv6 (string form) */
3286 static char host_ip_ipv6_string[PJ_INET6_ADDRSTRLEN];
3287 
3288 void ast_sip_add_date_header(pjsip_tx_data *tdata)
3289 {
3290  char date[256];
3291  struct tm tm;
3292  time_t t = time(NULL);
3293 
3294  gmtime_r(&t, &tm);
3295  strftime(date, sizeof(date), "%a, %d %b %Y %T GMT", &tm);
3296 
3297  ast_sip_add_header(tdata, "Date", date);
3298 }
3299 
3300 static int register_service(void *data)
3301 {
3302  pjsip_module **module = data;
3303  if (!ast_pjsip_endpoint) {
3304  ast_log(LOG_ERROR, "There is no PJSIP endpoint. Unable to register services\n");
3305  return -1;
3306  }
3307  if (pjsip_endpt_register_module(ast_pjsip_endpoint, *module) != PJ_SUCCESS) {
3308  ast_log(LOG_ERROR, "Unable to register module %.*s\n", (int) pj_strlen(&(*module)->name), pj_strbuf(&(*module)->name));
3309  return -1;
3310  }
3311  ast_debug(1, "Registered SIP service %.*s (%p)\n", (int) pj_strlen(&(*module)->name), pj_strbuf(&(*module)->name), *module);
3312  return 0;
3313 }
3314 
3315 int ast_sip_register_service(pjsip_module *module)
3316 {
3318 }
3319 
3320 static int unregister_service(void *data)
3321 {
3322  pjsip_module **module = data;
3323  if (!ast_pjsip_endpoint) {
3324  return -1;
3325  }
3326  pjsip_endpt_unregister_module(ast_pjsip_endpoint, *module);
3327  ast_debug(1, "Unregistered SIP service %.*s\n", (int) pj_strlen(&(*module)->name), pj_strbuf(&(*module)->name));
3328  return 0;
3329 }
3330 
3331 void ast_sip_unregister_service(pjsip_module *module)
3332 {
3334 }
3335 
3337 
3339 {
3340  if (registered_authenticator) {
3341  ast_log(LOG_WARNING, "Authenticator %p is already registered. Cannot register a new one\n", registered_authenticator);
3342  return -1;
3343  }
3344  registered_authenticator = auth;
3345  ast_debug(1, "Registered SIP authenticator module %p\n", auth);
3346 
3347  return 0;
3348 }
3349 
3351 {
3352  if (registered_authenticator != auth) {
3353  ast_log(LOG_WARNING, "Trying to unregister authenticator %p but authenticator %p registered\n",
3354  auth, registered_authenticator);
3355  return;
3356  }
3357  registered_authenticator = NULL;
3358  ast_debug(1, "Unregistered SIP authenticator %p\n", auth);
3359 }
3360 
3361 int ast_sip_requires_authentication(struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
3362 {
3363  if (endpoint->allow_unauthenticated_options
3364  && !pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_options_method)) {
3365  ast_debug(3, "Skipping OPTIONS authentication due to endpoint configuration\n");
3366  return 0;
3367  }
3368 
3369  if (!registered_authenticator) {
3370  ast_log(LOG_WARNING, "No SIP authenticator registered. Assuming authentication is not required\n");
3371  return 0;
3372  }
3373 
3374  return registered_authenticator->requires_authentication(endpoint, rdata);
3375 }
3376 
3378  pjsip_rx_data *rdata, pjsip_tx_data *tdata)
3379 {
3380  if (!registered_authenticator) {
3381  ast_log(LOG_WARNING, "No SIP authenticator registered. Assuming authentication is successful\n");
3383  }
3384  return registered_authenticator->check_authentication(endpoint, rdata, tdata);
3385 }
3386 
3388 
3390 {
3391  if (registered_outbound_authenticator) {
3392  ast_log(LOG_WARNING, "Outbound authenticator %p is already registered. Cannot register a new one\n", registered_outbound_authenticator);
3393  return -1;
3394  }
3395  registered_outbound_authenticator = auth;
3396  ast_debug(1, "Registered SIP outbound authenticator module %p\n", auth);
3397 
3398  return 0;
3399 }
3400 
3402 {
3403  if (registered_outbound_authenticator != auth) {
3404  ast_log(LOG_WARNING, "Trying to unregister outbound authenticator %p but outbound authenticator %p registered\n",
3405  auth, registered_outbound_authenticator);
3406  return;
3407  }
3408  registered_outbound_authenticator = NULL;
3409  ast_debug(1, "Unregistered SIP outbound authenticator %p\n", auth);
3410 }
3411 
3412 int ast_sip_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge,
3413  pjsip_tx_data *old_request, pjsip_tx_data **new_request)
3414 {
3415  if (!registered_outbound_authenticator) {
3416  ast_log(LOG_WARNING, "No SIP outbound authenticator registered. Cannot respond to authentication challenge\n");
3417  return -1;
3418  }
3419  return registered_outbound_authenticator->create_request_with_auth(auths, challenge, old_request, new_request);
3420 }
3421 
3423  const char *name;
3424  unsigned int priority;
3427 };
3428 
3430 
3432  const char *name)
3433 {
3434  char *prev, *current, *identifier_order;
3435  struct endpoint_identifier_list *iter, *id_list_item;
3437 
3438  id_list_item = ast_calloc(1, sizeof(*id_list_item));
3439  if (!id_list_item) {
3440  ast_log(LOG_ERROR, "Unable to add endpoint identifier. Out of memory.\n");
3441  return -1;
3442  }
3443  id_list_item->identifier = identifier;
3444  id_list_item->name = name;
3445 
3446  ast_debug(1, "Register endpoint identifier %s(%p)\n", name ?: "", identifier);
3447 
3448  if (ast_strlen_zero(name)) {
3449  /* if an identifier has no name then place in front */
3450  AST_RWLIST_INSERT_HEAD(&endpoint_identifiers, id_list_item, list);
3451  return 0;
3452  }
3453 
3454  /* see if the name of the identifier is in the global endpoint_identifier_order list */
3455  identifier_order = prev = current = ast_sip_get_endpoint_identifier_order();
3456 
3457  if (ast_strlen_zero(identifier_order)) {
3458  id_list_item->priority = UINT_MAX;
3459  AST_RWLIST_INSERT_TAIL(&endpoint_identifiers, id_list_item, list);
3460  ast_free(identifier_order);
3461  return 0;
3462  }
3463 
3464  id_list_item->priority = 0;
3465  while ((current = strchr(current, ','))) {
3466  ++id_list_item->priority;
3467  if (!strncmp(prev, name, current - prev)
3468  && strlen(name) == current - prev) {
3469  break;
3470  }
3471  prev = ++current;
3472  }
3473 
3474  if (!current) {
3475  /* check to see if it is the only or last item */
3476  if (!strcmp(prev, name)) {
3477  ++id_list_item->priority;
3478  } else {
3479  id_list_item->priority = UINT_MAX;
3480  }
3481  }
3482 
3483  if (id_list_item->priority == UINT_MAX || AST_RWLIST_EMPTY(&endpoint_identifiers)) {
3484  /* if not in the endpoint_identifier_order list then consider it less in
3485  priority and add it to the end */
3486  AST_RWLIST_INSERT_TAIL(&endpoint_identifiers, id_list_item, list);
3487  ast_free(identifier_order);
3488  return 0;
3489  }
3490 
3492  if (id_list_item->priority < iter->priority) {
3493  AST_RWLIST_INSERT_BEFORE_CURRENT(id_list_item, list);
3494  break;
3495  }
3496 
3497  if (!AST_RWLIST_NEXT(iter, list)) {
3498  AST_RWLIST_INSERT_AFTER(&endpoint_identifiers, iter, id_list_item, list);
3499  break;
3500  }
3501  }
3503 
3504  ast_free(identifier_order);
3505  return 0;
3506 }
3507 
3509 {
3511 }
3512 
3514 {
3515  struct endpoint_identifier_list *iter;
3518  if (iter->identifier == identifier) {
3520  ast_free(iter);
3521  ast_debug(1, "Unregistered endpoint identifier %p\n", identifier);
3522  break;
3523  }
3524  }
3526 }
3527 
3528 struct ast_sip_endpoint *ast_sip_identify_endpoint(pjsip_rx_data *rdata)
3529 {
3530  struct endpoint_identifier_list *iter;
3531  struct ast_sip_endpoint *endpoint = NULL;
3535  endpoint = iter->identifier->identify_endpoint(rdata);
3536  if (endpoint) {
3537  break;
3538  }
3539  }
3540  return endpoint;
3541 }
3542 
3543 char *ast_sip_rdata_get_header_value(pjsip_rx_data *rdata, const pj_str_t str)
3544 {
3545  pjsip_generic_string_hdr *hdr;
3546  pj_str_t hdr_val;
3547 
3548  hdr = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str, NULL);
3549  if (!hdr) {
3550  return NULL;
3551  }
3552 
3553  pj_strdup_with_null(rdata->tp_info.pool, &hdr_val, &hdr->hvalue);
3554 
3555  return hdr_val.ptr;
3556 }
3557 
3558 static int do_cli_dump_endpt(void *v_a)
3559 {
3560  struct ast_cli_args *a = v_a;
3561 
3563  pjsip_endpt_dump(ast_sip_get_pjsip_endpoint(), a->argc == 4 ? PJ_TRUE : PJ_FALSE);
3565 
3566  return 0;
3567 }
3568 
3569 static char *cli_dump_endpt(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
3570 {
3571  switch (cmd) {
3572  case CLI_INIT:
3573 #ifdef AST_DEVMODE
3574  e->command = "pjsip dump endpt [details]";
3575  e->usage =
3576  "Usage: pjsip dump endpt [details]\n"
3577  " Dump the res_pjsip endpt internals.\n"
3578  "\n"
3579  "Warning: PJPROJECT documents that the function used by this\n"
3580  "CLI command may cause a crash when asking for details because\n"
3581  "it tries to access all active memory pools.\n";
3582 #else
3583  /*
3584  * In non-developer mode we will not document or make easily accessible
3585  * the details option even though it is still available. The user has
3586  * to know it exists to use it. Presumably they would also be aware of
3587  * the potential crash warning.
3588  */
3589  e->command = "pjsip dump endpt";
3590  e->usage =
3591  "Usage: pjsip dump endpt\n"
3592  " Dump the res_pjsip endpt internals.\n";
3593 #endif /* AST_DEVMODE */
3594  return NULL;
3595  case CLI_GENERATE:
3596  return NULL;
3597  }
3598 
3599  if (4 < a->argc
3600  || (a->argc == 4 && strcasecmp(a->argv[3], "details"))) {
3601  return CLI_SHOWUSAGE;
3602  }
3603 
3605 
3606  return CLI_SUCCESS;
3607 }
3608 
3609 static char *cli_show_endpoint_identifiers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
3610 {
3611 #define ENDPOINT_IDENTIFIER_FORMAT "%-20.20s\n"
3612  struct endpoint_identifier_list *iter;
3613 
3614  switch (cmd) {
3615  case CLI_INIT:
3616  e->command = "pjsip show identifiers";
3617  e->usage = "Usage: pjsip show identifiers\n"
3618  " List all registered endpoint identifiers\n";
3619  return NULL;
3620  case CLI_GENERATE:
3621  return NULL;
3622  }
3623 
3624  if (a->argc != 3) {
3625  return CLI_SHOWUSAGE;
3626  }
3627 
3628  ast_cli(a->fd, ENDPOINT_IDENTIFIER_FORMAT, "Identifier Names:");
3629  {
3633  iter->name ? iter->name : "name not specified");
3634  }
3635  }
3636  return CLI_SUCCESS;
3637 #undef ENDPOINT_IDENTIFIER_FORMAT
3638 }
3639 
3640 static char *cli_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
3641 {
3642  struct ast_sip_cli_context context;
3643 
3644  switch (cmd) {
3645  case CLI_INIT:
3646  e->command = "pjsip show settings";
3647  e->usage = "Usage: pjsip show settings\n"
3648  " Show global and system configuration options\n";
3649  return NULL;
3650  case CLI_GENERATE:
3651  return NULL;
3652  }
3653 
3654  context.output_buffer = ast_str_create(256);
3655  if (!context.output_buffer) {
3656  ast_cli(a->fd, "Could not allocate output buffer.\n");
3657  return CLI_FAILURE;
3658  }
3659 
3660  if (sip_cli_print_global(&context) || sip_cli_print_system(&context)) {
3661  ast_free(context.output_buffer);
3662  ast_cli(a->fd, "Error retrieving settings.\n");
3663  return CLI_FAILURE;
3664  }
3665 
3666  ast_cli(a->fd, "%s", ast_str_buffer(context.output_buffer));
3667  ast_free(context.output_buffer);
3668  return CLI_SUCCESS;
3669 }
3670 
3671 static struct ast_cli_entry cli_commands[] = {
3672  AST_CLI_DEFINE(cli_dump_endpt, "Dump the res_pjsip endpt internals"),
3673  AST_CLI_DEFINE(cli_show_settings, "Show global and system configuration options"),
3674  AST_CLI_DEFINE(cli_show_endpoint_identifiers, "List registered endpoint identifiers")
3675 };
3676 
3678 
3680 {
3683 }
3684 
3686 {
3687  struct ast_sip_endpoint_formatter *i;
3689 
3691  if (i == obj) {
3693  break;
3694  }
3695  }
3697 }
3698 
3700  struct ast_sip_ami *ami, int *count)
3701 {
3702  int res = 0;
3703  struct ast_sip_endpoint_formatter *i;
3705  *count = 0;
3707  if (i->format_ami && ((res = i->format_ami(endpoint, ami)) < 0)) {
3708  return res;
3709  }
3710 
3711  if (!res) {
3712  (*count)++;
3713  }
3714  }
3715  return 0;
3716 }
3717 
3718 pjsip_endpoint *ast_sip_get_pjsip_endpoint(void)
3719 {
3720  return ast_pjsip_endpoint;
3721 }
3722 
3723 int ast_sip_will_uri_survive_restart(pjsip_sip_uri *uri, struct ast_sip_endpoint *endpoint,
3724  pjsip_rx_data *rdata)
3725 {
3726  pj_str_t host_name;
3727  int result = 1;
3728 
3729  /* Determine if the contact cannot survive a restart/boot. */
3730  if (uri->port == rdata->pkt_info.src_port
3731  && !pj_strcmp(&uri->host,
3732  pj_cstr(&host_name, rdata->pkt_info.src_name))
3733  /* We have already checked if the URI scheme is sip: or sips: */
3734  && PJSIP_TRANSPORT_IS_RELIABLE(rdata->tp_info.transport)) {
3735  pj_str_t type_name;
3736 
3737  /* Determine the transport parameter value */
3738  if (!strcasecmp("WSS", rdata->tp_info.transport->type_name)) {
3739  /* WSS is special, as it needs to be ws. */
3740  pj_cstr(&type_name, "ws");
3741  } else {
3742  pj_cstr(&type_name, rdata->tp_info.transport->type_name);
3743  }
3744 
3745  if (!pj_stricmp(&uri->transport_param, &type_name)
3746  && (endpoint->nat.rewrite_contact
3747  /* Websockets are always rewritten */
3748  || !pj_stricmp(&uri->transport_param,
3749  pj_cstr(&type_name, "ws")))) {
3750  /*
3751  * The contact was rewritten to the reliable transport's
3752  * source address. Disconnecting the transport for any
3753  * reason invalidates the contact.
3754  */
3755  result = 0;
3756  }
3757  }
3758 
3759  return result;
3760 }
3761 
3763  pjsip_sip_uri *sip_uri, char *buf, size_t buf_len)
3764 {
3765  char *host = NULL;
3766  static const pj_str_t x_name = { AST_SIP_X_AST_TXP, AST_SIP_X_AST_TXP_LEN };
3767  pjsip_param *x_transport;
3768 
3769  if (!ast_strlen_zero(endpoint->transport)) {
3770  ast_copy_string(buf, endpoint->transport, buf_len);
3771  return 0;
3772  }
3773 
3774  x_transport = pjsip_param_find(&sip_uri->other_param, &x_name);
3775  if (!x_transport) {
3776  return -1;
3777  }
3778 
3779  /* Only use x_transport if the uri host is an ip (4 or 6) address */
3780  host = ast_alloca(sip_uri->host.slen + 1);
3781  ast_copy_pj_str(host, &sip_uri->host, sip_uri->host.slen + 1);
3782  if (!ast_sockaddr_parse(NULL, host, PARSE_PORT_FORBID)) {
3783  return -1;
3784  }
3785 
3786  ast_copy_pj_str(buf, &x_transport->value, buf_len);
3787 
3788  return 0;
3789 }
3790 
3791 int ast_sip_dlg_set_transport(const struct ast_sip_endpoint *endpoint, pjsip_dialog *dlg,
3792  pjsip_tpselector *selector)
3793 {
3794  pjsip_sip_uri *uri;
3795  pjsip_tpselector sel = { .type = PJSIP_TPSELECTOR_NONE, };
3796 
3797  uri = pjsip_uri_get_uri(dlg->target);
3798  if (!selector) {
3799  selector = &sel;
3800  }
3801 
3802  ast_sip_set_tpselector_from_ep_or_uri(endpoint, uri, selector);
3803 
3804  pjsip_dlg_set_transport(dlg, selector);
3805 
3806  if (selector == &sel) {
3808  }
3809 
3810  return 0;
3811 }
3812 
3813 static int sip_dialog_create_from(pj_pool_t *pool, pj_str_t *from, const char *user,
3814  const char *domain, const pj_str_t *target, pjsip_tpselector *selector)
3815 {
3816  pj_str_t tmp, local_addr;
3817  pjsip_uri *uri;
3818  pjsip_sip_uri *sip_uri;
3819  pjsip_transport_type_e type;
3820  int local_port;
3821  char default_user[PJSIP_MAX_URL_SIZE];
3822 
3823  if (ast_strlen_zero(user)) {
3824  ast_sip_get_default_from_user(default_user, sizeof(default_user));
3825  user = default_user;
3826  }
3827 
3828  /* Parse the provided target URI so we can determine what transport it will end up using */
3829  pj_strdup_with_null(pool, &tmp, target);
3830 
3831  if (!(uri = pjsip_parse_uri(pool, tmp.ptr, tmp.slen, 0)) ||
3832  (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri))) {
3833  return -1;
3834  }
3835 
3836  sip_uri = pjsip_uri_get_uri(uri);
3837 
3838  /* Determine the transport type to use */
3839  type = pjsip_transport_get_type_from_name(&sip_uri->transport_param);
3840  if (PJSIP_URI_SCHEME_IS_SIPS(sip_uri)) {
3841  if (type == PJSIP_TRANSPORT_UNSPECIFIED
3842  || !(pjsip_transport_get_flag_from_type(type) & PJSIP_TRANSPORT_SECURE)) {
3843  type = PJSIP_TRANSPORT_TLS;
3844  }
3845  } else if (!sip_uri->transport_param.slen) {
3846  type = PJSIP_TRANSPORT_UDP;
3847  } else if (type == PJSIP_TRANSPORT_UNSPECIFIED) {
3848  return -1;
3849  }
3850 
3851  /* If the host is IPv6 turn the transport into an IPv6 version */
3852  if (pj_strchr(&sip_uri->host, ':')) {
3853  type |= PJSIP_TRANSPORT_IPV6;
3854  }
3855 
3856  /* In multidomain scenario, username may contain @ with domain info */
3857  if (!ast_sip_get_disable_multi_domain() && strchr(user, '@')) {
3858  from->ptr = pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE);
3859  from->slen = pj_ansi_snprintf(from->ptr, PJSIP_MAX_URL_SIZE,
3860  "<sip:%s%s%s>",
3861  user,
3862  (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? ";transport=" : "",
3863  (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? pjsip_transport_get_type_name(type) : "");
3864  return 0;
3865  }
3866 
3867  if (!ast_strlen_zero(domain)) {
3868  from->ptr = pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE);
3869  from->slen = pj_ansi_snprintf(from->ptr, PJSIP_MAX_URL_SIZE,
3870  "<sip:%[email protected]%s%s%s>",
3871  user,
3872  domain,
3873  (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? ";transport=" : "",
3874  (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? pjsip_transport_get_type_name(type) : "");
3875  return 0;
3876  }
3877 
3878  /* Get the local bound address for the transport that will be used when communicating with the provided URI */
3879  if (pjsip_tpmgr_find_local_addr(pjsip_endpt_get_tpmgr(ast_sip_get_pjsip_endpoint()), pool, type, selector,
3880  &local_addr, &local_port) != PJ_SUCCESS) {
3881 
3882  /* If no local address can be retrieved using the transport manager use the host one */
3883  pj_strdup(pool, &local_addr, pj_gethostname());
3884  local_port = pjsip_transport_get_default_port_for_type(PJSIP_TRANSPORT_UDP);
3885  }
3886 
3887  /* If IPv6 was specified in the transport, set the proper type */
3888  if (pj_strchr(&local_addr, ':')) {
3889  type |= PJSIP_TRANSPORT_IPV6;
3890  }
3891 
3892  from->ptr = pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE);
3893  from->slen = pj_ansi_snprintf(from->ptr, PJSIP_MAX_URL_SIZE,
3894  "<sip:%[email protected]%s%.*s%s:%d%s%s>",
3895  user,
3896  (type & PJSIP_TRANSPORT_IPV6) ? "[" : "",
3897  (int)local_addr.slen,
3898  local_addr.ptr,
3899  (type & PJSIP_TRANSPORT_IPV6) ? "]" : "",
3900  local_port,
3901  (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? ";transport=" : "",
3902  (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? pjsip_transport_get_type_name(type) : "");
3903 
3904  return 0;
3905 }
3906 
3907 int ast_sip_set_tpselector_from_transport(const struct ast_sip_transport *transport, pjsip_tpselector *selector)
3908 {
3909  int res = 0;
3910  struct ast_sip_transport_state *transport_state;
3911 
3912  transport_state = ast_sip_get_transport_state(ast_sorcery_object_get_id(transport));
3913  if (!transport_state) {
3914  ast_log(LOG_ERROR, "Unable to retrieve PJSIP transport state for '%s'\n",
3915  ast_sorcery_object_get_id(transport));
3916  return -1;
3917  }
3918 
3919  /* Only flows maintain dynamic state which needs protection */
3920  if (transport_state->flow) {
3921  ao2_lock(transport_state);
3922  }
3923 
3924  if (transport_state->transport) {
3925  selector->type = PJSIP_TPSELECTOR_TRANSPORT;
3926  selector->u.transport = transport_state->transport;
3927  pjsip_transport_add_ref(selector->u.transport);
3928  } else if (transport_state->factory) {
3929  selector->type = PJSIP_TPSELECTOR_LISTENER;
3930  selector->u.listener = transport_state->factory;
3931  } else if (transport->type == AST_TRANSPORT_WS || transport->type == AST_TRANSPORT_WSS) {
3932  /* The WebSocket transport has no factory as it can not create outgoing connections, so
3933  * even if an endpoint is locked to a WebSocket transport we let the PJSIP logic
3934  * find the existing connection if available and use it.
3935  */
3936  } else if (transport->flow) {
3937  /* This is a child of another transport, so we need to establish a new connection */
3938 #ifdef HAVE_PJSIP_TRANSPORT_DISABLE_CONNECTION_REUSE
3939  selector->disable_connection_reuse = PJ_TRUE;
3940 #else
3941  ast_log(LOG_WARNING, "Connection reuse could not be disabled on transport '%s' as support is not available\n",
3942  ast_sorcery_object_get_id(transport));
3943 #endif
3944  } else {
3945  res = -1;
3946  }
3947 
3948  if (transport_state->flow) {
3949  ao2_unlock(transport_state);
3950  }
3951 
3952  ao2_ref(transport_state, -1);
3953 
3954  return res;
3955 }
3956 
3957 int ast_sip_set_tpselector_from_transport_name(const char *transport_name, pjsip_tpselector *selector)
3958 {
3960 
3961  if (ast_strlen_zero(transport_name)) {
3962  return 0;
3963  }
3964 
3965  transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_name);
3966  if (!transport) {
3967  ast_log(LOG_ERROR, "Unable to retrieve PJSIP transport '%s'\n",
3968  transport_name);
3969  return -1;
3970  }
3971 
3973 }
3974 
3976  pjsip_sip_uri *sip_uri, pjsip_tpselector *selector)
3977 {
3978  char transport_name[128];
3979 
3980  if (ast_sip_get_transport_name(endpoint, sip_uri, transport_name, sizeof(transport_name))) {
3981  return 0;
3982  }
3983 
3984  return ast_sip_set_tpselector_from_transport_name(transport_name, selector);
3985 }
3986 
3987 void ast_sip_tpselector_unref(pjsip_tpselector *selector)
3988 {
3989  if (selector->type == PJSIP_TPSELECTOR_TRANSPORT && selector->u.transport) {
3990  pjsip_transport_dec_ref(selector->u.transport);
3991  }
3992 }
3993 
3994 void ast_sip_add_usereqphone(const struct ast_sip_endpoint *endpoint, pj_pool_t *pool, pjsip_uri *uri)
3995 {
3996  pjsip_sip_uri *sip_uri;
3997  int i = 0;
3998  static const pj_str_t STR_PHONE = { "phone", 5 };
3999 
4000  if (!endpoint || !endpoint->usereqphone || (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri))) {
4001  return;
4002  }
4003 
4004  sip_uri = pjsip_uri_get_uri(uri);
4005 
4006  if (!pj_strlen(&sip_uri->user)) {
4007  return;
4008  }
4009 
4010  if (pj_strbuf(&sip_uri->user)[0] == '+') {
4011  i = 1;
4012  }
4013 
4014  /* Test URI user against allowed characters in AST_DIGIT_ANY */
4015  for (; i < pj_strlen(&sip_uri->user); i++) {
4016  if (!strchr(AST_DIGIT_ANY, pj_strbuf(&sip_uri->user)[i])) {
4017  break;
4018  }
4019  }
4020 
4021  if (i < pj_strlen(&sip_uri->user)) {
4022  return;
4023  }
4024 
4025  sip_uri->user_param = STR_PHONE;
4026 }
4027 
4028 pjsip_dialog *ast_sip_create_dialog_uac(const struct ast_sip_endpoint *endpoint,
4029  const char *uri, const char *request_user)
4030 {
4031  char enclosed_uri[PJSIP_MAX_URL_SIZE];
4032  pj_str_t local_uri = { "sip:[email protected]", 13 }, remote_uri, target_uri;
4033  pj_status_t res;
4034  pjsip_dialog *dlg = NULL;
4035  const char *outbound_proxy = endpoint->outbound_proxy;
4036  pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
4037  static const pj_str_t HCONTACT = { "Contact", 7 };
4038 
4039  snprintf(enclosed_uri, sizeof(enclosed_uri), "<%s>", uri);
4040  pj_cstr(&remote_uri, enclosed_uri);
4041 
4042  pj_cstr(&target_uri, uri);
4043 
4044  res = pjsip_dlg_create_uac(pjsip_ua_instance(), &local_uri, NULL, &remote_uri, &target_uri, &dlg);
4045  if (res == PJ_SUCCESS && !(PJSIP_URI_SCHEME_IS_SIP(dlg->target) || PJSIP_URI_SCHEME_IS_SIPS(dlg->target))) {
4046  /* dlg->target is a pjsip_other_uri, but it's assumed to be a
4047  * pjsip_sip_uri below. Fail fast. */
4048  res = PJSIP_EINVALIDURI;
4049  pjsip_dlg_terminate(dlg);
4050  }
4051  if (res != PJ_SUCCESS) {
4052  if (res == PJSIP_EINVALIDURI) {
4054  "Endpoint '%s': Could not create dialog to invalid URI '%s'. Is endpoint registered and reachable?\n",
4055  ast_sorcery_object_get_id(endpoint), uri);
4056  }
4057  return NULL;
4058  }
4059 
4060  /* We have to temporarily bump up the sess_count here so the dialog is not prematurely destroyed */
4061  dlg->sess_count++;
4062 
4063  ast_sip_dlg_set_transport(endpoint, dlg, &selector);
4064 
4065  if (sip_dialog_create_from(dlg->pool, &local_uri, endpoint->fromuser, endpoint->fromdomain, &remote_uri, &selector)) {
4066  dlg->sess_count--;
4067  pjsip_dlg_terminate(dlg);
4068  ast_sip_tpselector_unref(&selector);
4069  return NULL;
4070  }
4071 
4072  ast_sip_tpselector_unref(&selector);
4073 
4074  /* Update the dialog with the new local URI, we do it afterwards so we can use the dialog pool for construction */
4075  pj_strdup_with_null(dlg->pool, &dlg->local.info_str, &local_uri);
4076  dlg->local.info->uri = pjsip_parse_uri(dlg->pool, dlg->local.info_str.ptr, dlg->local.info_str.slen, 0);
4077  if (!dlg->local.info->uri) {
4079  "Could not parse URI '%s' for endpoint '%s'\n",
4080  dlg->local.info_str.ptr, ast_sorcery_object_get_id(endpoint));
4081  dlg->sess_count--;
4082  pjsip_dlg_terminate(dlg);
4083  return NULL;
4084  }
4085 
4086  dlg->local.contact = pjsip_parse_hdr(dlg->pool, &HCONTACT, local_uri.ptr, local_uri.slen, NULL);
4087 
4088  if (!ast_strlen_zero(endpoint->contact_user)) {
4089  pjsip_sip_uri *sip_uri;
4090 
4091  sip_uri = pjsip_uri_get_uri(dlg->local.contact->uri);
4092  pj_strdup2(dlg->pool, &sip_uri->user, endpoint->contact_user);
4093  }
4094 
4095  /* If a request user has been specified and we are permitted to change it, do so */
4096  if (!ast_strlen_zero(request_user)) {
4097  pjsip_sip_uri *sip_uri;
4098 
4099  if (PJSIP_URI_SCHEME_IS_SIP(dlg->target) || PJSIP_URI_SCHEME_IS_SIPS(dlg->target)) {
4100  sip_uri = pjsip_uri_get_uri(dlg->target);
4101  pj_strdup2(dlg->pool, &sip_uri->user, request_user);
4102  }
4103  if (PJSIP_URI_SCHEME_IS_SIP(dlg->remote.info->uri) || PJSIP_URI_SCHEME_IS_SIPS(dlg->remote.info->uri)) {
4104  sip_uri = pjsip_uri_get_uri(dlg->remote.info->uri);
4105  pj_strdup2(dlg->pool, &sip_uri->user, request_user);
4106  }
4107  }
4108 
4109  /* Add the user=phone parameter if applicable */
4110  ast_sip_add_usereqphone(endpoint, dlg->pool, dlg->target);
4111  ast_sip_add_usereqphone(endpoint, dlg->pool, dlg->remote.info->uri);
4112 
4113  if (!ast_strlen_zero(outbound_proxy)) {
4114  pjsip_route_hdr route_set, *route;
4115  static const pj_str_t ROUTE_HNAME = { "Route", 5 };
4116  pj_str_t tmp;
4117 
4118  pj_list_init(&route_set);
4119 
4120  pj_strdup2_with_null(dlg->pool, &tmp, outbound_proxy);
4121  if (!(route = pjsip_parse_hdr(dlg->pool, &ROUTE_HNAME, tmp.ptr, tmp.slen, NULL))) {
4122  ast_log(LOG_ERROR, "Could not create dialog to endpoint '%s' as outbound proxy URI '%s' is not valid\n",
4123  ast_sorcery_object_get_id(endpoint), outbound_proxy);
4124  dlg->sess_count--;
4125  pjsip_dlg_terminate(dlg);
4126  return NULL;
4127  }
4128  pj_list_insert_nodes_before(&route_set, route);
4129 
4130  pjsip_dlg_set_route_set(dlg, &route_set);
4131  }
4132 
4133  dlg->sess_count--;
4134 
4135  return dlg;
4136 }
4137 
4138 /*!
4139  * \brief Determine if a SIPS Contact header is required.
4140  *
4141  * This uses the guideline provided in RFC 3261 Section 12.1.1 to
4142  * determine if the Contact header must be a sips: URI.
4143  *
4144  * \param rdata The incoming dialog-starting request
4145  * \retval 0 SIPS not required
4146  * \retval 1 SIPS required
4147  */
4148 static int uas_use_sips_contact(pjsip_rx_data *rdata)
4149 {
4150  pjsip_rr_hdr *record_route;
4151 
4152  if (PJSIP_URI_SCHEME_IS_SIPS(rdata->msg_info.msg->line.req.uri)) {
4153  return 1;
4154  }
4155 
4156  record_route = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_RECORD_ROUTE, NULL);
4157  if (record_route) {
4158  if (PJSIP_URI_SCHEME_IS_SIPS(&record_route->name_addr)) {
4159  return 1;
4160  }
4161  } else {
4162  pjsip_contact_hdr *contact;
4163 
4164  contact = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
4165  ast_assert(contact != NULL);
4166  if (PJSIP_URI_SCHEME_IS_SIPS(contact->uri)) {
4167  return 1;
4168  }
4169  }
4170 
4171  return 0;
4172 }
4173 
4174 typedef pj_status_t (*create_dlg_uac)(pjsip_user_agent *ua, pjsip_rx_data *rdata,
4175  const pj_str_t *contact, pjsip_dialog **p_dlg);
4176 
4177 static pjsip_dialog *create_dialog_uas(const struct ast_sip_endpoint *endpoint,
4178  pjsip_rx_data *rdata, pj_status_t *status, create_dlg_uac create_fun)
4179 {
4180  pjsip_dialog *dlg;
4181  pj_str_t contact;
4182  pjsip_transport_type_e type = rdata->tp_info.transport->key.type;
4183  pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
4184  pjsip_transport *transport;
4185  pjsip_contact_hdr *contact_hdr;
4186 
4187  ast_assert(status != NULL);
4188 
4189  contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
4190  if (!contact_hdr || ast_sip_set_tpselector_from_ep_or_uri(endpoint, pjsip_uri_get_uri(contact_hdr->uri),
4191  &selector)) {
4192  return NULL;
4193  }
4194 
4195  transport = rdata->tp_info.transport;
4196  if (selector.type == PJSIP_TPSELECTOR_TRANSPORT) {
4197  transport = selector.u.transport;
4198  }
4199  type = transport->key.type;
4200 
4201  contact.ptr = pj_pool_alloc(rdata->tp_info.pool, PJSIP_MAX_URL_SIZE);
4202  contact.slen = pj_ansi_snprintf(contact.ptr, PJSIP_MAX_URL_SIZE,
4203  "<%s:%s%.*s%s:%d%s%s>",
4204  uas_use_sips_contact(rdata) ? "sips" : "sip",
4205  (type & PJSIP_TRANSPORT_IPV6) ? "[" : "",
4206  (int)transport->local_name.host.slen,
4207  transport->local_name.host.ptr,
4208  (type & PJSIP_TRANSPORT_IPV6) ? "]" : "",
4209  transport->local_name.port,
4210  (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? ";transport=" : "",
4211  (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? pjsip_transport_get_type_name(type) : "");
4212 
4213  *status = create_fun(pjsip_ua_instance(), rdata, &contact, &dlg);
4214  if (*status != PJ_SUCCESS) {
4215  char err[PJ_ERR_MSG_SIZE];
4216 
4217  pj_strerror(*status, err, sizeof(err));
4218  ast_log(LOG_ERROR, "Could not create dialog with endpoint %s. %s\n",
4219  ast_sorcery_object_get_id(endpoint), err);
4220  ast_sip_tpselector_unref(&selector);
4221  return NULL;
4222  }
4223 
4224  dlg->sess_count++;
4225  pjsip_dlg_set_transport(dlg, &selector);
4226  dlg->sess_count--;
4227 
4228  ast_sip_tpselector_unref(&selector);
4229 
4230  return dlg;
4231 }
4232 
4233 pjsip_dialog *ast_sip_create_dialog_uas(const struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, pj_status_t *status)
4234 {
4235 #ifdef HAVE_PJSIP_DLG_CREATE_UAS_AND_INC_LOCK
4236  pjsip_dialog *dlg;
4237 
4238  dlg = create_dialog_uas(endpoint, rdata, status, pjsip_dlg_create_uas_and_inc_lock);
4239  if (dlg) {
4240  pjsip_dlg_dec_lock(dlg);
4241  }
4242 
4243  return dlg;
4244 #else
4245  return create_dialog_uas(endpoint, rdata, status, pjsip_dlg_create_uas);
4246 #endif
4247 }
4248 
4249 pjsip_dialog *ast_sip_create_dialog_uas_locked(const struct ast_sip_endpoint *endpoint,
4250  pjsip_rx_data *rdata, pj_status_t *status)
4251 {
4252 #ifdef HAVE_PJSIP_DLG_CREATE_UAS_AND_INC_LOCK
4253  return create_dialog_uas(endpoint, rdata, status, pjsip_dlg_create_uas_and_inc_lock);
4254 #else
4255  /*
4256  * This is put here in order to be compatible with older versions of pjproject.
4257  * Best we can do in this case is immediately lock after getting the dialog.
4258  * However, that does leave a "gap" between creating and locking.
4259  */
4260  pjsip_dialog *dlg;
4261 
4262  dlg = create_dialog_uas(endpoint, rdata, status, pjsip_dlg_create_uas);
4263  if (dlg) {
4264  pjsip_dlg_inc_lock(dlg);
4265  }
4266 
4267  return dlg;
4268 #endif
4269  }
4270 
4271 int ast_sip_create_rdata_with_contact(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port,
4272  char *transport_type, const char *local_name, int local_port, const char *contact)
4273 {
4274  pj_str_t tmp;
4275 
4276  /*
4277  * Initialize the error list in case there is a parse error
4278  * in the given packet.
4279  */
4280  pj_list_init(&rdata->msg_info.parse_err);
4281 
4282  rdata->tp_info.transport = PJ_POOL_ZALLOC_T(rdata->tp_info.pool, pjsip_transport);
4283  if (!rdata->tp_info.transport) {
4284  return -1;
4285  }
4286 
4287  ast_copy_string(rdata->pkt_info.packet, packet, sizeof(rdata->pkt_info.packet));
4288  ast_copy_string(rdata->pkt_info.src_name, src_name, sizeof(rdata->pkt_info.src_name));
4289  rdata->pkt_info.src_port = src_port;
4290  pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&tmp, src_name), &rdata->pkt_info.src_addr);
4291  pj_sockaddr_set_port(&rdata->pkt_info.src_addr, src_port);
4292 
4293  pjsip_parse_rdata(packet, strlen(packet), rdata);
4294  if (!rdata->msg_info.msg || !pj_list_empty(&rdata->msg_info.parse_err)) {
4295  return -1;
4296  }
4297 
4298  if (!ast_strlen_zero(contact)) {
4299  pjsip_contact_hdr *contact_hdr;
4300 
4301  contact_hdr = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_CONTACT, NULL);
4302  if (contact_hdr) {
4303  contact_hdr->uri = pjsip_parse_uri(rdata->tp_info.pool, (char *)contact,
4304  strlen(contact), PJSIP_PARSE_URI_AS_NAMEADDR);
4305  if (!contact_hdr->uri) {
4306  ast_log(LOG_WARNING, "Unable to parse contact URI from '%s'.\n", contact);
4307  return -1;
4308  }
4309  }
4310  }
4311 
4312  pj_strdup2(rdata->tp_info.pool, &rdata->msg_info.via->recvd_param, rdata->pkt_info.src_name);
4313  rdata->msg_info.via->rport_param = -1;
4314 
4315  rdata->tp_info.transport->key.type = pjsip_transport_get_type_from_name(pj_cstr(&tmp, transport_type));
4316  rdata->tp_info.transport->type_name = transport_type;
4317  pj_strdup2(rdata->tp_info.pool, &rdata->tp_info.transport->local_name.host, local_name);
4318  rdata->tp_info.transport->local_name.port = local_port;
4319 
4320  return 0;
4321 }
4322 
4323 int ast_sip_create_rdata(pjsip_rx_data *rdata, char *packet, const char *src_name, int src_port,
4324  char *transport_type, const char *local_name, int local_port)
4325 {
4326  return ast_sip_create_rdata_with_contact(rdata, packet, src_name, src_port, transport_type,
4327  local_name, local_port, NULL);
4328 }
4329 
4330 /* PJSIP doesn't know about the INFO method, so we have to define it ourselves */
4331 static const pjsip_method info_method = {PJSIP_OTHER_METHOD, {"INFO", 4} };
4332 static const pjsip_method message_method = {PJSIP_OTHER_METHOD, {"MESSAGE", 7} };
4333 
4334 static struct {
4335  const char *method;
4336  const pjsip_method *pmethod;
4337 } methods [] = {
4338  { "INVITE", &pjsip_invite_method },
4339  { "CANCEL", &pjsip_cancel_method },
4340  { "ACK", &pjsip_ack_method },
4341  { "BYE", &pjsip_bye_method },
4342  { "REGISTER", &pjsip_register_method },
4343  { "OPTIONS", &pjsip_options_method },
4344  { "SUBSCRIBE", &pjsip_subscribe_method },
4345  { "NOTIFY", &pjsip_notify_method },
4346  { "PUBLISH", &pjsip_publish_method },
4347  { "INFO", &info_method },
4348  { "MESSAGE", &message_method },
4349 };
4350 
4351 static const pjsip_method *get_pjsip_method(const char *method)
4352 {
4353  int i;
4354  for (i = 0; i < ARRAY_LEN(methods); ++i) {
4355  if (!strcmp(method, methods[i].method)) {
4356  return methods[i].pmethod;
4357  }
4358  }
4359  return NULL;
4360 }
4361 
4362 static int create_in_dialog_request(const pjsip_method *method, struct pjsip_dialog *dlg, pjsip_tx_data **tdata)
4363 {
4364  if (pjsip_dlg_create_request(dlg, method, -1, tdata) != PJ_SUCCESS) {
4365  ast_log(LOG_WARNING, "Unable to create in-dialog request.\n");
4366  return -1;
4367  }
4368 
4369  return 0;
4370 }
4371 
4372 static pj_bool_t supplement_on_rx_request(pjsip_rx_data *rdata);
4373 static pjsip_module supplement_module = {
4374  .name = { "Out of dialog supplement hook", 29 },
4375  .id = -1,
4376  .priority = PJSIP_MOD_PRIORITY_APPLICATION - 1,
4377  .on_rx_request = supplement_on_rx_request,
4378 };
4379 
4380 static int create_out_of_dialog_request(const pjsip_method *method, struct ast_sip_endpoint *endpoint,
4381  const char *uri, struct ast_sip_contact *provided_contact, pjsip_tx_data **tdata)
4382 {
4383  RAII_VAR(struct ast_sip_contact *, contact, ao2_bump(provided_contact), ao2_cleanup);
4384  pj_str_t remote_uri;
4385  pj_str_t from;
4386  pj_pool_t *pool;
4387  pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
4388  pjsip_uri *sip_uri;
4389  const char *fromuser;
4390 
4391  if (ast_strlen_zero(uri)) {
4392  if (!endpoint && (!contact || ast_strlen_zero(contact->uri))) {
4393  ast_log(LOG_ERROR, "An endpoint and/or uri must be specified\n");
4394  return -1;
4395  }
4396 
4397  if (!contact) {
4399  }
4400  if (!contact || ast_strlen_zero(contact->uri)) {
4401  ast_log(LOG_WARNING, "Unable to retrieve contact for endpoint %s\n",
4402  ast_sorcery_object_get_id(endpoint));
4403  return -1;
4404  }
4405 
4406  pj_cstr(&remote_uri, contact->uri);
4407  } else {
4408  pj_cstr(&remote_uri, uri);
4409  }
4410 
4411  pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "Outbound request", 256, 256);
4412 
4413  if (!pool) {
4414  ast_log(LOG_ERROR, "Unable to create PJLIB memory pool\n");
4415  return -1;
4416  }
4417 
4418  sip_uri = pjsip_parse_uri(pool, remote_uri.ptr, remote_uri.slen, 0);
4419  if (!sip_uri || (!PJSIP_URI_SCHEME_IS_SIP(sip_uri) && !PJSIP_URI_SCHEME_IS_SIPS(sip_uri))) {
4420  ast_log(LOG_ERROR, "Unable to create outbound %.*s request to endpoint %s as URI '%s' is not valid\n",
4421  (int) pj_strlen(&method->name), pj_strbuf(&method->name),
4422  endpoint ? ast_sorcery_object_get_id(endpoint) : "<none>",
4423  pj_strbuf(&remote_uri));
4424  pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
4425  return -1;
4426  }
4427 
4428  ast_sip_set_tpselector_from_ep_or_uri(endpoint, pjsip_uri_get_uri(sip_uri), &selector);
4429 
4430  fromuser = endpoint ? (!ast_strlen_zero(endpoint->fromuser) ? endpoint->fromuser : ast_sorcery_object_get_id(endpoint)) : NULL;
4431  if (sip_dialog_create_from(pool, &from, fromuser,
4432  endpoint ? endpoint->fromdomain : NULL, &remote_uri, &selector)) {
4433  ast_log(LOG_ERROR, "Unable to create From header for %.*s request to endpoint %s\n",
4434  (int) pj_strlen(&method->name), pj_strbuf(&method->name),
4435  endpoint ? ast_sorcery_object_get_id(endpoint) : "<none>");
4436  pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
4437  ast_sip_tpselector_unref(&selector);
4438  return -1;
4439  }
4440 
4441  if (pjsip_endpt_create_request(ast_sip_get_pjsip_endpoint(), method, &remote_uri,
4442  &from, &remote_uri, &from, NULL, -1, NULL, tdata) != PJ_SUCCESS) {
4443  ast_log(LOG_ERROR, "Unable to create outbound %.*s request to endpoint %s\n",
4444  (int) pj_strlen(&method->name), pj_strbuf(&method->name),
4445  endpoint ? ast_sorcery_object_get_id(endpoint) : "<none>");
4446  pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
4447  ast_sip_tpselector_unref(&selector);
4448  return -1;
4449  }
4450 
4451  pjsip_tx_data_set_transport(*tdata, &selector);
4452 
4453  ast_sip_tpselector_unref(&selector);
4454 
4455  if (endpoint && !ast_strlen_zero(endpoint->contact_user)){
4456  pjsip_contact_hdr *contact_hdr;
4457  pjsip_sip_uri *contact_uri;
4458  static const pj_str_t HCONTACT = { "Contact", 7 };
4459  static const pj_str_t HCONTACTSHORT = { "m", 1 };
4460 
4461  contact_hdr = pjsip_msg_find_hdr_by_names((*tdata)->msg, &HCONTACT, &HCONTACTSHORT, NULL);
4462  if (contact_hdr) {
4463  contact_uri = pjsip_uri_get_uri(contact_hdr->uri);
4464  pj_strdup2((*tdata)->pool, &contact_uri->user, endpoint->contact_user);
4465  }
4466  }
4467 
4468  /* Add the user=phone parameter if applicable */
4469  ast_sip_add_usereqphone(endpoint, (*tdata)->pool, (*tdata)->msg->line.req.uri);
4470 
4471  /* If an outbound proxy is specified on the endpoint apply it to this request */
4472  if (endpoint && !ast_strlen_zero(endpoint->outbound_proxy) &&
4473  ast_sip_set_outbound_proxy((*tdata), endpoint->outbound_proxy)) {
4474  ast_log(LOG_ERROR, "Unable to apply outbound proxy on request %.*s to endpoint %s as outbound proxy URI '%s' is not valid\n",
4475  (int) pj_strlen(&method->name), pj_strbuf(&method->name), ast_sorcery_object_get_id(endpoint),
4476  endpoint->outbound_proxy);
4477  pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
4478  return -1;
4479  }
4480 
4481  ast_sip_mod_data_set((*tdata)->pool, (*tdata)->mod_data, supplement_module.id, MOD_DATA_CONTACT, ao2_bump(contact));
4482 
4483  /* We can release this pool since request creation copied all the necessary
4484  * data into the outbound request's pool
4485  */
4486  pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
4487  return 0;
4488 }
4489 
4490 int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg,
4491  struct ast_sip_endpoint *endpoint, const char *uri,
4492  struct ast_sip_contact *contact, pjsip_tx_data **tdata)
4493 {
4494  const pjsip_method *pmethod = get_pjsip_method(method);
4495 
4496  if (!pmethod) {
4497  ast_log(LOG_WARNING, "Unknown method '%s'. Cannot send request\n", method);
4498  return -1;
4499  }
4500 
4501  if (dlg) {
4502  return create_in_dialog_request(pmethod, dlg, tdata);
4503  } else {
4504  ast_assert(endpoint != NULL);
4505  return create_out_of_dialog_request(pmethod, endpoint, uri, contact, tdata);
4506  }
4507 }
4508 
4510 
4512 {
4513  struct ast_sip_supplement *iter;
4514  int inserted = 0;
4516 
4518  if (iter->priority > supplement->priority) {
4520  inserted = 1;
4521  break;
4522  }
4523  }
4525 
4526  if (!inserted) {
4527  AST_RWLIST_INSERT_TAIL(&supplements, supplement, next);
4528  }
4529 }
4530 
4532 {
4533  struct ast_sip_supplement *iter;
4535 
4537  if (supplement == iter) {
4539  break;
4540  }
4541  }
4543 }
4544 
4545 static int send_in_dialog_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg)
4546 {
4547  if (pjsip_dlg_send_request(dlg, tdata, -1, NULL) != PJ_SUCCESS) {
4548  ast_log(LOG_WARNING, "Unable to send in-dialog request.\n");
4549  return -1;
4550  }
4551  return 0;
4552 }
4553 
4554 static pj_bool_t does_method_match(const pj_str_t *message_method, const char *supplement_method)
4555 {
4556  pj_str_t method;
4557 
4558  if (ast_strlen_zero(supplement_method)) {
4559  return PJ_TRUE;
4560  }
4561 
4562  pj_cstr(&method, supplement_method);
4563 
4564  return pj_stristr(&method, message_method) ? PJ_TRUE : PJ_FALSE;
4565 }
4566 
4567 #define TIMER_INACTIVE 0
4568 #define TIMEOUT_TIMER2 5
4569 
4570 /*! \brief Structure to hold information about an outbound request */
4572  /*! The endpoint associated with this request */
4574  /*! Information to be provided to the callback upon receipt of a response */
4575  void *token;
4576  /*! The callback to be called upon receipt of a response */
4577  void (*callback)(void *token, pjsip_event *e);
4578  /*! Number of challenges received. */
4579  unsigned int challenge_count;
4580 };
4581 
4582 static void send_request_data_destroy(void *obj)
4583 {
4584  struct send_request_data *req_data = obj;
4585 
4586  ao2_cleanup(req_data->endpoint);
4587 }
4588 
4590  void *token, void (*callback)(void *token, pjsip_event *e))
4591 {
4592  struct send_request_data *req_data;
4593 
4594  req_data = ao2_alloc_options(sizeof(*req_data), send_request_data_destroy,
4596  if (!req_data) {
4597  return NULL;
4598  }
4599 
4600  req_data->endpoint = ao2_bump(endpoint);
4601  req_data->token = token;
4602  req_data->callback = callback;
4603 
4604  return req_data;
4605 }
4606 
4608  /*! Information to be provided to the callback upon receipt of a response */
4609  void *token;
4610  /*! The callback to be called upon receipt of a response */
4611  void (*callback)(void *token, pjsip_event *e);
4612  /*! Non-zero when the callback is called. */
4613  unsigned int cb_called;
4614  /*! Non-zero if endpt_send_request_cb() was called. */
4615  unsigned int send_cb_called;
4616  /*! Timeout timer. */
4617  pj_timer_entry *timeout_timer;
4618  /*! Original timeout. */
4619  pj_int32_t timeout;
4620  /*! The transmit data. */
4621  pjsip_tx_data *tdata;
4622 };
4623 
4624 /*! \internal This function gets called by pjsip when the transaction ends,
4625  * even if it timed out. The lock prevents a race condition if both the pjsip
4626  * transaction timer and our own timer expire simultaneously.
4627  */
4628 static void endpt_send_request_cb(void *token, pjsip_event *e)
4629 {
4630  struct send_request_wrapper *req_wrapper = token;
4631  unsigned int cb_called;
4632 
4633  /*
4634  * Needed because we cannot otherwise tell if this callback was
4635  * called when pjsip_endpt_send_request() returns error.
4636  */
4637  req_wrapper->send_cb_called = 1;
4638 
4639  if (e->body.tsx_state.type == PJSIP_EVENT_TIMER) {
4640  ast_debug(2, "%p: PJSIP tsx timer expired\n", req_wrapper);
4641 
4642  if (req_wrapper->timeout_timer
4643  && req_wrapper->timeout_timer->id != TIMEOUT_TIMER2) {
4644  ast_debug(3, "%p: Timeout already handled\n", req_wrapper);
4645  ao2_ref(req_wrapper, -1);
4646  return;
4647  }
4648  } else {
4649  ast_debug(2, "%p: PJSIP tsx response received\n", req_wrapper);
4650  }
4651 
4652  ao2_lock(req_wrapper);
4653 
4654  /* It's possible that our own timer was already processing while
4655  * we were waiting on the lock so check the timer id. If it's
4656  * still TIMER2 then we still need to process.
4657  */
4658  if (req_wrapper->timeout_timer
4659  && req_wrapper->timeout_timer->id == TIMEOUT_TIMER2) {
4660  int timers_cancelled = 0;
4661 
4662  ast_debug(3, "%p: Cancelling timer\n", req_wrapper);
4663 
4664  timers_cancelled = pj_timer_heap_cancel_if_active(
4665  pjsip_endpt_get_timer_heap(ast_sip_get_pjsip_endpoint()),
4666  req_wrapper->timeout_timer, TIMER_INACTIVE);
4667  if (timers_cancelled > 0) {
4668  /* If the timer was cancelled the callback will never run so
4669  * clean up its reference to the wrapper.
4670  */
4671  ast_debug(3, "%p: Timer cancelled\n", req_wrapper);
4672  ao2_ref(req_wrapper, -1);
4673  } else {
4674  /*
4675  * If it wasn't cancelled, it MAY be in the callback already
4676  * waiting on the lock. When we release the lock, it will
4677  * now know not to proceed.
4678  */
4679  ast_debug(3, "%p: Timer already expired\n", req_wrapper);
4680  }
4681  }
4682 
4683  cb_called = req_wrapper->cb_called;
4684  req_wrapper->cb_called = 1;
4685  ao2_unlock(req_wrapper);
4686 
4687  /* It's possible that our own timer expired and called the callbacks
4688  * so no need to call them again.
4689  */
4690  if (!cb_called && req_wrapper->callback) {
4691  req_wrapper->callback(req_wrapper->token, e);
4692  ast_debug(2, "%p: Callbacks executed\n", req_wrapper);
4693  }
4694 
4695  ao2_ref(req_wrapper, -1);
4696 }
4697 
4698 /*! \internal This function gets called by our own timer when it expires.
4699  * If the timer is cancelled however, the function does NOT get called.
4700  * The lock prevents a race condition if both the pjsip transaction timer
4701  * and our own timer expire simultaneously.
4702  */
4703 static void send_request_timer_callback(pj_timer_heap_t *theap, pj_timer_entry *entry)
4704 {
4705  struct send_request_wrapper *req_wrapper = entry->user_data;
4706  unsigned int cb_called;
4707 
4708  ast_debug(2, "%p: Internal tsx timer expired after %d msec\n",
4709  req_wrapper, req_wrapper->timeout);
4710 
4711  ao2_lock(req_wrapper);
4712  /*
4713  * If the id is not TIMEOUT_TIMER2 then the timer was cancelled
4714  * before we got the lock or it was already handled so just clean up.
4715  */
4716  if (entry->id != TIMEOUT_TIMER2) {
4717  ao2_unlock(req_wrapper);
4718  ast_debug(3, "%p: Timeout already handled\n", req_wrapper);
4719  ao2_ref(req_wrapper, -1);
4720  return;
4721  }
4722  entry->id = TIMER_INACTIVE;
4723 
4724  ast_debug(3, "%p: Timer handled here\n", req_wrapper);
4725 
4726  cb_called = req_wrapper->cb_called;
4727  req_wrapper->cb_called = 1;
4728  ao2_unlock(req_wrapper);
4729 
4730  if (!cb_called && req_wrapper->callback) {
4731  pjsip_event event;
4732 
4733  PJSIP_EVENT_INIT_TX_MSG(event, req_wrapper->tdata);
4734  event.body.tsx_state.type = PJSIP_EVENT_TIMER;
4735 
4736  req_wrapper->callback(req_wrapper->token, &event);
4737  ast_debug(2, "%p: Callbacks executed\n", req_wrapper);
4738  }
4739 
4740  ao2_ref(req_wrapper, -1);
4741 }
4742 
4743 static void send_request_wrapper_destructor(void *obj)
4744 {
4745  struct send_request_wrapper *req_wrapper = obj;
4746 
4747  pjsip_tx_data_dec_ref(req_wrapper->tdata);
4748  ast_debug(2, "%p: wrapper destroyed\n", req_wrapper);
4749 }
4750 
4751 static pj_status_t endpt_send_request(struct ast_sip_endpoint *endpoint,
4752  pjsip_tx_data *tdata, pj_int32_t timeout, void *token, pjsip_endpt_send_callback cb)
4753 {
4754  struct send_request_wrapper *req_wrapper;
4755  pj_status_t ret_val;
4756  pjsip_endpoint *endpt = ast_sip_get_pjsip_endpoint();
4757 
4758  if (!cb && token) {
4759  /* Silly. Without a callback we cannot do anything with token. */
4760  pjsip_tx_data_dec_ref(tdata);
4761  return PJ_EINVAL;
4762  }
4763 
4764  /* Create wrapper to detect if the callback was actually called on an error. */
4765  req_wrapper = ao2_alloc(sizeof(*req_wrapper), send_request_wrapper_destructor);
4766  if (!req_wrapper) {
4767  pjsip_tx_data_dec_ref(tdata);
4768  return PJ_ENOMEM;
4769  }
4770 
4771  ast_debug(2, "%p: Wrapper created\n", req_wrapper);
4772 
4773  req_wrapper->token = token;
4774  req_wrapper->callback = cb;
4775  req_wrapper->timeout = timeout;
4776  req_wrapper->timeout_timer = NULL;
4777  req_wrapper->tdata = tdata;
4778  /* Add a reference to tdata. The wrapper destructor cleans it up. */
4779  pjsip_tx_data_add_ref(tdata);
4780 
4781  if (timeout > 0) {
4782  pj_time_val timeout_timer_val = { timeout / 1000, timeout % 1000 };
4783 
4784  req_wrapper->timeout_timer = PJ_POOL_ALLOC_T(tdata->pool, pj_timer_entry);
4785 
4786  ast_debug(2, "%p: Set timer to %d msec\n", req_wrapper, timeout);
4787 
4788  pj_timer_entry_init(req_wrapper->timeout_timer, TIMEOUT_TIMER2,
4789  req_wrapper, send_request_timer_callback);
4790 
4791  /* We need to insure that the wrapper and tdata are available if/when the
4792  * timer callback is executed.
4793  */
4794  ao2_ref(req_wrapper, +1);
4795  ret_val = pj_timer_heap_schedule(pjsip_endpt_get_timer_heap(endpt),
4796  req_wrapper->timeout_timer, &timeout_timer_val);
4797  if (ret_val != PJ_SUCCESS) {
4799  "Failed to set timer. Not sending %.*s request to endpoint %s.\n",
4800  (int) pj_strlen(&tdata->msg->line.req.method.name),
4801  pj_strbuf(&tdata->msg->line.req.method.name),
4802  endpoint ? ast_sorcery_object_get_id(endpoint) : "<unknown>");
4803  ao2_t_ref(req_wrapper, -2, "Drop timer and routine ref");
4804  pjsip_tx_data_dec_ref(tdata);
4805  return ret_val;
4806  }
4807  }
4808 
4809  /* We need to insure that the wrapper and tdata are available when the
4810  * transaction callback is executed.
4811  */
4812  ao2_ref(req_wrapper, +1);
4813  ret_val = pjsip_endpt_send_request(endpt, tdata, -1, req_wrapper, endpt_send_request_cb);
4814  if (ret_val != PJ_SUCCESS) {
4815  char errmsg[PJ_ERR_MSG_SIZE];
4816 
4817  if (!req_wrapper->send_cb_called) {
4818  /* endpt_send_request_cb is not expected to ever be called now. */
4819  ao2_ref(req_wrapper, -1);
4820  }
4821 
4822  /* Complain of failure to send the request. */
4823  pj_strerror(ret_val, errmsg, sizeof(errmsg));
4824  ast_log(LOG_ERROR, "Error %d '%s' sending %.*s request to endpoint %s\n",
4825  (int) ret_val, errmsg, (int) pj_strlen(&tdata->msg->line.req.method.name),
4826  pj_strbuf(&tdata->msg->line.req.method.name),
4827  endpoint ? ast_sorcery_object_get_id(endpoint) : "<unknown>");
4828 
4829  if (timeout > 0) {
4830  int timers_cancelled;
4831 
4832  ao2_lock(req_wrapper);
4833  timers_cancelled = pj_timer_heap_cancel_if_active(
4834  pjsip_endpt_get_timer_heap(endpt),
4835  req_wrapper->timeout_timer, TIMER_INACTIVE);
4836  if (timers_cancelled > 0) {
4837  ao2_ref(req_wrapper, -1);
4838  }
4839 
4840  /* Was the callback called? */
4841  if (req_wrapper->cb_called) {
4842  /*
4843  * Yes so we cannot report any error. The callback
4844  * has already freed any resources associated with
4845  * token.
4846  */
4847  ret_val = PJ_SUCCESS;
4848  } else {
4849  /*
4850  * No so we claim it is called so our caller can free
4851  * any resources associated with token because of
4852  * failure.
4853  */
4854  req_wrapper->cb_called = 1;
4855  }
4856  ao2_unlock(req_wrapper);
4857  } else if (req_wrapper->cb_called) {
4858  /*
4859  * We cannot report any error. The callback has
4860  * already freed any resources associated with
4861  * token.
4862  */
4863  ret_val = PJ_SUCCESS;
4864  }
4865  }
4866 
4867  ao2_ref(req_wrapper, -1);
4868  return ret_val;
4869 }
4870 
4871 int ast_sip_failover_request(pjsip_tx_data *tdata)
4872 {
4873  pjsip_via_hdr *via;
4874 
4875  if (!tdata || !tdata->dest_info.addr.count
4876  || (tdata->dest_info.cur_addr == tdata->dest_info.addr.count - 1)) {
4877  /* No more addresses to try */
4878  return 0;
4879  }
4880 
4881  /* Try next address */
4882  ++tdata->dest_info.cur_addr;
4883 
4884  via = (pjsip_via_hdr*)pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL);
4885  via->branch_param.slen = 0;
4886 
4887  pjsip_tx_data_invalidate_msg(tdata);
4888 
4889  return 1;
4890 }
4891 
4892 static void send_request_cb(void *token, pjsip_event *e);
4893 
4894 static int check_request_status(struct send_request_data *req_data, pjsip_event *e)
4895 {
4896  struct ast_sip_endpoint *endpoint;
4897  pjsip_transaction *tsx;
4898  pjsip_tx_data *tdata;
4899  int res = 0;
4900 
4901  if (!(endpoint = ao2_bump(req_data->endpoint))) {
4902  return 0;
4903  }
4904 
4905  tsx = e->body.tsx_state.tsx;
4906 
4907  switch (tsx->status_code) {
4908  case 401:
4909  case 407:
4910  /* Resend the request with a challenge response if we are challenged. */
4911  res = ++req_data->challenge_count < MAX_RX_CHALLENGES /* Not in a challenge loop */
4913  e->body.tsx_state.src.rdata, tsx->last_tx, &tdata);
4914  break;
4915  case 408:
4916  case 503:
4917  if ((res = ast_sip_failover_request(tsx->last_tx))) {
4918  tdata = tsx->last_tx;
4919  /*
4920  * Bump the ref since it will be on a new transaction and
4921  * we don't want it to go away along with the old transaction.
4922  */
4923  pjsip_tx_data_add_ref(tdata);
4924  }
4925  break;
4926  }
4927 
4928  if (res) {
4929  res = endpt_send_request(endpoint, tdata, -1,
4930  req_data, send_request_cb) == PJ_SUCCESS;
4931  }
4932 
4933  ao2_ref(endpoint, -1);
4934  return res;
4935 }
4936 
4937 static void send_request_cb(void *token, pjsip_event *e)
4938 {
4939  struct send_request_data *req_data = token;
4940  pjsip_rx_data *challenge;
4941  struct ast_sip_supplement *supplement;
4942 
4943  if (e->type == PJSIP_EVENT_TSX_STATE) {
4944  switch(e->body.tsx_state.type) {
4945  case PJSIP_EVENT_TRANSPORT_ERROR:
4946  case PJSIP_EVENT_TIMER:
4947  /*
4948  * Check the request status on transport error or timeout. A transport
4949  * error can occur when a TCP socket closes and that can be the result
4950  * of a 503. Also we may need to failover on a timeout (408).
4951  */
4952  if (check_request_status(req_data, e)) {
4953  return;
4954  }
4955  break;
4956  case PJSIP_EVENT_RX_MSG:
4957  challenge = e->body.tsx_state.src.rdata;
4958 
4959  /*
4960  * Call any supplements that want to know about a response
4961  * with any received data.
4962  */
4964  AST_LIST_TRAVERSE(&supplements, supplement, next) {
4965  if (supplement->incoming_response
4966  && does_method_match(&challenge->msg_info.cseq->method.name,
4967  supplement->method)) {
4968  supplement->incoming_response(req_data->endpoint, challenge);
4969  }
4970  }
4972 
4973  if (check_request_status(req_data, e)) {
4974  /*
4975  * Request with challenge response or failover sent.
4976  * Passed our req_data ref to the new request.
4977  */
4978  return;
4979  }
4980  break;
4981  default:
4982  ast_log(LOG_ERROR, "Unexpected PJSIP event %u\n", e->body.tsx_state.type);
4983  break;
4984  }
4985  }
4986 
4987  if (req_data->callback) {
4988  req_data->callback(req_data->token, e);
4989  }
4990  ao2_ref(req_data, -1);
4991 }
4992 
4993 int ast_sip_send_out_of_dialog_request(pjsip_tx_data *tdata,
4994  struct ast_sip_endpoint *endpoint, int timeout, void *token,
4995  void (*callback)(void *token, pjsip_event *e))
4996 {
4997  struct ast_sip_supplement *supplement;
4998  struct send_request_data *req_data;
4999  struct ast_sip_contact *contact;
5000 
5001  req_data = send_request_data_alloc(endpoint, token, callback);
5002  if (!req_data) {
5003  pjsip_tx_data_dec_ref(tdata);
5004  return -1;
5005  }
5006 
5007  if (endpoint) {
5008  ast_sip_message_apply_transport(endpoint->transport, tdata);
5009  }
5010 
5011  contact = ast_sip_mod_data_get(tdata->mod_data, supplement_module.id, MOD_DATA_CONTACT);
5012 
5014  AST_LIST_TRAVERSE(&supplements, supplement, next) {
5015  if (supplement->outgoing_request
5016  && does_method_match(&tdata->msg->line.req.method.name, supplement->method)) {
5017  supplement->outgoing_request(endpoint, contact, tdata);
5018  }
5019  }
5021 
5022  ast_sip_mod_data_set(tdata->pool, tdata->mod_data, supplement_module.id, MOD_DATA_CONTACT, NULL);
5023  ao2_cleanup(contact);
5024 
5025  if (endpt_send_request(endpoint, tdata, timeout, req_data, send_request_cb)
5026  != PJ_SUCCESS) {
5027  ao2_cleanup(req_data);
5028  return -1;
5029  }
5030 
5031  return 0;
5032 }
5033 
5034 int ast_sip_send_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg,
5035  struct ast_sip_endpoint *endpoint, void *token,
5036  void (*callback)(void *token, pjsip_event *e))
5037 {
5038  ast_assert(tdata->msg->type == PJSIP_REQUEST_MSG);
5039 
5040  if (dlg) {
5041  return send_in_dialog_request(tdata, dlg);
5042  } else {
5043  return ast_sip_send_out_of_dialog_request(tdata, endpoint, -1, token, callback);
5044  }
5045 }
5046 
5047 int ast_sip_set_outbound_proxy(pjsip_tx_data *tdata, const char *proxy)
5048 {
5049  pjsip_route_hdr *route;
5050  static const pj_str_t ROUTE_HNAME = { "Route", 5 };
5051  pj_str_t tmp;
5052 
5053  pj_strdup2_with_null(tdata->pool, &tmp, proxy);
5054  if (!(route = pjsip_parse_hdr(tdata->pool, &ROUTE_HNAME, tmp.ptr, tmp.slen, NULL))) {
5055  return -1;
5056  }
5057 
5058  pj_list_insert_nodes_before(&tdata->msg->hdr, (pjsip_hdr*)route);
5059 
5060  return 0;
5061 }
5062 
5063 int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value)
5064 {
5065  pj_str_t hdr_name;
5066  pj_str_t hdr_value;
5067  pjsip_generic_string_hdr *hdr;
5068 
5069  pj_cstr(&hdr_name, name);
5070  pj_cstr(&hdr_value, value);
5071 
5072  hdr = pjsip_generic_string_hdr_create(tdata->pool, &hdr_name, &hdr_value);
5073 
5074  pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) hdr);
5075  return 0;
5076 }
5077 
5078 static pjsip_msg_body *ast_body_to_pjsip_body(pj_pool_t *pool, const struct ast_sip_body *body)
5079 {
5080  pj_str_t type;
5081  pj_str_t subtype;
5082  pj_str_t body_text;
5083 
5084  pj_cstr(&type, body->type);
5085  pj_cstr(&subtype, body->subtype);
5086  pj_cstr(&body_text, body->body_text);
5087 
5088  return pjsip_msg_body_create(pool, &type, &subtype, &body_text);
5089 }
5090 
5091 int ast_sip_add_body(pjsip_tx_data *tdata, const struct ast_sip_body *body)
5092 {
5093  pjsip_msg_body *pjsip_body = ast_body_to_pjsip_body(tdata->pool, body);
5094  tdata->msg->body = pjsip_body;
5095  return 0;
5096 }
5097 
5098 int ast_sip_add_body_multipart(pjsip_tx_data *tdata, const struct ast_sip_body *bodies[], int num_bodies)
5099 {
5100  int i;
5101  /* NULL for type and subtype automatically creates "multipart/mixed" */
5102  pjsip_msg_body *body = pjsip_multipart_create(tdata->pool, NULL, NULL);
5103 
5104  for (i = 0; i < num_bodies; ++i) {
5105  pjsip_multipart_part *part = pjsip_multipart_create_part(tdata->pool);
5106  part->body = ast_body_to_pjsip_body(tdata->pool, bodies[i]);
5107  pjsip_multipart_add_part(tdata->pool, body, part);
5108  }
5109 
5110  tdata->msg->body = body;
5111  return 0;
5112 }
5113 
5114 int ast_sip_append_body(pjsip_tx_data *tdata, const char *body_text)
5115 {
5116  size_t combined_size = strlen(body_text) + tdata->msg->body->len;
5117  struct ast_str *body_buffer = ast_str_alloca(combined_size);
5118 
5119  ast_str_set(&body_buffer, 0, "%.*s%s", (int) tdata->msg->body->len, (char *) tdata->msg->body->data, body_text);
5120 
5121  tdata->msg->body->data = pj_pool_alloc(tdata->pool, combined_size);
5122  pj_memcpy(tdata->msg->body->data, ast_str_buffer(body_buffer), combined_size);
5123  tdata->msg->body->len = combined_size;
5124 
5125  return 0;
5126 }
5127 
5129 {
5130  return ast_threadpool_serializer_group(name, sip_threadpool, shutdown_group);
5131 }
5132 
5134 {
5135  return ast_sip_create_serializer_group(name, NULL);
5136 }
5137 
5138 int ast_sip_push_task(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)
5139 {
5140  if (!serializer) {
5141  serializer = ast_serializer_pool_get(sip_serializer_pool);
5142  }
5143 
5144  return ast_taskprocessor_push(serializer, sip_task, task_data);
5145 }
5146 
5147 struct sync_task_data {
5148  ast_mutex_t lock;
5149  ast_cond_t cond;
5150  int complete;
5151  int fail;
5152  int (*task)(void *);
5153  void *task_data;
5154 };
5155 
5156 static int sync_task(void *data)
5157 {
5158  struct sync_task_data *std = data;
5159  int ret;
5160 
5161  std->fail = std->task(std->task_data);
5162 
5163  /*
5164  * Once we unlock std->lock after signaling, we cannot access
5165  * std again. The thread waiting within ast_sip_push_task_wait()
5166  * is free to continue and release its local variable (std).
5167  */
5168  ast_mutex_lock(&std->lock);
5169  std->complete = 1;
5170  ast_cond_signal(&std->cond);
5171  ret = std->fail;
5172  ast_mutex_unlock(&std->lock);
5173  return ret;
5174 }
5175 
5176 static int ast_sip_push_task_wait(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)
5177 {
5178  /* This method is an onion */
5179  struct sync_task_data std;
5180 
5181  memset(&std, 0, sizeof(std));
5182  ast_mutex_init(&std.lock);
5183  ast_cond_init(&std.cond, NULL);
5184  std.task = sip_task;
5185  std.task_data = task_data;
5186 
5187  if (ast_sip_push_task(serializer, sync_task, &std)) {
5188  ast_mutex_destroy(&std.lock);
5189  ast_cond_destroy(&std.cond);
5190  return -1;
5191  }
5192 
5193  ast_mutex_lock(&std.lock);
5194  while (!std.complete) {
5195  ast_cond_wait(&std.cond, &std.lock);
5196  }
5197  ast_mutex_unlock(&std.lock);
5198 
5199  ast_mutex_destroy(&std.lock);
5200  ast_cond_destroy(&std.cond);
5201  return std.fail;
5202 }
5203 
5204 int ast_sip_push_task_wait_servant(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)
5205 {
5206  if (ast_sip_thread_is_servant()) {
5207  return sip_task(task_data);
5208  }
5209 
5210  return ast_sip_push_task_wait(serializer, sip_task, task_data);
5211 }
5212 
5213 int ast_sip_push_task_synchronous(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)
5214 {
5215  return ast_sip_push_task_wait_servant(serializer, sip_task, task_data);
5216 }
5217 
5218 int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int (*sip_task)(void *), void *task_data)
5219 {
5220  if (!serializer) {
5221  /* Caller doesn't care which PJSIP serializer the task executes under. */
5222  serializer = ast_serializer_pool_get(sip_serializer_pool);
5223  if (!serializer) {
5224  /* No serializer picked to execute the task */
5225  return -1;
5226  }
5227  }
5228  if (ast_taskprocessor_is_task(serializer)) {
5229  /*
5230  * We are the requested serializer so we must execute
5231  * the task now or deadlock waiting on ourself to
5232  * execute it.
5233  */
5234  return sip_task(task_data);
5235  }
5236 
5237  return ast_sip_push_task_wait(serializer, sip_task, task_data);
5238 }
5239 
5240 void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size)
5241 {
5242  size_t chars_to_copy = MIN(size - 1, pj_strlen(src));
5243  memcpy(dest, pj_strbuf(src), chars_to_copy);
5244  dest[chars_to_copy] = '\0';
5245 }
5246 
5247 int ast_copy_pj_str2(char **dest, const pj_str_t *src)
5248 {
5249  int res = ast_asprintf(dest, "%.*s", (int)pj_strlen(src), pj_strbuf(src));
5250 
5251  if (res < 0) {
5252  *dest = NULL;
5253  }
5254 
5255  return res;
5256 }
5257 
5258 
5259 int ast_sip_is_content_type(pjsip_media_type *content_type, char *type, char *subtype)
5260 {
5261  pjsip_media_type compare;
5262 
5263  if (!content_type) {
5264  return 0;
5265  }
5266 
5267  pjsip_media_type_init2(&compare, type, subtype);
5268 
5269  return pjsip_media_type_cmp(content_type, &compare, 0) ? 0 : -1;
5270 }
5271 
5272 pj_caching_pool caching_pool;
5273 pj_pool_t *memory_pool;
5274 pj_thread_t *monitor_thread;
5275 static int monitor_continue;
5276 
5277 static void *monitor_thread_exec(void *endpt)
5278 {
5279  while (monitor_continue) {
5280  const pj_time_val delay = {0, 10};
5281  pjsip_endpt_handle_events(ast_pjsip_endpoint, &delay);
5282  }
5283  return NULL;
5284 }
5285 
5286 static void stop_monitor_thread(void)
5287 {
5288  monitor_continue = 0;
5289  pj_thread_join(monitor_thread);
5290 }
5291 
5294 #define SIP_SERVANT_ID 0x5E2F1D
5295 
5296 static void sip_thread_start(void)
5297 {
5298  pj_thread_desc *desc;
5299  pj_thread_t *thread;
5300  uint32_t *servant_id;
5301 
5302  servant_id = ast_threadstorage_get(&servant_id_storage, sizeof(*servant_id));
5303  if (!servant_id) {
5304  ast_log(LOG_ERROR, "Could not set SIP servant ID in thread-local storage.\n");
5305  return;
5306  }
5307  *servant_id = SIP_SERVANT_ID;
5308 
5309  desc = ast_threadstorage_get(&pj_thread_storage, sizeof(pj_thread_desc));
5310  if (!desc) {
5311  ast_log(LOG_ERROR, "Could not get thread desc from thread-local storage. Expect awful things to occur\n");
5312  return;
5313  }
5314  pj_bzero(*desc, sizeof(*desc));
5315 
5316  if (pj_thread_register("Asterisk Thread", *desc, &thread) != PJ_SUCCESS) {
5317  ast_log(LOG_ERROR, "Couldn't register thread with PJLIB.\n");
5318  }
5319 }
5320 
5322 {
5323  uint32_t *servant_id;
5324 
5325  if (monitor_thread &&
5326  pthread_self() == *(pthread_t *)pj_thread_get_os_handle(monitor_thread)) {
5327  return 1;
5328  }
5329 
5330  servant_id = ast_threadstorage_get(&servant_id_storage, sizeof(*servant_id));
5331  if (!servant_id) {
5332  return 0;
5333  }
5334 
5335  return *servant_id == SIP_SERVANT_ID;
5336 }
5337 
5338 void *ast_sip_dict_get(void *ht, const char *key)
5339 {
5340  unsigned int hval = 0;
5341 
5342  if (!ht) {
5343  return NULL;
5344  }
5345 
5346  return pj_hash_get(ht, key, PJ_HASH_KEY_STRING, &hval);
5347 }
5348 
5349 void *ast_sip_dict_set(pj_pool_t* pool, void *ht,
5350  const char *key, void *val)
5351 {
5352  if (!ht) {
5353  ht = pj_hash_create(pool, 11);
5354  }
5355 
5356  pj_hash_set(pool, ht, key, PJ_HASH_KEY_STRING, 0, val);
5357 
5358  return ht;
5359 }
5360 
5361 static pj_bool_t supplement_on_rx_request(pjsip_rx_data *rdata)
5362 {
5363  struct ast_sip_supplement *supplement;
5364 
5365  if (pjsip_rdata_get_dlg(rdata)) {
5366  return PJ_FALSE;
5367  }
5368 
5370  AST_LIST_TRAVERSE(&supplements, supplement, next) {
5371  if (supplement->incoming_request
5372  && does_method_match(&rdata->msg_info.msg->line.req.method.name, supplement->method)) {
5373  struct ast_sip_endpoint *endpoint;
5374 
5375  endpoint = ast_pjsip_rdata_get_endpoint(rdata);
5376  supplement->incoming_request(endpoint, rdata);
5377  ao2_cleanup(endpoint);
5378  }
5379  }
5381 
5382  return PJ_FALSE;
5383 }
5384 
5385 static void supplement_outgoing_response(pjsip_tx_data *tdata, struct ast_sip_endpoint *sip_endpoint)
5386 {
5387  struct ast_sip_supplement *supplement;
5388  pjsip_cseq_hdr *cseq = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CSEQ, NULL);
5390 
5391  if (sip_endpoint) {
5392  ast_sip_message_apply_transport(sip_endpoint->transport, tdata);
5393  }
5394 
5396  AST_LIST_TRAVERSE(&supplements, supplement, next) {
5397  if (supplement->outgoing_response && does_method_match(&cseq->method.name, supplement->method)) {
5398  supplement->outgoing_response(sip_endpoint, contact, tdata);
5399  }
5400  }
5402 
5403  ast_sip_mod_data_set(tdata->pool, tdata->mod_data, supplement_module.id, MOD_DATA_CONTACT, NULL);
5404  ao2_cleanup(contact);
5405 }
5406 
5407 int ast_sip_send_response(pjsip_response_addr *res_addr, pjsip_tx_data *tdata, struct ast_sip_endpoint *sip_endpoint)
5408 {
5409  pj_status_t status;
5410 
5411  supplement_outgoing_response(tdata, sip_endpoint);
5412  status = pjsip_endpt_send_response(ast_sip_get_pjsip_endpoint(), res_addr, tdata, NULL, NULL);
5413  if (status != PJ_SUCCESS) {
5414  pjsip_tx_data_dec_ref(tdata);
5415  }
5416 
5417  return status == PJ_SUCCESS ? 0 : -1;
5418 }
5419 
5420 int ast_sip_send_stateful_response(pjsip_rx_data *rdata, pjsip_tx_data *tdata, struct ast_sip_endpoint *sip_endpoint)
5421 {
5422  pjsip_transaction *tsx;
5423 
5424  if (pjsip_tsx_create_uas(NULL, rdata, &tsx) != PJ_SUCCESS) {
5425  struct ast_sip_contact *contact;
5426 
5427  /* ast_sip_create_response bumps the refcount of the contact and adds it to the tdata.
5428  * We'll leak that reference if we don't get rid of it here.
5429  */
5430  contact = ast_sip_mod_data_get(tdata->mod_data, supplement_module.id, MOD_DATA_CONTACT);
5431  ao2_cleanup(contact);
5432  ast_sip_mod_data_set(tdata->pool, tdata->mod_data, supplement_module.id, MOD_DATA_CONTACT, NULL);
5433  pjsip_tx_data_dec_ref(tdata);
5434  return -1;
5435  }
5436  pjsip_tsx_recv_msg(tsx, rdata);
5437 
5438  supplement_outgoing_response(tdata, sip_endpoint);
5439 
5440  if (pjsip_tsx_send_msg(tsx, tdata) != PJ_SUCCESS) {
5441  pjsip_tx_data_dec_ref(tdata);
5442  return -1;
5443  }
5444 
5445  return 0;
5446 }
5447 
5448 int ast_sip_create_response(const pjsip_rx_data *rdata, int st_code,
5449  struct ast_sip_contact *contact, pjsip_tx_data **tdata)
5450 {
5451  int res = pjsip_endpt_create_response(ast_sip_get_pjsip_endpoint(), rdata, st_code, NULL, tdata);
5452 
5453  if (!res) {
5454  ast_sip_mod_data_set((*tdata)->pool, (*tdata)->mod_data, supplement_module.id, MOD_DATA_CONTACT, ao2_bump(contact));
5455  }
5456 
5457  return res;
5458 }
5459 
5460 int ast_sip_get_host_ip(int af, pj_sockaddr *addr)
5461 {
5462  if (af == pj_AF_INET() && !ast_strlen_zero(host_ip_ipv4_string)) {
5463  pj_sockaddr_copy_addr(addr, &host_ip_ipv4);
5464  return 0;
5465  } else if (af == pj_AF_INET6() && !ast_strlen_zero(host_ip_ipv6_string)) {
5466  pj_sockaddr_copy_addr(addr, &host_ip_ipv6);
5467  return 0;
5468  }
5469 
5470  return -1;
5471 }
5472 
5473 const char *ast_sip_get_host_ip_string(int af)
5474 {
5475  if (af == pj_AF_INET()) {
5476  return host_ip_ipv4_string;
5477  } else if (af == pj_AF_INET6()) {
5478  return host_ip_ipv6_string;
5479  }
5480 
5481  return NULL;
5482 }
5483 
5485  char *buf, size_t buf_len)
5486 {
5487  switch (dtmf) {
5488  case AST_SIP_DTMF_NONE:
5489  ast_copy_string(buf, "none", buf_len);
5490  break;
5491  case AST_SIP_DTMF_RFC_4733:
5492  ast_copy_string(buf, "rfc4733", buf_len);
5493  break;
5494  case AST_SIP_DTMF_INBAND:
5495  ast_copy_string(buf, "inband", buf_len);
5496  break;
5497  case AST_SIP_DTMF_INFO:
5498  ast_copy_string(buf, "info", buf_len);
5499  break;
5500  case AST_SIP_DTMF_AUTO:
5501  ast_copy_string(buf, "auto", buf_len);
5502  break;
5504  ast_copy_string(buf, "auto_info", buf_len);
5505  break;
5506  default:
5507  buf[0] = '\0';
5508  return -1;
5509  }
5510  return 0;
5511 }
5512 
5513 int ast_sip_str_to_dtmf(const char * dtmf_mode)
5514 {
5515  int result = -1;
5516 
5517  if (!strcasecmp(dtmf_mode, "info")) {
5518  result = AST_SIP_DTMF_INFO;
5519  } else if (!strcasecmp(dtmf_mode, "rfc4733")) {
5520  result = AST_SIP_DTMF_RFC_4733;
5521  } else if (!strcasecmp(dtmf_mode, "inband")) {
5522  result = AST_SIP_DTMF_INBAND;
5523  } else if (!strcasecmp(dtmf_mode, "none")) {
5524  result = AST_SIP_DTMF_NONE;
5525  } else if (!strcasecmp(dtmf_mode, "auto")) {
5526  result = AST_SIP_DTMF_AUTO;
5527  } else if (!strcasecmp(dtmf_mode, "auto_info")) {
5528  result = AST_SIP_DTMF_AUTO_INFO;
5529  }
5530 
5531  return result;
5532 }
5533 
5535 {
5536  const char *value;
5537 
5538  if (ast_sip_call_codec_pref_test(pref, LOCAL) && ast_sip_call_codec_pref_test(pref, INTERSECT) && ast_sip_call_codec_pref_test(pref, ALL)) {
5539  value = "local";
5540  } else if (ast_sip_call_codec_pref_test(pref, LOCAL) && ast_sip_call_codec_pref_test(pref, UNION) && ast_sip_call_codec_pref_test(pref, ALL)) {
5541  value = "local_merge";
5542  } else if (ast_sip_call_codec_pref_test(pref, LOCAL) && ast_sip_call_codec_pref_test(pref, INTERSECT) && ast_sip_call_codec_pref_test(pref, FIRST)) {
5543  value = "local_first";
5544  } else if (ast_sip_call_codec_pref_test(pref, REMOTE) && ast_sip_call_codec_pref_test(pref, INTERSECT) && ast_sip_call_codec_pref_test(pref, ALL)) {
5545  value = "remote";
5546  } else if (ast_sip_call_codec_pref_test(pref, REMOTE) && ast_sip_call_codec_pref_test(pref, UNION) && ast_sip_call_codec_pref_test(pref, ALL)) {
5547  value = "remote_merge";
5548  } else if (ast_sip_call_codec_pref_test(pref, REMOTE) && ast_sip_call_codec_pref_test(pref, UNION) && ast_sip_call_codec_pref_test(pref, FIRST)) {
5549  value = "remote_first";
5550  } else {
5551  value = "unknown";
5552  }
5553 
5554  return value;
5555 }
5556 
5557 int ast_sip_call_codec_str_to_pref(struct ast_flags *pref, const char *pref_str, int is_outgoing)
5558 {
5559  pref->flags = 0;
5560 
5561  if (strcmp(pref_str, "local") == 0) {
5563  } else if (is_outgoing && strcmp(pref_str, "local_merge") == 0) {
5565  } else if (strcmp(pref_str, "local_first") == 0) {
5567  } else if (strcmp(pref_str, "remote") == 0) {
5569  } else if (is_outgoing && strcmp(pref_str, "remote_merge") == 0) {
5571  } else if (strcmp(pref_str, "remote_first") == 0) {
5573  } else {
5574  return -1;
5575  }
5576 
5577  return 0;
5578 }
5579 
5580 /*!
5581  * \brief Set name and number information on an identity header.
5582  *
5583  * \param pool Memory pool to use for string duplication
5584  * \param id_hdr A From, P-Asserted-Identity, or Remote-Party-ID header to modify
5585  * \param id The identity information to apply to the header
5586  */
5587 void ast_sip_modify_id_header(pj_pool_t *pool, pjsip_fromto_hdr *id_hdr, const struct ast_party_id *id)
5588 {
5589  pjsip_name_addr *id_name_addr;
5590  pjsip_sip_uri *id_uri;
5591 
5592  id_name_addr = (pjsip_name_addr *) id_hdr->uri;
5593  id_uri = pjsip_uri_get_uri(id_name_addr->uri);
5594 
5595  if (id->name.valid) {
5596  if (!ast_strlen_zero(id->name.str)) {
5597  int name_buf_len = strlen(id->name.str) * 2 + 1;
5598  char *name_buf = ast_alloca(name_buf_len);
5599 
5600  ast_escape_quoted(id->name.str, name_buf, name_buf_len);
5601  pj_strdup2(pool, &id_name_addr->display, name_buf);
5602  } else {
5603  pj_strdup2(pool, &id_name_addr->display, NULL);
5604  }
5605  }
5606 
5607  if (id->number.valid) {
5608  pj_strdup2(pool, &id_uri->user, id->number.str);
5609  }
5610 }
5611 
5612 
5613 static void remove_request_headers(pjsip_endpoint *endpt)
5614 {
5615  const pjsip_hdr *request_headers = pjsip_endpt_get_request_headers(endpt);
5616  pjsip_hdr *iter = request_headers->next;
5617 
5618  while (iter != request_headers) {
5619  pjsip_hdr *to_erase = iter;
5620  iter = iter->next;
5621  pj_list_erase(to_erase);
5622  }
5623 }
5624 
5626 {
5627  return ast_threadpool_queue_size(sip_threadpool);
5628 }
5629 
5631 {
5632  return sip_threadpool;
5633 }
5634 
5635 #ifdef TEST_FRAMEWORK
5636 AST_TEST_DEFINE(xml_sanitization_end_null)
5637 {
5638  char sanitized[8];
5639 
5640  switch (cmd) {
5641  case TEST_INIT:
5642  info->name = "xml_sanitization_end_null";
5643  info->category = "/res/res_pjsip/";
5644  info->summary = "Ensure XML sanitization works as expected with a long string";
5645  info->description = "This test sanitizes a string which exceeds the output\n"
5646  "buffer size. Once done the string is confirmed to be NULL terminated.";
5647  return AST_TEST_NOT_RUN;
5648  case TEST_EXECUTE:
5649  break;
5650  }
5651 
5652  ast_sip_sanitize_xml("aaaaaaaaaaaa", sanitized, sizeof(sanitized));
5653  if (sanitized[7] != '\0') {
5654  ast_test_status_update(test, "Sanitized XML string is not null-terminated when it should be\n");
5655  return AST_TEST_FAIL;
5656  }
5657 
5658  return AST_TEST_PASS;
5659 }
5660 
5661 AST_TEST_DEFINE(xml_sanitization_exceeds_buffer)
5662 {
5663  char sanitized[8];
5664 
5665  switch (cmd) {
5666  case TEST_INIT:
5667  info->name = "xml_sanitization_exceeds_buffer";
5668  info->category = "/res/res_pjsip/";
5669  info->summary = "Ensure XML sanitization does not exceed buffer when output won't fit";
5670  info->description = "This test sanitizes a string which before sanitization would\n"
5671  "fit within the output buffer. After sanitization, however, the string would\n"
5672  "exceed the buffer. Once done the string is confirmed to be NULL terminated.";
5673  return AST_TEST_NOT_RUN;
5674  case TEST_EXECUTE:
5675  break;
5676  }
5677 
5678  ast_sip_sanitize_xml("<><><>&", sanitized, sizeof(sanitized));
5679  if (sanitized[7] != '\0') {
5680  ast_test_status_update(test, "Sanitized XML string is not null-terminated when it should be\n");
5681  return AST_TEST_FAIL;
5682  }
5683 
5684  return AST_TEST_PASS;
5685 }
5686 #endif
5687 
5688 /*!
5689  * \internal
5690  * \brief Reload configuration within a PJSIP thread
5691  */
5692 static int reload_configuration_task(void *obj)
5693 {
5697  return 0;
5698 }
5699 
5700 static int unload_pjsip(void *data)
5701 {
5702  /*
5703  * These calls need the pjsip endpoint and serializer to clean up.
5704  * If they're not set, then there's nothing to clean up anyway.
5705  */
5706  if (ast_pjsip_endpoint && sip_serializer_pool) {
5716  }
5717 
5718  if (monitor_thread) {
5720  monitor_thread = NULL;
5721  }
5722 
5723  if (memory_pool) {
5724  /* This mimics the behavior of pj_pool_safe_release
5725  * which was introduced in pjproject 2.6.
5726  */
5727  pj_pool_t *temp_pool = memory_pool;
5728 
5729  memory_pool = NULL;
5730  pj_pool_release(temp_pool);
5731  }
5732 
5734 
5735  if (caching_pool.lock) {
5736  ast_pjproject_caching_pool_destroy(&caching_pool);
5737  }
5738 
5739  pj_shutdown();
5740 
5741  return 0;
5742 }
5743 
5744 static int load_pjsip(void)
5745 {
5746  const unsigned int flags = 0; /* no port, no brackets */
5747  pj_status_t status;
5748 
5749  /* The third parameter is just copied from
5750  * example code from PJLIB. This can be adjusted
5751  * if necessary.
5752  */
5753  ast_pjproject_caching_pool_init(&caching_pool, NULL, 1024 * 1024);
5754  if (pjsip_endpt_create(&caching_pool.factory, "SIP", &ast_pjsip_endpoint) != PJ_SUCCESS) {
5755  ast_log(LOG_ERROR, "Failed to create PJSIP endpoint structure. Aborting load\n");
5756  goto error;
5757  }
5758 
5759  /* PJSIP will automatically try to add a Max-Forwards header. Since we want to control that,
5760  * we need to stop PJSIP from doing it automatically
5761  */
5763 
5764  memory_pool = pj_pool_create(&caching_pool.factory, "SIP", 1024, 1024, NULL);
5765  if (!memory_pool) {
5766  ast_log(LOG_ERROR, "Failed to create memory pool for SIP. Aborting load\n");
5767  goto error;
5768  }
5769 
5770  if (!pj_gethostip(pj_AF_INET(), &host_ip_ipv4)) {
5771  pj_sockaddr_print(&host_ip_ipv4, host_ip_ipv4_string, sizeof(host_ip_ipv4_string), flags);
5772  ast_verb(3, "Local IPv4 address determined to be: %s\n", host_ip_ipv4_string);
5773  }
5774 
5775  if (!pj_gethostip(pj_AF_INET6(), &host_ip_ipv6)) {
5776  pj_sockaddr_print(&host_ip_ipv6, host_ip_ipv6_string, sizeof(host_ip_ipv6_string), flags);
5777  ast_verb(3, "Local IPv6 address determined to be: %s\n", host_ip_ipv6_string);
5778  }
5779 
5780  pjsip_tsx_layer_init_module(ast_pjsip_endpoint);
5781  pjsip_ua_init_module(ast_pjsip_endpoint, NULL);
5782 
5783  monitor_continue = 1;
5784  status = pj_thread_create(memory_pool, "SIP", (pj_thread_proc *) &monitor_thread_exec,
5785  NULL, PJ_THREAD_DEFAULT_STACK_SIZE * 2, 0, &monitor_thread);
5786  if (status != PJ_SUCCESS) {
5787  ast_log(LOG_ERROR, "Failed to start SIP monitor thread. Aborting load\n");
5788  goto error;
5789  }
5790 
5791  return AST_MODULE_LOAD_SUCCESS;
5792 
5793 error:
5794  return AST_MODULE_LOAD_DECLINE;
5795 }
5796 
5797 /*
5798  * This is a place holder function to ensure that pjmedia_strerr() is at
5799  * least directly referenced by this module to ensure that the loader
5800  * linker will link to the function. If a module only indirectly
5801  * references a function from another module, such as a callback parameter
5802  * to a function, the loader linker has been known to miss the link.
5803  */
5804 void never_called_res_pjsip(void);
5806 {
5807  pjmedia_strerror(0, NULL, 0);
5808 }
5809 
5810 static int load_module(void)
5811 {
5812  struct ast_threadpool_options options;
5813 
5814  /* pjproject and config_system need to be initialized before all else */
5815  if (pj_init() != PJ_SUCCESS) {
5816  return AST_MODULE_LOAD_DECLINE;
5817  }
5818 
5819  if (pjlib_util_init() != PJ_SUCCESS) {
5820  goto error;
5821  }
5822 
5823  /* Register PJMEDIA error codes for SDP parsing errors */
5824  if (pj_register_strerror(PJMEDIA_ERRNO_START, PJ_ERRNO_SPACE_SIZE, pjmedia_strerror)
5825  != PJ_SUCCESS) {
5826  ast_log(LOG_WARNING, "Failed to register pjmedia error codes. Codes will not be decoded.\n");
5827  }
5828 
5829  if (ast_sip_initialize_system()) {
5830  ast_log(LOG_ERROR, "Failed to initialize SIP 'system' configuration section. Aborting load\n");
5831  goto error;
5832  }
5833 
5834  /* The serializer needs threadpool and threadpool needs pjproject to be initialized so it's next */
5835  sip_get_threadpool_options(&options);
5836  options.thread_start = sip_thread_start;
5837  sip_threadpool = ast_threadpool_create("pjsip", NULL, &options);
5838  if (!sip_threadpool) {
5839  goto error;
5840  }
5841 
5842  sip_serializer_pool = ast_serializer_pool_create(
5843  "pjsip/default", SERIALIZER_POOL_SIZE, sip_threadpool, -1);
5844  if (!sip_serializer_pool) {
5845  ast_log(LOG_ERROR, "Failed to create SIP serializer pool. Aborting load\n");
5846  goto error;
5847  }
5848 
5850  ast_log(LOG_ERROR, "Failed to start scheduler. Aborting load\n");
5851  goto error;
5852  }
5853 
5854  /* Now load all the pjproject infrastructure. */
5855  if (load_pjsip()) {
5856  goto error;
5857  }
5858 
5860  ast_log(LOG_ERROR, "Failed to initialize SIP transport monitor. Aborting load\n");
5861  goto error;
5862  }
5863 
5866 
5868  ast_log(LOG_ERROR, "Failed to pre-initialize OPTIONS handling. Aborting load\n");
5869  goto error;
5870  }
5871 
5873  ast_log(LOG_ERROR, "Failed to initialize SIP configuration. Aborting load\n");
5874  goto error;
5875  }
5876 
5879 
5881  ast_log(LOG_ERROR, "Failed to initialize SIP transport management. Aborting load\n");
5882  goto error;
5883  }
5884 
5886  ast_log(LOG_ERROR, "Failed to register distributor module. Aborting load\n");
5887  goto error;
5888  }
5889 
5891  ast_log(LOG_ERROR, "Failed to initialize supplement hooks. Aborting load\n");
5892  goto error;
5893  }
5894 
5896  ast_log(LOG_ERROR, "Failed to initialize OPTIONS handling. Aborting load\n");
5897  goto