Fixing content type ordering when content_type is not defined.
[akelos.git] / vendor / pear / OS / Guess.php
bloba85bf360ebc06fe884f8fec9ba0cc65d834ec83d
1 <?php
2 //
3 // +----------------------------------------------------------------------+
4 // | PHP Version 5 |
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2004 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 3.0 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available through the world-wide-web at the following url: |
11 // | http://www.php.net/license/3_0.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Authors: Stig Bakken <ssb@php.net> |
17 // | |
18 // +----------------------------------------------------------------------+
20 // $Id: Guess.php,v 1.13.4.1 2004/10/19 04:15:56 cellog Exp $
22 // {{{ uname examples
24 // php_uname() without args returns the same as 'uname -a', or a PHP-custom
25 // string for Windows.
26 // PHP versions prior to 4.3 return the uname of the host where PHP was built,
27 // as of 4.3 it returns the uname of the host running the PHP code.
29 // PC RedHat Linux 7.1:
30 // Linux host.example.com 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown
32 // PC Debian Potato:
33 // Linux host 2.4.17 #2 SMP Tue Feb 12 15:10:04 CET 2002 i686 unknown
35 // PC FreeBSD 3.3:
36 // FreeBSD host.example.com 3.3-STABLE FreeBSD 3.3-STABLE #0: Mon Feb 21 00:42:31 CET 2000 root@example.com:/usr/src/sys/compile/CONFIG i386
38 // PC FreeBSD 4.3:
39 // FreeBSD host.example.com 4.3-RELEASE FreeBSD 4.3-RELEASE #1: Mon Jun 25 11:19:43 EDT 2001 root@example.com:/usr/src/sys/compile/CONFIG i386
41 // PC FreeBSD 4.5:
42 // FreeBSD host.example.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb 6 23:59:23 CET 2002 root@example.com:/usr/src/sys/compile/CONFIG i386
44 // PC FreeBSD 4.5 w/uname from GNU shellutils:
45 // FreeBSD host.example.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Wed Feb i386 unknown
47 // HP 9000/712 HP-UX 10:
48 // HP-UX iq B.10.10 A 9000/712 2008429113 two-user license
50 // HP 9000/712 HP-UX 10 w/uname from GNU shellutils:
51 // HP-UX host B.10.10 A 9000/712 unknown
53 // IBM RS6000/550 AIX 4.3:
54 // AIX host 3 4 000003531C00
56 // AIX 4.3 w/uname from GNU shellutils:
57 // AIX host 3 4 000003531C00 unknown
59 // SGI Onyx IRIX 6.5 w/uname from GNU shellutils:
60 // IRIX64 host 6.5 01091820 IP19 mips
62 // SGI Onyx IRIX 6.5:
63 // IRIX64 host 6.5 01091820 IP19
65 // SparcStation 20 Solaris 8 w/uname from GNU shellutils:
66 // SunOS host.example.com 5.8 Generic_108528-12 sun4m sparc
68 // SparcStation 20 Solaris 8:
69 // SunOS host.example.com 5.8 Generic_108528-12 sun4m sparc SUNW,SPARCstation-20
71 // Mac OS X (Darwin)
72 // Darwin home-eden.local 7.5.0 Darwin Kernel Version 7.5.0: Thu Aug 5 19:26:16 PDT 2004; root:xnu/xnu-517.7.21.obj~3/RELEASE_PPC Power Macintosh
74 // Mac OS X early versions
75 //
77 // }}}
79 /* TODO:
80 * - define endianness, to allow matchSignature("bigend") etc.
83 class OS_Guess
85 var $sysname;
86 var $nodename;
87 var $cpu;
88 var $release;
89 var $extra;
91 function OS_Guess($uname = null)
93 list($this->sysname,
94 $this->release,
95 $this->cpu,
96 $this->extra,
97 $this->nodename) = $this->parseSignature($uname);
100 function parseSignature($uname = null)
102 static $sysmap = array(
103 'HP-UX' => 'hpux',
104 'IRIX64' => 'irix',
106 static $cpumap = array(
107 'i586' => 'i386',
108 'i686' => 'i386',
109 'ppc' => 'powerpc',
111 if ($uname === null) {
112 $uname = php_uname();
114 $parts = split('[[:space:]]+', trim($uname));
115 $n = count($parts);
117 $release = $machine = $cpu = '';
118 $sysname = $parts[0];
119 $nodename = $parts[1];
120 $cpu = $parts[$n-1];
121 $extra = '';
122 if ($cpu == 'unknown') {
123 $cpu = $parts[$n-2];
126 switch ($sysname) {
127 case 'AIX':
128 $release = "$parts[3].$parts[2]";
129 break;
130 case 'Windows':
131 switch ($parts[1]) {
132 case '95/98':
133 $release = '9x';
134 break;
135 default:
136 $release = $parts[1];
137 break;
139 $cpu = 'i386';
140 break;
141 case 'Linux':
142 $extra = $this->_detectGlibcVersion();
143 // use only the first two digits from the kernel version
144 $release = ereg_replace('^([[:digit:]]+\.[[:digit:]]+).*', '\1', $parts[2]);
145 break;
146 case 'Mac' :
147 $sysname = 'darwin';
148 $nodename = $parts[2];
149 $release = $parts[3];
150 if ($cpu == 'Macintosh') {
151 if ($parts[$n - 2] == 'Power') {
152 $cpu = 'powerpc';
155 break;
156 case 'Darwin' :
157 if ($cpu == 'Macintosh') {
158 if ($parts[$n - 2] == 'Power') {
159 $cpu = 'powerpc';
162 $release = ereg_replace('^([[:digit:]]+\.[[:digit:]]+).*', '\1', $parts[2]);
163 break;
164 default:
165 $release = ereg_replace('-.*', '', $parts[2]);
166 break;
170 if (isset($sysmap[$sysname])) {
171 $sysname = $sysmap[$sysname];
172 } else {
173 $sysname = strtolower($sysname);
175 if (isset($cpumap[$cpu])) {
176 $cpu = $cpumap[$cpu];
178 return array($sysname, $release, $cpu, $extra, $nodename);
181 function _detectGlibcVersion()
183 // Use glibc's <features.h> header file to
184 // get major and minor version number:
185 include_once "System.php";
186 $tmpfile = System::mktemp("glibctest");
187 $fp = fopen($tmpfile, "w");
188 fwrite($fp, "#include <features.h>\n__GLIBC__ __GLIBC_MINOR__\n");
189 fclose($fp);
190 $cpp = popen("/usr/bin/cpp $tmpfile", "r");
191 $major = $minor = 0;
192 while ($line = fgets($cpp, 1024)) {
193 if ($line{0} == '#' || trim($line) == '') {
194 continue;
196 if (list($major, $minor) = explode(' ', trim($line))) {
197 break;
200 pclose($cpp);
201 unlink($tmpfile);
202 if (!($major && $minor) && is_link('/lib/libc.so.6')) {
203 // Let's try reading the libc.so.6 symlink
204 if (ereg('^libc-([.*])\.so$', basename(readlink('/lib/libc.so.6')), $matches)) {
205 list($major, $minor) = explode('.', $matches);
208 if (!($major && $minor)) {
209 return '';
211 return "glibc{$major}.{$minor}";
214 function getSignature()
216 if (empty($this->extra)) {
217 return "{$this->sysname}-{$this->release}-{$this->cpu}";
219 return "{$this->sysname}-{$this->release}-{$this->cpu}-{$this->extra}";
222 function getSysname()
224 return $this->sysname;
227 function getNodename()
229 return $this->nodename;
232 function getCpu()
234 return $this->cpu;
237 function getRelease()
239 return $this->release;
242 function getExtra()
244 return $this->extra;
247 function matchSignature($match)
249 if (is_array($match)) {
250 $fragments = $match;
251 } else {
252 $fragments = explode('-', $match);
254 $n = count($fragments);
255 $matches = 0;
256 if ($n > 0) {
257 $matches += $this->_matchFragment($fragments[0], $this->sysname);
259 if ($n > 1) {
260 $matches += $this->_matchFragment($fragments[1], $this->release);
262 if ($n > 2) {
263 $matches += $this->_matchFragment($fragments[2], $this->cpu);
265 if ($n > 3) {
266 $matches += $this->_matchFragment($fragments[3], $this->extra);
268 return ($matches == $n);
271 function _matchFragment($fragment, $value)
273 if (strcspn($fragment, '*?') < strlen($fragment)) {
274 $reg = '^' . str_replace(array('*', '?', '/'), array('.*', '.', '\\/'), $fragment) . '$';
275 return eregi($reg, $value);
277 return ($fragment == '*' || !strcasecmp($fragment, $value));
282 * Local Variables:
283 * indent-tabs-mode: nil
284 * c-basic-offset: 4
285 * End: