55#include "common.h"
66#include "php_network.h"
77#include <sys/types.h>
8+ #ifndef _MSC_VER
89#include <netinet/tcp.h> /* TCP_NODELAY */
910#include <sys/socket.h>
11+ #endif
1012#include <ext/standard/php_smart_str.h>
1113#include <ext/standard/php_var.h>
1214
@@ -61,6 +63,8 @@ PHPAPI int redis_check_eof(RedisSock *redis_sock TSRMLS_DC)
6163
6264PHPAPI zval * redis_sock_read_multibulk_reply_zval (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock ) {
6365 char inbuf [1024 ];
66+ int numElems ;
67+ zval * z_tab ;
6468
6569 if (-1 == redis_check_eof (redis_sock TSRMLS_CC )) {
6670 return NULL ;
@@ -78,9 +82,8 @@ PHPAPI zval *redis_sock_read_multibulk_reply_zval(INTERNAL_FUNCTION_PARAMETERS,
7882 if (inbuf [0 ] != '*' ) {
7983 return NULL ;
8084 }
81- int numElems = atoi (inbuf + 1 );
85+ numElems = atoi (inbuf + 1 );
8286
83- zval * z_tab ;
8487 MAKE_STD_ZVAL (z_tab );
8588 array_init (z_tab );
8689
@@ -106,14 +109,15 @@ PHPAPI char *redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes TSRMLS_
106109 if (bytes == -1 ) {
107110 return NULL ;
108111 } else {
109- reply = emalloc (bytes + 1 );
112+ char c ;
113+ int i ;
114+
115+ reply = emalloc (bytes + 1 );
110116
111117 while (offset < bytes ) {
112118 got = php_stream_read (redis_sock -> stream , reply + offset , bytes - offset );
113119 offset += got ;
114120 }
115- char c ;
116- int i ;
117121 for (i = 0 ; i < 2 ; i ++ ) {
118122 php_stream_read (redis_sock -> stream , & c , 1 );
119123 }
@@ -128,7 +132,6 @@ PHPAPI char *redis_sock_read_bulk_reply(RedisSock *redis_sock, int bytes TSRMLS_
128132 */
129133PHPAPI char * redis_sock_read (RedisSock * redis_sock , int * buf_len TSRMLS_DC )
130134{
131-
132135 char inbuf [1024 ];
133136 char * resp = NULL ;
134137
@@ -146,7 +149,6 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
146149 }
147150
148151 switch (inbuf [0 ]) {
149-
150152 case '-' :
151153 return NULL ;
152154
@@ -156,6 +158,7 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
156158 return resp ;
157159
158160 case '+' :
161+ case '*' :
159162 case ':' :
160163 // Single Line Reply
161164 /* :123\r\n */
@@ -180,7 +183,6 @@ PHPAPI char *redis_sock_read(RedisSock *redis_sock, int *buf_len TSRMLS_DC)
180183}
181184
182185void add_constant_long (zend_class_entry * ce , char * name , int value ) {
183-
184186 zval * constval ;
185187 constval = pemalloc (sizeof (zval ), 1 );
186188 INIT_PZVAL (constval );
@@ -330,12 +332,13 @@ PHPAPI void redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *
330332
331333 char * response ;
332334 int response_len ;
335+ double ret ;
333336
334337 if ((response = redis_sock_read (redis_sock , & response_len TSRMLS_CC )) == NULL ) {
335338 RETURN_FALSE ;
336339 }
337340
338- double ret = atof (response );
341+ ret = atof (response );
339342 efree (response );
340343 IF_MULTI_OR_PIPELINE () {
341344 add_next_index_double (z_tab , ret );
@@ -347,12 +350,12 @@ PHPAPI void redis_bulk_double_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *
347350PHPAPI void redis_type_response (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock , zval * z_tab , void * ctx ) {
348351 char * response ;
349352 int response_len ;
353+ long l ;
350354
351355 if ((response = redis_sock_read (redis_sock , & response_len TSRMLS_CC )) == NULL ) {
352356 RETURN_FALSE ;
353357 }
354358
355- long l ;
356359 if (strncmp (response , "+string" , 7 ) == 0 ) {
357360 l = REDIS_STRING ;
358361 } else if (strncmp (response , "+set" , 4 ) == 0 ){
@@ -378,22 +381,23 @@ PHPAPI void redis_type_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_s
378381PHPAPI void redis_info_response (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock , zval * z_tab , void * ctx ) {
379382 char * response ;
380383 int response_len ;
384+ char * pos , * cur ;
385+ char * key , * value , * p ;
386+ int is_numeric ;
387+ zval * z_multi_result ;
381388
382389 if ((response = redis_sock_read (redis_sock , & response_len TSRMLS_CC )) == NULL ) {
383390 RETURN_FALSE ;
384391 }
385392
386- zval * z_multi_result ;
387393 MAKE_STD_ZVAL (z_multi_result );
388394 array_init (z_multi_result ); /* pre-allocate array for multi's results. */
389395 /* response :: [response_line]
390396 * response_line :: key ':' value CRLF
391397 */
392398
393- char * pos , * cur = response ;
399+ cur = response ;
394400 while (1 ) {
395- char * key , * value , * p ;
396- int is_numeric ;
397401 /* key */
398402 pos = strchr (cur , ':' );
399403 if (pos == NULL ) {
@@ -488,16 +492,16 @@ PHPAPI void redis_long_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_s
488492 }
489493
490494 if (response [0 ] == ':' ) {
491- long long ret = atoll (response + 1 );
495+ long ret = atol (response + 1 );
492496 IF_MULTI_OR_PIPELINE () {
493- if (ret > (long long )LONG_MAX ) { /* overflow */
497+ if (ret > (long )LONG_MAX ) { /* overflow */
494498 add_next_index_stringl (z_tab , response + 1 , response_len - 1 , 1 );
495499 } else {
496500 efree (response );
497501 add_next_index_long (z_tab , (long )ret );
498502 }
499503 } else {
500- if (ret > (long long )LONG_MAX ) { /* overflow */
504+ if (ret > (long )LONG_MAX ) { /* overflow */
501505 RETURN_STRINGL (response + 1 , response_len - 1 , 1 );
502506 } else {
503507 efree (response );
@@ -522,6 +526,8 @@ PHPAPI int redis_sock_read_multibulk_reply_zipped_with_flag(INTERNAL_FUNCTION_PA
522526 */
523527
524528 char inbuf [1024 ];
529+ int numElems ;
530+ zval * z_multi_result ;
525531
526532 if (-1 == redis_check_eof (redis_sock TSRMLS_CC )) {
527533 return -1 ;
@@ -539,8 +545,7 @@ PHPAPI int redis_sock_read_multibulk_reply_zipped_with_flag(INTERNAL_FUNCTION_PA
539545 if (inbuf [0 ] != '*' ) {
540546 return -1 ;
541547 }
542- int numElems = atoi (inbuf + 1 );
543- zval * z_multi_result ;
548+ numElems = atoi (inbuf + 1 );
544549 MAKE_STD_ZVAL (z_multi_result );
545550 array_init (z_multi_result ); /* pre-allocate array for multi's results. */
546551
@@ -699,6 +704,8 @@ PHPAPI int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
699704 struct timeval tv , * tv_ptr = NULL ;
700705 char * host = NULL , * persistent_id = NULL , * errstr = NULL ;
701706 int host_len , err = 0 ;
707+ php_netstream_data_t * sock ;
708+ int tcp_flag = 1 ;
702709
703710 if (redis_sock -> stream != NULL ) {
704711 redis_sock_disconnect (redis_sock TSRMLS_CC );
@@ -742,8 +749,7 @@ PHPAPI int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
742749 }
743750
744751 /* set TCP_NODELAY */
745- php_netstream_data_t * sock = (php_netstream_data_t * )redis_sock -> stream -> abstract ;
746- int tcp_flag = 1 ;
752+ sock = (php_netstream_data_t * )redis_sock -> stream -> abstract ;
747753 setsockopt (sock -> socket , IPPROTO_TCP , TCP_NODELAY , (char * ) & tcp_flag , sizeof (int ));
748754
749755 php_stream_auto_cleanup (redis_sock -> stream );
@@ -820,6 +826,8 @@ PHPAPI int redis_sock_disconnect(RedisSock *redis_sock TSRMLS_DC)
820826PHPAPI int redis_sock_read_multibulk_reply (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock , zval * z_tab , void * ctx )
821827{
822828 char inbuf [1024 ];
829+ int numElems ;
830+ zval * z_multi_result ;
823831
824832 if (-1 == redis_check_eof (redis_sock TSRMLS_CC )) {
825833 return -1 ;
@@ -836,8 +844,7 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo
836844 if (inbuf [0 ] != '*' ) {
837845 return -1 ;
838846 }
839- int numElems = atoi (inbuf + 1 );
840- zval * z_multi_result ;
847+ numElems = atoi (inbuf + 1 );
841848 MAKE_STD_ZVAL (z_multi_result );
842849 array_init (z_multi_result ); /* pre-allocate array for multi's results. */
843850
@@ -860,6 +867,8 @@ PHPAPI int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSo
860867PHPAPI int redis_sock_read_multibulk_reply_raw (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock , zval * z_tab , void * ctx )
861868{
862869 char inbuf [1024 ];
870+ int numElems ;
871+ zval * z_multi_result ;
863872
864873 if (-1 == redis_check_eof (redis_sock TSRMLS_CC )) {
865874 return -1 ;
@@ -876,8 +885,7 @@ PHPAPI int redis_sock_read_multibulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, Red
876885 if (inbuf [0 ] != '*' ) {
877886 return -1 ;
878887 }
879- int numElems = atoi (inbuf + 1 );
880- zval * z_multi_result ;
888+ numElems = atoi (inbuf + 1 );
881889 MAKE_STD_ZVAL (z_multi_result );
882890 array_init (z_multi_result ); /* pre-allocate array for multi's results. */
883891
@@ -926,6 +934,8 @@ PHPAPI int redis_sock_read_multibulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, R
926934{
927935 char inbuf [1024 ], * response ;
928936 int response_len ;
937+ int i , numElems ;
938+ zval * z_multi_result ;
929939
930940 zval * * z_keys = ctx ;
931941
@@ -944,8 +954,7 @@ PHPAPI int redis_sock_read_multibulk_reply_assoc(INTERNAL_FUNCTION_PARAMETERS, R
944954 if (inbuf [0 ] != '*' ) {
945955 return -1 ;
946956 }
947- int i , numElems = atoi (inbuf + 1 );
948- zval * z_multi_result ;
957+ numElems = atoi (inbuf + 1 );
949958 MAKE_STD_ZVAL (z_multi_result );
950959 array_init (z_multi_result ); /* pre-allocate array for multi's results. */
951960
@@ -1122,12 +1131,15 @@ redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval **re
11221131
11231132PHPAPI int
11241133redis_key_prefix (RedisSock * redis_sock , char * * key , int * key_len TSRMLS_DC ) {
1134+ int ret_len ;
1135+ char * ret ;
1136+
11251137 if (redis_sock -> prefix == NULL || redis_sock -> prefix_len == 0 ) {
11261138 return 0 ;
11271139 }
11281140
1129- int ret_len = redis_sock -> prefix_len + * key_len ;
1130- char * ret = ecalloc (1 + ret_len , 1 );
1141+ ret_len = redis_sock -> prefix_len + * key_len ;
1142+ ret = ecalloc (1 + ret_len , 1 );
11311143 memcpy (ret , redis_sock -> prefix , redis_sock -> prefix_len );
11321144 memcpy (ret + redis_sock -> prefix_len , * key , * key_len );
11331145
0 commit comments