{"action":"created","comment":{"url":"https://api.github.com/repos/Metaswitch/sprout/pulls/comments/41011239","id":41011239,"diff_hunk":"@@ -0,0 +1,204 @@\n+/**\n+ * @file session_expires_helper.cpp Class that implements the relevant parts of\n+ * session expires processing (RFC 4028)\n+ *\n+ * project clearwater - ims in the cloud\n+ * copyright (c) 2015  metaswitch networks ltd\n+ *\n+ * this program is free software: you can redistribute it and/or modify it\n+ * under the terms of the gnu general public license as published by the\n+ * free software foundation, either version 3 of the license, or (at your\n+ * option) any later version, along with the \"special exception\" for use of\n+ * the program along with ssl, set forth below. this program is distributed\n+ * in the hope that it will be useful, but without any warranty;\n+ * without even the implied warranty of merchantability or fitness for\n+ * a particular purpose.  see the gnu general public license for more\n+ * details. you should have received a copy of the gnu general public\n+ * license along with this program.  if not, see\n+ * <http://www.gnu.org/licenses/>.\n+ *\n+ * the author can be reached by email at clearwater@metaswitch.com or by\n+ * post at metaswitch networks ltd, 100 church st, enfield en2 6bq, uk\n+ *\n+ * special exception\n+ * metaswitch networks ltd  grants you permission to copy, modify,\n+ * propagate, and distribute a work formed by combining openssl with the\n+ * software, or a work derivative of such a combination, even if such\n+ * copying, modification, propagation, or distribution would otherwise\n+ * violate the terms of the gpl. you must comply with the gpl in all\n+ * respects for all of the code used other than openssl.\n+ * \"openssl\" means openssl toolkit software distributed by the openssl\n+ * project and licensed under the openssl licenses, or a work based on such\n+ * software and licensed under the openssl licenses.\n+ * \"openssl licenses\" means the openssl license and original ssleay license\n+ * under which the openssl project distributes the openssl toolkit software,\n+ * as those licenses appear in the file license-openssl.\n+ */\n+\n+#include \"log.h\"\n+#include \"constants.h\"\n+#include \"custom_headers.h\"\n+#include \"sproutsasevent.h\"\n+#include \"session_expires_helper.h\"\n+\n+// The RFC states that the minimum session expiry defaults to 90s if no Min-SE\n+// header is present.\n+const static SessionExpiresHelper::SessionInterval DEFAULT_MIN_SE = 90;\n+\n+\n+SessionExpiresHelper::SessionExpiresHelper(SessionInterval target_se) :\n+  _target_se(target_se)\n+{}\n+\n+\n+bool SessionExpiresHelper::timer_supported(pjsip_msg* msg)\n+{\n+  pjsip_supported_hdr* supported_hdr = (pjsip_supported_hdr*)\n+    pjsip_msg_find_hdr(msg, PJSIP_H_SUPPORTED, NULL);\n+\n+  if (supported_hdr != NULL)\n+  {\n+    for (unsigned ii = 0; ii < supported_hdr->count; ++ii)\n+    {\n+      if (pj_strcmp(&supported_hdr->values[ii], &STR_TIMER) == 0)","path":"sprout/session_expires_helper.cpp","position":63,"original_position":63,"commit_id":"8ef068a1a0dfba5d265c2494d22722a1d8e0a3ea","original_commit_id":"8ef068a1a0dfba5d265c2494d22722a1d8e0a3ea","user":{"login":"bossmc","id":1073983,"avatar_url":"https://avatars.githubusercontent.com/u/1073983?v=3","gravatar_id":"","url":"https://api.github.com/users/bossmc","html_url":"https://github.com/bossmc","followers_url":"https://api.github.com/users/bossmc/followers","following_url":"https://api.github.com/users/bossmc/following{/other_user}","gists_url":"https://api.github.com/users/bossmc/gists{/gist_id}","starred_url":"https://api.github.com/users/bossmc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bossmc/subscriptions","organizations_url":"https://api.github.com/users/bossmc/orgs","repos_url":"https://api.github.com/users/bossmc/repos","events_url":"https://api.github.com/users/bossmc/events{/privacy}","received_events_url":"https://api.github.com/users/bossmc/received_events","type":"User","site_admin":false},"body":"Case-sensitive?  I know the spec is clear that it's lower case, but when has a spec stopped a UE from doing something weird?","created_at":"2015-10-02T11:12:58Z","updated_at":"2015-10-02T11:12:58Z","html_url":"https://github.com/Metaswitch/sprout/pull/1205#discussion_r41011239","pull_request_url":"https://api.github.com/repos/Metaswitch/sprout/pulls/1205","_links":{"self":{"href":"https://api.github.com/repos/Metaswitch/sprout/pulls/comments/41011239"},"html":{"href":"https://github.com/Metaswitch/sprout/pull/1205#discussion_r41011239"},"pull_request":{"href":"https://api.github.com/repos/Metaswitch/sprout/pulls/1205"}}},"pull_request":{"url":"https://api.github.com/repos/Metaswitch/sprout/pulls/1205","id":46616023,"html_url":"https://github.com/Metaswitch/sprout/pull/1205","diff_url":"https://github.com/Metaswitch/sprout/pull/1205.diff","patch_url":"https://github.com/Metaswitch/sprout/pull/1205.patch","issue_url":"https://api.github.com/repos/Metaswitch/sprout/issues/1205","number":1205,"state":"open","locked":false,"title":"[Reviewer: Andy] Session expires fixes","user":{"login":"AlexHockey","id":4903205,"avatar_url":"https://avatars.githubusercontent.com/u/4903205?v=3","gravatar_id":"","url":"https://api.github.com/users/AlexHockey","html_url":"https://github.com/AlexHockey","followers_url":"https://api.github.com/users/AlexHockey/followers","following_url":"https://api.github.com/users/AlexHockey/following{/other_user}","gists_url":"https://api.github.com/users/AlexHockey/gists{/gist_id}","starred_url":"https://api.github.com/users/AlexHockey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlexHockey/subscriptions","organizations_url":"https://api.github.com/users/AlexHockey/orgs","repos_url":"https://api.github.com/users/AlexHockey/repos","events_url":"https://api.github.com/users/AlexHockey/events{/privacy}","received_events_url":"https://api.github.com/users/AlexHockey/received_events","type":"User","site_admin":false},"body":"Andy, please can you review this PR to implement session timers as per RFC 4028 (rather than our previous approximation to it). \r\n\r\nAs proper handling of the session-timer header requires us to maintain state between the request and response I have refactored the logic out into a new class, `SessionExpiresHelper`, that is called to update requests and responses correctly. \r\n\r\nPreviously we rejected requests that contained a min-SE higher than our target value, on the basis that it would mean refreshes weren't sent frequently enough. As discussed this logic is actually really incomplete. For one thing there is nothing to prevent establishment of a call where neither UA supports timer. Also downstream devices can just raise the min-SE without rejecting the request and the first time we hear about this is on the 200 OK, by which point it's too late to reject the request. As such I have removed the logic to reject requests with a too-large min-SE. now we set the Session-Expires to the min-SE and proxy the request on. \r\n\r\nTested in UT. ","created_at":"2015-10-02T09:15:06Z","updated_at":"2015-10-02T11:12:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"33df52332fffdb0cbb4cdfb285bbe828834d6fa4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Metaswitch/sprout/pulls/1205/commits","review_comments_url":"https://api.github.com/repos/Metaswitch/sprout/pulls/1205/comments","review_comment_url":"https://api.github.com/repos/Metaswitch/sprout/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Metaswitch/sprout/issues/1205/comments","statuses_url":"https://api.github.com/repos/Metaswitch/sprout/statuses/8ef068a1a0dfba5d265c2494d22722a1d8e0a3ea","head":{"label":"Metaswitch:session_expires_fixes","ref":"session_expires_fixes","sha":"8ef068a1a0dfba5d265c2494d22722a1d8e0a3ea","user":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"repo":{"id":9887542,"name":"sprout","full_name":"Metaswitch/sprout","owner":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Metaswitch/sprout","description":"sprout and bono, the Clearwater SIP router and edge proxy","fork":false,"url":"https://api.github.com/repos/Metaswitch/sprout","forks_url":"https://api.github.com/repos/Metaswitch/sprout/forks","keys_url":"https://api.github.com/repos/Metaswitch/sprout/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Metaswitch/sprout/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Metaswitch/sprout/teams","hooks_url":"https://api.github.com/repos/Metaswitch/sprout/hooks","issue_events_url":"https://api.github.com/repos/Metaswitch/sprout/issues/events{/number}","events_url":"https://api.github.com/repos/Metaswitch/sprout/events","assignees_url":"https://api.github.com/repos/Metaswitch/sprout/assignees{/user}","branches_url":"https://api.github.com/repos/Metaswitch/sprout/branches{/branch}","tags_url":"https://api.github.com/repos/Metaswitch/sprout/tags","blobs_url":"https://api.github.com/repos/Metaswitch/sprout/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Metaswitch/sprout/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Metaswitch/sprout/git/refs{/sha}","trees_url":"https://api.github.com/repos/Metaswitch/sprout/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Metaswitch/sprout/statuses/{sha}","languages_url":"https://api.github.com/repos/Metaswitch/sprout/languages","stargazers_url":"https://api.github.com/repos/Metaswitch/sprout/stargazers","contributors_url":"https://api.github.com/repos/Metaswitch/sprout/contributors","subscribers_url":"https://api.github.com/repos/Metaswitch/sprout/subscribers","subscription_url":"https://api.github.com/repos/Metaswitch/sprout/subscription","commits_url":"https://api.github.com/repos/Metaswitch/sprout/commits{/sha}","git_commits_url":"https://api.github.com/repos/Metaswitch/sprout/git/commits{/sha}","comments_url":"https://api.github.com/repos/Metaswitch/sprout/comments{/number}","issue_comment_url":"https://api.github.com/repos/Metaswitch/sprout/issues/comments{/number}","contents_url":"https://api.github.com/repos/Metaswitch/sprout/contents/{+path}","compare_url":"https://api.github.com/repos/Metaswitch/sprout/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Metaswitch/sprout/merges","archive_url":"https://api.github.com/repos/Metaswitch/sprout/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Metaswitch/sprout/downloads","issues_url":"https://api.github.com/repos/Metaswitch/sprout/issues{/number}","pulls_url":"https://api.github.com/repos/Metaswitch/sprout/pulls{/number}","milestones_url":"https://api.github.com/repos/Metaswitch/sprout/milestones{/number}","notifications_url":"https://api.github.com/repos/Metaswitch/sprout/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Metaswitch/sprout/labels{/name}","releases_url":"https://api.github.com/repos/Metaswitch/sprout/releases{/id}","created_at":"2013-05-06T13:37:07Z","updated_at":"2015-09-03T05:56:02Z","pushed_at":"2015-10-02T09:15:07Z","git_url":"git://github.com/Metaswitch/sprout.git","ssh_url":"git@github.com:Metaswitch/sprout.git","clone_url":"https://github.com/Metaswitch/sprout.git","svn_url":"https://github.com/Metaswitch/sprout","homepage":null,"size":37106,"stargazers_count":15,"watchers_count":15,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":23,"mirror_url":null,"open_issues_count":77,"forks":23,"open_issues":77,"watchers":15,"default_branch":"dev"}},"base":{"label":"Metaswitch:dev","ref":"dev","sha":"170de8cfe029431f396a9ca00439c7d2abcd609a","user":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"repo":{"id":9887542,"name":"sprout","full_name":"Metaswitch/sprout","owner":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Metaswitch/sprout","description":"sprout and bono, the Clearwater SIP router and edge proxy","fork":false,"url":"https://api.github.com/repos/Metaswitch/sprout","forks_url":"https://api.github.com/repos/Metaswitch/sprout/forks","keys_url":"https://api.github.com/repos/Metaswitch/sprout/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Metaswitch/sprout/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Metaswitch/sprout/teams","hooks_url":"https://api.github.com/repos/Metaswitch/sprout/hooks","issue_events_url":"https://api.github.com/repos/Metaswitch/sprout/issues/events{/number}","events_url":"https://api.github.com/repos/Metaswitch/sprout/events","assignees_url":"https://api.github.com/repos/Metaswitch/sprout/assignees{/user}","branches_url":"https://api.github.com/repos/Metaswitch/sprout/branches{/branch}","tags_url":"https://api.github.com/repos/Metaswitch/sprout/tags","blobs_url":"https://api.github.com/repos/Metaswitch/sprout/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Metaswitch/sprout/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Metaswitch/sprout/git/refs{/sha}","trees_url":"https://api.github.com/repos/Metaswitch/sprout/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Metaswitch/sprout/statuses/{sha}","languages_url":"https://api.github.com/repos/Metaswitch/sprout/languages","stargazers_url":"https://api.github.com/repos/Metaswitch/sprout/stargazers","contributors_url":"https://api.github.com/repos/Metaswitch/sprout/contributors","subscribers_url":"https://api.github.com/repos/Metaswitch/sprout/subscribers","subscription_url":"https://api.github.com/repos/Metaswitch/sprout/subscription","commits_url":"https://api.github.com/repos/Metaswitch/sprout/commits{/sha}","git_commits_url":"https://api.github.com/repos/Metaswitch/sprout/git/commits{/sha}","comments_url":"https://api.github.com/repos/Metaswitch/sprout/comments{/number}","issue_comment_url":"https://api.github.com/repos/Metaswitch/sprout/issues/comments{/number}","contents_url":"https://api.github.com/repos/Metaswitch/sprout/contents/{+path}","compare_url":"https://api.github.com/repos/Metaswitch/sprout/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Metaswitch/sprout/merges","archive_url":"https://api.github.com/repos/Metaswitch/sprout/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Metaswitch/sprout/downloads","issues_url":"https://api.github.com/repos/Metaswitch/sprout/issues{/number}","pulls_url":"https://api.github.com/repos/Metaswitch/sprout/pulls{/number}","milestones_url":"https://api.github.com/repos/Metaswitch/sprout/milestones{/number}","notifications_url":"https://api.github.com/repos/Metaswitch/sprout/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Metaswitch/sprout/labels{/name}","releases_url":"https://api.github.com/repos/Metaswitch/sprout/releases{/id}","created_at":"2013-05-06T13:37:07Z","updated_at":"2015-09-03T05:56:02Z","pushed_at":"2015-10-02T09:15:07Z","git_url":"git://github.com/Metaswitch/sprout.git","ssh_url":"git@github.com:Metaswitch/sprout.git","clone_url":"https://github.com/Metaswitch/sprout.git","svn_url":"https://github.com/Metaswitch/sprout","homepage":null,"size":37106,"stargazers_count":15,"watchers_count":15,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":23,"mirror_url":null,"open_issues_count":77,"forks":23,"open_issues":77,"watchers":15,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/Metaswitch/sprout/pulls/1205"},"html":{"href":"https://github.com/Metaswitch/sprout/pull/1205"},"issue":{"href":"https://api.github.com/repos/Metaswitch/sprout/issues/1205"},"comments":{"href":"https://api.github.com/repos/Metaswitch/sprout/issues/1205/comments"},"review_comments":{"href":"https://api.github.com/repos/Metaswitch/sprout/pulls/1205/comments"},"review_comment":{"href":"https://api.github.com/repos/Metaswitch/sprout/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Metaswitch/sprout/pulls/1205/commits"},"statuses":{"href":"https://api.github.com/repos/Metaswitch/sprout/statuses/8ef068a1a0dfba5d265c2494d22722a1d8e0a3ea"}}}}