ctb_formats_alias/bookmark.rs
1// SPDX-License-Identifier: AGPL-3.0-or-later AND MIT AND Artistic-2.0
2// SPDX-License-Identifier for parts derived from mac_alias: MIT
3// SPDX-License-Identifier for parts derived from Mac-Alias: Artistic-2.0
4/*
5This file is part of Collective Toolbox, a database and document workspace and utilities.
6Copyright (C) 2026 Collective Toolbox Developers
7Contact: info@collectivetoolbox.com
8
9This program is free software: you can redistribute it and/or modify it under
10the terms of the GNU Affero General Public License as published by the Free
11Software Foundation, either version 3 of the License, or (at your option) any
12later version.
13
14This program is distributed in the hope that it will be useful, but WITHOUT ANY
15WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
17
18You should have received a copy of the GNU Affero General Public License along
19with this program. If not, see <https://www.gnu.org/licenses/>.
20*/
21
22// See additional licensing details at end of file.
23
24// Parts derived from mac_alias:
25// Copyright (c) 2014 Alastair Houghton
26// Copyright (c) 2022 Russell Keith-Magee
27// From https://github.com/dmgbuild/mac_alias
28
29// Parts derived from Mac-Alias:
30// Author: "Arne Johannessen <ajnn@cpan.org>"
31// From https://www.cpan.org/authors/id/A/AJ/AJNN/Mac-Alias-1.01.tar.gz
32
33//! macOS Bookmark format parsing and path resolution.
34
35#[allow(
36 unused_imports,
37 clippy::wildcard_imports,
38 reason = "Standard workspace module prelude"
39)]
40use crate::utilities::*;
41
42use std::collections::BTreeMap;
43use std::path::{Path, PathBuf};
44
45use crate::AliasRecord;
46use crate::shared::{
47 build_posix_path_from_components, normalize_path_string, read_u32_le,
48};
49
50const BOOKMARK_MAGIC: &[u8; 4] = b"book";
51const BOOKMARK_MAGIC_ALIAS: &[u8; 4] = b"alis";
52
53const BOOKMARK_HEADER_SIZE: usize = 48;
54const BOOKMARK_UNKNOWN_VERSION: u32 = 0x1004_0000;
55const BOOKMARK_TOC_MAGIC: u32 = 0xffff_fffe;
56
57const BOOKMARK_KEY_TARGET_PATH_COMPONENTS: u32 = 0x1004;
58const BOOKMARK_KEY_TARGET_URL: u32 = 0x1003;
59const BOOKMARK_KEY_TARGET_FILENAME: u32 = 0x1020;
60const BOOKMARK_KEY_DISPLAY_NAME: u32 = 0xf017;
61const BOOKMARK_KEY_ALIAS_DATA: u32 = 0xfe00;
62
63const BOOKMARK_TYPE_STRING: u32 = 0x0101;
64const BOOKMARK_TYPE_DATA: u32 = 0x0201;
65const BOOKMARK_TYPE_ARRAY: u32 = 0x0601;
66const BOOKMARK_TYPE_URL: u32 = 0x0901;
67
68/// Creates a basic Mac bookmark file pointing at a target.
69pub fn create_simple_bookmark<P: AsRef<Path>>(
70 target_path: P,
71 name: Option<&str>,
72) -> Result<Vec<u8>> {
73 let target_path = target_path.as_ref();
74 let path_string = normalize_path_string(target_path)?;
75 // Reason for fallback: when display name is omitted and target_path has no filename component (e.g. root directory "/"), use full normalized path string as display name.
76 let display_name = name
77 .map(str::to_owned)
78 .or_else(|| {
79 target_path
80 .file_name()
81 .map(|value| value.to_string_lossy().to_string())
82 })
83 .unwrap_or_else(|| path_string.clone());
84
85 let alias_record = AliasRecord::new_simple(&path_string, name)?;
86 let alias_record_bytes = alias_record.to_bytes()?;
87 build_bookmark_file(&path_string, &display_name, &alias_record_bytes)
88}
89
90/// Reads the target path from a Mac bookmark file.
91pub fn read_path_from_bookmark<P: AsRef<Path>>(
92 bookmark_path: P,
93) -> Result<PathBuf> {
94 let bytes = std::fs::read(bookmark_path.as_ref()).with_context(|| {
95 format!(
96 "Failed to read bookmark file {}",
97 bookmark_path.as_ref().display()
98 )
99 })?;
100 read_path_from_bookmark_bytes(&bytes)
101}
102
103/// Reads the target path from a Mac bookmark file's bytes.
104pub fn read_path_from_bookmark_bytes(bytes: &[u8]) -> Result<PathBuf> {
105 let header = parse_bookmark_header(bytes)?;
106 let toc_entries = parse_bookmark_toc_entries(bytes, &header)?;
107
108 if let Some(offset) = toc_entries.get(&BOOKMARK_KEY_TARGET_PATH_COMPONENTS)
109 {
110 let components =
111 read_bookmark_path_components(bytes, &header, *offset)?;
112 return Ok(build_posix_path_from_components(&components));
113 }
114
115 if let Some(offset) = toc_entries.get(&BOOKMARK_KEY_TARGET_URL) {
116 if let Some(path) = read_bookmark_url_path(bytes, &header, *offset)? {
117 return Ok(path);
118 }
119 }
120
121 bail!("Bookmark did not contain a target path")
122}
123
124fn read_bookmark_path_components(
125 bytes: &[u8],
126 header: &BookmarkHeader,
127 offset: u32,
128) -> Result<Vec<String>> {
129 let record = read_bookmark_record(bytes, header, offset)?;
130 if record.record_type != BOOKMARK_TYPE_ARRAY {
131 bail!("Bookmark path components were not stored as an array");
132 }
133
134 if record.data.len() % 4 != 0 {
135 bail!("Bookmark path component array had invalid length");
136 }
137
138 let mut components = Vec::new();
139 let mut offset_index = 0usize;
140 while offset_index < record.data.len() {
141 let end = offset_index
142 .checked_add(4)
143 .context("Bookmark path component offset overflow")?;
144 let slice = record
145 .data
146 .get(offset_index..end)
147 .context("Bookmark path component offset out of range")?;
148 let slice_array: [u8; 4] = slice.try_into()?;
149 let offset_value = u32::from_le_bytes(slice_array);
150 let component_record =
151 read_bookmark_record(bytes, header, offset_value)?;
152 if component_record.record_type != BOOKMARK_TYPE_STRING {
153 bail!("Bookmark path component was not a string");
154 }
155 let component = String::from_utf8(component_record.data)
156 .context("Bookmark path component was not UTF-8")?;
157 components.push(component);
158 offset_index = end;
159 }
160
161 Ok(components)
162}
163
164fn read_bookmark_url_path(
165 bytes: &[u8],
166 header: &BookmarkHeader,
167 offset: u32,
168) -> Result<Option<PathBuf>> {
169 let record = read_bookmark_record(bytes, header, offset)?;
170 if record.record_type != BOOKMARK_TYPE_URL
171 && record.record_type != BOOKMARK_TYPE_STRING
172 {
173 return Ok(None);
174 }
175
176 let url =
177 String::from_utf8(record.data).context("Bookmark URL was not UTF-8")?;
178 if let Some(path) = url.strip_prefix("file://") {
179 let path = path.trim_start_matches('/');
180 return Ok(Some(PathBuf::from("/").join(path)));
181 }
182
183 Ok(None)
184}
185
186#[derive(Debug, Clone)]
187struct BookmarkHeader {
188 header_size: usize,
189 toc_offset: u32,
190}
191
192fn parse_bookmark_header(bytes: &[u8]) -> Result<BookmarkHeader> {
193 if bytes.len() >= BOOKMARK_HEADER_SIZE
194 && (bytes.starts_with(BOOKMARK_MAGIC)
195 || bytes.starts_with(BOOKMARK_MAGIC_ALIAS))
196 {
197 let header_size = read_u32_le(bytes, 12)?;
198 let header_size = usize::try_from(header_size)
199 .context("Bookmark header size overflow")?;
200 let header_size = header_size.max(BOOKMARK_HEADER_SIZE);
201 let toc_offset = read_u32_le(bytes, header_size)?;
202 return Ok(BookmarkHeader {
203 header_size,
204 toc_offset,
205 });
206 }
207
208 bail!("Not a bookmark file")
209}
210
211fn parse_bookmark_toc_entries(
212 bytes: &[u8],
213 header: &BookmarkHeader,
214) -> Result<BTreeMap<u32, u32>> {
215 let mut entries = BTreeMap::new();
216 let mut next_offset = header.toc_offset;
217
218 while next_offset != 0 {
219 let toc_start = bookmark_offset(header, next_offset)?;
220 let toc_size_minus_8 = read_u32_le(bytes, toc_start)?;
221 let toc_magic = read_u32_le(bytes, toc_start.saturating_add(4))?;
222 if toc_magic != BOOKMARK_TOC_MAGIC {
223 bail!("Bookmark TOC had invalid magic");
224 }
225 let next = read_u32_le(bytes, toc_start.saturating_add(12))?;
226 let count = read_u32_le(bytes, toc_start.saturating_add(16))?;
227
228 let count_usize =
229 usize::try_from(count).context("Bookmark TOC count overflow")?;
230 let mut entry_offset = toc_start
231 .checked_add(20)
232 .context("Bookmark TOC offset overflow")?;
233 let toc_size_usize = usize::try_from(toc_size_minus_8)
234 .context("Bookmark TOC size overflow")?
235 .checked_add(8)
236 .context("Bookmark TOC size overflow")?;
237 let toc_end = toc_start
238 .checked_add(toc_size_usize)
239 .context("Bookmark TOC end overflow")?;
240 for _ in 0..count_usize {
241 if entry_offset
242 .checked_add(12)
243 .context("Bookmark TOC entry overflow")?
244 > toc_end
245 {
246 break;
247 }
248 let key = read_u32_le(bytes, entry_offset)?;
249 let offset = read_u32_le(bytes, entry_offset.saturating_add(4))?;
250 entries.insert(key, offset);
251 entry_offset = entry_offset
252 .checked_add(12)
253 .context("Bookmark TOC entry overflow")?;
254 }
255
256 next_offset = next;
257 }
258
259 Ok(entries)
260}
261
262#[derive(Debug)]
263struct BookmarkRecord {
264 record_type: u32,
265 data: Vec<u8>,
266}
267
268fn read_bookmark_record(
269 bytes: &[u8],
270 header: &BookmarkHeader,
271 offset: u32,
272) -> Result<BookmarkRecord> {
273 let record_start = bookmark_offset(header, offset)?;
274 let length = read_u32_le(bytes, record_start)?;
275 let record_type = read_u32_le(bytes, record_start.saturating_add(4))?;
276 let length_usize =
277 usize::try_from(length).context("Bookmark record size overflow")?;
278 let data_start = record_start
279 .checked_add(8)
280 .context("Bookmark record data overflow")?;
281 let data_end = data_start
282 .checked_add(length_usize)
283 .context("Bookmark record data overflow")?;
284 let data = bytes
285 .get(data_start..data_end)
286 .context("Bookmark record data out of bounds")?
287 .to_vec();
288 Ok(BookmarkRecord { record_type, data })
289}
290
291fn bookmark_offset(header: &BookmarkHeader, relative: u32) -> Result<usize> {
292 let relative =
293 usize::try_from(relative).context("Bookmark offset overflow")?;
294 header
295 .header_size
296 .checked_add(relative)
297 .context("Bookmark offset overflow")
298}
299
300fn build_bookmark_file(
301 target_path: &str,
302 display_name: &str,
303 alias_record: &[u8],
304) -> Result<Vec<u8>> {
305 let components = target_path
306 .trim_start_matches('/')
307 .split('/')
308 .filter(|component| !component.is_empty())
309 .map(str::to_owned)
310 .collect::<Vec<_>>();
311
312 // Reason for fallback: when normalized path components vector is empty (e.g. root directory "/"), file_name defaults to display_name string.
313 let file_name = components
314 .last()
315 .cloned()
316 .unwrap_or_else(|| display_name.to_string());
317
318 let mut records = Vec::new();
319 let component_record_indices = components
320 .iter()
321 .map(|component| {
322 records.push(BookmarkRecordBuilder::string(component));
323 records.len().saturating_sub(1)
324 })
325 .collect::<Vec<_>>();
326
327 let path_array_index = records.len();
328 records.push(BookmarkRecordBuilder::array(component_record_indices));
329
330 let file_name_index = records.len();
331 records.push(BookmarkRecordBuilder::string(&file_name));
332
333 let display_name_index = records.len();
334 records.push(BookmarkRecordBuilder::string(display_name));
335
336 let alias_data_index = records.len();
337 records.push(BookmarkRecordBuilder::data(alias_record));
338
339 let offsets = compute_record_offsets(&records)?;
340
341 let mut toc_entries = BTreeMap::new();
342 toc_entries.insert(
343 BOOKMARK_KEY_TARGET_PATH_COMPONENTS,
344 *offsets
345 .get(path_array_index)
346 .context("Missing path array index")?,
347 );
348 toc_entries.insert(
349 BOOKMARK_KEY_TARGET_FILENAME,
350 *offsets
351 .get(file_name_index)
352 .context("Missing file name index")?,
353 );
354 toc_entries.insert(
355 BOOKMARK_KEY_DISPLAY_NAME,
356 *offsets
357 .get(display_name_index)
358 .context("Missing display name index")?,
359 );
360 toc_entries.insert(
361 BOOKMARK_KEY_ALIAS_DATA,
362 *offsets
363 .get(alias_data_index)
364 .context("Missing alias data index")?,
365 );
366
367 let mut bytes = Vec::new();
368 bytes.extend_from_slice(BOOKMARK_MAGIC);
369 bytes.extend_from_slice(&0u32.to_le_bytes());
370 bytes.extend_from_slice(&BOOKMARK_UNKNOWN_VERSION.to_le_bytes());
371 bytes
372 .extend_from_slice(&u32::try_from(BOOKMARK_HEADER_SIZE)?.to_le_bytes());
373 bytes.extend_from_slice(&[0u8; 32]);
374
375 let toc_offset = compute_toc_offset(&records)?;
376 bytes.extend_from_slice(&toc_offset.to_le_bytes());
377
378 for record in &records {
379 let data = record.to_bytes(&offsets)?;
380 bytes.extend_from_slice(&data);
381 }
382
383 bytes.extend_from_slice(&build_toc(&toc_entries)?);
384
385 let total_size =
386 u32::try_from(bytes.len()).context("Bookmark size overflow")?;
387 bytes
388 .get_mut(4..8)
389 .context("Bytes too short to write total size")?
390 .copy_from_slice(&total_size.to_le_bytes());
391 Ok(bytes)
392}
393
394fn compute_record_offsets(
395 records: &[BookmarkRecordBuilder],
396) -> Result<Vec<u32>> {
397 let mut offsets = Vec::with_capacity(records.len());
398 let mut cursor = u32::from(4u8);
399 for record in records {
400 offsets.push(cursor);
401 let record_len = record.total_size()?;
402 cursor = cursor
403 .checked_add(record_len)
404 .context("Bookmark record overflow")?;
405 }
406 Ok(offsets)
407}
408
409fn compute_toc_offset(records: &[BookmarkRecordBuilder]) -> Result<u32> {
410 let offsets = compute_record_offsets(records)?;
411 // Reason for fallback: when bookmark records slice is empty, TOC cursor starts immediately after the 4-byte bookmark magic header (offset 4).
412 let mut cursor = offsets.last().copied().unwrap_or(4u32);
413 if let Some(last) = records.last() {
414 cursor = cursor
415 .checked_add(last.total_size()?)
416 .context("Bookmark record overflow")?;
417 }
418 Ok(cursor)
419}
420
421fn build_toc(entries: &BTreeMap<u32, u32>) -> Result<Vec<u8>> {
422 let count =
423 u32::try_from(entries.len()).context("TOC entry count overflow")?;
424 let toc_size = 20u32
425 .checked_add(count.checked_mul(12).context("TOC size overflow")?)
426 .context("TOC size overflow")?;
427 let toc_size_minus_8 =
428 toc_size.checked_sub(8).context("TOC size overflow")?;
429
430 let mut bytes = Vec::new();
431 bytes.extend_from_slice(&toc_size_minus_8.to_le_bytes());
432 bytes.extend_from_slice(&BOOKMARK_TOC_MAGIC.to_le_bytes());
433 bytes.extend_from_slice(&1u32.to_le_bytes());
434 bytes.extend_from_slice(&0u32.to_le_bytes());
435 bytes.extend_from_slice(&count.to_le_bytes());
436 for (key, offset) in entries {
437 bytes.extend_from_slice(&key.to_le_bytes());
438 bytes.extend_from_slice(&offset.to_le_bytes());
439 bytes.extend_from_slice(&0u32.to_le_bytes());
440 }
441 Ok(bytes)
442}
443
444#[derive(Debug, Clone)]
445enum BookmarkRecordBuilder {
446 String(String),
447 Data(Vec<u8>),
448 Array(Vec<usize>),
449}
450
451impl BookmarkRecordBuilder {
452 fn string(value: &str) -> Self {
453 Self::String(value.to_string())
454 }
455
456 fn data(value: &[u8]) -> Self {
457 Self::Data(value.to_vec())
458 }
459
460 fn array(indices: Vec<usize>) -> Self {
461 Self::Array(indices)
462 }
463
464 fn record_type(&self) -> u32 {
465 match self {
466 Self::String(_) => BOOKMARK_TYPE_STRING,
467 Self::Data(_) => BOOKMARK_TYPE_DATA,
468 Self::Array(_) => BOOKMARK_TYPE_ARRAY,
469 }
470 }
471
472 fn data_len(&self) -> Result<u32> {
473 match self {
474 Self::String(value) => {
475 u32::try_from(value.len()).context("Bookmark string too large")
476 }
477 Self::Data(value) => {
478 u32::try_from(value.len()).context("Bookmark data too large")
479 }
480 Self::Array(values) => {
481 let len = u32::try_from(values.len())
482 .context("Bookmark array too large")?;
483 len.checked_mul(4).context("Bookmark array too large")
484 }
485 }
486 }
487
488 fn total_size(&self) -> Result<u32> {
489 self.data_len()?
490 .checked_add(8)
491 .context("Bookmark record too large")
492 }
493
494 fn to_bytes(&self, offsets: &[u32]) -> Result<Vec<u8>> {
495 let mut bytes = Vec::new();
496 let data = match self {
497 Self::String(value) => value.as_bytes().to_vec(),
498 Self::Data(value) => value.clone(),
499 Self::Array(values) => {
500 let mut data = Vec::new();
501 for index in values {
502 let offset = offsets
503 .get(*index)
504 .context("Bookmark array index out of range")?;
505 data.extend_from_slice(&offset.to_le_bytes());
506 }
507 data
508 }
509 };
510 let data_len =
511 u32::try_from(data.len()).context("Bookmark record too large")?;
512 bytes.extend_from_slice(&data_len.to_le_bytes());
513 bytes.extend_from_slice(&self.record_type().to_le_bytes());
514 bytes.extend_from_slice(&data);
515 Ok(bytes)
516 }
517}
518
519#[cfg(test)]
520#[allow(
521 clippy::panic,
522 clippy::expect_used,
523 clippy::unwrap_used,
524 clippy::unwrap_in_result,
525 clippy::panic_in_result_fn,
526 clippy::indexing_slicing,
527 clippy::arithmetic_side_effects,
528 reason = "Standard repository test boilerplate"
529)]
530mod tests {
531 use std::fs;
532 use std::path::PathBuf;
533
534 use tempfile::TempDir;
535
536 use super::*;
537
538 #[crate::ctb_test]
539 fn test_create_bookmark_round_trip_bytes() {
540 let bytes = create_simple_bookmark(
541 "/tmp/ctb/bookmark-target.txt",
542 Some("bookmark-target"),
543 )
544 .unwrap();
545 let target = read_path_from_bookmark_bytes(&bytes).unwrap();
546 assert_eq!(target, PathBuf::from("/tmp/ctb/bookmark-target.txt"));
547 }
548
549 #[crate::ctb_test]
550 fn test_create_bookmark_round_trip_file() {
551 let dir = TempDir::new().unwrap();
552 let bytes =
553 create_simple_bookmark("/tmp/ctb/bookmark-target.txt", None)
554 .unwrap();
555 let path = dir.path().join("bookmark");
556 fs::write(&path, bytes).unwrap();
557 let target = read_path_from_bookmark(&path).unwrap();
558 assert_eq!(target, PathBuf::from("/tmp/ctb/bookmark-target.txt"));
559 }
560}
561
562/*
563
564// From mac_alias:
565
566MIT License
567
568Copyright (c) 2014 Alastair Houghton
569Copyright (c) 2022 Russell Keith-Magee
570
571Permission is hereby granted, free of charge, to any person obtaining a copy
572of this software and associated documentation files (the "Software"), to deal
573in the Software without restriction, including without limitation the rights
574to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
575copies of the Software, and to permit persons to whom the Software is
576furnished to do so, subject to the following conditions:
577
578The above copyright notice and this permission notice shall be included in
579all copies or substantial portions of the Software.
580
581THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
582IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
583FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
584AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
585LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
586OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
587THE SOFTWARE.
588
589
590// From Mac-Alias:
591
592 The Artistic License 2.0
593
594 Copyright (c) 2000-2006, The Perl Foundation.
595
596 Everyone is permitted to copy and distribute verbatim copies
597 of this license document, but changing it is not allowed.
598
599Preamble
600
601This license establishes the terms under which a given free software
602Package may be copied, modified, distributed, and/or redistributed.
603The intent is that the Copyright Holder maintains some artistic
604control over the development of that Package while still keeping the
605Package available as open source and free software.
606
607You are always permitted to make arrangements wholly outside of this
608license directly with the Copyright Holder of a given Package. If the
609terms of this license do not permit the full use that you propose to
610make of the Package, you should contact the Copyright Holder and seek
611a different licensing arrangement.
612
613Definitions
614
615 "Copyright Holder" means the individual(s) or organization(s)
616 named in the copyright notice for the entire Package.
617
618 "Contributor" means any party that has contributed code or other
619 material to the Package, in accordance with the Copyright Holder's
620 procedures.
621
622 "You" and "your" means any person who would like to copy,
623 distribute, or modify the Package.
624
625 "Package" means the collection of files distributed by the
626 Copyright Holder, and derivatives of that collection and/or of
627 those files. A given Package may consist of either the Standard
628 Version, or a Modified Version.
629
630 "Distribute" means providing a copy of the Package or making it
631 accessible to anyone else, or in the case of a company or
632 organization, to others outside of your company or organization.
633
634 "Distributor Fee" means any fee that you charge for Distributing
635 this Package or providing support for this Package to another
636 party. It does not mean licensing fees.
637
638 "Standard Version" refers to the Package if it has not been
639 modified, or has been modified only in ways explicitly requested
640 by the Copyright Holder.
641
642 "Modified Version" means the Package, if it has been changed, and
643 such changes were not explicitly requested by the Copyright
644 Holder.
645
646 "Original License" means this Artistic License as Distributed with
647 the Standard Version of the Package, in its current version or as
648 it may be modified by The Perl Foundation in the future.
649
650 "Source" form means the source code, documentation source, and
651 configuration files for the Package.
652
653 "Compiled" form means the compiled bytecode, object code, binary,
654 or any other form resulting from mechanical transformation or
655 translation of the Source form.
656
657
658Permission for Use and Modification Without Distribution
659
660(1) You are permitted to use the Standard Version and create and use
661Modified Versions for any purpose without restriction, provided that
662you do not Distribute the Modified Version.
663
664
665Permissions for Redistribution of the Standard Version
666
667(2) You may Distribute verbatim copies of the Source form of the
668Standard Version of this Package in any medium without restriction,
669either gratis or for a Distributor Fee, provided that you duplicate
670all of the original copyright notices and associated disclaimers. At
671your discretion, such verbatim copies may or may not include a
672Compiled form of the Package.
673
674(3) You may apply any bug fixes, portability changes, and other
675modifications made available from the Copyright Holder. The resulting
676Package will still be considered the Standard Version, and as such
677will be subject to the Original License.
678
679
680Distribution of Modified Versions of the Package as Source
681
682(4) You may Distribute your Modified Version as Source (either gratis
683or for a Distributor Fee, and with or without a Compiled form of the
684Modified Version) provided that you clearly document how it differs
685from the Standard Version, including, but not limited to, documenting
686any non-standard features, executables, or modules, and provided that
687you do at least ONE of the following:
688
689 (a) make the Modified Version available to the Copyright Holder
690 of the Standard Version, under the Original License, so that the
691 Copyright Holder may include your modifications in the Standard
692 Version.
693
694 (b) ensure that installation of your Modified Version does not
695 prevent the user installing or running the Standard Version. In
696 addition, the Modified Version must bear a name that is different
697 from the name of the Standard Version.
698
699 (c) allow anyone who receives a copy of the Modified Version to
700 make the Source form of the Modified Version available to others
701 under
702
703 (i) the Original License or
704
705 (ii) a license that permits the licensee to freely copy,
706 modify and redistribute the Modified Version using the same
707 licensing terms that apply to the copy that the licensee
708 received, and requires that the Source form of the Modified
709 Version, and of any works derived from it, be made freely
710 available in that license fees are prohibited but Distributor
711 Fees are allowed.
712
713
714Distribution of Compiled Forms of the Standard Version
715or Modified Versions without the Source
716
717(5) You may Distribute Compiled forms of the Standard Version without
718the Source, provided that you include complete instructions on how to
719get the Source of the Standard Version. Such instructions must be
720valid at the time of your distribution. If these instructions, at any
721time while you are carrying out such distribution, become invalid, you
722must provide new instructions on demand or cease further distribution.
723If you provide valid instructions or cease distribution within thirty
724days after you become aware that the instructions are invalid, then
725you do not forfeit any of your rights under this license.
726
727(6) You may Distribute a Modified Version in Compiled form without
728the Source, provided that you comply with Section 4 with respect to
729the Source of the Modified Version.
730
731
732Aggregating or Linking the Package
733
734(7) You may aggregate the Package (either the Standard Version or
735Modified Version) with other packages and Distribute the resulting
736aggregation provided that you do not charge a licensing fee for the
737Package. Distributor Fees are permitted, and licensing fees for other
738components in the aggregation are permitted. The terms of this license
739apply to the use and Distribution of the Standard or Modified Versions
740as included in the aggregation.
741
742(8) You are permitted to link Modified and Standard Versions with
743other works, to embed the Package in a larger work of your own, or to
744build stand-alone binary or bytecode versions of applications that
745include the Package, and Distribute the result without restriction,
746provided the result does not expose a direct interface to the Package.
747
748
749Items That are Not Considered Part of a Modified Version
750
751(9) Works (including, but not limited to, modules and scripts) that
752merely extend or make use of the Package, do not, by themselves, cause
753the Package to be a Modified Version. In addition, such works are not
754considered parts of the Package itself, and are not subject to the
755terms of this license.
756
757
758General Provisions
759
760(10) Any use, modification, and distribution of the Standard or
761Modified Versions is governed by this Artistic License. By using,
762modifying or distributing the Package, you accept this license. Do not
763use, modify, or distribute the Package, if you do not accept this
764license.
765
766(11) If your Modified Version has been derived from a Modified
767Version made by someone other than you, you are nevertheless required
768to ensure that your Modified Version complies with the requirements of
769this license.
770
771(12) This license does not grant you the right to use any trademark,
772service mark, tradename, or logo of the Copyright Holder.
773
774(13) This license includes the non-exclusive, worldwide,
775free-of-charge patent license to make, have made, use, offer to sell,
776sell, import and otherwise transfer the Package with respect to any
777patent claims licensable by the Copyright Holder that are necessarily
778infringed by the Package. If you institute patent litigation
779(including a cross-claim or counterclaim) against any party alleging
780that the Package constitutes direct or contributory patent
781infringement, then this Artistic License to you shall terminate on the
782date that such litigation is filed.
783
784(14) Disclaimer of Warranty:
785THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
786IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
787WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
788NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL
789LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL
790BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
791DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF
792ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
793
794*/