Commit Graph

3245 Commits

Author SHA1 Message Date
Richard Mudgett 4af24ec74b res_pjsip_session.c: Extract sip_session_defer_termination_stop_timer().
Change-Id: I9e115dee74bd72e06081d0ee73ecdeb886caa5fb
2015-07-16 12:19:18 -05:00
Richard Mudgett 71b3bcf5e0 res_pjsip_session.c: Add some helpful comments and minor tweaks.
Change-Id: I742aeeaf5f760593f323a00fb691affe22e35743
2015-07-16 12:19:18 -05:00
Richard Mudgett 53c91737a5 res_pjsip_session.c: Fix off nominal crash potential in debug message.
Change-Id: I09928297927ee85f7655289acee3a586816466bc
2015-07-16 12:19:18 -05:00
Benjamin Ford e01d93e092 ARI: Fixed unload mode for unload module.
Changed the unload mode to AST_FORCE_SOFT from AST_FORCE_FIRM,
which would unload a module even if it was in use.

* Changed unload mode to proper mode

ASTERISK-25173

Change-Id: If2402487b5bce05d9770f25f65f5c8e292ad5533
2015-07-15 10:33:53 -05:00
Matt Jordan b188eb788d Merge "res_pjsip_session.c: Fix crash on call disconnect." 2015-07-14 22:17:49 -05:00
Richard Mudgett 1b666549f3 res_pjsip_session.c: Fix crash on call disconnect.
The crash fix for ASTERISK-25183 backported some code from master to try
to make sure that a BYE response is processed by the same serializer used
by the BYE request.  The identified race condition causing that backport
was the BYE request code had not finished processing after sending the BYE
before the BYE response came in for processing under a different thread.
Unfortunately, there is still a race condition.  Now the race condition is
between destroying the call session's serializer in
ast_taskprocessor_unreference() and using ast_taskprocessor_get() to get a
reference to the serializer for a BYE response.  Even worse, the new race
condition is a design limitation of the taskprocessor implementation that
didn't matter in versions before v12.  Back then, taskprocessors were only
destroyed when a module unloaded.  Now res_pjsip can destroy them when a
call ends.

However, as noted on the ASTERISK-25183 commit,
session_inv_on_state_changed() is disassociating the dialog from the
session when the invite dialog state becomes PJSIP_INV_STATE_DISCONNECTED.
This is a tad too soon because our BYE request transaction has not
completed yet.

* Split session_end() that is called by session_inv_on_state_changed() to
hold off session destruction until the BYE transaction timeout occurs or a
failed initial INVITE transaction timeout occurs in
session_inv_on_tsx_state_changed().

ASTERISK-25201 #close
Reported by: Matt Jordan

Change-Id: Iaf8dc8485fd8392a2a3ee4ad3b7f7f04a0dcc961
2015-07-14 16:32:58 -05:00
Benjamin Ford 9d458b8311 ARI: Added new functionality to reload a single module.
An http request can be sent to reload an Asterisk module. If the
module can not be reloaded or is not already loaded, an error
response will be returned.

The command "curl -v -u user:pass -X PUT 'http://localhost:8088
/ari/asterisk/modules/{moduleName}'" (or something similar, based
on configuration) can be run in the terminal to access this new
functionality.

For more information, see:
https://wiki.asterisk.org/wiki.display/~bford/Asterisk+ARI+Resource

* Added new ARI functionality
* Asterisk modules can be reloaded through http requests

ASTERISK-25173

Change-Id: I289188bcae182b2083bdbd9ebfffd50b62f58ae1
2015-07-14 13:17:30 -05:00
Benjamin Ford f64f1c2772 ARI: Added new functionality to unload a single module.
An http request can be sent to unload an Asterisk module. If the
module can not be unloaded or is already unloaded, an error response
will be returned.

The command "curl -v -u user:pass -X DELETE 'http://localhost:8088
/ari/asterisk/modules/{moduleName}'" (or something similar, depending
on configuration) can be run in the terminal to access this new
functionality.

For more information, see:
https://wiki.asterisk.org/wiki.display/~bford/Asterisk+ARI+Resource

* Added new ARI functionality
* Asterisk modules can be unloaded through http requests

ASTERISK-25173

Change-Id: I535a95f5676deb02651522761ecbdc0b00b5ac57
2015-07-14 08:59:27 -05:00
Benjamin Ford aa5707b889 ARI: Added new functionality to load a single module.
An http request can be sent to load an Asterisk module. If the
module can not be loaded or is loaded already, an error response
will be returned.

The command curl -v -u user:pass -X POST 'http://localhost:8088/ari
/asterisk/modules/{moduleName}'" (or something similar, depending on
configuration) can be run in the terminal to access this new
functionality.

For more information, see:
https://wiki.asterisk.org/wiki.display/~bford/Asterisk+ARI+Resource

* Added new ARI functionality
* Asterisk modules can be loaded through http requests

ASTERISK-25173

Change-Id: I9e05d5b8c5c666ecfef341504f9edc1aa84fda33
2015-07-13 16:04:33 -05:00
Benjamin Ford 6a764db370 ARI: Added new functionality to get information on a single module.
An http request can be sent to retrieve information on a single
module, including the resource name, description, use count, status,
and support level.

The command "curl -v -u user:pass -X GET 'http://localhost:8088/ari
/asterisk/modules/{moduleName}'" (or something similar, depending on
configuration) can be run in the terminal to access this new
functionality.

For more information, see:
https://wiki.asterisk.org/wiki.display/~bford/Asterisk+ARI+Resource

* Added new ARI functionality
* Information on a single module can now be retrieved

ASTERISK-25173

Change-Id: Ibce5a94e70ecdf4e90329cf0ba66c33a62d37463
2015-07-13 14:29:27 -05:00
Joshua Colp 61661f3f7d Merge "res/res_sorcery_astdb: Add a debugging message for when retrieval by ID fails" 2015-07-11 13:34:40 -05:00
Joshua Colp 677bbeb41e Merge "res/res_pjsip_outbound_registration: Fix WARNING message" 2015-07-11 13:34:29 -05:00
Matt Jordan e64e586900 res/res_sorcery_astdb: Add a debugging message for when retrieval by ID fails
Having a debug message tell us that we attempted to look up an item but
failed is nice in circumstances when it isn't clear if the wizard was
queried correctly or not.

Change-Id: I2600c3bbea87f252196358f62e73f4c7da8632f7
2015-07-11 12:22:41 -05:00
Matt Jordan 7c14dfdc61 res/res_pjsip_outbound_registration: Fix WARNING message
Newlines are nice.

Change-Id: Icf0d915db02882e47cd9077ed9009f5d44140d42
2015-07-11 12:22:33 -05:00
Matt Jordan 3e286e6b51 res_pjsip/configuration: Fix a variety of default value problems
This patch fixes some bad default value handling in the following
settings:

* The 'message_context' and 'accountcode' settings are not mandatory. As
  such, we can allow their stringfield values to be empty.
* The 'media_encryption' setting applies a default value of 'none' to
  the setting, which it then can't parse or understand. Since the value
  is documented to be 'no', this will now apply that as the default
  value.

Change-Id: Ib9be7f97a7a5b9bc7aee868edf5acf38774cff83
2015-07-11 12:22:25 -05:00
Benjamin Ford 1b7760a8aa ARI: Added new functionality to get all module information.
An http request can be sent to retrieve a list of all existing modules,
including the resource name, description, use count, status, and
support level.

The command "curl -v -u user:pass -X GET 'http://localhost:8088/ari/
asterisk/modules" (or something similar, depending on configuration)
can be run in the terminal to access this new functionality.

For more information, see:
https://wiki.asterisk.org/wiki.display/~bford/Asterisk+ARI+Resource

* Added new ARI functionality
* Information on modules can now be retrieved

Change-Id: I63cbbf0ec0c3544cc45ed2a588dceabe91c5e0b0
2015-07-10 11:17:12 -05:00
Joshua Colp 9276415f65 res_rtp_asterisk: Ensure DTLS timeout timer is -1 if DTLS is not used.
This change fixes a bug where the DTLS timeout timer would be
initialized to 0 if DTLS was not used for an RTP session.

ASTERISK-25103

Change-Id: If8d26bb054f1d300838850da5b8db9044c2fe2ac
2015-07-08 04:28:21 -05:00
Matt Jordan 70c777146e Merge "res_pjsip_mwi.c: Use safer loop coding in mwi_subscription_mailboxes_str()." 2015-07-07 20:38:40 -05:00
Matt Jordan 8cd8d87479 Merge "res_pjsip_mwi.c: Fix MWI subscription memory corruption crash." 2015-07-07 20:38:15 -05:00
Joshua Colp 785aa18a23 Merge "PJSIP XML, XPIDF: Fix buffer size overwrite memory corruption error." 2015-07-07 17:39:07 -05:00
Joshua Colp d173d9692a Merge topic 'res_pjsip_mwi_cleanups'
* changes:
  res_pjsip_mwi.c: Eliminate a simple RAII_VAR.
  res_pjsip_mwi.c: Fix mid-line log message line breaks.
2015-07-07 17:24:43 -05:00
Joshua Colp 78ff4a2a4a Merge "PJSIP FAX: Fix T.38 automatic reject timer NULL channel pointer dereferences." 2015-07-07 17:20:54 -05:00
Joshua Colp ff40a643eb Merge "res_pjsip_t38.c: Fix always false if test." 2015-07-07 17:12:10 -05:00
Joshua Colp 20297252ed Merge "res/res_http_websocket: Don't send HTTP response fragmented." 2015-07-07 17:01:18 -05:00
Joshua Colp 5717340ab3 res_rtp_asterisk: Prevent simultaneous access to DTLS SSL context.
This change moves logic for setting up the DTLS SSL contexts to
when the SDP is done being processed instead of when ICE negotiation
completes. It also stops handshakes from being initiated when we
are acting as a server.

Manipulating the SSL context when ICE negotiation has completed
is problematic as the SSL context is not protected and if acting
as a client the remote side may have started DTLS negotiation
already.

The retransmission timeout timer code has also been split up
and simplified some. Both RTP and RTCP now have their own timers
and the points at which the timer is stopped and started is now
more specific. When a packet is sent the timer is started. When
a response is received but before it is processed the timer is
stopped. This provides a guarantee that the timeout is not
occurring while the response is processed.

ASTERISK-22805 #close
ASTERISK-24550 #close
ASTERISK-24651 #close
ASTERISK-24832 #close
ASTERISK-25103 #close
ASTERISK-25127 #close

Change-Id: Ib75ea2546f29d6efc3d2d37c58df6986c7bd9b91
2015-07-07 14:31:32 -05:00
Richard Mudgett 189841ddb7 res_pjsip_mwi.c: Fix MWI subscription memory corruption crash.
MWI subscriptions can crash or corrupt memory when using the subscription
datastore to access the MWI subscription object because the datastore is
not holding a reference to the object.

* Give the subscription datastore a ref to the MWI subscription object.
It is unfortunate that the ref causes a circular ref chain that must be
explicitly broken to allow the memory to get released.  The loop is broken
when the subscription is shutdown and if the subscription setup fails.

ASTERISK-25168 #close
Reported by: Carl Fortin

Change-Id: Ice4fa823f138ff10a6c74d280699c41a82836d4f
2015-07-06 16:15:12 -05:00
Richard Mudgett 7cd99be534 PJSIP XML, XPIDF: Fix buffer size overwrite memory corruption error.
When res_pjsip body generator modules were generating XML or XPIDF
response bodies, there was a chance that the generated body would be the
exact size of the supplied buffer.  Adding the nul string terminator would
then write beyond the end of the buffer and potentially corrupt memory.

* Fix MALLOC_DEBUG high fence violations caused by adding a nul string
terminator on the end of a buffer for XML or XPIDF response bodies.

* Made calls to pj_xml_print() safer if the XML prolog is requested.  Due
to a bug in pjproject, the return value could be -1 _or_
AST_PJSIP_XML_PROLOG_LEN if the supplied buffer is not large enough.

* Updated the doxygen comment of AST_PJSIP_XML_PROLOG_LEN to describe the
return value of pj_xml_print() when the supplied buffer is not large
enough.

ASTERISK-25168
Reported by: Carl Fortin

Change-Id: Id70e1d373a6a2b2bd9e678b5cbc5e55b308981de
2015-07-06 16:15:12 -05:00
Richard Mudgett 792ed7ce93 PJSIP FAX: Fix T.38 automatic reject timer NULL channel pointer dereferences.
When a caller calls a FAX number and then hangs up right after the call is
answered then the T.38 re-INVITE automatic reject timer may still be
running after the channel goes away.

* Added session NULL channel checks on the code paths that get executed by
t38_automatic_reject() to prevent a crash when the T.38 re-INVITE
automatic reject timer expires.

ASTERISK-25168
Reported by: Carl Fortin

Change-Id: I07b6cd23815aedce5044f8f32543779e2f7a2403
2015-07-06 16:15:12 -05:00
Richard Mudgett 030e8339dd res_pjsip_mwi.c: Use safer loop coding in mwi_subscription_mailboxes_str().
Change-Id: I6f39d809a6d1b47b35bb32b298f5a12f35d6f907
2015-07-06 16:10:57 -05:00
Richard Mudgett 453d7b8d69 res_pjsip_mwi.c: Eliminate a simple RAII_VAR.
Change-Id: Ib1843f81e826a6c760c424c88eb70c350d9d61da
2015-07-06 16:10:57 -05:00
Richard Mudgett 786c6d42ef res_pjsip_mwi.c: Fix mid-line log message line breaks.
* Add create_mwi_subscriptions_for_endpoint() doxygen comment.

Change-Id: I3c3f921f4ec749fb65b62d2f6fa0d4d1888b94e2
2015-07-06 16:10:57 -05:00
Richard Mudgett 1b91094edd res_pjsip_t38.c: Fix always false if test.
Calling t38_change_state() sets the t38 state so it makes little sense to
then check the state right after the call for something else.

