Fix DBDelTree error codes for AMI, CLI and AGI

The AMI DBDelTree command will return Success/Key tree deleted successfully even
if the given key does not exist. The CLI command 'database deltree' had a
similar problem, but was saved because it actually responded with '0 database
entries removed'. AGI had a slightly different error, where it would return
success if the database was unavailable.

This came from confusion about the ast_db_deltree retval, which is -1 in the
event of a database error, or number of entries deleted (including 0 for
deleting nothing).

* Changed some poorly named res variables to num_deleted
* Specified specific errors when calling ast_db_deltree (database unavailable
  vs. entry not found vs. success)
* Fixed similar bug in AGI database deltree, where 'Database unavailable'
  results in successful result

(closes issue AST-967)
Reported by: John Bigelow
Review: https://reviewboard.asterisk.org/r/2138/
........

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

Merged revisions 374427 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 374428 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: http://svn.asterisk.org/svn/asterisk/trunk@374429 f38db490-d61c-443f-a65b-d21fe96a405b
dsp.c fix incorrect DTMF Digit_Duration.

it's always short by 'hits_to_begin*DTMF_GSIZE', or 25.5ms if hitstobegin=2

(issue ASTERISK-16003)
Tested by: alecdavis
alecdavis (license 585)

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

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

Merged revisions 374476 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 374477 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: http://svn.asterisk.org/svn/asterisk/trunk@374478 f38db490-d61c-443f-a65b-d21fe96a405b
dsp.c User Configurable DTMF_HITS_TO_BEGIN and DTMF_MISSES_TO_END

Instead of a recompile, allow values to be adjusted in dsp.conf

For binary distributions allows easy adjustment for wobbly GSM calls, and other reasons.

Defaults to DTMF_HITS_TO_BEGIN=2 and DTMF_MISSES_TO_END=3

(closes issue ASTERISK-17493)
Tested by: alecdavis
alecdavis (license 585)

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

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

Merged revisions 374481 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 374485 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: http://svn.asterisk.org/svn/asterisk/trunk@374493 f38db490-d61c-443f-a65b-d21fe96a405b
Merged revisions 374515-374535 from
https://origsvn.digium.com/svn/asterisk/be/branches/C.3-bier

