#
# MSCs Illustrating NTA Usage
#

User Agent Client Initiating a Call
-----------------------------------

                    APP ¦ NTA
User                    ¦
Agent                   ¦
 |                      ¦
 | nta = nta_agent_create
 |- - - - - - - - - - - - - - - - -> NTA
 | (msg_cb, contact)    ¦           agent
 |                      ¦             |
 |                      ¦             |
 |- - ->Call            ¦             |
 |        |             ¦             |
 |        | leg = nta_leg_create      |
 |        |- - - - - - -¦- - - - - - -|- - - -> leg
 |        |(nta, leg_cb, ..., To, From, ... )    |
 |        |             ¦             |          |
 |        |             ¦             |          |
 |        | oreq = nta_outgoing_create|          |
 |        |- - - - - - -¦- - - - - - -|- - - - - | - - -> outgoing
 |        |       (leg, response_cb, INVITE, url, headers...) |
 |        |             ¦             |          |            |
 |        |             ¦             |          |	      | INVITE
 |        |             ¦             |          |	      |---->
 |        |             ¦             |          |            |
 |        |             ¦             |          |            | 100 Trying
 |        |             ¦             |          |            |<----
 |        |             ¦             |          |            |
 |        |             ¦             |          |            | 180 Ringing
 |        |             ¦             |      response_cb(180) |<----
 |  ALERT |<--------------------------|----------|------------|
 |<-------|             ¦             |          |            | 200 OK
 |        |             ¦             |      response_cb(200) |<----
 |OFFHOOK |<--------------------------|----------|------------|
 |<-------|             ¦             |          |            |
 |        | nta_outgoing_destroy      |          |            |
 |        |---------------------------|----------|----------->|
 |        |             ¦             |          |            X
 |        | nta_leg_destroy           |          |
 |        |---------------------------|--------->|
 |        |             ¦             |          X
 |        | leg = nta_leg_create      |
 |        |- - - - - - -¦- - - - - - -|- - - -> leg
 |        |(nta, leg_cb, ..., To+tag, From, ...) |
 |        |             ¦             |          |
 |        | oreq = nta_outgoing_create|          |
 |        |- - - - - - -¦- - - - - - -|- - - - - | - - -> outgoing
 |        | (leg, ..., ACK, url, headers)        |            |
 |        |             ¦             |          |            | ACK
 |        |             ¦             |          |            |---->
 |        | nta_outgoing_destroy      |          |            |
 |        |---------------------------|----------|----------->|
 |        |             ¦             |          |            X


User Agent Client Releasing a Call
-----------------------------------

                    APP ¦ NTA
User    Call            ¦            NTA        leg
Agent     |             ¦           agent        |
 |        |             ¦             |          |
 |ONHOOK  |             ¦             |          |
 |------->|             ¦             |          |
 |        |oreq = nta_outgoing_create |          |
 |        |- - - - - - -¦- - - - - - -|- - - - - | - - -> outgoing
 |        | (leg, ..., BYE, url, headers)        |            |
 |        |             ¦             |          |            | BYE
 |        |             ¦             |          |            |---->
 |        |             ¦             |          |            |
 |        |             ¦             |          |            | 180 Ringing
 |        |             ¦             |      response_cb(180) |<----
 |        |<--------------------------|----------|------------|
 |        |             ¦             |          |            | 200 OK
 |        |             ¦             |      response_cb(200) |<----
 |        |<--------------------------|----------|------------|
 |        |             ¦             |          |            |
 |        |nta_outgoing_destroy       |          |            |
 |        |---------------------------|----------|----------->|
 |        |             ¦             |          |            X
 |        |nta_leg_destroy            |          |
 |        |---------------------------|--------->|
 |        |             ¦             |          X
 |        X             ¦             |          


User Agent Server Accepting a Call
----------------------------------

                    APP ¦ NTA
User                  	¦	     NTA 
Agent                 	¦	    agent
 |                      ¦             |                INVITE
 |			¦             |<----------------------
 |                      ¦             |
 |                   msg_cb(leg, msg) |
 |<-----------------------------------|
 |                      ¦             |
 |- - -> Call           ¦             |
 |        | nta_msg_leg ¦             |
 |        |-------------------------->|- - - -> leg
 |        | (msg, request_cb)         |          |
 |        |             ¦             |          |- - - -> incoming
 |        | nta_leg_tag ¦             |          |            |
 |        |---------------------------|--------->|            |
 |        | (tag)       ¦             |          |            |
 |        |             ¦             |     request_cb(reply) |
 |        |<--------------------------|----------|------------|
 |        |             ¦             |          |            |
 |        | nta_incoming_bind(ireq, ack_cb)      |            |
 |        |---------------------------|----------|----------->|
 |        |             ¦             |          |            |
 |        | nta_incoming_reply(180)   |          |            |
 | ALERT  |---------------------------|----------|----------->| 180 Ringing
 |<-------|             ¦             |          |            |---->
 |        |             ¦             |          |            |
 |OFFHOOK |             ¦             |          |            |
 |------->| nta_incoming_reply        |          |            |
 |        |---------------------------|----------|----------->| 200 Ok
 |        | (200, sdp)  ¦             |          |            |---->
 |        |             ¦             |          |            |
 |        |             ¦             |          |            | ACK
 |        |             ¦             |          |ack_cb(ACK) |<----
 |        |<--------------------------|----------|------------|
 |        |             ¦             |          |            |
 |        | nta_incoming_destroy(ireq)|          |            |
 |        |---------------------------|----------|----------->|
 |        |             ¦             |          |            X


User Agent Server Receiving a Call Release
------------------------------------------

                    APP ¦ NTA
User    Call            ¦            NTA        leg
Agent     |             ¦           agent        |
 |        |             ¦             |          |              BYE
 |        |             ¦             |          |<------------------
 |        |             ¦             |          |
 |        |             ¦             |          |- - - -> Incoming
 |        |             ¦             |          |            |
 |        |             ¦             |     request_cb(reply) |
 | ONHOOK |<--------------------------|----------|------------|
 |<-------|             ¦             |          |            |
 |        | nta_incoming_reply(200)   |          |            |
 |        |---------------------------|----------|----------->| 200 Ok
 |        | (200, sdp)  ¦             |          |            |---->
 |        |             ¦             |          |            |
 |        | nta_incoming_destroy(ireq)|          |            |
 |        |---------------------------|----------|----------->|
 |        |             ¦             |          |            X
 |        |nta_leg_destroy            |          |
 |        |---------------------------|--------->|
 |        X             ¦             |          X