* Made the code in t38_interpret_parameters() reject or exit T.38 mode as
intended but not implemented.

Change-Id: Ib281263a6ed44da9448132c4e6df1e183b8a3df2
2015-07-06 16:08:47 -05:00
Mark Michelson 3cdbe696a3 Merge "res_pjsip: Failover when server is not available" 2015-07-06 11:52:47 -05:00
Kevin Harwell 74135c8efa res_pjsip: Failover when server is not available
Previously Asterisk did not properly failover to the next resolved DNS
address when a endpoint could not be reached. With this patch, and while
using res_pjsip, SIP requests (both in/out of dialog) now attempt to use
the next address in the list of resolved addresses until a proper response
is received or no more addresses are left.

ASTERISK-25076 #close
Reported by: Joshua Colp

Change-Id: Ief14f4ebd82474881f72f4538f4577f30af2a764
2015-07-06 10:49:08 -05:00
Joshua Colp 38a3c27a09 res_sorcery_memory_cache: Execute stale unit test last.
In Jenkins there is currently a sporadic test failure of a
variable number of sorcery memory cache unit tests. I have not
been able to reproduce this on the build agents themselves or
on my development machine.

My working theory is that the stale unit test is causing a
sorcery instance to persist longer than expected, causing subsequent
tests to fail when setting up and initializing the next
sorcery instance.

To see if this is the case this change moves the stale unit test
to execute last so no subsequent unit tests can have issues
initializing their sorcery instance.

Change-Id: Ifd6550a949613be774b75fa5db12c02110f82c4a
2015-07-06 11:27:53 -03:00
Joshua Colp f35a4b8525 res/res_http_websocket: Don't send HTTP response fragmented.
This change makes it so that when accepting a WebSocket
connection the HTTP response is sent as one packet instead of
fragmented. Browsers don't like it when you send it fragmented.

ASTERISK-25103

Change-Id: I9b82c4ec2949b0bce692ad0bf6f7cea9709e7f69
2015-07-04 18:26:43 -05:00
Walter Doekes 3fab8212e3 res_timing: Don't close FD 0 when out of open files.
This fixes so a failure to get a timer file descriptor does not cascade
to closing FD 0.

On error, both res_timing_kqueue and res_timing_timerfd would call the
destructor before setting the file handle. The file handle had been
initialized to 0, causing FD 0 to be closed. This in turn, resulted in
floods of "CLI>" messages and an unusable terminal.

ASTERISK-19277 #close
Reported by: Barry Chern

For the master branch, this was already fixed. This patch only ensures
that we do not attempt to close a negative file descriptor.

Change-Id: I147d7e33726c6e5a2751928d56561494f5800350
2015-07-02 05:13:37 -05:00
Joshua Colp c12ace3ab3 Merge "res_sorcery_realtime: Fix leak of sorcery object type." 2015-06-30 07:32:23 -05:00
Mark Michelson 58d18324f0 res_sorcery_realtime: Fix leak of sorcery object type.
This prevents a leak of a sorcery object type when realtime sorcery
objects are retrieved by fields or when multiple objects are retrieved.

The extent of this leak is that sorcery object types would be leaked.
These are allocated whenever an object type is registered with sorcery,
meaning that on module shutdown, these objects would be leaked. This
could be problematic if many reloads were performed, but it is not as
severe as if every sorcery object retrieved from realtime were being
leaked.

ASTERISK-25165 #close
Reported by Corey Farrell

Change-Id: I625c3b50eee4576670b7eeb013c81ad043b4b4f8
2015-06-29 14:34:58 -05:00
Matt Jordan 598a5f0d15 Merge "res_pjsip_nat: Adjust when contact should be rewritten." 2015-06-29 11:56:46 -05:00
Matt Jordan 80d97290bb res/res_corosync: Always decline module load, instead of failing
Returns a 'failure' from the module load routine indicates to Asterisk
that it should abort loading completely. This is rarely - in fact,
really, never - a good option. Aborting load of Asterisk from a dynamic
module implies that the core, and the rest of the dynamic modules, don't
matter: we should abandon all processing.

res_corosync is really not that important.

This patch updates the module such that, if it fails to load, it
politely declines (emitting ERROR messages along the way), and allows
Asterisk to continue to function.

Note that this issue was keeping Asterisk unit tests from running on
certain build agents.

Change-Id: I252249e81fb9b1a68e0da873f54f47e21d648f0f
2015-06-26 22:06:06 -05:00
Mark Michelson e18b22a806 res_pjsip_nat: Adjust when contact should be rewritten.
A previous change made the contact only get rewritten if the dialog's
route set was not marked frozen. Unfortunately, while the intent of this
is correct, the dialog's route set actually gets marked as frozen
earlier than expected, especially for UAS dialogs.

Instead, the idea is that the contact needs to not be rewritten if there
is a pre-existing route set on the dialog. This is now accomplished by
checking the dialog's route set list instead of checking if the route
set is frozen.

Doing this causes some broken tests to begin passing again.

ASTERISK-25196
Reported by Mark Michelson

Change-Id: I525ab251fd40a52ede327a52a2810a56deb0529e
2015-06-26 16:12:33 -05:00
Richard Mudgett 99b1aa6d26 res_pjsip_outbound_registration.c: Add a serializer shutdown group.
The client_state objects contain a serializer used to send the outbound
REGISTER messages.  Once all those message transactions are complete then
the module can shutdown.

ASTERISK-24907 #close
Reported by: Kevin Harwell

Change-Id: Ibb2fe558f98190f2a06da830e0fadfa25516f547
2015-06-26 13:45:15 -05:00
Matt Jordan c0194b55b5 Merge "threadpool, res_pjsip: Add serializer group shutdown API calls." 2015-06-26 13:36:17 -05:00
Matt Jordan 8c1161a268 Merge "res_pjsip_outbound_registration.c: Fix handle_client_state_destruction() refs" 2015-06-26 13:34:54 -05:00
Matt Jordan 4208fe6ba7 Merge "res_pjsip_outbound_registration.c: Use ast_sorcery_object_unregister() API" 2015-06-26 13:34:47 -05:00
Matt Jordan d568177d7d Merge "res_pjsip_refer: Prevent sending duplicate headers." 2015-06-26 11:26:43 -05:00
Matt Jordan 8a9628dce5 Merge "res_pjsip_outbound_registration.c: Reorder load_module() and unload_module()." 2015-06-26 11:25:49 -05:00
Matt Jordan 05dbfedb43 Merge "res_pjsip_nat: Rewrite route set when required." 2015-06-26 10:59:35 -05:00
Mark Michelson f536e9b59c res_pjsip_refer: Prevent sending duplicate headers.
res_pjsip_refer will attempt to add Referred-By or Replaces headers to
outbound INVITEs at times. If the INVITE gets challenged for
authentication, then we will resend the INVITE. Prior to this patch, the
Referred-By or Replaces header would be re-added to the outbound INVITE,
resulting in duplicated headers.

ASTERISK-25204 #close
Reported by Mark Michelson

Change-Id: I59fb5c08b4d253c0dba9ee3d3950b5025358222d
2015-06-26 10:41:05 -05:00
Mark Michelson 700606a659 res_pjsip_nat: Rewrite route set when required.
When performing some provider testing, the rewrite_contact option was
interfering with proper construction of a route set when sending an ACK
after receiving a 200 OK response to an INVITE.

The initial INVITE was sent to address sip:foo. The 200 OK had a Contact
header with URI sip:bar. In addition, the 200 OK had Record-Route
headers for sip:baz and sip:foo, in that order. Since the Record-Route
headers had the lr parameter, the result should have been:

* Set R-URI of the ACK to sip:bar.
* Add Route headers for sip:foo and sip:baz, in that order.

However, the rewrite_contact option resulted in our rewriting the
Contact header on the 200 OK to sip:foo. The result was:

* R-URI remained sip:foo.
* We added Route headers for sip:foo and sip:baz, in that order.

The result was that sip:bar was not indicated in the ACK at all, so the
far end never received our ACK. The call eventually dropped.

The intention of rewrite_contact is to rewrite the most immediate
destination of our SIP request to be the same address on which we
received a request or response. In the case of processing a SIP response
with Record-Route headers, this means that instead of rewriting the
Contact header, we should instead rewrite the bottom-most Record-Route
header. In the case of processing a SIP request with Record-Route
headers, this means we rewrite the top-most Record-route header.
Like when we rewrite the Contact header, we also ensure to update
the dialog's route set if it exists.

ASTERISK-25196 #close
Reported by Mark Michelson

Change-Id: I9702157c3603a2d0bd8a8215ac27564d366b666f
2015-06-26 09:53:26 -05:00
Richard Mudgett af4ae3095e threadpool, res_pjsip: Add serializer group shutdown API calls.
A module trying to unload needs to wait for all serializers it creates and
uses to complete processing before unloading.

ASTERISK-24907
Reported by: Kevin Harwell

Change-Id: I8c80b90f2f82754e8dbb02ddf3c9121e5e966059
2015-06-25 14:33:44 -05:00
Richard Mudgett 4c133d81cd res_pjsip_outbound_registration.c: Fix handle_client_state_destruction() refs
* handle_client_state_destruction() must always be passed a ref to
client_state because it will always unref client_state.
handle_registration_response() was not passing a client_state ref.

* Made the final un-REGISTER message get sent normally using the pjproject
register control structure in handle_client_state_destruction().  The
previous code attempted to short circuit the response handling for the
module to unload.  That doesn't work for a couple reasons.  One,
pjsip_regc_send() may call the registered callback before it returns and
unbalance the client_state ref count.  Two, the registered callback
handles any authentication for the un-REGISTER message.

* Made the distinction between internal registration state and external
registration status with sip_outbound_registration_status_str().  This is
necessary to avoid altering documented AMI messages with internal
changes.

* Removed references to client_state->client outside of the serializer
thread.  When handle_client_state_destruction() destroys the pjproject
register control structure that memory is freed and cannot be referenced
anymore.  These accesses were to provide information for debug and
off-nominal warning messages.

* In sip_outbound_registration_timer_cb() you should not access entry->id
after unrefing client_state because the passed in entry is normally
pointing to the timer entry in the client_state object.

ASTERISK-24907
Reported by: Kevin Harwell

Change-Id: Ia7b446d8644b6b4550ef5bea49527671de65183f
2015-06-25 14:33:44 -05:00
Richard Mudgett dc63377c60 res_pjsip_outbound_registration.c: Use ast_sorcery_object_unregister() API
The sorcery pjsip 'registration' config object needs to be destroyed on
module unload.  Otherwise, a reload of res_pjsip could try to use
callbacks for a previously unloaded instance of the module provided by
ast_sorcery_object_register() or one of the variants.  Also, if
res_pjsip_outbound_registration were subsequently reloaded, the sorcery
config field objects would be registered in sorcery twice.

ASTERISK-24907
Reported by: Kevin Harwell

Change-Id: I304fad13dece2604af48353f6c6d9d5c7b064697
2015-06-25 14:32:19 -05:00
Richard Mudgett 77ff7325a2 res_pjsip_outbound_registration.c: Reorder load_module() and unload_module().
It is best if the loading code creates and initializes the module's
infrastructure before letting the system know of its existence.  The
unloading code needs to reverse the actions of the loading code and in the
reverse order.

ASTERISK-24907
Reported by: Kevin Harwell

Change-Id: I5d151383e9787b5b60aa5e1627b10f040acdded4
2015-06-25 14:30:48 -05:00
Mark Michelson 3f1fe83633 Merge "res_pjsip_mwi: Set up unsolicited MWI upon registration." 2015-06-25 09:51:48 -05:00
Richard Mudgett 71a4d1a033 Unit tests: Fix more unit test description strings.
Analyzing the code shows that the unit test summary and description
strings should not end with a new-line character.  Where these strings are
used in the code a new-line is provided for output.

Change-Id: I2f4f37988ec363c8d1c5077a2fc8ca841c5cd30c
2015-06-24 17:13:31 -05:00
Richard Mudgett af66b0f3f7 res_pjsip_outbound_registration.c: Add missing line endings to CLI commands
Change-Id: I39ae612746d892d2dbe86f3ff2d7027fa1da57f7
2015-06-23 13:16:47 -05:00
Richard Mudgett 3f0708e5fe res_pjsip_outbound_registration.c: Eliminate simple RAII_VAR() usage.
Change-Id: I399cb9d61bbba706b48c98e0bf75e98984cd9a9e
2015-06-23 13:16:24 -05:00
Richard Mudgett 9ceb848242 res_pjsip_outbound_registration.c: Misc code cleanups.
* Break some long lines.

* Fix doxygen comment.

Change-Id: I8f12ba6822f84d5e7bb575280270cd7e2fefb305
2015-06-23 13:16:08 -05:00
Joshua Colp 7846f73432 res_pjsip_mwi: Set up unsolicited MWI upon registration.
The res_pjsip_mwi previously required a reload to set up the proper
subscriptions to allow unsolicited MWI to work. This change
makes it so the act of registering will also cause this to occur.
This is particularly useful if realtime is involved as no reload
needs to occur within Asterisk to cause the MWI information
to get sent.

ASTERISK-25180 #close

Change-Id: Id847b47de4b8b3ab8858455ccc2f07b0f915f252
2015-06-23 08:15:05 -05:00
Richard Mudgett 096b27d9d2 res_pjsip_outbound_registration.c: Fix whitespace conflict potential.
Change-Id: I82e6e388e3688aebe0783f16c9e0800a747584b5
2015-06-22 13:57:21 -05:00
Matt Jordan bd77ace25a Merge "Resolve race conditions involving Stasis bridges." 2015-06-19 10:11:36 -05:00
Mark Michelson d7a1e84a1e Resolve race conditions involving Stasis bridges.
This resolves two observed race conditions.

First, a bit of background on what the Stasis application does:

