16 Commits
0.2.1 ... 0.2.7

Author SHA1 Message Date
michael
ea50047133 Fixed package version
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@304244 c90b9560-bf6c-de11-be94-00142212c4b1
2010-10-10 07:43:20 +00:00
michael
e16b06dede Fixed bug #18998 (Change expect.logfile on runtime leave file descriptor opened)
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@304243 c90b9560-bf6c-de11-be94-00142212c4b1
2010-10-10 07:37:35 +00:00
johannes
80e342cf6b s,function_entry,zend_function_entry,
As announced in http://news.php.net/php.pecl.dev/7123


git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@297236 c90b9560-bf6c-de11-be94-00142212c4b1
2010-03-31 20:39:48 +00:00
pajoye
3e030e95e6 - update to package.xml v2
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@290265 c90b9560-bf6c-de11-be94-00142212c4b1
2009-11-05 11:49:14 +00:00
gwynne
e4b08ad2de fix a huge number of wrong MIME types. UGH.
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@284003 c90b9560-bf6c-de11-be94-00142212c4b1
2009-07-13 12:15:13 +00:00
shire
ce1a540073 fixes with arginfo for php-5.3 compatability
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@276740 c90b9560-bf6c-de11-be94-00142212c4b1
2009-03-03 23:21:38 +00:00
michael
f85ba457db add new release 0.2.5
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@269920 c90b9560-bf6c-de11-be94-00142212c4b1
2008-11-27 10:13:57 +00:00
michael
b7d18cfbb9 Fixed bug #14768 (configure error in Ubuntu 8.04)
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@269919 c90b9560-bf6c-de11-be94-00142212c4b1
2008-11-27 10:10:11 +00:00
sfox
c5895a300f - Bring the majority of PECL extensions into line with macro/x.x.x versioning.
- Please use the -dev tag during the development cycle so that snapshots can easily be distinguished from releases.


git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@256435 c90b9560-bf6c-de11-be94-00142212c4b1
2008-03-31 09:37:00 +00:00
michael
925378d4ae adhere to C standard
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@244616 c90b9560-bf6c-de11-be94-00142212c4b1
2007-10-22 15:27:03 +00:00
michael
4e2f9109e1 Fixed Bug #6996 (Segmentation fault on expect_expectl)
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@244548 c90b9560-bf6c-de11-be94-00142212c4b1
2007-10-21 16:55:44 +00:00
michael
f6251794c5 Make expect stream non-seekable (avoid warnings)
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@244508 c90b9560-bf6c-de11-be94-00142212c4b1
2007-10-20 07:15:40 +00:00
michael
2246eef8d7 Fixed #12268 (Capturing output via exp_loguser from within PHP / Apache):
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@244507 c90b9560-bf6c-de11-be94-00142212c4b1
2007-10-20 06:50:37 +00:00
michael
50ecf39bfd - Allow proceeding with configuration, even if expect.h was not found
- Fix bug #5950 (fopen("expect://") leaves zombies)


git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@242353 c90b9560-bf6c-de11-be94-00142212c4b1
2007-09-09 15:43:36 +00:00
michael
41baa86ee3 New package with bugfix.
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@215802 c90b9560-bf6c-de11-be94-00142212c4b1
2006-07-05 14:53:16 +00:00
michael
c206870203 Fix segfault on scenario with EXP_TIMEOUT.
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@215801 c90b9560-bf6c-de11-be94-00142212c4b1
2006-07-05 14:51:56 +00:00
7 changed files with 209 additions and 64 deletions

View File

