Commit Graph

3379 Commits

Author SHA1 Message Date
zuul 64c03d4d19 Merge "config_transport: Fix objects returned by ast_sip_get_transport_states" 2016-03-03 21:45:39 -06:00
Joshua Colp 6af7fc4c37 res_pjsip_dtmf_info: NULL terminate the message body.
PJSIP does not ensure that when printing the message body the
buffer will be NULL terminated. This is problematic when searching
for the signal and duration values of the DTMF.

This change ensures the buffer is always NULL terminated.

Change-Id: I52653a1a60c93092d06af31a27408d569cc98968
2016-03-03 10:43:20 -06:00
Joshua Colp d7fe2becdd Merge "SIP diversion: Fix REDIRECTING(reason) value inconsistencies." 2016-03-03 07:40:41 -06:00
Joshua Colp 8140d7a8ef Merge "res_pjsip_send_to_voicemail.c: Allow either quoted or not send_to_vm reason." 2016-03-03 05:32:59 -06:00
zuul 71427f1454 Merge "res_pjsip_send_to_voicemail.c: Fix off-nominal double channel unref." 2016-03-02 21:24:14 -06:00
zuul 53f84a4670 Merge "CHAOS: cleanup possible null vars on msg alloc failure" 2016-03-02 18:02:38 -06:00
George Joseph 7b71bca8a4 config_transport: Fix objects returned by ast_sip_get_transport_states
ast_sip_get_transport_states was returning a container of internal_state
objects instead of ast_sip_transport_state objects.  This was causing
transport lookups to fail, most noticably in res_pjsip_nat, which
couldn't find the correct external addresses.  This was causing contacts
to go out with internal ip addresses.

ASTERISK-25830 #close
Reported-by: Sean Bright

Change-Id: I1aee6a2fd46c42e8dd0af72498d17de459ac750e
2016-03-02 16:10:18 -06:00
Scott Griepentrog 0a3f0e85ac CHAOS: cleanup possible null vars on msg alloc failure
In message.c, if msg_alloc fails to init the string field,
vars may be null, so use a null tolerant cleanup.

In res_pjsip_messaging.c, if msg_data_create fails, mdata
will be null, so use a null tolerant cleanup.

ASTERISK-25323

Change-Id: Ic2d55c2c3750d5616e2a05ea92a19c717507ff56
2016-03-02 11:56:51 -06:00
Scott Griepentrog 60aa871be3 CHAOS: prevent crash on failed strdup
This patch avoids crashing on a null pointer
if the strdup() allocation fails.

ASTERISK-25323

Change-Id: I3f67434820ba53b53663efd6cbb42749f4f6c0f5
2016-03-02 10:29:16 -06:00
Richard Mudgett 25de01f301 SIP diversion: Fix REDIRECTING(reason) value inconsistencies.
Previous chan_sip behavior:

Before this patch chan_sip would always strip any quotes from an incoming
reason and pass that value up as the REDIRECTING(reason).  For an outgoing
reason value, chan_sip would check the value against known values and
quote any it didn't recognize.  Incoming 480 response message reason text
was just assigned to the REDIRECTING(reason).

Previous chan_pjsip behavior:

Before this patch chan_pjsip would always pass the incoming reason value
up as the REDIRECTING(reason).  For an outgoing reason value, chan_pjsip
would send the reason value as passed down.

With this patch:

Both channel drivers match incoming reason values with values documented
by REDIRECTING(reason) and values documented by RFC5806 regardless of
whether they are quoted or not.  RFC5806 values are mapped to the
equivalent REDIRECTING(reason) documented value and is set in
REDIRECTING(reason).  e.g., an incoming RFC5806 'unconditional' value or a
quoted string version ('"unconditional"') is converted to
REDIRECTING(reason)'s 'cfu' value.  The user's dialplan only needs to deal
with 'cfu' instead of any of the aliases.

The incoming 480 response reason text supported by chan_sip checks for
known reason values and if not matched then puts quotes around the reason
string and assigns that to REDIRECTING(reason).

Both channel drivers send outgoing known REDIRECTING(reason) values as the
unquoted RFC5806 equivalent.  User custom values are either sent as is or
with added quotes if SIP doesn't allow a character within the value as
part of a RFC3261 Section 25.1 token.  Note that there are still
limitations on what characters can be put in a custom user value.  e.g.,
embedding quotes in the middle of the reason string is silly and just
going to cause you grief.

