Asterisk - The Open Source Telephony Project GIT-master-35be64c
Loading...
Searching...
No Matches
res_pjsip_outbound_registration.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 * Joshua Colp <jcolp@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*** MODULEINFO
20 <depend>pjproject</depend>
21 <depend>res_pjsip</depend>
22 <use type="module">res_statsd</use>
23 <support_level>core</support_level>
24 ***/
25
26#include "asterisk.h"
27
28#include <pjsip.h>
29#include <pjsip_ua.h>
30
31#include "asterisk/res_pjsip.h"
33#include "asterisk/module.h"
35#include "asterisk/cli.h"
38#include "asterisk/taskpool.h"
40#include "asterisk/statsd.h"
42#include "asterisk/vector.h"
43#include "asterisk/pbx.h"
44
45/*** DOCUMENTATION
46 <configInfo name="res_pjsip_outbound_registration" language="en_US">
47 <synopsis>SIP resource for outbound registrations</synopsis>
48 <description><para>
49 <emphasis>Outbound Registration</emphasis>
50 </para>
51 <para>This module allows <literal>res_pjsip</literal> to register to other SIP servers.</para>
52 </description>
53 <configFile name="pjsip.conf">
54 <configObject name="registration">
55 <since>
56 <version>12.0.0</version>
57 </since>
58 <synopsis>The configuration for outbound registration</synopsis>
59 <description><para>
60 Registration is <emphasis>COMPLETELY</emphasis> separate from the rest of
61 <literal>pjsip.conf</literal>. A minimal configuration consists of
62 setting a <literal>server_uri</literal> and a <literal>client_uri</literal>.
63 </para></description>
64 <configOption name="auth_rejection_permanent" default="yes">
65 <since>
66 <version>12.0.0</version>
67 </since>
68 <synopsis>Determines whether failed authentication challenges are treated
69 as permanent failures.</synopsis>
70 <description><para>If this option is enabled and an authentication challenge fails,
71 registration will not be attempted again until the configuration is reloaded.</para></description>
72 </configOption>
73 <configOption name="client_uri">
74 <since>
75 <version>12.0.0</version>
76 </since>
77 <synopsis>Client SIP URI used when attemping outbound registration</synopsis>
78 <description><para>
79 This is the address-of-record for the outbound registration (i.e. the URI in
80 the To header of the REGISTER).</para>
81 <para>For registration with an ITSP, the client SIP URI may need to consist of
82 an account name or number and the provider's hostname for their registrar, e.g.
83 client_uri=1234567890@example.com. This may differ between providers.</para>
84 <para>For registration to generic registrars, the client SIP URI will depend
85 on networking specifics and configuration of the registrar.
86 </para></description>
87 </configOption>
88 <configOption name="contact_user" default="s">
89 <since>
90 <version>12.0.0</version>
91 </since>
92 <synopsis>Contact User to use in request. If this value is not set, this defaults to 's'</synopsis>
93 </configOption>
94 <configOption name="contact_header_params">
95 <since>
96 <version>17.0.0</version>
97 </since>
98 <synopsis>Header parameters to place in the Contact header</synopsis>
99 </configOption>
100 <configOption name="expiration" default="3600">
101 <since>
102 <version>12.0.0</version>
103 </since>
104 <synopsis>Expiration time for registrations in seconds</synopsis>
105 </configOption>
106 <configOption name="max_retries" default="10">
107 <since>
108 <version>12.0.0</version>
109 </since>
110 <synopsis>Maximum number of registration attempts.</synopsis>
111 <description><para>
112 This sets the maximum number of registration attempts that are made before
113 stopping any further attempts. If set to 0 then upon failure no further attempts
114 are made.
115 </para></description>
116 </configOption>
117 <configOption name="security_negotiation" default="no">
118 <since>
119 <version>21.0.0</version>
120 </since>
121 <synopsis>The kind of security agreement negotiation to use. Currently, only mediasec is supported.</synopsis>
122 <description>
123 <enumlist>
124 <enum name="no" />
125 <enum name="mediasec" />
126 </enumlist>
127 </description>
128 </configOption>
129 <configOption name="security_mechanisms">
130 <since>
131 <version>21.0.0</version>
132 </since>
133 <synopsis>List of security mechanisms supported.</synopsis>
134 <description><para>
135 This is a comma-delimited list of security mechanisms to use. Each security mechanism
136 must be in the form defined by RFC 3329 section 2.2.
137 </para></description>
138 </configOption>
139 <configOption name="outbound_auth" default="">
140 <since>
141 <version>12.2.0</version>
142 </since>
143 <synopsis>Authentication object(s) to be used for outbound registrations.</synopsis>
144 <description><para>
145 This is a comma-delimited list of <replaceable>auth</replaceable>
146 sections defined in <filename>pjsip.conf</filename> used to respond
147 to outbound authentication challenges.</para>
148 <note><para>
149 Using the same auth section for inbound and outbound
150 authentication is not recommended. There is a difference in
151 meaning for an empty realm setting between inbound and outbound
152 authentication uses. See the auth realm description for details.
153 </para></note>
154 </description>
155 </configOption>
156 <configOption name="outbound_proxy" default="">
157 <since>
158 <version>12.0.0</version>
159 </since>
160 <synopsis>Full SIP URI of the outbound proxy used to send registrations</synopsis>
161 </configOption>
162 <configOption name="max_random_initial_delay" default="10">
163 <since>
164 <version>16.27.0</version>
165 <version>18.13.0</version>
166 <version>19.5.0</version>
167 </since>
168 <synopsis>Maximum interval in seconds for which an initial registration may be randomly delayed</synopsis>
169 <description>
170 <para>By default, registrations are randomly delayed by a small amount to prevent
171 too many registrations from being made simultaneously.</para>
172 <para>Depending on your system usage, it may be desirable to set this to a smaller
173 or larger value to have fine grained control over the size of this random delay.</para>
174 </description>
175 </configOption>
176 <configOption name="retry_interval" default="60">
177 <since>
178 <version>12.0.0</version>
179 </since>
180 <synopsis>Interval in seconds between retries if outbound registration is unsuccessful</synopsis>
181 </configOption>
182 <configOption name="forbidden_retry_interval" default="0">
183 <since>
184 <version>11.7.0</version>
185 </since>
186 <synopsis>Interval used when receiving a 403 Forbidden response.</synopsis>
187 <description><para>
188 If a 403 Forbidden is received, chan_pjsip will wait
189 <replaceable>forbidden_retry_interval</replaceable> seconds before
190 attempting registration again. If 0 is specified, chan_pjsip will not
191 retry after receiving a 403 Forbidden response. Setting this to a non-zero
192 value goes against a "SHOULD NOT" in RFC3261, but can be used to work around
193 buggy registrars.
194 </para></description>
195 </configOption>
196 <configOption name="fatal_retry_interval" default="0">
197 <since>
198 <version>13.7.0</version>
199 </since>
200 <synopsis>Interval used when receiving a Fatal response.</synopsis>
201 <description><para>
202 If a fatal response is received, chan_pjsip will wait
203 <replaceable>fatal_retry_interval</replaceable> seconds before
204 attempting registration again. If 0 is specified, chan_pjsip will not
205 retry after receiving a fatal (non-temporary 4xx, 5xx, 6xx) response.
206 Setting this to a non-zero value may go against a "SHOULD NOT" in RFC3261,
207 but can be used to work around buggy registrars.</para>
208 <note><para>if also set the <replaceable>forbidden_retry_interval</replaceable>
209 takes precedence over this one when a 403 is received.
210 Also, if <replaceable>auth_rejection_permanent</replaceable> equals 'yes' then
211 a 401 and 407 become subject to this retry interval.</para></note>
212 </description>
213 </configOption>
214 <configOption name="server_uri">
215 <since>
216 <version>12.0.0</version>
217 </since>
218 <synopsis>SIP URI of the server to register against</synopsis>
219 <description><para>
220 This is the URI at which to find the registrar to send the outbound REGISTER. This URI
221 is used as the request URI of the outbound REGISTER request from Asterisk.</para>
222 <para>For registration with an ITSP, the setting may often be just the domain of
223 the registrar, e.g. sip:sip.example.com.
224 </para></description>
225 </configOption>
226 <configOption name="transport">
227 <since>
228 <version>12.0.0</version>
229 </since>
230 <synopsis>Transport used for outbound authentication</synopsis>
231 <description>
232 <note><para>A <replaceable>transport</replaceable> configured in
233 <literal>pjsip.conf</literal>. As with other <literal>res_pjsip</literal> modules, this will use the first available transport of the appropriate type if unconfigured.</para></note>
234 </description>
235 </configOption>
236 <configOption name="line">
237 <since>
238 <version>13.4.0</version>
239 </since>
240 <synopsis>Whether to add a 'line' parameter to the Contact for inbound call matching</synopsis>
241 <description><para>
242 When enabled this option will cause a 'line' parameter to be added to the Contact
243 header placed into the outgoing registration request. If the remote server sends a call
244 this line parameter will be used to establish a relationship to the outbound registration,
245 ultimately causing the configured endpoint to be used.
246 </para></description>
247 </configOption>
248 <configOption name="endpoint">
249 <since>
250 <version>13.4.0</version>
251 </since>
252 <synopsis>Endpoint to use for incoming related calls</synopsis>
253 <description><para>
254 When line support is enabled this configured endpoint name is used for incoming calls
255 that are related to the outbound registration.
256 </para></description>
257 </configOption>
258 <configOption name="type">
259 <since>
260 <version>12.0.0</version>
261 </since>
262 <synopsis>Must be of type 'registration'.</synopsis>
263 </configOption>
264 <configOption name="support_path">
265 <since>
266 <version>12.1.0</version>
267 </since>
268 <synopsis>Enables advertising SIP Path support for outbound REGISTER requests.</synopsis>
269 <description><para>
270 When this option is enabled, outbound REGISTER requests will advertise
271 support for Path headers so that intervening proxies can add to the Path
272 header as necessary.
273 </para></description>
274 </configOption>
275 <configOption name="support_outbound">
276 <since>
277 <version>17.0.0</version>
278 </since>
279 <synopsis>Enables advertising SIP Outbound support (RFC5626) for outbound REGISTER requests.</synopsis>
280 </configOption>
281 <configOption name="user_agent">
282 <since>
283 <version>21.2.0</version>
284 </since>
285 <synopsis>Overrides the User-Agent header that should be used for outbound REGISTER requests.</synopsis>
286 </configOption>
287 </configObject>
288 </configFile>
289 </configInfo>
290 <manager name="PJSIPUnregister" language="en_US">
291 <since>
292 <version>12.0.0</version>
293 </since>
294 <synopsis>
295 Unregister an outbound registration.
296 </synopsis>
297 <syntax>
298 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
299 <parameter name="Registration" required="true">
300 <para>The outbound registration to unregister or '*all' to unregister them all.</para>
301 </parameter>
302 </syntax>
303 <description>
304 <para>
305 Unregisters the specified (or all) outbound registration(s) and stops future registration attempts.
306 Call PJSIPRegister to start registration and schedule re-registrations according to configuration.
307 </para>
308 </description>
309 </manager>
310 <manager name="PJSIPRegister" language="en_US">
311 <since>
312 <version>13.2.0</version>
313 </since>
314 <synopsis>
315 Register an outbound registration.
316 </synopsis>
317 <syntax>
318 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
319 <parameter name="Registration" required="true">
320 <para>The outbound registration to register or '*all' to register them all.</para>
321 </parameter>
322 </syntax>
323 <description>
324 <para>
325 Unregisters the specified (or all) outbound registration(s) then starts registration and schedules re-registrations
326 according to configuration.
327 </para>
328 </description>
329 </manager>
330 <manager name="PJSIPShowRegistrationsOutbound" language="en_US">
331 <since>
332 <version>12.0.0</version>
333 </since>
334 <synopsis>
335 Lists PJSIP outbound registrations.
336 </synopsis>
337 <syntax />
338 <description>
339 <para>
340 In response <literal>OutboundRegistrationDetail</literal> events showing configuration and status
341 information are raised for each outbound registration object. <literal>AuthDetail</literal>
342 events are raised for each associated auth object as well. Once all events are completed an
343 <literal>OutboundRegistrationDetailComplete</literal> is issued.
344 </para>
345 </description>
346 </manager>
347 <managerEvent language="en_US" name="OutboundRegistrationDetail">
348 <managerEventInstance class="EVENT_FLAG_COMMAND">
349 <since>
350 <version>12.0.0</version>
351 </since>
352 <synopsis>
353 Provides configuration details and status information about an
354 outbound registration.
355 </synopsis>
356 <syntax>
357 <parameter name="ObjectType">
358 <para>The object's type. This will always be 'registration'.</para>
359 </parameter>
360 <parameter name="ObjectName">
361 <para>The name of this object.</para>
362 </parameter>
363 <parameter name="MaxRetries">
364 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='max_retries']/synopsis/node())"/></para>
365 </parameter>
366 <parameter name="ClientUri">
367 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='client_uri']/synopsis/node())"/></para>
368 </parameter>
369 <parameter name="SecurityNegotiation">
370 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='security_negotiation']/synopsis/node())"/></para>
371 </parameter>
372 <parameter name="AuthRejectionPermanent">
373 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='auth_rejection_permanent']/synopsis/node())"/></para>
374 </parameter>
375 <parameter name="ServerUri">
376 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='server_uri']/synopsis/node())"/></para>
377 </parameter>
378 <parameter name="MaxRandomInitialDelay">
379 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='max_random_initial_delay']/synopsis/node())"/></para>
380 </parameter>
381 <parameter name="SupportPath">
382 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='support_path']/synopsis/node())"/></para>
383 </parameter>
384 <parameter name="RetryInterval">
385 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='retry_interval']/synopsis/node())"/></para>
386 </parameter>
387 <parameter name="ContactHeaderParams">
388 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='contact_header_params']/synopsis/node())"/></para>
389 </parameter>
390 <parameter name="Expiration">
391 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='expiration']/synopsis/node())"/></para>
392 </parameter>
393 <parameter name="Transport">
394 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='transport']/synopsis/node())"/></para>
395 </parameter>
396 <parameter name="Line">
397 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='line']/synopsis/node())"/></para>
398 </parameter>
399 <parameter name="ContactUser">
400 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='contact_user']/synopsis/node())"/></para>
401 </parameter>
402 <parameter name="Endpoint">
403 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='endpoint']/synopsis/node())"/></para>
404 </parameter>
405 <parameter name="UserAgent">
406 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='user_agent']/synopsis/node())"/></para>
407 </parameter>
408 <parameter name="ForbiddenRetryInterval">
409 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='forbidden_retry_interval']/synopsis/node())"/></para>
410 </parameter>
411 <parameter name="OutboundAuth">
412 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='outbound_auth']/synopsis/node())"/></para>
413 </parameter>
414 <parameter name="OutboundProxy">
415 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='outbound_proxy']/synopsis/node())"/></para>
416 </parameter>
417 <parameter name="FatalRetryInterval">
418 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='fatal_retry_interval']/synopsis/node())"/></para>
419 </parameter>
420 <parameter name="SupportOutbound">
421 <para><xi:include xpointer="xpointer(/docs/configInfo[@name='res_pjsip_outbound_registration']/configFile[@name='pjsip.conf']/configObject[@name='registration']/configOption[@name='support_outbound']/synopsis/node())"/></para>
422 </parameter>
423 <parameter name="Status">
424 <para>The current status of this registration. Will be one of:</para>
425 <enumlist>
426 <enum name="Registered"/>
427 <enum name="Unregistered"/>
428 <enum name="Rejected"/>
429 </enumlist>
430 </parameter>
431 <parameter name="NextReg">
432 <para>The number of seconds until the next registration.</para>
433 </parameter>
434 </syntax>
435 </managerEventInstance>
436 </managerEvent>
437 ***/
438
439/* forward declarations */
440static int set_outbound_initial_authentication_credentials(pjsip_regc *regc,
441 const struct ast_sip_auth_vector *auth_vector);
442
443/*! \brief Some thread local storage used to determine if the running thread invoked the callback */
444AST_THREADSTORAGE(register_callback_invoked);
445
446/*! \brief Amount of buffer time (in seconds) before expiration that we re-register at */
447#define REREGISTER_BUFFER_TIME 10
448
449/*! \brief Size of the buffer for creating a unique string for the line */
450#define LINE_PARAMETER_SIZE 8
451
452/*! \brief Various states that an outbound registration may be in */
454 /*! \brief Currently unregistered */
456 /*! \brief Registered, yay! */
458 /*! \brief Registration was rejected, but response was temporal */
460 /*! \brief Registration was rejected, permanently */
462 /*! \brief Registration is stopping. */
464 /*! \brief Registration has been stopped */
466};
467
468/*!
469 * \internal
470 * \brief Convert the internal registration state to an external status string.
471 * \since 13.5.0
472 *
473 * \param state Current outbound registration state.
474 *
475 * \return External registration status string.
476 */
478{
479 const char *str;
480
481 str = "Unregistered";
482 switch (state) {
486 break;
488 str = "Registered";
489 break;
492 str = "Rejected";
493 break;
494 }
495 return str;
496}
497
498/*! \brief Outbound registration information */
500 /*! \brief Sorcery object details */
502 /*! \brief Stringfields */
504 /*! \brief URI for the registrar */
506 /*! \brief URI for the AOR */
508 /*! \brief Optional user for contact header */
510 /*! \brief Optional header parameters for contact */
512 /*! \brief Explicit transport to use for registration */
514 /*! \brief Outbound proxy to use */
516 /*! \brief Endpoint to use for related incoming calls */
518 /*! \brief User-Agent to use when sending the REGISTER */
520 );
521 /*! \brief Requested expiration time */
522 unsigned int expiration;
523 /*! \brief Maximum random initial delay interval for initial registrations */
525 /*! \brief Interval at which retries should occur for temporal responses */
526 unsigned int retry_interval;
527 /*! \brief Interval at which retries should occur for permanent responses */
529 /*! \brief Interval at which retries should occur for all permanent responses */
531 /*! \brief Treat authentication challenges that we cannot handle as permanent failures */
533 /*! \brief Maximum number of retries permitted */
534 unsigned int max_retries;
535 /*! \brief Whether to add a line parameter to the outbound Contact or not */
536 unsigned int line;
537 /*! \brief Type of security negotiation to use (RFC 3329). */
539 /*! \brief Client security mechanisms (RFC 3329). */
541 /*! \brief Configured authentication credentials */
543 /*! \brief Whether Path support is enabled */
544 unsigned int support_path;
545 /*! \brief Whether Outbound support is enabled */
546 unsigned int support_outbound;
547};
548
549/*! \brief Outbound registration client state information (persists for lifetime of regc) */
551 /*! \brief Current state of this registration */
553 /*!
554 * \brief Outbound registration client
555 * \note May only be accessed within the serializer thread
556 * because it might get destroyed and set to NULL for
557 * module unload.
558 */
559 pjsip_regc *client;
560 /*!
561 * \brief Last tdata sent
562 * We need the original tdata to resend a request on auth failure
563 * or timeout. On an auth failure, we use the original tdata
564 * to initialize the new tdata for the authorized response. On a timeout
565 * we need it to skip failed SRV entries if any.
566 */
567 pjsip_tx_data *last_tdata;
568 /*! \brief Timer entry for retrying on temporal responses */
569 pj_timer_entry timer;
570 /*! \brief Optional line parameter placed into Contact */
572 /*! \brief Current number of retries */
573 unsigned int retries;
574 /*! \brief Maximum number of retries permitted */
575 unsigned int max_retries;
576 /*! \brief Interval at which retries should occur for temporal responses */
577 unsigned int retry_interval;
578 /*! \brief Interval at which retries should occur for permanent responses */
580 /*! \brief Interval at which retries should occur for all permanent responses */
582 /*! \brief Treat authentication challenges that we cannot handle as permanent failures */
584 /*! \brief Determines whether SIP Path support should be advertised */
585 unsigned int support_path;
586 /*! \brief Determines whether SIP Outbound support should be advertised */
587 unsigned int support_outbound;
588 /*! \brief Type of security negotiation to use (RFC 3329). */
590 /*! \brief Client security mechanisms (RFC 3329). */
592 /*! \brief Security mechanisms of the peer (RFC 3329). */
594 /*! CSeq number of last sent auth request. */
595 unsigned int auth_cseq;
596 /*! \brief Serializer for stuff and things */
598 /*! \brief Configured authentication credentials */
600 /*! \brief Registration should be destroyed after completion of transaction */
601 unsigned int destroy:1;
602 /*! \brief Non-zero if we have attempted sending a REGISTER with authentication */
603 unsigned int auth_attempted:1;
604 /*! \brief Status code of last response if we have tried to register before */
606 /*! \brief The name of the transport to be used for the registration */
608 /*! \brief The name of the registration sorcery object */
610 /*! \brief Expected time of registration lapse/expiration */
612 /*! \brief The value for the User-Agent header sent in requests */
614};
615
616/*! \brief Outbound registration state information (persists for lifetime that registration should exist) */
618 /*! \brief Outbound registration configuration object */
620 /*! \brief Client state information */
622};
623
624/*! Time needs to be long enough for a transaction to timeout if nothing replies. */
625#define MAX_UNLOAD_TIMEOUT_TIME 35 /* Seconds */
626
627/*! Shutdown group to monitor sip_outbound_registration_client_state serializers. */
629
630/*! \brief Default number of state container buckets */
631#define DEFAULT_STATE_BUCKETS 53
632static AO2_GLOBAL_OBJ_STATIC(current_states);
633
634/*! subscription id for network change events */
636
637/*! \brief hashing function for state objects */
638static int registration_state_hash(const void *obj, const int flags)
639{
640 const struct sip_outbound_registration_state *object;
641 const char *key;
642
643 switch (flags & OBJ_SEARCH_MASK) {
644 case OBJ_SEARCH_KEY:
645 key = obj;
646 break;
648 object = obj;
650 break;
651 default:
652 ast_assert(0);
653 return 0;
654 }
655 return ast_str_hash(key);
656}
657
658/*! \brief comparator function for state objects */
659static int registration_state_cmp(void *obj, void *arg, int flags)
660{
661 const struct sip_outbound_registration_state *object_left = obj;
662 const struct sip_outbound_registration_state *object_right = arg;
663 const char *right_key = arg;
664 int cmp;
665
666 switch (flags & OBJ_SEARCH_MASK) {
668 right_key = ast_sorcery_object_get_id(object_right->registration);
669 /* Fall through */
670 case OBJ_SEARCH_KEY:
671 cmp = strcmp(ast_sorcery_object_get_id(object_left->registration), right_key);
672 break;
674 /* Not supported by container. */
675 ast_assert(0);
676 return 0;
677 default:
678 cmp = 0;
679 break;
680 }
681 if (cmp) {
682 return 0;
683 }
684 return CMP_MATCH;
685}
686
687static struct sip_outbound_registration_state *get_state(const char *id)
688{
690 struct ao2_container *states;
691
692 states = ao2_global_obj_ref(current_states);
693 if (states) {
694 state = ao2_find(states, id, OBJ_SEARCH_KEY);
695 ao2_ref(states, -1);
696 }
697 return state;
698}
699
708
709/*! \brief Callback function for matching an outbound registration based on line */
710static int line_identify_relationship(void *obj, void *arg, int flags)
711{
713 pjsip_param *line = arg;
714
715 return !pj_strcmp2(&line->value, state->client_state->line) ? CMP_MATCH : 0;
716}
717
718static struct pjsip_param *get_uri_option_line(const void *uri)
719{
720 static const pj_str_t LINE_STR = { "line", 4 };
721
722 return ast_sip_pjsip_uri_get_other_param((pjsip_uri *)uri, &LINE_STR);
723}
724
725/*! \brief Endpoint identifier which uses the 'line' parameter to establish a relationship to an outgoing registration */
726static struct ast_sip_endpoint *line_identify(pjsip_rx_data *rdata)
727{
728 pjsip_param *line;
729 RAII_VAR(struct ao2_container *, states, NULL, ao2_cleanup);
731
732 if (!(line = get_uri_option_line(rdata->msg_info.to->uri))
733 && !(line = get_uri_option_line(rdata->msg_info.msg->line.req.uri))) {
734 return NULL;
735 }
736
737 states = ao2_global_obj_ref(current_states);
738 if (!states) {
739 return NULL;
740 }
741
743 if (!state || ast_strlen_zero(state->registration->endpoint)) {
744 return NULL;
745 }
746
747 ast_debug(3, "Determined relationship to outbound registration '%s' based on line '%s', using configured endpoint '%s'\n",
748 ast_sorcery_object_get_id(state->registration), state->client_state->line, state->registration->endpoint);
749
750 return ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", state->registration->endpoint);
751}
752
756
757/*! \brief Helper function which cancels the timer on a client */
759{
760 if (pj_timer_heap_cancel_if_active(pjsip_endpt_get_timer_heap(ast_sip_get_pjsip_endpoint()),
761 &client_state->timer, client_state->timer.id)) {
762 /* The timer was successfully cancelled, drop the refcount of client_state */
763 ao2_ref(client_state, -1);
764 }
765}
766
767static pj_str_t PATH_NAME = { "path", 4 };
768static pj_str_t OUTBOUND_NAME = { "outbound", 8 };
769
770AST_VECTOR(pjsip_generic_string_hdr_vector, pjsip_generic_string_hdr *);
771
772/*!
773 * \internal
774 * \brief Callback function which finds a contact whose contact_status has security mechanisms.
775 *
776 * \param obj Pointer to the ast_sip_contact.
777 * \param arg Pointer-pointer to a contact_status that will be set to the contact_status found by this function.
778 * \param flags Flags used by the ao2_callback function.
779 *
780 * \note The refcount of the found contact_status must be decremented by the caller.
781 */
782static int contact_has_security_mechanisms(void *obj, void *arg, int flags)
783{
784 struct ast_sip_contact *contact = obj;
785 struct ast_sip_contact_status **ret = arg;
786 struct ast_sip_contact_status *contact_status = ast_sip_get_contact_status(contact);
787
788 if (!contact_status) {
789 return 0;
790 }
791 if (!AST_VECTOR_SIZE(&contact_status->security_mechanisms)) {
792 ao2_cleanup(contact_status);
793 return 0;
794 }
795 *ret = contact_status;
796 return CMP_MATCH | CMP_STOP;
797}
798
799static int contact_add_security_headers_to_status(void *obj, void *arg, int flags)
800{
801 struct ast_sip_contact *contact = obj;
802 struct pjsip_generic_string_hdr_vector *header_vector = arg;
803 struct ast_sip_contact_status *contact_status = ast_sip_get_contact_status(contact);
804
805 if (!contact_status) {
806 return 0;
807 }
808 if (AST_VECTOR_SIZE(&contact_status->security_mechanisms)) {
809 goto out;
810 }
811
812 ao2_lock(contact_status);
814 ao2_unlock(contact_status);
815
816out:
817 ao2_cleanup(contact_status);
818 return 0;
819}
820
821/*! \brief Adds security negotiation mechanisms of outbound registration client state as Security headers to tdata. */
823 pjsip_tx_data *tdata)
824{
825 int add_sec_client_header = 0;
826 struct sip_outbound_registration *reg = NULL;
827 struct ast_sip_endpoint *endpt = NULL;
828 struct ao2_container *contact_container;
829 struct ast_sip_contact_status *contact_status = NULL;
830 struct ast_sip_security_mechanism_vector *sec_mechs = NULL;
831 static const pj_str_t security_verify = { "Security-Verify", 15 };
832 static const pj_str_t security_client = { "Security-Client", 15 };
833
835 return;
836 }
837
838 /* Get contact status through registration -> endpoint name -> aor -> contact (if set) */
839 if ((reg = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "registration", client_state->registration_name))
840 && !ast_strlen_zero(reg->endpoint) && (endpt = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", reg->endpoint))
841 && (contact_container = ast_sip_location_retrieve_contacts_from_aor_list(endpt->aors))) {
842 /* Retrieve all contacts associated with aors from this endpoint
843 * and find the first one that has security mechanisms.
844 */
845 ao2_callback(contact_container, OBJ_NODATA, contact_has_security_mechanisms, &contact_status);
846 if (contact_status) {
847 ao2_lock(contact_status);
848 sec_mechs = &contact_status->security_mechanisms;
849 }
850 ao2_cleanup(contact_container);
851 }
852 /* Use client_state->server_security_mechanisms if contact_status does not exist. */
853 if (!contact_status && AST_VECTOR_SIZE(&client_state->server_security_mechanisms)) {
854 sec_mechs = &client_state->server_security_mechanisms;
855 }
856 if (client_state->status == SIP_REGISTRATION_REJECTED_TEMPORARY || client_state->auth_attempted) {
857 if (sec_mechs != NULL && pjsip_msg_find_hdr_by_name(tdata->msg, &security_verify, NULL) == NULL) {
858 ast_sip_add_security_headers(sec_mechs, "Security-Verify", 0, tdata);
859 }
860 if (client_state->last_status_code == 494) {
861 ast_sip_remove_headers_by_name_and_value(tdata->msg, &security_client, NULL);
862 } else {
863 /* necessary if a retry occures */
864 add_sec_client_header = (pjsip_msg_find_hdr_by_name(tdata->msg, &security_client, NULL) == NULL) ? 1 : 0;
865 }
866 } else {
867 ast_sip_add_security_headers(&client_state->security_mechanisms, "Security-Client", 0, tdata);
868 }
869
870 if (add_sec_client_header) {
871 ast_sip_add_security_headers(&client_state->security_mechanisms, "Security-Client", 0, tdata);
872 }
873
874 /* Cleanup */
875 if (contact_status) {
876 ao2_unlock(contact_status);
877 ao2_cleanup(contact_status);
878 }
879 ao2_cleanup(endpt);
880 ao2_cleanup(reg);
881}
882
883/*! \brief Helper function which sends a message and cleans up, if needed, on failure */
885 pjsip_tx_data *tdata)
886{
887 pj_status_t status;
888 int *callback_invoked;
889 pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
890
891 callback_invoked = ast_threadstorage_get(&register_callback_invoked, sizeof(int));
892 if (!callback_invoked) {
893 pjsip_tx_data_dec_ref(tdata);
894 return PJ_ENOMEM;
895 }
896 *callback_invoked = 0;
897
898 /* Due to the message going out the callback may now be invoked, so bump the count */
899 ao2_ref(client_state, +1);
900 /*
901 * We also bump tdata in expectation of saving it to client_state->last_tdata.
902 * We have to do it BEFORE pjsip_regc_send because if it succeeds, it decrements
903 * the ref count on its own.
904 */
905 pjsip_tx_data_add_ref(tdata);
906
907 /* Add Security-Verify or Security-Client headers */
908 add_security_headers(client_state, tdata);
909
910 /*
911 * Replace the User-Agent header if a different one should be used
912 */
913 if (!ast_strlen_zero(client_state->user_agent)) {
914 static const pj_str_t user_agent_str = { "User-Agent", 10 };
915 pjsip_generic_string_hdr *default_user_agent_hdr;
916 pjsip_generic_string_hdr *user_agent_hdr;
917 pj_str_t user_agent_val;
918 default_user_agent_hdr = pjsip_msg_find_hdr_by_name(tdata->msg, &user_agent_str, NULL);
919 user_agent_val = pj_str(client_state->user_agent);
920 user_agent_hdr = pjsip_generic_string_hdr_create(tdata->pool, &user_agent_str, &user_agent_val);
921 if (!user_agent_hdr) {
922 ast_log(LOG_ERROR, "Could not add custom User-Agent to outbound registration %s, sending REGISTER request with non-custom header\n", client_state->registration_name);
923 } else {
924 if (default_user_agent_hdr) {
925 pj_list_erase(default_user_agent_hdr);
926 }
927 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)user_agent_hdr);
928 }
929 }
930
931 /*
932 * Set the transport in case transports were reloaded.
933 * When pjproject removes the extraneous error messages produced,
934 * we can check status and only set the transport and resend if there was an error
935 */
937 pjsip_regc_set_transport(client_state->client, &selector);
938 ast_sip_tpselector_unref(&selector);
939
940 status = pjsip_regc_send(client_state->client, tdata);
941
942 /*
943 * If the attempt to send the message failed and the callback was not invoked we need to
944 * drop the references we just added
945 */
946 if ((status != PJ_SUCCESS) && !(*callback_invoked)) {
947 pjsip_tx_data_dec_ref(tdata);
948 ao2_ref(client_state, -1);
949 return status;
950 }
951
952 /*
953 * Decref the old last_data before replacing it.
954 * BTW, it's quite possible that last_data == tdata
955 * if we're trying successive servers in an SRV set.
956 */
957 if (client_state->last_tdata) {
958 pjsip_tx_data_dec_ref(client_state->last_tdata);
959 }
960 client_state->last_tdata = tdata;
961
962 return status;
963}
964
965/*! \brief Helper function to add string to Supported header */
966static int add_to_supported_header(pjsip_tx_data *tdata, pj_str_t *name)
967{
968 pjsip_supported_hdr *hdr;
969 int i;
970
971 hdr = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_SUPPORTED, NULL);
972 if (!hdr) {
973 /* insert a new Supported header */
974 hdr = pjsip_supported_hdr_create(tdata->pool);
975 if (!hdr) {
976 pjsip_tx_data_dec_ref(tdata);
977 return 0;
978 }
979
980 pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)hdr);
981 }
982
983 /* Don't add the value if it's already there */
984 for (i = 0; i < hdr->count; ++i) {
985 if (pj_stricmp(&hdr->values[i], name) == 0) {
986 return 1;
987 }
988 }
989
990 if (hdr->count >= PJSIP_GENERIC_ARRAY_MAX_COUNT) {
991 return 0;
992 }
993
994 /* add on to the existing Supported header */
995 pj_strassign(&hdr->values[hdr->count++], name);
996
997 return 1;
998}
999
1000/*! \brief Helper function to add configured supported headers */
1001static int add_configured_supported_headers(struct sip_outbound_registration_client_state *client_state, pjsip_tx_data *tdata)
1002{
1003 if (client_state->support_path) {
1004 if (!add_to_supported_header(tdata, &PATH_NAME)) {
1005 return 0;
1006 }
1007 }
1008
1009 if (client_state->support_outbound) {
1010 if (!add_to_supported_header(tdata, &OUTBOUND_NAME)) {
1011 return 0;
1012 }
1013 }
1014
1015 return 1;
1016}
1017
1018/*! \brief Callback function for registering */
1019static int handle_client_registration(void *data)
1020{
1021 RAII_VAR(struct sip_outbound_registration_client_state *, client_state, data, ao2_cleanup);
1022 pjsip_tx_data *tdata;
1023
1024 if (set_outbound_initial_authentication_credentials(client_state->client, &client_state->outbound_auths)) {
1025 ast_log(LOG_WARNING, "Failed to set initial authentication credentials\n");
1026 }
1027
1028 if (client_state->status == SIP_REGISTRATION_STOPPED
1029 || pjsip_regc_register(client_state->client, PJ_FALSE, &tdata) != PJ_SUCCESS) {
1030 return 0;
1031 }
1032
1033 if (DEBUG_ATLEAST(1)) {
1034 pjsip_regc_info info;
1035
1036 pjsip_regc_get_info(client_state->client, &info);
1037 ast_log(LOG_DEBUG, "Outbound REGISTER attempt %u to '%.*s' with client '%.*s'\n",
1038 client_state->retries + 1,
1039 (int) info.server_uri.slen, info.server_uri.ptr,
1040 (int) info.client_uri.slen, info.client_uri.ptr);
1041 }
1042
1043 if (!add_configured_supported_headers(client_state, tdata)) {
1044 ast_log(LOG_WARNING, "Failed to set supported headers\n");
1045 return -1;
1046 }
1047
1048 registration_client_send(client_state, tdata);
1049
1050 return 0;
1051}
1052
1053/*! \brief Timer callback function, used just for registrations */
1054static void sip_outbound_registration_timer_cb(pj_timer_heap_t *timer_heap, struct pj_timer_entry *entry)
1055{
1056 struct sip_outbound_registration_client_state *client_state = entry->user_data;
1057
1058 entry->id = 0;
1059
1060 /*
1061 * Transfer client_state reference to serializer task so the
1062 * nominal path will not dec the client_state ref in this
1063 * pjproject callback thread.
1064 */
1065 if (ast_sip_push_task(client_state->serializer, handle_client_registration, client_state)) {
1066 ast_log(LOG_WARNING, "Scheduled outbound registration could not be executed.\n");
1067 ao2_ref(client_state, -1);
1068 }
1069}
1070
1071/*! \brief Helper function which sets up the timer to re-register in a specific amount of time */
1072static void schedule_registration(struct sip_outbound_registration_client_state *client_state, unsigned int seconds)
1073{
1074 pj_time_val delay = { .sec = seconds, };
1075 pjsip_regc_info info;
1076
1077 cancel_registration(client_state);
1078
1079 pjsip_regc_get_info(client_state->client, &info);
1080 ast_debug(1, "Scheduling outbound registration to server '%.*s' from client '%.*s' in %d seconds\n",
1081 (int) info.server_uri.slen, info.server_uri.ptr,
1082 (int) info.client_uri.slen, info.client_uri.ptr,
1083 seconds);
1084
1085 ao2_ref(client_state, +1);
1086 if (pjsip_endpt_schedule_timer(ast_sip_get_pjsip_endpoint(), &client_state->timer, &delay) != PJ_SUCCESS) {
1087 ast_log(LOG_WARNING, "Failed to schedule registration to server '%.*s' from client '%.*s'\n",
1088 (int) info.server_uri.slen, info.server_uri.ptr,
1089 (int) info.client_uri.slen, info.client_uri.ptr);
1090 ao2_ref(client_state, -1);
1091 }
1092 client_state->registration_expires = ((int) time(NULL)) + seconds;
1093}
1094
1096{
1097 const char *status_old;
1098 const char *status_new;
1099
1100 if (client_state->status == status) {
1101 /* Status state did not change at all. */
1102 return;
1103 }
1104
1105 status_old = sip_outbound_registration_status_str(client_state->status);
1107 client_state->status = status;
1108
1109 if (!strcmp(status_old, status_new)) {
1110 /*
1111 * The internal status state may have changed but the status
1112 * state we tell the world did not change at all.
1113 */
1114 return;
1115 }
1116
1117 ast_statsd_log_string_va("PJSIP.registrations.state.%s", AST_STATSD_GAUGE, "-1", 1.0,
1118 status_old);
1119 ast_statsd_log_string_va("PJSIP.registrations.state.%s", AST_STATSD_GAUGE, "+1", 1.0,
1120 status_new);
1121}
1122
1123/*! \brief Callback function for unregistering (potentially) and destroying state */
1125{
1126 struct sip_outbound_registration_client_state *client_state = data;
1127
1128 cancel_registration(client_state);
1129
1130 if (client_state->client) {
1131 pjsip_regc_info info;
1132 pjsip_tx_data *tdata;
1133
1134 pjsip_regc_get_info(client_state->client, &info);
1135
1136 if (info.is_busy == PJ_TRUE) {
1137 /* If a client transaction is in progress we defer until it is complete */
1138 ast_debug(1,
1139 "Registration transaction is busy with server '%.*s' from client '%.*s'.\n",
1140 (int) info.server_uri.slen, info.server_uri.ptr,
1141 (int) info.client_uri.slen, info.client_uri.ptr);
1142 client_state->destroy = 1;
1143 ao2_ref(client_state, -1);
1144 return 0;
1145 }
1146
1147 switch (client_state->status) {
1149 break;
1151 ast_debug(1,
1152 "Trying to unregister with server '%.*s' from client '%.*s' before destruction.\n",
1153 (int) info.server_uri.slen, info.server_uri.ptr,
1154 (int) info.client_uri.slen, info.client_uri.ptr);
1155
1157 client_state->destroy = 1;
1158 if (pjsip_regc_unregister(client_state->client, &tdata) == PJ_SUCCESS
1159 && add_configured_supported_headers(client_state, tdata)
1160 && registration_client_send(client_state, tdata) == PJ_SUCCESS) {
1161 ao2_ref(client_state, -1);
1162 return 0;
1163 }
1164 break;
1169 break;
1170 }
1171
1172 pjsip_regc_destroy(client_state->client);
1173 client_state->client = NULL;
1174 }
1175
1180 ao2_ref(client_state, -1);
1181
1182 return 0;
1183}
1184
1185/*! \brief Structure for registration response */
1187 /*! \brief Response code for the registration attempt */
1188 int code;
1189 /*! \brief Expiration time for registration */
1191 /*! \brief Retry-After value */
1193 /*! \brief Outbound registration client state */
1195 /*! \brief The response message */
1196 pjsip_rx_data *rdata;
1197 /*! \brief Request for which the response was received */
1198 pjsip_tx_data *old_request;
1199 /*! \brief Key for the reliable transport in use */
1201};
1202
1203/*! \brief Registration response structure destructor */
1204static void registration_response_destroy(void *obj)
1205{
1206 struct registration_response *response = obj;
1207
1208 if (response->rdata) {
1209 pjsip_rx_data_free_cloned(response->rdata);
1210 }
1211
1212 if (response->old_request) {
1213 pjsip_tx_data_dec_ref(response->old_request);
1214 }
1215
1216 ao2_cleanup(response->client_state);
1217}
1218
1219/*! \brief Helper function which determines if a response code is temporal or not */
1222{
1223 /* Shamelessly taken from pjsua */
1224 if (code == PJSIP_SC_REQUEST_TIMEOUT ||
1225 code == PJSIP_SC_INTERNAL_SERVER_ERROR ||
1226 code == PJSIP_SC_BAD_GATEWAY ||
1227 code == PJSIP_SC_SERVICE_UNAVAILABLE ||
1228 code == PJSIP_SC_SERVER_TIMEOUT ||
1229 ((code == PJSIP_SC_UNAUTHORIZED ||
1230 code == PJSIP_SC_PROXY_AUTHENTICATION_REQUIRED) &&
1232 PJSIP_IS_STATUS_IN_CLASS(code, 600)) {
1233 return 1;
1234 } else {
1235 return 0;
1236 }
1237}
1238
1239static void schedule_retry(struct registration_response *response, unsigned int interval,
1240 const char *server_uri, const char *client_uri)
1241{
1243 schedule_registration(response->client_state, interval);
1244
1245 if (response->rdata) {
1246 ast_log(LOG_WARNING, "Temporal response '%d' received from '%s' on "
1247 "registration attempt to '%s', retrying in '%u'\n",
1248 response->code, server_uri, client_uri, interval);
1249 } else {
1250 ast_log(LOG_WARNING, "No response received from '%s' on "
1251 "registration attempt to '%s', retrying in '%u'\n",
1252 server_uri, client_uri, interval);
1253 }
1254}
1255
1256static int reregister_immediately_cb(void *obj)
1257{
1259
1260 if (state->client_state->status != SIP_REGISTRATION_REGISTERED) {
1261 ao2_ref(state, -1);
1262 return 0;
1263 }
1264
1265 if (DEBUG_ATLEAST(1)) {
1266 pjsip_regc_info info;
1267
1268 pjsip_regc_get_info(state->client_state->client, &info);
1270 "Outbound registration transport to server '%.*s' from client '%.*s' shutdown\n",
1271 (int) info.server_uri.slen, info.server_uri.ptr,
1272 (int) info.client_uri.slen, info.client_uri.ptr);
1273 }
1274
1275 cancel_registration(state->client_state);
1276
1277 ao2_ref(state->client_state, +1);
1278 handle_client_registration(state->client_state);
1279
1280 ao2_ref(state, -1);
1281 return 0;
1282}
1283
1284/*!
1285 * \internal
1286 * \brief The reliable transport we registered using has shutdown.
1287 * \since 13.18.0
1288 *
1289 * \param obj What is needed to initiate a reregister attempt.
1290 *
1291 * \note Normally executed by the pjsip monitor thread.
1292 */
1294{
1295 const char *registration_name = obj;
1297
1298 state = get_state(registration_name);
1299 if (!state) {
1300 /* Registration no longer exists or shutting down. */
1301 return;
1302 }
1303 if (ast_sip_push_task(state->client_state->serializer, reregister_immediately_cb, state)) {
1304 ao2_ref(state, -1);
1305 }
1306}
1307
1308static int monitor_matcher(void *a, void *b)
1309{
1310 char *ma = a;
1311 char *mb = b;
1312
1313 return strcmp(ma, mb) == 0;
1314}
1315
1316static void registration_transport_monitor_setup(const char *transport_key, const char *registration_name)
1317{
1318 char *monitor;
1319 enum ast_transport_monitor_reg monitor_res;
1320
1321 monitor = ao2_alloc_options(strlen(registration_name) + 1, NULL,
1323 if (!monitor) {
1324 return;
1325 }
1326 strcpy(monitor, registration_name);/* Safe */
1327
1328 /*
1329 * We'll ignore if the transport has already been shutdown before we
1330 * register the monitor. We might get into a message spamming infinite
1331 * loop of registration, shutdown, reregistration...
1332 */
1334 monitor, monitor_matcher))) {
1335 ast_log(LOG_NOTICE, "Failed to register transport monitor for regisration %s: %d\n", registration_name, monitor_res);
1336 }
1337 ao2_ref(monitor, -1);
1338}
1339
1341{
1342 static const pj_str_t associated_uri_str = { "P-Associated-URI", 16 };
1343 static const pj_str_t service_route_str = { "Service-Route", 13 };
1344 pjsip_hdr *header = NULL;
1345 pjsip_msg *msg = response->rdata->msg_info.msg;
1346 struct ast_sip_service_route_vector *service_routes = NULL;
1347
1348 /* If no transport is specified then we can't update any */
1350 return;
1351 }
1352
1353 ast_sip_transport_state_set_transport(response->client_state->transport_name, response->rdata->tp_info.transport);
1354
1355 while ((header = pjsip_msg_find_hdr_by_name(msg, &service_route_str, header ? header->next : NULL))) {
1356 char *service_route;
1357 size_t size;
1358
1359 /* The below code takes the approach that if we can't store all service routes then we
1360 * store none at all. This gives a predictable failure condition instead of storing a
1361 * partial list and having partial route headers.
1362 */
1363 size = pj_strlen(&((pjsip_generic_string_hdr*)header)->hvalue) + 1;
1364 service_route = ast_malloc(size);
1365 if (!service_route) {
1366 if (service_routes) {
1368 service_routes = NULL;
1369 }
1370 break;
1371 }
1372
1373 ast_copy_pj_str(service_route, &((pjsip_generic_string_hdr*)header)->hvalue, size);
1374
1375 if (!service_routes) {
1376 service_routes = ast_sip_service_route_vector_alloc();
1377 if (!service_routes) {
1378 ast_free(service_route);
1379 break;
1380 }
1381 }
1382
1383 if (AST_VECTOR_APPEND(service_routes, service_route)) {
1384 ast_free(service_route);
1386 service_routes = NULL;
1387 break;
1388 }
1389 }
1390
1391 /* If any service routes were handled then store them on the transport */
1392 if (service_routes) {
1394 }
1395
1396 /* If an associated URI is present in the response we need to use it on any outgoing
1397 * traffic on the transport.
1398 */
1399 header = pjsip_msg_find_hdr_by_name(msg, &associated_uri_str, NULL);
1400 if (header) {
1401 char value[pj_strlen(&((pjsip_generic_string_hdr*)header)->hvalue) + 1];
1402
1403 ast_copy_pj_str(value, &((pjsip_generic_string_hdr*)header)->hvalue, sizeof(value));
1405 }
1406}
1407
1408
1409/*! \brief Callback function for handling a response to a registration attempt */
1410static int handle_registration_response(void *data)
1411{
1412 struct registration_response *response = data;
1413 pjsip_regc_info info;
1414 char server_uri[PJSIP_MAX_URL_SIZE];
1415 char client_uri[PJSIP_MAX_URL_SIZE];
1416
1417 if (response->client_state->status == SIP_REGISTRATION_STOPPED) {
1418 ao2_ref(response, -1);
1419 return 0;
1420 }
1421
1422 pjsip_regc_get_info(response->client_state->client, &info);
1423 ast_copy_pj_str(server_uri, &info.server_uri, sizeof(server_uri));
1424 ast_copy_pj_str(client_uri, &info.client_uri, sizeof(client_uri));
1425 response->client_state->last_status_code = response->code;
1426
1427 ast_debug(1, "Processing REGISTER response %d from server '%s' for client '%s'\n",
1428 response->code, server_uri, client_uri);
1429
1430 if (response->code == 408 || response->code == 503) {
1431 if ((ast_sip_failover_request(response->old_request))) {
1432 int res = registration_client_send(response->client_state, response->old_request);
1433 /* The tdata ref was stolen */
1434 response->old_request = NULL;
1435 if (res == PJ_SUCCESS) {
1436 ao2_ref(response, -1);
1437 return 0;
1438 }
1439 }
1440 } else if ((response->code == 401 || response->code == 407 || response->code == 494)
1441 && (!response->client_state->auth_attempted
1442 || response->rdata->msg_info.cseq->cseq != response->client_state->auth_cseq)) {
1443 int res;
1444 pjsip_cseq_hdr *cseq_hdr;
1445 pjsip_tx_data *tdata;
1446
1448 struct sip_outbound_registration *reg = NULL;
1449 struct ast_sip_endpoint *endpt = NULL;
1450 struct ao2_container *contact_container = NULL;
1451 pjsip_generic_string_hdr *header;
1452 struct pjsip_generic_string_hdr_vector header_vector;
1453 static const pj_str_t security_server = { "Security-Server", 15 };
1454
1455 if ((reg = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "registration",
1456 response->client_state->registration_name)) && reg->endpoint &&
1457 (endpt = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", reg->endpoint))) {
1458 /* Retrieve all contacts associated with aors from this endpoint (if set). */
1459 contact_container = ast_sip_location_retrieve_contacts_from_aor_list(endpt->aors);
1460 }
1461 /* Add server list of security mechanism to client_state and contact status if exists. */
1462 AST_VECTOR_INIT(&header_vector, 1);
1463 header = pjsip_msg_find_hdr_by_name(response->rdata->msg_info.msg, &security_server, NULL);
1464 for (; header;
1465 header = pjsip_msg_find_hdr_by_name(response->rdata->msg_info.msg, &security_server, header->next)) {
1466 AST_VECTOR_APPEND(&header_vector, header);
1468 }
1469 if (contact_container) {
1470 /* Add server security mechanisms to contact status of all associated contacts to be able to send correct
1471 * Security-Verify headers on subsequent non-REGISTER requests through this outbound registration.
1472 */
1473 ao2_callback(contact_container, OBJ_NODATA, contact_add_security_headers_to_status, &header_vector);
1474 ao2_cleanup(contact_container);
1475 }
1476 AST_VECTOR_FREE(&header_vector);
1477 ao2_cleanup(endpt);
1478 ao2_cleanup(reg);
1479 }
1480
1481 if (response->code == 494) {
1483 response->client_state->retries++;
1484 schedule_registration(response->client_state, 0);
1485 ao2_ref(response, -1);
1486 return 0;
1488 response->rdata, response->old_request, &tdata)) {
1489 response->client_state->auth_attempted = 1;
1490 ast_debug(1, "Sending authenticated REGISTER to server '%s' from client '%s'\n",
1491 server_uri, client_uri);
1492 pjsip_tx_data_add_ref(tdata);
1493
1495
1496 res = registration_client_send(response->client_state, tdata);
1497
1498 /* Save the cseq that actually got sent. */
1499 cseq_hdr = (pjsip_cseq_hdr *) pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CSEQ,
1500 NULL);
1501 response->client_state->auth_cseq = cseq_hdr->cseq;
1502 pjsip_tx_data_dec_ref(tdata);
1503 if (res == PJ_SUCCESS) {
1504 ao2_ref(response, -1);
1505 return 0;
1506 }
1507 } else {
1508 ast_log(LOG_WARNING, "Failed to create authenticated REGISTER request to server '%s' from client '%s'\n",
1509 server_uri, client_uri);
1510 }
1511 /* Otherwise, fall through so the failure is processed appropriately */
1512 }
1513
1514 response->client_state->auth_attempted = 0;
1515
1516 if (PJSIP_IS_STATUS_IN_CLASS(response->code, 200)) {
1517 /* Check if this is in regards to registering or unregistering */
1518 if (response->expiration) {
1519 int next_registration_round;
1520
1521 /* If the registration went fine simply reschedule registration for the future */
1522 ast_debug(1, "Outbound registration to '%s' with client '%s' successful\n", server_uri, client_uri);
1524 response->client_state->retries = 0;
1525 next_registration_round = response->expiration - REREGISTER_BUFFER_TIME;
1526 if (next_registration_round < 0) {
1527 /* Re-register immediately. */
1528 next_registration_round = 0;
1529 }
1530 schedule_registration(response->client_state, next_registration_round);
1531
1532 /* See if we should monitor for transport shutdown */
1533 if (PJSIP_TRANSPORT_IS_RELIABLE(response->rdata->tp_info.transport)) {
1535 response->client_state->registration_name);
1536 }
1537 } else {
1538 ast_debug(1, "Outbound unregistration to '%s' with client '%s' successful\n", server_uri, client_uri);
1540 if (PJSIP_TRANSPORT_IS_RELIABLE(response->rdata->tp_info.transport)) {
1544 }
1545 }
1546
1548 } else if (response->client_state->destroy) {
1549 /* We need to deal with the pending destruction instead. */
1550 } else if (response->retry_after) {
1551 /* If we have been instructed to retry after a period of time, schedule it as such */
1552 schedule_retry(response, response->retry_after, server_uri, client_uri);
1553 } else if (response->client_state->retry_interval
1554 && sip_outbound_registration_is_temporal(response->code, response->client_state)) {
1555 if (response->client_state->retries == response->client_state->max_retries) {
1556 /* If we received enough temporal responses to exceed our maximum give up permanently */
1558 ast_log(LOG_WARNING, "Maximum retries reached when attempting outbound registration to '%s' with client '%s', stopping registration attempt\n",
1559 server_uri, client_uri);
1560 } else {
1561 /* On the other hand if we can still try some more do so */
1562 response->client_state->retries++;
1563 schedule_retry(response, response->client_state->retry_interval, server_uri, client_uri);
1564 }
1565 } else {
1566 if (response->code == 403
1568 && response->client_state->retries < response->client_state->max_retries) {
1569 /* A forbidden response retry interval is configured and there are retries remaining */
1571 response->client_state->retries++;
1573 ast_log(LOG_WARNING, "403 Forbidden fatal response received from '%s' on registration attempt to '%s', retrying in '%u' seconds\n",
1574 server_uri, client_uri, response->client_state->forbidden_retry_interval);
1575 } else if (response->client_state->fatal_retry_interval
1576 && response->client_state->retries < response->client_state->max_retries) {
1577 /* Some kind of fatal failure response received, so retry according to configured interval */
1579 response->client_state->retries++;
1581 ast_log(LOG_WARNING, "'%d' fatal response received from '%s' on registration attempt to '%s', retrying in '%u' seconds\n",
1582 response->code, server_uri, client_uri, response->client_state->fatal_retry_interval);
1583 } else {
1584 /* Finally if there's no hope of registering give up */
1586 if (response->rdata) {
1587 ast_log(LOG_WARNING, "Fatal response '%d' received from '%s' on registration attempt to '%s', stopping outbound registration\n",
1588 response->code, server_uri, client_uri);
1589 } else {
1590 ast_log(LOG_WARNING, "Fatal registration attempt to '%s', stopping outbound registration\n", client_uri);
1591 }
1592 }
1593 }
1594
1595 ast_system_publish_registry("PJSIP", client_uri, server_uri,
1597
1598 if (response->client_state->destroy) {
1599 /* We have a pending deferred destruction to complete now. */
1600 ao2_ref(response->client_state, +1);
1602 }
1603
1604 ao2_ref(response, -1);
1605 return 0;
1606}
1607
1608/*! \brief Callback function for outbound registration client */
1609static void sip_outbound_registration_response_cb(struct pjsip_regc_cbparam *param)
1610{
1611 struct sip_outbound_registration_client_state *client_state = param->token;
1612 struct registration_response *response;
1613 int *callback_invoked;
1614
1615 callback_invoked = ast_threadstorage_get(&register_callback_invoked, sizeof(int));
1616
1617 ast_assert(callback_invoked != NULL);
1619
1620 *callback_invoked = 1;
1621
1622 response = ao2_alloc(sizeof(*response), registration_response_destroy);
1623 if (!response) {
1624 ao2_ref(client_state, -1);
1625 return;
1626 }
1627 response->code = param->code;
1628 response->expiration = param->expiration;
1629 /*
1630 * Transfer client_state reference to response so the
1631 * nominal path will not dec the client_state ref in this
1632 * pjproject callback thread.
1633 */
1634 response->client_state = client_state;
1635
1636 ast_debug(1, "Received REGISTER response %d(%.*s)\n",
1637 param->code, (int) param->reason.slen, param->reason.ptr);
1638
1639 if (param->rdata) {
1640 struct pjsip_retry_after_hdr *retry_after;
1641 pjsip_transaction *tsx;
1642
1643 retry_after = pjsip_msg_find_hdr(param->rdata->msg_info.msg, PJSIP_H_RETRY_AFTER,
1644 NULL);
1645 response->retry_after = retry_after ? retry_after->ivalue : 0;
1646
1647 /*
1648 * If we got a response from the server, we have to use the tdata
1649 * from the transaction, not the tdata saved when we sent the
1650 * request. If we use the saved tdata, we won't process responses
1651 * like 423 Interval Too Brief correctly and we'll wind up sending
1652 * the bad Expires value again.
1653 */
1654 pjsip_tx_data_dec_ref(client_state->last_tdata);
1655
1656 tsx = pjsip_rdata_get_tsx(param->rdata);
1657 response->old_request = tsx->last_tx;
1658 pjsip_tx_data_add_ref(response->old_request);
1659 pjsip_rx_data_clone(param->rdata, 0, &response->rdata);
1660 AST_SIP_MAKE_REMOTE_IPADDR_PORT_STR(param->rdata->tp_info.transport,
1661 response->transport_key);
1662
1663 } else {
1664 /* old_request steals the reference */
1665 response->old_request = client_state->last_tdata;
1666 }
1667 client_state->last_tdata = NULL;
1668
1669 /*
1670 * Transfer response reference to serializer task so the
1671 * nominal path will not dec the response ref in this
1672 * pjproject callback thread.
1673 */
1674 if (ast_sip_push_task(client_state->serializer, handle_registration_response, response)) {
1675 ast_log(LOG_WARNING, "Failed to pass incoming registration response to taskpool\n");
1676 ao2_cleanup(response);
1677 }
1678}
1679
1680/*! \brief Destructor function for registration state */
1682{
1684
1685 ast_debug(3, "Destroying registration state for registration to server '%s' from client '%s'\n",
1686 state->registration ? state->registration->server_uri : "",
1687 state->registration ? state->registration->client_uri : "");
1688 ao2_cleanup(state->registration);
1689
1690 if (!state->client_state) {
1691 /* Nothing to do */
1692 } else if (!state->client_state->serializer) {
1693 ao2_ref(state->client_state, -1);
1694 } else if (ast_sip_push_task(state->client_state->serializer,
1695 handle_client_state_destruction, state->client_state)) {
1696 ast_log(LOG_WARNING, "Failed to pass outbound registration client destruction to taskpool\n");
1697 ao2_ref(state->client_state, -1);
1698 }
1699}
1700
1701/*! \brief Destructor function for client registration state */
1703{
1704 struct sip_outbound_registration_client_state *client_state = obj;
1705
1706 ast_statsd_log_string("PJSIP.registrations.count", AST_STATSD_GAUGE, "-1", 1.0);
1707 ast_statsd_log_string_va("PJSIP.registrations.state.%s", AST_STATSD_GAUGE, "-1", 1.0,
1709
1711 ast_free(client_state->transport_name);
1712 ast_free(client_state->registration_name);
1713 ast_free(client_state->user_agent);
1714 if (client_state->last_tdata) {
1715 pjsip_tx_data_dec_ref(client_state->last_tdata);
1716 }
1717}
1718
1719/*! \brief Allocator function for registration state */
1721{
1723 char tps_name[AST_TASKPROCESSOR_MAX_NAME + 1];
1724
1726 if (!state) {
1727 return NULL;
1728 }
1729 state->client_state = ao2_alloc(sizeof(*state->client_state),
1731 if (!state->client_state) {
1733 return NULL;
1734 }
1735
1736 state->client_state->status = SIP_REGISTRATION_UNREGISTERED;
1737 pj_timer_entry_init(&state->client_state->timer, 0, state->client_state,
1739 state->client_state->transport_name = ast_strdup(registration->transport);
1740 state->client_state->registration_name =
1742 state->client_state->user_agent = ast_strdup(registration->user_agent);
1743
1744 ast_statsd_log_string("PJSIP.registrations.count", AST_STATSD_GAUGE, "+1", 1.0);
1745 ast_statsd_log_string_va("PJSIP.registrations.state.%s", AST_STATSD_GAUGE, "+1", 1.0,
1746 sip_outbound_registration_status_str(state->client_state->status));
1747
1748 if (!state->client_state->transport_name
1749 || !state->client_state->registration_name) {
1751 return NULL;
1752 }
1753
1754 /* Create name with seq number appended. */
1755 ast_taskprocessor_build_name(tps_name, sizeof(tps_name), "pjsip/outreg/%s",
1757
1758 state->client_state->serializer = ast_sip_create_serializer_group(tps_name,
1760 if (!state->client_state->serializer) {
1762 return NULL;
1763 }
1764
1765 state->registration = ao2_bump(registration);
1766 return state;
1767}
1768
1769/*! \brief Destructor function for registration information */
1771{
1772 struct sip_outbound_registration *registration = obj;
1773
1776
1777 ast_string_field_free_memory(registration);
1778}
1779
1780/*! \brief Allocator function for registration information */
1781static void *sip_outbound_registration_alloc(const char *name)
1782{
1783 struct sip_outbound_registration *registration;
1784
1785 registration = ast_sorcery_generic_alloc(sizeof(*registration),
1787 if (!registration || ast_string_field_init(registration, 256)) {
1788 ao2_cleanup(registration);
1789 return NULL;
1790 }
1791
1792 return registration;
1793}
1794
1795/*! \brief Helper function which populates a pj_str_t with a contact header */
1796static int sip_dialog_create_contact(pj_pool_t *pool, pj_str_t *contact, const char *user,
1797 const pj_str_t *target, pjsip_tpselector *selector, const char *line, const char *header_params)
1798{
1799 pj_str_t tmp, local_addr;
1800 pjsip_uri *uri;
1801 pjsip_sip_uri *sip_uri;
1802 pjsip_transport_type_e type;
1803 int local_port;
1804
1805 pj_strdup_with_null(pool, &tmp, target);
1806
1807 if (!(uri = pjsip_parse_uri(pool, tmp.ptr, tmp.slen, 0)) ||
1808 (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri))) {
1809 return -1;
1810 }
1811
1812 sip_uri = pjsip_uri_get_uri(uri);
1813
1814 type = pjsip_transport_get_type_from_name(&sip_uri->transport_param);
1815 if (PJSIP_URI_SCHEME_IS_SIPS(sip_uri)) {
1816 if (type == PJSIP_TRANSPORT_UNSPECIFIED
1817 || !(pjsip_transport_get_flag_from_type(type) & PJSIP_TRANSPORT_SECURE)) {
1818 type = PJSIP_TRANSPORT_TLS;
1819 }
1820 } else if (!sip_uri->transport_param.slen) {
1821 type = PJSIP_TRANSPORT_UDP;
1822 } else if (type == PJSIP_TRANSPORT_UNSPECIFIED) {
1823 return -1;
1824 }
1825
1826 if (pj_strchr(&sip_uri->host, ':')) {
1827 type |= PJSIP_TRANSPORT_IPV6;
1828 }
1829
1830 if (pjsip_tpmgr_find_local_addr(pjsip_endpt_get_tpmgr(ast_sip_get_pjsip_endpoint()),
1831 pool, type, selector, &local_addr, &local_port) != PJ_SUCCESS) {
1832 return -1;
1833 }
1834
1835 if (!pj_strchr(&sip_uri->host, ':') && pj_strchr(&local_addr, ':')) {
1836 type |= PJSIP_TRANSPORT_IPV6;
1837 }
1838
1839 contact->ptr = pj_pool_alloc(pool, PJSIP_MAX_URL_SIZE);
1840 contact->slen = pj_ansi_snprintf(contact->ptr, PJSIP_MAX_URL_SIZE,
1841 "<%s:%s@%s%.*s%s:%d%s%s%s%s>%s%s",
1842 ((pjsip_transport_get_flag_from_type(type) & PJSIP_TRANSPORT_SECURE) && PJSIP_URI_SCHEME_IS_SIPS(uri)) ? "sips" : "sip",
1843 user,
1844 (type & PJSIP_TRANSPORT_IPV6) ? "[" : "",
1845 (int)local_addr.slen,
1846 local_addr.ptr,
1847 (type & PJSIP_TRANSPORT_IPV6) ? "]" : "",
1848 local_port,
1849 (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? ";transport=" : "",
1850 (type != PJSIP_TRANSPORT_UDP && type != PJSIP_TRANSPORT_UDP6) ? pjsip_transport_get_type_name(type) : "",
1851 !ast_strlen_zero(line) ? ";line=" : "",
1852 S_OR(line, ""),
1853 !ast_strlen_zero(header_params) ? ";" : "",
1854 S_OR(header_params, ""));
1855
1856 return 0;
1857}
1858
1859/*!
1860 * \internal
1861 * \brief Check if a registration can be reused
1862 *
1863 * This checks if the existing outbound registration's configuration differs from a newly-applied
1864 * outbound registration to see if the applied one.
1865 *
1866 * \param existing The pre-existing outbound registration
1867 * \param applied The newly-created registration
1868 */
1870 struct sip_outbound_registration *applied)
1871{
1872 int rc = 1;
1874 struct ast_variable *ve = ast_sorcery_objectset_create(sorcery, existing);
1875 struct ast_variable *va = ast_sorcery_objectset_create(sorcery, applied);
1876 struct ast_variable *vc = NULL;
1877
1878 if (ast_sorcery_changeset_create(ve, va, &vc) || vc != NULL) {
1879 rc = 0;
1880 ast_debug(4, "Registration '%s' changed. Can't re-use.\n", ast_sorcery_object_get_id(existing));
1881 } else {
1882 ast_debug(4, "Registration '%s' didn't change. Can re-use\n", ast_sorcery_object_get_id(existing));
1883 }
1884
1888
1889 return rc;
1890}
1891
1892/*! \brief Get google oauth2 access token using refresh token */
1893static const char *fetch_google_access_token(const struct ast_sip_auth *auth)
1894{
1895 char *cmd = NULL;
1896 const char *token;
1897 const char *url = "https://www.googleapis.com/oauth2/v3/token";
1898 char buf[4096];
1899 int res;
1900 struct ast_json_error error;
1901 struct ast_json *json;
1902
1903 /* set timeout to be shorter than default 180s (also checks func_curl is available) */
1904 if (ast_func_write(NULL, "CURLOPT(conntimeout)", "10")) {
1905 ast_log(LOG_ERROR, "CURL is unavailable. This is required for Google OAuth 2.0 authentication. Please ensure it is loaded.\n");
1906 return NULL;
1907 }
1908
1909 res = ast_asprintf(&cmd,
1910 "CURL(%s,client_id=%s&client_secret=%s&refresh_token=%s&grant_type=refresh_token)",
1911 url, auth->oauth_clientid, auth->oauth_secret, auth->refresh_token);
1912 if (res < 0) {
1913 return NULL;
1914 }
1915
1916 ast_debug(2, "Performing Google OAuth 2.0 authentication using command: %s\n", cmd);
1917
1918 buf[0] = '\0';
1919 res = ast_func_read(NULL, cmd, buf, sizeof(buf));
1920 ast_free(cmd);
1921 if (res) {
1922 ast_log(LOG_ERROR, "Could not retrieve Google OAuth 2.0 authentication\n");
1923 return NULL;
1924 }
1925
1926 ast_debug(2, "Google OAuth 2.0 authentication returned: %s\n", buf);
1927
1928 json = ast_json_load_string(buf, &error);
1929 if (!json) {
1930 ast_log(LOG_ERROR, "Could not parse Google OAuth 2.0 authentication: %d(%d) %s: '%s'\n",
1931 error.line, error.column, error.text, buf);
1932 return NULL;
1933 }
1934
1935 token = ast_json_string_get(ast_json_object_get(json, "access_token"));
1936 if (!token) {
1937 ast_log(LOG_ERROR, "Could not find Google OAuth 2.0 access_token in: '%s'\n",
1938 buf);
1939 }
1940 token = ast_strdup(token);
1941 ast_json_unref(json);
1942 return token;
1943}
1944
1945/*!
1946 * \internal
1947 * \brief Set pjsip registration context with any authentication credentials that need to be
1948 * sent in the initial registration request
1949 *
1950 * \param regc The pjsip registration context
1951 * \param auth_vector The vector of configured authentication credentials
1952 */
1954 const struct ast_sip_auth_vector *auth_vector)
1955{
1956 size_t auth_size = AST_VECTOR_SIZE(auth_vector);
1957 struct ast_sip_auth *auths[auth_size];
1958 const char *access_token;
1959 pjsip_cred_info auth_creds[1];
1960 pjsip_auth_clt_pref prefs;
1961 int res = 0;
1962 int idx;
1963
1964 memset(auths, 0, sizeof(auths));
1965 if (ast_sip_retrieve_auths(auth_vector, auths)) {
1966 res = -1;
1967 goto cleanup;
1968 }
1969
1970 for (idx = 0; idx < auth_size; ++idx) {
1971 switch (auths[idx]->type) {
1973 pj_cstr(&auth_creds[0].username, auths[idx]->auth_user);
1974 pj_cstr(&auth_creds[0].scheme, "Bearer");
1975 pj_cstr(&auth_creds[0].realm, auths[idx]->realm);
1976 ast_debug(2, "Obtaining Google OAuth access token\n");
1977 access_token = fetch_google_access_token(auths[idx]);
1978 if (!access_token) {
1979 ast_log(LOG_WARNING, "Obtaining Google OAuth access token failed\n");
1980 access_token = auths[idx]->auth_pass;
1981 res = -1;
1982 }
1983 ast_debug(2, "Setting data to '%s'\n", access_token);
1984
1985 pj_cstr(&auth_creds[0].data, access_token);
1986 auth_creds[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
1987
1988 pjsip_regc_set_credentials(regc, 1, auth_creds);
1989
1990 /* for oauth, send auth without waiting for unauthorized response */
1991 prefs.initial_auth = PJ_TRUE;
1992 pj_cstr(&prefs.algorithm, "oauth");
1993 pjsip_regc_set_prefs(regc, &prefs);
1994
1995 if (access_token != auths[idx]->auth_pass) {
1996 ast_free((char *) access_token);
1997 }
1998 break;
1999 default:
2000 /* other cases handled after receiving auth rejection */
2001 break;
2002 }
2003 }
2004
2005cleanup:
2006 ast_sip_cleanup_auths(auths, auth_size);
2007 return res;
2008}
2009
2010/*! \brief Helper function that allocates a pjsip registration client and configures it */
2012{
2015 ao2_bump(state->registration), ao2_cleanup);
2016 pj_pool_t *pool;
2017 pj_str_t tmp;
2018 pjsip_uri *uri;
2019 pj_str_t server_uri, client_uri, contact_uri;
2020 pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
2021
2022 pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "URI Validation", 256, 256);
2023 if (!pool) {
2024 ast_log(LOG_ERROR, "Could not create pool for URI validation on outbound registration '%s'\n",
2026 return -1;
2027 }
2028
2029 pj_strdup2_with_null(pool, &tmp, registration->server_uri);
2030 uri = pjsip_parse_uri(pool, tmp.ptr, tmp.slen, 0);
2031 if (!uri) {
2032 ast_log(LOG_ERROR, "Invalid server URI '%s' specified on outbound registration '%s'\n",
2034 pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
2035 return -1;
2036 }
2037
2038 pj_strdup2_with_null(pool, &tmp, registration->client_uri);
2039 uri = pjsip_parse_uri(pool, tmp.ptr, tmp.slen, 0);
2040 if (!uri) {
2041 ast_log(LOG_ERROR, "Invalid client URI '%s' specified on outbound registration '%s'\n",
2043 pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
2044 return -1;
2045 }
2046
2047 pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
2048
2049 ast_assert(state->client_state->client == NULL);
2050 if (pjsip_regc_create(ast_sip_get_pjsip_endpoint(), state->client_state,
2052 &state->client_state->client) != PJ_SUCCESS) {
2053 return -1;
2054 }
2055
2057 pjsip_regc_set_transport(state->client_state->client, &selector);
2058
2060 pjsip_route_hdr route_set, *route;
2061 static const pj_str_t ROUTE_HNAME = { "Route", 5 };
2062 pj_str_t tmp;
2063
2064 pj_list_init(&route_set);
2065
2066 pj_strdup2_with_null(pjsip_regc_get_pool(state->client_state->client), &tmp,
2068 route = pjsip_parse_hdr(pjsip_regc_get_pool(state->client_state->client),
2069 &ROUTE_HNAME, tmp.ptr, tmp.slen, NULL);
2070 if (!route) {
2071 ast_sip_tpselector_unref(&selector);
2072 return -1;
2073 }
2074 pj_list_insert_nodes_before(&route_set, route);
2075
2076 pjsip_regc_set_route_set(state->client_state->client, &route_set);
2077 }
2078
2079 if (state->registration->line) {
2080 ast_generate_random_string(state->client_state->line, sizeof(state->client_state->line));
2081 }
2082
2084
2085 if (sip_dialog_create_contact(pjsip_regc_get_pool(state->client_state->client),
2086 &contact_uri, S_OR(registration->contact_user, "s"), &server_uri, &selector,
2087 state->client_state->line, registration->contact_header_params)) {
2088 ast_sip_tpselector_unref(&selector);
2089 return -1;
2090 }
2091
2092 ast_sip_tpselector_unref(&selector);
2093
2094 pj_cstr(&client_uri, registration->client_uri);
2095 if (pjsip_regc_init(state->client_state->client, &server_uri, &client_uri,
2096 &client_uri, 1, &contact_uri, registration->expiration) != PJ_SUCCESS) {
2097 return -1;
2098 }
2099
2100 return 0;
2101}
2102
2103/*! \brief Helper function which performs a single registration */
2105{
2107 struct sip_outbound_registration *registration = ao2_bump(state->registration);
2108 size_t i;
2109 int max_delay;
2110 pjsip_regc_info info;
2111
2112 /* Just in case the client state is being reused for this registration, free the auth information */
2113 ast_sip_auth_vector_destroy(&state->client_state->outbound_auths);
2114 ast_sip_security_mechanisms_vector_destroy(&state->client_state->security_mechanisms);
2115 ast_sip_security_mechanisms_vector_destroy(&state->client_state->server_security_mechanisms);
2116
2117 AST_VECTOR_INIT(&state->client_state->outbound_auths, AST_VECTOR_SIZE(&registration->outbound_auths));
2118 for (i = 0; i < AST_VECTOR_SIZE(&registration->outbound_auths); ++i) {
2119 char *name = ast_strdup(AST_VECTOR_GET(&registration->outbound_auths, i));
2120
2121 if (name && AST_VECTOR_APPEND(&state->client_state->outbound_auths, name)) {
2122 ast_free(name);
2123 }
2124 }
2125 ast_sip_security_mechanisms_vector_copy(&state->client_state->security_mechanisms,
2126 &registration->security_mechanisms);
2127 state->client_state->retry_interval = registration->retry_interval;
2128 state->client_state->forbidden_retry_interval = registration->forbidden_retry_interval;
2129 state->client_state->fatal_retry_interval = registration->fatal_retry_interval;
2130 state->client_state->max_retries = registration->max_retries;
2131 state->client_state->retries = 0;
2132 state->client_state->support_path = registration->support_path;
2133 state->client_state->support_outbound = registration->support_outbound;
2134 state->client_state->security_negotiation = registration->security_negotiation;
2135 state->client_state->auth_rejection_permanent = registration->auth_rejection_permanent;
2136 max_delay = registration->max_random_initial_delay;
2137
2138 /*
2139 * pjsip_regc_update_expires will remove the Expires header from the REGISTER request if the
2140 * expiration interval is re-set to the same value as the current interval. We want to avoid
2141 * this so we only call it if the interval has changed.
2142 */
2143 if (pjsip_regc_get_info(state->client_state->client, &info) == PJ_SUCCESS && info.interval != (unsigned) registration->expiration) {
2144 pjsip_regc_update_expires(state->client_state->client, registration->expiration);
2145 }
2146
2147 /* n mod 0 is undefined, so don't let that happen */
2148 schedule_registration(state->client_state, (max_delay ? ast_random() % max_delay : 0) + 1);
2149
2150 ao2_ref(registration, -1);
2151 ao2_ref(state, -1);
2152 return 0;
2153}
2154
2155/*! \brief Apply function which finds or allocates a state structure */
2156static int sip_outbound_registration_apply(const struct ast_sorcery *sorcery, void *obj)
2157{
2158 RAII_VAR(struct ao2_container *, states, ao2_global_obj_ref(current_states), ao2_cleanup);
2161 struct sip_outbound_registration *applied = obj;
2162
2163 if (!states) {
2164 /* Global container has gone. Likely shutting down. */
2165 return -1;
2166 }
2168
2169 ast_debug(4, "Applying configuration to outbound registration '%s'\n", ast_sorcery_object_get_id(applied));
2170
2171 if (ast_strlen_zero(applied->server_uri)) {
2172 ast_log(LOG_ERROR, "No server URI specified on outbound registration '%s'\n",
2173 ast_sorcery_object_get_id(applied));
2174 return -1;
2175 } else if (ast_sip_validate_uri_length(applied->server_uri)) {
2176 ast_log(LOG_ERROR, "Server URI or hostname length exceeds pjproject limit or is not a sip(s) uri: '%s'\n",
2177 ast_sorcery_object_get_id(applied));
2178 return -1;
2179 } else if (ast_strlen_zero(applied->client_uri)) {
2180 ast_log(LOG_ERROR, "No client URI specified on outbound registration '%s'\n",
2181 ast_sorcery_object_get_id(applied));
2182 return -1;
2183 } else if (ast_sip_validate_uri_length(applied->client_uri)) {
2184 ast_log(LOG_ERROR, "Client URI or hostname length exceeds pjproject limit or is not a sip(s) uri: '%s'\n",
2185 ast_sorcery_object_get_id(applied));
2186 return -1;
2187 } else if (applied->line && ast_strlen_zero(applied->endpoint)) {
2188 ast_log(LOG_ERROR, "Line support has been enabled on outbound registration '%s' without providing an endpoint\n",
2189 ast_sorcery_object_get_id(applied));
2190 return -1;
2191 } else if (!ast_strlen_zero(applied->endpoint) && !applied->line) {
2192 ast_log(LOG_ERROR, "An endpoint has been specified on outbound registration '%s' without enabling line support\n",
2193 ast_sorcery_object_get_id(applied));
2194 return -1;
2195 }
2196
2197 if (state && can_reuse_registration(state->registration, applied)) {
2198 ast_debug(4,
2199 "No change between old configuration and new configuration on outbound registration '%s'. Using previous state\n",
2200 ast_sorcery_object_get_id(applied));
2201
2202 /*
2203 * This is OK to replace without relinking the state in the
2204 * current_states container since state->registration and
2205 * applied have the same key.
2206 */
2207 ao2_lock(states);
2208 ao2_replace(state->registration, applied);
2209 ao2_unlock(states);
2210 return 0;
2211 }
2212
2213 if (!(new_state = sip_outbound_registration_state_alloc(applied))) {
2214 return -1;
2215 }
2216
2217 if (ast_sip_push_task_wait_serializer(new_state->client_state->serializer,
2219 return -1;
2220 }
2221
2222 if (ast_sip_push_task(new_state->client_state->serializer,
2224 ast_log(LOG_ERROR, "Failed to perform outbound registration on '%s'\n",
2225 ast_sorcery_object_get_id(new_state->registration));
2226 ao2_ref(new_state, -1);
2227 return -1;
2228 }
2229
2230 ao2_lock(states);
2231 if (state) {
2232 ao2_unlink(states, state);
2233 }
2234 ao2_link(states, new_state);
2235 ao2_unlock(states);
2236
2237 return 0;
2238}
2239
2240static int security_mechanism_to_str(const void *obj, const intptr_t *args, char **buf)
2241{
2242 const struct sip_outbound_registration *registration = obj;
2243
2245}
2246
2247static const char *security_negotiation_map[] = {
2249 [AST_SIP_SECURITY_NEG_MEDIASEC] = "mediasec",
2250};
2251
2252static int security_negotiation_to_str(const void *obj, const intptr_t *args, char **buf)
2253{
2254 const struct sip_outbound_registration *registration = obj;
2257 }
2258 return 0;
2259}
2260
2261static int security_mechanisms_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
2262{
2263 struct sip_outbound_registration *registration = obj;
2264
2265 return ast_sip_security_mechanism_vector_init(&registration->security_mechanisms, var->value);
2266}
2267
2268static int security_negotiation_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
2269{
2270 struct sip_outbound_registration *registration = obj;
2271
2272 return ast_sip_set_security_negotiation(&registration->security_negotiation, var->value);
2273}
2274
2275static int outbound_auth_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
2276{
2277 struct sip_outbound_registration *registration = obj;
2278
2279 return ast_sip_auth_vector_init(&registration->outbound_auths, var->value);
2280}
2281
2282static int outbound_auths_to_str(const void *obj, const intptr_t *args, char **buf)
2283{
2284 const struct sip_outbound_registration *registration = obj;
2285
2286 return ast_sip_auths_to_str(&registration->outbound_auths, buf);
2287}
2288
2289static int outbound_auths_to_var_list(const void *obj, struct ast_variable **fields)
2290{
2291 const struct sip_outbound_registration *registration = obj;
2292 int i;
2293 struct ast_variable *head = NULL;
2294
2295 for (i = 0; i < AST_VECTOR_SIZE(&registration->outbound_auths) ; i++) {
2296 ast_variable_list_append(&head, ast_variable_new("outbound_auth",
2297 AST_VECTOR_GET(&registration->outbound_auths, i), ""));
2298 }
2299
2300 if (head) {
2301 *fields = head;
2302 }
2303
2304 return 0;
2305}
2306
2307static int unregister_task(void *obj)
2308{
2310 struct pjsip_regc *client = state->client_state->client;
2311 pjsip_tx_data *tdata;
2312 pjsip_regc_info info;
2313
2314 pjsip_regc_get_info(client, &info);
2315 ast_debug(1, "Unregistering contacts with server '%s' from client '%s'\n",
2316 state->registration->server_uri, state->registration->client_uri);
2317
2318 cancel_registration(state->client_state);
2319
2320 if (pjsip_regc_unregister(client, &tdata) == PJ_SUCCESS
2321 && add_configured_supported_headers(state->client_state, tdata)) {
2322 registration_client_send(state->client_state, tdata);
2323 }
2324
2325 ao2_ref(state, -1);
2326 return 0;
2327}
2328
2330{
2331 ao2_ref(state, +1);
2332 if (ast_sip_push_task(state->client_state->serializer, unregister_task, state)) {
2333 ao2_ref(state, -1);
2334 return -1;
2335 }
2336
2337 return 0;
2338}
2339
2341{
2342 ao2_ref(state, +1);
2343 if (ast_sip_push_task(state->client_state->serializer, sip_outbound_registration_perform, state)) {
2344 ao2_ref(state, -1);
2345 return -1;
2346 }
2347
2348 return 0;
2349}
2350
2351static void unregister_all(void)
2352{
2353 struct ao2_container *states;
2354
2355 states = ao2_global_obj_ref(current_states);
2356 if (!states) {
2357 return;
2358 }
2359
2360 /* Clean out all the states and let sorcery handle recreating the registrations */
2362 ao2_ref(states, -1);
2363}
2364
2365static void reregister_all(void)
2366{
2369}
2370
2371static char *cli_complete_registration(const char *line, const char *word,
2372 int pos, int state)
2373{
2374 char *result = NULL;
2375 int wordlen;
2376 int which = 0;
2377 struct sip_outbound_registration *registration;
2379 struct ao2_iterator i;
2380
2381 if (pos != 3) {
2382 return NULL;
2383 }
2384
2385 wordlen = strlen(word);
2386 if (wordlen == 0 && ++which > state) {
2387 return ast_strdup("*all");
2388 }
2389
2392 if (!registrations) {
2393 return NULL;
2394 }
2395
2397 while ((registration = ao2_iterator_next(&i))) {
2398 const char *name = ast_sorcery_object_get_id(registration);
2399
2400 if (!strncasecmp(word, name, wordlen) && ++which > state) {
2402 }
2403
2404 ao2_ref(registration, -1);
2405 if (result) {
2406 break;
2407 }
2408 }
2410
2412 return result;
2413}
2414
2415static char *cli_unregister(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
2416{
2418 const char *registration_name;
2419
2420 switch (cmd) {
2421 case CLI_INIT:
2422 e->command = "pjsip send unregister";
2423 e->usage =
2424 "Usage: pjsip send unregister <registration> | *all\n"
2425 " Unregisters the specified (or all) outbound registration(s) "
2426 "and stops future registration attempts.\n";
2427 return NULL;
2428 case CLI_GENERATE:
2429 return cli_complete_registration(a->line, a->word, a->pos, a->n);
2430 }
2431
2432 if (a->argc != 4) {
2433 return CLI_SHOWUSAGE;
2434 }
2435
2436 registration_name = a->argv[3];
2437
2438 if (strcmp(registration_name, "*all") == 0) {
2440 ast_cli(a->fd, "Unregister all queued\n");
2441 return CLI_SUCCESS;
2442 }
2443
2444 state = get_state(registration_name);
2445 if (!state) {
2446 ast_cli(a->fd, "Unable to retrieve registration %s\n", registration_name);
2447 return CLI_FAILURE;
2448 }
2449
2450 if (queue_unregister(state)) {
2451 ast_cli(a->fd, "Failed to queue unregistration\n");
2452 }
2453
2454 ao2_ref(state, -1);
2455 return CLI_SUCCESS;
2456}
2457
2458static char *cli_register(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
2459{
2461 const char *registration_name;
2462
2463 switch (cmd) {
2464 case CLI_INIT:
2465 e->command = "pjsip send register";
2466 e->usage =
2467 "Usage: pjsip send register <registration> | *all \n"
2468 " Unregisters the specified (or all) outbound "
2469 "registration(s) then starts registration(s) and schedules re-registrations.\n";
2470 return NULL;
2471 case CLI_GENERATE:
2472 return cli_complete_registration(a->line, a->word, a->pos, a->n);
2473 }
2474
2475 if (a->argc != 4) {
2476 return CLI_SHOWUSAGE;
2477 }
2478
2479 registration_name = a->argv[3];
2480
2481 if (strcmp(registration_name, "*all") == 0) {
2483 ast_cli(a->fd, "Re-register all queued\n");
2484 return CLI_SUCCESS;
2485 }
2486
2487 state = get_state(registration_name);
2488 if (!state) {
2489 ast_cli(a->fd, "Unable to retrieve registration %s\n", registration_name);
2490 return CLI_FAILURE;
2491 }
2492
2493 /* We need to serialize the unregister and register so they need
2494 * to be queued as separate tasks.
2495 */
2496 if (queue_unregister(state)) {
2497 ast_cli(a->fd, "Failed to queue unregistration\n");
2498 } else if (queue_register(state)) {
2499 ast_cli(a->fd, "Failed to queue registration\n");
2500 }
2501
2502 ao2_ref(state, -1);
2503 return CLI_SUCCESS;
2504}
2505
2506static int ami_unregister(struct mansession *s, const struct message *m)
2507{
2508 const char *registration_name = astman_get_header(m, "Registration");
2510
2511 if (ast_strlen_zero(registration_name)) {
2512 astman_send_error(s, m, "Registration parameter missing.");
2513 return 0;
2514 }
2515
2516 if (strcmp(registration_name, "*all") == 0) {
2518 astman_send_ack(s, m, "Unregistrations queued.");
2519 return 0;
2520 }
2521
2522 state = get_state(registration_name);
2523 if (!state) {
2524 astman_send_error(s, m, "Unable to retrieve registration entry\n");
2525 return 0;
2526 }
2527
2528 if (queue_unregister(state)) {
2529 astman_send_ack(s, m, "Failed to queue unregistration");
2530 } else {
2531 astman_send_ack(s, m, "Unregistration sent");
2532 }
2533
2534 ao2_ref(state, -1);
2535 return 0;
2536}
2537
2538static int ami_register(struct mansession *s, const struct message *m)
2539{
2540 const char *registration_name = astman_get_header(m, "Registration");
2542
2543 if (ast_strlen_zero(registration_name)) {
2544 astman_send_error(s, m, "Registration parameter missing.");
2545 return 0;
2546 }
2547
2548 if (strcmp(registration_name, "*all") == 0) {
2550 astman_send_ack(s, m, "Reregistrations queued.");
2551 return 0;
2552 }
2553
2554 state = get_state(registration_name);
2555 if (!state) {
2556 astman_send_error(s, m, "Unable to retrieve registration entry\n");
2557 return 0;
2558 }
2559
2560 /* We need to serialize the unregister and register so they need
2561 * to be queued as separate tasks.
2562 */
2563 if (queue_unregister(state)) {
2564 astman_send_ack(s, m, "Failed to queue unregistration");
2565 } else if (queue_register(state)) {
2566 astman_send_ack(s, m, "Failed to queue unregistration");
2567 } else {
2568 astman_send_ack(s, m, "Reregistration sent");
2569 }
2570
2571 ao2_ref(state, -1);
2572 return 0;
2573}
2574
2581
2583{
2584 struct sip_ami_outbound *ami = obj;
2585 struct ast_str *buf;
2587
2588 buf = ast_sip_create_ami_event("OutboundRegistrationDetail", ami->ami);
2589 if (!buf) {
2590 return -1;
2591 }
2592
2594
2596 pjsip_regc_info info;
2597
2598 if (state->client_state->status == SIP_REGISTRATION_REGISTERED) {
2599 ++ami->registered;
2600 } else {
2601 ++ami->not_registered;
2602 }
2603
2604 ast_str_append(&buf, 0, "Status: %s\r\n",
2605 sip_outbound_registration_status_str(state->client_state->status));
2606
2607 pjsip_regc_get_info(state->client_state->client, &info);
2608 ast_str_append(&buf, 0, "NextReg: %d\r\n", info.next_reg);
2609 ao2_ref(state, -1);
2610 }
2611
2612 astman_append(ami->ami->s, "%s\r\n", ast_str_buffer(buf));
2613 ast_free(buf);
2614
2616}
2617
2618static int ami_outbound_registration_detail(void *obj, void *arg, int flags)
2619{
2620 struct sip_ami_outbound *ami = arg;
2621
2622 ami->registration = obj;
2624}
2625
2627 const struct message *m)
2628{
2629 struct ast_sip_ami ami = { .s = s, .m = m, .action_id = astman_get_header(m, "ActionID"), };
2630 struct sip_ami_outbound ami_outbound = { .ami = &ami };
2631 struct ao2_container *regs;
2632
2633 regs = get_registrations();
2634 if (!regs) {
2635 astman_send_error(s, m, "Unable to retrieve "
2636 "outbound registrations\n");
2637 return -1;
2638 }
2639
2640 astman_send_listack(s, m, "Following are Events for each Outbound registration",
2641 "start");
2642
2644
2645 astman_send_list_complete_start(s, m, "OutboundRegistrationDetailComplete",
2646 ami_outbound.registered + ami_outbound.not_registered);
2647 astman_append(s,
2648 "Registered: %d\r\n"
2649 "NotRegistered: %d\r\n",
2650 ami_outbound.registered,
2651 ami_outbound.not_registered);
2653
2654 ao2_ref(regs, -1);
2655 return 0;
2656}
2657
2658static struct ao2_container *cli_get_container(const char *regex)
2659{
2661 struct ao2_container *s_container;
2662
2664 if (!container) {
2665 return NULL;
2666 }
2667
2670 if (!s_container) {
2671 return NULL;
2672 }
2673
2674 if (ao2_container_dup(s_container, container, 0)) {
2675 ao2_ref(s_container, -1);
2676 return NULL;
2677 }
2678
2679 return s_container;
2680}
2681
2683{
2685
2686 return 0;
2687}
2688
2689static void *cli_retrieve_by_id(const char *id)
2690{
2691 struct ao2_container *states;
2692 void *obj = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "registration", id);
2693
2694 if (!obj) {
2695 /* if the object no longer exists then remove its state */
2696 states = ao2_global_obj_ref(current_states);
2697 if (states) {
2699 ao2_ref(states, -1);
2700 }
2701 }
2702
2703 return obj;
2704}
2705
2706static int cli_print_header(void *obj, void *arg, int flags)
2707{
2708 struct ast_sip_cli_context *context = arg;
2709
2710 ast_assert(context->output_buffer != NULL);
2711
2712 ast_str_append(&context->output_buffer, 0,
2713 " <Registration/ServerURI..............................> <Auth....................> <Status.......>\n");
2714
2715 return 0;
2716}
2717
2718static int cli_print_body(void *obj, void *arg, int flags)
2719{
2720 struct sip_outbound_registration *registration = obj;
2721 struct ast_sip_cli_context *context = arg;
2722 const char *id = ast_sorcery_object_get_id(registration);
2724 int expsecs;
2725#define REGISTRATION_URI_FIELD_LEN 53
2726
2727 ast_assert(context->output_buffer != NULL);
2728 expsecs = state ? state->client_state->registration_expires - ((int) time(NULL)) : 0;
2729
2730 ast_str_append(&context->output_buffer, 0, " %-s/%-*.*s %-26s %-16s %s%d%s\n",
2731 id,
2732 (int) (REGISTRATION_URI_FIELD_LEN - strlen(id)),
2733 (int) (REGISTRATION_URI_FIELD_LEN - strlen(id)),
2737 : "n/a",
2738 (state ? sip_outbound_registration_status_str(state->client_state->status) : "Unregistered"),
2739 state ? " (exp. " : "", abs(expsecs), state ? (expsecs < 0 ? "s ago)" : "s)") : "");
2741
2742 if (context->show_details
2743 || (context->show_details_only_level_0 && context->indent_level == 0)) {
2744 ast_str_append(&context->output_buffer, 0, "\n");
2746 }
2747
2748 return 0;
2749}
2750
2751/*
2752 * A function pointer to callback needs to be within the
2753 * module in order to avoid problems with an undefined
2754 * symbol when the module is loaded.
2755 */
2756static char *my_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
2757{
2758 return ast_sip_cli_traverse_objects(e, cmd, a);
2759}
2760
2762 AST_CLI_DEFINE(cli_unregister, "Unregisters outbound registration target"),
2763 AST_CLI_DEFINE(cli_register, "Registers an outbound registration target"),
2764 AST_CLI_DEFINE(my_cli_traverse_objects, "List PJSIP Registrations",
2765 .command = "pjsip list registrations",
2766 .usage = "Usage: pjsip list registrations [ like <pattern> ]\n"
2767 " List the configured PJSIP Registrations\n"
2768 " Optional regular expression pattern is used to filter the list.\n"),
2769 AST_CLI_DEFINE(my_cli_traverse_objects, "Show PJSIP Registrations",
2770 .command = "pjsip show registrations",
2771 .usage = "Usage: pjsip show registrations [ like <pattern> ]\n"
2772 " Show the configured PJSIP Registrations\n"
2773 " Optional regular expression pattern is used to filter the list.\n"),
2774 AST_CLI_DEFINE(my_cli_traverse_objects, "Show PJSIP Registration",
2775 .command = "pjsip show registration",
2776 .usage = "Usage: pjsip show registration <id>\n"
2777 " Show the configured PJSIP Registration\n"),
2778};
2779
2781
2782static void auth_observer(const char *type)
2783{
2784 struct sip_outbound_registration *registration;
2786 struct ao2_container *regs;
2787 const char *registration_id;
2788 struct ao2_iterator i;
2789
2790 ast_debug(4, "Auths updated. Checking for any outbound registrations that are in permanent rejected state so they can be retried\n");
2791
2792 regs = ast_sorcery_retrieve_by_fields(ast_sip_get_sorcery(), "registration",
2794 if (!regs || ao2_container_count(regs) == 0) {
2795 ao2_cleanup(regs);
2796 return;
2797 }
2798
2799 i = ao2_iterator_init(regs, 0);
2800 for (; (registration = ao2_iterator_next(&i)); ao2_ref(registration, -1)) {
2801 registration_id = ast_sorcery_object_get_id(registration);
2802 state = get_state(registration_id);
2803 if (state && state->client_state->status == SIP_REGISTRATION_REJECTED_PERMANENT) {
2804 ast_debug(4, "Trying outbound registration '%s' again\n", registration_id);
2805
2806 if (ast_sip_push_task(state->client_state->serializer,
2808 ast_log(LOG_ERROR, "Failed to perform outbound registration on '%s'\n", registration_id);
2809 ao2_ref(state, -1);
2810 }
2811 }
2813 }
2815 ao2_cleanup(regs);
2816}
2817
2821
2822static int check_state(void *obj, void *arg, int flags)
2823{
2825 struct sip_outbound_registration *registration;
2826
2827 registration = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "registration",
2828 ast_sorcery_object_get_id(state->registration));
2829 if (!registration) {
2830 /* This is a dead registration */
2831 return CMP_MATCH;
2832 }
2833
2834 ao2_ref(registration, -1);
2835 return 0;
2836}
2837
2838/*!
2839 * \internal
2840 * \brief Observer to purge dead registration states.
2841 *
2842 * \param name Module name owning the sorcery instance.
2843 * \param sorcery Instance being observed.
2844 * \param object_type Name of object being observed.
2845 * \param reloaded Non-zero if the object is being reloaded.
2846 */
2847static void registration_loaded_observer(const char *name, const struct ast_sorcery *sorcery, const char *object_type, int reloaded)
2848{
2849 struct ao2_container *states;
2850
2851 if (strcmp(object_type, "registration")) {
2852 /* Not interested */
2853 return;
2854 }
2855
2856 states = ao2_global_obj_ref(current_states);
2857 if (!states) {
2858 /* Global container has gone. Likely shutting down. */
2859 return;
2860 }
2861
2862 /*
2863 * Refresh the current configured registrations. We don't need to hold
2864 * onto the objects, as the apply handler will cause their states to
2865 * be created appropriately.
2866 */
2868
2869 /* Now to purge dead registrations. */
2871 ao2_ref(states, -1);
2872}
2873
2877
2878static void registration_deleted_observer(const void *obj)
2879{
2880 const struct sip_outbound_registration *registration = obj;
2881 struct ao2_container *states;
2882
2883 states = ao2_global_obj_ref(current_states);
2884 if (!states) {
2885 /* Global container has gone. Likely shutting down. */
2886 return;
2887 }
2888
2890
2891 ao2_ref(states, -1);
2892}
2893
2897
2899{
2900 /* This callback is only concerned with network change messages from the system topic. */
2902 return;
2903 }
2904 ast_debug(3, "Received network change event\n");
2905
2907}
2908
2909static int unload_module(void)
2910{
2911 int remaining;
2912
2914
2915 ast_manager_unregister("PJSIPShowRegistrationsOutbound");
2916 ast_manager_unregister("PJSIPUnregister");
2917 ast_manager_unregister("PJSIPRegister");
2918
2922
2924
2927
2929
2930 ao2_global_obj_release(current_states);
2931
2933
2934 /* Wait for registration serializers to get destroyed. */
2935 ast_debug(2, "Waiting for registration transactions to complete for unload.\n");
2937 if (remaining) {
2938 /*
2939 * NOTE: We probably have a sip_outbound_registration_client_state
2940 * ref leak if the remaining count cannot reach zero after a few
2941 * minutes of trying to unload.
2942 */
2943 ast_log(LOG_WARNING, "Unload incomplete. Could not stop %d outbound registrations. Try again later.\n",
2944 remaining);
2945 return -1;
2946 }
2947
2948 ast_debug(2, "Successful shutdown.\n");
2949
2952
2953 return 0;
2954}
2955
2956static int load_module(void)
2957{
2958 struct ao2_container *new_states;
2959
2961 if (!shutdown_group) {
2963 }
2964
2965 /* Because we delegate to unload_module() in our error paths, everything we do here
2966 has to be idempotent. Due to the way we define our CLI handlers (specifically
2967 setting the `command` and `usage` members to statically allocated strings) we
2968 _must_ register them for them to later be safely unregistered. */
2970
2971 /* Create outbound registration states container. */
2974 if (!new_states) {
2975 ast_log(LOG_ERROR, "Unable to allocate registration states container\n");
2976 unload_module();
2978 }
2980 ao2_ref(new_states, -1);
2981
2982 /*
2983 * Register sorcery object descriptions.
2984 */
2985 ast_sorcery_apply_config(ast_sip_get_sorcery(), "res_pjsip_outbound_registration");
2986 ast_sorcery_apply_default(ast_sip_get_sorcery(), "registration", "config", "pjsip.conf,criteria=type=registration");
2987
2989 unload_module();
2991 }
2992
2993 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "type", "", OPT_NOOP_T, 0, 0);
2995 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "client_uri", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct sip_outbound_registration, client_uri));
2996 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "contact_user", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct sip_outbound_registration, contact_user));
2997 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "contact_header_params", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct sip_outbound_registration, contact_header_params));
2998 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "transport", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct sip_outbound_registration, transport));
2999 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct sip_outbound_registration, outbound_proxy));
3000 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "expiration", "3600", OPT_UINT_T, 0, FLDSET(struct sip_outbound_registration, expiration));
3001 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "max_random_initial_delay", "10", OPT_UINT_T, 0, FLDSET(struct sip_outbound_registration, max_random_initial_delay));
3002 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "retry_interval", "60", OPT_UINT_T, 0, FLDSET(struct sip_outbound_registration, retry_interval));
3003 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "forbidden_retry_interval", "0", OPT_UINT_T, 0, FLDSET(struct sip_outbound_registration, forbidden_retry_interval));
3004 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "fatal_retry_interval", "0", OPT_UINT_T, 0, FLDSET(struct sip_outbound_registration, fatal_retry_interval));
3006 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "auth_rejection_permanent", "yes", OPT_BOOL_T, 1, FLDSET(struct sip_outbound_registration, auth_rejection_permanent));
3008 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "support_path", "no", OPT_BOOL_T, 1, FLDSET(struct sip_outbound_registration, support_path));
3009 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "support_outbound", "no", OPT_YESNO_T, 1, FLDSET(struct sip_outbound_registration, support_outbound));
3012 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "line", "no", OPT_BOOL_T, 1, FLDSET(struct sip_outbound_registration, line));
3013 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "endpoint", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct sip_outbound_registration, endpoint));
3014 ast_sorcery_object_field_register(ast_sip_get_sorcery(), "registration", "user_agent", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct sip_outbound_registration, user_agent));
3015
3016 /*
3017 * Register sorcery observers.
3018 */
3023 || ast_sorcery_observer_add(ast_sip_get_sorcery(), "registration",
3025 ast_log(LOG_ERROR, "Unable to register observers.\n");
3026 unload_module();
3028 }
3029
3030 /* Register how this module identifies endpoints. */
3032
3033 /* Register CLI commands. */
3035 if (!cli_formatter) {
3036 ast_log(LOG_ERROR, "Unable to allocate memory for cli formatter\n");
3037 unload_module();
3039 }
3040 cli_formatter->name = "registration";
3048
3049 /* Register AMI actions. */
3053
3054 /* Clear any previous statsd gauges in case we weren't shutdown cleanly */
3055 ast_statsd_log("PJSIP.registrations.count", AST_STATSD_GAUGE, 0);
3056 ast_statsd_log("PJSIP.registrations.state.Registered", AST_STATSD_GAUGE, 0);
3057 ast_statsd_log("PJSIP.registrations.state.Unregistered", AST_STATSD_GAUGE, 0);
3058 ast_statsd_log("PJSIP.registrations.state.Rejected", AST_STATSD_GAUGE, 0);
3059
3060 /* Load configuration objects */
3062
3067
3069}
3070
3071static int reload_module(void)
3072{
3074 return 0;
3075}
3076
3077AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP Outbound Registration Support",
3078 .support_level = AST_MODULE_SUPPORT_CORE,
3079 .load = load_module,
3081 .unload = unload_module,
3082 .load_pri = AST_MODPRI_APP_DEPEND,
3083 .requires = "res_pjsip",
3084 .optional_modules = "res_statsd",
void ast_cli_unregister_multiple(void)
Definition ael_main.c:408
jack_status_t status
Definition app_jack.c:149
const char * str
Definition app_jack.c:150
#define var
Definition ast_expr2f.c:605
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition astmm.h:267
#define ast_malloc(len)
A wrapper for malloc()
Definition astmm.h:191
#define ast_log
Definition astobj2.c:42
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags)
Copy all object references in the src container into the dest container.
#define ao2_iterator_next(iter)
Definition astobj2.h:1911
#define AO2_GLOBAL_OBJ_STATIC(name)
Define a global object holder to be used to hold an ao2 object, statically initialized.
Definition astobj2.h:847
#define ao2_link(container, obj)
Add an object to a container.
Definition astobj2.h:1532
@ CMP_MATCH
Definition astobj2.h:1027
@ CMP_STOP
Definition astobj2.h:1028
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition astobj2.h:367
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition astobj2.h:363
#define ao2_global_obj_replace_unref(holder, obj)
Replace an ao2 object in the global holder, throwing away any old object.
Definition astobj2.h:901
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition astobj2.h:1693
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_cleanup(obj)
Definition astobj2.h:1934
#define ao2_unlink(container, obj)
Remove an object from a container.
Definition astobj2.h:1578
int() ao2_callback_fn(void *obj, void *arg, int flags)
Type of a generic callback function.
Definition astobj2.h:1226
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition astobj2.h:918
#define ao2_find(container, arg, flags)
Definition astobj2.h:1736
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_unlock(a)
Definition astobj2.h:729
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition astobj2.h:501
#define ao2_lock(a)
Definition astobj2.h:717
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition astobj2.h:404
#define ao2_global_obj_release(holder)
Release the ao2 object held in the global holder.
Definition astobj2.h:859
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition astobj2.h:480
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
@ OBJ_SEARCH_PARTIAL_KEY
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition astobj2.h:1116
@ OBJ_SEARCH_OBJECT
The arg parameter is an object of the same type.
Definition astobj2.h:1087
@ OBJ_NODATA
Definition astobj2.h:1044
@ OBJ_SEARCH_MASK
Search option field mask.
Definition astobj2.h:1072
@ OBJ_MULTIPLE
Definition astobj2.h:1049
@ OBJ_UNLINK
Definition astobj2.h:1039
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition astobj2.h:1101
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition astobj2.h:1327
#define ao2_alloc(data_size, destructor_fn)
Definition astobj2.h:409
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Definition astobj2.h:1303
static PGresult * result
Definition cel_pgsql.c:84
static int max_retries
Definition chan_iax2.c:369
static const char type[]
static struct ast_sorcery * sorcery
static struct ast_channel * callback(struct ast_channelstorage_instance *driver, ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags, int rdlock)
Standard Command Line Interface.
#define CLI_SHOWUSAGE
Definition cli.h:45
#define CLI_SUCCESS
Definition cli.h:44
#define AST_CLI_DEFINE(fn, txt,...)
Definition cli.h:197
void ast_cli(int fd, const char *fmt,...)
Definition clicompat.c:6
@ CLI_INIT
Definition cli.h:152
@ CLI_GENERATE
Definition cli.h:153
#define CLI_FAILURE
Definition cli.h:46
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition cli.h:265
short word
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
@ OPT_UINT_T
Type for default option handler for unsigned integers.
@ OPT_NOOP_T
Type for a default handler that should do nothing.
@ OPT_BOOL_T
Type for default option handler for bools (ast_true/ast_false)
@ OPT_YESNO_T
Type for default option handler for bools (ast_true/ast_false)
@ OPT_STRINGFIELD_T
Type for default option handler for stringfields.
char buf[BUFSIZE]
Definition eagi_proxy.c:66
#define abs(x)
Definition f2c.h:195
static const char name[]
Definition format_mp3.c:68
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
void astman_send_listack(struct mansession *s, const struct message *m, char *msg, char *listflag)
Send ack in manager transaction to begin a list.
Definition manager.c:1963
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition manager.c:1921
void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)
Start the list complete event.
Definition manager.c:1999
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition manager.c:1953
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
Definition manager.c:1582
void astman_send_list_complete_end(struct mansession *s)
End the list complete event.
Definition manager.c:2007
void astman_append(struct mansession *s, const char *fmt,...)
Definition manager.c:1842
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition manager.c:7792
#define ast_sip_push_task(serializer, sip_task, task_data)
Definition res_pjsip.h:2126
struct ast_taskprocessor * ast_sip_create_serializer_group(const char *name, struct ast_serializer_shutdown_group *shutdown_group)
Create a new serializer for SIP tasks.
Definition res_pjsip.c:2132
#define ast_sip_push_task_wait_serializer(serializer, sip_task, task_data)
Definition res_pjsip.h:2221
#define ast_sip_push_task_wait_servant(serializer, sip_task, task_data)
Definition res_pjsip.h:2165
#define ast_variable_new(name, value, filename)
#define ast_variable_list_append(head, new_var)
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition extconf.c:1260
#define DEBUG_ATLEAST(level)
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_DEBUG
#define LOG_ERROR
#define LOG_NOTICE
#define LOG_WARNING
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition json.c:73
struct ast_json * ast_json_load_string(const char *input, struct ast_json_error *error)
Parse null terminated string into a JSON object or array.
Definition json.c:567
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition json.c:283
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition json.c:407
#define EVENT_FLAG_REPORTING
Definition manager.h:84
#define EVENT_FLAG_SYSTEM
Definition manager.h:75
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition manager.h:193
Asterisk module definitions.
@ AST_MODFLAG_LOAD_ORDER
Definition module.h:331
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition module.h:557
@ AST_MODPRI_APP_DEPEND
Definition module.h:342
@ AST_MODULE_SUPPORT_CORE
Definition module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition module.h:46
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition module.h:78
Core PBX routines and definitions.
int ast_func_read(struct ast_channel *chan, const char *function, char *workspace, size_t len)
executes a read operation on a function
int ast_func_write(struct ast_channel *chan, const char *function, const char *value)
executes a write operation on a function
static struct stasis_subscription * sub
Statsd channel stats. Exmaple of how to subscribe to Stasis events.
static char url[512]
static int reload(void)
struct ao2_container * container
Definition res_fax.c:603
struct pjsip_param * ast_sip_pjsip_uri_get_other_param(pjsip_uri *uri, const pj_str_t *param_str)
Find an 'other' SIP/SIPS URI parameter by name.
Definition res_pjsip.c:3531
void ast_sip_header_to_security_mechanism(const pjsip_generic_string_hdr *hdr, struct ast_sip_security_mechanism_vector *security_mechanisms)
Append to security mechanism vector from SIP header.
int ast_sip_set_security_negotiation(enum ast_sip_security_negotiation *security_negotiation, const char *val)
Set the security negotiation based on a given string.
void ast_sip_security_mechanisms_vector_copy(struct ast_sip_security_mechanism_vector *dst, const struct ast_sip_security_mechanism_vector *src)
Duplicate a security mechanism.
int ast_sip_transport_state_set_transport(const char *transport_name, pjsip_transport *transport)
Sets the PJSIP transport on a child transport.
void ast_sip_cleanup_auths(struct ast_sip_auth *auths[], size_t num_auths)
Clean up retrieved auth structures from memory.
int ast_sip_format_auths_ami(const struct ast_sip_auth_vector *auths, struct ast_sip_ami *ami)
Format auth details for AMI.
int ast_sip_create_request_with_auth(const struct ast_sip_auth_vector *auths, pjsip_rx_data *challenge, pjsip_tx_data *tdata, pjsip_tx_data **new_request)
Create a response to an authentication challenge.
Definition res_pjsip.c:208
int ast_sip_auths_to_str(const struct ast_sip_auth_vector *auths, char **buf)
Converts an auths array to a string of comma separated values.
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition res_pjsip.c:518
int ast_sip_register_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier)
Register a SIP endpoint identifier.
Definition res_pjsip.c:304
#define AST_SIP_MAKE_REMOTE_IPADDR_PORT_STR(_transport, _dest)
Fill a buffer with a pjsip transport's remote ip address and port.
Definition res_pjsip.h:91
int ast_sip_retrieve_auths(const struct ast_sip_auth_vector *auths, struct ast_sip_auth **out)
Retrieve relevant SIP auth structures from sorcery.
void ast_sip_service_route_vector_destroy(struct ast_sip_service_route_vector *service_routes)
Destroy a vector of service routes.
void ast_sip_unregister_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier)
Unregister a SIP endpoint identifier.
Definition res_pjsip.c:309
void ast_copy_pj_str(char *dest, const pj_str_t *src, size_t size)
Copy a pj_str_t into a standard character buffer.
Definition res_pjsip.c:2221
void ast_sip_security_mechanisms_vector_destroy(struct ast_sip_security_mechanism_vector *security_mechanisms)
Free contents of a security mechanism vector.
void ast_sip_transport_monitor_unregister_all(ast_transport_monitor_shutdown_cb cb, void *data, ast_transport_monitor_data_matcher matches)
Unregister a transport shutdown monitor from all reliable transports.
enum ast_transport_monitor_reg ast_sip_transport_monitor_register_replace_key(const char *transport_key, ast_transport_monitor_shutdown_cb cb, void *ao2_data, ast_transport_monitor_data_matcher matches)
Register a reliable transport shutdown monitor callback replacing any duplicate.
int ast_sip_security_mechanisms_to_str(const struct ast_sip_security_mechanism_vector *security_mechanisms, int add_qvalue, char **buf)
Writes the security mechanisms of an endpoint into a buffer as a string and returns the buffer.
#define IP6ADDR_COLON_PORT_BUFLEN
Definition res_pjsip.h:83
void ast_sip_tpselector_unref(pjsip_tpselector *selector)
Unreference a pjsip_tpselector.
Definition res_pjsip.c:921
struct ast_sip_service_route_vector * ast_sip_service_route_vector_alloc(void)
Allocate a vector of service routes.
int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf)
Converts a sorcery object to a string of object properties.
@ AST_SIP_AUTH_TYPE_GOOGLE_OAUTH
Definition res_pjsip.h:585
ast_transport_monitor_reg
Definition res_pjsip.h:4178
struct ao2_container * ast_sip_location_retrieve_contacts_from_aor_list(const char *aor_list)
Retrieve all contacts from a list of AORs.
Definition location.c:335
void ast_sip_remove_headers_by_name_and_value(pjsip_msg *msg, const pj_str_t *hdr_name, const char *value)
Removes all headers of a specific name and value from a pjsip_msg.
void ast_sip_auth_vector_destroy(struct ast_sip_auth_vector *vector)
Free contents of an auth vector.
ast_sip_security_negotiation
The kind of security negotiation.
Definition res_pjsip.h:353
@ AST_SIP_SECURITY_NEG_MEDIASEC
Definition res_pjsip.h:357
@ AST_SIP_SECURITY_NEG_NONE
Definition res_pjsip.h:355
int ast_sip_set_tpselector_from_transport_name(const char *transport_name, pjsip_tpselector *selector)
Sets pjsip_tpselector from ast_sip_transport.
Definition res_pjsip.c:891
struct ast_str * ast_sip_create_ami_event(const char *event, struct ast_sip_ami *ami)
Creates a string to store AMI event data in.
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
struct ast_sip_contact_status * ast_sip_get_contact_status(const struct ast_sip_contact *contact)
Retrieve the current status for a contact.
int ast_sip_security_mechanism_vector_init(struct ast_sip_security_mechanism_vector *security_mechanism, const char *value)
Initialize security mechanism vector from string of security mechanisms.
int ast_sip_auth_vector_init(struct ast_sip_auth_vector *vector, const char *auth_names)
Initialize an auth vector with the configured values.
void ast_sip_transport_monitor_unregister_key(const char *transport_key, ast_transport_monitor_shutdown_cb cb, void *data, ast_transport_monitor_data_matcher matches)
Unregister a reliable transport shutdown monitor.
int ast_sip_add_security_headers(struct ast_sip_security_mechanism_vector *security_mechanisms, const char *header_name, int add_qval, pjsip_tx_data *tdata)
Add security headers to transmission data.
int ast_sip_transport_state_set_preferred_identity(const char *transport_name, const char *identity)
Sets the P-Preferred-Identity on a child transport.
int ast_sip_failover_request(pjsip_tx_data *tdata)
Set a request to use the next value in the list of resolved addresses.
Definition res_pjsip.c:1838
int ast_sip_transport_state_set_service_routes(const char *transport_name, struct ast_sip_service_route_vector *service_routes)
Sets the service routes on a child transport.
int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Unregisters a CLI formatter.
Definition pjsip_cli.c:326
int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags)
Prints a sorcery object's ast_variable list.
Definition pjsip_cli.c:36
char * ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition pjsip_cli.c:109
int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Registers a CLI formatter.
Definition pjsip_cli.c:310
static struct ao2_container * new_states
Used on [re]loads to hold new state data.
static int ami_show_outbound_registrations(struct mansession *s, const struct message *m)
static const struct ast_sorcery_instance_observer observer_callbacks_registrations
static int sip_outbound_registration_regc_alloc(void *data)
Helper function that allocates a pjsip registration client and configures it.
static void save_response_fields_to_transport(struct registration_response *response)
static void * sip_outbound_registration_alloc(const char *name)
Allocator function for registration information.
#define REREGISTER_BUFFER_TIME
Amount of buffer time (in seconds) before expiration that we re-register at.
static void unregister_all(void)
#define LINE_PARAMETER_SIZE
Size of the buffer for creating a unique string for the line.
static int queue_unregister(struct sip_outbound_registration_state *state)
static void registration_deleted_observer(const void *obj)
static int cli_print_header(void *obj, void *arg, int flags)
static struct ast_serializer_shutdown_group * shutdown_group
static int cli_iterator(void *container, ao2_callback_fn callback, void *args)
static char * cli_register(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define REGISTRATION_URI_FIELD_LEN
static int registration_state_cmp(void *obj, void *arg, int flags)
comparator function for state objects
static int handle_registration_response(void *data)
Callback function for handling a response to a registration attempt.
static struct pjsip_param * get_uri_option_line(const void *uri)
static void add_security_headers(struct sip_outbound_registration_client_state *client_state, pjsip_tx_data *tdata)
Adds security negotiation mechanisms of outbound registration client state as Security headers to tda...
static int handle_client_registration(void *data)
Callback function for registering.
#define DEFAULT_STATE_BUCKETS
Default number of state container buckets.
static void sip_outbound_registration_timer_cb(pj_timer_heap_t *timer_heap, struct pj_timer_entry *entry)
Timer callback function, used just for registrations.
static const struct ast_sorcery_observer registration_observer
static int queue_register(struct sip_outbound_registration_state *state)
static int sip_dialog_create_contact(pj_pool_t *pool, pj_str_t *contact, const char *user, const pj_str_t *target, pjsip_tpselector *selector, const char *line, const char *header_params)
Helper function which populates a pj_str_t with a contact header.
static int outbound_auth_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
#define MAX_UNLOAD_TIMEOUT_TIME
static void registration_transport_monitor_setup(const char *transport_key, const char *registration_name)
static int ami_register(struct mansession *s, const struct message *m)
static pj_str_t PATH_NAME
static int contact_has_security_mechanisms(void *obj, void *arg, int flags)
static int ami_unregister(struct mansession *s, const struct message *m)
static void registration_transport_shutdown_cb(void *obj)
static void sip_outbound_registration_state_destroy(void *obj)
Destructor function for registration state.
static const char * fetch_google_access_token(const struct ast_sip_auth *auth)
Get google oauth2 access token using refresh token.
static int contact_add_security_headers_to_status(void *obj, void *arg, int flags)
static int security_negotiation_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
static struct sip_outbound_registration_state * get_state(const char *id)
static int security_mechanisms_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
static void registration_response_destroy(void *obj)
Registration response structure destructor.
static struct ast_sip_endpoint * line_identify(pjsip_rx_data *rdata)
Endpoint identifier which uses the 'line' parameter to establish a relationship to an outgoing regist...
static void sip_outbound_registration_client_state_destroy(void *obj)
Destructor function for client registration state.
static int reload_module(void)
static int reregister_immediately_cb(void *obj)
static int security_mechanism_to_str(const void *obj, const intptr_t *args, char **buf)
static int add_to_supported_header(pjsip_tx_data *tdata, pj_str_t *name)
Helper function to add string to Supported header.
static struct sip_outbound_registration_state * sip_outbound_registration_state_alloc(struct sip_outbound_registration *registration)
Allocator function for registration state.
static void network_change_stasis_cb(void *data, struct stasis_subscription *sub, struct stasis_message *message)
static int sip_outbound_registration_is_temporal(unsigned int code, struct sip_outbound_registration_client_state *client_state)
Helper function which determines if a response code is temporal or not.
static int handle_client_state_destruction(void *data)
Callback function for unregistering (potentially) and destroying state.
static void auth_observer(const char *type)
static const char * sip_outbound_registration_status_str(enum sip_outbound_registration_status state)
static int sip_outbound_registration_apply(const struct ast_sorcery *sorcery, void *obj)
Apply function which finds or allocates a state structure.
static void update_client_state_status(struct sip_outbound_registration_client_state *client_state, enum sip_outbound_registration_status status)
static void * cli_retrieve_by_id(const char *id)
static const struct ast_sorcery_observer observer_callbacks_auth
static pj_status_t registration_client_send(struct sip_outbound_registration_client_state *client_state, pjsip_tx_data *tdata)
Helper function which sends a message and cleans up, if needed, on failure.
static int outbound_auths_to_str(const void *obj, const intptr_t *args, char **buf)
static int ami_outbound_registration_detail(void *obj, void *arg, int flags)
static void reregister_all(void)
static char * cli_unregister(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static struct ast_sip_endpoint_identifier line_identifier
static int unregister_task(void *obj)
static int outbound_auths_to_var_list(const void *obj, struct ast_variable **fields)
static struct ao2_container * cli_get_container(const char *regex)
static char * cli_complete_registration(const char *line, const char *word, int pos, int state)
static void sip_outbound_registration_destroy(void *obj)
Destructor function for registration information.
static const char * security_negotiation_map[]
static pj_str_t OUTBOUND_NAME
static struct stasis_subscription * network_change_sub
static struct ao2_container * get_registrations(void)
static int load_module(void)
static int cli_print_body(void *obj, void *arg, int flags)
static void schedule_retry(struct registration_response *response, unsigned int interval, const char *server_uri, const char *client_uri)
static void schedule_registration(struct sip_outbound_registration_client_state *client_state, unsigned int seconds)
Helper function which sets up the timer to re-register in a specific amount of time.
sip_outbound_registration_status
Various states that an outbound registration may be in.
@ SIP_REGISTRATION_REGISTERED
Registered, yay!
@ SIP_REGISTRATION_REJECTED_PERMANENT
Registration was rejected, permanently.
@ SIP_REGISTRATION_STOPPED
Registration has been stopped.
@ SIP_REGISTRATION_STOPPING
Registration is stopping.
@ SIP_REGISTRATION_UNREGISTERED
Currently unregistered.
@ SIP_REGISTRATION_REJECTED_TEMPORARY
Registration was rejected, but response was temporal.
static int security_negotiation_to_str(const void *obj, const intptr_t *args, char **buf)
static char * my_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int unload_module(void)
static int line_identify_relationship(void *obj, void *arg, int flags)
Callback function for matching an outbound registration based on line.
static int set_outbound_initial_authentication_credentials(pjsip_regc *regc, const struct ast_sip_auth_vector *auth_vector)
static struct ast_cli_entry cli_outbound_registration[]
static struct ast_sip_cli_formatter_entry * cli_formatter
static int check_state(void *obj, void *arg, int flags)
static int sip_outbound_registration_perform(void *data)
Helper function which performs a single registration.
static int can_reuse_registration(struct sip_outbound_registration *existing, struct sip_outbound_registration *applied)
static void sip_outbound_registration_response_cb(struct pjsip_regc_cbparam *param)
Callback function for outbound registration client.
static int registration_state_hash(const void *obj, const int flags)
hashing function for state objects
static int monitor_matcher(void *a, void *b)
static void cancel_registration(struct sip_outbound_registration_client_state *client_state)
Helper function which cancels the timer on a client.
static void registration_loaded_observer(const char *name, const struct ast_sorcery *sorcery, const char *object_type, int reloaded)
static int ami_outbound_registration_task(void *obj)
static int add_configured_supported_headers(struct sip_outbound_registration_client_state *client_state, pjsip_tx_data *tdata)
Helper function to add configured supported headers.
int ast_sip_validate_uri_length(const char *uri)
Definition location.c:529
static void cleanup(void)
Clean up any old apps that we don't need any more.
Definition res_stasis.c:327
static struct @523 args
#define NULL
Definition resample.c:96
int ast_serializer_shutdown_group_join(struct ast_serializer_shutdown_group *shutdown_group, int timeout)
Wait for the serializers in the group to shutdown with timeout.
struct ast_serializer_shutdown_group * ast_serializer_shutdown_group_alloc(void)
Create a serializer group shutdown control object.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition sorcery.c:2381
void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Remove an observer from a specific object type.
Definition sorcery.c:2487
#define ast_sorcery_objectset_create(sorcery, object)
Create an object set (KVP list) for an object.
Definition sorcery.h:1137
void ast_sorcery_instance_observer_remove(struct ast_sorcery *sorcery, const struct ast_sorcery_instance_observer *callbacks)
Remove an observer from a sorcery instance.
Definition sorcery.c:601
@ AST_RETRIEVE_FLAG_MULTIPLE
Return all matching objects.
Definition sorcery.h:120
@ AST_RETRIEVE_FLAG_ALL
Perform no matching, return all objects.
Definition sorcery.h:123
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition sorcery.c:1917
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
Definition sorcery.h:837
struct ao2_container * ast_sorcery_retrieve_by_regex(const struct ast_sorcery *sorcery, const char *type, const char *regex)
Retrieve multiple objects using a regular expression on their id.
Definition sorcery.c:2018
int ast_sorcery_observer_add(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Add an observer to a specific object type.
Definition sorcery.c:2455
void ast_sorcery_load_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to load persistent objects.
Definition sorcery.c:1457
#define ast_sorcery_object_field_register_custom(sorcery, type, name, default_val, config_handler, sorcery_handler, multiple_handler, flags,...)
Register a field within an object with custom handlers.
Definition sorcery.h:1005
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition sorcery.c:1792
int ast_sorcery_object_unregister(struct ast_sorcery *sorcery, const char *type)
Unregister an object type.
Definition sorcery.c:1125
int ast_sorcery_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
Definition sorcery.c:2528
#define ast_sorcery_apply_config(sorcery, name)
Definition sorcery.h:455
int ast_sorcery_changeset_create(const struct ast_variable *original, const struct ast_variable *modified, struct ast_variable **changes)
Create a changeset given two object sets.
Definition sorcery.c:1727
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition sorcery.h:955
int ast_sorcery_object_id_sort(const void *obj, const void *arg, int flags)
ao2 object sorter based on sorcery id.
Definition sorcery.c:2504
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition sorcery.h:476
void ast_sorcery_reload_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to reload persistent objects.
Definition sorcery.c:1506
int ast_sorcery_instance_observer_add(struct ast_sorcery *sorcery, const struct ast_sorcery_instance_observer *callbacks)
Add an observer to a sorcery instance.
Definition sorcery.c:584
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
Definition sorcery.c:1961
@ STASIS_SUBSCRIPTION_FILTER_SELECTIVE
Definition stasis.h:297
int stasis_subscription_accept_message_type(struct stasis_subscription *subscription, const struct stasis_message_type *type)
Indicate to a subscription that we are interested in a message type.
Definition stasis.c:1101
int stasis_subscription_set_filter(struct stasis_subscription *subscription, enum stasis_subscription_message_filter filter)
Set the message type filtering level on a subscription.
Definition stasis.c:1155
struct stasis_subscription * stasis_unsubscribe_and_join(struct stasis_subscription *subscription)
Cancel a subscription, blocking until the last message is processed.
Definition stasis.c:1212
#define stasis_subscribe(topic, callback, data)
Definition stasis.h:649
void ast_system_publish_registry(const char *channeltype, const char *username, const char *domain, const char *status, const char *cause)
Publish a channel driver outgoing registration message.
struct stasis_topic * ast_system_topic(void)
A Stasis Message Bus API topic which publishes messages regarding system changes.
struct stasis_message_type * ast_network_change_type(void)
A stasis_message_type for network changes.
void AST_OPTIONAL_API_NAME() ast_statsd_log_string_va(const char *metric_name, const char *metric_type, const char *value, double sample_rate,...)
Send a stat to the configured statsd server.
Definition res_statsd.c:205
#define AST_STATSD_GAUGE
Support for publishing to a statsd server.
Definition statsd.h:32
void AST_OPTIONAL_API_NAME() ast_statsd_log_string(const char *metric_name, const char *metric_type, const char *value, double sample_rate)
Send a stat to the configured statsd server.
Definition res_statsd.c:136
void AST_OPTIONAL_API_NAME() ast_statsd_log(const char *metric_name, const char *metric_type, intmax_t value)
Send a stat to the configured statsd server.
Definition res_statsd.c:251
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition strings.h:1139
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition strings.h:80
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition strings.h:1259
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
char * ast_generate_random_string(char *buf, size_t size)
Create a pseudo-random string of a fixed length.
Definition strings.c:226
Generic container type.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition astobj2.h:1821
descriptor for a cli entry.
Definition cli.h:171
char * command
Definition cli.h:186
const char * usage
Definition cli.h:177
JSON parsing error information.
Definition json.h:887
Abstract JSON element (object, array, string, int, ...).
AMI variable container.
Definition res_pjsip.h:3274
struct mansession * s
Definition res_pjsip.h:3276
const struct message * m
Definition res_pjsip.h:3278
const ast_string_field oauth_clientid
Definition res_pjsip.h:683
const ast_string_field oauth_secret
Definition res_pjsip.h:683
const ast_string_field realm
Definition res_pjsip.h:683
const ast_string_field auth_user
Definition res_pjsip.h:683
const ast_string_field refresh_token
Definition res_pjsip.h:683
const ast_string_field auth_pass
Definition res_pjsip.h:683
CLI Formatter Context passed to all formatters.
CLI Formatter Registry Entry.
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
ao2_callback_fn * print_header
void *(* retrieve_by_id)(const char *id)
const char *(* get_id)(const void *obj)
const char * name
ao2_callback_fn * print_body
struct ao2_container *(* get_container)(const char *regex)
A contact's status.
Definition res_pjsip.h:453
struct ast_sip_security_mechanism_vector security_mechanisms
Definition res_pjsip.h:468
Contact associated with an address of record.
Definition res_pjsip.h:392
An entity responsible for identifying the source of a SIP message.
Definition res_pjsip.h:1427
struct ast_sip_endpoint *(* identify_endpoint)(pjsip_rx_data *rdata)
Callback used to identify the source of a message. See ast_sip_identify_endpoint for more details.
Definition res_pjsip.h:1432
An entity with which Asterisk communicates.
Definition res_pjsip.h:1067
const ast_string_field aors
Definition res_pjsip.h:1096
Interface for the sorcery instance observer.
Definition sorcery.h:237
void(* object_type_loaded)(const char *name, const struct ast_sorcery *sorcery, const char *object_type, int reloaded)
Callback after any object_type is loaded/reloaded.
Definition sorcery.h:260
Interface for a sorcery object type observer.
Definition sorcery.h:332
void(* loaded)(const char *object_type)
Callback for when an object type is loaded/reloaded.
Definition sorcery.h:343
void(* deleted)(const void *object)
Callback for when an object is deleted.
Definition sorcery.h:340
Full structure for sorcery.
Definition sorcery.c:231
Support for dynamic strings.
Definition strings.h:623
A ast_taskprocessor structure is a singleton by name.
Structure for variables, used for configurations and for channel variables.
struct header * next
In case you didn't read that giant block of text above the mansession_session struct,...
Definition manager.c:314
Structure for registration response.
struct sip_outbound_registration_client_state * client_state
Outbound registration client state.
char transport_key[IP6ADDR_COLON_PORT_BUFLEN]
Key for the reliable transport in use.
pjsip_rx_data * rdata
The response message.
int code
Response code for the registration attempt.
int expiration
Expiration time for registration.
pjsip_tx_data * old_request
Request for which the response was received.
struct sip_outbound_registration * registration
Outbound registration client state information (persists for lifetime of regc)
struct ast_sip_auth_vector outbound_auths
Configured authentication credentials.
unsigned int auth_rejection_permanent
Treat authentication challenges that we cannot handle as permanent failures.
char * user_agent
The value for the User-Agent header sent in requests.
unsigned int support_outbound
Determines whether SIP Outbound support should be advertised.
unsigned int auth_attempted
Non-zero if we have attempted sending a REGISTER with authentication.
enum ast_sip_security_negotiation security_negotiation
Type of security negotiation to use (RFC 3329).
char line[LINE_PARAMETER_SIZE]
Optional line parameter placed into Contact.
unsigned int support_path
Determines whether SIP Path support should be advertised.
char * transport_name
The name of the transport to be used for the registration.
int last_status_code
Status code of last response if we have tried to register before.
unsigned int registration_expires
Expected time of registration lapse/expiration.
unsigned int retry_interval
Interval at which retries should occur for temporal responses.
unsigned int destroy
Registration should be destroyed after completion of transaction.
struct ast_sip_security_mechanism_vector server_security_mechanisms
Security mechanisms of the peer (RFC 3329).
unsigned int forbidden_retry_interval
Interval at which retries should occur for permanent responses.
struct ast_taskprocessor * serializer
Serializer for stuff and things.
unsigned int max_retries
Maximum number of retries permitted.
unsigned int fatal_retry_interval
Interval at which retries should occur for all permanent responses.
char * registration_name
The name of the registration sorcery object.
pj_timer_entry timer
Timer entry for retrying on temporal responses.
enum sip_outbound_registration_status status
Current state of this registration.
unsigned int retries
Current number of retries.
pjsip_tx_data * last_tdata
Last tdata sent We need the original tdata to resend a request on auth failure or timeout....
pjsip_regc * client
Outbound registration client.
struct ast_sip_security_mechanism_vector security_mechanisms
Client security mechanisms (RFC 3329).
Outbound registration state information (persists for lifetime that registration should exist)
struct sip_outbound_registration_client_state * client_state
Client state information.
struct sip_outbound_registration * registration
Outbound registration configuration object.
Outbound registration information.
struct ast_sip_auth_vector outbound_auths
Configured authentication credentials.
SORCERY_OBJECT(details)
Sorcery object details.
unsigned int auth_rejection_permanent
Treat authentication challenges that we cannot handle as permanent failures.
unsigned int expiration
Requested expiration time.
unsigned int support_outbound
Whether Outbound support is enabled.
enum ast_sip_security_negotiation security_negotiation
Type of security negotiation to use (RFC 3329).
unsigned int support_path
Whether Path support is enabled.
unsigned int max_random_initial_delay
Maximum random initial delay interval for initial registrations.
unsigned int retry_interval
Interval at which retries should occur for temporal responses.
unsigned int forbidden_retry_interval
Interval at which retries should occur for permanent responses.
unsigned int max_retries
Maximum number of retries permitted.
unsigned int fatal_retry_interval
Interval at which retries should occur for all permanent responses.
unsigned int line
Whether to add a line parameter to the outbound Contact or not.
struct ast_sip_security_mechanism_vector security_mechanisms
Client security mechanisms (RFC 3329).
structure to hold users read from phoneprov_users.conf
int value
Definition syslog.c:37
An API for managing task processing threads that can be shared across modules.
void * ast_taskprocessor_unreference(struct ast_taskprocessor *tps)
Unreference the specified taskprocessor and its reference count will decrement.
void ast_taskprocessor_build_name(char *buf, unsigned int size, const char *format,...)
Build a taskprocessor name with a sequence number on the end.
#define AST_TASKPROCESSOR_MAX_NAME
Suggested maximum taskprocessor name length (less null terminator).
static char server_uri[512]
static struct test_val b
static struct test_val a
Definitions to aid in the use of thread local storage.
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
#define AST_THREADSTORAGE(name)
Define a thread storage variable.
FILE * out
Definition utils/frame.c:33
int error(const char *format,...)
char * usage
Definition utils/frame.c:37
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:981
#define ast_assert(a)
Definition utils.h:779
long int ast_random(void)
Definition utils.c:2346
#define ARRAY_IN_BOUNDS(v, a)
Checks to see if value is within the bounds of the given array.
Definition utils.h:727
#define ARRAY_LEN(a)
Definition utils.h:706
Vector container support.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition vector.h:637
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition vector.h:185
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition vector.h:124
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition vector.h:267
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
Definition vector.h:890
#define AST_VECTOR(name, type)
Define a vector structure.
Definition vector.h:44
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition vector.h:708