1a Creates a stasis_app_control structure. This structure is linked into
   a global container and can be looked up using a channel's unique ID.
2a Puts the channel in an event loop. The event loop can exit either
   because the stasis_app_control structure has been marked done, or
   because of some other factor, such as a hangup. In the event loop, the
   stasis_app_control determines if any specific ARI commands need to be
   run on the channel and will run them from this thread.
3a Checks if the channel is bridged. If the channel is bridged, then
   ast_bridge_depart() is called since channels that are added to Stasis
   bridges are always imparted as departable.
4a Unlink the stasis_app_control from the container.

When an ARI command is received by Asterisk, the following occurs
1b A thread is spawned to handle the HTTP request
2b The stasis_app_control(s) that corresponds to the channel(s) in the
   request is/are retrieved. If the stasis_app_control cannot be
   retrieved, then it is assumed that the channel in question has exited
   the Stasis app or perhaps was never in Stasis in the first place.
3b A command is queued onto the stasis_app_control, and the channel's
   event loop thread is signaled to run the command.
4b While most ARI commands do nothing further, some, such as adding or
   removing channels from a bridge, will block until the command they
   issued has been completed by the channel's event loop.

The first race condition that is solved by this patch involves a crash
that can occur due to faulty detection of the channel's bridged status
in step 3a. What can happen is that in step 2a, the event loop may run
the ast_bridge_impart() function to asynchronously place the channel
into a bridge, then immediately exit the event loop because the channel
has hung up. In step 3a, we would detect that the channel was not
bridged and would not call ast_bridge_depart(). The reason that the
channel did not appear to be bridged was that the depart_thread that is
spawned by ast_bridge_impart() had not yet started. That is the thread
where the channel is marked as being bridged. Since we did not call
ast_bridge_depart(), the Stasis application would exit, and then the
channel would be destroyed Then the depart_thread would start up and
try to manipulate the destroyed channel, causing a crash.

The fix for this is to switch from using ast_channel_is_bridged() to
checking the NULLity of ast_channel_internal_bridge_channel() to
determine if ast_bridge_depart() needs to be called. The channel's
internal bridge_channel is set when ast_bridge_impart() is called and
is NULLed by the call to ast_bridge_depart(). If the channel's internal
bridge_channel is non-NULL, then the channel must have been imparted
into the bridge and needs to be departed, even if the actual bridging
operation has not yet started. By departing the channel when necessary,
the thread that is running the Stasis application will block until the
bridge gives the okay that the depart_thread has exited.

The second race condition that is solved by this patch involves a leak
of HTTP handler threads. The problem was that step 2b would successfully
retrieve a stasis_app_control structure. Then step 2a would exit the
channel from the event loop due to a hangup. Steps 3a and 4a would
execute, and then finally steps 3b and 4b would. The problem is that at
step 4b, when attempting to add a channel to a bridge, the thread would
block forever since the channel would never execute the queued command
since it was finished with the event loop. This meant that the HTTP
handling thread would be leaked, along with any references that thread
may have owned (in my case, I was seeing bridges leaked).

The fix for this is to hone in better on when the channel has exited the
event loop. The stasis_app_control structure has an is_done field that
is now set at each point where the channel may exit the event loop. If
step 2b retrieves a valid stasis_app_control structure but the control
is marked as done, then the attempted operation exits immediately since
there will be nothing to service the attempted command.

ASTERISK-25091 #close
Reported by Ilya Trikoz

Change-Id: If66265b73b4c9f8f58599124d777fedc54576628
2015-06-18 16:19:20 -05:00
Joshua Colp 9668a1acb5 res_sorcery_memory_cache: Remove 'prefetch' option.
To prevent confusion I am removing the prefetch option until such
time as it is implemented. All other functionality, however, has
been implemented.

ASTERISK-25067

Change-Id: I9ce6aa3e5c6c5bc3c5baa8ff90fa036d73939895
2015-06-17 09:00:21 -03:00
Matt Jordan 8c0b917032 Merge "Parking: Add documentation for AMI ParkedCallSwap event." 2015-06-16 11:40:34 -05:00
Mark Michelson 59552c2d08 Parking: Add documentation for AMI ParkedCallSwap event.
This event was added some time ago in order to clarify when a channel
took the place of another channel in a parking lot. However, there was
no XML documentation added for the event. This patch adds the XML
documentation.

ASTERISK-24900 #close
Reported by Rusty Newton

Change-Id: I4cfe7777c4b94bbff91c9221c6096a7a02a92eac
2015-06-16 11:22:11 -05:00
Kevin Harwell 93ac45d3bd res_pjsip: Add option to force G.726 to be treated as AAL2 packed.
Some phones send g.726 audio packed for AAL2, which differs from what is
recommended by RFC 3351. If Asterisk receives audio formatted as such when
negotiating g.726 then it sounds a bit distorted. Added an option to
res_pjsip_endpoint that allows g.726 negotiated audio to be treated as g.726
AAL2 packed.

ASTERISK-25158 #close
Reported by: Steve Pitts

Change-Id: Ie7e21f75493d7fe53e75e12c971e72f5afa33615
2015-06-15 12:40:03 -05:00
Richard Mudgett 30cd559345 DNS: Need to use the same serializer for a pjproject SIP transaction.
All send/receive processing for a SIP transaction needs to be done under
the same threadpool serializer to prevent reentrancy problems inside
pjproject when using an external DNS resolver to process messages for the
transaction.

* Add threadpool API call to get the current serializer associated with
the worker thread.

* Pick a serializer from a pool of default serializers if the caller of
res_pjsip.c:ast_sip_push_task() does not provide one.

This is a simple way to ensure that all outgoing SIP request messages are
processed under a serializer.  Otherwise, any place where a pushed task is
done that would result in an outgoing out-of-dialog request would need to
be modified to supply a serializer.  Serializers from the default
serializer pool are picked in a round robin sequence for simplicity.

A side effect is that the default serializer pool will limit the growth of
the thread pool from random tasks.  This is not necessarily a bad thing.

* Made pjsip_resolver.c use the requesting thread's serializer to execute
the async callback.

* Made pjsip_distributor.c save the thread's serializer name on the
outgoing request tdata struct so the response can be processed under the
same serializer.

ASTERISK-25115 #close
Reported by: John Bigelow

Change-Id: Iea71c16ce1132017b5791635e198b8c27973f40a
2015-06-10 19:22:13 -05:00
Richard Mudgett b23f33e7e5 DNS: Fix some corner cases.
* Fix query_set destruction before we are done kicking the queries off.

* Fixed no queries requested handling.

* Add empty queries request unit test.

* Added missing allocation check in ast_dns_query_set_add().

* Made initial pjsip resolving query vector slightly larger.

ASTERISK-25115
Reported by: John Bigelow

Change-Id: Ie8be8347d0992e93946d72b6e7b1299727b038f2
2015-06-10 18:06:15 -05:00
Richard Mudgett ae589da466 DNS: Remove trailing newline from summary and descriptions.
Those trailing newlines mess up test formatting.

Change-Id: I5e3f3a55b82c9d7acb9661201d4993d1958f1185
2015-06-10 18:06:14 -05:00
Richard Mudgett 83bc9d366d pjsip_resolver.c: Fix debug code to only execute at acceptable debug level.
Change-Id: I1716c93d6e097ad28128ecb9e806aac7a4180c8a
2015-06-10 13:07:02 -05:00
Ivan Poddubny 07f5f45e5a res_pjsip_transport_websocket: Fix use-after-free bugs.
This patch fixes use-after-free bugs caught by AddressSanitizer.

1. PJSIP transport manager may decide to destroy transport on its own.
For example, when the contact registered via websocket has not renewed
its registration in time. The transport was destoyed, but the websocket
listener thread was still active until the socket closes, and then tried
to call transport_shutdown on transport that has been freed.

Also, the transport destructor accessed wstransport->rdata.tp_info.pool
right after freeing memory that contained wstransport itself.

This patch converts transport to an ao2 object, allowing it to be
refcounted, so that it is available until both websocket listener and
pjsip transport manager are finished with it.

2. The websocket listener deletes the last reference on websocket session
when the tcp connection is closed, and it gets destroyed, but
the transport manager may still use it, for example when disconnect
happens in the middle of a SIP transaction.

A new reference to websocket session has been added that is released
with the transport to prevent this.

ASTERISK-25096 #close
Reported by: Josh Kitchens

ASTERISK-24963 #close
Reported by: Badalian Vyacheslav

Change-Id: Idc0b63eb6e459c1ddfb2430127d34b3c4d8d373b
2015-06-10 17:00:39 +03:00
Matt Jordan 8785d0ccbf Merge "test_sorcery_memory_cache_thrash: Add unit tests for thrashing the memory cache." 2015-06-05 18:04:25 -05:00
Matt Jordan 5788c6db67 Merge "res_sorcery_memory_cache: Implement expire_on_reload option." 2015-06-05 18:04:17 -05:00
David M. Lee 9fca378b36 Fixes for OS X
* Add some type casting so tv_usec can really be a long, instead of
   some strange platform specific type.

 * Add some .dylib style files to .gitignore.

 * Switch from using -Xlinker to -Wl,. For [reasons unknown][], newer
   versions of GCC, when compiling the Homebrew formula for Asterisk,
   are not properly passing the -Xlinker options to the linker. Given
   that -Wl, does exactly the [same thing][], and does it properly, this
   patch changes the -Xlinker options to use -Wl, instead.

 [reasons unknown]: http://bit.ly/1SUbEYx
 [same thing]: https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

Change-Id: Id5e6b3c6cc86282ea5fca630dc3991137c5bf4dd
2015-06-05 11:23:16 -05:00
Joshua Colp 128fe4cee8 res_sorcery_memory_cache: Implement expire_on_reload option.
This change implements the expire_on_reload option for memory caches.
If enabled and a reload is performed all objects within the cache
will be expired and the cache emptied.

ASTERISK-25067
Reported by: Matt Jordan

Change-Id: Id46aa1957d660556700e689e195eed57c989b85e
2015-06-04 15:28:31 -03:00
Joshua Colp 028edae82e test_sorcery_memory_cache_thrash: Add unit tests for thrashing the memory cache.
This change adds a CLI command which can perform memory cache thrashing as well
as unit tests which perform thrashing under the following configurations:

1. Low number of unique objects that go stale after 1 second
2. Low number of unique objects that expire after 1 second
3. Low number of unique objects which are constantly updated
4. Large number of unique objects which exceed a defined cache size
5. Large number of unique objects which exceed a defined cache size
   that also expire and go stale rapidly
6. Large number of unique objects which expire and go stale rapidly
7. Large number of unique objects

For all of the above there are a large number of threads constantly
attempting to retrieve random objects and each test runs for a few
seconds.

ASTERISK-25067
Reported by: Matt Jordan

Change-Id: I8c8ceff977332c80ed4a31f10d694d48552b2f78
2015-06-04 15:06:08 -03:00
Mark Michelson 86c79314f1 Merge "res_sorcery_memory_cache: Add test event when a refresh occurs." 2015-06-04 09:48:09 -05:00
Matt Jordan 269fbff366 Merge "Remove const cast from leaf functions." 2015-06-04 06:42:30 -05:00
Joshua Colp 19de2bbc5f res_sorcery_memory_cache: Add test event when a refresh occurs.
This change adds a testsuite event for when a refresh occurs.
This is useful as it provides a guaranteed mechanism of knowing when
it has occurred instead of waiting an arbitrary amount of time.

ASTERISK-25067
Reported by: Matt Jordan

Change-Id: Iaa6b8d2d6bab7f99ee08e1c8908b8272a8987e65
2015-06-04 07:33:30 -03:00
Mark Michelson 92ccffd9e6 res_pjsip: Prevent access of NULL channels.
It is possible to receive incoming requests or responses after the channel
on an ast_sip_session has been destroyed and NULLed out. Handlers of these
sorts of requests or responses need to be prepared for the possibility
that the channel is NULL or else they could cause a crash.

While several places have been amended to deal with NULL channels, there
were still a couple of places that needed updating.

res_pjsip_dtmf_info.c: When handling incoming INFO requests, we need to
return early if there is no channel on the session.

res_pjsip_session.c: When handling a 302 response, we need to stop the
redirecting attempt if there is no channel on the session.

ASTERISK-25148 #close
reported by Mark Michelson

Change-Id: Id1a75ffc3d0eaa168b0b28188fb54d6cf9fc47a9
2015-06-03 17:41:23 -05:00
George Joseph d355ee7ff3 res_pjsip/location: Fix ref leak in contact_apply_handler
contact_apply_handler calls ast_res_pjsip_find_or_create_contact_status
to force the creation of a contact_status object whenever a new
contact is added but it didn't unref the returned object.

Added an ao2_cleanup(status) to plug the leak.

ASTERISK-25141

Change-Id: Icc1401cae142855a1abc86ab5179dfb3ee861c40
Reported-by: Corey Farrell
2015-06-03 13:25:29 -05:00
Richard Mudgett 6d8dc9bb5c res_pjsip: Remove outgoing authentication code no longer needed.
Associated with ASTERISK-25131

Change-Id: Iefa3b2066cfd8b108a90d2dd4a64d92c3a195d33
2015-06-02 13:11:31 -05:00
Richard Mudgett 00a47ffc7e res_pjsip_session: Fix cherry pick to master compile error.
ASTERISK-25131
Reported by: Richard Mudgett

Change-Id: I87c9c96ae4a8fe2bc8a0ddea6958a2ad9cefd8e3
2015-06-02 13:09:12 -05:00
Joerg Sonnenberger 9472bbaa95 Remove const cast from leaf functions.
app_control_register_rule and app_control_unregister_rule lock/unlock
the queue, which is a mutating operation according to the
ao2_lock/_unlock prototype. Depending on the specific (implicit) casts
in SCOPED_LOCK and RAII_VAR, the compiler may warn or not. As the only
callers of those functions do not have the const, get consistent results
by just dropping it.

Change-Id: Ib9e6296155a39bc5d627142a3828180c3cfe8fbb
2015-06-02 19:27:28 +02:00
Matt Jordan af420ba4ae Merge "res_pjsip_session: Fix in-dialog authentication." 2015-06-02 09:29:46 -05:00
Mark Michelson 3906175426 Merge "res_sorcery_memory_cache: Add CLI commands and AMI actions." 2015-06-01 13:04:10 -05:00
Joshua Colp 34bb5ca97c Merge "res_sorcery_memory_cache: Add support for refreshing stale objects." 2015-06-01 13:01:17 -05:00
Richard Mudgett 5cdcae5240 res_pjsip_session: Fix in-dialog authentication.
When the remote peer requires authentication for in-dialog requests then
re-INVITEs to the peer cause the call to be disconnected and other
in-dialog requests to the peer like MESSAGE just don't go through.

* Made session_inv_on_tsx_state_changed() handle in-dialog authentication
for re-INVITEs and other methods.  Initial INVITEs cannot be handled here
because the INVITE transaction must be restarted earlier.

* Pulled needed code from res/res_pjsip/pjsip_outbound_auth.c in
preparation for removing the file.  The generic outbound authentication
code did not work as well as anticipated.

* Created outbound_invite_auth() to only handle initial outbound INVITEs.
Re-INVITEs cannot be handled here.  The re-INVITE transaction is still in
progress and the PJSIP library cannot handle the overlapping INVITE
transactions.  Other method types should not be handled here as this code
only works on outgoing calls and we need to handle incoming and outgoing
calls.

ASTERISK-25131 #close
Reported by: Richard Mudgett

Change-Id: I12bdd7ddccc819b4ce4b091e826d1e26334601b0
2015-06-01 10:50:35 -05:00
Corey Farrell 9f1939ee27 pjsip_configuration: Fix leak in persistent_endpoint_update_state.
The loop to find the first available contact of an endpoint grabbed
contact from the iterator, then checked for offline state.  This
caused the first contact after the state was found to leak a reference.

ASTERISK-25141

Change-Id: Id0f1d87410fc63742db0594eb4b18b36e99aec08
2015-06-01 03:08:50 -05:00
George Joseph bef000dd7c res_pjsip/location: Fix memory leak in permanent_uri_handler
When permanent_uri_handler was creating the contact status
object for each contact, it wasn't unreffing it at the
end of the loop.

ASTERISK-25141 #close
Reported-by: Corey Farrell

Change-Id: I7bb127994677bb3d459f87952f8425c9b9967b12
2015-05-29 16:34:27 -05:00
Joshua Colp dfc45254d1 res_sorcery_memory_cache: Add CLI commands and AMI actions.
This change adds the following CLI commands and AMI actions:

sorcery memory cache show
sorcery memory cache dump
sorcery memory cache expire
sorcery memory cache stale

SorceryMemoryCacheExpire
SorceryMemoryCacheExpireObject
SorceryMemoryCacheStale
SorceryMemoryCacheStaleObject

These allow both examination and manipulation of sorcery memory
caches from external sources.

Cached objects can be explicitly expired from a cache or marked
as stale. If expired they are immediately removed. If marked as
stale they will be background refreshed when next retrieved.

ASTERISK-25067
Reported by Matt Jordan

Change-Id: I68e03cfd8c34b5e07f4b6ee4fd93a3f4a00a3d9e
2015-05-29 14:00:55 -03:00
Matt Jordan 9159abb158 Merge "res/res_config_pgsql.c: Use PQescapeStringConn for escaping names." 2015-05-29 04:41:45 -05:00
Mark Michelson 2e54e7227c res_sorcery_memory_cache: Add support for refreshing stale objects.
This change introduces a check of object_lifetime_stale when retrieving
cached objects. If the amount of time the object has been in the cache
exceeds the lifetime, then a task is scheduled to update the cached
object based on an object retrieved from other sorcery wizards instead.

To prevent the cached object from being retrieved during a refresh,
thread-local storage is used to mark the thread as being a stale object
update. This results in the cache returning no object, leading to
sorcery querying other wizards for the object instead.

A test has been added for stale objects as well. This test ensures that
stale objects are retrieved the same as freshly-cached objects. The test
also ensures that after an object is stale, changes in the backend are
reflected in the cache, to include if the object has been deleted from
the backend.

ASTERISK-25067
Reported by Matt Jordan

Change-Id: I9bd7c049adf6939bfe2899f393c2bfbbf412d217
2015-05-27 15:22:35 -05:00
George Joseph b8ac683822 res_pjsip: Add AMI events for chan_pjsip contact lifecycle changes
Add a new ContactStatus AMI event.
Publish the following status/state changes:
Created
Removed
Reachable
Unreachable
Unknown

Contact URI, new status/state, aor and endpoint names, and the
last qualify rtt result are included in the event.

ASTERISK-25114 #close

Change-Id: Id25aae5f7122facba183273efb3e8f36c20fb61e
Reported-by: George Joseph <george.joseph@fairview5.com>
Tested-by: George Joseph <george.joseph@fairview5.com>
2015-05-26 16:47:55 -05:00
Rodrigo Ramírez Norambuena 95b186a174 res/res_config_pgsql.c: Use PQescapeStringConn for escaping names.
Use function PQescapeStringConn for escaping the name of the table and
schema instead of doing it manually.

ASTERISK-25132 #close
Reported By: Rodrigo Ramírez Norambuena <decipher.hk@gmail.com>

Change-Id: I302a263f7210d20925f14716b508b081998b7608
2015-05-26 16:48:27 -04:00
Matt Jordan e1a64e021b Merge "Stasis: Fix unsafe use of stasis_unsubscribe in modules." 2015-05-24 13:56:20 -05:00
Ivan Poddubny 70d54ab6c4 res_pjsip_transport_websocket: Fix crash on receiving large SIP packets
Incoming SIP packets larger than PJSIP_MAX_PKT_LEN were themselves
truncated before passing to pjsip_tpmgr_receive_packet, but the length
was passed unaltered, thus causing memory corruption and segfault.

ASTERISK-25122 #close

Change-Id: I608a6b6b7f229eacc33a0a7d771d18e27e5b08ab
2015-05-23 13:15:34 +03:00
Corey Farrell 50044fdc15 Stasis: Fix unsafe use of stasis_unsubscribe in modules.
Many uses of stasis_unsubscribe in modules can be reached through unload.
These have been switched to stasis_unsubscribe_and_join.

Some subscription callbacks do nothing, for these I've created a noop
callback function in stasis.c.  This is used by some modules that monitor
MWI topics in order to enable cache, since the callback does not become
invalid after dlclose it is safe to use stasis_unsubscribe on these, even
during module unload.

ASTERISK-25121 #close

Change-Id: Ifc2549fbd8eef7d703c222978e8f452e2972189c
2015-05-22 22:30:22 -05:00
Matt Jordan f66c41e668 res/res_pjsip_pubsub: Note that 'dialog' is also a valid event type for RLS
In addition to specifying lists of 'presence' and 'message-summary',
users can also create lists of type 'dialog'. These should be treated in
the same fashion as 'presence'.

Change-Id: I583bb69cd9f88b0b29bf09ddaddeac4e84189f6e
2015-05-22 12:27:56 -05:00
Matt Jordan ad7192a8fd res/res_pjsip_exten_state: Fix confusing NOTICE message
When a SUBSCRIBE request is made to a dialplan hint that doesn't exist,
the current NOTICE message informing users of this swaps the context and
extension parameters. This can cause a bit of confusion.

Thanks to CptBurger in #asterisk for helping to point this out.

Change-Id: Ie584d1a58ae217385c87a450ca25b55ca0e36e43
2015-05-22 12:23:52 -05:00
Mark Michelson f7dc49b1f0 Merge "res_sorcery_memory_cache: Add support for object_lifetime_maximum." 2015-05-22 11:55:24 -05:00
Matt Jordan 9cffcca5f9 res/ari: Register Stasis application on WebSocket attempt
Prior to this patch, when a WebSocket connection is made, ARI would not
be informed of the connection until after the WebSocket layer had
accepted the connection. This created a brief race condition where the
ARI client would be notified that it was connected, a channel would be
sent into the Stasis dialplan application, but ARI would not yet have
registered the Stasis application presented in the HTTP request that
established the WebSocket.

This patch resolves this issue by doing the following:
 * When a WebSocket attempt is made, a callback is made into the ARI
   application layer, which verifies and registers the apps presented in
   the HTTP request. Because we do not yet have a WebSocket, we cannot
   have an event session for the corresponding applications. Some
   defensive checks were thus added to make the application objects
   tolerant to a NULL event session.
 * When a WebSocket connection is made, the registered application is
   updated with the newly created event session that wraps the WebSocket
   connection.

ASTERISK-24988 #close
Reported by: Joshua Colp

Change-Id: Ia5dc60dc2b6bee76cd5aff0f69dd53b36e83f636
2015-05-22 11:13:34 -05:00
Matt Jordan d7086a27b4 Merge "res_sorcery_memory_cache: Add support for maximum_objects." 2015-05-22 10:57:03 -05:00
Joshua Colp 5aa1c30b31 Merge "res_pjsip: Refactor endpt_send_transaction (qualify_timeout)" 2015-05-22 10:40:54 -05:00
Mark Michelson 242306ade3 Merge "res_pjsip_outbound_registration: Check request URI for line." 2015-05-22 10:38:20 -05:00
George Joseph 29ef6571cb res_pjsip: Refactor endpt_send_transaction (qualify_timeout)
This patch refactors the transaction timeout processing to eliminate
calling the lower level public pjsip functions and reverts to calling
pjsip_endpt_send_request again.  This is the result of me noticing
a possible incompatibility with pjproject-2.4 which was causing
contact status flapping.

The original version of this feature used the lower level calls to
get access to the tsx structure in order to cancel the transaction
when our own timer expires. Since we no longer have that access,
if our own timer expires before the pjsip timer, we call the callbacks
and just let the pjsip transaction take it's own course.  When the
transaction ends, it discovers the callbacks have already been run
and just cleans itself up.

A few messages in pjsip_configuration were also added/cleaned up.

ASTERISK-25105 #close

Change-Id: I0810f3999cf63f3a72607bbecac36af0a957f33e
Reported-by: George Joseph <george.joseph@fairview5.com>
Tested-by: George Joseph <george.joseph@fairview5.com>
2015-05-22 10:17:32 -05:00
Joshua Colp 81d375baad res_sorcery_memory_cache: Add support for object_lifetime_maximum.
This makes the "object_lifetime_maximum" option operational.

On the addition of an object to an empty memory cache a scheduled
task is created which, when invoked, expires objects from the cache
which have exceeded their lifetime. If more objects have been added
the remaining life of the oldest object is used to schedule the
next invocation of the scheduled task.

If the oldest object is removed from the cache before it can be
expired automatically the scheduled task is cancelled, if possible,
and the lifetime of the next oldest is used to schedule the task.

If during these two operations no additional objects exist in the
cache then no task is scheduled.

An additional unit test has been added which verifies this
functionality.

ASTERISK-25067
Reported by: Matt Jordan

Change-Id: I87409674674a508e7717ee20739ca15cec6ba7b6
2015-05-22 11:57:26 -03:00
demon-ru 9e2a582d2d res_pjsip_outbound_registration: Check request URI for line.
When an inbound call is received the To header is checked
for the "line" option. Some remote servers will place this
in the request URI instead. This adds an additional check for
the option in the request URI.

ASTERISK-25072 #close
Reported by: Dmitriy Serov

Change-Id: Id4e44debbb80baad623b914a88574371575353c8
2015-05-22 09:57:09 -05:00
Mark Michelson 071b3d43cb res_sorcery_memory_cache: Add support for maximum_objects.
This makes the "maximum_objects" option operational.

A heap has been added alongside the hash table in the cache. When
objects are added to the cache, they are also added to the heap.
Similarly, when objects are removed from the cache, they are removed
from the heap.

The heap's use comes into play when an item is to be added to a "full"
cache. When the cache is full, the oldest item is removed from the
cache, using the heap to determine the oldest item.

A unit test has been added that verifies that the maximum_objects option
works as expected and that the oldest object is removed from the cache
when an object beyond the maximum is added.

ASTERISK-25067 #close
Reported by Matt Jordan

Change-Id: I490658830e9c4cbf0b3051e4cdc4913cf9f1b73a
2015-05-22 09:46:58 -05:00
Joshua Colp f2cc766d81 res_sorcery_memory_cache: Add basic module implementation.
This change adds a basic res_sorcery_memory_cache module which implements
configuration option parsing, configuration file parsing for threading,
sorcery interface implementation, and unit tests.

Objects can be added, updated, deleted, and retrieved from the memory
cache. Automatic expiration and stale handling will be added in the
future.

Note that unit tests exist within the module itself in case the
threading done as a result of expiration results in asynchronous
actions (which it likely will). Providing access and a notification
mechanism for an external test module would be complicated and
not worth it.

ASTERISK-25067 #close
Reported by: Matt Jordan

Change-Id: Id8a6a357ef5a83d466f81eee56a67d13eeb118b9
2015-05-22 09:28:24 -05:00
Corey Farrell 36e5402885 res_mwi_external_ami: Use module version of AMI registration.
Use ast_manager_register_xml for res_mwi_external_ami manager
actions.  This ensures the module is held open while any of
the actions are being run.

ASTERISK-25117 #close
Reported by: Corey Farrell

Change-Id: Iececfdc2da498b2c32b9e09042f5f12292007ac7
2015-05-21 18:18:57 -05:00
Matt Jordan 5ce54ed74a res/res_http_websocket: Add a pre-session established callback
This patch updates http_websocket and its corresponding implementation
with a pre-session established callback. This callback allows for
WebSocket server consumers to be notified when a WebSocket connection is
attempted, but before we accept it. Consumers can choose to reject the
connection, if their application specific logic allows for it.

As a result, this patch pulls out the previously private
websocket_protocol struct and makes it public, as
ast_websocket_protocol. In order to preserve backwards compatibility
with existing modules, the existing APIs were left as-is, and new APIs
were added for the creation of the ast_websocket_protocol as well as for
adding a sub-protocol to a WebSocket server.

In particular, the following new API calls were added:
* ast_websocket_add_protocol2 - add a protocol to the core WebSocket
  server
* ast_websocket_server_add_protocol2 - add a protocol to a specific
  WebSocket server
* ast_websocket_sub_protocol_alloc - allocate a sub-protocol object.
  Consumers can populate this with whatever callbacks they wish to
  support, then add it to the core server or a specified server.

ASTERISK-24988
Reported by: Joshua Colp

Change-Id: Ibe0bbb30c17eec6b578071bdbd197c911b620ab2
2015-05-20 14:47:28 -05:00
John Bigelow ddb7cbef8e res/res_resolver_unbound.c: Add missing include of signal.h
ASTERISK-25110 #close
Reported by: John Bigelow

Change-Id: I99a9d93f066f265357b647b8e99a75e45da5a39f
2015-05-20 12:55:40 -05:00
Matt Jordan d8698b7f3f doxygen: Fix doxygen errors
This patch fixes a number of errors and warning messages in the doxygen
log. Specifically, it addresses:
* A number of files incorrectly places a '\brief' tag immediately after
  a '\file' tag. Doing so emits a warning, as '\file' takes an optional
  argument specifying which file the doxygen comment is for. As '\brief'
  is not a file, doxygen was unamused.
* A grouping of Stasis Topics and Messages in rtp_engine.h was
  incorrectly terminated. We now correctly terminate the grouping, which
  prevents members of rtp_engine.h from showing up in the wrong group.
* Group indicators which are not part of the Stasis Topics and Messages
  group were removed. Group indicators without an \addtogroup or
  \ingroup have no meaning.

Change-Id: Ia1415ffec6767e27233ae1cae5ed5970de5656d4
2015-05-19 21:11:21 -05:00
George Joseph 5d93928175 res_pjsip_config_wizard/config: Fix template processing
The config wizard was always pulling the first occurrence of
a variable from an ast_variable list but this gets the template
value from the list instead of any overridden value.  This patch
creates ast_variable_find_last_in_list() in config.c and updates
res_pjsip_config_wizard to use it instead of
ast_variable_find_in_list.  Now the overridden values, where they
exist, are used instead of template variables.

Updated test_config to test the new API.

ASTERISK-25089 #close

Reported-by: George Joseph <george.joseph@fairview5.com>
Tested-by: George Joseph <george.joseph@fairview5.com>
Change-Id: Ifa7ddefc956a463923ee6839dd1ebe021c299de4
2015-05-15 17:19:49 -05:00
Joshua Colp e092a89694 Merge "MALLOC_DEBUG: Replace WRAP_LIBC_MALLOC with ASTMM_LIBC." 2015-05-14 10:57:04 -05:00
Joshua Colp 35ff01823b Merge "AST_MODULE_INFO: Format corrections to the usages of AST_MODULE_INFO macro." 2015-05-14 05:03:43 -05:00
Corey Farrell 478fb4a388 MALLOC_DEBUG: Replace WRAP_LIBC_MALLOC with ASTMM_LIBC.
There are 3 ways that calls directly to standard allocator functions can
be dealt with:
1. Block their use, cause them to generate an error.  This is the default.
2. Replace them with the Asterisk equivalent function calls.
3. Leave them alone.

This change allows one of these 3 options to be selected by any source.
The source just needs to define ASTMM_LIBC to ASTMM_BLOCK, ASTMM_REDIRECT,
or ASTMM_IGNORE to use option 1, 2 or 3 respectively.  Normally ASTMM_BLOCK
is the correct option, so it is default when ASTMM_LIBC is not defined.
In some cases when building 3rd party code it is desirable to have it use
Asterisk functions, without changing the whole source - ASTMM_REDIRECT
accomplishes this.  When using 3rd party libraries sometimes a static
inline function will make use of malloc or free.  In these cases it may
be unsafe to replace the allocator in the header, as it's possible the
memory could be freed by the library using standard allocators.  For
those cases ASTMM_IGNORE is needed.

Change-Id: I8afef4bc7f3b93914263ae27d3a5858b69663fc7
2015-05-13 21:55:07 -04:00
Rodrigo Ramírez Norambuena eec010829a AST_MODULE_INFO: Format corrections to the usages of AST_MODULE_INFO macro.
Change-Id: Icf88f9f861c6b2a16e5f626ff25795218a6f2723
2015-05-13 16:34:23 -05:00
Joshua Colp 74165b9d6c Merge "res_rtp_asterisk: Correction for the limit which detects that a packet is DTLS." 2015-05-13 10:38:24 -05:00
Joshua Colp 7b7bef722c Merge "Fix error's produced by astmm.h when standard allocators are used." 2015-05-11 05:34:06 -05:00
Yousf Ateya 2ab5d22c0d res_rtp_asterisk: Correction for the limit which detects that a packet is DTLS.
First byte of DTLS packet shall be in range 20-63, not 20-64. Refer to RFC
https://tools.ietf.org/html/rfc5764#section-5.1.2 for correct values.

Change-Id: Iae6fa0d72b37c36a27fe40686e0ae6fba3afec31
2015-05-10 16:28:26 +02:00
Corey Farrell 2d4dc0c963 Fix error's produced by astmm.h when standard allocators are used.
astmm.h includes defines that are meant to cause error's when standard
allocators (malloc, calloc, free, etc) are used.  It actually only
causes a warning, which is not always caught on certain sources.  In
modules this unknown symbol is not detected until runtime, where the
module fails to load.  This modifies the define's so that using one
of the blocked functions will cause a compile error regardless of
CFLAGS.

Moved spandsp header includes to before asterisk.h so the static inline
functions can continue using malloc and free.  Although these functions
are never called and optimized away, the updated replacement macro's
would still cause a failure.

Change-Id: I532640aca0913ba9da3b18c04a0f010ca1715af5
2015-05-08 15:38:03 -04:00
Sean Bright 63c71c9f4a res_rtp_asterisk: Issue ERROR if res_srtp is not found.
While trying to get WebRTC working with chan_pjsip, I was running
into the following error:

    Attempted to set an invalid DTLS-SRTP configuration on RTP
    instance...

Josh helpfully pointed out that res_srtp.so might not be loaded, and
sure enough, it wasn't. This patch adds a ERROR indiciating as much
to hopefully help others having a similar problem.

Change-Id: I13aa477b47b299876728a21b130998a0ea6cd19f
2015-05-08 13:34:18 -05:00
Joshua Colp e33682cae2 res_pjsip_exten_state: Fix race condition between sending NOTIFY and termination
The res_pjsip_exten_state module currently has a race condition between
processing the extension state callback from the PBX core and processing
the subscription shutdown callback from res_pjsip_pubsub. There is currently
no synchronization between the two. This can present a problem as while
the SIP subscription will remain valid the tree it points to may not.
This is in particular a problem as a task to send a NOTIFY may get queued
which will try to use the tree that may no longer be valid.

This change does the following to fix this problem:

1. All access to the subscription tree is done within the task that
sends the NOTIFY to ensure that no other thread is modifying or
destroying the tree. This task executes on the serializer for the
subscriptions.

2. A reference to the subscription serializer is kept to ensure it
remains valid for the lifetime of the extension state subscription.

3. The NOTIFY task has been changed so it will no longer attempt
to send a NOTIFY if the subscription has already been terminated.

ASTERISK-25057 #close
Reported by: Matt Jordan

Change-Id: I0b3cd2fac5be8d9b3dc5e693aaa79846eeaf5643
2015-05-07 07:42:10 -05:00
Matt Jordan f451af65c4 Merge topics 'ASTERISK-25049', 'ASTERISK-25056'
* changes:
  CLI: Enable automatic references to modules.
  Modules: Make ast_module_info->self available to auxiliary sources.
2015-05-07 07:04:43 -05:00
Kevin Harwell 1f5db1c7e3 res_stasis_snoop: Spying on a single direction continually increases CPU
Creating a snoop channel in ARI and spying only on a single direction (in or
out) results in CPU utilization continually increasing until the CPU is fully
consumed. This occurs because frames are being put in the opposing direction's
slin factory queue, but not being removed.

Fixed the problem by always reading and disposing of frames from the opposite
queue of the direction selected.

ASTERISK-24938 #closes

Change-Id: I935bfd15f1db958f364d9d6b3b45582c0113dd60
2015-05-06 17:37:51 -05:00
Matt Jordan b2a77db74a Merge "res_ari_bridges: Add missing dependencies." 2015-05-06 06:13:44 -05:00
Joshua Colp f45833c9ad Merge "Restrict functionality when ACLs are misconfigured." 2015-05-05 10:13:23 -05:00
Corey Farrell c541923ac3 res_ari_bridges: Add missing dependencies.
Missed this module in the previous commit.  res_ari_bridges uses symbols
from res_stasis_playback and res_stasis_recording.

ASTERISK-25027 #close
Reported by: Corey Farrell

Change-Id: I90bf756abd25adfc4920d2869ebe7feb636b8c5f
2015-05-05 09:53:18 -05:00
Corey Farrell df6c1d755f CLI: Enable automatic references to modules.
* Pass module to ast_cli_register and ast_cli_register_multiple.
* Add a module reference before executing any CLI callback, remove
  the reference when complete.

ASTERISK-25049 #close
Reported by: Corey Farrell

Change-Id: I7aafc7c9f2b912918f28fe51d51e9e8a755750e3
2015-05-04 20:47:18 -04:00
Corey Farrell a8bfa9e104 Modules: Make ast_module_info->self available to auxiliary sources.
ast_module_info->self is often needed to register items with the core.  Many
modules have ad-hoc code to make this pointer available to auxiliary sources.
This change updates the module build process to make the needed information
available to all sources in a module.

ASTERISK-25056 #close
Reported by: Corey Farrell

Change-Id: I18c8cd58fbcb1b708425f6757becaeca9fa91815
2015-05-04 20:47:01 -04:00
Matt Jordan 07bcaf5288 Merge "res_odbc: Use negative connection cache for all connections" 2015-05-04 07:46:12 -05:00
Martin Tomec ebe371357e res_odbc: Use negative connection cache for all connections
Apply the negative connection cache setting to all connections,
even those that are not pooled. This ensures that the connection
will not be  re-established before the negative connection cache
time is met.

ASTERISK-22708 #close

Change-Id: I431cc2e8584ab0b6908b3523d0a0e18c9a527271
2015-05-04 06:47:59 -05:00
Corey Farrell 44bbdbe3a4 res_pjsip_dlg_options: Fix MODULEINFO section.
Removed the extra space before "MODULEINFO" in res_pjsip_dlg_options.
This extra space prevented any of the dependencies from being seen by
menuselect, so building with default options would fail if PJSIP was
not installed.

This also makes the tool that extracts information for menuselect
tolerant of multiple spaces in the future.

ASTERISK-25033 #close
Reported by: Peter Whisker

Change-Id: Iccd54846f70c4a7a50cb5bf70b7bb5cb4bab3698
2015-05-02 02:22:31 -05:00
Joshua Colp bb6ddb3dc8 res_ari_device_states: Fix dependency on res_stasis_device_state.
The res_ari_device_states module depends on res_stasis_device_state,
not res_stasis_device_states.

Change-Id: I26e02ad37f9e36bcc859867e2fad1b90452ec3de
2015-04-30 13:44:57 -05:00
Mark Michelson 11ffcf662f Restrict functionality when ACLs are misconfigured.
This patch has two main purposes:

1) Improve warning messages when ACLs are configured improperly.
2) Prevent misconfigured ACLs from allowing potentially unwanted
traffic.

To acomplish point (2) in most cases, whatever configuration object that
the ACL belonged to was not allowed to load.

The one exception is res_pjsip_acl. In that case, ACLs are their own
configuration object. Furthermore, the module loading code has no
indication that a ACL configuration had a failure. So the tactic taken
here is to create an ACL that just blocks everything.

ASTERISK-24969
Reported by Corey Farrell

Change-Id: I2ebcb6959cefad03cea4d81401be946203fcacae
2015-04-30 10:43:51 -05:00
Joshua Colp 80aa9aee5d res_pjsip_outbound_registration: Fix double unref on error return.
When the PJSIP pjsip_regc_send function is invoked and an error
status returned the caller currently decrements the reference count
of the client state that it just incremented, assuming the
registration callback would not have been invoked. In practice
this is not correct. If the failure happens after the transaction
has been set up the callback will still be invoked. This will
cause the reference count to be incorrectly decremented twice, once
by the registration callback and second by the caller of
pjsip_regc_send.

This change makes it so that whether the callback is invoked or
not is known by the caller of pjsip_regc_send. Depending on
this it can know whether it is responsible for decrementing the
reference count of the client state or not.

ASTERISK-25037 #close
Reported by: Joshua Colp

Change-Id: I749dc12f3a22115c49c5d7d95ff42a5fa45319de
2015-04-30 07:25:26 -05:00
Matt Jordan 7fe923d20b Merge "ARI: Fix missing dependencies." 2015-04-29 16:44:09 -05:00
Kevin Harwell 5d0c182885 res_fax: allow 2400 transmission rate according to v.27ter standard
A previous set of patches (see: ASTERISK-22790 & ASTERISK-23231) made it so
a v.27 modem was not allowed to have a minimum transmission rate of 2400 bits
per second. This reverts all or some of those patches since according to the
v.27ter standard a rate of 2400 bits per second is also supported.

One of the original patches also added 9600 bits per second support for v.27.
This patch also removes that since v.27ter only supports 2400/4800 bits per
second.

Also, since Asterisk specifically supports v.27ter the enum was renamed to
better reflect this.

ASTERISK-24955 #close
Reported by: Matt Jordan