* Setting a REDIRECTING(reason) value now recognizes RFC5806 aliases.
e.g., Setting REDIRECTING(reason) to 'unconditional' is converted to the
'cfu' value.

* Added missing malloc() NULL return check in res_pjsip_diversion.c
set_redirecting_reason().

* Fixed potential read from a stale pointer in res_pjsip_diversion.c
add_diversion_header().  The reason string needed to be copied into the
tdata memory pool to ensure that the string would always be available.
Otherwise, if the reason string returned by reason_code_to_str() was a
user's reason string then the string could be freed later by another
thread.

Change-Id: Ifba83d23a195a9f64d55b9c681d2e62476b68a87
2016-03-01 20:21:58 -06:00
Richard Mudgett 8c8ef4efb0 res_pjsip_send_to_voicemail.c: Allow either quoted or not send_to_vm reason.
Change-Id: Id6350b3c7d4ec8df7ec89863566645e2b0f441fd
2016-03-01 20:16:37 -06:00
Richard Mudgett 75ec137e91 res_pjsip_send_to_voicemail.c: Fix off-nominal double channel unref.
* Fix double unref of other_party channel in off nominal path.

* This is unlikely to be a real problem.  However, for safety,
in handle_incoming_request() keep the datastore ref with the
other_party channel ref until we are finished with the other_party
channel.

Change-Id: I78f22547bf0bb99fb20814ceab75952bd857f821
2016-03-01 20:09:32 -06:00
Joshua Colp 91f8763452 Merge "res_pjsip_t38.c: Back out part of an earlier fix attempt." 2016-03-01 06:00:36 -06:00
zuul c47d15fda7 Merge "res_pjsip_mwi: Turn some NOTICEs and WARNINGs into debug 1s." 2016-02-29 16:55:33 -06:00
Richard Mudgett bf29a4e2e6 res_pjsip_t38.c: Back out part of an earlier fix attempt.
This backs out item 4 of the 4875e5ac32
commit.  Item 4 added the t38_bye_supplement.  Unfortunately, the frame
that it puts into the bridge may or may not be processed by the time the
bridged peer is kicked out of the bridge.  If it is processed then all is
well.  However, if it is not processed then that channel is stuck in fax
mode until it hangs up or maybe if it joins another bridge for T.38
faxing.

ASTERISK-25582

Change-Id: Ib20a03ecadf1bf8a0dcadfadf6c2f2e60919a9f7
2016-02-29 12:50:43 -06:00
George Joseph acf329a3c7 res_pjsip_mwi: Turn some NOTICEs and WARNINGs into debug 1s.
There are a few cases where we're emitting notices or warnings
for things that really need neither, like a client retrying to subscribe
to mwi when they're not conifgured for it.  They get a 404 so there's no
need for non-debug messages.

Change-Id: I05e38a7ff6c2f2521146f4be6a79731b9864e61f
2016-02-27 16:54:10 -06:00
Joshua Colp 62d98b5a7f Merge "res_pjsip/config_transport: Allow reloading transports." 2016-02-27 10:18:26 -06:00
George Joseph 7e3e1ddf7e res_sorcery_memory_cache: Fix SEGV in some CLI commands
A few of the CLI commands weren't checking for enough arguments
and were SEGVing.

Change-Id: Ie6494132ad2fe54b4f014bcdc112a37c36a9b413
2016-02-25 14:18:57 -06:00
zuul d6b2c1d98e Merge "res_config_sqlite3: Fix crashes when reading peers from sqlite3 tables" 2016-02-24 18:26:07 -06:00
zuul 062857ece3 Merge "res_pjsip_config_wizard: Add command to export primitive objects" 2016-02-23 17:41:35 -06:00
Joshua Colp def3fb4634 Merge "res_pjproject: Add ability to map pjproject log levels to Asterisk log levels" 2016-02-22 10:55:03 -06:00
Christof Lauber b7970cabfa res_config_sqlite3: Fix crashes when reading peers from sqlite3 tables
Introduced realloaction of ast_str buf in sqlite3_escape functions in case
the returned buffer from threadstorage was actually too small.

Change-Id: I3c5eb43aaade93ee457943daddc651781954c445
2016-02-22 10:11:43 +01:00
George Joseph ba8adb4ce3 res_pjsip/config_transport: Allow reloading transports.
The 'reload' mechanism actually involves closing the underlying
socket and calling the appropriate udp, tcp or tls start functions
again.  Only outbound_registration, pubsub and session needed work
to reset the transport before sending requests to insure that the
pjsip transport didn't get pulled out from under them.

