res_rtp_asterisk & udptl: fix port selection to work with SELinux restrictions

ast_bind to a port reserved for another program by SELinux causes
errno == EACCES.  This caused random failures when binding rtp or
udptl sockets.  Treat EACCES as a non-fatal error, try next port.

(closes issue ASTERISK-23134)
Reported by: Corey Farrell
........

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

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/12@406935 f38db490-d61c-443f-a65b-d21fe96a405b
Skinny: fix up possible double unlock of chan.

Return before chan is possibly unlocked a second time when hanging up
a channel in SUBSTATE_OFFHOOK.


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/12@406987 f38db490-d61c-443f-a65b-d21fe96a405b
PJSIP: Fix address for ACK in NAT situations

In NAT scenarios where a call is placed to a Grandstream phone,
res_pjsip will sometimes send the ACK to a 200 OK to the private
address of the device behind the NAT instead of the address of the NAT
device. This corrects that behavior by rewriting the address in the
Contact header in the incoming 200 OK and the dialog's target address
if necessary (since it has already been rewritten to the incorrect
private address).

(closes issue ASTERISK-23106)
Review: https://reviewboard.asterisk.org/r/3168/
Reported by: Matt Jordan


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/12@407000 f38db490-d61c-443f-a65b-d21fe96a405b
res_pjsip_mwi: Subscribe fails when missing aor name

When subscribing to MWI (res_pjsip_mwi) and the sip uri did not contain a name
(ex: sip:<ip address>) then the subscription would fail since it would be unable
to locate an associated aor.  This patch makes it so that when a subscribe comes
with no aor name then it will subscribe to all aors on the located endpoint.

(closes issue ASTERISK-23072)
Reported by: Bob M
Review: https://reviewboard.asterisk.org/r/3164/


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/12@407014 f38db490-d61c-443f-a65b-d21fe96a405b
Decouple subscription handling from NOTIFY/PUBLISH body generation.

When the PJSIP pubsub framework was created, subscription handlers were required
to state what event they handled along with what body types they knew how to
generate. While this serves well when implementing a base RFC, it has problems
when trying to extend the body to support non-standard or proprietary body
elements. The code also was NOTIFY-specific, meaning that when the time comes
that we start writing code to send out PUBLISH requests with MWI or presence
bodies, we would likely find ourselves duplicating code that had previously been
written.

This changeset introduces the concept of body generators and body supplements. A
body generator is responsible for allocating a native structure for a given body
type, providing the primary body content, converting the native structure to a
string, and deallocating resources. A body supplement takes the primary body
content (the native structure, not a string) generated by the body generator and
adds nonstandard elements to the body. With these elements living in their own
module, it becomes easy to extend our support for body types and to re-use
resources when sending a PUBLISH request.

Body generators and body supplements register themselves with the pubsub core,
similar to how subscription and publish handlers had done. Now, subscription
handlers do not need to know what type of body content they generate, but they
still need to inform the pubsub core about what the default body type for a
given event package is. The pubsub core keeps track of what body generators and
body supplements have been registered. When a SUBSCRIBE arrives, the pubsub core
will check that there is a subscription handler for the event in the SUBSCRIBE,
then it will check that there is a body generator that can provide the content
specified in the Accept header(s).

Because of the nature of body generators and supplements, it means
res_pjsip_exten_state and res_pjsip_mwi have been completely gutted. They no
longer worry about body types, instead calling
ast_sip_pubsub_generate_body_content() when they need to generate a NOTIFY body.

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/12@407016 f38db490-d61c-443f-a65b-d21fe96a405b
alembic: script modifications due to errors

A couple of the scripts had errors that would not allow a full migration to
take place.  The extensions table needed to make its 'id' column a primary
key in order to work with mysql.  The other script ...add_endpoints... was
missing tables that it was trying to add columns to.

Added the primary key on id for extensions and added the tables in for the
missing pjsip configuration options.  While it is not ideal to modify already
released scripts this was a case where it had to be done due to errors in
the script and lacking a better alternative.

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/12@407019 f38db490-d61c-443f-a65b-d21fe96a405b
Add file that apparently got missed in the merge.



git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/12@407031 f38db490-d61c-443f-a65b-d21fe96a405b
res_pjsip_exten_state: Exporting global symbols caused load order issues

