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

2003-06-19 Thread Ilia Alshanetsky
iliaa   Thu Jun 19 12:35:17 2003 EDT

  Modified files:  
/php4/ext/standard  streamsfuncs.c 
  Log:
  Fixed memory leak, when invalid context is specified.
  
  
Index: php4/ext/standard/streamsfuncs.c
diff -u php4/ext/standard/streamsfuncs.c:1.19 php4/ext/standard/streamsfuncs.c:1.20
--- php4/ext/standard/streamsfuncs.c:1.19   Thu Jun 19 12:10:54 2003
+++ php4/ext/standard/streamsfuncs.cThu Jun 19 12:35:17 2003
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: streamsfuncs.c,v 1.19 2003/06/19 16:10:54 iliaa Exp $ */
+/* $Id: streamsfuncs.c,v 1.20 2003/06/19 16:35:17 iliaa Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -669,10 +669,10 @@
 
 static int parse_context_params(php_stream_context *context, zval *params)
 {
-   int ret = SUCCESS;
+   int ret = FAILURE;
zval **tmp;
 
-   if (SUCCESS == zend_hash_find(Z_ARRVAL_P(params), notification, 
sizeof(notification), (void**)tmp)) {
+   if ((ret = zend_hash_find(Z_ARRVAL_P(params), notification, 
sizeof(notification), (void**)tmp)) == SUCCESS) {

if (context-notifier) {
php_stream_notification_free(context-notifier);
@@ -684,10 +684,14 @@
context-notifier-ptr = *tmp;
ZVAL_ADDREF(*tmp);
}
-   if (SUCCESS == zend_hash_find(Z_ARRVAL_P(params), options, 
sizeof(options), (void**)tmp)) {
+   if ((ret = zend_hash_find(Z_ARRVAL_P(params), options, sizeof(options), 
(void**)tmp)) == SUCCESS) {
parse_context_options(context, *tmp);
}
-   
+
+   if (ret != SUCCESS) {
+   php_stream_context_free(context);
+   }
+
return ret;
 }
 



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



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

2003-06-19 Thread Ilia Alshanetsky
iliaa   Thu Jun 19 17:04:43 2003 EDT

  Modified files:  
/php4/ext/standard  streamsfuncs.c 
  Log:
  Reverting previous patch (not necessary, thanks Pollita ;) )
  
  
Index: php4/ext/standard/streamsfuncs.c
diff -u php4/ext/standard/streamsfuncs.c:1.20 php4/ext/standard/streamsfuncs.c:1.21
--- php4/ext/standard/streamsfuncs.c:1.20   Thu Jun 19 12:35:17 2003
+++ php4/ext/standard/streamsfuncs.cThu Jun 19 17:04:43 2003
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: streamsfuncs.c,v 1.20 2003/06/19 16:35:17 iliaa Exp $ */
+/* $Id: streamsfuncs.c,v 1.21 2003/06/19 21:04:43 iliaa Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -669,10 +669,10 @@
 
 static int parse_context_params(php_stream_context *context, zval *params)
 {
-   int ret = FAILURE;
+   int ret = SUCCESS;
zval **tmp;
 
-   if ((ret = zend_hash_find(Z_ARRVAL_P(params), notification, 
sizeof(notification), (void**)tmp)) == SUCCESS) {
+   if (SUCCESS == zend_hash_find(Z_ARRVAL_P(params), notification, 
sizeof(notification), (void**)tmp)) {

if (context-notifier) {
php_stream_notification_free(context-notifier);
@@ -684,14 +684,10 @@
context-notifier-ptr = *tmp;
ZVAL_ADDREF(*tmp);
}
-   if ((ret = zend_hash_find(Z_ARRVAL_P(params), options, sizeof(options), 
(void**)tmp)) == SUCCESS) {
+   if (SUCCESS == zend_hash_find(Z_ARRVAL_P(params), options, 
sizeof(options), (void**)tmp)) {
parse_context_options(context, *tmp);
}
-
-   if (ret != SUCCESS) {
-   php_stream_context_free(context);
-   }
-
+   
return ret;
 }
 



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



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

2003-06-19 Thread Sara Golemon
pollita Thu Jun 19 18:30:54 2003 EDT

  Modified files:  
/php4/ext/standard  streamsfuncs.c 
  Log:
  Quiet down decode_context_param when stream (not context) is passed.
  Switch stream_socket_*() to use macro for retrieving context from zval.
  
  
Index: php4/ext/standard/streamsfuncs.c
diff -u php4/ext/standard/streamsfuncs.c:1.21 php4/ext/standard/streamsfuncs.c:1.22
--- php4/ext/standard/streamsfuncs.c:1.21   Thu Jun 19 17:04:43 2003
+++ php4/ext/standard/streamsfuncs.cThu Jun 19 18:30:54 2003
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: streamsfuncs.c,v 1.21 2003/06/19 21:04:43 iliaa Exp $ */
+/* $Id: streamsfuncs.c,v 1.22 2003/06/19 22:30:54 pollita Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -64,9 +64,7 @@
RETURN_FALSE;
}

-   if (zcontext) {
-   context = decode_context_param(zcontext TSRMLS_CC);
-   }
+   context = php_stream_context_from_zval(zcontext, flags  
PHP_FILE_NO_DEFAULT_CONTEXT);
 
if (flags  PHP_STREAM_CLIENT_PERSISTENT) {
spprintf(hashkey, 0, stream_socket_client__%s, host);
@@ -149,9 +147,7 @@
RETURN_FALSE;
}

-   if (zcontext) {
-   context = decode_context_param(zcontext TSRMLS_CC);
-   }
+   context = php_stream_context_from_zval(zcontext, flags  
PHP_FILE_NO_DEFAULT_CONTEXT);
 
if (zerrno) {
zval_dtor(zerrno);
@@ -698,15 +694,19 @@
 {
php_stream_context *context = NULL;
 
-   context = zend_fetch_resource(contextresource TSRMLS_CC, -1, 
Stream-Context, NULL, 1, php_le_stream_context());
+   context = zend_fetch_resource(contextresource TSRMLS_CC, -1, NULL, NULL, 1, 
php_le_stream_context());
if (context == NULL) {
php_stream *stream;
 
-   php_stream_from_zval_no_verify(stream, contextresource);
+   stream = zend_fetch_resource(contextresource TSRMLS_CC, -1, NULL, 
NULL, 2, php_file_le_stream(), php_file_le_pstream);
 
if (stream) {
context = stream-context;
if (context == NULL) {
+   /* Only way this happens is if file is opened with 
NO_DEFAULT_CONTEXT
+  param, but then something is called which requires 
a context.
+  Don't give them the default one though since they 
already said they
+  didn't want it. */
context = stream-context = php_stream_context_alloc();
}
}
@@ -727,7 +727,10 @@
RETURN_FALSE;
}
context = decode_context_param(zcontext TSRMLS_CC);
-   ZEND_VERIFY_RESOURCE(context);
+   if (!context) {
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, Invalid stream/context 
parameter.);
+   RETURN_FALSE;
+   }
 
