Re-link peers by IP when dnsmgr changes the IP

Asterisk's dnsmgr currently takes a pointer to an ast_sockaddr and updates it
anytime an address resolves to something different. There are a couple of
issues with this. First, the ast_sockaddr is usually the address of an
ast_sockaddr inside a refcounted struct and we never bump the refcount of those
structs when using dnsmgr. This makes it possible that a refresh could happen
after the destructor for that object is called (despite ast_dnsmgr_release
being called in that destructor). Second, the module using dnsmgr cannot be
aware of an address changing without polling for it in the code. If an action
needs to be taken on address update (like re-linking a SIP peer in the
peers_by_ip table), then polling for this change negates many of the benefits
of having dnsmgr in the first place.

This patch adds a function to the dnsmgr API that calls an update callback
instead of blindly updating the address itself. It also moves calls to
ast_dnsmgr_release outside of the destructor functions and into cleanup
functions that are called when we no longer need the objects and increments the
refcount of the objects using dnsmgr since those objects are stored on the
ast_dnsmgr_entry struct. A helper function for returning the proper default SIP
port (non-tls vs tls) is also added and used.

This patch also incorporates changes from a patch posted by Timo Teräs to
ASTERISK-19106 for related dnsmgr issues.

(closes issue ASTERISK-19106)

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

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@353397 f38db490-d61c-443f-a65b-d21fe96a405b
Fix memory leak in error paths for action_originate().

* Fix memory leak of vars in error paths for action_originate().

* Moved struct fast_originate_helper tech and data members to stringfields.

* Simplified ActionID header handling for fast_originate().

* Added doxygen note to ast_request() and ast_call() and the associated
channel callbacks that the data/addr parameters should be treated as const
char *.

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

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@353463 f38db490-d61c-443f-a65b-d21fe96a405b
Allow res_calendar to be unloaded

The calendaring tech modules depend on res_calendar and initially
res_calendar just bumped the use count so that it couldn't be unloaded.
res_calendar can potentially create many threads and I've seen issues
where the Asterisk shutdown has failed where it looked like these
threads could be the culprit.

This patch adds unload support for res_calendar. Unloading res_calendar
will also unload the dependant tech modules as well.

(closes issue ASTERISK-16744)
Review: https://reviewboard.asterisk.org/r/1657/
........

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@353503 f38db490-d61c-443f-a65b-d21fe96a405b
Added clarification for the VERBOSITY setting to etc_default_asterisk

Clarified that using the VERBOSITY setting in etc_default_asterisk is the
same as using the -v command line switch, which causes Asterisk to launch
in console mode.

(closes issue ASTERISK-17030)
Reported by: Jonas
........

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@353551 f38db490-d61c-443f-a65b-d21fe96a405b
Resolve an overlap in the ast_audiohook_flags values.

AST_AUDIOHOOK_TRIGGER_WRITE and AST_AUDIOHOOK_WANTS_DTMF were overlapping which
may have caused unintended side effects.  This patch moves
AST_AUDIOHOOK_TRIGGER_WRITE, and updates AST_AUDIOHOOK_TRIGGER_MODE to reflect
the original intention.

This will affect existing modules that use these flags, so be sure to recompile
as necessary.

(closes issue ASTERISK-19246)
Reported by: feyfre
........

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@353599 f38db490-d61c-443f-a65b-d21fe96a405b
Use ast_sockaddr_stringify_fmt wrappers for various functions in chan_sip

There are a number of cleaner looking wrappers for ast_sockaddr_stringify_fmt
available which are slightly more readable than using a direct call to
ast_sockaddr_stringify_fmt. This patch switches a number of those calls in
chan_sip to use those wrappers and is generally harmless.

(Closes issue ASTERISK-16930)
Reported by: Michael L. Young
Patches:
	chan_sip-broken-registration-1.8.diff uploaded by Michael L. Young (license 5026)
........

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@353721 f38db490-d61c-443f-a65b-d21fe96a405b
Fix sip show peers port output, align columns, and fix ami port output.

A previous patch I committed from ASTERISK-16930 unexpectedly changed some output for
the AMI action "sippeers" which this patch changes back. Also, this aligns the output
for the cli command "sip show peers" and fixes another issue that patch introduced by
using ast_sockaddr_stringify calls multiple times without immediately using the pointer.
I also went ahead and did a little janitorial work to clean up whitespace in
_sip_show_peers.

(issue ASTERISK-16930)
(closes issue ASTERISK-19281)
Reported by: Patrick El Youssef
Patches:
	ASTERISK-19281.diff uploaded by Walter Doekes (license 5674)
........

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@353771 f38db490-d61c-443f-a65b-d21fe96a405b
Blocked revisions 353818

........
Backports some documentation for func_curl from 10 to 1.8

For some reason this function was completely undocumented in 1.8. I copied the
10 docs over to 1.8 and removed references to an enumerator that was added in
the Asterisk 10 version of func_curl.  That was the only change I noted.

(closes issue ASTERISK-19186)
Reported by: Olivier Krief


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@353819 f38db490-d61c-443f-a65b-d21fe96a405b
Fix TLS port binding behavior as well as reload behavior:

* Removes references to tlsbindport from http.conf.sample and manager.conf.sample
* Properly bind to port specified in tlsbindaddr, using the default port if specified.
* On a reload, properly close socket if the service has been disabled.

A note has been added to UPGRADE.txt to indicate how ports must be set for TLS.

(closes issue ASTERISK-16959)
reported by Olaf Holthausen

(closes issue ASTERISK-19201)
reported by Chris Mylonas

