@@ -88,9 +88,9 @@ static void setProtocolError(const char *errstr, client *c);
8888static void pauseClientsByClient (mstime_t end , int isPauseClientAll );
8989int postponeClientRead (client * c );
9090char * getClientSockname (client * c );
91- static int parseClientFiltersOrReply (client * c , int i , clientFilter * filter );
91+ static int parseClientFiltersOrReply (client * c , int index , clientFilter * filter );
9292static int clientMatchesFilter (client * client , clientFilter client_filter );
93- sds getAllFilteredClientsInfoString (clientFilter * client_filter , int hide_user_data );
93+ static sds getAllFilteredClientsInfoString (clientFilter * client_filter , int hide_user_data );
9494
9595int ProcessingEventsWhileBlocked = 0 ; /* See processEventsWhileBlocked(). */
9696__thread sds thread_shared_qb = NULL ;
@@ -3485,12 +3485,11 @@ sds getAllClientsInfoString(int type, int hide_user_data) {
34853485 return o ;
34863486}
34873487
3488- sds getAllFilteredClientsInfoString (clientFilter * client_filter , int hide_user_data ) {
3488+ static sds getAllFilteredClientsInfoString (clientFilter * client_filter , int hide_user_data ) {
34893489 listNode * ln ;
34903490 listIter li ;
34913491 client * client ;
34923492 sds o = sdsnewlen (SDS_NOINIT , 500 );
3493- sdsclear (o );
34943493 listRewind (server .clients , & li );
34953494 while ((ln = listNext (& li )) != NULL ) {
34963495 client = listNodeValue (ln );
@@ -3620,21 +3619,22 @@ void quitCommand(client *c) {
36203619 c -> flag .close_after_reply = 1 ;
36213620}
36223621
3623- static int parseClientFiltersOrReply (client * c , int i , clientFilter * filter ) {
3624- while (i < c -> argc ) {
3625- int moreargs = c -> argc > i + 1 ;
3622+ static int parseClientFiltersOrReply (client * c , int index , clientFilter * filter ) {
3623+ while (index < c -> argc ) {
3624+ int moreargs = c -> argc > index + 1 ;
36263625
3627- if (!strcasecmp (c -> argv [i ]-> ptr , "id" )) {
3626+ if (!strcasecmp (c -> argv [index ]-> ptr , "id" )) {
36283627 if (filter -> ids == NULL ) {
3629- filter -> ids = intsetNew (); // Initialize the intset for IDs
3628+ /* Initialize the intset for IDs */
3629+ filter -> ids = intsetNew ();
36303630 }
3631- i ++ ; // Move to the first ID after "ID"
3631+ index ++ ; /* Move to the first ID after "ID" */
36323632
3633- // Process all IDs until a non-numeric argument or end of args
3634- while (i < c -> argc ) {
3633+ /* Process all IDs until a non-numeric argument or end of args */
3634+ while (index < c -> argc ) {
36353635 long long id ;
3636- if (!string2ll (c -> argv [i ]-> ptr , sdslen (c -> argv [i ]-> ptr ), & id )) {
3637- break ; // Stop processing IDs if a non-numeric argument is encountered
3636+ if (!string2ll (c -> argv [index ]-> ptr , sdslen (c -> argv [index ]-> ptr ), & id )) {
3637+ break ; /* Stop processing IDs if a non-numeric argument is encountered */
36383638 }
36393639 if (id < 1 ) {
36403640 addReplyError (c , "client-id should be greater than 0" );
@@ -3643,12 +3643,12 @@ static int parseClientFiltersOrReply(client *c, int i, clientFilter *filter) {
36433643
36443644 uint8_t added ;
36453645 filter -> ids = intsetAdd (filter -> ids , id , & added );
3646- i ++ ; // Move to the next argument
3646+ index ++ ; /* Move to the next argument */
36473647 }
3648- } else if (!strcasecmp (c -> argv [i ]-> ptr , "maxage" ) && moreargs ) {
3648+ } else if (!strcasecmp (c -> argv [index ]-> ptr , "maxage" ) && moreargs ) {
36493649 long long tmp ;
36503650
3651- if (getLongLongFromObjectOrReply (c , c -> argv [i + 1 ], & tmp ,
3651+ if (getLongLongFromObjectOrReply (c , c -> argv [index + 1 ], & tmp ,
36523652 "maxage is not an integer or out of range" ) != C_OK )
36533653 return C_ERR ;
36543654 if (tmp <= 0 ) {
@@ -3657,37 +3657,37 @@ static int parseClientFiltersOrReply(client *c, int i, clientFilter *filter) {
36573657 }
36583658
36593659 filter -> max_age = tmp ;
3660- i += 2 ;
3661- } else if (!strcasecmp (c -> argv [i ]-> ptr , "type" ) && moreargs ) {
3662- filter -> type = getClientTypeByName (c -> argv [i + 1 ]-> ptr );
3660+ index += 2 ;
3661+ } else if (!strcasecmp (c -> argv [index ]-> ptr , "type" ) && moreargs ) {
3662+ filter -> type = getClientTypeByName (c -> argv [index + 1 ]-> ptr );
36633663 if (filter -> type == -1 ) {
3664- addReplyErrorFormat (c , "Unknown client type '%s'" , (char * )c -> argv [i + 1 ]-> ptr );
3664+ addReplyErrorFormat (c , "Unknown client type '%s'" , (char * )c -> argv [index + 1 ]-> ptr );
36653665 return C_ERR ;
36663666 }
3667- i += 2 ;
3668- } else if (!strcasecmp (c -> argv [i ]-> ptr , "addr" ) && moreargs ) {
3669- filter -> addr = c -> argv [i + 1 ]-> ptr ;
3670- i += 2 ;
3671- } else if (!strcasecmp (c -> argv [i ]-> ptr , "laddr" ) && moreargs ) {
3672- filter -> laddr = c -> argv [i + 1 ]-> ptr ;
3673- i += 2 ;
3674- } else if (!strcasecmp (c -> argv [i ]-> ptr , "user" ) && moreargs ) {
3675- filter -> user = ACLGetUserByName (c -> argv [i + 1 ]-> ptr , sdslen (c -> argv [i + 1 ]-> ptr ));
3667+ index += 2 ;
3668+ } else if (!strcasecmp (c -> argv [index ]-> ptr , "addr" ) && moreargs ) {
3669+ filter -> addr = c -> argv [index + 1 ]-> ptr ;
3670+ index += 2 ;
3671+ } else if (!strcasecmp (c -> argv [index ]-> ptr , "laddr" ) && moreargs ) {
3672+ filter -> laddr = c -> argv [index + 1 ]-> ptr ;
3673+ index += 2 ;
3674+ } else if (!strcasecmp (c -> argv [index ]-> ptr , "user" ) && moreargs ) {
3675+ filter -> user = ACLGetUserByName (c -> argv [index + 1 ]-> ptr , sdslen (c -> argv [index + 1 ]-> ptr ));
36763676 if (filter -> user == NULL ) {
3677- addReplyErrorFormat (c , "No such user '%s'" , (char * )c -> argv [i + 1 ]-> ptr );
3677+ addReplyErrorFormat (c , "No such user '%s'" , (char * )c -> argv [index + 1 ]-> ptr );
36783678 return C_ERR ;
36793679 }
3680- i += 2 ;
3681- } else if (!strcasecmp (c -> argv [i ]-> ptr , "skipme" ) && moreargs ) {
3682- if (!strcasecmp (c -> argv [i + 1 ]-> ptr , "yes" )) {
3680+ index += 2 ;
3681+ } else if (!strcasecmp (c -> argv [index ]-> ptr , "skipme" ) && moreargs ) {
3682+ if (!strcasecmp (c -> argv [index + 1 ]-> ptr , "yes" )) {
36833683 filter -> skipme = 1 ;
3684- } else if (!strcasecmp (c -> argv [i + 1 ]-> ptr , "no" )) {
3684+ } else if (!strcasecmp (c -> argv [index + 1 ]-> ptr , "no" )) {
36853685 filter -> skipme = 0 ;
36863686 } else {
36873687 addReplyErrorObject (c , shared .syntaxerr );
36883688 return C_ERR ;
36893689 }
3690- i += 2 ;
3690+ index += 2 ;
36913691 } else {
36923692 addReplyErrorObject (c , shared .syntaxerr );
36933693 return C_ERR ;
@@ -3697,16 +3697,16 @@ static int parseClientFiltersOrReply(client *c, int i, clientFilter *filter) {
36973697}
36983698
36993699static int clientMatchesFilter (client * client , clientFilter client_filter ) {
3700- // Check each filter condition and return false if the client does not match.
3700+ /* Check each filter condition and return false if the client does not match. */
37013701 if (client_filter .addr && strcmp (getClientPeerId (client ), client_filter .addr ) != 0 ) return 0 ;
37023702 if (client_filter .laddr && strcmp (getClientSockname (client ), client_filter .laddr ) != 0 ) return 0 ;
37033703 if (client_filter .type != -1 && getClientType (client ) != client_filter .type ) return 0 ;
37043704 if (client_filter .ids && !intsetFind (client_filter .ids , client -> id )) return 0 ;
37053705 if (client_filter .user && client -> user != client_filter .user ) return 0 ;
3706- if (client_filter .skipme && client == server .current_client ) return 0 ; // Skipme check
3706+ if (client_filter .skipme && client == server .current_client ) return 0 ;
37073707 if (client_filter .max_age != 0 && (long long )(commandTimeSnapshot () / 1000 - client -> ctime ) < client_filter .max_age ) return 0 ;
37083708
3709- // If all conditions are satisfied, the client matches the filter.
3709+ /* If all conditions are satisfied, the client matches the filter. */
37103710 return 1 ;
37113711}
37123712
@@ -3884,12 +3884,14 @@ static void clientCommandKill(client *c) {
38843884
38853885 /* New style syntax: parse options. */
38863886 if (parseClientFiltersOrReply (c , i , & client_filter ) != C_OK ) {
3887- goto client_kill_done ; // Free the intset on error
3887+ /* Free the intset on error */
3888+ goto client_kill_done ;
38883889 return ;
38893890 }
38903891 } else {
38913892 addReplyErrorObject (c , shared .syntaxerr );
3892- goto client_kill_done ; // Free the intset on error
3893+ /* Free the intset on error */
3894+ goto client_kill_done ;
38933895 return ;
38943896 }
38953897
0 commit comments