mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
New Zend API
This commit is contained in:
parent
9d1c26481a
commit
00b2df7b8f
5 changed files with 85 additions and 83 deletions
|
@ -55,14 +55,14 @@ char *_php3_gethostbyname(char *name);
|
|||
Get the Internet host name corresponding to a given IP address */
|
||||
PHP_FUNCTION(gethostbyaddr)
|
||||
{
|
||||
pval *arg;
|
||||
pval **arg;
|
||||
|
||||
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
|
||||
if (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
convert_to_string(arg);
|
||||
convert_to_string_ex(arg);
|
||||
|
||||
return_value->value.str.val = _php3_gethostbyaddr(arg->value.str.val);
|
||||
return_value->value.str.val = _php3_gethostbyaddr((*arg)->value.str.val);
|
||||
return_value->value.str.len = strlen(return_value->value.str.val);
|
||||
return_value->type = IS_STRING;
|
||||
}
|
||||
|
@ -94,14 +94,14 @@ char *_php3_gethostbyaddr(char *ip)
|
|||
Get the IP address corresponding to a given Internet host name */
|
||||
PHP_FUNCTION(gethostbyname)
|
||||
{
|
||||
pval *arg;
|
||||
pval **arg;
|
||||
|
||||
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
|
||||
if (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
convert_to_string(arg);
|
||||
convert_to_string_ex(arg);
|
||||
|
||||
return_value->value.str.val = _php3_gethostbyname(arg->value.str.val);
|
||||
return_value->value.str.val = _php3_gethostbyname((*arg)->value.str.val);
|
||||
return_value->value.str.len = strlen(return_value->value.str.val);
|
||||
return_value->type = IS_STRING;
|
||||
}
|
||||
|
@ -111,30 +111,30 @@ PHP_FUNCTION(gethostbyname)
|
|||
Return a list of IP addresses that a given hostname resolves to. */
|
||||
PHP_FUNCTION(gethostbynamel)
|
||||
{
|
||||
pval *arg;
|
||||
pval **arg;
|
||||
struct hostent *hp;
|
||||
struct in_addr in;
|
||||
int i;
|
||||
|
||||
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
|
||||
if (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
convert_to_string(arg);
|
||||
convert_to_string_ex(arg);
|
||||
|
||||
if (array_init(return_value) == FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
hp = gethostbyname(arg->value.str.val);
|
||||
hp = gethostbyname((*arg)->value.str.val);
|
||||
if (hp == NULL || hp->h_addr_list == NULL) {
|
||||
#if DEBUG
|
||||
php_error(E_WARNING, "Unable to resolve %s\n", arg->value.str.val);
|
||||
php_error(E_WARNING, "Unable to resolve %s\n", (*arg)->value.str.val);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0 ; hp->h_addr_list[i] != 0 ; i++) {
|
||||
memcpy(&in.s_addr, hp->h_addr_list[i], sizeof(in.s_addr));
|
||||
in = *(struct in_addr *) hp->h_addr_list[i];
|
||||
add_next_index_string(return_value, inet_ntoa(in), 1);
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ char *_php3_gethostbyname(char *name)
|
|||
Check DNS records corresponding to a given Internet host name or IP address */
|
||||
PHP_FUNCTION(checkdnsrr)
|
||||
{
|
||||
pval *arg1,*arg2;
|
||||
pval **arg1,**arg2;
|
||||
int type,i;
|
||||
#ifndef MAXPACKET
|
||||
#define MAXPACKET 8192 /* max packet size used internally by BIND */
|
||||
|
@ -173,34 +173,34 @@ PHP_FUNCTION(checkdnsrr)
|
|||
|
||||
switch (ARG_COUNT(ht)) {
|
||||
case 1:
|
||||
if (getParameters(ht, 1, &arg1) == FAILURE) {
|
||||
if (getParametersEx(1, &arg1) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
type = T_MX;
|
||||
convert_to_string(arg1);
|
||||
convert_to_string_ex(arg1);
|
||||
break;
|
||||
case 2:
|
||||
if (getParameters(ht, 2, &arg1, &arg2) == FAILURE) {
|
||||
if (getParametersEx(2, &arg1, &arg2) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
convert_to_string(arg1);
|
||||
convert_to_string(arg2);
|
||||
if ( !strcasecmp("A",arg2->value.str.val) ) type = T_A;
|
||||
else if ( !strcasecmp("NS",arg2->value.str.val) ) type = T_NS;
|
||||
else if ( !strcasecmp("MX",arg2->value.str.val) ) type = T_MX;
|
||||
else if ( !strcasecmp("PTR",arg2->value.str.val) ) type = T_PTR;
|
||||
else if ( !strcasecmp("ANY",arg2->value.str.val) ) type = T_ANY;
|
||||
else if ( !strcasecmp("SOA",arg2->value.str.val) ) type = T_SOA;
|
||||
else if ( !strcasecmp("CNAME",arg2->value.str.val) ) type = T_CNAME;
|
||||
convert_to_string_ex(arg1);
|
||||
convert_to_string_ex(arg2);
|
||||
if ( !strcasecmp("A",(*arg2)->value.str.val) ) type = T_A;
|
||||
else if ( !strcasecmp("NS",(*arg2)->value.str.val) ) type = T_NS;
|
||||
else if ( !strcasecmp("MX",(*arg2)->value.str.val) ) type = T_MX;
|
||||
else if ( !strcasecmp("PTR",(*arg2)->value.str.val) ) type = T_PTR;
|
||||
else if ( !strcasecmp("ANY",(*arg2)->value.str.val) ) type = T_ANY;
|
||||
else if ( !strcasecmp("SOA",(*arg2)->value.str.val) ) type = T_SOA;
|
||||
else if ( !strcasecmp("CNAME",(*arg2)->value.str.val) ) type = T_CNAME;
|
||||
else {
|
||||
php_error(E_WARNING,"Type '%s' not supported",arg2->value.str.val);
|
||||
php_error(E_WARNING,"Type '%s' not supported",(*arg2)->value.str.val);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
i = res_search(arg1->value.str.val,C_IN,type,ans,sizeof(ans));
|
||||
i = res_search((*arg1)->value.str.val,C_IN,type,ans,sizeof(ans));
|
||||
if ( i < 0 ) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
|
|
@ -57,36 +57,36 @@ DLEXPORT php3_module_entry *get_module(void) { return &odbc_module_entry; }
|
|||
Send an email message */
|
||||
PHP_FUNCTION(mail)
|
||||
{
|
||||
pval *argv[4];
|
||||
pval **argv[4];
|
||||
char *to=NULL, *message=NULL, *headers=NULL, *subject=NULL;
|
||||
int argc;
|
||||
|
||||
argc = ARG_COUNT(ht);
|
||||
if (argc < 3 || argc > 4 || getParametersArray(ht, argc, argv) == FAILURE) {
|
||||
if (argc < 3 || argc > 4 || getParametersArrayEx(argc, argv) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
/* To: */
|
||||
convert_to_string(argv[0]);
|
||||
if (argv[0]->value.str.val) {
|
||||
to = argv[0]->value.str.val;
|
||||
convert_to_string_ex(argv[0]);
|
||||
if ((*argv[0])->value.str.val) {
|
||||
to = (*argv[0])->value.str.val;
|
||||
} else {
|
||||
php_error(E_WARNING, "No to field in mail command");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
/* Subject: */
|
||||
convert_to_string(argv[1]);
|
||||
if (argv[1]->value.str.val) {
|
||||
subject = argv[1]->value.str.val;
|
||||
convert_to_string_ex(argv[1]);
|
||||
if ((*argv[1])->value.str.val) {
|
||||
subject = (*argv[1])->value.str.val;
|
||||
} else {
|
||||
php_error(E_WARNING, "No subject field in mail command");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
/* message body */
|
||||
convert_to_string(argv[2]);
|
||||
if (argv[2]->value.str.val) {
|
||||
message = argv[2]->value.str.val;
|
||||
convert_to_string_ex(argv[2]);
|
||||
if ((*argv[2])->value.str.val) {
|
||||
message = (*argv[2])->value.str.val;
|
||||
} else {
|
||||
/* this is not really an error, so it is allowed. */
|
||||
php_error(E_WARNING, "No message string in mail command");
|
||||
|
@ -94,8 +94,8 @@ PHP_FUNCTION(mail)
|
|||
}
|
||||
|
||||
if (argc == 4) { /* other headers */
|
||||
convert_to_string(argv[3]);
|
||||
headers = argv[3]->value.str.val;
|
||||
convert_to_string_ex(argv[3]);
|
||||
headers = (*argv[3])->value.str.val;
|
||||
}
|
||||
|
||||
if (_php3_mail(to, subject, message, headers)){
|
||||
|
|
|
@ -205,19 +205,19 @@ static inline uint32 randomMT(void)
|
|||
Seeds random number generator */
|
||||
PHP_FUNCTION(srand)
|
||||
{
|
||||
pval *arg;
|
||||
pval **arg;
|
||||
|
||||
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
|
||||
if (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
convert_to_long(arg);
|
||||
convert_to_long_ex(arg);
|
||||
#ifdef HAVE_SRAND48
|
||||
srand48((unsigned int) arg->value.lval);
|
||||
srand48((unsigned int) (*arg)->value.lval);
|
||||
#else
|
||||
#ifdef HAVE_SRANDOM
|
||||
srandom((unsigned int) arg->value.lval);
|
||||
srandom((unsigned int) (*arg)->value.lval);
|
||||
#else
|
||||
srand((unsigned int) arg->value.lval);
|
||||
srand((unsigned int) (*arg)->value.lval);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
@ -227,12 +227,13 @@ PHP_FUNCTION(srand)
|
|||
Seeds Mersenne Twister random number generator */
|
||||
PHP_FUNCTION(mt_srand)
|
||||
{
|
||||
pval *arg;
|
||||
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
|
||||
pval **arg;
|
||||
|
||||
if (ARG_COUNT(ht) != 1 || getParametersEx(1, &arg) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
convert_to_long(arg);
|
||||
seedMT(arg->value.lval);
|
||||
convert_to_long_ex(arg);
|
||||
seedMT((*arg)->value.lval);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
@ -240,19 +241,19 @@ PHP_FUNCTION(mt_srand)
|
|||
Returns a random number */
|
||||
PHP_FUNCTION(rand)
|
||||
{
|
||||
pval *p_min=NULL, *p_max=NULL;
|
||||
pval **p_min=NULL, **p_max=NULL;
|
||||
|
||||
switch (ARG_COUNT(ht)) {
|
||||
case 0:
|
||||
break;
|
||||
case 2:
|
||||
if (getParameters(ht, 2, &p_min, &p_max)==FAILURE) {
|
||||
if (getParametersEx(2, &p_min, &p_max)==FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
convert_to_long(p_min);
|
||||
convert_to_long(p_max);
|
||||
if (p_max->value.lval-p_min->value.lval <= 0) {
|
||||
php_error(E_WARNING,"rand(): Invalid range: %ld..%ld", p_min->value.lval, p_max->value.lval);
|
||||
convert_to_long_ex(p_min);
|
||||
convert_to_long_ex(p_max);
|
||||
if ((*p_max)->value.lval-(*p_min)->value.lval <= 0) {
|
||||
php_error(E_WARNING,"rand(): Invalid range: %ld..%ld", (*p_min)->value.lval, (*p_max)->value.lval);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -296,8 +297,8 @@ PHP_FUNCTION(rand)
|
|||
* -RL
|
||||
*/
|
||||
if (p_min && p_max) { /* implement range */
|
||||
return_value->value.lval = p_min->value.lval +
|
||||
(int)((double)(p_max->value.lval - p_min->value.lval + 1) * return_value->value.lval/(PHP_RAND_MAX+1.0));
|
||||
return_value->value.lval = (*p_min)->value.lval +
|
||||
(int)((double)((*p_max)->value.lval - (*p_min)->value.lval + 1) * return_value->value.lval/(PHP_RAND_MAX+1.0));
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
@ -306,19 +307,19 @@ PHP_FUNCTION(rand)
|
|||
Returns a random number from Mersenne Twister */
|
||||
PHP_FUNCTION(mt_rand)
|
||||
{
|
||||
pval *p_min=NULL, *p_max=NULL;
|
||||
pval **p_min=NULL, **p_max=NULL;
|
||||
|
||||
switch (ARG_COUNT(ht)) {
|
||||
case 0:
|
||||
break;
|
||||
case 2:
|
||||
if (getParameters(ht, 2, &p_min, &p_max)==FAILURE) {
|
||||
if (getParametersEx(2, &p_min, &p_max)==FAILURE) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
convert_to_long(p_min);
|
||||
convert_to_long(p_max);
|
||||
if (p_max->value.lval-p_min->value.lval <= 0) {
|
||||
php_error(E_WARNING,"mtrand(): Invalid range: %ld..%ld", p_min->value.lval, p_max->value.lval);
|
||||
convert_to_long_ex(p_min);
|
||||
convert_to_long_ex(p_max);
|
||||
if ((*p_max)->value.lval-(*p_min)->value.lval <= 0) {
|
||||
php_error(E_WARNING,"mtrand(): Invalid range: %ld..%ld", (*p_min)->value.lval, (*p_max)->value.lval);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -338,8 +339,8 @@ PHP_FUNCTION(mt_rand)
|
|||
return_value->value.lval = (long)(randomMT() >> 1);
|
||||
|
||||
if (p_min && p_max) { /* implement range */
|
||||
return_value->value.lval = p_min->value.lval +
|
||||
(int)((double)(p_max->value.lval - p_min->value.lval + 1) * return_value->value.lval/(PHP_RAND_MAX+1.0));
|
||||
return_value->value.lval = (*p_min)->value.lval +
|
||||
(int)((double)((*p_max)->value.lval - (*p_min)->value.lval + 1) * return_value->value.lval/(PHP_RAND_MAX+1.0));
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
|
|
@ -30,7 +30,7 @@ PHP_FUNCTION(soundex)
|
|||
{
|
||||
char *somestring;
|
||||
int i, _small, len, code, last;
|
||||
pval *arg;
|
||||
pval *arg, **parg;
|
||||
char soundex[4 + 1];
|
||||
|
||||
static char soundex_table[26] =
|
||||
|
@ -61,10 +61,11 @@ PHP_FUNCTION(soundex)
|
|||
0, /* Y */
|
||||
'2'}; /* Z */
|
||||
|
||||
if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &arg) == FAILURE) {
|
||||
if (ARG_COUNT(ht) != 1 || getParametersEx(1, &parg) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
convert_to_string(arg);
|
||||
convert_to_string_ex(parg);
|
||||
arg = *parg;
|
||||
if (arg->value.str.len==0) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
|
|
@ -204,18 +204,18 @@ PHP_FUNCTION(define_syslog_variables)
|
|||
*/
|
||||
PHP_FUNCTION(openlog)
|
||||
{
|
||||
pval *ident, *option, *facility;
|
||||
if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &ident, &option, &facility) == FAILURE) {
|
||||
pval **ident, **option, **facility;
|
||||
if (ARG_COUNT(ht) != 3 || getParametersEx(3, &ident, &option, &facility) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
convert_to_string(ident);
|
||||
convert_to_long(option);
|
||||
convert_to_long(facility);
|
||||
convert_to_string_ex(ident);
|
||||
convert_to_long_ex(option);
|
||||
convert_to_long_ex(facility);
|
||||
if (syslog_device) {
|
||||
efree(syslog_device);
|
||||
}
|
||||
syslog_device = estrndup(ident->value.str.val,ident->value.str.len);
|
||||
openlog(syslog_device, option->value.lval, facility->value.lval);
|
||||
syslog_device = estrndup((*ident)->value.str.val,(*ident)->value.str.len);
|
||||
openlog(syslog_device, (*option)->value.lval, (*facility)->value.lval);
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
@ -237,20 +237,20 @@ PHP_FUNCTION(closelog)
|
|||
Generate a system log message */
|
||||
PHP_FUNCTION(syslog)
|
||||
{
|
||||
pval *priority, *message;
|
||||
pval **priority, **message;
|
||||
|
||||
if (ARG_COUNT(ht) != 2 || getParameters(ht, 2, &priority, &message) == FAILURE) {
|
||||
if (ARG_COUNT(ht) != 2 || getParametersEx(2, &priority, &message) == FAILURE) {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
convert_to_long(priority);
|
||||
convert_to_string(message);
|
||||
convert_to_long_ex(priority);
|
||||
convert_to_string_ex(message);
|
||||
|
||||
/*
|
||||
* CAVEAT: if the message contains patterns such as "%s",
|
||||
* this will cause problems.
|
||||
*/
|
||||
|
||||
syslog(priority->value.lval, message->value.str.val);
|
||||
syslog((*priority)->value.lval, (*message)->value.str.val);
|
||||
RETURN_TRUE;
|
||||
}
|
||||
/* }}} */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue