[PHP-CVS] cvs: php4 /ext/standard file.c

2003-06-14 Thread Marcus Boerger
helly   Sat Jun 14 13:08:49 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  Fix  ZTS mode
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.347 php4/ext/standard/file.c:1.348
--- php4/ext/standard/file.c:1.347  Fri Jun 13 17:33:59 2003
+++ php4/ext/standard/file.cSat Jun 14 13:08:49 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.347 2003/06/13 21:33:59 pollita Exp $ */
+/* $Id: file.c,v 1.348 2003/06/14 17:08:49 helly Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -131,6 +131,7 @@
 {
php_stream_context *context = (php_stream_context*)rsrc-ptr;
zval_dtor(context-options);
+   context-options = NULL;
php_stream_context_free(context);
 }
 



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



[PHP-CVS] cvs: php4 /ext/standard file.c /main/streams streams.c

2003-06-14 Thread Marcus Boerger
helly   Sat Jun 14 15:30:42 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
/php4/main/streams  streams.c 
  Log:
  Fix ZTS mode (hopefully all is working fine now again)
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.348 php4/ext/standard/file.c:1.349
--- php4/ext/standard/file.c:1.348  Sat Jun 14 13:08:49 2003
+++ php4/ext/standard/file.cSat Jun 14 15:30:42 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.348 2003/06/14 17:08:49 helly Exp $ */
+/* $Id: file.c,v 1.349 2003/06/14 19:30:42 helly Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -130,8 +130,10 @@
 static ZEND_RSRC_DTOR_FUNC(file_context_dtor)
 {
php_stream_context *context = (php_stream_context*)rsrc-ptr;
-   zval_dtor(context-options);
-   context-options = NULL;
+   if (context-options) {
+   zval_ptr_dtor(context-options);
+   context-options = NULL;
+   }
php_stream_context_free(context);
 }
 
Index: php4/main/streams/streams.c
diff -u php4/main/streams/streams.c:1.25 php4/main/streams/streams.c:1.26
--- php4/main/streams/streams.c:1.25Fri Jun 13 17:33:59 2003
+++ php4/main/streams/streams.c Sat Jun 14 15:30:42 2003
@@ -19,7 +19,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.25 2003/06/13 21:33:59 pollita Exp $ */
+/* $Id: streams.c,v 1.26 2003/06/14 19:30:42 helly Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -413,7 +413,7 @@
size_t justread = 0;
int flags;
php_stream_bucket *bucket;
-   php_stream_filter_status_t status;
+   php_stream_filter_status_t status = PSFS_ERR_FATAL;
php_stream_filter *filter;
 
/* read a chunk into a bucket */
@@ -893,7 +893,7 @@
php_stream_bucket *bucket;
php_stream_bucket_brigade brig_in = { NULL, NULL }, brig_out = { NULL, NULL };
php_stream_bucket_brigade *brig_inp = brig_in, *brig_outp = brig_out, 
*brig_swap;
-   php_stream_filter_status_t status;
+   php_stream_filter_status_t status = PSFS_ERR_FATAL;
php_stream_filter *filter;
 
if (buf) {
@@ -1618,7 +1618,10 @@
 
 PHPAPI void php_stream_context_free(php_stream_context *context)
 {
-   zval_ptr_dtor(context-options);
+   if (context-options) {
+   zval_ptr_dtor(context-options);
+   context-options = NULL;
+   }
efree(context);
 }
 



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



[PHP-CVS] cvs: php4 /ext/standard file.c

2003-05-31 Thread Ilia Alshanetsky
iliaa   Fri May 30 20:32:45 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  Fixed bug #23913 (make rename() work across partitions on *nix)
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.343 php4/ext/standard/file.c:1.344
--- php4/ext/standard/file.c:1.343  Wed May 21 17:36:51 2003
+++ php4/ext/standard/file.cFri May 30 20:32:45 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.343 2003/05/21 21:36:51 pollita Exp $ */
+/* $Id: file.c,v 1.344 2003/05/31 00:32:45 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -1391,6 +1391,14 @@
ret = VCWD_RENAME(old_name, new_name);
 
if (ret == -1) {
+#ifdef EXDEV
+   if (errno == EXDEV) {
+   if (php_copy_file(old_name, new_name TSRMLS_CC) == SUCCESS) {
+   VCWD_UNLINK(old_name);
+   RETURN_TRUE;
+   }
+   }
+#endif 
php_error_docref2(NULL TSRMLS_CC, old_name, new_name, E_WARNING, %s, 
strerror(errno));
RETURN_FALSE;
}



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



[PHP-CVS] cvs: php4 /ext/standard file.c

2003-03-28 Thread Ilia Alshanetsky
iliaa   Fri Mar 28 09:31:31 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  CS
  
  Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.328 php4/ext/standard/file.c:1.329
--- php4/ext/standard/file.c:1.328  Fri Mar 21 17:22:15 2003
+++ php4/ext/standard/file.cFri Mar 28 09:31:31 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.328 2003/03/21 22:22:15 sterling Exp $ */
+/* $Id: file.c,v 1.329 2003/03/28 14:31:31 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -539,10 +539,10 @@
if (!(p = php_stream_locate_eol(stream, target_buf, target_len 
TSRMLS_CC))) {
p = e;
goto parse_eol;
-   }
-   
+   }
+
if (stream-flags  PHP_STREAM_FLAG_EOL_MAC) {
-   eol_marker = '\r';
+   eol_marker = '\r';
}   
 
/* for performance reasons the code is duplicated, so that the if 
(include_new_line) 
@@ -558,7 +558,7 @@
add_index_stringl(return_value, i++, slashed, 
len, 0);
} else {
add_index_stringl(return_value, i++, 
estrndup(s, p-s), p-s, 0);
-   }
+   }
s = p;
} while ((p = memchr(p, eol_marker, (e-p;
} else {
@@ -573,7 +573,7 @@
add_index_stringl(return_value, i++, slashed, 
len, 0);
} else {
add_index_stringl(return_value, i++, 
estrndup(s, p-s), p-s, 0);
-   }
+   }
s = ++p;
} while ((p = memchr(p, eol_marker, (e-p;
}
@@ -582,8 +582,8 @@
if (s != e) {
p = e;
goto parse_eol;
-   }
-   }
+   }
+   }
 
if (target_buf) {
efree(target_buf);
@@ -637,10 +637,9 @@
 
stream = php_stream_fopen_tmpfile();
 
-   if (stream) {
+   if (stream) {
php_stream_to_zval(stream, return_value);
-   }
-   else{
+   } else {
RETURN_FALSE;
}
 }
@@ -665,9 +664,7 @@
ZEND_FETCH_RESOURCE(context, php_stream_context*, zcontext, -1, 
stream-context, le_stream_context);
}

-   stream = php_stream_open_wrapper_ex(filename, mode,
-   (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE 
| REPORT_ERRORS,
-   NULL, context);
+   stream = php_stream_open_wrapper_ex(filename, mode, (use_include_path ? 
USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, context);
 
if (stream == NULL) {
RETURN_FALSE;
@@ -822,8 +819,9 @@
if (argc == 1) {
/* ask streams to give us a buffer of an appropriate size */
buf = php_stream_get_line(stream, NULL, 0, line_len);
-   if (buf == NULL)
+   if (buf == NULL) {
goto exit_failed;
+   }
} else if (argc  1) {
convert_to_long_ex(arg2);
len = Z_LVAL_PP(arg2);
@@ -834,8 +832,9 @@
}
 
buf = ecalloc(len + 1, sizeof(char));
-   if (php_stream_get_line(stream, buf, len, line_len) == NULL)
+   if (php_stream_get_line(stream, buf, len, line_len) == NULL) {
goto exit_failed;
+   }
}

if (PG(magic_quotes_runtime)) {
@@ -853,8 +852,9 @@
 
 exit_failed:
RETVAL_FALSE;
-   if (buf)
+   if (buf) {
efree(buf);
+   }
 }
 /* }}} */
 
@@ -902,28 +902,31 @@
int allowed_tags_len=0;
 
