wez             Wed Jan  1 06:04:45 2003 EDT

  Added files:                 
    /php4/ext/standard  filters.c 

  Modified files:              
    /php4/ext/standard  basic_functions.c config.m4 php_standard.h 
                        php_string.h string.c user_filters.c 
    /php4/ext/standard/tests/file       userfilters.phpt 
  Log:
  Move rot13 filter into a new filters.c source file.
  Tidy up some other filter related code.
  
  # win32 -> someone please add user_filters.c and filters.c to the .dsp
  
  
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.551 
php4/ext/standard/basic_functions.c:1.552
--- php4/ext/standard/basic_functions.c:1.551   Tue Dec 31 13:39:29 2002
+++ php4/ext/standard/basic_functions.c Wed Jan  1 06:04:43 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: basic_functions.c,v 1.551 2002/12/31 18:39:29 wez Exp $ */
+/* $Id: basic_functions.c,v 1.552 2003/01/01 11:04:43 wez Exp $ */
 
 #include "php.h"
 #include "php_streams.h"
@@ -1031,7 +1031,7 @@
        PHP_MINIT(file) (INIT_FUNC_ARGS_PASSTHRU);
        PHP_MINIT(pack) (INIT_FUNC_ARGS_PASSTHRU);
        PHP_MINIT(browscap) (INIT_FUNC_ARGS_PASSTHRU);
-       PHP_MINIT(string_filters) (INIT_FUNC_ARGS_PASSTHRU);
+       PHP_MINIT(standard_filters) (INIT_FUNC_ARGS_PASSTHRU);
        PHP_MINIT(user_filters) (INIT_FUNC_ARGS_PASSTHRU);
 
 #if defined(HAVE_LOCALECONV) && defined(ZTS)
@@ -1104,7 +1104,7 @@
        PHP_MSHUTDOWN(assert) (SHUTDOWN_FUNC_ARGS_PASSTHRU);
        PHP_MSHUTDOWN(url_scanner_ex) (SHUTDOWN_FUNC_ARGS_PASSTHRU);
        PHP_MSHUTDOWN(file) (SHUTDOWN_FUNC_ARGS_PASSTHRU);
-       PHP_MSHUTDOWN(string_filters) (SHUTDOWN_FUNC_ARGS_PASSTHRU);
+       PHP_MSHUTDOWN(standard_filters) (SHUTDOWN_FUNC_ARGS_PASSTHRU);
 #if defined(HAVE_LOCALECONV) && defined(ZTS)
        PHP_MSHUTDOWN(localeconv) (SHUTDOWN_FUNC_ARGS_PASSTHRU);
 #endif
Index: php4/ext/standard/config.m4
diff -u php4/ext/standard/config.m4:1.49 php4/ext/standard/config.m4:1.50
--- php4/ext/standard/config.m4:1.49    Tue Dec 31 13:39:35 2002
+++ php4/ext/standard/config.m4 Wed Jan  1 06:04:44 2003
@@ -1,4 +1,4 @@
-dnl $Id: config.m4,v 1.49 2002/12/31 18:39:35 wez Exp $ -*- sh -*-
+dnl $Id: config.m4,v 1.50 2003/01/01 11:04:44 wez Exp $ -*- sh -*-
 
 divert(3)dnl
 
@@ -255,6 +255,7 @@
                             url_scanner.c var.c versioning.c assert.c strnatcmp.c 
levenshtein.c \
                             incomplete_class.c url_scanner_ex.c ftp_fopen_wrapper.c \
                             http_fopen_wrapper.c php_fopen_wrapper.c credits.c css.c \
-                            var_unserializer.c ftok.c aggregation.c sha1.c 
user_filters.c )
+                            var_unserializer.c ftok.c aggregation.c sha1.c 
+user_filters.c \
+                                                       filters.c )
 
 PHP_ADD_MAKEFILE_FRAGMENT
Index: php4/ext/standard/php_standard.h
diff -u php4/ext/standard/php_standard.h:1.17 php4/ext/standard/php_standard.h:1.18
--- php4/ext/standard/php_standard.h:1.17       Tue Dec 31 11:07:53 2002
+++ php4/ext/standard/php_standard.h    Wed Jan  1 06:04:44 2003
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_standard.h,v 1.17 2002/12/31 16:07:53 sebastian Exp $ */
+/* $Id: php_standard.h,v 1.18 2003/01/01 11:04:44 wez Exp $ */
 
 #include "basic_functions.h"
 #include "php_math.h"
@@ -62,6 +62,9 @@
 #include "aggregation.h"
 
 #define phpext_standard_ptr basic_functions_module_ptr
