summaryrefslogtreecommitdiff
path: root/res
AgeCommit message (Collapse)Author
2015-06-22res_pjsip_outbound_registration.c: Misc code cleanups.Richard Mudgett
* Break some long lines. * Fix doxygen comment. Change-Id: I8f12ba6822f84d5e7bb575280270cd7e2fefb305
2015-06-18Resolve race conditions involving Stasis bridges.Mark Michelson
This resolves two observed race conditions. First, a bit of background on what the Stasis application does: 1a Creates a stasis_app_control structure. This structure is linked into a global container and can be looked up using a channel's unique ID. 2a Puts the channel in an event loop. The event loop can exit either because the stasis_app_control structure has been marked done, or because of some other factor, such as a hangup. In the event loop, the stasis_app_control determines if any specific ARI commands need to be run on the channel and will run them from this thread. 3a Checks if the channel is bridged. If the channel is bridged, then ast_bridge_depart() is called since channels that are added to Stasis bridges are always imparted as departable. 4a Unlink the stasis_app_control from the container. When an ARI command is received by Asterisk, the following occurs 1b A thread is spawned to handle the HTTP request 2b The stasis_app_control(s) that corresponds to the channel(s) in the request is/are retrieved. If the stasis_app_control cannot be retrieved, then it is assumed that the channel in question has exited the Stasis app or perhaps was never in Stasis in the first place. 3b A command is queued onto the stasis_app_control, and the channel's event loop thread is signaled to run the command. 4b While most ARI commands do nothing further, some, such as adding or removing channels from a bridge, will block until the command they issued has been completed by the channel's event loop. The first race condition that is solved by this patch involves a crash that can occur due to faulty detection of the channel's bridged status in step 3a. What can happen is that in step 2a, the event loop may run the ast_bridge_impart() function to asynchronously place the channel into a bridge, then immediately exit the event loop because the channel has hung up. In step 3a, we would detect that the channel was not bridged and would not call ast_bridge_depart(). The reason that the channel did not appear to be bridged was that the depart_thread that is spawned by ast_bridge_impart() had not yet started. That is the thread where the channel is marked as being bridged. Since we did not call ast_bridge_depart(), the Stasis application would exit, and then the channel would be destroyed Then the depart_thread would start up and try to manipulate the destroyed channel, causing a crash. The fix for this is to switch from using ast_channel_is_bridged() to checking the NULLity of ast_channel_internal_bridge_channel() to determine if ast_bridge_depart() needs to be called. The channel's internal bridge_channel is set when ast_bridge_impart() is called and is NULLed by the call to ast_bridge_depart(). If the channel's internal bridge_channel is non-NULL, then the channel must have been imparted into the bridge and needs to be departed, even if the actual bridging operation has not yet started. By departing the channel when necessary, the thread that is running the Stasis application will block until the bridge gives the okay that the depart_thread has exited. The second race condition that is solved by this patch involves a leak of HTTP handler threads. The problem was that step 2b would successfully retrieve a stasis_app_control structure. Then step 2a would exit the channel from the event loop due to a hangup. Steps 3a and 4a would execute, and then finally steps 3b and 4b would. The problem is that at step 4b, when attempting to add a channel to a bridge, the thread would block forever since the channel would never execute the queued command since it was finished with the event loop. This meant that the HTTP handling thread would be leaked, along with any references that thread may have owned (in my case, I was seeing bridges leaked). The fix for this is to hone in better on when the channel has exited the event loop. The stasis_app_control structure has an is_done field that is now set at each point where the channel may exit the event loop. If step 2b retrieves a valid stasis_app_control structure but the control is marked as done, then the attempted operation exits immediately since there will be nothing to service the attempted command. ASTERISK-25091 #close Reported by Ilya Trikoz Change-Id: If66265b73b4c9f8f58599124d777fedc54576628
2015-06-16Parking: Add documentation for AMI ParkedCallSwap event.Mark Michelson
This event was added some time ago in order to clarify when a channel took the place of another channel in a parking lot. However, there was no XML documentation added for the event. This patch adds the XML documentation. ASTERISK-24900 #close Reported by Rusty Newton Change-Id: I4cfe7777c4b94bbff91c9221c6096a7a02a92eac
2015-06-15res_pjsip: Add option to force G.726 to be treated as AAL2 packed.Kevin Harwell
Some phones send g.726 audio packed for AAL2, which differs from what is recommended by RFC 3351. If Asterisk receives audio formatted as such when negotiating g.726 then it sounds a bit distorted. Added an option to res_pjsip_endpoint that allows g.726 negotiated audio to be treated as g.726 AAL2 packed. ASTERISK-25158 #close Reported by: Steve Pitts Change-Id: Ie7e21f75493d7fe53e75e12c971e72f5afa33615
2015-06-10res_pjsip_transport_websocket: Fix use-after-free bugs.Ivan Poddubny
This patch fixes use-after-free bugs caught by AddressSanitizer. 1. PJSIP transport manager may decide to destroy transport on its own. For example, when the contact registered via websocket has not renewed its registration in time. The transport was destoyed, but the websocket listener thread was still active until the socket closes, and then tried to call transport_shutdown on transport that has been freed. Also, the transport destructor accessed wstransport->rdata.tp_info.pool right after freeing memory that contained wstransport itself. This patch converts transport to an ao2 object, allowing it to be refcounted, so that it is available until both websocket listener and pjsip transport manager are finished with it. 2. The websocket listener deletes the last reference on websocket session when the tcp connection is closed, and it gets destroyed, but the transport manager may still use it, for example when disconnect happens in the middle of a SIP transaction. A new reference to websocket session has been added that is released with the transport to prevent this. ASTERISK-25096 #close Reported by: Josh Kitchens ASTERISK-24963 #close Reported by: Badalian Vyacheslav Change-Id: Idc0b63eb6e459c1ddfb2430127d34b3c4d8d373b
2015-06-05Merge "Fixes for OS X" into 13Joshua Colp
2015-06-03res_pjsip: Prevent access of NULL channels.Mark Michelson
It is possible to receive incoming requests or responses after the channel on an ast_sip_session has been destroyed and NULLed out. Handlers of these sorts of requests or responses need to be prepared for the possibility that the channel is NULL or else they could cause a crash. While several places have been amended to deal with NULL channels, there were still a couple of places that needed updating. res_pjsip_dtmf_info.c: When handling incoming INFO requests, we need to return early if there is no channel on the session. res_pjsip_session.c: When handling a 302 response, we need to stop the redirecting attempt if there is no channel on the session. ASTERISK-25148 #close reported by Mark Michelson Change-Id: Id1a75ffc3d0eaa168b0b28188fb54d6cf9fc47a9
2015-06-03res_pjsip/location: Fix ref leak in contact_apply_handlerGeorge Joseph
contact_apply_handler calls ast_res_pjsip_find_or_create_contact_status to force the creation of a contact_status object whenever a new contact is added but it didn't unref the returned object. Added an ao2_cleanup(status) to plug the leak. ASTERISK-25141 Change-Id: Icc1401cae142855a1abc86ab5179dfb3ee861c40 Reported-by: Corey Farrell
2015-06-02Fixes for OS XDavid M. Lee
* Add some type casting so tv_usec can really be a long, instead of some strange platform specific type. * Add some .dylib style files to .gitignore. * Switch from using -Xlinker to -Wl,. For [reasons unknown][], newer versions of GCC, when compiling the Homebrew formula for Asterisk, are not properly passing the -Xlinker options to the linker. Given that -Wl, does exactly the [same thing][], and does it properly, this patch changes the -Xlinker options to use -Wl, instead. [reasons unknown]: http://bit.ly/1SUbEYx [same thing]: https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html Change-Id: Id5e6b3c6cc86282ea5fca630dc3991137c5bf4dd
2015-06-02Merge "res_pjsip_session: Fix in-dialog authentication." into 13Matt Jordan
2015-06-01pjsip_configuration: Fix leak in persistent_endpoint_update_state.Corey Farrell
The loop to find the first available contact of an endpoint grabbed contact from the iterator, then checked for offline state. This caused the first contact after the state was found to leak a reference. ASTERISK-25141 Change-Id: Id0f1d87410fc63742db0594eb4b18b36e99aec08
2015-05-29res_pjsip/location: Fix memory leak in permanent_uri_handlerGeorge Joseph
When permanent_uri_handler was creating the contact status object for each contact, it wasn't unreffing it at the end of the loop. ASTERISK-25141 #close Reported-by: Corey Farrell Change-Id: I7bb127994677bb3d459f87952f8425c9b9967b12
2015-05-27res_pjsip_session: Fix in-dialog authentication.Richard Mudgett
When the remote peer requires authentication for in-dialog requests then re-INVITEs to the peer cause the call to be disconnected and other in-dialog requests to the peer like MESSAGE just don't go through. * Made session_inv_on_tsx_state_changed() handle in-dialog authentication for re-INVITEs and other methods. Initial INVITEs cannot be handled here because the INVITE transaction must be restarted earlier. * Pulled needed code from res/res_pjsip/pjsip_outbound_auth.c in preparation for removing the file. The generic outbound authentication code did not work as well as anticipated. * Created outbound_invite_auth() to only handle initial outbound INVITEs. Re-INVITEs cannot be handled here. The re-INVITE transaction is still in progress and the PJSIP library cannot handle the overlapping INVITE transactions. Other method types should not be handled here as this code only works on outgoing calls and we need to handle incoming and outgoing calls. ASTERISK-25131 #close Reported by: Richard Mudgett Change-Id: I12bdd7ddccc819b4ce4b091e826d1e26334601b0
2015-05-26res_pjsip: Add AMI events for chan_pjsip contact lifecycle changesGeorge Joseph
Add a new ContactStatus AMI event. Publish the following status/state changes: Created Removed Reachable Unreachable Unknown Contact URI, new status/state, aor and endpoint names, and the last qualify rtt result are included in the event. ASTERISK-25114 #close Change-Id: Id25aae5f7122facba183273efb3e8f36c20fb61e Reported-by: George Joseph <george.joseph@fairview5.com> Tested-by: George Joseph <george.joseph@fairview5.com>
2015-05-24Merge "Stasis: Fix unsafe use of stasis_unsubscribe in modules." into 13Matt Jordan
2015-05-23res_pjsip_transport_websocket: Fix crash on receiving large SIP packetsIvan Poddubny
Incoming SIP packets larger than PJSIP_MAX_PKT_LEN were themselves truncated before passing to pjsip_tpmgr_receive_packet, but the length was passed unaltered, thus causing memory corruption and segfault. ASTERISK-25122 #close Change-Id: I608a6b6b7f229eacc33a0a7d771d18e27e5b08ab
2015-05-22Stasis: Fix unsafe use of stasis_unsubscribe in modules.Corey Farrell
Many uses of stasis_unsubscribe in modules can be reached through unload. These have been switched to stasis_unsubscribe_and_join. Some subscription callbacks do nothing, for these I've created a noop callback function in stasis.c. This is used by some modules that monitor MWI topics in order to enable cache, since the callback does not become invalid after dlclose it is safe to use stasis_unsubscribe on these, even during module unload. ASTERISK-25121 #close Change-Id: Ifc2549fbd8eef7d703c222978e8f452e2972189c
2015-05-22Merge "res/res_pjsip_pubsub: Note that 'dialog' is also a valid event type ↵Matt Jordan
for RLS" into 13
2015-05-22Merge "res/res_pjsip_exten_state: Fix confusing NOTICE message" into 13Matt Jordan
2015-05-22res/res_pjsip_pubsub: Note that 'dialog' is also a valid event type for RLSMatt Jordan
In addition to specifying lists of 'presence' and 'message-summary', users can also create lists of type 'dialog'. These should be treated in the same fashion as 'presence'. Change-Id: I583bb69cd9f88b0b29bf09ddaddeac4e84189f6e
2015-05-22res/res_pjsip_exten_state: Fix confusing NOTICE messageMatt Jordan
When a SUBSCRIBE request is made to a dialplan hint that doesn't exist, the current NOTICE message informing users of this swaps the context and extension parameters. This can cause a bit of confusion. Thanks to CptBurger in #asterisk for helping to point this out. Change-Id: Ie584d1a58ae217385c87a450ca25b55ca0e36e43
2015-05-22Merge "res/ari: Register Stasis application on WebSocket attempt" into 13Matt Jordan
2015-05-22res/ari: Register Stasis application on WebSocket attemptMatt Jordan
Prior to this patch, when a WebSocket connection is made, ARI would not be informed of the connection until after the WebSocket layer had accepted the connection. This created a brief race condition where the ARI client would be notified that it was connected, a channel would be sent into the Stasis dialplan application, but ARI would not yet have registered the Stasis application presented in the HTTP request that established the WebSocket. This patch resolves this issue by doing the following: * When a WebSocket attempt is made, a callback is made into the ARI application layer, which verifies and registers the apps presented in the HTTP request. Because we do not yet have a WebSocket, we cannot have an event session for the corresponding applications. Some defensive checks were thus added to make the application objects tolerant to a NULL event session. * When a WebSocket connection is made, the registered application is updated with the newly created event session that wraps the WebSocket connection. ASTERISK-24988 #close Reported by: Joshua Colp Change-Id: Ia5dc60dc2b6bee76cd5aff0f69dd53b36e83f636
2015-05-22Merge "res_pjsip: Refactor endpt_send_transaction (qualify_timeout)" into 13Joshua Colp
2015-05-22Merge "res_pjsip_outbound_registration: Check request URI for line." into 13Matt Jordan
2015-05-22res_pjsip: Refactor endpt_send_transaction (qualify_timeout)George Joseph
This patch refactors the transaction timeout processing to eliminate calling the lower level public pjsip functions and reverts to calling pjsip_endpt_send_request again. This is the result of me noticing a possible incompatibility with pjproject-2.4 which was causing contact status flapping. The original version of this feature used the lower level calls to get access to the tsx structure in order to cancel the transaction when our own timer expires. Since we no longer have that access, if our own timer expires before the pjsip timer, we call the callbacks and just let the pjsip transaction take it's own course. When the transaction ends, it discovers the callbacks have already been run and just cleans itself up. A few messages in pjsip_configuration were also added/cleaned up. ASTERISK-25105 #close Change-Id: I0810f3999cf63f3a72607bbecac36af0a957f33e Reported-by: George Joseph <george.joseph@fairview5.com> Tested-by: George Joseph <george.joseph@fairview5.com>
2015-05-22res_pjsip_outbound_registration: Check request URI for line.demon-ru
When an inbound call is received the To header is checked for the "line" option. Some remote servers will place this in the request URI instead. This adds an additional check for the option in the request URI. ASTERISK-25072 #close Reported by: Dmitriy Serov Change-Id: Id4e44debbb80baad623b914a88574371575353c8
2015-05-21res_mwi_external_ami: Use module version of AMI registration.Corey Farrell
Use ast_manager_register_xml for res_mwi_external_ami manager actions. This ensures the module is held open while any of the actions are being run. ASTERISK-25117 #close Reported by: Corey Farrell Change-Id: Iececfdc2da498b2c32b9e09042f5f12292007ac7
2015-05-19res/res_http_websocket: Add a pre-session established callbackMatt Jordan
This patch updates http_websocket and its corresponding implementation with a pre-session established callback. This callback allows for WebSocket server consumers to be notified when a WebSocket connection is attempted, but before we accept it. Consumers can choose to reject the connection, if their application specific logic allows for it. As a result, this patch pulls out the previously private websocket_protocol struct and makes it public, as ast_websocket_protocol. In order to preserve backwards compatibility with existing modules, the existing APIs were left as-is, and new APIs were added for the creation of the ast_websocket_protocol as well as for adding a sub-protocol to a WebSocket server. In particular, the following new API calls were added: * ast_websocket_add_protocol2 - add a protocol to the core WebSocket server * ast_websocket_server_add_protocol2 - add a protocol to a specific WebSocket server * ast_websocket_sub_protocol_alloc - allocate a sub-protocol object. Consumers can populate this with whatever callbacks they wish to support, then add it to the core server or a specified server. ASTERISK-24988 Reported by: Joshua Colp Change-Id: Ibe0bbb30c17eec6b578071bdbd197c911b620ab2
2015-05-15res_pjsip_config_wizard/config: Fix template processingGeorge Joseph
The config wizard was always pulling the first occurrence of a variable from an ast_variable list but this gets the template value from the list instead of any overridden value. This patch creates ast_variable_find_last_in_list() in config.c and updates res_pjsip_config_wizard to use it instead of ast_variable_find_in_list. Now the overridden values, where they exist, are used instead of template variables. Updated test_config to test the new API. ASTERISK-25089 #close Reported-by: George Joseph <george.joseph@fairview5.com> Tested-by: George Joseph <george.joseph@fairview5.com> Change-Id: Ifa7ddefc956a463923ee6839dd1ebe021c299de4
2015-05-13res_rtp_asterisk: Correction for the limit which detects that a packet is DTLS.Yousf Ateya
First byte of DTLS packet shall be in range 20-63, not 20-64. Refer to RFC https://tools.ietf.org/html/rfc5764#section-5.1.2 for correct values. Change-Id: Iae6fa0d72b37c36a27fe40686e0ae6fba3afec31
2015-05-08res_rtp_asterisk: Issue ERROR if res_srtp is not found.Sean Bright
While trying to get WebRTC working with chan_pjsip, I was running into the following error: Attempted to set an invalid DTLS-SRTP configuration on RTP instance... Josh helpfully pointed out that res_srtp.so might not be loaded, and sure enough, it wasn't. This patch adds a ERROR indiciating as much to hopefully help others having a similar problem. Change-Id: I13aa477b47b299876728a21b130998a0ea6cd19f
2015-05-07res_pjsip_exten_state: Fix race condition between sending NOTIFY and terminationJoshua Colp
The res_pjsip_exten_state module currently has a race condition between processing the extension state callback from the PBX core and processing the subscription shutdown callback from res_pjsip_pubsub. There is currently no synchronization between the two. This can present a problem as while the SIP subscription will remain valid the tree it points to may not. This is in particular a problem as a task to send a NOTIFY may get queued which will try to use the tree that may no longer be valid. This change does the following to fix this problem: 1. All access to the subscription tree is done within the task that sends the NOTIFY to ensure that no other thread is modifying or destroying the tree. This task executes on the serializer for the subscriptions. 2. A reference to the subscription serializer is kept to ensure it remains valid for the lifetime of the extension state subscription. 3. The NOTIFY task has been changed so it will no longer attempt to send a NOTIFY if the subscription has already been terminated. ASTERISK-25057 #close Reported by: Matt Jordan Change-Id: I0b3cd2fac5be8d9b3dc5e693aaa79846eeaf5643
2015-05-06res_stasis_snoop: Spying on a single direction continually increases CPUKevin Harwell
Creating a snoop channel in ARI and spying only on a single direction (in or out) results in CPU utilization continually increasing until the CPU is fully consumed. This occurs because frames are being put in the opposing direction's slin factory queue, but not being removed. Fixed the problem by always reading and disposing of frames from the opposite queue of the direction selected. ASTERISK-24938 #closes Change-Id: I935bfd15f1db958f364d9d6b3b45582c0113dd60
2015-05-05res_ari_bridges: Add missing dependencies.Corey Farrell
Missed this module in the previous commit. res_ari_bridges uses symbols from res_stasis_playback and res_stasis_recording. ASTERISK-25027 #close Reported by: Corey Farrell Change-Id: I90bf756abd25adfc4920d2869ebe7feb636b8c5f
2015-05-04Merge "res_odbc: Use negative connection cache for all connections" into 13Matt Jordan
2015-05-04res_odbc: Use negative connection cache for all connectionsMartin Tomec
Apply the negative connection cache setting to all connections, even those that are not pooled. This ensures that the connection will not be re-established before the negative connection cache time is met. ASTERISK-22708 #close Change-Id: I431cc2e8584ab0b6908b3523d0a0e18c9a527271
2015-05-02res_pjsip_dlg_options: Fix MODULEINFO section.Corey Farrell
Removed the extra space before "MODULEINFO" in res_pjsip_dlg_options. This extra space prevented any of the dependencies from being seen by menuselect, so building with default options would fail if PJSIP was not installed. This also makes the tool that extracts information for menuselect tolerant of multiple spaces in the future. ASTERISK-25033 #close Reported by: Peter Whisker Change-Id: Iccd54846f70c4a7a50cb5bf70b7bb5cb4bab3698
2015-05-01Merge "res_pjsip_outbound_authenticator_digest: Add missing outbound ↵Matt Jordan
authenticator callback." into 13
2015-04-30res_pjsip_outbound_authenticator_digest: Add missing outbound authenticator ↵Mark Michelson
callback. The Asterisk 13 version of the fix for outbound registration was missing a key component that set the outbound authenticator's callback that creates an authenticated request based on an old request. This was picked up by some outbound registration tests failing in the testsuite. Change-Id: I5ca9379698c606da36bc38eaffccedaf64211ce3
2015-04-30res_ari_device_states: Fix dependency on res_stasis_device_state.Joshua Colp
The res_ari_device_states module depends on res_stasis_device_state, not res_stasis_device_states. Change-Id: I26e02ad37f9e36bcc859867e2fad1b90452ec3de
2015-04-30Merge "res_pjsip_outbound_registration: Add virtual line support." into 13Matt Jordan
2015-04-30res_pjsip_outbound_registration: Fix double unref on error return.Joshua Colp
When the PJSIP pjsip_regc_send function is invoked and an error status returned the caller currently decrements the reference count of the client state that it just incremented, assuming the registration callback would not have been invoked. In practice this is not correct. If the failure happens after the transaction has been set up the callback will still be invoked. This will cause the reference count to be incorrectly decremented twice, once by the registration callback and second by the caller of pjsip_regc_send. This change makes it so that whether the callback is invoked or not is known by the caller of pjsip_regc_send. Depending on this it can know whether it is responsible for decrementing the reference count of the client state or not. ASTERISK-25037 #close Reported by: Joshua Colp Change-Id: I749dc12f3a22115c49c5d7d95ff42a5fa45319de
2015-04-29Merge "ARI: Fix missing dependencies." into 13Matt Jordan
2015-04-29res_fax: allow 2400 transmission rate according to v.27ter standardKevin Harwell
A previous set of patches (see: ASTERISK-22790 & ASTERISK-23231) made it so a v.27 modem was not allowed to have a minimum transmission rate of 2400 bits per second. This reverts all or some of those patches since according to the v.27ter standard a rate of 2400 bits per second is also supported. One of the original patches also added 9600 bits per second support for v.27. This patch also removes that since v.27ter only supports 2400/4800 bits per second. Also, since Asterisk specifically supports v.27ter the enum was renamed to better reflect this. ASTERISK-24955 #close Reported by: Matt Jordan Change-Id: I4b9dfb6bf7eff08463ab47ee1a74224f27cae733
2015-04-29res_sorcery_config: Fix build issue due to syntax error.Joshua Colp
Change-Id: Ic8322f04e37842848ad72cf2871bd0378f67c4ac
2015-04-29chan_pjsip: Creating Channel Causes Asterisk to Crash When Duplicate AORAshley Sanders
Sections Exist in pjsip.conf This patch modifies the current loading strategy of the pjsip configuration. If duplicate sections (e.g. sections containing the same [id/type]) are defined in [pjsip.conf], the loader will consider the configuration for the given type as invalid when the duplicate section is encountered. The entire configuration (including what was previously loaded) for the duplicate [id/type] sections will be rejected and destroyed, an error message is logged and the load processing for the given stops. ASTERISK-24996 Reported By: Ashley Sanders Change-Id: I35090ca4cd40f1f34881dfe701a329145c347aef
2015-04-29res_pjsip_outbound_registration: Add virtual line support.Joshua Colp
Virtual line support establishes a relationship between messages related to an outbound registration and a local endpoint. This is accomplished by attaching a parameter to the Contact of the outbound registration and looking for it on any received requests. If the parameter exists and can be matched to an outbound registration the configured endpoint is associated with the request. ASTERISK-24949 #close Reported by: Joshua Colp Change-Id: I7df909d2625479110a83fdd354c21ac539e8615d
2015-04-29ARI: Fix missing dependencies.Corey Farrell
ARI modules that are generated by 'make ari-stubs' are all dependent on res_ari_model. Additionally some of the same modules depend on one or more res_stasis_* modules. ASTERISK-25027 #close Reported by: Corey Farrell Change-Id: I8e07fe7e81fedacb87232f2b6f8b5f47927b4153
2015-04-29res_pjsip: Remove incorrect MODULEINFO from presence_xml.c.Corey Farrell
Remove incorrect MODULEINFO block and unneeded header includes from presence_xml.c. ASTERISK-25027 Reported by: Corey Farrell Change-Id: I977c609ab9d1fe05373027c4138900f6985990eb