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

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

Issue 10832116: Attach the native entry struct to the ArchiveEntry object. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix the ISO9660 constant 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/read_request.dart ('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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "entry.h"
5 #include "messaging.h" 6 #include "messaging.h"
6 #include "reader.h" 7 #include "reader.h"
7 8
8 void archiveReadNew(Dart_Port p) { 9 void archiveReadNew(Dart_Port p) {
9 struct archive* a = archive_read_new(); 10 checkPointerResult(p, archive_read_new(), "archive input stream");
10 DART_INT64(result, (intptr_t) a)
11 postSuccess(p, &result);
12 return;
13 } 11 }
14 12
15 void archiveReadSupportFilterAll(Dart_Port p, struct archive* a) { 13 void archiveReadSupportFilterAll(Dart_Port p, struct archive* a) {
16 checkResult(p, a, archive_read_support_filter_all(a)); 14 checkResult(p, a, archive_read_support_filter_all(a));
17 } 15 }
18 16
19 void archiveReadSupportFilterBzip2(Dart_Port p, struct archive* a) { 17 void archiveReadSupportFilterBzip2(Dart_Port p, struct archive* a) {
20 checkResult(p, a, archive_read_support_filter_bzip2(a)); 18 checkResult(p, a, archive_read_support_filter_bzip2(a));
21 } 19 }
22 20
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 void archiveReadOpenMemory(Dart_Port p, struct archive* a, 136 void archiveReadOpenMemory(Dart_Port p, struct archive* a,
139 Dart_CObject* request) { 137 Dart_CObject* request) {
140 Dart_CObject* filename = getTypedArgument(p, request, 0, kUint8Array); 138 Dart_CObject* filename = getTypedArgument(p, request, 0, kUint8Array);
141 if (filename == NULL) return; 139 if (filename == NULL) return;
142 140
143 int result = archive_read_open_memory(a, filename->value.as_byte_array.values, 141 int result = archive_read_open_memory(a, filename->value.as_byte_array.values,
144 filename->value.as_byte_array.length); 142 filename->value.as_byte_array.length);
145 checkResult(p, a, result); 143 checkResult(p, a, result);
146 } 144 }
147 145
148 #define RAW_ARCHIVE_SIZE 32
149
150 void archiveReadNextHeader(Dart_Port p, struct archive* a) { 146 void archiveReadNextHeader(Dart_Port p, struct archive* a) {
151 // TODO(nweiz): At some point, we'll want to attach the actual archive pointer 147 // 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 148 // 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 149 // 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 150 // to create it and we'll have to attach a finalizer to the Dart object to
155 // ensure that it gets freed. 151 // ensure that it gets freed.
156 struct archive_entry* entry; 152 struct archive_entry* entry = archive_entry_new();
157 int result = archive_read_next_header(a, &entry); 153 if (checkPointerError(p, entry, "archive entry")) return;
154
155 int result = archive_read_next_header2(a, entry);
158 if (result == ARCHIVE_EOF) { 156 if (result == ARCHIVE_EOF) {
159 postSuccess(p, NULL); 157 postSuccess(p, NULL);
160 return; 158 archive_entry_free(entry);
159 } else if (checkError(p, a, result)) {
160 archive_entry_free(entry);
161 } else {
162 postArchiveEntryArray(p, entry);
161 } 163 }
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 } 164 }
313 165
314 void archiveReadDataBlock(Dart_Port p, struct archive* a) { 166 void archiveReadDataBlock(Dart_Port p, struct archive* a) {
315 const void* buffer; 167 const void* buffer;
316 size_t len; 168 size_t len;
317 int64_t offset; 169 int64_t offset;
318 int result = archive_read_data_block(a, &buffer, &len, &offset); 170 int result = archive_read_data_block(a, &buffer, &len, &offset);
319 if (result == ARCHIVE_EOF) { 171 if (result == ARCHIVE_EOF) {
320 postSuccess(p, NULL); 172 postSuccess(p, NULL);
321 return; 173 return;
(...skipping 14 matching lines...) Expand all
336 // TODO(nweiz): wrap archive_read_into_fd when issue 4160 is fixed 188 // TODO(nweiz): wrap archive_read_into_fd when issue 4160 is fixed
337 // TODO(nweiz): wrap archive_read_extract and friends 189 // TODO(nweiz): wrap archive_read_extract and friends
338 190
339 void archiveReadClose(Dart_Port p, struct archive* a) { 191 void archiveReadClose(Dart_Port p, struct archive* a) {
340 checkResult(p, a, archive_read_close(a)); 192 checkResult(p, a, archive_read_close(a));
341 } 193 }
342 194
343 void archiveReadFree(Dart_Port p, struct archive* a) { 195 void archiveReadFree(Dart_Port p, struct archive* a) {
344 checkResult(p, a, archive_read_free(a)); 196 checkResult(p, a, archive_read_free(a));
345 } 197 }
OLDNEW
« no previous file with comments | « utils/archive/read_request.dart ('k') | utils/archive/reader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698