OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "nacl_io/httpfs/http_fs.h" | 5 #include "nacl_io/httpfs/http_fs.h" |
6 | 6 |
7 #include <assert.h> | 7 #include <assert.h> |
8 #include <ctype.h> | 8 #include <ctype.h> |
9 #include <errno.h> | 9 #include <errno.h> |
10 #include <fcntl.h> | 10 #include <fcntl.h> |
(...skipping 23 matching lines...) Expand all Loading... |
34 bool upper = true; | 34 bool upper = true; |
35 for (size_t i = 0; i < s.length(); ++i) { | 35 for (size_t i = 0; i < s.length(); ++i) { |
36 char c = s[i]; | 36 char c = s[i]; |
37 result += upper ? toupper(c) : tolower(c); | 37 result += upper ? toupper(c) : tolower(c); |
38 upper = c == '-'; | 38 upper = c == '-'; |
39 } | 39 } |
40 | 40 |
41 return result; | 41 return result; |
42 } | 42 } |
43 | 43 |
44 Error HttpFs::Access(const Path& path, int a_mode) { | |
45 ScopedNode node; | |
46 NodeMap_t::iterator iter = node_cache_.find(path.Join()); | |
47 if (iter == node_cache_.end()) { | |
48 // If we can't find the node in the cache, fetch it | |
49 std::string url = MakeUrl(path); | |
50 node.reset(new HttpFsNode(this, url, cache_content_)); | |
51 Error error = node->Init(0); | |
52 if (error) | |
53 return error; | |
54 | |
55 error = node->GetStat(NULL); | |
56 if (error) | |
57 return error; | |
58 } else { | |
59 node = iter->second; | |
60 } | |
61 | |
62 int obj_mode = node->GetMode(); | |
63 if (((a_mode & R_OK) && !(obj_mode & S_IREAD)) || | |
64 ((a_mode & W_OK) && !(obj_mode & S_IWRITE)) || | |
65 ((a_mode & X_OK) && !(obj_mode & S_IEXEC))) { | |
66 return EACCES; | |
67 } | |
68 | |
69 return 0; | |
70 } | |
71 | |
72 Error HttpFs::Open(const Path& path, int open_flags, ScopedNode* out_node) { | 44 Error HttpFs::Open(const Path& path, int open_flags, ScopedNode* out_node) { |
73 out_node->reset(NULL); | 45 out_node->reset(NULL); |
74 | 46 |
75 NodeMap_t::iterator iter = node_cache_.find(path.Join()); | 47 NodeMap_t::iterator iter = node_cache_.find(path.Join()); |
76 if (iter != node_cache_.end()) { | 48 if (iter != node_cache_.end()) { |
77 *out_node = iter->second; | 49 *out_node = iter->second; |
78 return 0; | 50 return 0; |
79 } | 51 } |
80 | 52 |
81 // If we can't find the node in the cache, create it | 53 // If we can't find the node in the cache, create it |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 *out_manifest = text; | 406 *out_manifest = text; |
435 return 0; | 407 return 0; |
436 } | 408 } |
437 | 409 |
438 std::string HttpFs::MakeUrl(const Path& path) { | 410 std::string HttpFs::MakeUrl(const Path& path) { |
439 return url_root_ + | 411 return url_root_ + |
440 (path.IsAbsolute() ? path.Range(1, path.Size()) : path.Join()); | 412 (path.IsAbsolute() ? path.Range(1, path.Size()) : path.Join()); |
441 } | 413 } |
442 | 414 |
443 } // namespace nacl_io | 415 } // namespace nacl_io |
OLD | NEW |