22 Commits
0.1 ... 0.2.5

Author SHA1 Message Date
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
michael
1ac4b57036 New package.
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@215725 c90b9560-bf6c-de11-be94-00142212c4b1
2006-07-04 08:33:55 +00:00
michael
f2d7fbb1d1 Return array of match substrings (according to the parentheses), instead of returning the whole string.
The whole match string can be found in array[0]. (thanks to Michael A.Logdon-Porter for this patch)


git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@215723 c90b9560-bf6c-de11-be94-00142212c4b1
2006-07-04 08:09:57 +00:00
michael
d7abe0572c Follow convention of using strlcpy(), instead of strncpy.
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@215677 c90b9560-bf6c-de11-be94-00142212c4b1
2006-07-02 08:45:16 +00:00
michael
e33a147aef Add null-termination to the result, if the orignal string doesn't have it.
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@215644 c90b9560-bf6c-de11-be94-00142212c4b1
2006-07-01 10:10:16 +00:00
michael
17d7c347b8 conform to C standard of variable declaration
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@207572 c90b9560-bf6c-de11-be94-00142212c4b1
2006-02-20 15:29:03 +00:00
michael
549a25aae3 added third parameter to expect_expectl that will return the exact match occurred
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@207506 c90b9560-bf6c-de11-be94-00142212c4b1
2006-02-19 14:56:25 +00:00
michael
45c984eb53 new package
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@200385 c90b9560-bf6c-de11-be94-00142212c4b1
2005-11-12 09:39:22 +00:00
michael
a0786b31c2 fixed #5941 (Segfault on INI handlers in ZTS mode)
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@200384 c90b9560-bf6c-de11-be94-00142212c4b1
2005-11-12 09:38:03 +00:00
michael
b6e7f4d085 fixed error message typo
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@198767 c90b9560-bf6c-de11-be94-00142212c4b1
2005-10-19 09:09:24 +00:00
michael
ab6a35e71b fixed OnUpdateLong for Zend Engine 1
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@197345 c90b9560-bf6c-de11-be94-00142212c4b1
2005-10-02 11:46:06 +00:00
michael
269bc73f95 fixed for situation, when there'are wrong library/header in /usr/, but we
really need other path, like: /usr/local/expect-...


git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@197344 c90b9560-bf6c-de11-be94-00142212c4b1
2005-10-02 11:43:18 +00:00
michael
4deb2dcbaf removed unneeded check for exp_popen
git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@197342 c90b9560-bf6c-de11-be94-00142212c4b1
2005-10-02 09:57:52 +00:00
8 changed files with 156 additions and 49 deletions

View File