+PHP_MINIT_FUNCTION(standard_filters);
+PHP_MSHUTDOWN_FUNCTION(standard_filters);
+
 
 /*
  * Local variables:
Index: php4/ext/standard/php_string.h
diff -u php4/ext/standard/php_string.h:1.66 php4/ext/standard/php_string.h:1.67
--- php4/ext/standard/php_string.h:1.66 Tue Dec 31 11:07:53 2002
+++ php4/ext/standard/php_string.h      Wed Jan  1 06:04:44 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_string.h,v 1.66 2002/12/31 16:07:53 sebastian Exp $ */
+/* $Id: php_string.h,v 1.67 2003/01/01 11:04:44 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */
 
@@ -90,9 +90,6 @@
 #if HAVE_STRFMON
 PHP_FUNCTION(money_format);
 #endif
-
-PHP_MINIT_FUNCTION(string_filters);
-PHP_MSHUTDOWN_FUNCTION(string_filters);
 
 #if defined(HAVE_LOCALECONV) && defined(ZTS)
 PHP_MINIT_FUNCTION(localeconv);
Index: php4/ext/standard/string.c
diff -u php4/ext/standard/string.c:1.340 php4/ext/standard/string.c:1.341
--- php4/ext/standard/string.c:1.340    Tue Dec 31 11:07:55 2002
+++ php4/ext/standard/string.c  Wed Jan  1 06:04:44 2003
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: string.c,v 1.340 2002/12/31 16:07:55 sebastian Exp $ */
+/* $Id: string.c,v 1.341 2003/01/01 11:04:44 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -4166,82 +4166,6 @@
 
 /* }}} */
 #endif
-
-/* {{{ rot13 stream filter implementation */
-static size_t strfilter_rot13_write(php_stream *stream, php_stream_filter *thisfilter,
-                       const char *buf, size_t count TSRMLS_DC)
-{
-       char rotbuf[1024];
-       size_t chunk;
-       size_t wrote = 0;
-
-       while (count > 0) {
-               chunk = count;
-               if (chunk > sizeof(rotbuf))
-                       chunk = sizeof(rotbuf);
-
-               PHP_STRLCPY(rotbuf, buf, sizeof(rotbuf), chunk);
-               buf += chunk;
-               count -= chunk;
-
-               php_strtr(rotbuf, chunk, rot13_from, rot13_to, 52);
-               wrote += php_stream_filter_write_next(stream, thisfilter, rotbuf, 
chunk);
-       }
-
-       return wrote;
-}
-
-static size_t strfilter_rot13_read(php_stream *stream, php_stream_filter *thisfilter,
-                       char *buf, size_t count TSRMLS_DC)
-{
-       size_t read;
-
-       read = php_stream_filter_read_next(stream, thisfilter, buf, count);
-       php_strtr(buf, read, rot13_from, rot13_to, 52);
-
-       return read;
-}
-
-static int strfilter_rot13_flush(php_stream *stream, php_stream_filter *thisfilter, 
int closing TSRMLS_DC)
-{
-       return php_stream_filter_flush_next(stream, thisfilter, closing);
-}
-
-static int strfilter_rot13_eof(php_stream *stream, php_stream_filter *thisfilter 
TSRMLS_DC)
-{
-       return php_stream_filter_eof_next(stream, thisfilter);
-}
-
-
-static php_stream_filter_ops strfilter_rot13_ops = {
-       strfilter_rot13_write,
-       strfilter_rot13_read,
-       strfilter_rot13_flush,
-       strfilter_rot13_eof,
-       NULL,
-       "string.rot13"
-};
-
-static php_stream_filter *strfilter_rot13_create(const char *filtername, const char 
*filterparams,
-               int filterparamslen, int persistent TSRMLS_DC)
-{
-       return php_stream_filter_alloc(&strfilter_rot13_ops, NULL, persistent);
-}
-
-static php_stream_filter_factory strfilter_rot13_factory = {
-       strfilter_rot13_create
-};
-
-PHP_MINIT_FUNCTION(string_filters)
-{
-       return php_stream_filter_register_factory("string.rot13", 
&strfilter_rot13_factory TSRMLS_CC);
-}
-
-PHP_MSHUTDOWN_FUNCTION(string_filters)
-{
-       return php_stream_filter_unregister_factory("string.rot13" TSRMLS_CC);
-}
-/* }}} */
 
 /*
  * Local variables:
Index: php4/ext/standard/user_filters.c
diff -u php4/ext/standard/user_filters.c:1.1 php4/ext/standard/user_filters.c:1.2
--- php4/ext/standard/user_filters.c:1.1        Tue Dec 31 13:39:35 2002
+++ php4/ext/standard/user_filters.c    Wed Jan  1 06:04:44 2003
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: user_filters.c,v 1.1 2002/12/31 18:39:35 wez Exp $ */
+/* $Id: user_filters.c,v 1.2 2003/01/01 11:04:44 wez Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -445,3 +445,13 @@
        efree(fdat);
 }
 /* }}} */
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
Index: php4/ext/standard/tests/file/userfilters.phpt
diff -u php4/ext/standard/tests/file/userfilters.phpt:1.1 
php4/ext/standard/tests/file/userfilters.phpt:1.2
--- php4/ext/standard/tests/file/userfilters.phpt:1.1   Tue Dec 31 13:39:36 2002
+++ php4/ext/standard/tests/file/userfilters.phpt       Wed Jan  1 06:04:44 2003
@@ -45,7 +45,7 @@
 
 var_dump(stream_filter_prepend($fp, "string.uppercase"));
 var_dump(fgets($fp));