switch(ZEND_NUM_ARGS()) {
-   case 1:
-   if (zend_get_parameters_ex(1, fd) == FAILURE) {
-   RETURN_FALSE;
-   }
-   break;
-   case 2:
-   if (zend_get_parameters_ex(2, fd, bytes) == FAILURE) {
-   RETURN_FALSE;
-   }
-   break;
-   case 3:
-   if (zend_get_parameters_ex(3, fd, bytes, allow) == FAILURE) {
-   RETURN_FALSE;
-   }
-   convert_to_string_ex(allow);
-   allowed_tags = Z_STRVAL_PP(allow);
-   allowed_tags_len = Z_STRLEN_PP(allow);
-   break;
-   default:
-   WRONG_PARAM_COUNT;
-   /* NOTREACHED */
-   break;
+   case 1:
+ 

[PHP-CVS] cvs: php4 /ext/standard file.c

2003-03-21 Thread Sterling Hughes
sterlingFri Mar 21 17:22:16 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  fix segfault in file_set_contents() when the file could not successfully 
  be opened.
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.327 php4/ext/standard/file.c:1.328
--- php4/ext/standard/file.c:1.327  Tue Mar 18 09:35:15 2003
+++ php4/ext/standard/file.cFri Mar 21 17:22:15 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.327 2003/03/18 14:35:15 wez Exp $ */
+/* $Id: file.c,v 1.328 2003/03/21 22:22:15 sterling Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -476,6 +476,10 @@
 
stream = php_stream_open_wrapper(filename, wb, 
(use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | 
REPORT_ERRORS, NULL);
+   if (stream == NULL) {
+   RETURN_FALSE;
+   }
+
if (data_len) {
numbytes = php_stream_write(stream, data, data_len);
if (numbytes  0) {



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



[PHP-CVS] cvs: php4 /ext/standard file.c /main php_streams.h /main/streams xp_socket.c

2003-02-27 Thread Wez Furlong
wez Thu Feb 27 14:10:24 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
/php4/main  php_streams.h 
/php4/main/streams  xp_socket.c 
  Log:
  Add a generic meta data api for streams.
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.317 php4/ext/standard/file.c:1.318
--- php4/ext/standard/file.c:1.317  Thu Feb 27 13:16:34 2003
+++ php4/ext/standard/file.cThu Feb 27 14:10:22 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.317 2003/02/27 18:16:34 wez Exp $ */
+/* $Id: file.c,v 1.318 2003/02/27 19:10:22 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -646,22 +646,12 @@
 #endif

add_assoc_long(return_value, unread_bytes, stream-writepos - 
stream-readpos);
-   
-#if 0
-   if (php_stream_is(stream, PHP_STREAM_IS_SOCKET)){
-   php_netstream_data_t *sock = PHP_NETSTREAM_DATA_FROM_STREAM(stream);
-
-   add_assoc_bool(return_value, timed_out, sock-timeout_event);
-   add_assoc_bool(return_value, blocked, sock-is_blocked);
-   add_assoc_bool(return_value, eof, stream-eof);
-   } else {
-#endif
+
+   if (!php_stream_populate_meta_data(stream, return_value)) {
add_assoc_bool(return_value, timed_out, 0);
add_assoc_bool(return_value, blocked, 1);
add_assoc_bool(return_value, eof, php_stream_eof(stream));
-#if 0
}
-#endif
 
 }
 /* }}} */
Index: php4/main/php_streams.h
diff -u php4/main/php_streams.h:1.75 php4/main/php_streams.h:1.76
--- php4/main/php_streams.h:1.75Thu Feb 27 12:43:37 2003
+++ php4/main/php_streams.h Thu Feb 27 14:10:23 2003
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_streams.h,v 1.75 2003/02/27 17:43:37 wez Exp $ */
+/* $Id: php_streams.h,v 1.76 2003/02/27 19:10:23 wez Exp $ */
 
 #ifndef PHP_STREAMS_H
 #define PHP_STREAMS_H
@@ -348,6 +348,9 @@
 
 PHPAPI int _php_stream_truncate_set_size(php_stream *stream, size_t newsize 
TSRMLS_DC);
 #define php_stream_truncate_set_size(stream, size) 
_php_stream_truncate_set_size((stream), (size) TSRMLS_CC)
+
+#define PHP_STREAM_OPTION_META_DATA_API11 /* ptrparam is a zval* to 
which to add meta data information */
+#define php_stream_populate_meta_data(stream, zv)  
(_php_stream_set_option((stream), PHP_STREAM_OPTION_META_DATA_API, 0, zv TSRMLS_CC) == 
PHP_STREAM_OPTION_RETURN_OK ? 1 : 0)
 
 #define PHP_STREAM_OPTION_RETURN_OK 0 /* option set OK */
 #define PHP_STREAM_OPTION_RETURN_ERR   -1 /* problem setting option */
Index: php4/main/streams/xp_socket.c
diff -u php4/main/streams/xp_socket.c:1.2 php4/main/streams/xp_socket.c:1.3
--- php4/main/streams/xp_socket.c:1.2   Thu Feb 27 13:06:30 2003
+++ php4/main/streams/xp_socket.c   Thu Feb 27 14:10:24 2003
@@ -16,7 +16,7 @@
   +--+
 */
 
-/* $Id: xp_socket.c,v 1.2 2003/02/27 18:06:30 wez Exp $ */
+/* $Id: xp_socket.c,v 1.3 2003/02/27 19:10:24 wez Exp $ */
 
 #include php.h
 #include ext/standard/file.h
@@ -201,6 +201,12 @@
case PHP_STREAM_OPTION_READ_TIMEOUT:
sock-timeout = *(struct timeval*)ptrparam;
sock-timeout_event = 0;
+   return PHP_STREAM_OPTION_RETURN_OK;
+
+   case PHP_STREAM_OPTION_META_DATA_API:
+   add_assoc_bool((zval *)ptrparam, timed_out, 
sock-timeout_event);
+   add_assoc_bool((zval *)ptrparam, blocked, sock-is_blocked);
+   add_assoc_bool((zval *)ptrparam, eof, stream-eof);
return PHP_STREAM_OPTION_RETURN_OK;

case PHP_STREAM_OPTION_XPORT_API:



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



[PHP-CVS] cvs: php4 /ext/standard file.c

2003-02-27 Thread Hartmut Holzgraefe
hholzgraFri Feb 28 02:52:23 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  make sure that GNU extensions exist for fnmatch()
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.319 php4/ext/standard/file.c:1.320
--- php4/ext/standard/file.c:1.319  Thu Feb 27 17:23:39 2003
+++ php4/ext/standard/file.cFri Feb 28 02:52:23 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.319 2003/02/27 22:23:39 wez Exp $ */
+/* $Id: file.c,v 1.320 2003/02/28 07:52:23 hholzgra Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -107,6 +107,8 @@
 #endif
 
 #ifdef HAVE_FNMATCH
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
 #include fnmatch.h
 #endif
 



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



[PHP-CVS] cvs: php4 /ext/standard file.c

2003-02-27 Thread Hartmut Holzgraefe
hholzgraFri Feb 28 02:57:01 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  it is still to early in the morning for coding :(
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.320 php4/ext/standard/file.c:1.321
--- php4/ext/standard/file.c:1.320  Fri Feb 28 02:52:23 2003
+++ php4/ext/standard/file.cFri Feb 28 02:57:00 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.320 2003/02/28 07:52:23 hholzgra Exp $ */
+/* $Id: file.c,v 1.321 2003/02/28 07:57:00 hholzgra Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -109,6 +109,7 @@
 #ifdef HAVE_FNMATCH
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
+#endif
 #include fnmatch.h
 #endif
 



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



[PHP-CVS] cvs: php4 /ext/standard file.c

2003-02-26 Thread Derick Rethans
derick  Wed Feb 26 14:34:16 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  - Fix proto
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.314 php4/ext/standard/file.c:1.315
--- php4/ext/standard/file.c:1.314  Tue Feb 25 15:12:18 2003
+++ php4/ext/standard/file.cWed Feb 26 14:34:16 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.314 2003/02/25 20:12:18 moriyoshi Exp $ */
+/* $Id: file.c,v 1.315 2003/02/26 19:34:16 derick Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -2082,7 +2082,7 @@
 }
 /* }}} */
 
-/* {{{ proto int readfile(string filename [, int use_include_path])
+/* {{{ proto int readfile(string filename [, bool use_include_path])
Output a file or a URL */
 PHP_FUNCTION(readfile)
 {



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



Re: [PHP-CVS] cvs: php4 /ext/standard file.c /main php_streams.h /main/streams plain_wrapper.c

2003-02-26 Thread Marcus Börger
At 02:39 25.02.2003, Ilia Alshanetsky wrote:
iliaa   Mon Feb 24 20:39:07 2003 EDT

  Log:
  Added locking to streams.
  Allow PHP to automatically release locks on files when terminating the
  stream.
  Fixed bugs in the handling of the 3rd optional parameter to flock().


What about updating README.STREAMS ?

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


[PHP-CVS] cvs: php4 /ext/standard file.c

2003-02-25 Thread Moriyoshi Koizumi
moriyoshi   Tue Feb 25 15:12:22 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  Set fgetss() free from the length parameter
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.313 php4/ext/standard/file.c:1.314
--- php4/ext/standard/file.c:1.313  Mon Feb 24 20:39:06 2003
+++ php4/ext/standard/file.cTue Feb 25 15:12:18 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.313 2003/02/25 01:39:06 iliaa Exp $ */
+/* $Id: file.c,v 1.314 2003/02/25 20:12:18 moriyoshi Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -1668,19 +1668,24 @@
 }
 /* }}} */
 
-/* {{{ proto string fgetss(resource fp, int length [, string allowable_tags])
+/* {{{ proto string fgetss(resource fp [, int length, string allowable_tags])
Get a line from file pointer and strip HTML tags */
 PHPAPI PHP_FUNCTION(fgetss)
 {
-   zval **fd, **bytes, **allow=NULL;
-   int len;
+   zval **fd, **bytes = NULL, **allow=NULL;
+   size_t len = 0;
size_t actual_len, retval_len;
-   char *buf;
+   char *buf = NULL, *retval;
php_stream *stream;
char *allowed_tags=NULL;
int allowed_tags_len=0;
 
switch(ZEND_NUM_ARGS()) {
+   case 1:
+   if (zend_get_parameters_ex(1, fd) == FAILURE) {
+   RETURN_FALSE;
+   }
+   break;
case 2:
if (zend_get_parameters_ex(2, fd, bytes) == FAILURE) {
RETURN_FALSE;
@@ -1702,26 +1707,29 @@
 
php_stream_from_zval(stream, fd);
 
-   convert_to_long_ex(bytes);
-   len = Z_LVAL_PP(bytes);
-if (len  0) {
-   php_error_docref(NULL TSRMLS_CC, E_WARNING, Length parameter may not 
be negative);
-   RETURN_FALSE;
-}
-
-   buf = emalloc(sizeof(char) * (len + 1));
-   /*needed because recv doesnt set null char at end*/
-   memset(buf, 0, len + 1);
+   if (bytes != NULL) {
+   convert_to_long_ex(bytes);
+   if (Z_LVAL_PP(bytes)  0) {
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, Length parameter 
may not be negative);
+   RETURN_FALSE;
+   }
 
-   if (php_stream_get_line(stream, buf, len, actual_len) == NULL) {
-   efree(buf);
+   len = (size_t) Z_LVAL_PP(bytes);
+   buf = emalloc(sizeof(char) * (len + 1));
+   /*needed because recv doesnt set null char at end*/
+   memset(buf, 0, len + 1);
+   }
+
+   if ((retval = php_stream_get_line(stream, buf, len, actual_len)) == NULL) 
 {
+   if (buf != NULL) {
+   efree(buf);
+   }
RETURN_FALSE;
}
 
-   /* strlen() can be used here since we are doing it on the return of an fgets() 
anyway */
-   retval_len = php_strip_tags(buf, actual_len, stream-fgetss_state, 
allowed_tags, allowed_tags_len);
+   retval_len = php_strip_tags(retval, actual_len, stream-fgetss_state, 
allowed_tags, allowed_tags_len);
 
-   RETURN_STRINGL(buf, retval_len, 0);
+   RETURN_STRINGL(retval, retval_len, 0);
 }
 /* }}} */
 



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



[PHP-CVS] cvs: php4 /ext/standard file.c /main php_streams.h /main/streams cast.c plain_wrapper.c streams.c

2003-02-24 Thread Wez Furlong
wez Mon Feb 24 16:40:24 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
/php4/main  php_streams.h 
/php4/main/streams  cast.c plain_wrapper.c streams.c 
  Log:
  MFB: Bunch of streams related fixes.
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.310 php4/ext/standard/file.c:1.311
--- php4/ext/standard/file.c:1.310  Sun Feb 23 22:13:25 2003
+++ php4/ext/standard/file.cMon Feb 24 16:40:23 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.310 2003/02/24 03:13:25 iliaa Exp $ */
+/* $Id: file.c,v 1.311 2003/02/24 21:40:23 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -2384,7 +2384,7 @@
int ret = FAILURE;
 
srcstream = php_stream_open_wrapper(src, rb, 
-   ENFORCE_SAFE_MODE | REPORT_ERRORS,
+   STREAM_DISABLE_OPEN_BASEDIR | REPORT_ERRORS,
NULL);

if (!srcstream) {
Index: php4/main/php_streams.h
diff -u php4/main/php_streams.h:1.71 php4/main/php_streams.h:1.72
--- php4/main/php_streams.h:1.71Mon Feb 17 20:22:21 2003
+++ php4/main/php_streams.h Mon Feb 24 16:40:23 2003
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_streams.h,v 1.71 2003/02/18 01:22:21 wez Exp $ */
+/* $Id: php_streams.h,v 1.72 2003/02/24 21:40:23 wez Exp $ */
 
 #ifndef PHP_STREAMS_H
 #define PHP_STREAMS_H
@@ -405,6 +405,9 @@
 
 /* this flag is used when only the headers from HTTP request are to be fetched */
 #define STREAM_ONLY_GET_HEADERS512
+
+/* don't apply open_basedir checks */
+#define STREAM_DISABLE_OPEN_BASEDIR1024
 
 /* Antique - no longer has meaning */
 #define IGNORE_URL_WIN 0
Index: php4/main/streams/cast.c
diff -u php4/main/streams/cast.c:1.3 php4/main/streams/cast.c:1.4
--- php4/main/streams/cast.c:1.3Wed Feb 19 03:40:19 2003
+++ php4/main/streams/cast.cMon Feb 24 16:40:23 2003
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: cast.c,v 1.3 2003/02/19 08:40:19 sniper Exp $ */
+/* $Id: cast.c,v 1.4 2003/02/24 21:40:23 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -208,7 +208,12 @@
return FAILURE;
 #endif
 
-   if (flags  PHP_STREAM_CAST_TRY_HARD) {
+   if (!php_stream_is_filtered(stream)  stream-ops-cast  
stream-ops-cast(stream, castas, NULL TSRMLS_CC) == SUCCESS) {
+   if (FAILURE == stream-ops-cast(stream, castas, ret 
TSRMLS_CC)) {
+   return FAILURE;
+   }
+   goto exit_success;
+   } else if (flags  PHP_STREAM_CAST_TRY_HARD) {
php_stream *newstream;
 
newstream = php_stream_fopen_tmpfile();
Index: php4/main/streams/plain_wrapper.c
diff -u php4/main/streams/plain_wrapper.c:1.2 php4/main/streams/plain_wrapper.c:1.3
--- php4/main/streams/plain_wrapper.c:1.2   Wed Feb 19 03:40:19 2003
+++ php4/main/streams/plain_wrapper.c   Mon Feb 24 16:40:23 2003
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: plain_wrapper.c,v 1.2 2003/02/19 08:40:19 sniper Exp $ */
+/* $Id: plain_wrapper.c,v 1.3 2003/02/24 21:40:23 wez Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -603,7 +603,7 @@
DIR *dir = NULL;
php_stream *stream = NULL;
 
-   if (php_check_open_basedir(path TSRMLS_CC)) {
+   if ((options  STREAM_DISABLE_OPEN_BASEDIR == 0)  
php_check_open_basedir(path TSRMLS_CC)) {
return NULL;
}

@@ -637,7 +637,7 @@
return php_stream_fopen_with_path_rel(path, mode, PG(include_path), 
opened_path, options);
}
 
-   if (php_check_open_basedir(path TSRMLS_CC)) {
+   if ((options  STREAM_DISABLE_OPEN_BASEDIR == 0)  
php_check_open_basedir(path TSRMLS_CC)) {
return NULL;
}
 
@@ -702,7 +702,7 @@
}
 
 
-   if (php_check_open_basedir(filename TSRMLS_CC)) {
+   if ((options  STREAM_DISABLE_OPEN_BASEDIR == 0)  
php_check_open_basedir(filename TSRMLS_CC)) {
return NULL;
}
 
@@ -722,7 +722,7 @@
/* Absolute path open */
if (IS_ABSOLUTE_PATH(filename, filename_length)) {
 
-   if (php_check_open_basedir(filename TSRMLS_CC)) {
+   if ((options  STREAM_DISABLE_OPEN_BASEDIR == 0)  
php_check_open_basedir(filename TSRMLS_CC)) {
return NULL;
}
 
@@ -748,7 +748,7 @@

free(cwd);

-   if (php_check_open_basedir(trypath TSRMLS_CC)) {
+   if ((options  STREAM_DISABLE_OPEN_BASEDIR == 0)  

Re: [PHP-CVS] cvs: php4 /ext/standard file.c /main php_streams.h /main/streams cast.c plain_wrapper.c streams.c

2003-02-24 Thread Rasmus Lerdorf
On Mon, 24 Feb 2003, Wez Furlong wrote:
 wez   Mon Feb 24 16:40:24 2003 EDT
 
   Modified files:  
 /php4/ext/standardfile.c 
 /php4/mainphp_streams.h 
 /php4/main/streamscast.c plain_wrapper.c streams.c 
   Log:
   MFB: Bunch of streams related fixes.

Sorry, which branch are you merging from?  


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



[PHP-CVS] cvs: php4 /ext/standard file.c

2003-02-24 Thread Moriyoshi Koizumi
moriyoshi   Mon Feb 24 17:39:47 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  Made fgetss() binary safe too
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.311 php4/ext/standard/file.c:1.312
--- php4/ext/standard/file.c:1.311  Mon Feb 24 16:40:23 2003
+++ php4/ext/standard/file.cMon Feb 24 17:39:47 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.311 2003/02/24 21:40:23 wez Exp $ */
+/* $Id: file.c,v 1.312 2003/02/24 22:39:47 moriyoshi Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -1675,6 +1675,7 @@
 {
zval **fd, **bytes, **allow=NULL;
int len;
+   size_t actual_len, retval_len;
char *buf;
php_stream *stream;
char *allowed_tags=NULL;
@@ -1713,15 +1714,15 @@
/*needed because recv doesnt set null char at end*/
memset(buf, 0, len + 1);
 
-   if (php_stream_gets(stream, buf, len) == NULL)  {
+   if (php_stream_get_line(stream, buf, len, actual_len) == NULL) {
efree(buf);
RETURN_FALSE;
}
 
/* strlen() can be used here since we are doing it on the return of an fgets() 
anyway */
-   php_strip_tags(buf, strlen(buf), stream-fgetss_state, allowed_tags, 
allowed_tags_len);
+   retval_len = php_strip_tags(buf, actual_len, stream-fgetss_state, 
allowed_tags, allowed_tags_len);
 
-   RETURN_STRING(buf, 0);
+   RETURN_STRINGL(buf, retval_len, 0);
 }
 /* }}} */
 



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



Re: [PHP-CVS] cvs: php4 /ext/standard file.c /main php_streams.h /main/streams cast.c plain_wrapper.c streams.c

2003-02-24 Thread Wez Furlong
PHP_4_3.

I made the original fixes there and then up-ported them to PHP5, which
wasn't suffering so much since the ze-stream patch.

--Wez.

On Mon, 24 Feb 2003, Rasmus Lerdorf wrote:

 On Mon, 24 Feb 2003, Wez Furlong wrote:
  wez Mon Feb 24 16:40:24 2003 EDT
 
Modified files:
  /php4/ext/standard  file.c
  /php4/main  php_streams.h
  /php4/main/streams  cast.c plain_wrapper.c streams.c
Log:
MFB: Bunch of streams related fixes.

 Sorry, which branch are you merging from?


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





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



[PHP-CVS] cvs: php4 /ext/standard file.c /main php_streams.h /main/streams plain_wrapper.c

2003-02-24 Thread Ilia Alshanetsky
iliaa   Mon Feb 24 20:39:07 2003 EDT

  Modified files:  
/php4/main  php_streams.h 
/php4/main/streams  plain_wrapper.c 
/php4/ext/standard  file.c 
  Log:
  Added locking to streams.
  Allow PHP to automatically release locks on files when terminating the 
  stream.
  Fixed bugs in the handling of the 3rd optional parameter to flock().
  
  
Index: php4/main/php_streams.h
diff -u php4/main/php_streams.h:1.72 php4/main/php_streams.h:1.73
--- php4/main/php_streams.h:1.72Mon Feb 24 16:40:23 2003
+++ php4/main/php_streams.h Mon Feb 24 20:39:06 2003
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: php_streams.h,v 1.72 2003/02/24 21:40:23 wez Exp $ */
+/* $Id: php_streams.h,v 1.73 2003/02/25 01:39:06 iliaa Exp $ */
 
 #ifndef PHP_STREAMS_H
 #define PHP_STREAMS_H
@@ -325,6 +325,15 @@
 /* set the timeout duration for reads on the stream. ptrparam is a pointer to a 
struct timeval * */
 #define PHP_STREAM_OPTION_READ_TIMEOUT 4
 #define PHP_STREAM_OPTION_SET_CHUNK_SIZE   5
+
+/* set or release lock on a stream */
+#define PHP_STREAM_OPTION_LOCKING  6
+
+/* whether or not locking is supported */
+#define PHP_STREAM_LOCK_SUPPORTED  1   
+
+#define php_stream_supports_lock(stream)   php_stream_set_option((stream), 
PHP_STREAM_OPTION_LOCKING, 0, (void *) PHP_STREAM_LOCK_SUPPORTED TSRMLS_CC) == 0 ? 1 : 0
+#define php_stream_lock(stream, mode)  php_stream_set_option((stream), 
PHP_STREAM_OPTION_LOCKING, (mode), (void *) NULL TSRMLS_CC)
 
 #define PHP_STREAM_OPTION_RETURN_OK 0 /* option set OK */
 #define PHP_STREAM_OPTION_RETURN_ERR   -1 /* problem setting option */
Index: php4/main/streams/plain_wrapper.c
diff -u php4/main/streams/plain_wrapper.c:1.3 php4/main/streams/plain_wrapper.c:1.4
--- php4/main/streams/plain_wrapper.c:1.3   Mon Feb 24 16:40:23 2003
+++ php4/main/streams/plain_wrapper.c   Mon Feb 24 20:39:06 2003
@@ -16,13 +16,14 @@
+--+
  */
 
-/* $Id: plain_wrapper.c,v 1.3 2003/02/24 21:40:23 wez Exp $ */
+/* $Id: plain_wrapper.c,v 1.4 2003/02/25 01:39:06 iliaa Exp $ */
 
 #include php.h
 #include php_globals.h
 #include php_network.h
 #include php_open_temporary_file.h
 #include ext/standard/file.h
+#include ext/standard/flock_compat.h
 #include stddef.h
 #include fcntl.h
 #if HAVE_SYS_WAIT_H
@@ -131,6 +132,7 @@
int fd; /* underlying file descriptor */
int is_process_pipe;/* use pclose instead of fclose */
int is_pipe;/* don't try and seek */
+   int lock_flag;  /* stores the lock state */
char *temp_file_name;   /* if non-null, this is the path to a temporary file 
that
 * is to be deleted when the 
stream is closed */
 #if HAVE_FLUSHIO
@@ -167,6 +169,8 @@
php_stdio_stream_data *self = 
(php_stdio_stream_data*)stream-abstract;
 
self-temp_file_name = opened_path;
+   self-lock_flag = LOCK_UN;
+   
return stream;
}
fclose(fp);
@@ -186,6 +190,7 @@
self = emalloc_rel_orig(sizeof(*self));
self-file = NULL;
self-is_pipe = 0;
+   self-lock_flag = LOCK_UN;
self-is_process_pipe = 0;
self-temp_file_name = NULL;
self-fd = fd;
@@ -228,6 +233,7 @@
self = emalloc_rel_orig(sizeof(*self));
self-file = file;
self-is_pipe = 0;
+   self-lock_flag = LOCK_UN;
self-is_process_pipe = 0;
self-temp_file_name = NULL;
self-fd = fileno(file);
@@ -270,6 +276,7 @@
self = emalloc_rel_orig(sizeof(*self));
self-file = file;
self-is_pipe = 1;
+   self-lock_flag = LOCK_UN;
self-is_process_pipe = 1;
self-fd = fileno(file);
self-temp_file_name = NULL;
@@ -340,6 +347,9 @@
assert(data != NULL);

if (close_handle) {
+   if (data-lock_flag != LOCK_UN) {
+   php_stream_lock(stream, LOCK_UN);
+   }
if (data-file) {
if (data-is_process_pipe) {
errno = 0;
@@ -541,6 +551,24 @@
return -1;
}
break;
+   
+   case PHP_STREAM_OPTION_LOCKING:
+   if (fd == -1) {
+   return -1;
+   }
+
+   if ((int) ptrparam == PHP_STREAM_LOCK_SUPPORTED) {
+   return 0;
+   }
+
+   if (!php_flock(fd, value) || (errno == EWOULDBLOCK  value  
LOCK_NB)) {
+   

[PHP-CVS] cvs: php4 /ext/standard file.c /ext/standard/tests/file bug22382.phpt test2.csv

2003-02-23 Thread Ilia Alshanetsky
iliaa   Sun Feb 23 22:13:25 2003 EDT

  Added files: 
/php4/ext/standard/tests/file   bug22382.phpt test2.csv 

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  Fixed bug #22382 (fgetcsv did not handle \ correctly).
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.309 php4/ext/standard/file.c:1.310
--- php4/ext/standard/file.c:1.309  Sat Feb 22 15:35:22 2003
+++ php4/ext/standard/file.cSun Feb 23 22:13:25 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.309 2003/02/22 20:35:22 iliaa Exp $ */
+/* $Id: file.c,v 1.310 2003/02/24 03:13:25 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -2558,6 +2558,21 @@
 
/* 2A. handle enclosure delimited field */
while (*bptr) {
+   /* we need to determine if the enclosure is 'real' or 
is it escaped */
+   if (*(bptr - 1) == '\\') {
+   int escape_cnt = 0;
+   char *bptr_p = bptr - 2;
+   
+   while (bptr_p  buf  *bptr_p == '\\') {
+   escape_cnt++;
+   bptr_p--;
+   }
+   if (!(escape_cnt % 2)) {
+   goto normal_char;
+   continue;
+   }
+   }
+   
if (*bptr == enclosure) {
/* handle the enclosure */
if ( *(bptr+1) == enclosure) {
@@ -2571,6 +2586,7 @@
break;  /* .. from handling this field 
- resumes at 3. */
}
} else {
+normal_char:
/* normal character */
*tptr++ = *bptr++;
 

Index: php4/ext/standard/tests/file/bug22382.phpt
+++ php4/ext/standard/tests/file/bug22382.phpt
--TEST--
Bug #22382: fgetcvs does not handle escaped quotes correctly
--POST--
--GET--
--FILE--
?php
$fp = fopen(dirname(__FILE__)./test2.csv, r);
while(($line = fgetcsv($fp, 1024))) {
var_dump($line);
}
fclose($fp);
?
--EXPECT--
array(6) {
  [0]=
  string(3) One
  [1]=
  string(7) \Two\
  [2]=
  string(7) Three\
  [3]=
  string(4) Four
  [4]=
  string(2) \\
  [5]=
  string(28) \\\
}
Index: php4/ext/standard/tests/file/test2.csv
+++ php4/ext/standard/tests/file/test2.csv
One,\Two\,Three\,Four,\\,\\\



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



[PHP-CVS] cvs: php4 /ext/standard file.c filters.c user_filters.c /main php_streams.h /main/streams cast.c context.h filter.c filter_api.h php_stream_context.h php_stream_filter_api.h php_stream_plain_wrapper.h php_stream_userspace.h plain_wrapper.h streams.c userspace.h

2003-02-17 Thread Wez Furlong
wez Mon Feb 17 20:22:22 2003 EDT

  Added files: 
/php4/main/streams  php_stream_context.h php_stream_filter_api.h 
php_stream_plain_wrapper.h 
php_stream_userspace.h 

  Removed files:   
/php4/main/streams  context.h filter_api.h plain_wrapper.h 
userspace.h 

  Modified files:  
/php4/ext/standard  file.c filters.c user_filters.c 
/php4/main  php_streams.h 
/php4/main/streams  cast.c filter.c streams.c 
  Log:
  Implement new filter API, stage 1.
  This breaks user-space filters (for the time being), and those
  weird convert.* filters in ext/standard/filters.c
  
  The filters stack has been separated into one chain for read and one chain
  for write.
  
  The user-space stream_filter_append() type functions currently only operate
  on the read chain. They need extending to work with the write chain too.
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.304 php4/ext/standard/file.c:1.305
--- php4/ext/standard/file.c:1.304  Mon Feb 17 08:29:57 2003
+++ php4/ext/standard/file.cMon Feb 17 20:22:21 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.304 2003/02/17 13:29:57 zeev Exp $ */
+/* $Id: file.c,v 1.305 2003/02/18 01:22:21 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -627,6 +627,7 @@
}
add_assoc_string(return_value, stream_type, (char *)stream-ops-label, 1);
 
+#if 0  /* TODO: needs updating for new filter API */
if (stream-filterhead) {
php_stream_filter *filter;

@@ -639,6 +640,7 @@
 
add_assoc_zval(return_value, filters, newval);
}
+#endif

add_assoc_long(return_value, unread_bytes, stream-writepos - 
stream-readpos);

@@ -1266,9 +1268,9 @@
}
 
if (append) { 
-   php_stream_filter_append(stream, filter);
+   php_stream_filter_append(stream-readfilters, filter);
} else {
-   php_stream_filter_prepend(stream, filter);
+   php_stream_filter_prepend(stream-readfilters, filter);
}
 
RETURN_TRUE;
Index: php4/ext/standard/filters.c
diff -u php4/ext/standard/filters.c:1.23 php4/ext/standard/filters.c:1.24
--- php4/ext/standard/filters.c:1.23Sat Jan 18 19:45:49 2003
+++ php4/ext/standard/filters.c Mon Feb 17 20:22:21 2003
@@ -17,7 +17,7 @@
+--+
 */
 
-/* $Id: filters.c,v 1.23 2003/01/19 00:45:49 iliaa Exp $ */
+/* $Id: filters.c,v 1.24 2003/02/18 01:22:21 wez Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -25,61 +25,40 @@
 #include ext/standard/file.h
 #include ext/standard/php_string.h
 
-/* {{{ common no-opperation methods */
-static int commonfilter_nop_flush(php_stream *stream, php_stream_filter *thisfilter, 
int closing TSRMLS_DC)
-{
-   return php_stream_filter_flush_next(stream, thisfilter, closing);
-}
-
-static int commonfilter_nop_eof(php_stream *stream, php_stream_filter *thisfilter 
TSRMLS_DC)
-{
-   return php_stream_filter_eof_next(stream, thisfilter);
-}
-/* }}} */
-
 /* {{{ 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);
+static php_stream_filter_status_t strfilter_rot13_filter(
+   php_stream *stream,
+   php_stream_filter *thisfilter,
+   php_stream_bucket_brigade *buckets_in,
+   php_stream_bucket_brigade *buckets_out,
+   size_t *bytes_consumed,
+   int flags
+   TSRMLS_DC)
+{
+   php_stream_bucket *bucket;
+   size_t consumed = 0;
+
+   while (buckets_in-head) {
+   bucket = php_stream_bucket_make_writeable(buckets_in-head TSRMLS_CC);
+   
+   php_strtr(bucket-buf, bucket-buflen, rot13_from, rot13_to, 52);
+   consumed += bucket-buflen;
+   
+   php_stream_bucket_append(buckets_out, bucket TSRMLS_CC);
}
 
-   return wrote;
-}
-
-static size_t strfilter_rot13_read(php_stream *stream, 

[PHP-CVS] cvs: php4 /ext/standard file.c /main/streams php_stream_filter_api.h

2003-02-17 Thread Sara Golemon
pollita Mon Feb 17 21:53:24 2003 EDT

  Modified files:  
/php4/main/streams  php_stream_filter_api.h 
/php4/ext/standard  file.c 
  Log:
  Fix stream_filter_(ap|pre)pend to allow attaching on the read and/or write chains.  
Automagically decide what to do if noone tells us.
  
  
Index: php4/main/streams/php_stream_filter_api.h
diff -u php4/main/streams/php_stream_filter_api.h:1.1 
php4/main/streams/php_stream_filter_api.h:1.2
--- php4/main/streams/php_stream_filter_api.h:1.1   Mon Feb 17 20:22:21 2003
+++ php4/main/streams/php_stream_filter_api.h   Mon Feb 17 21:53:23 2003
@@ -19,7 +19,7 @@
+--+
  */
 
-/* $Id: php_stream_filter_api.h,v 1.1 2003/02/18 01:22:21 wez Exp $ */
+/* $Id: php_stream_filter_api.h,v 1.2 2003/02/18 02:53:23 pollita Exp $ */
 
 /* The filter API works on the principle of Bucket-Brigades.  This is
  * partially inspired by the Apache 2 method of doing things, although
@@ -33,6 +33,10 @@
  * The first filter in the chain is invoked on the brigade and (depending on
  * it's return value), the next filter is invoked and so on.
  * */
+
+#define PHP_STREAM_FILTER_READ 0x0001
+#define PHP_STREAM_FILTER_WRITE0x0002
+#define PHP_STREAM_FILTER_ALL  (PHP_STREAM_FILTER_READ | PHP_STREAM_FILTER_WRITE)
 
 typedef struct _php_stream_bucket  php_stream_bucket;
 typedef struct _php_stream_bucket_brigade  php_stream_bucket_brigade;
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.305 php4/ext/standard/file.c:1.306
--- php4/ext/standard/file.c:1.305  Mon Feb 17 20:22:21 2003
+++ php4/ext/standard/file.cMon Feb 17 21:53:24 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.305 2003/02/18 01:22:21 wez Exp $ */
+/* $Id: file.c,v 1.306 2003/02/18 02:53:24 pollita Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -179,6 +179,10 @@
REGISTER_LONG_CONSTANT(STREAM_NOTIFY_SEVERITY_WARN,   
PHP_STREAM_NOTIFY_SEVERITY_WARN, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(STREAM_NOTIFY_SEVERITY_ERR,
PHP_STREAM_NOTIFY_SEVERITY_ERR,  CONST_CS | CONST_PERSISTENT);
 
+   REGISTER_LONG_CONSTANT(STREAM_FILTER_READ,
+PHP_STREAM_FILTER_READ, CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT(STREAM_FILTER_WRITE,   
+PHP_STREAM_FILTER_WRITE,CONST_CS | CONST_PERSISTENT);
+   REGISTER_LONG_CONSTANT(STREAM_FILTER_ALL, 
+PHP_STREAM_FILTER_ALL,  CONST_CS | CONST_PERSISTENT);
+
REGISTER_LONG_CONSTANT(FILE_USE_INCLUDE_PATH, PHP_FILE_USE_INCLUDE_PATH, 
CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(FILE_IGNORE_NEW_LINES, PHP_FILE_IGNORE_NEW_LINES, 
CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT(FILE_SKIP_EMPTY_LINES, PHP_FILE_SKIP_EMPTY_LINES, 
CONST_CS | CONST_PERSISTENT);
@@ -1252,31 +1256,60 @@
zval *zstream;
php_stream *stream;
char *filtername, *filterparams = NULL;
-   int filternamelen, filterparamslen = 0;
+   int filternamelen, filterparamslen = 0, read_write = 0;
php_stream_filter *filter;
 
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, rs|s, zstream,
-   filtername, filternamelen, filterparams, 
filterparamslen) == FAILURE) {
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, rs|ls, zstream,
+   filtername, filternamelen, read_write, 
+filterparams, filterparamslen) == FAILURE) {
RETURN_FALSE;
}
 
php_stream_from_zval(stream, zstream);
-   
-   filter = php_stream_filter_create(filtername, filterparams, filterparamslen, 
php_stream_is_persistent(stream) TSRMLS_CC);
-   if (filter == NULL) {
-   RETURN_FALSE;
+
+   if ((read_write  PHP_STREAM_FILTER_ALL) == 0) {
+   /* Chain not specified.
+* Examine stream-mode to determine which filters are needed
+* There's no harm in attaching a filter to an unused chain,
+* but why waste the memory and clock cycles? 
+*/
+   if (strchr(stream-mode, 'r') || strchr(stream-mode, '+')) {
+   read_write |= PHP_STREAM_FILTER_READ;
+   }
+   if (strchr(stream-mode, 'w') || strchr(stream-mode, '+') || 
+strchr(stream-mode, 'a')) {
+   read_write |= PHP_STREAM_FILTER_WRITE;
+   }
}
 
-   if (append) { 
-   php_stream_filter_append(stream-readfilters, filter);
-   } else {
-   php_stream_filter_prepend(stream-readfilters, filter);
+   if (read_write  PHP_STREAM_FILTER_READ) {
+   filter = php_stream_filter_create(filtername, 

[PHP-CVS] cvs: php4 /ext/standard file.c

2003-02-09 Thread Ilia Alshanetsky
iliaa   Sun Feb  9 15:05:14 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  Added feature request #14097 (option allowing file() command not to include
  line endings in it's output. As well as another option, which allows blank 
  lines to be excluded from the output).
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.296 php4/ext/standard/file.c:1.297
--- php4/ext/standard/file.c:1.296  Tue Jan 21 09:53:17 2003
+++ php4/ext/standard/file.cSun Feb  9 15:05:13 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.296 2003/01/21 14:53:17 iliaa Exp $ */
+/* $Id: file.c,v 1.297 2003/02/09 20:05:13 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -458,11 +458,13 @@
int target_len, len;
char eol_marker = '\n';
zend_bool use_include_path = 0;
+   zend_bool include_new_line = 1;
+   zend_bool skip_blank_lines = 0;
php_stream *stream;
 
/* Parse arguments */
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|b,
- filename, filename_len, 
use_include_path) == FAILURE) {
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|bbb,
+   filename, filename_len, use_include_path, 
+include_new_line, skip_blank_lines) == FAILURE) {
return;
}
 
@@ -488,19 +490,39 @@
if (stream-flags  PHP_STREAM_FLAG_EOL_MAC) {
eol_marker = '\r';
}   
-   
-   do {
-   p++;
-   parse_eol:
-   if (PG(magic_quotes_runtime)) {
-   /* s is in target_buf which is freed at the end of the 
function */
-   slashed = php_addslashes(s, (p-s), len, 0 TSRMLS_CC);
-   add_index_stringl(return_value, i++, slashed, len, 0);
-   } else {
-   add_index_stringl(return_value, i++, estrndup(s, p-s), 
p-s, 0);
-   }
-   s = p;
-   } while ((p = memchr(p, eol_marker, (e-p;
+
+   /* for performance reasons the code is duplicated, so that the if 
+(include_new_line) 
+* will not need to be done for every single line in the file.
+*/
+   if (include_new_line) { 
+   do {
+   p++;
+   parse_eol:
+   if (PG(magic_quotes_runtime)) {
+   /* s is in target_buf which is freed at the 
+end of the function */
+   slashed = php_addslashes(s, (p-s), len, 0 
+TSRMLS_CC);
+   add_index_stringl(return_value, i++, slashed, 
+len, 0);
+   } else {
+   add_index_stringl(return_value, i++, 
+estrndup(s, p-s), p-s, 0);
+   }
+   s = p;
+   } while ((p = memchr(p, eol_marker, (e-p;
+   } else {
+   do {
+   if (skip_blank_lines  !(p-s)) {
+   s = ++p;
+   continue;
+   }
+   if (PG(magic_quotes_runtime)) {
+   /* s is in target_buf which is freed at the 
+end of the function */
+   slashed = php_addslashes(s, (p-s), len, 0 
+TSRMLS_CC);
+   add_index_stringl(return_value, i++, slashed, 
+len, 0);
+   } else {
+   add_index_stringl(return_value, i++, 
+estrndup(s, p-s), p-s, 0);
+   }
+   s = ++p;
+   } while ((p = memchr(p, eol_marker, (e-p;
+   }

/* handle any left overs of files without new lines */
if (s != e) {



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




[PHP-CVS] cvs: php4 /ext/standard file.c

2003-02-09 Thread Ilia Alshanetsky
iliaa   Sun Feb  9 15:35:54 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  Added feature request #17983 (optional parameter to mkdir() that makes
  directory creation recursive).
  Fixed prototype for file() function.
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.297 php4/ext/standard/file.c:1.298
--- php4/ext/standard/file.c:1.297  Sun Feb  9 15:05:13 2003
+++ php4/ext/standard/file.cSun Feb  9 15:35:54 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.297 2003/02/09 20:05:13 iliaa Exp $ */
+/* $Id: file.c,v 1.298 2003/02/09 20:35:54 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -444,7 +444,7 @@
 }
 /* }}} */
 
-/* {{{ proto array file(string filename [, bool use_include_path])
+/* {{{ proto array file(string filename [, bool use_include_path [, bool 
+include_new_line [, bool skip_blank_lines]]])
Read entire file into an array */
 
 #define PHP_FILE_BUF_SIZE  80
@@ -1733,32 +1733,86 @@
 }
 
 /* }}} */
-/* {{{ proto bool mkdir(string pathname[, int mode])
+
+/* {{{ proto int mkdir(char *dir int mode)
+*/
+
+PHPAPI int php_mkdir(char *dir, long mode TSRMLS_DC)
+{
+   int ret;
+   
+   if (PG(safe_mode)  (!php_checkuid(dir, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
+   return -1;
+   }
+
+   if (php_check_open_basedir(dir TSRMLS_CC)) {
+   return -1;
+   }
+
+   if ((ret = VCWD_MKDIR(dir, (mode_t)mode))  0) {
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, strerror(errno));
+   }
+
+   return ret; 
+}
+/* }}} */
+
+/* {{{ proto bool mkdir(string pathname [, int mode [, bool recursive])
Create a directory */
 PHP_FUNCTION(mkdir)
 {
int dir_len, ret;
long mode = 0777;
char *dir;
+   zend_bool recursive = 0;
 
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|l, dir, dir_len, 
mode) == FAILURE) {
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|lb, dir, dir_len, 
+mode, recursive) == FAILURE) {
return;
}
 
-   if (PG(safe_mode)  (!php_checkuid(dir, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
-   RETURN_FALSE;
-   }
-
-   if (php_check_open_basedir(dir TSRMLS_CC)) {
-   RETURN_FALSE;
+   if (!recursive) {
+   ret = php_mkdir(dir, mode);
+   } else {
+   /* we look for directory separator from the end of string, thus 
+hopefuly reducing our work load */
+   char *p, *e, *buf;
+   struct stat sb;
+   
+   buf = estrndup(dir, dir_len);
+   e = buf + dir_len;
+   
+   /* find a top level directory we need to create */
+   while ((p = strrchr(buf, DEFAULT_SLASH))) {
+   *p = '\0';
+   if (VCWD_STAT(buf, sb) == 0) {
+   *p = DEFAULT_SLASH;
+   break;
+   }
+   }
+   if (p == buf) {
+   ret = php_mkdir(dir, mode);
+   } else if (!(ret = php_mkdir(buf, mode))) {
+   if (!p) {
+   p = buf;
+   }
+   /* create any needed directories if the creation of the 1st 
+directory worked */
+   while (++p != e) {
+   if (*p == '\0'  *(p + 1) != '\0') {
+   *p = DEFAULT_SLASH;
+   if ((ret = VCWD_MKDIR(buf, (mode_t)mode))  0) 
+{
+   php_error_docref(NULL TSRMLS_CC, 
+E_WARNING, strerror(errno));
+   break;
+   }
+   }
+   }
+   }
+   efree(buf);
}
 
-   ret = VCWD_MKDIR(dir, (mode_t)mode);
if (ret  0) {
-   php_error_docref1(NULL TSRMLS_CC, dir, E_WARNING, %s, 
strerror(errno));
RETURN_FALSE;
+   } else {
+   RETURN_TRUE;
}
-   RETURN_TRUE;
 }
 /* }}} */
 



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




[PHP-CVS] cvs: php4 /ext/standard file.c

2003-02-09 Thread Wez Furlong
wez Sun Feb  9 18:11:23 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  ZTS fix
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.299 php4/ext/standard/file.c:1.300
--- php4/ext/standard/file.c:1.299  Sun Feb  9 15:43:05 2003
+++ php4/ext/standard/file.cSun Feb  9 18:11:23 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.299 2003/02/09 20:43:05 iliaa Exp $ */
+/* $Id: file.c,v 1.300 2003/02/09 23:11:23 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -1802,7 +1802,7 @@
}
 
if (!recursive) {
-   ret = php_mkdir(dir, mode);
+   ret = php_mkdir(dir, mode TSRMLS_CC);
} else {
/* we look for directory separator from the end of string, thus 
hopefuly reducing our work load */
char *p, *e, *buf;
@@ -1820,8 +1820,8 @@
}
}
if (p == buf) {
-   ret = php_mkdir(dir, mode);
-   } else if (!(ret = php_mkdir(buf, mode))) {
+   ret = php_mkdir(dir, mode TSRMLS_CC);
+   } else if (!(ret = php_mkdir(buf, mode TSRMLS_CC))) {
if (!p) {
p = buf;
}



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




Re: [PHP-CVS] cvs: php4 /ext/standard file.c

2003-01-20 Thread Jani Taskinen
 
MFH?

On Sat, 18 Jan 2003, Derick Rethans wrote:

derick Sat Jan 18 08:55:58 2003 EDT

  Modified files:  
/php4/ext/standard file.c 
  Log:
  - Fixed memleak in fscanf().
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.292 php4/ext/standard/file.c:1.293
--- php4/ext/standard/file.c:1.292 Sat Jan 11 18:05:19 2003
+++ php4/ext/standard/file.c   Sat Jan 18 08:55:58 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.292 2003/01/11 23:05:19 moriyoshi Exp $ */
+/* $Id: file.c,v 1.293 2003/01/18 13:55:58 derick Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -1518,6 +1518,7 @@
 
   buf = php_stream_get_line((php_stream *) what, NULL, 0, len);
   if (buf == NULL) {
+  efree(args);
   RETURN_FALSE;
   }
 





-- 
- For Sale! -


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




Re: [PHP-CVS] cvs: php4 /ext/standard file.c

2003-01-20 Thread Jani Taskinen

MFH?


On Sat, 18 Jan 2003, Wez Furlong wrote:

wezSat Jan 18 09:10:22 2003 EDT

  Modified files:  
/php4/ext/standard file.c 
  Log:
  Fix potential problem for 64-bit architectures.
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.293 php4/ext/standard/file.c:1.294
--- php4/ext/standard/file.c:1.293 Sat Jan 18 08:55:58 2003
+++ php4/ext/standard/file.c   Sat Jan 18 09:10:22 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.293 2003/01/18 13:55:58 derick Exp $ */
+/* $Id: file.c,v 1.294 2003/01/18 14:10:22 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -1482,7 +1482,8 @@
 {
   int  result;
   zval **file_handle, **format_string;
-  int len, type;
+  size_t len;
+  int type;
   char *buf;
   void *what;
 





-- 
- For Sale! -


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




[PHP-CVS] cvs: php4 /ext/standard file.c

2003-01-18 Thread Derick Rethans
derick  Sat Jan 18 08:55:58 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  - Fixed memleak in fscanf().
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.292 php4/ext/standard/file.c:1.293
--- php4/ext/standard/file.c:1.292  Sat Jan 11 18:05:19 2003
+++ php4/ext/standard/file.cSat Jan 18 08:55:58 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.292 2003/01/11 23:05:19 moriyoshi Exp $ */
+/* $Id: file.c,v 1.293 2003/01/18 13:55:58 derick Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -1518,6 +1518,7 @@
 
buf = php_stream_get_line((php_stream *) what, NULL, 0, len);
if (buf == NULL) {
+   efree(args);
RETURN_FALSE;
}
 



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




[PHP-CVS] cvs: php4 /ext/standard file.c

2003-01-18 Thread Wez Furlong
wez Sat Jan 18 09:10:22 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  Fix potential problem for 64-bit architectures.
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.293 php4/ext/standard/file.c:1.294
--- php4/ext/standard/file.c:1.293  Sat Jan 18 08:55:58 2003
+++ php4/ext/standard/file.cSat Jan 18 09:10:22 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.293 2003/01/18 13:55:58 derick Exp $ */
+/* $Id: file.c,v 1.294 2003/01/18 14:10:22 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -1482,7 +1482,8 @@
 {
int  result;
zval **file_handle, **format_string;
-   int len, type;
+   size_t len;
+   int type;
char *buf;
void *what;
 



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




[PHP-CVS] cvs: php4 /ext/standard file.c

2003-01-09 Thread Ilia Alshanetsky
iliaa   Thu Jan  9 17:49:19 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  Fixed a memory corruption that occurs when an unterminated  is encountered
  this bug maybe be related to #21556.
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.288 php4/ext/standard/file.c:1.289
--- php4/ext/standard/file.c:1.288  Sun Jan  5 17:24:49 2003
+++ php4/ext/standard/file.cThu Jan  9 17:49:18 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.288 2003/01/05 22:24:49 pollita Exp $ */
+/* $Id: file.c,v 1.289 2003/01/09 22:49:18 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -2276,7 +2276,7 @@
efree(lineEnd); 
efree(temp); 
efree(buf);
-   zval_ptr_dtor(return_value);
+   zval_dtor(return_value);
RETURN_FALSE;
}
 



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




[PHP-CVS] cvs: php4 /ext/standard file.c

2003-01-09 Thread Ilia Alshanetsky
iliaa   Thu Jan  9 18:23:32 2003 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  CS fixes
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.289 php4/ext/standard/file.c:1.290
--- php4/ext/standard/file.c:1.289  Thu Jan  9 17:49:18 2003
+++ php4/ext/standard/file.cThu Jan  9 18:23:32 2003
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.289 2003/01/09 22:49:18 iliaa Exp $ */
+/* $Id: file.c,v 1.290 2003/01/09 23:23:32 iliaa Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -639,13 +639,15 @@
WRONG_PARAM_COUNT;
}
 
-   if (url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash()) {
+   if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) {
array_init(return_value);
for(zend_hash_internal_pointer_reset(url_stream_wrappers_hash);
(key_flags = 
zend_hash_get_current_key_ex(url_stream_wrappers_hash, stream_protocol, 
stream_protocol_len, NULL, 0, NULL)) != HASH_KEY_NON_EXISTANT;
-   zend_hash_move_forward(url_stream_wrappers_hash)) 
-   if (key_flags == HASH_KEY_IS_STRING)
+   zend_hash_move_forward(url_stream_wrappers_hash)) {
+   if (key_flags == HASH_KEY_IS_STRING) {
add_next_index_stringl(return_value, 
stream_protocol, stream_protocol_len, 1);
+   }
+   }
} else {
RETURN_FALSE;
}
@@ -660,17 +662,17 @@
php_stream *stream;
int this_fd;
 
-   if (Z_TYPE_P(stream_array) != IS_ARRAY)
+   if (Z_TYPE_P(stream_array) != IS_ARRAY) {
return 0;
-
+   }
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(stream_array));
 zend_hash_get_current_data(Z_ARRVAL_P(stream_array), (void **) elem) 
== SUCCESS;
 zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
 
php_stream_from_zval_no_verify(stream, elem);
-   if (stream == NULL)
+   if (stream == NULL) {
continue;
-
+   }
/* get the fd.
 * NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag
 * when casting.  It is only used here so that the buffered data 
warning
@@ -693,9 +695,9 @@
HashTable *new_hash;
int this_fd, ret = 0;
 
-   if (Z_TYPE_P(stream_array) != IS_ARRAY)
+   if (Z_TYPE_P(stream_array) != IS_ARRAY) {
return 0;
-
+   }
ALLOC_HASHTABLE(new_hash);
zend_hash_init(new_hash, 0, NULL, ZVAL_PTR_DTOR, 0);

@@ -704,9 +706,9 @@
 zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
 
php_stream_from_zval_no_verify(stream, elem);
-   if (stream == NULL)
+   if (stream == NULL) {
continue;
-
+   }
/* get the fd 
 * NB: Most other code will NOT use the PHP_STREAM_CAST_INTERNAL flag
 * when casting.  It is only used here so that the buffered data 
warning
@@ -715,8 +717,9 @@
if (SUCCESS == php_stream_cast(stream, PHP_STREAM_AS_FD | 
PHP_STREAM_CAST_INTERNAL, (void*)this_fd, 1)) {
if (FD_ISSET(this_fd, fds)) {
zend_hash_next_index_insert(new_hash, (void *)elem, 
sizeof(zval *), (void **)dest_elem);
-   if (dest_elem)
+   if (dest_elem) {
zval_add_ref(dest_elem);
+   }
ret++;
continue;
}
@@ -740,9 +743,9 @@
HashTable *new_hash;
int ret = 0;
 
-   if (Z_TYPE_P(stream_array) != IS_ARRAY)
+   if (Z_TYPE_P(stream_array) != IS_ARRAY) {
return 0;
-
+   }
ALLOC_HASHTABLE(new_hash);
zend_hash_init(new_hash, 0, NULL, ZVAL_PTR_DTOR, 0);

@@ -751,9 +754,9 @@
 zend_hash_move_forward(Z_ARRVAL_P(stream_array))) {
 
php_stream_from_zval_no_verify(stream, elem);
-   if (stream == NULL)
+   if (stream == NULL) {
continue;
-
+   }
if ((stream-writepos - stream-readpos)  0) {
/* allow readable non-descriptor based streams to participate 
in stream_select.
 * Non-descriptor streams will only work if they have 
previously buffered the
@@ -762,8 +765,9 @@
 * operate correctly in stream_select.
 * */

[PHP-CVS] cvs: php4 /ext/standard file.c

2002-12-26 Thread Wez Furlong
wez Thu Dec 26 17:35:01 2002 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  Remove cruft that opened a stream that was never closed in get_meta_tags().
  (probably my fault).
  Noticed by Philip Olson
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.282 php4/ext/standard/file.c:1.283
--- php4/ext/standard/file.c:1.282  Thu Dec  5 15:01:18 2002
+++ php4/ext/standard/file.cThu Dec 26 17:35:00 2002
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.282 2002/12/05 20:01:18 iliaa Exp $ */
+/* $Id: file.c,v 1.283 2002/12/26 22:35:00 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -273,14 +273,9 @@
return;
}
 
-   php_stream_open_wrapper(filename, rb, 0, NULL);
-
-   
md.stream = php_stream_open_wrapper(filename, rb,
(use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | 
REPORT_ERRORS,
NULL);
-   
-
 
if (!md.stream) {
RETURN_FALSE;



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




[PHP-CVS] cvs: php4 /ext/standard file.c

2002-11-27 Thread Sterling Hughes
sterlingWed Nov 27 15:05:21 2002 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  don't use stupid constants, be smart, just read the line
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.279 php4/ext/standard/file.c:1.280
--- php4/ext/standard/file.c:1.279  Wed Nov  6 13:07:23 2002
+++ php4/ext/standard/file.cWed Nov 27 15:05:20 2002
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.279 2002/11/06 18:07:23 iliaa Exp $ */
+/* $Id: file.c,v 1.280 2002/11/27 20:05:20 sterling Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -1484,26 +1484,22 @@
RETURN_FALSE;
}
 
-   len = SCAN_MAX_FSCANF_BUFSIZE;
 
-   buf = emalloc(len + 1);
-   /* needed because recv doesnt put a null at the end*/
-   memset(buf, 0, len+1);
-
-   if (php_stream_gets((php_stream *) what, buf, len) == NULL) {
-   efree(buf);
+   buf = php_stream_get_line((php_stream *) what, NULL, 0, len);
+   if (buf == NULL) {
RETURN_FALSE;
}
 
convert_to_string_ex(format_string);
result = php_sscanf_internal(buf, Z_STRVAL_PP(format_string),
argCount, args, 2, return_value TSRMLS_CC);
+
efree(args);
efree(buf);
+
if (SCAN_ERROR_WRONG_PARAM_COUNT == result) {
-   WRONG_PARAM_COUNT
+   WRONG_PARAM_COUNT;
}
-
 
 }
 /* }}} */



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




Re: [PHP-CVS] cvs: php4 /ext/standard file.c

2002-11-27 Thread Derick Rethans
On Wed, 27 Nov 2002, Sterling Hughes wrote:

 sterling  Wed Nov 27 15:05:21 2002 EDT
 
   Modified files:  
 /php4/ext/standardfile.c 
   Log:
   don't use stupid constants, be smart, just read the line

MFH?

Derick
-- 

-
 Derick Rethans http://derickrethans.nl/ 
 PHP Magazine - PHP Magazine for Professionals   http://php-mag.net/
-


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




[PHP-CVS] cvs: php4 /ext/standard file.c

2002-10-29 Thread Marcus Börger
helly   Tue Oct 29 07:53:58 2002 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  fix overrun
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.276 php4/ext/standard/file.c:1.277
--- php4/ext/standard/file.c:1.276  Thu Oct 24 15:17:08 2002
+++ php4/ext/standard/file.cTue Oct 29 07:53:58 2002
 -21,7 +21,7 
+--+
  */
 
-/* $Id: file.c,v 1.276 2002/10/24 19:17:08 helly Exp $ */
+/* $Id: file.c,v 1.277 2002/10/29 12:53:58 helly Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
 -501,7 +501,8 
p++;
parse_eol:
if (PG(magic_quotes_runtime)) {
-   slashed = php_addslashes(s, (p-s), len, 1 TSRMLS_CC);
+   // s is in target_buf which is freed at the end of the 
+function
+   slashed = php_addslashes(s, (p-s), len, 0 TSRMLS_CC);
add_index_stringl(return_value, i++, slashed, len, 0);
} else {
add_index_stringl(return_value, i++, estrndup(s, p-s), 
p-s, 0);



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




Re: [PHP-CVS] Re: [PHP-QA] Re: [PHP-CVS] cvs: php4 /ext/standard file.c /ext/standard/tests/strings strtoupper.phpt

2002-10-25 Thread Melvyn Sopacua
At 01:30 25-10-2002, Ilia A. wrote:


Could you please try the attached patch and let me know if it fixes the
problem.


Confirmed.



Met vriendelijke groeten / With kind regards,

Webmaster IDG.nl
Melvyn Sopacua


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




[PHP-CVS] cvs: php4 /ext/standard file.c /main php_streams.h streams.c

2002-10-19 Thread Wez Furlong
wez Sat Oct 19 09:11:48 2002 EDT

  Modified files:  
/php4/main  streams.c php_streams.h 
/php4/ext/standard  file.c 
  Log:
  made fgets() binary safe.
  php_stream_gets is now a macro which calls php_stream_get_line. The latter
  has an option argument to return the number of bytes in the line.
  Functions like fgetcsv(), fgetss() can be made binary safe by calling
  php_stream_get_line directly.
  
  # HEADS UP: You will need to make clean after updating your CVS, as the
  # binary signature has changed.
  
  
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.111 php4/main/streams.c:1.112
--- php4/main/streams.c:1.111   Sat Oct 19 06:34:10 2002
+++ php4/main/streams.c Sat Oct 19 09:11:48 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.111 2002/10/19 10:34:10 wez Exp $ */
+/* $Id: streams.c,v 1.112 2002/10/19 13:11:48 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -668,7 +668,8 
 /* If buf == NULL, the buffer will be allocated automatically and will be of an
  * appropriate length to hold the line, regardless of the line length, memory
  * permitting */
-PHPAPI char *_php_stream_gets(php_stream *stream, char *buf, size_t maxlen TSRMLS_DC)
+PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen,
+   size_t *returned_len TSRMLS_DC)
 {
size_t avail = 0;
size_t current_buf_size = 0;
 -772,6 +773,8 
}

buf[0] = '\0';
+   if (returned_len)
+   *returned_len = total_copied;
 
return bufstart;
 }
Index: php4/main/php_streams.h
diff -u php4/main/php_streams.h:1.55 php4/main/php_streams.h:1.56
--- php4/main/php_streams.h:1.55Fri Oct 18 16:39:49 2002
+++ php4/main/php_streams.h Sat Oct 19 09:11:48 2002
 -359,8 +359,10 
 PHPAPI int _php_stream_flush(php_stream *stream, int closing TSRMLS_DC);
 #define php_stream_flush(stream)   _php_stream_flush((stream), 0 TSRMLS_CC)
 
-PHPAPI char *_php_stream_gets(php_stream *stream, char *buf, size_t maxlen TSRMLS_DC);
-#define php_stream_gets(stream, buf, maxlen)   _php_stream_gets((stream), (buf), 
(maxlen) TSRMLS_CC)
+PHPAPI char *_php_stream_get_line(php_stream *stream, char *buf, size_t maxlen, 
+size_t *returned_len TSRMLS_DC);
+#define php_stream_gets(stream, buf, maxlen)   _php_stream_get_line((stream), (buf), 
+(maxlen), NULL TSRMLS_CC)
+
+#define php_stream_get_line(stream, buf, maxlen, retlen) 
+_php_stream_get_line((stream), (buf), (maxlen), (retlen) TSRMLS_CC)
 
 /* CAREFUL! this is equivalent to puts NOT fputs! */
 PHPAPI int _php_stream_puts(php_stream *stream, char *buf TSRMLS_DC);
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.272 php4/ext/standard/file.c:1.273
--- php4/ext/standard/file.c:1.272  Fri Oct 18 16:39:49 2002
+++ php4/ext/standard/file.cSat Oct 19 09:11:48 2002
 -21,7 +21,7 
+--+
  */
 
-/* $Id: file.c,v 1.272 2002/10/18 20:39:49 iliaa Exp $ */
+/* $Id: file.c,v 1.273 2002/10/19 13:11:48 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
 -1239,6 +1239,7 
int len;
char *buf = NULL;
int argc = ZEND_NUM_ARGS();
+   size_t line_len = 0;
php_stream *stream;
 
if (argc1 || argc2 || zend_get_parameters_ex(argc, arg1, arg2) == FAILURE) 
{
 -1249,7 +1250,7 
 
if (argc == 1) {
/* ask streams to give us a buffer of an appropriate size */
-   buf = php_stream_gets(stream, NULL, 0);
+   buf = php_stream_get_line(stream, NULL, 0, line_len);
if (buf == NULL)
goto exit_failed;
} else if (argc  1) {
 -1262,19 +1263,19 
}
 
buf = ecalloc(len + 1, sizeof(char));
-   if (php_stream_gets(stream, buf, len) == NULL)
+   if (php_stream_get_line(stream, buf, len, line_len) == NULL)
goto exit_failed;
}

if (PG(magic_quotes_runtime)) {
-   Z_STRVAL_P(return_value) = php_addslashes(buf, 0, 
Z_STRLEN_P(return_value), 1 TSRMLS_CC);
+   Z_STRVAL_P(return_value) = php_addslashes(buf, line_len, 
+Z_STRLEN_P(return_value), 1 TSRMLS_CC);
Z_TYPE_P(return_value) = IS_STRING;
} else {
-   ZVAL_STRING(return_value, buf, 0);
+   ZVAL_STRINGL(return_value, buf, line_len, 0);
/* resize buffer if it's much larger than the result.
 * Only needed if the user requested a buffer size. */
if (argc  1  Z_STRLEN_P(return_value)  len / 2) {
-   Z_STRVAL_P(return_value) = erealloc(buf, 
Z_STRLEN_P(return_value) + 1);
+   Z_STRVAL_P(return_value) = erealloc(buf, line_len + 1);
}
}
return;



-- 
PHP CVS Mailing 

[PHP-CVS] cvs: php4 /ext/standard file.c

2002-10-18 Thread Wez Furlong
wez Fri Oct 18 12:55:48 2002 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  Improve file().
  Patch by Tal Peer [EMAIL PROTECTED]
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.270 php4/ext/standard/file.c:1.271
--- php4/ext/standard/file.c:1.270  Tue Oct 15 12:45:26 2002
+++ php4/ext/standard/file.cFri Oct 18 12:55:47 2002
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.270 2002/10/15 16:45:26 wez Exp $ */
+/* $Id: file.c,v 1.271 2002/10/18 16:55:47 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -463,7 +463,7 @@
int filename_len;
char *slashed, *target_buf;
register int i = 0;
-   int target_len, len;
+   int len;
char eol_marker = '\n';
zend_bool use_include_path = 0;
zend_bool reached_eof = 0;
@@ -486,47 +486,19 @@
array_init(return_value);
 
/* Now loop through the file and do the magic quotes thing if needed */
-   target_len = 0;
-   target_buf = NULL;
while (1) {
-   if (!target_buf) {
-   target_buf = (char *) emalloc(PHP_FILE_BUF_SIZE+1);
-   target_buf[PHP_FILE_BUF_SIZE] = 0; /* avoid overflows */
-   } else {
-   target_buf = (char *) erealloc(target_buf, 
target_len+PHP_FILE_BUF_SIZE+1);
-   target_buf[target_len+PHP_FILE_BUF_SIZE] = 0; /* avoid 
overflows */
-   }
-   if (php_stream_gets(stream, target_buf+target_len, 
PHP_FILE_BUF_SIZE)==NULL) {
-   if (target_len==0) {
-   efree(target_buf);
-   break;
-   } else {
-   reached_eof = 1;
-   }
+   target_buf = php_stream_gets(stream, NULL, 0);
+   if (target_buf == NULL) {
+   break;
}

-   /* mini-hack because I don't feel like re-writing this whole function 
*/
-   if (stream-flags  PHP_STREAM_FLAG_EOL_MAC)
-   eol_marker = '\r';
-   
-   if (!reached_eof) {
-   target_len += strlen(target_buf+target_len);
-   if (target_buf[target_len-1] != eol_marker) {
-   continue;
-   }
-   }
if (PG(magic_quotes_runtime)) {
-   slashed = php_addslashes(target_buf, target_len, len, 1 
TSRMLS_CC); /* 1 = free source string */
-   add_index_stringl(return_value, i++, slashed, len, 0);
+   /* 1 = free source string */
+   slashed = php_addslashes(target_buf, strlen(target_buf), len, 
+1 TSRMLS_CC);
+   add_next_index_stringl(return_value, slashed, len, 0);
} else {
-   target_buf = erealloc(target_buf, target_len+1); /* do we 
really want to do that? */
-   add_index_stringl(return_value, i++, target_buf, target_len, 
0);
-   }
-   if (reached_eof) {
-   break;
+   add_next_index_string(return_value, target_buf, 0);
}
-   target_buf = NULL;
-   target_len = 0;
}
php_stream_close(stream);
 }



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




Re: [PHP-CVS] cvs: php4 /ext/standard file.c /main php_streams.h streams.c

2002-10-18 Thread Ilia A.
On October 18, 2002 05:04 pm, Rasmus Lerdorf wrote:
  On October 18, 2002 04:40 pm, Rasmus Lerdorf wrote:
  Fixed bug #19971 (optimized the file() function).
  The file() function is now also binary safe.
  
   That's a bit misleading.  By definition file() cannot be binary-safe in
   that \n is treated specially.
 
  Not quite, in the old code (4.2.3) doing a file() would produce a wildly
  inaccurate count of lines. For example, a php executable was only 2200
  lines, while 'wc -l' and manual checks using C yielded a result of 9800
  lines. In my mind that meant that the old code was un-safe to use on
  binary files. The new code works properly and breaks down the file by
  lines accurately.
 
  Ilia
 
  P.S. Thanks to Wez  Sascha we also support MAC EOL in 4.3.0, so we don't
  look for \n specifically per say.

 My point is that the original data is munged once it goes through the
 file() function.  In that sense it is not binary safe as there is no
 way to restore the original data.

Unless the user actually goes and modifies the data, it is very easy to 
restore the original file back. The example script below will demonstrate 
that the output of file() can still be safely restored.

?php
echo md5_file(sapi/cli/php).\n;
echo md5(implode(, file(sapi/cli/php))).\n;
?

Both of the md5s are identical, meaning that the file() call itself did 
nothing that would corrupt the file preventing the the user from restoring 
file. IMHO that means that the function is binary safe.

Ilia

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




Re: [PHP-CVS] cvs: php4 /ext/standard file.c /main php_streams.h streams.c

2002-10-18 Thread Ilia A.
On October 18, 2002 04:40 pm, Rasmus Lerdorf wrote:
Fixed bug #19971 (optimized the file() function).
The file() function is now also binary safe.

 That's a bit misleading.  By definition file() cannot be binary-safe in
 that \n is treated specially.

Not quite, in the old code (4.2.3) doing a file() would produce a wildly 
inaccurate count of lines. For example, a php executable was only 2200 lines, 
while 'wc -l' and manual checks using C yielded a result of 9800 lines. In my 
mind that meant that the old code was un-safe to use on binary files.
The new code works properly and breaks down the file by lines accurately. 

Ilia

P.S. Thanks to Wez  Sascha we also support MAC EOL in 4.3.0, so we don't look 
for \n specifically per say. 


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




Re: [PHP-CVS] cvs: php4 /ext/standard file.c /main php_streams.hstreams.c

2002-10-18 Thread Rasmus Lerdorf
 On October 18, 2002 04:40 pm, Rasmus Lerdorf wrote:
 Fixed bug #19971 (optimized the file() function).
 The file() function is now also binary safe.
 
  That's a bit misleading.  By definition file() cannot be binary-safe in
  that \n is treated specially.

 Not quite, in the old code (4.2.3) doing a file() would produce a wildly
 inaccurate count of lines. For example, a php executable was only 2200 lines,
 while 'wc -l' and manual checks using C yielded a result of 9800 lines. In my
 mind that meant that the old code was un-safe to use on binary files.
 The new code works properly and breaks down the file by lines accurately.

 Ilia

 P.S. Thanks to Wez  Sascha we also support MAC EOL in 4.3.0, so we don't look
 for \n specifically per say.

My point is that the original data is munged once it goes through the
file() function.  In that sense it is not binary safe as there is no
way to restore the original data.  I agree that the new approach is more
consistent, I just want to make sure that this isn't misinterpreted in
some way as to someone documenting that this function is now binary-clean.

-Rasmus


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




Re: [PHP-CVS] cvs: php4 /ext/standard file.c /main php_streams.hstreams.c

2002-10-18 Thread Rasmus Lerdorf
  But EOL is not always \n and it can be a mix of \r\n \n or \r.  You have
  no way of knowing which eol caused the break for any particular line.  In
  that sense file() is irreversible.

 Why would I care about that, the EOL are not stripped by file(), so I do not
 need to know EOLs when assembling the file back. As long as I assemble the
 number of lines equal to the number of lines read, I will get the same file.

Ah, you are right.  You have fixed this now.  I just tested your code.  In
the past something like:

$a = file('abc');
$fp = fopen(abc.new,w);
foreach($a as $l) {
fwrite($fp, $l);
}
fclose($fp);

Would create an abc.new file that was different from abc.

-Rasmus


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




[PHP-CVS] cvs: php4 /ext/standard file.c /main streams.c

2002-10-15 Thread Wez Furlong

wez Tue Oct 15 12:45:27 2002 EDT

  Modified files:  
/php4/ext/standard  file.c 
/php4/main  streams.c 
  Log:
  Nope, that last one wasn't a leak in main/streams.c, it was
  file_get_contents misinterpreting the result...
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.269 php4/ext/standard/file.c:1.270
--- php4/ext/standard/file.c:1.269  Sun Oct 13 22:28:35 2002
+++ php4/ext/standard/file.cTue Oct 15 12:45:26 2002
 -21,7 +21,7 
+--+
  */
 
-/* $Id: file.c,v 1.269 2002/10/14 02:28:35 wez Exp $ */
+/* $Id: file.c,v 1.270 2002/10/15 16:45:26 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
 -435,7 +435,7 
}
 
/* uses mmap if possible */
-   if ((len = php_stream_copy_to_mem(stream, contents, PHP_STREAM_COPY_ALL, 0)) 
 0) {
+   if ((len = php_stream_copy_to_mem(stream, contents, PHP_STREAM_COPY_ALL, 0)) 
+= 0) {

if (PG(magic_quotes_runtime)) {
contents = php_addslashes(contents, len, newlen, 1 
TSRMLS_CC); /* 1 = free source string */
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.107 php4/main/streams.c:1.108
--- php4/main/streams.c:1.107   Tue Oct 15 12:38:11 2002
+++ php4/main/streams.c Tue Oct 15 12:45:26 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.107 2002/10/15 16:38:11 wez Exp $ */
+/* $Id: streams.c,v 1.108 2002/10/15 16:45:26 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -1028,7 +1028,7 
 #endif

srcfile = mmap(NULL, maxlen, PROT_READ, MAP_SHARED, srcfd, 0);
-   if (srcfile != (void*)MAP_FAILED  ret  0) {
+   if (srcfile != (void*)MAP_FAILED) {
 
*buf = pemalloc_rel_orig(maxlen + 1, persistent);
 



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




[PHP-CVS] cvs: php4 /ext/standard file.c /main streams.c

2002-10-13 Thread Wez Furlong

wez Sun Oct 13 22:28:36 2002 EDT

  Modified files:  
/php4/ext/standard  file.c 
/php4/main  streams.c 
  Log:
  - fgets($fp) (with no length parameter) now uses a buffer as long as the
the next line available from the $fp. Previously, there was a 1KB limit.
(Wez)
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.268 php4/ext/standard/file.c:1.269
--- php4/ext/standard/file.c:1.268  Sat Oct  5 06:59:35 2002
+++ php4/ext/standard/file.cSun Oct 13 22:28:35 2002
 -21,7 +21,7 
+--+
  */
 
-/* $Id: file.c,v 1.268 2002/10/05 10:59:35 wez Exp $ */
+/* $Id: file.c,v 1.269 2002/10/14 02:28:35 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
 -1247,8 +1247,8 
 PHPAPI PHP_FUNCTION(fgets)
 {
zval **arg1, **arg2;
-   int len = 1024;
-   char *buf;
+   int len;
+   char *buf = NULL;
int argc = ZEND_NUM_ARGS();
php_stream *stream;
 
 -1258,30 +1258,33 
 
php_stream_from_zval(stream, arg1);
 
-   if (argc1) {
+   if (argc == 1) {
+   /* ask streams to give us a buffer of an appropriate size */
+   buf = php_stream_gets(stream, NULL, 0);
+   if (buf == NULL)
+   goto exit_failed;
+   } else if (argc  1) {
convert_to_long_ex(arg2);
len = Z_LVAL_PP(arg2);
-   }
-
-   if (len  0) {
-   php_error_docref(NULL TSRMLS_CC, E_WARNING, Length parameter may not 
be negative);
-   RETURN_FALSE;
-   }
-
-   buf = emalloc(sizeof(char) * (len + 1));
-   /* needed because recv doesnt put a null at the end*/
-   memset(buf, 0, len+1);
 
-   if (php_stream_gets(stream, buf, len) == NULL)
-   goto exit_failed;
+   if (len  0) {
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, Length parameter 
+may not be negative);
+   RETURN_FALSE;
+   }
 
+   buf = ecalloc(len + 1, sizeof(char));
+   if (php_stream_gets(stream, buf, len) == NULL)
+   goto exit_failed;
+   }
+   
if (PG(magic_quotes_runtime)) {
Z_STRVAL_P(return_value) = php_addslashes(buf, 0, 
Z_STRLEN_P(return_value), 1 TSRMLS_CC);
Z_TYPE_P(return_value) = IS_STRING;
} else {
ZVAL_STRING(return_value, buf, 0);
-   /* resize buffer if it's much larger than the result */
-   if (Z_STRLEN_P(return_value)  len / 2) {
+   /* resize buffer if it's much larger than the result.
+* Only needed if the user requested a buffer size. */
+   if (argc  1  Z_STRLEN_P(return_value)  len / 2) {
Z_STRVAL_P(return_value) = erealloc(buf, 
Z_STRLEN_P(return_value) + 1);
}
}
 -1289,7 +1292,8 
 
 exit_failed:
RETVAL_FALSE;
-   efree(buf);
+   if (buf)
+   efree(buf);
 }
 /* }}} */
 
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.103 php4/main/streams.c:1.104
--- php4/main/streams.c:1.103   Sun Oct 13 19:43:46 2002
+++ php4/main/streams.c Sun Oct 13 22:28:35 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.103 2002/10/13 23:43:46 wez Exp $ */
+/* $Id: streams.c,v 1.104 2002/10/14 02:28:35 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -666,8 +666,8 
 PHPAPI char *_php_stream_gets(php_stream *stream, char *buf, size_t maxlen TSRMLS_DC)
 {
size_t avail = 0;
-   int did_copy = 0;
size_t current_buf_size = 0;
+   size_t total_copied = 0;
int grow_mode = 0;
char *bufstart = buf;
 
 -718,6 +718,7 
 * hard to follow */
bufstart = erealloc(bufstart, current_buf_size + cpysz 
+ 1);
current_buf_size += cpysz + 1;
+   buf = bufstart + total_copied;
} else {
if (cpysz = maxlen - 1) {
cpysz = maxlen - 1;
 -731,8 +732,8 
stream-readpos += cpysz;
buf += cpysz;
maxlen -= cpysz;
+   total_copied += cpysz;
 
-   did_copy = 1;
if (done) {
break;
}
 -758,8 +759,11 
}
}

-   if (!did_copy)
+   if (total_copied == 0) {
+   if (grow_mode)
+   assert(bufstart != NULL);
return NULL;
+   }

buf[0] = '\0';
 



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

[PHP-CVS] cvs: php4 /ext/standard file.c

2002-09-28 Thread Wez Furlong

wez Sat Sep 28 09:04:48 2002 EDT

  Modified files:  
/php4/ext/standard  file.c 
  Log:
  Add missing folding marker.
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.264 php4/ext/standard/file.c:1.265
--- php4/ext/standard/file.c:1.264  Fri Sep 27 19:42:38 2002
+++ php4/ext/standard/file.cSat Sep 28 09:04:47 2002
 -21,7 +21,7 
+--+
  */
 
-/* $Id: file.c,v 1.264 2002/09/27 23:42:38 wez Exp $ */
+/* $Id: file.c,v 1.265 2002/09/28 13:04:47 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
 -761,6 +761,7 
 
RETURN_LONG(retval);
 }
+/* }}} */
 
 
 /* {{{ stream_context related functions */



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




[PHP-CVS] cvs: php4 /ext/standard file.c file.h http_fopen_wrapper.c

2002-09-26 Thread Wez Furlong

wez Thu Sep 26 06:17:42 2002 EDT

  Modified files:  
/php4/ext/standard  file.c file.h http_fopen_wrapper.c 
  Log:
  Remove an unused variable and a now-unused function.
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.261 php4/ext/standard/file.c:1.262
--- php4/ext/standard/file.c:1.261  Thu Sep 26 06:14:40 2002
+++ php4/ext/standard/file.cThu Sep 26 06:17:40 2002
@@ -21,7 +21,7 @@
+--+
  */
 
-/* $Id: file.c,v 1.261 2002/09/26 10:14:40 wez Exp $ */
+/* $Id: file.c,v 1.262 2002/09/26 10:17:40 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -1113,41 +1113,6 @@
 }
 #endif /* HAVE_SYS_TIME_H || defined(PHP_WIN32) */
 /* }}} */
-
-
-/* {{{ proto array socket_get_status(resource socket_descriptor)
-   Return an array describing socket status */
-PHP_FUNCTION(socket_get_status)
-{
-   zval **socket;
-   php_stream *stream;
-
-   if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), socket) 
== FAILURE) {
-   WRONG_PARAM_COUNT;
-   }
-
-   php_stream_from_zval(stream, socket);
-   
-
-   array_init(return_value);
-
-   if (php_stream_is(stream, PHP_STREAM_IS_SOCKET)){
-
-   php_netstream_data_t *sock = PHP_NETSTREAM_DATA_FROM_STREAM(stream);
-
-   add_assoc_bool(return_value, timed_out, sock-timeout_event);
-   add_assoc_bool(return_value, blocked, sock-is_blocked);
-   add_assoc_bool(return_value, eof, sock-eof);
-   add_assoc_long(return_value, unread_bytes, stream-writepos - 
stream-readpos);
-
-   }
-   else{
-   RETURN_FALSE;
-   }
-
-}
-/* }}} */
-
 
 /* {{{ proto string fgets(resource fp[, int length])
Get a line from file pointer */
Index: php4/ext/standard/file.h
diff -u php4/ext/standard/file.h:1.66 php4/ext/standard/file.h:1.67
--- php4/ext/standard/file.h:1.66   Thu Sep 26 06:14:41 2002
+++ php4/ext/standard/file.hThu Sep 26 06:17:40 2002
@@ -16,7 +16,7 @@
+--+
 */
 
-/* $Id: file.h,v 1.66 2002/09/26 10:14:41 wez Exp $ */
+/* $Id: file.h,v 1.67 2002/09/26 10:17:40 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */
 
@@ -57,7 +57,6 @@
 PHP_FUNCTION(set_socket_blocking); /* deprecated */
 PHP_FUNCTION(socket_set_blocking);
 PHP_FUNCTION(socket_set_timeout);
-PHP_FUNCTION(socket_get_status);
 PHP_FUNCTION(set_file_buffer);
 PHP_FUNCTION(get_meta_tags);
 PHP_FUNCTION(flock);
Index: php4/ext/standard/http_fopen_wrapper.c
diff -u php4/ext/standard/http_fopen_wrapper.c:1.50 
php4/ext/standard/http_fopen_wrapper.c:1.51
--- php4/ext/standard/http_fopen_wrapper.c:1.50 Thu Sep 26 06:14:41 2002
+++ php4/ext/standard/http_fopen_wrapper.c  Thu Sep 26 06:17:41 2002
@@ -18,7 +18,7 @@
|  Wez Furlong [EMAIL PROTECTED]  |
+--+
  */
-/* $Id: http_fopen_wrapper.c,v 1.50 2002/09/26 10:14:41 wez Exp $ */ 
+/* $Id: http_fopen_wrapper.c,v 1.51 2002/09/26 10:17:41 wez Exp $ */ 
 
 #include php.h
 #include php_globals.h
@@ -283,7 +283,7 @@
while (!body  !php_stream_eof(stream)){

if (php_stream_gets(stream, http_header_line, 
HTTP_HEADER_BLOCK_SIZE-1) != NULL){
-   char *p, *ws;
+   char *p;
int found_eol = 0;
int http_header_line_length;




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




[PHP-CVS] cvs: php4 /ext/standard file.c file.h /main streams.c user_streams.c

2002-09-26 Thread Wez Furlong

wez Thu Sep 26 08:12:28 2002 EDT

  Modified files:  
/php4/ext/standard  file.c file.h 
/php4/main  streams.c user_streams.c 
  Log:
  Fix segfault in wrapper error log mechanism when errors are logged on
  second and subsequent events.
  Implement very simple recursion protection for user streams written
  like this:
  class urlEncodeStream {
  var $fp = NULL;
  
  function stream_open($path, $mode, $options, $opened_path)
  {
  $this-fp = fopen($path, $mode); // -- this recurses infinitely
  return is_resource($this-fp);
  }
  }
  
  file_register_wrapper('urlencode', 'urlEncodeStream');
  $fp = fopen('urlencode:///tmp/outputfile.txt', 'w');
  
  Noticed by: Yasuo.
  
  
  
Index: php4/ext/standard/file.c
diff -u php4/ext/standard/file.c:1.262 php4/ext/standard/file.c:1.263
--- php4/ext/standard/file.c:1.262  Thu Sep 26 06:17:40 2002
+++ php4/ext/standard/file.cThu Sep 26 08:12:26 2002
 -21,7 +21,7 
+--+
  */
 
-/* $Id: file.c,v 1.262 2002/09/26 10:17:40 wez Exp $ */
+/* $Id: file.c,v 1.263 2002/09/26 12:12:26 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
 -132,6 +132,7 
 static void file_globals_ctor(php_file_globals *file_globals_p TSRMLS_DC)
 {
FG(pclose_ret) = 0;
+   FG(user_stream_current_filename) = NULL;
FG(def_chunk_size) = PHP_SOCK_CHUNK_SIZE;
 }
 
Index: php4/ext/standard/file.h
diff -u php4/ext/standard/file.h:1.67 php4/ext/standard/file.h:1.68
--- php4/ext/standard/file.h:1.67   Thu Sep 26 06:17:40 2002
+++ php4/ext/standard/file.hThu Sep 26 08:12:27 2002
 -16,7 +16,7 
+--+
 */
 
-/* $Id: file.h,v 1.67 2002/09/26 10:17:40 wez Exp $ */
+/* $Id: file.h,v 1.68 2002/09/26 12:12:27 wez Exp $ */
 
 /* Synced with php 3.0 revision 1.30 1999-06-16 [ssb] */
 
 -115,6 +115,7 
int auto_detect_line_endings;
int default_socket_timeout;
char *user_agent;
+   char *user_stream_current_filename; /* for simple recursion protection */
 } php_file_globals;
 
 #ifdef ZTS
Index: php4/main/streams.c
diff -u php4/main/streams.c:1.82 php4/main/streams.c:1.83
--- php4/main/streams.c:1.82Wed Sep 25 11:25:12 2002
+++ php4/main/streams.c Thu Sep 26 08:12:27 2002
 -20,7 +20,7 
+--+
  */
 
-/* $Id: streams.c,v 1.82 2002/09/25 15:25:12 wez Exp $ */
+/* $Id: streams.c,v 1.83 2002/09/26 12:12:27 wez Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
 -1988,7 +1988,7 
int free_msg = 0;
 
if (wrapper) {
-   if (wrapper-err_count) {
+   if (wrapper-err_count  0) {
int i;
size_t l;
int brlen;
 -2038,6 +2038,7 
if (wrapper-err_stack)
efree(wrapper-err_stack);
wrapper-err_stack = NULL;
+   wrapper-err_count = 0;
}
 #if ZEND_DEBUG
if (stream == NULL  copy_of_path != NULL)
Index: php4/main/user_streams.c
diff -u php4/main/user_streams.c:1.22 php4/main/user_streams.c:1.23
--- php4/main/user_streams.c:1.22   Mon Sep 23 14:18:40 2002
+++ php4/main/user_streams.cThu Sep 26 08:12:27 2002
 -17,10 +17,11 
+--+
 */
 
-/* $Id: user_streams.c,v 1.22 2002/09/23 18:18:40 wez Exp $ */
+/* $Id: user_streams.c,v 1.23 2002/09/26 12:12:27 wez Exp $ */
 
 #include php.h
 #include php_globals.h
+#include ext/standard/file.h
 
 static int le_protocols;
 
 -137,6 +138,13 
int call_result;
php_stream *stream = NULL;
 
+   /* Try to catch bad usage without prevent flexibility */
+   if (FG(user_stream_current_filename) != NULL  strcmp(filename, 
+FG(user_stream_current_filename)) == 0) {
+   php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, infinite 
+recursion prevented);
+   return NULL;
+   }
+   FG(user_stream_current_filename) = filename;
+   
us = emalloc(sizeof(*us));
us-wrapper = uwrap;
 
 -206,6 +214,8 
zval_ptr_dtor(zmode);
zval_ptr_dtor(zfilename);
 
+   FG(user_stream_current_filename) = NULL;
+   
return stream;
 }
 



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