cli_common.c: accept redict:// URIs

This commit is contained in:
Drew DeVault 2024-03-21 12:10:04 +01:00
parent e8abf37673
commit 91e1a0c764

View File

@ -306,7 +306,7 @@ static sds percentDecode(const char *pe, size_t len) {
/* Parse a URI and extract the server connection information.
* URI scheme is based on the provisional specification[1] excluding support
* for query parameters. Valid URIs are:
* scheme: "redis://"
* scheme: "redict://" or "redis://"
* authority: [[<username> ":"] <password> "@"] [<hostname> [":" <port>]]
* path: ["/" [<db>]]
*
@ -318,8 +318,10 @@ void parseRedisUri(const char *uri, const char* tool_name, cliConnInfo *connInfo
UNUSED(tls_flag);
#endif
const char *scheme = "redis://";
const char *tlsscheme = "rediss://";
const char *scheme = "redict://";
const char *tlsscheme = "redicts://";
const char *schemecompat = "redis://";
const char *tlsschemecompat = "rediss://";
const char *curr = uri;
const char *end = uri + strlen(uri);
const char *userinfo, *username, *port, *host, *path;
@ -330,11 +332,21 @@ void parseRedisUri(const char *uri, const char* tool_name, cliConnInfo *connInfo
*tls_flag = 1;
curr += strlen(tlsscheme);
#else
fprintf(stderr,"rediss:// is only supported when %s is compiled with OpenSSL\n", tool_name);
fprintf(stderr,"redicts:// is only supported when %s is compiled with OpenSSL\n", tool_name);
exit(1);
#endif
} else if (!strncasecmp(scheme, curr, strlen(scheme))) {
curr += strlen(scheme);
} else if (!strncasecmp(tlsschemecompat, curr, strlen(tlsschemecompat))) {
#ifdef USE_OPENSSL
*tls_flag = 1;
curr += strlen(tlsschemecompat);
#else
fprintf(stderr,"rediss:// is only supported when %s is compiled with OpenSSL\n", tool_name);
exit(1);
#endif
} else if (!strncasecmp(schemecompat, curr, strlen(schemecompat))) {
curr += strlen(schemecompat);
} else {
fprintf(stderr,"Invalid URI scheme\n");
exit(1);