1/*
2   +----------------------------------------------------------------------+
3   | PHP Version 7                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1997-2015 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#include "url.h"
41#include "php_string.h"
42
43#ifdef PHP_WIN32
44typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
45typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
46# include "winver.h"
47
48# if _MSC_VER < 1300
49#  define OSVERSIONINFOEX php_win_OSVERSIONINFOEX
50# endif
51#endif
52
53#define SECTION(name)   if (!sapi_module.phpinfo_as_text) { \
54                            php_info_print("<h2>" name "</h2>\n"); \
55                        } else { \
56                            php_info_print_table_start(); \
57                            php_info_print_table_header(1, name); \
58                            php_info_print_table_end(); \
59                        } \
60
61PHPAPI extern char *php_ini_opened_path;
62PHPAPI extern char *php_ini_scanned_path;
63PHPAPI extern char *php_ini_scanned_files;
64
65static int php_info_print_html_esc(const char *str, size_t len) /* {{{ */
66{
67    size_t written;
68    zend_string *new_str;
69
70    new_str = php_escape_html_entities((unsigned char *) str, len, 0, ENT_QUOTES, "utf-8");
71    written = php_output_write(new_str->val, new_str->len);
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    size_t len, written;
81    va_list argv;
82
83    va_start(argv, fmt);
84    len = vspprintf(&buf, 0, fmt, argv);
85    va_end(argv);
86
87    written = php_output_write(buf, len);
88    efree(buf);
89    return written;
90}
91/* }}} */
92
93static int php_info_print(const char *str) /* {{{ */
94{
95    return php_output_write(str, strlen(str));
96}
97/* }}} */
98
99static void php_info_print_stream_hash(const char *name, HashTable *ht) /* {{{ */
100{
101    zend_string *key;
102
103    if (ht) {
104        if (zend_hash_num_elements(ht)) {
105            int first = 1;
106
107            if (!sapi_module.phpinfo_as_text) {
108                php_info_printf("<tr><td class=\"e\">Registered %s</td><td class=\"v\">", name);
109            } else {
110                php_info_printf("\nRegistered %s => ", name);
111            }
112
113            ZEND_HASH_FOREACH_STR_KEY(ht, key) {
114                if (key) {
115                    if (first) {
116                        first = 0;
117                    } else {
118                        php_info_print(", ");
119                    }
120                    if (!sapi_module.phpinfo_as_text) {
121                        php_info_print_html_esc(key->val, key->len);
122                    } else {
123                        php_info_print(key->val);
124                    }
125                }
126            } ZEND_HASH_FOREACH_END();
127
128            if (!sapi_module.phpinfo_as_text) {
129                php_info_print("</td></tr>\n");
130            }
131        } else {
132            char reg_name[128];
133            snprintf(reg_name, sizeof(reg_name), "Registered %s", name);
134            php_info_print_table_row(2, reg_name, "none registered");
135        }
136    } else {
137        php_info_print_table_row(2, name, "disabled");
138    }
139}
140/* }}} */
141
142PHPAPI void php_info_print_module(zend_module_entry *zend_module) /* {{{ */
143{
144    if (zend_module->info_func || zend_module->version) {
145        if (!sapi_module.phpinfo_as_text) {
146            zend_string *url_name = php_url_encode(zend_module->name, strlen(zend_module->name));
147
148            php_strtolower(url_name->val, url_name->len);
149            php_info_printf("<h2><a name=\"module_%s\">%s</a></h2>\n", url_name->val, zend_module->name);
150
151            efree(url_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);
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 class=\"v\">%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(zval *el) /* {{{ */
176{
177    zend_module_entry *module = (zend_module_entry*)Z_PTR_P(el);
178    if (module->info_func || module->version) {
179        php_info_print_module(module);
180    }
181    return ZEND_HASH_APPLY_KEEP;
182}
183/* }}} */
184
185static int _display_module_info_def(zval *el) /* {{{ */
186{
187    zend_module_entry *module = (zend_module_entry*)Z_PTR_P(el);
188    if (!module->info_func && !module->version) {
189        php_info_print_module(module);
190    }
191    return ZEND_HASH_APPLY_KEEP;
192}
193/* }}} */
194
195/* {{{ php_print_gpcse_array
196 */
197static void php_print_gpcse_array(char *name, uint name_length)
198{
199    zval *data, *tmp, tmp2;
200    zend_string *string_key;
201    zend_ulong num_key;
202    zend_string *key;
203
204    key = zend_string_init(name, name_length, 0);
205    zend_is_auto_global(key);
206
207    if ((data = zend_hash_find(&EG(symbol_table), key)) != NULL && (Z_TYPE_P(data) == IS_ARRAY)) {
208        ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(data), num_key, string_key, tmp) {
209            if (!sapi_module.phpinfo_as_text) {
210                php_info_print("<tr>");
211                php_info_print("<td class=\"e\">");
212            }
213
214            php_info_print("$");
215            php_info_print(name);
216            php_info_print("['");
217
218            if (string_key != NULL) {
219                if (!sapi_module.phpinfo_as_text) {
220                    php_info_print_html_esc(string_key->val, string_key->len);
221                } else {
222                    php_info_print(string_key->val);
223                }
224            } else {
225                php_info_printf(ZEND_ULONG_FMT, num_key);
226            }
227            php_info_print("']");
228            if (!sapi_module.phpinfo_as_text) {
229                php_info_print("</td><td class=\"v\">");
230            } else {
231                php_info_print(" => ");
232            }
233            if (Z_TYPE_P(tmp) == IS_ARRAY) {
234                if (!sapi_module.phpinfo_as_text) {
235                    php_info_print("<pre>");
236                    zend_print_zval_r_ex((zend_write_func_t) php_info_print_html_esc, tmp, 0);
237                    php_info_print("</pre>");
238                } else {
239                    zend_print_zval_r(tmp, 0);
240                }
241            } else {
242                ZVAL_COPY_VALUE(&tmp2, tmp);
243                if (Z_TYPE(tmp2) != IS_STRING) {
244                    tmp = NULL;
245                    zval_copy_ctor(&tmp2);
246                    convert_to_string(&tmp2);
247                }
248
249                if (!sapi_module.phpinfo_as_text) {
250                    if (Z_STRLEN(tmp2) == 0) {
251                        php_info_print("<i>no value</i>");
252                    } else {
253                        php_info_print_html_esc(Z_STRVAL(tmp2), Z_STRLEN(tmp2));
254                    }
255                } else {
256                    php_info_print(Z_STRVAL(tmp2));
257                }
258
259                if (!tmp) {
260                    zval_dtor(&tmp2);
261                }
262            }
263            if (!sapi_module.phpinfo_as_text) {
264                php_info_print("</td></tr>\n");
265            } else {
266                php_info_print("\n");
267            }
268        } ZEND_HASH_FOREACH_END();
269    }
270    zend_string_free(key);
271}
272/* }}} */
273
274/* {{{ php_info_print_style
275 */
276void php_info_print_style(void)
277{
278    php_info_printf("<style type=\"text/css\">\n");
279    php_info_print_css();
280    php_info_printf("</style>\n");
281}
282/* }}} */
283
284/* {{{ php_info_html_esc
285 */
286PHPAPI zend_string *php_info_html_esc(char *string)
287{
288    return php_escape_html_entities((unsigned char *) string, strlen(string), 0, ENT_QUOTES, NULL);
289}
290/* }}} */
291
292#ifdef PHP_WIN32
293/* {{{  */
294
295char* php_get_windows_name()
296{
297    OSVERSIONINFOEX osvi;
298    SYSTEM_INFO si;
299    PGNSI pGNSI;
300    PGPI pGPI;
301    BOOL bOsVersionInfoEx;
302    DWORD dwType;
303    char *major = NULL, *sub = NULL, *retval;
304
305    ZeroMemory(&si, sizeof(SYSTEM_INFO));
306    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
307    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
308
309    if (!(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi))) {
310        return NULL;
311    }
312
313    pGNSI = (PGNSI) GetProcAddress(GetModuleHandle("kernel32.dll"), "GetNativeSystemInfo");
314    if(NULL != pGNSI) {
315        pGNSI(&si);
316    } else {
317        GetSystemInfo(&si);
318    }
319
320    if (VER_PLATFORM_WIN32_NT==osvi.dwPlatformId && osvi.dwMajorVersion > 4 ) {
321        if (osvi.dwMajorVersion == 6) {
322            if( osvi.dwMinorVersion == 0 ) {
323                if( osvi.wProductType == VER_NT_WORKSTATION ) {
324                    major = "Windows Vista";
325                } else {
326                    major = "Windows Server 2008";
327                }
328            } else
329            if ( osvi.dwMinorVersion == 1 ) {
330                if( osvi.wProductType == VER_NT_WORKSTATION )  {
331                    major = "Windows 7";
332                } else {
333                    major = "Windows Server 2008 R2";
334                }
335            } else if ( osvi.dwMinorVersion == 2 ) {
336                /* could be Windows 8/Windows Server 2012, could be Windows 8.1/Windows Server 2012 R2 */
337                OSVERSIONINFOEX osvi81;
338                DWORDLONG dwlConditionMask = 0;
339                int op = VER_GREATER_EQUAL;
340
341                ZeroMemory(&osvi81, sizeof(OSVERSIONINFOEX));
342                osvi81.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
343                osvi81.dwMajorVersion = 6;
344                osvi81.dwMinorVersion = 3;
345                osvi81.wServicePackMajor = 0;
346
347                VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op);
348                VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, op);
349                VER_SET_CONDITION(dwlConditionMask, VER_SERVICEPACKMAJOR, op);
350
351                if (VerifyVersionInfo(&osvi81,
352                    VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR,
353                    dwlConditionMask)) {
354                    osvi.dwMinorVersion = 3; /* Windows 8.1/Windows Server 2012 R2 */
355                    if( osvi.wProductType == VER_NT_WORKSTATION )  {
356                        major = "Windows 8.1";
357                    } else {
358                        major = "Windows Server 2012 R2";
359                    }
360                } else {
361                    if( osvi.wProductType == VER_NT_WORKSTATION )  {
362                        major = "Windows 8";
363                    } else {
364                        major = "Windows Server 2012";
365                    }
366                }
367            } else {
368                major = "Unknown Windows version";
369            }
370
371            pGPI = (PGPI) GetProcAddress(GetModuleHandle("kernel32.dll"), "GetProductInfo");
372            pGPI(6, 0, 0, 0, &dwType);
373
374            switch (dwType) {
375                case PRODUCT_ULTIMATE:
376                    sub = "Ultimate Edition";
377                    break;
378                case PRODUCT_HOME_PREMIUM:
379                    sub = "Home Premium Edition";
380                    break;
381                case PRODUCT_HOME_BASIC:
382                    sub = "Home Basic Edition";
383                    break;
384                case PRODUCT_ENTERPRISE:
385                    sub = "Enterprise Edition";
386                    break;
387                case PRODUCT_BUSINESS:
388                    sub = "Business Edition";
389                    break;
390                case PRODUCT_STARTER:
391                    sub = "Starter Edition";
392                    break;
393                case PRODUCT_CLUSTER_SERVER:
394                    sub = "Cluster Server Edition";
395                    break;
396                case PRODUCT_DATACENTER_SERVER:
397                    sub = "Datacenter Edition";
398                    break;
399                case PRODUCT_DATACENTER_SERVER_CORE:
400                    sub = "Datacenter Edition (core installation)";
401                    break;
402                case PRODUCT_ENTERPRISE_SERVER:
403                    sub = "Enterprise Edition";
404                    break;
405                case PRODUCT_ENTERPRISE_SERVER_CORE:
406                    sub = "Enterprise Edition (core installation)";
407                    break;
408                case PRODUCT_ENTERPRISE_SERVER_IA64:
409                    sub = "Enterprise Edition for Itanium-based Systems";
410                    break;
411                case PRODUCT_SMALLBUSINESS_SERVER:
412                    sub = "Small Business Server";
413                    break;
414                case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
415                    sub = "Small Business Server Premium Edition";
416                    break;
417                case PRODUCT_STANDARD_SERVER:
418                    sub = "Standard Edition";
419                    break;
420                case PRODUCT_STANDARD_SERVER_CORE:
421                    sub = "Standard Edition (core installation)";
422                    break;
423                case PRODUCT_WEB_SERVER:
424                    sub = "Web Server Edition";
425                    break;
426            }
427        }
428
429        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) {
430            if (GetSystemMetrics(SM_SERVERR2))
431                major = "Windows Server 2003 R2";
432            else if (osvi.wSuiteMask==VER_SUITE_STORAGE_SERVER)
433                major = "Windows Storage Server 2003";
434            else if (osvi.wSuiteMask==VER_SUITE_WH_SERVER)
435                major = "Windows Home Server";
436            else if (osvi.wProductType == VER_NT_WORKSTATION &&
437                si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) {
438                major = "Windows XP Professional x64 Edition";
439            } else {
440                major = "Windows Server 2003";
441            }
442
443            /* Test for the server type. */
444            if ( osvi.wProductType != VER_NT_WORKSTATION ) {
445                if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_IA64 ) {
446                    if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
447                        sub = "Datacenter Edition for Itanium-based Systems";
448                    else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
449                        sub = "Enterprise Edition for Itanium-based Systems";
450                }
451
452                else if ( si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 ) {
453                    if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
454                        sub = "Datacenter x64 Edition";
455                    else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
456                        sub = "Enterprise x64 Edition";
457                    else sub = "Standard x64 Edition";
458                } else {
459                    if ( osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER )
460                        sub = "Compute Cluster Edition";
461                    else if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
462                        sub = "Datacenter Edition";
463                    else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
464                        sub = "Enterprise Edition";
465                    else if ( osvi.wSuiteMask & VER_SUITE_BLADE )
466                        sub = "Web Edition";
467                    else sub = "Standard Edition";
468                }
469            }
470        }
471
472        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) {
473            major = "Windows XP";
474            if( osvi.wSuiteMask & VER_SUITE_PERSONAL ) {
475                sub = "Home Edition";
476            } else if (GetSystemMetrics(SM_MEDIACENTER)) {
477                sub = "Media Center Edition";
478            } else if (GetSystemMetrics(SM_STARTER)) {
479                sub = "Starter Edition";
480            } else if (GetSystemMetrics(SM_TABLETPC)) {
481                sub = "Tablet PC Edition";
482            } else {
483                sub = "Professional";
484            }
485        }
486
487        if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) {
488            major = "Windows 2000";
489
490            if (osvi.wProductType == VER_NT_WORKSTATION ) {
491                sub = "Professional";
492            } else {
493                if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
494                    sub = "Datacenter Server";
495                else if( osvi.wSuiteMask & VER_SUITE_ENTERPRISE )
496                    sub = "Advanced Server";
497                else sub = "Server";
498            }
499        }
500    } else {
501        return NULL;
502    }
503
504    spprintf(&retval, 0, "%s%s%s%s%s", major, sub?" ":"", sub?sub:"", osvi.szCSDVersion[0] != '\0'?" ":"", osvi.szCSDVersion);
505    return retval;
506}
507/* }}}  */
508
509/* {{{  */
510void php_get_windows_cpu(char *buf, int bufsize)
511{
512    SYSTEM_INFO SysInfo;
513    GetSystemInfo(&SysInfo);
514    switch (SysInfo.wProcessorArchitecture) {
515        case PROCESSOR_ARCHITECTURE_INTEL :
516            snprintf(buf, bufsize, "i%d", SysInfo.dwProcessorType);
517            break;
518        case PROCESSOR_ARCHITECTURE_MIPS :
519            snprintf(buf, bufsize, "MIPS R%d000", SysInfo.wProcessorLevel);
520            break;
521        case PROCESSOR_ARCHITECTURE_ALPHA :
522            snprintf(buf, bufsize, "Alpha %d", SysInfo.wProcessorLevel);
523            break;
524        case PROCESSOR_ARCHITECTURE_PPC :
525            snprintf(buf, bufsize, "PPC 6%02d", SysInfo.wProcessorLevel);
526            break;
527        case PROCESSOR_ARCHITECTURE_IA64 :
528            snprintf(buf, bufsize,  "IA64");
529            break;
530#if defined(PROCESSOR_ARCHITECTURE_IA32_ON_WIN64)
531        case PROCESSOR_ARCHITECTURE_IA32_ON_WIN64 :
532            snprintf(buf, bufsize, "IA32");
533            break;
534#endif
535#if defined(PROCESSOR_ARCHITECTURE_AMD64)
536        case PROCESSOR_ARCHITECTURE_AMD64 :
537            snprintf(buf, bufsize, "AMD64");
538            break;
539#endif
540        case PROCESSOR_ARCHITECTURE_UNKNOWN :
541        default:
542            snprintf(buf, bufsize, "Unknown");
543            break;
544    }
545}
546/* }}}  */
547#endif
548
549/* {{{ php_get_uname
550 */
551PHPAPI zend_string *php_get_uname(char mode)
552{
553    char *php_uname;
554    char tmp_uname[256];
555#ifdef PHP_WIN32
556    DWORD dwBuild=0;
557    DWORD dwVersion = GetVersion();
558    DWORD dwWindowsMajorVersion =  (DWORD)(LOBYTE(LOWORD(dwVersion)));
559    DWORD dwWindowsMinorVersion =  (DWORD)(HIBYTE(LOWORD(dwVersion)));
560    DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
561    char ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
562
563    GetComputerName(ComputerName, &dwSize);
564
565    if (mode == 's') {
566        php_uname = "Windows NT";
567    } else if (mode == 'r') {
568        snprintf(tmp_uname, sizeof(tmp_uname), "%d.%d", dwWindowsMajorVersion, dwWindowsMinorVersion);
569        php_uname = tmp_uname;
570    } else if (mode == 'n') {
571        php_uname = ComputerName;
572    } else if (mode == 'v') {
573        char *winver = php_get_windows_name();
574        dwBuild = (DWORD)(HIWORD(dwVersion));
575        if(winver == NULL) {
576            snprintf(tmp_uname, sizeof(tmp_uname), "build %d", dwBuild);
577        } else {
578            snprintf(tmp_uname, sizeof(tmp_uname), "build %d (%s)", dwBuild, winver);
579        }
580        php_uname = tmp_uname;
581        if(winver) {
582            efree(winver);
583        }
584    } else if (mode == 'm') {
585        php_get_windows_cpu(tmp_uname, sizeof(tmp_uname));
586        php_uname = tmp_uname;
587    } else { /* assume mode == 'a' */
588        char *winver = php_get_windows_name();
589        char wincpu[20];
590
591        ZEND_ASSERT(winver != NULL);
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 zend_string_init(php_uname, strlen(php_uname), 0);
664}
665/* }}} */
666
667/* {{{ php_print_info_htmlhead
668 */
669PHPAPI void php_print_info_htmlhead(void)
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();
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)
684{
685    Bucket *f = (Bucket *) a;
686    Bucket *s = (Bucket *) b;
687
688    return strcasecmp(((zend_module_entry *)Z_PTR(f->val))->name,
689                  ((zend_module_entry *)Z_PTR(s->val))->name);
690}
691/* }}} */
692
693/* {{{ php_print_info
694 */
695PHPAPI void php_print_info(int flag)
696{
697    char **env, *tmp1, *tmp2;
698    zend_string *php_uname;
699
700    if (!sapi_module.phpinfo_as_text) {
701        php_print_info_htmlhead();
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->val);
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() ? "enabled" : "disabled" );
796
797        {
798            const zend_multibyte_functions *functions = zend_multibyte_get_functions();
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());
822        php_info_print_stream_hash("Stream Socket Transports", php_stream_xport_get_hash());
823        php_info_print_stream_hash("Stream Filters", php_get_stream_filters_hash());
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));
839        }
840        php_info_print_box_end();
841        zend_string_free(php_uname);
842    }
843
844    zend_ini_sort_entries();
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
862        zend_hash_init(&sorted_registry, zend_hash_num_elements(&module_registry), NULL, NULL, 1);
863        zend_hash_copy(&sorted_registry, &module_registry, NULL);
864        zend_hash_sort(&sorted_registry, module_name_cmp, 0);
865
866        zend_hash_apply(&sorted_registry, _display_module_info_func);
867
868        SECTION("Additional Modules");
869        php_info_print_table_start();
870        php_info_print_table_header(1, "Module Name");
871        zend_hash_apply(&sorted_registry, _display_module_info_def);
872        php_info_print_table_end();
873
874        zend_hash_destroy(&sorted_registry);
875    }
876
877    if (flag & PHP_INFO_ENVIRONMENT) {
878        SECTION("Environment");
879        php_info_print_table_start();
880        php_info_print_table_header(2, "Variable", "Value");
881        for (env=environ; env!=NULL && *env !=NULL; env++) {
882            tmp1 = estrdup(*env);
883            if (!(tmp2=strchr(tmp1,'='))) { /* malformed entry? */
884                efree(tmp1);
885                continue;
886            }
887            *tmp2 = 0;
888            tmp2++;
889            php_info_print_table_row(2, tmp1, tmp2);
890            efree(tmp1);
891        }
892        php_info_print_table_end();
893    }
894
895    if (flag & PHP_INFO_VARIABLES) {
896        zval *data;
897
898        SECTION("PHP Variables");
899
900        php_info_print_table_start();
901        php_info_print_table_header(2, "Variable", "Value");
902        if ((data = zend_hash_str_find(&EG(symbol_table), "PHP_SELF", sizeof("PHP_SELF")-1)) != NULL && Z_TYPE_P(data) == IS_STRING) {
903            php_info_print_table_row(2, "PHP_SELF", Z_STRVAL_P(data));
904        }
905        if ((data = zend_hash_str_find(&EG(symbol_table), "PHP_AUTH_TYPE", sizeof("PHP_AUTH_TYPE")-1)) != NULL && Z_TYPE_P(data) == IS_STRING) {
906            php_info_print_table_row(2, "PHP_AUTH_TYPE", Z_STRVAL_P(data));
907        }
908        if ((data = zend_hash_str_find(&EG(symbol_table), "PHP_AUTH_USER", sizeof("PHP_AUTH_USER")-1)) != NULL && Z_TYPE_P(data) == IS_STRING) {
909            php_info_print_table_row(2, "PHP_AUTH_USER", Z_STRVAL_P(data));
910        }
911        if ((data = zend_hash_str_find(&EG(symbol_table), "PHP_AUTH_PW", sizeof("PHP_AUTH_PW")-1)) != NULL && Z_TYPE_P(data) == IS_STRING) {
912            php_info_print_table_row(2, "PHP_AUTH_PW", Z_STRVAL_P(data));
913        }
914        php_print_gpcse_array(ZEND_STRL("_REQUEST"));
915        php_print_gpcse_array(ZEND_STRL("_GET"));
916        php_print_gpcse_array(ZEND_STRL("_POST"));
917        php_print_gpcse_array(ZEND_STRL("_FILES"));
918        php_print_gpcse_array(ZEND_STRL("_COOKIE"));
919        php_print_gpcse_array(ZEND_STRL("_SERVER"));
920        php_print_gpcse_array(ZEND_STRL("_ENV"));
921        php_info_print_table_end();
922    }
923
924
925    if ((flag & PHP_INFO_CREDITS) && !sapi_module.phpinfo_as_text) {
926        php_info_print_hr();
927        php_print_credits(PHP_CREDITS_ALL & ~PHP_CREDITS_FULLPAGE);
928    }
929
930    if (flag & PHP_INFO_LICENSE) {
931        if (!sapi_module.phpinfo_as_text) {
932            SECTION("PHP License");
933            php_info_print_box_start(0);
934            php_info_print("<p>\n");
935            php_info_print("This program is free software; you can redistribute it and/or modify ");
936            php_info_print("it under the terms of the PHP License as published by the PHP Group ");
937            php_info_print("and included in the distribution in the file:  LICENSE\n");
938            php_info_print("</p>\n");
939            php_info_print("<p>");
940            php_info_print("This program is distributed in the hope that it will be useful, ");
941            php_info_print("but WITHOUT ANY WARRANTY; without even the implied warranty of ");
942            php_info_print("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
943            php_info_print("</p>\n");
944            php_info_print("<p>");
945            php_info_print("If you did not receive a copy of the PHP license, or have any questions about ");
946            php_info_print("PHP licensing, please contact license@php.net.\n");
947            php_info_print("</p>\n");
948            php_info_print_box_end();
949        } else {
950            php_info_print("\nPHP License\n");
951            php_info_print("This program is free software; you can redistribute it and/or modify\n");
952            php_info_print("it under the terms of the PHP License as published by the PHP Group\n");
953            php_info_print("and included in the distribution in the file:  LICENSE\n");
954            php_info_print("\n");
955            php_info_print("This program is distributed in the hope that it will be useful,\n");
956            php_info_print("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
957            php_info_print("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
958            php_info_print("\n");
959            php_info_print("If you did not receive a copy of the PHP license, or have any\n");
960            php_info_print("questions about PHP licensing, please contact license@php.net.\n");
961        }
962    }
963
964    if (!sapi_module.phpinfo_as_text) {
965        php_info_print("</div></body></html>");
966    }
967}
968/* }}} */
969
970PHPAPI void php_info_print_table_start(void) /* {{{ */
971{
972    if (!sapi_module.phpinfo_as_text) {
973        php_info_print("<table>\n");
974    } else {
975        php_info_print("\n");
976    }
977}
978/* }}} */
979
980PHPAPI void php_info_print_table_end(void) /* {{{ */
981{
982    if (!sapi_module.phpinfo_as_text) {
983        php_info_print("</table>\n");
984    }
985
986}
987/* }}} */
988
989PHPAPI void php_info_print_box_start(int flag) /* {{{ */
990{
991    php_info_print_table_start();
992    if (flag) {
993        if (!sapi_module.phpinfo_as_text) {
994            php_info_print("<tr class=\"h\"><td>\n");
995        }
996    } else {
997        if (!sapi_module.phpinfo_as_text) {
998            php_info_print("<tr class=\"v\"><td>\n");
999        } else {
1000            php_info_print("\n");
1001        }
1002    }
1003}
1004/* }}} */
1005
1006PHPAPI void php_info_print_box_end(void) /* {{{ */
1007{
1008    if (!sapi_module.phpinfo_as_text) {
1009        php_info_print("</td></tr>\n");
1010    }
1011    php_info_print_table_end();
1012}
1013/* }}} */
1014
1015PHPAPI void php_info_print_hr(void) /* {{{ */
1016{
1017    if (!sapi_module.phpinfo_as_text) {
1018        php_info_print("<hr />\n");
1019    } else {
1020        php_info_print("\n\n _______________________________________________________________________\n\n");
1021    }
1022}
1023/* }}} */
1024
1025PHPAPI void php_info_print_table_colspan_header(int num_cols, char *header) /* {{{ */
1026{
1027    int spaces;
1028
1029    if (!sapi_module.phpinfo_as_text) {
1030        php_info_printf("<tr class=\"h\"><th colspan=\"%d\">%s</th></tr>\n", num_cols, header );
1031    } else {
1032        spaces = (int)(74 - strlen(header));
1033        php_info_printf("%*s%s%*s\n", (int)(spaces/2), " ", header, (int)(spaces/2), " ");
1034    }
1035}
1036/* }}} */
1037
1038/* {{{ php_info_print_table_header
1039 */
1040PHPAPI void php_info_print_table_header(int num_cols, ...)
1041{
1042    int i;
1043    va_list row_elements;
1044    char *row_element;
1045
1046    va_start(row_elements, num_cols);
1047    if (!sapi_module.phpinfo_as_text) {
1048        php_info_print("<tr class=\"h\">");
1049    }
1050    for (i=0; i<num_cols; i++) {
1051        row_element = va_arg(row_elements, char *);
1052        if (!row_element || !*row_element) {
1053            row_element = " ";
1054        }
1055        if (!sapi_module.phpinfo_as_text) {
1056            php_info_print("<th>");
1057            php_info_print(row_element);
1058            php_info_print("</th>");
1059        } else {
1060            php_info_print(row_element);
1061            if (i < num_cols-1) {
1062                php_info_print(" => ");
1063            } else {
1064                php_info_print("\n");
1065            }
1066        }
1067    }
1068    if (!sapi_module.phpinfo_as_text) {
1069        php_info_print("</tr>\n");
1070    }
1071
1072    va_end(row_elements);
1073}
1074/* }}} */
1075
1076/* {{{ php_info_print_table_row_internal
1077 */
1078static void php_info_print_table_row_internal(int num_cols,
1079        const char *value_class, va_list row_elements)
1080{
1081    int i;
1082    char *row_element;
1083
1084    if (!sapi_module.phpinfo_as_text) {
1085        php_info_print("<tr>");
1086    }
1087    for (i=0; i<num_cols; i++) {
1088        if (!sapi_module.phpinfo_as_text) {
1089            php_info_printf("<td class=\"%s\">",
1090               (i==0 ? "e" : value_class )
1091            );
1092        }
1093        row_element = va_arg(row_elements, char *);
1094        if (!row_element || !*row_element) {
1095            if (!sapi_module.phpinfo_as_text) {
1096                php_info_print( "<i>no value</i>" );
1097            } else {
1098                php_info_print( " " );
1099            }
1100        } else {
1101            if (!sapi_module.phpinfo_as_text) {
1102                php_info_print_html_esc(row_element, strlen(row_element));
1103            } else {
1104                php_info_print(row_element);
1105                if (i < num_cols-1) {
1106                    php_info_print(" => ");
1107                }
1108            }
1109        }
1110        if (!sapi_module.phpinfo_as_text) {
1111            php_info_print(" </td>");
1112        } else if (i == (num_cols - 1)) {
1113            php_info_print("\n");
1114        }
1115    }
1116    if (!sapi_module.phpinfo_as_text) {
1117        php_info_print("</tr>\n");
1118    }
1119}
1120/* }}} */
1121
1122/* {{{ php_info_print_table_row
1123 */
1124PHPAPI void php_info_print_table_row(int num_cols, ...)
1125{
1126    va_list row_elements;
1127
1128    va_start(row_elements, num_cols);
1129    php_info_print_table_row_internal(num_cols, "v", row_elements);
1130    va_end(row_elements);
1131}
1132/* }}} */
1133
1134/* {{{ php_info_print_table_row_ex
1135 */
1136PHPAPI void php_info_print_table_row_ex(int num_cols, const char *value_class,
1137        ...)
1138{
1139    va_list row_elements;
1140
1141    va_start(row_elements, value_class);
1142    php_info_print_table_row_internal(num_cols, value_class, row_elements);
1143    va_end(row_elements);
1144}
1145/* }}} */
1146
1147/* {{{ register_phpinfo_constants
1148 */
1149void register_phpinfo_constants(INIT_FUNC_ARGS)
1150{
1151    REGISTER_LONG_CONSTANT("INFO_GENERAL", PHP_INFO_GENERAL, CONST_PERSISTENT|CONST_CS);
1152    REGISTER_LONG_CONSTANT("INFO_CREDITS", PHP_INFO_CREDITS, CONST_PERSISTENT|CONST_CS);
1153    REGISTER_LONG_CONSTANT("INFO_CONFIGURATION", PHP_INFO_CONFIGURATION, CONST_PERSISTENT|CONST_CS);
1154    REGISTER_LONG_CONSTANT("INFO_MODULES", PHP_INFO_MODULES, CONST_PERSISTENT|CONST_CS);
1155    REGISTER_LONG_CONSTANT("INFO_ENVIRONMENT", PHP_INFO_ENVIRONMENT, CONST_PERSISTENT|CONST_CS);
1156    REGISTER_LONG_CONSTANT("INFO_VARIABLES", PHP_INFO_VARIABLES, CONST_PERSISTENT|CONST_CS);
1157    REGISTER_LONG_CONSTANT("INFO_LICENSE", PHP_INFO_LICENSE, CONST_PERSISTENT|CONST_CS);
1158    REGISTER_LONG_CONSTANT("INFO_ALL", PHP_INFO_ALL, CONST_PERSISTENT|CONST_CS);
1159    REGISTER_LONG_CONSTANT("CREDITS_GROUP", PHP_CREDITS_GROUP, CONST_PERSISTENT|CONST_CS);
1160    REGISTER_LONG_CONSTANT("CREDITS_GENERAL",   PHP_CREDITS_GENERAL, CONST_PERSISTENT|CONST_CS);
1161    REGISTER_LONG_CONSTANT("CREDITS_SAPI",  PHP_CREDITS_SAPI, CONST_PERSISTENT|CONST_CS);
1162    REGISTER_LONG_CONSTANT("CREDITS_MODULES",   PHP_CREDITS_MODULES, CONST_PERSISTENT|CONST_CS);
1163    REGISTER_LONG_CONSTANT("CREDITS_DOCS",  PHP_CREDITS_DOCS, CONST_PERSISTENT|CONST_CS);
1164    REGISTER_LONG_CONSTANT("CREDITS_FULLPAGE",  PHP_CREDITS_FULLPAGE, CONST_PERSISTENT|CONST_CS);
1165    REGISTER_LONG_CONSTANT("CREDITS_QA",    PHP_CREDITS_QA, CONST_PERSISTENT|CONST_CS);
1166    REGISTER_LONG_CONSTANT("CREDITS_ALL",   PHP_CREDITS_ALL, CONST_PERSISTENT|CONST_CS);
1167}
1168/* }}} */
1169
1170/* {{{ proto void phpinfo([int what])
1171   Output a page of useful information about PHP and the current request */
1172PHP_FUNCTION(phpinfo)
1173{
1174    zend_long flag = PHP_INFO_ALL;
1175
1176    if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flag) == FAILURE) {
1177        return;
1178    }
1179
1180    /* Andale!  Andale!  Yee-Hah! */
1181    php_output_start_default();
1182    php_print_info((int)flag);
1183    php_output_end();
1184
1185    RETURN_TRUE;
1186}
1187
1188/* }}} */
1189
1190/* {{{ proto string phpversion([string extension])
1191   Return the current PHP version */
1192PHP_FUNCTION(phpversion)
1193{
1194    char *ext_name = NULL;
1195    size_t ext_name_len = 0;
1196
1197    if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &ext_name, &ext_name_len) == FAILURE) {
1198        return;
1199    }
1200
1201    if (!ext_name) {
1202        RETURN_STRING(PHP_VERSION);
1203    } else {
1204        const char *version;
1205        version = zend_get_module_version(ext_name);
1206        if (version == NULL) {
1207            RETURN_FALSE;
1208        }
1209        RETURN_STRING(version);
1210    }
1211}
1212/* }}} */
1213
1214/* {{{ proto void phpcredits([int flag])
1215   Prints the list of people who've contributed to the PHP project */
1216PHP_FUNCTION(phpcredits)
1217{
1218    zend_long flag = PHP_CREDITS_ALL;
1219
1220    if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flag) == FAILURE) {
1221        return;
1222    }
1223
1224    php_print_credits((int)flag);
1225    RETURN_TRUE;
1226}
1227/* }}} */
1228
1229/* {{{ proto string php_sapi_name(void)
1230   Return the current SAPI module name */
1231PHP_FUNCTION(php_sapi_name)
1232{
1233    if (zend_parse_parameters_none() == FAILURE) {
1234        return;
1235    }
1236
1237    if (sapi_module.name) {
1238        RETURN_STRING(sapi_module.name);
1239    } else {
1240        RETURN_FALSE;
1241    }
1242}
1243
1244/* }}} */
1245
1246/* {{{ proto string php_uname(void)
1247   Return information about the system PHP was built on */
1248PHP_FUNCTION(php_uname)
1249{
1250    char *mode = "a";
1251    size_t modelen = sizeof("a")-1;
1252
1253    if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &mode, &modelen) == FAILURE) {
1254        return;
1255    }
1256    RETURN_STR(php_get_uname(*mode));
1257}
1258
1259/* }}} */
1260
1261/* {{{ proto string php_ini_scanned_files(void)
1262   Return comma-separated string of .ini files parsed from the additional ini dir */
1263PHP_FUNCTION(php_ini_scanned_files)
1264{
1265    if (zend_parse_parameters_none() == FAILURE) {
1266        return;
1267    }
1268
1269    if (strlen(PHP_CONFIG_FILE_SCAN_DIR) && php_ini_scanned_files) {
1270        RETURN_STRING(php_ini_scanned_files);
1271    } else {
1272        RETURN_FALSE;
1273    }
1274}
1275/* }}} */
1276
1277/* {{{ proto string php_ini_loaded_file(void)
1278   Return the actual loaded ini filename */
1279PHP_FUNCTION(php_ini_loaded_file)
1280{
1281    if (zend_parse_parameters_none() == FAILURE) {
1282        return;
1283    }
1284
1285    if (php_ini_opened_path) {
1286        RETURN_STRING(php_ini_opened_path);
1287    } else {
1288        RETURN_FALSE;
1289    }
1290}
1291/* }}} */
1292
1293/*
1294 * Local variables:
1295 * tab-width: 4
1296 * c-basic-offset: 4
1297 * End:
1298 * vim600: sw=4 ts=4 fdm=marker
1299 * vim<600: sw=4 ts=4
1300 */
1301