Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/mount_http.cc

Issue 15800004: [NaCl SDK] nacl_io: Added support for access() syscall. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase to HEAD. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 /* Copyright (c) 2012 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 5
6 #include "nacl_io/mount_http.h" 6 #include "nacl_io/mount_http.h"
7 7
8 #include <assert.h> 8 #include <assert.h>
9 #include <ctype.h> 9 #include <ctype.h>
10 #include <errno.h> 10 #include <errno.h>
11 #include <fcntl.h> 11 #include <fcntl.h>
12 #include <stdio.h> 12 #include <stdio.h>
13 #include <string.h> 13 #include <string.h>
14 #include <sys/stat.h> 14 #include <sys/stat.h>
15 #include <sys/types.h> 15 #include <sys/types.h>
16 #include <unistd.h>
16 17
17 #include <vector> 18 #include <vector>
18 19
19 #include <ppapi/c/pp_errors.h> 20 #include <ppapi/c/pp_errors.h>
20 21
21 #include "nacl_io/mount_node_dir.h" 22 #include "nacl_io/mount_node_dir.h"
22 #include "nacl_io/mount_node_http.h" 23 #include "nacl_io/mount_node_http.h"
23 #include "nacl_io/osinttypes.h" 24 #include "nacl_io/osinttypes.h"
24 #include "sdk_util/auto_lock.h" 25 #include "sdk_util/auto_lock.h"
25 26
(...skipping 21 matching lines...) Expand all
47 bool upper = true; 48 bool upper = true;
48 for (size_t i = 0; i < s.length(); ++i) { 49 for (size_t i = 0; i < s.length(); ++i) {
49 char c = s[i]; 50 char c = s[i];
50 result += upper ? toupper(c) : tolower(c); 51 result += upper ? toupper(c) : tolower(c);
51 upper = c == '-'; 52 upper = c == '-';
52 } 53 }
53 54
54 return result; 55 return result;
55 } 56 }
56 57
58 Error MountHttp::Access(const Path& path, int a_mode) {
59 assert(url_root_.empty() || url_root_[url_root_.length() - 1] == '/');
60
61 NodeMap_t::iterator iter = node_cache_.find(path.Join());
62 if (iter == node_cache_.end()) {
63 // If we can't find the node in the cache, fetch it
64 std::string url = MakeUrl(path);
65 MountNodeHttp* node = new MountNodeHttp(this, url, cache_content_);
66 Error error = node->Init(O_RDONLY);
67 if (error) {
68 node->Release();
69 return error;
70 }
71
72 error = node->GetStat(NULL);
73 node->Release();
74 if (error)
75 return error;
76 }
77
78 // Don't allow write or execute access.
79 if (a_mode & (W_OK | X_OK))
80 return EACCES;
81
82 return 0;
83 }
84
57 Error MountHttp::Open(const Path& path, int mode, MountNode** out_node) { 85 Error MountHttp::Open(const Path& path, int mode, MountNode** out_node) {
58 *out_node = NULL; 86 *out_node = NULL;
59 87
60 assert(url_root_.empty() || url_root_[url_root_.length() - 1] == '/'); 88 assert(url_root_.empty() || url_root_[url_root_.length() - 1] == '/');
61 89
62 NodeMap_t::iterator iter = node_cache_.find(path.Join()); 90 NodeMap_t::iterator iter = node_cache_.find(path.Join());
63 if (iter != node_cache_.end()) { 91 if (iter != node_cache_.end()) {
64 *out_node = iter->second; 92 *out_node = iter->second;
65 return 0; 93 return 0;
66 } 94 }
67 95
68 // If we can't find the node in the cache, create it 96 // If we can't find the node in the cache, create it
69 std::string url = url_root_ + (path.IsAbsolute() ? path.Range(1, path.Size()) 97 std::string url = MakeUrl(path);
70 : path.Join());
71
72 MountNodeHttp* node = new MountNodeHttp(this, url, cache_content_); 98 MountNodeHttp* node = new MountNodeHttp(this, url, cache_content_);
73 Error error = node->Init(mode); 99 Error error = node->Init(mode);
74 if (error) { 100 if (error) {
75 node->Release(); 101 node->Release();
76 return error; 102 return error;
77 } 103 }
78 104
79 error = node->GetStat(NULL); 105 error = node->GetStat(NULL);
80 if (error) { 106 if (error) {
81 node->Release(); 107 node->Release();
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 break; 356 break;
331 case 'w': 357 case 'w':
332 mode |= S_IWRITE; 358 mode |= S_IWRITE;
333 break; 359 break;
334 default: 360 default:
335 fprintf(stderr, "Unable to parse write %s for %s.\n", modestr, name); 361 fprintf(stderr, "Unable to parse write %s for %s.\n", modestr, name);
336 return EINVAL; 362 return EINVAL;
337 } 363 }
338 364
339 Path path(name); 365 Path path(name);
340 std::string url = 366 std::string url = MakeUrl(path);
341 url_root_ +
342 (path.IsAbsolute() ? path.Range(1, path.Size()) : path.Join());
343
344 MountNodeHttp* node = new MountNodeHttp(this, url, cache_content_); 367 MountNodeHttp* node = new MountNodeHttp(this, url, cache_content_);
345 Error error = node->Init(mode); 368 Error error = node->Init(mode);
346 if (error) { 369 if (error) {
347 node->Release(); 370 node->Release();
348 return error; 371 return error;
349 } 372 }
350 373
351 node->SetCachedSize(atoi(lenstr)); 374 node->SetCachedSize(atoi(lenstr));
352 375
353 MountNodeDir* dir_node; 376 MountNodeDir* dir_node;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 manifest_node->Release(); 418 manifest_node->Release();
396 return error; 419 return error;
397 } 420 }
398 421
399 manifest_node->Release(); 422 manifest_node->Release();
400 text[len] = 0; 423 text[len] = 0;
401 424
402 *out_manifest = text; 425 *out_manifest = text;
403 return 0; 426 return 0;
404 } 427 }
428
429 std::string MountHttp::MakeUrl(const Path& path) {
430 return url_root_ +
431 (path.IsAbsolute() ? path.Range(1, path.Size()) : path.Join());
432 }
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/mount_http.h ('k') | native_client_sdk/src/libraries/nacl_io/mount_mem.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698