-
+fclose($fp);
 ?>
 --EXPECT--
 bool(true)

Index: php4/ext/standard/filters.c
+++ php4/ext/standard/filters.c
/*
   +----------------------------------------------------------------------+
   | PHP Version 4                                                        |
   +----------------------------------------------------------------------+
   | Copyright (c) 1997-2003 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          |
   | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Authors:                                                             |
   | Wez Furlong ([EMAIL PROTECTED])                                   |
   +----------------------------------------------------------------------+
*/

/* $Id: filters.c,v 1.1 2003/01/01 11:04:44 wez Exp $ */

#include "php.h"
#include "php_globals.h"
#include "ext/standard/basic_functions.h"
#include "ext/standard/file.h"

/* {{{ rot13 stream filter implementation */
static char rot13_from[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
static char rot13_to[] = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM";

static size_t strfilter_rot13_write(php_stream *stream, php_stream_filter *thisfilter,
                        const char *buf, size_t count TSRMLS_DC)
{
        char rotbuf[1024];
        size_t chunk;
        size_t wrote = 0;

        while (count > 0) {
                chunk = count;
                if (chunk > sizeof(rotbuf))
                        chunk = sizeof(rotbuf);

                PHP_STRLCPY(rotbuf, buf, sizeof(rotbuf), chunk);
                buf += chunk;
                count -= chunk;

                php_strtr(rotbuf, chunk, rot13_from, rot13_to, 52);
                wrote += php_stream_filter_write_next(stream, thisfilter, rotbuf, 
chunk);
        }

        return wrote;
}

static size_t strfilter_rot13_read(php_stream *stream, php_stream_filter *thisfilter,
                        char *buf, size_t count TSRMLS_DC)
{
        size_t read;

        read = php_stream_filter_read_next(stream, thisfilter, buf, count);
        php_strtr(buf, read, rot13_from, rot13_to, 52);

        return read;
}

static int strfilter_rot13_flush(php_stream *stream, php_stream_filter *thisfilter, 
int closing TSRMLS_DC)
{
        return php_stream_filter_flush_next(stream, thisfilter, closing);
}

static int strfilter_rot13_eof(php_stream *stream, php_stream_filter *thisfilter 
TSRMLS_DC)
{
        return php_stream_filter_eof_next(stream, thisfilter);
}

static php_stream_filter_ops strfilter_rot13_ops = {
        strfilter_rot13_write,
        strfilter_rot13_read,
        strfilter_rot13_flush,
        strfilter_rot13_eof,
        NULL,
        "string.rot13"
};

static php_stream_filter *strfilter_rot13_create(const char *filtername, const char 
*filterparams,
                int filterparamslen, int persistent TSRMLS_DC)
{
        return php_stream_filter_alloc(&strfilter_rot13_ops, NULL, persistent);
}

static php_stream_filter_factory strfilter_rot13_factory = {
        strfilter_rot13_create
};
/* }}} */

static const struct {
        php_stream_filter_ops *ops;
        php_stream_filter_factory *factory;
} standard_filters[] = {
        { &strfilter_rot13_ops, &strfilter_rot13_factory },
        { NULL, NULL }
};

PHP_MINIT_FUNCTION(standard_filters)
{
        int i;

        for (i = 0; standard_filters[i].ops; i++) {
                if (FAILURE == php_stream_filter_register_factory(
                                        standard_filters[i].ops->label,
                                        standard_filters[i].factory
                                        TSRMLS_CC)) {
                        return FAILURE;
                }
        }

        return SUCCESS;
}

PHP_MSHUTDOWN_FUNCTION(standard_filters)
{
        int i;

        for (i = 0; standard_filters[i].ops; i++) {
                php_stream_filter_unregister_factory(standard_filters[i].ops->label 
TSRMLS_CC);
        }
        return SUCCESS;
}

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: sw=4 ts=4 fdm=marker
 * vim<600: sw=4 ts=4
 */

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to