mirror of
https://github.com/php-win-ext/pecl-expect.git
synced 2026-03-24 05:02:05 +01:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41baa86ee3 | ||
|
|
c206870203 | ||
|
|
1ac4b57036 | ||
|
|
f2d7fbb1d1 | ||
|
|
d7abe0572c | ||
|
|
e33a147aef | ||
|
|
17d7c347b8 | ||
|
|
549a25aae3 | ||
|
|
45c984eb53 | ||
|
|
a0786b31c2 | ||
|
|
b6e7f4d085 | ||
|
|
ab6a35e71b | ||
|
|
269bc73f95 | ||
|
|
4deb2dcbaf |
21
config.m4
21
config.m4
@@ -3,32 +3,23 @@ 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
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if test -z "$LIBEXPECT_DIR"; then
|
||||
AC_MSG_ERROR(Cannot find libexpect)
|
||||
AC_MSG_ERROR(expect extension requires libexpect version >= 5.43.0)
|
||||
fi
|
||||
|
||||
LIBEXPECT_LIBDIR=$LIBEXPECT_DIR/lib
|
||||
PHP_ADD_LIBRARY_WITH_PATH(expect, $LIBEXPECT_DIR/lib, EXPECT_SHARED_LIBADD)
|
||||
PHP_ADD_INCLUDE($LIBEXPECT_DIR/include)
|
||||
|
||||
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
|
||||
|
||||
@@ -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");
|
||||
|
||||
54
expect.c
54
expect.c
@@ -23,7 +23,7 @@
|
||||
/* {{{ 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 }
|
||||
};
|
||||
/* }}} */
|
||||
@@ -49,12 +49,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 +64,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -163,19 +170,19 @@ PHP_FUNCTION(expect_popen)
|
||||
|
||||
|
||||
/* {{{
|
||||
* 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;
|
||||
}
|
||||
|
||||
@@ -198,7 +205,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 +255,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;
|
||||
|
||||
@@ -14,10 +14,11 @@
|
||||
</maintainers>
|
||||
|
||||
<release>
|
||||
<version>0.1</version>
|
||||
<date>2005-10-01</date>
|
||||
<version>0.2.2</version>
|
||||
<date>2006-07-05</date>
|
||||
<state>beta</state>
|
||||
<notes>Initial release. Try it out!</notes>
|
||||
<notes>Fix segfault on scenario with EXP_TIMEOUT.
|
||||
</notes>
|
||||
</release>
|
||||
|
||||
<filelist>
|
||||
|
||||
Reference in New Issue
Block a user