Commit Graph

4375 Commits

Author SHA1 Message Date
Sean Bright 048b12b59d vector.h: Fix implementation of AST_VECTOR_COMPACT() for empty vectors
The assumed behavior of realloc() - that it was effectively a free() if
its second argument was 0 - is Linux specific behavior and is not
guaranteed by either POSIX or the C specification.

Instead, if we want to resize a vector to 0, do it explicitly.

Change-Id: Ife31d4b510ebab41cb5477fdc7ea4e3138ca8b4f
2020-08-10 07:21:52 -05:00
Ben Ford 9ed6387c14 utils.c: NULL terminate ast_base64decode_string.
With the addition of STIR/SHAKEN, the function ast_base64decode_string
was added for convenience since there is a lot of converting done during
the STIR/SHAKEN process. This function returned the decoded string for
you, but did not NULL terminate it, causing some issues (specifically
with MALLOC_DEBUG). Now, the returned string is NULL terminated, and the
documentation has been updated to reflect this.

Change-Id: Icdd7d05b323b0c47ff6ed43492937a03641bdcf5
2020-08-06 12:19:48 -05:00
George Joseph a15e64aaf5 ACN: Configuration renaming for pjsip endpoint
This change renames the codec preference endpoint options.
incoming_offer_codec_prefs becomes codec_prefs_incoming_offer
to keep the options together when showing an endpoint.

Change-Id: I6202965b4723777f22a83afcbbafcdafb1d11c8d
2020-08-06 10:50:16 -05:00
Sean Bright 7d96b3e437 utf8.c: Add UTF-8 validation and utility functions
There are various places in Asterisk - specifically in regards to
database integration - where having some kind of UTF-8 validation would
be beneficial. This patch adds:

* Functions to validate that a given string contains only valid UTF-8
  sequences.

* A function to copy a string (similar to ast_copy_string) stopping when
  an invalid UTF-8 sequence is encountered.

* A UTF-8 validator that allows for progressive validation.

All of this is based on the excellent UTF-8 decoder by Björn Höhrmann.
More information is available here:

    https://bjoern.hoehrmann.de/utf-8/decoder/dfa/

The API was written in such a way that should allow us to replace the
implementation later should we determine that we need something more
comprehensive.

Change-Id: I3555d787a79e7c780a7800cd26e0b5056368abf9
2020-07-28 09:45:29 -05:00
Sean Bright b5bb4a7a0d vector.h: Add AST_VECTOR_SORT()
Allows a vector to be sorted in-place, rather than only during
insertion.

Change-Id: I22cba9ddf556a7e44dacc53c4431bd81dd2fa780
2020-07-24 11:29:47 -05:00
George Joseph 9c3b57822a Prepare master for the next Asterisk version
* Updated AMI version to 8.0.0
* Updated ARI version to 7.0.0
* Update make_ari_stubs.py to "Asterisk 19"

Change-Id: I51fb38c2e29f2db785f64a8bbd5565d56bea5af5
2020-07-21 07:37:23 -05:00
Ben Ford 5fbed5af24 res_stir_shaken: Add stir_shaken option and general improvements.
Added a new configuration option for PJSIP endpoints - stir_shaken. If
set to yes, then STIR/SHAKEN support will be added to inbound and
outbound INVITEs. The default is no. Alembic has been updated to include
this option.

Previously the dialplan function was not trimming the whitespace from
the parameters it recieved. Now it does.

Also added a conditional that, when TEST_FRAMEWORK is enabled, the
timestamp in the identity header will be overlooked. This is just for
testing, since the testsuite will rely on a SIPp scenario with a preset
identity header to trigger the MISMATCH result.

Change-Id: I43d67f1489b8c1c5729ed3ca8d71e35ddf438df1
2020-07-10 09:57:09 -05:00
George Joseph 9bd1d686a1 ACN: Add tracing to existing code
Prior to making any modifications to the pjsip infrastructure
for ACN, I've added the tracing functions to the existing code.
This should make the final commit easier to review, but we can also
now run a "before and after" trace.

No functional changes were made with this commit.

Change-Id: Ia83a1a2687ccb96f2bc8a2a3928a5214c4be775c
2020-07-08 09:24:42 -05:00
George Joseph 2d22e34206 ACN: res_pjsip endpoint options
This commit adds the endpoint options required to control
Advanced Codec Negotiation.

incoming_offer_codec_prefs
outgoing_offer_codec_prefs
incoming_answer_codec_prefs
outgoing_answer_codec_prefs

The documentation may need tweaking and some additional edits
added, especially for the "answer" prefs.  That'll be handled
when things finalize.

This commit is safe to merge as it doens't alter any existing
functionality nor does it alter the previous codec negotiation
work which may now be obsolete.

Change-Id: I920ba925d7dd36430dfd2ebd9d82d23f123d0e11
2020-07-08 09:03:58 -05:00
George Joseph d093e44b1e frame.c: Make debugging easier
* ast_frame_subclass2str() and ast_frame_type2str() now return
   a pointer to the buffer that was passed in instead of void.
   This makes it easier to use these functions inline in
   printf-style debugging statements.

 * Added many missing control frame entries in
   ast_frame_subclass2str.

Change-Id: Ifd0d6578e758cd644c96d17a5383ff2128c572fc
2020-07-07 15:01:17 -05:00
George Joseph 955b7b4fdb Scope Trace: Make it easier to trace through synchronous tasks
Tracing through synchronous tasks was a little troublesome because
the new thread's stack counter reset to 0.  This change allows
a synchronous task to set its trace level to be the same as the
thread that pushed the task.  For now, the task's level has to be
passed in the task's data structure but a future enhancement to the
taskprocessor subsystem could automatically set the trace level
of the servant to be that of the caller.

This doesn't really make sense for async tasks because you never
know when they're going to run anyway.

Change-Id: Ib8049c0b815063a45d8c7b0cb4e30b7b87b1d825
2020-07-07 14:07:57 -05:00
Kevin Harwell cfed0ea033 manager - Add Content-Type parameter to the SendText action
This patch allows a user of AMI to now specify the type of message
content contained within by setting the 'Content-Type' parameter.

Note, the AMI version has been bumped for this change.

ASTERISK-28945 #close

Change-Id: Ibb5315702532c6b954e1498beddc8855fabdf4bb
2020-07-06 05:27:43 -05:00
George Joseph 8d1064eaaf Streams: Add features for Advanced Codec Negotiation
The Streams API becomes the home for the core ACN capabilities.
These include...

 * Parsing and formatting of codec negotation preferences.
 * Resolving pending streams and topologies with those configured
   using configured preferences.
 * Utility functions for creating string representations of
   streams, topologies, and negotiation preferences.

For codec negotiation preferences:
 * Added ast_stream_codec_prefs_parse() which takes a string
   representation of codec negotiation preferences, which
   may come from a pjsip endpoint for example, and populates
   a ast_stream_codec_negotiation_prefs structure.
 * Added ast_stream_codec_prefs_to_str() which does the reverse.
 * Added many functions to parse individual parameter name
   and value strings to their respectrive enum values, and the
   reverse.

For streams:
 * Added ast_stream_create_resolved() which takes a "live" stream
   and resolves it with a configured stream and the negotiation
   preferences to create a new stream.
 * Added ast_stream_to_str() which create a string representation
   of a stream suitable for debug or display purposes.

For topology:
 * Added ast_stream_topology_create_resolved() which takes a "live"
   topology and resolves it, stream by stream, with a configured
   topology stream and the negotiation preferences to create a new
   topology.
 * Added ast_stream_topology_to_str() which create a string
   representation of a topology suitable for debug or display
   purposes.
 * Renamed ast_format_caps_from_topology() to
   ast_stream_topology_get_formats() to be more consistent with
   the existing ast_stream_get_formats().

Additional changes:
 * A new function ast_format_cap_append_names() appends the results
   to the ast_str buffer instead of replacing buffer contents.

Change-Id: I2df77dedd0c72c52deb6e329effe057a8e06cd56
2020-07-01 09:27:14 -05:00
George Joseph 7440fd0397 Scope Trace: Add some new tracing macros and an ast_str helper
Created new SCOPE_ functions that don't depend on RAII_VAR.  Besides
generating less code, the use of the explicit SCOPE_EXIT macros
capture the line number where the scope exited.  The RAII_VAR
versions can't do that.

 * SCOPE_ENTER(level, ...): Like SCOPE_TRACE but doesn't use
   RAII_VAR and therefore needs needs one of...

 * SCOPE_EXIT(...): Decrements the trace stack counter and optionally
   prints a message.

 * SCOPE_EXIT_EXPR(__expr, ...): Decrements the trace stack counter,
   optionally prints a message, then executes the expression.
   SCOPE_EXIT_EXPR(break, "My while got broken\n");

 * SCOPE_EXIT_RTN(, ...): Decrements the trace stack counter,
   optionally prints a message, then returns without a value.
   SCOPE_EXIT_RTN("Bye\n");

 * SCOPE_EXIT_RTN_VALUE(__return_value, ...): Decrements the trace
   stack counter, optionally prints a message, then returns the value
   specified.
   SCOPE_EXIT_RTN_VALUE(rc, "Returning with RC: %d\n", rc);

