5 $parms[
'download'] = getHttpVars(
'download',
'');
6 $parms[
'version'] = getHttpVars(
'version',
'');
7 $parms[
'buildid'] = getHttpVars(
'buildid',
'');
8 $parms[
'os'] = getHttpVars(
'os',
'');
9 $parms[
'arch'] = getHttpVars(
'arch',
'');
11 $parms[
'clientDir'] = $action->parent->getParam(
'OFFLINE_CLIENT_BUILD_OUTPUT_DIR',
'');
12 if( ! is_dir($parms[
'clientDir']) ) {
14 $err = sprintf(sprintf(
'OFFLINE_CLIENT_BUILD_OUTPUT_DIR: '._(
"OFFLINE:%s directory not found"), $parms[
'clientDir']));
15 error_log(__METHOD__.
" ".$err);
19 $parms[
'clientDir'] = realpath($parms[
'clientDir']);
21 switch( $parms[
'download'] ) {
36 header(
'HTTP/1.1 400 Bad Request');
37 header(
'Content-Type: text/plain');
41 header(
'HTTP/1.1 404 Not Found');
42 header(
'Content-Type: text/plain');
46 if( ! is_file($infoFile) ) {
49 $info = file_get_contents($infoFile);
50 if( $info ===
false ) {
53 $lines = preg_split(
'/\n/', $info);
54 $parsedInfo = array();
55 foreach( $lines as &$line ) {
57 if( preg_match(
'/^(?<key>[^=]+)=(?<value>.*)$/', $line, $m) ) {
58 $parsedInfo[$m[
'key']] = $m[
'value'];
66 if( ! is_file($filename) ) {
68 $err = sprintf(
"File '%s' not found.", $filename);
69 error_log(__METHOD__.
" ".$err);
73 $fh = fopen($filename,
'r');
76 $err = sprintf(
"Error opening file '%s'.", $filename);
77 error_log(__METHOD__.
" ".$err);
81 header(
'HTTP/1.1 200 OK');
82 header(
'Content-Type: ' . $type);
83 header(
'Content-Length: ' . filesize($filename));
91 $err = sprintf(
"Unknown download '%s'.", $parms[
'download']);
92 error_log(__METHOD__.
" ".$err);
98 $buildList =
getBuildFor($parms[
'os'], $parms[
'arch']);
99 if( count($buildList) <= 0 ) {
101 $err = sprintf(
"No builds found for {os='%s', arch='%s'}.", $parms[
'os'], $parms[
'arch']);
102 error_log(__METHOD__.
" ".$err);
107 $core_externurl = getParam(
'CORE_EXTERNURL');
109 $build = array_shift($buildList);
111 $completeInfoFile = sprintf(
'%s/%s.complete.mar.info', $parms[
'clientDir'], $build[
'mar_basename']);
112 $completeInfo =
parseInfo($completeInfoFile);
114 $partialInfoFile = sprintf(
'%s/%s.partial.mar.info', $parms[
'clientDir'], $build[
'mar_basename']);
115 $partialInfo =
parseInfo($partialInfoFile);
118 $xml .=
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
119 $xml .=
"<updates xmlns=\"http://www.mozilla.org/2005/app-update\">\n";
120 $xml .= sprintf(
"<update type=\"major\" version=\"%s\" extensionVersion=\"%s\" buildID=\"%s\" detailsURL=\"%s\" >\n",
121 $completeInfo[
'version'],
122 $completeInfo[
'version'],
123 $completeInfo[
'buildid'],
124 sprintf(
"%s?app=OFFLINE&action=OFF_DLCLIENT", $core_externurl)
127 if( $parms[
'version'] == $partialInfo[
'version_from'] && $parms[
'buildid'] == $partialInfo[
'buildid_from'] ) {
129 $xml .= sprintf(
" <patch type=\"partial\" URL=\"%s\" hashFunction=\"%s\" hashValue=\"%s\" size=\"%s\" />\n",
130 sprintf(
"%sguest.php?app=OFFLINE&action=OFF_UPDATE&download=partial&version=%%VERSION%%&buildid=%%BUILD_ID%%&os=%s&arch=%s",
135 $partialInfo[
'hashfunction'],
136 $partialInfo[
'hashvalue'],
142 $xml .= sprintf(
" <patch type=\"complete\" URL=\"%s\" hashFunction=\"%s\" hashValue=\"%s\" size=\"%s\" />\n",
143 sprintf(
"%sguest.php?app=OFFLINE&action=OFF_UPDATE&download=complete&version=%%VERSION%%&buildid=%%BUILD_ID%%&os=%s&arch=%s",
148 $completeInfo[
'hashfunction'],
149 $completeInfo[
'hashvalue'],
150 $completeInfo[
'size']
153 $xml .=
"</update>\n";
154 $xml .=
"</updates>\n";
156 header(
'HTTP/1.1 200 OK');
157 header(
'Content-Type: text/xml');
158 header(
'Content-Length: ' . strlen($xml));
164 $buildList =
getBuildFor($parms[
'os'], $parms[
'arch']);
165 if( count($buildList) <= 0 ) {
167 $err = sprintf(
"No builds found for {os='%s', arch='%s'}.", $parms[
'os'], $parms[
'arch']);
168 error_log(__METHOD__.
" ".$err);
173 $build = array_shift($buildList);
175 $completeMar = sprintf(
'%s/%s.complete.mar', $parms[
'clientDir'], $build[
'mar_basename']);
176 if( ! is_file($completeMar) ) {
178 $err = sprintf(
"Complete MAR '%s' not found.", $completeMar);
179 error_log(__METHOD__.
" ".$err);
183 sendFile(
'application/binary', $completeMar);
188 $buildList =
getBuildFor($parms[
'os'], $parms[
'arch']);
189 if( count($buildList) <= 0 ) {
191 $err = sprintf(
"No builds found for {os='%s', arch='%s'}.", $parms[
'os'], $parms[
'arch']);
192 error_log(__METHOD__.
" ".$err);
197 $build = array_shift($buildList);
199 $partialMar = sprintf(
'%s/%s.partial.mar', $parms[
'clientDir'], $build[
'mar_basename']);
201 sendfile(
'application/binary', $partialMar);
206 include_once(
'OFFLINE/Class.OfflineClientBuilder.php');
209 $buildList = $ocb->getOsArchList();
212 foreach( $buildList as &$build ) {
213 if( $build[
'os'] == $os && $build[
'arch'] == $arch ) {
off_update_download_partial(&$parms, &$action)
off_update_download_update(&$parms, &$action)
off_update_download_complete(&$parms, &$action)
sendFile($type, $filename)
off_update_unknown_download(&$parms, &$action)