Change-Id: I4b9dfb6bf7eff08463ab47ee1a74224f27cae733
2015-04-29 15:39:11 -05:00
Joshua Colp 648b22f19d Merge "res_pjsip_outbound_registration: Don't fail on delayed processing." 2015-04-29 13:09:20 -05:00
Mark Michelson 03261b9614 Merge "Git Conversion: Switch Non-C files to ASTERISK_REGISTER_FILE." 2015-04-29 12:28:24 -05:00
Mark Michelson 4f1db2070d res_pjsip_outbound_registration: Don't fail on delayed processing.
Odd behaviors have been observed during outbound registrations. The most
common problem witnessed has been one where a request with
authentication credentials cannot be created after receiving a 401
response. Other behaviors include apparently processing an incorrect SIP
response.

Inspecting the code led to an apparent issue with regards to how we
handle transactions in outbound registration code. When a response to a
REGISTER arrives, we save a pointer to the transaction and then push a
task onto the registration serializer. Between the time that we save the
pointer and push the task, it's possible for the transaction to be
destroyed due to a timeout. It's also possible for the address to be
reused by the transaction layer for a new transaction.

To allow for authentication of a REGISTER request to be authenticated
after the transaction has timed out, we now hold a reference to the
original REGISTER request instead of the transaction. The function for
creating a request with authentication has been altered to take the
original request instead of the transaction where the original request
was sent.

ASTERISK-25020
Reported by Mark Michelson

Change-Id: I756c19ab05ada5d0503175db9676acf87c686d0a
2015-04-29 12:04:06 -05:00
Joshua Colp ed5715eb39 res_sorcery_config: Fix build issue due to syntax error.
Change-Id: Ic8322f04e37842848ad72cf2871bd0378f67c4ac
2015-04-29 10:48:14 -05:00
Matt Jordan 48d5971a82 Merge "chan_pjsip: Creating Channel Causes Asterisk to Crash When Duplicate AOR Sections Exist in pjsip.conf" 2015-04-29 10:13:03 -05:00
Corey Farrell f226bd6f60 ARI: Fix missing dependencies.
ARI modules that are generated by 'make ari-stubs' are all dependent on
res_ari_model.  Additionally some of the same modules depend on one or more
res_stasis_* modules.

ASTERISK-25027 #close
Reported by: Corey Farrell

Change-Id: I8e07fe7e81fedacb87232f2b6f8b5f47927b4153
2015-04-29 07:46:44 -04:00
Corey Farrell 881844297a res_pjsip: Remove incorrect MODULEINFO from presence_xml.c.
Remove incorrect MODULEINFO block and unneeded header includes
from presence_xml.c.

ASTERISK-25027
Reported by: Corey Farrell

Change-Id: I977c609ab9d1fe05373027c4138900f6985990eb
2015-04-29 07:46:03 -04:00
Corey Farrell 55a780d211 Git Conversion: Switch Non-C files to ASTERISK_REGISTER_FILE.
This switches files used to generate other sources to use the new
ASTERISK_REGISTER_FILE macro.

ASTERISK-25026 #close
Reported by: Corey Farrell

Change-Id: Ieb2537b83421cad07c8955e5f90c405ccf079740
2015-04-29 01:02:10 -04:00
Joshua Colp 2415e94b07 Merge "res_pjsip_outbound_registration: Add debugging messages." 2015-04-28 19:18:29 -05:00
Ashley Sanders 46cf643c75 chan_pjsip: Creating Channel Causes Asterisk to Crash When Duplicate AOR
Sections Exist in pjsip.conf

This patch modifies the current loading strategy of the pjsip configuration. If
duplicate sections (e.g. sections containing the same [id/type]) are defined in
[pjsip.conf], the loader will consider the configuration for the given type as
invalid when the duplicate section is encountered. The entire configuration
(including what was previously loaded) for the duplicate [id/type] sections
will be rejected and destroyed, an error message is logged and the load
processing for the given stops.

ASTERISK-24996
Reported By: Ashley Sanders

Change-Id: I35090ca4cd40f1f34881dfe701a329145c347aef
2015-04-28 14:01:54 -05:00
Mark Michelson f47fed2e12 res_pjsip_outbound_registration: Add debugging messages.
When problems occur regarding outbound registrations, it currently
is difficult to debug. Most off-nominal paths had warning messages,
but sometimes we want to know what's going on before hitting the
off-nominal path. This patch adds lots of debugging output that
should give a clearer picture of what is happening with regards
to outbound registrations.

ASTERISK-25020
Reported by Mark Michelson

Change-Id: I577bde7860be0a6c872b5bcb4d5047340bf45d45
2015-04-28 10:43:38 -05:00
Steve Davies 5e96584829 res_rtp_asterisk: Resolve 2 discrete memory leaks in DTLS
ao2 ref leak in res_rtp_asterisk.c when a DTLS policy is created.
The resources are linked into a table, but the original alloc refs
are never released. ast_strdup leak in rtp_engine.c. If
ast_rtp_dtls_cfg_copy() is called twice on the same destination struct,
a pointer to an alloc'd string is overwritten before the string is free'd.

ASTERISK-25022
Reported by: one47

Change-Id: I62a8ceb8679709f6c3769136dc6aa9a68202ff9b
2015-04-28 06:57:44 -05:00
Matt Jordan e43fa9868b Merge "Astobj2: Allow reference debugging to be enabled/disabled by config." 2015-04-28 06:42:30 -05:00
Corey Farrell 5c1d07baf0 Astobj2: Allow reference debugging to be enabled/disabled by config.
* The REF_DEBUG compiler flag no longer has any effect on code that uses
  Astobj2.  It is used to determine if reference debugging is enabled by
  default.  Reference debugging can be enabled or disabled in asterisk.conf.
* Caller information is provided in logger errors for ao2 bad magic numbers.
* Optimizes AO2 by merging internal functions with the public counterpart.
  This was possible now that we no longer require a dual ABI.

ASTERISK-24974 #close
Reported by: Corey Farrell

Change-Id: Icf3552721fe999365ba8a8cf00a965aa6b897cc1
2015-04-27 18:37:26 -04:00
George Joseph 356568dc7f res_pjsip: Fix SEGV on pending-qualify contacts
Permanent contacts that hadn't been qualified yet were missing
their contact_status entries causing SEGVs when running CLI
commands.

This patch makes sure that contact_statuses are created for
both dynamic and permanent contacts when they are created.
It also adds checks in the CLI code to make sure there's a
contact_status, just in case.

ASTERISK-25018 #close
Reported-by: Ivan Poddubny
Tested-by: Ivan Poddubny
Tested-by: George Joseph

Change-Id: I3cc13e5cedcafb24c400368b515b02d7fb81e029
2015-04-27 12:19:06 -05:00
Matt Jordan 0c92a85aee Merge "Clang: Fix some more tautological-compare warnings." 2015-04-26 15:53:58 -05:00
Matt Jordan 3646ce0cb5 Merge "res_pjsip_outbound_authenticator: Increase CSeq on authed requests." 2015-04-24 12:24:02 -05:00
Mark Michelson bd61c9300c res_pjsip_outbound_authenticator: Increase CSeq on authed requests.
The way PJSIP generates an authenticated request is to use a previous
request as a template. This means that the authenticated request will
have the same Call-ID, From header (including tag), and CSeq as the
original request. PJSIP generates a new branch on the Via header to
indicate that this is a new transaction, though.

There are some SIP implementations, though, that do not notice the
change in the branch and therefore will match the authed request to the
original request's transaction. Since the CSeq is the same, the server
will repeat the response it sent to the original request.

This patch aids interoperability by increasing the CSeq of the authed
request by one.

ASTERISK-24845 #close
Reported by: Carl Fortin
Tested by: Carl Fortin

Change-Id: I39c4ca52e688a9f83bcc1878371334becdc5be01
2015-04-24 10:23:33 -05:00
Diederik de Groot f8e21a1adf Clang: Fix some more tautological-compare warnings.
clang can warn about a so called tautological-compare, when it finds
comparisons which are logically always true, and are therefor deemed
unnecessary.

Exanple:
unsigned int x = 4;
if (x > 0)    // x is always going to be bigger than 0

Enum Case:
Each enumeration is its own type. Enums are an integer type but they
do not have to be *signed*. C leaves it up to the compiler as an
implementation option what to consider the integer type of a particu-
lar enumeration is. Gcc treats an enum without negative values as
an int while clang treats this enum as an unsigned int.

rmudgett & mmichelson: cast the enum to (unsigned int) in assert.
The cast does have an effect. For gcc, which seems to treat all enums
as int, the cast to unsigned int will eliminate the possibility of
negative values being allowed. For clang, which seems to treat enums
without any negative members as unsigned int, the cast will have no
effect. If for some reason in the future a negative value is ever
added to the enum the assert will still catch the negative value.

ASTERISK-24917
Change-Id: Ief23ef68916192b9b72dabe702b543ecfeca0b62
2015-04-24 09:48:44 -05:00
Matt Jordan 61c8ae548a Merge "res_pjsip_t38: Don't crash on authenticated reinvite after originated T.38 FAX." 2015-04-24 09:24:54 -05:00
Mark Michelson 1a8355622d Merge "Clang: change previous tautological-compare fixes." 2015-04-23 17:23:50 -05:00
Mark Michelson 89a3fc0572 res_pjsip_t38: Don't crash on authenticated reinvite after originated T.38 FAX.
When Asterisk originates a channel to an application, the channel is
hung up once the application finishes executing. When the application
in question is SendFax, the Asterisk PJSIP code will attempt to reinvite
the T.38 session to audio after the FAX completes. The hangup of the
channel happens in the midst of this reinvite transaction. In most
circumstances, this works out okay because the BYE is delayed until the
reinvite transaction can complete.

However, if the reinvite that Asterisk sends receives a 401/407
response, then Asterisk's attempt to re-send the reinvite with
authentication will fail. This is because the session supplement in
res_pjsip_t38 makes the assumption that the channel on the session will
always be non-NULL. Since the channel has been hung up, though, the
channel is now NULL. Attempting to operate on the channel causes a
crash.

This patch fixes the issue by ensuring that the channel on the session
is not NULL before attempting to mess with the T.38 framehook.

This patch also contains some corrections for comments that were
incorrect and really confused me when I first started looking at the
code.

ASTERISK-25004 #close
Reported by Mark Michelson

Change-Id: Ic5a1230668369dda4bb13524098aed9306ab45a0
2015-04-23 13:09:49 -05:00
George Joseph 75666ad7c6 res_pjsip: Validate that contact uris start with sip: or sips:
Currently we use pjsip_parse_hdr to validate contact uris but it
appears that it allows uris without a scheme if there's a port
supplied.  I.E myexample.com will fail but myexample.com:5060 will
pass even though it has no scheme.  This causes SEGVs later on
whenever the uri is used.

To prevent this, permanent_contact_validate has been updated to check
that the scheme is either 'sip' or 'sips'.

2 uses of possibly-null endpoint have also been fixed in
create_out_of_dialog_request.

ASTERISK-24999

Change-Id: Ifc17d16a4923e1045d37fe51e43bbe29fa556ca2
Reported-by: Brad Latus
2015-04-23 11:54:59 -05:00
Diederik de Groot ca7193167e Clang: change previous tautological-compare fixes.
clang can warn about a so called tautological-compare, when it finds
comparisons which are logically always true, and are therefor deemed
unnecessary.

Exanple:
unsigned int x = 4;
if (x > 0)    // x is always going to be bigger than 0

Enum Case:
Each enumeration is its own type. Enums are an integer type but they
do not have to be *signed*. C leaves it up to the compiler as an
implementation option what to consider the integer type of a particu-
lar enumeration is. Gcc treats an enum without negative values as
an int while clang treats this enum as an unsigned int.

rmudgett & mmichelson: cast the enum to (unsigned int) in assert.
The cast does have an effect. For gcc, which seems to treat all enums
as int, the cast to unsigned int will eliminate the possibility of
negative values being allowed. For clang, which seems to treat enums
without any negative members as unsigned int, the cast will have no
effect. If for some reason in the future a negative value is ever
added to the enum the assert will still catch the negative value.

ASTERISK-24917

Change-Id: I0557ae0154a0b7de68883848a609309cdf0aee6a
2015-04-23 11:39:13 -05:00
George Joseph cc77440deb res_corosync: Add check for config file before calling corosync apis
On some systems, res_corosync isn't compatible with the installed version of
corosync so corosync_cfg_initialize fails, load_module returns LOAD_FAILURE,
and Asterisk terminates.  The work around has been to remember to add
res_corosync as a noload in modules.conf.  A better solution though is to have
res_corosync check for its config file before attempting to call corosync apis
and return LOAD_DECLINE if there's no config file.  This lets Asterisk loading
continue.

If you have a res_corosync.conf file and res_corosync fails, you get the same
behavior as today and the fatal error tells you something is wrong with the
install.

ASTERISK-24998

Change-Id: Iaf94a9431a4922ec4ec994003f02135acfdd3889
2015-04-23 06:30:29 -05:00
Joshua Colp 190fa4f333 res_pjsip_mwi: Send unsolicited MWI NOTIFY on startup and when endpoint registers.
Currently the res_pjsip_mwi module only sends an unsolicited MWI NOTIFY upon
a mailbox state change (such as a new message being left, or one being deleted).
In practice this is not sufficient to keep clients aware of the current MWI status.

This change makes the module send unsolicited MWI NOTIFY on startup so that
clients are guaranteed to have the most up to date MWI information. It also makes
clients receive an unsolicited MWI NOTIFY upon registration so if they are unaware
of the current MWI status they receive it.

ASTERISK-24982 #close
Reported by: Joshua Colp

