Back to index

php5  5.3.10
Defines | Functions
streamsfuncs.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define PHP_STREAM_CLIENT_PERSISTENT   1
#define PHP_STREAM_CLIENT_ASYNC_CONNECT   2
#define PHP_STREAM_CLIENT_CONNECT   4

Functions

 PHP_FUNCTION (stream_socket_client)
 PHP_FUNCTION (stream_socket_server)
 PHP_FUNCTION (stream_socket_accept)
 PHP_FUNCTION (stream_socket_get_name)
 PHP_FUNCTION (stream_socket_recvfrom)
 PHP_FUNCTION (stream_socket_sendto)
 PHP_FUNCTION (stream_copy_to_stream)
 PHP_FUNCTION (stream_get_contents)
 PHP_FUNCTION (stream_set_blocking)
 PHP_FUNCTION (stream_select)
 PHP_FUNCTION (stream_set_timeout)
 PHP_FUNCTION (stream_set_read_buffer)
 PHP_FUNCTION (stream_set_write_buffer)
 PHP_FUNCTION (stream_get_transports)
 PHP_FUNCTION (stream_get_wrappers)
 PHP_FUNCTION (stream_get_line)
 PHP_FUNCTION (stream_get_meta_data)
 PHP_FUNCTION (stream_wrapper_register)
 PHP_FUNCTION (stream_wrapper_unregister)
 PHP_FUNCTION (stream_wrapper_restore)
 PHP_FUNCTION (stream_context_create)
 PHP_FUNCTION (stream_context_set_params)
 PHP_FUNCTION (stream_context_get_params)
 PHP_FUNCTION (stream_context_set_option)
 PHP_FUNCTION (stream_context_get_options)
 PHP_FUNCTION (stream_context_get_default)
 PHP_FUNCTION (stream_context_set_default)
 PHP_FUNCTION (stream_filter_prepend)
 PHP_FUNCTION (stream_filter_append)
 PHP_FUNCTION (stream_filter_remove)
 PHP_FUNCTION (stream_socket_enable_crypto)
 PHP_FUNCTION (stream_socket_shutdown)
 PHP_FUNCTION (stream_resolve_include_path)
 PHP_FUNCTION (stream_is_local)
 PHP_FUNCTION (stream_supports_lock)

Define Documentation

Definition at line 23 of file streamsfuncs.h.

#define PHP_STREAM_CLIENT_CONNECT   4

Definition at line 24 of file streamsfuncs.h.

Definition at line 22 of file streamsfuncs.h.


Function Documentation

PHP_FUNCTION ( stream_socket_client  )

Definition at line 86 of file streamsfuncs.c.

{
       char *host;
       int host_len;
       zval *zerrno = NULL, *zerrstr = NULL, *zcontext = NULL;
       double timeout = FG(default_socket_timeout);
       php_timeout_ull conv;
       struct timeval tv;
       char *hashkey = NULL;
       php_stream *stream = NULL;
       int err;
       long flags = PHP_STREAM_CLIENT_CONNECT;
       char *errstr = NULL;
       php_stream_context *context = NULL;

       RETVAL_FALSE;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zzdlr", &host, &host_len, &zerrno, &zerrstr, &timeout, &flags, &zcontext) == FAILURE) {
              RETURN_FALSE;
       }

       context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);

       if (context) {
              zend_list_addref(context->rsrc_id);
       }

       if (flags & PHP_STREAM_CLIENT_PERSISTENT) {
              spprintf(&hashkey, 0, "stream_socket_client__%s", host);
       }

       /* prepare the timeout value for use */
       conv = (php_timeout_ull) (timeout * 1000000.0);
#ifdef PHP_WIN32
       tv.tv_sec = (long)(conv / 1000000);
       tv.tv_usec =(long)(conv % 1000000);
#else
       tv.tv_sec = conv / 1000000;
       tv.tv_usec = conv % 1000000;
