2000-10-13 00:09:31 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 15:32:16 +00:00
|
|
|
| PHP Version 4 |
|
2000-10-13 00:09:31 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 15:32:16 +00:00
|
|
|
| Copyright (c) 1997-2002 The PHP Group |
|
2000-10-13 00:09:31 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
|
|
|
| http://www.php.net/license/2_02.txt. |
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
2002-02-28 08:29:35 +00:00
|
|
|
| Authors: Rasmus Lerdorf <rasmus@php.net> |
|
2000-10-13 00:09:31 +00:00
|
|
|
| Jim Winstead <jimw@php.net> |
|
|
|
|
| Hartmut Holzgraefe <hholzgra@php.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2001-06-26 13:33:24 +00:00
|
|
|
#if HAVE_UNISTD_H
|
2001-06-22 07:07:48 +00:00
|
|
|
#include <unistd.h>
|
2001-06-26 13:33:24 +00:00
|
|
|
#endif
|
2000-10-13 00:09:31 +00:00
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include "php_globals.h"
|
|
|
|
#include "php_standard.h"
|
|
|
|
#include "php_fopen_wrappers.h"
|
2002-09-07 20:54:14 +00:00
|
|
|
#include "SAPI.h"
|
2000-10-13 00:09:31 +00:00
|
|
|
|
2002-09-07 19:00:46 +00:00
|
|
|
static size_t php_stream_output_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
|
|
|
|
{
|
|
|
|
PHPWRITE(buf, count);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t php_stream_output_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
|
|
|
|
{
|
2002-10-05 10:35:13 +00:00
|
|
|
stream->eof = 1;
|
2002-09-07 19:00:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int php_stream_output_close(php_stream *stream, int close_handle TSRMLS_DC)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int php_stream_output_flush(php_stream *stream TSRMLS_DC)
|
|
|
|
{
|
|
|
|
sapi_flush(TSRMLS_C);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
php_stream_ops php_stream_output_ops = {
|
|
|
|
php_stream_output_write,
|
|
|
|
php_stream_output_read,
|
|
|
|
php_stream_output_close,
|
|
|
|
php_stream_output_flush,
|
|
|
|
"Output",
|
2002-09-23 01:47:04 +00:00
|
|
|
NULL, /* seek */
|
|
|
|
NULL, /* cast */
|
|
|
|
NULL, /* stat */
|
|
|
|
NULL /* set_option */
|
2002-09-07 19:00:46 +00:00
|
|
|
};
|
|
|
|
|
2002-10-21 16:41:06 +00:00
|
|
|
static size_t php_stream_input_write(php_stream *stream, const char *buf, size_t count TSRMLS_DC)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t php_stream_input_read(php_stream *stream, char *buf, size_t count TSRMLS_DC)
|
|
|
|
{
|
2002-10-21 19:08:18 +00:00
|
|
|
size_t read_bytes = 0;
|
2002-10-21 16:41:06 +00:00
|
|
|
if(!stream->eof) {
|
2002-11-12 18:29:11 +00:00
|
|
|
if(SG(request_info).raw_post_data) { /* data has already been read by a post handler */
|
|
|
|
read_bytes = SG(request_info).raw_post_data_length - stream->position;
|
2002-10-21 16:41:06 +00:00
|
|
|
if(read_bytes <= count) {
|
|
|
|
stream->eof = 1;
|
|
|
|
} else {
|
|
|
|
read_bytes = count;
|
|
|
|
}
|
|
|
|
if(read_bytes) {
|
2002-11-12 18:29:11 +00:00
|
|
|
memcpy(buf, SG(request_info).raw_post_data + stream->position, read_bytes);
|
2002-10-21 16:41:06 +00:00
|
|
|
}
|
2002-11-12 18:29:11 +00:00
|
|
|
} else if(sapi_module.read_post) {
|
2002-10-21 16:41:06 +00:00
|
|
|
read_bytes = sapi_module.read_post(buf, count TSRMLS_CC);
|
|
|
|
if(read_bytes <= 0){
|
|
|
|
stream->eof = 1;
|
|
|
|
read_bytes = 0;
|
|
|
|
}
|
2002-11-12 18:29:11 +00:00
|
|
|
} else {
|
|
|
|
stream->eof = 1;
|
2002-10-21 16:41:06 +00:00
|
|
|
}
|
|
|
|
}
|
2002-10-21 19:08:18 +00:00
|
|
|
|
2002-11-21 10:29:11 +00:00
|
|
|
SG(read_post_bytes) += read_bytes;
|
2002-10-21 19:08:18 +00:00
|
|
|
return read_bytes;
|
2002-10-21 16:41:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int php_stream_input_close(php_stream *stream, int close_handle TSRMLS_DC)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int php_stream_input_flush(php_stream *stream TSRMLS_DC)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
php_stream_ops php_stream_input_ops = {
|
|
|
|
php_stream_input_write,
|
|
|
|
php_stream_input_read,
|
|
|
|
php_stream_input_close,
|
|
|
|
php_stream_input_flush,
|
|
|
|
"Input",
|
|
|
|
NULL, /* seek */
|
|
|
|
NULL, /* cast */
|
|
|
|
NULL, /* stat */
|
|
|
|
NULL /* set_option */
|
|
|
|
};
|
|
|
|
|
2002-04-11 12:13:17 +00:00
|
|
|
php_stream * php_stream_url_wrap_php(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC)
|
2000-10-13 00:09:31 +00:00
|
|
|
{
|
2002-03-15 21:03:08 +00:00
|
|
|
FILE * fp = NULL;
|
|
|
|
php_stream * stream = NULL;
|
2002-03-21 17:02:50 +00:00
|
|
|
|
|
|
|
if (!strncasecmp(path, "php://", 6))
|
|
|
|
path += 6;
|
2000-10-13 00:09:31 +00:00
|
|
|
|
2002-09-07 19:00:46 +00:00
|
|
|
if (!strcasecmp(path, "output")) {
|
|
|
|
return php_stream_alloc(&php_stream_output_ops, NULL, 0, "wb");
|
|
|
|
}
|
|
|
|
|
2002-10-21 16:41:06 +00:00
|
|
|
if (!strcasecmp(path, "input")) {
|
|
|
|
return php_stream_alloc(&php_stream_input_ops, NULL, 0, "rb");
|
2002-11-12 18:29:11 +00:00
|
|
|
}
|
2002-10-21 16:41:06 +00:00
|
|
|
|
2002-03-15 21:03:08 +00:00
|
|
|
if (!strcasecmp(path, "stdin")) {
|
|
|
|
fp = fdopen(dup(STDIN_FILENO), mode);
|
|
|
|
} else if (!strcasecmp(path, "stdout")) {
|
|
|
|
fp = fdopen(dup(STDOUT_FILENO), mode);
|
|
|
|
} else if (!strcasecmp(path, "stderr")) {
|
|
|
|
fp = fdopen(dup(STDERR_FILENO), mode);
|
2000-10-13 00:09:31 +00:00
|
|
|
}
|
2002-03-15 21:03:08 +00:00
|
|
|
|
|
|
|
if (fp) {
|
|
|
|
stream = php_stream_fopen_from_file(fp, mode);
|
|
|
|
if (stream == NULL)
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
return stream;
|
2000-10-13 00:09:31 +00:00
|
|
|
}
|
2002-03-15 21:03:08 +00:00
|
|
|
|
2002-03-24 18:05:49 +00:00
|
|
|
static php_stream_wrapper_ops php_stdio_wops = {
|
2002-03-15 21:03:08 +00:00
|
|
|
php_stream_url_wrap_php,
|
2002-09-26 10:14:41 +00:00
|
|
|
NULL, /* close */
|
|
|
|
NULL, /* fstat */
|
|
|
|
NULL, /* stat */
|
|
|
|
NULL, /* opendir */
|
|
|
|
"PHP"
|
2002-03-24 18:05:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
php_stream_wrapper php_stream_php_wrapper = {
|
|
|
|
&php_stdio_wops,
|
2002-04-16 22:14:27 +00:00
|
|
|
NULL,
|
|
|
|
0, /* is_url */
|
2002-03-15 21:03:08 +00:00
|
|
|
};
|
|
|
|
|
2001-06-05 13:12:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-09-09 13:29:31 +00:00
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
2001-06-05 13:12:10 +00:00
|
|
|
*/
|