Change-Id: I043f20230227e91218f18a82c7d5bb2aa62b1d58
2015-04-22 05:41:46 -05:00
Joshua Colp bfdc766bf6 Merge "res_pjsip_pubsub: Set the endpoint on SUBSCRIBE dialogs." 2015-04-22 05:29:18 -05:00
Mark Michelson 6331be0638 res_pjsip_pubsub: Set the endpoint on SUBSCRIBE dialogs.
When SUBSCRIBE dialogs were established, we never associated
the endpoint that created the subscription with the dialog
we end up creating. In most cases, this ended up not causing
any problems.

The actual bug that was observed was that when a device that
was behind NAT established a subscription with Asterisk, Asterisk
would end up sending in-dialog NOTIFY requests to the device's
private IP addres instead of the public address of the NAT router.

When Asterisk receives the initial SUBSCRIBE from the device,
res_pjsip_nat rewrites the contact to the public address on which the
SUBSCRIBE was received. This allows for the dialog to have its target
address set to the proper public address. Asterisk then would send a 200
OK response to the SUBSCRIBE, then a NOTIFY with the initial
subscription state. The device would then send a 200 OK response to
Asterisk's NOTIFY.

Here's where things went wrong. When the 200 OK arrived, res_pjsip_nat
did not rewrite the address in the Contact header. Then, when the PJSIP
dialog layer processed the 200 OK, PJSIP would perform a comparison
between the IP address in the Contact header and its saved target
address for the dialog. Since they differed, PJSIP would update the
target dialog address to be the address in the Contact header. From this
point, if Asterisk needed to send a NOTIFY to the device, the result was
that the NOTIFY would be sent to the private address that the device
placed in the Contact header.

The reason why res_pjsip_nat did not rewrite the address when it
received the 200 OK response was that it could not associate the
incoming response with a configured endpoint. This is because on a
response, the only way to associate the response to an endpoint is by
finding the dialog that the response is associated with and then finding
the endpoint that is associated with that dialog. We do not perform
endpoint lookups on responses. res_pjsip_pubsub skipped the step of
associating the endpoint with the dialog we created, so res_pjsip_nat
could not find the associated endpoint and therefore couldn't rewrite
the contact.

This commit message is like 50x longer than the actual fix.

ASTERISK 24981 #close
Reported by Mark Michelson

Change-Id: I2b963c58c063bae293e038406f7d044a8a5377cd
2015-04-21 05:01:58 -05:00
Joshua Colp b1deedf0dc Merge "pjsip_options: Fix non-qualified contacts showing as unavailable" 2015-04-20 17:24:04 -05:00
George Joseph 06ba1e59cb pjsip_options: Fix format specifier for int64_t rtt.
Contact status rtt is an int64_t and needs the PRId64 macro to
properly create the format specifier on 32-bit systems.

Change-Id: I4b8ab958fc1e9a179556a9b4ffa49673ba9fdec7
2015-04-20 09:57:26 -05:00
George Joseph 298faf7c50 pjsip_options: Fix non-qualified contacts showing as unavailable
The "Add qualify_timeout processing and eventing" patch introduced
an issue where contacts that had qualify_frequency set to 0 were
showing Unavailable instead Unknown.  This patch checks for
qualify_frequency=0 and create an "Unknown"  contact_status
with an RTT = 0.

Previously, the lack of contact_status implied Unknown but since
we're now changing endpoint state based on contact_status, I've
had to add new UNKNOWN status so that changes could trigger the
appropriate contact_status observers.

ASTERISK-24977: #close

Change-Id: Ifcbc01533ce57f0e4e584b89a395326e098b8fe7
2015-04-19 20:07:45 -05:00
Richard Mudgett 1269dd06bc res_fax: Fix latent bug exposed by ASTERISK-24841 changes.
Three fax related tests started failing as a result of changes made for
ASTERISK-24841:
tests/fax/pjsip/gateway_t38_g711
tests/fax/sip/gateway_mix1
tests/fax/sip/gateway_mix3

Historically, ast_channel_make_compatible() did nothing if the channels
were already "compatible" even if they had a sub-optimal translation path
already setup.  With the changes from ASTERISK-24841 this is no longer
true in order to allow the best translation paths to always be picked.  In
res_fax.c:fax_gateway_framehook() code manually setup the channels to go
through slin and then called ast_channel_make_compatible().  With the
previous version of ast_channel_make_compatible() this was always a
no-operation.

* Remove call to ast_channel_make_compatible() in fax_gateway_framehook()
that now undoes what was just setup when the framehook is attached.

* Fixed locking around saving the channel formats in
fax_gateway_framehook() to ensure that the formats that are saved are
consistent.

* Fix copy pasta errors in fax_gateway_framehook() that confuses read and
write when dealing with saved channel formats.

ASTERISK-24841
Reported by: Matt Jordan

Change-Id: I6fda0877104a370af586a5e8cf9e161a484da78d
2015-04-17 18:46:25 -05:00
Matt Jordan 8435a0cdff Merge "Detect potential forwarding loops based on count." 2015-04-17 15:58:13 -05:00
Mark Michelson aae45acbda Detect potential forwarding loops based on count.
A potential problem that can arise is the following:

* Bob's phone is programmed to automatically forward to Carol.
* Carol's phone is programmed to automatically forward to Bob.
* Alice calls Bob.

If left unchecked, this results in an endless loops of call forwards
that would eventually result in some sort of fiery crash.

Asterisk's method of solving this issue was to track which interfaces
had been dialed. If a destination were dialed a second time, then
the attempt to call that destination would fail since a loop was
detected.

The problem with this method is that call forwarding has evolved. Some
SIP phones allow for a user to manually forward an incoming call to an
ad-hoc destination. This can mean that:

* There are legitimate use cases where a device may be dialed multiple
times, or
* There can be human error when forwarding calls.

This change removes the old method of detecting forwarding loops in
favor of keeping a count of the number of destinations a channel has
dialed on a particular branch of a call. If the number exceeds the
set number of max forwards, then the call fails. This approach has
the following advantages over the old:

* It is much simpler.
* It can detect loops involving local channels.
* It is user configurable.

The only disadvantage it has is that in the case where there is a
legitimate forwarding loop present, it takes longer to detect it.
However, the forwarding loop is still properly detected and the
call is cleaned up as it should be.

Address review feedback on gerrit.

* Correct "mfgium" to "Digium"
* Decrement max forwards by one in the case where allocation of the
  max forwards datastore is required.
* Remove irrelevant code change from pjsip_global_headers.c

ASTERISK-24958 #close

Change-Id: Ia7e4b7cd3bccfbd34d9a859838356931bba56c23
2015-04-17 15:58:07 -05:00
Matt Jordan bb347fa594 Merge topic 'ASTERISK-24863'
* changes:
  res_pjsip: Add global option to limit the maximum time for initial qualifies
  pjsip_options: Add qualify_timeout processing and eventing
  res_pjsip: Refactor endpt_send_request to include transaction timeout
2015-04-17 15:33:29 -05:00
George Joseph c6ed681638 res_pjsip: Add global option to limit the maximum time for initial qualifies
Currently when Asterisk starts initial qualifies of contacts are spread out
randomly between 0 and qualify_timeout to prevent network and system overload.
If a contact's qualify_frequency is 5 minutes however, that contact may be
unavailable to accept calls for the entire 5 minutes after startup.  So while
staggering the initial qualifies is a good idea, basing the time on
qualify_timeout could leave contacts unavailable for too long.

This patch adds a new global parameter "max_initial_qualify_time" that sets the
maximum time for the initial qualifies.  This way you could make sure that all
your contacts are initialy, randomly qualified within say 30 seconds but still
have the contact's ongoing qualifies at a 5 minute interval.