#endif
       if (zerrno)   {
              zval_dtor(zerrno);
              ZVAL_LONG(zerrno, 0);
       }
       if (zerrstr) {
              zval_dtor(zerrstr);
              ZVAL_STRING(zerrstr, "", 1);
       }

       stream = php_stream_xport_create(host, host_len, ENFORCE_SAFE_MODE | REPORT_ERRORS,
                     STREAM_XPORT_CLIENT | (flags & PHP_STREAM_CLIENT_CONNECT ? STREAM_XPORT_CONNECT : 0) |
                     (flags & PHP_STREAM_CLIENT_ASYNC_CONNECT ? STREAM_XPORT_CONNECT_ASYNC : 0),
                     hashkey, &tv, context, &errstr, &err);


       if (stream == NULL) {
              /* host might contain binary characters */
              char *quoted_host = php_addslashes(host, host_len, NULL, 0 TSRMLS_CC);

              php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", quoted_host, errstr == NULL ? "Unknown error" : errstr);
              efree(quoted_host);
       }

       if (hashkey) {
              efree(hashkey);
       }

       if (stream == NULL)  {
              if (zerrno) {
                     zval_dtor(zerrno);
                     ZVAL_LONG(zerrno, err);
              }
              if (zerrstr && errstr) {
                     /* no need to dup; we need to efree buf anyway */
                     zval_dtor(zerrstr);
                     ZVAL_STRING(zerrstr, errstr, 0);
              } else if (errstr) {
                     efree(errstr);
              }
              RETURN_FALSE;
       }

       if (errstr) {
              efree(errstr);
       }

       php_stream_to_zval(stream, return_value);

}

Here is the call graph for this function:

PHP_FUNCTION ( stream_socket_server  )

Definition at line 179 of file streamsfuncs.c.

{
       char *host;
       int host_len;
       zval *zerrno = NULL, *zerrstr = NULL, *zcontext = NULL;
       php_stream *stream = NULL;
       int err = 0;
       long flags = STREAM_XPORT_BIND | STREAM_XPORT_LISTEN;
       char *errstr = NULL;
       php_stream_context *context = NULL;

       RETVAL_FALSE;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zzlr", &host, &host_len, &zerrno, &zerrstr, &flags, &zcontext) == FAILURE) {
              RETURN_FALSE;
       }

       context = php_stream_context_from_zval(zcontext, flags & PHP_FILE_NO_DEFAULT_CONTEXT);

       if (context) {
              zend_list_addref(context->rsrc_id);
       }

       if (zerrno)   {
              zval_dtor(zerrno);
              ZVAL_LONG(zerrno, 0);
       }
       if (zerrstr) {
              zval_dtor(zerrstr);
              ZVAL_STRING(zerrstr, "", 1);
       }

       stream = php_stream_xport_create(host, host_len, ENFORCE_SAFE_MODE | REPORT_ERRORS,
                     STREAM_XPORT_SERVER | flags,
                     NULL, NULL, context, &errstr, &err);

       if (stream == NULL) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to connect to %s (%s)", host, errstr == NULL ? "Unknown error" : errstr);
       }

       if (stream == NULL)  {
              if (zerrno) {
                     zval_dtor(zerrno);
                     ZVAL_LONG(zerrno, err);
              }
              if (zerrstr && errstr) {
                     /* no need to dup; we need to efree buf anyway */
                     zval_dtor(zerrstr);
                     ZVAL_STRING(zerrstr, errstr, 0);
              } else if (errstr) {
                     efree(errstr);
              }
              RETURN_FALSE;
       }

       if (errstr) {
              efree(errstr);
       }

       php_stream_to_zval(stream, return_value);
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_socket_accept  )

Definition at line 244 of file streamsfuncs.c.

{
       double timeout = FG(default_socket_timeout);
       zval *zpeername = NULL;
       char *peername = NULL;
       int peername_len;
       php_timeout_ull conv;
       struct timeval tv;
       php_stream *stream = NULL, *clistream = NULL;
       zval *zstream;

       char *errstr = NULL;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|dz", &zstream, &timeout, &zpeername) == FAILURE) {
              RETURN_FALSE;
       }

       php_stream_from_zval(stream, &zstream);

       /* prepare the timeout value for use */
       conv = (php_timeout_ull) (timeout * 1000000.0);
#ifdef PHP_WIN32
       tv.tv_sec = (long)(conv / 1000000);
       tv.tv_usec = (long)(conv % 1000000);
#else
       tv.tv_sec = conv / 1000000;
       tv.tv_usec = conv % 1000000;
#endif
       if (zpeername) {
              zval_dtor(zpeername);
              ZVAL_NULL(zpeername);
       }

       if (0 == php_stream_xport_accept(stream, &clistream,
                            zpeername ? &peername : NULL,
                            zpeername ? &peername_len : NULL,
                            NULL, NULL,
                            &tv, &errstr
                            TSRMLS_CC) && clistream) {

              if (peername) {
                     ZVAL_STRINGL(zpeername, peername, peername_len, 0);
              }
              php_stream_to_zval(clistream, return_value);
       } else {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "accept failed: %s", errstr ? errstr : "Unknown error");
              RETVAL_FALSE;
       }

       if (errstr) {
              efree(errstr);
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_socket_get_name  )

