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

Side by Side Diff: utils/archive/reader.c

Issue 10842002: Add the beginnings of a Dart wrapper for libarchive. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « utils/archive/reader.h ('k') | utils/archive/reader.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include "messaging.h"
6 #include "reader.h"
7
8 void archiveReadNew(Dart_Port p) {
9 struct archive* a = archive_read_new();
10 DART_INT64(result, (intptr_t) a)
11 postSuccess(p, &result);
12 return;
13 }
14
15 void archiveReadSupportFilterAll(Dart_Port p, struct archive* a) {
16 checkResult(p, a, archive_read_support_filter_all(a));
17 }
18
19 void archiveReadSupportFilterBzip2(Dart_Port p, struct archive* a) {
20 checkResult(p, a, archive_read_support_filter_bzip2(a));
21 }
22
23 void archiveReadSupportFilterCompress(Dart_Port p, struct archive* a) {
24 checkResult(p, a, archive_read_support_filter_compress(a));
25 }
26
27 void archiveReadSupportFilterGzip(Dart_Port p, struct archive* a) {
28 checkResult(p, a, archive_read_support_filter_gzip(a));
29 }
30
31 void archiveReadSupportFilterLzma(Dart_Port p, struct archive* a) {
32 checkResult(p, a, archive_read_support_filter_lzma(a));
33 }
34
35 void archiveReadSupportFilterXz(Dart_Port p, struct archive* a) {
36 checkResult(p, a, archive_read_support_filter_xz(a));
37 }
38
39 void archiveReadSupportFilterProgram(Dart_Port p, struct archive* a,
40 Dart_CObject* request) {
41 Dart_CObject* cmd = getTypedArgument(p, request, 0, kString);
42 if (cmd == NULL) return;
43 int result = archive_read_support_filter_program(
44 a, cmd->value.as_string);
45 checkResult(p, a, result);
46 }
47
48 void archiveReadSupportFilterProgramSignature(
49 Dart_Port p, struct archive* a, Dart_CObject* request) {
50 Dart_CObject* cmd = getTypedArgument(p, request, 0, kString);
51 if (cmd == NULL) return;
52
53 Dart_CObject* signature = getTypedArgument(p, request, 1, kUint8Array);
54 if (cmd == NULL) return;
55
56 int result = archive_read_support_filter_program_signature(
57 a, cmd->value.as_string, signature->value.as_byte_array.values,
58 signature->value.as_byte_array.length);
59 checkResult(p, a, result);
60 }
61
62 void archiveReadSupportFormatAll(Dart_Port p, struct archive* a) {
63 checkResult(p, a, archive_read_support_format_all(a));
64 }
65
66 void archiveReadSupportFormatAr(Dart_Port p, struct archive* a) {
67 checkResult(p, a, archive_read_support_format_ar(a));
68 }
69
70 void archiveReadSupportFormatCpio(Dart_Port p, struct archive* a) {
71 checkResult(p, a, archive_read_support_format_cpio(a));
72 }
73
74 void archiveReadSupportFormatEmpty(Dart_Port p, struct archive* a) {
75 checkResult(p, a, archive_read_support_format_empty(a));
76 }
77
78 void archiveReadSupportFormatIso9660(Dart_Port p, struct archive* a) {
79 checkResult(p, a, archive_read_support_format_iso9660(a));
80 }
81
82 void archiveReadSupportFormatMtree(Dart_Port p, struct archive* a) {
83 checkResult(p, a, archive_read_support_format_mtree(a));
84 }
85
86 void archiveReadSupportFormatRaw(Dart_Port p, struct archive* a) {
87 checkResult(p, a, archive_read_support_format_raw(a));
88 }
89
90 void archiveReadSupportFormatTar(Dart_Port p, struct archive* a) {
91 checkResult(p, a, archive_read_support_format_tar(a));
92 }
93
94 void archiveReadSupportFormatZip(Dart_Port p, struct archive* a) {
95 checkResult(p, a, archive_read_support_format_zip(a));
96 }
97
98 void archiveReadSetFilterOptions(Dart_Port p, struct archive* a,
99 Dart_CObject* request) {
100 Dart_CObject* options = getTypedArgument(p, request, 0, kString);
101 if (options == NULL) return;
102 int result = archive_read_set_filter_options(a, options->value.as_string);
103 checkResult(p, a, result);
104 }
105
106 void archiveReadSetFormatOptions(Dart_Port p, struct archive* a,
107 Dart_CObject* request) {
108 Dart_CObject* options = getTypedArgument(p, request, 0, kString);
109 if (options == NULL) return;
110 int result = archive_read_set_format_options(a, options->value.as_string);
111 checkResult(p, a, result);
112 }
113
114 void archiveReadSetOptions(Dart_Port p, struct archive* a,
115 Dart_CObject* request) {
116 Dart_CObject* options = getTypedArgument(p, request, 0, kString);
117 if (options == NULL) return;
118 int result = archive_read_set_options(a, options->value.as_string);
119 checkResult(p, a, result);
120 }
121
122 // TODO(nweiz): wrap archive_read_open2
123 // TODO(nweiz): wrap archive_read_FILE when issue 4160 is fixed
124
125 void archiveReadOpenFilename(Dart_Port p, struct archive* a,
126 Dart_CObject* request) {
127 Dart_CObject* filename = getTypedArgument(p, request, 0, kString);
128 if (filename == NULL) return;
129
130 Dart_CObject* block_size = getIntArgument(p, request, 1);
131 if (block_size == NULL) return;
132
133 int result = archive_read_open_filename(a, filename->value.as_string,
134 getInteger(block_size));
135 checkResult(p, a, result);
136 }
137
138 void archiveReadOpenMemory(Dart_Port p, struct archive* a,
139 Dart_CObject* request) {
140 Dart_CObject* filename = getTypedArgument(p, request, 0, kUint8Array);
141 if (filename == NULL) return;
142
143 int result = archive_read_open_memory(a, filename->value.as_byte_array.values,
144 filename->value.as_byte_array.length);
145 checkResult(p, a, result);
146 }
147
148 #define RAW_ARCHIVE_SIZE 32
149
150 void archiveReadNextHeader(Dart_Port p, struct archive* a) {
151 // TODO(nweiz): At some point, we'll want to attach the actual archive pointer
152 // to the struct we send to Dart so that it can later be modified, passed in
153 // to other functions, etc. When we do so, we'll need to use archive_entry_new
154 // to create it and we'll have to attach a finalizer to the Dart object to
155 // ensure that it gets freed.
156 struct archive_entry* entry;
157 int result = archive_read_next_header(a, &entry);
158 if (result == ARCHIVE_EOF) {
159 postSuccess(p, NULL);
160 return;
161 }
162 if (checkError(p, a, result)) return;
163
164 Dart_CObject* archive_entry_array[RAW_ARCHIVE_SIZE];
165
166 // archive_entry_paths(3)
167 DART_STRING(hardlink, (char*) archive_entry_hardlink(entry))
168 archive_entry_array[0] = &hardlink;
169 DART_STRING(pathname, (char*) archive_entry_pathname(entry))
170 archive_entry_array[1] = &pathname;
171 DART_STRING(sourcepath, (char*) archive_entry_sourcepath(entry))
172 archive_entry_array[2] = &sourcepath;
173 DART_STRING(symlink, (char*) archive_entry_symlink(entry))
174 archive_entry_array[3] = &symlink;
175
176 // archive_entry_perms(3)
177 DART_INT32(gid, archive_entry_gid(entry))
178 archive_entry_array[4] = &gid;
179 DART_INT32(uid, archive_entry_uid(entry))
180 archive_entry_array[5] = &uid;
181 DART_INT32(perm, archive_entry_perm(entry))
182 archive_entry_array[6] = &perm;
183 DART_STRING(strmode, (char*) archive_entry_strmode(entry))
184 archive_entry_array[7] = &strmode;
185 DART_STRING(gname, (char*) archive_entry_gname(entry))
186 archive_entry_array[8] = &gname;
187 DART_STRING(uname, (char*) archive_entry_uname(entry))
188 archive_entry_array[9] = &uname;
189
190 unsigned long fflags_set;
191 unsigned long fflags_clear;
192 archive_entry_fflags(entry, &fflags_set, &fflags_clear);
193 DART_INT64(wrapped_fflags_set, fflags_set)
194 archive_entry_array[10] = &wrapped_fflags_set;
195 DART_INT64(wrapped_fflags_clear, fflags_clear)
196 archive_entry_array[11] = &wrapped_fflags_clear;
197
198 DART_STRING(fflags_text, (char*) archive_entry_fflags_text(entry))
199 archive_entry_array[12] = &fflags_text;
200
201 // archive_entry_stat(3)
202 DART_INT32(filetype, archive_entry_filetype(entry))
203 archive_entry_array[13] = &filetype;
204 DART_INT32(mode, archive_entry_mode(entry))
205 archive_entry_array[14] = &mode;
206
207 Dart_CObject size;
208 if (archive_entry_size_is_set(entry)) {
209 size.type = kInt64;
210 size.value.as_int64 = archive_entry_size(entry);
211 } else {
212 size.type = kNull;
213 }
214 archive_entry_array[15] = &size;
215
216 Dart_CObject dev;
217 if (archive_entry_dev_is_set(entry)) {
218 dev.type = kInt64;
219 dev.value.as_int64 = archive_entry_dev(entry);
220 } else {
221 dev.type = kNull;
222 }
223 archive_entry_array[16] = &dev;
224
225 DART_INT64(devmajor, archive_entry_devmajor(entry))
226 archive_entry_array[17] = &devmajor;
227 DART_INT64(devminor, archive_entry_devminor(entry))
228 archive_entry_array[18] = &devminor;
229
230 Dart_CObject ino;
231 if (archive_entry_ino_is_set(entry)) {
232 ino.type = kInt64;
233 ino.value.as_int64 = archive_entry_ino64(entry);
234 } else {
235 ino.type = kNull;
236 }
237 archive_entry_array[19] = &ino;
238
239 DART_INT64(nlink, archive_entry_nlink(entry))
240 archive_entry_array[20] = &nlink;
241 DART_INT64(rdev, archive_entry_rdev(entry))
242 archive_entry_array[21] = &rdev;
243 DART_INT64(rdevmajor, archive_entry_rdevmajor(entry))
244 archive_entry_array[22] = &rdevmajor;
245 DART_INT64(rdevminor, archive_entry_rdevminor(entry))
246 archive_entry_array[23] = &rdevminor;
247
248 // archive_entry_time(3)
249 Dart_CObject atime;
250 Dart_CObject atime_nsec;
251 if (archive_entry_atime_is_set(entry)) {
252 atime.type = kInt64;
253 atime.value.as_int64 = archive_entry_atime(entry);
254 atime_nsec.type = kInt64;
255 atime_nsec.value.as_int64 = archive_entry_atime_nsec(entry);
256 } else {
257 atime.type = kNull;
258 atime_nsec.type = kNull;
259 }
260 archive_entry_array[24] = &atime;
261 archive_entry_array[25] = &atime_nsec;
262
263 Dart_CObject birthtime;
264 Dart_CObject birthtime_nsec;
265 if (archive_entry_birthtime_is_set(entry)) {
266 birthtime.type = kInt64;
267 birthtime.value.as_int64 = archive_entry_birthtime(entry);
268 birthtime_nsec.type = kInt64;
269 birthtime_nsec.value.as_int64 = archive_entry_birthtime_nsec(entry);
270 } else {
271 birthtime.type = kNull;
272 birthtime_nsec.type = kNull;
273 }
274 archive_entry_array[26] = &birthtime;
275 archive_entry_array[27] = &birthtime_nsec;
276
277 Dart_CObject ctime;
278 Dart_CObject ctime_nsec;
279 if (archive_entry_ctime_is_set(entry)) {
280 ctime.type = kInt64;
281 ctime.value.as_int64 = archive_entry_ctime(entry);
282 ctime_nsec.type = kInt64;
283 ctime_nsec.value.as_int64 = archive_entry_ctime_nsec(entry);
284 } else {
285 ctime.type = kNull;
286 ctime_nsec.type = kNull;
287 }
288 archive_entry_array[28] = &ctime;
289 archive_entry_array[29] = &ctime_nsec;
290
291 Dart_CObject mtime;
292 Dart_CObject mtime_nsec;
293 if (archive_entry_mtime_is_set(entry)) {
294 mtime.type = kInt64;
295 mtime.value.as_int64 = archive_entry_mtime(entry);
296 mtime_nsec.type = kInt64;
297 mtime_nsec.value.as_int64 = archive_entry_mtime_nsec(entry);
298 } else {
299 mtime.type = kNull;
300 mtime_nsec.type = kNull;
301 }
302 archive_entry_array[30] = &mtime;
303 archive_entry_array[31] = &mtime_nsec;
304 // If you add entries, don't forget to increase RAW_ARCHIVE_SIZE.
305
306 Dart_CObject wrapped_archive_entry;
307 wrapped_archive_entry.type = kArray;
308 wrapped_archive_entry.value.as_array.values = archive_entry_array;
309 wrapped_archive_entry.value.as_array.length = RAW_ARCHIVE_SIZE;
310
311 postSuccess(p, &wrapped_archive_entry);
312 }
313
314 void archiveReadDataBlock(Dart_Port p, struct archive* a) {
315 const void* buffer;
316 size_t len;
317 int64_t offset;
318 int result = archive_read_data_block(a, &buffer, &len, &offset);
319 if (result == ARCHIVE_EOF) {
320 postSuccess(p, NULL);
321 return;
322 }
323 if (checkError(p, a, result)) return;
324
325 Dart_CObject wrapped_data_block;
326 wrapped_data_block.type = kUint8Array;
327 wrapped_data_block.value.as_byte_array.length = len;
328 wrapped_data_block.value.as_byte_array.values = (void*) buffer + offset;
329 postSuccess(p, &wrapped_data_block);
330 }
331
332 void archiveReadDataSkip(Dart_Port p, struct archive* a) {
333 checkResult(p, a, archive_read_data_skip(a));
334 }
335
336 // TODO(nweiz): wrap archive_read_into_fd when issue 4160 is fixed
337 // TODO(nweiz): wrap archive_read_extract and friends
338
339 void archiveReadClose(Dart_Port p, struct archive* a) {
340 checkResult(p, a, archive_read_close(a));
341 }
342
343 void archiveReadFree(Dart_Port p, struct archive* a) {
344 // TODO(nweiz): Should we attach a finalizer to the Dart object that calls
345 // this automatically?
346 checkResult(p, a, archive_read_free(a));
347 }
OLDNEW
« no previous file with comments | « utils/archive/reader.h ('k') | utils/archive/reader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698