]> granicus.if.org Git - php/commitdiff
ported ext/sockets
authorAnatol Belski <ab@php.net>
Tue, 19 Aug 2014 11:22:27 +0000 (13:22 +0200)
committerAnatol Belski <ab@php.net>
Tue, 19 Aug 2014 11:22:27 +0000 (13:22 +0200)
ext/sockets/conversions.c
ext/sockets/sendrecvmsg.c
ext/sockets/sockaddr_conv.c
ext/sockets/sockets.c

index fd350b264f7cfe6f722be59e0f09775dcf0b0228..7f616232b89e2dc3ffe8af329545ebe172bd28ab 100644 (file)
@@ -303,9 +303,9 @@ 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 php_int_t from_zval_integer_common(const zval *arr_value, ser_context *ctx)
 {
-       long ret = 0;
+       php_int_t ret = 0;
        zval lzval;
 
        ZVAL_NULL(&lzval);
@@ -328,7 +328,7 @@ double_case:
 
        case IS_OBJECT:
        case IS_STRING: {
-               long lval;
+               php_int_t lval;
                double dval;
 
                convert_to_string(&lzval);
@@ -363,7 +363,7 @@ double_case:
 }
 void from_zval_write_int(const zval *arr_value, char *field, ser_context *ctx)
 {
-       long lval;
+       php_int_t lval;
        int ival;
 
        lval = from_zval_integer_common(arr_value, ctx);
@@ -382,7 +382,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;
+       php_int_t lval;
        uint32_t ival;
 
        lval = from_zval_integer_common(arr_value, ctx);
@@ -401,7 +401,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;
+       php_int_t lval;
        uint16_t ival;
 
        lval = from_zval_integer_common(arr_value, ctx);
@@ -420,7 +420,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;
+       php_int_t lval;
        sa_family_t ival;
 
        lval = from_zval_integer_common(arr_value, ctx);
@@ -439,7 +439,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;
+       php_int_t lval;
        pid_t ival;
 
        lval = from_zval_integer_common(arr_value, ctx);
@@ -458,7 +458,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;
+       php_int_t lval;
        uid_t ival;
 
        lval = from_zval_integer_common(arr_value, ctx);
@@ -984,8 +984,8 @@ 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",
+                               (php_int_t)CMSG_LEN(entry->size), (php_int_t)cmsg->cmsg_len);
                return;
        }
 
@@ -1072,7 +1072,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;
+       php_int_t lval;
        struct msghdr *msghdr = (struct msghdr *)msghdr_c;
 
        lval = from_zval_integer_common(elem, ctx);
@@ -1081,8 +1081,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", (php_int_t)MAX_USER_BUFF_SIZE, lval);
                return;
        }
 
@@ -1431,7 +1431,7 @@ void to_zval_read_fd_array(const char *data, zval *zv, res_context *ctx)
 
        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)", (php_int_t)*cmsg_len, (php_int_t)data_offset);
                return;
        }
        num_elems = (*cmsg_len - data_offset) / sizeof(int);
index b9e66f1920279527eaa4e41547ea0b67a9012b6e..07740cdfe5537a8c28a8ad08faead2bcee2fa961 100644 (file)
@@ -167,7 +167,7 @@ PHP_FUNCTION(socket_sendmsg)
 {
        zval                    *zsocket,
                                        *zmsg;
-       long                    flags = 0;
+       php_int_t                       flags = 0;
        php_socket              *php_sock;
        struct msghdr   *msghdr;
        zend_llist              *allocations;
@@ -175,7 +175,7 @@ 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() TSRMLS_CC, "ra|i", &zsocket, &zmsg, &flags) == FAILURE) {
                return;
        }
 
@@ -209,7 +209,7 @@ PHP_FUNCTION(socket_recvmsg)
 {
        zval                    *zsocket,
                                        *zmsg;
-       long                    flags = 0;
+       php_int_t                       flags = 0;
        php_socket              *php_sock;
        ssize_t                 res;
        struct msghdr   *msghdr;
@@ -217,7 +217,7 @@ 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() TSRMLS_CC, "ra/|i",
                        &zsocket, &zmsg, &flags) == FAILURE) {
                return;
        }
@@ -268,17 +268,17 @@ PHP_FUNCTION(socket_recvmsg)
                RETURN_FALSE;
        }
 
