diff options
Diffstat (limited to 'ext/sockets')
34 files changed, 1238 insertions, 879 deletions
diff --git a/ext/sockets/config.m4 b/ext/sockets/config.m4 index a5a63dfb61..cea27000cf 100644 --- a/ext/sockets/config.m4 +++ b/ext/sockets/config.m4 @@ -56,6 +56,6 @@ if test "$PHP_SOCKETS" != "no"; then AC_DEFINE(HAVE_AI_V4MAPPED,1,[Whether you have AI_V4MAPPED]) fi - PHP_NEW_EXTENSION([sockets], [sockets.c multicast.c conversions.c sockaddr_conv.c sendrecvmsg.c], [$ext_shared]) + PHP_NEW_EXTENSION([sockets], [sockets.c multicast.c conversions.c sockaddr_conv.c sendrecvmsg.c], [$ext_shared],, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) PHP_INSTALL_HEADERS([ext/sockets/], [php_sockets.h]) fi diff --git a/ext/sockets/config.w32 b/ext/sockets/config.w32 index aeaa8ed425..e6c4cfea68 100644 --- a/ext/sockets/config.w32 +++ b/ext/sockets/config.w32 @@ -7,9 +7,9 @@ if (PHP_SOCKETS != "no") { if (CHECK_LIB("ws2_32.lib", "sockets", PHP_SOCKETS) && CHECK_LIB("Iphlpapi.lib", "sockets", PHP_SOCKETS) && CHECK_HEADER_ADD_INCLUDE("winsock.h", "CFLAGS_SOCKETS")) { - EXTENSION('sockets', 'sockets.c multicast.c conversions.c sockaddr_conv.c sendrecvmsg.c'); + EXTENSION('sockets', 'sockets.c multicast.c conversions.c sockaddr_conv.c sendrecvmsg.c', PHP_SOCKETS_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); AC_DEFINE('HAVE_SOCKETS', 1); - PHP_INSTALL_HEADERS("ext/sockets", "php_sockets.h"); + PHP_INSTALL_HEADERS("ext/sockets", "php_sockets.h windows_common.h"); } else { WARNING("sockets not enabled; libraries and headers not found"); } diff --git a/ext/sockets/conversions.c b/ext/sockets/conversions.c index eeec99f358..f2621f65d0 100644 --- a/ext/sockets/conversions.c +++ b/ext/sockets/conversions.c @@ -6,7 +6,7 @@ #endif #include <Zend/zend_llist.h> -#include <ext/standard/php_smart_str.h> +#include <zend_smart_str.h> #ifndef PHP_WIN32 # include <sys/types.h> @@ -106,9 +106,9 @@ const struct key_value empty_key_value_list[] = {{0}}; /* PARAMETERS */ static int param_get_bool(void *ctx, const char *key, int def) { - int **elem; - if (zend_hash_find(ctx, key, strlen(key) + 1, (void**)&elem) == SUCCESS) { - return **elem; + int *elem; + if ((elem = zend_hash_str_find_ptr(ctx, key, strlen(key))) != NULL) { + return *elem; } else { return def; } @@ -159,8 +159,8 @@ static void do_from_to_zval_err(struct err_s *err, smart_str_appends(&path, " > "); } - if (path.len > 3) { - path.len -= 3; + if (path.s && ZSTR_LEN(path.s) > 3) { + ZSTR_LEN(path.s) -= 3; } smart_str_0(&path); @@ -170,12 +170,12 @@ static void do_from_to_zval_err(struct err_s *err, err->level = E_WARNING; spprintf(&err->msg, 0, "error converting %s data (path: %s): %.*s", what_conv, - path.c && path.c != '\0' ? path.c : "unavailable", + path.s && *ZSTR_VAL(path.s) != '\0' ? ZSTR_VAL(path.s) : "unavailable", user_msg_size, user_msg); err->should_free = 1; efree(user_msg); - smart_str_free_ex(&path, 0); + smart_str_free(&path); } ZEND_ATTRIBUTE_FORMAT(printf, 2 ,3) static void do_from_zval_err(ser_context *ctx, const char *fmt, ...) @@ -196,10 +196,10 @@ static void do_to_zval_err(res_context *ctx, const char *fmt, ...) va_end(ap); } -void err_msg_dispose(struct err_s *err TSRMLS_DC) +void err_msg_dispose(struct err_s *err) { if (err->msg != NULL) { - php_error_docref0(NULL TSRMLS_CC, err->level, "%s", err->msg); + php_error_docref0(NULL, err->level, "%s", err->msg); if (err->should_free) { efree(err->msg); } @@ -213,21 +213,18 @@ void allocations_dispose(zend_llist **allocations) } static unsigned from_array_iterate(const zval *arr, - void (*func)(zval **elem, unsigned i, void **args, ser_context *ctx), + void (*func)(zval *elem, unsigned i, void **args, ser_context *ctx), void **args, ser_context *ctx) { - HashPosition pos; unsigned i; - zval **elem; + zval *elem; char buf[sizeof("element #4294967295")]; char *bufp = buf; /* Note i starts at 1, not 0! */ - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos), i = 1; - !ctx->err.has_error - && zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **)&elem, &pos) == SUCCESS; - zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos), i++) { + i = 1; + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arr), elem) { if (snprintf(buf, sizeof(buf), "element #%u", i) >= sizeof(buf)) { memcpy(buf, "element", sizeof("element")); } @@ -236,7 +233,11 @@ static unsigned from_array_iterate(const zval *arr, func(elem, i, args, ctx); zend_llist_remove_tail(&ctx->keys); - } + if (ctx->err.has_error) { + break; + } + i++; + } ZEND_HASH_FOREACH_END(); return i -1; } @@ -248,15 +249,15 @@ static void from_zval_write_aggregation(const zval *container, ser_context *ctx) { const field_descriptor *descr; - zval **elem; + zval *elem; if (Z_TYPE_P(container) != IS_ARRAY) { do_from_zval_err(ctx, "%s", "expected an array here"); } for (descr = descriptors; descr->name != NULL && !ctx->err.has_error; descr++) { - if (zend_hash_find(Z_ARRVAL_P(container), - descr->name, descr->name_size, (void**)&elem) == SUCCESS) { + if ((elem = zend_hash_str_find(Z_ARRVAL_P(container), + descr->name, descr->name_size - 1)) != NULL) { if (descr->from_zval == NULL) { do_from_zval_err(ctx, "No information on how to convert value " @@ -265,7 +266,7 @@ static void from_zval_write_aggregation(const zval *container, } zend_llist_add_element(&ctx->keys, (void*)&descr->name); - descr->from_zval(*elem, ((char*)structure) + descr->field_offset, ctx); + descr->from_zval(elem, ((char*)structure) + descr->field_offset, ctx); zend_llist_remove_tail(&ctx->keys); } else if (descr->required) { @@ -285,7 +286,7 @@ static void to_zval_read_aggregation(const char *structure, assert(Z_ARRVAL_P(zarr) != NULL); for (descr = descriptors; descr->name != NULL && !ctx->err.has_error; descr++) { - zval *new_zv; + zval *new_zv, tmp; if (descr->to_zval == NULL) { do_to_zval_err(ctx, "No information on how to convert native " @@ -293,8 +294,8 @@ static void to_zval_read_aggregation(const char *structure, break; } - ALLOC_INIT_ZVAL(new_zv); - add_assoc_zval_ex(zarr, descr->name, descr->name_size, new_zv); + ZVAL_NULL(&tmp); + new_zv = zend_symtable_str_update(Z_ARRVAL_P(zarr), descr->name, descr->name_size - 1, &tmp); zend_llist_add_element(&ctx->keys, (void*)&descr->name); descr->to_zval(structure + descr->field_offset, new_zv, ctx); @@ -303,14 +304,14 @@ static void to_zval_read_aggregation(const char *structure, } /* CONVERSIONS for integers */ -static long from_zval_integer_common(const zval *arr_value, ser_context *ctx) +static zend_long from_zval_integer_common(const zval *arr_value, ser_context *ctx) { - long ret = 0; - zval lzval = zval_used_for_init; + zend_long ret = 0; + zval lzval; + ZVAL_NULL(&lzval); if (Z_TYPE_P(arr_value) != IS_LONG) { - ZVAL_COPY_VALUE(&lzval, arr_value); - zval_copy_ctor(&lzval); + ZVAL_COPY(&lzval, (zval *)arr_value); arr_value = &lzval; } @@ -328,7 +329,7 @@ double_case: case IS_OBJECT: case IS_STRING: { - long lval; + zend_long lval; double dval; convert_to_string(&lzval); @@ -336,14 +337,12 @@ double_case: switch (is_numeric_string(Z_STRVAL(lzval), Z_STRLEN(lzval), &lval, &dval, 0)) { case IS_DOUBLE: zval_dtor(&lzval); - Z_TYPE(lzval) = IS_DOUBLE; - Z_DVAL(lzval) = dval; + ZVAL_DOUBLE(&lzval, dval); goto double_case; case IS_LONG: zval_dtor(&lzval); - Z_TYPE(lzval) = IS_LONG; - Z_LVAL(lzval) = lval; + ZVAL_LONG(&lzval, lval); goto long_case; } @@ -365,7 +364,7 @@ double_case: } void from_zval_write_int(const zval *arr_value, char *field, ser_context *ctx) { - long lval; + zend_long lval; int ival; lval = from_zval_integer_common(arr_value, ctx); @@ -384,7 +383,7 @@ void from_zval_write_int(const zval *arr_value, char *field, ser_context *ctx) } static void from_zval_write_uint32(const zval *arr_value, char *field, ser_context *ctx) { - long lval; + zend_long lval; uint32_t ival; lval = from_zval_integer_common(arr_value, ctx); @@ -392,7 +391,7 @@ static void from_zval_write_uint32(const zval *arr_value, char *field, ser_conte return; } - if (sizeof(long) > sizeof(uint32_t) && (lval < 0 || lval > 0xFFFFFFFF)) { + if (sizeof(zend_long) > sizeof(uint32_t) && (lval < 0 || lval > 0xFFFFFFFF)) { do_from_zval_err(ctx, "%s", "given PHP integer is out of bounds " "for an unsigned 32-bit integer"); return; @@ -403,7 +402,7 @@ static void from_zval_write_uint32(const zval *arr_value, char *field, ser_conte } static void from_zval_write_net_uint16(const zval *arr_value, char *field, ser_context *ctx) { - long lval; + zend_long lval; uint16_t ival; lval = from_zval_integer_common(arr_value, ctx); @@ -422,7 +421,7 @@ static void from_zval_write_net_uint16(const zval *arr_value, char *field, ser_c } static void from_zval_write_sa_family(const zval *arr_value, char *field, ser_context *ctx) { - long lval; + zend_long lval; sa_family_t ival; lval = from_zval_integer_common(arr_value, ctx); @@ -441,7 +440,7 @@ static void from_zval_write_sa_family(const zval *arr_value, char *field, ser_co } static void from_zval_write_pid_t(const zval *arr_value, char *field, ser_context *ctx) { - long lval; + zend_long lval; pid_t ival; lval = from_zval_integer_common(arr_value, ctx); @@ -460,7 +459,7 @@ static void from_zval_write_pid_t(const zval *arr_value, char *field, ser_contex } static void from_zval_write_uid_t(const zval *arr_value, char *field, ser_context *ctx) { - long lval; + zend_long lval; uid_t ival; lval = from_zval_integer_common(arr_value, ctx); @@ -470,13 +469,13 @@ static void from_zval_write_uid_t(const zval *arr_value, char *field, ser_contex /* uid_t can be signed or unsigned (generally unsigned) */ if ((uid_t)-1 > (uid_t)0) { - if (sizeof(long) > sizeof(uid_t) && (lval < 0 || (uid_t)lval != lval)) { + if (sizeof(zend_long) > sizeof(uid_t) && (lval < 0 || (uid_t)lval != lval)) { do_from_zval_err(ctx, "%s", "given PHP integer is out of bounds " "for a uid_t value"); return; } } else { - if (sizeof(long) > sizeof(uid_t) && (uid_t)lval != lval) { + if (sizeof(zend_long) > sizeof(uid_t) && (uid_t)lval != lval) { do_from_zval_err(ctx, "%s", "given PHP integer is out of bounds " "for a uid_t value"); return; @@ -492,49 +491,49 @@ void to_zval_read_int(const char *data, zval *zv, res_context *ctx) int ival; memcpy(&ival, data, sizeof(ival)); - ZVAL_LONG(zv, (long)ival); + ZVAL_LONG(zv, (zend_long)ival); } static void to_zval_read_unsigned(const char *data, zval *zv, res_context *ctx) { unsigned ival; memcpy(&ival, data, sizeof(ival)); - ZVAL_LONG(zv, (long)ival); + ZVAL_LONG(zv, (zend_long)ival); } static void to_zval_read_net_uint16(const char *data, zval *zv, res_context *ctx) { uint16_t ival; memcpy(&ival, data, sizeof(ival)); - ZVAL_LONG(zv, (long)ntohs(ival)); + ZVAL_LONG(zv, (zend_long)ntohs(ival)); } static void to_zval_read_uint32(const char *data, zval *zv, res_context *ctx) { uint32_t ival; memcpy(&ival, data, sizeof(ival)); - ZVAL_LONG(zv, (long)ival); + ZVAL_LONG(zv, (zend_long)ival); } static void to_zval_read_sa_family(const char *data, zval *zv, res_context *ctx) { sa_family_t ival; memcpy(&ival, data, sizeof(ival)); - ZVAL_LONG(zv, (long)ival); + ZVAL_LONG(zv, (zend_long)ival); } static void to_zval_read_pid_t(const char *data, zval *zv, res_context *ctx) { pid_t ival; memcpy(&ival, data, sizeof(ival)); - ZVAL_LONG(zv, (long)ival); + ZVAL_LONG(zv, (zend_long)ival); } static void to_zval_read_uid_t(const char *data, zval *zv, res_context *ctx) { uid_t ival; memcpy(&ival, data, sizeof(ival)); - ZVAL_LONG(zv, (long)ival); + ZVAL_LONG(zv, (zend_long)ival); } /* CONVERSIONS for sockaddr */ @@ -542,35 +541,28 @@ static void from_zval_write_sin_addr(const zval *zaddr_str, char *inaddr, ser_co { int res; struct sockaddr_in saddr = {0}; - zval lzval = zval_used_for_init; - TSRMLS_FETCH(); + zend_string *addr_str; - if (Z_TYPE_P(zaddr_str) != IS_STRING) { - ZVAL_COPY_VALUE(&lzval, zaddr_str); - zval_copy_ctor(&lzval); - convert_to_string(&lzval); - zaddr_str = &lzval; - } - - res = php_set_inet_addr(&saddr, Z_STRVAL_P(zaddr_str), ctx->sock TSRMLS_CC); + addr_str = zval_get_string((zval *) zaddr_str); + res = php_set_inet_addr(&saddr, ZSTR_VAL(addr_str), ctx->sock); if (res) { memcpy(inaddr, &saddr.sin_addr, sizeof saddr.sin_addr); } else { /* error already emitted, but let's emit another more relevant */ do_from_zval_err(ctx, "could not resolve address '%s' to get an AF_INET " - "address", Z_STRVAL_P(zaddr_str)); + "address", ZSTR_VAL(addr_str)); } - zval_dtor(&lzval); + zend_string_release(addr_str); } static void to_zval_read_sin_addr(const char *data, zval *zv, res_context *ctx) { const struct in_addr *addr = (const struct in_addr *)data; socklen_t size = INET_ADDRSTRLEN; + zend_string *str = zend_string_alloc(size - 1, 0); + memset(ZSTR_VAL(str), '\0', size); - Z_TYPE_P(zv) = IS_STRING; - Z_STRVAL_P(zv) = ecalloc(1, size); - Z_STRLEN_P(zv) = 0; + ZVAL_NEW_STR(zv, str); if (inet_ntop(AF_INET, addr, Z_STRVAL_P(zv), size) == NULL) { do_to_zval_err(ctx, "could not convert IPv4 address to string " @@ -599,18 +591,10 @@ static void from_zval_write_sin6_addr(const zval *zaddr_str, char *addr6, ser_co { int res; struct sockaddr_in6 saddr6 = {0}; - zval lzval = zval_used_for_init; - TSRMLS_FETCH(); - - if (Z_TYPE_P(zaddr_str) != IS_STRING) { - ZVAL_COPY_VALUE(&lzval, zaddr_str); - zval_copy_ctor(&lzval); - convert_to_string(&lzval); - zaddr_str = &lzval; - } + zend_string *addr_str; - res = php_set_inet6_addr(&saddr6, - Z_STRVAL_P(zaddr_str), ctx->sock TSRMLS_CC); + addr_str = zval_get_string((zval *) zaddr_str); + res = php_set_inet6_addr(&saddr6, ZSTR_VAL(addr_str), ctx->sock); if (res) { memcpy(addr6, &saddr6.sin6_addr, sizeof saddr6.sin6_addr); } else { @@ -619,16 +603,17 @@ static void from_zval_write_sin6_addr(const zval *zaddr_str, char *addr6, ser_co "address", Z_STRVAL_P(zaddr_str)); } - zval_dtor(&lzval); + zend_string_release(addr_str); } static void to_zval_read_sin6_addr(const char *data, zval *zv, res_context *ctx) { const struct in6_addr *addr = (const struct in6_addr *)data; socklen_t size = INET6_ADDRSTRLEN; + zend_string *str = zend_string_alloc(size - 1, 0); + + memset(ZSTR_VAL(str), '\0', size); - Z_TYPE_P(zv) = IS_STRING; - Z_STRVAL_P(zv) = ecalloc(1, size); - Z_STRLEN_P(zv) = 0; + ZVAL_NEW_STR(zv, str); if (inet_ntop(AF_INET6, addr, Z_STRVAL_P(zv), size) == NULL) { do_to_zval_err(ctx, "could not convert IPv6 address to string " @@ -657,33 +642,28 @@ static void to_zval_read_sockaddr_in6(const char *data, zval *zv, res_context *c #endif /* HAVE_IPV6 */ static void from_zval_write_sun_path(const zval *path, char *sockaddr_un_c, ser_context *ctx) { - zval lzval = zval_used_for_init; + zend_string *path_str; struct sockaddr_un *saddr = (struct sockaddr_un*)sockaddr_un_c; - if (Z_TYPE_P(path) != IS_STRING) { - ZVAL_COPY_VALUE(&lzval, path); - zval_copy_ctor(&lzval); - convert_to_string(&lzval); - path = &lzval; - } + path_str = zval_get_string((zval *) path); /* code in this file relies on the path being nul terminated, even though * this is not required, at least on linux for abstract paths. It also * assumes that the path is not empty */ - if (Z_STRLEN_P(path) == 0) { + if (ZSTR_LEN(path_str) == 0) { do_from_zval_err(ctx, "%s", "the path is cannot be empty"); return; } - if (Z_STRLEN_P(path) >= sizeof(saddr->sun_path)) { + if (ZSTR_LEN(path_str) >= sizeof(saddr->sun_path)) { do_from_zval_err(ctx, "the path is too long, the maximum permitted " "length is %ld", sizeof(saddr->sun_path) - 1); return; } - memcpy(&saddr->sun_path, Z_STRVAL_P(path), Z_STRLEN_P(path)); - saddr->sun_path[Z_STRLEN_P(path)] = '\0'; + memcpy(&saddr->sun_path, ZSTR_VAL(path_str), ZSTR_LEN(path_str)); + saddr->sun_path[ZSTR_LEN(path_str)] = '\0'; - zval_dtor(&lzval); + zend_string_release(path_str); } static void to_zval_read_sun_path(const char *data, zval *zv, res_context *ctx) { struct sockaddr_un *saddr = (struct sockaddr_un*)data; @@ -695,7 +675,7 @@ static void to_zval_read_sun_path(const char *data, zval *zv, res_context *ctx) return; } - ZVAL_STRINGL(zv, saddr->sun_path, nul_pos - (char*)&saddr->sun_path, 1); + ZVAL_STRINGL(zv, saddr->sun_path, nul_pos - (char*)&saddr->sun_path); } static const field_descriptor descriptors_sockaddr_un[] = { {"family", sizeof("family"), 0, offsetof(struct sockaddr_un, sun_family), from_zval_write_sa_family, to_zval_read_sa_family}, @@ -716,7 +696,7 @@ static void from_zval_write_sockaddr_aux(const zval *container, ser_context *ctx) { int family; - zval **elem; + zval *elem; int fill_sockaddr; if (Z_TYPE_P(container) != IS_ARRAY) { @@ -726,11 +706,11 @@ static void from_zval_write_sockaddr_aux(const zval *container, fill_sockaddr = param_get_bool(ctx, KEY_FILL_SOCKADDR, 1); - if (zend_hash_find(Z_ARRVAL_P(container), "family", sizeof("family"), (void**)&elem) == SUCCESS - && Z_TYPE_PP(elem) != IS_NULL) { + if ((elem = zend_hash_str_find(Z_ARRVAL_P(container), "family", sizeof("family") - 1)) != NULL + && Z_TYPE_P(elem) != IS_NULL) { const char *node = "family"; zend_llist_add_element(&ctx->keys, &node); - from_zval_write_int(*elem, (char*)&family, ctx); + from_zval_write_int(elem, (char*)&family, ctx); zend_llist_remove_tail(&ctx->keys); } else { family = ctx->sock->type; @@ -889,14 +869,13 @@ static void from_zval_write_control(const zval *arr, } if (entry->calc_space) { - zval **data_elem; + zval *data_elem; /* arr must be an array at this point */ - if (zend_hash_find(Z_ARRVAL_P(arr), "data", sizeof("data"), - (void**)&data_elem) == FAILURE) { + if ((data_elem = zend_hash_str_find(Z_ARRVAL_P(arr), "data", sizeof("data") - 1)) == NULL) { do_from_zval_err(ctx, "cmsghdr should have a 'data' element here"); return; } - data_len = entry->calc_space(*data_elem, ctx); + data_len = entry->calc_space(data_elem, ctx); if (ctx->err.has_error) { return; } @@ -926,11 +905,10 @@ static void from_zval_write_control(const zval *arr, } static void from_zval_write_control_array(const zval *arr, char *msghdr_c, ser_context *ctx) { - HashPosition pos; char buf[sizeof("element #4294967295")]; char *bufp = buf; - zval **elem; - uint32_t i; + zval *elem; + uint32_t i = 0; int num_elems; void *control_buf; zend_llist_element *alloc; @@ -954,21 +932,20 @@ static void from_zval_write_control_array(const zval *arr, char *msghdr_c, ser_c control_len = (size_t)num_elems * CMSG_SPACE(20); cur_offset = 0; - for (zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos), i = 0; - !ctx->err.has_error - && zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **)&elem, &pos) == SUCCESS; - zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos)) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(arr), elem) { + if (ctx->err.has_error) { + break; + } if (snprintf(buf, sizeof(buf), "element #%u", (unsigned)i++) >= sizeof(buf)) { memcpy(buf, "element", sizeof("element")); } zend_llist_add_element(&ctx->keys, &bufp); - from_zval_write_control(*elem, &control_buf, alloc, &control_len, - &cur_offset, ctx); + from_zval_write_control(elem, &control_buf, alloc, &control_len, &cur_offset, ctx); zend_llist_remove_tail(&ctx->keys); - } + } ZEND_HASH_FOREACH_END(); msg->msg_control = control_buf; msg->msg_controllen = cur_offset; /* not control_len, which may be larger */ @@ -988,21 +965,21 @@ static void to_zval_read_cmsg_data(const char *cmsghdr_c, zval *zv, res_context } if (CMSG_LEN(entry->size) > cmsg->cmsg_len) { do_to_zval_err(ctx, "the cmsghdr structure is unexpectedly small; " - "expected a length of at least %ld, but got %ld", - (long)CMSG_LEN(entry->size), (long)cmsg->cmsg_len); + "expected a length of at least %pd, but got %pd", + (zend_long)CMSG_LEN(entry->size), (zend_long)cmsg->cmsg_len); return; } len = (size_t)cmsg->cmsg_len; /* use another var because type of cmsg_len varies */ - if (zend_hash_add(&ctx->params, KEY_CMSG_LEN, sizeof(KEY_CMSG_LEN), - &len_p, sizeof(len_p), NULL) == FAILURE) { + + if (zend_hash_str_add_ptr(&ctx->params, KEY_CMSG_LEN, sizeof(KEY_CMSG_LEN) - 1, len_p) == NULL) { do_to_zval_err(ctx, "%s", "could not set parameter " KEY_CMSG_LEN); return; } entry->to_array((const char *)CMSG_DATA(cmsg), zv, ctx); - zend_hash_del(&ctx->params, KEY_CMSG_LEN, sizeof(KEY_CMSG_LEN)); + zend_hash_str_del(&ctx->params, KEY_CMSG_LEN, sizeof(KEY_CMSG_LEN) - 1); } static void to_zval_read_control(const char *cmsghdr_c, zval *zv, res_context *ctx) { @@ -1037,10 +1014,10 @@ static void to_zval_read_control_array(const char *msghdr_c, zval *zv, res_conte for (cmsg = CMSG_FIRSTHDR(msg); cmsg != NULL && !ctx->err.has_error; cmsg = CMSG_NXTHDR(msg, cmsg)) { - zval *elem; + zval *elem, tmp; - ALLOC_INIT_ZVAL(elem); - add_next_index_zval(zv, elem); + ZVAL_NULL(&tmp); + elem = zend_hash_next_index_insert(Z_ARRVAL_P(zv), &tmp); if (snprintf(buf, sizeof(buf), "element #%u", (unsigned)i++) >= sizeof(buf)) { memcpy(buf, "element", sizeof("element")); @@ -1076,7 +1053,7 @@ static void to_zval_read_name(const char *sockaddr_p, zval *zv, res_context *ctx } static void from_zval_write_msghdr_buffer_size(const zval *elem, char *msghdr_c, ser_context *ctx) { - long lval; + zend_long lval; struct msghdr *msghdr = (struct msghdr *)msghdr_c; lval = from_zval_integer_common(elem, ctx); @@ -1085,8 +1062,8 @@ static void from_zval_write_msghdr_buffer_size(const zval *elem, char *msghdr_c, } if (lval < 0 || lval > MAX_USER_BUFF_SIZE) { - do_from_zval_err(ctx, "the buffer size must be between 1 and %ld; " - "given %ld", (long)MAX_USER_BUFF_SIZE, lval); + do_from_zval_err(ctx, "the buffer size must be between 1 and %pd; " + "given %pd", (zend_long)MAX_USER_BUFF_SIZE, lval); return; } @@ -1095,18 +1072,20 @@ static void from_zval_write_msghdr_buffer_size(const zval *elem, char *msghdr_c, msghdr->msg_iov[0].iov_base = accounted_emalloc((size_t)lval, ctx); msghdr->msg_iov[0].iov_len = (size_t)lval; } -static void from_zval_write_iov_array_aux(zval **elem, unsigned i, void **args, ser_context *ctx) +static void from_zval_write_iov_array_aux(zval *elem, unsigned i, void **args, ser_context *ctx) { struct msghdr *msg = args[0]; size_t len; - zval_add_ref(elem); + if (Z_REFCOUNTED_P(elem)) { + Z_ADDREF_P(elem); + } convert_to_string_ex(elem); - len = Z_STRLEN_PP(elem); + len = Z_STRLEN_P(elem); msg->msg_iov[i - 1].iov_base = accounted_emalloc(len, ctx); msg->msg_iov[i - 1].iov_len = len; - memcpy(msg->msg_iov[i - 1].iov_base, Z_STRVAL_PP(elem), len); + memcpy(msg->msg_iov[i - 1].iov_base, Z_STRVAL_P(elem), len); zval_ptr_dtor(elem); } @@ -1183,15 +1162,14 @@ void from_zval_write_msghdr_recv(const zval *container, char *msghdr_c, ser_cont const int falsev = 0, *falsevp = &falsev; - if (zend_hash_add(&ctx->params, KEY_FILL_SOCKADDR, sizeof(KEY_FILL_SOCKADDR), - (void*)&falsevp, sizeof(falsevp), NULL) == FAILURE) { + if (zend_hash_str_add_ptr(&ctx->params, KEY_FILL_SOCKADDR, sizeof(KEY_FILL_SOCKADDR) - 1, (void *)falsevp) == NULL) { do_from_zval_err(ctx, "could not add fill_sockaddr; this is a bug"); return; } from_zval_write_aggregation(container, msghdr_c, descriptors, ctx); - zend_hash_del(&ctx->params, KEY_FILL_SOCKADDR, sizeof(KEY_FILL_SOCKADDR)); + zend_hash_str_del(&ctx->params, KEY_FILL_SOCKADDR, sizeof(KEY_FILL_SOCKADDR) - 1); if (ctx->err.has_error) { return; } @@ -1208,7 +1186,7 @@ static void to_zval_read_iov(const char *msghdr_c, zval *zv, res_context *ctx) { const struct msghdr *msghdr = (const struct msghdr *)msghdr_c; size_t iovlen = msghdr->msg_iovlen; - ssize_t **recvmsg_ret, + ssize_t *recvmsg_ret, bytes_left; uint i; @@ -1218,24 +1196,22 @@ static void to_zval_read_iov(const char *msghdr_c, zval *zv, res_context *ctx) } array_init_size(zv, (uint)iovlen); - if (zend_hash_find(&ctx->params, KEY_RECVMSG_RET, sizeof(KEY_RECVMSG_RET), - (void**)&recvmsg_ret) == FAILURE) { + if ((recvmsg_ret = zend_hash_str_find_ptr(&ctx->params, KEY_RECVMSG_RET, sizeof(KEY_RECVMSG_RET) - 1)) == NULL) { do_to_zval_err(ctx, "recvmsg_ret not found in params. This is a bug"); return; } - bytes_left = **recvmsg_ret; + bytes_left = *recvmsg_ret; for (i = 0; bytes_left > 0 && i < (uint)iovlen; i++) { - zval *elem; - size_t len = MIN(msghdr->msg_iov[i].iov_len, (size_t)bytes_left); - char *buf = safe_emalloc(1, len, 1); + zval elem; + size_t len = MIN(msghdr->msg_iov[i].iov_len, (size_t)bytes_left); + zend_string *buf = zend_string_alloc(len, 0); - MAKE_STD_ZVAL(elem); - memcpy(buf, msghdr->msg_iov[i].iov_base, len); - buf[len] = '\0'; + memcpy(ZSTR_VAL(buf), msghdr->msg_iov[i].iov_base, ZSTR_LEN(buf)); + ZSTR_VAL(buf)[ZSTR_LEN(buf)] = '\0'; - ZVAL_STRINGL(elem, buf, len, 0); - add_next_index_zval(zv, elem); + ZVAL_NEW_STR(&elem, buf); + add_next_index_zval(zv, &elem); bytes_left -= len; } } @@ -1257,45 +1233,39 @@ void to_zval_read_msghdr(const char *msghdr_c, zval *zv, res_context *ctx) /* CONVERSIONS for if_index */ static void from_zval_write_ifindex(const zval *zv, char *uinteger, ser_context *ctx) { - unsigned ret = 0; - zval lzval = zval_used_for_init; + unsigned ret = 0; if (Z_TYPE_P(zv) == IS_LONG) { if (Z_LVAL_P(zv) < 0 || Z_LVAL_P(zv) > UINT_MAX) { /* allow 0 (unspecified interface) */ do_from_zval_err(ctx, "the interface index cannot be negative or " - "larger than %u; given %ld", UINT_MAX, Z_LVAL_P(zv)); + "larger than %u; given %pd", UINT_MAX, Z_LVAL_P(zv)); } else { ret = (unsigned)Z_LVAL_P(zv); } } else { - if (Z_TYPE_P(zv) != IS_STRING) { - ZVAL_COPY_VALUE(&lzval, zv); - zval_copy_ctor(&lzval); - convert_to_string(&lzval); - zv = &lzval; - } + zend_string *str; + + str = zval_get_string((zval *) zv); #if HAVE_IF_NAMETOINDEX - ret = if_nametoindex(Z_STRVAL_P(zv)); + ret = if_nametoindex(ZSTR_VAL(str)); if (ret == 0) { - do_from_zval_err(ctx, "no interface with name \"%s\" could be " - "found", Z_STRVAL_P(zv)); + do_from_zval_err(ctx, "no interface with name \"%s\" could be found", ZSTR_VAL(str)); } #elif defined(SIOCGIFINDEX) { struct ifreq ifr; - if (strlcpy(ifr.ifr_name, Z_STRVAL_P(zv), sizeof(ifr.ifr_name)) + if (strlcpy(ifr.ifr_name, ZSTR_VAL(str), sizeof(ifr.ifr_name)) >= sizeof(ifr.ifr_name)) { - do_from_zval_err(ctx, "the interface name \"%s\" is too large ", - Z_STRVAL_P(zv)); + do_from_zval_err(ctx, "the interface name \"%s\" is too large ", ZSTR_VAL(str)); } else if (ioctl(ctx->sock->bsd_socket, SIOCGIFINDEX, &ifr) < 0) { if (errno == ENODEV) { do_from_zval_err(ctx, "no interface with name \"%s\" could be " - "found", Z_STRVAL_P(zv)); + "found", ZSTR_VAL(str)); } else { do_from_zval_err(ctx, "error fetching interface index for " "interface with name \"%s\" (errno %d)", - Z_STRVAL_P(zv), errno); + ZSTR_VAL(str), errno); } } else { ret = (unsigned)ifr.ifr_ifindex; @@ -1306,13 +1276,13 @@ static void from_zval_write_ifindex(const zval *zv, char *uinteger, ser_context "this platform does not support looking up an interface by " "name, an integer interface index must be supplied instead"); #endif + + zend_string_release(str); } if (!ctx->err.has_error) { memcpy(uinteger, &ret, sizeof(ret)); } - - zval_dtor(&lzval); } /* CONVERSIONS for struct in6_pktinfo */ @@ -1374,24 +1344,21 @@ size_t calculate_scm_rights_space(const zval *arr, ser_context *ctx) return zend_hash_num_elements(Z_ARRVAL_P(arr)) * sizeof(int); } -static void from_zval_write_fd_array_aux(zval **elem, unsigned i, void **args, ser_context *ctx) +static void from_zval_write_fd_array_aux(zval *elem, unsigned i, void **args, ser_context *ctx) { int *iarr = args[0]; - TSRMLS_FETCH(); - if (Z_TYPE_PP(elem) == IS_RESOURCE) { + if (Z_TYPE_P(elem) == IS_RESOURCE) { php_stream *stream; php_socket *sock; - ZEND_FETCH_RESOURCE_NO_RETURN(sock, php_socket *, elem, -1, - NULL, php_sockets_le_socket()); + sock = (php_socket *)zend_fetch_resource_ex(elem, NULL, php_sockets_le_socket()); if (sock) { iarr[i] = sock->bsd_socket; return; } - ZEND_FETCH_RESOURCE2_NO_RETURN(stream, php_stream *, elem, -1, - NULL, php_file_le_stream(), php_file_le_pstream()); + stream = (php_stream *)zend_fetch_resource2_ex(elem, NULL, php_file_le_stream(), php_file_le_pstream()); if (stream == NULL) { do_from_zval_err(ctx, "resource is not a stream or a socket"); return; @@ -1417,56 +1384,51 @@ void from_zval_write_fd_array(const zval *arr, char *int_arr, ser_context *ctx) } void to_zval_read_fd_array(const char *data, zval *zv, res_context *ctx) { - size_t **cmsg_len; + size_t *cmsg_len; int num_elems, i; struct cmsghdr *dummy_cmsg = 0; size_t data_offset; - TSRMLS_FETCH(); data_offset = (unsigned char *)CMSG_DATA(dummy_cmsg) - (unsigned char *)dummy_cmsg; - if (zend_hash_find(&ctx->params, KEY_CMSG_LEN, sizeof(KEY_CMSG_LEN), - (void **)&cmsg_len) == FAILURE) { + if ((cmsg_len = zend_hash_str_find_ptr(&ctx->params, KEY_CMSG_LEN, sizeof(KEY_CMSG_LEN) - 1)) == NULL) { do_to_zval_err(ctx, "could not get value of parameter " KEY_CMSG_LEN); return; } - if (**cmsg_len < data_offset) { + if (*cmsg_len < data_offset) { do_to_zval_err(ctx, "length of cmsg is smaller than its data member " - "offset (%ld vs %ld)", (long)**cmsg_len, (long)data_offset); + "offset (%pd vs %pd)", (zend_long)*cmsg_len, (zend_long)data_offset); return; } - num_elems = (**cmsg_len - data_offset) / sizeof(int); + num_elems = (*cmsg_len - data_offset) / sizeof(int); array_init_size(zv, num_elems); for (i = 0; i < num_elems; i++) { - zval *elem; + zval elem; int fd; struct stat statbuf; - MAKE_STD_ZVAL(elem); - fd = *((int *)data + i); /* determine whether we have a socket */ if (fstat(fd, &statbuf) == -1) { do_to_zval_err(ctx, "error creating resource for received file " "descriptor %d: fstat() call failed with errno %d", fd, errno); - efree(elem); return; } if (S_ISSOCK(statbuf.st_mode)) { - php_socket *sock = socket_import_file_descriptor(fd TSRMLS_CC); - zend_register_resource(elem, sock, php_sockets_le_socket() TSRMLS_CC); + php_socket *sock = socket_import_file_descriptor(fd); + ZVAL_RES(&elem, zend_register_resource(sock, php_sockets_le_socket())); } else { php_stream *stream = php_stream_fopen_from_fd(fd, "rw", NULL); - php_stream_to_zval(stream, elem); + php_stream_to_zval(stream, &elem); } - add_next_index_zval(zv, elem); + add_next_index_zval(zv, &elem); } } #endif @@ -1484,8 +1446,8 @@ void *from_zval_run_conversions(const zval *container, zend_llist **allocations /* out */, struct err_s *err /* in/out */) { - ser_context ctx = {{0}}; - char *structure = NULL; + ser_context ctx; + char *structure; *allocations = NULL; @@ -1493,6 +1455,7 @@ void *from_zval_run_conversions(const zval *container, return NULL; } + memset(&ctx, 0, sizeof(ctx)); zend_hash_init(&ctx.params, 8, NULL, NULL, 0); zend_llist_init(&ctx.keys, sizeof(const char *), NULL, 0); zend_llist_init(&ctx.allocations, sizeof(void *), &free_from_zval_allocation, 0); @@ -1524,38 +1487,36 @@ zval *to_zval_run_conversions(const char *structure, to_zval_read_field *reader, const char *top_name, const struct key_value *key_value_pairs, - struct err_s *err) + struct err_s *err, zval *zv) { - res_context ctx = {{0}, {0}}; + res_context ctx; const struct key_value *kv; - zval *zv = NULL; if (err->has_error) { return NULL; } - ALLOC_INIT_ZVAL(zv); - + memset(&ctx, 0, sizeof(ctx)); zend_llist_init(&ctx.keys, sizeof(const char *), NULL, 0); zend_llist_add_element(&ctx.keys, &top_name); zend_hash_init(&ctx.params, 8, NULL, NULL, 0); for (kv = key_value_pairs; kv->key != NULL; kv++) { - zend_hash_update(&ctx.params, kv->key, kv->key_size, - (void*)&kv->value, sizeof(kv->value), NULL); + zend_hash_str_update_ptr(&ctx.params, kv->key, kv->key_size - 1, kv->value); } + ZVAL_NULL(zv); /* main call */ reader(structure, zv, &ctx); if (ctx.err.has_error) { - zval_ptr_dtor(&zv); - zv = NULL; + zval_ptr_dtor(zv); + ZVAL_UNDEF(zv); *err = ctx.err; } zend_llist_destroy(&ctx.keys); zend_hash_destroy(&ctx.params); - return zv; + return Z_ISUNDEF_P(zv)? NULL : zv; } diff --git a/ext/sockets/conversions.h b/ext/sockets/conversions.h index 7d515246a0..0ae6b6d853 100644 --- a/ext/sockets/conversions.h +++ b/ext/sockets/conversions.h @@ -39,7 +39,7 @@ typedef void (to_zval_read_field)(const char *data, zval *zv, res_context *ctx); extern const struct key_value empty_key_value_list[]; /* AUX FUNCTIONS */ -void err_msg_dispose(struct err_s *err TSRMLS_DC); +void err_msg_dispose(struct err_s *err); void allocations_dispose(zend_llist **allocations); /* CONVERSION FUNCTIONS */ @@ -79,6 +79,6 @@ zval *to_zval_run_conversions(const char *structure, to_zval_read_field *reader, const char *top_name, const struct key_value *key_value_pairs, - struct err_s *err); + struct err_s *err, zval *zv); #endif diff --git a/ext/sockets/multicast.c b/ext/sockets/multicast.c index b1a028b7bb..6d37bfb1dd 100644 --- a/ext/sockets/multicast.c +++ b/ext/sockets/multicast.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -51,9 +51,9 @@ enum source_op { UNBLOCK_SOURCE }; -static int _php_mcast_join_leave(php_socket *sock, int level, struct sockaddr *group, socklen_t group_len, unsigned int if_index, int join TSRMLS_DC); +static int _php_mcast_join_leave(php_socket *sock, int level, struct sockaddr *group, socklen_t group_len, unsigned int if_index, int join); #ifdef HAS_MCAST_EXT -static int _php_mcast_source_op(php_socket *sock, int level, struct sockaddr *group, socklen_t group_len, struct sockaddr *source, socklen_t source_len, unsigned int if_index, enum source_op sop TSRMLS_DC); +static int _php_mcast_source_op(php_socket *sock, int level, struct sockaddr *group, socklen_t group_len, struct sockaddr *source, socklen_t source_len, unsigned int if_index, enum source_op sop); #endif #ifdef RFC3678_API @@ -63,14 +63,14 @@ static const char *_php_source_op_to_string(enum source_op sop); static int _php_source_op_to_ipv4_op(enum source_op sop); #endif -int php_string_to_if_index(const char *val, unsigned *out TSRMLS_DC) +int php_string_to_if_index(const char *val, unsigned *out) { #if HAVE_IF_NAMETOINDEX unsigned int ind; ind = if_nametoindex(val); if (ind == 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "no interface with name \"%s\" could be found", val); return FAILURE; } else { @@ -78,32 +78,34 @@ int php_string_to_if_index(const char *val, unsigned *out TSRMLS_DC) return SUCCESS; } #else - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "this platform does not support looking up an interface by " "name, an integer interface index must be supplied instead"); return FAILURE; #endif } -static int php_get_if_index_from_zval(zval *val, unsigned *out TSRMLS_DC) +static int php_get_if_index_from_zval(zval *val, unsigned *out) { int ret; if (Z_TYPE_P(val) == IS_LONG) { if (Z_LVAL_P(val) < 0 || Z_LVAL_P(val) > UINT_MAX) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "the interface index cannot be negative or larger than %u;" - " given %ld", UINT_MAX, Z_LVAL_P(val)); + " given %pd", UINT_MAX, Z_LVAL_P(val)); ret = FAILURE; } else { *out = Z_LVAL_P(val); ret = SUCCESS; } } else { - zval_add_ref(&val); - convert_to_string_ex(&val); - ret = php_string_to_if_index(Z_STRVAL_P(val), out TSRMLS_CC); - zval_ptr_dtor(&val); + if (Z_REFCOUNTED_P(val)) { + Z_ADDREF_P(val); + } + convert_to_string_ex(val); + ret = php_string_to_if_index(Z_STRVAL_P(val), out); + zval_ptr_dtor(val); } return ret; @@ -112,49 +114,49 @@ static int php_get_if_index_from_zval(zval *val, unsigned *out TSRMLS_DC) static int php_get_if_index_from_array(const HashTable *ht, const char *key, - php_socket *sock, unsigned int *if_index TSRMLS_DC) + php_socket *sock, unsigned int *if_index) { - zval **val; + zval *val; - if (zend_hash_find(ht, key, strlen(key) + 1, (void **)&val) == FAILURE) { + if ((val = zend_hash_str_find(ht, key, strlen(key))) == NULL) { *if_index = 0; /* default: 0 */ return SUCCESS; } - return php_get_if_index_from_zval(*val, if_index TSRMLS_CC); + return php_get_if_index_from_zval(val, if_index); } static int php_get_address_from_array(const HashTable *ht, const char *key, - php_socket *sock, php_sockaddr_storage *ss, socklen_t *ss_len TSRMLS_DC) + php_socket *sock, php_sockaddr_storage *ss, socklen_t *ss_len) { - zval **val, - *valcp; + zval *val; - if (zend_hash_find(ht, key, strlen(key) + 1, (void **)&val) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no key \"%s\" passed in optval", key); + if ((val = zend_hash_str_find(ht, key, strlen(key))) == NULL) { + php_error_docref(NULL, E_WARNING, "no key \"%s\" passed in optval", key); return FAILURE; } - valcp = *val; - zval_add_ref(&valcp); + if (Z_REFCOUNTED_P(val)) { + Z_ADDREF_P(val); + } convert_to_string_ex(val); - if (!php_set_inet46_addr(ss, ss_len, Z_STRVAL_P(valcp), sock TSRMLS_CC)) { - zval_ptr_dtor(&valcp); + if (!php_set_inet46_addr(ss, ss_len, Z_STRVAL_P(val), sock)) { + zval_ptr_dtor(val); return FAILURE; } - zval_ptr_dtor(&valcp); + zval_ptr_dtor(val); return SUCCESS; } -static int php_do_mcast_opt(php_socket *php_sock, int level, int optname, zval **arg4 TSRMLS_DC) +static int php_do_mcast_opt(php_socket *php_sock, int level, int optname, zval *arg4) { HashTable *opt_ht; unsigned int if_index; int retval; int (*mcast_req_fun)(php_socket *, int, struct sockaddr *, socklen_t, - unsigned TSRMLS_DC); + unsigned); #ifdef HAS_MCAST_EXT int (*mcast_sreq_fun)(php_socket *, int, struct sockaddr *, socklen_t, - struct sockaddr *, socklen_t, unsigned TSRMLS_DC); + struct sockaddr *, socklen_t, unsigned); #endif switch (optname) { @@ -169,19 +171,19 @@ static int php_do_mcast_opt(php_socket *php_sock, int level, int optname, zval * mcast_req_fun = &php_mcast_leave; mcast_req_fun: convert_to_array_ex(arg4); - opt_ht = HASH_OF(*arg4); + opt_ht = Z_ARRVAL_P(arg4); if (php_get_address_from_array(opt_ht, "group", php_sock, &group, - &glen TSRMLS_CC) == FAILURE) { + &glen) == FAILURE) { return FAILURE; } if (php_get_if_index_from_array(opt_ht, "interface", php_sock, - &if_index TSRMLS_CC) == FAILURE) { + &if_index) == FAILURE) { return FAILURE; } retval = mcast_req_fun(php_sock, level, (struct sockaddr*)&group, - glen, if_index TSRMLS_CC); + glen, if_index); break; } @@ -205,28 +207,28 @@ mcast_req_fun: mcast_sreq_fun = &php_mcast_leave_source; mcast_sreq_fun: convert_to_array_ex(arg4); - opt_ht = HASH_OF(*arg4); + opt_ht = Z_ARRVAL_P(arg4); if (php_get_address_from_array(opt_ht, "group", php_sock, &group, - &glen TSRMLS_CC) == FAILURE) { + &glen) == FAILURE) { return FAILURE; } if (php_get_address_from_array(opt_ht, "source", php_sock, &source, - &slen TSRMLS_CC) == FAILURE) { + &slen) == FAILURE) { return FAILURE; } if (php_get_if_index_from_array(opt_ht, "interface", php_sock, - &if_index TSRMLS_CC) == FAILURE) { + &if_index) == FAILURE) { return FAILURE; } retval = mcast_sreq_fun(php_sock, level, (struct sockaddr*)&group, - glen, (struct sockaddr*)&source, slen, if_index TSRMLS_CC); + glen, (struct sockaddr*)&source, slen, if_index); break; } #endif default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "unexpected option in php_do_mcast_opt (level %d, option %d). " "This is a bug.", level, optname); return FAILURE; @@ -244,7 +246,7 @@ mcast_req_fun: int php_do_setsockopt_ip_mcast(php_socket *php_sock, int level, int optname, - zval **arg4 TSRMLS_DC) + zval *arg4) { unsigned int if_index; struct in_addr if_addr; @@ -262,18 +264,18 @@ int php_do_setsockopt_ip_mcast(php_socket *php_sock, case PHP_MCAST_JOIN_SOURCE_GROUP: case PHP_MCAST_LEAVE_SOURCE_GROUP: #endif - if (php_do_mcast_opt(php_sock, level, optname, arg4 TSRMLS_CC) == FAILURE) { + if (php_do_mcast_opt(php_sock, level, optname, arg4) == FAILURE) { return FAILURE; } else { return SUCCESS; } case IP_MULTICAST_IF: - if (php_get_if_index_from_zval(*arg4, &if_index TSRMLS_CC) == FAILURE) { + if (php_get_if_index_from_zval(arg4, &if_index) == FAILURE) { return FAILURE; } - if (php_if_index_to_addr4(if_index, php_sock, &if_addr TSRMLS_CC) == FAILURE) { + if (php_if_index_to_addr4(if_index, php_sock, &if_addr) == FAILURE) { return FAILURE; } opt_ptr = &if_addr; @@ -282,17 +284,18 @@ int php_do_setsockopt_ip_mcast(php_socket *php_sock, case IP_MULTICAST_LOOP: convert_to_boolean_ex(arg4); + ipv4_mcast_ttl_lback = (unsigned char) (Z_TYPE_P(arg4) == IS_TRUE); goto ipv4_loop_ttl; case IP_MULTICAST_TTL: convert_to_long_ex(arg4); - if (Z_LVAL_PP(arg4) < 0L || Z_LVAL_PP(arg4) > 255L) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + if (Z_LVAL_P(arg4) < 0L || Z_LVAL_P(arg4) > 255L) { + php_error_docref(NULL, E_WARNING, "Expected a value between 0 and 255"); return FAILURE; } + ipv4_mcast_ttl_lback = (unsigned char) Z_LVAL_P(arg4); ipv4_loop_ttl: - ipv4_mcast_ttl_lback = (unsigned char) Z_LVAL_PP(arg4); opt_ptr = &ipv4_mcast_ttl_lback; optlen = sizeof(ipv4_mcast_ttl_lback); goto dosockopt; @@ -313,7 +316,7 @@ dosockopt: int php_do_setsockopt_ipv6_mcast(php_socket *php_sock, int level, int optname, - zval **arg4 TSRMLS_DC) + zval *arg4) { unsigned int if_index; void *opt_ptr; @@ -330,14 +333,14 @@ int php_do_setsockopt_ipv6_mcast(php_socket *php_sock, case PHP_MCAST_JOIN_SOURCE_GROUP: case PHP_MCAST_LEAVE_SOURCE_GROUP: #endif - if (php_do_mcast_opt(php_sock, level, optname, arg4 TSRMLS_CC) == FAILURE) { + if (php_do_mcast_opt(php_sock, level, optname, arg4) == FAILURE) { return FAILURE; } else { return SUCCESS; } case IPV6_MULTICAST_IF: - if (php_get_if_index_from_zval(*arg4, &if_index TSRMLS_CC) == FAILURE) { + if (php_get_if_index_from_zval(arg4, &if_index) == FAILURE) { return FAILURE; } @@ -347,16 +350,17 @@ int php_do_setsockopt_ipv6_mcast(php_socket *php_sock, case IPV6_MULTICAST_LOOP: convert_to_boolean_ex(arg4); + ov = (int) Z_TYPE_P(arg4) == IS_TRUE; goto ipv6_loop_hops; case IPV6_MULTICAST_HOPS: convert_to_long_ex(arg4); - if (Z_LVAL_PP(arg4) < -1L || Z_LVAL_PP(arg4) > 255L) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + if (Z_LVAL_P(arg4) < -1L || Z_LVAL_P(arg4) > 255L) { + php_error_docref(NULL, E_WARNING, "Expected a value between -1 and 255"); return FAILURE; } + ov = (int) Z_LVAL_P(arg4); ipv6_loop_hops: - ov = (int) Z_LVAL_PP(arg4); opt_ptr = &ov; optlen = sizeof(ov); goto dosockopt; @@ -379,9 +383,9 @@ int php_mcast_join( int level, struct sockaddr *group, socklen_t group_len, - unsigned int if_index TSRMLS_DC) + unsigned int if_index) { - return _php_mcast_join_leave(sock, level, group, group_len, if_index, 1 TSRMLS_CC); + return _php_mcast_join_leave(sock, level, group, group_len, if_index, 1); } int php_mcast_leave( @@ -389,9 +393,9 @@ int php_mcast_leave( int level, struct sockaddr *group, socklen_t group_len, - unsigned int if_index TSRMLS_DC) + unsigned int if_index) { - return _php_mcast_join_leave(sock, level, group, group_len, if_index, 0 TSRMLS_CC); + return _php_mcast_join_leave(sock, level, group, group_len, if_index, 0); } #ifdef HAS_MCAST_EXT @@ -402,9 +406,9 @@ int php_mcast_join_source( socklen_t group_len, struct sockaddr *source, socklen_t source_len, - unsigned int if_index TSRMLS_DC) + unsigned int if_index) { - return _php_mcast_source_op(sock, level, group, group_len, source, source_len, if_index, JOIN_SOURCE TSRMLS_CC); + return _php_mcast_source_op(sock, level, group, group_len, source, source_len, if_index, JOIN_SOURCE); } int php_mcast_leave_source( @@ -414,9 +418,9 @@ int php_mcast_leave_source( socklen_t group_len, struct sockaddr *source, socklen_t source_len, - unsigned int if_index TSRMLS_DC) + unsigned int if_index) { - return _php_mcast_source_op(sock, level, group, group_len, source, source_len, if_index, LEAVE_SOURCE TSRMLS_CC); + return _php_mcast_source_op(sock, level, group, group_len, source, source_len, if_index, LEAVE_SOURCE); } int php_mcast_block_source( @@ -426,9 +430,9 @@ int php_mcast_block_source( socklen_t group_len, struct sockaddr *source, socklen_t source_len, - unsigned int if_index TSRMLS_DC) + unsigned int if_index) { - return _php_mcast_source_op(sock, level, group, group_len, source, source_len, if_index, BLOCK_SOURCE TSRMLS_CC); + return _php_mcast_source_op(sock, level, group, group_len, source, source_len, if_index, BLOCK_SOURCE); } int php_mcast_unblock_source( @@ -438,9 +442,9 @@ int php_mcast_unblock_source( socklen_t group_len, struct sockaddr *source, socklen_t source_len, - unsigned int if_index TSRMLS_DC) + unsigned int if_index) { - return _php_mcast_source_op(sock, level, group, group_len, source, source_len, if_index, UNBLOCK_SOURCE TSRMLS_CC); + return _php_mcast_source_op(sock, level, group, group_len, source, source_len, if_index, UNBLOCK_SOURCE); } #endif /* HAS_MCAST_EXT */ @@ -451,7 +455,7 @@ static int _php_mcast_join_leave( struct sockaddr *group, /* struct sockaddr_in/sockaddr_in6 */ socklen_t group_len, unsigned int if_index, - int join TSRMLS_DC) + int join) { #ifdef RFC3678_API struct group_req greq = {0}; @@ -471,7 +475,7 @@ static int _php_mcast_join_leave( assert(group_len == sizeof(struct sockaddr_in)); if (if_index != 0) { - if (php_if_index_to_addr4(if_index, sock, &addr TSRMLS_CC) == + if (php_if_index_to_addr4(if_index, sock, &addr) == FAILURE) return -2; /* failure, but notice already emitted */ mreq.imr_interface = addr; @@ -498,7 +502,7 @@ static int _php_mcast_join_leave( } #endif else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "Option %s is inapplicable to this socket type", join ? "MCAST_JOIN_GROUP" : "MCAST_LEAVE_GROUP"); return -2; @@ -515,7 +519,7 @@ static int _php_mcast_source_op( struct sockaddr *source, socklen_t source_len, unsigned int if_index, - enum source_op sop TSRMLS_DC) + enum source_op sop) { #ifdef RFC3678_API struct group_source_req gsreq = {0}; @@ -540,7 +544,7 @@ static int _php_mcast_source_op( assert(source_len == sizeof(struct sockaddr_in)); if (if_index != 0) { - if (php_if_index_to_addr4(if_index, sock, &addr TSRMLS_CC) == + if (php_if_index_to_addr4(if_index, sock, &addr) == FAILURE) return -2; /* failure, but notice already emitted */ mreqs.imr_interface = addr; @@ -553,14 +557,14 @@ static int _php_mcast_source_op( } #if HAVE_IPV6 else if (sock->type == AF_INET6) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "This platform does not support %s for IPv6 sockets", _php_source_op_to_string(sop)); return -2; } #endif else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "Option %s is inapplicable to this socket type", _php_source_op_to_string(sop)); return -2; @@ -624,7 +628,7 @@ static int _php_source_op_to_ipv4_op(enum source_op sop) #endif /* HAS_MCAST_EXT */ #if PHP_WIN32 -int php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struct in_addr *out_addr TSRMLS_DC) +int php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struct in_addr *out_addr) { MIB_IPADDRTABLE *addr_table; ULONG size; @@ -648,7 +652,7 @@ retry: goto retry; } if (retval != NO_ERROR) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "GetIpAddrTable failed with error %lu", retval); return FAILURE; } @@ -659,12 +663,12 @@ retry: return SUCCESS; } } - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "No interface with index %u was found", if_index); return FAILURE; } -int php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, unsigned *if_index TSRMLS_DC) +int php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, unsigned *if_index) { MIB_IPADDRTABLE *addr_table; ULONG size; @@ -688,7 +692,7 @@ retry: goto retry; } if (retval != NO_ERROR) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "GetIpAddrTable failed with error %lu", retval); return FAILURE; } @@ -703,7 +707,7 @@ retry: { char addr_str[17] = {0}; inet_ntop(AF_INET, addr, addr_str, sizeof(addr_str)); - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "The interface with IP address %s was not found", addr_str); } return FAILURE; @@ -711,7 +715,7 @@ retry: #else -int php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struct in_addr *out_addr TSRMLS_DC) +int php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struct in_addr *out_addr) { struct ifreq if_req; @@ -732,13 +736,13 @@ int php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struct in_add #else #error Neither SIOCGIFNAME nor if_indextoname are available #endif - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "Failed obtaining address for interface %u: error %d", if_index, errno); return FAILURE; } if (ioctl(php_sock->bsd_socket, SIOCGIFADDR, &if_req) == -1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "Failed obtaining address for interface %u: error %d", if_index, errno); return FAILURE; } @@ -748,7 +752,7 @@ int php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struct in_add return SUCCESS; } -int php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, unsigned *if_index TSRMLS_DC) +int php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, unsigned *if_index) { struct ifconf if_conf = {0}; char *buf = NULL, @@ -770,7 +774,7 @@ int php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, unsigned *i if (ioctl(php_sock->bsd_socket, SIOCGIFCONF, (char*)&if_conf) == -1 && (errno != EINVAL || lastsize != 0)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "Failed obtaining interfaces list: error %d", errno); goto err; } @@ -813,7 +817,7 @@ int php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, unsigned *i #else #error Neither SIOCGIFINDEX nor if_nametoindex are available #endif - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "Error converting interface name to index: error %d", errno); goto err; @@ -832,7 +836,7 @@ int php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, unsigned *i { char addr_str[17] = {0}; inet_ntop(AF_INET, addr, addr_str, sizeof(addr_str)); - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "The interface with IP address %s was not found", addr_str); } diff --git a/ext/sockets/multicast.h b/ext/sockets/multicast.h index 91ae8b5972..29ef05567a 100644 --- a/ext/sockets/multicast.h +++ b/ext/sockets/multicast.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -48,38 +48,38 @@ int php_do_setsockopt_ip_mcast(php_socket *php_sock, int level, int optname, - zval **arg4 TSRMLS_DC); + zval *arg4); int php_do_setsockopt_ipv6_mcast(php_socket *php_sock, int level, int optname, - zval **arg4 TSRMLS_DC); + zval *arg4); int php_if_index_to_addr4( unsigned if_index, php_socket *php_sock, - struct in_addr *out_addr TSRMLS_DC); + struct in_addr *out_addr); int php_add4_to_if_index( struct in_addr *addr, php_socket *php_sock, - unsigned *if_index TSRMLS_DC); + unsigned *if_index); -int php_string_to_if_index(const char *val, unsigned *out TSRMLS_DC); +int php_string_to_if_index(const char *val, unsigned *out); int php_mcast_join( php_socket *sock, int level, struct sockaddr *group, socklen_t group_len, - unsigned int if_index TSRMLS_DC); + unsigned int if_index); int php_mcast_leave( php_socket *sock, int level, struct sockaddr *group, socklen_t group_len, - unsigned int if_index TSRMLS_DC); + unsigned int if_index); #ifdef HAS_MCAST_EXT int php_mcast_join_source( @@ -89,7 +89,7 @@ int php_mcast_join_source( socklen_t group_len, struct sockaddr *source, socklen_t source_len, - unsigned int if_index TSRMLS_DC); + unsigned int if_index); int php_mcast_leave_source( php_socket *sock, @@ -98,7 +98,7 @@ int php_mcast_leave_source( socklen_t group_len, struct sockaddr *source, socklen_t source_len, - unsigned int if_index TSRMLS_DC); + unsigned int if_index); int php_mcast_block_source( php_socket *sock, @@ -107,7 +107,7 @@ int php_mcast_block_source( socklen_t group_len, struct sockaddr *source, socklen_t source_len, - unsigned int if_index TSRMLS_DC); + unsigned int if_index); int php_mcast_unblock_source( php_socket *sock, @@ -116,5 +116,5 @@ int php_mcast_unblock_source( socklen_t group_len, struct sockaddr *source, socklen_t source_len, - unsigned int if_index TSRMLS_DC); + unsigned int if_index); #endif diff --git a/ext/sockets/package.xml b/ext/sockets/package.xml index 2799fff13d..5fa67d9939 100644 --- a/ext/sockets/package.xml +++ b/ext/sockets/package.xml @@ -50,7 +50,6 @@ package.xml added to support installation using pear installer <file role="src" name="php_sockets_win.c"/> <file role="src" name="php_sockets_win.h"/> <file role="src" name="sockets.c"/> - <file role="src" name="sockets.dsp"/> <file role="src" name="unix_socket_constants.h"/> <file role="src" name="win32_socket_constants.h"/> <file role="test" name="tests/ipv4loop.phpt"/> diff --git a/ext/sockets/php_sockets.h b/ext/sockets/php_sockets.h index 8abf25d6a6..ce5cdaf313 100644 --- a/ext/sockets/php_sockets.h +++ b/ext/sockets/php_sockets.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -35,6 +35,8 @@ # include "windows_common.h" #endif +#define PHP_SOCKETS_VERSION PHP_VERSION + extern zend_module_entry sockets_module_entry; #define phpext_sockets_ptr &sockets_module_entry @@ -59,7 +61,7 @@ typedef struct { int type; int error; int blocking; - zval *zstream; + zval zstream; } php_socket; #ifdef PHP_WIN32 @@ -70,6 +72,8 @@ struct sockaddr_un { #endif PHP_SOCKETS_API int php_sockets_le_socket(void); +PHP_SOCKETS_API php_socket *php_create_socket(void); +PHP_SOCKETS_API void php_destroy_socket(zend_resource *rsrc); #define php_sockets_le_socket_name "Socket" @@ -79,7 +83,7 @@ PHP_SOCKETS_API int php_sockets_le_socket(void); (socket)->error = _err; \ SOCKETS_G(last_error) = _err; \ if (_err != EAGAIN && _err != EWOULDBLOCK && _err != EINPROGRESS) { \ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s [%d]: %s", msg, _err, sockets_strerror(_err TSRMLS_CC)); \ + php_error_docref(NULL, E_WARNING, "%s [%d]: %s", msg, _err, sockets_strerror(_err)); \ } \ } while (0) @@ -88,13 +92,8 @@ ZEND_BEGIN_MODULE_GLOBALS(sockets) char *strerror_buf; ZEND_END_MODULE_GLOBALS(sockets) -#ifdef ZTS -#define SOCKETS_G(v) TSRMG(sockets_globals_id, zend_sockets_globals *, v) -#else -#define SOCKETS_G(v) (sockets_globals.v) -#endif - -ZEND_EXTERN_MODULE_GLOBALS(sockets); +ZEND_EXTERN_MODULE_GLOBALS(sockets) +#define SOCKETS_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(sockets, v) enum sockopt_return { SOCKOPT_ERROR, @@ -102,8 +101,8 @@ enum sockopt_return { SOCKOPT_SUCCESS }; -char *sockets_strerror(int error TSRMLS_DC); -php_socket *socket_import_file_descriptor(PHP_SOCKET sock TSRMLS_DC); +char *sockets_strerror(int error); +php_socket *socket_import_file_descriptor(PHP_SOCKET sock); #else #define phpext_sockets_ptr NULL diff --git a/ext/sockets/sendrecvmsg.c b/ext/sockets/sendrecvmsg.c index 5550f4d20f..7471ad143a 100644 --- a/ext/sockets/sendrecvmsg.c +++ b/ext/sockets/sendrecvmsg.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -71,7 +71,7 @@ inline ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags) #define LONG_CHECK_VALID_INT(l) \ do { \ if ((l) < INT_MIN && (l) > INT_MAX) { \ - php_error_docref0(NULL TSRMLS_CC, E_WARNING, "The value %ld does not fit inside " \ + php_error_docref0(NULL, E_WARNING, "The value %pd does not fit inside " \ "the boundaries of a native integer", (l)); \ return; \ } \ @@ -83,6 +83,10 @@ static struct { } ancillary_registry; +static void ancillary_registery_free_elem(zval *el) { + pefree(Z_PTR_P(el), 1); +} + #ifdef ZTS static MUTEX_T ancillary_mutex; #endif @@ -92,7 +96,7 @@ static void init_ancillary_registry(void) anc_reg_key key; ancillary_registry.initialized = 1; - zend_hash_init(&ancillary_registry.ht, 32, NULL, NULL, 1); + zend_hash_init(&ancillary_registry.ht, 32, NULL, ancillary_registery_free_elem, 1); #define PUT_ENTRY(sizev, var_size, calc, from, to, level, type) \ entry.size = sizev; \ @@ -102,8 +106,7 @@ static void init_ancillary_registry(void) entry.to_array = to; \ key.cmsg_level = level; \ key.cmsg_type = type; \ - zend_hash_update(&ancillary_registry.ht, (char*)&key, sizeof(key), \ - (void*)&entry, sizeof(entry), NULL) + zend_hash_str_update_mem(&ancillary_registry.ht, (char*)&key, sizeof(key) - 1, (void*)&entry, sizeof(entry)) #if defined(IPV6_PKTINFO) && HAVE_IPV6 PUT_ENTRY(sizeof(struct in6_pktinfo), 0, 0, from_zval_write_in6_pktinfo, @@ -153,8 +156,7 @@ ancillary_reg_entry *get_ancillary_reg_entry(int cmsg_level, int msg_type) tsrm_mutex_unlock(ancillary_mutex); #endif - if (zend_hash_find(&ancillary_registry.ht, (char*)&key, sizeof(key), - (void**)&entry) == SUCCESS) { + if ((entry = zend_hash_str_find_ptr(&ancillary_registry.ht, (char*)&key, sizeof(key) - 1)) != NULL) { return entry; } else { return NULL; @@ -165,7 +167,7 @@ PHP_FUNCTION(socket_sendmsg) { zval *zsocket, *zmsg; - long flags = 0; + zend_long flags = 0; php_socket *php_sock; struct msghdr *msghdr; zend_llist *allocations; @@ -173,20 +175,22 @@ PHP_FUNCTION(socket_sendmsg) ssize_t res; /* zmsg should be passed by ref */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra|l", &zsocket, &zmsg, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ra|l", &zsocket, &zmsg, &flags) == FAILURE) { return; } LONG_CHECK_VALID_INT(flags); - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &zsocket, -1, - php_sockets_le_socket_name, php_sockets_le_socket()); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(zsocket), + php_sockets_le_socket_name, php_sockets_le_socket())) == NULL) { + RETURN_FALSE; + } msghdr = from_zval_run_conversions(zmsg, php_sock, from_zval_write_msghdr_send, sizeof(*msghdr), "msghdr", &allocations, &err); if (err.has_error) { - err_msg_dispose(&err TSRMLS_CC); + err_msg_dispose(&err); RETURN_FALSE; } @@ -196,7 +200,7 @@ PHP_FUNCTION(socket_sendmsg) zend_llist_destroy(allocations); efree(allocations); - RETURN_LONG((long)res); + RETURN_LONG((zend_long)res); } else { PHP_SOCKET_ERROR(php_sock, "error in sendmsg", errno); RETURN_FALSE; @@ -207,7 +211,7 @@ PHP_FUNCTION(socket_recvmsg) { zval *zsocket, *zmsg; - long flags = 0; + zend_long flags = 0; php_socket *php_sock; ssize_t res; struct msghdr *msghdr; @@ -215,28 +219,30 @@ PHP_FUNCTION(socket_recvmsg) struct err_s err = {0}; //ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra|l", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ra/|l", &zsocket, &zmsg, &flags) == FAILURE) { return; } LONG_CHECK_VALID_INT(flags); - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &zsocket, -1, - php_sockets_le_socket_name, php_sockets_le_socket()); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(zsocket), + php_sockets_le_socket_name, php_sockets_le_socket())) == NULL) { + RETURN_FALSE; + } msghdr = from_zval_run_conversions(zmsg, php_sock, from_zval_write_msghdr_recv, sizeof(*msghdr), "msghdr", &allocations, &err); if (err.has_error) { - err_msg_dispose(&err TSRMLS_CC); + err_msg_dispose(&err); RETURN_FALSE; } res = recvmsg(php_sock->bsd_socket, msghdr, (int)flags); if (res != -1) { - zval *zres; + zval *zres, tmp; struct key_value kv[] = { {KEY_RECVMSG_RET, sizeof(KEY_RECVMSG_RET), &res}, {0} @@ -244,7 +250,7 @@ PHP_FUNCTION(socket_recvmsg) zres = to_zval_run_conversions((char *)msghdr, to_zval_read_msghdr, - "msghdr", kv, &err); + "msghdr", kv, &err, &tmp); /* we don;t need msghdr anymore; free it */ msghdr = NULL; @@ -253,31 +259,30 @@ PHP_FUNCTION(socket_recvmsg) zval_dtor(zmsg); if (!err.has_error) { ZVAL_COPY_VALUE(zmsg, zres); - efree(zres); /* only shallow destruction */ } else { - err_msg_dispose(&err TSRMLS_CC); + err_msg_dispose(&err); ZVAL_FALSE(zmsg); /* no need to destroy/free zres -- it's NULL in this circumstance */ assert(zres == NULL); } } else { SOCKETS_G(last_error) = errno; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "error in recvmsg [%d]: %s", - errno, sockets_strerror(errno TSRMLS_CC)); + php_error_docref(NULL, E_WARNING, "error in recvmsg [%d]: %s", + errno, sockets_strerror(errno)); RETURN_FALSE; } - RETURN_LONG((long)res); + RETURN_LONG((zend_long)res); } PHP_FUNCTION(socket_cmsg_space) { - long level, + zend_long level, type, n = 0; ancillary_reg_entry *entry; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|l", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|l", &level, &type, &n) == FAILURE) { return; } @@ -287,31 +292,31 @@ PHP_FUNCTION(socket_cmsg_space) LONG_CHECK_VALID_INT(n); if (n < 0) { - php_error_docref0(NULL TSRMLS_CC, E_WARNING, "The third argument " + php_error_docref0(NULL, E_WARNING, "The third argument " "cannot be negative"); return; } entry = get_ancillary_reg_entry(level, type); if (entry == NULL) { - php_error_docref0(NULL TSRMLS_CC, E_WARNING, "The pair level %ld/type %ld is " + php_error_docref0(NULL, E_WARNING, "The pair level %pd/type %pd is " "not supported by PHP", level, type); return; } - if (entry->var_el_size > 0 && n > (LONG_MAX - (long)entry->size - - (long)CMSG_SPACE(0) - 15L) / entry->var_el_size) { + if (entry->var_el_size > 0 && n > (ZEND_LONG_MAX - (zend_long)entry->size - + (zend_long)CMSG_SPACE(0) - 15L) / entry->var_el_size) { /* the -15 is to account for any padding CMSG_SPACE may add after the data */ - php_error_docref0(NULL TSRMLS_CC, E_WARNING, "The value for the " - "third argument (%ld) is too large", n); + php_error_docref0(NULL, E_WARNING, "The value for the " + "third argument (%pd) is too large", n); return; } - RETURN_LONG((long)CMSG_SPACE(entry->size + n * entry->var_el_size)); + RETURN_LONG((zend_long)CMSG_SPACE(entry->size + n * entry->var_el_size)); } #if HAVE_IPV6 -int php_do_setsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, zval **arg4 TSRMLS_DC) +int php_do_setsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, zval *arg4) { struct err_s err = {0}; zend_llist *allocations = NULL; @@ -325,8 +330,8 @@ int php_do_setsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, #ifdef IPV6_PKTINFO case IPV6_PKTINFO: #ifdef PHP_WIN32 - if (Z_TYPE_PP(arg4) == IS_ARRAY) { - php_error_docref0(NULL TSRMLS_CC, E_WARNING, "Windows does not " + if (Z_TYPE_P(arg4) == IS_ARRAY) { + php_error_docref0(NULL, E_WARNING, "Windows does not " "support sticky IPV6_PKTINFO"); return FAILURE; } else { @@ -336,10 +341,10 @@ int php_do_setsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, return 1; } #endif - opt_ptr = from_zval_run_conversions(*arg4, php_sock, from_zval_write_in6_pktinfo, + opt_ptr = from_zval_run_conversions(arg4, php_sock, from_zval_write_in6_pktinfo, sizeof(struct in6_pktinfo), "in6_pktinfo", &allocations, &err); if (err.has_error) { - err_msg_dispose(&err TSRMLS_CC); + err_msg_dispose(&err); return FAILURE; } @@ -362,7 +367,7 @@ dosockopt: return retval != 0 ? FAILURE : SUCCESS; } -int php_do_getsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, zval *result TSRMLS_DC) +int php_do_getsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, zval *result) { struct err_s err = {0}; void *buffer; @@ -388,14 +393,14 @@ int php_do_getsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, if (res != 0) { PHP_SOCKET_ERROR(php_sock, "unable to get socket option", errno); } else { + zval tmp; zval *zv = to_zval_run_conversions(buffer, reader, "in6_pktinfo", - empty_key_value_list, &err); + empty_key_value_list, &err, &tmp); if (err.has_error) { - err_msg_dispose(&err TSRMLS_CC); + err_msg_dispose(&err); res = -1; } else { ZVAL_COPY_VALUE(result, zv); - efree(zv); } } efree(buffer); diff --git a/ext/sockets/sendrecvmsg.h b/ext/sockets/sendrecvmsg.h index 5a3798274f..b12974e4bd 100644 --- a/ext/sockets/sendrecvmsg.h +++ b/ext/sockets/sendrecvmsg.h @@ -12,8 +12,8 @@ PHP_FUNCTION(socket_cmsg_space); void php_socket_sendrecvmsg_init(INIT_FUNC_ARGS); void php_socket_sendrecvmsg_shutdown(SHUTDOWN_FUNC_ARGS); -int php_do_setsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, zval **arg4 TSRMLS_DC); -int php_do_getsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, zval *result TSRMLS_DC); +int php_do_setsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, zval *arg4); +int php_do_getsockopt_ipv6_rfc3542(php_socket *php_sock, int level, int optname, zval *result); /* for conversions.c */ typedef struct { diff --git a/ext/sockets/sockaddr_conv.c b/ext/sockets/sockaddr_conv.c index 961896bdab..1ce109ee8c 100644 --- a/ext/sockets/sockaddr_conv.c +++ b/ext/sockets/sockaddr_conv.c @@ -9,11 +9,11 @@ #include <arpa/inet.h> #endif -extern int php_string_to_if_index(const char *val, unsigned *out TSRMLS_DC); +extern int php_string_to_if_index(const char *val, unsigned *out); #if HAVE_IPV6 /* Sets addr by hostname, or by ip in string form (AF_INET6) */ -int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_sock TSRMLS_DC) /* {{{ */ +int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_sock) /* {{{ */ { struct in6_addr tmp; #if HAVE_GETADDRINFO @@ -44,7 +44,7 @@ int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_ return 0; } if (addrinfo->ai_family != PF_INET6 || addrinfo->ai_addrlen != sizeof(struct sockaddr_in6)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Host lookup failed: Non AF_INET6 domain returned on AF_INET6 socket"); + php_error_docref(NULL, E_WARNING, "Host lookup failed: Non AF_INET6 domain returned on AF_INET6 socket"); freeaddrinfo(addrinfo); return 0; } @@ -54,14 +54,14 @@ int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_ #else /* No IPv6 specific hostname resolution is available on this system? */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Host lookup failed: getaddrinfo() not available on this system"); + php_error_docref(NULL, E_WARNING, "Host lookup failed: getaddrinfo() not available on this system"); return 0; #endif } if (scope++) { - long lval = 0; + zend_long lval = 0; double dval = 0; unsigned scope_id = 0; @@ -70,7 +70,7 @@ int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_ scope_id = lval; } } else { - php_string_to_if_index(scope, &scope_id TSRMLS_CC); + php_string_to_if_index(scope, &scope_id); } sin6->sin6_scope_id = scope_id; @@ -82,7 +82,7 @@ int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_ #endif /* Sets addr by hostname, or by ip in string form (AF_INET) */ -int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_sock TSRMLS_DC) /* {{{ */ +int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_sock) /* {{{ */ { struct in_addr tmp; struct hostent *host_entry; @@ -90,7 +90,7 @@ int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_soc if (inet_aton(string, &tmp)) { sin->sin_addr.s_addr = tmp.s_addr; } else { - if (strlen(string) > MAXFQDNLEN || ! (host_entry = gethostbyname(string))) { + if (strlen(string) > MAXFQDNLEN || ! (host_entry = php_network_gethostbyname(string))) { /* Note: < -10000 indicates a host lookup error */ #ifdef PHP_WIN32 PHP_SOCKET_ERROR(php_sock, "Host lookup failed", WSAGetLastError()); @@ -100,7 +100,7 @@ int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_soc return 0; } if (host_entry->h_addrtype != AF_INET) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Host lookup failed: Non AF_INET domain returned on AF_INET socket"); + php_error_docref(NULL, E_WARNING, "Host lookup failed: Non AF_INET domain returned on AF_INET socket"); return 0; } memcpy(&(sin->sin_addr.s_addr), host_entry->h_addr_list[0], host_entry->h_length); @@ -112,11 +112,11 @@ int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_soc /* Sets addr by hostname or by ip in string form (AF_INET or AF_INET6, * depending on the socket) */ -int php_set_inet46_addr(php_sockaddr_storage *ss, socklen_t *ss_len, char *string, php_socket *php_sock TSRMLS_DC) /* {{{ */ +int php_set_inet46_addr(php_sockaddr_storage *ss, socklen_t *ss_len, char *string, php_socket *php_sock) /* {{{ */ { if (php_sock->type == AF_INET) { struct sockaddr_in t = {0}; - if (php_set_inet_addr(&t, string, php_sock TSRMLS_CC)) { + if (php_set_inet_addr(&t, string, php_sock)) { memcpy(ss, &t, sizeof t); ss->ss_family = AF_INET; *ss_len = sizeof(t); @@ -126,7 +126,7 @@ int php_set_inet46_addr(php_sockaddr_storage *ss, socklen_t *ss_len, char *strin #if HAVE_IPV6 else if (php_sock->type == AF_INET6) { struct sockaddr_in6 t = {0}; - if (php_set_inet6_addr(&t, string, php_sock TSRMLS_CC)) { + if (php_set_inet6_addr(&t, string, php_sock)) { memcpy(ss, &t, sizeof t); ss->ss_family = AF_INET6; *ss_len = sizeof(t); @@ -135,7 +135,7 @@ int php_set_inet46_addr(php_sockaddr_storage *ss, socklen_t *ss_len, char *strin } #endif else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "IP address used in the context of an unexpected type of socket"); } return 0; diff --git a/ext/sockets/sockaddr_conv.h b/ext/sockets/sockaddr_conv.h index 8e51edac8f..1e7e3cf046 100644 --- a/ext/sockets/sockaddr_conv.h +++ b/ext/sockets/sockaddr_conv.h @@ -16,16 +16,16 @@ * The IPv6 literal can be a IPv4 mapped address (like ::ffff:127.0.0.1). * If the hostname yields no IPv6 addresses, a mapped IPv4 address may be returned (AI_V4MAPPED) */ -int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_sock TSRMLS_DC); +int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_sock); /* * Convert an IPv4 literal or a hostname into a sockaddr_in. */ -int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_sock TSRMLS_DC); +int php_set_inet_addr(struct sockaddr_in *sin, char *string, php_socket *php_sock); /* * Calls either php_set_inet6_addr() or php_set_inet_addr(), depending on the type of the socket. */ -int php_set_inet46_addr(php_sockaddr_storage *ss, socklen_t *ss_len, char *string, php_socket *php_sock TSRMLS_DC); +int php_set_inet46_addr(php_sockaddr_storage *ss, socklen_t *ss_len, char *string, php_socket *php_sock); #endif diff --git a/ext/sockets/sockets.c b/ext/sockets/sockets.c index c5bcf676d9..63674c50d7 100644 --- a/ext/sockets/sockets.c +++ b/ext/sockets/sockets.c @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -251,6 +251,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_socket_import_stream, 0, 0, 1) ZEND_ARG_INFO(0, stream) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_socket_export_stream, 0, 0, 1) + ZEND_ARG_INFO(0, socket) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_socket_sendmsg, 0, 0, 3) ZEND_ARG_INFO(0, socket) ZEND_ARG_INFO(0, msghdr) @@ -305,6 +309,7 @@ PHP_FUNCTION(socket_shutdown); PHP_FUNCTION(socket_last_error); PHP_FUNCTION(socket_clear_error); PHP_FUNCTION(socket_import_stream); +PHP_FUNCTION(socket_export_stream); /* {{{ sockets_functions[] */ @@ -339,6 +344,7 @@ const zend_function_entry sockets_functions[] = { PHP_FE(socket_last_error, arginfo_socket_last_error) PHP_FE(socket_clear_error, arginfo_socket_clear_error) PHP_FE(socket_import_stream, arginfo_socket_import_stream) + PHP_FE(socket_export_stream, arginfo_socket_export_stream) PHP_FE(socket_sendmsg, arginfo_socket_sendmsg) PHP_FE(socket_recvmsg, arginfo_socket_recvmsg) PHP_FE(socket_cmsg_space, arginfo_socket_cmsg_space) @@ -360,7 +366,7 @@ zend_module_entry sockets_module_entry = { NULL, PHP_RSHUTDOWN(sockets), PHP_MINFO(sockets), - NO_VERSION_YET, + PHP_SOCKETS_VERSION, PHP_MODULE_GLOBALS(sockets), PHP_GINIT(sockets), NULL, @@ -370,6 +376,9 @@ zend_module_entry sockets_module_entry = { #ifdef COMPILE_DL_SOCKETS +#ifdef ZTS + ZEND_TSRMLS_CACHE_DEFINE() +#endif ZEND_GET_MODULE(sockets) #endif @@ -384,25 +393,25 @@ PHP_SOCKETS_API int php_sockets_le_socket(void) /* {{{ */ /* allocating function to make programming errors due to uninitialized fields * less likely */ -static php_socket *php_create_socket(void) /* {{{ */ +PHP_SOCKETS_API php_socket *php_create_socket(void) /* {{{ */ { - php_socket *php_sock = emalloc(sizeof *php_sock); + php_socket *php_sock = emalloc(sizeof(php_socket)); php_sock->bsd_socket = -1; /* invalid socket */ php_sock->type = PF_UNSPEC; php_sock->error = 0; php_sock->blocking = 1; - php_sock->zstream = NULL; + ZVAL_UNDEF(&php_sock->zstream); return php_sock; } /* }}} */ -static void php_destroy_socket(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */ +PHP_SOCKETS_API void php_destroy_socket(zend_resource *rsrc) /* {{{ */ { php_socket *php_sock = rsrc->ptr; - if (php_sock->zstream == NULL) { + if (Z_ISUNDEF(php_sock->zstream)) { if (!IS_INVALID_SOCKET(php_sock)) { close(php_sock->bsd_socket); } @@ -413,7 +422,7 @@ static void php_destroy_socket(zend_rsrc_list_entry *rsrc TSRMLS_DC) /* {{{ */ } /* }}} */ -static int php_open_listen_sock(php_socket **php_sock, int port, int backlog TSRMLS_DC) /* {{{ */ +static int php_open_listen_sock(php_socket **php_sock, int port, int backlog) /* {{{ */ { struct sockaddr_in la; struct hostent *hp; @@ -422,9 +431,9 @@ static int php_open_listen_sock(php_socket **php_sock, int port, int backlog TSR *php_sock = sock; #ifndef PHP_WIN32 - if ((hp = gethostbyname("0.0.0.0")) == NULL) { + if ((hp = php_network_gethostbyname("0.0.0.0")) == NULL) { #else - if ((hp = gethostbyname("localhost")) == NULL) { + if ((hp = php_network_gethostbyname("localhost")) == NULL) { #endif efree(sock); return 0; @@ -463,7 +472,7 @@ static int php_open_listen_sock(php_socket **php_sock, int port, int backlog TSR } /* }}} */ -static int php_accept_connect(php_socket *in_sock, php_socket **new_sock, struct sockaddr *la, socklen_t *la_len TSRMLS_DC) /* {{{ */ +static int php_accept_connect(php_socket *in_sock, php_socket **new_sock, struct sockaddr *la, socklen_t *la_len) /* {{{ */ { php_socket *out_sock = php_create_socket(); @@ -550,7 +559,7 @@ static int php_read(php_socket *sock, void *buf, size_t maxlen, int flags) } /* }}} */ -char *sockets_strerror(int error TSRMLS_DC) /* {{{ */ +char *sockets_strerror(int error) /* {{{ */ { const char *buf; @@ -600,6 +609,9 @@ char *sockets_strerror(int error TSRMLS_DC) /* {{{ */ /* {{{ PHP_GINIT_FUNCTION */ static PHP_GINIT_FUNCTION(sockets) { +#if defined(COMPILE_DL_SOCKETS) && defined(ZTS) + ZEND_TSRMLS_CACHE_UPDATE(); +#endif sockets_globals->last_error = 0; sockets_globals->strerror_buf = NULL; } @@ -609,6 +621,9 @@ static PHP_GINIT_FUNCTION(sockets) */ static PHP_MINIT_FUNCTION(sockets) { +#if defined(COMPILE_DL_SOCKETS) && defined(ZTS) + ZEND_TSRMLS_CACHE_UPDATE(); +#endif le_socket = zend_register_list_destructors_ex(php_destroy_socket, NULL, le_socket_name, module_number); REGISTER_LONG_CONSTANT("AF_UNIX", AF_UNIX, CONST_CS | CONST_PERSISTENT); @@ -707,6 +722,10 @@ static PHP_MINIT_FUNCTION(sockets) REGISTER_LONG_CONSTANT("IPV6_MULTICAST_LOOP", IPV6_MULTICAST_LOOP, CONST_CS | CONST_PERSISTENT); #endif +#ifdef IPV6_V6ONLY + REGISTER_LONG_CONSTANT("IPV6_V6ONLY", IPV6_V6ONLY, CONST_CS | CONST_PERSISTENT); +#endif + #ifndef WIN32 # include "unix_socket_constants.h" #else @@ -763,19 +782,16 @@ static PHP_RSHUTDOWN_FUNCTION(sockets) } /* }}} */ -static int php_sock_array_to_fd_set(zval *sock_array, fd_set *fds, PHP_SOCKET *max_fd TSRMLS_DC) /* {{{ */ +static int php_sock_array_to_fd_set(zval *sock_array, fd_set *fds, PHP_SOCKET *max_fd) /* {{{ */ { - zval **element; + zval *element; php_socket *php_sock; int num = 0; if (Z_TYPE_P(sock_array) != IS_ARRAY) return 0; - for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(sock_array)); - zend_hash_get_current_data(Z_ARRVAL_P(sock_array), (void **) &element) == SUCCESS; - zend_hash_move_forward(Z_ARRVAL_P(sock_array))) { - - php_sock = (php_socket*) zend_fetch_resource(element TSRMLS_CC, -1, le_socket_name, NULL, 1, le_socket); + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(sock_array), element) { + php_sock = (php_socket*) zend_fetch_resource_ex(element, le_socket_name, le_socket); if (!php_sock) continue; /* If element is not a resource, skip it */ PHP_SAFE_FD_SET(php_sock->bsd_socket, fds); @@ -783,61 +799,53 @@ static int php_sock_array_to_fd_set(zval *sock_array, fd_set *fds, PHP_SOCKET *m *max_fd = php_sock->bsd_socket; } num++; - } + } ZEND_HASH_FOREACH_END(); return num ? 1 : 0; } /* }}} */ -static int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds TSRMLS_DC) /* {{{ */ +static int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds) /* {{{ */ { - zval **element; - zval **dest_element; + zval *element; + zval *dest_element; php_socket *php_sock; - HashTable *new_hash; - char *key; + zval new_hash; int num = 0; - ulong num_key; - uint key_len; + zend_ulong num_key; + zend_string *key; if (Z_TYPE_P(sock_array) != IS_ARRAY) return 0; - ALLOC_HASHTABLE(new_hash); - zend_hash_init(new_hash, zend_hash_num_elements(Z_ARRVAL_P(sock_array)), NULL, ZVAL_PTR_DTOR, 0); - for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(sock_array)); - zend_hash_get_current_data(Z_ARRVAL_P(sock_array), (void **) &element) == SUCCESS; - zend_hash_move_forward(Z_ARRVAL_P(sock_array))) { - - php_sock = (php_socket*) zend_fetch_resource(element TSRMLS_CC, -1, le_socket_name, NULL, 1, le_socket); + array_init(&new_hash); + ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(sock_array), num_key, key, element) { + php_sock = (php_socket*) zend_fetch_resource_ex(element, le_socket_name, le_socket); if (!php_sock) continue; /* If element is not a resource, skip it */ if (PHP_SAFE_FD_ISSET(php_sock->bsd_socket, fds)) { /* Add fd to new array */ - switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(sock_array), &key, &key_len, &num_key, 0, NULL)) { - case HASH_KEY_IS_STRING: - zend_hash_add(new_hash, key, key_len, (void *)element, sizeof(zval *), (void **)&dest_element); - break; - case HASH_KEY_IS_LONG: - zend_hash_index_update(new_hash, num_key, (void *)element, sizeof(zval *), (void **)&dest_element); - break; + if (key) { + dest_element = zend_hash_add(Z_ARRVAL(new_hash), key, element); + } else { + dest_element = zend_hash_index_update(Z_ARRVAL(new_hash), num_key, element); + } + if (dest_element) { + Z_ADDREF_P(dest_element); } - if (dest_element) zval_add_ref(dest_element); } num++; - } + } ZEND_HASH_FOREACH_END(); /* Destroy old array, add new one */ - zend_hash_destroy(Z_ARRVAL_P(sock_array)); - efree(Z_ARRVAL_P(sock_array)); + zval_ptr_dtor(sock_array); - zend_hash_internal_pointer_reset(new_hash); - Z_ARRVAL_P(sock_array) = new_hash; + ZVAL_COPY_VALUE(sock_array, &new_hash); return num ? 1 : 0; } /* }}} */ -/* {{{ proto int socket_select(array &read_fds, array &write_fds, array &except_fds, int tv_sec[, int tv_usec]) U +/* {{{ proto int socket_select(array &read_fds, array &write_fds, array &except_fds, int tv_sec[, int tv_usec]) Runs the select() system call on the sets mentioned with a timeout specified by tv_sec and tv_usec */ PHP_FUNCTION(socket_select) { @@ -847,9 +855,9 @@ PHP_FUNCTION(socket_select) fd_set rfds, wfds, efds; PHP_SOCKET max_fd = 0; int retval, sets = 0; - long usec = 0; + zend_long usec = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!a!a!z!|l", &r_array, &w_array, &e_array, &sec, &usec) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/!a/!a/!z!|l", &r_array, &w_array, &e_array, &sec, &usec) == FAILURE) { return; } @@ -857,12 +865,12 @@ PHP_FUNCTION(socket_select) FD_ZERO(&wfds); FD_ZERO(&efds); - if (r_array != NULL) sets += php_sock_array_to_fd_set(r_array, &rfds, &max_fd TSRMLS_CC); - if (w_array != NULL) sets += php_sock_array_to_fd_set(w_array, &wfds, &max_fd TSRMLS_CC); - if (e_array != NULL) sets += php_sock_array_to_fd_set(e_array, &efds, &max_fd TSRMLS_CC); + if (r_array != NULL) sets += php_sock_array_to_fd_set(r_array, &rfds, &max_fd); + if (w_array != NULL) sets += php_sock_array_to_fd_set(w_array, &wfds, &max_fd); + if (e_array != NULL) sets += php_sock_array_to_fd_set(e_array, &efds, &max_fd); if (!sets) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no resource arrays were passed to select"); + php_error_docref(NULL, E_WARNING, "no resource arrays were passed to select"); RETURN_FALSE; } @@ -899,41 +907,41 @@ PHP_FUNCTION(socket_select) if (retval == -1) { SOCKETS_G(last_error) = errno; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to select [%d]: %s", errno, sockets_strerror(errno TSRMLS_CC)); + php_error_docref(NULL, E_WARNING, "unable to select [%d]: %s", errno, sockets_strerror(errno)); RETURN_FALSE; } - if (r_array != NULL) php_sock_array_from_fd_set(r_array, &rfds TSRMLS_CC); - if (w_array != NULL) php_sock_array_from_fd_set(w_array, &wfds TSRMLS_CC); - if (e_array != NULL) php_sock_array_from_fd_set(e_array, &efds TSRMLS_CC); + if (r_array != NULL) php_sock_array_from_fd_set(r_array, &rfds); + if (w_array != NULL) php_sock_array_from_fd_set(w_array, &wfds); + if (e_array != NULL) php_sock_array_from_fd_set(e_array, &efds); RETURN_LONG(retval); } /* }}} */ -/* {{{ proto resource socket_create_listen(int port[, int backlog]) U +/* {{{ proto resource socket_create_listen(int port[, int backlog]) Opens a socket on port to accept connections */ PHP_FUNCTION(socket_create_listen) { php_socket *php_sock; - long port, backlog = 128; + zend_long port, backlog = 128; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &port, &backlog) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &port, &backlog) == FAILURE) { return; } - if (!php_open_listen_sock(&php_sock, port, backlog TSRMLS_CC)) { + if (!php_open_listen_sock(&php_sock, port, backlog)) { RETURN_FALSE; } php_sock->error = 0; php_sock->blocking = 1; - ZEND_REGISTER_RESOURCE(return_value, php_sock, le_socket); + RETURN_RES(zend_register_resource(php_sock, le_socket)); } /* }}} */ -/* {{{ proto resource socket_accept(resource socket) U +/* {{{ proto resource socket_accept(resource socket) Accepts a connection on the listening socket fd */ PHP_FUNCTION(socket_accept) { @@ -942,38 +950,41 @@ PHP_FUNCTION(socket_accept) php_sockaddr_storage sa; socklen_t php_sa_len = sizeof(sa); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &arg1) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } - if (!php_accept_connect(php_sock, &new_sock, (struct sockaddr*)&sa, &php_sa_len TSRMLS_CC)) { + if (!php_accept_connect(php_sock, &new_sock, (struct sockaddr*)&sa, &php_sa_len)) { RETURN_FALSE; } - ZEND_REGISTER_RESOURCE(return_value, new_sock, le_socket); + RETURN_RES(zend_register_resource(new_sock, le_socket)); } /* }}} */ -/* {{{ proto bool socket_set_nonblock(resource socket) U +/* {{{ proto bool socket_set_nonblock(resource socket) Sets nonblocking mode on a socket resource */ PHP_FUNCTION(socket_set_nonblock) { zval *arg1; php_socket *php_sock; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &arg1) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } - if (php_sock->zstream != NULL) { + if (!Z_ISUNDEF(php_sock->zstream)) { php_stream *stream; /* omit notice if resource doesn't exist anymore */ - stream = zend_fetch_resource(&php_sock->zstream TSRMLS_CC, -1, - NULL, NULL, 2, php_file_le_stream(), php_file_le_pstream()); + stream = zend_fetch_resource2_ex(&php_sock->zstream, NULL, php_file_le_stream(), php_file_le_pstream()); if (stream != NULL) { if (php_stream_set_option(stream, PHP_STREAM_OPTION_BLOCKING, 0, NULL) != -1) { @@ -983,7 +994,7 @@ PHP_FUNCTION(socket_set_nonblock) } } - if (php_set_sock_blocking(php_sock->bsd_socket, 0 TSRMLS_CC) == SUCCESS) { + if (php_set_sock_blocking(php_sock->bsd_socket, 0) == SUCCESS) { php_sock->blocking = 0; RETURN_TRUE; } else { @@ -993,26 +1004,27 @@ PHP_FUNCTION(socket_set_nonblock) } /* }}} */ -/* {{{ proto bool socket_set_block(resource socket) U +/* {{{ proto bool socket_set_block(resource socket) Sets blocking mode on a socket resource */ PHP_FUNCTION(socket_set_block) { zval *arg1; php_socket *php_sock; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &arg1) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } /* if socket was created from a stream, give the stream a chance to take * care of the operation itself, thereby allowing it to update its internal * state */ - if (php_sock->zstream != NULL) { + if (!Z_ISUNDEF(php_sock->zstream)) { php_stream *stream; - stream = zend_fetch_resource(&php_sock->zstream TSRMLS_CC, -1, - NULL, NULL, 2, php_file_le_stream(), php_file_le_pstream()); + stream = zend_fetch_resource2_ex(&php_sock->zstream, NULL, php_file_le_stream(), php_file_le_pstream()); if (stream != NULL) { if (php_stream_set_option(stream, PHP_STREAM_OPTION_BLOCKING, 1, NULL) != -1) { @@ -1022,7 +1034,7 @@ PHP_FUNCTION(socket_set_block) } } - if (php_set_sock_blocking(php_sock->bsd_socket, 1 TSRMLS_CC) == SUCCESS) { + if (php_set_sock_blocking(php_sock->bsd_socket, 1) == SUCCESS) { php_sock->blocking = 1; RETURN_TRUE; } else { @@ -1032,19 +1044,21 @@ PHP_FUNCTION(socket_set_block) } /* }}} */ -/* {{{ proto bool socket_listen(resource socket[, int backlog]) U +/* {{{ proto bool socket_listen(resource socket[, int backlog]) Sets the maximum number of connections allowed to be waited for on the socket specified by fd */ PHP_FUNCTION(socket_listen) { zval *arg1; php_socket *php_sock; - long backlog = 0; + zend_long backlog = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &arg1, &backlog) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &arg1, &backlog) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } if (listen(php_sock->bsd_socket, backlog) != 0) { PHP_SOCKET_ERROR(php_sock, "unable to listen on socket", errno); @@ -1054,29 +1068,33 @@ PHP_FUNCTION(socket_listen) } /* }}} */ -/* {{{ proto void socket_close(resource socket) U +/* {{{ proto void socket_close(resource socket) Closes a file descriptor */ PHP_FUNCTION(socket_close) { zval *arg1; php_socket *php_sock; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &arg1) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); - if (php_sock->zstream != NULL) { + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } + + if (!Z_ISUNDEF(php_sock->zstream)) { php_stream *stream = NULL; php_stream_from_zval_no_verify(stream, &php_sock->zstream); if (stream != NULL) { /* close & destroy stream, incl. removing it from the rsrc list; * resource stored in php_sock->zstream will become invalid */ - php_stream_free(stream, PHP_STREAM_FREE_CLOSE | + php_stream_free(stream, + PHP_STREAM_FREE_KEEP_RSRC | PHP_STREAM_FREE_CLOSE | (stream->is_persistent?PHP_STREAM_FREE_CLOSE_PERSISTENT:0)); } } - zend_list_delete(Z_RESVAL_P(arg1)); + zend_list_close(Z_RES_P(arg1)); } /* }}} */ @@ -1086,15 +1104,18 @@ PHP_FUNCTION(socket_write) { zval *arg1; php_socket *php_sock; - int retval, str_len; - long length = 0; + int retval; + size_t str_len; + zend_long length = 0; char *str; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &arg1, &str, &str_len, &length) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|l", &arg1, &str, &str_len, &length) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } if (ZEND_NUM_ARGS() < 3) { length = str_len; @@ -1115,17 +1136,17 @@ PHP_FUNCTION(socket_write) } /* }}} */ -/* {{{ proto string socket_read(resource socket, int length [, int type]) U +/* {{{ proto string socket_read(resource socket, int length [, int type]) Reads a maximum of length bytes from socket */ PHP_FUNCTION(socket_read) { zval *arg1; php_socket *php_sock; - char *tmpbuf; + zend_string *tmpbuf; int retval; - long length, type = PHP_BINARY_READ; + zend_long length, type = PHP_BINARY_READ; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|l", &arg1, &length, &type) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|l", &arg1, &length, &type) == FAILURE) { return; } @@ -1134,14 +1155,16 @@ PHP_FUNCTION(socket_read) RETURN_FALSE; } - tmpbuf = emalloc(length + 1); + tmpbuf = zend_string_alloc(length, 0); - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } if (type == PHP_NORMAL_READ) { - retval = php_read(php_sock, tmpbuf, length, 0); + retval = php_read(php_sock, ZSTR_VAL(tmpbuf), length, 0); } else { - retval = recv(php_sock->bsd_socket, tmpbuf, length, 0); + retval = recv(php_sock->bsd_socket, ZSTR_VAL(tmpbuf), length, 0); } if (retval == -1) { @@ -1158,17 +1181,18 @@ PHP_FUNCTION(socket_read) PHP_SOCKET_ERROR(php_sock, "unable to read from socket", errno); } - efree(tmpbuf); + zend_string_free(tmpbuf); RETURN_FALSE; } else if (!retval) { - efree(tmpbuf); + zend_string_free(tmpbuf); RETURN_EMPTY_STRING(); } - tmpbuf = erealloc(tmpbuf, retval + 1); - tmpbuf[retval] = '\0' ; + tmpbuf = zend_string_truncate(tmpbuf, retval, 0); + ZSTR_LEN(tmpbuf) = retval; + ZSTR_VAL(tmpbuf)[ZSTR_LEN(tmpbuf)] = '\0' ; - RETURN_STRINGL(tmpbuf, retval, 0); + RETURN_NEW_STR(tmpbuf); } /* }}} */ @@ -1189,11 +1213,13 @@ PHP_FUNCTION(socket_getsockname) char *addr_string; socklen_t salen = sizeof(php_sockaddr_storage); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|z", &arg1, &addr, &port) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz/|z/", &arg1, &addr, &port) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } sa = (struct sockaddr *) &sa_storage; @@ -1202,13 +1228,17 @@ PHP_FUNCTION(socket_getsockname) RETURN_FALSE; } + if (port != NULL) { + ZVAL_DEREF(port); + } + switch (sa->sa_family) { #if HAVE_IPV6 case AF_INET6: sin6 = (struct sockaddr_in6 *) sa; inet_ntop(AF_INET6, &sin6->sin6_addr, addr6, INET6_ADDRSTRLEN); zval_dtor(addr); - ZVAL_STRING(addr, addr6, 1); + ZVAL_STRING(addr, addr6); if (port != NULL) { zval_dtor(port); @@ -1225,7 +1255,7 @@ PHP_FUNCTION(socket_getsockname) inet_ntoa_lock = 0; zval_dtor(addr); - ZVAL_STRING(addr, addr_string, 1); + ZVAL_STRING(addr, addr_string); if (port != NULL) { zval_dtor(port); @@ -1238,12 +1268,12 @@ PHP_FUNCTION(socket_getsockname) s_un = (struct sockaddr_un *) sa; zval_dtor(addr); - ZVAL_STRING(addr, s_un->sun_path, 1); + ZVAL_STRING(addr, s_un->sun_path); RETURN_TRUE; break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported address family %d", sa->sa_family); + php_error_docref(NULL, E_WARNING, "Unsupported address family %d", sa->sa_family); RETURN_FALSE; } } @@ -1266,11 +1296,13 @@ PHP_FUNCTION(socket_getpeername) char *addr_string; socklen_t salen = sizeof(php_sockaddr_storage); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|z", &arg1, &arg2, &arg3) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz/|z/", &arg1, &arg2, &arg3) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } sa = (struct sockaddr *) &sa_storage; @@ -1285,7 +1317,7 @@ PHP_FUNCTION(socket_getpeername) sin6 = (struct sockaddr_in6 *) sa; inet_ntop(AF_INET6, &sin6->sin6_addr, addr6, INET6_ADDRSTRLEN); zval_dtor(arg2); - ZVAL_STRING(arg2, addr6, 1); + ZVAL_STRING(arg2, addr6); if (arg3 != NULL) { zval_dtor(arg3); @@ -1303,7 +1335,7 @@ PHP_FUNCTION(socket_getpeername) inet_ntoa_lock = 0; zval_dtor(arg2); - ZVAL_STRING(arg2, addr_string, 1); + ZVAL_STRING(arg2, addr_string); if (arg3 != NULL) { zval_dtor(arg3); @@ -1317,25 +1349,25 @@ PHP_FUNCTION(socket_getpeername) s_un = (struct sockaddr_un *) sa; zval_dtor(arg2); - ZVAL_STRING(arg2, s_un->sun_path, 1); + ZVAL_STRING(arg2, s_un->sun_path); RETURN_TRUE; break; default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported address family %d", sa->sa_family); + php_error_docref(NULL, E_WARNING, "Unsupported address family %d", sa->sa_family); RETURN_FALSE; } } /* }}} */ -/* {{{ proto resource socket_create(int domain, int type, int protocol) U +/* {{{ proto resource socket_create(int domain, int type, int protocol) Creates an endpoint for communication in the domain specified by domain, of type specified by type */ PHP_FUNCTION(socket_create) { - long arg1, arg2, arg3; + zend_long arg1, arg2, arg3; php_socket *php_sock = php_create_socket(); - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &arg1, &arg2, &arg3) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll", &arg1, &arg2, &arg3) == FAILURE) { efree(php_sock); return; } @@ -1345,12 +1377,12 @@ PHP_FUNCTION(socket_create) && arg1 != AF_INET6 #endif && arg1 != AF_INET) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid socket domain [%ld] specified for argument 1, assuming AF_INET", arg1); + php_error_docref(NULL, E_WARNING, "invalid socket domain [%pd] specified for argument 1, assuming AF_INET", arg1); arg1 = AF_INET; } if (arg2 > 10) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid socket type [%ld] specified for argument 2, assuming SOCK_STREAM", arg2); + php_error_docref(NULL, E_WARNING, "invalid socket type [%pd] specified for argument 2, assuming SOCK_STREAM", arg2); arg2 = SOCK_STREAM; } @@ -1359,7 +1391,7 @@ PHP_FUNCTION(socket_create) if (IS_INVALID_SOCKET(php_sock)) { SOCKETS_G(last_error) = errno; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create socket [%d]: %s", errno, sockets_strerror(errno TSRMLS_CC)); + php_error_docref(NULL, E_WARNING, "Unable to create socket [%d]: %s", errno, sockets_strerror(errno)); efree(php_sock); RETURN_FALSE; } @@ -1367,7 +1399,7 @@ PHP_FUNCTION(socket_create) php_sock->error = 0; php_sock->blocking = 1; - ZEND_REGISTER_RESOURCE(return_value, php_sock, le_socket); + RETURN_RES(zend_register_resource(php_sock, le_socket)); } /* }}} */ @@ -1378,15 +1410,18 @@ PHP_FUNCTION(socket_connect) zval *arg1; php_socket *php_sock; char *addr; - int retval, addr_len; - long port = 0; + int retval; + size_t addr_len; + zend_long port = 0; int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "rs|l", &arg1, &addr, &addr_len, &port) == FAILURE) { + if (zend_parse_parameters(argc, "rs|l", &arg1, &addr, &addr_len, &port) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } switch(php_sock->type) { #if HAVE_IPV6 @@ -1394,7 +1429,7 @@ PHP_FUNCTION(socket_connect) struct sockaddr_in6 sin6 = {0}; if (argc != 3) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Socket of type AF_INET6 requires 3 arguments"); + php_error_docref(NULL, E_WARNING, "Socket of type AF_INET6 requires 3 arguments"); RETURN_FALSE; } @@ -1403,7 +1438,7 @@ PHP_FUNCTION(socket_connect) sin6.sin6_family = AF_INET6; sin6.sin6_port = htons((unsigned short int)port); - if (! php_set_inet6_addr(&sin6, addr, php_sock TSRMLS_CC)) { + if (! php_set_inet6_addr(&sin6, addr, php_sock)) { RETURN_FALSE; } @@ -1415,14 +1450,14 @@ PHP_FUNCTION(socket_connect) struct sockaddr_in sin = {0}; if (argc != 3) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Socket of type AF_INET requires 3 arguments"); + php_error_docref(NULL, E_WARNING, "Socket of type AF_INET requires 3 arguments"); RETURN_FALSE; } sin.sin_family = AF_INET; sin.sin_port = htons((unsigned short int)port); - if (! php_set_inet_addr(&sin, addr, php_sock TSRMLS_CC)) { + if (! php_set_inet_addr(&sin, addr, php_sock)) { RETURN_FALSE; } @@ -1434,7 +1469,7 @@ PHP_FUNCTION(socket_connect) struct sockaddr_un s_un = {0}; if (addr_len >= sizeof(s_un.sun_path)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Path too long"); + php_error_docref(NULL, E_WARNING, "Path too long"); RETURN_FALSE; } @@ -1446,7 +1481,7 @@ PHP_FUNCTION(socket_connect) } default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported socket type %d", php_sock->type); + php_error_docref(NULL, E_WARNING, "Unsupported socket type %d", php_sock->type); RETURN_FALSE; } @@ -1463,13 +1498,13 @@ PHP_FUNCTION(socket_connect) Returns a string describing an error */ PHP_FUNCTION(socket_strerror) { - long arg1; + zend_long arg1; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &arg1) == FAILURE) { return; } - RETURN_STRING(sockets_strerror(arg1 TSRMLS_CC), 1); + RETURN_STRING(sockets_strerror(arg1)); } /* }}} */ @@ -1482,15 +1517,17 @@ PHP_FUNCTION(socket_bind) struct sockaddr *sock_type = (struct sockaddr*) &sa_storage; php_socket *php_sock; char *addr; - int addr_len; - long port = 0; - long retval = 0; + size_t addr_len; + zend_long port = 0; + zend_long retval = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &arg1, &addr, &addr_len, &port) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|l", &arg1, &addr, &addr_len, &port) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } switch(php_sock->type) { case AF_UNIX: @@ -1500,7 +1537,7 @@ PHP_FUNCTION(socket_bind) sa->sun_family = AF_UNIX; if (addr_len >= sizeof(sa->sun_path)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, + php_error_docref(NULL, E_WARNING, "Invalid path: too long (maximum size is %d)", (int)sizeof(sa->sun_path) - 1); RETURN_FALSE; @@ -1519,7 +1556,7 @@ PHP_FUNCTION(socket_bind) sa->sin_family = AF_INET; sa->sin_port = htons((unsigned short) port); - if (! php_set_inet_addr(sa, addr, php_sock TSRMLS_CC)) { + if (! php_set_inet_addr(sa, addr, php_sock)) { RETURN_FALSE; } @@ -1534,7 +1571,7 @@ PHP_FUNCTION(socket_bind) sa->sin6_family = AF_INET6; sa->sin6_port = htons((unsigned short) port); - if (! php_set_inet6_addr(sa, addr, php_sock TSRMLS_CC)) { + if (! php_set_inet6_addr(sa, addr, php_sock)) { RETURN_FALSE; } @@ -1543,7 +1580,7 @@ PHP_FUNCTION(socket_bind) } #endif default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unsupported socket type '%d', must be AF_UNIX, AF_INET, or AF_INET6", php_sock->type); + php_error_docref(NULL, E_WARNING, "unsupported socket type '%d', must be AF_UNIX, AF_INET, or AF_INET6", php_sock->type); RETURN_FALSE; } @@ -1561,39 +1598,38 @@ PHP_FUNCTION(socket_bind) PHP_FUNCTION(socket_recv) { zval *php_sock_res, *buf; - char *recv_buf; + zend_string *recv_buf; php_socket *php_sock; int retval; - long len, flags; + zend_long len, flags; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rzll", &php_sock_res, &buf, &len, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz/ll", &php_sock_res, &buf, &len, &flags) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &php_sock_res, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(php_sock_res), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } /* overflow check */ if ((len + 1) < 2) { RETURN_FALSE; } - recv_buf = emalloc(len + 1); - memset(recv_buf, 0, len + 1); + recv_buf = zend_string_alloc(len, 0); - if ((retval = recv(php_sock->bsd_socket, recv_buf, len, flags)) < 1) { + if ((retval = recv(php_sock->bsd_socket, ZSTR_VAL(recv_buf), len, flags)) < 1) { efree(recv_buf); zval_dtor(buf); - Z_TYPE_P(buf) = IS_NULL; + ZVAL_NULL(buf); } else { - recv_buf[retval] = '\0'; + ZSTR_LEN(recv_buf) = retval; + ZSTR_VAL(recv_buf)[ZSTR_LEN(recv_buf)] = '\0'; /* Rebuild buffer zval */ zval_dtor(buf); - - Z_STRVAL_P(buf) = recv_buf; - Z_STRLEN_P(buf) = retval; - Z_TYPE_P(buf) = IS_STRING; + ZVAL_NEW_STR(buf, recv_buf); } if (retval == -1) { @@ -1611,15 +1647,17 @@ PHP_FUNCTION(socket_send) { zval *arg1; php_socket *php_sock; - int buf_len, retval; - long len, flags; + size_t buf_len, retval; + zend_long len, flags; char *buf; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsll", &arg1, &buf, &buf_len, &len, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rsll", &arg1, &buf, &buf_len, &len, &flags) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } retval = send(php_sock->bsd_socket, buf, (buf_len < len ? buf_len : len), flags); @@ -1646,40 +1684,44 @@ PHP_FUNCTION(socket_recvfrom) #endif socklen_t slen; int retval; - long arg3, arg4; - char *recv_buf, *address; + zend_long arg3, arg4; + char *address; + zend_string *recv_buf; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rzllz|z", &arg1, &arg2, &arg3, &arg4, &arg5, &arg6) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rz/llz/|z/", &arg1, &arg2, &arg3, &arg4, &arg5, &arg6) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } /* overflow check */ if ((arg3 + 2) < 3) { RETURN_FALSE; } - recv_buf = emalloc(arg3 + 2); - memset(recv_buf, 0, arg3 + 2); + recv_buf = zend_string_alloc(arg3 + 1, 0); switch (php_sock->type) { case AF_UNIX: slen = sizeof(s_un); s_un.sun_family = AF_UNIX; - retval = recvfrom(php_sock->bsd_socket, recv_buf, arg3, arg4, (struct sockaddr *)&s_un, (socklen_t *)&slen); + retval = recvfrom(php_sock->bsd_socket, ZSTR_VAL(recv_buf), arg3, arg4, (struct sockaddr *)&s_un, (socklen_t *)&slen); if (retval < 0) { PHP_SOCKET_ERROR(php_sock, "unable to recvfrom", errno); - efree(recv_buf); + zend_string_free(recv_buf); RETURN_FALSE; } + ZSTR_LEN(recv_buf) = retval; + ZSTR_VAL(recv_buf)[ZSTR_LEN(recv_buf)] = '\0'; zval_dtor(arg2); zval_dtor(arg5); - ZVAL_STRINGL(arg2, recv_buf, retval, 0); - ZVAL_STRING(arg5, s_un.sun_path, 1); + ZVAL_NEW_STR(arg2, recv_buf); + ZVAL_STRING(arg5, s_un.sun_path); break; case AF_INET: @@ -1688,17 +1730,19 @@ PHP_FUNCTION(socket_recvfrom) sin.sin_family = AF_INET; if (arg6 == NULL) { - efree(recv_buf); + zend_string_free(recv_buf); WRONG_PARAM_COUNT; } - retval = recvfrom(php_sock->bsd_socket, recv_buf, arg3, arg4, (struct sockaddr *)&sin, (socklen_t *)&slen); + retval = recvfrom(php_sock->bsd_socket, ZSTR_VAL(recv_buf), arg3, arg4, (struct sockaddr *)&sin, (socklen_t *)&slen); if (retval < 0) { PHP_SOCKET_ERROR(php_sock, "unable to recvfrom", errno); - efree(recv_buf); + zend_string_free(recv_buf); RETURN_FALSE; } + ZSTR_LEN(recv_buf) = retval; + ZSTR_VAL(recv_buf)[ZSTR_LEN(recv_buf)] = '\0'; zval_dtor(arg2); zval_dtor(arg5); @@ -1706,8 +1750,8 @@ PHP_FUNCTION(socket_recvfrom) address = inet_ntoa(sin.sin_addr); - ZVAL_STRINGL(arg2, recv_buf, retval, 0); - ZVAL_STRING(arg5, address ? address : "0.0.0.0", 1); + ZVAL_NEW_STR(arg2, recv_buf); + ZVAL_STRING(arg5, address ? address : "0.0.0.0"); ZVAL_LONG(arg6, ntohs(sin.sin_port)); break; #if HAVE_IPV6 @@ -1721,13 +1765,15 @@ PHP_FUNCTION(socket_recvfrom) WRONG_PARAM_COUNT; } - retval = recvfrom(php_sock->bsd_socket, recv_buf, arg3, arg4, (struct sockaddr *)&sin6, (socklen_t *)&slen); + retval = recvfrom(php_sock->bsd_socket, ZSTR_VAL(recv_buf), arg3, arg4, (struct sockaddr *)&sin6, (socklen_t *)&slen); if (retval < 0) { PHP_SOCKET_ERROR(php_sock, "unable to recvfrom", errno); - efree(recv_buf); + zend_string_free(recv_buf); RETURN_FALSE; } + ZSTR_LEN(recv_buf) = retval; + ZSTR_VAL(recv_buf)[ZSTR_LEN(recv_buf)] = '\0'; zval_dtor(arg2); zval_dtor(arg5); @@ -1736,13 +1782,13 @@ PHP_FUNCTION(socket_recvfrom) memset(addr6, 0, INET6_ADDRSTRLEN); inet_ntop(AF_INET6, &sin6.sin6_addr, addr6, INET6_ADDRSTRLEN); - ZVAL_STRINGL(arg2, recv_buf, retval, 0); - ZVAL_STRING(arg5, addr6[0] ? addr6 : "::", 1); + ZVAL_NEW_STR(arg2, recv_buf); + ZVAL_STRING(arg5, addr6[0] ? addr6 : "::"); ZVAL_LONG(arg6, ntohs(sin6.sin6_port)); break; #endif default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported socket type %d", php_sock->type); + php_error_docref(NULL, E_WARNING, "Unsupported socket type %d", php_sock->type); RETURN_FALSE; } @@ -1761,16 +1807,19 @@ PHP_FUNCTION(socket_sendto) #if HAVE_IPV6 struct sockaddr_in6 sin6; #endif - int retval, buf_len, addr_len; - long len, flags, port = 0; + int retval; + size_t buf_len, addr_len; + zend_long len, flags, port = 0; char *buf, *addr; int argc = ZEND_NUM_ARGS(); - if (zend_parse_parameters(argc TSRMLS_CC, "rslls|l", &arg1, &buf, &buf_len, &len, &flags, &addr, &addr_len, &port) == FAILURE) { + if (zend_parse_parameters(argc, "rslls|l", &arg1, &buf, &buf_len, &len, &flags, &addr, &addr_len, &port) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } switch (php_sock->type) { case AF_UNIX: @@ -1790,7 +1839,7 @@ PHP_FUNCTION(socket_sendto) sin.sin_family = AF_INET; sin.sin_port = htons((unsigned short) port); - if (! php_set_inet_addr(&sin, addr, php_sock TSRMLS_CC)) { + if (! php_set_inet_addr(&sin, addr, php_sock)) { RETURN_FALSE; } @@ -1806,7 +1855,7 @@ PHP_FUNCTION(socket_sendto) sin6.sin6_family = AF_INET6; sin6.sin6_port = htons((unsigned short) port); - if (! php_set_inet6_addr(&sin6, addr, php_sock TSRMLS_CC)) { + if (! php_set_inet6_addr(&sin6, addr, php_sock)) { RETURN_FALSE; } @@ -1814,7 +1863,7 @@ PHP_FUNCTION(socket_sendto) break; #endif default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unsupported socket type %d", php_sock->type); + php_error_docref(NULL, E_WARNING, "Unsupported socket type %d", php_sock->type); RETURN_FALSE; } @@ -1827,7 +1876,7 @@ PHP_FUNCTION(socket_sendto) } /* }}} */ -/* {{{ proto mixed socket_get_option(resource socket, int level, int optname) U +/* {{{ proto mixed socket_get_option(resource socket, int level, int optname) Gets socket options for the socket */ PHP_FUNCTION(socket_get_option) { @@ -1840,13 +1889,15 @@ PHP_FUNCTION(socket_get_option) socklen_t optlen; php_socket *php_sock; int other_val; - long level, optname; + zend_long level, optname; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &arg1, &level, &optname) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rll", &arg1, &level, &optname) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } if (level == IPPROTO_IP) { switch (optname) { @@ -1858,8 +1909,8 @@ PHP_FUNCTION(socket_get_option) PHP_SOCKET_ERROR(php_sock, "unable to retrieve socket option", errno); RETURN_FALSE; } - if (php_add4_to_if_index(&if_addr, php_sock, &if_index TSRMLS_CC) == SUCCESS) { - RETURN_LONG((long) if_index); + if (php_add4_to_if_index(&if_addr, php_sock, &if_index) == SUCCESS) { + RETURN_LONG((zend_long) if_index); } else { RETURN_FALSE; } @@ -1868,7 +1919,7 @@ PHP_FUNCTION(socket_get_option) } #if HAVE_IPV6 else if (level == IPPROTO_IPV6) { - int ret = php_do_getsockopt_ipv6_rfc3542(php_sock, level, optname, return_value TSRMLS_CC); + int ret = php_do_getsockopt_ipv6_rfc3542(php_sock, level, optname, return_value); if (ret == SUCCESS) { return; } else if (ret == FAILURE) { @@ -1939,7 +1990,7 @@ PHP_FUNCTION(socket_get_option) Sets socket options for the socket */ PHP_FUNCTION(socket_set_option) { - zval *arg1, **arg4; + zval *arg1, *arg4; struct linger lv; php_socket *php_sock; int ov, optlen, retval; @@ -1948,18 +1999,20 @@ PHP_FUNCTION(socket_set_option) #else struct timeval tv; #endif - long level, optname; + zend_long level, optname; void *opt_ptr; HashTable *opt_ht; - zval **l_onoff, **l_linger; - zval **sec, **usec; + zval *l_onoff, *l_linger; + zval *sec, *usec; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllZ", &arg1, &level, &optname, &arg4) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "rllz", &arg1, &level, &optname, &arg4) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket *, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } set_errno(0); @@ -1972,15 +2025,15 @@ PHP_FUNCTION(socket_set_option) if (level == IPPROTO_IP) { - int res = php_do_setsockopt_ip_mcast(php_sock, level, optname, arg4 TSRMLS_CC); + int res = php_do_setsockopt_ip_mcast(php_sock, level, optname, arg4); HANDLE_SUBCALL(res); } #if HAVE_IPV6 else if (level == IPPROTO_IPV6) { - int res = php_do_setsockopt_ipv6_mcast(php_sock, level, optname, arg4 TSRMLS_CC); + int res = php_do_setsockopt_ipv6_mcast(php_sock, level, optname, arg4); if (res == 1) { - res = php_do_setsockopt_ipv6_rfc3542(php_sock, level, optname, arg4 TSRMLS_CC); + res = php_do_setsockopt_ipv6_rfc3542(php_sock, level, optname, arg4); } HANDLE_SUBCALL(res); } @@ -1992,22 +2045,22 @@ PHP_FUNCTION(socket_set_option) const char l_linger_key[] = "l_linger"; convert_to_array_ex(arg4); - opt_ht = HASH_OF(*arg4); + opt_ht = Z_ARRVAL_P(arg4); - if (zend_hash_find(opt_ht, l_onoff_key, sizeof(l_onoff_key), (void **)&l_onoff) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no key \"%s\" passed in optval", l_onoff_key); + if ((l_onoff = zend_hash_str_find(opt_ht, l_onoff_key, sizeof(l_onoff_key) - 1)) == NULL) { + php_error_docref(NULL, E_WARNING, "no key \"%s\" passed in optval", l_onoff_key); RETURN_FALSE; } - if (zend_hash_find(opt_ht, l_linger_key, sizeof(l_linger_key), (void **)&l_linger) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no key \"%s\" passed in optval", l_linger_key); + if ((l_linger = zend_hash_str_find(opt_ht, l_linger_key, sizeof(l_linger_key) - 1)) == NULL) { + php_error_docref(NULL, E_WARNING, "no key \"%s\" passed in optval", l_linger_key); RETURN_FALSE; } convert_to_long_ex(l_onoff); convert_to_long_ex(l_linger); - lv.l_onoff = (unsigned short)Z_LVAL_PP(l_onoff); - lv.l_linger = (unsigned short)Z_LVAL_PP(l_linger); + lv.l_onoff = (unsigned short)Z_LVAL_P(l_onoff); + lv.l_linger = (unsigned short)Z_LVAL_P(l_linger); optlen = sizeof(lv); opt_ptr = &lv; @@ -2020,26 +2073,26 @@ PHP_FUNCTION(socket_set_option) const char usec_key[] = "usec"; convert_to_array_ex(arg4); - opt_ht = HASH_OF(*arg4); + opt_ht = Z_ARRVAL_P(arg4); - if (zend_hash_find(opt_ht, sec_key, sizeof(sec_key), (void **)&sec) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no key \"%s\" passed in optval", sec_key); + if ((sec = zend_hash_str_find(opt_ht, sec_key, sizeof(sec_key) - 1)) == NULL) { + php_error_docref(NULL, E_WARNING, "no key \"%s\" passed in optval", sec_key); RETURN_FALSE; } - if (zend_hash_find(opt_ht, usec_key, sizeof(usec_key), (void **)&usec) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "no key \"%s\" passed in optval", usec_key); + if ((usec = zend_hash_str_find(opt_ht, usec_key, sizeof(usec_key) - 1)) == NULL) { + php_error_docref(NULL, E_WARNING, "no key \"%s\" passed in optval", usec_key); RETURN_FALSE; } convert_to_long_ex(sec); convert_to_long_ex(usec); #ifndef PHP_WIN32 - tv.tv_sec = Z_LVAL_PP(sec); - tv.tv_usec = Z_LVAL_PP(usec); + tv.tv_sec = Z_LVAL_P(sec); + tv.tv_usec = Z_LVAL_P(usec); optlen = sizeof(tv); opt_ptr = &tv; #else - timeout = Z_LVAL_PP(sec) * 1000 + Z_LVAL_PP(usec) / 1000; + timeout = Z_LVAL_P(sec) * 1000 + Z_LVAL_P(usec) / 1000; optlen = sizeof(int); opt_ptr = &timeout; #endif @@ -2047,9 +2100,9 @@ PHP_FUNCTION(socket_set_option) } #ifdef SO_BINDTODEVICE case SO_BINDTODEVICE: { - if (Z_TYPE_PP(arg4) == IS_STRING) { - opt_ptr = Z_STRVAL_PP(arg4); - optlen = Z_STRLEN_PP(arg4); + if (Z_TYPE_P(arg4) == IS_STRING) { + opt_ptr = Z_STRVAL_P(arg4); + optlen = Z_STRLEN_P(arg4); } else { opt_ptr = ""; optlen = 0; @@ -2061,7 +2114,7 @@ PHP_FUNCTION(socket_set_option) default: default_case: convert_to_long_ex(arg4); - ov = Z_LVAL_PP(arg4); + ov = Z_LVAL_P(arg4); optlen = sizeof(ov); opt_ptr = &ov; @@ -2079,16 +2132,16 @@ default_case: /* }}} */ #ifdef HAVE_SOCKETPAIR -/* {{{ proto bool socket_create_pair(int domain, int type, int protocol, array &fd) U +/* {{{ proto bool socket_create_pair(int domain, int type, int protocol, array &fd) Creates a pair of indistinguishable sockets and stores them in fds. */ PHP_FUNCTION(socket_create_pair) { - zval *retval[2], *fds_array_zval; + zval retval[2], *fds_array_zval; php_socket *php_sock[2]; PHP_SOCKET fds_array[2]; - long domain, type, protocol; + zend_long domain, type, protocol; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lllz", &domain, &type, &protocol, &fds_array_zval) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "lllz/", &domain, &type, &protocol, &fds_array_zval) == FAILURE) { return; } @@ -2100,18 +2153,18 @@ PHP_FUNCTION(socket_create_pair) && domain != AF_INET6 #endif && domain != AF_UNIX) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid socket domain [%ld] specified for argument 1, assuming AF_INET", domain); + php_error_docref(NULL, E_WARNING, "invalid socket domain [%pd] specified for argument 1, assuming AF_INET", domain); domain = AF_INET; } if (type > 10) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid socket type [%ld] specified for argument 2, assuming SOCK_STREAM", type); + php_error_docref(NULL, E_WARNING, "invalid socket type [%pd] specified for argument 2, assuming SOCK_STREAM", type); type = SOCK_STREAM; } if (socketpair(domain, type, protocol, fds_array) != 0) { SOCKETS_G(last_error) = errno; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "unable to create socket pair [%d]: %s", errno, sockets_strerror(errno TSRMLS_CC)); + php_error_docref(NULL, E_WARNING, "unable to create socket pair [%d]: %s", errno, sockets_strerror(errno)); efree(php_sock[0]); efree(php_sock[1]); RETURN_FALSE; @@ -2120,9 +2173,6 @@ PHP_FUNCTION(socket_create_pair) zval_dtor(fds_array_zval); array_init(fds_array_zval); - MAKE_STD_ZVAL(retval[0]); - MAKE_STD_ZVAL(retval[1]); - php_sock[0]->bsd_socket = fds_array[0]; php_sock[1]->bsd_socket = fds_array[1]; php_sock[0]->type = domain; @@ -2132,11 +2182,11 @@ PHP_FUNCTION(socket_create_pair) php_sock[0]->blocking = 1; php_sock[1]->blocking = 1; - ZEND_REGISTER_RESOURCE(retval[0], php_sock[0], le_socket); - ZEND_REGISTER_RESOURCE(retval[1], php_sock[1], le_socket); + ZVAL_RES(&retval[0], zend_register_resource(php_sock[0], le_socket)); + ZVAL_RES(&retval[1], zend_register_resource(php_sock[1], le_socket)); - add_index_zval(fds_array_zval, 0, retval[0]); - add_index_zval(fds_array_zval, 1, retval[1]); + add_index_zval(fds_array_zval, 0, &retval[0]); + add_index_zval(fds_array_zval, 1, &retval[1]); RETURN_TRUE; } @@ -2144,19 +2194,21 @@ PHP_FUNCTION(socket_create_pair) #endif #ifdef HAVE_SHUTDOWN -/* {{{ proto bool socket_shutdown(resource socket[, int how]) U +/* {{{ proto bool socket_shutdown(resource socket[, int how]) Shuts down a socket for receiving, sending, or both. */ PHP_FUNCTION(socket_shutdown) { zval *arg1; - long how_shutdown = 2; + zend_long how_shutdown = 2; php_socket *php_sock; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &arg1, &how_shutdown) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &arg1, &how_shutdown) == FAILURE) { return; } - ZEND_FETCH_RESOURCE(php_sock, php_socket*, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } if (shutdown(php_sock->bsd_socket, how_shutdown) != 0) { PHP_SOCKET_ERROR(php_sock, "unable to shutdown socket", errno); @@ -2168,19 +2220,21 @@ PHP_FUNCTION(socket_shutdown) /* }}} */ #endif -/* {{{ proto int socket_last_error([resource socket]) U +/* {{{ proto int socket_last_error([resource socket]) Returns the last socket error (either the last used or the provided socket resource) */ PHP_FUNCTION(socket_last_error) { zval *arg1 = NULL; php_socket *php_sock; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &arg1) == FAILURE) { return; } if (arg1) { - ZEND_FETCH_RESOURCE(php_sock, php_socket*, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } RETVAL_LONG(php_sock->error); } else { RETVAL_LONG(SOCKETS_G(last_error)); @@ -2188,19 +2242,21 @@ PHP_FUNCTION(socket_last_error) } /* }}} */ -/* {{{ proto void socket_clear_error([resource socket]) U +/* {{{ proto void socket_clear_error([resource socket]) Clears the error on the socket or the last error code. */ PHP_FUNCTION(socket_clear_error) { zval *arg1 = NULL; php_socket *php_sock; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|r", &arg1) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &arg1) == FAILURE) { return; } if (arg1) { - ZEND_FETCH_RESOURCE(php_sock, php_socket*, &arg1, -1, le_socket_name, le_socket); + if ((php_sock = (php_socket *)zend_fetch_resource(Z_RES_P(arg1), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } php_sock->error = 0; } else { SOCKETS_G(last_error) = 0; @@ -2210,7 +2266,7 @@ PHP_FUNCTION(socket_clear_error) } /* }}} */ -php_socket *socket_import_file_descriptor(PHP_SOCKET socket TSRMLS_DC) +php_socket *socket_import_file_descriptor(PHP_SOCKET socket) { #ifdef SO_DOMAIN int type; @@ -2257,7 +2313,7 @@ error: return NULL; } -/* {{{ proto void socket_import_stream(resource stream) +/* {{{ proto resource socket_import_stream(resource stream) Imports a stream that encapsulates a socket into a socket extension resource. */ PHP_FUNCTION(socket_import_stream) { @@ -2266,17 +2322,17 @@ PHP_FUNCTION(socket_import_stream) php_socket *retsock = NULL; PHP_SOCKET socket; /* fd */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &zstream) == FAILURE) { return; } - php_stream_from_zval(stream, &zstream); + php_stream_from_zval(stream, zstream); if (php_stream_cast(stream, PHP_STREAM_AS_SOCKETD, (void**)&socket, 1)) { /* error supposedly already shown */ RETURN_FALSE; } - retsock = socket_import_file_descriptor(socket TSRMLS_CC); + retsock = socket_import_file_descriptor(socket); if (retsock == NULL) { RETURN_FALSE; } @@ -2293,18 +2349,110 @@ PHP_FUNCTION(socket_import_stream) #endif /* hold a zval reference to the stream (holding a php_stream* directly could - * also be done, but this might be slightly better if in the future we want - * to provide a socket_export_stream) */ - MAKE_STD_ZVAL(retsock->zstream); - *retsock->zstream = *zstream; - zval_copy_ctor(retsock->zstream); - Z_UNSET_ISREF_P(retsock->zstream); - Z_SET_REFCOUNT_P(retsock->zstream, 1); + * also be done, but this makes socket_export_stream a bit simpler) */ + ZVAL_COPY(&retsock->zstream, zstream); php_stream_set_option(stream, PHP_STREAM_OPTION_READ_BUFFER, PHP_STREAM_BUFFER_NONE, NULL); - ZEND_REGISTER_RESOURCE(return_value, retsock, le_socket); + RETURN_RES(zend_register_resource(retsock, le_socket)); +} +/* }}} */ + +/* {{{ proto resource socket_export_stream(resource socket) + Exports a socket extension resource into a stream that encapsulates a socket. */ +PHP_FUNCTION(socket_export_stream) +{ + zval *zsocket; + php_socket *socket; + php_stream *stream = NULL; + php_netstream_data_t *stream_data; + char *protocol = NULL; + size_t protocollen = 0; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zsocket) == FAILURE) { + return; + } + if ((socket = (php_socket *) zend_fetch_resource(Z_RES_P(zsocket), le_socket_name, le_socket)) == NULL) { + RETURN_FALSE; + } + + /* Either we already exported a stream or the socket came from an import, + * just return the existing stream */ + if (!Z_ISUNDEF(socket->zstream)) { + RETURN_ZVAL(&socket->zstream, 1, 0); + } + + /* Determine if socket is using a protocol with one of the default registered + * socket stream wrappers */ + if (socket->type == PF_INET +#if HAVE_IPV6 + || socket->type == PF_INET6 +#endif + ) { + int protoid; + socklen_t protoidlen = sizeof(protoid); + + getsockopt(socket->bsd_socket, SOL_SOCKET, SO_TYPE, (char *) &protoid, &protoidlen); + + if (protoid == SOCK_STREAM) { + /* SO_PROTOCOL is not (yet?) supported on OS X, so lets assume it's TCP there */ +#ifdef SO_PROTOCOL + protoidlen = sizeof(protoid); + getsockopt(socket->bsd_socket, SOL_SOCKET, SO_PROTOCOL, (char *) &protoid, &protoidlen); + if (protoid == IPPROTO_TCP) +#endif + { + protocol = "tcp"; + protocollen = 3; + } + } else if (protoid == SOCK_DGRAM) { + protocol = "udp"; + protocollen = 3; + } +#ifdef PF_UNIX + } else if (socket->type == PF_UNIX) { + int type; + socklen_t typelen = sizeof(type); + + getsockopt(socket->bsd_socket, SOL_SOCKET, SO_TYPE, (char *) &type, &typelen); + + if (type == SOCK_STREAM) { + protocol = "unix"; + protocollen = 4; + } else if (type == SOCK_DGRAM) { + protocol = "udg"; + protocollen = 3; + } +#endif + } + + /* Try to get a stream with the registered sockops for the protocol in use + * We don't want streams to actually *do* anything though, so don't give it + * anything apart from the protocol */ + if (protocol != NULL) { + stream = php_stream_xport_create(protocol, protocollen, 0, 0, NULL, NULL, NULL, NULL, NULL); + } + + /* Fall back to creating a generic socket stream */ + if (stream == NULL) { + stream = php_stream_sock_open_from_socket(socket->bsd_socket, 0); + + if (stream == NULL) { + php_error_docref(NULL, E_WARNING, "failed to create stream"); + RETURN_FALSE; + } + } + + stream_data = (php_netstream_data_t *) stream->abstract; + stream_data->socket = socket->bsd_socket; + stream_data->is_blocked = socket->blocking; + stream_data->timeout.tv_sec = FG(default_socket_timeout); + stream_data->timeout.tv_usec = 0; + + php_stream_to_zval(stream, &socket->zstream); + + RETURN_ZVAL(&socket->zstream, 1, 0); } /* }}} */ diff --git a/ext/sockets/sockets.dsp b/ext/sockets/sockets.dsp deleted file mode 100644 index 961bab784d..0000000000 --- a/ext/sockets/sockets.dsp +++ /dev/null @@ -1,117 +0,0 @@ -# Microsoft Developer Studio Project File - Name="sockets" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
-
-CFG=sockets - Win32 Debug_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "sockets.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "sockets.mak" CFG="sockets - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "sockets - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE "sockets - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-MTL=midl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "sockets - Win32 Release_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "Release_TS"
-# PROP BASE Intermediate_Dir "Release_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SOCKETS_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\..\bindlib_w32" /D "WIN32" /D "PHP_EXPORTS" /D "COMPILE_DL_SOCKETS" /D ZTS=1 /D HAVE_SOCKETS=1 /D ZEND_DEBUG=0 /D "NDEBUG" /D "_WINDOWS" /D "ZEND_WIN32" /D "PHP_WIN32" /YX /FD /c
-# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x407 /d "NDEBUG"
-# ADD RSC /l 0x407 /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
-# ADD LINK32 php5ts.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_sockets.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline"
-# SUBTRACT LINK32 /debug
-
-!ELSEIF "$(CFG)" == "sockets - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "Debug_TS"
-# PROP BASE Intermediate_Dir "Debug_TS"
-# PROP BASE Ignore_Export_Lib 0
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Ignore_Export_Lib 0
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SOCKETS_EXPORTS" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\..\bindlib_w32" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "PHP_EXPORTS" /D "COMPILE_DL_SOCKETS" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_SOCKETS=1 /YX /FD /GZ /c
-# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
-# ADD BASE RSC /l 0x407 /d "_DEBUG"
-# ADD RSC /l 0x407 /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LINK32=link.exe
-# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
-# ADD LINK32 php5ts_debug.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"..\..\Debug_TS/php_sockets.dll" /pdbtype:sept /libpath:"..\..\Debug_TS"
-
-!ENDIF
-
-# Begin Target
-
-# Name "sockets - Win32 Release_TS"
-# Name "sockets - Win32 Debug_TS"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\php_sockets_win.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\sockets.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\php_sockets.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\php_sockets_win.h
-# End Source File
-# End Group
-# End Target
-# End Project
diff --git a/ext/sockets/tests/socket_cmsg_rights.phpt b/ext/sockets/tests/socket_cmsg_rights.phpt index 7b750f16a8..e4d1f03b87 100644 --- a/ext/sockets/tests/socket_cmsg_rights.phpt +++ b/ext/sockets/tests/socket_cmsg_rights.phpt @@ -52,7 +52,7 @@ checktimeout($s, 500); $data = [ "name" => [], "buffer_size" => 2000, - "controllen" => socket_cmsg_space(SOL_SOCKET, SCM_RIGHTS, 3) + "controllen" => socket_cmsg_space(SOL_SOCKET, SCM_RIGHTS, 4) ]; var_dump($data); if (!socket_recvmsg($s, $data, 0)) die("recvmsg"); @@ -71,7 +71,7 @@ array(3) { ["buffer_size"]=> int(2000) ["controllen"]=> - int(32) + int(%d) } Array ( diff --git a/ext/sockets/tests/socket_connect_error.phpt b/ext/sockets/tests/socket_connect_error.phpt index 33e60f3d54..483763aed3 100644 --- a/ext/sockets/tests/socket_connect_error.phpt +++ b/ext/sockets/tests/socket_connect_error.phpt @@ -29,5 +29,5 @@ Warning: socket_create() expects exactly 3 parameters, 0 given in %s on line %d Warning: socket_create() expects exactly 3 parameters, 2 given in %s on line %d -Warning: socket_create() expects parameter 1 to be long, array given in %s on line %d +Warning: socket_create() expects parameter 1 to be integer, array given in %s on line %d diff --git a/ext/sockets/tests/socket_create_listen-wrongparams.phpt b/ext/sockets/tests/socket_create_listen-wrongparams.phpt index ecc5172e30..608678aaca 100644 --- a/ext/sockets/tests/socket_create_listen-wrongparams.phpt +++ b/ext/sockets/tests/socket_create_listen-wrongparams.phpt @@ -10,9 +10,9 @@ if (!extension_loaded('sockets')) { $sock1 = socket_create_listen(array()); $sock2 = socket_create_listen(31337, array()); --EXPECTF-- -Warning: socket_create_listen() expects parameter 1 to be long, array given in %s on line %d +Warning: socket_create_listen() expects parameter 1 to be integer, array given in %s on line %d -Warning: socket_create_listen() expects parameter 2 to be long, array given in %s on line %d +Warning: socket_create_listen() expects parameter 2 to be integer, array given in %s on line %d --CREDITS-- Till Klampaeckel, till@php.net PHP Testfest Berlin 2009-05-09 diff --git a/ext/sockets/tests/socket_create_pair-wrongparams-win32.phpt b/ext/sockets/tests/socket_create_pair-wrongparams-win32.phpt index de33d951f3..1691496772 100644 --- a/ext/sockets/tests/socket_create_pair-wrongparams-win32.phpt +++ b/ext/sockets/tests/socket_create_pair-wrongparams-win32.phpt @@ -24,7 +24,7 @@ var_dump(socket_create_pair(AF_INET, 31337, 0, $sockets)); Warning: socket_create_pair() expects exactly 4 parameters, 3 given in %s on line %d NULL -Warning: socket_create_pair() expects parameter 1 to be long, %unicode_string_optional% given in %s on line %d +Warning: socket_create_pair() expects parameter 1 to be integer, %unicode_string_optional% given in %s on line %d NULL bool(true) diff --git a/ext/sockets/tests/socket_create_pair-wrongparams.phpt b/ext/sockets/tests/socket_create_pair-wrongparams.phpt index afca2b899a..5286f3a91f 100644 --- a/ext/sockets/tests/socket_create_pair-wrongparams.phpt +++ b/ext/sockets/tests/socket_create_pair-wrongparams.phpt @@ -24,7 +24,7 @@ var_dump(socket_create_pair(AF_INET, 31337, 0, $sockets)); Warning: socket_create_pair() expects exactly 4 parameters, 3 given in %s on line %d NULL -Warning: socket_create_pair() expects parameter 1 to be long, %unicode_string_optional% given in %s on line %d +Warning: socket_create_pair() expects parameter 1 to be integer, %unicode_string_optional% given in %s on line %d NULL Warning: socket_create_pair(): unable to create socket pair [%d]: %s not supported in %s on line %d diff --git a/ext/sockets/tests/socket_export_stream-1.phpt b/ext/sockets/tests/socket_export_stream-1.phpt new file mode 100644 index 0000000000..498e0a277c --- /dev/null +++ b/ext/sockets/tests/socket_export_stream-1.phpt @@ -0,0 +1,27 @@ +--TEST-- +socket_export_stream: Basic test +--SKIPIF-- +<?php +if (!extension_loaded('sockets')) { + die('SKIP sockets extension not available.'); +} + +--FILE-- +<?php + +$domain = (strtoupper(substr(PHP_OS, 0, 3) == 'WIN') ? AF_INET : AF_UNIX); +socket_create_pair($domain, SOCK_STREAM, 0, $s); + +$s0 = reset($s); +$s1 = next($s); + +$stream = socket_export_stream($s0); +var_dump($stream); + +socket_write($s1, "test message"); +socket_close($s1); + +var_dump(stream_get_contents($stream)); +--EXPECTF-- +resource(%d) of type (stream) +string(12) "test message" diff --git a/ext/sockets/tests/socket_export_stream-2.phpt b/ext/sockets/tests/socket_export_stream-2.phpt new file mode 100644 index 0000000000..98528420fa --- /dev/null +++ b/ext/sockets/tests/socket_export_stream-2.phpt @@ -0,0 +1,48 @@ +--TEST-- +socket_export_stream: Bad arguments +--SKIPIF-- +<?php +if (!extension_loaded('sockets')) { + die('SKIP sockets extension not available.'); +} + +--FILE-- +<?php + +var_dump(socket_export_stream()); +var_dump(socket_export_stream(1, 2)); +var_dump(socket_export_stream(1)); +var_dump(socket_export_stream(new stdclass)); +var_dump(socket_export_stream(fopen(__FILE__, "rb"))); +var_dump(socket_export_stream(stream_socket_server("udp://127.0.0.1:58392", $errno, $errstr, STREAM_SERVER_BIND))); +$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +var_dump($s); +socket_close($s); +var_dump(socket_export_stream($s)); + + +echo "Done."; +--EXPECTF-- +Warning: socket_export_stream() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: socket_export_stream() expects exactly 1 parameter, 2 given in %s on line %d +NULL + +Warning: socket_export_stream() expects parameter 1 to be resource, integer given in %s on line %d +NULL + +Warning: socket_export_stream() expects parameter 1 to be resource, object given in %s on line %d +NULL + +Warning: socket_export_stream(): supplied resource is not a valid Socket resource in %s on line %d +bool(false) + +Warning: socket_export_stream(): supplied resource is not a valid Socket resource in %s on line %d +bool(false) +resource(%d) of type (Socket) + +Warning: socket_export_stream(): supplied resource is not a valid Socket resource in %s on line %d +bool(false) +Done. + diff --git a/ext/sockets/tests/socket_export_stream-3.phpt b/ext/sockets/tests/socket_export_stream-3.phpt new file mode 100644 index 0000000000..b13bb34739 --- /dev/null +++ b/ext/sockets/tests/socket_export_stream-3.phpt @@ -0,0 +1,47 @@ +--TEST-- +socket_export_stream: Test with multicasting +--SKIPIF-- +<?php +if (!extension_loaded('sockets')) { + die('SKIP sockets extension not available.'); +} +$s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +$br = socket_bind($s, '0.0.0.0', 58381); +if ($br === false) + die("SKIP IPv4/port 58381 not available"); +$so = socket_set_option($s, IPPROTO_IP, MCAST_JOIN_GROUP, array( + "group" => '224.0.0.23', + "interface" => "lo", +)); +if ($so === false) + die("SKIP joining group 224.0.0.23 on interface lo failed"); +--FILE-- +<?php + +$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock, '0.0.0.0', 58381); +$stream = socket_export_stream($sock); +var_dump($stream); +$so = socket_set_option($sock, IPPROTO_IP, MCAST_JOIN_GROUP, array( + "group" => '224.0.0.23', + "interface" => "lo", +)); +var_dump($so); + +$sendsock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +var_dump($sendsock); +$br = socket_bind($sendsock, '127.0.0.1'); +$so = socket_sendto($sendsock, $m = "my message", strlen($m), 0, "224.0.0.23", 58381); +var_dump($so); + +stream_set_blocking($stream, 0); +var_dump(fread($stream, strlen($m))); +echo "Done.\n"; +--EXPECTF-- +resource(%d) of type (stream) +bool(true) +resource(%d) of type (Socket) +int(10) +string(10) "my message" +Done. + diff --git a/ext/sockets/tests/socket_export_stream-4-win.phpt b/ext/sockets/tests/socket_export_stream-4-win.phpt new file mode 100644 index 0000000000..e38db7bd08 --- /dev/null +++ b/ext/sockets/tests/socket_export_stream-4-win.phpt @@ -0,0 +1,108 @@ +--TEST-- +socket_export_stream: effects of closing +--SKIPIF-- +<?php +if (!extension_loaded('sockets')) { + die('SKIP sockets extension not available.'); +} +if(substr(PHP_OS, 0, 3) != 'WIN' ) { + die("skip Not Valid for Linux"); +} + +--FILE-- +<?php + +function test($stream, $sock) { + if ($stream !== null) { + echo "stream_set_blocking "; + print_r(stream_set_blocking($stream, 0)); + echo "\n"; + } + if ($sock !== null) { + echo "socket_set_block "; + print_r(socket_set_block($sock)); + echo "\n"; + echo "socket_get_option "; + print_r(socket_get_option($sock, SOL_SOCKET, SO_TYPE)); + echo "\n"; + } + echo "\n"; +} + +echo "normal\n"; +$sock0 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock0, '0.0.0.0', 58380); +$stream0 = socket_export_stream($sock0); +test($stream0, $sock0); + +echo "\nunset stream\n"; +$sock1 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock1, '0.0.0.0', 58381); +$stream1 = socket_export_stream($sock1); +unset($stream1); +test(null, $sock1); + +echo "\nunset socket\n"; +$sock2 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock2, '0.0.0.0', 58382); +$stream2 = socket_export_stream($sock2); +unset($sock2); +test($stream2, null); + +echo "\nclose stream\n"; +$sock3 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock3, '0.0.0.0', 58383); +$stream3 = socket_export_stream($sock3); +fclose($stream3); +test($stream3, $sock3); + +echo "\nclose socket\n"; +$sock4 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock4, '0.0.0.0', 58484); +$stream4 = socket_export_stream($sock4); +socket_close($sock4); +test($stream4, $sock4); + +echo "Done.\n"; +--EXPECTF-- +normal +stream_set_blocking 1 +socket_set_block 1 +socket_get_option 2 + + +unset stream +socket_set_block 1 +socket_get_option 2 + + +unset socket +stream_set_blocking 1 + + +close stream +stream_set_blocking +Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d + +socket_set_block +Warning: socket_set_block(): unable to set blocking mode [%d]: An operation was attempted on something that is not a socket. + in %s on line %d + +socket_get_option +Warning: socket_get_option(): unable to retrieve socket option [%d]: An operation was attempted on something that is not a socket. + in %s on line %d + + + +close socket +stream_set_blocking +Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d + +socket_set_block +Warning: socket_set_block(): supplied resource is not a valid Socket resource in %s on line %d + +socket_get_option +Warning: socket_get_option(): supplied resource is not a valid Socket resource in %s on line %d + + +Done. diff --git a/ext/sockets/tests/socket_export_stream-4.phpt b/ext/sockets/tests/socket_export_stream-4.phpt new file mode 100644 index 0000000000..ff329ec795 --- /dev/null +++ b/ext/sockets/tests/socket_export_stream-4.phpt @@ -0,0 +1,105 @@ +--TEST-- +socket_export_stream: effects of closing +--SKIPIF-- +<?php +if (!extension_loaded('sockets')) { + die('SKIP sockets extension not available.'); +} +if(substr(PHP_OS, 0, 3) == 'WIN' ) { + die("skip Not Valid for Windows"); +} +--FILE-- +<?php + +function test($stream, $sock) { + if ($stream !== null) { + echo "stream_set_blocking "; + print_r(stream_set_blocking($stream, 0)); + echo "\n"; + } + if ($sock !== null) { + echo "socket_set_block "; + print_r(socket_set_block($sock)); + echo "\n"; + echo "socket_get_option "; + print_r(socket_get_option($sock, SOL_SOCKET, SO_TYPE)); + echo "\n"; + } + echo "\n"; +} + +echo "normal\n"; +$sock0 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock0, '0.0.0.0', 58380); +$stream0 = socket_export_stream($sock0); +test($stream0, $sock0); + +echo "\nunset stream\n"; +$sock1 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock1, '0.0.0.0', 58381); +$stream1 = socket_export_stream($sock1); +unset($stream1); +test(null, $sock1); + +echo "\nunset socket\n"; +$sock2 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock2, '0.0.0.0', 58382); +$stream2 = socket_export_stream($sock2); +unset($sock2); +test($stream2, null); + +echo "\nclose stream\n"; +$sock3 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock3, '0.0.0.0', 58383); +$stream3 = socket_export_stream($sock3); +fclose($stream3); +test($stream3, $sock3); + +echo "\nclose socket\n"; +$sock4 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock4, '0.0.0.0', 58484); +$stream4 = socket_export_stream($sock4); +socket_close($sock4); +test($stream4, $sock4); + +echo "Done.\n"; +--EXPECTF-- +normal +stream_set_blocking 1 +socket_set_block 1 +socket_get_option 2 + + +unset stream +socket_set_block 1 +socket_get_option 2 + + +unset socket +stream_set_blocking 1 + + +close stream +stream_set_blocking +Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d + +socket_set_block +Warning: socket_set_block(): unable to set blocking mode [%d]: %s in %s on line %d + +socket_get_option +Warning: socket_get_option(): unable to retrieve socket option [%d]: %s in %s on line %d + + + +close socket +stream_set_blocking +Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d + +socket_set_block +Warning: socket_set_block(): supplied resource is not a valid Socket resource in %s on line %d + +socket_get_option +Warning: socket_get_option(): supplied resource is not a valid Socket resource in %s on line %d + + +Done. diff --git a/ext/sockets/tests/socket_export_stream-5.phpt b/ext/sockets/tests/socket_export_stream-5.phpt new file mode 100644 index 0000000000..732b2072d0 --- /dev/null +++ b/ext/sockets/tests/socket_export_stream-5.phpt @@ -0,0 +1,25 @@ +--TEST-- +socket_export_stream: effects of leaked handles +--SKIPIF-- +<?php +if (!extension_loaded('sockets')) { + die('SKIP sockets extension not available.'); +} +if (!function_exists('leak_variable')) + die('SKIP only for debug builds'); +--FILE-- +<?php + +$sock0 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock0, '0.0.0.0', 58380); +$stream0 = socket_export_stream($sock0); +leak_variable($stream0, true); + +$sock1 = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); +socket_bind($sock1, '0.0.0.0', 58381); +$stream1 = socket_export_stream($sock1); +leak_variable($sock1, true); + +echo "Done.\n"; +--EXPECT-- +Done. diff --git a/ext/sockets/tests/socket_import_stream-2.phpt b/ext/sockets/tests/socket_import_stream-2.phpt index 085f0e3834..4f06bbd719 100644 --- a/ext/sockets/tests/socket_import_stream-2.phpt +++ b/ext/sockets/tests/socket_import_stream-2.phpt @@ -43,7 +43,7 @@ bool(false) resource(%d) of type (stream) bool(true) -Warning: socket_import_stream(): %d is not a valid stream resource in %s on line %d +Warning: socket_import_stream(): supplied resource is not a valid stream resource in %s on line %d bool(false) Done. diff --git a/ext/sockets/tests/socket_import_stream-4-win.phpt b/ext/sockets/tests/socket_import_stream-4-win.phpt index b36764f617..1c9a7789c6 100644 --- a/ext/sockets/tests/socket_import_stream-4-win.phpt +++ b/ext/sockets/tests/socket_import_stream-4-win.phpt @@ -77,27 +77,27 @@ stream_set_blocking 1 close stream stream_set_blocking -Warning: stream_set_blocking(): %d is not a valid stream resource in %s on line %d +Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d socket_set_block -Warning: socket_set_block(): unable to set blocking mode [%d]: An operation was attempted on something that is not a socket. +Warning: socket_set_block(): unable to set blocking mode [10038]: %s in %ssocket_import_stream-4-win.php on line %d socket_get_option -Warning: socket_get_option(): unable to retrieve socket option [%d]: An operation was attempted on something that is not a socket. +Warning: socket_get_option(): unable to retrieve socket option [10038]: %s in %ssocket_import_stream-4-win.php on line %d close socket stream_set_blocking -Warning: stream_set_blocking(): %d is not a valid stream resource in %s on line %d +Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d socket_set_block -Warning: socket_set_block(): %d is not a valid Socket resource in %s on line %d +Warning: socket_set_block(): supplied resource is not a valid Socket resource in %s on line %d socket_get_option -Warning: socket_get_option(): %d is not a valid Socket resource in %s on line %d +Warning: socket_get_option(): supplied resource is not a valid Socket resource in %s on line %d Done. diff --git a/ext/sockets/tests/socket_import_stream-4.phpt b/ext/sockets/tests/socket_import_stream-4.phpt index 8095d8dac7..4b645014d7 100644 --- a/ext/sockets/tests/socket_import_stream-4.phpt +++ b/ext/sockets/tests/socket_import_stream-4.phpt @@ -76,7 +76,7 @@ stream_set_blocking 1 close stream stream_set_blocking -Warning: stream_set_blocking(): %d is not a valid stream resource in %s on line %d +Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d socket_set_block Warning: socket_set_block(): unable to set blocking mode [%d]: %s in %s on line %d @@ -88,13 +88,13 @@ Warning: socket_get_option(): unable to retrieve socket option [%d]: %s in %s on close socket stream_set_blocking -Warning: stream_set_blocking(): %d is not a valid stream resource in %s on line %d +Warning: stream_set_blocking(): supplied resource is not a valid stream resource in %s on line %d socket_set_block -Warning: socket_set_block(): %d is not a valid Socket resource in %s on line %d +Warning: socket_set_block(): supplied resource is not a valid Socket resource in %s on line %d socket_get_option -Warning: socket_get_option(): %d is not a valid Socket resource in %s on line %d +Warning: socket_get_option(): supplied resource is not a valid Socket resource in %s on line %d Done. diff --git a/ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp-win32.phpt b/ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp-win32.phpt index ec965094bc..8754028f84 100644 --- a/ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp-win32.phpt +++ b/ext/sockets/tests/socket_sentto_recvfrom_ipv6_udp-win32.phpt @@ -48,7 +48,7 @@ require 'ipv6_skipif.inc'; socket_close($socket); --EXPECTF-- -Warning: socket_recvfrom(): unable to recvfrom [10022]: An invalid argument was supplied. +Warning: socket_recvfrom(): unable to recvfrom [10022]: %s in %s on line %d Warning: Wrong parameter count for socket_sendto() in %s on line %d diff --git a/ext/sockets/tests/socket_set_block-retval.phpt b/ext/sockets/tests/socket_set_block-retval.phpt index 2aa4b0e5c4..88e0029989 100644 --- a/ext/sockets/tests/socket_set_block-retval.phpt +++ b/ext/sockets/tests/socket_set_block-retval.phpt @@ -21,7 +21,7 @@ var_dump(socket_set_block($socket2)); --EXPECTF-- bool(true) -Warning: socket_set_block(): %d is not a valid Socket resource in %s on line %d +Warning: socket_set_block(): supplied resource is not a valid Socket resource in %s on line %d bool(false) --CREDITS-- Robin Mehner, robin@coding-robin.de diff --git a/ext/sockets/tests/socket_set_nonblock-retval.phpt b/ext/sockets/tests/socket_set_nonblock-retval.phpt index b90861859a..c9bb1150ab 100644 --- a/ext/sockets/tests/socket_set_nonblock-retval.phpt +++ b/ext/sockets/tests/socket_set_nonblock-retval.phpt @@ -21,7 +21,7 @@ var_dump(socket_set_nonblock($socket2)); --EXPECTF-- bool(true) -Warning: socket_set_nonblock(): %d is not a valid Socket resource in %s on line %d +Warning: socket_set_nonblock(): supplied resource is not a valid Socket resource in %s on line %d bool(false) --CREDITS-- Robin Mehner, robin@coding-robin.de diff --git a/ext/sockets/unix_socket_constants.h b/ext/sockets/unix_socket_constants.h index 51136a85d8..b8f48fdaa8 100644 --- a/ext/sockets/unix_socket_constants.h +++ b/ext/sockets/unix_socket_constants.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ @@ -21,406 +21,406 @@ /* This file is to be included by sockets.c */ #ifdef EPERM - /* Operation not permitted */ + /* Operation not permitted */ REGISTER_LONG_CONSTANT("SOCKET_EPERM", EPERM, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOENT - /* No such file or directory */ + /* No such file or directory */ REGISTER_LONG_CONSTANT("SOCKET_ENOENT", ENOENT, CONST_CS | CONST_PERSISTENT); #endif #ifdef EINTR - /* Interrupted system call */ + /* Interrupted system call */ REGISTER_LONG_CONSTANT("SOCKET_EINTR", EINTR, CONST_CS | CONST_PERSISTENT); #endif #ifdef EIO - /* I/O error */ + /* I/O error */ REGISTER_LONG_CONSTANT("SOCKET_EIO", EIO, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENXIO - /* No such device or address */ + /* No such device or address */ REGISTER_LONG_CONSTANT("SOCKET_ENXIO", ENXIO, CONST_CS | CONST_PERSISTENT); #endif #ifdef E2BIG - /* Arg list too long */ + /* Arg list too long */ REGISTER_LONG_CONSTANT("SOCKET_E2BIG", E2BIG, CONST_CS | CONST_PERSISTENT); #endif #ifdef EBADF - /* Bad file number */ + /* Bad file number */ REGISTER_LONG_CONSTANT("SOCKET_EBADF", EBADF, CONST_CS | CONST_PERSISTENT); #endif #ifdef EAGAIN - /* Try again */ + /* Try again */ REGISTER_LONG_CONSTANT("SOCKET_EAGAIN", EAGAIN, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOMEM - /* Out of memory */ + /* Out of memory */ REGISTER_LONG_CONSTANT("SOCKET_ENOMEM", ENOMEM, CONST_CS | CONST_PERSISTENT); #endif #ifdef EACCES - /* Permission denied */ + /* Permission denied */ REGISTER_LONG_CONSTANT("SOCKET_EACCES", EACCES, CONST_CS | CONST_PERSISTENT); #endif #ifdef EFAULT - /* Bad address */ + /* Bad address */ REGISTER_LONG_CONSTANT("SOCKET_EFAULT", EFAULT, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOTBLK - /* Block device required */ + /* Block device required */ REGISTER_LONG_CONSTANT("SOCKET_ENOTBLK", ENOTBLK, CONST_CS | CONST_PERSISTENT); #endif #ifdef EBUSY - /* Device or resource busy */ + /* Device or resource busy */ REGISTER_LONG_CONSTANT("SOCKET_EBUSY", EBUSY, CONST_CS | CONST_PERSISTENT); #endif #ifdef EEXIST - /* File exists */ + /* File exists */ REGISTER_LONG_CONSTANT("SOCKET_EEXIST", EEXIST, CONST_CS | CONST_PERSISTENT); #endif #ifdef EXDEV - /* Cross-device link */ + /* Cross-device link */ REGISTER_LONG_CONSTANT("SOCKET_EXDEV", EXDEV, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENODEV - /* No such device */ + /* No such device */ REGISTER_LONG_CONSTANT("SOCKET_ENODEV", ENODEV, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOTDIR - /* Not a directory */ + /* Not a directory */ REGISTER_LONG_CONSTANT("SOCKET_ENOTDIR", ENOTDIR, CONST_CS | CONST_PERSISTENT); #endif #ifdef EISDIR - /* Is a directory */ + /* Is a directory */ REGISTER_LONG_CONSTANT("SOCKET_EISDIR", EISDIR, CONST_CS | CONST_PERSISTENT); #endif #ifdef EINVAL - /* Invalid argument */ + /* Invalid argument */ REGISTER_LONG_CONSTANT("SOCKET_EINVAL", EINVAL, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENFILE - /* File table overflow */ + /* File table overflow */ REGISTER_LONG_CONSTANT("SOCKET_ENFILE", ENFILE, CONST_CS | CONST_PERSISTENT); #endif #ifdef EMFILE - /* Too many open files */ + /* Too many open files */ REGISTER_LONG_CONSTANT("SOCKET_EMFILE", EMFILE, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOTTY - /* Not a typewriter */ + /* Not a typewriter */ REGISTER_LONG_CONSTANT("SOCKET_ENOTTY", ENOTTY, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOSPC - /* No space left on device */ + /* No space left on device */ REGISTER_LONG_CONSTANT("SOCKET_ENOSPC", ENOSPC, CONST_CS | CONST_PERSISTENT); #endif #ifdef ESPIPE - /* Illegal seek */ + /* Illegal seek */ REGISTER_LONG_CONSTANT("SOCKET_ESPIPE", ESPIPE, CONST_CS | CONST_PERSISTENT); #endif #ifdef EROFS - /* Read-only file system */ + /* Read-only file system */ REGISTER_LONG_CONSTANT("SOCKET_EROFS", EROFS, CONST_CS | CONST_PERSISTENT); #endif #ifdef EMLINK - /* Too many links */ + /* Too many links */ REGISTER_LONG_CONSTANT("SOCKET_EMLINK", EMLINK, CONST_CS | CONST_PERSISTENT); #endif #ifdef EPIPE - /* Broken pipe */ + /* Broken pipe */ REGISTER_LONG_CONSTANT("SOCKET_EPIPE", EPIPE, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENAMETOOLONG - /* File name too long */ + /* File name too long */ REGISTER_LONG_CONSTANT("SOCKET_ENAMETOOLONG", ENAMETOOLONG, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOLCK - /* No record locks available */ + /* No record locks available */ REGISTER_LONG_CONSTANT("SOCKET_ENOLCK", ENOLCK, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOSYS - /* Function not implemented */ + /* Function not implemented */ REGISTER_LONG_CONSTANT("SOCKET_ENOSYS", ENOSYS, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOTEMPTY - /* Directory not empty */ + /* Directory not empty */ REGISTER_LONG_CONSTANT("SOCKET_ENOTEMPTY", ENOTEMPTY, CONST_CS | CONST_PERSISTENT); #endif #ifdef ELOOP - /* Too many symbolic links encountered */ + /* Too many symbolic links encountered */ REGISTER_LONG_CONSTANT("SOCKET_ELOOP", ELOOP, CONST_CS | CONST_PERSISTENT); #endif #ifdef EWOULDBLOCK - /* Operation would block */ + /* Operation would block */ REGISTER_LONG_CONSTANT("SOCKET_EWOULDBLOCK", EWOULDBLOCK, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOMSG - /* No message of desired type */ + /* No message of desired type */ REGISTER_LONG_CONSTANT("SOCKET_ENOMSG", ENOMSG, CONST_CS | CONST_PERSISTENT); #endif #ifdef EIDRM - /* Identifier removed */ + /* Identifier removed */ REGISTER_LONG_CONSTANT("SOCKET_EIDRM", EIDRM, CONST_CS | CONST_PERSISTENT); #endif #ifdef ECHRNG - /* Channel number out of range */ + /* Channel number out of range */ REGISTER_LONG_CONSTANT("SOCKET_ECHRNG", ECHRNG, CONST_CS | CONST_PERSISTENT); #endif #ifdef EL2NSYNC - /* Level 2 not synchronized */ + /* Level 2 not synchronized */ REGISTER_LONG_CONSTANT("SOCKET_EL2NSYNC", EL2NSYNC, CONST_CS | CONST_PERSISTENT); #endif #ifdef EL3HLT - /* Level 3 halted */ + /* Level 3 halted */ REGISTER_LONG_CONSTANT("SOCKET_EL3HLT", EL3HLT, CONST_CS | CONST_PERSISTENT); #endif #ifdef EL3RST - /* Level 3 reset */ + /* Level 3 reset */ REGISTER_LONG_CONSTANT("SOCKET_EL3RST", EL3RST, CONST_CS | CONST_PERSISTENT); #endif #ifdef ELNRNG - /* Link number out of range */ + /* Link number out of range */ REGISTER_LONG_CONSTANT("SOCKET_ELNRNG", ELNRNG, CONST_CS | CONST_PERSISTENT); #endif #ifdef EUNATCH - /* Protocol driver not attached */ + /* Protocol driver not attached */ REGISTER_LONG_CONSTANT("SOCKET_EUNATCH", EUNATCH, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOCSI - /* No CSI structure available */ + /* No CSI structure available */ REGISTER_LONG_CONSTANT("SOCKET_ENOCSI", ENOCSI, CONST_CS | CONST_PERSISTENT); #endif #ifdef EL2HLT - /* Level 2 halted */ + /* Level 2 halted */ REGISTER_LONG_CONSTANT("SOCKET_EL2HLT", EL2HLT, CONST_CS | CONST_PERSISTENT); #endif #ifdef EBADE - /* Invalid exchange */ + /* Invalid exchange */ REGISTER_LONG_CONSTANT("SOCKET_EBADE", EBADE, CONST_CS | CONST_PERSISTENT); #endif #ifdef EBADR - /* Invalid request descriptor */ + /* Invalid request descriptor */ REGISTER_LONG_CONSTANT("SOCKET_EBADR", EBADR, CONST_CS | CONST_PERSISTENT); #endif #ifdef EXFULL - /* Exchange full */ + /* Exchange full */ REGISTER_LONG_CONSTANT("SOCKET_EXFULL", EXFULL, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOANO - /* No anode */ + /* No anode */ REGISTER_LONG_CONSTANT("SOCKET_ENOANO", ENOANO, CONST_CS | CONST_PERSISTENT); #endif #ifdef EBADRQC - /* Invalid request code */ + /* Invalid request code */ REGISTER_LONG_CONSTANT("SOCKET_EBADRQC", EBADRQC, CONST_CS | CONST_PERSISTENT); #endif #ifdef EBADSLT - /* Invalid slot */ + /* Invalid slot */ REGISTER_LONG_CONSTANT("SOCKET_EBADSLT", EBADSLT, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOSTR - /* Device not a stream */ + /* Device not a stream */ REGISTER_LONG_CONSTANT("SOCKET_ENOSTR", ENOSTR, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENODATA - /* No data available */ + /* No data available */ REGISTER_LONG_CONSTANT("SOCKET_ENODATA", ENODATA, CONST_CS | CONST_PERSISTENT); #endif #ifdef ETIME - /* Timer expired */ + /* Timer expired */ REGISTER_LONG_CONSTANT("SOCKET_ETIME", ETIME, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOSR - /* Out of streams resources */ + /* Out of streams resources */ REGISTER_LONG_CONSTANT("SOCKET_ENOSR", ENOSR, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENONET - /* Machine is not on the network */ + /* Machine is not on the network */ REGISTER_LONG_CONSTANT("SOCKET_ENONET", ENONET, CONST_CS | CONST_PERSISTENT); #endif #ifdef EREMOTE - /* Object is remote */ + /* Object is remote */ REGISTER_LONG_CONSTANT("SOCKET_EREMOTE", EREMOTE, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOLINK - /* Link has been severed */ + /* Link has been severed */ REGISTER_LONG_CONSTANT("SOCKET_ENOLINK", ENOLINK, CONST_CS | CONST_PERSISTENT); #endif #ifdef EADV - /* Advertise error */ + /* Advertise error */ REGISTER_LONG_CONSTANT("SOCKET_EADV", EADV, CONST_CS | CONST_PERSISTENT); #endif #ifdef ESRMNT - /* Srmount error */ + /* Srmount error */ REGISTER_LONG_CONSTANT("SOCKET_ESRMNT", ESRMNT, CONST_CS | CONST_PERSISTENT); #endif #ifdef ECOMM - /* Communication error on send */ + /* Communication error on send */ REGISTER_LONG_CONSTANT("SOCKET_ECOMM", ECOMM, CONST_CS | CONST_PERSISTENT); #endif #ifdef EPROTO - /* Protocol error */ + /* Protocol error */ REGISTER_LONG_CONSTANT("SOCKET_EPROTO", EPROTO, CONST_CS | CONST_PERSISTENT); #endif #ifdef EMULTIHOP - /* Multihop attempted */ + /* Multihop attempted */ REGISTER_LONG_CONSTANT("SOCKET_EMULTIHOP", EMULTIHOP, CONST_CS | CONST_PERSISTENT); #endif #ifdef EBADMSG - /* Not a data message */ + /* Not a data message */ REGISTER_LONG_CONSTANT("SOCKET_EBADMSG", EBADMSG, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOTUNIQ - /* Name not unique on network */ + /* Name not unique on network */ REGISTER_LONG_CONSTANT("SOCKET_ENOTUNIQ", ENOTUNIQ, CONST_CS | CONST_PERSISTENT); #endif #ifdef EBADFD - /* File descriptor in bad state */ + /* File descriptor in bad state */ REGISTER_LONG_CONSTANT("SOCKET_EBADFD", EBADFD, CONST_CS | CONST_PERSISTENT); #endif #ifdef EREMCHG - /* Remote address changed */ + /* Remote address changed */ REGISTER_LONG_CONSTANT("SOCKET_EREMCHG", EREMCHG, CONST_CS | CONST_PERSISTENT); #endif #ifdef ERESTART - /* Interrupted system call should be restarted */ + /* Interrupted system call should be restarted */ REGISTER_LONG_CONSTANT("SOCKET_ERESTART", ERESTART, CONST_CS | CONST_PERSISTENT); #endif #ifdef ESTRPIPE - /* Streams pipe error */ + /* Streams pipe error */ REGISTER_LONG_CONSTANT("SOCKET_ESTRPIPE", ESTRPIPE, CONST_CS | CONST_PERSISTENT); #endif #ifdef EUSERS - /* Too many users */ + /* Too many users */ REGISTER_LONG_CONSTANT("SOCKET_EUSERS", EUSERS, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOTSOCK - /* Socket operation on non-socket */ + /* Socket operation on non-socket */ REGISTER_LONG_CONSTANT("SOCKET_ENOTSOCK", ENOTSOCK, CONST_CS | CONST_PERSISTENT); #endif #ifdef EDESTADDRREQ - /* Destination address required */ + /* Destination address required */ REGISTER_LONG_CONSTANT("SOCKET_EDESTADDRREQ", EDESTADDRREQ, CONST_CS | CONST_PERSISTENT); #endif #ifdef EMSGSIZE - /* Message too long */ + /* Message too long */ REGISTER_LONG_CONSTANT("SOCKET_EMSGSIZE", EMSGSIZE, CONST_CS | CONST_PERSISTENT); #endif #ifdef EPROTOTYPE - /* Protocol wrong type for socket */ + /* Protocol wrong type for socket */ REGISTER_LONG_CONSTANT("SOCKET_EPROTOTYPE", EPROTOTYPE, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOPROTOOPT - /* Protocol not available */ + /* Protocol not available */ REGISTER_LONG_CONSTANT("SOCKET_ENOPROTOOPT", ENOPROTOOPT, CONST_CS | CONST_PERSISTENT); #endif #ifdef EPROTONOSUPPORT - /* Protocol not supported */ + /* Protocol not supported */ REGISTER_LONG_CONSTANT("SOCKET_EPROTONOSUPPORT", EPROTONOSUPPORT, CONST_CS | CONST_PERSISTENT); #endif #ifdef ESOCKTNOSUPPORT - /* Socket type not supported */ + /* Socket type not supported */ REGISTER_LONG_CONSTANT("SOCKET_ESOCKTNOSUPPORT", ESOCKTNOSUPPORT, CONST_CS | CONST_PERSISTENT); #endif #ifdef EOPNOTSUPP - /* Operation not supported on transport endpoint */ + /* Operation not supported on transport endpoint */ REGISTER_LONG_CONSTANT("SOCKET_EOPNOTSUPP", EOPNOTSUPP, CONST_CS | CONST_PERSISTENT); #endif #ifdef EPFNOSUPPORT - /* Protocol family not supported */ + /* Protocol family not supported */ REGISTER_LONG_CONSTANT("SOCKET_EPFNOSUPPORT", EPFNOSUPPORT, CONST_CS | CONST_PERSISTENT); #endif #ifdef EAFNOSUPPORT - /* Address family not supported by protocol */ + /* Address family not supported by protocol */ REGISTER_LONG_CONSTANT("SOCKET_EAFNOSUPPORT", EAFNOSUPPORT, CONST_CS | CONST_PERSISTENT); #endif #ifdef EADDRINUSE - /* Address already in use */ + /* Address already in use */ REGISTER_LONG_CONSTANT("SOCKET_EADDRINUSE", EADDRINUSE, CONST_CS | CONST_PERSISTENT); #endif #ifdef EADDRNOTAVAIL - /* Cannot assign requested address */ + /* Cannot assign requested address */ REGISTER_LONG_CONSTANT("SOCKET_EADDRNOTAVAIL", EADDRNOTAVAIL, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENETDOWN - /* Network is down */ + /* Network is down */ REGISTER_LONG_CONSTANT("SOCKET_ENETDOWN", ENETDOWN, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENETUNREACH - /* Network is unreachable */ + /* Network is unreachable */ REGISTER_LONG_CONSTANT("SOCKET_ENETUNREACH", ENETUNREACH, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENETRESET - /* Network dropped connection because of reset */ + /* Network dropped connection because of reset */ REGISTER_LONG_CONSTANT("SOCKET_ENETRESET", ENETRESET, CONST_CS | CONST_PERSISTENT); #endif #ifdef ECONNABORTED - /* Software caused connection abort */ + /* Software caused connection abort */ REGISTER_LONG_CONSTANT("SOCKET_ECONNABORTED", ECONNABORTED, CONST_CS | CONST_PERSISTENT); #endif #ifdef ECONNRESET - /* Connection reset by peer */ + /* Connection reset by peer */ REGISTER_LONG_CONSTANT("SOCKET_ECONNRESET", ECONNRESET, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOBUFS - /* No buffer space available */ + /* No buffer space available */ REGISTER_LONG_CONSTANT("SOCKET_ENOBUFS", ENOBUFS, CONST_CS | CONST_PERSISTENT); #endif #ifdef EISCONN - /* Transport endpoint is already connected */ + /* Transport endpoint is already connected */ REGISTER_LONG_CONSTANT("SOCKET_EISCONN", EISCONN, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOTCONN - /* Transport endpoint is not connected */ + /* Transport endpoint is not connected */ REGISTER_LONG_CONSTANT("SOCKET_ENOTCONN", ENOTCONN, CONST_CS | CONST_PERSISTENT); #endif #ifdef ESHUTDOWN - /* Cannot send after transport endpoint shutdown */ + /* Cannot send after transport endpoint shutdown */ REGISTER_LONG_CONSTANT("SOCKET_ESHUTDOWN", ESHUTDOWN, CONST_CS | CONST_PERSISTENT); #endif #ifdef ETOOMANYREFS - /* Too many references: cannot splice */ + /* Too many references: cannot splice */ REGISTER_LONG_CONSTANT("SOCKET_ETOOMANYREFS", ETOOMANYREFS, CONST_CS | CONST_PERSISTENT); #endif #ifdef ETIMEDOUT - /* Connection timed out */ + /* Connection timed out */ REGISTER_LONG_CONSTANT("SOCKET_ETIMEDOUT", ETIMEDOUT, CONST_CS | CONST_PERSISTENT); #endif #ifdef ECONNREFUSED - /* Connection refused */ + /* Connection refused */ REGISTER_LONG_CONSTANT("SOCKET_ECONNREFUSED", ECONNREFUSED, CONST_CS | CONST_PERSISTENT); #endif #ifdef EHOSTDOWN - /* Host is down */ + /* Host is down */ REGISTER_LONG_CONSTANT("SOCKET_EHOSTDOWN", EHOSTDOWN, CONST_CS | CONST_PERSISTENT); #endif #ifdef EHOSTUNREACH - /* No route to host */ + /* No route to host */ REGISTER_LONG_CONSTANT("SOCKET_EHOSTUNREACH", EHOSTUNREACH, CONST_CS | CONST_PERSISTENT); #endif #ifdef EALREADY - /* Operation already in progress */ + /* Operation already in progress */ REGISTER_LONG_CONSTANT("SOCKET_EALREADY", EALREADY, CONST_CS | CONST_PERSISTENT); #endif #ifdef EINPROGRESS - /* Operation now in progress */ + /* Operation now in progress */ REGISTER_LONG_CONSTANT("SOCKET_EINPROGRESS", EINPROGRESS, CONST_CS | CONST_PERSISTENT); #endif #ifdef EISNAM - /* Is a named type file */ + /* Is a named type file */ REGISTER_LONG_CONSTANT("SOCKET_EISNAM", EISNAM, CONST_CS | CONST_PERSISTENT); #endif #ifdef EREMOTEIO - /* Remote I/O error */ + /* Remote I/O error */ REGISTER_LONG_CONSTANT("SOCKET_EREMOTEIO", EREMOTEIO, CONST_CS | CONST_PERSISTENT); #endif #ifdef EDQUOT - /* Quota exceeded */ + /* Quota exceeded */ REGISTER_LONG_CONSTANT("SOCKET_EDQUOT", EDQUOT, CONST_CS | CONST_PERSISTENT); #endif #ifdef ENOMEDIUM - /* No medium found */ + /* No medium found */ REGISTER_LONG_CONSTANT("SOCKET_ENOMEDIUM", ENOMEDIUM, CONST_CS | CONST_PERSISTENT); #endif #ifdef EMEDIUMTYPE - /* Wrong medium type */ + /* Wrong medium type */ REGISTER_LONG_CONSTANT("SOCKET_EMEDIUMTYPE", EMEDIUMTYPE, CONST_CS | CONST_PERSISTENT); #endif diff --git a/ext/sockets/win32_socket_constants.h b/ext/sockets/win32_socket_constants.h index c0aa54754e..302ffeff54 100644 --- a/ext/sockets/win32_socket_constants.h +++ b/ext/sockets/win32_socket_constants.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ diff --git a/ext/sockets/windows_common.h b/ext/sockets/windows_common.h index b5f3c6bdb4..4e98d96be0 100644 --- a/ext/sockets/windows_common.h +++ b/ext/sockets/windows_common.h @@ -1,6 +1,6 @@ /* +----------------------------------------------------------------------+ - | PHP Version 5 | + | PHP Version 7 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2016 The PHP Group | +----------------------------------------------------------------------+ |