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