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        ZEND_ASSERT(winver != NULL);
589
590        php_get_windows_cpu(wincpu, sizeof(wincpu));
591        dwBuild = (DWORD)(HIWORD(dwVersion));
592
593        /* Windows "version" 6.2 could be Windows 8/Windows Server 2012, but also Windows 8.1/Windows Server 2012 R2 */
594        if (dwWindowsMajorVersion == 6 && dwWindowsMinorVersion == 2) {
595            if (strncmp(winver, "Windows 8.1", 11) == 0 || strncmp(winver, "Windows Server 2012 R2", 22) == 0) {
596                dwWindowsMinorVersion = 3;
597            }
598        }
599
600        snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d build %d (%s) %s",
601                 "Windows NT", ComputerName,
602                 dwWindowsMajorVersion, dwWindowsMinorVersion, dwBuild, winver?winver:"unknown", wincpu);
603        if(winver) {
604            efree(winver);
605        }
606        php_uname = tmp_uname;
607    }
608#else
609#ifdef HAVE_SYS_UTSNAME_H
610    struct utsname buf;
611    if (uname((struct utsname *)&buf) == -1) {
612        php_uname = PHP_UNAME;
613    } else {
614#ifdef NETWARE
615        if (mode == 's') {
616            php_uname = buf.sysname;
617        } else if (mode == 'r') {
618            snprintf(tmp_uname, sizeof(tmp_uname), "%d.%d.%d",
619                     buf.netware_major, buf.netware_minor, buf.netware_revision);
620            php_uname = tmp_uname;
621        } else if (mode == 'n') {
622            php_uname = buf.servername;
623        } else if (mode == 'v') {
624            snprintf(tmp_uname, sizeof(tmp_uname), "libc-%d.%d.%d #%d",
625                     buf.libmajor, buf.libminor, buf.librevision, buf.libthreshold);
626            php_uname = tmp_uname;
627        } else if (mode == 'm') {
628            php_uname = buf.machine;
629        } else { /* assume mode == 'a' */
630            snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %d.%d.%d libc-%d.%d.%d #%d %s",
631                     buf.sysname, buf.servername,
632                     buf.netware_major, buf.netware_minor, buf.netware_revision,
633                     buf.libmajor, buf.libminor, buf.librevision, buf.libthreshold,
634                     buf.machine);
635            php_uname = tmp_uname;
636        }
637#else
638        if (mode == 's') {
639            php_uname = buf.sysname;
640        } else if (mode == 'r') {
641            php_uname = buf.release;
642        } else if (mode == 'n') {
643            php_uname = buf.nodename;
644        } else if (mode == 'v') {
645            php_uname = buf.version;
646        } else if (mode == 'm') {
647            php_uname = buf.machine;
648        } else { /* assume mode == 'a' */
649            snprintf(tmp_uname, sizeof(tmp_uname), "%s %s %s %s %s",
650                     buf.sysname, buf.nodename, buf.release, buf.version,
651                     buf.machine);
652            php_uname = tmp_uname;
653        }
654#endif /* NETWARE */
655    }
656#else
657    php_uname = PHP_UNAME;
658#endif
659#endif
660    return zend_string_init(php_uname, strlen(php_uname), 0);
661}
662/* }}} */
663
664/* {{{ php_print_info_htmlhead
665 */
666PHPAPI void php_print_info_htmlhead(TSRMLS_D)
667{
668    php_info_print("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n");
669    php_info_print("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
670    php_info_print("<head>\n");
671    php_info_print_style(TSRMLS_C);
672    php_info_print("<title>phpinfo()</title>");
673    php_info_print("<meta name=\"ROBOTS\" content=\"NOINDEX,NOFOLLOW,NOARCHIVE\" />");
674    php_info_print("</head>\n");
675    php_info_print("<body><div class=\"center\">\n");
676}
677/* }}} */
678
679/* {{{ module_name_cmp */
680static int module_name_cmp(const void *a, const void *b TSRMLS_DC)
681{
682    Bucket *f = (Bucket *) a;
683    Bucket *s = (Bucket *) b;
684
685    return strcasecmp(((zend_module_entry *)Z_PTR(f->val))->name,
686                  ((zend_module_entry *)Z_PTR(s->val))->name);
687}
688/* }}} */
689
690/* {{{ php_print_info
691 */
692PHPAPI void php_print_info(int flag TSRMLS_DC)
693{
694    char **env, *tmp1, *tmp2;
695    zend_string *php_uname;
696
697    if (!sapi_module.phpinfo_as_text) {
698        php_print_info_htmlhead(TSRMLS_C);
699    } else {
700        php_info_print("phpinfo()\n");
701    }
702
703    if (flag & PHP_INFO_GENERAL) {
704        char *zend_version = get_zend_version();
705        char temp_api[10];
706
707        php_uname = php_get_uname('a');
708
709        if (!sapi_module.phpinfo_as_text) {
710            php_info_print_box_start(1);
711        }
712
713        if (!sapi_module.phpinfo_as_text) {
714            time_t the_time;
715            struct tm *ta, tmbuf;
716
717            the_time = time(NULL);
718            ta = php_localtime_r(&the_time, &tmbuf);
719
720            php_info_print("<a href=\"http://www.php.net/\"><img border=\"0\" src=\"");
721            if (ta && (ta->tm_mon==3) && (ta->tm_mday==1)) {
722                php_info_print(PHP_EGG_LOGO_DATA_URI "\" alt=\"PHP logo\" /></a>");
723            } else {
724                php_info_print(PHP_LOGO_DATA_URI "\" alt=\"PHP logo\" /></a>");
725            }
726        }
727
728        if (!sapi_module.phpinfo_as_text) {
729            php_info_printf("<h1 class=\"p\">PHP Version %s</h1>\n", PHP_VERSION);
730        } else {
731            php_info_print_table_row(2, "PHP Version", PHP_VERSION);
732        }
733        php_info_print_box_end();
734        php_info_print_table_start();
735        php_info_print_table_row(2, "System", php_uname->val);
736        php_info_print_table_row(2, "Build Date", __DATE__ " " __TIME__);
737#ifdef COMPILER
738        php_info_print_table_row(2, "Compiler", COMPILER);
739#endif
740#ifdef ARCHITECTURE
741        php_info_print_table_row(2, "Architecture", ARCHITECTURE);
742#endif
743#ifdef CONFIGURE_COMMAND
744        php_info_print_table_row(2, "Configure Command", CONFIGURE_COMMAND );
745#endif
746
747        if (sapi_module.pretty_name) {
748            php_info_print_table_row(2, "Server API", sapi_module.pretty_name );
749        }
750
751#ifdef VIRTUAL_DIR
752        php_info_print_table_row(2, "Virtual Directory Support", "enabled" );
753#else
754        php_info_print_table_row(2, "Virtual Directory Support", "disabled" );
755#endif
756
757        php_info_print_table_row(2, "Configuration File (php.ini) Path", PHP_CONFIG_FILE_PATH);
758        php_info_print_table_row(2, "Loaded Configuration File", php_ini_opened_path ? php_ini_opened_path : "(none)");
759        php_info_print_table_row(2, "Scan this dir for additional .ini files", php_ini_scanned_path ? php_ini_scanned_path : "(none)");
760        php_info_print_table_row(2, "Additional .ini files parsed", php_ini_scanned_files ? php_ini_scanned_files : "(none)");
761
762        snprintf(temp_api, sizeof(temp_api), "%d", PHP_API_VERSION);
763        php_info_print_table_row(2, "PHP API", temp_api);
764
765        snprintf(temp_api, sizeof(temp_api), "%d", ZEND_MODULE_API_NO);
766        php_info_print_table_row(2, "PHP Extension", temp_api);
767
768        snprintf(temp_api, sizeof(temp_api), "%d", ZEND_EXTENSION_API_NO);
769        php_info_print_table_row(2, "Zend Extension", temp_api);
770
771        php_info_print_table_row(2, "Zend Extension Build", ZEND_EXTENSION_BUILD_ID);
772        php_info_print_table_row(2, "PHP Extension Build", ZEND_MODULE_BUILD_ID);
773
774#if ZEND_DEBUG
775        php_info_print_table_row(2, "Debug Build", "yes" );
776#else
777        php_info_print_table_row(2, "Debug Build", "no" );
778#endif
779
780#ifdef ZTS
781        php_info_print_table_row(2, "Thread Safety", "enabled" );
782#else
783        php_info_print_table_row(2, "Thread Safety", "disabled" );
784#endif
785
786#ifdef ZEND_SIGNALS
787        php_info_print_table_row(2, "Zend Signal Handling", "enabled" );
788#else
789        php_info_print_table_row(2, "Zend Signal Handling", "disabled" );
790#endif
791
792        php_info_print_table_row(2, "Zend Memory Manager", is_zend_mm(TSRMLS_C) ? "enabled" : "disabled" );
793
794        {
795            const zend_multibyte_functions *functions = zend_multibyte_get_functions(TSRMLS_C);
796            char *descr;
797            if (functions) {
798                spprintf(&descr, 0, "provided by %s", functions->provider_name);
799            } else {
800                descr = estrdup("disabled");
801            }
802            php_info_print_table_row(2, "Zend Multibyte Support", descr);
803            efree(descr);
804        }
805
806#if HAVE_IPV6
807        php_info_print_table_row(2, "IPv6 Support", "enabled" );
808#else
809        php_info_print_table_row(2, "IPv6 Support", "disabled" );
810#endif
811
812#if HAVE_DTRACE
813        php_info_print_table_row(2, "DTrace Support", "enabled" );
814#else
815        php_info_print_table_row(2, "DTrace Support", "disabled" );
816#endif
817
818        php_info_print_stream_hash("PHP Streams",  php_stream_get_url_stream_wrappers_hash() TSRMLS_CC);
819        php_info_print_stream_hash("Stream Socket Transports", php_stream_xport_get_hash() TSRMLS_CC);
820        php_info_print_stream_hash("Stream Filters", php_get_stream_filters_hash() TSRMLS_CC);
821
822        php_info_print_table_end();
823
824        /* Zend Engine */
825        php_info_print_box_start(0);
826        if (!sapi_module.phpinfo_as_text) {
827            php_info_print("<a href=\"http://www.zend.com/\"><img border=\"0\" src=\"");
828            php_info_print(ZEND_LOGO_DATA_URI "\" alt=\"Zend logo\" /></a>\n");
829        }
830        php_info_print("This program makes use of the Zend Scripting Language Engine:");
831        php_info_print(!sapi_module.phpinfo_as_text?"<br />":"\n");
832        if (sapi_module.phpinfo_as_text) {
833            php_info_print(zend_version);
834        } else {
835            zend_html_puts(zend_version, strlen(zend_version) TSRMLS_CC);
836        }
837        php_info_print_box_end();
838        zend_string_free(php_uname);
839    }
840
841    zend_ini_sort_entries(TSRMLS_C);
842
843    if (flag & PHP_INFO_CONFIGURATION) {
844        php_info_print_hr();
845        if (!sapi_module.phpinfo_as_text) {
846            php_info_print("<h1>Configuration</h1>\n");
847        } else {
848            SECTION("Configuration");
849        }
850        if (!(flag & PHP_INFO_MODULES)) {
851            SECTION("PHP Core");
852            display_ini_entries(NULL);
853        }
854    }
855
856    if (flag & PHP_INFO_MODULES) {
857        HashTable sorted_registry;
858
859        zend_hash_init(&sorted_registry, zend_hash_num_elements(&module_registry), NULL, NULL, 1);
860        zend_hash_copy(&sorted_registry, &module_registry, NULL);
861        zend_hash_sort(&sorted_registry, zend_qsort, module_name_cmp, 0 TSRMLS_CC);
862
863        zend_hash_apply(&sorted_registry, _display_module_info_func TSRMLS_CC);
864
865        SECTION("Additional Modules");
866        php_info_print_table_start();
867        php_info_print_table_header(1, "Module Name");
868        zend_hash_apply(&sorted_registry, _display_module_info_def TSRMLS_CC);
869        php_info_print_table_end();
870
871        zend_hash_destroy(&sorted_registry);
872    }
873
874    if (flag & PHP_INFO_ENVIRONMENT) {
875        SECTION("Environment");
876        php_info_print_table_start();
877        php_info_print_table_header(2, "Variable", "Value");
878        for (env=environ; env!=NULL && *env !=NULL; env++) {
879            tmp1 = estrdup(*env);
880            if (!(tmp2=strchr(tmp1,'='))) { /* malformed entry? */
881                efree(tmp1);
882                continue;
883            }
884            *tmp2 = 0;
885            tmp2++;
886            php_info_print_table_row(2, tmp1, tmp2);
887            efree(tmp1);
888        }
889        php_info_print_table_end();
890    }
891
892    if (flag & PHP_INFO_VARIABLES) {
893        zval *data;
894
895        SECTION("PHP Variables");
896
897        php_info_print_table_start();
898        php_info_print_table_header(2, "Variable", "Value");
899        if ((data = zend_hash_str_find(&EG(symbol_table).ht, "PHP_SELF", sizeof("PHP_SELF")-1)) != NULL && Z_TYPE_P(data) == IS_STRING) {
900            php_info_print_table_row(2, "PHP_SELF", Z_STRVAL_P(data));
901        }
902        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) {
903            php_info_print_table_row(2, "PHP_AUTH_TYPE", Z_STRVAL_P(data));
904        }
905        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) {
906            php_info_print_table_row(2, "PHP_AUTH_USER", Z_STRVAL_P(data));
907        }
908        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) {
909            php_info_print_table_row(2, "PHP_AUTH_PW", Z_STRVAL_P(data));
910        }
911        php_print_gpcse_array(ZEND_STRL("_REQUEST") TSRMLS_CC);
912        php_print_gpcse_array(ZEND_STRL("_GET") TSRMLS_CC);
913        php_print_gpcse_array(ZEND_STRL("_POST") TSRMLS_CC);
914        php_print_gpcse_array(ZEND_STRL("_FILES") TSRMLS_CC);
915        php_print_gpcse_array(ZEND_STRL("_COOKIE") TSRMLS_CC);
916        php_print_gpcse_array(ZEND_STRL("_SERVER") TSRMLS_CC);
917        php_print_gpcse_array(ZEND_STRL("_ENV") TSRMLS_CC);
918        php_info_print_table_end();
919    }
920
921
922    if ((flag & PHP_INFO_CREDITS) && !sapi_module.phpinfo_as_text) {
923        php_info_print_hr();
924        php_print_credits(PHP_CREDITS_ALL & ~PHP_CREDITS_FULLPAGE TSRMLS_CC);
925    }
926
927    if (flag & PHP_INFO_LICENSE) {
928        if (!sapi_module.phpinfo_as_text) {
929            SECTION("PHP License");
930            php_info_print_box_start(0);
931            php_info_print("<p>\n");
932            php_info_print("This program is free software; you can redistribute it and/or modify ");
933            php_info_print("it under the terms of the PHP License as published by the PHP Group ");
934            php_info_print("and included in the distribution in the file:  LICENSE\n");
935            php_info_print("</p>\n");
936            php_info_print("<p>");
937            php_info_print("This program is distributed in the hope that it will be useful, ");
938            php_info_print("but WITHOUT ANY WARRANTY; without even the implied warranty of ");
939            php_info_print("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
940            php_info_print("</p>\n");
941            php_info_print("<p>");
942            php_info_print("If you did not receive a copy of the PHP license, or have any questions about ");
943            php_info_print("PHP licensing, please contact license@php.net.\n");
944            php_info_print("</p>\n");
945            php_info_print_box_end();
946        } else {
947            php_info_print("\nPHP License\n");
948            php_info_print("This program is free software; you can redistribute it and/or modify\n");
949            php_info_print("it under the terms of the PHP License as published by the PHP Group\n");
950            php_info_print("and included in the distribution in the file:  LICENSE\n");
951            php_info_print("\n");
952            php_info_print("This program is distributed in the hope that it will be useful,\n");
953            php_info_print("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
954            php_info_print("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
955            php_info_print("\n");
956            php_info_print("If you did not receive a copy of the PHP license, or have any\n");
957            php_info_print("questions about PHP licensing, please contact license@php.net.\n");
958        }
959    }
960
961    if (!sapi_module.phpinfo_as_text) {
962        php_info_print("</div></body></html>");
963    }
964}
965/* }}} */
966
967PHPAPI void php_info_print_table_start(void) /* {{{ */
968{
969    if (!sapi_module.phpinfo_as_text) {
970        php_info_print("<table>\n");
971    } else {
972        php_info_print("\n");
973    }
974}
975/* }}} */
976
977PHPAPI void php_info_print_table_end(void) /* {{{ */
978{
979    if (!sapi_module.phpinfo_as_text) {
980        php_info_print("</table>\n");
981    }
982
983}
984/* }}} */
985
986PHPAPI void php_info_print_box_start(int flag) /* {{{ */
987{
988    php_info_print_table_start();
989    if (flag) {
990        if (!sapi_module.phpinfo_as_text) {
991            php_info_print("<tr class=\"h\"><td>\n");
992        }
993    } else {
994        if (!sapi_module.phpinfo_as_text) {
995            php_info_print("<tr class=\"v\"><td>\n");
996        } else {
997            php_info_print("\n");
998        }
999    }
1000}
1001/* }}} */
1002
1003PHPAPI void php_info_print_box_end(void) /* {{{ */
1004{
1005    if (!sapi_module.phpinfo_as_text) {
1006        php_info_print("</td></tr>\n");
1007    }
1008    php_info_print_table_end();
1009}
1010/* }}} */
1011
1012PHPAPI void php_info_print_hr(void) /* {{{ */
1013{
1014    if (!sapi_module.phpinfo_as_text) {
1015        php_info_print("<hr />\n");
1016    } else {
1017        php_info_print("\n\n _______________________________________________________________________\n\n");
1018    }
1019}
1020/* }}} */
1021
1022PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header) /* {{{ */
1023{
1024    int spaces;
1025
1026    if (!sapi_module.phpinfo_as_text) {
1027        php_info_printf("<tr class=\"h\"><th colspan=\"%d\">%s</th></tr>\n", num_cols, header );
1028    } else {
1029        spaces = (74 - strlen(header));
1030        php_info_printf("%*s%s%*s\n", (int)(spaces/2), " ", header, (int)(spaces/2), " ");
1031    }
1032}
1033/* }}} */
1034
1035/* {{{ php_info_print_table_header
1036 */
1037PHPAPI void php_info_print_table_header(int num_cols, ...)
1038{
1039    int i;
1040    va_list row_elements;
1041    char *row_element;
1042
1043    va_start(row_elements, num_cols);
1044    if (!sapi_module.phpinfo_as_text) {
1045        php_info_print("<tr class=\"h\">");
1046    }
1047    for (i=0; i<num_cols; i++) {
1048        row_element = va_arg(row_elements, char *);
1049        if (!row_element || !*row_element) {
1050            row_element = " ";
1051        }
1052        if (!sapi_module.phpinfo_as_text) {
1053            php_info_print("<th>");
1054            php_info_print(row_element);
1055            php_info_print("</th>");
1056        } else {
1057            php_info_print(row_element);
1058            if (i < num_cols-1) {
1059                php_info_print(" => ");
1060            } else {
1061                php_info_print("\n");
1062            }
1063        }
1064    }
1065    if (!sapi_module.phpinfo_as_text) {
1066        php_info_print("</tr>\n");
1067    }
1068
1069    va_end(row_elements);
1070}
1071/* }}} */
1072
1073/* {{{ php_info_print_table_row_internal
1074 */
1075static void php_info_print_table_row_internal(int num_cols,
1076        const char *value_class, va_list row_elements)
1077{
1078    int i;
1079    char *row_element;
1080
1081    if (!sapi_module.phpinfo_as_text) {
1082        php_info_print("<tr>");
1083    }
1084    for (i=0; i<num_cols; i++) {
1085        if (!sapi_module.phpinfo_as_text) {
1086            php_info_printf("<td class=\"%s\">",
1087               (i==0 ? "e" : value_class )
1088            );
1089        }
1090        row_element = va_arg(row_elements, char *);
1091        if (!row_element || !*row_element) {
1092            if (!sapi_module.phpinfo_as_text) {
1093                php_info_print( "<i>no value</i>" );
1094            } else {
1095                php_info_print( " " );
1096            }
1097        } else {
1098            if (!sapi_module.phpinfo_as_text) {
1099                php_info_print_html_esc(row_element, strlen(row_element));
1100            } else {
1101                php_info_print(row_element);
1102                if (i < num_cols-1) {
1103                    php_info_print(" => ");
1104                }
1105            }
1106        }
1107        if (!sapi_module.phpinfo_as_text) {
1108            php_info_print(" </td>");
1109        } else if (i == (num_cols - 1)) {
1110            php_info_print("\n");
1111        }
1112    }
1113    if (!sapi_module.phpinfo_as_text) {
1114        php_info_print("</tr>\n");
1115    }
1116}
1117/* }}} */
1118
1119/* {{{ php_info_print_table_row
1120 */
1121PHPAPI void php_info_print_table_row(int num_cols, ...)
1122{
1123    va_list row_elements;
1124
1125    va_start(row_elements, num_cols);
1126    php_info_print_table_row_internal(num_cols, "v", row_elements);
1127    va_end(row_elements);
1128}
1129/* }}} */
1130
1131/* {{{ php_info_print_table_row_ex
1132 */
1133PHPAPI void php_info_print_table_row_ex(int num_cols, const char *value_class,
1134        ...)
1135{
1136    va_list row_elements;
1137
1138    va_start(row_elements, value_class);
1139    php_info_print_table_row_internal(num_cols, value_class, row_elements);
1140    va_end(row_elements);
1141}
1142/* }}} */
1143
1144/* {{{ register_phpinfo_constants
1145 */
1146void register_phpinfo_constants(INIT_FUNC_ARGS)
1147{
1148    REGISTER_LONG_CONSTANT("INFO_GENERAL", PHP_INFO_GENERAL, CONST_PERSISTENT|CONST_CS);
1149    REGISTER_LONG_CONSTANT("INFO_CREDITS", PHP_INFO_CREDITS, CONST_PERSISTENT|CONST_CS);
1150    REGISTER_LONG_CONSTANT("INFO_CONFIGURATION", PHP_INFO_CONFIGURATION, CONST_PERSISTENT|CONST_CS);
1151    REGISTER_LONG_CONSTANT("INFO_MODULES", PHP_INFO_MODULES, CONST_PERSISTENT|CONST_CS);
1152    REGISTER_LONG_CONSTANT("INFO_ENVIRONMENT", PHP_INFO_ENVIRONMENT, CONST_PERSISTENT|CONST_CS);
1153    REGISTER_LONG_CONSTANT("INFO_VARIABLES", PHP_INFO_VARIABLES, CONST_PERSISTENT|CONST_CS);
1154    REGISTER_LONG_CONSTANT("INFO_LICENSE", PHP_INFO_LICENSE, CONST_PERSISTENT|CONST_CS);
1155    REGISTER_LONG_CONSTANT("INFO_ALL", PHP_INFO_ALL, CONST_PERSISTENT|CONST_CS);
1156    REGISTER_LONG_CONSTANT("CREDITS_GROUP", PHP_CREDITS_GROUP, CONST_PERSISTENT|CONST_CS);
1157    REGISTER_LONG_CONSTANT("CREDITS_GENERAL",   PHP_CREDITS_GENERAL, CONST_PERSISTENT|CONST_CS);
1158    REGISTER_LONG_CONSTANT("CREDITS_SAPI",  PHP_CREDITS_SAPI, CONST_PERSISTENT|CONST_CS);
1159    REGISTER_LONG_CONSTANT("CREDITS_MODULES",   PHP_CREDITS_MODULES, CONST_PERSISTENT|CONST_CS);
1160    REGISTER_LONG_CONSTANT("CREDITS_DOCS",  PHP_CREDITS_DOCS, CONST_PERSISTENT|CONST_CS);
1161    REGISTER_LONG_CONSTANT("CREDITS_FULLPAGE",  PHP_CREDITS_FULLPAGE, CONST_PERSISTENT|CONST_CS);
1162    REGISTER_LONG_CONSTANT("CREDITS_QA",    PHP_CREDITS_QA, CONST_PERSISTENT|CONST_CS);
1163    REGISTER_LONG_CONSTANT("CREDITS_ALL",   PHP_CREDITS_ALL, CONST_PERSISTENT|CONST_CS);
1164}
1165/* }}} */
1166
1167/* {{{ proto void phpinfo([int what])
1168   Output a page of useful information about PHP and the current request */
1169PHP_FUNCTION(phpinfo)
1170{
1171    zend_long flag = PHP_INFO_ALL;
1172
1173    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) {
1174        return;
1175    }
1176
1177    /* Andale!  Andale!  Yee-Hah! */
1178    php_output_start_default(TSRMLS_C);
1179    php_print_info(flag TSRMLS_CC);
1180    php_output_end(TSRMLS_C);
1181
1182    RETURN_TRUE;
1183}
1184
1185/* }}} */
1186
1187/* {{{ proto string phpversion([string extension])
1188   Return the current PHP version */
1189PHP_FUNCTION(phpversion)
1190{
1191    char *ext_name = NULL;
1192    size_t ext_name_len = 0;
1193
1194    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &ext_name, &ext_name_len) == FAILURE) {
1195        return;
1196    }
1197
1198    if (!ext_name) {
1199        RETURN_STRING(PHP_VERSION);
1200    } else {
1201        const char *version;
1202        version = zend_get_module_version(ext_name);
1203        if (version == NULL) {
1204            RETURN_FALSE;
1205        }
1206        RETURN_STRING(version);
1207    }
1208}
1209/* }}} */
1210
1211/* {{{ proto void phpcredits([int flag])
1212   Prints the list of people who've contributed to the PHP project */
1213PHP_FUNCTION(phpcredits)
1214{
1215    zend_long flag = PHP_CREDITS_ALL;
1216
1217    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flag) == FAILURE) {
1218        return;
1219    }
1220
1221    php_print_credits(flag TSRMLS_CC);
1222    RETURN_TRUE;
1223}
1224/* }}} */
1225
1226/* {{{ proto string php_sapi_name(void)
1227   Return the current SAPI module name */
1228PHP_FUNCTION(php_sapi_name)
1229{
1230    if (zend_parse_parameters_none() == FAILURE) {
1231        return;
1232    }
1233
1234    if (sapi_module.name) {
1235        RETURN_STRING(sapi_module.name);
1236    } else {
1237        RETURN_FALSE;
1238    }
1239}
1240
1241/* }}} */
1242
1243/* {{{ proto string php_uname(void)
1244   Return information about the system PHP was built on */
1245PHP_FUNCTION(php_uname)
1246{
1247    char *mode = "a";
1248    size_t modelen = sizeof("a")-1;
1249
1250    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &mode, &modelen) == FAILURE) {
1251        return;
1252    }
1253    RETURN_STR(php_get_uname(*mode));
1254}
1255
1256/* }}} */
1257
1258/* {{{ proto string php_ini_scanned_files(void)
1259   Return comma-separated string of .ini files parsed from the additional ini dir */
1260PHP_FUNCTION(php_ini_scanned_files)
1261{
1262    if (zend_parse_parameters_none() == FAILURE) {
1263        return;
1264    }
1265
1266    if (strlen(PHP_CONFIG_FILE_SCAN_DIR) && php_ini_scanned_files) {
1267        RETURN_STRING(php_ini_scanned_files);
1268    } else {
1269        RETURN_FALSE;
1270    }
1271}
1272/* }}} */
1273
1274/* {{{ proto string php_ini_loaded_file(void)
1275   Return the actual loaded ini filename */
1276PHP_FUNCTION(php_ini_loaded_file)
1277{
1278    if (zend_parse_parameters_none() == FAILURE) {
1279        return;
1280    }
1281
1282    if (php_ini_opened_path) {
1283        RETURN_STRING(php_ini_opened_path);
1284    } else {
1285        RETURN_FALSE;
1286    }
1287}
1288/* }}} */
1289
1290/*
1291 * Local variables:
1292 * tab-width: 4
1293 * c-basic-offset: 4
1294 * End:
1295 * vim600: sw=4 ts=4 fdm=marker
1296 * vim<600: sw=4 ts=4
1297 */
1298