summaryrefslogtreecommitdiff
path: root/res/res_pjsip/pjsip_options.c
AgeCommit message (Collapse)Author
2017-12-07pjsip_options: dynamic contact's fields not updated on reloadKevin Harwell
Dynamic contacts were not being properly updated on reload. As a matter of fact any changes to the AOR that a dynamic contact was associated with were not being applied. On reload, this patch makes it so for each dynamic contact, the associated AOR is now retrieved and the AOR's fields are applied to the contact. ASTERISK-27467 Change-Id: I8e3165dc6a745218c1c9db837f77fafa0516985d
2017-02-27res_pjsip: Fix crash when contact has no statusJørgen H
This change fixes an assumption in res_pjsip that a contact will always have a status. There is a race condition where this is not true and would crash. The status will now be unknown when this situation occurs. ASTERISK-26623 #close Change-Id: Id52d3ca4d788562d236da49990a319118f8d22b5
2017-02-08Revert "Update qualifies when AOR configuration changes."Mark Michelson
This reverts commit 6492e91392b8fd394193e411c6eb64b45486093f. The change in question was intended to prevent the need to reload in order to update qualifies on contacts when an AOR changes. However, this ended up causing a deadlock instead. Change-Id: I1a835c90a5bb65b6dc3a1e94cddc12a4afc3d71e
2017-02-01Update qualifies when AOR configuration changes.Mark Michelson
Prior to this change, qualifies would only update in the following cases: * A reload of res_pjsip.so was issued. * A dynamic contact was re-registered after its AOR's qualify_frequency had been changed This does not work well if you are using realtime for your AORs. You can update your database to have a new qualify_frequency, but the permanent contacts on that AOR will not have their qualifies updated. And the dynamic contacts on that AOR will not have their qualifies updated until the next registration, which could be a long time. This change seeks to fix this problem by making it so that whenever AOR configuration is applied, the contacts pertaining to that AOR have their qualifies updated. Additions from this patch: * AOR sorcery objects now have an apply handler that calls into a newly added function in the OPTIONS code. This causes all contacts associated with that AOR to re-schedule qualifies. * When it is time to qualify a contact, the OPTIONS code checks to see if the AOR can still be retrieved. If not, then qualification is canceled on the contact. Alterations from this patch: * The registrar code no longer updates contact's qualify_frequence and qualify_timeout. There is no point to this since those values already get updated when the AOR changes. * Reloading res_pjsip.so no longer calls the OPTIONS initialization function. Reloading res_pjsip.so results in re-loading AORs, which results in re-scheduling qualifies. Change-Id: I2e7c3316da28f389c45954f24c4e9389abac1121
2016-12-09Merge "res_pjsip: Fix 'A = B != C' kind."Joshua Colp
2016-12-08res_pjsip: Fix 'A = B != C' kind.Badalyan Vyacheslav
Consider reviewing the expression of the 'A = B != C' kind. The expression is calculated as following: 'A = (B != C)' Change-Id: Ibaa637dfda47d51a20e26069d3103e05ce80003d
2016-12-07res_pjsip_registrar: AMI Add RegistrationInboundContactStatuses commandGeorge Joseph
The PJSIPShowRegistrationsInbound AMI command was just dumping out all AORs which was pretty useless and resource heavy since it had to get all endpoints, then all aors for each endpoint, then all contacts for each aor. PJSIPShowRegistrationInboundContactStatuses sends ContactStatusDetail events which meets the intended purpose of the other command and has significantly less overhead. Also, some additional fields that were added to Contact since the original creation of the ContactStatusDetail event have been added to the end of the event. For compatibility purposes, PJSIPShowRegistrationsInbound is left intact. ASTERISK-26644 #close Change-Id: I326f12c9ecb52bf37ba03f0748749de4da01490a
2016-09-09res_pjsip: Add ignore_uri_user_options option.Richard Mudgett
This implements the chan_sip legacy_useroption_parsing option but with a better name. * Made the caller-id number and redirecting number strings obtained from incoming SIP URI user fields always truncated at the first semicolon. People don't care about anything after the semicolon showing up on their displays even though the RFC allows the semicolon. ASTERISK-26316 #close Reported by: Kevin Harwell Change-Id: Ib42b0e940dd34d84c7b14bc2e90d1ba392624f62
2016-08-30res_pjsip: qualify/unqualify added/deleted realtime endpointsAlexei Gradinari
If the PJSIP endpoint's AOR with the permanent contact was deleted from the realtime storage the res_pjsip module continues trying to qualify this contact. The error 'Unable to find an endpoint to qualify contact' appeares every 'qualify_frequency' seconds. This patch deletes this contact in this case. The PJSIP endpoint's AOR with the permanent contact is never qualified if it is added to realtime storage after asterisk started. This patch adds qualifying for the AOR's permanent contacts on the first handling of this AOR. ASTERISK-26319 #close Change-Id: Ib93dded9121edb113076903d1aa95402f799f8fe
2016-07-13pjsip_options.c: Fix container operation.Richard Mudgett
aor_observer_deleted() needs to operate on all contacts found for the deleted AOR instead of only the first one found. This is really only a problem if there is more than one contact for the AOR. Change-Id: Id24ac0d5e8c931330231fb45dd2a331a84339dc1
2016-07-12res_pjsip: Fix statsd regression.Richard Mudgett
The ASTERISK-25904 change-id I8fad8aae9305481469c38d2146e1ba3a56d3108f patch introduced several regressions when the newly created "Updated" state goes out for each endpoint registration refresh. 1) It restarted any OPTIONS RTT ping cycle. 2) It would interfere with a currently active ping and throw off that ping's resulting RTT calculation. 3) It cleared the RTT time each time the endpoint was refreshed. 4) The cleared RTT time was sent out as a statsd update each time. 5) It created two AMI events for each update. * Revert the original patch and reimplement it. Now the current contact status state is re-sent instead of the state being momentarily toggled every time the endpoint refreshes its registration. The statsd events are not created for the re-sent refresh because they are sent after every OPTIONS ping. ASTERISK-26160 #close Reported by: Matt Jordan Change-Id: Ie072be790fbb2a8f5c1c874266e4143fa31f66d1
2016-06-22res_pjsip: improve realtime performance #2Alexei Gradinari
The patch removes updating all Endpoints' status on startup. Instead, only non-qualified aors with static contact and non-qualified non-expired contacts are retrieved from the realtime to update the endpoint status to ONLINE. The endpoint name was added to the contact object to simply find the endpoint that created this contact. The status of endpoints with qualified aors will be updated by 'qualify' functions. ASTERISK-26061 #close Change-Id: Id324c1776fa55d3741e0c5457ecac0304cb1a0df
2016-06-09sorcery: Add setting object type congestion levels.Richard Mudgett
Sorcery creates taskprocessors for object types to process object observer callbacks. An API call is needed to be able to set the congestion levels of these taskprocessors for selected object types. * Updated PJSIP's contact and contact_status sorcery object type observer default congestion levels based upon stress testing. Increased the congestion levels to reduce the potential for bursty register/unregister and subscribe/unsubscribe activity from triggering the taskprocessor overload alert. ASTERISK-26088 Reported by: Richard Mudgett Change-Id: I4542e83b556f0714009bfeff89505c801f1218c6
2016-05-26res_pjsip: add "via_addr", "via_port", "call_id" to contactAlexei Gradinari
As res_pjsip_nat rewrites contact's address, only the last Via header can contain the source address of registered endpoint. Also Call-Id header may contain the source address of registered endpoint. Added "via_addr", "via_port", "call_id" to contact. Added new fields ViaAddress, CallID to AMI event ContactStatus. ASTERISK-26011 Change-Id: I36bcc0bf422b3e0623680152d80486aeafe4c576
2016-05-05res_pjsip: improve realtime performanceAlexei Gradinari
This patch modified pjsip_options to retrieve only permament contacts for aor if the qualify_frequency is > 0 and persisted contacts if the qualify_frequency is > 0. This patch also fixed a bug in res_sorcery_astdb. res_sorcery_astdb doesn't save object data retrived from astdb. ASTERISK-25826 Change-Id: I1831fa46c4578eae5a3e574ee3362fddf08a1f05
2016-05-03res_pjsip/AMI: add contact.updated eventAlexei Gradinari
With the old SIP module AMI sends PeerStatus event on every successfully REGISTER requests, ie, on start registration, update registration and stop registration. With PJSIP AMI sends ContactStatus only when status is changed. Regarding registration: on start registration - Created on stop registration - Removed but on update registration nothing This patch added contact.updated event. ASTERISK-25904 Change-Id: I8fad8aae9305481469c38d2146e1ba3a56d3108f
2016-04-11res_pjsip: Add headers to AMI Event ContactStatusDetailAlexei Gradinari
* Added Useragent and RegExpire headers to AMI Event ContactStatusDetail with associated documentation. ASTERISK-25903 #close Change-Id: If3d121e943e588d016ba51d4eb9c6a421a562239
2016-03-30Merge "res_pjsip/pjsip_options: Fix From generation on outgoing OPTIONS"zuul
2016-03-28res_pjsip/pjsip_options: Fix From generation on outgoing OPTIONSGeorge Joseph
No one seemed to notice but every time an OPTIONS goes out, it goes out with a From of "asterisk" (or whatever the default from_user is set to), even if you specify an endpoint. The issue had several causes... qualify_contact is only called with an endpoint if called from the CLI. If the endpoint is NULL, qualify_contact only looks up the endpoint if authenticate_qualify=yes. Even then, it never passes it on to ast_sip_create_request where the From header is set. Therefore From is always "asterisk" (or whatever the default from_user is set to). Even if ast_sip_create_request were to get an endpoint, it only sets the From if endpoint->from_user is set. The fix is 4 parts... First, create_out_of_dialog_request was modified to use the endpoint id if endpoint was specified and from_user is not set. Second, qualify_contact was modified to always look up an endpoint if one wasn't specified regardless of authenticate_qualify. It then passes the endpoint on to create_out_of_dialog_request. Third (and most importantly), find_an_endpoint was modified to find an endpoint by using an "aors LIKE %contact->aor%" predicate with ast_sorcery_retrieve_by_fields. As such, this patch will only work if the sorcery realtime optimizations patch goes in. Otherwise we'd be pulling the entire endpoints database every time we send an OPTIONS. Since we already know the contact's aor, the on_endpoint callback was also modified to just check if the contact->aor is an exact match to one of the endpoint's. Finally, since we now have an endpoint for every OPTIONS request, res_pjsip/endpt_send_request (which handles out-of-dialog reqests) was updated to get the transport from the endpoint and set it on tdata. Now the correct transport is used. Change-Id: I2207e12bb435e373bd1e03ad091d82e5aba011af
2016-03-27sorcery/res_pjsip: Refactor for realtime performanceGeorge Joseph
There were a number of places in the res_pjsip stack that were getting all endpoints or all aors, and then filtering them locally. A good example is pjsip_options which, on startup, retrieves all endpoints, then the aors for those endpoints, then tests the aors to see if the qualify_frequency is > 0. One issue was that it never did anything with the endpoints other than retrieve the aors so we probably could have skipped a step and just retrieved all aors. But nevermind. This worked reasonably well with local config files but with a realtime backend and thousands of objects, this was a nightmare. The issue really boiled down to the fact that while realtime supports predicates that are passed to the database engine, the non-realtime sorcery backends didn't. They do now. The realtime engines have a scheme for doing simple comparisons. They take in an ast_variable (or list) for matching, and the name of each variable can contain an operator. For instance, a name of "qualify_frequency >" and a value of "0" would create a SQL predicate that looks like "where qualify_frequency > '0'". If there's no operator after the name, the engines add an '=' so a simple name of "qualify_frequency" and a value of "10" would return exact matches. The non-realtime backends decide whether to include an object in a result set by calling ast_sorcery_changeset_create on every object in the internal container. However, ast_sorcery_changeset_create only does exact string matches though so a name of "qualify_frequency >" and a value of "0" returns nothing because the literal "qualify_frequency >" doesn't match any name in the objset set. So, the real task was to create a generic string matcher that can take a left value, operator and a right value and perform the match. To that end, strings.c has a new ast_strings_match(left, operator, right) function. Left and right are the strings to operate on and the operator can be a string containing any of the following: = (or NULL or ""), !=, >, >=, <, <=, like or regex. If the operator is like or regex, the right string should be a %-pattern or a regex expression. If both left and right can be converted to float, then a numeric comparison is performed, otherwise a string comparison is performed. To use this new function on ast_variables, 2 new functions were added to config.c. One that compares 2 ast_variables, and one that compares 2 ast_variable lists. The former is useful when you want to compare 2 ast_variables that happen to be in a list but don't want to traverse the list. The latter will traverse the right list and return true if all the variables in it match the left list. Now, the backends' fields_cmp functions call ast_variable_lists_match instead of ast_sorcery_changeset_create and they can now process the same syntax as the realtime engines. The realtime backend just passes the variable list unaltered to the engine. The only gotcha is that there's no common realtime engine support for regex so that's been noted in the api docs for ast_sorcery_retrieve_by_fields. Only one more change to sorcery was done... A new config flag "allow_unqualified_fetch" was added to reg_sorcery_realtime. "no": ignore fetches if no predicate fields were supplied. "error": same as no but emit an error. (good for testing) "yes": allow (the default); "warn": allow but emit a warning. (good for testing) Now on to res_pjsip... pjsip_options was modified to retrieve aors with qualify_frequency > 0 rather than all endpoints then all aors. Not only was this a big improvement in realtime retrieval but even for config files there's an improvement because we're not going through endpoints anymore. res_pjsip_mwi was modified to retieve only endpoints with something in the mailboxes field instead of all endpoints then testing mailboxes. res_pjsip_registrar_expire was completely refactored. It was retrieving all contacts then setting up scheduler entries to check for expiration. Now, it's a single thread (like keepalive) that periodically retrieves only contacts whose expiration time is < now and deletes them. A new contact_expiration_check_interval was added to global with a default of 30 seconds. Ross Beer reports that with this patch, his Asterisk startup time dropped from around an hour to under 30 seconds. There are still objects that can't be filtered at the database like identifies, transports, and registrations. These are not going to be anywhere near as numerous as endpoints, aors, auths, contacts however. Back to allow_unqualified_fetch. If this is set to yes and you have a very large number of objects in the database, the pjsip CLI commands will attempt to retrive ALL of them if not qualified with a LIKE. Worse, if you type "pjsip show endpoint <tab>" guess what's going to happen? :) Having a cache helps but all the objects will have to be retrieved at least once to fill the cache. Setting allow_unqualified_fetch=no prevents the mass retrieve and should be used on endpoints, auths, aors, and contacts. It should NOT be used for identifies, registrations and transports since these MUST be retrieved in bulk. Example sorcery.conf: [res_pjsip] endpoint=config,pjsip.conf,criteria=type=endpoint endpoint=realtime,ps_endpoints,allow_unqualified_fetch=error ASTERISK-25826 #close Reported-by: Ross Beer Tested-by: Ross Beer Change-Id: Id2691e447db90892890036e663aaf907b2dc1c67
2016-03-24config: fix flags in uint option handlerGianluca Merlo
The configuration unsigned integer option handler sets flags for the parser as if the option should be a signed integer (PARSE_INT32), leading to errors on "out of range" values. Fix flags (PARSE_UINT32). A fix to res_pjsip is also present which stops invalid flags from being passed when registering sorcery object fields for qualify status. ASTERISK-25612 #close Change-Id: I96b539336275e0e72a8e8033487d2c3344debd3e
2016-03-07res_pjsip: Strip spaces from items parsed from comma-separated listsGeorge Joseph
Configurations like "aors = a, b, c" were either ignoring everything after "a" or trying to look up " b". Same for mailboxes, ciphers, contacts and a few others. To fix, all the strsep(&copy, ",") calls have been wrapped in ast_strip. To facilitate this, ast_strip, ast_skip_blanks and ast_skip_nonblanks were updated to handle null pointers. In some cases, an ast_strlen_zero() test was added to skip consecutive commas. There was also an attempt to ast_free an ast_strdupa'd string in ast_sip_for_each_aor which was causing a SEGV. I removed it. Although this issue was reported for realtime, the issue was in the res_pjsip modules so all config mechanisms were affected. ASTERISK-25829 #close Reported-by: Mateusz Kowalski Change-Id: I0b22a2cf22a7c1c50d4ecacbfa540155bec0e7a2
2016-02-15Fix creation race of contact_status structures.Mark Michelson
It is possible when processing a SIP REGISTER request to have two threads end up creating contact_status structures in sorcery. contact_status is created using a "find or create" function. If two threads call into this at the same time, each thread will fail to find an existing contact_status, and so both will end up creating a new contact status. During testing, we would see sporadic failures because the PJSIP_CONTACT() dialplan function would operate on a different contact_status than what had been updated by res_pjsip/pjsip_options. The fix here is two-fold: 1) The "find or create" function for contact_status now has a lock around the entire operation. This way, if two threads attempt the operation simultaneously, the first to get there will create the object, and the second will find the object created by the first thread. 2) res_sorcery_memory has had its create callback updated so that it will not allow for objects with duplicate IDs to be created. Change-Id: I55b1460ff1eb0af0a3697b82d7c2bac9f6af5b97
2015-12-04res_pjsip/contacts/statsd: Make contact lifecycle events more consistentGeorge Joseph
It will never be perfect or even pretty, mostly because of the differences between static and dynamic contacts. Created: Can't use the contact or contact_status alloc functions because the objects come and go regardless of the actual state. Can't use the contact_apply_handler, ast_sip_location_add_contact or a sorcery created handler because they only get called for dynamic contacts. Similarly, permanent_uri_handler only gets called for static contacts. So, Matt had it right. :) ast_res_pjsip_find_or_create_contact_status is the only place it can go and not have duplicated code. Both permanent_uri_handler and contact_apply_handler call find_or_create. Removed: Can't use the destructors for the same reason as above. The only place to put this is in persistent_endpoint_contact_deleted_observer which I believe is the "correct" place but even that will handle only dynamic contacts. This doesn't called on shutdown however. There is no hook to use for static contacts that may be removed because of a config change while asterisk is in operation. I moved the cleanup of contact_status from ast_sip_location_delete_contact to the handler as well. Status Change and RTT: Although they worked fine where they were (in update_contact_status) I moved them to persistent_endpoint_contact_status_observer to make it more consistent with removed. There was logic there already to detect a state change. Finally, fixed a nit in permanent_uri_handler rmudgett reported eralier. ASTERISK-25608 #close Change-Id: I4b56e7dfc3be3baaaf6f1eac5b2068a0b79e357d Reported-by: George Joseph Tested-by: George Joseph
2015-12-02res_pjsip: Update logging to show contact->uri in messagesGeorge Joseph
An earlier commit changed the id of dynamic contacts to contain a hash instead of the uri. This patch updates status change logging to show the aor/uri instead of the id. This required adding the aor id to contact and contact_status and adding uri to contact_status. The aor id gets added to contact and contact_status in their allocators and the uri gets added to contact_status in pjsip_options when the contact_status is created or updated. ASTERISK-25598 #close Reported-by: George Joseph Tested-by: George Joseph Change-Id: I56cbec1d2ddbe8461367dd8b6da8a6f47f6fe511
2015-11-24Fixed some typosDavid M. Lee
Fixes some minor typos in the CHANGES file, plus an embarrasing typo in the StatsD API. Change-Id: I9ca4858c64a4a07d2643b81baa64baebb27a4eb7
2015-11-23res_pjsip/pjsip_options: Add StatsD statistics for PJSIP contactsMatt Jordan
This patch adds the ability to send StatsD statistics related to the state of PJSIP contacts. This includes: * A GUAGE statistic measuring the count of contacts in a particular state. This measures how many contacts are reachable, unreachable, etc. * The RTT time for each contact, if those contacts are qualified. This provides StatsD engines useful time-based data about each contact. ASTERISK-25571 Change-Id: Ib8378d73afedfc622be0643b87c542557e0b332c
2015-11-02pjsip_options: Schedule/unschedule qualifies on AoR creation/destructionMatt Jordan
When an AoR is created or destroyed dynamically, the scheduled OPTIONS requests that qualify the contacts on the AoR are not necessarily started or destroyed, particularly for persistent contacts created for that AoR. This patch adds create/update/delete sorcery observers for an AoR, which schedule/unschedule the qualifies as expected. Change-Id: Ic287ed2e2952a7808ee068776fe966f9554bdf7d
2015-06-05Fixes 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-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-04Modules: Make ast_module_info->self available to auxiliary sources.Corey Farrell
ast_module_info->self is often needed to register items with the core. Many modules have ad-hoc code to make this pointer available to auxiliary sources. This change updates the module build process to make the needed information available to all sources in a module. ASTERISK-25056 #close Reported by: Corey Farrell Change-Id: I18c8cd58fbcb1b708425f6757becaeca9fa91815
2015-04-27res_pjsip: Fix SEGV on pending-qualify contactsGeorge Joseph
Permanent contacts that hadn't been qualified yet were missing their contact_status entries causing SEGVs when running CLI commands. This patch makes sure that contact_statuses are created for both dynamic and permanent contacts when they are created. It also adds checks in the CLI code to make sure there's a contact_status, just in case. ASTERISK-25018 #close Reported-by: Ivan Poddubny Tested-by: Ivan Poddubny Tested-by: George Joseph Change-Id: I3cc13e5cedcafb24c400368b515b02d7fb81e029
2015-04-20Merge "pjsip_options: Fix non-qualified contacts showing as unavailable"Joshua Colp
2015-04-20pjsip_options: Fix format specifier for int64_t rtt.George Joseph
Contact status rtt is an int64_t and needs the PRId64 macro to properly create the format specifier on 32-bit systems. Change-Id: I4b8ab958fc1e9a179556a9b4ffa49673ba9fdec7
2015-04-19pjsip_options: Fix non-qualified contacts showing as unavailableGeorge Joseph
The "Add qualify_timeout processing and eventing" patch introduced an issue where contacts that had qualify_frequency set to 0 were showing Unavailable instead Unknown. This patch checks for qualify_frequency=0 and create an "Unknown" contact_status with an RTT = 0. Previously, the lack of contact_status implied Unknown but since we're now changing endpoint state based on contact_status, I've had to add new UNKNOWN status so that changes could trigger the appropriate contact_status observers. ASTERISK-24977: #close Change-Id: Ifcbc01533ce57f0e4e584b89a395326e098b8fe7
2015-04-16res_pjsip: Add global option to limit the maximum time for initial qualifiesGeorge Joseph
Currently when Asterisk starts initial qualifies of contacts are spread out randomly between 0 and qualify_timeout to prevent network and system overload. If a contact's qualify_frequency is 5 minutes however, that contact may be unavailable to accept calls for the entire 5 minutes after startup. So while staggering the initial qualifies is a good idea, basing the time on qualify_timeout could leave contacts unavailable for too long. This patch adds a new global parameter "max_initial_qualify_time" that sets the maximum time for the initial qualifies. This way you could make sure that all your contacts are initialy, randomly qualified within say 30 seconds but still have the contact's ongoing qualifies at a 5 minute interval. If max_initial_qualify_time is > 0, the formula is initial_interval = min(max_initial_interval, qualify_timeout * random(). If not set, qualify_timeout is used. The default is "0" (disabled). ASTERISK-24863 #close Change-Id: Ib80498aa1ea9923277bef51d6a9015c9c79740f4 Tested-by: George Joseph <george.joseph@fairview5.com>
2015-04-16pjsip_options: Add qualify_timeout processing and eventingGeorge Joseph
This is the second follow-on to https://reviewboard.asterisk.org/r/4572/ and the discussion at http://lists.digium.com/pipermail/asterisk-dev/2015-March/073921.html The basic issues are that changes in contact status don't cause events to be emitted for the associated endpoint. Only dynamic contact add/delete actions update the endpoint. Also, the qualify timeout is fixed by pjsip at 32 seconds which is a long time. This patch makes use of the new transaction timeout feature in r4585 and provides the following capabilities... 1. A new aor/contact variable 'qualify_timeout' has been added that allows the user to specify the maximum time in milliseconds to wait for a response to an OPTIONS message. The default is 3000ms. When the timer expires, the contact is marked unavailable. 2. Contact status changes are now propagated up to the endpoint as follows... When any contact is 'Available', the endpoint is marked as 'Reachable'. When all contacts are 'Unavailable', the endpoint is marked as 'Unreachable'. The existing endpoint events are generated appropriately. ASTERISK-24863 #close Change-Id: Id0ce0528e58014da1324856ea537e7765466044a Tested-by: Dmitriy Serov Tested-by: George Joseph <george.joseph@fairview5.com>
2015-03-27Add stateful PJSIP response API call, and use it for out-of-dialog responses.Mark Michelson
Asterisk had an issue where retransmissions of MESSAGE requests resulted in Asterisk processing the retransmission as if it were a new MESSAGE request. This patch fixes the issue by creating a transaction in PJSIP on the incoming request. This way, if a retransmission arrives, the PJSIP transaction layer will resend the response and Asterisk will not ever see the retransmission. ASTERISK-24920 #close Reported by Mark Michelson Review: https://reviewboard.asterisk.org/r/4532/ ........ Merged revisions 433619 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@433620 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-03-20Audit ast_pjsip_rdata_get_endpoint() usage for ref leaks.Richard Mudgett
Valgrind found some memory leaks associated with ast_pjsip_rdata_get_endpoint(). The leaks would manifest when sending responses to OPTIONS requests, processing MESSAGE requests, and res_pjsip supplements implementing the incoming_request callback. * Fix ast_pjsip_rdata_get_endpoint() endpoint ref leaks in res/res_pjsip.c:supplement_on_rx_request(), res/res_pjsip/pjsip_options.c:send_options_response(), res/res_pjsip_messaging.c:rx_data_to_ast_msg(), and res/res_pjsip_messaging.c:send_response(). * Eliminated RAII_VAR() use with ast_pjsip_rdata_get_endpoint() in res/res_pjsip_nat.c:nat_on_rx_message(). * Fixed inconsistent but benign return value in res/res_pjsip/pjsip_options.c:options_on_rx_request(). Review: https://reviewboard.asterisk.org/r/4511/ ........ Merged revisions 433222 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@433223 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-02-11HTTP: Stop accepting requests on final system shutdown.Richard Mudgett
There are three CLI commands to stop and restart Asterisk each. 1) core stop/restart now - Hangup all calls and stop or restart Asterisk. New channels are prevented while the shutdown request is pending. 2) core stop/restart gracefully - Stop or restart Asterisk when there are no calls remaining in the system. New channels are prevented while the shutdown request is pending. 3) core stop/restart when convenient - Stop or restart Asterisk when there are no calls in the system. New calls are not prevented while the shutdown request is pending. ARI has made stopping/restarting Asterisk more problematic. While a shutdown request is pending it is desirable to continue to process ARI HTTP requests for current calls. To handle the current calls while a shutdown request is pending, a new committed to shutdown phase is needed so ARI applications can deal with the calls until the system is fully committed to shutdown. * Added a new shutdown committed phase so ARI applications can deal with calls until the final committed to shutdown phase is reached. * Made refuse new HTTP requests when the system has reached the final system shutdown phase. Starting anything while the system is actively releasing resources and unloading modules is not a good thing. * Split the bridging framework shutdown to not cleanup the global bridging containers when shutting down in a hurry. This is similar to how other modules prevent crashes on rapid system shutdown. * Moved ast_begin_shutdown(), ast_cancel_shutdown(), and ast_shutting_down(). You should not have to include channel.h just to access these system functions. ASTERISK-24752 #close Reported by: Matthew Jordan Review: https://reviewboard.asterisk.org/r/4399/ ........ Merged revisions 431692 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@431694 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-01-27res_pjsip: make it unloadable (take 2)Kevin Harwell
Due to the original patch causing memory corruptions it was removed until the problem could be resolved. This patch is the original patch plus some added locking around stasis router subcription that was needed to avoid the memory corruption. Description of the original problem and patch (still applicable): The res_pjsip module was previously unloadable. With this patch it can now be unloaded. This patch is based off the original patch on the issue (listed below) by Corey Farrell with a few modifications. Namely, removed a few changes not required to make the module unloadable and also fixed a bug that would cause asterisk to crash on unloading. This patch is the first step (should hopefully be followed by another/others at some point) in allowing res_pjsip and the modules that depend on it to be unloadable. At this time, res_pjsip and some of the modules that depend on res_pjsip cannot be unloaded without causing problems of some sort. The goal of this patch is to get res_pjsip and only res_pjsip to be able to unload successfully and/or shutdown without incident (crashes, leaks, etc...). Other dependent modules may still cause problems on unload. Basically made sure, with the patch applied, that res_pjsip (with no other dependent modules loaded) could be succesfully unloaded and Asterisk could shutdown without any leaks or crashes that pertained directly to res_pjsip. ASTERISK-24485 #close Reported by: Corey Farrell Review: https://reviewboard.asterisk.org/r/4363/ patches: pjsip_unload-broken-r1.patch submitted by Corey Farrell (license 5909) ........ Merged revisions 431179 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@431180 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-01-17REVERTING res_pjsip: make it unloadableKevin Harwell
Due to the original patch causing memory corruptions the patch is being removed until the problem can be resolved. ........ Merged revisions 430734 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@430735 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-01-14res_pjsip: make it unloadableKevin Harwell
The res_pjsip module was previously unloadable. With this patch it can now be unloaded. This patch is based off the original patch on the issue (listed below) by Corey Farrell with a few modifications. Namely, removed a few changes not required to make the module unloadable and also fixed a bug that would cause asterisk to crash on unloading. This patch is the first step (should hopefully be followed by another/others at some point) in allowing res_pjsip and the modules that depend on it to be unloadable. At this time, res_pjsip and some of the modules that depend on res_pjsip cannot be unloaded without causing problems of some sort. The goal of this patch is to get res_pjsip and only res_pjsip to be able to unload successfully and/or shutdown without incident (crashes, leaks, etc...). Other dependent modules may still cause problems on unload. Basically made sure, with the patch applied, that res_pjsip (with no other dependent modules loaded) could be succesfully unloaded and Asterisk could shutdown without any leaks or crashes that pertained directly to res_pjsip. ASTERISK-24485 #close Reported by: Corey Farrell Review: https://reviewboard.asterisk.org/r/4311/ patches: pjsip_unload-broken-r1.patch submitted by Corey Farrell (license 5909) ........ Merged revisions 430628 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@430629 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-01-07Fix dev-mode build on recent gccKinsey Moore
........ Merged revisions 430274 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@430275 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-12-23pjsip_options: Fix continued qualifies after endpoint/aor deletionGeorge Joseph
If you remove an endpoint/aor from pjsip.conf then do a core reload, qualifies will continue even though the object are gone. This happens because nothing clears out the qualify tasks. This patch unschedules all existing qualify tasks before scheduling new ones on reload. Tested-by: George Joseph Review: https://reviewboard.asterisk.org/r/4290/ ........ Merged revisions 430064 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@430067 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-12-10PJSIP: Fix assert on initial mass qualifyKinsey Moore
This fixes the MWI test regressions caused by r429127 and ensures that contacts have non-zero qualify_frequency before attempting scheduling. ........ Merged revisions 429245 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 429246 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@429247 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-12-09PJSIP: Stagger outbound qualifiesKinsey Moore
This change staggers initiation of outbound qualify (OPTIONS) attempts to reduce instantaneous server load and prevent network congestion. Review: https://reviewboard.asterisk.org/r/4246/ ASTERISK-24342 #close Reported by: Richard Mudgett ........ Merged revisions 429127 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 429128 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@429129 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-10-30res_pjsip: incorrect qualify statistics after disabling for contactKevin Harwell
When removing the qualify_frequency from an AoR or a contact the statistics shown when issuing "pjsip show aors" from the CLI are incorrect. This patch deletes the contact's status object from sorcery, disassociating it from the contact, if the qualify_freqency is removed from configuration. ASTERISK-24462 #close Reported by: Mark Michelson Review: https://reviewboard.asterisk.org/r/4116/ ........ Merged revisions 426755 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 426757 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@426761 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-10-06res_pjsip/pjsip_options: Do not 404 an OPTIONS request not sent to an endpointMatthew Jordan
An OPTIONS request that is sent to Asterisk but not to a specific endpoint is currently sent a 404 in response. This is because, not surprisingly, an empty extension is never going to be found in the dialplan. This patch makes it so that we only attempt to look up the endpoint in the dialplan if it is specified in the OPTIONS request URI. #SIPit31 ASTERISK-24370 #close Reported by: Matt Jordan ........ Merged revisions 424624 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 424625 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@424626 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-09-24pjsip_options.c: Fix race condition stopping periodic out of dialog OPTIONS ↵Richard Mudgett
request. The crash on the issues is a result of an invalid transport configuration change when asterisk is restarted. The attempt to send the qualify request fails and we cleaned up. However, the callback is also called which results in a double unref of the objects involved. * Put a wrapper around pjsip_endpt_send_request() to detect when the passed in callback is called because of an error so callers can know to not cleanup. * Made send_request_cb() able to handle repeated challenges (Up to 10). * Fix periodic endpoint qualify OPTIONS sched deletion race by avoiding it. The sched entry will no longer self stop and must be externally stopped. * Added REF_DEBUG description tags to struct sched_data in pjsip_options.c. * Fix some off-nominal ref leaks in schedule_qualify(), qualify_and_schedule(). * Reordered pjsip_options.c module start/stop code to cleanup better on error. ASTERISK-24295 #close Reported by: Rogger Padilla Review: https://reviewboard.asterisk.org/r/3954/ ........ Merged revisions 423866 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 423867 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@423868 65c4cc65-6c06-0410-ace0-fbb531ad65f3