In my testing, no calls were dropped when a transport was changed
for any of the 3 transport types even if ip addresses or ports were
changed. To be on the safe side however, a new transport option was
added (allow_reload) which defaults to 'no'.  Unless it's explicitly
set to 'yes' for a transport, changes to that transport will be ignored
on a reload of res_pjsip.  This should preserve the current behavior.

Change-Id: I5e759850e25958117d4c02f62ceb7244d7ec9edf
2016-02-19 18:57:55 -06:00
George Joseph f8767a8804 res_pjproject: Add ability to map pjproject log levels to Asterisk log levels
Warnings and errors in the pjproject libraries are generally handled by
Asterisk.  In many cases, Asterisk wouldn't even consider them to be warnings
or errors so the messages emitted by pjproject directly are either superfluous
or misleading.  A good exampe of this are the level-0 errors pjproject emits
when it can't open a TCP/TLS socket to a client to send an OPTIONS.  We don't
consider a failure to qualify a UDP client an "ERROR", why should a TCP/TLS
client be treated any differently?

A config file for res_pjproject has bene added (pjproject.conf) and a new
log_mappings object allows mapping pjproject levels to Asterisk levels
(or nothing).  The defaults if no pjproject.conf file is found are the same
as those that were hard-coded into res_pjproject initially: 0,1 = LOG_ERROR,
2 = LOG_WARNING, 3,4,5 = LOG_DEBUG<level>

Change-Id: Iba7bb349c70397586889b8f45b8c3d6c6c8c3898
2016-02-18 16:30:29 -06:00
Alexei Gradinari 14886643c6 res_pjsip_outbound_publish: Fix processing 412 response
When Asterisk receives a 412 (Conditional Request Failed) response
it has to recreate publish session.
There is bug in res_pjsip_outbound_publish.c
The function sip_outbound_publish_client_alloc is called with wrong object
while processing 412 (Conditional Request Failed) response.
This patch fixes it.

ASTERISK-25229 #close

Change-Id: I3b62f2debf6bb1e5817cde7b13ea39ef2bf14359
2016-02-18 12:04:56 -06:00
George Joseph 62282bb8ce res_odbc: Fix exports.in for missing symbols
res_odbc.exports.in was missing a few symbols.
Changed to wildcards.

Change-Id: Ieadd76df24e43ea92577f651d478a0f7b742c30c
2016-02-16 16:42:26 -06:00
George Joseph 49203628f9 res_statsd: Fix exports.in for missing symbols
res_statsd.export.in was missing the _va variations of the log
functions causing Asterisk to crash in res_pjsip if OPTIONAL_API
wasn't enabled.

ASTERISK-25727 #close
Reported-by: Gergely Dömsödi

Change-Id: I395729f9f51bdd33c5ca757f5f96ebedad74077b
2016-02-16 12:26:29 -06:00
George Joseph 4f08e9fb64 res_pjsip_config_wizard: Add command to export primitive objects
A new command (pjsip export config_wizard primitives) has been added that
will export all the pjsip objects it created to the console or a file
suitable for reuse in a pjsip.conf file.

ASTERISK-24919 #close
Reported-by: Ray Crumrine

Change-Id: Ica2a5f494244b4f8345b0437b16d06aa0484452b
2016-02-15 21:37:04 -06:00
George Joseph be811c4be1 res_pjsip_caller_id: Fix segfault when replacing rpid or pai header
If the PJSIP_HEADER dialplan function adds a PAI or RPID header and send_rpid
or send_pai is set, res_pjsip_caller_id attemps to retrieve, parse and modify
the header added by the dialplan function.  Since the header added by the
dialplan function is generic string, there are no virtual functions to parse
the uri and we get a segfault when we try.  Since the modify, was really only
an overwrite, we now just delete the old header if it was type PJSIP_H_OTHER
and recreate it.

This raises a question for another time though:  What should happen with
duplicate headers?  Right now res_pjsip_header_funcs doesn't check for dups
so if it's session supplement is loaded after res_pjsip_caller_id's (or any
other module that adds headers), there'll be dups in the message.

ASTERISK-25337 #close

