{"action":"created","comment":{"url":"https://api.github.com/repos/szeged/servo/pulls/comments/65054916","id":65054916,"diff_hunk":"@@ -5,115 +5,123 @@\n use regex::Regex;\n use std::cell::RefCell;\n use std::collections::HashMap;\n-use std::fs::File;\n-use std::io::{BufRead, BufReader};\n use std::string::String;\n+use util::resource_files::read_resource_file_lines;\n \n const EXCLUDE_READS: &'static str = \"exclude-reads\";\n const EXCLUDE_WRITES: &'static str = \"exclude-writes\";\n-const FILE_PATH: &'static str = \"./resources/gatt_blacklist.txt\";\n const VALID_UUID_REGEX: &'static str = \"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\";\n \n thread_local!(pub static BLUETOOTH_BLACKLIST: RefCell<BluetoothBlacklist> =\n               RefCell::new(BluetoothBlacklist(parse_blacklist())));\n \n-macro_rules! return_if_blacklisted {\n-    ($uuid:expr, $exclude_fn:ident) => {\n-        if BLUETOOTH_BLACKLIST.with(|blist| {\n-            blist.borrow().$exclude_fn($uuid.as_ref())\n-        }) {\n-            return Err(Security);\n-        }\n+pub fn uuid_is_blacklisted(uuid: &str, exclude_type: Blacklist) -> bool {\n+    match exclude_type {\n+        Blacklist::All => {\n+            BLUETOOTH_BLACKLIST.with(|blist| {\n+                blist.borrow().is_blacklisted(uuid)\n+            })\n+        },\n+        Blacklist::Reads => {\n+            BLUETOOTH_BLACKLIST.with(|blist| {\n+                blist.borrow().is_blacklisted_for_reads(uuid)\n+            })\n+        },\n+        Blacklist::Writes => {\n+            BLUETOOTH_BLACKLIST.with(|blist| {\n+                blist.borrow().is_blacklisted_for_writes(uuid)\n+            })\n+        },\n     }\n }\n \n-pub struct BluetoothBlacklist(Option<HashMap<String, ExcludeType>>);\n+pub struct BluetoothBlacklist(Option<HashMap<String, Blacklist>>);\n \n #[derive(Eq, PartialEq)]\n-pub enum ExcludeType {\n-    Exclude, // Read and Write\n-    ExcludeReads,\n-    ExcludeWrites,\n+pub enum Blacklist {\n+    All, // Read and Write\n+    Reads,\n+    Writes,\n }\n \n impl BluetoothBlacklist {\n-\n     // https://webbluetoothcg.github.io/web-bluetooth/#blacklisted\n     pub fn is_blacklisted(&self, uuid: &str) -> bool {\n         match self.0 {\n-            Some(ref map) => map.get(uuid).map_or(false, |et| et.eq(&ExcludeType::Exclude)),\n+            Some(ref map) => map.get(uuid).map_or(false, |et| et.eq(&Blacklist::All)),\n             None => false,\n         }\n     }\n \n     // https://webbluetoothcg.github.io/web-bluetooth/#blacklisted-for-reads\n     pub fn is_blacklisted_for_reads(&self, uuid: &str) -> bool {\n         match self.0 {\n-            Some(ref map) => map.get(uuid).map_or(false, |et| et.eq(&ExcludeType::Exclude) ||\n-                                                              et.eq(&ExcludeType::ExcludeReads)),\n+            Some(ref map) => map.get(uuid).map_or(false, |et| et.eq(&Blacklist::All) ||\n+                                                              et.eq(&Blacklist::Reads)),\n             None => false,\n         }\n     }\n \n     // https://webbluetoothcg.github.io/web-bluetooth/#blacklisted-for-writes\n     pub fn is_blacklisted_for_writes(&self, uuid: &str) -> bool {\n         match self.0 {\n-            Some(ref map) => map.get(uuid).map_or(false, |et| et.eq(&ExcludeType::Exclude) ||\n-                                                              et.eq(&ExcludeType::ExcludeWrites)),\n+            Some(ref map) => map.get(uuid).map_or(false, |et| et.eq(&Blacklist::All) ||\n+                                                              et.eq(&Blacklist::Writes)),\n             None => false,\n         }\n     }\n }\n \n // https://webbluetoothcg.github.io/web-bluetooth/#parsing-the-blacklist\n-fn parse_blacklist() -> Option<HashMap<String, ExcludeType>> {\n+fn parse_blacklist() -> Option<HashMap<String, Blacklist>> {\n     // Step 1 missing, currently we parse ./resources/gatt_blacklist.txt.\n-    let file = match File::open(FILE_PATH) {\n-        Ok(file) => file,\n-        Err(_) => return None,\n-    };\n-    let content = BufReader::new(file);\n     let valid_uuid_regex = Regex::new(VALID_UUID_REGEX).unwrap();\n+    let mut data: Vec<u8> = Vec::new();\n+    let lines = read_resource_file_lines(\"gatt_blacklist.txt\", &mut data)\n+                    .expect(\"Could not find gatt_blacklist.txt file\");\n     // Step 3\n     let mut result = HashMap::new();\n     // Step 2 and 4\n-    for line in content.lines() {\n-        if let Ok(line) = line {\n-            // Step 4.1\n-            if !line.is_empty() && !line.starts_with('#') {\n-                let mut exclude_type = ExcludeType::Exclude;\n-                let mut words = line.split_whitespace();\n-                if let Some(uuid) = words.next() {\n-                    if valid_uuid_regex.is_match(uuid) {\n-                        match words.next() {\n-                            // Step 4.2 We already have an initialized exclude_type with ExcludeType::Exclude.\n-                            None => {},\n-                            // Step 4.3\n-                            Some(EXCLUDE_READS) => {\n-                                exclude_type = ExcludeType::ExcludeReads;\n-                            },\n-                            Some(EXCLUDE_WRITES) => {\n-                                exclude_type  = ExcludeType::ExcludeWrites;\n-                            },\n-                            // Step 4.4\n-                            _ => {\n-                                return None;\n-                            },\n-                        }\n-                    } else {\n-                        return None;\n-                    }\n-                    // Step 4.5\n-                    if result.contains_key(uuid) {\n-                        return None;\n-                    }\n-                    // Step 4.6\n-                    result.insert(uuid.to_string(), exclude_type);\n-                }\n-            }\n-        } else {\n+    for line in lines {","path":"components/script/bluetooth_blacklist.rs","position":143,"original_position":143,"commit_id":"b790d5376212eabd9145c9d88c7ffa1727d2b644","original_commit_id":"b790d5376212eabd9145c9d88c7ffa1727d2b644","user":{"login":"dati91","id":2149430,"avatar_url":"https://avatars.githubusercontent.com/u/2149430?v=3","gravatar_id":"","url":"https://api.github.com/users/dati91","html_url":"https://github.com/dati91","followers_url":"https://api.github.com/users/dati91/followers","following_url":"https://api.github.com/users/dati91/following{/other_user}","gists_url":"https://api.github.com/users/dati91/gists{/gist_id}","starred_url":"https://api.github.com/users/dati91/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dati91/subscriptions","organizations_url":"https://api.github.com/users/dati91/orgs","repos_url":"https://api.github.com/users/dati91/repos","events_url":"https://api.github.com/users/dati91/events{/privacy}","received_events_url":"https://api.github.com/users/dati91/received_events","type":"User","site_admin":false},"body":"maybe `while let`?","created_at":"2016-05-30T10:43:50Z","updated_at":"2016-05-30T10:43:50Z","html_url":"https://github.com/szeged/servo/pull/39#discussion_r65054916","pull_request_url":"https://api.github.com/repos/szeged/servo/pulls/39","_links":{"self":{"href":"https://api.github.com/repos/szeged/servo/pulls/comments/65054916"},"html":{"href":"https://github.com/szeged/servo/pull/39#discussion_r65054916"},"pull_request":{"href":"https://api.github.com/repos/szeged/servo/pulls/39"}}},"pull_request":{"url":"https://api.github.com/repos/szeged/servo/pulls/39","id":71878800,"html_url":"https://github.com/szeged/servo/pull/39","diff_url":"https://github.com/szeged/servo/pull/39.diff","patch_url":"https://github.com/szeged/servo/pull/39.patch","issue_url":"https://api.github.com/repos/szeged/servo/issues/39","number":39,"state":"open","locked":false,"title":"Fix 1","user":{"login":"zakorgy","id":11725775,"avatar_url":"https://avatars.githubusercontent.com/u/11725775?v=3","gravatar_id":"","url":"https://api.github.com/users/zakorgy","html_url":"https://github.com/zakorgy","followers_url":"https://api.github.com/users/zakorgy/followers","following_url":"https://api.github.com/users/zakorgy/following{/other_user}","gists_url":"https://api.github.com/users/zakorgy/gists{/gist_id}","starred_url":"https://api.github.com/users/zakorgy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zakorgy/subscriptions","organizations_url":"https://api.github.com/users/zakorgy/orgs","repos_url":"https://api.github.com/users/zakorgy/repos","events_url":"https://api.github.com/users/zakorgy/events{/privacy}","received_events_url":"https://api.github.com/users/zakorgy/received_events","type":"User","site_admin":false},"body":"<!-- Please describe your changes on the following line: -->\r\n\r\n---\r\n<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->\r\n- [X] `./mach build -d` does not report any errors\r\n- [X] `./mach test-tidy` does not report any errors\r\n- [ ] These changes fix #__ (github issue number if applicable).\r\n\r\n<!-- Either: -->\r\n- [ ] There are tests for these changes OR\r\n- [ ] These changes do not require tests because _____\r\n\r\n<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->\r\n\r\n","created_at":"2016-05-30T09:55:49Z","updated_at":"2016-05-30T10:43:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f20e653baaa13f9d5f850889fdc8955514873cf2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/szeged/servo/pulls/39/commits","review_comments_url":"https://api.github.com/repos/szeged/servo/pulls/39/comments","review_comment_url":"https://api.github.com/repos/szeged/servo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/szeged/servo/issues/39/comments","statuses_url":"https://api.github.com/repos/szeged/servo/statuses/b790d5376212eabd9145c9d88c7ffa1727d2b644","head":{"label":"zakorgy:blacklist","ref":"blacklist","sha":"b790d5376212eabd9145c9d88c7ffa1727d2b644","user":{"login":"zakorgy","id":11725775,"avatar_url":"https://avatars.githubusercontent.com/u/11725775?v=3","gravatar_id":"","url":"https://api.github.com/users/zakorgy","html_url":"https://github.com/zakorgy","followers_url":"https://api.github.com/users/zakorgy/followers","following_url":"https://api.github.com/users/zakorgy/following{/other_user}","gists_url":"https://api.github.com/users/zakorgy/gists{/gist_id}","starred_url":"https://api.github.com/users/zakorgy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zakorgy/subscriptions","organizations_url":"https://api.github.com/users/zakorgy/orgs","repos_url":"https://api.github.com/users/zakorgy/repos","events_url":"https://api.github.com/users/zakorgy/events{/privacy}","received_events_url":"https://api.github.com/users/zakorgy/received_events","type":"User","site_admin":false},"repo":{"id":53485776,"name":"servo","full_name":"zakorgy/servo","owner":{"login":"zakorgy","id":11725775,"avatar_url":"https://avatars.githubusercontent.com/u/11725775?v=3","gravatar_id":"","url":"https://api.github.com/users/zakorgy","html_url":"https://github.com/zakorgy","followers_url":"https://api.github.com/users/zakorgy/followers","following_url":"https://api.github.com/users/zakorgy/following{/other_user}","gists_url":"https://api.github.com/users/zakorgy/gists{/gist_id}","starred_url":"https://api.github.com/users/zakorgy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zakorgy/subscriptions","organizations_url":"https://api.github.com/users/zakorgy/orgs","repos_url":"https://api.github.com/users/zakorgy/repos","events_url":"https://api.github.com/users/zakorgy/events{/privacy}","received_events_url":"https://api.github.com/users/zakorgy/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zakorgy/servo","description":"The Servo Browser Engine","fork":true,"url":"https://api.github.com/repos/zakorgy/servo","forks_url":"https://api.github.com/repos/zakorgy/servo/forks","keys_url":"https://api.github.com/repos/zakorgy/servo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zakorgy/servo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zakorgy/servo/teams","hooks_url":"https://api.github.com/repos/zakorgy/servo/hooks","issue_events_url":"https://api.github.com/repos/zakorgy/servo/issues/events{/number}","events_url":"https://api.github.com/repos/zakorgy/servo/events","assignees_url":"https://api.github.com/repos/zakorgy/servo/assignees{/user}","branches_url":"https://api.github.com/repos/zakorgy/servo/branches{/branch}","tags_url":"https://api.github.com/repos/zakorgy/servo/tags","blobs_url":"https://api.github.com/repos/zakorgy/servo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zakorgy/servo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zakorgy/servo/git/refs{/sha}","trees_url":"https://api.github.com/repos/zakorgy/servo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zakorgy/servo/statuses/{sha}","languages_url":"https://api.github.com/repos/zakorgy/servo/languages","stargazers_url":"https://api.github.com/repos/zakorgy/servo/stargazers","contributors_url":"https://api.github.com/repos/zakorgy/servo/contributors","subscribers_url":"https://api.github.com/repos/zakorgy/servo/subscribers","subscription_url":"https://api.github.com/repos/zakorgy/servo/subscription","commits_url":"https://api.github.com/repos/zakorgy/servo/commits{/sha}","git_commits_url":"https://api.github.com/repos/zakorgy/servo/git/commits{/sha}","comments_url":"https://api.github.com/repos/zakorgy/servo/comments{/number}","issue_comment_url":"https://api.github.com/repos/zakorgy/servo/issues/comments{/number}","contents_url":"https://api.github.com/repos/zakorgy/servo/contents/{+path}","compare_url":"https://api.github.com/repos/zakorgy/servo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zakorgy/servo/merges","archive_url":"https://api.github.com/repos/zakorgy/servo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zakorgy/servo/downloads","issues_url":"https://api.github.com/repos/zakorgy/servo/issues{/number}","pulls_url":"https://api.github.com/repos/zakorgy/servo/pulls{/number}","milestones_url":"https://api.github.com/repos/zakorgy/servo/milestones{/number}","notifications_url":"https://api.github.com/repos/zakorgy/servo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zakorgy/servo/labels{/name}","releases_url":"https://api.github.com/repos/zakorgy/servo/releases{/id}","deployments_url":"https://api.github.com/repos/zakorgy/servo/deployments","created_at":"2016-03-09T09:36:07Z","updated_at":"2016-01-25T13:06:41Z","pushed_at":"2016-05-30T09:52:44Z","git_url":"git://github.com/zakorgy/servo.git","ssh_url":"git@github.com:zakorgy/servo.git","clone_url":"https://github.com/zakorgy/servo.git","svn_url":"https://github.com/zakorgy/servo","homepage":"https://servo.org/","size":185495,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"szeged:blacklist","ref":"blacklist","sha":"097b237a3cefb5b2141ef68f3b4c9f0437a7572a","user":{"login":"szeged","id":1826696,"avatar_url":"https://avatars.githubusercontent.com/u/1826696?v=3","gravatar_id":"","url":"https://api.github.com/users/szeged","html_url":"https://github.com/szeged","followers_url":"https://api.github.com/users/szeged/followers","following_url":"https://api.github.com/users/szeged/following{/other_user}","gists_url":"https://api.github.com/users/szeged/gists{/gist_id}","starred_url":"https://api.github.com/users/szeged/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szeged/subscriptions","organizations_url":"https://api.github.com/users/szeged/orgs","repos_url":"https://api.github.com/users/szeged/repos","events_url":"https://api.github.com/users/szeged/events{/privacy}","received_events_url":"https://api.github.com/users/szeged/received_events","type":"Organization","site_admin":false},"repo":{"id":50353354,"name":"servo","full_name":"szeged/servo","owner":{"login":"szeged","id":1826696,"avatar_url":"https://avatars.githubusercontent.com/u/1826696?v=3","gravatar_id":"","url":"https://api.github.com/users/szeged","html_url":"https://github.com/szeged","followers_url":"https://api.github.com/users/szeged/followers","following_url":"https://api.github.com/users/szeged/following{/other_user}","gists_url":"https://api.github.com/users/szeged/gists{/gist_id}","starred_url":"https://api.github.com/users/szeged/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szeged/subscriptions","organizations_url":"https://api.github.com/users/szeged/orgs","repos_url":"https://api.github.com/users/szeged/repos","events_url":"https://api.github.com/users/szeged/events{/privacy}","received_events_url":"https://api.github.com/users/szeged/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/szeged/servo","description":"The Servo Browser Engine","fork":true,"url":"https://api.github.com/repos/szeged/servo","forks_url":"https://api.github.com/repos/szeged/servo/forks","keys_url":"https://api.github.com/repos/szeged/servo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/szeged/servo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/szeged/servo/teams","hooks_url":"https://api.github.com/repos/szeged/servo/hooks","issue_events_url":"https://api.github.com/repos/szeged/servo/issues/events{/number}","events_url":"https://api.github.com/repos/szeged/servo/events","assignees_url":"https://api.github.com/repos/szeged/servo/assignees{/user}","branches_url":"https://api.github.com/repos/szeged/servo/branches{/branch}","tags_url":"https://api.github.com/repos/szeged/servo/tags","blobs_url":"https://api.github.com/repos/szeged/servo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/szeged/servo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/szeged/servo/git/refs{/sha}","trees_url":"https://api.github.com/repos/szeged/servo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/szeged/servo/statuses/{sha}","languages_url":"https://api.github.com/repos/szeged/servo/languages","stargazers_url":"https://api.github.com/repos/szeged/servo/stargazers","contributors_url":"https://api.github.com/repos/szeged/servo/contributors","subscribers_url":"https://api.github.com/repos/szeged/servo/subscribers","subscription_url":"https://api.github.com/repos/szeged/servo/subscription","commits_url":"https://api.github.com/repos/szeged/servo/commits{/sha}","git_commits_url":"https://api.github.com/repos/szeged/servo/git/commits{/sha}","comments_url":"https://api.github.com/repos/szeged/servo/comments{/number}","issue_comment_url":"https://api.github.com/repos/szeged/servo/issues/comments{/number}","contents_url":"https://api.github.com/repos/szeged/servo/contents/{+path}","compare_url":"https://api.github.com/repos/szeged/servo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/szeged/servo/merges","archive_url":"https://api.github.com/repos/szeged/servo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/szeged/servo/downloads","issues_url":"https://api.github.com/repos/szeged/servo/issues{/number}","pulls_url":"https://api.github.com/repos/szeged/servo/pulls{/number}","milestones_url":"https://api.github.com/repos/szeged/servo/milestones{/number}","notifications_url":"https://api.github.com/repos/szeged/servo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/szeged/servo/labels{/name}","releases_url":"https://api.github.com/repos/szeged/servo/releases{/id}","deployments_url":"https://api.github.com/repos/szeged/servo/deployments","created_at":"2016-01-25T13:48:48Z","updated_at":"2016-01-25T13:06:41Z","pushed_at":"2016-05-30T09:55:49Z","git_url":"git://github.com/szeged/servo.git","ssh_url":"git@github.com:szeged/servo.git","clone_url":"https://github.com/szeged/servo.git","svn_url":"https://github.com/szeged/servo","homepage":"https://servo.org/","size":208810,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":3,"mirror_url":null,"open_issues_count":2,"forks":3,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/szeged/servo/pulls/39"},"html":{"href":"https://github.com/szeged/servo/pull/39"},"issue":{"href":"https://api.github.com/repos/szeged/servo/issues/39"},"comments":{"href":"https://api.github.com/repos/szeged/servo/issues/39/comments"},"review_comments":{"href":"https://api.github.com/repos/szeged/servo/pulls/39/comments"},"review_comment":{"href":"https://api.github.com/repos/szeged/servo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/szeged/servo/pulls/39/commits"},"statuses":{"href":"https://api.github.com/repos/szeged/servo/statuses/b790d5376212eabd9145c9d88c7ffa1727d2b644"}}}}
{"actor":{"display_login":"dati91"}}