-       RETURN_INT((long)res);
+       RETURN_INT((php_int_t)res);
 }
 
 PHP_FUNCTION(socket_cmsg_space)
 {
-       long                            level,
+       php_int_t                               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() TSRMLS_CC, "ii|i",
                        &level, &type, &n) == FAILURE) {
                return;
        }
@@ -295,16 +295,16 @@ PHP_FUNCTION(socket_cmsg_space)
 
        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 TSRMLS_CC, 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 > (PHP_INT_MAX - (php_int_t)entry->size -
+                       (php_int_t)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);
+                               "third argument (%pd) is too large", n);
                return;
        }
 
index ad7347f0ecb6d6434488304ca6b1236711230b2a..f5639413968b8c2c6a824462afccd396d8dd7301 100644 (file)
@@ -61,7 +61,7 @@ int php_set_inet6_addr(struct sockaddr_in6 *sin6, char *string, php_socket *php_
        }
 
        if (scope++) {
-               long lval = 0;
+               php_int_t lval = 0;
                double dval = 0;
                unsigned scope_id = 0;
 
index 9dae998577372edf6f2efcf2b33a6b5c9181323b..5ea62bbd102946d4478d49c3692a76bd2aa5975b 100644 (file)
@@ -793,7 +793,7 @@ static int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds TSRMLS_DC) /
        php_socket      *php_sock;
        zval            new_hash;
        int                     num = 0;
-       ulong       num_key;
+       php_uint_t       num_key;
        zend_string *key;
 
        if (Z_TYPE_P(sock_array) != IS_ARRAY) return 0;
@@ -836,9 +836,9 @@ PHP_FUNCTION(socket_select)
        fd_set                  rfds, wfds, efds;
        PHP_SOCKET              max_fd = 0;
        int                             retval, sets = 0;
-       long                    usec = 0;
+       php_int_t                       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() TSRMLS_CC, "a/!a/!a/!z!|i", &r_array, &w_array, &e_array, &sec, &usec) == FAILURE) {
                return;
        }
 
@@ -905,9 +905,9 @@ PHP_FUNCTION(socket_select)
 PHP_FUNCTION(socket_create_listen)
 {
        php_socket      *php_sock;
-       long            port, backlog = 128;
+       php_int_t               port, backlog = 128;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &port, &backlog) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i|i", &port, &backlog) == FAILURE) {
                return;
        }
 
@@ -1027,9 +1027,9 @@ PHP_FUNCTION(socket_listen)
 {
        zval            *arg1;
        php_socket      *php_sock;
-       long            backlog = 0;
+       php_int_t               backlog = 0;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &arg1, &backlog) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|i", &arg1, &backlog) == FAILURE) {
                return;
        }
 
@@ -1076,10 +1076,10 @@ PHP_FUNCTION(socket_write)
        zval            *arg1;
        php_socket      *php_sock;
        int                     retval, str_len;
-       long            length = 0;
+       php_int_t               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() TSRMLS_CC, "rs|i", &arg1, &str, &str_len, &length) == FAILURE) {
                return;
        }
 
@@ -1112,9 +1112,9 @@ PHP_FUNCTION(socket_read)
        php_socket      *php_sock;
        zend_string     *tmpbuf;
        int                     retval;
-       long            length, type = PHP_BINARY_READ;
+       php_int_t               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() TSRMLS_CC, "ri|i", &arg1, &length, &type) == FAILURE) {
                return;
        }
 
@@ -1326,10 +1326,10 @@ PHP_FUNCTION(socket_getpeername)
    Creates an endpoint for communication in the domain specified by domain, of type specified by type */
 PHP_FUNCTION(socket_create)
 {
-       long            arg1, arg2, arg3;
+       php_int_t               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() TSRMLS_CC, "iii", &arg1, &arg2, &arg3) == FAILURE) {
                efree(php_sock);
                return;
        }
@@ -1339,12 +1339,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 TSRMLS_CC, 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 TSRMLS_CC, E_WARNING, "invalid socket type [%pd] specified for argument 2, assuming SOCK_STREAM", arg2);
                arg2 = SOCK_STREAM;
        }
 
@@ -1373,10 +1373,10 @@ PHP_FUNCTION(socket_connect)
        php_socket                      *php_sock;
        char                            *addr;
        int                                     retval, addr_len;
-       long                            port = 0;
+       php_int_t                               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 TSRMLS_CC, "rs|i", &arg1, &addr, &addr_len, &port) == FAILURE) {
                return;
        }
 