................
  r374515 | rmudgett | 2012-10-04 17:52:36 -0500 (Thu, 04 Oct 2012) | 10 lines

  chan_misdn: Remove some deadcode

  * Made setup_bc() static.

  Patches:
	patch1_unused-code.diff (license #6372) patch uploaded by Guenther Kelleter
	Modified

  JIRA ABE-2882

................
  r374516 | rmudgett | 2012-10-04 18:01:01 -0500 (Thu, 04 Oct 2012) | 7 lines

  chan_misdn: Remove unused bchan states

  Patches:
	patch2_unused-states.diff (license #6372) patch uploaded by Guenther Kelleter

  JIRA ABE-2882

................
  r374517 | rmudgett | 2012-10-04 18:17:51 -0500 (Thu, 04 Oct 2012) | 16 lines

  chan_misdn: Remove unnecessary null pointer checks and checks for stack->nt

  * cleanup_bc() is always called with valid bc (or it would've crashed
  before).

  * Value of stack->nt is known in advance at some places.

  * Rename handle_event() to handle_event_te(), handle_frm() to
  handle_frm_te().

  Patches:
	patch3_checks.diff (license #6372) patch uploaded by Guenther Kelleter
	Modified

  JIRA ABE-2882

................
  r374518 | rmudgett | 2012-10-04 18:21:59 -0500 (Thu, 04 Oct 2012) | 7 lines

  chan_misdn: Fix spelling in log messages

  Patches:
	patch4_spelling.diff (license #6372) patch uploaded by Guenther Kelleter

  JIRA ABE-2882

................
  r374519 | rmudgett | 2012-10-04 18:31:59 -0500 (Thu, 04 Oct 2012) | 15 lines

  chan_misdn: Don't cleanup a bc twice.

  In handle_frm_te() after calling misdn_lib_send_event(bc,
  EVENT_RELEASE_COMPLETE) bc is emptied, cleaned and set not in use,
  although misdn_lib_send_event() already did the same.  This is bad.  When
  it's not in use we are not allowed to touch it.

  * Moved log message in front of the resulting actions and fixed it to
  match the case.

  Patches:
	patch5_bccleanup.diff (license #6372) patch uploaded by Guenther Kelleter

  JIRA ABE-2882

................
  r374520 | rmudgett | 2012-10-04 18:43:56 -0500 (Thu, 04 Oct 2012) | 12 lines

  chan_misdn: Fix memory leaks, bc, chan not cleaned up etc., really bad stuff.

  * Fix return codes of cb_events() for EVENT_SETUP to use caller's cleanup
  mechanisms.

  * Move cl_queue_chan() call after bearer check.

  Patches:
	patch6_leaks.diff (license #6372) patch uploaded by Guenther Kelleter

  JIRA ABE-2882

................
  r374521 | rmudgett | 2012-10-04 18:48:38 -0500 (Thu, 04 Oct 2012) | 11 lines

  chan_misdn: We must initialize cause on sending a DISCONNECT.

  We must initialize cause on sending a DISCONNECT, so it is later correctly
  indicated to ast_channel in case the answer (RELEASE/RELEASE_COMPLETE)
  does not include one.

  Patches:
	patch7_hangupcause.diff (license #6372) patch uploaded by Guenther Kelleter

  JIRA ABE-2882

................
  r374522 | rmudgett | 2012-10-04 19:03:56 -0500 (Thu, 04 Oct 2012) | 7 lines

  chan_misdn: Remove unused code for upqueue

  Patches:
	patch8_unused-upqueue.diff (license #6372) patch uploaded by Guenther Kelleter

  JIRA ABE-2882

................
  r374523 | rmudgett | 2012-10-04 19:11:50 -0500 (Thu, 04 Oct 2012) | 7 lines

  chan_misdn: Improve debugging (port number, messages fixed, dups removed)

  Patches:
	patch9_debug.diff (license #6372) patch uploaded by Guenther Kelleter

  JIRA ABE-2882

................
  r374533 | rmudgett | 2012-10-05 12:17:18 -0500 (Fri, 05 Oct 2012) | 8 lines

  chan_misdn: Better debug: we can print_bc_info even if there's no ast leg.

  Patches:
	patch10_debug-bc-2.diff (license #6372) patch uploaded by Guenther Kelleter
	Modified.

  JIRA ABE-2882

................
  r374534 | rmudgett | 2012-10-05 12:34:10 -0500 (Fri, 05 Oct 2012) | 16 lines

  chan_misdn: setup_bc() is called too early for an incoming SETUP on TE.

  This prevents the B channel from being setup for HDLC mode when requested
  by the bearer capability and config option hdlc=yes.  It violates
  ETS300102 Ch.5.2.3.2: "The user, in any case, must not connect to the
  channel until a CONNECT ACKNOWLEDGE message has been received."

  * Call setup_bc() on receipt of CONNECT_ACKNOWLEGDE for PTMP, and on first
  response to SETUP for PTP.

  Patches:
	abe-2881-2.diff (license #6372) patch uploaded by Guenther Kelleter
	Modified.

  JIRA ABE-2881

................
  r374535 | rmudgett | 2012-10-05 12:41:05 -0500 (Fri, 05 Oct 2012) | 2 lines

  chan_misdn: Remove some more deadcode.

................
........

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

Merged revisions 374537 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 374538 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: http://svn.asterisk.org/svn/asterisk/trunk@374539 f38db490-d61c-443f-a65b-d21fe96a405b
Multiple revisions 374570,374581

........
  r374570 | dlee | 2012-10-05 15:14:41 -0500 (Fri, 05 Oct 2012) | 22 lines
  
  Improve AMI long line error handling
  
  In AMI's parser, when it receives a long line (> 1024 characters), it discards
  that line, but continues to process the message normally.
  
  Typically, this is not a problem because a) who has lines that long and b)
  usually a discarded line results in an invalid message. But if that line is
  specifying an optional field, then the message will be processed, you get a
  'Response: Success', but things don't work the way you expected them to.
  
  This patch changes the behavior when a line-too-long parse error occurs.
  
  * Changes the log message to avoid way-too-long (and truncated anyways) log
    messages
  * Adds a 'parsing' status flag to Response: Success
  * Sets parsing = MESSAGE_LINE_TOO_LONG if, well, a line is too long
  * Responds with an appropriate error if parsing != MESSAGE_OKAY
  
  (closes issue AST-961)
  Reported by: John Bigelow
  Review: https://reviewboard.asterisk.org/r/2142/
........
  r374581 | dlee | 2012-10-05 15:20:28 -0500 (Fri, 05 Oct 2012) | 1 line
  
  I've committed too much. Reverting part of r374570.
........

Merged revisions 374570,374581 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 374586 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 374587 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: http://svn.asterisk.org/svn/asterisk/trunk@374588 f38db490-d61c-443f-a65b-d21fe96a405b
Update documentation for MessageSend application/command's From field for XMPP

When using the channel technology agnostic application/AMI command MessageSend,
the "From" field is technically optional for the SIP channel driver.  However,
if being sent by the XMPP resource module (either res_xmpp or res_jabber), the
"From" field is necessary, and must correspond to a defined account.  This
patch updates the documentation for this application/AMI command to reflect
this.

(closes issue ASTERISK-20405)
Reported by: Leif Madsen
........

Merged revisions 374611 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: http://svn.asterisk.org/svn/asterisk/trunk@374612 f38db490-d61c-443f-a65b-d21fe96a405b
Handle capability stanzas that fail to provide node or version information

While XEP-0115 states that the node and ver attributes are both required, some
devices fail to provide either field.  Prior to this patch, failure to provide
the node or ver attribute would cause a crash in res_xmpp.  While failing to
provide the node or ver attribute is technically invalid, since this
information is not utilized by Asterisk except for reporting purposes, for
interoperability reasons, we continue to process the capability stanza anyways.

(closes issue ASTERISK-20495)
Reported by: Martin W
Tested by: Martin W
patches:
  20495.patch uploaded by Martin W (license #6434)
........

Merged revisions 374622 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: http://svn.asterisk.org/svn/asterisk/trunk@374623 f38db490-d61c-443f-a65b-d21fe96a405b
Trivial patch to make 'best_score' defined for all architectures.

Fixes trivial build error on Solaris:

  acl.c: In function `get_local_address':
  acl.c:196: error: `best_score' undeclared (first use in this function)
  acl.c:196: error: (Each undeclared identifier is reported only once
  acl.c:196: error: for each function it appears in.)
  make[2]: *** [acl.o] Error 1

(issue ASTERISK-20366)
Reported by: Ben Klang
Tested by: Ben Klang
patches:
  0002-main-acl.c-Trivial.-best_score-should-be-defined-for.patch by Shaun Ruffell (license 5417)
........

Merged revisions 374632 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: http://svn.asterisk.org/svn/asterisk/trunk@374633 f38db490-d61c-443f-a65b-d21fe96a405b
pjproject: Fix for Solaris builds. Do not undef s_addr.

pjproject, in order to solve build problems on Windows [1], undefines s_addr in
one of it's headers that is included in res_rtp_asterisk.c. On Solaris s_addr
is not a structure member, but defined to map to the real strucuture member,
therefore when building on Solaris it's possible to get build errors like:

    [CC] res_rtp_asterisk.c -> res_rtp_asterisk.o
    In file included from /export/home/admin/asterisk-11-svn/include/asterisk/stun.h:29,
                     from res_rtp_asterisk.c:51:
    /export/home/admin/asterisk-11-svn/include/asterisk/network.h: In function `inaddrcmp':
    /export/home/admin/asterisk-11-svn/include/asterisk/network.h:92: error: structure has no member named `s_addr'
    /export/home/admin/asterisk-11-svn/include/asterisk/network.h:92: error: structure has no member named `s_addr'
    res_rtp_asterisk.c: In function `ast_rtp_on_ice_tx_pkt':
    res_rtp_asterisk.c:706: warning: dereferencing type-punned pointer will break strict-aliasing rules
    res_rtp_asterisk.c:710: warning: dereferencing type-punned pointer will break strict-aliasing rules
    res_rtp_asterisk.c: In function `rtp_add_candidates_to_ice':
    res_rtp_asterisk.c:1085: error: structure has no member named `s_addr'
    make[2]: *** [res_rtp_asterisk.o] Error 1
    make[1]: *** [res] Error 2
    make[1]: Leaving directory `/export/home/admin/asterisk-11-svn'
    gmake: *** [_cleantest_all] Error 2

Unfortunately, in order to make this work, I also had to make sure pjproject
only used the typdef pj_in_addr and not the struct pj_in_addr so that when
building Asterisk I could "typedef struct in_addr pj_in_addr". It's possible
then that the library and users of those interfaces in Asterisk have a different
idea about the type of the argument, while on the surface it looks like they are
all 32 bit big endian values.

[1] http://trac.pjsip.org/repos/changeset/484

(issues ASTERISK-20366)
Reported by: Ben Klang
Tested by: Ben Klang, mjordan
patches:
  0001-pjproject-Fix-for-Solaris-builds.-Do-not-undef-s.patch uploaded by Shaun Ruffell (license 5417)
........

Merged revisions 374642 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: http://svn.asterisk.org/svn/asterisk/trunk@374643 f38db490-d61c-443f-a65b-d21fe96a405b
Resolve issues in ConfBridge regarding marked, waitmarked, and unmarked users

Thank's to Neil Tallim (flan)'s tireless testing, issue reporting, and patches
it became clear that app_confbridge had some complex logic in how it handled
interactions between marked, waitmarked, and unmarked users.  In particular,
there were some areas in which the interactions between the users resulted
in inconsistent behavior, and app_confbridge was missing logic in how to handle
some corner cases.  Some areas included:
 * Poor handling of mixing unmarked and waitmarked users
 * Inconsistencies in how MOH and muting was applied to various users
 * Handling of various announcements for different user profile options
flan's patches seem to fix the various issues, but highlighted how hard the
code could be to maintain.  In an attempt to make things easier to maintain and
to more fully enumerate the various cases that exist, this patch breaks up the
logic into a state machine-like setup.

Please note that the various state transitioned are documented on the Asterisk
wiki:

https://wiki.asterisk.org/wiki/display/AST/Confbridge+state+changes

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

Note that for the following issues, mjordan uploaded the patch, although it
was written by twilson.  Any contributor license discrepency is due to that.

(closes issue ASTERISK-19562)
Reported by: flan
Tested by: flan, mjordan, jrose
patches:
  bugASTERISK-19562_ASTERISK-19726_ASTERISK-20181.patch uploaded by twilson (license 6283)

(closes issue ASTERISK-19726)
Reported by: flan
Tested by: flan
patches:
  bugASTERISK-19562_ASTERISK-19726_ASTERISK-20181.patch uploaded by twilson (license 6283)

(closes issue ASTERISK-20181)
Reported by: Jonathan White
Tested by: Jonathan White
patches:
  bugASTERISK-19562_ASTERISK-19726_ASTERISK-20181.patch uploaded by twilson (license 6283)
........

Merged revisions 374652 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 374657 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: http://svn.asterisk.org/svn/asterisk/trunk@374658 f38db490-d61c-443f-a65b-d21fe96a405b
Disable ICE support by default

Since there are a number of legacy devices out there that fail to handle ICE
candidates properly (which is a nice way of saying something much uglier),
disable it by default.

Support for ICE candidates can be enabled in rtp.conf using the icesupport
setting.
........

Merged revisions 374676 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: http://svn.asterisk.org/svn/asterisk/trunk@374677 f38db490-d61c-443f-a65b-d21fe96a405b
Fix deletion of unopenable spool files.

If scan_service() cannot open the spool file, it logs a message saying
that it will delete the file and calls remove_from_queue() to do it.
However, remove_from_queue() fails to delete the spool file because struct
outgoing has not yet been fully initialized.

* Merged allocating a new struct outgoing and init_outgoing() into
new_outgoing().  Allocation is initialization.

* Made apply_outgoing() not initialize the spool filename in struct
outgoing.

* Made apply_outgoing() call ast_trim_blanks() and ast_skip_blanks()
rather than manually inlining them.

* Reduced indentation levels in apply_outgoing().

* Fixed a garbled comment in remove_from_queue().

* Reworked scan_service() to simplify it.

(closes issue ASTERISK-17231)
Reported by: David Chappell
Patches:
      spool_open_failure.diff (license #4997) patch uploaded by David Chappell
      Started with this patch.
........

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

* Fixed some memory leaks on off nominal paths in init_outgoing() when
merging into the new_outgoing() function dealing with o->capabilities.
........

Merged revisions 374695 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 374708 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: http://svn.asterisk.org/svn/asterisk/trunk@374717 f38db490-d61c-443f-a65b-d21fe96a405b
dahdi.conf.sample: Add description for "buffers" setting.

This contains an edited version of the patch originally uploaded by John
Bigelow.

(closes issue ASTERISK-14435)
Reported by: John Bigelow
Patches:
      buffers.patch (license #5091) patch uploaded by John Bigelow
      0001-dahdi.conf.sample-Add-description-for-buffers-settin.patch (license #5417) patch uploaded by Shaun Ruffell
      Modified
........

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

Merged revisions 374728 from http://svn.asterisk.org/svn/asterisk/branches/10
........

Merged revisions 374729 from http://svn.asterisk.org/svn/asterisk/branches/11


git-svn-id: http://svn.asterisk.org/svn/asterisk/trunk@374730 f38db490-d61c-443f-a65b-d21fe96a405b