Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 51 additions & 6 deletions src/networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -4457,10 +4457,12 @@ static int parseClientFiltersOrReply(client *c, int index, clientFilter *filter)
int moreargs = c->argc > index + 1;

if (!strcasecmp(c->argv[index]->ptr, "id")) {
if (filter->ids == NULL) {
/* Initialize the intset for IDs */
filter->ids = intsetNew();
if (filter->ids) {
zfree(filter->ids);
}
/* Initialize the intset for IDs */
filter->ids = intsetNew();

index++; /* Move to the first ID after "ID" */

/* Process all IDs until a non-numeric argument or end of args */
Expand All @@ -4479,10 +4481,12 @@ static int parseClientFiltersOrReply(client *c, int index, clientFilter *filter)
index++; /* Move to the next argument */
}
} else if (!strcasecmp(c->argv[index]->ptr, "not-id")) {
if (filter->not_ids == NULL) {
/* Initialize the intset for NOT-IDs */
filter->not_ids = intsetNew();
if (filter->not_ids) {
zfree(filter->not_ids);
}
/* Initialize the intset for NOT-IDs */
filter->not_ids = intsetNew();

index++; /* Move to the first ID after "NOT-ID" */

/* Process all NOT-IDs until a non-numeric argument or end of args */
Expand Down Expand Up @@ -4577,13 +4581,21 @@ static int parseClientFiltersOrReply(client *c, int index, clientFilter *filter)
filter->idle = idle_time;
index += 2;
} else if (!strcasecmp(c->argv[index]->ptr, "flags") && moreargs) {
if (filter->flags) {
sdsfree(filter->flags);
filter->flags = NULL;
}
filter->flags = sdsnew(c->argv[index + 1]->ptr);
if (validateClientFlagFilter(filter->flags) == C_ERR) {
addReplyErrorFormat(c, "Unknown flags found in the provided filter: %s", filter->flags);
return C_ERR;
}
index += 2;
} else if (!strcasecmp(c->argv[index]->ptr, "not-flags") && moreargs) {
if (filter->not_flags) {
sdsfree(filter->not_flags);
filter->not_flags = NULL;
}
filter->not_flags = sdsnew(c->argv[index + 1]->ptr);
if (validateClientFlagFilter(filter->not_flags) == C_ERR) {
addReplyErrorFormat(c, "Unknown flags found in the NOT-FLAGS filter: %s", filter->not_flags);
Expand All @@ -4597,18 +4609,34 @@ static int parseClientFiltersOrReply(client *c, int index, clientFilter *filter)
filter->not_name = c->argv[index + 1]->ptr;
index += 2;
} else if (!strcasecmp(c->argv[index]->ptr, "lib-name") && moreargs) {
if (filter->lib_name) {
decrRefCount(filter->lib_name);
filter->lib_name = NULL;
}
filter->lib_name = c->argv[index + 1];
incrRefCount(filter->lib_name);
index += 2;
} else if (!strcasecmp(c->argv[index]->ptr, "not-lib-name") && moreargs) {
if (filter->not_lib_name) {
decrRefCount(filter->not_lib_name);
filter->not_lib_name = NULL;
}
filter->not_lib_name = c->argv[index + 1];
incrRefCount(filter->not_lib_name);
index += 2;
} else if (!strcasecmp(c->argv[index]->ptr, "lib-ver") && moreargs) {
if (filter->lib_ver) {
decrRefCount(filter->lib_ver);
filter->lib_ver = NULL;
}
filter->lib_ver = c->argv[index + 1];
incrRefCount(filter->lib_ver);
index += 2;
} else if (!strcasecmp(c->argv[index]->ptr, "not-lib-ver") && moreargs) {
if (filter->not_lib_ver) {
decrRefCount(filter->not_lib_ver);
filter->not_lib_ver = NULL;
}
filter->not_lib_ver = c->argv[index + 1];
incrRefCount(filter->not_lib_ver);
index += 2;
Expand All @@ -4635,23 +4663,39 @@ static int parseClientFiltersOrReply(client *c, int index, clientFilter *filter)
filter->not_db_number = not_db_id;
index += 2;
} else if (!strcasecmp(c->argv[index]->ptr, "capa") && moreargs) {
if (filter->capa) {
sdsfree(filter->capa);
filter->capa = NULL;
}
filter->capa = sdsnew(c->argv[index + 1]->ptr);
if (validateClientCapaFilter(filter->capa) == C_ERR) {
addReplyErrorFormat(c, "Unknown capa found in the provided filter: %s", filter->capa);
return C_ERR;
}
index += 2;
} else if (!strcasecmp(c->argv[index]->ptr, "not-capa") && moreargs) {
if (filter->not_capa) {
sdsfree(filter->not_capa);
filter->not_capa = NULL;
}
filter->not_capa = sdsnew(c->argv[index + 1]->ptr);
if (validateClientCapaFilter(filter->not_capa) == C_ERR) {
addReplyErrorFormat(c, "Unknown capa found in the NOT-CAPA filter: %s", filter->not_capa);
return C_ERR;
}
index += 2;
} else if (!strcasecmp(c->argv[index]->ptr, "ip") && moreargs) {
if (filter->ip) {
sdsfree(filter->ip);
filter->ip = NULL;
}
filter->ip = sdsnew(c->argv[index + 1]->ptr);
index += 2;
} else if (!strcasecmp(c->argv[index]->ptr, "not-ip") && moreargs) {
if (filter->not_ip) {
sdsfree(filter->not_ip);
filter->not_ip = NULL;
}
filter->not_ip = sdsnew(c->argv[index + 1]->ptr);
index += 2;
} else {
Expand Down Expand Up @@ -5016,6 +5060,7 @@ void clientListCommand(client *c) {
filter.not_type = -1;
filter.db_number = -1;
filter.not_db_number = -1;

int i = 2;

if (parseClientFiltersOrReply(c, i, &filter) != C_OK) {
Expand Down
Loading
Loading