mirror of
https://github.com/php/php-src.git
synced 2024-09-24 03:17:26 +00:00
Clean up the function for the Zend API (php3, early php4 relics removed).
Use PF_INET, instead of AF_INET, if present. remove some code enclosed in #if 0 ... #endif that made no sense
This commit is contained in:
parent
fd7cf8dd7c
commit
6bc04c0858
@ -62,6 +62,14 @@
|
|||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef PF_INET
|
||||||
|
#define PF_INET AF_INET
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PF_UNIX
|
||||||
|
#define PF_UNIX AF_UNIX
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
@ -168,25 +176,25 @@ static void php_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
|
|||||||
switch(arg_count) {
|
switch(arg_count) {
|
||||||
case 5:
|
case 5:
|
||||||
convert_to_double_ex(args[4]);
|
convert_to_double_ex(args[4]);
|
||||||
conv = (unsigned long) ((*args[4])->value.dval * 1000000.0);
|
conv = (unsigned long) (Z_DVAL_PP(args[4]) * 1000000.0);
|
||||||
timeout.tv_sec = conv / 1000000;
|
timeout.tv_sec = conv / 1000000;
|
||||||
timeout.tv_usec = conv % 1000000;
|
timeout.tv_usec = conv % 1000000;
|
||||||
/* fall-through */
|
/* fall-through */
|
||||||
case 4:
|
case 4:
|
||||||
zval_dtor(*args[3]);
|
zval_ptr_dtor(args[3]);
|
||||||
ZVAL_STRING(*args[3], "", 1);
|
ZVAL_STRING(*args[3], "", 1);
|
||||||
/* fall-through */
|
/* fall-through */
|
||||||
case 3:
|
case 3:
|
||||||
zval_dtor(*args[2]);
|
zval_ptr_dtor(args[2]);
|
||||||
ZVAL_LONG(*args[2], 0);
|
ZVAL_LONG(*args[2], 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
convert_to_string_ex(args[0]);
|
convert_to_string_ex(args[0]);
|
||||||
convert_to_long_ex(args[1]);
|
convert_to_long_ex(args[1]);
|
||||||
portno = (unsigned short) (*args[1])->value.lval;
|
portno = (unsigned short) Z_LVAL_PP(args[1]);
|
||||||
|
|
||||||
key = emalloc((*args[0])->value.str.len + 10);
|
key = emalloc(Z_STRLEN_PP(args[0]) + 10);
|
||||||
sprintf(key, "%s:%d", (*args[0])->value.str.val, portno);
|
sprintf(key, "%s:%d", Z_STRVAL_PP(args[0]), portno);
|
||||||
|
|
||||||
if (persistent && zend_hash_find(&FG(ht_fsock_keys), key, strlen(key) + 1,
|
if (persistent && zend_hash_find(&FG(ht_fsock_keys), key, strlen(key) + 1,
|
||||||
(void *) &sockp) == SUCCESS) {
|
(void *) &sockp) == SUCCESS) {
|
||||||
@ -204,8 +212,7 @@ static void php_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
|
|||||||
udp = 1;
|
udp = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
socketd = socket(AF_INET, udp ? SOCK_DGRAM : SOCK_STREAM, 0);
|
socketd = socket(PF_INET, udp ? SOCK_DGRAM : SOCK_STREAM, 0);
|
||||||
|
|
||||||
if (socketd == SOCK_ERR) {
|
if (socketd == SOCK_ERR) {
|
||||||
CLOSE_SOCK(1);
|
CLOSE_SOCK(1);
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
@ -213,22 +220,22 @@ static void php_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
|
|||||||
|
|
||||||
server.sin_family = AF_INET;
|
server.sin_family = AF_INET;
|
||||||
|
|
||||||
if(php_lookup_hostname(udp ? &(*args[0])->value.str.val[6] : (*args[0])->value.str.val, &server.sin_addr)) {
|
if(php_lookup_hostname(udp ? &Z_STRVAL_PP(args[0])[6] : Z_STRVAL_PP(args[0]), &server.sin_addr)) {
|
||||||
CLOSE_SOCK(1);
|
CLOSE_SOCK(1);
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
server.sin_port = htons(portno);
|
server.sin_port = htons(portno);
|
||||||
|
|
||||||
if (php_connect_nonb(socketd, (struct sockaddr *)&server, sizeof(server), &timeout) == SOCK_CONN_ERR) {
|
if (php_connect_nonb(socketd, (struct sockaddr *) &server, sizeof(server), &timeout) == SOCK_CONN_ERR) {
|
||||||
CLOSE_SOCK(1);
|
CLOSE_SOCK(1);
|
||||||
|
|
||||||
if (arg_count>2) {
|
if (arg_count>2) {
|
||||||
zval_dtor(*args[2]);
|
zval_ptr_dtor(args[2]);
|
||||||
ZVAL_LONG(*args[2], errno);
|
ZVAL_LONG(*args[2], errno);
|
||||||
}
|
}
|
||||||
if (arg_count>3) {
|
if (arg_count>3) {
|
||||||
zval_dtor(*args[3]);
|
zval_ptr_dtor(args[3]);
|
||||||
ZVAL_STRING(*args[3], strerror(errno), 1);
|
ZVAL_STRING(*args[3], strerror(errno), 1);
|
||||||
}
|
}
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
@ -237,24 +244,24 @@ static void php_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
|
|||||||
} else {
|
} else {
|
||||||
/* Unix domain socket. s->strval is socket name. */
|
/* Unix domain socket. s->strval is socket name. */
|
||||||
struct sockaddr_un unix_addr;
|
struct sockaddr_un unix_addr;
|
||||||
socketd = socket(AF_UNIX, SOCK_STREAM, 0);
|
socketd = socket(PF_UNIX, SOCK_STREAM, 0);
|
||||||
if (socketd == SOCK_ERR) {
|
if (socketd == SOCK_ERR) {
|
||||||
CLOSE_SOCK(1);
|
CLOSE_SOCK(1);
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&unix_addr, (char)0, sizeof(unix_addr));
|
memset(&unix_addr, 0, sizeof(unix_addr));
|
||||||
unix_addr.sun_family = AF_UNIX;
|
unix_addr.sun_family = AF_UNIX;
|
||||||
strlcpy(unix_addr.sun_path, (*args[0])->value.str.val, sizeof(unix_addr.sun_path));
|
strlcpy(unix_addr.sun_path, Z_STRVAL_PP(args[0]), sizeof(unix_addr.sun_path));
|
||||||
|
|
||||||
if (php_connect_nonb(socketd, (struct sockaddr *) &unix_addr, sizeof(unix_addr), &timeout) == SOCK_CONN_ERR) {
|
if (php_connect_nonb(socketd, (struct sockaddr *) &unix_addr, sizeof(unix_addr), &timeout) == SOCK_CONN_ERR) {
|
||||||
CLOSE_SOCK(1);
|
CLOSE_SOCK(1);
|
||||||
if (arg_count>2) {
|
if (arg_count>2) {
|
||||||
zval_dtor(*args[2]);
|
zval_ptr_dtor(args[2]);
|
||||||
ZVAL_LONG(*args[2], errno);
|
ZVAL_LONG(*args[2], errno);
|
||||||
}
|
}
|
||||||
if (arg_count>3) {
|
if (arg_count>3) {
|
||||||
zval_dtor(*args[3]);
|
zval_ptr_dtor(args[3]);
|
||||||
ZVAL_STRING(*args[3], strerror(errno), 1);
|
ZVAL_STRING(*args[3], strerror(errno), 1);
|
||||||
}
|
}
|
||||||
RETURN_FALSE;
|
RETURN_FALSE;
|
||||||
@ -262,26 +269,16 @@ static void php_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
|
|||||||
#endif /* AF_UNIX */
|
#endif /* AF_UNIX */
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
*sock = socketd;
|
||||||
if ((fp = fdopen (socketd, "r+")) == NULL){
|
|
||||||
RETURN_LONG(-6); /* FIXME */
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_SETVBUF
|
|
||||||
if ((setvbuf(fp, NULL, _IONBF, 0)) != 0){
|
|
||||||
RETURN_LONG(-7); /* FIXME */
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
*sock=socketd;
|
|
||||||
if (persistent) {
|
if (persistent) {
|
||||||
zend_hash_update(&FG(ht_fsock_keys), key, strlen(key) + 1,
|
zend_hash_update(&FG(ht_fsock_keys), key, strlen(key) + 1,
|
||||||
sock, sizeof(*sock), NULL);
|
sock, sizeof(*sock), NULL);
|
||||||
zend_hash_update(&FG(ht_fsock_socks), (char *) sock, sizeof(*sock),
|
zend_hash_update(&FG(ht_fsock_socks), (char *) sock, sizeof(*sock),
|
||||||
key, strlen(key) + 1, NULL);
|
key, strlen(key) + 1, NULL);
|
||||||
}
|
}
|
||||||
if(key) efree(key);
|
|
||||||
|
if(key)
|
||||||
|
efree(key);
|
||||||
|
|
||||||
ZEND_REGISTER_RESOURCE(return_value, sock, php_file_le_socket());
|
ZEND_REGISTER_RESOURCE(return_value, sock, php_file_le_socket());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user