2020-10-28 06:00:54 +00:00
|
|
|
#ifndef __CLICOMMON_H
|
|
|
|
#define __CLICOMMON_H
|
|
|
|
|
|
|
|
#include <hiredis.h>
|
2021-08-03 10:21:29 +01:00
|
|
|
#include <sdscompat.h> /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
|
2020-10-28 06:00:54 +00:00
|
|
|
|
|
|
|
typedef struct cliSSLconfig {
|
|
|
|
/* Requested SNI, or NULL */
|
|
|
|
char *sni;
|
|
|
|
/* CA Certificate file, or NULL */
|
|
|
|
char *cacert;
|
|
|
|
/* Directory where trusted CA certificates are stored, or NULL */
|
|
|
|
char *cacertdir;
|
2021-02-07 12:36:56 +02:00
|
|
|
/* Skip server certificate verification. */
|
|
|
|
int skip_cert_verify;
|
2020-10-28 06:00:54 +00:00
|
|
|
/* Client certificate to authenticate with, or NULL */
|
|
|
|
char *cert;
|
|
|
|
/* Private key file to authenticate with, or NULL */
|
|
|
|
char *key;
|
2021-06-10 20:39:33 +08:00
|
|
|
/* Preferred cipher list, or NULL (applies only to <= TLSv1.2) */
|
2024-05-22 23:24:12 -07:00
|
|
|
char *ciphers;
|
2021-06-10 20:39:33 +08:00
|
|
|
/* Preferred ciphersuites list, or NULL (applies only to TLSv1.3) */
|
2024-05-22 23:24:12 -07:00
|
|
|
char *ciphersuites;
|
2020-10-28 06:00:54 +00:00
|
|
|
} cliSSLconfig;
|
|
|
|
|
2021-09-14 17:45:06 +01:00
|
|
|
|
|
|
|
/* server connection information object, used to describe an ip:port pair, db num user input, and user:pass. */
|
|
|
|
typedef struct cliConnInfo {
|
|
|
|
char *hostip;
|
|
|
|
int hostport;
|
|
|
|
int input_dbnum;
|
|
|
|
char *auth;
|
|
|
|
char *user;
|
|
|
|
} cliConnInfo;
|
|
|
|
|
2020-10-28 06:00:54 +00:00
|
|
|
int cliSecureConnection(redisContext *c, cliSSLconfig config, const char **err);
|
|
|
|
|
|
|
|
ssize_t cliWriteConn(redisContext *c, const char *buf, size_t buf_len);
|
|
|
|
|
2023-05-02 17:31:32 -07:00
|
|
|
int cliSecureInit(void);
|
2020-10-28 06:00:54 +00:00
|
|
|
|
2021-08-03 10:21:29 +01:00
|
|
|
sds readArgFromStdin(void);
|
|
|
|
|
2024-05-22 23:24:12 -07:00
|
|
|
sds *getSdsArrayFromArgv(int argc, char **argv, int quoted);
|
2021-08-03 10:21:29 +01:00
|
|
|
|
|
|
|
sds unquoteCString(char *str);
|
|
|
|
|
2024-05-22 23:24:12 -07:00
|
|
|
void parseRedisUri(const char *uri, const char *tool_name, cliConnInfo *connInfo, int *tls_flag);
|
2021-09-14 17:45:06 +01:00
|
|
|
|
|
|
|
void freeCliConnInfo(cliConnInfo connInfo);
|
redis-cli: Better --json Unicode support and --quoted-json (#10286)
Normally, `redis-cli` escapes non-printable data received from Redis, using a custom scheme (which is also used to handle quoted input). When using `--json` this is not desired as it is not compatible with RFC 7159, which specifies JSON strings are assumed to be Unicode and how they should be escaped.
This commit changes `--json` to follow RFC 7159, which means that properly encoded Unicode strings in Redis will result with a valid Unicode JSON.
However, this introduces a new problem with `--json` and data that is not valid Unicode (e.g., random binary data, text that follows other encoding, etc.). To address this, we add `--quoted-json` which produces JSON strings that follow the original redis-cli quoting scheme.
For example, a value that consists of only null (0x00) bytes will show up as:
* `"\u0000\u0000\u0000"` when using `--json`
* `"\\x00\\x00\\x00"` when using `--quoted-json`
2022-03-06 04:25:52 +09:00
|
|
|
|
|
|
|
sds escapeJsonString(sds s, const char *p, size_t len);
|
|
|
|
|
2023-12-21 19:51:46 +08:00
|
|
|
sds cliVersion(void);
|
|
|
|
|
2024-01-30 19:43:39 +08:00
|
|
|
redisContext *redisConnectWrapper(const char *ip, int port, const struct timeval tv);
|
|
|
|
redisContext *redisConnectUnixWrapper(const char *path, const struct timeval tv);
|
|
|
|
|
2020-10-28 06:00:54 +00:00
|
|
|
#endif /* __CLICOMMON_H */
|