(closes issue ASTERISK-19204)
reported by Chris Mylonas

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

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@353820 f38db490-d61c-443f-a65b-d21fe96a405b
Restore the 'w' modifier support for ISDN spans.  Dial(DAHDI/g0/1234w888)

This feature also causes the sending complete ie to be sent for switch
types that do not automatically send the ie.  (EuroISDN/ETSI)

The main difference between dialing Dial(DAHDI/g0/1234w888) and
Dial(DAHDI/g0/1234,,D(888)) is the sending of the sending complete ie.

(closes issue ASTERISK-19176)
Reported by: rmudgett
Tested by: rmudgett
........

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@353868 f38db490-d61c-443f-a65b-d21fe96a405b
Ensure entering T.38 passthrough does not cause an infinite loop

After R340970 Asterisk was still polling the RTCP file descriptor after RTCP is
shut down and removed. If the descriptor happened to have data ready when the
removal occured then Asterisk would go into an infinite loop trying to read
data that it can never actually access. This change disables the audio RTCP
file descriptor for the duration of the T.38 transaction.

(closes issue ASTERISK-18951)
Reported-by: Kristijan Vrban
........

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@353916 f38db490-d61c-443f-a65b-d21fe96a405b
Fixes a segfault occuring when performing attended transfer with FAXOPT(gateway)=yes

(closes issue ASTERISK-19184)
Reported by: Alexandr


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@353962 f38db490-d61c-443f-a65b-d21fe96a405b
Fixes deadlocks occuring in chan_agent due to r335976

Bad locking order was added to chan_agent to prevent segfaults from having no locking
in a patch by irroot. This patch addresses the bad locking order by releasing locks before
getting the right locking order to stop deadlocks from occuring when doing multiple
interactions with agents.

(closes issue ASTERISK-19285)
Reported by: Alex Villacis Lasso
Review: https://reviewboard.asterisk.org/r/1708/
........

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@354000 f38db490-d61c-443f-a65b-d21fe96a405b
Add missing headers to AMI UnParkedCall event to uniquely identify the call.

The AMI UnParkedCall event was missing the Parkinglot and Uniqueid headers
that the AMI ParkedCall event contains.

(closes issue ASTERISK-19240)
Reported by: Michael Yara
........

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@354119 f38db490-d61c-443f-a65b-d21fe96a405b
Improved documentation of CLI "dialplan add extension" command.

* Documented dialplan add extension <exten>,<priority>,<app(<app-data>)>
format.

* Allow acceptance of command without the app-data value.  There are many
applications that do no need any parameters so it is silly to require that
field for all commands.

* Fixed a couple ast_malloc/ast_free mismatches with ast_add_extension2()
calls.

(closes issue ASTERISK-19222)
Reported by: Andrey Solovyev
Tested by: rmudgett
........

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@354217 f38db490-d61c-443f-a65b-d21fe96a405b
Fix column duplication bug in module reload for cdr_pgsql.

Prior to this patch, attempts to reload cdr_pgsql.so would cause the column list to keep
its current data and then add a second copy during the reload. This would cause attempts
to log the CDR to the database to fail. This patch also cleans up some unnecessary null
checks for ast_free and deals with a few potential locking problems.

(closes issue ASTERISK-19216)
Reported by: Jacek Konieczny
Review: https://reviewboard.asterisk.org/r/1711/
........

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@354270 f38db490-d61c-443f-a65b-d21fe96a405b
Fix multiple SIP realtime issues

1. Set lastms to 0 when clearing instead of ""
2. Don't set ipaddr or port to the string "(null)" when they are empty
3. Add missing required fields, set default for lastms to 0, and modify
   the length of the ipaddr field to 45 in the Postgresql realtime.sql
   file.

(closes issue ASTERISK-19172)
Review: https://reviewboard.asterisk.org/r/1703/
........

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@354349 f38db490-d61c-443f-a65b-d21fe96a405b
Remove some unnecessary locking from ast_hangup().

This patch removes some unnecessary locking of the channels container in
ast_hangup().  The reason this came up is that this lock can very quickly block
the entire system.  If any of the channel cleanup code decides to block, it
causes a problem for the whole system.  For example, when audiohooks get
destroyed, if that blocks for a while waiting on the mixmonitor thread to exit
because it's busy blocking on some I/O, it causes a problem for many other
threads in the meantime.

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

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@354493 f38db490-d61c-443f-a65b-d21fe96a405b
Fix crash in ParkAndAnnounce.

Well, thats embarrasing.  I forgot to initialize the caller_id storage.

(closes issue ASTERISK-19311)
Reported by: tootai
Tested by: rmudgett
........

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@354496 f38db490-d61c-443f-a65b-d21fe96a405b
Fix SIP INFO DTMF handling for non-numeric codes

In ASTERISK-18924, SIP INFO DTMF handlingw as changed to account for both
lowercase alphatbetic DTMF events, as well as uppercase alphabetic DTMF
events.  When this occurred, the comparison of the character buffer containing
the event code was changed such that the buffer was first compared again '0'
and '9' to determine if it was numeric.  Unfortunately, since the first
character in the buffer will typically be '1' in the case of non-numeric
event codes (10-16), this caused those codes to be converted to a DTMF event
of '1'.  This patch fixes that, and cleans up handling of both
application/dtmf-relay and application/dtmf content types.

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

(closes issue ASTERISK-19290)
Reported by: Ira Emus
Tested by: mjordan
........

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/10@354543 f38db490-d61c-443f-a65b-d21fe96a405b