@@ -6,19 +6,20 @@ PHP_ARG_WITH(expect,for expect support,
[ --with-expect[=DIR] Include expect support (requires libexpect >= 5.43.0).])
if test "$PHP_EXPECT" != "no"; then
for i in $PHP_EXPECT /usr/local /usr ; do
if test -f $i/include/expect.h; then
LIBEXPECT_DIR=$i
for i in $PHP_EXPECT/include/expect.h $PHP_EXPECT/include/*/expect.h \
/usr/local/include/expect.h /usr/local/include/*/expect.h \
/usr/include/expect.h /usr/include/*/expect.h ;
do
if test -f $i; then
LIBEXPECT_INCLUDE_DIR=`dirname $i`
LIBEXPECT_DIR=`dirname $LIBEXPECT_INCLUDE_DIR`
break
fi
done
if test -z "$LIBEXPECT_DIR"; then
AC_MSG_ERROR(expect extension requires libexpect version >= 5.43.0)
fi
PHP_ADD_LIBRARY_WITH_PATH(expect, $LIBEXPECT_DIR/lib, EXPECT_SHARED_LIBADD)
PHP_ADD_INCLUDE($LIBEXPECT_DIR/include)
PHP_ADD_INCLUDE($LIBEXPECT_INCLUDE_DIR)
PHP_NEW_EXTENSION(expect, expect.c expect_fopen_wrapper.c, $ext_shared)
PHP_SUBST(EXPECT_SHARED_LIBADD)

View File

@@ -19,11 +19,23 @@
/* $ Id: $ */
#include "php_expect.h"
#include <string.h>
#include <errno.h>
ZEND_BEGIN_ARG_INFO_EX(arginfo_expect_popen, 0, 0, 1)
ZEND_ARG_INFO(0, command)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_expect_expectl, 0, 0, 2)
ZEND_ARG_INFO(0, stream)
ZEND_ARG_INFO(0, expect_cases)
ZEND_ARG_INFO(1, match)
ZEND_END_ARG_INFO()
/* {{{ expect_functions[] */
function_entry expect_functions[] = {
PHP_FE(expect_popen, NULL)
PHP_FE(expect_expectl, third_arg_force_ref)
zend_function_entry expect_functions[] = {
PHP_FE(expect_popen, arginfo_expect_popen)
PHP_FE(expect_expectl, arginfo_expect_expectl)
{ NULL, NULL, NULL }
};
/* }}} */
@@ -40,7 +52,7 @@ zend_module_entry expect_module_entry = {
NULL,
NULL,
PHP_MINFO(expect),
"0.1",
PHP_EXPECT_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* }}} */
@@ -49,6 +61,26 @@ zend_module_entry expect_module_entry = {
ZEND_GET_MODULE(expect)
#endif
ZEND_DECLARE_MODULE_GLOBALS(expect)
/* {{{ php_expect_init_globals
*/
static void php_expect_init_globals (zend_expect_globals *globals TSRMLS_DC)
{
globals->logfile_stream = NULL;
}
/* }}} */
/* {{{ php_expect_destroy_globals
*/
static void php_expect_destroy_globals(zend_expect_globals *globals TSRMLS_DC)
{
if (globals->logfile_stream) {
php_stream_close(globals->logfile_stream);
}
}
/* }}} */
/* {{{ PHP_INI_MH
* */
static PHP_INI_MH(OnSetExpectTimeout)
@@ -79,12 +111,25 @@ static PHP_INI_MH(OnSetExpectLogUser)
* */
static PHP_INI_MH(OnSetExpectLogFile)
{
if (EXPECT_G(logfile_stream)) {
php_stream_close(EXPECT_G(logfile_stream));
}
if (new_value_length > 0) {
exp_logfile = fopen (new_value, "a");
if (!exp_logfile) {
php_error_docref (NULL TSRMLS_CC, E_ERROR, "could not open log file for writting");
php_stream* stream = php_stream_open_wrapper (new_value, "a", 0, NULL);
if (!stream) {
php_error_docref (NULL TSRMLS_CC, E_ERROR, "could not open log file for writing");
return FAILURE;
}
stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
if (php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void **) &exp_logfile, REPORT_ERRORS) != SUCCESS) {
return FAILURE;
}
EXPECT_G(logfile_stream) = stream;
exp_logfile_all = 1;
} else {
EXPECT_G(logfile_stream) = NULL;
exp_logfile = NULL;
exp_logfile_all = 0;
}
return SUCCESS;
}
@@ -133,7 +178,8 @@ PHP_MSHUTDOWN_FUNCTION(expect)
PHP_MINFO_FUNCTION(expect)
{
php_info_print_table_start();
php_info_print_table_row(2, "Expect support", "enabled");
php_info_print_table_header(2, "Expect support", "enabled");
php_info_print_table_row(2, "Version", PHP_EXPECT_VERSION);
php_info_print_table_row(2, "Stream wrapper support", "expect://");
php_info_print_table_end();
@@ -151,6 +197,7 @@ PHP_FUNCTION(expect_popen)
int command_len;
FILE *fp;
php_stream *stream = NULL;
zval *z_pid;
if (ZEND_NUM_ARGS() != 1) { WRONG_PARAM_COUNT; }
@@ -164,6 +211,13 @@ PHP_FUNCTION(expect_popen)
if (!stream) {
RETURN_FALSE;
}
stream->flags |= PHP_STREAM_FLAG_NO_SEEK;
MAKE_STD_ZVAL (z_pid);
ZVAL_LONG (z_pid, exp_pid);
stream->wrapperdata = z_pid;
php_stream_to_zval(stream, return_value);
}
/* }}} */
@@ -187,9 +241,14 @@ PHP_FUNCTION(expect_expectl)
}
php_stream_from_zval (stream, &z_stream);
if (php_stream_cast (stream, PHP_STREAM_AS_FD, (void*)&fd, 1) != SUCCESS || fd < 0) {
php_error_docref (NULL TSRMLS_CC, E_ERROR, "couldn't cast expect stream to a file descriptor");
return;
if (!stream->wrapperdata) {
php_error_docref (NULL TSRMLS_CC, E_ERROR, "supplied argument is not a valid stream resource");
return;
}
if (php_stream_cast (stream, PHP_STREAM_AS_FD, (void*)&fd, REPORT_ERRORS) != SUCCESS || fd < 0) {
return;
}
argc = zend_hash_num_elements (Z_ARRVAL_P(z_cases));
@@ -255,10 +314,10 @@ PHP_FUNCTION(expect_expectl)
key = exp_expectv (fd, ecases);
int exp_match_len = exp_match_end - exp_match + 1;
int exp_match_len = exp_match_end - exp_match;
if (z_match && exp_match && exp_match_len > 0) {
char *tmp = (char *)emalloc (sizeof(char) * exp_match_len);
strlcpy (tmp, exp_match, exp_match_len);
char *tmp = (char *)emalloc (sizeof(char) * (exp_match_len + 1));
strlcpy (tmp, exp_match, exp_match_len + 1);
zval_dtor (z_match);
array_init(z_match);
add_index_string(z_match, 0, tmp, 1);
@@ -271,9 +330,9 @@ PHP_FUNCTION(expect_expectl)
and add matching substring to matches array */
for (i = 1; i <= 9; i++) {
if (matchedcase.re->startp[i] != NULL) {
int sub_match_len = matchedcase.re->endp[i] - matchedcase.re->startp[i] + 1;
char *sub_match = (char *)emalloc (sizeof(char) * sub_match_len);
strlcpy (sub_match, matchedcase.re->startp[i], sub_match_len);
int sub_match_len = matchedcase.re->endp[i] - matchedcase.re->startp[i];
char *sub_match = (char *)emalloc (sizeof(char) * (sub_match_len + 1));
strlcpy (sub_match, matchedcase.re->startp[i], sub_match_len + 1);
add_next_index_string(z_match, sub_match, 1);
efree (sub_match);
}

View File

@@ -21,26 +21,43 @@
#include "php.h"
#include "php_expect.h"
#include "php_streams.h"
#include <sys/wait.h>
php_stream *php_expect_stream_opener (php_stream_wrapper *wrapper, char *command, char *mode, int options,
php_stream *php_expect_stream_open (php_stream_wrapper *wrapper, char *command, char *mode, int options,
char **opened_command, php_stream_context *context STREAMS_DC TSRMLS_DC)
{
FILE *fp;
if (strncasecmp("expect://", command, sizeof("expect://")-1) == 0) {
command += sizeof("expect://")-1;
}
if ((fp = exp_popen(command)) != NULL) {
return php_stream_fopen_from_pipe (fp, "");
php_stream* stream = php_stream_fopen_from_pipe (fp, mode);
zval *z_pid;
MAKE_STD_ZVAL (z_pid);
ZVAL_LONG (z_pid, exp_pid);
stream->wrapperdata = z_pid;
return stream;
}
return NULL;
}
static int php_expect_stream_close (php_stream_wrapper *wrapper, php_stream *stream TSRMLS_DC)
{
zval* z_pid = stream->wrapperdata;
int s = 0;
waitpid (Z_LVAL_P(z_pid), &s, 0);
zval_ptr_dtor (&z_pid);
stream->wrapperdata = NULL;
return s;
}
/* }}} */
static php_stream_wrapper_ops php_expect_wrapper_ops = {
php_expect_stream_opener,
NULL, /* close */
php_expect_stream_open,
php_expect_stream_close, /* close */
NULL, /* stat */
NULL, /* stat_url */
NULL, /* opendir */

View File

@@ -1,35 +1,53 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0">
<package>
<name>expect</name>
<summary>PHP extension for expect library</summary>
<description>This extension allows to interact with processes through PTY, using expect library.</description>
<license>PHP License</license>
<maintainers>
<maintainer>
<user>michael</user>
<name>Michael Spector</name>
<email>michael@php.net</email>
</maintainer>
</maintainers>
<release>
<version>0.2.1</version>
<date>2006-07-04</date>
<state>beta</state>
<notes>1) Support returning match substrings in array.
2) Fix missing null-termination in returned match string.
</notes>
</release>
<filelist>
<dir role="doc" name="/">
<file role="src">config.m4</file>
<file role="src">expect.dsp</file>
<file role="src">config.w32</file>
<file role="src">expect.c</file>
<file role="src">expect_fopen_wrapper.c</file>
<file role="src">php_expect.h</file>
</dir>
</filelist>
<?xml version="1.0" encoding="UTF-8"?>
<package packagerversion="1.9.0" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
http://pear.php.net/dtd/tasks-1.0.xsd
http://pear.php.net/dtd/package-2.0
http://pear.php.net/dtd/package-2.0.xsd">
<name>expect</name>
<channel>pecl.php.net</channel>
<summary>PHP extension for expect library</summary>
<description>This extension allows to interact with processes through PTY, using expect library.
</description>
<lead>
<name>Michael Spector</name>
<user>michael</user>
<email>michael@php.net</email>
<active>yes</active>
</lead>
<date>2010-10-10</date>
<time>09:28:00</time>
<version>
<release>0.2.7</release>
<api>0.2.7</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
Fixed bug #18998 (Change expect.logfile on runtime leave file descriptor opened)
</notes>
<contents>
<dir name="/">
<file name="config.m4" role="src" />
<file name="config.w32" role="src" />
<file name="expect.c" role="src" />
<file name="expect.dsp" role="src" />
<file name="expect_fopen_wrapper.c" role="src" />
<file name="php_expect.h" role="src" />
</dir> <!-- / -->
</contents>
<dependencies>
<required>
<php>
<min>4.0.0</min>
</php>
<pearinstaller>
<min>1.4.0b1</min>
</pearinstaller>
</required>
</dependencies>
<providesextension>expect</providesextension>
<extsrcrelease />
</package>

View File

@@ -35,6 +35,8 @@
extern zend_module_entry expect_module_entry;
#define phpext_expect_ptr &expect_module_entry
#define PHP_EXPECT_VERSION "0.2.7-dev"
#ifdef PHP_WIN32
#define PHP_EXPECT_API __declspec(dllexport)
#else
@@ -50,6 +52,16 @@ PHP_FUNCTION(expect_expectl);
extern php_stream_wrapper php_expect_wrapper;
ZEND_BEGIN_MODULE_GLOBALS(expect)
php_stream* logfile_stream;
ZEND_END_MODULE_GLOBALS(expect)
#ifdef ZTS
#define EXPECT_G(v) TSRMG(expect_globals_id, zend_expect_globals *, v)
#else
#define EXPECT_G(v) (expect_globals.v)
#endif
#ifdef ZTS
#include "TSRM.h"
#endif /* ZTS */

24
tests/bug12268.phpt Normal file
View File

@@ -0,0 +1,24 @@
--TEST--
PECL Bug #12268 CGI
--SKIPIF--
<?php if (!extension_loaded("expect") || php_sapi_name() == 'cli') print "skip"; ?>
--INI--
expect.loguser=0
expect.logfile=php://output
--FILE--
<?php
if (php_sapi_name() == 'cli') exit;
$stream = expect_popen("echo Hello");
ob_start();
expect_expectl ($stream, array());
$r = ob_get_contents();
fclose ($stream);
print "Output: $r";
?>
--EXPECT--
Output: Hello

14
tests/bug6996.phpt Normal file
View File

@@ -0,0 +1,14 @@
--TEST--
PECL Bug #6996
--SKIPIF--
<?php if (!extension_loaded("expect")) print "skip"; ?>
--FILE--
<?php
$stream = popen ("expect://echo 2>/dev/null", "r");
expect_expectl ($stream, array());
fclose ($stream);
?>
--EXPECTF--
Fatal error: expect_expectl(): supplied argument is not a valid stream resource in %s on line %d