Fix Some Configured Conference Bridge Sounds Not Being Set

The "sound_only_one" sound was not being set even though it was configured.  In
looking into this, I found that the "join" and "leave" prompts were not being
set either.

(closes issue ASTERISK-20898)
Reported by: Stephan
Tested by: Stephan
Patches:
    asterisk-20898-custom-sounds-ignored.diff uploaded by 
                                                 Michael L. Young (license 5026)

Review: https://reviewboard.asterisk.org/r/2289/
Change cleanup ordering in filestream destructor.

This patch came about due to a problem observed where wav files had an
empty header.  The header is supposed to be updated in wav_close().  It
turns out that this was broken when the cache_record_files option from
asterisk.conf was enabled.  The cleanup code was moving the file to its
final destination *before* running the close() method of the file
destructor, so the header didn't get updated.

Another problem here is that the move was being done before actually
closing the FILE *.

Finally, the last bug fixed here is that I noticed that wav_close()
checks for stream->filename to be non-NULL.  In the previous cleanup
order, it's checking a pointer to freed memory.  This doesn't actually
cause anything to break, but it's treading on dangerous waters.  Now the
free() of stream->filename is happening after the format module's
close() method gets called, so it's safer.

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

Merged revisions 380210 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Correct the number of available call numbers in IAX2.

There is currently an edge case where call number 32768 might be allocated for
a call, even though the IAX2 protocol requires call numbers be only 15 bits.
This resulted in some unpredictable behavior when call number 32678 is chosen.

This patch was mostly written by Richard Mudgett via ReviewBoard.  I'm just
committing it.

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

Merged revisions 380254 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Update configure script to be compatible with ptlib 2.10.9

With ptlib 2.10.9, the configure script fails due to grep returning multiple
matches for the pattern it searches for. This patch updates the pattern
matching to return only the actual version for the symbol searched for,
PTLIB_VERSION.

(closes issue ASTERISK-20980)
Reported by: Stefan Reuter
patches:
  ASTERISK-20980-1.patch uploaded by Stefan Reuter (license 5339)
........

Merged revisions 380297 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Ensure that a declined media stream is terminated with a '\r\n'

In r369028, chan_sip's processing of media streams in an SDP was modified to
better handle multiple offered media streams. Part of that change modified
how streams were declined. Previously, declined media streams were not
handled in an RFC compliant manner; now, we set the port number to 0 in the
media stream definition and proceed on with the next media stream.

