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 = FindExistingNode(path); | |
46 if (node.get() == NULL) { | |
47 // If we can't find the node in the cache, fetch it | |
48 std::string url = MakeUrl(path); | |
49 node.reset(new HttpFsNode(this, url, cache_content_)); | |
50 Error error = node->Init(0); | |
51 if (error) | |
52 return error; | |
53 | |
54 error = node->GetStat(NULL); | |
55 if (error) | |
56 return error; | |
57 } | |
58 | |
59 int obj_mode = node->GetMode(); | |
60 if (((a_mode & R_OK) && !(obj_mode & S_IREAD)) || | |
61 ((a_mode & W_OK) && !(obj_mode & S_IWRITE)) || | |
62 ((a_mode & X_OK) && !(obj_mode & S_IEXEC))) { | |
63 return EACCES; | |
64 } | |
65 | |
66 return 0; | |
67 } | |
68 | |
69 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) { |
70 out_node->reset(NULL); | 45 out_node->reset(NULL); |
71 | 46 |
72 ScopedNode node = FindExistingNode(path); | 47 ScopedNode node = FindExistingNode(path); |
73 if (node.get() != NULL) { | 48 if (node.get() != NULL) { |
74 *out_node = node; | 49 *out_node = node; |
75 return 0; | 50 return 0; |
76 } | 51 } |
77 | 52 |
78 // 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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 *out_manifest = text; | 404 *out_manifest = text; |
430 return 0; | 405 return 0; |
431 } | 406 } |
432 | 407 |
433 std::string HttpFs::MakeUrl(const Path& path) { | 408 std::string HttpFs::MakeUrl(const Path& path) { |
434 return url_root_ + | 409 return url_root_ + |
435 (path.IsAbsolute() ? path.Range(1, path.Size()) : path.Join()); | 410 (path.IsAbsolute() ? path.Range(1, path.Size()) : path.Join()); |
436 } | 411 } |
437 | 412 |
438 } // namespace nacl_io | 413 } // namespace nacl_io |
OLD | NEW |