function _get($type, $job_id) { if (substr($job_id, 0, 4) != 'http') { throw new UnexpectedValueException('Parameter 2 must be a URL: ' . $job_id); } $xml_string = http_get_url($job_id); // make sure we got a response, log it and parse into SimpleXML object if (!$xml_string) { throw new RuntimeException('Got no response from: ' . $job_id); } if (!empty($this->_options['LogResponses'])) { $this->log('RECEIVED from ' . $job_id . "\n" . $xml_string); } $xml = $this->_parseResponse($xml_string); $progress_tags = $xml->xpath('//Progress'); // default is error because tags not found $progress = -1; $tag_count = sizeof($progress_tags); $status = 'Progress or PercentDone tags not found in response: ' . $tag_count; if ($tag_count > 0) { $data = $progress_tags[$tag_count - 1]; if (!empty($data->PercentDone)) { $progress = (string) $data->PercentDone; if (!empty($data->Status)) { $status = (string) $data->Status; } } } if (!is_numeric($progress)) { $progress = 1; $status = htmlspecialchars(str_replace('"', "'", $xml_string)); } $result = array('percent' => $progress, 'status' => $status); return $result; }
function _get($type, $job_id) { $rest_endpoint = $this->_options['RESTEndPoint']; // make sure we have an endpoint to get progress info from if (!$rest_endpoint) { throw new UnexpectedValueException('Configuration option RestEndPoint required'); } // build and get url as xml string $url = end_with_slash($rest_endpoint) . 'mm.' . $this->getVersion() . '/rest/' . $type . '/' . $job_id; $xml_string = http_get_url($url); // make sure we got a response, log it and parse into SimpleXML object if (!$xml_string) { throw new RuntimeException('Got no response from: ' . $url); } if (!empty($this->_options['LogResponses'])) { $this->log('RECEIVED from ' . $url . "\n" . $xml_string); } $xml = $this->_parseResponse($xml_string); // default is one in case tags not found, so no error occurs $progress = 1; $status = 'Progress or PercentDone tags not found in response'; if (!empty($xml->Progress) && is_object($xml->Progress)) { $data = $xml->Progress[sizeof($xml->Progress) - 1]; if (!empty($data->PercentDone)) { $progress = (string) $data->PercentDone; if (!empty($data->Status)) { $status = (string) $data->Status; } } } if (!is_numeric($progress)) { $progress = 1; $status = htmlspecialchars(str_replace('"', "'", $xml_string)); } $result = array('percent' => $progress, 'status' => $status); return $result; }
function _codeFile() { $this->__cleanUpJob(); $file_time = microtime(true); $audio_path = ''; $video_path = ''; // load configuration URL and make sure it's not empty and can be parsed as XML $xml_string = http_get_url($this->_options['DecoderConfigURL']); if (!$xml_string) { throw new RuntimeException('No response from DecoderConfigURL: ' . $this->_options['DecoderConfigURL']); } $this->__mashXML = @simplexml_load_string($xml_string); if (!$this->__mashXML) { throw new RuntimeException('Unable to parse DecoderConfigURL: ' . $this->_options['DecoderConfigURL']); } // TODO: we should be respecting 'config' attributes in the tags! $this->__mashData = MovieMasher_Coder_Decoder::mashInfo($this->__mashXML, $this->_options['CoderBaseURL'], $this->_options['DecoderFPS'], $this->_options['DecoderExactRender']); if (empty($this->__mashData['duration'])) { throw new UnexpectedValueException('Unable to determine mash duration: ' . $this->_options['DecoderConfigURL']); } $no_audio = $this->_options['CoderNoAudio'] || !$this->__mashData['has_audio']; $no_video = $this->_options['CoderNoVideo'] || !$this->__mashData['has_video']; if ($no_video && $no_audio) { throw new UnexpectedValueException('You cannot set both CoderNoVideo and CoderNoAudio'); } if (!empty($this->_options['Verbose'])) { $this->log('MASH: ' . $this->__mashXML->asXML()); } $this->__cacheMedia(); if (!safe_path($this->_buildDir . 'build')) { throw new RuntimeException('Could not create path: ' . $this->_buildDir . 'build'); } // do flash first, since it's most likely to produce an error if (!$no_video) { $this->__buildFlash(); } if (!$no_audio) { $audio_path = $this->__buildAudio(); } if (!$no_video) { $video_path = $this->__buildVideo(); } $file_name = $this->_buildDir . $this->_options['CoderFilename'] . '.' . $this->_options['DecoderExtension']; $this->__buildMovie($file_name, $audio_path, $video_path); return $file_name; }
function __authCheck($signature, $data) { $err = ''; $auth_key = $this->_options['AuthKey']; $auth_key_format = $this->_options['AuthKeyFormat']; $key = http_get_url($auth_key); if (!$key) { throw new UnexpectedValueException('Could not load file: ' . $auth_key); } switch ($auth_key_format) { case 'ssh-rsa': $key = x509_from_rsa($key); if (!$key) { $err = 'Could not convert RSA to x509'; break; } // intentional fallthrough to x509 case 'x509': if (!public_verify($data, $signature, $key)) { $err = "Error authorizing request"; } break; default: $err = 'Unsupported AuthKeyFormat: ' . $auth_key_format; } if ($err) { throw new UnexpectedValueException($err); } }