return -1;
}
- static size_t php_openssl_sockop_write(php_stream *stream, const char *buf, size_t count) /* {{{ */
-static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)/* {{{ */
++static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t count) /* {{{ */
{
- return php_openssl_sockop_io( 0, stream, (char*)buf, count );
- return php_openssl_sockop_io(1, stream, buf, count TSRMLS_CC);
++ return php_openssl_sockop_io( 1, stream, buf, count );
}
/* }}} */
- static size_t php_openssl_sockop_read(php_stream *stream, char *buf, size_t count) /* {{{ */
-static size_t php_openssl_sockop_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC) /* {{{ */
++static size_t php_openssl_sockop_write(php_stream *stream, const char *buf, size_t count) /* {{{ */
{
- return php_openssl_sockop_io( 1, stream, buf, count );
- return php_openssl_sockop_io(0, stream, (char*)buf, count TSRMLS_CC);
++ return php_openssl_sockop_io( 0, stream, (char*)buf, count );
}
/* }}} */
/* Only do this if SSL is active. */
if (sslsock->ssl_active) {
int retry = 1;
- struct timeval start_time,
- *timeout;
- int blocked = sslsock->s.is_blocked,
- has_timeout = 0;
+ struct timeval start_time;
+ struct timeval *timeout;
+ int blocked = sslsock->s.is_blocked;
+ int has_timeout = 0;
+ int nr_bytes = 0;
+
+ /* prevent overflow in openssl */
+ if (count > INT_MAX) {
+ count = INT_MAX;
+ }
/* Begin by making the socket non-blocking. This allows us to check the timeout. */
- if (SUCCESS == php_set_sock_blocking(sslsock->s.socket, 0 TSRMLS_CC)) {
+ if (SUCCESS == php_set_sock_blocking(sslsock->s.socket, 0)) {
sslsock->s.is_blocked = 0;
}
/* Now, do the IO operation. Don't block if we can't complete... */
if (read) {
- nr_bytes = SSL_read(sslsock->ssl_handle, buf, count);
+ nr_bytes = SSL_read(sslsock->ssl_handle, buf, (int)count);
-
+
if (sslsock->reneg && sslsock->reneg->should_close) {
/* renegotiation rate limiting triggered */
- php_stream_xport_shutdown(stream, (stream_shutdown_t)SHUT_RDWR TSRMLS_CC);
+ php_stream_xport_shutdown(stream, (stream_shutdown_t)SHUT_RDWR);
nr_bytes = 0;
stream->eof = 1;
- break;
+ break;
}
} else {
- nr_bytes = SSL_write(sslsock->ssl_handle, buf, count);
+ nr_bytes = SSL_write(sslsock->ssl_handle, buf, (int)count);
}
/* Now, how much time until we time out? */
if (errno == EAGAIN && err == SSL_ERROR_WANT_READ && read) {
retry = 1;
}
- if (errno == EAGAIN && SSL_ERROR_WANT_WRITE && read == 0) {
+ if (errno == EAGAIN && SSL_ERROR_WANT_WRITE && read == 0) {
retry = 1;
}
-
+
/* Also, on reads, we may get this condition on an EOF. We should check properly. */
if (read) {
- stream->eof = (retry == 0 && errno != EAGAIN && !SSL_pending(sslsock->ssl_handle));
+ stream->eof = (retry == 0 && errno != EAGAIN && !SSL_pending(sslsock->ssl_handle));
}
-
+
/* Now, if we have to wait some time, and we're supposed to be blocking, wait for the socket to become
* available. Now, php_pollfd_for uses select to wait up to our time_left value only...
*/
}
} else {
/* Else, if we got bytes back, check for possible errors. */
-- int err = SSL_get_error(sslsock->ssl_handle, nr_bytes );
++ int err = SSL_get_error(sslsock->ssl_handle, nr_bytes);
/* If we didn't get any error, then let's return it to PHP. */
- if (err == SSL_ERROR_NONE)
- break;
+ if (err == SSL_ERROR_NONE) {
+ break;
+ }
/* Otherwise, we need to wait again (up to time_left or we get an error) */
- if (blocked)
+ if (blocked) {
if (read) {
php_pollfd_for(sslsock->s.socket, (err == SSL_ERROR_WANT_WRITE) ?
(POLLOUT|POLLPRI) : (POLLIN|POLLPRI), has_timeout ? &left_time : NULL);
php_pollfd_for(sslsock->s.socket, (err == SSL_ERROR_WANT_READ) ?
(POLLIN|POLLPRI) : (POLLOUT|POLLPRI), has_timeout ? &left_time : NULL);
}
+ }
}
- /* Finally, we keep going until we got data, and an SSL_ERROR_NONE, unless we had an error. */
+
+ /* Finally, we keep going until we got data, and an SSL_ERROR_NONE, unless we had an error. */
} while (retry);
-
+
/* Tell PHP if we read / wrote bytes. */
if (nr_bytes > 0) {
- php_stream_notify_progress_increment(stream->context, nr_bytes, 0);
+ php_stream_notify_progress_increment(PHP_STREAM_CONTEXT(stream), nr_bytes, 0);
}
/* And if we were originally supposed to be blocking, let's reset the socket to that. */
if (blocked) {
- php_set_sock_blocking(sslsock->s.socket, 1 TSRMLS_CC);
+ php_set_sock_blocking(sslsock->s.socket, 1);
- sslsock->s.is_blocked = 1;
+ sslsock->s.is_blocked = 1;
}
+
+ return 0 > nr_bytes ? 0 : nr_bytes;
} else {
+ size_t nr_bytes = 0;
+
/*
- * This block is if we had no timeout... We will just sit and wait forever on the IO operation.
- * This block is if we had no timeout... We will just sit and wait forever on the IO operation.
++ * This block is if we had no timeout... We will just sit and wait forever on the IO operation.
*/
if (read) {
- nr_bytes = php_stream_socket_ops.read(stream, buf, count TSRMLS_CC);
+ nr_bytes = php_stream_socket_ops.read(stream, buf, count);
} else {
- nr_bytes = php_stream_socket_ops.write(stream, buf, count TSRMLS_CC);
+ nr_bytes = php_stream_socket_ops.write(stream, buf, count);
}
- }
- /* PHP doesn't expect a negative return. */
- if (nr_bytes < 0) {
- nr_bytes = 0;
+ return nr_bytes;
}
-
- return nr_bytes;
}
/* }}} */
php_openssl_sockop_set_option,
};
-static long get_crypto_method(php_stream_context *ctx, long crypto_method)
+static zend_long get_crypto_method(php_stream_context *ctx, zend_long crypto_method)
{
- zval **val;
+ zval *val;
- if (ctx && php_stream_context_get_option(ctx, "ssl", "crypto_method", &val) == SUCCESS) {
+ if (ctx && (val = php_stream_context_get_option(ctx, "ssl", "crypto_method")) != NULL) {
convert_to_long_ex(val);
- crypto_method = (long)Z_LVAL_PP(val);
+ crypto_method = (zend_long)Z_LVAL_P(val);
- crypto_method |= STREAM_CRYPTO_IS_CLIENT;
+ crypto_method |= STREAM_CRYPTO_IS_CLIENT;
}
return crypto_method;
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
-- */
++ */