Removed the exportation of global symbols from the module as it is no longer
needed and it could potentially cause load problems as on some systems it
would try to load before res_pjsip_pubsub


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/12@407034 f38db490-d61c-443f-a65b-d21fe96a405b
res_pjsip: Config option to enable PJSIP logger at load time.

Added a "debug" configuration option for res_pjsip that when set to "yes"
enables SIP messages to be logged.  It is specified under the "system" type.
Also added an alembic script to add the option to realtime.

(closes issue ASTERISK-23038)
Reported by: Rusty Newton
Review: https://reviewboard.asterisk.org/r/3148/


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/12@407036 f38db490-d61c-443f-a65b-d21fe96a405b
app_dial: Allow macro/gosub pre-bridge execution to occur on priorities

The parsing for the destination of the macro/gosub uses the '^' character to
separate out context, extension, and priority. However, the logic for the
macro/gosub execution was written such that it would only do the actual
macro/gosub jump if a '^' character existed. This doesn't apply when the
macro/gosub jump occurs in a priority/priority label. This patch changes
the logic so that the parsing still occurs, but the jump will occur even
for priorities/priority labels.

(issue ASTERISK-23164)

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

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

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/12@407082 f38db490-d61c-443f-a65b-d21fe96a405b
CDRs: fix a variety of dial status problems, h/hangup handler creating CDRs

This patch fixes a number of small-ish problems that were noticed when
witnessing the records that the FreePBX dialplan produces:
(1) Mid-call events (as well as privacy options) have the ability to change the
    overall state of the Dial operation after the called party answers. This
    means that publishing the DialEnd event when the called party is premature;
    we have to wait for the execution of these subroutines to complete before
    we can signal the overall status of the DialEnd. This patch moves that
    publication and adds handlers for the mid-call events.
(2) The AST_FLAG_OUTGOING channel flag is cleared if an after bridge goto
    datastore is detected. This flag was preventing CDRs from being recorded
    for all outbound channels that had a 'continue' option enabled on them by
    the Dial application.
(3) The CDR engine now locks the 'Dial' application as being the CDR
    application if it detects that the current CDR has entered that app. This
    is similar to the logic that is done for Parking. In general, if we entered
    into Dial, then we want that CDR to record the application as such - this
    prevents pre-dial handlers, mid-call handlers, and other shenaniganry
    from changing the application value.
(4) The CDR engine now checks for the AST_SOFTHANGUP_HANGUP_EXEC in more places
    to determine if the channel is in hangup logic or dead. In either case, we
    don't want to record changes in the channel.
(5) The default option for "endbeforehexten" has been changed to "yes". In
    general, you don't want to see CDRs in the 'h' exten or in hangup logic.
    Since the semantics of that option changed in 12, it made sense to update
    the default value as well.
(6) Finally, because we now have the ability to synchronize on the messages
    published to the CDR topic, on shutdown the CDR engine will now synchronize
    to the messages currently in flight. This helps to ensure that all
    in-flight CDRs are written before shutting down.

(closes issue ASTERISK-23164)
Reported by: Matt Jordan

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/12@407084 f38db490-d61c-443f-a65b-d21fe96a405b
app_stack: protect against missing parameters to STACK_PEEK and LOCAL_PEEK

STACK_PEEK requires 2 parameters and LOCAL_PEEK requires 1 parameter.  This
protects against situations where those parameters are blank or missing by
logging an error and returning.

(closes issue ASTERISK-23220)
Reported by: James Sharp
........

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

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/12@407104 f38db490-d61c-443f-a65b-d21fe96a405b
res_stasis: Enable transfers and provide events when they occur.

This change enables transfers within ARI created bridges and adds events
for when they occur. Unlike other events these will be received if *any*
subscribed object is involved in the transfer.

(closes issue ASTERISK-22984)
Reported by: David M. Lee

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


git-svn-id: http://svn.asterisk.org/svn/asterisk/branches/12@407153 f38db490-d61c-443f-a65b-d21fe96a405b
cdrs: Check for applications to lock onto during dial begin handling

This patch brings CDR processing further in line with r407085. During some dial
operations, the application would not be locked to the Dial application and
would instead continue to show the previously known application. In particular,
this would occur when a Parked call would time out. This was due to a previous
snapshot already locking the application to Park - processing this in a Dial
Begin allows the Dial application to reassert its rightful place.

(CDRs. Ugh.)

But hooray for the Parked Call tests for catching this in the Asterisk Test
Suite.


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