*return_value = *context-options;
zval_copy_ctor(return_value);
@@ -756,7 +759,10 @@
 
/* figure out where the context is coming from exactly */
context = decode_context_param(zcontext TSRMLS_CC);
-   ZEND_VERIFY_RESOURCE(context);
+   if (!context) {
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, Invalid stream/context 
parameter.);
+   RETURN_FALSE;
+   }
 
if (options) {
/* handle the array syntax */
@@ -780,7 +786,10 @@
}
 
context = decode_context_param(zcontext TSRMLS_CC);
-   ZEND_VERIFY_RESOURCE(context);
+   if (!context) {
+   php_error_docref(NULL TSRMLS_CC, E_WARNING, Invalid stream/context 
parameter.);
+   RETURN_FALSE;
+   }
 
RETVAL_BOOL(parse_context_params(context, params) == SUCCESS);
 }



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



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

2003-06-17 Thread Sara Golemon
pollita Tue Jun 17 14:38:56 2003 EDT

  Modified files:  
/php4/ext/standard  streamsfuncs.c 
  Log:
  No need to allocate a hashtable when return_value is just going to be overwriten
  
Index: php4/ext/standard/streamsfuncs.c
diff -u php4/ext/standard/streamsfuncs.c:1.17 php4/ext/standard/streamsfuncs.c:1.18
--- php4/ext/standard/streamsfuncs.c:1.17   Mon Jun 16 14:19:14 2003
+++ php4/ext/standard/streamsfuncs.cTue Jun 17 14:38:56 2003
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: streamsfuncs.c,v 1.17 2003/06/16 18:19:14 pollita Exp $ */
+/* $Id: streamsfuncs.c,v 1.18 2003/06/17 18:38:56 pollita Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -726,7 +726,6 @@
context = decode_context_param(zcontext TSRMLS_CC);
ZEND_VERIFY_RESOURCE(context);
 
-   array_init(return_value);
*return_value = *context-options;
zval_copy_ctor(return_value);




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



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

2003-06-16 Thread Sara Golemon
pollita Mon Jun 16 14:19:14 2003 EDT

  Modified files:  
/php4/ext/standard  streamsfuncs.c 
/php4/main/streams  streams.c 
  Log:
  optionvalue is being copied via zval_copy_ctor, there's no need to addref the 
original
  
Index: php4/ext/standard/streamsfuncs.c
diff -u php4/ext/standard/streamsfuncs.c:1.16 php4/ext/standard/streamsfuncs.c:1.17
--- php4/ext/standard/streamsfuncs.c:1.16   Fri Jun 13 17:33:59 2003
+++ php4/ext/standard/streamsfuncs.cMon Jun 16 14:19:14 2003
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: streamsfuncs.c,v 1.16 2003/06/13 21:33:59 pollita Exp $ */
+/* $Id: streamsfuncs.c,v 1.17 2003/06/16 18:19:14 pollita Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -650,7 +650,6 @@
while (SUCCESS == 
zend_hash_get_current_data_ex(Z_ARRVAL_PP(wval), (void**)oval, opos)) {
 
if (HASH_KEY_IS_STRING == 
zend_hash_get_current_key_ex(Z_ARRVAL_PP(wval), okey, okey_len, NULL, 0, opos)) {
-   ZVAL_ADDREF(*oval);
php_stream_context_set_option(context, wkey, 
okey, *oval);
}
zend_hash_move_forward_ex(Z_ARRVAL_PP(wval), opos);
Index: php4/main/streams/streams.c
diff -u php4/main/streams/streams.c:1.26 php4/main/streams/streams.c:1.27
--- php4/main/streams/streams.c:1.26Sat Jun 14 15:30:42 2003
+++ php4/main/streams/streams.c Mon Jun 16 14:19:14 2003
@@ -19,7 +19,7 @@
+--+
  */
 
-/* $Id: streams.c,v 1.26 2003/06/14 19:30:42 helly Exp $ */
+/* $Id: streams.c,v 1.27 2003/06/16 18:19:14 pollita Exp $ */
 
 #define _GNU_SOURCE
 #include php.h
@@ -1676,7 +1676,6 @@
return FAILURE;
}
 
-   ZVAL_ADDREF(optionvalue);
wrapperhash = category;
}
return zend_hash_update(Z_ARRVAL_PP(wrapperhash), (char*)optionname, 
strlen(optionname)+1, (void**)copied_val, sizeof(zval *), NULL);



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



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

2003-06-03 Thread Wez Furlong
wez Mon Jun  2 12:36:10 2003 EDT

  Modified files:  
/php4/ext/standard  streamsfuncs.c 
  Log:
  Add seekable flag to stream_get_meta_data()
  # Caveat Emptor: some streams don't know if they are seekable until
  # sometime tries to seek first (user streams).
  
  
Index: php4/ext/standard/streamsfuncs.c
diff -u php4/ext/standard/streamsfuncs.c:1.13 php4/ext/standard/streamsfuncs.c:1.14
--- php4/ext/standard/streamsfuncs.c:1.13   Wed May 21 09:33:55 2003
+++ php4/ext/standard/streamsfuncs.cMon Jun  2 12:36:10 2003
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: streamsfuncs.c,v 1.13 2003/05/21 13:33:55 wez Exp $ */
+/* $Id: streamsfuncs.c,v 1.14 2003/06/02 16:36:10 wez Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -334,6 +334,8 @@
 #endif

add_assoc_long(return_value, unread_bytes, stream-writepos - 
stream-readpos);
+
+   add_assoc_bool(return_value, seekable, (stream-ops-seek)  (stream-flags 
 PHP_STREAM_FLAG_NO_SEEK) == 0);
 
if (!php_stream_populate_meta_data(stream, return_value)) {
add_assoc_bool(return_value, timed_out, 0);



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



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

2003-04-04 Thread Wez Furlong
wez Fri Apr  4 03:57:41 2003 EDT

  Modified files:  
/php4/ext/standard  streamsfuncs.c 
  Log:
  Simplify and enhance readability.
  
  
Index: php4/ext/standard/streamsfuncs.c
diff -u php4/ext/standard/streamsfuncs.c:1.6 php4/ext/standard/streamsfuncs.c:1.7
--- php4/ext/standard/streamsfuncs.c:1.6Fri Apr  4 00:21:03 2003
+++ php4/ext/standard/streamsfuncs.cFri Apr  4 03:57:40 2003
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: streamsfuncs.c,v 1.6 2003/04/04 05:21:03 pollita Exp $ */
+/* $Id: streamsfuncs.c,v 1.7 2003/04/04 08:57:40 wez Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -351,12 +351,12 @@
 
if (stream_xport_hash = php_stream_xport_get_hash()) {
array_init(return_value);
-   for(zend_hash_internal_pointer_reset(stream_xport_hash);
-   (key_flags = zend_hash_get_current_key_ex(stream_xport_hash, 
stream_xport, stream_xport_len, NULL, 0, NULL)) != HASH_KEY_NON_EXISTANT;
-   zend_hash_move_forward(stream_xport_hash)) {
-   if (key_flags == HASH_KEY_IS_STRING) {
-   add_next_index_stringl(return_value, 
stream_xport, stream_xport_len, 1);
-   }
+   zend_hash_internal_pointer_reset(stream_xport_hash);
+   while (zend_hash_get_current_key_ex(stream_xport_hash,
+   stream_xport, stream_xport_len,
+   NULL, 0, NULL) == HASH_KEY_IS_STRING) {
+   add_next_index_stringl(return_value, stream_xport, 
stream_xport_len, 1);
+   zend_hash_move_forward(stream_xport_hash);
}
} else {
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 streamsfuncs.c

2003-04-04 Thread Sara Golemon
pollita Fri Apr  4 15:43:36 2003 EDT

  Modified files:  
/php4/ext/standard  streamsfuncs.c 
  Log:
  User shouldn't have to initialize this pass-by-ref parameter
  
Index: php4/ext/standard/streamsfuncs.c
diff -u php4/ext/standard/streamsfuncs.c:1.7 php4/ext/standard/streamsfuncs.c:1.8
--- php4/ext/standard/streamsfuncs.c:1.7Fri Apr  4 03:57:40 2003
+++ php4/ext/standard/streamsfuncs.cFri Apr  4 15:43:36 2003
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: streamsfuncs.c,v 1.7 2003/04/04 08:57:40 wez Exp $ */
+/* $Id: streamsfuncs.c,v 1.8 2003/04/04 20:43:36 pollita Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -201,7 +201,7 @@
 
char *errstr = NULL;

-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, r|dz!, zstream, 
timeout, peername) == FAILURE) {
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, r|dz, zstream, 
timeout, peername) == FAILURE) {
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 streamsfuncs.c

2003-04-04 Thread Wez Furlong
wez Fri Apr  4 16:09:25 2003 EDT

  Modified files:  
/php4/ext/standard  streamsfuncs.c 
  Log:
  Warning fix
  
  
Index: php4/ext/standard/streamsfuncs.c
diff -u php4/ext/standard/streamsfuncs.c:1.8 php4/ext/standard/streamsfuncs.c:1.9
--- php4/ext/standard/streamsfuncs.c:1.8Fri Apr  4 15:43:36 2003
+++ php4/ext/standard/streamsfuncs.cFri Apr  4 16:09:25 2003
@@ -17,7 +17,7 @@
   +--+
 */
 
-/* $Id: streamsfuncs.c,v 1.8 2003/04/04 20:43:36 pollita Exp $ */
+/* $Id: streamsfuncs.c,v 1.9 2003/04/04 21:09:25 wez Exp $ */
 
 #include php.h
 #include php_globals.h
@@ -343,13 +343,13 @@
 {
HashTable *stream_xport_hash;
char *stream_xport;
-   int key_flags, stream_xport_len;
+   int stream_xport_len;
 
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
 
-   if (stream_xport_hash = php_stream_xport_get_hash()) {
+   if ((stream_xport_hash = php_stream_xport_get_hash())) {
array_init(return_value);
zend_hash_internal_pointer_reset(stream_xport_hash);
while (zend_hash_get_current_key_ex(stream_xport_hash,



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