Repository: valkey-io/valkey
File: src/networking.c (C)

Code before:
 * such as identifying specific clients to kill or retrieve. Each field in the struct
 * represents a filter that can be applied based on specific attributes of a client. */
typedef struct {
    /* A set of client IDs to filter. If NULL, no ID filtering is applied. */
    intset *ids;
    intset *not_ids;
    /* Maximum age (in seconds) of a client connection for filtering.
     * Connections younger than this value will not match.
     * A value of 0 means no age filtering. */
    long long max_age;
    /* Address/port of the client. If NULL, no address filtering is applied. */
    char *addr;
    char *not_addr;
    /* Remote address/port of the client. If NULL, no address filtering is applied. */
    char *laddr;
    char *not_laddr;
    /* Filtering clients by authentication user. If NULL, no user-based filtering is applied. */
    user *user;
    user *not_user;
    /* Client type to filter. If set to -1, no type filtering is applied. */
    int type;
    int not_type;
    /* Boolean flag to determine if the current client (`me`) should be filtered. 1 means "skip me", 0 means otherwise. */
    /* Flag to determine if the current client (`me`) should be filtered. 1 means "skip me", 0 means otherwise.
     * If set to -1, the filter is not applied. */
    int skipme;
    /* Client name to filter. If NULL, no name filtering is applied. */
    char *name;
    char *not_name;
    /* Idle time (in seconds) of a client connection for filtering.
     * Connections with idle time more than this value will match.
     * A value of 0 means no idle time filtering. */
    long long idle;
    /* Client flags for filtering. If NULL, no filtering is applied. */
    sds flags;
    sds not_flags;
    /* Library name to filter. If NULL, no library name filtering is applied. */
    robj *lib_name;
    robj *not_lib_name;
    /* Library version to filter. If NULL, no library version filtering is applied. */
    robj *lib_ver;
    robj *not_lib_ver;
    /* Database index to filter. If set to -1, no DB number filtering is applied. */
    int db_number;
    int not_db_number;
    /* Client capa for filtering. If NULL, no filtering is applied. */
    sds capa;
    sds not_capa;
    /* Client ip for filtering. If NULL, no filtering is applied. */
    sds ip;
    sds not_ip;

Review comment (suggestion):
I don't see why it's a good idea to add the new value -1 to this. Does it make the logic simpler in any way? It just pushes the decision about the default value to to a different place in the code. I wasn't needed before.

Until now, it was done like this: In the CLIENT KILL implementation, we just initialize it to 1 and in CLIENT LIST we initialize it to 0, before we parse the filters. I think this is a very simple approach and I see no reason to change it, but I may be missing something.

(We could technically change it to a `bool` if we want to.)

Code after:
/* This struct is used to encapsulate filtering criteria for operations on clients
 * such as identifying specific clients to kill or retrieve. Each field in the struct
 * represents a filter that can be applied based on specific attributes of a client. */
typedef struct {
    /* A set of client IDs to filter. If NULL, no ID filtering is applied. */
    intset *ids;
    intset *not_ids;
    /* Maximum age (in seconds) of a client connection for filtering.
     * Connections younger than this value will not match.
     * A value of 0 means no age filtering. */
    long long max_age;
    /* Address/port of the client. If NULL, no address filtering is applied. */
    char *addr;
    char *not_addr;
    /* Remote address/port of the client. If NULL, no address filtering is applied. */
    char *laddr;
    char *not_laddr;
    /* Filtering clients by authentication user. If NULL, no user-based filtering is applied. */
    user *user;
    user *not_user;
    /* Client type to filter. If set to -1, no type filtering is applied. */
    int type;
    int not_type;
    /* Boolean flag to determine if the current client (`me`) should be filtered. 1 means "skip me", 0 means otherwise. */
    int skipme;
    /* Client name to filter. If NULL, no name filtering is applied. */
    char *name;
    char *not_name;
    /* Idle time (in seconds) of a client connection for filtering.
     * Connections with idle time more than this value will match.
     * A value of 0 means no idle time filtering. */
    long long idle;
    /* Client flags for filtering. If NULL, no filtering is applied. */
    sds flags;
    sds not_flags;
    /* Library name to filter. If NULL, no library name filtering is applied. */
    robj *lib_name;
    robj *not_lib_name;
    /* Library version to filter. If NULL, no library version filtering is applied. */
    robj *lib_ver;
    robj *not_lib_ver;
    /* Database index to filter. If set to -1, no DB number filtering is applied. */
    int db_number;
    int not_db_number;
    /* Client capa for filtering. If NULL, no filtering is applied. */
    sds capa;
    sds not_capa;
    /* Client ip for filtering. If NULL, no filtering is applied. */
    sds ip;
    sds not_ip;
} clientFilter;