From 9f879a846fdcc6e6fe2ad76f7d4f01179a7633b3 Mon Sep 17 00:00:00 2001 From: Adam Jacob Muller Date: Mon, 20 Jun 2011 21:42:52 -0400 Subject: [PATCH 1/2] handle binary plist files --- classes/parsers/plist/PlistParser.inc | 35 ++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/classes/parsers/plist/PlistParser.inc b/classes/parsers/plist/PlistParser.inc index 412781b..7f2c257 100644 --- a/classes/parsers/plist/PlistParser.inc +++ b/classes/parsers/plist/PlistParser.inc @@ -2,6 +2,7 @@ class plistParser extends XMLReader { + var $filename; public function parse($file) { trigger_error( 'plistParser::parse() is deprecated, please use plistParser::parseFile()', @@ -15,12 +16,40 @@ class plistParser extends XMLReader if(basename($file) == $file) { throw new Exception("Non-relative file path expected", 1); } - $this->open("file://" . $file); - return $this->process(); + $string=file_get_contents($file,false,null,-1,8); + if ($string=="bplist00") { + return $this->binary2xml($file); + } else { + $this->open("file://" . $file); + return $this->process(); + } } + private function binary2xml($infile) { + if (file_exists("/usr/bin/plutil")===false) { + throw new Exception("converting binary plists requires plutil and /usr/bin/plutil does not appear to exist"); + } + $tmpfile=tempnam("/tmp","plistParser"); + $cmd=sprintf("/usr/bin/plutil -convert xml1 -o %s %s",escapeshellarg($tmpfile),escapeshellarg($infile)); + $output=array(); + exec($cmd,$output,$rc); + if ($rc>0) { + var_dump($cmd); + print_r($output); + throw new Exception("plutil failed"); + } + $this->open("file://".$tmpfile); + unlink($tmpfile); + return $this->process(); + } public function parseString($string) { - $this->XML($string); + if (substr($string,0.8)=="bplist00") { + $tmpfile=tempnam("/tmp","plistParser"); + file_put_contents($tmpfile,$string); + return $this->binary2xml($file); + } else { + $this->XML($string); + } return $this->process(); } From 374fcc4c8303e49c4be927a0cb244222e699a0b6 Mon Sep 17 00:00:00 2001 From: Adam Jacob Muller Date: Mon, 20 Jun 2011 21:49:27 -0400 Subject: [PATCH 2/2] remove extranious variable --- classes/parsers/plist/PlistParser.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/classes/parsers/plist/PlistParser.inc b/classes/parsers/plist/PlistParser.inc index 7f2c257..3a311aa 100644 --- a/classes/parsers/plist/PlistParser.inc +++ b/classes/parsers/plist/PlistParser.inc @@ -2,7 +2,6 @@ class plistParser extends XMLReader { - var $filename; public function parse($file) { trigger_error( 'plistParser::parse() is deprecated, please use plistParser::parseFile()',