Change-Id: I5e296b52d30f106b822c0eb27c4c2b0e0f71c7fa
2016-02-15 15:53:32 -06:00
zuul 23b2b7747d Merge "Fix creation race of contact_status structures." 2016-02-15 15:39:47 -06:00
Mark Michelson 13b6c02945 Fix creation race of contact_status structures.
It is possible when processing a SIP REGISTER request to have two
threads end up creating contact_status structures in sorcery.
contact_status is created using a "find or create" function. If two
threads call into this at the same time, each thread will fail to find
an existing contact_status, and so both will end up creating a new
contact status.

During testing, we would see sporadic failures because the
PJSIP_CONTACT() dialplan function would operate on a different
contact_status than what had been updated by res_pjsip/pjsip_options.

The fix here is two-fold:
1) The "find or create" function for contact_status now has a lock
around the entire operation. This way, if two threads attempt the
operation simultaneously, the first to get there will create the object,
and the second will find the object created by the first thread.

2) res_sorcery_memory has had its create callback updated so that it
will not allow for objects with duplicate IDs to be created.

Change-Id: I55b1460ff1eb0af0a3697b82d7c2bac9f6af5b97
2016-02-15 13:48:44 -06:00
Joshua Colp 5c400a0fed res_pjsip_pubsub: Move where the subscription is stored to after initialized.
A problem arose when testing the AMI subscription listing actions where it
was possible for a subscription that had not been fully initialized to be
listed. This was problematic as the underlying listing code would crash.

This change makes it so the subscription tree is fully set up before it is
added to the list of subscriptions. This ensures that when the listing actions
get the subscription it is valid.

ASTERISK-25738 #close

Change-Id: Iace2b13641c31bbcc0d43a39f99aba1f340c0f48
2016-02-15 13:01:54 -06:00
zuul 1783edd181 Merge "res_pjsip: Refactor load_module/unload_module" 2016-02-12 16:50:18 -06:00
zuul 295a501d79 Merge "res_pjsip: Handle pjsip_dlg_create_uas deprecation" 2016-02-12 16:50:13 -06:00
George Joseph b37555cc94 res_pjsip: Refactor load_module/unload_module
load_module was just too hairy with every step having to clean up all
previous steps on failure.

Some of the pjproject init calls have now been moved to a separate
load_pjsip function and the unload_pjsip function was enhanced to clean
up everything if an error happened at any stage of the load process.

In the process, a bunch of missing pj_shutdowns, serializer_pool_shutdowns
and ast_threadpool_shutdowns were also corrected.

Change-Id: I5eec711b437c35b56605ed99537ebbb30463b302
2016-02-11 19:05:11 -07:00
zuul a39486552e Merge "Resources/res_phoneprov: fix memory leak and heap-use-after-free" 2016-02-11 17:04:51 -06:00
Badalyan Vyacheslav c4d9f46878 Resources/res_phoneprov: fix memory leak and heap-use-after-free
* heap-use-after-free happens when we free "cfg"
but then use "value" which refers to it

* A memory leak occurs because in some cases
it is not released "defaults"

ASTERISK-25721 #close
Reported by: Badalyan Vyacheslav
Tested by: Badalyan Vyacheslav

Change-Id: I3807d3f4726df6864430ec144cf6265d3f538469
2016-02-11 20:19:03 +00:00
Joshua Colp 39a6cd8a79 Merge "res_pjsip: Fix infinite recursion when loading transports from realtime" 2016-02-11 06:10:06 -06:00
George Joseph 168c18737f res_pjsip: Handle pjsip_dlg_create_uas deprecation
Pjproject has deprecated pjsip_dlg_create_uas in 2.5 and replaced it with
pjsip_dlg_create_uas_and_inc_lock which, as the name implies, automatically
increments the lock on the returned dialog.  To account for this, configure.ac
now detects the presence of pjsip_dlg_create_uas_and_inc_lock and res_pjsip.c
has an #ifdef HAVE_PJSIP_DLG_CREATE_UAS_AND_INC_LOCK to decide whether to use
the original call or the new one.  If the new one was used, the ref count is
decremented before returning.

ASTERISK-25751 #close
Reported-by Josh Colp

Change-Id: I1be776b94761df03bd0693bc7795a75682615ca8
2016-02-10 15:28:08 -07:00
Rodrigo Ramírez Norambuena fd668670b5 res_config_pgsql: Show error message in reload if not connected.
Change-Id: I9290115a1aaadb589eb1d02eaeb502eec01b31fa
2016-02-10 14:41:09 -03:00
Joshua Colp cf89aecc8a Merge "res_config_pgsql: Add message on cli failed command status" 2016-02-09 13:45:33 -06:00
George Joseph bbf3ace682 res_pjsip: Fix infinite recursion when loading transports from realtime
Attempting to load a transport from realtime was forcing asterisk into an
infinite recursion loop.  The first thing transport_apply did was to do a
sorcery retrieve by id for an existing transport of the same name. For files,
this just returns the previous object from res_sorcery_config's internal
container, if any.  For realtime, the res_sourcery_realtime driver looks in the
database and finds the existing row but now it has to rehydrate it into a
sorcery object which means calling... transport_apply.  And so it goes.

The main issue with loading from realtime (apart from the loop) was that
transport stores structures and pointers directly in the ast_sip_transport
structure instead of the separate ast_transport_state structure.  This patch
separates those items into the ast_sip_transport_state structure.  The pattern
is roughly the same as res_pjsip_outbound_registration.

Although all current usages of ast_sip_transport and ast_sip_transport_state
were modified to use the new ast_sip_get_transport_state API, the original
items are left in ast_sip_transport and kept updated to maintain ABI
compatability for third-party modules.  They are marked as deprecated and
noted that they're now in ast_sip_transport_state.

ASTERISK-25606 #close
Reported-by: Martin Moučka

Change-Id: Ic7a836ea8e786e8def51fe3f8cce855ea54f5f19
2016-02-08 19:11:18 -06:00
Rodrigo Ramírez Norambuena 72bf53eea5 res_config_pgsql: Add message on cli failed command status
In case failed of command "realtime show pgsql status" show a message the data
of connection to more clear information in error.

Change-Id: Ia8e9e2400466606e7118f52a46e05df0719b6a29
2016-02-07 17:08:43 -03:00
Mark Michelson c0a8ecc8c0 Merge "logging: Remove/fix some message annoyances" 2016-02-04 14:10:58 -06:00
Joshua Colp d8f1a74d15 Merge "res_stasis_device_state: Fix refcounting error." 2016-02-04 12:35:37 -06:00
Joshua Colp 8b311bebd8 Merge "res_xmpp: Does not connect in component mode" 2016-02-04 12:26:49 -06:00
Mark Michelson 82e2938fa8 res_stasis_device_state: Fix refcounting error.
Device state subscription lifetimes were governed by when the
subscription was established and unsubscribed from. However, it is
possible that at the time of unsubscription, there could be device state
events still in flight. When those device state events occur, the device
state callback could attempt to dereference a freed pointer. Crash.

This change ensures that the lifetime of the device state subscription
does not end until the underlying stasis subscription has confirmed that
its final message has been sent.

Change-Id: I25a0f1472894c1a562252fb7129671478e25e9b2
2016-02-04 12:05:52 -06:00
Sean Bright d83dba7099 res_rtp_asterisk: Allow ICE host candidates to be overriden
During ICE negotiation the IPs of the local interfaces are sent to the remote
peer as host candidates. In many cases Asterisk is behind a static one-to-one
NAT, so these host addresses will be internal IP addresses.

To help in hiding the topology of the internal network, this patch adds the
ability to override the host candidates by matching them against a
user-defined list of replacements.

Change-Id: I1c9541af97b83a4c690c8150d19bf7202c8bff1f
2016-02-03 17:06:20 -06:00
George Joseph dcbedf9ab1 logging: Remove/fix some message annoyances
test_dlinklists doesn't need to NOTICE everyone that every macro worked.

res_phoneprov doesn't need to VERBOSE everyone that a phoneprov extension or
provider was registered.

res_odbc was missing a newline at the end of one message.

Change-Id: I6c06361518ef3711821795e535acd439782a995e
2016-02-03 14:11:11 -06:00
Mark Michelson 6522361871 res_sorcery_realtime: Fix regex regression.
A regression was introduced where searching for realtime PJSIP objects
by regex by starting the regex with a leading "^" would cause no items
to be returned.

This was due to a change which attempted to drop the requirement for a
leading "^" to be present due to how some CLI commands formulate their
regexes. However, the change, rather than simply eliminating the
requirement, caused any regexes that did begin with "^" to end up not
returning the expected results.

This change fixes the problem by inspecting the regex and formulating
the realtime query differently depending on if it begins with "^".

ASTERISK-25702 #close
Reported by Nic Colledge

Patches:
    realtime_retrieve_regex.patch submitted by Alexei Gradinari License #5691

Change-Id: I055df608a6e6a10732044fa737a9fe8dca602693
2016-02-02 15:01:37 -06:00