OLD | NEW |
| (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 "entry.h" | |
6 #include "messaging.h" | |
7 #include "reader.h" | |
8 | |
9 void archiveReadNew(Dart_Port p) { | |
10 checkPointerResult(p, archive_read_new(), "archive input stream"); | |
11 } | |
12 | |
13 void archiveReadSupportFilterAll(Dart_Port p, struct archive* a) { | |
14 checkResult(p, a, archive_read_support_filter_all(a)); | |
15 } | |
16 | |
17 void archiveReadSupportFilterBzip2(Dart_Port p, struct archive* a) { | |
18 checkResult(p, a, archive_read_support_filter_bzip2(a)); | |
19 } | |
20 | |
21 void archiveReadSupportFilterCompress(Dart_Port p, struct archive* a) { | |
22 checkResult(p, a, archive_read_support_filter_compress(a)); | |
23 } | |
24 | |
25 void archiveReadSupportFilterGzip(Dart_Port p, struct archive* a) { | |
26 checkResult(p, a, archive_read_support_filter_gzip(a)); | |
27 } | |
28 | |
29 void archiveReadSupportFilterLzma(Dart_Port p, struct archive* a) { | |
30 checkResult(p, a, archive_read_support_filter_lzma(a)); | |
31 } | |
32 | |
33 void archiveReadSupportFilterXz(Dart_Port p, struct archive* a) { | |
34 checkResult(p, a, archive_read_support_filter_xz(a)); | |
35 } | |
36 | |
37 void archiveReadSupportFilterProgram(Dart_Port p, struct archive* a, | |
38 Dart_CObject* request) { | |
39 Dart_CObject* cmd = getTypedArgument(p, request, 0, kString); | |
40 if (cmd == NULL) return; | |
41 int result = archive_read_support_filter_program( | |
42 a, cmd->value.as_string); | |
43 checkResult(p, a, result); | |
44 } | |
45 | |
46 void archiveReadSupportFilterProgramSignature( | |
47 Dart_Port p, struct archive* a, Dart_CObject* request) { | |
48 Dart_CObject* cmd = getTypedArgument(p, request, 0, kString); | |
49 if (cmd == NULL) return; | |
50 | |
51 Dart_CObject* signature = getTypedArgument(p, request, 1, kUint8Array); | |
52 if (cmd == NULL) return; | |
53 | |
54 int result = archive_read_support_filter_program_signature( | |
55 a, cmd->value.as_string, signature->value.as_byte_array.values, | |
56 signature->value.as_byte_array.length); | |
57 checkResult(p, a, result); | |
58 } | |
59 | |
60 void archiveReadSupportFormatAll(Dart_Port p, struct archive* a) { | |
61 checkResult(p, a, archive_read_support_format_all(a)); | |
62 } | |
63 | |
64 void archiveReadSupportFormatAr(Dart_Port p, struct archive* a) { | |
65 checkResult(p, a, archive_read_support_format_ar(a)); | |
66 } | |
67 | |
68 void archiveReadSupportFormatCpio(Dart_Port p, struct archive* a) { | |
69 checkResult(p, a, archive_read_support_format_cpio(a)); | |
70 } | |
71 | |
72 void archiveReadSupportFormatEmpty(Dart_Port p, struct archive* a) { | |
73 checkResult(p, a, archive_read_support_format_empty(a)); | |
74 } | |
75 | |
76 void archiveReadSupportFormatIso9660(Dart_Port p, struct archive* a) { | |
77 checkResult(p, a, archive_read_support_format_iso9660(a)); | |
78 } | |
79 | |
80 void archiveReadSupportFormatMtree(Dart_Port p, struct archive* a) { | |
81 checkResult(p, a, archive_read_support_format_mtree(a)); | |
82 } | |
83 | |
84 void archiveReadSupportFormatRaw(Dart_Port p, struct archive* a) { | |
85 checkResult(p, a, archive_read_support_format_raw(a)); | |
86 } | |
87 | |
88 void archiveReadSupportFormatTar(Dart_Port p, struct archive* a) { | |
89 checkResult(p, a, archive_read_support_format_tar(a)); | |
90 } | |
91 | |
92 void archiveReadSupportFormatZip(Dart_Port p, struct archive* a) { | |
93 checkResult(p, a, archive_read_support_format_zip(a)); | |
94 } | |
95 | |
96 void archiveReadSetFilterOption(Dart_Port p, struct archive* a, | |
97 Dart_CObject* request) { | |
98 char* module; | |
99 char* name; | |
100 char* value; | |
101 | |
102 getOptionArguments(p, request, &module, &name, &value); | |
103 int result = archive_read_set_filter_option(a, module, name, value); | |
104 checkResult(p, a, result); | |
105 } | |
106 | |
107 void archiveReadSetFormatOptions(Dart_Port p, struct archive* a, | |
108 Dart_CObject* request) { | |
109 char* module; | |
110 char* name; | |
111 char* value; | |
112 | |
113 getOptionArguments(p, request, &module, &name, &value); | |
114 int result = archive_read_set_format_option(a, module, name, value); | |
115 checkResult(p, a, result); | |
116 } | |
117 | |
118 void archiveReadSetOptions(Dart_Port p, struct archive* a, | |
119 Dart_CObject* request) { | |
120 char* module; | |
121 char* name; | |
122 char* value; | |
123 | |
124 getOptionArguments(p, request, &module, &name, &value); | |
125 int result = archive_read_set_option(a, module, name, value); | |
126 checkResult(p, a, result); | |
127 } | |
128 | |
129 // TODO(nweiz): wrap archive_read_open2 | |
130 // TODO(nweiz): wrap archive_read_FILE when issue 4160 is fixed | |
131 | |
132 void archiveReadOpenFilename(Dart_Port p, struct archive* a, | |
133 Dart_CObject* request) { | |
134 Dart_CObject* filename = getTypedArgument(p, request, 0, kString); | |
135 if (filename == NULL) return; | |
136 | |
137 Dart_CObject* block_size = getIntArgument(p, request, 1); | |
138 if (block_size == NULL) return; | |
139 | |
140 int result = archive_read_open_filename(a, filename->value.as_string, | |
141 getInteger(block_size)); | |
142 checkResult(p, a, result); | |
143 } | |
144 | |
145 void archiveReadOpenMemory(Dart_Port p, struct archive* a, | |
146 Dart_CObject* request) { | |
147 Dart_CObject* filename = getTypedArgument(p, request, 0, kUint8Array); | |
148 if (filename == NULL) return; | |
149 | |
150 int result = archive_read_open_memory(a, filename->value.as_byte_array.values, | |
151 filename->value.as_byte_array.length); | |
152 checkResult(p, a, result); | |
153 } | |
154 | |
155 void archiveReadNextHeader(Dart_Port p, struct archive* a) { | |
156 // TODO(nweiz): At some point, we'll want to attach the actual archive pointer | |
157 // to the struct we send to Dart so that it can later be modified, passed in | |
158 // to other functions, etc. When we do so, we'll need to use archive_entry_new | |
159 // to create it and we'll have to attach a finalizer to the Dart object to | |
160 // ensure that it gets freed. | |
161 struct archive_entry* entry = archive_entry_new(); | |
162 if (checkPointerError(p, entry, "archive entry")) return; | |
163 | |
164 int result = archive_read_next_header2(a, entry); | |
165 if (result == ARCHIVE_EOF) { | |
166 postSuccess(p, NULL); | |
167 archive_entry_free(entry); | |
168 } else if (checkError(p, a, result)) { | |
169 archive_entry_free(entry); | |
170 } else { | |
171 postArchiveEntryArray(p, entry); | |
172 } | |
173 } | |
174 | |
175 void archiveReadDataBlock(Dart_Port p, struct archive* a) { | |
176 const void* buffer; | |
177 size_t len; | |
178 int64_t offset; | |
179 int result = archive_read_data_block(a, &buffer, &len, &offset); | |
180 if (result == ARCHIVE_EOF) { | |
181 postSuccess(p, NULL); | |
182 return; | |
183 } | |
184 if (checkError(p, a, result)) return; | |
185 | |
186 Dart_CObject wrapped_data_block; | |
187 wrapped_data_block.type = kUint8Array; | |
188 wrapped_data_block.value.as_byte_array.length = len; | |
189 wrapped_data_block.value.as_byte_array.values = (void*) buffer + offset; | |
190 postSuccess(p, &wrapped_data_block); | |
191 } | |
192 | |
193 void archiveReadDataSkip(Dart_Port p, struct archive* a) { | |
194 checkResult(p, a, archive_read_data_skip(a)); | |
195 } | |
196 | |
197 // TODO(nweiz): wrap archive_read_into_fd when issue 4160 is fixed | |
198 // TODO(nweiz): wrap archive_read_extract and friends | |
199 | |
200 void archiveReadClose(Dart_Port p, struct archive* a) { | |
201 checkResult(p, a, archive_read_close(a)); | |
202 } | |
203 | |
204 void archiveReadFree(Dart_Port p, struct archive* a) { | |
205 checkResult(p, a, archive_read_free(a)); | |
206 } | |
OLD | NEW |