If max_initial_qualify_time is > 0, the formula is initial_interval =
min(max_initial_interval, qualify_timeout * random().  If not set,
qualify_timeout is used.

The default is "0" (disabled).

ASTERISK-24863 #close

Change-Id: Ib80498aa1ea9923277bef51d6a9015c9c79740f4
Tested-by: George Joseph <george.joseph@fairview5.com>
2015-04-16 16:44:45 -05:00
Scott Griepentrog 664d3263e4 res_pjsip_pubsub: On notify fail deleted sub_tree is then referenced
This change makes the send_notify of the sub_tree
not happen when the sub_tree has been deleted due
to the notify call failing, which avoids a crash.

ASTERISK-24970 #close

Change-Id: I1f20ffc08b192f59c457293b218025a693992cbf
2015-04-16 13:52:10 -05:00
George Joseph 51886c68dc pjsip_options: Add qualify_timeout processing and eventing
This is the second follow-on to https://reviewboard.asterisk.org/r/4572/ and the
discussion at
http://lists.digium.com/pipermail/asterisk-dev/2015-March/073921.html

The basic issues are that changes in contact status don't cause events to be
emitted for the associated endpoint.  Only dynamic contact add/delete actions
update the endpoint.  Also, the qualify timeout is fixed by pjsip at 32 seconds
which is a long time.

This patch makes use of the new transaction timeout feature in r4585 and
provides the following capabilities...

1.  A new aor/contact variable 'qualify_timeout' has been added that allows the
user to specify the maximum time in milliseconds to wait for a response to an
OPTIONS message.  The default is 3000ms.  When the timer expires, the contact is
marked unavailable.

2.  Contact status changes are now propagated up to the endpoint as follows...
When any contact is 'Available', the endpoint is marked as 'Reachable'.  When
all contacts are 'Unavailable', the endpoint is marked as 'Unreachable'.  The
existing endpoint events are generated appropriately.

ASTERISK-24863 #close

Change-Id: Id0ce0528e58014da1324856ea537e7765466044a
Tested-by: Dmitriy Serov
Tested-by: George Joseph <george.joseph@fairview5.com>
2015-04-16 09:34:56 -05:00
George Joseph ab6382cafd res_pjsip: Refactor endpt_send_request to include transaction timeout
This is the first follow-on to https://reviewboard.asterisk.org/r/4572/ and the
discussion at
http://lists.digium.com/pipermail/asterisk-dev/2015-March/073921.html

Since we currently have no control over pjproject transaction timeout, this
patch pulls the pjsip_endpt_send_request function out of pjproject and into
res_pjsip/endpt_send_transaction in order to implement that capability.

Now when the transaction is initiated, we also schedule our own pj_timer with
our own desired timeout.

If the transaction completes before either timeout, pjproject cancels its timer,
and calls our tsx callback where we cancel our timer and run the app callback.

If the pjproject timer times out first, pjproject calls our tsx callback where
we cancel our timer and run the app callback.

If our timer times out first, we terminate the transaction which causes
pjproject to cancel its timer and call our tsx callback where we run the app
callback.

Regardless of the scenario, pjproject is calling the tsx callback inside the
group_lock and there are checks in the callback to make sure it doesn't run
twice.

As part of this patch ast_sip_send_out_of_dialog_request was created to replace
its similarly named private function.  It takes a new timeout argument in
milliseconds (<= 0 to disable the timeout).

ASTERISK-24863 #close
Reported-by: George Joseph <george.joseph@fairview5.com>
Tested-by: George Joseph <george.joseph@fairview5.com>

Change-Id: I0778dc730d9689c5147a444a04aee3c1026bf747
2015-04-16 06:44:56 -05:00
Joshua Colp a3cec44a0a res_pjsip: Add external PJSIP resolver implementation using core DNS API.
This change adds the following:

1. A query set implementation. This is an API that allows queries to be executed in parallel and once all have completed a callback is invoked.
2. Unit tests for the query set implementation.
3. An external PJSIP resolver which uses the DNS core API to do NAPTR, SRV, AAAA, and A lookups.

For the resolver it will do NAPTR, SRV, and AAAA/A lookups in parallel. If NAPTR or SRV
are available it will then do more queries. And so on. Preference is NAPTR > SRV > AAAA/A,
with IPv6 preferred over IPv4. For transport it will prefer TLS > TCP > UDP if no explicit
transport has been provided. Configured transports on the system are taken into account to
eliminate resolved addresses which have no hope of completing.

ASTERISK-24947 #close
Reported by: Joshua Colp

Change-Id: I56cb03ce4f9d3d600776f36928e0b3e379b5d71e
2015-04-15 10:47:53 -03:00
Corey Farrell 62508d6891 Build System: Create Makefile macro MOD_ADD_SOURCE.
This new macro allows a single line to add all additional
sources to a module.  This helps prevent modules from
missing steps, and makes future changes easier since
they can be made in a single place.

ASTERISK-24960 #close
Reported by: Corey Farrell

Change-Id: I38f12d8b72c5e7bb37a879b2fb51761a2855eb4b
2015-04-14 12:53:03 -04:00
Matt Jordan 4a58261694 git migration: Refactor the ASTERISK_FILE_VERSION macro
Git does not support the ability to replace a token with a version
string during check-in. While it does have support for replacing a
token on clone, this is somewhat sub-optimal: the token is replaced
with the object hash, which is not particularly easy for human
consumption. What's more, in practice, the source file version was often
not terribly useful. Generally, when triaging bugs, the overall version
of Asterisk is far more useful than an individual SVN version of a file. As a
result, this patch removes Asterisk's support for showing source file
versions.

Specifically, it does the following:

* Rename ASTERISK_FILE_VERSION macro to ASTERISK_REGISTER_FILE, and
  remove passing the version in with the macro. Other facilities
  than 'core show file version' make use of the file names, such as
  setting a debug level only on a specific file. As such, the act of
  registering source files with the Asterisk core still has use. The
  macro rename now reflects the new macro purpose.

* main/asterisk:
  - Refactor the file_version structure to reflect that it no longer
    tracks a version field.
  - Remove the "core show file version" CLI command. Without the file
    version, it is no longer useful.
  - Remove the ast_file_version_find function. The file version is no
    longer tracked.
  - Rename ast_register_file_version/ast_unregister_file_version to
    ast_register_file/ast_unregister_file, respectively.

* main/manager: Remove value from the Version key of the ModuleCheck
  Action. The actual key itself has not been removed, as doing so would
  absolutely constitute a backwards incompatible change. However, since
  the file version is no longer tracked, there is no need to attempt to
  include it in the Version key.

* UPGRADE: Add notes for:
  - Modification to the ModuleCheck AMI Action
  - Removal of the "core show file version" CLI command

Change-Id: I6cf0ff280e1668bf4957dc21f32a5ff43444a40e
2015-04-13 03:48:57 -04:00
George Joseph b35e184d41 Add .gitignore and .gitreview files
Add the .gitignore and .gitreview files to the asterisk repo.

NB:  You can add local ignores to the .git/info/exclude file
without having to do a commit.

Common ignore patterns are in the top-level .gitignore file.
Subdirectory-specific ignore patterns are in their own .gitignore
files.

Change-Id: I842a1588ff27d8a0189f12d597f0a7af033d6c69
Tested-by: George Joseph
2015-04-11 19:43:43 -06:00
Matthew Jordan 5f181bcccd res/res_pjsip_t38: Add missing initialization of t38faxmaxdatagram
Prior to this patch, the far_max_datagram value on the UDPTL structure would
remain -1 if the remote endpoint fails to provide the SDP media attribute
T38FaxMaxDatagram. This can result in the INVITE request being rejected. With
this patch, we will now properly initialize the value with either the default
value or with the value provided by pjsip.conf's t38_udptl_maxdatagram
parameter.

Review: https://reviewboard.asterisk.org/r/4589

ASTERISK-24928 #close
Reported by: Juergen Spies
Tested by: Juergen Spies
patches:
  pjsipT38patch20150331.txt submitted by Juergen Spies (License 6698)
........

Merged revisions 434688 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434689 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-11 15:11:15 +00:00
Richard Mudgett c499cabf53 chan_pjsip/res_pjsip/bridge_softmix/core: Improve translation path choices.
With this patch, chan_pjsip/res_pjsip now sets the native formats to the
codecs negotiated by a call.

* The changes in chan_pjsip.c and res_pjsip_sdp_rtp.c set the native
formats to include all the negotiated audio codecs instead of only the
initial preferred audio codec and later the currently received audio
codec.

* The audio frame handling in channel.c:ast_read() is more streamlined and
will automatically adjust to changes in received frame formats.  The new
policy is to remove translation and pass the new frame format to the
receiver except if the translation was to a signed linear format.  A more
long winded version is commented in ast_read() along with some caveats.

* The audio frame handling in channel.c:ast_write() is more streamlined
and will automatically adjust any needed translation to changes in the
frame formats sent.  Frame formats sent can change for many reasons such
as a recording is being played back or the bridged peer changed the format
it sends.  Since it is a normal expectation that sent formats can change,
the codec mismatch warning message is demoted to a debug message.

* Removed the short circuit check in
channel.c:ast_channel_make_compatible_helper().  Two party bridges need to
make channels compatible with each other.  However, transfers and moving
channels among bridges can result in otherwise compatible channels having
sub-optimal translation paths if the make compatible check is short
circuited.  A result of forcing the reevaluation of channel compatibility
is that the asterisk.conf:transcode_via_slin and codecs.conf:genericplc
options take effect consistently now.  It is unfortunate that these two
options are enabled by default and negate some of the benefits to the
changes in channel.c:ast_read() by forcing translation through signed
linear on a two party bridge.

* Improved the softmix bridge technology to better control the translation
of frames to the bridge.  All of the incoming translation is now normally
handled by ast_read() instead of splitting any translation steps between
ast_read() and the slin factory.  If any frame comes in with an unexpected
format then the translation path in ast_read() is updated for the next
frame and the slin factory handles the current frame translation.

This is the final patch in a series of patches aimed at improving
translation path choices.  The other patches are on the following reviews:
https://reviewboard.asterisk.org/r/4600/
https://reviewboard.asterisk.org/r/4605/

ASTERISK-24841 #close
Reported by: Matt Jordan

Review: https://reviewboard.asterisk.org/r/4609/
........

Merged revisions 434671 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434672 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-10 23:37:20 +00:00
Matthew Jordan 8bae18ab93 res_pjsip: Add an 'auto' option for DTMF Mode
This patch adds support for automatically detecting the type of DTMF that a
PJSIP endpoint supports. When the 'dtmf_mode' endpoint option is set to 'auto',
the channel created for an endpoint will attempt to determine if RFC 4733
DTMF is supported. If so, it will use that DTMF type. If not, the DTMF type
for the channel will be set to inband.

Review: https://reviewboard.asterisk.org/r/4438

ASTERISK-24706 #close
Reported by: yaron nahum
patches:
  yaron_patch_3_Feb.diff submitted by yaron nahum (License 6676)
........

Merged revisions 434637 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434638 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-10 17:56:47 +00:00
George Joseph f69e46de25 res_pjsip_config_wizard: Cleanup load unload
While investigating other unload issues I realized that the load/unload process 
for the config wizard was pretty ugly so I've refactored it as follows...

When the res_pjsip sorcery instance is created the config_wizard bumps it's own 
module reference to prevent it from unloading while the sorcery instance is 
still active.  When res_pjsip unloads and it's sorcery instance is destroyed, 
the config wizard unrefs itself which then allows itself to unload cleanly.  
Since the config wizard now can't load after res_pjsip or unload before it 
(which should have been the correct behavior all along), I was able to remove 
the chunks of code in both load_module and unload_module that handled that case.

Ran the testsuite tests to insure there were no functional changes and REF_DEBUG 
to insure that Asterisk was shutting down cleanly with no FRACKs or leaks.

Tested-by: George Joseph
Review: https://reviewboard.asterisk.org/r/4610/
........

Merged revisions 434619 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434620 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-10 17:00:38 +00:00
Matthew Jordan 894153b8b1 res/ari: Fix model validation for ChannelHold event
When the ChannelHold event was added, the 'musicclass' parameter was
erroneously removed. This caused the ChannelHold events to be rejected as
they failed model validation. This patch updates the Swagger schema such that
it now properly reflects the event that is being created.

Hooray for tests that catch things like this.
........

Merged revisions 434597 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434598 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-10 14:56:05 +00:00
George Joseph ed6b6e3c03 res_pjsip_phoneprov_provider: Fix reference leak on unload
res_pjsip_phoneprov_provider was leaking references to phoneprov objects due to 
a missing OBJ_NODATA in an ao2_callback in load_users().  Rather than adding the 
OBJ_NODATA, I changed load_users to use a more straightforward ao2_iterator.  
This plugged the leak but exposed an unload order issue between 
res_pjsip_phoneprov_provider, res_phoneprov and res_pjsip.

res_pjsip_phoneprov_provider unloads first, then res_phoneprov, then res_pjsip.  
Since res_pjsip_phoneprov_provider uses res_pjsip's sorcery instance, when it 
unloads, it's objects are still in the sorcery instance.  When res_pjsip 
unloads, it destroys all its objects including res_pjsip_phoneprov_provider's.  
The phoneprov destructor then attempts to unregister the extension from 
res_phoneprov but because res_phoneprov is already cleaned up, its users 
container is gone and we get a FRACK.

Simple solution, check for the NULL users container before attempting to remove 
the entry. Duh.

Ran tests/res_phoneprov/res_phoneprov_provider.  No leaks in 
res_pjsip_phoneprov_provider and no FRACKs.

Reported-by: Corey Farrell
Tested-by: George Joseph
Review: https://reviewboard.asterisk.org/r/4608/
ASTERISK-24935 #close
........

Merged revisions 434545 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434547 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-09 23:12:13 +00:00
Kevin Harwell 520b9f2174 res_pjsip: add CLI command to show global and system configuration
Added a new CLI command for res_pjsip that shows both global and system
configuration settings: pjsip show settings

ASTERISK-24918 #close
Reported by: Scott Griepentrog
Review: https://reviewboard.asterisk.org/r/4597/
........

Merged revisions 434527 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434528 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-09 22:07:50 +00:00
Matthew Jordan 3ef0a17b1f res/res_pjsip_dlg_options: Add a module to handle in-dialog OPTIONS requests
This patch adds a new session supplement that handles in-dialog OPTIONS
requests. Said OPTIONS requests are sent a 200 OK, as an endpoint lookup
for the OPTIONS request would already have been done by the time the
session supplement receives the inbound request.

ASTERISK-24862 #close
Reported by: yaron nahum
patches:
  res_pjsip_dlg_options.c submitted by yaron nahum (License 6676)
........

Merged revisions 434506 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434507 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-09 15:43:20 +00:00
Matthew Jordan ea0098724e clang compiler warnings: Fix autological comparisons
This fixes autological comparison warnings in the following:
 * chan_skinny: letohl may return a signed or unsigned value, depending on the
   macro chosen
 * func_curl: Provide a specific cast to CURLoption to prevent mismatch
 * cel: Fix enum comparisons where the enum can never be negative
 * enum: Fix comparison of return result of dn_expand, which returns a signed
   int value
 * event: Fix enum comparisons where the enum can never be negative
 * indications: tone_data.freq1 and freq2 are unsigned, and hence can never be
   negative
 * presencestate: Use the actual enum value for INVALID state
 * security_events: Fix enum comparisons where the enum can never be negative
 * udptl: Don't bother to check if the return value from encode_length is less
   than 0, as it returns an unsigned int
 * translate: Since the parameters are unsigned int, don't bother checking
   to see if they are negative. The cast to unsigned int would already blow
   past the matrix bounds.
 * res_pjsip_exten_state: Use a temporary value to cache the return of
   ast_hint_presence_state
 * res_stasis_playback: Fix enum comparisons where the enum can never be
   negative
 * res_stasis_recording: Add an enum value for the case where the recording
   operation is in error; fix enum comparisons
 * resource_bridges: Use enum value as opposed to -1
 * resource_channels: Use enum value as opposed to -1

Review: https://reviewboard.asterisk.org/r/4533
ASTERISK-24917
Reported by: dkdegroot
patches:
  rb4533.patch submitted by dkdegroot (License 6600)
........

Merged revisions 434469 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 434470 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434471 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-09 12:57:21 +00:00
Jonathan Rose a759714101 res_pjsip_t38: Fix FAX failures when using PJSIP with authentication
Without this patch, if a PJSIP endpoint with udptl enabled and authentication
set attempted to use sendFax, the FAX session would fail during setup. This
was because the invite issued in response to being auth challenged would cause
the PJSIP channel performing the FAX to receive a second T38 framehook and
this would cause frames to be consumed in an inappropriate manner.

ASTERISK-24933 #close
Reported by: Jonathan Rose
Review: https://reviewboard.asterisk.org/r/4577/
........

Merged revisions 434425 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434431 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-08 18:32:31 +00:00
Matthew Jordan b8fa8aa775 clang compiler warnings: Fix pointer-bool-converesion warnings
This patch fixes several warnings pointed out by the clang compiler.
* chan_pjsip: Removed check for data->text, as it will always be non-NULL.
* app_minivm: Fixed evaluation of etemplate->locale, which will always
  evaluate to 'true'. This patch changes the evaluation to use
  ast_strlen_zero.
* app_queue:
  - Fixed evaluation of qe->parent->monfmt, which always evaluates to
    true. Instead, we just check to see if the dereferenced pointer
    evaluates to true.
  - Fixed evaluation of mem->state_interface, wrapping it with a call to
    ast_strlen_zero.
* res_smdi: Wrapped search_msg->mesg_desk_term with calls to ast_strlen_zero.

Review: https://reviewboard.asterisk.org/r/4541

ASTERISK-24917
Reported by: dkdegroot
patches:
  rb4541.patch submitted by dkdegroot (License 6600)
........

Merged revisions 434285 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 434286 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434287 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-08 11:45:05 +00:00
Mark Michelson 1eba6abae5 Do not queue message requests that we do not respond to.
If we receive a MESSAGE request that we cannot send a response
to, we should not send the incoming MESSAGE to the dialplan.

This commit should help the bouncing message_retrans test to
pass consistently.
........

Merged revisions 434218 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434219 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-07 15:34:53 +00:00
Matthew Jordan c2f50ba6f4 ARI: Add the ability to intercept hold and raise an event
For some applications - such as SLA - a phone pressing hold should not behave
in the fashion that the Asterisk core would like it to. Instead, the hold
action has some application specific behaviour associated with it - such as
disconnecting the channel that initiated the hold; only playing MoH to channels
in the bridge if the channels are of a particular type, etc.

One way of accomplishing this is to use a framehook to intercept the
hold/unhold frames, raise an event, and eat the frame. Tasty. This patch
accomplishes that using a new dialplan function, HOLD_INTERCEPT.

In addition, some general cleanup of raising hold/unhold Stasis messages was
done, including removing some RAII_VAR usage.

Review: https://reviewboard.asterisk.org/r/4549/

ASTERISK-24922 #close
........

Merged revisions 434216 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434217 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-07 15:22:42 +00:00
Matthew Jordan c1cfe3fae2 clang compiler warnings: Fix non-literal-null-conversion warnings
Clang will flag errors when a char pointer is set to '\0', as opposed to a
value that the char pointer points to. This patch fixes this warning
in a variety of locations.

Review: https://reviewboard.asterisk.org/r/4551

ASTERISK-24917
Reported by: dkdegroot
patches:
  rb4551.patch submitted by dkdegroot (License 6600)
........

Merged revisions 434187 from http://svn.asterisk.org/svn/asterisk/branches/11
........

Merged revisions 434188 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434189 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-07 02:03:48 +00:00
Kevin Harwell 87d7c90e4e res_pjsip: config option 'timers' can't be set to 'no'
When setting the configuration option 'timers' equal to 'no' the bit flag was
not properly negated. This patch clears all associated flags and only sets the
specified one. pjsip will handle any necessary flag combinations. Also went
ahead and did similar for the '100rel' option.

ASTERISK-24910 #close
Reported by: Ray Crumrine
Review: https://reviewboard.asterisk.org/r/4582/
........

Merged revisions 434131 from http://svn.asterisk.org/svn/asterisk/branches/13


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434132 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-04-06 19:23:57 +00:00