|
@@ -101,6 +101,28 @@ function read_authenticated_message($handle, $ppcl) {
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
+function get_ppub_length_after_truncation($ppub_name, $truncation_level) {
|
|
|
+ include_once("ppub.php");
|
|
|
+
|
|
|
+ $ppub = new Ppub();
|
|
|
+ $ppub->read_file(PUBLICATION_DIR . "/" . $ppub_name);
|
|
|
+
|
|
|
+ if($truncation_level == 3) {
|
|
|
+ // TRUNCATE_AFTER_HEADER
|
|
|
+ return $ppub->blob_start;
|
|
|
+ }
|
|
|
+ else if($truncation_level == 2) {
|
|
|
+ // send_failure(1, "Truncation level " . $truncation_level . " on publication " . PUBLICATION_DIR . "/" . $ppub_name);
|
|
|
+ // TRUNCATE_AFTER_METADATA
|
|
|
+ return $ppub->asset_list[0]->end_location + $ppub->blob_start;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // TRUNCATE_AFTER_DEFAULT_ASSET
|
|
|
+ return $ppub->asset_list[1]->end_location + $ppub->blob_start;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
if(!ENABLE_PPRF) {
|
|
|
send_failure(1, "PPRF has been disabled on this server");
|
|
|
}
|
|
@@ -418,9 +440,16 @@ if($message_info["type"] == 4) {
|
|
|
$path = PUBLICATION_DIR . "/" . $name;
|
|
|
$size = filesize($path);
|
|
|
|
|
|
+ // Truncation level is derived from the first two flags of the request, 3 = 0b11
|
|
|
+ $truncation_level = ($flags & 3);
|
|
|
+ if($truncation_level > 0) {
|
|
|
+ $size = get_ppub_length_after_truncation($name, $truncation_level);
|
|
|
+ }
|
|
|
+
|
|
|
$ppub = fopen($path, 'rb');
|
|
|
-
|
|
|
- $message = "\x00\x00";
|
|
|
+
|
|
|
+ // Flags (currently only truncation flags supported)
|
|
|
+ $message = pack("v", $truncation_level);
|
|
|
$message .= pack("P", $size);
|
|
|
|
|
|
send_partial_message(133, $message);
|