@@ -3,32 +3,24 @@ dnl $Id$
dnl
PHP_ARG_WITH(expect,for expect support,
[ --with-expect[=DIR] Include expect support (requires libexpect).])
[ --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
LIBEXPECT_INCDIR=$i/include
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(Cannot find libexpect)
fi
PHP_ADD_LIBRARY_WITH_PATH(expect, $LIBEXPECT_DIR/lib, EXPECT_SHARED_LIBADD)
PHP_ADD_INCLUDE($LIBEXPECT_INCLUDE_DIR)
LIBEXPECT_LIBDIR=$LIBEXPECT_DIR/lib
PHP_CHECK_LIBRARY(expect, exp_popen,
[ AC_DEFINE(HAVE_LIBEXPECT, 1, "") ],
[ AC_MSG_ERROR(expect module requires libexpect.) ],
[ -L$LIBEXPECT_LIBDIR ]
)
PHP_ADD_LIBRARY_WITH_PATH(expect, $LIBEXPECT_LIBDIR, EXPECT_SHARED_LIBADD)
PHP_ADD_INCLUDE($LIBEXPECT_INCDIR)
PHP_SUBST(EXPECT_SHARED_LIBADD)
PHP_NEW_EXTENSION(expect, expect.c expect_fopen_wrapper.c, $ext_shared)
PHP_SUBST(EXPECT_SHARED_LIBADD)
fi

View File

@@ -4,8 +4,7 @@
ARG_WITH('expect' , 'expect support', 'no');
if (PHP_EXPECT != "no") {
if (CHECK_HEADER_ADD_INCLUDE("expect.h", "CFLAGS_EXPECT", PHP_EXPECT) &&
CHECK_LIB("expect.lib", "expect", PHP_EXPECT)) {
if (CHECK_HEADER_ADD_INCLUDE("expect.h", "CFLAGS_EXPECT", PHP_EXPECT) && CHECK_LIB("expect.lib", "expect", PHP_EXPECT)) {
EXTENSION("expect", "expect.c", PHP_EXPECT_SHARED, null, "php_expect.dll");
} else {
WARNING("expect not enabled; libraries and headers not found");

View File

@@ -19,11 +19,13 @@
/* $ Id: $ */
#include "php_expect.h"
#include <string.h>
#include <errno.h>
/* {{{ expect_functions[] */
function_entry expect_functions[] = {
PHP_FE(expect_popen, NULL)
PHP_FE(expect_expectl, NULL)
PHP_FE(expect_expectl, third_arg_force_ref)
{ NULL, NULL, NULL }
};
/* }}} */
@@ -40,7 +42,7 @@ zend_module_entry expect_module_entry = {
NULL,
NULL,
PHP_MINFO(expect),
"0.1",
PHP_EXPECT_VERSION,
STANDARD_MODULE_PROPERTIES
};
/* }}} */
@@ -49,12 +51,13 @@ zend_module_entry expect_module_entry = {
ZEND_GET_MODULE(expect)
#endif
/* {{{ PHP_INI_MH
* */
static PHP_INI_MH(OnSetExpectTimeout)
{
return OnUpdateLong (entry, new_value, new_value_length, &exp_timeout, mh_arg2, mh_arg3, stage TSRMLS_CC);
if (new_value) {
exp_timeout = atoi(new_value);
}
}
/* }}} */
@@ -63,7 +66,13 @@ static PHP_INI_MH(OnSetExpectTimeout)
* */
static PHP_INI_MH(OnSetExpectLogUser)
{
return OnUpdateBool (entry, new_value, new_value_length, &exp_loguser, mh_arg2, mh_arg3, stage TSRMLS_CC);
if (new_value) {
if (strncasecmp("on", new_value, sizeof("on"))) {
exp_loguser = atoi(new_value);
} else {
exp_loguser = 1;
}
}
}
/* }}} */
@@ -73,11 +82,19 @@ static PHP_INI_MH(OnSetExpectLogUser)
static PHP_INI_MH(OnSetExpectLogFile)
{
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;
}
exp_logfile_all = 1;
} else {
exp_logfile = NULL;
exp_logfile_all = 0;
}
return SUCCESS;
}
@@ -126,7 +143,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();
@@ -144,6 +162,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; }
@@ -157,32 +176,44 @@ 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);
}
/* }}} */
/* {{{
* proto mixed expect_expectl (resource stream, array expect_cases)
* proto mixed expect_expectl (resource stream, array expect_cases [, array match])
*/
PHP_FUNCTION(expect_expectl)
{
struct exp_case *ecases, *ec;
zval *z_stream, *z_cases, **z_case, **z_value;
struct exp_case *ecases, *ec, matchedcase;
zval *z_stream, *z_cases, *z_match=NULL, **z_case, **z_value;
php_stream *stream;
int fd, argc;
ulong key;
if (ZEND_NUM_ARGS() != 2) { WRONG_PARAM_COUNT; }
if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3) { WRONG_PARAM_COUNT; }
if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "ra", &z_stream, &z_cases) == FAILURE) {
if (zend_parse_parameters (ZEND_NUM_ARGS() TSRMLS_CC, "ra|z", &z_stream, &z_cases, &z_match) == FAILURE) {
return;
}
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));
@@ -198,7 +229,7 @@ PHP_FUNCTION(expect_expectl)
if (Z_TYPE_PP(z_case) != IS_ARRAY) {
efree (ecases);
php_error_docref (NULL TSRMLS_CC, E_ERROR, "expression case must be an array");
php_error_docref (NULL TSRMLS_CC, E_ERROR, "expect case must be an array");
return;
}
@@ -248,6 +279,33 @@ PHP_FUNCTION(expect_expectl)
key = exp_expectv (fd, ecases);
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 + 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);
/* Get case that was matched */
matchedcase = ecases[key];
/* If there are subpattern matches ... */
if (matchedcase.re->startp != NULL) {
int i;
/* iterate across all possible 9 subpatterns (a limitation of libexpect)
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];
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);
}
}
}
efree (tmp);
}
if (zend_hash_index_find (Z_ARRVAL_P(z_cases), key, (void **)&z_case) == SUCCESS) {
if (zend_hash_index_find(Z_ARRVAL_PP(z_case), 1, (void **)&z_value) == SUCCESS) {
*return_value = **z_value;

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

@@ -14,10 +14,11 @@
</maintainers>
<release>
<version>0.1</version>
<date>2005-10-01</date>
<version>0.2.5</version>
<date>2008-11-27</date>
<state>beta</state>
<notes>Initial release. Try it out!</notes>
<notes>Fixed bug #14768 (configure error in Ubuntu 8.04)
</notes>
</release>
<filelist>

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.5-dev"
#ifdef PHP_WIN32
#define PHP_EXPECT_API __declspec(dllexport)
#else

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