mirror of
https://github.com/bdnugget/php-src.git
synced 2026-11-10 10:40:50 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e53a821b97 |
No files matched your search
+2
-15
@@ -111,8 +111,8 @@ Exceptions:
|
||||
Function calls in assert conditions may also cause this problem, if
|
||||
they modify one of their arguments or global variables.
|
||||
|
||||
[9] When commenting out code using a #if statement, do NOT use 0 only. Instead
|
||||
use "<cvs username here>_0". For example, #if FOO_0, where FOO is your
|
||||
[9] When commenting out code using a #if statement, do NOT use 0 only. Append
|
||||
to any 0 an _<cvs username here>. For example, #if 0_FOO, where FOO is
|
||||
cvs user foo. This allows easier tracking of why code was commented out,
|
||||
especially in bundled libraries.
|
||||
|
||||
@@ -122,19 +122,6 @@ Exceptions:
|
||||
existing. End users should use function_exists() to test for the
|
||||
existence of a function
|
||||
|
||||
[11] Prefer emalloc(), efree(), estrdup(), etc. to their standard C library
|
||||
counterparts. These functions implement an internal "safety-net"
|
||||
mechanism that ensures the deallocation of any unfreed memory at the
|
||||
end of a request. They also provide useful allocation and overflow
|
||||
information while running in debug mode.
|
||||
|
||||
In almost all cases, memory returned to the engine must be allocated
|
||||
using emalloc().
|
||||
|
||||
The use of malloc() should be limited to cases where a third-party
|
||||
library may need to control or free the memory, or when the memory in
|
||||
question needs to survive between multiple requests.
|
||||
|
||||
Naming Conventions
|
||||
------------------
|
||||
|
||||
|
||||
@@ -299,11 +299,6 @@ EXTENSION: icap
|
||||
MAINTENANCE: Unknown
|
||||
STATUS: Obsolete
|
||||
-------------------------------------------------------------------------------
|
||||
EXTENSION: iconv
|
||||
PRIMARY MAINTAINER: Moriyoshi Koizumi <moriyoshi@php.net>
|
||||
MAINTENANCE: Maintained
|
||||
STATUS: Working
|
||||
-------------------------------------------------------------------------------
|
||||
EXTENSION: imap
|
||||
PRIMARY MAINTAINER: Chuck Hagenbuch <chuck@horde.org>
|
||||
MAINTENANCE: Odd Fixes
|
||||
|
||||
+2
-4
@@ -41,16 +41,14 @@ install-modules: build-modules
|
||||
|
||||
install-tester:
|
||||
@echo "Installing regression tester: $(INSTALL_ROOT)$(PEAR_INSTALLDIR)/"
|
||||
@$(mkinstalldirs) $(INSTALL_ROOT)$(PEAR_INSTALLDIR)
|
||||
@$(mkinstalldirs) $(PEAR_INSTALLDIR)
|
||||
@$(INSTALL) -m 755 $(top_srcdir)/run-tests.php $(INSTALL_ROOT)$(PEAR_INSTALLDIR)
|
||||
|
||||
install-su: install-pear install-tester
|
||||
|
||||
test: $(SAPI_CLI_PATH)
|
||||
@TEST_PHP_EXECUTABLE=$(top_builddir)/$(SAPI_CLI_PATH) \
|
||||
TEST_PHP_SRCDIR=$(top_srcdir) \
|
||||
CC=$(CC) \
|
||||
$(top_builddir)/$(SAPI_CLI_PATH) -d 'open_basedir=' -d 'safe_mode=0' $(top_srcdir)/run-tests.php $(TESTS)
|
||||
$(top_builddir)/$(SAPI_CLI_PATH) $(top_srcdir)/run-tests.php $(TESTS)
|
||||
|
||||
clean:
|
||||
find . -name \*.lo -o -name \*.o | xargs rm -f
|
||||
|
||||
@@ -4,98 +4,6 @@ PHP 4 NEWS
|
||||
- ATTENTION! "make install" will *by default* install the CLI SAPI binary in
|
||||
{PREFIX}/bin/php. If you don't disable the CGI binary, it will be
|
||||
installed as {PREFIX}/bin/php-cgi.
|
||||
- Removed extensions: (Jan, Jani)
|
||||
. ext/aspell
|
||||
. ext/ccvs
|
||||
. ext/cybercash
|
||||
. ext/icap
|
||||
. sapi/fhttpd
|
||||
- Moved extensions to PECL (http://pear.php.net/): (James, Derick)
|
||||
. ext/vpopmail
|
||||
. ext/cybermut
|
||||
- Fixed bug #19566 (get_declared_classes() segfaults). (Moriyoshi, Marcus, Andi)
|
||||
- Fixed bug #20381 (array_merge_recursive mangles input arrays). (Moriyoshi)
|
||||
- Added -n command switch to cli and cgi version which allows to skip php.ini
|
||||
parsing at startup. (Marcus, Wez)
|
||||
- Fixed bug #19689 (absolute paths like /test/dir/ not working correctly).
|
||||
(Ilia)
|
||||
- Fixed bug #20424 (stream_get_meta_data crashes on a normal file stream).
|
||||
(Derick, Wez)
|
||||
- Added "neutral" language entry to mbstring spec. (Moriyoshi)
|
||||
- Changed bundled gd library to consider php.ini option memory_limit. (Marcus)
|
||||
- Modified log() to accept multiple bases. (Jason)
|
||||
- Fixed bugs #16190/18746 (ext/db: flatfile support with windows). (Marcus)
|
||||
- Added gd_info() which returns an array of gd support information. (Marcus)
|
||||
- Implemented features/changes requested in Bug #16960 (Timm):
|
||||
. Added a new function sybase_unbuffered_query()
|
||||
. Added a new function sybase_fetch_assoc()
|
||||
. Added sybase_set_message_handler() which enables users to handle
|
||||
server messages in a callback function
|
||||
. Added an ini entry for deadlock retries - retrying deadlocks can cause
|
||||
transaction state to break (sybct.deadlock_retry_count,
|
||||
defaults to -1 "forever").
|
||||
. Fixed sybase_fetch_object() not to return objects with numeric members
|
||||
. Fixed issues with identical fieldnames
|
||||
. Made sybase_fetch_*() functions return correct datatypes
|
||||
. Made phpinfo() section more verbose
|
||||
. Made sybase_query() error messages more verbose
|
||||
- Fixed bug #19935 (made OpenSSL file system operations abide by safe_mode
|
||||
& open_basedir restrictions). (Ilia)
|
||||
- Fixed bug #18868 (improved the check for availability of realpath()). (Ilia)
|
||||
- Fixed width/height detection of bmp images using getimagesize() function on
|
||||
big endian systems and added code to retrieve bmp bit depth. (Ilia)
|
||||
- Fixed bug #20035 (line counting error when script starts with #! in
|
||||
cgi/cli/fastcgi sapis). (Ilia)
|
||||
- Fixed bug #20235 (incorrect handling of symlinks on ZTS build). (Ilia)
|
||||
- Added sanity checks to headers_sent() & image_type_to_mime_type(). (Ilia)
|
||||
- Added an aditional parameter to the jdtojewish() function which makes
|
||||
the function return the symbolic hebrew name. (Moshe Doron, Derick)
|
||||
- Fixed bug #20169 (implode() clobbers first argument). (Moriyoshi)
|
||||
- Improved dba extension (Marcus)
|
||||
. Added dba_handlers() that returns an array of installed handlers and
|
||||
dba_list() that returns an associative array of open database files.
|
||||
. Added bundled cdb support wich can be activated by --with-cdb without a
|
||||
path. The bundled version supports cdb_make that allows writing cdb files.
|
||||
. Added optional skip parameter to dba_fetch() to support multiple key-value
|
||||
pairs with the same key for cdb handler.
|
||||
. Added locking for those handlers that do not have their own locking.
|
||||
. Added support for magic_quotes_runtime php.ini option.
|
||||
. Added flatfile support what finally makes ext/db deprecated.
|
||||
- Added imagerotate() which is available only when bundled libgd is used.
|
||||
(Pierre-Alain Joye, Ilia)
|
||||
- Fixed bug #17497 (mssql extension crashes if magic_quotes_runtime is on).
|
||||
(Sterling)
|
||||
- Remove $_FILES from $_REQUEST (import_request_variables is not modified),
|
||||
this didn't work properly in the first place, and added confusion. (Sterling)
|
||||
- Fix the socket_read() function on win32 to work in normal mode (reading to
|
||||
the end of a line), as well as binary mode. (Sterling)
|
||||
- Fixed bug #20110 (added sanity check to prevent include/require functions
|
||||
from trying to include directories). (Ilia)
|
||||
- Fixed bug #20108 (segmentation fault on printf("%1.1s", "string")). (Ilia)
|
||||
- Added dbx_escape_string() function to dbx module. (Marc)
|
||||
- Added Oracle (oci8) support to dbx module. (Marc)
|
||||
- Updated FDF extension to work with Adode fdftk 5.0. (Hartmut)
|
||||
- Made raw POST data to be available also as "php://input" stream. (Hartmut)
|
||||
- Added mb_strtolower() and mb_strtoupper(). (Moriyoshi)
|
||||
- Fixed an infinite loop in setlocale() when only invalid locale names
|
||||
were passed in the array. (patch by Pal Loberg, pallo@initio.no)
|
||||
- Fixed bugs #19156 and #19544 (COM extension leaks memory and keeps
|
||||
components referenced). (Harald)
|
||||
- Added fribidi_get_charsets() and fribidi_charset_info() functions. (Tal)
|
||||
- Added Oracle TIMESTAMP type to oci8 extension. (Thies)
|
||||
- Fixed fgets($fp) to read until EOL when length parameter is not set. (Wez)
|
||||
- Changed registry entries under "HKLM\SOFTWARE\PHP\Per Directory Values" to
|
||||
work also with administrative directives such as safe_mode, open_basedir,
|
||||
etc. (Claudio Felber)
|
||||
- Added str_word_count() function which counts words inside a string. (Ilia)
|
||||
- Added PGSQL_CONNECT_FORCE_NEW option to pg_connect() (Yasuo)
|
||||
- Added ICONV_IMPL and ICONV_VERSION constants to iconv extension to
|
||||
indicate which iconv implementation is used. (Moriyoshi)
|
||||
- Fixed bug #4232 (Added %e & %E support to printf/sprintf). (Ilia)
|
||||
- Fixed bug #17580 (Allow ini parser to parse files >16K). (Ilia)
|
||||
- Fixed bug #19649 (Sanity checks for browscap.ini parser). (Ilia)
|
||||
- Added experimental patch to address problem with floats on various locales.
|
||||
(Bug #17079). (Ilia)
|
||||
- Fixed bug #19280 (imap_header fails with many To: addresses). (Ilia)
|
||||
- Added mb_regex_set_options(). The Options parameters of various mbregex
|
||||
functions are now deprecated. (Moriyoshi)
|
||||
@@ -128,10 +36,11 @@ PHP 4 NEWS
|
||||
- Added array_diff_assoc() and array_intersect_assoc(). (Andrey)
|
||||
- Fixed bug #17825 (ob_start() chunk size option didn't work well). (Yasuo)
|
||||
- Fixed output buffer infinite loop when buffer_size became 0. (Marcus, Wez)
|
||||
- Fixed output buffering implicit flush. (Yasuo)
|
||||
- Added getopt() for parsing command line options and arguments. (Jon)
|
||||
- Added pg_fetch_assoc(), pg_fetch_all(), pg_ping(), pg_meta_data(), pg_convert(),
|
||||
pg_insert(), pg_select(), pg_update(), pg_delete(), pg_result_seek(),
|
||||
pg_unescape_bytea(), pg_get_notify() and pg_get_pid(). (Yasuo)
|
||||
pg_insert(), pg_select(), pg_update(), pg_delete(), pg_result_seek() and
|
||||
pg_unescape_bytea(). (Yasuo)
|
||||
- Fixed bug #17281 (Sanity checks for encoding sessions). (Ilia)
|
||||
- Fixed bug #16995 and #19392 (Prevent crash if $HTTP_SESSION_VARS != ARRAY).
|
||||
(Ilia)
|
||||
@@ -169,7 +78,7 @@ PHP 4 NEWS
|
||||
- Fixed bug #11643 (Session related, fix SID redefinition). (Ilia)
|
||||
- Fixed bug #18556 (Scripting Engine, problem with locales like tr_TR). (Ilia)
|
||||
- Changed y2k_compliance to default to 1 now. (Sascha)
|
||||
- Added platform independent socket error constants for better error handling. (Jason)
|
||||
- Added platform independent socket error constants for better error handling.
|
||||
- Fixed include(), require() and GD functions to work with remote files under
|
||||
win32. Fixed bug #18609 (ImageCreateFromJPEG can't fetch from a URL. (Wez)
|
||||
- Update output of phpinfo() to use more CSS to reduce the file size, do
|
||||
@@ -224,7 +133,7 @@ PHP 4 NEWS
|
||||
- Added XsltObject->result_dump_mem($result) for returning xslt-result directly
|
||||
into a string and XsltObject->result_dump_file($result,$file[,$compression])
|
||||
for dumping into a file. (morus.walter@web.de, chregu)
|
||||
- Made mime_magic and ZIP extensions available on Windows. (Edin)
|
||||
- Made mime_magic extension available on win32 platform. (Edin)
|
||||
- Added xslt_backend_version() and xslt_backend_name() for getting
|
||||
information about the processor backend. (chregu)
|
||||
- Added php.ini option "allow_webdav_methods" to allow handling of
|
||||
@@ -314,6 +223,7 @@ PHP 4 NEWS
|
||||
condition. Also fixed host resolution error messages on win32. (Jason)
|
||||
- Added optional 3rd parameter 'recursive' to ftp_rawlist() which will
|
||||
do 'LIST -R' instead of 'LIST'. (Jani)
|
||||
- Disabled the fifth parameter in mail() when safe-mode is turned on. (Derick)
|
||||
- Changed getimagesize() to always set unknown fields to 0 and added support
|
||||
for iff imagetype. (Marcus)
|
||||
- Added runtime Apache2 thread check to ensure we don't run a non-threaded
|
||||
@@ -388,6 +298,7 @@ PHP 4 NEWS
|
||||
when dealing with built-in extensions. (Sebastian)
|
||||
- Added large OID value (2^31 to 2^32) support for pg_lo_import(),
|
||||
pg_lo_unlink(), pg_lo_open() and pg_lo_export(). (Yasuo)
|
||||
- Changed the mbstring extension to be enabled by default. (Yasuo)
|
||||
- Fixed mixing OCIPlogon() and OCINLogon() to not leak Oracle-Sessions. (Thies)
|
||||
- Added php.ini options for EXIF extension to encode and decode Unicode/JIS
|
||||
user comments. (Marcus)
|
||||
@@ -440,7 +351,6 @@ PHP 4 NEWS
|
||||
process is now more portable and less resource-consuming. (Sascha)
|
||||
|
||||
06 Sep 2002, Version 4.2.3
|
||||
- Disabled the fifth parameter in mail() when safe-mode is turned on. (Derick)
|
||||
- Enable UTF8 modifier support for PCRE on win32. (Wez, Edin)
|
||||
- Enabled strcoll() on win32. (Markus)
|
||||
- Fixed possible ASCII control char injection in mail(). (Stefan Esser)
|
||||
|
||||
+5
-5
@@ -7,9 +7,9 @@ WHAT IT IS
|
||||
|
||||
HOW TO USE IT
|
||||
|
||||
Very simple. First, change to the ext/ directory of the PHP 4 sources. If
|
||||
you just need the basic framework and will be writing all the code in your
|
||||
functions yourself, you can now do
|
||||
Very simple. First, cd do directory ext/ in PHP 4 sources. If you just need
|
||||
the basic framework and will be writing all the code in your functions
|
||||
yourself, you can now do
|
||||
|
||||
./ext_skel --extname=module_name
|
||||
|
||||
@@ -22,7 +22,7 @@ HOW TO USE IT
|
||||
If you don't need to test the existence of any external header files,
|
||||
libraries or functions in them, the module is already almost ready to be
|
||||
compiled in PHP. Just remove 3 comments in your_module_name/config.m4,
|
||||
change back up to PHP sources top directory, and do
|
||||
cd back up to PHP sources top directory, and do
|
||||
|
||||
./buildconf; ./configure --enable-module_name; make
|
||||
|
||||
@@ -38,7 +38,7 @@ HOW TO USE IT
|
||||
FORMAT OF FUNCTION DEFINITIONS FILE
|
||||
|
||||
All the definitions must be on one line. In it's simplest form, it's just
|
||||
the function name, e.g.
|
||||
the function name, ie.
|
||||
|
||||
my_function
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ and not output any error messages.
|
||||
Both functions return SUCCESS or FAILURE depending on the result.
|
||||
|
||||
The auto-conversions are performed as necessary. Arrays, objects, and
|
||||
resources cannot be auto-converted.
|
||||
resources cannot be autoconverted.
|
||||
|
||||
|
||||
Type specifiers
|
||||
|
||||
@@ -4,7 +4,7 @@ $Id$
|
||||
HOW TO CREATE A SELF-CONTAINED PHP EXTENSION
|
||||
|
||||
A self-contained extension can be distributed independently of
|
||||
the PHP source. To create such an extension, two things are
|
||||
the PHP source. To create such an extension, three things are
|
||||
required:
|
||||
|
||||
- Configuration file (config.m4)
|
||||
@@ -115,9 +115,8 @@ CREATING SOURCE FILES
|
||||
|
||||
CREATING THE SELF-CONTAINED EXTENSION
|
||||
|
||||
Put config.m4 and the source files into one directory. Then, run phpize
|
||||
(this is installed during make install by PHP 4.0).
|
||||
|
||||
Put config.m4 and the source files into one directory. Afterwards,
|
||||
run phpize (this is installed during make install by PHP 4.0).
|
||||
For example, if you configured PHP with --prefix=/php, you would run
|
||||
|
||||
$ /php/bin/phpize
|
||||
|
||||
+9
-11
@@ -4,7 +4,7 @@ $Id$
|
||||
|
||||
WARNING: some prototypes in this file are out of date.
|
||||
The information contained here is being integrated into
|
||||
the PHP manual - stay tuned...
|
||||
the php manual - stay tuned...
|
||||
|
||||
Please send comments to: Wez Furlong <wez@thebrainroom.com>
|
||||
|
||||
@@ -12,7 +12,7 @@ Why Streams?
|
||||
============
|
||||
You may have noticed a shed-load of issock parameters flying around the PHP
|
||||
code; we don't want them - they are ugly and cumbersome and force you to
|
||||
special case sockets and files every time you need to work with a "user-level"
|
||||
special case sockets and files everytime you need to work with a "user-level"
|
||||
PHP file pointer.
|
||||
Streams take care of that and present the PHP extension coder with an ANSI
|
||||
stdio-alike API that looks much nicer and can be extended to support non file
|
||||
@@ -28,8 +28,6 @@ The main functions are:
|
||||
PHPAPI size_t php_stream_read(php_stream * stream, char * buf, size_t count);
|
||||
PHPAPI size_t php_stream_write(php_stream * stream, const char * buf, size_t
|
||||
count);
|
||||
PHPAPI size_t php_stream_printf(php_stream * stream TSRMLS_DC,
|
||||
const char * fmt, ...);
|
||||
PHPAPI int php_stream_eof(php_stream * stream);
|
||||
PHPAPI int php_stream_getc(php_stream * stream);
|
||||
PHPAPI char *php_stream_gets(php_stream * stream, char *buf, size_t maxlen);
|
||||
@@ -39,7 +37,7 @@ PHPAPI int php_stream_seek(php_stream * stream, off_t offset, int whence);
|
||||
PHPAPI off_t php_stream_tell(php_stream * stream);
|
||||
|
||||
These (should) behave in the same way as the ANSI stdio functions with similar
|
||||
names: fread, fwrite, fprintf, feof, fgetc, fgets, fclose, fflush, fseek, ftell.
|
||||
names: fread, fwrite, feof, fgetc, fgets, fclose, fflush, fseek, ftell.
|
||||
|
||||
Opening Streams
|
||||
===============
|
||||
@@ -140,7 +138,7 @@ make_seekable will always set newstream to be the stream that is valid
|
||||
if the function succeeds.
|
||||
When you have finished, remember to close the stream.
|
||||
|
||||
NOTE: If you only need to seek forward, there is no need to call this
|
||||
NOTE: If you only need to seek forwards, there is no need to call this
|
||||
function, as the php_stream_seek can emulate forward seeking when the
|
||||
whence parameter is SEEK_CUR.
|
||||
|
||||
@@ -190,7 +188,7 @@ If your system has the fopencookie function, php streams can synthesize a
|
||||
FILE* on top of any stream, which is useful for SSL sockets, memory based
|
||||
streams, data base streams etc. etc.
|
||||
|
||||
In situations where this is not desirable, you should query the stream
|
||||
In situations where this is not desireable, you should query the stream
|
||||
to see if it naturally supports FILE *. You can use this code snippet
|
||||
for this purpose:
|
||||
|
||||
@@ -284,7 +282,7 @@ Writing your own stream implementation
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
RULE #1: when writing your own streams: make sure you have configured PHP with
|
||||
--enable-debug.
|
||||
I've taken some great pains to hook into the Zend memory manager to help track
|
||||
I've taken some great pains to hook into the zend memory manager to help track
|
||||
down allocation problems. It will also help you spot incorrect use of the
|
||||
STREAMS_DC, STREAMS_CC and the semi-private STREAMS_REL_CC macros for function
|
||||
definitions.
|
||||
@@ -297,7 +295,7 @@ be more up to date than these docs :-)
|
||||
First, you need to figure out what data you need to associate with the
|
||||
php_stream. For example, you might need a pointer to some memory for memory
|
||||
based streams, or if you were making a stream to read data from an RDBMS like
|
||||
MySQL, you might want to store the connection and rowset handles.
|
||||
mysql, you might want to store the connection and rowset handles.
|
||||
|
||||
The stream has a field called abstract that you can use to hold this data.
|
||||
If you need to store more than a single field of data, define a structure to
|
||||
@@ -327,7 +325,7 @@ Once you have that part figured out, you can write your implementation and
|
||||
define the your own php_stream_ops struct (we called it my_ops in the above
|
||||
example).
|
||||
|
||||
For example, for reading from this weird MySQL stream:
|
||||
For example, for reading from this wierd mysql stream:
|
||||
|
||||
static size_t php_mysqlop_read(php_stream * stream, char * buf, size_t count)
|
||||
{
|
||||
@@ -356,7 +354,7 @@ are all mandatory. The rest are optional. Declare your stream ops struct:
|
||||
php_stream_ops my_ops = {
|
||||
php_mysqlop_write, php_mysqlop_read, php_mysqlop_close,
|
||||
php_mysqlop_flush, NULL, NULL, NULL,
|
||||
"Strange MySQL example"
|
||||
"Strange mySQL example"
|
||||
}
|
||||
|
||||
Thats it!
|
||||
|
||||
@@ -66,8 +66,8 @@ Check list for submitting patch
|
||||
-------------------------------
|
||||
- Did you run "make test" to check if your patch didn't break
|
||||
other features?
|
||||
- Did you compile PHP with --enable-debug and check the PHP and
|
||||
web server error logs when you test your patch?
|
||||
- Did you compile PHP with --enable-debug and check php/webserver
|
||||
error logs when you test your patch?
|
||||
- Did you build PHP for multi-threaded web servers. (Optional)
|
||||
- Did you create test script for "make test"? (Recommended)
|
||||
- Did you check your patch is unified format and it does not
|
||||
@@ -88,11 +88,6 @@ If you are patching PEAR, send the patch to pear-dev@lists.php.net.
|
||||
|
||||
Please add the prefix "[PATCH]" to your email subject and make sure
|
||||
to include the patch as a MIME attachment even if it is short.
|
||||
|
||||
NOTE: only MIME attachments of type 'text/*' are accepted. The
|
||||
easiest way to acclomplish this, is to make the extension
|
||||
'.txt'.
|
||||
|
||||
Test scripts should be included in the same email.
|
||||
Explain what has been fixed/added/changed by your patch.
|
||||
|
||||
|
||||
+78
-204
@@ -14,11 +14,10 @@ Usage:
|
||||
make test
|
||||
|
||||
"make test" basically executes "run-tests.php" script
|
||||
under the source root (parallel builds will not work). Therefore you
|
||||
can execute the script as follows:
|
||||
under source root. Therefore you can execute the script
|
||||
as follows
|
||||
|
||||
TEST_PHP_EXECUTABLE=sapi/cli/php \
|
||||
sapi/cli/php [-c /path/to/php.ini] run-tests.php [ext/foo/tests/GLOB]
|
||||
./sapi/cli/php -c /path/to/php.ini/ run-tests.php [ext/some_extension_name]
|
||||
|
||||
|
||||
[Which "php" executable "make test" look for]
|
||||
@@ -38,248 +37,123 @@ executing "run-tests.php" script, you may get errors.
|
||||
|
||||
[Which php.ini is used]
|
||||
-----------------------
|
||||
"make test" uses the same php.ini file as it would once installed.
|
||||
The tests have been written to be independent of that php.ini file,
|
||||
so if you find a test that is affected by a setting, please report
|
||||
this, so we can address the issue.
|
||||
"make test" force to use php.ini-dist as default config file. If
|
||||
you would like to test with other configuration file, user
|
||||
"run-tests.php" script.
|
||||
|
||||
Example:
|
||||
./sapi/cli/php -c /path/to/php.ini/ run-tests.php ext/standard
|
||||
|
||||
If you use php.ini other than php.ini-dist, you may see more failed
|
||||
tests.
|
||||
|
||||
|
||||
[Which test scripts are executed]
|
||||
---------------------------------
|
||||
"run-tests.php" ("make test"), without any arguments executes all
|
||||
test scripts by extracting all directories named "tests"
|
||||
from the source root and any subdirectories below. If there are files,
|
||||
which have a "phpt" extension, "run-tests.php" looks at the sections
|
||||
in these files, determines whether it should run it, by evaluating
|
||||
the 'SKIP' section. If the test is eligible for execution, the 'FILE'
|
||||
section is extracted into a ".php" file (with the same name besides
|
||||
the extension) and gets executed.
|
||||
When an argument is given or TESTS environment variable is set, the
|
||||
GLOB is expanded by the shell and any file with extension "*.phpt" is
|
||||
regarded as a test file.
|
||||
"run-tests.php" ("make test") executes all test scripts by default
|
||||
by looking all directory named "tests". If there are files have "phpt"
|
||||
extension, "run-tests.php" takes test php code from the file and
|
||||
executes it.
|
||||
|
||||
Tester can easily execute tests selectively with as follows.
|
||||
|
||||
Examples:
|
||||
./sapi/cli/php run-tests.php ext/mbstring/*
|
||||
./sapi/cli/php run-tests.php ext/mbstring/020.phpt
|
||||
./sapi/cli/php -c /path/to/php.ini/ run-tests.php ext/mbstring
|
||||
./sapi/cli/php -c /path/to/php.ini/ run-tests.php ext/mbstring/020.phpt
|
||||
|
||||
|
||||
[Test results]
|
||||
--------------
|
||||
Test results are printed to standard output. If there is a failed test,
|
||||
the "run-tests.php" script saves the result, the expected result and the
|
||||
code executed to the test script directory. For example, if
|
||||
ext/myext/tests/myext.phpt fails to pass, the following files are created:
|
||||
"run-tests.php" script saves the result, expected result and code
|
||||
executed to the test script directory. For example, if
|
||||
ext/myext/tests/myext.phpt is failed to pass, following files are
|
||||
created:
|
||||
|
||||
ext/myext/tests/myext.php - actual test file executed
|
||||
ext/myext/tests/myext.log - log of test execution (L)
|
||||
ext/myext/tests/myext.exp - expected output (E)
|
||||
ext/myext/tests/myext.out - output from test script (O)
|
||||
ext/myext/tests/myext.diff - diff of .out and .exp (D)
|
||||
|
||||
Failed tests are always bugs. Either the test is bugged or not considering
|
||||
factors applying to the tester's environment, or there is a bug in PHP.
|
||||
If this is a known bug, we strive to provide bug numbers, in either the
|
||||
test name or the file name. You can check the status of such a bug, by
|
||||
going to: http://bugs.php.net/12345 where 12345 is the bug number.
|
||||
For clarity and automated processing, bug numbers are prefixed by a hash
|
||||
sign '#' in test names and/or test cases are named bug12345.phpt.
|
||||
Tester can verify these files, if failed test is actually a bug or not.
|
||||
|
||||
NOTE: The files generated by tests can be selected by setting the
|
||||
environment variable TEST_PHP_LOG_FORMAT. For each file you want to be
|
||||
generated use the character in brackets as shown above (default is LEOD).
|
||||
The php file will be generated always.
|
||||
|
||||
NOTE: You can set environment variable TEST_PHP_DETAILED to enable
|
||||
detailed test information.
|
||||
|
||||
[Automated testing]
|
||||
If you like to keep up to speed, with latest developments and quality
|
||||
assurance, setting the environment variable NO_INTERACTION to 1, will not
|
||||
prompt the tester for any user input.
|
||||
|
||||
Normally, the exit status of "make test" is zero, regardless of the results
|
||||
of independent tests. Set the environment variable REPORT_EXIT_STATUS to 1,
|
||||
and "make test" will set the exit status ("$?") to non-zero, when an
|
||||
individual test has failed.
|
||||
|
||||
Example script to be run by cron(1):
|
||||
========== qa-test.sh =============
|
||||
#!/bin/sh
|
||||
|
||||
CO_DIR=$HOME/cvs/php4
|
||||
MYMAIL=qa-test@domain.com
|
||||
TMPDIR=/var/tmp
|
||||
TODAY=`date +"%Y%m%d"`
|
||||
|
||||
# Make sure compilation enviroment is correct
|
||||
CONFIGURE_OPTS='--disable-all --enable-cli --with-pcre'
|
||||
export MAKE=gmake
|
||||
export CC=gcc
|
||||
|
||||
# Set test environment
|
||||
export NO_INTERACTIVITY=1
|
||||
export REPORT_EXIT_STATUS=1
|
||||
|
||||
cd $CO_DIR
|
||||
cvs update . >>$TMPDIR/phpqatest.$TODAY
|
||||
./cvsclean ; ./buildconf ; ./configure $CONFIGURE_OPTS ; $MAKE
|
||||
$MAKE test >>$TMPDIR/phpqatest.$TODAY 2>&1
|
||||
if test $? -gt 0
|
||||
then
|
||||
cat $TMPDIR/phpqatest.$TODAY | mail -s"PHP-QA Test Failed for $TODAY" $MYMAIL
|
||||
fi
|
||||
========== end of qa-test.sh =============
|
||||
|
||||
NOTE: the exit status of run-tests.php will be 1 when
|
||||
REPORT_EXIT_STATUS is set. The result of "make test" may be higher
|
||||
than that. At present, gmake 3.79.1 returns 2, so it is
|
||||
advised to test for non-zero, rather then a specific value.
|
||||
|
||||
|
||||
[Creating new test files]
|
||||
-------------------------
|
||||
Writing test file is very easy if you are used to PHP.
|
||||
Writing test file is very easy if you are used to PHP. Test file
|
||||
has following format. Here is a actual test file from iconv module.
|
||||
|
||||
Here is an actual test file from standard module.
|
||||
|
||||
===== ext/standard/tests/strings/strtr.phpt =======
|
||||
===== ext/iconv/002.phpt =======
|
||||
--TEST--
|
||||
strtr() function
|
||||
--FILE--
|
||||
<?php
|
||||
/* Do not change this test it is a REATME.TESTING example. */
|
||||
$trans = array("hello"=>"hi", "hi"=>"hello", "a"=>"A", "world"=>"planet");
|
||||
var_dump(strtr("# hi all, I said hello world! #", $trans));
|
||||
?>
|
||||
--EXPECT--
|
||||
string(32) "# hello All, I sAid hi planet! #"
|
||||
===== ext/standard/tests/strings/strtr.phpt =======
|
||||
|
||||
As you can see the file is devided into several sections. Below is a
|
||||
list of all possible sections:
|
||||
|
||||
"--TEST--" is title of the test (required).
|
||||
"--SKIPIF--" is condition when to skip this test (optional).
|
||||
"--POST--" is POST variable passed to test script (optional).
|
||||
"--GET--" is GET variable passed to test script (optional).
|
||||
"--INI--" each line contains an ini setting e.g. foo=bar (optional).
|
||||
"--FILE--" is the test script (required).
|
||||
"--EXPECT--" is the expected output from the test script (required).
|
||||
"--EXPECTF--" is an alternative of --EXPECT--. The difference is that
|
||||
this form uses sscanf for output validation (alternative).
|
||||
"--EXPECTREGEX--" is an alternative of --EXPECT--. This form allows the tester
|
||||
to specify the result in a regular expression (alternative).
|
||||
|
||||
A test must at least contain the sections TEST, FILE and either EXPECT
|
||||
or EXPECTF. When a test is called run-test.php takes the name from the
|
||||
TEST section and writes the FILE section into a ".php" file with the
|
||||
same name as the ".phpt" file. This ".php" file will then be executed
|
||||
and its output compared to the contents of the EXPECT section. It is a
|
||||
good idea to generate output with var_dump() calls.
|
||||
|
||||
/ext/standard/tests/strings/str_shuffle.phpt is a good example for using
|
||||
EXPECTF instead of EXPECT. From time to time the algorithm used for shuffle
|
||||
changed and sometimes the machine used to execute the code has influence
|
||||
on the result of shuffle. But it always returns a three character string
|
||||
detectable by %s. Other scan-able forms are %i for integers, %d for numbers
|
||||
only, %f for floating point values, %c for single characters and %x for
|
||||
hexadecimal values.
|
||||
|
||||
==== /ext/standard/tests/strings/str_shuffle.phpt ===
|
||||
--TEST--
|
||||
Testing str_shuffle.
|
||||
--FILE--
|
||||
<?php
|
||||
/* Do not change this test it is a REATME.TESTING example. */
|
||||
$s = '123';
|
||||
var_dump(str_shuffle($s));
|
||||
var_dump($s);
|
||||
?>
|
||||
--EXPECTF--
|
||||
string(3) %s
|
||||
string(3) "123"
|
||||
==== end of /ext/standard/tests/strings/str_shuffle.phpt ===
|
||||
|
||||
/ext/standard/tests/strings/strings001.phpt is a good example for using
|
||||
EXPECTREGEX instead of EXPECT. This test also shows that in EXPECTREGEX
|
||||
some characters need to be escaped since otherwise they would be
|
||||
interpreted as a regular expression.
|
||||
|
||||
==== /ext/standard/tests/strings/strings001.phpt ===
|
||||
--TEST--
|
||||
Test whether strstr() and strrchr() are binary safe.
|
||||
--FILE--
|
||||
<?php
|
||||
/* Do not change this test it is a REATME.TESTING example. */
|
||||
$s = "alabala nica".chr(0)."turska panica";
|
||||
var_dump(strstr($s, "nic"));
|
||||
var_dump(strrchr($s," nic"));
|
||||
?>
|
||||
--EXPECTREGEX--
|
||||
string\(18\) \"nica\x00turska panica\"
|
||||
string\(19\) \" nica\x00turska panica\"
|
||||
==== end of /ext/standard/tests/strings/strings001.phpt ===
|
||||
|
||||
Some tests depend on modules or functions available only in certain versions
|
||||
or they even require minimum version of php or zend. These tests should be
|
||||
skipped when the requirement cannot be fullfilled. To achieve this you can
|
||||
use the SKIPIF section. To tell run-test.php that your test should be skipped
|
||||
the SKIPIF section must print out the word "skip" followed by a reason why
|
||||
the test should skip.
|
||||
|
||||
==== /ext/exif/tests/exif005.phpt ===
|
||||
--TEST--
|
||||
Check for exif_read_data, unusual IFD start
|
||||
UCS4BE to ASCII
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (!extension_loaded('exif')) print 'skip exif extension not available';
|
||||
?>
|
||||
<?php include('skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
/* Do not change this test it is a REATME.TESTING example.
|
||||
* test5.jpg is a 1*1 image that contains an Exif section with ifd = 00000009h
|
||||
*/
|
||||
$image = exif_read_data('./ext/exif/tests/test5.jpg','',true,false);
|
||||
var_dump($image['IFD0']);
|
||||
?>
|
||||
<?php include('002.inc'); ?>
|
||||
--EXPECT--
|
||||
array(2) {
|
||||
["ImageDescription"]=>
|
||||
string(11) "Ifd00000009"
|
||||
["DateTime"]=>
|
||||
string(19) "2002:10:18 20:06:00"
|
||||
abcd
|
||||
abcd
|
||||
===== end of ext/iconv/002.phpt =======
|
||||
|
||||
As you can see the file has the following sections:
|
||||
|
||||
"--TEST--" is title of the test.
|
||||
"--SKIPIF--" is condition when to skip this test (optional).
|
||||
"--POST--" is POST variable passed to test script (optional).
|
||||
"--GET--" is GET variable passed to test script (optional).
|
||||
"--INI--" each line contains an ini setting e.g. foo=bar (optional).
|
||||
"--FILE--" is the test script.
|
||||
"--EXPECT--" is the expected output from the test script.
|
||||
|
||||
ext/iconv/002.phpt uses 2 files. "skipif.inc" is used to skip
|
||||
test when test cannot be performed such as iconv module is not
|
||||
compiled or loaded.
|
||||
|
||||
==== ext/iconv/skipif.inc ====
|
||||
<?php
|
||||
// This script prints "skip" if condition does not meet.
|
||||
|
||||
if (!extension_loaded("iconv") && ini_get("enable_dl")) {
|
||||
$dlext = (substr(PHP_OS, 0, 3) == "WIN") ? ".dll" : ".so";
|
||||
@dl("iconv$dlext");
|
||||
}
|
||||
==== end of /ext/exif/tests/exif005.phpt ===
|
||||
if (!extension_loaded("iconv")) {
|
||||
die("skip\n");
|
||||
}
|
||||
?>
|
||||
==== end of ext/iconv/skipif.inc ====
|
||||
|
||||
Test script and SKIPIF code should be directly written into *.phpt. However,
|
||||
it is recommended to use include files when more test scripts depend on the
|
||||
same SKIPIF code or when certain test files need the same values for some
|
||||
input. But no file used by any test should have one of the following
|
||||
extensions: ".php", ".log", ".exp", ".out" or ".diff".
|
||||
ext/inconv/002.inc is the test script. "run-tests.php" script
|
||||
executes test script with CGI executable.
|
||||
|
||||
Tests should be named according to the following list:
|
||||
==== ext/iconv/002.inc ===
|
||||
<?php
|
||||
/*
|
||||
Expected output:
|
||||
abcd
|
||||
abcd
|
||||
*/
|
||||
|
||||
Class: Name: Example:
|
||||
Tests for bugs bug<bugid>.phpt bug17123.phpt
|
||||
Tests for functions <functionname>.phpt dba_open.phpt
|
||||
General tests for extensions <extname><no>.phpt dba3.phpt
|
||||
$s = unpack("V*", iconv("ascii","UCS-4LE", "abcd"));
|
||||
foreach($s as $c) { print "&#$c;"; } print "\n";
|
||||
|
||||
When you use an include file for the SKIPIF section it should be named
|
||||
"skipif.inc" and an include file used in the FILE section of many tests
|
||||
should be named "test.inc".
|
||||
$s = pack("NNNN", 97, 98, 99, 100);
|
||||
$q = iconv("UCS-4BE", "ascii", $s);
|
||||
print $q; print "\n";
|
||||
?>
|
||||
=== end of ext/iconv/002.inc ===
|
||||
|
||||
NOTE: All tests should run correctly with error_reporting(E_ALL) and
|
||||
display_errors=1. This is the default when called from run-test.php.
|
||||
If you have a good reason for lowering the error reporting, use --INI--
|
||||
section and comment this in your testcode.
|
||||
Test script and skipif code may be directly written into *.phpt.
|
||||
However, it is recommended to use other files for ease of writing
|
||||
test scripts.
|
||||
|
||||
NOTE: If your test intentionally generates a PHP warning message use
|
||||
$php_errormsg variable, which you can then output. This will result
|
||||
in a consistent error message output across all platforms and PHP
|
||||
configurations, preventing your test from failing due inconsistencies
|
||||
in the error message content.
|
||||
|
||||
[How to help us]
|
||||
----------------
|
||||
|
||||
@@ -2,7 +2,7 @@ PHP Build System V5 Overview
|
||||
|
||||
- supports Makefile.ins during transition phase
|
||||
- not-really-portable Makefile includes have been eliminated
|
||||
- supports separate build directories without VPATH by using
|
||||
- supports seperate build directories without VPATH by using
|
||||
explicit rules only
|
||||
- does not waste disk-space/CPU-time for building temporary libraries
|
||||
=> especially noticeable on slower systems
|
||||
@@ -50,8 +50,8 @@ are specified in the config.m4 now using the following macro:
|
||||
PHP_NEW_EXTENSION(foo, foo.c bar.c baz.cpp, $ext_shared)
|
||||
|
||||
E.g. this enables the extension foo which consists of three source-code
|
||||
modules, two in C and one in C++. And, depending on the user's wishes,
|
||||
the extension will even be built as a dynamic module.
|
||||
modules, two in C and one in C++. And dependending on the user's
|
||||
wishes, the extension will even be built as a dynamic module.
|
||||
|
||||
The full syntax:
|
||||
|
||||
|
||||
@@ -158,6 +158,7 @@ ext/standard
|
||||
basename()
|
||||
dirname()
|
||||
strrpos()
|
||||
strrchr()
|
||||
strip_tags()
|
||||
|
||||
ext/wddx
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ static FILE *tsrm_error_file;
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define TSRM_ERROR(args)
|
||||
#define TSRM_ERROR
|
||||
#define TSRM_SAFE_RETURN_RSRC(array, offset, range) \
|
||||
if (offset==0) { \
|
||||
return &array; \
|
||||
|
||||
@@ -14,13 +14,11 @@
|
||||
# include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#if HAVE_ALLOCA_H && !defined(_ALLOCA_H)
|
||||
# include <alloca.h>
|
||||
#endif
|
||||
|
||||
/* AIX requires this to be the first thing in the file. */
|
||||
#ifndef __GNUC__
|
||||
# ifndef HAVE_ALLOCA_H
|
||||
# if HAVE_ALLOCA_H
|
||||
# include <alloca.h>
|
||||
# else
|
||||
# ifdef _AIX
|
||||
#pragma alloca
|
||||
# else
|
||||
|
||||
+63
-24
@@ -41,7 +41,7 @@
|
||||
#include "tsrm_nw.h"
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_REALPATH
|
||||
#ifdef __BEOS__
|
||||
#define realpath(x,y) strcpy(y,x)
|
||||
#endif
|
||||
|
||||
@@ -284,7 +284,7 @@ CWD_API char *virtual_getcwd(char *buf, size_t size TSRMLS_DC)
|
||||
|
||||
/* Resolve path relatively to state and put the real path into state */
|
||||
/* returns 0 for ok, 1 for error */
|
||||
CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath)
|
||||
CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path)
|
||||
{
|
||||
int path_length = strlen(path);
|
||||
char *ptr, *path_copy;
|
||||
@@ -304,7 +304,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
|
||||
|
||||
#if !defined(TSRM_WIN32) && !defined(NETWARE)
|
||||
if (IS_ABSOLUTE_PATH(path, path_length)) {
|
||||
if (use_realpath && realpath(path, resolved_path)) {
|
||||
if (realpath(path, resolved_path)) {
|
||||
path = resolved_path;
|
||||
path_length = strlen(path);
|
||||
}
|
||||
@@ -322,7 +322,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
|
||||
memcpy(ptr, path, path_length);
|
||||
ptr += path_length;
|
||||
*ptr = '\0';
|
||||
if (use_realpath && realpath(tmp, resolved_path)) {
|
||||
if (realpath(tmp, resolved_path)) {
|
||||
path = resolved_path;
|
||||
path_length = strlen(path);
|
||||
}
|
||||
@@ -337,7 +337,12 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
|
||||
fprintf(stderr,"cwd = %s path = %s\n", state->cwd, path);
|
||||
#endif
|
||||
if (IS_ABSOLUTE_PATH(path_copy, path_length)) {
|
||||
/* COPY_WHEN_ABSOLUTE needs to account for volume name that is unique to NetWare absolute paths */
|
||||
#ifndef NETWARE
|
||||
copy_amount = COPY_WHEN_ABSOLUTE;
|
||||
#else
|
||||
copy_amount = COPY_WHEN_ABSOLUTE(path_copy);
|
||||
#endif
|
||||
is_absolute = 1;
|
||||
#ifdef TSRM_WIN32
|
||||
} else if (IS_UNC_PATH(path_copy, path_length)) {
|
||||
@@ -410,7 +415,12 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
|
||||
ptr = tsrm_strtok_r(NULL, TOKENIZER_STRING, &tok);
|
||||
}
|
||||
|
||||
/* COPY_WHEN_ABSOLUTE needs to account for volume name that is unique to NetWare absolute paths */
|
||||
#ifndef NETWARE
|
||||
if (state->cwd_length == COPY_WHEN_ABSOLUTE) {
|
||||
#else
|
||||
if (state->cwd_length == COPY_WHEN_ABSOLUTE(state->cwd)) {
|
||||
#endif
|
||||
state->cwd = (char *) realloc(state->cwd, state->cwd_length+1+1);
|
||||
state->cwd[state->cwd_length] = DEFAULT_SLASH;
|
||||
state->cwd[state->cwd_length+1] = '\0';
|
||||
@@ -439,7 +449,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
|
||||
|
||||
CWD_API int virtual_chdir(const char *path TSRMLS_DC)
|
||||
{
|
||||
return virtual_file_ex(&CWDG(cwd), path, php_is_dir_ok, 1)?-1:0;
|
||||
return virtual_file_ex(&CWDG(cwd), path, php_is_dir_ok)?-1:0;
|
||||
}
|
||||
|
||||
CWD_API int virtual_chdir_file(const char *path, int (*p_chdir)(const char *path TSRMLS_DC) TSRMLS_DC)
|
||||
@@ -460,7 +470,12 @@ CWD_API int virtual_chdir_file(const char *path, int (*p_chdir)(const char *path
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* COPY_WHEN_ABSOLUTE needs to account for volume name that is unique to NetWare absolute paths */
|
||||
#ifndef NETWARE
|
||||
if (length == COPY_WHEN_ABSOLUTE && IS_ABSOLUTE_PATH(path, length+1)) { /* Also use trailing slash if this is absolute */
|
||||
#else
|
||||
if (length == COPY_WHEN_ABSOLUTE(path) && IS_ABSOLUTE_PATH(path, length+1)) { /* Also use trailing slash if this is absolute */
|
||||
#endif
|
||||
length++;
|
||||
}
|
||||
temp = (char *) tsrm_do_alloca(length+1);
|
||||
@@ -480,7 +495,7 @@ CWD_API char *virtual_realpath(const char *path, char *real_path TSRMLS_DC)
|
||||
int retval;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
retval = virtual_file_ex(&new_state, path, NULL, 1);
|
||||
retval = virtual_file_ex(&new_state, path, NULL);
|
||||
|
||||
if (!retval) {
|
||||
int len = new_state.cwd_length>MAXPATHLEN-1?MAXPATHLEN-1:new_state.cwd_length;
|
||||
@@ -498,7 +513,7 @@ CWD_API int virtual_filepath_ex(const char *path, char **filepath, verify_path_f
|
||||
int retval;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
retval = virtual_file_ex(&new_state, path, verify_path, 1);
|
||||
retval = virtual_file_ex(&new_state, path, verify_path);
|
||||
|
||||
*filepath = new_state.cwd;
|
||||
|
||||
@@ -521,7 +536,7 @@ CWD_API FILE *virtual_fopen(const char *path, const char *mode TSRMLS_DC)
|
||||
}
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, path, NULL, 1);
|
||||
virtual_file_ex(&new_state, path, NULL);
|
||||
|
||||
f = fopen(new_state.cwd, mode);
|
||||
|
||||
@@ -536,7 +551,7 @@ CWD_API int virtual_access(const char *pathname, int mode TSRMLS_DC)
|
||||
int ret;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, pathname, NULL, 1);
|
||||
virtual_file_ex(&new_state, pathname, NULL);
|
||||
|
||||
ret = access(new_state.cwd, mode);
|
||||
|
||||
@@ -554,7 +569,7 @@ CWD_API int virtual_utime(const char *filename, struct utimbuf *buf TSRMLS_DC)
|
||||
int ret;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, filename, NULL, 0);
|
||||
virtual_file_ex(&new_state, filename, NULL);
|
||||
|
||||
ret = utime(new_state.cwd, buf);
|
||||
|
||||
@@ -569,7 +584,7 @@ CWD_API int virtual_chmod(const char *filename, mode_t mode TSRMLS_DC)
|
||||
int ret;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, filename, NULL, 1);
|
||||
virtual_file_ex(&new_state, filename, NULL);
|
||||
|
||||
ret = chmod(new_state.cwd, mode);
|
||||
|
||||
@@ -584,7 +599,7 @@ CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group TSRMLS_
|
||||
int ret;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, filename, NULL, 0);
|
||||
virtual_file_ex(&new_state, filename, NULL);
|
||||
|
||||
ret = chown(new_state.cwd, owner, group);
|
||||
|
||||
@@ -599,7 +614,7 @@ CWD_API int virtual_open(const char *path TSRMLS_DC, int flags, ...)
|
||||
int f;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, path, NULL, 1);
|
||||
virtual_file_ex(&new_state, path, NULL);
|
||||
|
||||
if (flags & O_CREAT) {
|
||||
mode_t mode;
|
||||
@@ -623,7 +638,7 @@ CWD_API int virtual_creat(const char *path, mode_t mode TSRMLS_DC)
|
||||
int f;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, path, NULL, 1);
|
||||
virtual_file_ex(&new_state, path, NULL);
|
||||
|
||||
f = creat(new_state.cwd, mode);
|
||||
|
||||
@@ -638,11 +653,11 @@ CWD_API int virtual_rename(char *oldname, char *newname TSRMLS_DC)
|
||||
int retval;
|
||||
|
||||
CWD_STATE_COPY(&old_state, &CWDG(cwd));
|
||||
virtual_file_ex(&old_state, oldname, NULL, 0);
|
||||
virtual_file_ex(&old_state, oldname, NULL);
|
||||
oldname = old_state.cwd;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, newname, NULL, 0);
|
||||
virtual_file_ex(&new_state, newname, NULL);
|
||||
newname = new_state.cwd;
|
||||
|
||||
retval = rename(oldname, newname);
|
||||
@@ -660,7 +675,7 @@ CWD_API int virtual_stat(const char *path, struct stat *buf TSRMLS_DC)
|
||||
int retval;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, path, NULL, 1);
|
||||
virtual_file_ex(&new_state, path, NULL);
|
||||
|
||||
retval = stat(new_state.cwd, buf);
|
||||
|
||||
@@ -674,7 +689,7 @@ CWD_API int virtual_stat(const char *path, struct stat_libc *buf TSRMLS_DC)
|
||||
int retval;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, path, NULL, 1);
|
||||
virtual_file_ex(&new_state, path, NULL);
|
||||
|
||||
retval = stat(new_state.cwd, (struct stat*)buf);
|
||||
|
||||
@@ -690,7 +705,7 @@ CWD_API int virtual_lstat(const char *path, struct stat *buf TSRMLS_DC)
|
||||
int retval;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, path, NULL, 0);
|
||||
virtual_file_ex(&new_state, path, NULL);
|
||||
|
||||
retval = lstat(new_state.cwd, buf);
|
||||
|
||||
@@ -705,7 +720,7 @@ CWD_API int virtual_unlink(const char *path TSRMLS_DC)
|
||||
int retval;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, path, NULL, 0);
|
||||
virtual_file_ex(&new_state, path, NULL);
|
||||
|
||||
retval = unlink(new_state.cwd);
|
||||
|
||||
@@ -719,7 +734,7 @@ CWD_API int virtual_mkdir(const char *pathname, mode_t mode TSRMLS_DC)
|
||||
int retval;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, pathname, NULL, 1);
|
||||
virtual_file_ex(&new_state, pathname, NULL);
|
||||
|
||||
#ifdef TSRM_WIN32
|
||||
retval = mkdir(new_state.cwd);
|
||||
@@ -736,7 +751,7 @@ CWD_API int virtual_rmdir(const char *pathname TSRMLS_DC)
|
||||
int retval;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, pathname, NULL, 0);
|
||||
virtual_file_ex(&new_state, pathname, NULL);
|
||||
|
||||
retval = rmdir(new_state.cwd);
|
||||
|
||||
@@ -754,7 +769,7 @@ CWD_API DIR *virtual_opendir(const char *pathname TSRMLS_DC)
|
||||
DIR *retval;
|
||||
|
||||
CWD_STATE_COPY(&new_state, &CWDG(cwd));
|
||||
virtual_file_ex(&new_state, pathname, NULL, 1);
|
||||
virtual_file_ex(&new_state, pathname, NULL);
|
||||
|
||||
retval = opendir(new_state.cwd);
|
||||
|
||||
@@ -764,9 +779,33 @@ CWD_API DIR *virtual_opendir(const char *pathname TSRMLS_DC)
|
||||
|
||||
#ifdef TSRM_WIN32
|
||||
|
||||
/* On Windows the trick of prepending "cd cwd; " doesn't work so we need to perform
|
||||
a real chdir() and mutex it
|
||||
*/
|
||||
CWD_API FILE *virtual_popen(const char *command, const char *type TSRMLS_DC)
|
||||
{
|
||||
return popen_ex(command, type, CWDG(cwd).cwd, NULL);
|
||||
char prev_cwd[MAXPATHLEN];
|
||||
char *getcwd_result;
|
||||
FILE *retval;
|
||||
|
||||
getcwd_result = getcwd(prev_cwd, MAXPATHLEN);
|
||||
if (!getcwd_result) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef ZTS
|
||||
tsrm_mutex_lock(cwd_mutex);
|
||||
#endif
|
||||
|
||||
chdir(CWDG(cwd).cwd);
|
||||
retval = popen(command, type);
|
||||
chdir(prev_cwd);
|
||||
|
||||
#ifdef ZTS
|
||||
tsrm_mutex_unlock(cwd_mutex);
|
||||
#endif
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#elif defined(NETWARE)
|
||||
|
||||
@@ -52,11 +52,7 @@ typedef unsigned short mode_t;
|
||||
#define IS_SLASH(c) ((c) == '/' || (c) == '\\')
|
||||
#define IS_SLASH_P(c) (*(c) == '/' || \
|
||||
(*(c) == '\\' && !IsDBCSLeadByte(*(c-1))))
|
||||
|
||||
/* COPY_WHEN_ABSOLUTE also takes path as argument because netware needs it
|
||||
* to account for volume name that is unique to NetWare absolute paths
|
||||
*/
|
||||
#define COPY_WHEN_ABSOLUTE(path) 2
|
||||
#define COPY_WHEN_ABSOLUTE 2
|
||||
#define IS_ABSOLUTE_PATH(path, len) \
|
||||
(len >= 2 && isalpha(path[0]) && path[1] == ':')
|
||||
#define IS_UNC_PATH(path, len) \
|
||||
@@ -95,7 +91,7 @@ typedef unsigned short mode_t;
|
||||
|
||||
|
||||
#ifndef COPY_WHEN_ABSOLUTE
|
||||
#define COPY_WHEN_ABSOLUTE(path) 0
|
||||
#define COPY_WHEN_ABSOLUTE 0
|
||||
#endif
|
||||
|
||||
#ifndef IS_ABSOLUTE_PATH
|
||||
@@ -163,7 +159,7 @@ CWD_API int virtual_chmod(const char *filename, mode_t mode TSRMLS_DC);
|
||||
CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group TSRMLS_DC);
|
||||
#endif
|
||||
|
||||
CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath);
|
||||
CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path);
|
||||
|
||||
typedef struct _virtual_cwd_globals {
|
||||
cwd_state cwd;
|
||||
@@ -195,7 +191,7 @@ typedef struct _virtual_cwd_globals {
|
||||
#define VCWD_RENAME(oldname, newname) virtual_rename(oldname, newname TSRMLS_CC)
|
||||
#define VCWD_STAT(path, buff) virtual_stat(path, buff TSRMLS_CC)
|
||||
#if !defined(TSRM_WIN32) && !defined(NETWARE)
|
||||
#define VCWD_LSTAT(path, buff) virtual_lstat(path, buff TSRMLS_CC)
|
||||
#define VCWD_LSTAT(path, buff) virtual_stat(path, buff TSRMLS_CC)
|
||||
#else
|
||||
#define VCWD_LSTAT(path, buff) virtual_lstat(path, buff TSRMLS_CC)
|
||||
#endif
|
||||
@@ -233,7 +229,7 @@ typedef struct _virtual_cwd_globals {
|
||||
#define VCWD_POPEN(command, type) popen(command, type)
|
||||
#define VCWD_ACCESS(pathname, mode) access(pathname, mode)
|
||||
|
||||
#ifdef HAVE_REALPATH
|
||||
#if !defined(TSRM_WIN32) && !defined(NETWARE)
|
||||
#define VCWD_REALPATH(path, real_path) realpath(path, real_path)
|
||||
#else
|
||||
#define VCWD_REALPATH(path, real_path) strcpy(real_path, path)
|
||||
|
||||
+1
-6
@@ -148,11 +148,6 @@ static HANDLE dupHandle(HANDLE fh, BOOL inherit) {
|
||||
}
|
||||
|
||||
TSRM_API FILE *popen(const char *command, const char *type)
|
||||
{
|
||||
return popen_ex(command, type, NULL, NULL);
|
||||
}
|
||||
|
||||
TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, char *env)
|
||||
{
|
||||
FILE *stream = NULL;
|
||||
int fno, str_len = strlen(type), read, mode;
|
||||
@@ -195,7 +190,7 @@ TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd,
|
||||
|
||||
cmd = (char*)malloc(strlen(command)+strlen(TWG(comspec))+sizeof(" /c "));
|
||||
sprintf(cmd, "%s /c %s", TWG(comspec), command);
|
||||
if (!CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, NORMAL_PRIORITY_CLASS, env, cwd, &startup, &process)) {
|
||||
if (!CreateProcess(NULL, cmd, &security, &security, security.bInheritHandle, NORMAL_PRIORITY_CLASS, NULL, NULL, &startup, &process)) {
|
||||
return NULL;
|
||||
}
|
||||
free(cmd);
|
||||
|
||||
@@ -92,7 +92,6 @@ typedef struct {
|
||||
TSRM_API void tsrm_win32_startup(void);
|
||||
TSRM_API void tsrm_win32_shutdown(void);
|
||||
|
||||
TSRM_API FILE *popen_ex(const char *command, const char *type, const char *cwd, char *env);
|
||||
TSRM_API FILE *popen(const char *command, const char *type);
|
||||
TSRM_API int pclose(FILE *stream);
|
||||
|
||||
|
||||
+111
-191
@@ -9,7 +9,7 @@ dnl of the most recently added extension. $(srcdir) and $(builddir)
|
||||
dnl are substituted with the proper paths. Can be used to supply
|
||||
dnl custom rules and/or additional targets.
|
||||
dnl
|
||||
AC_DEFUN([PHP_ADD_MAKEFILE_FRAGMENT],[
|
||||
AC_DEFUN(PHP_ADD_MAKEFILE_FRAGMENT,[
|
||||
ifelse($1,,src=$ext_srcdir/Makefile.frag,src=$1)
|
||||
ifelse($2,,ac_srcdir=$ext_srcdir,ac_srcdir=$2)
|
||||
ifelse($3,,ac_builddir=$ext_builddir,ac_builddir=$3)
|
||||
@@ -21,13 +21,13 @@ dnl PHP_DEFINE(WHAT[, value])
|
||||
dnl
|
||||
dnl Creates builddir/include/what.h and in there #define WHAT value
|
||||
dnl
|
||||
AC_DEFUN([PHP_DEFINE],[
|
||||
AC_DEFUN(PHP_DEFINE,[
|
||||
[echo "#define ]$1[]ifelse([$2],,[ 1],[ $2])[" > include/php_]translit($1,A-Z,a-z)[.h]
|
||||
])
|
||||
|
||||
dnl PHP_INIT_BUILD_SYSTEM
|
||||
dnl
|
||||
AC_DEFUN([PHP_INIT_BUILD_SYSTEM],[
|
||||
AC_DEFUN(PHP_INIT_BUILD_SYSTEM,[
|
||||
mkdir include >/dev/null 2>&1
|
||||
> Makefile.objects
|
||||
> Makefile.fragments
|
||||
@@ -40,7 +40,7 @@ dnl PHP_GEN_GLOBAL_MAKEFILE
|
||||
dnl
|
||||
dnl Generates the global makefile.
|
||||
dnl
|
||||
AC_DEFUN([PHP_GEN_GLOBAL_MAKEFILE],[
|
||||
AC_DEFUN(PHP_GEN_GLOBAL_MAKEFILE,[
|
||||
cat >Makefile <<EOF
|
||||
srcdir = $abs_srcdir
|
||||
builddir = $abs_builddir
|
||||
@@ -66,13 +66,13 @@ dnl Note: If source-path begins with a "/", the "/" is removed and
|
||||
dnl the path is interpreted relative to the top build-directory.
|
||||
dnl
|
||||
dnl which array to append to?
|
||||
AC_DEFUN([PHP_ADD_SOURCES],[
|
||||
AC_DEFUN(PHP_ADD_SOURCES,[
|
||||
PHP_ADD_SOURCES_X($1, $2, $3, ifelse($4,cli,PHP_CLI_OBJS,ifelse($4,sapi,PHP_SAPI_OBJS,PHP_GLOBAL_OBJS)))
|
||||
])
|
||||
dnl
|
||||
dnl _PHP_ASSIGN_BUILD_VARS(type)
|
||||
dnl PHP_ASSIGN_BUILD_VARS(type)
|
||||
dnl internal, don't use
|
||||
AC_DEFUN([_PHP_ASSIGN_BUILD_VARS],[
|
||||
AC_DEFUN(PHP_ASSIGN_BUILD_VARS,[
|
||||
ifelse($1,shared,[
|
||||
b_c_pre=$shared_c_pre
|
||||
b_cxx_pre=$shared_cxx_pre
|
||||
@@ -98,7 +98,7 @@ dnl name of the array target-var directly, as well as whether
|
||||
dnl shared objects will be built from the sources. Should not be
|
||||
dnl used directly.
|
||||
dnl
|
||||
AC_DEFUN([PHP_ADD_SOURCES_X],[
|
||||
AC_DEFUN(PHP_ADD_SOURCES_X,[
|
||||
dnl relative to source- or build-directory?
|
||||
dnl ac_srcdir/ac_bdir include trailing slash
|
||||
case $1 in
|
||||
@@ -108,7 +108,7 @@ dnl ac_srcdir/ac_bdir include trailing slash
|
||||
esac
|
||||
|
||||
dnl how to build .. shared or static?
|
||||
ifelse($5,yes,_PHP_ASSIGN_BUILD_VARS(shared),_PHP_ASSIGN_BUILD_VARS(php))
|
||||
ifelse($5,yes,PHP_ASSIGN_BUILD_VARS(shared),PHP_ASSIGN_BUILD_VARS(php))
|
||||
|
||||
dnl iterate over the sources
|
||||
old_IFS=[$]IFS
|
||||
@@ -140,14 +140,14 @@ EOF
|
||||
dnl
|
||||
dnl Disable building CLI
|
||||
dnl
|
||||
AC_DEFUN([PHP_DISABLE_CLI],[
|
||||
AC_DEFUN(PHP_DISABLE_CLI,[
|
||||
disable_cli=1
|
||||
])
|
||||
|
||||
dnl
|
||||
dnl Separator into the configure --help display.
|
||||
dnl
|
||||
AC_DEFUN([PHP_HELP_SEPARATOR],[
|
||||
AC_DEFUN(PHP_HELP_SEPARATOR,[
|
||||
AC_ARG_ENABLE([],[
|
||||
$1
|
||||
],[])
|
||||
@@ -163,7 +163,7 @@ dnl PHP-related symbols.
|
||||
dnl
|
||||
dnl If successful, adds -rdynamic to PHP_LDFLAGS.
|
||||
dnl
|
||||
AC_DEFUN([PHP_TARGET_RDYNAMIC],[
|
||||
AC_DEFUN(PHP_TARGET_RDYNAMIC,[
|
||||
if test -n "$GCC"; then
|
||||
dnl we should use a PHP-specific macro here
|
||||
TSRM_CHECK_GCC_ARG(-rdynamic, gcc_rdynamic=yes)
|
||||
@@ -173,7 +173,7 @@ AC_DEFUN([PHP_TARGET_RDYNAMIC],[
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_REMOVE_USR_LIB],[
|
||||
AC_DEFUN(PHP_REMOVE_USR_LIB,[
|
||||
unset ac_new_flags
|
||||
for i in [$]$1; do
|
||||
case [$]i in
|
||||
@@ -184,7 +184,7 @@ AC_DEFUN([PHP_REMOVE_USR_LIB],[
|
||||
$1=[$]ac_new_flags
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_SETUP_OPENSSL],[
|
||||
AC_DEFUN(PHP_SETUP_OPENSSL,[
|
||||
if test "$PHP_OPENSSL" = "yes"; then
|
||||
PHP_OPENSSL="/usr/local/ssl /usr/local /usr /usr/local/openssl"
|
||||
fi
|
||||
@@ -250,7 +250,7 @@ dnl Use this macro, if you need to add libraries and or library search
|
||||
dnl paths to the PHP build system which are only given in compiler
|
||||
dnl notation.
|
||||
dnl
|
||||
AC_DEFUN([PHP_EVAL_LIBLINE],[
|
||||
AC_DEFUN(PHP_EVAL_LIBLINE,[
|
||||
for ac_i in $1; do
|
||||
case $ac_i in
|
||||
-l*)
|
||||
@@ -270,7 +270,7 @@ dnl
|
||||
dnl Use this macro, if you need to add header search paths to the PHP
|
||||
dnl build system which are only given in compiler notation.
|
||||
dnl
|
||||
AC_DEFUN([PHP_EVAL_INCLINE],[
|
||||
AC_DEFUN(PHP_EVAL_INCLINE,[
|
||||
for ac_i in $1; do
|
||||
case $ac_i in
|
||||
-I*)
|
||||
@@ -281,7 +281,7 @@ AC_DEFUN([PHP_EVAL_INCLINE],[
|
||||
done
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_READDIR_R_TYPE],[
|
||||
AC_DEFUN(PHP_READDIR_R_TYPE,[
|
||||
dnl HAVE_READDIR_R is also defined by libmysql
|
||||
AC_CHECK_FUNC(readdir_r,ac_cv_func_readdir_r=yes,ac_cv_func_readdir=no)
|
||||
if test "$ac_cv_func_readdir_r" = "yes"; then
|
||||
@@ -333,7 +333,7 @@ int readdir_r(DIR *, struct dirent *);
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_SHLIB_SUFFIX_NAME],[
|
||||
AC_DEFUN(PHP_SHLIB_SUFFIX_NAME,[
|
||||
PHP_SUBST(SHLIB_SUFFIX_NAME)
|
||||
SHLIB_SUFFIX_NAME=so
|
||||
case $host_alias in
|
||||
@@ -346,7 +346,7 @@ AC_DEFUN([PHP_SHLIB_SUFFIX_NAME],[
|
||||
esac
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_DEBUG_MACRO],[
|
||||
AC_DEFUN(PHP_DEBUG_MACRO,[
|
||||
DEBUG_LOG=$1
|
||||
cat >$1 <<X
|
||||
CONFIGURE: $CONFIGURE_COMMAND
|
||||
@@ -374,7 +374,7 @@ X
|
||||
rm -fr conftest*
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_DOES_PWRITE_WORK],[
|
||||
AC_DEFUN(PHP_DOES_PWRITE_WORK,[
|
||||
AC_TRY_RUN([
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -401,7 +401,7 @@ $1
|
||||
])
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_DOES_PREAD_WORK],[
|
||||
AC_DEFUN(PHP_DOES_PREAD_WORK,[
|
||||
echo test > conftest_in
|
||||
AC_TRY_RUN([
|
||||
#include <sys/types.h>
|
||||
@@ -429,7 +429,7 @@ $1
|
||||
rm -f conftest_in
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_PWRITE_TEST],[
|
||||
AC_DEFUN(PHP_PWRITE_TEST,[
|
||||
AC_CACHE_CHECK(whether pwrite works,ac_cv_pwrite,[
|
||||
PHP_DOES_PWRITE_WORK
|
||||
if test "$ac_cv_pwrite" = "no"; then
|
||||
@@ -448,7 +448,7 @@ AC_DEFUN([PHP_PWRITE_TEST],[
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_PREAD_TEST],[
|
||||
AC_DEFUN(PHP_PREAD_TEST,[
|
||||
AC_CACHE_CHECK(whether pread works,ac_cv_pread,[
|
||||
PHP_DOES_PREAD_WORK
|
||||
if test "$ac_cv_pread" = "no"; then
|
||||
@@ -467,7 +467,7 @@ AC_DEFUN([PHP_PREAD_TEST],[
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_MISSING_TIME_R_DECL],[
|
||||
AC_DEFUN(PHP_MISSING_TIME_R_DECL,[
|
||||
AC_MSG_CHECKING([for missing declarations of reentrant functions])
|
||||
AC_TRY_COMPILE([#include <time.h>],[struct tm *(*func)() = localtime_r],[
|
||||
:
|
||||
@@ -501,13 +501,13 @@ dnl
|
||||
dnl PHP_LIBGCC_LIBPATH(gcc)
|
||||
dnl Stores the location of libgcc in libgcc_libpath
|
||||
dnl
|
||||
AC_DEFUN([PHP_LIBGCC_LIBPATH],[
|
||||
AC_DEFUN(PHP_LIBGCC_LIBPATH,[
|
||||
changequote({,})
|
||||
libgcc_libpath=`$1 --print-libgcc-file-name|sed 's%/*[^/][^/]*$%%'`
|
||||
changequote([,])
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_ARG_ANALYZE_EX],[
|
||||
AC_DEFUN(PHP_ARG_ANALYZE_EX,[
|
||||
ext_output="yes, shared"
|
||||
ext_shared=yes
|
||||
case [$]$1 in
|
||||
@@ -530,7 +530,7 @@ esac
|
||||
PHP_ALWAYS_SHARED([$1])
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_ARG_ANALYZE],[
|
||||
AC_DEFUN(PHP_ARG_ANALYZE,[
|
||||
ifelse([$3],yes,[PHP_ARG_ANALYZE_EX([$1])])
|
||||
ifelse([$2],,,[AC_MSG_RESULT([$ext_output])])
|
||||
])
|
||||
@@ -543,11 +543,11 @@ dnl and will overwrite any previous variable of that name.
|
||||
dnl If extension-or-not is yes (default), then do the ENABLE_ALL check and run
|
||||
dnl the PHP_ARG_ANALYZE_EX.
|
||||
dnl
|
||||
AC_DEFUN([PHP_ARG_WITH],[
|
||||
AC_DEFUN(PHP_ARG_WITH,[
|
||||
PHP_REAL_ARG_WITH([$1],[$2],[$3],[$4],PHP_[]translit($1,a-z0-9-,A-Z0-9_),[ifelse($5,,yes,$5)])
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_REAL_ARG_WITH],[
|
||||
AC_DEFUN(PHP_REAL_ARG_WITH,[
|
||||
ifelse([$2],,,[AC_MSG_CHECKING([$2])])
|
||||
AC_ARG_WITH($1,[$3],$5=[$]withval,
|
||||
[
|
||||
@@ -568,11 +568,11 @@ dnl and will overwrite any previous variable of that name.
|
||||
dnl If extension-or-not is yes (default), then do the ENABLE_ALL check and run
|
||||
dnl the PHP_ARG_ANALYZE_EX.
|
||||
dnl
|
||||
AC_DEFUN([PHP_ARG_ENABLE],[
|
||||
AC_DEFUN(PHP_ARG_ENABLE,[
|
||||
PHP_REAL_ARG_ENABLE([$1],[$2],[$3],[$4],PHP_[]translit($1,a-z-,A-Z_),[ifelse($5,,yes,$5)])
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_REAL_ARG_ENABLE],[
|
||||
AC_DEFUN(PHP_REAL_ARG_ENABLE,[
|
||||
ifelse([$2],,,[AC_MSG_CHECKING([$2])])
|
||||
AC_ARG_ENABLE($1,[$3],$5=[$]enableval,
|
||||
[
|
||||
@@ -585,11 +585,11 @@ AC_ARG_ENABLE($1,[$3],$5=[$]enableval,
|
||||
PHP_ARG_ANALYZE($5,[$2],$6)
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_MODULE_PTR],[
|
||||
AC_DEFUN(PHP_MODULE_PTR,[
|
||||
EXTRA_MODULE_PTRS="$EXTRA_MODULE_PTRS $1,"
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_CONFIG_NICE],[
|
||||
AC_DEFUN(PHP_CONFIG_NICE,[
|
||||
rm -f $1
|
||||
cat >$1<<EOF
|
||||
#! /bin/sh
|
||||
@@ -612,7 +612,7 @@ EOF
|
||||
chmod +x $1
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_TIME_R_TYPE],[
|
||||
AC_DEFUN(PHP_TIME_R_TYPE,[
|
||||
AC_CACHE_CHECK(for type of reentrant time-related functions, ac_cv_time_r_type,[
|
||||
AC_TRY_RUN([
|
||||
#include <time.h>
|
||||
@@ -658,16 +658,16 @@ main() {
|
||||
esac
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_SUBST],[
|
||||
AC_DEFUN(PHP_SUBST,[
|
||||
PHP_VAR_SUBST="$PHP_VAR_SUBST $1"
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_SUBST_OLD],[
|
||||
AC_DEFUN(PHP_SUBST_OLD,[
|
||||
PHP_SUBST($1)
|
||||
AC_SUBST($1)
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_MKDIR_P_CHECK],[
|
||||
AC_DEFUN(PHP_MKDIR_P_CHECK,[
|
||||
AC_CACHE_CHECK(for working mkdir -p, ac_cv_mkdir_p,[
|
||||
test -d conftestdir && rm -rf conftestdir
|
||||
mkdir -p conftestdir/somedir >/dev/null 2>&1
|
||||
@@ -682,7 +682,7 @@ dnl `mkdir -p' must be quiet about creating existing directories
|
||||
])
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_TM_GMTOFF],[
|
||||
AC_DEFUN(PHP_TM_GMTOFF,[
|
||||
AC_CACHE_CHECK([for tm_gmtoff in struct tm], ac_cv_struct_tm_gmtoff,
|
||||
[AC_TRY_COMPILE([#include <sys/types.h>
|
||||
#include <$ac_cv_struct_tm>], [struct tm tm; tm.tm_gmtoff;],
|
||||
@@ -695,19 +695,19 @@ fi
|
||||
|
||||
dnl PHP_CONFIGURE_PART(MESSAGE)
|
||||
dnl Idea borrowed from mm
|
||||
AC_DEFUN([PHP_CONFIGURE_PART],[
|
||||
AC_DEFUN(PHP_CONFIGURE_PART,[
|
||||
AC_MSG_RESULT()
|
||||
AC_MSG_RESULT([${T_MD}$1${T_ME}])
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_PROG_SENDMAIL],[
|
||||
AC_DEFUN(PHP_PROG_SENDMAIL,[
|
||||
AC_PATH_PROG(PROG_SENDMAIL, sendmail,[], $PATH:/usr/bin:/usr/sbin:/usr/etc:/etc:/usr/ucblib:/usr/lib)
|
||||
if test -n "$PROG_SENDMAIL"; then
|
||||
AC_DEFINE(HAVE_SENDMAIL,1,[whether you have sendmail])
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_RUNPATH_SWITCH],[
|
||||
AC_DEFUN(PHP_RUNPATH_SWITCH,[
|
||||
dnl check for -R, etc. switch
|
||||
AC_MSG_CHECKING([if compiler supports -R])
|
||||
AC_CACHE_VAL(php_cv_cc_dashr,[
|
||||
@@ -735,7 +735,7 @@ else
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_STRUCT_FLOCK],[
|
||||
AC_DEFUN(PHP_STRUCT_FLOCK,[
|
||||
AC_CACHE_CHECK(for struct flock,ac_cv_struct_flock,
|
||||
AC_TRY_COMPILE([
|
||||
#include <unistd.h>
|
||||
@@ -753,7 +753,7 @@ if test "$ac_cv_struct_flock" = "yes" ; then
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_SOCKLEN_T],[
|
||||
AC_DEFUN(PHP_SOCKLEN_T,[
|
||||
AC_CACHE_CHECK(for socklen_t,ac_cv_socklen_t,
|
||||
AC_TRY_COMPILE([
|
||||
#include <sys/types.h>
|
||||
@@ -775,7 +775,7 @@ dnl PHP_SET_SYM_FILE(path)
|
||||
dnl
|
||||
dnl set the path of the file which contains the symbol export list
|
||||
dnl
|
||||
AC_DEFUN([PHP_SET_SYM_FILE],
|
||||
AC_DEFUN(PHP_SET_SYM_FILE,
|
||||
[
|
||||
PHP_SYM_FILE=$1
|
||||
])
|
||||
@@ -783,14 +783,14 @@ AC_DEFUN([PHP_SET_SYM_FILE],
|
||||
dnl
|
||||
dnl PHP_BUILD_THREAD_SAFE
|
||||
dnl
|
||||
AC_DEFUN([PHP_BUILD_THREAD_SAFE],[
|
||||
AC_DEFUN(PHP_BUILD_THREAD_SAFE,[
|
||||
enable_experimental_zts=yes
|
||||
if test "$pthreads_working" != "yes"; then
|
||||
AC_MSG_ERROR([ZTS currently requires working POSIX threads. We were unable to verify that your system supports Pthreads.])
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_REQUIRE_CXX],[
|
||||
AC_DEFUN(PHP_REQUIRE_CXX,[
|
||||
if test -z "$php_cxx_done"; then
|
||||
AC_PROG_CXX
|
||||
AC_PROG_CXXCPP
|
||||
@@ -801,7 +801,7 @@ AC_DEFUN([PHP_REQUIRE_CXX],[
|
||||
dnl
|
||||
dnl PHP_BUILD_SHARED
|
||||
dnl
|
||||
AC_DEFUN([PHP_BUILD_SHARED],[
|
||||
AC_DEFUN(PHP_BUILD_SHARED,[
|
||||
PHP_BUILD_PROGRAM
|
||||
OVERALL_TARGET=libphp4.la
|
||||
php_build_target=shared
|
||||
@@ -818,7 +818,7 @@ AC_DEFUN([PHP_BUILD_SHARED],[
|
||||
dnl
|
||||
dnl PHP_BUILD_STATIC
|
||||
dnl
|
||||
AC_DEFUN([PHP_BUILD_STATIC],[
|
||||
AC_DEFUN(PHP_BUILD_STATIC,[
|
||||
PHP_BUILD_PROGRAM
|
||||
OVERALL_TARGET=libphp4.la
|
||||
php_build_target=static
|
||||
@@ -827,7 +827,7 @@ AC_DEFUN([PHP_BUILD_STATIC],[
|
||||
dnl
|
||||
dnl PHP_BUILD_BUNDLE
|
||||
dnl
|
||||
AC_DEFUN([PHP_BUILD_BUNDLE],[
|
||||
AC_DEFUN(PHP_BUILD_BUNDLE,[
|
||||
PHP_BUILD_PROGRAM
|
||||
OVERALL_TARGET=libs/libphp4.bundle
|
||||
php_build_target=static
|
||||
@@ -836,7 +836,7 @@ AC_DEFUN([PHP_BUILD_BUNDLE],[
|
||||
dnl
|
||||
dnl PHP_BUILD_PROGRAM
|
||||
dnl
|
||||
AC_DEFUN([PHP_BUILD_PROGRAM],[
|
||||
AC_DEFUN(PHP_BUILD_PROGRAM,[
|
||||
OVERALL_TARGET=[]ifelse($1,,php,$1)
|
||||
php_c_pre='$(CC)'
|
||||
php_c_meta='$(COMMON_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS)'
|
||||
@@ -858,11 +858,11 @@ AC_DEFUN([PHP_BUILD_PROGRAM],[
|
||||
])
|
||||
|
||||
dnl
|
||||
dnl PHP_RUN_ONCE(namespace, variable, code)
|
||||
dnl AC_PHP_ONCE(namespace, variable, code)
|
||||
dnl
|
||||
dnl execute code, if variable is not set in namespace
|
||||
dnl
|
||||
AC_DEFUN([PHP_RUN_ONCE],[
|
||||
AC_DEFUN(AC_PHP_ONCE,[
|
||||
changequote({,})
|
||||
unique=`echo $2|sed 's/[^a-zA-Z0-9]/_/g'`
|
||||
changequote([,])
|
||||
@@ -878,7 +878,7 @@ dnl PHP_EXPAND_PATH(path, variable)
|
||||
dnl
|
||||
dnl expands path to an absolute path and assigns it to variable
|
||||
dnl
|
||||
AC_DEFUN([PHP_EXPAND_PATH],[
|
||||
AC_DEFUN(PHP_EXPAND_PATH,[
|
||||
if test -z "$1" || echo "$1" | grep '^/' >/dev/null ; then
|
||||
$2=$1
|
||||
else
|
||||
@@ -891,8 +891,8 @@ AC_DEFUN([PHP_EXPAND_PATH],[
|
||||
])
|
||||
dnl
|
||||
dnl internal, don't use
|
||||
AC_DEFUN([_PHP_ADD_LIBPATH_GLOBAL],[
|
||||
PHP_RUN_ONCE(LIBPATH, $1, [
|
||||
AC_DEFUN(PHP_ADD_LIBPATH_GLOBAL,[
|
||||
AC_PHP_ONCE(LIBPATH, $1, [
|
||||
test -n "$ld_runpath_switch" && LDFLAGS="$LDFLAGS $ld_runpath_switch$1"
|
||||
LDFLAGS="$LDFLAGS -L$1"
|
||||
PHP_RPATHS="$PHP_RPATHS $1"
|
||||
@@ -905,16 +905,16 @@ dnl PHP_ADD_LIBPATH(path[, shared-libadd])
|
||||
dnl
|
||||
dnl add a library to linkpath/runpath
|
||||
dnl
|
||||
AC_DEFUN([PHP_ADD_LIBPATH],[
|
||||
AC_DEFUN(PHP_ADD_LIBPATH,[
|
||||
if test "$1" != "/usr/lib"; then
|
||||
PHP_EXPAND_PATH($1, ai_p)
|
||||
ifelse([$2],,[
|
||||
_PHP_ADD_LIBPATH_GLOBAL([$ai_p])
|
||||
PHP_ADD_LIBPATH_GLOBAL([$ai_p])
|
||||
],[
|
||||
if test "$ext_shared" = "yes"; then
|
||||
$2="$ld_runpath_switch$ai_p -L$ai_p [$]$2"
|
||||
else
|
||||
_PHP_ADD_LIBPATH_GLOBAL([$ai_p])
|
||||
PHP_ADD_LIBPATH_GLOBAL([$ai_p])
|
||||
fi
|
||||
])
|
||||
fi
|
||||
@@ -925,7 +925,7 @@ dnl PHP_UTILIZE_RPATHS()
|
||||
dnl
|
||||
dnl builds RPATHS/LDFLAGS from PHP_RPATHS
|
||||
dnl
|
||||
AC_DEFUN([PHP_UTILIZE_RPATHS],[
|
||||
AC_DEFUN(PHP_UTILIZE_RPATHS,[
|
||||
OLD_RPATHS=$PHP_RPATHS
|
||||
unset PHP_RPATHS
|
||||
|
||||
@@ -950,10 +950,10 @@ dnl
|
||||
dnl add an include path.
|
||||
dnl if before is 1, add in the beginning of INCLUDES.
|
||||
dnl
|
||||
AC_DEFUN([PHP_ADD_INCLUDE],[
|
||||
AC_DEFUN(PHP_ADD_INCLUDE,[
|
||||
if test "$1" != "/usr/include"; then
|
||||
PHP_EXPAND_PATH($1, ai_p)
|
||||
PHP_RUN_ONCE(INCLUDEPATH, $ai_p, [
|
||||
AC_PHP_ONCE(INCLUDEPATH, $ai_p, [
|
||||
if test "$2"; then
|
||||
INCLUDES="-I$ai_p $INCLUDES"
|
||||
else
|
||||
@@ -964,19 +964,19 @@ AC_DEFUN([PHP_ADD_INCLUDE],[
|
||||
])
|
||||
dnl
|
||||
dnl internal, don't use
|
||||
AC_DEFUN([_PHP_X_ADD_LIBRARY],[dnl
|
||||
AC_DEFUN(PHP_X_ADD_LIBRARY,[dnl
|
||||
ifelse([$2],,$3="-l$1 [$]$3", $3="[$]$3 -l$1") dnl
|
||||
])dnl
|
||||
dnl
|
||||
dnl internal, don't use
|
||||
AC_DEFUN([_PHP_ADD_LIBRARY_SKELETON],[
|
||||
AC_DEFUN(PHP_ADD_LIBRARY_SKELETON,[
|
||||
case $1 in
|
||||
c|c_r|pthread*[)] ;;
|
||||
*[)] ifelse($3,,[
|
||||
_PHP_X_ADD_LIBRARY($1,$2,$5)
|
||||
PHP_X_ADD_LIBRARY($1,$2,$5)
|
||||
],[
|
||||
if test "$ext_shared" = "yes"; then
|
||||
_PHP_X_ADD_LIBRARY($1,$2,$3)
|
||||
PHP_X_ADD_LIBRARY($1,$2,$3)
|
||||
else
|
||||
$4($1,$2)
|
||||
fi
|
||||
@@ -990,8 +990,8 @@ dnl PHP_ADD_LIBRARY(library[, append[, shared-libadd]])
|
||||
dnl
|
||||
dnl add a library to the link line
|
||||
dnl
|
||||
AC_DEFUN([PHP_ADD_LIBRARY],[
|
||||
_PHP_ADD_LIBRARY_SKELETON([$1],[$2],[$3],[PHP_ADD_LIBRARY],[LIBS])
|
||||
AC_DEFUN(PHP_ADD_LIBRARY,[
|
||||
PHP_ADD_LIBRARY_SKELETON([$1],[$2],[$3],[PHP_ADD_LIBRARY],[LIBS])
|
||||
])
|
||||
|
||||
dnl
|
||||
@@ -999,8 +999,8 @@ dnl PHP_ADD_LIBRARY_DEFER(library[, append[, shared-libadd]])
|
||||
dnl
|
||||
dnl add a library to the link line (deferred)
|
||||
dnl
|
||||
AC_DEFUN([PHP_ADD_LIBRARY_DEFER],[
|
||||
_PHP_ADD_LIBRARY_SKELETON([$1],[$2],[$3],[PHP_ADD_LIBRARY_DEFER],[DLIBS])
|
||||
AC_DEFUN(PHP_ADD_LIBRARY_DEFER,[
|
||||
PHP_ADD_LIBRARY_SKELETON([$1],[$2],[$3],[PHP_ADD_LIBRARY_DEFER],[DLIBS])
|
||||
])
|
||||
|
||||
dnl
|
||||
@@ -1010,7 +1010,7 @@ dnl add a library to the link line and path to linkpath/runpath.
|
||||
dnl if shared-libadd is not empty and $ext_shared is yes,
|
||||
dnl shared-libadd will be assigned the library information
|
||||
dnl
|
||||
AC_DEFUN([PHP_ADD_LIBRARY_WITH_PATH],[
|
||||
AC_DEFUN(PHP_ADD_LIBRARY_WITH_PATH,[
|
||||
ifelse($3,,[
|
||||
if test -n "$2"; then
|
||||
PHP_ADD_LIBPATH($2)
|
||||
@@ -1036,7 +1036,7 @@ dnl and path to linkpath/runpath (not deferred)
|
||||
dnl if shared-libadd is not empty and $ext_shared is yes,
|
||||
dnl shared-libadd will be assigned the library information
|
||||
dnl
|
||||
AC_DEFUN([PHP_ADD_LIBRARY_DEFER_WITH_PATH],[
|
||||
AC_DEFUN(PHP_ADD_LIBRARY_DEFER_WITH_PATH,[
|
||||
ifelse($3,,[
|
||||
if test -n "$2"; then
|
||||
PHP_ADD_LIBPATH($2)
|
||||
@@ -1061,8 +1061,8 @@ dnl add a (Darwin / Mac OS X) framework to the link
|
||||
dnl line. if before is 1, the framework is added
|
||||
dnl to the beginning of the line.
|
||||
|
||||
AC_DEFUN([PHP_ADD_FRAMEWORK], [
|
||||
PHP_RUN_ONCE(FRAMEWORKS, $1, [
|
||||
AC_DEFUN(PHP_ADD_FRAMEWORK, [
|
||||
AC_PHP_ONCE(FRAMEWORKS, $1, [
|
||||
if test "$2"; then
|
||||
PHP_FRAMEWORKS="-framework $1 $PHP_FRAMEWORKS"
|
||||
else
|
||||
@@ -1082,9 +1082,9 @@ dnl to be specifically added. if before is 1, the
|
||||
dnl framework path is added to the beginning of the
|
||||
dnl relevant lines.
|
||||
|
||||
AC_DEFUN([PHP_ADD_FRAMEWORKPATH], [
|
||||
AC_DEFUN(PHP_ADD_FRAMEWORKPATH, [
|
||||
PHP_EXPAND_PATH($1, ai_p)
|
||||
PHP_RUN_ONCE(FRAMEWORKPATH, $ai_p, [
|
||||
AC_PHP_ONCE(FRAMEWORKPATH, $ai_p, [
|
||||
if test "$2"; then
|
||||
PHP_FRAMEWORKPATH="-F$ai_p $PHP_FRAMEWORKPATH"
|
||||
else
|
||||
@@ -1098,7 +1098,7 @@ dnl PHP_ADD_FRAMEWORK_WITH_PATH(framework, path)
|
||||
dnl
|
||||
dnl add a (Darwin / Mac OS X) framework path and the
|
||||
dnl framework itself to the link and include lines.
|
||||
AC_DEFUN([PHP_ADD_FRAMEWORK_WITH_PATH], [
|
||||
AC_DEFUN(PHP_ADD_FRAMEWORK_WITH_PATH, [
|
||||
PHP_ADD_FRAMEWORKPATH($2)
|
||||
PHP_ADD_FRAMEWORK($1)
|
||||
])
|
||||
@@ -1106,14 +1106,14 @@ AC_DEFUN([PHP_ADD_FRAMEWORK_WITH_PATH], [
|
||||
dnl
|
||||
dnl Set libtool variable
|
||||
dnl
|
||||
AC_DEFUN([PHP_SET_LIBTOOL_VARIABLE],[
|
||||
AC_DEFUN(PHP_SET_LIBTOOL_VARIABLE,[
|
||||
LIBTOOL='$(SHELL) libtool $1'
|
||||
])
|
||||
|
||||
dnl
|
||||
dnl Check for cc option
|
||||
dnl
|
||||
AC_DEFUN([PHP_CHECK_CC_OPTION],[
|
||||
AC_DEFUN(PHP_CHECK_CC_OPTION,[
|
||||
echo "main(){return 0;}" > conftest.$ac_ext
|
||||
opt=$1
|
||||
changequote({,})
|
||||
@@ -1135,7 +1135,7 @@ AC_DEFUN([PHP_CHECK_CC_OPTION],[
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_REGEX],[
|
||||
AC_DEFUN(PHP_REGEX,[
|
||||
|
||||
if test "$REGEX_TYPE" = "php"; then
|
||||
AC_DEFINE(HSREGEX,1,[ ])
|
||||
@@ -1152,7 +1152,7 @@ AC_MSG_RESULT([$REGEX_TYPE])
|
||||
dnl
|
||||
dnl See if we have broken header files like SunOS has.
|
||||
dnl
|
||||
AC_DEFUN([PHP_MISSING_FCLOSE_DECL],[
|
||||
AC_DEFUN(PHP_MISSING_FCLOSE_DECL,[
|
||||
AC_MSG_CHECKING([for fclose declaration])
|
||||
AC_TRY_COMPILE([#include <stdio.h>],[int (*func)() = fclose],[
|
||||
AC_DEFINE(MISSING_FCLOSE_DECL,0,[ ])
|
||||
@@ -1166,7 +1166,7 @@ AC_DEFUN([PHP_MISSING_FCLOSE_DECL],[
|
||||
dnl
|
||||
dnl Check for broken sprintf(), C99 conformance
|
||||
dnl
|
||||
AC_DEFUN([PHP_AC_BROKEN_SPRINTF],[
|
||||
AC_DEFUN(PHP_AC_BROKEN_SPRINTF,[
|
||||
AC_CACHE_CHECK(whether sprintf is broken, ac_cv_broken_sprintf,[
|
||||
AC_TRY_RUN([main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[
|
||||
ac_cv_broken_sprintf=no
|
||||
@@ -1186,7 +1186,7 @@ AC_DEFUN([PHP_AC_BROKEN_SPRINTF],[
|
||||
dnl
|
||||
dnl Check for broken snprintf(), C99 conformance
|
||||
dnl
|
||||
AC_DEFUN([PHP_AC_BROKEN_SNPRINTF],[
|
||||
AC_DEFUN(PHP_AC_BROKEN_SNPRINTF,[
|
||||
AC_CACHE_CHECK(whether snprintf is broken, ac_cv_broken_snprintf,[
|
||||
AC_TRY_RUN([
|
||||
#define NULL (0L)
|
||||
@@ -1221,7 +1221,7 @@ dnl
|
||||
dnl Basically sets up the link-stage for building module-name
|
||||
dnl from object_var in build-dir.
|
||||
dnl
|
||||
AC_DEFUN([PHP_SHARED_MODULE],[
|
||||
AC_DEFUN(PHP_SHARED_MODULE,[
|
||||
PHP_MODULES="$PHP_MODULES \$(phplibdir)/$1.la"
|
||||
PHP_SUBST($2)
|
||||
cat >>Makefile.objects<<EOF
|
||||
@@ -1241,7 +1241,7 @@ dnl Selects the SAPI name and type (static, shared, programm)
|
||||
dnl and optionally also the source-files for the SAPI-specific
|
||||
dnl objects.
|
||||
dnl
|
||||
AC_DEFUN([PHP_SELECT_SAPI],[
|
||||
AC_DEFUN(PHP_SELECT_SAPI,[
|
||||
PHP_SAPI=$1
|
||||
|
||||
case "$2" in
|
||||
@@ -1255,7 +1255,7 @@ AC_DEFUN([PHP_SELECT_SAPI],[
|
||||
])
|
||||
|
||||
dnl deprecated
|
||||
AC_DEFUN([PHP_EXTENSION],[
|
||||
AC_DEFUN(PHP_EXTENSION,[
|
||||
sources=`awk -f $abs_srcdir/scan_makefile_in.awk < []PHP_EXT_SRCDIR($1)[]/Makefile.in`
|
||||
|
||||
PHP_NEW_EXTENSION($1, $sources, $2, $3)
|
||||
@@ -1265,11 +1265,11 @@ AC_DEFUN([PHP_EXTENSION],[
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_ADD_BUILD_DIR],[
|
||||
AC_DEFUN(PHP_ADD_BUILD_DIR,[
|
||||
BUILD_DIR="$BUILD_DIR $1"
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_GEN_BUILD_DIRS],[
|
||||
AC_DEFUN(PHP_GEN_BUILD_DIRS,[
|
||||
PHP_MKDIR_P_CHECK
|
||||
if test "$ac_cv_mkdir_p" = "yes"; then
|
||||
mkdir -p $BUILD_DIR
|
||||
@@ -1289,7 +1289,7 @@ dnl a dynamically loadable library. Optional parameter "sapi_class" can
|
||||
dnl be set to "cli" to mark extension build only with CLI or CGI sapi's.
|
||||
dnl extra-cflags are passed to the compiler, with @ext_srcdir@ being
|
||||
dnl substituted.
|
||||
AC_DEFUN([PHP_NEW_EXTENSION],[
|
||||
AC_DEFUN(PHP_NEW_EXTENSION,[
|
||||
ext_builddir=[]PHP_EXT_BUILDDIR($1)
|
||||
ext_srcdir=[]PHP_EXT_SRCDIR($1)
|
||||
|
||||
@@ -1332,7 +1332,7 @@ dnl
|
||||
dnl Must be run after all --with-NN options that let the user
|
||||
dnl choose dynamic extensions, and after the gcc test.
|
||||
dnl
|
||||
AC_DEFUN([PHP_SOLARIS_PIC_WEIRDNESS],[
|
||||
AC_DEFUN(PHP_SOLARIS_PIC_WEIRDNESS,[
|
||||
AC_MSG_CHECKING([whether -fPIC is required])
|
||||
if test -n "$EXT_SHARED"; then
|
||||
os=`uname -sr 2>/dev/null`
|
||||
@@ -1356,7 +1356,7 @@ dnl Checks whether $withval is "shared" or starts with "shared,XXX"
|
||||
dnl and sets $shared to "yes" or "no", and removes "shared,?" stuff
|
||||
dnl from $withval.
|
||||
dnl
|
||||
AC_DEFUN([PHP_WITH_SHARED],[
|
||||
AC_DEFUN(PHP_WITH_SHARED,[
|
||||
PHP_ARG_ANALYZE_EX(withval)
|
||||
shared=$ext_shared
|
||||
unset ext_shared ext_output
|
||||
@@ -1370,7 +1370,7 @@ dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
|
||||
|
||||
dnl Written by Paul Eggert <eggert@twinsun.com>.
|
||||
|
||||
AC_DEFUN([PHP_SYS_LFS],
|
||||
AC_DEFUN(PHP_SYS_LFS,
|
||||
[dnl
|
||||
# If available, prefer support for large files unless the user specified
|
||||
# one of the CPPFLAGS, LDFLAGS, or LIBS variables.
|
||||
@@ -1405,7 +1405,7 @@ AC_DEFUN([PHP_SYS_LFS],
|
||||
esac
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_SOCKADDR_SA_LEN],[
|
||||
AC_DEFUN(PHP_SOCKADDR_SA_LEN,[
|
||||
AC_CACHE_CHECK([for field sa_len in struct sockaddr],ac_cv_sockaddr_sa_len,[
|
||||
AC_TRY_COMPILE([#include <sys/types.h>
|
||||
#include <sys/socket.h>],
|
||||
@@ -1420,11 +1420,11 @@ AC_DEFUN([PHP_SOCKADDR_SA_LEN],[
|
||||
dnl ## PHP_OUTPUT(file)
|
||||
dnl ## adds "file" to the list of files generated by AC_OUTPUT
|
||||
dnl ## This macro can be used several times.
|
||||
AC_DEFUN([PHP_OUTPUT],[
|
||||
AC_DEFUN(PHP_OUTPUT,[
|
||||
PHP_OUTPUT_FILES="$PHP_OUTPUT_FILES $1"
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_DECLARED_TIMEZONE],[
|
||||
AC_DEFUN(PHP_DECLARED_TIMEZONE,[
|
||||
AC_CACHE_CHECK(for declared timezone, ac_cv_declared_timezone,[
|
||||
AC_TRY_COMPILE([
|
||||
#include <sys/types.h>
|
||||
@@ -1444,7 +1444,7 @@ AC_DEFUN([PHP_DECLARED_TIMEZONE],[
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_EBCDIC],[
|
||||
AC_DEFUN(PHP_EBCDIC,[
|
||||
AC_CACHE_CHECK([whether system uses EBCDIC],ac_cv_ebcdic,[
|
||||
AC_TRY_RUN( [
|
||||
int main(void) {
|
||||
@@ -1462,7 +1462,7 @@ int main(void) {
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_FOPENCOOKIE],[
|
||||
AC_DEFUN(PHP_FOPENCOOKIE,[
|
||||
AC_CHECK_FUNC(fopencookie, [ have_glibc_fopencookie=yes ])
|
||||
|
||||
if test "$have_glibc_fopencookie" = "yes" ; then
|
||||
@@ -1487,16 +1487,16 @@ AC_DEFUN([PHP_FOPENCOOKIE],[
|
||||
#include <stdio.h>
|
||||
|
||||
struct cookiedata {
|
||||
__off64_t pos;
|
||||
fpos_t pos;
|
||||
};
|
||||
|
||||
__ssize_t reader(void *cookie, char *buffer, size_t size)
|
||||
size_t reader(void *cookie, char *buffer, size_t size)
|
||||
{ return size; }
|
||||
__ssize_t writer(void *cookie, const char *buffer, size_t size)
|
||||
size_t writer(void *cookie, const char *buffer, size_t size)
|
||||
{ return size; }
|
||||
int closer(void *cookie)
|
||||
{ return 0; }
|
||||
int seeker(void *cookie, __off64_t *position, int whence)
|
||||
int seeker(void *cookie, fpos_t *position, int whence)
|
||||
{ ((struct cookiedata*)cookie)->pos = *position; return 0; }
|
||||
|
||||
cookie_io_functions_t funcs = {reader, writer, seeker, closer};
|
||||
@@ -1505,13 +1505,13 @@ main() {
|
||||
struct cookiedata g = { 0 };
|
||||
FILE *fp = fopencookie(&g, "r", funcs);
|
||||
|
||||
if (fp && fseek(fp, 8192, SEEK_SET) == 0 && g.pos == 8192)
|
||||
if (fp && fseek(fp, 69, SEEK_SET) == 0 && g.pos == 69)
|
||||
exit(0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
],
|
||||
[ cookie_io_functions_use_off64_t=yes ],
|
||||
[ cookie_io_functions_use_fpos_t=yes ],
|
||||
[ ] )
|
||||
|
||||
else
|
||||
@@ -1532,8 +1532,8 @@ main() {
|
||||
if test "$have_fopen_cookie" = "yes" ; then
|
||||
AC_DEFINE(HAVE_FOPENCOOKIE, 1, [ ])
|
||||
AC_DEFINE_UNQUOTED(COOKIE_IO_FUNCTIONS_T, $cookie_io_functions_t, [ ])
|
||||
if test "$cookie_io_functions_use_off64_t" = "yes" ; then
|
||||
AC_DEFINE(COOKIE_SEEKER_USES_OFF64_T, 1, [ ])
|
||||
if test "$cookie_io_functions_use_fpos_t" = "yes" ; then
|
||||
AC_DEFINE(COOKIE_SEEKER_USES_FPOS_T, 1, [ ])
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -1546,7 +1546,7 @@ dnl PHP_CHECK_LIBRARY(library, function [, action-found [, action-not-found [, e
|
||||
dnl
|
||||
dnl Wrapper for AC_CHECK_LIB
|
||||
dnl
|
||||
AC_DEFUN([PHP_CHECK_LIBRARY], [
|
||||
AC_DEFUN(PHP_CHECK_LIBRARY, [
|
||||
save_old_LDFLAGS=$LDFLAGS
|
||||
LDFLAGS="$5 $LDFLAGS"
|
||||
AC_CHECK_LIB([$1],[$2],[
|
||||
@@ -1563,7 +1563,7 @@ dnl PHP_CHECK_FRAMEWORK(framework, function [, action-found [, action-not-found
|
||||
dnl
|
||||
dnl El cheapo wrapper for AC_CHECK_LIB
|
||||
dnl
|
||||
AC_DEFUN([PHP_CHECK_FRAMEWORK], [
|
||||
AC_DEFUN(PHP_CHECK_FRAMEWORK, [
|
||||
save_old_LDFLAGS=$LDFLAGS
|
||||
LDFLAGS="-framework $1 $LDFLAGS"
|
||||
dnl supplying "c" to AC_CHECK_LIB is technically cheating, but
|
||||
@@ -1583,7 +1583,7 @@ dnl PHP_SETUP_ICONV(shared-add [, action-found [, action-not-found]])
|
||||
dnl
|
||||
dnl Common setup macro for iconv
|
||||
dnl
|
||||
AC_DEFUN([PHP_SETUP_ICONV], [
|
||||
AC_DEFUN(PHP_SETUP_ICONV, [
|
||||
found_iconv=no
|
||||
unset ICONV_DIR
|
||||
|
||||
@@ -1654,7 +1654,7 @@ ifelse([$3],[],,[else $3])
|
||||
fi
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_DEF_HAVE],[AC_DEFINE([HAVE_]translit($1,a-z_-,A-Z__), 1, [ ])])
|
||||
AC_DEFUN(PHP_DEF_HAVE,[AC_DEFINE([HAVE_]translit($1,a-z_-,A-Z__), 1, [ ])])
|
||||
|
||||
dnl
|
||||
dnl PHP_CHECK_FUNC_LIB(func, libs)
|
||||
@@ -1671,7 +1671,7 @@ ifdef([builtin],[builtin(define, phpshift, [builtin(shift, $@)])],[
|
||||
define([phpshift],[ifelse(index([$@],[,]),-1,,[substr([$@],incr(index([$@],[,])))])])
|
||||
])
|
||||
|
||||
AC_DEFUN([PHP_CHECK_FUNC_LIB],[
|
||||
AC_DEFUN(PHP_CHECK_FUNC_LIB,[
|
||||
ifelse($2,,:,[
|
||||
unset ac_cv_lib_$2[]_$1
|
||||
unset ac_cv_lib_$2[]___$1
|
||||
@@ -1680,13 +1680,6 @@ AC_DEFUN([PHP_CHECK_FUNC_LIB],[
|
||||
AC_CHECK_LIB($2, __$1, [found=yes], [found=no])
|
||||
])
|
||||
|
||||
if test "$found" = "yes"; then
|
||||
ac_libs=$LIBS
|
||||
LIBS="$LIBS -l$2"
|
||||
AC_TRY_RUN([main() { return (0); }],[found=yes],[found=no],[found=no])
|
||||
LIBS=$ac_libs
|
||||
fi
|
||||
|
||||
if test "$found" = "yes"; then
|
||||
PHP_ADD_LIBRARY($2)
|
||||
PHP_DEF_HAVE($1)
|
||||
@@ -1704,7 +1697,7 @@ dnl This macro checks whether 'func' or '__func' exists
|
||||
dnl in the default libraries and as a fall back in the specified library.
|
||||
dnl Defines HAVE_func and HAVE_library if found and adds the library to LIBS.
|
||||
dnl
|
||||
AC_DEFUN([PHP_CHECK_FUNC],[
|
||||
AC_DEFUN(PHP_CHECK_FUNC,[
|
||||
unset ac_cv_func_$1
|
||||
unset ac_cv_func___$1
|
||||
unset found
|
||||
@@ -1727,7 +1720,7 @@ dnl PHP_AP_EXTRACT_VERSION(/path/httpd)
|
||||
dnl This macro is used to get a comparable
|
||||
dnl version for apache1/2.
|
||||
dnl
|
||||
AC_DEFUN([PHP_AP_EXTRACT_VERSION],[
|
||||
AC_DEFUN(PHP_AP_EXTRACT_VERSION,[
|
||||
ac_output=`$1 -v 2>&1`
|
||||
ac_IFS=$IFS
|
||||
IFS="- /.
|
||||
@@ -1737,76 +1730,3 @@ IFS="- /.
|
||||
|
||||
APACHE_VERSION=`expr [$]4 \* 1000000 + [$]5 \* 1000 + [$]6`
|
||||
])
|
||||
|
||||
dnl PHP_PROG_SED
|
||||
dnl ------------
|
||||
dnl Check for a fully-functional sed program, that truncates
|
||||
dnl as few characters as possible. Prefer GNU sed if found.
|
||||
dnl
|
||||
dnl Based on LT_AC_PROG_SED (libtool CVS)
|
||||
dnl
|
||||
AC_DEFUN([PHP_PROG_SED],
|
||||
[AC_MSG_CHECKING([for working sed])
|
||||
AC_CACHE_VAL(ac_cv_path_sed,
|
||||
[
|
||||
|
||||
# Create a temporary directory, and hook for its removal unless debugging.
|
||||
$debug ||
|
||||
{
|
||||
trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0
|
||||
trap '{ (exit 1); exit 1; }' 1 2 13 15
|
||||
}
|
||||
|
||||
# Create a (secure) tmp directory for tmp files.
|
||||
: ${TMPDIR=/tmp}
|
||||
{
|
||||
tmp=`(umask 077 && mktemp -d -q "$TMPDIR/sedXXXXXX") 2>/dev/null` &&
|
||||
test -n "$tmp" && test -d "$tmp"
|
||||
} ||
|
||||
{
|
||||
tmp=$TMPDIR/sed$$-$RANDOM
|
||||
(umask 077 && mkdir $tmp)
|
||||
} ||
|
||||
{
|
||||
echo "$me: cannot create a temporary directory in $TMPDIR" >&2
|
||||
{ (exit 1); exit 1; }
|
||||
}
|
||||
_max=0
|
||||
_count=0
|
||||
|
||||
# Use the sed found in PATH, skip the rest
|
||||
_sed=sed
|
||||
|
||||
# Check for GNU sed and select it if it is found.
|
||||
if "${_sed}" --version 2>&1 < /dev/null | egrep '(GNU)' > /dev/null; then
|
||||
ac_cv_path_sed=${_sed}
|
||||
else
|
||||
cat /dev/null > "$tmp/sed.in"
|
||||
_count=0
|
||||
echo -n "0123456789" >"$tmp/sed.in"
|
||||
while true; do
|
||||
cat "$tmp/sed.in" "$tmp/sed.in" >"$tmp/sed.tmp"
|
||||
mv "$tmp/sed.tmp" "$tmp/sed.in"
|
||||
cp "$tmp/sed.in" "$tmp/sed.nl"
|
||||
echo >>"$tmp/sed.nl"
|
||||
${_sed} -e 's/a$//' < "$tmp/sed.nl" >"$tmp/sed.out" || break
|
||||
cmp -s "$tmp/sed.out" "$tmp/sed.nl" || break
|
||||
# 10000 chars as input seems more than enough
|
||||
test $_count -gt 10 && break
|
||||
_count=`expr $_count + 1`
|
||||
if test $_count -gt $_max; then
|
||||
_max=$_count
|
||||
ac_cv_path_sed=${_sed}
|
||||
fi
|
||||
done
|
||||
fi
|
||||
rm -rf "$tmp"
|
||||
])
|
||||
if test -z "$ac_cv_path_sed"; then
|
||||
AC_MSG_ERROR([Could not find working sed on this system. Please install GNU sed.])
|
||||
else
|
||||
SED=$ac_cv_path_sed
|
||||
PHP_SUBST(SED)
|
||||
AC_MSG_RESULT([$SED])
|
||||
fi
|
||||
])
|
||||
+280
@@ -0,0 +1,280 @@
|
||||
Following is a merge of two letters I sent to php4beta@lists.php.net,
|
||||
describing the changes in API between PHP 3.0 and PHP 4.0 (Zend).
|
||||
This file is by no means thorough documentation of the PHP API,
|
||||
and is intended for developers who are familiar with the PHP 3.0 API,
|
||||
and want to port their code to PHP 4.0, or take advantage of its new
|
||||
features. For highlights about the PHP 3.0 API, consult apidoc.txt.
|
||||
|
||||
Zeev
|
||||
|
||||
--------------------------------------------------------------------------
|
||||
|
||||
I'm going to try to list the important changes in API and programming
|
||||
techniques that are involved in developing modules for PHP4/Zend, as
|
||||
opposed to PHP3. Listing the whole PHP4 API is way beyond my scope here,
|
||||
it's mostly a 'diff' from the apidoc.txt, which you're all pretty familiar
|
||||
with.
|
||||
An important note that I neglected to mention yesterday - the php4 tree is
|
||||
based on the php 3.0.5 tree, plus all 3.0.6 patches hand-patched into it.
|
||||
Notably, it does NOT include any 3.0.7 patches. All of those have to be
|
||||
reapplied, with extreme care - modules should be safe to patch (mostly),
|
||||
but anything that touches the core or main.c will almost definitely require
|
||||
changes in order to work properly.
|
||||
|
||||
[1] Symbol Tables
|
||||
|
||||
One of the major changes in Zend involves changing the way symbols tables
|
||||
work. Zend enforces reference counting on all values and resources. This
|
||||
required changes in the semantics of the hash tables that implement symbol
|
||||
tables. Instead of storing pval in the hashes, we now store pval *. All
|
||||
of the API functions in Zend were changed in a way that this change is
|
||||
completely transparent. However, if you've used 'low level' hash functions
|
||||
to access or update elements in symbol tables, your code will require
|
||||
changes. Following are two simple examples, one demonstrates the
|
||||
difference between PHP3 and Zend when reading a symbol's value, and the
|
||||
other demonstrates the difference when writing a value.
|
||||
|
||||
php3_read()
|
||||
{
|
||||
pval *foo;
|
||||
|
||||
_php3_hash_find(ht, "foo", sizeof("foo"), &foo);
|
||||
/* foo->type is the type and foo->value is the value */
|
||||
}
|
||||
|
||||
|
||||
php4_read()
|
||||
{
|
||||
pval **foo;
|
||||
|
||||
_php3_hash_find(ht, "foo", sizeof("foo"), &foo);
|
||||
/* (*foo)->type is the type and (*foo)->value is the value */
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
php3_write()
|
||||
{
|
||||
pval newval;
|
||||
|
||||
newval.type = ...;
|
||||
newval.value = ...;
|
||||
_php3_hash_update(ht, "bar", sizeof("bar"), &newval, sizeof(pval), NULL);
|
||||
}
|
||||
|
||||
php4_write()
|
||||
{
|
||||
pval *newval = ALLOC_ZVAL();
|
||||
|
||||
newval->refcount=1;
|
||||
newval->is_ref=0;
|
||||
newval->type = ...;
|
||||
newval->value = ...;
|
||||
_php3_hash_update(ht, "bar", sizeof("bar"), &newval, sizeof(pval *), NULL);
|
||||
}
|
||||
|
||||
|
||||
[2] Resources
|
||||
|
||||
One of the 'cute' things about the reference counting support is that it
|
||||
completely eliminates the problem of resource leaking. A simple loop that
|
||||
included '$result = mysql_query(...)' in PHP leaked unless the user
|
||||
remembered to run mysql_free($result) at the end of the loop body, and
|
||||
nobody really did. In order to take advantage of the automatic resource
|
||||
deallocation upon destruction, there's virtually one small change you need
|
||||
to conduct. Change the result type of a resource that you want to destroy
|
||||
itself as soon as its no longer referenced (just about any resource I can
|
||||
think of) as IS_RESOURCE, instead of as IS_LONG. The rest is magic.
|
||||
|
||||
A special treatment is required for SQL modules that follow MySQL's
|
||||
approach for having the link handle as an optional argument. Modules that
|
||||
follow the MySQL module model, store the last opened link in a global
|
||||
variable, that they use in case the user neglects to explicitly specify a
|
||||
link handle. Due to the way referenec counting works, this global
|
||||
reference is just like any other reference, and must increase that SQL link
|
||||
resource's reference count (otherwise, it will be closed prematurely).
|
||||
Simply, when you set the default link to a certain link, increase that
|
||||
link's reference count by calling zend_list_addref().
|
||||
As always, the MySQL module is the one used to demonstrate 'new
|
||||
technology'. You can look around it and look for IS_RESOURCE, as well as
|
||||
zend_list_addref(), to see a clear example of how the new API should be used.
|
||||
|
||||
|
||||
[3] Thread safety issues
|
||||
|
||||
I'm not going to say that Zend was designed with thread safety in mind, but
|
||||
from some point, we've decided upon several guidelines that would make the
|
||||
move to thread safety much, much easier. Generally, we've followed the PHP
|
||||
3.1 approach of moving global variables to a structure, and encapsulating
|
||||
all global variable references within macros. There are three main
|
||||
differences:
|
||||
1. We grouped related globals in a single structure, instead of grouping
|
||||
all globals in one structure.
|
||||
2. We've used much, much shorter macro names to increase the readability
|
||||
of the source code.
|
||||
3. Regardless of whether we're compiling in thread safe mode or not, all
|
||||
global variables are *always* stored in a structure. For example, you
|
||||
would never have a global variable 'foo', instead, it'll be a property of a
|
||||
global structure, for example, compiler_globals.foo. That makes
|
||||
development much, much easier, since your code will simply not compile
|
||||
unless you remember to put the necessary macro around foo.
|
||||
|
||||
To write code that'll be thread safe in the future (when we release our
|
||||
thread safe memory manager and work on integrating it), you can take a look
|
||||
at zend_globals.h. Essentially, two sets of macros are defined, one for
|
||||
thread safe mode, and one for thread unsafe mode. All global references
|
||||
are encapsulated within ???G(varname), where ??? is the appropriate prefix
|
||||
for your structure (for example, so far we have CG(), EG() and AG(), which
|
||||
stand for the compiler, executor and memory allocator, respectively).
|
||||
When compiling with thread safety enabled, each function that makes use of
|
||||
a ???G() macro, must obtain the pointer to its copy of the structure. It
|
||||
can do so in one of two forms:
|
||||
1. It can receive it as an argument.
|
||||
2. It can fetch it.
|
||||
|
||||
Obviously, the first method is preferable since it's much quicker.
|
||||
However, it's not always possible to send the structure all the way to a
|
||||
particular function, or it may simply bloat the code too much in some
|
||||
cases. Functions that receive the globals as an argument, should look like
|
||||
this:
|
||||
|
||||
rettype functioname(???LS_D) <-- a function with no arguments
|
||||
rettype functioname(type arg1, ..., type argn ???LS_DC) <-- a funciton with
|
||||
arguments
|
||||
|
||||
Calls to such functions should look like this:
|
||||
functionname(???LS_C) <-- a function with no arguments
|
||||
functionname(arg1, ..., argn ???LS_CC) <-- a function with arguments
|
||||
|
||||
LS stands for 'Local Storage', _C stands for Call and _CC stands for Call
|
||||
Comma, _D stands for Declaration and _DC stands for Declaration Comma.
|
||||
Note that there's NO comma between the last argument and ???LS_DC or ???LS_CC.
|
||||
|
||||
If you do not pass the structure as an argument you can always fetch it by
|
||||
using the appropriate ???LS_FETCH() macros within a functions variable
|
||||
declarations.
|
||||
|
||||
In general, every module that makes use of globals should use this approach
|
||||
if it plans to be thread safe.
|
||||
|
||||
|
||||
[4] Generalized INI support
|
||||
|
||||
The code comes to solve several issues:
|
||||
|
||||
a. The ugly long block of code in main.c that reads values from the
|
||||
cfg_hash into php3_ini.
|
||||
b. Get rid of php3_ini. The performance penalty of copying it around all
|
||||
the time in the Apache module probably wasn't too high, but
|
||||
psychologically, it annoyed me :)
|
||||
c. Get rid of the ugly code in mod_php4.c, that also reads values from
|
||||
Apache directives and puts them into the php3_ini structure.
|
||||
d. Generalize all the code so that you only have to add an entry in one
|
||||
single place and get it automatically supported in php3.ini, Apache, Win32
|
||||
registry, runtime function ini_get() and ini_alter() and any future method
|
||||
we might have.
|
||||
e. Allow users to easily override *ANY* php3.ini value, except for ones
|
||||
they're not supposed to, of course.
|
||||
|
||||
I'm happy to say that I think I pretty much reached all goals. php_ini.c
|
||||
implements a mechanism that lets you add your INI entry in a single place,
|
||||
with a default value in case there's no php3.ini value. What you get by
|
||||
using this mechanism:
|
||||
|
||||
1. Automatic initialization from php3.ini if available, or from the
|
||||
default value if not.
|
||||
2. Automatic support in ini_alter(). That means a user can change the
|
||||
value for this INI entry at runtime, without you having to add in a single
|
||||
line of code, and definitely no additional function (for example, in PHP3,
|
||||
we had to add in special dedicated functions, like
|
||||
set_magic_quotes_runtime() or the likes - no need for that anymore).
|
||||
3. Automatic support in Apache .conf files.
|
||||
4. No need for a global php3_ini-like variable that'll store all that
|
||||
info. You can directly access each INI entry by name, in runtime. 'Sure,
|
||||
that's not revolutionary, it's just slow' is probably what some of you
|
||||
think - which is true, but, you can also register a callback function that
|
||||
is called each time your INI entry is changed, if you wish to store it in a
|
||||
cached location for intensive use.
|
||||
5. Ability to access the current active value for a given INI entry, and
|
||||
the 'master' value.
|
||||
|
||||
Of course, (2) and (3) are only applicable in some cases. Some entries
|
||||
shouldn't be overriden by users in runtime or through Apache .conf files -
|
||||
you can, of course, mark them as such.
|
||||
|
||||
|
||||
So, enough hype, how does it work.
|
||||
|
||||
Essentially:
|
||||
|
||||
static PHP_INI_MH(OnChangeBar); /* declare a message handler for a change
|
||||
in "bar" */
|
||||
|
||||
PHP_INI_BEGIN()
|
||||
PHP_INI_ENTRY("foo", "1", PHP_INI_ALL, NULL, NULL)
|
||||
PHP_INI_ENTRY("bar", "bah", PHP_INI_SYSTEM, OnChangeBar, NULL)
|
||||
PHP_INI_END()
|
||||
|
||||
static PHP_INI_MH(OnChangeBar)
|
||||
{
|
||||
a_global_var_for_bar = new_value;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int whatever_minit(INIT_FUNC_ARGS)
|
||||
{
|
||||
...
|
||||
REGISTER_INI_ENTRIES();
|
||||
...
|
||||
}
|
||||
|
||||
|
||||
int whatever_mshutdown(SHUTDOWN_FUNC_ARGS)
|
||||
{
|
||||
...
|
||||
UNREGISTER_INI_ENTRIES();
|
||||
...
|
||||
}
|
||||
|
||||
|
||||
and that's it. Here's what it does. As you can probably guess, this code
|
||||
registers two INI entries - "foo" and "bar". They're given defaults "1"
|
||||
and "bah" respectively - note that all defaults are always given as
|
||||
strings. That doesn't reduce your ability to use integer values, simply
|
||||
specify them as strings. "foo" is marked so that it can be changed by
|
||||
anyone at any time (PHP_INI_ALL), whereas "bar" is marked so it can be
|
||||
changed only at startup in the php3.ini only, presumably, by the system
|
||||
administrator (PHP_INI_SYSTEM).
|
||||
When "foo" changes, no function is called. Access to it is done using the
|
||||
macros INI_INT("foo"), INI_FLT("foo") or INI_STR("foo"), which return a
|
||||
long, double or char * respectively (strings that are returned aren't
|
||||
duplicated - if they're manipulated, you must duplicate them first). You
|
||||
can also access the original value (the 'master' value, in case one of them
|
||||
was overriden by a user) using another pair of macros:
|
||||
INI_ORIG_INT("foo"), INI_ORIG_FLT("foo") and INI_ORIG_STR("foo").
|
||||
|
||||
When "bar" changes, a special message handler is called, OnBarChange().
|
||||
Always declare those message handlers using PHP_INI_MH(), as they might
|
||||
change in the future. Message handlers are called as soon as an ini entry
|
||||
initializes or changes, and allow you to cache a certain INI value in a
|
||||
quick C structure. In this example, whenever "bar" changes, the new value
|
||||
is stored in a_global_var_for_bar, which is a global char * pointer,
|
||||
quickly accessible from other functions. Things get a bit more complicated
|
||||
when you want to implement a thread-safe module, but it's doable as well.
|
||||
Message handlers may return SUCCESS to acknowledge the new value, or
|
||||
FAILURE to reject it. That enables you to reject invalid values for some
|
||||
INI entries if you want. Finally, you can have a pointer passed to your
|
||||
message handler - that's the fifth argument to PHP_INI_ENTRY(). It is
|
||||
passed as mh_arg to the message handler.
|
||||
|
||||
Remember that for certain values, there's really no reason to mess with a
|
||||
callback function. A perfect example for this are the syntax highlight
|
||||
colors, which no longer have a dedicated global C slot that stores them,
|
||||
but instead, are fetched from the php_ini hash on demand.
|
||||
|
||||
"As always", for a perfect working example of this mechanism, consult
|
||||
functions/mysql.c. This module uses the new INI entry mechanism, and was
|
||||
also converted to be thread safe in general, and in its php_ini support in
|
||||
particular. Converting your modules to look like this for thread safety
|
||||
isn't a bad idea (not necessarily now, but in the long run).
|
||||
|
||||
+492
@@ -0,0 +1,492 @@
|
||||
PHP Version 3.0 API Documentation
|
||||
|
||||
Table of Contents
|
||||
-----------------
|
||||
1. Function Prototype
|
||||
2. Function Arguments
|
||||
3. Variable number of function arguments
|
||||
4. Using the function arguments
|
||||
5. Memory management in functions
|
||||
6. Setting variables in the symbol table
|
||||
7. Returning values from functions
|
||||
8. Returning 'complex' values from functions (arrays or objects)
|
||||
9. Using the resource list
|
||||
10. Using the persistent resource table
|
||||
11. Adding runtime configuration directives
|
||||
-----------------
|
||||
|
||||
1. Function Prototype
|
||||
|
||||
All functions look like this:
|
||||
|
||||
PHP_FUNCTION(foo) {
|
||||
|
||||
}
|
||||
|
||||
Even if your function doesn't take any arguments, this is how it is
|
||||
called.
|
||||
|
||||
-----------------
|
||||
|
||||
2. Function Arguments
|
||||
|
||||
Arguments are always of type pval. This type contains a union which
|
||||
has the actual type of the argument. So, if your function takes two
|
||||
arguments, you would do something like the following at the top of your
|
||||
function:
|
||||
|
||||
pval *arg1, *arg2;
|
||||
if (ARG_COUNT(ht) != 2 || getParameters(ht,2,&arg1,&arg2)==FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
NOTE: Arguments can be passed either by value or by reference. In both
|
||||
cases you will need to pass &(pval *) to getParameters. If you want to
|
||||
check if the n'th parameter was sent to you by reference or not, you can
|
||||
use the function, ParameterPassedByReference(ht,n). It will return either
|
||||
1 or 0.
|
||||
|
||||
When you change any of the passed parameters, whether they are sent by
|
||||
reference or by value, you can either start over with the parameter by
|
||||
calling pval_destructor on it, or if it's an ARRAY you want to add to,
|
||||
you can use functions similar to the ones in internal_functions.h which
|
||||
manipulate return_value as an ARRAY.
|
||||
|
||||
Also if you change a parameter to IS_STRING make sure you first assign
|
||||
the new estrdup'ed string and the string length, and only later change the
|
||||
type to IS_STRING. If you change the string of a parameter which already
|
||||
IS_STRING or IS_ARRAY you should run pval_destructor on it first.
|
||||
|
||||
-----------------
|
||||
|
||||
3. Variable number of function arguments
|
||||
|
||||
A function can take a variable number of arguments. If your function can
|
||||
take either 2 or 3 arguments, use the following:
|
||||
|
||||
pval *arg1, *arg2, *arg3;
|
||||
int arg_count = ARG_COUNT(ht);
|
||||
|
||||
if (arg_count<2 || arg_count>3 ||
|
||||
getParameters(ht,arg_count,&arg1,&arg2,&arg3)==FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
------------------
|
||||
|
||||
4. Using the function arguments
|
||||
|
||||
The type of each argument is stored in the pval type field:
|
||||
|
||||
|
||||
This type can be any of the following:
|
||||
|
||||
IS_STRING String
|
||||
IS_DOUBLE Double-precision floating point
|
||||
IS_LONG Long
|
||||
IS_ARRAY Array
|
||||
|
||||
IS_EMPTY ??
|
||||
IS_USER_FUNCTION ??
|
||||
IS_INTERNAL_FUNCTION ?? (if some of these cannot be passed to a
|
||||
function - delete)
|
||||
IS_CLASS ??
|
||||
IS_OBJECT ??
|
||||
|
||||
If you get an argument of one type and would like to use it as another,
|
||||
or if you just want to force the argument to be of a certain type, you
|
||||
can use one of the following conversion functions:
|
||||
|
||||
convert_to_long(arg1);
|
||||
convert_to_double(arg1);
|
||||
convert_to_string(arg1);
|
||||
convert_to_boolean_long(arg1); If the string is "" or "0" it
|
||||
becomes 0, 1 otherwise
|
||||
convert_string_to_number(arg1); Converts string to either LONG or
|
||||
DOUBLE depending on string
|
||||
|
||||
These function all do in-place conversion. They do not return anything.
|
||||
|
||||
The actual argument is stored in a union.
|
||||
|
||||
For type IS_STRING, use arg1->value.str.val
|
||||
IS_LONG arg1->value.lval
|
||||
IS_DOUBLE arg1->value.dval
|
||||
|
||||
-------------------
|
||||
|
||||
5. Memory management in functions
|
||||
|
||||
Any memory needed by a function should be allocated with either emalloc()
|
||||
or estrdup(). These are memory handling abstraction functions that look
|
||||
and smell like the normal malloc() and strdup() functions. Memory should
|
||||
be freed with efree().
|
||||
|
||||
There are two kinds of memory in this program. Memory which is returned
|
||||
to the parser in a variable and memory which you need for temporary
|
||||
storage in your internal function. When you assign a string to a
|
||||
variable which is returned to the parser you need to make sure you first
|
||||
allocate the memory with either emalloc or estrdup. This memory
|
||||
should NEVER be freed by you, unless you later, in the same function
|
||||
overwrite your original assignment (this kind of programming practice is
|
||||
not good though).
|
||||
|
||||
For any temporary/permanent memory you need in your functions/library you
|
||||
should use the three emalloc(), estrdup(), and efree() functions. They
|
||||
behave EXACTLY like their counterpart functions. Anything you emalloc()
|
||||
or estrdup() you have to efree() at some point or another, unless it's
|
||||
supposed to stick around until the end of the program, otherwise there
|
||||
will be a memory leak. The meaning of "the functions behave exactly like
|
||||
their counterparts" is if you efree() something which was not
|
||||
emalloc()'ed nor estrdup()'ed you might get a segmentation fault. So
|
||||
please take care and free all of your wasted memory. One of the biggest
|
||||
improvements in PHP 3.0 will hopefully be the memory management.
|
||||
|
||||
If you compile with "-DDEBUG", PHP3 will print out a list of all
|
||||
memory that was allocated using emalloc() and estrdup() but never
|
||||
freed with efree() when it is done running the specified script.
|
||||
|
||||
-------------------
|
||||
|
||||
6. Setting variables in the symbol table
|
||||
|
||||
A number of macros are available which make it easier to set a variable
|
||||
in the symbol table:
|
||||
|
||||
SET_VAR_STRING(name,value) **
|
||||
SET_VAR_DOUBLE(name,value)
|
||||
SET_VAR_LONG(name,value)
|
||||
|
||||
** Be careful here. The value part must be malloc'ed manually because
|
||||
the memory management code will try to free this pointer later. Do
|
||||
not pass statically allocated memory into a SET_VAR_STRING
|
||||
|
||||
Symbol tables in PHP 3.0 are implemented as hash tables. At any given time,
|
||||
&symbol_table is a pointer to the 'main' symbol table, and active_symbol_table
|
||||
points to the currently active symbol table (these may be identical like in
|
||||
startup, or different, if you're inside a function).
|
||||
|
||||
The following examples use 'active_symbol_table'. You should replace it with
|
||||
&symbol_table if you specifically want to work with the 'main' symbol table.
|
||||
Also, the same funcions may be applied to arrays, as explained below.
|
||||
|
||||
* To check whether a variable named $foo already exists in a symbol table:
|
||||
if (hash_exists(active_symbol_table,"foo",sizeof("foo"))) { exists... }
|
||||
else { doesn't exist }
|
||||
|
||||
* If you also need to get the type of the variable, you can use:
|
||||
hash_find(active_symbol_table,"foo",sizeof("foo"),&pvalue);
|
||||
check(pvalue.type);
|
||||
|
||||
Arrays in PHP 3.0 are implemented using the same hashtables as symbol tables.
|
||||
This means the two above functions can also be used to check variables
|
||||
inside arrays.
|
||||
|
||||
If you want to define a new array in a symbol table, you should do this:
|
||||
|
||||
1. Possibly check it exists and abort, using hash_exists()
|
||||
or hash_find().
|
||||
2. Code:
|
||||
|
||||
pval arr;
|
||||
|
||||
if (array_init(&arr) == FAILURE) { failed... };
|
||||
hash_update(active_symbol_table,"foo",sizeof("foo"),&arr,sizeof(pval),NULL);
|
||||
|
||||
This code declares a new array, named $foo, in the active symbol table.
|
||||
This array is empty.
|
||||
|
||||
Here's how to add new entries to it:
|
||||
|
||||
pval entry;
|
||||
|
||||
entry.type = IS_LONG;
|
||||
entry.value.lval = 5;
|
||||
|
||||
hash_update(arr.value.ht,"bar",sizeof("bar"),&entry,sizeof(pval),NULL); /* defines $foo["bar"] = 5 */
|
||||
hash_index_update(arr.value.ht,7,&entry,sizeof(pval),NULL); /* defines $foo[7] = 5 */
|
||||
hash_next_index_insert(arr.value.ht,&entry,sizeof(pval),NULL); /* defines the next free place in $foo[],
|
||||
* $foo[8], to be 5 (works like php2)
|
||||
*/
|
||||
|
||||
If you'd like to modify a value that you inserted to a hash, you must first retreive it from the hash. To
|
||||
prevent that overhead, you can supply a pval ** to the hash add function, and it'll be updated with the
|
||||
pval * address of the inserted element inside the hash. If that value is NULL (like in all of the
|
||||
above examples) - that parameter is ignored.
|
||||
|
||||
hash_next_index_insert() works more or less using the same logic
|
||||
"$foo[] = bar;" works in PHP 2.0.
|
||||
|
||||
If you are building an array to return from a function, you can initialize
|
||||
the array just like above by doing:
|
||||
|
||||
if (array_init(return_value) == FAILURE) { failed...; }
|
||||
|
||||
and then adding values with the helper functions:
|
||||
|
||||
add_next_index_long(return_value,long_value);
|
||||
add_next_index_double(return_value,double_value);
|
||||
add_next_index_string(return_value,estrdup(string_value));
|
||||
|
||||
Of course, if the adding isn't done right after the array
|
||||
initialization, you'd probably have to look for the array first:
|
||||
|
||||
pval *arr;
|
||||
|
||||
if (hash_find(active_symbol_table,"foo",sizeof("foo"),(void **)&arr)==FAILURE) { can't find... }
|
||||
else { use arr->value.ht... }
|
||||
|
||||
Note that hash_find receives a pointer to a pval pointer, and
|
||||
not a pval pointer.
|
||||
|
||||
Just about any hash function returns SUCCESS or FAILURE (except for
|
||||
hash_exists() that returns a boolean truth value).
|
||||
|
||||
-------------------
|
||||
|
||||
7. Returning 'simple' values from functions (integers, floats or strings)
|
||||
|
||||
A number of macros are available to make it easier to return things from
|
||||
functions:
|
||||
|
||||
These set the return value and return from the function:
|
||||
|
||||
RETURN_FALSE
|
||||
RETURN_TRUE
|
||||
RETURN_LONG(l)
|
||||
RETURN_STRING(s,dup) If dup is true, duplicates the string
|
||||
RETURN_STRINGL(s,l,dup) Return string (s) specifying length (l).
|
||||
RETURN_DOUBLE(d)
|
||||
|
||||
These only set the return value:
|
||||
|
||||
RETVAL_FALSE
|
||||
RETVAL_TRUE
|
||||
RETVAL_LONG(l)
|
||||
RETVAL_STRING(s,dup) If dup is true, duplicates the string
|
||||
RETVAL_STRINGL(s,l,dup) Return string (s) specifying length (l).
|
||||
RETVAL_DOUBLE(d)
|
||||
|
||||
The string macros above will all estrdup() the passed 's' argument,
|
||||
so you can safely free the argument after calling the macro, or
|
||||
alternatively use statically allocated memory.
|
||||
|
||||
If your function returns boolean success/error responses, always use
|
||||
RETURN_TRUE and RETURN_FALSE respectively.
|
||||
|
||||
-------------------
|
||||
|
||||
8. Returning 'complex' values from functions (arrays or objects)
|
||||
|
||||
Your function can also return a complex data type such as an object
|
||||
or an array.
|
||||
|
||||
Returning an object:
|
||||
|
||||
1. Call object_init(return_value).
|
||||
2. Fill it up with values:
|
||||
|
||||
add_property_long(return_value,property_name,l) Add a property named 'property_name', of type long, equals to 'l'
|
||||
add_property_double(return_value,property_name,d) Same, only a double
|
||||
add_property_string(return_value,property_name,str) Same, only a string
|
||||
add_property_stringl(return_value,property_name,str,l) Add a property named 'property_name', of type string, string is 'str' with length 'l'
|
||||
|
||||
3. Possibly, register functions for this object. In order to
|
||||
obtain values from the object, the function would have to fetch
|
||||
"this" from the active_symbol_table. Its type should be IS_OBJECT,
|
||||
and it's basically a regular hash table (i.e., you can use regular
|
||||
hash functions on .value.ht). The actual registration of the
|
||||
function can be done using:
|
||||
|
||||
add_method(return_value,function_name,function_ptr)
|
||||
|
||||
|
||||
Returning an array:
|
||||
|
||||
1. Call array_init(return_value).
|
||||
2. Fill it up with values:
|
||||
|
||||
add_assoc_long(return_value,key,l) add associative entry with key 'key' and long value 'l'
|
||||
add_assoc_double(return_value,key,d)
|
||||
add_assoc_string(return_value,key,str)
|
||||
add_assoc_stringl(return_value,key,str,length) specify the string length
|
||||
|
||||
add_index_long(return_value,index,l) add entry in index 'index' with long value 'l'
|
||||
add_index_double(return_value,index,d)
|
||||
add_index_string(return_value,index,str)
|
||||
add_index_stringl(return_value,index,str,length) specify the string length
|
||||
|
||||
add_next_index_long(return_value,l) add an array entry in the next free offset with long value 'l'
|
||||
add_next_index_double(return_value,d)
|
||||
add_next_index_string(return_value,str)
|
||||
add_next_index_stringl(return_value,str,length) specify the string length
|
||||
|
||||
-------------------
|
||||
|
||||
9. Using the resource list
|
||||
|
||||
PHP 3.0 has a standard way of dealing with various types of resources,
|
||||
that replaces all of the local linked lists in PHP 2.0.
|
||||
|
||||
Available functions:
|
||||
|
||||
php3_list_insert(ptr, type) returns the 'id' of the newly inserted resource
|
||||
php3_list_delete(id) delete the resource with the specified id
|
||||
php3_list_find(id,*type) returns the pointer of the resource with the specified id, updates 'type' to the resource's type
|
||||
|
||||
Typically, these functions are used for SQL drivers but they can be
|
||||
used for anything else, and are used, for instance, for maintaining
|
||||
file descriptors.
|
||||
|
||||
Typical list code would look like this:
|
||||
|
||||
Adding a new resource:
|
||||
|
||||
RESOURCE *resource;
|
||||
|
||||
...allocate memory for resource and acquire resource...
|
||||
/* add a new resource to the list */
|
||||
return_value->value.lval = php3_list_insert((void *) resource, LE_RESOURCE_TYPE);
|
||||
return_value->type = IS_LONG;
|
||||
|
||||
Using an existing resource:
|
||||
|
||||
pval *resource_id;
|
||||
RESOURCE *resource;
|
||||
int type;
|
||||
|
||||
convert_to_long(resource_id);
|
||||
resource = php3_list_find(resource_id->value.lval, &type);
|
||||
if (type != LE_RESOURCE_TYPE) {
|
||||
php3_error(E_WARNING,"resource index %d has the wrong type",resource_id->value.lval);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
...use resource...
|
||||
|
||||
Deleting an existing resource:
|
||||
|
||||
pval *resource_id;
|
||||
RESOURCE *resource;
|
||||
int type;
|
||||
|
||||
convert_to_long(resource_id);
|
||||
php3_list_delete(resource_id->value.lval);
|
||||
|
||||
|
||||
The resource types should be registered in php3_list.h, in enum
|
||||
list_entry_type. In addition, one should add shutdown code for any
|
||||
new resource type defined, in list.c's list_entry_destructor() (even if
|
||||
you don't have anything to do on shutdown, you must add an empty case).
|
||||
|
||||
-------------------
|
||||
|
||||
10. Using the persistent resource table
|
||||
|
||||
PHP 3.0 has a standard way of storing persistent resources (i.e.,
|
||||
resources that are kept in between hits). The first module to use
|
||||
this feature was the MySQL module, and mSQL followed it, so one can
|
||||
get the general impression of how a persistent resource should be
|
||||
used by reading mysql.c. The functions you should look at are:
|
||||
php3_mysql_do_connect()
|
||||
php3_mysql_connect()
|
||||
php3_mysql_pconnect()
|
||||
|
||||
The general idea of persistence modules is this:
|
||||
1. Code all of your module to work with the regular resource list
|
||||
mentioned in section (9).
|
||||
2. Code extra connect functions that check if the resource already
|
||||
exists in the persistent resource list. If it does, register it
|
||||
as in the regular resource list as a pointer to the persistent
|
||||
resource list (because of 1., the rest of the code
|
||||
should work immediately). If it doesn't, then create it, add it
|
||||
to the persistent resource list AND add a pointer to it from the
|
||||
regular resource list, so all of the code would work since it's
|
||||
in the regular resource list, but on the next connect, the
|
||||
resource would be found in the persistent resource list and be
|
||||
used without having to recreate it.
|
||||
You should register these resources with a different type (e.g.
|
||||
LE_MYSQL_LINK for non-persistent link and LE_MYSQL_PLINK for
|
||||
a persistent link).
|
||||
|
||||
If you read mysql.c, you'll notice that except for the more complex
|
||||
connect function, nothing in the rest of the module has to be changed.
|
||||
|
||||
The very same interface exists for the regular resource list and the
|
||||
persistent resource list, only 'list' is replaced with 'plist':
|
||||
|
||||
php3_plist_insert(ptr, type) returns the 'id' of the newly inserted resource
|
||||
php3_plist_delete(id) delete the resource with the specified id
|
||||
php3_plist_find(id,*type) returns the pointer of the resource with the specified id, updates 'type' to the resource's type
|
||||
|
||||
However, it's more than likely that these functions would prove
|
||||
to be useless for you when trying to implement a persistent module.
|
||||
Typically, one would want to use the fact that the persistent resource
|
||||
list is really a hash table. For instance, in the MySQL/mSQL modules,
|
||||
when there's a pconnect() call (persistent connect), the function
|
||||
builds a string out of the host/user/passwd that were passed to the
|
||||
function, and hashes the SQL link with this string as a key. The next
|
||||
time someone calls a pconnect() with the same host/user/passwd, the
|
||||
same key would be generated, and the function would find the SQL link
|
||||
in the persistent list.
|
||||
|
||||
Until further documented, you should look at mysql.c or msql.c to
|
||||
see how one should use the plist's hash table abilities.
|
||||
|
||||
One important thing to note: resources going into the persistent
|
||||
resource list must *NOT* be allocated with PHP's memory manager, i.e.,
|
||||
they should NOT be created with emalloc(), estrdup(), etc. Rather,
|
||||
one should use the regular malloc(), strdup(), etc. The reason for
|
||||
this is simple - at the end of the request (end of the hit), every
|
||||
memory chunk that was allocated using PHP's memory manager is deleted.
|
||||
Since the persistent list isn't supposed to be erased at the end
|
||||
of a request, one mustn't use PHP's memory manager for allocating
|
||||
resources that go to it.
|
||||
|
||||
Shutting down persistent resources:
|
||||
|
||||
When you register resource that's going to be in the persistent list,
|
||||
you should add destructors to it both in the non-persistent list
|
||||
and in the persistent list.
|
||||
The destructor in the non-persistent list destructor shouldn't do anything.
|
||||
The one in the persistent list destructor should properly free any
|
||||
resources obtained by that type (e.g. memory, SQL links, etc). Just like
|
||||
with the non-persistent resources, you *MUST* add destructors for every
|
||||
resource, even it requires no destructotion and the destructor would
|
||||
be empty.
|
||||
Remember, since emalloc() and friends aren't to be used in conjunction
|
||||
with the persistent list, you mustn't use efree() here either.
|
||||
|
||||
-------------------
|
||||
|
||||
11. Adding runtime configuration directives
|
||||
|
||||
Many of the features of PHP3 can be configured at runtime. These
|
||||
configuration directives can appear in either the designated php3.ini
|
||||
file, or in the case of the Apache module version in the Apache .conf
|
||||
files. The advantage of having them in the Apache .conf files is that
|
||||
they can be configured on a per-directory basis. This means that one
|
||||
directory may have a certain safemodeexecdir for example, while another
|
||||
directory may have another. This configuration granularity is especially
|
||||
handy when a server supports multiple virtual hosts.
|
||||
|
||||
The steps required to add a new directive:
|
||||
|
||||
1. Add directive to php3_ini_structure struct in mod_php4.h.
|
||||
|
||||
2. In main.c, edit the php3_module_startup function and add the
|
||||
appropriate cfg_get_string() or cfg_get_long() call.
|
||||
|
||||
3. Add the directive, restrictions and a comment to the php3_commands
|
||||
structure in mod_php4.c. Note the restrictions part. RSRC_CONF are
|
||||
directives that can only be present in the actual Apache .conf files.
|
||||
Any OR_OPTIONS directives can be present anywhere, include normal
|
||||
.htaccess files.
|
||||
|
||||
4. In either php3take1handler() or php3flaghandler() add the appropriate
|
||||
entry for your directive.
|
||||
|
||||
5. In the configuration section of the _php3_info() function in
|
||||
functions/info.c you need to add your new directive.
|
||||
|
||||
6. And last, you of course have to use your new directive somewhere.
|
||||
It will be addressable as php3_ini.directive
|
||||
+1
-1
@@ -67,7 +67,7 @@ snapshot:
|
||||
|
||||
cvsclean:
|
||||
@for i in `find . -name .cvsignore`; do \
|
||||
(cd `dirname $$i` 2>/dev/null && rm -rf `cat .cvsignore | grep -v config.nice` *.o *.a .libs || true); \
|
||||
(cd `dirname $$i` 2>/dev/null && rm -rf `cat .cvsignore` *.o *.a .libs || true); \
|
||||
done
|
||||
|
||||
.PHONY: $(ALWAYS) snapshot cvsclean
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
# | Sascha Schumann <sascha@schumann.cx> |
|
||||
# +----------------------------------------------------------------------+
|
||||
#
|
||||
# $Id: buildcheck.sh,v 1.21 2002-10-30 11:42:22 sas Exp $
|
||||
# $Id: buildcheck.sh,v 1.19 2002-07-21 13:09:07 sas Exp $
|
||||
#
|
||||
|
||||
echo "buildconf: checking installation..."
|
||||
|
||||
+46
-305
@@ -1,13 +1,13 @@
|
||||
#!/bin/sh
|
||||
##
|
||||
## GNU shtool -- The GNU Portable Shell Tool
|
||||
## Copyright (c) 1994-2002 Ralf S. Engelschall <rse@engelschall.com>
|
||||
## Copyright (c) 1994-2001 Ralf S. Engelschall <rse@engelschall.com>
|
||||
##
|
||||
## See http://www.gnu.org/software/shtool/ for more information.
|
||||
## See ftp://ftp.gnu.org/gnu/shtool/ for latest version.
|
||||
##
|
||||
## Version: 1.6.2 (02-Nov-2002)
|
||||
## Contents: 4/19 available modules
|
||||
## Version: 1.5.4 (14-Jun-2001)
|
||||
## Contents: 3/17 available modules
|
||||
##
|
||||
|
||||
##
|
||||
@@ -41,7 +41,6 @@
|
||||
## echo Print string with optional construct expansion
|
||||
## install Install a program, script or datafile
|
||||
## mkdir Make one or more directories
|
||||
## path Deal with program paths
|
||||
##
|
||||
## Not available commands (because module was not built-in):
|
||||
## mdate Pretty-print modification time of a file or dir
|
||||
@@ -51,14 +50,13 @@
|
||||
## mkln Make link with calculation of relative paths
|
||||
## mkshadow Make a shadow tree through symbolic links
|
||||
## fixperm Fix file permissions inside a source tree
|
||||
## rotate Logfile rotation
|
||||
## tarball Roll distribution tarballs
|
||||
## subst Apply sed(1) substitution operations
|
||||
## guessos Simple operating system guesser
|
||||
## arx Extended archive command
|
||||
## slo Separate linker options by library class
|
||||
## scpp Sharing C Pre-Processor
|
||||
## version Maintain a version information file
|
||||
## path Deal with program paths
|
||||
##
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
@@ -67,8 +65,8 @@ if [ $# -eq 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
if [ ".$1" = ".-h" -o ".$1" = ".--help" ]; then
|
||||
echo "This is GNU shtool, version 1.6.2 (02-Nov-2002)"
|
||||
echo "Copyright (c) 1994-2002 Ralf S. Engelschall <rse@engelschall.com>"
|
||||
echo "This is GNU shtool, version 1.5.4 (14-Jun-2001)"
|
||||
echo "Copyright (c) 1994-2001 Ralf S. Engelschall <rse@engelschall.com>"
|
||||
echo "Report bugs to <bug-shtool@gnu.org>"
|
||||
echo ''
|
||||
echo "Usage: shtool [<options>] [<cmd-name> [<cmd-options>] [<cmd-args>]]"
|
||||
@@ -80,63 +78,38 @@ if [ ".$1" = ".-h" -o ".$1" = ".--help" ]; then
|
||||
echo ' -r, --recreate recreate this shtool script via shtoolize'
|
||||
echo ''
|
||||
echo 'Available <cmd-name> [<cmd-options>] [<cmd-args>]:'
|
||||
echo ' echo [-n|--newline] [-e|--expand] [<str> ...]'
|
||||
echo ' install [-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy]'
|
||||
echo ' [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>]'
|
||||
echo ' [-o|--owner <owner>] [-g|--group <group>] [-e|--exec'
|
||||
echo ' <sed-cmd>] <file> [<file> ...] <path>'
|
||||
echo ' mkdir [-t|--trace] [-f|--force] [-p|--parents] [-m|--mode'
|
||||
echo ' <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir>'
|
||||
echo ' [<dir> ...]'
|
||||
echo ' path [-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename]'
|
||||
echo ' [-m|--magic] [-p|--path <path>] <str> [<str> ...]'
|
||||
echo ' echo [-n] [-e] [<str> ...]'
|
||||
echo ' install [-v] [-t] [-c] [-C] [-s] [-m<mode>] [-o<owner>] [-g<group>]'
|
||||
echo ' [-e<sed-cmd>] <file> [<file> ...] <path>'
|
||||
echo ' mkdir [-t] [-f] [-p] [-m<mode>] <dir> [<dir> ...]'
|
||||
echo ''
|
||||
echo 'Not available <cmd-name> (because module was not built-in):'
|
||||
echo ' mdate [-n|--newline] [-z|--zero] [-s|--shorten] [-d|--digits]'
|
||||
echo ' [-f|--field-sep <str>] [-o|--order <spec>] <path>'
|
||||
echo ' table [-F|--field-sep <sep>] [-w|--width <width>] [-c|--columns'
|
||||
echo ' <cols>] [-s|--strip <strip>] <str><sep><str>...'
|
||||
echo ' prop [-p|--prefix <str>]'
|
||||
echo ' move [-v|--verbose] [-t|--trace] [-e|--expand] [-p|--preserve]'
|
||||
echo ' <src-file> <dst-file>'
|
||||
echo ' mkln [-t|--trace] [-f|--force] [-s|--symbolic] <src-path>'
|
||||
echo ' [<src-path> ...] <dst-path>'
|
||||
echo ' mkshadow [-v|--verbose] [-t|--trace] [-a|--all] <src-dir> <dst-dir>'
|
||||
echo ' fixperm [-v|--verbose] [-t|--trace] <path> [<path> ...]'
|
||||
echo ' rotate [-v|--verbose] [-t|--trace] [-f|--force] [-n|--num-files'
|
||||
echo ' <count>] [-s|--size <size>] [-c|--copy] [-r|--remove]'
|
||||
echo ' [-a|--archive-dir <dir>] [-z|--compress [<tool>:]<level>]'
|
||||
echo ' [-b|--background] [-d|--delay] [-p|--pad <len>] [-o|--owner'
|
||||
echo ' <owner>] [-g|--group <group>] [-m|--mode <mode>] [-M|--migrate'
|
||||
echo ' <cmd>] [-P|--prolog <cmd>] [-E|--epilog <cmd>] <file> [...]'
|
||||
echo ' tarball [-t|--trace] [-v|--verbose] [-o|--output <tarball>]'
|
||||
echo ' [-c|--compress <prog>] [-d|--directory <dir>] [-u|--user'
|
||||
echo ' <user>] [-g|--group <group>] [-e|--exclude <pattern>]'
|
||||
echo ' <path> [<path> ...]'
|
||||
echo ' subst [-v|--verbose] [-t|--trace] [-n|--nop] [-s|--stealth]'
|
||||
echo ' [-i|--interactive] [-b|--backup <ext>] [-e|--exec <cmd>]'
|
||||
echo ' [-f|--file <cmd-file>] [<file>] [...]'
|
||||
echo ' mdate [-n] [-z] [-s] [-d] [-f<str>] [-o<spec>] <path>'
|
||||
echo ' table [-F<sep>] [-w<width>] [-c<cols>] [-s<strip>] <str><sep><str>...'
|
||||
echo ' prop [-p<str>]'
|
||||
echo ' move [-v] [-t] [-e] [-p] <src-file> <dst-file>'
|
||||
echo ' mkln [-t] [-f] [-s] <src-path> [<src-path> ...] <dst-path>'
|
||||
echo ' mkshadow [-v] [-t] [-a] <src-dir> <dst-dir>'
|
||||
echo ' fixperm [-v] [-t] <path> [<path> ...]'
|
||||
echo ' tarball [-t] [-v] [-o<tarball>] [-c<prog>] [-d<dir>] [-u<user>]'
|
||||
echo ' [-g<group>] [-e<pattern>] <path> [<path> ...]'
|
||||
echo ' guessos '
|
||||
echo ' arx [-t|--trace] [-C|--command <cmd>] <op> <archive> [<file>'
|
||||
echo ' ...]'
|
||||
echo ' slo [-p|--prefix <str>] -- -L<dir> -l<lib> [-L<dir> -l<lib>'
|
||||
echo ' ...]'
|
||||
echo ' scpp [-v|--verbose] [-p|--preserve] [-f|--filter <filter>]'
|
||||
echo ' [-o|--output <ofile>] [-t|--template <tfile>] [-M|--mark'
|
||||
echo ' <mark>] [-D|--define <dname>] [-C|--class <cname>]'
|
||||
echo ' <file> [<file> ...]'
|
||||
echo ' version [-l|--language <lang>] [-n|--name <name>] [-p|--prefix'
|
||||
echo ' <prefix>] [-s|--set <version>] [-e|--edit] [-i|--increase'
|
||||
echo ' <knob>] [-d|--display <type>] <file>'
|
||||
echo ' arx [-t] [-C<cmd>] <op> <archive> [<file> ...]'
|
||||
echo ' slo [-p<str>] -- -L<dir> -l<lib> [-L<dir> -l<lib> ...]'
|
||||
echo ' scpp [-v] [-p] [-f<filter>] [-o<ofile>] [-t<tfile>] [-M<mark>]'
|
||||
echo ' [-D<dname>] [-C<cname>] <file> [<file> ...]'
|
||||
echo ' version [-l<lang>] [-n<name>] [-p<prefix>] [-s<version>] [-e]'
|
||||
echo ' [-i<knob>] [-d<type>] <file>'
|
||||
echo ' path [-s] [-r] [-d] [-b] [-m] [-p<path>] <str> [<str> ...]'
|
||||
echo ''
|
||||
exit 0
|
||||
fi
|
||||
if [ ".$1" = ".-v" -o ".$1" = ."--version" ]; then
|
||||
echo "GNU shtool 1.6.2 (02-Nov-2002)"
|
||||
echo "GNU shtool 1.5.4 (14-Jun-2001)"
|
||||
exit 0
|
||||
fi
|
||||
if [ ".$1" = ".-r" -o ".$1" = ."--recreate" ]; then
|
||||
shtoolize -oshtool echo install mkdir path
|
||||
shtoolize -ofoo echo install mkdir
|
||||
exit 0
|
||||
fi
|
||||
if [ ".$1" = ".-d" -o ".$1" = ."--debug" ]; then
|
||||
@@ -145,7 +118,7 @@ if [ ".$1" = ".-d" -o ".$1" = ."--debug" ]; then
|
||||
fi
|
||||
name=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'`
|
||||
case "$name" in
|
||||
echo|install|mkdir|path )
|
||||
echo|install|mkdir )
|
||||
# implicit tool command selection
|
||||
tool="$name"
|
||||
;;
|
||||
@@ -166,22 +139,19 @@ gen_tmpfile=no
|
||||
case $tool in
|
||||
echo )
|
||||
str_tool="echo"
|
||||
str_usage="[-n|--newline] [-e|--expand] [<str> ...]"
|
||||
str_usage="[-n] [-e] [<str> ...]"
|
||||
arg_spec="0+"
|
||||
opt_spec="n.e."
|
||||
opt_alias="n:newline,e:expand"
|
||||
opt_n=no
|
||||
opt_e=no
|
||||
;;
|
||||
install )
|
||||
str_tool="install"
|
||||
str_usage="[-v|--verbose] [-t|--trace] [-d|--mkdir] [-c|--copy] [-C|--compare-copy] [-s|--strip] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] [-e|--exec <sed-cmd>] <file> [<file> ...] <path>"
|
||||
arg_spec="1+"
|
||||
opt_spec="v.t.d.c.C.s.m:o:g:e+"
|
||||
opt_alias="v:verbose,t:trace,d:mkdir,c:copy,C:compare-copy,s:strip,m:mode,o:owner,g:group,e:exec"
|
||||
str_usage="[-v] [-t] [-c] [-C] [-s] [-m<mode>] [-o<owner>] [-g<group>] [-e<sed-cmd>] <file> [<file> ...] <path>"
|
||||
arg_spec="2+"
|
||||
opt_spec="v.t.c.C.s.m:o:g:e+"
|
||||
opt_v=no
|
||||
opt_t=no
|
||||
opt_d=no
|
||||
opt_c=no
|
||||
opt_C=no
|
||||
opt_s=no
|
||||
@@ -192,30 +162,13 @@ case $tool in
|
||||
;;
|
||||
mkdir )
|
||||
str_tool="mkdir"
|
||||
str_usage="[-t|--trace] [-f|--force] [-p|--parents] [-m|--mode <mode>] [-o|--owner <owner>] [-g|--group <group>] <dir> [<dir> ...]"
|
||||
str_usage="[-t] [-f] [-p] [-m<mode>] <dir> [<dir> ...]"
|
||||
arg_spec="1+"
|
||||
opt_spec="t.f.p.m:o:g:"
|
||||
opt_alias="t:trace,f:force,p:parents,m:mode,o:owner,g:group"
|
||||
opt_spec="t.f.p.m:"
|
||||
opt_t=no
|
||||
opt_f=no
|
||||
opt_p=no
|
||||
opt_m=""
|
||||
opt_o=""
|
||||
opt_g=""
|
||||
;;
|
||||
path )
|
||||
str_tool="path"
|
||||
str_usage="[-s|--suppress] [-r|--reverse] [-d|--dirname] [-b|--basename] [-m|--magic] [-p|--path <path>] <str> [<str> ...]"
|
||||
gen_tmpfile=yes
|
||||
arg_spec="1+"
|
||||
opt_spec="s.r.d.b.m.p:"
|
||||
opt_alias="s:suppress,r:reverse,d:dirname,b:basename,m:magic,p:path"
|
||||
opt_s=no
|
||||
opt_r=no
|
||||
opt_d=no
|
||||
opt_b=no
|
||||
opt_m=no
|
||||
opt_p="$PATH"
|
||||
;;
|
||||
-* )
|
||||
echo "$0:Error: unknown option \`$tool'" 2>&1
|
||||
@@ -233,11 +186,6 @@ esac
|
||||
## COMMON UTILITY CODE
|
||||
##
|
||||
|
||||
# commonly used ASCII values
|
||||
ASC_TAB=" "
|
||||
ASC_NL="
|
||||
"
|
||||
|
||||
# determine name of tool
|
||||
if [ ".$tool" != . ]; then
|
||||
# used inside shtool script
|
||||
@@ -259,10 +207,6 @@ eval `echo $arg_spec |\
|
||||
eval `echo h.$opt_spec |\
|
||||
sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'`
|
||||
|
||||
# parse option alias string
|
||||
eval `echo h:help,$opt_alias |\
|
||||
tr 'x-' 'x_' | sed -e 's/\([a-zA-Z0-9]\):\([^,]*\),*/opt_ALIAS_\2=\1;/g'`
|
||||
|
||||
# interate over argument line
|
||||
opt_PREV=''
|
||||
while [ $# -gt 0 ]; do
|
||||
@@ -283,18 +227,6 @@ while [ $# -gt 0 ]; do
|
||||
else
|
||||
# split argument into option and argument
|
||||
case "$1" in
|
||||
--[a-zA-Z0-9]*=*)
|
||||
eval `echo "x$1" |\
|
||||
sed -e 's/^x--\([a-zA-Z0-9-]*\)=\(.*\)$/opt_OPT="\1";opt_ARG="\2"/'`
|
||||
opt_STR=`echo $opt_OPT | tr 'x-' 'x_'`
|
||||
eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
|
||||
;;
|
||||
--[a-zA-Z0-9]*)
|
||||
opt_OPT=`echo "x$1" | cut -c4-`
|
||||
opt_STR=`echo $opt_OPT | tr 'x-' 'x_'`
|
||||
eval "opt_OPT=\${opt_ALIAS_${opt_STR}-${opt_OPT}}"
|
||||
opt_ARG=''
|
||||
;;
|
||||
-[a-zA-Z0-9]*)
|
||||
eval `echo "x$1" |\
|
||||
sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \
|
||||
@@ -334,17 +266,17 @@ while [ $# -gt 0 ]; do
|
||||
;;
|
||||
'+' )
|
||||
# option with argument (multiple occurances append)
|
||||
eval "opt_${opt_OPT}=\"\$opt_${opt_OPT}\${ASC_NL}\$opt_ARG\""
|
||||
eval "opt_${opt_OPT}=\"\$opt_${opt_OPT} \$opt_ARG\""
|
||||
;;
|
||||
* )
|
||||
echo "$msgprefix:Error: unknown option: \`$opt_OPT'" 1>&2
|
||||
echo "$msgprefix:Error: unknown option: \`-$opt_OPT'" 1>&2
|
||||
echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [ ".$opt_PREV" != . ]; then
|
||||
echo "$msgprefix:Error: missing argument to option \`$opt_PREV'" 1>&2
|
||||
echo "$msgprefix:Error: missing argument to option \`-$opt_PREV'" 1>&2
|
||||
echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -397,7 +329,7 @@ case $tool in
|
||||
echo )
|
||||
##
|
||||
## echo -- Print string with optional construct expansion
|
||||
## Copyright (c) 1998-2002 Ralf S. Engelschall <rse@engelschall.com>
|
||||
## Copyright (c) 1998-2001 Ralf S. Engelschall <rse@engelschall.com>
|
||||
## Originally written for WML as buildinfo
|
||||
##
|
||||
|
||||
@@ -430,7 +362,7 @@ echo )
|
||||
term_bold=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' </dev/null 2>/dev/null`
|
||||
term_norm=`awk 'BEGIN { printf("%c%c%c", 27, 91, 109); }' </dev/null 2>/dev/null`
|
||||
;;
|
||||
vt100|vt100*|cygwin)
|
||||
vt100|vt100*)
|
||||
term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' </dev/null 2>/dev/null`
|
||||
term_norm=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' </dev/null 2>/dev/null`
|
||||
;;
|
||||
@@ -448,7 +380,7 @@ echo )
|
||||
fi
|
||||
done
|
||||
if [ ".$term_bold" != . ]; then
|
||||
for seq in sgr0 me rmso init reset; do # 'reset' is last
|
||||
for seq in sgr0 me rmso reset; do # 'reset' is last
|
||||
norm="`$dir/$tool $seq 2>/dev/null`"
|
||||
if [ ".$norm" != . ]; then
|
||||
term_norm="$norm"
|
||||
@@ -467,8 +399,6 @@ echo )
|
||||
esac
|
||||
if [ ".$term_bold" = . -o ".$term_norm" = . ]; then
|
||||
echo "$msgprefix:Warning: unable to determine terminal sequence for bold mode" 1>&2
|
||||
term_bold=''
|
||||
term_norm=''
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -568,13 +498,13 @@ echo )
|
||||
if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%d'`" != . ]; then
|
||||
if [ ".$domainname" = . ]; then
|
||||
if [ -f /etc/resolv.conf ]; then
|
||||
domainname="`egrep '^[ ]*domain' /etc/resolv.conf | sed -e 'q' |\
|
||||
domainname="`egrep '^[ ]*domain' /etc/resolv.conf | head -1 |\
|
||||
sed -e 's/.*domain//' \
|
||||
-e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
|
||||
-e 's/^\.//' -e 's/^/./' |\
|
||||
awk '{ printf("%s", $1); }'`"
|
||||
if [ ".$domainname" = . ]; then
|
||||
domainname="`egrep '^[ ]*search' /etc/resolv.conf | sed -e 'q' |\
|
||||
domainname="`egrep '^[ ]*search' /etc/resolv.conf | head -1 |\
|
||||
sed -e 's/.*search//' \
|
||||
-e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \
|
||||
-e 's/ .*//' -e 's/ .*//' \
|
||||
@@ -651,32 +581,10 @@ echo )
|
||||
install )
|
||||
##
|
||||
## install -- Install a program, script or datafile
|
||||
## Copyright (c) 1997-2002 Ralf S. Engelschall <rse@engelschall.com>
|
||||
## Copyright (c) 1997-2001 Ralf S. Engelschall <rse@engelschall.com>
|
||||
## Originally written for shtool
|
||||
##
|
||||
|
||||
# special case: "shtool install -d <dir> [...]" internally
|
||||
# maps to "shtool mkdir -f -p -m 755 <dir> [...]"
|
||||
if [ "$opt_d" = yes ]; then
|
||||
cmd="$0 mkdir -f -p -m 755"
|
||||
if [ ".$opt_o" != . ]; then
|
||||
cmd="$cmd -o '$opt_o'"
|
||||
fi
|
||||
if [ ".$opt_g" != . ]; then
|
||||
cmd="$cmd -g '$opt_g'"
|
||||
fi
|
||||
if [ ".$opt_v" = .yes ]; then
|
||||
cmd="$cmd -v"
|
||||
fi
|
||||
if [ ".$opt_t" = .yes ]; then
|
||||
cmd="$cmd -t"
|
||||
fi
|
||||
for dir in "$@"; do
|
||||
eval "$cmd $dir" || exit $?
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# determine source(s) and destination
|
||||
argc=$#
|
||||
srcs=""
|
||||
@@ -749,9 +657,7 @@ install )
|
||||
# adjust the target file
|
||||
if [ ".$opt_e" != . ]; then
|
||||
sed='sed'
|
||||
OIFS="$IFS"; IFS="$ASC_NL"; set -- $opt_e; IFS="$OIFS"
|
||||
for e
|
||||
do
|
||||
for e in $opt_e; do
|
||||
sed="$sed -e '$e'"
|
||||
done
|
||||
cp $dsttmp $dsttmp.old
|
||||
@@ -812,7 +718,7 @@ install )
|
||||
mkdir )
|
||||
##
|
||||
## mkdir -- Make one or more directories
|
||||
## Copyright (c) 1996-2002 Ralf S. Engelschall <rse@engelschall.com>
|
||||
## Copyright (c) 1996-2001 Ralf S. Engelschall <rse@engelschall.com>
|
||||
## Originally written for public domain by Noah Friedman <friedman@prep.ai.mit.edu>
|
||||
## Cleaned up and enhanced for shtool
|
||||
##
|
||||
@@ -835,18 +741,6 @@ mkdir )
|
||||
echo "mkdir $p" 1>&2
|
||||
fi
|
||||
mkdir $p || errstatus=$?
|
||||
if [ ".$opt_o" != . ]; then
|
||||
if [ ".$opt_t" = .yes ]; then
|
||||
echo "chown $opt_o $p" 1>&2
|
||||
fi
|
||||
chown $opt_o $p || errstatus=$?
|
||||
fi
|
||||
if [ ".$opt_g" != . ]; then
|
||||
if [ ".$opt_t" = .yes ]; then
|
||||
echo "chgrp $opt_g $p" 1>&2
|
||||
fi
|
||||
chgrp $opt_g $p || errstatus=$?
|
||||
fi
|
||||
if [ ".$opt_m" != . ]; then
|
||||
if [ ".$opt_t" = .yes ]; then
|
||||
echo "chmod $opt_m $p" 1>&2
|
||||
@@ -872,18 +766,6 @@ mkdir )
|
||||
echo "mkdir $pathcomp" 1>&2
|
||||
fi
|
||||
mkdir $pathcomp || errstatus=$?
|
||||
if [ ".$opt_o" != . ]; then
|
||||
if [ ".$opt_t" = .yes ]; then
|
||||
echo "chown $opt_o $pathcomp" 1>&2
|
||||
fi
|
||||
chown $opt_o $pathcomp || errstatus=$?
|
||||
fi
|
||||
if [ ".$opt_g" != . ]; then
|
||||
if [ ".$opt_t" = .yes ]; then
|
||||
echo "chgrp $opt_g $pathcomp" 1>&2
|
||||
fi
|
||||
chgrp $opt_g $pathcomp || errstatus=$?
|
||||
fi
|
||||
if [ ".$opt_m" != . ]; then
|
||||
if [ ".$opt_t" = .yes ]; then
|
||||
echo "chmod $opt_m $pathcomp" 1>&2
|
||||
@@ -898,147 +780,6 @@ mkdir )
|
||||
exit $errstatus
|
||||
;;
|
||||
|
||||
path )
|
||||
##
|
||||
## path -- Deal with program paths
|
||||
## Copyright (c) 1998-2002 Ralf S. Engelschall <rse@engelschall.com>
|
||||
## Originally written for Apache
|
||||
##
|
||||
|
||||
namelist="$*"
|
||||
|
||||
# check whether the test command supports the -x option
|
||||
if [ -x /bin/sh ] 2>/dev/null; then
|
||||
minusx="-x"
|
||||
else
|
||||
minusx="-r"
|
||||
fi
|
||||
|
||||
# split path string
|
||||
paths="`echo $opt_p |\
|
||||
sed -e 's/^:/.:/' \
|
||||
-e 's/::/:.:/g' \
|
||||
-e 's/:$/:./' \
|
||||
-e 's/:/ /g'`"
|
||||
|
||||
# SPECIAL REQUEST
|
||||
# translate forward to reverse path
|
||||
if [ ".$opt_r" = .yes ]; then
|
||||
if [ "x$namelist" = "x." ]; then
|
||||
rp='.'
|
||||
else
|
||||
rp=''
|
||||
for pe in `IFS="$IFS/"; echo $namelist`; do
|
||||
rp="../$rp"
|
||||
done
|
||||
fi
|
||||
echo $rp | sed -e 's:/$::'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# SPECIAL REQUEST
|
||||
# strip out directory or base name
|
||||
if [ ".$opt_d" = .yes ]; then
|
||||
echo "$namelist" |\
|
||||
sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;'
|
||||
exit 0
|
||||
fi
|
||||
if [ ".$opt_b" = .yes ]; then
|
||||
echo "$namelist" |\
|
||||
sed -e 's;.*/\([^/]*\)$;\1;'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# MAGIC SITUATION
|
||||
# Perl Interpreter (perl)
|
||||
if [ ".$opt_m" = .yes -a ".$namelist" = .perl ]; then
|
||||
rm -f $tmpfile >/dev/null 2>&1
|
||||
touch $tmpfile
|
||||
found=0
|
||||
pc=99
|
||||
for dir in $paths; do
|
||||
dir=`echo $dir | sed -e 's;/*$;;'`
|
||||
nc=99
|
||||
for name in perl perl5 miniperl; do
|
||||
if [ $minusx "$dir/$name" -a ! -d "$dir/$name" ]; then
|
||||
perl="$dir/$name"
|
||||
pv=`$perl -e 'printf("%.3f", $]);'`
|
||||
echo "$pv:$pc:$nc:$perl" >>$tmpfile
|
||||
found=1
|
||||
fi
|
||||
nc=`expr $nc - 1`
|
||||
done
|
||||
pc=`expr $pc - 1`
|
||||
done
|
||||
if [ $found = 1 ]; then
|
||||
perl="`cat $tmpfile | sort -r -u | sed -e 'q' | cut -d: -f4`"
|
||||
rm -f $tmpfile >/dev/null 2>&1
|
||||
echo "$perl"
|
||||
exit 0
|
||||
fi
|
||||
rm -f $tmpfile >/dev/null 2>&1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# MAGIC SITUATION
|
||||
# C pre-processor (cpp)
|
||||
if [ ".$opt_m" = .yes -a ".$namelist" = .cpp ]; then
|
||||
echo >$tmpfile.c "#include <assert.h>"
|
||||
echo >>$tmpfile.c "Syntax Error"
|
||||
# 1. try the standard cc -E approach
|
||||
cpp="${CC-cc} -E"
|
||||
(eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
|
||||
my_error=`grep -v '^ *+' $tmpfile.out`
|
||||
if [ ".$my_error" != . ]; then
|
||||
# 2. try the cc -E approach and GCC's -traditional-ccp option
|
||||
cpp="${CC-cc} -E -traditional-cpp"
|
||||
(eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
|
||||
my_error=`grep -v '^ *+' $tmpfile.out`
|
||||
if [ ".$my_error" != . ]; then
|
||||
# 3. try a standalone cpp command in path and lib dirs
|
||||
for path in $paths /lib /usr/lib /usr/local/lib; do
|
||||
path=`echo $path | sed -e 's;/*$;;'`
|
||||
if [ $minusx "$path/cpp" -a ! -d "$path/cpp" ]; then
|
||||
cpp="$path/cpp"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ ".$cpp" != . ]; then
|
||||
(eval "$cpp $tmpfile.c >/dev/null") 2>$tmpfile.out
|
||||
my_error=`grep -v '^ *+' $tmpfile.out`
|
||||
if [ ".$my_error" != . ]; then
|
||||
# ok, we gave up...
|
||||
cpp=''
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
rm -f $tmpfile >/dev/null 2>&1
|
||||
rm -f $tmpfile.c $tmpfile.out >/dev/null 2>&1
|
||||
if [ ".$cpp" != . ]; then
|
||||
echo "$cpp"
|
||||
exit 0
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# STANDARD SITUATION
|
||||
# iterate over names
|
||||
for name in $namelist; do
|
||||
# iterate over paths
|
||||
for path in $paths; do
|
||||
path=`echo $path | sed -e 's;/*$;;'`
|
||||
if [ $minusx "$path/$name" -a ! -d "$path/$name" ]; then
|
||||
if [ ".$opt_s" != .yes ]; then
|
||||
echo "$path/$name"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
done
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
exit 0
|
||||
|
||||
+6
-42
@@ -27,12 +27,8 @@ dnl ## Diversion 5 is the last one. Here we generate files and clean up.
|
||||
dnl Basic autoconf + automake initialization, generation of config.nice.
|
||||
dnl -------------------------------------------------------------------------
|
||||
|
||||
AC_PREREQ(2.13)
|
||||
AC_INIT(README.CVS-RULES)
|
||||
|
||||
dnl check for working sed
|
||||
PHP_PROG_SED
|
||||
|
||||
PHP_CONFIG_NICE(config.nice)
|
||||
for arg in $0 "$@"; do
|
||||
CONFIGURE_COMMAND="$CONFIGURE_COMMAND '$arg'"
|
||||
@@ -44,7 +40,7 @@ AC_CONFIG_HEADER(main/php_config.h)
|
||||
MAJOR_VERSION=4
|
||||
MINOR_VERSION=3
|
||||
RELEASE_VERSION=0
|
||||
EXTRA_VERSION="RC2"
|
||||
EXTRA_VERSION="-pre1"
|
||||
VERSION="$MAJOR_VERSION.$MINOR_VERSION.$RELEASE_VERSION$EXTRA_VERSION"
|
||||
|
||||
dnl Define where extension directories are located in the configure context
|
||||
@@ -158,12 +154,6 @@ if test "$ac_cv_c_const" = "yes" ; then
|
||||
LEX_CFLAGS="-DYY_USE_CONST"
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([flex version])
|
||||
set `$LEX -V | grep 'version' | cut -d ' ' -f 3 | sed -e 's/\./ /g' | sed -e 's/[^0-9 ]//g'`
|
||||
if test "${1}" != "2" -o "${2}" != "5" -o "${3}" -lt "4"; then
|
||||
AC_MSG_WARN(You will need flex 2.5.4 or later if you want to regenerate Zend/PHP lexical parsers.)
|
||||
fi
|
||||
AC_MSG_RESULT(${1}.${2}.${3} (ok))
|
||||
|
||||
dnl Platform-specific compile settings.
|
||||
dnl -------------------------------------------------------------------------
|
||||
@@ -233,7 +223,10 @@ PHP_CONFIGURE_PART(Configuring SAPI modules)
|
||||
|
||||
esyscmd(./scripts/config-stubs sapi)
|
||||
|
||||
dnl Show which main SAPI was selected
|
||||
if test "$PHP_SAPI" = "default"; then
|
||||
PHP_SELECT_SAPI(cgi, program, cgi_main.c getopt.c,,'$(SAPI_CGI_PATH)')
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([for chosen SAPI module])
|
||||
AC_MSG_RESULT([$PHP_SAPI])
|
||||
|
||||
@@ -285,10 +278,7 @@ PHP_CHECK_FUNC(gethostname, nsl)
|
||||
PHP_CHECK_FUNC(gethostbyaddr, nsl)
|
||||
PHP_CHECK_FUNC(yp_get_default_domain, nsl)
|
||||
|
||||
PHP_CHECK_FUNC(dlopen, dl)
|
||||
if test "$ac_cv_func_dlopen" = "yes"; then
|
||||
AC_DEFINE(HAVE_LIBDL, 1, [ ])
|
||||
fi
|
||||
AC_CHECK_LIB(dl, dlopen, [PHP_ADD_LIBRARY(dl)])
|
||||
AC_CHECK_LIB(m, sin)
|
||||
|
||||
dnl Check for resolver routines.
|
||||
@@ -334,7 +324,6 @@ limits.h \
|
||||
locale.h \
|
||||
monetary.h \
|
||||
mach-o/dyld.h \
|
||||
netdb.h \
|
||||
pwd.h \
|
||||
resolv.h \
|
||||
signal.h \
|
||||
@@ -360,7 +349,6 @@ unistd.h \
|
||||
unix.h \
|
||||
utime.h \
|
||||
sys/utsname.h \
|
||||
sys/ipc.h \
|
||||
],[],[],[
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
@@ -416,15 +404,6 @@ if test "$ac_cv_sockaddr_storage" = yes; then
|
||||
AC_DEFINE(HAVE_SOCKADDR_STORAGE,1,[Whether you have struct sockaddr_storage])
|
||||
fi
|
||||
|
||||
dnl Check if sockaddr data structure includes an "sa_len" member
|
||||
|
||||
AC_TRY_COMPILE([
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
], [static struct sockaddr sa; int n = (int) sa.sa_len; return n],
|
||||
[AC_DEFINE(HAVE_SOCKADDR_LEN,1,[Whether sockaddr struct has sa_len])],
|
||||
[])
|
||||
|
||||
dnl Check for IPv6 support
|
||||
AC_CACHE_CHECK([for IPv6 support], ac_cv_ipv6_support,
|
||||
[AC_TRY_LINK([ #include <sys/types.h>
|
||||
@@ -445,7 +424,6 @@ ctime_r \
|
||||
cuserid \
|
||||
crypt \
|
||||
flock \
|
||||
ftok \
|
||||
gai_strerror \
|
||||
gcvt \
|
||||
getlogin \
|
||||
@@ -822,7 +800,6 @@ dnl -------------------------------------------------------------------------
|
||||
|
||||
PHP_CONFIGURE_PART(Configuring Zend)
|
||||
LIBZEND_BASIC_CHECKS
|
||||
LIBZEND_DLSYM_CHECK
|
||||
LIBZEND_OTHER_CHECKS
|
||||
|
||||
TSRM_LIB='TSRM/libtsrm.la'
|
||||
@@ -1128,8 +1105,6 @@ PHP_ADD_MAKEFILE_FRAGMENT($abs_srcdir/Makefile.frag,$abs_srcdir/Zend,Zend)
|
||||
PHP_GEN_BUILD_DIRS
|
||||
PHP_GEN_GLOBAL_MAKEFILE
|
||||
|
||||
AC_DEFINE([HAVE_BUILD_DEFS_H], 1, [ ])
|
||||
|
||||
$php_shtool mkdir -p pear/scripts
|
||||
ALL_OUTPUT_FILES="php4.spec main/build-defs.h \
|
||||
pear/scripts/phpize pear/scripts/php-config \
|
||||
@@ -1235,17 +1210,6 @@ cat <<X
|
||||
X
|
||||
fi
|
||||
|
||||
if test "$PHP_DB" != "no"; then
|
||||
cat <<X
|
||||
+--------------------------------------------------------------------+
|
||||
| *** WARNING *** |
|
||||
| |
|
||||
| You chose to compile PHP with DB extension. This extension is |
|
||||
| deprecated and does not support databse locking correctly. Please |
|
||||
| use DBA extension which is a fully operational superset. |
|
||||
X
|
||||
fi
|
||||
|
||||
if test "$MYSQL_MODULE_TYPE" = "builtin" && test "$PHP_SAPI" != "cgi" && test "$PHP_SAPI" != "cli" && test "$php_multiple_shlib_versions_ok" != "yes"; then
|
||||
cat <<X
|
||||
+--------------------------------------------------------------------+
|
||||
|
||||
+63
-59
@@ -30,8 +30,6 @@
|
||||
#include "php_bcmath.h"
|
||||
#include "libbcmath/src/bcmath.h"
|
||||
|
||||
ZEND_DECLARE_MODULE_GLOBALS(bcmath);
|
||||
|
||||
function_entry bcmath_functions[] = {
|
||||
PHP_FE(bcadd, NULL)
|
||||
PHP_FE(bcsub, NULL)
|
||||
@@ -49,11 +47,7 @@ zend_module_entry bcmath_module_entry = {
|
||||
STANDARD_MODULE_HEADER,
|
||||
"bcmath",
|
||||
bcmath_functions,
|
||||
#if ZTS
|
||||
PHP_MODULE_STARTUP_N(bcmath),
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
NULL,
|
||||
PHP_RINIT(bcmath),
|
||||
PHP_RSHUTDOWN(bcmath),
|
||||
@@ -70,22 +64,32 @@ ZEND_GET_MODULE(bcmath)
|
||||
static long bc_precision;
|
||||
#endif
|
||||
|
||||
#if ZTS
|
||||
PHP_MODULE_STARTUP_D(bcmath)
|
||||
{
|
||||
zend_bcmath_globals *bcmath_globals;
|
||||
/* Storage used for special numbers. */
|
||||
extern bc_num _zero_;
|
||||
extern bc_num _one_;
|
||||
extern bc_num _two_;
|
||||
|
||||
ts_allocate_id(&bcmath_globals_id, sizeof(zend_bcmath_globals), NULL, NULL);
|
||||
bcmath_globals = ts_resource(bcmath_globals_id);
|
||||
return SUCCESS;
|
||||
|
||||
/* Make a copy of a number! Just increments the reference count! */
|
||||
bc_num copy_num (bc_num num)
|
||||
{
|
||||
num->n_refs++;
|
||||
return num;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Initialize a number NUM by making it a copy of zero. */
|
||||
void init_num (bc_num *num)
|
||||
{
|
||||
*num = copy_num (_zero_);
|
||||
}
|
||||
|
||||
|
||||
PHP_RSHUTDOWN_FUNCTION(bcmath)
|
||||
{
|
||||
bc_free_num(&BCG(_zero_));
|
||||
bc_free_num(&BCG(_one_));
|
||||
bc_free_num(&BCG(_two_));
|
||||
bc_free_num(&_zero_);
|
||||
bc_free_num(&_one_);
|
||||
bc_free_num(&_two_);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -97,7 +101,7 @@ PHP_RINIT_FUNCTION(bcmath)
|
||||
bc_precision=0;
|
||||
}
|
||||
|
||||
bc_init_numbers(TSRMLS_C);
|
||||
bc_init_numbers();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -137,11 +141,11 @@ PHP_FUNCTION(bcadd)
|
||||
}
|
||||
convert_to_string_ex(left);
|
||||
convert_to_string_ex(right);
|
||||
bc_init_num(&first TSRMLS_CC);
|
||||
bc_init_num(&second TSRMLS_CC);
|
||||
bc_init_num(&result TSRMLS_CC);
|
||||
bc_str2num(&first, Z_STRVAL_PP(left), scale TSRMLS_CC);
|
||||
bc_str2num(&second, Z_STRVAL_PP(right), scale TSRMLS_CC);
|
||||
bc_init_num(&first);
|
||||
bc_init_num(&second);
|
||||
bc_init_num(&result);
|
||||
bc_str2num(&first, Z_STRVAL_PP(left), scale);
|
||||
bc_str2num(&second, Z_STRVAL_PP(right), scale);
|
||||
bc_add (first, second, &result, scale);
|
||||
Z_STRVAL_P(return_value) = bc_num2str(result);
|
||||
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
|
||||
@@ -180,11 +184,11 @@ PHP_FUNCTION(bcsub)
|
||||
}
|
||||
convert_to_string_ex(left);
|
||||
convert_to_string_ex(right);
|
||||
bc_init_num(&first TSRMLS_CC);
|
||||
bc_init_num(&second TSRMLS_CC);
|
||||
bc_init_num(&result TSRMLS_CC);
|
||||
bc_str2num(&first, Z_STRVAL_PP(left), scale TSRMLS_CC);
|
||||
bc_str2num(&second, Z_STRVAL_PP(right), scale TSRMLS_CC);
|
||||
bc_init_num(&first);
|
||||
bc_init_num(&second);
|
||||
bc_init_num(&result);
|
||||
bc_str2num(&first, Z_STRVAL_PP(left), scale);
|
||||
bc_str2num(&second, Z_STRVAL_PP(right), scale);
|
||||
bc_sub (first, second, &result, scale);
|
||||
Z_STRVAL_P(return_value) = bc_num2str(result);
|
||||
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
|
||||
@@ -223,12 +227,12 @@ PHP_FUNCTION(bcmul)
|
||||
}
|
||||
convert_to_string_ex(left);
|
||||
convert_to_string_ex(right);
|
||||
bc_init_num(&first TSRMLS_CC);
|
||||
bc_init_num(&second TSRMLS_CC);
|
||||
bc_init_num(&result TSRMLS_CC);
|
||||
bc_str2num(&first, Z_STRVAL_PP(left), scale TSRMLS_CC);
|
||||
bc_str2num(&second, Z_STRVAL_PP(right), scale TSRMLS_CC);
|
||||
bc_multiply (first, second, &result, scale TSRMLS_CC);
|
||||
bc_init_num(&first);
|
||||
bc_init_num(&second);
|
||||
bc_init_num(&result);
|
||||
bc_str2num(&first, Z_STRVAL_PP(left), scale);
|
||||
bc_str2num(&second, Z_STRVAL_PP(right), scale);
|
||||
bc_multiply (first, second, &result, scale);
|
||||
Z_STRVAL_P(return_value) = bc_num2str(result);
|
||||
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
|
||||
Z_TYPE_P(return_value) = IS_STRING;
|
||||
@@ -266,12 +270,12 @@ PHP_FUNCTION(bcdiv)
|
||||
}
|
||||
convert_to_string_ex(left);
|
||||
convert_to_string_ex(right);
|
||||
bc_init_num(&first TSRMLS_CC);
|
||||
bc_init_num(&second TSRMLS_CC);
|
||||
bc_init_num(&result TSRMLS_CC);
|
||||
bc_str2num(&first, Z_STRVAL_PP(left), scale TSRMLS_CC);
|
||||
bc_str2num(&second, Z_STRVAL_PP(right), scale TSRMLS_CC);
|
||||
switch (bc_divide (first, second, &result, scale TSRMLS_CC)) {
|
||||
bc_init_num(&first);
|
||||
bc_init_num(&second);
|
||||
bc_init_num(&result);
|
||||
bc_str2num(&first, Z_STRVAL_PP(left), scale);
|
||||
bc_str2num(&second, Z_STRVAL_PP(right), scale);
|
||||
switch (bc_divide (first, second, &result, scale)) {
|
||||
case 0: /* OK */
|
||||
Z_STRVAL_P(return_value) = bc_num2str(result);
|
||||
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
|
||||
@@ -307,12 +311,12 @@ PHP_FUNCTION(bcmod)
|
||||
}
|
||||
convert_to_string_ex(left);
|
||||
convert_to_string_ex(right);
|
||||
bc_init_num(&first TSRMLS_CC);
|
||||
bc_init_num(&second TSRMLS_CC);
|
||||
bc_init_num(&result TSRMLS_CC);
|
||||
bc_str2num(&first, Z_STRVAL_PP(left), 0 TSRMLS_CC);
|
||||
bc_str2num(&second, Z_STRVAL_PP(right), 0 TSRMLS_CC);
|
||||
switch (bc_modulo(first, second, &result, 0 TSRMLS_CC)) {
|
||||
bc_init_num(&first);
|
||||
bc_init_num(&second);
|
||||
bc_init_num(&result);
|
||||
bc_str2num(&first, Z_STRVAL_PP(left), 0);
|
||||
bc_str2num(&second, Z_STRVAL_PP(right), 0);
|
||||
switch (bc_modulo(first, second, &result, 0)) {
|
||||
case 0:
|
||||
Z_STRVAL_P(return_value) = bc_num2str(result);
|
||||
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
|
||||
@@ -356,12 +360,12 @@ PHP_FUNCTION(bcpow)
|
||||
}
|
||||
convert_to_string_ex(left);
|
||||
convert_to_string_ex(right);
|
||||
bc_init_num(&first TSRMLS_CC);
|
||||
bc_init_num(&second TSRMLS_CC);
|
||||
bc_init_num(&result TSRMLS_CC);
|
||||
bc_str2num(&first, Z_STRVAL_PP(left), scale TSRMLS_CC);
|
||||
bc_str2num(&second, Z_STRVAL_PP(right), scale TSRMLS_CC);
|
||||
bc_raise (first, second, &result, scale TSRMLS_CC);
|
||||
bc_init_num(&first);
|
||||
bc_init_num(&second);
|
||||
bc_init_num(&result);
|
||||
bc_str2num(&first, Z_STRVAL_PP(left), scale);
|
||||
bc_str2num(&second, Z_STRVAL_PP(right), scale);
|
||||
bc_raise (first, second, &result, scale);
|
||||
Z_STRVAL_P(return_value) = bc_num2str(result);
|
||||
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
|
||||
Z_TYPE_P(return_value) = IS_STRING;
|
||||
@@ -398,9 +402,9 @@ PHP_FUNCTION(bcsqrt)
|
||||
break;
|
||||
}
|
||||
convert_to_string_ex(left);
|
||||
bc_init_num(&result TSRMLS_CC);
|
||||
bc_str2num(&result, Z_STRVAL_PP(left), scale TSRMLS_CC);
|
||||
if (bc_sqrt (&result, scale TSRMLS_CC) != 0) {
|
||||
bc_init_num(&result);
|
||||
bc_str2num(&result, Z_STRVAL_PP(left), scale);
|
||||
if (bc_sqrt (&result, scale) != 0) {
|
||||
Z_STRVAL_P(return_value) = bc_num2str(result);
|
||||
Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value));
|
||||
Z_TYPE_P(return_value) = IS_STRING;
|
||||
@@ -440,11 +444,11 @@ PHP_FUNCTION(bccomp)
|
||||
|
||||
convert_to_string_ex(left);
|
||||
convert_to_string_ex(right);
|
||||
bc_init_num(&first TSRMLS_CC);
|
||||
bc_init_num(&second TSRMLS_CC);
|
||||
bc_init_num(&first);
|
||||
bc_init_num(&second);
|
||||
|
||||
bc_str2num(&first, Z_STRVAL_PP(left), scale TSRMLS_CC);
|
||||
bc_str2num(&second, Z_STRVAL_PP(right), scale TSRMLS_CC);
|
||||
bc_str2num(&first, Z_STRVAL_PP(left), scale);
|
||||
bc_str2num(&second, Z_STRVAL_PP(right), scale);
|
||||
Z_LVAL_P(return_value) = bc_compare(first, second);
|
||||
Z_TYPE_P(return_value) = IS_LONG;
|
||||
|
||||
|
||||
@@ -52,9 +52,6 @@ typedef struct bc_struct
|
||||
in the case of leading zeros generated. */
|
||||
} bc_struct;
|
||||
|
||||
#include <php.h>
|
||||
#include <ext/bcmath/php_bcmath.h>
|
||||
|
||||
|
||||
/* The base used in storing the numbers in n_value above.
|
||||
Currently this MUST be 10. */
|
||||
@@ -84,6 +81,12 @@ typedef struct bc_struct
|
||||
#endif
|
||||
|
||||
|
||||
/* Global numbers. */
|
||||
extern bc_num _zero_;
|
||||
extern bc_num _one_;
|
||||
extern bc_num _two_;
|
||||
|
||||
|
||||
/* Function Prototypes */
|
||||
|
||||
/* Define the _PROTOTYPE macro if it is needed. */
|
||||
@@ -96,7 +99,7 @@ typedef struct bc_struct
|
||||
#endif
|
||||
#endif
|
||||
|
||||
_PROTOTYPE(void bc_init_numbers, (TSRMLS_D));
|
||||
_PROTOTYPE(void bc_init_numbers, (void));
|
||||
|
||||
_PROTOTYPE(bc_num bc_new_num, (int length, int scale));
|
||||
|
||||
@@ -104,9 +107,9 @@ _PROTOTYPE(void bc_free_num, (bc_num *num));
|
||||
|
||||
_PROTOTYPE(bc_num bc_copy_num, (bc_num num));
|
||||
|
||||
_PROTOTYPE(void bc_init_num, (bc_num *num TSRMLS_DC));
|
||||
_PROTOTYPE(void bc_init_num, (bc_num *num));
|
||||
|
||||
_PROTOTYPE(void bc_str2num, (bc_num *num, char *str, int scale TSRMLS_DC));
|
||||
_PROTOTYPE(void bc_str2num, (bc_num *num, char *str, int scale));
|
||||
|
||||
_PROTOTYPE(char *bc_num2str, (bc_num num));
|
||||
|
||||
@@ -116,7 +119,7 @@ _PROTOTYPE(long bc_num2long, (bc_num num));
|
||||
|
||||
_PROTOTYPE(int bc_compare, (bc_num n1, bc_num n2));
|
||||
|
||||
_PROTOTYPE(char bc_is_zero, (bc_num num TSRMLS_DC));
|
||||
_PROTOTYPE(char bc_is_zero, (bc_num num));
|
||||
|
||||
_PROTOTYPE(char bc_is_near_zero, (bc_num num, int scale));
|
||||
|
||||
@@ -126,26 +129,26 @@ _PROTOTYPE(void bc_add, (bc_num n1, bc_num n2, bc_num *result, int scale_min));
|
||||
|
||||
_PROTOTYPE(void bc_sub, (bc_num n1, bc_num n2, bc_num *result, int scale_min));
|
||||
|
||||
_PROTOTYPE(void bc_multiply, (bc_num n1, bc_num n2, bc_num *prod, int scale TSRMLS_DC));
|
||||
_PROTOTYPE(void bc_multiply, (bc_num n1, bc_num n2, bc_num *prod, int scale));
|
||||
|
||||
_PROTOTYPE(int bc_divide, (bc_num n1, bc_num n2, bc_num *quot, int scale TSRMLS_DC));
|
||||
_PROTOTYPE(int bc_divide, (bc_num n1, bc_num n2, bc_num *quot, int scale));
|
||||
|
||||
_PROTOTYPE(int bc_modulo, (bc_num num1, bc_num num2, bc_num *result,
|
||||
int scale TSRMLS_DC));
|
||||
int scale));
|
||||
|
||||
_PROTOTYPE(int bc_divmod, (bc_num num1, bc_num num2, bc_num *quot,
|
||||
bc_num *rem, int scale TSRMLS_DC));
|
||||
bc_num *rem, int scale));
|
||||
|
||||
_PROTOTYPE(int bc_raisemod, (bc_num base, bc_num expo, bc_num mod,
|
||||
bc_num *result, int scale TSRMLS_DC));
|
||||
bc_num *result, int scale));
|
||||
|
||||
_PROTOTYPE(void bc_raise, (bc_num num1, bc_num num2, bc_num *result,
|
||||
int scale TSRMLS_DC));
|
||||
int scale));
|
||||
|
||||
_PROTOTYPE(int bc_sqrt, (bc_num *num, int scale TSRMLS_DC));
|
||||
_PROTOTYPE(int bc_sqrt, (bc_num *num, int scale));
|
||||
|
||||
_PROTOTYPE(void bc_out_num, (bc_num num, int o_base, void (* out_char)(int),
|
||||
int leading_zero TSRMLS_DC));
|
||||
int leading_zero));
|
||||
|
||||
/* Prototypes needed for external utility routines. */
|
||||
|
||||
|
||||
@@ -48,9 +48,10 @@ out_char (int c)
|
||||
|
||||
|
||||
void
|
||||
pn (bc_num num TSRMLS_DC)
|
||||
pn (num)
|
||||
bc_num num;
|
||||
{
|
||||
bc_out_num (num, 10, out_char, 0 TSRMLS_CC);
|
||||
bc_out_num (num, 10, out_char, 0);
|
||||
out_char ('\n');
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,9 @@ _one_mult (num, size, digit, result)
|
||||
by zero is tried. The algorithm is found in Knuth Vol 2. p237. */
|
||||
|
||||
int
|
||||
bc_divide (bc_num n1, bc_num n2, bc_num *quot, int scale TSRMLS_DC)
|
||||
bc_divide (n1, n2, quot, scale)
|
||||
bc_num n1, n2, *quot;
|
||||
int scale;
|
||||
{
|
||||
bc_num qval;
|
||||
unsigned char *num1, *num2;
|
||||
@@ -98,7 +100,7 @@ bc_divide (bc_num n1, bc_num n2, bc_num *quot, int scale TSRMLS_DC)
|
||||
unsigned int norm;
|
||||
|
||||
/* Test for divide by zero. */
|
||||
if (bc_is_zero (n2 TSRMLS_CC)) return -1;
|
||||
if (bc_is_zero (n2)) return -1;
|
||||
|
||||
/* Test for divide by 1. If it is we must truncate. */
|
||||
if (n2->n_scale == 0)
|
||||
@@ -259,7 +261,7 @@ bc_divide (bc_num n1, bc_num n2, bc_num *quot, int scale TSRMLS_DC)
|
||||
|
||||
/* Clean up and return the number. */
|
||||
qval->n_sign = ( n1->n_sign == n2->n_sign ? PLUS : MINUS );
|
||||
if (bc_is_zero (qval TSRMLS_CC)) qval->n_sign = PLUS;
|
||||
if (bc_is_zero (qval)) qval->n_sign = PLUS;
|
||||
_bc_rm_leading_zeros (qval);
|
||||
bc_free_num (quot);
|
||||
*quot = qval;
|
||||
|
||||
@@ -45,24 +45,26 @@
|
||||
*/
|
||||
|
||||
int
|
||||
bc_divmod (bc_num num1, bc_num num2, bc_num *quot, bc_num *rem, int scale TSRMLS_DC)
|
||||
bc_divmod (num1, num2, quot, rem, scale)
|
||||
bc_num num1, num2, *quot, *rem;
|
||||
int scale;
|
||||
{
|
||||
bc_num quotient = NULL;
|
||||
bc_num temp;
|
||||
int rscale;
|
||||
|
||||
/* Check for correct numbers. */
|
||||
if (bc_is_zero (num2 TSRMLS_CC)) return -1;
|
||||
if (bc_is_zero (num2)) return -1;
|
||||
|
||||
/* Calculate final scale. */
|
||||
rscale = MAX (num1->n_scale, num2->n_scale+scale);
|
||||
bc_init_num(&temp TSRMLS_CC);
|
||||
bc_init_num(&temp);
|
||||
|
||||
/* Calculate it. */
|
||||
bc_divide (num1, num2, &temp, scale TSRMLS_CC);
|
||||
bc_divide (num1, num2, &temp, scale);
|
||||
if (quot)
|
||||
quotient = bc_copy_num (temp);
|
||||
bc_multiply (temp, num2, &temp, rscale TSRMLS_CC);
|
||||
bc_multiply (temp, num2, &temp, rscale);
|
||||
bc_sub (num1, temp, rem, rscale);
|
||||
bc_free_num (&temp);
|
||||
|
||||
@@ -80,8 +82,10 @@ bc_divmod (bc_num num1, bc_num num2, bc_num *quot, bc_num *rem, int scale TSRMLS
|
||||
result in RESULT. */
|
||||
|
||||
int
|
||||
bc_modulo (bc_num num1, bc_num num2, bc_num *result, int scale TSRMLS_DC)
|
||||
bc_modulo (num1, num2, result, scale)
|
||||
bc_num num1, num2, *result;
|
||||
int scale;
|
||||
{
|
||||
return bc_divmod (num1, num2, NULL, result, scale TSRMLS_CC);
|
||||
return bc_divmod (num1, num2, NULL, result, scale);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,11 @@
|
||||
#include "bcmath.h"
|
||||
#include "private.h"
|
||||
|
||||
/* Storage used for special numbers. */
|
||||
bc_num _zero_;
|
||||
bc_num _one_;
|
||||
bc_num _two_;
|
||||
|
||||
bc_num _bc_Free_list = NULL;
|
||||
|
||||
/* new_num allocates a number and sets fields to known values. */
|
||||
@@ -98,20 +103,21 @@ bc_free_num (num)
|
||||
/* Intitialize the number package! */
|
||||
|
||||
void
|
||||
bc_init_numbers (TSRMLS_D)
|
||||
bc_init_numbers ()
|
||||
{
|
||||
BCG(_zero_) = bc_new_num (1,0);
|
||||
BCG(_one_) = bc_new_num (1,0);
|
||||
BCG(_one_)->n_value[0] = 1;
|
||||
BCG(_two_) = bc_new_num (1,0);
|
||||
BCG(_two_)->n_value[0] = 2;
|
||||
_zero_ = bc_new_num (1,0);
|
||||
_one_ = bc_new_num (1,0);
|
||||
_one_->n_value[0] = 1;
|
||||
_two_ = bc_new_num (1,0);
|
||||
_two_->n_value[0] = 2;
|
||||
}
|
||||
|
||||
|
||||
/* Make a copy of a number! Just increments the reference count! */
|
||||
|
||||
bc_num
|
||||
bc_copy_num (bc_num num)
|
||||
bc_copy_num (num)
|
||||
bc_num num;
|
||||
{
|
||||
num->n_refs++;
|
||||
return num;
|
||||
@@ -121,8 +127,9 @@ bc_copy_num (bc_num num)
|
||||
/* Initialize a number NUM by making it a copy of zero. */
|
||||
|
||||
void
|
||||
bc_init_num (bc_num *num TSRMLS_DC)
|
||||
bc_init_num (num)
|
||||
bc_num *num;
|
||||
{
|
||||
*num = bc_copy_num (BCG(_zero_));
|
||||
*num = bc_copy_num (_zero_);
|
||||
}
|
||||
|
||||
@@ -86,11 +86,15 @@ bc_out_long (val, size, space, out_char)
|
||||
as the routine to do the actual output of the characters. */
|
||||
|
||||
void
|
||||
bc_out_num (num, o_base, out_char, leading_zero)
|
||||
bc_num num;
|
||||
int o_base;
|
||||
#ifdef __STDC__
|
||||
bc_out_num (bc_num num, int o_base, void (*out_char)(int), int leading_zero TSRMLS_DC)
|
||||
void (*out_char)(int);
|
||||
#else
|
||||
bc_out_num (bc_num num, int o_base, void (*out_char)(), int leading_zero TSRMLS_DC)
|
||||
void (*out_char)();
|
||||
#endif
|
||||
int leading_zero;
|
||||
{
|
||||
char *nptr;
|
||||
int index, fdigit, pre_space;
|
||||
@@ -101,7 +105,7 @@ bc_out_num (bc_num num, int o_base, void (*out_char)(), int leading_zero TSRMLS_
|
||||
if (num->n_sign == MINUS) (*out_char) ('-');
|
||||
|
||||
/* Output the number. */
|
||||
if (bc_is_zero (num TSRMLS_CC))
|
||||
if (bc_is_zero (num))
|
||||
(*out_char) ('0');
|
||||
else
|
||||
if (o_base == 10)
|
||||
@@ -114,7 +118,7 @@ bc_out_num (bc_num num, int o_base, void (*out_char)(), int leading_zero TSRMLS_
|
||||
else
|
||||
nptr++;
|
||||
|
||||
if (leading_zero && bc_is_zero (num TSRMLS_CC))
|
||||
if (leading_zero && bc_is_zero (num))
|
||||
(*out_char) ('0');
|
||||
|
||||
/* Now the fraction. */
|
||||
@@ -128,36 +132,36 @@ bc_out_num (bc_num num, int o_base, void (*out_char)(), int leading_zero TSRMLS_
|
||||
else
|
||||
{
|
||||
/* special case ... */
|
||||
if (leading_zero && bc_is_zero (num TSRMLS_CC))
|
||||
if (leading_zero && bc_is_zero (num))
|
||||
(*out_char) ('0');
|
||||
|
||||
/* The number is some other base. */
|
||||
digits = NULL;
|
||||
bc_init_num (&int_part TSRMLS_CC);
|
||||
bc_divide (num, BCG(_one_), &int_part, 0 TSRMLS_CC);
|
||||
bc_init_num (&frac_part TSRMLS_CC);
|
||||
bc_init_num (&cur_dig TSRMLS_CC);
|
||||
bc_init_num (&base TSRMLS_CC);
|
||||
bc_init_num (&int_part);
|
||||
bc_divide (num, _one_, &int_part, 0);
|
||||
bc_init_num (&frac_part);
|
||||
bc_init_num (&cur_dig);
|
||||
bc_init_num (&base);
|
||||
bc_sub (num, int_part, &frac_part, 0);
|
||||
/* Make the INT_PART and FRAC_PART positive. */
|
||||
int_part->n_sign = PLUS;
|
||||
frac_part->n_sign = PLUS;
|
||||
bc_int2num (&base, o_base);
|
||||
bc_init_num (&max_o_digit TSRMLS_CC);
|
||||
bc_init_num (&max_o_digit);
|
||||
bc_int2num (&max_o_digit, o_base-1);
|
||||
|
||||
|
||||
/* Get the digits of the integer part and push them on a stack. */
|
||||
while (!bc_is_zero (int_part TSRMLS_CC))
|
||||
while (!bc_is_zero (int_part))
|
||||
{
|
||||
bc_modulo (int_part, base, &cur_dig, 0 TSRMLS_CC);
|
||||
bc_modulo (int_part, base, &cur_dig, 0);
|
||||
/* PHP Change: malloc() -> emalloc() */
|
||||
temp = (stk_rec *) emalloc (sizeof(stk_rec));
|
||||
if (temp == NULL) bc_out_of_memory();
|
||||
temp->digit = bc_num2long (cur_dig);
|
||||
temp->next = digits;
|
||||
digits = temp;
|
||||
bc_divide (int_part, base, &int_part, 0 TSRMLS_CC);
|
||||
bc_divide (int_part, base, &int_part, 0);
|
||||
}
|
||||
|
||||
/* Print the digits on the stack. */
|
||||
@@ -181,9 +185,9 @@ bc_out_num (bc_num num, int o_base, void (*out_char)(), int leading_zero TSRMLS_
|
||||
{
|
||||
(*out_char) ('.');
|
||||
pre_space = 0;
|
||||
t_num = bc_copy_num (BCG(_one_));
|
||||
t_num = bc_copy_num (_one_);
|
||||
while (t_num->n_len <= num->n_scale) {
|
||||
bc_multiply (frac_part, base, &frac_part, num->n_scale TSRMLS_CC);
|
||||
bc_multiply (frac_part, base, &frac_part, num->n_scale);
|
||||
fdigit = bc_num2long (frac_part);
|
||||
bc_int2num (&int_part, fdigit);
|
||||
bc_sub (frac_part, int_part, &frac_part, 0);
|
||||
@@ -193,7 +197,7 @@ bc_out_num (bc_num num, int o_base, void (*out_char)(), int leading_zero TSRMLS_
|
||||
bc_out_long (fdigit, max_o_digit->n_len, pre_space, out_char);
|
||||
pre_space = 1;
|
||||
}
|
||||
bc_multiply (t_num, base, &t_num, 0 TSRMLS_CC);
|
||||
bc_multiply (t_num, base, &t_num, 0);
|
||||
}
|
||||
bc_free_num (&t_num);
|
||||
}
|
||||
|
||||
@@ -44,7 +44,9 @@
|
||||
only the integer part is used. */
|
||||
|
||||
void
|
||||
bc_raise (bc_num num1, bc_num num2, bc_num *result, int scale TSRMLS_DC)
|
||||
bc_raise (num1, num2, result, scale)
|
||||
bc_num num1, num2, *result;
|
||||
int scale;
|
||||
{
|
||||
bc_num temp, power;
|
||||
long exponent;
|
||||
@@ -64,7 +66,7 @@ bc_raise (bc_num num1, bc_num num2, bc_num *result, int scale TSRMLS_DC)
|
||||
if (exponent == 0)
|
||||
{
|
||||
bc_free_num (result);
|
||||
*result = bc_copy_num (BCG(_one_));
|
||||
*result = bc_copy_num (_one_);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -87,7 +89,7 @@ bc_raise (bc_num num1, bc_num num2, bc_num *result, int scale TSRMLS_DC)
|
||||
while ((exponent & 1) == 0)
|
||||
{
|
||||
pwrscale = 2*pwrscale;
|
||||
bc_multiply (power, power, &power, pwrscale TSRMLS_CC);
|
||||
bc_multiply (power, power, &power, pwrscale);
|
||||
exponent = exponent >> 1;
|
||||
}
|
||||
temp = bc_copy_num (power);
|
||||
@@ -98,10 +100,10 @@ bc_raise (bc_num num1, bc_num num2, bc_num *result, int scale TSRMLS_DC)
|
||||
while (exponent > 0)
|
||||
{
|
||||
pwrscale = 2*pwrscale;
|
||||
bc_multiply (power, power, &power, pwrscale TSRMLS_CC);
|
||||
bc_multiply (power, power, &power, pwrscale);
|
||||
if ((exponent & 1) == 1) {
|
||||
calcscale = pwrscale + calcscale;
|
||||
bc_multiply (temp, power, &temp, calcscale TSRMLS_CC);
|
||||
bc_multiply (temp, power, &temp, calcscale);
|
||||
}
|
||||
exponent = exponent >> 1;
|
||||
}
|
||||
@@ -109,7 +111,7 @@ bc_raise (bc_num num1, bc_num num2, bc_num *result, int scale TSRMLS_DC)
|
||||
/* Assign the value. */
|
||||
if (neg)
|
||||
{
|
||||
bc_divide (BCG(_one_), temp, result, rscale TSRMLS_CC);
|
||||
bc_divide (_one_, temp, result, rscale);
|
||||
bc_free_num (&temp);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -43,20 +43,22 @@
|
||||
only the integer part is used. */
|
||||
|
||||
int
|
||||
bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, int scale TSRMLS_DC)
|
||||
bc_raisemod (base, expo, mod, result, scale)
|
||||
bc_num base, expo, mod, *result;
|
||||
int scale;
|
||||
{
|
||||
bc_num power, exponent, parity, temp;
|
||||
int rscale;
|
||||
|
||||
/* Check for correct numbers. */
|
||||
if (bc_is_zero(mod TSRMLS_CC)) return -1;
|
||||
if (bc_is_zero(mod)) return -1;
|
||||
if (bc_is_neg(expo)) return -1;
|
||||
|
||||
/* Set initial values. */
|
||||
power = bc_copy_num (base);
|
||||
exponent = bc_copy_num (expo);
|
||||
temp = bc_copy_num (BCG(_one_));
|
||||
bc_init_num(&parity TSRMLS_CC);
|
||||
temp = bc_copy_num (_one_);
|
||||
bc_init_num(&parity);
|
||||
|
||||
/* Check the base for scale digits. */
|
||||
if (base->n_scale != 0)
|
||||
@@ -66,7 +68,7 @@ bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, int scale TSR
|
||||
if (exponent->n_scale != 0)
|
||||
{
|
||||
bc_rt_warn ("non-zero scale in exponent");
|
||||
bc_divide (exponent, BCG(_one_), &exponent, 0 TSRMLS_CC); /*truncate */
|
||||
bc_divide (exponent, _one_, &exponent, 0); /*truncate */
|
||||
}
|
||||
|
||||
/* Check the modulus for scale digits. */
|
||||
@@ -75,17 +77,17 @@ bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, int scale TSR
|
||||
|
||||
/* Do the calculation. */
|
||||
rscale = MAX(scale, base->n_scale);
|
||||
while ( !bc_is_zero(exponent TSRMLS_CC) )
|
||||
while ( !bc_is_zero(exponent) )
|
||||
{
|
||||
(void) bc_divmod (exponent, BCG(_two_), &exponent, &parity, 0 TSRMLS_CC);
|
||||
if ( !bc_is_zero(parity TSRMLS_CC) )
|
||||
(void) bc_divmod (exponent, _two_, &exponent, &parity, 0);
|
||||
if ( !bc_is_zero(parity) )
|
||||
{
|
||||
bc_multiply (temp, power, &temp, rscale TSRMLS_CC);
|
||||
(void) bc_modulo (temp, mod, &temp, scale TSRMLS_CC);
|
||||
bc_multiply (temp, power, &temp, rscale);
|
||||
(void) bc_modulo (temp, mod, &temp, scale);
|
||||
}
|
||||
|
||||
bc_multiply (power, power, &power, rscale TSRMLS_CC);
|
||||
(void) bc_modulo (power, mod, &power, scale TSRMLS_CC);
|
||||
bc_multiply (power, power, &power, rscale);
|
||||
(void) bc_modulo (power, mod, &power, scale);
|
||||
}
|
||||
|
||||
/* Assign the value. */
|
||||
|
||||
@@ -176,7 +176,7 @@ _bc_shift_addsub (bc_num accum, bc_num val, int shift, int sub)
|
||||
*/
|
||||
static void
|
||||
_bc_rec_mul (bc_num u, int ulen, bc_num v, int vlen, bc_num *prod,
|
||||
int full_scale TSRMLS_DC)
|
||||
int full_scale)
|
||||
{
|
||||
bc_num u0, u1, v0, v1;
|
||||
int u0len, v0len;
|
||||
@@ -197,14 +197,14 @@ _bc_rec_mul (bc_num u, int ulen, bc_num v, int vlen, bc_num *prod,
|
||||
|
||||
/* Split u and v. */
|
||||
if (ulen < n) {
|
||||
u1 = bc_copy_num (BCG(_zero_));
|
||||
u1 = bc_copy_num (_zero_);
|
||||
u0 = new_sub_num (ulen,0, u->n_value);
|
||||
} else {
|
||||
u1 = new_sub_num (ulen-n, 0, u->n_value);
|
||||
u0 = new_sub_num (n, 0, u->n_value+ulen-n);
|
||||
}
|
||||
if (vlen < n) {
|
||||
v1 = bc_copy_num (BCG(_zero_));
|
||||
v1 = bc_copy_num (_zero_);
|
||||
v0 = new_sub_num (vlen,0, v->n_value);
|
||||
} else {
|
||||
v1 = new_sub_num (vlen-n, 0, v->n_value);
|
||||
@@ -217,12 +217,12 @@ _bc_rec_mul (bc_num u, int ulen, bc_num v, int vlen, bc_num *prod,
|
||||
_bc_rm_leading_zeros (v0);
|
||||
v0len = v0->n_len;
|
||||
|
||||
m1zero = bc_is_zero(u1 TSRMLS_CC) || bc_is_zero(v1 TSRMLS_CC);
|
||||
m1zero = bc_is_zero(u1) || bc_is_zero(v1);
|
||||
|
||||
/* Calculate sub results ... */
|
||||
|
||||
bc_init_num(&d1 TSRMLS_CC);
|
||||
bc_init_num(&d2 TSRMLS_CC);
|
||||
bc_init_num(&d1);
|
||||
bc_init_num(&d2);
|
||||
bc_sub (u1, u0, &d1, 0);
|
||||
d1len = d1->n_len;
|
||||
bc_sub (v0, v1, &d2, 0);
|
||||
@@ -231,19 +231,19 @@ _bc_rec_mul (bc_num u, int ulen, bc_num v, int vlen, bc_num *prod,
|
||||
|
||||
/* Do recursive multiplies and shifted adds. */
|
||||
if (m1zero)
|
||||
m1 = bc_copy_num (BCG(_zero_));
|
||||
m1 = bc_copy_num (_zero_);
|
||||
else
|
||||
_bc_rec_mul (u1, u1->n_len, v1, v1->n_len, &m1, 0 TSRMLS_CC);
|
||||
_bc_rec_mul (u1, u1->n_len, v1, v1->n_len, &m1, 0);
|
||||
|
||||
if (bc_is_zero(d1 TSRMLS_CC) || bc_is_zero(d2 TSRMLS_CC))
|
||||
m2 = bc_copy_num (BCG(_zero_));
|
||||
if (bc_is_zero(d1) || bc_is_zero(d2))
|
||||
m2 = bc_copy_num (_zero_);
|
||||
else
|
||||
_bc_rec_mul (d1, d1len, d2, d2len, &m2, 0 TSRMLS_CC);
|
||||
_bc_rec_mul (d1, d1len, d2, d2len, &m2, 0);
|
||||
|
||||
if (bc_is_zero(u0 TSRMLS_CC) || bc_is_zero(v0 TSRMLS_CC))
|
||||
m3 = bc_copy_num (BCG(_zero_));
|
||||
if (bc_is_zero(u0) || bc_is_zero(v0))
|
||||
m3 = bc_copy_num (_zero_);
|
||||
else
|
||||
_bc_rec_mul (u0, u0->n_len, v0, v0->n_len, &m3, 0 TSRMLS_CC);
|
||||
_bc_rec_mul (u0, u0->n_len, v0, v0->n_len, &m3, 0);
|
||||
|
||||
/* Initialize product */
|
||||
prodlen = ulen+vlen+1;
|
||||
@@ -274,7 +274,9 @@ _bc_rec_mul (bc_num u, int ulen, bc_num v, int vlen, bc_num *prod,
|
||||
*/
|
||||
|
||||
void
|
||||
bc_multiply (bc_num n1, bc_num n2, bc_num *prod, int scale TSRMLS_DC)
|
||||
bc_multiply (n1, n2, prod, scale)
|
||||
bc_num n1, n2, *prod;
|
||||
int scale;
|
||||
{
|
||||
bc_num pval;
|
||||
int len1, len2;
|
||||
@@ -287,7 +289,7 @@ bc_multiply (bc_num n1, bc_num n2, bc_num *prod, int scale TSRMLS_DC)
|
||||
prod_scale = MIN(full_scale,MAX(scale,MAX(n1->n_scale,n2->n_scale)));
|
||||
|
||||
/* Do the multiply */
|
||||
_bc_rec_mul (n1, len1, n2, len2, &pval, full_scale TSRMLS_CC);
|
||||
_bc_rec_mul (n1, len1, n2, len2, &pval, full_scale);
|
||||
|
||||
/* Assign to prod and clean up the number. */
|
||||
pval->n_sign = ( n1->n_sign == n2->n_sign ? PLUS : MINUS );
|
||||
@@ -295,7 +297,7 @@ bc_multiply (bc_num n1, bc_num n2, bc_num *prod, int scale TSRMLS_DC)
|
||||
pval->n_len = len2 + len1 + 1 - full_scale;
|
||||
pval->n_scale = prod_scale;
|
||||
_bc_rm_leading_zeros (pval);
|
||||
if (bc_is_zero (pval TSRMLS_CC))
|
||||
if (bc_is_zero (pval))
|
||||
pval->n_sign = PLUS;
|
||||
bc_free_num (prod);
|
||||
*prod = pval;
|
||||
|
||||
@@ -42,14 +42,16 @@
|
||||
after the decimal place. */
|
||||
|
||||
int
|
||||
bc_sqrt (bc_num *num, int scale TSRMLS_DC)
|
||||
bc_sqrt (num, scale)
|
||||
bc_num *num;
|
||||
int scale;
|
||||
{
|
||||
int rscale, cmp_res, done;
|
||||
int cscale;
|
||||
bc_num guess, guess1, point5, diff;
|
||||
|
||||
/* Initial checks. */
|
||||
cmp_res = bc_compare (*num, BCG(_zero_));
|
||||
cmp_res = bc_compare (*num, _zero_);
|
||||
if (cmp_res < 0)
|
||||
return 0; /* error */
|
||||
else
|
||||
@@ -57,23 +59,23 @@ bc_sqrt (bc_num *num, int scale TSRMLS_DC)
|
||||
if (cmp_res == 0)
|
||||
{
|
||||
bc_free_num (num);
|
||||
*num = bc_copy_num (BCG(_zero_));
|
||||
*num = bc_copy_num (_zero_);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
cmp_res = bc_compare (*num, BCG(_one_));
|
||||
cmp_res = bc_compare (*num, _one_);
|
||||
if (cmp_res == 0)
|
||||
{
|
||||
bc_free_num (num);
|
||||
*num = bc_copy_num (BCG(_one_));
|
||||
*num = bc_copy_num (_one_);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Initialize the variables. */
|
||||
rscale = MAX (scale, (*num)->n_scale);
|
||||
bc_init_num(&guess TSRMLS_CC);
|
||||
bc_init_num(&guess1 TSRMLS_CC);
|
||||
bc_init_num(&diff TSRMLS_CC);
|
||||
bc_init_num(&guess);
|
||||
bc_init_num(&guess1);
|
||||
bc_init_num(&diff);
|
||||
point5 = bc_new_num (1,1);
|
||||
point5->n_value[1] = 5;
|
||||
|
||||
@@ -82,7 +84,7 @@ bc_sqrt (bc_num *num, int scale TSRMLS_DC)
|
||||
if (cmp_res < 0)
|
||||
{
|
||||
/* The number is between 0 and 1. Guess should start at 1. */
|
||||
guess = bc_copy_num (BCG(_one_));
|
||||
guess = bc_copy_num (_one_);
|
||||
cscale = (*num)->n_scale;
|
||||
}
|
||||
else
|
||||
@@ -91,9 +93,9 @@ bc_sqrt (bc_num *num, int scale TSRMLS_DC)
|
||||
bc_int2num (&guess,10);
|
||||
|
||||
bc_int2num (&guess1,(*num)->n_len);
|
||||
bc_multiply (guess1, point5, &guess1, 0 TSRMLS_CC);
|
||||
bc_multiply (guess1, point5, &guess1, 0);
|
||||
guess1->n_scale = 0;
|
||||
bc_raise (guess, guess1, &guess, 0 TSRMLS_CC);
|
||||
bc_raise (guess, guess1, &guess, 0);
|
||||
bc_free_num (&guess1);
|
||||
cscale = 3;
|
||||
}
|
||||
@@ -104,9 +106,9 @@ bc_sqrt (bc_num *num, int scale TSRMLS_DC)
|
||||
{
|
||||
bc_free_num (&guess1);
|
||||
guess1 = bc_copy_num (guess);
|
||||
bc_divide (*num, guess, &guess, cscale TSRMLS_CC);
|
||||
bc_divide (*num, guess, &guess, cscale);
|
||||
bc_add (guess, guess1, &guess, 0);
|
||||
bc_multiply (guess, point5, &guess, cscale TSRMLS_CC);
|
||||
bc_multiply (guess, point5, &guess, cscale);
|
||||
bc_sub (guess, guess1, &diff, cscale+1);
|
||||
if (bc_is_near_zero (diff, cscale))
|
||||
{
|
||||
@@ -119,7 +121,7 @@ bc_sqrt (bc_num *num, int scale TSRMLS_DC)
|
||||
|
||||
/* Assign the number and clean up. */
|
||||
bc_free_num (num);
|
||||
bc_divide (guess,BCG(_one_),num,rscale TSRMLS_CC);
|
||||
bc_divide (guess,_one_,num,rscale);
|
||||
bc_free_num (&guess);
|
||||
bc_free_num (&guess1);
|
||||
bc_free_num (&point5);
|
||||
|
||||
@@ -41,7 +41,10 @@
|
||||
/* Convert strings to bc numbers. Base 10 only.*/
|
||||
|
||||
void
|
||||
bc_str2num (bc_num *num, char *str, int scale TSRMLS_DC)
|
||||
bc_str2num (num, str, scale)
|
||||
bc_num *num;
|
||||
char *str;
|
||||
int scale;
|
||||
{
|
||||
int digits, strscale;
|
||||
char *ptr, *nptr;
|
||||
@@ -62,7 +65,7 @@ bc_str2num (bc_num *num, char *str, int scale TSRMLS_DC)
|
||||
while (isdigit((int)*ptr)) ptr++, strscale++; /* digits */
|
||||
if ((*ptr != '\0') || (digits+strscale == 0))
|
||||
{
|
||||
*num = bc_copy_num (BCG(_zero_));
|
||||
*num = bc_copy_num (_zero_);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,13 +41,14 @@
|
||||
/* In some places we need to check if the number NUM is zero. */
|
||||
|
||||
char
|
||||
bc_is_zero (bc_num num TSRMLS_DC)
|
||||
bc_is_zero (num)
|
||||
bc_num num;
|
||||
{
|
||||
int count;
|
||||
char *nptr;
|
||||
|
||||
/* Quick check. */
|
||||
if (num == BCG(_zero_)) return TRUE;
|
||||
if (num == _zero_) return TRUE;
|
||||
|
||||
/* Initialize */
|
||||
count = num->n_len + num->n_scale;
|
||||
|
||||
@@ -23,30 +23,9 @@
|
||||
|
||||
#if WITH_BCMATH
|
||||
|
||||
#include "libbcmath/src/bcmath.h"
|
||||
|
||||
ZEND_BEGIN_MODULE_GLOBALS(bcmath)
|
||||
bc_num _zero_;
|
||||
bc_num _one_;
|
||||
bc_num _two_;
|
||||
ZEND_END_MODULE_GLOBALS(bcmath)
|
||||
|
||||
#if ZTS
|
||||
# define BCG(v) TSRMG(bcmath_globals_id, zend_bcmath_globals *, v)
|
||||
extern int bcmath_globals_id;
|
||||
#else
|
||||
# define BCG(v) (bcmath_globals.v)
|
||||
extern zend_bcmath_globals bcmath_globals;
|
||||
#endif
|
||||
|
||||
#define BC
|
||||
|
||||
extern zend_module_entry bcmath_module_entry;
|
||||
#define phpext_bcmath_ptr &bcmath_module_entry
|
||||
|
||||
#if ZTS
|
||||
PHP_MINIT_FUNCTION(bcmath);
|
||||
#endif
|
||||
PHP_RINIT_FUNCTION(bcmath);
|
||||
PHP_RSHUTDOWN_FUNCTION(bcmath);
|
||||
PHP_MINFO_FUNCTION(bcmath);
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
--TEST--
|
||||
bcadd() function
|
||||
--SKIP--
|
||||
<?php if(!extension_loaded("bcmath")) print "skip"; ?>
|
||||
--INI--
|
||||
bcmath.scale=0
|
||||
--FILE--
|
||||
<?php
|
||||
echo bcadd("1", "2"),"\n";
|
||||
echo bcadd("-1", "5", 4),"\n";
|
||||
echo bcadd("1928372132132819737213", "8728932001983192837219398127471", 2),"\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
3
|
||||
4.0000
|
||||
8728932003911564969352217864684.00
|
||||
@@ -1,18 +0,0 @@
|
||||
--TEST--
|
||||
bccomp() function
|
||||
--SKIP--
|
||||
<?php if(!extension_loaded("bcmath")) print "skip"; ?>
|
||||
--INI--
|
||||
bcmath.scale=0
|
||||
--FILE--
|
||||
<?php
|
||||
echo bccomp("-1", "5", 4),"\n";
|
||||
echo bccomp("1928372132132819737213", "8728932001983192837219398127471"),"\n";
|
||||
echo bccomp("1.00000000000000000001", "1", 2),"\n";
|
||||
echo bccomp("97321", "2321"),"\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
-1
|
||||
-1
|
||||
0
|
||||
1
|
||||
@@ -1,18 +0,0 @@
|
||||
--TEST--
|
||||
bcdiv() function
|
||||
--SKIP--
|
||||
<?php if(!extension_loaded("bcmath")) print "skip"; ?>
|
||||
--INI--
|
||||
bcmath.scale=0
|
||||
--FILE--
|
||||
<?php
|
||||
echo bcdiv("1", "2"),"\n";
|
||||
echo bcdiv("1", "2", 2),"\n";
|
||||
echo bcdiv("-1", "5", 4),"\n";
|
||||
echo bcdiv("8728932001983192837219398127471", "1928372132132819737213", 2),"\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
0
|
||||
0.50
|
||||
-0.2000
|
||||
4526580661.75
|
||||
@@ -1,16 +0,0 @@
|
||||
--TEST--
|
||||
bcmod() function
|
||||
--SKIP--
|
||||
<?php if(!extension_loaded("bcmath")) print "skip"; ?>
|
||||
--INI--
|
||||
bcmath.scale=0
|
||||
--FILE--
|
||||
<?php
|
||||
echo bcmod("11", "2"),"\n";
|
||||
echo bcmod("-1", "5"),"\n";
|
||||
echo bcmod("8728932001983192837219398127471", "1928372132132819737213"),"\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
1
|
||||
-1
|
||||
1459434331351930289678
|
||||
@@ -1,18 +0,0 @@
|
||||
--TEST--
|
||||
bcmul() function
|
||||
--SKIP--
|
||||
<?php if(!extension_loaded("bcmath")) print "skip"; ?>
|
||||
--INI--
|
||||
bcmath.scale=0
|
||||
--FILE--
|
||||
<?php
|
||||
echo bcmul("1", "2"),"\n";
|
||||
echo bcmul("-3", "5"),"\n";
|
||||
echo bcmul("1234567890", "9876543210"),"\n";
|
||||
echo bcmul("2.5", "1.5", 2),"\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
2
|
||||
-15
|
||||
12193263111263526900
|
||||
3.75
|
||||
@@ -1,16 +0,0 @@
|
||||
--TEST--
|
||||
bcpow() function
|
||||
--SKIP--
|
||||
<?php if(!extension_loaded("bcmath")) print "skip"; ?>
|
||||
--INI--
|
||||
bcmath.scale=0
|
||||
--FILE--
|
||||
<?php
|
||||
echo bcpow("1", "2"),"\n";
|
||||
echo bcpow("-2", "5", 4),"\n";
|
||||
echo bcpow("2", "64"),"\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
1
|
||||
-32
|
||||
18446744073709551616
|
||||
@@ -1,21 +0,0 @@
|
||||
--TEST--
|
||||
bcscale() function
|
||||
--SKIP--
|
||||
<?php if(!extension_loaded("bcmath")) print "skip"; ?>
|
||||
--INI--
|
||||
bcmath.scale=0
|
||||
--FILE--
|
||||
<?php
|
||||
echo bcadd("1", "2"),"\n";
|
||||
bcscale(2);
|
||||
echo bcadd("1", "2"),"\n";
|
||||
bcscale(10);
|
||||
echo bcadd("1", "2"),"\n";
|
||||
bcscale(0);
|
||||
echo bcadd("1", "2"),"\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
3
|
||||
3.00
|
||||
3.0000000000
|
||||
3
|
||||
@@ -1,14 +0,0 @@
|
||||
--TEST--
|
||||
bcsqrt() function
|
||||
--SKIP--
|
||||
<?php if(!extension_loaded("bcmath")) print "skip"; ?>
|
||||
--INI--
|
||||
bcmath.scale=0
|
||||
--FILE--
|
||||
<?php
|
||||
echo bcsqrt("9"),"\n";
|
||||
echo bcsqrt("1928372132132819737213", 5),"\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
3
|
||||
43913234134.28826
|
||||
@@ -1,16 +0,0 @@
|
||||
--TEST--
|
||||
bcsub() function
|
||||
--SKIP--
|
||||
<?php if(!extension_loaded("bcmath")) print "skip"; ?>
|
||||
--INI--
|
||||
bcmath.scale=0
|
||||
--FILE--
|
||||
<?php
|
||||
echo bcsub("1", "2"),"\n";
|
||||
echo bcsub("-1", "5", 4),"\n";
|
||||
echo bcsub("8728932001983192837219398127471", "1928372132132819737213", 2),"\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
-1
|
||||
-6.0000
|
||||
8728932000054820705086578390258.00
|
||||
+39
-133
@@ -33,8 +33,6 @@
|
||||
#include "php_calendar.h"
|
||||
#include "sdncal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
function_entry calendar_functions[] = {
|
||||
PHP_FE(jdtogregorian, NULL)
|
||||
PHP_FE(gregoriantojd, NULL)
|
||||
@@ -87,15 +85,15 @@ typedef long int (*cal_to_jd_func_t)(int month, int day, int year);
|
||||
typedef void (*cal_from_jd_func_t)(long int jd, int* year, int* month, int* day);
|
||||
typedef char* (*cal_as_string_func_t)(int year, int month, int day);
|
||||
|
||||
struct cal_entry_t {
|
||||
char *name;
|
||||
char *symbol;
|
||||
cal_to_jd_func_t to_jd;
|
||||
cal_from_jd_func_t from_jd;
|
||||
int num_months;
|
||||
int max_days_in_month;
|
||||
char **month_name_short;
|
||||
char **month_name_long;
|
||||
struct cal_entry_t {
|
||||
char * name;
|
||||
char * symbol;
|
||||
cal_to_jd_func_t to_jd;
|
||||
cal_from_jd_func_t from_jd;
|
||||
int num_months;
|
||||
int max_days_in_month;
|
||||
char ** month_name_short;
|
||||
char ** month_name_long;
|
||||
};
|
||||
static struct cal_entry_t cal_conversion_table[CAL_NUM_CALS] = {
|
||||
{ "Gregorian", "CAL_GREGORIAN", GregorianToSdn, SdnToGregorian, 12, 31, MonthNameShort, MonthNameLong },
|
||||
@@ -110,9 +108,6 @@ enum { CAL_DOW_DAYNO, CAL_DOW_SHORT, CAL_DOW_LONG };
|
||||
enum { CAL_MONTH_GREGORIAN_SHORT, CAL_MONTH_GREGORIAN_LONG,
|
||||
CAL_MONTH_JULIAN_SHORT, CAL_MONTH_JULIAN_LONG, CAL_MONTH_JEWISH,
|
||||
CAL_MONTH_FRENCH };
|
||||
|
||||
/* for heb_number_to_chars */
|
||||
static char alef_bet[25] = "0àáâãäåæçèéëìîðñòôö÷øùú";
|
||||
|
||||
PHP_MINIT_FUNCTION(calendar)
|
||||
{
|
||||
@@ -142,9 +137,9 @@ PHP_MINIT_FUNCTION(calendar)
|
||||
|
||||
PHP_MINFO_FUNCTION(calendar)
|
||||
{
|
||||
php_info_print_table_start();
|
||||
php_info_print_table_row(2, "Calendar support", "enabled");
|
||||
php_info_print_table_end();
|
||||
php_info_print_table_start();
|
||||
php_info_print_table_row(2, "Calendar support", "enabled");
|
||||
php_info_print_table_end();
|
||||
}
|
||||
|
||||
/* {{{ proto array cal_info(int calendar)
|
||||
@@ -156,11 +151,11 @@ PHP_FUNCTION(cal_info)
|
||||
int i;
|
||||
struct cal_entry_t * calendar;
|
||||
|
||||
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &cal) != SUCCESS) {
|
||||
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &cal) != SUCCESS) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
convert_to_long_ex(cal);
|
||||
if (Z_LVAL_PP(cal) < 0 || Z_LVAL_PP(cal) >= CAL_NUM_CALS) {
|
||||
if (Z_LVAL_PP(cal) < 0 || Z_LVAL_PP(cal) >= CAL_NUM_CALS) {
|
||||
zend_error(E_WARNING, "%s(): invalid calendar ID %d", get_active_function_name(TSRMLS_C), Z_LVAL_PP(cal));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
@@ -173,7 +168,7 @@ PHP_FUNCTION(cal_info)
|
||||
array_init(months);
|
||||
array_init(smonths);
|
||||
|
||||
for (i=1; i<= calendar->num_months; i++) {
|
||||
for (i=1; i<= calendar->num_months; i++) {
|
||||
add_index_string(months, i, calendar->month_name_long[i], 1);
|
||||
add_index_string(smonths, i, calendar->month_name_short[i], 1);
|
||||
}
|
||||
@@ -194,7 +189,7 @@ PHP_FUNCTION(cal_days_in_month)
|
||||
struct cal_entry_t * calendar;
|
||||
long sdn_start, sdn_next;
|
||||
|
||||
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &cal, &month, &year) != SUCCESS) {
|
||||
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &cal, &month, &year) != SUCCESS) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
@@ -202,7 +197,7 @@ PHP_FUNCTION(cal_days_in_month)
|
||||
convert_to_long_ex(month);
|
||||
convert_to_long_ex(year);
|
||||
|
||||
if (Z_LVAL_PP(cal) < 0 || Z_LVAL_PP(cal) >= CAL_NUM_CALS) {
|
||||
if (Z_LVAL_PP(cal) < 0 || Z_LVAL_PP(cal) >= CAL_NUM_CALS) {
|
||||
zend_error(E_WARNING, "%s(): invalid calendar ID %d", get_active_function_name(TSRMLS_C), Z_LVAL_PP(cal));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
@@ -229,7 +224,7 @@ PHP_FUNCTION(cal_to_jd)
|
||||
zval ** cal, **month, **day, **year;
|
||||
long jdate;
|
||||
|
||||
if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &cal, &month, &day, &year) != SUCCESS) {
|
||||
if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &cal, &month, &day, &year) != SUCCESS) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
@@ -238,7 +233,7 @@ PHP_FUNCTION(cal_to_jd)
|
||||
convert_to_long_ex(day);
|
||||
convert_to_long_ex(year);
|
||||
|
||||
if (Z_LVAL_PP(cal) < 0 || Z_LVAL_PP(cal) >= CAL_NUM_CALS) {
|
||||
if (Z_LVAL_PP(cal) < 0 || Z_LVAL_PP(cal) >= CAL_NUM_CALS) {
|
||||
zend_error(E_WARNING, "%s(): invalid calendar ID %d", get_active_function_name(TSRMLS_C), Z_LVAL_PP(cal));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
@@ -258,13 +253,13 @@ PHP_FUNCTION(cal_from_jd)
|
||||
char date[16];
|
||||
struct cal_entry_t * calendar;
|
||||
|
||||
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &jd, &cal) != SUCCESS) {
|
||||
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &jd, &cal) != SUCCESS) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
convert_to_long_ex(jd);
|
||||
convert_to_long_ex(cal);
|
||||
|
||||
if (Z_LVAL_PP(cal) < 0 || Z_LVAL_PP(cal) >= CAL_NUM_CALS) {
|
||||
if (Z_LVAL_PP(cal) < 0 || Z_LVAL_PP(cal) >= CAL_NUM_CALS) {
|
||||
zend_error(E_WARNING, "%s(): invalid calendar ID %d", get_active_function_name(TSRMLS_C), Z_LVAL_PP(cal));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
@@ -316,7 +311,7 @@ PHP_FUNCTION(jdtogregorian)
|
||||
|
||||
/* {{{ proto int gregoriantojd(int month, int day, int year)
|
||||
Converts a gregorian calendar date to julian day count */
|
||||
PHP_FUNCTION(gregoriantojd)
|
||||
PHP_FUNCTION(gregoriantojd)
|
||||
{
|
||||
pval **year, **month, **day;
|
||||
int jdate;
|
||||
@@ -337,7 +332,7 @@ PHP_FUNCTION(gregoriantojd)
|
||||
|
||||
/* {{{ proto string jdtojulian(int juliandaycount)
|
||||
Convert a julian day count to a julian calendar date */
|
||||
PHP_FUNCTION(jdtojulian)
|
||||
PHP_FUNCTION(jdtojulian)
|
||||
{
|
||||
pval **julday;
|
||||
int year, month, day;
|
||||
@@ -357,7 +352,7 @@ PHP_FUNCTION(jdtojulian)
|
||||
|
||||
/* {{{ proto int juliantojd(int month, int day, int year)
|
||||
Converts a julian calendar date to julian day count */
|
||||
PHP_FUNCTION(juliantojd)
|
||||
PHP_FUNCTION(juliantojd)
|
||||
{
|
||||
pval **year, **month, **day;
|
||||
int jdate;
|
||||
@@ -376,119 +371,30 @@ PHP_FUNCTION(juliantojd)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/*
|
||||
caution: the hebrew format product non unique result.
|
||||
for example both: year '5' and year '5000' product 'ä'.
|
||||
use the numeric one for calculations.
|
||||
*/
|
||||
static char* heb_number_to_chars(int n)
|
||||
{
|
||||
char *p, *old, *ret;
|
||||
|
||||
p = emalloc(10);
|
||||
old = p;
|
||||
|
||||
/*
|
||||
prevents the option breaking the jewish beliefs, and some other
|
||||
critical resources ;)
|
||||
*/
|
||||
if (n > 9999 || n < 1)
|
||||
return NULL;
|
||||
|
||||
/* alafim case */
|
||||
if (n / 1000) {
|
||||
*p = alef_bet[n / 1000];
|
||||
p++;
|
||||
n = n % 1000;
|
||||
}
|
||||
|
||||
/* taf-taf case */
|
||||
while (n >= 400) {
|
||||
*p = alef_bet[22];
|
||||
p++;
|
||||
n-=400;
|
||||
}
|
||||
|
||||
/* meot case */
|
||||
if (n >= 100) {
|
||||
*p = alef_bet[18+n/100];
|
||||
p++;
|
||||
n = n % 100;
|
||||
}
|
||||
|
||||
/* tet-vav tet-zain case */
|
||||
if (n == 15 || n == 16) {
|
||||
*p = alef_bet[9];
|
||||
p++;
|
||||
*p = alef_bet[n-9];
|
||||
p++;
|
||||
} else {
|
||||
/* asarot case */
|
||||
if (n >= 10) {
|
||||
*p = alef_bet[9+n/10];
|
||||
p++;
|
||||
n = n % 10;
|
||||
}
|
||||
|
||||
/* yeihot case */
|
||||
if (n > 0) {
|
||||
*p = alef_bet[n];
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
*p = '\0';
|
||||
ret = emalloc((int) (p - old) + 1);
|
||||
strncpy(ret, old, (int) (p - old) + 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* {{{ proto string jdtojewish(int juliandaycount)
|
||||
Converts a julian day count to a jewish calendar date */
|
||||
PHP_FUNCTION(jdtojewish)
|
||||
PHP_FUNCTION(jdtojewish)
|
||||
{
|
||||
long julday, fl;
|
||||
pval **julday;
|
||||
int year, month, day;
|
||||
char date[10], hebdate[25];
|
||||
|
||||
if (ZEND_NUM_ARGS() == 1) {
|
||||
if (zend_parse_parameters(1 TSRMLS_CC,"l", &julday) != SUCCESS) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
fl=0;
|
||||
} else if (ZEND_NUM_ARGS() == 2) {
|
||||
if (zend_parse_parameters(2 TSRMLS_CC,"ll", &julday, &fl) != SUCCESS) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
} else {
|
||||
char date[10];
|
||||
|
||||
if (zend_get_parameters_ex(1, &julday) != SUCCESS) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
convert_to_long_ex(julday);
|
||||
|
||||
SdnToJewish(julday, &year, &month, &day);
|
||||
if(!fl) {
|
||||
sprintf(date, "%i/%i/%i", month, day, year);
|
||||
RETURN_STRING(date, 1);
|
||||
} else {
|
||||
if (year <= 0 || year > 9999) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Out of range year.");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
sprintf(hebdate, "%s %s %s", \
|
||||
heb_number_to_chars(day), \
|
||||
JewishMonthHebName[month], \
|
||||
heb_number_to_chars(year));
|
||||
|
||||
RETURN_STRING(hebdate, 1);
|
||||
|
||||
}
|
||||
SdnToJewish(Z_LVAL_PP(julday), &year, &month, &day);
|
||||
sprintf(date, "%i/%i/%i", month, day, year);
|
||||
|
||||
RETURN_STRING(date, 1);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto int jewishtojd(int month, int day, int year)
|
||||
Converts a jewish calendar date to a julian day count */
|
||||
PHP_FUNCTION(jewishtojd)
|
||||
PHP_FUNCTION(jewishtojd)
|
||||
{
|
||||
pval **year, **month, **day;
|
||||
int jdate;
|
||||
@@ -509,7 +415,7 @@ PHP_FUNCTION(jewishtojd)
|
||||
|
||||
/* {{{ proto string jdtofrench(int juliandaycount)
|
||||
Converts a julian day count to a french republic calendar date */
|
||||
PHP_FUNCTION(jdtofrench)
|
||||
PHP_FUNCTION(jdtofrench)
|
||||
{
|
||||
pval **julday;
|
||||
int year, month, day;
|
||||
@@ -530,7 +436,7 @@ PHP_FUNCTION(jdtofrench)
|
||||
|
||||
/* {{{ proto int frenchtojd(int month, int day, int year)
|
||||
Converts a french republic calendar date to julian day count */
|
||||
PHP_FUNCTION(frenchtojd)
|
||||
PHP_FUNCTION(frenchtojd)
|
||||
{
|
||||
pval **year, **month, **day;
|
||||
int jdate;
|
||||
@@ -551,7 +457,7 @@ PHP_FUNCTION(frenchtojd)
|
||||
|
||||
/* {{{ proto mixed jddayofweek(int juliandaycount [, int mode])
|
||||
Returns name or number of day of week from julian day count */
|
||||
PHP_FUNCTION(jddayofweek)
|
||||
PHP_FUNCTION(jddayofweek)
|
||||
{
|
||||
pval *julday, *mode;
|
||||
int day;
|
||||
@@ -589,7 +495,7 @@ PHP_FUNCTION(jddayofweek)
|
||||
|
||||
/* {{{ proto string jdmonthname(int juliandaycount, int mode)
|
||||
Returns name of month for julian day count */
|
||||
PHP_FUNCTION(jdmonthname)
|
||||
PHP_FUNCTION(jdmonthname)
|
||||
{
|
||||
pval **julday, **mode;
|
||||
char *monthname = NULL;
|
||||
|
||||
@@ -311,24 +311,6 @@ char *JewishMonthName[14] =
|
||||
"Elul"
|
||||
};
|
||||
|
||||
char *JewishMonthHebName[14] =
|
||||
{
|
||||
"",
|
||||
"úùøé",
|
||||
"çùåï",
|
||||
"ëñìå",
|
||||
"èáú",
|
||||
"ùáè",
|
||||
"àãø",
|
||||
"'àãø á",
|
||||
"ðéñï",
|
||||
"àééø",
|
||||
"ñéåï",
|
||||
"úîåæ",
|
||||
"àá",
|
||||
"àìåì"
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
* Given the year within the 19 year metonic cycle and the time of a molad
|
||||
* (new moon) which starts that year, this routine will calculate what day
|
||||
|
||||
@@ -79,7 +79,6 @@ long int JulianToSdn(int year, int month, int day);
|
||||
void SdnToJewish(long int sdn, int *pYear, int *pMonth, int *pDay);
|
||||
long int JewishToSdn(int year, int month, int day);
|
||||
extern char *JewishMonthName[14];
|
||||
extern char *JewishMonthHebName[14];
|
||||
|
||||
/* French republic calendar conversions. */
|
||||
void SdnToFrench(long int sdn, int *pYear, int *pMonth, int *pDay);
|
||||
@@ -94,4 +93,4 @@ int DayOfWeek(long int sdn);
|
||||
extern char *DayNameShort[7];
|
||||
extern char *DayNameLong[7];
|
||||
|
||||
#endif /* SDNCAL_H */
|
||||
#endif /* SDNCAL_H */
|
||||
+6
-6
@@ -1339,7 +1339,7 @@ static int process_typeinfo(ITypeInfo *typeinfo, HashTable *id_to_name, int prin
|
||||
|
||||
ret = 1;
|
||||
} else {
|
||||
zend_error(E_WARNING, "Thats not a dispatchable interface!! type kind = %08x", attr->typekind);
|
||||
zend_error(E_WARNING, "Thats not a dispatchable interface!! type kind = %08x\n", attr->typekind);
|
||||
}
|
||||
|
||||
typeinfo->lpVtbl->ReleaseTypeAttr(typeinfo, attr);
|
||||
@@ -1710,7 +1710,7 @@ PHP_FUNCTION(com_propget)
|
||||
int arg_count = ZEND_NUM_ARGS();
|
||||
VARIANT *var_result;
|
||||
|
||||
if (arg_count < 2) {
|
||||
if (arg_count<3) {
|
||||
ZEND_WRONG_PARAM_COUNT();
|
||||
}
|
||||
arguments = (zval **) emalloc(sizeof(pval *)*arg_count);
|
||||
@@ -1870,6 +1870,7 @@ PHPAPI pval php_COM_get_property_handler(zend_property_reference *property_refer
|
||||
switch (Z_TYPE_P(overloaded_property)) {
|
||||
case OE_IS_ARRAY:
|
||||
if (do_COM_offget(var_result, obj, &overloaded_property->element, FALSE TSRMLS_CC) == FAILURE) {
|
||||
pval_destructor(&overloaded_property->element);
|
||||
FREE_VARIANT(var_result);
|
||||
FREE_COM(obj_prop);
|
||||
|
||||
@@ -1879,6 +1880,7 @@ PHPAPI pval php_COM_get_property_handler(zend_property_reference *property_refer
|
||||
|
||||
case OE_IS_OBJECT:
|
||||
if (do_COM_propget(var_result, obj, &overloaded_property->element, FALSE TSRMLS_CC) == FAILURE) {
|
||||
pval_destructor(&overloaded_property->element);
|
||||
FREE_VARIANT(var_result);
|
||||
FREE_COM(obj_prop);
|
||||
|
||||
@@ -1887,6 +1889,7 @@ PHPAPI pval php_COM_get_property_handler(zend_property_reference *property_refer
|
||||
break;
|
||||
|
||||
case OE_IS_METHOD:
|
||||
pval_destructor(&overloaded_property->element);
|
||||
FREE_VARIANT(var_result);
|
||||
|
||||
if (obj != obj_prop) {
|
||||
@@ -1901,10 +1904,7 @@ PHPAPI pval php_COM_get_property_handler(zend_property_reference *property_refer
|
||||
return return_value;
|
||||
}
|
||||
|
||||
if (obj == obj_prop) {
|
||||
// not head
|
||||
pval_destructor(&overloaded_property->element);
|
||||
}
|
||||
pval_destructor(&overloaded_property->element);
|
||||
|
||||
if (V_VT(var_result) == VT_DISPATCH) {
|
||||
if (V_DISPATCH(var_result) == NULL) {
|
||||
|
||||
+1
-1
@@ -230,7 +230,7 @@ static int php_VARIANT_set_property_handler(zend_property_reference *property_re
|
||||
|
||||
static int do_VARIANT_propset(VARIANT *var_arg, pval *arg_property, pval *value TSRMLS_DC)
|
||||
{
|
||||
VARTYPE type;
|
||||
int type;
|
||||
|
||||
if (!strcmp(Z_STRVAL_P(arg_property), "value")) {
|
||||
php_pval_to_variant(value, var_arg, codepage TSRMLS_CC);
|
||||
|
||||
+10
-16
@@ -42,7 +42,7 @@ static void comval_to_variant(pval *pval_arg, VARIANT *var_arg TSRMLS_DC);
|
||||
/* implementations */
|
||||
PHPAPI void php_pval_to_variant(pval *pval_arg, VARIANT *var_arg, int codepage TSRMLS_DC)
|
||||
{
|
||||
VARTYPE type = VT_EMPTY; /* default variant type */
|
||||
int type = VT_EMPTY; /* default variant type */
|
||||
|
||||
switch (Z_TYPE_P(pval_arg)) {
|
||||
case IS_NULL:
|
||||
@@ -90,11 +90,11 @@ PHPAPI void php_pval_to_variant(pval *pval_arg, VARIANT *var_arg, int codepage T
|
||||
|
||||
PHPAPI void php_pval_to_variant_ex(pval *pval_arg, VARIANT *var_arg, pval *pval_type, int codepage TSRMLS_DC)
|
||||
{
|
||||
php_pval_to_variant_ex2(pval_arg, var_arg, (unsigned short) Z_LVAL_P(pval_type), codepage TSRMLS_CC);
|
||||
php_pval_to_variant_ex2(pval_arg, var_arg, Z_LVAL_P(pval_type), codepage TSRMLS_CC);
|
||||
}
|
||||
|
||||
|
||||
PHPAPI void php_pval_to_variant_ex2(pval *pval_arg, VARIANT *var_arg, VARTYPE type, int codepage TSRMLS_DC)
|
||||
PHPAPI void php_pval_to_variant_ex2(pval *pval_arg, VARIANT *var_arg, int type, int codepage TSRMLS_DC)
|
||||
{
|
||||
OLECHAR *unicode_str;
|
||||
|
||||
@@ -108,7 +108,7 @@ PHPAPI void php_pval_to_variant_ex2(pval *pval_arg, VARIANT *var_arg, VARTYPE ty
|
||||
int numberOfElements = zend_hash_num_elements(ht);
|
||||
SAFEARRAY *safeArray;
|
||||
SAFEARRAYBOUND bounds[1];
|
||||
VARIANT *v, var;
|
||||
VARIANT *v;
|
||||
zval **entry; /* An entry in the input array */
|
||||
|
||||
type &= ~VT_ARRAY;
|
||||
@@ -118,35 +118,29 @@ PHPAPI void php_pval_to_variant_ex2(pval *pval_arg, VARIANT *var_arg, VARTYPE ty
|
||||
ALLOC_VARIANT(V_VARIANTREF(var_arg));
|
||||
var_arg = V_VARIANTREF(var_arg); /* put the array in that VARIANT */
|
||||
}
|
||||
if (!type) {
|
||||
// if no type is given we take the variant type
|
||||
type = VT_VARIANT;
|
||||
}
|
||||
|
||||
bounds[0].lLbound = 0;
|
||||
bounds[0].cElements = numberOfElements;
|
||||
safeArray = SafeArrayCreate(type, 1, bounds);
|
||||
safeArray = SafeArrayCreate(VT_VARIANT, 1, bounds);
|
||||
|
||||
if (NULL == safeArray) {
|
||||
php_error( E_WARNING,"Unable to convert php array to VARIANT array - %s", numberOfElements ? "" : "(Empty input array)");
|
||||
ZVAL_FALSE(pval_arg);
|
||||
} else {
|
||||
V_ARRAY(var_arg) = safeArray;
|
||||
V_VT(var_arg) = VT_ARRAY|type; /* Now have a valid safe array allocated */
|
||||
V_VT(var_arg) = VT_ARRAY|VT_VARIANT; /* Now have a valid safe array allocated */
|
||||
if (SUCCEEDED(SafeArrayLock(safeArray))) {
|
||||
ulong i;
|
||||
UINT size = SafeArrayGetElemsize(safeArray);
|
||||
|
||||
zend_hash_internal_pointer_reset(ht);
|
||||
for (i = 0; i < (ulong)numberOfElements; ++i) {
|
||||
if ((zend_hash_get_current_data(ht, (void **)&entry) == SUCCESS) && (entry != NULL)) { /* Get a pointer to the php array element */
|
||||
/* Add another value to the safe array */
|
||||
if (SUCCEEDED(SafeArrayPtrOfIndex(safeArray, &i, &v))) { /* Pointer to output element entry retrieved successfully */
|
||||
if (type == VT_VARIANT) {
|
||||
php_pval_to_variant(*entry, v, codepage TSRMLS_CC); /* Do the required conversion */
|
||||
if (SUCCEEDED(SafeArrayPtrOfIndex( safeArray, &i, &v))) { /* Pointer to output element entry retrieved successfully */
|
||||
if (type) { /* explicit type */
|
||||
php_pval_to_variant_ex2(*entry, v, type, codepage TSRMLS_CC); /* Do the required conversion */
|
||||
} else {
|
||||
php_pval_to_variant_ex2(*entry, &var, type, codepage TSRMLS_CC); /* Do the required conversion */
|
||||
memcpy(v, &(var.byref), size);
|
||||
php_pval_to_variant(*entry, v, codepage TSRMLS_CC); /* Do the required conversion */
|
||||
}
|
||||
} else {
|
||||
php_error( E_WARNING,"phpArrayToSafeArray() - Unable to retrieve pointer to output element number (%d)", i);
|
||||
|
||||
@@ -13,7 +13,7 @@ BEGIN_EXTERN_C()
|
||||
|
||||
PHPAPI void php_pval_to_variant(pval *pval_arg, VARIANT *var_arg, int codepage TSRMLS_DC);
|
||||
PHPAPI void php_pval_to_variant_ex(pval *pval_arg, VARIANT *var_arg, pval *pval_type, int codepage TSRMLS_DC);
|
||||
PHPAPI void php_pval_to_variant_ex2(pval *pval_arg, VARIANT *var_arg, VARTYPE type, int codepage TSRMLS_DC);
|
||||
PHPAPI void php_pval_to_variant_ex2(pval *pval_arg, VARIANT *var_arg, int type, int codepage TSRMLS_DC);
|
||||
PHPAPI int php_variant_to_pval(VARIANT *var_arg, pval *pval_arg, int codepage TSRMLS_DC);
|
||||
PHPAPI OLECHAR *php_char_to_OLECHAR(char *C_str, uint strlen, int codepage TSRMLS_DC);
|
||||
PHPAPI char *php_OLECHAR_to_char(OLECHAR *unicode_str, uint *out_length, int codepage TSRMLS_DC);
|
||||
|
||||
+5
-12
@@ -6,8 +6,8 @@ PHP_ARG_WITH(curl, for CURL support,
|
||||
[ --with-curl[=DIR] Include CURL support])
|
||||
|
||||
dnl Temporary option while we develop this aspect of the extension
|
||||
dnl PHP_ARG_WITH(curlwrappers, if we should use CURL for url streams,
|
||||
dnl [ --with-curlwrappers Use CURL for url streams], no, no)
|
||||
PHP_ARG_WITH(curlwrappers, if we should use CURL for url streams,
|
||||
[ --with-curlwrappers Use CURL for url streams], no, no)
|
||||
|
||||
if test "$PHP_CURL" != "no"; then
|
||||
if test -r $PHP_CURL/include/curl/easy.h; then
|
||||
@@ -61,16 +61,9 @@ if test "$PHP_CURL" != "no"; then
|
||||
$CURL_LIBS -L$CURL_DIR/lib
|
||||
])
|
||||
|
||||
PHP_CHECK_LIBRARY(curl,curl_version_info,
|
||||
[
|
||||
AC_DEFINE(HAVE_CURL_VERSION_INFO,1,[ ])
|
||||
],[],[
|
||||
$CURL_LIBS -L$CURL_DIR/lib
|
||||
])
|
||||
|
||||
dnl if test "$PHP_CURLWRAPPERS" != "no" ; then
|
||||
dnl AC_DEFINE(PHP_CURL_URL_WRAPPERS,1,[ ])
|
||||
dnl fi
|
||||
if test "$PHP_CURLWRAPPERS" != "no" ; then
|
||||
AC_DEFINE(PHP_CURL_URL_WRAPPERS,1,[ ])
|
||||
fi
|
||||
|
||||
PHP_NEW_EXTENSION(curl, curl.c curlstreams.c, $ext_shared)
|
||||
PHP_SUBST(CURL_SHARED_LIBADD)
|
||||
|
||||
+28
-114
@@ -51,11 +51,6 @@ static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC);
|
||||
|
||||
#define SAVE_CURL_ERROR(__handle, __err) (__handle)->err.no = (int) __err;
|
||||
|
||||
#define CAAL(s, v) add_assoc_long_ex(return_value, s, sizeof(s), (long) v);
|
||||
#define CAAD(s, v) add_assoc_double_ex(return_value, s, sizeof(s), (double) v);
|
||||
#define CAAS(s, v) add_assoc_string_ex(return_value, s, sizeof(s), (char *) v, 1);
|
||||
#define CAAZ(s, v) add_assoc_zval_ex(return_value, s, sizeof(s), (zval *) v);
|
||||
|
||||
/* {{{ curl_functions[]
|
||||
*/
|
||||
function_entry curl_functions[] = {
|
||||
@@ -179,18 +174,9 @@ PHP_MINIT_FUNCTION(curl)
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_CONNECTTIMEOUT);
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_SSL_VERIFYPEER);
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_CAINFO);
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_CAPATH);
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_COOKIEJAR);
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_SSL_CIPHER_LIST);
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_BINARYTRANSFER);
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_HTTPGET);
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_HTTP_VERSION);
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_SSLKEY);
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYTYPE);
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_SSLKEYPASSWD);
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE);
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_SSLENGINE_DEFAULT);
|
||||
REGISTER_CURL_CONSTANT(CURLOPT_CRLF);
|
||||
|
||||
/* Constants effecting the way CURLOPT_CLOSEPOLICY works */
|
||||
REGISTER_CURL_CONSTANT(CURLCLOSEPOLICY_LEAST_RECENTLY_USED);
|
||||
@@ -216,10 +202,6 @@ PHP_MINIT_FUNCTION(curl)
|
||||
REGISTER_CURL_CONSTANT(CURLINFO_SSL_VERIFYRESULT);
|
||||
REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_DOWNLOAD);
|
||||
REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_LENGTH_UPLOAD);
|
||||
REGISTER_CURL_CONSTANT(CURLINFO_STARTTRANSFER_TIME);
|
||||
REGISTER_CURL_CONSTANT(CURLINFO_CONTENT_TYPE);
|
||||
REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_TIME);
|
||||
REGISTER_CURL_CONSTANT(CURLINFO_REDIRECT_COUNT);
|
||||
|
||||
/* Error Constants */
|
||||
REGISTER_CURL_CONSTANT(CURLE_OK);
|
||||
@@ -275,15 +257,6 @@ PHP_MINIT_FUNCTION(curl)
|
||||
REGISTER_CURL_CONSTANT(CURLE_OBSOLETE);
|
||||
REGISTER_CURL_CONSTANT(CURLE_SSL_PEER_CERTIFICATE);
|
||||
|
||||
REGISTER_CURL_CONSTANT(CURL_NETRC_OPTIONAL);
|
||||
REGISTER_CURL_CONSTANT(CURL_NETRC_IGNORED);
|
||||
REGISTER_CURL_CONSTANT(CURL_NETRC_REQUIRED);
|
||||
|
||||
REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_NONE);
|
||||
REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_0);
|
||||
REGISTER_CURL_CONSTANT(CURL_HTTP_VERSION_1_1);
|
||||
|
||||
|
||||
if (curl_global_init(CURL_GLOBAL_SSL) != CURLE_OK) {
|
||||
return FAILURE;
|
||||
}
|
||||
@@ -568,9 +541,8 @@ static void curl_free_slist(void **slist)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* {{{ proto array curl_version(void)
|
||||
Return cURL version information. */
|
||||
/* {{{ proto string curl_version(void)
|
||||
Return the CURL version string. */
|
||||
PHP_FUNCTION(curl_version)
|
||||
{
|
||||
if (ZEND_NUM_ARGS() != 0) {
|
||||
@@ -707,9 +679,6 @@ PHP_FUNCTION(curl_setopt)
|
||||
case CURLOPT_SSL_VERIFYHOST:
|
||||
case CURLOPT_SSL_VERIFYPEER:
|
||||
case CURLOPT_DNS_USE_GLOBAL_CACHE:
|
||||
case CURLOPT_HTTPGET:
|
||||
case CURLOPT_HTTP_VERSION:
|
||||
case CURLOPT_CRLF:
|
||||
convert_to_long_ex(zvalue);
|
||||
error = curl_easy_setopt(ch->cp, option, Z_LVAL_PP(zvalue));
|
||||
break;
|
||||
@@ -722,6 +691,8 @@ PHP_FUNCTION(curl_setopt)
|
||||
case CURLOPT_USERAGENT:
|
||||
case CURLOPT_FTPPORT:
|
||||
case CURLOPT_COOKIE:
|
||||
case CURLOPT_SSLCERT:
|
||||
case CURLOPT_SSLCERTPASSWD:
|
||||
case CURLOPT_COOKIEFILE:
|
||||
case CURLOPT_REFERER:
|
||||
case CURLOPT_INTERFACE:
|
||||
@@ -729,14 +700,8 @@ PHP_FUNCTION(curl_setopt)
|
||||
case CURLOPT_RANDOM_FILE:
|
||||
case CURLOPT_EGDSOCKET:
|
||||
case CURLOPT_CAINFO:
|
||||
case CURLOPT_CAPATH:
|
||||
case CURLOPT_COOKIEJAR:
|
||||
case CURLOPT_SSL_CIPHER_LIST:
|
||||
case CURLOPT_SSLKEY:
|
||||
case CURLOPT_SSLKEYTYPE:
|
||||
case CURLOPT_SSLKEYPASSWD:
|
||||
case CURLOPT_SSLENGINE:
|
||||
case CURLOPT_SSLENGINE_DEFAULT: {
|
||||
case CURLOPT_SSL_CIPHER_LIST: {
|
||||
char *copystr = NULL;
|
||||
|
||||
convert_to_string_ex(zvalue);
|
||||
@@ -806,33 +771,21 @@ PHP_FUNCTION(curl_setopt)
|
||||
}
|
||||
break;
|
||||
case CURLOPT_WRITEFUNCTION:
|
||||
if (ch->handlers->write->func) {
|
||||
zval_ptr_dtor(&ch->handlers->write->func);
|
||||
}
|
||||
zval_add_ref(zvalue);
|
||||
ch->handlers->write->func = *zvalue;
|
||||
ch->handlers->write->method = PHP_CURL_USER;
|
||||
break;
|
||||
case CURLOPT_READFUNCTION:
|
||||
if (ch->handlers->read->func) {
|
||||
zval_ptr_dtor(&ch->handlers->read->func);
|
||||
}
|
||||
zval_add_ref(zvalue);
|
||||
ch->handlers->read->func = *zvalue;
|
||||
ch->handlers->read->method = PHP_CURL_USER;
|
||||
break;
|
||||
case CURLOPT_HEADERFUNCTION:
|
||||
if (ch->handlers->write_header->func) {
|
||||
zval_ptr_dtor(&ch->handlers->write_header->func);
|
||||
}
|
||||
zval_add_ref(zvalue);
|
||||
ch->handlers->write_header->func = *zvalue;
|
||||
ch->handlers->write_header->method = PHP_CURL_USER;
|
||||
break;
|
||||
case CURLOPT_PASSWDFUNCTION:
|
||||
if (ch->handlers->passwd) {
|
||||
zval_ptr_dtor(&ch->handlers->passwd);
|
||||
}
|
||||
zval_add_ref(zvalue);
|
||||
ch->handlers->passwd = *zvalue;
|
||||
error = curl_easy_setopt(ch->cp, CURLOPT_PASSWDFUNCTION, curl_passwd);
|
||||
@@ -858,15 +811,13 @@ PHP_FUNCTION(curl_setopt)
|
||||
}
|
||||
|
||||
for (zend_hash_internal_pointer_reset(postfields);
|
||||
zend_hash_get_current_data(postfields,
|
||||
(void **) ¤t) == SUCCESS;
|
||||
zend_hash_get_current_data(postfields, (void **) ¤t) == SUCCESS;
|
||||
zend_hash_move_forward(postfields)) {
|
||||
|
||||
SEPARATE_ZVAL(current);
|
||||
convert_to_string_ex(current);
|
||||
|
||||
zend_hash_get_current_key_ex(postfields,
|
||||
&string_key, &string_key_len, &num_key, 0, NULL);
|
||||
zend_hash_get_current_key_ex(postfields, &string_key, &string_key_len, &num_key, 0, NULL);
|
||||
|
||||
postval = Z_STRVAL_PP(current);
|
||||
if (*postval == '@') {
|
||||
@@ -933,8 +884,7 @@ PHP_FUNCTION(curl_setopt)
|
||||
slist = curl_slist_append(slist, indiv);
|
||||
if (! slist) {
|
||||
efree(indiv);
|
||||
php_error(E_WARNING, "%s(): Couldn't build curl_slist",
|
||||
get_active_function_name(TSRMLS_C));
|
||||
php_error(E_WARNING, "%s(): Couldn't build curl_slist", get_active_function_name(TSRMLS_C));
|
||||
RETURN_FALSE;
|
||||
}
|
||||
zend_llist_add_element(&ch->to_free.str, &indiv);
|
||||
@@ -956,24 +906,6 @@ PHP_FUNCTION(curl_setopt)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ cleanup_handle(ch)
|
||||
Cleanup an execution phase */
|
||||
static void
|
||||
cleanup_handle(php_curl *ch)
|
||||
{
|
||||
if (ch->uses < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ch->handlers->write->buf.len) {
|
||||
memset(&ch->handlers->write->buf, 0, sizeof(smart_str));
|
||||
}
|
||||
|
||||
memset(ch->err.str, 0, CURL_ERROR_SIZE + 1);
|
||||
ch->err.no = 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool curl_exec(resource ch)
|
||||
Perform a CURL session */
|
||||
PHP_FUNCTION(curl_exec)
|
||||
@@ -988,20 +920,14 @@ PHP_FUNCTION(curl_exec)
|
||||
}
|
||||
ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
|
||||
|
||||
cleanup_handle(ch);
|
||||
|
||||
error = curl_easy_perform(ch->cp);
|
||||
SAVE_CURL_ERROR(ch, error);
|
||||
if (error != CURLE_OK) {
|
||||
if (ch->handlers->write->buf.len > 0) {
|
||||
if (ch->handlers->write->buf.len > 0)
|
||||
smart_str_free(&ch->handlers->write->buf);
|
||||
}
|
||||
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
ch->uses++;
|
||||
|
||||
if (ch->handlers->write->method == PHP_CURL_RETURN && ch->handlers->write->buf.len > 0) {
|
||||
if (ch->handlers->write->type != PHP_CURL_BINARY)
|
||||
smart_str_0(&ch->handlers->write->buf);
|
||||
@@ -1012,6 +938,10 @@ PHP_FUNCTION(curl_exec)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#define CAAL(s, v) add_assoc_long_ex(return_value, s, sizeof(s), v);
|
||||
#define CAAD(s, v) add_assoc_double_ex(return_value, s, sizeof(s), v);
|
||||
#define CAAS(s, v) add_assoc_string_ex(return_value, s, sizeof(s), v, 1);
|
||||
|
||||
/* {{{ proto string curl_getinfo(resource ch, int opt)
|
||||
Get information regarding a specific transfer */
|
||||
PHP_FUNCTION(curl_getinfo)
|
||||
@@ -1029,16 +959,14 @@ PHP_FUNCTION(curl_getinfo)
|
||||
ZEND_FETCH_RESOURCE(ch, php_curl *, zid, -1, le_curl_name, le_curl);
|
||||
|
||||
if (argc < 2) {
|
||||
char *s_code;
|
||||
char *url;
|
||||
long l_code;
|
||||
double d_code;
|
||||
|
||||
array_init(return_value);
|
||||
|
||||
curl_easy_getinfo(ch->cp, CURLINFO_EFFECTIVE_URL, &s_code);
|
||||
CAAS("url", s_code);
|
||||
curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_TYPE, &s_code);
|
||||
CAAS("content_type", s_code);
|
||||
curl_easy_getinfo(ch->cp, CURLINFO_EFFECTIVE_URL, &url);
|
||||
CAAS("url", url);
|
||||
curl_easy_getinfo(ch->cp, CURLINFO_HTTP_CODE, &l_code);
|
||||
CAAL("http_code", l_code);
|
||||
curl_easy_getinfo(ch->cp, CURLINFO_HEADER_SIZE, &l_code);
|
||||
@@ -1049,8 +977,6 @@ PHP_FUNCTION(curl_getinfo)
|
||||
CAAL("filetime", l_code);
|
||||
curl_easy_getinfo(ch->cp, CURLINFO_SSL_VERIFYRESULT, &l_code);
|
||||
CAAL("ssl_verify_result", l_code);
|
||||
curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_COUNT, &l_code);
|
||||
CAAL("redirect_count", l_code);
|
||||
curl_easy_getinfo(ch->cp, CURLINFO_TOTAL_TIME, &d_code);
|
||||
CAAD("total_time", d_code);
|
||||
curl_easy_getinfo(ch->cp, CURLINFO_NAMELOOKUP_TIME, &d_code);
|
||||
@@ -1071,19 +997,14 @@ PHP_FUNCTION(curl_getinfo)
|
||||
CAAD("download_content_length", d_code);
|
||||
curl_easy_getinfo(ch->cp, CURLINFO_CONTENT_LENGTH_UPLOAD, &d_code);
|
||||
CAAD("upload_content_length", d_code);
|
||||
curl_easy_getinfo(ch->cp, CURLINFO_STARTTRANSFER_TIME, &d_code);
|
||||
CAAD("starttransfer_time", d_code);
|
||||
curl_easy_getinfo(ch->cp, CURLINFO_REDIRECT_TIME, &d_code);
|
||||
CAAD("redirect_time", d_code);
|
||||
} else {
|
||||
option = Z_LVAL_PP(zoption);
|
||||
switch (option) {
|
||||
case CURLINFO_EFFECTIVE_URL:
|
||||
case CURLINFO_CONTENT_TYPE: {
|
||||
char *s_code;
|
||||
case CURLINFO_EFFECTIVE_URL: {
|
||||
char *url;
|
||||
|
||||
curl_easy_getinfo(ch->cp, option, &s_code);
|
||||
RETURN_STRING(s_code, 1);
|
||||
curl_easy_getinfo(ch->cp, option, &url);
|
||||
RETURN_STRING(url, 1);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -1091,8 +1012,7 @@ PHP_FUNCTION(curl_getinfo)
|
||||
case CURLINFO_HEADER_SIZE:
|
||||
case CURLINFO_REQUEST_SIZE:
|
||||
case CURLINFO_FILETIME:
|
||||
case CURLINFO_SSL_VERIFYRESULT:
|
||||
case CURLINFO_REDIRECT_COUNT: {
|
||||
case CURLINFO_SSL_VERIFYRESULT: {
|
||||
long code;
|
||||
|
||||
curl_easy_getinfo(ch->cp, option, &code);
|
||||
@@ -1109,9 +1029,7 @@ PHP_FUNCTION(curl_getinfo)
|
||||
case CURLINFO_SPEED_DOWNLOAD:
|
||||
case CURLINFO_SPEED_UPLOAD:
|
||||
case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
|
||||
case CURLINFO_CONTENT_LENGTH_UPLOAD:
|
||||
case CURLINFO_STARTTRANSFER_TIME:
|
||||
case CURLINFO_REDIRECT_TIME: {
|
||||
case CURLINFO_CONTENT_LENGTH_UPLOAD: {
|
||||
double code;
|
||||
|
||||
curl_easy_getinfo(ch->cp, option, &code);
|
||||
@@ -1187,14 +1105,10 @@ static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
||||
zend_llist_clean(&ch->to_free.slist);
|
||||
zend_llist_clean(&ch->to_free.post);
|
||||
|
||||
if (ch->handlers->write->func)
|
||||
zval_ptr_dtor(&ch->handlers->write->func);
|
||||
if (ch->handlers->read->func)
|
||||
zval_ptr_dtor(&ch->handlers->read->func);
|
||||
if (ch->handlers->write_header->func)
|
||||
zval_ptr_dtor(&ch->handlers->write_header->func);
|
||||
if (ch->handlers->passwd)
|
||||
zval_ptr_dtor(&ch->handlers->passwd);
|
||||
if (ch->handlers->write->func) zval_ptr_dtor(&ch->handlers->write->func);
|
||||
if (ch->handlers->read->func) zval_ptr_dtor(&ch->handlers->read->func);
|
||||
if (ch->handlers->write_header->func) zval_ptr_dtor(&ch->handlers->write_header->func);
|
||||
if (ch->handlers->passwd) zval_ptr_dtor(&ch->handlers->passwd);
|
||||
|
||||
efree(ch->handlers->write);
|
||||
efree(ch->handlers->write_header);
|
||||
@@ -1211,6 +1125,6 @@ static void _php_curl_close(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: fdm=marker
|
||||
* vim: noet sw=4 ts=4
|
||||
* vim600: noet sw=4 ts=4 fdm=marker
|
||||
* vim<600: noet sw=4 ts=4
|
||||
*/
|
||||
@@ -92,7 +92,6 @@ typedef struct {
|
||||
struct _php_curl_error err;
|
||||
struct _php_curl_free to_free;
|
||||
long id;
|
||||
unsigned int uses;
|
||||
} php_curl;
|
||||
|
||||
/* streams support */
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
dnl
|
||||
dnl $Id$
|
||||
dnl
|
||||
|
||||
PHP_ARG_WITH(cybermut, for cybermut support,
|
||||
[ --with-cybermut[=DIR] Include CyberMut (french Credit Mutuel telepaiement)])
|
||||
|
||||
if test "$PHP_CYBERMUT" != "no"; then
|
||||
for i in /usr/local /usr $PHP_CYBERMUT; do
|
||||
if test -r $i/cm-mac.h; then
|
||||
CYBERMUT_INC_DIR=$i
|
||||
elif test -r $i/include/cm-mac.h; then
|
||||
CYBERMUT_INC_DIR=$i/include
|
||||
fi
|
||||
|
||||
if test -r $i/libcm-mac.a; then
|
||||
CYBERMUT_LIB_DIR=$i
|
||||
elif test -r $i/lib/libcm-mac.a; then
|
||||
CYBERMUT_LIB_DIR=$i/lib
|
||||
fi
|
||||
done
|
||||
|
||||
if test -z "$CYBERMUT_INC_DIR"; then
|
||||
AC_MSG_ERROR(Could not find cm-mac.h Please make sure you have the
|
||||
CyberMut SDK installed. Use
|
||||
./configure --with-cybermut=<cybermut-dir> if necessary)
|
||||
fi
|
||||
|
||||
if test -z "$CYBERMUT_LIB_DIR"; then
|
||||
AC_MSG_ERROR(Could not find libcm-mac.a Please make sure you have the
|
||||
CyberMut SDK installed. Use
|
||||
./configure --with-cybermut=<cybermut-dir> if necessary)
|
||||
fi
|
||||
AC_MSG_RESULT(found in $CYBERMUT_LIB_DIR)
|
||||
|
||||
AC_MSG_RESULT(linking libcm-mac.a with libcybermut.a)
|
||||
ln -sf $CYBERMUT_LIB_DIR/libcm-mac.a $CYBERMUT_LIB_DIR/libcybermut.a
|
||||
|
||||
PHP_ADD_INCLUDE($CYBERMUT_INC_DIR)
|
||||
|
||||
PHP_SUBST(CYBERMUT_SHARED_LIBADD)
|
||||
PHP_ADD_LIBRARY_WITH_PATH(cybermut, $CYBERMUT_LIB_DIR, CYBERMUT_SHARED_LIBADD)
|
||||
|
||||
AC_DEFINE(HAVE_CYBERMUT, 1, [ ])
|
||||
|
||||
|
||||
PHP_NEW_EXTENSION(cybermut, cybermut.c, $ext_shared)
|
||||
fi
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2002 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.02 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available at through the world-wide-web at |
|
||||
| http://www.php.net/license/2_02.txt. |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Sylvain PAGES <spages@free.fr> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
#include "php_ini.h"
|
||||
#include "php_cybermut.h"
|
||||
|
||||
#include "cm-mac.h"
|
||||
|
||||
/* If you declare any globals in php_cybermut.h uncomment this:
|
||||
ZEND_DECLARE_MODULE_GLOBALS(cybermut)
|
||||
*/
|
||||
|
||||
/* True global resources - no need for thread safety here */
|
||||
static int le_cybermut;
|
||||
|
||||
/* {{{ cybermut_functions[]
|
||||
*/
|
||||
function_entry cybermut_functions[] = {
|
||||
PHP_FE(cybermut_creerformulairecm, NULL)
|
||||
PHP_FE(cybermut_testmac, NULL)
|
||||
PHP_FE(cybermut_creerreponsecm, NULL)
|
||||
{NULL, NULL, NULL} /* Must be the last line in cybermut_functions[] */
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
/* {{{ cybermut_module_entry
|
||||
*/
|
||||
zend_module_entry cybermut_module_entry = {
|
||||
STANDARD_MODULE_HEADER,
|
||||
"cybermut",
|
||||
cybermut_functions,
|
||||
PHP_MINIT(cybermut),
|
||||
PHP_MSHUTDOWN(cybermut),
|
||||
NULL,
|
||||
NULL,
|
||||
PHP_MINFO(cybermut),
|
||||
NO_VERSION_YET,
|
||||
STANDARD_MODULE_PROPERTIES
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
#ifdef COMPILE_DL_CYBERMUT
|
||||
ZEND_GET_MODULE(cybermut)
|
||||
#endif
|
||||
|
||||
PHP_MINIT_FUNCTION(cybermut)
|
||||
{
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
PHP_MSHUTDOWN_FUNCTION(cybermut)
|
||||
{
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/* {{{ PHP_MINFO_FUNCTION
|
||||
*/
|
||||
PHP_MINFO_FUNCTION(cybermut)
|
||||
{
|
||||
php_info_print_table_start();
|
||||
php_info_print_table_header(2, "cybermut support", "enabled");
|
||||
php_info_print_table_end();
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string cybermut_creerformulairecm(string url_CM, string version, string TPE, string montant, string ref_commande, string texte_libre, string url_retour, string url_retour_ok, string url_retour_err, string langue, string code_societe, string texte_bouton)
|
||||
Returns a string containing source HTML of the form of request for payment. This result corresponds to the last parameter "formulaire" of the original function which was removed */
|
||||
PHP_FUNCTION(cybermut_creerformulairecm)
|
||||
{
|
||||
zval **url_CM, **version, **TPE, **montant, **ref_commande, **texte_libre, **url_retour, **url_retour_ok, **url_retour_err, **langue, **code_societe, **texte_bouton;
|
||||
|
||||
char formulaire [10000];
|
||||
|
||||
if (ZEND_NUM_ARGS() != 12 || zend_get_parameters_ex(12, &url_CM, &version, &TPE, &montant, &ref_commande, &texte_libre, &url_retour, &url_retour_ok, &url_retour_err, &langue, &code_societe, &texte_bouton) == FAILURE){
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
convert_to_string_ex(url_CM);
|
||||
convert_to_string_ex(version);
|
||||
convert_to_string_ex(TPE);
|
||||
convert_to_string_ex(montant);
|
||||
convert_to_string_ex(ref_commande);
|
||||
convert_to_string_ex(texte_libre);
|
||||
convert_to_string_ex(url_retour);
|
||||
convert_to_string_ex(url_retour_ok);
|
||||
convert_to_string_ex(url_retour_err);
|
||||
convert_to_string_ex(langue);
|
||||
convert_to_string_ex(code_societe);
|
||||
convert_to_string_ex(texte_bouton);
|
||||
|
||||
CreerFormulaireCM ( Z_STRVAL_PP(url_CM), Z_STRVAL_PP(version), Z_STRVAL_PP(TPE), Z_STRVAL_PP(montant), Z_STRVAL_PP(ref_commande), Z_STRVAL_PP(texte_libre), Z_STRVAL_PP(url_retour), Z_STRVAL_PP(url_retour_ok), Z_STRVAL_PP(url_retour_err), Z_STRVAL_PP(langue), Z_STRVAL_PP(code_societe), Z_STRVAL_PP(texte_bouton), formulaire);
|
||||
|
||||
|
||||
RETURN_STRING(formulaire, 1);
|
||||
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto bool cybermut_testmac(string code_MAC, string version, string TPE, string cdate, string montant, string ref_commande, string texte_libre, string code_retour)
|
||||
Returns a boolean attesting that the authentification proceeded well. TRUE if the received message is authenticated and FALSE if not */
|
||||
PHP_FUNCTION(cybermut_testmac)
|
||||
{
|
||||
zval **code_MAC, **version, **TPE, **cdate, **montant, **ref_commande, **texte_libre, **code_retour;
|
||||
int cdr_test;
|
||||
|
||||
if (ZEND_NUM_ARGS() != 8 || zend_get_parameters_ex(8, &code_MAC, &version, &TPE, &cdate, &montant, &ref_commande, &texte_libre, &code_retour) == FAILURE){
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
convert_to_string_ex(code_MAC);
|
||||
convert_to_string_ex(version);
|
||||
convert_to_string_ex(TPE);
|
||||
convert_to_string_ex(cdate);
|
||||
convert_to_string_ex(montant);
|
||||
convert_to_string_ex(ref_commande);
|
||||
convert_to_string_ex(texte_libre);
|
||||
convert_to_string_ex(code_retour);
|
||||
|
||||
cdr_test = TestMAC ( Z_STRVAL_PP(code_MAC), Z_STRVAL_PP(version), Z_STRVAL_PP(TPE), Z_STRVAL_PP(cdate), Z_STRVAL_PP(montant), Z_STRVAL_PP(ref_commande), Z_STRVAL_PP(texte_libre), Z_STRVAL_PP(code_retour));
|
||||
|
||||
if (cdr_test == 1) {
|
||||
RETURN_TRUE;
|
||||
} else {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string cybermut_creerreponsecm(string phrase)
|
||||
Returns a string containing the message of acknowledgement of delivery (headers and body of the message). This result corresponds to the last parameter "reponse" of the original function which was removed */
|
||||
PHP_FUNCTION(cybermut_creerreponsecm)
|
||||
{
|
||||
zval **phrase;
|
||||
char buf[5000];
|
||||
|
||||
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &phrase) == FAILURE){
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
convert_to_string_ex(phrase);
|
||||
|
||||
CreerReponseCM( Z_STRVAL_PP(phrase), buf);
|
||||
|
||||
RETURN_STRING (buf, 1);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 fdm=marker
|
||||
* vim<600: sw=4 ts=4
|
||||
*/
|
||||
@@ -0,0 +1,214 @@
|
||||
<reference id="ref.cybermut">
|
||||
<title>Credit Mutuel CyberMUT functions</title>
|
||||
<titleabbrev>CyberMUT</titleabbrev>
|
||||
<partintro>
|
||||
<simpara>
|
||||
This extension allows you to process credit cards transactions using Credit
|
||||
Mutuel CyberMUT system (<ulink url="http://www.creditmutuel.fr/centre_commercial/vendez_sur_internet.html">http://www.creditmutuel.fr/centre_commercial/vendez_sur_internet.html</ulink>).
|
||||
</simpara>
|
||||
<simpara>
|
||||
CynerMUT is a popular Web Payment Service in France, provided by the
|
||||
Credit Mutuel bank. If you are foreign in France, these functions will not
|
||||
be useful for you.
|
||||
</simpara>
|
||||
<simpara>
|
||||
These functions are only available if PHP has been compiled with the
|
||||
<option role="configure">--with-cybermut[=DIR]</option> option, where DIR is
|
||||
the location of libcm-mac.a and cm-mac.h. You will require the
|
||||
appropriate SDK for your platform, which may be sent to you after your
|
||||
CyberMUT's subscription (contact them via Web, or go to the nearest
|
||||
Credit Mutuel).
|
||||
</simpara>
|
||||
<simpara>
|
||||
The use of these functions is almost identical to the original functions,
|
||||
except for the parameters of return for CreerFormulaireCM and CreerReponseCM,
|
||||
which are returned directly by functions PHP, whereas they had passed in
|
||||
reference in the original functions.
|
||||
</simpara>
|
||||
<simpara>
|
||||
These functions have been added in PHP 4.0.4. ???
|
||||
</simpara>
|
||||
|
||||
<note><para>
|
||||
These functions only provide a link to CyberMUT SDK. Be sure to read the
|
||||
CynerMUT Developers Guide for full details of the required parameters.
|
||||
</para></note>
|
||||
</partintro>
|
||||
|
||||
<refentry id="function.cybermut_creerformulairecm">
|
||||
<refnamediv>
|
||||
<refname>cybermut_creerformulairecm</refname>
|
||||
<refpurpose>Generate HTML form of request for payment</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>string <function>pfpro_init</function></funcdef>
|
||||
<paramdef>string <parameter>url_CM</parameter></paramdef>
|
||||
<paramdef>string <parameter>version</parameter></paramdef>
|
||||
<paramdef>string <parameter>TPE</parameter></paramdef>
|
||||
<paramdef>string <parameter>montant</parameter></paramdef>
|
||||
<paramdef>string <parameter>ref_commande</parameter></paramdef>
|
||||
<paramdef>string <parameter>texte_libre</parameter></paramdef>
|
||||
<paramdef>string <parameter>url_retour</parameter></paramdef>
|
||||
<paramdef>string <parameter>url_retour_ok</parameter></paramdef>
|
||||
<paramdef>string <parameter>url_retour_err</parameter></paramdef>
|
||||
<paramdef>string <parameter>langue</parameter></paramdef>
|
||||
<paramdef>string <parameter>code_societe</parameter></paramdef>
|
||||
<paramdef>string <parameter>texte_bouton</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
<function>cynermut_creerformulairecm</function> is used to generate the
|
||||
HTML form of request for payment.
|
||||
</para>
|
||||
<para>
|
||||
See also <function>cybermut_testmac</function>
|
||||
<function>cybermut_creerreponsecm</function>.
|
||||
</para>
|
||||
<example>
|
||||
<title>First step of payment (equiv cgi1.c)</title>
|
||||
<programlisting role="php">
|
||||
<?php
|
||||
// Directory where are located the keys
|
||||
putenv("CMKEYDIR=/var/creditmut/cles");
|
||||
|
||||
// Version number
|
||||
$VERSION="1.2";
|
||||
|
||||
$retour = creditmut_creerformulairecm(
|
||||
"https://www.creditmutuel.fr/test/telepaiement/paiement.cgi",
|
||||
$VERSION,
|
||||
"1234567890",
|
||||
"300FRF",
|
||||
$REFERENCE,
|
||||
$TEXTE_LIBRE,
|
||||
$URL_RETOUR,
|
||||
$URL_RETOUR_OK,
|
||||
$URL_RETOUR_ERR,
|
||||
"francais",
|
||||
"company",
|
||||
"Paiement par carte bancaire");
|
||||
|
||||
echo $retour;
|
||||
?>
|
||||
</programlisting>
|
||||
</example>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<refentry id="function.cybermut_testmac">
|
||||
<refnamediv>
|
||||
<refname>cybermut_testmac</refname>
|
||||
<refpurpose>Make sure that there no was data diddling contained
|
||||
in the received message of confirmation </refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>bool <function>cybermut_testmac</function></funcdef>
|
||||
<paramdef>string <parameter>code_MAC</parameter></paramdef>
|
||||
<paramdef>string <parameter>version</parameter></paramdef>
|
||||
<paramdef>string <parameter>TPE</parameter></paramdef>
|
||||
<paramdef>string <parameter>cdate</parameter></paramdef>
|
||||
<paramdef>string <parameter>montant</parameter></paramdef>
|
||||
<paramdef>string <parameter>ref_commande</parameter></paramdef>
|
||||
<paramdef>string <parameter>texte_libre</parameter></paramdef>
|
||||
<paramdef>string <parameter>code-retour</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
<function>cybermut_testmac</function> is used to make sure that there was
|
||||
not data diddling contained in the received message of confirmation.
|
||||
Pay attention to parameters code-retour and texte-libre, which cannot be
|
||||
evaluated as is, because auf the dash. You must retrieve them by using:
|
||||
<programlisting role="php">
|
||||
$code_retour=$HTTP_GET_VARS["code-retour"];
|
||||
$texte_libre=$HTTP_GET_VARS["texte-libre"];
|
||||
</programlisting>
|
||||
</para>
|
||||
<para>
|
||||
See also <function>cybermut_creerformulairecm</function>
|
||||
<function>cybermut_creerreponsecm</function>.
|
||||
</para>
|
||||
<example>
|
||||
<title>Last step of payment (equiv cgi2.c)</title>
|
||||
<programlisting role="php">
|
||||
<?php_track_vars?>
|
||||
<?php
|
||||
// Directory where are located the keys
|
||||
putenv("CMKEYDIR=/var/creditmut/cles");
|
||||
|
||||
// Version number
|
||||
$VERSION="1.2";
|
||||
|
||||
$texte_libre = $HTTP_GET_VARS["texte-libre"];
|
||||
$code_retour = $HTTP_GET_VARS["code-retour"];
|
||||
|
||||
$mac_ok = creditmut_testmac($MAC,$VERSION,$TPE,$date,$montant,$reference,$texte_libre,$code_retour);
|
||||
|
||||
if ($mac_ok) {
|
||||
|
||||
//
|
||||
// insert data processing here
|
||||
//
|
||||
//
|
||||
|
||||
$result=creditmut_creerreponsecm("OK");
|
||||
} else {
|
||||
$result=creditmut_creerreponsecm("Document Falsifie");}
|
||||
|
||||
?>
|
||||
</programlisting>
|
||||
</example>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<refentry id="function.cybermut_creerreponsecm">
|
||||
<refnamediv>
|
||||
<refname>cybermut_creerreponsecm</refname>
|
||||
<refpurpose>Generate the acknowledgement of delivery of the confirmation
|
||||
of payment</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>string <function>cybermut_creerreponsecm</function></funcdef>
|
||||
<paramdef>string <parameter>phrase</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
Returns: string containing the message of aknowledgement of delivery.
|
||||
</para>
|
||||
<para>
|
||||
The parameter is "OK" if the message of confirmation of the payment
|
||||
were correctly auhentified by <function>cybermut_testmac</function>.
|
||||
Any other chain is regarded as an error message.
|
||||
</para>
|
||||
<para>
|
||||
See also <function>cybermut_creerformulairecm</function>
|
||||
<function>cybermut_testmac</function>.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
</reference>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
Local variables:
|
||||
mode: sgml
|
||||
sgml-omittag:t
|
||||
sgml-shorttag:t
|
||||
sgml-minimize-attributes:nil
|
||||
sgml-always-quote-attributes:t
|
||||
sgml-indent-step:1
|
||||
sgml-indent-data:t
|
||||
sgml-parent-document:nil
|
||||
sgml-default-dtd-file:"../../manual.ced"
|
||||
sgml-exposed-tags:nil
|
||||
sgml-local-catalogs:nil
|
||||
sgml-local-ecat-files:nil
|
||||
End:
|
||||
-->
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2002 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.02 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available at through the world-wide-web at |
|
||||
| http://www.php.net/license/2_02.txt. |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Sylvain PAGES <spages@free.fr> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
#ifndef PHP_CYBERMUT_H
|
||||
#define PHP_CYBERMUT_H
|
||||
|
||||
extern zend_module_entry cybermut_module_entry;
|
||||
#define phpext_cybermut_ptr &cybermut_module_entry
|
||||
|
||||
#ifdef PHP_WIN32
|
||||
#define PHP_CYBERMUT_API __declspec(dllexport)
|
||||
#else
|
||||
#define PHP_CYBERMUT_API
|
||||
#endif
|
||||
|
||||
PHP_MINIT_FUNCTION(cybermut);
|
||||
PHP_MSHUTDOWN_FUNCTION(cybermut);
|
||||
PHP_RINIT_FUNCTION(cybermut);
|
||||
PHP_RSHUTDOWN_FUNCTION(cybermut);
|
||||
PHP_MINFO_FUNCTION(cybermut);
|
||||
|
||||
PHP_FUNCTION(confirm_cybermut_compiled); /* For testing, remove later. */
|
||||
PHP_FUNCTION(cybermut_creerformulairecm);
|
||||
PHP_FUNCTION(cybermut_testmac);
|
||||
PHP_FUNCTION(cybermut_creerreponsecm);
|
||||
|
||||
/*
|
||||
Declare any global variables you may need between the BEGIN
|
||||
and END macros here:
|
||||
|
||||
ZEND_BEGIN_MODULE_GLOBALS(cybermut)
|
||||
int global_variable;
|
||||
ZEND_END_MODULE_GLOBALS(cybermut)
|
||||
*/
|
||||
|
||||
/* In every function that needs to use variables in php_cybermut_globals,
|
||||
do call CYBERMUTLS_FETCH(); after declaring other variables used by
|
||||
that function, and always refer to them as CYBERMUTG(variable).
|
||||
You are encouraged to rename these macros something shorter, see
|
||||
examples in any other php module directory.
|
||||
*/
|
||||
|
||||
#ifdef ZTS
|
||||
#define CYBERMUTG(v) TSRMG(cybermut_globals_id, php_cybermut_globals *, v)
|
||||
#else
|
||||
#define CYBERMUTG(v) (cybermut_globals.v)
|
||||
#endif
|
||||
|
||||
#endif /* PHP_CYBERMUT_H */
|
||||
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
*/
|
||||
@@ -0,0 +1,23 @@
|
||||
--TEST--
|
||||
Check for cybermut presence
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("cybermut")) print "skip"; ?>
|
||||
--POST--
|
||||
--GET--
|
||||
--FILE--
|
||||
<?php
|
||||
echo "cybermut extension is available";
|
||||
/*
|
||||
you can add regression tests for your extension here
|
||||
|
||||
the output of your test code has to be equal to the
|
||||
text in the --EXPECT-- section below for the tests
|
||||
to pass, differences between the output and the
|
||||
expected text are interpreted as failure
|
||||
|
||||
see php4/tests/README for further information on
|
||||
writing regression tests
|
||||
*/
|
||||
?>
|
||||
--EXPECT--
|
||||
cybermut extension is available
|
||||
+1
-1
@@ -26,7 +26,7 @@ AC_DEFUN(AC_PREFERRED_DB_LIB,[
|
||||
|
||||
|
||||
PHP_ARG_WITH(db, for xDBM support,
|
||||
[ --with-db Include old xDBM support (deprecated use --with-dba)])
|
||||
[ --with-db Include old xDBM support (deprecated)])
|
||||
|
||||
if test "$PHP_DB" != "no"; then
|
||||
|
||||
|
||||
+22
-51
@@ -38,9 +38,15 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_FILE_H
|
||||
#ifdef PHP_31
|
||||
#include "os/nt/flock.h"
|
||||
#else
|
||||
#ifdef PHP_WIN32
|
||||
#include "win32/flock.h"
|
||||
#else
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
@@ -160,8 +166,8 @@ dbm_info *php_find_dbm(pval *id TSRMLS_DC)
|
||||
int info_type;
|
||||
|
||||
if (Z_TYPE_P(id) == IS_STRING) {
|
||||
numitems = zend_hash_next_free_element(&EG(regular_list));
|
||||
for (i=1; i<numitems; i++) {
|
||||
numitems = zend_hash_num_elements(&EG(regular_list));
|
||||
for (i=1; i<=numitems; i++) {
|
||||
if (zend_hash_index_find(&EG(regular_list), i, (void **) &le)==FAILURE) {
|
||||
continue;
|
||||
}
|
||||
@@ -183,39 +189,6 @@ dbm_info *php_find_dbm(pval *id TSRMLS_DC)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto array dblist(void)
|
||||
Return an associative array id->filename */
|
||||
#if HELLY_0
|
||||
/* New function not needed yet */
|
||||
PHP_FUNCTION(db_id_list)
|
||||
{
|
||||
ulong numitems, i;
|
||||
zend_rsrc_list_entry *le;
|
||||
dbm_info *info;
|
||||
|
||||
if (ZEND_NUM_ARGS()!=0) {
|
||||
ZEND_WRONG_PARAM_COUNT();
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (array_init(return_value) == FAILURE) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to initialize array");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
numitems = zend_hash_next_free_element(&EG(regular_list));
|
||||
for (i=1; i<numitems; i++) {
|
||||
if (zend_hash_index_find(&EG(regular_list), i, (void **) &le)==FAILURE) {
|
||||
continue;
|
||||
}
|
||||
if (Z_TYPE_P(le) == le_db) {
|
||||
info = (dbm_info *)(le->ptr);
|
||||
add_next_index_string(return_value, info->filename, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
#endif
|
||||
|
||||
/* {{{ php_get_info_db
|
||||
*/
|
||||
static char *php_get_info_db(void)
|
||||
@@ -396,7 +369,7 @@ dbm_info *php_dbm_open(char *filename, char *mode TSRMLS_DC)
|
||||
if (dbf) {
|
||||
info = (dbm_info *)emalloc(sizeof(dbm_info));
|
||||
if (!info) {
|
||||
php_error_docref1(NULL TSRMLS_CC, filename, E_ERROR, "Problem allocating memory!");
|
||||
php_error_docref1(NULL TSRMLS_CC, filename, E_ERROR, "Oroblem allocating memory!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -916,17 +889,17 @@ int flatfile_store(FILE *dbf, datum key_datum, datum value_datum, int mode) {
|
||||
fseek(dbf, 0L, SEEK_END);
|
||||
fprintf(dbf, "%d\n", key_datum.dsize);
|
||||
fflush(dbf);
|
||||
ret = fwrite(key_datum.dptr, sizeof(char), key_datum.dsize, dbf);
|
||||
ret = write(fileno(dbf), key_datum.dptr, key_datum.dsize);
|
||||
fprintf(dbf, "%d\n", value_datum.dsize);
|
||||
fflush(dbf);
|
||||
ret = fwrite(value_datum.dptr, sizeof(char), value_datum.dsize, dbf);
|
||||
ret = write(fileno(dbf), value_datum.dptr, value_datum.dsize);
|
||||
} else { /* DBM_REPLACE */
|
||||
flatfile_delete(dbf, key_datum);
|
||||
fprintf(dbf, "%d\n", key_datum.dsize);
|
||||
fflush(dbf);
|
||||
ret = fwrite(key_datum.dptr, sizeof(char), key_datum.dsize, dbf);
|
||||
ret = write(fileno(dbf), key_datum.dptr, key_datum.dsize);
|
||||
fprintf(dbf, "%d\n", value_datum.dsize);
|
||||
ret = fwrite(value_datum.dptr, sizeof(char), value_datum.dsize, dbf);
|
||||
ret = write(fileno(dbf), value_datum.dptr, value_datum.dsize);
|
||||
}
|
||||
|
||||
if (ret>0)
|
||||
@@ -948,9 +921,9 @@ datum flatfile_fetch(FILE *dbf, datum key_datum) {
|
||||
num = atoi(buf);
|
||||
if (num > buf_size) {
|
||||
buf_size+=num;
|
||||
buf = erealloc(buf, (buf_size+1)*sizeof(char));
|
||||
buf = emalloc((buf_size+1)*sizeof(char));
|
||||
}
|
||||
fread(buf, sizeof(char), num, dbf);
|
||||
read(fileno(dbf), buf, num);
|
||||
value_datum.dptr = buf;
|
||||
value_datum.dsize = num;
|
||||
}
|
||||
@@ -979,7 +952,8 @@ int flatfile_delete(FILE *dbf, datum key_datum) {
|
||||
num = atoi(buf);
|
||||
if (num > buf_size) {
|
||||
buf_size += num;
|
||||
buf = erealloc(buf, (buf_size+1)*sizeof(char));
|
||||
if (buf) efree(buf);
|
||||
buf = emalloc((buf_size+1)*sizeof(char));
|
||||
}
|
||||
pos = ftell(dbf);
|
||||
|
||||
@@ -1079,7 +1053,7 @@ datum flatfile_firstkey(FILE *dbf) {
|
||||
if (buf.dptr) efree(buf.dptr);
|
||||
buf.dptr = emalloc((buf_size+1)*sizeof(char));
|
||||
}
|
||||
num = fread(buf.dptr, sizeof(char), num, dbf);
|
||||
num=read(fileno(dbf), buf.dptr, num);
|
||||
if (num<0) break;
|
||||
buf.dsize = num;
|
||||
if (*(buf.dptr)!=0) {
|
||||
@@ -1093,7 +1067,7 @@ datum flatfile_firstkey(FILE *dbf) {
|
||||
if (buf.dptr) efree(buf.dptr);
|
||||
buf.dptr = emalloc((buf_size+1)*sizeof(char));
|
||||
}
|
||||
num = fread(buf.dptr, sizeof(char), num, dbf);
|
||||
num=read(fileno(dbf), buf.dptr, num);
|
||||
if (num<0) break;
|
||||
}
|
||||
if (buf.dptr) efree(buf.dptr);
|
||||
@@ -1119,7 +1093,7 @@ datum flatfile_nextkey(FILE *dbf) {
|
||||
if (buf.dptr) efree(buf.dptr);
|
||||
buf.dptr = emalloc((buf_size+1)*sizeof(char));
|
||||
}
|
||||
num = fread(buf.dptr, sizeof(char), num, dbf);
|
||||
num=read(fileno(dbf), buf.dptr, num);
|
||||
if (num<0) break;
|
||||
if (!fgets(buf.dptr, 15, dbf)) break;
|
||||
num = atoi(buf.dptr);
|
||||
@@ -1128,7 +1102,7 @@ datum flatfile_nextkey(FILE *dbf) {
|
||||
if (buf.dptr) efree(buf.dptr);
|
||||
buf.dptr = emalloc((buf_size+1)*sizeof(char));
|
||||
}
|
||||
num = fread(buf.dptr, sizeof(char), num, dbf);
|
||||
num=read(fileno(dbf), buf.dptr, num);
|
||||
if (num<0) break;
|
||||
buf.dsize = num;
|
||||
if (*(buf.dptr)!=0) {
|
||||
@@ -1176,9 +1150,6 @@ function_entry dbm_functions[] = {
|
||||
PHP_FE(dbmdelete, NULL)
|
||||
PHP_FE(dbmfirstkey, NULL)
|
||||
PHP_FE(dbmnextkey, NULL)
|
||||
#if HELLY_0
|
||||
PHP_FE(db_id_list, NULL)
|
||||
#endif
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/* }}} */
|
||||
|
||||
@@ -97,12 +97,20 @@ LINK32=link.exe
|
||||
|
||||
SOURCE=.\db.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\standard\flock_compat.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\standard\flock_compat.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\php_db.h
|
||||
# End Source File
|
||||
# End Group
|
||||
|
||||
@@ -2,15 +2,12 @@
|
||||
DBM File Creation Test
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("db")) print "skip"; ?>
|
||||
--POST--
|
||||
--GET--
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('test.inc');
|
||||
if (dbmopen($db_file, "n") && file_exists($db_file)) {
|
||||
echo "database file created\n";
|
||||
} else {
|
||||
echo "$db_file does not exist\n";
|
||||
}
|
||||
dbmclose($db_file);
|
||||
dbmopen("./test.dbm","n");
|
||||
dbmclose("./test.dbm");
|
||||
?>
|
||||
--EXPECT--
|
||||
database file created
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
--TEST--
|
||||
DBM Insert/Fetch Test
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("db")) print "skip";?>
|
||||
<?php if (!extension_loaded("db")) print "skip"; ?>
|
||||
--POST--
|
||||
--GET--
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('test.inc');
|
||||
if (dbmopen($db_file, "n")) {
|
||||
dbminsert($db_file, "key1", "This is a test insert");
|
||||
echo dbmfetch($db_file, "key1");
|
||||
dbmclose($db_file);
|
||||
} else {
|
||||
echo "Error creating database\n";
|
||||
}
|
||||
dbmopen("./test.dbm","n");
|
||||
dbminsert("./test.dbm","key1","This is a test insert");
|
||||
$a = dbmfetch("./test.dbm","key1");
|
||||
dbmclose("./test.dbm");
|
||||
echo $a
|
||||
?>
|
||||
--EXPECT--
|
||||
This is a test insert
|
||||
+8
-11
@@ -2,19 +2,16 @@
|
||||
DBM Insert/Replace/Fetch Test
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("db")) print "skip"; ?>
|
||||
--POST--
|
||||
--GET--
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('test.inc');
|
||||
if (dbmopen($db_file, "n")) {
|
||||
dbminsert($db_file, "key1", "This is a test insert");
|
||||
dbmreplace($db_file, "key1", "This is the replacement text");
|
||||
@dbminsert($db_file, "key1", "This is another replacement text?");
|
||||
$a = dbmfetch($db_file, "key1");
|
||||
dbmclose($db_file);
|
||||
echo $a;
|
||||
} else {
|
||||
echo "Error creating database\n";
|
||||
}
|
||||
dbmopen("./test.dbm","n");
|
||||
dbminsert("./test.dbm","key1","This is a test insert");
|
||||
dbmreplace("./test.dbm","key1","This is the replacement text");
|
||||
$a = dbmfetch("./test.dbm","key1");
|
||||
dbmclose("./test.dbm");
|
||||
echo $a
|
||||
?>
|
||||
--EXPECT--
|
||||
This is the replacement text
|
||||
+12
-14
@@ -2,22 +2,20 @@
|
||||
DBM Multiple Insert/Fetch Test
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("db")) print "skip"; ?>
|
||||
--POST--
|
||||
--GET--
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('test.inc');
|
||||
if (dbmopen($db_file, "n")) {
|
||||
dbminsert($db_file, "key1", "Content String 1");
|
||||
dbminsert($db_file, "key2", "Content String 2");
|
||||
dbminsert($db_file, "key3", "Third Content String");
|
||||
dbminsert($db_file, "key4", "Another Content String");
|
||||
dbminsert($db_file, "key5", "The last content string");
|
||||
$a = dbmfetch($db_file, "key4");
|
||||
$b = dbmfetch($db_file, "key2");
|
||||
dbmclose($db_file);
|
||||
echo "$a $b";
|
||||
} else {
|
||||
echo "Error creating database\n";
|
||||
}
|
||||
dbmopen("./test.dbm","n");
|
||||
dbminsert("./test.dbm","key1","Content String 1");
|
||||
dbminsert("./test.dbm","key2","Content String 2");
|
||||
dbminsert("./test.dbm","key3","Third Content String");
|
||||
dbminsert("./test.dbm","key4","Another Content String");
|
||||
dbminsert("./test.dbm","key5","The last content string");
|
||||
$a = dbmfetch("./test.dbm","key4");
|
||||
$b = dbmfetch("./test.dbm","key2");
|
||||
dbmclose("./test.dbm");
|
||||
echo "$a $b";
|
||||
?>
|
||||
--EXPECT--
|
||||
Another Content String Content String 2
|
||||
+15
-17
@@ -2,26 +2,24 @@
|
||||
DBM FirstKey/NextKey Loop Test With 5 Items
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("db")) print "skip"; ?>
|
||||
--POST--
|
||||
--GET--
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('test.inc');
|
||||
if (dbmopen($db_file, "n")) {
|
||||
dbminsert($db_file, "key1", "Content String 1");
|
||||
dbminsert($db_file, "key2", "Content String 2");
|
||||
dbminsert($db_file, "key3", "Third Content String");
|
||||
dbminsert($db_file, "key4", "Another Content String");
|
||||
dbminsert($db_file, "key5", "The last content string");
|
||||
$a = dbmfirstkey($db_file);
|
||||
$i=0;
|
||||
while($a) {
|
||||
$a = dbmnextkey($db_file, $a);
|
||||
$i++;
|
||||
}
|
||||
dbmclose($db_file);
|
||||
echo $i;
|
||||
} else {
|
||||
echo "Error creating database\n";
|
||||
dbmopen("./test.dbm","n");
|
||||
dbminsert("./test.dbm","key1","Content String 1");
|
||||
dbminsert("./test.dbm","key2","Content String 2");
|
||||
dbminsert("./test.dbm","key3","Third Content String");
|
||||
dbminsert("./test.dbm","key4","Another Content String");
|
||||
dbminsert("./test.dbm","key5","The last content string");
|
||||
$a = dbmfirstkey("./test.dbm");
|
||||
$i=0;
|
||||
while($a) {
|
||||
$a = dbmnextkey("./test.dbm",$a);
|
||||
$i++;
|
||||
}
|
||||
dbmclose("./test.dbm");
|
||||
echo $i
|
||||
?>
|
||||
--EXPECT--
|
||||
5
|
||||
+17
-19
@@ -2,28 +2,26 @@
|
||||
DBM FirstKey/NextKey with 2 deletes
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("db")) print "skip"; ?>
|
||||
--POST--
|
||||
--GET--
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('test.inc');
|
||||
if (dbmopen($db_file, "n")) {
|
||||
dbminsert($db_file, "key1", "Content String 1");
|
||||
dbminsert($db_file, "key2", "Content String 2");
|
||||
dbminsert($db_file, "key3", "Third Content String");
|
||||
dbminsert($db_file, "key4", "Another Content String");
|
||||
dbminsert($db_file, "key5", "The last content string");
|
||||
dbmdelete($db_file, "key3");
|
||||
dbmdelete($db_file, "key1");
|
||||
$a = dbmfirstkey($db_file);
|
||||
$i=0;
|
||||
while($a) {
|
||||
$a = dbmnextkey($db_file, $a);
|
||||
$i++;
|
||||
}
|
||||
dbmclose($db_file);
|
||||
echo $i;
|
||||
} else {
|
||||
echo "Error creating database\n";
|
||||
dbmopen("./test.dbm","n");
|
||||
dbminsert("./test.dbm","key1","Content String 1");
|
||||
dbminsert("./test.dbm","key2","Content String 2");
|
||||
dbminsert("./test.dbm","key3","Third Content String");
|
||||
dbminsert("./test.dbm","key4","Another Content String");
|
||||
dbminsert("./test.dbm","key5","The last content string");
|
||||
dbmdelete("./test.dbm","key3");
|
||||
dbmdelete("./test.dbm","key1");
|
||||
$a = dbmfirstkey("./test.dbm");
|
||||
$i=0;
|
||||
while($a) {
|
||||
$a = dbmnextkey("./test.dbm",$a);
|
||||
$i++;
|
||||
}
|
||||
dbmclose("./test.dbm");
|
||||
echo $i
|
||||
?>
|
||||
--EXPECT--
|
||||
3
|
||||
@@ -1,3 +0,0 @@
|
||||
<?php
|
||||
$db_file = dirname(__FILE__).'/test.dbm';
|
||||
?>
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
DBA
|
||||
Sascha Schumann, Marcus Boerger
|
||||
Sascha Schumann
|
||||
+8
-46
@@ -2,8 +2,6 @@ dnl
|
||||
dnl $Id$
|
||||
dnl
|
||||
|
||||
dnl Suppose we need FlatFile if no or only CDB is used.
|
||||
|
||||
AC_DEFUN(PHP_TEMP_LDFLAGS,[
|
||||
old_LDFLAGS=$LDFLAGS
|
||||
LDFLAGS="$1 $LDFLAGS"
|
||||
@@ -11,6 +9,7 @@ AC_DEFUN(PHP_TEMP_LDFLAGS,[
|
||||
LDFLAGS=$old_LDFLAGS
|
||||
])
|
||||
|
||||
|
||||
dnl Assign INCLUDE/LFLAGS from PREFIX
|
||||
AC_DEFUN(PHP_DBA_STD_ASSIGN,[
|
||||
if test -n "$THIS_PREFIX" && test "$THIS_PREFIX" != "/usr"; then
|
||||
@@ -39,9 +38,9 @@ AC_DEFUN(PHP_DBA_STD_ATTACH,[
|
||||
|
||||
dnl Print the result message
|
||||
AC_DEFUN(AC_DBA_STD_RESULT,[
|
||||
if test "$THIS_RESULT" = "yes" -o "$THIS_RESULT" = "builtin"; then
|
||||
if test "$THIS_RESULT" = "yes"; then
|
||||
HAVE_DBA=1
|
||||
AC_MSG_RESULT($THIS_RESULT)
|
||||
AC_MSG_RESULT(yes)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
@@ -49,7 +48,7 @@ AC_DEFUN(AC_DBA_STD_RESULT,[
|
||||
])
|
||||
|
||||
PHP_ARG_ENABLE(dba,whether to enable DBA,
|
||||
[ --enable-dba Build DBA with builtin modules])
|
||||
[ --enable-dba=shared Build DBA as a shared module])
|
||||
|
||||
AC_ARG_WITH(gdbm,
|
||||
[ --with-gdbm[=DIR] Include GDBM support],[
|
||||
@@ -175,7 +174,7 @@ AC_ARG_WITH(db3,
|
||||
AC_DEFINE_UNQUOTED(DB3_INCLUDE_FILE, "$DB3_EXTRA", [ ])
|
||||
fi
|
||||
|
||||
for LIB in db-3.1 db-3 db3 db; do
|
||||
for LIB in db-3 db3 db; do
|
||||
PHP_TEMP_LDFLAGS(-L$THIS_PREFIX/lib,[
|
||||
AC_CHECK_LIB($LIB, db_create, [AC_DEFINE(DBA_DB3,1,[ ]) THIS_LIBS=$LIB])
|
||||
])
|
||||
@@ -212,25 +211,14 @@ AC_ARG_WITH(dbm,
|
||||
AC_MSG_CHECKING(for DBM support)
|
||||
AC_DBA_STD_RESULT
|
||||
|
||||
AC_DEFUN(PHP_DBA_BUILTIN_CDB,[
|
||||
PHP_ADD_BUILD_DIR($ext_builddir/libcdb)
|
||||
AC_DEFINE(DBA_CDB_BUILTIN, 1, [ ])
|
||||
AC_DEFINE(DBA_CDB_MAKE, 1, [ ])
|
||||
AC_DEFINE(DBA_CDB, 1, [ ])
|
||||
cdb_sources="libcdb/cdb.c libcdb/cdb_make.c libcdb/uint32.c"
|
||||
THIS_RESULT="builtin"
|
||||
])
|
||||
|
||||
AC_ARG_WITH(cdb,
|
||||
[ --with-cdb[=DIR] Include CDB support],[
|
||||
if test "$withval" != "no"; then
|
||||
PHP_DBA_BUILTIN_CDB
|
||||
elif test "$withval" != "no"; then
|
||||
for i in /usr/local /usr $withval; do
|
||||
if test -f "$i/include/cdb.h" ; then
|
||||
THIS_PREFIX=$i
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
for LIB in cdb c; do
|
||||
PHP_TEMP_LDFLAGS(-L$THIS_PREFIX/lib,[
|
||||
@@ -242,43 +230,17 @@ AC_ARG_WITH(cdb,
|
||||
PHP_DBA_STD_CHECK
|
||||
PHP_DBA_STD_ATTACH
|
||||
fi
|
||||
],[
|
||||
if test "$PHP_DBA" != "no"; then
|
||||
PHP_DBA_BUILTIN_CDB
|
||||
fi
|
||||
])
|
||||
AC_MSG_CHECKING(for CDB support)
|
||||
AC_DBA_STD_RESULT
|
||||
|
||||
AC_DEFUN(PHP_DBA_BUILTIN_FLATFILE,[
|
||||
PHP_ADD_BUILD_DIR($ext_builddir/libflatfile)
|
||||
AC_DEFINE(DBA_FLATFILE, 1, [ ])
|
||||
flat_sources="dba_flatfile.c libflatfile/flatfile.c"
|
||||
THIS_RESULT="builtin"
|
||||
])
|
||||
|
||||
dnl
|
||||
dnl FlatFile check must be the last one.
|
||||
dnl
|
||||
AC_ARG_WITH(flatfile,
|
||||
[ --with-flatfile Include FlatFile support],[
|
||||
if test "$withval" != "no"; then
|
||||
PHP_DBA_BUILTIN_FLATFILE
|
||||
fi
|
||||
],[
|
||||
if test "$PHP_DBA" != "no"; then
|
||||
PHP_DBA_BUILTIN_FLATFILE
|
||||
fi
|
||||
])
|
||||
AC_MSG_CHECKING(for FlatFile support)
|
||||
AC_DBA_STD_RESULT
|
||||
|
||||
AC_MSG_CHECKING(whether to enable DBA interface)
|
||||
if test "$HAVE_DBA" = "1"; then
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(HAVE_DBA, 1, [ ])
|
||||
PHP_NEW_EXTENSION(dba, dba.c dba_cdb.c dba_db2.c dba_dbm.c dba_gdbm.c dba_ndbm.c dba_db3.c $cdb_sources $flat_sources, $ext_shared)
|
||||
PHP_NEW_EXTENSION(dba, dba.c dba_cdb.c dba_db2.c dba_dbm.c dba_gdbm.c dba_ndbm.c dba_db3.c, $ext_shared)
|
||||
PHP_SUBST(DBA_SHARED_LIBADD)
|
||||
else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
+59
-321
@@ -12,8 +12,7 @@
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Authors: Sascha Schumann <sascha@schumann.cx> |
|
||||
| Marcus Boerger <helly@php.net> |
|
||||
| Author: Sascha Schumann <sascha@schumann.cx> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
@@ -27,16 +26,8 @@
|
||||
|
||||
#if HAVE_DBA
|
||||
|
||||
#include "ext/standard/flock_compat.h"
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#ifdef HAVE_SYS_FILE_H
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
|
||||
#include "php_dba.h"
|
||||
#include "ext/standard/info.h"
|
||||
#include "ext/standard/php_string.h"
|
||||
|
||||
#include "php_gdbm.h"
|
||||
#include "php_ndbm.h"
|
||||
@@ -44,7 +35,6 @@
|
||||
#include "php_cdb.h"
|
||||
#include "php_db2.h"
|
||||
#include "php_db3.h"
|
||||
#include "php_flatfile.h"
|
||||
|
||||
/* {{{ dba_functions[]
|
||||
*/
|
||||
@@ -61,8 +51,6 @@ function_entry dba_functions[] = {
|
||||
PHP_FE(dba_nextkey, NULL)
|
||||
PHP_FE(dba_optimize, NULL)
|
||||
PHP_FE(dba_sync, NULL)
|
||||
PHP_FE(dba_handlers, NULL)
|
||||
PHP_FE(dba_list, NULL)
|
||||
{NULL, NULL, NULL}
|
||||
};
|
||||
/* }}} */
|
||||
@@ -88,18 +76,17 @@ ZEND_GET_MODULE(dba)
|
||||
#endif
|
||||
|
||||
typedef struct dba_handler {
|
||||
char *name; /* handler name */
|
||||
int flags; /* whether and how dba does locking and other flags*/
|
||||
int (*open)(dba_info *, char **error TSRMLS_DC);
|
||||
void (*close)(dba_info * TSRMLS_DC);
|
||||
char* (*fetch)(dba_info *, char *, int, int, int * TSRMLS_DC);
|
||||
int (*update)(dba_info *, char *, int, char *, int, int TSRMLS_DC);
|
||||
int (*exists)(dba_info *, char *, int TSRMLS_DC);
|
||||
int (*delete)(dba_info *, char *, int TSRMLS_DC);
|
||||
char* (*firstkey)(dba_info *, int * TSRMLS_DC);
|
||||
char* (*nextkey)(dba_info *, int * TSRMLS_DC);
|
||||
int (*optimize)(dba_info * TSRMLS_DC);
|
||||
int (*sync)(dba_info * TSRMLS_DC);
|
||||
char *name;
|
||||
int (*open)(dba_info * TSRMLS_DC);
|
||||
void (*close)(dba_info *);
|
||||
char* (*fetch)(dba_info *, char *, int, int *);
|
||||
int (*update)(dba_info *, char *, int, char *, int, int);
|
||||
int (*exists)(dba_info *, char *, int);
|
||||
int (*delete)(dba_info *, char *, int);
|
||||
char* (*firstkey)(dba_info *, int *);
|
||||
char* (*nextkey)(dba_info *, int *);
|
||||
int (*optimize)(dba_info *);
|
||||
int (*sync)(dba_info *);
|
||||
} dba_handler;
|
||||
|
||||
/* {{{ macromania */
|
||||
@@ -123,50 +110,25 @@ typedef struct dba_handler {
|
||||
} \
|
||||
convert_to_string_ex(key)
|
||||
|
||||
#define DBA_GET2_3 \
|
||||
zval **key; \
|
||||
zval **tmp; \
|
||||
int skip = 0; \
|
||||
switch(ac) { \
|
||||
case 2: \
|
||||
if (zend_get_parameters_ex(ac, &key, &id) != SUCCESS) { \
|
||||
WRONG_PARAM_COUNT; \
|
||||
} \
|
||||
break; \
|
||||
case 3: \
|
||||
if (zend_get_parameters_ex(ac, &key, &tmp, &id) != SUCCESS) { \
|
||||
WRONG_PARAM_COUNT; \
|
||||
} \
|
||||
convert_to_long_ex(tmp); \
|
||||
skip = Z_LVAL_PP(tmp); \
|
||||
break; \
|
||||
default: \
|
||||
WRONG_PARAM_COUNT; \
|
||||
} \
|
||||
convert_to_string_ex(key)
|
||||
|
||||
#define DBA_ID_GET \
|
||||
ZEND_FETCH_RESOURCE2(info, dba_info *, id, -1, "DBA identifier", le_db, le_pdb);
|
||||
|
||||
#define DBA_ID_GET1 DBA_ID_PARS; DBA_GET1; DBA_ID_GET
|
||||
#define DBA_ID_GET2 DBA_ID_PARS; DBA_GET2; DBA_ID_GET
|
||||
#define DBA_ID_GET2_3 DBA_ID_PARS; DBA_GET2_3; DBA_ID_GET
|
||||
#define DBA_ID_GET1 DBA_ID_PARS; DBA_GET1; DBA_ID_GET
|
||||
#define DBA_ID_GET2 DBA_ID_PARS; DBA_GET2; DBA_ID_GET
|
||||
|
||||
/* a DBA handler must have specific routines */
|
||||
|
||||
#define DBA_NAMED_HND(name, x, flags) \
|
||||
#define DBA_HND(x) \
|
||||
{\
|
||||
#name, flags, dba_open_##x, dba_close_##x, dba_fetch_##x, dba_update_##x, \
|
||||
#x, dba_open_##x, dba_close_##x, dba_fetch_##x, dba_update_##x, \
|
||||
dba_exists_##x, dba_delete_##x, dba_firstkey_##x, dba_nextkey_##x, \
|
||||
dba_optimize_##x, dba_sync_##x \
|
||||
},
|
||||
|
||||
#define DBA_HND(x, flags) DBA_NAMED_HND(x, x, flags)
|
||||
|
||||
/* check whether the user has write access */
|
||||
#define DBA_WRITE_CHECK \
|
||||
if(info->mode != DBA_WRITER && info->mode != DBA_TRUNC && info->mode != DBA_CREAT) { \
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "You cannot perform a modification to a database without proper access"); \
|
||||
php_error(E_WARNING, "%s(): you cannot perform a modification to a database without proper access", get_active_function_name(TSRMLS_C)); \
|
||||
RETURN_FALSE; \
|
||||
}
|
||||
|
||||
@@ -176,30 +138,24 @@ typedef struct dba_handler {
|
||||
|
||||
static dba_handler handler[] = {
|
||||
#if DBA_GDBM
|
||||
DBA_HND(gdbm, DBA_LOCK_EXT) /* Locking done in library if set */
|
||||
DBA_HND(gdbm)
|
||||
#endif
|
||||
#if DBA_DBM
|
||||
DBA_HND(dbm, DBA_LOCK_ALL) /* No lock in lib */
|
||||
DBA_HND(dbm)
|
||||
#endif
|
||||
#if DBA_NDBM
|
||||
DBA_HND(ndbm, DBA_LOCK_ALL) /* Could be done in library: filemode = 0644 + S_ENFMT */
|
||||
DBA_HND(ndbm)
|
||||
#endif
|
||||
#if DBA_CDB
|
||||
DBA_HND(cdb, DBA_STREAM_OPEN|DBA_LOCK_ALL) /* No lock in lib */
|
||||
#endif
|
||||
#if DBA_CDB_BUILTIN
|
||||
DBA_NAMED_HND(cdb_make, cdb, DBA_STREAM_OPEN|DBA_LOCK_ALL) /* No lock in lib */
|
||||
DBA_HND(cdb)
|
||||
#endif
|
||||
#if DBA_DB2
|
||||
DBA_HND(db2, DBA_LOCK_ALL) /* No lock in lib */
|
||||
DBA_HND(db2)
|
||||
#endif
|
||||
#if DBA_DB3
|
||||
DBA_HND(db3, DBA_LOCK_ALL) /* No lock in lib */
|
||||
DBA_HND(db3)
|
||||
#endif
|
||||
#if DBA_FLATFILE
|
||||
DBA_HND(flatfile, DBA_STREAM_OPEN|DBA_LOCK_ALL) /* No lock in lib */
|
||||
#endif
|
||||
{ NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
|
||||
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
static int le_db;
|
||||
@@ -208,19 +164,11 @@ static int le_pdb;
|
||||
|
||||
/* {{{ dba_close
|
||||
*/
|
||||
static void dba_close(dba_info *info TSRMLS_DC)
|
||||
static void dba_close(dba_info *info)
|
||||
{
|
||||
if (info->hnd) info->hnd->close(info TSRMLS_CC);
|
||||
if (info->path) efree(info->path);
|
||||
if (info->fp && info->fp!=info->lock.fp) php_stream_close(info->fp);
|
||||
if (info->lock.fd) {
|
||||
php_flock(info->lock.fd, LOCK_UN);
|
||||
close(info->lock.fd);
|
||||
info->lock.fd = 0;
|
||||
}
|
||||
if (info->lock.fp) php_stream_close(info->lock.fp);
|
||||
if (info->lock.name) efree(info->lock.name);
|
||||
efree(info);
|
||||
if(info->hnd) info->hnd->close(info);
|
||||
if(info->path) free(info->path);
|
||||
free(info);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -230,7 +178,7 @@ static void dba_close_rsrc(zend_rsrc_list_entry *rsrc TSRMLS_DC)
|
||||
{
|
||||
dba_info *info = (dba_info *)rsrc->ptr;
|
||||
|
||||
dba_close(info TSRMLS_CC);
|
||||
dba_close(info);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -285,8 +233,6 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode)
|
||||
{
|
||||
DBA_ID_PARS;
|
||||
zval **val, **key;
|
||||
char *v;
|
||||
int len;
|
||||
|
||||
if(ac != 3 || zend_get_parameters_ex(ac, &key, &val, &id) != SUCCESS) {
|
||||
WRONG_PARAM_COUNT;
|
||||
@@ -297,50 +243,14 @@ static void php_dba_update(INTERNAL_FUNCTION_PARAMETERS, int mode)
|
||||
|
||||
DBA_WRITE_CHECK;
|
||||
|
||||
if (PG(magic_quotes_runtime)) {
|
||||
len = Z_STRLEN_PP(val);
|
||||
v = estrndup(Z_STRVAL_PP(val), len);
|
||||
php_stripslashes(v, &len TSRMLS_CC);
|
||||
if(info->hnd->update(info, VALLEN(key), v, len, mode TSRMLS_CC) == SUCCESS) {
|
||||
efree(v);
|
||||
RETURN_TRUE;
|
||||
}
|
||||
efree(v);
|
||||
} else {
|
||||
if(info->hnd->update(info, VALLEN(key), VALLEN(val), mode TSRMLS_CC) == SUCCESS)
|
||||
RETURN_TRUE;
|
||||
}
|
||||
if(info->hnd->update(info, VALLEN(key), VALLEN(val), mode) == SUCCESS)
|
||||
RETURN_TRUE;
|
||||
RETURN_FALSE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#define FREENOW if(args) efree(args); if(key) efree(key)
|
||||
|
||||
/* {{{ php_find_dbm
|
||||
*/
|
||||
dba_info *php_dba_find(const char* path TSRMLS_DC)
|
||||
{
|
||||
list_entry *le;
|
||||
dba_info *info;
|
||||
int numitems, i;
|
||||
|
||||
numitems = zend_hash_next_free_element(&EG(regular_list));
|
||||
for (i=1; i<numitems; i++) {
|
||||
if (zend_hash_index_find(&EG(regular_list), i, (void **) &le)==FAILURE) {
|
||||
continue;
|
||||
}
|
||||
if (Z_TYPE_P(le) == le_db || Z_TYPE_P(le) == le_pdb) {
|
||||
info = (dba_info *)(le->ptr);
|
||||
if (!strcmp(info->path, path)) {
|
||||
return (dba_info *)(le->ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ php_dba_open
|
||||
*/
|
||||
static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
|
||||
@@ -348,14 +258,11 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
|
||||
zval ***args = (zval ***) NULL;
|
||||
int ac = ZEND_NUM_ARGS();
|
||||
dba_mode_t modenr;
|
||||
dba_info *info, *other;
|
||||
dba_info *info;
|
||||
dba_handler *hptr;
|
||||
char *key = NULL, *error = NULL;
|
||||
char *key = NULL;
|
||||
int keylen = 0;
|
||||
int i;
|
||||
int lock_mode, lock_flag, lock_dbf = 0;
|
||||
char *file_mode;
|
||||
char mode[4], *pmode, *lock_file_mode;
|
||||
|
||||
if(ac < 3) {
|
||||
WRONG_PARAM_COUNT;
|
||||
@@ -404,153 +311,41 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
|
||||
for (hptr = handler; hptr->name && strcasecmp(hptr->name, Z_STRVAL_PP(args[2])); hptr++);
|
||||
|
||||
if (!hptr->name) {
|
||||
php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "No such handler: %s", Z_STRVAL_PP(args[2]));
|
||||
php_error(E_WARNING, "%s(): no such handler: %s", get_active_function_name(TSRMLS_C), Z_STRVAL_PP(args[2]));
|
||||
FREENOW;
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
/* Check mode: [rwnc][fl]?t?
|
||||
* r: Read
|
||||
* w: Write
|
||||
* n: Create/Truncate
|
||||
* c: Create
|
||||
*
|
||||
* d: force lock on database file
|
||||
* l: force lock on lck file
|
||||
*
|
||||
* t: test open database, warning if locked
|
||||
*/
|
||||
strlcpy(mode, Z_STRVAL_PP(args[1]), sizeof(mode));
|
||||
pmode = &mode[0];
|
||||
if (pmode[0] && (pmode[1]=='d' || pmode[1]=='l')) { /* force lock on db file or lck file */
|
||||
if (pmode[1]=='d') {
|
||||
if ((hptr->flags & DBA_LOCK_ALL) == 0) {
|
||||
php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_NOTICE, "Handler %s does locking internally", hptr->name);
|
||||
}
|
||||
lock_dbf = 1;
|
||||
}
|
||||
lock_flag = DBA_LOCK_ALL;
|
||||
} else {
|
||||
lock_flag = (hptr->flags&DBA_LOCK_ALL);
|
||||
}
|
||||
switch (*pmode++) {
|
||||
case 'r':
|
||||
modenr = DBA_READER;
|
||||
lock_mode = (lock_flag & DBA_LOCK_READER) ? LOCK_SH : 0;
|
||||
file_mode = "r";
|
||||
switch (Z_STRVAL_PP(args[1])[0]) {
|
||||
case 'c':
|
||||
modenr = DBA_CREAT;
|
||||
break;
|
||||
case 'w':
|
||||
modenr = DBA_WRITER;
|
||||
lock_mode = (lock_flag & DBA_LOCK_WRITER) ? LOCK_EX : 0;
|
||||
file_mode = "r+b";
|
||||
break;
|
||||
case 'r':
|
||||
modenr = DBA_READER;
|
||||
break;
|
||||
case 'n':
|
||||
modenr = DBA_TRUNC;
|
||||
lock_mode = (lock_flag & DBA_LOCK_TRUNC) ? LOCK_EX : 0;
|
||||
file_mode = "w+b";
|
||||
break;
|
||||
case 'c':
|
||||
modenr = DBA_CREAT;
|
||||
lock_mode = (lock_flag & DBA_LOCK_CREAT) ? LOCK_EX : 0;
|
||||
file_mode = "a+b";
|
||||
break;
|
||||
default:
|
||||
modenr = 0;
|
||||
lock_mode = 0;
|
||||
file_mode = "";
|
||||
}
|
||||
if (*pmode=='d' || *pmode=='l') {
|
||||
pmode++; /* done already - skip here */
|
||||
}
|
||||
if (*pmode=='t') {
|
||||
pmode++;
|
||||
if (!lock_mode) {
|
||||
if ((hptr->flags & DBA_LOCK_ALL) == 0) {
|
||||
php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Handler %s uses its own locking which doesn't support mode modifier t (testing)", hptr->name);
|
||||
FREENOW;
|
||||
RETURN_FALSE;
|
||||
} else {
|
||||
php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Handler %s doesn't uses locking for this mode which makes modifier t (testing) obsolete", hptr->name);
|
||||
FREENOW;
|
||||
RETURN_FALSE;
|
||||
}
|
||||
} else {
|
||||
lock_mode |= LOCK_NB; /* test =: non blocking */
|
||||
}
|
||||
}
|
||||
if (*pmode || !modenr) {
|
||||
php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Illegal DBA mode");
|
||||
FREENOW;
|
||||
RETURN_FALSE;
|
||||
php_error(E_WARNING, "%s(): illegal DBA mode: %s", get_active_function_name(TSRMLS_C), Z_STRVAL_PP(args[1]));
|
||||
FREENOW;
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
info = emalloc(sizeof(dba_info));
|
||||
memset(info, 0, sizeof(dba_info));
|
||||
info->path = estrdup(Z_STRVAL_PP(args[0]));
|
||||
info = malloc(sizeof(*info));
|
||||
memset(info, 0, sizeof(info));
|
||||
info->path = strdup(Z_STRVAL_PP(args[0]));
|
||||
info->mode = modenr;
|
||||
info->argc = ac - 3;
|
||||
info->argv = args + 3;
|
||||
info->flags = (hptr->flags & ~DBA_LOCK_ALL) | (lock_flag & DBA_LOCK_ALL);
|
||||
info->lock.mode = lock_mode;
|
||||
info->hnd = NULL;
|
||||
|
||||
/* if any open call is a locking call:
|
||||
* check if we already habe a locking call open that should block this call
|
||||
* the problem is some systems would allow read during write
|
||||
*/
|
||||
if (hptr->flags & DBA_LOCK_ALL) {
|
||||
if ((other = php_dba_find(info->path TSRMLS_CC)) != NULL) {
|
||||
if ( ( (lock_mode&LOCK_EX) && (other->lock.mode&(LOCK_EX|LOCK_SH)) )
|
||||
|| ( (other->lock.mode&LOCK_EX) && (lock_mode&(LOCK_EX|LOCK_SH)) )
|
||||
) {
|
||||
error = "Unable to establish lock (database file already open)"; /* force failure exit */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!error && lock_mode) {
|
||||
if (lock_dbf) {
|
||||
info->lock.name = estrdup(info->path);
|
||||
lock_file_mode = file_mode;
|
||||
} else {
|
||||
spprintf(&info->lock.name, 0, "%s.lck", info->path);
|
||||
lock_file_mode = "a+b";
|
||||
}
|
||||
info->lock.fp = php_stream_open_wrapper(info->lock.name, lock_file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);
|
||||
if (!info->lock.fp) {
|
||||
dba_close(info TSRMLS_CC);
|
||||
/* stream operation already wrote an error message */
|
||||
FREENOW;
|
||||
RETURN_FALSE;
|
||||
}
|
||||
if (php_stream_cast(info->lock.fp, PHP_STREAM_AS_FD, (void*)&info->lock.fd, 1) == FAILURE) {
|
||||
dba_close(info TSRMLS_CC);
|
||||
/* stream operation already wrote an error message */
|
||||
FREENOW;
|
||||
RETURN_FALSE;
|
||||
}
|
||||
if (php_flock(info->lock.fd, lock_mode)) {
|
||||
error = "Unable to establish lock"; /* force failure exit */
|
||||
}
|
||||
}
|
||||
|
||||
/* centralised open stream for builtin */
|
||||
if (!error && (hptr->flags&DBA_STREAM_OPEN)==DBA_STREAM_OPEN) {
|
||||
if (info->lock.fp && lock_dbf) {
|
||||
info->fp = info->lock.fp; /* use the same stream for locking and database access */
|
||||
} else {
|
||||
info->fp = php_stream_open_wrapper(info->path, file_mode, STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);
|
||||
}
|
||||
if (!info->fp) {
|
||||
dba_close(info TSRMLS_CC);
|
||||
/* stream operation already wrote an error message */
|
||||
FREENOW;
|
||||
RETURN_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (error || hptr->open(info, &error TSRMLS_CC) != SUCCESS) {
|
||||
dba_close(info TSRMLS_CC);
|
||||
php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(args[0]), Z_STRVAL_PP(args[1]), E_WARNING, "Driver initialization failed for handler: %s%s%s", Z_STRVAL_PP(args[2]), error?": ":"", error?error:"");
|
||||
if (hptr->open(info TSRMLS_CC) != SUCCESS) {
|
||||
dba_close(info);
|
||||
php_error(E_WARNING, "%s(): driver initialization failed", get_active_function_name(TSRMLS_C));
|
||||
FREENOW;
|
||||
RETURN_FALSE;
|
||||
}
|
||||
@@ -608,28 +403,22 @@ PHP_FUNCTION(dba_exists)
|
||||
{
|
||||
DBA_ID_GET2;
|
||||
|
||||
if(info->hnd->exists(info, VALLEN(key) TSRMLS_CC) == SUCCESS) {
|
||||
if(info->hnd->exists(info, VALLEN(key)) == SUCCESS) {
|
||||
RETURN_TRUE;
|
||||
}
|
||||
RETURN_FALSE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto string dba_fetch(string key, [int skip ,] int handle)
|
||||
/* {{{ proto string dba_fetch(string key, int handle)
|
||||
Fetches the data associated with key */
|
||||
PHP_FUNCTION(dba_fetch)
|
||||
{
|
||||
char *val;
|
||||
int len = 0;
|
||||
DBA_ID_GET2_3;
|
||||
DBA_ID_GET2;
|
||||
|
||||
if (ac==3 && strcmp(info->hnd->name, "cdb")) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Handler %s does not support optional skip parameter", info->hnd->name);
|
||||
}
|
||||
if((val = info->hnd->fetch(info, VALLEN(key), skip, &len TSRMLS_CC)) != NULL) {
|
||||
if (val && PG(magic_quotes_runtime)) {
|
||||
val = php_addslashes(val, len, &len, 1 TSRMLS_CC);
|
||||
}
|
||||
if((val = info->hnd->fetch(info, VALLEN(key), &len)) != NULL) {
|
||||
RETURN_STRINGL(val, len, 0);
|
||||
}
|
||||
RETURN_FALSE;
|
||||
@@ -644,7 +433,7 @@ PHP_FUNCTION(dba_firstkey)
|
||||
int len;
|
||||
DBA_ID_GET1;
|
||||
|
||||
fkey = info->hnd->firstkey(info, &len TSRMLS_CC);
|
||||
fkey = info->hnd->firstkey(info, &len);
|
||||
if(fkey)
|
||||
RETURN_STRINGL(fkey, len, 0);
|
||||
RETURN_FALSE;
|
||||
@@ -659,7 +448,7 @@ PHP_FUNCTION(dba_nextkey)
|
||||
int len;
|
||||
DBA_ID_GET1;
|
||||
|
||||
nkey = info->hnd->nextkey(info, &len TSRMLS_CC);
|
||||
nkey = info->hnd->nextkey(info, &len);
|
||||
if(nkey)
|
||||
RETURN_STRINGL(nkey, len, 0);
|
||||
RETURN_FALSE;
|
||||
@@ -674,7 +463,7 @@ PHP_FUNCTION(dba_delete)
|
||||
|
||||
DBA_WRITE_CHECK;
|
||||
|
||||
if(info->hnd->delete(info, VALLEN(key) TSRMLS_CC) == SUCCESS)
|
||||
if(info->hnd->delete(info, VALLEN(key)) == SUCCESS)
|
||||
RETURN_TRUE;
|
||||
RETURN_FALSE;
|
||||
}
|
||||
@@ -703,7 +492,7 @@ PHP_FUNCTION(dba_optimize)
|
||||
DBA_ID_GET1;
|
||||
|
||||
DBA_WRITE_CHECK;
|
||||
if(info->hnd->optimize(info TSRMLS_CC) == SUCCESS) {
|
||||
if(info->hnd->optimize(info) == SUCCESS) {
|
||||
RETURN_TRUE;
|
||||
}
|
||||
RETURN_FALSE;
|
||||
@@ -716,64 +505,13 @@ PHP_FUNCTION(dba_sync)
|
||||
{
|
||||
DBA_ID_GET1;
|
||||
|
||||
if(info->hnd->sync(info TSRMLS_CC) == SUCCESS) {
|
||||
if(info->hnd->sync(info) == SUCCESS) {
|
||||
RETURN_TRUE;
|
||||
}
|
||||
RETURN_FALSE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto array dba_handlers()
|
||||
List configured databases */
|
||||
PHP_FUNCTION(dba_handlers)
|
||||
{
|
||||
dba_handler *hptr;
|
||||
|
||||
if (ZEND_NUM_ARGS()!=0) {
|
||||
ZEND_WRONG_PARAM_COUNT();
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (array_init(return_value) == FAILURE) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to initialize array");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
for(hptr = handler; hptr->name; hptr++) {
|
||||
add_next_index_string(return_value, hptr->name, 1);
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ proto array dba_list()
|
||||
List configured databases */
|
||||
PHP_FUNCTION(dba_list)
|
||||
{
|
||||
ulong numitems, i;
|
||||
zend_rsrc_list_entry *le;
|
||||
dba_info *info;
|
||||
|
||||
if (ZEND_NUM_ARGS()!=0) {
|
||||
ZEND_WRONG_PARAM_COUNT();
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (array_init(return_value) == FAILURE) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to initialize array");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
numitems = zend_hash_next_free_element(&EG(regular_list));
|
||||
for (i=1; i<numitems; i++) {
|
||||
if (zend_hash_index_find(&EG(regular_list), i, (void **) &le)==FAILURE) {
|
||||
continue;
|
||||
}
|
||||
if (Z_TYPE_P(le) == le_db || Z_TYPE_P(le) == le_pdb) {
|
||||
info = (dba_info *)(le->ptr);
|
||||
add_index_string(return_value, i, info->path, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
+4
-44
@@ -43,8 +43,8 @@ RSC=rc.exe
|
||||
# PROP Intermediate_Dir "Release_TS"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D DBA_DB3=1 /D DB3_INCLUDE_FILE="db.h" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=0 /D DBA_DB3=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D DBA_FLATFILE=1 /D DBA_CDB=1 /D DBA_CDB_MAKE=1 /D DBA_CDB_BUILTIN=1 /YX /FD /c
|
||||
# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "PHP_EXPORTS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D DBA_DB3=1 /D DB3_INCLUDE_FILE="db.h" /YX /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "PHP_EXPORTS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D DBA_DB3=1 /YX /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x407 /d "NDEBUG"
|
||||
@@ -70,8 +70,8 @@ LINK32=link.exe
|
||||
# PROP Intermediate_Dir "Debug_TS"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D "DBA_DB3" /D DB3_INCLUDE_FILE="db.h" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=1 /D "DBA_DB3" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D DBA_FLATFILE=1 /D DBA_CDB=1 /D DBA_CDB_MAKE=1 /D DBA_CDB_BUILTIN=1 /YX /FD /GZ /c
|
||||
# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "PHP_EXPORTS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D "DBA_DB3" /D DB3_INCLUDE_FILE="db.h" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\main" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "PHP_EXPORTS" /D "COMPILE_DL_DBA" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_DBA=1 /D "DBA_DB3" /YX /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x407 /d "_DEBUG"
|
||||
@@ -94,14 +94,6 @@ LINK32=link.exe
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\libcdb\cdb.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\libcdb\cdb_make.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\dba.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -122,42 +114,18 @@ SOURCE=.\dba_dbm.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\dba_flatfile.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\dba_gdbm.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\dba_ndbm.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\libflatfile\flatfile.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\libcdb\uint32.c
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\libcdb\cdb.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\libcdb\cdb_make.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\libflatfile\flatfile.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\php_cdb.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@@ -178,20 +146,12 @@ SOURCE=.\php_dbm.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\php_flatfile.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\php_gdbm.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\php_ndbm.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\libcdb\uint32.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
+33
-143
@@ -12,8 +12,7 @@
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Authors: Sascha Schumann <sascha@schumann.cx> |
|
||||
| Marcus Boerger <helly@php.net> |
|
||||
| Author: Sascha Schumann <sascha@schumann.cx> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
@@ -29,89 +28,51 @@
|
||||
#include "php_cdb.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
|
||||
#if DBA_CDB_BUILTIN
|
||||
#include "libcdb/cdb.h"
|
||||
#include "libcdb/cdb_make.h"
|
||||
#include "libcdb/uint32.h"
|
||||
#else
|
||||
#include <cdb.h>
|
||||
#include <uint32.h>
|
||||
#endif
|
||||
|
||||
#define CDB_INFO \
|
||||
dba_cdb *cdb = (dba_cdb *) info->dbf
|
||||
|
||||
typedef struct {
|
||||
struct cdb c;
|
||||
#if DBA_CDB_BUILTIN
|
||||
struct cdb_make m;
|
||||
php_stream *file;
|
||||
int make;
|
||||
#else
|
||||
int file;
|
||||
#endif
|
||||
int fd;
|
||||
uint32 eod; /* size of constant database */
|
||||
uint32 pos; /* current position for traversing */
|
||||
} dba_cdb;
|
||||
|
||||
DBA_OPEN_FUNC(cdb)
|
||||
{
|
||||
#if DBA_CDB_BUILTIN
|
||||
php_stream* file = 0;
|
||||
int make;
|
||||
#else
|
||||
int file = 0;
|
||||
#endif
|
||||
int gmode = 0;
|
||||
int fd;
|
||||
dba_cdb *cdb;
|
||||
dba_info *pinfo = (dba_info *) info;
|
||||
|
||||
switch (info->mode) {
|
||||
case DBA_READER:
|
||||
#if DBA_CDB_BUILTIN
|
||||
make = 0;
|
||||
file = info->fp;
|
||||
#else
|
||||
file = VCWD_OPEN(info->path, O_RDONLY);
|
||||
if (file < 0) {
|
||||
*error = "Unable to open file";
|
||||
return FAILURE;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
#if DBA_CDB_BUILTIN
|
||||
case DBA_TRUNC:
|
||||
case DBA_CREAT:
|
||||
make = 1;
|
||||
file = info->fp;
|
||||
break;
|
||||
case DBA_WRITER:
|
||||
*error = "Update operations are not supported";
|
||||
return FAILURE; /* not supported */
|
||||
gmode = O_RDONLY; break;
|
||||
/* currently not supported: */
|
||||
#if 0
|
||||
case DBA_WRITER:
|
||||
gmode = O_RDWR; break;
|
||||
#endif
|
||||
default:
|
||||
*error = "Currently not supported";
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
cdb = emalloc(sizeof(dba_cdb));
|
||||
memset(cdb, 0, sizeof(dba_cdb));
|
||||
|
||||
#if DBA_CDB_BUILTIN
|
||||
if (make) {
|
||||
cdb_make_start(&cdb->m, file TSRMLS_CC);
|
||||
} else {
|
||||
cdb_init(&cdb->c, file TSRMLS_CC);
|
||||
fd = VCWD_OPEN(info->path, gmode);
|
||||
if (fd < 0) {
|
||||
return FAILURE;
|
||||
}
|
||||
cdb->make = make;
|
||||
#else
|
||||
cdb_init(&cdb->c, file);
|
||||
#endif
|
||||
cdb->file = file;
|
||||
|
||||
cdb = malloc(sizeof *cdb);
|
||||
memset(cdb, 0, sizeof *cdb);
|
||||
|
||||
cdb_init(&cdb->c, fd);
|
||||
cdb->fd = fd;
|
||||
|
||||
pinfo->dbf = cdb;
|
||||
return SUCCESS;
|
||||
@@ -121,54 +82,27 @@ DBA_CLOSE_FUNC(cdb)
|
||||
{
|
||||
CDB_INFO;
|
||||
|
||||
/* cdb_free does not close associated file */
|
||||
#if DBA_CDB_BUILTIN
|
||||
if (cdb->make) {
|
||||
cdb_make_finish(&cdb->m TSRMLS_CC);
|
||||
} else {
|
||||
cdb_free(&cdb->c TSRMLS_CC);
|
||||
}
|
||||
#else
|
||||
/* cdb_free does not close associated fd */
|
||||
cdb_free(&cdb->c);
|
||||
close(cdb->file);
|
||||
#endif
|
||||
efree(cdb);
|
||||
close(cdb->fd);
|
||||
free(cdb);
|
||||
}
|
||||
|
||||
#if DBA_CDB_BUILTIN
|
||||
# define php_cdb_read(cdb, buf, len, pos) cdb_read(cdb, buf, len, pos TSRMLS_CC)
|
||||
# define php_cdb_findnext(cdb, key, len) cdb_findnext(cdb, key, len TSRMLS_CC)
|
||||
# define php_cdb_find(cdb, key, len) cdb_find(cdb, key, len TSRMLS_CC)
|
||||
#else
|
||||
# define php_cdb_read(cdb, buf, len, pos) cdb_read(cdb, buf, len, pos)
|
||||
# define php_cdb_findnext(cdb, key, len) cdb_findnext(cdb, key, len)
|
||||
# define php_cdb_find(cdb, key, len) cdb_find(cdb, key, len)
|
||||
#endif
|
||||
|
||||
DBA_FETCH_FUNC(cdb)
|
||||
{
|
||||
CDB_INFO;
|
||||
unsigned int len;
|
||||
char *new_entry = NULL;
|
||||
|
||||
#if DBA_CDB_BUILTIN
|
||||
if (cdb->make)
|
||||
return NULL; /* database was opened writeonly */
|
||||
#endif
|
||||
if (php_cdb_find(&cdb->c, key, keylen) == 1) {
|
||||
while(skip--) {
|
||||
if (php_cdb_findnext(&cdb->c, key, keylen) != 1) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (cdb_find(&cdb->c, key, keylen) == 1) {
|
||||
len = cdb_datalen(&cdb->c);
|
||||
new_entry = emalloc(len+1);
|
||||
new_entry = emalloc(len);
|
||||
|
||||
if (php_cdb_read(&cdb->c, new_entry, len, cdb_datapos(&cdb->c)) == -1) {
|
||||
efree(new_entry);
|
||||
if (cdb_read(&cdb->c, new_entry, len, cdb_datapos(&cdb->c)) == -1) {
|
||||
free(new_entry);
|
||||
return NULL;
|
||||
}
|
||||
new_entry[len] = 0;
|
||||
|
||||
if (newlen)
|
||||
*newlen = len;
|
||||
}
|
||||
@@ -178,16 +112,7 @@ DBA_FETCH_FUNC(cdb)
|
||||
|
||||
DBA_UPDATE_FUNC(cdb)
|
||||
{
|
||||
#if DBA_CDB_BUILTIN
|
||||
CDB_INFO;
|
||||
|
||||
if (!cdb->make)
|
||||
return FAILURE; /* database was opened readonly */
|
||||
if (!mode)
|
||||
return FAILURE; /* cdb_make dosn't know replace */
|
||||
if (cdb_make_add(&cdb->m, key, keylen, val, vallen TSRMLS_CC) != -1)
|
||||
return SUCCESS;
|
||||
#endif
|
||||
/* if anyone figures out cdbmake.c, let me know */
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
@@ -195,49 +120,24 @@ DBA_EXISTS_FUNC(cdb)
|
||||
{
|
||||
CDB_INFO;
|
||||
|
||||
#if DBA_CDB_BUILTIN
|
||||
if (cdb->make)
|
||||
return FAILURE; /* database was opened writeonly */
|
||||
#endif
|
||||
if (php_cdb_find(&cdb->c, key, keylen) == 1)
|
||||
if (cdb_find(&cdb->c, key, keylen) == 1)
|
||||
return SUCCESS;
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
DBA_DELETE_FUNC(cdb)
|
||||
{
|
||||
return FAILURE; /* cdb doesn't support delete */
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
/* {{{ cdb_file_read */
|
||||
#if DBA_CDB_BUILTIN
|
||||
# define cdb_file_read(fildes, buf, size) php_stream_read(fildes, buf, size)
|
||||
#else
|
||||
# define cdb_file_read(fildes, buf, size) read(fildes, buf, size)
|
||||
#endif
|
||||
/* }}} */
|
||||
|
||||
#define CREAD(n) do { \
|
||||
if (cdb_file_read(cdb->file, buf, n) < n) return NULL; \
|
||||
if (read(cdb->fd, buf, n) < n) return NULL; \
|
||||
} while (0)
|
||||
|
||||
/* {{{ cdb_file_lseek
|
||||
php_stream_seek does not return actual position */
|
||||
#if DBA_CDB_BUILTIN
|
||||
int cdb_file_lseek(php_stream *fp, off_t offset, int whence TSRMLS_DC) {
|
||||
php_stream_seek(fp, offset, whence);
|
||||
return php_stream_tell(fp);
|
||||
}
|
||||
#else
|
||||
int cdb_file_lseek(int fd, off_t offset, int whence TSRMLS_DC) {
|
||||
return lseek(fd, offset, whence);
|
||||
}
|
||||
#endif
|
||||
/* }}} */
|
||||
|
||||
#define CSEEK(n) do { \
|
||||
if (n >= cdb->eod) return NULL; \
|
||||
if (cdb_file_lseek(cdb->file, (off_t)n, SEEK_SET TSRMLS_CC) != (off_t) n) return NULL; \
|
||||
if (lseek(cdb->fd, (off_t)n, SEEK_SET) != (off_t) n) return NULL; \
|
||||
} while (0)
|
||||
|
||||
|
||||
@@ -248,11 +148,6 @@ DBA_FIRSTKEY_FUNC(cdb)
|
||||
char buf[8];
|
||||
char *key;
|
||||
|
||||
#if DBA_CDB_BUILTIN
|
||||
if (cdb->make)
|
||||
return NULL; /* database was opened writeonly */
|
||||
#endif
|
||||
|
||||
cdb->eod = -1;
|
||||
CSEEK(0);
|
||||
CREAD(4);
|
||||
@@ -268,7 +163,7 @@ DBA_FIRSTKEY_FUNC(cdb)
|
||||
uint32_unpack(buf + 4, &dlen);
|
||||
|
||||
key = emalloc(klen + 1);
|
||||
if (cdb_file_read(cdb->file, key, klen) < klen) {
|
||||
if (read(cdb->fd, key, klen) < klen) {
|
||||
efree(key);
|
||||
key = NULL;
|
||||
} else {
|
||||
@@ -289,18 +184,13 @@ DBA_NEXTKEY_FUNC(cdb)
|
||||
char buf[8];
|
||||
char *key;
|
||||
|
||||
#if DBA_CDB_BUILTIN
|
||||
if (cdb->make)
|
||||
return NULL; /* database was opened writeonly */
|
||||
#endif
|
||||
|
||||
CSEEK(cdb->pos);
|
||||
CREAD(8);
|
||||
uint32_unpack(buf, &klen);
|
||||
uint32_unpack(buf + 4, &dlen);
|
||||
|
||||
key = emalloc(klen + 1);
|
||||
if (cdb_file_read(cdb->file, key, klen) < klen) {
|
||||
if (read(cdb->fd, key, klen) < klen) {
|
||||
efree(key);
|
||||
key = NULL;
|
||||
} else {
|
||||
|
||||
+5
-7
@@ -63,9 +63,8 @@ DBA_OPEN_FUNC(db2)
|
||||
info->mode == DBA_WRITER ? 0 :
|
||||
info->mode == DBA_TRUNC ? DB_CREATE | DB_TRUNCATE : -1;
|
||||
|
||||
if (gmode == -1) {
|
||||
return FAILURE;/* not possible */
|
||||
}
|
||||
if (gmode == -1)
|
||||
return FAILURE;
|
||||
|
||||
if (info->argc > 0) {
|
||||
convert_to_long_ex(info->argv[0]);
|
||||
@@ -76,8 +75,7 @@ DBA_OPEN_FUNC(db2)
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
info->dbf = emalloc(sizeof(dba_db2_data));
|
||||
memset(info->dbf, 0, sizeof(dba_db2_data));
|
||||
info->dbf = calloc(sizeof(dba_db2_data), 1);
|
||||
((dba_db2_data *) info->dbf)->dbp = dbp;
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -89,7 +87,7 @@ DBA_CLOSE_FUNC(db2)
|
||||
if (dba->cursor)
|
||||
dba->cursor->c_close(dba->cursor);
|
||||
dba->dbp->close(dba->dbp, 0);
|
||||
efree(dba);
|
||||
free(dba);
|
||||
}
|
||||
|
||||
DBA_FETCH_FUNC(db2)
|
||||
@@ -160,7 +158,7 @@ DBA_FIRSTKEY_FUNC(db2)
|
||||
}
|
||||
|
||||
/* we should introduce something like PARAM_PASSTHRU... */
|
||||
return dba_nextkey_db2(info, newlen TSRMLS_CC);
|
||||
return dba_nextkey_db2(info, newlen);
|
||||
}
|
||||
|
||||
DBA_NEXTKEY_FUNC(db2)
|
||||
|
||||
+5
-9
@@ -66,7 +66,7 @@ DBA_OPEN_FUNC(db3)
|
||||
info->mode == DBA_TRUNC ? DB_CREATE | DB_TRUNCATE : -1;
|
||||
|
||||
if (gmode == -1)
|
||||
return FAILURE; /* not possible */
|
||||
return FAILURE;
|
||||
|
||||
if (info->argc > 0) {
|
||||
convert_to_long_ex(info->argv[0]);
|
||||
@@ -74,14 +74,10 @@ DBA_OPEN_FUNC(db3)
|
||||
}
|
||||
|
||||
if (db_create(&dbp, NULL, 0) == 0 &&
|
||||
#if (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
|
||||
dbp->open(dbp, 0, info->path, NULL, type, gmode, filemode) == 0) {
|
||||
#else
|
||||
dbp->open(dbp, info->path, NULL, type, gmode, filemode) == 0) {
|
||||
#endif
|
||||
dba_db3_data *data;
|
||||
|
||||
data = emalloc(sizeof(*data));
|
||||
|
||||
data = malloc(sizeof(*data));
|
||||
data->dbp = dbp;
|
||||
data->cursor = NULL;
|
||||
info->dbf = data;
|
||||
@@ -100,7 +96,7 @@ DBA_CLOSE_FUNC(db3)
|
||||
|
||||
if (dba->cursor) dba->cursor->c_close(dba->cursor);
|
||||
dba->dbp->close(dba->dbp, 0);
|
||||
efree(dba);
|
||||
free(dba);
|
||||
}
|
||||
|
||||
DBA_FETCH_FUNC(db3)
|
||||
@@ -170,7 +166,7 @@ DBA_FIRSTKEY_FUNC(db3)
|
||||
}
|
||||
|
||||
/* we should introduce something like PARAM_PASSTHRU... */
|
||||
return dba_nextkey_db3(info, newlen TSRMLS_CC);
|
||||
return dba_nextkey_db3(info, newlen);
|
||||
}
|
||||
|
||||
DBA_NEXTKEY_FUNC(db3)
|
||||
|
||||
+2
-3
@@ -78,14 +78,13 @@ DBA_OPEN_FUNC(dbm)
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
info->dbf = emalloc(sizeof(dba_dbm_data));
|
||||
memset(info->dbf, 0, sizeof(dba_dbm_data));
|
||||
info->dbf = calloc(sizeof(dba_dbm_data), 1);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
DBA_CLOSE_FUNC(dbm)
|
||||
{
|
||||
efree(info->dbf);
|
||||
free(info->dbf);
|
||||
dbmclose();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,175 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2002 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.02 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available at through the world-wide-web at |
|
||||
| http://www.php.net/license/2_02.txt. |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Marcus Boerger <helly@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
|
||||
#if DBA_FLATFILE
|
||||
#include "php_flatfile.h"
|
||||
|
||||
#include "libflatfile/flatfile.h"
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define FLATFILE_DATA flatfile *dba = info->dbf
|
||||
#define FLATFILE_GKEY datum gkey; gkey.dptr = (char *) key; gkey.dsize = keylen
|
||||
|
||||
DBA_OPEN_FUNC(flatfile)
|
||||
{
|
||||
info->dbf = emalloc(sizeof(flatfile));
|
||||
memset(info->dbf, 0, sizeof(flatfile));
|
||||
|
||||
((flatfile*)info->dbf)->fp = info->fp;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
DBA_CLOSE_FUNC(flatfile)
|
||||
{
|
||||
FLATFILE_DATA;
|
||||
|
||||
if (dba->nextkey.dptr)
|
||||
efree(dba->nextkey.dptr);
|
||||
efree(dba);
|
||||
}
|
||||
|
||||
DBA_FETCH_FUNC(flatfile)
|
||||
{
|
||||
datum gval;
|
||||
char *new = NULL;
|
||||
|
||||
FLATFILE_DATA;
|
||||
FLATFILE_GKEY;
|
||||
|
||||
gval = flatfile_fetch(dba, gkey TSRMLS_CC);
|
||||
if(gval.dptr) {
|
||||
if(newlen) *newlen = gval.dsize;
|
||||
new = estrndup(gval.dptr, gval.dsize);
|
||||
efree(gval.dptr);
|
||||
}
|
||||
return new;
|
||||
}
|
||||
|
||||
DBA_UPDATE_FUNC(flatfile)
|
||||
{
|
||||
datum gval;
|
||||
|
||||
FLATFILE_DATA;
|
||||
FLATFILE_GKEY;
|
||||
gval.dptr = (char *) val;
|
||||
gval.dsize = vallen;
|
||||
|
||||
switch(flatfile_store(dba, gkey, gval, mode==1 ? FLATFILE_INSERT : FLATFILE_REPLACE TSRMLS_CC)) {
|
||||
case -1:
|
||||
php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Operation not possible");
|
||||
return FAILURE;
|
||||
default:
|
||||
case 0:
|
||||
return SUCCESS;
|
||||
case 1:
|
||||
php_error_docref1(NULL TSRMLS_CC, key, E_WARNING, "Key already exists");
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
DBA_EXISTS_FUNC(flatfile)
|
||||
{
|
||||
datum gval;
|
||||
FLATFILE_DATA;
|
||||
FLATFILE_GKEY;
|
||||
|
||||
gval = flatfile_fetch(dba, gkey TSRMLS_CC);
|
||||
if(gval.dptr) {
|
||||
efree(gval.dptr);
|
||||
return SUCCESS;
|
||||
}
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
DBA_DELETE_FUNC(flatfile)
|
||||
{
|
||||
FLATFILE_DATA;
|
||||
FLATFILE_GKEY;
|
||||
return(flatfile_delete(dba, gkey TSRMLS_CC) == -1 ? FAILURE : SUCCESS);
|
||||
}
|
||||
|
||||
DBA_FIRSTKEY_FUNC(flatfile)
|
||||
{
|
||||
FLATFILE_DATA;
|
||||
|
||||
if (dba->nextkey.dptr)
|
||||
efree(dba->nextkey.dptr);
|
||||
dba->nextkey = flatfile_firstkey(dba TSRMLS_CC);
|
||||
if(dba->nextkey.dptr) {
|
||||
if(newlen)
|
||||
*newlen = dba->nextkey.dsize;
|
||||
return estrndup(dba->nextkey.dptr, dba->nextkey.dsize);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBA_NEXTKEY_FUNC(flatfile)
|
||||
{
|
||||
FLATFILE_DATA;
|
||||
|
||||
if(!dba->nextkey.dptr)
|
||||
return NULL;
|
||||
|
||||
if (dba->nextkey.dptr)
|
||||
efree(dba->nextkey.dptr);
|
||||
dba->nextkey = flatfile_nextkey(dba TSRMLS_CC);
|
||||
if(dba->nextkey.dptr) {
|
||||
if(newlen)
|
||||
*newlen = dba->nextkey.dsize;
|
||||
return estrndup(dba->nextkey.dptr, dba->nextkey.dsize);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBA_OPTIMIZE_FUNC(flatfile)
|
||||
{
|
||||
/* dummy */
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
DBA_SYNC_FUNC(flatfile)
|
||||
{
|
||||
/* dummy */
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 fdm=marker
|
||||
* vim<600: sw=4 ts=4
|
||||
*/
|
||||
+4
-5
@@ -49,7 +49,7 @@ DBA_OPEN_FUNC(gdbm)
|
||||
info->mode == DBA_TRUNC ? GDBM_NEWDB : -1;
|
||||
|
||||
if(gmode == -1)
|
||||
return FAILURE; /* not possible */
|
||||
return FAILURE;
|
||||
|
||||
if(info->argc > 0) {
|
||||
convert_to_long_ex(info->argv[0]);
|
||||
@@ -59,12 +59,11 @@ DBA_OPEN_FUNC(gdbm)
|
||||
dbf = gdbm_open(info->path, 0, gmode, filemode, NULL);
|
||||
|
||||
if(dbf) {
|
||||
info->dbf = emalloc(sizeof(dba_gdbm_data));
|
||||
info->dbf = malloc(sizeof(dba_gdbm_data));
|
||||
memset(info->dbf, 0, sizeof(dba_gdbm_data));
|
||||
((dba_gdbm_data *) info->dbf)->dbf = dbf;
|
||||
return SUCCESS;
|
||||
}
|
||||
*error = gdbm_strerror(gdbm_errno);
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
@@ -74,7 +73,7 @@ DBA_CLOSE_FUNC(gdbm)
|
||||
|
||||
if(dba->nextkey.dptr) free(dba->nextkey.dptr);
|
||||
gdbm_close(dba->dbf);
|
||||
efree(dba);
|
||||
free(dba);
|
||||
}
|
||||
|
||||
DBA_FETCH_FUNC(gdbm)
|
||||
@@ -105,7 +104,7 @@ DBA_UPDATE_FUNC(gdbm)
|
||||
if(gdbm_store(dba->dbf, gkey, gval,
|
||||
mode == 1 ? GDBM_INSERT : GDBM_REPLACE) == 0)
|
||||
return SUCCESS;
|
||||
php_error_docref2(NULL TSRMLS_CC, key, val, E_WARNING, "%s", gdbm_strerror(gdbm_errno));
|
||||
printf("XXX %s\n", gdbm_strerror(gdbm_errno));
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
|
||||
+6
-3
@@ -55,7 +55,7 @@ DBA_OPEN_FUNC(ndbm)
|
||||
gmode = O_RDWR | O_CREAT | O_TRUNC;
|
||||
break;
|
||||
default:
|
||||
return FAILURE; /* not possible */
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
if(info->argc > 0) {
|
||||
@@ -65,8 +65,11 @@ DBA_OPEN_FUNC(ndbm)
|
||||
|
||||
dbf = dbm_open(info->path, gmode, filemode);
|
||||
|
||||
pinfo->dbf = dbf;
|
||||
return SUCCESS;
|
||||
if(dbf) {
|
||||
pinfo->dbf = dbf;
|
||||
return SUCCESS;
|
||||
}
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
DBA_CLOSE_FUNC(ndbm)
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
#! /bin/sh
|
||||
|
||||
# You can use this script if you want to use an external cdb lib. If you
|
||||
# compile php using --with-cdb the internal functions will be used and no
|
||||
# external library is used so that this script is not necessary.
|
||||
#
|
||||
# cdb-0.75 lacks support for installing header files and creating a
|
||||
# library which programs can link against. This shell script fills
|
||||
# the gap.
|
||||
#
|
||||
# $Id: install_cdb.sh,v 1.2 2002-11-04 17:53:04 helly Exp $
|
||||
# $Id: install_cdb.sh,v 1.1 2002-09-19 04:18:20 sas Exp $
|
||||
|
||||
if test -r "cdb.a" && test -r "auto-str.c" && test -r "byte.a"; then
|
||||
:
|
||||
|
||||
@@ -1,195 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2002 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.02 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available at through the world-wide-web at |
|
||||
| http://www.php.net/license/2_02.txt. |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Marcus Boerger <helly@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* incorporated from D.J.Bernstein's cdb-0.75 (http://cr.yp.to/cdb.html)*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#ifndef PHP_WIN32
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "cdb.h"
|
||||
|
||||
#ifndef EPROTO
|
||||
# define EPROTO -15 /* cdb 0.75's default for PROTOless systems */
|
||||
#endif
|
||||
|
||||
/* {{{ cdb_match */
|
||||
static int cdb_match(struct cdb *c, char *key, unsigned int len, uint32 pos TSRMLS_DC)
|
||||
{
|
||||
char buf[32];
|
||||
unsigned int n;
|
||||
|
||||
while (len > 0) {
|
||||
n = sizeof(buf);
|
||||
if (n > len)
|
||||
n = len;
|
||||
if (cdb_read(c, buf, n, pos TSRMLS_CC) == -1)
|
||||
return -1;
|
||||
if (memcmp(buf, key, n))
|
||||
return 0;
|
||||
pos += n;
|
||||
key += n;
|
||||
len -= n;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ cdb_hashadd */
|
||||
static uint32 cdb_hashadd(uint32 h, unsigned char c)
|
||||
{
|
||||
h += (h << 5);
|
||||
return h ^ c;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ cdb_hash */
|
||||
uint32 cdb_hash(char *buf, unsigned int len)
|
||||
{
|
||||
uint32 h;
|
||||
|
||||
h = CDB_HASHSTART;
|
||||
while (len) {
|
||||
h = cdb_hashadd(h, *buf++);
|
||||
--len;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ cdb_free */
|
||||
void cdb_free(struct cdb *c TSRMLS_DC)
|
||||
{
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ cdb_findstart */
|
||||
void cdb_findstart(struct cdb *c TSRMLS_DC)
|
||||
{
|
||||
c->loop = 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ cdb_init */
|
||||
void cdb_init(struct cdb *c, php_stream *fp TSRMLS_DC)
|
||||
{
|
||||
cdb_free(c TSRMLS_CC);
|
||||
cdb_findstart(c TSRMLS_CC);
|
||||
c->fp = fp;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ cdb_read */
|
||||
int cdb_read(struct cdb *c, char *buf, unsigned int len, uint32 pos TSRMLS_DC)
|
||||
{
|
||||
if (php_stream_seek(c->fp, pos, SEEK_SET) == -1) {
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
while (len > 0) {
|
||||
int r;
|
||||
do {
|
||||
r = php_stream_read(c->fp, buf, len);
|
||||
} while ((r == -1) && (errno == EINTR));
|
||||
if (r == -1)
|
||||
return -1;
|
||||
if (r == 0) {
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
buf += r;
|
||||
len -= r;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ cdb_findnext */
|
||||
int cdb_findnext(struct cdb *c, char *key, unsigned int len TSRMLS_DC)
|
||||
{
|
||||
char buf[8];
|
||||
uint32 pos;
|
||||
uint32 u;
|
||||
|
||||
if (!c->loop) {
|
||||
u = cdb_hash(key, len);
|
||||
if (cdb_read(c, buf, 8, (u << 3) & 2047 TSRMLS_CC) == -1)
|
||||
return -1;
|
||||
uint32_unpack(buf + 4,&c->hslots);
|
||||
if (!c->hslots)
|
||||
return 0;
|
||||
uint32_unpack(buf, &c->hpos);
|
||||
c->khash = u;
|
||||
u >>= 8;
|
||||
u %= c->hslots;
|
||||
u <<= 3;
|
||||
c->kpos = c->hpos + u;
|
||||
}
|
||||
|
||||
while (c->loop < c->hslots) {
|
||||
if (cdb_read(c, buf, 8, c->kpos TSRMLS_CC) == -1)
|
||||
return -1;
|
||||
uint32_unpack(buf + 4, &pos);
|
||||
if (!pos)
|
||||
return 0;
|
||||
c->loop += 1;
|
||||
c->kpos += 8;
|
||||
if (c->kpos == c->hpos + (c->hslots << 3))
|
||||
c->kpos = c->hpos;
|
||||
uint32_unpack(buf, &u);
|
||||
if (u == c->khash) {
|
||||
if (cdb_read(c, buf, 8, pos TSRMLS_CC) == -1)
|
||||
return -1;
|
||||
uint32_unpack(buf, &u);
|
||||
if (u == len)
|
||||
switch(cdb_match(c, key, len, pos + 8 TSRMLS_CC)) {
|
||||
case -1:
|
||||
return -1;
|
||||
case 1:
|
||||
uint32_unpack(buf + 4, &c->dlen);
|
||||
c->dpos = pos + 8 + len;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ cdb_find */
|
||||
int cdb_find(struct cdb *c, char *key, unsigned int len TSRMLS_DC)
|
||||
{
|
||||
cdb_findstart(c TSRMLS_CC);
|
||||
return cdb_findnext(c, key, len TSRMLS_CC);
|
||||
}
|
||||
/* }}} */
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2002 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.02 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available at through the world-wide-web at |
|
||||
| http://www.php.net/license/2_02.txt. |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Marcus Boerger <helly@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* incorporated from D.J.Bernstein's cdb-0.75 (http://cr.yp.to/cdb.html)*/
|
||||
|
||||
#ifndef CDB_H
|
||||
#define CDB_H
|
||||
|
||||
#include "uint32.h"
|
||||
|
||||
#define CDB_HASHSTART 5381
|
||||
|
||||
struct cdb {
|
||||
php_stream *fp;
|
||||
uint32 loop; /* number of hash slots searched under this key */
|
||||
uint32 khash; /* initialized if loop is nonzero */
|
||||
uint32 kpos; /* initialized if loop is nonzero */
|
||||
uint32 hpos; /* initialized if loop is nonzero */
|
||||
uint32 hslots; /* initialized if loop is nonzero */
|
||||
uint32 dpos; /* initialized if cdb_findnext() returns 1 */
|
||||
uint32 dlen; /* initialized if cdb_findnext() returns 1 */
|
||||
};
|
||||
|
||||
uint32 cdb_hash(char *, unsigned int);
|
||||
|
||||
void cdb_free(struct cdb * TSRMLS_DC);
|
||||
void cdb_init(struct cdb *, php_stream *fp TSRMLS_DC);
|
||||
|
||||
int cdb_read(struct cdb *, char *, unsigned int, uint32 TSRMLS_DC);
|
||||
|
||||
void cdb_findstart(struct cdb * TSRMLS_DC);
|
||||
int cdb_findnext(struct cdb *, char *, unsigned int TSRMLS_DC);
|
||||
int cdb_find(struct cdb *, char *, unsigned int TSRMLS_DC);
|
||||
|
||||
#define cdb_datapos(c) ((c)->dpos)
|
||||
#define cdb_datalen(c) ((c)->dlen)
|
||||
|
||||
#endif
|
||||
@@ -1,240 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2002 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.02 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available at through the world-wide-web at |
|
||||
| http://www.php.net/license/2_02.txt. |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Marcus Boerger <helly@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* incorporated from D.J.Bernstein's cdb-0.75 (http://cr.yp.to/cdb.html)*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "cdb.h"
|
||||
#include "cdb_make.h"
|
||||
#include "uint32.h"
|
||||
|
||||
/* {{{ cdb_make_write */
|
||||
static int cdb_make_write(struct cdb_make *c, char *buf, uint32 sz TSRMLS_DC) {
|
||||
return php_stream_write(c->fp, buf, sz) == sz ? 0 : -1;
|
||||
}
|
||||
|
||||
/* {{{ cdb_posplus */
|
||||
static int cdb_posplus(struct cdb_make *c, uint32 len)
|
||||
{
|
||||
uint32 newpos = c->pos + len;
|
||||
if (newpos < len) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
c->pos = newpos;
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ cdb_make_start */
|
||||
int cdb_make_start(struct cdb_make *c, php_stream * f TSRMLS_DC)
|
||||
{
|
||||
c->head = 0;
|
||||
c->split = 0;
|
||||
c->hash = 0;
|
||||
c->numentries = 0;
|
||||
c->fp = f;
|
||||
c->pos = sizeof(c->final);
|
||||
if (php_stream_seek(f, c->pos, SEEK_SET) == -1) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Fseek failed");
|
||||
return -1;
|
||||
}
|
||||
return php_stream_tell(c->fp);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ cdb_make_addend */
|
||||
int cdb_make_addend(struct cdb_make *c, unsigned int keylen, unsigned int datalen, uint32 h TSRMLS_DC)
|
||||
{
|
||||
struct cdb_hplist *head;
|
||||
|
||||
head = c->head;
|
||||
if (!head || (head->num >= CDB_HPLIST)) {
|
||||
head = (struct cdb_hplist *)
|
||||
emalloc(sizeof(struct cdb_hplist));
|
||||
if (!head)
|
||||
return -1;
|
||||
head->num = 0;
|
||||
head->next = c->head;
|
||||
c->head = head;
|
||||
}
|
||||
head->hp[head->num].h = h;
|
||||
head->hp[head->num].p = c->pos;
|
||||
++head->num;
|
||||
++c->numentries;
|
||||
if (cdb_posplus(c,8) == -1)
|
||||
return -1;
|
||||
if (cdb_posplus(c, keylen) == -1)
|
||||
return -1;
|
||||
if (cdb_posplus(c, datalen) == -1)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ cdb_make_addbegin */
|
||||
int cdb_make_addbegin(struct cdb_make *c, unsigned int keylen, unsigned int datalen TSRMLS_DC)
|
||||
{
|
||||
char buf[8];
|
||||
|
||||
if (keylen > 0xffffffff) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
if (datalen > 0xffffffff) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_pack(buf, keylen);
|
||||
uint32_pack(buf + 4, datalen);
|
||||
if (cdb_make_write(c, buf, 8 TSRMLS_CC) != 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* {{{ cdb_make_add */
|
||||
int cdb_make_add(struct cdb_make *c,char *key,unsigned int keylen,char *data,unsigned int datalen TSRMLS_DC)
|
||||
{
|
||||
if (cdb_make_addbegin(c, keylen, datalen TSRMLS_CC) == -1)
|
||||
return -1;
|
||||
if (cdb_make_write(c, key, keylen TSRMLS_CC) != 0)
|
||||
return -1;
|
||||
if (cdb_make_write(c, data, datalen TSRMLS_CC) != 0)
|
||||
return -1;
|
||||
return cdb_make_addend(c, keylen, datalen, cdb_hash(key, keylen) TSRMLS_CC);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ cdb_make_finish */
|
||||
int cdb_make_finish(struct cdb_make *c TSRMLS_DC)
|
||||
{
|
||||
char buf[8];
|
||||
int i;
|
||||
uint32 len;
|
||||
uint32 u;
|
||||
uint32 memsize;
|
||||
uint32 count;
|
||||
uint32 where;
|
||||
struct cdb_hplist *x;
|
||||
struct cdb_hp *hp;
|
||||
|
||||
for (i = 0;i < 256;++i)
|
||||
c->count[i] = 0;
|
||||
|
||||
for (x = c->head; x; x = x->next) {
|
||||
i = x->num;
|
||||
while (i--)
|
||||
++c->count[255 & x->hp[i].h];
|
||||
}
|
||||
|
||||
memsize = 1;
|
||||
for (i = 0;i < 256;++i) {
|
||||
u = c->count[i] * 2;
|
||||
if (u > memsize)
|
||||
memsize = u;
|
||||
}
|
||||
|
||||
memsize += c->numentries; /* no overflow possible up to now */
|
||||
u = (uint32) 0 - (uint32) 1;
|
||||
u /= sizeof(struct cdb_hp);
|
||||
if (memsize > u) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
c->split = (struct cdb_hp *)
|
||||
emalloc(memsize * sizeof(struct cdb_hp));
|
||||
if (!c->split)
|
||||
return -1;
|
||||
|
||||
c->hash = c->split + c->numentries;
|
||||
|
||||
u = 0;
|
||||
for (i = 0;i < 256;++i) {
|
||||
u += c->count[i]; /* bounded by numentries, so no overflow */
|
||||
c->start[i] = u;
|
||||
}
|
||||
|
||||
for (x = c->head; x; x = x->next) {
|
||||
i = x->num;
|
||||
while (i--)
|
||||
c->split[--c->start[255 & x->hp[i].h]] = x->hp[i];
|
||||
}
|
||||
|
||||
for (i = 0;i < 256;++i) {
|
||||
count = c->count[i];
|
||||
|
||||
len = count + count; /* no overflow possible */
|
||||
uint32_pack(c->final + 8 * i,c->pos);
|
||||
uint32_pack(c->final + 8 * i + 4,len);
|
||||
|
||||
for (u = 0;u < len;++u)
|
||||
c->hash[u].h = c->hash[u].p = 0;
|
||||
|
||||
hp = c->split + c->start[i];
|
||||
for (u = 0;u < count;++u) {
|
||||
where = (hp->h >> 8) % len;
|
||||
while (c->hash[where].p)
|
||||
if (++where == len)
|
||||
where = 0;
|
||||
c->hash[where] = *hp++;
|
||||
}
|
||||
|
||||
for (u = 0;u < len;++u) {
|
||||
uint32_pack(buf, c->hash[u].h);
|
||||
uint32_pack(buf + 4, c->hash[u].p);
|
||||
if (cdb_make_write(c, buf, 8 TSRMLS_CC) != 0)
|
||||
return -1;
|
||||
if (cdb_posplus(c, 8) == -1)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (c->split)
|
||||
efree(c->split);
|
||||
|
||||
for (x = c->head; x; c->head = x) {
|
||||
x = x->next;
|
||||
efree(c->head);
|
||||
}
|
||||
|
||||
if (php_stream_flush(c->fp) != 0)
|
||||
return -1;
|
||||
php_stream_rewind(c->fp);
|
||||
if (php_stream_tell(c->fp) != 0)
|
||||
return -1;
|
||||
if (cdb_make_write(c, c->final, sizeof(c->final) TSRMLS_CC) != 0)
|
||||
return -1;
|
||||
return php_stream_flush(c->fp);
|
||||
}
|
||||
/* }}} */
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2002 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.02 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available at through the world-wide-web at |
|
||||
| http://www.php.net/license/2_02.txt. |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Marcus Boerger <helly@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
/* incorporated from D.J.Bernstein's cdb-0.75 (http://cr.yp.to/cdb.html)*/
|
||||
|
||||
#ifndef CDB_MAKE_H
|
||||
#define CDB_MAKE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "uint32.h"
|
||||
|
||||
#define CDB_HPLIST 1000
|
||||
|
||||
struct cdb_hp {
|
||||
uint32 h;
|
||||
uint32 p;
|
||||
};
|
||||
|
||||
struct cdb_hplist {
|
||||
struct cdb_hp hp[CDB_HPLIST];
|
||||
struct cdb_hplist *next;
|
||||
int num;
|
||||
} ;
|
||||
|
||||
struct cdb_make {
|
||||
/* char bspace[8192]; */
|
||||
char final[2048];
|
||||
uint32 count[256];
|
||||
uint32 start[256];
|
||||
struct cdb_hplist *head;
|
||||
struct cdb_hp *split; /* includes space for hash */
|
||||
struct cdb_hp *hash;
|
||||
uint32 numentries;
|
||||
/* buffer b; */
|
||||
uint32 pos;
|
||||
/* int fd; */
|
||||
php_stream * fp;
|
||||
};
|
||||
|
||||
int cdb_make_start(struct cdb_make *, php_stream * TSRMLS_DC);
|
||||
int cdb_make_addbegin(struct cdb_make *, unsigned int, unsigned int TSRMLS_DC);
|
||||
int cdb_make_addend(struct cdb_make *, unsigned int, unsigned int, uint32 TSRMLS_DC);
|
||||
int cdb_make_add(struct cdb_make *, char *, unsigned int, char *, unsigned int TSRMLS_DC);
|
||||
int cdb_make_finish(struct cdb_make * TSRMLS_DC);
|
||||
|
||||
#endif
|
||||
@@ -1,305 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2002 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.02 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available at through the world-wide-web at |
|
||||
| http://www.php.net/license/2_02.txt. |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Authors: Marcus Boerger <helly@php.net> |
|
||||
| based on ext/db/db.c by: |
|
||||
| Rasmus Lerdorf <rasmus@php.net> |
|
||||
| Jim Winstead <jimw@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
#include "php_globals.h"
|
||||
#include "safe_mode.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "flatfile.h"
|
||||
|
||||
/*
|
||||
* ret = -1 means that database was opened for read-only
|
||||
* ret = 0 success
|
||||
* ret = 1 key already exists - nothing done
|
||||
*/
|
||||
|
||||
/* {{{ flatfile_store
|
||||
*/
|
||||
int flatfile_store(flatfile *dba, datum key_datum, datum value_datum, int mode TSRMLS_DC) {
|
||||
if (mode == FLATFILE_INSERT) {
|
||||
if (flatfile_findkey(dba, key_datum TSRMLS_CC)) {
|
||||
return 1;
|
||||
}
|
||||
php_stream_seek(dba->fp, 0L, SEEK_END);
|
||||
php_stream_printf(dba->fp TSRMLS_CC, "%d\n", key_datum.dsize);
|
||||
php_stream_flush(dba->fp);
|
||||
if (php_stream_write(dba->fp, key_datum.dptr, key_datum.dsize) < key_datum.dsize)
|
||||
return -1;
|
||||
php_stream_printf(dba->fp TSRMLS_CC, "%d\n", value_datum.dsize);
|
||||
php_stream_flush(dba->fp);
|
||||
if (php_stream_write(dba->fp, value_datum.dptr, value_datum.dsize) < value_datum.dsize)
|
||||
return -1;
|
||||
} else { /* DBM_REPLACE */
|
||||
flatfile_delete(dba, key_datum TSRMLS_CC);
|
||||
php_stream_printf(dba->fp TSRMLS_CC, "%d\n", key_datum.dsize);
|
||||
php_stream_flush(dba->fp);
|
||||
if (php_stream_write(dba->fp, key_datum.dptr, key_datum.dsize) < key_datum.dsize)
|
||||
return -1;
|
||||
php_stream_printf(dba->fp TSRMLS_CC, "%d\n", value_datum.dsize);
|
||||
if (php_stream_write(dba->fp, value_datum.dptr, value_datum.dsize) < value_datum.dsize)
|
||||
return -1;
|
||||
}
|
||||
|
||||
php_stream_flush(dba->fp);
|
||||
return 0;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ flatfile_fetch
|
||||
*/
|
||||
datum flatfile_fetch(flatfile *dba, datum key_datum TSRMLS_DC) {
|
||||
datum value_datum = {NULL, 0};
|
||||
size_t num=0;
|
||||
size_t buf_size = 1024;
|
||||
char *buf;
|
||||
|
||||
if (flatfile_findkey(dba, key_datum TSRMLS_CC)) {
|
||||
buf = emalloc((buf_size+1) * sizeof(char));
|
||||
if (php_stream_gets(dba->fp, buf, 15)) {
|
||||
num = atoi(buf);
|
||||
if (num > buf_size) {
|
||||
buf_size+=num;
|
||||
buf = erealloc(buf, (buf_size+1)*sizeof(char));
|
||||
}
|
||||
php_stream_read(dba->fp, buf, num);
|
||||
value_datum.dptr = buf;
|
||||
value_datum.dsize = num;
|
||||
} else {
|
||||
value_datum.dptr = NULL;
|
||||
value_datum.dsize = 0;
|
||||
efree(buf);
|
||||
}
|
||||
}
|
||||
return value_datum;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ flatfile_delete
|
||||
*/
|
||||
int flatfile_delete(flatfile *dba, datum key_datum TSRMLS_DC) {
|
||||
char *key = key_datum.dptr;
|
||||
size_t size = key_datum.dsize;
|
||||
|
||||
char *buf;
|
||||
size_t num;
|
||||
size_t buf_size = 1024;
|
||||
size_t pos;
|
||||
|
||||
php_stream_rewind(dba->fp);
|
||||
|
||||
buf = emalloc((buf_size + 1)*sizeof(char));
|
||||
while(!php_stream_eof(dba->fp)) {
|
||||
/* read in the length of the key name */
|
||||
if (!php_stream_gets(dba->fp, buf, 15))
|
||||
break;
|
||||
num = atoi(buf);
|
||||
if (num > buf_size) {
|
||||
buf_size += num;
|
||||
buf = erealloc(buf, (buf_size+1)*sizeof(char));
|
||||
}
|
||||
pos = php_stream_tell(dba->fp);
|
||||
|
||||
/* read in the key name */
|
||||
num = php_stream_read(dba->fp, buf, sizeof(char)*num);
|
||||
if (num<0)
|
||||
break;
|
||||
*(buf+num) = '\0';
|
||||
|
||||
if (size == num && !memcmp(buf, key, size)) {
|
||||
php_stream_seek(dba->fp, pos, SEEK_SET);
|
||||
php_stream_putc(dba->fp, 0);
|
||||
php_stream_flush(dba->fp);
|
||||
php_stream_seek(dba->fp, 0L, SEEK_END);
|
||||
if (buf)
|
||||
efree(buf);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/* read in the length of the value */
|
||||
if (!php_stream_gets(dba->fp, buf, 15))
|
||||
break;
|
||||
num = atoi(buf);
|
||||
if (num > buf_size) {
|
||||
buf_size+=num;
|
||||
buf = erealloc(buf, (buf_size+1)*sizeof(char));
|
||||
}
|
||||
/* read in the value */
|
||||
num = php_stream_read(dba->fp, buf, sizeof(char)*num);
|
||||
if (num<0)
|
||||
break;
|
||||
}
|
||||
if (buf)
|
||||
efree(buf);
|
||||
return FAILURE;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ flatfile_findkey
|
||||
*/
|
||||
int flatfile_findkey(flatfile *dba, datum key_datum TSRMLS_DC) {
|
||||
char *buf = NULL;
|
||||
size_t num;
|
||||
size_t buf_size = 1024;
|
||||
int ret=0;
|
||||
void *key = key_datum.dptr;
|
||||
size_t size = key_datum.dsize;
|
||||
|
||||
php_stream_rewind(dba->fp);
|
||||
buf = emalloc((buf_size+1)*sizeof(char));
|
||||
while (!php_stream_eof(dba->fp)) {
|
||||
if (!php_stream_gets(dba->fp, buf, 15))
|
||||
break;
|
||||
num = atoi(buf);
|
||||
if (num > buf_size) {
|
||||
buf_size+=num;
|
||||
buf = erealloc(buf, (buf_size+1)*sizeof(char));
|
||||
}
|
||||
num = php_stream_read(dba->fp, buf, sizeof(char)*num);
|
||||
if (num<0) break;
|
||||
*(buf+num) = '\0';
|
||||
if (size == num) {
|
||||
if (!memcmp(buf, key, size)) {
|
||||
ret = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!php_stream_gets(dba->fp, buf, 15))
|
||||
break;
|
||||
num = atoi(buf);
|
||||
if (num > buf_size) {
|
||||
buf_size+=num;
|
||||
buf = erealloc(buf, (buf_size+1)*sizeof(char));
|
||||
}
|
||||
num = php_stream_read(dba->fp, buf, sizeof(char)*num);
|
||||
if (num<0)
|
||||
break;
|
||||
*(buf+num) = '\0';
|
||||
}
|
||||
if (buf)
|
||||
efree(buf);
|
||||
return(ret);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ flatfile_firstkey
|
||||
*/
|
||||
datum flatfile_firstkey(flatfile *dba TSRMLS_DC) {
|
||||
datum buf;
|
||||
size_t num;
|
||||
size_t buf_size = 1024;
|
||||
|
||||
php_stream_rewind(dba->fp);
|
||||
buf.dptr = emalloc((buf_size+1)*sizeof(char));
|
||||
while(!php_stream_eof(dba->fp)) {
|
||||
if (!php_stream_gets(dba->fp, buf.dptr, 15)) break;
|
||||
num = atoi(buf.dptr);
|
||||
if (num > buf_size) {
|
||||
buf_size+=num;
|
||||
buf.dptr = erealloc(buf.dptr, (buf_size+1)*sizeof(char));
|
||||
}
|
||||
num = php_stream_read(dba->fp, buf.dptr, num);
|
||||
if (num<0)
|
||||
break;
|
||||
buf.dsize = num;
|
||||
if (*(buf.dptr)!=0) {
|
||||
dba->CurrentFlatFilePos = php_stream_tell(dba->fp);
|
||||
return(buf);
|
||||
}
|
||||
if (!php_stream_gets(dba->fp, buf.dptr, 15)) break;
|
||||
num = atoi(buf.dptr);
|
||||
if (num > buf_size) {
|
||||
buf_size+=num;
|
||||
buf.dptr = erealloc(buf.dptr, (buf_size+1)*sizeof(char));
|
||||
}
|
||||
num = php_stream_read(dba->fp, buf.dptr, num);
|
||||
if (num<0)
|
||||
break;
|
||||
}
|
||||
if (buf.dptr)
|
||||
efree(buf.dptr);
|
||||
buf.dptr = NULL;
|
||||
return(buf);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ flatfile_nextkey
|
||||
*/
|
||||
datum flatfile_nextkey(flatfile *dba TSRMLS_DC) {
|
||||
datum buf;
|
||||
size_t num;
|
||||
size_t buf_size = 1024;
|
||||
|
||||
php_stream_seek(dba->fp, dba->CurrentFlatFilePos, SEEK_SET);
|
||||
buf.dptr = emalloc((buf_size+1)*sizeof(char));
|
||||
while(!php_stream_eof(dba->fp)) {
|
||||
if (!php_stream_gets(dba->fp, buf.dptr, 15)) break;
|
||||
num = atoi(buf.dptr);
|
||||
if (num > buf_size) {
|
||||
buf_size+=num;
|
||||
buf.dptr = erealloc(buf.dptr, (buf_size+1)*sizeof(char));
|
||||
}
|
||||
num = php_stream_read(dba->fp, buf.dptr, num);
|
||||
if (num<0)
|
||||
break;
|
||||
if (!php_stream_gets(dba->fp, buf.dptr, 15))
|
||||
break;
|
||||
num = atoi(buf.dptr);
|
||||
if (num > buf_size) {
|
||||
buf_size+=num;
|
||||
buf.dptr = erealloc(buf.dptr, (buf_size+1)*sizeof(char));
|
||||
}
|
||||
num = php_stream_read(dba->fp, buf.dptr, num);
|
||||
if (num<0)
|
||||
break;
|
||||
buf.dsize = num;
|
||||
if (*(buf.dptr)!=0) {
|
||||
dba->CurrentFlatFilePos = php_stream_tell(dba->fp);
|
||||
return(buf);
|
||||
}
|
||||
}
|
||||
if (buf.dptr)
|
||||
efree(buf.dptr);
|
||||
buf.dptr = NULL;
|
||||
return(buf);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
* c-basic-offset: 4
|
||||
* End:
|
||||
* vim600: sw=4 ts=4 fdm=marker
|
||||
* vim<600: sw=4 ts=4
|
||||
*/
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
| Copyright (c) 1997-2002 The PHP Group |
|
||||
+----------------------------------------------------------------------+
|
||||
| This source file is subject to version 2.02 of the PHP license, |
|
||||
| that is bundled with this package in the file LICENSE, and is |
|
||||
| available at through the world-wide-web at |
|
||||
| http://www.php.net/license/2_02.txt. |
|
||||
| If you did not receive a copy of the PHP license and are unable to |
|
||||
| obtain it through the world-wide-web, please send a note to |
|
||||
| license@php.net so we can mail you a copy immediately. |
|
||||
+----------------------------------------------------------------------+
|
||||
| Author: Marcus Boerger <helly@php.net> |
|
||||
+----------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
#ifndef PHP_LIBDBM_H
|
||||
#define PHP_LIBDBM_H
|
||||
|
||||
typedef struct {
|
||||
char *dptr;
|
||||
size_t dsize;
|
||||
} datum;
|
||||
|
||||
typedef struct {
|
||||
char *lockfn;
|
||||
int lockfd;
|
||||
php_stream *fp;
|
||||
size_t CurrentFlatFilePos;
|
||||
datum nextkey;
|
||||
} flatfile;
|
||||
|
||||
#define FLATFILE_INSERT 1
|
||||
#define FLATFILE_REPLACE 0
|
||||
|
||||
int flatfile_store(flatfile *dba, datum key_datum, datum value_datum, int mode TSRMLS_DC);
|
||||
datum flatfile_fetch(flatfile *dba, datum key_datum TSRMLS_DC);
|
||||
int flatfile_delete(flatfile *dba, datum key_datum TSRMLS_DC);
|
||||
int flatfile_findkey(flatfile *dba, datum key_datum TSRMLS_DC);
|
||||
datum flatfile_firstkey(flatfile *dba TSRMLS_DC);
|
||||
datum flatfile_nextkey(flatfile *dba TSRMLS_DC);
|
||||
|
||||
#endif
|
||||
+11
-35
@@ -24,71 +24,49 @@
|
||||
#if HAVE_DBA
|
||||
|
||||
typedef enum {
|
||||
/* do not allow 0 here */
|
||||
DBA_READER = 1,
|
||||
DBA_WRITER,
|
||||
DBA_TRUNC,
|
||||
DBA_CREAT
|
||||
} dba_mode_t;
|
||||
|
||||
typedef struct dba_lock {
|
||||
php_stream *fp;
|
||||
int fd;
|
||||
char *name;
|
||||
int mode; /* LOCK_EX,LOCK_SH */
|
||||
} dba_lock;
|
||||
|
||||
typedef struct dba_info {
|
||||
/* public */
|
||||
void *dbf; /* ptr to private data or whatever */
|
||||
char *path;
|
||||
dba_mode_t mode;
|
||||
php_stream *fp; /* this is the database stream for builtin handlers */
|
||||
/* arg[cv] are only available when the dba_open handler is called! */
|
||||
int argc;
|
||||
zval ***argv;
|
||||
/* private */
|
||||
int flags; /* whether and how dba did locking and other flags*/
|
||||
struct dba_handler *hnd;
|
||||
dba_lock lock;
|
||||
struct dba_handler *hnd;
|
||||
} dba_info;
|
||||
|
||||
#define DBA_LOCK_READER (0x0001)
|
||||
#define DBA_LOCK_WRITER (0x0002)
|
||||
#define DBA_LOCK_CREAT (0x0004)
|
||||
#define DBA_LOCK_TRUNC (0x0008)
|
||||
|
||||
#define DBA_LOCK_EXT (0)
|
||||
#define DBA_LOCK_ALL (DBA_LOCK_READER|DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC)
|
||||
#define DBA_LOCK_WCT (DBA_LOCK_WRITER|DBA_LOCK_CREAT|DBA_LOCK_TRUNC)
|
||||
|
||||
#define DBA_STREAM_OPEN (0x0010)
|
||||
|
||||
extern zend_module_entry dba_module_entry;
|
||||
#define dba_module_ptr &dba_module_entry
|
||||
|
||||
/* common prototypes which must be supplied by modules */
|
||||
|
||||
#define DBA_OPEN_FUNC(x) \
|
||||
int dba_open_##x(dba_info *info, char **error TSRMLS_DC)
|
||||
int dba_open_##x(dba_info *info TSRMLS_DC)
|
||||
#define DBA_CLOSE_FUNC(x) \
|
||||
void dba_close_##x(dba_info *info TSRMLS_DC)
|
||||
void dba_close_##x(dba_info *info)
|
||||
#define DBA_FETCH_FUNC(x) \
|
||||
char *dba_fetch_##x(dba_info *info, char *key, int keylen, int skip, int *newlen TSRMLS_DC)
|
||||
char *dba_fetch_##x(dba_info *info, char *key, int keylen, int *newlen)
|
||||
#define DBA_UPDATE_FUNC(x) \
|
||||
int dba_update_##x(dba_info *info, char *key, int keylen, char *val, int vallen, int mode TSRMLS_DC)
|
||||
int dba_update_##x(dba_info *info, char *key, int keylen, char *val, int vallen, int mode)
|
||||
#define DBA_EXISTS_FUNC(x) \
|
||||
int dba_exists_##x(dba_info *info, char *key, int keylen TSRMLS_DC)
|
||||
int dba_exists_##x(dba_info *info, char *key, int keylen)
|
||||
#define DBA_DELETE_FUNC(x) \
|
||||
int dba_delete_##x(dba_info *info, char *key, int keylen TSRMLS_DC)
|
||||
int dba_delete_##x(dba_info *info, char *key, int keylen)
|
||||
#define DBA_FIRSTKEY_FUNC(x) \
|
||||
char *dba_firstkey_##x(dba_info *info, int *newlen TSRMLS_DC)
|
||||
char *dba_firstkey_##x(dba_info *info, int *newlen)
|
||||
#define DBA_NEXTKEY_FUNC(x) \
|
||||
char *dba_nextkey_##x(dba_info *info, int *newlen TSRMLS_DC)
|
||||
char *dba_nextkey_##x(dba_info *info, int *newlen)
|
||||
#define DBA_OPTIMIZE_FUNC(x) \
|
||||
int dba_optimize_##x(dba_info *info TSRMLS_DC)
|
||||
int dba_optimize_##x(dba_info *info)
|
||||
#define DBA_SYNC_FUNC(x) \
|
||||
int dba_sync_##x(dba_info *info TSRMLS_DC)
|
||||
int dba_sync_##x(dba_info *info)
|
||||
|
||||
#define DBA_FUNCS(x) \
|
||||
DBA_OPEN_FUNC(x); \
|
||||
@@ -116,8 +94,6 @@ PHP_FUNCTION(dba_exists);
|
||||
PHP_FUNCTION(dba_fetch);
|
||||
PHP_FUNCTION(dba_optimize);
|
||||
PHP_FUNCTION(dba_sync);
|
||||
PHP_FUNCTION(dba_handlers);
|
||||
PHP_FUNCTION(dba_list);
|
||||
|
||||
#else
|
||||
#define dba_module_ptr NULL
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#ifndef PHP_FLATFILE_H
|
||||
#define PHP_FLATFILE_H
|
||||
|
||||
#if DBA_FLATFILE
|
||||
|
||||
#include "php_dba.h"
|
||||
|
||||
DBA_FUNCS(flatfile);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,21 +0,0 @@
|
||||
--TEST--
|
||||
DBA File Creation Test
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('skipif.inc');
|
||||
die("info $HND handler used");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('test.inc');
|
||||
echo "database handler: $handler\n";
|
||||
if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
|
||||
echo "database file created\n";
|
||||
dba_close($db_file);
|
||||
} else {
|
||||
echo "$db_file does not exist\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
database handler: %s
|
||||
database file created
|
||||
@@ -1,22 +0,0 @@
|
||||
--TEST--
|
||||
DBA Insert/Fetch Test
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('skipif.inc');
|
||||
die("info $HND handler used");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('test.inc');
|
||||
echo "database handler: $handler\n";
|
||||
if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
|
||||
dba_insert("key1", "This is a test insert", $db_file);
|
||||
echo dba_fetch("key1", $db_file);
|
||||
dba_close($db_file);
|
||||
} else {
|
||||
echo "Error creating database\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
database handler: %s
|
||||
This is a test insert
|
||||
@@ -1,24 +0,0 @@
|
||||
--TEST--
|
||||
DBA Insert/Replace/Fetch Test
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('skipif.inc');
|
||||
die("info $HND handler used");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('test.inc');
|
||||
echo "database handler: $handler\n";
|
||||
if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
|
||||
dba_insert("key1", "This is a test insert", $db_file);
|
||||
dba_replace("key1", "This is the replacement text", $db_file);
|
||||
$a = dba_fetch("key1", $db_file);
|
||||
dba_close($db_file);
|
||||
echo $a;
|
||||
} else {
|
||||
echo "Error creating database\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
database handler: %s
|
||||
This is the replacement text
|
||||
@@ -1,28 +0,0 @@
|
||||
--TEST--
|
||||
DBA Multiple Insert/Fetch Test
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('skipif.inc');
|
||||
die("info $HND handler used");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('test.inc');
|
||||
echo "database handler: $handler\n";
|
||||
if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
|
||||
dba_insert("key1", "Content String 1", $db_file);
|
||||
dba_insert("key2", "Content String 2", $db_file);
|
||||
dba_insert("key3", "Third Content String", $db_file);
|
||||
dba_insert("key4", "Another Content String", $db_file);
|
||||
dba_insert("key5", "The last content string", $db_file);
|
||||
$a = dba_fetch("key4", $db_file);
|
||||
$b = dba_fetch("key2", $db_file);
|
||||
dba_close($db_file);
|
||||
echo "$a $b";
|
||||
} else {
|
||||
echo "Error creating database\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
database handler: %s
|
||||
Another Content String Content String 2
|
||||
@@ -1,35 +0,0 @@
|
||||
--TEST--
|
||||
DBA FirstKey/NextKey Loop Test With 5 Items
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('skipif.inc');
|
||||
die("info $HND handler used");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('test.inc');
|
||||
echo "database handler: $handler\n";
|
||||
if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
|
||||
dba_insert("key1", "Content String 1", $db_file);
|
||||
dba_insert("key2", "Content String 2", $db_file);
|
||||
dba_insert("key3", "Third Content String", $db_file);
|
||||
dba_insert("key4", "Another Content String", $db_file);
|
||||
dba_insert("key5", "The last content string", $db_file);
|
||||
$a = dba_firstkey($db_file);
|
||||
$i=0;
|
||||
while($a) {
|
||||
$a = dba_nextkey($db_file);
|
||||
$i++;
|
||||
}
|
||||
echo $i;
|
||||
for ($i=1; $i<6; $i++) {
|
||||
echo dba_exists("key$i", $db_file) ? "Y" : "N";
|
||||
}
|
||||
dba_close($db_file);
|
||||
} else {
|
||||
echo "Error creating database\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
database handler: %s
|
||||
5YYYYY
|
||||
@@ -1,37 +0,0 @@
|
||||
--TEST--
|
||||
DBA FirstKey/NextKey with 2 deletes
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once('skipif.inc');
|
||||
die("info $HND handler used");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once('test.inc');
|
||||
echo "database handler: $handler\n";
|
||||
if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
|
||||
dba_insert("key1", "Content String 1", $db_file);
|
||||
dba_insert("key2", "Content String 2", $db_file);
|
||||
dba_insert("key3", "Third Content String", $db_file);
|
||||
dba_insert("key4", "Another Content String", $db_file);
|
||||
dba_insert("key5", "The last content string", $db_file);
|
||||
dba_delete("key3", $db_file);
|
||||
dba_delete("key1", $db_file);
|
||||
$a = dba_firstkey($db_file);
|
||||
$i=0;
|
||||
while($a) {
|
||||
$a = dba_nextkey($db_file);
|
||||
$i++;
|
||||
}
|
||||
echo $i;
|
||||
for ($i=1; $i<6; $i++) {
|
||||
echo dba_exists("key$i", $db_file) ? "Y" : "N";
|
||||
}
|
||||
dba_close($db_file);
|
||||
} else {
|
||||
echo "Error creating database\n";
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
database handler: %s
|
||||
3NYNYY
|
||||
Loaded 100 of 780 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user