Definition at line 301 of file streamsfuncs.c.

{
       php_stream *stream;
       zval *zstream;
       zend_bool want_peer;
       char *name = NULL;
       int name_len;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb", &zstream, &want_peer) == FAILURE) {
              RETURN_FALSE;
       }

       php_stream_from_zval(stream, &zstream);

       if (0 != php_stream_xport_get_name(stream, want_peer,
                            &name,
                            &name_len,
                            NULL, NULL
                            TSRMLS_CC)) {
              RETURN_FALSE;
       }

       RETURN_STRINGL(name, name_len, 0);
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_socket_recvfrom  )

Definition at line 358 of file streamsfuncs.c.

{
       php_stream *stream;
       zval *zstream, *zremote = NULL;
       char *remote_addr = NULL;
       int remote_addr_len;
       long to_read = 0;
       char *read_buf;
       long flags = 0;
       int recvd;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|lz", &zstream, &to_read, &flags, &zremote) == FAILURE) {
              RETURN_FALSE;
       }

       php_stream_from_zval(stream, &zstream);

       if (zremote) {
              zval_dtor(zremote);
              ZVAL_NULL(zremote);
       }

       if (to_read <= 0) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0");
              RETURN_FALSE;
       }

       read_buf = safe_emalloc(1, to_read, 1);

       recvd = php_stream_xport_recvfrom(stream, read_buf, to_read, flags, NULL, NULL,
                     zremote ? &remote_addr : NULL,
                     zremote ? &remote_addr_len : NULL
                     TSRMLS_CC);

       if (recvd >= 0) {
              if (zremote) {
                     ZVAL_STRINGL(zremote, remote_addr, remote_addr_len, 0);
              }
              read_buf[recvd] = '\0';

              if (PG(magic_quotes_runtime)) {
                     Z_TYPE_P(return_value) = IS_STRING;
                     Z_STRVAL_P(return_value) = php_addslashes(Z_STRVAL_P(return_value), Z_STRLEN_P(return_value), &Z_STRLEN_P(return_value), 1 TSRMLS_CC);
                     return;
              } else {
                     RETURN_STRINGL(read_buf, recvd, 0);
              }
       }

       efree(read_buf);
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_socket_sendto  )

Definition at line 329 of file streamsfuncs.c.

