Commit Graph

26736 Commits

Author SHA1 Message Date
Matt Jordan bb00b26f35 chan_pjsip: Set the context and extension on the channel when created
Prior to this patch, chan_pjsip was failing to pass the endpoint's
context and the desired extension to the ast_channel_alloc_* routine.
This caused a new channel snapshot to be issued without a context and
extension, which can cause some reporting issues for users of AMI, CEL,
and other APIs. The channel driver would later set the context and
extension on the channel such that the channel would start in the
correct location in the dialplan, but the information reported in the
initial event would be incorrect.

This patch modifies the channel driver such that it now passes the
context and extension directly into the allocation routine. This
provides the information in the new channel snapshot published over
Stasis.

ASTERISK-25156 #close
Reported by: cloos

Change-Id: Ic6f8542836e596db8f662071d118e8f934fdf25e
2015-06-11 19:07:22 -05:00
Matt Jordan a6446332fc Merge "install_prereq: Check if is installed aptitude otherwise to install." 2015-06-11 18:44:20 -05:00
Joshua Colp 7230ee2efe bridge: When performing a blonde transfer update connected line information.
When performing a blonde transfer the code uses the old masquerade
mechanism to move a channel around. As a result of this certain information,
such as connected line, is moved between the channels involved. Upon
completion of the move a frame is queued which is supposed to update the
connected line information on the channel. This does not occur as the
code considers it a redundant update since the masquerade operation
updated the channel (but did not inform it of the new connected line
information). The code also does not queue a connected line update
to be handled by the thread handling the channel. Without this any
other channel that may be loosely involved does not know it is
talking to a different caller.

This change does the following to resolve this:

1. The indicated connected line information is cleared upon
completion of the masquerade operation when doing a blonde transfer.
This prevents the connected line update from being considered
redundant.

2. A connected line update frame is now queued upon the completion
of the masquerade operation so any other channel loosely involved
knows that there is a different caller.

ASTERISK-25157 #close
Reported by: Joshua Colp

Change-Id: Ibb8798184a1dab3ecd35299faecc420034adbf20
2015-06-11 17:04:04 -05:00
Richard Mudgett a657ab12f9 app_directory: Fix crash when using the alias option 'a'.
The voicemail.conf mailbox key/value pair is defined as:
<mailbox>=[<password>[,<full-name>[,<email>[,<pager>[,<options>]]]]]
Where all fields in the value including the field values are optional.

Since the parsing code for the mailbox key/value pair is sloppy, this
patch tightens the parsing for the directory information.

* Renamed the 'pos' and 'bufptr' variables to 'name' and 'options'
respectively in search_directory_sub().  Those names make more sense.

* Made sure that search_directory_sub() is dealing with the voicemail.conf
mailbox options field if it even exists when looking for the 'hidefromdir'
and 'alias' options.

* Fix crash if a voicemail.conf mailbox is just
<mailbox>=<password>,<name> when the 'a' option is used.  If there were no
fields after the name then the 'options' pointer was not checked for NULL.

* Fix users.conf alias processing if the 'a' option is used.  The wrong
variable was used.

ASTERISK-25087 #close
Reported by: Chet Stevens

Change-Id: I86052ea77307beddddba5279824d39dc0d593374
2015-06-11 14:59:25 -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
Richard Mudgett 6d49dccd85 DNS: Fix doxygen comments.
Change-Id: Icafea3fb4ea64ac027561b23cbfe2b17997dc549
2015-06-10 12:17:02 -05:00
Richard Mudgett b705c09dbb res_pjsip.h: Fix some doxygen comments.
Change-Id: I4615771077c3c6a0a7273da6d7b5f77af7e8d976
2015-06-10 12:17:02 -05:00
Richard Mudgett aa8479778e taskprocessor.c: Remove extra unref from off-nominal path.
Change-Id: Iee3bd8c8a528776056972066698fe735f0f6cf60
2015-06-10 12:17:02 -05:00
Mark Michelson 339f965cbe Merge "chan_iax2: Prevent deadlock between hangup and sending lagrq/ping" 2015-06-10 12:06:02 -05:00
Mark Michelson 38c50df497 Merge "weakref attribute detection broken with gcc 4.6 and higher" 2015-06-10 10:38:35 -05:00
Mark Michelson f8359cf1ee Merge "res_pjsip_transport_websocket: Fix use-after-free bugs." 2015-06-10 10:38:12 -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
ibercom f897f36721 weakref attribute detection broken with gcc 4.6 and higher
GCC 4.7 Manual:
http://gcc.gnu.org/onlinedocs/gcc-4.7.4/gcc/Function-Attributes.html

weakref ("target")

A weak reference is an alias that does not by itself require a definition
to be given for the target symbol.

ASTERISK-22559 #close
Reported by: Ibercom

