Be more consistent with the return code for requests received from invalid domain.

When Asterisk receives an INVITE from an external domain when allowexternaldomains=no
send a 403 instead of a 404. This is consistent with Asterisk's behavior when receiving
a REGISTER in this situation.

(Closes issue ASTERISK-19601)
Reported by Matthew Jordan
Patches:
	ASTERISK-19601-no401.patch uploaded by Mark Michelson (License #5049)
........

Merged revisions 369302 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Multiple revisions 369323-369324

........
  r369323 | mmichelson | 2012-06-25 10:35:43 -0500 (Mon, 25 Jun 2012) | 9 lines
  
  Eliminate embedding of res_adsi.so module.
  
  The way this is done is to stop using the optional API.
  Instead, res_adsi.so, when loaded fills in a table of
  function pointers.
  
  Review: https://reviewboard.asterisk.org/r/1991
........
  r369324 | mmichelson | 2012-06-25 10:50:17 -0500 (Mon, 25 Jun 2012) | 2 lines
  
  Forgot to svn add this file in my last commit.
........

Merged revisions 369323-369324 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Fix Bridge application occasionally returning to the wrong location.

* Fix do_bridge_masquerade() getting the resume location from the zombie
channel.  The code must not touch a clone channel after it has masqueraded
it.  The clone channel has become a zombie and is starting to hangup.

(closes issue ASTERISK-19985)
Reported by: jamicque
Patches:
      jira_asterisk_19985_v1.8.patch (license #5621) patch uploaded by rmudgett
Tested by: jamicque
........

Merged revisions 369327 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Re-fix how local tag is generated when sending a 481 to an INVITE.

Match our local tag to whatever to-tag was sent in the initial INVITE.
Because the size of the to-tag may not fit in the buffer in the sip_pvt,
it has been changed to a string field.

(closes issue ASTERISK-19892)
reported by Walter Doekes

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

Merged revisions 369352 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Fix incorrect duration reporting in CDRs created in batch mode

Certain places in core/cdr.c would, if the duration value were 0, calculate the
duration as being the delta between the current time and the time at which the
CDR record was started.  While this does not typically cause a problem in
non-batch mode, this can cause an issue in batch mode where CDR records are
gathered and written long after those calls have ended. In particular, this
affects calls that were never answered, as those are expected to have a duration
of 0.  Often, this would result in CDR logs with a significant number of calls
with lengthy durations, but dispositions of "BUSY".

Note that this does not affect cdr_csv, as that backend does not use
ast_cdr_getvar and instead directly reports the duration value.  The affected
core backends include cdr_apative_odbc and cdr_custom; other extended or
deprecated CDR backends may potentially still directly manipulate the duration
values.

(issue ASTERISK-19860)
Reported by: Thomas Arimont

(issue AST-883)
Reported by: Thomas Arimont
Tested by: Matt Jordan

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

Merged revisions 369351 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Fix crash in unloading of res_adsi module

When res_adsi is unloaded, it removes the ADSI functions that it previously installed
by passing a NULL adsi_funcs pointer to ast_adsi_install_funcs.  This function was not
checking whether or not the adsi_funcs pointer passed in was NULL before dereferencing
it to check whether or not the version of the functions matches what the core was
expecting it.

This patch makes it so that the version is only checked if a potentially valid adsi_funcs
pointer was passed in.  Passing in NULL removes the installed functions, bypassing the
version check.
........

Merged revisions 369390 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Clean up after a reinvite that never gets a final response

The basic problem is that if a re-INVITE is sent by Asterisk and it receives a
provisional response, but no final response, then the dialog is never torn
down. In addition to leaking memory, this also leaks file descriptors and will
eventually lead to Asterisk no longer being able to process calls.

This patch just keeps track of whether there is an outstanding re-INVITE, and if
there is goes ahead and cleans up everything as though there was no outstanding
reinvite.

(closes issue ASTERISK-19992)
........

Merged revisions 369436 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Make the address family filter specific to the transport.

(closes issue ASTERISK-16618)
Reported by: Leif Madsen

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

Merged revisions 369471 from http://svn.asterisk.org/svn/asterisk/branches/1.8
With some configurations a transport is not actually specified so assume UDP in these cases.
........

Merged revisions 369490 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Fix apparent copy and paste error where incorrect "glue" is used.
Better handle re-INVITEs with provisional but no final repsonses

A previous attempt at fixing this issue had negative side effects related
to attended transfers which this patch should resolve. Many thanks to
Steve Davies for all of the good suggestions and testing.

(closes issue ASTERISK-19992)
Reported by: Steve Davies
Tested by: Steve Davies, Terry Wilson
Review: https://reviewboard.asterisk.org/r/2009/
........

Merged revisions 369557 from http://svn.asterisk.org/svn/asterisk/branches/1.8
More improvements to re-INVITEs timing out after a provisional response

There is no need to call check_pendings() on a final response to an INVITE
when destroying the scheduler entry as it will be done later during normal
processing.

(issue ASTERISK-19992)
........

Merged revisions 369579 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Do not send a BYE when a provisional response arrives during a re-INVITE

Commits r369557 and r369579 were done to improve handling of re-INVITEs
when the UA that was supposed to receive the re-INVITE fails to respond.
A limitation of those patches occurred when a UA sent a provisional
response to the re-INVITE.  This triggered a sending of a BYE in
check_pending.  This patch tweaks the handling of the re-INVITE such that
a BYE is not sent in response to those messages.

(issue ASTERISK-19992)
Reported by: Steve Davies
Tested by: Steve Davies
patches:
  (reinvite_tweak.diff license #5012 by Steve Davies)
........

Merged revisions 369626 from http://svn.asterisk.org/svn/asterisk/branches/1.8
AST-2012-011: Resolve heap corruption issue with voicemail

The heard and deleted arrays in the voicemail state structure were not
handled properly following the memory leak fix in r354890 and a fix for
an invalid free in r356797.  This could result in accessing and writing
into freed memory.  The allocation for these arrays has been reworked
to avoid the possibility of invalid frees, access of freed memory, and
crashes that were occurring as a result of this.

Locking around accesses and modifications of the voicemail state
structure members dh_arraysize, heard, and deleted has been added to
prevent simultaneous modification and access when IMAP storage is in
use.  If IMAP storage is not in use, this locking is not compiled in.

Review: https://reviewboard.asterisk.org/r/1994/
(closes issue ASTERISK-19923)
Reported by: Dan Delaney
Tested by: Dan Delaney, Julian Yap
Patches:
  vm_alloc_fix.diff uploaded by kmoore (license 6273)

........

Merged revisions 369652 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Fix bridging thread leak.

The bridge thread was exiting but was never being
reaped using pthread_join(). This has been fixed now
by calling pthread_join() in ast_bridge_destroy().

(closes issue ASTERISK-19834)
Reported by Marcus Hunger

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

Merged revisions 369708 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Remove a superfluous and dangerous freeing of an SSL_CTX.

The problem here is that multiple server sessions share
a SSL_CTX. When one session ended, the SSL_CTX would be
freed and set NULL, leaving the other sessions unable to
function.

The code being removed is superfluous because the SSL_CTX
structures for servers will be properly freed when ast_ssl_teardown
is called.

(closes issue ASTERISK-20074)
Reported by Trevor Helmsley
Patches:
	ASTERISK-20074.diff uploaded by Mark Michelson (license #5049)
Testers:
	Trevor Helmsley
........

Merged revisions 369731 from http://svn.asterisk.org/svn/asterisk/branches/1.8
chan_sip: Add case for FLASH control frames so that we don't display a warning.

chan_sip channels can receive flash control frames when connected to analog
phones and possibly for other reasons. There really isn't a reason to warn when
these frames are received, we can safely ignore them.

Patches:
    dahdi_sip_flash.diff uploaded by Jonathan Rose (license 6182)
........

Merged revisions 369750 from http://svn.asterisk.org/svn/asterisk/branches/1.8
chan_sip: Fix small behavioral change accidentally introduced in r369750

When removing the warning for AST_CONTROL_FLASH from sip_indicate, I also
inadvertently changed the return value, which would likely make the indication
not be sent in audio. This fixes that while still removing the warning message.
........

Merged revisions 369792 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Add Digium phones context to sip_notify sample config.

This makes it so that they can be reconfigured remotely.

(closes issue ASTERISK-19910)
........

Merged revisions 369818 from http://svn.asterisk.org/svn/asterisk/branches/1.8
Improve Goto and GotoIf related documentation

Correct documentation on labeliftrue and labeliffalse parameters of
GotoIf() and update several other locations that use the same syntax.

(closes issue ASTERISK-20007)
Patch-by: Leif Madsen
Reported-by: WIMPy
........

Merged revisions 369869 from http://svn.asterisk.org/svn/asterisk/branches/1.8