-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathrequest.h
173 lines (144 loc) · 6.94 KB
/
request.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright 2014 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REQUEST_H_
#define REQUEST_H_
#include "ppapi/cpp/var_array_buffer.h"
#include "ppapi/cpp/var_dictionary.h"
// Defines the protocol messsage used to communicate between JS and NaCL.
// This should be consistent with js/request.h.
namespace request {
// Defines requests keys. Every key should be unique and the same as the keys
// on the JS side.
namespace key {
// Mandatory keys for all unpacking requests.
const char kOperation[] = "operation"; // Should be a request::Operation.
const char kFileSystemId[] = "file_system_id"; // Should be a string.
const char kRequestId[] = "request_id"; // Should be a string.
// Optional keys unique to unpacking operations.
const char kMetadata[] = "metadata"; // Should be a pp:VarDictionary.
const char kArchiveSize[] =
"archive_size"; // Should be a string as int64_t is not support by pp::Var.
const char kIndex[] = "index"; // Should be a string as int64_t is not
// supported by pp::Var.
const char kEncoding[] = "encoding"; // Should be a string.
const char kOpenRequestId[] = "open_request_id"; // Should be a string, just
// like kRequestId.
const char kReadFileData[] = "read_file_data"; // Should be a
// pp::VarArrayBuffer.
const char kHasMoreData[] = "has_more_data"; // Should be a bool.
const char kPassphrase[] = "passphrase"; // Should be a string.
// Mandatory keys for all packing requests.
const char kCompressorId[] = "compressor_id"; // Should be an int.
// Optional keys unique to packing operations.
const char kEntryId[] = "entry_id"; // Should be an int.
const char kPathname[] = "pathname"; // Should be a string.
const char kFileSize[] = "file_size"; // Should be a string.
const char kIsDirectory[] = "is_directory"; // Should be a bool.
const char kModificationTime[] = "modification_time"; // Should be a string
// (mm/dd/yy h:m:s).
const char kHasError[] = "has_error"; // Should be a bool.
// Optional keys used for both packing and unpacking operations.
const char kError[] = "error"; // Should be a string.
const char kChunkBuffer[] = "chunk_buffer"; // Should be a pp::VarArrayBuffer.
const char kOffset[] = "offset"; // Should be a string as int64_t is not
// supported by pp::Var.
const char kLength[] = "length"; // Should be a string as int64_t is not
// supported by pp::Var.
const char kSrcFile[] = "src_file"; // Should be a string.
const char kSrcLine[] = "src_line"; // Should be a string.
const char kSrcFunc[] = "src_func"; // Should be a string.
const char kMessage[] = "message"; // Should be a string.
} // namespace key
// Defines request operations. These operations should be the same as the
// operations on the JavaScript side.
enum Operation {
READ_METADATA = 0,
READ_METADATA_DONE = 1,
READ_CHUNK = 2,
READ_CHUNK_DONE = 3,
READ_CHUNK_ERROR = 4,
READ_PASSPHRASE = 5,
READ_PASSPHRASE_DONE = 6,
READ_PASSPHRASE_ERROR = 7,
CLOSE_VOLUME = 8,
OPEN_FILE = 9,
OPEN_FILE_DONE = 10,
CLOSE_FILE = 11,
CLOSE_FILE_DONE = 12,
READ_FILE = 13,
READ_FILE_DONE = 14,
CONSOLE_LOG = 15,
CONSOLE_DEBUG = 16,
CREATE_ARCHIVE = 17,
CREATE_ARCHIVE_DONE = 18,
ADD_TO_ARCHIVE = 19,
ADD_TO_ARCHIVE_DONE = 20,
READ_FILE_CHUNK = 21,
READ_FILE_CHUNK_DONE = 22,
WRITE_CHUNK = 23,
WRITE_CHUNK_DONE = 24,
CLOSE_ARCHIVE = 25,
CLOSE_ARCHIVE_DONE = 26,
FILE_SYSTEM_ERROR = -1, // Errors specific to a file system.
COMPRESSOR_ERROR = -2 // Errors specific to a compressor.
};
// Operations greater than or equal to this value are for packing.
const int MINIMUM_PACK_REQUEST_VALUE = 17;
// Return true if the given operation is related to packing.
bool IsPackRequest(int operation);
// Creates a response to READ_METADATA request.
pp::VarDictionary CreateReadMetadataDoneResponse(
const std::string& file_system_id,
const std::string& request_id,
const pp::VarDictionary& metadata);
// Creates a request for a file chunk from JavaScript.
pp::VarDictionary CreateReadChunkRequest(const std::string& file_system_id,
const std::string& request_id,
int64_t offset,
int64_t length);
// Creates a request for a passphrase for a file from JavaScript.
pp::VarDictionary CreateReadPassphraseRequest(const std::string& file_system_id,
const std::string& request_id);
// Creates a response to OPEN_FILE request.
pp::VarDictionary CreateOpenFileDoneResponse(const std::string& file_system_id,
const std::string& request_id);
// Creates a response to CLOSE_FILE request.
pp::VarDictionary CreateCloseFileDoneResponse(
const std::string& file_system_id,
const std::string& request_id,
const std::string& open_request_id);
// Creates a response to READ_FILE request.
pp::VarDictionary CreateReadFileDoneResponse(
const std::string& file_system_id,
const std::string& request_id,
const pp::VarArrayBuffer& array_buffer,
bool has_more_data);
pp::VarDictionary CreateCreateArchiveDoneResponse(int compressor_id);
pp::VarDictionary CreateReadFileChunkRequest(int compressor_id,
int64_t length);
pp::VarDictionary CreateWriteChunkRequest(int compressor_id,
const pp::VarArrayBuffer& array_buffer,
int64_t length);
pp::VarDictionary CreateAddToArchiveDoneResponse(int compressor_id);
pp::VarDictionary CreateCloseArchiveDoneResponse(int compressor_id);
// Creates a file system error.
pp::VarDictionary CreateFileSystemError(const std::string& file_system_id,
const std::string& request_id,
const std::string& error);
pp::VarDictionary CreateConsoleLog(
const std::string& file_system_id,
const std::string& request_id,
const std::string& src_file,
int src_line,
const std::string& src_func,
const std::string& message);
// Creates a compressor error.
pp::VarDictionary CreateCompressorError(int compressor_id,
const std::string& error);
// Obtains a int64_t from a string value inside dictionary based on a
// request::Key.
int64_t GetInt64FromString(const pp::VarDictionary& dictionary,
const std::string& request_key);
} // namespace request
#endif // REQUEST_H_