Change-Id: I36a136cae947b65187a697533416f9ff9a0b8cdf
2015-06-10 11:18:25 +02:00
Matt Jordan bbeb753e5e Merge "Fix unsafe uses of ast_context pointers." 2015-06-09 06:57:53 -05:00
Corey Farrell 80621ce3c5 Fix unsafe uses of ast_context pointers.
Although ast_context_find, ast_context_find_or_create and
ast_context_destroy perform locking of the contexts table,
any context pointer can become invalid at any time that the
contexts table is unlocked. This change adds locking around
all complete operations involving these functions.

Places where ast_context_find was followed by ast_context_destroy
have been replaced with calls ast_context_destroy_by_name.

ASTERISK-25094 #close
Reported by: Corey Farrell

Change-Id: I1866b6787730c9c4f3f836b6133ffe9c820734fa
2015-06-08 11:09:57 -04:00
Kevin Harwell 53c1126090 AMI: Escape string values.
So this issue is a bit complicated. Since it is possible to pass values to AMI
that contain a '\r\n' (or other similar sequences) these values need to be
escaped. One way to solve this is to escape the values and then pass the escaped
values to the AMI variable parameter string building function. However, this
puts the onus on the pre-build function to escape all string values. This
potentially requires a fair amount of changes along with a lot of string
allocations/freeing for all values.

Surely there is a way to push this complexity down a level into the string
building function itself? This of course is possible, but ends up requiring a
way to distinguish between strings that need to be escaped and those that don't.
The best way to handle this is by introducing a new format specifier in the
format string. For instance a %s (no escape) and %S (escape). However, that is
a bit weird and unexpected.

So faced with those possibilities this patch implements a limited version of the
first option. Instead of attempting to escape all string values this patch only
escapes those values that make sense. This approach limits the number of changes
and doesn't suffer from the odd format specifier problem.

ASTERISK-24934 #close
Reported by: warren smith

Change-Id: Ib55a5b84fe0481b0f2caaaab68c566f392c0aac0
2015-06-08 09:44:04 -05: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
ibercom d463bac574 CLI: Cosmetic issue - core show uptime
Show uptime information ends with an unnecessary space.

Now NEEDCOMMA is better defined.

Change-Id: I11b360504a0703309ff51772ff8f672287f3c5a1
2015-06-05 02:17:59 -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
Rodrigo Ramírez Norambuena 6737ded058 install_prereq: Check if is installed aptitude otherwise to install.
If in Debian or system based, dont have aptitude installed the script do
nothing. This patch checked if aptitude  installed, if not installed.

Also, if execute script with all packages installed yet, the script not show
nothing and return exit 1 because the command 'grep' get nothing from pipe from
'awk'.

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

Change-Id: Iebdff55805d3917166e5e08e0a1e2176f36ff27f
2015-06-03 21:12:50 -04: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 0b3c9c6289 Merge "tcptls.c: Don't use OpenSSL functions when no SSL support is present." 2015-06-02 12:04:17 -05:00
Matt Jordan 2a6282f4d8 Merge "cdr/cdr_csv.c: Set file name for csv master to the module when (re)loaded." 2015-06-02 12:02:01 -05:00
Joerg Sonnenberger 5f712e82ac tcptls.c: Don't use OpenSSL functions when no SSL support is present.
Change-Id: I68a85a7fcbdb282140ff333c6274b6763d5f82a3
2015-06-02 11:53:17 -05:00
Matt Jordan af420ba4ae Merge "res_pjsip_session: Fix in-dialog authentication." 2015-06-02 09:29:46 -05:00
Mark Michelson 255f695434 Merge "Fix buffer overflow in slin sample frames generation." 2015-06-01 16:08:31 -05:00
Rodrigo Ramírez Norambuena 2cd40c2bd7 cdr/cdr_csv.c: Set file name for csv master to the module when (re)loaded.
Compute the location for the csv master file when the module is
loaded or reload.  Before it was calculated every time a log
entry was written.

Change-Id: I3ed9f6a8f965308099db70b71128f43d4d3f5585
2015-06-01 15:14:58 -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
Ivan Poddubny 0a5f8c0d73 Fix buffer overflow in slin sample frames generation.
The length of frames retured by sample functions was twice as large as
real, what caused global buffer overflow caught by AddressSanitizer.

ASTERISK-24717 #close
Reported by: Badalian Vyacheslav

Change-Id: Iec2fe682aef13e556684912f906bedf7c18229c6
2015-05-31 12:29:21 -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 3fc4a58d75 Merge "Revert "endpoint/stasis: Eliminate duplicate events on endpoint status change"" 2015-05-29 14:55:22 -05:00
George Joseph 82716410a4 Revert "endpoint/stasis: Eliminate duplicate events on endpoint status change"
This reverts commit 6fca75bb62.

Change-Id: Ifee026cc63e22c5ac5717c37867a9f036373ae5a
2015-05-29 14:52:41 -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