Unfortunately, the formatting of the declined media stream forgot to append a
'\r\n' to the end of the media stream. This is normally added to the accepted
media streams later on in the processing of the SDP. Since the declined media
stream uses a different buffer than the accepted media streams (and is a
malloc'd buffer as opposed to a struct ast_str), it's easier to just slap the
'\r\n' on the declined media stream buffer rather than attempt to append it
later on.

So, that's what we do. And now some devices (and probably some providers) will
be a bit happier (but probably not terribly happy, since we just rejected
something they offered).

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

(closes issue ASTERISK-20908)
Reported by: Dennis DeDonatis
Tested by: Dennis DeDonatis
call_parking: Make sure fallbacks are used when lacking a flat channel exten

A regression was introduced which removed automatic fallback behavior from
the PBX. This behavior was used by call parking (or at least documented as
how the feature works) in order to select an extension when the flat channel
extension wasn't available from the comebackcontext. Parking now handles
the fallbacks internally in order to keep behavior matching with how it is
documented.

(closes issue ASTERISK-20716)
Reported by: Chris Gentle
Review: https://reviewboard.asterisk.org/r/2296/
Corrected crypto tag in SDP ANSWER for SRTP. (again)

The original fix (r380043) for getting Asterisk to respond with the correct
tag overlooked some corner cases, and the fact that the same code is in 1.8.

This patch moves the building of the crypto line out of
sdp_crypto_process(). Instead, it merely copies the accepted tag. The call to
sdp_crypto_offer() will build the crypto line in all cases now, using a tag of
"1" in the case of sending offers.

(closes issue ASTERISK-20849)
Reported by: José Luis Millán
Review: https://reviewboard.asterisk.org/r/2295/
........

Merged revisions 380347 from http://svn.asterisk.org/svn/asterisk/branches/1.8
chan_agent: Prevent multiple channels from logging in as the same agent.

Multiple channels logging in as the same agent can result in dead channels
waiting for a condition signal that will never come because another
channel thread stole it.  A symptom is chan_sip repeatedly generating
warning messages about rescheduling autodestruction of dialogs with an
agent channel owner.

* Made only login_exec() (the app AgentLogin) clear the agent_pvt->chan
pointer to prevent multiple channels from logging in as the same agent.
agent_read(), agent_call(), and agent_set_base_channel() no longer
disconnect the agent channel from the agent_pvt.  This also eliminates the
need to keep checking for agent_pvt->chan being NULL.

* Made agent_hangup() not wake up the AgentLogin agent thread until it is
done.

* Made agent_request() not able to get the agent until he has logged in
and any wrapup time has expired.

* Made agent_request() use ast_hangup() instead of agent_hangup() to
correctly dispose of a channel.

* Removed agent_set_base_channel().  Nobody calls it and it is a bad thing
in general.

* Made only agent_devicestate() determine the current device state of an
agent.  Note: Agent group device states have never been supported.

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

Merged revisions 380364 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Fix memory leak in res_calendar_icalendar

The ICalendar module had a systemic memory leak on each fetch of data from
the ICalendar source. The previous fetched data was not being properly
disposed. This patch makes it so that before each fetch of data, we dispose
of the previously fetched data.

(closes issue ASTERISK-21012)
Reported by: Joel Vandal
Tested by: Joel Vandal
........

Merged revisions 380451 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Perform case insensitive comparisons for T.38 attributes

RFC5347 section 2.5.2 states the following:
...
The attribute "T38MaxBitRate" was once incorrectly registered with
IANA as "T38maxBitRate" (lower-case "m"). In accordance with T.38
examples and common implementation practice, the form "T38MaxBitRate"
SHOULD be generated by implementations conforming to this package.
In general, it is RECOMMENDED that implementations of this package
accept lowercase, uppercase, and mixed upper/lowercase encodings of
all the T.38 attributes.
...

Asterisk currently does not perform case insensitive matching on the T.38
attributes. This causes the T38MaxBitRate attribute to be negotiated at
2400 baud instead of 14400 (or whatever value you actually wanted).

This patch makes it so that when we compare T.38 attributes, we do so in a case
insensitive fashion.

Note that while the issue reporter did not directly write the patch, they
contributed to it (and would have provided one themselves if the license had
gone through a tad faster), and hence get attribution for it.

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

(closes issue ASTERISK-20897)
Reported by: Eric Hill
Tested by: Eric Hill
patches:
  -- uploaded by Eric Hill
........

Merged revisions 380458 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Unregister SIP provider API if module load is declined

A user in #asterisk ran into a problem where a configuration error prevented
the chan_sip module from being loaded. Upon fixing their configuratione error,
they could no longer load the chan_sip module. This was because the
configuration checking happened after the SIP provider was registered with the
Asterisk core, and subsequent attempts to load the SIP module failed as the
provider was already registered.

Since we want to detect any failure in registering chan_sip as early as
possible (as that could be emblematic of a deeper mismatch between module
and Asterisk core), this patch does not change the registration location, but
does ensure that if a module load is declined, we unregister the module as
the SIP api provider.
Support building Asterisk for Raspberry Pi/Raspbian with hard-float support

Building Asterisk on Raspbian with hard-float support fails as it uses the
string 'linux-gnueabihf' for host os, as opposed to 'linux-gnueabi'. This patch
modifies the configure script for Asterisk such that it will match on any
string beginning with 'linux-gnueabi', as opposed to requiring an explicit
match.

(closes issue ASTERISK-21006)
Reported by: Christian Hesse
Tested by: Christian Hesse
patches:
  linux-gnueabihf.patch uploaded by Christian Hesse (license 6459)
  linux-gnueabihf-autoconf.patch uploaded by Christian Hesse (license 6459)
........

Merged revisions 380520 from http://svn.asterisk.org/svn/asterisk/branches/1.8
chan_dahdi: Fix "dahdi show channels group" for groups greater than 31.

The variable type used was not large enough to hold a group bit field.
........

Merged revisions 380572 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Make CHECK_BLOCKING() debug message more useful.

Change the displayed pthread value to hex format so it can be easily
matched with CLI core show threads or gdb.
........

Merged revisions 380611 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Remove a cross-compile workaround.

ar and ranlib can be easily detected with autoconf.
Always check for libm, regardless of configure options.
Add support for parallel builds of pjproject.

Also adds proper dependency checking, and direct .a file targets.  We don't
take advantage of this currently, but we will soon.

(issue ASTERISK-20815)
Process session timers, even if Session-Expires header is missing

Previously, Asterisk only processed session timer information if both the
'Supported: timer' and 'Session-Expires' headers were present. However, the
Session-Expires header is optional. If we were to receive a request with a
Min-SE greater than our configured session-expires, we would respond with a
'Session-Expires' header that was too small.

This patch cleans the situation up a bit, always processing timer information
if the 'Supported: timer' header is present.

(closes issue ASTERISK-20787)
Reported by: Mark Michelson
Review: https://reviewboard.asterisk.org/r/2299/
........

Merged revisions 380696 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Fix a few compiler warnings.
Ignore warnings caused by PJ_TODO()s in pjproject.