@@ -1457,9 +1457,9 @@ PHP_FUNCTION(socket_connect)
    Returns a string describing an error */
 PHP_FUNCTION(socket_strerror)
 {
-       long    arg1;
+       php_int_t       arg1;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &arg1) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "i", &arg1) == FAILURE) {
                return;
        }
 
@@ -1477,10 +1477,10 @@ PHP_FUNCTION(socket_bind)
        php_socket                              *php_sock;
        char                                    *addr;
        int                                             addr_len;
-       long                                    port = 0;
-       long                                    retval = 0;
+       php_int_t                                       port = 0;
+       php_int_t                                       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() TSRMLS_CC, "rs|i", &arg1, &addr, &addr_len, &port) == FAILURE) {
                return;
        }
 
@@ -1558,9 +1558,9 @@ PHP_FUNCTION(socket_recv)
        zend_string     *recv_buf;
        php_socket      *php_sock;
        int                     retval;
-       long            len, flags;
+       php_int_t               len, flags;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/ll", &php_sock_res, &buf, &len, &flags) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/ii", &php_sock_res, &buf, &len, &flags) == FAILURE) {
                return;
        }
 
@@ -1603,10 +1603,10 @@ PHP_FUNCTION(socket_send)
        zval            *arg1;
        php_socket      *php_sock;
        int                     buf_len, retval;
-       long            len, flags;
+       php_int_t               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() TSRMLS_CC, "rsii", &arg1, &buf, &buf_len, &len, &flags) == FAILURE) {
                return;
        }
 
@@ -1637,11 +1637,11 @@ PHP_FUNCTION(socket_recvfrom)
 #endif
        socklen_t                       slen;
        int                                     retval;
-       long                            arg3, arg4;
+       php_int_t                               arg3, arg4;
        char                            *address;
        zend_string                     *recv_buf;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/llz/|z/", &arg1, &arg2, &arg3, &arg4, &arg5, &arg6) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz/iiz/|z/", &arg1, &arg2, &arg3, &arg4, &arg5, &arg6) == FAILURE) {
                return;
        }
 
@@ -1759,11 +1759,11 @@ PHP_FUNCTION(socket_sendto)
        struct sockaddr_in6     sin6;
 #endif
        int                                     retval, buf_len, addr_len;
-       long                            len, flags, port = 0;
+       php_int_t                               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 TSRMLS_CC, "rsiis|i", &arg1, &buf, &buf_len, &len, &flags, &addr, &addr_len, &port) == FAILURE) {
                return;
        }
 
@@ -1837,9 +1837,9 @@ PHP_FUNCTION(socket_get_option)
        socklen_t               optlen;
        php_socket              *php_sock;
        int                             other_val;
-       long                    level, optname;
+       php_int_t                       level, optname;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &arg1, &level, &optname) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rii", &arg1, &level, &optname) == FAILURE) {
                return;
        }
 
@@ -1945,14 +1945,14 @@ PHP_FUNCTION(socket_set_option)
 #else
        struct                                  timeval tv;
 #endif
-       long                                    level, optname;
+       php_int_t                                       level, optname;
        void                                    *opt_ptr;
        HashTable                               *opt_ht;
        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() TSRMLS_CC, "riiz", &arg1, &level, &optname, &arg4) == FAILURE) {
                return;
        }
 
@@ -2083,9 +2083,9 @@ PHP_FUNCTION(socket_create_pair)
        zval            retval[2], *fds_array_zval;
        php_socket      *php_sock[2];
        PHP_SOCKET      fds_array[2];
-       long            domain, type, protocol;
+       php_int_t               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() TSRMLS_CC, "iiiz/", &domain, &type, &protocol, &fds_array_zval) == FAILURE) {
                return;
        }
 
@@ -2097,12 +2097,12 @@ 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 TSRMLS_CC, 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 TSRMLS_CC, E_WARNING, "invalid socket type [%pd] specified for argument 2, assuming SOCK_STREAM", type);
                type = SOCK_STREAM;
        }
 
@@ -2143,10 +2143,10 @@ PHP_FUNCTION(socket_create_pair)
 PHP_FUNCTION(socket_shutdown)
 {
        zval            *arg1;
-       long            how_shutdown = 2;
+       php_int_t               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() TSRMLS_CC, "r|i", &arg1, &how_shutdown) == FAILURE) {
                return;
        }