Create an ast_str helper ast_str_tmp() that allocates a temporary
ast_str that can be passed to a function that needs it, then frees
it.  This makes using the above macros easier.  Example:

   SCOPE_ENTER(1, Format Caps 1: %s  Format Caps 2: %s\n",
       ast_str_tmp(32, ast_format_cap_get_names(cap1, &STR_TMP),
       ast_str_tmp(32, ast_format_cap_get_names(cap2, &STR_TMP));

The calls to ast_str_tmp create an ast_str of the specified initial
length which can be referenced as STR_TMP.  It then calls the
expression, which must return a char *, ast_strdupa's it, frees
STR_TMP, then returns the ast_strdupa'd string.  That string is
freed when the function returns.

Change-Id: I44059b20d55a889aa91440d2f8a590865998be51
2020-06-30 09:22:32 -05:00
Ben Ford 1274117102 res_stir_shaken: Add outbound INVITE support.
Integrated STIR/SHAKEN support with outgoing INVITEs. When an INVITE is
sent, the caller ID will be checked to see if there is a certificate
that corresponds to it. If so, that information will be retrieved and an
Identity header will be added to the SIP message. The format is:

header.payload.signature;info=<public_key_url>alg=ES256;ppt=shaken

Header, payload, and signature are all BASE64 encoded. The public key
URL is retrieved from the certificate. Currently the algorithm and ppt
are ES256 and shaken, respectively. This message is signed and can be
used for verification on the receiving end.

Two new configuration options have been added to the certificate object:
attestation and origid. The attestation is required and must be A, B, or
C. origid is the origination identifier.

A new utility function has been added as well that takes a string,
allocates space, BASE64 encodes it, then returns it, eliminating the
need to calculate the size yourself.

Change-Id: I1f84d6a5839cb2ed152ef4255b380cfc2de662b4
2020-06-18 17:45:27 -05:00
Kevin Harwell 415b55af5a pjproject: Upgrade bundled version to pjproject 2.10
This patch makes the usual necessary changes when upgrading to a new
version pjproject. For instance, version number bump, patches removed
from third-party, new *.md5 file added, etc..

This patch also includes a change to the Asterisk pjproject Makefile to
explicitly create the 'source/pjsip-apps/lib' directory. This directory
is no longer there by default so needs to be added so the Asterisk
malloc debug can be built.

This patch also includes some minor changes to Asterisk that were a result
of the upgrade. Specifically, there was a backward incompatibility change
made in 2.10 that modified the "expires header" variable field from a
signed to an unsigned value. This potentially effects comparison. Namely,
those check for a value less than zero. This patch modified a few locations
in the Asterisk code that may have been affected.

Lastly, this patch adds a new macro PJSIP_MINVERSION that can be used to
check a minimum version of pjproject at compile time.

ASTERISK-28899 #close

Change-Id: Iec8821c6cbbc08c369d0e3cd2f14e691b41d0c81
2020-06-16 08:07:17 -05:00
Joshua C. Colp de2813cf23 core_unreal / core_local: Add multistream and re-negotiation.
When requesting a Local channel the requested stream topology
or a converted stream topology will now be placed onto the
resulting channels.

Frames written in on streams will now also preserve the stream
identifier as they are queued on the opposite channel.

Finally when a stream topology change is requested it is
immediately accepted and reflected on both channels. Each
channel also receives a queued frame to indicate that the
topology has changed.

ASTERISK-28938

Change-Id: I4e9d94da5230d4bd046dc755651493fce1d87186
2020-06-15 08:49:40 -05:00
Kevin Harwell 3d1bf3c537 Compiler fixes for gcc 10
This patch fixes a few compile warnings/errors that now occur when using gcc
10+.

Also, the Makefile.rules check to turn off partial inlining in gcc versions
greater or equal to 8.2.1 had a bug where it only it only checked against
versions with at least 3 numbers (ex: 8.2.1 vs 10). This patch now ensures
any version above the specified version is correctly compared.

Change-Id: I54718496eb0c3ce5bd6d427cd279a29e8d2825f9
2020-06-10 09:33:28 -05:00
Ben Ford 3927f79cb5 res_stir_shaken: Add inbound INVITE support.
Integrated STIR/SHAKEN support with incoming INVITES. Upon receiving an
INVITE, the Identity header is retrieved, parsing the message to verify
the signature. If any of the parsing fails,
AST_STIR_SHAKEN_VERIFY_NOT_PRESENT will be added to the channel for this
caller ID. If verification itself fails,
AST_STIR_SHAKEN_VERIFY_SIGNATURE_FAILED will be added. If anything in
the payload does not line up with the SIP signaling,
AST_STIR_SHAKEN_VERIFY_MISMATCH will be added. If all of the above steps
pass, then AST_STIR_SHAKEN_VERIFY_PASSED will be added, completing the
verification process.

A new config option has been added to the general section for
stir_shaken.conf. "signature_timeout" is the amount of time a signature
will be considered valid. If an INVITE is received and the amount of
time between when it was received and when it was signed is greater than
signature_timeout, verification will fail.

Some changes were also made to signing and verification. There was an
error where the whole JSON string was being signed rather than the
header combined with the payload. This has been changed to sign the
correct thing. Verification has been changed to do this as well, and the
unit tests have been updated to reflect these changes.

A couple of utility functions have also been added. One decodes a BASE64
string and returns the decoded string, doing all the length calculations
for you. The other retrieves a string value from a header in a rdata
object.

Change-Id: I855f857be3d1c63b64812ac35d9ce0534085b913
2020-06-08 10:50:16 -05:00
George Joseph ca3c22c5f1 Scope Tracing: A new facility for tracing scope enter/exit
What's wrong with ast_debug?

  ast_debug is fine for general purpose debug output but it's not
  really geared for scope tracing since it doesn't present its
  output in a way that makes capturing and analyzing flow through
  Asterisk easy.

How is scope tracing better?

  Scope tracing uses the same "cleanup" attribute that RAII_VAR
  uses to print messages to a separate "trace" log level.  Even
  better, the messages are indented and unindented based on a
  thread-local call depth counter.  When output to a separate log
  file, the output is uncluttered and easy to follow.

  Here's an example of the output. The leading timestamps and
  thread ids are removed and the output cut off at 68 columns for
  commit message restrictions but you get the idea.

--> res_pjsip_session.c:3680 handle_incoming PJSIP/1173-00000001
	--> res_pjsip_session.c:3661 handle_incoming_response PJSIP/1173
		--> res_pjsip_session.c:3669 handle_incoming_response PJSIP/
			--> chan_pjsip.c:3265 chan_pjsip_incoming_response_after
				--> chan_pjsip.c:3194 chan_pjsip_incoming_response P
					    chan_pjsip.c:3245 chan_pjsip_incoming_respon
				<-- chan_pjsip.c:3194 chan_pjsip_incoming_response P
			<-- chan_pjsip.c:3265 chan_pjsip_incoming_response_after
		<-- res_pjsip_session.c:3669 handle_incoming_response PJSIP/
	<-- res_pjsip_session.c:3661 handle_incoming_response PJSIP/1173
<-- res_pjsip_session.c:3680 handle_incoming PJSIP/1173-00000001

  The messages with the "-->" or "<--" were produced by including
  the following at the top of each function:

  SCOPE_TRACE(1, "%s\n", ast_sip_session_get_name(session));

  Scope isn't limited to functions any more than RAII_VAR is.  You
  can also see entry and exit from "if", "for", "while", etc blocks.

  There is also an ast_trace() macro that doesn't track entry or
  exit but simply outputs a message to the trace log using the
  current indent level.  The deepest message in the sample
  (chan_pjsip.c:3245) was used to indicate which "case" in a
  "select" was executed.

How do you use it?

  More documentation is available in logger.h but here's an overview:

  * Configure with --enable-dev-mode.  Like debug, scope tracing
    is #ifdef'd out if devmode isn't enabled.

  * Add a SCOPE_TRACE() call to the top of your function.

  * Set a logger channel in logger.conf to output the "trace" level.

  * Use the CLI (or cli.conf) to set a trace level similar to setting
    debug level... CLI> core set trace 2 res_pjsip.so

Summary Of Changes:

  * Added LOG_TRACE logger level.  Actually it occupies the slot
    formerly occupied by the now defunct "event" level.

  * Added core asterisk option "trace" similar to debug.  Includes
	ability to specify global trace level in asterisk.conf and CLI
	commands to turn on/off and set levels.  Levels can be set
	globally (probably not a good idea), or by module/source file.

  * Updated sample asterisk.conf and logger.conf.  Tracing is
    disabled by default in both.

  * Added __ast_trace() to logger.c which keeps track of the indent
    level using TLS. It's #ifdef'd out if devmode isn't enabled.

  * Added ast_trace() and SCOPE_TRACE() macros to logger.h.
    These are all #ifdef'd out if devmode isn't enabled.

Why not use gcc's -finstrument-functions capability?

  gcc's facility doesn't allow access to local data and doesn't
  operate on non-function scopes.

Known Issues:

  The only know issue is that we currently don't know the line
  number where the scope exited.  It's reported as the same place
  the scope was entered.  There's probably a way to get around it
  but it might involve looking at the stack and doing an 'addr2line'
  to get the line number.  Kind of like ast_backtrace() does.
  Not sure if it's worth it.

Change-Id: Ic5ebb859883f9c10a08c5630802de33500cad027
2020-06-02 11:35:07 -05:00
Ben Ford e29df34de0 res_stir_shaken: Added dialplan function and API call.
Adds the "STIR_SHAKEN" dialplan function and an API call to add a
STIR_SHAKEN verification result to a channel. This information will be
held in a datastore on the channel that can later be queried through the
"STIR_SHAKEN" dialplan funtion to get information on STIR_SHAKEN results
including identity, attestation, and verify_result. Here are some
examples:

STIR_SHAKEN(count)
STIR_SHAKEN(0, identity)
STIR_SHAKEN(1, attestation)
STIR_SHAKEN(2, verify_result)

Getting the count can be used to iterate through the results and pull
information by specifying the index and the field you want to retrieve.

Change-Id: Ice6d52a3a7d6e4607c9c35b28a1f7c25f5284a82
2020-05-13 06:41:29 -05:00
Nathan Bruning f217fcdc62 app_queue: track masquerades in app_queue to avoid leaked stasis subscriptions
Add a new "masquarade" channel event, and use it in app_queue to track unique id's.

Testcase is submitted as https://gerrit.asterisk.org/c/testsuite/+/14210

ASTERISK-28829 #close
ASTERISK-25844 #close

Change-Id: Ifc5f9f9fd70903f3c6e49738d3bc632b085d2df6
2020-05-06 04:10:26 -05:00
Ben Ford 9acf840f7c res_stir_shaken: Implemented signature verification.
There are a lot of moving parts in this patch, but the focus of it is on
the verification of the signature using a public key located at the
public key URL provided in the JSON payload. First, we check the
database to see if we have already downloaded the key. If so, check to
see if it has expired. If it has, redownload from the URL. If we don't
have an entry in the database, just go ahead and download the public
key. The expiration is tested each time we download the file. After
that, read the public key from the file and use it to verify the
signature. All sanity checking is done when the payload is first
received, so the verification is complete once this point is reached.

The XML has also been added since a new config option was added to
general (curl_timeout). The maximum amount of time to wait for a
download can be configured through this option, with a low value by
default.

Change-Id: I3ba4c63880493bf8c7d17a9cfca1af0e934d1a1c
2020-05-01 06:31:46 -05:00
Joshua C. Colp 1c5e68580a stream: Enforce formats immutability and ensure formats exist.
Some places in Asterisk did not treat the formats on a stream
as immutable when they are.

The ast_stream_get_formats function is now const to enforce this
and parts of Asterisk have been updated to take this into account.
Some violations of this were also fixed along the way.

An additional minor tweak is that streams are now allocated with
an empty format capabilities structure removing the need in various
places to check that one is present on the stream.

ASTERISK-28846

Change-Id: I32f29715330db4ff48edd6f1f359090458a9bfbe
2020-04-23 09:16:51 -05:00
Joshua C. Colp 6cfc6ff53c confbridge: Add support for disabling text messaging.
When in a conference bridge it may be necessary to have
text messages disabled for specific participants or for
all. This change adds a configuration option, "text_messaging",
which can be used to enable or disable this on the
user profile. By default existing behavior is preserved
as it defaults to "yes".

ASTERISK-28841

Change-Id: I30b5d9ae6f4803881d1ed9300590d405e392bc13
2020-04-20 12:03:22 -05:00
Jean Aunis de66713fd5 func_volume: Accept decimal number as argument
Allow voice volume to be multiplied or divided by a floating point number.

ASTERISK-28813

Change-Id: I5b42b890ec4e1f6b0b3400cb44ff16522b021c8c
2020-04-14 09:28:05 -05:00
George Joseph 7ba6d43083 test_res_pjsip_session_caps: Create unit test
This unit test runs through combinations of...
	* Local codecs
	* Remote Codecs
	* Codec Preference
	* Incoming/Outgoing

A few new APIs were created to make it easier to test
the functionality but didn't result in any actual
functional change.

ASTERISK_28777

Change-Id: Ic8957c43e7ceeab0e9272af60ea53f056164f164
2020-04-06 08:02:53 -05:00
George Joseph 2ee455958e codec_negotiation: Implement outgoing_call_offer_pref
Based on this new endpoint setting, a joint list of preferred codecs
between those received from the Asterisk core (remote), and those
specified in the endpoint's "allow" parameter (local) is created and
is used to create the outgoing SDP offer.

* Add outgoing_call_offer_pref to pjsip_configuration (endpoint)

* Add "call_direction" to res_pjsip_session.

* Update pjsip_session_caps.c to make the functions more generic
  so they could be used for both incoming and outgoing.

* Update ast_sip_session_create_outgoing to create the
  pending_media_state->topology with the results of
  ast_sip_session_create_joint_call_stream().

* The endpoint "preferred_codec_only" option now automatically sets
  AST_SIP_CALL_CODEC_PREF_FIRST in incoming_call_offer_pref.

* A helper function ast_stream_get_format_count() was added to
  streams to return the current count of formats.

ASTERISK-28777

Change-Id: Id4ec0b4a906c2ae5885bf947f101c59059935437
2020-04-06 08:00:49 -05:00
Ben Ford 57a457c26c res_stir_shaken: Implemented signing of JSON payload.
This change provides functions that take in a JSON payload, verify that
the contents contain all the mandatory fields and required values (if
any), and signs the payload with the private key. Four fields are added
to the payload: x5u, attest, iat, and origid. As of now, these are just
placeholder values that will be set to actual values once the logic is
implemented for what to do when an actual payload is received, but the
functions to add these values have all been implemented and are ready to
use. Upon successful signing and the addition of those four values, a
ast_stir_shaken_payload is returned, containing other useful information
such as the algorithm and signature.

Change-Id: I74fa41c0640ab2a64a1a80110155bd7062f13393
2020-04-03 11:08:29 -05:00
Jaco Kroon d32e559e8a acl: implement a centralized ACL output mechanism for HAs and ACLs.
named_acl.c (which is really a named_ha) now uses ast_ha_output.

I've also updated main/manager.c to output the actual ACL on "manager
show user <username>" if one is set.  If this works then we can add
similar to other modules as required.

Change-Id: I0ec9876a90dddd379c80ec078d48e3ee6991eb0f
2020-03-31 11:08:45 -05:00
Jaco Kroon 6f731f153b netsock2: compile fixes.
This fixes ast_addressfamily_to_sockaddrsize to reference the
provided argument, and ast_sockaddr_from_sockaddr to not use the name of
a structure as argument.

Change-Id: Ibf5db469c47c3b4214edf8456326086174e8edd7
2020-03-26 07:46:50 -05:00
Ben Ford 211bb8a79c res_stir_shaken: Initial commit and reading private key.
This commit sets up some of the initial framework for the module and
adds a way to read the private key from the specified file, which will
then be appended to the certificate object. This works fine for now, but
eventually some other structure will likely need to be used to store all
this information. Similarly, the caller_id_number is specified on the
certificate config object, but in the end we will want that information
to be tied to the certificate itself and read it from there.

A method has been added that will retrieve the private key associated
with the caller_id_number passed in. Tab completion for certificates and
stores has also been added.

Change-Id: Ic4bc1416fab5d6afe15a8e2d32f7ddd4e023295f
2020-03-25 18:04:22 -05:00
Sean Bright d68f940f6e dns_txt: Add TXT record parsing support
Change-Id: Ie0eca23b8e6f4c7d9846b6013d79099314d90ef5
2020-03-13 09:58:59 -05:00
George Joseph 99efe1f868 Merge "codec negotiation: add incoming_call_offer_prefs option" 2020-03-09 15:07:09 -05:00
Joshua Colp bdf7b4eeb3 Merge "message & stasis/messaging: make text message variables work in ARI" 2020-03-04 06:10:09 -06:00
Kevin Harwell 06dada3f01 codec negotiation: add incoming_call_offer_prefs option
Add a new option, incoming_call_offer_pref, to res_pjsip endpoints that
specifies the preferred order of codecs after receiving an offer.

This patch does the following:

  Adds a new enumeration, ast_sip_call_codec_pref, used by the the new
configuration option that's added to the endpoint media structure.

  Adds a new ast_sip_session_caps structure that's set for each session media
object.

  Creates a new file, res_pjsip_session_caps that "implements" the new
structure and option, and is compiled into the res_pjsip_session library.

ASTERISK-28756 #close

Change-Id: I35e7a2a0c236cfb6bd9cdf89539f57a1ffefc76f
2020-03-03 14:51:14 -06:00
Kevin Harwell f8a852605d Merge "res/res_pjsip_sdp_rtp: Fix MOH transitions" 2020-03-02 14:17:45 -06:00
Kevin Harwell a715cf5aaa message & stasis/messaging: make text message variables work in ARI
When a text message was received any associated variable was not written to
the ARI TextMessageReceived event. This occurred because Asterisk only wrote
out "send" variables. However, even those "send" variables would fail ARI
validation due to a TextMessageVariable formatting bug.

Since it seems the TextMessageReceived event has never been able to include
actual variables it was decided to remove the TextMessageVariable object type
from ARI, and simply return a JSON object of key/value pairs for variables.
This aligns more with how the ARI sendMessage handles variables, and other
places in ARI.

ASTERISK-28755 #close

Change-Id: Ia6051c01a53b30cf7edef84c27df4ed4479b8b6f
2020-03-02 12:12:11 -06:00
Kevin Harwell d18af40431 Merge "say: Remove unused "plural" option from main/say" 2020-02-27 13:43:19 -06:00
Kevin Harwell 566f9a541f Merge "format_cap: make function parameters 'const'" 2020-02-27 13:16:51 -06:00
Kevin Harwell a3b3a9d2dc Merge "pjsip: Update ACLs on named ACL changes." 2020-02-27 12:53:48 -06:00
Torrey Searle 77c9ba8e63 res/res_pjsip_sdp_rtp: Fix MOH transitions
Update the state of remote_hold immediately on receipt of remote
SDP so that the information is available when building the SDP
answer

ASTERISK-28754 #close

Change-Id: I7026032a807e9c95081cb8f060400b05deb4836f
2020-02-26 02:41:27 -06:00
Kevin Harwell 1e1651b4f4 format_cap: make function parameters 'const'
There were a couple places where the format cap function parameter was not
'const' when it should have been. This patch makes them 'const'.

Change-Id: Ife753fb16a962d842a6b44f45363a61a66bfdb2e
2020-02-24 12:44:43 -06:00
Walter Doekes 0b5c6fddf1 say: Remove unused "plural" option from main/say
There are exceptions for plural objects, but they are detected using the
supplied NUMBER, not using an extra option.

Change-Id: I95d1d1b2796b1aba92048a2dbae8a3856ed8a113
2020-02-24 15:41:52 +01:00
George Joseph 3854b561a5 Merge "bridging: Add better support for adding/removing streams." 2020-02-20 13:44:10 -06:00
Joshua C. Colp d6712790cd pjsip: Update ACLs on named ACL changes.
This change extends the Sorcery API to allow a wizard to be
told to explicitly reload objects or a specific object type
even if the wizard believes that nothing has changed.

This has been leveraged by res_pjsip and res_pjsip_acl to
reload endpoints and PJSIP ACLs when a named ACL changes.

ASTERISK-28697

Change-Id: Ib8fee9bd9dd490db635132c479127a4114c1ca0b
2020-02-20 04:52:11 -06:00
Joshua C. Colp 5a5be92b79 bridging: Add better support for adding/removing streams.
This change adds support to bridge_softmix to allow the addition
and removal of additional video source streams. When such a change
occurs each participant is renegotiated as needed to reflect the
update. If another video source is added then each participant
gets another source. If a video source is removed then it is
removed from each participant. This functionality allows you to
have both your webcam and screenshare providing video if you
desire, or even more streams. Mapping has been changed to use
the topology index on the source channel as a unique identifier
for outgoing participant streams, this will never change and
provides an easy way to establish the mapping.

The bridge_simple and bridge_native_rtp modules have also been
updated to renegotiate when the stream topology of a party changes
allowing the same behavior to occur as added to bridge_softmix.
If a screen share is added then the opposite party is renegotiated.
If that screen share is removed then the opposite party is
renegotiated again.

Some additional fixes are also included in here. Stream state is
now conveyed in SDP so sendonly/recvonly/inactive streams can
be requested. Removed streams now also remove previous state
from themselves so consumers don't get confused.

ASTERISK-28733

Change-Id: I93f41fb41b85646bef71408111c17ccea30cb0c5
2020-02-18 10:26:30 -06:00
Ben Ford 168637cc0c RTP/ICE: Send on first valid pair.
When handling ICE negotiations, it's possible that there can be a delay
between STUN binding requests which in turn will cause a delay in ICE
completion, preventing media from flowing. It should be possible to send
media when there is at least one valid pair, preventing this scenario
from occurring.

A change was added to PJPROJECT that adds an optional callback
(on_valid_pair) that will be called when the first valid pair is found
during ICE negotiation. Asterisk uses this to start the DTLS handshake,
allowing media to flow. It will only be called once, either on the first
valid pair, or when ICE negotiation is complete.

ASTERISK-28716

Change-Id: Ia7b68c34f06d2a1d91c5ed51627b66fd0363d867
2020-02-18 09:55:12 -06:00
George Joseph b76ab5e5c9 message.c: Add option to suppress the Message channel AMI and ARI events
In order to reduce the amount of AMI and ARI events generated,
the global "Message/ast_msg_queue" channel can be set to suppress
it's normal channel housekeeping events such as "Newexten",
"VarSet", etc. This can greatly reduce load on the manager
and ARI applications when the Digium Phone Module for Asterisk
is in use.  To enable, set "hide_messaging_ami_events" in
asterisk.conf to "yes"  In Asterisk versions <18, the default
is "no" preserving existing behavior.  Beginning with
Asterisk 18, the option will default to "yes".

NOTE:  This change does not affect UserEvents or the ARI
TextMessageReceived events.

* Added the "hide_messaging_ami_events" option to asterisk.conf.

* Changed message.c to set the AST_CHAN_TP_INTERNAL property on
  the "Message/ast_msg_queue" channel if the option is set in
  asterisk.conf.  This suppresses the reporting of the events.

Change-Id: Ia2e3516d43f4e0df994fc6598565d6bba2d7018b
2020-02-03 13:58:48 -06:00
Friendly Automation 4255277ffd Merge "feat: AudioSocket channel, application, and ARI support." 2020-01-15 07:22:08 -06:00
Friendly Automation 3f663a543d Merge "netsock2: ast_addressfamily_to_sockaddrsize and ast_sockaddr_from_sockaddr." 2020-01-14 09:48:22 -06:00
Seán C McCord 163efbd724 feat: AudioSocket channel, application, and ARI support.
This commit adds support for
[AudioSocket](
https://wiki.asterisk.org/wiki/display/AST/AudioSocket),
a very simple bidirectional audio streaming protocol. There are both
channel and application interfaces.

A description of the protocol can be found on the above referenced
GitHub page.  A short talk about the reasons and implementation can be
found on [YouTube](https://www.youtube.com/watch?v=tjduXbZZEgI), from
CommCon 2019.

ARI support has also been added via the existing "externalMedia" ARI
functionality. The UUID is specified using the arbitrary "data" field.

ASTERISK-28484 #close

Change-Id: Ie866e6c4fa13178ec76f2a6971ad3590a3a588b5
2020-01-14 09:36:44 -06:00
Friendly Automation 51f811183a Merge "ARI: Ability to inhibit COLP frames when adding channels to a bridge" 2020-01-10 12:03:35 -06:00
Jaco Kroon 3bc8b36537 netsock2: ast_addressfamily_to_sockaddrsize and ast_sockaddr_from_sockaddr.
ast_addressfamily_to_sockaddrize will determine the size that's
required, and ast_sockaddr_from_sockaddr then wraps this new function
and ast_sockaddr_copy_sockaddr to copy arbitrary sockaddr's (without
knowing the address family) into the ast_sockaddr structure.

Change-Id: Iee604e96e9096c79b477d6e5ff310cf0b06dae86
Signed-off-by: Jaco Kroon <jaco@uls.co.za>
2020-01-10 01:55:48 -06:00
Friendly Automation 34746220a0 Merge "res_pjsip_pubsub: Add ability to persist generator state information." 2020-01-09 16:23:40 -06:00
Joshua Colp a55d403429 Merge "res_pjsip_endpoint_identifier_ip.c: Add port matching support" 2020-01-09 15:08:04 -06:00
Joshua C. Colp 4e7adbd8f4 res_pjsip_pubsub: Add ability to persist generator state information.
Some body generators, such as dialog-info+xml, require storing state
information which is then conveyed in the NOTIFY request itself. Up
until now there was no way for such body generators to persist this
information.

Two new API calls have been added to allow body generators to set and
get persisted data. This data is persisted out alongside the normal
persistence information and allows the body generator to restore
state information or to simply use this for normal storage of state.
State is stored in the form of JSON and it is up to the body
generator to interpret this as needed.

The dialog-info+xml body generator has been updated to take advantage
of this to persist the version number.

ASTERISK-27759

Change-Id: I5fda56c624fd13c17b3c48e0319b77079e9e27de
2020-01-08 09:48:18 -06:00
Joshua Colp bf0247ae7c Merge "stasis.c: Use correct topic name in stasis_topic_pool_delete_topic" 2020-01-08 09:41:18 -06:00
Sean Bright 312abaa1fe res_pjsip_endpoint_identifier_ip.c: Add port matching support
Adds source port matching support when IP matching is used:

  [example]
  type = identify
  match = 1.2.3.4:5060/32, 1.2.3.4:6000/32, asterisk.org:4444

If the IP matches but the source port does not, we reject and search for
alternatives. SRV lookups are still performed if enabled (srv_lookups = yes),
unless the configured FQDN includes a port number in which case just a host
lookup is performed.

ASTERISK-28639 #close
Reported by: Mitch Claborn

Change-Id: I256d5bd5d478b95f526e2f80ace31b690eebba92
2020-01-08 08:37:53 -06:00
George Joseph 1c9ddad4db stasis.c: Use correct topic name in stasis_topic_pool_delete_topic
When a topic is created for an object, its name is only
<object>:<uniqueid>
For example:
bridge:cb68b3a8-fce7-4738-8a17-d7847562f020

When a topic is added to a pool, its name has the pool's topic
name prepended.  For example:
bridge:all/bridge:cb68b3a8-fce7-4738-8a17-d7847562f020

The topic_pool_entry's name however, is only what was passed
in to stasis_topic_pool_get_topic which is
bridge:cb68b3a8-fce7-4738-8a17-d7847562f020
That's actually correct because the entry is qualified by the
pool that's in.

When you're ready to delete the entry from the pool, you retrieve
the tropic name from the object but since it now has the pool's
topic name prepended, it won't be found in the pool container.

Fix:

* Modified stasis_topic_pool_delete_topic() to skip past the
pool topic's name, if it was prepended to the topic name,
before searching the container for a pool entry.

ASTERISK-28633
Reported by: Joeran Vinzens

Change-Id: I4396aa69dd83e4ab84c5b91b39293cfdbcf483e6
2020-01-06 09:51:42 -06:00
Sean Bright 87110c1bdf websocket: Consider pending SSL data when waiting for socket input
When TLS is in use, checking the readiness of the underlying FD is insufficient
for determining if there is data available to be read. So before polling the
FD, check if there is any buffered data in the TLS layer and use that first.

ASTERISK-28562 #close
Reported by: Robert Sutton

Change-Id: I95fcb3e2004700d5cf8e5ee04943f0115b15e10d
2020-01-02 15:51:37 -06:00
Jean Aunis 034ac357ad ARI: Ability to inhibit COLP frames when adding channels to a bridge
This patch adds a new flag "inhibitConnectedLineUpdates" to the 'addChannel'
operation in the Bridges REST API. When set, this flag avoids generating COLP
frames when the specified channels enter the bridge.

ASTERISK-28629

Change-Id: Ib995d4f0c6106279aa448b34b042b68f0f2ca5dc
2020-01-02 15:06:15 +00:00
George Joseph be93537382 Merge "res_fax: wrap v21 detected Asterisk initiated negotiation with config option" 2020-01-02 08:43:21 -06:00
Friendly Automation 07b7c6f50a Merge "confbridge: Add support for specifying maximum sample rate." 2019-12-19 10:00:43 -06:00
Joshua C. Colp ed394ce5b1 configure: Add check for MySQL client bool and my_bool type usage.
Instead of trying to use the defined MySQL client version from the
header use a configure check to determine whether the bool or my_bool
type should be used for defining a boolean.

ASTERISK-28604

Change-Id: Id2225b3785115de074c50c123ff1a68005b4a9c7
2019-12-16 10:36:25 -06:00
Joshua C. Colp 89b7144fbd confbridge: Add support for specifying maximum sample rate.
ConfBridge has the ability to move between different sample
rates for mixing the conference bridge. Up until now there has
only been the ability to set the conference bridge to mix at
a specific sample rate, or to let it move between sample rates
as necessary. This change adds the ability to configure a
conference bridge with a maximum sample rate so it can move
between sample rates but only up to the configured maximum.

ASTERISK-28658

Change-Id: Idff80896ccfb8a58a816e4ce9ac4ebde785963ee
2019-12-16 09:54:21 -06:00
Kevin Harwell b6f5607359 res_fax: wrap v21 detected Asterisk initiated negotiation with config option
A previous patch:

Gerrit Change-Id: I73bb24799bfe1a48adae9c034a2edbae54cc2a39

made it so a T.38 Gateway tries to negotiate with both sides by sending T.38
negotiation request to both endpoints supported T.38 versus the previous
behavior of forwarding negotiation to the "other" channel once a preamble
was detected.

This had the unfortunate side effect of breaking some setups. Specifically
ones that set the max datagram option on an endpoint configuration (configured
max datagram was not propagated since Asterisk now initiates negotiations).

This patch adds a configuration option, "negotiate_both", that when enabled
makes it so Asterisk initiates the negotiation requests to both endpoints vs.
the previous behavior of waiting, and forwarding the request.

The default is disabled keeping with the old behavior.

ASTERISK-28660

Change-Id: I5deb875f3485e20bc75119ec743090655d864a1a
2019-12-13 14:24:10 -06:00
Jaco Kroon 32160cb456 ACL: ast_apply_acl_nolog - identical to ast_apply_acl but without logging.
Due to use in res_rtp_asterisk there is a need to be able to apply an
ACL without logging any invalid/denies.  It's probably sensible to at
least validate the ACL once directly after load and report invalid ACLs.

Change-Id: I256169229d945ca7c1bbf228fc492d91df345843
Signed-off-by: Jaco Kroon <jaco@uls.co.za>
2019-12-12 02:14:55 -06:00
Joshua Colp cd3a2a478f Merge "core: Improve MALLOC_DEBUG for frames." 2019-12-02 06:45:24 -06:00
Kevin Harwell bdd785d31c various files - fix some alerts raised by lgtm code analysis
This patch fixes several issues reported by the lgtm code analysis tool:

https://lgtm.com/projects/g/asterisk/asterisk

Not all reported issues were addressed in this patch. This patch mostly fixes
confirmed reported errors, potential problematic code points, and a few other
"low hanging" warnings or recommendations found in core supported modules.
These include, but are not limited to the following:

* innapropriate stack allocation in loops
* buffer overflows
* variable declaration "hiding" another variable declaration
* comparisons results that are always the same
* ambiguously signed bit-field members
* missing header guards

Change-Id: Id4a881686605d26c94ab5409bc70fcc21efacc25
2019-11-18 08:30:45 -06:00
Corey Farrell 8a1f30af04
core: Improve MALLOC_DEBUG for frames.
* Pass caller information to frame allocation functions.
* Disable caching as it interfers with MALLOC_DEBUG reporting.
* Stop using ast_calloc_cache.

Change-Id: Id343cd80a3db941d2daefde2a060750fea8cd260
2019-11-08 10:20:13 -05:00
Sean Bright a4222614c4 utils.h: Set lower bound for thread stack size to PTHREAD_STACK_MIN
ASTERISK-28590 #close

Change-Id: I51abce00c04d0a06550bda5205580705185b9c1c
2019-10-18 13:53:40 -05:00
Kevin Harwell 2970a13fb8 res_pjsip/res_pjsip_mwi: use centralized serializer pools
Both res_pjsip and res_pjsip_mwi made use of serializer pools. However, they
both implemented their own serializer pool functionality that was pretty much
identical in each of the source files. This patch removes the duplicated code,
and uses the new 'ast_serializer_pool' object instead.

Additionally res_pjsip_mwi enables a shutdown group on the pool since if the
timing was right the module could be unloaded while taskprocessor threads still
needed to execute, thus causing a crash.

Change-Id: I959b0805ad024585bbb6276593118be34fbf6e1d
2019-10-07 16:54:16 -05:00
Kevin Harwell c0efe19cec serializer: move/add asterisk serializer pool functionality
Serializer pools have previously existed in Asterisk. However, for the most
part the code has been duplicated across modules. This patch abstracts the
code into an 'ast_serializer_pool' object. As well the code is now centralized
in serializer.c/h.

In addition serializer pools can now optionally be monitored by a shutdown
group. This will prevent the pool from being destroyed until all serializers
have completed.

Change-Id: Ib1e906144b90ffd4d5ed9826f0b719ca9c6d2971
2019-10-07 16:54:16 -05:00
Torrey Searle b43cdc7f1e channel/chan_pjsip: add dialplan function for music on hold
Add a new dialplan function PJSIP_MOH_PASSTHROUGH that allows
the on-hold behavior to be controlled on a per-call basis

ASTERISK-28542 #close

Change-Id: Iebe905b2ad6dbaa87ab330267147180b05a3c3a8
2019-10-01 02:06:45 -05:00
Corey Farrell 725e991faf
core: Add AO2_ALLOC_OPT_NO_REF_DEBUG option.
Previous to this patch passing a NULL tag to ao2_alloc or ao2_ref based
functions would result in the reference not being logged under
REF_DEBUG.  This could sometimes cause inaccurate logging if NULL was
accidentally passed to a reference action.  Now reference logging is
only disabled by option passed to the allocation method.

Change-Id: I3c17d867d901d53f9fcd512bef4d52e342637b54
2019-09-23 13:34:14 -04:00
Joshua Colp e79a3b428a Merge "func_jitterbuffer: Add audio/video sync support." 2019-09-19 08:23:15 -05:00
Joshua Colp 7298a785ad func_jitterbuffer: Add audio/video sync support.
This change adds support to the JITTERBUFFER dialplan function
for audio and video synchronization. When enabled the RTCP SR
report is used to produce an NTP timestamp for both the audio and
video streams. Using this information the video frames are queued
until their NTP timestamp is equal to or behind the NTP timestamp
of the audio. The audio jitterbuffer acts as the leader deciding
when to shrink/grow the jitterbuffer when adaptive is in use. For
both adaptive and fixed the video buffer follows the size of the
audio jitterbuffer.

ASTERISK-28533

Change-Id: I3fd75160426465e6d46bb2e198c07b9d314a4492
2019-09-18 20:22:50 +00:00
Florian Floimair c18983207d core: Add H.265/HEVC passthrough support
This change adds H.265/HEVC as a known codec and creates a cached
"h265" media format for use.

Note that RFC 7798 section 7.2 also describes additional SDP
parameters. Handling of these is not yet supported.

ASTERISK-28512

Change-Id: I26d262cc4110b4f7e99348a3ddc53bad0d2cd1f2
2019-09-17 13:42:26 +02:00
Sean Bright 32ce6e9a06 channels: Allow updating variable value
When modifying an already defined variable in some channel drivers they
add a new variable with the same name to the list, but that value is
never used, only the first one found.

Introduce ast_variable_list_replace() and use it where appropriate.

ASTERISK-23756 #close
Patches:
  setvar-multiplie.patch submitted by Michael Goryainov

Change-Id: Ie1897a96c82b8945e752733612ee963686f32839
2019-09-12 16:00:07 -05:00
Ben Ford 0e56643d9f res_rtp: Add unit tests for RTCP stats.
Added unit tests for RTCP video stats. These tests include NACK, REMB,
FIR/FUR/PLI, SR/RR/SDES, and packet loss statistics. The REMB and FIR
tests are currently disabled due to a bug. We expect to receive a
compound packet, but the code sends this out as a single packet, which
the browser accepts, but makes Asterisk upset.

While writing these tests, I noticed an issue with NACK as well. Where
it is handling a received NACK request, it was reading in only the first
8 bits of following packets that were also lost. This has been changed
to the correct value of 16 bits.

Also made a minor fix to the data buffer unit test.

Change-Id: I56107c7411003a247589bbb6086d25c54719901b
2019-09-10 13:11:07 -05:00
George Joseph 9e015713cc dns_core: Create new API ast_dns_resolve_ipv6_and_ipv4
The new function takes in a pointer to an ast_sockaddr structure,
a hostname and an optional port and then dispatches parallel
"AAAA" and "A" record queries.  If an "AAAA" record is returned,
it's parsed into the ast_sockaddr structure along with the port
if it was supplied.  If no "AAAA" record was returned, the
first "A" record returned (if any) is parsed instead.

This is a synchronous call.  If you need asynchronous lookups,
use ast_dns_query_set_resolve_async and roll your own.

Change-Id: I194b0b0e73da94b35cc35263a868ffac3a8d0a95
2019-08-22 07:33:48 -05:00
Sean Bright 64906c4c9b audiohook.c: Substitute silence for unavailable audio frames
There are 4 scenarios to consider when capturing audio from a channel
with an audiohook:

 1. There is no rx and no tx audio, so return nothing.
 2. There is rx but no tx audio, so return rx.
 3. There is tx but no rx audio, so return tx.
 4. There is rx and tx audio, so mix them and return.

The file passed as the primary argument to MixMonitor will be written to
in scenarios 2, 3, and 4. However, if you pass the r() and t() options
to MixMonitor, a frame will only be written to the r() file if there was
rx audio and a frame will only be written to the t() file if there was
tx audio.

If you subsequently take the r() and t() files and try to mix them, the
sides of the conversation will 'drift' and be non-representative of the
user experience.

This patch adds a new 'S' option to MixMonitor that injects a frame of
silence on either the r() side or the t() side of the channel so that
when later mixed, there is no such drift.

Change-Id: Ibf5ed73a811087727bd561a89a59f4447b4ee20e
2019-08-20 08:44:00 -05:00
Joshua Colp 261646c1c4 cdr / cel: Use event time at event creation instead of processing.
When updating times on CDR or CEL records using the time at which
it is done can result in times being incorrect if the system is
heavily loaded and stasis message processing is delayed.

This change instead makes it so CDR and CEL use the time at which
the stasis messages that drive the systems are created. This allows
them to be backed up while still producing correct records.

ASTERISK-28498

Change-Id: I6829227e67aefa318efe5e183a94d4a1b4e8500a
2019-08-07 07:48:32 -03:00
George Joseph 8d10028b98 Update master for Asterisk 18
Change-Id: I8b8ed97001446fab0c14d7c89391ee572fb29dd6
2019-07-29 10:04:48 -06:00
Walter Doekes 3c6f11992b sched: Don't allow ast_sched_del to deadlock ast_sched_runq from same thread
When fixing ASTERISK~24212, a change was done so a scheduled callback could not
be removed while it was running. The caller of ast_sched_del would have to wait.

However, when the caller of ast_sched_del is the callback itself (however wrong
this might be), this new check would cause a deadlock: it would wait forever
for itself.

This changeset introduces an additional check: if ast_sched_del is called
by the callback itself, it is immediately rejected (along with an ERROR log and
a backtrace). Additionally, the AST_SCHED_DEL_UNREF macro is adjusted so the
after-ast_sched_del-refcall function is only run if ast_sched_del returned
success.

This should fix the following spurious race condition found in chan_sip:
- thread 1: schedule sip_poke_peer_now (using AST_SCHED_REPLACE)
- thread 2: run sip_poke_peer_now
- thread 2: blank out sched-ID (too soon!)
- thread 1: set sched-ID (too late!)
- thread 2: try to delete the currently running sched-ID

After this fix, an ERROR would be logged, but no deadlocks (in do_monitor) nor
excess calls to sip_unref_peer(peer) (causing double frees of rtp_instances and
other madness) should occur.

(Thanks Richard Mudgett for reviewing/improving this "scary" change.)

Note that this change does not fix the observed race condition: unlocked
access to peer->pokeexpire (and potentially other scheduled items in chan_sip),
causing AST_SCHED_DEL_UNREF to look at a changing id. But it will make the
deadlock go away. And in the observed case, it will not have adverse affects
(like memory leaks) because the scheduled item is removed through a different
path.

ASTERISK-28282

Change-Id: Ic26777fa0732725e6ca7010df17af77a012aa856
2019-07-18 01:22:55 -06:00
Kevin Harwell b31ac83900 mwi: Update the MWI core to use stasis_state API
** Note **

This patch is meant to be the minimum needed in order for the MWI core to use
the now underlying stasis_state module. As such it does not completely remove
its reliance on the stasis_cache. Doing so has allowed current consumers to
not have to change, and update those code paths for this patch. When time
allows, subsequent patches can/will be made to those consumers to take advantage
of some of the new MWI API included here. Thus, eventually and ultimately
removing MWI dependency on the stasis_cache.

** End Note **

This patch makes it so the MWI core now takes advantage of the new stasis_state
API. Consumers of MWI should no longer need to depend upon stasis topic pooling,
and the stasis cache directly. Similar functionality and implementation details
have now been pushed into the stasis_state module. However, all MWI state should
be accessed via the MWI API itself.

As such a few new methods, and constructs have been added to the MWI core that
facilitate consumer publishing, subscribing, and iterating over MWI state data.

* ast_mwi_subscriber *

Created via ast_mwi_add_subscriber, a subscriber subscribes to a given mailbox
in order to receive updates about the given mailbox. Adding a subscriber will
create the underlying topic, and associated state data if those do not already
exist for it. The topic, and last known state data is guaranteed to exist for
the lifetime of the subscriber.

* ast_mwi_publisher *

Before publishing to a particular topic a publisher should be created. This can
be achieved by using ast_mwi_add_publisher. Publishing to a mailbox should then
be done using one of the MWI publish functions. This ensures the message is
published to the appropriate topic, and the last known state is maintained.

* ast_mwi_observer *

Add an observer in order to watch for particular MWI module related events. For
instance if a submodule needs to know when a subscription is added to any
mailbox an observer can be added to watch for that.

* other *

Urgent message count is now part of the published MWI state object. Also state
can be iterated over using defined callbacks.

ASTERISK-28442

Change-Id: I93f935f9090cd5ddff6d4bc80ff90703c05cf776
2019-07-08 18:12:49 -05:00
Kevin Harwell 363bafc29e stasis_state: Add new stasis_state module
This new module describes an API that can be thought of as a combination of
stasis topic pools, and caching. Except, hopefully done in a more efficient
and less memory "leaky" manner.

The API defines methods, and data structures for managing, and tracking
published message state through stasis. By adding a subscriber or publisher,
consumers can more easily track the lifetime of the contained state. For
instance, when no more publishers and/or subscribers have need of the topic,
and associated state its data is removed from the managed container.

* stasis_state_manager *

The manager stores and well, manages state data. Each state is an association
of a unique stasis topic, and the last known published stasis message on that
topic. There is only ever one managed state object per topic. For each topic
all messages are forwarded to an "all" topic also maintained by the manager.

* stasis_state_subscriber *

Topic and state can be created, or referenced within the manager by adding a
stasis_state_subscriber. When adding a subscriber if no state currently exists
new managed state is immediately created. If managed state already exists then
a new subscriber is created referencing that state. The managed state is
guaranteed to live throughout the subscriber's lifetime. State is only removed
from the manager when no other entities require it.

* stasis_state_publisher *

Topic and state can be created, or referenced within the manager by also adding
a stasis_state_publisher. When adding a publisher if no state currently exists
new managed state is created. If managed state already exists then a new
publisher is created referencing that state. The managed state is guaranteed to
live throughout the publisher's lifetime. State is only removed from the
manager when no other entities require it.

* stasis_state_observer *

Some modules may wish to watch for, and react to managed state events. By
registering a state observer, and implementing handlers for the desired
callbacks those modules can do so.

* other *

Callbacks also exist that allow consumers to iterate over all, or some of the
managed state.

ASTERISK-28442

Change-Id: I7a4a06685a96e511da9f5bd23f9601642d7bd8e5
2019-06-28 11:41:15 -05:00
Friendly Automation 0a54b6c26a Merge "app_confbridge: Attended transfer event fixup" 2019-06-21 11:24:35 -05:00
George Joseph f3e5419d41 app_confbridge: Attended transfer event fixup
When a channel already in a conference bridge is attended transfered
to another extension, or when an existing call is attended
transferred into a conference bridge, we now generate ConfbridgeJoin
and ConfbridgeLeave events for the entering and departing channels.

Change-Id: Id7709cfbceb26fbcb828b2d0d2a6b2fbeaf028e1
2019-06-13 14:07:16 -06:00
Joshua Colp a8e5cf557d res_rtp_asterisk: Add support for DTLS packet fragmentation.
This change adds support for larger TLS certificates by allowing
OpenSSL to fragment the DTLS packets according to the configured
MTU. By default this is set to 1200.

This is accomplished by implementing our own BIO method that
supports MTU querying. The configured MTU is returned to OpenSSL
which fragments the packet accordingly. When a packet is to be
sent it is done directly out the RTP instance.

ASTERISK-28018

Change-Id: If2d5032019a28ffd48f43e9e93ed71dbdbf39c06
2019-06-13 07:51:57 -06:00
Matt Jordan 0760af71ad res_prometheus: Add Asterisk channel metrics
This patch adds basic Asterisk channel statistics to the res_prometheus
module. This includes:

* asterisk_calls_sum: A running sum of the total number of
  processed calls

* asterisk_calls_count: The current number of calls

* asterisk_channels_count: The current number of channels

* asterisk_channels_state: The state of any particular channel

* asterisk_channels_duration_seconds: How long a channel has existed,
  in seconds

In all cases, enough information is provided with each channel metric
to determine a unique instance of Asterisk that provided the data, as
well as the name, type, unique ID, and - if present - linked ID of each
channel.

ASTERISK-28403

Change-Id: I0db306ec94205d4f58d1e7fbabfe04b185869f59
2019-05-21 11:03:13 -05:00
Matt Jordan c50f29dfad Add core Prometheus support to Asterisk
Prometheus is the defacto monitoring tool for containerized applications.
This patch adds native support to Asterisk for serving up Prometheus
compatible metrics, such that a Prometheus server can scrape an Asterisk
instance in the same fashion as it does other HTTP services.

The core module in this patch provides an API that future work can build
on top of. The API manages metrics in one of two ways:
(1) Registered metrics. In this particular case, the API assumes that
    the metric (either allocated on the stack or on the heap) will have
    its value updated by the module registering it at will, and not
    just when Prometheus scrapes Asterisk. When a scrape does occur,
    the metrics are locked so that the current value can be retrieved.
(2) Scrape callbacks. In this case, the API allows consumers to be
    called via a callback function when a Prometheus initiated scrape
    occurs. The consumers of the API are responsible for populating
    the response to Prometheus themselves, typically using stack
    allocated metrics that are then formatted properly into strings
    via this module's convenience functions.

These two mechanisms balance the different ways in which information is
generated within Asterisk: some information is generated in a fashion
that makes it appropriate to update the relevant metrics immediately;
some information is better to defer until a Prometheus server asks for
it.

Note that some care has been taken in how metrics are defined to
minimize the impact on performance. Prometheus's metric definition
and its support for nesting metrics based on labels - which are
effectively key/value pairs - can make storage and managing of metrics
somewhat tricky. While a naive approach, where we allow for any number
of labels and perform a lot of heap allocations to manage the information,
would absolutely have worked, this patch instead opts to try to place
as much information in length limited arrays, stack allocations, and
vectors to minimize the performance impacts of scrapes. The author of
this patch has worked on enough systems that were driven to their knees
by poor monitoring implementations to be a bit cautious.

Additionally, this patch only adds support for gauges and counters.
Additional work to add summaries, histograms, and other Prometheus
metric types may add value in the future. This would be of particular
interest if someone wanted to track SIP response types.

Finally, this patch includes unit tests for the core APIs.

ASTERISK-28403

Change-Id: I891433a272c92fd11c705a2c36d65479a415ec42
2019-05-20 20:33:58 -05:00
Kevin Harwell def6bbc96b conversions.c: Add conversions for largest max sized integer
Added a conversion for umax (largest maximum sized integer allowed). Adjusted
the other current conversion functions (uint and ulong) to be derivatives of
the umax conversion since they are simply subsets of umax.

Also made the negative check move the pointer on spaces since strtoumax does it
anyways.

Change-Id: I56c2ef2629d49b524c8df58af12951c181f81f08
2019-05-06 15:31:09 -06:00
Friendly Automation fca9f0a4ad Merge "app_confbridge: Add "all" variants of REMB behavior." 2019-05-03 10:54:13 -05:00
Friendly Automation a6d9c4f11a Merge "stasis: Call callbacks when imparting fails" 2019-05-03 10:13:33 -05:00
Holger Hans Peter Freyther 3087c82eb6 stasis: Call callbacks when imparting fails
After a bridge has been deleted the stasis control will depart
the channel and might attempt to re-add it to the dial bridge.

The later can fail and this can lead to a situation that the stasis
control is unlinked but the after_bridge_cb_failed cb is executed trying
to access a dangling control object.

Fix it by calling the after_cb's before bridge_channel_impart_signal.

ASTERISK-26718

Change-Id: Ib4e8f70d7a21bd54afe3cb51cc6717ef7c355496
2019-05-02 09:31:29 -06:00
Joshua Colp 80dba268ea app_confbridge: Add "all" variants of REMB behavior.
When producing a combined REMB value the normal behavior
is to have a REMB value which is unique for each sender
based on all of their receivers. This can result in one
sender having low bitrate while all the rest are high.

This change adds "all" variants which produces a bridge
level REMB value instead. All REMB reports are combined
together into a single REMB value that is the same for
each sender.

ASTERISK-28401

Change-Id: I883e6cc26003b497c8180b346111c79a131ba88c
2019-05-02 07:29:08 -06:00
Joshua Colp 6bb70c93f1 rtp: Add support for transport-cc in receiver direction.
The transport-cc draft is a mechanism by which additional information
about packet reception can be provided to the sender of packets so
they can do sender side bandwidth estimation. This is accomplished
by having a transport specific sequence number and an RTCP feedback
message. This change implements this in the receiver direction.

For each received RTP packet where transport-cc is negotiated we store
the time at which the RTP packet was received and its sequence number.
At a 1 second interval we go through all packets in that period of time
and use the stored time of each in comparison to its preceding packet to
calculate its delta. This delta information is placed in the RTCP
feedback message, along with indicators for any packets which were not
received.

The browser then uses this information to better estimate available
bandwidth and adjust accordingly. This may result in it lowering the
available send bandwidth or adjusting how "bursty" it can be.

ASTERISK-28400

Change-Id: I654a2cff5bd5554ab94457a14f70adb71f574afc
2019-05-01 05:13:14 -06:00
Friendly Automation c2326155aa Merge "mwi core: Move core MWI functionality into its own files" 2019-04-30 10:41:10 -05:00
Antoni Goldstein 8e21c25ce5 app_dial.c: RINGTIME, PROGRESSTIME and ms resolution dial timings
Added RINGTIME, RINGTIME_MS, PROGRESSTIME, PROGRESSTIME_MS variables filled
at the earliest received PROGRESS or RINGING.
Added millisecond versions of DIALEDTIME and ANSWEREDTIME.

Added millisecond versions of ast_channel_get_up_time and
ast_channel_get_duration in channel.c.

ASTERISK-28363

Change-Id: If95f1a7d8c4acbac740037de0c6e3109ff6620b1
2019-04-24 06:27:41 -06:00
Kevin Harwell ff0d0ac23a mwi core: Move core MWI functionality into its own files
There is enough MWI functionality to warrant it having its own 'c' and header
files. This patch moves all current core MWI data structures, and functions
into the following files:

main/mwi.h
main/mwi.c

Note, code was simply moved, and not modified. However, this patch is also in
preparation for core MWI changes, and additions to come.

Change-Id: I9dde8bfae1e7ec254fa63166e090f77e4d3097e0
2019-04-23 17:40:15 -05:00
Friendly Automation 3c106814d5 Merge "loader: support for permanent dlopen()" 2019-04-19 09:06:03 -05:00
Dan Cropp cffa2a74cb res_pjsip: Added a norefersub configuration setting
Added a new PJSIP global setting called norefersub.
Default is true to keep support working as before.

res_pjsip_refer:  Configures PJSIP norefersub capability accordingly.

Checks the PJSIP global setting value.
If it is true (default) it adds the norefersub capability to PJSIP.
If it is false (disabled) it does not add the norefersub capability
to PJSIP.

This is useful for Cisco switches that do not follow RFC4488.

ASTERISK-28375 #close
Reported-by: Dan Cropp

Change-Id: I0b1c28ebc905d881f4a16e752715487a688b30e9
2019-04-17 10:18:40 -05:00
George Joseph 1ab20c5d91 Merge "stasis.c: Added topic_all container" 2019-04-08 10:53:18 -05:00
George Joseph 2f13cdd315 Merge "res/res_ari: Added ARI resource /ari/channels/{channelId}/rtp_statistics" 2019-04-08 10:51:45 -05:00
Friendly Automation 6a83c99c36 Merge "main/json.c: Added app_name, app_data to channel type" 2019-04-08 10:32:16 -05:00
Sebastian Kemper ccac55b894
loader: support for permanent dlopen()
Asterisk assumes that dlopen() will always run the constructor of a
shared library and every dlclose() will run its destructor. But dlopen()
may be permanent, meaning the constructor will only be run once, as is
the case with musl libc.

With a permanent dlopen() the Asterisk module loader does not work
correctly, because it's expectations regarding when the constructors and
destructors are run are not met. In fact a segmentation fault will occur
when the first module is "re-opened" that has AST_MODFLAG_GLOBAL_SYMBOLS
set (the dlopen() does not call the constructor, resource_being_loaded
is not set to NULL, then strlen is called with NULL instead of a string,
see issue ASTERISK-28319).

This commit adds code to the loader that will manually run the
constructors/destructors of the (non-builtin) modules where needed. To
achieve this a new ao2 container (linked list) is started and filled
with objects that contain the names of the modules and the pointers to
their respective info structs.

This behavior can be activated when configuring Asterisk
(--enable-permanent-dlopen). By default this is disabled, of course.

ASTERISK-28319 #close

Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
Change-Id: I86693a0ecf25d5ba81c73773a03df4abc3426875
2019-04-04 15:14:21 -04:00
sungtae kim 30d568ddec stasis.c: Added topic_all container
Added topic_all container for centralizing the topic. This makes more
easier to managing the topics.

Added cli commands.
stasis show topics : It shows all registered topics.
stasis show topic <name> : It shows speicifed topic's detail info.

ASTERISK-28264

Change-Id: Ie86d125d2966f93de74ee00f47ae6fbc8c081c5f
2019-03-28 00:57:16 +01:00
sungtae kim 76768ad6ce main/json.c: Added app_name, app_data to channel type
It was difficult to check the channel's current application and
parameters using ARI for current channels. Added app_name, app_data
items to show the current application information.

ASTERISK-28343

Change-Id: Ia48972b3850e5099deab0faeaaf51223a1f2f38c
2019-03-26 21:16:47 +01:00
Matthew Fredrickson 41a2662e16 main/taskprocessor: Increase max name length of taskprocessors
Since the new names went in, the maximum taskprocessor name is too
short.  This patch increases the name field to a length to better
handle the new names.

Change-Id: I32f32d6926f25c8ef5a91303fd2988d2c2858877
2019-03-22 19:46:34 +00:00
George Joseph 7e77815ad1 sorcery.c: Sorcery enhancements for wizard management
Added ability to specifiy a wizard is read-only when applying
it to a specific object type.  This allows you to specify
create, update and delete callbacks for the wizard but limit
which object types can use them.

Added the ability to allow an object type to have multiple
wizards of the same type.  This is indicated when a wizard
is added to a specific object type.

Added 3 new sorcery wizard functions:

* ast_sorcery_object_type_insert_wizard which does the same thing
  as the existing ast_sorcery_insert_wizard_mapping function but
  accepts the new read-only and allot-duplicates flags and also
  returns the ast_sorcery_wizard structure used and it's internal
  data structure. This allows immediate use of the wizard's
  callbacks without having to register a "wizard mapped" observer.

* ast_sorcery_object_type_apply_wizard which does the same
  thing as the existing ast_sorcery_apply_wizard_mapping function
  but has the added capabilities of
  ast_sorcery_object_type_insert_wizard.

* ast_sorcery_object_type_remove_wizard which removes a wizard
  matching both its name and its original argument string.

* The original logic in __ast_sorcery_insert_wizard_mapping was moved
  to __ast_sorcery_object_type_insert_wizard and enhanced for the
  new capabilities, then __ast_sorcery_insert_wizard_mapping was
  refactored to just call __ast_sorcery_insert_wizard_mapping.

* Added a unit test to test_sorcery.c to test the read-only
  capability.

Change-Id: I40f35840252e4313d99e11dbd80e270a3aa10605
2019-03-18 11:39:42 -06:00
Joshua Colp 4a9e30e286 Merge "vector: Add AST_VECTOR_COMPACT() to reclaim wasted space" 2019-03-18 06:31:46 -05:00
Joshua Colp a284587460 Merge "Revert "Test_cel: Fails when DONT_OPTIMIZE is off"" 2019-03-18 06:05:31 -05:00
Sean Bright 0fac5bcbe5 vector: Add AST_VECTOR_COMPACT() to reclaim wasted space
This might be useful in situations where you are loading an undetermined number
of items into a vector and don't want to keep (potentially) 2x the necessary
memory around indefinitely.

Change-Id: I9711daa0fe01783fc6f04c5710eba84f2676d7b9
2019-03-15 14:53:39 -06:00
Joshua C. Colp a145f83d30 Merge "stasis: Improve topic/subscription names and statistics." 2019-03-14 09:22:14 -05:00
sungtae kim 71c0c7f631 res/res_ari: Added ARI resource /ari/channels/{channelId}/rtp_statistics
Added ARI resource for channel statistics.
GET /ari/channels/{channelId}/rtp_statistics : It returns given
channel's rtp statistics detail.

ASTERISK-28320

Change-Id: I4343eec070438cec13f2a4f22e7fd9e574381376
2019-03-13 23:00:03 +01:00
Corey Farrell a40198a4d4
Revert "Test_cel: Fails when DONT_OPTIMIZE is off"
This reverts commit 1c8378bbc9.

Change-Id: I1b9227b263c3dc4246a50aebf52a7640a0f7ea07
2019-03-13 09:30:40 -04:00
Friendly Automation 4114c2bc3c Merge "chan_pjsip: add a flag to ignore 183 responses if no SDP present" 2019-03-12 10:10:12 -05:00
Joshua Colp 0231dd6ae7 stasis: Improve topic/subscription names and statistics.
Topic names now follow: <subsystem>:<functionality>[/<object>]

This ensures that they are all unique, and also provides better
insight in to what each topic is for.

Subscriber ids now also use the main topic name they are
subscribed to and an incrementing integer as their identifier to
make it easier to understand what the subscription is primarily
responsible for.

Both the CLI commands for listing topic and subscription statistics
now sort to make it a bit easier to see what is going on.

Subscriptions will now show all topics that they are receiving messages
from, not just the main topic they were subscribed to.

ASTERISK-28335

Change-Id: I484e971a38c3640f2bd156282e532eed84bf220d
2019-03-11 11:39:35 -03:00
Torrey Searle 4661c08549 chan_pjsip: add a flag to ignore 183 responses if no SDP present
chan_sip will always ignore 183 responses that do not contain SDP
however, chan_pjsip will currently always translate it into a
183 with SDP.  This new flag allows chan_pjsip to have the same
behavior as chan_sip.

ASTERISK-28322 #close

Change-Id: If81cfaa17c11b6ac703e3d71696f259d86c6be4a
2019-03-08 14:16:30 -05:00
Corey Farrell 9b7b8cb155 jansson: json_pack with new format to verify required runtime version.
Add a json_pack at startup that will fail if runtime links against a
library older than jansson-2.11.

Change-Id: I101aebafe0f9407650206f7c552dad3d69377b5a
2019-03-08 12:47:50 -06:00
George Joseph 5f6890a8f9 Merge "res_stasis: Add ability to switch applications." 2019-03-08 12:43:45 -06:00
George Joseph 9390333862 Merge "Replace calls to strtok() with strtok_r()" 2019-03-08 12:42:44 -06:00
George Joseph 228205f520 Merge "bridging: Add creation timestamps" 2019-03-08 11:11:36 -06:00
Sean Bright 2473b791b9 Replace calls to strtok() with strtok_r()
strtok() uses a static buffer, making it not thread safe.

Also add a #define to cause a compile failure if strtok is used.

Change-Id: Icce265153e1e65adafa8849334438ab6d190e541
2019-03-07 16:44:50 -06:00
Ben Ford 6626df586e res_stasis: Add ability to switch applications.
Added the ability to move between Stasis applications within Stasis.
This can be done by calling 'move' in an application, providing (at
minimum) the channel's id and the application to switch to. If the
application is not registered or active, nothing will happen and the
channel will remain in the current application, and an event will be
triggered to let the application know that the move failed. The event
name is "ApplicationMoveFailed", and provides the "destination" that the
channel was attempting to move to, as well as the usual channel
information. Optionally, a list of arguments can be passed to the
function call for the receiving application. A full example of a 'move'
call would look like this:

client.channels.move(channelId, app, appArgs)

The control object used to control the channel in Stasis can now switch
which application it belongs to, rather than belonging to one Stasis
application for its lifetime. This allows us to use the same control
object instead of having to tear down the current one and create
another.

ASTERISK-28267 #close

Change-Id: I43d12b10045a98a8d42541889b85695be26f288a
2019-03-07 07:53:01 -06:00
sungtae kim 3638c433ac bridging: Add creation timestamps
This small feature will help to checking the bridge's status to
figure out which bridge is in old/zombie or not. Also added
detail items for the 'bridge show *' cli to provide more detail
info. And added creation item to the ARI as well.

ASTERISK-28279

Change-Id: I460238c488eca4d216b9176576211cb03286e040
2019-03-03 05:25:22 -06:00
Kevin Harwell 930a7fe910 res_pjsip_registrar: blocked threads on reliable transport shutdown take 3
When a contact was removed by the registrar it did not always check to see if
the circumstances involved a monitored reliable transport. For instance, if the
'remove_existing' option was set to 'true' then when existing contacts were
removed due to 'max_contacts' being reached, those existing contacts being
removed did not unregister the transport monitor.

Also, it was possible to add more than one monitor on a reliable transport for
a given aor and contact.

This patch makes it so all contact removals done by the registrar also remove
any associated transport monitors if necessary. It also makes it so duplicate
monitors cannot be added for a given transport.

ASTERISK-28213

Change-Id: I94b06f9026ed177d6adfd538317c784a42c1b17a
2019-02-27 17:02:43 -06:00
Joshua C. Colp 18f92cb6f3 Merge "taskprocessor: Enable subsystems and overload by subsystem" 2019-02-26 07:04:15 -06:00
Joshua C. Colp 5f29d3b581 Merge "Core: Increase AST_PBX_MAX_STACK to 512 if not LOW_MEMORY" 2019-02-26 06:08:45 -06:00
Joshua C. Colp cf1b64aaf0 Merge "res_pjsip_session Added rtcp stats result vector into the session" 2019-02-21 06:30:52 -06:00
George Joseph bc8dead610 Core: Increase AST_PBX_MAX_STACK to 512 if not LOW_MEMORY
The current settings AST_PBX_MAX_STACK is 128 entries which is
too low for some FreePBX installations with complex parking
arrangements.  Increased to 512 if LOW_MEMORY is not defined.

ASTERISK-28300

Change-Id: I7c4b540bc92e6642df0f3da639b003f7da8b1299
2019-02-20 12:52:53 -06:00
George Joseph c2adeb9dc2 taskprocessor: Enable subsystems and overload by subsystem
To prevent one subsystem's taskprocessors from causing others
to stall, new capabilities have been added to taskprocessors.

* Any taskprocessor name that has a '/' will have the part
  before the '/' saved as its "subsystem".
  Examples:
  "sorcery/acl-0000006a" and "sorcery/aor-00000019"
  will be grouped to subsystem "sorcery".
  "pjsip/distributor-00000025" and "pjsip/distributor-00000026"
  will bn grouped to subsystem "pjsip".
  Taskprocessors with no '/' have an empty subsystem.

* When a taskprocessor enters high-water alert status and it
  has a non-empty subsystem, the subsystem alert count will
  be incremented.

* When a taskprocessor leaves high-water alert status and it
  has a non-empty subsystem, the subsystem alert count will be
  decremented.

* A new api ast_taskprocessor_get_subsystem_alert() has been
  added that returns the number of taskprocessors in alert for
  the subsystem.

* A new CLI command "core show taskprocessor alerted subsystems"
  has been added.

* A new unit test was addded.

REMINDER: The taskprocessor code itself doesn't take any action
based on high-water alerts or overloading.  It's up to taskprocessor
users to check and take action themselves.  Currently only the pjsip
distributor does this.

* A new pjsip/global option "taskprocessor_overload_trigger"
  has been added that allows the user to select the trigger
  mechanism the distributor uses to pause accepting new requests.
  "none": Don't pause on any overload condition.
  "global": Pause on ANY taskprocessor overload (the default and
  current behavior)
  "pjsip_only": Pause only on pjsip taskprocessor overloads.

* The core pjsip pool was renamed from "SIP" to "pjsip" so it can
  be properly grouped into the "pjsip" subsystem.

* stasis taskprocessor names were changed to "stasis" as the
  subsystem.

* Sorcery core taskprocessor names were changed to "sorcery" to
  match the object taskprocessors.

Change-Id: I8c19068bb2fc26610a9f0b8624bdf577a04fcd56
2019-02-20 11:51:08 -06:00
Kevin Harwell 8681fc9db7 ARI event type filtering
Event type filtering is now enabled, and configurable per application. An app is
now able to specify which events are sent to the application by configuring an
allowed and/or disallowed list(s). This can be done by issuing the following:

PUT /applications/{applicationName}/eventFilter

And then enumerating the allowed/disallowed event types as a body parameter.

ASTERISK-28106

Change-Id: I9671ba1fcdb3b6c830b553d4c5365aed5d588d5b
2019-02-20 09:56:22 -06:00
Kevin Harwell 8f1b3edde8 json.c/strings.c - Add a couple of utility functions
Added 'ast_json_object_string_get' to the JSON wrapper in order to make it a
little easier to retrieve a string field from the JSON object.

Also added an 'ast_strings_equal' function that safely checks (checks for NULLs)
for equality between two strings.

Change-Id: I26f0a16d61537505eb41b4b05ef2e6d67fc2541b
2019-02-19 09:44:58 -06:00
Sungtae Kim 7e1d881d89 res_pjsip_session Added rtcp stats result vector into the session
Currently, the Asterisk's pjsip_session module does not keeping the
rtcp's stats info after it was removed. But by adding the results
vector and keeping it until session is destroying, it can give more
useful information for other modules.

ASTERISK-28253

Change-Id: Ib25c2d3fc4da084aecfde2a82c1b1d733bd64fa5
2019-02-13 23:04:08 +01:00
Joshua Colp 54a912b26d res_odbc: Add basic query logging.
When Asterisk is connected and used with a database the response
time of the database can cause problems in Asterisk if it is long.
Normally the only way to see this problem would be to retrieve a
backtrace from Asterisk and examine where things are blocked, or
examine the database to see if there is any indication of a
problem.

This change adds some basic query logging to make it easier to
investigate such a problem. When logging is enabled res_odbc will
now keep track of the number of queries executed, as well as the
query that has taken the longest time to execute. There is also
an option which will cause a WARNING message to be output if a
query takes longer than a configurable amount of time to execute.

This makes it easier and clearer for users that their database may
be experiencing a problem that could impact Asterisk.

ASTERISK-28277

Change-Id: I173cf4928b10754478a6a8c27dfa96ede0f058a6
2019-02-07 08:23:14 -06:00
George Joseph 7071e9d64c media_index.c: Refactored so it doesn't cache the index
Testing revealed that the cache added no benefit but that it could
consume excessive memory.

Two new index related functions were created:
ast_sounds_get_index_for_file() and ast_media_index_update_for_file()
which restrict index updating to specific sound files.

The original ast_sounds_get_index() and ast_media_index_update()
calls are still available but since they no longer cache the results
internally, developers should re-use an index they may already have
instead of calling ast_sounds_get_index() repeatedly.  If information
for only a single file is needed, ast_sounds_get_index_for_file()
should be called instead of ast_sounds_get_index().

The media_index directory scan code was elimininated in favor of
using the existing ast_file_read_dirs() function.

Since there's no more cache, ast_sounds_index_init now only
registers the sounds cli commands instead of generating the
initial index and subscribing to stasis format register/unregister
messages.

"sounds" is no longer a valid target for the "module reload"
command.

Both the sounds cli commands and the sounds ari resources were
refactored to only call ast_sounds_get_index() once per invocation
and to use ast_sounds_get_index_for_file() when a specific sound
file is requested.

Change-Id: I1cef327ba1b0648d85d218b70ce469ad07f4aa8d
2019-01-28 12:26:58 -07:00
Joshua C. Colp fc8db07208 Merge "Test_cel: Fails when DONT_OPTIMIZE is off" 2019-01-23 11:26:34 -06:00
Chris-Savinovich 1c8378bbc9 Test_cel: Fails when DONT_OPTIMIZE is off
A bug in GCC causes TEST_CEL to return failure under the following
conditions:
1. TEST_FRAMEWORK on
2. DONT_OPTIMIZE off
3. Fedora and Ubuntu
4. GCC 8.2.1
5. Test name: test_cel_dial_pickup
6. There must exist a certain combination of multithreading.
The bug affects arithmetic calculations when the optimization level
is bigger than O1 and the -fpartial-inline flag is on. Provided these
conditions, function ast_str_to_lower() fails to convert to lower case
due to said function being of type force_inline.  The solution is to
remove the "force_inline" type declaration from function ast_str_to_lower()

Change-Id: Ied32e0071f12ed9d5f3b4cdd878b2532a1c769d7
2019-01-22 15:53:01 -06:00
Joshua C. Colp 1323730f6c stasis / manager / ari: Better filter messages.
Previously both AMI and ARI used a default route on
their stasis message router to handle some of the
messages for publishing out their respective
connection. This caused messages to be given to
their subscription that could not be formatted
into AMI or JSON.

This change adds an API call to the stasis message
router which allows a default route to be set as well
as formatters that the default route is expecting.
This allows both AMI and ARI to specify that their
default route only wants messages of their given
formatter. By doing so stasis can more intelligently
filter at publishing time so that they do not receive
messages which will not be turned into AMI or JSON.

ASTERISK-28244

Change-Id: I65272819a53ce99f869181d1d370da559a7d1703
2019-01-17 14:51:47 -04:00
Joshua C. Colp b19210214f Merge "res_pjsip: add option to enable ContactStatus event when contact is updated" 2019-01-14 08:38:14 -06:00
Joshua C. Colp c2e02645b4 Merge "stasis/endpoint: Fix memory leak of channel_ids in ast_endpoint structure." 2019-01-14 08:26:32 -06:00
mohitdhiman d60ee2eeae stasis/endpoint: Fix memory leak of channel_ids in ast_endpoint structure.
During Bridging of two channels if masquerade operation is performed on a
channel (clone channel) which was created with endpoint details
(ast_channel_alloc_with_endpoint()) and the original channel which is created
without endpoint details (ast_channel_alloc()) then both the channels must
exchange their endpoint details or else after masquerade when clone channel
is being destroyed the endpoint cleanup callbacks will be destroyed too and
after call completion unique_id of original channel will still be there in
ast_endpoint structure's channel_ids container.

ASTERISK-28197

Change-Id: I97ce73da390af20fd082fb09d722a6fe9cb2f39d
2019-01-14 17:07:35 +05:30
Alexei Gradinari f0546d1d87 res_pjsip: add option to enable ContactStatus event when contact is updated
The commit I2f97ebfa79969a36a97bb7b9afd5b6268cf1a07d removed sending out
the ContactStatus AMI event when a contact is updated.
Thist change broke things which rely on old behavior.

This patch adds a new PJSIP global configuration option
'send_contact_status_on_update_registration' to be able to preserve old
ContactStatus behavior.
By default new behavior, i.e. the ContactStatus event will not be sent when a
device refreshes its registration.

Change-Id: I706adf7584e7077eb6bde6d9799ca408bc82ce46
2019-01-11 10:52:18 -05:00
Diederik de Groot 7bd30905fd RAII: Change order or variables in clang version
This prevents use-after-scope issues when unwinding the stack,
which happens in reverse order. The varname variable needs to
remain alive for the destruction to be able to access it.
Issue was found using clang + address-sanitizer.

ASTERISK-28232 #close

Change-Id: I00811c34ae910836a5fb6d22304528aef92624db
2019-01-05 18:39:47 +01:00
Corey Farrell 110934706f
stasis: Fix ABI between DEVMODE and non-DEVMODE.
Eliminate differences with DEVMODE prototypes for public functions.

ASTERISK-28212 #close

Change-Id: I872c04842ab6b61e9dd6d37e4166bc619aa20626
2018-12-26 13:36:13 -05:00
George Joseph 3464093f85 Merge "res_pjsip: Patch for res_pjsip_* module load/reload crash" 2018-12-18 10:42:49 -06:00
Joshua C. Colp fe07093660 stasis: Add statistics gathering in developer mode.
This change adds statistics gathering to Stasis topics,
subscriptions, and message types. These can be viewed using
CLI commands and provide insight into how Stasis is used
and how long certain operations take to execute.

These are only available when Asterisk is compiled in
developer mode and do not have any impact under normal
operation.

ASTERISK-28117

Change-Id: I94411b53767f89ee01714daaecf0c2f1666e863f
2018-12-12 12:14:53 -05:00
Friendly Automation 1f8062c6a6 Merge "stasis: Allow filtering by formatter" 2018-12-12 11:09:19 -06:00
Sean Bright 6d69fb3cc2 utils: Wrap socket() and pipe() to reduce syscalls
Some platforms provide an implementation of socket() and pipe2() that allow the
caller to specify that the resulting file descriptors should be non-blocking.

Using these allows us to potentially elide 3 calls into 1 by avoiding extraneous
calls to fcntl() to set the O_NONBLOCK flag afterwards.

In passing, change ast_alertpipe_init() to use pipe2() directly instead of the
wrapper if it is available.

Change-Id: I3ebe654fb549587537161506c6c950f4ab298bb0
2018-12-07 09:06:08 -05:00
George Joseph 3f3dd992a2 stasis: Allow filtering by formatter
A subscriber can now indicate that it only wants messages
that have formatters of a specific type.  For instance,
manager can indicate that it only wants messages that have a
"to_ami" formatter.  You can combine this with the existing
filter for message type to get only messages with specific
formatters or messages of specific types.

ASTERISK-28186

Change-Id: Ifdb7a222a73b6b56c6bb9e4ee93dc8a394a5494c
2018-12-07 08:59:00 -05:00
Chris-Savinovich 58e50e56cb core: Merge malloc_trim patch
We've had multiple opportunities where Richard Mudgett's
malloc_trim patch has been useful. Let's get it
pushed up to gerrit and merged.

Since malloc_trim is only available in libc, an entry is
added to configure.ac to create a definition for
HAVE_MALLOC_TRIM.

Change-Id: Ia38308c550149d9d6eae4ca414a649957de9700c
2018-12-03 14:01:01 -06:00
Sungtae Kim 8644511cbf res_pjsip: Patch for res_pjsip_* module load/reload crash
The session_supplements for the pjsip makes crashes when the module
load/unload.

ASTERISK-28157

Change-Id: I5b82be3a75d702cf1933d8d1417f44aa10ad1029
2018-12-03 08:44:59 -06:00
George Joseph 3667c5e1d2 bridges: Remove reliance on stasis caching
* The bridging core no longer uses the stasis cache for bridge
  snapshots.  The latest bridge snapshot is now stored on the
  ast_bridge structure itself.

* The following APIs are no longer available since the stasis cache
  is no longer used:
    ast_bridge_topic_cached()
    ast_bridge_topic_all_cached()

* A topic pool is now used for individual bridge topics.

* The ast_bridge_cache() function was removed since there's no
  longer a separate container of snapshots.

* A new function "ast_bridges()" was created to retrieve the
  container of all bridges.  Users formerly calling
  ast_bridge_cache() can use the new function to iterate over
  bridges and retrieve the latest snapshot directly from the
  bridge.

* The ast_bridge_snapshot_get_latest() function was renamed to
  ast_bridge_get_snapshot_by_uniqueid().

* A new function "ast_bridge_get_snapshot()" was created to retrieve
  the bridge snapshot directly from the bridge structure.

* The ast_bridge_topic_all() function now returns a normal topic
  not a cached one so you can't use stasis cache functions on it
  either.

* The ast_bridge_snapshot_type() stasis message now has the
  ast_bridge_snapshot_update structure as it's data.  It contains
  the last snapshot and the new one.

* cdr, cel, manager and ari have been updated to use the new
  arrangement.

Change-Id: I7049b80efa88676ce5c4666f818fa18ad1985369
2018-11-26 14:30:02 -07:00
Jenkins2 4ca709768d Merge "stasis: Segment channel snapshot to reduce creation cost." 2018-11-26 14:07:47 -06:00
Joshua Colp a6b37e5c43 Merge "astobj2: Create function to copy weak proxied objects from container." 2018-11-26 13:48:00 -06:00
Joshua Colp 50ac85cb40 stasis: Segment channel snapshot to reduce creation cost.
When a channel snapshot was created it used to be done
from scratch, copying all data (many strings). This incurs
a cost when doing so.

This change segments the channel snapshot into different
components which can be reused if unchanged from the
previous snapshot creation, reducing the cost. In normal
cases this results in some pointers being copied with
reference count being bumped, some integers being set,
and a string or two copied. The other benefit is that it
is now possible to determine if a channel snapshot update
is redundant and thus stop it before a message is published
to stasis.

The specific segments in the channel snapshot were split up
based on whether they are changed together, how often they
are changed, and their general grouping. In practice only
1 (or 0) of the segments actually get changed in normal
operation.

Invalidation is done by setting a flag on the channel when
the segment source is changed, forcing creation of a new
segment when the channel snapshot is created.

ASTERISK-28119

Change-Id: I5d7ef3df963a88ac47bc187d73c5225c315f8423
2018-11-26 12:56:24 -06:00
Joshua Colp d0ccbb3377 stasis: Use an implementation specific channel snapshot cache.
Channels no longer use the Stasis cache for channel snapshots. Instead
they are stored in a hash table in stasis_channels which reduces the
number of Stasis messages created and allows better storage.

As a result the following APIs are no longer available since the stasis
cache is no longer used:
ast_channel_topic_cached()
ast_channel_topic_all_cached()

The ast_channel_cache_all() and ast_channel_cache_by_name() functions
now return an ao2_container of ast_channel_snapshots rather than
a container of stasis_messages therefore you can't (and don't need
to) call stasis_cache functions on it.

The ast_channel_topic_all() function now returns a normal topic not
a cached one so you can't use stasis cache functions on it either.

The ast_channel_snapshot_type() stasis message now has the
ast_channel_snapshot_update structure as it's data. It contains the
last snapshot and the new one.

ast_channel_snapshot_get_latest() still returns the latest snapshot.

The latest snapshot is now stored on the channel itself to eliminate
cache hits when Stasis messages that have the snapshot as a payload
are created.

ASTERISK-28102

Change-Id: I9334febff60a82d7c39703e49059fa3a68825786
2018-11-26 18:43:53 +00:00
Corey Farrell 021ce938ca
astobj2: Remove legacy ao2_container_alloc routine.
Replace usage of ao2_container_alloc with ao2_container_alloc_hash or
ao2_container_alloc_list.  Remove ao2_container_alloc macro.

Change-Id: I0907d78bc66efc775672df37c8faad00f2f6c088
2018-11-21 09:56:16 -05:00
Corey Farrell bc7f4f4db3
astobj2: Create function to copy weak proxied objects from container.
Create ao2_container_dup_weakproxy_objs to perform a similar function to
ao2_container_dup.  This function expects the source container to have
weakproxy objects, inserts the associated non-weak objects into the
destination container.  Orphaned weakproxy objects are ignored.

Create test for this new function and for ao2_weakproxy_find.

Change-Id: I898387f058057e08696fe9070f8cd94ef3a27482
2018-11-21 08:47:27 -05:00
Joshua Colp b7af9c8b19 Merge "stasis: Remove stringfields and lock from change message." 2018-11-20 05:06:01 -06:00
Joshua Colp 614c8a60d7 Merge "stasis: Add internal filtering of messages." 2018-11-19 08:36:50 -06:00
George Joseph ece5f8015f backtrace: Refactor ast_bt_get_symbols so it doesn't crash
We've been seeing crashes in libbfd when we attempt to generate
a stack trace from multiple threads.  It turns out that libbfd
is NOT thread-safe.  It can cache the bfd structure and give it to
multiple threads without protecting itself.  To get around this,
we've added a global mutex around the bfd functions and also have
refactored the use of those functions to be more efficient and
to provide more information about inlined functions.

Also added a few more tests to test_pbx.c.  One just calls
ast_assert() and the other calls ast_log_backtrace().  Neither are
run by default.

WARNING:  This change necessitated changing the return value of
ast_bt_get_symbols() from an array of strings to a VECTOR of
strings.  However, the use of this function outside Asterisk is not
likely.

ASTERISK-28140

Change-Id: I79d02862ddaa2423a0809caa4b3b85c128131621
2018-11-19 05:49:39 -07:00
Joshua C. Colp 56eb18f395 stasis: Remove stringfields and lock from change message.
When a subscribe or unsubscribe occurs a message is published
containing this information. This change makes it so that the
message no longer uses stringfields or a lock, as both are not
really needed for the message.

Change-Id: I3f4831931d79f94fd979baf48048738df5dc1632
2018-11-18 19:53:14 -04:00
Joshua Colp 3077ad0c24 stasis: Add internal filtering of messages.
This change adds the ability for subscriptions to indicate
which message types they are interested in accepting. By
doing so the filtering is done before being dispatched
to the subscriber, reducing the amount of work that has
to be done.

This is optional and if a subscriber does not add
message types they wish to accept and set the subscription
to selective filtering the previous behavior is preserved
and they receive all messages.

There is also the ability to explicitly force the reception
of all messages for cases such as AMI or ARI where a large
number of messages are expected that are then generically
converted into a different format.

ASTERISK-28103

Change-Id: I99bee23895baa0a117985d51683f7963b77aa190
2018-11-18 15:08:16 -05:00
Joshua Colp bf579222c4 stasis: Clarify lifetime of topics.
As mentioned in the comment I've added in the code there is no
ability to unsubscribe all subscribers from a topic and explicitly
destroy it. This is not currently a problem as we have two types of
topics:

Long lived topics which exist for the lifetime of the system.
Ephemeral topics which feed a long lived topic.

In the case of the ephemeral topics there is no subscriber which does
not have its lifetime managed by the same entity that has created
the topic. This ensures that when the topic is being unreferenced the
subscribers are also unsubscribed and destroyed, allowing the topic
to ultimately be destroyed as well.

Change-Id: Ic5e244da7b16b1895ba1fc5ece481ebba5809c9a
2018-11-05 09:46:54 -05:00
Alexei Gradinari eee935983b pjsip: new endpoint's options to control Connected Line updates
This patch adds new options 'trust_connected_line' and 'send_connected_line'
to the endpoint.

The option 'trust_connected_line' is to control if connected line updates
are accepted from this endpoint.

The option 'send_connected_line' is to control if connected line updates
can be sent to this endpoint.

The default value is 'yes' for both options.

Change-Id: I16af967815efd904597ec2f033337e4333d097cd
2018-10-30 10:39:28 -05:00
Torrey Searle cac4ccef25 res_pjsip_session: add new flag use_callerid_contact
Add a new global flag to res_pjsip to allow the callerid to be used
as the username in the contact header.  This allows chan_pjsip to have
the same behavour as chan_sip

ASTERISK-28087 #close

Change-Id: I9a720e058323f6862a91c62f8a8c1a4b5c087b95
2018-10-26 10:39:03 +02:00
Joshua Colp e7b22ee133 Merge "bridge_softmix: Add SDP "label" attribute to streams" 2018-10-25 07:45:23 -05:00
Joshua Colp dbfb75e02d Merge "res_pjsip: Implement additional SIP RFCs for Google Voice trunk compatability" 2018-10-25 05:51:02 -05:00
George Joseph 8d1c6bb6e6 bridge_softmix: Add SDP "label" attribute to streams
Adding the "label" attribute used for participant info correlation
was previously done in app_confbridge but it wasn't working
correctly because it didn't have knowledge about which video
streams belonged to which channel.  Only bridge_softmix has that
data so now it's set when the bridge topology is changed.

ASTERISK-28107

Change-Id: Ieddeca5799d710cad083af3fcc3e677fa2a2a499
2018-10-24 08:41:23 -05:00
George Joseph a99d48d3f3 Merge "astobj2: Eliminate legacy container allocation macros." 2018-10-24 08:30:08 -05:00
Nick French 37b2e68628 res_pjsip: Implement additional SIP RFCs for Google Voice trunk compatability
This change implements a few different generic things which were brought
on by Google Voice SIP.

1.  The concept of flow transports have been introduced.  These are
configurable transports in pjsip.conf which can be used to reference a
flow of signaling to a target.  These have runtime configuration that can
be changed by the signaling itself (such as Service-Routes and
P-Preferred-Identity).  When used these guarantee an individual connection
(in the case of TCP or TLS) even if multiple flow transports exist to the
same target.

2.  Service-Routes (RFC 3608) support has been added to the outbound
registration module which when received will be stored on the flow
transport and used for requests referencing it.

3.  P-Associated-URI / P-Preferred-Identity (RFC 3325) support has been
added to the outbound registration module.  If a P-Associated-URI header
is received it will be used on requests as the P-Preferred-Identity.

4.  Configurable outbound extension support has been added to the outbound
registration module.  When set the extension will be placed in the
Supported header.

5.  Header parameters can now be configured on an outbound registration
which will be placed in the Contact header.

6.  Google specific OAuth / Bearer token authentication
(draft-ietf-sipcore-sip-authn-02) has been added to the outbound
registration module.

All functionality changes are controlled by pjsip.conf configuration
options and do not affect non-configured pjsip endpoints otherwise.

ASTERISK-27971 #close

Change-Id: Id214c2d1c550a41fcf564b7df8f3da7be565bd58
2018-10-24 07:51:25 -05:00
Corey Farrell 687ab7aeee
astobj2: Eliminate legacy container allocation macros.
These macros have been documented as legacy for a long time but are
still used in new code because they exist.  Remove all references to:
* ao2_container_alloc_options
* ao2_t_container_alloc_options
* ao2_t_container_alloc

These macro's are also removed.  Only ao2_container_alloc remains due to
it's use in over 100 places.

Change-Id: I1a26258b5bf3deb081aaeed11a0baa175c933c7a
2018-10-19 17:33:05 -04:00
Corey Farrell 4c19b94968
lock: Replace __ast_mutex_logger with private log_mutex_error.
__ast_mutex_logger used the variable `canlog` without accepting it as a
argument.  Replace with internal macro `log_mutex_error` which takes
canlog as the first arguement.  This will prevent confusion when working
with lock.c code, many of the function declare the canlog variable and
in some cases it previously appeared to be unused.

Change-Id: I83b372cb0654c5c18eadc512f65a57fa6c2e9853
2018-10-19 12:34:08 -04:00
Corey Farrell 5ab94d2a3e
taskprocessor: Warn on unused result from pushing task.
Add attribute_warn_unused_result to ast_taskprocessor_push,
ast_taskprocessor_push_local and ast_threadpool_push.  This will help
ensure we perform the necessary cleanup upon failure.

Change-Id: I7e4079bd7b21cfe52fb431ea79e41314520c3f6d
2018-10-17 09:14:05 -04:00
Corey Farrell c8ee1a183f
loader: Flag module as declined in all cases where it fails to load.
This has no effect on startup since AST_MODULE_LOAD_FAILURE aborts
startup, but it's possible for this code to be returned on manual load
of a module after startup.

It is an error for a module to not have a load callback but this is not
a fatal system error.  In this case flag the module as declined, return
AST_MODULE_LOAD_FAILURE only if a required module is broken.

Expand doxygen documentation for AST_MODULE_LOAD_*.

Change-Id: I3c030bb917f6e5a0dfd9d91491a4661b348cabf8
2018-10-04 19:40:47 -04:00
Corey Farrell e4cf513f81
loader: Improve error handling.
* Display list of unavailable dependencies when they cause another
  module to fail loading.
* When a module declines to load find all modules which depend on it so
  they can be declined and listed together.
* Prevent retry of declined modules during startup.
* When a module fails to dlopen try loading it with RTLD_LAZY so we can
  attempt to display the list of missing dependencies.

These changes are meant to reduce logger spam that is caused when a
module has many dependencies and declines to load.  This also fixes some
error paths which failed to recognize required modules.

Module load/start errors are delayed until the end of loader startup.

Change-Id: I046052c71331c556c09d39f47a3b92975f3e1758
2018-10-02 13:18:12 -04:00
Joshua Colp 69f4740fa1 Merge "lock: Improve performance of DEBUG_THREADS." 2018-10-01 08:32:49 -05:00
Joshua Colp 02bb329bb5 Merge "configure.ac: Check for unbound version >= 1.5" 2018-10-01 07:08:52 -05:00
Corey Farrell 205c6be895
lock: Improve performance of DEBUG_THREADS.
Add a volatile flag to lock tracking structures so we only need to use
the global lock when first initializing tracking.

Additionally add support for DEBUG_THREADS_LOOSE_ABI.  This is used by
astobj2.c to eliminate storage for tracking fields when DEBUG_THREADS is
not defined.

Change-Id: Iabd650908901843e9fff47ef1c539f0e1b8cb13b
2018-09-28 14:42:04 -04:00
George Joseph aa10d6d5eb Merge "jansson: Backport fixes to bundled, use json_vsprintf if available." 2018-09-26 11:09:50 -05:00
George Joseph de14ed0b93 Merge "rtp_engine: rtcp_report_to_json can overflow the ssrc integer value" 2018-09-26 08:02:28 -05:00
George Joseph 1ba51b00cc configure.ac: Check for unbound version >= 1.5
In order to do this and provide good feedback, a new macro was
created (AST_EXT_LIB_EXTRA_CHECK) which does the normal check and
path setups for the library then compiles, links and runs a supplied
code fragment to do the final determination.  In this case, the
final code fragment compares UNBOUND_VERSION_MAJOR
and UNBOUND_VERSION_MINOR to determine if they're greater than or
equal to 1.5.

Since we require version 1.5, some code in res_resolver_unbound
was also simplified.

ASTERISK-28045
Reported by: Samuel Galarneau

Change-Id: Iee94ad543cd6f8b118df8c4c7afd9c4e2ca1fa72
2018-09-25 13:30:09 -06:00
Corey Farrell adf539b2f0 jansson: Backport fixes to bundled, use json_vsprintf if available.
Use json_vsprintf from versions which contain fix for va_copy leak.

Apply fixes from jansson master:
* va_copy leak fix.
* Avoid potential invalid memory read in json_pack.
* Rename variable that shadowed another.

Change-Id: I7522e462d2a52f53010ffa1e7d705c666ec35539
2018-09-24 18:00:26 -05:00
Kevin Harwell 31fba4e869
rtp_engine: rtcp_report_to_json can overflow the ssrc integer value
When writing an RTCP report to json the code attempts to pack the "ssrc" and
"source_ssrc" unsigned integer values as a signed int value type. This of course
means if the ssrc's unsigned value is greater than that which can fit into a
signed integer value it gets converted to a negative number. Subsequently, the
negative value goes out in the json report.

This patch now packs the value as a json_int_t, which is the widest integer type
available on a given system. This should make it so the value no longer
overflows.

Note, this was caught by two failing tests hep/rtcp-receiver/ and
hep/rtcp-sender.

Change-Id: I2af275286ee5e795b79f0c3d450d9e4b28e958b0
2018-09-21 18:06:21 -04:00
George Joseph d277db4a38 stasis: Add function to delete topic from pool
There's been a long standing leak when using topic pools.  The
topics in the pool get cleaned up when the last pool reference is
released but you can't remove a topic specifically.  If you reloaded
app_voicemail for instance, and mailboxes went away, their topics
were left in the pool.

* Added stasis_topic_pool_delete_topic() so modules can clean up
  topics from pools.
* Registered the topic pool containers so it can be examined from
  the CLI when AO2_DEBUG is enabled.  They'll be named
  "<topic_pool_name>-pool".

Change-Id: Ib7957951ee5c9b9b4482af7b9b4349112d62bc25
2018-09-20 12:13:22 -06:00
Joshua Colp ce9a980be6 pjproject: Upgrade to 2.8.
This change brings in PJSIP 2.8, removes all the patches
that were merged upstream, and makes a minor change to
support a breaking change that was done.

ASTERISK-28059

Change-Id: I5097772b11b0f95c3c1f52df6400158666f0a189
2018-09-18 11:32:18 -05:00
Sean Bright 3d9deb35f0 autoconf: Check for srtp_get_version_string() before using it
Change-Id: Id2a916ff9448706090e72ff2c7fb3f5ba24a05df
2018-09-17 10:48:03 -05:00
Sean Bright 07cb13f75f res_pjsip: Log IPv6 addresses correctly
Both pjsip_tx_data.tp_info.dst_name and pjsip_rx_data.pkt_info.src_name
store IPv6 addresses without enclosing brackets. This causes some log
output to be confusing because it is difficult to separate the IPv6
address from a port specification.

* Use pj_sockaddr_print() along with pjsip_tx_data.tp_info.dst_addr and
  pjsip_rx_data.pkt_info.src_addr where possible for consistent IPv6
  output.

* When a pj_sockaddr is not available, explicitly wrap IPv6 addresses
  in brackets.

* When assigning pjsip_rx_data.pkt_info.src_name ourselves, make sure
  to also set pjsip_rx_data.pkt_info.src_addr.

Change-Id: I5cfe997ced7883862a12b9c7d8551d76ae02fcf8
2018-09-14 14:59:23 -05:00
Sean Bright 600c5d79fd res_pjproject: Add utility functions to convert between socket structures
Currently, to convert from a pj_sockaddr to an ast_sockaddr, the address
needs to be rendered to a string and then parsed into the correct
structure. This also involves a call to getaddrinfo(3). The same is true
for the inverse operation.

Instead, because we know the internal structure of both ast_sockaddr and
pj_sockaddr, we can translate directly between the two without the
need for an intermediate string.

Change-Id: If0fc4bba9643f755604c6ffbb0d7cc46020bc761
2018-09-06 13:30:12 -05:00
Jenkins2 5241a53acd Merge "Build System: Improve ccache matching for different menuselect options." 2018-08-14 13:41:32 -05:00
Joshua Colp a0426e136b Merge "stasis: Reduce calculation of stasis message type hash." 2018-08-08 05:54:02 -05:00
Joshua Colp 39a8920504 Merge "res_pjsip: Make pjlib.h consistently included." 2018-08-08 05:53:53 -05:00
Richard Mudgett c6ad25dcb7 res_pjsip.h: Fix doxygen comments.
Change-Id: I9cf97bdc756012d1f552ab007f4aa85e0ddb4e62
2018-08-07 10:30:45 -05:00
Joshua Colp 455ca1095e stasis: Reduce calculation of stasis message type hash.
When the stasis cache is used a hash is calculated for
retrieving or inserting messages. This change calculates
a hash when the message type is initialized that is then
used each time needed. This ensures that the hash is
calculated only once for the message type.

Change-Id: I4fe6bfdafb55bf5c322dd313fbd8c32cce73ef37
2018-08-06 11:18:04 -05:00
Richard Mudgett acbb9f52b2 res_pjsip: Make pjlib.h consistently included.
* Don't include pjlib.h twice in res_pjsip.h
* Consistently use #include <> form for pjproject includes.
(pjsip.h and pjlib.h)

Change-Id: I3f7b42044840de64edf7e9d7695cb60c45990dc7
2018-08-03 16:07:22 -05:00
Corey Farrell a10a3aff6a Build System: Improve ccache matching for different menuselect options.
Changing any Menuselect option in the `Compiler Flags` section causes a
full rebuild of the Asterisk source tree.  Every enabled option causes
a #define to be added to buildopts.h, thus breaking ccache caching for
every source file that includes "asterisk.h".  In most cases each option
only applies to one or two files.  Now we only define those options for
the specific sources which use them, this causes much better cache
matching when working with multiple builds.  For example testing code
with an without MALLOC_DEBUG will now use just over half the ccache
size, only main/astmm.o will have two builds cached instead of every
file.

Reorder main/Makefile so _ASTCFLAGS set on specific object files are all
together, sorted by filename.  Stop adding -DMALLOC_DEBUG to CFLAGS of
bundled pjproject, this define is no longer used by any header so only
serves to break cache.

The only code change is a slight adjustment to how main/astmm.c is
initialized.  Initialization functions always exist so main/asterisk.c
can call them unconditionally.  Additionally rename the astmm
initialization functions so they are not exported.

Change-Id: Ie2085237a964f6e1e6fff55ed046e2afff83c027
2018-08-01 12:01:15 -04:00
Alexander Traud 0a4d58735f BuildSystem: Enable Jansson in Solaris 11.
In Solaris, the header <jansson.h> is in /usr/include/jansson. To find
Jansson even in such a subdirectory, the tool pkg-config is queried via
AST_PKG_CONFIG_CHECK. For those platforms, which do not list Jansson via
pkg-config, the previous check remains and is executed thereafter.

Because the check for the NetBSD Editline library uses the tool pkg-config
the code of PKG_PROG_PKG_CONFIG must be used. Because that check happens
earlier than Jansson, it must be placed in front of that.

ASTERISK-27991

Change-Id: I69ea0f379f87a50049654b2487c76ee1c04fa53a
2018-07-28 14:39:40 +02:00
Joshua Colp 66f581313f devicestate: Don't create topic when change isn't cached.
When publishing a device state the change can be marked as being
cachable or not. If it is not cached the change is just published
to all interested and not stored away for later query. This was not
fully taken into account when publishing in stasis. The act of
publishing would create a topic for the device even if it may be
ephemeral.

This change makes it so messages which are not cached won't create
a topic for the device. If a topic does already exist it will be
published to but otherwise the change will only be published to
the device state all topic.

ASTERISK-27591

Change-Id: I18da0e8cbb18e79602e731020c46ba4101e59f0a
2018-07-25 14:21:06 -05:00
Jenkins2 8f890374cb Merge "Enable bundling of jansson, require 2.11." 2018-07-24 10:07:23 -05:00
George Joseph d48d6a7ecc Merge "sched: Make ABI compatible between dev mode and non-dev mode." 2018-07-23 13:32:01 -05:00
George Joseph ba8f2c401c xmldoc.c: Fix dump of xml document
The "xmldoc dump" cli command was simply concatenating xml documents
into the output file.  The resulting file had multiple "xml"
processing instructions and multiple root elements which is illegal.
Normally this isn't an issue because Asterisk has only 1 main xml
documentation file but codec_opus has its own file so if it's
downloaded and you do "xmldoc dump", the result is invalid.

* Added 2 new functions to xml.c:
    ast_xml_copy_node_list creates a copy of a list of children.
    ast_xml_add_child_list adds a list to an existing list.

* Modified handle_dump_docs to create a new output document and
  add to it the children from each input file.  It then dumps the
  new document to the output file.

Change-Id: I3f182d38c75776aee76413dadd2d489d54a85c07
2018-07-23 06:47:20 -05:00
Joshua Colp 33f855bb69 sched: Make ABI compatible between dev mode and non-dev mode.
In the past there was an assertion in the ast_sched_del function
and in order to ensure it was useful the calling function name,
line number, and filename had to be passed in. This cause the ABI
to be different between dev mode and non-dev mode.

This assertion is no longer present so the special logic can be
removed to make it the same between them both.

Change-Id: Icbc69c801e357d7004efc5cf2ab936d9b83b6ab8
2018-07-22 10:46:39 -05:00
Corey Farrell ee154464d7 Enable bundling of jansson, require 2.11.
Change-Id: Ib3111b151d37cbda40768cf2a8a9c6cf6c5c7cbd
2018-07-20 13:42:02 -04:00
George Joseph 85a95b8a29 Merge "res_rtp_asterisk: Add support for sending NACK requests." 2018-07-18 14:46:28 -05:00
George Joseph c8e4cd8bce Merge "res_pjsip_sdp_rtp: include ice in ANSWER only if offered" 2018-07-18 14:29:19 -05:00
Ben Ford 5bacde37a2 res_rtp_asterisk: Add support for sending NACK requests.
Support has been added for receiving a NACK request and handling it.
Now, Asterisk can detect when a NACK request should be sent and knows
how to construct one based on the packets we've received from the remote
end. A buffer has been added that will store out of order packets until
we receive the packet we are expecting. Then, these packets are handled
like normal and frames are queued to the core like normal. Asterisk
knows which packets to request in the NACK request using a vector
which stores the sequence numbers of the packets we are currently missing.

If a missing packet is received, cycle through the buffer until we reach
another packet we have not received yet. If the buffer reaches a certain
size, send a NACK request. If the buffer reaches its max size, queue all
frames to the core and wipe the buffer and vector.

According to RFC3711, the NACK request must be sent out in a compound
packet. All compound packets must start with a sender or receiver
report, so some work was done to refactor the current sender / receiver
code to allow it to be used without having to also include sdes
information and automatically send the report.

Also added additional functionality to ast_data_buffer, along with some
testing.

For more information, refer to the wiki page:
https://wiki.asterisk.org/wiki/display/AST/WebRTC+User+Experience+Improvements

ASTERISK-27810 #close

Change-Id: Idab644b08a1593659c92cda64132ccc203fe991d
2018-07-18 13:37:03 -05:00
Corey Farrell 49f83a7490 loader: Fix startup issues.
* Merge the preload and load stages, use load ordering to try preload's
  first.  This fixes an issue where `preload=res_config_curl` would fail
  unless res_curl and func_curl were also preloaded.  Now it is only
  required that those modules be loaded during startup: autoload or
  regular load is good enough.
* The configuration option `require` and `preload-require` were only
  effective if the modules failed to load.  These options will now abort
  Asterisk startup if required modules fail to reach the 'Running'
  state.
* Missing or invalid 'module.conf' did not prevent startup.  Asterisk
  doesn't do anything without modules so this a fatal error.

Change-Id: Ie4176699133f0e3a823b43f90c3348677e43a5f3
2018-07-16 18:21:52 -04:00
Torrey Searle 1445384699 res_pjsip_sdp_rtp: include ice in ANSWER only if offered
Keep track if ICE candidates were in the SDP offer & only put them
in the corresponding SDP answer if the offer condaind ICE candidates

ASTERISK-27957 #close

Change-Id: Idf2597ee48e9a287e07aa4030bfa705430a13a92
2018-07-13 03:03:40 -05:00
George Joseph 8f42447c68 res_pjsip: Add 'suppress_q850_reason_headers' option to endpoint
A new option 'suppress_q850_reason_headers' has been added to the
endpoint object. Some devices can't accept multiple Reason headers and
get confused when both 'SIP' and 'Q.850' Reason headers are received.
This option allows the 'Q.850' Reason header to be suppressed.
The default value is 'no'.

ASTERISK-27949
Reported-by: Ross Beer

Change-Id: I54cf37a827d77de2079256bb3de7e90fa5e1deb1
2018-07-06 07:03:45 -06:00
Richard Mudgett 7a238fe74d AMI SendText action: Fix to use correct thread to send the text.
The AMI action was directly sending the text to the channel driver.
However, this makes two threads attempt to handle media and runs afowl of
CHECK_BLOCKING.

* Queue a read action to make the channel's media handling thread actually
send the text message.  This changes the AMI actions success/fail response
to just mean the text was queued to be sent not that the text actually got
sent.  The channel driver may not even support sending text messages.

ASTERISK-27943

Change-Id: I9dce343d8fa634ba5a416a1326d8a6340f98c379
2018-06-28 12:20:30 -06:00
Jenkins2 84bb8586fd Merge "res_pjsip_session: Add ability to accept multiple sdp answers" 2018-06-28 06:34:22 -05:00
George Joseph 880fbff6b7 res_pjsip_session: Add ability to accept multiple sdp answers
pjproject by default currently will follow media forked during an INVITE
on outbound calls if the To tag is different on a subsequent response as
that on an earlier response.  We handle this correctly.  There have
been reported cases where the To tag is the same but we still need to
follow the media.  The pjproject patch in this commit adds the
capability to sip_inv and also adds the capability to control it at
runtime.  The original "different tag" behavior was always controllable
at runtime but we never did anything with it and left it to default to
TRUE.

So, along with the pjproject patch, this commit adds options to both the
system and endpoint objects to control the two behaviors, and a small
logic change to session_inv_on_media_update in res_pjsip_session to
control the behavior at the endpoint level.

The default behavior for "different tags" remains the same at TRUE and
the default for "same tag" is FALSE.

Change-Id: I64d071942b79adb2f0a4e13137389b19404fe3d6
ASTERISK-27936
Reported-by: Ross Beer
2018-06-26 07:05:34 -06:00
Alexander Traud 675e2ddb49 uuid: Enable UUID in Solaris 11.
ASTERISK-27933
Reported by: bautsche

Change-Id: I9b8362824efbfb2a16981e46e85f7c8322908c49
2018-06-23 08:26:19 +02:00
George Joseph d87631d21f Merge changes from topic 'ASTERISK-27625'
* changes:
  channel.c: Make CHECK_BLOCKING() save thread LWP id for messages.
  channel.c: Fix usage of CHECK_BLOCKING()
  autoservice: Don't start channel autoservice if the thread is a user interface.
2018-06-21 10:26:31 -05:00
George Joseph 98bd5908a2 Merge "ARI POST DTMF: Make not compete with channel's media thread." 2018-06-21 10:26:23 -05:00
George Joseph 46c1f81fad Merge "AMI PlayDTMF Action: Make not compete with channel's media thread." 2018-06-21 10:25:32 -05:00
Jenkins2 5065cb2c24 Merge "Fix some doxygen and curly placement." 2018-06-20 17:01:10 -05:00
Richard Mudgett eb8bbe660e channel.c: Make CHECK_BLOCKING() save thread LWP id for messages.
* Removed an unnecessary call to ast_channel_blocker_set() in
__ast_read().

ASTERISK-27625

Change-Id: I342168b999984666fb869cd519fe779583a73834
2018-06-19 15:02:52 -05:00
Richard Mudgett da54605b8a ARI POST DTMF: Make not compete with channel's media thread.
There can be one and only one thread handling a channel's media at a time.
Otherwise, we don't know which thread is going to handle the media frames.

ASTERISK-27625

Change-Id: I4d6a2fe7386ea447ee199003bf8ad681cb30454e
2018-06-19 15:02:52 -05:00
Richard Mudgett 7d874c1af7 AMI PlayDTMF Action: Make not compete with channel's media thread.
There can be one and only one thread handling a channel's media at a time.
Otherwise, we don't know which thread is going to handle the media frames.

ASTERISK-27625

Change-Id: Ia341f1a6f4d54f2022261abec9021fe5b2eb4905
2018-06-19 15:02:52 -05:00
Richard Mudgett 080508d2eb channel.c: Fix usage of CHECK_BLOCKING()
The CHECK_BLOCKING() macro is used to indicate if a channel's handling
thread is about to do a blocking operation (poll, read, or write) of
media.  A few operations such as ast_queue_frame(), soft hangup, and
masquerades use the indication to wake up the blocked thread to reevaluate
what is going on.

ASTERISK-27625

Change-Id: I4dfc33e01e60627d962efa29d0a4244cf151a84d
2018-06-19 15:02:52 -05:00
Richard Mudgett 0989b63047 autoservice: Don't start channel autoservice if the thread is a user interface.
Executing dialplan functions from either AMI or ARI by getting a variable
could place the channel into autoservice.  However, these user interface
threads do not handle the channel's media so we wind up with two threads
attempting to handle the media.

There can be one and only one thread handling a channel's media at a time.
Otherwise, we don't know which thread is going to handle the media frames.

ASTERISK-27625

Change-Id: If2dc94ce15ddabf923ed1e2a65ea0ef56e013e49
2018-06-19 15:02:52 -05:00
Richard Mudgett 720c2d1da2 Fix some doxygen and curly placement.
Change-Id: I9a784a7c804120a8fa826c2a4cb9957e4b0b2fc8
2018-06-19 10:46:46 -06:00
Richard Mudgett c1686b8b3e tcptls.h: Remove redundant SSL_CTX typedef.
It is invalid to typedef something more than once.  Though not all gcc
compilers on different OS's complain about it.

Change-Id: I5a7d4565990c985822d61ce75bde0b45f9870540
2018-06-18 12:35:43 -06:00
Alexander Traud 0743ad6422 res_rtp_asterisk: Allow OpenSSL configured with no-deprecated.
Furthermore, allow OpenSSL configured with no-dh. Additionally, this change
allows auto-negotiation of the elliptic curve/group for servers, not only with
OpenSSL 1.0.2 but also with OpenSSL 1.1.0 and newer. This enables X25519
(since OpenSSL 1.1.0) and X448 (since OpenSSL 1.1.1) as a side-effect.

ASTERISK-27910

Change-Id: I5b0dd47c5194ee17f830f869d629d7ef212cf537
2018-06-08 22:02:38 +02:00
Alexander Traud 24503fb600 tcptls.h: Repair ./configure --with-ssl=PATH.
asterisk/tcptls.h was included (explicitly, implicitly, or transitively). Those
inclusions got replaced by forward declarations. As side effect, the inclusions
got completed.

ASTERISK-27878

Change-Id: I9d102728e30336d6522e5e4ae9e964013a0835f7
2018-05-28 17:29:23 +02:00
Joshua Colp 4ea98e49f1 Merge "rtp: Add support for RTP extension negotiation and abs-send-time." 2018-05-24 15:26:57 -05:00
Joshua Colp fbb33ba6e8 Merge "tcptls: Repair ./configure --with-ssl=PATH." 2018-05-24 06:20:15 -05:00
Joshua Colp 25764691b0 Merge "netsock2: Add ast_sockaddr_resolve_first_af to netsock2 public API" 2018-05-23 12:10:13 -05:00
Joshua Colp a507c73a78 rtp: Add support for RTP extension negotiation and abs-send-time.
When RTP was originally created it had the ability to place a single
extension in an RTP packet. In practice people wanted to potentially
put multiple extensions in one and so RFC 5285 (obsoleted by RFC
8285) came into existence. This allows RTP extensions to be negotiated
with a unique identifier to be used in the RTP packet, allowing
multiple extensions to be present in the packet.

This change extends the RTP engine API to add support for this. A
user of it can enable extensions and the API provides the ability to
retrieve the information (to construct SDP for example) and to provide
negotiated information (from SDP). The end result is that the RTP
engine can then query to see if the extension has been negotiated and
what unique identifier is to be used. It is then up to the RTP engine
implementation to construct the packet appropriately.

The first extension to use this support is abs-send-time which is
defined in the REMB draft[1] and is a second timestamp placed in an
RTP packet which is for when the packet has left the sending system.
It is used to more accurately determine the available bandwidth.

ASTERISK-27831

[1] https://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03

Change-Id: I508deac557867b1e27fc7339be890c8018171588
2018-05-23 09:41:59 -06:00
Matthew Fredrickson 9f9dce05b2 netsock2: Add ast_sockaddr_resolve_first_af to netsock2 public API
This function originally was used in chan_sip to enable some simplifying
assumptions and eventually was copy and pasted into res_pjsip_logger and
res_hep.  Since it's replicated in three places, it's probably best to
move it into the public netsock2 API for these modules to use.

Change-Id: Id52e23be885601c51d70259f62de1a5e59d38d04
2018-05-21 11:03:10 -05:00
Alexander Traud 2228ae3f27 tcptls: Repair ./configure --with-ssl=PATH.
SSL_OP_NO_TLSv1_1 and SSL_OP_NO_TLSv1_2 got discovered without honoring a PATH.

ASTERISK-27865

Change-Id: I8cd358eed7411726d08fa7b01691bef122fbeb71
2018-05-19 15:23:30 +02:00
Joshua Colp bc4b3c535d Merge "rtp_engine: Avoid a typo error in Doxygen for ast_rtp_codecs_find_payload_code." 2018-05-14 06:30:44 -05:00
Joshua Colp a103221de2 Merge "pjsip: Rewrite OPTIONS support with new eyes." 2018-05-14 04:06:53 -05:00
Alexander Traud 263637a38d rtp_engine: Avoid a typo error in Doxygen for ast_rtp_codecs_find_payload_code.
Change-Id: Ica089d4507a27ddfc4ce3a88d697ffbef378de48
2018-05-11 17:37:57 +02:00
Jenkins2 d83a37f0cc Merge "stream: Make the topology a reference counted object." 2018-05-08 05:42:53 -05:00
Jenkins2 dcaaae6cd1 Merge "iostreams: Add some documentation for the ast_iostream_* functions" 2018-05-04 06:14:56 -05:00
Joshua Colp 7528b86cad stream: Make the topology a reference counted object.
The stream topology has no lock of its own resulting in
another lock protecting it in some way (for example the
channel lock). If multiple channels are being juggled at
the same time this can be problematic. This change makes
the topology a reference counted object instead which
guarantees it will remain valid even without the channel
lock being held.

Change-Id: I4f4d3dd856a033ed55fe218c3a4fab364afedb03
2018-05-03 16:31:56 +00:00
Sean Bright 069a0b7593 iostreams: Add some documentation for the ast_iostream_* functions
Change-Id: Id71b87637f0a484eb5a1cd26c3d1c7c15c7dcf26
2018-05-02 18:08:30 -06:00
Gaurav Khurana 0827d5cc53 Add the ability to read the media file type from HTTP header for playback
How it works today:
media_cache tries to parse out the extension of the media file to be played
from the URI provided to Asterisk while caching the file.

What's expected:
Better will be to have Asterisk get extension from other ways too. One of the
common ways is to get the type of content from the CONTENT-TYPE header in the
HTTP response for fetching the media file using the URI provided.

Steps to Reproduce:
Provide a URL of the form: http://host/media/1234 to Asterisk for media
playback. It fails to play and logs show the following error line:

[Sep 15 15:48:05] WARNING [29148] [C-00000092] file.c:
File http://host/media/1234 does not exist in any format

Scenario this issue is blocking:
In the case where the media files are stored in some cloud object store,
following can block the media being played via Asterisk:

Cloud storage generally needs authenticated access to the storage. The way
to do that is by using signed URIs. With the signed URIs there's no way to
preserve the name of the file.
In most cases Cloud storage returns a key to access the object and preserving
file name is also not a thing there

ASTERISK-27286

 Reporter: Gaurav Khurana

Change-Id: I1b14692a49b2c1ac67688f58757184122e92ba89
2018-04-30 16:30:44 -04:00
George Joseph 3bad41257b Merge "BuildSystem: Add DragonFly BSD." 2018-04-30 09:07:30 -05:00
Joshua Colp 882e79b77e pjsip: Rewrite OPTIONS support with new eyes.
The OPTIONS support in PJSIP has organically grown, like many things in
Asterisk.  It has been tweaked, changed, and adapted based on situations
run into.  Unfortunately this has taken its toll.  Configuration file
based objects have poor performance and even dynamic ones aren't that
great.

This change scraps the existing code and starts fresh with new eyes.  It
leverages all of the APIs made available such as sorcery observers and
serializers to provide a better implementation.

1.  The state of contacts, AORs, and endpoints relevant to the qualify
process is maintained.  This state can be updated by external forces (such
as a device registering/unregistering) and also the reload process.  This
state also includes the association between endpoints and AORs.

2.  AORs are scheduled and not contacts.  This reduces the amount of work
spent juggling scheduled items.

3.  Manipulation of which AORs are being qualified and the endpoint states
all occur within a serializer to reduce the conflict that can occur with
multiple threads attempting to modify things.

4.  Operations regarding an AOR use a serializer specific to that AOR.

5.  AORs and endpoint state act as state compositors.  They take input
from lower level objects (contacts feed AORs, AORs feed endpoint state)
and determine if a sufficient enough change has occurred to be fed further
up the chain.

6.  Realtime is supported by using observers to know when a contact has
been registered.  If state does not exist for the associated AOR then it
is retrieved and becomes active as appropriate.

The end result of all of this is best shown with a configuration file of
3000 endpoints each with an AOR that has a static contact.  In the old
code it would take over a minute to load and use all 8 of my cores.  This
new code takes 2-3 seconds and barely touches the CPU even while dealing
with all of the OPTIONS requests.

ASTERISK-26806

Change-Id: I6a5ebbfca9001dfe933eaeac4d3babd8d2e6f082
2018-04-27 17:28:16 -05:00
Jenkins2 9c430569d4 Merge "bridge_softmix: Forward TEXT frames" 2018-04-27 10:06:30 -05:00
Richard Mudgett 661fec4b59 core: Remove unused/incomplete SDP modules.
Change-Id: Icc28fbdc46f58e54a21554e6fe8b078f841b1f86
2018-04-25 15:58:24 -03:00
Joshua Colp 1dedc73951 Merge "streams: Add string metadata capability" 2018-04-25 13:45:26 -05:00
Alexander Traud efe40ff671 BuildSystem: Add DragonFly BSD.
ASTERISK-27820

Change-Id: I310896143e94d65da1c2be3bb448204a8b86d557
2018-04-20 12:50:03 +02:00