1/*
2   +----------------------------------------------------------------------+
3   | PHP Version 5                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2014 The PHP Group                                |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 3.01 of the PHP license,      |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available through the world-wide-web at the following url:           |
10   | http://www.php.net/license/3_01.txt                                  |
11   | If you did not receive a copy of the PHP license and are unable to   |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Authors: Rasmus Lerdorf <rasmus@php.net>                             |
16   |          Zeev Suraski <zeev@zend.com>                                |
17   |          Colin Viebrock <colin@viebrock.ca>                          |
18   +----------------------------------------------------------------------+
19*/
20
21/* $Id$ */
22
23#include "php.h"
24#include "php_ini.h"
25#include "php_globals.h"
26#include "ext/standard/head.h"
27#include "ext/standard/html.h"
28#include "info.h"
29#include "credits.h"
30#include "css.h"
31#include "SAPI.h"
32#include <time.h>
33#include "php_main.h"
34#include "zend_globals.h"       /* needs ELS */
35#include "zend_extensions.h"
36#include "zend_highlight.h"
37#ifdef HAVE_SYS_UTSNAME_H
38#include <sys/utsname.h>
39#endif
40
41
42#ifdef PHP_WIN32
43typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
44typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
45# include "winver.h"
46
47# if _MSC_VER < 1300
48#  define OSVERSIONINFOEX php_win_OSVERSIONINFOEX
49# endif
50#endif
51
52#define SECTION(name)   if (!sapi_module.phpinfo_as_text) { \
53                            php_info_print("<h2>" name "</h2>\n"); \
54                        } else { \
55                            php_info_print_table_start(); \
56                            php_info_print_table_header(1, name); \
57                            php_info_print_table_end(); \
58                        } \
59
60PHPAPI extern char *php_ini_opened_path;
61PHPAPI extern char *php_ini_scanned_path;
62PHPAPI extern char *php_ini_scanned_files;
63
64static int php_info_print_html_esc(const char *str, int len) /* {{{ */
65{
66    int written;
67    zend_string *new_str;
68    TSRMLS_FETCH();
69
70    new_str = php_escape_html_entities((unsigned char *) str, len, 0, ENT_QUOTES, "utf-8" TSRMLS_CC);
71    written = php_output_write(new_str->val, new_str->len TSRMLS_CC);
72    zend_string_free(new_str);
73    return written;
74}
75/* }}} */
76
77static int php_info_printf(const char *fmt, ...) /* {{{ */
78{
79    char *buf;
80    int len, written;
81    va_list argv;
82    TSRMLS_FETCH();
83
84    va_start(argv, fmt);
85    len = vspprintf(&buf, 0, fmt, argv);
86    va_end(argv);
87
88    written = php_output_write(buf, len TSRMLS_CC);
89    efree(buf);
90    return written;
91}
92/* }}} */
93
94static int php_info_print(const char *str) /* {{{ */
95{
96    TSRMLS_FETCH();
97    return php_output_write(str, strlen(str) TSRMLS_CC);
98}
99/* }}} */
100
101static void php_info_print_stream_hash(const char *name, HashTable *ht TSRMLS_DC) /* {{{ */
102{
103    zend_string *key;
104
105    if (ht) {
106        if (zend_hash_num_elements(ht)) {
107            HashPosition pos;
108
109            if (!sapi_module.phpinfo_as_text) {
110                php_info_printf("<tr><td class=\"e\">Registered %s</td><td class=\"v\">", name);
111            } else {
112                php_info_printf("\nRegistered %s => ", name);
113            }
114
115            zend_hash_internal_pointer_reset_ex(ht, &pos);
116            while (zend_hash_get_current_key_ex(ht, &key, NULL, 0, &pos) == HASH_KEY_IS_STRING)
117            {
118                if (!sapi_module.phpinfo_as_text) {
119                    php_info_print_html_esc(key->val, key->len);
120                } else {
121                    php_info_print(key->val);
122                }
123                zend_hash_move_forward_ex(ht, &pos);
124                if (zend_hash_get_current_key_ex(ht, &key, NULL, 0, &pos) == HASH_KEY_IS_STRING) {
125                    php_info_print(", ");
126                } else {
127                    break;
128                }
129            }
130
131            if (!sapi_module.phpinfo_as_text) {
132                php_info_print("</td></tr>\n");
133            }
134        } else {
135            char reg_name[128];
136            snprintf(reg_name, sizeof(reg_name), "Registered %s", name);
137            php_info_print_table_row(2, reg_name, "none registered");
138        }
139    } else {
140        php_info_print_table_row(2, name, "disabled");
141    }
142}
143/* }}} */
144
145PHPAPI void php_info_print_module(zend_module_entry *zend_module TSRMLS_DC) /* {{{ */
146{
147    if (zend_module->info_func || zend_module->version) {
148        if (!sapi_module.phpinfo_as_text) {
149            php_info_printf("<h2><a name=\"module_%s\">%s</a></h2>\n", zend_module->name, zend_module->name);
150        } else {
151            php_info_print_table_start();
152            php_info_print_table_header(1, zend_module->name);
153            php_info_print_table_end();
154        }
155        if (zend_module->info_func) {
156            zend_module->info_func(zend_module TSRMLS_CC);
157        } else {
158            php_info_print_table_start();
159            php_info_print_table_row(2, "Version", zend_module->version);
160            php_info_print_table_end();
161            DISPLAY_INI_ENTRIES();
162        }
163    } else {
164        if (!sapi_module.phpinfo_as_text) {
165            php_info_printf("<tr><td class=\"v\">%s</td></tr>\n", zend_module->name);
166        } else {
167            php_info_printf("%s\n", zend_module->name);
168        }
169    }
170}
171/* }}} */
172
173static int _display_module_info_func(zval *el TSRMLS_DC) /* {{{ */
174{
175    zend_module_entry *module = (zend_module_entry*)Z_PTR_P(el);
176    if (module->info_func || module->version) {
177        php_info_print_module(module TSRMLS_CC);
178    }
179    return ZEND_HASH_APPLY_KEEP;
180}
181/* }}} */
182
183static int _display_module_info_def(zval *el TSRMLS_DC) /* {{{ */
184{
185    zend_module_entry *module = (zend_module_entry*)Z_PTR_P(el);
186    if (!module->info_func && !module->version) {
187        php_info_print_module(module TSRMLS_CC);
188    }
189    return ZEND_HASH_APPLY_KEEP;
190}
191/* }}} */
192
193/* {{{ php_print_gpcse_array
194 */
195static void php_print_gpcse_array(char *name, uint name_length TSRMLS_DC)
196{
197    zval *data, *tmp, tmp2;
198    zend_string *string_key;
199    zend_ulong num_key;
200    zend_string *key;
201
202    key = zend_string_init(name, name_length, 0);
203    zend_is_auto_global(key TSRMLS_CC);
204
205    if ((data = zend_hash_find(&EG(symbol_table).ht, key)) != NULL && (Z_TYPE_P(data) == IS_ARRAY)) {
206        ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(data), num_key, string_key, tmp) {
207            if (!sapi_module.phpinfo_as_text) {
208                php_info_print("<tr>");
209                php_info_print("<td class=\"e\">");
210            }
211
212            php_info_print(name);
213            php_info_print("[\"");
214
215            if (string_key != NULL) {
216                if (!sapi_module.phpinfo_as_text) {
217                    php_info_print_html_esc(string_key->val, string_key->len);
218                } else {
219                    php_info_print(string_key->val);
220                }
221            } else {
222                php_info_printf("%pd", num_key);
223            }
224            php_info_print("\"]");
225            if (!sapi_module.phpinfo_as_text) {
226                php_info_print("</td><td class=\"v\">");
227            } else {
228                php_info_print(" => ");
229            }
230            if (Z_TYPE_P(tmp) == IS_ARRAY) {
231                if (!sapi_module.phpinfo_as_text) {
232                    php_info_print("<pre>");
233                    zend_print_zval_r_ex((zend_write_func_t) php_info_print_html_esc, tmp, 0 TSRMLS_CC);
234                    php_info_print("</pre>");
235                } else {
236                    zend_print_zval_r(tmp, 0 TSRMLS_CC);
237                }
238            } else {
239                ZVAL_COPY_VALUE(&tmp2, tmp);
240                if (Z_TYPE(tmp2) != IS_STRING) {
241                    tmp = NULL;
242                    zval_copy_ctor(&tmp2);
243                    convert_to_string(&tmp2);
244                }
245
246                if (!sapi_module.phpinfo_as_text) {
247                    if (Z_STRLEN(tmp2) == 0) {
248                        php_info_print("<i>no value</i>");
249                    } else {
250                        php_info_print_html_esc(Z_STRVAL(tmp2), Z_STRLEN(tmp2));
251                    }
252                } else {
253                    php_info_print(Z_STRVAL(tmp2));
254                }
255
256                if (!tmp) {
257                    zval_dtor(&tmp2);
258                }
259            }
260            if (!sapi_module.phpinfo_as_text) {
261                php_info_print("</td></tr>\n");
262            } else {
263                php_info_print("\n");
264            }
265        } ZEND_HASH_FOREACH_END();
266    }
267    zend_string_free(key);
268}
269/* }}} */
270
271/* {{{ php_info_print_style
272 */
273void php_info_print_style(TSRMLS_D)
274{
275    php_info_printf("<style type=\"text/css\">\n");
276    php_info_print_css(TSRMLS_C);
277    php_info_printf("</style>\n");
278}
279/* }}} */
280
281/* {{{ php_info_html_esc
282 */
283PHPAPI zend_string *php_info_html_esc(char *string TSRMLS_DC)
284{
285    return php_escape_html_entities((unsigned char *) string, strlen(string), 0, ENT_QUOTES, NULL TSRMLS_CC);
286}
287/* }}} */
288
289#ifdef PHP_WIN32
290/* {{{  */
291
292char* php_get_windows_name()
293{
294    OSVERSIONINFOEX osvi;
295    SYSTEM_INFO si;
296    PGNSI pGNSI;
297    PGPI pGPI;
298    BOOL bOsVersionInfoEx;
299    DWORD dwType;
300    char *major = NULL, *sub = NULL, *retval;
301
302    ZeroMemory(&si, sizeof(SYSTEM_INFO));
303    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
304    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
305
306    if (!(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi))) {
307        return NULL;
308    }
309
310    pGNSI = (PGNSI) GetProcAddress(GetModuleHandle("kernel32.dll"), "GetNativeSystemInfo");
311    if(NULL != pGNSI) {
312        pGNSI(&si);
313    } else {
314        GetSystemInfo(&si);
315    }
316
317    if (VER_PLATFORM_WIN32_NT==osvi.dwPlatformId && osvi.dwMajorVersion > 4 ) {
318        if (osvi.dwMajorVersion == 6) {
319            if( osvi.dwMinorVersion == 0 ) {
320                if( osvi.wProductType == VER_NT_WORKSTATION ) {
321                    major = "Windows Vista";
322                } else {
323                    major = "Windows Server 2008";
324                }
325            } else
326            if ( osvi.dwMinorVersion == 1 ) {
327                if( osvi.wProductType == VER_NT_WORKSTATION )  {
328                    major = "Windows 7";
329                } else {
330                    major = "Windows Server 2008 R2";
331                }
332            } else if ( osvi.dwMinorVersion == 2 ) {
333                /* could be Windows 8/Windows Server 2012, could be Windows 8.1/Windows Server 2012 R2 */
334                OSVERSIONINFOEX osvi81;
335                DWORDLONG dwlConditionMask = 0;
336                int op = VER_GREATER_EQUAL;
337
338                ZeroMemory(&osvi81, sizeof(OSVERSIONINFOEX));
339                osvi81.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
340                osvi81.dwMajorVersion = 6;
341                osvi81.dwMinorVersion = 3;
342                osvi81.wServicePackMajor = 0;
343
344                VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op);
345                VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, op);
346                VER_SET_CONDITION(dwlConditionMask, VER_SERVICEPACKMAJOR, op);
347
348                if (VerifyVersionInfo(&osvi81,
349                    VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR,
350                    dwlConditionMask)) {
351                    osvi.dwMinorVersion = 3; /* Windows 8.1/Windows Server 2012 R2 */
352                    if( osvi.wProductType == VER_NT_WORKSTATION )  {
353                        major = "Windows 8.1";
354                    } else {
355                        major = "Windows Server 2012 R2";
356                    }
357                } else {
358                    if( osvi.wProductType == VER_NT_WORKSTATION )  {
359                        major = "Windows 8";
360                    } else {
361                        major = "Windows Server 2012";
362                    }
363                }
364            } else {
365                major = "Unknown Windows version";
366            }
367
368            pGPI = (PGPI) GetProcAddress(GetModuleHandle("kernel32.dll"), "GetProductInfo");
369            pGPI(6, 0, 0, 0, &dwType);
370
371            switch (dwType) {
372                case PRODUCT_ULTIMATE:
373                    sub = "Ultimate Edition";
374                    break;
375                case PRODUCT_HOME_PREMIUM:
376                    sub = "Home Premium Edition";
377                    break;
378                case PRODUCT_HOME_BASIC:
379                    sub = "Home Basic Edition";
380                    break;
381                case PRODUCT_ENTERPRISE:
382                    sub = "Enterprise Edition";
383                    break;
384                case PRODUCT_BUSINESS:
385                    sub = "Business Edition";
386                    break;
387                case PRODUCT_STARTER:
388                    sub = "Starter Edition";
389                    break;
390                case PRODUCT_CLUSTER_SERVER:
391                    sub = "Cluster Server Edition";
392                    break;
393                case PRODUCT_DATACENTER_SERVER:
394                    sub = "Datacenter Edition";
395                    break;
396                case PRODUCT_DATACENTER_SERVER_CORE:
397                    sub = "Datacenter Edition (core installation)";
398                    break;
399                case PRODUCT_ENTERPRISE_SERVER:
400                    sub = "Enterprise Edition";
401                    break;
402                case PRODUCT_ENTERPRISE_SERVER_CORE:
403                    sub = "Enterprise Edition (core installation)";
404                    break;
405                case PRODUCT_ENTERPRISE_SERVER_IA64:
406                    sub = "Enterprise Edition for Itanium-based Systems";
407                    break;
408                case PRODUCT_SMALLBUSINESS_SERVER:
409                    sub = "Small Business Server";
410                    break;
411                case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
412                    sub = "Small Business Server Premium Edition";
413                    break;
414                case PRODUCT_STANDARD_SERVER:
415                    sub = "Standard Edition";
416                    break;
417                case PRODUCT_STANDARD_SERVER_CORE:
418                    sub = "Standard Edition (core installation)";
419                    break;
420                case PRODUCT_WEB_SERVER:
421                    sub = "Web Server Edition";
422                    break;
423            }
424        }
425
426        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) {
427            if (GetSystemMetrics(SM_SERVERR2))
428                major = "Windows Server 2003 R2";
429            else if (osvi.wSuiteMask==VER_SUITE_STORAGE_SERVER)
430                major = "Windows Storage Server 2003";
431            else if (osvi.wSuiteMask==VER_SUITE_WH_SERVER)
432                major = "Windows Home Server";
433            else if (osvi.wProductType == VER_NT_WORKSTATION &&
434                si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) {
435                major = "Windows XP Professional x64 Edition";
436            } else {
437                major = "Windows Server 2003";
438            }
439
440            /* Test for the server type. */
441            if ( osvi.wProductType != VER_NT_WORKSTATION ) {
442                if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64 ) {
443                    if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
444                        sub = "Datacenter Edition for Itanium-based Systems";
445                    else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
446                        sub = "Enterprise Edition for Itanium-based Systems";
447                }
448
449                else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 ) {
450                    if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
451                        sub = "Datacenter x64 Edition";
452                    else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
453                        sub = "Enterprise x64 Edition";
454                    else sub = "Standard x64 Edition";
455                } else {
456                    if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER )
457                        sub = "Compute Cluster Edition";
458                    else if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
459                        sub = "Datacenter Edition";
460                    else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
461                        sub = "Enterprise Edition";
462                    else if ( osvi.wSuiteMask & VER_SUITE_BLADE )
463                        sub = "Web Edition";
464                    else sub = "Standard Edition";
465                }
466            }
467        }
468
469        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) {
470            major = "Windows XP";
471            if( osvi.wSuiteMask & VER_SUITE_PERSONAL ) {
472                sub = "Home Edition";
473            } else if (GetSystemMetrics(SM_MEDIACENTER)) {
474                sub = "Media Center Edition";
475            } else if (GetSystemMetrics(SM_STARTER)) {
476                sub = "Starter Edition";
477            } else if (GetSystemMetrics(SM_TABLETPC)) {
478                sub = "Tablet PC Edition";
479            } else {
480                sub = "Professional";
481            }
482        }
483
484        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) {
485            major = "Windows 2000";
486
487            if (osvi.wProductType == VER_NT_WORKSTATION ) {
488                sub = "Professional";
489            } else {
490                if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
491                    sub = "Datacenter Server";
492                else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
493                    sub = "Advanced Server";
494                else sub = "Server";
495            }
496        }
497    } else {
498        return NULL;
499    }
500
501    spprintf(&retval, 0, "%s%s%s%s%s", major, sub?" ":"", sub?sub:"", osvi.szCSDVersion[0] != '\0'?" ":"", osvi.szCSDVersion);
502    return retval;
503}
504/* }}}  */
505
506/* {{{  */
507void php_get_windows_cpu(char *buf, int bufsize)
508{
509    SYSTEM_INFO SysInfo;
510    GetSystemInfo(&SysInfo);
511    switch (SysInfo.wProcessorArchitecture) {
512        case PROCESSOR_ARCHITECTURE_INTEL :
513            snprintf(buf, bufsize, "i%d", SysInfo.dwProcessorType);
514            break;
515        case PROCESSOR_ARCHITECTURE_MIPS :
516            snprintf(buf, bufsize, "MIPS R%d000", SysInfo.wProcessorLevel);
517            break;
518        case PROCESSOR_ARCHITECTURE_ALPHA :
519            snprintf(buf, bufsize, "Alpha %d", SysInfo.wProcessorLevel);
520            break;
521        case PROCESSOR_ARCHITECTURE_PPC :
522            snprintf(buf, bufsize, "PPC 6%02d", SysInfo.wProcessorLevel);
523            break;
524        case PROCESSOR_ARCHITECTURE_IA64 :
525            snprintf(buf, bufsize,  "IA64");
526            break;
527#if defined(PROCESSOR_ARCHITECTURE_IA32_ON_WIN64)
528        case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 :
529            snprintf(buf, bufsize, "IA32");
530            break;
531#endif
532#if defined(PROCESSOR_ARCHITECTURE_AMD64)
533        case PROCESSOR_ARCHITECTURE_AMD64 :
534            snprintf(buf, bufsize, "AMD64");
535            break;
536#endif
537        case PROCESSOR_ARCHITECTURE_UNKNOWN :
538        default:
539            snprintf(buf, bufsize, "Unknown");
540            break;
541    }
542}
543/* }}}  */
544#endif
545
546/* {{{ php_get_uname
547 */
548PHPAPI zend_string *php_get_uname(char mode)
549{
550    char *php_uname;
551    char tmp_uname[256];
552#ifdef PHP_WIN32
553    DWORD dwBuild=0;
554    DWORD dwVersion = GetVersion();
555    DWORD dwWindowsMajorVersion =  (DWORD)(LOBYTE(LOWORD(dwVersion)));
556    DWORD dwWindowsMinorVersion =  (DWORD)(HIBYTE(LOWORD(dwVersion)));
557    DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
558    char ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
559
560    GetComputerName(ComputerName, &dwSize);
561
562    if (mode == 's') {
563        php_uname = "Windows NT";
564    } else if (mode == 'r') {
565        snprintf(tmp_uname, sizeof(tmp_uname), "%d.%d", dwWindowsMajorVersion, dwWindowsMinorVersion);
566        php_uname = tmp_uname;
567    } else if (mode == 'n') {
568        php_uname = ComputerName;
569    } else if (mode == 'v') {
570        char *winver = php_get_windows_name();
571        dwBuild = (DWORD)(HIWORD(dwVersion));
572        if(winver == NULL) {
573            snprintf(tmp_uname, sizeof(tmp_uname), "build %d", dwBuild);
574        } else {
575            snprintf(tmp_uname, sizeof(tmp_uname), "build %d (%s)", dwBuild, winver);
576        }
577        php_uname = tmp_uname;
578        if(winver) {
579            efree(winver);
580        }
581    } else if (mode == 'm') {
582        php_get_windows_cpu(tmp_uname, sizeof(tmp_uname));
583        php_uname = tmp_uname;
584    } else { /* assume mode == 'a' */
585        char *winver = php_get_windows_name();
586        char wincpu[20];
587
588        php_get_windows_cpu(wincpu, sizeof(wincpu));
589        dwBuild = (DWORD)(HIWORD(dwVersion));
590
591        /* Windows "version" 6.2 could be Windows 8/Windows Server 2012, but also Windows 8.1/Windows Server 2012 R2 */
592        if (dwWindowsMajorVersion == 6 && dwWindowsMinorVersion == 2) {
593            if (strncmp(winver, "Windows 8.1", 11) == 0 || strncmp(winver, "Windows Server 2012 R2", 22) == 0) {
594                dwWindowsMinorVersion = 3;
595            }
596        }
597
598        snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d build %d (%s) %s",
599                 "Windows NT", ComputerName,
600                 dwWindowsMajorVersion, dwWindowsMinorVersion, dwBuild, winver?winver:"unknown", wincpu);
601        if(winver) {
602            efree(winver);
603        }
604        php_uname = tmp_uname;
605    }
606#else
607#ifdef HAVE_SYS_UTSNAME_H
608    struct utsname buf;
609    if (uname((struct utsname *)&buf) == -1) {
610        php_uname = PHP_UNAME;
611    } else {
612#ifdef NETWARE
613        if (mode == 's') {
614            php_uname = buf.sysname;
615        } else if (mode == 'r') {
616            snprintf(tmp_uname, sizeof(tmp_uname), "%d.%d.%d",
617                     buf.netware_major, buf.netware_minor, buf.netware_revision);
618            php_uname = tmp_uname;
619        } else if (mode == 'n') {
620            php_uname = buf.servername;
621        } else if (mode == 'v') {
622            snprintf(tmp_uname, sizeof(tmp_uname), "libc-%d.%d.%d #%d",
623                     buf.libmajor, buf.libminor, buf.librevision, buf.libthreshold);
624            php_uname = tmp_uname;
625        } else if (mode == 'm') {
626            php_uname = buf.machine;
627        } else { /* assume mode == 'a' */
628            snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d.%d libc-%d.%d.%d #%d %s",
629                     buf.sysname, buf.servername,
630                     buf.netware_major, buf.netware_minor, buf.netware_revision,
631                     buf.libmajor, buf.libminor, buf.librevision, buf.libthreshold,
632                     buf.machine);
633            php_uname = tmp_uname;
634        }
635#else
636        if (mode == 's') {
637            php_uname = buf.sysname;
638        } else if (mode == 'r') {
639            php_uname = buf.release;
640        } else if (mode == 'n') {
641            php_uname = buf.nodename;
642        } else if (mode == 'v') {
643            php_uname = buf.version;
644        } else if (mode == 'm') {
645            php_uname = buf.machine;
646        } else { /* assume mode == 'a' */
647            snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %s %s %s",
648                     buf.sysname, buf.nodename, buf.release, buf.version,
649                     buf.machine);
650            php_uname = tmp_uname;
651        }
652#endif /* NETWARE */
653    }
654#else
655    php_uname = PHP_UNAME;
656#endif
657#endif
658    return zend_string_init(php_uname, strlen(php_uname), 0);
659}
660/* }}} */
661
662/* {{{ php_print_info_htmlhead
663 */
664PHPAPI void php_print_info_htmlhead(TSRMLS_D)
665{
666    php_info_print("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n");
667    php_info_print("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
668    php_info_print("<head>\n");
669    php_info_print_style(TSRMLS_C);
670    php_info_print("<title>phpinfo()</title>");
671    php_info_print("<meta name=\"ROBOTS\" content=\"NOINDEX,NOFOLLOW,NOARCHIVE\" />");
672    php_info_print("</head>\n");
673    php_info_print("<body><div class=\"center\">\n");
674}
675/* }}} */
676
677/* {{{ module_name_cmp */
678static int module_name_cmp(const void *a, const void *b TSRMLS_DC)
679{
680    Bucket *f = (Bucket *) a;
681    Bucket *s = (Bucket *) b;
682
683    return strcasecmp(((zend_module_entry *)Z_PTR(f->val))->name,
684                  ((zend_module_entry *)Z_PTR(s->val))->name);
685}
686/* }}} */
687
688/* {{{ php_print_info
689 */
690PHPAPI void php_print_info(int flag TSRMLS_DC)
691{
692    char **env, *tmp1, *tmp2;
693    zend_string *php_uname;
694
695    if (!sapi_module.phpinfo_as_text) {
696        php_print_info_htmlhead(TSRMLS_C);
697    } else {
698        php_info_print("phpinfo()\n");
699    }
700
701    if (flag & PHP_INFO_GENERAL) {
702        char *zend_version = get_zend_version();
703        char temp_api[10];
704
705        php_uname = php_get_uname('a');
706
707        if (!sapi_module.phpinfo_as_text) {
708            php_info_print_box_start(1);
709        }
710
711        if (!sapi_module.phpinfo_as_text) {
712            time_t the_time;
713            struct tm *ta, tmbuf;
714
715            the_time = time(NULL);
716            ta = php_localtime_r(&the_time, &tmbuf);
717
718            php_info_print("<a href=\"http://www.php.net/\"><img border=\"0\" src=\"");
719            if (ta && (ta->tm_mon==3) && (ta->tm_mday==1)) {
720                php_info_print(PHP_EGG_LOGO_DATA_URI "\" alt=\"PHP logo\" /></a>");
721            } else {
722                php_info_print(PHP_LOGO_DATA_URI "\" alt=\"PHP logo\" /></a>");
723            }
724        }
725
726        if (!sapi_module.phpinfo_as_text) {
727            php_info_printf("<h1 class=\"p\">PHP Version %s</h1>\n", PHP_VERSION);
728        } else {
729            php_info_print_table_row(2, "PHP Version", PHP_VERSION);
730        }
731        php_info_print_box_end();
732        php_info_print_table_start();
733        php_info_print_table_row(2, "System", php_uname->val);
734        php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__);
735#ifdef COMPILER
736        php_info_print_table_row(2, "Compiler", COMPILER);
737#endif
738#ifdef ARCHITECTURE
739        php_info_print_table_row(2, "Architecture", ARCHITECTURE);
740#endif
741#ifdef CONFIGURE_COMMAND
742        php_info_print_table_row(2, "Configure Command", CONFIGURE_COMMAND );
743#endif
744
745        if (sapi_module.pretty_name) {
746            php_info_print_table_row(2, "Server API", sapi_module.pretty_name );
747        }
748
749#ifdef VIRTUAL_DIR
750        php_info_print_table_row(2, "Virtual Directory Support", "enabled" );
751#else
752        php_info_print_table_row(2, "Virtual Directory Support", "disabled" );
753#endif
754
755        php_info_print_table_row(2, "Configuration File (php.ini) Path", PHP_CONFIG_FILE_PATH);
756        php_info_print_table_row(2, "Loaded Configuration File", php_ini_opened_path ? php_ini_opened_path : "(none)");
757        php_info_print_table_row(2, "Scan this dir for additional .ini files", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
758        php_info_print_table_row(2, "Additional .ini files parsed", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
759
760        snprintf(temp_api, sizeof(temp_api), "%d", PHP_API_VERSION);
761        php_info_print_table_row(2, "PHP API", temp_api);
762
763        snprintf(temp_api, sizeof(temp_api), "%d", ZEND_MODULE_API_NO);
764        php_info_print_table_row(2, "PHP Extension", temp_api);
765
766        snprintf(temp_api, sizeof(temp_api), "%d", ZEND_EXTENSION_API_NO);
767        php_info_print_table_row(2, "Zend Extension", temp_api);
768
769        php_info_print_table_row(2, "Zend Extension Build", ZEND_EXTENSION_BUILD_ID);
770        php_info_print_table_row(2, "PHP Extension Build", ZEND_MODULE_BUILD_ID);
771
772#if ZEND_DEBUG
773        php_info_print_table_row(2, "Debug Build", "yes" );
774#else
775        php_info_print_table_row(2, "Debug Build", "no" );
776#endif
777
778#ifdef ZTS
779        php_info_print_table_row(2, "Thread Safety", "enabled" );
780#else
781        php_info_print_table_row(2, "Thread Safety", "disabled" );
782#endif
783
784#ifdef ZEND_SIGNALS
785        php_info_print_table_row(2, "Zend Signal Handling", "enabled" );
786#else
787        php_info_print_table_row(2, "Zend Signal Handling", "disabled" );
788#endif
789
790        php_info_print_table_row(2, "Zend Memory Manager", is_zend_mm(TSRMLS_C) ? "enabled" : "disabled" );
791
792        {
793            const zend_multibyte_functions *functions = zend_multibyte_get_functions(TSRMLS_C);
794            char *descr;
795            if (functions) {
796                spprintf(&descr, 0, "provided by %s", functions->provider_name);
797            } else {
798                descr = estrdup("disabled");
799            }
800            php_info_print_table_row(2, "Zend Multibyte Support", descr);
801            efree(descr);
802        }
803
804#if HAVE_IPV6
805        php_info_print_table_row(2, "IPv6 Support", "enabled" );
806#else
807        php_info_print_table_row(2, "IPv6 Support", "disabled" );
808#endif
809
810#if HAVE_DTRACE
811        php_info_print_table_row(2, "DTrace Support", "enabled" );
812#else
813        php_info_print_table_row(2, "DTrace Support", "disabled" );
814#endif
815
816        php_info_print_stream_hash("PHP Streams",  php_stream_get_url_stream_wrappers_hash() TSRMLS_CC);
817        php_info_print_stream_hash("Stream Socket Transports", php_stream_xport_get_hash() TSRMLS_CC);
818        php_info_print_stream_hash("Stream Filters", php_get_stream_filters_hash() TSRMLS_CC);
819
820        php_info_print_table_end();
821
822        /* Zend Engine */
823        php_info_print_box_start(0);
824        if (!sapi_module.phpinfo_as_text) {
825            php_info_print("<a href=\"http://www.zend.com/\"><img border=\"0\" src=\"");
826            php_info_print(ZEND_LOGO_DATA_URI "\" alt=\"Zend logo\" /></a>\n");
827        }
828        php_info_print("This program makes use of the Zend Scripting Language Engine:");
829        php_info_print(!sapi_module.phpinfo_as_text?"<br />":"\n");
830        if (sapi_module.phpinfo_as_text) {
831            php_info_print(zend_version);
832        } else {
833            zend_html_puts(zend_version, strlen(zend_version) TSRMLS_CC);
834        }
835        php_info_print_box_end();
836        zend_string_free(php_uname);
837    }
838
839    zend_ini_sort_entries(TSRMLS_C);
840
841    if (flag & PHP_INFO_CONFIGURATION) {
842        php_info_print_hr();
843        if (!sapi_module.phpinfo_as_text) {
844            php_info_print("<h1>Configuration</h1>\n");
845        } else {
846            SECTION("Configuration");
847        }
848        if (!(flag & PHP_INFO_MODULES)) {
849            SECTION("PHP Core");
850            display_ini_entries(NULL);
851        }
852    }
853
854    if (flag & PHP_INFO_MODULES) {
855        HashTable sorted_registry;
856
857        zend_hash_init(&sorted_registry, zend_hash_num_elements(&module_registry), NULL, NULL, 1);
858        zend_hash_copy(&sorted_registry, &module_registry, NULL);
859        zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC);
860
861        zend_hash_apply(&sorted_registry, _display_module_info_func TSRMLS_CC);
862
863        SECTION("Additional Modules");
864        php_info_print_table_start();
865        php_info_print_table_header(1, "Module Name");
866        zend_hash_apply(&sorted_registry, _display_module_info_def TSRMLS_CC);
867        php_info_print_table_end();
868
869        zend_hash_destroy(&sorted_registry);
870    }
871
872    if (flag & PHP_INFO_ENVIRONMENT) {
873        SECTION("Environment");
874        php_info_print_table_start();
875        php_info_print_table_header(2, "Variable", "Value");
876        for (env=environ; env!=NULL && *env !=NULL; env++) {
877            tmp1 = estrdup(*env);
878            if (!(tmp2=strchr(tmp1,'='))) { /* malformed entry? */
879                efree(tmp1);
880                continue;
881            }
882            *tmp2 = 0;
883            tmp2++;
884            php_info_print_table_row(2, tmp1, tmp2);
885            efree(tmp1);
886        }
887        php_info_print_table_end();
888    }
889
890    if (flag & PHP_INFO_VARIABLES) {
891        zval *data;
892
893        SECTION("PHP Variables");
894
895        php_info_print_table_start();
896        php_info_print_table_header(2, "Variable", "Value");
897        if ((data = zend_hash_str_find(&EG(symbol_table).ht, "PHP_SELF", sizeof("PHP_SELF")-1)) != NULL && Z_TYPE_P(data) == IS_STRING) {
898            php_info_print_table_row(2, "PHP_SELF", Z_STRVAL_P(data));
899        }
900        if ((data = zend_hash_str_find(&EG(symbol_table).ht, "PHP_AUTH_TYPE", sizeof("PHP_AUTH_TYPE")-1)) != NULL && Z_TYPE_P(data) == IS_STRING) {
901            php_info_print_table_row(2, "PHP_AUTH_TYPE", Z_STRVAL_P(data));
902        }
903        if ((data = zend_hash_str_find(&EG(symbol_table).ht, "PHP_AUTH_USER", sizeof("PHP_AUTH_USER")-1)) != NULL && Z_TYPE_P(data) == IS_STRING) {
904            php_info_print_table_row(2, "PHP_AUTH_USER", Z_STRVAL_P(data));
905        }
906        if ((data = zend_hash_str_find(&EG(symbol_table).ht, "PHP_AUTH_PW", sizeof("PHP_AUTH_PW")-1)) != NULL && Z_TYPE_P(data) == IS_STRING) {
907            php_info_print_table_row(2, "PHP_AUTH_PW", Z_STRVAL_P(data));
908        }
909        php_print_gpcse_array(ZEND_STRL("_REQUEST") TSRMLS_CC);
910        php_print_gpcse_array(ZEND_STRL("_GET") TSRMLS_CC);
911        php_print_gpcse_array(ZEND_STRL("_POST") TSRMLS_CC);
912        php_print_gpcse_array(ZEND_STRL("_FILES") TSRMLS_CC);
913        php_print_gpcse_array(ZEND_STRL("_COOKIE") TSRMLS_CC);
914        php_print_gpcse_array(ZEND_STRL("_SERVER") TSRMLS_CC);
915        php_print_gpcse_array(ZEND_STRL("_ENV") TSRMLS_CC);
916        php_info_print_table_end();
917    }
918
919
920    if ((flag & PHP_INFO_CREDITS) && !sapi_module.phpinfo_as_text) {
921        php_info_print_hr();
922        php_print_credits(PHP_CREDITS_ALL & ~PHP_CREDITS_FULLPAGE TSRMLS_CC);
923    }
924
925    if (flag & PHP_INFO_LICENSE) {
926        if (!sapi_module.phpinfo_as_text) {
927            SECTION("PHP License");
928            php_info_print_box_start(0);
929            php_info_print("<p>\n");
930            php_info_print("This program is free software; you can redistribute it and/or modify ");
931            php_info_print("it under the terms of the PHP License as published by the PHP Group ");
932            php_info_print("and included in the distribution in the file:  LICENSE\n");
933            php_info_print("</p>\n");
934            php_info_print("<p>");
935            php_info_print("This program is distributed in the hope that it will be useful, ");
936            php_info_print("but WITHOUT ANY WARRANTY; without even the implied warranty of ");
937            php_info_print("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
938            php_info_print("</p>\n");
939            php_info_print("<p>");
940            php_info_print("If you did not receive a copy of the PHP license, or have any questions about ");
941            php_info_print("PHP licensing, please contact license@php.net.\n");
942            php_info_print("</p>\n");
943            php_info_print_box_end();
944        } else {
945            php_info_print("\nPHP License\n");
946            php_info_print("This program is free software; you can redistribute it and/or modify\n");
947            php_info_print("it under the terms of the PHP License as published by the PHP Group\n");
948            php_info_print("and included in the distribution in the file:  LICENSE\n");
949            php_info_print("\n");
950            php_info_print("This program is distributed in the hope that it will be useful,\n");
951            php_info_print("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
952            php_info_print("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
953            php_info_print("\n");
954            php_info_print("If you did not receive a copy of the PHP license, or have any\n");
955            php_info_print("questions about PHP licensing, please contact license@php.net.\n");
956        }
957    }
958
959    if (!sapi_module.phpinfo_as_text) {
960        php_info_print("</div></body></html>");
961    }
962}
963/* }}} */
964
965PHPAPI void php_info_print_table_start(void) /* {{{ */
966{
967    if (!sapi_module.phpinfo_as_text) {
968        php_info_print("<table>\n");
969    } else {
970        php_info_print("\n");
971    }
972}
973/* }}} */
974
975PHPAPI void php_info_print_table_end(void) /* {{{ */
976{
977    if (!sapi_module.phpinfo_as_text) {
978        php_info_print("</table>\n");
979    }
980
981}
982/* }}} */
983
984PHPAPI void php_info_print_box_start(int flag) /* {{{ */
985{
986    php_info_print_table_start();
987    if (flag) {
988        if (!sapi_module.phpinfo_as_text) {
989            php_info_print("<tr class=\"h\"><td>\n");
990        }
991    } else {
992        if (!sapi_module.phpinfo_as_text) {
993            php_info_print("<tr class=\"v\"><td>\n");
994        } else {
995            php_info_print("\n");
996        }
997    }
998}
999/* }}} */
1000
1001PHPAPI void php_info_print_box_end(void) /* {{{ */
1002{
1003    if (!sapi_module.phpinfo_as_text) {
1004        php_info_print("</td></tr>\n");
1005    }
1006    php_info_print_table_end();
1007}
1008/* }}} */
1009
1010PHPAPI void php_info_print_hr(void) /* {{{ */
1011{
1012    if (!sapi_module.phpinfo_as_text) {
1013        php_info_print("<hr />\n");
1014    } else {
1015        php_info_print("\n\n _______________________________________________________________________\n\n");
1016    }
1017}
1018/* }}} */
1019
1020PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header) /* {{{ */
1021{
1022    int spaces;
1023
1024    if (!sapi_module.phpinfo_as_text) {
1025        php_info_printf("<tr class=\"h\"><th colspan=\"%d\">%s</th></tr>\n", num_cols, header );
1026    } else {
1027        spaces = (74 - strlen(header));
1028        php_info_printf("%*s%s%*s\n", (int)(spaces/2), " ", header, (int)(spaces/2), " ");
1029    }
1030}
1031/* }}} */
1032
1033/* {{{ php_info_print_table_header
1034 */
1035PHPAPI void php_info_print_table_header(int num_cols, ...)
1036{
1037    int i;
1038    va_list row_elements;
1039    char *row_element;
1040
1041    va_start(row_elements, num_cols);
1042    if (!sapi_module.phpinfo_as_text) {
1043        php_info_print("<tr class=\"h\">");
1044    }
1045    for (i=0; i<num_cols; i++) {
1046        row_element = va_arg(row_elements, char *);
1047        if (!row_element || !*row_element) {
1048            row_element = " ";
1049        }
1050        if (!sapi_module.phpinfo_as_text) {
1051            php_info_print("<th>");
1052            php_info_print(row_element);
1053            php_info_print("</th>");
1054        } else {
1055            php_info_print(row_element);
1056            if (i < num_cols-1) {
1057                php_info_print(" => ");
1058            } else {
1059                php_info_print("\n");
1060            }
1061        }
1062    }
1063    if (!sapi_module.phpinfo_as_text) {
1064        php_info_print("</tr>\n");
1065    }
1066
1067    va_end(row_elements);
1068}
1069/* }}} */
1070
1071/* {{{ php_info_print_table_row_internal
1072 */
1073static void php_info_print_table_row_internal(int num_cols,
1074        const char *value_class, va_list row_elements)
1075{
1076    int i;
1077    char *row_element;
1078
1079    if (!sapi_module.phpinfo_as_text) {
1080        php_info_print("<tr>");
1081    }
1082    for (i=0; i<num_cols; i++) {
1083        if (!sapi_module.phpinfo_as_text) {
1084            php_info_printf("<td class=\"%s\">",
1085               (i==0 ? "e" : value_class )
1086            );
1087        }
1088        row_element = va_arg(row_elements, char *);
1089        if (!row_element || !*row_element) {
1090            if (!sapi_module.phpinfo_as_text) {
1091                php_info_print( "<i>no value</i>" );
1092            } else {
1093                php_info_print( " " );
1094            }
1095        } else {
1096            if (!sapi_module.phpinfo_as_text) {
1097                php_info_print_html_esc(row_element, strlen(row_element));
1098            } else {
1099                php_info_print(row_element);
1100                if (i < num_cols-1) {
1101                    php_info_print(" => ");
1102                }
1103            }
1104        }
1105        if (!sapi_module.phpinfo_as_text) {
1106            php_info_print(" </td>");
1107        } else if (i == (num_cols - 1)) {
1108            php_info_print("\n");
1109        }
1110    }
1111    if (!sapi_module.phpinfo_as_text) {
1112        php_info_print("</tr>\n");
1113    }
1114}
1115/* }}} */
1116
1117/* {{{ php_info_print_table_row
1118 */
1119PHPAPI void php_info_print_table_row(int num_cols, ...)
1120{
1121    va_list row_elements;
1122
1123    va_start(row_elements, num_cols);
1124    php_info_print_table_row_internal(num_cols, "v", row_elements);
1125    va_end(row_elements);
1126}
1127/* }}} */
1128
1129/* {{{ php_info_print_table_row_ex
1130 */
1131PHPAPI void php_info_print_table_row_ex(int num_cols, const char *value_class,
1132        ...)
1133{
1134    va_list row_elements;
1135
1136    va_start(row_elements, value_class);
1137    php_info_print_table_row_internal(num_cols, value_class, row_elements);
1138    va_end(row_elements);
1139}
1140/* }}} */
1141
1142/* {{{ register_phpinfo_constants
1143 */
1144void register_phpinfo_constants(INIT_FUNC_ARGS)
1145{
1146    REGISTER_LONG_CONSTANT("INFO_GENERAL", PHP_INFO_GENERAL, CONST_PERSISTENT|CONST_CS);
1147    REGISTER_LONG_CONSTANT("INFO_CREDITS", PHP_INFO_CREDITS, CONST_PERSISTENT|CONST_CS);
1148    REGISTER_LONG_CONSTANT("INFO_CONFIGURATION", PHP_INFO_CONFIGURATION, CONST_PERSISTENT|CONST_CS);
1149    REGISTER_LONG_CONSTANT("INFO_MODULES", PHP_INFO_MODULES, CONST_PERSISTENT|CONST_CS);
1150    REGISTER_LONG_CONSTANT("INFO_ENVIRONMENT", PHP_INFO_ENVIRONMENT, CONST_PERSISTENT|CONST_CS);
1151    REGISTER_LONG_CONSTANT("INFO_VARIABLES", PHP_INFO_VARIABLES, CONST_PERSISTENT|CONST_CS);
1152    REGISTER_LONG_CONSTANT("INFO_LICENSE", PHP_INFO_LICENSE, CONST_PERSISTENT|CONST_CS);
1153    REGISTER_LONG_CONSTANT("INFO_ALL", PHP_INFO_ALL, CONST_PERSISTENT|CONST_CS);
1154    REGISTER_LONG_CONSTANT("CREDITS_GROUP", PHP_CREDITS_GROUP, CONST_PERSISTENT|CONST_CS);
1155    REGISTER_LONG_CONSTANT("CREDITS_GENERAL",   PHP_CREDITS_GENERAL, CONST_PERSISTENT|CONST_CS);
1156    REGISTER_LONG_CONSTANT("CREDITS_SAPI",  PHP_CREDITS_SAPI, CONST_PERSISTENT|CONST_CS);
1157    REGISTER_LONG_CONSTANT("CREDITS_MODULES",   PHP_CREDITS_MODULES, CONST_PERSISTENT|CONST_CS);
1158    REGISTER_LONG_CONSTANT("CREDITS_DOCS",  PHP_CREDITS_DOCS, CONST_PERSISTENT|CONST_CS);
1159    REGISTER_LONG_CONSTANT("CREDITS_FULLPAGE",  PHP_CREDITS_FULLPAGE, CONST_PERSISTENT|CONST_CS);
1160    REGISTER_LONG_CONSTANT("CREDITS_QA",    PHP_CREDITS_QA, CONST_PERSISTENT|CONST_CS);
1161    REGISTER_LONG_CONSTANT("CREDITS_ALL",   PHP_CREDITS_ALL, CONST_PERSISTENT|CONST_CS);
1162}
1163/* }}} */
1164
1165/* {{{ proto void phpinfo([int what])
1166   Output a page of useful information about PHP and the current request */
1167PHP_FUNCTION(phpinfo)
1168{
1169    zend_long flag = PHP_INFO_ALL;
1170
1171    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) {
1172        return;
1173    }
1174
1175    /* Andale!  Andale!  Yee-Hah! */
1176    php_output_start_default(TSRMLS_C);
1177    php_print_info(flag TSRMLS_CC);
1178    php_output_end(TSRMLS_C);
1179
1180    RETURN_TRUE;
1181}
1182
1183/* }}} */
1184
1185/* {{{ proto string phpversion([string extension])
1186   Return the current PHP version */
1187PHP_FUNCTION(phpversion)
1188{
1189    char *ext_name = NULL;
1190    int ext_name_len = 0;
1191
1192    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &ext_name, &ext_name_len) == FAILURE) {
1193        return;
1194    }
1195
1196    if (!ext_name) {
1197        RETURN_STRING(PHP_VERSION);
1198    } else {
1199        const char *version;
1200        version = zend_get_module_version(ext_name);
1201        if (version == NULL) {
1202            RETURN_FALSE;
1203        }
1204        RETURN_STRING(version);
1205    }
1206}
1207/* }}} */
1208
1209/* {{{ proto void phpcredits([int flag])
1210   Prints the list of people who've contributed to the PHP project */
1211PHP_FUNCTION(phpcredits)
1212{
1213    zend_long flag = PHP_CREDITS_ALL;
1214
1215    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) {
1216        return;
1217    }
1218
1219    php_print_credits(flag TSRMLS_CC);
1220    RETURN_TRUE;
1221}
1222/* }}} */
1223
1224/* {{{ proto string php_sapi_name(void)
1225   Return the current SAPI module name */
1226PHP_FUNCTION(php_sapi_name)
1227{
1228    if (zend_parse_parameters_none() == FAILURE) {
1229        return;
1230    }
1231
1232    if (sapi_module.name) {
1233        RETURN_STRING(sapi_module.name);
1234    } else {
1235        RETURN_FALSE;
1236    }
1237}
1238
1239/* }}} */
1240
1241/* {{{ proto string php_uname(void)
1242   Return information about the system PHP was built on */
1243PHP_FUNCTION(php_uname)
1244{
1245    char *mode = "a";
1246    size_t modelen = sizeof("a")-1;
1247
1248    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &mode, &modelen) == FAILURE) {
1249        return;
1250    }
1251    RETURN_STR(php_get_uname(*mode));
1252}
1253
1254/* }}} */
1255
1256/* {{{ proto string php_ini_scanned_files(void)
1257   Return comma-separated string of .ini files parsed from the additional ini dir */
1258PHP_FUNCTION(php_ini_scanned_files)
1259{
1260    if (zend_parse_parameters_none() == FAILURE) {
1261        return;
1262    }
1263
1264    if (strlen(PHP_CONFIG_FILE_SCAN_DIR) && php_ini_scanned_files) {
1265        RETURN_STRING(php_ini_scanned_files);
1266    } else {
1267        RETURN_FALSE;
1268    }
1269}
1270/* }}} */
1271
1272/* {{{ proto string php_ini_loaded_file(void)
1273   Return the actual loaded ini filename */
1274PHP_FUNCTION(php_ini_loaded_file)
1275{
1276    if (zend_parse_parameters_none() == FAILURE) {
1277        return;
1278    }
1279
1280    if (php_ini_opened_path) {
1281        RETURN_STRING(php_ini_opened_path);
1282    } else {
1283        RETURN_FALSE;
1284    }
1285}
1286/* }}} */
1287
1288/*
1289 * Local variables:
1290 * tab-width: 4
1291 * c-basic-offset: 4
1292 * End:
1293 * vim600: sw=4 ts=4 fdm=marker
1294 * vim<600: sw=4 ts=4
1295 */
1296