{
       php_stream *stream;
       zval *zstream;
       long flags = 0;
       char *data, *target_addr = NULL;
       int datalen, target_addr_len = 0;
       php_sockaddr_storage sa;
       socklen_t sl = 0;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|ls", &zstream, &data, &datalen, &flags, &target_addr, &target_addr_len) == FAILURE) {
              RETURN_FALSE;
       }
       php_stream_from_zval(stream, &zstream);

       if (target_addr_len) {
              /* parse the address */
              if (FAILURE == php_network_parse_network_address_with_port(target_addr, target_addr_len, (struct sockaddr*)&sa, &sl TSRMLS_CC)) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to parse `%s' into a valid network address", target_addr);
                     RETURN_FALSE;
              }
       }

       RETURN_LONG(php_stream_xport_sendto(stream, data, datalen, flags, target_addr ? &sa : NULL, sl TSRMLS_CC));
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_copy_to_stream  )

Definition at line 466 of file streamsfuncs.c.

{
       php_stream *src, *dest;
       zval *zsrc, *zdest;
       long maxlen = PHP_STREAM_COPY_ALL, pos = 0;
       size_t len;
       int ret;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rr|ll", &zsrc, &zdest, &maxlen, &pos) == FAILURE) {
              RETURN_FALSE;
       }

       php_stream_from_zval(src, &zsrc);
       php_stream_from_zval(dest, &zdest);

       if (pos > 0 && php_stream_seek(src, pos, SEEK_SET) < 0) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to position %ld in the stream", pos);
              RETURN_FALSE;
       }

       ret = php_stream_copy_to_stream_ex(src, dest, maxlen, &len);

       if (ret != SUCCESS) {
              RETURN_FALSE;
       }
       RETURN_LONG(len);
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_get_contents  )

Definition at line 414 of file streamsfuncs.c.

{
       php_stream    *stream;
       zval          *zsrc;
       long          maxlen        = PHP_STREAM_COPY_ALL,
                            desiredpos    = -1L;
       int                  len,
                            newlen;
       char          *contents     = NULL;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|ll", &zsrc, &maxlen, &desiredpos) == FAILURE) {
              RETURN_FALSE;
       }

       php_stream_from_zval(stream, &zsrc);

       if (desiredpos >= 0) {
              int           seek_res = 0;
              off_t  position;

              position = php_stream_tell(stream);
              if (position >= 0 && desiredpos > position) {
                     /* use SEEK_CUR to allow emulation in streams that don't support seeking */
                     seek_res = php_stream_seek(stream, desiredpos - position, SEEK_CUR);
              } else if (desiredpos < position)  {
                     /* desired position before position or error on tell */
                     seek_res = php_stream_seek(stream, desiredpos, SEEK_SET);
              }

              if (seek_res != 0) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING,
                            "Failed to seek to position %ld in the stream", desiredpos);
                     RETURN_FALSE;
              }
       }

       len = php_stream_copy_to_mem(stream, &contents, maxlen, 0);

       if (contents) {
              if (len && PG(magic_quotes_runtime)) {
                     contents = php_addslashes(contents, len, &newlen, 1 TSRMLS_CC); /* 1 = free source string */
                     len = newlen;
              }
              RETVAL_STRINGL(contents, len, 0);
       } else {
              RETVAL_EMPTY_STRING();
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_set_blocking  )

Definition at line 1331 of file streamsfuncs.c.

{
       zval *arg1;
       int block;
       long arg2;
       php_stream *stream;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) {
              return;
       }

       php_stream_from_zval(stream, &arg1);

       block = arg2;

       if (php_stream_set_option(stream, PHP_STREAM_OPTION_BLOCKING, block == 0 ? 0 : 1, NULL) == -1) {
              RETURN_FALSE;
       }

       RETURN_TRUE;
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_select  )

Definition at line 754 of file streamsfuncs.c.

{
       zval                 *r_array, *w_array, *e_array, **sec = NULL;
       struct timeval       tv;
       struct timeval *tv_p = NULL;
       fd_set               rfds, wfds, efds;
       php_socket_t  max_fd = 0;
       int                         retval, sets = 0;
       long                 usec = 0;
       int                         set_count, max_set_count = 0;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!a!a!Z!|l", &r_array, &w_array, &e_array, &sec, &usec) == FAILURE)
              return;

       FD_ZERO(&rfds);
       FD_ZERO(&wfds);
       FD_ZERO(&efds);

       if (r_array != NULL) {
              set_count = stream_array_to_fd_set(r_array, &rfds, &max_fd TSRMLS_CC);
              if (set_count > max_set_count)
                     max_set_count = set_count;
              sets += set_count;
       }

       if (w_array != NULL) {
              set_count = stream_array_to_fd_set(w_array, &wfds, &max_fd TSRMLS_CC);
              if (set_count > max_set_count)
                     max_set_count = set_count;
              sets += set_count;
       }

       if (e_array != NULL) {
              set_count = stream_array_to_fd_set(e_array, &efds, &max_fd TSRMLS_CC);
              if (set_count > max_set_count)
                     max_set_count = set_count;
              sets += set_count;
       }

       if (!sets) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "No stream arrays were passed");
              RETURN_FALSE;
       }

       PHP_SAFE_MAX_FD(max_fd, max_set_count);

       /* If seconds is not set to null, build the timeval, else we wait indefinitely */
       if (sec != NULL) {
              convert_to_long_ex(sec);

              if (Z_LVAL_PP(sec) < 0) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "The seconds parameter must be greater than 0");
                     RETURN_FALSE;
              } else if (usec < 0) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "The microseconds parameter must be greater than 0");
                     RETURN_FALSE;
              }

              /* Solaris + BSD do not like microsecond values which are >= 1 sec */
              if (usec > 999999) {
                     tv.tv_sec = Z_LVAL_PP(sec) + (usec / 1000000);
                     tv.tv_usec = usec % 1000000;
              } else {
                     tv.tv_sec = Z_LVAL_PP(sec);
                     tv.tv_usec = usec;
              }

              tv_p = &tv;
       }

       /* slight hack to support buffered data; if there is data sitting in the
        * read buffer of any of the streams in the read array, let's pretend
        * that we selected, but return only the readable sockets */
       if (r_array != NULL) {

              retval = stream_array_emulate_read_fd_set(r_array TSRMLS_CC);
              if (retval > 0) {
                     if (w_array != NULL) {
                            zend_hash_clean(Z_ARRVAL_P(w_array));
                     }
                     if (e_array != NULL) {
                            zend_hash_clean(Z_ARRVAL_P(e_array));
                     }
                     RETURN_LONG(retval);
              }
       }

       retval = php_select(max_fd+1, &rfds, &wfds, &efds, tv_p);

       if (retval == -1) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to select [%d]: %s (max_fd=%d)",
                            errno, strerror(errno), max_fd);
              RETURN_FALSE;
       }

       if (r_array != NULL) stream_array_from_fd_set(r_array, &rfds TSRMLS_CC);
       if (w_array != NULL) stream_array_from_fd_set(w_array, &wfds TSRMLS_CC);
       if (e_array != NULL) stream_array_from_fd_set(e_array, &efds TSRMLS_CC);

       RETURN_LONG(retval);
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_set_timeout  )
PHP_FUNCTION ( stream_set_read_buffer  )

Definition at line 1421 of file streamsfuncs.c.

{
       zval *arg1;
       int ret;
       long arg2;
       size_t buff;
       php_stream *stream;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) {
              RETURN_FALSE;
       }

       php_stream_from_zval(stream, &arg1);

       buff = arg2;

       /* if buff is 0 then set to non-buffered */
       if (buff == 0) {
              ret = php_stream_set_option(stream, PHP_STREAM_OPTION_READ_BUFFER, PHP_STREAM_BUFFER_NONE, NULL);
       } else {
              ret = php_stream_set_option(stream, PHP_STREAM_OPTION_READ_BUFFER, PHP_STREAM_BUFFER_FULL, &buff);
       }

       RETURN_LONG(ret == 0 ? 0 : EOF);
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_set_write_buffer  )

Definition at line 1392 of file streamsfuncs.c.

{
       zval *arg1;
       int ret;
       long arg2;
       size_t buff;
       php_stream *stream;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &arg1, &arg2) == FAILURE) {
              RETURN_FALSE;
       }

       php_stream_from_zval(stream, &arg1);

       buff = arg2;

       /* if buff is 0 then set to non-buffered */
       if (buff == 0) {
              ret = php_stream_set_option(stream, PHP_STREAM_OPTION_WRITE_BUFFER, PHP_STREAM_BUFFER_NONE, NULL);
       } else {
              ret = php_stream_set_option(stream, PHP_STREAM_OPTION_WRITE_BUFFER, PHP_STREAM_BUFFER_FULL, &buff);
       }

       RETURN_LONG(ret == 0 ? 0 : EOF);
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_get_transports  )

Definition at line 556 of file streamsfuncs.c.

{
       HashTable *stream_xport_hash;
       char *stream_xport;
       int stream_xport_len;
       ulong num_key;

       if (zend_parse_parameters_none() == FAILURE) {
              return;
       }

       if ((stream_xport_hash = php_stream_xport_get_hash())) {
              HashPosition pos;
              array_init(return_value);
              zend_hash_internal_pointer_reset_ex(stream_xport_hash, &pos);
              while (zend_hash_get_current_key_ex(stream_xport_hash,
                                   &stream_xport, &stream_xport_len,
                                   &num_key, 0, &pos) == HASH_KEY_IS_STRING) {
                     add_next_index_stringl(return_value, stream_xport, stream_xport_len - 1, 1);
                     zend_hash_move_forward_ex(stream_xport_hash, &pos);
              }
       } else {
              RETURN_FALSE;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_get_wrappers  )

Definition at line 585 of file streamsfuncs.c.

{
       HashTable *url_stream_wrappers_hash;
       char *stream_protocol;
       int key_flags, stream_protocol_len = 0;
       ulong num_key;

       if (zend_parse_parameters_none() == FAILURE) {
              return;
       }

       if ((url_stream_wrappers_hash = php_stream_get_url_stream_wrappers_hash())) {
              HashPosition pos;
              array_init(return_value);
              for (zend_hash_internal_pointer_reset_ex(url_stream_wrappers_hash, &pos);
                     (key_flags = zend_hash_get_current_key_ex(url_stream_wrappers_hash, &stream_protocol, &stream_protocol_len, &num_key, 0, &pos)) != HASH_KEY_NON_EXISTANT;
                     zend_hash_move_forward_ex(url_stream_wrappers_hash, &pos)) {
                            if (key_flags == HASH_KEY_IS_STRING) {
                                   add_next_index_stringl(return_value, stream_protocol, stream_protocol_len - 1, 1);
                            }
              }
       } else {
              RETURN_FALSE;
       }

}

Here is the call graph for this function:

PHP_FUNCTION ( stream_get_line  )

Definition at line 1296 of file streamsfuncs.c.

{
       char *str = NULL;
       int str_len = 0;
       long max_length;
       zval *zstream;
       char *buf;
       size_t buf_size;
       php_stream *stream;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|s", &zstream, &max_length, &str, &str_len) == FAILURE) {
              RETURN_FALSE;
       }

       if (max_length < 0) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "The maximum allowed length must be greater than or equal to zero");
              RETURN_FALSE;
       }
       if (!max_length) {
              max_length = PHP_SOCK_CHUNK_SIZE;
       }

       php_stream_from_zval(stream, &zstream);

       if ((buf = php_stream_get_record(stream, max_length, &buf_size, str, str_len TSRMLS_CC))) {
              RETURN_STRINGL(buf, buf_size, 0);
       } else {
              RETURN_FALSE;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_get_meta_data  )

Definition at line 497 of file streamsfuncs.c.

{
       zval *arg1;
       php_stream *stream;
       zval *newval;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) {
              return;
       }
       php_stream_from_zval(stream, &arg1);

       array_init(return_value);

       if (stream->wrapperdata) {
              MAKE_STD_ZVAL(newval);
              MAKE_COPY_ZVAL(&stream->wrapperdata, newval);

              add_assoc_zval(return_value, "wrapper_data", newval);
       }
       if (stream->wrapper) {
              add_assoc_string(return_value, "wrapper_type", (char *)stream->wrapper->wops->label, 1);
       }
       add_assoc_string(return_value, "stream_type", (char *)stream->ops->label, 1);

       add_assoc_string(return_value, "mode", stream->mode, 1);

#if 0  /* TODO: needs updating for new filter API */
       if (stream->filterhead) {
              php_stream_filter *filter;

              MAKE_STD_ZVAL(newval);
              array_init(newval);

              for (filter = stream->filterhead; filter != NULL; filter = filter->next) {
                     add_next_index_string(newval, (char *)filter->fops->label, 1);
              }

              add_assoc_zval(return_value, "filters", newval);
       }
#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 (stream->orig_path) {
              add_assoc_string(return_value, "uri", stream->orig_path, 1);
       }

       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));
       }

}

Here is the call graph for this function:

PHP_FUNCTION ( stream_wrapper_register  )

Definition at line 491 of file userspace.c.

{
       char *protocol, *classname;
       int protocol_len, classname_len;
       struct php_user_stream_wrapper * uwrap;
       int rsrc_id;
       long flags = 0;
       
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|l", &protocol, &protocol_len, &classname, &classname_len, &flags) == FAILURE) {
              RETURN_FALSE;
       }
       
       uwrap = (struct php_user_stream_wrapper *)ecalloc(1, sizeof(*uwrap));
       uwrap->protoname = estrndup(protocol, protocol_len);
       uwrap->classname = estrndup(classname, classname_len);
       uwrap->wrapper.wops = &user_stream_wops;
       uwrap->wrapper.abstract = uwrap;
       uwrap->wrapper.is_url = ((flags & PHP_STREAM_IS_URL) != 0);

       rsrc_id = ZEND_REGISTER_RESOURCE(NULL, uwrap, le_protocols);

       if (zend_lookup_class(uwrap->classname, classname_len, (zend_class_entry***)&uwrap->ce TSRMLS_CC) == SUCCESS) {
              uwrap->ce = *(zend_class_entry**)uwrap->ce;
              if (php_register_url_stream_wrapper_volatile(protocol, &uwrap->wrapper TSRMLS_CC) == SUCCESS) {
                     RETURN_TRUE;
              } else {
                     /* We failed.  But why? */
                     if (zend_hash_exists(php_stream_get_url_stream_wrappers_hash(), protocol, protocol_len + 1)) {
                            php_error_docref(NULL TSRMLS_CC, E_WARNING, "Protocol %s:// is already defined.", protocol);
                     } else {
                            /* Hash doesn't exist so it must have been an invalid protocol scheme */
                            php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid protocol scheme specified. Unable to register wrapper class %s to %s://", classname, protocol);
                     }
              }
       } else {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "class '%s' is undefined", classname);
       }

       zend_list_delete(rsrc_id);
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_wrapper_unregister  )

Definition at line 536 of file userspace.c.

{
       char *protocol;
       int protocol_len;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &protocol, &protocol_len) == FAILURE) {
              RETURN_FALSE;
       }

       if (php_unregister_url_stream_wrapper_volatile(protocol TSRMLS_CC) == FAILURE) {
              /* We failed */
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to unregister protocol %s://", protocol);
              RETURN_FALSE;
       }

       RETURN_TRUE;
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_wrapper_restore  )

Definition at line 557 of file userspace.c.

{
       char *protocol;
       int protocol_len;
       php_stream_wrapper **wrapperpp = NULL, *wrapper;
       HashTable *global_wrapper_hash;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &protocol, &protocol_len) == FAILURE) {
              RETURN_FALSE;
       }

       global_wrapper_hash = php_stream_get_url_stream_wrappers_hash_global();
       if (php_stream_get_url_stream_wrappers_hash() == global_wrapper_hash) {
              php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s:// was never changed, nothing to restore", protocol);
              RETURN_TRUE;
       }

       if ((zend_hash_find(global_wrapper_hash, protocol, protocol_len + 1, (void**)&wrapperpp) == FAILURE) || !wrapperpp) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s:// never existed, nothing to restore", protocol);
              RETURN_FALSE;
       }

       /* next line might delete the pointer that wrapperpp points at, so deref it now */
       wrapper = *wrapperpp;

       /* A failure here could be okay given that the protocol might have been merely unregistered */
       php_unregister_url_stream_wrapper_volatile(protocol TSRMLS_CC);

       if (php_register_url_stream_wrapper_volatile(protocol, wrapper TSRMLS_CC) == FAILURE) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to restore original %s:// wrapper", protocol);
              RETURN_FALSE;
       }      

       RETURN_TRUE;
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_context_create  )

Definition at line 1148 of file streamsfuncs.c.

{
       zval *options = NULL, *params = NULL;
       php_stream_context *context;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!a!", &options, &params) == FAILURE) {
              RETURN_FALSE;
       }

       context = php_stream_context_alloc();

       if (options) {
              parse_context_options(context, options TSRMLS_CC);
       }

       if (params) {
              parse_context_params(context, params TSRMLS_CC);
       }

       RETURN_RESOURCE(context->rsrc_id);
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_context_set_params  )

Definition at line 1053 of file streamsfuncs.c.

{
       zval *params, *zcontext;
       php_stream_context *context;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &zcontext, &params) == FAILURE) {
              RETURN_FALSE;
       }

       context = decode_context_param(zcontext TSRMLS_CC);
       if (!context) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter");
              RETURN_FALSE;
       }

       RETVAL_BOOL(parse_context_params(context, params TSRMLS_CC) == SUCCESS);
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_context_get_params  )

Definition at line 1074 of file streamsfuncs.c.

{
       zval *zcontext, *options;
       php_stream_context *context;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zcontext) == FAILURE) {
              RETURN_FALSE;
       }

       context = decode_context_param(zcontext TSRMLS_CC);
       if (!context) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter");
              RETURN_FALSE;
       }

       array_init(return_value);
       if (context->notifier && context->notifier->ptr && context->notifier->func == user_space_stream_notifier) {
              add_assoc_zval_ex(return_value, ZEND_STRS("notification"), context->notifier->ptr);
              Z_ADDREF_P(context->notifier->ptr);
       }
       ALLOC_INIT_ZVAL(options);
       ZVAL_ZVAL(options, context->options, 1, 0);
       add_assoc_zval_ex(return_value, ZEND_STRS("options"), options);
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_context_set_option  )

Definition at line 1017 of file streamsfuncs.c.

{
       zval *options = NULL, *zcontext = NULL, *zvalue = NULL;
       php_stream_context *context;
       char *wrappername, *optionname;
       int wrapperlen, optionlen;

       if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
                            "rssz", &zcontext, &wrappername, &wrapperlen,
                            &optionname, &optionlen, &zvalue) == FAILURE) {
              if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,
                                   "ra", &zcontext, &options) == FAILURE) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "called with wrong number or type of parameters; please RTM");
                     RETURN_FALSE;
              }
       }

       /* figure out where the context is coming from exactly */
       context = decode_context_param(zcontext TSRMLS_CC);
       if (!context) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter");
              RETURN_FALSE;
       }

       if (options) {
              /* handle the array syntax */
              RETVAL_BOOL(parse_context_options(context, options TSRMLS_CC) == SUCCESS);
       } else {
              php_stream_context_set_option(context, wrappername, optionname, zvalue);
              RETVAL_TRUE;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_context_get_options  )

Definition at line 997 of file streamsfuncs.c.

{
       zval *zcontext;
       php_stream_context *context;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zcontext) == FAILURE) {
              RETURN_FALSE;
       }
       context = decode_context_param(zcontext TSRMLS_CC);
       if (!context) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid stream/context parameter");
              RETURN_FALSE;
       }

       RETURN_ZVAL(context->options, 1, 0);
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_context_get_default  )

Definition at line 1102 of file streamsfuncs.c.

{
       zval *params = NULL;
       php_stream_context *context;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", &params) == FAILURE) {
              RETURN_FALSE;
       }

       if (FG(default_context) == NULL) {
              FG(default_context) = php_stream_context_alloc();
       }
       context = FG(default_context);

       if (params) {
              parse_context_options(context, params TSRMLS_CC);
       }

       php_stream_context_to_zval(context, return_value);
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_context_set_default  )

Definition at line 1126 of file streamsfuncs.c.

{
       zval *options = NULL;
       php_stream_context *context;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &options) == FAILURE) {
              return;
       }

       if (FG(default_context) == NULL) {
              FG(default_context) = php_stream_context_alloc();
       }
       context = FG(default_context);

       parse_context_options(context, options TSRMLS_CC);

       php_stream_context_to_zval(context, return_value);
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_filter_prepend  )

Definition at line 1248 of file streamsfuncs.c.

Here is the call graph for this function:

PHP_FUNCTION ( stream_filter_append  )

Definition at line 1256 of file streamsfuncs.c.

Here is the call graph for this function:

PHP_FUNCTION ( stream_filter_remove  )

Definition at line 1264 of file streamsfuncs.c.

{
       zval *zfilter;
       php_stream_filter *filter;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zfilter) == FAILURE) {
              RETURN_FALSE;
       }

       filter = zend_fetch_resource(&zfilter TSRMLS_CC, -1, NULL, NULL, 1, php_file_le_stream_filter());
       if (!filter) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid resource given, not a stream filter");
              RETURN_FALSE;
       }

       if (php_stream_filter_flush(filter, 1) == FAILURE) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to flush filter, not removing");
              RETURN_FALSE;
       }

       if (zend_list_delete(Z_LVAL_P(zfilter)) == FAILURE) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not invalidate filter, not removing");
              RETURN_FALSE;
       } else {
              php_stream_filter_remove(filter, 1 TSRMLS_CC);
              RETURN_TRUE;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_socket_enable_crypto  )

Definition at line 1450 of file streamsfuncs.c.

{
       long cryptokind = 0;
       zval *zstream, *zsessstream = NULL;
       php_stream *stream, *sessstream = NULL;
       zend_bool enable;
       int ret;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rb|lr", &zstream, &enable, &cryptokind, &zsessstream) == FAILURE) {
              RETURN_FALSE;
       }

       php_stream_from_zval(stream, &zstream);

       if (ZEND_NUM_ARGS() >= 3) {
              if (zsessstream) {
                     php_stream_from_zval(sessstream, &zsessstream);
              }

              if (php_stream_xport_crypto_setup(stream, cryptokind, sessstream TSRMLS_CC) < 0) {
                     RETURN_FALSE;
              }
       } else if (enable) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "When enabling encryption you must specify the crypto type");
              RETURN_FALSE;
       }

       ret = php_stream_xport_crypto_enable(stream, enable TSRMLS_CC);
       switch (ret) {
              case -1:
                     RETURN_FALSE;

              case 0:
                     RETURN_LONG(0);

              default:
                     RETURN_TRUE;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_socket_shutdown  )
PHP_FUNCTION ( stream_resolve_include_path  )

Definition at line 1493 of file streamsfuncs.c.

{
       char *filename, *resolved_path;
       int filename_len;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) {
              return;
       }

       resolved_path = zend_resolve_path(filename, filename_len TSRMLS_CC);

       if (resolved_path) {
              RETURN_STRING(resolved_path, 0);
       }
       RETURN_FALSE;
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_is_local  )

Definition at line 1513 of file streamsfuncs.c.

{
       zval **zstream;
       php_stream *stream = NULL;
       php_stream_wrapper *wrapper = NULL;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &zstream) == FAILURE) {
              RETURN_FALSE;
       }

       if (Z_TYPE_PP(zstream) == IS_RESOURCE) {
              php_stream_from_zval(stream, zstream);
              if (stream == NULL) {
                     RETURN_FALSE;
              }
              wrapper = stream->wrapper;
       } else {
              convert_to_string_ex(zstream);

              wrapper = php_stream_locate_url_wrapper(Z_STRVAL_PP(zstream), NULL, 0 TSRMLS_CC);
       }

       if (!wrapper) {
              RETURN_FALSE;
       }

       RETURN_BOOL(wrapper->is_url==0);
}

Here is the call graph for this function:

PHP_FUNCTION ( stream_supports_lock  )

Definition at line 1545 of file streamsfuncs.c.

{
       php_stream *stream;
       zval *zsrc;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsrc) == FAILURE) {
              RETURN_FALSE;
       }

       php_stream_from_zval(stream, &zsrc);

       if (!php_stream_supports_lock(stream)) {
              RETURN_FALSE;
       }

       RETURN_TRUE;
}

Here is the call graph for this function: